@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36

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 (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  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 +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -89,9 +89,16 @@ export interface RevisionRow {
89
89
  /** The version this revision maps in the agent's owning system (one revision per version), or null for one committed here. */
90
90
  readonly externalVersion: string | null;
91
91
  }
92
- /** How an ended run (state 'ended') ended apart from being done: 'escalated' (it finished its work and waits for a person,
93
- * which the v2 status reads as completed with a review) or 'completed'. A failed or stopped run says so in its state. */
94
- export type RunOutcome = "completed" | "escalated";
92
+ /** How a run ended, beside its state. An ended run (state 'ended'): 'escalated' (it finished its work and waits for a
93
+ * person, which the v2 status reads as completed with a review) or 'completed'. A stopped run (state 'stopped'): 'stopped'
94
+ * when a person stopped it (its turn ended, never the run: an agentic run reads input_required and idle, as main's
95
+ * statusOf reads a stopped run, and a person's message reopens it), 'cancelled' when it was cancelled (over for good). A
96
+ * failed run says so in its state. */
97
+ export type RunOutcome = "completed" | "escalated" | "stopped" | "cancelled";
98
+ /** Whether `run`, of a revision of `kind`, was stopped by a person and waits for them (state 'stopped', outcome 'stopped',
99
+ * 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
100
+ * are over for good. */
101
+ export declare function stoppedByPerson(run: Pick<RunRow, "state" | "outcome" | "importedFrom">, kind: string): boolean;
95
102
  /** The harness an imported run came from. */
96
103
  export type ImportSource = "claude-code" | "codex" | "pi";
97
104
  /** Where an imported run came from: the harness that ran it, and its own session id. `file` is the server's own record of
@@ -127,7 +134,7 @@ export interface RunRow {
127
134
  readonly costUsd: number | null;
128
135
  readonly metrics: unknown;
129
136
  readonly summary: string | null;
130
- /** An ended run's outcome (RunOutcome), null for a plain completion or a run not ended this way. */
137
+ /** How the run ended beside its state (RunOutcome), null for a plain completion, a failure, or a run not ended. */
131
138
  readonly outcome: RunOutcome | null;
132
139
  /** When the run itself was archived (its agent's archive is read apart); null when it is not. */
133
140
  readonly archivedAt: number | null;
@@ -145,7 +152,7 @@ export interface RunPatch {
145
152
  readonly costUsd?: number | null;
146
153
  readonly metrics?: unknown;
147
154
  readonly summary?: string | null;
148
- /** An ended run's outcome, set in its end commit; null clears it. */
155
+ /** How the run ended (RunOutcome), set in its end commit; null clears it. */
149
156
  readonly outcome?: RunOutcome | null;
150
157
  /** The SHA-256 hashes of the sign-in pointers handed to the run, which the runner writes at its claim (under the epoch
151
158
  * fence); null clears them. While the run runs, a sign-in hashing to one of these cannot be forgotten (sign-ins-store.ts). */
@@ -161,7 +168,9 @@ export type UpdatedRun = RunRow & {
161
168
  };
162
169
  /** A run's launch, as the server writes it at start: its JSON `body` (run-launch.ts: the first input, title, place, effort,
163
170
  * cap, trigger and origin), and `sealed` ciphertext for any secret it carries (sealed with the server's key outside the
164
- * store, AAD `run_launch|<run_id>|sealed`), or none. Written once, in the same transaction as the queued run. */
171
+ * store, AAD `run_launch|<run_id>|sealed`: the MCP credentials its caller handed it, store/seal.ts sealRunMcpAuth), or
172
+ * none. The body is written once, in the same transaction as the queued run. `sealed` is the run's for its life only: a
173
+ * message may replace it (runs.command and runs.reopen, `launchSealed`), and the write that ends the run erases it. */
165
174
  export interface RunLaunchInput {
166
175
  readonly body: unknown;
167
176
  readonly sealed?: Uint8Array | null;
@@ -174,6 +183,11 @@ export interface RunLaunchRow {
174
183
  readonly sealed: Uint8Array | null;
175
184
  readonly createdAt: number;
176
185
  }
186
+ /** A message's new launch secrets (runs.command, runs.reopen): `launchSealed` replaces the run's launch `sealed` in the
187
+ * command's own transaction, so the runner that takes the command reads them, and a run already final takes neither. */
188
+ export interface LaunchSealedWrite {
189
+ readonly launchSealed?: Uint8Array;
190
+ }
177
191
  /** A run imported from another harness's session: an ended run with where it came from, its launch (built from the
178
192
  * session), its cost and metrics, and its transcript as journal batches — the whole thing written in one transaction.
179
193
  * `transcript` is the session as pi-durable write batches (a root conversation and its entries), each batch a commit. */
@@ -455,6 +469,8 @@ export interface Agents {
455
469
  /** The agent an external reference ("<source>:<kind>:<id>") maps to (Runs.createInline), or undefined before its first
456
470
  * run. */
457
471
  byExternal(ref: string): Promise<AgentRow | undefined>;
472
+ /** Whether the agent already has the revision that maps `version` of its owning system (one row looked up, no bodies read). */
473
+ hasExternalVersion(agentId: string, version: string): Promise<boolean>;
458
474
  list(options?: {
459
475
  archived?: boolean;
460
476
  }): Promise<AgentRow[]>;
@@ -643,16 +659,17 @@ export interface Runs {
643
659
  }): Promise<RunRow[]>;
644
660
  /** Archives the run (its own archive time), or unarchives it: idempotent. */
645
661
  archive(runId: string, archived: boolean): Promise<void>;
646
- /** A person's follow-up to a run that ended completed: in one transaction, the run goes back to running with no runner
662
+ /** A person's follow-up to a run that ended completed, or that a person stopped: in one transaction, the run goes back to running with no runner
647
663
  * (released, so a runner claims it at once by the claimable rule's released branch), its end's own fields cleared
648
664
  * (ended_at, summary, outcome, its waits) and everything it did kept (its epoch, its journal, its cost and metrics,
649
665
  * so its next turn is booked on top of what it spent), and `command` (the follow-up's steer) is written untaken for it.
650
- * Only an agentic run that ended completed (state 'ended'), not imported and not a learning run, reopens: a workflow,
651
- * a failed, stopped or cancelled run, any other, or none is RunFinal, and nothing is written. */
666
+ * Only an agentic run that ended completed (state 'ended') or that a person stopped (state 'stopped', outcome
667
+ * 'stopped'), not imported and not a learning run, reopens: a workflow, a failed or cancelled run, any other, or none
668
+ * is RunFinal, and nothing is written. */
652
669
  reopen(runId: string, command: {
653
670
  kind: string;
654
671
  body?: unknown;
655
- }): Promise<Command>;
672
+ }, options?: LaunchSealedWrite): Promise<Command>;
656
673
  /** The runs a runner may claim, oldest first: queued; parked with an untaken command or its wake_at passed; running with
657
674
  * no runner (released at a runner's shutdown: it stays running, a run that started keeps that fact) or its claim run
658
675
  * out. */
