@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37

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 (522) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +417 -219
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +79 -7
  13. package/dist/archil-settings.js +140 -14
  14. package/dist/attach-conformance-cli.d.ts +1 -0
  15. package/dist/attach-conformance-cli.js +18 -0
  16. package/dist/attach-conformance.d.ts +25 -0
  17. package/dist/attach-conformance.js +343 -0
  18. package/dist/attach-images.d.ts +15 -0
  19. package/dist/attach-images.js +59 -0
  20. package/dist/background.d.ts +0 -6
  21. package/dist/background.js +0 -28
  22. package/dist/box-image.d.ts +1 -97
  23. package/dist/box-image.js +4 -284
  24. package/dist/box-paths.d.ts +2 -7
  25. package/dist/box-paths.js +7 -13
  26. package/dist/box-settings.d.ts +0 -11
  27. package/dist/box-settings.js +4 -29
  28. package/dist/browser-commands.js +1 -1
  29. package/dist/browser-computer.d.ts +47 -3
  30. package/dist/browser-computer.js +286 -18
  31. package/dist/browser-cost.d.ts +1 -1
  32. package/dist/browser-live.d.ts +20 -8
  33. package/dist/browser-live.js +50 -27
  34. package/dist/browser-person.d.ts +19 -2
  35. package/dist/browser-person.js +55 -6
  36. package/dist/browser-wait-ended.d.ts +23 -0
  37. package/dist/browser-wait-ended.js +42 -0
  38. package/dist/cap.d.ts +12 -57
  39. package/dist/cap.js +20 -160
  40. package/dist/catalog.d.ts +1 -12
  41. package/dist/catalog.js +3 -33
  42. package/dist/cli.js +17 -26
  43. package/dist/composio-preset.d.ts +36 -0
  44. package/dist/composio-preset.js +179 -0
  45. package/dist/computer-attach.d.ts +125 -0
  46. package/dist/computer-attach.js +330 -0
  47. package/dist/computer-calls.d.ts +48 -0
  48. package/dist/computer-calls.js +126 -0
  49. package/dist/computer-channel.d.ts +57 -0
  50. package/dist/computer-channel.js +115 -0
  51. package/dist/computer-commands.d.ts +1 -1
  52. package/dist/computer-held-routes.d.ts +35 -0
  53. package/dist/computer-held-routes.js +106 -0
  54. package/dist/computer-held.d.ts +48 -0
  55. package/dist/computer-held.js +87 -0
  56. package/dist/computer-keys.d.ts +21 -1
  57. package/dist/computer-keys.js +53 -11
  58. package/dist/computer-live.d.ts +160 -0
  59. package/dist/computer-live.js +643 -0
  60. package/dist/computer-routes.d.ts +1 -4
  61. package/dist/computer-routes.js +3 -5
  62. package/dist/computer-setting.d.ts +2 -0
  63. package/dist/computer-setting.js +38 -1
  64. package/dist/computer-view.d.ts +24 -2
  65. package/dist/computer-view.js +51 -3
  66. package/dist/computer-viewer.d.ts +6 -0
  67. package/dist/computer-viewer.js +297 -0
  68. package/dist/computers.d.ts +79 -12
  69. package/dist/computers.js +147 -28
  70. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  71. package/dist/console/assets/index-DRN62V5v.css +1 -0
  72. package/dist/console/index.html +2 -2
  73. package/dist/docker-daemon.d.ts +2 -2
  74. package/dist/docker-daemon.js +2 -2
  75. package/dist/errors.js +5 -5
  76. package/dist/faux-computers.d.ts +9 -20
  77. package/dist/faux-computers.js +56 -24
  78. package/dist/files.d.ts +1 -9
  79. package/dist/files.js +1 -9
  80. package/dist/github-connection.d.ts +10 -2
  81. package/dist/github-connection.js +65 -2
  82. package/dist/github-faux.js +1 -1
  83. package/dist/github.d.ts +22 -2
  84. package/dist/github.js +42 -8
  85. package/dist/gpu-words.d.ts +14 -0
  86. package/dist/gpu-words.js +21 -0
  87. package/dist/graph-view.d.ts +3 -1
  88. package/dist/graph-view.js +25 -1
  89. package/dist/handed-values.d.ts +1 -1
  90. package/dist/handed-values.js +1 -1
  91. package/dist/harness-install.d.ts +60 -3
  92. package/dist/harness-install.js +322 -34
  93. package/dist/harness.d.ts +1 -0
  94. package/dist/harness.js +36 -2
  95. package/dist/host-tools.d.ts +9 -10
  96. package/dist/host-tools.js +7 -7
  97. package/dist/hosted-search.d.ts +5 -4
  98. package/dist/hosted-search.js +2 -7
  99. package/dist/import-sources.d.ts +10 -0
  100. package/dist/import-sources.js +44 -2
  101. package/dist/import.d.ts +3 -3
  102. package/dist/import.js +37 -6
  103. package/dist/index.d.ts +1 -3
  104. package/dist/index.js +1 -2
  105. package/dist/key-refusal.d.ts +1 -1
  106. package/dist/key-refusal.js +2 -2
  107. package/dist/learn/check.d.ts +11 -2
  108. package/dist/learn/check.js +124 -6
  109. package/dist/learn/commit.d.ts +43 -7
  110. package/dist/learn/commit.js +166 -22
  111. package/dist/learn/folder.d.ts +11 -0
  112. package/dist/learn/folder.js +37 -1
  113. package/dist/learn/general.d.ts +66 -0
  114. package/dist/learn/general.js +73 -0
  115. package/dist/learn/grade.d.ts +22 -1
  116. package/dist/learn/grade.js +107 -16
  117. package/dist/learn/index.d.ts +1 -1
  118. package/dist/learn/index.js +1 -1
  119. package/dist/learn/learning.sh +12 -1
  120. package/dist/learn/notes.d.ts +3 -0
  121. package/dist/learn/notes.js +3 -0
  122. package/dist/learn/reflect.d.ts +14 -2
  123. package/dist/learn/reflect.js +54 -30
  124. package/dist/learn/skills.d.ts +37 -5
  125. package/dist/learn/skills.js +60 -7
  126. package/dist/learned-nodes.d.ts +6 -2
  127. package/dist/learned-workflow.d.ts +43 -9
  128. package/dist/learned-workflow.js +128 -37
  129. package/dist/learning-batch.d.ts +283 -0
  130. package/dist/learning-batch.js +574 -0
  131. package/dist/learning-cost.d.ts +79 -0
  132. package/dist/learning-cost.js +69 -0
  133. package/dist/learning-evals.d.ts +33 -0
  134. package/dist/learning-evals.js +98 -0
  135. package/dist/learning-routes.d.ts +32 -4
  136. package/dist/learning-routes.js +48 -12
  137. package/dist/learning-words.d.ts +9 -0
  138. package/dist/learning-words.js +12 -2
  139. package/dist/learning.d.ts +39 -19
  140. package/dist/learning.js +88 -46
  141. package/dist/live/stream.js +6 -3
  142. package/dist/live/translate.d.ts +4 -3
  143. package/dist/live/translate.js +8 -4
  144. package/dist/live-reach.d.ts +37 -0
  145. package/dist/live-reach.js +62 -0
  146. package/dist/mcp-gateway.d.ts +9 -0
  147. package/dist/mcp-gateway.js +60 -11
  148. package/dist/mcp-oauth.d.ts +57 -7
  149. package/dist/mcp-oauth.js +133 -18
  150. package/dist/mcp-private-hosts.d.ts +4 -4
  151. package/dist/mcp-private-hosts.js +20 -12
  152. package/dist/mcp-probe.d.ts +27 -3
  153. package/dist/mcp-probe.js +106 -29
  154. package/dist/mcp-secret-writes.js +8 -0
  155. package/dist/mcp-servers-store.d.ts +38 -15
  156. package/dist/mcp-servers-store.js +120 -23
  157. package/dist/mcp-store.d.ts +10 -4
  158. package/dist/mcp-store.js +17 -6
  159. package/dist/model-form.d.ts +26 -0
  160. package/dist/model-form.js +80 -0
  161. package/dist/model.d.ts +5 -5
  162. package/dist/model.js +29 -16
  163. package/dist/openapi.d.ts +2 -0
  164. package/dist/openapi.js +586 -64
  165. package/dist/owner.d.ts +0 -1
  166. package/dist/owner.js +0 -2
  167. package/dist/page.d.ts +18 -0
  168. package/dist/page.js +48 -20
  169. package/dist/paid-calls.d.ts +1 -1
  170. package/dist/paid-calls.js +1 -1
  171. package/dist/place-offers.d.ts +96 -0
  172. package/dist/place-offers.js +202 -0
  173. package/dist/place.d.ts +9 -13
  174. package/dist/place.js +21 -32
  175. package/dist/port-models.d.ts +2 -1
  176. package/dist/port-models.js +5 -3
  177. package/dist/print.d.ts +16 -9
  178. package/dist/print.js +15 -17
  179. package/dist/propose.d.ts +4 -0
  180. package/dist/propose.js +34 -11
  181. package/dist/provider.js +3 -2
  182. package/dist/reflect-range.d.ts +8 -1
  183. package/dist/reflect-range.js +1 -1
  184. package/dist/run-cut.d.ts +5 -0
  185. package/dist/run-cut.js +19 -0
  186. package/dist/run-launch.d.ts +28 -3
  187. package/dist/run-launch.js +14 -4
  188. package/dist/run-learning-served.d.ts +2 -2
  189. package/dist/run-manifest.d.ts +2 -2
  190. package/dist/run-manifest.js +2 -2
  191. package/dist/run-reads-over-store.d.ts +1 -1
  192. package/dist/run-repo.d.ts +20 -0
  193. package/dist/run-repo.js +63 -0
  194. package/dist/run-secrets.js +3 -3
  195. package/dist/run-timeline-served.d.ts +1 -1
  196. package/dist/run-timeline-served.js +56 -44
  197. package/dist/run-view.d.ts +8 -5
  198. package/dist/run-view.js +18 -10
  199. package/dist/runnable.d.ts +2 -2
  200. package/dist/runnable.js +6 -2
  201. package/dist/runner/adapter-loop.d.ts +39 -8
  202. package/dist/runner/adapter-loop.js +770 -83
  203. package/dist/runner/adapter-run-spec.d.ts +36 -7
  204. package/dist/runner/adapter-run-spec.js +171 -37
  205. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  206. package/dist/runner/adapters/pi-computer.js +43 -0
  207. package/dist/runner/adapters/pi.d.ts +20 -7
  208. package/dist/runner/adapters/pi.js +111 -26
  209. package/dist/runner/beside.d.ts +7 -3
  210. package/dist/runner/beside.js +26 -12
  211. package/dist/runner/claim-secrets.d.ts +4 -0
  212. package/dist/runner/claim-secrets.js +6 -1
  213. package/dist/runner/cli-run-spec.d.ts +27 -3
  214. package/dist/runner/cli-run-spec.js +198 -74
  215. package/dist/runner/commands.d.ts +8 -2
  216. package/dist/runner/commands.js +31 -6
  217. package/dist/runner/computer-channel.d.ts +34 -0
  218. package/dist/runner/computer-channel.js +61 -0
  219. package/dist/runner/conformance/harness.d.ts +0 -1
  220. package/dist/runner/conformance/harness.js +87 -18
  221. package/dist/runner/conformance/subject.d.ts +1 -1
  222. package/dist/runner/dispatch.js +3 -0
  223. package/dist/runner/end-of-run.d.ts +22 -12
  224. package/dist/runner/end-of-run.js +38 -16
  225. package/dist/runner/github-app.d.ts +2 -1
  226. package/dist/runner/github-app.js +6 -4
  227. package/dist/runner/harness-loops.js +16 -2
  228. package/dist/runner/held-run.d.ts +65 -0
  229. package/dist/runner/held-run.js +158 -0
  230. package/dist/runner/journal-kinds.d.ts +35 -6
  231. package/dist/runner/journal-kinds.js +20 -1
  232. package/dist/runner/journal-reader.d.ts +5 -4
  233. package/dist/runner/journal-reader.js +12 -10
  234. package/dist/runner/learning-ask.d.ts +7 -1
  235. package/dist/runner/learning-ask.js +21 -6
  236. package/dist/runner/learning-dispatch.d.ts +22 -0
  237. package/dist/runner/learning-dispatch.js +77 -10
  238. package/dist/runner/learning-end.d.ts +37 -1
  239. package/dist/runner/learning-end.js +115 -14
  240. package/dist/runner/learning-factory.d.ts +1 -1
  241. package/dist/runner/learning-factory.js +15 -5
  242. package/dist/runner/learning-loop.d.ts +139 -7
  243. package/dist/runner/learning-loop.js +369 -32
  244. package/dist/runner/learning-seed.d.ts +9 -0
  245. package/dist/runner/learning-seed.js +14 -1
  246. package/dist/runner/live-ticker.js +1 -0
  247. package/dist/runner/loop-contract.d.ts +16 -1
  248. package/dist/runner/loop-contract.js +6 -0
  249. package/dist/runner/loop.d.ts +10 -2
  250. package/dist/runner/loop.js +22 -1
  251. package/dist/runner/main.d.ts +13 -1
  252. package/dist/runner/main.js +38 -6
  253. package/dist/runner/mcp-claim.d.ts +11 -4
  254. package/dist/runner/mcp-claim.js +140 -23
  255. package/dist/runner/mcp-github.d.ts +4 -2
  256. package/dist/runner/mcp-github.js +1 -8
  257. package/dist/runner/mcp-run.d.ts +6 -4
  258. package/dist/runner/mcp-run.js +16 -3
  259. package/dist/runner/metrics.d.ts +15 -2
  260. package/dist/runner/metrics.js +21 -2
  261. package/dist/runner/model-route.d.ts +3 -0
  262. package/dist/runner/model-route.js +5 -2
  263. package/dist/runner/pr-checkout.d.ts +60 -0
  264. package/dist/runner/pr-checkout.js +176 -0
  265. package/dist/runner/reflect-hook.d.ts +19 -0
  266. package/dist/runner/reflect-hook.js +20 -8
  267. package/dist/runner/runner.d.ts +26 -0
  268. package/dist/runner/runner.js +231 -27
  269. package/dist/runner/scratch-sweep.d.ts +13 -0
  270. package/dist/runner/scratch-sweep.js +62 -0
  271. package/dist/runner/sessions.d.ts +1 -1
  272. package/dist/runner/spec-holds.d.ts +8 -3
  273. package/dist/runner/spec-holds.js +12 -10
  274. package/dist/runner/store-port.d.ts +7 -2
  275. package/dist/runner/store-secrets.js +21 -4
  276. package/dist/runner/subagent.d.ts +44 -0
  277. package/dist/runner/subagent.js +190 -0
  278. package/dist/runner/workflow-host.d.ts +24 -3
  279. package/dist/runner/workflow-host.js +24 -4
  280. package/dist/runner/workflow-loop.d.ts +6 -3
  281. package/dist/runner/workflow-loop.js +9 -8
  282. package/dist/runner/workflow-spec.d.ts +39 -15
  283. package/dist/runner/workflow-spec.js +143 -40
  284. package/dist/runs-over-store.d.ts +16 -6
  285. package/dist/runs-over-store.js +145 -29
  286. package/dist/seal-key.js +3 -3
  287. package/dist/sealed-settings-store.d.ts +5 -2
  288. package/dist/sealed-settings-store.js +10 -4
  289. package/dist/sealing.js +1 -2
  290. package/dist/secret-cut.d.ts +1 -1
  291. package/dist/secret-cut.js +1 -1
  292. package/dist/secret-writes.d.ts +5 -4
  293. package/dist/secret-writes.js +5 -4
  294. package/dist/server-secrets-store.d.ts +4 -3
  295. package/dist/server-secrets-store.js +15 -9
  296. package/dist/server-secrets.js +3 -2
  297. package/dist/server.d.ts +75 -63
  298. package/dist/server.js +712 -316
  299. package/dist/settings-wake.d.ts +21 -0
  300. package/dist/settings-wake.js +59 -0
  301. package/dist/standard-webhooks.d.ts +4 -1
  302. package/dist/standard-webhooks.js +8 -4
  303. package/dist/store/agent-body.d.ts +9 -2
  304. package/dist/store/agent-body.js +16 -8
  305. package/dist/store/command-wake.d.ts +12 -0
  306. package/dist/store/command-wake.js +37 -0
  307. package/dist/store/deadline.js +9 -5
  308. package/dist/store/dialect.d.ts +6 -0
  309. package/dist/store/dialect.js +5 -0
  310. package/dist/store/index.d.ts +4 -4
  311. package/dist/store/index.js +2 -2
  312. package/dist/store/journal/storage.d.ts +3 -2
  313. package/dist/store/journal/storage.js +15 -6
  314. package/dist/store/postgres/connection.js +9 -4
  315. package/dist/store/postgres/dialect.js +4 -0
  316. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  317. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  318. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  319. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  320. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  321. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  322. package/dist/store/schema.d.ts +2 -1
  323. package/dist/store/schema.js +85 -13
  324. package/dist/store/seal.d.ts +13 -0
  325. package/dist/store/seal.js +19 -0
  326. package/dist/store/sqlite/connection.d.ts +5 -0
  327. package/dist/store/sqlite/connection.js +88 -47
  328. package/dist/store/sqlite/run-patch.d.ts +25 -7
  329. package/dist/store/sqlite/run-patch.js +58 -14
  330. package/dist/store/sqlite/store.js +331 -59
  331. package/dist/store/store.d.ts +330 -21
  332. package/dist/store/store.js +34 -2
  333. package/dist/store-reads/analytics.js +3 -2
  334. package/dist/store-reads/cap.d.ts +2 -4
  335. package/dist/store-reads/cap.js +16 -7
  336. package/dist/store-reads/decisions.d.ts +3 -3
  337. package/dist/store-reads/decisions.js +3 -6
  338. package/dist/store-reads/import-summary.d.ts +1 -1
  339. package/dist/store-reads/journal.d.ts +5 -4
  340. package/dist/store-reads/journal.js +118 -27
  341. package/dist/store-reads/learning.d.ts +34 -4
  342. package/dist/store-reads/learning.js +137 -23
  343. package/dist/store-reads/runs.d.ts +7 -5
  344. package/dist/store-reads/runs.js +17 -10
  345. package/dist/store-reads/stats.js +5 -1
  346. package/dist/store-reads/workflow.d.ts +1 -1
  347. package/dist/store-view.d.ts +5 -0
  348. package/dist/store-view.js +70 -29
  349. package/dist/template-eval.js +8 -5
  350. package/dist/template-github-permissions.d.ts +22 -8
  351. package/dist/template-github-permissions.js +35 -15
  352. package/dist/templates.d.ts +64 -0
  353. package/dist/templates.js +101 -16
  354. package/dist/timeline/timeline.d.ts +30 -1
  355. package/dist/timeline/timeline.js +29 -13
  356. package/dist/timeline/util.d.ts +4 -0
  357. package/dist/timeline/util.js +14 -0
  358. package/dist/tool-blurbs.js +1 -0
  359. package/dist/tool-budget.d.ts +27 -7
  360. package/dist/tool-budget.js +21 -9
  361. package/dist/tool-gate.d.ts +23 -10
  362. package/dist/tool-gate.js +60 -44
  363. package/dist/tool-plane.d.ts +46 -28
  364. package/dist/tool-plane.js +73 -31
  365. package/dist/tools.d.ts +31 -38
  366. package/dist/tools.js +117 -74
  367. package/dist/trigger-adapter.d.ts +4 -0
  368. package/dist/trigger-secrets-shown.d.ts +2 -2
  369. package/dist/trigger-secrets-shown.js +1 -1
  370. package/dist/trigger-signatures.d.ts +26 -6
  371. package/dist/trigger-signatures.js +44 -8
  372. package/dist/trigger-targets.d.ts +2 -0
  373. package/dist/trigger-targets.js +1 -0
  374. package/dist/trigger-webhook.js +5 -2
  375. package/dist/triggers.d.ts +10 -6
  376. package/dist/triggers.js +37 -7
  377. package/dist/turn-end.d.ts +0 -3
  378. package/dist/turn-end.js +0 -3
  379. package/dist/turns.js +16 -1
  380. package/dist/usage-lines.d.ts +1 -1
  381. package/dist/validate.d.ts +6 -0
  382. package/dist/validate.js +41 -4
  383. package/dist/web-fetch.d.ts +1 -1
  384. package/dist/web-search.d.ts +10 -5
  385. package/dist/web-search.js +7 -6
  386. package/dist/webhooks.d.ts +147 -103
  387. package/dist/webhooks.js +564 -324
  388. package/dist/workflow/decision-recovery.d.ts +23 -0
  389. package/dist/workflow/decision-recovery.js +80 -0
  390. package/dist/workflow/decisions.d.ts +134 -0
  391. package/dist/workflow/decisions.js +46 -0
  392. package/dist/workflow/host-session.d.ts +5 -0
  393. package/dist/workflow/host-session.js +85 -0
  394. package/dist/workflow/host-tools.d.ts +3 -0
  395. package/dist/workflow/host-tools.js +3 -0
  396. package/dist/workflow/node-runner.d.ts +113 -0
  397. package/dist/workflow/node-runner.js +270 -0
  398. package/dist/workflow/node.d.ts +89 -0
  399. package/dist/workflow/node.js +101 -0
  400. package/dist/workflow/operator-error.d.ts +4 -0
  401. package/dist/workflow/operator-error.js +4 -0
  402. package/dist/workflow/pi-versions.d.ts +32 -0
  403. package/dist/workflow/pi-versions.js +65 -0
  404. package/dist/workflow/record-file.d.ts +10 -0
  405. package/dist/workflow/record-file.js +56 -0
  406. package/dist/workflow/record-tool.d.ts +77 -0
  407. package/dist/workflow/record-tool.js +126 -0
  408. package/dist/workflow/record.d.ts +151 -0
  409. package/dist/workflow/record.js +401 -0
  410. package/dist/workflow/run-error.d.ts +16 -0
  411. package/dist/workflow/run-error.js +26 -0
  412. package/dist/workflow/runner.d.ts +6 -0
  413. package/dist/workflow/runner.js +240 -0
  414. package/dist/workflow/store.d.ts +23 -0
  415. package/dist/workflow/store.js +242 -0
  416. package/dist/workflow/task.d.ts +133 -0
  417. package/dist/workflow/task.js +412 -0
  418. package/dist/workflow/thinking.d.ts +3 -0
  419. package/dist/workflow/thinking.js +7 -0
  420. package/dist/workflow/tool-context.d.ts +21 -0
  421. package/dist/workflow/tool-context.js +13 -0
  422. package/dist/workflow/types.d.ts +126 -0
  423. package/dist/workflow/types.js +1 -0
  424. package/dist/workflow-run.d.ts +2 -2
  425. package/dist/workspace/agent-computer.d.ts +137 -0
  426. package/dist/workspace/agent-computer.js +292 -0
  427. package/dist/workspace/archil-claim.d.ts +11 -0
  428. package/dist/workspace/archil-claim.js +18 -10
  429. package/dist/workspace/archil-disks.d.ts +49 -0
  430. package/dist/workspace/archil-disks.js +185 -0
  431. package/dist/workspace/archil-exec.js +2 -3
  432. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  433. package/dist/workspace/archil-mount-credential.js +13 -4
  434. package/dist/workspace/attached-computers.d.ts +41 -0
  435. package/dist/workspace/attached-computers.js +114 -0
  436. package/dist/workspace/computer-deps.d.ts +32 -17
  437. package/dist/workspace/computer-deps.js +37 -14
  438. package/dist/workspace/computer-for-claim.d.ts +58 -13
  439. package/dist/workspace/computer-for-claim.js +267 -26
  440. package/dist/workspace/computer-hold.d.ts +11 -27
  441. package/dist/workspace/computer-hold.js +36 -56
  442. package/dist/workspace/computer-janitor.d.ts +3 -2
  443. package/dist/workspace/computer-janitor.js +43 -9
  444. package/dist/workspace/computer-ledger.d.ts +5 -1
  445. package/dist/workspace/computer-ledger.js +11 -0
  446. package/dist/workspace/computer-mcp.d.ts +25 -0
  447. package/dist/workspace/computer-mcp.js +41 -0
  448. package/dist/workspace/computer-ports.d.ts +4 -13
  449. package/dist/workspace/computer-ports.js +4 -107
  450. package/dist/workspace/computer-script.d.ts +37 -0
  451. package/dist/workspace/computer-script.js +138 -0
  452. package/dist/workspace/executors.d.ts +1 -1
  453. package/dist/workspace/index.d.ts +7 -4
  454. package/dist/workspace/index.js +4 -1
  455. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  456. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  457. package/dist/workspace/resolve-computer.d.ts +45 -11
  458. package/dist/workspace/resolve-computer.js +72 -14
  459. package/dist/workspace/run-disk.d.ts +34 -0
  460. package/dist/workspace/run-disk.js +91 -0
  461. package/dist/workspace/run-tools.d.ts +35 -18
  462. package/dist/workspace/run-tools.js +24 -29
  463. package/dist/workspace/server-run-workspace.d.ts +3 -2
  464. package/dist/workspace/server-run-workspace.js +17 -4
  465. package/dist/workspace.js +1 -1
  466. package/package.json +19 -21
  467. package/templates/README.md +9 -6
  468. package/templates/code-review/agent.md +27 -11
  469. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  470. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  471. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  472. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  473. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  474. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  475. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  476. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  477. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  478. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  479. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  480. package/templates/code-review/evals/re-review/prompt.md +1 -1
  481. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  482. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  483. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  484. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  485. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  486. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  487. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  488. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  489. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  490. package/templates/code-review/findings.schema.json +131 -27
  491. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  492. package/templates/code-review/skills/review/DEEP.md +130 -0
  493. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  494. package/templates/code-review/skills/review/SKILL.md +104 -154
  495. package/templates/market-monitor/agent.md +1 -1
  496. package/dist/box/record.d.ts +0 -6
  497. package/dist/box/record.js +0 -41
  498. package/dist/box/sweep.d.ts +0 -53
  499. package/dist/box/sweep.js +0 -193
  500. package/dist/box-egress-vm.d.ts +0 -118
  501. package/dist/box-egress-vm.js +0 -354
  502. package/dist/box-egress.d.ts +0 -105
  503. package/dist/box-egress.js +0 -256
  504. package/dist/box-relay-vm.d.ts +0 -84
  505. package/dist/box-relay-vm.js +0 -437
  506. package/dist/box-relay.d.ts +0 -36
  507. package/dist/box-relay.js +0 -207
  508. package/dist/boxes.d.ts +0 -109
  509. package/dist/boxes.js +0 -249
  510. package/dist/budget.d.ts +0 -71
  511. package/dist/budget.js +0 -199
  512. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  513. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  514. package/dist/daytona-api.d.ts +0 -10
  515. package/dist/daytona-api.js +0 -20
  516. package/dist/egress-proxy.d.ts +0 -45
  517. package/dist/egress-proxy.js +0 -416
  518. package/dist/egress-table.d.ts +0 -24
  519. package/dist/egress-table.js +0 -165
  520. package/dist/run-db.d.ts +0 -53
  521. package/dist/run-db.js +0 -116
  522. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -9,8 +9,11 @@ import { posix } from "node:path";
