@parcha/agentrun-serve 0.1.0-beta.62 → 0.1.0-beta.63

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 (128) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +32 -13
  3. package/dist/adapters.js +4 -2
  4. package/dist/agent-delete.d.ts +3 -3
  5. package/dist/agent-delete.js +50 -4
  6. package/dist/chatgpt-plan.d.ts +8 -1
  7. package/dist/chatgpt-plan.js +55 -6
  8. package/dist/console/assets/{backend-DEgVn5lC.js → backend-BxQ2G1M0.js} +2 -2
  9. package/dist/console/assets/{index-CG5tELph.js → index-C8Y5Zl8x.js} +2 -2
  10. package/dist/console/assets/share-CjBJ_rxP.js +6 -0
  11. package/dist/console/index.html +1 -1
  12. package/dist/console/share.html +1 -1
  13. package/dist/harness-opencode/adapter.d.ts +3 -1
  14. package/dist/harness-opencode/adapter.js +6 -2
  15. package/dist/harness-opencode/harness.d.ts +4 -0
  16. package/dist/harness-opencode/harness.js +6 -1
  17. package/dist/host-tools.d.ts +18 -3
  18. package/dist/host-tools.js +27 -4
  19. package/dist/learn/ledger.d.ts +37 -16
  20. package/dist/learn/ledger.js +56 -24
  21. package/dist/learn/promote.d.ts +4 -1
  22. package/dist/learning-cost.d.ts +5 -3
  23. package/dist/learning-model.js +7 -5
  24. package/dist/learning-work.d.ts +69 -0
  25. package/dist/learning-work.js +148 -0
  26. package/dist/openapi.js +23 -9
  27. package/dist/run-export.js +7 -4
  28. package/dist/run-launch.d.ts +6 -1
  29. package/dist/run-launch.js +10 -3
  30. package/dist/run-view.js +9 -3
  31. package/dist/runnable.js +5 -5
  32. package/dist/runner/adapter-loop.js +31 -3
  33. package/dist/runner/adapter-run-spec.d.ts +14 -3
  34. package/dist/runner/adapter-run-spec.js +50 -19
  35. package/dist/runner/adapters/index.d.ts +2 -0
  36. package/dist/runner/adapters/index.js +3 -0
  37. package/dist/runner/adapters/pi.d.ts +42 -3
  38. package/dist/runner/adapters/pi.js +114 -13
  39. package/dist/runner/audit.d.ts +8 -2
  40. package/dist/runner/audit.js +34 -18
  41. package/dist/runner/book-cut.d.ts +6 -0
  42. package/dist/runner/book-cut.js +38 -0
  43. package/dist/runner/claim-secrets.d.ts +9 -4
  44. package/dist/runner/claim-secrets.js +10 -5
  45. package/dist/runner/cli-run-spec.d.ts +0 -2
  46. package/dist/runner/cli-run-spec.js +44 -19
  47. package/dist/runner/held.d.ts +6 -3
  48. package/dist/runner/learned-first.d.ts +5 -0
  49. package/dist/runner/learned-first.js +1 -1
  50. package/dist/runner/learning-end.d.ts +15 -8
  51. package/dist/runner/learning-end.js +23 -7
  52. package/dist/runner/loop-contract.d.ts +4 -0
  53. package/dist/runner/main.js +2 -0
  54. package/dist/runner/model-route.d.ts +4 -0
  55. package/dist/runner/model-route.js +1 -1
  56. package/dist/runner/pr-checkout.d.ts +12 -0
  57. package/dist/runner/pr-checkout.js +21 -2
  58. package/dist/runner/promotion.d.ts +9 -2
  59. package/dist/runner/promotion.js +79 -28
  60. package/dist/runner/reflect-hook.d.ts +7 -0
  61. package/dist/runner/reflect-hook.js +2 -1
  62. package/dist/runner/run-child-host.js +21 -12
  63. package/dist/runner/run-child.js +1 -0
  64. package/dist/runner/runner.d.ts +9 -0
  65. package/dist/runner/runner.js +156 -25
  66. package/dist/runner/store-port.d.ts +4 -1
  67. package/dist/runner/workflow-first.js +4 -3
  68. package/dist/runner/workflow-loop.js +13 -1
  69. package/dist/secret-cut.d.ts +4 -0
  70. package/dist/secret-cut.js +1 -1
  71. package/dist/secret-rules.d.ts +2 -0
  72. package/dist/secret-rules.js +63 -19
  73. package/dist/server.js +20 -9
  74. package/dist/share-host.js +6 -3
  75. package/dist/store/schema.d.ts +4 -3
  76. package/dist/store/schema.js +4 -3
  77. package/dist/store/seal.d.ts +8 -2
  78. package/dist/store/seal.js +13 -2
  79. package/dist/store/sqlite/learning-rows.js +2 -1
  80. package/dist/store/sqlite/run-patch.js +4 -4
  81. package/dist/store/sqlite/store.js +28 -4
  82. package/dist/store/store.d.ts +5 -0
  83. package/dist/store-reads/journal.d.ts +2 -0
  84. package/dist/store-reads/journal.js +1 -1
  85. package/dist/store-reads/learning.d.ts +4 -3
  86. package/dist/store-reads/learning.js +62 -18
  87. package/dist/store-view.d.ts +3 -0
  88. package/dist/store-view.js +18 -1
  89. package/dist/tool-list.d.ts +4 -0
  90. package/dist/tool-list.js +4 -0
  91. package/dist/tools.js +2 -2
  92. package/dist/workspace/attach.js +22 -5
  93. package/dist/workspace/kind-skills/desktop/SKILL.md +7 -3
  94. package/package.json +12 -12
  95. package/templates/kyb/agent.md +7 -1
  96. package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
  97. package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
  98. package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
  99. package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
  100. package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
  101. package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
  102. package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
  103. package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
  104. package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
  105. package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
  106. package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
  107. package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
  108. package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
  109. package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
  110. package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
  111. package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
  112. package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
  113. package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
  114. package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
  115. package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
  116. package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
  117. package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
  118. package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
  119. package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
  120. package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
  121. package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
  122. package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
  123. package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
  124. package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
  125. package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
  126. package/templates/kyb/kyb.schema.json +2 -2
  127. package/templates/kyb/rules/SANCTIONS.md +82 -13
  128. package/dist/console/assets/share-CIeFK2Oe.js +0 -6
