@parcha/agentrun-harness-claude 0.0.0-bootstrap.0 → 0.1.0-beta.29

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 (50) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +4 -0
  4. package/README.md +57 -0
  5. package/dist/adapter.d.ts +123 -0
  6. package/dist/adapter.js +487 -0
  7. package/dist/binary.d.ts +25 -0
  8. package/dist/binary.js +71 -0
  9. package/dist/cli-names.d.ts +7 -0
  10. package/dist/cli-names.js +17 -0
  11. package/dist/env.d.ts +81 -0
  12. package/dist/env.js +92 -0
  13. package/dist/errors.d.ts +27 -0
  14. package/dist/errors.js +42 -0
  15. package/dist/harness.d.ts +287 -0
  16. package/dist/harness.js +881 -0
  17. package/dist/host/kernel.d.ts +10 -0
  18. package/dist/host/kernel.js +1 -0
  19. package/dist/host/machine.d.ts +77 -0
  20. package/dist/host/machine.js +259 -0
  21. package/dist/host/policy.d.ts +85 -0
  22. package/dist/host/policy.js +359 -0
  23. package/dist/host/process.d.ts +130 -0
  24. package/dist/host/process.js +31 -0
  25. package/dist/host/tool-server.d.ts +44 -0
  26. package/dist/host/tool-server.js +47 -0
  27. package/dist/ids.d.ts +9 -0
  28. package/dist/ids.js +17 -0
  29. package/dist/inbox.d.ts +14 -0
  30. package/dist/inbox.js +36 -0
  31. package/dist/index.d.ts +11 -0
  32. package/dist/index.js +7 -0
  33. package/dist/serial.d.ts +3 -0
  34. package/dist/serial.js +10 -0
  35. package/dist/spawn.d.ts +51 -0
  36. package/dist/spawn.js +131 -0
  37. package/dist/store.d.ts +119 -0
  38. package/dist/store.js +202 -0
  39. package/dist/testing/fake-anthropic.d.ts +97 -0
  40. package/dist/testing/fake-anthropic.js +279 -0
  41. package/dist/testing/fake-sdk.d.ts +60 -0
  42. package/dist/testing/fake-sdk.js +402 -0
  43. package/dist/testing/index.d.ts +3 -0
  44. package/dist/testing/index.js +5 -0
  45. package/dist/transcript.d.ts +73 -0
  46. package/dist/transcript.js +116 -0
  47. package/dist/versions.d.ts +34 -0
  48. package/dist/versions.js +76 -0
  49. package/package.json +78 -1
  50. package/vendor/durable-harness/UPSTREAM.json +59 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## 0.1.0-beta.29 (2026-11-04)
