@parcha/agentrun-harness-claude 0.1.0-beta.57 → 0.1.0-beta.59
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 +55 -0
- package/dist/adapter.d.ts +7 -3
- package/dist/adapter.js +3 -3
- package/dist/env.d.ts +11 -1
- package/dist/env.js +18 -5
- package/dist/facts.d.ts +1 -0
- package/dist/facts.js +5 -0
- package/dist/harness.d.ts +9 -5
- package/dist/harness.js +36 -4
- package/dist/host/policy.d.ts +1 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/login-refresh.d.ts +22 -0
- package/dist/login-refresh.js +45 -0
- package/dist/login.d.ts +40 -10
- package/dist/login.js +131 -33
- package/dist/store.d.ts +41 -5
- package/dist/store.js +85 -39
- package/dist/testing/fake-sdk.d.ts +11 -0
- package/dist/testing/fake-sdk.js +65 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.59 (2026-11-25)
|
|
6
|
+
|
|
7
|
+
**Breaking:**
|
|
8
|
+
|
|
9
|
+
- Ollama models run only on a harness that forwards the route, an output schema beside tools on Ollama is refused, and an ACP agent's permission requests for AgentRun's tools are no longer answered from their titles. What to change on upgrade: <!-- changes/b51-breaking.md -->
|
|
10
|
+
- A harness module on Messages or Responses that should keep running Ollama models must forward its model requests with the `fetch` its launch hands it (`ModuleLaunch.fetch`, given to `startModelProxy`'s `fetch`) and set `forwardsRoute: true` in its facts. Without the fact it is offered no Ollama model, and a run of it that names one is refused before it starts, in words that name these two steps.
|
|
11
|
+
- A claude-agent node with an output schema on an Ollama model now stops with a 400 `invalid_request_error`, since the claude-agent harness sends its tools on every turn and Ollama can't hold an answer to a format and also call tools. Drop the schema, or run the node on a model with a key.
|
|
12
|
+
- A recipe for an agent that asks permission before every tool call needs an `allowFile` in a form its agent reads, or the title tie (`quirks.permissionTie: "title"`). Without either, every request for an AgentRun tool goes to the host's gate as the agent's own call, and its runs stop there.
|
|
13
|
+
- An agent's `tool_call` title no longer names the AgentRun tool it calls. A recipe without `announces` (the new field where its agent's `tool_call` names the tool) has every call matched to its MCP call by its arguments alone, a call with no arguments included. A call announced with no input at all is matched to an MCP call that nothing else matches, the oldest first, until the agent reports it ended, so two such calls in flight can trade ids. Declare `announces` to tie each call to its own.
|
|
14
|
+
- Goose's offer promises `tool_gate: "config"` (was `"permission"`): its calls of AgentRun's tools are held by its permission file and the host's gate at the MCP call.
|
|
15
|
+
- `agentrun harness-check` fails `mcp_tool` for an agent that asks permission for `check_echo` on a recipe with neither field. A recipe whose check passed before can fail its next one.
|
|
16
|
+
- `examples/harness-recipe/antigravity.json` declares `announces` and the title tie (`quirks.permissionTie: "title"`), since agy asks permission for every MCP call: its requests for the AgentRun calls it announced are answered allow once, and the host's gate decides at the MCP call. A copy of the recipe made before this release has neither and needs both, or its runs stop at the gate.
|
|
17
|
+
- The exported test helper `fakeAgentRecipe` (`@parcha/agentrun-harness-acp/testing`) now gives its recipe an `allowFile` (style "goose", the default) or the title tie (style "cursor"), and each style's `announces`, as each shipped recipe does. The fake's style "cursor" now announces its MCP calls late, as Cursor 2026.11.13 does (`announce: "early"` for the old shape). A suite that relied on the fake asking for AgentRun's tools and being answered from the title gets neither by default.
|
|
18
|
+
- On macOS, signing in to Claude from the console now saves the login's Keychain item under the Mac user the server runs as, so `claude auth status` in that person's terminal reads it signed in, as AgentRun's badge does. Before, the claude CLI that AgentRun starts for the sign-in, the status check and a run got no `USER`, so the item's account was `unknown`. Those three now carry `USER` and `LOGNAME` set to the user the server runs as (`os.userInfo()`), even when the server itself was started without `USER` or with another user's. <!-- changes/claude-keychain-account-user.md -->
|
|
19
|
+
|
|
20
|
+
Who breaks: anyone who signed Claude in from the console on macOS before this release. That login reads signed out once the server is updated, since its item is under `unknown`. What to do: sign in again under Settings → Model keys. The old item stays in the Keychain under the account `unknown`; `@parcha/agentrun-serve`'s changelog for this version says how to delete it.
|
|
21
|
+
|
|
22
|
+
**Changes:**
|
|
23
|
+
|
|
24
|
+
- A model the runner's route translates onto a harness's wire (this machine's Ollama models on Anthropic's Messages and OpenAI's Responses) is offered only to a harness whose proxy forwards with the route's `fetch`, and the Messages translation no longer drops what it can't run. Before, any harness on the wire was offered those models, including a module that sends its requests to the network, where nothing answers. <!-- changes/b51-route-hints.md -->
|
|
25
|
+
- `AdapterFacts` gains `forwardsRoute`. claude-agent, Goose, codex and opencode set it, and so does every recipe that builds on Goose's facts. A harness without it is offered none of the route's models, takes none as its default, and its words say to add a key ("No model yet for <harness>: add an OpenRouter or Anthropic key"). A run that names one is refused before it starts.
|
|
26
|
+
- An output schema (`output_config.format` of type `json_schema`) on a Messages request with no tools now reaches Ollama as its `format`. Before, it was dropped and the answer came back unconstrained. Beside tools it is refused with a 400 `invalid_request_error` that says to drop the output schema or use a model route that takes tools with a format, because Ollama holds the whole answer to the format and leaves the model no way to call a tool.
|
|
27
|
+
- The Messages translation answers `POST /v1/messages` and `POST /v1/messages/count_tokens` alone. Any other method or path is a 404 `not_found_error` in Anthropic's error shape, and nothing reaches Ollama.
|
|
28
|
+
- `agentrun harness-check` on a model the route translates (`--model ollama/<tag>`) now reaches it. Its recorder wraps the route's own fetch, so the recipe's agent gets the same route a server's run gets and the check still sees every request. Before, every request went to the route's placeholder origin and `mcp_tool` failed.
|
|
29
|
+
- A run's trace no longer costs or carries what it should not. Under `agentrun-serve runner`, where each run is a process of its own, a run's end waited up to 3 s on the collector, since that process flushed its own spans before it exited: now it sends its trace to its runner, which exports it in the background, and a run's process never holds an `OTEL_*` setting at all. The runner reads that trace as untrusted: every string it carries (a provider, a host, a call id, a request's or turn's end, a failure) is cut of every secret the runner holds, or taken only from values the runner knows, and a call's id, its parent's or a route's name longer than 128 characters is kept as its SHA-256, so a run's process can't hold megabytes of ids open in its runner. A name the model wrote no longer reaches a span as written: a call the harness refused (a tool the session does not have; the kernel's `tool_start` event says `refused: true`, which claude-agent now sets) is `execute_tool` with `error.type=tool_refused` and no tool name, a model the run does not know (not a route's model, nor one its price table names by that same id) is named by its route's model, and every name is cut of every secret the runner holds and at 64 characters. Each value of `OTEL_EXPORTER_OTLP_HEADERS` and `OTEL_EXPORTER_OTLP_TRACES_HEADERS` of 8 characters or more is now a secret the server and the runner hold, under any header name, an unknown one too, but a `Content-Type`, `Accept`, `Content-Encoding` or `User-Agent` header's value, and a dataset or tenant header's (`x-honeycomb-dataset`, `x-axiom-dataset`, `x-scope-orgid`), which is only cut from the tracer's `[otel]` lines, so a dataset named `production` refuses no source capture. A credential is held without the word before it too, after a known auth scheme (`Bearer`, `Basic`, `Api-Key`, `Api-Token`, `Token`, `sentry`, `Splunk`, `GenieKey`) or under a credential-named header (`authorization`, `x-sentry-auth`, `x-api-key`); any other header's value is held whole, never its tail alone. So are an OTLP endpoint's user, password and each query parameter named like a credential: a word of its name is a credential word or ends in key, token, secret, password, auth, sig, signature or credential (`api_key`, `access_token`, `apiKey`, `accesstoken`, `writekey`; never `authority` or `keyspace`). A comma inside a header value must be written `%2C`. The tracer's own `[otel]` lines, where an exporter's error may quote a header it sent, are cut of each such value at any length, a short one too, and of what follows any header value's first word; everywhere else (the runner's logs, what a run writes, a served run, a source capture) a held value is still cut at 8 characters or more and a shorter header value is on no held list, on purpose, since a needle of a few characters would cut ordinary text, turn a served number such as `1` into `[redacted]`, or refuse a source capture of any project that holds it. <!-- changes/otel-trace-names-and-child-export.md -->
|
|
30
|
+
- The Claude login on this machine now uses the folders the server's env gives it only when they belong to the server's own user, as it already did for the home. Those folders are `CLAUDE_CONFIG_DIR`, `CLAUDE_SECURESTORAGE_CONFIG_DIR`, and `ANTHROPIC_CONFIG_DIR` or else `XDG_CONFIG_HOME`'s `anthropic`. Each one must be a folder that user owns, or a folder still to be made inside one it owns. The home and these folders are judged by one rule, so that no other user can change where the path leads after the check: <!-- changes/claude-login-config-dirs.md -->
|
|
31
|
+
|
|
32
|
+
- The path is walked as the system walks it, one name at a time, so a trailing slash, `.` or `..` hides nothing, and a `..` after a link goes up from where the link leads. Each link on the way, and each link in the chain it leads through, must be one that user or root made.
|
|
33
|
+
- Each folder above the real folder must be that user's or root's, and not one others may write in (anyone, or its group, unless that group is the user's private one), unless the sticky bit keeps each entry its maker's (as /tmp has it).
|
|
34
|
+
- The folder itself must be that user's and not open to others' writes by the same rule. So must the folder a still-to-make one is made in, sticky or not, so a folder still to make in /tmp is refused, root's included.
|
|
35
|
+
- The CLI gets the real path the check looked at (the home included), from the same look: each decision (a run, the sign-in, the Settings view's line and status check, a turn-on) walks the folders once and takes the login, or the refusal, from that walk, never the path as given. Where the folders are refused, the view's `command` is empty and its `folder` is the folder as the env names it. Where the env's path has a link on it, the shown sign-in line and the CLI now name the folder the link leads to. On macOS the CLI names its Keychain item after that folder, so a login the person's own Claude CLI keeps under a path with a link reads as signed out until it is signed in again from here.
|
|
36
|
+
|
|
37
|
+
A server started under a sudo that keeps the env (root, with the person's `CLAUDE_CONFIG_DIR`) no longer signs the Claude CLI in as root inside the person's folder. Where a folder fails the check, the turn-on and the sign-in at this machine's login are refused (403) in words that name the variable and the folder, and no run goes on the login. AgentRun's own login keeps its folders in the data folder, so the env's folders refuse nothing there, but the home rule above applies to both places. A login saved before on folders, the home's included, that fail the check is kept, not turned off: the start logs why it is not used, every read refuses it in those words, and it is back once the folder is mended (a chmod, or the server started as the right user). A chmod needs no restart: a run's check, a save's, a template's plan or apply, and capabilities look at the folders again, so the login is offered and runs again as soon as the view reads it signed in, and stops again once its folder is refused. Such a request asked while the server is still making the offers again from such a change, or from a turn-on or turn-off, waits for them, and the server logs `claude_login_wait` as it waits, with `why`: `queue` (behind a turn-on, turn-off or sign-in), `refresh` or `turn`. A sign-in, a turn-on or a turn-off never waits for those offers. The Settings view says such a login is `refused`, with why, and offers Turn off, which removes it; until then no API key is made. The refusal words now name the server's user (`uid 501 (svc)`, say), the home's refusal included. A folder that is the user's but open to others' writes is refused in words of its own, which name the open folder, its mode and the `chmod g-w,o-w` that closes it. A folder of this machine's login still to make is made by AgentRun at the turn-on and before the CLI's sign-in, 0700 whatever the umask, and checked again before the CLI gets it, so a login the CLI signs in there is not refused after.
|
|
38
|
+
|
|
39
|
+
Where the env's `HOME` is another user's and the login therefore uses the server's user's own home, the sign-in line the Settings view shows now carries `HOME=<that home>`. Before, it left `HOME` to the terminal, so the line run in the person's terminal signed in to their own home, which the server never reads. The harness's `ClaudeAgentLogin` has a new optional `homeApart` that asks for this.
|
|
40
|
+
|
|
41
|
+
A folder its group may write in is the user's alone where that group is the user's private one, as the local account files alone say: `/etc/nsswitch.conf` takes users and groups from those files only (`files` or `compat`), and the group is the user's primary group, which no other user has as theirs and which `/etc/group` lists with no other member. So a umask of 002 under such a group refuses nothing there. A switch that also asks another source (sssd, LDAP, NIS, winbind, or systemd's user records, as recent Ubuntu, Debian and Fedora installs do) can give the group members the files do not show, so there such a folder is refused.
|
|
42
|
+
|
|
43
|
+
Behaviour change: a login that ran before is refused, at either place, where the server's home is a folder anyone may write in, or its group where another user is in it, or is reached through one (a home on a volume whose group is set for a pod, 2775, say). So is a login on this machine's folders where one of these variables points at another user's folder, or reaches through another user's link or folder, or through such an open folder. A group shared with other users, a group that is not the user's primary one, one `/etc/group` does not list, account files that defer to a directory service (a `+` or `-` line), and any group where `/etc/nsswitch.conf` asks a source other than the files for users or groups, or is missing, all count as open: under a umask of 002 with such a group, a home, a `~/.config` or a `CLAUDE_CONFIG_DIR` folder made by hand is refused until it is `chmod g-w`. The setting stays. Start the server as the person whose Claude plan it is, with that person's variables, and make the folders on the way writable by their owner alone.
|
|
44
|
+
|
|
45
|
+
## 0.1.0-beta.58 (2026-11-25)
|
|
46
|
+
|
|
47
|
+
- More follow-ups to the Claude login on this machine (Settings → Model keys), and to the server's probe of the harness offers. <!-- changes/claude-sign-in-followups-2.md -->
|
|
48
|
+
- A tool key's save or delete while the offers held are behind the inputs, and the probe out was made from the inputs read now (a turn-on of the login, say), waits for that probe's turn and starts no probe of its own while it lands. The turn ends when the probe lands or fails, or when a later probe overtakes it; the change then reads the inputs again: landed, it composes the capabilities; failed, it probes for itself; overtaken, it goes by the later probe. So it never answers `500` for another request's failed probe once its key is stored, never waits on a dropped probe, and its key always shows in the capabilities it answers after. Before, it started a probe that dropped the one out, so the save answered only after a whole probe of its own. The server logs `harness_offers_wait` as it waits.
|
|
49
|
+
- A probe of the offers that fails leaves no probe out when it was the latest one, so a later change back to the inputs the offers held were made from reuses them. Before, that change probed again.
|
|
50
|
+
- The Playground's "No model yet" bar is gone while the login is on and reads signed in, no agent is picked (no agents yet, or the agents still being read), and the server's default place is the runner, where a first agent on Claude Agent runs on the login. The bar's ChatGPT and key offer goes with it, whatever harness the first agent will use. On a server whose default place is a box, or before its places are read, the bar stays: a first agent there runs in the box on the model keys. Before, a Playground with no agents offered ChatGPT or a key though an agent on Claude Agent would run on the login.
|
|
51
|
+
- A run of an agent on Claude Agent in a box, refused for its model while the login is on, on a model the login runs (Anthropic's own, `anthropic/<id>`, or none named), says that the login runs agents on the runner only, names the box, and says that moving the agent to the runner runs it on the login. Its `409 agent_not_runnable` carries a new `details.login_on_runner: true` (additive), and the Playground offers "Move it to the runner" there, which saves the agent's definition with its computer set to none and its box-only tools dropped, as the agent's Computer step does, and names the tools it dropped. Which tools run only in a box is the capabilities' word: a move taken before they are read, or after their read failed, reads them itself, and while that read fails it saves nothing and says so. The Computer step, with no tools read, refuses a pick that puts the agent on the runner, in words, and changes nothing. Before, either saved the agent on the runner with bash still granted, and its next run was refused there. The offer is the refused agent's: it shows only while that agent is picked and moves only that agent. After the move, a revision picked in the Playground becomes the one the move saved, so the next request runs on the runner. An agent already on the runner is not saved again. The login still runs agents on the runner only. An agent on any other model (an OpenRouter one, Anthropic's through OpenRouter included) is offered no move: on the runner it still needs its provider's key, which its refusal names. Serve puts a run on the login and makes the offer by one rule.
|
|
52
|
+
- A run's check of the login takes the Settings view's signed-in answer from a runner in a process of its own on the same data folder (`agentrun-serve --no-runner` beside `agentrun-serve runner`). The answer is kept in the data folder's `claude-login-answers/`: one file per login (0600, in a 0700 folder), named by a hash of the machine's id and the login, holding only the time; a signed-out answer removes it. A run's check reads it only as a regular file of at most 32 bytes, never through a link, and a FIFO there is no answer rather than a held check. A note tightens a wider folder to 0700 and never writes through a link at its name. On disk, an answer outlives a server restart for up to its 10 minutes. Before, it was in the server process's memory, so such a runner refused a first run whose two checks timed out right after Settings read signed in.
|
|
53
|
+
- A sign-in whose CLI is a script naming an interpreter that is not there (`#!/path`, or `#!/usr/bin/env <program>` with the program on no folder of the sign-in's PATH) fails at its start, in words that name the interpreter. Before, the parent watch's exit 127 read as the CLI's own exit. The `#!` line is read as the kernel reads it, as bytes, so an interpreter under a folder whose name is not ASCII (a home folder named `José`, say) is found.
|
|
54
|
+
- `parentWatched` throws a `RangeError` at the call for a `termGraceMs` the parent-watch shim would refuse (anything but a whole number of ms from 1 to 2^31 - 1), whichever watch is asked for. Before, the shim exited 2 at spawn, which read as the child's own exit.
|
|
55
|
+
- The status check reads an answer that is already in the CLI's output when the drain's second ends, though the server's event loop was held up past that second. Before, the loop ran the drain's timer before its reads, and the check read `no_status`.
|
|
56
|
+
- Where each run is a user of its own (the image, `run_isolation: "uid"`), a claude-agent run now runs on the Claude login in AgentRun's own login folder instead of failing at its claim. The runner, as the server's user, reads the login's access token from that folder and hands the run's CLI that token alone, in `CLAUDE_CODE_OAUTH_TOKEN`: never the folder and never the refresh token, so the run's CLI never renews the login. The runner reads the folder again when the run starts and whenever Anthropic refuses the token mid-run, so a renewal your own Claude CLI wrote there is picked up. The runner also renews the login itself, in the CLI's place, when a token has less than five minutes left and after Anthropic refuses one mid-run: it sends the pinned CLI's own refresh request, holds the CLI's own refresh lock on the folder, reads the file again under it (a renewal by the CLI or another runner is taken, and nothing is sent twice), and writes the answer back to that folder's `.credentials.json` alone, atomically at mode 0600, every other field kept. It holds the lock as the CLI does, by the directory it made and the mtime it set (to the microsecond; on a filesystem that keeps whole seconds alone, any mtime in that second, as the CLI reads its own lock there), so a lock another holder took over while the runner was paused is never touched or removed, and nothing is sent under it. Runners take the lock one at a time, a dead one included, through a short-lived `.takeover` directory beside it, so two runners never hold it at once, unless a runner stalls past the 60 s stale time inside a takeover or between its last check of the lock and its removal of it (every lock that expires has these gaps). The CLI does not see that directory: between a runner and the CLI the lock is as safe as the CLI's own, and where the CLI's second lock beside the login folder can be made, it keeps the two from both sending. If the write back fails, the runner keeps the new pair in memory: later asks get its token, send nothing (the old refresh token is spent and never sent again) and try the write again, under the same lock and after reading the file again, so a newer pair another holder wrote is kept; once that token has less than five minutes left and is still unsaved, the run fails in words that say the renewal could not be saved and what to fix. A held token Anthropic refuses is never handed again: the ask fails while its pair is unsaved, and once the pair is saved the runner renews from it. One ask sends at most one renewal and nothing retries it. A renewal that fails, a refresh token Anthropic refused included, fails the run at its start, and ends the turn mid-run, in words that say to open the Claude CLI once to renew the login; a token refused mid-run that the runner had no way to renew ends the turn in words that say to run the claude CLI once on this login to renew it. No token is in the runner's log or in any error, and each token handed is cut from the run's journal, messages and rows as the runner writes them. A command the run's CLI starts can read the token, as the run's own user can. Under per-run users, a run on this machine's own Claude login (`~/.claude`, or the `CLAUDE_CONFIG_DIR` AgentRun was started with) still fails at its claim. So does a login run while another runner on the same data folder runs its login runs under the server's user, and the error names that runner. A login kept in a form the runner does not read fails in words too. For each of these, set `AGENTRUN_RUN_USER=same` or give the run a `model_key`. `claudeAgentAdapter({ login })` in `@parcha/agentrun-harness-claude` also takes `{ token(), refused?(sent) }`, a host's reader of the login's access token: on the CLI's request for a newer token it tells the host which token was refused, then answers from `token()`. The pinned CLI's refresh request, lock and write back are exported as `CLAUDE_LOGIN_REFRESH` (and `loginRefresh` from `/facts`), and a test reads each of them in the installed CLI. <!-- changes/claude-login-per-run-users.md -->
|
|
57
|
+
- A host tool with replay `never` called early in a long message of parallel calls now runs. Such a tool waits until the transcript line that made its call is in the log, and the Agent SDK hands the log a message's lines only once the whole message has streamed, while the CLI starts each call as its block ends. The 10 s wait was counted from the call, so in a message of 12 calls streamed about 1.3 s apart the first calls were refused ("the transcript entry for tool call ... did not reach the log within 10000 ms") though nothing was wrong. The wait's clock now restarts on each stream event of the message that made the call (the main thread's, or a subagent's own), so it runs out 10 s after that message ends, or after its last event if the stream stalls; a call whose line never lands is still refused then. A message's end unties its calls from the stream, so the next message in the same stream (the main thread's next answer, say) never holds them open. A short message waits as before. <!-- changes/claude-barrier-message-end.md -->
|
|
58
|
+
A call the CLI refuses itself early in such a message is shown to the host again: its answer line comes with the rest of the message, and the wait for it had run out the same way, so the refusal was only logged ("a refused call is not shown").
|
|
59
|
+
|
|
5
60
|
## 0.1.0-beta.57 (2026-11-24)
|
|
6
61
|
|
|
7
62
|
**Breaking:**
|
package/dist/adapter.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { skillProblems, type AgentAdapter, type HostSkill, type SessionSpec, typ
|
|
|
2
2
|
import { type ModelProxyOptions } from "@parcha/agentrun-kernel/host";
|
|
3
3
|
import { ClaudeAgentNotInstalled, ClaudeAgentPinMismatch } from "./errors.js";
|
|
4
4
|
import { type ClaudeAgentSdk } from "./harness.js";
|
|
5
|
+
import { type BarrierTimers } from "./store.js";
|
|
5
6
|
import { type ConfineChild } from "./host/machine.js";
|
|
6
|
-
import type { ClaudeAgentLogin } from "./login.js";
|
|
7
|
+
import type { ClaudeAgentLogin, ClaudeLoginToken } from "./login.js";
|
|
7
8
|
import type { ToolServerModules } from "./host/tool-server.js";
|
|
8
9
|
export { CLAUDE_AGENT_CLI_SKILL_NAMES } from "./cli-names.js";
|
|
9
10
|
/** The pinned CLI's tools off by name in every session (WebSearch unless `webSearch`): those the copied harness leaves
|
|
@@ -47,8 +48,9 @@ export interface ClaudeAgentAdapterOptions {
|
|
|
47
48
|
provider?: ClaudeAgentProvider;
|
|
48
49
|
/** A person's own login on this machine (login.ts), which the CLI runs on in place of a provider: it calls Anthropic
|
|
49
50
|
* itself, with no proxy, no model URL and no key of the host's; each response is booked from its stream, billed to the
|
|
50
|
-
* person's plan (`price` is not read), and the session has no host port. The host
|
|
51
|
-
|
|
51
|
+
* person's plan (`price` is not read), and the session has no host port. The host says where the login is, or hands
|
|
52
|
+
* its access token alone (ClaudeLoginToken), asked at each start of the CLI and on a 401. */
|
|
53
|
+
login?: ClaudeAgentLogin | ClaudeLoginToken;
|
|
52
54
|
/** Start the CLI under the host's confinement (its own `confine()`, a `setpriv --no-new-privs` prefix, say). It may
|
|
53
55
|
* only add in front of the pinned binary and its arguments, and never touches its environment. */
|
|
54
56
|
confine?: ConfineChild;
|
|
@@ -95,6 +97,8 @@ export interface ClaudeAgentAdapterOptions {
|
|
|
95
97
|
standIn?: {
|
|
96
98
|
command: string;
|
|
97
99
|
};
|
|
100
|
+
/** For tests: the timers a host tool's wait for its call to reach the log runs on (a fake clock). Default the system's. */
|
|
101
|
+
barrierTimers?: BarrierTimers;
|
|
98
102
|
/** How hard the model thinks when a node names no level (its `thinking`, else its `effort`). Default medium; it is
|
|
99
103
|
* never off. */
|
|
100
104
|
thinking?: ClaudeAgentThinking;
|
package/dist/adapter.js
CHANGED
|
@@ -336,8 +336,7 @@ export function claudeAgentAdapter(options) {
|
|
|
336
336
|
...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}),
|
|
337
337
|
...(provider.auth ? { auth: provider.auth } : {}),
|
|
338
338
|
...(provider.headers ? { headers: provider.headers } : {}),
|
|
339
|
-
//
|
|
340
|
-
// the run's zone. A session on a login has no proxy, and keeps the machine's date.
|
|
339
|
+
// The CLI's own date lines follow the clock (policy.ts `day`).
|
|
341
340
|
...(options.now ? { day: () => isoDay(options.now(), options.zone) } : {}),
|
|
342
341
|
...(options.log ? { log: options.log } : {}),
|
|
343
342
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
@@ -372,6 +371,7 @@ export function claudeAgentAdapter(options) {
|
|
|
372
371
|
...(options.log ? { log: options.log } : {}),
|
|
373
372
|
...(options.now ? { now: options.now } : {}),
|
|
374
373
|
...(options.zone ? { zone: options.zone } : {}),
|
|
374
|
+
...(options.barrierTimers ? { barrierTimers: options.barrierTimers } : {}),
|
|
375
375
|
// The host's gate, asked about each host-tool call and each WebSearch before it is written or run.
|
|
376
376
|
...(io.gate ? { gate: (call) => io.gate(call) } : {}),
|
|
377
377
|
});
|
|
@@ -399,7 +399,7 @@ export function claudeAgentAdapter(options) {
|
|
|
399
399
|
// A call the CLI refused itself (a tool the session doesn't have): shown as a call that failed, by the name the
|
|
400
400
|
// model gave. The CLI's transcript, mirrored to the store, keeps the refusal.
|
|
401
401
|
if (e?.type === "tool_refused" && typeof e.callId === "string" && typeof e.name === "string") {
|
|
402
|
-
io.onEvent({ type: "tool_start", callId: e.callId, name: e.name, args: e.args ?? {} });
|
|
402
|
+
io.onEvent({ type: "tool_start", callId: e.callId, name: e.name, args: e.args ?? {}, refused: true });
|
|
403
403
|
io.onEvent({ type: "tool_end", callId: e.callId, name: e.name, isError: true });
|
|
404
404
|
options.log?.("claude-agent: the CLI turned down a call to a tool this session does not have", { name: e.name, reason: e.reason });
|
|
405
405
|
}
|
package/dist/env.d.ts
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* CLI's behavior; none reaches the child unless it is listed here.
|
|
9
9
|
*/
|
|
10
10
|
import { type ClaudeAgentLogin } from './login.js';
|
|
11
|
-
/** What never reaches a CLI that runs on a person's login: a model URL, key or token of
|
|
11
|
+
/** What never reaches a CLI that runs on a person's login from the app's own variables: a model URL, key or token of
|
|
12
|
+
* any kind, a refresh token or a token's file descriptor among them. A login handed as a token sets its own
|
|
13
|
+
* CLAUDE_CODE_OAUTH_TOKEN after. */
|
|
12
14
|
export declare const LOGIN_UNSET: readonly string[];
|
|
13
15
|
/** The `PATH` of the CLI and its commands in the VM: the image's, never the Function's. */
|
|
14
16
|
export declare const VM_PATH = "/usr/local/bin:/usr/bin:/bin";
|
|
@@ -36,6 +38,12 @@ export interface DurableEnvOptions {
|
|
|
36
38
|
* environment has no model URL or key at all (login.ts).
|
|
37
39
|
*/
|
|
38
40
|
login?: ClaudeAgentLogin;
|
|
41
|
+
/**
|
|
42
|
+
* The person's own login handed as its access token alone (login.ts ClaudeLoginToken, read by the host for this
|
|
43
|
+
* start), in place of the model port and of `login`: the CLI gets it as CLAUDE_CODE_OAUTH_TOKEN, with no refresh token
|
|
44
|
+
* and no login directory (its credentials directories are the session's own), and a 401 never parks it.
|
|
45
|
+
*/
|
|
46
|
+
oauthToken?: string;
|
|
39
47
|
/** The platform the CLI runs on, this host's by default. On macOS a CLI on a login runs in the person's home (`HOME`). */
|
|
40
48
|
platform?: NodeJS.Platform;
|
|
41
49
|
/** The model, as the CLI's main and alias models. */
|
|
@@ -65,6 +73,8 @@ export interface DurableEnvOptions {
|
|
|
65
73
|
* - `HOME`, `CLAUDE_CONFIG_DIR`, `TMPDIR` and the XDG dirs in the session's
|
|
66
74
|
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`),
|
|
67
75
|
* but `HOME` on macOS on a login: the person's (login.ts personHome);
|
|
76
|
+
* - on a login, `USER` and `LOGNAME`: the user this process runs as
|
|
77
|
+
* (login.ts loginUser), the account of the login's Keychain item on macOS;
|
|
68
78
|
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
69
79
|
* resumes on any VM, whatever the cwd;
|
|
70
80
|
* - the model through the VM's model port, with the attach's key; the
|
package/dist/env.js
CHANGED
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
* about 50 `CLAUDE_*`, `ANTHROPIC_*` and `MCP_*` variables that change the
|
|
11
11
|
* CLI's behavior; none reaches the child unless it is listed here.
|
|
12
12
|
*/
|
|
13
|
-
import { loginEnv, personHome } from './login.js';
|
|
14
|
-
/** What never reaches a CLI that runs on a person's login: a model URL, key or token of
|
|
15
|
-
|
|
13
|
+
import { loginEnv, loginUser, personHome } from './login.js';
|
|
14
|
+
/** What never reaches a CLI that runs on a person's login from the app's own variables: a model URL, key or token of
|
|
15
|
+
* any kind, a refresh token or a token's file descriptor among them. A login handed as a token sets its own
|
|
16
|
+
* CLAUDE_CODE_OAUTH_TOKEN after. */
|
|
17
|
+
export const LOGIN_UNSET = Object.freeze(['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_API_KEY', 'CLAUDE_CODE_OAUTH_TOKEN', 'CLAUDE_CODE_OAUTH_REFRESH_TOKEN', 'CLAUDE_CODE_OAUTH_TOKEN_FILE_DESCRIPTOR', 'ANTHROPIC_CUSTOM_HEADERS', 'CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX']);
|
|
16
18
|
/** The `PATH` of the CLI and its commands in the VM: the image's, never the Function's. */
|
|
17
19
|
export const VM_PATH = '/usr/local/bin:/usr/bin:/bin';
|
|
18
20
|
/** Claude Code's default Bash timeout. */
|
|
@@ -23,6 +25,8 @@ export const PROJECT_DIR_NAME = 'session';
|
|
|
23
25
|
* - `HOME`, `CLAUDE_CONFIG_DIR`, `TMPDIR` and the XDG dirs in the session's
|
|
24
26
|
* cache dirs, which the relay wipes before every spawn (`/var/lib/dh/s`),
|
|
25
27
|
* but `HOME` on macOS on a login: the person's (login.ts personHome);
|
|
28
|
+
* - on a login, `USER` and `LOGNAME`: the user this process runs as
|
|
29
|
+
* (login.ts loginUser), the account of the login's Keychain item on macOS;
|
|
26
30
|
* - the projects key fixed (`CLAUDE_CODE_PROJECT_DIR_NAME`), so a transcript
|
|
27
31
|
* resumes on any VM, whatever the cwd;
|
|
28
32
|
* - the model through the VM's model port, with the attach's key; the
|
|
@@ -44,7 +48,9 @@ export function durableEnv(options) {
|
|
|
44
48
|
const { home, model } = options;
|
|
45
49
|
const small = options.smallModel ?? model;
|
|
46
50
|
const env = { ...(options.extra ?? {}) };
|
|
47
|
-
if (options.login)
|
|
51
|
+
if (options.login && options.oauthToken !== undefined)
|
|
52
|
+
throw new Error('agentrun-harness-claude: the CLI takes a login by its directories or by its token, not both');
|
|
53
|
+
if (options.login || options.oauthToken !== undefined) {
|
|
48
54
|
// On a login, no model URL, key or token reaches the CLI, the app's own variables included: its login is its only one.
|
|
49
55
|
for (const name of Object.keys(env))
|
|
50
56
|
if (LOGIN_UNSET.includes(name))
|
|
@@ -53,12 +59,19 @@ export function durableEnv(options) {
|
|
|
53
59
|
else if (options.baseUrl === undefined || options.token === undefined) {
|
|
54
60
|
throw new Error('agentrun-harness-claude: the CLI needs its model port and key, or a login');
|
|
55
61
|
}
|
|
62
|
+
// A login by its token: the token alone, its credentials directories the session's own (so no app variable points
|
|
63
|
+
// them at a login), and no wait for a newer token on a 401: the host is asked for one at once (getOAuthToken). It
|
|
64
|
+
// reads no keychain, so its HOME stays the session's on every platform.
|
|
65
|
+
const byToken = options.oauthToken === undefined ? undefined : { CLAUDE_CODE_OAUTH_TOKEN: options.oauthToken, CLAUDE_CODE_OAUTH_401_WAIT_MS: '0', CLAUDE_SECURESTORAGE_CONFIG_DIR: options.configDir, ANTHROPIC_CONFIG_DIR: `${home}/.config/anthropic` };
|
|
56
66
|
const platform = options.platform ?? process.platform;
|
|
57
67
|
Object.assign(env, {
|
|
58
68
|
PATH: VM_PATH,
|
|
59
69
|
// On macOS the CLI on a login reads its tokens from the login keychain, which is under the person's home: in the
|
|
60
70
|
// session's it finds none and reads signed out. Its config, XDG and temporary dirs stay the session's.
|
|
61
71
|
HOME: options.login && platform === 'darwin' ? personHome(options.login) : home,
|
|
72
|
+
// On a login, the user it is the login of: on macOS the CLI names the Keychain item's account by USER, and with
|
|
73
|
+
// none it reads the account "unknown", not the one the sign-in saved the tokens under (login.ts loginUser).
|
|
74
|
+
...(options.login ? loginUser() : {}),
|
|
62
75
|
TMPDIR: options.tmpDir,
|
|
63
76
|
CLAUDE_CONFIG_DIR: options.configDir,
|
|
64
77
|
CLAUDE_CODE_PROJECT_DIR_NAME: PROJECT_DIR_NAME,
|
|
@@ -66,7 +79,7 @@ export function durableEnv(options) {
|
|
|
66
79
|
XDG_CACHE_HOME: options.cacheDir,
|
|
67
80
|
XDG_DATA_HOME: `${home}/.local/share`,
|
|
68
81
|
XDG_STATE_HOME: `${home}/.local/state`,
|
|
69
|
-
...(options.login ? loginEnv(options.login, platform) : { ANTHROPIC_BASE_URL: options.baseUrl, ANTHROPIC_AUTH_TOKEN: options.token }),
|
|
82
|
+
...(byToken ?? (options.login ? loginEnv(options.login, platform) : { ANTHROPIC_BASE_URL: options.baseUrl, ANTHROPIC_AUTH_TOKEN: options.token })),
|
|
70
83
|
ANTHROPIC_DEFAULT_OPUS_MODEL: model,
|
|
71
84
|
ANTHROPIC_DEFAULT_SONNET_MODEL: model,
|
|
72
85
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: small,
|
package/dist/facts.d.ts
CHANGED
package/dist/facts.js
CHANGED
|
@@ -27,6 +27,8 @@ export const facts = Object.freeze({
|
|
|
27
27
|
webSearch: "native",
|
|
28
28
|
// Its model is Anthropic's, on its own settings, never the gateway's default for the other harnesses.
|
|
29
29
|
ownModel: true,
|
|
30
|
+
// Its proxy forwards with the fetch it is handed: a model the route translates onto its wire runs on it.
|
|
31
|
+
forwardsRoute: true,
|
|
30
32
|
// Anthropic's ids hold no dot; OpenRouter names the same models with dots (anthropic/claude-sonnet-5.5).
|
|
31
33
|
normalizeModel: (model) => (model.provider === "anthropic" ? { ...model, modelId: model.modelId.replaceAll(".", "-") } : model),
|
|
32
34
|
install: Object.freeze({ npmLine: CLAUDE_AGENT_SDK_INSTALL, spec: `@anthropic-ai/claude-agent-sdk@${CLAUDE_AGENT_SDK_VERSION}`, codes: Object.freeze({ install: "CLAUDE_AGENT_NOT_INSTALLED", pins: "CLAUDE_AGENT_PIN_MISMATCH" }) }),
|
|
@@ -41,3 +43,6 @@ export const facts = Object.freeze({
|
|
|
41
43
|
schemaProblems: (tool, schema) => [...toolSchemaProblems(tool, schema), ...["anyOf", "allOf", "oneOf"].filter((key) => key in schema).map((key) => `/${key}: the Claude Agent CLI drops a tool whose root has ${key}`)],
|
|
42
44
|
policy: (options) => anthropicPolicy({ model: options.model, tools: options.tools, ...(options.auth ? { auth: options.auth } : {}), ...(options.webSearch === true ? { webSearch: true, ...(options.webSearchAllowance ? { webSearchAllowance: options.webSearchAllowance } : {}) } : {}), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}) }),
|
|
43
45
|
});
|
|
46
|
+
// The pinned CLI's renewal of a login (login-refresh.ts), here too so a host that renews a login in the CLI's place
|
|
47
|
+
// reads it without loading the adapter and its SDK.
|
|
48
|
+
export { LOGIN_REFRESH as loginRefresh } from "./login-refresh.js";
|
package/dist/harness.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type GateAnswer, type GateCall } from '@parcha/agentrun-kernel';
|
|
2
2
|
import { type DriveContext, type Harness, type HostTool, type ReplayPolicy, type SessionState, type Submission } from './host/kernel.js';
|
|
3
3
|
import { type GatewayHandler, type ProviderTool, type SessionMachine } from './host/process.js';
|
|
4
|
-
import { type ClaudeAgentLogin } from './login.js';
|
|
4
|
+
import { type ClaudeAgentLogin, type ClaudeLoginToken } from './login.js';
|
|
5
5
|
import type { ModelPort } from '@parcha/agentrun-kernel';
|
|
6
6
|
import { toolServer } from './host/tool-server.js';
|
|
7
|
-
import { JournalSessionStore } from './store.js';
|
|
7
|
+
import { JournalSessionStore, type BarrierTimers } from './store.js';
|
|
8
8
|
/**
|
|
9
9
|
* Claude Code on harness-world: a kernel `Harness` that drives the Claude
|
|
10
10
|
* Agent SDK's `query()` in the drive (in the Function), with the `claude` CLI
|
|
@@ -200,10 +200,11 @@ export interface ClaudeCodeHarnessOptions {
|
|
|
200
200
|
/**
|
|
201
201
|
* The person's own login the CLI runs on (login.ts), in place of the model route: the drive asks its machine for no
|
|
202
202
|
* proxy, the CLI's environment holds no model URL, key or token, and each response is booked from the CLI's stream
|
|
203
|
-
* through `models`, billed to the plan. `credential` and `gatewayUrl` are not read.
|
|
203
|
+
* through `models`, billed to the plan. `credential` and `gatewayUrl` are not read. A login handed as a token
|
|
204
|
+
* (ClaudeLoginToken) is asked for its token at each drive, and again when the CLI asks for a newer one on a 401.
|
|
204
205
|
*/
|
|
205
206
|
login?: {
|
|
206
|
-
at: ClaudeAgentLogin;
|
|
207
|
+
at: ClaudeAgentLogin | ClaudeLoginToken;
|
|
207
208
|
models: Pick<ModelPort, 'beforeRequest' | 'afterRequest'>;
|
|
208
209
|
};
|
|
209
210
|
/** 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. */
|
|
@@ -212,8 +213,11 @@ export interface ClaudeCodeHarnessOptions {
|
|
|
212
213
|
name?: string;
|
|
213
214
|
/** The Agent SDK module. Default: `import('@anthropic-ai/claude-agent-sdk')` on the first drive, after its version is checked against the pin. */
|
|
214
215
|
sdk?: ClaudeAgentSdk;
|
|
215
|
-
/** How long a `never` tool waits for its call to reach the log before it is refused
|
|
216
|
+
/** How long a `never` tool waits for its call to reach the log before it is refused, from the last stream event of the
|
|
217
|
+
* message that made the call (the SDK mirrors a message's lines once it ends). Default 10 s. */
|
|
216
218
|
barrierMs?: number;
|
|
219
|
+
/** The timers that wait runs on. Default the system's; a test passes a fake clock. */
|
|
220
|
+
barrierTimers?: BarrierTimers;
|
|
217
221
|
/**
|
|
218
222
|
* Hold mirrored transcript lines this long so they share journal batches
|
|
219
223
|
* (fewer events per turn). A barrier or a turn's end sends them at once.
|
package/dist/harness.js
CHANGED
|
@@ -10,7 +10,7 @@ import { defersCatalog } from '@parcha/agentrun-kernel';
|
|
|
10
10
|
import { Restart, Unavailable } from './host/kernel.js';
|
|
11
11
|
import { askGate, BuiltinCalls, CLAUDE_ROUTES, gatewayCredential, gatewayHandler, gatewayUrl, isBrandedMachine, NativeJournal, openTurn, placeSubmissions, recoveryNote, restartEvent, replayBy, toolBridge, toolKey, waitForSubmissions, } from './host/process.js';
|
|
12
12
|
import { durableEnv, nativeModelId } from './env.js';
|
|
13
|
-
import { loginBooking, loginEnv } from './login.js';
|
|
13
|
+
import { LOGIN_TOKEN_REFUSED, loginBooking, loginByToken, loginEnv } from './login.js';
|
|
14
14
|
import { uuidFrom } from './ids.js';
|
|
15
15
|
import { MessageQueue } from './inbox.js';
|
|
16
16
|
import { sandboxSpawn } from './spawn.js';
|
|
@@ -234,7 +234,7 @@ export function claudeCodeHarness(options = {}) {
|
|
|
234
234
|
const { query } = await loadSdk();
|
|
235
235
|
const journal = new NativeJournal(ctx);
|
|
236
236
|
const records = await journal.read();
|
|
237
|
-
const store = new JournalSessionStore(journal, { records, coalesceMs: options.coalesceMs ?? 150 });
|
|
237
|
+
const store = new JournalSessionStore(journal, { records, coalesceMs: options.coalesceMs ?? 150, ...(options.barrierTimers ? { timers: options.barrierTimers } : {}) });
|
|
238
238
|
// The handler reads the credential per request, in the drive's async
|
|
239
239
|
// context: on a serverless function the OIDC token comes from the request
|
|
240
240
|
// that started the drive.
|
|
@@ -340,6 +340,8 @@ export function claudeCodeHarness(options = {}) {
|
|
|
340
340
|
try {
|
|
341
341
|
const result = await running;
|
|
342
342
|
const images = (result.images ?? []).map((image) => ({ type: 'image', data: image.data, mimeType: image.mimeType }));
|
|
343
|
+
// The tool's structured content is not passed on: the pinned CLI replaces an MCP answer's content with
|
|
344
|
+
// JSON.stringify(structuredContent), so sending both would hide the tool's text from the model.
|
|
343
345
|
return { content: [{ type: 'text', text: result.text }, ...images], ...(result.isError ? { isError: true } : {}) };
|
|
344
346
|
}
|
|
345
347
|
catch (err) {
|
|
@@ -497,13 +499,17 @@ export function claudeCodeHarness(options = {}) {
|
|
|
497
499
|
},
|
|
498
500
|
],
|
|
499
501
|
};
|
|
502
|
+
// A login handed as a token: its token as the host reads it now, for this start of the CLI (a token the host
|
|
503
|
+
// refuses, one near its end say, fails the drive in the host's words before the CLI starts).
|
|
504
|
+
const byToken = login && loginByToken(login.at) ? login.at : undefined;
|
|
505
|
+
let sentToken = byToken ? await byToken.token() : undefined;
|
|
500
506
|
// The CLI's environment in the VM (the SDK gets it with the Function's config dir; `sandboxSpawn` swaps the VM's back in).
|
|
501
507
|
const vmEnv = durableEnv({
|
|
502
508
|
home: machine.dirs.home,
|
|
503
509
|
configDir: machine.dirs.config,
|
|
504
510
|
tmpDir: machine.dirs.tmp,
|
|
505
511
|
cacheDir: machine.dirs.cache,
|
|
506
|
-
...(login ? { login: login.at } : { baseUrl: machine.modelUrl, token: machine.modelKey }),
|
|
512
|
+
...(sentToken !== undefined ? { oauthToken: sentToken } : login ? { login: login.at } : { baseUrl: machine.modelUrl, token: machine.modelKey }),
|
|
507
513
|
model,
|
|
508
514
|
...(smallModel ? { smallModel } : {}),
|
|
509
515
|
...(sandbox.commandTimeoutMs ? { bashTimeoutMs: sandbox.commandTimeoutMs } : {}),
|
|
@@ -541,10 +547,33 @@ export function claudeCodeHarness(options = {}) {
|
|
|
541
547
|
const recordedDay = !store.hasSession ? dayOf(now(), options.zone) : undefined;
|
|
542
548
|
/** A message the CLI's transcript holds told the model `day`. */
|
|
543
549
|
const told = (day) => ctx.state().effectOrder.some((e) => e.name === DATE_EFFECT && e.input?.day === day && store.hasUser(e.key.slice(DATE_EFFECT.length + 1)));
|
|
550
|
+
// On a login handed as a token, the CLI's ask for a newer one when Anthropic refuses it (the SDK's
|
|
551
|
+
// `getOAuthToken`, answering the CLI's `oauth_token_refresh`; the pins test holds that the pinned SDK takes it,
|
|
552
|
+
// as its typings do not say): the host told which token was refused (`refused`, so a host that renews renews
|
|
553
|
+
// it), then its token read once more, answered when it is another than the one the CLI holds. Else null, and
|
|
554
|
+
// the drive halts in words (the host's, or LOGIN_TOKEN_REFUSED), so the CLI fails the request at once
|
|
555
|
+
// (CLAUDE_CODE_OAUTH_401_WAIT_MS=0) and the turn ends: never a wait.
|
|
556
|
+
const askToken = byToken
|
|
557
|
+
? async () => {
|
|
558
|
+
try {
|
|
559
|
+
if (sentToken !== undefined)
|
|
560
|
+
await byToken.refused?.(sentToken);
|
|
561
|
+
const next = await byToken.token();
|
|
562
|
+
if (next !== sentToken)
|
|
563
|
+
return (sentToken = next);
|
|
564
|
+
ctx.halt?.(new Error(LOGIN_TOKEN_REFUSED));
|
|
565
|
+
}
|
|
566
|
+
catch (error) {
|
|
567
|
+
ctx.halt?.(error instanceof Error ? error : new Error(String(error)));
|
|
568
|
+
}
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
: undefined;
|
|
544
572
|
const queryOptions = {
|
|
545
573
|
model,
|
|
546
574
|
cwd: machine.root,
|
|
547
575
|
env: sdkEnv,
|
|
576
|
+
...(askToken ? { getOAuthToken: askToken } : {}),
|
|
548
577
|
// Built-ins on: the allowed ones (less those whose state the log does not carry), each let through by
|
|
549
578
|
// the PreToolUse hook once its intent is in the log. Off: the bridged tools are the only ones. Either
|
|
550
579
|
// way nothing is asked of a user, and nothing else is permitted.
|
|
@@ -553,7 +582,7 @@ export function claudeCodeHarness(options = {}) {
|
|
|
553
582
|
...(skills ? { plugins: [{ type: 'local', path: skills.plugin }], skills: [...skills.names] } : {}),
|
|
554
583
|
disallowedTools: disallowed,
|
|
555
584
|
hooks,
|
|
556
|
-
...(ownSandbox ? { sandbox: claudeSandboxSettings(machine, sandbox.network, login
|
|
585
|
+
...(ownSandbox ? { sandbox: claudeSandboxSettings(machine, sandbox.network, login && !byToken ? login.at : undefined) } : {}),
|
|
557
586
|
...(bridge.tools.length ? { mcpServers: { [MCP_SERVER]: server } } : {}),
|
|
558
587
|
allowedTools: bridge.tools.map((t) => `mcp__${MCP_SERVER}__${t.name}`),
|
|
559
588
|
permissionMode: 'dontAsk',
|
|
@@ -681,6 +710,9 @@ export function claudeCodeHarness(options = {}) {
|
|
|
681
710
|
ctx.halt?.(mirrorUnmapped('a batch the Agent SDK could not keep in the log'));
|
|
682
711
|
throw ctx.signal.reason ?? mirrorUnmapped('a batch the Agent SDK could not keep in the log');
|
|
683
712
|
}
|
|
713
|
+
// Each event of a message's stream restarts the barrier's clock for the calls made in it (the mirror sends a
|
|
714
|
+
// message's lines once the message ends).
|
|
715
|
+
store.heard(m);
|
|
684
716
|
booking?.observe(m);
|
|
685
717
|
const end = transcript.observe(m);
|
|
686
718
|
// A turn on a login ends once its responses are booked.
|
package/dist/host/policy.d.ts
CHANGED
|
@@ -52,9 +52,7 @@ export interface AnthropicPolicyOptions {
|
|
|
52
52
|
onThinkingDisabled?: (request: {
|
|
53
53
|
model: string;
|
|
54
54
|
}) => void;
|
|
55
|
-
/** The day of the run's clock (YYYY-MM-DD
|
|
56
|
-
* the CLI's own date lines, which it reads from the machine's clock, say this day instead (`CLI_DATE`). Absent, they
|
|
57
|
-
* pass as the CLI wrote them. */
|
|
55
|
+
/** The day of the run's clock (YYYY-MM-DD) when the host set one; the CLI's date lines say it (`CLI_DATE`). */
|
|
58
56
|
day?: () => string;
|
|
59
57
|
}
|
|
60
58
|
/** `now`'s day in `zone` (default UTC) as YYYY-MM-DD, the form the CLI's date line takes. */
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claude
|
|
|
7
7
|
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
8
8
|
export type { AnthropicPolicyOptions, AnthropicUsage } from "./host/policy.js";
|
|
9
9
|
export type { ChildCommand, ConfineChild } from "./host/machine.js";
|
|
10
|
-
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
11
|
-
export type { ClaudeAgentLogin, ClaudeLoginStatus } from "./login.js";
|
|
10
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
11
|
+
export type { ClaudeAgentLogin, ClaudeLoginStatus, ClaudeLoginToken } from "./login.js";
|
|
12
|
+
export { LOGIN_REFRESH as CLAUDE_LOGIN_REFRESH } from "./login-refresh.js";
|
|
12
13
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer, type ToolServerModules } from "./host/tool-server.js";
|
|
13
14
|
export type { ServedTool } from "./host/tool-server.js";
|
|
14
15
|
export { SIGN_IN_MS as CLAUDE_SIGN_IN_MS, signInEnv as claudeSignInEnv } from "./login.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { CLAUDE_AGENT_PACKAGE, ClaudeAgentNotInstalled, ClaudeAgentPinMismatch,
|
|
|
4
4
|
export { CLAUDE_AGENT_SDK_INSTALL, CLAUDE_AGENT_SDK_VERSION, CLAUDE_AGENT_BASE_INPUT_TOKENS, CLAUDE_CODE_VERSION as CLAUDE_AGENT_CLI_VERSION } from "./versions.js";
|
|
5
5
|
export { findClaudeExecutable as claudeAgentExecutable, platformSuffix as claudeAgentPlatform } from "./binary.js";
|
|
6
6
|
export { anthropicPolicy, CLAUDE_WEB_SEARCH_TOOL, OWN_TOOL_PREFIX, thinks, withWebSearches } from "./host/policy.js";
|
|
7
|
-
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
7
|
+
export { ClaudeLoginNoStatus, ClaudeLoginTimedOut, claudeLoginStatus, LOGIN_TOKEN_REFUSED as CLAUDE_LOGIN_TOKEN_REFUSED, loginByToken as claudeLoginByToken, sweepClaudeStatusFolders, loginCommand as claudeLoginCommand, loginEnv as claudeLoginEnv, parseLoginStatus as parseClaudeLoginStatus, startClaudeLogin } from "./login.js";
|
|
8
|
+
export { LOGIN_REFRESH as CLAUDE_LOGIN_REFRESH } from "./login-refresh.js";
|
|
8
9
|
export { listedTools, MCP_OUTPUT_TOKENS, RESULT_SIZE_KEY, toolServer } from "./host/tool-server.js";
|
|
9
10
|
export { SIGN_IN_MS as CLAUDE_SIGN_IN_MS, signInEnv as claudeSignInEnv } from "./login.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The pinned CLI's renewal of a login: where it posts, as which client, with which scopes when the login names none,
|
|
2
|
+
* and the lock it holds while it renews. */
|
|
3
|
+
export declare const LOGIN_REFRESH: Readonly<{
|
|
4
|
+
/** `TOKEN_URL:"https://platform.claude.com/v1/oauth/token"` in the CLI's production OAuth config (the one object that
|
|
5
|
+
* also holds its `CLIENT_ID`). */
|
|
6
|
+
tokenUrl: "https://platform.claude.com/v1/oauth/token";
|
|
7
|
+
/** `CLIENT_ID:"9d1c250a-e61b-44d9-88ed-5944d1962f5e"` in the same object: the CLI's public OAuth client, which it sends
|
|
8
|
+
* when the login names no `clientId` of its own (`client_id:s??cn().CLIENT_ID`). */
|
|
9
|
+
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
10
|
+
/** The scopes it asks for when the login holds none: its list
|
|
11
|
+
* `[user:profile, user:inference, "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"]`, and
|
|
12
|
+
* `user:plugins` (its production config's `PLUGINS_SCOPE_REGISTERED:!0`). */
|
|
13
|
+
scopes: readonly ["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload", "user:plugins"];
|
|
14
|
+
/** The lock's directory in the credentials directory: `lockfilePath:<join>(e,".oauth_refresh.lock")`. */
|
|
15
|
+
lockName: ".oauth_refresh.lock";
|
|
16
|
+
/** The older lock's suffix, on the credentials directory's real path: `` `${await <realpath>(e)}.lock` ``. */
|
|
17
|
+
legacyLockSuffix: ".lock";
|
|
18
|
+
/** A lock older than this is a dead holder's, taken over: `stale:60000`. */
|
|
19
|
+
lockStaleMs: 60000;
|
|
20
|
+
/** How often a holder touches its lock: `update:5000`. */
|
|
21
|
+
lockUpdateMs: 5000;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// How the pinned CLI renews a person's login, for a host that holds the login itself and renews it in the CLI's place
|
|
2
|
+
// (serve's runner, whose runs under a user of their own get the access token alone: login.ts ClaudeLoginToken).
|
|
3
|
+
// Written for AgentRun.
|
|
4
|
+
//
|
|
5
|
+
// Read from the pinned CLI's bundled code (2.1.286, from Agent SDK 0.3.286: versions.ts), with no run of it. Each value
|
|
6
|
+
// below is cited by the code it is in; test/pins.test.mjs reads the installed CLI and turns red when a repin moves any
|
|
7
|
+
// of them (the token URL, the client id, the request's body or header, the answer's fields, the write back, the lock).
|
|
8
|
+
//
|
|
9
|
+
// - The request: the CLI's refresh (`grant_type:"refresh_token"`) posts
|
|
10
|
+
// `{grant_type:"refresh_token",refresh_token:<the login's>,client_id:<the login's clientId>??CLIENT_ID,scope:<scopes>.join(" ")}`
|
|
11
|
+
// as JSON to `cn().TOKEN_URL`, with `{headers:{"Content-Type":"application/json"},timeout:30000}`. Its scopes are the
|
|
12
|
+
// login's own (`scopes:X.scopes`, what it sends when the login names its client, and its fallback), or the list below.
|
|
13
|
+
// - The answer: `{access_token, refresh_token = the one sent, expires_in}` (seconds), and `refresh_token_expires_in`
|
|
14
|
+
// and `scope` when given. Any status but 200 is a failure; `invalid_grant` marks the refresh token dead.
|
|
15
|
+
// - The write back: `{...file, claudeAiOauth: {accessToken, refreshToken, expiresAt: now + expires_in * 1000,
|
|
16
|
+
// refreshTokenExpiresAt: the answer's ?? the file's, scopes, subscriptionType, rateLimitTier, clientId}}`, only while
|
|
17
|
+
// the file still holds the refresh token it sent (or a cleared one), through its atomic writer at mode 0600
|
|
18
|
+
// (`await <write>(<path>,<json>,384),await <chmod>(<path>,384)`, 384 = 0o600).
|
|
19
|
+
// - The lock: before it reads the login to renew it, it takes a lock with proper-lockfile's options
|
|
20
|
+
// `{lockfilePath:<credentials dir>/.oauth_refresh.lock,realpath:!1,stale:60000,update:5000}` (a directory made with
|
|
21
|
+
// mkdir, its mtime touched every 5 s while held, taken over once 60 s old), then the older path
|
|
22
|
+
// `<realpath of the credentials dir>.lock` with the same options; it reads the login again under them, and takes a
|
|
23
|
+
// token another holder renewed meanwhile instead of renewing.
|
|
24
|
+
/** The pinned CLI's renewal of a login: where it posts, as which client, with which scopes when the login names none,
|
|
25
|
+
* and the lock it holds while it renews. */
|
|
26
|
+
export const LOGIN_REFRESH = Object.freeze({
|
|
27
|
+
/** `TOKEN_URL:"https://platform.claude.com/v1/oauth/token"` in the CLI's production OAuth config (the one object that
|
|
28
|
+
* also holds its `CLIENT_ID`). */
|
|
29
|
+
tokenUrl: "https://platform.claude.com/v1/oauth/token",
|
|
30
|
+
/** `CLIENT_ID:"9d1c250a-e61b-44d9-88ed-5944d1962f5e"` in the same object: the CLI's public OAuth client, which it sends
|
|
31
|
+
* when the login names no `clientId` of its own (`client_id:s??cn().CLIENT_ID`). */
|
|
32
|
+
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
33
|
+
/** The scopes it asks for when the login holds none: its list
|
|
34
|
+
* `[user:profile, user:inference, "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"]`, and
|
|
35
|
+
* `user:plugins` (its production config's `PLUGINS_SCOPE_REGISTERED:!0`). */
|
|
36
|
+
scopes: Object.freeze(["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload", "user:plugins"]),
|
|
37
|
+
/** The lock's directory in the credentials directory: `lockfilePath:<join>(e,".oauth_refresh.lock")`. */
|
|
38
|
+
lockName: ".oauth_refresh.lock",
|
|
39
|
+
/** The older lock's suffix, on the credentials directory's real path: `` `${await <realpath>(e)}.lock` ``. */
|
|
40
|
+
legacyLockSuffix: ".lock",
|
|
41
|
+
/** A lock older than this is a dead holder's, taken over: `stale:60000`. */
|
|
42
|
+
lockStaleMs: 60_000,
|
|
43
|
+
/** How often a holder touches its lock: `update:5000`. */
|
|
44
|
+
lockUpdateMs: 5_000,
|
|
45
|
+
});
|