@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SandboxProvider.ts"],"names":[],"mappings":";;;;;AA+UO,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-XCYK7I45.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()` and\n * `daytona()` set it to the Vercel and Daytona sandbox 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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { a as BindMountSandboxHandle, S as SandboxProvider, b as BranchStrategy, E as ExecResult, M as MergeToHeadBranchStrategy, c as NamedBranchStrategy } from './SandboxProvider-YCL97qco.js';
|
|
2
|
+
export { A as AnySandboxProvider, d as BindMountBranchStrategy, e as BindMountCreateOptions, B as BindMountSandboxProvider, f as BindMountSandboxProviderConfig, H as HeadBranchStrategy, g as InteractiveExecOptions, h as IsolatedBranchStrategy, i as IsolatedCreateOptions, j as IsolatedSandboxHandle, I as IsolatedSandboxProvider, k as IsolatedSandboxProviderConfig, l as NoSandboxBranchStrategy, m as NoSandboxHandle, N as NoSandboxProvider, n as createBindMountSandboxProvider, o as createIsolatedSandboxProvider } from './SandboxProvider-YCL97qco.js';
|
|
3
3
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
export { M as MountConfig } from './MountConfig-CmXclHA5.js';
|
|
5
5
|
|
|
@@ -26,8 +26,11 @@ interface HostSessionLookup {
|
|
|
26
26
|
readonly searchedRoot: string;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Encode a cwd into the Claude Code `~/.claude/projects/<encoded>/` layout
|
|
30
|
-
*
|
|
29
|
+
* Encode a cwd into the Claude Code `~/.claude/projects/<encoded>/` layout,
|
|
30
|
+
* matching Claude Code's own naming: every character that isn't an ASCII
|
|
31
|
+
* letter or digit becomes a hyphen (so `/`, `\`, `:` and `.` all do), and a
|
|
32
|
+
* name longer than 200 characters is cut to 200 and suffixed with a hash of
|
|
33
|
+
* the full path. A trailing path separator is ignored.
|
|
31
34
|
*/
|
|
32
35
|
declare const encodeProjectPath: (cwd: string) => string;
|
|
33
36
|
/** Absolute host path to a Claude session JSONL file. */
|
|
@@ -46,8 +49,8 @@ declare const findClaudeSessionOnHost: (id: string, projectsDir?: string) => Pro
|
|
|
46
49
|
*/
|
|
47
50
|
declare const transferClaudeSession: (jsonl: string, fromCwd: string, toCwd: string) => string;
|
|
48
51
|
/**
|
|
49
|
-
* Locate a Codex session rollout file on the host by its id,
|
|
50
|
-
* date-nested
|
|
52
|
+
* Locate a Codex session rollout file on the host by its id, scanning the
|
|
53
|
+
* date-nested `YYYY/MM/DD/` directories depth-first.
|
|
51
54
|
*/
|
|
52
55
|
declare const findCodexSessionOnHost: (id: string, sessionsDir?: string) => Promise<HostSessionLookup>;
|
|
53
56
|
/**
|
|
@@ -57,9 +60,33 @@ declare const findCodexSessionOnHost: (id: string, sessionsDir?: string) => Prom
|
|
|
57
60
|
*/
|
|
58
61
|
declare const transferCodexSession: (jsonl: string, fromCwd: string, toCwd: string) => string;
|
|
59
62
|
|
|
63
|
+
/**
|
|
64
|
+
* How full an iteration's context window was: the input side of its LAST
|
|
65
|
+
* model call, cache reads and cache writes included (see ADR 0023).
|
|
66
|
+
*
|
|
67
|
+
* Each model call's input already holds the whole conversation so far, so the
|
|
68
|
+
* last call is the context size. Never sum calls, and never use a total the
|
|
69
|
+
* agent reports for a turn or a session: those grow with every tool
|
|
70
|
+
* round-trip and can exceed the window.
|
|
71
|
+
*/
|
|
72
|
+
interface ContextWindow {
|
|
73
|
+
/** Input tokens of the last model call, cached and uncached together. */
|
|
74
|
+
readonly tokens: number;
|
|
75
|
+
/** The model's context window size, only when the agent itself reports it. */
|
|
76
|
+
readonly limit?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
type ParsedStreamEvent = {
|
|
61
80
|
type: "text";
|
|
62
81
|
text: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The input side of ONE model call (cache included), emitted once per call.
|
|
85
|
+
* The Orchestrator keeps the last one per iteration; see ContextWindow.
|
|
86
|
+
*/
|
|
87
|
+
| {
|
|
88
|
+
type: "context_window";
|
|
89
|
+
contextWindow: ContextWindow;
|
|
63
90
|
} | {
|
|
64
91
|
type: "result";
|
|
65
92
|
result: string;
|
|
@@ -73,6 +100,15 @@ type ParsedStreamEvent = {
|
|
|
73
100
|
} | {
|
|
74
101
|
type: "usage";
|
|
75
102
|
usage: IterationUsage;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The agent reported a failure in its own stream (an API rejection, a
|
|
106
|
+
* failed turn). Some agents exit 0 after one, so the Orchestrator fails the
|
|
107
|
+
* run on it whatever the exit code.
|
|
108
|
+
*/
|
|
109
|
+
| {
|
|
110
|
+
type: "error";
|
|
111
|
+
message: string;
|
|
76
112
|
};
|
|
77
113
|
/** Options passed to buildPrintCommand and buildInteractiveArgs. */
|
|
78
114
|
interface AgentCommandOptions {
|
|
@@ -82,7 +118,7 @@ interface AgentCommandOptions {
|
|
|
82
118
|
readonly resumeSession?: string;
|
|
83
119
|
/**
|
|
84
120
|
* When true alongside `resumeSession`, the agent should fork the session
|
|
85
|
-
* instead of mutating it — Claude's `--fork-session`, Codex's
|
|
121
|
+
* instead of mutating it — Claude's `--fork-session`, pi's `--fork`, Codex's
|
|
86
122
|
* `codex exec fork`. The parent session JSONL is left intact and the agent
|
|
87
123
|
* writes a new session under a fresh id.
|
|
88
124
|
*/
|
|
@@ -131,6 +167,12 @@ interface AgentSessionStorage {
|
|
|
131
167
|
* directory that was searched (for not-found errors).
|
|
132
168
|
*/
|
|
133
169
|
findByIdOnHost(sessionId: string): Promise<HostSessionLookup>;
|
|
170
|
+
/**
|
|
171
|
+
* `false` when the agent's CLI can resume a session but has no native fork:
|
|
172
|
+
* `.fork()` then throws `ForkNotSupportedError` before any sandbox starts.
|
|
173
|
+
* Omitted means the agent forks.
|
|
174
|
+
*/
|
|
175
|
+
readonly canFork?: boolean;
|
|
134
176
|
}
|
|
135
177
|
interface AgentProvider {
|
|
136
178
|
readonly name: string;
|
|
@@ -145,10 +187,21 @@ interface AgentProvider {
|
|
|
145
187
|
parseStreamLine(line: string): ParsedStreamEvent[];
|
|
146
188
|
/** Parse token usage from the captured session JSONL content. Only implemented by Claude Code. */
|
|
147
189
|
parseSessionUsage?(content: string): IterationUsage | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Parse the last model call's context window from the captured session
|
|
192
|
+
* JSONL. For agents whose stream has no per-call figure (codex). Overrides
|
|
193
|
+
* the stream's `context_window` events when it returns a value.
|
|
194
|
+
*/
|
|
195
|
+
parseSessionContextWindow?(content: string): ContextWindow | undefined;
|
|
148
196
|
}
|
|
149
197
|
/** Options for the pi agent provider. */
|
|
150
198
|
interface PiOptions {
|
|
151
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Reasoning effort level. Maps to the CLI's --thinking flag. When omitted,
|
|
201
|
+
* no flag is passed and pi uses its own default (`medium`), which some
|
|
202
|
+
* models reject: with pi 0.73.1, `anthropic/claude-haiku-5-5` returns a 400.
|
|
203
|
+
* Pass `"off"` for those.
|
|
204
|
+
*/
|
|
152
205
|
readonly thinking?: "off" | "minimal" | "low" | "medium" | "high" | "xhigh";
|
|
153
206
|
/** Environment variables injected by this agent provider. */
|
|
154
207
|
readonly env?: Record<string, string>;
|
|
@@ -193,8 +246,17 @@ declare const codex: (model: string, options?: CodexOptions) => AgentProvider &
|
|
|
193
246
|
interface CursorOptions {
|
|
194
247
|
/** Environment variables injected by this agent provider. */
|
|
195
248
|
readonly env?: Record<string, string>;
|
|
249
|
+
/** When false, session capture is disabled. Default: true. */
|
|
250
|
+
readonly captureSessions?: boolean;
|
|
251
|
+
/** Override Cursor `chats` directories for tests or non-standard installs. */
|
|
252
|
+
readonly sessionStorage?: {
|
|
253
|
+
readonly hostChatsDir?: string;
|
|
254
|
+
readonly sandboxChatsDir?: string;
|
|
255
|
+
};
|
|
196
256
|
}
|
|
197
|
-
declare const cursor: (model: string, options?: CursorOptions) => AgentProvider
|
|
257
|
+
declare const cursor: (model: string, options?: CursorOptions) => AgentProvider & {
|
|
258
|
+
readonly sessionStorage: AgentSessionStorage;
|
|
259
|
+
};
|
|
198
260
|
/** Options for the opencode agent provider. */
|
|
199
261
|
interface OpenCodeOptions {
|
|
200
262
|
/** Provider-specific reasoning effort variant (e.g. "high", "max", "low", "minimal"). */
|
|
@@ -207,16 +269,34 @@ interface OpenCodeOptions {
|
|
|
207
269
|
readonly agent?: string;
|
|
208
270
|
/** Environment variables injected by this agent provider. */
|
|
209
271
|
readonly env?: Record<string, string>;
|
|
272
|
+
/** When false, session capture is disabled. Default: true. */
|
|
273
|
+
readonly captureSessions?: boolean;
|
|
274
|
+
/** Override where session exports live, for tests or non-standard installs. */
|
|
275
|
+
readonly sessionStorage?: {
|
|
276
|
+
readonly hostSessionsDir?: string;
|
|
277
|
+
readonly sandboxExportDir?: string;
|
|
278
|
+
};
|
|
210
279
|
}
|
|
211
|
-
declare const opencode: (model: string, options?: OpenCodeOptions) => AgentProvider
|
|
280
|
+
declare const opencode: (model: string, options?: OpenCodeOptions) => AgentProvider & {
|
|
281
|
+
readonly sessionStorage: AgentSessionStorage;
|
|
282
|
+
};
|
|
212
283
|
/** Options for the GitHub Copilot CLI agent provider. */
|
|
213
284
|
interface CopilotOptions {
|
|
214
285
|
/** Reasoning effort level. Maps to the CLI's --effort flag. */
|
|
215
286
|
readonly effort?: "low" | "medium" | "high";
|
|
216
287
|
/** Environment variables injected by this agent provider. */
|
|
217
288
|
readonly env?: Record<string, string>;
|
|
289
|
+
/** When false, session capture is disabled. Default: true. */
|
|
290
|
+
readonly captureSessions?: boolean;
|
|
291
|
+
/** Override Copilot `session-state` directories for tests or non-standard installs. */
|
|
292
|
+
readonly sessionStorage?: {
|
|
293
|
+
readonly hostSessionsDir?: string;
|
|
294
|
+
readonly sandboxSessionsDir?: string;
|
|
295
|
+
};
|
|
218
296
|
}
|
|
219
|
-
declare const copilot: (model: string, options?: CopilotOptions) => AgentProvider
|
|
297
|
+
declare const copilot: (model: string, options?: CopilotOptions) => AgentProvider & {
|
|
298
|
+
readonly sessionStorage: AgentSessionStorage;
|
|
299
|
+
};
|
|
220
300
|
interface ClaudeCodeOptions {
|
|
221
301
|
readonly effort?: "low" | "medium" | "high" | "xhigh" | "max";
|
|
222
302
|
/** Environment variables injected by this agent provider. */
|
|
@@ -271,25 +351,25 @@ type AgentStreamEvent = {
|
|
|
271
351
|
readonly timestamp: Date;
|
|
272
352
|
};
|
|
273
353
|
|
|
274
|
-
|
|
354
|
+
interface SandboxHooks {
|
|
275
355
|
readonly host?: {
|
|
276
|
-
readonly onWorktreeReady?:
|
|
356
|
+
readonly onWorktreeReady?: readonly {
|
|
277
357
|
readonly command: string;
|
|
278
358
|
readonly timeoutMs?: number;
|
|
279
|
-
}
|
|
280
|
-
readonly onSandboxReady?:
|
|
359
|
+
}[];
|
|
360
|
+
readonly onSandboxReady?: readonly {
|
|
281
361
|
readonly command: string;
|
|
282
362
|
readonly timeoutMs?: number;
|
|
283
|
-
}
|
|
363
|
+
}[];
|
|
284
364
|
};
|
|
285
365
|
readonly sandbox?: {
|
|
286
|
-
readonly onSandboxReady?:
|
|
366
|
+
readonly onSandboxReady?: readonly {
|
|
287
367
|
readonly command: string;
|
|
288
368
|
readonly sudo?: boolean;
|
|
289
369
|
readonly timeoutMs?: number;
|
|
290
|
-
}
|
|
370
|
+
}[];
|
|
291
371
|
};
|
|
292
|
-
}
|
|
372
|
+
}
|
|
293
373
|
|
|
294
374
|
/** Per-iteration result carrying an optional session ID. */
|
|
295
375
|
interface IterationResult {
|
|
@@ -299,6 +379,8 @@ interface IterationResult {
|
|
|
299
379
|
readonly sessionFilePath?: string;
|
|
300
380
|
/** Token usage snapshot from the last assistant message in the session, or undefined when capture is disabled or provider does not support usage parsing. */
|
|
301
381
|
readonly usage?: IterationUsage;
|
|
382
|
+
/** Input tokens of the iteration's last model call (cache included), plus the model's limit when the agent reports it. Undefined when the agent reports no per-call figure. */
|
|
383
|
+
readonly contextWindow?: ContextWindow;
|
|
302
384
|
}
|
|
303
385
|
|
|
304
386
|
/**
|
|
@@ -344,7 +426,7 @@ interface OutputStringDefinition {
|
|
|
344
426
|
readonly maxRetries?: number;
|
|
345
427
|
}
|
|
346
428
|
/** Union of all output definition shapes accepted by `run()`. */
|
|
347
|
-
type OutputDefinition = OutputObjectDefinition<
|
|
429
|
+
type OutputDefinition = OutputObjectDefinition<unknown> | OutputStringDefinition;
|
|
348
430
|
/**
|
|
349
431
|
* Helpers for declaring structured output on `run()`.
|
|
350
432
|
*
|
|
@@ -565,7 +647,8 @@ interface RunOptions<A extends AgentProvider = AgentProvider> {
|
|
|
565
647
|
* - Phase boundaries (between iterations) also check the signal.
|
|
566
648
|
* - The rejected promise surfaces `signal.reason` via
|
|
567
649
|
* `signal.throwIfAborted()` — no Sandcastle-specific wrapping.
|
|
568
|
-
* - The worktree is preserved on disk after abort
|
|
650
|
+
* - The worktree is preserved on disk after abort, even when it has no
|
|
651
|
+
* uncommitted changes, and its path is printed to stderr.
|
|
569
652
|
*/
|
|
570
653
|
readonly signal?: AbortSignal;
|
|
571
654
|
/** Override default timeouts for built-in lifecycle steps. Unset keys keep their defaults. */
|
|
@@ -606,7 +689,9 @@ interface RunResult {
|
|
|
606
689
|
/** Host path to the preserved worktree, set when the run succeeded but the worktree had uncommitted changes. */
|
|
607
690
|
readonly preservedWorktreePath?: string;
|
|
608
691
|
/** Continue the last captured agent session for exactly one iteration.
|
|
609
|
-
* Present only when the provider supports resume (`sessionStorage` populated).
|
|
692
|
+
* Present only when the provider supports resume (`sessionStorage` populated).
|
|
693
|
+
* `output` and `promptArgs` are not inherited: pass `output` again to get
|
|
694
|
+
* structured output from the follow-up (its prompt must contain the tag). */
|
|
610
695
|
readonly resume?: (prompt: string, options?: ResumeRunResultOptions) => Promise<RunResult>;
|
|
611
696
|
/**
|
|
612
697
|
* Fork the last captured agent session for exactly one iteration: the
|
|
@@ -619,6 +704,8 @@ interface RunResult {
|
|
|
619
704
|
* sandbox. Safe concurrent fan-out (`Promise.all([r.fork(a), r.fork(b)])`)
|
|
620
705
|
* requires the caller to give each fork a distinct `branch` — `head` and
|
|
621
706
|
* `merge-to-head` are not safe for concurrent forks. See ADR 0018.
|
|
707
|
+
*
|
|
708
|
+
* Like `resume`, `output` and `promptArgs` are not inherited.
|
|
622
709
|
*/
|
|
623
710
|
readonly fork?: (prompt: string, options?: ResumeRunResultOptions) => Promise<RunResult>;
|
|
624
711
|
}
|
|
@@ -641,7 +728,7 @@ interface InteractiveOptions {
|
|
|
641
728
|
/** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
|
|
642
729
|
readonly agent: AgentProvider;
|
|
643
730
|
/** Sandbox provider (e.g. docker(), noSandbox()). */
|
|
644
|
-
readonly sandbox?:
|
|
731
|
+
readonly sandbox?: SandboxProvider;
|
|
645
732
|
/** Inline prompt string (mutually exclusive with promptFile). */
|
|
646
733
|
readonly prompt?: string;
|
|
647
734
|
/** Path to a prompt file (mutually exclusive with prompt). */
|
|
@@ -843,6 +930,27 @@ interface Sandbox {
|
|
|
843
930
|
readonly branch: string;
|
|
844
931
|
/** Host path to the worktree. */
|
|
845
932
|
readonly worktreePath: string;
|
|
933
|
+
/**
|
|
934
|
+
* The provider's id for this sandbox, for a supervisor outside this process
|
|
935
|
+
* (a run registry, a kill step for stuck runs) to address it with the
|
|
936
|
+
* provider's own tools:
|
|
937
|
+
*
|
|
938
|
+
* - `docker()`: the container name: `docker inspect <sandboxId>`,
|
|
939
|
+
* `docker rm -f <sandboxId>`.
|
|
940
|
+
* - `podman()`: the container name: `podman inspect <sandboxId>`,
|
|
941
|
+
* `podman rm -f <sandboxId>`.
|
|
942
|
+
* - `vercel()`: the Vercel sandbox's id (its `name` from `@vercel/sandbox`
|
|
943
|
+
* 2 on, its `sandboxId` in 1.x): pass it to the SDK's `Sandbox.get()`,
|
|
944
|
+
* then call `stop()`.
|
|
945
|
+
* - `daytona()`: the Daytona sandbox id: `daytona.get(<sandboxId>)`, then
|
|
946
|
+
* `delete()`, from `@daytona/sdk`.
|
|
947
|
+
* - A custom provider: whatever its handle's `sandboxId` is.
|
|
948
|
+
*
|
|
949
|
+
* `undefined` for `noSandbox()` and the native `bwrap()` and `seatbelt()`
|
|
950
|
+
* sandboxes: their sandbox is a child process of this one, with nothing
|
|
951
|
+
* outside it to address.
|
|
952
|
+
*/
|
|
953
|
+
readonly sandboxId?: string;
|
|
846
954
|
/** Invoke an agent inside the existing sandbox. */
|
|
847
955
|
run(options: SandboxRunOptions): Promise<SandboxRunResult>;
|
|
848
956
|
/** Launch an interactive agent session inside the existing sandbox. */
|
|
@@ -870,7 +978,7 @@ interface SandboxExecOptions {
|
|
|
870
978
|
readonly onLine?: (line: string) => void;
|
|
871
979
|
/** Working directory for the command. Defaults to the sandbox repo path. */
|
|
872
980
|
readonly cwd?: string;
|
|
873
|
-
/** Run the command
|
|
981
|
+
/** Run the whole command as root, when the provider supports it. */
|
|
874
982
|
readonly sudo?: boolean;
|
|
875
983
|
/** Stdin payload — piped to the child process and then closed. Avoids the Linux 128 KB per-arg limit. */
|
|
876
984
|
readonly stdin?: string;
|
|
@@ -909,7 +1017,7 @@ interface WorktreeInteractiveOptions {
|
|
|
909
1017
|
/** Agent provider to use (e.g. claudeCode("claude-opus-4-8")) */
|
|
910
1018
|
readonly agent: AgentProvider;
|
|
911
1019
|
/** Sandbox provider (e.g. docker(), noSandbox()). Defaults to noSandbox(). */
|
|
912
|
-
readonly sandbox?:
|
|
1020
|
+
readonly sandbox?: SandboxProvider;
|
|
913
1021
|
/** Inline prompt string (mutually exclusive with promptFile). */
|
|
914
1022
|
readonly prompt?: string;
|
|
915
1023
|
/** Path to a prompt file (mutually exclusive with prompt). */
|
|
@@ -1048,4 +1156,107 @@ interface CwdError extends Error {
|
|
|
1048
1156
|
/** The provided `cwd` path does not exist or is not a directory. */
|
|
1049
1157
|
declare const CwdError: CwdErrorConstructor;
|
|
1050
1158
|
|
|
1051
|
-
|
|
1159
|
+
/**
|
|
1160
|
+
* Thrown by `.fork()` (and by any run given `forkSession`) when the **agent
|
|
1161
|
+
* provider** can resume a session but its CLI has no native fork. It is thrown
|
|
1162
|
+
* before any sandbox starts. Use `.resume()` instead, which continues the
|
|
1163
|
+
* session in place.
|
|
1164
|
+
*
|
|
1165
|
+
* Public-facing shape of the internal `ForkNotSupportedError` in `errors.ts`,
|
|
1166
|
+
* declared here so Effect's types stay out of the published `.d.ts` files.
|
|
1167
|
+
* Match it on `_tag` (or `name`), both `"ForkNotSupportedError"`.
|
|
1168
|
+
*/
|
|
1169
|
+
interface ForkNotSupportedError extends Error {
|
|
1170
|
+
readonly _tag: "ForkNotSupportedError";
|
|
1171
|
+
readonly name: "ForkNotSupportedError";
|
|
1172
|
+
/** The agent provider's name, e.g. `"copilot"`. */
|
|
1173
|
+
readonly agentProvider: string;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
interface SyncOutPathErrorConstructor {
|
|
1177
|
+
new (args: {
|
|
1178
|
+
readonly message: string;
|
|
1179
|
+
readonly path: string;
|
|
1180
|
+
}): SyncOutPathError;
|
|
1181
|
+
readonly prototype: SyncOutPathError;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Sync-out refused to write a file on the host because its path, as reported
|
|
1185
|
+
* by an isolated sandbox, would land outside the host worktree (or in its
|
|
1186
|
+
* `.git`): an absolute path, a `..` segment, or a symlink leading out.
|
|
1187
|
+
*
|
|
1188
|
+
* Public-facing type for `SyncOutPathError`. The runtime class is the same
|
|
1189
|
+
* `Data.TaggedError` from `errors.ts`, re-declared here as a plain `Error`
|
|
1190
|
+
* subclass so that Effect's types stay out of Sandcastle's published `.d.ts`
|
|
1191
|
+
* files.
|
|
1192
|
+
*/
|
|
1193
|
+
interface SyncOutPathError extends Error {
|
|
1194
|
+
readonly _tag: "SyncOutPathError";
|
|
1195
|
+
readonly message: string;
|
|
1196
|
+
/** The offending path, as the sandbox reported it. */
|
|
1197
|
+
readonly path: string;
|
|
1198
|
+
}
|
|
1199
|
+
/** Sync-out refused a host path that would land outside the worktree. */
|
|
1200
|
+
declare const SyncOutPathError: SyncOutPathErrorConstructor;
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* Native sandbox providers: bind-mount sandbox providers that contain the
|
|
1204
|
+
* agent with the host OS's own process sandbox (Bubblewrap, Seatbelt) instead
|
|
1205
|
+
* of a container. They share the "bind-mount" tag, so core knows them by a
|
|
1206
|
+
* mark set when the provider is constructed.
|
|
1207
|
+
*/
|
|
1208
|
+
|
|
1209
|
+
interface NativeInteractiveNotSupportedErrorConstructor {
|
|
1210
|
+
new (args: {
|
|
1211
|
+
readonly message: string;
|
|
1212
|
+
readonly provider: string;
|
|
1213
|
+
}): NativeInteractiveNotSupportedError;
|
|
1214
|
+
readonly prototype: NativeInteractiveNotSupportedError;
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* `interactive()` was called with a native sandbox provider (`bwrap()`,
|
|
1218
|
+
* `seatbelt()`). Native providers don't run interactive sessions: use `run()`,
|
|
1219
|
+
* or pass `docker()` or `noSandbox()` to `interactive()`.
|
|
1220
|
+
*
|
|
1221
|
+
* Public-facing type for `NativeInteractiveNotSupportedError`. The runtime
|
|
1222
|
+
* class is the same `Data.TaggedError` from `errors.ts`, re-declared here as a
|
|
1223
|
+
* plain `Error` subclass so that Effect's types stay out of Sandcastle's
|
|
1224
|
+
* published `.d.ts` files.
|
|
1225
|
+
*/
|
|
1226
|
+
interface NativeInteractiveNotSupportedError extends Error {
|
|
1227
|
+
readonly _tag: "NativeInteractiveNotSupportedError";
|
|
1228
|
+
readonly message: string;
|
|
1229
|
+
/** The native sandbox provider `interactive()` was called with. */
|
|
1230
|
+
readonly provider: string;
|
|
1231
|
+
}
|
|
1232
|
+
/** `interactive()` was called with a native sandbox provider. */
|
|
1233
|
+
declare const NativeInteractiveNotSupportedError: NativeInteractiveNotSupportedErrorConstructor;
|
|
1234
|
+
|
|
1235
|
+
interface NativeSandboxUnavailableErrorConstructor {
|
|
1236
|
+
new (args: {
|
|
1237
|
+
readonly message: string;
|
|
1238
|
+
readonly fixCommand?: string;
|
|
1239
|
+
}): NativeSandboxUnavailableError;
|
|
1240
|
+
readonly prototype: NativeSandboxUnavailableError;
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* A native sandbox provider (`bwrap()`, `seatbelt()`) can't run on this host:
|
|
1244
|
+
* the wrong OS, its tool isn't installed, or the kernel blocks it. Thrown when
|
|
1245
|
+
* the provider is constructed, before any worktree exists, so a run never
|
|
1246
|
+
* falls back to running unsandboxed.
|
|
1247
|
+
*
|
|
1248
|
+
* Public-facing type for `NativeSandboxUnavailableError`. The runtime class is
|
|
1249
|
+
* the same `Data.TaggedError` from `errors.ts`, re-declared here as a plain
|
|
1250
|
+
* `Error` subclass so that Effect's types stay out of Sandcastle's published
|
|
1251
|
+
* `.d.ts` files.
|
|
1252
|
+
*/
|
|
1253
|
+
interface NativeSandboxUnavailableError extends Error {
|
|
1254
|
+
readonly _tag: "NativeSandboxUnavailableError";
|
|
1255
|
+
readonly message: string;
|
|
1256
|
+
/** A shell command that fixes the host, when there is one (e.g. an install command). */
|
|
1257
|
+
readonly fixCommand?: string;
|
|
1258
|
+
}
|
|
1259
|
+
/** A native sandbox provider can't run on this host. */
|
|
1260
|
+
declare const NativeSandboxUnavailableError: NativeSandboxUnavailableErrorConstructor;
|
|
1261
|
+
|
|
1262
|
+
export { type AgentCommandOptions, type AgentProvider, type AgentStreamEvent, BindMountSandboxHandle, BranchStrategy, type ClaudeCodeOptions, type CloseResult, type CodexOptions, type ContextWindow, type CopilotOptions, type CreateSandboxOptions, type CreateWorktreeOptions, type CursorOptions, CwdError, ExecResult, type ForkNotSupportedError, type HostSessionLookup, type InteractiveOptions, type InteractiveResult, type IterationResult, type IterationUsage, type LoggingOption, MergeToHeadBranchStrategy, NamedBranchStrategy, NativeInteractiveNotSupportedError, NativeSandboxUnavailableError, type OpenCodeOptions, Output, type OutputDefinition, type OutputObjectDefinition, type OutputStringDefinition, type PiOptions, type PrintCommand, type PromptArgs, type ResumeSandboxRunResultOptions, type RunOptions, type RunResult, type Sandbox, type SandboxExecOptions, type SandboxHooks, type SandboxInteractiveOptions, type SandboxInteractiveResult, SandboxProvider, type SandboxRunOptions, type SandboxRunResult, StructuredOutputError, SyncOutPathError, type Timeouts, type Worktree, type WorktreeBranchStrategy, type WorktreeCreateSandboxOptions, type WorktreeInteractiveOptions, type WorktreeRunOptions, type WorktreeRunResult, claudeCode, claudeHostSessionPath, claudeSandboxSessionPath, codex, copilot, createSandbox, createWorktree, cursor, encodeProjectPath, findClaudeSessionOnHost, findCodexSessionOnHost, interactive, opencode, pi, run, transferClaudeSession, transferCodexSession };
|