@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.60

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 (194) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +188 -106
  3. package/dist/agent-delete.d.ts +6 -9
  4. package/dist/agent-delete.js +5 -3
  5. package/dist/agent-package.js +11 -1
  6. package/dist/api-only.d.ts +2 -2
  7. package/dist/api-only.js +3 -3
  8. package/dist/archil-routes.d.ts +4 -1
  9. package/dist/archil-routes.js +15 -12
  10. package/dist/archil-settings.d.ts +18 -8
  11. package/dist/archil-settings.js +35 -17
  12. package/dist/chatgpt-plan.d.ts +4 -2
  13. package/dist/chatgpt-plan.js +13 -3
  14. package/dist/claude-login-token.d.ts +5 -0
  15. package/dist/claude-login-token.js +8 -0
  16. package/dist/claude-login.d.ts +49 -3
  17. package/dist/claude-login.js +140 -10
  18. package/dist/cli-learning/connections.js +1 -1
  19. package/dist/console/assets/{backend-BztxEAvb.js → backend-QnwGVBeU.js} +1 -1
  20. package/dist/console/assets/index-DZi-muIj.js +629 -0
  21. package/dist/console/assets/{share-L84tlUDW.js → share-pz61zIn9.js} +2 -2
  22. package/dist/console/assets/{styles-CaRKlHke.js → styles-CcceGcu2.js} +31 -31
  23. package/dist/console/assets/styles-fjQBFfMv.css +1 -0
  24. package/dist/console/index.html +3 -3
  25. package/dist/console/share.html +3 -3
  26. package/dist/decisions.d.ts +1 -1
  27. package/dist/decisions.js +2 -2
  28. package/dist/factory-activity.d.ts +68 -0
  29. package/dist/factory-activity.js +153 -0
  30. package/dist/factory-runs.d.ts +11 -0
  31. package/dist/factory-runs.js +52 -0
  32. package/dist/filed-tool.d.ts +32 -0
  33. package/dist/filed-tool.js +122 -0
  34. package/dist/harness-keys.d.ts +1 -2
  35. package/dist/harness-keys.js +1 -2
  36. package/dist/harness-table.d.ts +4 -0
  37. package/dist/harness-table.js +4 -0
  38. package/dist/harness.js +6 -2
  39. package/dist/import-worker.js +2 -2
  40. package/dist/import.d.ts +9 -0
  41. package/dist/import.js +11 -1
  42. package/dist/key-refusal.d.ts +5 -0
  43. package/dist/key-refusal.js +25 -15
  44. package/dist/learn/audit.d.ts +20 -22
  45. package/dist/learn/audit.js +72 -55
  46. package/dist/learn/check.js +1 -1
  47. package/dist/learn/commit.d.ts +35 -43
  48. package/dist/learn/commit.js +62 -270
  49. package/dist/learn/compile.d.ts +4 -4
  50. package/dist/learn/compile.js +6 -7
  51. package/dist/learn/corrections.js +1 -1
  52. package/dist/learn/delete.d.ts +5 -12
  53. package/dist/learn/delete.js +17 -30
  54. package/dist/learn/forget-run.d.ts +16 -0
  55. package/dist/learn/forget-run.js +53 -0
  56. package/dist/learn/index.js +1 -1
  57. package/dist/learn/learning-of.d.ts +0 -4
  58. package/dist/learn/learning-of.js +0 -5
  59. package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
  60. package/dist/learn/{folder.js → legacy/folder.js} +4 -7
  61. package/dist/learn/legacy/place.d.ts +16 -0
  62. package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
  63. package/dist/learn/legacy/scrub.d.ts +28 -0
  64. package/dist/learn/legacy/scrub.js +258 -0
  65. package/dist/learn/promote.d.ts +40 -66
  66. package/dist/learn/promote.js +69 -207
  67. package/dist/learn/reset-ledger.d.ts +18 -0
  68. package/dist/learn/reset-ledger.js +14 -0
  69. package/dist/learn/rows.d.ts +186 -0
  70. package/dist/learn/rows.js +376 -0
  71. package/dist/learn/workflow-draft.d.ts +4 -1
  72. package/dist/learn/workflow-draft.js +12 -2
  73. package/dist/learning-reset.d.ts +1 -1
  74. package/dist/learning-reset.js +9 -11
  75. package/dist/learning-routes.d.ts +60 -81
  76. package/dist/learning-routes.js +187 -360
  77. package/dist/learning-words.d.ts +2 -0
  78. package/dist/learning-words.js +2 -0
  79. package/dist/learning.d.ts +18 -24
  80. package/dist/learning.js +35 -66
  81. package/dist/mcp-gateway.d.ts +6 -0
  82. package/dist/mcp-gateway.js +44 -8
  83. package/dist/mcp-resources.d.ts +1 -1
  84. package/dist/native/discovery.d.ts +6 -0
  85. package/dist/native/discovery.js +14 -1
  86. package/dist/native/remote.d.ts +5 -0
  87. package/dist/native/remote.js +16 -0
  88. package/dist/native/runtime.js +3 -2
  89. package/dist/observation/observer.d.ts +6 -6
  90. package/dist/openapi.js +89 -29
  91. package/dist/place-offers.d.ts +3 -0
  92. package/dist/place-offers.js +3 -0
  93. package/dist/place.d.ts +33 -11
  94. package/dist/place.js +61 -26
  95. package/dist/purged-workflow.d.ts +0 -33
  96. package/dist/purged-workflow.js +3 -71
  97. package/dist/redact/match.d.ts +19 -4
  98. package/dist/redact/match.js +123 -30
  99. package/dist/run-launch.d.ts +3 -3
  100. package/dist/run-learning-served.d.ts +3 -3
  101. package/dist/run-learning-served.js +1 -1
  102. package/dist/run-listing.d.ts +1 -1
  103. package/dist/run-timeline-served.d.ts +1 -1
  104. package/dist/run-timeline-served.js +6 -5
  105. package/dist/runnable.js +25 -8
  106. package/dist/runner/adapter-run-spec.js +11 -20
  107. package/dist/runner/audit.d.ts +2 -4
  108. package/dist/runner/audit.js +28 -51
  109. package/dist/runner/cli-run-spec.js +8 -14
  110. package/dist/runner/compare-end.d.ts +0 -2
  111. package/dist/runner/compare-end.js +6 -2
  112. package/dist/runner/disk-free.d.ts +15 -4
  113. package/dist/runner/disk-free.js +25 -7
  114. package/dist/runner/feedback-round.d.ts +1 -1
  115. package/dist/runner/feedback-round.js +2 -2
  116. package/dist/runner/harness-loops.js +2 -3
  117. package/dist/runner/held.d.ts +0 -10
  118. package/dist/runner/held.js +0 -25
  119. package/dist/runner/journal-kinds.d.ts +4 -1
  120. package/dist/runner/journal-kinds.js +1 -1
  121. package/dist/runner/learned-first.d.ts +0 -2
  122. package/dist/runner/learned-first.js +3 -3
  123. package/dist/runner/learning-end.d.ts +12 -16
  124. package/dist/runner/learning-end.js +41 -75
  125. package/dist/runner/learning-seed.d.ts +13 -16
  126. package/dist/runner/learning-seed.js +13 -23
  127. package/dist/runner/main.js +1 -1
  128. package/dist/runner/mcp-run.d.ts +4 -0
  129. package/dist/runner/mcp-run.js +2 -0
  130. package/dist/runner/native-loop.js +2 -3
  131. package/dist/runner/promotion.d.ts +19 -28
  132. package/dist/runner/promotion.js +50 -69
  133. package/dist/runner/reflect-hook.d.ts +2 -2
  134. package/dist/runner/reflect-hook.js +4 -1
  135. package/dist/runner/run-child-host.d.ts +1 -9
  136. package/dist/runner/run-child-host.js +11 -67
  137. package/dist/runner/runner.d.ts +1 -1
  138. package/dist/runner/sdk-loop.js +2 -4
  139. package/dist/sdk/check.d.ts +1 -4
  140. package/dist/sdk/check.js +2 -3
  141. package/dist/sdk/runs.d.ts +20 -7
  142. package/dist/sdk/runs.js +105 -68
  143. package/dist/secrets.d.ts +4 -0
  144. package/dist/secrets.js +44 -10
  145. package/dist/server-fs.d.ts +1 -1
  146. package/dist/server-fs.js +1 -1
  147. package/dist/server-keys.d.ts +6 -0
  148. package/dist/server-keys.js +12 -0
  149. package/dist/server.d.ts +15 -15
  150. package/dist/server.js +214 -164
  151. package/dist/source-sync/auxiliary.js +2 -2
  152. package/dist/store/index.d.ts +1 -1
  153. package/dist/store/index.js +1 -1
  154. package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
  155. package/dist/store/schema.d.ts +28 -2
  156. package/dist/store/schema.js +81 -5
  157. package/dist/store/sqlite/learning-rows.d.ts +23 -0
  158. package/dist/store/sqlite/learning-rows.js +559 -0
  159. package/dist/store/sqlite/store.d.ts +7 -1
  160. package/dist/store/sqlite/store.js +84 -18
  161. package/dist/store/store.d.ts +219 -6
  162. package/dist/store/store.js +13 -0
  163. package/dist/store-reads/journal.d.ts +33 -3
  164. package/dist/store-reads/journal.js +99 -4
  165. package/dist/store-reads/learning.d.ts +18 -22
  166. package/dist/store-reads/learning.js +35 -26
  167. package/dist/store-reads/loop.js +1 -1
  168. package/dist/store-view.d.ts +24 -2
  169. package/dist/store-view.js +40 -11
  170. package/dist/templates.d.ts +10 -2
  171. package/dist/templates.js +31 -4
  172. package/dist/tool-plane.d.ts +4 -2
  173. package/dist/tool-plane.js +9 -2
  174. package/dist/web-holds.d.ts +2 -0
  175. package/dist/web-holds.js +5 -2
  176. package/dist/web-run.js +2 -1
  177. package/dist/workspace/archil-exec.js +1 -1
  178. package/dist/workspace/archil.d.ts +1 -1
  179. package/dist/workspace/archil.js +1 -1
  180. package/dist/workspace/computer-deps.js +5 -3
  181. package/dist/workspace/computer-providers.d.ts +11 -1
  182. package/dist/workspace/computer-providers.js +29 -2
  183. package/dist/workspace/index.d.ts +1 -2
  184. package/dist/workspace/index.js +1 -2
  185. package/dist/workspace/paths.d.ts +0 -4
  186. package/dist/workspace/paths.js +0 -6
  187. package/dist/workspace/workspace.d.ts +1 -1
  188. package/dist/workspace/workspace.js +1 -1
  189. package/package.json +13 -13
  190. package/templates/TOOLS.md +46 -0
  191. package/dist/console/assets/index-LwNL4L9q.js +0 -619
  192. package/dist/console/assets/styles-DQo8rzY-.css +0 -1
  193. package/dist/workspace/learning-workspace.d.ts +0 -24
  194. /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/README.md CHANGED