9
9
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
10
10
  import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
11
11
  import { runLearningBody } from "../learning-routes.js";
12
- import { learningStartOf, readLaunchBody } from "../run-launch.js";
12
+ import { learningStartOf, readLaunchBody, seedFailed } from "../run-launch.js";
13
+ import { said, STOPPED } from "../learning-words.js";
13
14
  import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
15
+ import { costSummary, runCostOf } from "../learning-cost.js";
16
+ import { runPathOf, workflowNameOf } from "../runner/learning-end.js";
14
17
  import { reflects } from "../reflect-range.js";
15
18
  import { notesOf } from "../usage.js";
16
19
  import { runEntries, runReflect, runTimeline } from "./journal.js";
@@ -18,6 +21,7 @@ import { FINAL_STATES } from "../store/store.js";
18
21
  import { journalEntries } from "../runner/journal-reader.js";
19
22
  import { KINDS } from "../runner/journal-kinds.js";
20
23
  import { keptOf, learnedOf, lostOf } from "../runner/learning-loop.js";
24
+ import { GENERAL_NO_BUDGET, GENERAL_NO_ROOM, GENERAL_UNCHECKED } from "../learn/general.js";
21
25
  const timeOf = (ms) => new Date(ms).toISOString();
22
26
  const usdOrNull = (value) => (typeof value === "number" && Number.isFinite(value) ? value : null);
