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

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 (444) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/README.md +343 -246
  3. package/dist/adapters.d.ts +0 -7
  4. package/dist/adapters.js +11 -22
  5. package/dist/agent-rows.d.ts +98 -0
  6. package/dist/agent-rows.js +1 -0
  7. package/dist/agents-store.d.ts +6 -2
  8. package/dist/agents-store.js +60 -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 +14 -0
  14. package/dist/api-only.js +33 -0
  15. package/dist/archil-routes.d.ts +1 -1
  16. package/dist/bash-read-only.d.ts +22 -0
  17. package/dist/bash-read-only.js +701 -0
  18. package/dist/box-egress-vm.d.ts +0 -8
  19. package/dist/box-egress-vm.js +0 -10
  20. package/dist/box-egress.d.ts +0 -4
  21. package/dist/box-egress.js +1 -16
  22. package/dist/box-paths.d.ts +25 -2
  23. package/dist/box-paths.js +79 -11
  24. package/dist/box-relay.d.ts +0 -11
  25. package/dist/box-relay.js +0 -20
  26. package/dist/box-settings.d.ts +26 -0
  27. package/dist/box-settings.js +63 -0
  28. package/dist/boxes.d.ts +21 -1
  29. package/dist/boxes.js +27 -20
  30. package/dist/browser-commands.d.ts +5 -2
  31. package/dist/browser-commands.js +4 -4
  32. package/dist/browser-computer.d.ts +5 -0
  33. package/dist/browser-computer.js +21 -0
  34. package/dist/browser-cost.d.ts +9 -6
  35. package/dist/browser-cost.js +94 -51
  36. package/dist/browser-live.d.ts +7 -20
  37. package/dist/browser-live.js +15 -93
  38. package/dist/browser-person.d.ts +18 -53
  39. package/dist/browser-person.js +94 -279
  40. package/dist/budget.d.ts +0 -4
  41. package/dist/budget.js +0 -7
  42. package/dist/cap.d.ts +8 -12
  43. package/dist/cap.js +12 -27
  44. package/dist/cli.js +61 -20
  45. package/dist/closed-pipes.d.ts +2 -0
  46. package/dist/closed-pipes.js +13 -0
  47. package/dist/computer-commands.d.ts +2 -0
  48. package/dist/computer-commands.js +2 -0
  49. package/dist/computer-keys.js +5 -2
  50. package/dist/computer-setting.d.ts +20 -4
  51. package/dist/computer-setting.js +25 -5
  52. package/dist/computers.d.ts +31 -3
  53. package/dist/computers.js +70 -11
  54. package/dist/confine.d.ts +120 -0
  55. package/dist/confine.js +436 -0
  56. package/dist/console/assets/index-RPHGlXmM.js +540 -0
  57. package/dist/console/assets/index-opTN5Naq.css +1 -0
  58. package/dist/console/index.html +2 -2
  59. package/dist/daytona-api.d.ts +0 -11
  60. package/dist/daytona-api.js +1 -82
  61. package/dist/decision-rows.d.ts +1 -1
  62. package/dist/decision-rows.js +1 -1
  63. package/dist/docker-daemon.d.ts +31 -0
  64. package/dist/docker-daemon.js +56 -0
  65. package/dist/docker-host-addresses.d.ts +37 -0
  66. package/dist/docker-host-addresses.js +110 -0
  67. package/dist/effort-guidance.js +4 -3
  68. package/dist/environment.d.ts +0 -3
  69. package/dist/environment.js +3 -5
  70. package/dist/errors.d.ts +0 -2
  71. package/dist/errors.js +6 -9
  72. package/dist/filed-answer.d.ts +32 -0
  73. package/dist/filed-answer.js +160 -0
  74. package/dist/files.d.ts +1 -11
  75. package/dist/files.js +2 -21
  76. package/dist/github-connection.d.ts +2 -2
  77. package/dist/github-connection.js +1 -1
  78. package/dist/graph-view.d.ts +3 -5
  79. package/dist/graph-view.js +4 -14
  80. package/dist/handed-values.d.ts +9 -0
  81. package/dist/handed-values.js +26 -0
  82. package/dist/harness-install.d.ts +22 -5
  83. package/dist/harness-install.js +98 -20
  84. package/dist/harness-opencode/adapter.d.ts +7 -0
  85. package/dist/harness-opencode/adapter.js +23 -6
  86. package/dist/harness-opencode/index.d.ts +1 -1
  87. package/dist/harness-opencode/index.js +1 -1
  88. package/dist/harness-opencode/verify.d.ts +17 -0
  89. package/dist/harness-opencode/verify.js +30 -10
  90. package/dist/harness-table.js +6 -1
  91. package/dist/harness.d.ts +4 -3
  92. package/dist/harness.js +16 -1
  93. package/dist/heard.js +1 -1
  94. package/dist/held-fd.d.ts +5 -0
  95. package/dist/held-fd.js +14 -0
  96. package/dist/host-calls.d.ts +20 -0
  97. package/dist/host-calls.js +12 -0
  98. package/dist/host-tools.d.ts +4 -21
  99. package/dist/host-tools.js +4 -61
  100. package/dist/host.d.ts +2 -4
  101. package/dist/host.js +2 -7
  102. package/dist/import-summary.d.ts +1 -5
  103. package/dist/import-summary.js +0 -21
  104. package/dist/import.d.ts +6 -6
  105. package/dist/import.js +62 -24
  106. package/dist/key-refusal.d.ts +5 -1
  107. package/dist/key-refusal.js +19 -4
  108. package/dist/learn/check.d.ts +6 -2
  109. package/dist/learn/check.js +83 -29
  110. package/dist/learn/folder.d.ts +5 -1
  111. package/dist/learn/folder.js +10 -3
  112. package/dist/learn/grade.d.ts +14 -0
  113. package/dist/learn/grade.js +68 -12
  114. package/dist/learn/index.d.ts +4 -4
  115. package/dist/learn/index.js +4 -4
  116. package/dist/learn/reflect.d.ts +31 -2
  117. package/dist/learn/reflect.js +79 -4
  118. package/dist/learn/relevance.d.ts +24 -0
  119. package/dist/learn/relevance.js +91 -0
  120. package/dist/learn/secrets.d.ts +8 -1
  121. package/dist/learn/secrets.js +95 -15
  122. package/dist/learn/skills.d.ts +112 -14
  123. package/dist/learn/skills.js +556 -52
  124. package/dist/learned-workflow.d.ts +37 -5
  125. package/dist/learned-workflow.js +106 -12
  126. package/dist/learning-routes.d.ts +16 -49
  127. package/dist/learning-routes.js +46 -36
  128. package/dist/learning-run.d.ts +6 -250
  129. package/dist/learning-run.js +11 -665
  130. package/dist/learning-words.d.ts +12 -5
  131. package/dist/learning-words.js +18 -9
  132. package/dist/learning.d.ts +93 -77
  133. package/dist/learning.js +176 -304
  134. package/dist/live/stream.js +1 -1
  135. package/dist/live/translate.js +13 -3
  136. package/dist/local-models.d.ts +11 -5
  137. package/dist/local-models.js +13 -8
  138. package/dist/mcp-gateway.d.ts +11 -52
  139. package/dist/mcp-gateway.js +44 -148
  140. package/dist/mcp-oauth.d.ts +10 -14
  141. package/dist/mcp-oauth.js +14 -32
  142. package/dist/mcp-probe.d.ts +0 -7
  143. package/dist/mcp-probe.js +4 -10
  144. package/dist/mcp-servers-store.d.ts +6 -6
  145. package/dist/mcp-servers-store.js +13 -15
  146. package/dist/mcp-store.js +3 -4
  147. package/dist/mcp.js +4 -3
  148. package/dist/model.d.ts +6 -7
  149. package/dist/model.js +43 -27
  150. package/dist/monid.d.ts +0 -2
  151. package/dist/monid.js +3 -6
  152. package/dist/openapi.d.ts +8 -1
  153. package/dist/openapi.js +124 -50
  154. package/dist/page.d.ts +1 -3
  155. package/dist/page.js +9 -19
  156. package/dist/paid-calls.d.ts +21 -27
  157. package/dist/paid-calls.js +28 -62
  158. package/dist/pause.d.ts +0 -2
  159. package/dist/pause.js +1 -8
  160. package/dist/place.d.ts +0 -5
  161. package/dist/place.js +0 -10
  162. package/dist/print.d.ts +2 -1
  163. package/dist/print.js +4 -2
  164. package/dist/propose.js +83 -39
  165. package/dist/push-handler.d.ts +1 -1
  166. package/dist/reflect-range.d.ts +25 -0
  167. package/dist/reflect-range.js +30 -0
  168. package/dist/refusal-words.d.ts +5 -1
  169. package/dist/refusal-words.js +5 -1
  170. package/dist/rows.d.ts +1 -1
  171. package/dist/run-cut.d.ts +0 -6
  172. package/dist/run-cut.js +0 -6
  173. package/dist/run-db.d.ts +2 -13
  174. package/dist/run-db.js +2 -41
  175. package/dist/run-launch.d.ts +19 -2
  176. package/dist/run-launch.js +13 -5
  177. package/dist/run-learning-served.d.ts +46 -2
  178. package/dist/run-learning-served.js +26 -7
  179. package/dist/run-reads-over-store.d.ts +1 -1
  180. package/dist/run-reads-over-store.js +15 -6
  181. package/dist/run-secrets.d.ts +33 -0
  182. package/dist/run-secrets.js +53 -0
  183. package/dist/run-timeline-served.d.ts +5 -1
  184. package/dist/run-timeline-served.js +19 -5
  185. package/dist/run-view.d.ts +12 -17
  186. package/dist/run-view.js +29 -28
  187. package/dist/runnable.d.ts +18 -10
  188. package/dist/runnable.js +21 -10
  189. package/dist/runner/adapter-loop.d.ts +14 -3
  190. package/dist/runner/adapter-loop.js +464 -62
  191. package/dist/runner/adapter-run-spec.d.ts +29 -8
  192. package/dist/runner/adapter-run-spec.js +96 -37
  193. package/dist/runner/adapters/index.js +11 -1
  194. package/dist/runner/adapters/pi.d.ts +15 -1
  195. package/dist/runner/adapters/pi.js +19 -5
  196. package/dist/runner/beside.d.ts +30 -3
  197. package/dist/runner/beside.js +54 -12
  198. package/dist/runner/claim-secrets.d.ts +10 -1
  199. package/dist/runner/claim-secrets.js +49 -15
  200. package/dist/runner/cli-run-spec.d.ts +2 -0
  201. package/dist/runner/cli-run-spec.js +60 -17
  202. package/dist/runner/commands.js +1 -1
  203. package/dist/runner/computer-journal.d.ts +15 -2
  204. package/dist/runner/computer-journal.js +41 -5
  205. package/dist/runner/conformance/harness.js +118 -8
  206. package/dist/runner/conformance/subject.d.ts +4 -1
  207. package/dist/runner/dispatch.d.ts +8 -1
  208. package/dist/runner/dispatch.js +81 -7
  209. package/dist/runner/end-of-run.d.ts +8 -2
  210. package/dist/runner/end-of-run.js +10 -4
  211. package/dist/runner/github-app.js +1 -1
  212. package/dist/runner/harness-loops.d.ts +9 -1
  213. package/dist/runner/harness-loops.js +15 -2
  214. package/dist/runner/journal-kinds.d.ts +30 -6
  215. package/dist/runner/journal-kinds.js +20 -5
  216. package/dist/runner/journal-reader.d.ts +1 -1
  217. package/dist/runner/journal-reader.js +2 -2
  218. package/dist/runner/learning-ask.d.ts +4 -0
  219. package/dist/runner/learning-ask.js +15 -1
  220. package/dist/runner/learning-end.d.ts +18 -3
  221. package/dist/runner/learning-end.js +113 -11
  222. package/dist/runner/learning-loop.d.ts +5 -0
  223. package/dist/runner/learning-loop.js +26 -6
  224. package/dist/runner/live-ticker.d.ts +1 -1
  225. package/dist/runner/live-ticker.js +28 -4
  226. package/dist/runner/loop-contract.d.ts +3 -2
  227. package/dist/runner/main.d.ts +64 -10
  228. package/dist/runner/main.js +165 -27
  229. package/dist/runner/mcp-claim.d.ts +1 -1
  230. package/dist/runner/mcp-claim.js +2 -3
  231. package/dist/runner/mcp-run.d.ts +2 -0
  232. package/dist/runner/mcp-run.js +15 -5
  233. package/dist/runner/memory-claim.d.ts +9 -0
  234. package/dist/runner/memory-claim.js +25 -0
  235. package/dist/runner/metrics.d.ts +33 -1
  236. package/dist/runner/metrics.js +85 -1
  237. package/dist/runner/model-route.d.ts +13 -0
  238. package/dist/runner/model-route.js +154 -11
  239. package/dist/runner/redact.d.ts +8 -2
  240. package/dist/runner/redact.js +11 -2
  241. package/dist/runner/reflect-hook.d.ts +12 -1
  242. package/dist/runner/reflect-hook.js +33 -3
  243. package/dist/runner/runner.d.ts +20 -0
  244. package/dist/runner/runner.js +56 -10
  245. package/dist/runner/store-port.d.ts +1 -1
  246. package/dist/runner/store-secrets.d.ts +3 -3
  247. package/dist/runner/store-secrets.js +8 -12
  248. package/dist/runner/text-tools.d.ts +44 -0
  249. package/dist/runner/text-tools.js +237 -0
  250. package/dist/runner/workflow-loop.d.ts +6 -0
  251. package/dist/runner/workflow-loop.js +6 -4
  252. package/dist/runner/workflow-spec.d.ts +18 -0
  253. package/dist/runner/workflow-spec.js +68 -26
  254. package/dist/runs-over-store.d.ts +8 -3
  255. package/dist/runs-over-store.js +76 -19
  256. package/dist/seal-key.d.ts +54 -15
  257. package/dist/seal-key.js +232 -82
  258. package/dist/sealed-settings-store.d.ts +19 -4
  259. package/dist/sealed-settings-store.js +9 -9
  260. package/dist/sealing.d.ts +4 -0
  261. package/dist/sealing.js +20 -0
  262. package/dist/secret-cut.d.ts +1 -1
  263. package/dist/secret-cut.js +1 -1
  264. package/dist/secret-name.d.ts +9 -0
  265. package/dist/secret-name.js +15 -0
  266. package/dist/secret-writes.d.ts +0 -1
  267. package/dist/secret-writes.js +0 -1
  268. package/dist/secrets.d.ts +2 -10
  269. package/dist/secrets.js +21 -17
  270. package/dist/server-fs.d.ts +4 -0
  271. package/dist/server-fs.js +8 -2
  272. package/dist/server-lock.d.ts +0 -24
  273. package/dist/server-lock.js +1 -80
  274. package/dist/server-secrets-store.d.ts +4 -4
  275. package/dist/server-secrets-store.js +10 -32
  276. package/dist/server-secrets.d.ts +4 -9
  277. package/dist/server-secrets.js +12 -33
  278. package/dist/server.d.ts +26 -44
  279. package/dist/server.js +229 -142
  280. package/dist/sign-ins-store.d.ts +34 -36
  281. package/dist/sign-ins-store.js +27 -38
  282. package/dist/sign-ins.d.ts +2 -119
  283. package/dist/sign-ins.js +5 -311
  284. package/dist/standard-webhooks.d.ts +1 -1
  285. package/dist/standard-webhooks.js +1 -1
  286. package/dist/stats.d.ts +3 -2
  287. package/dist/stats.js +1 -1
  288. package/dist/store/agent-body.d.ts +8 -2
  289. package/dist/store/agent-body.js +16 -4
  290. package/dist/store/index.d.ts +3 -3
  291. package/dist/store/index.js +3 -3
  292. package/dist/store/open.d.ts +18 -5
  293. package/dist/store/open.js +23 -3
  294. package/dist/store/postgres/connection.d.ts +18 -2
  295. package/dist/store/postgres/connection.js +156 -32
  296. package/dist/store/postgres/migrate.d.ts +4 -0
  297. package/dist/store/postgres/migrate.js +27 -3
  298. package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
  299. package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
  300. package/dist/store/postgres/store.d.ts +9 -2
  301. package/dist/store/postgres/store.js +9 -0
  302. package/dist/store/schema.js +1 -1
  303. package/dist/store/seal.js +2 -2
  304. package/dist/store/sqlite/connection.js +49 -5
  305. package/dist/store/sqlite/run-patch.d.ts +3 -0
  306. package/dist/store/sqlite/run-patch.js +3 -0
  307. package/dist/store/sqlite/store.js +64 -20
  308. package/dist/store/store.d.ts +38 -6
  309. package/dist/store/store.js +12 -2
  310. package/dist/store-reads/cap.d.ts +1 -1
  311. package/dist/store-reads/cap.js +22 -4
  312. package/dist/store-reads/journal.d.ts +25 -6
  313. package/dist/store-reads/journal.js +173 -21
  314. package/dist/store-reads/learning.d.ts +26 -8
  315. package/dist/store-reads/learning.js +12 -4
  316. package/dist/store-reads/workflow.d.ts +1 -1
  317. package/dist/store-reads/workflow.js +1 -1
  318. package/dist/store-view.d.ts +5 -1
  319. package/dist/store-view.js +91 -23
  320. package/dist/template-eval.d.ts +60 -4
  321. package/dist/template-eval.js +120 -54
  322. package/dist/templates.d.ts +24 -10
  323. package/dist/templates.js +69 -38
  324. package/dist/timeline/group.d.ts +33 -0
  325. package/dist/timeline/group.js +77 -0
  326. package/dist/timeline/index.d.ts +7 -0
  327. package/dist/timeline/index.js +7 -0
  328. package/dist/timeline/labels.d.ts +79 -0
  329. package/dist/timeline/labels.js +150 -0
  330. package/dist/timeline/origin.d.ts +56 -0
  331. package/dist/timeline/origin.js +92 -0
  332. package/dist/timeline/render-text.d.ts +11 -0
  333. package/dist/timeline/render-text.js +62 -0
  334. package/dist/timeline/timeline.d.ts +274 -0
  335. package/dist/timeline/timeline.js +1308 -0
  336. package/dist/timeline/util.d.ts +17 -0
  337. package/dist/timeline/util.js +49 -0
  338. package/dist/tool-gate.d.ts +41 -216
  339. package/dist/tool-gate.js +79 -540
  340. package/dist/tool-keys-store.d.ts +11 -12
  341. package/dist/tool-keys-store.js +24 -31
  342. package/dist/tool-keys.d.ts +9 -104
  343. package/dist/tool-keys.js +15 -271
  344. package/dist/tool-plane.d.ts +14 -42
  345. package/dist/tool-plane.js +23 -81
  346. package/dist/tool-settings-store.d.ts +1 -2
  347. package/dist/tool-settings-store.js +5 -8
  348. package/dist/tools.d.ts +31 -19
  349. package/dist/tools.js +101 -108
  350. package/dist/trigger-adapter.d.ts +2 -2
  351. package/dist/trigger-schedule.js +2 -1
  352. package/dist/trigger-secrets-shown.js +5 -1
  353. package/dist/trigger-targets.d.ts +13 -1
  354. package/dist/trigger-targets.js +31 -1
  355. package/dist/triggers.d.ts +2 -2
  356. package/dist/triggers.js +3 -3
  357. package/dist/turn-end.d.ts +1 -1
  358. package/dist/turn-end.js +1 -1
  359. package/dist/turns.d.ts +0 -6
  360. package/dist/turns.js +0 -19
  361. package/dist/uploads.js +1 -1
  362. package/dist/usage.d.ts +0 -2
  363. package/dist/usage.js +0 -2
  364. package/dist/validate.d.ts +2 -0
  365. package/dist/validate.js +23 -14
  366. package/dist/webhooks.d.ts +102 -76
  367. package/dist/webhooks.js +266 -233
  368. package/dist/workflow-run.d.ts +114 -0
  369. package/dist/workflow-run.js +144 -0
  370. package/dist/workspace/beneath.d.ts +19 -0
  371. package/dist/workspace/beneath.js +106 -0
  372. package/dist/workspace/computer-deps.d.ts +52 -5
  373. package/dist/workspace/computer-deps.js +154 -19
  374. package/dist/workspace/computer-for-claim.d.ts +19 -14
  375. package/dist/workspace/computer-for-claim.js +77 -16
  376. package/dist/workspace/computer-hold.d.ts +6 -1
  377. package/dist/workspace/computer-hold.js +6 -1
  378. package/dist/workspace/computer-janitor.d.ts +47 -0
  379. package/dist/workspace/computer-janitor.js +182 -0
  380. package/dist/workspace/computer-providers.d.ts +6 -2
  381. package/dist/workspace/computer-providers.js +1 -1
  382. package/dist/workspace/grep-worker.d.ts +5 -0
  383. package/dist/workspace/grep-worker.js +9 -6
  384. package/dist/workspace/index.d.ts +4 -3
  385. package/dist/workspace/index.js +4 -4
  386. package/dist/workspace/local.d.ts +11 -2
  387. package/dist/workspace/local.js +161 -43
  388. package/dist/workspace/resolve-computer.d.ts +50 -10
  389. package/dist/workspace/resolve-computer.js +46 -11
  390. package/dist/workspace/run-tools.d.ts +13 -31
  391. package/dist/workspace/run-tools.js +10 -27
  392. package/dist/workspace-paths.d.ts +0 -17
  393. package/dist/workspace-paths.js +1 -41
  394. package/dist/workspace.d.ts +0 -17
  395. package/dist/workspace.js +3 -99
  396. package/launcher/agentrun-serve +6 -33
  397. package/package.json +14 -14
  398. package/templates/README.md +9 -3
  399. package/templates/inbound-lead/agent.md +1 -1
  400. package/templates/kyb/agent.md +1 -1
  401. package/templates/market-monitor/agent.md +2 -2
  402. package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
  403. package/dist/app.d.ts +0 -5
  404. package/dist/app.js +0 -514
  405. package/dist/bound-files.d.ts +0 -4
  406. package/dist/bound-files.js +0 -164
  407. package/dist/bounds.d.ts +0 -26
  408. package/dist/bounds.js +0 -137
  409. package/dist/coding-tools.d.ts +0 -47
  410. package/dist/coding-tools.js +0 -189
  411. package/dist/computer-adb.d.ts +0 -12
  412. package/dist/computer-adb.js +0 -14
  413. package/dist/console/assets/index-35-7aeIZ.js +0 -519
  414. package/dist/console/assets/index-Cejbov-Y.css +0 -1
  415. package/dist/content-filter.d.ts +0 -7
  416. package/dist/content-filter.js +0 -23
  417. package/dist/disk.d.ts +0 -33
  418. package/dist/disk.js +0 -85
  419. package/dist/door-line.d.ts +0 -23
  420. package/dist/door-line.js +0 -83
  421. package/dist/grade.d.ts +0 -63
  422. package/dist/grade.js +0 -150
  423. package/dist/harness-app.d.ts +0 -69
  424. package/dist/harness-app.js +0 -1162
  425. package/dist/mcp-servers.d.ts +0 -269
  426. package/dist/mcp-servers.js +0 -456
  427. package/dist/packs.d.ts +0 -71
  428. package/dist/packs.js +0 -180
  429. package/dist/request-start.d.ts +0 -27
  430. package/dist/request-start.js +0 -381
  431. package/dist/run-box.d.ts +0 -205
  432. package/dist/run-box.js +0 -661
  433. package/dist/run-holder.d.ts +0 -52
  434. package/dist/run-holder.js +0 -139
  435. package/dist/runs.d.ts +0 -1200
  436. package/dist/runs.js +0 -4103
  437. package/dist/sealed-settings.d.ts +0 -60
  438. package/dist/sealed-settings.js +0 -178
  439. package/dist/served-only.d.ts +0 -5
  440. package/dist/served-only.js +0 -12
  441. package/dist/sessions.d.ts +0 -6
  442. package/dist/sessions.js +0 -109
  443. package/dist/workspace/computer-serves.d.ts +0 -12
  444. package/dist/workspace/computer-serves.js +0 -15
