@ai-hero/sandcastle 0.10.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.
Files changed (62) hide show
  1. package/README.md +15 -1316
  2. package/dist/LinuxCapability-B_PQfsY_.d.ts +32 -0
  3. package/dist/{SandboxProvider-EkSMuBp8.d.ts → SandboxProvider-YCL97qco.d.ts} +30 -3
  4. package/dist/chunk-4EIVTSOZ.js +93 -0
  5. package/dist/chunk-4EIVTSOZ.js.map +1 -0
  6. package/dist/{chunk-NGBM7T3E.js → chunk-6NQPCXSG.js} +5 -2
  7. package/dist/chunk-6NQPCXSG.js.map +1 -0
  8. package/dist/chunk-767EAJVT.js +112 -0
  9. package/dist/chunk-767EAJVT.js.map +1 -0
  10. package/dist/chunk-7N7AMUYA.js +353 -0
  11. package/dist/chunk-7N7AMUYA.js.map +1 -0
  12. package/dist/{chunk-52CIJF45.js → chunk-A4C2FG74.js} +258 -327
  13. package/dist/chunk-A4C2FG74.js.map +1 -0
  14. package/dist/chunk-J5J5YJ5S.js +50 -0
  15. package/dist/chunk-J5J5YJ5S.js.map +1 -0
  16. package/dist/{chunk-5VM5QZ26.js → chunk-LWNC4UTZ.js} +12097 -3252
  17. package/dist/chunk-LWNC4UTZ.js.map +1 -0
  18. package/dist/chunk-NMQ5Z6YG.js +148 -0
  19. package/dist/chunk-NMQ5Z6YG.js.map +1 -0
  20. package/dist/{chunk-NSFQW6ML.js → chunk-U42XXICG.js} +92 -85
  21. package/dist/chunk-U42XXICG.js.map +1 -0
  22. package/dist/chunk-XCWKLDH4.js +24 -0
  23. package/dist/chunk-XCWKLDH4.js.map +1 -0
  24. package/dist/{chunk-BIWNFKGV.js → chunk-XCYK7I45.js} +2 -2
  25. package/dist/chunk-XCYK7I45.js.map +1 -0
  26. package/dist/index.d.ts +335 -39
  27. package/dist/index.js +2854 -2090
  28. package/dist/index.js.map +1 -1
  29. package/dist/main.js +1006 -627
  30. package/dist/main.js.map +1 -1
  31. package/dist/sandboxes/bwrap.d.ts +58 -0
  32. package/dist/sandboxes/bwrap.js +293 -0
  33. package/dist/sandboxes/bwrap.js.map +1 -0
  34. package/dist/sandboxes/daytona.d.ts +1 -1
  35. package/dist/sandboxes/daytona.js +78 -17
  36. package/dist/sandboxes/daytona.js.map +1 -1
  37. package/dist/sandboxes/docker.d.ts +19 -5
  38. package/dist/sandboxes/docker.js +4 -4
  39. package/dist/sandboxes/no-sandbox.d.ts +2 -2
  40. package/dist/sandboxes/no-sandbox.js +2 -2
  41. package/dist/sandboxes/podman.d.ts +19 -5
  42. package/dist/sandboxes/podman.js +69 -56
  43. package/dist/sandboxes/podman.js.map +1 -1
  44. package/dist/sandboxes/seatbelt.d.ts +65 -0
  45. package/dist/sandboxes/seatbelt.js +422 -0
  46. package/dist/sandboxes/seatbelt.js.map +1 -0
  47. package/dist/sandboxes/vercel.d.ts +13 -6
  48. package/dist/sandboxes/vercel.js +195 -126
  49. package/dist/sandboxes/vercel.js.map +1 -1
  50. package/dist/templates/blank/main.mts +1 -1
  51. package/dist/templates/parallel-planner/main.mts +14 -23
  52. package/dist/templates/parallel-planner-with-review/main.mts +14 -16
  53. package/dist/templates/simple-loop/main.mts +1 -1
  54. package/package.json +34 -10
  55. package/dist/chunk-52CIJF45.js.map +0 -1
  56. package/dist/chunk-5VM5QZ26.js.map +0 -1
  57. package/dist/chunk-72UVAC7B.js +0 -99
  58. package/dist/chunk-72UVAC7B.js.map +0 -1
  59. package/dist/chunk-BIWNFKGV.js.map +0 -1
  60. package/dist/chunk-NGBM7T3E.js.map +0 -1
  61. package/dist/chunk-NSFQW6ML.js.map +0 -1
  62. package/dist/mountUtils-CCA-bbpK.d.ts +0 -25
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Shared mount utilities for Docker and Podman sandbox providers.
3
+ *
4
+ * Handles host/sandbox path resolution, tilde expansion, user mount
5
+ * validation, image naming, and Windows path normalization.
6
+ */
7
+
8
+ /**
9
+ * SELinux volume label suffix applied to bind mounts.
10
+ *
11
+ * - `"z"` — shared label. No-op on non-SELinux systems.
12
+ * - `"Z"` — private label; only this container can access the mount.
13
+ * - `false` — disable labeling entirely.
14
+ */
15
+ type SelinuxLabel = "z" | "Z" | false;
16
+ /**
17
+ * Derive the default image name from the repo directory.
18
+ * Returns `sandcastle:<dir-name>` where dir-name is the last path segment,
19
+ * lowercased and sanitized for image tag rules.
20
+ *
21
+ * Handles both POSIX (`/`) and Windows (`\`) path separators.
22
+ */
23
+ declare const defaultImageName: (repoDir: string) => string;
24
+
25
+ /**
26
+ * A Linux capability name as `docker run --cap-drop` and `podman run --cap-drop`
27
+ * accept it: without the `CAP_` prefix (see capabilities(7)), or `"ALL"` for
28
+ * every capability.
29
+ */
30
+ type LinuxCapability = "ALL" | "AUDIT_CONTROL" | "AUDIT_READ" | "AUDIT_WRITE" | "BLOCK_SUSPEND" | "BPF" | "CHECKPOINT_RESTORE" | "CHOWN" | "DAC_OVERRIDE" | "DAC_READ_SEARCH" | "FOWNER" | "FSETID" | "IPC_LOCK" | "IPC_OWNER" | "KILL" | "LEASE" | "LINUX_IMMUTABLE" | "MAC_ADMIN" | "MAC_OVERRIDE" | "MKNOD" | "NET_ADMIN" | "NET_BIND_SERVICE" | "NET_BROADCAST" | "NET_RAW" | "PERFMON" | "SETFCAP" | "SETGID" | "SETPCAP" | "SETUID" | "SYS_ADMIN" | "SYS_BOOT" | "SYS_CHROOT" | "SYS_MODULE" | "SYS_NICE" | "SYS_PACCT" | "SYS_PTRACE" | "SYS_RAWIO" | "SYS_RESOURCE" | "SYS_TIME" | "SYS_TTY_CONFIG" | "SYSLOG" | "WAKE_ALARM";
31
+
32
+ export { type LinuxCapability as L, type SelinuxLabel as S, defaultImageName as d };
@@ -21,6 +21,26 @@ interface InteractiveExecOptions {
21
21
  interface BindMountSandboxHandle {
22
22
  /** Absolute path to the worktree inside the sandbox. */
23
23
  readonly worktreePath: string;
24
+ /**
25
+ * The id a supervisor outside this process can use to address the sandbox
26
+ * with the runtime's own tools, e.g. `docker()` and `podman()` set it to the
27
+ * container name (`docker rm -f <sandboxId>`). Surfaced as
28
+ * `Sandbox.sandboxId`. Omit it when there is nothing outside the process to
29
+ * address, as for the native `bwrap()` and `seatbelt()` sandboxes, whose
30
+ * sandbox is a child process of this one.
31
+ */
32
+ readonly sandboxId?: string;
33
+ /**
34
+ * Absolute path to the agent's home directory, as commands running inside
35
+ * the sandbox see it. Sandcastle runs commands there to find and place agent
36
+ * session files. Omit when it is `/home/agent`, as in the Docker image.
37
+ */
38
+ readonly sandboxHomedir?: string;
39
+ /**
40
+ * Absolute path to a writable temp directory, as commands running inside
41
+ * the sandbox see it. Omit when it is `/tmp`.
42
+ */
43
+ readonly sandboxTmpdir?: string;
24
44
  /**
25
45
  * Execute a command in the sandbox.
26
46
  *
@@ -62,11 +82,11 @@ interface BindMountCreateOptions {
62
82
  /** Host-side path to the original repo root. */
63
83
  readonly hostRepoPath: string;
64
84
  /** Volume mounts to apply (host:sandbox pairs). */
65
- readonly mounts: Array<{
85
+ readonly mounts: {
66
86
  hostPath: string;
67
87
  sandboxPath: string;
68
88
  readonly?: boolean;
69
- }>;
89
+ }[];
70
90
  /** Environment variables to inject into the sandbox. */
71
91
  readonly env: Record<string, string>;
72
92
  }
@@ -89,6 +109,13 @@ interface BindMountSandboxProviderConfig {
89
109
  interface IsolatedSandboxHandle {
90
110
  /** Absolute path to the worktree inside the sandbox. */
91
111
  readonly worktreePath: string;
112
+ /**
113
+ * The vendor's id for the sandbox, so a supervisor outside this process can
114
+ * address it with the vendor's own CLI or API, e.g. `vercel()` and
115
+ * `daytona()` set it to the Vercel and Daytona sandbox ids. Surfaced as
116
+ * `Sandbox.sandboxId`. Omit it when the provider has no such id.
117
+ */
118
+ readonly sandboxId?: string;
92
119
  /**
93
120
  * Execute a command in the sandbox.
94
121
  *
@@ -240,4 +267,4 @@ declare const createBindMountSandboxProvider: (config: BindMountSandboxProviderC
240
267
  */
241
268
  declare const createIsolatedSandboxProvider: (config: IsolatedSandboxProviderConfig) => IsolatedSandboxProvider;
242
269
 
243
- export { type AnySandboxProvider as A, type BindMountSandboxHandle as B, type ExecResult as E, type HeadBranchStrategy as H, type IsolatedSandboxProvider as I, type MergeToHeadBranchStrategy as M, type NoSandboxProvider as N, type SandboxProvider as S, type BranchStrategy as a, type NamedBranchStrategy as b, type BindMountBranchStrategy as c, type BindMountCreateOptions as d, type BindMountSandboxProvider as e, type BindMountSandboxProviderConfig as f, type InteractiveExecOptions as g, type IsolatedBranchStrategy as h, type IsolatedCreateOptions as i, type IsolatedSandboxHandle as j, type IsolatedSandboxProviderConfig as k, type NoSandboxBranchStrategy as l, type NoSandboxHandle as m, createBindMountSandboxProvider as n, createIsolatedSandboxProvider as o };
270
+ export { type AnySandboxProvider as A, type BindMountSandboxProvider as B, type ExecResult as E, type HeadBranchStrategy as H, type IsolatedSandboxProvider as I, type MergeToHeadBranchStrategy as M, type NoSandboxProvider as N, type SandboxProvider as S, type BindMountSandboxHandle as a, type BranchStrategy as b, type NamedBranchStrategy as c, type BindMountBranchStrategy as d, type BindMountCreateOptions as e, type BindMountSandboxProviderConfig as f, type InteractiveExecOptions as g, type IsolatedBranchStrategy as h, type IsolatedCreateOptions as i, type IsolatedSandboxHandle as j, type IsolatedSandboxProviderConfig as k, type NoSandboxBranchStrategy as l, type NoSandboxHandle as m, createBindMountSandboxProvider as n, createIsolatedSandboxProvider as o };
@@ -0,0 +1,93 @@
1
+ import { createRequire } from 'node:module';
2
+ import { Effect_exports, Display } from './chunk-LWNC4UTZ.js';
3
+
4
+ createRequire(import.meta.url);
5
+
6
+ // src/ErrorHandler.ts
7
+ var formatErrorMessage = (error) => {
8
+ switch (error._tag) {
9
+ case "ExecError": {
10
+ return `Command failed in sandbox (${error.command}): ${error.message}`;
11
+ }
12
+ case "ExecHostError": {
13
+ return `Command failed on host (${error.command}): ${error.message}`;
14
+ }
15
+ case "CopyError": {
16
+ return `File copy failed: ${error.message}`;
17
+ }
18
+ case "DockerError": {
19
+ return `Docker operation failed: ${error.message}. Is Docker running?`;
20
+ }
21
+ case "PodmanError": {
22
+ return `Podman operation failed: ${error.message}. Is Podman running?`;
23
+ }
24
+ case "SyncError": {
25
+ return `Git sync failed: ${error.message}`;
26
+ }
27
+ case "WorktreeError": {
28
+ return `Git worktree operation failed: ${error.message}`;
29
+ }
30
+ case "PromptError": {
31
+ return `Failed to resolve prompt: ${error.message}`;
32
+ }
33
+ case "AgentError": {
34
+ return `Agent invocation failed: ${error.message}`;
35
+ }
36
+ case "ConfigDirError":
37
+ case "InitError":
38
+ case "AgentIdleTimeoutError":
39
+ case "WorktreeTimeoutError":
40
+ case "ContainerStartTimeoutError":
41
+ case "CopyToWorktreeTimeoutError":
42
+ case "CopyToWorktreeError":
43
+ case "SyncInTimeoutError":
44
+ case "HookTimeoutError":
45
+ case "GitSetupTimeoutError":
46
+ case "PromptExpansionTimeoutError":
47
+ case "CommitCollectionTimeoutError":
48
+ case "MergeToHostTimeoutError":
49
+ case "SessionCaptureError":
50
+ case "SyncOutPathError":
51
+ case "CwdError":
52
+ case "ImageNotFoundError": {
53
+ return error.message;
54
+ }
55
+ }
56
+ };
57
+ var showErrorAndExit = (error) => Effect_exports.gen(function* () {
58
+ const d = yield* Display;
59
+ yield* d.status(formatErrorMessage(error), "error");
60
+ return yield* Effect_exports.sync(() => process.exit(1));
61
+ });
62
+ var withFriendlyErrors = (effect) => Effect_exports.catchTags(effect, {
63
+ ExecError: showErrorAndExit,
64
+ ExecHostError: showErrorAndExit,
65
+ CopyError: showErrorAndExit,
66
+ DockerError: showErrorAndExit,
67
+ PodmanError: showErrorAndExit,
68
+ SyncError: showErrorAndExit,
69
+ SyncOutPathError: showErrorAndExit,
70
+ WorktreeError: showErrorAndExit,
71
+ PromptError: showErrorAndExit,
72
+ AgentError: showErrorAndExit,
73
+ ConfigDirError: showErrorAndExit,
74
+ InitError: showErrorAndExit,
75
+ AgentIdleTimeoutError: showErrorAndExit,
76
+ WorktreeTimeoutError: showErrorAndExit,
77
+ ContainerStartTimeoutError: showErrorAndExit,
78
+ CopyToWorktreeTimeoutError: showErrorAndExit,
79
+ CopyToWorktreeError: showErrorAndExit,
80
+ SyncInTimeoutError: showErrorAndExit,
81
+ HookTimeoutError: showErrorAndExit,
82
+ GitSetupTimeoutError: showErrorAndExit,
83
+ PromptExpansionTimeoutError: showErrorAndExit,
84
+ CommitCollectionTimeoutError: showErrorAndExit,
85
+ MergeToHostTimeoutError: showErrorAndExit,
86
+ SessionCaptureError: showErrorAndExit,
87
+ CwdError: showErrorAndExit,
88
+ ImageNotFoundError: showErrorAndExit
89
+ });
90
+
91
+ export { formatErrorMessage, withFriendlyErrors };
92
+ //# sourceMappingURL=chunk-4EIVTSOZ.js.map
93
+ //# sourceMappingURL=chunk-4EIVTSOZ.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,CAA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BAAA,GAAqB,CAChC,MAAA,KAEA,cAAA,CAAO,UAAU,MAAA,EAA6C;AAAA,EAC5D,SAAA,EAAW,gBAAA;AAAA,EACX,aAAA,EAAe,gBAAA;AAAA,EACf,SAAA,EAAW,gBAAA;AAAA,EACX,WAAA,EAAa,gBAAA;AAAA,EACb,WAAA,EAAa,gBAAA;AAAA,EACb,SAAA,EAAW,gBAAA;AAAA,EACX,gBAAA,EAAkB,gBAAA;AAAA,EAClB,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-4EIVTSOZ.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"]}
@@ -62,6 +62,9 @@ var BoundedTail = class {
62
62
  this.items.push(bounded);
63
63
  while (this.totalChars > this.maxChars && this.items.length > 1) {
64
64
  const dropped = this.items.shift();
65
+ if (dropped === void 0) {
66
+ break;
67
+ }
65
68
  this.totalChars -= dropped.length + this.separator.length;
66
69
  }
67
70
  }
@@ -72,5 +75,5 @@ var BoundedTail = class {
72
75
  };
73
76
 
74
77
  export { BoundedTail, MAX_TAIL_CHARS, __commonJS, __export, __reExport, __require, __toESM };
75
- //# sourceMappingURL=chunk-NGBM7T3E.js.map
76
- //# sourceMappingURL=chunk-NGBM7T3E.js.map
78
+ //# sourceMappingURL=chunk-6NQPCXSG.js.map
79
+ //# sourceMappingURL=chunk-6NQPCXSG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/boundedTail.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBO,IAAM,iBAAiB,EAAA,GAAK;AAa5B,IAAM,cAAN,MAAkB;AAAA,EACN,QAAkB,EAAC;AAAA,EAC5B,UAAA,GAAa,CAAA;AAAA,EACJ,QAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjB,WAAA,CAAY,QAAA,GAAmB,cAAA,EAAgB,SAAA,GAAY,EAAA,EAAI;AAC7D,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAChB,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AAAA,EACnB;AAAA;AAAA,EAGA,KAAK,IAAA,EAAoB;AACvB,IAAA,MAAM,OAAA,GACJ,IAAA,CAAK,MAAA,GAAS,IAAA,CAAK,QAAA,GACf,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,MAAA,GAAS,IAAA,CAAK,QAAQ,CAAA,GACtC,IAAA;AACN,IAAA,IAAA,CAAK,UAAA,IACH,QAAQ,MAAA,IAAU,IAAA,CAAK,MAAM,MAAA,GAAS,CAAA,GAAI,IAAA,CAAK,SAAA,CAAU,MAAA,GAAS,CAAA,CAAA;AACpE,IAAA,IAAA,CAAK,KAAA,CAAM,KAAK,OAAO,CAAA;AACvB,IAAA,OAAO,KAAK,UAAA,GAAa,IAAA,CAAK,YAAY,IAAA,CAAK,KAAA,CAAM,SAAS,CAAA,EAAG;AAC/D,MAAA,MAAM,OAAA,GAAU,IAAA,CAAK,KAAA,CAAM,KAAA,EAAM;AACjC,MAAA,IAAI,YAAY,MAAA,EAAW;AACzB,QAAA;AAAA,MACF;AACA,MAAA,IAAA,CAAK,UAAA,IAAc,OAAA,CAAQ,MAAA,GAAS,IAAA,CAAK,SAAA,CAAU,MAAA;AAAA,IACrD;AAAA,EACF;AAAA;AAAA,EAGA,QAAA,GAAmB;AACjB,IAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,SAAS,CAAA;AAAA,EACvC;AACF","file":"chunk-6NQPCXSG.js","sourcesContent":["/**\n * A bounded, rolling tail of streamed output — a pure, provider-agnostic\n * utility shared by every sandbox provider that streams `exec` output.\n *\n * When a provider streams output line-by-line, it accumulates the stream only\n * to build the returned `ExecResult.stdout`/`stderr`. Consumers read just the\n * tail of that value (e.g. the last lines of an error, or a fallback for the\n * agent's final result), so retaining the whole stream is unnecessary — and,\n * once the accumulated string passes V8's ~512MB max string length, fatal: a\n * naive `chunks.join()` throws `RangeError: Invalid string length`, which on a\n * long agent run crashes the whole orchestration.\n */\n\n/**\n * Default maximum number of characters retained in a bounded output tail.\n *\n * 64KiB sits comfortably above any agent completion signal or structured-output\n * payload while staying far below V8's max string length.\n */\nexport const MAX_TAIL_CHARS = 64 * 1024;\n\n/**\n * A fixed-size rolling tail of strings, bounded by total character length.\n *\n * `push` appends to the tail; once the joined length would exceed `maxChars`,\n * the oldest items are dropped from the front. A single item longer than\n * `maxChars` is truncated to its own tail, so a newline-free blob can't\n * overflow on one push. `toString` joins the retained items, and its length is\n * always at most `maxChars`.\n *\n * The running length counter is encapsulated so callers can't desync it.\n */\nexport class BoundedTail {\n private readonly items: string[] = [];\n private totalChars = 0;\n private readonly maxChars: number;\n private readonly separator: string;\n\n /**\n * @param maxChars Maximum length of the joined tail. Defaults to {@link MAX_TAIL_CHARS}.\n * @param separator String placed between items by {@link toString}. Must match\n * how the caller would otherwise have joined the accumulated chunks (e.g.\n * `\"\\n\"` for line streams, `\"\"` for raw chunk streams).\n */\n constructor(maxChars: number = MAX_TAIL_CHARS, separator = \"\") {\n this.maxChars = maxChars;\n this.separator = separator;\n }\n\n /** Append one item to the tail, evicting oldest items to stay within budget. */\n push(item: string): void {\n const bounded =\n item.length > this.maxChars\n ? item.slice(item.length - this.maxChars)\n : item;\n this.totalChars +=\n bounded.length + (this.items.length > 0 ? this.separator.length : 0);\n this.items.push(bounded);\n while (this.totalChars > this.maxChars && this.items.length > 1) {\n const dropped = this.items.shift();\n if (dropped === undefined) {\n break;\n }\n this.totalChars -= dropped.length + this.separator.length;\n }\n }\n\n /** Join the retained tail into a single string (length ≤ `maxChars`). */\n toString(): string {\n return this.items.join(this.separator);\n }\n}\n"]}
@@ -0,0 +1,112 @@
1
+ import { createRequire } from 'node:module';
2
+ import { NativeSandboxUnavailableError } from './chunk-A4C2FG74.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
+ //# s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IAAA,EAAK;AAClB,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,uEAAuE,MAAM,CAAA;AAAA,GACxF;AACF,CAAA;AAEA,IAAM,KAAA,GAAQ,MACZ,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-767EAJVT.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"]}