@parcha/agentrun-harness-claude 0.0.0-stage → 0.1.0-beta.30
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/CHANGELOG.md +92 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +56 -2
- package/dist/adapter.d.ts +129 -0
- package/dist/adapter.js +514 -0
- package/dist/binary.d.ts +25 -0
- package/dist/binary.js +71 -0
- package/dist/cli-names.d.ts +7 -0
- package/dist/cli-names.js +17 -0
- package/dist/env.d.ts +81 -0
- package/dist/env.js +92 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.js +42 -0
- package/dist/harness.d.ts +287 -0
- package/dist/harness.js +887 -0
- package/dist/host/kernel.d.ts +10 -0
- package/dist/host/kernel.js +1 -0
- package/dist/host/machine.d.ts +77 -0
- package/dist/host/machine.js +261 -0
- package/dist/host/policy.d.ts +104 -0
- package/dist/host/policy.js +437 -0
- package/dist/host/process.d.ts +130 -0
- package/dist/host/process.js +31 -0
- package/dist/host/tool-server.d.ts +44 -0
- package/dist/host/tool-server.js +47 -0
- package/dist/ids.d.ts +9 -0
- package/dist/ids.js +17 -0
- package/dist/inbox.d.ts +14 -0
- package/dist/inbox.js +36 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +7 -0
- package/dist/serial.d.ts +3 -0
- package/dist/serial.js +10 -0
- package/dist/spawn.d.ts +51 -0
- package/dist/spawn.js +131 -0
- package/dist/store.d.ts +119 -0
- package/dist/store.js +202 -0
- package/dist/testing/fake-anthropic.d.ts +97 -0
- package/dist/testing/fake-anthropic.js +279 -0
- package/dist/testing/fake-sdk.d.ts +60 -0
- package/dist/testing/fake-sdk.js +402 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.js +5 -0
- package/dist/transcript.d.ts +73 -0
- package/dist/transcript.js +116 -0
- package/dist/versions.d.ts +34 -0
- package/dist/versions.js +76 -0
- package/package.json +76 -4
- package/vendor/durable-harness/UPSTREAM.json +59 -0
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The durable environment of the `claude` CLI in the session's VM
|
|
3
|
+
* (docs/workspaces.md §5.6 "Env"). It replaces the parent's environment
|
|
4
|
+
* entirely: the relay builds the child's environment from this alone (`env -i`
|
|
5
|
+
* after the privilege drop), and nothing of the Function's environment is in
|
|
6
|
+
* it (not its `PATH`, not a secret). A parent Claude Code session alone passes
|
|
7
|
+
* about 50 `CLAUDE_*`, `ANTHROPIC_*` and `MCP_*` variables that change the
|
|
8
|
+
* CLI's behavior; none reaches the child unless it is listed here.
|
|
9
|
+
*/
|
|
10
|
+
/** The `PATH` of the CLI and its commands in the VM: the image's, never the Function's. */
|
|
11
|
+
export declare const VM_PATH = "/usr/local/bin:/usr/bin:/bin";
|
|
12
|
+
/** The projects key both sides use (`CLAUDE_CODE_PROJECT_DIR_NAME`): the CLI's transcript is `projects/session/<id>.jsonl` wherever its cwd is. */
|
|
13
|
+
export declare const PROJECT_DIR_NAME = "session";
|
|
14
|
+
export interface DurableEnvOptions {
|
|
15
|
+
/** The session's HOME in the VM (`SessionMachine.dirs.home`). */
|
|
16
|
+
home: string;
|
|
17
|
+
/** The CLI's config dir in the VM (`dirs.config`: its transcript, settings, caches). */
|
|
18
|
+
configDir: string;
|
|
19
|
+
/** TMPDIR in the VM (`dirs.tmp`). */
|
|
20
|
+
tmpDir: string;
|
|
21
|
+
/** The XDG cache in the VM (`dirs.cache`). */
|
|
22
|
+
cacheDir: string;
|
|
23
|
+
/** Where the CLI sends model requests: the VM's model port (`SessionMachine.modelUrl`). */
|
|
24
|
+
baseUrl: string;
|
|
25
|
+
/**
|
|
26
|
+
* The key the CLI sends (`ANTHROPIC_AUTH_TOKEN`, so `authorization: Bearer
|
|
27
|
+
* <key>`): the attach's model key (`SessionMachine.modelKey`). The relay
|
|
28
|
+
* admits a model request only with it, from the CLI's own process.
|
|
29
|
+
*/
|
|
30
|
+
token: string;
|
|
31
|
+
/** The model, as the CLI's main and alias models. */
|
|
32
|
+
model: string;
|
|
33
|
+
/** The model for the CLI's small background calls (titles, summaries). Default `model`. */
|
|
34
|
+
smallModel?: string;
|
|
35
|
+
/** The longest a Bash command may run (`BASH_MAX_TIMEOUT_MS`, and its default): `sandbox({ commandTimeoutMs })`. */
|
|
36
|
+
bashTimeoutMs?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The longest of the session's tool descriptions. The CLI cuts an MCP tool's description at 2048 characters unless
|
|
39
|
+
* `CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH` says more; above that, it's set to this, so the model reads each one whole.
|
|
40
|
+
*/
|
|
41
|
+
toolDescriptionMax?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The most tokens an MCP tool's result may take (`MAX_MCP_OUTPUT_TOKENS`). Past it the CLI saves the result to a file
|
|
44
|
+
* and tells the model to read it, or cuts a result that holds an image; its default is 25,000.
|
|
45
|
+
*/
|
|
46
|
+
mcpOutputTokens?: number;
|
|
47
|
+
/**
|
|
48
|
+
* The app's own variables (`sandbox({ env })`, checked there and again at
|
|
49
|
+
* spawn): added under everything above, so none can replace the model
|
|
50
|
+
* port, its key, the paths or the durability flags.
|
|
51
|
+
*/
|
|
52
|
+
extra?: Readonly<Record<string, string>>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* - `HOME`, `CLAUDE_CONFIG_DIR`, `TMPDIR` and the XDG dirs in the session's
|
|
56
|
+
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`);
|
|
57
|
+
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
58
|
+
* resumes on any VM, whatever the cwd;
|
|
59
|
+
* - the model through the VM's model port, with the attach's key; the
|
|
60
|
+
* credential is added in the Function, never here;
|
|
61
|
+
* - no updater, telemetry, error reporting or other nonessential traffic;
|
|
62
|
+
* - the CLI state the transcript mirror does not carry turned off: auto-memory,
|
|
63
|
+
* background tasks, cron, workflows, file checkpoints;
|
|
64
|
+
* - no git of the CLI's own in `/workspace` (`CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS`):
|
|
65
|
+
* for the system prompt's git context the CLI runs `git status` there
|
|
66
|
+
* itself, outside Claude's sandbox, as the CLI's user, and git runs what
|
|
67
|
+
* the repo's config names (a clean filter, a textconv): a `.git/config`
|
|
68
|
+
* the model planted on the Drive would run with the CLI's environment
|
|
69
|
+
* (its model key) and the CLI's view of the VM (docs/workspaces.md §6).
|
|
70
|
+
* It also drops the commit and PR instructions from the prompt.
|
|
71
|
+
*/
|
|
72
|
+
/** Where the pinned CLI cuts an MCP tool's description by default. */
|
|
73
|
+
export declare const MCP_DESCRIPTION_CUT = 2048;
|
|
74
|
+
export declare function durableEnv(options: DurableEnvOptions): Record<string, string>;
|
|
75
|
+
/**
|
|
76
|
+
* A Gateway model id (`anthropic/claude-sonnet-4.5`) as the native id the
|
|
77
|
+
* CLI knows (`claude-sonnet-4-5`). The Gateway accepts both; with a Gateway
|
|
78
|
+
* id the CLI logs `unrecognized_model` and does not know the model's limits.
|
|
79
|
+
* Ids that are not Anthropic Gateway ids come back unchanged.
|
|
80
|
+
*/
|
|
81
|
+
export declare function nativeModelId(model: string): string;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright 2026 Vercel Inc. Licensed under the Apache License, Version 2.0; see LICENSE in this package.
|
|
2
|
+
// From github.com/vercel-labs/durable-harness, packages/harness-claude-code/src/env.ts at ea8aa4060c (UPSTREAM.json records its blob and sha256).
|
|
3
|
+
// Changed by Parcha, patches: 002-names, 008-tool-description-max, 016-mcp-output-tokens
|
|
4
|
+
/**
|
|
5
|
+
* The durable environment of the `claude` CLI in the session's VM
|
|
6
|
+
* (docs/workspaces.md §5.6 "Env"). It replaces the parent's environment
|
|
7
|
+
* entirely: the relay builds the child's environment from this alone (`env -i`
|
|
8
|
+
* after the privilege drop), and nothing of the Function's environment is in
|
|
9
|
+
* it (not its `PATH`, not a secret). A parent Claude Code session alone passes
|
|
10
|
+
* about 50 `CLAUDE_*`, `ANTHROPIC_*` and `MCP_*` variables that change the
|
|
11
|
+
* CLI's behavior; none reaches the child unless it is listed here.
|
|
12
|
+
*/
|
|
13
|
+
/** The `PATH` of the CLI and its commands in the VM: the image's, never the Function's. */
|
|
14
|
+
export const VM_PATH = '/usr/local/bin:/usr/bin:/bin';
|
|
15
|
+
/** Claude Code's default Bash timeout. */
|
|
16
|
+
const BASH_DEFAULT_MS = 120_000;
|
|
17
|
+
/** The projects key both sides use (`CLAUDE_CODE_PROJECT_DIR_NAME`): the CLI's transcript is `projects/session/<id>.jsonl` wherever its cwd is. */
|
|
18
|
+
export const PROJECT_DIR_NAME = 'session';
|
|
19
|
+
/**
|
|
20
|
+
* - `HOME`, `CLAUDE_CONFIG_DIR`, `TMPDIR` and the XDG dirs in the session's
|
|
21
|
+
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`);
|
|
22
|
+
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
23
|
+
* resumes on any VM, whatever the cwd;
|
|
24
|
+
* - the model through the VM's model port, with the attach's key; the
|
|
25
|
+
* credential is added in the Function, never here;
|
|
26
|
+
* - no updater, telemetry, error reporting or other nonessential traffic;
|
|
27
|
+
* - the CLI state the transcript mirror does not carry turned off: auto-memory,
|
|
28
|
+
* background tasks, cron, workflows, file checkpoints;
|
|
29
|
+
* - no git of the CLI's own in `/workspace` (`CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS`):
|
|
30
|
+
* for the system prompt's git context the CLI runs `git status` there
|
|
31
|
+
* itself, outside Claude's sandbox, as the CLI's user, and git runs what
|
|
32
|
+
* the repo's config names (a clean filter, a textconv): a `.git/config`
|
|
33
|
+
* the model planted on the Drive would run with the CLI's environment
|
|
34
|
+
* (its model key) and the CLI's view of the VM (docs/workspaces.md §6).
|
|
35
|
+
* It also drops the commit and PR instructions from the prompt.
|
|
36
|
+
*/
|
|
37
|
+
/** Where the pinned CLI cuts an MCP tool's description by default. */
|
|
38
|
+
export const MCP_DESCRIPTION_CUT = 2048;
|
|
39
|
+
export function durableEnv(options) {
|
|
40
|
+
const { home, model } = options;
|
|
41
|
+
const small = options.smallModel ?? model;
|
|
42
|
+
const env = { ...(options.extra ?? {}) };
|
|
43
|
+
Object.assign(env, {
|
|
44
|
+
PATH: VM_PATH,
|
|
45
|
+
HOME: home,
|
|
46
|
+
TMPDIR: options.tmpDir,
|
|
47
|
+
CLAUDE_CONFIG_DIR: options.configDir,
|
|
48
|
+
CLAUDE_CODE_PROJECT_DIR_NAME: PROJECT_DIR_NAME,
|
|
49
|
+
XDG_CONFIG_HOME: `${home}/.config`,
|
|
50
|
+
XDG_CACHE_HOME: options.cacheDir,
|
|
51
|
+
XDG_DATA_HOME: `${home}/.local/share`,
|
|
52
|
+
XDG_STATE_HOME: `${home}/.local/state`,
|
|
53
|
+
ANTHROPIC_BASE_URL: options.baseUrl,
|
|
54
|
+
ANTHROPIC_AUTH_TOKEN: options.token,
|
|
55
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: model,
|
|
56
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: model,
|
|
57
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: small,
|
|
58
|
+
DISABLE_AUTOUPDATER: '1',
|
|
59
|
+
DISABLE_TELEMETRY: '1',
|
|
60
|
+
DISABLE_ERROR_REPORTING: '1',
|
|
61
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1',
|
|
62
|
+
CLAUDE_CODE_DISABLE_AUTO_MEMORY: '1',
|
|
63
|
+
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: '1',
|
|
64
|
+
CLAUDE_CODE_DISABLE_MCP_TASK_BACKGROUND: '1',
|
|
65
|
+
CLAUDE_CODE_DISABLE_CRON: '1',
|
|
66
|
+
CLAUDE_CODE_DISABLE_WORKFLOWS: '1',
|
|
67
|
+
CLAUDE_CODE_DISABLE_FILE_CHECKPOINTING: '1',
|
|
68
|
+
CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS: '1',
|
|
69
|
+
CLAUDE_AGENT_SDK_CLIENT_APP: 'agentrun-claude-agent',
|
|
70
|
+
});
|
|
71
|
+
if (options.toolDescriptionMax !== undefined && options.toolDescriptionMax > MCP_DESCRIPTION_CUT)
|
|
72
|
+
env.CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH = String(options.toolDescriptionMax);
|
|
73
|
+
if (options.mcpOutputTokens !== undefined)
|
|
74
|
+
env.MAX_MCP_OUTPUT_TOKENS = String(Math.max(1, Math.floor(options.mcpOutputTokens)));
|
|
75
|
+
if (options.bashTimeoutMs !== undefined) {
|
|
76
|
+
const max = Math.max(1_000, Math.floor(options.bashTimeoutMs));
|
|
77
|
+
env.BASH_MAX_TIMEOUT_MS = String(max);
|
|
78
|
+
// The CLI's own default (2 min), unless the cap is lower.
|
|
79
|
+
env.BASH_DEFAULT_TIMEOUT_MS = String(Math.min(BASH_DEFAULT_MS, max));
|
|
80
|
+
}
|
|
81
|
+
return env;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A Gateway model id (`anthropic/claude-sonnet-4.5`) as the native id the
|
|
85
|
+
* CLI knows (`claude-sonnet-4-5`). The Gateway accepts both; with a Gateway
|
|
86
|
+
* id the CLI logs `unrecognized_model` and does not know the model's limits.
|
|
87
|
+
* Ids that are not Anthropic Gateway ids come back unchanged.
|
|
88
|
+
*/
|
|
89
|
+
export function nativeModelId(model) {
|
|
90
|
+
const m = /^anthropic\/(claude-[a-z]+-[0-9.]+)$/.exec(model);
|
|
91
|
+
return m ? m[1].replace(/\./g, '-') : model;
|
|
92
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Which pin a mismatch is about. */
|
|
2
|
+
export type ClaudeAgentPin = "cli_sha256" | "cli_version" | "sdk_version";
|
|
3
|
+
/** The Agent SDK or its CLI is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
4
|
+
export declare class ClaudeAgentPinMismatch extends Error {
|
|
5
|
+
readonly pin: ClaudeAgentPin;
|
|
6
|
+
readonly expected: string;
|
|
7
|
+
readonly found: string;
|
|
8
|
+
readonly path?: string | undefined;
|
|
9
|
+
readonly code = "CLAUDE_AGENT_PIN_MISMATCH";
|
|
10
|
+
constructor(pin: ClaudeAgentPin, expected: string, found: string, path?: string | undefined);
|
|
11
|
+
}
|
|
12
|
+
/** This package's name on npm, as a message names it. */
|
|
13
|
+
export declare const CLAUDE_AGENT_PACKAGE = "@parcha/agentrun-harness-claude";
|
|
14
|
+
/** The host has not installed the Agent SDK (it is an optional peer dependency the host brings), or its CLI. The message
|
|
15
|
+
* is one line: what is missing, and, where installing the pinned SDK is the fix, the line that does it (`install`). */
|
|
16
|
+
export declare class ClaudeAgentNotInstalled extends Error {
|
|
17
|
+
readonly detail?: string | undefined;
|
|
18
|
+
readonly install?: string | undefined;
|
|
19
|
+
readonly code = "CLAUDE_AGENT_NOT_INSTALLED";
|
|
20
|
+
constructor(detail?: string | undefined, install?: string | undefined);
|
|
21
|
+
}
|
|
22
|
+
/** A thinking level that would turn the model's reasoning off: never taken; a node that names none thinks at medium. */
|
|
23
|
+
export declare class ClaudeAgentThinkingOff extends Error {
|
|
24
|
+
readonly level: string;
|
|
25
|
+
readonly code = "CLAUDE_AGENT_THINKING_OFF";
|
|
26
|
+
constructor(level: string);
|
|
27
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The Claude Agent adapter's setup errors, typed for a host to map to a run's failure line. Written for AgentRun.
|
|
2
|
+
/** The Agent SDK or its CLI is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
3
|
+
export class ClaudeAgentPinMismatch extends Error {
|
|
4
|
+
pin;
|
|
5
|
+
expected;
|
|
6
|
+
found;
|
|
7
|
+
path;
|
|
8
|
+
code = "CLAUDE_AGENT_PIN_MISMATCH";
|
|
9
|
+
constructor(pin, expected, found, path) {
|
|
10
|
+
super(`agentrun-harness-claude: the Claude Agent ${pin === "sdk_version" ? "SDK" : "CLI"}${path ? ` at ${path}` : ""} is not the pinned build: its ${pin.replace("_", " ")} is ${found}, not ${expected}`);
|
|
11
|
+
this.pin = pin;
|
|
12
|
+
this.expected = expected;
|
|
13
|
+
this.found = found;
|
|
14
|
+
this.path = path;
|
|
15
|
+
this.name = "ClaudeAgentPinMismatch";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** This package's name on npm, as a message names it. */
|
|
19
|
+
export const CLAUDE_AGENT_PACKAGE = "@parcha/agentrun-harness-claude";
|
|
20
|
+
/** The host has not installed the Agent SDK (it is an optional peer dependency the host brings), or its CLI. The message
|
|
21
|
+
* is one line: what is missing, and, where installing the pinned SDK is the fix, the line that does it (`install`). */
|
|
22
|
+
export class ClaudeAgentNotInstalled extends Error {
|
|
23
|
+
detail;
|
|
24
|
+
install;
|
|
25
|
+
code = "CLAUDE_AGENT_NOT_INSTALLED";
|
|
26
|
+
constructor(detail, install) {
|
|
27
|
+
super(`Claude Agent SDK not installed${detail ? `: ${detail}` : ""}${install ? `; install it with: ${install}` : ""}`);
|
|
28
|
+
this.detail = detail;
|
|
29
|
+
this.install = install;
|
|
30
|
+
this.name = "ClaudeAgentNotInstalled";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A thinking level that would turn the model's reasoning off: never taken; a node that names none thinks at medium. */
|
|
34
|
+
export class ClaudeAgentThinkingOff extends Error {
|
|
35
|
+
level;
|
|
36
|
+
code = "CLAUDE_AGENT_THINKING_OFF";
|
|
37
|
+
constructor(level) {
|
|
38
|
+
super(`agentrun-harness-claude: thinking is never off; ${JSON.stringify(String(level).slice(0, 20))} is not a level (low, medium, high, xhigh or max)`);
|
|
39
|
+
this.level = level;
|
|
40
|
+
this.name = "ClaudeAgentThinkingOff";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { type DriveContext, type Harness, type HostTool, type ReplayPolicy, type SessionState, type Submission } from './host/kernel.js';
|
|
2
|
+
import { type GatewayHandler, type ProviderTool, type SessionMachine } from './host/process.js';
|
|
3
|
+
import { JournalSessionStore } from './store.js';
|
|
4
|
+
/**
|
|
5
|
+
* Claude Code on harness-world: a kernel `Harness` that drives the Claude
|
|
6
|
+
* Agent SDK's `query()` in the drive (in the Function), with the `claude` CLI
|
|
7
|
+
* as its child **in the session's sandbox VM** (docs/workspaces.md
|
|
8
|
+
* §5.6 "Claude Code"), never on the machine that drives the session.
|
|
9
|
+
*
|
|
10
|
+
* Every drive (one queue delivery):
|
|
11
|
+
*
|
|
12
|
+
* 1. returns at once when there is nothing to do (no open turn, nothing
|
|
13
|
+
* pending): an idle wake attaches no VM;
|
|
14
|
+
* 2. attaches the session's VM through the sandbox tier (`sandbox.attach`:
|
|
15
|
+
* the `sandbox.attach` fact, the relay armed with the drive's fence) and
|
|
16
|
+
* refuses any machine the session factory didn't make (`isBrandedMachine`:
|
|
17
|
+
* `Unavailable('sandbox_required')`);
|
|
18
|
+
* 3. starts `query()` with streaming input: a resume of the session the log
|
|
19
|
+
* holds (the SDK `load()`s the transcript from the journal; `sandboxSpawn`
|
|
20
|
+
* uploads only its `projects/**` into the VM), or a new session whose id
|
|
21
|
+
* is derived from the run;
|
|
22
|
+
* 4. mirrors every transcript line the CLI writes into the journal (the
|
|
23
|
+
* SDK's `sessionStore`, flushed eagerly; `sandboxSpawn` maps the VM's
|
|
24
|
+
* paths to the Function's, on the trusted side);
|
|
25
|
+
* 5. if the last turn never ended, opens with the recovery note; places each
|
|
26
|
+
* submission, then sends it (steers go in mid-turn, at priority `next`);
|
|
27
|
+
* serves the app's tools (an in-process MCP server, in the Function) and
|
|
28
|
+
* records each built-in call through the hooks;
|
|
29
|
+
* 6. writes the normalized transcript and live events, and at each turn's
|
|
30
|
+
* end a `turn` entry and a flush;
|
|
31
|
+
* 7. closes the input, lets the CLI exit, and kills what is left of the
|
|
32
|
+
* session's processes in the VM (the VM and the Drive stay).
|
|
33
|
+
*
|
|
34
|
+
* **The model.** The CLI's base URL is the VM's model port, its key the
|
|
35
|
+
* attach's model key (`SessionMachine.modelKey`); every request it sends is
|
|
36
|
+
* relayed to this drive's `gatewayHandler` (Claude's fixed table, the body
|
|
37
|
+
* policy, the model allowlist, the budget, the credential), so the VM never
|
|
38
|
+
* holds a credential (decision 6). The spend is kept in the session's
|
|
39
|
+
* journal (`journalLedger`); a request past `sandbox({ budget })`'s turn or
|
|
40
|
+
* session cap ends the turn at once with an `Unavailable` naming the cap.
|
|
41
|
+
*
|
|
42
|
+
* **Tools.** Tool-less by default: the app's `HostTool`s (`tools`) are the
|
|
43
|
+
* CLI's only tools (`tools: []`), and the system prompt says so. With
|
|
44
|
+
* `builtins`, Claude Code's own tools are on in the VM, on `/workspace` (the
|
|
45
|
+
* session's Drive): `true` is the pinned allowlist `CLAUDE_BUILTINS`, a list
|
|
46
|
+
* names them, the `claude_code` preset brings the CLI's whole set; the
|
|
47
|
+
* ones whose state the transcript does not carry (`CLAUDE_BUILTINS_OFF`) are
|
|
48
|
+
* always off. Each call is recorded through the hooks (`PreToolUse` commits
|
|
49
|
+
* the intent before the call runs, after the assistant entry that made it is
|
|
50
|
+
* in the log; `PostToolUse` / `PostToolUseFailure` the outcome, after the
|
|
51
|
+
* Drive's writes are flushed for a mutating call), so after a crash the
|
|
52
|
+
* recovery note says which calls completed and which were interrupted ("may
|
|
53
|
+
* have half-run"); nothing reruns one. Bash's timeout is clamped to what is
|
|
54
|
+
* left of the invocation, so a command never outlives it: one the clamp ends
|
|
55
|
+
* is recorded as out of time, never left open. Claude Code runs its commands
|
|
56
|
+
* under its own sandbox (bubblewrap, checked by a self-test in the VM before
|
|
57
|
+
* the spawn): writes only to `/workspace` and the temp and home dirs, no read
|
|
58
|
+
* of the CLI's state (`/var/lib/dh/s`), the model key unset in their
|
|
59
|
+
* environment, a pid namespace that hides the CLI's own environ and keeps
|
|
60
|
+
* them from tracing it, and no way to the model port. Where it can't start,
|
|
61
|
+
* the drive fails the turn with an `Unavailable` (`unsandboxedCommands`
|
|
62
|
+
* opts out).
|
|
63
|
+
*
|
|
64
|
+
* **A lost CLI.** When the CLI exits mid-turn (the link to the VM dropped, so
|
|
65
|
+
* the relay killed it, or the VM killed it), the drive is rebuilt from the
|
|
66
|
+
* log in the same delivery (`Restart`): it re-attaches and resumes the turn
|
|
67
|
+
* with the recovery note, a few times per delivery while time is left.
|
|
68
|
+
*/
|
|
69
|
+
/** The SDK functions the harness calls (the module `@anthropic-ai/claude-agent-sdk`, a peer dependency). */
|
|
70
|
+
export type ClaudeAgentSdk = Pick<typeof import('@anthropic-ai/claude-agent-sdk'), 'query'>;
|
|
71
|
+
type QueryOptions = NonNullable<Parameters<ClaudeAgentSdk['query']>[0]['options']>;
|
|
72
|
+
/** The VM's network, as `sandbox({ network })` says it (durable-harness's `SandboxNetwork`). */
|
|
73
|
+
export type ClaudeSandboxNetwork = 'allow-all' | 'deny-all' | {
|
|
74
|
+
readonly allow: readonly string[];
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The session's sandbox, as a kernel harness gets it from the sandbox tier
|
|
78
|
+
* (harness-world-sandbox's `kernelSandbox` over the session factory, with the
|
|
79
|
+
* descriptor's fields; durable-harness builds it from `sandbox()`).
|
|
80
|
+
*/
|
|
81
|
+
export interface ClaudeSandbox {
|
|
82
|
+
/** Attach the session's VM for this drive (the `sandbox.attach` fact): the branded machine, with `/model` serving `model`. */
|
|
83
|
+
attach(ctx: DriveContext, request: {
|
|
84
|
+
model?: GatewayHandler;
|
|
85
|
+
deadline?: number;
|
|
86
|
+
}): Promise<SessionMachine>;
|
|
87
|
+
/**
|
|
88
|
+
* The notes the machine carried (a lost Drive) reached the model in a turn
|
|
89
|
+
* that committed: don't show them again. `key` is what they described
|
|
90
|
+
* (`SessionMachine.notesKey`): a loss recorded since is kept.
|
|
91
|
+
*/
|
|
92
|
+
acknowledge?(ctx: DriveContext, key?: string): Promise<void>;
|
|
93
|
+
/** `sandbox({ env })`: non-secret variables for the CLI (checked there, and again at every spawn). */
|
|
94
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
95
|
+
/** `sandbox({ network })`: what the CLI's own sandbox lets commands reach, and whether provider-hosted tools may run. */
|
|
96
|
+
readonly network: ClaudeSandboxNetwork;
|
|
97
|
+
/** `sandbox({ budget })`'s dollar caps (`Infinity` turns one off). */
|
|
98
|
+
readonly budget: {
|
|
99
|
+
readonly turnUsd: number;
|
|
100
|
+
readonly sessionUsd: number;
|
|
101
|
+
};
|
|
102
|
+
/** `sandbox({ commandTimeoutMs })`: the longest a Bash command may run. */
|
|
103
|
+
readonly commandTimeoutMs?: number;
|
|
104
|
+
/**
|
|
105
|
+
* The writer of the Drive's manifest for one drive (`hw.sandbox-files`,
|
|
106
|
+
* harness-world-sandbox's `DriveFiles`): told of each mutating built-in as
|
|
107
|
+
* it ends, and asked to catch up once attached and for a snapshot after
|
|
108
|
+
* each turn. Without it the session has no manifest (the Files panel has
|
|
109
|
+
* nothing to show).
|
|
110
|
+
*/
|
|
111
|
+
files?(ctx: DriveContext, machine: SessionMachine): ClaudeDriveFiles;
|
|
112
|
+
}
|
|
113
|
+
/** The Drive manifest's writer for one drive (`ClaudeSandbox.files`): harness-world-sandbox's `DriveFiles`, structurally. */
|
|
114
|
+
export interface ClaudeDriveFiles {
|
|
115
|
+
/** A mutating built-in ended: a live event, and the paths it named for the next snapshot. */
|
|
116
|
+
changed(call: {
|
|
117
|
+
tool: string;
|
|
118
|
+
callId: string;
|
|
119
|
+
paths?: readonly string[];
|
|
120
|
+
}): void;
|
|
121
|
+
/** List first if an earlier invocation ended before its snapshot. Best effort. */
|
|
122
|
+
catchUp(): Promise<void>;
|
|
123
|
+
/** After a turn: list the Drive, if a call may have changed it. Best effort, bounded. */
|
|
124
|
+
snapshot(): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
/** `builtins`: off, the pinned allowlist, a list of names, or the CLI's whole preset. */
|
|
127
|
+
export type ClaudeBuiltins = boolean | readonly string[] | {
|
|
128
|
+
readonly type: 'preset';
|
|
129
|
+
readonly preset: 'claude_code';
|
|
130
|
+
};
|
|
131
|
+
export interface ClaudeCodeHarnessOptions {
|
|
132
|
+
/**
|
|
133
|
+
* The session's sandbox (required: Claude Code runs only in the session's
|
|
134
|
+
* sandbox VM). Without one, or when it hands back a machine the
|
|
135
|
+
* session factory didn't make, a drive fails the turn with
|
|
136
|
+
* `Unavailable('sandbox_required')` (docs/workspaces.md §6 rule 1).
|
|
137
|
+
*/
|
|
138
|
+
sandbox?: ClaudeSandbox;
|
|
139
|
+
/**
|
|
140
|
+
* The app's tools, served to Claude Code as an in-process MCP server
|
|
141
|
+
* (`mcp__hands__<name>`) in the Function: each call is a kernel effect
|
|
142
|
+
* keyed by its `tool_use` id, with the tool's own replay policy. Default
|
|
143
|
+
* none.
|
|
144
|
+
*/
|
|
145
|
+
tools?: HostTool[];
|
|
146
|
+
/**
|
|
147
|
+
* Claude Code's own tools, in the VM, on `/workspace`. Default false
|
|
148
|
+
* (tool-less: `tools` are the CLI's only tools). `true`: the pinned
|
|
149
|
+
* allowlist `CLAUDE_BUILTINS`; a list: those names; `{ type: 'preset',
|
|
150
|
+
* preset: 'claude_code' }`: the CLI's whole set. `CLAUDE_BUILTINS_OFF` is
|
|
151
|
+
* off whatever this says.
|
|
152
|
+
*/
|
|
153
|
+
builtins?: ClaudeBuiltins;
|
|
154
|
+
/** More built-ins to turn off (tool names, added to `CLAUDE_BUILTINS_OFF`). */
|
|
155
|
+
disallowedTools?: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Skills the model may load with the Skill tool: a local plugin directory (`plugin`: its `.claude-plugin/plugin.json`
|
|
158
|
+
* and `skills/<name>/SKILL.md`) and the plugin-qualified names enabled (`<plugin>:<name>`). Only those are listed to
|
|
159
|
+
* the model and loadable; the CLI's bundled skills, and any in its home, are not. Default none: the Skill tool is off.
|
|
160
|
+
*/
|
|
161
|
+
skills?: {
|
|
162
|
+
readonly plugin: string;
|
|
163
|
+
readonly names: readonly string[];
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* A built-in's replay policy: what the recovery note says about a call a
|
|
167
|
+
* crash interrupted ("safe to repeat", or "may have taken effect"), and
|
|
168
|
+
* whether its outcome waits for the Drive's writes to be flushed (every
|
|
169
|
+
* policy but `safe`). Nothing reruns a built-in either way. Default
|
|
170
|
+
* `claudeBuiltinReplay` (reads safe).
|
|
171
|
+
*/
|
|
172
|
+
builtinReplay?: Record<string, ReplayPolicy> | ((name: string) => ReplayPolicy);
|
|
173
|
+
/** Provider-hosted tools the model may use; default none. `web_search` turns the CLI's WebSearch on, built-ins off or
|
|
174
|
+
* not: each call recorded as a built-in's (the session's model proxy decides what the provider may run). */
|
|
175
|
+
providerTools?: readonly ProviderTool[];
|
|
176
|
+
/**
|
|
177
|
+
* The model, a native Anthropic id (`claude-sonnet-4-5`) or a Gateway one
|
|
178
|
+
* (`anthropic/claude-sonnet-4.5`, passed as its native id: `nativeModelId`).
|
|
179
|
+
* Default `claude-sonnet-4-5`.
|
|
180
|
+
*/
|
|
181
|
+
model?: string;
|
|
182
|
+
/** The model of the CLI's small background calls (`nativeModelId` too). Default `model`. */
|
|
183
|
+
smallModel?: string;
|
|
184
|
+
/** Appended to Claude Code's own system prompt (the `claude_code` preset). */
|
|
185
|
+
instructions?: string;
|
|
186
|
+
/** The provider credential, read per model request, in the Function. Default `gatewayCredential`. */
|
|
187
|
+
credential?: () => Promise<string>;
|
|
188
|
+
/** The Gateway's base URL. Default `gatewayUrl()`. */
|
|
189
|
+
gatewayUrl?: string;
|
|
190
|
+
/** The CLI's path in the VM. Default `CLAUDE_VM_EXECUTABLE` (the base image's pinned build). Tests on the stand-in VM pass the host build. */
|
|
191
|
+
executable?: string;
|
|
192
|
+
/** The kernel name (its sessions' runs are `workflow//durable-harness@<version>//<name>`). Default `claude-code`. */
|
|
193
|
+
name?: string;
|
|
194
|
+
/** The Agent SDK module. Default: `import('@anthropic-ai/claude-agent-sdk')` on the first drive, after its version is checked against the pin. */
|
|
195
|
+
sdk?: ClaudeAgentSdk;
|
|
196
|
+
/** How long a `never` tool waits for its call to reach the log before it is refused. Default 10 s. */
|
|
197
|
+
barrierMs?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Hold mirrored transcript lines this long so they share journal batches
|
|
200
|
+
* (fewer events per turn). A barrier or a turn's end sends them at once.
|
|
201
|
+
* Default 150 ms.
|
|
202
|
+
*/
|
|
203
|
+
coalesceMs?: number;
|
|
204
|
+
/** Keep the child this long after a turn, for a follow-up to skip the resume. Default 0. */
|
|
205
|
+
idleMs?: number;
|
|
206
|
+
/** `query()`'s `maxTurns` (model round trips per turn). */
|
|
207
|
+
maxTurns?: number;
|
|
208
|
+
/**
|
|
209
|
+
* Run the CLI's commands without Claude Code's own sandbox where bubblewrap
|
|
210
|
+
* doesn't work in the VM (with `builtins` on). Default false: such a drive
|
|
211
|
+
* fails the turn with an `Unavailable`. Without that sandbox a command runs
|
|
212
|
+
* beside the CLI as the same user: it can read the CLI's environment (the
|
|
213
|
+
* model key) and trace the CLI or take its socket (the VM's kernel has no
|
|
214
|
+
* Yama ptrace restriction, P0.16), so the model port's key and peer check no
|
|
215
|
+
* longer tell the CLI's calls from the model's (the key is then only a
|
|
216
|
+
* correlation id), and nothing hides the CLI's config dir. The VM stays the
|
|
217
|
+
* boundary. For the stand-in VM's tests, and images without user namespaces.
|
|
218
|
+
*/
|
|
219
|
+
unsandboxedCommands?: boolean;
|
|
220
|
+
/** Called with the child's stderr tail when it exits mid-turn, the gateway's refusals, and SDK diagnostics. */
|
|
221
|
+
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
222
|
+
}
|
|
223
|
+
/** The default model. */
|
|
224
|
+
export declare const DEFAULT_MODEL = "claude-sonnet-4-5";
|
|
225
|
+
/** What the harness appends to the system prompt about the tools, before `instructions`, with the built-ins off and the app's tools there. */
|
|
226
|
+
export declare const TOOLS_NOTE = "Your only tools are this app's, the mcp__hands__ tools; you have no shell, file, search or web tools of your own.";
|
|
227
|
+
/** `TOOLS_NOTE` with WebSearch on (`providerTools: ['web_search']`) and the other built-ins off. */
|
|
228
|
+
export declare const WEB_SEARCH_NOTE = "Your only tools are this app's (the mcp__hands__ tools, if it has any) and WebSearch; you have no shell, file or fetch tools of your own.";
|
|
229
|
+
/** `TOOLS_NOTE` for a session with no tools at all (built-ins off, no `tools`). */
|
|
230
|
+
export declare const NO_TOOLS_NOTE = "You have no tools in this session: no shell, file, search or web tools. Answer from the conversation.";
|
|
231
|
+
/** With the built-ins on (docs/workspaces.md §5.6 "Workspace note"): what `/workspace` is. */
|
|
232
|
+
export declare const DRIVE_NOTE = "Your working directory, /workspace, is this session's own disk: files there are durable (they stay for later turns, on any machine) but not transactional: a command that a crash interrupted may have half-run, so check before you repeat one. Commands end with this turn: nothing keeps running in the background.";
|
|
233
|
+
/**
|
|
234
|
+
* Built-ins that stay off whatever `builtins` says: their state lives in the
|
|
235
|
+
* CLI process or its local files, which the transcript the log carries does
|
|
236
|
+
* not hold (cron jobs, scheduled wakeups, worktrees, agent teams and their
|
|
237
|
+
* messages, background shells, workflows, the task list, P0.17: 2.1.296
|
|
238
|
+
* keeps it in the config dir), or they wait for a user who is not there
|
|
239
|
+
* (questions, plan mode).
|
|
240
|
+
*/
|
|
241
|
+
export declare const CLAUDE_BUILTINS_OFF: string[];
|
|
242
|
+
/**
|
|
243
|
+
* `builtins: true`: the pinned allowlist, the tools Claude Code 2.1.296 has
|
|
244
|
+
* (its `system/init` list, checked by a test) that act on `/workspace` and
|
|
245
|
+
* whose state is in the transcript. The design's Glob, Grep and TodoWrite are
|
|
246
|
+
* not tools of this CLI (it searches through Bash, and its task list is off,
|
|
247
|
+
* P0.17); WebSearch is provider-hosted (`providerTools`).
|
|
248
|
+
*/
|
|
249
|
+
export declare const CLAUDE_BUILTINS: readonly ["Bash", "Read", "Edit", "Write", "NotebookEdit", "WebFetch"];
|
|
250
|
+
/** Built-ins that only read: "safe to repeat" after a crash, and no flush before their outcome. Everything else: "may have taken effect". */
|
|
251
|
+
export declare const CLAUDE_SAFE_BUILTINS: string[];
|
|
252
|
+
/** The default `builtinReplay`. */
|
|
253
|
+
export declare const claudeBuiltinReplay: (name: string) => ReplayPolicy;
|
|
254
|
+
/** The `builtins` option, resolved: the `tools` option for `query()` (undefined: the preset, all of them). */
|
|
255
|
+
export declare function builtinTools(builtins: ClaudeBuiltins | undefined): string[] | undefined;
|
|
256
|
+
/** The Claude Code sandbox settings for the VM (§5.5 "Claude Code runs under its own sandbox"; P0.10, P0.16). */
|
|
257
|
+
export declare function claudeSandboxSettings(machine: Pick<SessionMachine, 'root' | 'dirs'>, network: ClaudeSandboxNetwork): NonNullable<QueryOptions['sandbox']>;
|
|
258
|
+
/** Loopback, as names and literals a command could hand the sandbox's proxy for the model port. */
|
|
259
|
+
export declare const LOOPBACK_NAMES: string[];
|
|
260
|
+
export declare function claudeCodeHarness(options?: ClaudeCodeHarnessOptions): Harness;
|
|
261
|
+
/** Whether a file tool's path is under one of `PROTECTED_DIRS` of the workspace (relative paths are the workspace's). */
|
|
262
|
+
export declare function protectedPath(root: string, path: string): boolean;
|
|
263
|
+
/** The user's turn that resumes a cut-off turn when the user has said nothing new: no recovery text in it. */
|
|
264
|
+
export declare const RECOVERY_NUDGE = "Continue.";
|
|
265
|
+
/**
|
|
266
|
+
* The user's turn that resumes a cut-off turn: only the user's words, the prompts of that turn the transcript never got
|
|
267
|
+
* (`lostPrompts`), then the messages sent since (`pending`), each whole, in that order. With none, the bare nudge: a
|
|
268
|
+
* resumed session moves only on a user message. The harness's own account of the turn goes in the system prompt.
|
|
269
|
+
*/
|
|
270
|
+
export declare function recoveryUserTurn(state: SessionState, store: Pick<JournalSessionStore, 'hasUser'>, pending: readonly Submission[]): string;
|
|
271
|
+
/**
|
|
272
|
+
* The harness's recovery note, as the resuming drive's system prompt carries it, or undefined with no turn to recover:
|
|
273
|
+
* only the harness's own words. Each tool call of the cut-off turn by its name, its id and its status, and never its
|
|
274
|
+
* input, output or error text: those can hold what a file or a web page said, and the system prompt would give that the
|
|
275
|
+
* harness's authority. Nor do they go in the user's turn, which would give it the user's.
|
|
276
|
+
*/
|
|
277
|
+
export declare function recoverySystemNote(state: SessionState): string | undefined;
|
|
278
|
+
/**
|
|
279
|
+
* The prompts among `placed` that never reached the transcript: neither the
|
|
280
|
+
* message sent for them (its `uuid` is derived from the first submission of
|
|
281
|
+
* their placement, `place:<id>`) nor a recovery note that carried them is in
|
|
282
|
+
* it. The crash came between the placement and the CLI's write.
|
|
283
|
+
*/
|
|
284
|
+
export declare function lostPrompts(state: SessionState, placed: string[], store: Pick<JournalSessionStore, 'hasUser'>): string[];
|
|
285
|
+
/** A built-in's result as text: Bash's output, an edit's patch, a read file's content, else the JSON. */
|
|
286
|
+
export declare function toolResponseText(response: unknown): string;
|
|
287
|
+
export {};
|