package/CHANGELOG.md CHANGED
@@ -2,6 +2,53 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.63 (2026-11-26)
6
+
7
+ - An agent on any CLI harness (claude-agent, codex, opencode, and Goose or Cursor where their owner installed them) now gets the browser, the same way it gets web_fetch. Before, granting `browser` to such an agent came back with "browser runs on pi here; on <harness> it is not bound yet", and a run of an agent whose computer is a browser was refused at its claim with "This agent's computer is a browser, which only the pi harness drives here". Now neither is refused on any of them. The harness is handed the browser's tools (`snapshot`, `run`, `screenshot` and the rest) as host tools. They drive the same session pi's would: the agent's browser computer, or else the vendor its tool plane picks. They use the same live view, the same spend held under the run's cap, and the same release when the run is let go. <!-- changes/browser-on-every-harness.md -->
8
+ - The person can take part as on pi: the agent's `browser_request_handoff` asks them and its call waits, with the run working, its row saying it waits for them in the browser, and its session held, until they hand the browser back; and the person can take the browser over in its live view unasked, while the agent's next browser call waits for them and is then told they had it. Either way the agent's later browser calls drive the same session, and none is made again.
9
+ - A browser call in flight when its runner dies is answered as interrupted ("may or may not have taken effect") when the run resumes on another runner, and is never sent to the browser again; the model goes on from that answer. The next claim takes back the session the run opened, and it is released once when the run ends. Each browser call's memo is its own, so nothing it kept carries into another call.
10
+ - Every browser answer the harness is handed (a page's snapshot text, the hand-over and take-over words) passes through the run's redactor first, as every other host tool's answer does: a secret the run holds that a page shows back reaches the CLI only as `[redacted]`.
11
+ - `subagent` still runs on pi only, and is refused in words on every other harness; `pdf_pages` and `llm` stay a workflow's node tools.
12
+ - `capabilities.tools` lists every harness under the browser's `harnesses`, not `pi` alone.
13
+ - The kyb template can screen a name against each sanctions list's own published file. With a shell it saves the file with `web_save` and greps every row, and its answer names the method `full_list_grep` with the list's version where the file or its URL gives one (`unknown` otherwise). Before it reports `no_hit` it has searched each identifier it holds, a short name such as `ADF Ltd` whole as a word, and, where a common name needs narrowing, whole UN records rather than lines, since the UN file keeps each part of a person's name on its own line. It reads a name with another in brackets, such as `ADF (Allied Democratic Forces)`, as both names, so a short name is not passed over as one word inside a longer name. It reads an EU entry's rows whole, the header line first, so a long remark no longer cuts off the name, birth date, documents or citizenship that come after it, and a `;` inside a quoted field shifts no column. Without a shell it screens through the list owners' indexes and records, as before. <!-- changes/kyb-list-files.md -->
14
+ - `agentrun share RUN --to URL` publishes an ended run to a share host and prints its link, `<URL>/r/<id>`. It exports the run again with `--restore`, checks the bundle against `--expect SHA` before anything is sent, and posts the bundle byte for byte to `POST <URL>/r/v2/shares`. A bundle whose sha256 changed since the preview page showed it is refused (exit 1), with words saying to open the page again. Before it sends anything, it prints that a share is public: anyone with the link can open it. The preview page's footer now shows the whole command, `agentrun share RUN --to <url> [--restore IDS] --expect SHA`, with `<url>` your share host's address, and how to sign in to it. The page names no default share host. <!-- changes/share-publish-cli.md -->
15
+ - `agentrun login --share URL < TOKEN_FILE` signs in to a share host: the token, read from stdin, is checked at `URL/r/v2/shares` and kept in a `share` entry of the same 0600 config file. The server's `base_url` and `api_key` stay as they were, so every other command still goes where it went, and a later `agentrun login` keeps the share entry. `agentrun logout --share` removes that entry alone; `agentrun logout` still removes the file.
16
+ - A share host's refusal is said in the CLI's own words, never its message or a value: a 422 prints its counts by rule (a rule the bundle's own records don't name counts as `unknown`), a 400 says the host does not take the bundle's format, a 413 gives its numbers, a full quota says to take a share down, and a refused token (exit 4) gives the login command. Publishing with no share login for that address refuses before the export, with the same command.
17
+ - `agentrun share delete URL` takes a share down with the same token (`DELETE <host>/r/v2/shares/<id>`); its page and bundle then answer 410. A share of another token's (exit 4), one the host does not have (exit 1) and one already deleted (exit 0) are each said plainly.
18
+ - `agentrun share RUN` with none of `--to`, `--dry-run` and `--out` still exits 2 and sends nothing; its words now name `--to`. `--to` with `--dry-run` or `--out` is refused.
19
+ - On a Linux desktop, `apps.list` leaves out, and `apps.launch` and `apps.terminate` refuse as `denied` naming the file and why, an app whose desktop file computerd's own user could change: on the way to it from `/`, every symbolic link followed, the user owns a folder, a link or the file (`~/.local/share/applications` among them), the mode bits let it write the file or a folder holding one of them, or computerd runs as root. The entry is read from the file that walk checked, opened without following a link and refused if another took its place. An app runs what its desktop file says, so before, an agent given `write` and the apps group, with bash denied and exec off, could write a desktop file there and `apps.launch` it, or shadow a system app's id, and run any command. Apps installed under the user's home, as on a paired machine's `~/.local/share/applications`, are no longer listed, and a computerd that runs as root lists none. <!-- changes/apps-launch-writable-desktop-files.md -->
20
+
21
+ The surface's `apps.open` (a script's `computer.apps.open`) refuses a `url` that starts with `-`, after leading whitespace too, as `invalid` before the call leaves it, in computerd's words, so a paired Linux machine on an older computerd doesn't hand it to the app as a flag. The computer README and `AppsLaunchParams.url`'s comment say what a `url` is on Linux. The words every offer of a computer's ops carries (`GUI_REACH`) and the desktop kind skill say that `apps.open` with a path reaches what a shell does for a file the agent wrote too, where `write` is granted.
22
+ - On a Linux desktop, `apps.launch` (a script's `computer.apps.open`) refuses a `url` that is neither an absolute URL with a scheme (`https://…`, `file:///…`) nor an absolute path, and starts nothing. Before, computerd put the `url` into the app's argv as it was: one starting with `-`, after leading whitespace too, reached the app as a flag (Chromium's `--renderer-cmd-prefix` runs a command, on a computer whose exec is off), and a relative path reached it as a file. A `url` starting with `-` is refused `invalid` in words of its own: `starts with "-": the app would take it as a flag, not a url`. The macOS and Android daemons already took only a URL with a scheme, handed to the OS rather than to an argv. <!-- changes/apps-open-url-guard.md -->
23
+
24
+ The words every offer of a computer's ops carries (`GUI_REACH`) now say that `apps.open` with a URL or a path, not only a `file://` URL, reaches what the shell and the file ops do. serve's README and the desktop kind skill no longer say that every op the gate refuses whatever its arguments is left out of `computer_op`'s list: only the ops held to a tool (the file ops, `shell.run`, `processes.start`) are; apps and raw input stay.
25
+ - A server's start lists the ChatGPT plan's models only with an access token OpenAI takes. The start never renews the token itself, so a stop right after it can't spend the refresh token and lose the sign-in. Until a run renews the token, the fallback list stays. Once one has, the server's next read of the sign-in (`GET /capabilities`, which the console reads, or the ChatGPT sign-in page) lists the models while that token is fresh, with no restart. A server's stop now also waits, within its 2 s, for the change its start's model list tells it. A renewal that loses its write-back to a new sign-in, and whose new pair OpenAI doesn't confirm revoked, now carries that pair in the saved row. If another process is renewing that row, it waits for that renewal first. The server's next start revokes the pair. <!-- changes/plan-settle-followups.md -->
26
+ - The scrubber now cuts a read of `.env` files named by a glob or a brace, such as `cat .env*`, `head .env.*` or `cat .env.{local,production}`. Before, these printed every file uncut. The dotfile exemption covers only a plain path, so these commands keep their `env` token and their output is an `env-dump` cut. <!-- changes/scrubber-env-globs.md -->
27
+
28
+ The env-dump reader now also catches:
29
+ - `process` with `.env` on the next line;
30
+ - the `Environment` property (`systemctl show -p Environment`) and `/etc/environment`;
31
+ - `heroku config` and its subcommands;
32
+ - `ps` with an uppercase `E` (`ps auxE`, `ps -E`).
33
+
34
+ A transcript's cut now also starts and ends at a full PS1 prompt: `user@host:~$`, `root@c:/#`, `[user@host dir]$`, with or without a `(venv) ` prefix.
35
+
36
+ A shared run's title now has one more env-dump cut. The title is the first message on one line, so `$ printenv` and its `NAME=value` output sat on the same line there and were shared uncut. The export now reads the title as a flattened transcript: after a prompt, when a command that prints the environment is followed by a `NAME=value` word, everything from that word to the next prompt is cut. This covers only that shape. Output that doesn't start with `NAME=` (`printenv NAME`, `echo $NAME`, `cat .env`, `docker inspect`, `heroku config`) is still carried in the title, though the row that holds the same message is cut. Only the title is read this way; a row or file keeps reading `$ env NAME=value command` as a command. A share host reads an uploaded bundle's title the same way.
37
+
38
+ A `.env` name in another case (`cat .ENV`, `cat .Env.local`) is now an env-dump. env-file matches only lower-case names, and the exemption used to drop these names anyway.
39
+ - A raise that reaches an agentic run's claim while that claim is parking the run again at its cap (a refused raise woke it, and the park is slow, as one that keeps a computer is) now waits for the run's next claim, which resumes the run. Before, the parking claim took the raise and the run was left parked with nothing to wake it. <!-- changes/serve-raise-during-repark.md -->
40
+ - A capped workflow run parked at its cap that a claim wakes with no raise that resumes it (a raise the cap's rule refuses, from a race of two raises or a retry) now parks again on the pause it stood at, with nothing written, before any step runs. Before, each such claim ran the held step into the same cap and wrote a new `agentrun.budget` entry. A refused raise's row is left untaken and wakes the run on every poll, so the entries grew without bound. <!-- changes/serve-refused-raise-claim-loop.md -->
41
+ - A capped workflow run writes one budget entry per cap in two more cases. A retry of the raise that resumed the run, reaching it once it parked again at the raised cap, is taken and leaves the new pause standing: its raise entry names the pause the raise answered, as an agentic run's does, not the one the run stands at since. A claim of a run paused at its cap whose row reads running (a woken claim lost before its release) parks the run again on its pause, as a claim of the parked run does. Before, each ran the held step into the same cap and wrote another `agentrun.budget` entry. A run's view shows the pause it stands at after such a retry: a raise entry clears only the pause it names. <!-- changes/serve-workflow-raise-retry-lost-claim.md -->
42
+ - A tool result is held to the model's context window, not only to the fixed 120,000-character bound: a model with a small window (an Ollama model at 65,536 tokens, a 16k one) is never handed a result that fills its context. <!-- changes/tool-result-window-bound.md -->
43
+ - `boundResult(text, budget?)` takes the model's window (`{ contextWindow, baseInputTokens? }`): a result may take at most a quarter of what the window leaves (`RESULT_WINDOW_SHARE`), at three characters a token (`RESULT_CHARS_PER_TOKEN`), and never more than `HOST_RESULT_MAX_CHARS`. Past that it is cut with a note saying it was cut to fit the window and how to read on; a window too small for any cut refuses the result in words, and a result of at most 400 characters (`RESULT_ALWAYS_WHOLE_CHARS`) always stands whole, so bounding a bound changes nothing. With no window the bound is exactly as before. `resultMaxChars(budget)` gives the bound, and `boundTo(text, max)` cuts to a given bound, saying how (`ResultBound`: the characters kept, the whole length, the bound).
44
+ - `SessionSpec.contextWindow` carries the session model's window, and each harness adapter (Claude, Codex, ACP, OpenCode) takes a `contextWindow` option for when the host passes none; Codex and OpenCode are told that window in place of their 272,000 guess. A Codex script cut off by a crash is answered within the same bound (`recoveryMaxChars`), not `EXEC_RECOVERY_MAX_CHARS`.
45
+ - agentrun-serve puts the run's model window from its catalog on every session, and pi now holds every tool result to it too: a host tool's and a pi-native one's (web_fetch, web_search, the browser's), which before reached the model up to pi's own output limits. What a host tool streams while it runs is held to the bound too (`boundedProgress`), since pi writes a call cut off past its restart limit from that text, without its hooks.
46
+ - A turn's results together fit what the window has left (`TurnBudget`, `ResultBudget.turn`): from what the context already holds (the last request's input tokens and its answer's output, else the session's system prompt and tool schemas counted with o200k), less the room kept for the model's answer (`answerReserve`: a quarter of the window, at most `ANSWER_RESERVE_MAX_TOKENS`, 16,384 tokens), each call the model made takes the smaller of its own bound and what is left over the calls still unanswered, so parallel calls split it, and below the least a cut keeps a result is refused in words. The kernel owns the rule; the session's model proxy reports each answer's facts (`ModelProxyOptions.turn`, its calls counted from the stream by `toolCallsIn`) for Claude, Codex, OpenCode and Goose, and pi and Claude Code on a person's login report them from their own hooks (pi's afterResponse, the login's stream booking). `windowBudget(window, system?)` builds the budget with its turn. A call whose result goes to the harness's own tool rather than the model (`ToolBridgeOptions.outsideTurn`: Codex's code-mode script calls) takes the per-result bound alone, outside the turn's split.
47
+ - The bridge records each cut it hands a harness (`bound:<callId>`, `boundKey`), and a replay of the call is cut by that record. Codex compares a nested call's two records on those lengths, never on the note's words; `boundOf` is gone. A session written before the record still agrees where Codex got the host's bound's cut, as before.
48
+ - On Claude, Codex, ACP and OpenCode, a turn's budget outlasts a process that stops in the turn (a park, a crash): each answer's facts and each result's length as it was handed go to the session's journal as they happen (`journalTurn`, `TURN_STREAM`), and a budget that has read no answer yet takes them back before any call claims (`TurnBudget.restore`). The calls a resume answers split what their answer left, and a result handed before the stop keeps its part. Codex's recovered script outputs claim their room in the turn too and are held to that claim (`ResultBudget.maxChars`). pi's turn budget is not journaled yet: a pi session opened again starts a fresh one, and each result there keeps its per-result bound.
49
+ - A run with `checkout: pull_request` or `checkout: repository` on a Mode 2 server whose Archil region has no serverless exec (gcp-us-central1) now gets its checkout: the server's git fetch runs in the run's sandbox computer once it has mounted the run's folder, the same script with the GitHub App's token on the process's stdin, never on its argv or in its environment. Before, the fetch went to Archil's exec, which that region refuses, and the run was told its checkout failed with "Exec is not enabled". A run there with no computer that mounts its folder is told up front that it has no checkout and why, and its timeline names a sandbox computer as the fix. A template whose computer list asks for a shell first (code-review, agent-scout) is applied there with the first sandbox whose keys are set and that mounts the run's folder (E2B, Modal or Agent37 on Archil), so its runs have a shell and their checkout. A computer's exec now takes stdin (process.write). Regions with exec and Mode 1 are unchanged. <!-- changes/archil-no-exec-checkout.md -->
50
+ - A CLI run's end-of-run turn (its learning step) now reads the turn's last message as its answer, as a pi run's always has. Before, it ran every message of the turn together, so a claude-agent turn whose stream stalled and was asked again whole stored the stalled part and the whole answer as one. The Claude adapter takes the stream idle limit from its host (`streamIdleMs`, `LOCAL_STREAM_IDLE_MS`) rather than from a route's `fetch`, and serve sets it only for a model on its own machine. <!-- changes/cli-end-of-run-answer.md -->
51
+
5
52
  ## 0.1.0-beta.62 (2026-11-26)