@@ -843,6 +860,12 @@ export interface Settings {
843
860
  /** Saves `value` under `key` only when the key has no row yet, in one statement, so of two processes that race the first
844
861
  * wins; the value saved under it after (this one, or the one there before). */
845
862
  putIfAbsent(key: string, value: unknown): Promise<unknown>;
863
+ /** Saves `value` under `key` only while its row still holds `was` (as get read it), in one statement: a compare-and-set,
864
+ * so of two writers that read one row only one replaces it. True when it was replaced; false, with nothing written,
865
+ * when the row changed since or is gone. */
866
+ replaceIf(key: string, was: unknown, value: unknown): Promise<boolean>;
867
+ /** The key's row goes only while it still holds `was`, in one statement: true when it went. */
868
+ removeIf(key: string, was: unknown): Promise<boolean>;
846
869
  /** The key's row goes; a key with no row is left as it is. */
847
870
  remove(key: string): Promise<void>;
848
871
  /** Every setting, by key. */
@@ -902,6 +925,13 @@ export interface ComputerLedger {
902
925
  list(provider: string): Promise<ComputerLedgerRow[]>;
903
926
  /** The session's row goes. */
904
927
  remove(provider: string, sessionId: string): Promise<void>;
928
+ /** Replaces the session's `labels` and `detail` only while its row still holds `was`'s, in one statement (a
929
+ * compare-and-set, so two writers that read one row never both write it): true when it was replaced; false, with
930
+ * nothing written, when the row changed since or is gone. */
931
+ swap(provider: string, sessionId: string, was: {
932
+ readonly labels: Readonly<Record<string, string>>;
933
+ readonly detail: Readonly<Record<string, unknown>>;
934
+ }, labels: Readonly<Record<string, string>>, detail: Readonly<Record<string, unknown>>): Promise<boolean>;
905
935
  }
906
936
  /** A trigger source's sealed setting as a row (store schema `trigger_settings`): its adapter, scope ("server" for the one
907
937
  * server-wide set, or a trigger's id for its own), field, and the value sealed (store/seal.ts) under AAD
@@ -1146,6 +1176,15 @@ export interface Store {
1146
1176
  /** The run's journal: pi-durable's Storage for this one run, every commit fenced by the claim (store/journal). Its commit
1147
1177
  * holds the store's one connection while it runs, so it awaits nothing but its own statements, under a deadline. */
1148
1178
  journal(claim: Claim): Journal;
1179
+ /** The store this one reads from: itself, but for the store a snapshot hands its callback, which is a new object at each
1180
+ * snapshot and gives the store it was taken of. What a reader keeps per store (a served answer's cache) is kept by this. */
1181
+ readonly origin: Store;
1182
+ /** `read` against this store as it stood at one moment: every read it makes sees one snapshot (one read-only transaction),
1183
+ * so a write that lands meanwhile, a runner's commit among them, is in all of its reads or in none. The store it is given
1184
+ * only reads. On SQLite the transaction holds this process's one connection until `read` settles, so `read` awaits the
1185
+ * store it is given and nothing else: never this store (that waits for the snapshot, which waits for it), and no
1186
+ * network or disk. Its deadline is the transaction's (StoreDeadline). */
1187
+ snapshot<T>(read: (store: Store) => Promise<T>): Promise<T>;
1149
1188
  /** A run's journal opened for reading only (JournalReads): the server's reads of a run, which hold no claim. Its reads
1150
1189
  * alone, never a commit; a read never fences, so it needs no claim. A run with no journal yet reads as empty. */
1151
1190
  readJournal(runId: string): JournalReads;
@@ -1167,7 +1206,7 @@ export interface Store {
1167
1206
  command(runId: string, command: {
1168
1207
  kind: string;
1169
1208
  body?: unknown;
1170
- }): Promise<Command>;
1209
+ }, options?: LaunchSealedWrite): Promise<Command>;
1171
1210
  /** The run's commands with an id above `after`, in id order. */
