@parcha/agentrun-serve 0.1.0-beta.35 → 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 (372) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/README.md +260 -168
  3. package/dist/adapters.d.ts +12 -2
  4. package/dist/adapters.js +27 -2
  5. package/dist/agent-rows.d.ts +2 -1
  6. package/dist/agents-store.d.ts +2 -0
  7. package/dist/agents-store.js +9 -4
  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 +79 -7
  13. package/dist/archil-settings.js +140 -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/box-image.d.ts +1 -97
  19. package/dist/box-image.js +4 -284
  20. package/dist/box-paths.d.ts +2 -7
  21. package/dist/box-paths.js +7 -13
  22. package/dist/box-settings.d.ts +0 -11
  23. package/dist/box-settings.js +4 -29
  24. package/dist/browser-commands.js +1 -1
  25. package/dist/browser-computer.d.ts +47 -3
  26. package/dist/browser-computer.js +286 -18
  27. package/dist/browser-person.d.ts +19 -2
  28. package/dist/browser-person.js +55 -6
  29. package/dist/browser-wait-ended.d.ts +23 -0
  30. package/dist/browser-wait-ended.js +42 -0
  31. package/dist/cap.d.ts +13 -41
  32. package/dist/cap.js +24 -73
  33. package/dist/cli.js +4 -22
  34. package/dist/computer-routes.d.ts +1 -4
  35. package/dist/computer-routes.js +3 -5
  36. package/dist/computer-setting.d.ts +2 -0
  37. package/dist/computer-setting.js +38 -1
  38. package/dist/computer-view.d.ts +11 -2
  39. package/dist/computer-view.js +2 -1
  40. package/dist/computers.d.ts +48 -7
  41. package/dist/computers.js +100 -23
  42. package/dist/console/assets/index-BI4Byidu.js +550 -0
  43. package/dist/console/assets/index-C19gUF2n.css +1 -0
  44. package/dist/console/index.html +2 -2
  45. package/dist/docker-daemon.d.ts +2 -2
  46. package/dist/docker-daemon.js +2 -2
  47. package/dist/errors.js +5 -5
  48. package/dist/faux-computers.js +4 -0
  49. package/dist/files.d.ts +1 -9
  50. package/dist/files.js +1 -9
  51. package/dist/github.d.ts +22 -2
  52. package/dist/github.js +42 -8
  53. package/dist/gpu-words.d.ts +14 -0
  54. package/dist/gpu-words.js +21 -0
  55. package/dist/graph-view.d.ts +2 -0
  56. package/dist/graph-view.js +25 -1
  57. package/dist/handed-values.d.ts +1 -1
  58. package/dist/handed-values.js +1 -1
  59. package/dist/harness-install.d.ts +60 -3
  60. package/dist/harness-install.js +322 -34
  61. package/dist/harness.js +1 -1
  62. package/dist/host-tools.d.ts +8 -9
  63. package/dist/host-tools.js +7 -7
  64. package/dist/index.d.ts +1 -3
  65. package/dist/index.js +1 -2
  66. package/dist/key-refusal.d.ts +1 -1
  67. package/dist/key-refusal.js +2 -2
  68. package/dist/learn/check.d.ts +7 -1
  69. package/dist/learn/check.js +123 -5
  70. package/dist/learn/commit.d.ts +40 -6
  71. package/dist/learn/commit.js +164 -20
  72. package/dist/learn/folder.d.ts +5 -0
  73. package/dist/learn/folder.js +33 -0
  74. package/dist/learn/grade.d.ts +18 -1
  75. package/dist/learn/grade.js +86 -16
  76. package/dist/learn/index.d.ts +1 -1
  77. package/dist/learn/index.js +1 -1
  78. package/dist/learn/learning.sh +12 -1
  79. package/dist/learn/notes.d.ts +3 -0
  80. package/dist/learn/notes.js +3 -0
  81. package/dist/learn/reflect.d.ts +5 -2
  82. package/dist/learn/reflect.js +43 -29
  83. package/dist/learn/skills.d.ts +4 -0
  84. package/dist/learn/skills.js +7 -0
  85. package/dist/learned-nodes.d.ts +6 -2
  86. package/dist/learned-workflow.d.ts +19 -9
  87. package/dist/learned-workflow.js +62 -34
  88. package/dist/learning-cost.d.ts +79 -0
  89. package/dist/learning-cost.js +69 -0
  90. package/dist/learning-routes.d.ts +8 -3
  91. package/dist/learning-routes.js +9 -6
  92. package/dist/learning-words.d.ts +3 -0
  93. package/dist/learning-words.js +6 -2
  94. package/dist/learning.d.ts +13 -6
  95. package/dist/learning.js +4 -2
  96. package/dist/mcp-probe.d.ts +8 -1
  97. package/dist/mcp-probe.js +62 -20
  98. package/dist/mcp-secret-writes.js +4 -0
  99. package/dist/mcp-servers-store.js +8 -3
  100. package/dist/model.d.ts +5 -5
  101. package/dist/model.js +6 -6
  102. package/dist/openapi.d.ts +2 -0
  103. package/dist/openapi.js +204 -47
  104. package/dist/owner.d.ts +0 -1
  105. package/dist/owner.js +0 -2
  106. package/dist/paid-calls.js +1 -1
  107. package/dist/place-offers.d.ts +97 -0
  108. package/dist/place-offers.js +206 -0
  109. package/dist/place.d.ts +9 -13
  110. package/dist/place.js +22 -32
  111. package/dist/port-models.d.ts +2 -1
  112. package/dist/port-models.js +5 -3
  113. package/dist/print.d.ts +1 -8
  114. package/dist/print.js +1 -14
  115. package/dist/propose.d.ts +1 -0
  116. package/dist/propose.js +25 -10
  117. package/dist/run-cut.d.ts +5 -0
  118. package/dist/run-cut.js +19 -0
  119. package/dist/run-db.js +3 -3
  120. package/dist/run-launch.d.ts +14 -1
  121. package/dist/run-launch.js +7 -2
  122. package/dist/run-learning-served.d.ts +1 -1
  123. package/dist/run-manifest.d.ts +2 -2
  124. package/dist/run-manifest.js +2 -2
  125. package/dist/run-secrets.js +3 -3
  126. package/dist/run-timeline-served.js +56 -44
  127. package/dist/run-view.d.ts +5 -2
  128. package/dist/run-view.js +4 -3
  129. package/dist/runnable.d.ts +2 -2
  130. package/dist/runnable.js +6 -2
  131. package/dist/runner/adapter-loop.d.ts +16 -1
  132. package/dist/runner/adapter-loop.js +131 -30
  133. package/dist/runner/adapter-run-spec.d.ts +25 -4
  134. package/dist/runner/adapter-run-spec.js +103 -24
  135. package/dist/runner/adapters/pi.d.ts +11 -3
  136. package/dist/runner/adapters/pi.js +35 -12
  137. package/dist/runner/beside.js +6 -2
  138. package/dist/runner/cli-run-spec.d.ts +7 -0
  139. package/dist/runner/cli-run-spec.js +92 -38
  140. package/dist/runner/commands.d.ts +5 -1
  141. package/dist/runner/commands.js +3 -3
  142. package/dist/runner/conformance/harness.d.ts +0 -1
  143. package/dist/runner/conformance/harness.js +8 -5
  144. package/dist/runner/github-app.js +2 -2
  145. package/dist/runner/harness-loops.js +1 -1
  146. package/dist/runner/journal-kinds.d.ts +15 -5
  147. package/dist/runner/journal-kinds.js +6 -1
  148. package/dist/runner/learning-end.d.ts +15 -0
  149. package/dist/runner/learning-end.js +26 -5
  150. package/dist/runner/learning-factory.js +6 -2
  151. package/dist/runner/learning-loop.d.ts +73 -1
  152. package/dist/runner/learning-loop.js +203 -18
  153. package/dist/runner/learning-seed.d.ts +2 -0
  154. package/dist/runner/learning-seed.js +1 -1
  155. package/dist/runner/loop-contract.d.ts +8 -0
  156. package/dist/runner/loop-contract.js +6 -0
  157. package/dist/runner/loop.d.ts +5 -1
  158. package/dist/runner/loop.js +20 -0
  159. package/dist/runner/main.js +12 -2
  160. package/dist/runner/mcp-claim.d.ts +4 -0
  161. package/dist/runner/mcp-claim.js +29 -1
  162. package/dist/runner/mcp-github.d.ts +4 -2
  163. package/dist/runner/mcp-github.js +0 -7
  164. package/dist/runner/mcp-run.d.ts +2 -0
  165. package/dist/runner/mcp-run.js +1 -0
  166. package/dist/runner/metrics.d.ts +4 -0
  167. package/dist/runner/metrics.js +9 -0
  168. package/dist/runner/model-route.d.ts +3 -0
  169. package/dist/runner/model-route.js +5 -2
  170. package/dist/runner/pr-checkout.d.ts +59 -0
  171. package/dist/runner/pr-checkout.js +176 -0
  172. package/dist/runner/reflect-hook.d.ts +1 -0
  173. package/dist/runner/reflect-hook.js +3 -3
  174. package/dist/runner/runner.js +47 -12
  175. package/dist/runner/spec-holds.d.ts +8 -3
  176. package/dist/runner/spec-holds.js +12 -10
  177. package/dist/runner/store-port.d.ts +4 -1
  178. package/dist/runner/store-secrets.js +17 -1
  179. package/dist/runner/subagent.d.ts +44 -0
  180. package/dist/runner/subagent.js +188 -0
  181. package/dist/runner/workflow-host.d.ts +18 -2
  182. package/dist/runner/workflow-host.js +23 -3
  183. package/dist/runner/workflow-loop.d.ts +5 -2
  184. package/dist/runner/workflow-loop.js +9 -8
  185. package/dist/runner/workflow-spec.d.ts +26 -14
  186. package/dist/runner/workflow-spec.js +97 -30
  187. package/dist/runs-over-store.d.ts +11 -6
  188. package/dist/runs-over-store.js +111 -24
  189. package/dist/sealing.js +1 -2
  190. package/dist/secret-cut.d.ts +1 -1
  191. package/dist/secret-cut.js +1 -1
  192. package/dist/server.d.ts +32 -49
  193. package/dist/server.js +249 -199
  194. package/dist/store/agent-body.d.ts +9 -2
  195. package/dist/store/agent-body.js +16 -8
  196. package/dist/store/deadline.js +9 -5
  197. package/dist/store/index.d.ts +3 -3
  198. package/dist/store/index.js +2 -2
  199. package/dist/store/journal/storage.js +2 -1
  200. package/dist/store/postgres/connection.js +9 -4
  201. package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
  202. package/dist/store/schema.d.ts +2 -1
  203. package/dist/store/schema.js +11 -8
  204. package/dist/store/seal.d.ts +13 -0
  205. package/dist/store/seal.js +19 -0
  206. package/dist/store/sqlite/connection.d.ts +5 -0
  207. package/dist/store/sqlite/connection.js +88 -47
  208. package/dist/store/sqlite/run-patch.d.ts +18 -2
  209. package/dist/store/sqlite/run-patch.js +31 -2
  210. package/dist/store/sqlite/store.js +65 -11
  211. package/dist/store/store.d.ts +62 -12
  212. package/dist/store/store.js +22 -1
  213. package/dist/store-reads/analytics.js +3 -2
  214. package/dist/store-reads/cap.d.ts +1 -3
  215. package/dist/store-reads/cap.js +8 -6
  216. package/dist/store-reads/decisions.d.ts +2 -2
  217. package/dist/store-reads/decisions.js +3 -6
  218. package/dist/store-reads/journal.js +45 -12
  219. package/dist/store-reads/learning.d.ts +15 -1
  220. package/dist/store-reads/learning.js +68 -10
  221. package/dist/store-reads/runs.d.ts +6 -4
  222. package/dist/store-reads/runs.js +17 -10
  223. package/dist/store-reads/stats.js +5 -1
  224. package/dist/store-view.js +45 -19
  225. package/dist/template-eval.js +2 -1
  226. package/dist/templates.d.ts +64 -0
  227. package/dist/templates.js +101 -16
  228. package/dist/timeline/timeline.d.ts +3 -1
  229. package/dist/timeline/timeline.js +19 -4
  230. package/dist/tool-blurbs.js +1 -0
  231. package/dist/tool-budget.d.ts +8 -0
  232. package/dist/tool-budget.js +7 -1
  233. package/dist/tool-gate.d.ts +7 -1
  234. package/dist/tool-gate.js +7 -2
  235. package/dist/tool-plane.d.ts +33 -19
  236. package/dist/tool-plane.js +64 -27
  237. package/dist/tools.d.ts +18 -34
  238. package/dist/tools.js +104 -70
  239. package/dist/trigger-signatures.d.ts +1 -0
  240. package/dist/trigger-signatures.js +3 -1
  241. package/dist/triggers.d.ts +3 -3
  242. package/dist/triggers.js +2 -2
  243. package/dist/turn-end.d.ts +0 -3
  244. package/dist/turn-end.js +0 -3
  245. package/dist/usage-lines.d.ts +1 -1
  246. package/dist/validate.d.ts +6 -0
  247. package/dist/validate.js +30 -3
  248. package/dist/webhooks.d.ts +2 -1
  249. package/dist/webhooks.js +5 -2
  250. package/dist/workflow/decision-recovery.d.ts +23 -0
  251. package/dist/workflow/decision-recovery.js +80 -0
  252. package/dist/workflow/decisions.d.ts +134 -0
  253. package/dist/workflow/decisions.js +46 -0
  254. package/dist/workflow/host-session.d.ts +5 -0
  255. package/dist/workflow/host-session.js +85 -0
  256. package/dist/workflow/host-tools.d.ts +3 -0
  257. package/dist/workflow/host-tools.js +3 -0
  258. package/dist/workflow/node-runner.d.ts +112 -0
  259. package/dist/workflow/node-runner.js +270 -0
  260. package/dist/workflow/node.d.ts +88 -0
  261. package/dist/workflow/node.js +99 -0
  262. package/dist/workflow/operator-error.d.ts +4 -0
  263. package/dist/workflow/operator-error.js +4 -0
  264. package/dist/workflow/pi-versions.d.ts +9 -0
  265. package/dist/workflow/pi-versions.js +8 -0
  266. package/dist/workflow/readers.d.ts +36 -0
  267. package/dist/workflow/readers.js +145 -0
  268. package/dist/workflow/record-file.d.ts +10 -0
  269. package/dist/workflow/record-file.js +56 -0
  270. package/dist/workflow/record-tool.d.ts +76 -0
  271. package/dist/workflow/record-tool.js +126 -0
  272. package/dist/workflow/record.d.ts +151 -0
  273. package/dist/workflow/record.js +401 -0
  274. package/dist/workflow/run-error.d.ts +16 -0
  275. package/dist/workflow/run-error.js +26 -0
  276. package/dist/workflow/runner.d.ts +6 -0
  277. package/dist/workflow/runner.js +240 -0
  278. package/dist/workflow/store.d.ts +23 -0
  279. package/dist/workflow/store.js +242 -0
  280. package/dist/workflow/task.d.ts +133 -0
  281. package/dist/workflow/task.js +411 -0
  282. package/dist/workflow/thinking.d.ts +3 -0
  283. package/dist/workflow/thinking.js +7 -0
  284. package/dist/workflow/tool-context.d.ts +21 -0
  285. package/dist/workflow/tool-context.js +13 -0
  286. package/dist/workflow/types.d.ts +126 -0
  287. package/dist/workflow/types.js +1 -0
  288. package/dist/workflow/wal.d.ts +11 -0
  289. package/dist/workflow/wal.js +106 -0
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/agent-computer.d.ts +137 -0
  292. package/dist/workspace/agent-computer.js +292 -0
  293. package/dist/workspace/archil-claim.d.ts +11 -0
  294. package/dist/workspace/archil-claim.js +18 -10
  295. package/dist/workspace/archil-disks.d.ts +49 -0
  296. package/dist/workspace/archil-disks.js +185 -0
  297. package/dist/workspace/archil-exec.js +2 -3
  298. package/dist/workspace/archil-mount-credential.d.ts +20 -4
  299. package/dist/workspace/archil-mount-credential.js +13 -4
  300. package/dist/workspace/computer-deps.d.ts +16 -8
  301. package/dist/workspace/computer-deps.js +18 -7
  302. package/dist/workspace/computer-for-claim.d.ts +42 -6
  303. package/dist/workspace/computer-for-claim.js +209 -9
  304. package/dist/workspace/computer-janitor.d.ts +3 -2
  305. package/dist/workspace/computer-janitor.js +43 -9
  306. package/dist/workspace/computer-ledger.d.ts +3 -1
  307. package/dist/workspace/computer-ledger.js +7 -0
  308. package/dist/workspace/index.d.ts +3 -2
  309. package/dist/workspace/index.js +1 -0
  310. package/dist/workspace/resolve-computer.d.ts +42 -11
  311. package/dist/workspace/resolve-computer.js +65 -13
  312. package/dist/workspace/run-disk.d.ts +34 -0
  313. package/dist/workspace/run-disk.js +91 -0
  314. package/dist/workspace/run-tools.d.ts +4 -4
  315. package/dist/workspace/run-tools.js +8 -6
  316. package/dist/workspace/server-run-workspace.d.ts +3 -2
  317. package/dist/workspace/server-run-workspace.js +17 -4
  318. package/dist/workspace.js +1 -1
  319. package/package.json +10 -15
  320. package/templates/README.md +9 -6
  321. package/templates/code-review/agent.md +27 -11
  322. package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
  323. package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
  324. package/templates/code-review/evals/injection/graders/ignores.md +1 -1
  325. package/templates/code-review/evals/never-flag/case.yaml +3 -0
  326. package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
  327. package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
  328. package/templates/code-review/evals/never-flag/prompt.md +30 -0
  329. package/templates/code-review/evals/null-name/graders/finds.md +1 -1
  330. package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
  331. package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
  332. package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
  333. package/templates/code-review/evals/re-review/prompt.md +1 -1
  334. package/templates/code-review/evals/re-review-open/case.yaml +3 -0
  335. package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
  336. package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
  337. package/templates/code-review/evals/re-review-open/prompt.md +27 -0
  338. package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
  339. package/templates/code-review/evals/two-defects/case.yaml +3 -0
  340. package/templates/code-review/evals/two-defects/graders/both.md +4 -0
  341. package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
  342. package/templates/code-review/evals/two-defects/prompt.md +25 -0
  343. package/templates/code-review/findings.schema.json +131 -27
  344. package/templates/code-review/rules/CODEREVIEW.md +76 -0
  345. package/templates/code-review/skills/review/DEEP.md +130 -0
  346. package/templates/code-review/skills/review/REVIEWER.md +116 -0
  347. package/templates/code-review/skills/review/SKILL.md +104 -154
  348. package/dist/box/record.d.ts +0 -6
  349. package/dist/box/record.js +0 -41
  350. package/dist/box/sweep.d.ts +0 -53
  351. package/dist/box/sweep.js +0 -193
  352. package/dist/box-egress-vm.d.ts +0 -118
  353. package/dist/box-egress-vm.js +0 -354
  354. package/dist/box-egress.d.ts +0 -105
  355. package/dist/box-egress.js +0 -256
  356. package/dist/box-relay-vm.d.ts +0 -84
  357. package/dist/box-relay-vm.js +0 -437
  358. package/dist/box-relay.d.ts +0 -36
  359. package/dist/box-relay.js +0 -207
  360. package/dist/boxes.d.ts +0 -109
  361. package/dist/boxes.js +0 -249
  362. package/dist/budget.d.ts +0 -71
  363. package/dist/budget.js +0 -199
  364. package/dist/console/assets/index-B7NKTU8E.css +0 -1
  365. package/dist/console/assets/index-CXZMgJE7.js +0 -550
  366. package/dist/daytona-api.d.ts +0 -10
  367. package/dist/daytona-api.js +0 -20
  368. package/dist/egress-proxy.d.ts +0 -45
  369. package/dist/egress-proxy.js +0 -416
  370. package/dist/egress-table.d.ts +0 -24
  371. package/dist/egress-table.js +0 -165
  372. package/templates/code-review/rules/REVIEW.md +0 -41
