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

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 (146) hide show
  1. package/CHANGELOG.md +147 -0
  2. package/README.md +142 -17
  3. package/dist/agents-store.js +7 -3
  4. package/dist/api-only.d.ts +2 -1
  5. package/dist/api-only.js +3 -2
  6. package/dist/capacity.d.ts +50 -0
  7. package/dist/capacity.js +49 -0
  8. package/dist/cli-learning/claude-wire.d.ts +41 -0
  9. package/dist/cli-learning/claude-wire.js +258 -0
  10. package/dist/cli-learning/cli.d.ts +11 -0
  11. package/dist/cli-learning/cli.js +241 -0
  12. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  13. package/dist/cli-learning/codex-worktree.js +119 -0
  14. package/dist/cli-learning/connections.d.ts +62 -0
  15. package/dist/cli-learning/connections.js +87 -0
  16. package/dist/cli-learning/entry.d.ts +1 -0
  17. package/dist/cli-learning/entry.js +4 -0
  18. package/dist/cli-learning/evidence.d.ts +78 -0
  19. package/dist/cli-learning/evidence.js +492 -0
  20. package/dist/cli-learning/hook.d.ts +33 -0
  21. package/dist/cli-learning/hook.js +544 -0
  22. package/dist/cli-learning/install.d.ts +33 -0
  23. package/dist/cli-learning/install.js +335 -0
  24. package/dist/cli-learning/observation-proof.d.ts +14 -0
  25. package/dist/cli-learning/observation-proof.js +10 -0
  26. package/dist/cli-learning/policy.d.ts +48 -0
  27. package/dist/cli-learning/policy.js +363 -0
  28. package/dist/cli-learning/schema.d.ts +16 -0
  29. package/dist/cli-learning/schema.js +27 -0
  30. package/dist/cli-learning/state.d.ts +23 -0
  31. package/dist/cli-learning/state.js +61 -0
  32. package/dist/cli.js +24 -2
  33. package/dist/console/assets/index-Bt1B51b7.js +733 -0
  34. package/dist/console/assets/index-sVftE9Ht.css +1 -0
  35. package/dist/console/index.html +2 -2
  36. package/dist/email/email-faux.d.ts +3 -1
  37. package/dist/email/email-faux.js +3 -2
  38. package/dist/email/routes.js +22 -12
  39. package/dist/harness-install.d.ts +6 -2
  40. package/dist/harness-install.js +40 -8
  41. package/dist/harness.d.ts +1 -1
  42. package/dist/harness.js +2 -2
  43. package/dist/learn/secrets.js +14 -3
  44. package/dist/learning-words.d.ts +1 -1
  45. package/dist/learning-words.js +1 -1
  46. package/dist/mcp-pin-first.js +2 -1
  47. package/dist/mcp-private-hosts.d.ts +24 -3
  48. package/dist/mcp-private-hosts.js +53 -3
  49. package/dist/model-gateway.d.ts +2 -0
  50. package/dist/model-gateway.js +3 -1
  51. package/dist/native/runtimes.d.ts +2 -0
  52. package/dist/native/runtimes.js +2 -0
  53. package/dist/observation/learning.d.ts +32 -0
  54. package/dist/observation/learning.js +66 -0
  55. package/dist/observation/observer.d.ts +8 -1
  56. package/dist/observation/observer.js +89 -9
  57. package/dist/observation/schema.js +12 -4
  58. package/dist/observation/usage-identity.d.ts +9 -0
  59. package/dist/observation/usage-identity.js +11 -0
  60. package/dist/openapi.js +89 -13
  61. package/dist/run-launch.d.ts +14 -0
  62. package/dist/run-launch.js +4 -0
  63. package/dist/run-view.d.ts +2 -0
  64. package/dist/run-view.js +12 -7
  65. package/dist/runner/adapter-loop.js +29 -26
  66. package/dist/runner/adapter-run-spec.js +2 -2
  67. package/dist/runner/beside.d.ts +13 -0
  68. package/dist/runner/beside.js +27 -8
  69. package/dist/runner/cli-run-spec.js +2 -2
  70. package/dist/runner/disk-free.d.ts +44 -0
  71. package/dist/runner/disk-free.js +96 -0
  72. package/dist/runner/feedback-round.d.ts +12 -8
  73. package/dist/runner/feedback-round.js +16 -30
  74. package/dist/runner/harness-loops.js +3 -1
  75. package/dist/runner/journal-kinds.d.ts +1 -1
  76. package/dist/runner/learning-end.js +4 -0
  77. package/dist/runner/main.d.ts +17 -6
  78. package/dist/runner/main.js +187 -45
  79. package/dist/runner/presence.d.ts +11 -2
  80. package/dist/runner/presence.js +31 -3
  81. package/dist/runner/run-child-host.d.ts +12 -15
  82. package/dist/runner/run-child-host.js +46 -108
  83. package/dist/runner/run-errors.js +2 -0
  84. package/dist/runner/runner-check.d.ts +51 -0
  85. package/dist/runner/runner-check.js +206 -0
  86. package/dist/runner/runner-metrics.d.ts +19 -0
  87. package/dist/runner/runner-metrics.js +49 -0
  88. package/dist/runner/runner.d.ts +37 -0
  89. package/dist/runner/runner.js +43 -3
  90. package/dist/runner/sdk-loop.js +34 -22
  91. package/dist/runs-over-store.d.ts +8 -1
  92. package/dist/runs-over-store.js +57 -9
  93. package/dist/sdk/runs.d.ts +22 -2
  94. package/dist/sdk/runs.js +103 -34
  95. package/dist/server.d.ts +3 -0
  96. package/dist/server.js +149 -26
  97. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  98. package/dist/start-switches.js +2 -0
  99. package/dist/stats.d.ts +4 -0
  100. package/dist/stats.js +1 -1
  101. package/dist/store/agent-body.d.ts +12 -0
  102. package/dist/store/agent-body.js +16 -2
  103. package/dist/store/dialect.d.ts +2 -0
  104. package/dist/store/dialect.js +1 -0
  105. package/dist/store/index.d.ts +3 -3
  106. package/dist/store/index.js +2 -2
  107. package/dist/store/postgres/connection.d.ts +5 -2
  108. package/dist/store/postgres/connection.js +19 -7
  109. package/dist/store/postgres/dialect.js +1 -0
  110. package/dist/store/postgres/migrate.d.ts +30 -0
  111. package/dist/store/postgres/migrate.js +72 -5
  112. package/dist/store/postgres/migration-lint.d.ts +8 -0
  113. package/dist/store/postgres/migration-lint.js +119 -0
  114. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  115. package/dist/store/postgres/store.d.ts +8 -3
  116. package/dist/store/postgres/store.js +31 -11
  117. package/dist/store/schema.d.ts +18 -1
  118. package/dist/store/schema.js +33 -2
  119. package/dist/store/sqlite/run-launch.d.ts +9 -1
  120. package/dist/store/sqlite/run-launch.js +44 -0
  121. package/dist/store/sqlite/store.d.ts +17 -0
  122. package/dist/store/sqlite/store.js +87 -10
  123. package/dist/store/store-schema.d.ts +34 -0
  124. package/dist/store/store-schema.js +125 -0
  125. package/dist/store/store.d.ts +53 -1
  126. package/dist/store/store.js +13 -0
  127. package/dist/store-reads/analytics.d.ts +3 -2
  128. package/dist/store-reads/analytics.js +20 -8
  129. package/dist/store-view.d.ts +4 -3
  130. package/dist/store-view.js +11 -7
  131. package/dist/templates.d.ts +3 -2
  132. package/dist/tool-gate.d.ts +4 -2
  133. package/dist/unified-usage.d.ts +24 -0
  134. package/dist/unified-usage.js +400 -0
  135. package/dist/uploads-archil.d.ts +100 -0
  136. package/dist/uploads-archil.js +430 -0
  137. package/dist/uploads.d.ts +55 -1
  138. package/dist/uploads.js +185 -98
  139. package/dist/validate.js +1 -1
  140. package/dist/workspace/archil-disk.d.ts +6 -5
  141. package/dist/workspace/archil-disk.js +27 -12
  142. package/dist/workspace/archil.js +3 -2
  143. package/package.json +10 -10
  144. package/skills/agentrun-serve/SKILL.md +52 -7
  145. package/dist/console/assets/index-D0mr9wfZ.css +0 -1
  146. package/dist/console/assets/index-D7G6o-1E.js +0 -720