1172
1211
  commands(runId: string, after: number): Promise<Command[]>;
1173
1212
  /** Every run's commands with an id above its own cursor, in id order, in one read: a runner's poll of all it holds. A run
@@ -1252,21 +1291,32 @@ export declare class StoreLaunchMissing extends Error {
1252
1291
  export type ConstraintRule = "check" | "unique" | "foreign_key" | "not_null";
1253
1292
  /** A row the store's constraints refuse (a duplicate id or name, a revision of an unknown agent, a bad kind). When the
1254
1293
  * database said which rule refused it, `rule`; for a duplicate, `unique`: the table and the columns whose values were
1255
- * taken already (a primary key's or a UNIQUE's), so a caller tells "the name is taken" from any other refusal. */
1294
+ * taken already (a primary key's or a UNIQUE's), so a caller tells "the name is taken" from any other refusal. `index`:
1295
+ * the unique index (or constraint) the database named, when it named one: an index on an expression (one answer per
1296
+ * approval, schema.ts ONE_ANSWER_INDEX) has no plain columns to name, only its name. */
1256
1297
  export declare class StoreConstraint extends Error {
1257
1298
  readonly rule?: ConstraintRule;
1258
1299
  readonly unique?: {
1259
1300
  readonly table: string;
1260
1301
  readonly columns: readonly string[];
1261
1302
  };
1303
+ readonly index?: string;
1262
1304
  constructor(message: string, details?: {
1263
1305
  rule?: ConstraintRule;
1264
1306
  unique?: {
1265
1307
  table: string;
1266
1308
  columns: readonly string[];
1267
1309
  };
1310
+ index?: string;
1268
1311
  });
1269
1312
  }
