mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-16 15:15:35 +02:00
## Thinking Path > - Paperclip is an open source app that manages AI agents for work > - Paperclip runs agents in local and remote sandbox environments > - A sandbox needs a bounded channel for commands and asynchronous input > - Daytona needs a real pseudo-terminal transport for this channel > - The sandbox gateway also needs a mode that handles channel loss safely > - This pull request adds the Daytona transport and gateway mode behind a default-off kill switch > - The benefit is a tested foundation for later transport selection ## Linked Issues or Issue Description **Subsystem affected** Cross-cutting (multiple of the above): sandbox providers, plugin SDK, server settings, and shared types. **Problem or motivation** The merged sandbox protocol has no runtime transport for Daytona. The generated sandbox gateway also has no duplex mode. A later transport-selection change needs both parts and a safe per-run gate. **Proposed solution** Add a Daytona `duplexCommandStream` transport over a raw pseudo-terminal. Add a generated gateway mode named `duplex_v1`. Add the `enableSandboxDuplexBridge` setting with a default value of `false`. Keep transport selection disabled until a later pull request. **Alternatives considered** Keep the protocol unused until the transport-selection change. This would delay provider tests and leave the gateway path without direct coverage. **Roadmap alignment** This change supports the completed Roadmap item for cloud and sandbox agents. It extends the merged sandbox channel foundation in pull request #11738. **Additional context** The Daytona provider remains an untrusted boundary. Deployments must use least-privilege provider credentials and provider-side quota controls. Operators must name an owner for duplex telemetry retention before rollout. ## What Changed - Add the Daytona `duplexCommandStream` capability over a raw pseudo-terminal. - Add a launch wrapper that disables echo and newline translation for NDJSON frames. - Close channels on lease release, destroy, resume of a stopped worker, and worker shutdown. - Declare the capability in the Daytona manifest and set `PLUGIN_VERSION` to `0.1.5`. - Add the worker-to-host notification sink at `ctx.duplexChannel.data` and `ctx.duplexChannel.exit`. - Add the generated sandbox gateway mode `PAPERCLIP_API_BRIDGE_MODE=duplex_v1`. - Add channel-loss results of `409 outcome_indeterminate` and `503 bridge_unavailable`. - Add the per-run setting `enableSandboxDuplexBridge`, with a default value of `false`. - Add unit tests, generated-source codec tests, lifecycle tests, and a credential-gated live Daytona test. ## Verification - Daytona suite: 185 tests pass. - Adapter utilities: 754 tests pass and 4 tests skip. - Plugin SDK: 62 tests pass. - Shared package: 28 tests pass. - Server duplex tests pass. - Shared, plugin SDK, server, and Daytona TypeScript checks pass. - The live Daytona test passes 3 cases when `DAYTONA_API_KEY` is set. - The live Daytona test skips 3 cases without `DAYTONA_API_KEY`. - CI must run the full workspace typecheck, test, and build gates after PR creation. ## Risks - The Daytona control plane and pseudo-terminal remain untrusted boundaries. - The duplex gateway changes behavior only when the mode and per-run setting enable it. - A lost channel fails requests without replay, so callers must handle indeterminate outcomes. - The transport-selection change must require both `duplexCommandStream === true` and `enableSandboxDuplexBridge === true`. - The provider credential and quota limits need operator control before rollout. ## Model Used OpenAI Codex, GPT-5, tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes: #` / `Refs: #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
134 lines
6.1 KiB
TypeScript
134 lines
6.1 KiB
TypeScript
import { z } from "zod";
|
|
import { DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE } from "../types/feedback.js";
|
|
import {
|
|
DAILY_RETENTION_PRESETS,
|
|
WEEKLY_RETENTION_PRESETS,
|
|
MONTHLY_RETENTION_PRESETS,
|
|
DEFAULT_BACKUP_RETENTION,
|
|
DEFAULT_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS,
|
|
MAX_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS,
|
|
MIN_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS,
|
|
} from "../types/instance.js";
|
|
import { feedbackDataSharingPreferenceSchema } from "./feedback.js";
|
|
|
|
function presetSchema<T extends readonly number[]>(presets: T, label: string) {
|
|
return z.number().refine(
|
|
(v): v is T[number] => (presets as readonly number[]).includes(v),
|
|
{ message: `${label} must be one of: ${presets.join(", ")}` },
|
|
);
|
|
}
|
|
|
|
export const backupRetentionPolicySchema = z.object({
|
|
dailyDays: presetSchema(DAILY_RETENTION_PRESETS, "dailyDays").default(DEFAULT_BACKUP_RETENTION.dailyDays),
|
|
weeklyWeeks: presetSchema(WEEKLY_RETENTION_PRESETS, "weeklyWeeks").default(DEFAULT_BACKUP_RETENTION.weeklyWeeks),
|
|
monthlyMonths: presetSchema(MONTHLY_RETENTION_PRESETS, "monthlyMonths").default(DEFAULT_BACKUP_RETENTION.monthlyMonths),
|
|
});
|
|
|
|
export const instanceGeneralSettingsSchema = z.object({
|
|
censorUsernameInLogs: z.boolean().default(false),
|
|
keyboardShortcuts: z.boolean().default(false),
|
|
feedbackDataSharingPreference: feedbackDataSharingPreferenceSchema.default(
|
|
DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE,
|
|
),
|
|
backupRetention: backupRetentionPolicySchema.default(DEFAULT_BACKUP_RETENTION),
|
|
// Execution policy. Absent/"any" = unrestricted; "kubernetes" forces the
|
|
// Kubernetes sandbox provider and denies local/ssh execution (cloud_tenant).
|
|
executionMode: z.enum(["kubernetes", "any"]).optional(),
|
|
}).strict();
|
|
|
|
export const patchInstanceGeneralSettingsSchema = instanceGeneralSettingsSchema.partial();
|
|
|
|
export const instanceExperimentalSettingsSchema = z.object({
|
|
enableEnvironments: z.boolean().default(false),
|
|
enableManagedSandboxOnly: z.boolean().default(false),
|
|
enableIsolatedWorkspaces: z.boolean().default(false),
|
|
enableStreamlinedLeftNavigation: z.boolean().default(true),
|
|
enableApps: z.boolean().default(false),
|
|
enablePipelines: z.boolean().default(false),
|
|
enableCases: z.boolean().default(false),
|
|
enableConferenceRoomChat: z.boolean().default(false),
|
|
enableClassicTaskInterface: z.boolean().default(false),
|
|
enableTaskWatchdogs: z.boolean().default(false),
|
|
enableIssuePlanDecompositions: z.boolean().default(false),
|
|
enableExperimentalFileViewer: z.boolean().default(false),
|
|
enableExternalObjects: z.boolean().default(false),
|
|
enableSmokeLab: z.boolean().default(false),
|
|
enableBuiltInAgents: z.boolean().default(false),
|
|
enableBetaSkills: z.boolean().default(false),
|
|
enableSummaries: z.boolean().default(false),
|
|
enableStatusCards: z.boolean().default(false),
|
|
enableDecisions: z.boolean().default(false),
|
|
enableGoalsSidebarLink: z.boolean().default(false),
|
|
enableServerInfoDebugView: z.boolean().default(false),
|
|
enableSimplifiedEnglishInteractions: z.boolean().default(false),
|
|
autoRestartDevServerWhenIdle: z.boolean().default(false),
|
|
enableIssueGraphLivenessAutoRecovery: z.boolean().default(false),
|
|
enableWorkspaceBranchReconcileForward: z.boolean().default(true),
|
|
enableWorkspaceDirtyQuarantineRepair: z.boolean().default(true),
|
|
enableOwnerInstanceAdmin: z.boolean().default(false),
|
|
// Kill switch for the sandbox duplex command-stream bridge. Default off. When
|
|
// off the host keeps the file bridge for every run with no manifest change and
|
|
// no redeploy. The host reads this per run before it selects the transport.
|
|
enableSandboxDuplexBridge: z.boolean().default(false),
|
|
enableWorktreeRunExecution: z.boolean().default(false),
|
|
worktreeRunExecutionActivatedAt: z.string().datetime().nullable().default(null),
|
|
worktreeRunExecutionActivationInstanceId: z.string().min(1).nullable().default(null),
|
|
issueGraphLivenessAutoRecoveryLookbackHours: z
|
|
.number()
|
|
.int()
|
|
.min(MIN_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS)
|
|
.max(MAX_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS)
|
|
.default(DEFAULT_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS),
|
|
}).strict();
|
|
|
|
export const patchInstanceExperimentalSettingsSchema = instanceExperimentalSettingsSchema
|
|
.omit({
|
|
worktreeRunExecutionActivatedAt: true,
|
|
worktreeRunExecutionActivationInstanceId: true,
|
|
})
|
|
.partial()
|
|
.strip();
|
|
|
|
export const managedSettingMetadataSchema = z.object({
|
|
managed: z.literal(true),
|
|
managedBy: z.literal("paperclip-cloud"),
|
|
}).strict();
|
|
|
|
// Response shape of the experimental settings endpoints: on cloud-managed
|
|
// instances every overlaid key is listed in `managedKeys`; self-hosted
|
|
// responses omit the field entirely.
|
|
export const instanceExperimentalSettingsWithManagedSchema = instanceExperimentalSettingsSchema.extend({
|
|
managedKeys: z.record(managedSettingMetadataSchema).optional(),
|
|
}).strict();
|
|
|
|
export const patchInstanceSettingsSchema = z.object({
|
|
defaultEnvironmentId: z.string().uuid().nullable().optional(),
|
|
}).strict();
|
|
|
|
export const issueGraphLivenessAutoRecoveryRequestSchema = z.object({
|
|
lookbackHours: z
|
|
.number()
|
|
.int()
|
|
.min(MIN_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS)
|
|
.max(MAX_ISSUE_GRAPH_LIVENESS_AUTO_RECOVERY_LOOKBACK_HOURS)
|
|
.optional(),
|
|
}).strict();
|
|
|
|
export type InstanceGeneralSettings = z.infer<typeof instanceGeneralSettingsSchema>;
|
|
export type PatchInstanceGeneralSettings = z.infer<typeof patchInstanceGeneralSettingsSchema>;
|
|
export type InstanceExperimentalSettings = z.infer<typeof instanceExperimentalSettingsSchema>;
|
|
export type PatchInstanceExperimentalSettings = z.infer<typeof patchInstanceExperimentalSettingsSchema>;
|
|
export type PatchInstanceSettings = z.infer<typeof patchInstanceSettingsSchema>;
|
|
export type IssueGraphLivenessAutoRecoveryRequest = z.infer<
|
|
typeof issueGraphLivenessAutoRecoveryRequestSchema
|
|
>;
|
|
|
|
export const instanceSettingsSchema = z.object({
|
|
id: z.string().uuid(),
|
|
defaultEnvironmentId: z.string().uuid().nullable(),
|
|
general: instanceGeneralSettingsSchema,
|
|
experimental: instanceExperimentalSettingsWithManagedSchema,
|
|
createdAt: z.union([z.date(), z.string().datetime()]),
|
|
updatedAt: z.union([z.date(), z.string().datetime()]),
|
|
}).strict();
|