@@ -5,16 +5,14 @@
5
5
  // echoes it back. One read of the store across all its planes (store.sealedSecrets): tool, model, computer and Archil keys
6
6
  // (sealed_keys); MCP credentials, their headers' values and OAuth tokens and client secret (mcp_servers), and a sign-in in
7
7
  // flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
8
- // and webhook secret among them (trigger_settings), but a field its source marks public; browser sign-in pointers, live
9
- // and forgotten; live viewer tokens; a launch's sealed part. Beside the store, what the data directory keeps sealed where
10
- // the runner shares it (the server's own list, server-secrets.ts openServerSecrets: the outbound webhook's signing secret,
11
- // the trigger settings files of a server that keeps them there). Each value in every spelling the server's list has
8
+ // and webhook secret among them, and the outbound webhook's signing secret (trigger_settings), but a field its source marks public; browser sign-in pointers, live
9
+ // and forgotten; live viewer tokens; a launch's sealed part. Beside the store, what the data directory keeps where the
10
+ // runner shares it (server-secrets.ts besideTheStore: the owner's API token and the sign-in session secret). Each value in every spelling the server's list has
12
11
  // (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
13
12
  // is left out: the store never holds one in the clear, and nothing of this runner can be handed it.
14
- import { unseal } from "@parcha/pi-durable-agent";
15
- import { openServerSecrets, ServerSecrets } from "../server-secrets.js";
13
+ import { unseal } from "../sealing.js";
14
+ import { besideTheStore, ServerSecrets } from "../server-secrets.js";
16
15
  import { TRIGGER_ADAPTERS } from "../trigger-adapters.js";