@@ -74,9 +74,10 @@ once they have loaded. A port already taken at the start is left to the start's
74
74
  replaces, as it always has, and prints no `Starting` line.
75
75
 
76
76
  A Docker box's image is built on its first run, which shows that on its timeline. `npx @parcha/agentrun` prints the
77
- `Boxes:` line on stderr, after its own line on stdout. On a machine where Docker is not running, the `Boxes:` line says so instead (`Boxes: none, so new agents run on the
78
- runner. Docker isn't running on this machine (no docker command on PATH): install or start Docker, then restart
79
- AgentRun.`); see [Sandbox](#sandbox).
77
+ `Boxes:` line on stderr, after its own line on stdout. On a machine where Docker is not running, the `Boxes:` line says so instead (`Boxes: none, so a new agent must name its
78
+ place: a box, or the runner. Docker isn't running on this machine (no docker command on PATH): install or start Docker,
79
+ then restart AgentRun.`; in Mode 2, where the runner's shell is Archil's serverless exec, `Boxes: none, so new agents run on
80
+ the runner.` and Docker's reason); see [Sandbox](#sandbox).
80
81
 
81
82
  `Open` is [the console](#the-console), which takes [your password](#your-password). For a client, export the two lines before
82
83
  it, then make an agent, start a run, and read its timeline until a page says `final`:
@@ -292,8 +293,12 @@ its first word is held too when that word is a known auth scheme (`Bearer`, `Bas
292
293
  and any query parameter named like a credential, and, inside any header's value, the value of each `name=value` pair
293
294
  named like a credential, read over the whole value as written, a URL's query and fragment included (a cookie's
294
295
  `session=<token>`, `https://relay/v1?region=us;session=<token>`, `#access_token=<token>`; pairs split at `;`, `&`, a
295
- comma or its `%2C`, and spaces, again at `?`, `#` and `/` too, and again at all but `;`, so `api_key=<key;rest>` holds
296
- the whole key; a value in quotes is held without them; `theme=dark` is not held), and the user, password and
296
+ comma or its `%2C`, and spaces, again at `?`, `#` and `/` too, and three times keeping a `;`: at all but `;`, so
297
+ `api_key=<key;rest>%2Cregion=us` holds the key; at `&` and spaces alone, so `api_key=<key;rest%2Cmore>` holds the
298
+ whole key; and at those or their `%26` and `%20`, so that key is held as written before an encoded `&` or space too,
299
+ and at those or `%26` alone, so a key with a `%20` in it is held before a `%26` (all are held, since a redactor matches each held value exactly and the longer reading never covers the
300
+ key alone); a value whose part before its first `;` is empty, `token=;<key>` or `token=%3B<key>`, is
301
+ held after that `;` too; a value in quotes, raw or written `%22` or `%27`, is held without them; `theme=dark` is not held), and the user, password and
297
302
  credential-named query parameters of every URL in it, one inside another's query or path too, scheme-relative
298
303
  (`//<key>@host`) or with its slashes escaped (`https:\/\/`). A URL's query, an endpoint's too, is read split at `&`
299
304
  alone and again at `&` and `;`, so `?api_key=<key;rest>` holds the whole key and `?region=us;session=<token>` the
@@ -390,7 +395,7 @@ sealed secrets, so a lost key is not replaced: recreating the container with the
390
395
 
391
396
  From a checkout, the same command in its root, with `--build` to build the image from it.
392
397
  `packages/serve/docker/Dockerfile` builds that image: the server and the open packages it runs, on Node 24.22.3 and Debian 13
393
- (trixie), with git 2.47 for an agent's learning folder and the Docker client. Everything it keeps is under `/data`: the agent store,
398
+ (trixie), with git 2.47 for a source project's capture and the Docker client. Everything it keeps is under `/data`: the agent store,
394
399
  the runs and the token.
395
400
 
396
401
  The image's default command, `server-and-runner --data /data --listen 0.0.0.0 --port 7340 --drain-timeout 6s`, starts
@@ -458,7 +463,7 @@ that can claim is there, the refusal is gone.
458
463
  The data directory has two parts. Its own files, the control plane, hold the agent store (`DIR/store.sqlite`, where
459
464
  each run's row keeps its claim: an epoch and its holder), the token and the server's settings; only the server and its
460
465
  runners open them. Everything the agents make is on the disk, `DIR/disk/`: one folder per agent, `DIR/disk/agents/<agent>/` (its id
461
- in lower case, a dash and 16 hex digits of its SHA-256), with its learning folder (`learning/`) and its runs
466
+ in lower case, a dash and 16 hex digits of its SHA-256), with its runs
462
467
  (`runs/<id>/`, each with `work/`, where its tools work). Nothing is copied in or out of a run's folder: where it
463
468
  works, it works in that folder. A run's record is not in its folder: its row, its claim and its journal (what the run
464
469
  did, in order) are rows of the store.
@@ -624,17 +629,43 @@ command in the background ([background processes](#background-processes)). The p
624
629
  revision, so its answers show it. A definition that names its tools keeps exactly those, an empty list included, and
625
630
  gets the box only when one of them runs only there (`bash` or a background tool). One whose tools need no shell (`[]`,
626
631
  or `read`, `write`, `web_fetch` and the like) is saved with no place and runs on the runner, so its first run starts at
627
- once instead of waiting on a container. Where docker is unavailable, a new agent is saved with no place. So is one whose
628
- tools name one the box refuses (`browser`, runner-only for now). A workflow is never given a box.
629
-
630
- `capabilities.places.default_place` is the place a new agent with a shell gets here, and where a revision that names no
631
- place and has a shell tool runs. It is worked out again at each run, the same way as at create: an agentic revision with
632
- no place and a shell tool runs in the Docker box wherever this server has docker now, and on the runner where it does
633
- not. A workflow, a revision whose tools need no shell, and one whose tools name one the box refuses run on the runner. A save checks a revision with no place against where it would run, so `bash`
634
- with no place saves where docker is there and is `422` where it is not. When that is the runner,
635
- `default_reason` says why in docker's own words, such as `new agents run on the runner, because the docker box is
636
- unavailable here: Docker isn't running on this machine (no docker command on PATH): install or start Docker, then
637
- restart AgentRun`. The console's new-agent form says docker's reason too, under its place picker. The console's new-agent form starts on `default_place`, with bash ticked when that place is a sandbox.
632
+ once instead of waiting on a container. One whose tools name one the box refuses (`browser`, runner-only for now) is
633
+ saved with no place too. A workflow is never given a box.
634
+
635
+ Where a new agent with no place goes, by mode:
636
+
637
+ - **Docker's box available:** it gets the box (`default_place` is `{"mode": "sandbox", "box": "docker"}`, no
638
+ `default_reason`), as above.
639
+ - **No Docker, and the runner has no shell (Mode 1): refused, `name a box`.** A new agent that would get the box (no
640
+ tools named, or a shell tool) is `422 input_invalid` with `{field: "definition.place", reason: "missing"}`, and so is an
641
+ edit that would save such a revision: `name a box: this server has no Docker box for a new agent. Set place to {mode:
642
+ sandbox, box: <one of: daytona, e2b>}, or to {mode: runner} to run without a shell. docker: <why>.` The words list the
643
+ boxes this server has (`<none is set up>` when it has none), and its `fix` says the same, so no box is picked for it:
644
+ the default box is the one whose provider descriptor sets `defaultBox` (Docker's), never another box that answers. They
645
+ end with why Docker's box is not here, in its entry's own words and fix (joining the docker group, say). A template
646
+ apply, or an `agentrun deploy`, of a package that names no `tools` and no `computer` list is refused the same way,
647
+ whatever MCP tools it ticks: it is the agent that gets the box where Docker is here. Its `dry_run` is refused
648
+ alike, with no plan. `default_place` is `null`, and
649
+ `default_reason` carries those words. A definition with no place that names a shell tool and the browser is refused at
650
+ the shell tool instead: a box refuses the browser, so no place runs both, and the words say to remove one.
651
+ - **No Docker, in Mode 2:** not refused. The runner's shell is Archil's serverless exec, so a new agent with no place
652
+ saves for the runner as before, and `default_place` is `{"mode": "runner"}`, no `default_reason`. A background tool
653
+ still runs in a box alone, so naming one with no place is refused at the tool.
654
+
655
+ A definition that names its place, the runner included, a workflow, and one whose tools need no shell save as before in
656
+ every mode, and so does a package that names its tools (`tools: []` included) or its computer list. An agent saved
657
+ before this change with no place and no tools keeps running on the runner: the store holds its tools as `[]`.
658
+
659
+ `capabilities.places.default_place` is always sent: the place a new agent with a shell gets here, and where a revision
660
+ that names no place and has a shell tool runs; `null` means no default, so a new agent names its place. It is worked out
661
+ again at each run, the same way as at create: an agentic revision with no place and a shell tool runs in the Docker box
662
+ wherever this server has docker now, on the runner in Mode 2, and in Mode 1 with no Docker its run is `409
663
+ agent_not_runnable` in the `name a box` words. A workflow, a revision whose tools need no shell, and one whose tools name
664
+ one the box refuses run on the runner. `default_reason` is there exactly when `default_place` is `null`; a client tells
665
+ the cases apart by `default_place === null`, never by reading `default_reason`. Docker's own reason is on its entry in
666
+ `boxes`. The console's new-agent form starts on `default_place`, with bash ticked when that place is a sandbox; with
667
+ `null`, it starts on neither the server nor a box, Create waits until one is chosen, and its picker says each box's
668
+ reason, and, with no box set up, that the agent needs one set up or On the server chosen.
638
669
  What a person picks or unticks there is what is sent.
639
670
 
640
671
  A run runs in its revision's place, else where `default_place` says at that run (a workflow, a revision whose tools need
@@ -654,8 +685,8 @@ the server is in Mode 1.
654
685
  `unavailable`) and, when it is unavailable, the `reason`.
655
686
  A definition naming a box this server does not have saves with a warning on `definition.place`, and a run of it is
656
687
  `409 agent_not_runnable` with `details.box`. `GET /v2/openapi.json` marks `definition.place`, the run's `place` and
657
- `capabilities.places` `x-agentrun-serve: "place/1"`, `default_reason` `"place/3"`, and `default_place` `"place/4"`
658
- (it replaced `places.default`).
688
+ `capabilities.places` `x-agentrun-serve: "place/1"`, and `default_place` and `default_reason` `"place/5"` (`default_place`
689
+ replaced `places.default`, and took `null` at place/5).
659
690
 
660
691
  ### A run in a Docker box
661
692
 
@@ -1026,7 +1057,10 @@ run's hold), newest first. The runs list carries no computer, so this is the one
1026
1057
  across runs and agents; the console's Settings → Computers shows it as Running now. An agent's own computer kept
1027
1058
  between runs is on the agent's read (`own_computer`), and a paired computer under `paired` in `GET /v2/computers`. The keys are
1028
1059
  `DAYTONA_API_KEY` (with `DAYTONA_API_URL` and `DAYTONA_TARGET` optional), `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET`,
1029
- `E2B_API_KEY`, `AGENT37_API_KEY` and `AGENT37_SSH_KEY`, `MORPH_API_KEY`, `ORGO_API_KEY`, `PHONE_HARNESS_API_KEY`,
1060
+ `E2B_API_KEY`, `AGENT37_API_KEY` (with `AGENT37_SSH_KEY` optional: unset, the server makes its own SSH key on first use,
1061
+ seals it in its store as every saved key under `AGENTRUN_SEAL_KEY`, and registers it on the workspace as
1062
+ `agentrun-<hash>`, one key per store even when claims or servers reach first use together; without a seal key, a new
1063
+ key each restart, the old one left on the workspace), `MORPH_API_KEY`, `ORGO_API_KEY`, `PHONE_HARNESS_API_KEY`,
1030
1064
  `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID`, `KERNEL_API_KEY`, `BOXD_API_KEY` (with `BOXD_ORG` and
1031
1065
  `BOXD_REGION` optional), `SMOLCLOUD_API_KEY`, `GROUNDBOX_API_KEY`, `CLOUDFLARE_RELAY_URL` and `CLOUDFLARE_RELAY_TOKEN` (the relay Worker's,
1032
1066
  `packages/computer/relays/cloudflare`), and `FLY_API_TOKEN` and `FLY_APP`; Docker takes none.
@@ -1208,8 +1242,12 @@ passes the binding's conformance cases (below) needs no change here.
1208
1242
  - **Mode 1** (the default): on this server's own disk. Only a provider that binds a folder of this machine can hold
1209
1243
  it, so a sandbox runs on Docker only; a Daytona, Modal, E2B or Agent37 sandbox is refused ("Mode 1 runs a sandbox only on
1210
1244
  Docker").
1211
- - **Mode 2**: on Archil disks. `PUT /v2/workspace/archil` turns it on with the account key, `ARCHIL_API_KEY`, its
1212
- region and that region's S3 URL (and an exec image pinned by digest, if you want one other than serve's default);
1245
+ - **Mode 2**: on Archil disks. `PUT /v2/workspace/archil` turns it on with the account key, `ARCHIL_API_KEY`, and its
1246
+ region (and an exec image pinned by digest, if you want one other than serve's default). For a region serve knows
1247
+ (`aws-us-east-1`, `aws-us-west-2`, `aws-eu-west-1` and `gcp-us-central1`, the regions Archil's SDK names; `GET` lists
1248
+ them in `regions`), the S3 URL is the region's (`https://s3.green.us-east-1.aws.prod.archil.com` for `aws-us-east-1`)
1249
+ and `s3Url` may be left out; one given is used instead, and `GET` says which in `s3UrlFrom`. Any other region needs
1250
+ its `s3Url`;
1213
1251
  `DELETE` turns it off. The default exec image is Docker's `buildpack-deps:trixie-scm` pinned by digest (git 2.47),
1214
1252
  because Archil's own has git 2.34 and a read-only bash policy runs git only at 2.43 or later. An image you name needs
1215
1253
  git 2.43 for that too, and GNU coreutils and perl, as Debian-family images have. A Modal, E2B or Agent37 sandbox
@@ -1232,17 +1270,17 @@ passes the binding's conformance cases (below) needs no change here.
1232
1270
  machine) or null (none).
1233
1271
 
1234
1272
  The PUT is a secret write, so it takes the owner's signed-in session. A server with none to give it (API only, or
1235
- `AGENTRUN_ACCOUNTS=0` reached beyond loopback) is set where it is started instead: `AGENTRUN_ARCHIL_REGION` and
1236
- `AGENTRUN_ARCHIL_S3_URL` together, and `AGENTRUN_ARCHIL_IMAGE` for a pinned exec image, with the account key in
1237
- `ARCHIL_API_KEY`. Each agent's disk is then made on its first run, as with saved settings:
1273
+ `AGENTRUN_ACCOUNTS=0` reached beyond loopback) is set where it is started instead: `AGENTRUN_ARCHIL_REGION`,
1274
+ `AGENTRUN_ARCHIL_S3_URL` for a region serve doesn't know (or to use another endpoint than a known region's), and
1275
+ `AGENTRUN_ARCHIL_IMAGE` for a pinned exec image, with the account key in `ARCHIL_API_KEY`. Each agent's disk is then
1276
+ made on its first run, as with saved settings:
1238
1277
 
