@ai-hero/sandcastle 0.12.0 → 0.13.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.
- package/README.md +15 -1368
- package/dist/LinuxCapability-B_PQfsY_.d.ts +32 -0
- package/dist/{SandboxProvider-EkSMuBp8.d.ts → SandboxProvider-YCL97qco.d.ts} +30 -3
- package/dist/chunk-4EIVTSOZ.js +93 -0
- package/dist/chunk-4EIVTSOZ.js.map +1 -0
- package/dist/{chunk-NGBM7T3E.js → chunk-6NQPCXSG.js} +5 -2
- package/dist/chunk-6NQPCXSG.js.map +1 -0
- package/dist/chunk-767EAJVT.js +112 -0
- package/dist/chunk-767EAJVT.js.map +1 -0
- package/dist/chunk-7N7AMUYA.js +353 -0
- package/dist/chunk-7N7AMUYA.js.map +1 -0
- package/dist/{chunk-DJRHWPEH.js → chunk-A4C2FG74.js} +258 -327
- package/dist/chunk-A4C2FG74.js.map +1 -0
- package/dist/chunk-J5J5YJ5S.js +50 -0
- package/dist/chunk-J5J5YJ5S.js.map +1 -0
- package/dist/{chunk-VOG34SRF.js → chunk-LWNC4UTZ.js} +13702 -4881
- package/dist/chunk-LWNC4UTZ.js.map +1 -0
- package/dist/chunk-NMQ5Z6YG.js +148 -0
- package/dist/chunk-NMQ5Z6YG.js.map +1 -0
- package/dist/{chunk-CP3TYXZA.js → chunk-U42XXICG.js} +92 -85
- package/dist/chunk-U42XXICG.js.map +1 -0
- package/dist/chunk-XCWKLDH4.js +24 -0
- package/dist/chunk-XCWKLDH4.js.map +1 -0
- package/dist/{chunk-BIWNFKGV.js → chunk-XCYK7I45.js} +2 -2
- package/dist/chunk-XCYK7I45.js.map +1 -0
- package/dist/index.d.ts +237 -26
- package/dist/index.js +2789 -2169
- package/dist/index.js.map +1 -1
- package/dist/main.js +1004 -625
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +58 -0
- package/dist/sandboxes/bwrap.js +293 -0
- package/dist/sandboxes/bwrap.js.map +1 -0
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +78 -17
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +18 -4
- package/dist/sandboxes/docker.js +4 -4
- package/dist/sandboxes/no-sandbox.d.ts +1 -1
- package/dist/sandboxes/no-sandbox.js +2 -2
- package/dist/sandboxes/podman.d.ts +18 -4
- package/dist/sandboxes/podman.js +69 -56
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +65 -0
- package/dist/sandboxes/seatbelt.js +422 -0
- package/dist/sandboxes/seatbelt.js.map +1 -0
- package/dist/sandboxes/vercel.d.ts +12 -5
- package/dist/sandboxes/vercel.js +195 -126
- package/dist/sandboxes/vercel.js.map +1 -1
- package/dist/templates/parallel-planner/main.mts +13 -22
- package/dist/templates/parallel-planner-with-review/main.mts +13 -15
- package/package.json +34 -10
- package/dist/chunk-62WN33RK.js +0 -104
- package/dist/chunk-62WN33RK.js.map +0 -1
- package/dist/chunk-BIWNFKGV.js.map +0 -1
- package/dist/chunk-CP3TYXZA.js.map +0 -1
- package/dist/chunk-DJRHWPEH.js.map +0 -1
- package/dist/chunk-NGBM7T3E.js.map +0 -1
- package/dist/chunk-VOG34SRF.js.map +0 -1
- package/dist/mountUtils-CCA-bbpK.d.ts +0 -25
package/dist/sandboxes/vercel.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { createIsolatedSandboxProvider } from '../chunk-
|
|
3
|
-
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-
|
|
2
|
+
import { createIsolatedSandboxProvider } from '../chunk-XCYK7I45.js';
|
|
3
|
+
import { MAX_TAIL_CHARS, BoundedTail } from '../chunk-6NQPCXSG.js';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
|
+
import { randomUUID } from 'crypto';
|
|
5
6
|
import { mkdir, writeFile, stat, readFile, unlink } from 'fs/promises';
|
|
6
7
|
import { tmpdir } from 'os';
|
|
7
8
|
import { dirname, join } from 'path';
|
|
@@ -9,137 +10,205 @@ import { Writable } from 'stream';
|
|
|
9
10
|
|
|
10
11
|
createRequire(import.meta.url);
|
|
11
12
|
var VERCEL_REPO_PATH = "/vercel/sandbox/workspace";
|
|
13
|
+
var setOrUndefined = (value) => value === "" ? void 0 : value;
|
|
14
|
+
var resolveVercelAuth = (options) => {
|
|
15
|
+
const { env } = process;
|
|
16
|
+
const tokenOption = setOrUndefined(options?.token);
|
|
17
|
+
const teamIdOption = setOrUndefined(options?.teamId);
|
|
18
|
+
const projectIdOption = setOrUndefined(options?.projectId);
|
|
19
|
+
const token = tokenOption ?? setOrUndefined(env.VERCEL_TOKEN);
|
|
20
|
+
if (token === void 0) {
|
|
21
|
+
return {
|
|
22
|
+
...teamIdOption === void 0 ? {} : { teamId: teamIdOption },
|
|
23
|
+
...projectIdOption === void 0 ? {} : { projectId: projectIdOption }
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const teamId = teamIdOption ?? setOrUndefined(env.VERCEL_TEAM_ID);
|
|
27
|
+
const projectId = projectIdOption ?? setOrUndefined(env.VERCEL_PROJECT_ID);
|
|
28
|
+
const missing = [
|
|
29
|
+
teamId === void 0 ? "VERCEL_TEAM_ID (or the teamId option)" : null,
|
|
30
|
+
projectId === void 0 ? "VERCEL_PROJECT_ID (or the projectId option)" : null
|
|
31
|
+
].filter((name) => name !== null);
|
|
32
|
+
if (missing.length > 0) {
|
|
33
|
+
const source = tokenOption === void 0 ? "VERCEL_TOKEN" : "the token option";
|
|
34
|
+
throw new Error(
|
|
35
|
+
`vercel(): ${source} is set, but a Vercel token also needs a team and project id. Missing: ${missing.join(", ")}.`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return { token, teamId, projectId };
|
|
39
|
+
};
|
|
40
|
+
var setUpOrStop = async (sandbox, setUp) => {
|
|
41
|
+
try {
|
|
42
|
+
await setUp();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
try {
|
|
45
|
+
await sandbox.stop();
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var toCreateParams = (options, env) => {
|
|
52
|
+
const o = options ?? {};
|
|
53
|
+
const passThrough = {
|
|
54
|
+
source: o.source,
|
|
55
|
+
ports: o.ports,
|
|
56
|
+
resources: o.resources,
|
|
57
|
+
networkPolicy: o.networkPolicy,
|
|
58
|
+
// runtime takes precedence over the template convenience alias
|
|
59
|
+
runtime: o.runtime ?? o.template,
|
|
60
|
+
// prefer explicit timeout, fall back to the timeoutMs alias
|
|
61
|
+
timeout: o.timeout ?? o.timeoutMs
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
// An unset option (or an empty runtime) is left out for the SDK default.
|
|
65
|
+
...Object.fromEntries(
|
|
66
|
+
Object.entries(passThrough).filter(
|
|
67
|
+
([, value]) => value !== void 0 && value !== ""
|
|
68
|
+
)
|
|
69
|
+
),
|
|
70
|
+
env,
|
|
71
|
+
...resolveVercelAuth(options)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
var withStdin = async (sandbox, command, stdin) => {
|
|
75
|
+
if (stdin === void 0) {
|
|
76
|
+
return command;
|
|
77
|
+
}
|
|
78
|
+
const stdinPath = `/tmp/sandcastle-stdin-${randomUUID()}`;
|
|
79
|
+
await sandbox.writeFiles([{ path: stdinPath, content: Buffer.from(stdin) }]);
|
|
80
|
+
return `{ rm -f ${stdinPath}; ${command}
|
|
81
|
+
} < ${stdinPath}`;
|
|
82
|
+
};
|
|
83
|
+
var lineWritable = (onLine, tail) => {
|
|
84
|
+
let partial = "";
|
|
85
|
+
return new Writable({
|
|
86
|
+
write(chunk, _encoding, callback) {
|
|
87
|
+
const text = partial + chunk.toString();
|
|
88
|
+
const lines = text.split("\n");
|
|
89
|
+
partial = lines.pop() ?? "";
|
|
90
|
+
for (const line of lines) {
|
|
91
|
+
tail.push(line);
|
|
92
|
+
onLine(line);
|
|
93
|
+
}
|
|
94
|
+
callback();
|
|
95
|
+
},
|
|
96
|
+
final(callback) {
|
|
97
|
+
if (partial) {
|
|
98
|
+
tail.push(partial);
|
|
99
|
+
onLine(partial);
|
|
100
|
+
partial = "";
|
|
101
|
+
}
|
|
102
|
+
callback();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
var tailWritable = (tail) => new Writable({
|
|
107
|
+
write(chunk, _encoding, callback) {
|
|
108
|
+
tail.push(chunk.toString());
|
|
109
|
+
callback();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
var execStreamed = async (sandbox, params, {
|
|
113
|
+
onLine,
|
|
114
|
+
maxOutputTailChars
|
|
115
|
+
}) => {
|
|
116
|
+
const stdoutTail = new BoundedTail(maxOutputTailChars, "\n");
|
|
117
|
+
const stderrTail = new BoundedTail(maxOutputTailChars, "");
|
|
118
|
+
const result = await sandbox.runCommand({
|
|
119
|
+
...params,
|
|
120
|
+
stdout: lineWritable(onLine, stdoutTail),
|
|
121
|
+
stderr: tailWritable(stderrTail)
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
stdout: stdoutTail.toString(),
|
|
125
|
+
stderr: stderrTail.toString(),
|
|
126
|
+
exitCode: result.exitCode
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var execBuffered = async (sandbox, params) => {
|
|
130
|
+
const result = await sandbox.runCommand(params);
|
|
131
|
+
const stdout = await result.stdout();
|
|
132
|
+
const stderr = await result.stderr();
|
|
133
|
+
return { stdout, stderr, exitCode: result.exitCode };
|
|
134
|
+
};
|
|
135
|
+
var copyDirIn = async (sandbox, hostPath, sandboxPath) => {
|
|
136
|
+
const tarPath = join(tmpdir(), `sandcastle-copyin-${Date.now()}.tar.gz`);
|
|
137
|
+
execSync(`tar -czf "${tarPath}" -C "${hostPath}" .`);
|
|
138
|
+
try {
|
|
139
|
+
const tarContent = await readFile(tarPath);
|
|
140
|
+
const sandboxTarPath = `/tmp/sandcastle-copyin-${Date.now()}.tar.gz`;
|
|
141
|
+
await sandbox.writeFiles([{ path: sandboxTarPath, content: tarContent }]);
|
|
142
|
+
await sandbox.runCommand({
|
|
143
|
+
cmd: "sh",
|
|
144
|
+
args: [
|
|
145
|
+
"-c",
|
|
146
|
+
`mkdir -p "${sandboxPath}" && tar -xzf "${sandboxTarPath}" -C "${sandboxPath}" && rm -f "${sandboxTarPath}"`
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
} finally {
|
|
150
|
+
await unlink(tarPath).catch(() => void 0);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var makeWorktreeDir = async (sandbox) => {
|
|
154
|
+
const mkdirResult = await sandbox.runCommand({
|
|
155
|
+
cmd: "mkdir",
|
|
156
|
+
args: ["-p", VERCEL_REPO_PATH]
|
|
157
|
+
});
|
|
158
|
+
if (mkdirResult.exitCode !== 0) {
|
|
159
|
+
const stderr = await mkdirResult.stderr();
|
|
160
|
+
throw new Error(
|
|
161
|
+
`vercel(): could not create ${VERCEL_REPO_PATH}: ${stderr.trim()}`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var makeHandle = (sandbox, maxOutputTailChars) => ({
|
|
166
|
+
worktreePath: VERCEL_REPO_PATH,
|
|
167
|
+
// `@vercel/sandbox` 2 renamed the sandbox's id from `sandboxId` to `name`.
|
|
168
|
+
sandboxId: sandbox.name ?? sandbox.sandboxId,
|
|
169
|
+
exec: async (command, opts) => {
|
|
170
|
+
const params = {
|
|
171
|
+
cmd: "sh",
|
|
172
|
+
args: ["-c", await withStdin(sandbox, command, opts?.stdin)],
|
|
173
|
+
cwd: opts?.cwd ?? VERCEL_REPO_PATH,
|
|
174
|
+
...opts?.sudo === true ? { sudo: true } : {}
|
|
175
|
+
};
|
|
176
|
+
return opts?.onLine ? execStreamed(sandbox, params, {
|
|
177
|
+
onLine: opts.onLine,
|
|
178
|
+
maxOutputTailChars
|
|
179
|
+
}) : execBuffered(sandbox, params);
|
|
180
|
+
},
|
|
181
|
+
copyIn: async (hostPath, sandboxPath) => {
|
|
182
|
+
const info = await stat(hostPath);
|
|
183
|
+
if (info.isDirectory()) {
|
|
184
|
+
await copyDirIn(sandbox, hostPath, sandboxPath);
|
|
185
|
+
} else {
|
|
186
|
+
const content = await readFile(hostPath);
|
|
187
|
+
await sandbox.writeFiles([{ path: sandboxPath, content }]);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
copyFileOut: async (sandboxPath, hostPath) => {
|
|
191
|
+
const buffer = await sandbox.readFileToBuffer({ path: sandboxPath });
|
|
192
|
+
if (!buffer) {
|
|
193
|
+
throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);
|
|
194
|
+
}
|
|
195
|
+
await mkdir(dirname(hostPath), { recursive: true });
|
|
196
|
+
await writeFile(hostPath, buffer);
|
|
197
|
+
},
|
|
198
|
+
close: async () => {
|
|
199
|
+
await sandbox.stop();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
12
202
|
var vercel = (options) => createIsolatedSandboxProvider({
|
|
13
203
|
name: "vercel",
|
|
14
204
|
env: options?.env,
|
|
15
205
|
create: async (createOptions) => {
|
|
16
|
-
const maxOutputTailChars = options?.maxOutputTailChars ?? MAX_TAIL_CHARS;
|
|
17
206
|
const { Sandbox } = await import('@vercel/sandbox');
|
|
18
|
-
const createParams = {};
|
|
19
|
-
if (options?.source) createParams.source = options.source;
|
|
20
|
-
if (options?.ports) createParams.ports = options.ports;
|
|
21
|
-
if (options?.resources) createParams.resources = options.resources;
|
|
22
|
-
if (options?.networkPolicy)
|
|
23
|
-
createParams.networkPolicy = options.networkPolicy;
|
|
24
|
-
const resolvedRuntime = options?.runtime ?? options?.template;
|
|
25
|
-
if (resolvedRuntime) createParams.runtime = resolvedRuntime;
|
|
26
|
-
const timeoutValue = options?.timeout ?? options?.timeoutMs;
|
|
27
|
-
if (timeoutValue !== void 0) createParams.timeout = timeoutValue;
|
|
28
|
-
createParams.env = createOptions.env;
|
|
29
|
-
if (options?.token) createParams.token = options.token;
|
|
30
|
-
if (options?.projectId) createParams.projectId = options.projectId;
|
|
31
|
-
if (options?.teamId) createParams.teamId = options.teamId;
|
|
32
207
|
const sandbox = await Sandbox.create(
|
|
33
|
-
|
|
208
|
+
toCreateParams(options, createOptions.env)
|
|
34
209
|
);
|
|
35
|
-
await sandbox
|
|
36
|
-
|
|
37
|
-
worktreePath: VERCEL_REPO_PATH,
|
|
38
|
-
exec: async (command, opts) => {
|
|
39
|
-
if (opts?.onLine) {
|
|
40
|
-
const onLine = opts.onLine;
|
|
41
|
-
const stdoutTail = new BoundedTail(maxOutputTailChars, "\n");
|
|
42
|
-
const stderrTail = new BoundedTail(maxOutputTailChars, "");
|
|
43
|
-
let partial = "";
|
|
44
|
-
const stdoutWritable = new Writable({
|
|
45
|
-
write(chunk, _encoding, callback) {
|
|
46
|
-
const text = partial + chunk.toString();
|
|
47
|
-
const lines = text.split("\n");
|
|
48
|
-
partial = lines.pop() ?? "";
|
|
49
|
-
for (const line of lines) {
|
|
50
|
-
stdoutTail.push(line);
|
|
51
|
-
onLine(line);
|
|
52
|
-
}
|
|
53
|
-
callback();
|
|
54
|
-
},
|
|
55
|
-
final(callback) {
|
|
56
|
-
if (partial) {
|
|
57
|
-
stdoutTail.push(partial);
|
|
58
|
-
onLine(partial);
|
|
59
|
-
partial = "";
|
|
60
|
-
}
|
|
61
|
-
callback();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const stderrWritable = new Writable({
|
|
65
|
-
write(chunk, _encoding, callback) {
|
|
66
|
-
stderrTail.push(chunk.toString());
|
|
67
|
-
callback();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const result2 = await sandbox.runCommand({
|
|
71
|
-
cmd: "sh",
|
|
72
|
-
args: ["-c", command],
|
|
73
|
-
cwd: opts?.cwd ?? VERCEL_REPO_PATH,
|
|
74
|
-
stdout: stdoutWritable,
|
|
75
|
-
stderr: stderrWritable,
|
|
76
|
-
...opts?.sudo ? { sudo: true } : {}
|
|
77
|
-
});
|
|
78
|
-
return {
|
|
79
|
-
stdout: stdoutTail.toString(),
|
|
80
|
-
stderr: stderrTail.toString(),
|
|
81
|
-
exitCode: result2.exitCode
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
const result = await sandbox.runCommand({
|
|
85
|
-
cmd: "sh",
|
|
86
|
-
args: ["-c", command],
|
|
87
|
-
cwd: opts?.cwd ?? VERCEL_REPO_PATH,
|
|
88
|
-
...opts?.sudo ? { sudo: true } : {}
|
|
89
|
-
});
|
|
90
|
-
const stdout = await result.stdout();
|
|
91
|
-
const stderr = await result.stderr();
|
|
92
|
-
return {
|
|
93
|
-
stdout,
|
|
94
|
-
stderr,
|
|
95
|
-
exitCode: result.exitCode
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
copyIn: async (hostPath, sandboxPath) => {
|
|
99
|
-
const info = await stat(hostPath);
|
|
100
|
-
if (info.isDirectory()) {
|
|
101
|
-
const tarPath = join(
|
|
102
|
-
tmpdir(),
|
|
103
|
-
`sandcastle-copyin-${Date.now()}.tar.gz`
|
|
104
|
-
);
|
|
105
|
-
execSync(`tar -czf "${tarPath}" -C "${hostPath}" .`);
|
|
106
|
-
try {
|
|
107
|
-
const tarContent = await readFile(tarPath);
|
|
108
|
-
const sandboxTarPath = `/tmp/sandcastle-copyin-${Date.now()}.tar.gz`;
|
|
109
|
-
await sandbox.writeFiles([
|
|
110
|
-
{ path: sandboxTarPath, content: tarContent }
|
|
111
|
-
]);
|
|
112
|
-
await sandbox.runCommand({
|
|
113
|
-
cmd: "sh",
|
|
114
|
-
args: [
|
|
115
|
-
"-c",
|
|
116
|
-
`mkdir -p "${sandboxPath}" && tar -xzf "${sandboxTarPath}" -C "${sandboxPath}" && rm -f "${sandboxTarPath}"`
|
|
117
|
-
]
|
|
118
|
-
});
|
|
119
|
-
} finally {
|
|
120
|
-
await unlink(tarPath).catch(() => {
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
const content = await readFile(hostPath);
|
|
125
|
-
await sandbox.writeFiles([{ path: sandboxPath, content }]);
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
copyFileOut: async (sandboxPath, hostPath) => {
|
|
129
|
-
const buffer = await sandbox.readFileToBuffer({
|
|
130
|
-
path: sandboxPath
|
|
131
|
-
});
|
|
132
|
-
if (!buffer) {
|
|
133
|
-
throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);
|
|
134
|
-
}
|
|
135
|
-
await mkdir(dirname(hostPath), { recursive: true });
|
|
136
|
-
await writeFile(hostPath, buffer);
|
|
137
|
-
},
|
|
138
|
-
close: async () => {
|
|
139
|
-
await sandbox.stop();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
return handle;
|
|
210
|
+
await setUpOrStop(sandbox, async () => makeWorktreeDir(sandbox));
|
|
211
|
+
return makeHandle(sandbox, options?.maxOutputTailChars ?? MAX_TAIL_CHARS);
|
|
143
212
|
}
|
|
144
213
|
});
|
|
145
214
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sandboxes/vercel.ts"],"names":["result"],"mappings":";;;;;;;;;;AAsBA,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,MA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,CAAA;AAClD,QAAA,MAAM,SAAA,CAAU,UAAU,MAAM,CAAA;AAAA,MAClC,CAAA;AAAA,MAEA,OAAO,YAA2B;AAChC,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 \"sandcastle/sandboxes/vercel\";\n * await run({ agent: claudeCode(\"claude-opus-4-8\"), sandbox: vercel() });\n */\n\nimport { execSync } from \"node:child_process\";\nimport { readFile, unlink, writeFile, mkdir, stat } from \"node:fs/promises\";\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 { BoundedTail, MAX_TAIL_CHARS } from \"../boundedTail.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 Sandcastle-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 Sandcastle 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 },\n ): Promise<ExecResult> => {\n if (opts?.onLine) {\n const onLine = opts.onLine;\n const stdoutTail = new BoundedTail(maxOutputTailChars, \"\\n\");\n const stderrTail = new BoundedTail(maxOutputTailChars, \"\");\n let partial = \"\";\n\n const stdoutWritable = new Writable({\n write(chunk, _encoding, callback) {\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 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 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 stat(hostPath);\n if (info.isDirectory()) {\n const tarPath = join(\n tmpdir(),\n `sandcastle-copyin-${Date.now()}.tar.gz`,\n );\n execSync(`tar -czf \"${tarPath}\" -C \"${hostPath}\" .`);\n try {\n const tarContent = await readFile(tarPath);\n const sandboxTarPath = `/tmp/sandcastle-copyin-${Date.now()}.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 \"${sandboxPath}\" && tar -xzf \"${sandboxTarPath}\" -C \"${sandboxPath}\" && rm -f \"${sandboxTarPath}\"`,\n ],\n });\n } finally {\n await unlink(tarPath).catch(() => {});\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 });\n await writeFile(hostPath, buffer);\n },\n\n close: async (): Promise<void> => {\n await sandbox.stop();\n },\n };\n\n return handle;\n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CAAC,CAAA;AAAA,IAC3D;AAAA,EACF,CAAA;AAAA,EAEA,WAAA,EAAa,OAAO,WAAA,EAAa,QAAA,KAA4B;AAC3D,IAAA,MAAM,SAAS,MAAM,OAAA,CAAQ,iBAAiB,EAAE,IAAA,EAAM,aAAa,CAAA;AACnE,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,kCAAA,EAAqC,WAAW,CAAA,CAAE,CAAA;AAAA,IACpE;AACA,IAAA,MAAM,MAAM,OAAA,CAAQ,QAAQ,GAAG,EAAE,SAAA,EAAW,MAAM,CAAA;AAClD,IAAA,MAAM,SAAA,CAAU,UAAU,MAAM,CAAA;AAAA,EAClC,CAAA;AAAA,EAEA,OAAO,YAA2B;AAChC,IAAA,MAAM,QAAQ,IAAA,EAAK;AAAA,EACrB;AACF,CAAA,CAAA;AAUO,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;AAE/D,IAAA,MAAM,EAAE,OAAA,EAAQ,GAAI,MAAM,OAAO,iBAAiB,CAAA;AAClD,IAAA,MAAM,OAAA,GAAU,MAAM,OAAA,CAAQ,MAAA;AAAA,MAC5B,cAAA,CAAe,OAAA,EAAS,aAAA,CAAc,GAAG;AAAA,KAC3C;AACA,IAAA,MAAM,WAAA,CAAY,OAAA,EAAS,YAAY,eAAA,CAAgB,OAAO,CAAC,CAAA;AAC/D,IAAA,OAAO,UAAA,CAAW,OAAA,EAAS,OAAA,EAAS,kBAAA,IAAsB,cAAc,CAAA;AAAA,EAC1E;AACF,CAAC","file":"vercel.js","sourcesContent":["/**\n * Vercel isolated sandbox provider — wraps `@vercel/sandbox` into a SandboxProvider.\n *\n * Usage:\n * import { vercel } from \"sandcastle/sandboxes/vercel\";\n * await run({ agent: claudeCode(\"claude-opus-4-8\"), sandbox: vercel() });\n */\n\nimport { execSync } from \"node:child_process\";\nimport { randomUUID } from \"node:crypto\";\nimport { readFile, unlink, writeFile, mkdir, stat } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { Writable } from \"node:stream\";\nimport { createIsolatedSandboxProvider } from \"../SandboxProvider.js\";\nimport type {\n ExecResult,\n IsolatedSandboxHandle,\n IsolatedSandboxProvider,\n} from \"../SandboxProvider.js\";\nimport type { SandboxInstance } from \"@vercel/sandbox\";\nimport { BoundedTail, MAX_TAIL_CHARS } from \"../boundedTail.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 Sandcastle-specific options for auth and branch strategy.\n */\nexport interface VercelOptions {\n /**\n * Vercel access token.\n *\n * Falls back to the `VERCEL_TOKEN` environment variable. A token needs a\n * team and project id too (`teamId`/`VERCEL_TEAM_ID`,\n * `projectId`/`VERCEL_PROJECT_ID`). With no token at all, the SDK's OIDC\n * auth applies, which reads `VERCEL_OIDC_TOKEN`.\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 *\n * Omit it to get Vercel's default image (`vercel/sandbox/universal` as of\n * `@vercel/sandbox` 3.x), which ships coding agent CLIs such as `claude`.\n * The named runtimes ship none: install your agent's CLI in an\n * `onSandboxReady` hook.\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 * Falls back to the `VERCEL_PROJECT_ID` environment variable when a token is used.\n */\n readonly projectId?: string;\n\n /**\n * Vercel team ID to associate sandbox operations with.\n * Falls back to the `VERCEL_TEAM_ID` environment variable when a token is used.\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/** An option or env var counts as unset when it is missing or empty. */\nconst setOrUndefined = (value: string | undefined): string | undefined =>\n value === \"\" ? undefined : value;\n\n/**\n * Resolve the auth params for `Sandbox.create()`.\n *\n * `@vercel/sandbox` only accepts a token as an explicit param, together with\n * `teamId` and `projectId` (all three or none); otherwise it falls back to\n * OIDC. So read `VERCEL_TOKEN`, `VERCEL_TEAM_ID` and `VERCEL_PROJECT_ID`\n * here, explicit options first.\n */\nconst resolveVercelAuth = (\n options: VercelOptions | undefined,\n): { token?: string; teamId?: string; projectId?: string } => {\n const { env } = process;\n const tokenOption = setOrUndefined(options?.token);\n const teamIdOption = setOrUndefined(options?.teamId);\n const projectIdOption = setOrUndefined(options?.projectId);\n const token = tokenOption ?? setOrUndefined(env.VERCEL_TOKEN);\n\n if (token === undefined) {\n // No token: the SDK's OIDC flow, which may use team/project ids as hints.\n return {\n ...(teamIdOption === undefined ? {} : { teamId: teamIdOption }),\n ...(projectIdOption === undefined ? {} : { projectId: projectIdOption }),\n };\n }\n\n const teamId = teamIdOption ?? setOrUndefined(env.VERCEL_TEAM_ID);\n const projectId = projectIdOption ?? setOrUndefined(env.VERCEL_PROJECT_ID);\n const missing = [\n teamId === undefined ? \"VERCEL_TEAM_ID (or the teamId option)\" : null,\n projectId === undefined\n ? \"VERCEL_PROJECT_ID (or the projectId option)\"\n : null,\n ].filter((name): name is string => name !== null);\n\n if (missing.length > 0) {\n const source =\n tokenOption === undefined ? \"VERCEL_TOKEN\" : \"the token option\";\n throw new Error(\n `vercel(): ${source} is set, but a Vercel token also needs a team and project id. ` +\n `Missing: ${missing.join(\", \")}.`,\n );\n }\n\n return { token, teamId, projectId };\n};\n\n/**\n * Run the setup of a sandbox that `create()` has just made. If it fails, stop\n * the sandbox before rethrowing: no handle exists yet, so neither Sandcastle's\n * teardown nor `close()` can reach it, and it would run until Vercel's\n * timeout.\n */\nconst setUpOrStop = async (\n sandbox: { stop: () => Promise<unknown> },\n setUp: () => Promise<void>,\n): Promise<void> => {\n try {\n await setUp();\n } catch (error) {\n try {\n await sandbox.stop();\n } catch {\n // Report the setup error, which says why create() failed.\n }\n throw error;\n }\n};\n\n/** The `Sandbox.create` params: SDK pass-through options, env and auth. */\nconst toCreateParams = (\n options: VercelOptions | undefined,\n env: Record<string, string>,\n): Record<string, unknown> => {\n const o = options ?? {};\n const passThrough: Record<string, unknown> = {\n source: o.source,\n ports: o.ports,\n resources: o.resources,\n networkPolicy: o.networkPolicy,\n // runtime takes precedence over the template convenience alias\n runtime: o.runtime ?? o.template,\n // prefer explicit timeout, fall back to the timeoutMs alias\n timeout: o.timeout ?? o.timeoutMs,\n };\n return {\n // An unset option (or an empty runtime) is left out for the SDK default.\n ...Object.fromEntries(\n Object.entries(passThrough).filter(\n ([, value]) => value !== undefined && value !== \"\",\n ),\n ),\n env,\n ...resolveVercelAuth(options),\n };\n};\n\ntype RunCommandParams = Parameters<SandboxInstance[\"runCommand\"]>[0];\n\n/**\n * The command to run for `exec`. `runCommand` gives a command no stdin\n * unless it is detached: the command reads EOF. So write stdin to a file in\n * the sandbox and redirect it in (a file, not an argument, keeps clear of the\n * per-arg size limit). The redirect opens the file before the group runs, so\n * the group can delete it straight away and leave nothing behind.\n */\nconst withStdin = async (\n sandbox: SandboxInstance,\n command: string,\n stdin: string | undefined,\n): Promise<string> => {\n if (stdin === undefined) {\n return command;\n }\n const stdinPath = `/tmp/sandcastle-stdin-${randomUUID()}`;\n await sandbox.writeFiles([{ path: stdinPath, content: Buffer.from(stdin) }]);\n return `{ rm -f ${stdinPath}; ${command}\\n} < ${stdinPath}`;\n};\n\n/** A stream that hands each stdout line to `onLine` and keeps a bounded tail. */\nconst lineWritable = (\n onLine: (line: string) => void,\n tail: BoundedTail,\n): Writable => {\n let partial = \"\";\n return new Writable({\n write(chunk: Buffer, _encoding, callback) {\n const text = partial + chunk.toString();\n const lines = text.split(\"\\n\");\n partial = lines.pop() ?? \"\";\n for (const line of lines) {\n tail.push(line);\n onLine(line);\n }\n callback();\n },\n final(callback) {\n if (partial) {\n tail.push(partial);\n onLine(partial);\n partial = \"\";\n }\n callback();\n },\n });\n};\n\n/** A stream that only keeps a bounded tail of what is written to it. */\nconst tailWritable = (tail: BoundedTail): Writable =>\n new Writable({\n write(chunk: Buffer, _encoding, callback) {\n tail.push(chunk.toString());\n callback();\n },\n });\n\n/** Run a command, streaming stdout lines to `onLine`; returns bounded tails. */\nconst execStreamed = async (\n sandbox: SandboxInstance,\n params: RunCommandParams,\n {\n onLine,\n maxOutputTailChars,\n }: {\n readonly onLine: (line: string) => void;\n readonly maxOutputTailChars: number;\n },\n): Promise<ExecResult> => {\n const stdoutTail = new BoundedTail(maxOutputTailChars, \"\\n\");\n const stderrTail = new BoundedTail(maxOutputTailChars, \"\");\n const result = await sandbox.runCommand({\n ...params,\n stdout: lineWritable(onLine, stdoutTail),\n stderr: tailWritable(stderrTail),\n });\n return {\n stdout: stdoutTail.toString(),\n stderr: stderrTail.toString(),\n exitCode: result.exitCode,\n };\n};\n\n/** Run a command to completion and return its whole output. */\nconst execBuffered = async (\n sandbox: SandboxInstance,\n params: RunCommandParams,\n): Promise<ExecResult> => {\n const result = await sandbox.runCommand(params);\n const stdout = await result.stdout();\n const stderr = await result.stderr();\n return { stdout, stderr, exitCode: result.exitCode };\n};\n\n/** Copy a host directory in as a tarball, unpacked at `sandboxPath`. */\nconst copyDirIn = async (\n sandbox: SandboxInstance,\n hostPath: string,\n sandboxPath: string,\n): Promise<void> => {\n const tarPath = join(tmpdir(), `sandcastle-copyin-${Date.now()}.tar.gz`);\n execSync(`tar -czf \"${tarPath}\" -C \"${hostPath}\" .`);\n try {\n const tarContent = await readFile(tarPath);\n const sandboxTarPath = `/tmp/sandcastle-copyin-${Date.now()}.tar.gz`;\n await sandbox.writeFiles([{ path: sandboxTarPath, content: tarContent }]);\n await sandbox.runCommand({\n cmd: \"sh\",\n args: [\n \"-c\",\n `mkdir -p \"${sandboxPath}\" && tar -xzf \"${sandboxTarPath}\" -C \"${sandboxPath}\" && rm -f \"${sandboxTarPath}\"`,\n ],\n });\n } finally {\n await unlink(tarPath).catch(() => undefined);\n }\n};\n\n/**\n * Create the worktree folder with its parents: Vercel's default image has no\n * /vercel/sandbox (its user's home is /vercel), and `mkDir` isn't recursive.\n */\nconst makeWorktreeDir = async (sandbox: SandboxInstance): Promise<void> => {\n const mkdirResult = await sandbox.runCommand({\n cmd: \"mkdir\",\n args: [\"-p\", VERCEL_REPO_PATH],\n });\n if (mkdirResult.exitCode !== 0) {\n const stderr = await mkdirResult.stderr();\n throw new Error(\n `vercel(): could not create ${VERCEL_REPO_PATH}: ${stderr.trim()}`,\n );\n }\n};\n\n/** The Sandcastle handle over a Vercel sandbox whose worktree folder exists. */\nconst makeHandle = (\n sandbox: SandboxInstance,\n maxOutputTailChars: number,\n): IsolatedSandboxHandle => ({\n worktreePath: VERCEL_REPO_PATH,\n // `@vercel/sandbox` 2 renamed the sandbox's id from `sandboxId` to `name`.\n sandboxId: sandbox.name ?? sandbox.sandboxId,\n\n exec: async (command, opts): Promise<ExecResult> => {\n const params: RunCommandParams = {\n cmd: \"sh\",\n args: [\"-c\", await withStdin(sandbox, command, opts?.stdin)],\n cwd: opts?.cwd ?? VERCEL_REPO_PATH,\n ...(opts?.sudo === true ? { sudo: true } : {}),\n };\n return opts?.onLine\n ? execStreamed(sandbox, params, {\n onLine: opts.onLine,\n maxOutputTailChars,\n })\n : execBuffered(sandbox, params);\n },\n\n copyIn: async (hostPath, sandboxPath): Promise<void> => {\n const info = await stat(hostPath);\n if (info.isDirectory()) {\n await copyDirIn(sandbox, hostPath, sandboxPath);\n } else {\n const content = await readFile(hostPath);\n await sandbox.writeFiles([{ path: sandboxPath, content }]);\n }\n },\n\n copyFileOut: async (sandboxPath, hostPath): Promise<void> => {\n const buffer = await sandbox.readFileToBuffer({ path: sandboxPath });\n if (!buffer) {\n throw new Error(`File not found in Vercel sandbox: ${sandboxPath}`);\n }\n await mkdir(dirname(hostPath), { recursive: true });\n await writeFile(hostPath, buffer);\n },\n\n close: async (): Promise<void> => {\n await sandbox.stop();\n },\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 // Dynamic import so the peer dependency is only loaded at runtime\n const { Sandbox } = await import(\"@vercel/sandbox\");\n const sandbox = await Sandbox.create(\n toCreateParams(options, createOptions.env),\n );\n await setUpOrStop(sandbox, async () => makeWorktreeDir(sandbox));\n return makeHandle(sandbox, options?.maxOutputTailChars ?? MAX_TAIL_CHARS);\n },\n });\n"]}
|
|
@@ -131,33 +131,24 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
|
|
|
131
131
|
),
|
|
132
132
|
);
|
|
133
133
|
|
|
134
|
-
// Log any agents that threw (network error, sandbox crash, etc.)
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
// Log any agents that threw (network error, sandbox crash, etc.), and
|
|
135
|
+
// only pass branches that actually produced commits to the merge phase.
|
|
136
|
+
// An agent that ran successfully but made no commits has nothing to merge.
|
|
137
|
+
const completedIssues: typeof issues = [];
|
|
138
|
+
for (const [i, issue] of issues.entries()) {
|
|
139
|
+
const outcome = settled[i];
|
|
140
|
+
if (outcome?.status === "rejected") {
|
|
137
141
|
console.error(
|
|
138
|
-
` ✗ ${
|
|
142
|
+
` ✗ ${issue.id} (${issue.branch}) failed: ${outcome.reason}`,
|
|
139
143
|
);
|
|
144
|
+
} else if (
|
|
145
|
+
outcome?.status === "fulfilled" &&
|
|
146
|
+
outcome.value.commits.length > 0
|
|
147
|
+
) {
|
|
148
|
+
completedIssues.push(issue);
|
|
140
149
|
}
|
|
141
150
|
}
|
|
142
151
|
|
|
143
|
-
// Only pass branches that actually produced commits to the merge phase.
|
|
144
|
-
// An agent that ran successfully but made no commits has nothing to merge.
|
|
145
|
-
const completedIssues = settled
|
|
146
|
-
.map((outcome, i) => ({ outcome, issue: issues[i]! }))
|
|
147
|
-
.filter(
|
|
148
|
-
(
|
|
149
|
-
entry,
|
|
150
|
-
): entry is {
|
|
151
|
-
outcome: PromiseFulfilledResult<
|
|
152
|
-
Awaited<ReturnType<typeof sandcastle.run>>
|
|
153
|
-
>;
|
|
154
|
-
issue: (typeof issues)[number];
|
|
155
|
-
} =>
|
|
156
|
-
entry.outcome.status === "fulfilled" &&
|
|
157
|
-
entry.outcome.value.commits.length > 0,
|
|
158
|
-
)
|
|
159
|
-
.map((entry) => entry.issue);
|
|
160
|
-
|
|
161
152
|
const completedBranches = completedIssues.map((i) => i.branch);
|
|
162
153
|
|
|
163
154
|
console.log(
|
|
@@ -161,26 +161,24 @@ for (let iteration = 1; iteration <= MAX_ITERATIONS; iteration++) {
|
|
|
161
161
|
}),
|
|
162
162
|
);
|
|
163
163
|
|
|
164
|
-
// Log any agents that threw (network error, sandbox crash, etc.)
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
// Log any agents that threw (network error, sandbox crash, etc.), and
|
|
165
|
+
// only pass branches that actually produced commits to the merge phase.
|
|
166
|
+
// An agent that ran successfully but made no commits has nothing to merge.
|
|
167
|
+
const completedIssues: typeof issues = [];
|
|
168
|
+
for (const [i, issue] of issues.entries()) {
|
|
169
|
+
const outcome = settled[i];
|
|
170
|
+
if (outcome?.status === "rejected") {
|
|
167
171
|
console.error(
|
|
168
|
-
` ✗ ${
|
|
172
|
+
` ✗ ${issue.id} (${issue.branch}) failed: ${outcome.reason}`,
|
|
169
173
|
);
|
|
174
|
+
} else if (
|
|
175
|
+
outcome?.status === "fulfilled" &&
|
|
176
|
+
outcome.value.commits.length > 0
|
|
177
|
+
) {
|
|
178
|
+
completedIssues.push(issue);
|
|
170
179
|
}
|
|
171
180
|
}
|
|
172
181
|
|
|
173
|
-
// Only pass branches that actually produced commits to the merge phase.
|
|
174
|
-
// An agent that ran successfully but made no commits has nothing to merge.
|
|
175
|
-
const completedIssues = settled
|
|
176
|
-
.map((outcome, i) => ({ outcome, issue: issues[i]! }))
|
|
177
|
-
.filter(
|
|
178
|
-
(entry) =>
|
|
179
|
-
entry.outcome.status === "fulfilled" &&
|
|
180
|
-
entry.outcome.value.commits.length > 0,
|
|
181
|
-
)
|
|
182
|
-
.map((entry) => entry.issue);
|
|
183
|
-
|
|
184
182
|
const completedBranches = completedIssues.map((i) => i.branch);
|
|
185
183
|
|
|
186
184
|
console.log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-hero/sandcastle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "CLI for orchestrating AI agents in isolated sandbox environments",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,6 +29,14 @@
|
|
|
29
29
|
"./sandboxes/no-sandbox": {
|
|
30
30
|
"import": "./dist/sandboxes/no-sandbox.js",
|
|
31
31
|
"types": "./dist/sandboxes/no-sandbox.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./sandboxes/bwrap": {
|
|
34
|
+
"import": "./dist/sandboxes/bwrap.js",
|
|
35
|
+
"types": "./dist/sandboxes/bwrap.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./sandboxes/seatbelt": {
|
|
38
|
+
"import": "./dist/sandboxes/seatbelt.js",
|
|
39
|
+
"types": "./dist/sandboxes/seatbelt.d.ts"
|
|
32
40
|
}
|
|
33
41
|
},
|
|
34
42
|
"bin": {
|
|
@@ -37,17 +45,27 @@
|
|
|
37
45
|
"scripts": {
|
|
38
46
|
"build": "tsup",
|
|
39
47
|
"postbuild": "rm -rf dist/templates && cp -r src/templates dist/templates && node scripts/check-public-types-effect-free.mjs",
|
|
48
|
+
"pretest": "tsx scripts/ensure-build.ts",
|
|
40
49
|
"test": "vitest run",
|
|
41
50
|
"test:watch": "vitest",
|
|
42
|
-
"typecheck": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
51
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
|
|
52
|
+
"prelint": "tsx scripts/ensure-build.ts",
|
|
53
|
+
"lint": "tsc --noEmit -p scripts/tsconfig.json && tsx scripts/lint-ratchet.ts",
|
|
54
|
+
"lint:shrink": "tsx scripts/lint-ratchet.ts --shrink",
|
|
55
|
+
"lint:report": "tsx scripts/lint-ratchet.ts --report",
|
|
56
|
+
"format": "biome format --write .",
|
|
57
|
+
"format:check": "biome format .",
|
|
45
58
|
"prepare": "husky",
|
|
46
59
|
"release": "changeset publish",
|
|
47
60
|
"sandcastle": "npm run build && tsx .sandcastle/run.ts",
|
|
48
61
|
"test-podman": "npm run build && tsx --env-file=.sandcastle/.env .sandcastle/test-podman.ts",
|
|
49
62
|
"test-vercel": "npm run build && tsx --env-file=.sandcastle/.env .sandcastle/test-vercel.ts",
|
|
50
|
-
"test-interactive": "npm run build && tsx --env-file=.sandcastle/.env .sandcastle/test-interactive.ts"
|
|
63
|
+
"test-interactive": "npm run build && tsx --env-file=.sandcastle/.env .sandcastle/test-interactive.ts",
|
|
64
|
+
"verify": "tsx .sandcastle/verify/verify.ts",
|
|
65
|
+
"verify:world": "npm run build >/dev/null && tsx .sandcastle/verify/verify.ts world",
|
|
66
|
+
"coverage:gate": "tsx scripts/coverage-gate.ts",
|
|
67
|
+
"coverage:floor": "tsx scripts/coverage-floor.ts",
|
|
68
|
+
"api:report": "tsx scripts/api-report.ts"
|
|
51
69
|
},
|
|
52
70
|
"keywords": [
|
|
53
71
|
"cli",
|
|
@@ -63,22 +81,28 @@
|
|
|
63
81
|
},
|
|
64
82
|
"license": "MIT",
|
|
65
83
|
"devDependencies": {
|
|
84
|
+
"@biomejs/biome": "2.6.4",
|
|
66
85
|
"@changesets/cli": "^2.30.0",
|
|
67
|
-
"@daytona/sdk": "^0.
|
|
86
|
+
"@daytona/sdk": "^0.227.0",
|
|
68
87
|
"@effect/cli": "^0.74.0",
|
|
88
|
+
"@effect/language-service": "0.87.5",
|
|
69
89
|
"@effect/platform": "^0.95.0",
|
|
70
90
|
"@effect/platform-node": "^0.105.0",
|
|
71
91
|
"@effect/printer": "^0.48.0",
|
|
72
92
|
"@effect/printer-ansi": "^0.48.0",
|
|
93
|
+
"@microsoft/api-extractor": "^7.60.1",
|
|
73
94
|
"@types/node": "^25.5.0",
|
|
74
|
-
"@typescript/native
|
|
95
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
96
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
97
|
+
"dependency-cruiser": "^18.7.0",
|
|
75
98
|
"effect": "^3.20.0",
|
|
76
99
|
"husky": "^9.1.7",
|
|
77
100
|
"lint-staged": "^15.5.1",
|
|
78
|
-
"
|
|
101
|
+
"oxlint": "1.90.0",
|
|
102
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
79
103
|
"tsup": "^8.5.1",
|
|
80
104
|
"tsx": "^4.21.0",
|
|
81
|
-
"typescript": "
|
|
105
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
82
106
|
"vitest": "^3.2.0",
|
|
83
107
|
"zod": "^4.4.3"
|
|
84
108
|
},
|
|
@@ -86,7 +110,7 @@
|
|
|
86
110
|
"@clack/prompts": "^1.1.0"
|
|
87
111
|
},
|
|
88
112
|
"peerDependencies": {
|
|
89
|
-
"@daytona/sdk": "
|
|
113
|
+
"@daytona/sdk": ">=0.164.0 <1.0.0",
|
|
90
114
|
"@vercel/sandbox": ">=1.0.0"
|
|
91
115
|
},
|
|
92
116
|
"peerDependenciesMeta": {
|