1313
+ /** An approve or deny command refused because its approval is answered already: an unrefused answer naming it was
1314
+ * written first (the one-answer index, schema.ts ONE_ANSWER_INDEX), so this one lost. Both stores raise it from that
1315
+ * index's unique violation alone, at the command's insert; any other refusal stays a plain StoreConstraint. Its caller
1316
+ * reads the answer that won: approve's 409 already_answered, or nothing to do. */
1317
+ export declare class AnswerTaken extends StoreConstraint {
1318
+ constructor(message: string, index: string);
1319
+ }
1270
1320
  /** An agent's current revision is not the one a conditional write expected (addRevision's `ifCurrent`): another write
1271
1321
  * moved it first. `current` is the agent's current revision now. Nothing was written. */
1272
1322
  export declare class RevisionMoved extends Error {
@@ -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;
@@ -157,10 +163,13 @@ export class StoreLaunchMissing extends Error {
157
163
  }
158
164
  /** A row the store's constraints refuse (a duplicate id or name, a revision of an unknown agent, a bad kind). When the
159
165
  * 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. */
166
+ * taken already (a primary key's or a UNIQUE's), so a caller tells "the name is taken" from any other refusal. `index`:
167
+ * the unique index (or constraint) the database named, when it named one: an index on an expression (one answer per
168
+ * approval, schema.ts ONE_ANSWER_INDEX) has no plain columns to name, only its name. */
161
169
  export class StoreConstraint extends Error {
162
170
  rule;
163
171
  unique;
172
+ index;
164
173
  constructor(message, details = {}) {
165
174
  super(message);
166
175
  this.name = "StoreConstraint";
@@ -168,6 +177,18 @@ export class StoreConstraint extends Error {
168
177
  this.rule = details.rule;
169
178
  if (details.unique)
170
179
  this.unique = details.unique;
180
+ if (details.index)
181
+ this.index = details.index;
182
+ }
183
+ }
184
+ /** An approve or deny command refused because its approval is answered already: an unrefused answer naming it was
185
+ * written first (the one-answer index, schema.ts ONE_ANSWER_INDEX), so this one lost. Both stores raise it from that
186
+ * index's unique violation alone, at the command's insert; any other refusal stays a plain StoreConstraint. Its caller
187
+ * reads the answer that won: approve's 409 already_answered, or nothing to do. */
188
+ export class AnswerTaken extends StoreConstraint {
189
+ constructor(message, index) {
190
+ super(message, { rule: "unique", index });
191
+ this.name = "AnswerTaken";
171
192
  }
172
193
  }
173
194
  /** 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),
@@ -5,9 +5,7 @@ import type { Store } from "../store/store.js";
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,14 +1,18 @@
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.
@@ -16,9 +20,7 @@ export async function spentOverStore(store, runId, context) {
16
20
  }
17
21
  /** /usage's meters for a run that ended, over the one store's journal (design 2.1): cap.ts meterFiguresFrom over A's
18
22
  * 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. */
23
+ * 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
24
  export async function metersOverStore(store, runId, context) {
23
25
  const raw = await runEntries(store, runId, context);
24
26
  if (!raw.length)
@@ -30,6 +32,6 @@ export async function metersOverStore(store, runId, context) {
30
32
  return figures;
31
33
  const model = bookedSpend(raw, "model");
32
34
  if (!model.requests)
33
- return figures;
35
+ return unbookedCli(raw) ? { ...figures, tokens: null } : figures;
34
36
  return { ...figures, tokens: model.usd, known: { ...figures.known, tokens: model.known } };
35
37
  }
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "@earendil-works/chord";
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, as durableDecisions answers them: 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, as durableDecisions answers them: 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")
@@ -5,14 +5,16 @@
5
5
  import { createHash } from "node:crypto";
6
6
  import { 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";
12
+ import { LEARNED_NODES, LEARNED_NODES_MAX } from "../learned-nodes.js";
11
13
  import { labelled } from "../reflect-range.js";
12
14
  import { reflectFrom } from "../runner/end-of-run.js";
13
15
  import { journalEntries, journalRecords } from "../runner/journal-reader.js";
14
16
  import { endedAnswer, KINDS } from "../runner/journal-kinds.js";
15
- import { bookedSpend, costIsBooked } from "../runner/metrics.js";
17
+ import { bookedSpend, cliModelWorked, costIsBooked } from "../runner/metrics.js";
16
18
  import { waitingText } from "../tool-gate.js";
17
19
  /** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
18
20
  * entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
@@ -35,7 +37,8 @@ export async function runReflect(store, runId, context) {
35
37
  * tool call its assistant tool-call and its result. So a claude-agent / codex / opencode run reads the same rows, words
36
38
  * and final answer as a pi run of the same conversation. A run's own pi entries and its end-of-run turn (already model
37
39
  * shaped) pass through unchanged, so a pi run is untouched. */
38
- /** The calls the CLI record holds parked at their gate (a start marked parked) with no sent mark and no end. */
40
+ /** The calls the CLI record holds parked at an MCP door (a start marked parked, not in its tool bridge) with no sent mark
41
+ * and no end. */
39
42
  function parkedUnsent(entries) {
40
43
  const parked = new Set();
41
44
  const past = new Set();
@@ -43,7 +46,8 @@ function parkedUnsent(entries) {
43
46
  const callId = entry.data?.callId;
44
47
  if (typeof callId !== "string")
45
48
  continue;
46
- if (entry.kind === KINDS.callStart && entry.data.parked === true)
49
+ const start = entry.data;
50
+ if (entry.kind === KINDS.callStart && start.parked === true && start.bridge !== true)
47
51
  parked.add(callId);
48
52
  else if (entry.kind === KINDS.callSent || entry.kind === KINDS.callEnd)
49
53
  past.add(callId);
@@ -120,7 +124,7 @@ export function withPaidCosts(entries) {
120
124
  continue;
121
125
  const d = (e.data ?? {});
122
126
  if (typeof d.turn === "number" && typeof d.model === "string" && d.model.startsWith("paid:"))
123
- 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 } : {}) });
127
+ 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 } : {}) });
124
128
  }