6
+
7
+ - `ClaudeAgentNotInstalled` says, in one line, what is missing and how to install it: the message keeps its prefix ("Claude Agent SDK not installed"), names the SDK, its platform package with the CLI, or the MCP library it brings as a peer, and ends with `; install it with: npm install --save-exact @anthropic-ai/claude-agent-sdk@0.3.286`, which is also on the error as `install` (and exported as `CLAUDE_AGENT_SDK_INSTALL`). A `cliPath` that holds nothing keeps its own message, with no install line. A host that matched the whole message exactly now matches its prefix.
8
+ - A host's gateway headers reach the provider on every model request a Claude Agent session makes: `claudeAgentAdapter({ provider: { ..., headers: { "x-litellm-tags": "job:...,purpose:...,run:..." } } })`, the same LiteLLM spend-tag header a pi lead's model requests carry, so a gateway attributes the Claude lead's spend to its job. The session's model proxy (`startModelProxy({ headers })` in `@parcha/agentrun-kernel/host`) adds them to every forwarded request, paid and free, after the client's own headers (so the CLI can neither set nor override them) and before the credential's. They are checked when the adapter is made (`hostHeaderProblems`): a token name that is not the proxy's own (`authorization`, `x-api-key`, `host`, `content-*`, `anthropic-*`, ...), and a one-line value of at most 1024 characters. A host sends a gateway's headers only to that gateway.
9
+ - A call the CLI turns down itself (a tool the session doesn't have, a built-in that is off) reaches the host as a failed call by its name, with the model's input, and the adapter logs it once with the CLI's reason. The host hears it only once the CLI's answer is in the session's store, as a tool's `tool_end` waits for its outcome. An answer that does not reach the store within `barrierMs` leaves the call unshown, and the adapter logs `a refused call is not shown`. A call the session's tool server ran is never taken for one the CLI turned down, whatever its error text, so it is heard once.
10
+ - A host's skills reach the Claude Agent model: `claudeAgentAdapter({ skills: [{ name, files }] })`. Each session writes them as a local plugin in its own private directory and starts the CLI with that plugin and those skills alone (as `agentrun:<name>`), still with no settings sources, so the CLI's bundled skills and any skill in a home directory are neither listed nor loadable. With skills the model is offered the Skill tool, which the session's tool proxy now lets through; without them it is not. A loaded skill survives a crash: it is part of the history the session store restores. The skills are checked when the adapter is made (`skillProblems`): plain names, a `SKILL.md` whose front matter names the skill and describes it, plain relative paths, 1 MiB in all. With skills the model also gets `read_skill_file` (`readSkillFileTool`, from `@parcha/agentrun-kernel`, for any harness): a read-only, replay-safe host tool that reads one of a skill's own listed files, exactly. A path that climbs (`..`) or is absolute is refused before any filesystem call, an unlisted path or another skill's file is refused by name, and no link is followed anywhere in the path (checked part by part, opened without following one, and checked again after the open).
11
+ - `claudeAgentAdapter({ webSearch: true })` turns on Claude's own WebSearch, and nothing else of the CLI's: the model may call it, the PreToolUse hook lets it through with its intent recorded before it runs (safe to repeat after a crash), and the system prompt's note names it. The CLI runs each search as a request of its own through the session's model proxy, which then admits Anthropic's web search server tool exactly as the pinned CLI sends it (`web_search_20250305`, at most 8 searches, the domains the model named); every other hosted tool, a later web search version, and every server tool's block stay refused. Each search the provider reports (`usage.server_tool_use.web_search_requests`, read from a stream's last `message_delta` or a whole body) is booked at $10 per 1,000 searches (`CLAUDE_WEB_SEARCH_USD`) on top of the host's `price`, into the session's cost and so its spend cap. A request with the web search tool reports no input bound (`inputTokensMax` undefined): the provider bills the pages it reads as input. In `@parcha/agentrun-kernel`, `ProviderPolicy.serverInputOverhead` may now return `undefined`, a policy's word that a body has no input bound: the model proxy leaves `inputTokensMax` undefined (never 0) and, unlike a throw or a non-count, reports no failure. WebFetch stays off. Default off: a session without the option runs as before.
12
+ - The harness packages are published from this release under their final names: `@parcha/agentrun-adapters` is `@parcha/agentrun-kernel`, `@parcha/agentrun-claude-agent` is `@parcha/agentrun-harness-claude`, `@parcha/agentrun-codex` is `@parcha/agentrun-harness-codex`. Their subpaths, directories, harness ids and `AGENTRUN_*` environment variables do not change.
13
+ - Messages these packages raise start with `agentrun-kernel:`, `agentrun-harness-claude:`, `agentrun-harness-codex:`.
14
+ - New package `@parcha/agentrun-harness-claude`, held (not on npm yet): the Claude Agent SDK as an AgentRun harness, adapter id `claude-agent`. `claudeAgentAdapter(options)` is an `AgentAdapter`, so `createHarnessRunner(claudeAgentAdapter(...), { store, tools })` runs a DSL `agent` node on the Claude Agent CLI.
15
+ - The host brings the SDK, an exact optional peer (0.3.286, whose CLI is 2.1.286); the adapter checks the SDK and its CLI against the pins when it is made, and throws `ClaudeAgentPinMismatch` or `ClaudeAgentNotInstalled` ("Claude Agent SDK not installed"). A host may pass the SDK module and the CLI's path (`sdk`, `sdkVersion`, `cliPath`).
16
+ - The CLI's built-in tools are off: the host's tools are its only tools, each call recorded before it runs, and a `PreToolUse` hook denies every other call and every error path. A test runs the pinned CLI against a scripted model that tries its built-ins, the web, sub-agents, scheduled jobs and another MCP server: nothing runs, writes or fetches.
17
+ - The CLI's model traffic goes through the session's loopback proxy (`@parcha/agentrun-kernel/host`) with an Anthropic policy: the pinned CLI's routes only, the session's model, no provider-hosted tool or anything the provider would fetch, the session's tools only, a known `anthropic-beta` set, and the runner asked before every paid request. A refusal names no request content.
18
+ - The CLI runs in the session's own directories with an empty working directory and an allowlisted environment; no provider key, sign-in or operator settings reach it.
19
+ - A host can start the CLI under its own confinement with `confine` (a `setpriv --no-new-privs` prefix, say): it may only add in front of the pinned binary and its arguments, and never touches the environment; anything else is refused when the CLI starts. Every child of a session gets `GIT_CEILING_DIRECTORIES` set to the session's directory, so the CLI's own git never looks for a repository above it.
20
+ - A request on the session's small model is asked about and priced as the small model (the Anthropic policy names the model of the body it checked).
21
+ - Every drive of a session writes through one serialized writer, so a drive opened after an interrupt reads only once the halted drive's last writes are in: a `never` tool that finished as the interrupt landed is folded completed, never taken for abandoned. An interrupt waits for a host tool's call in flight rather than abandon it, so a host tool must honour its signal or carry its own deadline.
22
+ - The pinned CLI is looked up beside the adapter's own install, not from the process's working directory.
23
+ - A missing `zod` beside the adapter is refused when the adapter is made (`ClaudeAgentNotInstalled`), not at the first turn.
24
+ - A host tool may answer with images (a screenshot): `HostTool.call`'s result takes `images: [{ mimeType, data }]` (base64) beside its text. The kernel records them with the call's outcome, so a call answered from its record answers with the same images.
25
+ - The Claude Agent adapter sends them to the model inline in the tool's result. It checks each image first, a type Anthropic's API takes (`image/jpeg`, `image/png`, `image/gif`, `image/webp`), base64, at most `maxImageBytes` (default 5 MB, `CLAUDE_AGENT_MAX_IMAGE_BYTES`; at most 10 MB), and makes an image it can't send the call's error, by the tool's name and the image (`toolImageProblems`).
26
+ - The session's model proxy lets an image through only inline inside a tool's result, and leaves out the note the CLI adds beside it naming the file it kept in its own session directory.
27
+ - A session resumed in a new directory still sends the image, from the store.
28
+ - `toolSchemaProblems(tool, schema)` lists what a harness adapter refuses in a host tool's input schema before a session starts, the same on every harness, each as `<tool>: <JSON pointer>: <why>`: a root that is not `{ "type": "object" }`, a schema that is not JSON or not valid JSON Schema 2020-12 (a `$schema` must name 2020-12, 2019-09, draft-07, -06 or -04), and a remote `$ref` (a local one into `$defs` is followed). An adapter's `check()` calls it first and then adds its own harness's measured refusals.
29
+ - The Claude Agent adapter's `check()` uses it, and also refuses a root with `anyOf`, `allOf` or `oneOf`, which the pinned CLI drops without a word, the tool missing from the session. Put the alternatives under a property. `open` refuses a session whose tools have any of these, naming each.
30
+ - A call's `tool_end` reaches the host only once its outcome is in the session's records, with the text recorded as `result`, and `createHarnessRunner(...).stop({ drainMs })` pauses every node a runner is running: no new turn, tool call or paid request starts, and the calls in flight run on until their outcomes are recorded, for at most `drainMs`, before the node fails `aborted`. Run again with the same step, the node resumes from its records, and a call that finished during the pause is never run or paid for again.
31
+ - Before, the Claude Agent adapter sent `tool_end` as the tool returned, before its outcome was written, and an interrupt cut off a call in flight, so a `safe` call ran again when its session resumed.
32
+ - `AdapterSession.interrupt` takes `{ drainMs }`. An adapter that cannot drain stops at once, as before. The Claude Agent adapter drains, and refuses a new turn while it does.
33
+ - A failed call's `tool_end` carries its recorded text too.
34
+ - A spend cap below one request's worst case at its model's output ceiling no longer refuses the run before it starts. Each request is limited to the output tokens what is left of the cap can buy, thinking included, and held at that, so the cap stays exact. A request is refused only when what is left cannot buy its least: 1,024 tokens for its answer, plus its thinking's least when it thinks. A $0.50 cap on Claude Sonnet now runs; before, any cap under about $1.30 could never send a request.
35
+ - A refusal says, in plain words, what the run spent of its cap, what its next request needs and the cap that would run it ("Not sent: ... Raise the cap to at least $0.48 to run it."), on the run's error and its timeline row, after the code `spend_cap_reached (out of budget): `, which pi-ai's retry takes as final. A request the cap refused counts as no model request in the run's usage, on every harness; a run whose only request was refused says "no model request sent". A reply the limit cut short says so on the run's timeline.
36
+ - The model proxy asks the host with a request's own output limit and its least (`outputTokensAsked`, `outputTokensLeast`), and writes the admitted limit (the ticket's `outputTokensMax`) into its body through a policy's new `limitOutput`; it never sends a request unlimited that was admitted with a limit, nor a body longer than the one its input was measured on. The runner's `beforeRequest` may answer `outputTokensMax` beside `holdUsd`, and holds each request in flight at the limit it was admitted with; a limit that is no whole number of tokens above 0 refuses the request, never sends it unlimited.
37
+ - `web_search` and `web_fetch` work on pi, `claude-agent` and `codex` with only a model key. Each resolves in one order: the provider the user picked (the agent's own `definition.tool_settings` over the server's `PUT /v2/settings/tools`), then the native tool, then the kernel's keyless fallback. `web_search` is `auto` by default, native where there is one: Claude's own WebSearch (its adapter is opened with it, and no `web_search` host tool is offered), and on pi one request to the run's own model provider with its hosted search (Anthropic's `web_search_20250305` at 5 searches, OpenAI's Responses `web_search`), read from the provider's events and booked as one of the run's requests, its tokens plus $0.01 a search. On codex it is Codex's own search, each search booked at $0.01, except behind a gateway or under a spend cap, where it is keyless Exa; on claude-agent under a spend cap it is keyless Exa too, since Claude's own search has per-use fees a cap cannot reserve yet; a pi model behind a gateway or on another provider likewise searches Exa's public MCP endpoint with no key (`exa-keyless`, at most 8 results; a 429 at its free limit, or a 403 for a connection that is not direct IPv4, answers `{error}`, never retried). Every provider answers one shape, `{provider, query, results: [{url, title, snippet, published?}], text?}`, snippets cut at 3,000 characters, and the model's copy ends with a line asking it to cite the URLs it relies on; Parallel's search answers it too. `web_fetch` is the kernel's guarded fetch by default, and a page whose text it cuts at 60,000 characters says `truncated: true` with `original_chars` ; Parallel (search and extract) runs only where it is picked, and only then is its key handed to the run; a picked Parallel that gives no page leaves the direct fetch's page saying why (`parallel`), never a silent fallback. A pick of Parallel without `PARALLEL_API_KEY` resolves `unavailable`, and a run naming the tool is refused (`409`). Settings are `{web_search?: {provider: auto|native|exa-keyless|parallel|off}, web_fetch?: {provider: kernel|parallel}}` (`off` turns `web_search` off: nothing is searched, and a run naming it is refused, `409`), kept in the data directory (`tool-settings.json`, 0600); a `permission` is refused (`422 not_yet`) until the tool gate, and `capabilities.features.tool_permissions` is false. `GET /v2/capabilities` gives the two tools a `resolves` per harness, with the providers offered, the server's (`provider`) and the default (`default_provider`): capabilities is the one tool catalog (an unavailable tool says why, `reason`: a provider pick's own words such as `web_search is turned off in settings`, or `Needs` and the variables it is missing), and `GET /v2/agents/{id}` projects it onto the agent as `tools` (each granted tool in the same order; for one with a choice the provider in force, `provider_from`, `default_provider` and `resolved` on its harness and model). Under a run's cap pi's own search request is bounded at its context plus 125,000 input tokens and its most fee (Claude's and Codex's own searches do not run under a cap), its booked cost stops the next request, and a run whose booked spend passes its cap shows one timeline row saying by how much. In `@parcha/pi-durable-agent` a revision keeps `toolSettings`, and the timeline counts any request marked with a string `request` label as a side request, as it did a compaction's summary, and a `web_search` that answers `{error}`, or a `web_fetch` page followed by its line for the model that is `ok: false`, reads as a failed call, in its row and in the run's tool counts. With no key and no native search, web_search falls back to Exa's public keyless MCP endpoint, a third-party service with its own unpublished rate limits (a 429 past them) and terms (https://exa.ai/terms), reached over direct IPv4: set `web_search` to `native` (native only) server-wide or in an agent's `tool_settings` to turn it off, or pick `parallel` with `PARALLEL_API_KEY` to search with a key. `auto`, the default, is native where there is one, else keyless Exa. Upgrading: a server holding `PARALLEL_API_KEY` used to read every `web_fetch` page through Parallel's extract on its own; now it is the guarded direct fetch unless Parallel is picked, so set `PUT /v2/settings/tools {"web_fetch": {"provider": "parallel"}}` to keep that. A run keeps the tools its first launch resolved for its life, and a workflow's model and call nodes' tools resolve whether or not its revision lists them. `claudeAgentAdapter` takes `webSearchAllowance`: with its web search on, a search request is bounded at its body plus that many input tokens, instead of having no bound. `fetch_page` leaves the tool table: it is a legacy name for `web_fetch`, so a revision or call node naming it still saves and runs `web_fetch` under that name, resolved as `web_fetch` is.
38
+ - A turn that a halt ended with a reason now ends `failed`, naming it, never `interrupted` with the reason dropped: a harness's spend cap, its transcript mirror, a refused spawn. Only the session's own stop (its interrupt or its close, told apart by identity with the kernel's `SessionHalt`) and its host's stop end a turn `interrupted`. `abortedOutcome` decides it, and both adapters use it. This changes how spend-cap and mirror halts end a turn: a host that read `interrupted` for them now reads `failed` with the reason.
39
+ - After a crash mid-turn, the claude-agent harness's recovery note no longer reaches the user's answer. The note (which tool calls completed, which may have half-run) was sent as a user message, and the model sometimes answered it back ("No tool calls had run, so nothing needed undoing, and ..."). It now rides in the resuming drive's system prompt. The user's turn holds only the user's own words: the interrupted turn's prompts the transcript lost, and messages sent since. With none, it is a bare "Continue.". A resumed session sends the system prompt recorded at its start, whatever a later launch passes (`systemPrompt.snapshot`, Agent SDK 0.3.286), so the resuming drive alone renders its own (`snapshot: false`). That drive records nothing, so the next drive sends the original prompt again. The note names each tool call of the cut-off turn by its name, id and status, and nothing it read: no input, output or error text. Those can hold what a file or a web page said, and the system prompt would give that the harness's authority. They are not put in the user's turn either, quoted or not, so a recovered turn sees the calls' statuses and is told to check the actual state before relying on them.
40
+ - A claude-agent run whose key the provider refuses now fails at the provider's first 401, in seconds, with the plain key words (for example "OpenRouter refused OPENROUTER_API_KEY (401: User not found): …"). Before, it read Working for about three minutes while the Claude CLI retried the 401 a dozen times. The session's model proxy reads the 401's words from at most 4 KB of its body, for at most 2 s, decoded and with no control character, and ends the turn as the spend cap does. A body with no string message gives no detail, so the run's error carries just the refused-key words. Codex already failed at its first 401.
41
+ - Checking a harness's binary against its pins no longer reads the whole binary into memory, and runs once per binary in a process. `verifyCodexBinary` (the codex binary, 294 MiB) and `verifyClaudeAgentCli` (claude-agent's CLI, 231 MiB) each read the file whole to hash it, and agentrun-serve checked each again for every model it resolved: twice per harness in its start's probe, then once per save and once per run check, and a run's own process once more when it made its adapter. One start probe peaked at 395 MiB of memory, 675 MiB with a default model, past a 512 MiB container's limit. The hash now reads 1 MiB at a time, and a check that passed is kept for the process while the binary stays the same file (its path, device, inode, size, and modification and change times, with the pins); touched or replaced, it is checked again, and a failed check is never kept. The kernel's `@parcha/agentrun-kernel/host` exports both parts, `sha256OfFile` and `checkedOnce`.
42
+ - A harness's own process dies with the process that started it. The Claude Agent CLI runs detached, in its own process group, and does not exit when its stdin closes, so a host that was SIGKILLed (and ran no close) left its CLI running, reparented, one more per crash. `@parcha/agentrun-kernel/host` now has `parentWatched(child)`: on Linux with util-linux setpriv the child starts under `setpriv --pdeathsig KILL --` (the kernel kills it the moment its parent dies), elsewhere under a small node shim that kills it when it is reparented. The Claude Agent machine launches every child with it, inside the host's confinement (`launchCommand`: the confine prefix, then the watch, then the pinned binary), so the death signal is set after any switch of user the prefix makes. The watch adds nothing to the child's environment.
43
+ - A claude-agent or codex run works in the run's workspace, the directory its file tools write to. Before, the CLI's working directory was an empty one beside it (`runs/<id>/harness/work`): Claude told its model that path, so a file written at its absolute path was refused as "outside the workspace", and the answer quoted the server's data directory. In QA this happened in 3 of 4 Claude runs that wrote a file.
44
+ - `SessionIO.cwd`: a host may name the session's working directory, its workspace. The Claude and Codex adapters run their CLI there, and keep their own state in the session's private directory as before. git stops at the workspace's parent. serve passes the run's `work/`.
45
+ - A file tool's refusal, an error such as ENOENT, and a write's or edit's result on claude-agent and codex name paths in the workspace relative to it (`notes/a.md`, `../escape.md: outside the workspace`), never by the server's data directory. A read's result is the file's own text and is not changed.
46
+ - A host tool's result reaches the model whole on claude-agent and codex. The Claude Agent CLI saved an MCP tool's result past 50,000 characters (a long `web_fetch` page, a `monid` answer, a 50 KB `read`) to a file under its own config directory and told the model to read it, which the run's confinement refuses, so the model could not read the page; Codex kept only the two ends of a result past its truncation policy (10,000 tokens for the models its catalog holds, about 12,000 characters for another). `@parcha/agentrun-kernel` states the bound once, `HOST_RESULT_MAX_CHARS` (120,000 characters, over every host tool's largest result); the Claude Agent adapter lists each host tool with it as `anthropic/maxResultSizeChars` and sets `MAX_MCP_OUTPUT_TOKENS` to it, and the Codex adapter sets `tool_output_token_limit` to it as Codex counts it (four bytes of UTF-8 a token: 90,000).
47
+ `web_fetch` (and `fetch_page`) reads a page a part at a time: `offset` and `max_chars` (20,000 by default, at least 200, at most 50,000; a smaller one or an offset below 0 is refused before anything is fetched, saying so; a workflow's call node reads 50,000 by default) name the part, the Page gives `chars`, its length, and a part that is not the whole page has `truncated` while more follows, `next_offset` where it begins and `original_chars` where the whole length is known; an agent reads a line after the JSON saying which characters these are and the offset that reads on. A page whose HTML pi-browser cut at 1,000,000 characters before reading it gives `html_chars`, its whole length, on every part and no `original_chars`, and the line after its last part says `The page was cut at 1,000,000 characters of HTML before reading; the rest wasn't read.`; `converted: "text"` says its text is plain text, its conversion to markdown having run out of time. The text was cut at 60,000 characters with no way to read the rest. A page's links come with the part at offset 0, at most 200 in 20,000 characters, and a URL longer than 4,096 characters is refused before anything is sent.
48
+ `web_search` leaves out its least relevant results when its answer would pass 100,000 characters, and `omitted` counts them.
49
+ - A host tool's result reaches a harness at most `HOST_RESULT_MAX_CHARS` (120,000) characters long. The kernel's tool bridge, which every host tool's result passes on its way to Claude Agent or Codex, keeps a longer one's start, cut where a character ends, ends it with a line saying where it was cut (`[cut at N of M characters]`), and flags the call's `tool_end` `truncated: true`; the call's record keeps the whole result. On a Codex resume, a call the rollout left unanswered is answered from that record with the same cut. A skill file read with `read_skill_file`, a delegate's answer and a rejection listing every schema error reached the harness whole, however long (a 1 MiB skill file, a 6 MB answer).
50
+ - The model proxy now tells the host, before a paid request is sent, the most input tokens it can be billed for. A spend cap could only count a request's cost once it was billed, so a single request whose input alone was over what was left of the cap was still sent and paid. `beforeRequest` now carries `inputTokensMax`: the UTF-8 bytes of the body exactly as it is sent, plus the input the provider adds that the body does not carry. A byte-level BPE token covers at least one byte, so this never undercounts the body, however dense its text. Each `inFlight` entry carries its own `inputTokensMax` until that request answers, so a cap can hold every open request at its own bound. When the provider's addition cannot be read, `inputTokensMax` is undefined, never 0, and a cap treats that input as unknown.
51
+ - What a provider adds is in one place, `providerInputOverhead(api, shape)` from `@parcha/agentrun-kernel/host`. `api` is pi's API kind, and `shape` is whether the request has tools, its tool_choice and its image count. Each figure is the largest the provider documents for any current model:
52
+ - `anthropic-messages`: the tool-use system prompt the Messages API adds to a body with tools, 675 tokens for tool_choice auto or none and 804 for any or tool, plus 4,784 tokens for each image, its high-resolution tier's maximum.
53
+ - `openai-responses`, and the Azure and Codex Responses kinds: no prompt of their own, and 73,800 tokens for each image. That is 30,000 patches, the most an image may have, times 2.46, the largest model multiplier.
54
+ - `openai-completions`, which OpenAI-compatible gateways speak too: nothing for its per-message formatting, since the body's bytes already bound it; 804 tokens when the request has tools, whatever its tool_choice, the largest Anthropic tool-use prompt, since a gateway may route to an Anthropic model; and 73,800 tokens for each image.
55
+ - Every other API kind, among them pi's `mistral-conversations`, `bedrock-converse-stream`, `google-generative-ai`, `google-vertex` and `pi-messages`, and a faux `faux:<id>`: nothing for text, an assumed 2,048 tokens when the request has tools, and 73,800 tokens for each image. The tool allowance for these kinds is assumed, not documented; it is documented only for `anthropic-messages`, the OpenAI Responses kinds and `openai-completions`. `providerInputOverhead` never returns undefined: only a body that cannot be measured is unmeasured.
56
+ - Images are billed by their area, not their bytes, so a small compressed image of large dimensions is counted at its maximum. A Codex body with a file input (a PDF, billed by its pages) is left unmeasured.
57
+ - A provider policy says what its provider adds with `serverInputOverhead(body)`. The Claude and Codex policies read their body's shape and use the figures above.
58
+ - The faux adapter in `@parcha/agentrun-kernel/testing` measures its prompt's UTF-8 bytes for each request, as a real adapter's proxy measures its body.
59
+ - `inputTokensMaxOf(policy, body, sent)` is exported from `@parcha/agentrun-kernel/host`.
60
+ - The proxy serializes the body once before admission and sends exactly what it measured. A body that cannot be serialized is refused before the runner is asked, so it is never booked.
61
+ - A Claude or Codex turn stopped while the session was still recording the person's message stays stopped. Before, the stop found no turn running, so the session read idle, and the stopped message stayed pending and was sent with the next message. Now a turn that ends on its session's stop leaves the session reading `open_turn` while that message is pending, so serve's stop settles it, and it is never sent.
62
+ - A Claude or Codex turn the person stopped stays stopped when the run's process is replaced. Before, the next process found the stopped turn still open in the session and resumed it: it ran its tools and paid for its model requests again, and its answer came before the person's follow-up. Now serve's open reads the run's stop record and settles that turn, ended `interrupted`, with nothing sent, and the follow-up is a turn of its own. A turn a crash or a drain cut is resumed as before.
63
+ - A stop that lands before the harness took the person's message withdraws that message too, so it is never sent later: not with the follow-up in the same process, and not by a process that replaces it.
64
+ - `AdapterSession` has `settleOpenTurn()`: it records the open turn as ended, interrupted, withdraws the input the turn never placed, and sends nothing. The Claude Agent, Codex and faux adapters implement it. A harness that runs as a child process does both with `settleTurn(drive)` from `@parcha/agentrun-kernel/process`. An adapter written outside this repository without it keeps the old behaviour: its stopped turn is resumed.
65
+ - After `interrupt()`, the Claude Agent and Codex sessions read `open_turn` while the stopped turn is still open in their records. serve's stop settles it there; a runner's pause leaves it for the next process to resume.
66
+ - When the earlier process died before it wrote the stopped turn's end, the next one writes it, `interrupted`, before the follow-up's turn starts.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ AgentRun
2
+ Copyright 2026 Parcha Labs, Inc.
3
+
4
+ This product includes software from vercel-labs/durable-harness (https://github.com/vercel-labs/durable-harness), Copyright 2026 Vercel Inc., licensed under the Apache License 2.0.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # @parcha/agentrun-harness-claude
2
+
3
+ The Claude Agent SDK as an AgentRun harness (adapter id `claude-agent`): a DSL `agent` node runs on the Claude Agent CLI
4
+ through `@parcha/agentrun-kernel`, durable in AgentRun's own store, with the host's tools as its only tools.
5
+
6
+ The host brings the SDK: `@anthropic-ai/claude-agent-sdk` is an exact optional peer dependency (0.3.286, whose CLI is
7
+ 2.1.286), used under Anthropic's terms, and this package never ships it. Install it with its optional dependencies (they
8
+ carry the CLI for your platform), or load it where your runtime installed it and pass it in.
9
+
10
+ ```ts
11
+ import { createHarnessRunner } from "@parcha/agentrun-kernel";
12
+ import { claudeAgentAdapter } from "@parcha/agentrun-harness-claude";
13
+
14
+ const runNode = createHarnessRunner(
15
+ claudeAgentAdapter({
16
+ model: "claude-sonnet-4-5",
17
+ provider: { origin: "https://api.anthropic.com", credential: () => process.env.ANTHROPIC_API_KEY! },
18
+ sessionsDir: "/var/lib/my-host/claude-agent-sessions",
19
+ // Optional: the SDK module and its CLI from where the host installed them (checked against the pins).
20
+ // sdk, sdkVersion, cliPath,
21
+ }),
22
+ { store, tools },
23
+ );
24
+ ```
25
+
26
+ - **Pinned, and checked.** Making the adapter checks the SDK's version and the CLI's sha256 and version against the
27
+ pins; a mismatch throws `ClaudeAgentPinMismatch` (which pin, expected, found), and a missing SDK or CLI throws
28
+ `ClaudeAgentNotInstalled` ("Claude Agent SDK not installed"). An SDK that starts the CLI as another release is refused
29
+ before the CLI starts.
30
+ - **The host's tools only.** The CLI's built-in tools are off. The host's tools are its only tools, served in-process
31
+ and named back to the host's own names; each call is a kernel effect whose intent is recorded before it runs, so a
32
+ call a crash cut off is reported, never repeated. A `PreToolUse` hook denies every other call, and every error inside
33
+ it is a deny. Sub-agents, scheduled jobs, worktrees, background shells, settings, plugins and MCP servers from
34
+ settings are off by option, and `test/tool-off.test.mjs` runs the pinned CLI against a scripted model that tries each
35
+ of them: nothing runs, writes or fetches.
36
+ - **Claude's own WebSearch, by option.** `webSearch: true` turns on the CLI's WebSearch and nothing else of its own: the
37
+ proxy then admits Anthropic's web search server tool exactly as the pinned CLI sends it, every other hosted tool stays
38
+ refused, and each search the provider reports is booked at $10 per 1,000 (`CLAUDE_WEB_SEARCH_USD`) beside the tokens,
39
+ into the session's cost and spend cap. A search request has no input bound unless `webSearchAllowance` gives the input
40
+ tokens it may read in beyond its body. WebFetch stays off. Default off.
41
+ - **The model behind a proxy.** The CLI talks to a model proxy on the loopback interface with a key of its session's
42
+ own; it never holds the provider key, a sign-in or the operator's settings. The proxy (`@parcha/agentrun-kernel/host`
43
+ with this package's Anthropic policy) forwards only the routes the pinned CLI calls, fixes the model, refuses
44
+ provider-hosted tools and anything the provider would run or fetch on its own, offers the model only the session's
45
+ tools, and asks the runner before every paid request. Every paid request is booked once; the runner alone accounts
46
+ spend.
47
+ - **A private machine.** A session runs in its own directories. Its working directory is the host's workspace when the
48
+ host names one (`io.cwd`, where the host's file tools write), so a path the model builds from it is one those tools
49
+ take; otherwise it is an empty directory of the session's. The CLI keeps nothing there. The CLI's environment is an
50
+ allowlist (`PATH`, `LANG`, `TZ`, its own homes and the proxy's address and key).
51
+ - **Durable.** The CLI's transcript is mirrored into the session's records (the SDK's session store), so a session a
52
+ process died inside resumes from them on any machine.
53
+
54
+ `./testing` has a scripted Agent SDK (no CLI, key or network) and a scripted Anthropic Messages API for the real CLI.
55
+
56
+ Code this package copies from another project is listed in `vendor/durable-harness/UPSTREAM.json` and credited in
57
+ [NOTICE](NOTICE).
@@ -0,0 +1,123 @@
1
+ import { skillProblems, type AgentAdapter, type HostSkill, type SessionSpec, type ToolImage } from "@parcha/agentrun-kernel";
2
+ import { type ModelProxyOptions } from "@parcha/agentrun-kernel/host";
3
+ import { ClaudeAgentNotInstalled, ClaudeAgentPinMismatch } from "./errors.js";
4
+ import { type ClaudeAgentSdk } from "./harness.js";
5
+ import { type ConfineChild } from "./host/machine.js";
6
+ export { CLAUDE_AGENT_CLI_SKILL_NAMES } from "./cli-names.js";
7
+ /** The pinned CLI's tools the copied harness leaves undecided, off by name in every session (WebSearch unless `webSearch`). */
8
+ export declare const CLAUDE_AGENT_ALSO_OFF: readonly string[];
9
+ /** The local plugin the session's skills are served from: the model sees each as `agentrun:<name>`, and may load it by
10
+ * that name or, unless the CLI has a command or skill of that name (`CLAUDE_AGENT_CLI_SKILL_NAMES`), by its bare one. */
11
+ export declare const CLAUDE_AGENT_SKILLS_PLUGIN = "agentrun";
12
+ /** A skill the model may load (the Skill tool): its name, and its files by path, `SKILL.md` among them. The shape every
13
+ * adapter takes a host's skills in (`HostSkill`, from @parcha/agentrun-kernel). */
14
+ export interface ClaudeAgentSkill extends HostSkill {
15
+ }
16
+ /** The skills, checked: each a name, a `SKILL.md` whose front matter has that name and a description, and files at plain
17
+ * relative paths, 1 MiB in all; or the problems. @parcha/agentrun-kernel' own check, which the Codex adapter runs too. */
18
+ export { skillProblems };
19
+ /** The adapter's id, as a host's `harness` field names it. */
20
+ export declare const CLAUDE_AGENT_ID = "claude-agent";
21
+ /** The pinned CLI's sha256, per platform package, where it is recorded; any other platform is checked by its version. */
22
+ export declare const CLAUDE_AGENT_DIGESTS: Readonly<Record<string, string>>;
23
+ export interface ClaudeAgentProvider {
24
+ /** The provider's origin (`https://api.anthropic.com`): the proxy forwards to its `/v1/messages` only. */
25
+ origin: string;
26
+ /** The provider key, read per request in this process. It never reaches the CLI. */
27
+ credential: () => Promise<string> | string;
28
+ /** How the provider takes it: Anthropic's API takes `x-api-key` (default); a gateway may take a bearer token. */
29
+ auth?: "x-api-key" | "bearer";
30
+ /** Headers sent with every model request, the CLI's small-model calls included (a gateway's spend tags:
31
+ * `{ "x-litellm-tags": "job:...,run:..." }`). The CLI can neither set nor override them. Send a gateway's only to it. */
32
+ headers?: Readonly<Record<string, string>>;
33
+ }
34
+ export interface ClaudeAgentAdapterOptions {
35
+ /** The provider's model id, or one per tier (`default` when a node names none). */
36
+ model: string | {
37
+ default: string;
38
+ fast?: string;
39
+ strong?: string;
40
+ };
41
+ /** The model of the CLI's small background calls. Default: the session's model. */
42
+ smallModel?: string;
43
+ provider: ClaudeAgentProvider;
44
+ /** Start the CLI under the host's confinement (its own `confine()`, a `setpriv --no-new-privs` prefix, say). It may
45
+ * only add in front of the pinned binary and its arguments, and never touches its environment. */
46
+ confine?: ConfineChild;
47
+ /** The price of a response; null (or no function) records its cost as unknown. */
48
+ price?: ModelProxyOptions["price"];
49
+ /** The most output tokens one request may ask for. Default 128 000, what the pinned CLI asks for on current models. */
50
+ maxOutputTokens?: number;
51
+ /** The most one image a tool answers with may be, as base64 (default 5 MB, `CLAUDE_AGENT_MAX_IMAGE_BYTES`; at most
52
+ * 10 MB, Anthropic's API's own limit). A larger one is the call's error. */
53
+ maxImageBytes?: number;
54
+ /** Where sessions keep their private directories when the host lends none (`io.dir`): one per session key. */
55
+ sessionsDir?: string;
56
+ /** The host's skills, which the model may load with the Skill tool (as `agentrun:<name>` or by the bare name), and no
57
+ * others: never the CLI's bundled ones or any in a home directory. Written into each session's private directory.
58
+ * Default none. */
59
+ skills?: readonly ClaudeAgentSkill[];
60
+ /** Claude's own WebSearch, and nothing else of the CLI's: the model may call it, and the CLI runs each call as a request
61
+ * of its own through the session's model proxy with Anthropic's web search server tool, the one hosted tool that proxy
62
+ * then admits. Each search the provider reports is booked at `CLAUDE_WEB_SEARCH_USD` on top of `price`, into the
63
+ * session's cost and so its spend cap. WebFetch stays off (it would fetch from the CLI's own process). Default off. */
64
+ webSearch?: boolean;
65
+ /** With `webSearch`: the input tokens a search request may read in beyond its body, added to its input bound, so a cap
66
+ * can hold it (`inputTokensMax`). Absent, a search request has no input bound. */
67
+ webSearchAllowance?: number;
68
+ /** Diagnostics. */
69
+ log?: (message: string, fields?: Record<string, unknown>) => void;
70
+ /**
71
+ * The Agent SDK module, loaded by the host (from where its runtime installed it). Default: imported by name. Either
72
+ * way it must be the pinned release (`CLAUDE_AGENT_SDK_VERSION`): the CLI it starts says its version, and a
73
+ * different one is refused before the CLI starts.
74
+ */
75
+ sdk?: ClaudeAgentSdk;
76
+ /** The injected module's version, as its package.json says: checked when the adapter is made. */
77
+ sdkVersion?: string;
78
+ /** The CLI to run (the SDK's platform package's `claude`). Default: found beside the SDK. Its sha256 and version are
79
+ * checked against the pins when the adapter is made. */
80
+ cliPath?: string;
81
+ /** For tests only (AGENTRUN_CLAUDE_AGENT_STANDIN=1 under a test runner): a scripted SDK's stand-in CLI, which no
82
+ * pin is checked against. */
83
+ standIn?: {
84
+ command: string;
85
+ };
86
+ /** How hard the model thinks when a node names no level (its `thinking`, else its `effort`). Default medium; it is
87
+ * never off. */
88
+ thinking?: ClaudeAgentThinking;
89
+ /** For tests: the fetch the model proxy forwards with. */
90
+ fetch?: typeof fetch;
91
+ }
92
+ /** The thinking levels a session runs at: the SDK's effort levels, with adaptive thinking. There is no off. */
93
+ export type ClaudeAgentThinking = "low" | "medium" | "high" | "xhigh" | "max";
94
+ /** A session's level: the node's thinking, else its effort (minimal thinks at low, never at nothing), else the adapter's. */
95
+ export declare function thinkingOf(spec: Pick<SessionSpec, "thinking" | "effort">, fallback: ClaudeAgentThinking): ClaudeAgentThinking;
96
+ /** The pins a CLI is checked against: its sha256 on this platform (where one is recorded) and its version. */
97
+ export declare function claudeAgentCliPins(): {
98
+ sha256?: string;
99
+ version: string;
100
+ };
101
+ /** The CLI at `path`, checked against the pins: its path, or the typed reason it is not the pinned build. Its sha256 is
102
+ * read a chunk at a time, never the whole CLI in memory, and a check that passed holds for this process while the CLI
103
+ * stays the same file, unchanged (the kernel's checkedOnce): a host that checks it for each model it resolves, and a
104
+ * run's process that makes its adapter, check it once. */
105
+ export declare function verifyClaudeAgentCli(path: string | undefined, pins?: {
106
+ sha256?: string;
107
+ version: string;
108
+ }): {
109
+ path: string;
110
+ } | ClaudeAgentPinMismatch | ClaudeAgentNotInstalled;
111
+ /** What the adapter runs with, or the typed reason it cannot: the SDK (injected or installed) and its CLI, each the
112
+ * pinned build. `installed` looks a package's version up (default: where Node would import it from here). */
113
+ export declare function verifyClaudeAgent(options: Pick<ClaudeAgentAdapterOptions, "sdk" | "sdkVersion" | "cliPath">, installed?: (name: string) => string | undefined): {
114
+ cliPath: string;
115
+ };
116
+ /** The kernel's tool for a host tool: the same name, schema and replay policy, reported to the host under that name. */
117
+ /** The most a tool's image may be, as base64, by default: the strictest of the platforms Claude runs on (Anthropic's API
118
+ * takes 10 MB, Amazon Bedrock 5 MB), so one setting holds everywhere. */
119
+ export declare const CLAUDE_AGENT_MAX_IMAGE_BYTES: number;
120
+ /** Why a tool's images can't be sent, naming the tool and the image, or undefined: a type the API takes, base64, and at
121
+ * most `maxBytes` of it. */
122
+ export declare function toolImageProblems(tool: string, images: readonly ToolImage[], maxBytes?: number): string | undefined;
123
+ export declare function claudeAgentAdapter(options: ClaudeAgentAdapterOptions): AgentAdapter;