@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
@@ -5,6 +5,12 @@ export function endedReason(state) {
5
5
  const how = state === "ended" ? "ended" : state === "stopped" ? "was stopped" : "failed";
6
6
  return `the run ${how} before this command was taken`;
7
7
  }
8
+ /** Whether `run`, of a revision of `kind`, was stopped by a person and waits for them (state 'stopped', outcome 'stopped',
9
+ * an agentic run started here): its turn is over, the run is not. A workflow's stop, a cancel and an imported run's stop
10
+ * are over for good. */
11
+ export function stoppedByPerson(run, kind) {
12
+ return run.state === "stopped" && run.outcome === "stopped" && kind === "agentic" && run.importedFrom === null;
13
+ }
8
14
  /** A firing a trigger has no room for: `due` firings are DUE_KEPT already. Nothing was written. */
9
15
  export class TriggerFull extends Error {
10
16
  triggerId;
@@ -37,6 +43,8 @@ export class ExternalBodyConflict extends Error {
37
43
  this.version = version;
38
44
  }
39
45
  }
46
+ /** The most run changes one read returns unless asked for fewer. */
47
+ export const RUN_CHANGES_PAGE = 200;
40
48
  /** The longest an MCP token refresh may take: two tries of 4 s each. The runner's claim step gives its call up by then. */
41
49
  export const MCP_REFRESH_CALL_MS = 2 * 4_000;