1239
1278
  ```sh
1240
- AGENTRUN_ARCHIL_REGION=aws-us-east-1 AGENTRUN_ARCHIL_S3_URL=https://s3.example.com \
1241
- ARCHIL_API_KEY=... node packages/serve/dist/cli.js
1279
+ AGENTRUN_ARCHIL_REGION=aws-us-east-1 ARCHIL_API_KEY=... node packages/serve/dist/cli.js
1242
1280
  ```
1243
1281
 
1244
- Each value is checked as the PUT checks it. One of the region and S3 URL without the other, or a value the PUT would refuse,
1245
- stops the start, in words naming each variable. Set, they win over saved settings, as `ARCHIL_API_KEY` wins over a
1282
+ Each value is checked as the PUT checks it. A variable set without the region, no S3 URL for a region serve doesn't
1283
+ know, or a value the PUT would refuse, stops the start, in words naming each variable. Set, they win over saved settings, as `ARCHIL_API_KEY` wins over a
1246
1284
  saved key, and nothing is written to the store: `GET /v2/workspace/archil` says `source: "env"` (saved ones say
1247
1285
  `"console"`), and `PUT` and `DELETE` are `409 key_set_by_server`, since they are changed where the server is started.
1248
1286
  Unset, the saved settings, if any, hold again. A runner started on its own (`agentrun-serve runner`) reads them from its