6
53
 
7
54
  **Breaking:**
package/README.md CHANGED
@@ -1029,15 +1029,17 @@ command (`shell.run`) is held to the agent's `bash` setting, a started process t
1029
1029
  its tool among the agent's tools first, as the run's own file tools do: `files.write` needs `write`, and `files.read`,
1030
1030
  `files.list` and `files.stat` need `read`. An agent not given one is refused the op whatever its setting says, on every
1031
1031
  desktop, mounted or not. Naming a desktop does not grant its file ops. The shell's ops (`shell.run`, `processes.start`)
1032
- follow `bash`'s setting alone, not a grant. An op the gate refuses whatever its arguments is not offered:
1033
- `computer_op`'s op list and the script's `computer` declarations leave out an op whose tool the agent is not given, one
1034
- held to a tool set to deny, one held to a tool set to ask on a server where no one can approve, and one `bash`'s policy
1035
- refuses whatever its command (`processes.start` under the read-only policy). Leaving `read` out
1032
+ follow `bash`'s setting alone, not a grant. `computer_op`'s op list and the script's `computer` declarations leave out
1033
+ an op held to a tool (the file ops to `read` and `write`, `shell.run` to `bash`, `processes.start` to
1034
+ `bash_background`) that the gate refuses whatever its arguments: its tool not given, set to deny, or set to ask on a
1035
+ server where no one can approve, or `bash`'s policy refusing it whatever its command (`processes.start` under the
1036
+ read-only policy). Apps and raw input are held to no tool, so they stay in the list. Leaving `read` out
1036
1037
  keeps no file from an agent that has the shell, paired machines included: on a desktop with exec on,