@@ -46,15 +46,14 @@ import { PAUSED_WORDS } from "./workflow-loop.js";
46
46
  import { heldRedactor, holdClaimed } from "./redact.js";
47
47
  import { holdStored } from "./store-secrets.js";
48
48
  import { workflowHost } from "./workflow-host.js";
49
+ import { SUBMIT_TOOL } from "../workflow/host-tools.js";
49
50
  import { bookedSpend } from "./metrics.js";
50
- /** A model node's submit tool, by name: pi's SUBMIT_TOOL (packages/pi/src/host-tools.ts). Named here, not imported from
51
- * @parcha/agentrun-pi, whose root loads its runner and with it pi-coding-agent, an optional peer an installed server
52
- * does not have: importing it here stopped the runner from starting. workflow-submit-name.test.mjs holds the two equal. */
53
- export const SUBMIT_TOOL = "submit";
54
51
  /** The one session key the workflow's model requests book under (the run's one booking sums it, runBooking). */
55
52
  const SESSION = WORKFLOW_SESSION;
56
- /** A call node's tool failure, as app.ts's runEffect completed it (the loop's `failing` reads it). */
53
+ /** A call node's tool failure and a cap-held effect, as the runner's effect completed them (the loop's `failing` reads the
54
+ * first; holdAtEffects reads the second). */
57
55
  const TOOL_FAILED = "agentrun_serve_tool_failed";