@@ -1801,6 +1839,28 @@ has the row **Use Claude Code's login on this machine**, over these routes:
1801
1839
  The CLI dies with the server, as a session's CLI does, so a server that is killed outright (SIGKILL, the OOM killer)
1802
1840
  leaves no sign-in waiting on the browser's port.
1803
1841
  - `DELETE /v2/settings/claude-login` turns it off. The login stays as the CLI keeps it.
1842
+ - `POST /v2/settings/claude-login/sign-out` signs out of AgentRun's own login, for a fresh sign-in or another account: it
1843
+ ends a sign-in that waits, turns the mode off, runs the pinned CLI's own `claude auth logout` on
1844
+ `<data>/claude-login` (which removes its credentials file and, on macOS, its Keychain item for that folder), then
1845
+ removes that folder, the login's signed-in note in `claude-login-answers/` and the runner's token reader, whatever the
1846
+ CLI said. Each removal stands alone: one that fails is named in the answer and the rest still happen. It answers
1847
+ `{ "confirmed": true, "login": <the view, off> }`; `confirmed` false adds a `message` saying what may remain: the
1848
+ CLI didn't confirm its own sign-out, or its step failed, named (on macOS its Keychain item may remain), or a file it
1849
+ could not remove, by path. The CLI's sign-out runs where the folder is already gone too, so a retry after an
1850
+ unconfirmed sign-out confirms only where the CLI does. The next turn-on reads `signed_out` and the sign-in starts as
1851
+ before. `<data>/claude-login`
1852
+ is a folder AgentRun keeps itself: a turn-on where it is a link is refused, and a sign-out that finds a link there
1853
+ removes the link alone (and the login's signed-in note), runs no CLI through it, and names what it led to. Runs already going are left as a turn-off leaves them, and fail saying the
1854
+ login is signed out at their next read of it. Where each run is a user of its own, a run claimed on the login and
1855
+ started while the mode is off is refused at its start, as after a turn-off; the claim checks the login's folder, not
1856
+ its account, so a run claimed before Sign out and started after a new sign-in may run on the new account. What Sign
1857
+ out does not guarantee for a run still going: where runs stay in the runner's process, the run's CLI holds the login's
1858
+ refresh token itself and may write a renewed token pair back into `<data>/claude-login` after the folder is removed
1859
+ (nothing removes it again when that run ends), so once such runs end, a turn-on that reads `signed_in` again means
1860
+ Sign out again. The runner's own renewal, for
1861
+ runs that are users of their own, never writes back to a removed login. This machine's own login (`place` `machine`)
1862
+ is the person's: the sign-out is refused (403) with nothing touched, and the words say to run `claude auth logout` in
1863
+ a terminal there. The console's Claude login row offers Sign out only while AgentRun's own login is signed in.
1804
1864
 
1805
1865
  While it is on, a claude-agent run on an `anthropic/<model>` model goes on the login: its CLI gets no
1806
1866
  `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` or key, no model proxy runs, and the CLI's sandbox denies its commands
@@ -2103,7 +2163,8 @@ it is Parallel on the server's key, else keyless Firecrawl, or the provider pick
2103
2163
  unavailable for a workflow.
2104
2164
 
2105
2165
  Where the server holds a TypeSafe key (`TYPESAFE_API_KEY`, set or saved), Jev runs on the web tools by default, and
2106
- run content goes to TypeSafe. Each `web_search` sends TypeSafe its objective and each result's URL, title and snippet.
2166
+ run content goes to TypeSafe. Each `web_search` sends TypeSafe its objective and each result's URL, title, snippet and
2167
+ published date (when the provider gives one).
2107
2168
  Each `web_fetch` given an objective sends TypeSafe the page's text (up to 1,000,000 characters, in chunks) and the
2108
2169
  objective; a fetch with no objective sends nothing. TypeSafe bills every request to the server's TypeSafe key. To
2109
2170
  keep the old behaviour on a server that holds the key, set `AGENTRUN_WEB_JEV_OFF=1`. Jev (`jev-1.14.0`) scores each
@@ -2118,7 +2179,7 @@ OpenRouter key runs no ranking; `AGENTRUN_WEB_JEV_OFF=1` on the server turns Jev
2118
2179
  set, on whatever runner host claims it (the run's plane carries the switch, and keeps it at every later launch); a
2119
2180
  runner's own switch can add off for the runs that host claims, never turn it back on. `GET /capabilities`' `why` for
2120
2181
  each tool says what it sends TypeSafe, or that Jev is off: for `web_search` `…; Jev (jev-1.14.0) ranks results …; each
2121
- search sends that and each result's URL, title and snippet to TypeSafe …`, for `web_fetch` `…; a fetch given an
2182
+ search sends that and each result's URL, title, snippet and published date to TypeSafe …`, for `web_fetch` `…; a fetch given an
2122
2183
  objective sends the page's text and the objective to TypeSafe …`, and for either `…; Jev off: no TypeSafe key` or
2123
2184
  `…; Jev off (AGENTRUN_WEB_JEV_OFF)`.
2124
2185
 
@@ -3783,7 +3844,8 @@ serves these routes alone:
3783
3844
  are the console's, refused here;
3784
3845
  - what an agent learned, for the backend whose runs it learned from: the loop's compile turns
3785
3846
  (`GET /agents/{id}/learning/loop`), each learned workflow's promotion and what serves
3786
- (`GET /agents/{id}/learning/promotions`), the cost per run (`GET /agents/{id}/learning/cost`) and a run's learning
3847
+ (`GET /agents/{id}/learning/promotions`), the audit ledger of the workflows that serve
3848
+ (`GET /agents/{id}/learning/audits`), the cost per run (`GET /agents/{id}/learning/cost`) and a run's learning
3787
3849
  (`GET /runs/{id}/learning`), each cut of the host's secrets as the console's reads are; and its reset
3788
3850
  (`DELETE /agents/{id}/learning`, the agent and its runs kept), its one learning write served here;
3789
3851
  - a run's hosted machine fetching this server's computerd build (`GET /computers/daemon`), with the token its create
@@ -4351,21 +4413,22 @@ stays in every total.
4351
4413
  overwrites them. `VACUUM FULL` rewrites the table into a new file (under an exclusive lock), and the old file's
4352
4414
  blocks go back to the filesystem unwiped. Postgres's own WAL and its archived WAL keep the old values until they are
4353
4415
  recycled or expire, and backups keep them for their retention.
4354
- - Its agent's other runs and what the agent learned from it are kept. A promotion record keeps the run's id and the
4355
- commits it names. A run's purge removes its diff file and its feedback line from the folder's current files, and the
4356
- folder's history no longer serves its merge; the bytes stay in the folder's `.git` until a learning reset
4357
- (`DELETE /v2/agents/{id}/learning`) or the agent's purge, which delete the folder whole. Each merge's feedback line goes in
4358
- one commit by the host (none when nothing is left to remove), a line a person edited since stays, and another
4359
- merge's diff that shows the line as context is written without it. The log and a workflow's revisions leave out its
4360
- merges, known by the run the log names for each (its newest 200 changes). A purge takes off main only what the run
4361
- put there, in one host commit: each learned workflow whose `workflow.json` it wrote last (over the whole history,
4362
- past those 200; a host commit that puts a version back names that version's run) goes back, its whole folder, to
4363
- the version before it that no purged run wrote, so another run's champion keeps serving; one it wrote new leaves
4364
- main, its file reads `404`. No run lays its text, and a read at an older commit (a champion by its digest, an SDK
4365
- receipt's pinned commit, a later merge's diff, which shows its files as added) never serves it. Each merge's scrub lands once, so a `DELETE` sent again
4366
- after a stop takes no other run's same line, and a merge of the run made since is scrubbed by it. A second `DELETE`
4367
- does this again. It covers the learning folder on this
4368
- server; a Mode 2 agent's folder on an Archil disk keeps the run's text until a learning reset or the agent's purge.
4416
+ - Its agent's other runs, and what the agent learned from them, are kept. The run's own learning rows go in the purge's
4417
+ transaction: each line it added to `corrections.md`, each learned workflow version it wrote (a person's approve of one
4418
+ goes with it, being still its text; a person's retire or restore of one stays on the version that comes back), its
4419
+ grades, and the promotion records and audit rows of the workflow versions it alone wrote. Its saves stay as facts with
4420
+ no words (a version, its id and its merge key, so the run never merges again), and a person's save that changed only
4421
+ its text loses its words too; no other save names a file or workflow only it wrote.
4422
+ - The purge is a save of the agent's learning (the host's, which the log never shows). A write computed before it (a
4423
+ person's edit, a run's merge) is computed again on what the purge left, so none writes the purged text back. A run of
4424
+ the agent that read its learning before the purge (its seed) has its learning dropped at its end, nothing written
4425
+ (`learning.reason` `purged_since_seed`): the purge changed what it started from, so a file it gives back unchanged
4426
+ can't be told apart from the purged run's. A promotion, audit row or grade written after the purge for what it took
4427
+ (a check of the run's workflow version still replaying, a grade of the purged run) writes nothing. So the log and a
4428
+ workflow's revisions leave it out, and `GET /runs/{id}/learning/diff` is `404`. A workflow it revised goes back to the
4429
+ version before it, so another run's champion keeps serving; one it wrote new is gone, its file reads `404`. A read at
4430
+ an older version id (a champion by its digest, an SDK receipt's pinned save, a later merge's diff) reads the rows as
4431
+ they are now, so it never serves the run's text. A second `DELETE` does this again and finds nothing left.
4369
4432
  - It takes the owner's session (the password sign-in, or the console on a server bound to loopback) or the API token;
4370
4433
  any other console session is `403 forbidden`, no credential `401`. An [API-only](#api-only) server purges a run of
4371
4434
  any agent with its token, as it deletes or purges the whole agent.
@@ -4391,7 +4454,8 @@ delete what it sent. `DELETE /v2/agents/{id}` deletes such an agent whole, in th
4391
4454
  while a `DELETE` runs waits for it, then finds the agent gone (`404`), so none lands after its learning went. Each of
4392
4455
  its runs still going, its learning runs included, is cancelled as `POST /runs/{id}/cancel` cancels it, and the
4393
4456
  delete waits until every one has ended.
4394
- 2. Its learning is deleted by the learning module: every file of its learning folder, then its promotions and grades.
4457
+ 2. Its learning is deleted by the learning module: every learning row of the agent (its corrections, workflows, saves,
4458
+ promotion records, grades and audit rows).
4395
4459
  It refuses while learning work of the agent is in flight: `409 learning_busy`, naming
4396
4460
  that work in `details.runs`.
4397
4461
  3. The rest: its triggers (and what each registered at its source), its saved sign-ins (and each object at its vendor),
@@ -4424,6 +4488,14 @@ server's own origin, under a CSP that allows that origin only, but for the provi
4424
4488
  - **Mission Control**: the store's counts, imported history, analytics and the latest runs, available before the first
4425
4489
  server-run agent and without a model-provider key. Its introduction is dismissible. Connect agent and Query use
4426
4490
  the coding-agent selector; the page refreshes when you return from your coding agent.
4491
+ - **Agent Factory** (`#/factory`): a kanban of sessions reported to this server, including parallel runs of one agent,
4492
+ reported active child conversations, an audit's shadow run while it runs, and sessions without a repository. Waiting, Working, Needs you and Unknown
4493
+ describe execution; a completed run does not prove that its GitHub change passed checks or merged. Cards open the
4494
+ existing run viewer for activity and supported controls. GitHub links come from launch or trusted trigger provenance.
4495
+ Native connector health and missing SDK freshness are explicit; observed sessions do not acquire controls here.
4496
+ Archived active runs remain visible, imported history is excluded, and ended attention is separate from active counts.
4497
+ The board refreshes every ten seconds after a read settles. It reads bounded pages and offers **Load more** with
4498
+ partial-coverage counts; failures preserve the last-known cards with a stale notice.
4427
4499
  - **Agents**: **Build** opens a description composer and local starter templates; **Connected agents** lists definitions,
4428
4500
  with archived ones behind **Archived**. Build, edit and run actions share the remembered coding-agent dropdown,
4429
4501
  including **API playground**. Choosing a template prepares its full definition without creating or running it.
@@ -4452,6 +4524,18 @@ the checks' problems, and the seed and merge revisions. Its changed
4452
4524
  files remain available beside the result. The agent's Learning tab refreshes after returning to the console and
4453
4525
  while visible, without replacing an open edit or review.
4454
4526
 
4527
+ The visibility API uses `GET /v2/runs?scope=active` and `scope=review` (also on an agent's runs route), with `limit`
4528
+ and opaque `next_cursor`. Scope is filtered before pagination; cursors are tied to the scope and agent filters.
4529
+ Do not combine scope with `status` or `archived`. Scoped summaries add `factory` source/control, observation,
4530
+ activity, GitHub provenance and reported-child metadata. A lifecycle version captured inside each run snapshot
4531
+ orders overlapping observations across the two scopes. A run's summary is built once per change of the run and
4532
+ kept on its row, as the runs list keeps its items, so a refresh builds no view of a run that has not changed;
4533
+ only who observes the run and its computer are read at each request (a computer's read opens the run's journal
4534
+ only for a desktop or phone that is up, or a computer held for its owner). GitHub provenance is what the server
4535
+ saved of the delivery that fired the run, never a payload tag found in its input; a run started before servers
4536
+ saved it (0.1.0-beta.39) shows no GitHub link. An online connector is transport health, not a heartbeat for each
4537
+ session. These reads add no scheduling, branch-writing or merge authority.
4538
+
4455
4539
  Its files (`index.html`, and Vite's hashed files under `/assets/`) are public and hold no data: everything it shows
4456
4540
  comes through `/v2`. With accounts on (the default) the console asks for the owner's password
4457
4541
  ([your password](#your-password)) and the browser holds the owner's session cookie; a `?token=` link sets no cookie: the
@@ -4664,22 +4748,25 @@ corrections and shows captured runs; new captures begin with the next normal pro
4664
4748
  Historical learning files remain stored and are not converted into owner corrections or deleted. Older stored
4665
4749
  CLI `learning: "notes"` settings read publicly as `true`; that compatibility read does not rewrite the revision.
4666
4750
 
4667
- An agent that learns has a learning folder, `learning/` in its folder on the disk (`DATA/disk/agents/<key>/learning/`):
4751
+ An agent's learning is kept by the server as versioned rows in its store, SQLite or Postgres alike. It reads as a
4752
+ folder, and the routes name its files by path:
4668
4753
 
4669
4754
  - `corrections.md`, its owner's standing corrections, one `- ` line each, at most 2048 bytes;
4670
4755
  - one folder per learned workflow, `workflows/<name>/`, with its `workflow.json` and its `README.md` (front matter with
4671
4756
  `name` and `description`, and `status: pending` while it waits for its owner's OK).
4672
4757
 
4673
4758
  The server reads and writes it with its own code, in [`src/learn/`](src/learn/SPEC.md), whose `SPEC.md` is the
4674
- folder's contract. The folder is plain git with `main` checked out. The agent's first run that learns makes it, with
4675
- one empty commit on `main`; an agent that does not learn never gets one. The server is its only writer. Every git
4676
- call the server makes there runs with the folder's hooks and fsmonitor off, no replace refs, no lazy fetch and no system
4677
- or global config, one at a time per agent.
4759
+ contract. Three tables hold it: `learning_saves`, one row per version of the agent's learning (its random 40-hex id,
4760
+ its kind: `init`, `run`, `person` or `purged`, who saved it and why, and a run's merge key, one per run and round);
4761
+ `learning_items`, each item's versions (a note: one line of `corrections.md`; a workflow: its folder's files whole, with
4762
+ its `workflow.json`'s digest), never updated, each naming the run whose text it is; and `learning_records`, its promotion
4763
+ records, grades and audit rows. The server is its only writer, and nothing in it runs. The agent's first run that
4764
+ learns makes its first save, empty; an agent that does not learn never gets one.
4678
4765
 
4679
- Each run of an agent that learns starts from `main` as it is when the run is made, whatever its harness:
4766
+ Each run of an agent that learns starts from the agent's newest save when the run is made, whatever its harness:
4680
4767
 
4681
- - `runs/<id>/learning.json` pins that commit (`seed`). It is written once: a resume or a follow-up reads the same
4682
- commit, however `main` moves on.
4768
+ - The run's launch record pins that save's id (`learning.seed`). It is written once: a resume or a follow-up reads the
4769
+ same save, however the agent's learning moves on.
4683
4770
  - The agent's corrections go into the run's instructions after the agent's, under `# Learned`, so a run reads them
4684
4771
  whatever its tools: `corrections.md` whole, after one line that says they are its owner's standing corrections, to
4685
4772
  follow each one that applies. Nothing picks, ranks or summarizes them: the file's cap keeps it whole. A run with no
@@ -4687,7 +4774,7 @@ Each run of an agent that learns starts from `main` as it is when the run is mad
4687
4774
  pi's system prompt and claude-agent's and codex's instructions: the same channel `CLAUDE.md` and `AGENTS.md` travel
4688
4775
  in. No file is written into the run's work. The pin keeps the section the run reads (`section`), so a resume or a
4689
4776
  follow-up reads the same.
4690
- - The workflows the agent learned, each a folder `workflows/<name>/` on `main` with its `workflow.json` and its
4777
+ - The workflows the agent learned, each a folder `workflows/<name>/` at the run's seed with its `workflow.json` and its
4691
4778
  `README.md`, are the run's as one tool, `learned_workflow {name, input}`, on every harness (pi, claude-agent, codex),
4692
4779
  with no edit of the agent's definition. Only an active, promoted revision is: its `README.md` sets no status, or `active`,
4693
4780
  and its promotion record names the checked champion. A compiled draft without that record is withheld; front
@@ -4695,10 +4782,10 @@ Each run of an agent that learns starts from `main` as it is when the run is mad
4695
4782
  than one line) reads as retired, so no run is given it. Its description names each workflow with the line its README gives, 8 KiB of lines in all: by name, each
4696
4783
  while its line fits, and one that does not, or holds one of the server's secrets, is left out. A README whose front
4697
4784
  matter does not read one way (not closed, or a line that is no key at its left edge) is not read. The pin names the
4698
- ones the run gets (`workflows`), each kept whole in the run's directory (`learned-workflows.json`), outside its work,
4699
- and the ones left out (`workflows_left_out`). The list is fixed when the run starts: a workflow approved or retired
4785
+ ones the run gets (`workflows`), each read whole from the rows at the run's seed when the run is claimed, outside its
4786
+ work, and the ones left out (`workflows_left_out`). The list is fixed when the run starts: a workflow approved or retired
4700
4787
  while it runs is the next run's to get or not. A call checks the workflow again against the agent's own tools as its
4701
- run resolves them, as the commit's checks did: one whose call node names a tool the agent was not
4788
+ run resolves them, as the save's checks did: one whose call node names a tool the agent was not
4702
4789
  granted (or one its run resolves unavailable), whose model node names any tool (a learned model node runs without
4703
4790
  tools, so the checks refuse one too), or that holds a code node or a shell or executor call, is refused before any of
4704
4791
  its nodes runs. It runs with the workflow DSL: each model node on the run's own model (the one the run was made with
@@ -4721,15 +4808,13 @@ Each run of an agent that learns starts from `main` as it is when the run is mad
4721
4808
  runs; set to ask, the `learned_workflow` call asks once, naming every such tool, and the run parks. A run's own draft
4722
4809
  can't call one yet: the checks admitting it are coming.
4723
4810
 
4724
- The server reads the commit with git plumbing, never the working tree. What it holds that is not a regular UTF-8 file of
4725
- 1 MiB or less, or a workflow out of shape, is not read, and the server's stderr names it. A learning fault never blocks
4726
- a run: when the folder cannot be made or read, the run starts with nothing learned. A host without
4727
- git 2.32 or later (what learning's own git calls need) is one such fault, said once on stderr.
4811
+ A workflow out of shape is not read, and the server's stderr names it. A learning fault never blocks a run: when the
4812
+ agent's learning cannot be read, the run starts with nothing learned (`seed_failed`).
4728
4813
 
4729
4814
  ### What a run learns
4730
4815
 
4731
- When a run that learns answers or fails, its end step (`src/runner/reflect-hook.ts`) keeps two things, one commit a
4732
- round on the agent's `main`, whatever its harness:
4816
+ When a run that learns answers or fails, its end step (`src/runner/reflect-hook.ts`) keeps two things, one save a
4817
+ round on the agent's learning, whatever its harness:
4733
4818
 
4734
4819
  - Its owner's words. A grade's words, or a message they sent after the job's first, become one line of
4735
4820
  `corrections.md`, with no model turn: `- ` and the words, whitespace folded. A line that holds one of the server's
@@ -4741,13 +4826,13 @@ round on the agent's `main`, whatever its harness:
4741
4826
  and the run takes it once. The turn (`compilePrompt`, in `src/learn/compile.ts`) gives the agent's last runs (each
4742
4827
  input, its tool calls, its answer and what the person said after it), the workflow language and one worked example,
4743
4828
  and asks for the whole job as one workflow draft. The draft is checked in code and dry-run; what the checks refuse
4744
- goes back to the model, as data, up to 3 times. A draft that passes is committed directly, with no grader: its
4829
+ goes back to the model, as data, up to 3 times. A draft that passes is saved directly, with no grader: its
4745
4830
  promotion check (below) decides whether it serves. A compile whose drafts all failed is recorded as the compile's
4746
4831
  attempt (compile once), and its errors are on the run's learning (`draft_errors`), never silent.
4747
4832
  [`src/learn/SPEC.md`](src/learn/SPEC.md) has the rules.
4748
4833
  - Its answer's quote re-pick, with `learning.repick: true` (off by default): a workflow whose answer quotes the pages
4749
4834
  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
4750
- draft. On, the server rewrites the passing draft before it commits it, so the re-pick reads the pages themselves,
4835
+ draft. On, the server rewrites the passing draft before it saves it, so the re-pick reads the pages themselves,
4751
4836
  sent as untrusted data (the model is told never to follow anything written in them, and the step has no tools), at
4752
4837
  most `learning.repick_max_chars` characters of them (150000 by default, 1 to 400000; past it the longest pages are
4753
4838
  cut first). Its request is the served run's, under the run's cost cap. The setting is read at each compile: turning
@@ -4760,11 +4845,13 @@ owner and no compile due spends nothing on learning, and its learning ends `drop
4760
4845
  work was its learned workflows, each answering, with nothing said after its first message and no compile due, ends
4761
4846
  `dropped` (`empty`) too: "Nothing new: the run only ran a learned workflow."
4762
4847
 
4763
- The round's commit is made with plumbing: the passing draft's files added or changed (its `README.md` with
4848
+ The round's save is one transaction: the passing draft's workflow written whole (its `README.md` with
4764
4849
  `status: pending` when a step calls a tool with no price, to wait for its owner's OK) and the owner's line appended to
4765
- `corrections.md`. Its message is `learning: <run id>: merged`, the reason and a `Run-Id` trailer; `main` moves only from
4766
- the commit the change was made on (once more on a `main` that moved meanwhile), and a run a trailer already names is
4767
- merged, never twice. A draft file that is not on `main` as it was on the run's seed is a conflict, never written over.
4850
+ `corrections.md`, with the run's reason. It is a compare and swap on the agent's newest version (computed once more on
4851
+ a version that moved meanwhile), and its merge key (the run and its round) is taken once, in the same transaction, so a
4852
+ run's round is merged once, never twice. A draft file that is not at the newest version as it was at the run's seed is
4853
+ a conflict, never written over; a seed the agent's learning no longer holds (a reset since) makes the whole merge a
4854
+ conflict that says so.
4768
4855
 
4769
4856
  A new workflow revision serves only once its promotion check passes. For a server-run agent, the first run that lays it replays it on the
4770
4857
  inputs of the agent's last `compile_after` completed runs, one replay run each at workflow cost, and scores each against
@@ -4815,7 +4902,7 @@ evidence and the shadow result through the run-scoped SDK credential.
4815
4902
  The run's `learning` (on `GET /runs/{run_id}`, and `{state, reason, detail}` in run lists, the detail cut to 140
4816
4903
  characters and no time) says how it went: `seeded`, then `reflecting` during its end step, and `merged`, or `dropped`
4817
4904
  with a reason from a closed list (`seed_failed`, `no_budget`, `unknown_cost`, `cancelled`, `crashed`, `reflect_failed`,
4818
- `empty`, `checker`, `use`; a run record with any other reason is not counted). It is `null` for a run that does not
4905
+ `empty`, `checker`, `use`, `reset`, `purged_since_seed`; a run record with any other reason is not counted). It is `null` for a run that does not
4819
4906
  learn (its agent's `learning` is not true, the server's switch was off when it started, or it is a workflow's or an
4820
4907
  imported run). Its `detail` says the same in a person's words, never the machine's: "Started from 2 corrections.",
4821
4908
  "Keeping what this run learned…", "Learned the workflow sort-invoice. Kept your correction.", "Nothing new to keep from
@@ -4845,64 +4932,60 @@ proposed and reused, staleness after a rule changes, and wrong keeps after a pla
4845
4932
  A person reads and changes an agent's learning through this server's own routes (`learning/1` in `/v2/openapi.json`),
4846
4933
  with the token, an archived agent's too:
4847
4934
 
4848
- - `GET /agents/{agent_id}/learning`: `main`'s head, `corrections.md` as `corrections`, the learned workflows (each its
4935
+ - `GET /agents/{agent_id}/learning`: its newest save's id as `main`, `corrections.md` as `corrections`, the learned workflows (each its
4849
4936
  name, files, description, status and `etag`; `status` is one word: `pending` or `retired` as its `README.md` says,
4850
4937
  else where it stands as `.../learning/promotions` says it: `serving`, `checking`, `held` or `stopped`, a champion
4851
- the cost rule stopped included), the first 20 changes on `main` (newest first, each `by: {run}` from its
4852
- `Run-Id` trailer or `{user: true}`, with its commit, time, reason and files), how the agent's runs that tried to learn
4938
+ the cost rule stopped included), the first 20 changes of its log (newest first, each `by: {run}` for a run's merge or
4939
+ `{user: true}` for a person's change, with its save id as `commit`, time, reason and files), how the agent's runs that tried to learn
4853
4940
  fared (`merged`, `dropped` by reason, `in_progress`), counted as `GET /stats` counts them, and `impact`, what
4854
4941
  learning changed: the agent's completed runs that started from at least one learned item (a correction, or a learned
4855
4942
  workflow) against those that started before its first, each side's `runs`; `median_duration_s`, the time to the
4856
4943
  answer (the run's start to its job's end, before its end-of-run step). What a run costs, learning included, and what
4857
4944
  learning itself cost are `.../learning/cost`'s (`summary.before`/`after`, the bill's `learning_usd`).
4858
- Null unless both sides count 2 runs. An agent with no folder answers `main: null`, empty lists and `impact: null`.
4859
- `GET .../learning/log?cursor=&limit=` pages on, up to 200 at a time; a cursor reads the same commit its first page
4860
- did.
4861
- - `GET .../learning/corrections`: `corrections.md` on `main` as `{text, etag, cap_bytes}` (empty text when there is
4945
+ Null unless both sides count 2 runs. An agent with no save yet answers `main: null`, empty lists and `impact: null`.
4946
+ `GET .../learning/log?cursor=&limit=` pages on, up to 200 at a time; a cursor names the version its page stopped at, so the
4947
+ next page starts below it however the log grew since.
4948
+ - `GET .../learning/corrections`: `corrections.md` at the newest save as `{text, etag, cap_bytes}` (empty text when there is
4862
4949
  none). `PUT .../learning/corrections` with `{text}` replaces it whole under `If-Match: <etag>`: a stale ETag is 412,
4863
4950
  none (or `If-Match: *`) 428 `precondition_required`. A text that holds one of the server's secrets, a secret's shape or
4864
4951
  a hidden character, or passes 2048 bytes, is 422 with the problems, and nothing is written. A text read cut of a
4865
- secret and sent back keeps the cut: a person's write never puts a secret back. One commit on `main` in the agent's
4866
- queue, `learning: edited by a person: corrections.md` with a `Changed-By: user` trailer.
4867
- - `GET .../learning/files/{file}`: `corrections.md` or a workflow's file on `main`, with its `ETag`, the file's git blob
4868
- id. `POST .../learning/files/{file}/retire` under `If-Match`, on a workflow's `README.md`, sets `status: retired`: no
4952
+ secret and sent back keeps the cut: a person's write never puts a secret back. One save of the agent's learning,
4953
+ `edited by a person: corrections.md`, which the log shows as `by: {user: true}`.
4954
+ - `GET .../learning/files/{file}`: `corrections.md` or a workflow's file at the newest save, with its `ETag`, its text's
4955
+ blob id (as git would name its bytes). `POST .../learning/files/{file}/retire` under `If-Match`, on a workflow's `README.md`, sets `status: retired`: no
4869
4956
  later run is given it. `POST .../learning/files/{file}/approve` makes a pending workflow active (see
4870
4957
  [Approving a workflow that waits](#approving-a-workflow-that-waits), below). `POST .../learning/files/{file}/restore`
4871
4958
  under `If-Match` gives a retired workflow to every later run again, after checking its files again as a run's draft
4872
4959
  is checked (a refusal is 400 with `problems`, and it stays retired); it takes the owner's password session alone, as
4873
4960
  an approval does. The learning view gives each workflow `last_change` (`{kind, by, at}`: `approved`, `edited`,
4874
4961
  `created`, `retired` or `restored` by a `person`, or `learned` by a `run`) and each retired one `retired` (`{at, by}`).
4875
- - `GET .../learning/workflows/{name}/revisions` lists a learned workflow's revisions on `main`;
4962
+ - `GET .../learning/workflows/{name}/revisions` lists a learned workflow's revisions, newest first;
4876
4963
  `GET .../learning/promotions` its promotion records; `GET .../learning/loop` each compile turn; and
4877
4964
  `GET .../learning/cost` the agent's cost per run, run after run.
4878
- - `DELETE /agents/{agent_id}/learning` resets the agent's learning: its learning folder whole (`corrections.md`, its
4879
- workflows, their history and the audit ledger), here and on every Archil disk its runs used (`503` while one can't be
4880
- reached), then its promotion records and grades. The agent and its runs stay,
4965
+ - `DELETE /agents/{agent_id}/learning` resets the agent's learning: every learning row of the agent (`corrections.md`,
4966
+ its workflows, every save and version of them, its promotion records, grades and audit rows), in one transaction. A
4967
+ run started before it from a save it removed merges nothing: its seed is no longer held, a conflict. The agent and its runs stay,
4881
4968
  with their files, costs and each run's own learning, so the run list, `GET /stats` and `GET /usage` read the same (a
4882
- served run keeps its share of its revision's compile and check); a run's learning diff goes with the folder (404);
4969
+ served run keeps its share of its revision's compile and check); a run's learning diff goes with the rows (404);
4883
4970
  the next run takes the agent path, given nothing learned. It cancels the runs that exist only for learning (replays,
4884
4971
  audit shadows) and waits for them; while a run of the agent's own is still going it is `409 learning_busy` (each named
4885
4972
  in `details.runs`), and nothing is deleted. `204`, a second call and an agent that never learned included. The
4886
4973
  API-only profile serves it too.
4887
4974
  - `GET /runs/{run_id}/learning`: the run's learning whole (its seed, its merge, the corrections it added, the workflow it
4888
4975
  wrote, its compile turn's attempts and the checks' problems), `null` for a run that does not learn.
4889
- `GET /runs/{run_id}/learning/diff`: a merged run's merge commit against its parent, each file's patch as git writes it
4890
- from the first `@@`, or `withheld` (`too_large`, `secret`).
4891
-
4892
- Every read is the folder's snapshot (`.agentrun/snapshot.json`, written last by the same exec as each commit to
4893
- `main`), the files it names, each checked against its blob id (a file that is not, read twice, is a write in flight:
4894
- `503`), and a merge's `.agentrun/diffs/<run>.json`, through the folder's file API: no git and no exec. Every text it
4895
- answers is cut of the server's secrets as they are then; a file name holding one (a workflow named after a value made
4896
- secret since, say) reads `[redacted]` whole, in the workflows, the log's `files` and a diff's `path`, while its route
4897
- still answers the real name to a caller who knows it. A log page reads the snapshot alone (it keeps the newest 200
4898
- changes). A cursor reads at the main it names while this server still holds that snapshot, else as the first page of
4899
- `main` now. Every write to `main` (a run's merge, a person's corrections, retire, approve or restore) is one exec of the learning
4900
- script, a compare and swap on `main`. A symbolic link at the agent's home, its learning folder or the folder's `.git` is never
4901
- followed: a read or a write there answers `500`, and nothing is written.
4976
+ `GET /runs/{run_id}/learning/diff`: a merged run's merge save against the one before it, each file's patch in unified
4977
+ diff form from the first `@@` (as git writes one), `404` once the run is purged or the agent's learning reset, or `withheld` (`too_large`, `secret`).
4978
+
4979
+ Every read is the store's learning rows: the newest save, or a save by its id, read as the rows are now (so a purged
4980
+ run's text is never served at any version). Every text it answers is cut of the server's secrets as they are then; a
4981
+ file name holding one (a workflow named after a value made secret since, say) reads `[redacted]` whole, in the
4982
+ workflows, the log's `files` and a diff's `path`, while its route still answers the real name to a caller who knows it.
4983
+ Every write (a run's merge, a person's corrections, retire, approve or restore) is one save, a compare and swap on the
4984
+ agent's newest version, computed again when another write landed first; one that keeps losing is `503`, to retry.
4902
4985
 
4903
4986
  ### Approving a workflow that waits
4904
4987
 
4905
- A learned workflow whose step calls a tool with no price is committed with `status: pending` in its `README.md` and
4988
+ A learned workflow whose step calls a tool with no price is saved with `status: pending` in its `README.md` and
4906
4989
  given to no run until its owner approves it.
4907
4990
 
4908
4991
  Who can approve: the owner, signed in with their password. No token approves, the server's own included, so a run that reaches this server only through its API (its MCP tools, a sandbox run) can't approve its own workflows. Runs that use bash on the host run as you: they can read this server's files, its session key among them, so no route keeps them from approving. For untrusted tasks, use the sandbox.
@@ -4913,8 +4996,7 @@ carry) and a token sent beside the session. So is every request on a server with
4913
4996
  (`AGENTRUN_ACCOUNTS=0`), which has no password session: its console session comes from the launch code, never the token. With no credential it is 401, as every route.
4914
4997
  `capabilities.learning.approve` is true only for the owner's session; every other caller reads `approve: false` with
4915
4998
  `approve_needs: "password"`. A workflow that is not pending is 400; a stale ETag is 412, none 428. The approval is one
4916
- host commit, `learning: approved by a person: <file>`, with the trailers `Changed-By: user` and `Approved-Via: console`;
4917
- the log shows `by: {user: true, via: "console"}` at the commit's time.
4999
+ save, `approved by a person: <file>`; the log shows `by: {user: true, via: "console"}` at the save's time.
4918
5000
 
4919
5001
  ## A run's cost: its tokens and its basis
4920
5002