23
27
  /** What a kept row says of a run that looked back (learning-run.ts closeLearning's fields): none for one that did not. */
@@ -26,9 +30,9 @@ function answeredOf(row) {
26
30
  return {};
27
31
  return { answered_at: row.answered_at, job_cost_usd: usdOrNull(row.job_cost_usd), look_back_usd: usdOrNull(row.look_back_usd) };
28
32
  }
29
- /** Run `runId`'s learning end; null when the run kept no learning. Proposed while its learning run has not ended. */
30
- export async function runLearningEnd(store, runId) {
31
- const kept = await store.learning.proposal(runId);
33
+ /** Run `runId`'s learning end (its newest round's, or round `round`'s); null when the run kept no learning. Proposed while its learning run has not ended. */
34
+ export async function runLearningEnd(store, runId, round) {
35
+ const kept = await store.learning.proposal(runId, round);
32
36
  if (!kept)
33
37
  return null;
34
38
  const row = (kept.proposal ?? {});
@@ -58,17 +62,26 @@ async function endOfKept(store, kept, row) {
58
62
  // What the grade spent: the graded entry's, or what a grade that failed spent before it did.
59
63
  const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
60
64
  const cost = spent ? { cost_usd: { grade: spent.usd }, tokens: { grade: spent.tokens ?? null } } : {};
65
+ // A generality check that could not run (learning-loop.ts `unchecked`) is said after the end's words: the grader read
66
+ // every note. Its provider's error stays in the journal.
67
+ // One skipped for no room under the cap (GENERAL_NO_BUDGET) says so.
68
+ const unchecked = graded?.unchecked ?? dropped?.unchecked;
69
+ const skip = unchecked === undefined ? undefined : unchecked === GENERAL_NO_BUDGET ? GENERAL_NO_ROOM : GENERAL_UNCHECKED;
70
+ const withSkip = (detail) => (skip ? [detail, skip].filter(Boolean).join(" ") : detail);
61
71
  if (merged && graded) {
62
- const what = learnedOf(keptOf(row.proposal, graded.verdict), graded.verdict);
72
+ // Each item as the merge settled it: its record's verdict (a note it left out is no longer kept, and says why). A merge
73
+ // recorded with none (before the record kept it) reads no item decisions.
74
+ const verdict = merged.verdict;
75
+ const what = verdict ? learnedOf(keptOf(row.proposal, verdict), verdict) : { learned: [], pending: [], skills: [], workflows: [] };
63
76
  return {
64
- state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, verdict: graded.verdict, graded: { ...graded.graded }, ...cost, merged: merged.commit,
77
+ state: "merged", reason: null, detail: withSkip(merged.detail), at: endedAt, ...left, ...(verdict ? { verdict } : {}), graded: { ...graded.graded }, ...cost, merged: merged.commit,
65
78
  learned: what.learned, ...(what.pending.length ? { pending: what.pending } : {}), ...(what.skills.length ? { skills: what.skills } : {}), ...(what.workflows.length ? { workflows: what.workflows } : {}),
66
79
  };
67
80
  }
68
81
  const reason = (dropped?.reason ?? null);
69
82
  const lost = reason === "grader" ? lostOf(row.proposal) : [];
70
83
  return {
71
- state: "dropped", reason, detail: dropped?.detail ?? null, at: endedAt,
84
+ state: "dropped", reason, detail: withSkip(dropped?.detail ?? null), at: endedAt,
72
85
  ...(dropped?.problems?.length ? { problems: [...dropped.problems] } : left),
73
86
  // The verdict, when one was given; the blobs it read only go with a merge (the server kept them for its merge alone).
74
87
  ...(graded ? { verdict: graded.verdict } : {}), ...cost, ...(lost.length ? { lost } : {}),
@@ -144,15 +157,9 @@ export async function agentLearningOverStore(store, agentId) {
144
157
  kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
145
158
  const final = FINAL_STATES.includes(run.state);
146
159
  const started = await learningStartOfRun(store, run.id);
147
- const end = await runLearningEnd(store, run.id);
148
- // What the run's journal says here (the notes its job opened, what its claims laid of the skills and workflows it was
149
- // offered): read once for a settled run and kept by its epoch (settledJournalReads), else read now.
150
- const offered = !!(started?.skills?.length || started?.workflows?.length);
151
- const journal = async () => ({
152
- read: final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: true })) : [],
153
- laid: offered ? laidOf(await runEntries(store, run.id, BACKGROUND_CONTEXT)) : undefined,
154
- });
155
- const { read, laid } = final ? await settledJournalReads(store, run.id, run.epoch, journal) : await journal();
160
+ // A run that only uses what its agent learned keeps no proposal: its end is its start's (usedOnly), as its run reads give it.
161
+ const end = (await runLearningEnd(store, run.id)) ?? (started?.use ? usedOnly(started, final, timeOf(run.endedAt ?? run.startedAt)) : null);
162
+ const { read, laid } = await journalReadsOf(store, run, started);
156
163
  if (started || end)
157
164
  files.push(notesOf({ given: started?.given ?? [], read }));
158
165
  // The row learningImpact reads (the file path's RunRow): an ended run is a completed one.
@@ -163,10 +170,78 @@ export async function agentLearningOverStore(store, agentId) {
163
170
  });
164
171
  // What its claims laid of the skills and workflows it was offered (every learningLaid entry, laidOf): the run started
165
172
  // from those alone.
166
- learnings.set(run.id, end ? impactLearningOf(end, started, laid) : null);
173
+ learnings.set(run.id, end ? impactLearningOf(end, started, laid, await roundsSpendOf(store, run.id)) : null);
167
174
  }
