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

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 (466) hide show
  1. package/CHANGELOG.md +368 -0
  2. package/README.md +341 -208
  3. package/dist/adapters.d.ts +3 -4
  4. package/dist/adapters.js +18 -15
  5. package/dist/agent-rows.d.ts +99 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +75 -25
  9. package/dist/agents.d.ts +9 -125
  10. package/dist/agents.js +15 -305
  11. package/dist/answer-json.d.ts +23 -0
  12. package/dist/answer-json.js +58 -0
  13. package/dist/api-only.d.ts +1 -1
  14. package/dist/api-only.js +2 -2
  15. package/dist/archil-settings.d.ts +11 -1
  16. package/dist/archil-settings.js +10 -0
  17. package/dist/bash-read-only.d.ts +35 -0
  18. package/dist/bash-read-only.js +778 -0
  19. package/dist/box-settings.d.ts +3 -23
  20. package/dist/box-settings.js +7 -51
  21. package/dist/boxes.d.ts +17 -0
  22. package/dist/boxes.js +27 -20
  23. package/dist/browser-commands.d.ts +5 -2
  24. package/dist/browser-commands.js +4 -4
  25. package/dist/browser-computer.d.ts +5 -0
  26. package/dist/browser-computer.js +21 -0
  27. package/dist/browser-cost.d.ts +9 -6
  28. package/dist/browser-cost.js +95 -51
  29. package/dist/browser-live.d.ts +7 -20
  30. package/dist/browser-live.js +15 -93
  31. package/dist/browser-person.d.ts +18 -51
  32. package/dist/browser-person.js +94 -277
  33. package/dist/budget.d.ts +0 -5
  34. package/dist/budget.js +0 -5
  35. package/dist/cap.d.ts +14 -8
  36. package/dist/cap.js +19 -9
  37. package/dist/cli.js +71 -18
  38. package/dist/closed-pipes.d.ts +2 -0
  39. package/dist/closed-pipes.js +13 -0
  40. package/dist/computer-commands.d.ts +2 -0
  41. package/dist/computer-commands.js +2 -0
  42. package/dist/computer-keys.d.ts +20 -10
  43. package/dist/computer-keys.js +36 -54
  44. package/dist/computer-setting.d.ts +20 -3
  45. package/dist/computer-setting.js +58 -10
  46. package/dist/computers.d.ts +35 -2
  47. package/dist/computers.js +72 -11
  48. package/dist/confine.d.ts +120 -0
  49. package/dist/confine.js +436 -0
  50. package/dist/console/assets/index-B7NKTU8E.css +1 -0
  51. package/dist/console/assets/index-CXZMgJE7.js +550 -0
  52. package/dist/console/index.html +2 -2
  53. package/dist/content-filter.d.ts +7 -0
  54. package/dist/content-filter.js +23 -0
  55. package/dist/decision-cap.d.ts +7 -29
  56. package/dist/decision-cap.js +3 -94
  57. package/dist/decision-rows.d.ts +1 -1
  58. package/dist/decision-rows.js +1 -1
  59. package/dist/docker-daemon.d.ts +31 -0
  60. package/dist/docker-daemon.js +56 -0
  61. package/dist/effort-guidance.js +4 -3
  62. package/dist/environment.d.ts +0 -3
  63. package/dist/environment.js +3 -5
  64. package/dist/errors.d.ts +1 -2
  65. package/dist/errors.js +9 -9
  66. package/dist/explain.js +3 -1
  67. package/dist/filed-answer.d.ts +32 -0
  68. package/dist/filed-answer.js +160 -0
  69. package/dist/files.d.ts +1 -3
  70. package/dist/files.js +2 -4
  71. package/dist/github-connection.d.ts +1 -1
  72. package/dist/github-connection.js +25 -7
  73. package/dist/github-faux.d.ts +26 -0
  74. package/dist/github-faux.js +76 -0
  75. package/dist/github.d.ts +6 -2
  76. package/dist/github.js +5 -3
  77. package/dist/graph-served.d.ts +5 -3
  78. package/dist/graph-served.js +14 -6
  79. package/dist/graph-view.d.ts +3 -5
  80. package/dist/graph-view.js +9 -16
  81. package/dist/handed-values.d.ts +9 -0
  82. package/dist/handed-values.js +26 -0
  83. package/dist/harness-install.d.ts +1 -7
  84. package/dist/harness-install.js +1 -18
  85. package/dist/harness-opencode/adapter.d.ts +7 -0
  86. package/dist/harness-opencode/adapter.js +23 -6
  87. package/dist/harness-opencode/harness.js +0 -1
  88. package/dist/harness-opencode/host/policy.js +2 -2
  89. package/dist/harness-opencode/index.d.ts +1 -1
  90. package/dist/harness-opencode/index.js +1 -1
  91. package/dist/harness-opencode/verify.d.ts +17 -0
  92. package/dist/harness-opencode/verify.js +30 -10
  93. package/dist/harness-table.js +6 -1
  94. package/dist/heard.js +1 -1
  95. package/dist/held-fd.d.ts +5 -0
  96. package/dist/held-fd.js +14 -0
  97. package/dist/host-calls.d.ts +20 -0
  98. package/dist/host-calls.js +12 -0
  99. package/dist/host-tools.d.ts +4 -21
  100. package/dist/host-tools.js +4 -61
  101. package/dist/host.d.ts +2 -4
  102. package/dist/host.js +2 -7
  103. package/dist/import-summary.d.ts +1 -5
  104. package/dist/import-summary.js +0 -21
  105. package/dist/import.d.ts +6 -6
  106. package/dist/import.js +14 -15
  107. package/dist/index.d.ts +1 -0
  108. package/dist/index.js +1 -0
  109. package/dist/key-refusal.d.ts +5 -1
  110. package/dist/key-refusal.js +19 -4
  111. package/dist/learn/check.d.ts +8 -2
  112. package/dist/learn/check.js +85 -31
  113. package/dist/learn/folder.d.ts +11 -4
  114. package/dist/learn/folder.js +17 -19
  115. package/dist/learn/grade.d.ts +18 -1
  116. package/dist/learn/grade.js +108 -14
  117. package/dist/learn/index.d.ts +5 -5
  118. package/dist/learn/index.js +5 -5
  119. package/dist/learn/learning.sh +1 -14
  120. package/dist/learn/notes.d.ts +14 -3
  121. package/dist/learn/notes.js +16 -6
  122. package/dist/learn/reflect.d.ts +31 -2
  123. package/dist/learn/reflect.js +83 -6
  124. package/dist/learn/relevance.d.ts +24 -0
  125. package/dist/learn/relevance.js +91 -0
  126. package/dist/learn/secrets.d.ts +7 -1
  127. package/dist/learn/secrets.js +86 -19
  128. package/dist/learn/skills.d.ts +159 -18
  129. package/dist/learn/skills.js +644 -64
  130. package/dist/learned-nodes.d.ts +14 -0
  131. package/dist/learned-nodes.js +8 -0
  132. package/dist/learned-workflow.d.ts +41 -6
  133. package/dist/learned-workflow.js +153 -18
  134. package/dist/learning-routes.d.ts +49 -4
  135. package/dist/learning-routes.js +113 -31
  136. package/dist/learning-run.d.ts +16 -31
  137. package/dist/learning-run.js +31 -38
  138. package/dist/learning-words.d.ts +12 -5
  139. package/dist/learning-words.js +18 -9
  140. package/dist/learning.d.ts +91 -97
  141. package/dist/learning.js +176 -320
  142. package/dist/live/stream.js +1 -1
  143. package/dist/live/translate.js +12 -2
  144. package/dist/llm.d.ts +4 -1
  145. package/dist/llm.js +4 -2
  146. package/dist/local-models.d.ts +11 -5
  147. package/dist/local-models.js +13 -8
  148. package/dist/mcp-gateway.d.ts +17 -49
  149. package/dist/mcp-gateway.js +55 -136
  150. package/dist/mcp-oauth.d.ts +10 -14
  151. package/dist/mcp-oauth.js +14 -32
  152. package/dist/mcp-probe.d.ts +0 -7
  153. package/dist/mcp-probe.js +4 -10
  154. package/dist/mcp-servers-store.d.ts +18 -18
  155. package/dist/mcp-servers-store.js +12 -14
  156. package/dist/mcp-store.js +3 -4
  157. package/dist/mcp.js +4 -3
  158. package/dist/model.d.ts +9 -7
  159. package/dist/model.js +51 -27
  160. package/dist/monid.d.ts +0 -2
  161. package/dist/monid.js +3 -6
  162. package/dist/openapi.d.ts +8 -1
  163. package/dist/openapi.js +156 -58
  164. package/dist/page.d.ts +1 -3
  165. package/dist/page.js +6 -18
  166. package/dist/paid-calls.d.ts +21 -27
  167. package/dist/paid-calls.js +26 -61
  168. package/dist/pause.d.ts +2 -19
  169. package/dist/pause.js +5 -74
  170. package/dist/port-models.d.ts +10 -3
  171. package/dist/port-models.js +26 -6
  172. package/dist/propose.d.ts +2 -0
  173. package/dist/propose.js +80 -45
  174. package/dist/push-handler.d.ts +1 -1
  175. package/dist/reflect-range.d.ts +25 -0
  176. package/dist/reflect-range.js +30 -0
  177. package/dist/refusal-words.d.ts +5 -1
  178. package/dist/refusal-words.js +5 -1
  179. package/dist/rows.d.ts +1 -1
  180. package/dist/run-cut.d.ts +0 -6
  181. package/dist/run-cut.js +0 -6
  182. package/dist/run-db.d.ts +2 -11
  183. package/dist/run-db.js +2 -37
  184. package/dist/run-launch.d.ts +21 -2
  185. package/dist/run-launch.js +14 -5
  186. package/dist/run-learning-served.d.ts +21 -4
  187. package/dist/run-learning-served.js +23 -13
  188. package/dist/run-reads-over-store.d.ts +5 -3
  189. package/dist/run-reads-over-store.js +25 -14
  190. package/dist/run-secrets.d.ts +1 -1
  191. package/dist/run-timeline-served.d.ts +5 -1
  192. package/dist/run-timeline-served.js +27 -6
  193. package/dist/run-view.d.ts +37 -22
  194. package/dist/run-view.js +85 -38
  195. package/dist/runnable.d.ts +21 -10
  196. package/dist/runnable.js +35 -12
  197. package/dist/runner/adapter-loop.d.ts +36 -5
  198. package/dist/runner/adapter-loop.js +663 -69
  199. package/dist/runner/adapter-run-spec.d.ts +42 -8
  200. package/dist/runner/adapter-run-spec.js +186 -52
  201. package/dist/runner/adapters/index.js +11 -1
  202. package/dist/runner/adapters/pi.d.ts +40 -2
  203. package/dist/runner/adapters/pi.js +110 -27
  204. package/dist/runner/beside.d.ts +38 -3
  205. package/dist/runner/beside.js +54 -5
  206. package/dist/runner/claim-secrets.d.ts +16 -1
  207. package/dist/runner/claim-secrets.js +62 -14
  208. package/dist/runner/cli-run-spec.d.ts +5 -0
  209. package/dist/runner/cli-run-spec.js +159 -41
  210. package/dist/runner/commands.js +1 -1
  211. package/dist/runner/computer-journal.d.ts +15 -2
  212. package/dist/runner/computer-journal.js +41 -5
  213. package/dist/runner/conformance/harness.d.ts +1 -0
  214. package/dist/runner/conformance/harness.js +123 -13
  215. package/dist/runner/conformance/subject.d.ts +4 -1
  216. package/dist/runner/dispatch.d.ts +8 -1
  217. package/dist/runner/dispatch.js +81 -7
  218. package/dist/runner/end-of-run.d.ts +8 -2
  219. package/dist/runner/end-of-run.js +10 -4
  220. package/dist/runner/github-app.d.ts +7 -2
  221. package/dist/runner/github-app.js +47 -16
  222. package/dist/runner/harness-loops.d.ts +15 -2
  223. package/dist/runner/harness-loops.js +38 -2
  224. package/dist/runner/journal-kinds.d.ts +60 -6
  225. package/dist/runner/journal-kinds.js +43 -5
  226. package/dist/runner/journal-reader.d.ts +1 -1
  227. package/dist/runner/journal-reader.js +2 -2
  228. package/dist/runner/learning-ask.d.ts +4 -0
  229. package/dist/runner/learning-ask.js +15 -1
  230. package/dist/runner/learning-end.d.ts +18 -3
  231. package/dist/runner/learning-end.js +194 -20
  232. package/dist/runner/learning-loop.d.ts +7 -0
  233. package/dist/runner/learning-loop.js +36 -8
  234. package/dist/runner/learning-seed.d.ts +6 -0
  235. package/dist/runner/learning-seed.js +6 -0
  236. package/dist/runner/loop-contract.d.ts +4 -0
  237. package/dist/runner/main.d.ts +61 -9
  238. package/dist/runner/main.js +144 -20
  239. package/dist/runner/mcp-claim.d.ts +3 -0
  240. package/dist/runner/mcp-claim.js +7 -3
  241. package/dist/runner/mcp-github.d.ts +11 -2
  242. package/dist/runner/mcp-github.js +55 -4
  243. package/dist/runner/mcp-run.d.ts +2 -0
  244. package/dist/runner/mcp-run.js +16 -5
  245. package/dist/runner/memory-claim.d.ts +9 -0
  246. package/dist/runner/memory-claim.js +25 -0
  247. package/dist/runner/metrics.d.ts +46 -1
  248. package/dist/runner/metrics.js +156 -1
  249. package/dist/runner/model-route.d.ts +16 -0
  250. package/dist/runner/model-route.js +134 -10
  251. package/dist/runner/reflect-hook.d.ts +12 -1
  252. package/dist/runner/reflect-hook.js +33 -3
  253. package/dist/runner/runner.d.ts +20 -0
  254. package/dist/runner/runner.js +146 -18
  255. package/dist/runner/spec-holds.d.ts +7 -2
  256. package/dist/runner/spec-holds.js +4 -3
  257. package/dist/runner/store-port.d.ts +1 -1
  258. package/dist/runner/store-secrets.d.ts +3 -3
  259. package/dist/runner/store-secrets.js +8 -12
  260. package/dist/runner/text-tools.d.ts +44 -0
  261. package/dist/runner/text-tools.js +237 -0
  262. package/dist/runner/workflow-host.d.ts +7 -2
  263. package/dist/runner/workflow-host.js +3 -1
  264. package/dist/runner/workflow-loop.d.ts +10 -1
  265. package/dist/runner/workflow-loop.js +14 -6
  266. package/dist/runner/workflow-spec.d.ts +21 -0
  267. package/dist/runner/workflow-spec.js +217 -93
  268. package/dist/runs-over-store.d.ts +14 -3
  269. package/dist/runs-over-store.js +100 -23
  270. package/dist/seal-key.d.ts +0 -2
  271. package/dist/seal-key.js +5 -45
  272. package/dist/sealed-settings-store.d.ts +19 -4
  273. package/dist/sealed-settings-store.js +9 -9
  274. package/dist/sealing.d.ts +4 -0
  275. package/dist/sealing.js +20 -0
  276. package/dist/secret-cut.d.ts +1 -1
  277. package/dist/secret-cut.js +1 -1
  278. package/dist/secret-name.d.ts +9 -0
  279. package/dist/secret-name.js +15 -0
  280. package/dist/secret-writes.d.ts +0 -1
  281. package/dist/secret-writes.js +0 -1
  282. package/dist/server-fs.d.ts +4 -0
  283. package/dist/server-fs.js +8 -2
  284. package/dist/server-lock.d.ts +0 -24
  285. package/dist/server-lock.js +5 -85
  286. package/dist/server-secrets-store.d.ts +4 -4
  287. package/dist/server-secrets-store.js +9 -31
  288. package/dist/server-secrets.d.ts +4 -9
  289. package/dist/server-secrets.js +12 -36
  290. package/dist/server.d.ts +37 -56
  291. package/dist/server.js +322 -134
  292. package/dist/sign-ins-store.d.ts +34 -36
  293. package/dist/sign-ins-store.js +27 -38
  294. package/dist/sign-ins.d.ts +2 -119
  295. package/dist/sign-ins.js +5 -311
  296. package/dist/standard-webhooks.d.ts +1 -1
  297. package/dist/standard-webhooks.js +1 -1
  298. package/dist/stats.d.ts +3 -2
  299. package/dist/stats.js +1 -1
  300. package/dist/stop-signals.d.ts +4 -2
  301. package/dist/stop-signals.js +5 -3
  302. package/dist/store/agent-body.d.ts +12 -2
  303. package/dist/store/agent-body.js +22 -4
  304. package/dist/store/deadline.d.ts +18 -0
  305. package/dist/store/deadline.js +45 -0
  306. package/dist/store/index.d.ts +2 -2
  307. package/dist/store/index.js +2 -2
  308. package/dist/store/open.d.ts +6 -3
  309. package/dist/store/open.js +2 -2
  310. package/dist/store/postgres/connection.d.ts +22 -2
  311. package/dist/store/postgres/connection.js +211 -41
  312. package/dist/store/postgres/migrate.d.ts +4 -0
  313. package/dist/store/postgres/migrate.js +9 -2
  314. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  315. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  316. package/dist/store/postgres/store.d.ts +9 -2
  317. package/dist/store/postgres/store.js +9 -0
  318. package/dist/store/schema.js +1 -1
  319. package/dist/store/seal.js +2 -2
  320. package/dist/store/sqlite/connection.js +14 -5
  321. package/dist/store/sqlite/run-patch.d.ts +3 -0
  322. package/dist/store/sqlite/run-patch.js +3 -0
  323. package/dist/store/sqlite/store.js +41 -12
  324. package/dist/store/store.d.ts +35 -6
  325. package/dist/store/store.js +12 -2
  326. package/dist/store-reads/cap.d.ts +1 -1
  327. package/dist/store-reads/cap.js +22 -4
  328. package/dist/store-reads/journal.d.ts +9 -6
  329. package/dist/store-reads/journal.js +129 -18
  330. package/dist/store-reads/learning.d.ts +82 -8
  331. package/dist/store-reads/learning.js +184 -11
  332. package/dist/store-reads/workflow.d.ts +1 -1
  333. package/dist/store-reads/workflow.js +1 -1
  334. package/dist/store-view.d.ts +19 -1
  335. package/dist/store-view.js +95 -27
  336. package/dist/template-eval.d.ts +60 -4
  337. package/dist/template-eval.js +120 -54
  338. package/dist/templates.d.ts +33 -14
  339. package/dist/templates.js +82 -46
  340. package/dist/timeline/group.d.ts +33 -0
  341. package/dist/timeline/group.js +77 -0
  342. package/dist/timeline/index.d.ts +7 -0
  343. package/dist/timeline/index.js +7 -0
  344. package/dist/timeline/labels.d.ts +79 -0
  345. package/dist/timeline/labels.js +150 -0
  346. package/dist/timeline/origin.d.ts +56 -0
  347. package/dist/timeline/origin.js +92 -0
  348. package/dist/timeline/render-text.d.ts +11 -0
  349. package/dist/timeline/render-text.js +62 -0
  350. package/dist/timeline/timeline.d.ts +282 -0
  351. package/dist/timeline/timeline.js +1308 -0
  352. package/dist/timeline/util.d.ts +17 -0
  353. package/dist/timeline/util.js +49 -0
  354. package/dist/tool-budget.d.ts +18 -0
  355. package/dist/tool-budget.js +50 -0
  356. package/dist/tool-gate.d.ts +47 -218
  357. package/dist/tool-gate.js +87 -545
  358. package/dist/tool-keys-store.d.ts +11 -12
  359. package/dist/tool-keys-store.js +24 -31
  360. package/dist/tool-keys.d.ts +5 -101
  361. package/dist/tool-keys.js +8 -267
  362. package/dist/tool-plane.d.ts +23 -52
  363. package/dist/tool-plane.js +23 -81
  364. package/dist/tool-settings-store.d.ts +1 -2
  365. package/dist/tool-settings-store.js +5 -8
  366. package/dist/tools.d.ts +67 -25
  367. package/dist/tools.js +170 -119
  368. package/dist/trigger-adapter.d.ts +2 -2
  369. package/dist/trigger-targets.d.ts +13 -1
  370. package/dist/trigger-targets.js +31 -1
  371. package/dist/triggers.d.ts +2 -2
  372. package/dist/triggers.js +3 -3
  373. package/dist/turn-end.d.ts +1 -1
  374. package/dist/turn-end.js +1 -1
  375. package/dist/turns.d.ts +0 -6
  376. package/dist/turns.js +0 -19
  377. package/dist/uploads.d.ts +28 -5
  378. package/dist/uploads.js +83 -10
  379. package/dist/usage.d.ts +1 -49
  380. package/dist/usage.js +3 -84
  381. package/dist/validate.d.ts +4 -0
  382. package/dist/validate.js +33 -14
  383. package/dist/webhooks.d.ts +102 -76
  384. package/dist/webhooks.js +266 -233
  385. package/dist/workflow-run.d.ts +114 -0
  386. package/dist/workflow-run.js +144 -0
  387. package/dist/workspace/archil-claim.d.ts +2 -2
  388. package/dist/workspace/archil-claim.js +4 -3
  389. package/dist/workspace/archil-disk.d.ts +10 -1
  390. package/dist/workspace/archil-disk.js +4 -0
  391. package/dist/workspace/archil-exec.d.ts +12 -2
  392. package/dist/workspace/archil-exec.js +16 -0
  393. package/dist/workspace/archil.d.ts +2 -2
  394. package/dist/workspace/archil.js +25 -5
  395. package/dist/workspace/attach.js +2 -0
  396. package/dist/workspace/beneath.d.ts +19 -0
  397. package/dist/workspace/beneath.js +106 -0
  398. package/dist/workspace/computer-deps.d.ts +26 -9
  399. package/dist/workspace/computer-deps.js +144 -43
  400. package/dist/workspace/computer-for-claim.d.ts +17 -14
  401. package/dist/workspace/computer-for-claim.js +99 -26
  402. package/dist/workspace/computer-hold.d.ts +6 -1
  403. package/dist/workspace/computer-hold.js +6 -1
  404. package/dist/workspace/computer-janitor.d.ts +47 -0
  405. package/dist/workspace/computer-janitor.js +182 -0
  406. package/dist/workspace/computer-ledger.d.ts +1 -8
  407. package/dist/workspace/computer-ledger.js +0 -3
  408. package/dist/workspace/computer-providers.d.ts +5 -3
  409. package/dist/workspace/computer-providers.js +11 -9
  410. package/dist/workspace/grep-worker.d.ts +5 -0
  411. package/dist/workspace/grep-worker.js +9 -6
  412. package/dist/workspace/hands.d.ts +5 -2
  413. package/dist/workspace/hands.js +4 -3
  414. package/dist/workspace/index.d.ts +6 -5
  415. package/dist/workspace/index.js +4 -4
  416. package/dist/workspace/local.d.ts +14 -2
  417. package/dist/workspace/local.js +170 -43
  418. package/dist/workspace/paths.js +3 -2
  419. package/dist/workspace/pi-env.d.ts +4 -0
  420. package/dist/workspace/pi-env.js +3 -2
  421. package/dist/workspace/resolve-computer.d.ts +55 -10
  422. package/dist/workspace/resolve-computer.js +66 -14
  423. package/dist/workspace/run-tools.d.ts +15 -31
  424. package/dist/workspace/run-tools.js +19 -30
  425. package/dist/workspace/workspace.d.ts +5 -0
  426. package/dist/workspace-paths.d.ts +0 -17
  427. package/dist/workspace-paths.js +1 -41
  428. package/dist/workspace.d.ts +0 -17
  429. package/dist/workspace.js +4 -110
  430. package/package.json +14 -14
  431. package/skills/agentrun-serve/SKILL.md +1 -1
  432. package/templates/README.md +11 -5
  433. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  434. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  435. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  436. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  437. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  438. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  439. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  440. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  441. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  442. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  443. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  444. package/templates/market-monitor/agent.md +2 -2
  445. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  446. package/templates/release-notes/agent.md +11 -0
  447. package/dist/bound-files.d.ts +0 -4
  448. package/dist/bound-files.js +0 -164
  449. package/dist/coding-tools.d.ts +0 -47
  450. package/dist/coding-tools.js +0 -189
  451. package/dist/computer-adb.d.ts +0 -12
  452. package/dist/computer-adb.js +0 -14
  453. package/dist/console/assets/index-Dn0ngwG9.js +0 -535
  454. package/dist/console/assets/index-DvW6Aled.css +0 -1
  455. package/dist/grade.d.ts +0 -63
  456. package/dist/grade.js +0 -150
  457. package/dist/mcp-servers.d.ts +0 -269
  458. package/dist/mcp-servers.js +0 -456
  459. package/dist/packs.d.ts +0 -71
  460. package/dist/packs.js +0 -180
  461. package/dist/sealed-settings.d.ts +0 -60
  462. package/dist/sealed-settings.js +0 -171
  463. package/dist/sessions.d.ts +0 -6
  464. package/dist/sessions.js +0 -109
  465. package/dist/workspace/computer-serves.d.ts +0 -12
  466. package/dist/workspace/computer-serves.js +0 -15