package/CHANGELOG.md CHANGED
@@ -2,6 +2,153 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 0.1.0-beta.51 (2026-11-21)
6
+
7
+ **Breaking:**
8
+
9
+ - A pending approval says why a call its setting allows asks in a field of its own, `asks_because` (on `pending` of GET /runs/{run_id} and the run list), and no longer among the call's arguments: `args_preview` is the model's arguments alone, with no `asked_because` key, and `summary` no longer ends "Asks because ...". A client that read the reason from `args_preview`'s `asked_because` (or from the end of `summary`) breaks: read `asks_because` instead, absent on a call that asks by its setting. The console's approval card, on the run page and on Mission Control, says "Asks because <why>." above the arguments' box. <!-- changes/approval-asks-because.md -->
10
+ - A runner can run on a disk of its own, and `runner --check` checks its environment by name. A runner with `AGENTRUN_STORE_URL`, `AGENTRUN_SEAL_KEY` and a local `--data` never reads the server's data directory: in Mode 2 (Archil settings saved) it runs every run; while the server is in Mode 1 it claims nothing and says why, on its log and to the server, which refuses a new run in those words (`503 runner_refused`) while no runner on its own data directory is there. The mode is the server's (its saved settings, or the Archil settings in its own environment), never the runner's. The runner never fails the run itself. The server tells the disks apart by an id it keeps in `/data/data-root.id` and says in the store at each start, beside the names (never the values) of its run-facing environment. <!-- changes/disk-free-runner.md -->
11
+ What breaks: `runner --check --data D --name N` now also checks the runner's environment (the store opens, the seal key is the store's, the runner holds every run-facing name the server holds, an upstream on loopback answers) and fails on any gap. A health check run with an empty environment (compose's `env -i`) now fails: run it with the container's environment (the check prints names, never values), or use `runner --check --heartbeat --data D --name N` for the heartbeat alone. `runner --check --env [--data D]` checks the environment alone, before a runner starts. Not yet on a disk of its own: screen recordings. See deploy/README.md, "A runner on a disk of its own".
12
+
13
+ **Changes:**
14
+
15
+ - A disk removed at Archil while a run is on it now fails that run's next disk call as the disk being gone (`UNAVAILABLE`, in Archil's words), not as a missing file. <!-- changes/archil-disk-gone-midrun.md -->
16
+ - Email: Save signs in before it keeps the account, and the console opens and makes email triggers. <!-- changes/email-save-signs-in.md -->
17
+ - Behavior change: `PUT /v2/settings/email` signs in to IMAP and SMTP first, as Test does, sending nothing. If either refuses or can't be reached, it answers 424 `upstream_failed` with `details.imap` and `details.smtp` (each `{ok, message}`) and saves nothing, keeping any account saved before. It used to save any password. A body that doesn't read is still 422 by field, before any sign-in. The console's Save shows the refusal beside the form.
18
+ - Public API addition: the apply answer (`POST /v2/templates/{template}/apply`, Apply and Update) carries `agent_change`: `made`, `updated` (a new revision written) or `unchanged` (an update with `agent_id` whose package and parameters the current revision already holds, no revision written), with `revision_version` the agent's current revision once it is done. It also carries `triggers`, every trigger the apply made or kept, in the package's order, each `{trigger_id, name, kind, enabled}`; `trigger_ids` is unchanged. The TypeScript and Python clients' `ApplyTemplateResponse` gain both. The console's Apply and Update result lists each trigger by its name and kind in words, on or off, an email trigger beside its schedules (a schedule keeps its line and next time); it used to list the schedules alone.
19
+ - An email trigger's page opens in the console: the account and mailbox it watches, how often, its last check, its filter, its agent and its firings, with Pause, Run now and Delete. It carries the same "Waits for your approval" warning the other triggers' pages do when its agent has a tool that asks (refused, with accounts off), and Run unattended. It used to say the page didn't open it yet.
20
+ - Triggers → New makes an email trigger (`#/triggers/new-email`), beside the schedule, webhook, GitHub, app and feed forms: its agent, mailbox (INBOX unless changed), how often it reads, what each run is asked, its cost cap and whether it is on, with the same approval warning and Run unattended. With no account saved it says so and links to Settings → Email. An email trigger used to be made through the API or a template alone.
21
+ - A template's apply result, on Templates and in the API playground, says from the answer's `agent_change` what the apply did: an update that changed nothing reads "Nothing to update: rev 2 is current.", never that the agent is made or applied. <!-- changes/lookback-tidy.md -->
22
+ The console also:
23
+ - Takes a run with only a field for an agent whose `input_schema` fields are all optional, as the server does, and says a refusal of neither at the message box. Filling a field clears the server's issue at the message only where the message is optional; a required message keeps its issue until it is fixed.
24
+ - Offers the Grade form on an ended run whose learning reads `reflecting`, and says a `409 run_learning` in the server's words, keeping the choice.
25
+ - Says on every tool row of a template's install page that the template asks you to grant it, and on a tool whose `asks` is `ask` that each call waits for your OK unless you allowed it in Settings or pick Never ask; no listed tool reads as one the template does not ask for.
26
+ - Says on a Triggers row, of any kind, whose agent has tools that ask "Waits for your approval: <tools>" (or "Refused without your approval" with accounts off), as the trigger's page does, reading each agent once.
27
+ - Names each trigger's agent on Triggers when the agent was made after the console opened (a template applied from a URL makes one with its triggers): the agents' names are read again each time Triggers opens, as Runs and Mission Control read them. It used to show the agent's id.
28
+
29
+ A look-back cut by a stop or cancel is said as "a stop or cancel cut it while it wrote what it learned", and the learning state's `reflecting` description names the run's end it reads.
30
+ - A run whose revision ships skills no longer fails at its claim on a fresh Mode 2 (Archil) folder with `".agents/skills" is not there` when it runs in its own process. A `WorkspaceError` now crosses the run's channel as a `WorkspaceError` with its `code`, as the other run errors do, so `layOwnSkills` (and every other check of `instanceof WorkspaceError` in the run's process) reads a missing folder as `NOT_FOUND` again. Runs in the runner's process were not affected. <!-- changes/run-process-workspace-error.md -->
31
+ - A runner that holds many customers' runs keeps per-run users without putting its own user in 256 groups, and its operator can stop owners from allowing private-network hosts (`AGENTRUN_PRIVATE_HOSTS`). See [docs/multi-tenant-runners.md](https://github.com/Parcha-ai/agentrun/blob/main/docs/multi-tenant-runners.md) for the threat model. <!-- changes/runner-per-run-users-one-group.md -->
32
+
33
+ - In the image, the server's user (node) is now in one group, its own, and in no slot's group. A platform that reads a user's groups at start (Northflank's environment injector refused node's 257 groups) can run the image with per-run users on, so `AGENTRUN_RUN_USER=same` is no longer needed there.
34
+ - A run's folders are given to its slot before it starts (`agentrun-runas own <slot>`: the slot's uid, node's group, folders `2770` with the setgid bit) and back to node at its end (`own runner`). The server reads a running run's files through its one group; no other slot can enter them, nor the slot's next run. The helper gains `cap_chown` (kept alone while it gives folders, each entry changed through a descriptor opened without following a link); `reown` and `reap --fix` are gone. A give-back that fails retires the slot, as a reap that does not hold does.
35
+ - A run that shuts one of its folders (`chmod 700`, which drops its setgid bit) hides it from the server until the run ends.
36
+ - `AGENTRUN_PRIVATE_HOSTS` bounds the private-network hosts an owner may allow an MCP server or a calendar on (Settings → MCP servers). Unset, the owner's list holds, as before. `none` reads no owner's list and saves only an empty one (422, naming the switch, otherwise): set it on a server or runner many customers share, and on each runner, which reads its own environment and says the bound at its start. A comma list of address ranges (`10.20.0.0/16,fd12:3456::/32`) allows a listed host only inside them. A value that is neither reads as `none`. `GET /v2/capabilities` lists it under `switches`.
37
+ - `GET /v2/capacity` (`capacity/1`) says how much room the runners have, read from the store alone, so a server with no runner beside it (`--no-runner`, `AGENTRUN_API_ONLY=1`, where it is served too) answers for every runner on its store. It gives the runs waiting for a runner (`runs.queued`: queued, handed back, or with a claim that ran out, past any backoff) and the runs a live claim holds (`runs.executing`). It lists each live runner by name with its build's `version`, its `slots` (the most runs it holds at once), what it holds (`executing`) and its `free_slots`, plus the total `free_slots`. It counts the runs handed back still running within `?window=` minutes (`hand_backs`: 1 to 1440, default 15). It names no run, agent or address, and it takes the server's token like every route but capabilities and health. An operator or a scaler reads it to size the runners by backlog, not CPU. <!-- changes/runner-capacity.md -->
38
+ Each runner's row now says its version and slots (`runners.version`, `runners.slots`), and every release that leaves its run running writes a row to a new `hand_backs` table, kept for a day. Postgres migration `0024_runner_capacity.sql` adds both, and a SQLite store gets them at the server's open. Both are additive. A runner of an earlier build that is already running keeps working, with its version and slots read as null. On SQLite, one also starts again as before. On Postgres, a runner of an earlier build that starts after the migration refuses the store, as for any migration it does not know: upgrade Postgres runners with the server. A runner of this build waits on SQLite for a server that added them.
39
+ A runner prints metric lines in the server's log format (`at=… event=… key=value`), so a log-based metric can count them: `runner_claimed`, with `took_over=1` when it took over a run whose lease ran out; `runner_hand_back` with a `cause` (`drain`, `interrupted`, `end_retry`, `give_back`, or `claim_lost` with its `why`); `runner_drained` (`ms`, `held`, `left`), once per close that held a run; and `runner_gauge` every minute (`active`, `slots`, `rss_mib`). The existing `Runner … claimed` and `ready` lines are unchanged. A runner beside a server prints the same lines where the server prints its own.
40
+ - A runner on Postgres no longer needs the store's schema to match its own version exactly. The server can migrate first while the earlier release's runners keep running, as long as the migrations are additive. Each store keeps a runner floor: the oldest schema version a runner's build must know. A migration marked `-- runners: breaking` raises the floor to its own version. Every runner reads the floor again every 10 s, whether or not it holds runs. When the floor rises above its version, it claims nothing more, drains, hands its runs back and exits 3. A runner that starts below the floor exits 3 and says to run a runner of the server's release. A runner on a store its server has not migrated yet still exits 3, as before. Runners of earlier releases still need an exact match, so roll this release's runners with its server as before; from this release on, a runner keeps running beside the next releases' additive migrations. <!-- changes/runner-floor.md -->
41
+ - `agentrun-serve store-schema [--data DIR]` prints the store's schema version and runner floor beside this build's version, and what this build's server and runner do on that store, as one line of JSON. It reads only: no lock, no migration. `--build` prints the build's own versions with no store. `GET /v2/capabilities` carries the same live values in `store_schema` (`version`, `runner_floor`, `known`), for a deploy check that refuses a build older than its store.
42
+ - A Postgres migration that drops or renames anything, changes a column's type, makes a column NOT NULL, or adds a NOT NULL column with no default must carry the `-- runners: breaking` header. A test fails one that does not. Migrations up to 0022 predate the rule and count as breaking; 0023, the first the lint reads, is additive. A SQLite runner still opens only its own schema version.
43
+ - With Archil on (Mode 2), uploads live on Archil and the server places a run's files in its folder at the run's start, so a runner reads no upload and needs no disk of the server's. `POST` and `PUT /v2/files` keep each file on the server's own uploads disk, `agentrun-<server id>-files` (made by the first upload), at `files/<file_id>/`, and listing, reading and deleting read it there. A run started with `file_ids` has each file copied into its folder at `work/inputs/<path>` before it is queued (2 files at a time across every start on the server, at most 45 s). Its launch records `files_placed` and the disk it used, and its claim copies nothing. A copy that fails refuses the start with `424 upstream_failed` in words, and no run is made. <!-- changes/uploads-on-archil.md -->
44
+ In Mode 2, an uploaded file that no run names is deleted after `AGENTRUN_UPLOAD_RETENTION` (default `7d`, or `off`), swept hourly (`event=uploads_expired`). Mode 1 is unchanged: uploads stay in `DIR/files/`, are copied in at the claim, and are never deleted. Files uploaded under one mode are not seen under the other.
45
+ - Connect independently started Codex CLI and Claude Code sessions with `learning connect`, without <!-- changes/existing-cli-learning.md -->
46
+ an SDK wrapper or replacing the source task launcher. Hooks record completed prompt windows and
47
+ reported usage; later prompts receive pinned owner corrections from AgentRun. Source task dialogue
48
+ never becomes a standing correction automatically. Source hooks do not expose a workflow execution
49
+ bridge or launch extra native reflection sessions. Retired automatic notes and skills stay on disk
50
+ but are not served or converted to owner corrections. Existing CLI profiles with a stored
51
+ `learning: "notes"` setting read as enabled under the current learning model; new definitions use
52
+ its boolean or loop settings.
53
+
54
+ Connection credentials are scoped, installation preserves unrelated hooks, and disconnect removes
55
+ only its own hooks. Incomplete evidence and cancellations stay explicit. The console offers capture
56
+ and correction delivery enrollment for existing applications while execution and editing stay in
57
+ their original setup. Initial enrollment requires a local AgentRun server and the selected CLI's
58
+ sign-in; metadata observation alone does not enable it.
59
+
60
+ Private pending capture journals are bound to their destination and credential generation. A reconnect
61
+ starts a fresh journal; prior or unbound records remain on disk and are not automatically migrated,
62
+ uploaded or deleted. `learning retry` reports `blocked_journals` and exits with status 1 when those
63
+ records need review.
64
+
65
+ Disconnect disables local capture before removing hooks or contacting the server. If server revocation is
66
+ pending, loaded hooks and retries stay disabled until disconnect completes; status exposes `capture_enabled`.
67
+ Retries advance across retained sessions, queued hooks and unfinished turns so older entries cannot indefinitely
68
+ hide later uploads. Interrupted connection commands recover an abandoned lock while a live owner keeps it.
69
+ Recovery also recognizes a proven previous kernel boot on the same host. A different namespace from the
70
+ same boot, or an unknown boot identity, stays protected until its owner's death can be established.
71
+ Project installer and shared Codex hook locks now keep private owner records and recover after a proven
72
+ owner death. Legacy empty or malformed installer locks stay protected regardless of age; the error names
73
+ the lock and requires stopping and verifying all relevant installers before manually removing that lock.
74
+ - Observe token usage from already-running Codex sessions without restarting their native processes. Polling subscriptions follow loaded interactive, exec and delegated sessions; explicitly selected historical sessions remain available. Input, output and reported cache counters use native model metadata and source UTC dates, with cumulative baselines, atomic local checkpoints and sequence deduplication preventing duplicate accounting. <!-- changes/existing-codex-polling-usage.md -->
75
+
76
+ Polling usage requires the receiver’s advertised capability. Existing lifetime totals are not backfilled; missing counters, tail gaps and queue drops remain partial coverage. Conversation content stays local, existing learning consent is unchanged, and OTLP ingestion keeps its existing behavior.
77
+
78
+ Selected failed sessions remain eligible for bounded usage polling, so counters flushed after Codex reports a system error are retained. Acknowledged counters are not counted again after another poll or a connector restart.
79
+ - The CLI capture API uses `agentrun cli-learning enroll|list|revoke|start|get|events|complete`. <!-- changes/cli-capture-command-routing.md -->
80
+ Its earlier generated `CLI learning` group was one word internally and did not accept the documented
81
+ invocations. The generated TypeScript resource is `cliLearning` with the same verbs, and Python uses
82
+ `cli_learning`; API paths and operation IDs are unchanged. The local `learning connect`, `status`,
83
+ `disconnect`, `retry` and `hook` commands and the existing learning API commands keep their routes.
84
+ - Keep delayed CLI hook retries in source order. An older queued submit or session ending cannot <!-- changes/cli-capture-retry-boundaries.md -->
85
+ interrupt a newer prompt. When earlier dialogue cannot be ordered safely, retain it privately and
86
+ mark the capture incomplete instead of presenting it as prior context.
87
+
88
+ Bound newly captured prompts, answers and dialogue to the server's text and event limits, including
89
+ after secret redaction. Truncated evidence remains explicitly incomplete and can be uploaded instead
90
+ of retrying an oversized request indefinitely. Already frozen historical requests remain unchanged
91
+ because an uncertain earlier upload may have committed their immutable payloads.
92
+
93
+ Serialize session journals with the existing token-fenced ownership lock. Concurrent recovery of a
94
+ dead owner cannot remove a new owner's lock. Legacy empty or PID-only locks remain pending rather
95
+ than being removed on age alone; remove such a lock only after confirming no hook or retry process
96
+ still owns that journal.
97
+
98
+ A pending local disconnect no longer advertises learning as ready while hook removal or remote
99
+ revocation is blocked. The connector withholds its readiness proof until the connection is active.
100
+ - Install Codex learning hooks in linked worktrees through the main-checkout `hooks.json` that native <!-- changes/cli-learning-worktree-hooks.md -->
101
+ Codex actually loads. Reconnecting migrates unchanged owned hooks without changing the learning
102
+ connection or credential. Shared-file locking and stable hook group positions preserve other enrolled
103
+ projects and their native trust keys; worktree-local TOML stays untouched. Observation readiness checks
104
+ the derived shared configuration and does not mark ignored local hooks ready. Modified configuration,
105
+ invalid Git ownership and size overflow fail without replacement; interrupted migrations retain both
106
+ ownership records for safe disconnect. Loaded Codex project configuration requires a new or reopened
107
+ session before hooks activate. A nested linked worktree cannot also learn through its enclosing checkout.
108
+ - Capture reported token usage for new Codex and Claude Code CLI learning prompts, deduplicating native response records within each prompt. The dashboard's unified `analytics.usage` includes retained source observations and recorded runs, using verified session identity to group potentially overlapping usage. When exact overlap is unavailable, the total keeps the larger coherent source or recorded view as a lower bound, with incomplete coverage explicit. A stale or zero source report cannot erase a larger completed prompt total; distinct immutable CLI turns can sum, while upload dates alone do not prove separate native execution. Range and session filters apply to the combined total; unavailable cache breakdowns, partial boundary days, missing reports and the 90-day source retention limit stay explicit. Unbound observation identities cannot be matched to separately recorded runs. Missing, ambiguous or incomplete prompt usage remains unknown; existing run completions are not rewritten. An enabled CLI learning profile with no recorded prompts explains that its next source prompt starts capture and that earlier conversations are not imported automatically. <!-- changes/cli-prompt-usage-coverage.md -->
109
+
110
+ The dashboard and Agents page share one connected-agent inventory. Source sessions and AgentRun agents appear together, including profiles awaiting their first captured prompt, and the separate observed-session sections are removed. Selecting a source session filters its reported usage without treating the session as a completed run or requesting a server-agent run endpoint.
111
+
112
+ Ordinary analytics reads project the saved accounting and identity fields instead of transferring full CLI policies and SDK replay records. Historical identity still selects the right source usage across date ranges. PostgreSQL records containing unsupported Unicode escapes retain the earlier JavaScript parsing path for that record, preserving their counters and exact native identity. Unexpected accounting read failures are surfaced by the usage endpoint.
113
+ - Show connected coding agents in the same searchable inventory and count as registered agents, with <!-- changes/connected-agent-inventory.md -->
114
+ project, session, model, activity and token details. Preserve loaded cards when another source is
115
+ loading or unavailable, and exclude nonarchivable connections from the archived view.
116
+
117
+ Identify coding sessions by their native title, project basename or delegated task name, with a stable
118
+ ID suffix for unnamed sessions. Names refresh even while idle. The observer sends bounded labels only
119
+ to receivers advertising support; prompts, conversation previews, full paths and obvious credentials
120
+ are excluded. Token accounting and selection scopes stay unchanged.
121
+ Unicode labels respect queue and delivery byte limits so long multilingual names cannot stall delivery.
122
+ - Give connected coding sessions the same card layout and coding-agent Run/Edit handoffs as other <!-- changes/connected-agent-learning-controls.md -->
123
+ agents, with learning status and setup or settings actions. Project learning connections remain
124
+ available in Learning Dojo but no longer appear as duplicate agents in the active inventory.
125
+
126
+ The connector can associate a session with an existing project/runtime learning connection using
127
+ its installed hook receipt and a scoped proof. Learning is shown as on only after that exact session
128
+ has reported a hook window and the server and project settings allow learning. Missing setup,
129
+ unverified activation and unsupported delegated sessions remain explicit. Revoked or invalid proofs
130
+ do not grant access or prevent ordinary activity and token reports. This does not install hooks,
131
+ enroll additional projects, import conversations or change how coding sessions are started.
132
+ - Dashboard and agent analytics show exact, comma-separated token totals, input and output counts whenever they fit. Counts adapt to the actual column width and font, using compact notation only when needed. The full number remains available on hover and to screen readers when abbreviated. <!-- changes/console-exact-token-counts.md -->
133
+ - The dashboard and agent analytics show Input and Output counts beneath the token total. Input includes cached tokens, including when a connected source reports total and output usage without a cache breakdown. Missing counts display a dash, and genuine zero counts remain zero. The token card no longer shows cache percentages or model-request diagnostics; incomplete coverage and history limits remain visible. <!-- changes/console-token-breakdown.md -->
134
+ - Show Mission Control's activity and token-usage charts directly below the main agent and run counts, <!-- changes/mission-analytics-placement.md -->
135
+ before the observed-session summary.
136
+ - Keep verified session identity privately beside retained observation usage, independently of current <!-- changes/observation-usage-identity.md -->
137
+ learning readiness. Disconnecting, replacing credentials, or receiving an older client's activity
138
+ no longer counts observed tokens separately from the same session's captured runs. Existing verified
139
+ associations migrate when another observation arrives; the accounting identity grants no learning
140
+ authorization and is removed with the retained session.
141
+
142
+ If an earlier disconnect already discarded the verified identity, it cannot be reconstructed. Where
143
+ unidentified observations may overlap recorded native runs, usage compares the complete native view
144
+ with each collector's complete observation view and reports a conservative total with incomplete
145
+ coverage. It does not add possibly overlapping collectors or infer an identity from unverified fields.
146
+
147
+ A verified report that tries to assign a different native identity to an already identified observed
148
+ session is refused with `409 connector_session_identity_conflict`. The entire batch remains uncommitted,
149
+ including its usage and receipts; distinct native sessions must use distinct external session IDs.
150
+ - Template packages such as Inbound Lead and KYB accept and retain their `learning.agree_on` settings through import, apply and later edits. A learned workflow's promotion check and shadow audit compare the declared answer fields, with each dotted path required in the template's output schema; a missing path disagrees. Without `agree_on`, the existing whole-answer comparison remains. The console and API describe which fields the check compared. <!-- changes/template-learning-compat.md -->
151
+
5
152
  ## 0.1.0-beta.50 (2026-11-20)