168
175
  return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
169
176
  }
177
+ /** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
178
+ * agentic runs that ended (ended, stopped or failed), oldest first, numbered from 1, with its own cost and what learning
179
+ * added for it (runCostOf over its row's cost and its learning's spend, learningSpendOf), the path it took and the learned workflow it called
180
+ * (journalReadsOf), and the learned revision it started from (its launch's seed); and what the series shows
181
+ * (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left out; a learning
182
+ * run (a run's grade and merge) is no run of the list, and its cost is its run's learning. `limit`: the latest runs
183
+ * shown, each keeping its number; the summary is over every run. */
184
+ export async function agentCostOverStore(store, agentId, limit = Infinity) {
185
+ const kinds = new Map();
186
+ const ended = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
187
+ const runs = [];
188
+ for (const run of ended) {
189
+ if (!kinds.has(run.revisionId))
190
+ kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
191
+ if (kinds.get(run.revisionId) === "workflow")
192
+ continue;
193
+ runs.push(await costRunOf(store, run, runs.length + 1));
194
+ }
195
+ return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length };
196
+ }
197
+ /** What run `runId`'s learning spent, as its cost per run counts it: what it kept as it answered (`looked`: answeredOf),
198
+ * and its grade's spend (`grade`): its learning run's cost once that run ended, stopped or failed (runner/learning-loop.ts
199
+ * keeps the grade's spend there, a paid grade a person stopped included; null when unknown), 0 while it runs or when the
200
+ * run queued none. */
201
+ async function learningSpendOf(store, runId) {
202
+ const kept = await store.learning.proposal(runId);
203
+ if (!kept)
204
+ return { looked: null, grade: 0 };
205
+ const looked = answeredOf((kept.proposal ?? {}));
206
+ const learningRun = kept.learningRunId ? await store.runs.get(kept.learningRunId) : undefined;
207
+ return { looked, grade: learningRun && FINAL_STATES.includes(learningRun.state) ? (learningRun.costUsd ?? null) : 0 };
208
+ }
209
+ /** One run of the cost series, as number `n` of it: its figures and its path (agentCostOverStore's loop body, and a learning
210
+ * batch's row once the run's learning has settled). */
211
+ export async function costRunOf(store, run, n) {
212
+ const started = await learningStartOfRun(store, run.id);
213
+ // A run a follow-up opened again (a review's, a person's) learned in rounds: every round's look-back and grade are its
214
+ // learning (roundsSpendOf), never the newest round's alone.
215
+ const rounds = await roundsSpendOf(store, run.id);
216
+ const { looked, grade } = rounds ? { looked: rounds, grade: rounds.grade_usd } : await learningSpendOf(store, run.id);
217
+ const { path, workflow } = await journalReadsOf(store, run, started);
218
+ return { n, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, ...runCostOf(run.costUsd, looked, grade) };
219
+ }
220
+ /** What a run's journal tells the agent's learning view and its cost per run: the notes its job opened (`read`, once
221
+ * final), what its claims laid of the skills and workflows it was offered (`laid`), and, for a run offered a learned
222
+ * workflow, the path it took and the workflow it called last (`path`, `workflow`: runner/learning-end.ts
223
+ * runPathOf, workflowNameOf; any other run's path is `agent`). Read once for a settled run and kept by its epoch
224
+ * (settledJournalReads), else read now. */
225
+ async function journalReadsOf(store, run, started) {
226
+ const final = FINAL_STATES.includes(run.state);
227
+ const offered = !!(started?.skills?.length || started?.workflows?.length);
228
+ const flows = !!started?.workflows?.length;
229
+ const journal = async () => {
230
+ const rows = (final && started?.given.length) || flows ? await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: final }) : [];
231
+ const entries = offered ? await runEntries(store, run.id, BACKGROUND_CONTEXT) : [];
232
+ const path = flows ? runPathOf(rows) : "agent";
233
+ return {
234
+ read: final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), rows) : [],
235
+ laid: offered ? laidOf(entries) : undefined,
236
+ path,
237
+ // Only a name the launch offered: a call's raw `name` (a failed call's included) is the model's text, never shown.
238
+ workflow: path === "agent" ? null : offeredName(workflowNameOf([...callArgsOf(entries).values()]), started?.workflows),
239
+ };
240
+ };
241
+ return final ? settledJournalReads(store, run.id, run.epoch, journal) : journal();
242
+ }
243
+ /** `name` when it is one of the learned workflows the run's launch offered, else null. */
244
+ const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
170
245
  /** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
171
246
  * and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
172
247
  * next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
@@ -204,16 +279,42 @@ export function laidOf(entries) {
204
279
  }
205
280
  return { skills: [...skills], workflows: [...workflows] };
206
281
  }
282
+ export async function roundsSpendOf(store, runId) {
283
+ const newest = await store.learning.proposal(runId);
284
+ if (!newest || newest.round < 2)
285
+ return undefined;
286
+ let first;
287
+ let look = 0;
288
+ let grade = 0;
289
+ for (let round = 1; round <= newest.round; round++) {
290
+ const kept = round === newest.round ? newest : await store.learning.proposal(runId, round);
291
+ if (!kept)
292
+ continue;
293
+ const answered = answeredOf((kept.proposal ?? {}));
294
+ if (!first && answered.answered_at !== undefined)
295
+ first = answered;
296
+ // A round that never looked back (no figures kept) added none.
297
+ look = look === null || answered.look_back_usd === null ? null : look + (answered.look_back_usd ?? 0);
298
+ const learningRun = kept.learningRunId ? await store.runs.get(kept.learningRunId) : undefined;
299
+ const spent = learningRun && FINAL_STATES.includes(learningRun.state) ? (learningRun.costUsd ?? null) : 0;
300
+ grade = grade === null || spent === null ? null : grade + spent;
301
+ }
302
+ if (!first || typeof first.answered_at !== "string")
303
+ return undefined;
304
+ return { answered_at: first.answered_at, job_cost_usd: first.job_cost_usd ?? null, look_back_usd: look, grade_usd: grade };
305
+ }
207
306
  /** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
208
307
  * it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
209
308
  * not); its grade's cost once it ended (0 when nothing was graded). */
