@loucompanion/forge-bridge 0.1.3-dev.9bc5014a2270 → 0.1.3-dev.a891d9601712

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +44 -0
  2. package/dist/bridge/bridge.base.d.ts +5 -1
  3. package/dist/bridge/bridge.service.d.ts +36 -2
  4. package/dist/bridge/bridge.service.js +531 -16
  5. package/dist/bridge/bridge.types.d.ts +114 -1
  6. package/dist/cli/cli.help.js +12 -0
  7. package/dist/cli/cli.service.d.ts +12 -0
  8. package/dist/cli/cli.service.js +163 -0
  9. package/dist/cli/local-config.d.ts +2 -0
  10. package/dist/cli/local-config.js +6 -2
  11. package/dist/sandbox/command-runner.d.ts +4 -0
  12. package/dist/sandbox/command-runner.js +47 -0
  13. package/dist/sandbox/contract.d.ts +5 -0
  14. package/dist/sandbox/contract.js +276 -0
  15. package/dist/sandbox/event-budget.d.ts +11 -0
  16. package/dist/sandbox/event-budget.js +27 -0
  17. package/dist/sandbox/image-policy.d.ts +33 -0
  18. package/dist/sandbox/image-policy.js +245 -0
  19. package/dist/sandbox/index.d.ts +5 -0
  20. package/dist/sandbox/index.js +5 -0
  21. package/dist/sandbox/lease-watchdog.d.ts +18 -0
  22. package/dist/sandbox/lease-watchdog.js +67 -0
  23. package/dist/sandbox/preflight.d.ts +36 -0
  24. package/dist/sandbox/preflight.js +239 -0
  25. package/dist/sandbox/process.d.ts +20 -0
  26. package/dist/sandbox/process.js +124 -0
  27. package/dist/sandbox/repository-lock.d.ts +5 -0
  28. package/dist/sandbox/repository-lock.js +83 -0
  29. package/dist/sandbox/runtime.d.ts +214 -0
  30. package/dist/sandbox/runtime.js +1615 -0
  31. package/dist/sandbox/sandbox.types.d.ts +83 -0
  32. package/dist/sandbox/sandbox.types.js +1 -0
  33. package/dist/sandbox/worker-supervisor.d.ts +13 -0
  34. package/dist/sandbox/worker-supervisor.js +36 -0
  35. package/dist/sandbox/worker.d.ts +1 -0
  36. package/dist/sandbox/worker.js +228 -0
  37. package/dist/sandbox/workspace.service.d.ts +12 -0
  38. package/dist/sandbox/workspace.service.js +49 -0
  39. package/dist/session/phase-completion.artifacts.js +23 -2
  40. package/dist/session/provider-cli/provider-cli.base.d.ts +1 -0
  41. package/dist/session/provider-cli/provider-cli.deterministic.d.ts +2 -0
  42. package/dist/session/provider-cli/provider-cli.deterministic.js +20 -9
  43. package/dist/session/provider-cli/provider-cli.process.d.ts +1 -0
  44. package/dist/session/provider-cli/provider-cli.process.js +23 -1
  45. package/dist/session/provider-cli/provider-cli.prompts.d.ts +12 -1
  46. package/dist/session/provider-cli/provider-cli.prompts.js +119 -2
  47. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  48. package/dist/session/provider-cli/provider-cli.service.js +151 -24
  49. package/dist/session/session.service.js +14 -7
  50. package/dist/session/session.types.d.ts +52 -1
  51. package/dist/session/session.types.js +156 -3
  52. package/dist/shared/process/windows-launch.d.ts +1 -1
  53. package/dist/shared/process/windows-launch.js +6 -3
  54. package/dist/shared/provider-capabilities.d.ts +1 -0
  55. package/dist/shared/provider-capabilities.js +3 -0
  56. package/dist/shared/redaction/redaction.js +4 -2
  57. package/dist/version.d.ts +1 -1
  58. package/dist/version.js +1 -1
  59. package/dist/worktree/dependency-warmer.d.ts +8 -1
  60. package/dist/worktree/dependency-warmer.js +40 -3
  61. package/package.json +4 -2
