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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/CHANGELOG.md +263 -0
  2. package/README.md +339 -179
  3. package/dist/adapters.d.ts +15 -2
  4. package/dist/adapters.js +34 -2
  5. package/dist/agent-rows.d.ts +3 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +25 -5
  8. package/dist/api-only.d.ts +2 -1
  9. package/dist/api-only.js +3 -1
  10. package/dist/archil-routes.d.ts +40 -7
  11. package/dist/archil-routes.js +167 -54
  12. package/dist/archil-settings.d.ts +90 -8
  13. package/dist/archil-settings.js +150 -14
  14. package/dist/attach-images.d.ts +15 -0
  15. package/dist/attach-images.js +59 -0
  16. package/dist/background.d.ts +0 -6
  17. package/dist/background.js +0 -28
  18. package/dist/bash-read-only.d.ts +13 -0
  19. package/dist/bash-read-only.js +77 -0
  20. package/dist/box-image.d.ts +1 -97
  21. package/dist/box-image.js +4 -284
  22. package/dist/box-paths.d.ts +2 -7
  23. package/dist/box-paths.js +7 -13
  24. package/dist/box-settings.d.ts +0 -11
  25. package/dist/box-settings.js +4 -29
  26. package/dist/browser-commands.js +1 -1
  27. package/dist/browser-computer.d.ts +47 -3
  28. package/dist/browser-computer.js +286 -18
  29. package/dist/browser-cost.d.ts +2 -2
  30. package/dist/browser-cost.js +6 -4
  31. package/dist/browser-person.d.ts +19 -2
  32. package/dist/browser-person.js +55 -6
  33. package/dist/browser-wait-ended.d.ts +23 -0
  34. package/dist/browser-wait-ended.js +42 -0
  35. package/dist/cap.d.ts +19 -44
  36. package/dist/cap.js +31 -77
  37. package/dist/cli.js +36 -27
  38. package/dist/computer-keys.d.ts +20 -10
  39. package/dist/computer-keys.js +36 -57
  40. package/dist/computer-routes.d.ts +1 -4
  41. package/dist/computer-routes.js +3 -5
  42. package/dist/computer-setting.d.ts +8 -5
  43. package/dist/computer-setting.js +91 -26
  44. package/dist/computer-view.d.ts +11 -2
  45. package/dist/computer-view.js +2 -1
  46. package/dist/computers.d.ts +54 -8
  47. package/dist/computers.js +101 -22
  48. package/dist/console/assets/index-BI4Byidu.js +550 -0
  49. package/dist/console/assets/index-C19gUF2n.css +1 -0
  50. package/dist/console/index.html +2 -2
  51. package/dist/content-filter.d.ts +7 -0
  52. package/dist/content-filter.js +23 -0
  53. package/dist/decision-cap.d.ts +7 -29
  54. package/dist/decision-cap.js +3 -94
  55. package/dist/docker-daemon.d.ts +2 -2
  56. package/dist/docker-daemon.js +2 -2
  57. package/dist/errors.d.ts +1 -0
  58. package/dist/errors.js +8 -5
  59. package/dist/explain.js +3 -1
  60. package/dist/faux-computers.js +4 -0
  61. package/dist/files.d.ts +1 -9
  62. package/dist/files.js +1 -9
  63. package/dist/github-connection.js +25 -7
  64. package/dist/github-faux.d.ts +26 -0
  65. package/dist/github-faux.js +76 -0
  66. package/dist/github.d.ts +28 -4
  67. package/dist/github.js +46 -10
  68. package/dist/gpu-words.d.ts +14 -0
  69. package/dist/gpu-words.js +21 -0
  70. package/dist/graph-served.d.ts +5 -3
  71. package/dist/graph-served.js +14 -6
  72. package/dist/graph-view.d.ts +2 -0
  73. package/dist/graph-view.js +29 -2
  74. package/dist/handed-values.d.ts +1 -1
  75. package/dist/handed-values.js +1 -1
  76. package/dist/harness-install.d.ts +60 -3
  77. package/dist/harness-install.js +322 -34
  78. package/dist/harness-opencode/harness.js +0 -1
  79. package/dist/harness-opencode/host/policy.js +2 -2
  80. package/dist/harness.js +1 -1
  81. package/dist/host-tools.d.ts +8 -9
  82. package/dist/host-tools.js +7 -7
  83. package/dist/index.d.ts +2 -3
  84. package/dist/index.js +2 -2
  85. package/dist/key-refusal.d.ts +1 -1
  86. package/dist/key-refusal.js +2 -2
  87. package/dist/learn/check.d.ts +10 -2
  88. package/dist/learn/check.js +126 -8
  89. package/dist/learn/commit.d.ts +40 -6
  90. package/dist/learn/commit.js +164 -20
  91. package/dist/learn/folder.d.ts +11 -3
  92. package/dist/learn/folder.js +40 -16
  93. package/dist/learn/grade.d.ts +22 -2
  94. package/dist/learn/grade.js +127 -19
  95. package/dist/learn/index.d.ts +2 -2
  96. package/dist/learn/index.js +2 -2
  97. package/dist/learn/learning.sh +11 -13
  98. package/dist/learn/notes.d.ts +17 -3
  99. package/dist/learn/notes.js +19 -6
  100. package/dist/learn/reflect.d.ts +5 -2
  101. package/dist/learn/reflect.js +48 -32
  102. package/dist/learn/skills.d.ts +52 -5
  103. package/dist/learn/skills.js +104 -21
  104. package/dist/learned-nodes.d.ts +18 -0
  105. package/dist/learned-nodes.js +8 -0
  106. package/dist/learned-workflow.d.ts +27 -13
  107. package/dist/learned-workflow.js +110 -38
  108. package/dist/learning-cost.d.ts +79 -0
  109. package/dist/learning-cost.js +69 -0
  110. package/dist/learning-routes.d.ts +48 -2
  111. package/dist/learning-routes.js +99 -28
  112. package/dist/learning-run.d.ts +7 -5
  113. package/dist/learning-run.js +9 -6
  114. package/dist/learning-words.d.ts +3 -0
  115. package/dist/learning-words.js +6 -2
  116. package/dist/learning.d.ts +13 -28
  117. package/dist/learning.js +4 -18
  118. package/dist/llm.d.ts +4 -1
  119. package/dist/llm.js +4 -2
  120. package/dist/mcp-gateway.d.ts +6 -0
  121. package/dist/mcp-gateway.js +11 -1
  122. package/dist/mcp-probe.d.ts +8 -1
  123. package/dist/mcp-probe.js +62 -20
  124. package/dist/mcp-secret-writes.js +4 -0
  125. package/dist/mcp-servers-store.d.ts +12 -12
  126. package/dist/mcp-servers-store.js +8 -3
  127. package/dist/model.d.ts +8 -5
  128. package/dist/model.js +14 -6
  129. package/dist/openapi.d.ts +2 -0
  130. package/dist/openapi.js +236 -55
  131. package/dist/owner.d.ts +0 -1
  132. package/dist/owner.js +0 -2
  133. package/dist/pause.d.ts +2 -19
  134. package/dist/pause.js +5 -74
  135. package/dist/place-offers.d.ts +97 -0
  136. package/dist/place-offers.js +206 -0
  137. package/dist/place.d.ts +9 -13
  138. package/dist/place.js +22 -32
  139. package/dist/port-models.d.ts +12 -4
  140. package/dist/port-models.js +31 -9
  141. package/dist/print.d.ts +1 -8
  142. package/dist/print.js +1 -14
  143. package/dist/propose.d.ts +3 -0
  144. package/dist/propose.js +25 -19
  145. package/dist/run-cut.d.ts +5 -0
  146. package/dist/run-cut.js +19 -0
  147. package/dist/run-db.js +3 -3
  148. package/dist/run-launch.d.ts +18 -3
  149. package/dist/run-launch.js +11 -5
  150. package/dist/run-learning-served.d.ts +12 -1
  151. package/dist/run-manifest.d.ts +2 -2
  152. package/dist/run-manifest.js +2 -2
  153. package/dist/run-reads-over-store.d.ts +4 -2
  154. package/dist/run-reads-over-store.js +10 -8
  155. package/dist/run-secrets.js +3 -3
  156. package/dist/run-timeline-served.js +60 -38
  157. package/dist/run-view.d.ts +35 -16
  158. package/dist/run-view.js +64 -35
  159. package/dist/runnable.d.ts +6 -3
  160. package/dist/runnable.js +20 -4
  161. package/dist/runner/adapter-loop.d.ts +46 -5
  162. package/dist/runner/adapter-loop.js +381 -56
  163. package/dist/runner/adapter-run-spec.d.ts +46 -4
  164. package/dist/runner/adapter-run-spec.js +200 -45
  165. package/dist/runner/adapters/pi.d.ts +39 -3
  166. package/dist/runner/adapters/pi.js +124 -29
  167. package/dist/runner/beside.d.ts +8 -0
  168. package/dist/runner/beside.js +24 -2
  169. package/dist/runner/claim-secrets.d.ts +6 -0
  170. package/dist/runner/claim-secrets.js +15 -1
  171. package/dist/runner/cli-run-spec.d.ts +10 -0
  172. package/dist/runner/cli-run-spec.js +207 -64
  173. package/dist/runner/commands.d.ts +5 -1
  174. package/dist/runner/commands.js +3 -3
  175. package/dist/runner/conformance/harness.d.ts +1 -1
  176. package/dist/runner/conformance/harness.js +13 -10
  177. package/dist/runner/github-app.d.ts +7 -2
  178. package/dist/runner/github-app.js +46 -15
  179. package/dist/runner/harness-loops.d.ts +6 -1
  180. package/dist/runner/harness-loops.js +24 -1
  181. package/dist/runner/journal-kinds.d.ts +53 -7
  182. package/dist/runner/journal-kinds.js +29 -1
  183. package/dist/runner/learning-end.d.ts +15 -0
  184. package/dist/runner/learning-end.js +113 -20
  185. package/dist/runner/learning-factory.js +6 -2
  186. package/dist/runner/learning-loop.d.ts +75 -1
  187. package/dist/runner/learning-loop.js +215 -22
  188. package/dist/runner/learning-seed.d.ts +8 -0
  189. package/dist/runner/learning-seed.js +7 -1
  190. package/dist/runner/loop-contract.d.ts +12 -0
  191. package/dist/runner/loop-contract.js +6 -0
  192. package/dist/runner/loop.d.ts +5 -1
  193. package/dist/runner/loop.js +20 -0
  194. package/dist/runner/main.d.ts +9 -4
  195. package/dist/runner/main.js +38 -13
  196. package/dist/runner/mcp-claim.d.ts +7 -0
  197. package/dist/runner/mcp-claim.js +35 -2
  198. package/dist/runner/mcp-github.d.ts +15 -4
  199. package/dist/runner/mcp-github.js +55 -11
  200. package/dist/runner/mcp-run.d.ts +2 -0
  201. package/dist/runner/mcp-run.js +2 -0
  202. package/dist/runner/metrics.d.ts +18 -1
  203. package/dist/runner/metrics.js +81 -1
  204. package/dist/runner/model-route.d.ts +6 -0
  205. package/dist/runner/model-route.js +5 -2
  206. package/dist/runner/pr-checkout.d.ts +59 -0
  207. package/dist/runner/pr-checkout.js +176 -0
  208. package/dist/runner/reflect-hook.d.ts +1 -0
  209. package/dist/runner/reflect-hook.js +3 -3
  210. package/dist/runner/runner.js +136 -19
  211. package/dist/runner/spec-holds.d.ts +13 -3
  212. package/dist/runner/spec-holds.js +13 -10
  213. package/dist/runner/store-port.d.ts +4 -1
  214. package/dist/runner/store-secrets.js +17 -1
  215. package/dist/runner/subagent.d.ts +44 -0
  216. package/dist/runner/subagent.js +188 -0
  217. package/dist/runner/workflow-host.d.ts +25 -4
  218. package/dist/runner/workflow-host.js +26 -4
  219. package/dist/runner/workflow-loop.d.ts +9 -3
  220. package/dist/runner/workflow-loop.js +17 -10
  221. package/dist/runner/workflow-spec.d.ts +28 -13
  222. package/dist/runner/workflow-spec.js +247 -102
  223. package/dist/runs-over-store.d.ts +18 -7
  224. package/dist/runs-over-store.js +149 -31
  225. package/dist/seal-key.d.ts +0 -2
  226. package/dist/seal-key.js +0 -2
  227. package/dist/sealing.js +1 -2
  228. package/dist/secret-cut.d.ts +1 -1
  229. package/dist/secret-cut.js +1 -1
  230. package/dist/server-lock.js +4 -5
  231. package/dist/server.d.ts +49 -63
  232. package/dist/server.js +429 -230
  233. package/dist/stop-signals.d.ts +4 -2
  234. package/dist/stop-signals.js +5 -3
  235. package/dist/store/agent-body.d.ts +14 -3
  236. package/dist/store/agent-body.js +22 -8
  237. package/dist/store/deadline.d.ts +18 -0
  238. package/dist/store/deadline.js +49 -0
  239. package/dist/store/index.d.ts +3 -3
  240. package/dist/store/index.js +2 -2
  241. package/dist/store/journal/storage.js +2 -1
  242. package/dist/store/postgres/connection.d.ts +4 -0
  243. package/dist/store/postgres/connection.js +64 -13
  244. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  245. package/dist/store/schema.d.ts +2 -1
  246. package/dist/store/schema.js +11 -8
  247. package/dist/store/seal.d.ts +13 -0
  248. package/dist/store/seal.js +19 -0
  249. package/dist/store/sqlite/connection.d.ts +5 -0
  250. package/dist/store/sqlite/connection.js +88 -82
  251. package/dist/store/sqlite/run-patch.d.ts +18 -2
  252. package/dist/store/sqlite/run-patch.js +31 -2
  253. package/dist/store/sqlite/store.js +65 -11
  254. package/dist/store/store.d.ts +62 -12
  255. package/dist/store/store.js +22 -1
  256. package/dist/store-reads/analytics.js +3 -2
  257. package/dist/store-reads/cap.d.ts +1 -3
  258. package/dist/store-reads/cap.js +8 -6
  259. package/dist/store-reads/decisions.d.ts +2 -2
  260. package/dist/store-reads/decisions.js +3 -6
  261. package/dist/store-reads/journal.js +83 -15
  262. package/dist/store-reads/learning.d.ts +73 -3
  263. package/dist/store-reads/learning.js +232 -9
  264. package/dist/store-reads/runs.d.ts +6 -4
  265. package/dist/store-reads/runs.js +17 -10
  266. package/dist/store-reads/stats.js +5 -1
  267. package/dist/store-view.d.ts +15 -1
  268. package/dist/store-view.js +88 -29
  269. package/dist/template-eval.js +2 -1
  270. package/dist/templates.d.ts +73 -4
  271. package/dist/templates.js +113 -23
  272. package/dist/timeline/timeline.d.ts +11 -1
  273. package/dist/timeline/timeline.js +19 -4
  274. package/dist/tool-blurbs.js +1 -0
  275. package/dist/tool-budget.d.ts +26 -0
  276. package/dist/tool-budget.js +56 -0
  277. package/dist/tool-gate.d.ts +13 -3
  278. package/dist/tool-gate.js +15 -7
  279. package/dist/tool-plane.d.ts +42 -29
  280. package/dist/tool-plane.js +64 -27
  281. package/dist/tools.d.ts +53 -39
  282. package/dist/tools.js +174 -79
  283. package/dist/trigger-signatures.d.ts +1 -0
  284. package/dist/trigger-signatures.js +3 -1
  285. package/dist/triggers.d.ts +3 -3
  286. package/dist/triggers.js +2 -2
  287. package/dist/turn-end.d.ts +0 -3
  288. package/dist/turn-end.js +0 -3
  289. package/dist/uploads.d.ts +28 -5
  290. package/dist/uploads.js +82 -9
  291. package/dist/usage-lines.d.ts +1 -1
  292. package/dist/usage.d.ts +1 -47
  293. package/dist/usage.js +3 -82
  294. package/dist/validate.d.ts +8 -0
  295. package/dist/validate.js +40 -3
  296. package/dist/webhooks.d.ts +2 -1
  297. package/dist/webhooks.js +5 -2
  298. package/dist/workflow/decision-recovery.d.ts +23 -0
  299. package/dist/workflow/decision-recovery.js +80 -0
  300. package/dist/workflow/decisions.d.ts +134 -0
  301. package/dist/workflow/decisions.js +46 -0
  302. package/dist/workflow/host-session.d.ts +5 -0
  303. package/dist/workflow/host-session.js +85 -0
  304. package/dist/workflow/host-tools.d.ts +3 -0
  305. package/dist/workflow/host-tools.js +3 -0
  306. package/dist/workflow/node-runner.d.ts +112 -0
  307. package/dist/workflow/node-runner.js +270 -0
  308. package/dist/workflow/node.d.ts +88 -0
  309. package/dist/workflow/node.js +99 -0
  310. package/dist/workflow/operator-error.d.ts +4 -0
  311. package/dist/workflow/operator-error.js +4 -0
  312. package/dist/workflow/pi-versions.d.ts +9 -0
  313. package/dist/workflow/pi-versions.js +8 -0
  314. package/dist/workflow/readers.d.ts +36 -0
  315. package/dist/workflow/readers.js +145 -0
  316. package/dist/workflow/record-file.d.ts +10 -0
  317. package/dist/workflow/record-file.js +56 -0
  318. package/dist/workflow/record-tool.d.ts +76 -0
  319. package/dist/workflow/record-tool.js +126 -0
  320. package/dist/workflow/record.d.ts +151 -0
  321. package/dist/workflow/record.js +401 -0
  322. package/dist/workflow/run-error.d.ts +16 -0
  323. package/dist/workflow/run-error.js +26 -0
  324. package/dist/workflow/runner.d.ts +6 -0
  325. package/dist/workflow/runner.js +240 -0
  326. package/dist/workflow/store.d.ts +23 -0
  327. package/dist/workflow/store.js +242 -0
  328. package/dist/workflow/task.d.ts +133 -0
  329. package/dist/workflow/task.js +411 -0
  330. package/dist/workflow/thinking.d.ts +3 -0
  331. package/dist/workflow/thinking.js +7 -0
  332. package/dist/workflow/tool-context.d.ts +21 -0
  333. package/dist/workflow/tool-context.js +13 -0
  334. package/dist/workflow/types.d.ts +126 -0
  335. package/dist/workflow/types.js +1 -0
  336. package/dist/workflow/wal.d.ts +11 -0
  337. package/dist/workflow/wal.js +106 -0
  338. package/dist/workflow-run.d.ts +1 -1
  339. package/dist/workspace/agent-computer.d.ts +137 -0
  340. package/dist/workspace/agent-computer.js +292 -0
  341. package/dist/workspace/archil-claim.d.ts +13 -2
  342. package/dist/workspace/archil-claim.js +22 -13
  343. package/dist/workspace/archil-disk.d.ts +10 -1
  344. package/dist/workspace/archil-disk.js +4 -0
  345. package/dist/workspace/archil-disks.d.ts +49 -0
  346. package/dist/workspace/archil-disks.js +185 -0
  347. package/dist/workspace/archil-exec.d.ts +12 -2
  348. package/dist/workspace/archil-exec.js +18 -3
  349. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  350. package/dist/workspace/archil-mount-credential.js +13 -4
  351. package/dist/workspace/archil.d.ts +2 -2
  352. package/dist/workspace/archil.js +25 -5
  353. package/dist/workspace/attach.js +2 -0
  354. package/dist/workspace/computer-deps.d.ts +18 -11
  355. package/dist/workspace/computer-deps.js +64 -40
  356. package/dist/workspace/computer-for-claim.d.ts +47 -9
  357. package/dist/workspace/computer-for-claim.js +236 -24
  358. package/dist/workspace/computer-janitor.d.ts +3 -2
  359. package/dist/workspace/computer-janitor.js +43 -9
  360. package/dist/workspace/computer-ledger.d.ts +3 -8
  361. package/dist/workspace/computer-ledger.js +7 -3
  362. package/dist/workspace/computer-providers.d.ts +5 -3
  363. package/dist/workspace/computer-providers.js +11 -9
  364. package/dist/workspace/hands.d.ts +5 -2
  365. package/dist/workspace/hands.js +4 -3
  366. package/dist/workspace/index.d.ts +5 -4
  367. package/dist/workspace/index.js +2 -1
  368. package/dist/workspace/local.d.ts +3 -0
  369. package/dist/workspace/local.js +9 -0
  370. package/dist/workspace/paths.js +3 -2
  371. package/dist/workspace/pi-env.d.ts +4 -0
  372. package/dist/workspace/pi-env.js +3 -2
  373. package/dist/workspace/resolve-computer.d.ts +48 -12
  374. package/dist/workspace/resolve-computer.js +88 -19
  375. package/dist/workspace/run-disk.d.ts +34 -0
  376. package/dist/workspace/run-disk.js +91 -0
  377. package/dist/workspace/run-tools.d.ts +6 -4
  378. package/dist/workspace/run-tools.js +17 -9
  379. package/dist/workspace/server-run-workspace.d.ts +3 -2
  380. package/dist/workspace/server-run-workspace.js +17 -4
  381. package/dist/workspace/workspace.d.ts +5 -0
  382. package/dist/workspace.d.ts +0 -3
  383. package/dist/workspace.js +2 -15
  384. package/package.json +11 -16
  385. package/skills/agentrun-serve/SKILL.md +1 -1
  386. package/templates/README.md +11 -8
  387. package/templates/code-review/agent.md +27 -11
  388. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  389. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  390. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  391. package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
  392. package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
  393. package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
  394. package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
  395. package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
  396. package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
  397. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  398. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  399. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  400. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  401. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  402. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  403. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  404. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  405. package/templates/code-review/evals/re-review/prompt.md +1 -1
  406. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  407. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  408. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  409. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  410. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  411. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  412. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  413. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  414. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  415. package/templates/code-review/findings.schema.json +131 -27
  416. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  417. package/templates/code-review/skills/review/DEEP.md +130 -0
  418. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  419. package/templates/code-review/skills/review/SKILL.md +104 -154
  420. package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
  421. package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
  422. package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
  423. package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
  424. package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
  425. package/templates/release-notes/agent.md +11 -0
  426. package/dist/box/record.d.ts +0 -6
  427. package/dist/box/record.js +0 -41
  428. package/dist/box/sweep.d.ts +0 -53
  429. package/dist/box/sweep.js +0 -193
  430. package/dist/box-egress-vm.d.ts +0 -118
  431. package/dist/box-egress-vm.js +0 -354
  432. package/dist/box-egress.d.ts +0 -105
  433. package/dist/box-egress.js +0 -256
  434. package/dist/box-relay-vm.d.ts +0 -84
  435. package/dist/box-relay-vm.js +0 -437
  436. package/dist/box-relay.d.ts +0 -36
  437. package/dist/box-relay.js +0 -207
  438. package/dist/boxes.d.ts +0 -109
  439. package/dist/boxes.js +0 -249
  440. package/dist/budget.d.ts +0 -76
  441. package/dist/budget.js +0 -204
  442. package/dist/console/assets/index-RPHGlXmM.js +0 -540
  443. package/dist/console/assets/index-opTN5Naq.css +0 -1
  444. package/dist/daytona-api.d.ts +0 -10
  445. package/dist/daytona-api.js +0 -20
  446. package/dist/egress-proxy.d.ts +0 -45
  447. package/dist/egress-proxy.js +0 -416
  448. package/dist/egress-table.d.ts +0 -24
  449. package/dist/egress-table.js +0 -165
  450. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -0,0 +1,188 @@