1037
1038
  `computer.shell.run` reads and writes any file the desktop's user can, held to `bash`'s setting alone, which allows by
1038
1039
  default. To keep files from such an agent, set `bash` to deny or turn the desktop's exec off. Input ops on a desktop
1039
- with a terminal app or a GUI file manager, and `apps.open` with a `file://` URL, can do what a shell or the file ops
1040
- do, whatever `bash`'s, `read`'s or `write`'s setting: to deny that, don't grant input ops or apps on that desktop, or
1040
+ with a terminal app or a GUI file manager, and `apps.open` with a URL or a path, including a file the agent wrote
1041
+ where `write` is granted, can do what a shell or the file ops do, whatever `bash`'s, `read`'s or `write`'s setting:
1042
+ to deny that, don't grant input ops or apps on that desktop, or
1041
1043
  use an image with neither a terminal nor a file manager. A script's call of a computer tool answers the
1042
1044
  tool's value. Codex's code mode takes no binding of ours, so a Codex run is offered
1043
1045
  `computer_op` beside the computer's tools and its scripts call them as nested calls, each answering the tool's value as
@@ -1574,7 +1576,7 @@ curl -s http://127.0.0.1:7340/v2/agents/support/runs -H "Authorization: Bearer $
1574
1576
  curl -s http://127.0.0.1:7340/v2/runs/$RUN_ID/messages -H "Authorization: Bearer $AGENTRUN_TOKEN" \