125
129
  const charges = [];
126
130
  for (const e of entries) {
@@ -137,13 +141,31 @@ export function withPaidCosts(entries) {
137
141
  }
138
142
  if (!charges.length)
139
143
  return [...entries];
144
+ // The tool each call ran, by its id, from the model's answers (a CLI run's record shaped as pi's: piShaped).
145
+ const toolOfCall = new Map();
146
+ for (const e of entries) {
147
+ if (e.kind !== "pi.assistant")
148
+ continue;
149
+ for (const message of (e.model ?? [])) {
150
+ for (const part of Array.isArray(message.content) ? message.content : []) {
151
+ const call = part;
152
+ if (call.type === "toolCall" && typeof call.id === "string" && typeof call.name === "string")
153
+ toolOfCall.set(call.id, call.name);
154
+ }
155
+ }
156
+ }
140
157
  const out = [...entries];
141
158
  for (const charge of charges) {
142
159
  // Who charged: the request's own charged_by, which the cap writes as main's charge label names it (parallel, monid, an
143
160
  // MCP server, a browser vendor).
144
161
  const by = charge.chargedBy;
145
162
  const at = charge.call === undefined ? -1 : out.findIndex((e) => e.kind === "pi.tool-result" && String(e.model?.[0]?.toolCallId ?? "") === charge.call);
146
- 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 } : {}) };
163
+ // Named for its call's tool where the request names none of its own: by what was paid for where that is the tool
164
+ // itself (an MCP tool's catalog name, whose wire name the call carries), else by the call's tool (web_fetch, for
165
+ // Parallel's extract). A request that names its tool (a browser step's "browser") keeps it.
166
+ const called = !charge.own && charge.call !== undefined ? toolOfCall.get(charge.call) : undefined;
167
+ const tool = called !== undefined && wireName(charge.tool) !== called ? called : charge.tool;
168
+ const data = { tool, ...(by ? { charged_by: by } : {}), ...(charge.call ? { call: charge.call } : {}), ...(charge.tag ? { tag: charge.tag } : {}), ...(charge.usd !== null ? { usd: charge.usd } : {}) };
147
169
  const entry = { conversationId: at >= 0 ? out[at].conversationId : conv, kind: TOOL_COST, data, id: `paid:${charge.call ?? charge.tool}#${charge.turn}` };
148
170
  out.splice(at >= 0 ? at + 1 : out.length, 0, entry);
149
171
  }
@@ -151,6 +173,12 @@ export function withPaidCosts(entries) {
151
173
  }
152
174
  /** Whether `entries` are a CLI harness's record (its loop's calls and messages). */
153
175
  export const isCliRecord = (entries) => entries.some((entry) => entry.kind === KINDS.message || entry.kind === KINDS.callStart || entry.kind === KINDS.callEnd);
