@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
@@ -5,13 +5,17 @@
5
5
  // a person's words, the verdict, what it merged, learned, held for the owner's OK and lost, what the checks left out,
6
6
  // and what the grade spent. What the server keeps on a run before its end (what it was given and read, its seed's
7
7
  // notes, its answer's time and costs) is the run's, not this.
8
+ import { posix } from "node:path";
8
9
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
9
10
  import { currentLearning, holdsForOk, LEARNING_REASONS } from "../learning.js";
10
11
  import { runLearningBody } from "../learning-routes.js";
11
12
  import { learningStartOf, readLaunchBody } from "../run-launch.js";
12
13
  import { learningImpact, noteRuns, notesRead } from "../learning-run.js";
14
+ import { costSummary, runCostOf } from "../learning-cost.js";
15
+ import { runPathOf, workflowNameOf } from "../runner/learning-end.js";
16
+ import { reflects } from "../reflect-range.js";
13
17
  import { notesOf } from "../usage.js";
14
- import { runReflect, runTimeline } from "./journal.js";
18
+ import { runEntries, runReflect, runTimeline } from "./journal.js";
15
19
  import { FINAL_STATES } from "../store/store.js";
16
20
  import { journalEntries } from "../runner/journal-reader.js";
17
21
  import { KINDS } from "../runner/journal-kinds.js";
@@ -57,9 +61,12 @@ async function endOfKept(store, kept, row) {
57
61
  const spent = graded ?? (dropped && "usd" in dropped ? { usd: dropped.usd ?? null, tokens: dropped.tokens ?? null } : undefined);
58
62
  const cost = spent ? { cost_usd: { grade: spent.usd }, tokens: { grade: spent.tokens ?? null } } : {};
59
63
  if (merged && graded) {
60
- const what = learnedOf(keptOf(row.proposal, graded.verdict), graded.verdict);
64
+ // Each item as the merge settled it: its record's verdict (a note it left out is no longer kept, and says why). A merge
65
+ // recorded with none (before the record kept it) reads no item decisions.
66
+ const verdict = merged.verdict;
67
+ const what = verdict ? learnedOf(keptOf(row.proposal, verdict), verdict) : { learned: [], pending: [], skills: [], workflows: [] };
61
68
  return {
62
- state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, verdict: graded.verdict, graded: { ...graded.graded }, ...cost, merged: merged.commit,
69
+ state: "merged", reason: null, detail: merged.detail, at: endedAt, ...left, ...(verdict ? { verdict } : {}), graded: { ...graded.graded }, ...cost, merged: merged.commit,
63
70
  learned: what.learned, ...(what.pending.length ? { pending: what.pending } : {}), ...(what.skills.length ? { skills: what.skills } : {}), ...(what.workflows.length ? { workflows: what.workflows } : {}),
64
71
  };
65
72
  }
@@ -143,7 +150,7 @@ export async function agentLearningOverStore(store, agentId) {
143
150
  const final = FINAL_STATES.includes(run.state);
144
151
  const started = await learningStartOfRun(store, run.id);
145
152
  const end = await runLearningEnd(store, run.id);
146
- const read = final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: true })) : [];
153
+ const { read, laid } = await journalReadsOf(store, run, started);
147
154
  if (started || end)
148
155
  files.push(notesOf({ given: started?.given ?? [], read }));
149
156
  // The row learningImpact reads (the file path's RunRow): an ended run is a completed one.
@@ -152,18 +159,118 @@ export async function agentLearningOverStore(store, agentId) {
152
159
  startedAt: new Date(run.startedAt).toISOString(), endedAt: run.endedAt === null ? null : new Date(run.endedAt).toISOString(),
153
160
  costUsd: run.costUsd, importedFrom: run.importedFrom, archivedAt: run.archivedAt === null ? null : new Date(run.archivedAt).toISOString(),
154
161
  });
155
- learnings.set(run.id, end ? impactLearningOf(end, started) : null);
162
+ // What its claims laid of the skills and workflows it was offered (every learningLaid entry, laidOf): the run started
163
+ // from those alone.
164
+ learnings.set(run.id, end ? impactLearningOf(end, started, laid) : null);
156
165
  }
