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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/CHANGELOG.md +325 -1
  2. package/README.md +332 -88
  3. package/dist/acp-package.d.ts +5 -1
  4. package/dist/acp-package.js +19 -2
  5. package/dist/adapters.d.ts +23 -2
  6. package/dist/adapters.js +106 -33
  7. package/dist/agents-store.js +1 -1
  8. package/dist/answer-text.d.ts +3 -0
  9. package/dist/answer-text.js +22 -0
  10. package/dist/attach-conformance.js +5 -4
  11. package/dist/box-paths.d.ts +3 -2
  12. package/dist/box-paths.js +5 -4
  13. package/dist/browser-computer.d.ts +3 -8
  14. package/dist/browser-computer.js +12 -35
  15. package/dist/browser-cost.js +94 -20
  16. package/dist/capacity.d.ts +1 -1
  17. package/dist/capacity.js +3 -3
  18. package/dist/chatgpt-plan.d.ts +5 -0
  19. package/dist/chatgpt-plan.js +25 -11
  20. package/dist/claude-login-token.d.ts +15 -11
  21. package/dist/claude-login-token.js +167 -107
  22. package/dist/claude-login.d.ts +76 -31
  23. package/dist/claude-login.js +426 -79
  24. package/dist/claude-sign-in.d.ts +3 -0
  25. package/dist/claude-sign-in.js +10 -1
  26. package/dist/cli.js +323 -292
  27. package/dist/composio-made.d.ts +1 -6
  28. package/dist/composio-made.js +1 -6
  29. package/dist/composio-owners.d.ts +26 -0
  30. package/dist/composio-owners.js +36 -0
  31. package/dist/composio-preset.d.ts +56 -23
  32. package/dist/composio-preset.js +173 -77
  33. package/dist/composio-triggers.d.ts +4 -4
  34. package/dist/composio-triggers.js +6 -7
  35. package/dist/compute-cost.js +11 -2
  36. package/dist/computer-attach.d.ts +6 -3
  37. package/dist/computer-attach.js +41 -29
  38. package/dist/computer-held-routes.d.ts +1 -1
  39. package/dist/computer-held-routes.js +9 -4
  40. package/dist/computer-keys.d.ts +11 -1
  41. package/dist/computer-keys.js +26 -1
  42. package/dist/computer-record.js +3 -1
  43. package/dist/computer-view.d.ts +5 -3
  44. package/dist/computer-view.js +10 -6
  45. package/dist/computer-viewer.js +36 -7
  46. package/dist/computers.d.ts +2 -1
  47. package/dist/computers.js +6 -3
  48. package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
  49. package/dist/console/assets/backend-BztxEAvb.js +166 -0
  50. package/dist/console/assets/index-LwNL4L9q.js +619 -0
  51. package/dist/console/assets/share-L84tlUDW.js +6 -0
  52. package/dist/console/assets/styles-CaRKlHke.js +291 -0
  53. package/dist/console/assets/styles-DQo8rzY-.css +1 -0
  54. package/dist/console/index.html +4 -3
  55. package/dist/console/share.html +17 -0
  56. package/dist/decisions.d.ts +17 -7
  57. package/dist/decisions.js +41 -15
  58. package/dist/dial-relay.js +10 -4
  59. package/dist/docker-daemon.js +4 -5
  60. package/dist/docker-host-addresses.js +29 -11
  61. package/dist/email/account.d.ts +6 -0
  62. package/dist/email/account.js +6 -0
  63. package/dist/email/authentication.d.ts +21 -0
  64. package/dist/email/authentication.js +106 -0
  65. package/dist/email/email-faux.d.ts +11 -2
  66. package/dist/email/email-faux.js +21 -5
  67. package/dist/email/mail.d.ts +25 -0
  68. package/dist/email/mail.js +58 -2
  69. package/dist/email/names.js +2 -2
  70. package/dist/email/tools.d.ts +9 -4
  71. package/dist/email/tools.js +95 -13
  72. package/dist/env-switch.d.ts +12 -2
  73. package/dist/env-switch.js +23 -3
  74. package/dist/errors.d.ts +1 -0
  75. package/dist/errors.js +2 -0
  76. package/dist/fal-price.d.ts +11 -1
  77. package/dist/fal-price.js +33 -0
  78. package/dist/faux-computers.js +1 -1
  79. package/dist/filed-answer.d.ts +2 -2
  80. package/dist/filed-answer.js +2 -2
  81. package/dist/graph-served.d.ts +10 -5
  82. package/dist/graph-served.js +40 -10
  83. package/dist/handed-values.js +1 -2
  84. package/dist/harness-check.d.ts +2 -1
  85. package/dist/harness-check.js +45 -12
  86. package/dist/harness-keys.js +9 -6
  87. package/dist/harness-opencode/facts.js +2 -0
  88. package/dist/harness-recipe-entry.d.ts +9 -3
  89. package/dist/harness-recipe-entry.js +18 -9
  90. package/dist/harness-recipe.d.ts +21 -0
  91. package/dist/harness-recipe.js +25 -3
  92. package/dist/harness-table.d.ts +8 -0
  93. package/dist/harness-table.js +17 -6
  94. package/dist/helper-env.d.ts +4 -1
  95. package/dist/helper-env.js +4 -1
  96. package/dist/host-check.d.ts +2 -3
  97. package/dist/host-check.js +13 -7
  98. package/dist/hosted-search.js +1 -1
  99. package/dist/import.d.ts +11 -8
  100. package/dist/import.js +437 -186
  101. package/dist/key-refusal.d.ts +9 -2
  102. package/dist/key-refusal.js +86 -32
  103. package/dist/learn/audit.d.ts +8 -5
  104. package/dist/learn/audit.js +15 -7
  105. package/dist/learn/compile.d.ts +5 -2
  106. package/dist/learn/compile.js +45 -21
  107. package/dist/learn/field-check.d.ts +111 -0
  108. package/dist/learn/field-check.js +174 -0
  109. package/dist/learn/ledger.d.ts +32 -29
  110. package/dist/learn/ledger.js +26 -19
  111. package/dist/learn/promote.d.ts +79 -36
  112. package/dist/learn/promote.js +60 -65
  113. package/dist/learn/secrets.d.ts +4 -0
  114. package/dist/learn/secrets.js +12 -0
  115. package/dist/learned-nodes.d.ts +8 -5
  116. package/dist/learned-nodes.js +8 -5
  117. package/dist/learned-workflow.d.ts +2 -1
  118. package/dist/learned-workflow.js +13 -10
  119. package/dist/learning-cost.d.ts +25 -8
  120. package/dist/learning-cost.js +23 -8
  121. package/dist/learning-setting.d.ts +6 -0
  122. package/dist/learning-setting.js +11 -1
  123. package/dist/listen-first.d.ts +5 -4
  124. package/dist/listen-first.js +4 -5
  125. package/dist/live-reach.d.ts +7 -0
  126. package/dist/live-reach.js +7 -0
  127. package/dist/mcp-api-only-origins.d.ts +15 -0
  128. package/dist/mcp-api-only-origins.js +40 -0
  129. package/dist/mcp-gateway.d.ts +16 -2
  130. package/dist/mcp-gateway.js +41 -3
  131. package/dist/mcp-oauth.d.ts +1 -1
  132. package/dist/mcp-oauth.js +3 -2
  133. package/dist/mcp-probe.d.ts +3 -0
  134. package/dist/mcp-probe.js +3 -0
  135. package/dist/mcp-secret-writes.d.ts +24 -2
  136. package/dist/mcp-secret-writes.js +30 -2
  137. package/dist/mcp-servers-store.d.ts +52 -14
  138. package/dist/mcp-servers-store.js +165 -61
  139. package/dist/mcp-sources.d.ts +1 -2
  140. package/dist/mcp-sources.js +1 -2
  141. package/dist/mcp-store.d.ts +5 -5
  142. package/dist/mcp-store.js +3 -3
  143. package/dist/mcp.js +1 -1
  144. package/dist/model-gateway.d.ts +1 -1
  145. package/dist/model-gateway.js +20 -36
  146. package/dist/ollama-provider.d.ts +23 -9
  147. package/dist/ollama-provider.js +49 -20
  148. package/dist/openapi.js +202 -51
  149. package/dist/otel/genai.d.ts +83 -7
  150. package/dist/otel/genai.js +69 -9
  151. package/dist/otel/tracer.d.ts +42 -13
  152. package/dist/otel/tracer.js +241 -56
  153. package/dist/page.d.ts +7 -1
  154. package/dist/page.js +76 -22
  155. package/dist/paid-calls.d.ts +6 -4
  156. package/dist/paid-calls.js +15 -7
  157. package/dist/place-offers.d.ts +55 -34
  158. package/dist/place-offers.js +93 -54
  159. package/dist/place.d.ts +13 -14
  160. package/dist/place.js +56 -41
  161. package/dist/print.js +1 -1
  162. package/dist/provider.d.ts +3 -2
  163. package/dist/provider.js +17 -8
  164. package/dist/redact/match.d.ts +27 -9
  165. package/dist/redact/match.js +266 -57
  166. package/dist/run-census.d.ts +1 -1
  167. package/dist/run-census.js +4 -5
  168. package/dist/run-cut.js +4 -5
  169. package/dist/run-export-store.d.ts +15 -0
  170. package/dist/run-export-store.js +30 -0
  171. package/dist/run-export.d.ts +139 -0
  172. package/dist/run-export.js +379 -0
  173. package/dist/run-file-cut.d.ts +5 -0
  174. package/dist/run-file-cut.js +13 -0
  175. package/dist/run-launch.js +16 -3
  176. package/dist/run-model-key.d.ts +15 -6
  177. package/dist/run-model-key.js +30 -31
  178. package/dist/run-reads-over-store.js +4 -4
  179. package/dist/run-secrets.js +3 -5
  180. package/dist/run-timeline-served.js +3 -1
  181. package/dist/runnable.js +2 -2
  182. package/dist/runner/adapter-loop.d.ts +35 -18
  183. package/dist/runner/adapter-loop.js +94 -47
  184. package/dist/runner/adapter-run-spec.d.ts +14 -1
  185. package/dist/runner/adapter-run-spec.js +64 -28
  186. package/dist/runner/adapters/pi.js +4 -2
  187. package/dist/runner/audit.d.ts +8 -5
  188. package/dist/runner/audit.js +37 -17
  189. package/dist/runner/beside.js +5 -6
  190. package/dist/runner/claim-secrets.d.ts +10 -3
  191. package/dist/runner/claim-secrets.js +29 -13
  192. package/dist/runner/cli-run-spec.d.ts +18 -0
  193. package/dist/runner/cli-run-spec.js +81 -46
  194. package/dist/runner/compare-end.d.ts +2 -1
  195. package/dist/runner/compare-end.js +25 -10
  196. package/dist/runner/conformance/harness.js +2 -3
  197. package/dist/runner/conformance/subject.d.ts +4 -1
  198. package/dist/runner/harness-loops.js +3 -3
  199. package/dist/runner/held.d.ts +5 -2
  200. package/dist/runner/journal-kinds.d.ts +4 -1
  201. package/dist/runner/journal-kinds.js +22 -4
  202. package/dist/runner/learned-first.js +20 -4
  203. package/dist/runner/learning-end.d.ts +2 -8
  204. package/dist/runner/learning-end.js +11 -19
  205. package/dist/runner/live-ticker.js +7 -5
  206. package/dist/runner/loop-contract.d.ts +0 -2
  207. package/dist/runner/loop.d.ts +7 -0
  208. package/dist/runner/loop.js +1 -0
  209. package/dist/runner/main.js +12 -11
  210. package/dist/runner/mcp-claim.js +21 -5
  211. package/dist/runner/meta-tools.js +3 -2
  212. package/dist/runner/metrics.d.ts +7 -0
  213. package/dist/runner/metrics.js +19 -0
  214. package/dist/runner/model-route.d.ts +10 -7
  215. package/dist/runner/model-route.js +79 -15
  216. package/dist/runner/native-loop.js +10 -8
  217. package/dist/runner/presence.d.ts +1 -4
  218. package/dist/runner/presence.js +6 -8
  219. package/dist/runner/promotion.d.ts +25 -13
  220. package/dist/runner/promotion.js +125 -50
  221. package/dist/runner/redact.d.ts +3 -1
  222. package/dist/runner/redact.js +5 -3
  223. package/dist/runner/responses-fetch.d.ts +36 -0
  224. package/dist/runner/responses-fetch.js +511 -0
  225. package/dist/runner/run-child-host.d.ts +20 -5
  226. package/dist/runner/run-child-host.js +179 -77
  227. package/dist/runner/run-child.js +11 -4
  228. package/dist/runner/runner-check.js +5 -1
  229. package/dist/runner/runner.d.ts +2 -3
  230. package/dist/runner/runner.js +13 -9
  231. package/dist/runner/sdk-loop.js +8 -8
  232. package/dist/runner/spec-holds.d.ts +8 -1
  233. package/dist/runner/spec-holds.js +9 -4
  234. package/dist/runner/workflow-calls.d.ts +9 -0
  235. package/dist/runner/workflow-calls.js +150 -0
  236. package/dist/runner/workflow-first.d.ts +120 -32
  237. package/dist/runner/workflow-first.js +218 -94
  238. package/dist/runner/workflow-spec.js +1 -1
  239. package/dist/runs-over-store.js +8 -7
  240. package/dist/save-once.d.ts +14 -0
  241. package/dist/save-once.js +31 -0
  242. package/dist/scrub-command.d.ts +34 -31
  243. package/dist/scrub-command.js +116 -147
  244. package/dist/sdk/runs.d.ts +6 -0
  245. package/dist/sdk/runs.js +89 -10
  246. package/dist/seal-key.js +4 -4
  247. package/dist/secret-cut.d.ts +3 -0
  248. package/dist/secret-cut.js +7 -1
  249. package/dist/secret-rules.d.ts +8 -1
  250. package/dist/secret-rules.js +482 -53
  251. package/dist/secrets.d.ts +51 -9
  252. package/dist/secrets.js +311 -21
  253. package/dist/server-keys.d.ts +4 -3
  254. package/dist/server-keys.js +4 -3
  255. package/dist/server-secrets-store.js +2 -4
  256. package/dist/server.d.ts +15 -3
  257. package/dist/server.js +312 -80
  258. package/dist/share-context.d.ts +22 -0
  259. package/dist/share-context.js +76 -0
  260. package/dist/shell-lex.d.ts +105 -0
  261. package/dist/shell-lex.js +646 -0
  262. package/dist/sign-ins-store.d.ts +5 -7
  263. package/dist/sign-ins-store.js +12 -16
  264. package/dist/sign-ins.d.ts +7 -11
  265. package/dist/sign-ins.js +40 -41
  266. package/dist/skills/agentrun-serve/SKILL.md +5 -2
  267. package/dist/start-switches.d.ts +6 -5
  268. package/dist/start-switches.js +8 -4
  269. package/dist/stats.d.ts +5 -1
  270. package/dist/stats.js +1 -1
  271. package/dist/store/agent-body.js +2 -2
  272. package/dist/store/dialect.d.ts +4 -0
  273. package/dist/store/dialect.js +1 -0
  274. package/dist/store/index.d.ts +2 -2
  275. package/dist/store/index.js +1 -1
  276. package/dist/store/mcp-record-keys.d.ts +10 -0
  277. package/dist/store/mcp-record-keys.js +13 -0
  278. package/dist/store/postgres/dialect.js +2 -0
  279. package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
  280. package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
  281. package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
  282. package/dist/store/postgres/store.js +4 -0
  283. package/dist/store/schema.d.ts +33 -10
  284. package/dist/store/schema.js +70 -16
  285. package/dist/store/seal.d.ts +4 -1
  286. package/dist/store/sqlite/run-launch.d.ts +3 -10
  287. package/dist/store/sqlite/run-launch.js +12 -23
  288. package/dist/store/sqlite/run-patch.d.ts +17 -10
  289. package/dist/store/sqlite/run-patch.js +50 -13
  290. package/dist/store/sqlite/store.d.ts +3 -0
  291. package/dist/store/sqlite/store.js +116 -34
  292. package/dist/store/store-schema.js +3 -4
  293. package/dist/store/store.d.ts +67 -32
  294. package/dist/store/store.js +14 -11
  295. package/dist/store-reads/analytics.d.ts +2 -1
  296. package/dist/store-reads/analytics.js +7 -5
  297. package/dist/store-reads/learning.d.ts +35 -26
  298. package/dist/store-reads/learning.js +120 -92
  299. package/dist/store-reads/stats.d.ts +2 -2
  300. package/dist/store-reads/stats.js +13 -7
  301. package/dist/store-view.js +10 -7
  302. package/dist/suggestions.d.ts +1 -1
  303. package/dist/suggestions.js +29 -13
  304. package/dist/template-eval.d.ts +72 -9
  305. package/dist/template-eval.js +358 -64
  306. package/dist/timeline/labels.d.ts +1 -1
  307. package/dist/timeline/labels.js +4 -3
  308. package/dist/timeline/timeline.d.ts +23 -11
  309. package/dist/timeline/timeline.js +115 -31
  310. package/dist/timeline/web-calls.d.ts +8 -6
  311. package/dist/timeline/web-calls.js +10 -6
  312. package/dist/tool-gate.d.ts +13 -1
  313. package/dist/tool-gate.js +43 -3
  314. package/dist/tool-keys-store.js +2 -4
  315. package/dist/tool-keys.d.ts +11 -0
  316. package/dist/tool-keys.js +16 -0
  317. package/dist/tool-plane.d.ts +50 -11
  318. package/dist/tool-plane.js +94 -30
  319. package/dist/tools.d.ts +5 -1
  320. package/dist/tools.js +7 -7
  321. package/dist/trigger-email.js +12 -6
  322. package/dist/triggers.d.ts +15 -34
  323. package/dist/triggers.js +119 -126
  324. package/dist/validate.d.ts +8 -1
  325. package/dist/validate.js +163 -23
  326. package/dist/web-fake.d.ts +2 -1
  327. package/dist/web-fake.js +8 -6
  328. package/dist/web-fetch.d.ts +8 -6
  329. package/dist/web-fetch.js +13 -11
  330. package/dist/web-holds.d.ts +32 -0
  331. package/dist/web-holds.js +86 -0
  332. package/dist/web-run.d.ts +32 -5
  333. package/dist/web-run.js +75 -28
  334. package/dist/web-save.js +23 -12
  335. package/dist/web-search.js +14 -25
  336. package/dist/wires.d.ts +4 -3
  337. package/dist/wires.js +5 -4
  338. package/dist/workspace/archil-claim.d.ts +12 -5
  339. package/dist/workspace/archil-claim.js +45 -5
  340. package/dist/workspace/attach.js +52 -19
  341. package/dist/workspace/attached-computers.d.ts +6 -2
  342. package/dist/workspace/attached-computers.js +5 -4
  343. package/dist/workspace/computer-deps.d.ts +23 -6
  344. package/dist/workspace/computer-deps.js +35 -17
  345. package/dist/workspace/computer-for-claim.d.ts +21 -4
  346. package/dist/workspace/computer-for-claim.js +160 -54
  347. package/dist/workspace/computer-intervals.d.ts +2 -0
  348. package/dist/workspace/computer-intervals.js +1 -1
  349. package/dist/workspace/computer-janitor.d.ts +48 -14
  350. package/dist/workspace/computer-janitor.js +153 -44
  351. package/dist/workspace/computer-kept.d.ts +158 -32
  352. package/dist/workspace/computer-kept.js +288 -63
  353. package/dist/workspace/computer-providers.d.ts +8 -3
  354. package/dist/workspace/computer-providers.js +12 -5
  355. package/dist/workspace/index.d.ts +1 -1
  356. package/dist/workspace/index.js +1 -1
  357. package/dist/workspace/local.js +41 -1
  358. package/dist/workspace/mount-revoke-left.d.ts +31 -0
  359. package/dist/workspace/mount-revoke-left.js +72 -0
  360. package/dist/workspace/paired-route.js +4 -5
  361. package/dist/workspace/resolve-computer.d.ts +5 -2
  362. package/dist/workspace/resolve-computer.js +9 -3
  363. package/dist/workspace/run-end-computers.d.ts +11 -5
  364. package/dist/workspace/run-end-computers.js +153 -28
  365. package/dist/workspace/run-tools.d.ts +22 -3
  366. package/dist/workspace/run-tools.js +17 -5
  367. package/dist/workspace/run-workspace.d.ts +14 -1
  368. package/dist/workspace/run-workspace.js +34 -1
  369. package/dist/workspace/workspace.d.ts +6 -0
  370. package/package.json +12 -13
  371. package/skills/agentrun-serve/SKILL.md +5 -2
  372. package/templates/README.md +22 -6
  373. package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
  374. package/dist/console/assets/index-Bwn1oTem.css +0 -1
  375. package/dist/console/assets/index-DPh29cyz.js +0 -747