@@ -1,7 +1,26 @@
1
- import type { RunOnceResultPacket, RunnerDispatchEvent } from "../session/session.types.js";
1
+ import type { ApiKeySecretGrant, RunOnceResultPacket, RunnerDispatchEvent } from "../session/session.types.js";
2
+ import type { SandboxFeatureMatrix } from "../sandbox/sandbox.types.js";
2
3
  export interface BridgeServiceConfig {
3
4
  readonly serverUrl: string;
4
5
  readonly runnerId: string;
6
+ readonly runnerInstanceId: string;
7
+ readonly trustDomainId: string;
8
+ readonly maxConcurrentSandboxes: number;
9
+ readonly maxConcurrentSandboxBuilds: number;
10
+ readonly sandboxPidCapacity: number;
11
+ readonly dockerEnabled: boolean;
12
+ readonly sandboxPublicationMode?: "bridge_push" | "shared_filesystem";
13
+ readonly dockerExecutable: string;
14
+ readonly dockerContext: string;
15
+ readonly sandboxStateRoot: string;
16
+ readonly requireRootlessDocker: boolean;
17
+ readonly diskHighWatermarkPercent: number;
18
+ readonly diskLowWatermarkPercent: number;
19
+ readonly minimumWorkspaceBytes: number;
20
+ readonly imageRetentionCount: number;
21
+ readonly imageRetentionTtlMs: number;
22
+ readonly auditRetentionCount: number;
23
+ readonly auditRetentionTtlMs: number;
5
24
  readonly deviceToken: string;
6
25
  readonly deviceName: string;
7
26
  readonly defaultRepoRoot: string;
@@ -17,6 +36,8 @@ export interface BridgeServiceConfig {
17
36
  readonly supportsManagedForgeArtifacts: boolean;
18
37
  readonly supportsRunnerAuthoredPhaseArtifacts: boolean;
19
38
  readonly supportsDraftRunOnce: boolean;
39
+ readonly supportsDraftAttachments: boolean;
40
+ readonly supportsDraftImageAttachments: boolean;
20
41
  readonly version: string;
21
42
  readonly protocolVersion: number;
22
43
  readonly minServerVersion?: string | null;
@@ -52,17 +73,51 @@ export interface BridgeCapabilities {
52
73
  readonly repoMappings?: readonly BridgeRepoMapping[] | null;
53
74
  readonly os?: string | null;
54
75
  readonly sandboxProfiles?: readonly string[] | null;
76
+ readonly runnerInstanceId?: string | null;
77
+ readonly trustDomainId?: string | null;
78
+ readonly sandboxRuntimes?: readonly string[] | null;
79
+ readonly sandboxRuntimeVersion?: string | null;
80
+ readonly sandboxFeatures?: SandboxFeatureMatrix | null;
81
+ readonly sandboxPublicationModes?: readonly string[] | null;
82
+ readonly sandboxAuthModes?: Readonly<Record<string, readonly string[]>> | null;
83
+ readonly maxConcurrentSandboxes?: number | null;
84
+ readonly reservedSandboxCount?: number | null;
85
+ readonly activeSandboxCount?: number | null;
86
+ readonly startingSandboxCount?: number | null;
87
+ readonly degradedReservationCount?: number | null;
88
+ readonly availableMemoryBytes?: number | null;
89
+ readonly availableCpuMillis?: number | null;
90
+ readonly availableWorkspaceBytes?: number | null;
91
+ readonly diskLow?: boolean | null;
92
+ readonly preflightGeneration?: number | null;
93
+ readonly sandboxUnavailableCode?: string | null;
94
+ readonly sandboxUnavailableReason?: string | null;
55
95
  readonly supportsApiSecretGrant?: boolean | null;
56
96
  readonly supportsManagedWorktrees?: boolean | null;
57
97
  readonly supportsManagedForgeArtifacts?: boolean | null;
58
98
  readonly supportsRunnerAuthoredPhaseArtifacts?: boolean | null;
59
99
  readonly supportsDraftRunOnce?: boolean | null;
100
+ readonly supportsDraftAttachments?: boolean | null;
101
+ readonly supportsDraftImageAttachments?: boolean | null;
60
102
  }
61
103
  export interface BridgeHelloRequest {
62
104
  readonly version: string;
63
105
  readonly protocolVersion: number;
64
106
  readonly capabilities: BridgeCapabilities;
65
107
  readonly minServerVersion?: string | null;
108
+ readonly runnerInstanceId: string;
109
+ }
110
+ export interface BridgePublishCredential {
111
+ readonly username: string;
112
+ readonly secret: string;
113
+ readonly remoteUrl: string;
114
+ readonly expiresAt: string;
115
+ }
116
+ export interface BridgePublishGrantRedemptionResponse {
117
+ readonly accepted: boolean;
118
+ readonly code?: string | null;
119
+ readonly message?: string | null;
120
+ readonly credential?: BridgePublishCredential | null;
66
121
  }
67
122
  export interface BridgeHeartbeatRequest {
68
123
  readonly status?: string | null;
@@ -78,17 +133,75 @@ export interface BridgeCallbackAck {
78
133
  export interface BridgeDispatchEventCallback {
79
134
  readonly leaseId: string;
80
135
  readonly fencingToken: string;
136
+ readonly dispatchAttemptId?: string | null;
137
+ readonly runnerInstanceId?: string | null;
81
138
  readonly event: RunnerDispatchEvent;
82
139
  }
83
140
  export interface BridgeDispatchResultCallback {
84
141
  readonly leaseId: string;
85
142
  readonly fencingToken: string;
143
+ readonly dispatchAttemptId?: string | null;
144
+ readonly runnerInstanceId?: string | null;
86
145
  readonly result: RunOnceResultPacket;
87
146
  }
147
+ export interface BridgeOfferDecisionCallback {
148
+ readonly dispatchAttemptId: string;
149
+ readonly leaseId: string;
150
+ readonly fencingToken: string;
151
+ readonly runnerInstanceId: string;
152
+ readonly accepted: boolean;
153
+ readonly code?: string | null;
154
+ readonly message?: string | null;
155
+ readonly reservedUntil?: string | null;
156
+ }
157
+ export interface BridgeDispatchStartedCallback {
158
+ readonly dispatchAttemptId: string;
159
+ readonly leaseId: string;
160
+ readonly fencingToken: string;
161
+ readonly runnerInstanceId: string;
162
+ }
163
+ export interface BridgeSecretGrantRedemptionRequest {
164
+ readonly dispatchAttemptId: string;
165
+ readonly leaseId: string;
166
+ readonly fencingToken: string;
167
+ readonly runnerInstanceId: string;
168
+ readonly grantId: string;
169
+ }
170
+ export interface BridgeSecretGrantRedemptionResponse extends BridgeCallbackAck {
171
+ readonly grant?: ApiKeySecretGrant | null;
172
+ }
173
+ export interface BridgeLeaseUpdateRequest {
174
+ readonly dispatchAttemptId: string;
175
+ readonly leaseId: string;
176
+ readonly fencingToken: string;
177
+ readonly runnerInstanceId: string;
178
+ readonly expiresAt: string;
179
+ }
88
180
  export interface BridgeCancelRequest {
89
181
  readonly leaseId: string;
90
182
  readonly fencingToken: string;
91
183
  readonly reason?: string | null;
92
184
  }
185
+ export interface BridgeReapRequest {
186
+ readonly runnerId: string;
187
+ readonly runnerInstanceId: string;
188
+ readonly requestedAt: string;
189
+ readonly reason?: string | null;
190
+ }
191
+ export interface BridgeAttemptSnapshotItem {
192
+ readonly dispatchAttemptId: string;
193
+ readonly fencingToken: string;
194
+ readonly runnerInstanceId: string;
195
+ readonly status: string;
196
+ readonly expiresAt: string;
197
+ }
198
+ export interface BridgeAttemptSnapshotResponse extends BridgeCallbackAck {
199
+ readonly attempts?: readonly BridgeAttemptSnapshotItem[] | null;
200
+ readonly generatedAt?: string | null;
201
+ }
93
202
  export type BridgeDispatchHandler = (dispatch: unknown) => Promise<void>;
203
+ export type BridgeOfferHandler = (dispatch: unknown) => Promise<void>;
204
+ export type BridgeStartHandler = (dispatch: unknown) => Promise<void>;
205
+ export type BridgeLeaseUpdateHandler = (request: BridgeLeaseUpdateRequest) => Promise<void>;
94
206
  export type BridgeCancelHandler = (request: BridgeCancelRequest) => Promise<void>;
207
+ export type BridgeReapHandler = (request: BridgeReapRequest) => Promise<void>;
@@ -19,6 +19,7 @@ export function helpText() {
19
19
  " add-repo * Map a Forge repo label/name to a local checkout path",
20
20
  " remove-repo * Remove a saved repo mapping",
21
21
  " cleanup * Prune managed bridge worktrees",
22
+ " sandbox * Initialize, diagnose, or reap Docker sandboxes",
22
23
  " version * Print the installed bridge package version",
23
24
  " help * Display help for command",
24
25
  " run-once * Internal: run one dispatch packet from JSON",
@@ -133,6 +134,17 @@ export function commandHelpText(command) {
133
134
  " forge-bridge cleanup --all --force",
134
135
  "",
135
136
  ].join("\n");
137
+ case "sandbox":
138
+ return [
139
+ "Forge Bridge — sandbox",
140
+ "Initialize or diagnose a repository-owned Forge sandbox contract.",
141
+ "",
142
+ "Usage:",
143
+ " forge-bridge sandbox init [--repo <path>]",
144
+ " forge-bridge sandbox doctor [--repo <path>] [--require-pinned-base]",
145
+ " forge-bridge sandbox reap",
146
+ "",
147
+ ].join("\n");
136
148
  case "run-once":
137
149
  return [
138
150
  "Forge Bridge — run-once",
@@ -45,6 +45,18 @@ export declare function parseArgs(argv: readonly string[]): {
45
45
  readonly config: BridgeServiceConfig;
46
46
  readonly mode: CleanupMode;
47
47
  readonly force: boolean;
48
+ } | {
49
+ readonly ok: true;
50
+ readonly command: "sandbox-init";
51
+ readonly repoPath: string;
52
+ } | {
53
+ readonly ok: true;
54
+ readonly command: "sandbox-doctor";
55
+ readonly repoPath: string;
56
+ readonly requirePinnedBase: boolean;
57
+ } | {
58
+ readonly ok: true;
59
+ readonly command: "sandbox-reap";
48
60
  } | {
49
61
  readonly ok: false;
50
62
  readonly error: string;
@@ -6,11 +6,15 @@ import { createInterface } from "node:readline/promises";
6
6
  import { promisify } from "node:util";
7
7
  import { resolveCursorAgentDirectLaunch } from "../shared/cursor-agent/cursor-agent.launch.js";
8
8
  import { buildWindowsCmdLaunch } from "../shared/process/windows-launch.js";
9
+ import { supportsDraftImageAttachmentsFor } from "../shared/provider-capabilities.js";
9
10
  import { redactSecrets, redactText } from "../shared/redaction/redaction.js";
10
11
  import { defaultBridgeServiceConfig, ForgeBridgeService } from "../bridge/bridge.service.js";
11
12
  import { forgeBridgeVersion } from "../version.js";
12
13
  import { addRepoMapping, applyLocalConfigDefaults, providerStatusesFor, readLocalConfigSync, removeRepoMapping, resolveLocalConfigPath, writeLocalConfig } from "./local-config.js";
13
14
  import { BridgeSessionService } from "../session/session.service.js";
15
+ import { validateDockerfilePolicy, validateSandboxContract } from "../sandbox/contract.js";
16
+ import { DockerPreflight } from "../sandbox/preflight.js";
17
+ import { DockerSandboxRuntime } from "../sandbox/runtime.js";
14
18
  import { parseCompletionMcpArgs, runCompletionMcpServer } from "../session/phase-completion.js";
15
19
  import { failureResult, parseRunOnceDispatchPacket } from "../session/session.types.js";
16
20
  import { commandHelpText, helpText } from "./cli.help.js";
@@ -124,6 +128,15 @@ export class ForgeBridgeCliService {
124
128
  if (args.command === "cleanup") {
125
129
  return await cleanupRepos(args.config, args.mode, args.force, io);
126
130
  }
131
+ if (args.command === "sandbox-init") {
132
+ return await initializeSandbox(args.repoPath, io);
133
+ }
134
+ if (args.command === "sandbox-doctor") {
135
+ return await diagnoseSandbox(args.repoPath, args.requirePinnedBase, io);
136
+ }
137
+ if (args.command === "sandbox-reap") {
138
+ return await reapSandboxes(io);
139
+ }
127
140
  if (args.command === "mcp") {
128
141
  const parsed = parseCompletionMcpArgs(args.argv);
129
142
  if (!parsed.ok) {
@@ -252,6 +265,9 @@ export function parseArgs(argv) {
252
265
  if (argv[0] === "mcp") {
253
266
  return { ok: true, command: "mcp", argv };
254
267
  }
268
+ if (argv[0] === "sandbox") {
269
+ return parseSandboxArgs(argv);
270
+ }
255
271
  if (argv[0] !== "run-once") {
256
272
  return {
257
273
  ok: false,
@@ -282,6 +298,151 @@ export function parseArgs(argv) {
282
298
  resultPath: path.resolve(resultPath)
283
299
  };
284
300
  }
301
+ function parseSandboxArgs(argv) {
302
+ const action = argv[1];
303
+ let repoPath = process.cwd();
304
+ let requirePinnedBase = false;
305
+ for (let index = 2; index < argv.length; index += 1) {
306
+ const arg = argv[index];
307
+ if (arg === "--repo") {
308
+ repoPath = argv[++index] ?? "";
309
+ if (!repoPath)
310
+ return { ok: false, error: "--repo requires a path." };
311
+ }
312
+ else if (arg === "--require-pinned-base" && action === "doctor") {
313
+ requirePinnedBase = true;
314
+ }
315
+ else {
316
+ return { ok: false, error: `Unknown sandbox argument: ${arg}` };
317
+ }
318
+ }
319
+ if (action === "init")
320
+ return { ok: true, command: "sandbox-init", repoPath: path.resolve(repoPath) };
321
+ if (action === "doctor")
322
+ return { ok: true, command: "sandbox-doctor", repoPath: path.resolve(repoPath), requirePinnedBase };
323
+ if (action === "reap" && argv.length === 2)
324
+ return { ok: true, command: "sandbox-reap" };
325
+ return { ok: false, error: "Usage: forge-bridge sandbox <init|doctor|reap> [--repo <path>] [--require-pinned-base]" };
326
+ }
327
+ const sandboxContractTemplate = `schemaVersion: 1
328
+ workingDirectory: /workspace
329
+ commands:
330
+ install: npm ci
331
+ test: npm test
332
+ caches:
333
+ - name: npm
334
+ mode: readonly
335
+ services: []
336
+ environment: []
337
+ artifacts: []
338
+ logs: []
339
+ browser: false
340
+ `;
341
+ const sandboxDockerfileTemplate = `# Pin this base by digest before enabling sandbox_required.
342
+ FROM node:22.17.0-bookworm-slim
343
+ WORKDIR /workspace
344
+ `;
345
+ async function initializeSandbox(repoPath, io) {
346
+ const forgePath = path.join(repoPath, ".forge");
347
+ const files = [
348
+ ["forge.sandbox.yml", sandboxContractTemplate],
349
+ ["Dockerfile", sandboxDockerfileTemplate],
350
+ ["forge.env.example", "# List non-secret variable names in forge.sandbox.yml. Never commit secret values.\n"]
351
+ ];
352
+ await fs.mkdir(forgePath, { recursive: true });
353
+ let created = 0;
354
+ for (const [name, contents] of files) {
355
+ const target = path.join(forgePath, name);
356
+ try {
357
+ const handle = await fs.open(target, "wx", 0o600);
358
+ await handle.writeFile(contents);
359
+ await handle.close();
360
+ io.stdout.write(`Created ${path.relative(repoPath, target)}\n`);
361
+ created += 1;
362
+ }
363
+ catch (error) {
364
+ if (error.code !== "EEXIST")
365
+ throw error;
366
+ io.stdout.write(`Kept existing ${path.relative(repoPath, target)}\n`);
367
+ }
368
+ }
369
+ io.stdout.write(created > 0 ? "Sandbox scaffold is ready. Run `forge-bridge sandbox doctor`.\n" : "Sandbox scaffold already exists.\n");
370
+ return 0;
371
+ }
372
+ async function diagnoseSandbox(repoPath, requirePinnedBase, io) {
373
+ try {
374
+ const forgePath = path.join(repoPath, ".forge");
375
+ const contractSource = await fs.readFile(path.join(forgePath, "forge.sandbox.yml"), "utf8");
376
+ const dockerfile = await fs.readFile(path.join(forgePath, "Dockerfile"), "utf8");
377
+ const contract = validateSandboxContract(contractSource);
378
+ const warnings = validateDockerfilePolicy(dockerfile, requirePinnedBase);
379
+ io.stdout.write(`Contract: valid (${contract.digest})\n`);
380
+ for (const warning of warnings)
381
+ io.stdout.write(`Warning: ${warning}\n`);
382
+ const config = defaultBridgeServiceConfig();
383
+ const preflight = new DockerPreflight({
384
+ dockerExecutable: config.dockerExecutable,
385
+ dockerContext: config.dockerContext,
386
+ stateRoot: config.sandboxStateRoot,
387
+ maxConcurrentSandboxes: config.maxConcurrentSandboxes,
388
+ diskHighWatermarkPercent: config.diskHighWatermarkPercent,
389
+ diskLowWatermarkPercent: config.diskLowWatermarkPercent,
390
+ minimumWorkspaceBytes: config.minimumWorkspaceBytes,
391
+ requireRootless: config.requireRootlessDocker
392
+ });
393
+ try {
394
+ const result = await preflight.refresh();
395
+ if (!result.healthy) {
396
+ io.stderr.write(`Docker: unavailable (${result.unavailableCode ?? "preflight_failed"}): ${result.unavailableReason ?? "unknown reason"}\n`);
397
+ return 1;
398
+ }
399
+ io.stdout.write(`Docker: healthy (${result.runtimeVersion}; capacity ${result.maxConcurrentSandboxes})\n`);
400
+ return 0;
401
+ }
402
+ finally {
403
+ await preflight.release();
404
+ }
405
+ }
406
+ catch (error) {
407
+ io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
408
+ return 1;
409
+ }
410
+ }
411
+ async function reapSandboxes(io) {
412
+ const config = defaultBridgeServiceConfig();
413
+ if (!/^[0-9a-f-]{32,36}$/iu.test(config.runnerId)) {
414
+ io.stderr.write("FORGE_RUNNER_ID must identify the runner whose exact-labeled resources may be reaped.\n");
415
+ return 2;
416
+ }
417
+ const preflight = new DockerPreflight({
418
+ dockerExecutable: config.dockerExecutable,
419
+ dockerContext: config.dockerContext,
420
+ stateRoot: config.sandboxStateRoot,
421
+ maxConcurrentSandboxes: config.maxConcurrentSandboxes,
422
+ diskHighWatermarkPercent: config.diskHighWatermarkPercent,
423
+ diskLowWatermarkPercent: config.diskLowWatermarkPercent,
424
+ minimumWorkspaceBytes: config.minimumWorkspaceBytes,
425
+ requireRootless: config.requireRootlessDocker
426
+ });
427
+ try {
428
+ const result = await preflight.refresh();
429
+ if (!result.healthy && result.unavailableCode !== "docker_disk_low") {
430
+ io.stderr.write(`Docker: unavailable (${result.unavailableCode ?? "preflight_failed"}): ${result.unavailableReason ?? "unknown reason"}\n`);
431
+ return 1;
432
+ }
433
+ const runtime = new DockerSandboxRuntime(config);
434
+ await runtime.reap({ diskLow: result.diskLow });
435
+ io.stdout.write(`Sandbox reaper completed for runner ${config.runnerId}.\n`);
436
+ return 0;
437
+ }
438
+ catch (error) {
439
+ io.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
440
+ return 1;
441
+ }
442
+ finally {
443
+ await preflight.release();
444
+ }
445
+ }
285
446
  function parseConnectArgs(argv) {
286
447
  let serverUrl = null;
287
448
  let runnerId = null;
@@ -499,6 +660,8 @@ function pairedConfig(current, args, claim) {
499
660
  supportsManagedForgeArtifacts: current.supportsManagedForgeArtifacts ?? true,
500
661
  supportsRunnerAuthoredPhaseArtifacts: current.supportsRunnerAuthoredPhaseArtifacts ?? true,
501
662
  supportsDraftRunOnce: current.supportsDraftRunOnce ?? true,
663
+ supportsDraftAttachments: current.supportsDraftAttachments ?? true,
664
+ supportsDraftImageAttachments: supportsDraftImageAttachmentsFor(args.cliProviders),
502
665
  repoMappings: current.repoMappings ?? []
503
666
  };
504
667
  }
@@ -17,6 +17,8 @@ export interface BridgeLocalConfig {
17
17
  readonly supportsManagedForgeArtifacts?: boolean;
18
18
  readonly supportsRunnerAuthoredPhaseArtifacts?: boolean;
19
19
  readonly supportsDraftRunOnce?: boolean;
20
+ readonly supportsDraftAttachments?: boolean;
21
+ readonly supportsDraftImageAttachments?: boolean;
20
22
  }
21
23
  export interface LocalRepoMapping extends BridgeRepoMapping {
22
24
  readonly label: string;
@@ -54,7 +54,9 @@ export function applyLocalConfigDefaults(config, local) {
54
54
  supportsManagedWorktrees: local.supportsManagedWorktrees ?? config.supportsManagedWorktrees,
55
55
  supportsManagedForgeArtifacts: local.supportsManagedForgeArtifacts ?? config.supportsManagedForgeArtifacts,
56
56
  supportsRunnerAuthoredPhaseArtifacts: local.supportsRunnerAuthoredPhaseArtifacts ?? config.supportsRunnerAuthoredPhaseArtifacts,
57
- supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce
57
+ supportsDraftRunOnce: local.supportsDraftRunOnce ?? config.supportsDraftRunOnce,
58
+ supportsDraftAttachments: local.supportsDraftAttachments ?? config.supportsDraftAttachments,
59
+ supportsDraftImageAttachments: local.supportsDraftImageAttachments ?? config.supportsDraftImageAttachments
58
60
  };
59
61
  }
60
62
  export async function addRepoMapping(label, repoPath) {
@@ -113,7 +115,9 @@ function normalizeLocalConfig(config) {
113
115
  supportsManagedWorktrees: config.supportsManagedWorktrees,
114
116
  supportsManagedForgeArtifacts: config.supportsManagedForgeArtifacts,
115
117
  supportsRunnerAuthoredPhaseArtifacts: config.supportsRunnerAuthoredPhaseArtifacts,
116
- supportsDraftRunOnce: config.supportsDraftRunOnce
118
+ supportsDraftRunOnce: config.supportsDraftRunOnce,
119
+ supportsDraftAttachments: config.supportsDraftAttachments,
120
+ supportsDraftImageAttachments: config.supportsDraftImageAttachments
117
121
  };
118
122
  }
119
123
  function emptyConfig() {
@@ -0,0 +1,4 @@
1
+ import type { CommandOptions, CommandResult, CommandRunner } from "./sandbox.types.js";
2
+ export declare class BoundedCommandRunner implements CommandRunner {
3
+ run(command: string, args: readonly string[], options?: CommandOptions): Promise<CommandResult>;
4
+ }
@@ -0,0 +1,47 @@
1
+ import { spawn } from "node:child_process";
2
+ export class BoundedCommandRunner {
3
+ async run(command, args, options = {}) {
4
+ const maxOutputBytes = options.maxOutputBytes ?? 1024 * 1024;
5
+ return await new Promise((resolve, reject) => {
6
+ const controller = new AbortController();
7
+ const abort = () => controller.abort(options.signal?.reason ?? "command cancelled");
8
+ options.signal?.addEventListener("abort", abort, { once: true });
9
+ const timeout = options.timeoutMs
10
+ ? setTimeout(() => controller.abort(`command exceeded ${options.timeoutMs}ms`), options.timeoutMs)
11
+ : null;
12
+ timeout?.unref?.();
13
+ const child = spawn(command, [...args], {
14
+ cwd: options.cwd,
15
+ env: options.env ? { ...options.env } : undefined,
16
+ stdio: [options.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
17
+ signal: controller.signal,
18
+ windowsHide: true,
19
+ });
20
+ let stdout = Buffer.alloc(0);
21
+ let stderr = Buffer.alloc(0);
22
+ const append = (current, chunk) => {
23
+ if (current.length >= maxOutputBytes)
24
+ return current;
25
+ return Buffer.concat([current, chunk.subarray(0, maxOutputBytes - current.length)]);
26
+ };
27
+ child.stdout.on("data", (chunk) => { stdout = append(stdout, chunk); });
28
+ child.stderr.on("data", (chunk) => { stderr = append(stderr, chunk); });
29
+ child.on("error", (error) => {
30
+ cleanup();
31
+ reject(error);
32
+ });
33
+ child.on("close", (code) => {
34
+ cleanup();
35
+ resolve({ exitCode: code ?? 1, stdout: stdout.toString("utf8"), stderr: stderr.toString("utf8") });
36
+ });
37
+ if (options.stdin !== undefined) {
38
+ child.stdin.end(options.stdin);
39
+ }
40
+ function cleanup() {
41
+ if (timeout)
42
+ clearTimeout(timeout);
43
+ options.signal?.removeEventListener("abort", abort);
44
+ }
45
+ });
46
+ }
47
+ }
@@ -0,0 +1,5 @@
1
+ import type { ValidatedSandboxContract } from "./sandbox.types.js";
2
+ export declare function validateSandboxContract(source: string): ValidatedSandboxContract;
3
+ export declare function validateDockerfilePolicy(source: string, requirePinnedBase: boolean): readonly string[];
4
+ export declare function dockerfileBaseImages(source: string): readonly string[];
5
+ export declare function dockerfileUpstreamImages(source: string): readonly string[];