@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.50

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 (170) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +236 -26
  3. package/dist/agent-delete.d.ts +36 -12
  4. package/dist/agent-delete.js +213 -30
  5. package/dist/agents-store.d.ts +6 -2
  6. package/dist/agents-store.js +18 -5
  7. package/dist/agents.d.ts +8 -1
  8. package/dist/agents.js +14 -4
  9. package/dist/answer-json.d.ts +2 -2
  10. package/dist/answer-json.js +3 -4
  11. package/dist/api-only.d.ts +7 -10
  12. package/dist/api-only.js +9 -11
  13. package/dist/archil-routes.d.ts +1 -1
  14. package/dist/archil-routes.js +4 -3
  15. package/dist/browser-sessions.d.ts +56 -0
  16. package/dist/browser-sessions.js +117 -0
  17. package/dist/compute-cost.d.ts +101 -0
  18. package/dist/compute-cost.js +250 -0
  19. package/dist/computer-routes.d.ts +4 -15
  20. package/dist/computer-routes.js +6 -10
  21. package/dist/console/assets/index-D0mr9wfZ.css +1 -0
  22. package/dist/console/assets/index-D7G6o-1E.js +720 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/errors.d.ts +4 -1
  25. package/dist/errors.js +15 -5
  26. package/dist/eval-previous.d.ts +52 -0
  27. package/dist/eval-previous.js +164 -0
  28. package/dist/file-types.d.ts +2 -0
  29. package/dist/file-types.js +3 -1
  30. package/dist/harness.js +2 -1
  31. package/dist/import.js +4 -3
  32. package/dist/learn/check.d.ts +16 -4
  33. package/dist/learn/check.js +30 -26
  34. package/dist/learn/promote.d.ts +7 -1
  35. package/dist/learn/promote.js +47 -0
  36. package/dist/learn/repick.d.ts +43 -0
  37. package/dist/learn/repick.js +202 -0
  38. package/dist/learn/workflow-draft.d.ts +4 -0
  39. package/dist/learn/workflow-draft.js +10 -7
  40. package/dist/learned-workflow.d.ts +2 -0
  41. package/dist/learned-workflow.js +19 -2
  42. package/dist/learning-setting.d.ts +13 -0
  43. package/dist/learning-setting.js +23 -1
  44. package/dist/llms.txt +1 -1
  45. package/dist/openapi.js +180 -14
  46. package/dist/paid-calls.d.ts +17 -7
  47. package/dist/paid-calls.js +15 -9
  48. package/dist/run-launch.d.ts +2 -2
  49. package/dist/run-launch.js +2 -1
  50. package/dist/run-learning-served.d.ts +1 -1
  51. package/dist/run-timeline-served.js +5 -3
  52. package/dist/run-usage.d.ts +125 -0
  53. package/dist/run-usage.js +394 -0
  54. package/dist/runner/adapter-loop.d.ts +4 -0
  55. package/dist/runner/adapter-loop.js +66 -21
  56. package/dist/runner/adapter-run-spec.d.ts +8 -3
  57. package/dist/runner/adapter-run-spec.js +13 -6
  58. package/dist/runner/big-writes.d.ts +33 -0
  59. package/dist/runner/big-writes.js +105 -0
  60. package/dist/runner/cli-run-spec.js +14 -6
  61. package/dist/runner/conformance/harness.d.ts +2 -0
  62. package/dist/runner/conformance/harness.js +18 -4
  63. package/dist/runner/feedback-round.d.ts +29 -1
  64. package/dist/runner/feedback-round.js +54 -3
  65. package/dist/runner/held.d.ts +4 -1
  66. package/dist/runner/journal-kinds.d.ts +3 -1
  67. package/dist/runner/learning-end.js +54 -18
  68. package/dist/runner/loop-contract.d.ts +3 -0
  69. package/dist/runner/metrics.d.ts +4 -0
  70. package/dist/runner/metrics.js +9 -0
  71. package/dist/runner/monid-run.js +2 -2
  72. package/dist/runner/promotion.js +8 -2
  73. package/dist/runner/reflect-hook.js +3 -2
  74. package/dist/runner/run-child-host.d.ts +15 -2
  75. package/dist/runner/run-child-host.js +24 -8
  76. package/dist/runner/run-child.js +3 -0
  77. package/dist/runner/save-slots.d.ts +9 -0
  78. package/dist/runner/save-slots.js +91 -0
  79. package/dist/runs-over-store.d.ts +3 -2
  80. package/dist/runs-over-store.js +9 -7
  81. package/dist/sdk/runs.d.ts +3 -4
  82. package/dist/sdk/runs.js +10 -7
  83. package/dist/sdk/runtimes.d.ts +19 -0
  84. package/dist/sdk/runtimes.js +23 -0
  85. package/dist/sdk/schema.d.ts +14 -8
  86. package/dist/sdk/schema.js +18 -6
  87. package/dist/server.d.ts +7 -3
  88. package/dist/server.js +223 -100
  89. package/dist/store/agent-body.d.ts +2 -3
  90. package/dist/store/agent-body.js +3 -2
  91. package/dist/store/index.d.ts +2 -2
  92. package/dist/store/index.js +1 -1
  93. package/dist/store/journal/storage.js +1 -1
  94. package/dist/store/open.d.ts +1 -1
  95. package/dist/store/open.js +1 -1
  96. package/dist/store/postgres/migrations/0021_purged.sql +13 -0
  97. package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
  98. package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
  99. package/dist/store/schema.d.ts +20 -1
  100. package/dist/store/schema.js +60 -5
  101. package/dist/store/sqlite/connection.d.ts +4 -1
  102. package/dist/store/sqlite/connection.js +5 -0
  103. package/dist/store/sqlite/run-patch.d.ts +8 -3
  104. package/dist/store/sqlite/run-patch.js +15 -7
  105. package/dist/store/sqlite/store.d.ts +2 -1
  106. package/dist/store/sqlite/store.js +279 -68
  107. package/dist/store/sqlite/worker.d.ts +9 -0
  108. package/dist/store/sqlite/worker.js +18 -1
  109. package/dist/store/store.d.ts +149 -9
  110. package/dist/store/store.js +63 -0
  111. package/dist/store-reads/analytics.js +2 -1
  112. package/dist/store-reads/cap.d.ts +17 -7
  113. package/dist/store-reads/cap.js +54 -4
  114. package/dist/store-reads/decisions.d.ts +21 -0
  115. package/dist/store-reads/decisions.js +22 -0
  116. package/dist/store-reads/journal.d.ts +8 -2
  117. package/dist/store-reads/journal.js +27 -8
  118. package/dist/store-reads/learning.d.ts +1 -1
  119. package/dist/store-reads/learning.js +5 -2
  120. package/dist/store-reads/runs.js +2 -0
  121. package/dist/store-reads/stats.js +4 -2
  122. package/dist/store-view.d.ts +12 -1
  123. package/dist/store-view.js +98 -38
  124. package/dist/template-eval.d.ts +15 -1
  125. package/dist/template-eval.js +92 -13
  126. package/dist/templates.d.ts +1 -1
  127. package/dist/templates.js +4 -3
  128. package/dist/timeline/labels.js +17 -0
  129. package/dist/tool-list.js +1 -0
  130. package/dist/tools.d.ts +6 -2
  131. package/dist/tools.js +22 -1
  132. package/dist/trigger-targets.d.ts +28 -9
  133. package/dist/trigger-targets.js +19 -16
  134. package/dist/triggers.d.ts +2 -1
  135. package/dist/triggers.js +5 -2
  136. package/dist/validate.d.ts +4 -2
  137. package/dist/validate.js +13 -3
  138. package/dist/viewer-credential.d.ts +3 -4
  139. package/dist/viewer-credential.js +6 -4
  140. package/dist/web-fake.d.ts +25 -0
  141. package/dist/web-fake.js +38 -1
  142. package/dist/web-save.d.ts +75 -0
  143. package/dist/web-save.js +235 -0
  144. package/dist/workspace/archil-claim.d.ts +5 -2
  145. package/dist/workspace/archil-claim.js +5 -2
  146. package/dist/workspace/archil-disk.d.ts +10 -1
  147. package/dist/workspace/archil-disk.js +19 -1
  148. package/dist/workspace/archil.d.ts +3 -0
  149. package/dist/workspace/archil.js +101 -16
  150. package/dist/workspace/computer-for-claim.d.ts +19 -1
  151. package/dist/workspace/computer-for-claim.js +88 -20
  152. package/dist/workspace/computer-intervals.d.ts +26 -0
  153. package/dist/workspace/computer-intervals.js +58 -0
  154. package/dist/workspace/computer-janitor.d.ts +7 -3
  155. package/dist/workspace/computer-janitor.js +14 -6
  156. package/dist/workspace/computer-kept.d.ts +7 -2
  157. package/dist/workspace/computer-kept.js +9 -2
  158. package/dist/workspace/pieced.d.ts +14 -0
  159. package/dist/workspace/pieced.js +23 -0
  160. package/dist/workspace/resolve-computer.d.ts +7 -4
  161. package/dist/workspace/resolve-computer.js +21 -32
  162. package/dist/workspace/run-disk.js +32 -12
  163. package/dist/workspace/run-end-computers.d.ts +1 -0
  164. package/dist/workspace/run-end-computers.js +4 -1
  165. package/dist/workspace/run-workspace.d.ts +1 -1
  166. package/dist/workspace/run-workspace.js +11 -6
  167. package/package.json +10 -10
  168. package/templates/README.md +36 -7
  169. package/dist/console/assets/index-CTGegcKt.css +0 -1
  170. package/dist/console/assets/index-D1Se6mgG.js +0 -715