157
166
  return { counts, impact: learningImpact(rows, (row) => learnings.get(row.id) ?? null), notes: noteRuns(files) };
158
167
  }
168
+ /** Agent `agentId`'s cost per run from the one store (GET /agents/{id}/learning/cost, learning-cost.ts): each of its
169
+ * agentic runs that ended (ended, stopped or failed), oldest first, numbered from 1, with its own cost and what learning
170
+ * 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
171
+ * (journalReadsOf), and the learned revision it started from (its launch's seed); and what the series shows
172
+ * (costSummary). A run still at work, an imported or archived one and a workflow revision's run are left out; a learning
173
+ * 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
174
+ * shown, each keeping its number; the summary is over every run. */
175
+ export async function agentCostOverStore(store, agentId, limit = Infinity) {
176
+ const kinds = new Map();
177
+ const ended = (await store.runs.list({ agentId })).filter((run) => run.agentId === agentId && FINAL_STATES.includes(run.state) && !run.importedFrom && run.archivedAt === null).sort((a, b) => a.startedAt - b.startedAt || (a.id < b.id ? -1 : 1));
178
+ const runs = [];
179
+ for (const run of ended) {
180
+ if (!kinds.has(run.revisionId))
181
+ kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind);
182
+ if (kinds.get(run.revisionId) === "workflow")
183
+ continue;
184
+ const started = await learningStartOfRun(store, run.id);
185
+ const { looked, grade } = await learningSpendOf(store, run.id);
186
+ const { path, workflow } = await journalReadsOf(store, run, started);
187
+ runs.push({ n: runs.length + 1, run_id: run.id, started_at: new Date(run.startedAt).toISOString(), path, workflow, learned_revision: started?.seed ?? null, ...runCostOf(run.costUsd, looked, grade) });
188
+ }
189
+ return { runs: runs.slice(Math.max(0, runs.length - limit)), summary: costSummary(runs), total_runs: runs.length, unknown_cost_runs: runs.filter((run) => run.total_usd === null).length };
190
+ }
191
+ /** What run `runId`'s learning spent, as its cost per run counts it: what it kept as it answered (`looked`: answeredOf),
192
+ * and its grade's spend (`grade`): its learning run's cost once that run ended, stopped or failed (runner/learning-loop.ts
193
+ * keeps the grade's spend there, a paid grade a person stopped included; null when unknown), 0 while it runs or when the
194
+ * run queued none. */
195
+ async function learningSpendOf(store, runId) {
196
+ const kept = await store.learning.proposal(runId);
197
+ if (!kept)
198
+ return { looked: null, grade: 0 };
199
+ const looked = answeredOf((kept.proposal ?? {}));
200
+ const learningRun = kept.learningRunId ? await store.runs.get(kept.learningRunId) : undefined;
201
+ return { looked, grade: learningRun && FINAL_STATES.includes(learningRun.state) ? (learningRun.costUsd ?? null) : 0 };
202
+ }
203
+ /** What a run's journal tells the agent's learning view and its cost per run: the notes its job opened (`read`, once
204
+ * final), what its claims laid of the skills and workflows it was offered (`laid`), and, for a run offered a learned
205
+ * workflow, the path it took and the workflow it called last (`path`, `workflow`: runner/learning-end.ts
206
+ * runPathOf, workflowNameOf; any other run's path is `agent`). Read once for a settled run and kept by its epoch
207
+ * (settledJournalReads), else read now. */
208
+ async function journalReadsOf(store, run, started) {
209
+ const final = FINAL_STATES.includes(run.state);
210
+ const offered = !!(started?.skills?.length || started?.workflows?.length);
211
+ const flows = !!started?.workflows?.length;
212
+ const journal = async () => {
213
+ const rows = (final && started?.given.length) || flows ? await runTimeline(store, run.id, BACKGROUND_CONTEXT, { settled: final }) : [];
214
+ const entries = offered ? await runEntries(store, run.id, BACKGROUND_CONTEXT) : [];
215
+ const path = flows ? runPathOf(rows) : "agent";
216
+ return {
217
+ read: final && started?.given.length ? notesReadOf(started.given, await runReflect(store, run.id, BACKGROUND_CONTEXT), rows) : [],
218
+ laid: offered ? laidOf(entries) : undefined,
219
+ path,
220
+ // Only a name the launch offered: a call's raw `name` (a failed call's included) is the model's text, never shown.
221
+ workflow: path === "agent" ? null : offeredName(workflowNameOf([...callArgsOf(entries).values()]), started?.workflows),
222
+ };
223
+ };
224
+ return final ? settledJournalReads(store, run.id, run.epoch, journal) : journal();
225
+ }
226
+ /** `name` when it is one of the learned workflows the run's launch offered, else null. */
227
+ const offeredName = (name, offered) => (name !== null && offered?.includes(name) ? name : null);
228
+ /** What a settled run's journal tells the agent's learning view, kept by store and run id with the run's epoch: a claim
229
+ * and a run's end each move the epoch, and only a claim writes to its journal, so a settled run's reads hold until the
230
+ * next claim of it. At most SETTLED_READS_MAX runs a store, the oldest read dropped first. */
231
+ const settledReads = new WeakMap();
232
+ const SETTLED_READS_MAX = 4096;
233
+ async function settledJournalReads(store, runId, epoch, read) {
234
+ let runs = settledReads.get(store);
235
+ if (!runs)
236
+ settledReads.set(store, (runs = new Map()));
237
+ const kept = runs.get(runId);
238
+ if (kept && kept.epoch === epoch)
239
+ return kept.value;
240
+ const value = await read();
241
+ runs.delete(runId);
242
+ runs.set(runId, { epoch, value });
243
+ if (runs.size > SETTLED_READS_MAX)
244
+ runs.delete(runs.keys().next().value);
245
+ return value;
246
+ }
247
+ /** What every claim of a run laid, from its learningLaid entries, each name once: a resumed claim finds an earlier
248
+ * claim's skill folders there already and lays none of them again, though the run still has them. None laid when it has
249
+ * no entry. */
250
+ export function laidOf(entries) {
251
+ const names = (list) => (Array.isArray(list) ? list.filter((name) => typeof name === "string") : []);
252
+ const skills = new Set();
253
+ const workflows = new Set();
254
+ for (const entry of entries) {
255
+ if (entry.kind !== KINDS.learningLaid)
256
+ continue;
257
+ const data = (entry.data ?? {});
258
+ for (const name of names(data.skills))
259
+ skills.add(name);
260
+ for (const name of names(data.workflows))
261
+ workflows.add(name);
262
+ }
263
+ return { skills: [...skills], workflows: [...workflows] };
264
+ }
159
265
  /** What a run's learning end tells its impact, as ofAgent's learningOf read a held run: how it ended and when, the notes
160
266
  * it started from; when its job answered and its costs once it looked back (a look-back of 0 for an ended one that did
161
267
  * not); its grade's cost once it ended (0 when nothing was graded). */