176
+ /** A path as a run's rows name it, for a harness working in `cwd`: one under `cwd` by its name there (`hello.md`), any
177
+ * other as given. */
178
+ const inWorkspace = (cwd) => (path) => {
179
+ const root = cwd.replace(/\/+$/, "");
180
+ return path.startsWith(`${root}/`) && path.length > root.length + 1 ? path.slice(root.length + 1) : path;
181
+ };
154
182
  /** A run's timeline rows, the renderer (timelineOf) unchanged, over the one store's entries, with a CLI harness's record
155
183
  * rendered as its pi-shaped entries (piShaped) and its paid tool charges read back from the paid-tools session
156
184
  * (withPaidCosts). A run whose record carries no per-request cost (a CLI harness's, a workflow's: metrics.ts
@@ -161,28 +189,67 @@ export const isCliRecord = (entries) => entries.some((entry) => entry.kind === K
161
189
  export async function runTimeline(store, runId, context, options = {}) {
162
190
  const entries = await runEntries(store, runId, context);
163
191
  const cli = isCliRecord(entries);
164
- const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), options);
192
+ // A CLI names a file by its absolute path under its working directory (CallStartData.cwd): the rows name it by its
193
+ // name in the workspace, never a path on the runner's machine. Its arguments, as the harness sent them, stay.
194
+ const cwd = cli && !options.path ? entries.find((entry) => entry.kind === KINDS.callStart && typeof entry.data?.cwd === "string")?.data : undefined;
195
+ const rendered = timelineOf(withPaidCosts(cli ? piShaped(entries) : entries), cwd ? { ...options, path: inWorkspace(cwd.cwd) } : options);
165
196
  const rows = costIsBooked(entries, cli) ? bookedUsage(rendered, entries, options) : rendered;
166
- return labelled((await runReflect(store, runId, context)), await datedRows(store, runId, rows));
197
+ return labelled((await runReflect(store, runId, context)), withLearnedNodes(await datedRows(store, runId, rows), entries, options.redact));
198
+ }
199
+ /** `rows` with each learned_workflow call's result row carrying the nodes its workflow ran (`learned_nodes`), from the
200
+ * LEARNED_NODES entry the call kept beside itself (learned-workflow.ts), joined by the call's id: each label through
201
+ * `redact` when given (the run's cut), as every text a row shows; never a node's error text. Rows of a run that ran none are as they were. */
202
+ function withLearnedNodes(rows, entries, redact) {
203
+ const traces = new Map();
204
+ const said = (text) => (redact ? redact(text) : text);
205
+ for (const entry of entries) {
206
+ if (entry.kind !== LEARNED_NODES)
207
+ continue;
208
+ const data = (entry.data ?? {});
209
+ if (typeof data.call !== "string" || !Array.isArray(data.nodes))
210
+ continue;
211
+ traces.set(data.call, data.nodes.slice(0, LEARNED_NODES_MAX).flatMap((node) => {
212
+ const one = (node ?? {});
213
+ if (typeof one.label !== "string" || typeof one.status !== "string")
214
+ return [];
215
+ // A model node's model and tier, each through the run's cut as the label is.
216
+ return [{ label: said(one.label), kind: String(one.kind ?? ""), status: one.status, duration_ms: typeof one.duration_ms === "number" ? one.duration_ms : 0,
217
+ ...(typeof one.model === "string" ? { model: said(one.model) } : {}), ...(typeof one.tier === "string" ? { tier: said(one.tier) } : {}) }];
218
+ }));
219
+ }
220
+ if (!traces.size)
221
+ return rows;
222
+ 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));
167
223
  }