1575
1577
  -H 'content-type: application/json' -d "{\"content\": \"And the refund?\", \"model_key\": \"$NEXT_KEY\"}"
1576
1578
 
1577
- # When the run's turn has ended (run.ended), revoke it.
1579
+ # When the run is terminal and GET /v2/runs/$RUN_ID reads learning_work.state other than "running", revoke it.
1578
1580
  curl -s https://litellm.example.com/key/delete -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
1579
1581
  -H 'content-type: application/json' -d "{\"keys\": [\"$KEY\"]}"
1580
1582
  ```
@@ -1594,15 +1596,32 @@ Custody, as for a per_run MCP server's `mcp_auth`:
1594
1596
  keeps failing, the message waits untaken and is delivered again, never run on the key held before it or the
1595
1597
  server's. A stop or cancel sent after it still reaches the run. A message without one keeps the key the run holds.
1596
1598
 
1597
- **The revoke-at-turn-end contract.** The write that ends a run's turn erases its key from the store, and the run
1598
- reports the turn ended (`run.ended`, the run's `completed`, `failed` or `stopped` status) only after that write. Every model request
1599
- tied to the turn finishes before then: the job, its subagents, its learned workflows' nodes, its end-of-run compile
1600
- turn. So a caller may revoke the key as soon as it sees the turn end, and no request of that run will
1601
- answer 401 for it. Model spend that would run after the turn ends is never sent on the run's key or the server's:
1599
+ **The revoke contract: `learning_work`.** The write that ends a run's turn erases its key from the store. Every model
1600
+ request tied to the turn finishes before then: the job, its subagents, its learned workflows' nodes, its end-of-run
1601
+ compile turn. A run that learns also starts learning work on its key at its end: a learned workflow's check (replay
1602
+ runs) and its audit (a shadow run). Each of those runs takes a copy of the key sealed for it alone, and the write that
1603
+ ends that run (or its purge) erases the copy. They are capped at their share of what the run's cap leaves at its end;
1604
+ with too little left they are dropped and spend nothing. GET `/v2/runs/{run_id}` says where that work stands in
1605
+ `learning_work`:
1606
+
1607
+ - `state`: `none` (the run started none), `running` (its compile turn, or a run in `runs`, is still going) or `ended`
1608
+ (all of it finished or dropped, at `ended_at`). It only moves forward once the run is terminal; a lost or cancelled
1609
+ child counts as ended.
1610
+ - Revoke the key once the run is terminal and `learning_work.state` is not `running`. No request of the run or its
1611
+ children answers 401 for it then.
1612
+ - `deadline_at`, while `running`: the latest instant that work may still spend on the key. It is the later of the
1613
+ compile turn's start plus its 10 minute timeout and each child's start plus 30 minutes, and it only moves later. The
1614
+ server cancels a child still at work at its 30 minutes, as a person's cancel is, and it then counts as ended. Set
1615
+ the key's expiry no earlier than `deadline_at` as a backstop for a missed read; `state` stays the signal to revoke on.
1616
+ - A purge of the run (`DELETE /v2/runs/{run_id}`) while its check's replays still run cancels them and erases their
1617
+ copies first, and answers only once they have ended: after a 204 nothing spends on the key. A live shadow audit
1618
+ refuses the purge (409 `run_not_final`), as any run made from it does.
1619
+ - What those runs spend is the run's own learning: its `cost.learning_usd`, with the replays as `cost.check_usd` and
1620
+ the shadow as `cost.shadow_usd`, never a workflow revision's spend.
1602
1621
 
1603
1622
  | Spend | With the run's key | Server holds no key, run brought none |
1604
1623
  | --- | --- | --- |
1605
- | A shadow audit, a learned workflow's replay check | Skipped, logged | Skipped, logged |
1624
+ | A shadow audit, a learned workflow's replay check | On a sealed copy of the run's key, at its end, within its cap's room (listed in `learning_work`) | Skipped, logged |
1606
1625
  | A grade's feedback round (`PUT /runs/{id}/grade`) | A new turn with no key: the server's, else not opened | Not opened; the grade is kept |
1607
1626
  | An owner's replay, an SDK run's compile turn | Tied to no run's key | 409 or skipped, in words |
1608
1627
  | A trigger's firing | Starts a run with no key | 422 `model_key_required` for the firing |
package/dist/adapters.js CHANGED
@@ -14,6 +14,7 @@ import { CLAUDE_SDK, codexBinaryIn, HarnessNotInstalled, installDirOf, installLi
14
14
  import { commandData } from "./harness-owned.js";
15
15
  import { DATA_ENV, defaultData } from "./files.js";
16
16
  import { harnessOf, onAdapter } from "./harness-table.js";
17
+ import { OLLAMA_PROVIDER } from "./ollama-provider.js";
17
18
  import { HarnessUnavailable, heldRefusedProvider, providerFor } from "./provider.js";
18
19
  import { keyShaped } from "./secret-cut.js";
19
20
  import { servedSkills } from "./learn/workflow-draft.js";
@@ -412,8 +413,9 @@ export async function claudeOf(env, needs, load = loadClaude, sdkOf = (version,
412
413
  // whoever bills it (its priceModel).
413
414
  const endpoint = provider ? { origin: provider.origin, credential: provider.credential, auth: provider.auth, ...(provider.headers ? { headers: provider.headers } : {}) } : { origin: "", credential: () => "" };
414
415
  // A model the route translates onto the wire (an Ollama model): its proxy forwards with the route's own fetch, and the
415
- // provider's own web search (nativeOptions), which the translation cannot run, is not offered.
416
- const forward = provider?.fetch ? { fetch: provider.fetch } : {};
416
+ // provider's own web search (nativeOptions), which the translation cannot run, is not offered. One on this machine says
417
+ // nothing while it loads, reads its prompt or thinks, so the CLI waits it out (the runner's route.local reads the same).
418
+ const forward = provider?.fetch ? { fetch: provider.fetch, ...(provider.priceModel.provider === OLLAMA_PROVIDER ? { streamIdleMs: claude.LOCAL_STREAM_IDLE_MS } : {}) } : {};
417
419
  const priced = provider ? { ...needs, model: provider.priceModel } : native;
418
420
  // Its CLI checked off the event loop first (hashed and run as a child), so the server goes on answering: a pass is
419
421
  // kept, and the adapter's own check answers from it. A CLI that fails its pins is the adapter's to report, in its
@@ -71,9 +71,9 @@ export declare function purgeAgent(host: AgentDeleteHost, agentId: string): Prom
71
71
  /** The setting that marks agent `agentId`'s purge begun and not finished (purgeAgent). */
72
72
  export declare const purgingKey: (agentId: string) => string;
73
73
  /** Purges run `runId` with every run made from it, as the header says. 404 not_found when it is not there; 409
74
- * run_not_final, nothing purged, while it or a run made from it is live. A purged run's only work is forgetCopies again,
75
- * which finds nothing left once a purge finished it; its store scrub was marked before the purge changed a row
76
- * (sqlite/store.ts #purging). */
74
+ * run_not_final, nothing purged, while it or a run made from it is live. Its learning work still going is ended first
75
+ * (endLearningWork). A purged run's only work is forgetCopies again, which finds nothing left once a purge finished it;
76
+ * its store scrub was marked before the purge changed a row (sqlite/store.ts #purging). */
77
77
  export declare function purgeRun(host: AgentDeleteHost, runId: string): Promise<void>;
78
78
  /** One delete of an agent at a time: a second DELETE of the same agent waits for the first, then finds it gone (404) or
79
79
  * finishes what the first left. `queued`, a test's seam: told each time a work waits behind another of its agent's,
@@ -18,7 +18,9 @@
18
18
  // agent kept and refusing runs. A trigger that reached it anyway keeps its row (store TriggersLeft): the same 503.
19
19
  import { ApiError } from "./errors.js";
20
20
  import { LearningInFlight } from "./learn/delete.js";
21
- import { FINAL_STATES, RunsMadeFromLeft, StoreConstraint, TriggersLeft } from "./store/index.js";
21
+ import { learningChildrenOf } from "./learning-work.js";
22
+ import { sendCommand } from "./runner/commands.js";
23
+ import { FINAL_STATES, RunFinal, RunsMadeFromLeft, StoreConstraint, TriggersLeft } from "./store/index.js";
22
24
  import { forgetServed } from "./store-view.js";
23
25
  import { requireSourceIOIdle } from "./source-sync/io.js";
24
26
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -95,12 +97,55 @@ export async function purgeAgent(host, agentId) {
95
97
  // Its tombstone refuses every write from here (410 purged).
96
98
  await host.store.settings.remove(purgingKey(agentId));
97
99
  }
100
+ /** Run `runId`'s learning work still going, ended before anything of the run is purged: the replay runs of its learned
101
+ * workflow's check (learning-work.ts names them), which are made from the runs whose input they replay, never from it,
102
+ * so neither its live check nor the store's purge waits for them. Its caller reads the run's `learning_work` to know
103
+ * when the run's own model key may be revoked, and a purged run reads nothing: so each one still going has its sealed
104
+ * launch secrets (its copy of the run's key, its handed MCP credentials) erased in the same store write as its cancel
105
+ * (runs.command's launchSealed), no claim of it from here opening a key, and is waited for until it is final and let go,
106
+ * its spend booked. Each child is named in the run's record before it is created, under the run's own claim
107
+ * (runner/promotion.ts startReplay, runner/audit.ts startAudit; a keyed one is never relaunched), and this runs only once
108
+ * that claim let the run go (liveOf): none starts after it. Its audit's shadow is made from it, so a live one refused
109
+ * the purge above (409) and none is here. One not ended by the wait's end refuses the purge with 409 run_not_final,
110
+ * nothing of the run purged; its cancel stands, and the next DELETE finds it ended. */
111
+ async function endLearningWork(host, runId) {
112
+ const going = async () => {
113
+ const out = [];
114
+ for (const child of await learningChildrenOf(host.store.settings, runId)) {
115
+ if (child.run === null || out.includes(child.run))
116
+ continue;
117
+ const row = await host.store.runs.get(child.run);
118
+ if (row && row.purgedAt === null && isLive(row))
119
+ out.push(child.run);
120
+ }
121
+ return out;
122
+ };
123
+ let live = await going();
124
+ if (!live.length)
125
+ return;
126
+ for (const id of live) {
127
+ try {
128
+ await sendCommand(host.store, id, { kind: "cancel", body: {} }, { launchSealed: () => null });
129
+ }
130
+ catch (error) {
131
+ // Final already: the write that ended it erased its secrets with it.
132
+ if (!(error instanceof RunFinal))
133
+ throw error;
134
+ }
135
+ }
136
+ const deadline = Date.now() + host.waitMs;
137
+ while ((live = await going()).length && Date.now() < deadline)
138
+ await sleep(host.pollMs);
139
+ if (live.length) {
140
+ throw liveRuns(`The run ${runId}'s learning work was cancelled and has not ended yet (${live.join(", ")}): send the DELETE again once ${live.length === 1 ? "it has" : "they have"} ended. Nothing was purged.`, live);
141
+ }
142
+ }
98
143
  /** The setting that marks agent `agentId`'s purge begun and not finished (purgeAgent). */