162
- function impactLearningOf(end, started) {
268
+ function impactLearningOf(end, started, laid) {
163
269
  const over = end.state === "merged" || end.state === "dropped";
164
270
  const looked = end.answered_at !== undefined ? { answered_at: end.answered_at, job_cost_usd: end.job_cost_usd ?? null, look_back_usd: end.look_back_usd ?? null } : over ? { look_back_usd: 0 } : {};
165
271
  return {
166
- state: end.state, reason: end.reason, at: end.at, ...(started?.seedNotes !== undefined ? { seed_notes: started.seedNotes } : {}), ...looked,
272
+ state: end.state, reason: end.reason, at: end.at, ...(started?.seedNotes !== undefined ? { seed_notes: started.seedNotes } : {}),
273
+ ...(laid?.skills.length ? { seed_skills: laid.skills.length } : {}), ...(laid?.workflows.length ? { seed_workflows: laid.workflows.length } : {}), ...looked,
167
274
  ...(over ? { grade_usd: end.cost_usd ? end.cost_usd.grade : 0 } : {}),
168
275
  };
169
276
  }
@@ -176,6 +283,120 @@ export function notesReadOf(given, reflect, rows) {
176
283
  const names = new Map(given.map((note) => [note.file, note.name]));
177
284
  return notesRead(reflect, rows).flatMap((file) => (names.has(file) ? [{ file, name: names.get(file) }] : []));
178
285
  }
286
+ /** learned_workflow by every name a harness calls it (runner/learning-end.ts LEARNED_NAMES). */
287
+ const WORKFLOW_CALLS = new Set(["learned_workflow", "mcp__hands__learned_workflow"]);
288
+ /** 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
289
+ * call in its assistant entry, a CLI harness's in its record's call start). A timeline row's input preview is cut and
290
+ * for some tools absent, so what a call read or ran is read from these. */
291
+ export function callArgsOf(entries) {
292
+ const out = new Map();
293
+ const argsOf = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : {});
294
+ for (const entry of entries) {
295
+ if (entry.kind === "pi.assistant") {
296
+ for (const part of (entry.model?.[0]?.content ?? [])) {
297
+ if (part?.type === "toolCall" && typeof part.id === "string" && typeof part.name === "string")
298
+ out.set(part.id, { tool: part.name, args: argsOf(part.arguments) });
299
+ }
300
+ }
301
+ else if (entry.kind === KINDS.callStart) {
302
+ const data = (entry.data ?? {});
303
+ if (typeof data.callId === "string" && typeof data.tool === "string")
304
+ out.set(data.callId, { tool: data.tool, args: argsOf(data.input) });
305
+ }
306
+ }
307
+ return out;
308
+ }
309
+ /** The plugin claude-agent serves a run's skills from (@parcha/agentrun-harness-claude CLAUDE_AGENT_SKILLS_PLUGIN): the
310
+ * model loads each as `agentrun:<name>`, or by its bare name. */
311
+ const CLAUDE_SKILLS_PLUGIN = "agentrun";
312
+ /** The id ranges of a run's end-of-run turns, each from its prompt (an endOfRunTurn entry, `role: "person"`) to its
313
+ * answer (`role: "model"`); one with no answer runs to the person's next message (a reopened run's follow-up), else to
314
+ * the end. A reopened run has one per time it looked back. */
315
+ function endOfRunTurns(entries) {
316
+ const turns = [];
317
+ let open;
318
+ for (const entry of [...entries].filter((one) => one.id !== undefined).sort((a, b) => a.id - b.id)) {
319
+ const role = entry.data?.role;
320
+ if (entry.kind === KINDS.endOfRunTurn && role === "person")
321
+ open ??= entry.id;
322
+ else if (open !== undefined && ((entry.kind === KINDS.endOfRunTurn && role === "model") || (entry.kind === KINDS.message && role === "person"))) {
323
+ turns.push([open, entry.id]);
324
+ open = undefined;
325
+ }
326
+ }
327
+ if (open !== undefined)
328
+ turns.push([open, Number.POSITIVE_INFINITY]);
329
+ return turns;
330
+ }
331
+ /** 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
332
+ * records as a kernel step of its own (`kernel.start` named `tool.Skill`, keyed `tool:<call id>`, then its `kernel.end`)
333
+ * and never as a host tool's call record, so no timeline row or callArgsOf entry has it. Each by the name the model
334
+ * gave (`agentrun:<name>` or the bare one), only when its step completed, and only outside every end-of-run turn (a
335
+ * reopened run's follow-up's loads are the job's). */
336
+ export function nativeSkillLoads(entries) {
337
+ const turns = endOfRunTurns(entries);
338
+ const inTurn = (id) => id !== undefined && turns.some(([from, to]) => id >= from && id <= to);
339
+ const asked = new Map();
340
+ const loaded = [];
341
+ for (const entry of entries) {
342
+ if (inTurn(entry.id))
343
+ continue;
344
+ const data = (entry.data ?? {});
345
+ if (entry.kind === "kernel.start" && data.name === "tool.Skill" && typeof data.stepId === "string") {
346
+ const skill = data.input?.skill;
347
+ if (typeof skill === "string")
348
+ asked.set(data.stepId, skill);
349
+ }
350
+ else if (entry.kind === "kernel.end" && typeof data.stepId === "string" && data.status === "completed" && asked.has(data.stepId)) {
351
+ loaded.push(asked.get(data.stepId));
352
+ }
353
+ }
354
+ return loaded;
355
+ }
356
+ /** Whether a skill loaded by the name `asked` is skill `name`: by its plugin-qualified name or its bare one. */
357
+ const loadsSkill = (asked, name) => asked === name || asked === `${CLAUDE_SKILLS_PLUGIN}:${name}`;
358
+ /** Where a claim lays a learned skill's SKILL.md in the run's work (learning.ts RUN_SKILLS). */
359
+ const laidSkillPath = (name) => `.agents/skills/${name}/SKILL.md`;
360
+ /** Whether call `call` read skill `name`'s SKILL.md: the read hand on the path its claim laid it at (`.agents/skills/
361
+ * <name>/SKILL.md` in the run's work, relative or absolute under it, never another file whose path ends the same way), a
362
+ * CLI adapter's read_skill_file of the skill's SKILL.md, or a Skill tool call on the skill. */
363
+ function readsSkill(call, name) {
364
+ const text = (key) => (typeof call.args[key] === "string" ? call.args[key] : "");
365
+ if (call.tool === "read" || call.tool === "mcp__hands__read") {
366
+ const path = posix.normalize(text("path"));
367
+ return path === laidSkillPath(name) || (path.startsWith("/") && path.endsWith(`/${laidSkillPath(name)}`));
368
+ }
369
+ if (call.tool === "read_skill_file")
370
+ return text("skill") === name && posix.normalize(text("path")) === "SKILL.md";
371
+ if (call.tool === "Skill")
372
+ return [text("skill"), text("command"), text("name")].some((asked) => loadsSkill(asked, name));
373
+ return false;
374
+ }
375
+ /** `laid`: what the run's claims laid (laidOf): a skill its launch offered but no claim laid (over the budget, or a name
376
+ * the revision's own skill holds, whose copy is the one installed) is not the run's learned skill, whatever it read.
377
+ * `loads`: the skills its job loaded with a harness's own Skill tool (nativeSkillLoads), each a read of its SKILL.md. */
378
+ export function learnedUseOf(started, reflect, rows, args = new Map(), laid = { skills: [] }, loads = []) {
379
+ const job = rows.filter((row) => !reflects(reflect, row.id));
380
+ const results = new Map(job.flatMap((row) => (row.kind === "tool_result" && row.tool_use_id ? [[row.tool_use_id, row.tool_status]] : [])));
381
+ const calls = job.filter((row) => row.kind === "tool_use" && !row.parent_tool_use_id && row.tool_use_id).flatMap((row) => {
382
+ const call = args.get(row.tool_use_id);
383
+ return call ? [{ id: row.tool_use_id, ...call }] : [];
384
+ });
385
+ const installed = new Set(laid.skills);
386
+ const skills = (started?.skills ?? []).filter((name) => installed.has(name)).map((name) => ({ name, read: calls.some((call) => results.get(call.id) === "success" && readsSkill(call, name)) || loads.some((asked) => loadsSkill(asked, name)) }));
387
+ const workflows = new Map();
388
+ for (const call of calls) {
389
+ if (!WORKFLOW_CALLS.has(call.tool) || typeof call.args.name !== "string")
390
+ continue;
391
+ const seen = workflows.get(call.args.name) ?? { calls: 0, failed: 0 };
392
+ seen.calls += 1;
393
+ // Only a result that says so: a call with no result yet (one still running) is no failure.
394
+ if (results.get(call.id) === "failed")
395
+ seen.failed += 1;
396
+ workflows.set(call.args.name, seen);
397
+ }
398
+ return { skills, workflows: [...workflows].map(([name, seen]) => ({ name, ...seen })) };
399
+ }
179
400
  /** `end` with its run's given notes (from its launch's learning start) and the notes its job read. */