@@ -15,11 +15,11 @@ import { defineExtension, ROOT_CONVERSATION_ID, wrapTool } from "@earendil-works
15
15
  import { chargedCost, DecisionProviderError, EffectFailure, inspectWorkflow } from "@parcha/agentrun-dsl";
16
16
  import { modelPortFor } from "@parcha/agentrun-kernel";
17
17
  import { startModelProxy } from "@parcha/agentrun-kernel/host";
18
- import { CapRefused, checkRaise, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
18
+ import { CapRefused, checkRaise, DecisionPriceUnreadable, DECISION_SESSION, followUpOf, parkOf, runCap } from "@parcha/agentrun-kernel/kernel/cap";
19
19
  import { completer } from "../llm.js";
20
- // The serve decision-provider list prices and the replay check, shared with main's decision cap. They move to the new
21
- // path when the old per-run decision cap (decision-cap.ts) is deleted in the cutover; one source of truth until then.
22
- import { askedBefore, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
20
+ // The decision providers' list prices, the catalog's read and the replay check (decision-cap.ts), with holdOf, which the
21
+ // parity tests hold this cap's figures to.
22
+ import { askedBefore, catalogPrice, JEV_INPUT_USD, PARALLEL_DECISION_USD } from "../decision-cap.js";
23
23
  import { decisionProvidersIn } from "../decisions.js";
24
24
  import { imageLoader } from "../pdf-pages.js";
25
25
  import { llmTiers, nodeTiers, workflowNodes } from "../model.js";
@@ -39,20 +39,22 @@ import { PI_WIRES, storeSettings } from "./adapter-run-spec.js";
39
39
  import { policyFor } from "./adapters/pi.js";
40
40
  import { sessionProvider } from "../port-models.js";
41
41
  import { journalSessions } from "./sessions.js";
42
- import { KINDS } from "./journal-kinds.js";
42
+ import { KINDS, NODE_LOG_SESSION, WORKFLOW_SESSION } from "./journal-kinds.js";
43
+ import { cutStrings } from "../key-refusal.js";
44
+ import { CLOSE_MS, entriesOf } from "./loop.js";
43
45
  import { PAUSED_WORDS } from "./workflow-loop.js";
44
46
  import { heldRedactor, holdClaimed } from "./redact.js";
45
47
  import { holdStored } from "./store-secrets.js";
46
48
  import { workflowHost } from "./workflow-host.js";
49
+ import { bookedSpend } from "./metrics.js";
47
50
  /** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
48
51
  * @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
49
52
  * does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
50
53
  export const SUBMIT_TOOL = "submit";
51
54
  /** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
52
- const SESSION = "workflow";
53
- /** A call node's tool failure and a cap-held effect, as app.ts's runEffect completed them (the loop's `failing` reads them). */
55
+ const SESSION = WORKFLOW_SESSION;
56
+ /** A call node's tool failure, as app.ts's runEffect completed it (the loop's `failing` reads it). */
54
57
  const TOOL_FAILED = "agentrun_serve_tool_failed";
55
- const CAP_HELD = "agentrun_serve_cap_held";
56
58
  /** A tier's provider from the runner's model route (model-route.ts routeOf), the one way the runner resolves a model
57
59
  * (the pi adapter's path): the route's provider, model and price for the proxy's booking, and the catalog's cost and
58
60
  * output ceiling as the cap prices the hold. So a workflow model node and a pi turn book the same model the same way. */
@@ -67,6 +69,7 @@ export function routeProviderOf(env) {
67
69
  export async function providerFromRoute(route) {
68
70
  return {
69
71
  modelId: route.model,
72
+ ...(route.named ? { named: route.named } : {}),
70
73
  api: route.provider.api,
71
74
  ...(route.like ? { like: route.like } : {}),
72
75
  origin: route.provider.origin,
@@ -96,11 +99,13 @@ async function raisedCapOf(harness, context) {
96
99
  }
97
100
  return capUsd;
98
101
  }
99
- /** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it. */
102
+ /** The run's cap rule, handed to the loop so it parks and takes raises by the kernel cap without importing it. A park
103
+ * names the cap the run is held to when it parks (`capUsd()`: this claim's raise, else the launch's), so a raise too small
104
+ * for the step that parked shows the new pause at the raised cap, and the next raise is checked against that. */
100
105
  function capRuleOf(capUsd) {
101
106
  return {
102
107
  park: (refusal) => {
103
- const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd);
108
+ const park = parkOf({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) }, capUsd());
104
109
  return park.outcome === "parked"
105
110
  ? { outcome: "parked", pending: park.pending, words: park.words }
106
111
  : { outcome: "failed", error: park.error };
@@ -143,7 +148,7 @@ export function workflowSpecOf(deps) {
143
148
  if (unbound !== undefined)
144
149
  throw new Error(nodeToolUnboundText(unbound));
145
150
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor before the workflow runs.
146
- if (run?.redact)
151
+ if (run?.redact && deps.sealKey)
147
152
  await holdStored(heldRedactor(run.redact), deps.store, deps.sealKey, deps.data);
148
153
  const tiers = tiersOf(claimed.workflow);
149
154
  // The run's own keys, as the server's runnable check reads them: each by its name from the runner's environment first,
@@ -189,7 +194,7 @@ export function workflowSpecOf(deps) {
189
194
  const provider = providers.get(resolved) ?? providers.get("default");
190
195
  if (!provider)
191
196
  throw new Error(`the workflow names tier ${String(tier)}, which this run has no model for`);
192
- return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId };
197
+ return { provider: providerId(providers.has(resolved) ? resolved : "default"), modelId: provider.modelId, ...(provider.named ? { named: provider.named } : {}) };
193
198
  };
194
199
  const capModelOf = (id) => {
195
200
  for (const provider of providers.values())
@@ -211,6 +216,9 @@ export function workflowSpecOf(deps) {
211
216
  let decisionCap;
212
217
  // The run's paid tool calls on its one cap (TOOL_SESSION), wired at harnessReady: a call node's hold and its request.
213
218
  let paidTools;
219
+ // The call nodes' effects as they run (KINDS.nodeEffect on NODE_LOG_SESSION), opened at harnessReady: the run's graph
220
+ // lists its effects from them.
221
+ let nodeLog;
214
222
  // The run's own keys with its plane, as an agentic run's tool host gets them: the call nodes' effects and the model
215
223
  // nodes' tools run on these.
216
224
  const callEnv = callEnvOf(claimedEnv, claimed);
@@ -218,12 +226,10 @@ export function workflowSpecOf(deps) {
218
226
  const nodeHost = {
219
227
  where: { root: claimed.workRoot, work: claimed.workRoot, ref: { id: claim.runId } },
220
228
  env: callEnv,
221
- coding: { tools: [], extension: { name: "coding", tools: [] } },
222
229
  install: (extension) => void installed.push(extension),
223
230
  onConversation: () => { },
224
231
  beforeResume: () => { },
225
232
  beforeRelease: () => { },
226
- handoverInJournal: true,
227
233
  };
228
234
  const nodeBindings = await bindNodeTools(nodeNames, nodeHost);
229
235
  // Each node tool as the node gets it and the registry holds it: booked on the run's one ledger (bookedNodeTools), in an
@@ -248,8 +254,8 @@ export function workflowSpecOf(deps) {
248
254
  tools: [...new Set([...toolsOf(claimed.workflow), ...nodeNames])],
249
255
  agentId: claimed.agentId,
250
256
  revisionId: claimed.revisionId,
251
- ...(claimed.capUsd !== undefined ? { cap: capRuleOf(claimed.capUsd) } : {}),
252
- endPatch: async () => endPatchOf(booking, decisionCap, paidTools),
257
+ ...(claimed.capUsd !== undefined ? { cap: capRuleOf(() => effectiveCapUsd ?? claimed.capUsd) } : {}),
258
+ endPatch: async () => endPatchOf(booking, decisionCap, paidTools, run?.journal),
253
259
  build: (loopHooks) => {
254
260
  hooks.setPark(loopHooks);
255
261
  const hostDeps = {
@@ -258,7 +264,7 @@ export function workflowSpecOf(deps) {
258
264
  // would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
259
265
  sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
260
266
  nodeTool: (name) => nodeTools.get(name),
261
- runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools),
267
+ runEffect: runEffectOf(claimed, complete, callEnv, callPolicyOf(deps.store, claim.runId, claimed), () => paidTools, (line) => nodeLog?.append([{ kind: KINDS.nodeEffect, data: (run?.redact ? cutStrings(line, run.redact) : line) }]) ?? Promise.resolve()),
262
268
  workRoot: claimed.workRoot,
263
269
  flush: () => deps.store.flush(),
264
270
  // A decision node books through the run's one cap (admitted and settled as main holds it); a cap refusal for room
@@ -305,8 +311,15 @@ export function workflowSpecOf(deps) {
305
311
  // The run's paid tool calls on the same cap (TOOL_SESSION): a call node's hold before its admission, and the paid
306
312
  // request it makes, as an agentic run's tool calls book (paidStep).
307
313
  paidTools = await run.tools(await sessions.open(TOOL_SESSION), { flush: () => deps.store.flush() });
314
+ nodeLog = await sessions.open(NODE_LOG_SESSION);
308
315
  hooks.setPort(booking.models);
309
316
  },
317
+ settle: async () => {
318
+ const left = await hooks.bookingsSettled();
319
+ // Past the bound: the end is written, and each request still unbooked counts at its hold and bound (never less).
320
+ if (left > 0)
321
+ console.warn(`[runner] ${claim.runId}: ${left} model request(s) still unbooked ${CLOSE_MS} ms after the workflow ended; each counts at its hold and bound`);
322
+ },
310
323
  release: async () => {
311
324
  for (const proxy of proxies)
312
325
  await proxy.close().catch(() => undefined);
@@ -372,18 +385,46 @@ export function pauseAtEffects(cap, hooks, flight) {
372
385
  }
373
386
  /** The proxies start before the booking is wired; their hooks forward to the booking set at harnessReady. A request before
374
387
  * then would be a bug (no model request runs before the workflow does), so it refuses loudly. `park` is the loop's hook,
375
- * set at build, which a cap refusal calls. */
388
+ * set at build, which a cap refusal calls. Each request admitted is counted until it is booked: a request a person's
389
+ * stop cut short is booked only once its proxy sees the provider's side end, which can be after its node ended, and the
390
+ * run's end waits for it (bookingsSettled), as the pi adapter's loop does. */
376
391
  function deferredHooks() {
377
392
  let port;
378
393
  let loop;
394
+ let unbooked = 0;
395
+ const bookedAll = [];
379
396
  return {
380
397
  port: {
381
- beforeRequest: (request) => (port ?? missing()).beforeRequest(request),
382
- afterRequest: (usage, ticket, ended) => (port ?? missing()).afterRequest(usage, ticket, ended),
398
+ beforeRequest: async (request) => {
399
+ const ticket = await (port ?? missing()).beforeRequest(request);
400
+ unbooked += 1;
401
+ return ticket;
402
+ },
403
+ afterRequest: async (usage, ticket, ended) => {
404
+ try {
405
+ await (port ?? missing()).afterRequest(usage, ticket, ended);
406
+ }
407
+ finally {
408
+ unbooked = Math.max(0, unbooked - 1);
409
+ if (unbooked === 0)
410
+ for (const wake of bookedAll.splice(0))
411
+ wake();
412
+ }
413
+ },
383
414
  responded: (ids, ticket) => (port ?? missing()).responded?.(ids, ticket) ?? Promise.resolve(),
384
415
  note: (model, request) => (port ?? missing()).note?.(model, request),
385
416
  },
386
417
  setPort: (p) => { port = p; },
418
+ /** Waits, at most CLOSE_MS, until every request admitted is booked, and says how many are still not. Past the bound
419
+ * the run's end is written anyway, and a request left unbooked reads at its hold and bound, the worst it can have cost. */
420
+ bookingsSettled: async () => {
421
+ if (unbooked === 0)
422
+ return 0;
423
+ let timer;
424
+ await Promise.race([new Promise((resolve) => bookedAll.push(resolve)), new Promise((resolve) => (timer = setTimeout(resolve, CLOSE_MS)))]);
425
+ clearTimeout(timer);
426
+ return unbooked;
427
+ },
387
428
  park: (refusal) => loop?.park(refusal),
388
429
  // A person's pause, asked where the cap is (the loop's hooks): none before the loop hands its hooks over.
389
430
  paused: () => loop?.paused() ?? false,
@@ -409,7 +450,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
409
450
  return NO_HOLD(tool);
410
451
  const fee = tool === "web_search" ? parallelSearchFee(searchArgs(input).n) : parallelExtractFee(1);
411
452
  // Who charges for it (main's charge row's charged_by), as paidOn names it: the hold is the record its request books under.
412
- return { usd: fee.usd, name: fee.name, basis: fee.basis, chargedBy: fee.by };
453
+ return { usd: fee.usd, name: fee.name, tool, basis: fee.basis, chargedBy: fee.by };
413
454
  }
414
455
  if (tool === "llm") {
415
456
  const model = modelOfTier(typeof input.tier === "string" ? input.tier : undefined);
@@ -480,7 +521,7 @@ export function holdAtEffects(cap, deps) {
480
521
  const call = `${params.node.label}@${params.executionPath ?? ""}`;
481
522
  const id = `${call}#hold${(seq += 1)}`;
482
523
  try {
483
- await paid.admit({ id, name: hold.name, holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
524
+ await paid.admit({ id, name: hold.name, ...(hold.tool ? { tool: hold.tool } : {}), holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
484
525
  }
485
526
  catch (error) {
486
527
  if (error instanceof CapRefused && !error.forGood) {
@@ -532,7 +573,7 @@ function callPolicyOf(store, runId, claimed) {
532
573
  // Nothing read yet: unread, so a policy asked before the first read fails closed too.
533
574
  let current = { settings: {}, problems: [], unreadable: true };
534
575
  // Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part.
535
- const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, undefined, true);
576
+ const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, true);
536
577
  return async (tool) => {
537
578
  current = await storeSettings(store);
538
579
  return { permission: gate.policy(tool), denyFrom: gate.denyFrom(tool) };
@@ -562,13 +603,15 @@ export function failingEffects(cap) {
562
603
  },
563
604
  };
564
605
  }
565
- function runEffectOf(claimed, complete, env, policy, paidTools) {
606
+ function runEffectOf(claimed, complete, env, policy, paidTools, log) {
566
607
  // An `llm` call gives its call's hold back as its own model request is judged (the cap holds that request itself).
567
608
  const completeHeld = async (args, signal) => {
568
609
  await releaseCallHold();
569
610
  return complete(args, signal);
570
611
  };
571
- return (async ({ node, input, signal, executionPath }) => {
612
+ // A line the node log could not take (the claim lost meanwhile) costs the graph a line, never the call.
613
+ const logged = (line) => log(line).catch(() => undefined);
614
+ return (async ({ node, input, signal, executionPath, item }) => {
572
615
  // The call's ledger: its paid request books on the run's one ledger, on the hold taken before the call (holdAtEffects)
573
616
  // when it has one. No pause: a refusal inside an admitted effect fails the call, never parks the run there.
574
617
  const held = heldBooking();
@@ -577,6 +620,9 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
577
620
  const effect = node.via === "tool" && node.tool ? toolOf(node.tool)?.effect : undefined;
578
621
  if (!effect)
579
622
  throw new Error(`call node "${node.label}": agentrun-serve runs no tool ${node.tool ?? `via ${node.via}`}`);
623
+ // Its start and its end on the run's node log (main's app.ts), which the run's graph lists as its effects.
624
+ const at = { path: executionPath ?? null, item: item?.index ?? null, tool: node.tool, label: node.label };
625
+ await logged({ t: "effect.start", ...at, input, at: new Date().toISOString() });
580
626
  // Its tool's permission now (main's app.ts:382-384): a deny set since the run started is refused in the gate's words,
581
627
  // and an ask too, since a call node cannot wait for an approval. Neither runs.
582
628
  try {
@@ -585,10 +631,15 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
585
631
  throw new Error(deniedText(node.tool, undefined, denyFrom));
586
632
  if (permission === "ask")
587
633
  throw new Error(callNodeAskText(node.tool));
588
- return await effect(input, { signal, env, work: claimed.workRoot, complete: completeHeld, ...(ledger ? { ledger } : {}) });
634
+ const output = await effect(input, { signal, env, work: claimed.workRoot, complete: completeHeld, ...(ledger ? { ledger } : {}) });
635
+ await logged({ t: "effect.end", ...at, status: "done", output, at: new Date().toISOString() });
636
+ return output;
589
637
  }
590
638
  catch (error) {
591
639
  const message = String(error?.message ?? error);
640
+ // Whole up to 64 KB, so the server redacts it before it cuts it for the graph (graph-served.ts); a longer one is
641
+ // marked cut.
642
+ await logged({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 65_536), ...(message.length > 65_536 ? { error_truncated: true } : {}), at: new Date().toISOString() });
592
643
  if (signal.aborted || error?.name === "AbortError")
593
644
  throw error;
594
645
  return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
@@ -598,71 +649,130 @@ function runEffectOf(claimed, complete, env, policy, paidTools) {
598
649
  /** The end's cost and metrics: what every model request of the run cost (the booking) plus what its decisions and its
599
650
  * call nodes' paid requests cost (the decision cap, the paid tools), one spend for the run. Unknown (no figure) once any
600
651
  * part is unknown. */
601
- async function endPatchOf(booking, decisionCap, paidTools) {
652
+ /** What the run's decisions cost by their booking (bookedSpend, "decisions"), read from only what that needs: the root's
653
+ * session keys (journalSessions writes them there) and the decisions session's own conversation, never the run's model
654
+ * or tool records, so the read stays small within the end patch's bound. No decisions session: none, $0. */
655
+ async function decisionsBooked(journal) {
656
+ const root = await entriesOf(journal, ROOT_CONVERSATION_ID, BACKGROUND_CONTEXT);
657
+ const key = root.find((entry) => entry.kind === KINDS.sessionKey && entry.data?.key === DECISION_SESSION);
658
+ const conversation = key?.data?.conversation;
659
+ if (conversation == null)
660
+ return 0;
661
+ const decisions = await entriesOf(journal, conversation, BACKGROUND_CONTEXT);
662
+ return bookedSpend([key, ...decisions], "decisions").usd;
663
+ }
664
+ async function endPatchOf(booking, decisionCap, paidTools, journalOf) {
602
665
  if (!booking)
603
666
  return {};
604
667
  const model = booking.spentUsd();
605
- const decision = decisionCap ? decisionCap.spentUsd() : 0;
668
+ // A decision's cost is what its booking says it charged (bookedSpend over the decisions session's records, as the pi and
669
+ // CLI specs read it): one its provider reported no cost for is unknown, never the hold the cap counts it at
670
+ // (decisionCap.spentUsd, which stays the cap's own figure). With no journal to read, any decision is unknown.
671
+ const decision = !decisionCap ? 0 : journalOf ? await decisionsBooked(journalOf()) : null;
606
672
  const paid = paidTools ? paidTools.spentUsd() : 0;
607
673
  return model === null || decision === null || paid === null ? {} : { costUsd: model + decision + paid };
608
674
  }
609
675
  /** The run's one cap as a WorkflowCap: model nodes and call nodes pass through (their money is on the proxy), and a
610
- * decision node is admitted and settled through the run's decisions (`getCap`, wired at harnessReady), priced as main
611
- * holds it. The reference is deferred because the cap is not built until the Harness opens. */
676
+ * decision node is priced before the DSL driver admits its request (`judge`) and held, sent and settled through the run's
677
+ * decisions once it is admitted (`admitted`), priced as main holds it. The reference is deferred because the cap is not
678
+ * built until the Harness opens. */
612
679
  function decisionWorkflowCap(getCap, providers, hooks) {
613
- return { node: (fn) => fn, effect: (fn) => fn, judge: (fn, driver) => decisionJudge(fn, { getCap, providers, park: hooks.park, hooks, driver }) };
680
+ const judging = decisionJudging({ getCap, providers, park: hooks.park, hooks });
681
+ return { node: (fn) => fn, effect: (fn) => fn, judge: judging.before, admitted: judging.admitted };
614
682
  }
615
- /** A decision wrapped over the DSL driver's judge (the host's `recovered.runJudge`): it prices the request as main does
616
- * (holdOf), admits it through the kernel cap before the driver sends it, asks the driver's judge, and settles the hold at
617
- * what the answer charged (its hold when it reports none, the way `charged:held` books it). A refusal for room parks the
618
- * run through the loop's hook (as a model node's does); a refusal for no price fails it; a price the catalog could not
619
- * read fails the decision node as a connection error, never the cap's stop. A request the driver answers from what it
620
- * decided before (a route's, or one an earlier process admitted that did not fail) holds nothing (askedBefore). */
621
- function decisionJudge(inner, deps) {
622
- const judge = inner;
623
- return (async (params) => {
624
- if (deps.driver && askedBefore(deps.driver, params))
625
- return judge(params);
626
- // A person's pause in force parks the run before a new decision is held or sent, as a refusal for room does.
627
- if (deps.hooks?.paused()) {
628
- deps.hooks.pause();
629
- throw new Error(PAUSED_WORDS);
630
- }
631
- const id = params.provider ?? deps.providers.default;
632
- const provider = Object.hasOwn(deps.providers.providers, id) ? deps.providers.providers[id] : undefined;
633
- // A provider the host lacks is refused by the judge itself (configuration), before anything is held.
634
- if (!provider)
635
- return judge(params);
636
- const cap = deps.getCap();
637
- // The cap is wired at harnessReady, before any node runs; a decision reaching here without it is a bug.
638
- if (!cap)
639
- throw new Error(`decision "${params.label}": the run's decision cap was not wired before the workflow ran`);
640
- const request = await decisionRequestOf(provider, params);
641
- try {
642
- await cap.admit(request);
643
- }
644
- catch (error) {
645
- // A refusal the cap read: for room the run parks (a raise sends it), for no price it fails; both through the loop's
646
- // hook, as a model node's refusal does. A price the catalog could not read fails the decision node, never the cap.
647
- if (error instanceof CapRefused) {
648
- deps.park({ message: error.message, forGood: error.forGood, ...(error.figures ? { figures: error.figures } : {}) });
649
- throw error;
650
- }
651
- throw error; // DecisionPriceUnreadable, or anything else: the decision node's own failure.
652
- }
653
- try {
654
- const result = await judge(params);
655
- await cap.settle(request.id, { end: "charged", usd: finiteUsd(result?.cost_usd) });
656
- return result;
657
- }
658
- catch (error) {
659
- // Sent and maybe billed (its outcome lost, its answer rejected): at what it was charged, else at its hold (null).
660
- // One its provider refused unbilled, or that never left, charged nothing: booked at $0 so no later process counts it.
661
- const charged = chargedCost(error);
662
- await cap.settle(request.id, { end: "charged", usd: charged !== undefined ? charged : unbilled(error) ? 0 : null });
663
- throw error;
664
- }
665
- });
683
+ /** A decision under the run's cap, in two halves around the DSL driver's admission of its request (dsl withRecovery: the
684
+ * request is committed, `decision.request`, before the judge is asked; one asked and never answered is never asked again):
685
+ * - `before`, outside the admission: a request the driver answers from what it decided before (a route's, or one an
686
+ * earlier process admitted that did not fail) holds nothing (askedBefore); a person's pause parks the run; the
687
+ * request is priced as main prices it (holdOf), its catalog read again on a moment's outage.
688
+ * - `admitted`, the judge the driver asks once it has admitted the request: the hold is taken through the kernel cap (its
689
+ * record made durable before the send), the provider is asked, and the hold is settled at what the answer charged (its
690
+ * hold when it reports none). So a hold is never kept for a request the driver did not admit: a process that dies
691
+ * before the admission leaves nothing for the next claim to count beside asking it again. A refusal for room or for no
692
+ * price ends the admitted request failed, unsent, in the driver's commit (asked again by the next claim), and then parks
693
+ * the run, or fails it, through the loop's hook, as a model node's refusal does. A price the catalog still could not
694
+ * read fails the decision node as an unsent connection error, never the cap's stop. */
695
+ function decisionJudging(deps) {
696
+ /** Each request `before` priced, by the params object the driver hands on to `admitted`; and the cap's refusal of one. */
697
+ const priced = new WeakMap();
698
+ const refused = new WeakMap();
699
+ return {
700
+ before(inner, driver) {
701
+ const judge = inner;
702
+ return (async (params) => {
703
+ if (driver && askedBefore(driver, params))
704
+ return judge(params);
705
+ // A person's pause in force parks the run before a new decision is held or sent, as a refusal for room does.
706
+ if (deps.hooks?.paused()) {
707
+ deps.hooks.pause();
708
+ throw new Error(PAUSED_WORDS);
709
+ }
710
+ const id = params.provider ?? deps.providers.default;
711
+ const provider = Object.hasOwn(deps.providers.providers, id) ? deps.providers.providers[id] : undefined;
712
+ // A provider the host lacks is refused by the judge itself (configuration), before anything is held.
713
+ if (!provider)
714
+ return judge(params);
715
+ // The cap is wired at harnessReady, before any node runs; a decision reaching here without it is a bug.
716
+ if (!deps.getCap())
717
+ throw new Error(`decision "${params.label}": the run's decision cap was not wired before the workflow ran`);
718
+ priced.set(params, await decisionRequestOf(provider, params));
719
+ try {
720
+ return await judge(params);
721
+ }
722
+ catch (error) {
723
+ const refusal = refused.get(params);
724
+ if (!refusal)
725
+ throw error;
726
+ // The cap refused the admitted request: the driver ended it failed, unsent; that commit lands before the run
727
+ // parks, so the next claim asks it again rather than finding it asked and never answered. A commit the store
728
+ // refused is thrown, never a park: parked with the request still asked, the next claim would refuse to ask it.
729
+ await driver?.flush();
730
+ deps.park({ message: refusal.message, forGood: refusal.forGood, ...(refusal.figures ? { figures: refusal.figures } : {}) });
731
+ throw refusal;
732
+ }
733
+ finally {
734
+ priced.delete(params);
735
+ refused.delete(params);
736
+ }
737
+ });
738
+ },
739
+ admitted(inner) {
740
+ const judge = inner;
741
+ return (async (params) => {
742
+ const request = priced.get(params);
743
+ const cap = deps.getCap();
744
+ if (!request || !cap)
745
+ return judge(params);
746
+ try {
747
+ await cap.admit(request);
748
+ }
749
+ catch (error) {
750
+ // A refusal the cap read: told to `before` (which parks or fails the run once the driver has ended the request),
751
+ // and thrown here as a request that never left, so the driver ends it failed with nothing spent.
752
+ if (error instanceof CapRefused) {
753
+ refused.set(params, error);
754
+ throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
755
+ }
756
+ // A price the catalog could not read: the decision node fails unsent, as a connection error, never the cap.
757
+ if (error instanceof DecisionPriceUnreadable)
758
+ throw new DecisionProviderError("connection", `${params.label}'s decision was not sent: ${error.message}`, { unsent: true, cause: error });
759
+ throw error;
760
+ }
761
+ try {
762
+ const result = await judge(params);
763
+ await cap.settle(request.id, { end: "charged", usd: finiteUsd(result?.cost_usd) });
764
+ return result;
765
+ }
766
+ catch (error) {
767
+ // Sent and maybe billed (its outcome lost, its answer rejected): at what it was charged, else at its hold (null).
768
+ // One its provider refused unbilled, or that never left, charged nothing: booked at $0 so no later process counts it.
769
+ const charged = chargedCost(error);
770
+ await cap.settle(request.id, { end: "charged", usd: charged !== undefined ? charged : unbilled(error) ? 0 : null });
771
+ throw error;
772
+ }
773
+ });
774
+ },
775
+ };
666
776
  }
667
777
  /** A decision's request for the kernel cap, priced as main holds it (serve decision-cap.ts holdOf): Parallel's list price
668
778
  * for one request; Jev's published per-input-token price; an OpenRouter Decisions model at its catalog price (per request,
@@ -687,11 +797,12 @@ async function decisionRequestOf(provider, params) {
687
797
  return { ...base, model: openrouterModel(model ?? provider.id, null, null) };
688
798
  let price;
689
799
  try {
690
- price = await priced.priceOf(model);
800
+ // Read again on a moment's outage (catalogPrice, CATALOG_TRIES reads), as main reads it.
801
+ price = await catalogPrice(priced, model, params.signal);
691
802
  }
692
803
  catch {
693
- // The catalog could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel throws
694
- // DecisionPriceUnreadable for "unreadable").
804
+ // The catalog still could not be read: the decision fails unsent as a connection error, never the cap's stop (asModel
805
+ // throws DecisionPriceUnreadable for "unreadable").
695
806
  return { ...base, model: "unreadable" };
696
807
  }
697
808
  if (!price)
@@ -741,17 +852,30 @@ function nodeToolGate(names, policy) {
741
852
  name: "tool-gate",
742
853
  wraps: [...names].map((name) => wrapTool({ name }, (inner) => ({
743
854
  ...inner,
744
- async execute(args, api, context) {
745
- const { permission, denyFrom } = await policy(inner.name);
746
- if (permission === "deny")
747
- return forModel(deniedText(inner.name, undefined, denyFrom), { isError: true });
748
- if (permission === "ask")
749
- return forModel(modelNodeAskText(inner.name), { isError: true });
750
- return inner.execute(args, api, context);
751
- },
855
+ execute: gatedNodeCall(inner.name, policy, inner.execute),
752
856
  }))),
753
857
  });
754
858
  }
859
+ /** The task memo the gate keeps that it let a call through, before the call runs. */
860
+ const LET_THROUGH = "agentrun.gate.let-through";
861
+ /** `execute` behind the gate, for the tool `name`. A call it lets through is marked so in its task first, so when
862
+ * pi-durable's recovery runs the same call again on a later claim (the first attempt cut with its claim, maybe after it
863
+ * was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
864
+ * (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
865
+ export function gatedNodeCall(name, policy, execute) {
866
+ return async (args, api, context) => {
867
+ const task = api;
868
+ const { permission, denyFrom } = await policy(name);
869
+ if (permission !== "allow") {
870
+ // A call an earlier attempt of which this gate let through may have reached its host: whatever refuses it now, its
871
+ // effect is not known, never "not run".
872
+ const ran = (await task.memo(LET_THROUGH, context)) === true ? "unknown" : "no";
873
+ return forModel(permission === "deny" ? deniedText(name, undefined, denyFrom, ran) : modelNodeAskText(name, ran), { isError: true });
874
+ }
875
+ await task.memo(LET_THROUGH, true, context);
876
+ return execute(args, api, context);
877
+ };
878
+ }
755
879
  /** `binding`'s tools with each call's paid requests booked on the run's one ledger (Ledger.paid, the paid tool calls on
756
880
  * the run's cap, as an agentic run's are), a refusal for room parking the run (Ledger.pause, as main's paidCall pauses):
757
881
  * a node's tool call is the node's own turn, so the run parks and resumes it from its journal. */
@@ -1,11 +1,11 @@
1
- import type { Revision } from "@parcha/pi-durable-agent";
2
- import type { MessageOrigin } from "@parcha/pi-durable-agent/timeline";
1
+ import type { Revision } from "./agent-rows.js";
2
+ import type { MessageOrigin } from "./timeline/index.js";
3
3
  import { type AgentEntry, type ExternalRef } from "./agents-store.js";
4
4
  import { ApiError, type InputIssue } from "./errors.js";
5
5
  import { type LearningMode, type Seed, type Shown } from "./learning.js";
6
6
  import { type Place } from "./place.js";
7
7
  import { type RunLaunch } from "./run-launch.js";
8
- import type { ApprovalDecision, RunMoment } from "./run-view.js";
8
+ import { type ApprovalDecision, type RunMoment } from "./run-view.js";
9
9
  import { type NewRevision, type RunOrigin, type RunRow, type Store } from "./store/index.js";
10
10
  import { type ToolSettingsMap } from "./tool-plane.js";
11
11
  import type { RunTrigger } from "./triggers.js";
@@ -111,6 +111,12 @@ export interface StartDeps {
111
111
  /** The uploaded files named by file_ids, ready to copy; throws when one is not ready (server.ts uploads.readyFiles). The
112
112
  * copy into the run's work/ is the runner's at its claim; this only checks they are ready before the run starts. */
113
113
  readyFiles(ids: readonly unknown[]): Promise<unknown>;
114
+ /** Holds the run's files for it (uploads.ts Uploads.hold) before its row is written, so a file deleted after the start
115
+ * is still the run's at its claim; `release` lets go of a hold whose run was never written (or was another's). */
116
+ readonly files?: {
117
+ hold(runId: string, ids: readonly string[]): Promise<void>;
118
+ release(runId: string): Promise<void>;
119
+ };
114
120
  /** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
115
121
  fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
116
122
  /** A run's title from its input (server.ts workflowTitle), for a workflow run's title. */
@@ -128,6 +134,8 @@ export interface StartDeps {
128
134
  readonly documents?: string;
129
135
  /** What a run's box may reach, as the server resolved it, or "none". */
130
136
  readonly boxAllow?: readonly string[] | "none";
137
+ /** The operator set that (run-launch.ts boxAllowSet). */
138
+ readonly boxAllowSet?: true;
131
139
  /** The run's model, pinned at start: resolved exactly as the old per-run process resolved it from the revision and agent
132
140
  * (app.ts's runModels / wireModels over revision.body.model on its harness). The runner reads launch.model alone, so one
133
141
  * resolution happens, here. Required. */
@@ -147,6 +155,9 @@ export interface StartDeps {
147
155
  }>;
148
156
  /** The learning budget in bytes (learning.ts LEARNING_BUDGET), for which notes fit a run's # Learned section. */
149
157
  readonly learningBudget?: number;
158
+ /** The model the server names to grade what a run proposes (learning.ts gradeModelOf), put on each learning start; none,
159
+ * the agent's own grades it. */
160
+ readonly gradeModel?: string;
150
161
  /** The host's secrets as they are shown now (learning-run.ts shown), for cutting the notes a run is given. */
151
162
  shown?(): Shown;
152
163
  }