@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
@@ -20,8 +20,14 @@
20
20
  // that dies: the run's next claim reads it back from the journal and takes the wait up (`adopt`).
21
21
  import { createHash } from "node:crypto";
22
22
  import { HOST_PHASE } from "./timeline/index.js";
23
- /** How long a person's time lasts at most before it expires: an unanswered ask, and a take-over with no input. Its worth of session time is held up front. */
23
+ /** How long a person's time lasts at most before it expires: an unanswered ask, a take-over with no input, and a run that
24
+ * waits for its person's answer with its browser kept open. Its worth of session time is held up front. The default of
25
+ * the server setting PERSON_WAIT_ENV. */
24
26
  export const PERSON_HOLD_MS = 15 * 60_000;
27
+ /** The server setting for that window, in whole minutes (1 to 360; anything else keeps the 15-minute default): how long a
28
+ * run waiting for its person keeps its browser open, how long an agent's hand-over ask waits, and how long a take-over
29
+ * lasts with no input. One setting for all three, so they never drift apart. */
30
+ export const PERSON_WAIT_ENV = "AGENTRUN_BROWSER_PERSON_WAIT_MIN";
25
31
  /** How long a take-over outlasts its viewer. */
26
32
  export const PERSON_AWAY_MS = 2 * 60_000;
27
33
  /** Under `--faux` only (the tests, beside the fake browser's own FAUX_BROWSER_LOG): the two windows above, in ms, `<hold>,<away>`. */