42
50
  /** The most one bounded store write may take, counted from its call: its wait behind its connection (SQLite's queue, a
@@ -130,7 +138,16 @@ export class SchemaVersionUnknown extends Error {
130
138
  found;
131
139
  known;
132
140
  constructor(file, found, known) {
133
- super(found === null ? `the store at ${file} has no schema yet: the server sets it up at its start` : `the store at ${file} is schema version ${found}; this build knows version ${known}`);
141
+ // `file` is a path (SQLite) or already a phrase (Postgres: "the Postgres schema x").
142
+ const store = file.startsWith("the ") ? file : `the store at ${file}`;
143
+ super(found === null
144
+ ? `${store} has no schema yet: the server sets it up at its start`
145
+ : found < known
146
+ ? `${store} is schema version ${found}, and this release (version ${known}) can't open a store an earlier release set up.\n` +
147
+ "Start the server on a new, empty data folder with --data <new folder> (docker run or compose arguments: --data /data/<new folder> --listen 0.0.0.0 --port 7340 --drain-timeout 6s), then add your agents, MCP servers, keys and sign-ins again.\n" +
148
+ 'On Render the Docker Command replaces the image\'s entrypoint too, so it must be the whole start command shown in "Before you upgrade" in the release notes.\n' +
149
+ "Keep the old folder as it is: the earlier release still opens it."
150
+ : `${store} is schema version ${found}, set up by a later release than this one (this release knows version ${known}). Run that release or a later one.`);
134
151
  this.name = "SchemaVersionUnknown";
135
152
  this.found = found;
136
153
  this.known = known;
@@ -157,10 +174,13 @@ export class StoreLaunchMissing extends Error {
157
174
  }
158
175
  /** A row the store's constraints refuse (a duplicate id or name, a revision of an unknown agent, a bad kind). When the
159
176
  * database said which rule refused it, `rule`; for a duplicate, `unique`: the table and the columns whose values were
160
- * taken already (a primary key's or a UNIQUE's), so a caller tells "the name is taken" from any other refusal. */
177
+ * taken already (a primary key's or a UNIQUE's), so a caller tells "the name is taken" from any other refusal. `index`:
178
+ * the unique index (or constraint) the database named, when it named one: an index on an expression (one answer per
179
+ * approval, schema.ts ONE_ANSWER_INDEX) has no plain columns to name, only its name. */
161
180
  export class StoreConstraint extends Error {
162
181
  rule;
163
182
  unique;
183
+ index;
164
184
  constructor(message, details = {}) {
165
185
  super(message);
166
186
  this.name = "StoreConstraint";
@@ -168,6 +188,18 @@ export class StoreConstraint extends Error {
168
188
  this.rule = details.rule;
169
189
  if (details.unique)
170
190
  this.unique = details.unique;
191
+ if (details.index)
192
+ this.index = details.index;
193
+ }
194
+ }
195
+ /** An approve or deny command refused because its approval is answered already: an unrefused answer naming it was
196
+ * written first (the one-answer index, schema.ts ONE_ANSWER_INDEX), so this one lost. Both stores raise it from that
197
+ * index's unique violation alone, at the command's insert; any other refusal stays a plain StoreConstraint. Its caller
198
+ * reads the answer that won: approve's 409 already_answered, or nothing to do. */
199
+ export class AnswerTaken extends StoreConstraint {
200
+ constructor(message, index) {
201
+ super(message, { rule: "unique", index });
202
+ this.name = "AnswerTaken";
171
203
  }
172
204
  }
173
205
  /** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
@@ -31,7 +31,8 @@ export async function analytics(store, filter = {}) {
31
31
  const revision = await store.agents.revision(run.revisionId);
32
32
  harnessOf.set(run.revisionId, revision?.kind === "workflow" ? "workflow" : (revision?.body?.harness ?? DEFAULT_HARNESS));
33
33
  }
34
- const running = runReadState(run) === "running";
34
+ const read = runReadState(run, harnessOf.get(run.revisionId) === "workflow" ? "workflow" : "agentic");
35
+ const running = read === "running";
35
36
  const isPending = running && pending[run.id] !== undefined;
36
37
  const metered = !running && metricsOf(run) !== null;
37
38
  const metrics = metered ? metricsOf(run) : null;
@@ -41,7 +42,7 @@ export async function analytics(store, filter = {}) {
41
42
  costUsd: run.costUsd,
42
43
  running,
43
44
  pending: isPending,
44
- state: isPending ? pending[run.id] : runReadState(run),
45
+ state: isPending ? pending[run.id] : read,
45
46
  metered,
46
47
  metrics,
47
48
  harness: harnessOf.get(run.revisionId),
@@ -1,13 +1,11 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import { type Meters } from "../cap.js";
3
3
  import type { Store } from "../store/store.js";
4
4
  /** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
5
5
  export declare function spentOverStore(store: Store, runId: string, context: Context): Promise<number | null>;
6
6
  /** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
7
7
  * entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
8
- * file-backed run held each on its root. The same figures meterFiguresIn reads from a settled run's own database — only
9
- * where the entries come from changes, so no money behaviour differs (the money-parity rule), as spentOverStore is to
10
- * spentIn. A run with no journal reads as a store that was never there: every figure 0, tokens unknown. */
8
+ * file-backed run held each on its root. A run with no journal reads as a store that was never there: every figure 0, tokens unknown. */
11
9
  export declare function metersOverStore(store: Store, runId: string, context: Context): Promise<Meters & {
12
10
  known: {
13
11
  tokens: number;
@@ -1,24 +1,33 @@
1
1
  import { meterFiguresFrom, spentFrom } from "../cap.js";
2
- import { bookedCapSpend, bookedSpend, costIsBooked } from "../runner/metrics.js";
2
+ import { bookedCapSpend, bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
3
3
  import { isCliRecord, runEntries, withPaidCosts } from "./journal.js";
4
+ /** A CLI run whose model answered or called a tool with no model request booked (metrics.ts cliModelWorked): what it
5
+ * spent no booking read, so its spend is unknown. */
6
+ const unbookedCli = (entries) => isCliRecord(entries) && bookedSpend(entries, "model").requests === 0 && cliModelWorked(entries);
4
7
  /** What a run has spent, as the cap reads it, from the one store's journal: its model requests and its paid tool calls. */
5
8
  export async function spentOverStore(store, runId, context) {
6
9
  const entries = await runEntries(store, runId, context);
7
10
  // A run whose record carries no cost of its own (a CLI harness's, a workflow's) reads what its sessions booked, the
8
11
  // figure its cap holds it to (metrics.ts bookedCapSpend), its record's answers reading $0: 0 before any request, an
9
12
  // unknown booked spend unknown (null).
13
+ // A CLI run whose model worked with no request booked (its requests went past its model proxy) reads unknown, never $0.
10
14
  if (costIsBooked(entries, isCliRecord(entries)))
11
- return bookedCapSpend(entries);
15
+ return unbookedCli(entries) ? null : bookedCapSpend(entries);
12
16
  // A pi run's paid tool calls (a browser's time, a search, a monid call) are booked on the run's one ledger, not its root:
13
17
  // folded back as the charges the file-backed root held (withPaidCosts), as metersOverStore reads them, so a live run's
14
18
  // listed spend counts them.
15
- return spentFrom(withPaidCosts(entries));
19
+ const spent = spentFrom(withPaidCosts(entries));
20
+ // Its learned workflow's decisions (LS-07), booked in their own session: at what each charged, as the run's end reads
21
+ // them (metrics.ts bookedSpend, "decisions"), so a running or paused run lists them, and one that reported no cost leaves
22
+ // the listed spend unknown, never the hold the cap counts for it.
23
+ const decisions = bookedSpend(entries, "decisions");
24
+ if (!decisions.requests)
25
+ return spent;
26
+ return spent === null || decisions.usd === null ? null : spent + decisions.usd;
16
27
  }
17
28
  /** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
18
29
  * entries, with the run's paid tool charges folded back from its paid-tools session (journal.ts withPaidCosts) as the
19
- * file-backed run held each on its root. The same figures meterFiguresIn reads from a settled run's own database — only
20
- * where the entries come from changes, so no money behaviour differs (the money-parity rule), as spentOverStore is to
21
- * spentIn. A run with no journal reads as a store that was never there: every figure 0, tokens unknown. */
30
+ * file-backed run held each on its root. A run with no journal reads as a store that was never there: every figure 0, tokens unknown. */
22
31
  export async function metersOverStore(store, runId, context) {
23
32
  const raw = await runEntries(store, runId, context);
24
33
  if (!raw.length)
@@ -30,6 +39,6 @@ export async function metersOverStore(store, runId, context) {
30
39
  return figures;
31
40
  const model = bookedSpend(raw, "model");
32
41
  if (!model.requests)
33
- return figures;
42
+ return unbookedCli(raw) ? { ...figures, tokens: null } : figures;
34
43
  return { ...figures, tokens: model.usd, known: { ...figures.known, tokens: model.known } };
35
44
  }
@@ -1,5 +1,5 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import type { Store } from "../store/store.js";
3
- /** A run's decision receipts, as the old durableDecisions answered them: the single `agentrun.decisions` document's
4
- * `receipts`, or the keyed `.count` and family rows in order. The same shape, read through the one store's journal. */
3
+ /** A run's decision receipts: the keyed `.count` and family rows in order, read through
4
+ * the one store's journal. */
5
5
  export declare function decisionsOverStore(store: Store, runId: string, context: Context): Promise<Array<Record<string, unknown>>>;
@@ -1,4 +1,4 @@
1
- import { decisionKey } from "@parcha/agentrun-pi/durable";
1
+ import { decisionKey } from "../workflow/decisions.js";
2
2
  /** A session-scoped document's current value, by kind and (for a family) key: findDocument, then its stored value. */
3
3
  async function sessionDocValue(reads, kind, key, context) {
4
4
  const record = await reads.findDocument({ kind, scope: { kind: "session" }, ...(key !== undefined ? { key } : {}) }, "current", context);
@@ -7,14 +7,11 @@ async function sessionDocValue(reads, kind, key, context) {
7
7
  const stored = await reads.document(record.id, "current", context);
8
8
  return stored ? stored.value : undefined;
9
9
  }
10
- /** A run's decision receipts, as the old durableDecisions answered them: the single `agentrun.decisions` document's
11
- * `receipts`, or the keyed `.count` and family rows in order. The same shape, read through the one store's journal. */
10
+ /** A run's decision receipts: the keyed `.count` and family rows in order, read through
11
+ * the one store's journal. */
12
12
  export async function decisionsOverStore(store, runId, context) {
13
13
  const reads = store.readJournal(runId);
14
14
  try {
15
- const single = (await sessionDocValue(reads, "agentrun.decisions", undefined, context));
16
- if (single)
17
- return Array.isArray(single.receipts) ? single.receipts : [];
18
15
  const count = (await sessionDocValue(reads, "agentrun.decisions.count", undefined, context))?.count;
19
16
  const rows = [];
20
17
  if (typeof count === "number")
@@ -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 Found } from "../import-summary.js";
3
3
  import type { Store } from "../store/store.js";
4
4
  /** An imported run of the one store, as found: its metrics from the row (undefined when it has none), and its requests'
@@ -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 { EntryLike, TimelineEvent, TimelineOptions } from "../timeline/index.js";
3
3
  import { Hearing } from "../heard.js";
4
4
  import { type Reflect } from "../reflect-range.js";
@@ -6,9 +6,10 @@ import type { Store } from "../store/store.js";
6
6
  /** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
7
7
  * entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
8
8
  export declare function runEntries(store: Store, runId: string, context: Context): Promise<EntryLike[]>;
9
- /** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): `after`, the entry
10
- * before its input; `until`, the run's end entry once written. Undefined for a run that asked none. */
11
- export declare function runReflect(store: Store, runId: string, context: Context): Promise<Pick<Reflect, "after" | "until"> | undefined>;
9
+ /** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): its newest round's
10
+ * `after`, the entry before its input, and `until`, the run's end entry once written; `earlier`, each earlier round's (a
11
+ * follow-up opened the run again after it). Undefined for a run that asked none. */
12
+ export declare function runReflect(store: Store, runId: string, context: Context): Promise<Pick<Reflect, "after" | "until" | "earlier"> | undefined>;
12
13
  /** The paid tool charges a run booked, read back from its paid-tools session (the kernel cap's TOOL_SESSION) as the
13
14
  * TOOL_COST entries the timeline renders, which the file-backed path had on the run's root (the paid-call ledger). Each
14
15
  * paid request's runner.request names its tool (its model "paid:<name>") and the call it ran under (`call`, written by the
@@ -3,33 +3,41 @@
3
3
  // its own database file ("SELECT record FROM entries ORDER BY id") and fed the same pure renderer; these read the one store instead.
4
4
  // The renderer and the hearing keep their words; only where the entries come from changes.
5
5
  import { createHash } from "node:crypto";
6
- import { CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
6
+ import { CALL_REFUSED, CAPS, costLabel, timelineOf, TOOL_COST } from "../timeline/index.js";
7
7
  import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
8
+ import { wireName } from "../catalog.js";
8
9
  import { TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
9
10
  import { Hearing } from "../heard.js";
10
11
  import { redactedAnswer } from "../key-refusal.js";
11
12
  import { LEARNED_NODES, LEARNED_NODES_MAX } from "../learned-nodes.js";
12
- import { labelled } from "../reflect-range.js";
13
- import { reflectFrom } from "../runner/end-of-run.js";
14
- import { journalEntries, journalRecords } from "../runner/journal-reader.js";
13
+ import { computerCallsOf } from "../computer-calls.js";
14
+ import { labelled, reflects } from "../reflect-range.js";
15
+ import { reflectRanges } from "../runner/end-of-run.js";
16
+ import { journalEntries, journalRecords, recordOf } from "../runner/journal-reader.js";
15
17
  import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
16
- import { bookedSpend, costIsBooked } from "../runner/metrics.js";
18
+ import { bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
17
19
  import { waitingText } from "../tool-gate.js";
20
+ import { Turns } from "../turns.js";
18
21
  /** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
19
22
  * entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
20
23
  export async function runEntries(store, runId, context) {
21
24
  const entries = (await journalEntries(store.readJournal(runId), context));
22
25
  return entries.slice().sort((a, b) => Number(a.id ?? 0) - Number(b.id ?? 0));
23
26
  }
24
- /** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): `after`, the entry
25
- * before its input; `until`, the run's end entry once written. Undefined for a run that asked none. */
27
+ /** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): its newest round's
28
+ * `after`, the entry before its input, and `until`, the run's end entry once written; `earlier`, each earlier round's (a
29
+ * follow-up opened the run again after it). Undefined for a run that asked none. */
26
30
  export async function runReflect(store, runId, context) {
27
- const records = await journalRecords(store.readJournal(runId), context);
28
- const from = reflectFrom(records.submissions ?? [], records.entries);
29
- if (from === undefined)
31
+ return reflectOf(await journalRecords(store.readJournal(runId), context));
32
+ }
33
+ /** runReflect over records already read. */
34
+ function reflectOf(records) {
35
+ const ranges = reflectRanges(records.submissions ?? [], records.entries);
36
+ const newest = ranges.at(-1);
37
+ if (newest === undefined)
30
38
  return undefined;
31
- const end = records.entries.find((entry) => entry.kind === KINDS.end && Number(entry.id) >= from);
32
- return { after: from - 1, ...(end ? { until: Number(end.id) } : {}) };
39
+ const earlier = ranges.slice(0, -1).flatMap(({ from, until }) => (until === undefined ? [] : [{ after: from - 1, until }]));
40
+ return { after: newest.from - 1, ...(newest.until !== undefined ? { until: newest.until } : {}), ...(earlier.length ? { earlier } : {}) };
33
41
  }
34
42
  /** The CLI record (a harness whose own records are resume log only, record "loop": adapter-loop.ts openCliRecord) as the
35
43
  * pi-shaped entries the timeline renderer reads: a model message is an assistant turn, a person message a user turn, and a
@@ -96,7 +104,10 @@ function piShaped(entries) {
96
104
  // text), as pi's own interrupted result does, never an empty failure.
97
105
  const failed = data.status !== undefined && data.status !== "done";
98
106
  const content = data.output === undefined && data.status === "interrupted" ? endedAnswer("", { status: "interrupted" }).text : (data.output ?? "");
99
- return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...timestamp }] };
107
+ // One refused before it ran (its gate's deny, a person's, an approval the run ended without) carries pi's refusal
108
+ // mark, so its rows read refused, as pi's do, never as a call that ran and failed.
109
+ const refused = data.status === "refused" ? { details: { [CALL_REFUSED]: true } } : {};
110
+ return { ...entry, kind: "pi.tool-result", model: [{ role: "tool", toolCallId: String(data.callId ?? ""), content, ...(failed ? { isError: true } : {}), ...refused, ...timestamp }] };
100
111
  }
101
112
  return entry;
102
113
  });
@@ -123,7 +134,7 @@ export function withPaidCosts(entries) {
123
134
  continue;
124
135
  const d = (e.data ?? {});
125
136
  if (typeof d.turn === "number" && typeof d.model === "string" && d.model.startsWith("paid:"))
126
- named.set(d.turn, { tool: typeof d.tool === "string" && d.tool ? d.tool : d.model.slice("paid:".length), ...(typeof d.call === "string" ? { call: d.call } : {}), ...(typeof d.charged_by === "string" && d.charged_by ? { chargedBy: d.charged_by } : {}), ...(typeof d.tag === "string" && d.tag ? { tag: d.tag } : {}) });
137
+ named.set(d.turn, { ...(typeof d.tool === "string" && d.tool ? { tool: d.tool, own: true } : { tool: d.model.slice("paid:".length) }), ...(typeof d.call === "string" ? { call: d.call } : {}), ...(typeof d.charged_by === "string" && d.charged_by ? { chargedBy: d.charged_by } : {}), ...(typeof d.tag === "string" && d.tag ? { tag: d.tag } : {}) });
127
138
  }
128
139
  const charges = [];
129
140
  for (const e of entries) {
@@ -140,13 +151,31 @@ export function withPaidCosts(entries) {
140
151
  }
141
152
  if (!charges.length)
142
153
  return [...entries];
154
+ // The tool each call ran, by its id, from the model's answers (a CLI run's record shaped as pi's: piShaped).
155
+ const toolOfCall = new Map();
156
+ for (const e of entries) {
157
+ if (e.kind !== "pi.assistant")
158
+ continue;
159
+ for (const message of (e.model ?? [])) {
160
+ for (const part of Array.isArray(message.content) ? message.content : []) {
161
+ const call = part;
162
+ if (call.type === "toolCall" && typeof call.id === "string" && typeof call.name === "string")
163
+ toolOfCall.set(call.id, call.name);
164
+ }
165
+ }
166
+ }
143
167
  const out = [...entries];
144
168
  for (const charge of charges) {
145
169
  // Who charged: the request's own charged_by, which the cap writes as main's charge label names it (parallel, monid, an
146
170
  // MCP server, a browser vendor).
147
171
  const by = charge.chargedBy;
148
172
  const at = charge.call === undefined ? -1 : out.findIndex((e) => e.kind === "pi.tool-result" && String(e.model?.[0]?.toolCallId ?? "") === charge.call);
149
- const data = { tool: charge.tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
173
+ // Named for its call's tool where the request names none of its own: by what was paid for where that is the tool
174
+ // itself (an MCP tool's catalog name, whose wire name the call carries), else by the call's tool (web_fetch, for
175
+ // Parallel's extract). A request that names its tool (a browser step's "browser") keeps it.
176
+ const called = !charge.own && charge.call !== undefined ? toolOfCall.get(charge.call) : undefined;
177
+ const tool = called !== undefined && wireName(charge.tool) !== called ? called : charge.tool;
178
+ const data = { tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
150
179
  const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}#${charge.turn}` };
151
180
  out.splice(at >= 0 ? at + 1 : out.length, 0, entry);
152
181
  }
@@ -170,12 +199,39 @@ const inWorkspace = (cwd) => (path) => {
170
199
  export async function runTimeline(store, runId, context, options = {}) {
171
200
  const entries = await runEntries(store, runId, context);
172
201
  const cli = isCliRecord(entries);
202
+ const records = await journalRecords(store.readJournal(runId), context);
203
+ const reflect = reflectOf(records);
173
204
  // A CLI names a file by its absolute path under its working directory (CallStartData.cwd): the rows name it by its
174
205
  // name in the workspace, never a path on the runner's machine. Its arguments, as the harness sent them, stay.
175
206
  const cwd = cli && !options.path ? entries.find((entry) => entry.kind === KINDS.callStart && typeof entry.data?.cwd === "string")?.data : undefined;
176
- const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), cwd ? { ...options, path: inWorkspace(cwd.cwd) } : options);
177
- const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : rendered;
178
- return labelled((await runReflect(store, runId, context)), withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact));
207
+ // A run whose newest turn a stop or a cancel cut reads it over (run-view.ts statusOf: input_required) from the moment pi
208
+ // settles that turn's message aborted, before the runner books what the abort cut (its request's end mark comes once the
209
+ // session's proxy sees its upstream end). Its cost reads that turn the same way, the request it cut a charge with no
210
+ // price, never one in flight: never the known sum as its cost while the run reads stopped.
211
+ const read = { ...options, ...(cwd ? { path: inWorkspace(cwd.cwd) } : {}), ...(!options.settled && turnCutOf(records, reflect) ? { turnCut: true } : {}) };
212
+ const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), read);
213
+ const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : withSideUsage(rendered, entries);
214
+ return labelled(reflect, withComputerCalls(withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact), entries));
215
+ }
216
+ /** Whether the run's newest turn is over, cut (turns.ts: no message of the run's open, the newest one's end interrupted),
217
+ * its end-of-run turn's entries apart, as the run's view reads its status. */
218
+ function turnCutOf(records, reflect) {
219
+ const turns = new Turns();
220
+ turns.note(recordOf(records.entries), records.submissions ?? [], reflect ? (id) => reflects(reflect, id) : undefined);
221
+ return turns.end()?.status === "interrupted";
222
+ }
223
+ /** `rows` with each tool call's result row carrying the computer protocol calls it made (`computer_calls`, and
224
+ * `computer_calls_dropped` past the record's bound), from the COMPUTER_CALLS entry the adapter loop kept beside the call
225
+ * (computer-calls.ts), joined by the call's id. A record holds no param's value and no answer's bytes, so it needs no cut.
226
+ * Rows of a run whose tools made none are as they were. */
227
+ function withComputerCalls(rows, entries) {
228
+ const made = computerCallsOf(entries);
229
+ if (!made.size)
230
+ return rows;
231
+ return rows.map((row) => {
232
+ const kept = row.kind === "tool_result" && row.tool_use_id ? made.get(row.tool_use_id) : undefined;
233
+ return kept ? { ...row, computer_calls: kept.calls, ...(kept.dropped > 0 ? { computer_calls_dropped: kept.dropped } : {}) } : row;
234
+ });
179
235
  }
180
236
  /** `rows` with each learned_workflow call's result row carrying the nodes its workflow ran (`learned_nodes`), from the
181
237
  * LEARNED_NODES entry the call kept beside itself (learned-workflow.ts), joined by the call's id: each label through
@@ -193,31 +249,65 @@ function withLearnedNodes(rows, entries, redact) {
193
249
  const one = (node ?? {});
194
250
  if (typeof one.label !== "string" || typeof one.status !== "string")
195
251
  return [];
196
- return [{ label: said(one.label), kind: String(one.kind ?? ""), status: one.status, duration_ms: typeof one.duration_ms === "number" ? one.duration_ms : 0 }];
252
+ // A model node's model and tier, each through the run's cut as the label is.
253
+ return [{ label: said(one.label), kind: String(one.kind ?? ""), status: one.status, duration_ms: typeof one.duration_ms === "number" ? one.duration_ms : 0,
254
+ ...(typeof one.model === "string" ? { model: said(one.model) } : {}), ...(typeof one.tier === "string" ? { tier: said(one.tier) } : {}) }];
197
255
  }));
198
256
  }
199
257
  if (!traces.size)
200
258
  return rows;
201
259
  return rows.map((row) => (row.kind === "tool_result" && row.tool_use_id && traces.has(row.tool_use_id) ? { ...row, learned_nodes: traces.get(row.tool_use_id) } : row));
202
260
  }
261
+ /** A pi run's `rows` with its side calls in its usage row: the requests its session booked that no answer of pi's carries
262
+ * (a learned workflow's nodes, a request on another model: runner/metrics.ts bookedSpend "side"), at what they were
263
+ * booked at, unknown when one's price is, beside the answers the renderer counted. Their requests join its count; its
264
+ * words are the renderer's, figures changed. A run with none is as rendered. */
265
+ function withSideUsage(rows, entries) {
266
+ const side = bookedSpend(entries, "side");
267
+ const at = rows.findLastIndex((row) => row.kind === "usage");
268
+ if (!side.requests || at < 0)
269
+ return [...rows];
270
+ const row = rows[at];
271
+ const own = row.usage ?? { usd: 0, requests: 0 };
272
+ const known = (own.usd ?? own.so_far_usd ?? 0) + side.known;
273
+ const unpriced = (own.usd === null ? (own.unpriced ?? 0) : 0) + side.unpriced;
274
+ const usd = unpriced ? null : Math.round(known * 1e6) / 1e6;
275
+ const requests = own.requests + side.requests;
276
+ const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
277
+ const spent = usd !== null ? dollars(usd) : `${dollars(Math.round(known * 1e6) / 1e6)} known, ${unpriced} not priced,`;
278
+ const summary = (row.summary ?? "").replace(/^([^:]+): .+? over \d+ model requests?/, `$1: ${spent} over ${requests} model request${requests === 1 ? "" : "s"}`);
279
+ const usage = { usd, requests, ...(usd === null ? { so_far_usd: Math.round(known * 1e6) / 1e6, unpriced } : {}), ...(own.not_metered ? { not_metered: own.not_metered } : {}) };
280
+ return rows.map((each, i) => (i === at ? { ...row, summary, usage } : each));
281
+ }
203
282
  /** A CLI or workflow run's `rows` with its usage row in its booking's words (runner/metrics.ts bookedSpend over every
204
283
  * session of the run but its decisions'): its model requests and its paid tool calls, their sum (unknown while one's cost is, with what is known so far,
205
284
  * costsofar/1), in the renderer's words (`Cost` once ended, else `Cost so far`). The renderer's own row is replaced in
206
285
  * place; a run that booked a request and rendered none gets one at the end. One that booked none keeps its rows, with no
207
- * usage row. */
286
+ * usage row, unless it is a CLI run whose model worked with none booked (metrics.ts cliModelWorked: its requests went
287
+ * past its model proxy): its usage row says its cost is unknown, its model's work one charge with no price, so its view,
288
+ * live or ended, reads unknown, never $0. */
208
289
  function bookedUsage(rows, entries, options) {
209
290
  const model = bookedSpend(entries, "model");
210
291
  const paid = bookedSpend(entries, "paid");
211
292
  const at = rows.findIndex((row) => row.kind === "usage");
212
293
  const kept = rows.filter((row) => row.kind !== "usage");
213
- if (!model.requests && !paid.requests)
214
- return kept;
215
- const usd = model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
216
- const unpriced = model.unpriced + paid.unpriced;
294
+ const unbooked = !model.requests && isCliRecord(entries) && cliModelWorked(entries);
295
+ if (!model.requests && !paid.requests && !unbooked) {
296
+ // A run whose cap refused its first request (its park at the cap, an agentrun.budget entry) says it sent none, as a
297
+ // pi run's usage line does: never a request it did not make, and never silence about why nothing ran.
298
+ if (!entries.some((entry) => entry.kind === KINDS.budget) || kept.length === 0)
299
+ return kept;
300
+ const last = kept[kept.length - 1];
301
+ return [...kept, { ...last, id: `${last.conversation_id ?? 0}:usage`, kind: "usage", summary: "no model request sent", agent_label: null, text: null, tool_name: null, tool_use_id: null, tool_status: null, tool_input_preview: null, tool_result_preview: null, tool_result_size_bytes: null, usage: { usd: 0, requests: 0 } }];
302
+ }
303
+ const usd = unbooked || model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
304
+ const unpriced = model.unpriced + paid.unpriced + (unbooked ? 1 : 0);
217
305
  const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
218
306
  const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
219
307
  const charges = paid.requests ? ` and ${paid.requests} paid tool call${paid.requests === 1 ? "" : "s"}` : "";
220
- const summary = `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
308
+ const summary = unbooked
309
+ ? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${charges}`
310
+ : `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
221
311
  const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
222
312
  const last = rows[rows.length - 1];
223
313
  const base = at >= 0 ? rows[at] : {
@@ -264,9 +354,10 @@ export async function wholeAnswers(store, runId, context, rows, options, whole)
264
354
  const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
265
355
  if (!rows.some(cut))
266
356
  return rows;
267
- let kept = answersServed.get(store);
357
+ // Kept by the store a snapshot was taken of: each snapshot's own store is a new object, and would never hit.
358
+ let kept = answersServed.get(store.origin);
268
359
  if (!kept)
269
- answersServed.set(store, (kept = new Map()));
360
+ answersServed.set(store.origin, (kept = new Map()));
270
361
  const keyOf = (row) => `${runId}\0${row.id}\0${whole.key}`;
271
362
  let uncut;
272
363
  const out = [];
@@ -1,6 +1,7 @@
1
1
  import { type ItemStatus, type Learning, type NoteUsed, type Shown } from "../learning.js";
2
2
  import { type RunLaunch } from "../run-launch.js";
3
3
  import { type Impact } from "../learning-run.js";
4
+ import { type CostRun, type CostSummary } from "../learning-cost.js";
4
5
  import { type Reflect } from "../reflect-range.js";
5
6
  import type { NoteRuns } from "../learning.js";
6
7
  import type { EntryLike, TimelineEvent } from "../timeline/index.js";
@@ -8,8 +9,8 @@ import type { AnalyticsFilter } from "./analytics.js";
8
9
  import type { Store } from "../store/store.js";
9
10
  /** A run's learning end: the Learning fields its end sets. */
10
11
  export type RunLearningEnd = Pick<Learning, "state" | "reason" | "detail" | "at" | "problems" | "verdict" | "graded" | "merged" | "cost_usd" | "tokens" | "learned" | "pending" | "skills" | "workflows" | "lost" | "answered_at" | "job_cost_usd" | "look_back_usd">;
11
- /** Run `runId`'s learning end; null when the run kept no learning. Proposed while its learning run has not ended. */
12
- export declare function runLearningEnd(store: Store, runId: string): Promise<RunLearningEnd | null>;
12
+ /** 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. */
13
+ export declare function runLearningEnd(store: Store, runId: string, round?: number): Promise<RunLearningEnd | null>;
13
14
  /** How the runs that tried to learn fared (GET /stats's `learning`): `runs` with a learning end, `merged`, `dropped` by
14
15
  * reason, and `in_progress` (proposed, its learning run not ended). The shape today's counts give (learning-run.ts
15
16
  * learningStats). */
@@ -51,6 +52,22 @@ export declare function agentLearningOverStore(store: Store, agentId: string): P
51
52
  impact: Impact;
52
53
  notes: NoteRuns;
53
54
  }>;
55
+ /** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
56
+ * agentic runs that ended (ended, stopped or failed), oldest first, numbered from 1, with its own cost and what learning
57
+ * 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
58
+ * (journalReadsOf), and the learned revision it started from (its launch's seed); and what the series shows
59
+ * (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left out; a learning
60
+ * 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
61
+ * shown, each keeping its number; the summary is over every run. */
62
+ export declare function agentCostOverStore(store: Store, agentId: string, limit?: number): Promise<{
63
+ runs: CostRun[];
64
+ summary: CostSummary;
65
+ total_runs: number;
66
+ unknown_cost_runs: number;
67
+ }>;
68
+ /** One run of the cost series, as number `n` of it: its figures and its path (agentCostOverStore's loop body, and a learning
69
+ * batch's row once the run's learning has settled). */
70
+ export declare function costRunOf(store: Store, run: NonNullable<Awaited<ReturnType<Store["runs"]["get"]>>>, n: number): Promise<CostRun>;
54
71
  /** What a run's claim laid of its learning seed: the learned skills and workflows it was given, by name. */
55
72
  type Laid = {
56
73
  readonly skills: readonly string[];
@@ -60,6 +77,16 @@ type Laid = {
60
77
  * claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
61
78
  * no entry. */
62
79
  export declare function laidOf(entries: readonly EntryLike[]): Laid;
80
+ /** What every round of a run that a follow-up opened again spent (undefined for a run with one round): when its first
81
+ * round's job answered and what the job cost to then, the look-backs of every round added up, and every round's grade. A
82
+ * figure that is unknown in any round is unknown (null). */
83
+ type RoundsSpend = {
84
+ answered_at: string;
85
+ job_cost_usd: number | null;
86
+ look_back_usd: number | null;
87
+ grade_usd: number | null;
88
+ };
89
+ export declare function roundsSpendOf(store: Store, runId: string): Promise<RoundsSpend | undefined>;
63
90
  /** A run's learning end with the notes its start gave it (`given`, when it started from a seed) and those its job read
64
91
  * (`read`, only when it read one): what a run view and GET /runs/{id}/learning show beside the end. */
65
92
  export type RunLearning = RunLearningEnd & {
@@ -107,6 +134,9 @@ export declare function learnedUseOf(started: RunLaunch["learning"], reflect: Pi
107
134
  }>, laid?: Pick<Laid, "skills">, loads?: readonly string[]): LearnedUse;
108
135
  /** `end` with its run's given notes (from its launch's learning start) and the notes its job read. */
109
136
  export declare function withNotes(end: RunLearningEnd, started: RunLaunch["learning"], read: readonly NoteUsed[]): RunLearning;
137
+ /** The learning of a run that only uses what its agent learned (`learning: "use"`): seeded while it runs, as a run that
138
+ * learns is; dropped `use` once it ended, since it is never asked what to keep. */
139
+ export declare function usedOnly(started: NonNullable<RunLaunch["learning"]>, terminal: boolean, at: string): RunLearningEnd;
110
140
  /** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
111
141
  * run's learning end (runLearningEnd), the notes it was given and the seed it started from as its launch records them,
112
142
  * what it held for its owner's OK as it stands on its agent's folder's main (`statuses`, learning-routes.ts statusesOf,
@@ -159,8 +189,8 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
159
189
  skills?: import("../learning.js").LearnedFile[];
160
190
  workflows?: import("../learning.js").LearnedFile[];
161
191
  run: string;
162
- state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
163
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
192
+ state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
193
+ reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
164
194
  detail: string | null;
165
195
  at: string;
166
196
  } | null>;