@snappedly-tools/shipyard 0.4.4 → 0.5.0

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.
@@ -1,6 +1,6 @@
1
- export { docker } from '../chunk-OCJKONZ7.js';
2
- export { defaultImageName } from '../chunk-2GT3OPO5.js';
1
+ export { docker } from '../chunk-WAXEMZUV.js';
2
+ export { defaultImageName } from '../chunk-FDYOTN55.js';
3
3
  import '../chunk-KMGNFXKN.js';
4
- import '../chunk-WA7QPAXO.js';
4
+ import '../chunk-ACD46ZM4.js';
5
5
  //# sourceMappingURL=docker.js.map
6
6
  //# sourceMappingURL=docker.js.map
@@ -1,4 +1,4 @@
1
- export { noSandbox } from '../chunk-VW4MI5GJ.js';
2
- import '../chunk-WA7QPAXO.js';
1
+ export { noSandbox } from '../chunk-SOJTAJTF.js';
2
+ import '../chunk-ACD46ZM4.js';
3
3
  //# sourceMappingURL=no-sandbox.js.map
4
4
  //# sourceMappingURL=no-sandbox.js.map
@@ -1,5 +1,5 @@
1
1
  import { createIsolatedSandboxProvider, shellQuote } from '../chunk-KMGNFXKN.js';
2
- import { MAX_TAIL_CHARS, OutputByteCounter, BoundedTail } from '../chunk-WA7QPAXO.js';
2
+ import { MAX_TAIL_CHARS, StreamedProcessOutput } from '../chunk-ACD46ZM4.js';
3
3
  import { execFileSync } from 'child_process';
4
4
  import { mkdir, lstat, writeFile, chmod, mkdtemp, readFile, rm } from 'fs/promises';
5
5
  import { randomUUID } from 'crypto';