@@ -509,7 +515,8 @@ export function personHands(options) {
509
515
  * and its release lets the browser go, booking its time to then. `pauses: false`: a refusal pauses nothing, the run
510
516
  * parks on its question as it would with no browser. Refused in the cap's words when there is no room. `lapsed`
511
517
  * settles, in words, at the bound, when the cap refuses a re-hold (a take-over's sharing the session), or when a
512
- * session it keeps is let go (sessionEnded); drop() lets the shares go, once. */
518
+ * session it keeps is let go (sessionEnded); confirmed() writes that lapse's row and ended state once the runner
519
+ * parked the run on it; drop() lets the shares go, once. */
513
520
  async wait(callId, tags, since = now()) {
514
521
  const user = `wait:${callId}`;
515
522
  const held = [];
@@ -524,25 +531,57 @@ export function personHands(options) {
524
531
  const expiresAt = since + holdMs;
525
532
  if (expiresAt <= now())
526
533
  return { refused: waitExpired(holdMs) };
534
+ const record = (row, at) => {
535
+ void note(HOST_PHASE, { summary: row, at });
536
+ try {
537
+ options.waitEnded?.(at, row);
538
+ }
539
+ catch { /* the Screen tab's state is a convenience; the row stands */ }
540
+ };
527
541
  for (const tag of new Set(tags)) {
528
542
  const refused = await acquire(tag, user, WAIT_WHAT, false, expiresAt);
529
543
  if (refused) {
530
544
  letGo();
545
+ // The cap has no room for the person's time: the run parks and its release lets the browser go, and the person is told why.
546
+ if (!closed)
547
+ record(`The browser was released while the run waited for you: ${refused.refused}`, now());
531
548
  return refused;
532
549
  }
533
550
  held.push(tag);
534
551
  }
535
- let lapse = () => { };
536
- const lapsed = new Promise((resolve) => (lapse = resolve));
552
+ let settle = () => { };
553
+ const lapsed = new Promise((resolve) => (settle = resolve));
554
+ // The wait ends once: at its window, when a session it keeps ends, or at the cap. Each settles `lapsed` at once, and its
555
+ // timeline row and the Screen tab's state are written when the runner confirms the run parked on it (a lapse during
556
+ // the answer's placement is ignored by the runner: the answer's turn goes on, on the same browser). The answer ends it
557
+ // too (drop: no row, the run goes on).
558
+ let over = false;
559
+ let pending;
560
+ const end = (words, row) => {
561
+ if (over)
562
+ return;
563
+ over = true;
564
+ pending = { row, at: now() };
565
+ settle(words);
566
+ };
567
+ const lapse = (words) => end(words, words === WAIT_SESSION_GONE ? BROWSER_GONE_WHILE_WAITING : `The browser was released while the run waited for you: ${words}`);
537
568
  const entry = { tags: new Set(held), lapse };
538
569
  waits.set(user, entry);
539
- bound = timers.set(() => lapse(waitExpired(holdMs)), Math.max(0, expiresAt - now()));
570
+ bound = timers.set(() => end(waitExpired(holdMs), releasedAfterWait(holdMs)), Math.max(0, expiresAt - now()));
540
571
  // A session let go while its hold was being admitted: told before this wait was there to hear it.
541
572
  if (held.some((tag) => ended.has(tag)))
542
573
  lapse(WAIT_SESSION_GONE);
543
574
  return {
544
575
  lapsed,
576
+ confirmed: () => {
577
+ const ended = pending;
578
+ pending = undefined;
579
+ if (ended)
580
+ record(ended.row, ended.at);
581
+ },
545
582
  drop: () => {
583
+ over = true;
584
+ pending = undefined;
546
585
  if (waits.get(user) === entry)
547
586
  waits.delete(user);
548
587
  letGo();
@@ -580,5 +619,15 @@ export function personHands(options) {
580
619
  * tests' (FAUX_PERSON_MS_ENV). */
581
620
  export function personWindows(env, faux) {
582
621
  const [hold, away] = (faux ? env[FAUX_PERSON_MS_ENV] ?? "" : "").split(",").map(Number);
583
- return { holdMs: hold && hold > 0 ? hold : PERSON_HOLD_MS, awayMs: away && away > 0 ? away : PERSON_AWAY_MS };
622
+ return { holdMs: hold && hold > 0 ? hold : personWaitMs(env), awayMs: away && away > 0 ? away : PERSON_AWAY_MS };
623
+ }
624
+ /** The person's window from the server setting PERSON_WAIT_ENV, in ms: whole minutes from 1 to 360, else the default. */
625
+ export function personWaitMs(env) {
626
+ const raw = env[PERSON_WAIT_ENV]?.trim();
627
+ const minutes = raw && /^\d+$/.test(raw) ? Number(raw) : NaN;
628
+ return minutes >= 1 && minutes <= 360 ? minutes * 60_000 : PERSON_HOLD_MS;
584
629
  }
630
+ /** The timeline row when a run's wait for its person ends at its window and its browser is let go. */
631
+ export const releasedAfterWait = (holdMs) => `The browser was released after ${Math.round(holdMs / 60_000) || 1} min waiting for you`;
632
+ /** The timeline row when a browser the run kept open for its person ended before their answer (its provider ended it). */
633
+ export const BROWSER_GONE_WHILE_WAITING = "The browser session ended while the run waited for you";
@@ -0,0 +1,23 @@
1
+ /** The store seam: the server's settings (store/store.ts Settings), the three calls this uses. */
2
+ export type WaitEndedSettings = {
3
+ get(key: string): Promise<unknown | undefined>;
4
+ put(key: string, value: unknown): Promise<void>;
5
+ remove(key: string): Promise<void>;
6
+ };
7
+ /** A browser let go while its run waited for its person: when (ISO) and the timeline row's words. */
8
+ export type WaitEnded = {
9
+ at: string;
10
+ why: string;
11
+ };
12
+ /** The run's process, as its wait ends with the browser let go: kept for the Screen tab. */
13
+ export declare function markWaitEnded(settings: WaitEndedSettings, runId: string, ended: WaitEnded, epoch?: number): Promise<void>;
14
+ /** The run's process, as any browser session of the run opens, or at the run's end: nothing ended any more. Given the
15
+ * claim's `epoch`, a message a later claim wrote stays (a follow-up that started on another runner while this claim's
16
+ * loop was still closing keeps its own). */
17
+ export declare function clearWaitEnded(settings: WaitEndedSettings, runId: string, epoch?: number): Promise<void>;
18
+ /** The server's Screen read: for a run that has ended, nothing, and its row goes (a run that ended with no browser after
19
+ * the wait leaves none behind: the runner removes it at the end too, this catches any end that didn't); for a going
20
+ * run, the ended state. */
21
+ export declare function screenWaitEnded(settings: WaitEndedSettings, runId: string, terminal: boolean): Promise<WaitEnded | undefined>;
22
+ /** The ended state, or undefined. One settings read; a value of another shape is no ended state. */
23
+ export declare function readWaitEnded(settings: Pick<WaitEndedSettings, "get">, runId: string): Promise<WaitEnded | undefined>;
@@ -0,0 +1,42 @@
1
+ // Why a run's browser is not up while the run is still going, for GET /v2/runs/{run_id}/computer's `none`: the browser
2
+ // was let go while the run waited for its person (browser-person.ts personHands.wait ends with a timeline row saying so),
3
+ // and the run has opened none since. The Screen tab says that, with when, instead of waiting for a browser nobody is
4
+ // opening.
5
+ //
6
+ // One small server setting per run holds it (`browser_wait_ended:<run id>`: { at, why }), written by the run's process as
7
+ // the wait ends and removed as any browser session of the run opens, whatever let the old one go (its idle release, the
8
+ // tool, a close at the park). So a Screen poll, every few seconds on a parked run, reads one row, never the run's journal.
9
+ const keyOf = (runId) => `browser_wait_ended:${runId}`;
10
+ /** The run's process, as its wait ends with the browser let go: kept for the Screen tab. */
11
+ export async function markWaitEnded(settings, runId, ended, epoch) {
12
+ await settings.put(keyOf(runId), epoch === undefined ? ended : { ...ended, epoch });
13
+ }
14
+ /** The run's process, as any browser session of the run opens, or at the run's end: nothing ended any more. Given the
15
+ * claim's `epoch`, a message a later claim wrote stays (a follow-up that started on another runner while this claim's
16
+ * loop was still closing keeps its own). */
17
+ export async function clearWaitEnded(settings, runId, epoch) {
18
+ if (epoch !== undefined) {
19
+ const written = (await settings.get(keyOf(runId)))?.epoch;
20
+ if (typeof written === "number" && written > epoch)
21
+ return;
22
+ }
23
+ await settings.remove(keyOf(runId));
24
+ }
25
+ /** The server's Screen read: for a run that has ended, nothing, and its row goes (a run that ended with no browser after
26
+ * the wait leaves none behind: the runner removes it at the end too, this catches any end that didn't); for a going
27
+ * run, the ended state. */
28
+ export async function screenWaitEnded(settings, runId, terminal) {
29
+ if (terminal) {
30
+ await settings.remove(keyOf(runId)).catch(() => undefined);
31
+ return undefined;
32
+ }
33
+ return readWaitEnded(settings, runId);
34
+ }
35
+ /** The ended state, or undefined. One settings read; a value of another shape is no ended state. */
36
+ export async function readWaitEnded(settings, runId) {
37
+ const value = await settings.get(keyOf(runId));
38
+ if (!value || typeof value !== "object")
39
+ return undefined;
40
+ const { at, why } = value;
41
+ return typeof at === "string" && typeof why === "string" ? { at, why } : undefined;
42
+ }
package/dist/cap.d.ts CHANGED
@@ -84,7 +84,7 @@ export declare function wrapUpDue(cap: number, spent: number, held: number, typi
84
84
  /** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
85
85
  * typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
86
86
  * the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
87
- * process opened again (costsIn, ownCosts), so a restart picks the same words. */
87
+ * process opened again (ownCosts), so a restart picks the same words. */
88
88
  export declare const wrapUpWords: (leftUsd: number, nonePriced?: boolean) => string;
89
89
  /** A request priced at `price` under `mode`, its input `bound` tokens after `previous` at `now`, plus `feeUsd`: `cost`, what
90
90
  * it is held at given its output tokens (its expected input, never more than uncached), and `worst`, its input uncached.
@@ -167,7 +167,7 @@ export declare const attemptLost: (a: Attempt, last: boolean) => boolean;
167
167
  export declare const anyAttemptLost: (attempts: readonly Attempt[] | undefined) => boolean;
168
168
  export declare function piEnded(message: Pick<AssistantMessage, "stopReason" | "usage" | "api">, began: boolean, attempts: readonly Attempt[] | undefined): Ended;
169
169
  /** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
170
- * request never left, so the entry answers none, and spentIn leaves it out by this. */
170
+ * request never left, so the entry answers none, and spentFrom leaves it out by this. */
171
171
  export declare const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
172
172
  /** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
173
173
  * as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
@@ -194,19 +194,8 @@ export declare const CAP_REFUSAL_PREFIX: RegExp;
194
194
  * before its end), and the usd of a cost written apart from an answer, a paid tool's charge among them; 0 for anything
195
195
  * else, or for a cost that is not a number (which makes the whole spend unknown, by the timeline's verdict). */
196
196
  export declare const costOf: (entry: EntryLike) => number;
197
- /** What the run's store says its model requests cost, across every conversation in it: known or not as the run's own
198
- * timeline says (pi-durable-agent's timelineOf), read as a settled run, since the process that wrote it is gone, and
199
- * then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
200
- * from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
201
- * one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
202
- * entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
203
- * end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
204
- * holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
205
- * cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
206
- * this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
207
- export declare function spentIn(storeFile: string): number | null;
208
- /** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
209
- * settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
197
+ /** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
198
+ * (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
210
199
  * own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
211
200
  * counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
212
201
  * figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
@@ -219,7 +208,7 @@ export declare const DECISION_COST = "agentrun.decision_cost";
219
208
  /** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
220
209
  * while it was out, and it counts at this figure. */
221
210
  export declare const DECISION_HOLD = "agentrun.decision_hold";
222
- /** What a workflow run's decisions cost, in its store: what the next process adds to spentIn's reading. Per decision
211
+ /** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
223
212
  * (its id):
224
213
  * - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
225
214
  * with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
@@ -229,12 +218,6 @@ export declare const DECISION_HOLD = "agentrun.decision_hold";
229
218
  * - else nothing: no hold is kept before the admission, so a request never sent is never counted.
230
219
  * A booking with no decision id is counted as it is. */
231
220
  export declare function decisionSpentIn(storeFile: string): number;
232
- /** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
233
- * processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
234
- export declare function costsIn(storeFile: string, model: string): number[];
235
- /** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
236
- * processes; a raise's new cap re-arms it. */
237
- export declare function wrapUpSentIn(storeFile: string, cap: number): boolean;
238
221
  /** /usage's meters for a run that ended, from its store: `tools`, each TOOL_COST's `usd`, unknown (null) when one is,
239
222
  * or when a call was cut (marked, never settled: what it charged no one knows); and `tokens`, the rest of its root
240
223
  * conversation as its settled timeline prices it; `browser`, the part of `tools` that is browser session time
@@ -250,17 +233,6 @@ export type Meters = {
250
233
  others: number | null;
251
234
  notMetered?: number;
252
235
  };
253
- export declare function metersIn(storeFile: string): Meters;
254
- /** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
255
- * its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
256
- * unknown cost is known to have spent on each (server.ts /usage). */
257
- export declare function meterFiguresIn(storeFile: string): Meters & {
258
- known: {
259
- tokens: number;
260
- browser: number;
261
- others: number;
262
- };
263
- };
264
236
  /** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
265
237
  * browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
266
238
  * it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
@@ -268,10 +240,10 @@ export declare function meterFiguresIn(storeFile: string): Meters & {
268
240
  * as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
269
241
  * browser_time meter's (meterFiguresFrom). */
270
242
  export declare const BROWSER_CHARGED = "agentrun.browser_charged";
271
- /** meterFiguresIn's figures from a run's entries by conversation, in log order: the one computation, shared by
272
- * meterFiguresIn (reading a settled run's own database) and the one-store reader (store-reads/cap.ts metersOverStore, over
273
- * A's journal). Only where the entries come from changes; the figures do not (the money-parity rule), as spentFrom is to
274
- * spentIn. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
243
+ /** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
244
+ * its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
245
+ * no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
246
+ * runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
275
247
  * paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
276
248
  export declare function meterFiguresFrom(rows: readonly {
277
249
  conversation: number;
@@ -284,7 +256,7 @@ export declare function meterFiguresFrom(rows: readonly {
284
256
  };
285
257
  };
286
258
  /** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
287
- * settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentIn counts it;
259
+ * settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
288
260
  * null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
289
261
  export declare function capToolSpend(entries: readonly EntryLike[]): number | null;
290
262
  /** The worst case of each model request a cap admitted and whose cost is not booked yet, by its turn, for a paid tool's
@@ -387,13 +359,16 @@ export declare function holdPaid(name: string, hold: {
387
359
  * raise a request's ceiling up to the model's, whatever maxTokens it asked for. */
388
360
  export declare const ceilingTokens: (model: Pick<Model<Api>, "maxTokens" | "contextWindow">) => number;
389
361
  /** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
390
- * fewer than one byte a token, and an image's base64 is far more bytes than its tokens), plus `overhead`, what the
391
- * provider adds server-side that the body does not hold. The same bound on every harness. */
362
+ * fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
363
+ * each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
364
+ * bound on every harness. */
392
365
  export declare const inputBound: (sent: string, overhead?: number) => number;
393
366
  /** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
394
367
  * kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
395
368
  * so the dearer choice is taken. */
396
- export declare function piOverhead(model: Pick<Model<Api>, "api">, context: Context): number | undefined;
369
+ export declare function piOverhead(model: Pick<Model<Api>, "api"> & {
370
+ id?: string;
371
+ }, context: Context): number | undefined;
397
372
  /** An amount in words: two decimals, or as many as it takes (up to eight) to show it whole ($0.50, $0.105, $0.0005). */
398
373
  export declare function money(usd: number): string;
399
374
  /** The code a cap's refusal begins with: `spend_cap_reached`, which the server ends the run with, and "out of budget",
@@ -500,8 +475,8 @@ export declare function requestParts(overhead?: (model: Model<Api>, context: Con
500
475
  feeUsd: number;
501
476
  } | undefined;
502
477
  /** The wrap-up on pi (capModels' `wrapUp`): the run's own model (`model`, its id), that model's priced requests so far
503
- * (`costs`, earlier processes' from the store, costsIn; capModels adds each one it books), whether it was told under this
504
- * cap already (`sent`, wrapUpSentIn), and `record`, which writes its row (request-start.ts, CAP_WRAPUP). */
478
+ * (`costs`; capModels adds each one it books), whether it was told under this
479
+ * cap already (`sent`), and `record`, which writes its row (request-start.ts, CAP_WRAPUP). */
505
480
  /** The wrap-up's state on pi. `sent`: told, in an answered request, once per cap. `pending`: a request carries the note
506
481
  * and has not ended: no other request takes it until that one is answered (told) or not (re-armed). */
507
482
  export type WrapUp = {
@@ -521,7 +496,7 @@ export type WrapUp = {
521
496
  * and, under the cap,
522
497
  * each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
523
498
  * ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
524
- * (spentIn), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
499
+ * (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
525
500
  * `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
526
501
  * priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
527
502
  * by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
package/dist/cap.js CHANGED
@@ -30,7 +30,7 @@
30
30
  // timeline (runs.ts withOverCap).
31
31
  //
32
32
  // A paid tool's charge (monid.run's, monid.ts) is the run's spend too: booked in the run's store as a TOOL_COST, which
33
- // the run's cost and spentIn both count, and added to what the run's process counts as spent (useSpend), so the next
33
+ // the run's cost and spentFrom both count, and added to what the run's process counts as spent (useSpend), so the next
34
34
  // request's check sees it. A charge the call does not say (null: stopped, timed out, failed with no cost) leaves the
35
35
  // run's cost unknown, and the cap counts the call at what it was held at, the bound it let the call go at, as it counts
36
36
  // one a crash cut: in the run's process and from its mark in the store. Before each paid call, paidCall holds it as a
@@ -45,12 +45,12 @@
45
45
  // (RunSpend.wait, budget.ts): a model node's request before it is sent, a call node's call and a decision before they are
46
46
  // admitted again. A refusal inside a call node's effect is told to the call (capRefusals), never only to the model.
47
47
  import { readRunDbSync } from "./run-db.js";
48
- import { durableDecisions } from "@parcha/agentrun-pi/durable";
48
+ import { durableDecisions } from "./workflow/readers.js";
49
49
  import { AsyncLocalStorage } from "node:async_hooks";
50
50
  import { existsSync } from "node:fs";
51
- import { providerInputOverhead } from "@parcha/agentrun-kernel/host";
51
+ import { imageInputOf, providerInputOverhead } from "@parcha/agentrun-kernel/host";
52
52
  import { bookRequest, isConnectCode, isGatewayTimeout, rejectionCode } from "@parcha/agentrun-kernel";
53
- import { CAP_WRAPUP, REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
53
+ import { REQUEST_CONTINUED, REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_REFUSED, REQUEST_STARTED, timelineOf, TOOL_COST, TOOL_STARTED } from "./timeline/index.js";
54
54
  /** How a request the cap refused begins its error, which the server ends the run with. */
55
55
  export const SPEND_CAP_REACHED = "spend_cap_reached";
56
56
  /** How near two dollar figures are the same figure: a sum a float puts a hair past the cap (0.0028 + 0.3072 is
@@ -139,7 +139,7 @@ export function wrapUpDue(cap, spent, held, typical, leastUsd) {
139
139
  /** The wrap-up's words, what is left to the cent. `nonePriced`: the run's own model has no priced request yet, so its
140
140
  * typical cost is the next request's expected cost and the note can come before the run has done anything (step 0):
141
141
  * the words say the budget and ask for a short answer, not a finish. Read from the same priced costs live and in a
142
- * process opened again (costsIn, ownCosts), so a restart picks the same words. */
142
+ * process opened again (ownCosts), so a restart picks the same words. */
143
143
  export const wrapUpWords = (leftUsd, nonePriced = false) => {
144
144
  const left = centsMoney(Math.max(0, leftUsd));
145
145
  return nonePriced ? `This run's budget is about ${left}, enough for little work: answer as soon as you can.` : `About ${left} left of this run's budget: finish now with your answer.`;
@@ -286,7 +286,7 @@ export function piEnded(message, began, attempts) {
286
286
  return { end: "nothing", label: last === undefined || "code" in last ? "never_left" : "status" };
287
287
  }
288
288
  /** How pi's error for a request whose start mark could not be written begins (request-start.ts builds it from this): the
289
- * request never left, so the entry answers none, and spentIn leaves it out by this. */
289
+ * request never left, so the entry answers none, and spentFrom leaves it out by this. */
290
290
  export const MARK_NOT_WRITTEN = "the model request was not sent: its mark could not be written";
291
291
  /** pi's error for a request that left and whose end mark the store refused (request-start.ts): its cost is not recorded
292
292
  * as booked, so it stays open, read at its start mark's hold, never closed by this entry at its own usage. */
@@ -337,7 +337,7 @@ const close = (open, figure) => {
337
337
  open.splice(at, 1);
338
338
  };
339
339
  /** The figures of the requests of each kind that `entries` leave open, marked as sent with no answer, cost or end, read in
340
- * order, as the run's timeline counts them (pi-durable-agent's meter), so the two agree on how many were cut. A start adds
340
+ * order, as the run's timeline counts them, so the two agree on how many were cut. A start adds
341
341
  * its figure. An end mark closes its own start: a stopped request's at the figure it names, a withdrawn one's (`unsent`,
342
342
  * which names none) the smallest. An end that names none for a request that left (an older store) closes nothing, so
343
343
  * that request stays cut. An answer, or a summary's cost, closes the smallest figure still open, since when requests
@@ -376,33 +376,8 @@ function openFigures(entries) {
376
376
  }
377
377
  return open;
378
378
  }
379
- /** What the run's store says its model requests cost, across every conversation in it: known or not as the run's own
380
- * timeline says (pi-durable-agent's timelineOf), read as a settled run, since the process that wrote it is gone, and
381
- * then the full amount, never the timeline's total rounded for display. Every response, and each cost written apart
382
- * from one (a compaction summary's; a harness request's that came in after its answer). A cost that is not a number, or
383
- * one still pending, leaves it unknown, as the timeline says. These readings are the cap's own, on its copy of the
384
- * entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end counts at the figure its
385
- * end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the figure its start mark
386
- * holds (openFigures), each the worst case the cap held for it; without that figure either stays cut, at an unknown
387
- * cost. A paid call settled at a charge it did not say, like one a crash cut, counts at the figure its mark holds. And
388
- * this cap's refusals are left out, as none left. Unknown is null, which a cap never reads as $0. */
389
- export function spentIn(storeFile) {
390
- if (!existsSync(storeFile))
391
- return 0;
392
- // Fresh, read-only and lock-free (run-db.ts): its process may hold it.
393
- const rows = [];
394
- readRunDbSync(storeFile, false, (db) => {
395
- // A read made again (its file changed during it) starts from none.
396
- rows.length = 0;
397
- for (const row of db.prepare("SELECT record FROM entries ORDER BY rowid").iterate()) {
398
- const entry = JSON.parse(String(row.record));
399
- rows.push(entry);
400
- }
401
- });
402
- return spentFrom(rows);
403
- }
404
- /** What the run's model requests cost, from its entries in log order: the one computation, shared by spentIn (reading a
405
- * settled run's own database) and the one-store reader (store-reads, reading A's journal). These readings are the cap's
379
+ /** What the run's model requests cost, from its entries in log order: the one computation, which the one-store reader
380
+ * (store-reads/cap.ts spentOverStore) runs over A's journal. These readings are the cap's
406
381
  * own, on its copy of the entries (the run's shown cost is the timeline's, unchanged): a request stopped before its end
407
382
  * counts at the figure its end mark holds (HELD_FIELD), and one a crash cut (marked as sent, no answer, no end) at the
408
383
  * figure its start mark holds (openFigures), each the worst case the cap held for it; without that figure either stays
@@ -546,7 +521,7 @@ export const DECISION_COST = "agentrun.decision_cost";
546
521
  /** A decision request's hold, kept before it is sent (decision-cap.ts): with no DECISION_COST after it, its process died
547
522
  * while it was out, and it counts at this figure. */
548
523
  export const DECISION_HOLD = "agentrun.decision_hold";
549
- /** What a workflow run's decisions cost, in its store: what the next process adds to spentIn's reading. Per decision
524
+ /** What a workflow run's decisions cost, in its store: what the next process adds to spentFrom's reading. Per decision
550
525
  * (its id):
551
526
  * - booked (DECISION_COST entries, at its charge, its hold, or $0 for nothing charged): the larger of what was booked,
552
527
  * with any hold no booking ended, and what its receipts say it cost (the costs the timeline's decision rows sum);
@@ -597,7 +572,7 @@ export function decisionSpentIn(storeFile) {
597
572
  }
598
573
  for (const receipt of receipts) {
599
574
  const usd = figureOf(receipt.cost_usd);
600
- // A stored receipt row names its decision `decision_id` (agentrun-pi decision-recovery.ts rowOf).
575
+ // A stored receipt row names its decision `decision_id` (workflow/decision-recovery.ts rowOf).
601
576
  const id = typeof receipt.decision_id === "string" ? receipt.decision_id : typeof receipt.id === "string" ? receipt.id : undefined;
602
577
  if (id !== undefined && usd !== undefined && usd > 0)
603
578
  receipted.set(id, (receipted.get(id) ?? 0) + usd);
@@ -618,7 +593,7 @@ export function decisionSpentIn(storeFile) {
618
593
  function entriesIn(storeFile) {
619
594
  if (!existsSync(storeFile))
620
595
  return [];
621
- // Fresh, read-only and lock-free (run-db.ts), as spentIn reads it.
596
+ // Fresh, read-only and lock-free (run-db.ts), as the cap's readings did.
622
597
  const rows = [];
623
598
  readRunDbSync(storeFile, false, (db) => {
624
599
  rows.length = 0;
@@ -627,32 +602,6 @@ function entriesIn(storeFile) {
627
602
  });
628
603
  return rows;
629
604
  }
630
- /** The priced answers of `model` (its id) in the run's store, in order: what the wrap-up's typical cost reads from earlier
631
- * processes (capModels' `wrapUp`). An answer whose cost is unknown or $0, or that was stopped or failed, is none. */
632
- export function costsIn(storeFile, model) {
633
- return entriesIn(storeFile).flatMap((entry) => {
634
- const message = entry.kind === "pi.assistant" ? entry.model?.[0] : undefined;
635
- const total = message?.usage?.cost?.total;
636
- return message?.model === model && message.stopReason !== "error" && message.stopReason !== "aborted" && typeof total === "number" && Number.isFinite(total) && total > 0 ? [total] : [];
637
- });
638
- }
639
- /** Whether the run was told its wrap-up under `cap` already (a CAP_WRAPUP entry of that cap): once per cap, across its
640
- * processes; a raise's new cap re-arms it. */
641
- export function wrapUpSentIn(storeFile, cap) {
642
- return entriesIn(storeFile).some((entry) => entry.kind === CAP_WRAPUP && typeof entry.data?.capUsd === "number" && Math.abs(entry.data.capUsd - cap) <= CAP_TOLERANCE);
643
- }
644
- export function metersIn(storeFile) {
645
- const { known: _, ...meters } = meterFiguresIn(storeFile);
646
- return meters;
647
- }
648
- /** metersIn's meters, and beside them each meter's known dollars: its settled charges' figures, whether or not another of
649
- * its charges is unknown (a hold, a call cut or never settled, is no charge here: it adds nothing). What a run of
650
- * unknown cost is known to have spent on each (server.ts /usage). */
651
- export function meterFiguresIn(storeFile) {
652
- if (!existsSync(storeFile))
653
- return { tools: 0, tokens: null, browser: { usd: 0, seconds: 0 }, others: 0, known: { tokens: 0, browser: 0, others: 0 } };
654
- return readRunDbSync(storeFile, false, (db) => meterFiguresFrom(db.prepare("SELECT conversation_id AS conversation, record FROM entries ORDER BY rowid").all().map((row) => ({ conversation: Number(row.conversation), entry: JSON.parse(String(row.record)) }))));
655
- }
656
605
  /** A browser charge's record on the run's root when the run books its money on the runner's one ledger (browser-cost.ts
657
606
  * browserSpend's `paid`): the same record a browser TOOL_COST is, for what the browser's process holds and the seconds
658
607
  * it was for, under a kind no cost reads. The charge's money is the ledger's paid step alone, which the cap counts and
@@ -660,10 +609,10 @@ export function meterFiguresIn(storeFile) {
660
609
  * as every paid tool's on the runner: a TOOL_COST beside it would count the same charge twice. Its seconds are the
661
610
  * browser_time meter's (meterFiguresFrom). */
662
611
  export const BROWSER_CHARGED = "agentrun.browser_charged";
663
- /** meterFiguresIn's figures from a run's entries by conversation, in log order: the one computation, shared by
664
- * meterFiguresIn (reading a settled run's own database) and the one-store reader (store-reads/cap.ts metersOverStore, over
665
- * A's journal). Only where the entries come from changes; the figures do not (the money-parity rule), as spentFrom is to
666
- * spentIn. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
612
+ /** /usage's meter figures from a run's entries by conversation, in log order, and beside them each meter's known dollars:
613
+ * its settled charges' figures, whether or not another of its charges is unknown (a hold, a call cut or never settled, is
614
+ * no charge here: it adds nothing). The one computation, which the one-store reader (store-reads/cap.ts metersOverStore)
615
+ * runs over A's journal. A paid tool's charge reaches it as the TOOL_COST / TOOL_UNMETERED the store reader folds back in from the
667
616
  * paid-tools session (store-reads/journal.ts withPaidCosts), as the file-backed run's root held each natively. */
668
617
  export function meterFiguresFrom(rows) {
669
618
  const root = rows.reduce((min, row) => Math.min(min, row.conversation), Infinity);
@@ -702,7 +651,7 @@ export function meterFiguresFrom(rows) {
702
651
  return { tools, tokens: usage ? (usage.usage?.usd ?? null) : 0, browser, others: otherTools, known, ...(notMetered ? { notMetered } : {}) };
703
652
  }
704
653
  /** What the paid tools of `entries` (TOOL_STARTED and TOOL_COST) spent, as the cap counts it: each charge, and a call
705
- * settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentIn counts it;
654
+ * settled at a charge it did not say, or a crash cut (marked, never settled), at its held figure, as spentFrom counts it;
706
655
  * null when one has no figure. The run's reported cost reads such a call unknown instead (the timeline). */
707
656
  export function capToolSpend(entries) {
708
657
  const open = new Map();
@@ -766,7 +715,7 @@ export const runCap = () => runSpend?.cap;
766
715
  * quote, else an allowance, `basis` saying which) fits the cap, and whenever the spend is unknown; else run, one paid
767
716
  * call at a time, so each check sees the charge before it, and held at that figure (paidHolds) until the charge it
768
717
  * reports (`charge` of its result, undefined for none) joins the spend. A charge it does not say (null), or a call that
769
- * fails, counts at its held figure, as its mark does from the store (spentIn), since it may have charged that much.
718
+ * fails, counts at its held figure, as its mark does from the store (spentFrom), since it may have charged that much.
770
719
  * With no cap it just runs. */
771
720
  /** A paid call this run's cap refused for room (paidCall): its words, after the code, and its figures as a model
772
721
  * request's refusal keeps them (what was taken, and the call's hold as what it needs). The model's next request is
@@ -879,15 +828,18 @@ function outputBound(model) {
879
828
  return [model.cost, ...(model.cost?.tiers ?? [])].every((rates) => rates?.output === 0) ? 0 : undefined;
880
829
  }
881
830
  /** A request's input tokens, bounded above: one per UTF-8 byte of what is sent (a byte-level tokenizer never takes
882
- * fewer than one byte a token, and an image's base64 is far more bytes than its tokens), plus `overhead`, what the
883
- * provider adds server-side that the body does not hold. The same bound on every harness. */
831
+ * fewer than one byte a token), plus `overhead`: what the provider adds server-side that the body does not hold, and
832
+ * each image at what it is billed as in place of its base64's bytes (below 0 for a large image: piOverhead). The same
833
+ * bound on every harness. */
884
834
  export const inputBound = (sent, overhead = 0) => Buffer.byteLength(sent, "utf8") + overhead;
885
835
  /** What pi's provider adds server-side to a request of `context`, the same table the model proxy uses, by the model's API
886
836
  * kind: undefined for a kind whose additions are not known. The context does not say how the request chooses a tool,
887
837
  * so the dearer choice is taken. */
888
838
  export function piOverhead(model, context) {
889
839
  const parts = (context.messages ?? []).flatMap((message) => (Array.isArray(message.content) ? (message.content) : []));
890
- return providerInputOverhead(model.api, { tools: (context.tools?.length ?? 0) > 0, toolChoice: "any", images: parts.filter((part) => part?.type === "image").length });
840
+ // Each image, in every turn, at what the model's provider bills it as by its size, in place of its base64's bytes in
841
+ // what is sent (imageInputOf, imageTokens).
842
+ return providerInputOverhead(model.api, { tools: (context.tools?.length ?? 0) > 0, toolChoice: "any", images: parts.filter((part) => part?.type === "image").map((part) => imageInputOf(part.data)), ...(model.id ? { model: model.id } : {}) });
891
843
  }
892
844
  const unmeasured = (cap) => `${SPEND_CAP_REACHED}: Not sent: the size of the next model request's input is unknown, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
893
845
  const noPrice = (cap) => `${SPEND_CAP_REACHED}: Not sent: the next model request's model has no price here, so the run's cap of ${money(cap)} cannot be kept: the run is out of budget.`;
@@ -952,7 +904,9 @@ const whyOf = ({ text, figures }) => ({ why: text, figures });
952
904
  * (RefusalFigures, the pause's spent_usd). */
953
905
  const spentOf = (spent, held, cap) => {
954
906
  const holds = centsMoney(held);
955
- return holds !== "$0" ? `spent ${centsMoney(spent)} and holds ${holds} for steps still running, of its ${money(cap)} cap` : `spent ${centsMoney(spent)} of its ${money(cap)} cap`;
907
+ // A spend above $0 that rounds to it reads "less than a cent", never "$0" (the kernel's spentMoney).
908
+ const spentWords = spent > 0 && centsMoney(spent) === "$0" ? "less than a cent" : centsMoney(spent);
909
+ return holds !== "$0" ? `spent ${spentWords} and holds ${holds} for steps still running, of its ${money(cap)} cap` : `spent ${spentWords} of its ${money(cap)} cap`;
956
910
  };
957
911
  /** An amount in words, to the nearest cent ($0.0237416 is $0.02), as money says it ($1, $0.20, $0). */
958
912
  export const centsMoney = (usd) => money(Math.round(usd * 100) / 100);
@@ -1075,7 +1029,7 @@ export function requestParts(overhead = piOverhead) {
1075
1029
  * and, under the cap,
1076
1030
  * each request to a model in `unpriced` (one serve has no price for) or whose output is priced and that has no output
1077
1031
  * ceiling, each whose input cannot be bounded, and every request once what the run has spent is unknown: `spent` null
1078
- * (spentIn), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
1032
+ * (spentFrom), or an answer since whose cost is unknown. A request's input is inputBound of its context, plus
1079
1033
  * `overhead(model, context)` (piOverhead), what its provider adds server-side; undefined is unmeasured, never 0. It is
1080
1034
  * priced by requestPrice under `mode`, after the previous request of its conversation (the context's last answer, read
1081
1035
  * by previousIn; its end as `now` read it when it settled here, else its own timestamp, which is when it began). Each
@@ -1248,7 +1202,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
1248
1202
  * of what it streamed (stoppedFigure, at most `worst`), unless an attempt before the stop was lost: then at `worst`, as
1249
1203
  * its lost mark reads in a later process; one that ended on an error after its response began
1250
1204
  * (markResponseBegan: its usage is what had streamed, not what the provider can have billed), or that failed with no
1251
- * answer, at `worst`, what the cap held for it; each as spentIn reads its end mark. Without a figure (a deferred
1205
+ * answer, at `worst`, what the cap held for it; each as spentFrom reads its end mark. Without a figure (a deferred
1252
1206
  * response) it is unknown, as is a cost that is not a number, from then on. */
1253
1207
  const count = (answer, turn, worst, stopped, attempts) => {
1254
1208
  const plus = (sum, cost) => (sum !== null && typeof cost === "number" && Number.isFinite(cost) ? sum + cost : null);
@@ -1256,7 +1210,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
1256
1210
  // One rule (bookRequest), from how the request ended (piEnded) as its marks read it too.
1257
1211
  const at = (message) => message.stopReason === "aborted" ? (stopped && !anyAttemptLost(attempts) ? stopped(message) : worst)
1258
1212
  : bookRequest(piEnded(message, responseBegan.has(message), attempts), worst === undefined ? {} : { hold: worst }).usd;
1259
- // A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as costsIn reads it again (its
1213
+ // A priced turn answer of the run's own model: the wrap-up's typical cost counts it, as a process opened again reads it (its
1260
1214
  // pi.assistant entries). Never a compaction summary's or a native search's request on the same model (completeSimple
1261
1215
  // calls, `turn` false): no pi.assistant entry keeps them, so a process opened again would count without them.
1262
1216
  const priced = (message) => {
@@ -1339,7 +1293,7 @@ export async function capModels(models, cap, spent, { unpriced = new Set(), over
1339
1293
  const refused = createAssistantMessageEventStream();
1340
1294
  const message = refusal(model, judged.why);
1341
1295
  // Its own start mark first, so pi's error entry for it answers that mark, never an earlier request a stop or a crash
1342
- // cut. A mark that cannot be written still ends the request: spentIn leaves refusals out either way.
1296
+ // cut. A mark that cannot be written still ends the request: spentFrom leaves refusals out either way.
1343
1297
  void Promise.resolve()
1344
1298
  .then(() => markRefused?.(judged.figures))
1345
1299
  .catch(() => undefined)