6
153
 
7
154
  - 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 -->
package/README.md CHANGED
@@ -10,16 +10,30 @@ runner starts beside the server. The capabilities document (`GET /v2/capabilitie
10
10
  Already use Claude Code or Codex? Choose **Connect agent** in the console and select your coding agent from the
11
11
  dropdown. Its skill asks whether to connect for future jobs, import past history, or both, then confirms the source
12
12
  project and machine. No destination model key is needed for this connection: a live agent uses its existing native
13
- sign-in and configuration. Turn **Self-improving** On separately to give later runs your corrections and the
14
- workflows its runs compile;
15
- imported history stays historical and does not automatically train the agent.
13
+ sign-in and configuration. Turn **Self-improving** On separately to give later runs your owner-written
14
+ corrections. Eligible server-run and SDK agents can also compile checked workflows; CLI capture has no workflow
15
+ bridge. Imported history stays historical and does not automatically train the agent.
16
16
 
17
17
  For a source on a different laptop, VM or container, choose **Connection setup → Another machine** and use the
18
18
  matching [Python source connector](../../connector/README.md). Remote execution currently needs the server and
19
19
  connector from the same reviewed development checkout; the published observation-only CLI does not include it.
20
20
  The source worker must stay online. See [Native agents](../../docs/native-agents.md) for setup, history scopes and
21
- runtime limits. Connected agents use ordinary agent revisions and the existing checked learning pipeline; managed
22
- adapter isolation is unchanged.
21
+ runtime limits. Connected agents use ordinary agent revisions; each connection declares whether it can launch runs
22
+ and execute checked workflows. The console shows server-run and source-connected agents in one inventory, with their
23
+ actual connection and activity state. A CLI capture profile linked to a source appears with that source; an unlinked
24
+ profile remains visible. A source session is not itself a recorded run. Managed adapter isolation is unchanged.
25
+
26
+ `GET /v2/observations` also reports `learning` for each observed session: `on`, `off`, `setup_required`,
27
+ `unknown` or `unsupported`, with a reason and verified profile IDs when available. Polling sources advertise
28
+ support through `cli_learning.session_association` in `/api/v2/control/connectors/capabilities`. A source may
29
+ attach `metadata.cli_learning` after matching the exact canonical project, runtime and server origin to an
30
+ existing private CLI learning connection. Its proof binds the connector, selected source, observed session,
31
+ runtime, connection, readiness, native-session hash and sequence using that connection's scoped credential.
32
+ The receiver stores verified identifiers, never the credential or proof, and returns no source paths or native
33
+ session hashes. On requires configured hooks and an accepted hook window for that exact native session;
34
+ configuration alone is `unknown` with `awaiting_activation`. Agent and server learning settings are read live.
35
+ Missing support, invalid proofs or revoked credentials do not interrupt activity or usage reporting. Delegated
36
+ subagents report `unsupported`. Observing a session never enrolls its project or changes its learning setting.
23
37
 
24
38
  ## Quick start (no key, no network)
25
39
 
@@ -362,6 +376,28 @@ entry (`max_concurrent_runs`, beside `run_memory_mib`).
362
376
  A data directory serves one AgentRun Server at a time: a second server on the same data root is refused at start
363
377
  (`server.lock`).
364
378
 
379
+ `GET /v2/capacity`, with the token, says how much room the runners have, read from the store alone. A server with no
380
+ runner beside it (`--no-runner`, `AGENTRUN_API_ONLY=1`) answers it for every runner on its store. Read it to size the
381
+ runners by backlog, not by CPU. It gives:
382
+
383
+ - `runs.queued`: the runs waiting for a runner now. These are queued runs, runs handed back or whose claim ran out (past
384
+ any backoff), and parked runs with something to wake them.
385
+ - `runs.executing`: the runs a live claim holds now, on any runner.
386
+ - `runners`: each runner that said it was there in the last 30 s, by name. Each has its build's `version`, its `slots`
387
+ (the most runs it holds at once), what it holds (`executing`), its `free_slots` and whether it `refused` to claim.
388
+ `version` and `slots` are null for a runner of an earlier build that is still running. (On Postgres, an earlier
389
+ runner refuses to start once the server has applied `0024_runner_capacity.sql`, so upgrade runners with the server.)
390
+ A runner also claims by its host's memory, so a free
391
+ slot is the most it may take.
392
+ - `free_slots`: the sum of the live runners' free slots.
393
+ - `hand_backs`: how many runs a runner gave back still running within `?window=` minutes (1 to 1440, default 15). A
394
+ drain, a loop that closed itself and a claim given back each count; a claim whose lease ran out does not.
395
+
396
+ It names no run, agent or address. Each runner also prints metric lines in the server's log format, which a log-based
397
+ metric counts: `runner_claimed` (`took_over=1` when it took over a run whose lease ran out), `runner_hand_back` with its
398
+ `cause` (`drain`, `interrupted`, `end_retry`, `give_back`, or `claim_lost` with its `why`), `runner_drained` once per close
399
+ that held a run (`ms`, `held`, `left`), and `runner_gauge` every minute (`active`, `slots`, `rss_mib`).
400
+
365
401
  `GET /v2/health`, with no credential like capabilities, answers `200 {status: "ok", checks: {store: "ok", disk: "ok"}}`
366
402
  when the agent store opens for a read and the data directory's disk has at least 64 MiB free (`AGENTRUN_MIN_FREE_MB`),
367
403
  and `503` with `status: "failing"` and which check failed (`store: "does_not_open"`, `disk: "below_floor"`, or
@@ -375,8 +411,10 @@ time, writes nothing more to the run, and the store refuses any write under a cl
375
411
  claim lapses another runner claims the run and resumes it from its journal. A run's own computer doesn't survive a
376
412
  runner loss, a crash, a server stop or a park (the claim that resumes the run starts a new one, and says so on the
377
413
  timeline and, once, to the model as an "AgentRun server note"), and the agent's own computer, a persistent setting, does. `agentrun-serve runner --check --data DIR --name N`
378
- (or `AGENTRUN_RUNNER_NAME=N` in place of `--name`) says whether the runner named `N` has a fresh heartbeat: it exits 0
379
- when it does and 1 when it does not, and 2 when no name is given. Name a runner you start yourself with
414
+ (or `AGENTRUN_RUNNER_NAME=N` in place of `--name`) checks the runner's environment by name (its store, its seal key,
415
+ every run-facing name its server holds, a forwarder on loopback) and whether the runner named `N` has a fresh
416
+ heartbeat: it exits 0 when both hold, 1 when either does not, and 2 when no name is given. `--check --env` checks the
417
+ environment alone, and `--check --heartbeat` the heartbeat alone ([deploy/README.md](../../deploy/README.md#the-runners-environment-runner---check)). Name a runner you start yourself with
380
418
  `agentrun-serve runner --data DIR --name N`.
381
419
 
382
420
  ## Start-time switches
@@ -391,6 +429,7 @@ AGENTRUN_WEBHOOK_PRIVATE_TARGETS=1 to allow it, only on a machine you alone use`
391
429
  | --- | --- | --- | --- |
392
430
  | `AGENTRUN_MCP_ALLOW_LOOPBACK=1` | An MCP server on this machine's loopback ([MCP servers](#mcp-servers)) | off | Loopback is this machine's other services too: set it only on a machine you alone use |
393
431
  | `AGENTRUN_WEBHOOK_PRIVATE_TARGETS=1` | The outbound webhook to a private network or this machine ([Webhooks](#webhooks)) | off | Whoever may set the webhook could make the server POST inside its network: only on a machine you alone use |
432
+ | `AGENTRUN_PRIVATE_HOSTS` | Bounds the private-network hosts an owner may allow an MCP server or a calendar on (Settings → MCP servers): `none` allows none (and only an empty list can be saved), or a comma list of address ranges (`10.20.0.0/16,fd12:3456::/32`) every listed host's address must also fall in. Loopback, link-local (cloud metadata) and this machine's addresses stay refused whatever it says. A value that is neither reads as `none` | unset: the owner's list holds | On a server or runner many customers share, an owner's list would reach the operator's own private network: set `none` there, on the server and on each runner (each process holds to its own) |
394
433
  | `AGENTRUN_BOX_ALLOW` | The hosts a run's computer may reach: a comma list, or `none` ([A run in a Docker box](#a-run-in-a-docker-box)) | the package registries and GitHub | A run's network is the operator's policy, not a caller's |
395
434
  | `AGENTRUN_BOX_CPUS`, `AGENTRUN_BOX_MEMORY`, `AGENTRUN_BOX_PIDS` | A Docker computer's size ([Computers](#computers)) | 2 CPUs, 4 GiB, 1,024 processes | The machine's capacity is the operator's |
396
435
 
@@ -2829,7 +2868,9 @@ account's app password (Gmail, iCloud and Fastmail each make one in the account'
2829
2868
  sign-in password is refused by most providers), at most 1,024 characters. It is sealed under the server's seal key
2830
2869
  (`AGENTRUN_SEAL_KEY`) and is in no answer, event or log line. Every connection is TLS: 993 and 465 from the start, any
2831
2870
  other port with STARTTLS required. Only `127.0.0.1` is reached in the clear. `POST /v2/settings/email/test` signs in to
2832
- both servers and sends nothing; `DELETE` forgets the account.
2871
+ both servers and sends nothing. A save signs in the same way first: an account either server refuses, or one a server
2872
+ can't be reached for, is 424 `upstream_failed` in the test's words (`details.imap` and `details.smtp`), with nothing
2873
+ saved and any account saved before kept as it was. `DELETE` forgets the account.
2833
2874
 
2834
2875
  **The trigger.** `{kind: "email", mailbox?: "INBOX", every_s?: 60, accept?}` reads the mailbox every `every_s` seconds
2835
2876
  and starts a run for each new message its `accept` takes (a rule's `where` reads `/from`, `/to`, `/subject`, `/text`).
@@ -2857,7 +2898,8 @@ after asks, saying "this run has sent 5 emails" (the count is the run's own reco
2857
2898
  stops two auto-responders answering each other. On a run an email started whose `email_read` is thread-scoped (no
2858
2899
  `scope: "mailbox"`), a send to anyone outside the thread's people
2859
2900
  (the account's own address and every From, To and Cc of the thread's messages) asks too, naming them ("eve@example.com
2860
- is outside this email's thread"). The approval's `summary` ends "Asks because ...". With accounts off, where no one can
2901
+ is outside this email's thread"). The pending approval carries the reason as `asks_because`, which the console's card
2902
+ says above the call's arguments ("Asks because ..."). With accounts off, where no one can
2861
2903
  approve, such a send is refused in those words.
2862
2904
 
2863
2905
  ## Templates
@@ -2894,6 +2936,7 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
2894
2936
  | Route | Here |
2895
2937
  | --- | --- |
2896
2938
  | `GET /health` | Without a credential: whether the store reads and the disk has room ([capacity and health](#capacity-and-health)). |
2939
+ | `GET /capacity` | This server's own (`capacity/1`): the runs waiting for a runner and held by one, each live runner's version, slots and free slots, and the hand-backs within `?window=` minutes, read from the store ([capacity and health](#capacity-and-health)). Served under `AGENTRUN_API_ONLY=1` too. |
2897
2940
  | `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. |
2898
2941
  | `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. |
2899
2942
  | `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. |
@@ -2914,7 +2957,7 @@ failed, 2 when nothing ran. The runner, the graders and the report are in
2914
2957
  | `GET /runs/{id}/files`, `GET /runs/{id}/files/{path}` | The files under the run's `work/`, raw, one byte range at a time on asking (`Range`, `206`); and its screen recordings under `recordings/` ([A video of each run](#computers)). |
2915
2958
  | `POST /files`, `PUT /files/{id}`, `GET /files`, `GET` and `DELETE /files/{id}` | [Uploads](#uploads): a file sent in one call (`POST /v2/files?path=...`, its bytes the body), or reserved and then sent (`PUT /v2/files/{id}`); the server's uploads listed, read and deleted. |
2916
2959
  | `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"`). |
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. |
2960
+ | `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 and verified source reports; source completion counters are read when needed to separate overlapping usage. 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`, `runs_with_token_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`. Token totals sum only runs with every token counter reported, counted by `runs_with_token_metrics`; other runs remain in `runs` but cannot hide the known partial total. If runs exist but none reports a complete count, `tokens` is null; an empty scope is zero. Individual token-kind totals remain null when a measured run reports that counter as unknown. `analytics.usage` combines recorded runs and connected source reports ([Unified token usage](#unified-token-usage)). `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. |
2918
2961
  | `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
2962
  | `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. |
2920
2963
  | `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. |
@@ -2937,6 +2980,53 @@ Quotes answer `501 unsupported_here` naming the feature. Home export and import
2937
2980
  `info.x-agentrun-serve.not_served` lists them). Capabilities declare each of the four false. No run waits out `input_wait_s` here (`null`). `limits.max_cost_usd` is the highest cap a run may name: `null` here, as any cap
2938
2981
  above $0 is taken; it does not mean caps are unsupported ([spend cap](#spend-cap)).
2939
2982
 
2983
+ ### Unified token usage
2984
+
2985
+ `GET /stats` includes `analytics.usage`, the dashboard's single reported token total across recorded runs and
2986
+ connected source sessions. It contains `tokens`, uncached `input`, `output`, `cache_read`, `cache_write`, `by_day`
2987
+ and `by_harness`. A source's inclusive input plus output can establish its total even when its cache breakdown is
2988
+ unavailable; the unavailable breakdown remains null. Run counts, outcomes, time and cost retain their existing
2989
+ meaning and do not treat an observed session as a completed run.
2990
+
2991
+ `known_runs` counts usable run contributions; `unknown_runs` marks missing counters or unresolved overlap.
2992
+ `observed_sessions` counts source identities with usable reports in scope, including when another view supplies
2993
+ the selected total; `unknown_sessions` marks missing or
2994
+ incomplete source coverage. Known and unknown counts can overlap: a selected aggregate can supply a lower bound
2995
+ without proving complete coverage. A verified native session hash and runtime link observations to CLI prompt windows,
2996
+ native runs, SDK runs or imported sessions. Same-source aggregates are added only when their windows prove they
2997
+ do not overlap. When retained daily source reports and run counters may overlap without an exact intersection,
2998
+ the result is a conservative lower bound and `unknown_runs` marks incomplete coverage, even when every source
2999
+ reported its counters. Offline prompt captures may arrive on a later day, so server timestamps alone do not
3000
+ prove their usage is separate from source day buckets. An imported root can include descendants with no retained
3001
+ identity. When its journal exactly reconciles with its saved counters, the root’s own usage can be separated and
3002
+ counted against source reports. Its full aggregate remains an alternative to the same runtime’s native total;
3003
+ the larger coherent view is retained, never added to that total. An unavailable or inconsistent journal uses the
3004
+ same conservative alternative. Unresolved descendant coverage stays in `unknown_runs`.
3005
+ CLI/SDK run metrics may also contain reflection in a separate session. When both the full metrics and immutable
3006
+ source completion counters are known, their nonnegative difference remains included. Historical CLI native
3007
+ reflections can themselves appear in source observations; when that overlap is possible, their full run is a
3008
+ runtime alternative too. Purged runs retain numeric counters but no private source identity: native counters
3009
+ remain conservative alternatives to potentially overlapping source views. Otherwise an unproven remainder is
3010
+ counted in `unknown_runs` coverage rather than silently discarded or guessed as zero.
3011
+ Historical identity remains valid when learning is
3012
+ disabled or revoked. Archiving a learning profile does not disconnect its observed source. Multiple collectors
3013
+ reporting the same verified session use the copy with the largest reported total for each UTC day, then the freshest
3014
+ receipt and stable session id. Disjoint days remain included; overlapping same-day copies are never added because
3015
+ the server retains daily aggregates rather than request identities. This may leave unknown coverage when collectors
3016
+ hold disjoint requests within the same day; their aggregate intersection cannot be inferred. The selected figure
3017
+ is then a lower bound, not a complete count of that session.
3018
+ Unbound observations have no native identity proof and remain distinct. Display names and project labels never
3019
+ establish identity, so an unbound collector cannot deduplicate a separately recorded run.
3020
+
3021
+ Run tokens use the run's start date. Source tokens use the UTC day on which usage was observed, not a session's
3022
+ lifetime total or an inferred request date. Only daily buckets fully inside `[from, to)` are counted; `partial_days`
3023
+ reports boundary days excluded because their aggregate cannot be split exactly. With no `to`, today's reported
3024
+ usage is included. Source history is retained for 90 days; `retention_limited` says the requested range extends
3025
+ beyond it. These figures are reported coverage, not a claim that unobserved history cost zero.
3026
+
3027
+ `agent` may select a recorded agent and its associated sessions, or a connected session id (`os_...`) for only that
3028
+ session's usage. The latter selects no recorded runs. It does not import or create an agent definition.
3029
+
2940
3030
  ### Feed triggers
2941
3031
 
2942
3032
  A feed trigger starts a run for each new or updated item in one or more feeds: RSS (2.0 and 1.0), Atom, JSON Feed, or a
@@ -3005,7 +3095,7 @@ serves these routes alone:
3005
3095
  (`GET /runs/{id}/learning`), each cut of the host's secrets as the console's reads are;
3006
3096
  - a run's hosted machine fetching this server's computerd build (`GET /computers/daemon`), with the token its create
3007
3097
  minted;
3008
- - `GET /capabilities`, `GET /health` and `GET /usage`;
3098
+ - `GET /capabilities`, `GET /health`, `GET /usage` and `GET /capacity`;
3009
3099
  - a run's desktop or phone, for a backend that shows its user the live view and lets them take over: see below.
3010
3100
 
3011
3101
  Here a run's computer routes take the server's token. `POST /runs/{id}/computer/viewer` mints a 5-minute link on
@@ -3069,6 +3159,25 @@ upload stays in the runs that copied it; a run started after names it in vain. E
3069
3159
  logs `event=uploads_swept removed=N`. `upload.expires_at`, which the contract requires, is advisory and not enforced in
3070
3160
  this release: a `PUT` after it is still taken.
3071
3161
 
3162
+ With Archil on (Mode 2), uploads live on Archil, not in `DIR`, so a runner needs no disk of the server's. The server
3163
+ keeps them on an Archil disk of its own, `agentrun-<server id>-files`, made by its first upload, at
3164
+ `files/<file_id>/` (the same bytes and record). Listing, reading and deleting read that disk; the routes, limits and
3165
+ answers are the ones above, but the bytes are held in the server's memory (up to 50 MiB a file) instead of streamed to
3166
+ disk. When a run is started with `file_ids`, the server copies each file into the run's folder on its disk, at
3167
+ `work/inputs/<path>` (the launch's `archil_disk`, else its agent's, made first when the agent has none), before the run
3168
+ is queued, for at most 45 s. The server copies 2 files at a time across all the runs it is starting, because Archil
3169
+ resets a connection carrying more large writes at once; 20 files of 10 MiB took 11 to 14 s. A copy that fails or takes
3170
+ longer refuses the start with
3171
+ `424 upstream_failed` ("The run's files could not be copied into its folder on Archil, so it was not started: ..."). No
3172
+ run is made and what was copied is removed. The run's claim then finds its files in place and reads no upload. Files
3173
+ uploaded while Archil was off stay in `DIR/files/` and are not seen while it is on, and the other way round.
3174
+
3175
+ In Mode 2, an uploaded file that no run names is deleted once it is older than `AGENTRUN_UPLOAD_RETENTION` (default
3176
+ `7d`; a whole number with `ms`, `s`, `m`, `h` or `d`, or `off` to keep every file). The server sweeps its uploads disk
3177
+ once an hour and logs `event=uploads_expired removed=N`. A file is kept while a run the store still has was started with
3178
+ it, or while a run started with it in the last hour (whose row may not be written yet). A file kept by a run that has
3179
+ since been deleted becomes unnamed and goes after the retention. Mode 1 keeps every upload, as before.
3180
+
3072
3181
  ## Agent home
3073
3182
 
3074
3183
  Each agent has a home, a directory of its own at `<data>/homes/<key>/`, kept across its runs; runs do not see it yet.
@@ -3667,6 +3776,15 @@ These reads make no paid request, and saving a matching key refreshes the setup
3667
3776
  Importing Claude Code, Codex or pi session history does not replay learning or connect a live learning stream.
3668
3777
  Before/after cost and duration are observations, not an accuracy evaluation.
3669
3778
 
3779
+ **Existing CLI capture.** A project enrolled with `cli_learning` keeps running in its original Codex CLI or Claude
3780
+ Code process. Its hooks record normal prompt windows and provide the agent's explicit owner-written corrections
3781
+ on later prompts when learning is enabled. Capturing a prompt does not turn its content or answer into a correction.
3782
+ CLI capture starts no extra source prompt, native grading turn or automatic note/skill extraction. It has no
3783
+ approved workflow tool bridge, so it neither compiles nor executes learned workflows. The Learning tab edits
3784
+ corrections and shows captured runs; new captures begin with the next normal prompt after hooks are ready.
3785
+ Historical learning files remain stored and are not converted into owner corrections or deleted. Older stored
3786
+ CLI `learning: "notes"` settings read publicly as `true`; that compatibility read does not rewrite the revision.
3787
+
3670
3788
  An agent that learns has a learning folder, `learning/` in its folder on the disk (`DATA/disk/agents/<key>/learning/`):
3671
3789
 
3672
3790
  - `corrections.md`, its owner's standing corrections, one `- ` line each, at most 2048 bytes;
@@ -4502,16 +4620,23 @@ carries no cost at all, as from a provider that does not price the model. The te
4502
4620
  process of its uid).
4503
4621
  - In the image, each run's process also runs as a user of its own: slot `s` of its runner is uid and gid `1001 + s`
4504
4622
  (256 slots), started through `agentrun-runas`, a helper installed root:node `0750` with the file capabilities
4505
- `cap_setuid`, `cap_setgid` and `cap_setpcap`. The helper reaches only that range and refuses uid and gid 0; it sets
4623
+ `cap_chown`, `cap_setuid`, `cap_setgid` and `cap_setpcap`. The helper reaches only that range and refuses uid and gid 0; it sets
4506
4624
  the run's uid, gid and groups (its slot's group alone: not node's, not the Docker socket's group compose gives the
4507
4625
  server), empties every capability set, sets `no_new_privs` and keeps only the run's two descriptors open. So one run
4508
4626
  reads neither another live run's folder nor its process's memory, environment or descriptors, and none reads the data
4509
4627
  directory (`0711`: crossed to its own folders, never listed), the store's files (`0600`), the seal key or the
4510
- server's memory. A run's folders are its slot group's (`2770`), which the server's user is in. At the run's end every
4511
- process of its uid is killed, one in a session of its own included, its files in `/tmp`, `/var/tmp`, `/dev/shm`,
4512
- `/run/lock` (`/var/lock`) and `/dev/mqueue` are removed, and its folders go back to the server's group, which the
4513
- slot's next run cannot enter. SysV IPC objects (`ipcs`) a run leaves are not removed.
4514
- `GET /v2/capabilities` says `run_isolation: "uid"`.
4628
+ server's memory. The server's user (node) is in one group, its own (1000), and in no slot's; no slot is in node's.
4629
+ Before a run starts, its folders and everything in them are given to its slot: the slot's uid, node's group, folders
4630
+ `2770` with the setgid bit (`agentrun-runas own <slot>`, keeping `cap_chown` alone and changing each entry through a
4631
+ descriptor it opened without following a link). The run reaches them as their owner and the server reads them through
4632
+ its one group; no other slot can enter them. A folder the run itself shuts (`chmod 700`, which drops the setgid bit,
4633
+ since node's group is not the run's) the server cannot read until the run ends. At the run's end every process of its
4634
+ uid is killed, one in a session of its own included, its files in `/tmp`, `/var/tmp`, `/dev/shm`, `/run/lock`
4635
+ (`/var/lock`) and `/dev/mqueue` are removed, and its folders and everything in them go back to node
4636
+ (`agentrun-runas own runner`), which the slot's next run cannot enter. A give-back that fails retires the slot, as a
4637
+ reap that does not hold does. SysV IPC objects (`ipcs`) a run leaves are not removed.
4638
+ `GET /v2/capabilities` says `run_isolation: "uid"`. A runner shared by many customers: see the threat model,
4639
+ [docs/multi-tenant-runners.md](../../docs/multi-tenant-runners.md).
4515
4640
  - A platform that strips the image's file capabilities, or starts it with `no-new-privileges` (Docker's
4516
4641
  `security_opt: no-new-privileges:true`, Kubernetes' `allowPrivilegeEscalation: false`), leaves the helper unable to
4517
4642
  switch, or unable to start (a spawn `EPERM`): the runner then refuses to claim, saying so and naming the setting, and
@@ -12,6 +12,7 @@ import { approvalsOf } from "./approvals.js";
12
12
  import { ApiError, invalid } from "./errors.js";
13
13
  import { harnessOfBody } from "./harness.js";
14
14
  import { learningSettingIssue } from "./learning-setting.js";
15
+ import { learningSettingForBody } from "./store/agent-body.js";
15
16
  import { storedHarness } from "./harness-table.js";
16
17
  import { AgentBodyInvalid, RevisionMoved, bodyOf, canonical, isObject, StoreConstraint, } from "./store/index.js";
17
18
  import { canonicalToolSettings, settingsIssues } from "./tool-plane.js";
@@ -109,6 +110,7 @@ function revisionInputOf(definition, files) {
109
110
  return {
110
111
  kind: "agentic",
111
112
  instructions: definition.instructions,
113
+ ...(definition.cli_learning !== undefined ? { cli_learning: definition.cli_learning } : {}),
112
114
  ...(definition.sdk !== undefined ? { sdk: definition.sdk } : {}),
113
115
  ...(isObject(definition.native) ? { native: definition.native } : {}),
114
116
  ...(typeof definition.model === "string" ? { model: definition.model } : {}),
@@ -194,7 +196,7 @@ export async function createAgent(store, { definition, skills = {}, note }, opti
194
196
  if (given !== undefined && (await store.agents.get(given)))
195
197
  throw new ApiError("agent_exists", `an agent ${given} exists here`);
196
198
  // Stamped on the revision now, never resolved at run time: an agent saved with no place keeps running on the runner.
197
- const placed = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow) && !isObject(definition.sdk)
199
+ const placed = options.fresh && definition.place === undefined && definition.computer === undefined && !isObject(definition.workflow) && !isObject(definition.sdk) && !isObject(definition.cli_learning)
198
200
  ? { place: options.fresh.place, ...(definition.tools === undefined ? { tools: [...options.fresh.tools] } : {}) }
199
201
  : {};
200
202
  // A template's agent keeps the package it was applied from on its first revision (store `revisions.package`).
@@ -323,6 +325,7 @@ function editOn(entry, definition, skills, note, fromPackage = false) {
323
325
  files = (isObject(current?.skills) ? current.skills : {});
324
326
  const carried = current
325
327
  ? {
328
+ ...(currentBody.cli_learning && definition.cli_learning === undefined ? { cli_learning: currentBody.cli_learning } : {}),
326
329
  ...(currentBody.sdk && definition.sdk === undefined ? { sdk: currentBody.sdk } : {}),
327
330
  ...(currentBody.native && definition.native === undefined ? { native: currentBody.native } : {}),
328
331
  ...(definition.harness === undefined && currentBody.harness ? { harness: currentBody.harness } : {}),
@@ -335,7 +338,7 @@ function editOn(entry, definition, skills, note, fromPackage = false) {
335
338
  // What the host owns (the sdk and native references, the harness, the computer and place) carries as an edit's does.
336
339
  const owned = current && !fromPackage
337
340
  ? {
338
- ...(definition.learning === undefined && current.kind === "agentic" && !isObject(definition.workflow) && currentBody.learning !== undefined ? { learning: currentBody.learning } : {}),
341
+ ...(definition.learning === undefined && current.kind === "agentic" && !isObject(definition.workflow) && learningSettingForBody(currentBody) !== undefined ? { learning: learningSettingForBody(currentBody) } : {}),
339
342
  // No approvals here: an edit that leaves them out asks (openapi.ts DefinitionInput.approvals),
340
343
  // so no edit makes an agent unattended by saying nothing. The console's edit sends back the approvals it read.
341
344
  ...(definition.max_cost_usd === undefined && currentBody.maxCostUsd !== undefined ? { max_cost_usd: currentBody.maxCostUsd } : {}),
@@ -385,7 +388,7 @@ export function definitionOf(agent, revision, version) {
385
388
  const body = revision.body;
386
389
  const common = body.maxCostUsd !== undefined ? { max_cost_usd: body.maxCostUsd } : {};
387
390
  const kindBody = revision.kind === "agentic"
388
- ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(body.learning !== undefined ? { learning: body.learning } : {}), ...(body.inputSchema !== undefined ? { input_schema: body.inputSchema } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
391
+ ? { instructions: body.instructions, ...(body.model ? { model: body.model } : {}), ...(body.modelTiers ? { model_tiers: body.modelTiers } : {}), ...(body.thinking ? { thinking: body.thinking } : {}), ...(learningSettingForBody(body) !== undefined ? { learning: learningSettingForBody(body) } : {}), ...(body.inputSchema !== undefined ? { input_schema: body.inputSchema } : {}), ...(body.outputSchema !== undefined ? { output_schema: body.outputSchema } : {}), ...(body.checkout !== undefined ? { checkout: body.checkout } : {}), ...common }
389
392
  : { workflow: body.workflow, ...common };
390
393
  return {
391
394
  id: agent.id,
@@ -393,6 +396,7 @@ export function definitionOf(agent, revision, version) {
393
396
  name: agent.name,
394
397
  ...(agent.description !== null && agent.description !== undefined ? { description: agent.description } : {}),
395
398
  ...kindBody,
399
+ ...(body.cli_learning ? { cli_learning: body.cli_learning } : {}),
396
400
  ...(body.sdk ? { sdk: body.sdk } : {}),
397
401
  ...(body.native ? { native: body.native } : {}),
398
402
  // Its approvals, of either kind: "ask" where none is set, as the definition read says it (definitionOf).
@@ -7,7 +7,8 @@ export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
7
7
  * - an agent its inline runs made has its disk and its delete sent by the backend that made it;
8
8
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
9
9
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's;
10
- * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is. */
10
+ * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
11
+ * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart. */
11
12
  export declare const API_ONLY_ROUTES: ReadonlySet<string>;
12
13
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
13
14
  * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */
package/dist/api-only.js CHANGED
@@ -6,7 +6,8 @@ export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
6
6
  * - an agent its inline runs made has its disk and its delete sent by the backend that made it;
7
7
  * - a run's computer, take-over, hand-back and viewer link go to the backend, which has no owner's session here;
8
8
  * - a backend reads what its agents learned (loop, promotions, cost per run, a run's learning), cut as the console's;
9
- * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is. */
9
+ * - a run's usage lines (what its cost.usd joins, by meter) are a read of that run alone, cut as the run's read is;
10
+ * - an operator or a scaler reads the runners' capacity (getCapacity, capacity.ts) from the server whose runners run apart. */
10
11
  export const API_ONLY_ROUTES = new Set([
11
12
  "createRun", "createInlineRun", "getComputerDaemon",
12
13
  "getRunComputer", "takeOverRunComputer", "handBackRunComputer", "createRunComputerViewer",
@@ -17,7 +18,7 @@ export const API_ONLY_ROUTES = new Set([
17
18
  "sendMessage", "stopRun", "cancelRun", "raiseRunCap", "gradeRun",
18
19
  "listRunFiles", "readRunFile",
19
20
  "createFile", "listFiles", "getFile", "uploadFile", "deleteFile",
20
- "getCapabilities", "getHealth", "getUsage",
21
+ "getCapabilities", "getHealth", "getUsage", "getCapacity",
21
22
  ]);
22
23
  /** Whether `env` turns the profile on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused in
23
24
  * words (a TypeError), so a typo never leaves the console open on a server meant to be API-only. */