180
401
  export function withNotes(end, started, read) {
181
402
  return {
@@ -203,8 +424,10 @@ export async function runLearningOverStore(store, runId, shown, secrets, statuse
203
424
  const started = await learningStartOfRun(store, runId);
204
425
  const row = await store.runs.get(runId);
205
426
  const settled = row !== undefined && FINAL_STATES.includes(row.state);
206
- const read = started?.given.length ? notesReadOf(started.given, await runReflect(store, runId, BACKGROUND_CONTEXT), await runTimeline(store, runId, BACKGROUND_CONTEXT, { settled })) : [];
427
+ const used = started?.given.length || started?.skills?.length || started?.workflows?.length;
428
+ const [reflect, rows, entries] = used ? await Promise.all([runReflect(store, runId, BACKGROUND_CONTEXT), runTimeline(store, runId, BACKGROUND_CONTEXT, { settled }), runEntries(store, runId, BACKGROUND_CONTEXT)]) : [undefined, [], []];
429
+ const read = started?.given.length ? notesReadOf(started.given, reflect, rows) : [];
207
430
  const learning = withNotes(end, started, read);
208
431
  const current = holdsForOk(learning) && row && statuses ? currentLearning(learning, await statuses(row.agentId)) : learning;
209
- return runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled }, shown, secrets);
432
+ return runLearningBody({ id: runId, learning: current, seed: started?.seed ?? null, settled, used: learnedUseOf(started, reflect, rows, callArgsOf(entries), laidOf(entries), nativeSkillLoads(entries)) }, shown, secrets);
210
433
  }
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
- import type { ImportedFrom, RunRow, Store } from "../store/store.js";
2
+ import { type ImportedFrom, type RunRow, type Store } from "../store/store.js";
3
3
  /** A revision's kind, as the row names it. */