package/CHANGELOG.md CHANGED
@@ -2,6 +2,43 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.50 (2026-11-20)
6
+
7
+ - An API-only server (`AGENTRUN_API_ONLY=1`) serves four learning reads with its token: an agent's loop, promotions and cost per run, and a run's learning. <!-- changes/api-only-learning-reads.md -->
8
+ - Computer time is priced the way providers bill it: by the resources a computer holds, never by a size. An operator copies its provider's per-resource rates from the provider's price sheet into `AGENTRUN_COMPUTE_USD_PER_VCPU_SECOND_<PROVIDER>`, `AGENTRUN_COMPUTE_USD_PER_GIB_SECOND_<PROVIDER>`, `AGENTRUN_COMPUTE_USD_PER_GPU_SECOND_<PROVIDER>_<GPU_TYPE>` and `AGENTRUN_COMPUTE_USD_PER_DISK_GB_MONTH_<PROVIDER>` (a month of 730 hours). A priced computer's time is held on the run's ledger under its `max_cost_usd`, one 5-minute stretch ahead, as browser time is: a claim's computer, made while the run is set up, has its first stretch held as soon as the run's cap can judge, so the run's first request is judged beside it (a cap with no room parks the run there); a computer made later in the run (a lost sandbox's new one) has its first stretch held before its create, and a cap with no room makes nothing and fails the run in the cap's words; a cap with no room for a later stretch pauses the run for a raise; and the time it ran is booked before the run's end is written, so the end's `cost.usd` holds it all. The run's ledger tells a caller whether its cap can judge yet (`RunLedger.judges`), and a paid step asked while the run's spec is built waits for it instead of failing. With no price set nothing changes: the computer runs outside the cap, as a tool call with no price does, and is never refused. A resource set to `0` is booked at $0 and reads $0, never `unpriced`. `GET /v2/runs/{run_id}/usage` gives `compute_time` lines (`runusage/4`), one per provider and resource, with the raw quantity, its unit, its basis and the dollars the run's ledger booked, so `total` stays the run's `cost.usd`; the time no claim held (a computer kept for a follow-up, one deleted after its run, one whose delete failed) is said apart as `unheld_quantity` and is in no cost. Each computer interval gives `disk_gb` and `booked_seconds` (Postgres migration `0023_computer_interval_resources.sql`; a SQLite store gets both columns at the server's open). A computer's figures are its provider's own where its answer gives them: `CreatedComputer.resources` in `@parcha/agentrun-computer`, filled from Daytona's sandbox (vCPUs, memory, disk and GPUs), E2B's `getInfo` and Fly's machine guest (vCPUs and memory), and `Machine.resources` for a hosted provider's read of its machine. <!-- changes/compute-prices.md -->
9
+ - The file viewer shows images and plays video and audio from the run's file route, which now serves `.webm`, `.mp3`, `.wav`, `.m4a` and `.ogg` inline with their types. Settings → MCP servers has two fal presets, fal (key) and fal (sign in); fal bills your fal account, and a run's spend cap does not count it. <!-- changes/console-media-viewer-and-fal-preset.md -->
10
+ - A template eval case can name `previous: fixtures/previous.json`, the earlier completed results of the package's schedule trigger, each checked against its own `output_schema` (else the package's) when the case is read; the eval writes them in its own server's store as completed runs of the run's agent, each started by a firing of that trigger, then fires the trigger on its clock, so the run is handed its last result whole, as its `x-carried` fields with the first entries dropped and counted, or nothing, said so, exactly as a scheduled run is. What the run was handed is on its report as `handed_previous`, and a new `handed` grader checks it (`expect: whole | carried | too_large | none`, with `dropped` counts for carried arrays). <!-- changes/eval-previous-run.md -->
11
+ - A workflow decision Parallel answered on its own API (the `parallel` provider on the server's `PARALLEL_API_KEY`, booked at Parallel's list price, $0.001 a request) now counts as a paid call Parallel charged, beside `web_search` and `web_fetch`: it is in the run's `cost.tools_usd` (`toolsusd/2`), on the `parallel` `tools` line of `GET /v2/runs/{run_id}/usage` (`charged_by` and `provider` `parallel`, one call each, `basis` `estimate`), and on the `tools` meter of `GET /v2/usage`. It used to be on a `tokens` line under its model (`parallel-fast`). It moves; it is not added: `total` is still the run's `cost.usd`, and `cost.usd` does not change. A `parallel` decision sent through OpenRouter (no `PARALLEL_API_KEY`, on the OpenRouter key) is OpenRouter's to charge, at the cost OpenRouter reported, and stays a `tokens` line, as Jev's and other decision models' do. <!-- changes/parallel-decision-tool-lines.md -->
12
+
13
+ A Parallel search is now priced by its `mode`, from [Parallel's pricing page](https://docs.parallel.ai/resources/pricing) (read 2026-11-20): `turbo` or `fast` $0.001 a request, `basic` or `advanced` $0.005, each with 10 results included, and $0.001 for each result past them. `web_search` always searches `fast`, so what it books does not change. A search body in a mode with no price here, or naming none, is never sent, as a request to an endpoint with no price is not: it is never booked at $0 or at `fast`'s price.
14
+ - SDK runs accept externally executed agents through `sdk: {runtime: "external", platform: "OpenClaw"}`. Use `"Capy"` or another platform label without adding a runtime. The required label is 1–80 Unicode characters with no leading or trailing whitespace, control characters or unpaired UTF-16 surrogates; it is preserved in the console and on each recorded run. Registration and run start must name the same runtime and platform. Other SDK runtimes reject `platform`. See [Report runs from an external platform](../../docs/tutorials/platform-sdk-runs.md). <!-- changes/sdk-runs-openclaw-capy.md -->
15
+ Execution stays on the platform: managed launch, stop, cancel and follow-up requests are refused. External sources receive the owner's corrections when learning is on, with no workflows. Starts carrying `workflow_tools` or `workflow_adapters` are refused (422) before recording a run. `BackendLearningClient`, imported from `@parcha/agentrun-client/learning`, accepts the external binding and refuses a `workflows` bridge before any request. Existing Claude Agent SDK, Codex SDK and eve integrations retain their behavior.
16
+ The generated TypeScript `StartSdkRunBody` is now a union. Consumers that extend it with an interface or index its workflow fields must use a type intersection or select the SDK branch; the [client README](../client/README.md#learning-for-existing-backend-sdk-agents) describes the migration. `BackendLearningStart` remains extensible, and existing Python TypedDict constructors and CLI flags are preserved.
17
+ - `web_save {url, path}`, a new host tool, saves one public file (at most 200 MiB) into the run's `work/`, a bare name under `media/`. It downloads through `web_fetch`'s guard, never overwrites, and saves media only when the bytes, the declared type and the extension agree. An agent gets it by naming it. pi-browser adds `publicDownload`, the bytes version of `publicFetch`. A template eval's `web:` fixture takes an optional `save` section. <!-- changes/web-save-tool.md -->
18
+ - An API-only server (`AGENTRUN_API_ONLY=1`) now serves `GET /v2/runs/{run_id}/usage`, a run's usage lines. It answered `404` before, so a backend could read a run and its `cost.usd` but not the lines that make it up. The route reads only that run, takes the server's token, and cuts the host's secrets out of its names as `GET /v2/runs/{run_id}` does. Every other route the profile refused is still refused. <!-- changes/api-only-run-usage.md -->
19
+ - A run on an Archil disk that Archil no longer has fails at its claim, before any file call, saying so: the agent's disk is read at Archil at every claim (one GET), as a launch's disk already was, and a disk that is gone, or one in another region than the key's, refuses the run naming the disk, the region and the way out (`DELETE /v2/agents/{id}/archil` drops it, and the agent's next run makes a new one). No new disk is made in its place: the agent's learning and its runs' folders were on it. Before, such a run failed at its first claim with `".agents/skills" is not there`, since every call on the missing disk answered 404 and a 404 read as a folder that was not there. <!-- changes/archil-disk-gone.md -->
20
+ - An Archil run folder makes its folders before it writes: Archil can answer 404 to a put whose folder is not there (it made no parent for an expert run's `.agents/skills/` on a fresh run folder, so every expert run failed at its claim with `".agents/skills" is not there`). A write, an append, a mkdir, the run folder's own put and a synced folder's push now make each missing folder above the key, from the highest down, and put again; a folder already there is left as it is.
21
+ - An Archil workspace keeps Archil's own words in a failure: a missing file or folder is still `NOT_FOUND`, naming the call (list, read, write, append, mkdir, put) and what Archil said after it, and a disk Archil has no record of is `UNAVAILABLE` naming the disk and its region, never a missing folder.
22
+ - A run's folder on its Archil disk that can't be made fails the claim with the reason, where it was a log line; a folder already there is not put again, so a later claim whose kept computer holds it opens at once.
23
+ - With `learning.repick: true`, a learned workflow whose answer is written by a composed workflow now re-picks from the pages in that composed workflow, where before it was committed as compiled without a word. A re-pick the rewrite still does not reach (one that is not a single model step, or whose marker names are taken) is kept as compiled, and the server's log says so. <!-- changes/learning-repick-reach.md -->
24
+ - `POST /v2/templates/{template}/apply` now answers `revision_version`: the number of the agent's revision the apply wrote, its current one now (`1` for an agent it made; on an update with `agent_id`, the new revision's). This is a public API addition: the TypeScript and Python clients carry the field, and the console says "Updated: rev N" from it with no second read of the agent. A purged run's answer and input no longer stay in the server's in-process caches after its `DELETE` (or its agent's): the purge drops them, and a read under way when the purge lands keeps none of them. A SQLite purge whose WAL checkpoint another connection holds back now leaves the store's scrub marker (`store.sqlite.scrub`), and the next start's scrub truncates the log before it serves, a crash in between included; it no longer retries or logs a warning. A secret rewrite running beside the purge never removes the marker the purge left. When that marker cannot be written (a full disk), the purge has still committed: the `DELETE` answers 500 `internal`, saying so, and the server logs it; the run's cached answer and input are dropped all the same, and the next `DELETE` answers 204. <!-- changes/purge-tidy.md -->
25
+
26
+ Upgrade note: a retried apply whose answer was saved before the upgrade replays without `revision_version`; it ages out within a day.
27
+
28
+ ## 0.1.0-beta.49 (2026-11-20)
29
+
30
+ - `learning.repick: true` (off by default) has a learned workflow's quote re-pick read the pages its run fetched, sent as untrusted data to a step with no tools; `learning.repick_max_chars` (150,000 by default) caps what it sends. It reaches workflows compiled after it is set, and agents on an SDK bridge ignore it. <!-- changes/learning-repick-pages.md -->
31
+ - A purged run's or agent's content no longer stays in the SQLite store's file bytes: every store connection writes with `secure_delete` on, so a deleted or overwritten row's bytes are zeroed in its page, and a purge checkpoints the WAL (`TRUNCATE`) once it commits, so neither `store.sqlite` nor its `-wal` keeps an earlier copy. The checkpoint waits a few milliseconds for another connection, never the store's 10 s busy wait, so it holds up no other request. One another connection holds back is retried once, then logged (the next purge's checkpoint or the server's stop clears it), and never fails the `DELETE`. Postgres is not covered: `VACUUM` only makes a purged row's space reusable, so its bytes stay until a later write overwrites them; `VACUUM FULL` rewrites the table; Postgres's WAL, archived WAL and backups keep the old values for their own lifetimes. <!-- changes/purge-secure-delete.md -->
32
+ - `DELETE /v2/runs/{run_id}` purges a run that is not live: its launch, journal and timeline, messages, outputs and files, folders, kept answers, its agent's grades of it, its kept learning's content and what its agent's promotion records copied from it (a disagreement's input and answers; each record's decision, numbers and run ids stay) go, with the runs made from it (its audit's shadow run, the replay runs of its input, a learning run that grades it); no replay or shadow run of a purged run is started. Its row stays as a tombstone (id, agent, state, times, cost, purge time): `/usage`, `/stats` and a cap's spend read are unchanged, every route of the run answers `410 purged` with the tombstone in `details`, and no run list shows it. A second `DELETE` is `204`; a live run (queued, working, waiting on a person, or held by a runner) is `409 run_not_final`, nothing purged; a purge stopped part way is finished by the next `DELETE`. A message, a trigger's message or a grade sent to the run while its `DELETE` runs waits for it and is then `410 purged`. `DELETE /v2/agents/{agent_id}` now purges an archived agent made here the same way (its definition, learning, triggers, sign-ins, computer, disk and folders go, its runs become tombstones, its row is a tombstone answering `410 purged`); one not archived is `409 agent_not_archived`, which replaces `agent_not_external`. An unarchive or a write sent to the agent while its purge runs (its home, its definition, a move of its current revision) is `410 purged` once it ends, as is a definition edit or a template update whose body arrives after it, and a trigger made for a purged agent or moved to it: nothing of a purged agent is written again; after a purge stopped part way, each is `409 agent_not_runnable` until a `DELETE` finishes it. An agent another system owns is deleted whole, as before. Both deletes take the owner's session or the API token: any other console session is `403 forbidden`. The TypeScript client, the Python client and the CLI (`agentrun runs delete`) carry the new operation. <!-- changes/run-delete.md -->
33
+ - `GET /v2/runs/{run_id}/usage` (`runusage/1`) says what one run cost, line by line, and whose invoice each part lands on: `tokens` per model (`model`, and `provider` where the server sent the requests itself; null behind a gateway), `tools` per charger (`charged_by`, with calls of unpriced tools in `not_metered_calls`), and `browser_time` per browser provider (`provider`, seconds). Each line has its quantity as measured, its dollars as the run's booking holds them, and its basis (`reported`, `estimate`, `unpriced`). It reads the same for a pi run, a CLI-harness run and a workflow run (its decisions on the model that answered them). The lines join to `total`, the run's `cost.usd`; a charge of unknown cost is null with what is known beside it, never $0. `ended_at` is the end the lines cover: a follow-up can reopen an ended run, and a later read with another `ended_at` says it moved. The console's Dev tools tab shows the lines as "Cost by line". In the kernel, a paid request may say `reported` (it settles at the provider's own figure), written on its `runner.request`. <!-- changes/run-usage-lines.md -->
34
+ - `GET /v2/computers`' `folder` field is described by its rule alone, naming no vendor: `bind` a folder of this machine (Mode 1), `archil` the owner's Archil disk where the provider takes an Archil mount, has Archil's image and does not dial this server, `sync` a synced folder the runner keeps for any other computer that takes a folder in Mode 2, null none. The computer package's README no longer says a program of the user can join the window manager's namespace with nsenter: root made it, and the user holds no capability there. A Daytona desktop on exec is refused in the shared refusal's words alone. `runConformance` takes `onScreenshot(png)`, called with screen.screenshot-size's last whole screenshot. <!-- changes/computer-untangle-16.md -->
35
+ - In the console, updating an agent from a template (Update <agent>) now says it was updated and names the new revision ("Updated: rev 2"). It used to say the template was applied and "The agent is made", as if the apply had made a new agent. Only an Apply that makes a new agent says "made". <!-- changes/template-update-says-updated.md -->
36
+ - A scheduled run handed its previous result's `x-carried` fields is told how many entries each carried array lost from its front, "the first N entries" (the template keeps the array oldest first), no longer "the N oldest": the engine drops from the front and reads no dates. A stored `x-carried` the save would refuse (a repeated, unknown or empty name) is read as none, so its run gets the too-large line. `submitParameters` leaves every `x-` keyword out of submit tool schemas, as it does `criteria`, not only `x-carried`; a property or definition so named keeps its name. <!-- changes/x-carried-first-entries.md -->
37
+ - A run's look-back (its own after its job, or the feedback round a grade opens) keeps the run's end: GET, the list, SSE and the console show it completed (or failed) with its answer and `ended_at` while its learning reads `reflecting`, polled until it settles, and it tells `run.ended` once. Stop and cancel refuse it then, and a runner-side stop or cancel that lands mid-round drops only the round, so a graded run is never left cancelled or stopped. A runner lost during the look-back leaves the next one the same end at the same time. `PUT /v2/runs/{run_id}/grade` during a look-back is `409 run_learning` (a new error code), nothing kept: grade the run once its learning moves on from `reflecting`. <!-- changes/grade-keeps-run-end.md -->
38
+ - `GET /v2/runs/{run_id}/usage` gives `browser_sessions` (`runusage/2`): one record per browser session the run opened, with the provider's session id, when the server opened it and let it go, why it ended, the seconds charged for it, and the provider's own record of it (`provider_record`: its start, end and proxy bytes), read once when the session is let go. With it a person running AgentRun sees how long each session ran, spots one that ended late or was lost, and finds each on the provider's own dashboard and invoice by its id. A provider that keeps no record, or a read that fails, says so in `provider_record_status`, with the record null, never zeros. In the computer package, a browser provider may offer `sessionUsage(ref)`, the vendor's record of a session; Browserbase's reads `GET /v1/sessions/{id}`. <!-- changes/run-usage-browser-sessions.md -->
39
+ - `GET /v2/runs/{run_id}/usage` gives `computer_intervals` (`runusage/3`): one record per computer the run made through its provider (a sandbox, a desktop or a phone), by when each was made, with the provider's own id for it (`provider_id`), its `kind`, what its create asked for (`gpu`, `cpus`, `memory_mb`; null where it asked none, never a guess), when the create answered (`started_at`), when the provider's delete of it answered ok (`ended_at`), and whether the run's park kept it past its claim (`kept`). With it a person running AgentRun sees how long each of a run's computers lived, finds one left running after its run (`ended_at` null: no delete was proven, never a guessed end), and matches the provider's invoice by its id. The server writes the store's new `computer_intervals` table (Postgres migration `0022_computer_intervals.sql`; a SQLite store gets it at the server's open) at the claim's create, the park, and every delete that answers ok: the claim's release, a later claim letting an earlier one's go, the run's end, a kept computer's end, and the janitor's sweeps. A write that fails is said on the runner's log and never fails the run. The agent's own computer, a paired one and `--faux`'s have no record. Computer time is not priced: it is on no line and not in `total`. A `tools` line now names its `provider` too, the same vendor as `charged_by`; a `tokens` line behind a model gateway keeps `provider` null, since the server does not know the gateway's upstream. <!-- changes/computer-intervals.md -->
40
+ - An agent whose `input_schema` fields are all optional takes a run that gives one of them and no `content` (`{"pr_number": 3318}` was refused 422). An input with neither is still refused at `input.content`. <!-- changes/input-content-or-field.md -->
41
+
5
42
  ## 0.1.0-beta.48 (2026-11-20)
6
43
 
7
44
  - A harness module builds its harness the way the built-in harnesses are built: `entries(builtins, kit)` now gets a kit with `kit.adapterEntry(facts, adapter)` and `kit.acpEntry({ facts, recipe, proxy })`, so the harness is offered its wire's vendor's models, named on that vendor's and OpenRouter's key rows, and gated and named by its own facts. [HARNESS.md](../../HARNESS.md) is the guide, and `examples/harness-module` is a whole module (Goose under an id of its own). <!-- changes/harness-modules-kit.md -->
package/README.md CHANGED
@@ -1429,6 +1429,7 @@ agent_not_runnable`, with `details.unbound` and `details.missing`).
1429
1429
  | `ask_person` | Ask the person who started the run; the turn ends until a message answers | nothing | no, no |
1430
1430
  | `web_fetch` | Read one web page from a public host through the guarded direct fetch, or through Parallel's extract where Parallel is picked ([search and fetch](#search-and-fetch)), a part at a time: `{url, offset?, max_chars?}` in, a Page out, `{ok, url, status, title, text, chars, truncated?, original_chars?, beyond_read?, offset?, next_offset?, html_chars?, converted?, links, links_omitted?, via, parallel?, refused?, error?}` | nothing (`PARALLEL_API_KEY` for Parallel, one billed extract a page a run) | yes, yes |
1431
1431
  | `web_search` | Search the web, natively where the harness or the model's provider can, else through Parallel where the server holds its key, else keyless through Exa, or through the provider picked ([search and fetch](#search-and-fetch)): `{query, n?}` in, `{provider, query, results: [{url, title, snippet, published?}], text?}` or `{error}` out | nothing (`PARALLEL_API_KEY` for Parallel) | yes, yes |
1432
+ | `web_save` | Download one file from a public URL into the run's `work/` and keep it there, for a link that expires (a generated image, audio or video): `{url, path}` in, `path` relative to `work/` and a bare name under `media/`; `{ok: true, path, bytes, content_type, url}` or `{ok: false, url, refused \| error}` out. Never overwrites | nothing | no, no |
1432
1433
  | `browser` | A hosted browser, Browserbase's or Kernel's, on pi-browser's durable adapter: `snapshot`, `run`, `screenshot`, `browser_read`, `browser_release`, `browser_relaunch`, `browser_downloads` and `browser_upload` (into and from the run's `work/`); Kernel keeps no downloads, so a run on Kernel has no `browser_downloads` | `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID`, or `KERNEL_API_KEY` | yes, no |
1433
1434
  | `monid:<provider>/<endpoint>`, `monid:<provider>/*` | One monid endpoint, or every endpoint monid lists for a provider (at most 50), each pinned at the save and run as a tool of its own, paid per call from the monid wallet: `{body?, queryParams?, pathParams?}` in, the run's `output`, `price` and `cost` out ([monid](#monid)) | `MONID_API_KEY` | no, no |
1434
1435
  | `pdf_pages` | A workflow call only: `{path, maxPages?, dpi?}` in, `{name, pageCount, dpi, pages: [{page, image}], text}` out. Draws a document's first pages (3 by default, at 110 dpi) as PNGs under the run's `work/pages/<stem>/<dpi>/` (`<stem>`: the document's path below its directory made one name, with a short hash, so two documents of one file name never share pages), the dpi lowered so a page's long side is at most 1568 px, with its text (`pdftotext`, cut at 20,000 characters). A PNG or JPEG passes through as one page, scaled down to 1568 px. `path` is under `--documents` or the run's `work/`, never outside | `pdftoppm`, `pdftotext` | no, yes |
@@ -1471,6 +1472,14 @@ can branch on it. An agent gets the Page as JSON text; a workflow's `call` node
1471
1472
  it as its output (`args: {url, offset?, max_chars?}`, 50,000 characters of text by default, `out` a schema of that
1472
1473
  shape). A call node naming a tool the table cannot run that way is refused before the run starts (`409`).
1473
1474
 
1475
+ `web_save {url, path}` downloads one public file through the same guard (pi-browser's `publicDownload`, the same hop
1476
+ loop), at most 200 MiB in at most 10 minutes, into the run's Workspace (a bare name goes under `media/`), so `..`, an
1477
+ absolute path and a link are refused, and a path already in use is refused, never overwritten. The file is written once,
1478
+ after the whole download, so a failed one leaves nothing. An image, audio or video is saved only when its bytes, the
1479
+ declared type and the path's extension agree (`media/card.png`, never `media/card`); any other type only to a path whose
1480
+ extension names the declared type. It makes no paid request and is never run again after a crash. Only an agent that
1481
+ names `web_save` has it; no workflow node or call node may name it.
1482
+
1474
1483
  On another harness, every host tool's result reaches the model within the host's bound of 120,000 characters
1475
1484
  (`HOST_RESULT_MAX_CHARS`, `@parcha/agentrun-kernel`): the kernel's tool bridge cuts a longer one, its start with a line
1476
1485
  saying where it was cut, and flags the call `truncated`. Each CLI adapter tells its CLI to pass a result that long to
@@ -1677,9 +1686,11 @@ Parallel's fees are the run's spend, booked as monid's are: each search and each
1677
1686
  run's records before it is sent (`agentrun.tool_started`, held at its price) and settled once Parallel answers
1678
1687
  (`agentrun.tool_cost`: `tool` `web_search` or `web_fetch`, `charged_by` `"parallel"`, `usd`), shown on its timeline
1679
1688
  (`Tool cost: parallel charged $0.0010 for web_search`), summed into its cost and under `/usage`'s `tools` meter. Parallel
1680
- answers what it used as counts, never an amount, so each is booked at Parallel's published price (docs.parallel.ai,
1681
- read 2026-11-03), an estimate: a `fast` search $0.001 for up to 10 results and $0.001 for each one past them, an extract
1682
- $0.001 a URL; on a 4xx other than a 408 nothing (Parallel refused it), and on a 408, a 5xx, a timeout or a lost
1689
+ answers what it used as counts, never an amount, so each is booked at Parallel's published price
1690
+ ([docs.parallel.ai/resources/pricing](https://docs.parallel.ai/resources/pricing), read 2026-11-20), an estimate: a
1691
+ search by its mode, `turbo` or `fast` $0.001 and `basic` or `advanced` $0.005, each for up to 10 results, and $0.001 for
1692
+ each result past them (`web_search` always searches `fast`); an extract $0.001 a URL. A search in a mode with no price
1693
+ here, or naming none, is never sent, as an endpoint with no price is not; on a 4xx other than a 408 nothing (Parallel refused it), and on a 408, a 5xx, a timeout or a lost
1683
1694
  connection its price (Parallel may have billed it). Under a [spend cap](#spend-cap) each is a paid call: sent only when
1684
1695
  what the run has spent and holds, plus its price, fits the cap. Otherwise nothing reaches Parallel: a search answers the
1685
1696
  cap's refusal (`spend_cap_reached: Not sent: this run has spent $0 of its $0.0009 cap, and the next step, Parallel's search, could cost up to $0.001 …`) and a page is the
@@ -2680,8 +2691,9 @@ so the store's files keep no copy of the old row: neither the one rewritten nor
2680
2691
  free space. A marker beside the database (`store.sqlite.scrub`) is written before the rewrite and removed once the
2681
2692
  checkpoint is done. A `VACUUM` held off by another connection's write past the store's busy wait is tried once more
2682
2693
  after a short pause. A start that finds the marker (the server stopped mid-way, or another connection held the
2683
- `VACUUM` or the checkpoint back, logged as `store_scrub_not_done`) runs the scrub again. On Postgres the old row version stays until the
2684
- database vacuums it. The log line names the trigger and the field, never the value.
2694
+ `VACUUM` or the checkpoint back, logged as `store_scrub_not_done`) runs the scrub again. On Postgres the old row version
2695
+ stays on disk as a purged row's does (Purging a run or an agent made here: on disk). The log line names the trigger and
2696
+ the field, never the value.
2685
2697
 
2686
2698
  The create is refused before Composio is asked anything with `409 composio_no_public_url` when the server has no public
2687
2699
  address (`AGENTRUN_PUBLIC_URL`): Composio could not reach it. `features.triggers.public_url` on `GET /v2/capabilities`
@@ -2884,12 +2896,13 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
2884
2896
  | `GET /health` | Without a credential: whether the store reads and the disk has room ([capacity and health](#capacity-and-health)). |
2885
2897
  | `GET /openapi.json` | Without a credential: this API as an OpenAPI 3.1 document, the `agentrun.v2/0` contract (vendored in `src/openapi/`, its source in `info`) with this server's own routes marked `x-agentrun-serve`, the operations it answers `501` marked `x-agentrun-serve-unsupported`, and a contract operation that takes more than the contract gives marked `x-agentrun-serve-changed` with each change named; `links.openapi` in capabilities points at it. |
2886
2898
  | `GET /capabilities` | Without a credential. `backend: local`, every feature flag present and true only when it works; `tools`, the tools an agentic revision may name; `workflows`, what a workflow revision's model nodes get and, in `workflows.decisions.providers`, the decision providers its typed questions run on; `models`, where models come from and the model of each tier. |
2887
- | `POST /agents`, `GET /agents`, `GET /agents/{id}` | `POST` takes `{definition, skills?, note?}` and makes the agent with its first revision, current. A definition has `instructions` (an agentic revision) or `workflow` (a workflow revision, checked by the DSL first), and `name`, `description`, `model` and `thinking` (agentic only), `harness` ([harnesses](#harnesses)), `place` ([place](#place)), `tools`, `tool_settings` ([search and fetch](#search-and-fetch)), `skills` (names; each `<name>/SKILL.md` is in `skills`) and `version`, which is the number the revision gets, and `max_cost_usd`, the agent's default cap (an agentic agent's or a workflow's), kept by an edit that leaves it out and cleared only by 0 ([spend cap](#spend-cap)), and `output_schema` (agentic only, at most 64 KiB): the JSON Schema the final answer's last fenced json block meets, which a completed run's `result.output` then holds (null when the answer doesn't meet it), kept by an edit that leaves it out. A template's answer schema is set here at apply, and a run a schedule trigger starts is handed that trigger's last completed `result.output` after its message; no other source's runs are, since each of their firings is a different event. A result over 32 KiB (as 2-space JSON) is handed only as the top-level fields its run's output schema (that run's revision's, not the agent's current one) names in `x-carried`, an array of unique names of the schema's root `properties`, with words naming them and the whole result's size. A carried array is kept oldest first by convention (the template that writes it owns the order; the engine reads no dates): when the carried fields are themselves over 32 KiB, the array largest in bytes right then gives up its first (oldest) entry, one at a time, measured again after each, a tie going to the first in `x-carried`, until they fit, and the words say per field how many oldest entries were dropped (`seen: 12 oldest entries dropped`). A scalar or object is never cut, nor anything inside an entry; with no `x-carried`, or carried fields still over the limit with no entry left to drop, the run is told the result was too large and handed none of it. A save refuses any other `x-carried` (`422`, field `definition.output_schema.x-carried`); the server leaves it out of every tool schema a model is sent. `checkout` (agentic only): `pull_request` has the server check out, before each run's first turn, the pull request the run's GitHub event names, in `repo/` at its head with its base and merge base, using a read-only token of its GitHub App that the agent never holds ([GitHub triggers](#github-triggers-connect-github)); `none` clears it, and an edit that leaves it out keeps it. A field the store does not keep (`input_schema`) is `422 input_invalid` by name, and so is a definition that can never run here; one this host cannot run yet saves with `warnings` ([models](#models)). The ETag (`home_etag`) is the current revision's id. `GET /agents/{id}` adds `tools`, the tools its current revision grants with each one's provider ([search and fetch](#search-and-fetch)). It also adds `run_blockers` (`x-agentrun-serve: "runblockers/1"`): `{message, fields}` as a start with no overrides would be refused now (`409 agent_not_runnable`), or null. It is always null for an archived, native or SDK agent and for a revision whose MCP tools its first run pins, and the read asks no other service, so under the agent's `max_cost_usd` an OpenRouter decision model's missing price is named only once a save or a start has read OpenRouter's catalog: null is no promise that a start is accepted. |
2899
+ | `POST /agents`, `GET /agents`, `GET /agents/{id}` | `POST` takes `{definition, skills?, note?}` and makes the agent with its first revision, current. A definition has `instructions` (an agentic revision) or `workflow` (a workflow revision, checked by the DSL first), and `name`, `description`, `model` and `thinking` (agentic only), `harness` ([harnesses](#harnesses)), `place` ([place](#place)), `tools`, `tool_settings` ([search and fetch](#search-and-fetch)), `skills` (names; each `<name>/SKILL.md` is in `skills`) and `version`, which is the number the revision gets, and `max_cost_usd`, the agent's default cap (an agentic agent's or a workflow's), kept by an edit that leaves it out and cleared only by 0 ([spend cap](#spend-cap)), and `output_schema` (agentic only, at most 64 KiB): the JSON Schema the final answer's last fenced json block meets, which a completed run's `result.output` then holds (null when the answer doesn't meet it), kept by an edit that leaves it out. A template's answer schema is set here at apply, and a run a schedule trigger starts is handed that trigger's last completed `result.output` after its message; no other source's runs are, since each of their firings is a different event. Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names. `checkout` (agentic only): `pull_request` has the server check out, before each run's first turn, the pull request the run's GitHub event names, in `repo/` at its head with its base and merge base, using a read-only token of its GitHub App that the agent never holds ([GitHub triggers](#github-triggers-connect-github)); `none` clears it, and an edit that leaves it out keeps it. A field the store does not keep (`input_schema`) is `422 input_invalid` by name, and so is a definition that can never run here; one this host cannot run yet saves with `warnings` ([models](#models)). The ETag (`home_etag`) is the current revision's id. `GET /agents/{id}` adds `tools`, the tools its current revision grants with each one's provider ([search and fetch](#search-and-fetch)). It also adds `run_blockers` (`x-agentrun-serve: "runblockers/1"`): `{message, fields}` as a start with no overrides would be refused now (`409 agent_not_runnable`), or null. It is always null for an archived, native or SDK agent and for a revision whose MCP tools its first run pins, and the read asks no other service, so under the agent's `max_cost_usd` an OpenRouter decision model's missing price is named only once a save or a start has read OpenRouter's catalog: null is no promise that a start is accepted. |
2888
2900
  | `PUT /agents/{id}/definition` | The same body, checked [the same way](#models): a new revision, its parent the current one, made current. Without `skills` the current revision's skill files carry over. A definition that is the current revision already writes nothing, so a PUT sent twice makes one revision. An agent's id and name stay those it was made with (another name is `422` on `definition.name`). Its description is a label kept on the agent, not on a revision: a PUT that names a new one makes the next revision (even when nothing else changed) and writes the description with it in one commit, so a stale or refused edit changes neither; a PUT that leaves it out keeps it. `If-Match` that is not the current ETag is `412 precondition_failed`; the store compares it again inside the commit, so of two edits that read the same revision exactly one lands. The contract's body is taken too: the definition itself, with `If-Match` required (`412` without it) and `definition.version` greater than the current one (`422`). Any such version is taken, and always makes a new revision, the same definition included; the revision is numbered as this server numbers them, the next, and the answer says which; the route reads a body holding `definition` as this one, any other as the contract's. |
2889
2901
  | `GET /agents/{id}/revisions` | The agent's revisions, newest first: `revision`, `version`, `parent`, `kind`, `current`, `note`, `created_at` and the `definition`. |
2890
2902
  | `POST /agents/{id}/current` | `{revision}`: one of the agent's revisions becomes current again. |
2891
2903
  | `POST /agents/{id}/archive`, `POST /agents/{id}/unarchive` | [Archiving](#archiving): hides the agent and its runs from the lists, or shows them again. Answers the agent, with `archived_at`. |
2892
- | `DELETE /agents/{id}` | This server's own route (`x-agentrun-serve: "agentdelete/1"`): [deletes an agent another system owns](#deleting-an-agent-another-system-owns) (one an inline run made) whole. `204`; an agent made here is `409 agent_not_external`. |
2904
+ | `DELETE /agents/{id}` | This server's own route (`x-agentrun-serve: "agentdelete/1"`): [deletes an agent another system owns](#deleting-an-agent-another-system-owns) (one an inline run made) whole, and [purges](#purging-a-run-or-an-agent-made-here) an archived agent made here. `204`; an agent made here not archived is `409 agent_not_archived`. |
2905
+ | `DELETE /runs/{id}` | This server's own route (`x-agentrun-serve: "purge/1"`): [purges](#purging-a-run-or-an-agent-made-here) a run that is not live, its cost kept in every total. `204`, again on a second `DELETE`; a live run is `409 run_not_final`, and every route of a purged run is `410 purged`. |
2893
2906
  | `DELETE /agents/{id}/sign-ins/{key}` | This server's own route (`x-agentrun-serve: "signins/1"`): forgets one of the agent's [saved sign-ins](#saved-sign-ins), at its vendor and here. `409 sign_in_held` while a run holds its save lease, or while a run it was handed is still going. |
2894
2907
  | `POST /agents/{id}/runs`, `GET /agents/{id}/runs` | A run of the current revision, or of `revision`. An agentic run's input is `{content: string}`; a workflow run's is what its workflow's input schema takes. `file_ids` names [uploaded](#uploads) files, copied into the run's `work/inputs/` before it starts and named in its first message. `labels` (this server's own, `runlabels/1`) is the caller's map of its own strings for the run: at most 16 keys, each 1 to 63 letters, digits, `.`, `_`, `-` or `/` starting with a letter or a digit, each value 1 to 256 characters with no control character; kept as given, served as `labels` on every read of the run (`{}` when none), never read by the server otherwise, so no place for a secret. The agent's runs, newest first; `label` filters them as `GET /runs` does. |
2895
2908
  | `GET /runs` | Every agent's runs, newest first, a page of at most 100; `agent`, `revision` and `status` narrow it, `label=<key>:<value>` (`runlabels/1`, split at the first `:`, once per request) keeps the runs holding that label, and `archived=true` lists only archived ones. A failed run's summary carries its `error`, and a waiting run's its `pending`. |
@@ -2903,6 +2916,7 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
2903
2916
  | `GET /agents/{id}/home/files`, and `GET`, `PUT`, `DELETE` on a file's path below it | The files in the agent's home, listed, read, written and deleted ([agent home](#agent-home)). This server's own routes (`x-agentrun-serve: "home/1"`). |
2904
2917
  | `GET /stats` | This server's own route, outside the contract (`x-agentrun-serve: "stats/1"`): the agents, the runs (`total`, `active`, `needs_input`, `failed`, `needs_review`, `status_unknown`), each agent's run count, the cost and what is archived, read from the agent store's aggregates alone, no run's files opened. Archived agents and runs are left out of every number but `archived`. A completed or cancelled run counts only in `runs.total`, but for an escalated one (completed, waiting for a person's review), which `needs_review` (`stats/3`) counts; `failed` never does. Each running run is in exactly one of `active` (queued or working) and `needs_input` (`input_required`), both from the runs this server holds, and `status_unknown`: a running run it does not hold, or holds as ended before its end is written. `cost.usd` sums the runs that ended with a cost and is null when none did, never $0, with `basis` (`reported`, `estimate` or `unpriced`: [A run's cost](#a-runs-cost-its-tokens-and-its-basis)), or null beside a null `usd`; `unknown_runs` counts the rest. `analytics` (`stats/2`) sums the runs' metrics over the runs not archived that the `from` and `to` query parameters (RFC 3339 date-times to the millisecond, an impossible one or a finer fraction refused; runs started in [`from`, `to`)) and `agent` pick, each optional, 400 when malformed: `filter` echoes them; `totals` (runs, completed, an escalated run included, `needs_review` (`stats/3`), failed, never an escalated run, `runs_with_metrics`, tokens and each token kind, requests, unmetered, `cost_usd` and `unknown_cost_runs`), `time` (`wall_ms` over the ended runs, `active_ms` where metrics have it), `by_harness_effort`, `by_day` (UTC), `by_source` (`live` or the import source) and the top 20 `tools`. A run with no metrics counts in `runs` and in no token sum. `learning` (`learning/1`) counts the runs that tried to learn over the same filters, from the store ([Learning](#learning)). The query bounds `analytics` and `learning` alone. |
2905
2918
  | `GET /runs/{id}/graph` | A workflow run drawn, live: its workflow, the DSL's `workflowGraph`, each node's state (a map's items with their labels and the branch each route took for them, a route's branch), every decision with its receipt (answers, evidence, the state the judge saw, image links), every call with its input and output, and the totals (cost, null when any part is unknown). While the run goes it reads the run process's `live.json`, rewritten every 300 ms, never the run's store, which the process holds; once it ended, its store is read lock-free, so a poll never waits on it and never answers `home_busy`. An agentic run has none (`404`). |
2919
+ | `GET /runs/{id}/usage` | This server's own (`runusage/1`): what one run cost, line by line: its model requests by model and provider, its paid tool calls by who charged for them, its browser time by provider, its computers' time by provider and resource (`runusage/4`), joining to its `cost.usd` ([A run's cost, line by line](#a-runs-cost-line-by-line)); beside them its browser sessions (`runusage/2`) and the computers it made, each from its create to its proven delete (`runusage/3`). Lines once the run ended; `reason` says why there are none. |
2906
2920
  | `GET /runs/{id}/trace` | A run's trace, for a person who debugs it: each model request that answered and each tool call as one span, in the order they started. A span has its `kind` (`model` or `tool`), its `name` (the model, or the tool), when it started and ended, how it ended (`status`), and the span it ran under (`parent_id`: the request that made a call, the call a subagent's request was started by). A model request also has its `tokens` (`input` not read from cache, `cache_read`, `cache_write`, `output`, and `reasoning` where reported), and its `usd`. A tool call also has the head of its arguments and of its output, as its Timeline rows show them, and what was charged under it (`usd`, `charged`, `not_metered`). A call that asked for approval ends as its approval did: `waiting` until it is answered, `refused` on a deny, `interrupted` when it was withdrawn with its run. Nothing is measured again or estimated: `model_requests` says what the run's record keeps. `priced`: each request is a span with its cost. `tokens_only`: a workflow run. Its model nodes' requests carry tokens and no cost, since the run's cost is its booking's; each of its decisions (a judge's, a route's, a verify's request) is a span too (`decision: true`), named by the model its provider answered with and labelled by its node, with its own cost. `not_recorded`: a CLI harness's record keeps no request, so its trace is its tool calls. A computer's own time is its provider's to bill and is in no span. Readable while the run goes; one read serves the run's first 2,000 spans and counts the rest in `dropped`. Its words are cut as the Timeline's are, and a run whose handed sign-in can't be read back is refused (`403`), as its graph is. The console's Dev tools tab reads it. |
2907
2921
  | `POST /runs/{id}/pause`, `POST /runs/{id}/resume` | A workflow run: what is in flight finishes, and no node, model call or decision starts until it is resumed. Its status reads `paused`, and stays so across a server restart. An agentic run is `501`, an ended one `409`. |
2908
2922
  | `POST /workflows/validate` | `{workflow, tools?}`: every issue a save would refuse (`[{path, code, message}]`, the DSL's validation with code not run) and what this host lacks as `warnings`. Writes nothing. A refused save's `422` carries each issue as a field under `definition.workflow`, with its `code`. |
@@ -2916,7 +2930,7 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
2916
2930
  | `GET` and `POST /triggers`, `GET`, `PATCH` and `DELETE /triggers/{id}`, `POST /triggers/{id}/fire`, `GET /triggers/{id}/firings`, `POST /triggers/{id}/secret`, `POST /hooks/{id}` (no token: [signed](#webhook-triggers)) | [Schedules](#schedules), this server's own routes (`x-agentrun-serve: "trigger/1"`): schedules that start an agent's capped runs, each firing once, and their history. |
2917
2931
  | `GET /templates`, `POST /templates/{name}/apply` | [Templates](#templates), this server's own routes (`x-agentrun-serve: "templates/1"`): the template packages it ships, and an apply that makes one's agent and triggers, all or nothing. |
2918
2932
  | `POST /mcp` | This server's own route (`x-agentrun-serve: "mcp/1"`): the [MCP endpoint](#for-coding-agents), Streamable HTTP with one JSON-RPC message per POST (`initialize`, `ping`, `tools/list`, `tools/call`), answered as JSON, stateless. Its ten tools call these routes in process with the caller's token. The Bearer token only, never the page's cookie; a browser `Origin` other than this server's own is `403`; any other method is `405`. |
2919
- | `GET /usage` | The runs' costs, by meter, agent, key, day or region (`key` and `region` are one line, `local`). A run of unknown cost adds what it is known to have spent so far (its `so_far_usd`: each priced charge, browser time and paid tools included) and is counted in `unpriced_runs` (in the total and in each line it is unknown on), so no sum is ever null, it never passes as $0, and a total is never below a line of its own: with `unpriced_runs` above 0 the total is a lower bound. `basis` says how the costs were reached ([A run's cost](#a-runs-cost-its-tokens-and-its-basis)). |
2933
+ | `GET /usage` | The runs' costs, by meter, agent, key, day or region (`key` and `region` are one line, `local`). By meter, `tools` holds the runs' paid tool calls and the workflow decisions Parallel charged on its own API, as `cost.tools_usd` does. A run of unknown cost adds what it is known to have spent so far (its `so_far_usd`: each priced charge, browser time and paid tools included) and is counted in `unpriced_runs` (in the total and in each line it is unknown on), so no sum is ever null, it never passes as $0, and a total is never below a line of its own: with `unpriced_runs` above 0 the total is a lower bound. `basis` says how the costs were reached ([A run's cost](#a-runs-cost-its-tokens-and-its-basis)). |
2920
2934
 
2921
2935
  Quotes answer `501 unsupported_here` naming the feature. Home export and import (`GET` and `PUT /agents/{id}/home`) and
2922
2936
  `POST /runs/{id}/kill` are not served here: they answer `404`, and the served document leaves them out (its
@@ -2973,7 +2987,10 @@ item (`["/number", "/title", "/html_url", "/user/login"]`): `item` then keeps on
2973
2987
  serves these routes alone:
2974
2988
 
2975
2989
  - a run's launch (`POST /agents/{id}/runs`, `POST /runs`), read (`GET /runs/{id}`), lists (`GET /agents/{id}/runs`,
2976
- `GET /runs`), timeline, messages, stop, cancel, kill (`501` here, as above) and cap raise (`PATCH /runs/{id}`);
2990
+ `GET /runs`), timeline, messages, stop, cancel, kill (`501` here, as above), cap raise (`PATCH /runs/{id}`) and grade
2991
+ (`PUT /runs/{id}/grade`);
2992
+ - a run's usage lines (`GET /runs/{id}/usage`): what its `cost.usd` joins, by meter, cut of the host's secrets as the
2993
+ run's read is;
2977
2994
  - its files (`GET /runs/{id}/files`, `GET /runs/{id}/files/{path}`) and [uploads](#uploads) (`/files`);
2978
2995
  - an agent's Archil disk (`GET` and `DELETE /agents/{id}/archil`);
2979
2996
  - the [delete of an agent another system owns](#deleting-an-agent-another-system-owns) (`DELETE /agents/{id}`), for
@@ -2982,18 +2999,17 @@ serves these routes alone:
2982
2999
  key names and whether each is saved, and whether it is ready) and `GET /workspace/archil` (whether runs' folders are
2983
3000
  on Archil, and whether its account key is saved). Neither answers a key's value. Their writes, tests and key choices
2984
3001
  are the console's, refused here;
3002
+ - what an agent learned, for the backend whose runs it learned from: the loop's compile turns
3003
+ (`GET /agents/{id}/learning/loop`), each learned workflow's promotion and what serves
3004
+ (`GET /agents/{id}/learning/promotions`), the cost per run (`GET /agents/{id}/learning/cost`) and a run's learning
3005
+ (`GET /runs/{id}/learning`), each cut of the host's secrets as the console's reads are;
3006
+ - a run's hosted machine fetching this server's computerd build (`GET /computers/daemon`), with the token its create
3007
+ minted;
2985
3008
  - `GET /capabilities`, `GET /health` and `GET /usage`;
2986
3009
  - a run's desktop or phone, for a backend that shows its user the live view and lets them take over: see below.
2987
3010
 
2988
- A run's computer here takes the server's token, the backend's own, since there is no owner to sign in: `GET
2989
- /runs/{id}/computer`, `POST /runs/{id}/computer/take-over` and `POST /runs/{id}/computer/hand-back`. For its user's
2990
- browser, the backend asks `POST /runs/{id}/computer/viewer` for `{ url, expires_at }`: a link on `AGENTRUN_PUBLIC_URL`
2991
- (refused in words when it is unset) to the run's live page, with a viewer credential in its query that opens that run's
2992
- page and socket, from the public address alone, for 5 minutes. The credential is an HMAC of the run and its expiry under
2993
- a key from the seal key, so every server on the store checks it, across restarts; the run's end (completed, failed or
2994
- cancelled) revokes it and closes a socket open on it, and a stop does not, as the run goes on. The person watches, and
2995
- takes over and hands back in the viewer's own bar; nothing else opens to the credential. A server that is not API-only
2996
- answers the mint `404`, and its live page takes the owner's sign-in alone.
3011
+ Here a run's computer routes take the server's token. `POST /runs/{id}/computer/viewer` mints a 5-minute link on
3012
+ `AGENTRUN_PUBLIC_URL` that opens that run's live page and socket until the run ends (API doc).
2997
3013
 
2998
3014
  Every other address is `404 not_found`, answered before the request is read further: the console at `/` and its
2999
3015
  assets, sign-in and setup, every `/settings` route, `POST /mcp`, triggers and their
@@ -3302,9 +3318,9 @@ typed answers and their probabilities.
3302
3318
 
3303
3319
  ## Archiving
3304
3320
 
3305
- An agent made here or a run is archived, never deleted: a run's `DELETE` stays `405`, and an agent's is `409
3306
- agent_not_external` (an agent another system owns is [deleted](#deleting-an-agent-another-system-owns), and is never
3307
- archived here). These routes are this server's own, outside the `/v2` contract, like `GET /runs` and an agent's
3321
+ Archiving an agent made here or a run hides it and keeps everything of it; [purging](#purging-a-run-or-an-agent-made-here)
3322
+ removes what it was given and did, its cost kept, and an agent made here is purged only once archived (an agent another
3323
+ system owns is [deleted](#deleting-an-agent-another-system-owns), and is never archived here). These routes are this server's own, outside the `/v2` contract, like `GET /runs` and an agent's
3308
3324
  revisions; capabilities list them in `features.archive`.
3309
3325
 
3310
3326
  - `POST /v2/agents/{id}/archive` hides the agent and its runs from `GET /agents`, `GET /runs` and
@@ -3324,6 +3340,56 @@ revisions; capabilities list them in `features.archive`.
3324
3340
  already going when its agent is archived keeps going.
3325
3341
  - The store keeps an archive as `archived_at` on the agent's or the run's row, null when it is not archived.
3326
3342
 
3343
+ ## Purging a run or an agent made here
3344
+
3345
+ An owner must be able to delete what a run read. `DELETE /v2/runs/{id}` purges a run that is not live; what it cost
3346
+ stays in every total.
3347
+
3348
+ | Purged | Kept |
3349
+ | --- | --- |
3350
+ | Its launch record (input, prompt), journal and timeline, messages and commands, outputs and files, the answers kept under its idempotency keys, its folders (here, and its own folder on an Archil disk; the disk is kept), its settings, its labels and summary, its agent's grades of it, and its kept learning's content | Its row, as its tombstone: id, agent, state, how it ended (a code), started and ended, `cost_usd` (an upper bound when that is all it has), its paid tools' cost, its purge time, how its learning ended (for `/stats`), and the spend figures `/usage` and a cap read from its journal, and the intervals of the computers it made (each a provider's id and its times). Its metrics keep their figures alone: counts by tool name, the effort and the cost basis, no grader's words, call arguments or results |
3351
+ | Its kept learning's turn and proposal | Each kept learning row as a link alone (the run's and its learning run's ids, its state): `/usage`'s learning line reads it, and it keeps its learning run out of every run list |
3352
+ | What a promotion record copied from it: a check's or an audit's disagreement's input, answers and the grader's words, and the words a hold's reason quoted from them | The record's decision, numbers and run ids, the run's among them |
3353
+
3354
+ - Every route of a purged run is `410 purged`, `details` its tombstone; no run list shows it. `/usage`, `/stats` and
3355
+ the spend a cap reads are as they were. A second `DELETE` is `204`; a run never here is `404`.
3356
+ - The runs made from it are purged with it, each a tombstone: its audit's shadow run, the replay runs of its input,
3357
+ and a learning run its kept learning names. A replay or a shadow run a check or an audit starts while the `DELETE`
3358
+ runs holds it: `409 run_not_final` naming that run, the run not purged, and the next `DELETE` purges both. Once the
3359
+ run is purged, no replay or shadow run of it is started.
3360
+ - A live run (queued, working, waiting on a person or an approval, or held by a runner), or a live run made from it,
3361
+ is `409 run_not_final` (`details.runs`), nothing purged: cancel it first. A run that ended and takes a follow-up
3362
+ (idle), or that a person stopped, is not live. Such a run reads idle a moment before its runner writes it ended: a
3363
+ `DELETE` then waits for that, up to 30 seconds, and purges it.
3364
+ - A message, a trigger's message or a grade sent to the run while its `DELETE` runs waits for it, then is `410 purged`:
3365
+ nothing opens the run again or keeps a grade of it under its purge.
3366
+ - `503 unavailable` while its folder on an Archil disk is not deleted there yet: the run is not purged, and the next
3367
+ `DELETE` finishes it, as it finishes a purge that stopped part way (its purge time is set last).
3368
+ - On disk. On both stores the purge deletes or blanks the rows above; what the database files keep differs.
3369
+ - **SQLite:** every store connection writes with `secure_delete` on, which zeroes the bytes a write frees, and a run's
3370
+ or an agent's purge checkpoints the WAL once it commits. So the purged content is in neither `store.sqlite` nor
3371
+ its `-wal` after the `DELETE`. A checkpoint another connection holds back leaves the store's scrub marker
3372
+ (`store.sqlite.scrub`), and the next start's scrub truncates the log before it serves, a crash in between
3373
+ included. Copies outside the file are out of scope: backups, snapshots, the filesystem's own journal.
3374
+ - **PostgreSQL** (not closed): a purged row's old version stays in its table as a dead tuple. `VACUUM` (or
3375
+ autovacuum, on its schedule) only marks its space reusable; the bytes stay in the data file until a later write
3376
+ overwrites them. `VACUUM FULL` rewrites the table into a new file (under an exclusive lock), and the old file's
3377
+ blocks go back to the filesystem unwiped. Postgres's own WAL and its archived WAL keep the old values until they are
3378
+ recycled or expire, and backups keep them for their retention.
3379
+ - Its agent's other runs and what the agent learned from it are kept. A promotion record keeps the run's id. The
3380
+ agent's learning folder keeps what the run taught it: its merge's diff (`.agentrun/diffs/<run>.json`, with its
3381
+ patches) and any feedback line it added to `corrections.md`, in the folder's history too. The run's purge removes
3382
+ neither; the agent's purge (below) removes the whole folder.
3383
+ - It takes the owner's session (the password sign-in, or the console on a server bound to loopback) or the API token;
3384
+ any other console session is `403 forbidden`, no credential `401`.
3385
+
3386
+ An agent made here is purged the same way once archived: `DELETE /v2/agents/{id}`. Its revisions' content, name and
3387
+ description, learning, triggers, saved sign-ins, own computer, disk and folders go, and each of its runs is purged.
3388
+ Its row stays as its tombstone (id, archive and purge times): every route of it is `410 purged`, and no list shows it.
3389
+ Not archived: `409 agent_not_archived`. A live run of it: `409 run_not_final`. Purging one agent touches no other.
3390
+ An unarchive or a write to it sent while its `DELETE` runs waits for it, then is `410 purged`; after a purge stopped
3391
+ part way, each is `409 agent_not_runnable` until a `DELETE` finishes it.
3392
+
3327
3393
  ## Deleting an agent another system owns
3328
3394
 
3329
3395
  An agent made by an inline run (`POST /v2/runs` with `external`) belongs to the system that sent it, which may have to
@@ -3682,6 +3748,14 @@ round on the agent's `main`, whatever its harness:
3682
3748
  promotion check (below) decides whether it serves. A compile whose drafts all failed is recorded as the compile's
3683
3749
  attempt (compile once), and its errors are on the run's learning (`draft_errors`), never silent.
3684
3750
  [`src/learn/SPEC.md`](src/learn/SPEC.md) has the rules.
3751
+ - Its answer's quote re-pick, with `learning.repick: true` (off by default): a workflow whose answer quotes the pages
3752
+ its run fetched re-picks once when a quote is in none of them. Off, the re-pick reads its compact notes and its failed
3753
+ draft. On, the server rewrites the passing draft before it commits it, so the re-pick reads the pages themselves,
3754
+ sent as untrusted data (the model is told never to follow anything written in them, and the step has no tools), at
3755
+ most `learning.repick_max_chars` characters of them (150000 by default, 1 to 400000; past it the longest pages are
3756
+ cut first). Its request is the served run's, under the run's cost cap. The setting is read at each compile: turning
3757
+ it on or off changes only the workflows compiled after that, never one already kept. An agent whose workflows run
3758
+ through an SDK bridge ignores it.
3685
3759
 
3686
3760
  The turn runs under the run's own cap, with no reserve, and within 10 minutes; its rows are labelled `learning`, and the
3687
3761
  run's answer stays the job's. While it runs, the run reads `reflecting` on every harness. A run with no words from its
@@ -3852,10 +3926,11 @@ and says how its figure was reached.
3852
3926
  and do not change it. A native, SDK or imported run's figure is its harness's own, an `estimate`; so is an imported
3853
3927
  session's catalog estimate where its source priced none ([importing your sessions](#importing-your-sessions)). LiteLLM writes no
3854
3928
  cost into a streamed answer's headers, so a run whose answers stream through LiteLLM reads `estimate`.
3855
- - `tools_usd` (on `GET /runs/{id}` alone, `toolsusd/1`): the part of `usd` its paid tool calls cost (monid's endpoints,
3856
- MCP tools with a saved price, Parallel behind `web_search` and `web_fetch`, browser time), as the run's ledger booked
3857
- them, rounded as `usd` is. It is inside `usd`, never added to it: `usd` less `tools_usd` is what its model requests and
3858
- decisions cost. A paid call in a learning run's end-of-run turn is learning's (in `learning_usd`), never in
3929
+ - `tools_usd` (on `GET /runs/{id}` alone, `toolsusd/1`; Parallel's decisions in it since `toolsusd/2`): the part of `usd` its paid tool calls cost (monid's endpoints,
3930
+ MCP tools with a saved price, Parallel behind `web_search` and `web_fetch`, browser time, and a workflow decision
3931
+ Parallel answered on its own API, on `PARALLEL_API_KEY`, at Parallel's list price), as the run's ledger booked them,
3932
+ rounded as `usd` is. It is inside `usd`, never added to it: `usd` less `tools_usd` is what its model requests and its
3933
+ other decisions cost (Jev's, an OpenRouter model's, Parallel's model reached through OpenRouter). A paid call in a learning run's end-of-run turn is learning's (in `learning_usd`), never in
3859
3934
  `tools_usd`. 0 when it made no paid call. Null while a paid call's charge is unknown (as `usd` is then); while the run
3860
3935
  is at work (until it ended, stopped or failed); for a learning run a follow-up opened again, whose `usd` is what its
3861
3936
  first round had cost; and for an imported, native or SDK run, whose `usd` is its import's or its harness's own figure
@@ -3866,6 +3941,137 @@ and says how its figure was reached.
3866
3941
 
3867
3942
  The console shows the tokens beside the run's cost, and the figure says its basis: `$0.0042 est.`, `$0.0042 reported`.
3868
3943
 
3944
+ ## A run's cost, line by line
3945
+
3946
+ `GET /runs/{id}/usage` (`runusage/1`) says what one run cost and where each part goes: its model requests by model, its
3947
+ paid tool calls by who charged for them, its browser time by browser provider. It answers "what did this run cost, and
3948
+ whose invoice does each part land on?" for every run that books its cost: a pi run, a run on a CLI harness that sends
3949
+ its model requests through this server, and a workflow run with its decisions. The console's Dev tools tab shows it
3950
+ under "Cost by line". Each line has its quantity as measured, its dollars as the run's booking holds them, and how those
3951
+ were reached. Nothing is priced here, and nothing is rounded to a billing increment or topped up to a minimum.
3952
+
3953
+ ```json
3954
+ { "run_id": "run_…", "ended_at": "2026-11-19T10:01:30.000Z", "currency": "USD", "total": { "usd": 0.0566 }, "reason": null,
3955
+ "lines": [
3956
+ { "meter": "tokens", "model": "claude-sonnet-5-5", "provider": "anthropic", "charged_by": null, "quantity": 3300, "unit": "token",
3957
+ "basis": "reported", "usd": 0.0036, "requests": 3, "tokens": { "input": 3000, "output": 300, "cache_read": 0, "cache_write": 0 },
3958
+ "unmetered_requests": 0 },
3959
+ { "meter": "tools", "model": null, "provider": "monid", "charged_by": "monid", "quantity": 1, "unit": "call", "basis": "reported", "usd": 0.003 },
3960
+ { "meter": "tools", "model": null, "provider": "docs", "charged_by": "docs", "quantity": 1, "unit": "call", "basis": "estimate", "usd": 0.05,
3961
+ "not_metered_calls": 2 } ],
3962
+ "browser_sessions": [],
3963
+ "computer_intervals": [
3964
+ { "provider": "daytona", "provider_id": "5f0c…", "kind": "sandbox", "gpu": null, "cpus": null, "memory_mb": null,
3965
+ "started_at": "2026-11-19T10:00:04.000Z", "ended_at": "2026-11-19T10:01:31.000Z", "kept": false } ] }
3966
+ ```
3967
+
3968
+ - `tokens`: one line per model the requests were sent on (`model`; a workflow decision on the model its provider
3969
+ answered with, except a decision Parallel charged for, which is on Parallel's `tools` line). `provider` is where the requests went, named only when this server sent them there itself: the run's
3970
+ own model on a provider's key, or a decision's provider. Behind a model gateway it is null, since the gateway picks the
3971
+ upstream. A model reached two ways is two lines, one per provider. `quantity` is the input, cache read, cache write and
3972
+ output tokens as each request reported them (a decision's as its receipt does), with the split beside it; `basis` is the run's `cost.basis` rule over that model's requests alone.
3973
+ - `tools`: one line per charger (`charged_by`: `monid`, an MCP server's name, `parallel`), the vendor whose invoice the
3974
+ calls land on. `provider` names the same vendor: the one that charges for a call is its provider. `quantity` is the charges booked, one per paid call. `basis` is `reported` when every charge is the
3975
+ vendor's own figure (monid's answer says what it charged), `estimate` when any is a price this server holds (an MCP
3976
+ tool's saved price, Parallel's). A workflow decision Parallel answered on its own API (`PARALLEL_API_KEY`) is a paid
3977
+ call on the `parallel` line, beside `web_search` and `web_fetch`, at Parallel's list price for one decision request
3978
+ (`estimate`), and on no `tokens` line. A `parallel` decision sent through OpenRouter (no `PARALLEL_API_KEY`, the
3979
+ OpenRouter key) is OpenRouter's to charge, at the cost OpenRouter reported: a `tokens` line, as any decision model's. Calls of a tool with no price set ran outside the run's cost, as `GET /usage` counts
3980
+ them: `not_metered_calls`, in neither `quantity` nor `usd`.
3981
+ - `browser_time`: one line per browser provider (`provider`). `quantity` is the seconds this server's clock charged the
3982
+ provider's sessions for, the provider's minimum per session included as the browser charged it; `basis` is
3983
+ `estimate`, the provider's price per hour on this server's clock, never its invoice.
3984
+ - A field a meter does not use is null, and so is a name the record does not keep: never `""`.
3985
+ - A charge of unknown cost makes its line's `usd` null, with `so_far_usd` and `unpriced` beside it, never $0. `total`
3986
+ joins the lines by the rule `cost.usd` is, so `total.usd` is the run's `cost.usd`, with the same `so_far_usd`,
3987
+ `unpriced` and `upper_bound` beside it; the `tools` lines sum to `cost.tools_usd`.
3988
+ - Learning is not on the lines. A learning run's end-of-run turn is this server's work for the agent, not the run's
3989
+ task, and `cost.usd` leaves it out too; its spend is `learning_usd` on the run read.
3990
+ - When the lines can change: only while the run works. A follow-up opens an ended run again (a trigger's often does),
3991
+ and it ends again later. `ended_at` is the end the lines cover: keep it with them, and read again at `run.ended`, which
3992
+ fires at each end. A later read with another `ended_at`, or null, means the run moved since.
3993
+ - `lines` and `total` are null, with `reason`, while the run is at work (`running`), for a run whose figure is not its
3994
+ booking's (`not_booked`: an imported, native or SDK run, or a CLI run whose model requests went past its proxy), and
3995
+ for a learning run a follow-up opened again (`reopened`, whose booking can't be split by round).
3996
+ - `compute_time` (`runusage/4`): one line per computer provider and resource (`resource`: `vcpu`, `memory`, `gpu` with
3997
+ its `gpu_type`, `disk`), for the computers the run made. Sum a provider's lines for its one compute figure. `quantity`
3998
+ is every second of each such computer at its figure (`vcpu_second`, `gib_second`, `gpu_second`, or `gb_month` of disk
3999
+ over a 730-hour month); a computer still open is counted up to `measured_to` (`open_computers` says how many). `usd` is
4000
+ what the run's ledger booked for it while a claim held the computer, at the operator's price ([Computer
4001
+ time](#computer-time)), so `total` stays the run's `cost.usd`. The part no claim held (`unheld_quantity`: a computer
4002
+ kept past its claim for a follow-up, one deleted after its run, one whose delete failed) is in no cost. A resource with
4003
+ no price set, or whose figure no one said, is `unpriced`, its `usd` null; a provider that bills nothing (`docker`) is
4004
+ $0. A `compute_time` line that is `unpriced` and any `unheld_quantity` are outside `total`.
4005
+ ```json
4006
+ { "meter": "compute_time", "model": null, "provider": "daytona", "charged_by": "daytona", "resource": "vcpu", "gpu_type": null,
4007
+ "quantity": 348, "unit": "vcpu_second", "basis": "estimate", "usd": 0.004872, "unheld_quantity": 0, "open_computers": 0 }
4008
+ ```
4009
+ - `browser_sessions` (`runusage/2`) holds one record per browser session the run opened, in the order it opened them.
4010
+ With it you can see how long each session ran, spot one that ended late or was lost, and find each on the provider's
4011
+ own dashboard and invoice by its id: the provider's id for the session (`provider_session_id`), when
4012
+ this server opened it and let it go (`started_at`, `ended_at`), why it ended (`release_reason`), the seconds charged
4013
+ for it (`charged_seconds`, what the line sums), and the provider's own record of it, read once when it was let go
4014
+ (`provider_record`: its `started_at`, `ended_at` and `proxy_bytes`). Browserbase keeps such a record; a provider that
4015
+ keeps none says `provider_record_status: "not_offered"`, and a read that failed says `failed`, with `provider_record`
4016
+ null, never zeros. A session whose end was never recorded (its run's process lost first) has `ended_at` null.
4017
+ `charged_seconds` are the seconds charged for the session, its provider's minimum included where the browser charged
4018
+ one at the release, as on the `browser_time` line; how long it ran is `ended_at` less `started_at`.
4019
+ - `computer_intervals` (`runusage/3`) holds one record per computer the run made through its provider (a sandbox, a
4020
+ desktop or a phone), by when each was made. With it you can see how long each of the run's computers lived, find one
4021
+ left running after its run, and match the provider's invoice by its own id: the provider (`provider`, this server's
4022
+ name for it, as the agent's computer setting names it), the provider's id for the computer (`provider_id`), its
4023
+ `kind`, what it was made with (`gpu` with its `type` and `count`, `cpus`, `memory_mb`, `disk_gb`: the provider's own
4024
+ figures where its answer gave them, as Daytona's, E2B's and Fly's do, else what its create asked for; null where neither
4025
+ says, and none is guessed), how much of its time a claim held and booked (`booked_seconds`), when the create answered
4026
+ (`started_at`), and when the provider's delete of it answered ok (`ended_at`). `ended_at` is written only on that ok:
4027
+ null means no delete was proven (the computer may still be running, or its delete failed or never answered), never a
4028
+ guessed end. `kept` is true once the run's park kept the computer past its claim, for the person's answer. A computer
4029
+ is ended wherever this server deletes it: the claim's release, a later claim letting an earlier one's go, the run's
4030
+ end, a kept computer's end at its time, and the janitor's sweeps. The agent's own persistent computer (it outlives
4031
+ every run), a paired computer and `--faux`'s are not the run's and have no record; a browser's sessions are in
4032
+ `browser_sessions`. A run's computers made before this server kept them have none either. The records are kept in the
4033
+ store's `computer_intervals` table (keyed by provider and the provider's id), and a purge of the run keeps them.
4034
+
4035
+ ### Computer time
4036
+
4037
+ A computer's time is priced the way providers bill it: by what the computer holds (its vCPUs, its memory, its GPUs, its
4038
+ disk), for as long as it holds them. There are no sizes. Copy your provider's per-resource rates from its price sheet
4039
+ into these settings on the server, each in US dollars, `<PROVIDER>` being the provider as the agent's computer setting
4040
+ names it and `<GPU_TYPE>` the provider's own GPU name, both in capitals with every other character an underscore:
4041
+
4042
+ | Setting | Price of |
4043
+ | --- | --- |
4044
+ | `AGENTRUN_COMPUTE_USD_PER_VCPU_SECOND_<PROVIDER>` | one vCPU for one second |
4045
+ | `AGENTRUN_COMPUTE_USD_PER_GIB_SECOND_<PROVIDER>` | one GiB of memory for one second |
4046
+ | `AGENTRUN_COMPUTE_USD_PER_GPU_SECOND_<PROVIDER>_<GPU_TYPE>` | one GPU of that type for one second (`..._DAYTONA_H100`) |
4047
+ | `AGENTRUN_COMPUTE_USD_PER_DISK_GB_MONTH_<PROVIDER>` | one GB of disk for a month of 730 hours |
4048
+
4049
+ A price sheet that quotes by the hour divides by 3,600 (a vCPU at $0.0504 an hour is `0.000014`). What a computer holds
4050
+ is its provider's own figure where the provider's answer gives one (Daytona: vCPUs, memory, disk and GPUs; E2B and Fly:
4051
+ vCPUs and memory), else what its create asked for. Nothing is built in: a provider that bills nothing (`docker`) is $0,
4052
+ a resource set to `0` is $0 (its time booked at $0, its line `estimate` with `usd` 0), and with no setting a resource
4053
+ is unpriced.
4054
+
4055
+ - **Priced:** the run's ledger holds the computer's time under the run's `max_cost_usd`, one stretch of 5 minutes ahead,
4056
+ as a browser's time is held. A claim's computer is made while the run is set up, before its cap can judge anything:
4057
+ its first stretch is held as soon as the cap can, so the run's first model request is judged beside it, and a cap
4058
+ with no room parks the run there for a raise. A computer made later in the run (a new sandbox in place of a lost one)
4059
+ has one stretch at what its create asks for held first, and a cap with no room for it makes nothing: the run fails in
4060
+ the cap's words. Each stretch the computer ran is booked (its provider is owed it, so it is never refused) and the
4061
+ next one held, the booked stretch's hold given back first so the cap never counts a stretch twice; a cap with no room
4062
+ for the next pauses the run, as a paid tool call's refusal does, and a raise lets it go on. Before the run's end or park is written, the time since is booked and the hold let go, so the end's `cost.usd`
4063
+ holds all of it. The booked time is in the run's `cost.usd` and on its `compute_time` lines.
4064
+ - **Unpriced** (no setting, or a figure no one said): nothing is held or booked, and nothing is refused. The computer
4065
+ runs outside the cap, as a tool call with no price does, and its `compute_time` lines say `unpriced`. An operator who
4066
+ sets no compute price keeps exactly the behavior before these settings.
4067
+ - **Not held by any claim:** a computer kept past its claim for a follow-up, one deleted after its run ended (the
4068
+ seconds between the end's booking and its delete included), and one whose delete failed run on with no claim to hold
4069
+ them. Their time is on the usage read (`unheld_quantity`, and the
4070
+ interval's `booked_seconds` beside its life) but in no cap and no cost: check `computer_intervals` for such a computer.
4071
+ A computer a later claim takes back is held again from then on.
4072
+ - A run whose process keeps no ledger here (a runner of its own with no run ledger) holds and books nothing, as if
4073
+ unpriced.
4074
+
3869
4075
  ## Spend cap
3870
4076
 
3871
4077
  A run may name `max_cost_usd`, an agentic run or a workflow run ([below](#a-workflow-run-under-its-cap)). A run that names none takes its agent's default,
@@ -3877,7 +4083,11 @@ before each model request, the agent's and a compaction's alike, on every harnes
3877
4083
  what each request still in flight is held at, plus the most this request can cost must stay within it, or the
3878
4084
  request is not sent and the run pauses ([below](#a-run-paused-at-its-cap)). The cap is a hard stop for everything but
3879
4085
  the charge of a monid call priced by usage, which can pass the estimate it was held at: when it does, the run stops at
3880
- once ([monid](#monid)). A request costs its input, plus the output it
4086
+ once ([monid](#monid)). An MCP tool counts only at the price saved for it (its server's `prices`); one with none is
4087
+ not metered and bills its own account outside the cap. fal's generations are such calls: they bill your fal account at
4088
+ fal's price for the model and the output, the fal presets save no price, and the cap does not count them. A template
4089
+ that uses fal caps its fal spend itself, with an input such as `max_fal_usd` that it prices its plan against before the
4090
+ first paid call. A request costs its input, plus the output it
3881
4091
  is sent with at the output price, plus any fee its tokens do not show (below). Its input is priced at its worst case:
3882
4092
  every input token at the higher of the input and cache-write prices, since the provider may bill any of it as a cache
3883
4093
  write and a cache can miss at any request. So no request passes the cap, a cache miss included: a request costs at most
@@ -1,11 +1,12 @@
1
- import { type Store } from "./store/index.js";
1
+ import { type PurgeKept, type Store } from "./store/index.js";
2
2
  /** The delete of an agent's learning: the server's is the learning module's deleteLearning over the agent's learning
3
3
  * folder (learn/delete.ts). Idempotent; refuses with LearningInFlight while learning work of the agent is in flight. */
4
4
  export type DeleteLearning = (store: Store, agentId: string) => Promise<unknown>;
5
- /** A point of a delete a test may stop it at (AgentDeleteHost.at): after step 1, after step 2, in step 3 between a
6
- * trigger's removal upstream and its settings', between its settings' and its row's, and in step 3 once its triggers
7
- * and the agent's first run are gone. */
8
- export type AgentDeleteStep = "after_step_1" | "after_step_2" | "in_step_3_trigger" | "in_step_3_trigger_settings" | "in_step_3";
5
+ /** A point of a delete a test may stop it at (AgentDeleteHost.at). An agent's: after step 1, after step 2, in step 3
6
+ * between a trigger's removal upstream and its settings', between its settings' and its row's, and in step 3 once its
7
+ * triggers and the agent's first run are gone (a purge's: after its learning, then the same). A run's: once the runs
8
+ * made from it are purged, and once its own things outside its rows are gone (its rows kept). */
9
+ export type AgentDeleteStep = "after_step_1" | "after_step_2" | "in_step_3_trigger" | "in_step_3_trigger_settings" | "in_step_3" | "run_made_from_gone" | "run_forgotten";
9
10
  /** What a delete does outside the store's own rows, as the server does it. */
10
11
  export interface AgentDeleteHost {
11
12
  readonly store: Store;
@@ -32,19 +33,42 @@ export interface AgentDeleteHost {
32
33
  removeDisk(agentId: string): Promise<void>;
33
34
  /** A final run's things outside its rows: its folders (its own folder on an Archil disk its launch named, read from its
34
35
  * launch record, which goes with its rows after; an ApiError (503 unavailable) while that folder is not deleted
35
- * there), its settings, the answers kept under its idempotency keys. */
36
- forgetRun(agentId: string, runId: string): Promise<void>;
36
+ * there), its settings, the answers kept under its idempotency keys. `alone`: its agent's Archil disk stays (a run's
37
+ * purge, or its agent's), so its own folder on that disk is deleted there too; with an external agent's delete that
38
+ * disk went whole. */
39
+ forgetRun(agentId: string, runId: string, alone: boolean): Promise<void>;
37
40
  /** The agent's things outside its rows: its folders, its settings, the answers kept under its idempotency keys. */
38
41
  forgetAgent(agentId: string): Promise<void>;
39
- /** How long step 1 waits for the agent's runs to be final, and how often it reads them meanwhile. */
42
+ /** The runs made from run `runId` (store runs.madeFrom, and its audit's shadow run), by id, whether there or not. */
43
+ madeFrom(runId: string): Promise<string[]>;
44
+ /** What agent `agentId`'s learning copied from run `runId`, gone: the grades it keeps of the run dropped, its promotion
45
+ * records' disagreements naming the run blanked, their decisions, numbers and run ids kept (learn/promote.ts
46
+ * forgetRunCopies). */
47
+ forgetCopies(agentId: string, runId: string): Promise<void>;
48
+ /** What run `runId`'s spend reads from its journal, read before its purge removes it (store-reads/cap.ts). */
49
+ kept(runId: string): Promise<PurgeKept>;
50
+ /** Whether run `runId`'s turn is over (it reads idle, a paused workflow aside): its runner writes it final next. */
51
+ turnOver(runId: string): Promise<boolean>;
52
+ /** How long step 1 waits for the agent's runs to be final (a purge: for a run whose turn is over), and how often it reads
53
+ * them meanwhile. */
40
54
  readonly waitMs: number;
41
55
  readonly pollMs: number;
42
- /** A test's seam: awaited at each step's point, so a throw there stops the delete as a crash would. */
43
- at?(step: AgentDeleteStep, agentId: string): void | Promise<void>;
56
+ /** A test's seam: awaited at each step's point with the agent's id (a run's step: the run's), so a throw there stops
57
+ * the delete as a crash would. */
58
+ at?(step: AgentDeleteStep, id: string): void | Promise<void>;
44
59
  }
45
60
  /** Deletes agent `agentId` (another system's, as the route checked) in the three steps above. Throws ApiError
46
61
  * runs_in_flight while a run of it is not final by the wait's end, learning_busy while its learning refuses. */
47
62
  export declare function deleteExternalAgent(host: AgentDeleteHost, agentId: string): Promise<void>;
63
+ /** Purges archived agent `agentId`, made here (as the route checked), as the header says: 409 run_not_final, nothing
64
+ * purged, while a run of it is live; learning_busy while its learning refuses. */
65
+ export declare function purgeAgent(host: AgentDeleteHost, agentId: string): Promise<void>;
66
+ /** The setting that marks agent `agentId`'s purge begun and not finished (purgeAgent). */
67
+ export declare const purgingKey: (agentId: string) => string;
68
+ /** Purges run `runId` with every run made from it, as the header says. 404 not_found when it is not there; 409
69
+ * run_not_final, nothing purged, while it or a run made from it is live. A purged run is no work. */
70
+ export declare function purgeRun(host: AgentDeleteHost, runId: string): Promise<void>;
48
71
  /** 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
49
- * finishes what the first left. */
50
- export declare function oneAtATime(): <T>(agentId: string, work: () => Promise<T>) => Promise<T>;
72
+ * finishes what the first left. `queued`, a test's seam: told each time a work waits behind another of its agent's,
73
+ * with how many of that agent's wait now (the one running not counted). */
74
+ export declare function oneAtATime(queued?: (agentId: string, waiting: number) => void): <T>(agentId: string, work: () => Promise<T>) => Promise<T>;