1
+ import { configure, defineTool, ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
2
+ import { HOST_RESULT_MAX_CHARS } from "@parcha/agentrun-kernel";
3
+ import { ASK_TOOL } from "../tools.js";
4
+ import { HOST_TOOL_OUTPUT } from "./adapters/pi.js";
5
+ import { cutAtLimit } from "./loop-contract.js";
6
+ import { PI_STOP } from "./pi-stop.js";
7
+ import { budgetOf, ConversationToolBudget } from "../tool-budget.js";
8
+ export const SUBAGENT_TOOL = "subagent";
9
+ /** The tiers a call may name for its child (its definition's model_tiers, else this server's tier); a call that names
10
+ * none runs its child on the agent's own model. */
11
+ export const SUBAGENT_TIERS = ["fast", "strong"];
12
+ /** How many of a run's children work at once; a call past it waits for a slot. */
13
+ export const SUBAGENT_PARALLEL = 4;
14
+ /** Tools no child is given: a subagent of its own (depth 1), and the person, whom only the run's own conversation asks. */
15
+ const NEVER_GIVEN = [SUBAGENT_TOOL, ASK_TOOL];
16
+ /** A child's instructions: the call's prompt is its whole task. Nothing of the parent's prompt is carried over. */
17
+ export const SUBAGENT_INSTRUCTIONS = "You are a subagent. The message you are given is your whole task: do it with the tools you have, then answer. Your last message is returned, as it is, to the agent that called you.";
18
+ /** The thinking levels a call may give its child (`effort`); absent, the child thinks at the agent's own level. */
19
+ export const SUBAGENT_EFFORTS = ["low", "medium", "high"];
20
+ /** One counter of free slots for the run's children (SUBAGENT_PARALLEL), handed out in call order. */
21
+ function slots(count) {
22
+ let free = count;
23
+ const waiting = [];
24
+ return {
25
+ async take(signal) {
26
+ if (free > 0)
27
+ free -= 1;
28
+ else {
29
+ await new Promise((resolve, reject) => {
30
+ const go = () => {
31
+ signal?.removeEventListener("abort", stop);
32
+ resolve();
33
+ };
34
+ const stop = () => {
35
+ const at = waiting.indexOf(go);
36
+ if (at >= 0)
37
+ waiting.splice(at, 1);
38
+ reject(signal?.reason ?? new Error("aborted"));
39
+ };
40
+ waiting.push(go);
41
+ signal?.addEventListener("abort", stop, { once: true });
42
+ });
43
+ }
44
+ let given = false;
45
+ return () => {
46
+ if (given)
47
+ return;
48
+ given = true;
49
+ const next = waiting.shift();
50
+ if (next)
51
+ next();
52
+ else
53
+ free += 1;
54
+ };
55
+ },
56
+ };
57
+ }
58
+ /** The text of an assistant message: its text parts, joined. */
59
+ const textOf = (message) => Array.isArray(message?.content) ? message.content.map((part) => (part?.type === "text" ? (part.text ?? "") : "")).join("") : typeof message?.content === "string" ? message.content : "";
60
+ /** `text` within the host's bound on a tool result (HOST_RESULT_MAX_CHARS), saying where it was cut. */
61
+ export function boundedAnswer(text) {
62
+ if (text.length <= HOST_RESULT_MAX_CHARS)
63
+ return text;
64
+ const note = `\n[the subagent's answer was cut at ${HOST_RESULT_MAX_CHARS.toLocaleString("en-US")} of its ${text.length.toLocaleString("en-US")} characters]`;
65
+ return text.slice(0, HOST_RESULT_MAX_CHARS - note.length) + note;
66
+ }
67
+ /** The catalog names of `asked` (each a catalog or session name of a granted tool) and the session names the child gets,
68
+ * or what is wrong with them. A catalog name gives every session name of its tool (`browser`: each browser tool); a
69
+ * session name gives that one alone (`browser_read`: never the rest of the browser's). */
70
+ export function chosenTools(asked, options) {
71
+ const catalog = [];
72
+ const names = [];
73
+ const offered = options.granted.filter((name) => !NEVER_GIVEN.includes(name));
74
+ for (const name of asked) {
75
+ if (NEVER_GIVEN.includes(name))
76
+ return { refused: `subagent: a subagent is never given ${name}${name === SUBAGENT_TOOL ? " (subagents go one level deep)" : " (only the run itself asks its person)"}. Nothing ran.` };
77
+ const found = options.granted.find((granted) => granted === name || options.sessionNames(granted).includes(name));
78
+ if (found === undefined)
79
+ return { refused: `subagent: ${name} is not one of this agent's tools, so no subagent may have it. A subagent may be given ${offered.length ? offered.join(", ") : "no tool here"}. Nothing ran.` };
80
+ if (!catalog.includes(found))
81
+ catalog.push(found);
82
+ for (const session of found === name ? options.sessionNames(found) : [name])
83
+ if (!names.includes(session))
84
+ names.push(session);
85
+ }
86
+ return { catalog, names };
87
+ }
88
+ /** The subagent tool: one of the session's own tools (adapters/pi.ts `tools`), so it needs no extension of its own. */
89
+ export function subagentTool(options) {
90
+ const free = slots(SUBAGENT_PARALLEL);
91
+ return defineTool({
92
+ name: SUBAGENT_TOOL,
93
+ description: `Run a subagent: a fresh conversation that starts with nothing but your prompt, on your own model (or the model tier you name: ${SUBAGENT_TIERS.join(" or ")}), with only the tools you list (a subset of your own), and get its final answer back as text. Write the prompt self-contained: the subagent sees none of your conversation. Several calls in one turn run at once, at most ${SUBAGENT_PARALLEL} at a time; more wait their turn. A subagent cannot start subagents of its own.`,
94
+ parameters: {
95
+ type: "object",
96
+ additionalProperties: false,
97
+ properties: {
98
+ prompt: { type: "string", minLength: 1, description: "The subagent's whole task, self-contained: it sees nothing else." },
99
+ tools: { type: "array", items: { type: "string" }, uniqueItems: true, description: "The tools it may use, each one of your own tools by name. Absent or empty: none." },
100
+ model: { enum: [...SUBAGENT_TIERS], description: "The model tier it runs on, one of this agent's own tiers. Absent: your own model." },
101
+ max_tool_calls: { type: "integer", minimum: 1, description: "The most tool calls it may make. It narrows your own budget for it, never widens it. Absent: your budget." },
102
+ effort: { enum: [...SUBAGENT_EFFORTS], description: "How hard it thinks: low, medium or high. Absent: as you do." },
103
+ },
104
+ required: ["prompt"],
105
+ },
106
+ // A rerun after a crash finds the same child (it is owned by this call's task) and the same submission (its request
107
+ // id), so the child's work is never started twice.
108
+ replay: "safe",
109
+ executionMode: "parallel",
110
+ outputLimits: HOST_TOOL_OUTPUT,
111
+ execute: async (given, api, context) => {
112
+ const args = given;
113
+ const fail = (text) => ({ output: [{ type: "text", text }], isError: true });
114
+ // Depth 1: a child is never offered subagent (its tools are the call's subset, NEVER_GIVEN aside); and only the run's
115
+ // own conversation calls it.
116
+ if (Number(api.conversationId) !== Number(ROOT_CONVERSATION_ID))
117
+ return fail("subagent: a subagent cannot start subagents of its own. Nothing ran.");
118
+ const model = args.model === undefined ? undefined : options.tier(args.model);
119
+ if (model && "why" in model)
120
+ return fail(`subagent: the ${args.model} tier has no model here: ${model.why} Nothing ran.`);
121
+ if (args.max_tool_calls !== undefined && !(Number.isSafeInteger(args.max_tool_calls) && args.max_tool_calls > 0))
122
+ return fail("subagent: max_tool_calls is a whole number above 0. Nothing ran.");
123
+ if (args.effort !== undefined && !SUBAGENT_EFFORTS.includes(args.effort))
124
+ return fail(`subagent: effort is one of ${SUBAGENT_EFFORTS.join(", ")}. Nothing ran.`);
125
+ // The child's own budget: the call's, held under the agent's (never wider); absent, the agent's holds it as it holds
126
+ // every conversation of the run.
127
+ const toolCalls = args.max_tool_calls === undefined ? undefined : budgetOf(options.toolCalls, args.max_tool_calls);
128
+ const chosen = chosenTools(args.tools ?? [], options);
129
+ if ("refused" in chosen)
130
+ return fail(chosen.refused);
131
+ // The registrations the parent's agent enables, by session name: exactly the ones the call named are the child's.
132
+ const names = new Set(chosen.names);
133
+ const parent = await api.agent(context);
134
+ const tools = parent.tools.filter((registration) => names.has(registration.name));
135
+ const missing = [...names].filter((name) => !tools.some((registration) => registration.name === name));
136
+ if (missing.length)
137
+ return fail(`subagent: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} not bound in this run, so no subagent may have ${missing.length === 1 ? "it" : "them"}. Nothing ran.`);
138
+ const release = await free.take(context.abortSignal);
139
+ try {
140
+ const child = await api.commit(async (tx) => {
141
+ // The ownership index remembers the child: a rerun of this call reuses it.
142
+ const existing = (await tx.scanConversations({ ownerTaskId: api.taskId }, 1)).items[0];
143
+ if (existing !== undefined)
144
+ return existing.id;
145
+ const created = await tx.createConversation({ ownership: { kind: "task", taskId: api.taskId } });
146
+ await configure(tx, created.id, {
147
+ // The tier's model, else the parent's own (its route through the session's proxy and booking).
148
+ // The child keeps the session's extension (its gate); its tools are exactly the call's subset.
149
+ model: model?.ref ?? parent.model,
150
+ // The call's effort, else the agent's own level (a task-owned conversation copies its owner's agent).
151
+ ...(args.effort ? { thinkingLevel: args.effort } : {}),
152
+ tools: tools,
153
+ modelTools: null,
154
+ instructions: [options.preamble, SUBAGENT_INSTRUCTIONS].filter(Boolean).join("\n\n"),
155
+ });
156
+ if (toolCalls !== undefined)
157
+ Object.assign(await tx.doc(ConversationToolBudget, created.id), { toolCalls });
158
+ return created.id;
159
+ }, context);
160
+ // The call's details name its child: the run's timeline nests the child's rows under this call.
161
+ const details = { conversationId: Number(child), ...(args.model ? { model: args.model } : {}), tools: chosen.catalog, ...(toolCalls !== undefined ? { max_tool_calls: toolCalls } : {}), ...(args.effort ? { effort: args.effort } : {}) };
162
+ await api.details(details, context);
163
+ const handle = await api.conversation(child, context);
164
+ if (!handle)
165
+ return { ...fail("subagent: its conversation could not be opened. Nothing ran."), details };
166
+ const submission = await handle.submit({ type: "input", content: args.prompt, requestId: `subagent:${String(api.taskId)}` }, context);
167
+ const settled = await submission.wait(context);
168
+ if (settled.status === "done" && settled.answer !== undefined) {
169
+ const answer = await api.commit((tx) => tx.entry(settled.answer), context);
170
+ const message = answer?.model?.findLast((each) => each.role === "assistant");
171
+ const text = textOf(message);
172
+ // An answer cut at the model's output limit is unfinished (as the run's own is: loop.ts cutLast): an error the
173
+ // parent reads, with what the child said before the cut.
174
+ if (message?.stopReason === PI_STOP.length)
175
+ return { ...fail(boundedAnswer(`subagent: its answer is unfinished: ${cutAtLimit(message.usage?.output)}${text ? `\nWhat it wrote before the cut:\n${text}` : ""}`)), details };
176
+ return { output: [{ type: "text", text: boundedAnswer(text || "(the subagent answered with no text)") }], details };
177
+ }
178
+ // Unanswered: its own words for why (a request the cap refused, a provider's error), from its last answer.
179
+ const last = await api.commit(async (tx) => (await tx.scanEntries({ conversationId: child, order: "descending" }, 20)).items.flatMap((entry) => entry.model ?? []).find((each) => each.role === "assistant"), context);
180
+ const why = last?.errorMessage ?? settled.reason ?? "it stopped";
181
+ return { ...fail(boundedAnswer(`subagent: it stopped before it answered: ${why}`)), details };
182
+ }
183
+ finally {
184
+ release();
185
+ }
186
+ },
187
+ });
188
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Extension } from "@earendil-works/pi-durable";
2
- import { type WorkflowTaskHost } from "@parcha/agentrun-pi/durable";
2
+ import { type WorkflowTaskHost } from "../workflow/task.js";
3
3
  /** A model node's tier, as the DSL names it. */
4
4
  export type NodeTier = string | undefined;
5
5
  /** A node tool's bindings for a model node's agent (its pi extensions and tools), as the node-tool table binds them. */
@@ -30,6 +30,8 @@ export interface DecisionDriver {
30
30
  decisionRequests(): Record<string, {
31
31
  status: string;
32
32
  }>;
33
+ /** Resolves once the driver's commits so far are durable (a request it ended, before the run parks on it). */
34
+ flush(): Promise<void>;
33
35
  }
34
36
  /** The run's spend cap over the workflow's adapters (app.ts's budget: stepped/failing/capStopped and the decision cap),
35
37
  * injected so this module holds no money of its own. Each wrapper is applied to its adapter where app.ts applied it; a run
@@ -38,11 +40,18 @@ export interface DecisionDriver {
38
40
  export interface WorkflowCap {
39
41
  /** stepped(gate(capStopped(·)), true): a model node, counted in flight, failing as a cap stop where no raise fixes it. */
40
42
  node<F>(fn: F): F;
41
- /** stepped(failing(·)): a call node, which waits for a raise on a held effect and goes again. */
43
+ /** stepped(failing(·)): a call node, before the driver admits its effect: it waits for a raise on a held effect and
44
+ * goes again. */
42
45
  effect<F>(fn: F): F;
43
- /** stepped(gate(capped.before(·))): a decision, held before the driver admits it (admitting and settling it through the
44
- * kernel cap). The driver tells a replayed request, which holds nothing (main's `capped.before(runJudge, askedBefore)`). */
46
+ /** A call node's effect once the driver has admitted it: held through the kernel cap, run, and settled. Absent: the
47
+ * effect runs as given. */
48
+ admittedEffect?<F>(fn: F): F;
49
+ /** A decision, before the driver admits its request: priced, or parked by a pause. The driver tells a replayed request,
50
+ * which holds nothing. */
45
51
  judge<F>(fn: F, driver?: DecisionDriver): F;
52
+ /** A decision's judge once the driver has admitted its request: held through the kernel cap, sent, and settled. Absent:
53
+ * the judge runs as given. */
54
+ admitted?<F>(fn: F): F;
46
55
  /** A call node's wait on a raise (deps.held), left out of its deadline. */
47
56
  held?(path: string): number;
48
57
  }