210
- function impactLearningOf(end, started, laid) {
309
+ function impactLearningOf(end, started, laid, rounds) {
211
310
  const over = end.state === "merged" || end.state === "dropped";
212
- const looked = end.answered_at !== undefined ? { answered_at: end.answered_at, job_cost_usd: end.job_cost_usd ?? null, look_back_usd: end.look_back_usd ?? null } : over ? { look_back_usd: 0 } : {};
311
+ // A run a follow-up opened again: its job answered at its first round's end, and every round's look-back and grade are
312
+ // its learning (the newest round's `job_cost_usd` also holds the earlier rounds' look-backs, never the job's own).
313
+ const looked = rounds ? { answered_at: rounds.answered_at, job_cost_usd: rounds.job_cost_usd, look_back_usd: rounds.look_back_usd } : end.answered_at !== undefined ? { answered_at: end.answered_at, job_cost_usd: end.job_cost_usd ?? null, look_back_usd: end.look_back_usd ?? null } : over ? { look_back_usd: 0 } : {};
213
314
  return {
214
315
  state: end.state, reason: end.reason, at: end.at, ...(started?.seedNotes !== undefined ? { seed_notes: started.seedNotes } : {}),
215
316
  ...(laid?.skills.length ? { seed_skills: laid.skills.length } : {}), ...(laid?.workflows.length ? { seed_workflows: laid.workflows.length } : {}), ...looked,
216
- ...(over ? { grade_usd: end.cost_usd ? end.cost_usd.grade : 0 } : {}),
317
+ ...(over ? { grade_usd: rounds ? rounds.grade_usd : end.cost_usd ? end.cost_usd.grade : 0 } : {}),
217
318
  };
218
319
  }
219
320
  /** The notes a run's job read (learning-run.ts noteRead's rule, over the runner's journal rows): its own successful
@@ -354,18 +455,31 @@ async function learningStartOfRun(store, runId) {
354
455
  const launch = row ? readLaunchBody(row.body) : undefined;
355
456
  return launch ? learningStartOf(launch) : undefined;
356
457
  }
458
+ /** The learning of a run that only uses what its agent learned (`learning: "use"`): seeded while it runs, as a run that
459
+ * learns is; dropped `use` once it ended, since it is never asked what to keep. */
460
+ export function usedOnly(started, terminal, at) {
461
+ // A start that could not be made (a folder unreadable or not copied) handed the run nothing: said so from its start, as
462
+ // the end hook says it for a run that learns, never "seeded" and then `use`. No proposal is written for it.
463
+ if (seedFailed(started)) {
464
+ const why = started.seedFailed === "unreadable" ? STOPPED.unreadable : started.seedFailed === "not_copied" ? STOPPED.notCopied : STOPPED.noSeed;
465
+ return { state: "dropped", reason: "seed_failed", detail: said.stopped(why), at };
466
+ }
467
+ return terminal ? { state: "dropped", reason: "use", detail: said.use, at } : { state: "seeded", reason: null, detail: said.seeded(started.seedNotes ?? 0), at };
468
+ }
357
469
  /** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
358
470
  * run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
359
471
  * what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
360
472
  * read only when it held something; none: as the merge wrote it), settled once the run is final. Null when the run kept
361
473
  * no learning. */
362
474
  export async function runLearningOverStore(store, runId, shown, secrets, statuses) {
363
- const end = await runLearningEnd(store, runId);
364
- if (!end)
365
- return null;
366
475
  const started = await learningStartOfRun(store, runId);
367
476
  const row = await store.runs.get(runId);
368
477
  const settled = row !== undefined && FINAL_STATES.includes(row.state);
478
+ // A run that only uses what its agent learned keeps no proposal: its learning is its start (seeded, then dropped `use`
479
+ // once it ended), the same words its run view gives.
480
+ const end = (await runLearningEnd(store, runId)) ?? (started?.use && row ? usedOnly(started, settled, timeOf(row.endedAt ?? row.startedAt)) : null);
481
+ if (!end)
482
+ return null;
369
483
  const used = started?.given.length || started?.skills?.length || started?.workflows?.length;
370
484
  const [reflect, rows, entries] = used ? await Promise.all([runReflect(store, runId, BACKGROUND_CONTEXT), runTimeline(store, runId, BACKGROUND_CONTEXT, { settled }), runEntries(store, runId, BACKGROUND_CONTEXT)]) : [undefined, [], []];
371
485
  const read = started?.given.length ? notesReadOf(started.given, reflect, rows) : [];
@@ -1,5 +1,5 @@
1
- import type { Context } from "@earendil-works/chord";
2
- import type { ImportedFrom, RunRow, Store } from "../store/store.js";
1
+ import type { Context } from "@earendil-works/chord/context";
2
+ import { type ImportedFrom, type RunRow, type Store } from "../store/store.js";
3
3
  /** A revision's kind, as the row names it. */
4
4
  export type RevisionKind = "agentic" | "workflow";
5
5
  /** The run state the v2 API serves, as the old store kept it: a non-terminal run is 'running' (the live view refines its
@@ -19,9 +19,11 @@ export interface RunRowView {
19
19
  readonly archivedAt?: string;
20
20
  readonly importedFrom?: ImportedFrom;
21
21
  }
22
- /** A run's v2 state from A's state and an ended run's outcome: an escalation reads 'escalated', a plain completion
23
- * 'completed'; stopped and failed are their own; queued, running and parked read 'running'. */
24
- export declare function runReadState(run: RunRow): RunReadState;
22
+ /** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
23
+ * stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
24
+ * stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
25
+ * stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
26
+ export declare function runReadState(run: RunRow, kind: RevisionKind): RunReadState;
25
27
  /** The runs, newest first; `agent` and `revision` narrow it. Archived runs are listed too (the server filters them), with
26
28
  * the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
27
29
  export declare function listRuns(store: Store, filter: {
@@ -1,16 +1,19 @@
1
+ import { stoppedByPerson } from "../store/store.js";
1
2
  import { spentOverStore } from "./cap.js";
2
3
  const isoOf = (ms) => new Date(ms).toISOString();
3
- /** A run's v2 state from A's state and an ended run's outcome: an escalation reads 'escalated', a plain completion
4
- * 'completed'; stopped and failed are their own; queued, running and parked read 'running'. */
5
- export function runReadState(run) {
6
- return stateOf(run);
4
+ /** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
5
+ * stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
6
+ * stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
7
+ * stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
8
+ export function runReadState(run, kind) {
9
+ return stateOf(run, kind);
7
10
  }
8
- function stateOf(run) {
11
+ function stateOf(run, kind) {
9
12
  switch (run.state) {
10
13
  case "ended":
11
14
  return run.outcome === "escalated" ? "escalated" : "completed";
12
15
  case "stopped":
13
- return "stopped";
16
+ return stoppedByPerson(run, kind) ? "running" : "stopped";
14
17
  case "failed":
15
18
  return "failed";
16
19
  default:
@@ -21,16 +24,20 @@ function stateOf(run) {
21
24
  * (the booked-so-far spend for a run not ended, else its stored cost). */
22
25
  function viewOf(run, agentArchivedAt, kind, cost) {
23
26
  const archivedAt = run.archivedAt ?? agentArchivedAt;
27
+ const state = stateOf(run, kind);
28
+ // A run that reads running has no end to show: a person's stop keeps its time and words in the store, for its reopen
29
+ // to clear, and the run is not over.
30
+ const over = state !== "running";
24
31
  return {
25
32
  id: run.id,
26
33
  agent: run.agentId,
27
34
  revision: run.revisionId,
28
35
  kind,
29
- state: stateOf(run),
36
+ state,
30
37
  startedAt: isoOf(run.startedAt),
31
- ...(run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
38
+ ...(over && run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
32
39
  ...(cost !== null ? { costUsd: cost } : {}),
33
- ...(run.summary !== null ? { summary: run.summary } : {}),
40
+ ...(over && run.summary !== null ? { summary: run.summary } : {}),
34
41
  ...(archivedAt !== null ? { archivedAt: isoOf(archivedAt) } : {}),
35
42
  ...(run.importedFrom !== null ? { importedFrom: { source: run.importedFrom.source, session: run.importedFrom.session } } : {}),
36
43
  };
@@ -47,7 +54,7 @@ function joins(store, context) {
47
54
  kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind ?? "agentic");
48
55
  // A run that has not ended shows the spend booked so far (the cap's own reading over the journal, the figure it holds
49
56
  // the run to), since cost_usd is written only at the end; an ended run shows its stored cost.
50
- const cost = runReadState(run) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
57
+ const cost = runReadState(run, kinds.get(run.revisionId)) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
51
58
  return viewOf(run, agentArchived.get(run.agentId), kinds.get(run.revisionId), cost);
52
59
  },
53
60
  };
@@ -16,8 +16,12 @@ export async function stats(store) {
16
16
  const shown = new Map();
17
17
  const hidden = new Map();
18
18
  const running = [];
19
+ // Each revision's kind, read once: an agentic run a person stopped reads running (runReadState).
20
+ const kinds = new Map();
19
21
  for (const run of runs) {
20
- const state = runReadState(run);
22
+ if (!kinds.has(run.revisionId))
23
+ kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow" ? "workflow" : "agentic");
24
+ const state = runReadState(run, kinds.get(run.revisionId));
21
25
  const runArchived = run.archivedAt !== null;
22
26
  if (state === "running" && !runArchived && !archivedAgent.has(run.agentId))
23
27
  running.push(run.id);
@@ -1,4 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import { type WorkflowRunView } from "../workflow-run.js";
3
3
  import type { Store } from "../store/store.js";
4
4
  /** The workflow run `runId`'s view from A: its graph's node status, and, once it ended, its outcome, the node it escalated
@@ -20,6 +20,11 @@ export interface ViewDeps {
20
20
  * for its owner's OK reads as it stands there. None: as the merge wrote it. */
21
21
  readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
22
22
  }
23
+ /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
24
+ * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
25
+ * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
26
+ * the answer before it. */
27
+ export declare const answerOf: (rows: readonly TimelineEvent[]) => string | null;
23
28
  /** GET /runs/{id}'s answer from the store, byte-identical to runs.ts's view for the same run. Undefined for an unknown run. */
24
29
  export declare function viewOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
25
30
  /** The run list's answer from the store, byte-identical to runs.ts's summary: the view's subset a list shows. */
@@ -4,7 +4,7 @@
4
4
  // model sees do not change. runs.ts still answers the API from files; this is the store-backed path the server cut switches
5
5
  // onto. viewOverStore answers the run read, summaryOverStore the run list, momentOverStore the one acceptance each act reads.
6
6
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
7
- import { CAPS } from "./timeline/index.js";
7
+ import { CAPS, isMessageRow } from "./timeline/index.js";
8
8
  import { runLink } from "./console-links.js";
9
9
  import { redacted, redactedAnswer, redactedOutput, withoutLoopback } from "./key-refusal.js";
10
10
  import { structuredAnswer } from "./answer-json.js";
@@ -13,25 +13,25 @@ import { said } from "./learning-words.js";
13
13
  import { CONTENT_FILTER_WORDS, contentFiltered, MODERATED } from "./content-filter.js";
14
14
  import { launchOf } from "./handed-values.js";
15
15
  import { learningStartOf, seedFailed } from "./run-launch.js";
16
- import { momentOf, pendingOf, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costView, soFarOf, withAsks, withApprovalRows, } from "./run-view.js";
16
+ import { momentOf, pendingOf, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costView, soFarOf, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
17
17
  import { reflects } from "./reflect-range.js";
18
18
  import { overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
19
19
  import { bookedSpend } from "./runner/metrics.js";
20
20
  import { journalRecords, recordOf } from "./runner/journal-reader.js";
21
21
  import { capNowOf, KINDS } from "./runner/journal-kinds.js";
22
- import { notesReadOf, runLearningEnd, withNotes } from "./store-reads/learning.js";
22
+ import { notesReadOf, runLearningEnd, usedOnly, withNotes } from "./store-reads/learning.js";
23
23
  import { runReflect, runTimeline, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
24
24
  import { readRun } from "./store-reads/runs.js";
25
- import { runCutValues, runErrorWordsOf } from "./run-cut.js";
25
+ import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
26
26
  import { Turns } from "./turns.js";
27
27
  import { harnessOfBody } from "./harness.js";
28
28
  import { browserAsk as browserAskOf, BROWSER_HANDOVER_KIND } from "./browser-commands.js";
29
29
  import { computerAsk as computerAskOf, COMPUTER_HANDOVER_KIND } from "./computer-commands.js";
30
30
  import { approvalsOf } from "./approvals.js";
31
- import { FINAL_STATES } from "./store/store.js";
31
+ import { FINAL_STATES, stoppedByPerson } from "./store/store.js";
32
32
  /** A run that has ended reads one of these (the old RunRow state → the v2 status: an escalation is a completion with a
33
33
  * review; a stopped run is a cancellation), as runs.ts's STATUS_OF mapped them. A running run reads its status from the
34
- * journal. */
34
+ * journal, and so does an agentic run a person stopped, which reads running (runReadState). */
35
35
  const STATUS_OF = { completed: "completed", failed: "failed", escalated: "completed", stopped: "cancelled" };
36
36
  /** A run that has reached a last state (its view is its ended shape). */
37
37
  const TERMINAL = new Set(["completed", "failed", "cancelled"]);
@@ -43,9 +43,9 @@ const iso = (ms) => new Date(ms).toISOString();
43
43
  const servedByStore = new WeakMap();
44
44
  const SERVED_KEPT = 32;
45
45
  function servedOnce(store, runId, input, values) {
46
- let served = servedByStore.get(store);
46
+ let served = servedByStore.get(store.origin);
47
47
  if (!served)
48
- servedByStore.set(store, (served = new Map()));
48
+ servedByStore.set(store.origin, (served = new Map()));
49
49
  const key = wholeAnswerFor(values).key;
50
50
  const last = served.get(runId);
51
51
  if (last && last.key === key && last.input === input)
@@ -60,8 +60,15 @@ function servedOnce(store, runId, input, values) {
60
60
  }
61
61
  return out;
62
62
  }
63
- /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's. */
64
- const answerOf = (rows) => rows.findLast((r) => r.kind === "final_answer" && r.agent_label !== LEARNING_LABEL)?.text ?? null;
63
+ /** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
64
+ * never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
65
+ * followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
66
+ * the answer before it. */
67
+ export const answerOf = (rows) => {
68
+ const asked = rows.findLastIndex((r) => isMessageRow(r) && r.agent_label === null && r.text !== null);
69
+ const row = rows.findLast((r) => r.kind === "final_answer" && r.agent_label !== LEARNING_LABEL);
70
+ return row && rows.lastIndexOf(row) > asked ? row.text ?? null : null;
71
+ };
65
72
  /** A failed run's error from its row (its own words are the summary; the store keeps no code or detail apart). A run
66
73
  * its cap ended once its cost passed it (the kernel's overCapEnd) is code spend_cap_reached, its message the words after
67
74
  * the code, as main served it; a provider's content-filter stop is `moderated`, in words a person can act on
@@ -99,8 +106,32 @@ function pausedOf(runRow, entries) {
99
106
  function liveOf(runRow, now) {
100
107
  return !FINAL_STATES.includes(runRow.state) && runRow.runner !== null && runRow.claimedUntil !== null && runRow.claimedUntil >= now;
101
108
  }
102
- /** Reads the run from the store and builds the RunView the view functions read. */
109
+ /** Reads the run from the store and builds the RunView the view functions read. Every read of the run (its row, launch,
110
+ * journal, live tick and commands) is made in one snapshot of the store (Store.snapshot), so the view is of one moment: a
111
+ * runner's commit that lands while it is built is in all of it or in none. What is read through the server's own handles
112
+ * (the run's cut, which reads the agent's sign-ins, and the learning statuses of its folder) is read outside the snapshot,
113
+ * before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. */
103
114
  async function storeRunOf(store, runId, deps) {
115
+ // The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
116
+ // run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
117
+ // was handed (rowShown's choke point). The snapshot renders under it, so it is read first, and read again after: the cut
118
+ // only grows, so one that is the same after the snapshot holds every value saved before the rows were read (underCut
119
+ // builds again under a cut that grew meanwhile).
120
+ const cutOf = async () => {
121
+ const known = await store.runs.get(runId);
122
+ return known ? runCutValues(deps, store, runId, { runRow: known, launch: await launchOf(store, runId) }) : undefined;
123
+ };
124
+ if (!(await store.runs.get(runId)))
125
+ return undefined;
126
+ const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut)));
127
+ if (!run?.shownEnd || !holdsForOk(run.shownEnd) || !deps.statuses)
128
+ return run && { ...run, learningEnd: run.shownEnd };
129
+ // What the learning end held for its owner's OK reads as it stands now on its agent's folder's main (learning.ts
130
+ // currentLearning); its record stays as the merge wrote it.
131
+ return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)) };
132
+ }
133
+ /** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
134
+ async function storeRunIn(store, runId, deps, cut) {
104
135
  const context = BACKGROUND_CONTEXT;
105
136
  const row = await readRun(store, runId, context);
106
137
  if (!row)
@@ -109,10 +140,6 @@ async function storeRunOf(store, runId, deps) {
109
140
  if (!runRow)
110
141
  return undefined;
111
142
  const launch = await launchOf(store, runId);
112
- // The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
113
- // run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
114
- // was handed (rowShown's choke point).
115
- const cut = await runCutValues(deps, store, runId, { runRow, launch });
116
143
  const unshown = cut === "unreadable";
117
144
  const values = cut === "unreadable" ? [] : cut.values;
118
145
  const revision = await store.agents.revision(row.revision);
@@ -149,12 +176,9 @@ async function storeRunOf(store, runId, deps) {
149
176
  // run that learns is seeded, then looking back once its end-of-run turn starts (main's seeded and reflecting).
150
177
  const started = launch ? learningStartOf(launch) : undefined;
151
178
  const read = started?.given.length ? notesReadOf(started.given, reflectRange, await runTimeline(store, runId, context, { settled: terminal })) : [];
152
- const under = !ended && started && !seedFailed(started) ? underWay(started, reflectRange, iso(runRow.startedAt)) : null;
179
+ const under = !ended && started && started.use ? usedOnly(started, terminal, iso(runRow.endedAt ?? runRow.startedAt)) : !ended && started && !seedFailed(started) ? underWay(started, reflectRange, iso(runRow.startedAt)) : null;
153
180
  const sofar = ended ?? under;
154
181
  const shownEnd = sofar && withNotes(sofar, started, read);
155
- // What it held for its owner's OK as it reads now, on its agent's folder's main (learning.ts currentLearning); its record
156
- // stays as the merge wrote it.
157
- const learningEnd = shownEnd && holdsForOk(shownEnd) && deps.statuses ? currentLearning(shownEnd, await deps.statuses(row.agent)) : shownEnd;
158
182
  const turns = new Turns();
159
183
  turns.note(recordOf(records.entries), records.submissions ?? [], skip, liveRow?.updatedAt ?? deps.now?.() ?? Date.now());
160
184
  const working = live && turns.open > 0;
@@ -173,7 +197,13 @@ async function storeRunOf(store, runId, deps) {
173
197
  // The run's cap as it stands, through the one reader the runner's gate reads too (capNowOf): a raise taken shows in the
174
198
  // run's cost.cap_usd and its budget card, never the old cap.
175
199
  const capUsd = capNowOf(launch?.maxCostUsd, records.entries);
176
- const meta = { ...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}), ...(Object.keys(answers).length ? { approvals: answers } : {}) };
200
+ // A person's stop of an agentic run (stoppedByPerson: its row reads running, readRun) is main's stop mark: the run is
201
+ // stopped while no message is newer than the stop (statusOf: input_required and idle), and a message reopens it.
202
+ const meta = {
203
+ ...(capUsd !== undefined ? { max_cost_usd: capUsd } : {}),
204
+ ...(Object.keys(answers).length ? { approvals: answers } : {}),
205
+ ...(stoppedByPerson(runRow, row.kind) ? { stopped_after: usersOf(rows) } : {}),
206
+ };
177
207
  // The budget card the run shows while it stands parked at its cap, from its journal's agentrun.budget park (none once a
178
208
  // raise clears it). Read over the same meta cap and rows the card's figures and time come from.
179
209
  const budget = budgetOf(records.entries, { meta, rows, updatedAt: iso(updatedAtMs) });
@@ -205,6 +235,9 @@ async function storeRunOf(store, runId, deps) {
205
235
  ((command.kind === "steer" && command.body?.answers !== false) || (command.kind === "raise" && budget?.kind === "budget"));
206
236
  const submitted = terminal || row.kind !== "agentic" || working ? 0 : (await commandsNow()).filter(pending).length;
207
237
  const outcome = terminal ? STATUS_OF[row.state] : undefined;
238
+ // A cancel the person asked for reads cancelled from the 202 on, while the runner is still cutting the turn: its command
239
+ // row (not refused) is the request, so a poll never reads working or completed between the request and the end.
240
+ const cancelling = !terminal && (await commandsNow()).some((command) => command.kind === "cancel" && command.refused === null);
208
241
  const view = {
209
242
  id: row.id,
210
243
  agentId: row.agent,
@@ -212,8 +245,9 @@ async function storeRunOf(store, runId, deps) {
212
245
  ...(row.importedFrom ? { imported: { source: row.importedFrom.source, session: row.importedFrom.session } } : {}),
213
246
  kind: row.kind,
214
247
  ...(outcome ? { outcome } : {}),
215
- // The store's "stopped" state is a cancellation; its moment reads cancelled.
216
- cancel: row.state === "stopped",
248
+ ...(cancelling ? { finishing: "cancelled" } : {}),
249
+ // A cancel is the run's outcome 'cancelled', never its state alone: a person's stop is stopped too, and is no cancel.
250
+ cancel: runRow.outcome === "cancelled" || cancelling,
217
251
  working,
218
252
  submitted,
219
253
  updatedAt: iso(updatedAtMs),
@@ -235,7 +269,7 @@ async function storeRunOf(store, runId, deps) {
235
269
  // What its decisions booked (their own session, never on the usage row, which counts its model requests and paid tools).
236
270
  const booked = bookedSpend(records.entries, "decisions");
237
271
  const decisions = booked.requests ? booked : undefined;
238
- return { row, runRow, launch, rows, version, harness, learningEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions };
272
+ return { row, runRow, launch, rows, version, harness, learningEnd: shownEnd, shownEnd, view, unshown, values, live, updatedAtMs, lastProgressAt, budget, paused, browserAsk, computerAsk, approvalsMode, output, ...(review ? { review } : {}), structured, decisions };
239
273
  }
240
274
  /** A run's learning as the view shows it: its end from the store (what it held for the owner's OK as it reads now), in a
241
275
  * person's words cut of the host's secrets now, and, for an ended run, the notes it read. */
@@ -275,7 +309,11 @@ export async function viewOverStore(store, runId, deps) {
275
309
  const { row, runRow, launch, view, unshown, values, output, review: kept, structured } = run;
276
310
  const { status, state } = statusOf(view, factsOf(run));
277
311
  const terminal = TERMINAL.has(status);
278
- const endedAtMs = terminal ? (runRow.endedAt ?? runRow.startedAt) : null;
312
+ // A cancel reads cancelled from its 202 (status terminal) while the runner is still cutting the turn: the run is settled
313
+ // only once the store holds its end (its row no longer running), so its end time, poll hint, timeline `final` and learning
314
+ // come from that end, never from the optimistic status. Later tool results, withdrawals and charges still stream in.
315
+ const ended = row.state !== "running";
316
+ const endedAtMs = terminal && ended ? (runRow.endedAt ?? runRow.startedAt) : null;
279
317
  const shownWords = (text) => withoutLoopback(redacted(text, values));
280
318
  // The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
281
319
  // was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
@@ -316,7 +354,7 @@ export async function viewOverStore(store, runId, deps) {
316
354
  // card), else its agent waiting on a person in its browser (browserPending), else the question its turn ended on (pendingOf).
317
355
  const redactor = redactorOf(values);
318
356
  const pending = !unshown && status === "input_required" && state === "waiting" ? (approvalOf(view, redactor) ?? run.budget ?? browserPending(run.browserAsk, redactor) ?? computerPending(run.computerAsk, redactor) ?? pendingOf(run.rows)) : null;
319
- const settled = terminal;
357
+ const settled = terminal && ended;
320
358
  return {
321
359
  run_id: row.id,
322
360
  agent_id: row.agent,
@@ -352,8 +390,8 @@ export async function viewOverStore(store, runId, deps) {
352
390
  imported_from: runRow.importedFrom ? { source: runRow.importedFrom.source, session: runRow.importedFrom.session } : null,
353
391
  trigger: launch?.trigger ?? null,
354
392
  // Cut by the run's one cut (the pointers it was handed among them), and none for a withheld run, as its words.
355
- learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), terminal && settled),
356
- poll_after_ms: terminal && settled ? 0 : 1000,
393
+ learning: unshown ? null : learningViewOf(run.learningEnd, secretsShown(values), settled),
394
+ poll_after_ms: settled ? 0 : 1000,
357
395
  last_progress_at: run.lastProgressAt,
358
396
  };
359
397
  }
@@ -378,7 +416,7 @@ export async function factsOverStore(store, runId, deps) {
378
416
  if (!run)
379
417
  return undefined;
380
418
  const { status } = statusOf(run.view, factsOf(run));
381
- const endedAtMs = TERMINAL.has(status) ? (run.runRow.endedAt ?? run.runRow.startedAt) : null;
419
+ const endedAtMs = TERMINAL.has(status) && run.row.state !== "running" ? (run.runRow.endedAt ?? run.runRow.startedAt) : null;
382
420
  return { kind: run.row.kind, revision: run.row.revision, agentId: run.row.agent, status, createdAt: iso(run.runRow.startedAt), endedAt: endedAtMs === null ? null : iso(endedAtMs), unshown: run.unshown };
383
421
  }
384
422
  /** A run's live moment from the store (momentOf), for the one acceptance each act a run takes reads. A run no runner holds
@@ -387,7 +425,10 @@ export async function momentOverStore(store, runId, deps = { origin: "", serverS
387
425
  const run = await storeRunOf(store, runId, deps);
388
426
  if (!run)
389
427
  return undefined;
390
- return momentOf(run.view, factsOf(run), run.live);
428
+ // What is archived of it: its agent (whose archive holds its runs too, so it is said first: unarchiving the run alone would
429
+ // not open it), else the run's own archive time.
430
+ const archived = (await store.agents.get(run.row.agent))?.archivedAt ? "agent" : run.row.archivedAt ? "run" : undefined;
431
+ return { ...momentOf(run.view, factsOf(run), run.live), ...(archived ? { archived } : {}) };
391
432
  }
392
433
  /** A run's timeline rows as the VIEW renders them (storeRunOf's view.rows: withAsks, so a run waiting on a question carries
393
434
  * its `:waiting` row). The run-ended/run-needs-input follower reads these for its wait marker, main's marker and webhook-id.