168
224
  /** A CLI or workflow run's `rows` with its usage row in its booking's words (runner/metrics.ts bookedSpend over every
169
225
  * 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,
170
226
  * costsofar/1), in the renderer's words (`Cost` once ended, else `Cost so far`). The renderer's own row is replaced in
171
227
  * place; a run that booked a request and rendered none gets one at the end. One that booked none keeps its rows, with no
172
- * usage row. */
228
+ * usage row, unless it is a CLI run whose model worked with none booked (metrics.ts cliModelWorked: its requests went
229
+ * past its model proxy): its usage row says its cost is unknown, its model's work one charge with no price, so its view,
230
+ * live or ended, reads unknown, never $0. */
173
231
  function bookedUsage(rows, entries, options) {
174
232
  const model = bookedSpend(entries, "model");
175
233
  const paid = bookedSpend(entries, "paid");
176
234
  const at = rows.findIndex((row) => row.kind === "usage");
177
235
  const kept = rows.filter((row) => row.kind !== "usage");
178
- if (!model.requests && !paid.requests)
179
- return kept;
180
- const usd = model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
181
- const unpriced = model.unpriced + paid.unpriced;
236
+ const unbooked = !model.requests && isCliRecord(entries) && cliModelWorked(entries);
237
+ if (!model.requests && !paid.requests && !unbooked) {
238
+ // A run whose cap refused its first request (its park at the cap, an agentrun.budget entry) says it sent none, as a
239
+ // pi run's usage line does: never a request it did not make, and never silence about why nothing ran.
240
+ if (!entries.some((entry) => entry.kind === KINDS.budget) || kept.length === 0)
241
+ return kept;
242
+ const last = kept[kept.length - 1];
243
+ 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 } }];
244
+ }
245
+ const usd = unbooked || model.usd === null || paid.usd === null ? null : model.usd + paid.usd;
246
+ const unpriced = model.unpriced + paid.unpriced + (unbooked ? 1 : 0);
182
247
  const dollars = (value) => (value === 0 ? "$0" : `$${value.toFixed(4)}`);
183
248
  const spent = usd !== null ? dollars(usd) : `${dollars(model.known + paid.known)} known, ${unpriced} not priced,`;
184
249
  const charges = paid.requests ? ` and ${paid.requests} paid tool call${paid.requests === 1 ? "" : "s"}` : "";
185
- const summary = `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
250
+ const summary = unbooked
251
+ ? `${costLabel(options.ended === true)}: unknown, its model's requests were not metered${charges}`
252
+ : `${costLabel(options.ended === true)}: ${spent} over ${model.requests} model request${model.requests === 1 ? "" : "s"}${charges}`;
186
253
  const usage = { usd, requests: model.requests, ...(usd === null ? { so_far_usd: model.known + paid.known, unpriced } : {}) };
187
254
  const last = rows[rows.length - 1];
