@ai-hero/sandcastle 0.12.0 → 0.14.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-Chsi-Zs6.d.ts} +31 -3
- package/dist/{chunk-NGBM7T3E.js → chunk-6NQPCXSG.js} +5 -2
- package/dist/chunk-6NQPCXSG.js.map +1 -0
- package/dist/chunk-7N7AMUYA.js +353 -0
- package/dist/chunk-7N7AMUYA.js.map +1 -0
- package/dist/chunk-ATA2V2TC.js +112 -0
- package/dist/chunk-ATA2V2TC.js.map +1 -0
- package/dist/chunk-BIF2X6QB.js +94 -0
- package/dist/chunk-BIF2X6QB.js.map +1 -0
- package/dist/{chunk-BIWNFKGV.js → chunk-BVZWLFFT.js} +2 -2
- package/dist/chunk-BVZWLFFT.js.map +1 -0
- package/dist/chunk-EXYXBRCX.js +60 -0
- package/dist/chunk-EXYXBRCX.js.map +1 -0
- package/dist/chunk-G2R53CVZ.js +3172 -0
- package/dist/chunk-G2R53CVZ.js.map +1 -0
- package/dist/{chunk-CP3TYXZA.js → chunk-GCLEXPXG.js} +95 -85
- package/dist/chunk-GCLEXPXG.js.map +1 -0
- package/dist/chunk-H2PEFS4W.js +1244 -0
- package/dist/chunk-H2PEFS4W.js.map +1 -0
- package/dist/chunk-HSXPRZKG.js +150 -0
- package/dist/chunk-HSXPRZKG.js.map +1 -0
- package/dist/chunk-IBK2XNSS.js +50 -0
- package/dist/chunk-IBK2XNSS.js.map +1 -0
- package/dist/chunk-RDW7FNN6.js +792 -0
- package/dist/chunk-RDW7FNN6.js.map +1 -0
- package/dist/{chunk-DJRHWPEH.js → chunk-S6UHPTRG.js} +284 -352
- package/dist/chunk-S6UHPTRG.js.map +1 -0
- package/dist/{chunk-VOG34SRF.js → chunk-STB2U7BB.js} +11823 -6977
- package/dist/chunk-STB2U7BB.js.map +1 -0
- package/dist/chunk-VRXR2T3S.js +24 -0
- package/dist/chunk-VRXR2T3S.js.map +1 -0
- package/dist/index.d.ts +241 -26
- package/dist/index.js +1082 -1679
- package/dist/index.js.map +1 -1
- package/dist/main.js +1248 -854
- package/dist/main.js.map +1 -1
- package/dist/sandboxes/bwrap.d.ts +58 -0
- package/dist/sandboxes/bwrap.js +296 -0
- package/dist/sandboxes/bwrap.js.map +1 -0
- package/dist/sandboxes/daytona.d.ts +1 -1
- package/dist/sandboxes/daytona.js +203 -98
- package/dist/sandboxes/daytona.js.map +1 -1
- package/dist/sandboxes/docker.d.ts +18 -4
- package/dist/sandboxes/docker.js +7 -4
- package/dist/sandboxes/e2b.d.ts +41 -0
- package/dist/sandboxes/e2b.js +202 -0
- package/dist/sandboxes/e2b.js.map +1 -0
- package/dist/sandboxes/modal.d.ts +78 -0
- package/dist/sandboxes/modal.js +171 -0
- package/dist/sandboxes/modal.js.map +1 -0
- 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 +72 -56
- package/dist/sandboxes/podman.js.map +1 -1
- package/dist/sandboxes/seatbelt.d.ts +65 -0
- package/dist/sandboxes/seatbelt.js +425 -0
- package/dist/sandboxes/seatbelt.js.map +1 -0
- package/dist/sandboxes/sprites.d.ts +54 -0
- package/dist/sandboxes/sprites.js +198 -0
- package/dist/sandboxes/sprites.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 +63 -11
- 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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { NativeSandboxUnavailableError } from './chunk-S6UHPTRG.js';
|
|
3
|
+
import { spawnSync } from 'child_process';
|
|
4
|
+
import { readFileSync } from 'fs';
|
|
5
|
+
|
|
6
|
+
createRequire(import.meta.url);
|
|
7
|
+
var INSTALL_COMMANDS = [
|
|
8
|
+
{ ids: ["debian", "ubuntu"], command: "sudo apt install bubblewrap" },
|
|
9
|
+
{
|
|
10
|
+
ids: ["fedora", "rhel", "centos", "rocky", "almalinux", "amzn"],
|
|
11
|
+
command: "sudo dnf install bubblewrap"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
ids: ["arch", "manjaro", "endeavouros"],
|
|
15
|
+
command: "sudo pacman -S bubblewrap"
|
|
16
|
+
},
|
|
17
|
+
{ ids: ["alpine"], command: "sudo apk add bubblewrap" },
|
|
18
|
+
{
|
|
19
|
+
ids: ["opensuse", "suse", "sles", "opensuse-leap", "opensuse-tumbleweed"],
|
|
20
|
+
command: "sudo zypper install bubblewrap"
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
var distroIds = (osRelease) => {
|
|
24
|
+
const field = (name) => {
|
|
25
|
+
const match = new RegExp(`^${name}=(.*)$`, "mu").exec(osRelease);
|
|
26
|
+
return (match?.[1] ?? "").replaceAll(/["']/gu, "").trim();
|
|
27
|
+
};
|
|
28
|
+
return [field("ID"), ...field("ID_LIKE").split(/\s+/u)].map((id) => id.toLowerCase()).filter((id) => id !== "");
|
|
29
|
+
};
|
|
30
|
+
var readOsRelease = () => {
|
|
31
|
+
for (const file of ["/etc/os-release", "/usr/lib/os-release"]) {
|
|
32
|
+
try {
|
|
33
|
+
return readFileSync(file, "utf8");
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
};
|
|
39
|
+
var installCommand = (osRelease) => {
|
|
40
|
+
for (const id of distroIds(osRelease)) {
|
|
41
|
+
const known = INSTALL_COMMANDS.find((entry) => entry.ids.includes(id));
|
|
42
|
+
if (known !== void 0) {
|
|
43
|
+
return known.command;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return void 0;
|
|
47
|
+
};
|
|
48
|
+
var notInstalled = () => {
|
|
49
|
+
const command = installCommand(readOsRelease());
|
|
50
|
+
if (command !== void 0) {
|
|
51
|
+
return {
|
|
52
|
+
message: `bwrap() needs Bubblewrap, and \`bwrap\` isn't on PATH. Install it with: ${command}`,
|
|
53
|
+
fixCommand: command
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const list = INSTALL_COMMANDS.map((entry) => ` ${entry.command}`).join("\n");
|
|
57
|
+
return {
|
|
58
|
+
message: `bwrap() needs Bubblewrap, and \`bwrap\` isn't on PATH. Install the \`bubblewrap\` package with your distro's package manager:
|
|
59
|
+
${list}`
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var userNamespacesBlocked = (stderr) => {
|
|
63
|
+
const profile = [
|
|
64
|
+
"abi <abi/4.0>,",
|
|
65
|
+
"include <tunables/global>",
|
|
66
|
+
"profile bwrap %s flags=(unconfined) {",
|
|
67
|
+
" userns,",
|
|
68
|
+
"}"
|
|
69
|
+
].join(String.raw`\n`);
|
|
70
|
+
const fixCommand = `printf '${profile}\\n' "$(command -v bwrap)" | sudo tee /etc/apparmor.d/bwrap >/dev/null && sudo apparmor_parser -r /etc/apparmor.d/bwrap`;
|
|
71
|
+
return {
|
|
72
|
+
message: `bwrap() can't start a sandbox: this kernel blocks unprivileged user namespaces (Ubuntu 24.04+ restricts them with AppArmor). Bubblewrap said: ${stderr.trim()}
|
|
73
|
+
Fix it by giving bwrap an AppArmor profile that allows user namespaces:
|
|
74
|
+
${fixCommand}
|
|
75
|
+
Or, more bluntly, allow them for every program: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0`,
|
|
76
|
+
fixCommand
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
var probe = () => {
|
|
80
|
+
const result = spawnSync("bwrap", ["--ro-bind", "/", "/", "true"], {
|
|
81
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
82
|
+
encoding: "utf8",
|
|
83
|
+
timeout: 3e4
|
|
84
|
+
});
|
|
85
|
+
const spawnError = result.error;
|
|
86
|
+
if (spawnError?.code === "ENOENT") {
|
|
87
|
+
return notInstalled();
|
|
88
|
+
}
|
|
89
|
+
if (result.status === 0) {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
const stderr = result.stderr ?? "";
|
|
93
|
+
if (/namespace|uid map/iu.test(stderr)) {
|
|
94
|
+
return userNamespacesBlocked(stderr);
|
|
95
|
+
}
|
|
96
|
+
const reason = stderr.trim() === "" ? result.error?.message ?? `exit code ${String(result.status)}` : stderr.trim();
|
|
97
|
+
return {
|
|
98
|
+
message: `bwrap() can't start a sandbox: \`bwrap --ro-bind / / true\` failed: ${reason}`
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
var check = () => process.platform === "linux" ? probe() : { message: "bwrap() needs Linux or WSL2; on macOS use seatbelt()" };
|
|
102
|
+
var outcome;
|
|
103
|
+
var assertBwrapUsable = () => {
|
|
104
|
+
outcome ??= { unavailable: check() };
|
|
105
|
+
if (outcome.unavailable !== void 0) {
|
|
106
|
+
throw new NativeSandboxUnavailableError(outcome.unavailable);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { assertBwrapUsable };
|
|
111
|
+
//# sourceMappingURL=chunk-ATA2V2TC.js.map
|
|
112
|
+
//# sourceMappingURL=chunk-ATA2V2TC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bwrapPreflight.ts"],"names":[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ACZ,OAAA,CAAQ,QAAA,KAAa,UACjB,KAAA,EAAM,GACN,EAAE,OAAA,EAAS,sDAAA,EAAuD;AAExE,IAAI,OAAA;AAMG,IAAM,oBAAoB,MAAY;AAC3C,EAAA,OAAA,KAAY,EAAE,WAAA,EAAa,KAAA,EAAM,EAAE;AACnC,EAAA,IAAI,OAAA,CAAQ,gBAAgB,MAAA,EAAW;AACrC,IAAA,MAAM,IAAI,6BAAA,CAA8B,OAAA,CAAQ,WAAW,CAAA;AAAA,EAC7D;AACF","file":"chunk-ATA2V2TC.js","sourcesContent":["/**\n * The `bwrap()` construction check (src/sandboxes/bwrap.ts): is Bubblewrap\n * usable on this host, and if not, why and how to fix it. Runs once per\n * process. Used only by `bwrap()`.\n *\n * Synchronous on purpose: `bwrap()` is a synchronous constructor, and it must\n * throw before anything else (a worktree, a temp dir) exists.\n */\n\n/* oxlint-disable node/no-sync -- bwrap() throws at construction, which is synchronous (allowlisted in scripts/lint-ratchet-config.ts). */\n\nimport { spawnSync } from \"node:child_process\";\nimport { readFileSync } from \"node:fs\";\nimport { NativeSandboxUnavailableError } from \"./NativeSandboxUnavailableError.js\";\n\n/** Why Bubblewrap isn't usable, and the command that fixes it, when there is one. */\ninterface BwrapUnavailable {\n readonly message: string;\n readonly fixCommand?: string;\n}\n\n/** The install command per package manager, keyed by the os-release IDs that use it. */\nconst INSTALL_COMMANDS: readonly {\n readonly ids: readonly string[];\n readonly command: string;\n}[] = [\n { ids: [\"debian\", \"ubuntu\"], command: \"sudo apt install bubblewrap\" },\n {\n ids: [\"fedora\", \"rhel\", \"centos\", \"rocky\", \"almalinux\", \"amzn\"],\n command: \"sudo dnf install bubblewrap\",\n },\n {\n ids: [\"arch\", \"manjaro\", \"endeavouros\"],\n command: \"sudo pacman -S bubblewrap\",\n },\n { ids: [\"alpine\"], command: \"sudo apk add bubblewrap\" },\n {\n ids: [\"opensuse\", \"suse\", \"sles\", \"opensuse-leap\", \"opensuse-tumbleweed\"],\n command: \"sudo zypper install bubblewrap\",\n },\n];\n\n/** The distro's IDs from os-release: `ID` first, then each of `ID_LIKE`. */\nconst distroIds = (osRelease: string): string[] => {\n const field = (name: string): string => {\n const match = new RegExp(`^${name}=(.*)$`, \"mu\").exec(osRelease);\n return (match?.[1] ?? \"\").replaceAll(/[\"']/gu, \"\").trim();\n };\n return [field(\"ID\"), ...field(\"ID_LIKE\").split(/\\s+/u)]\n .map((id) => id.toLowerCase())\n .filter((id) => id !== \"\");\n};\n\nconst readOsRelease = (): string => {\n for (const file of [\"/etc/os-release\", \"/usr/lib/os-release\"]) {\n try {\n return readFileSync(file, \"utf8\");\n } catch {\n // Try the next location.\n }\n }\n return \"\";\n};\n\n/** The install command for this distro, or undefined when it's not one we know. */\nconst installCommand = (osRelease: string): string | undefined => {\n for (const id of distroIds(osRelease)) {\n const known = INSTALL_COMMANDS.find((entry) => entry.ids.includes(id));\n if (known !== undefined) {\n return known.command;\n }\n }\n return undefined;\n};\n\nconst notInstalled = (): BwrapUnavailable => {\n const command = installCommand(readOsRelease());\n if (command !== undefined) {\n return {\n message: `bwrap() needs Bubblewrap, and \\`bwrap\\` isn't on PATH. Install it with: ${command}`,\n fixCommand: command,\n };\n }\n const list = INSTALL_COMMANDS.map((entry) => ` ${entry.command}`).join(\"\\n\");\n return {\n message: `bwrap() needs Bubblewrap, and \\`bwrap\\` isn't on PATH. Install the \\`bubblewrap\\` package with your distro's package manager:\\n${list}`,\n };\n};\n\n/** The probe failed because the kernel won't give an unprivileged user a user namespace. */\nconst userNamespacesBlocked = (stderr: string): BwrapUnavailable => {\n const profile = [\n \"abi <abi/4.0>,\",\n \"include <tunables/global>\",\n \"profile bwrap %s flags=(unconfined) {\",\n \" userns,\",\n \"}\",\n ].join(String.raw`\\n`);\n const fixCommand =\n `printf '${profile}\\\\n' \"$(command -v bwrap)\" | sudo tee /etc/apparmor.d/bwrap >/dev/null` +\n \" && sudo apparmor_parser -r /etc/apparmor.d/bwrap\";\n return {\n message:\n \"bwrap() can't start a sandbox: this kernel blocks unprivileged user namespaces \" +\n \"(Ubuntu 24.04+ restricts them with AppArmor). \" +\n `Bubblewrap said: ${stderr.trim()}\\n` +\n `Fix it by giving bwrap an AppArmor profile that allows user namespaces:\\n ${fixCommand}\\n` +\n \"Or, more bluntly, allow them for every program: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0\",\n fixCommand,\n };\n};\n\n/** Runs the trivial probe and explains its failure, or returns undefined when bwrap works. */\nconst probe = (): BwrapUnavailable | undefined => {\n const result = spawnSync(\"bwrap\", [\"--ro-bind\", \"/\", \"/\", \"true\"], {\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n encoding: \"utf8\",\n timeout: 30_000,\n });\n const spawnError: NodeJS.ErrnoException | undefined = result.error;\n if (spawnError?.code === \"ENOENT\") {\n return notInstalled();\n }\n if (result.status === 0) {\n return undefined;\n }\n const stderr = result.stderr ?? \"\";\n if (/namespace|uid map/iu.test(stderr)) {\n return userNamespacesBlocked(stderr);\n }\n const reason =\n stderr.trim() === \"\"\n ? (result.error?.message ?? `exit code ${String(result.status)}`)\n : stderr.trim();\n return {\n message: `bwrap() can't start a sandbox: \\`bwrap --ro-bind / / true\\` failed: ${reason}`,\n };\n};\n\nconst check = (): BwrapUnavailable | undefined =>\n process.platform === \"linux\"\n ? probe()\n : { message: \"bwrap() needs Linux or WSL2; on macOS use seatbelt()\" };\n\nlet outcome: { readonly unavailable: BwrapUnavailable | undefined } | undefined;\n\n/**\n * Throws `NativeSandboxUnavailableError` when Bubblewrap isn't usable on this\n * host. Checks on the first call only; later calls give the same answer.\n */\nexport const assertBwrapUsable = (): void => {\n outcome ??= { unavailable: check() };\n if (outcome.unavailable !== undefined) {\n throw new NativeSandboxUnavailableError(outcome.unavailable);\n }\n};\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { Display } from './chunk-G2R53CVZ.js';
|
|
3
|
+
import { Effect_exports } from './chunk-STB2U7BB.js';
|
|
4
|
+
|
|
5
|
+
createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
// src/ErrorHandler.ts
|
|
8
|
+
var formatErrorMessage = (error) => {
|
|
9
|
+
switch (error._tag) {
|
|
10
|
+
case "ExecError": {
|
|
11
|
+
return `Command failed in sandbox (${error.command}): ${error.message}`;
|
|
12
|
+
}
|
|
13
|
+
case "ExecHostError": {
|
|
14
|
+
return `Command failed on host (${error.command}): ${error.message}`;
|
|
15
|
+
}
|
|
16
|
+
case "CopyError": {
|
|
17
|
+
return `File copy failed: ${error.message}`;
|
|
18
|
+
}
|
|
19
|
+
case "DockerError": {
|
|
20
|
+
return `Docker operation failed: ${error.message}. Is Docker running?`;
|
|
21
|
+
}
|
|
22
|
+
case "PodmanError": {
|
|
23
|
+
return `Podman operation failed: ${error.message}. Is Podman running?`;
|
|
24
|
+
}
|
|
25
|
+
case "SyncError": {
|
|
26
|
+
return `Git sync failed: ${error.message}`;
|
|
27
|
+
}
|
|
28
|
+
case "WorktreeError": {
|
|
29
|
+
return `Git worktree operation failed: ${error.message}`;
|
|
30
|
+
}
|
|
31
|
+
case "PromptError": {
|
|
32
|
+
return `Failed to resolve prompt: ${error.message}`;
|
|
33
|
+
}
|
|
34
|
+
case "AgentError": {
|
|
35
|
+
return `Agent invocation failed: ${error.message}`;
|
|
36
|
+
}
|
|
37
|
+
case "ConfigDirError":
|
|
38
|
+
case "InitError":
|
|
39
|
+
case "AgentIdleTimeoutError":
|
|
40
|
+
case "WorktreeTimeoutError":
|
|
41
|
+
case "ContainerStartTimeoutError":
|
|
42
|
+
case "CopyToWorktreeTimeoutError":
|
|
43
|
+
case "CopyToWorktreeError":
|
|
44
|
+
case "SyncInTimeoutError":
|
|
45
|
+
case "HookTimeoutError":
|
|
46
|
+
case "GitSetupTimeoutError":
|
|
47
|
+
case "PromptExpansionTimeoutError":
|
|
48
|
+
case "CommitCollectionTimeoutError":
|
|
49
|
+
case "MergeToHostTimeoutError":
|
|
50
|
+
case "SessionCaptureError":
|
|
51
|
+
case "SyncOutPathError":
|
|
52
|
+
case "CwdError":
|
|
53
|
+
case "ImageNotFoundError": {
|
|
54
|
+
return error.message;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var showErrorAndExit = (error) => Effect_exports.gen(function* () {
|
|
59
|
+
const d = yield* Display;
|
|
60
|
+
yield* d.status(formatErrorMessage(error), "error");
|
|
61
|
+
return yield* Effect_exports.sync(() => process.exit(1));
|
|
62
|
+
});
|
|
63
|
+
var withFriendlyErrors = (effect) => Effect_exports.catchTags(effect, {
|
|
64
|
+
ExecError: showErrorAndExit,
|
|
65
|
+
ExecHostError: showErrorAndExit,
|
|
66
|
+
CopyError: showErrorAndExit,
|
|
67
|
+
DockerError: showErrorAndExit,
|
|
68
|
+
PodmanError: showErrorAndExit,
|
|
69
|
+
SyncError: showErrorAndExit,
|
|
70
|
+
SyncOutPathError: showErrorAndExit,
|
|
71
|
+
WorktreeError: showErrorAndExit,
|
|
72
|
+
PromptError: showErrorAndExit,
|
|
73
|
+
AgentError: showErrorAndExit,
|
|
74
|
+
ConfigDirError: showErrorAndExit,
|
|
75
|
+
InitError: showErrorAndExit,
|
|
76
|
+
AgentIdleTimeoutError: showErrorAndExit,
|
|
77
|
+
WorktreeTimeoutError: showErrorAndExit,
|
|
78
|
+
ContainerStartTimeoutError: showErrorAndExit,
|
|
79
|
+
CopyToWorktreeTimeoutError: showErrorAndExit,
|
|
80
|
+
CopyToWorktreeError: showErrorAndExit,
|
|
81
|
+
SyncInTimeoutError: showErrorAndExit,
|
|
82
|
+
HookTimeoutError: showErrorAndExit,
|
|
83
|
+
GitSetupTimeoutError: showErrorAndExit,
|
|
84
|
+
PromptExpansionTimeoutError: showErrorAndExit,
|
|
85
|
+
CommitCollectionTimeoutError: showErrorAndExit,
|
|
86
|
+
MergeToHostTimeoutError: showErrorAndExit,
|
|
87
|
+
SessionCaptureError: showErrorAndExit,
|
|
88
|
+
CwdError: showErrorAndExit,
|
|
89
|
+
ImageNotFoundError: showErrorAndExit
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export { formatErrorMessage, withFriendlyErrors };
|
|
93
|
+
//# sourceMappingURL=chunk-BIF2X6QB.js.map
|
|
94
|
+
//# sourceMappingURL=chunk-BIF2X6QB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ErrorHandler.ts"],"names":[],"mappings":";;;;;;;AAQO,IAAM,kBAAA,GAAqB,CAAC,KAAA,KAAgC;AACjE,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAK,WAAA,EAAa;AAChB,MAAA,OAAO,CAAA,2BAAA,EAA8B,KAAA,CAAM,OAAO,CAAA,GAAA,EAAM,MAAM,OAAO,CAAA,CAAA;AAAA,IACvE;AAAA,IACA,KAAK,eAAA,EAAiB;AACpB,MAAA,OAAO,CAAA,wBAAA,EAA2B,KAAA,CAAM,OAAO,CAAA,GAAA,EAAM,MAAM,OAAO,CAAA,CAAA;AAAA,IACpE;AAAA,IACA,KAAK,WAAA,EAAa;AAChB,MAAA,OAAO,CAAA,kBAAA,EAAqB,MAAM,OAAO,CAAA,CAAA;AAAA,IAC3C;AAAA,IACA,KAAK,aAAA,EAAe;AAClB,MAAA,OAAO,CAAA,yBAAA,EAA4B,MAAM,OAAO,CAAA,oBAAA,CAAA;AAAA,IAClD;AAAA,IACA,KAAK,aAAA,EAAe;AAClB,MAAA,OAAO,CAAA,yBAAA,EAA4B,MAAM,OAAO,CAAA,oBAAA,CAAA;AAAA,IAClD;AAAA,IACA,KAAK,WAAA,EAAa;AAChB,MAAA,OAAO,CAAA,iBAAA,EAAoB,MAAM,OAAO,CAAA,CAAA;AAAA,IAC1C;AAAA,IACA,KAAK,eAAA,EAAiB;AACpB,MAAA,OAAO,CAAA,+BAAA,EAAkC,MAAM,OAAO,CAAA,CAAA;AAAA,IACxD;AAAA,IACA,KAAK,aAAA,EAAe;AAClB,MAAA,OAAO,CAAA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,aAAA,EAAe,gBAAA;AAAA,EACf,WAAA,EAAa,gBAAA;AAAA,EACb,UAAA,EAAY,gBAAA;AAAA,EACZ,cAAA,EAAgB,gBAAA;AAAA,EAChB,SAAA,EAAW,gBAAA;AAAA,EACX,qBAAA,EAAuB,gBAAA;AAAA,EACvB,oBAAA,EAAsB,gBAAA;AAAA,EACtB,0BAAA,EAA4B,gBAAA;AAAA,EAC5B,0BAAA,EAA4B,gBAAA;AAAA,EAC5B,mBAAA,EAAqB,gBAAA;AAAA,EACrB,kBAAA,EAAoB,gBAAA;AAAA,EACpB,gBAAA,EAAkB,gBAAA;AAAA,EAClB,oBAAA,EAAsB,gBAAA;AAAA,EACtB,2BAAA,EAA6B,gBAAA;AAAA,EAC7B,4BAAA,EAA8B,gBAAA;AAAA,EAC9B,uBAAA,EAAyB,gBAAA;AAAA,EACzB,mBAAA,EAAqB,gBAAA;AAAA,EACrB,QAAA,EAAU,gBAAA;AAAA,EACV,kBAAA,EAAoB;AACtB,CAAC","file":"chunk-BIF2X6QB.js","sourcesContent":["import { Effect } from \"effect\";\nimport { Display } from \"./Display.js\";\nimport type { SandboxError } from \"./errors.js\";\n\n/**\n * Formats a tagged SandboxError into a user-friendly message with\n * context-specific hints about what went wrong and how to recover.\n */\nexport const formatErrorMessage = (error: SandboxError): string => {\n switch (error._tag) {\n case \"ExecError\": {\n return `Command failed in sandbox (${error.command}): ${error.message}`;\n }\n case \"ExecHostError\": {\n return `Command failed on host (${error.command}): ${error.message}`;\n }\n case \"CopyError\": {\n return `File copy failed: ${error.message}`;\n }\n case \"DockerError\": {\n return `Docker operation failed: ${error.message}. Is Docker running?`;\n }\n case \"PodmanError\": {\n return `Podman operation failed: ${error.message}. Is Podman running?`;\n }\n case \"SyncError\": {\n return `Git sync failed: ${error.message}`;\n }\n case \"WorktreeError\": {\n return `Git worktree operation failed: ${error.message}`;\n }\n case \"PromptError\": {\n return `Failed to resolve prompt: ${error.message}`;\n }\n case \"AgentError\": {\n return `Agent invocation failed: ${error.message}`;\n }\n case \"ConfigDirError\":\n case \"InitError\":\n case \"AgentIdleTimeoutError\":\n case \"WorktreeTimeoutError\":\n case \"ContainerStartTimeoutError\":\n case \"CopyToWorktreeTimeoutError\":\n case \"CopyToWorktreeError\":\n case \"SyncInTimeoutError\":\n case \"HookTimeoutError\":\n case \"GitSetupTimeoutError\":\n case \"PromptExpansionTimeoutError\":\n case \"CommitCollectionTimeoutError\":\n case \"MergeToHostTimeoutError\":\n case \"SessionCaptureError\":\n case \"SyncOutPathError\":\n case \"CwdError\":\n case \"ImageNotFoundError\": {\n return error.message;\n }\n }\n};\n\nconst showErrorAndExit = (error: SandboxError) =>\n Effect.gen(function* () {\n const d = yield* Display;\n yield* d.status(formatErrorMessage(error), \"error\");\n return yield* Effect.sync(() => process.exit(1));\n });\n\n/**\n * Wraps an effect so that any SandboxError is caught, displayed via the\n * Display service as an error-severity status message, then exits the process\n * with code 1. Non-SandboxError errors pass through unchanged.\n */\nexport const withFriendlyErrors = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n): Effect.Effect<A, Exclude<E, SandboxError>, R | Display> =>\n Effect.catchTags(effect as Effect.Effect<A, SandboxError, R>, {\n ExecError: showErrorAndExit,\n ExecHostError: showErrorAndExit,\n CopyError: showErrorAndExit,\n DockerError: showErrorAndExit,\n PodmanError: showErrorAndExit,\n SyncError: showErrorAndExit,\n SyncOutPathError: showErrorAndExit,\n WorktreeError: showErrorAndExit,\n PromptError: showErrorAndExit,\n AgentError: showErrorAndExit,\n ConfigDirError: showErrorAndExit,\n InitError: showErrorAndExit,\n AgentIdleTimeoutError: showErrorAndExit,\n WorktreeTimeoutError: showErrorAndExit,\n ContainerStartTimeoutError: showErrorAndExit,\n CopyToWorktreeTimeoutError: showErrorAndExit,\n CopyToWorktreeError: showErrorAndExit,\n SyncInTimeoutError: showErrorAndExit,\n HookTimeoutError: showErrorAndExit,\n GitSetupTimeoutError: showErrorAndExit,\n PromptExpansionTimeoutError: showErrorAndExit,\n CommitCollectionTimeoutError: showErrorAndExit,\n MergeToHostTimeoutError: showErrorAndExit,\n SessionCaptureError: showErrorAndExit,\n CwdError: showErrorAndExit,\n ImageNotFoundError: showErrorAndExit,\n });\n"]}
|
|
@@ -18,5 +18,5 @@ var createIsolatedSandboxProvider = (config) => ({
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export { createBindMountSandboxProvider, createIsolatedSandboxProvider };
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
21
|
+
//# sourceMappingURL=chunk-BVZWLFFT.js.map
|
|
22
|
+
//# sourceMappingURL=chunk-BVZWLFFT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SandboxProvider.ts"],"names":[],"mappings":";;;;;AAgVO,IAAM,8BAAA,GAAiC,CAC5C,MAAA,MAC8B;AAAA,EAC9B,GAAA,EAAK,YAAA;AAAA,EACL,MAAM,MAAA,CAAO,IAAA;AAAA,EACb,GAAA,EAAK,MAAA,CAAO,GAAA,IAAO,EAAC;AAAA,EACpB,gBAAgB,MAAA,CAAO,cAAA;AAAA,EACvB,QAAQ,MAAA,CAAO;AACjB,CAAA;AAMO,IAAM,6BAAA,GAAgC,CAC3C,MAAA,MAC6B;AAAA,EAC7B,GAAA,EAAK,UAAA;AAAA,EACL,MAAM,MAAA,CAAO,IAAA;AAAA,EACb,GAAA,EAAK,MAAA,CAAO,GAAA,IAAO,EAAC;AAAA,EACpB,QAAQ,MAAA,CAAO;AACjB,CAAA","file":"chunk-BVZWLFFT.js","sourcesContent":["/**\n * Sandbox provider types — the pluggable interface for sandbox runtimes.\n *\n * Provider authors implement a small Promise-based interface. Sandcastle\n * handles worktree creation, git mount resolution, and commit extraction.\n */\n\n/** Result of executing a command inside a sandbox. */\nexport interface ExecResult {\n readonly stdout: string;\n readonly stderr: string;\n readonly exitCode: number;\n}\n\n/** Options for interactiveExec — the streams the provider should wire to the spawned process. */\nexport interface InteractiveExecOptions {\n readonly stdin: NodeJS.ReadableStream;\n readonly stdout: NodeJS.WritableStream;\n readonly stderr: NodeJS.WritableStream;\n readonly cwd?: string;\n}\n\n/** Handle to a running bind-mount sandbox. */\nexport interface BindMountSandboxHandle {\n /** Absolute path to the worktree inside the sandbox. */\n readonly worktreePath: string;\n /**\n * The id a supervisor outside this process can use to address the sandbox\n * with the runtime's own tools, e.g. `docker()` and `podman()` set it to the\n * container name (`docker rm -f <sandboxId>`). Surfaced as\n * `Sandbox.sandboxId`. Omit it when there is nothing outside the process to\n * address, as for the native `bwrap()` and `seatbelt()` sandboxes, whose\n * sandbox is a child process of this one.\n */\n readonly sandboxId?: string;\n /**\n * Absolute path to the agent's home directory, as commands running inside\n * the sandbox see it. Sandcastle runs commands there to find and place agent\n * session files. Omit when it is `/home/agent`, as in the Docker image.\n */\n readonly sandboxHomedir?: string;\n /**\n * Absolute path to a writable temp directory, as commands running inside\n * the sandbox see it. Omit when it is `/tmp`.\n */\n readonly sandboxTmpdir?: string;\n /**\n * Execute a command in the sandbox.\n *\n * Implementations MUST support line-by-line streaming via `onLine`. This is\n * how Sandcastle delivers live feedback to the user and enforces idle timeouts —\n * without a streaming implementation, neither will work. A buffered/batch\n * implementation that only calls `onLine` after the process exits does NOT\n * satisfy this contract.\n *\n * When `stdin` is set, the implementation pipes the string to the child\n * process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.\n */\n exec(\n command: string,\n options?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n stdin?: string;\n },\n ): Promise<ExecResult>;\n /**\n * Launch an interactive process inside the sandbox.\n * Optional — providers that support interactive sessions implement this.\n * The provider detects TTY mode from the streams (e.g. stdin.isTTY) and\n * allocates a pseudo-terminal accordingly.\n */\n interactiveExec?(\n args: string[],\n options: InteractiveExecOptions,\n ): Promise<{ exitCode: number }>;\n /** Copy a single file from the host into the sandbox. */\n copyFileIn(hostPath: string, sandboxPath: string): Promise<void>;\n /** Copy a single file from the sandbox to the host. */\n copyFileOut(sandboxPath: string, hostPath: string): Promise<void>;\n /** Tear down the sandbox. */\n close(): Promise<void>;\n}\n\n/** Options passed to a bind-mount provider's `create` function. */\nexport interface BindMountCreateOptions {\n /** Host-side path to the worktree directory. */\n readonly worktreePath: string;\n /** Host-side path to the original repo root. */\n readonly hostRepoPath: string;\n /** Volume mounts to apply (host:sandbox pairs). */\n readonly mounts: {\n hostPath: string;\n sandboxPath: string;\n readonly?: boolean;\n }[];\n /** Environment variables to inject into the sandbox. */\n readonly env: Record<string, string>;\n}\n\n/** Configuration for createBindMountSandboxProvider. */\nexport interface BindMountSandboxProviderConfig {\n /** Human-readable name for this provider (e.g. \"docker\", \"podman\"). */\n readonly name: string;\n /** Environment variables injected by this provider. Merged at launch time. */\n readonly env?: Record<string, string>;\n /**\n * Absolute path to the home directory inside the sandbox (e.g. `\"/home/agent\"`).\n * Used to expand `~` in user-provided `sandboxPath` mount configs.\n * Set to `undefined` for providers that do not have a fixed home directory.\n */\n readonly sandboxHomedir?: string;\n /** Create a sandbox handle from the given options. */\n readonly create: (\n options: BindMountCreateOptions,\n ) => Promise<BindMountSandboxHandle>;\n}\n\n/** Handle to a running isolated sandbox (extends bind-mount with file transfer). */\nexport interface IsolatedSandboxHandle {\n /** Absolute path to the worktree inside the sandbox. */\n readonly worktreePath: string;\n /**\n * The vendor's id for the sandbox, so a supervisor outside this process can\n * address it with the vendor's own CLI or API, e.g. `vercel()`,\n * `daytona()` and `modal()` set it to the Vercel, Daytona and Modal sandbox\n * ids. Surfaced as\n * `Sandbox.sandboxId`. Omit it when the provider has no such id.\n */\n readonly sandboxId?: string;\n /**\n * Execute a command in the sandbox.\n *\n * Implementations MUST support line-by-line streaming via `onLine`. This is\n * how Sandcastle delivers live feedback to the user and enforces idle timeouts —\n * without a streaming implementation, neither will work. A buffered/batch\n * implementation that only calls `onLine` after the process exits does NOT\n * satisfy this contract.\n *\n * When `stdin` is set, the implementation pipes the string to the child\n * process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.\n */\n exec(\n command: string,\n options?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n stdin?: string;\n },\n ): Promise<ExecResult>;\n /**\n * Launch an interactive process inside the sandbox.\n * Optional — providers that support interactive sessions implement this.\n * The provider detects TTY mode from the streams (e.g. stdin.isTTY) and\n * allocates a pseudo-terminal accordingly.\n */\n interactiveExec?(\n args: string[],\n options: InteractiveExecOptions,\n ): Promise<{ exitCode: number }>;\n /** Copy a file or directory from the host into the sandbox. */\n copyIn(hostPath: string, sandboxPath: string): Promise<void>;\n /** Copy a single file from the sandbox to the host. */\n copyFileOut(sandboxPath: string, hostPath: string): Promise<void>;\n /** Tear down the sandbox. */\n close(): Promise<void>;\n}\n\n/** Options passed to an isolated provider's `create` function. */\nexport interface IsolatedCreateOptions {\n /** Environment variables to inject into the sandbox. */\n readonly env: Record<string, string>;\n}\n\n/** Configuration for createIsolatedSandboxProvider. */\nexport interface IsolatedSandboxProviderConfig {\n /** Human-readable name for this provider (e.g. \"daytona\", \"e2b\"). */\n readonly name: string;\n /** Environment variables injected by this provider. Merged at launch time. */\n readonly env?: Record<string, string>;\n /** Create an isolated sandbox handle from the given options. */\n readonly create: (\n options: IsolatedCreateOptions,\n ) => Promise<IsolatedSandboxHandle>;\n}\n\n/** A bind-mount sandbox provider. */\nexport interface BindMountSandboxProvider {\n /** @internal Discriminator for internal dispatch. */\n readonly tag: \"bind-mount\";\n /** Human-readable provider name. */\n readonly name: string;\n /** Environment variables injected by this provider. */\n readonly env: Record<string, string>;\n /**\n * Absolute path to the home directory inside the sandbox (e.g. `\"/home/agent\"`).\n * `undefined` when the provider does not declare a sandbox home directory.\n */\n readonly sandboxHomedir: string | undefined;\n /** @internal Create a sandbox handle. */\n readonly create: (\n options: BindMountCreateOptions,\n ) => Promise<BindMountSandboxHandle>;\n}\n\n/** An isolated sandbox provider. */\nexport interface IsolatedSandboxProvider {\n /** @internal Discriminator for internal dispatch. */\n readonly tag: \"isolated\";\n /** Human-readable provider name. */\n readonly name: string;\n /** Environment variables injected by this provider. */\n readonly env: Record<string, string>;\n /** @internal Create an isolated sandbox handle. */\n readonly create: (\n options: IsolatedCreateOptions,\n ) => Promise<IsolatedSandboxHandle>;\n}\n\n/** Handle to a no-sandbox session — runs commands directly on the host. */\nexport interface NoSandboxHandle {\n /** Absolute path to the worktree on the host. */\n readonly worktreePath: string;\n /**\n * Execute a command on the host.\n *\n * Implementations MUST support line-by-line streaming via `onLine`. This is\n * how Sandcastle delivers live feedback to the user and enforces idle timeouts —\n * without a streaming implementation, neither will work.\n *\n * When `stdin` is set, the implementation pipes the string to the child\n * process's stdin and closes it. This avoids the Linux 128 KB per-arg limit.\n */\n exec(\n command: string,\n options?: {\n onLine?: (line: string) => void;\n cwd?: string;\n sudo?: boolean;\n stdin?: string;\n },\n ): Promise<ExecResult>;\n /**\n * Launch an interactive process on the host with inherited stdio.\n */\n interactiveExec(\n args: string[],\n options: InteractiveExecOptions,\n ): Promise<{ exitCode: number }>;\n /** No-op — no container to tear down. */\n close(): Promise<void>;\n}\n\n/** A no-sandbox provider — runs the agent directly on the host with no container isolation. */\nexport interface NoSandboxProvider {\n /** @internal Discriminator for internal dispatch. */\n readonly tag: \"none\";\n /** Human-readable provider name. */\n readonly name: string;\n /** Environment variables injected by this provider. */\n readonly env: Record<string, string>;\n /** @internal Create a no-sandbox handle. */\n readonly create: (options: {\n readonly worktreePath: string;\n readonly env: Record<string, string>;\n }) => Promise<NoSandboxHandle>;\n}\n\n// ---------- Branch strategy types ----------\n\n/** Head strategy: agent writes directly to host working directory. Bind-mount only. */\nexport interface HeadBranchStrategy {\n readonly type: \"head\";\n}\n\n/** Merge-to-head strategy: temp branch, merge back to HEAD, delete temp branch. */\nexport interface MergeToHeadBranchStrategy {\n readonly type: \"merge-to-head\";\n}\n\n/** Branch strategy: commits land on an explicit named branch. */\nexport interface NamedBranchStrategy {\n readonly type: \"branch\";\n readonly branch: string;\n /**\n * Git ref to use as the starting point when creating a new branch.\n * Only used when the branch doesn't already exist — ignored otherwise.\n * Callers are responsible for ensuring the ref is current (e.g. `git fetch`).\n * Defaults to `HEAD` when omitted.\n */\n readonly baseBranch?: string;\n}\n\n/** Branch strategy for bind-mount providers (all three variants). */\nexport type BindMountBranchStrategy =\n | HeadBranchStrategy\n | MergeToHeadBranchStrategy\n | NamedBranchStrategy;\n\n/** Branch strategy for isolated providers (no head — can't write to host). */\nexport type IsolatedBranchStrategy =\n | MergeToHeadBranchStrategy\n | NamedBranchStrategy;\n\n/** Branch strategy for no-sandbox providers (all three — same as bind-mount). */\nexport type NoSandboxBranchStrategy =\n | HeadBranchStrategy\n | MergeToHeadBranchStrategy\n | NamedBranchStrategy;\n\n/** Union of all branch strategy variants. */\nexport type BranchStrategy =\n | BindMountBranchStrategy\n | IsolatedBranchStrategy\n | NoSandboxBranchStrategy;\n\n/**\n * A sandbox provider — the pluggable unit that `run()`, `interactive()`, and\n * `createSandbox()` accept. Tagged for internal dispatch: \"bind-mount\",\n * \"isolated\", or \"none\". When `NoSandboxProvider` is used, the agent runs\n * directly on the host with no container isolation — opt in at your own risk.\n */\nexport type SandboxProvider =\n | BindMountSandboxProvider\n | IsolatedSandboxProvider\n | NoSandboxProvider;\n\n/** @deprecated Use `SandboxProvider` — it now includes `NoSandboxProvider`. */\nexport type AnySandboxProvider = SandboxProvider;\n\n/**\n * Create a bind-mount sandbox provider from a config object.\n * The returned provider can be passed to `run()` or `createSandbox()`.\n */\nexport const createBindMountSandboxProvider = (\n config: BindMountSandboxProviderConfig,\n): BindMountSandboxProvider => ({\n tag: \"bind-mount\",\n name: config.name,\n env: config.env ?? {},\n sandboxHomedir: config.sandboxHomedir,\n create: config.create,\n});\n\n/**\n * Create an isolated sandbox provider from a config object.\n * The returned provider can be passed to `run()` or `createSandbox()`.\n */\nexport const createIsolatedSandboxProvider = (\n config: IsolatedSandboxProviderConfig,\n): IsolatedSandboxProvider => ({\n tag: \"isolated\",\n name: config.name,\n env: config.env ?? {},\n create: config.create,\n});\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
3
|
+
createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// src/shutdownRegistry.ts
|
|
6
|
+
var teardownCallbacks = /* @__PURE__ */ new Set();
|
|
7
|
+
var listenersInstalled = false;
|
|
8
|
+
var runTeardowns = () => {
|
|
9
|
+
for (const teardown of teardownCallbacks) {
|
|
10
|
+
try {
|
|
11
|
+
teardown();
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var handleExit = () => {
|
|
17
|
+
runTeardowns();
|
|
18
|
+
};
|
|
19
|
+
var handleSignal = () => {
|
|
20
|
+
detachListeners();
|
|
21
|
+
runTeardowns();
|
|
22
|
+
process.exit(1);
|
|
23
|
+
};
|
|
24
|
+
var attachListeners = () => {
|
|
25
|
+
if (listenersInstalled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
listenersInstalled = true;
|
|
29
|
+
process.on("exit", handleExit);
|
|
30
|
+
process.on("SIGINT", handleSignal);
|
|
31
|
+
process.on("SIGTERM", handleSignal);
|
|
32
|
+
};
|
|
33
|
+
var detachListeners = () => {
|
|
34
|
+
if (!listenersInstalled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
listenersInstalled = false;
|
|
38
|
+
process.removeListener("exit", handleExit);
|
|
39
|
+
process.removeListener("SIGINT", handleSignal);
|
|
40
|
+
process.removeListener("SIGTERM", handleSignal);
|
|
41
|
+
};
|
|
42
|
+
var registerShutdown = (teardown) => {
|
|
43
|
+
teardownCallbacks.add(teardown);
|
|
44
|
+
attachListeners();
|
|
45
|
+
let active = true;
|
|
46
|
+
return () => {
|
|
47
|
+
if (!active) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
active = false;
|
|
51
|
+
teardownCallbacks.delete(teardown);
|
|
52
|
+
if (teardownCallbacks.size === 0) {
|
|
53
|
+
detachListeners();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { registerShutdown };
|
|
59
|
+
//# sourceMappingURL=chunk-EXYXBRCX.js.map
|
|
60
|
+
//# sourceMappingURL=chunk-EXYXBRCX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shutdownRegistry.ts"],"names":[],"mappings":";;;;;AAsBA,IAAM,iBAAA,uBAAwB,GAAA,EAAsB;AACpD,IAAI,kBAAA,GAAqB,KAAA;AAEzB,IAAM,eAAe,MAAY;AAC/B,EAAA,KAAA,MAAW,YAAY,iBAAA,EAAmB;AACxC,IAAA,IAAI;AACF,MAAA,QAAA,EAAS;AAAA,IACX,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACF,CAAA;AAEA,IAAM,aAAa,MAAY;AAC7B,EAAA,YAAA,EAAa;AACf,CAAA;AAEA,IAAM,eAAe,MAAY;AAG/B,EAAA,eAAA,EAAgB;AAChB,EAAA,YAAA,EAAa;AACb,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAChB,CAAA;AAEA,IAAM,kBAAkB,MAAY;AAClC,EAAA,IAAI,kBAAA,EAAoB;AACtB,IAAA;AAAA,EACF;AACA,EAAA,kBAAA,GAAqB,IAAA;AACrB,EAAA,OAAA,CAAQ,EAAA,CAAG,QAAQ,UAAU,CAAA;AAC7B,EAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,YAAY,CAAA;AACjC,EAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,YAAY,CAAA;AACpC,CAAA;AAEA,IAAM,kBAAkB,MAAY;AAClC,EAAA,IAAI,CAAC,kBAAA,EAAoB;AACvB,IAAA;AAAA,EACF;AACA,EAAA,kBAAA,GAAqB,KAAA;AACrB,EAAA,OAAA,CAAQ,cAAA,CAAe,QAAQ,UAAU,CAAA;AACzC,EAAA,OAAA,CAAQ,cAAA,CAAe,UAAU,YAAY,CAAA;AAC7C,EAAA,OAAA,CAAQ,cAAA,CAAe,WAAW,YAAY,CAAA;AAChD,CAAA;AAUO,IAAM,gBAAA,GAAmB,CAAC,QAAA,KAA6C;AAC5E,EAAA,iBAAA,CAAkB,IAAI,QAAQ,CAAA;AAC9B,EAAA,eAAA,EAAgB;AAEhB,EAAA,IAAI,MAAA,GAAS,IAAA;AACb,EAAA,OAAO,MAAM;AACX,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA;AAAA,IACF;AACA,IAAA,MAAA,GAAS,KAAA;AACT,IAAA,iBAAA,CAAkB,OAAO,QAAQ,CAAA;AACjC,IAAA,IAAI,iBAAA,CAAkB,SAAS,CAAA,EAAG;AAChC,MAAA,eAAA,EAAgB;AAAA,IAClB;AAAA,EACF,CAAA;AACF","file":"chunk-EXYXBRCX.js","sourcesContent":["/**\n * Process-wide shutdown registry.\n *\n * Sandboxes need to run synchronous cleanup (remove a container, print\n * worktree-recovery guidance) when the host process is interrupted. Registering\n * `SIGINT`/`SIGTERM`/`exit` listeners per sandbox makes Node emit a\n * `MaxListenersExceededWarning` once more than ~10 sandboxes exist concurrently.\n *\n * This module installs exactly one listener per signal — no matter how many\n * sandboxes are alive — and fans out to a set of teardown callbacks. On\n * `SIGINT`/`SIGTERM` it runs every teardown and then exits once with code 1;\n * on a plain `exit` it runs every teardown without forcing the exit code.\n */\n\n/**\n * A synchronous cleanup step run during shutdown. It must not call\n * `process.exit` — the registry owns the single exit — and must not rely on\n * async work completing, because a signal handler cannot await before the\n * process exits.\n */\nexport type ShutdownCallback = () => void;\n\nconst teardownCallbacks = new Set<ShutdownCallback>();\nlet listenersInstalled = false;\n\nconst runTeardowns = (): void => {\n for (const teardown of teardownCallbacks) {\n try {\n teardown();\n } catch {\n // Best-effort: one teardown failing must not block the others.\n }\n }\n};\n\nconst handleExit = (): void => {\n runTeardowns();\n};\n\nconst handleSignal = (): void => {\n // Detach first so the synchronous \"exit\" event triggered by process.exit()\n // below does not run the same teardowns a second time.\n detachListeners();\n runTeardowns();\n process.exit(1);\n};\n\nconst attachListeners = (): void => {\n if (listenersInstalled) {\n return;\n }\n listenersInstalled = true;\n process.on(\"exit\", handleExit);\n process.on(\"SIGINT\", handleSignal);\n process.on(\"SIGTERM\", handleSignal);\n};\n\nconst detachListeners = (): void => {\n if (!listenersInstalled) {\n return;\n }\n listenersInstalled = false;\n process.removeListener(\"exit\", handleExit);\n process.removeListener(\"SIGINT\", handleSignal);\n process.removeListener(\"SIGTERM\", handleSignal);\n};\n\n/**\n * Register a teardown to run when the process receives `SIGINT`/`SIGTERM` or\n * exits. The first registration installs the shared listeners; the last\n * unregistration removes them, restoring the default signal behavior.\n *\n * @param teardown Synchronous cleanup to run on shutdown.\n * @returns An idempotent function that unregisters the teardown.\n */\nexport const registerShutdown = (teardown: ShutdownCallback): (() => void) => {\n teardownCallbacks.add(teardown);\n attachListeners();\n\n let active = true;\n return () => {\n if (!active) {\n return;\n }\n active = false;\n teardownCallbacks.delete(teardown);\n if (teardownCallbacks.size === 0) {\n detachListeners();\n }\n };\n};\n"]}
|