@@ -54,6 +63,12 @@ export interface WorkflowHostDeps {
54
63
  readonly provider: string;
55
64
  readonly modelId: string;
56
65
  };
66
+ /** Told as each model node's execution starts, before it runs: its execution path and the tier it asked for (the graph
67
+ * keeps what each execution ran on). Absent: nothing told. */
68
+ readonly onModelNode?: (node: {
69
+ readonly executionPath: string;
70
+ readonly tier?: string;
71
+ }) => Promise<void>;
57
72
  /** The thinking level every node agent runs at. */
58
73
  readonly thinkingLevel?: unknown;
59
74
  /** The extensions every model node's agent shares (the coding extension and the gate), installed in the registry too. */
@@ -75,6 +90,12 @@ export interface WorkflowHostDeps {
75
90
  readonly flush: () => Promise<void>;
76
91
  /** The node log's node.start/node.end lines; absent: no log. */
77
92
  readonly log?: (line: Record<string, unknown>) => void;
93
+ /** Told each workflow step's start and end, by its label (the workflow's node.start/node.end): what a cap's pause reads
94
+ * to name the node whose step it held (workflow-spec.ts openSteps). */
95
+ readonly steps?: {
96
+ start(label: string): void;
97
+ end(label: string): void;
98
+ };
78
99
  /** What a decision's receipt is shown as, as it is recorded (the live view); absent: not shown. */
79
100
  readonly onReceipt?: (receipt: Record<string, unknown>) => void;
80
101
  /** The run's spend cap over the adapters; absent: the workflow runs with no cap. */
@@ -1,11 +1,24 @@
1
- import { decisionRecovery, nodeRunner, taskScope } from "@parcha/agentrun-pi/durable";
1
+ import { decisionRecovery } from "../workflow/decision-recovery.js";
2
+ import { nodeRunner } from "../workflow/node-runner.js";
3
+ import { taskScope } from "../workflow/node.js";
2
4
  import { judgeFromProviders } from "@parcha/agentrun-dsl";
3
5
  import { withRecovery, workspaceFiles } from "@parcha/agentrun-dsl/recovery";
4
6
  const identityCap = { node: (fn) => fn, effect: (fn) => fn, judge: (fn) => fn };
7
+ /** `runNode` that tells `told` of each model node's execution (its path and tier) before it runs it. */
8
+ function withModelNode(runNode, told) {
9
+ if (!told)
10
+ return runNode;
11
+ return async (params) => {
12
+ if (typeof params.executionPath === "string")
13
+ await told({ executionPath: params.executionPath, ...(typeof params.tier === "string" ? { tier: params.tier } : {}) });
14
+ return runNode(params);
15
+ };
16
+ }
5
17
  /** The workflow task's host and the extensions to install before the Harness opens, as the per-run process built them.
6
18
  * Pass the result to createWorkflowLoop's spec.build. */
7
19
  export function workflowHost(deps) {
8
20
  const cap = deps.cap ?? identityCap;
21
+ const admitted = (fn) => (cap.admitted ? cap.admitted(fn) : fn);
9
22
  /** A model node's agent: its tier's model, the tools it names, and the extensions they come from (app.ts nodeAgent). */
10
23
  const nodeAgent = (node) => {
11
24
  const bindings = (node.tools ?? []).flatMap((name) => deps.nodeTool(name) ?? []);
@@ -19,6 +32,13 @@ export function workflowHost(deps) {
19
32
  const nodes = nodeRunner({ agent: (node) => nodeAgent(node) });
20
33
  /** The node log's starts and ends, from the workflow's events (app.ts onEvent). */
21
34
  const onEvent = (event) => {
35
+ // A nested `workflow` step stays open while its own steps run and sends no request itself: the steps open are the ones
36
+ // that can, so a pause inside it names its step, never nothing.
37
+ const enclosing = event.detail?.kind === "workflow";
38
+ if (typeof event.label === "string" && event.type === "node.start" && !enclosing)
39
+ deps.steps?.start(event.label);
40
+ if (typeof event.label === "string" && event.type === "node.end" && !enclosing)
41
+ deps.steps?.end(event.label);
22
42
  if (!deps.log || (event.type !== "node.start" && event.type !== "node.end") || typeof event.executionPath !== "string")
23
43
  return;
24
44
  const detail = (event.detail ?? {});
@@ -36,9 +56,11 @@ export function workflowHost(deps) {
36
56
  run: ({ key, runtime, context, driver }) => {
37
57
  const decisions = decisionRecovery({ key, runtime: runtime, context });
38
58
  const recovered = withRecovery(driver, {
39
- runNode: nodes.on(taskScope(runtime), context).runNode,
40
- runEffect: deps.runEffect,
41
- ...(deps.decisionProviders ? { runJudge: judgeFromProviders({ ...deps.decisionProviders, loadImage: deps.loadImage }), decisionProviders: deps.decisionProviders } : {}),
59
+ runNode: withModelNode(nodes.on(taskScope(runtime), context).runNode, deps.onModelNode),
60
+ // The effect the driver runs once it has admitted it: the cap holds and settles a paid call there (admittedEffect).
61
+ runEffect: (cap.admittedEffect ? cap.admittedEffect(deps.runEffect) : deps.runEffect),
62
+ // The judge the driver asks once it has admitted a request: the cap holds, sends and settles it there (admitted).
63
+ ...(deps.decisionProviders ? { runJudge: admitted(judgeFromProviders({ ...deps.decisionProviders, loadImage: deps.loadImage })), decisionProviders: deps.decisionProviders } : {}),
42
64
  recordDecision: async (receipt, exchange) => {
43
65
  await decisions.recordDecision(receipt, exchange);
44
66
  deps.onReceipt?.(receipt);
@@ -2,15 +2,18 @@ import type { Context } from "@earendil-works/chord";
2
2
  import { type Extension, Harness } from "@earendil-works/pi-durable";
3
3
  import type { Models } from "@earendil-works/pi-ai";
4
4
  import type { Workflow } from "@parcha/agentrun-dsl";
5
- import { type WorkflowTaskHost } from "@parcha/agentrun-pi/durable";
5
+ import { type WorkflowTaskHost } from "../workflow/task.js";
6
6
  import { type BudgetData, type EndData } from "./journal-kinds.js";
7
- import { type Claim, type LoopFactory } from "./loop-contract.js";
7
+ import { type Claim, type Journal, type LoopFactory } from "./loop-contract.js";
8
8
  /** A cap refusal, as the kernel cap hands one to parkOf/checkRaise (the loop never imports the cap; its rule is handed in
9
9
  * via the spec, so flat or tiered pricing is the cap's, not this loop's). */
10
+ /** `node`: the label of the workflow node whose step the cap held (a model node's request, a call node's call, a
11
+ * decision), which the run's pending budget names; absent when the step's node is not known. */
10
12
  export type CapRefusal = {
11
13
  readonly message: string;
12
14
  readonly forGood: boolean;
13
15
  readonly figures?: unknown;
16
+ readonly node?: string;
14
17
  };
15
18
  /** A raise's state as the cap's checkRaise reads it (the kernel cap's RaiseState). */
16
19
  export type RaiseState = {
@@ -105,7 +108,7 @@ export interface WorkflowRunSpec {
105
108
  export interface WorkflowHostHooks {
106
109
  /** A step the cap holds for a raise lets go here, with the cap's refusal: the loop parks the run (parkOf's pending
107
110
  * budget, in the cap's words) and a later claim resumes the workflow from its journal (the held step was never admitted,
108
- * so nothing is half done), with the raised cap. The caller must let the node's signal, which the loop aborts, end the
111
+ * or ended held with nothing sent, so nothing is half done), with the raised cap. The caller must let the node's signal, which the loop aborts, end the
109
112
  * step's wait. */
110
113
  park(refusal: CapRefusal): void;
111
114
  /** Whether a person's pause is in force (POST /runs/{id}/pause: a `pause` command taken with no `resume` after it). The
@@ -127,6 +130,9 @@ export declare const isWorkflowRevision: (revision: {
127
130
  * the claim opens from the store (redact.ts holdClaimed). */
128
131
  export interface WorkflowSpecRun {
129
132
  readonly redact?: (text: string) => string;
133
+ /** A fresh journal of the claim, for what the spec reads from the run's records at its end (its decisions' booked
134
+ * cost): a fresh one, since the Harness closes its own before the end is written. */
135
+ readonly journal?: () => Journal;
130
136
  }
131
137
  /** Loops for workflow runs: `spec(claim)` gives each claim's run what it runs (its workflow, input, models and host). */
132
138
  export declare function createWorkflowLoop(specOf: (claim: Claim, run: WorkflowSpecRun) => WorkflowRunSpec | Promise<WorkflowRunSpec>): LoopFactory;
@@ -1,7 +1,7 @@
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
3
  // claim, the fence, a cancel and the end commit are its. The DSL's durable runner (workflow-run.ts
4
- // startWorkflowRevision over agentrun-pi's workflow task) runs the revision's workflow UNCHANGED — the same nodes,
4
+ // startWorkflowRevision over the workflow task, workflow/task.ts) 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
7
7
  // nodes on the tool table, decisions, the cap) is built by the caller (WorkflowRunSpec.build), exactly as the per-run
@@ -19,10 +19,10 @@
19
19
  // shutdown writes nothing more and the next claim resumes.
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
- import { createWorkflowExtension } from "@parcha/agentrun-pi/durable";
22
+ import { createWorkflowExtension } from "../workflow/task.js";
23
23
  import { readWorkflowRun, startWorkflowRevision, workflowCarry } from "../workflow-run.js";
24
24
  import { KINDS } from "./journal-kinds.js";
25
- import { endedBy } from "./loop-contract.js";
25
+ import { stopEnd } 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). */
27
27
  const CUT_STEP_MS = 2_000;
28
28
  /** A paused run's words, its row's summary while it waits for a resume. */
@@ -213,7 +213,7 @@ function workflowLoop(specOf, deps) {
213
213
  const parkController = new AbortController();
214
214
  let heldRefusal;
215
215
  const context = withAbortSignal(AbortSignal.any([deps.signal, parkController.signal]), BACKGROUND_CONTEXT);
216
- spec = await specOf(claim, deps.redact ? { redact: deps.redact } : {});
216
+ spec = await specOf(claim, { ...(deps.redact ? { redact: deps.redact } : {}), journal: () => deps.journal(claim) });
217
217
  claimNow = claim;
218
218
  specReady();
219
219
  const revision = { id: spec.revisionId, kind: "workflow", body: { workflow: spec.workflow, tools: [...spec.tools] } };
@@ -270,10 +270,10 @@ function workflowLoop(specOf, deps) {
270
270
  await closeHarness();
271
271
  const endJournal = deps.journal(claim);
272
272
  // A person stopped or cancelled: the run ends stopped whatever the workflow's own outcome (its last node may have
273
- // completed as the stop landed, since the engine cancels by aborting the task), in the words that say which (endedBy),
274
- // with the stop row taken in the end commit.
273
+ // completed as the stop landed, since the engine cancels by aborting the task), in the words and the outcome that say
274
+ // which (stopEnd), with the stop row taken in the end commit. A workflow run is never reopened, either way.
275
275
  if (stopReason?.kind === "command")
276
- return await writeEnd(endJournal, context, { state: "stopped", summary: endedBy(stopReason.cancel) });
276
+ return await writeEnd(endJournal, context, stopEnd(stopReason.cancel));
277
277
  const carry = await workflowCarry({ runId: claim.runId, storage: endJournal, revision }, outcome, { context });
278
278
  // A completed run's output, read as main's server read it once the workflow completed (runs.ts workflowEnd:
279
279
  // readWorkflowRun's `output`, null when it has none), kept on its end for result.output.
@@ -281,6 +281,12 @@ function workflowLoop(specOf, deps) {
281
281
  const { output } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
282
282
  return await writeEnd(endJournal, context, { ...carry, output: output ?? null });
283
283
  }
284
+ // An escalated run's review, as main's server kept it (runs.ts): the escalation's kind, the escalate node's label (else
285
+ // the node it escalated at), and its summary (else the run's), kept on its end for the run's `review`.
286
+ if (carry.state === "escalated") {
287
+ const { escalation, escalatedAt } = await readWorkflowRun({ runId: claim.runId, storage: endJournal, revision }, { context });
288
+ return await writeEnd(endJournal, context, { ...carry, review: { kind: escalation?.kind ?? null, node: escalation?.label ?? escalatedAt?.label ?? null, reason: escalation?.summary ?? carry.summary } });
289
+ }
284
290
  return await writeEnd(endJournal, context, carry);
285
291
  }
286
292
  finally {
@@ -298,14 +304,15 @@ function workflowLoop(specOf, deps) {
298
304
  return { state: "interrupted" };
299
305
  if (parked.outcome === "failed")
300
306
  return await writeEnd(journal, BACKGROUND_CONTEXT, { state: "failed", summary: parked.error });
301
- const budget = { pending: parked.pending, words: parked.words };
307
+ // A workflow's pause names the node whose step waits at the cap (null when it is not known), as its pending budget shows.
308
+ const budget = { pending: parked.pending, words: parked.words, node: refusal.node ?? null };
302
309
  await append(journal, BACKGROUND_CONTEXT, KINDS.budget, budget, { run: { state: "parked", summary: parked.words } });
303
310
  return { state: "parked" };
304
311
  }
305
312
  async function writeEnd(journal, context, carry) {
306
313
  const state = carry.state === "failed" ? "failed" : carry.state === "stopped" ? "stopped" : "ended";
307
- const outcome = carry.state === "escalated" ? "escalated" : undefined;
308
- const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}) };
314
+ const outcome = carry.state === "escalated" ? "escalated" : carry.state === "stopped" ? carry.outcome : undefined;
315
+ const base = { state, summary: carry.summary, ...(outcome ? { outcome } : {}), ...(carry.output !== undefined ? { output: carry.output } : {}), ...(carry.review ? { review: carry.review } : {}) };
309
316
  const patch = await endPatchOf(spec, base);
310
317
  const data = { ...base, ...(patch.costUsd !== undefined ? { costUsd: patch.costUsd } : {}), ...(patch.metrics !== undefined ? { metrics: patch.metrics } : {}) };
311
318
  const runPatch = {
@@ -11,16 +11,14 @@ import { type ModelRoute } from "./model-route.js";
11
11
  import { type CapRefusal, type WorkflowHostHooks, type WorkflowRunSpec, type WorkflowSpecRun } from "./workflow-loop.js";
12
12
  import { type WorkflowCap } from "./workflow-host.js";
13
13
  import type { Store } from "../store/store.js";
14
- /** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
15
- * @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
16
- * does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
17
- export declare const SUBMIT_TOOL = "submit";
18
14
  /** How a tier's model is reached and priced, resolved by the caller for each tier the workflow names: the proxy's provider
19
15
  * (its API, origin, credential and policy), the catalog price the proxy books an answered request at (calculateCost,
20
16
  * tiered), and the cap's model (its price the catalog's cost as given). A test gives a scripted origin and fetch. */
21
17
  export interface WorkflowProvider {
22
18
  /** The model id the node asks for (the tier's model). */
23
19
  readonly modelId: string;
20
+ /** The model as the run names it (`provider/model-id`): what an `llm` call's answer says it ran on. Absent: `modelId`. */
21
+ readonly named?: string;
24
22
  /** The wire the proxy forwards on, and pi-ai's client of it speaks to the proxy (port-models.ts sessionProvider). */
25
23
  readonly api: Wire;
26
24
  /** The catalog's entry for the model (whether it reasons, its window), as pi's session takes it (model-route.ts). */
@@ -85,7 +83,15 @@ export declare function workflowSpecOf(deps: WorkflowSpecDeps): (claim: {
85
83
  /** The run's rule with a park on a refusal: `before` (runCap's one rule for the model session) is asked, and on a refusal
86
84
  * the run parks through the loop's hook (parkOf decides room vs for good from the refusal), the same as the pi adapter's
87
85
  * parkAtCap. It still returns the refusal, so the proxy refuses the request and the node's turn ends. */
88
- export declare function parkOnRefusal(before: BeforeRequest, hooks: Pick<WorkflowHostHooks, "park" | "paused" | "pause">, flight?: EffectsInFlight): BeforeRequest;
86
+ export declare function parkOnRefusal(before: BeforeRequest, hooks: Pick<WorkflowHostHooks, "park" | "paused" | "pause">, flight?: EffectsInFlight, steps?: OpenSteps): BeforeRequest;
87
+ /** The workflow's steps under way, by label (the workflow's node.start/node.end, through the host): `only` is the label
88
+ * of the one step open, else undefined (none, or several at once). */
89
+ export interface OpenSteps {
90
+ start(label: string): void;
91
+ end(label: string): void;
92
+ only(): string | undefined;
93
+ }
94
+ export declare function openSteps(): OpenSteps;
89
95
  /** How many call nodes' effects are in flight (pauseAtEffects counts them; parkOnRefusal reads it). */
90
96
  export interface EffectsInFlight {
91
97
  count: number;
@@ -99,7 +105,7 @@ export declare function pauseAtEffects(cap: WorkflowCap, hooks: Pick<WorkflowHos
99
105
  /** A call node `via: "tool"`: the node-tool table's effect (toolOf(tool).effect) with the run's ctx, as app.ts ran it. Its
100
106
  * paid requests (its `llm` call) book through the run's models under the cap. A cap-held request ends the effect held
101
107
  * (CAP_HELD), a tool failure as the tool's own (TOOL_FAILED); the loop's `failing` reads both. */
102
- /** What a call node's request may cost at most, judged before the engine admits it (holdAtEffects): a Parallel search's
108
+ /** What a call node's request may cost at most, judged once the engine has admitted it (holdAtEffects): a Parallel search's
103
109
  * or extract's fee as paidRequest prices it (a fixed fee, what it may charge at most); an `llm` call's request at the
104
110
  * cap's worst price for it (its model's tiered rates over an input bound of one token per UTF-8 byte of its prompt and
105
111
  * system plus LLM_FRAMING_BYTES for the request's own framing, and the output it asks for, else its model's most);
@@ -119,16 +125,25 @@ export declare const LLM_FRAMING_BYTES = 2048;
119
125
  /** The output an `llm` call that names none is sent asking for at most (port-models.ts sessionModel's maxTokens). */
120
126
  export declare const LLM_DEFAULT_OUTPUT = 32000;
121
127
  export declare function callHoldOf(tool: string, input: Record<string, unknown>, env: NodeJS.ProcessEnv, modelOfTier: (tier: string | undefined) => CapModel | undefined): CallHold;
122
- /** `cap` with each call node's most cost held on the run's one ledger before the engine admits its effect: applied
123
- * outside the cap's effect wrapper (and the engine's recovery wrapper, which admits it), as the pause is. A hold the cap
124
- * refuses for room parks the run there (`hooks.park`, as a model request's refusal does) and the effect, never admitted,
125
- * waits on the node's signal; one refused for good fails the call in the cap's words. Held, the effect runs with the
126
- * hold as its reservation; what is not taken is given back at its end. After it, the net: a call whose answer cost more
127
- * than its hold (an `llm` answer priced at its usage) fails in the cap's words. */
128
+ /** `cap` with each call node's most cost held on the run's one ledger, in two halves around the DSL driver's admission of
129
+ * its effect (dsl recovery/driver.ts wrapEffect: the effect is committed admitted before it is dispatched, and one
130
+ * admitted and never completed is never dispatched again):
131
+ * - `admittedEffect`, the effect the driver runs once it has admitted it: the call is priced (`holdOf`) and its hold
132
+ * taken (its record made durable before anything is sent), so a hold is never kept for an effect the driver did not
133
+ * admit: a process that dies before the admission leaves nothing for the next claim to count beside running the call
134
+ * again, and one that dies after it leaves the effect admitted, which the next claim never runs again, under the one
135
+ * hold it counts. Held, the effect runs with the hold as its reservation; what is not taken is given back at its end.
136
+ * A hold the cap refuses ends the effect completed with nothing sent: refused for room, as held (CAP_HELD); refused
137
+ * for good, as the call's failure in the cap's words (TOOL_FAILED). So does the net: a call whose answer cost more
138
+ * than its hold (an `llm` answer priced at its usage).
139
+ * - `effect`, outside the driver: an effect this process ended held parks the run (`park`, as a model request's refusal
140
+ * does) once that end is durable (`flush`), and waits on the node's signal. One an earlier claim ended held (its
141
+ * receipt, replayed) is the park that claim made: the call goes again, a new effect judged at this claim's cap. */
128
142
  export declare function holdAtEffects(cap: WorkflowCap, deps: {
129
143
  readonly paid: () => RunTools | undefined;
130
144
  readonly holdOf: (tool: string, input: Record<string, unknown>) => CallHold;
131
145
  readonly park: (refusal: CapRefusal) => void;
146
+ readonly flush: () => Promise<void>;
132
147
  }): WorkflowCap;
133
148
  /** The reservation of the call node this request runs under, given back as the request is judged on its own (an `llm`
134
149
  * call's model request): its hold is the request's from here. */
@@ -169,7 +184,7 @@ type GatedExecute = (args: never, api: never, context: never) => Promise<unknown
169
184
  * was sent) and the tool is now denied or set to ask, the refusal says that whether it took effect is not known
170
185
  * (RAN_UNKNOWN), never that it was not run or that nothing was sent and nothing was charged. */
171
186
  export declare function gatedNodeCall(name: string, policy: CallPolicy, execute: GatedExecute): GatedExecute;
172
- /** The tool names a workflow's model node offers its model: the node's `submit` (pi's SUBMIT_TOOL) and every tool the
187
+ /** The tool names a workflow's model node offers its model: the node's `submit` (SUBMIT_TOOL) and every tool the
173
188
  * workflow's model nodes name. */
174
189
  export declare function nodeOffer(workflow: Workflow): string[];
175
190
  export { BACKGROUND_CONTEXT };