99
144
  export const purgingKey = (agentId) => `agent.purging.${agentId}`;
100
145
  /** Purges run `runId` with every run made from it, as the header says. 404 not_found when it is not there; 409
101
- * run_not_final, nothing purged, while it or a run made from it is live. A purged run's only work is forgetCopies again,
102
- * which finds nothing left once a purge finished it; its store scrub was marked before the purge changed a row
103
- * (sqlite/store.ts #purging). */
146
+ * run_not_final, nothing purged, while it or a run made from it is live. Its learning work still going is ended first
147
+ * (endLearningWork). A purged run's only work is forgetCopies again, which finds nothing left once a purge finished it;
148
+ * its store scrub was marked before the purge changed a row (sqlite/store.ts #purging). */
104
149
  export async function purgeRun(host, runId) {
105
150
  const run = await host.store.runs.get(runId);
106
151
  if (!run)
@@ -111,6 +156,7 @@ export async function purgeRun(host, runId) {
111
156
  const live = await liveOf(host, [run, ...made]);
112
157
  if (live.length)
113
158
  throw notFinal(runId, live);
159
+ await endLearningWork(host, runId);
114
160
  for (const one of made)
115
161
  await purgeOneOrRefuse(host, one.agentId, one.id, runId, true);
116
162
  await host.at?.("run_made_from_gone", runId);
@@ -115,7 +115,8 @@ export declare class ChatGPTPlan implements PlanReader {
115
115
  /** Reads the sealed row into the state a reader sees. Returns this. A read never settles (settleLeft). */
116
116
  load(): Promise<this>;
117
117
  /** What a stop left in the row (a sign-in it cut off after its save: keep) settled, out of the caller's way: the
118
- * server's, once, at its start, once its first offers are made. Models it lists are told to the server (its change
118
+ * server's, at its start once its first offers are made, and at a read of a row a reader renewed while it was still
119
+ * unlisted (refresh). Models it lists are told to the server (its change
119
120
  * callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
120
121
  * (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
121
122
  * OpenAI's revocation endpoint. */
@@ -183,6 +184,12 @@ export declare class ChatGPTPlan implements PlanReader {
183
184
  /** The renewal itself, under this holder's lease on `row` (sealed as `bytes`). Every write back is a compare-and-set
184
185
  * against the leased row, so a sign-out or a new sign-in meanwhile is never overwritten: ours is dropped. */
185
186
  private renewUnder;
187
+ /** A pair this holder got and could not save (a renewal whose write back lost: renewUnder), whose revocation OpenAI
188
+ * didn't confirm: carried in the row (`retired`), for the server's next settle to revoke, as a replaced sign-in's pair
189
+ * is (keep). Never written over another holder's live lease (its write back would lose in turn): it waits for that
190
+ * write back, or for the lease to lapse, as a renewal waits on one (renew), and gives up only past that bound, said in
191
+ * the log. None with no row (a sign-out says OpenAI's word is not the whole answer while a renewal is out). */
192
+ private carry;
186
193
  /** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
187
194
  * is dropped, and the row's state wins. */
188
195
  private adopt;
@@ -208,8 +208,14 @@ export class ChatGPTPlan {
208
208
  #refreshing;
209
209
  /** The last settle queued (settle): each waits for the one before it. */
210
210
  #settling;
211
- /** The ends of the sign-ins cancelled and not yet ended (close waits for them). */
211
+ /** The ends of the sign-ins cancelled and not yet ended, and the start's settle with the change it tells (settleLeft):
212
+ * close waits for them. */
212
213
  #ending = new Set();
214
+ /** Set by close(): no read queues a settle after it, so none outlives the server's stop. */
215
+ #closed = false;
216
+ /** When a read last queued a settle (refresh): a list OpenAI keeps failing is asked again at most once a minute,
217
+ * however often the console reads. */
218
+ #readSettledAt = -Infinity;
213
219
  #watchers = new Set();
214
220
  #deps;
215
221
  constructor(deps) {
@@ -309,12 +315,16 @@ export class ChatGPTPlan {
309
315
  return this;
310
316
  }
311
317
  /** What a stop left in the row (a sign-in it cut off after its save: keep) settled, out of the caller's way: the
312
- * server's, once, at its start, once its first offers are made. Models it lists are told to the server (its change
318
+ * server's, at its start once its first offers are made, and at a read of a row a reader renewed while it was still
319
+ * unlisted (refresh). Models it lists are told to the server (its change
313
320
  * callback, as a sign-in's are), so the offers made from the fallback list are made again. A runner's reader
314
321
  * (planReaderOf, at each claim) never calls it, so no runner lists the plan's models or sends a refresh token to
315
322
  * OpenAI's revocation endpoint. */
316
323
  settleLeft() {
317
- void this.settle().then(({ listed }) => (listed ? this.tellChanged() : undefined));
324
+ // Its change callback is waited for by close(), as the settle is: the server never closes under a change it owes.
325
+ const told = this.settle().then(({ listed }) => (listed ? this.tellChanged() : undefined));
326
+ this.#ending.add(told);
327
+ void told.then(() => this.#ending.delete(told));
318
328
  }
319
329
  view() {
320
330
  if (this.#pending && this.#pending.expiresAt <= this.now())
@@ -528,7 +538,10 @@ export class ChatGPTPlan {
528
538
  if (!read || (!read.row.unlisted && !read.row.retired?.length))
529
539
  return {};
530
540
  const signedIn = read.row.credential.refresh;
531
- const models = read.row.unlisted && read.row.state === "signed_in" ? await this.listModels(read.row.credential.access) : undefined;
541
+ // The list is asked only with a token OpenAI takes (fresh). One that has ended is never renewed here: a renewal can
542
+ // outlast the server's stop, which would spend the refresh token and lose the new pair with the store closed. The row
543
+ // stays unlisted, and the first settle after a reader renewed it (a run's token()) lists.
544
+ const models = read.row.unlisted && read.row.state === "signed_in" && this.fresh(read.row) ? await this.listModels(read.row.credential.access) : undefined;
532
545
  const confirmed = new Set();
533
546
  for (const old of read.row.retired ?? [])
534
547
  if (await this.revoke(old))
@@ -588,6 +601,14 @@ export class ChatGPTPlan {
588
601
  await this.tellChanged();
589
602
  else if (this.#changeOwed)
590
603
  await this.tellChanged(true);
604
+ // A row still on the fallback list whose token a reader renewed lists now, not at the next start: a settle queued
605
+ // as the start's is (settleLeft), with the token as read and no renewal, one at a time, at most once a minute, none
606
+ // after close().
607
+ const row = this.#snapshot;
608
+ if (row?.unlisted && row.state === "signed_in" && this.fresh(row) && !this.#settling && !this.#closed && this.now() - this.#readSettledAt >= 60_000) {
609
+ this.#readSettledAt = this.now();
610
+ this.settleLeft();
611
+ }
591
612
  })().finally(() => (this.#refreshing = undefined)));
592
613
  }
593
614
  /** The plan's models from OpenAI's list (GET /v1/models with the token), those of the current families (the fallback
@@ -706,10 +727,37 @@ export class ChatGPTPlan {
706
727
  return renewed.credential.access;
707
728
  }
708
729
  // The owner signed out or in again while OpenAI renewed it: the new pair is the sign-in's no longer, and no one
709
- // holds it but this renewal, so it is revoked here, never handed out.
710
- await this.revoke(renewed.credential);
730
+ // holds it but this renewal, so it is revoked here, never handed out. One OpenAI doesn't confirm is carried.
731
+ if (!(await this.revoke(renewed.credential)))
732
+ await this.carry(renewed.credential);
711
733
  return this.adopt();
712
734
  }
735
+ /** A pair this holder got and could not save (a renewal whose write back lost: renewUnder), whose revocation OpenAI
736
+ * didn't confirm: carried in the row (`retired`), for the server's next settle to revoke, as a replaced sign-in's pair
737
+ * is (keep). Never written over another holder's live lease (its write back would lose in turn): it waits for that
738
+ * write back, or for the lease to lapse, as a renewal waits on one (renew), and gives up only past that bound, said in
739
+ * the log. None with no row (a sign-out says OpenAI's word is not the whole answer while a renewal is out). */
740
+ async carry(credential) {
741
+ const giveUp = this.now() + REFRESH_LEASE_MS + REFRESH_CALL_MS;
742
+ for (;;) {
743
+ const now = await this.readSealed();
744
+ if (!now)
745
+ return;
746
+ if (now.row.lease && now.row.lease.until > (await this.storeNow())) {
747
+ if (this.now() > giveUp) {
748
+ this.#deps.log?.({ chatgpt: "renewed_pair_unsaved" });
749
+ return;
750
+ }
751
+ await sleep(LEASE_WAIT_MS);
752
+ continue;
753
+ }
754
+ const next = { ...now.row, retired: [...(now.row.retired ?? []), credential] };
755
+ if (await this.swap(now.bytes, next)) {
756
+ this.wrote(next);
757
+ return;
758
+ }
759
+ }
760
+ }
713
761
  /** After a renewal whose write back lost its compare-and-set (the owner signed out or in again meanwhile): its result
714
762
  * is dropped, and the row's state wins. */
715
763
  async adopt() {
@@ -779,6 +827,7 @@ export class ChatGPTPlan {
779
827
  /** Stops the sign-in waiting, at the server's close. Resolves once every sign-in cancelled (by this, a newer start, a
780
828
  * sign-out or its 10 minutes) has ended, whatever its end said in the log. */
781
829
  close() {
830
+ this.#closed = true;
782
831
  this.cancel();
783
832
  // A settle out (the start's, a kept sign-in's) is waited for too: the server's stop bounds the wait (planClosed), and
784
833
  // what it cuts off stays in the row for the next start.