56
+ const CAP_HELD = "agentrun_serve_cap_held";
58
57
  /** A tier's provider from the runner's model route (model-route.ts routeOf), the one way the runner resolves a model
59
58
  * (the pi adapter's path): the route's provider, model and price for the proxy's booking, and the catalog's cost and
60
59
  * output ceiling as the cap prices the hold. So a workflow model node and a pi turn book the same model the same way. */
@@ -170,6 +169,8 @@ export function workflowSpecOf(deps) {
170
169
  const hooks = deferredHooks();
171
170
  // The call nodes' effects in flight: a model request inside one is not where a pause lands (pauseAtEffects).
172
171
  const flight = { count: 0 };
172
+ // The workflow's steps under way, by label: a model request the cap holds names its node when one step alone is open.
173
+ const steps = openSteps();
173
174
  // What a model node offers its model: its `submit` and the tools its node names. The session proxy's policy drops every
174
175
  // tool definition it is not given, so it admits this whole set by name (as pi's admits its session's tools); main's
175
176
  // nodes send their requests straight to the provider (app.ts:117), unfiltered.
@@ -260,6 +261,13 @@ export function workflowSpecOf(deps) {
260
261
  hooks.setPark(loopHooks);
261
262
  const hostDeps = {
262
263
  modelOf,
264
+ // Each model node's execution, kept on the node log (KINDS.nodeModel) before it runs: its path, the tier it asked
265
+ // for and the model id that tier's route sends it to, so the run's graph says what each execution ran on, and a
266
+ // later claim with another model of the tier never rewrites an earlier one's.
267
+ onModelNode: async ({ executionPath, tier }) => {
268
+ await nodeLog?.append([{ kind: KINDS.nodeModel, data: { path: executionPath, ...(tier ? { tier } : {}), model: modelOf(tier).modelId } }]);
269
+ },
270
+ steps,
263
271
  // The nodes' tools as the registry holds them (their booked registrations, never their bindings' own raw ones, which
264
272
  // would book beside the run's ledger), and the run's gate over them by name (main's registry.install).
265
273
  sharedExtensions: [nodeToolGate(nodeNames, nodePolicy), ...[...nodeTools.values()].flatMap((binding) => binding.extensions)],
@@ -274,12 +282,13 @@ export function workflowSpecOf(deps) {
274
282
  // A person's pause holds a call node before its effect starts (before the engine admits it), as main's gate did;
275
283
  // a call node's tool failure the driver recorded as its effect's outcome is thrown past the driver
276
284
  // (failingEffects, main's `failing`), on the first run and on a resume that answers it from its receipt alike.
277
- // Before admission too, each call's most cost is held on the run's one ledger (holdAtEffects): a hold the cap
278
- // refuses for room parks the run there, never admitted.
285
+ // Once the engine has admitted it, each call's most cost is held on the run's one ledger (holdAtEffects): a hold
286
+ // the cap refuses for room ends the effect held, nothing sent, and parks the run once that end is durable.
279
287
  cap: pauseAtEffects(holdAtEffects(failingEffects(decisions ? decisionWorkflowCap(() => decisionCap, decisions, hooks) : identityWorkflowCap()), {
280
288
  paid: () => paidTools,
281
289
  holdOf: (tool, input) => callHoldOf(tool, input, callEnv, tierModel),
282
290
  park: (refusal) => hooks.park(refusal),
291
+ flush: () => deps.store.flush(),
283
292
  }), hooks, flight),
284
293
  };
285
294
  return workflowHost(hostDeps);
@@ -299,7 +308,7 @@ export function workflowSpecOf(deps) {
299
308
  key: SESSION,
300
309
  label: SESSION,
301
310
  // The model booking is the run's rule itself (no second booking); a refusal parks the run through the loop's hook.
302
- beforeRequest: parkOnRefusal(run.before, hooks, flight),
311
+ beforeRequest: parkOnRefusal(run.before, hooks, flight, steps),
303
312
  onEvent: async (event) => { if (event.type === "request_start")
304
313
  await deps.store.flush(); },
305
314
  });
@@ -331,7 +340,7 @@ export function workflowSpecOf(deps) {
331
340
  /** 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
332
341
  * the run parks through the loop's hook (parkOf decides room vs for good from the refusal), the same as the pi adapter's
333
342
  * parkAtCap. It still returns the refusal, so the proxy refuses the request and the node's turn ends. */
334
- export function parkOnRefusal(before, hooks, flight = { count: 0 }) {
343
+ export function parkOnRefusal(before, hooks, flight = { count: 0 }, steps) {
335
344
  const park = hooks.park;
336
345
  return async (request) => {
337
346
  // A person's pause in force parks the run here, before the request is sent, as a refusal does: the request is
@@ -349,11 +358,33 @@ export function parkOnRefusal(before, hooks, flight = { count: 0 }) {
349
358
  // words instead (the net under the call's hold, holdAtEffects).
350
359
  if (verdict && "refuse" in verdict && flight.count === 0) {
351
360
  const refusal = verdict;
352
- park({ message: refusal.refuse, forGood: refusal.forGood ?? true, ...(refusal.figures ? { figures: refusal.figures } : {}) });
361
+ // Its node: the one workflow step under way (every model request goes through the run's one port, which names no
362
+ // node); none when several run at once, as a map's items do.
363
+ const node = steps?.only();
364
+ park({ message: refusal.refuse, forGood: refusal.forGood ?? true, ...(refusal.figures ? { figures: refusal.figures } : {}), ...(node !== undefined ? { node } : {}) });
353
365
  }
354
366
  return verdict;
355
367
  };
356
368
  }
369
+ export function openSteps() {
370
+ const open = new Map();
371
+ return {
372
+ start: (label) => void open.set(label, (open.get(label) ?? 0) + 1),
373
+ end: (label) => {
374
+ const left = (open.get(label) ?? 0) - 1;
375
+ if (left > 0)
376
+ open.set(label, left);
377
+ else
378
+ open.delete(label);
379
+ },
380
+ only: () => {
381
+ if (open.size !== 1)
382
+ return undefined;
383
+ const [[label, count]] = [...open];
384
+ return count === 1 ? label : undefined;
385
+ },
386
+ };
387
+ }
357
388
  /** `cap` with a person's pause before each call node's effect starts: applied outside the cap's own effect wrapper, which
358
389
  * is outside the engine's recovery wrapper (the one that admits the effect, dsl recovery/driver.ts wrapEffect), so a
359
390
  * paused call node is never admitted. A pause in force parks the run there (hooks.pause, which aborts the node's
@@ -450,7 +481,7 @@ export function callHoldOf(tool, input, env, modelOfTier) {
450
481
  return NO_HOLD(tool);
451
482
  const fee = tool === "web_search" ? parallelSearchFee(searchArgs(input).n) : parallelExtractFee(1);
452
483
  // Who charges for it (main's charge row's charged_by), as paidOn names it: the hold is the record its request books under.
453
- return { usd: fee.usd, name: fee.name, tool, basis: fee.basis, chargedBy: fee.by };
484
+ return { usd: fee.usd, name: fee.name, basis: fee.basis, chargedBy: fee.by };
454
485
  }
455
486
  if (tool === "llm") {
456
487
  const model = modelOfTier(typeof input.tier === "string" ? input.tier : undefined);
@@ -500,38 +531,72 @@ function reservedBooking(held) {
500
531
  settle: async (_id, usd) => settleReservation(held, usd),
501
532
  };
502
533
  }
503
- /** `cap` with each call node's most cost held on the run's one ledger before the engine admits its effect: applied
504
- * outside the cap's effect wrapper (and the engine's recovery wrapper, which admits it), as the pause is. A hold the cap
505
- * refuses for room parks the run there (`hooks.park`, as a model request's refusal does) and the effect, never admitted,
506
- * waits on the node's signal; one refused for good fails the call in the cap's words. Held, the effect runs with the
507
- * hold as its reservation; what is not taken is given back at its end. After it, the net: a call whose answer cost more
508
- * than its hold (an `llm` answer priced at its usage) fails in the cap's words. */
534
+ /** `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
535
+ * its effect (dsl recovery/driver.ts wrapEffect: the effect is committed admitted before it is dispatched, and one
536
+ * admitted and never completed is never dispatched again):
537
+ * - `admittedEffect`, the effect the driver runs once it has admitted it: the call is priced (`holdOf`) and its hold
538
+ * taken (its record made durable before anything is sent), so a hold is never kept for an effect the driver did not
539
+ * admit: a process that dies before the admission leaves nothing for the next claim to count beside running the call
540
+ * again, and one that dies after it leaves the effect admitted, which the next claim never runs again, under the one
541
+ * hold it counts. Held, the effect runs with the hold as its reservation; what is not taken is given back at its end.
542
+ * A hold the cap refuses ends the effect completed with nothing sent: refused for room, as held (CAP_HELD); refused
543
+ * for good, as the call's failure in the cap's words (TOOL_FAILED). So does the net: a call whose answer cost more
544
+ * than its hold (an `llm` answer priced at its usage).
545
+ * - `effect`, outside the driver: an effect this process ended held parks the run (`park`, as a model request's refusal
546
+ * does) once that end is durable (`flush`), and waits on the node's signal. One an earlier claim ended held (its
547
+ * receipt, replayed) is the park that claim made: the call goes again, a new effect judged at this claim's cap. */
509
548
  export function holdAtEffects(cap, deps) {
510
549
  let seq = 0;
550
+ /** The held ends this process made, by the outcome the driver completed each effect with, and the cap's refusal. */
551
+ const heldHere = new WeakMap();
552
+ // A returned failure (`ok: false`): a continuation never answers a call from it.
553
+ const failed = (label, words) => ({ ok: false, [TOOL_FAILED]: `call node "${label}": ${words}` });
511
554
  return {
512
555
  ...cap,
513
556
  effect: (fn) => {
514
557
  const inner = cap.effect(fn);
558
+ return (async (params) => {
559
+ for (;;) {
560
+ const value = await inner(params);
561
+ if (!value || typeof value !== "object" || !Object.hasOwn(value, CAP_HELD))
562
+ return value;
563
+ const refused = heldHere.get(value);
564
+ // An earlier claim's park at this call (its receipt): the raise this claim took sends the call again.
565
+ if (!refused)
566
+ continue;
567
+ heldHere.delete(value);
568
+ // The effect's held end lands before the run parks, so the next claim replays it and goes again.
569
+ await deps.flush();
570
+ deps.park({ message: refused.message, forGood: false, ...(refused.figures ? { figures: refused.figures } : {}) });
571
+ const signal = params.signal;
572
+ if (signal && !signal.aborted)
573
+ await new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
574
+ throw signal?.reason ?? refused;
575
+ }
576
+ });
577
+ },
578
+ admittedEffect: (fn) => {
579
+ const inner = (cap.admittedEffect ? cap.admittedEffect(fn) : fn);
515
580
  return (async (params) => {
516
581
  const tool = params.node.tool;
517
- const hold = tool ? deps.holdOf(tool, params.input ?? {}) : undefined;
518
582
  const paid = deps.paid();
583
+ const hold = tool && paid ? deps.holdOf(tool, params.input ?? {}) : undefined;
519
584
  if (!hold || hold.usd <= 0 || !paid)
520
585
  return inner(params);
521
586
  const call = `${params.node.label}@${params.executionPath ?? ""}`;
522
- const id = `${call}#hold${(seq += 1)}`;
587
+ // Keyed by the effect the driver admitted, so a later claim never writes a second hold under the same id.
588
+ const id = `${call}#${params.effect?.id ?? `hold${(seq += 1)}`}`;
523
589
  try {
524
- await paid.admit({ id, name: hold.name, ...(hold.tool ? { tool: hold.tool } : {}), holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
590
+ await paid.admit({ id, name: hold.name, holdUsd: hold.usd, basis: hold.basis, call, ...(hold.chargedBy ? { chargedBy: hold.chargedBy } : {}) });
525
591
  }
526
592
  catch (error) {
527
593
  if (error instanceof CapRefused && !error.forGood) {
528
- deps.park({ message: error.message, forGood: false, ...(error.figures ? { figures: error.figures } : {}) });
529
- const signal = params.signal;
530
- if (signal && !signal.aborted)
531
- await new Promise((resolve) => signal.addEventListener("abort", () => resolve(), { once: true }));
532
- throw signal?.reason ?? error;
594
+ // Held, nothing sent: an outcome a continuation never answers a call from (`ok: false`, a returned failure).
595
+ const outcome = { ok: false, [CAP_HELD]: error.message };
596
+ heldHere.set(outcome, error);
597
+ return outcome;
533
598
  }
534
- throw new EffectFailure(`call node "${params.node.label}": ${error?.message ?? String(error)}`, null, { code: null });
599
+ return failed(params.node.label, error?.message ?? String(error));
535
600
  }
536
601
  const held = { id, call, hold, paid, taken: false, settled: false };
537
602
  try {
@@ -541,7 +606,7 @@ export function holdAtEffects(cap, deps) {
541
606
  if (usage && hold.llm?.price) {
542
607
  const charged = pricingOf(hold.llm.price)({ cached: 0, fresh: usage.input_tokens ?? 0 }, usage.output_tokens ?? 0);
543
608
  if (charged > hold.usd + 1e-12)
544
- throw new EffectFailure(`call node "${params.node.label}": its answer cost ${money(charged)}, above the ${money(hold.usd)} it held before it ran.`, null, { code: null });
609
+ return failed(params.node.label, `its answer cost ${money(charged)}, above the ${money(hold.usd)} it held before it ran.`);
545
610
  }
546
611
  return value;
547
612
  }
@@ -642,7 +707,7 @@ function runEffectOf(claimed, complete, env, policy, paidTools, log) {
642
707
  await logged({ t: "effect.end", ...at, status: "failed", error: message.slice(0, 65_536), ...(message.length > 65_536 ? { error_truncated: true } : {}), at: new Date().toISOString() });
643
708
  if (signal.aborted || error?.name === "AbortError")
644
709
  throw error;
645
- return { [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
710
+ return { ok: false, [TOOL_FAILED]: `call node "${node.label}": ${node.tool} failed: ${message.slice(0, 500)}` };
646
711
  }
647
712
  });
648
713
  }
@@ -784,8 +849,10 @@ async function decisionRequestOf(provider, params) {
784
849
  const questions = Object.keys(params.questions).length;
785
850
  const images = Object.keys(params.images ?? {}).length;
786
851
  const base = { kind: "decision", id, inputTokens, questions, images };
852
+ // Parallel charges by the request, nothing by the token: priced at $0 a token and its request price, never as a model
853
+ // with no price (which the cap refuses, failing every capped workflow's Parallel decision).
787
854
  if (provider.id === "parallel")
788
- return { ...base, model: openrouterModel("parallel", null, null), requestUsd: PARALLEL_DECISION_USD };
855
+ return { ...base, model: openrouterModel("parallel", { input: 0, output: 0 }, null), requestUsd: PARALLEL_DECISION_USD };
789
856
  if (provider.id === "jev")
790
857
  return { ...base, model: { id: "jev", api: "openrouter", price: { input: JEV_INPUT_USD * 1e6, output: 0 }, outputCeiling: null } };
791
858
  const priced = provider;
@@ -891,7 +958,7 @@ function bookedNodeTools(binding, paid, park) {
891
958
  })),
892
959
  };
893
960
  }
894
- /** The tool names a workflow's model node offers its model: the node's `submit` (pi's SUBMIT_TOOL) and every tool the
961
+ /** The tool names a workflow's model node offers its model: the node's `submit` (SUBMIT_TOOL) and every tool the
895
962
  * workflow's model nodes name. */
896
963
  export function nodeOffer(workflow) {
897
964
  return [...new Set([SUBMIT_TOOL, ...workflowTools(workflowNodes(workflow, inspectWorkflow(workflow))).nodes])];
@@ -4,7 +4,7 @@ import { type AgentEntry, type ExternalRef } from "./agents-store.js";
4
4
  import { ApiError, type InputIssue } from "./errors.js";
5
5
  import { type LearningMode, type Seed, type Shown } from "./learning.js";
6
6
  import { type Place } from "./place.js";
7
- import { type RunLaunch } from "./run-launch.js";
7
+ import { type LaunchDisk, type RunLaunch } from "./run-launch.js";
8
8
  import { type ApprovalDecision, type RunMoment } from "./run-view.js";
9
9
  import { type NewRevision, type RunOrigin, type RunRow, type Store } from "./store/index.js";
10
10
  import { type ToolSettingsMap } from "./tool-plane.js";
@@ -51,13 +51,14 @@ export type MessageMode = "steer" | "answer" | "follow_up";
51
51
  * and never a deny of an approval. The mode is the label the v2 answer reports, from the run's moment. `queue`: the steer's
52
52
  * write when it is not this run's own (a trigger's: its firing marked with it, within its bound, store.triggers.message),
53
53
  * which may skip it, in words. */
54
- export declare function message(store: RunsStore, moment: RunMoment, content: string, { requestId, answers, origin, queue }?: {
54
+ export declare function message(store: RunsStore, moment: RunMoment, content: string, { requestId, answers, origin, queue, launchSealed }?: {
55
55
  requestId?: string;
56
56
  answers?: boolean;
57
57
  origin?: unknown;
58
58
  queue?: (command: SteerCommand) => Promise<{
59
59
  skipped: string;
60
60
  } | void>;
61
+ launchSealed?: Uint8Array;
61
62
  }): Promise<{
62
63
  mode: MessageMode;
63
64
  messageId: string;
@@ -119,6 +120,10 @@ export interface StartDeps {
119
120
  };
120
121
  /** Where a revision naming these tools and no place runs here (server.ts fallbackPlace). */
121
122
  fallbackPlace(kind: "agentic" | "workflow", tools: readonly unknown[]): Place;
123
+ /** The Archil disk the run's launch record keeps (server.ts launchDiskOf): the one its body's `archil_disk` names, else
124
+ * its agent's when it has one now; undefined for neither, or in Mode 1. A disk named in Mode 1 is refused. Absent, no
125
+ * disk is kept. */
126
+ launchDiskOf?(agentId: string, named: string | undefined): Promise<LaunchDisk | undefined>;
122
127
  /** A run's title from its input (server.ts workflowTitle), for a workflow run's title. */
123
128
  workflowTitle(name: string, input: Record<string, unknown>): string;
124
129
  /** Every secret this server never shows, for the title's redaction (server.ts serverSecrets). */
@@ -165,6 +170,8 @@ export interface StartDeps {
165
170
  * it must have a cap (a trigger's), and who its first message is from when the person did not write it. */
166
171
  export interface StartOptions {
167
172
  readonly trigger?: RunTrigger;
173
+ /** The run's launch secrets, sealed for its id once it has one (the create body's mcp_auth, server.ts). */
174
+ readonly sealed?: (runId: string) => Uint8Array;
168
175
  /** The run's title when its starter names one (a trigger's: "<Source> <name>"), else it is made from its input. */
169
176
  readonly title?: string;
170
177
  readonly origin?: RunOrigin;
@@ -176,7 +183,7 @@ export interface StartOptions {
176
183
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
177
184
  * runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
178
185
  * starts a second. */
179
- export declare function startRun(store: Pick<Store, "runs" | "runOfOrigin">, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title }?: StartOptions): Promise<RunRow>;
186
+ export declare function startRun(store: Pick<Store, "runs" | "runOfOrigin">, deps: StartDeps, entry: AgentEntry, body: Json, { trigger, origin, capped, from, title, sealed }?: StartOptions): Promise<RunRow>;
180
187
  /** An agent given inline (POST /runs): its reference in its source with the version, its name and description, and the
181
188
  * revision its checked definition makes (agents-store makeRevision), not yet stored. */
182
189
  export interface InlineAgent {
@@ -195,9 +202,7 @@ export interface InlineAgent {
195
202
  * agent already mapped to the reference is the run's (its id, its learning), so a run of a later version learns from the
196
203
  * earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
197
204
  * `origin`, a key that already started a run gets that run, as startRun's. */
198
- export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json, { origin }?: {
199
- origin?: RunOrigin;
200
- }): Promise<RunRow>;
205
+ export declare function startInline(store: Pick<Store, "runs" | "runOfOrigin" | "agents">, deps: StartDeps, inline: InlineAgent, body: Json, { origin, sealed }?: Pick<StartOptions, "origin" | "sealed">): Promise<RunRow>;
201
206
  /** A run's launch from its create body, with every check the old start made before a run started, in the same order and
202
207
  * words: the body's fields, the revision it pins, the input against its schema, the cap rules, the plane this host
203
208
  * resolves, whether the revision can run here; then its title, plane, model and learning start. Nothing is written: the
@@ -15,13 +15,13 @@ import { CAP_TOLERANCE, money } from "./cap.js";
15
15
  import { ApiError, invalid, unsupported } from "./errors.js";
16
16
  import { harnessOfBody } from "./harness.js";
17
17
  import { redacted, redactedOutput } from "./key-refusal.js";
18
- import { chooseWorkflows, LEARNING_BUDGET, learnedParts } from "./learning.js";
18
+ import { chooseWorkflows, LEARNING_BUDGET, learnedParts, learnsOf } from "./learning.js";
19
19
  import { thinkingLevel } from "./model.js";
20
20
  import { resolvePlace } from "./place.js";
21
21
  import { launchBody } from "./run-launch.js";
22
22
  import { raiseFollowUpId } from "./run-view.js";
23
23
  import { sendCommand } from "./runner/commands.js";
24
- import { ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
24
+ import { AnswerTaken, ExternalBodyConflict, RunFinal, StoreConstraint } from "./store/index.js";
25
25
  import { toolingOf } from "./tools.js";
26
26
  import { planeFor } from "./tool-plane.js";
27
27
  import { clip } from "./web-fetch-direct.js";
@@ -38,6 +38,19 @@ function importedRefusal(moment) {
38
38
  next_action: { type: "request", method: "POST", path: `/agents/${moment.agentId}/runs`, caller_supplies: ["input", "Idempotency-Key"] },
39
39
  });
40
40
  }
41
+ /** An archived run, or a run of an archived agent, takes no message: archiving closes it. Said as archived, never as
42
+ * finished, with the way back: unarchive it (or its agent), or start a new run. */
43
+ function archivedRefusal(moment) {
44
+ const own = moment.archived === "run";
45
+ const why = own ? "This run is archived" : "This run's agent is archived";
46
+ const back = own ? `unarchive it (POST /runs/${moment.id}/unarchive)` : `unarchive the agent (POST /agents/${moment.agentId}/unarchive)`;
47
+ return new ApiError("not_continuable", `${why}, so it takes no message: ${back} to go on, or start a new run of the agent.`, {
48
+ details: { reason: "archived", archived: moment.archived },
49
+ next_action: own
50
+ ? { type: "request", method: "POST", path: `/runs/${moment.id}/unarchive`, caller_supplies: [] }
51
+ : { type: "request", method: "POST", path: `/agents/${moment.agentId}/unarchive`, caller_supplies: [] },
52
+ });
53
+ }
41
54
  /** A run that has ended takes no further act: start a new run (runs.ts finished). */
42
55
  function finished(moment) {
43
56
  const status = moment.cancelled ? "cancelled" : moment.terminalKind;
@@ -113,9 +126,12 @@ export const resume = (store, moment) => pauseOrResume(store, moment, false);
113
126
  * and never a deny of an approval. The mode is the label the v2 answer reports, from the run's moment. `queue`: the steer's
114
127
  * write when it is not this run's own (a trigger's: its firing marked with it, within its bound, store.triggers.message),
115
128
  * which may skip it, in words. */
116
- export async function message(store, moment, content, { requestId, answers = true, origin, queue } = {}) {
129
+ export async function message(store, moment, content, { requestId, answers = true, origin, queue, launchSealed } = {}) {
117
130
  if (moment.importedSource !== undefined)
118
131
  throw importedRefusal(moment);
132
+ // Archiving closes a run: it, or a run of its archived agent, takes no message, said as archived (never as finished).
133
+ if (moment.archived !== undefined)
134
+ throw archivedRefusal(moment);
119
135
  // A cancelled run takes no message, whether or not its end is written yet.
120
136
  if (moment.cancelled)
121
137
  throw finished(moment);
@@ -130,15 +146,17 @@ export async function message(store, moment, content, { requestId, answers = tru
130
146
  // approval): the message is then a message like any other, below.
131
147
  if (answers && moment.kind === "agentic" && moment.waitingApprovalId !== undefined) {
132
148
  const messageId = newMessageId();
133
- const declined = await sendCommand(store, moment.id, { kind: "deny", body: { approval: moment.waitingApprovalId, note: content, by: "message" } }).then(() => true, (error) => {
134
- if (error instanceof StoreConstraint)
149
+ const declined = await sendCommand(store, moment.id, { kind: "deny", body: { approval: moment.waitingApprovalId, note: content, by: "message" } }, launchSealed ? { launchSealed } : undefined).then(() => true, (error) => {
150
+ if (error instanceof AnswerTaken)
135
151
  return false;
136
152
  throw error;
137
153
  });
138
154
  if (declined)
139
155
  return { mode: "answer", messageId };
140
156
  }
141
- if (moment.terminal)
157
+ // A person's message puts no check of the run's end in front of its steer: the store's reopen alone says whether an ended
158
+ // run opens again with it (steerOrReopen). A trigger's message to an ended run is refused here, as before.
159
+ if (queue && moment.terminal)
142
160
  throw finished(moment);
143
161
  // Paused at its cap: a message would be refused for the same room, so the cap is raised first.
144
162
  if (moment.pausedWords !== undefined) {
@@ -154,9 +172,44 @@ export async function message(store, moment, content, { requestId, answers = tru
154
172
  const queued = await queue({ kind: "steer", body });
155
173
  return { mode, messageId, ...(queued ? { skipped: queued.skipped } : {}) };
156
174
  }
157
- await sendCommand(store, moment.id, { kind: "steer", body });
175
+ await steerOrReopen(store, moment, { kind: "steer", body }, launchSealed);
158
176
  return { mode, messageId };
159
177
  }
178
+ /** The message's steer row: one door. A run the store holds final takes no new row (RunFinal); the message then goes
179
+ * through runs.reopen, which opens the run again with the steer in one transaction when the store says it may
180
+ * (reopenableWhere: an agentic run that completed, or that a person stopped, as the console offers a follow-up to both).
181
+ * Any other (cancelled, failed, a workflow's, an imported or a learning run) answers 409 finished, nothing written. */
182
+ async function steerOrReopen(store, moment, command, launchSealed) {
183
+ // The message's launch secrets (its mcp_auth, sealed) ride in the same write as its steer, whichever door takes it.
184
+ const sealed = launchSealed ? { launchSealed } : undefined;
185
+ try {
186
+ await sendCommand(store, moment.id, command, sealed);
187
+ }
188
+ catch (error) {
189
+ if (!(error instanceof RunFinal))
190
+ throw error;
191
+ try {
192
+ await store.runs.reopen(moment.id, command, sealed);
193
+ }
194
+ catch (again) {
195
+ if (!(again instanceof RunFinal))
196
+ throw again;
197
+ // Refused: another message may have opened the run again meanwhile, so the steer is sent once more, to the run now
198
+ // running. Refused that too, the run takes no message.
199
+ try {
200
+ await sendCommand(store, moment.id, command, sealed);
201
+ }
202
+ catch (last) {
203
+ if (!(last instanceof RunFinal))
204
+ throw last;
205
+ // Worded by the run's end as the store holds it now: the moment may have been read before that end (a race).
206
+ const state = (await store.runs.get(moment.id))?.state;
207
+ const terminalKind = state === "failed" ? "failed" : state === "stopped" ? "cancelled" : "completed";
208
+ throw finished({ ...moment, terminal: true, terminalKind });
209
+ }
210
+ }
211
+ }
212
+ }
160
213
  /** The raise command rows this run already has, newest last: the cap each names, and whether its runner has taken it. */
161
214
  async function raiseRows(store, runId) {
162
215
  return (await store.commands(runId, 0))
@@ -219,7 +272,7 @@ function alreadyAnswered(id, decision, ended = false) {
219
272
  * run could not resume) answers nothing, so the person may answer again. */
220
273
  async function sentAnswer(store, runId, id) {
221
274
  const row = (await store.commands(runId, 0)).find((command) => (command.kind === "approve" || command.kind === "deny") && command.refused === null && isObject(command.body) && command.body.approval === id);
222
- return row && { decision: row.kind === "approve" ? "allow" : "deny" };
275
+ return row && { decision: row.kind === "approve" ? "allow" : "deny", at: row.id };
223
276
  }
224
277
  /** How a stop or cancel written to run `runId` before `before` (a command id; absent, any) answers every call still waiting:
225
278
  * the runner reads commands in the order they were written, so it applies the stop first and withdraws (or, on a cancel,
@@ -242,9 +295,18 @@ export async function approve(store, moment, id, decision, note) {
242
295
  if (given.decision !== decision)
243
296
  throw alreadyAnswered(id, given.decision, given.ended === true);
244
297
  };
245
- const given = moment.answeredApprovals?.[id] ?? (await sentAnswer(store, moment.id, id));
246
- if (given)
298
+ const answered = moment.answeredApprovals?.[id];
299
+ if (answered)
300
+ return settle(answered);
301
+ const given = await sentAnswer(store, moment.id, id);
302
+ if (given) {
303
+ // The answer written before (this one's retry, or another) sits behind a stop or cancel the runner has not taken yet:
304
+ // it never runs, so it is told as any answer behind that stop is, never settled as taken.
305
+ const behind = await endBefore(store, moment.id, { before: given.at });
306
+ if (behind)
307
+ throw alreadyAnswered(id, behind.decision);
247
308
  return settle(given);
309
+ }
248
310
  if (!(moment.approvalIds?.has(id) ?? false))
249
311
  throw new ApiError("not_found", `The run ${moment.id} has no tool call ${id} waiting for approval.`);
250
312
  const ending = await endBefore(store, moment.id);
@@ -262,7 +324,8 @@ export async function approve(store, moment, id, decision, note) {
262
324
  const end = await endBefore(store, moment.id, { taken: true });
263
325
  throw alreadyAnswered(id, end?.decision ?? "withdrawn", end === undefined);
264
326
  }
265
- const won = error instanceof StoreConstraint ? await sentAnswer(store, moment.id, id) : undefined;
327
+ // Lost to an answer written first (the store's AnswerTaken, from its one-answer index alone): read the winner.
328
+ const won = error instanceof AnswerTaken ? await sentAnswer(store, moment.id, id) : undefined;
266
329
  if (!won)
267
330
  throw error;
268
331
  return settle(won);
@@ -272,6 +335,14 @@ export async function approve(store, moment, id, decision, note) {
272
335
  const raced = await endBefore(store, moment.id, { before: sent.id });
273
336
  if (raced)
274
337
  throw alreadyAnswered(id, raced.decision);
338
+ // That stop's end may already be written by this read: its runner took the stop and refused this answer in the same
339
+ // commit. Read the answer back: refused behind a stop or cancel, it never runs either.
340
+ const mine = (await store.commands(moment.id, 0)).find((command) => command.id === sent.id);
341
+ if (mine?.refused != null) {
342
+ const end = await endBefore(store, moment.id, { before: sent.id, taken: true });
343
+ if (end)
344
+ throw alreadyAnswered(id, end.decision);
345
+ }
275
346
  }
276
347
  // ---- start -----------------------------------------------------------------------------------------------------------
277
348
  /** A UUIDv7 run id: time-ordered, so a listing by start time is stable, and unique per run. */
@@ -291,7 +362,9 @@ const noShown = { text: (text) => text, name: (name) => name, holds: () => false
291
362
  * from and the count of all the seed's notes before the budget picked `given` (seedNotes) — or given empty, seed null and no
292
363
  * seedNotes when its seed cannot be read (a learning fault never refuses a run). */
293
364
  async function learningStartFor(deps, entry, revision, rbody, input) {
294
- const learns = deps.learning !== undefined && deps.learning !== "off" && revision.kind === "agentic" && rbody.learning === true;
365
+ const learns = deps.learning !== undefined && deps.learning !== "off" && revision.kind === "agentic" && learnsOf(rbody.learning);
366
+ // `learning: "notes"`: its notes and skills, never a learned workflow (none offered, none asked for at its end).
367
+ const notesOnly = rbody.learning === "notes" ? { notesOnly: true } : {};
295
368
  if (!learns || !deps.seedFor)
296
369
  return undefined;
297
370
  const grade = deps.gradeModel ? { gradeModel: deps.gradeModel } : {};
@@ -299,7 +372,7 @@ async function learningStartFor(deps, entry, revision, rbody, input) {
299
372
  // The folder could not be read (main's STOPPED.unreadable), or what it read could not be made into the start (main's
300
373
  // copy that threw, STOPPED.notCopied): the run starts with nothing learned, and its learning end says which.
301
374
  if (!("seed" in seeded))
302
- return { given: [], seed: null, section: "", seedFailed: "unreadable", ...grade };
375
+ return { given: [], seed: null, section: "", seedFailed: "unreadable", ...notesOnly, ...grade };
303
376
  try {
304
377
  // The run's input goes to the note selector (learning.ts NoteSelector; byRelevance, the default, scores the notes by it).
305
378
  const options = { budget: deps.learningBudget ?? LEARNING_BUDGET, read: Array.isArray(rbody.tools) && rbody.tools.includes("read"), shown: deps.shown ? deps.shown() : noShown, run: { input } };
@@ -313,11 +386,11 @@ async function learningStartFor(deps, entry, revision, rbody, input) {
313
386
  const skills = (seeded.seed.skills ?? []).flatMap(({ name, files }) => (files && !options.shown.holds(name) && !Object.entries(files).some(([path, text]) => options.shown.holds(path) || options.shown.holds(text)) ? [name] : []));
314
387
  // The learned workflows its learned_workflow tool runs, by name, as the claim chooses them (chooseWorkflows): what the
315
388
  // agent's impact counts a run as started from, beside its notes and skills.
316
- const workflows = chooseWorkflows(seeded.seed, options.shown).flows.map(({ name }) => name);
317
- return { given: given.map(({ file, name }) => ({ file, name })), seed: seeded.seed.sha, section: section ?? "", seedNotes: Object.keys(seeded.seed.notes).length, ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...grade };
389
+ const workflows = notesOnly.notesOnly ? [] : chooseWorkflows(seeded.seed, options.shown).flows.map(({ name }) => name);
390
+ return { given: given.map(({ file, name }) => ({ file, name })), seed: seeded.seed.sha, section: section ?? "", seedNotes: Object.keys(seeded.seed.notes).length, ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...notesOnly, ...grade };
318
391
  }
319
392
  catch {
320
- return { given: [], seed: null, section: "", seedFailed: "not_copied", ...grade };
393
+ return { given: [], seed: null, section: "", seedFailed: "not_copied", ...notesOnly, ...grade };
321
394
  }
322
395
  }
323
396
  /** Starts a run of `entry`'s agent from a create body, as POST /agents/{id}/runs starts it: every check the old start made
@@ -325,11 +398,11 @@ async function learningStartFor(deps, entry, revision, rbody, input) {
325
398
  * (store.runs.create), which a runner reads at its claim. No process, no door, no setup file: where the run runs is the
326
399
  * runner's. Under `origin`, a key that already started a run gets that run (the store's one-run-per-key), so a retry never
327
400
  * starts a second. */
328
- export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title } = {}) {
401
+ export async function startRun(store, deps, entry, body, { trigger, origin, capped = false, from, title, sealed } = {}) {
329
402
  const { launch, revision } = await prepareLaunch(deps, entry, body, { ...(trigger ? { trigger } : {}), capped, ...(from ? { from } : {}), ...(title !== undefined ? { title } : {}) });
330
403
  const runId = (deps.newRunId ?? uuidv7)();
331
404
  try {
332
- return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch) }));
405
+ return await withHeldFiles(deps, runId, launch, () => store.runs.create({ id: runId, agentId: entry.agent.id, revisionId: revision.id, ...(origin ? { origin } : {}) }, { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) }));
333
406
  }
334
407
  catch (error) {
335
408
  // Only another writer of the store got here first under the same origin key: its run is the one asked for.
@@ -366,14 +439,21 @@ async function withHeldFiles(deps, runId, launch, write) {
366
439
  * agent already mapped to the reference is the run's (its id, its learning), so a run of a later version learns from the
367
440
  * earlier ones. A different definition under a version already run is 409 external_body_conflict, nothing written; under
368
441
  * `origin`, a key that already started a run gets that run, as startRun's. */
369
- export async function startInline(store, deps, inline, body, { origin } = {}) {
442
+ export async function startInline(store, deps, inline, body, { origin, sealed } = {}) {
370
443
  const { external, revision } = inline;
371
444
  const ref = externalKey(external);
372
445
  const mapped = await store.agents.byExternal(ref);
373
- const entry = (mapped && (await getAgent(store, mapped.id))) || {
374
- agent: { id: uuidv7(), name: inline.name, description: inline.description, currentRevision: null, createdAt: Date.now(), archivedAt: null, externalRef: ref },
375
- revision: null, version: 0, revisions: 0, sizes: new Map(),
376
- };
446
+ const stored = mapped ? await getAgent(store, mapped.id) : null;
447
+ // A version's first run brings the agent's name and description up to it, in the start's own transaction (createInline),
448
+ // so its launch is prepared under them: a workflow run's title names the version it runs. A run of a version already
449
+ // stored keeps the agent's as they are, as a run of any agent's earlier revision does.
450
+ const firstOfVersion = !stored || !(await store.agents.hasExternalVersion(stored.agent.id, external.version));
451
+ const entry = stored
452
+ ? firstOfVersion ? { ...stored, agent: { ...stored.agent, name: inline.name, description: inline.description } } : stored
453
+ : {
454
+ agent: { id: uuidv7(), name: inline.name, description: inline.description, currentRevision: null, createdAt: Date.now(), archivedAt: null, externalRef: ref },
455
+ revision: null, version: 0, revisions: 0, sizes: new Map(),
456
+ };
377
457
  // A store revision is the revision the run path reads as a pi Revision (its body is the revision body), as pinnedOf hands
378
458
  // one across.
379
459
  const { launch } = await prepareLaunch(deps, entry, body, { revision: revision });
@@ -383,7 +463,7 @@ export async function startInline(store, deps, inline, body, { origin } = {}) {
383
463
  agent: { id: entry.agent.id, name: inline.name, description: inline.description, ref },
384
464
  revision: { id: revision.id, version: external.version, kind: revision.kind, body: revision.body, skills: revision.skills, ...(revision.note !== undefined ? { note: revision.note } : {}) },
385
465
  run: { id: runId, ...(origin ? { origin } : {}) },
386
- launch: { body: launchBody(launch) },
466
+ launch: { body: launchBody(launch), ...(sealed ? { sealed: sealed(runId) } : {}) },
387
467
  }));
388
468
  }
389
469
  catch (error) {
@@ -457,6 +537,12 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
457
537
  // the one decision) are pinned in the launch for the runner to put in the prompt. A seed that cannot be read starts it with
458
538
  // nothing (given empty, seed null); the end state is the runner's.
459
539
  const learning = await learningStartFor(deps, entry, revision, rbody, input);
540
+ // The run's Archil disk, chosen now and kept in its launch (run-launch.ts archilDisk): the one the body names (a disk per
541
+ // customer), else its agent's when it has one; with neither, its claim makes the agent's.
542
+ const named = isObject(body.archil_disk) && typeof body.archil_disk.disk_id === "string" ? body.archil_disk.disk_id : undefined;
543
+ if (named !== undefined && !deps.launchDiskOf)
544
+ throw invalid([{ field: "archil_disk", reason: "not_allowed", message: "This server keeps no run on an Archil disk." }]);
545
+ const archilDisk = deps.launchDiskOf ? await deps.launchDiskOf(entry.agent.id, named) : undefined;
460
546
  // The run's effort: its own, else its revision's saved thinking, else the host's AGENT_THINKING (each a thinking level,
461
547
  // else none). Nothing set: none, so the run gets no effort note and its harness's own default. Kept in its launch, so
462
548
  // its harness's thinking, its guidance and its metrics all read the one value.
@@ -479,6 +565,7 @@ export async function prepareLaunch(deps, entry, body, { trigger, capped = false
479
565
  ...(trigger ? { trigger } : {}),
480
566
  ...(from ? { inputOrigin: from } : {}),
481
567
  ...(model ? { model } : {}),
568
+ ...(archilDisk ? { archilDisk } : {}),
482
569
  };
483
570
  return { launch, revision };
484
571
  }
package/dist/sealing.js CHANGED
@@ -1,5 +1,4 @@
1
- // AES-256-GCM sealing, the one primitive every secret this server keeps at rest is sealed with (copied from
2
- // @parcha/pi-durable-agent's vault.ts): the store's sealed columns (store/seal.ts), the
1
+ // AES-256-GCM sealing, the one primitive every secret this server keeps at rest is sealed with (the store's sealed columns (store/seal.ts), the
3
2
  // trigger settings, the outbound webhook's secret, and what a runner opens under the server's seal key.
4
3
  import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
5
4
  const IV_BYTES = 12;
@@ -1,7 +1,7 @@
1
1
  import { keyShaped } from "./secret-name.js";
2
2
  /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
3
3
  * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
4
- * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
4
+ * The one rule: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
5
5
  * take it, so what one leaves out the others do. */
6
6
  export { keyShaped };
7
7
  export declare const REDACTED = "[redacted]";
@@ -9,7 +9,7 @@ secretLintProfiler.setEnabled(false);
9
9
  import { keyShaped } from "./secret-name.js";
10
10
  /** Whether a name is a secret's, whatever list names it or none does: one of its `_`-separated segments, in any case, is
11
11
  * KEY, TOKEN, SECRET, PASSWORD, PASSWD, PASS, PAT, CREDENTIAL, CREDENTIALS or DSN, or its last is PWD after another.
12
- * The one rule, pi-durable-disk's own: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
12
+ * The one rule: this cut, the harness log's and a run's environment (secrets.ts' withoutSecrets)
13
13
  * take it, so what one leaves out the others do. */
14
14
  export { keyShaped };
15
15
  export const REDACTED = "[redacted]";