@@ -7,6 +7,7 @@ import { type AdapterRun, type AdapterRunSpec } from "./adapter-loop.js";
7
7
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
8
8
  import { type ClaimModelKey } from "./claim-secrets.js";
9
9
  import { type Claim } from "./loop-contract.js";
10
+ import { type RunLogin } from "../claude-login.js";
10
11
  /** The shared claim-time computer types live on the base spec (adapter-run-spec.ts), re-exported for this module's API. */
11
12
  export type { ClaimComputer, ClaimDeps, ClaimLaunch, ComputerForClaim } from "./adapter-run-spec.js";
12
13
  /** What the runner hands the CLI spec builder: the same deps the pi spec takes (computerForClaim, computerDeps and
@@ -73,6 +74,23 @@ export declare function sweepEarlier(harnesses: string, epoch: number): Promise<
73
74
  * removed, then each of `parents` in order while it is empty: one another claim of the run has laid things in since (a
74
75
  * follow-up's) stays, with what is in it. Run again over what a cut-off sweep left, it finishes it. */
75
76
  export declare function sweepScratch(harnesses: string, epoch: number, parents: readonly string[]): Promise<void>;
77
+ /** The login a run starts on: Claude Code's login on this machine, where the owner turned it on for claude-agent here
78
+ * (claude-login.ts), the run carrying only where it is, its CLI saying it is signed in before the run starts. A run that
79
+ * brought its own key (`keyed`) runs on that key, and a run in a sandbox place on the model keys. A run's own process (no
80
+ * seal key: a user of its own, which cannot open the login's folder) goes on its runner's reader of the login's access
81
+ * token alone (held.ts claudeLogin), each token it hands held by `hold` (the redactors) and this process's own; its CLI
82
+ * then never gets a refresh token. Such a process never reads the login's setting itself: whether its run is on the
83
+ * login is its runner's to say. Its claim read the setting (run-child-host.ts staysInRunner), so a turn-on after the
84
+ * claim never moves it onto a login the claim did not check (a user of its own, a process runner on the same folder);
85
+ * a claim that read it on has the runner read it again at the start, which refuses the start in fixed words when that
86
+ * read names none or another folder. Nor could the process read it: the setting names the machine by the id in the
87
+ * server's data folder (claude-login.ts machineId), which the run's user can neither read nor make there. The runner's
88
+ * answer is the one decision (none: not on the login). A
89
+ * claim on a login other than AgentRun's own folder never gets this far: the claim itself is refused (staysInRunner,
90
+ * in LOGIN_MACHINE_NEEDS_SERVER_USER's words). A run in the runner itself (a seal key) reads the setting here. */
91
+ export declare function runLoginOf(deps: Pick<CliSpecDeps, "store" | "data" | "env" | "sealKey">, keyed: boolean, name: string | undefined, place: {
92
+ readonly mode: string;
93
+ }, hold: (values: string[]) => void): Promise<RunLogin | undefined>;
76
94
  /**
77
95
  * One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
78
96
  *
@@ -49,7 +49,7 @@ import { runTools, withKindTools } from "../workspace/run-tools.js";
49
49
  import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
50
50
  import { loadArchilSettings } from "../archil-settings.js";
51
51
  import { settingOfDefinition } from "../computer-setting.js";
52
- import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
52
+ import { computerFilesNote, computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
53
53
  import { computerTurnedOff, hadComputer, recordComputerOff } from "./computer-journal.js";
54
54
  import { hostLifecycle } from "./adapter-loop.js";
55
55
  import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, graderRouteOf, heldModelOf, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, seedEvalFiles, webHostTools } from "./adapter-run-spec.js";
@@ -72,10 +72,9 @@ import { journalEntries } from "./journal-reader.js";
72
72
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
73
73
  import { replayCallsOver } from "./promotion.js";
74
74
  import { learnedFirstWhereHeld } from "./learned-first.js";
75
- import { pathMetrics } from "./workflow-first.js";
76
75
  import { AUDIT_PARKED, withAudit } from "./audit.js";
77
76
  import { compareEndOfRun, GRADER, withGrader } from "./compare-end.js";
78
- import { runPathOverStore } from "../store-reads/learning.js";
77
+ import { runPathMetricsOverStore } from "../store-reads/learning.js";
79
78
  import { specBuilt } from "./spec-holds.js";
80
79
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
81
80
  import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
@@ -91,7 +90,7 @@ import { monidForClaim, withMonid } from "./monid-run.js";
91
90
  import { verifyPlacedProject, movedSkillFiles } from "../source-sync/claim.js";
92
91
  import { projectCheckpointForRun } from "./project-checkpoint.js";
93
92
  import { sourceAuxiliaryAdmitter } from "../source-sync/auxiliary.js";
94
- import { routeTrace } from "../otel/genai.js";
93
+ import { agentOfRun, routeTrace } from "../otel/genai.js";
95
94
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
96
95
  export const cliRefusesKind = (kind) => kind === "browser" ? "This agent's computer is a browser, which only the pi harness drives here: pick pi for this agent, or another kind of computer in Settings → Computers." : undefined;
97
96
  /** The run's model and the catalog that prices it, as main chooses a CLI run's (app.ts wireModels and runModels): on the
@@ -255,6 +254,28 @@ async function rmEmptyParents(parents) {
255
254
  }
256
255
  }
257
256
  }
257
+ /** The login a run starts on: Claude Code's login on this machine, where the owner turned it on for claude-agent here
258
+ * (claude-login.ts), the run carrying only where it is, its CLI saying it is signed in before the run starts. A run that
259
+ * brought its own key (`keyed`) runs on that key, and a run in a sandbox place on the model keys. A run's own process (no
260
+ * seal key: a user of its own, which cannot open the login's folder) goes on its runner's reader of the login's access
261
+ * token alone (held.ts claudeLogin), each token it hands held by `hold` (the redactors) and this process's own; its CLI
262
+ * then never gets a refresh token. Such a process never reads the login's setting itself: whether its run is on the
263
+ * login is its runner's to say. Its claim read the setting (run-child-host.ts staysInRunner), so a turn-on after the
264
+ * claim never moves it onto a login the claim did not check (a user of its own, a process runner on the same folder);
265
+ * a claim that read it on has the runner read it again at the start, which refuses the start in fixed words when that
266
+ * read names none or another folder. Nor could the process read it: the setting names the machine by the id in the
267
+ * server's data folder (claude-login.ts machineId), which the run's user can neither read nor make there. The runner's
268
+ * answer is the one decision (none: not on the login). A
269
+ * claim on a login other than AgentRun's own folder never gets this far: the claim itself is refused (staysInRunner,
270
+ * in LOGIN_MACHINE_NEEDS_SERVER_USER's words). A run in the runner itself (a seal key) reads the setting here. */
271
+ export async function runLoginOf(deps, keyed, name, place, hold) {
272
+ if (keyed)
273
+ return undefined;
274
+ if (deps.sealKey)
275
+ return loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, place);
276
+ const handed = await runnerSeam()?.claudeLogin();
277
+ return handed && heldTokenLogin(handed, hold);
278
+ }
258
279
  /**
259
280
  * One claimed CLI run's AdapterRunSpec, built from its launch record and its revision.
260
281
  *
@@ -354,15 +375,6 @@ async function cliSpec(launch, run, deps, claim, holds) {
354
375
  });
355
376
  }
356
377
  }
357
- // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
358
- // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
359
- // Before the session opens: a refusal (a granted tool its pin does not hold, a pinned meta tool) ends the run in its words.
360
- // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
361
- const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
362
- redact.hold(values); };
363
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, web, launch) });
364
- // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
365
- holds.hold({ passed: mcp });
366
378
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
367
379
  // on the claim's Archil disk (archil-claim.ts: its keys from the store's sealed rows, under the runner's seal key, in
368
380
  // this claim's memory only, dropped at the release); else Mode 1, the run's local folder.
@@ -386,6 +398,25 @@ async function cliSpec(launch, run, deps, claim, holds) {
386
398
  ? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
387
399
  : await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
388
400
  holds.hold({ ws });
401
+ // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
402
+ // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
403
+ // Before the session opens: a refusal (a granted tool its pin does not hold, a pinned meta tool) ends the run in its words.
404
+ // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
405
+ // A held run its model kept from running at its create (hold.refused) opens none: nothing can call one.
406
+ const heldRefusal = launch.hold?.refused?.message;
407
+ // What its gateway files (a long answer, a server's results) goes in the run's own files. In Mode 1 that is the run's
408
+ // folder on this machine (ws.workspace below, the folder a box bind-mounts). In Mode 2 it is the run's Archil disk:
409
+ // through the run's computer once it mounts the folder (filedIn, set at runTools), since the mount holds the disk's
410
+ // write delegation and a write over the disk's file API is refused (409) while it does; over that file API (ws.workspace)
411
+ // when no computer mounts it. The gateway reads work() only when a call is answered (mcp-gateway.ts textOf, fileResults),
412
+ // and a call reaches it only through the session this spec returns, after `tools` is made. After the run's Workspace,
413
+ // as the pi spec makes it: a refusal lets the Workspace and the Archil claim go (holds above).
414
+ let filedIn;
415
+ const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
416
+ redact.hold(values); };
417
+ const mcp = heldRefusal !== undefined ? undefined : await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => (mode === 2 ? filedIn ?? ws.workspace : ws.workspace), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.composioMcpOrigin ? { composioMcpOrigin: deps.composioMcpOrigin } : {}), ...reach, ...claimMetering(deps, web, launch) });
418
+ // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
419
+ holds.hold({ passed: mcp });
389
420
  // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
390
421
  const checkout = body.checkout ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part }), body.checkout) : undefined;
391
422
  holds.hold({ checkout });
@@ -425,9 +456,10 @@ async function cliSpec(launch, run, deps, claim, holds) {
425
456
  // whose computer is a browser is refused in words at its claim, before anything is made.
426
457
  // A person's stop ends the claim's waits at once: a first image pull or registration (Agent37's runs minutes) among them.
427
458
  // Whether an earlier claim made the run a computer of its own is the run's journal's to say (hadComputer), as the pi
428
- // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount). Its
429
- // screen's recording (computer.record) goes in the run's recordings folder, as the pi spec's does.
430
- { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(offAlready ? { turnedOff: offAlready } : {}), recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
459
+ // spec asks it. The computer a park kept, attached again, brings its mount credential with it (inheritMount); a park's
460
+ // row names the disk that credential is on (mountDisk). Its screen's recording (computer.record) goes in the run's
461
+ // recordings folder, as the pi spec's does.
462
+ { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(offAlready ? { turnedOff: offAlready } : {}), recordings: { folder: recordingsFolder(deps.data, runRow.agentId, claim.runId), say: (words) => run.phase?.(words) }, hadComputer: () => hadComputer(deps.journal(claim), context), stopRun: stopRunWith((refusal) => run.ledger.pause(refusal)), ...(run.ledger ? { compute: { ledger: { paid: run.ledger.paid, pause: (refusal) => run.ledger.pause(refusal), judges: () => run.ledger.judges?.() ?? true }, env: deps.env } } : {}), ...(claimSignal ? { signal: claimSignal } : {}), ...(archil ? { revokeMount: () => archil.revoke(), inheritMount: () => archil.inherit(), mountDisk: () => archil.disk.id } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onStarting: (said) => run.phase?.(computerStartingWords(said)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
431
463
  holds.hold({ computer });
432
464
  const loopComputer = loopComputerOf(computer.computer, computer.held, computer.made);
433
465
  const heldComputer = heldSpecOf(launch, loopComputer);
@@ -453,6 +485,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
453
485
  const bashPolicy = bashPolicyOf(body.toolSettings);
454
486
  // A computer that replaced an earlier claim's holds its acts to what it showed, as the pi spec's does.
455
487
  const tools = await runTools(ws.workspace, computer.computer, { mode, context, aliases: [scratch], ...(computer.hold ? { hold: computer.hold } : {}), ...(bashPolicy === undefined ? {} : { bashPolicy }), ...(computer.replaced ? { replaced: true } : {}) });
488
+ filedIn = tools.workspace;
456
489
  let remoteProjectCapture = false;
457
490
  holds.hold({ tools: { end: () => remoteProjectCapture ? Promise.resolve() : tools.end() } });
458
491
  const root = runFolder(deps.data, runRow.agentId, claim.runId);
@@ -488,16 +521,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
488
521
  if (runKey)
489
522
  holdRunKey(redact, runKey);
490
523
  }
491
- // Claude Code's login on this machine, where the owner turned it on for claude-agent here (claude-login.ts): the run
492
- // carries only where it is, and its CLI says it is signed in before the run starts. A run that brought its own key
493
- // runs on that key, and a run in a sandbox place on the model keys. A run's own process (a user of its own, which
494
- // cannot open the login's folder) goes on its runner's reader of the login's access token alone (held.ts claudeLogin),
495
- // each token it hands held by the redactors and this process's own; its CLI then never gets a refresh token. Whether
496
- // such a claim goes on the login at all is its runner's answer alone (none: it does not): the setting names the
497
- // machine by the id in the server's data folder (claude-login.ts machineId), which the run's user can neither read nor
498
- // make there.
499
- const handed = keyed || deps.sealKey ? undefined : await runnerSeam()?.claudeLogin();
500
- const login = keyed ? undefined : handed ? heldTokenLogin(handed, hold) : deps.sealKey ? await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, launch.place) : undefined;
524
+ const login = await runLoginOf(deps, keyed, name, launch.place, hold);
501
525
  const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey, claim), login);
502
526
  // A plan-billed recipe's keys saved for its harness alone (harness-keys.ts), opened at each claim for this run's harness
503
527
  // and no other (a run's own process asks its runner, which opens its claim's own: held.ts harnessKeys), held by the
@@ -511,28 +535,31 @@ async function cliSpec(launch, run, deps, claim, holds) {
511
535
  // is chosen, so it never falls to its owner's sign-in (a row counted at its claim may be gone, or not open, by now).
512
536
  // A person's claim that laid none keeps its session on the sign-in (or on nothing) for good: a trigger's message the
513
537
  // claim takes later is refused in it (personOnly), keys saved since or not, as no new claim opens them.
538
+ // A held run its model kept from running (hold.refused, above) opens none: its agent never starts.
514
539
  const recipe = name === undefined ? undefined : planRecipeOf(deps.env ?? {}, name);
515
540
  const recipeKeys = recipe?.keys;
516
541
  let personOnly;
517
542
  if (recipe !== undefined && recipeKeys?.length) {
518
543
  for (const key of recipeKeys)
519
544
  delete env[key];
520
- const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, recipe) : ((await runnerSeam()?.harnessKeys(recipe.digest)) ?? {});
521
- hold(Object.values(opened));
522
- if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
523
- layHarnessKeys(env, opened);
524
- else if (!personStarted(launch))
525
- throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
526
- else
527
- personOnly = RECIPE_TURN_PERSON_ONLY;
545
+ if (heldRefusal === undefined) {
546
+ const opened = deps.sealKey ? await openHarnessKeys(deps.store, deps.sealKey, recipe) : ((await runnerSeam()?.harnessKeys(recipe.digest)) ?? {});
547
+ hold(Object.values(opened));
548
+ if (recipeKeys.every((key) => typeof opened[key] === "string" && opened[key] !== ""))
549
+ layHarnessKeys(env, opened);
550
+ else if (!personStarted(launch))
551
+ throw new ClaimRefused(RECIPE_SIGN_IN_PERSON_ONLY);
552
+ else
553
+ personOnly = RECIPE_TURN_PERSON_ONLY;
554
+ }
528
555
  }
529
556
  // A held run its model kept from running at its create (hold.refused) chooses no model here, and no plan or login is
530
557
  // asked before it: its model's route chooses no model and reads no key, its adapter's provider being the stand-in that
531
- // refuses every request in the create's words (adapters.ts providerOf), never a key or the Claude login. Its claim lays
532
- // only the keys any claim of the run lays (its tools', a key handed with it: claimSecrets lays it no model key) and
533
- // takes no learning step (below), so it holds the computer on a host with no key for its model, and a key saved since
534
- // runs a new run, never this one.
535
- const heldRefusal = launch.hold?.refused?.message;
558
+ // refuses every request in the create's words (adapters.ts providerOf), never a key or the Claude login; a plan-billed
559
+ // agent's adapter is built on no key and refuses its start in those words (harness-table.ts acpPlanEntryOf). Its claim
560
+ // lays only the keys any claim of the run lays (its tools', a key handed with it: claimSecrets lays it no model key, and
561
+ // no key saved for its harness, above) and takes no learning step (below), so it holds the computer on a host with no
562
+ // key for its model, and a key saved since runs a new run, never this one.
536
563
  const chosen = heldRefusal !== undefined ? heldChoice(body.model) : await modelsOf(entry, env, modelAskOf(launch.model, body.model));
537
564
  if (heldRefusal === undefined) {
538
565
  await planBeforeRun(env, chosen.model);
@@ -641,6 +668,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
641
668
  // native tools are named by its facts on the owner's table (factsOf: a module's harness's too).
642
669
  const ownerFacts = factsOf(deps.env, name);
643
670
  const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, { ...(mcp ? { effectOf: (name) => mcp.effectOf(name), argumentsOf: (name) => mcp.argumentsOf(name) } : {}), facts: ownerFacts, turnedOff: offAlready !== undefined, onComputerOff: (kind) => recordComputerOff(run.harness, kind) });
671
+ // A park lets a computer the gate turned off go rather than keep it (SpecHolds Held.computerOff).
672
+ holds.hold({ computerOff: gate.computerOff });
644
673
  // The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
645
674
  // (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
646
675
  // (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
@@ -695,7 +724,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
695
724
  // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself. A held run its model kept from
696
725
  // running takes none of them, as on pi: it settles no audit and starts no replay run, starts on no workflow, and its
697
726
  // tool runs none (so no learned tier is routed, below).
698
- const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: {}, workflows: [] };
727
+ const learned = audits ? await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff: audits.spendOff, admitAuxiliary }, seedLaid?.workflows ?? []) : { choice: { reason: "held" }, workflows: [] };
699
728
  const firstChoice = learned.choice;
700
729
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
701
730
  // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
@@ -765,7 +794,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
765
794
  system: [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line)),
766
795
  // The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
767
796
  // redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
768
- tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
797
+ tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), { results, writes: gate.writes() }), ...[...webTools, ...(askTool ? [askTool] : []), ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
769
798
  context: "fresh",
770
799
  ...(thinking ? { thinking } : {}),
771
800
  };
@@ -809,8 +838,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
809
838
  // The answer's schema: a miss is asked again once (adapter-loop.ts, the output contract's retry), as on pi.
810
839
  ...(body.outputSchema !== undefined ? { outputSchema: body.outputSchema } : {}),
811
840
  ...(cap ? { cap } : {}),
812
- // Its model, as its GenAI trace names it (otel/genai.ts); its requests' host is its CLI's own to choose.
813
- trace: routeTrace({ named: `${chosen.model.provider}/${chosen.model.modelId}`, model: chosen.model.modelId }),
841
+ // Its model, as its GenAI trace names it (otel/genai.ts); its requests' host is its CLI's own to choose. And the agent
842
+ // the run is of (its id and name; the loop cuts them).
843
+ trace: { ...routeTrace({ named: `${chosen.model.provider}/${chosen.model.modelId}`, model: chosen.model.modelId }), agent: await agentOfRun(deps.store.agents, runRow.agentId) },
814
844
  // The run's MCP for a harness with its own client (mcp-run.ts), with its monid endpoints beside it (monid-run.ts):
815
845
  // the catalog tools the session mounts; absent when none.
816
846
  ...(catalog ? { mcp: catalog } : {}),
@@ -834,6 +864,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
834
864
  ...(tools.computer ? { scriptComputer: tools.computer } : {}),
835
865
  // A computer that replaced an earlier claim's: the model is told once, on its next request (the loop's computer note).
836
866
  ...(computer.replaced ? { computerNote: computerReplacedNote(computer.replaced) } : {}),
867
+ // A desktop or a phone that holds none of the run's files: the model is told once in the run where they are, or, where
868
+ // the gate would refuse a save (RunGate.writeBar), that a screenshot can't be saved to them.
869
+ ...(tools.apart ? { computerFilesNote: computerFilesNote({ ...tools.apart, writes: gate.writes(), outlives: computer.outlives === true }) } : {}),
837
870
  workRoot: root,
838
871
  // Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
839
872
  // against on the run's rows.
@@ -861,14 +894,16 @@ async function cliSpec(launch, run, deps, claim, holds) {
861
894
  const metrics = cliRunMetrics(piShaped(entries), booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}`, catalog: await hashedMcpOf(deps.store, claim.runId) });
862
895
  // Its cost is endCost's, read apart (an unknown one written as null, never left out: a follow-up's end clears the
863
896
  // cost an earlier end stored).
864
- return { metrics: { ...metrics, ...pathMetrics(launch, launch.learning ? await runPathOverStore(deps.store, claim.runId, launch.learning, run.redact) : undefined, entries), costBasis: costBasisOf(booked) } };
897
+ return { metrics: { ...metrics, ...(await runPathMetricsOverStore(deps.store, claim.runId, launch, { ...(run.redact ? { redact: run.redact } : {}), choice: firstChoice.reason })), costBasis: costBasisOf(booked) } };
865
898
  },
866
899
  // A run started with hold: true holds its computer for its owner (computer-held.ts), as the pi spec's.
867
900
  ...(heldComputer ? { held: heldComputer } : {}),
868
901
  // The run's Archil mount credential is revoked at its end on every outcome, even with no computer (idempotent with
869
902
  // the computer's release). A run that minted none revokes nothing. At a park, a desktop or a phone is kept for the
870
- // resume instead, its mount credential with it, as the pi spec's.
871
- ...(computer.keeps ? { keptWords: computerKeptWords(computer.keeps) } : {}),
903
+ // resume instead, its mount credential with it, as the pi spec's, said once its row is written; one the gate turned
904
+ // off is not, nor said to be.
905
+ keptWords: () => (computer.keeps === undefined || gate.computerOff() ? undefined : computerKeptWords(computer.keeps)),
906
+ ...(computer.keeps && computer.keepRow ? { keep: () => computer.keepRow() } : {}),
872
907
  release: (how) => holds.release(how),
873
908
  ...(movedProject ? { projectCheckpoint: projectCheckpointForRun({ store: deps.store, agentId: runRow.agentId, claim, launch, tools, computer,
874
909
  workspace: { data: deps.data, sealKey: deps.sealKey, env: deps.env, control: { ...deps.mountControl, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) } },
@@ -15,7 +15,8 @@ export type CompareEndDeps = {
15
15
  };
16
16
  /** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
17
17
  * asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
18
- * agree_on, graderRouteOf), and the two answers are not already the same. In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
18
+ * agree_on, graderRouteOf), and the two answers are not already the same (then a replay keeps only the grade it was judged
19
+ * with, `same` and no model asked). In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
19
20
  * learning ledger, which no run's process may. A comparison that fails keeps no verdict: the pair then differs, compared
20
21
  * whole (compareAnswers), in the log's words. */