17
- import { SEAL_KEY_ENV } from "../tool-keys.js";
18
16
  /** The keys of a sealed JSON value that hold secrets: OAuth tokens, a client's secret, a PKCE verifier. */
19
17
  const JSON_SECRETS = ["access_token", "refresh_token", "id_token", "client_secret", "verifier"];
20
18
  /** The secret strings of an opened JSON value: each header's value (a bearer's token alone too), and every string under
@@ -52,7 +50,7 @@ function jsonSecrets(text) {
52
50
  walk(value);
53
51
  return out;
54
52
  }
55
- /** A PEM key whole, and each of its base64 lines (the short last one too), as the server lists one (sealed-settings.ts). */
53
+ /** A PEM key whole, and each of its base64 lines (the short last one too), as the server lists one (sealed-settings-store.ts). */
56
54
  const pemForms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("-----"))];
57
55
  /** What of one opened sealed value is a secret to hold, by its plane: `listed` with the server list's floor and spellings,
58
56
  * `whole` as it is (a PEM key's lines). */
@@ -74,10 +72,8 @@ function secretsOf(row, plain, adapters) {
74
72
  }
75
73
  }
76
74
  /** Every secret the server keeps sealed that `sealKey` opens: the store's (one read across its planes) and, where the runner
77
- * shares the server's data directory `data`, what it keeps sealed beside the store. None without a key. */
75
+ * shares the server's data directory `data`, what it keeps beside the store. */
78
76
  export async function storeSecrets(store, sealKey, data, adapters = TRIGGER_ADAPTERS) {
79
- if (!sealKey)
80
- return [];
81
77
  const listed = [];
82
78
  const whole = [];
83
79
  for (const row of await store.sealedSecrets.all()) {
@@ -95,7 +91,7 @@ export async function storeSecrets(store, sealKey, data, adapters = TRIGGER_ADAP
95
91
  const list = new ServerSecrets();
96
92
  list.add("store", () => listed);
97
93
  list.add("store-whole", () => whole, { whole: true });
98
- const beside = data ? openServerSecrets(data, { [SEAL_KEY_ENV]: sealKey.toString("base64") }, adapters).secrets.values() : [];
94
+ const beside = data ? besideTheStore(data).values() : [];
99
95
  return [...list.values(), ...beside];
100
96
  }
101
97
  /** The server's sealed secrets (storeSecrets) held by `redact`, the run's one redactor, before any of the run's text is
@@ -0,0 +1,44 @@
1
+ type Tool = {
2
+ name: string;
3
+ description?: string;
4
+ parameters?: unknown;
5
+ };
6
+ type Part = {
7
+ type: string;
8
+ text?: string;
9
+ id?: string;
10
+ name?: string;
11
+ arguments?: unknown;
12
+ data?: string;
13
+ mimeType?: string;
14
+ };
15
+ type Message = {
16
+ role: string;
17
+ content: Part[] | string;
18
+ toolCallId?: string;
19
+ toolName?: string;
20
+ isError?: boolean;
21
+ timestamp?: number;
22
+ [key: string]: unknown;
23
+ };
24
+ /** A pi-ai context, as far as tools as text reads and writes it. */
25
+ export type PiContext = {
26
+ systemPrompt?: string;
27
+ messages: Message[];
28
+ tools?: Tool[];
29
+ };
30
+ /** The system prompt's tools section, in DeepSeek V3.2's own words: how to call, then each tool's schema. */
31
+ export declare function toolsSection(tools: readonly Tool[]): string;
32
+ /** `context` with its tools in its system prompt and every tool call and result in its history written as text. */
33
+ export declare function toolsAsText(context: PiContext): PiContext;
34
+ /** A reply's text read as text and calls: each `<tool_call>` block whose JSON names a tool, in order; the rest is
35
+ * text. A block whose JSON does not parse stays text. */
36
+ export declare function callsOfText(said: string, tools?: readonly Tool[]): {
37
+ text: string;
38
+ calls: {
39
+ name: string;
40
+ arguments: Record<string, unknown>;
41
+ }[];
42
+ broken?: boolean;
43
+ };
44
+ export {};
@@ -0,0 +1,237 @@
1
+ // Tools as text, for a model whose provider caches no prefix of a request that carries a `tools` parameter (a catalog
2
+ // entry's 'toolsAs: "text"', local-models.ts; the translated route, model-route.ts, reads it). Measured
3
+ // 2026-11-11 on OpenRouter's particle-1 (one provider, Particle AI): the same request with `tools` renders to a prompt
4
+ // whose token count varies by request (58,791 vs 58,793) and is cached 0-30% of the time; with its tools described in
5
+ // the system prompt and its calls and results written as text it is cached whole from the second send on (57,088 of
6
+ // 57,188 tokens). A tool-using review sends its whole history every turn, so that is the difference between paying
7
+ // $0.25/M (list) and $0.03/M for nearly all of its input. The text protocol is DeepSeek's DSML without its marker
8
+ // ("<function_calls><invoke name><parameter name string>"), the shape particle-1 writes on its own when given tools as
9
+ // text (DeepSeek V3.2's chat template words it so; the provider drops or breaks the `|DSML|` marker in what it streams);
10
+ // a reply with the marker, or a `<tool_call>{json}</tool_call>` block, is read too. Calls and results are rebuilt from
11
+ // history the same way every turn, so each request's prefix is byte for byte the last one's.
12
+ const OPEN = "<tool_call>";
13
+ const CLOSE = "</tool_call>";
14
+ /** The system prompt's tools section, in DeepSeek V3.2's own words: how to call, then each tool's schema. */
15
+ export function toolsSection(tools) {
16
+ return [
17
+ "## Tools",
18
+ "You have access to a set of tools you can use to answer the user's question.",
19
+ 'You can invoke functions by writing a "<function_calls>" block like the following as part of your reply to the user:',
20
+ "<function_calls>",
21
+ '<invoke name="$FUNCTION_NAME">',
22
+ '<parameter name="$PARAMETER_NAME" string="true|false">$PARAMETER_VALUE</parameter>',
23
+ "...",
24
+ "</invoke>",
25
+ '<invoke name="$FUNCTION_NAME2">',
26
+ "...",
27
+ "</invoke>",
28
+ "</function_calls>",
29
+ "",
30
+ 'String and scalar parameters should be specified as is without any escaping or quotes, while lists and objects should use JSON format. The "string" attribute should be set to "true" for string type parameters and "false" for other types (numbers, booleans, arrays, objects).',
31
+ "Several invokes in one block run together, in order. Write nothing after the block; the results come back to you in a <function_results> block. A reply with no block is your final answer.",
32
+ "",
33
+ "### Available Tool Schemas",
34
+ "",
35
+ "<functions>",
36
+ ...tools.map((tool) => JSON.stringify({ name: tool.name, description: (tool.description ?? "").trim(), parameters: tool.parameters ?? { type: "object", properties: {} } })),
37
+ "</functions>",
38
+ "",
39
+ "You MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.",
40
+ ].join("\n");
41
+ }
42
+ /** One call as a DSML invoke, as `toolsSection` asks for it. */
43
+ const invokeOf = (name, args) => {
44
+ const params = Object.entries((args && typeof args === "object" ? args : {})).map(([key, value]) => `<parameter name="${key}" string="${typeof value === "string"}">${typeof value === "string" ? value : JSON.stringify(value)}</parameter>`);
45
+ return [`<invoke name="${name}">`, ...params, "</invoke>"].join("\n");
46
+ };
47
+ /** `context` with its tools in its system prompt and every tool call and result in its history written as text. */
48
+ export function toolsAsText(context) {
49
+ const tools = context.tools ?? [];
50
+ const messages = [];
51
+ for (const message of context.messages) {
52
+ if (message.role === "assistant" && Array.isArray(message.content)) {
53
+ const said = message.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("").trim();
54
+ const calls = message.content.filter((part) => part.type === "toolCall").map((part) => invokeOf(part.name ?? "", part.arguments));
55
+ const text = [said, calls.length ? ["<function_calls>", ...calls, "</function_calls>"].join("\n") : ""].filter(Boolean).join("\n\n");
56
+ messages.push({ ...message, content: [{ type: "text", text: text || "(no text)" }] });
57
+ continue;
58
+ }
59
+ if (message.role === "toolResult") {
60
+ const parts = Array.isArray(message.content) ? message.content : [{ type: "text", text: String(message.content) }];
61
+ const body = parts.filter((part) => part.type === "text").map((part) => part.text ?? "").join("\n");
62
+ const images = parts.filter((part) => part.type === "image");
63
+ const text = `<result tool="${message.toolName ?? ""}"${message.isError ? ' error="true"' : ""}>\n${body}\n</result>`;
64
+ // Results of one turn's calls go together, as one user message, in the order called.
65
+ const last = messages[messages.length - 1];
66
+ if (last?.role === "user" && last.fromTools === true && Array.isArray(last.content))
67
+ last.content.push({ type: "text", text: `\n${text}` }, ...images);
68
+ else
69
+ messages.push({ role: "user", content: [{ type: "text", text: `<function_results>\n${text}` }, ...images], timestamp: message.timestamp, fromTools: true });
70
+ continue;
71
+ }
72
+ messages.push(message);
73
+ }
74
+ for (const message of messages) {
75
+ if (message.fromTools === true && Array.isArray(message.content))
76
+ message.content.push({ type: "text", text: "\n</function_results>" });
77
+ delete message.fromTools;
78
+ }
79
+ const system = [context.systemPrompt ?? "", tools.length ? toolsSection(tools) : ""].filter(Boolean).join("\n\n");
80
+ return { ...(system ? { systemPrompt: system } : {}), messages };
81
+ }
82
+ /** A reply's text read as text and calls: each `<tool_call>` block whose JSON names a tool, in order; the rest is
83
+ * text. A block whose JSON does not parse stays text. */
84
+ export function callsOfText(said, tools = []) {
85
+ const calls = [];
86
+ // DSML with its marker or without (the provider may drop it, or put zero-width spaces in its tags), as the model
87
+ // writes it: `<function_calls>` (or "<calls>"), each `<invoke name="...">` with `<parameter name="..." string="...">`
88
+ // values, or `<invoke name="...", "arguments": {...}}`. The slips particle-1 makes are read too: the tool named by a
89
+ // '<parameter name="invoke">', a `<name>value</parameter>` parameter, and an invoke with no name (the one tool whose
90
+ // schema takes every parameter given and all its required ones).
91
+ const text = said.replace(/\u200b/g, "").replace(/|DSML|\s*/g, "");
92
+ const first = text.search(/<(?:function_calls|calls|invoke\b|parameter\b)/);
93
+ const groups = [];
94
+ const current = () => groups[groups.length - 1] ?? (groups.push({ args: {} }), groups[0]);
95
+ // A string is written unescaped, so a value may hold "</parameter>" itself (a file that writes this protocol, an
96
+ // example in a comment): a value ends at the closing tag that the call's next tag, or the reply's end, follows.
97
+ const token = /<invoke\s+name="([^"]+)"(\s*,\s*"arguments"\s*:\s*)?|<\/invoke>|<parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*?)<\/(?:parameter|invoke)>(?=\s*(?:<parameter\s+name=|<\/?invoke\b|<\/function_calls>|<\/calls>|<[A-Za-z_][\w-]*>[^<]*<\/parameter>|$))|<([A-Za-z_][\w-]*)>([^<]*)<\/parameter>/g;
98
+ const block = first < 0 ? "" : text.slice(first);
99
+ let closed = false;
100
+ // A call the reply did not finish (cut off, or a tag opened and never closed) is never run on what it holds so far:
101
+ // the reply is broken, and asked again.
102
+ let unfinished = false;
103
+ let end = 0;
104
+ for (const match of block.matchAll(token)) {
105
+ const [whole, invoked, jsonArgs, key, isString, value, slipKey, slipValue] = match;
106
+ if (/<(?:invoke|parameter)\b/.test(block.slice(end, match.index)))
107
+ unfinished = true;
108
+ end = match.index + whole.length;
109
+ if (invoked !== undefined) {
110
+ groups.push({ name: invoked, args: {} });
111
+ closed = false;
112
+ if (jsonArgs) {
113
+ const object = objectAt(block, end);
114
+ if (object === undefined)
115
+ unfinished = true;
116
+ else {
117
+ end += object.length;
118
+ try {
119
+ Object.assign(groups[groups.length - 1].args, JSON.parse(object));
120
+ }
121
+ catch {
122
+ unfinished = true;
123
+ }
124
+ }
125
+ }
126
+ }
127
+ else if (whole === "</invoke>")
128
+ closed = true;
129
+ else if (key === "invoke" && value.includes("<parameter")) {
130
+ // `<parameter name="invoke">` opening a call whose name never came: its first parameter is inside.
131
+ groups.push({ args: {} });
132
+ closed = false;
133
+ const inner = /<parameter\s+name="([^"]+)"(?:\s+string="(true|false)")?\s*>([\s\S]*)$/.exec(value);
134
+ if (inner)
135
+ current().args[inner[1]] = valueOf(inner[3], inner[2]);
136
+ }
137
+ else if (key === "invoke" || key === "name" && current().name === undefined && tools.some((tool) => tool.name === value)) {
138
+ groups.push({ name: value.trim(), args: {} });
139
+ closed = false;
140
+ }
141
+ else if (key !== undefined) {
142
+ if (closed)
143
+ groups.push({ args: {} });
144
+ closed = false;
145
+ current().args[key] = valueOf(value, isString);
146
+ }
147
+ else if (slipKey !== undefined && !["function_calls", "calls", "invoke", "parameter"].includes(slipKey) && !(slipKey in current().args))
148
+ current().args[slipKey] = valueOf(slipValue, undefined);
149
+ }
150
+ if (first >= 0 && /<(?:invoke|parameter)\b/.test(block.slice(end)))
151
+ unfinished = true;
152
+ if (unfinished)
153
+ return { text: text.trim(), calls: [], broken: true };
154
+ for (const group of groups) {
155
+ const name = group.name ?? nameOf(group.args, tools);
156
+ if (name !== undefined)
157
+ calls.push({ name, arguments: group.args });
158
+ }
159
+ if (calls.length)
160
+ return { text: text.slice(0, first).trim(), calls };
161
+ if (first >= 0 && /<(?:function_calls|calls|invoke|parameter)\b/.test(text))
162
+ return { text: text.trim(), calls, broken: true };
163
+ // A `<tool_call>{"name": ..., "arguments": ...}</tool_call>` block.
164
+ let rest = "";
165
+ let at = 0;
166
+ for (;;) {
167
+ const open = text.indexOf(OPEN, at);
168
+ if (open < 0)
169
+ break;
170
+ const close = text.indexOf(CLOSE, open + OPEN.length);
171
+ const raw = text.slice(open + OPEN.length, close < 0 ? undefined : close).trim();
172
+ let call;
173
+ try {
174
+ call = JSON.parse(raw);
175
+ }
176
+ catch {
177
+ call = undefined;
178
+ }
179
+ rest += text.slice(at, open);
180
+ if (call && typeof call.name === "string") {
181
+ const args = typeof call.arguments === "string" ? valueOf(call.arguments, "false") : call.arguments;
182
+ calls.push({ name: call.name, arguments: (args && typeof args === "object" && !Array.isArray(args) ? args : {}) });
183
+ }
184
+ else
185
+ rest += text.slice(open, close < 0 ? undefined : close + CLOSE.length);
186
+ if (close < 0) {
187
+ at = text.length;
188
+ break;
189
+ }
190
+ at = close + CLOSE.length;
191
+ }
192
+ rest += text.slice(at);
193
+ return { text: rest.trim(), calls };
194
+ }
195
+ /** The one tool whose schema takes every argument given and all its required ones, or undefined. */
196
+ function nameOf(args, tools) {
197
+ const keys = Object.keys(args);
198
+ if (!keys.length)
199
+ return undefined;
200
+ const fits = tools.filter((tool) => {
201
+ const schema = (tool.parameters ?? {});
202
+ const known = Object.keys(schema.properties ?? {});
203
+ const props = (schema.properties ?? {});
204
+ return keys.every((key) => known.includes(key) && (!props[key]?.enum || props[key].enum.includes(args[key]))) && (schema.required ?? []).every((key) => keys.includes(key));
205
+ });
206
+ return fits.length === 1 ? fits[0].name : undefined;
207
+ }
208
+ /** A parameter's value: as written when it is a string, else its JSON (a number, a list, an object), else as written. */
209
+ function valueOf(value, isString) {
210
+ if (isString === "true")
211
+ return value;
212
+ try {
213
+ return JSON.parse(value.trim());
214
+ }
215
+ catch {
216
+ return value;
217
+ }
218
+ }
219
+ /** The JSON object that starts at `at` in `text` (its braces matched, strings skipped), or undefined. */
220
+ function objectAt(text, at) {
221
+ if (text[at] !== "{")
222
+ return undefined;
223
+ let depth = 0;
224
+ for (let i = at; i < text.length; i++) {
225
+ const c = text[i];
226
+ if (c === '"') {
227
+ for (i++; i < text.length && text[i] !== '"'; i++)
228
+ if (text[i] === "\\")
229
+ i++;
230
+ }
231
+ else if (c === "{")
232
+ depth++;
233
+ else if (c === "}" && --depth === 0)
234
+ return text.slice(at, i + 1);
235
+ }
236
+ return undefined;
237
+ }
@@ -94,6 +94,12 @@ export interface WorkflowRunSpec {
94
94
  * once, however the run ended (ended, stopped, failed, parked or interrupted), so a parked or resumed run starts fresh
95
95
  * proxies on its next claim. Never throws out. Absent: nothing to let go. */
96
96
  readonly release?: () => Promise<void>;
97
+ /** Resolves once every model request the spec admitted has been booked, or a bound has passed (then a request left
98
+ * unbooked reads at its hold and bound). A request its node let go of (a stop) is booked only once the provider's side
99
+ * ends, which can be after the node ended: once the workflow's task is over, the loop waits for this before it closes
100
+ * the Harness the bookings are written through. Not on a park or a lost claim: the next claim books a request left
101
+ * open there as cut. Absent: nothing to wait for. */
102
+ readonly settle?: () => Promise<void>;
97
103
  }