@@ -36,45 +36,29 @@ var vercel = (options) => createIsolatedSandboxProvider({
36
36
  worktreePath: VERCEL_REPO_PATH,
37
37
  exec: async (command, opts) => {
38
38
  if (opts?.onLine || opts?.maxOutputBytes !== void 0) {
39
- const onLine = opts?.onLine ?? (() => {
39
+ const output = new StreamedProcessOutput({
40
+ ...opts,
41
+ maxOutputTailChars
40
42
  });
41
- const outputLimit = opts?.maxOutputBytes === void 0 ? void 0 : new OutputByteCounter(opts.maxOutputBytes);
42
- const tailChars = opts?.maxOutputBytes ?? maxOutputTailChars;
43
- const stdoutTail = new BoundedTail(tailChars, "\n");
44
- const stderrTail = new BoundedTail(tailChars, "");
45
- let outputLimitError;
46
- const checkOutputLimit = (chunk) => {
47
- if (outputLimit === void 0 || outputLimitError !== void 0) {
48
- return;
49
- }
50
- outputLimit.add(chunk);
51
- if (outputLimit.exceeded) {
52
- outputLimitError = new Error(
53
- `Sandbox command output exceeded ${opts.maxOutputBytes} bytes`
54
- );
55
- }
56
- };
57
43
  let partial = "";
58
44
  const stdoutWritable = new Writable({
59
45
  write(chunk, _encoding, callback) {
60
- checkOutputLimit(chunk.toString());
61
- if (outputLimitError !== void 0) {
62
- callback(outputLimitError);
46
+ const error = output.checkLimit(chunk.toString());
47
+ if (error !== void 0) {
48
+ callback(error);
63
49
  return;
64
50
  }
65
51
  const text = partial + chunk.toString();
66
52
  const lines = text.split("\n");
67
53
  partial = lines.pop() ?? "";
68
54
  for (const line of lines) {
69
- stdoutTail.push(line);
70
- onLine(line);
55
+ output.addStdoutLine(line);
71
56
  }
72
57
  callback();
73
58
  },
74
59
  final(callback) {
75
60
  if (partial) {
76
- stdoutTail.push(partial);
77
- onLine(partial);
61
+ output.addStdoutLine(partial);
78
62
  partial = "";
79
63
  }
80
64
  callback();
@@ -82,12 +66,12 @@ var vercel = (options) => createIsolatedSandboxProvider({
82
66
  });
83
67
  const stderrWritable = new Writable({
84
68
  write(chunk, _encoding, callback) {
85
- checkOutputLimit(chunk.toString());
86
- if (outputLimitError !== void 0) {
87
- callback(outputLimitError);
69
+ const error = output.checkLimit(chunk.toString());
70
+ if (error !== void 0) {
71
+ callback(error);
88
72
  return;
89
73
  }
90
- stderrTail.push(chunk.toString());
74
+ output.addStderr(chunk.toString());
91
75
  callback();
92
76
  }
93
77
  });
@@ -99,12 +83,8 @@ var vercel = (options) => createIsolatedSandboxProvider({
99
83
  stderr: stderrWritable,
100
84
  ...opts?.sudo ? { sudo: true } : {}
101
85
  });
102
- if (outputLimitError !== void 0) throw outputLimitError;
103
- return {
104
- stdout: stdoutTail.toString(),
105
- stderr: stderrTail.toString(),
106
- exitCode: result2.exitCode
107
- };
86
+ if (output.error !== void 0) throw output.error;
87
+ return output.result(result2.exitCode);
108
88
  }
109
89
  const result = await sandbox.runCommand({
110
90
  cmd: "sh",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/sandboxes/vercel.ts"],"names":["result"],"mappings":";;;;;;;;;AAoCA,IAAM,gBAAA,GAAmB,2BAAA;AA+GlB,IAAM,MAAA,GAAS,CAAC,OAAA,KACrB,6BAAA,CAA8B;AAAA,EAC5B,IAAA,EAAM,QAAA;AAAA,EACN,KAAK,OAAA,EAAS,GAAA;AAAA,EACd,MAAA,EAAQ,OAAO,aAAA,KAAkD;AAC/D,IAAA,MAAM,kBAAA,GAAqB,SAAS,kBAAA,IAAsB,cAAA;AAE1D,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,OAAO,iBAAiB,CAAA;AAElD,IAAA,MAAM,eAAwC,EAAC;AAG/C,IAAA,IAAI,OAAA,EAAS,MAAA,EAAQ,YAAA,CAAa,MAAA,GAAS,OAAA,CAAQ,MAAA;AACnD,IAAA,IAAI,OAAA,EAAS,KAAA,EAAO,YAAA,CAAa,KAAA,GAAQ,OAAA,CAAQ,KAAA;AACjD,IAAA,IAAI,OAAA,EAAS,SAAA,EAAW,YAAA,CAAa,SAAA,GAAY,OAAA,CAAQ,SAAA;AACzD,IAAA,IAAI,OAAA,EAAS,aAAA;AACX,MAAA,YAAA,CAAa,gBAAgB,OAAA,CAAQ,aAAA;AAEvC,IAAA,MAAM,eAAA,GAAkB,OAAA,EAAS,OAAA,IAAW,OAAA,EAAS,QAAA;AACrD,IAAA,IAAI,eAAA,eAA8B,OAAA,GAAU,eAAA;AAG5C,IAAA,MAAM,YAAA,GAAe,OAAA,EAAS,OAAA,IAAW,OAAA,EAAS,SAAA;AAClD,IAAA,IAAI,YAAA,KAAiB,MAAA,E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C,QAAA,MAAM,QAAQ,IAAA,EAAK;AAAA,MACrB;AAAA,KACF;AAEA,IAAA,OAAO,MAAA;AAAA,EACT;AACF,CAAC","file":"vercel.js","sourcesContent":["/**\n * Vercel isolated sandbox provider — wraps `@vercel/sandbox` into a SandboxProvider.\n *\n * Usage:\n * import { vercel } from \"@snappedly-tools/shipyard/sandboxes/vercel\";\n * await run({ agent: codex(CODEX_MODELS.routine), sandbox: vercel() });\n */\n\nimport { execFileSync } from \"node:child_process\";\nimport {\n lstat,\n chmod,\n mkdir,\n mkdtemp,\n readFile,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { Writable } from \"node:stream\";\nimport {\n createIsolatedSandboxProvider,\n type ExecResult,\n type IsolatedSandboxHandle,\n type IsolatedSandboxProvider,\n} from \"../SandboxProvider.js\";\nimport {\n BoundedTail,\n MAX_TAIL_CHARS,\n OutputByteCounter,\n} from \"../boundedTail.js\";\nimport { shellQuote } from \"../shellQuote.js\";\n\n/** Worktree path inside the Vercel sandbox. */\nconst VERCEL_REPO_PATH = \"/vercel/sandbox/workspace\";\n\n/**\n * Options for creating a Vercel sandbox provider.\n *\n * All `@vercel/sandbox` `Sandbox.create()` options are accepted as pass-through,\n * plus Shipyard-specific options for auth and branch strategy.\n */\nexport interface VercelOptions {\n /**\n * Vercel access token.\n *\n * Falls back to the SDK's default auth behavior, which reads\n * `VERCEL_OIDC_TOKEN` (recommended for Vercel-hosted environments) or\n * `VERCEL_TOKEN` from the environment.\n */\n readonly token?: string;\n\n // ---- Pass-through @vercel/sandbox Sandbox.create() options ----\n\n /**\n * The source of the sandbox (git repo, tarball, or snapshot).\n * Omit to start an empty sandbox.\n */\n readonly source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n username?: string;\n password?: string;\n }\n | {\n type: \"tarball\";\n url: string;\n }\n | {\n type: \"snapshot\";\n snapshotId: string;\n };\n\n /** Array of port numbers to expose from the sandbox (up to 4). */\n readonly ports?: number[];\n\n /** Timeout in milliseconds before the sandbox auto-terminates. */\n readonly timeout?: number;\n\n /**\n * Resources to allocate to the sandbox.\n * Each vCPU gets 2048 MB of memory.\n */\n readonly resources?: {\n vcpus: number;\n };\n\n /**\n * The runtime of the sandbox (e.g. `\"node24\"`, `\"node22\"`, `\"python3.13\"`).\n * Defaults to `\"node24\"`.\n */\n readonly runtime?: string;\n\n /**\n * Network policy for the sandbox.\n * Defaults to full internet access if not specified.\n */\n readonly networkPolicy?: Record<string, unknown>;\n\n /**\n * Vercel project ID to associate sandbox operations with.\n */\n readonly projectId?: string;\n\n /**\n * Vercel team ID to associate sandbox operations with.\n */\n readonly teamId?: string;\n\n /**\n * Timeout in milliseconds (alias for `timeout`, kept for discoverability).\n */\n readonly timeoutMs?: number;\n\n /**\n * Sandbox template shorthand (e.g. `\"node-22\"`).\n * Maps to the `runtime` option.\n */\n readonly template?: string;\n\n /** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */\n readonly env?: Record<string, string>;\n\n /**\n * Maximum number of characters of streamed `exec` output retained per stream\n * (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).\n *\n * Output is delivered live to `onLine` regardless; this only bounds the tail\n * returned in `ExecResult`, preventing a long-running agent's output from\n * overflowing V8's max string length and crashing the run.\n */\n readonly maxOutputTailChars?: number;\n}\n\n/**\n * Create a Vercel isolated sandbox provider.\n *\n * The returned provider creates Vercel Firecracker microVM sandboxes via\n * the `@vercel/sandbox` SDK. Each sandbox is ephemeral — one sandbox per run.\n *\n * Requires `@vercel/sandbox` to be installed as a peer dependency.\n */\nexport const vercel = (options?: VercelOptions): IsolatedSandboxProvider =>\n createIsolatedSandboxProvider({\n name: \"vercel\",\n env: options?.env,\n create: async (createOptions): Promise<IsolatedSandboxHandle> => {\n const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;\n // Dynamic import so the peer dependency is only loaded at runtime\n const { Sandbox } = await import(\"@vercel/sandbox\");\n\n const createParams: Record<string, unknown> = {};\n\n // Pass through SDK options\n if (options?.source) createParams.source = options.source;\n if (options?.ports) createParams.ports = options.ports;\n if (options?.resources) createParams.resources = options.resources;\n if (options?.networkPolicy)\n createParams.networkPolicy = options.networkPolicy;\n // runtime takes precedence over the template convenience alias\n const resolvedRuntime = options?.runtime ?? options?.template;\n if (resolvedRuntime) createParams.runtime = resolvedRuntime;\n\n // Timeout: prefer explicit timeout, fall back to timeoutMs alias\n const timeoutValue = options?.timeout ?? options?.timeoutMs;\n if (timeoutValue !== undefined) createParams.timeout = timeoutValue;\n\n // Merge provider env with Shipyard env\n createParams.env = createOptions.env;\n\n // Auth: pass token and team/project IDs if provided\n if (options?.token) createParams.token = options.token;\n if (options?.projectId) createParams.projectId = options.projectId;\n if (options?.teamId) createParams.teamId = options.teamId;\n\n const sandbox = await Sandbox.create(\n createParams as Parameters<typeof Sandbox.create>[0],\n );\n\n // Ensure worktree directory exists\n await sandbox.mkDir(VERCEL_REPO_PATH);\n\n const handle: IsolatedSandboxHandle = {\n worktreePath: VERCEL_REPO_PATH,\n\n exec: async (\n command: string,\n opts?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n maxOutputBytes?: number;\n },\n ): Promise<ExecResult> => {\n if (opts?.onLine || opts?.maxOutputBytes !== undefined) {\n const onLine = opts?.onLine ?? (() => {});\n const outputLimit =\n opts?.maxOutputBytes === undefined\n ? undefined\n : new OutputByteCounter(opts.maxOutputBytes);\n const tailChars = opts?.maxOutputBytes ?? maxOutputTailChars;\n const stdoutTail = new BoundedTail(tailChars, \"\\n\");\n const stderrTail = new BoundedTail(tailChars, \"\");\n let outputLimitError: Error | undefined;\n const checkOutputLimit = (chunk: string): void => {\n if (outputLimit === undefined || outputLimitError !== undefined) {\n return;\n }\n outputLimit.add(chunk);\n if (outputLimit.exceeded) {\n outputLimitError = new Error(\n `Sandbox command output exceeded ${opts.maxOutputBytes} bytes`,\n );\n }\n };\n let partial = \"\";\n\n const stdoutWritable = new Writable({\n write(chunk, _encoding, callback) {\n checkOutputLimit(chunk.toString());\n if (outputLimitError !== undefined) {\n callback(outputLimitError);\n return;\n }\n const text = partial + chunk.toString();\n const lines = text.split(\"\\n\");\n partial = lines.pop() ?? \"\";\n for (const line of lines) {\n stdoutTail.push(line);\n onLine(line);\n }\n callback();\n },\n final(callback) {\n if (partial) {\n stdoutTail.push(partial);\n onLine(partial);\n partial = \"\";\n }\n callback();\n },\n });\n\n const stderrWritable = new Writable({\n write(chunk, _encoding, callback) {\n checkOutputLimit(chunk.toString());\n if (outputLimitError !== undefined) {\n callback(outputLimitError);\n return;\n }\n stderrTail.push(chunk.toString());\n callback();\n },\n });\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n stdout: stdoutWritable,\n stderr: stderrWritable,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n if (outputLimitError !== undefined) throw outputLimitError;\n\n return {\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode: result.exitCode,\n };\n }\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n const stdout = await result.stdout();\n const stderr = await result.stderr();\n\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n };\n },\n\n copyIn: async (\n hostPath: string,\n sandboxPath: string,\n ): Promise<void> => {\n const info = await lstat(hostPath);\n if (info.isSymbolicLink()) {\n throw new Error(`Refusing to copy a symbolic link: ${hostPath}`);\n }\n if (info.isDirectory()) {\n const tempDir = await mkdtemp(join(tmpdir(), \"shipyard-copyin-\"));\n const tarPath = join(tempDir, \"archive.tar.gz\");\n try {\n execFileSync(\"tar\", [\"-czf\", tarPath, \"-C\", hostPath, \".\"]);\n const tarContent = await readFile(tarPath);\n const sandboxTarPath = `/tmp/shipyard-copyin-${randomUUID()}.tar.gz`;\n await sandbox.writeFiles([\n { path: sandboxTarPath, content: tarContent },\n ]);\n await sandbox.runCommand({\n cmd: \"sh\",\n args: [\n \"-c\",\n `mkdir -p ${shellQuote(sandboxPath)} && tar -xzf ${shellQuote(sandboxTarPath)} -C ${shellQuote(sandboxPath)} && rm -f ${shellQuote(sandboxTarPath)}`,\n ],\n });\n } finally {\n await rm(tempDir, { recursive: true, force: true }).catch(\n () => {},\n );\n }\n } else {\n const content = await readFile(hostPath);\n await sandbox.writeFiles([{ path: sandboxPath, content }]);\n }\n },\n\n copyFileOut: async (\n sandboxPath: string,\n hostPath: string,\n ): Promise<void> => {\n const buffer = await sandbox.readFileToBuffer({\n path: sandboxPath,\n });\n if (!buffer) {\n throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);\n }\n await mkdir(dirname(hostPath), { recursive: true, mode: 0o700 });\n try {\n if ((await lstat(hostPath)).isSymbolicLink()) {\n throw new Error(\n `Refusing to overwrite symbolic link: ${hostPath}`,\n );\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n await writeFile(hostPath, buffer, { mode: 0o600 });\n await chmod(hostPath, 0o600);\n },\n\n close: async (): Promise<void> => {\n await sandbox.stop();\n },\n };\n\n return handle;\n },\n });\n"]}
1
+ {"version":3,"sources":["../../src/sandboxes/vercel.ts"],"names":["result"],"mappings":";;;;;;;;;AAiCA,IAAM,gBAAA,GAAmB,2BAAA;AA+GlB,IAAM,MAAA,GAAS,CAAC,OAAA,KACrB,6BAAA,CAA8B;AAAA,EAC5B,IAAA,EAAM,QAAA;AAAA,EACN,KAAK,OAAA,EAAS,GAAA;AAAA,EACd,MAAA,EAAQ,OAAO,aAAA,KAAkD;AAC/D,IAAA,MAAM,kBAAA,GAAqB,SAAS,kBAAA,IAAsB,cAAA;AAE1D,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,OAAO,iBAAi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Vercel isolated sandbox provider — wraps `@vercel/sandbox` into a SandboxProvider.\n *\n * Usage:\n * import { vercel } from \"@snappedly-tools/shipyard/sandboxes/vercel\";\n * await run({ agent: codex(CODEX_MODELS.routine), sandbox: vercel() });\n */\n\nimport { execFileSync } from \"node:child_process\";\nimport {\n lstat,\n chmod,\n mkdir,\n mkdtemp,\n readFile,\n rm,\n writeFile,\n} from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { Writable } from \"node:stream\";\nimport {\n createIsolatedSandboxProvider,\n type ExecResult,\n type IsolatedSandboxHandle,\n type IsolatedSandboxProvider,\n} from \"../SandboxProvider.js\";\nimport { MAX_TAIL_CHARS } from \"../boundedTail.js\";\nimport { StreamedProcessOutput } from \"../processOutput.js\";\nimport { shellQuote } from \"../shellQuote.js\";\n\n/** Worktree path inside the Vercel sandbox. */\nconst VERCEL_REPO_PATH = \"/vercel/sandbox/workspace\";\n\n/**\n * Options for creating a Vercel sandbox provider.\n *\n * All `@vercel/sandbox` `Sandbox.create()` options are accepted as pass-through,\n * plus Shipyard-specific options for auth and branch strategy.\n */\nexport interface VercelOptions {\n /**\n * Vercel access token.\n *\n * Falls back to the SDK's default auth behavior, which reads\n * `VERCEL_OIDC_TOKEN` (recommended for Vercel-hosted environments) or\n * `VERCEL_TOKEN` from the environment.\n */\n readonly token?: string;\n\n // ---- Pass-through @vercel/sandbox Sandbox.create() options ----\n\n /**\n * The source of the sandbox (git repo, tarball, or snapshot).\n * Omit to start an empty sandbox.\n */\n readonly source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n username?: string;\n password?: string;\n }\n | {\n type: \"tarball\";\n url: string;\n }\n | {\n type: \"snapshot\";\n snapshotId: string;\n };\n\n /** Array of port numbers to expose from the sandbox (up to 4). */\n readonly ports?: number[];\n\n /** Timeout in milliseconds before the sandbox auto-terminates. */\n readonly timeout?: number;\n\n /**\n * Resources to allocate to the sandbox.\n * Each vCPU gets 2048 MB of memory.\n */\n readonly resources?: {\n vcpus: number;\n };\n\n /**\n * The runtime of the sandbox (e.g. `\"node24\"`, `\"node22\"`, `\"python3.13\"`).\n * Defaults to `\"node24\"`.\n */\n readonly runtime?: string;\n\n /**\n * Network policy for the sandbox.\n * Defaults to full internet access if not specified.\n */\n readonly networkPolicy?: Record<string, unknown>;\n\n /**\n * Vercel project ID to associate sandbox operations with.\n */\n readonly projectId?: string;\n\n /**\n * Vercel team ID to associate sandbox operations with.\n */\n readonly teamId?: string;\n\n /**\n * Timeout in milliseconds (alias for `timeout`, kept for discoverability).\n */\n readonly timeoutMs?: number;\n\n /**\n * Sandbox template shorthand (e.g. `\"node-22\"`).\n * Maps to the `runtime` option.\n */\n readonly template?: string;\n\n /** Environment variables injected by this provider. Merged at launch time with env resolver and agent provider env. */\n readonly env?: Record<string, string>;\n\n /**\n * Maximum number of characters of streamed `exec` output retained per stream\n * (stdout and stderr) when an `onLine` callback is supplied (default: 64KiB).\n *\n * Output is delivered live to `onLine` regardless; this only bounds the tail\n * returned in `ExecResult`, preventing a long-running agent's output from\n * overflowing V8's max string length and crashing the run.\n */\n readonly maxOutputTailChars?: number;\n}\n\n/**\n * Create a Vercel isolated sandbox provider.\n *\n * The returned provider creates Vercel Firecracker microVM sandboxes via\n * the `@vercel/sandbox` SDK. Each sandbox is ephemeral — one sandbox per run.\n *\n * Requires `@vercel/sandbox` to be installed as a peer dependency.\n */\nexport const vercel = (options?: VercelOptions): IsolatedSandboxProvider =>\n createIsolatedSandboxProvider({\n name: \"vercel\",\n env: options?.env,\n create: async (createOptions): Promise<IsolatedSandboxHandle> => {\n const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;\n // Dynamic import so the peer dependency is only loaded at runtime\n const { Sandbox } = await import(\"@vercel/sandbox\");\n\n const createParams: Record<string, unknown> = {};\n\n // Pass through SDK options\n if (options?.source) createParams.source = options.source;\n if (options?.ports) createParams.ports = options.ports;\n if (options?.resources) createParams.resources = options.resources;\n if (options?.networkPolicy)\n createParams.networkPolicy = options.networkPolicy;\n // runtime takes precedence over the template convenience alias\n const resolvedRuntime = options?.runtime ?? options?.template;\n if (resolvedRuntime) createParams.runtime = resolvedRuntime;\n\n // Timeout: prefer explicit timeout, fall back to timeoutMs alias\n const timeoutValue = options?.timeout ?? options?.timeoutMs;\n if (timeoutValue !== undefined) createParams.timeout = timeoutValue;\n\n // Merge provider env with Shipyard env\n createParams.env = createOptions.env;\n\n // Auth: pass token and team/project IDs if provided\n if (options?.token) createParams.token = options.token;\n if (options?.projectId) createParams.projectId = options.projectId;\n if (options?.teamId) createParams.teamId = options.teamId;\n\n const sandbox = await Sandbox.create(\n createParams as Parameters<typeof Sandbox.create>[0],\n );\n\n // Ensure worktree directory exists\n await sandbox.mkDir(VERCEL_REPO_PATH);\n\n const handle: IsolatedSandboxHandle = {\n worktreePath: VERCEL_REPO_PATH,\n\n exec: async (\n command: string,\n opts?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n maxOutputBytes?: number;\n },\n ): Promise<ExecResult> => {\n if (opts?.onLine || opts?.maxOutputBytes !== undefined) {\n const output = new StreamedProcessOutput({\n ...opts,\n maxOutputTailChars,\n });\n let partial = \"\";\n\n const stdoutWritable = new Writable({\n write(chunk, _encoding, callback) {\n const error = output.checkLimit(chunk.toString());\n if (error !== undefined) {\n callback(error);\n return;\n }\n const text = partial + chunk.toString();\n const lines = text.split(\"\\n\");\n partial = lines.pop() ?? \"\";\n for (const line of lines) {\n output.addStdoutLine(line);\n }\n callback();\n },\n final(callback) {\n if (partial) {\n output.addStdoutLine(partial);\n partial = \"\";\n }\n callback();\n },\n });\n\n const stderrWritable = new Writable({\n write(chunk, _encoding, callback) {\n const error = output.checkLimit(chunk.toString());\n if (error !== undefined) {\n callback(error);\n return;\n }\n output.addStderr(chunk.toString());\n callback();\n },\n });\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n stdout: stdoutWritable,\n stderr: stderrWritable,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n if (output.error !== undefined) throw output.error;\n return output.result(result.exitCode);\n }\n\n const result = await sandbox.runCommand({\n cmd: \"sh\",\n args: [\"-c\", command],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n ...(opts?.sudo ? { sudo: true } : {}),\n });\n\n const stdout = await result.stdout();\n const stderr = await result.stderr();\n\n return {\n stdout,\n stderr,\n exitCode: result.exitCode,\n };\n },\n\n copyIn: async (\n hostPath: string,\n sandboxPath: string,\n ): Promise<void> => {\n const info = await lstat(hostPath);\n if (info.isSymbolicLink()) {\n throw new Error(`Refusing to copy a symbolic link: ${hostPath}`);\n }\n if (info.isDirectory()) {\n const tempDir = await mkdtemp(join(tmpdir(), \"shipyard-copyin-\"));\n const tarPath = join(tempDir, \"archive.tar.gz\");\n try {\n execFileSync(\"tar\", [\"-czf\", tarPath, \"-C\", hostPath, \".\"]);\n const tarContent = await readFile(tarPath);\n const sandboxTarPath = `/tmp/shipyard-copyin-${randomUUID()}.tar.gz`;\n await sandbox.writeFiles([\n { path: sandboxTarPath, content: tarContent },\n ]);\n await sandbox.runCommand({\n cmd: \"sh\",\n args: [\n \"-c\",\n `mkdir -p ${shellQuote(sandboxPath)} && tar -xzf ${shellQuote(sandboxTarPath)} -C ${shellQuote(sandboxPath)} && rm -f ${shellQuote(sandboxTarPath)}`,\n ],\n });\n } finally {\n await rm(tempDir, { recursive: true, force: true }).catch(\n () => {},\n );\n }\n } else {\n const content = await readFile(hostPath);\n await sandbox.writeFiles([{ path: sandboxPath, content }]);\n }\n },\n\n copyFileOut: async (\n sandboxPath: string,\n hostPath: string,\n ): Promise<void> => {\n const buffer = await sandbox.readFileToBuffer({\n path: sandboxPath,\n });\n if (!buffer) {\n throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);\n }\n await mkdir(dirname(hostPath), { recursive: true, mode: 0o700 });\n try {\n if ((await lstat(hostPath)).isSymbolicLink()) {\n throw new Error(\n `Refusing to overwrite symbolic link: ${hostPath}`,\n );\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n }\n await writeFile(hostPath, buffer, { mode: 0o600 });\n await chmod(hostPath, 0o600);\n },\n\n close: async (): Promise<void> => {\n await sandbox.stop();\n },\n };\n\n return handle;\n },\n });\n"]}
@@ -6,7 +6,8 @@
6
6
  // with their target branch names.
7
7
  // Phase 2 (Execute): N routine Codex agents run in parallel via Promise.allSettled,
8
8
  // each working a single issue on its own branch.
9
- // Phase 3 (Merge): A strong Codex agent merges all branches that produced commits.
9
+ // Phase 3 (Merge): A strong Codex agent merges all branches whose agents
10
+ // completed, including branches with work from an earlier run.
10
11
  //
11
12
  // The outer loop repeats up to MAX_ITERATIONS times so that newly unblocked
12
13
  // issues are picked up after each round of merges.
@@ -141,8 +142,9 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
141
142
  }
142
143
  }
143
144
 
144
- // Only pass branches that actually produced commits to the merge phase.
145
- // An agent that ran successfully but made no commits has nothing to merge.
145
+ // A run's commits are limited to changes made during that run. A deterministic
146
+ // branch can already contain the implementation from an earlier run, so an
147
+ // explicit completion signal must also make the branch eligible for merge.
146
148
  const completedIssues = settled
147
149
  .map((outcome, i) => ({ outcome, issue: issues[i]! }))
148
150
  .filter(
@@ -155,23 +157,24 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
155
157
  issue: (typeof issues)[number];
156
158
  } =>
157
159
  entry.outcome.status === "fulfilled" &&
158
- entry.outcome.value.commits.length > 0,
160
+ (entry.outcome.value.commits.length > 0 ||
161
+ entry.outcome.value.completionSignal !== undefined),
159
162
  )
160
163
  .map((entry) => entry.issue);
161
164
 
162
165
  const completedBranches = completedIssues.map((i) => i.branch);
163
166
 
164
167
  console.log(
165
- `\nExecution complete. ${completedBranches.length} branch(es) with commits:`,
168
+ `\nExecution complete. ${completedBranches.length} completed branch(es):`,
166
169
  );
167
170
  for (const branch of completedBranches) {
168
171
  console.log(` ${branch}`);
169
172
  }
170
173
 
171
174
  if (completedBranches.length === 0) {
172
- // All agents ran but none made commits — nothing to merge this cycle.
173
- console.log("No commits produced. Nothing to merge.");
174
- continue;
175
+ // No agent completed and retrying the same plan would repeat unchanged work.
176
+ console.log("No implementations completed. Stopping.");
177
+ break;
175
178
  }
176
179
 
177
180
  // -------------------------------------------------------------------------
@@ -6,10 +6,12 @@
6
6
  // listing unblocked issues with branch names.
7
7
  // Phase 2 (Execute + Review): For each issue, a sandbox is created via
8
8
  // createSandbox(). The implementer runs first
9
- // (100 iterations). If it produces commits, a
10
- // reviewer runs in the same sandbox on the same
11
- // branch (1 iteration). All issue pipelines run
12
- // concurrently via Promise.allSettled().
9
+ // (100 iterations). If it completes, a reviewer
10
+ // runs in the same sandbox on the same branch
11
+ // (1 iteration). All issue pipelines run
12
+ // concurrently via Promise.allSettled(). A completion
13
+ // signal also qualifies a branch whose work predates
14
+ // the current run.
13
15
  // Phase 3 (Merge): A strong Codex agent merges all completed
14
16
  // branches into the current branch.
15
17
  //
@@ -135,8 +137,12 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
135
137
  },
136
138
  });
137
139
 
138
- // Only review if the implementer produced commits
139
- if (implement.commits.length > 0) {
140
+ // Review new work and deterministic branches that completed with work
141
+ // from an earlier run but produced no new commit this time.
142
+ if (
143
+ implement.commits.length > 0 ||
144
+ implement.completionSignal !== undefined
145
+ ) {
140
146
  const review = await sandbox.run({
141
147
  name: "reviewer",
142
148
  maxIterations: 1,
@@ -152,6 +158,8 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
152
158
  return {
153
159
  ...review,
154
160
  commits: [...implement.commits, ...review.commits],
161
+ completionSignal:
162
+ review.completionSignal ?? implement.completionSignal,
155
163
  };
156
164
  }
157
165
 
@@ -171,30 +179,32 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
171
179
  }
172
180
  }
173
181
 
174
- // Only pass branches that actually produced commits to the merge phase.
175
- // An agent that ran successfully but made no commits has nothing to merge.
182
+ // A run's commits are limited to changes made during that run. A deterministic
183
+ // branch can already contain the implementation from an earlier run, so an
184
+ // explicit completion signal must also make the branch eligible for merge.
176
185
  const completedIssues = settled
177
186
  .map((outcome, i) => ({ outcome, issue: issues[i]! }))
178
187
  .filter(
179
188
  (entry) =>
180
189
  entry.outcome.status === "fulfilled" &&
181
- entry.outcome.value.commits.length > 0,
190
+ (entry.outcome.value.commits.length > 0 ||
191
+ entry.outcome.value.completionSignal !== undefined),
182
192
  )
183
193
  .map((entry) => entry.issue);
184
194
 
185
195
  const completedBranches = completedIssues.map((i) => i.branch);
186
196
 
187
197
  console.log(
188
- `\nExecution complete. ${completedBranches.length} branch(es) with commits:`,
198
+ `\nExecution complete. ${completedBranches.length} completed branch(es):`,
189
199
  );
190
200
  for (const branch of completedBranches) {
191
201
  console.log(` ${branch}`);
192
202
  }
193
203
 
194
204
  if (completedBranches.length === 0) {
195
- // All agents ran but none made commits — nothing to merge this cycle.
196
- console.log("No commits produced. Nothing to merge.");
197
- continue;
205
+ // No agent completed and retrying the same plan would repeat unchanged work.
206
+ console.log("No implementations completed. Stopping.");
207
+ break;
198
208
  }
199
209
 
200
210
  // -------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snappedly-tools/shipyard",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Run AI coding agents in isolated sandboxes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -76,7 +76,8 @@
76
76
  "prettier": "~3.8.1",
77
77
  "tsup": "^8.5.1",
78
78
  "typescript": "^6.0.3",
79
- "vitest": "^5.0.1"
79
+ "vitest": "^5.0.1",
80
+ "yaml": "^2.9.1"
80
81
  },
81
82
  "dependencies": {
82
83
  "@clack/prompts": "^1.8.1",