4
4
  export type RevisionKind = "agentic" | "workflow";
5
5
  /** The run state the v2 API serves, as the old store kept it: a non-terminal run is 'running' (the live view refines its
@@ -19,9 +19,11 @@ export interface RunRowView {
19
19
  readonly archivedAt?: string;
20
20
  readonly importedFrom?: ImportedFrom;
21
21
  }
22
- /** A run's v2 state from A's state and an ended run's outcome: an escalation reads 'escalated', a plain completion
23
- * 'completed'; stopped and failed are their own; queued, running and parked read 'running'. */
24
- export declare function runReadState(run: RunRow): RunReadState;
22
+ /** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
23
+ * stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
24
+ * stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
25
+ * stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
26
+ export declare function runReadState(run: RunRow, kind: RevisionKind): RunReadState;
25
27
  /** The runs, newest first; `agent` and `revision` narrow it. Archived runs are listed too (the server filters them), with
26
28
  * the archive time coalesced onto each row, and a not-ended run's cost its booked-so-far spend. */
27
29
  export declare function listRuns(store: Store, filter: {
@@ -1,16 +1,19 @@
1
+ import { stoppedByPerson } from "../store/store.js";
1
2
  import { spentOverStore } from "./cap.js";
2
3
  const isoOf = (ms) => new Date(ms).toISOString();
3
- /** A run's v2 state from A's state and an ended run's outcome: an escalation reads 'escalated', a plain completion
4
- * 'completed'; stopped and failed are their own; queued, running and parked read 'running'. */
5
- export function runReadState(run) {
6
- return stateOf(run);
4
+ /** A run's v2 state from A's state and its outcome: an escalation reads 'escalated', a plain completion 'completed';
5
+ * stopped and failed are their own; queued, running and parked read 'running', and so does an agentic run a person
6
+ * stopped (`kind`: its revision's), whose turn ended and never the run, as main's stop leaves one (runs.ts statusOf: a
7
+ * stopped run is input_required and idle). A cancel, a workflow's stop and an imported run's read 'stopped'. */
8
+ export function runReadState(run, kind) {
9
+ return stateOf(run, kind);
7
10
  }
8
- function stateOf(run) {
11
+ function stateOf(run, kind) {
9
12
  switch (run.state) {
10
13
  case "ended":
11
14
  return run.outcome === "escalated" ? "escalated" : "completed";
12
15
  case "stopped":
13
- return "stopped";
16
+ return stoppedByPerson(run, kind) ? "running" : "stopped";
14
17
  case "failed":
15
18
  return "failed";
16
19
  default:
@@ -21,16 +24,20 @@ function stateOf(run) {
21
24
  * (the booked-so-far spend for a run not ended, else its stored cost). */
22
25
  function viewOf(run, agentArchivedAt, kind, cost) {
23
26
  const archivedAt = run.archivedAt ?? agentArchivedAt;
27
+ const state = stateOf(run, kind);
28
+ // A run that reads running has no end to show: a person's stop keeps its time and words in the store, for its reopen
29
+ // to clear, and the run is not over.
30
+ const over = state !== "running";
24
31
  return {
25
32
  id: run.id,
26
33
  agent: run.agentId,
27
34
  revision: run.revisionId,
28
35
  kind,
29
- state: stateOf(run),
36
+ state,
30
37
  startedAt: isoOf(run.startedAt),
31
- ...(run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
38
+ ...(over && run.endedAt !== null ? { endedAt: isoOf(run.endedAt) } : {}),
32
39
  ...(cost !== null ? { costUsd: cost } : {}),
33
- ...(run.summary !== null ? { summary: run.summary } : {}),
40
+ ...(over && run.summary !== null ? { summary: run.summary } : {}),
34
41
  ...(archivedAt !== null ? { archivedAt: isoOf(archivedAt) } : {}),
35
42
  ...(run.importedFrom !== null ? { importedFrom: { source: run.importedFrom.source, session: run.importedFrom.session } } : {}),
36
43
  };
@@ -47,7 +54,7 @@ function joins(store, context) {
47
54
  kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind ?? "agentic");
48
55
  // A run that has not ended shows the spend booked so far (the cap's own reading over the journal, the figure it holds
49
56
  // the run to), since cost_usd is written only at the end; an ended run shows its stored cost.
50
- const cost = runReadState(run) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
57
+ const cost = runReadState(run, kinds.get(run.revisionId)) === "running" ? await spentOverStore(store, run.id, context) : run.costUsd;
51
58
  return viewOf(run, agentArchived.get(run.agentId), kinds.get(run.revisionId), cost);
52
59
  },
53
60
  };
@@ -16,8 +16,12 @@ export async function stats(store) {
16
16
  const shown = new Map();
17
17
  const hidden = new Map();
18
18
  const running = [];
19
+ // Each revision's kind, read once: an agentic run a person stopped reads running (runReadState).
20
+ const kinds = new Map();
19
21
  for (const run of runs) {
20
- const state = runReadState(run);
22
+ if (!kinds.has(run.revisionId))
23
+ kinds.set(run.revisionId, (await store.agents.revision(run.revisionId))?.kind === "workflow" ? "workflow" : "agentic");
24
+ const state = runReadState(run, kinds.get(run.revisionId));
21
25
  const runArchived = run.archivedAt !== null;
22
26
  if (state === "running" && !runArchived && !archivedAgent.has(run.agentId))
23
27
  running.push(run.id);
@@ -1,4 +1,4 @@
1
- import type { TimelineEvent } from "./timeline/index.js";
1
+ import { type TimelineEvent } from "./timeline/index.js";
2
2
  import { type ItemStatus } from "./learning.js";
3
3
  import { type RunMoment, type SignInReader } from "./run-view.js";
4
4
  import { type Store } from "./store/store.js";
@@ -24,6 +24,20 @@ export interface ViewDeps {
24
24
  export declare function viewOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
25
25
  /** The run list's answer from the store, byte-identical to runs.ts's summary: the view's subset a list shows. */
26
26
  export declare function summaryOverStore(store: Store, runId: string, deps: ViewDeps): Promise<Record<string, unknown> | undefined>;
27
+ /** A run's facts as its view states them, and none of its words: its kind, revision, agent, status and times, and whether
28
+ * its output is withheld (`unshown`). What a read that serves its own parts (the graph) needs of the run: read off the
29
+ * run as viewOverStore reads it, with nothing of it served, so nothing is redacted here. Undefined for an unknown run. */
30
+ export declare function factsOverStore(store: Store, runId: string, deps: ViewDeps): Promise<RunStated | undefined>;
31
+ /** A run's facts as its view states them (factsOverStore): no word of it, so nothing in it is redacted. */
32
+ export type RunStated = {
33
+ readonly kind: string;
34
+ readonly revision: string;
35
+ readonly agentId: string;
36
+ readonly status: string;
37
+ readonly createdAt: string;
38
+ readonly endedAt: string | null;
39
+ readonly unshown: boolean;
40
+ };
27
41
  /** A run's live moment from the store (momentOf), for the one acceptance each act a run takes reads. A run no runner holds
28
42
  * (ended, or running with no live claim) reads live false. */
29
43
  export declare function momentOverStore(store: Store, runId: string, deps?: ViewDeps): Promise<RunMoment | undefined>;