98
104
  /** What the interpreter's host may ask of the loop while it runs. */
99
105
  export interface WorkflowHostHooks {
@@ -1,6 +1,6 @@
1
1
  // The workflow loop on the runner (design: "Runners carry many loops"; the lead's ruling, workflow agents keep running
2
2
  // after the cutover). A run of a workflow revision, which the runner claims like any run: this loop is its driver, so the
3
- // claim, the fence, a cancel and the end commit are its. The DSL's durable runner (pi-durable-agent/workflow
3
+ // claim, the fence, a cancel and the end commit are its. The DSL's durable runner (workflow-run.ts
4
4
  // startWorkflowRevision over agentrun-pi's workflow task) runs the revision's workflow UNCHANGED — the same nodes,
5
5
  // decisions, call tools and cap it ran with in the per-run process — on the run's journal in the one store (A,
6
6
  // deps.journal(claim)) in place of a per-run store file. The interpreter's host (model nodes on the run's models, call
@@ -20,7 +20,7 @@
20
20
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
21
21
  import { createRegistry, Harness, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
22
22
  import { createWorkflowExtension } from "@parcha/agentrun-pi/durable";
23
- import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "@parcha/pi-durable-agent/workflow";
23
+ import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
24
24
  import { KINDS } from "./journal-kinds.js";
25
25
  import { endedBy } from "./loop-contract.js";
26
26
  /** The most the end's patch (cost and metrics) may take before the end is written without it (the pi loop's CUT_STEP_MS). */
@@ -263,8 +263,10 @@ function workflowLoop(specOf, deps) {
263
263
  void error;
264
264
  return { state: "interrupted" };
265
265
  }
266
- // The task is terminal. Close the Harness, then read the run's view from its journal and write the end, both on a
267
- // fresh journal of the same claim (the Harness closed its own).
266
+ // The task is terminal. Its model requests booked (a stopped one books once its provider's side ends, after the node
267
+ // let go of it), close the Harness, then read the run's view from its journal and write the end, both on a fresh
268
+ // journal of the same claim (the Harness closed its own).
269
+ await spec.settle?.().catch(() => undefined);
268
270
  await closeHarness();
269
271
  const endJournal = deps.journal(claim);
270
272
  // A person stopped or cancelled: the run ends stopped whatever the workflow's own outcome (its last node may have
@@ -4,6 +4,7 @@ import { type BeforeRequest, type Wire } from "@parcha/agentrun-kernel";
4
4
  import { type ProviderPolicy, type ProxyUsage } from "@parcha/agentrun-kernel/host";
5
5
  import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
6
6
  import { type Tier } from "../model.js";
7
+ import { deniedText } from "../refusal-words.js";
7
8
  import { type PaidBooking } from "../paid-calls.js";
8
9
  import { type RunTools } from "@parcha/agentrun-kernel/kernel/cap";
9
10
  import { type ModelRoute } from "./model-route.js";
@@ -138,6 +139,16 @@ export declare const heldBooking: () => {
138
139
  readonly paid: PaidBooking;
139
140
  } | undefined;
140
141
  export declare const releaseCallHold: () => Promise<void>;
142
+ /** A call tool's permission now, as main's per-run process read it at each call node (app.ts:382-384, the gate's
143
+ * policy): the revision's tool settings and approvals over the server's, the server's read again from the store at each
144
+ * call, so a deny or an ask set while the run goes reaches its next call. A read that fails is unread, as the agentic
145
+ * gate's is (adapter-run-spec.ts storeSettings): with no good read before it every tool asks, so a call node is refused
146
+ * (the revision's own allow never stands alone over settings no read has seen); after one, the gate holds to that read
147
+ * marked unread (RunGate.serverSettings), so its denies still refuse. */
148
+ type CallPolicy = (tool: string) => Promise<{
149
+ permission: "allow" | "ask" | "deny";
150
+ denyFrom: Parameters<typeof deniedText>[2];
151
+ }>;
141
152
  /** `cap` with a call node's recorded tool failure thrown as the node's failure, as main's `failing` (app.ts:417-420):
142
153
  * the driver records the effect's outcome ({ TOOL_FAILED: words }) as its receipt, and this, past the driver, throws it
143
154
  * as an EffectFailure in those words, so the call node fails and the run with it in the tool's words. Applied outside
@@ -151,6 +162,13 @@ export declare const RUNNER_NODE_TOOLS: readonly string[];
151
162
  /** A node naming a tool the runner does not bind for a model node yet: the run is refused at its claim in these words,
152
163
  * the tool never offered and never silently dropped. */
153
164
  export declare const nodeToolUnboundText: (tool: string) => string;
165
+ /** A model node's tool call as its pi-durable task runs it: its args, the task's api and the call's context. */
166
+ type GatedExecute = (args: never, api: never, context: never) => Promise<unknown>;
167
+ /** `execute` behind the gate, for the tool `name`. A call it lets through is marked so in its task first, so when
168
+ * pi-durable's recovery runs the same call again on a later claim (the first attempt cut with its claim, maybe after it
169
+ * was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
170
+ * (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
171
+ export declare function gatedNodeCall(name: string, policy: CallPolicy, execute: GatedExecute): GatedExecute;
154
172
  /** The tool names a workflow's model node offers its model: the node's `submit` (pi's SUBMIT_TOOL) and every tool the
155
173
  * workflow's model nodes name. */
156
174
  export declare function nodeOffer(workflow: Workflow): string[];
@@ -28,18 +28,19 @@ import { forModel } from "../result.js";
28
28
  import { WEB_FETCH_TOOL } from "../web-fetch.js";
29
29
  import { runGate } from "../tool-gate.js";
30
30
  import { callNodeAskText, deniedText, modelNodeAskText } from "../refusal-words.js";
31
- import { loadToolSettings, planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
31
+ import { planeOf, TOOL_PLANE_ENV } from "../tool-plane.js";
32
32
  import { AsyncLocalStorage } from "node:async_hooks";
33
33
  import { bookedIn, parallelExtractFee, parallelSearchFee } from "../paid-calls.js";
34
34
  import { searchArgs, WEB_SEARCH_TOOL } from "../web-search.js";
35
35
  import { money, pricingOf, requestPrice, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/cap";
36
36
  import { claimSecrets, withModelKeys } from "./claim-secrets.js";
37
37
  import { routeOf } from "./model-route.js";
38
- import { PI_WIRES } from "./adapter-run-spec.js";
38
+ 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, WORKFLOW_SESSION } from "./journal-kinds.js";
43
+ import { CLOSE_MS } from "./loop.js";
43
44
  import { PAUSED_WORDS } from "./workflow-loop.js";
44
45
  import { heldRedactor, holdClaimed } from "./redact.js";
45
46
  import { holdStored } from "./store-secrets.js";
@@ -49,7 +50,7 @@ import { workflowHost } from "./workflow-host.js";
49
50
  * does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
50
51
  export const SUBMIT_TOOL = "submit";
51
52
  /** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
52
- const SESSION = "workflow";
53
+ const SESSION = WORKFLOW_SESSION;
53
54
  /** A call node's tool failure and a cap-held effect, as app.ts's runEffect completed them (the loop's `failing` reads them). */
54
55
  const TOOL_FAILED = "agentrun_serve_tool_failed";
55
56
  const CAP_HELD = "agentrun_serve_cap_held";
@@ -143,7 +144,7 @@ export function workflowSpecOf(deps) {
143
144
  if (unbound !== undefined)
144
145
  throw new Error(nodeToolUnboundText(unbound));
145
146
  // Every secret the server keeps sealed (store-secrets.ts) held by the runner's one redactor before the workflow runs.
146
- if (run?.redact)
147
+ if (run?.redact && deps.sealKey)
147
148
  await holdStored(heldRedactor(run.redact), deps.store, deps.sealKey, deps.data);
148
149
  const tiers = tiersOf(claimed.workflow);
149
150
  // The run's own keys, as the server's runnable check reads them: each by its name from the runner's environment first,
@@ -218,12 +219,10 @@ export function workflowSpecOf(deps) {
218
219
  const nodeHost = {
219
220
  where: { root: claimed.workRoot, work: claimed.workRoot, ref: { id: claim.runId } },
220
221
  env: callEnv,
221
- coding: { tools: [], extension: { name: "coding", tools: [] } },
222
222
  install: (extension) => void installed.push(extension),
223
223
  onConversation: () => { },
224
224
  beforeResume: () => { },
225
225
  beforeRelease: () => { },
226
- handoverInJournal: true,
227
226
  };
228
227
  const nodeBindings = await bindNodeTools(nodeNames, nodeHost);
229
228
  // Each node tool as the node gets it and the registry holds it: booked on the run's one ledger (bookedNodeTools), in an
@@ -307,6 +306,12 @@ export function workflowSpecOf(deps) {
307
306
  paidTools = await run.tools(await sessions.open(TOOL_SESSION), { flush: () => deps.store.flush() });
308
307
  hooks.setPort(booking.models);
309
308
  },
309
+ settle: async () => {
310
+ const left = await hooks.bookingsSettled();
311
+ // Past the bound: the end is written, and each request still unbooked counts at its hold and bound (never less).
312
+ if (left > 0)
313
+ 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`);
314
+ },
310
315
  release: async () => {
311
316
  for (const proxy of proxies)
312
317
  await proxy.close().catch(() => undefined);
@@ -372,18 +377,46 @@ export function pauseAtEffects(cap, hooks, flight) {
372
377
  }
373
378
  /** The proxies start before the booking is wired; their hooks forward to the booking set at harnessReady. A request before
374
379
  * 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. */
380
+ * set at build, which a cap refusal calls. Each request admitted is counted until it is booked: a request a person's
381
+ * stop cut short is booked only once its proxy sees the provider's side end, which can be after its node ended, and the
382
+ * run's end waits for it (bookingsSettled), as the pi adapter's loop does. */
376
383
  function deferredHooks() {
377
384
  let port;
378
385
  let loop;
386
+ let unbooked = 0;
387
+ const bookedAll = [];
379
388
  return {
380
389
  port: {
381
- beforeRequest: (request) => (port ?? missing()).beforeRequest(request),
382
- afterRequest: (usage, ticket, ended) => (port ?? missing()).afterRequest(usage, ticket, ended),
390
+ beforeRequest: async (request) => {
391
+ const ticket = await (port ?? missing()).beforeRequest(request);
392
+ unbooked += 1;
393
+ return ticket;
394
+ },
395
+ afterRequest: async (usage, ticket, ended) => {
396
+ try {
397
+ await (port ?? missing()).afterRequest(usage, ticket, ended);
398
+ }
399
+ finally {
400
+ unbooked = Math.max(0, unbooked - 1);
401
+ if (unbooked === 0)
402
+ for (const wake of bookedAll.splice(0))
403
+ wake();
404
+ }
405
+ },
383
406
  responded: (ids, ticket) => (port ?? missing()).responded?.(ids, ticket) ?? Promise.resolve(),
384
407
  note: (model, request) => (port ?? missing()).note?.(model, request),
385
408
  },
386
409
  setPort: (p) => { port = p; },
410
+ /** Waits, at most CLOSE_MS, until every request admitted is booked, and says how many are still not. Past the bound
411
+ * the run's end is written anyway, and a request left unbooked reads at its hold and bound, the worst it can have cost. */
412
+ bookingsSettled: async () => {
413
+ if (unbooked === 0)
414
+ return 0;
415
+ let timer;
416
+ await Promise.race([new Promise((resolve) => bookedAll.push(resolve)), new Promise((resolve) => (timer = setTimeout(resolve, CLOSE_MS)))]);
417
+ clearTimeout(timer);
418
+ return unbooked;
419
+ },
387
420
  park: (refusal) => loop?.park(refusal),
388
421
  // A person's pause, asked where the cap is (the loop's hooks): none before the loop hands its hooks over.
389
422
  paused: () => loop?.paused() ?? false,
@@ -529,16 +562,12 @@ export const releaseCallHold = async () => {
529
562
  await giveBack(held);
530
563
  };
531
564
  function callPolicyOf(store, runId, claimed) {
532
- let current = { settings: {}, problems: [] };
565
+ // Nothing read yet: unread, so a policy asked before the first read fails closed too.
566
+ let current = { settings: {}, problems: [], unreadable: true };
533
567
  // Only the permission is read here: a workflow never parks, so whether anyone can answer an ask plays no part.
534
- const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, undefined, true);
568
+ const gate = runGate({ root: claimed.workRoot, work: claimed.workRoot }, runId, claimed.revision, () => current, true);
535
569
  return async (tool) => {
536
- try {
537
- current = await loadToolSettings(store);
538
- }
539
- catch {
540
- // Unread: the gate holds to its last good read.
541
- }
570
+ current = await storeSettings(store);
542
571
  return { permission: gate.policy(tool), denyFrom: gate.denyFrom(tool) };
543
572
  };
544
573
  }
@@ -745,17 +774,30 @@ function nodeToolGate(names, policy) {
745
774
  name: "tool-gate",
746
775
  wraps: [...names].map((name) => wrapTool({ name }, (inner) => ({
747
776
  ...inner,
748
- async execute(args, api, context) {
749
- const { permission, denyFrom } = await policy(inner.name);
750
- if (permission === "deny")
751
- return forModel(deniedText(inner.name, undefined, denyFrom), { isError: true });
752
- if (permission === "ask")
753
- return forModel(modelNodeAskText(inner.name), { isError: true });
754
- return inner.execute(args, api, context);
755
- },
777
+ execute: gatedNodeCall(inner.name, policy, inner.execute),
756
778
  }))),
757
779
  });
758
780
  }
781
+ /** The task memo the gate keeps that it let a call through, before the call runs. */
782
+ const LET_THROUGH = "agentrun.gate.let-through";
783
+ /** `execute` behind the gate, for the tool `name`. A call it lets through is marked so in its task first, so when
784
+ * pi-durable's recovery runs the same call again on a later claim (the first attempt cut with its claim, maybe after it
785
+ * was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
786
+ * (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
787
+ export function gatedNodeCall(name, policy, execute) {
788
+ return async (args, api, context) => {
789
+ const task = api;
790
+ const { permission, denyFrom } = await policy(name);
791
+ if (permission !== "allow") {
792
+ // A call an earlier attempt of which this gate let through may have reached its host: whatever refuses it now, its
793
+ // effect is not known, never "not run".
794
+ const ran = (await task.memo(LET_THROUGH, context)) === true ? "unknown" : "no";
795
+ return forModel(permission === "deny" ? deniedText(name, undefined, denyFrom, ran) : modelNodeAskText(name, ran), { isError: true });
796
+ }
797
+ await task.memo(LET_THROUGH, true, context);
798
+ return execute(args, api, context);
799
+ };
800
+ }
759
801
  /** `binding`'s tools with each call's paid requests booked on the run's one ledger (Ledger.paid, the paid tool calls on
760
802
  * the run's cap, as an agentic run's are), a refusal for room parking the run (Ledger.pause, as main's paidCall pauses):
761
803
  * a node's tool call is the node's own turn, so the run parks and resumes it from its journal. */
@@ -1,5 +1,5 @@
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";
@@ -71,7 +71,7 @@ export type SteerCommand = {
71
71
  /** Raises the cap of an agentic or workflow run that names one, to `cap`: above its own (by more than CAP_TOLERANCE), or the
72
72
  * same as its newest raise (a retry, which changes nothing). A raise command row the run's runner reads: it resumes a run
73
73
  * paused at its cap and sends its continuation, or (for a run working now) holds the raised cap from the run's next
74
- * process, as the old path did. The answer reports whether the run resumed; the runner owns the resume itself. */
74
+ * step. The answer reports whether the run resumed; the runner owns the resume itself. */
75
75
  export declare function raiseCap(store: RunsStore, moment: RunMoment, cap: number): Promise<{
76
76
  resumed: boolean;
77
77
  messageId?: string;
@@ -128,6 +128,8 @@ export interface StartDeps {
128
128
  readonly documents?: string;
129
129
  /** What a run's box may reach, as the server resolved it, or "none". */
130
130
  readonly boxAllow?: readonly string[] | "none";
131
+ /** The operator set that (run-launch.ts boxAllowSet). */
132
+ readonly boxAllowSet?: true;
131
133
  /** The run's model, pinned at start: resolved exactly as the old per-run process resolved it from the revision and agent
132
134
  * (app.ts's runModels / wireModels over revision.body.model on its harness). The runner reads launch.model alone, so one
133
135
  * resolution happens, here. Required. */
@@ -147,6 +149,9 @@ export interface StartDeps {
147
149
  }>;
148
150
  /** The learning budget in bytes (learning.ts LEARNING_BUDGET), for which notes fit a run's # Learned section. */
149
151
  readonly learningBudget?: number;
152
+ /** The model the server names to grade what a run proposes (learning.ts gradeModelOf), put on each learning start; none,
153
+ * the agent's own grades it. */
154
+ readonly gradeModel?: string;
150
155
  /** The host's secrets as they are shown now (learning-run.ts shown), for cutting the notes a run is given. */
151
156
  shown?(): Shown;
152
157
  }