188
255
  const base = at >= 0 ? rows[at] : {
@@ -229,9 +296,10 @@ export async function wholeAnswers(store, runId, context, rows, options, whole)
229
296
  const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
230
297
  if (!rows.some(cut))
231
298
  return rows;
232
- let kept = answersServed.get(store);
299
+ // Kept by the store a snapshot was taken of: each snapshot's own store is a new object, and would never hit.
300
+ let kept = answersServed.get(store.origin);
233
301
  if (!kept)
234
- answersServed.set(store, (kept = new Map()));
302
+ answersServed.set(store.origin, (kept = new Map()));
235
303
  const keyOf = (row) => `${runId}\0${row.id}\0${whole.key}`;
236
304
  let uncut;
237
305
  const out = [];
@@ -1,9 +1,10 @@
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 { Reflect } from "../reflect-range.js";
4
+ import { type CostRun, type CostSummary } from "../learning-cost.js";
5
+ import { type Reflect } from "../reflect-range.js";
5
6
  import type { NoteRuns } from "../learning.js";
6
- import type { TimelineEvent } from "../timeline/index.js";
7
+ import type { EntryLike, TimelineEvent } from "../timeline/index.js";
7
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. */
@@ -51,6 +52,28 @@ 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
+ /** What a run's claim laid of its learning seed: the learned skills and workflows it was given, by name. */
69
+ type Laid = {
70
+ readonly skills: readonly string[];
71
+ readonly workflows: readonly string[];
72
+ };
73
+ /** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
74
+ * claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
75
+ * no entry. */
76
+ export declare function laidOf(entries: readonly EntryLike[]): Laid;
54
77
  /** A run's learning end with the notes its start gave it (`given`, when it started from a seed) and those its job read
55
78
  * (`read`, only when it read one): what a run view and GET /runs/{id}/learning show beside the end. */
56
79
  export type RunLearning = RunLearningEnd & {
@@ -61,6 +84,41 @@ export type RunLearning = RunLearningEnd & {
61
84
  * `read` calls on a file of its copy of the folder, the end-of-run turn's (`reflect`) left out, keyed on the notes it was
62
85
  * `given` and named as given. A file it was not given (MEMORY.md, one it wrote, one not in its seed) is not one of them. */
63
86
  export declare function notesReadOf(given: readonly NoteUsed[] | undefined, reflect: Pick<Reflect, "after" | "until"> | undefined, rows: readonly TimelineEvent[]): NoteUsed[];
87
+ /** What a run's job did with the learned skills and workflows its launch offered it (GET /runs/{id}/learning `used`:
88
+ * its `skills` and `workflows`, apart from the skills and workflows it learned): each skill, and whether the job read its SKILL.md (a read of `.agents/skills/<name>/SKILL.md`, or a
89
+ * harness's own skill tool on it); each learned workflow the job called, by the call's `name` (callArgsOf), how
90
+ * many calls and how many failed. The end-of-run turn's rows are left out, as notesRead leaves them. */
91
+ export type LearnedUse = {
92
+ readonly skills: readonly {
93
+ readonly name: string;
94
+ readonly read: boolean;
95
+ }[];
96
+ readonly workflows: readonly {
97
+ readonly name: string;
98
+ readonly calls: number;
99
+ readonly failed: number;
100
+ }[];
101
+ };
102
+ /** Each tool call of a run's journal, by its call's id: its tool and the arguments it was called with, as recorded (pi's
103
+ * call in its assistant entry, a CLI harness's in its record's call start). A timeline row's input preview is cut and
104
+ * for some tools absent, so what a call read or ran is read from these. */
105
+ export declare function callArgsOf(entries: readonly EntryLike[]): Map<string, {
106
+ tool: string;
107
+ args: Record<string, unknown>;
108
+ }>;
109
+ /** The skills a run's job loaded with a harness's own Skill tool (claude-agent's): a native call, which the CLI's session
110
+ * records as a kernel step of its own (`kernel.start` named `tool.Skill`, keyed `tool:<call id>`, then its `kernel.end`)
111
+ * and never as a host tool's call record, so no timeline row or callArgsOf entry has it. Each by the name the model
112
+ * gave (`agentrun:<name>` or the bare one), only when its step completed, and only outside every end-of-run turn (a
113
+ * reopened run's follow-up's loads are the job's). */
114
+ export declare function nativeSkillLoads(entries: readonly EntryLike[]): string[];
115
+ /** `laid`: what the run's claims laid (laidOf): a skill its launch offered but no claim laid (over the budget, or a name
116
+ * the revision's own skill holds, whose copy is the one installed) is not the run's learned skill, whatever it read.
117
+ * `loads`: the skills its job loaded with a harness's own Skill tool (nativeSkillLoads), each a read of its SKILL.md. */
118
+ export declare function learnedUseOf(started: RunLaunch["learning"], reflect: Pick<Reflect, "after" | "until"> | undefined, rows: readonly TimelineEvent[], args?: ReadonlyMap<string, {
119
+ tool: string;
120
+ args: Record<string, unknown>;
121
+ }>, laid?: Pick<Laid, "skills">, loads?: readonly string[]): LearnedUse;
64
122
  /** `end` with its run's given notes (from its launch's learning start) and the notes its job read. */
65
123
  export declare function withNotes(end: RunLearningEnd, started: RunLaunch["learning"], read: readonly NoteUsed[]): RunLearning;
66
124
  /** GET /runs/{id}/learning from the one store, in the shape the route gives (learning-routes.ts runLearningBody): the
@@ -98,6 +156,17 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
98
156
  tokens: {
99
157
  grade: import("../learning.js").Tokens | null;
100
158
  };
159
+ used: {
160
+ skills: {
161
+ name: string;
162
+ read: boolean;
163
+ }[];
164
+ workflows: {
165
+ name: string;
166
+ calls: number;
167
+ failed: number;
168
+ }[];
169
+ };
101
170
  given?: NoteUsed[];
102
171
  read?: NoteUsed[];
103
172
  learned?: import("../learning.js").NoteLearned[];
@@ -105,7 +174,8 @@ export declare function runLearningOverStore(store: Store, runId: string, shown:
105
174
  workflows?: import("../learning.js").LearnedFile[];
106
175
  run: string;
107
176
  state: "proposed" | "merged" | "seeded" | "reflecting" | "dropped";
108
- reason: "empty" | "cancelled" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
177
+ reason: "cancelled" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
109
178
  detail: string | null;
110
179
  at: string;
111
180
  } | null>;
181
+ export {};