21
22
  export declare function compareEndOfRun(launch: RunLaunch, deps: CompareEndDeps): EndOfRunTurn | undefined;
@@ -1,5 +1,5 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
- import { gradeAnswers, sameAnswer } from "../learn/promote.js";
2
+ import { answersPair, comparedGrade, gradeAnswers, gradesOf, knownAnswerText, sameAnswer } from "../learn/promote.js";
3
3
  import { runPathOverStore } from "../store-reads/learning.js";
4
4
  import { auditedAnswerOf } from "./audit.js";
5
5
  import { held, heldEndOfRun } from "./held.js";
@@ -11,17 +11,22 @@ export const GRADER = "grader";
11
11
  const GRADER_MAX_TOKENS = 1_000;
12
12
  /** The job input as the grader reads it: the launch's text, or its typed input as JSON. */
13
13
  const inputText = (input) => (typeof input === "string" ? input : JSON.stringify(input ?? null));
14
- /** The two answers a replay run or a shadow compares at its end: the agent's and the workflow's. A replay's workflow
15
- * answer is its own, when the workflow it replays answered it; the agent's is its graded run's. A shadow's agent answer
16
- * is its own; the workflow's is the served run's answer it audits (its open ledger line's turn). Null: nothing to
17
- * compare. */
14
+ /** The two answers a replay run or a shadow compares at its end: the known one and the workflow's. A replay's workflow
15
+ * answer is its own, when the workflow it replays answered it; its known answer is its source run's newest grade's
16
+ * expected answer written over that run's own answer (knownAnswerText, which the check reads too), else that run's
17
+ * own answer, with that grade (`graded`, null for none), which its verdict keeps. A shadow's agent answer is its own;
18
+ * the workflow's is the served run's answer it audits (its open ledger line's turn). Null: nothing to compare. */
18
19
  async function pairOf(launch, deps, runId) {
19
20
  if (launch.replay) {
20
21
  const path = await runPathOverStore(deps.store, runId, launch.learning, deps.redact);
21
22
  if (path.path !== "workflow" || path.workflow !== launch.replay.workflow)
22
23
  return null;
23
- const [workflow, agent] = [await answerOf(deps.store, runId, BACKGROUND_CONTEXT), await answerOf(deps.store, launch.replay.of, BACKGROUND_CONTEXT)];
24
- return workflow === null || agent === null ? null : { agent, workflow };
24
+ const workflow = await answerOf(deps.store, runId, BACKGROUND_CONTEXT);
25
+ const said = await answerOf(deps.store, launch.replay.of, BACKGROUND_CONTEXT);
26
+ // The grade read once: the verdict keeps it, so the check judges this input on the grade its grader was asked against.
27
+ const graded = await gradeOf(deps.store, launch.replay.of);
28
+ const agent = graded?.expected ? knownAnswerText(said, graded.expected) : said;
29
+ return workflow === null || agent === null ? null : { agent, workflow, graded };
25
30
  }
26
31
  if (launch.audit) {
27
32
  const [agent, workflow] = [await answerOf(deps.store, runId, BACKGROUND_CONTEXT), await auditedAnswerOf({ store: deps.store, context: BACKGROUND_CONTEXT, folder: deps.folder }, runId)];
@@ -29,9 +34,15 @@ async function pairOf(launch, deps, runId) {
29
34
  }
30
35
  return null;
31
36
  }
37
+ /** Run `of`'s newest grade as the check judges it (comparedGrade), null when it has none. */
38
+ async function gradeOf(store, of) {
39
+ const source = await store.runs.get(of);
40
+ return comparedGrade(source ? (await gradesOf(store.settings, source.agentId)).findLast((one) => one.run === of) : undefined);
41
+ }
32
42
  /** The end-of-run step of a replay run or an audit's shadow (its callers pass no other run): its comparison (above),
33
43
  * asked only when the run completed, was not cut, has a grader (its route exists only for a revision that names no
34
- * agree_on, graderRouteOf), and the two answers are not already the same. In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
44
+ * agree_on, graderRouteOf), and the two answers are not already the same (then a replay keeps only the grade it was judged
45
+ * with, `same` and no model asked). In a run's own process the step is its runner's (held.ts endOfRun): it reads other runs and the
35
46
  * learning ledger, which no run's process may. A comparison that fails keeps no verdict: the pair then differs, compared
36
47
  * whole (compareAnswers), in the log's words. */
37
48
  export function compareEndOfRun(launch, deps) {
@@ -42,10 +53,14 @@ export function compareEndOfRun(launch, deps) {
42
53
  return undefined;
43
54
  try {
44
55
  const pair = await pairOf(launch, deps, input.runId);
45
- if (!pair || sameAnswer(pair.agent, pair.workflow))
56
+ if (!pair)
46
57
  return undefined;
58
+ // Equal answers ask no model; a replay's record still keeps the grade it was judged with (Compared.graded).
59
+ if (sameAnswer(pair.agent, pair.workflow))
60
+ return pair.graded === undefined ? undefined : { also: [], compared: { same: true, pair: answersPair(pair.agent, pair.workflow), graded: pair.graded } };
47
61
  const grade = input.grade;
48
- const compared = await gradeAnswers(inputText(launch.input), pair.agent, pair.workflow, { model: input.grader, ask: (request) => grade(request) });
62
+ const verdict = await gradeAnswers(inputText(launch.input), pair.agent, pair.workflow, { model: input.grader, ask: (request) => grade(request) });
63
+ const compared = pair.graded !== undefined ? { ...verdict, graded: pair.graded } : verdict;
49
64
  return { also: [], compared };
50
65
  }
51
66
  catch (error) {
@@ -256,7 +256,7 @@ async function world(subject, t, timing = STEADY) {
256
256
  * it (Claim.lost names that same runner), gives it back as a run it still holds, and the runner that then takes it over
257
257
  * claims a released run, not a lost one: the timeline never says the run went on after the crashed runner was lost. */
258
258
  const claimsSettled = async (name) => void (await Promise.allSettled([...(claiming.get(name) ?? [])]));
259
- const start = async (name, setup, holder, more = {}) => {
259
+ const start = async (name, setup, holder) => {
260
260
  const store = await openCaseStore({ dataDir: dir, role: "runner", url, env, clockFile });
261
261
  stores.push(store);
262
262
  // Each journal commit's outcome, by the claim's epoch (as child.ts records its process's): what a loop wrote, and
@@ -265,7 +265,6 @@ async function world(subject, t, timing = STEADY) {
265
265
  const observedLoop = (deps) => {
266
266
  const loop = factory({
267
267
  ...deps,
268
- ...more,
269
268
  journal: (claim) => new Proxy(deps.journal(claim), {
270
269
  get(target, property) {
271
270
  const value = Reflect.get(target, property, target);
@@ -1116,7 +1115,7 @@ const CASES = [
1116
1115
  answers.push(await input.ask(prompt, { origin: "reflect", deadlineMs: 10_000 }));
1117
1116
  return undefined;
1118
1117
  };
1119
- await w.start("runner-a", { script: [{ say: "the job's answer" }, { say: "a note" }], tools, hooks: quiet, agentId: "agent-1" }, undefined, { endOfRun });
1118
+ await w.start("runner-a", { script: [{ say: "the job's answer" }, { say: "a note" }], tools, hooks: quiet, agentId: "agent-1", endOfRun });
1120
1119
  await w.ended("ended");
1121
1120
  assert.equal(answers.length, 1, "asked once");
1122
1121
  const answer = answers[0];
@@ -1,6 +1,6 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import type { CallRecord } from "../journal-reader.js";
3
- import type { Journal, LoopFactory } from "../loop-contract.js";
3
+ import type { EndOfRunTurn, Journal, LoopFactory } from "../loop-contract.js";
4
4
  /** One step of the model's script: call a tool, say a text, or say the text of the last steer it was given. */
5
5
  export type ScriptStep = {
6
6
  readonly call: ToolName | MetaToolName;
@@ -61,6 +61,9 @@ export interface ConformanceSetup {
61
61
  readonly hooks: KernelHooks;
62
62
  /** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
63
63
  readonly agentId?: string;
64
+ /** The run's end-of-run step, for the subject's spec to carry (AdapterRunSpec.endOfRun), where every run's step comes
65
+ * from: a loop's deps carry none. */
66
+ readonly endOfRun?: EndOfRunTurn;
64
67
  /** Called with each message the subject's model is handed, when the subject can see it (a stand-in's fake reports what
65
68
  * it consumed and at what priority): for a case's failure message to name, never asserted on. */
66
69
  readonly received?: (message: {
@@ -130,11 +130,11 @@ async function loopOn(deps, harness, launch, runId) {
130
130
  const entry = harnessOf(env, harness);
131
131
  // A run that learns supplies its own end-of-run step (reflect + proposal over its store) from its spec builder now,
132
132
  // where the run's Archil claim is: a Mode 2 run's learning folder is on its claim's disk, not this machine's local
133
- // path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The loop prefers the spec's step over its deps' (stepOf); a
134
- // run that does not learn supplies none. The same for the pi and the CLI spec.
133
+ // path (adapter-run-spec.ts / cli-run-spec.ts endOfRun). The spec is the loop's only source of a step; a run that does
134
+ // not learn supplies none. The same for the pi and the CLI spec.
135
135
  return createAdapterLoop((claim, adapterRun) => entry?.facts && entry.adapter
136
136
  ? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
137
- : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), deps.modelRetry ?? {});
137
+ : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim, runner), { ...deps.modelRetry, ...(deps.tracing ? { tracing: deps.tracing } : {}) });
138
138
  }
139
139
  return undefined;
140
140
  }
@@ -67,8 +67,11 @@ export interface Held {
67
67
  * and renewed by it when near its end (claude-login-token.ts LoginTokens), which throws in words where there is none
68
68
  * to hand; `refused(sent)` tells the runner Anthropic refused `sent` (the CLI's 401), so the next ask renews it. Else
69
69
  * none, and the claim does not go on the login: the one answer to that, since the process can read neither the
70
- * setting's machine id nor the login's folder. A claim on a login other than AgentRun's own folder is refused
71
- * (LOGIN_NOT_HANDED). */
70
+ * setting's machine id nor the login's folder. A claim that read the login on has the runner read the setting again
71
+ * here, at the start, and is refused in fixed words (claude-login-token.ts LOGIN_CHANGED_SINCE_CLAIM, no folder in
72
+ * them) when that read names none or another folder, never left to a model key. A claim on a login other than
73
+ * AgentRun's own folder is refused at the claim (run-child-host.ts staysInRunner, LOGIN_MACHINE_NEEDS_SERVER_USER),
74
+ * before this is asked. */
72
75
  claudeLogin(): Promise<{
73
76
  token(): Promise<string>;
74
77
  refused(sent: string): Promise<void>;
@@ -298,11 +298,14 @@ export interface AnswerData {
298
298
  };
299
299
  }
300
300
  /** The calls of a tool a run's journal shows (toolCalls): `ran`, the ids run to a good end, and `unnamed`, those pi
301
- * recorded with no id; `ended`, every id with a result of any kind (done, an error, a refusal or a deny). */
301
+ * recorded with no id; `ended`, every id with a result of any kind (done, an error, a refusal or a deny); `args`, each
302
+ * call's arguments by its id, for the calls run to a good end: those its start (a CLI's) or its model's tool call (pi's)
303
+ * wrote last before that end, never a later one reusing the id. */
302
304
  export type ToolCalls = {
303
305
  readonly ran: ReadonlySet<string>;
304
306
  readonly unnamed: number;
305
307
  readonly ended: ReadonlySet<string>;
308
+ readonly args: ReadonlyMap<string, unknown>;
306
309
  };
307
310
  /** The calls of `tool` `entries` show: a CLI's (agentrun.call.start and its end) and pi's (a pi.tool-result of it), each
308
311
  * call id once, however many records say it. Run to a good end: a CLI's end done, a pi result that is no error. */
@@ -153,14 +153,32 @@ export function toolCalls(entries, tool) {
153
153
  const started = new Set();
154
154
  const ran = new Set();
155
155
  const ended = new Set();
156
+ const args = new Map();
157
+ // Each id's latest arguments not yet run: those a good end then fixes as the call's own. A call reusing an id that
158
+ // already ran changes nothing, and one whose id a refused or denied call had reads its own.
159
+ const asked = new Map();
160
+ const done = (id) => {
161
+ ran.add(id);
162
+ if (!args.has(id) && asked.has(id))
163
+ args.set(id, asked.get(id));
164
+ };
156
165
  let unnamed = 0;
157
166
  for (const entry of entries) {
158
- if (entry.kind === KINDS.callStart && entry.data.tool === tool)
167
+ if (entry.kind === KINDS.callStart && entry.data.tool === tool) {
159
168
  started.add(entry.data.callId);
169
+ asked.set(entry.data.callId, entry.data.input);
170
+ }
171
+ else if (entry.kind === "pi.assistant") {
172
+ const content = entry.model?.[0]?.content;
173
+ for (const block of Array.isArray(content) ? content : []) {
174
+ if (block?.type === "toolCall" && block.name === tool && typeof block.id === "string" && block.id)
175
+ asked.set(block.id, block.arguments);
176
+ }
177
+ }
160
178
  else if (entry.kind === KINDS.callEnd && started.has(entry.data.callId)) {
161
179
  ended.add(entry.data.callId);
162
180
  if (entry.data.status === "done")
163
- ran.add(entry.data.callId);
181
+ done(entry.data.callId);
164
182
  }
165
183
  else if (entry.kind === "pi.tool-result") {
166
184
  const result = entry.model?.[0];
@@ -172,12 +190,12 @@ export function toolCalls(entries, tool) {
172
190
  if (result.isError === true)
173
191
  continue;
174
192
  if (id)
175
- ran.add(id);
193
+ done(id);
176
194
  else
177
195
  unnamed++;
178
196
  }
179
197
  }
180
- return { ran, unnamed, ended };
198
+ return { ran, unnamed, ended, args };
181
199
  }
182
200
  /** How many calls of `tool` `entries` show run to a good end (toolCalls): a call refused, denied, failed or not ended is
183
201
  * not counted. What a tool's own ask counts (tools.ts AskContext.ran), with the calls its gate let through and that
@@ -3,7 +3,7 @@ import { learnsWorkflows } from "./adapter-run-spec.js";
3
3
  import { settleAudits } from "./audit.js";
4
4
  import { held } from "./held.js";
5
5
  import { claimPromotion, promotionGate, replayClaimed, replayLaid, replayRecordedFor, toolFlowsFor } from "./promotion.js";
6
- import { workflowFirstOf } from "./workflow-first.js";
6
+ import { toolStopsOf, workflowFirstOf } from "./workflow-first.js";
7
7
  /** The claim's learned first choice over `laid`, the workflows its seed lay laid (see the file's head). A replay run's
8
8
  * claim that is refused throws ClaimRefused, as replayClaimed does. */
9
9
  export async function learnedFirst(deps, laid) {
@@ -14,12 +14,28 @@ export async function learnedFirst(deps, laid) {
14
14
  if (launch.learning && !launch.replay && !launch.audit)
15
15
  await settleAudits({ store, agentId, revisionId, context, log, folder, shown, ...own });
16
16
  const promotion = claimPromotion({ store, agentId, runId, revisionId, launch, context, log, folder, shown, ...own });
17
- const choice = learnsWorkflows(deps.kind, laidFlows) ? await workflowFirstOf(deps.kind, laidFlows, launch, log, () => pastRunsOverStore(store, agentId), promotionGate(promotion), deps.outputSchema) : {};
17
+ const learns = learnsWorkflows(deps.kind, laidFlows);
18
+ // The agent's past runs, read once for both sides of the money rule: the platform's first choice and the agent's tool.
19
+ let read;
20
+ const past = () => (read ??= pastRunsOverStore(store, agentId));
21
+ let choice = learns ? await workflowFirstOf(deps.kind, laidFlows, launch, log, past, promotionGate(promotion), deps.outputSchema) : { reason: "none_laid" };
18
22
  // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
19
23
  await replayClaimed(store, agentId, runId, launch, choice);
20
24
  const recorded = await replayRecordedFor(store, launch, context);
21
- // The tool runs what serves, never a revision not promoted (promotion.ts toolFlowsFor).
22
- const workflows = await toolFlowsFor(promotion, launch, laidFlows, choice);
25
+ // The tool runs what serves, never a revision not promoted (promotion.ts toolFlowsFor), nor one the money rule stops,
26
+ // whoever made its calls (workflow-first.ts toolStopsOf): a learning run's, not a replay's (it runs its revision, read
27
+ // past or not). A shadow has no learning start (runner/audit.ts): it lays no workflow and reads no past.
28
+ let workflows = await toolFlowsFor(promotion, launch, laidFlows, choice);
29
+ if (learns && launch.learning && !launch.replay && workflows.length) {
30
+ const money = toolStopsOf(await past().catch((error) => ({ unread: error instanceof Error ? error.message : String(error) })), workflows);
31
+ for (const line of money.said)
32
+ log(line);
33
+ workflows = money.flows;
34
+ // A stop asks for its revision on a run nothing else serves or stops first (the run's one WORKFLOW_FIRST entry).
35
+ const stop = money.stops[0];
36
+ if (stop && !choice.serve && !choice.revise)
37
+ choice = { ...choice, reason: "cost_stop", revise: { ...stop, revision: launch.learning.seed, ...(deps.outputSchema !== undefined ? { outputSchema: deps.outputSchema } : {}) } };
38
+ }
23
39
  return { choice, workflows, ...(recorded ? { recorded: [...recorded] } : {}) };
24
40
  }
25
41
  /** learnedFirst where the claim is held: a runner's own (its seal key), else, in a run's own process, its runner's
@@ -100,12 +100,6 @@ export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): bo
100
100
  * onlyLearnedWorkflows asks of a run with nothing new, `handed_back` when it called a learned workflow otherwise,
101
101
  * `agent` when it called none. */
102
102
  export declare function runPathOf(rows: readonly TimelineEvent[]): RunPath;
103
- /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
104
- * or null when it called none by a name. */
105
- export declare function workflowNameOf(calls: readonly {
106
- tool: string;
107
- args: Record<string, unknown>;
108
- }[]): string | null;
109
103
  /**
110
104
  * One compile draft through the checks (the compile turn's `check`): its two files as the folder would hold them
111
105
  * (workflow-draft.ts draftFiles: its workflow.json, and the README.md the host writes from its front matter), against
@@ -160,8 +154,8 @@ export declare function traceFrom(timeline: readonly TimelineEvent[], refuse: re
160
154
  /** The compile turn's facts for run `runId` of agent `agentId` (learn/compile.ts): a revision of the learned workflow
161
155
  * that fits the run's input and whose promotion holds it at main's digest (runner/promotion.ts: its one check on the
162
156
  * agent's own runs fell under the bar; its champion served the run, or the agent did by hand), its text as main holds
163
- * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold compiled
164
- * it, read from the agent's kept learning; a stopped check's none; a connected agent's hold on give-backs only once it
157
+ * it, with the check's numbers and the inputs it disagreed on, once per hold (none when any run since the hold was asked
158
+ * its revise, read from the agent's kept learning; a stopped check's none; a connected agent's hold on give-backs only once it
165
159
  * is due, as a first compile is, on its runs since the hold); else, when the job is due (compileDue: the run
166
160
  * completed, the agent has no learned workflow active or waiting, and it has its definition's compile_after completed
167
161
  * agent runs), a new one, compiled once: one more after a first compile whose drafts all failed their checks, and none