@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
@@ -55,7 +55,7 @@ export type TriggerFailed = {
55
55
  };
56
56
  auto_paused: boolean;
57
57
  };
58
- /** A run's provenance, kept in its serve.json: the trigger that started it, and the firing. `name`: the trigger's name as
58
+ /** A run's provenance, kept with its launch row: the trigger that started it, and the firing. `name`: the trigger's name as
59
59
  * it was at the firing, put on the run so its Timeline row names the trigger without a store read (runs.ts
60
60
  * servedTriggerRow); a rename pushes the new name (server.ts triggerChanged). */
61
61
  export type RunTrigger = {
@@ -454,10 +454,10 @@ export declare class Triggers {
454
454
  * check. */
455
455
  private given;
456
456
  /** A run's title, from the trigger that starts it: "<its source> <its name>" (the word its Timeline row begins with,
457
- * pi-durable-agent's TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
457
+ * TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
458
458
  * pull_request opened"); never its input, which may be a sender's markup. */
459
459
  private titleOf;
460
- /** Who a firing's input is from (pi-durable-agent's MessageOrigin): the trigger, by its definition as it fires, never
460
+ /** Who a firing's input is from (a MessageOrigin): the trigger, by its definition as it fires, never
461
461
  * by its payload. Only a source whose words are its owner's (a schedule's, fired on time or by hand) gives owner true;
462
462
  * a pushed source's come from outside, its body empty or not. */
463
463
  private originOf;
package/dist/triggers.js CHANGED
@@ -913,7 +913,7 @@ export class Triggers {
913
913
  return { ...target, input: this.inputOf(trigger, { by: "manual", nominalAt: now, payload: null }) };
914
914
  }
915
915
  /** A run's title, from the trigger that starts it: "<its source> <its name>" (the word its Timeline row begins with,
916
- * pi-durable-agent's TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
916
+ * TRIGGER_LABELS), and the event its payload's tag names, when one does ("Webhook reviews:
917
917
  * pull_request opened"); never its input, which may be a sender's markup. */
918
918
  titleOf(trigger, firing) {
919
919
  const source = TRIGGER_LABELS[trigger.source.kind] ?? trigger.source.kind;
@@ -922,7 +922,7 @@ export class Triggers {
922
922
  const action = attrs?.action;
923
923
  return `${source} ${trigger.name}${event ? `: ${event}${action ? ` ${action}` : ""}` : ""}`;
924
924
  }
925
- /** Who a firing's input is from (pi-durable-agent's MessageOrigin): the trigger, by its definition as it fires, never
925
+ /** Who a firing's input is from (a MessageOrigin): the trigger, by its definition as it fires, never
926
926
  * by its payload. Only a source whose words are its owner's (a schedule's, fired on time or by hand) gives owner true;
927
927
  * a pushed source's come from outside, its body empty or not. */
928
928
  originOf(trigger) {
@@ -7,9 +7,6 @@ export { TURN_END } from "./timeline/index.js";
7
7
  * for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
8
8
  export declare const MESSAGE = "adapter.message";
9
9
  export declare const MESSAGE_END = "adapter.message_end";
10
- /** The root's marker of a paid request already written as a pi.assistant entry (`{ key, request, unpriced? }`, in the
11
- * entry's commit): `unpriced` when its cost was not in yet, which a REQUEST_COST_LATE naming it brings. */
12
- export declare const BOOKED = "adapter.request";
13
10
  /** What a turn's end says: the message it took (the MESSAGE id), the session's own outcome (`failed` too when the bridge
14
11
  * wrote the turn's error, in `error`), the entry of the turn's answer (its last request with text and no call; null
15
12
  * when the turn showed no text), and whether a request it made is still unbooked (its cost then comes later, as a
package/dist/turn-end.js CHANGED
@@ -10,9 +10,6 @@ export { TURN_END } from "./timeline/index.js";
10
10
  * for a message an older bridge sent and wrote no end for, the run's next process writes it as it opens. */
11
11
  export const MESSAGE = "adapter.message";
12
12
  export const MESSAGE_END = "adapter.message_end";
13
- /** The root's marker of a paid request already written as a pi.assistant entry (`{ key, request, unpriced? }`, in the
14
- * entry's commit): `unpriced` when its cost was not in yet, which a REQUEST_COST_LATE naming it brings. */
15
- export const BOOKED = "adapter.request";
16
13
  /** The `api` of every assistant message serve's bridge writes for a claude-agent or codex request (harness-app.ts): its
17
14
  * stop reason says nothing of the turn's end (a cost, a cut, an interruption and an answer read alike). */
18
15
  export const ADAPTER_API = "agentrun-adapter";
@@ -1,4 +1,4 @@
1
- /** A run's meters, from its store (cap.ts metersIn) or its live rows: each null when one of its charges is unknown. */
1
+ /** A run's meters, from the one store (store-reads/cap.ts metersOverStore) or its live rows: each null when one of its charges is unknown. */
2
2
  export type RunMeters = {
3
3
  tools: number | null;
4
4
  tokens: number | null;
@@ -9,12 +9,18 @@ export declare const isObject: (value: unknown) => value is Json;
9
9
  export declare const IDEMPOTENCY_TTL_S = 86400;
10
10
  export declare const stable: (value: unknown) => string;
11
11
  export declare const DEFINITION_FIELDS: string[];
12
+ /** What an agentic definition may ask the server to check out in each run's folder before its first turn
13
+ * (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
14
+ * `repo/`; `none` clears it on an edit. */
15
+ export declare const CHECKOUTS: readonly ["pull_request", "none"];
12
16
  /** Why a field a definition may have elsewhere has no place in an agent store's revision. */
13
17
  export declare const NOT_KEPT: Record<string, string>;
14
18
  /** The most tool calls an agent's budget (max_tool_calls, tool-budget.ts) may name. */
15
19
  export declare const MAX_TOOL_CALLS = 1000;
16
20
  /** The most bytes an agent's output_schema takes, as JSON. */
17
21
  export declare const MAX_OUTPUT_SCHEMA_BYTES: number;
22
+ /** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
23
+ export declare const MODEL_TIER_NAMES: readonly ["fast", "strong"];
18
24
  /** `provider/model-id`. */
19
25
  export declare const MODEL_REF: RegExp;
20
26
  /** A body's fields that `allowed` does not name, each as the 422's not_allowed issue. */
package/dist/validate.js CHANGED
@@ -17,7 +17,11 @@ export const isObject = (value) => typeof value === "object" && value !== null &
17
17
  /** How long an Idempotency-Key answers with its first answer (capabilities' limits.idempotency_ttl_s). */
18
18
  export const IDEMPOTENCY_TTL_S = 86_400;
19
19
  export const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(",")}]` : isObject(value) ? `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}` : JSON.stringify(value);
20
- export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls"];
20
+ export const DEFINITION_FIELDS = ["id", "version", "name", "description", "instructions", "workflow", "model", "model_tiers", "thinking", "harness", "place", "computer", "learning", "skills", "tools", "tool_settings", "approvals", "max_cost_usd", "cap_mode", "output_schema", "max_tool_calls", "checkout"];
21
+ /** What an agentic definition may ask the server to check out in each run's folder before its first turn
22
+ * (runner/pr-checkout.ts): `pull_request`, the pull request the run's GitHub event names, at its head, read-only, in
23
+ * `repo/`; `none` clears it on an edit. */
24
+ export const CHECKOUTS = ["pull_request", "none"];
21
25
  /** Why a field a definition may have elsewhere has no place in an agent store's revision. */
22
26
  export const NOT_KEPT = {
23
27
  input_schema: "The agent store keeps no input_schema: an agentic run takes {content}, and a workflow checks its input against its own schema.",
@@ -26,6 +30,8 @@ export const NOT_KEPT = {
26
30
  export const MAX_TOOL_CALLS = 1_000;
27
31
  /** The most bytes an agent's output_schema takes, as JSON. */
28
32
  export const MAX_OUTPUT_SCHEMA_BYTES = 64 * 1024;
33
+ /** The tiers an agentic revision may name a model for (`model_tiers`): those a subagent runs on (runner/subagent.ts). */
34
+ export const MODEL_TIER_NAMES = ["fast", "strong"];
29
35
  /** `provider/model-id`. */
30
36
  export const MODEL_REF = /^[^/\s]+\/\S+$/;
31
37
  const SKILL_FILE = "/SKILL.md";
@@ -79,6 +85,20 @@ export function definitionIssues(definition, { at = "definition", creating = tru
79
85
  else if (typeof d.model !== "string" || !MODEL_REF.test(d.model))
80
86
  out.push(issue(`${at}.model`, "bad_format", `${at}.model is "provider/model-id"`));
81
87
  }
88
+ if (d.model_tiers !== undefined) {
89
+ if (d.workflow !== undefined)
90
+ out.push(issue(`${at}.model_tiers`, "not_allowed", "A workflow revision keeps no model tiers: each model node names its tier, run on this host's model for it.", `Remove ${at}.model_tiers.`));
91
+ else if (!isObject(d.model_tiers) || !Object.keys(d.model_tiers).length)
92
+ out.push(issue(`${at}.model_tiers`, "wrong_type", `${at}.model_tiers is an object of ${MODEL_TIER_NAMES.join(", ")} to "provider/model-id"`));
93
+ else {
94
+ for (const [tier, ref] of Object.entries(d.model_tiers)) {
95
+ if (!MODEL_TIER_NAMES.includes(tier))
96
+ out.push(issue(`${at}.model_tiers.${tier}`, "not_allowed", `${at}.model_tiers names ${MODEL_TIER_NAMES.join(" and ")} alone`, `Remove ${at}.model_tiers.${tier}.`));
97
+ else if (typeof ref !== "string" || !MODEL_REF.test(ref))
98
+ out.push(issue(`${at}.model_tiers.${tier}`, "bad_format", `${at}.model_tiers.${tier} is "provider/model-id"`));
99
+ }
100
+ }
101
+ }
82
102
  if (d.harness !== undefined && !HARNESSES.includes(d.harness))
83
103
  out.push(issue(`${at}.harness`, "not_an_option", `${at}.harness is one of ${HARNESSES.join(", ")}`));
84
104
  if (d.place !== undefined)
@@ -94,8 +114,8 @@ export function definitionIssues(definition, { at = "definition", creating = tru
94
114
  if (d.learning !== undefined) {
95
115
  if (d.workflow !== undefined)
96
116
  out.push(issue(`${at}.learning`, "not_allowed", "A workflow revision does not learn: only an agentic run reflects on its work.", `Remove ${at}.learning.`));
97
- else if (typeof d.learning !== "boolean")
98
- out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true or false`));
117
+ else if (typeof d.learning !== "boolean" && d.learning !== "notes")
118
+ out.push(issue(`${at}.learning`, "wrong_type", `${at}.learning is true, false or "notes": true learns notes, skills and workflows, "notes" notes and skills alone`));
99
119
  }
100
120
  // An agentic revision's structured answer: the JSON Schema its final answer's last fenced json block meets, read into a
101
121
  // completed run's result.output (answer-json.ts structuredAnswer). A workflow's output is its workflow's own.
@@ -132,6 +152,13 @@ export function definitionIssues(definition, { at = "definition", creating = tru
132
152
  if (!(typeof d.max_cost_usd === "number" && Number.isFinite(d.max_cost_usd) && d.max_cost_usd >= 0))
133
153
  out.push(issue(`${at}.max_cost_usd`, "wrong_type", `${at}.max_cost_usd is a number of at least 0, in US dollars: above 0 sets the agent's default cap, 0 clears it`));
134
154
  }
155
+ // The server's checkout before each run's first turn: kept by an edit that leaves it out, cleared by `none`.
156
+ if (d.checkout !== undefined) {
157
+ if (d.workflow !== undefined)
158
+ out.push(issue(`${at}.checkout`, "not_allowed", "A workflow revision keeps no checkout: only an agentic run starts in a checkout.", `Remove ${at}.checkout.`));
159
+ else if (!CHECKOUTS.includes(d.checkout))
160
+ out.push(issue(`${at}.checkout`, "not_an_option", `${at}.checkout is one of ${CHECKOUTS.join(", ")}: pull_request checks out the pull request the run's GitHub event names, at its head, in repo/ before the first turn; none clears it`));
161
+ }
135
162
  // The tool calls each conversation of an agentic run may make (tool-budget.ts): above 0 sets the budget, 0 clears it, and
136
163
  // an edit that leaves it out keeps the agent's, as the default cap is kept.
137
164
  if (d.max_tool_calls !== undefined) {
@@ -58,7 +58,7 @@ export type WebhookSecret = Pick<SealedSettingsOverStore, "get" | "mint" | "remo
58
58
  export { signatureOf } from "./standard-webhooks.js";
59
59
  /** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
60
60
  * so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
61
- * asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
61
+ * asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
62
62
  * was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
63
63
  * row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
64
64
  * marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
@@ -71,6 +71,7 @@ export declare function waitMarkerOf(rows: readonly {
71
71
  id?: unknown;
72
72
  at?: unknown;
73
73
  asked_at?: unknown;
74
+ cap_usd?: unknown;
74
75
  } | null | undefined, waiting: boolean, learningLabel: string): string | undefined;
75
76
  export declare class Webhooks {
76
77
  private readonly store;
package/dist/webhooks.js CHANGED
@@ -55,7 +55,7 @@ function configOf(value) {
55
55
  }
56
56
  /** The mark of the wait a run stands at, its webhook-id's marker: one per ask, however often or whenever the run is read,
57
57
  * so every read of the same ask makes the same webhook-id. A question's is its waiting row (run-view.ts withAsks: the
58
- * asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time; a hand-over's, when it
58
+ * asked call's result, `:waiting`); an approval's, the call it holds; a budget pause's, its time and its cap; a hand-over's, when it
59
59
  * was asked; a stop, which waits on no ask, the last row that shows (not usage, a phase or learning's). Never the last
60
60
  * row for an ask: a run read between the person's answer and its runner's take of it shows the answer last, and a
61
61
  * marker from that row would tell the same ask twice, under two ids. Undefined when there is none. */
@@ -66,8 +66,11 @@ export function waitMarkerOf(rows, pending, waiting, learningLabel) {
66
66
  const kind = pending?.kind;
67
67
  if (kind === "approval" && typeof pending?.id === "string")
68
68
  return `approval:${pending.id}`;
69
+ // A pause at the cap, by when it came and the cap it waits at: waits at one cap are one pause, told once, and a raise that
70
+ // still does not cover the step pauses the run anew at the higher cap, told again (the runner writes no row for the
71
+ // refused step, so its time alone would not move).
69
72
  if (kind === "budget" && typeof pending?.at === "string")
70
- return `budget:${pending.at}`;
73
+ return `budget:${pending.at}${typeof pending.cap_usd === "number" ? `:${pending.cap_usd}` : ""}`;
71
74
  if ((kind === "browser" || kind === "computer") && typeof pending?.asked_at === "string")
72
75
  return `${kind}:${pending.asked_at}`;
73
76
  return rows.findLast((r) => r.kind === "waiting")?.id ?? last();
@@ -0,0 +1,23 @@
1
+ import { type DecisionExchange, type DecisionReceipt } from "@parcha/agentrun-dsl";
2
+ import type { DocumentReader } from "@earendil-works/pi-durable";
3
+ import type { WorkflowInvocation } from "./task.js";
4
+ type Context = WorkflowInvocation["context"];
5
+ /** The interpreter's two decision hooks over one invocation of a workflow task. */
6
+ export type DecisionRecovery = {
7
+ /** The interpreter's `recordDecision`: commits the receipt's row after every row recorded before it, and resolves
8
+ * once that commit is durable; a commit that fails rejects this receipt's call. The task's state is untouched. */
9
+ recordDecision(receipt: DecisionReceipt, exchange: DecisionExchange): Promise<void>;
10
+ /** The interpreter's `recovery.decision`: the receipt rebuilt from the last answered row this run recorded under
11
+ * `id`, or undefined when it recorded none (a request that failed, one recorded without its identity, or one another
12
+ * run recorded, is asked again). */
13
+ decision(id: string): Promise<DecisionReceipt | undefined>;
14
+ };
15
+ /** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
16
+ * handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
17
+ * `recovery.decision` beside the driver's recovery hooks. */
18
+ export declare function decisionRecovery(invocation: {
19
+ key: string;
20
+ runtime: Pick<WorkflowInvocation["runtime"], "commit"> & DocumentReader;
21
+ context: Context;
22
+ }): DecisionRecovery;
23
+ export {};
@@ -0,0 +1,80 @@
1
+ // A workflow task's decision receipts, durable in its run's Session: each receipt is a row (decisions.ts) committed
2
+ // through the task's own commit before the interpreter acts on its answers, and a resumed run's request is answered
3
+ // from the row its earlier process committed, so the judge is not asked again and the run decides what it decided.
4
+ // Every run in the Session shares the rows' document, and a receipt's id does not name its run, so each row carries
5
+ // the run's key and a run is answered only from its own rows.
6
+ import { DECISION_RECEIPT_VERSION } from "@parcha/agentrun-dsl";
7
+ import { appendDecision, DECISION_ROW_VERSION, readDecisionsFrom } from "./decisions.js";
8
+ /** What a receipt says of its provider beside its answers, each only when present: who answered, the sources, the
9
+ * questions refused, where each confidence came from, the images it carried and the state the judge saw. A replay gives the run all of it again. */
10
+ const kept = (from) => ({
11
+ ...(from.provider !== undefined ? { provider: from.provider } : {}),
12
+ ...(from.images !== undefined ? { images: from.images } : {}),
13
+ ...(from.cost_basis !== undefined ? { cost_basis: from.cost_basis } : {}),
14
+ ...(from.state !== undefined ? { state: from.state, state_truncated: from.state_truncated === true } : {}),
15
+ ...(from.evidence !== undefined ? { evidence: from.evidence } : {}),
16
+ ...(from.refused !== undefined ? { refused: from.refused } : {}),
17
+ ...(from.confidence_source !== undefined ? { confidence_source: from.confidence_source } : {}),
18
+ });
19
+ /** A receipt as the row the run `key` stores: the receipt's own fields, its identity, and the request's size. */
20
+ function rowOf(receipt, exchange, key) {
21
+ return {
22
+ v: DECISION_ROW_VERSION, at: receipt.at, node: receipt.node, kind: receipt.kind, item: receipt.item, execution_path: receipt.execution_path,
23
+ request_sha256: receipt.request_sha256,
24
+ request_bytes: Buffer.byteLength(JSON.stringify({ state: exchange.request.state, questions: exchange.request.questions })),
25
+ model: receipt.model, questions: receipt.questions, answers: receipt.answers, rule: receipt.rule, action: receipt.action,
26
+ usage: receipt.usage, cost_usd: receipt.cost_usd, latency_ms: receipt.latency_ms,
27
+ // An error the receipt kept cut says so, and the row keeps saying it: a host holds its tail back (serve graph-served.ts).
28
+ ...(receipt.error !== undefined ? { error: receipt.error, ...(receipt.error_truncated === true ? { error_truncated: true } : {}) } : {}),
29
+ status: receipt.status, ...kept(receipt),
30
+ decision_id: receipt.id, request: receipt.request, state_sha256: receipt.state_sha256, run_key: key,
31
+ };
32
+ }
33
+ /** The receipt the run `key`'s last answered row under `id` is: a rule is set only on an answered receipt, and an
34
+ * answered one carries no error. */
35
+ function answeredReceipt(rows, id, key) {
36
+ const row = rows.findLast((stored) => stored.run_key === key && stored.decision_id === id && stored.rule !== null && stored.error === undefined
37
+ && stored.request !== undefined && stored.state_sha256 !== undefined && stored.execution_path !== null);
38
+ if (!row)
39
+ return undefined;
40
+ return {
41
+ v: DECISION_RECEIPT_VERSION, id, at: row.at, node: row.node, kind: row.kind, item: row.item, execution_path: row.execution_path,
42
+ request: row.request, status: "answered", state_sha256: row.state_sha256,
43
+ questions: row.questions, answers: row.answers, rule: row.rule, action: row.action,
44
+ model: row.model, usage: row.usage, cost_usd: row.cost_usd, request_sha256: row.request_sha256, latency_ms: row.latency_ms,
45
+ ...kept(row),
46
+ };
47
+ }
48
+ /** The decision hooks a durable host gives the interpreter inside `WorkflowTaskHost.run`, over the invocation it is
49
+ * handed (the run's key, the task's runtime and context): `recordDecision` as the interpreter's own, and `decision` as
50
+ * `recovery.decision` beside the driver's recovery hooks. */
51
+ export function decisionRecovery(invocation) {
52
+ const { key, runtime, context } = invocation;
53
+ const harness = {
54
+ commit: async (change) => {
55
+ let result;
56
+ await runtime.commit(async (tx) => { result = await change(tx); return undefined; }, context);
57
+ return result;
58
+ },
59
+ // The form the store holds is settled once per invocation, from this reader: the run's open.
60
+ snapshot: ((...args) => runtime.snapshot(...args)),
61
+ };
62
+ // The run's rows as read so far: a resumed process reads the store once, and each later answer reads only the rows after them.
63
+ const known = [];
64
+ let next = 0;
65
+ let chain = Promise.resolve();
66
+ return {
67
+ recordDecision(receipt, exchange) {
68
+ const row = rowOf(receipt, exchange, key);
69
+ const committed = chain.then(() => appendDecision(harness, row, context));
70
+ chain = committed.catch(() => undefined);
71
+ return committed;
72
+ },
73
+ async decision(id) {
74
+ const read = await readDecisionsFrom(harness, next, context);
75
+ known.push(...read.rows);
76
+ next = read.next;
77
+ return answeredReceipt(known, id, key);
78
+ },
79
+ };
80
+ }
@@ -0,0 +1,134 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import { type DocumentReader, type Harness } from "@earendil-works/pi-durable";
3
+ /** The session document that holds a run's decision rows. */
4
+ export declare const DECISION_RECEIPTS_DOC = "agentrun.decisions";
5
+ /** The stored row's version. */
6
+ export declare const DECISION_ROW_VERSION = 1;
7
+ /** How the answers became the action, with every threshold applied. */
8
+ export type DecisionRowRule =
9
+ /** judge: each question's decoded value (choice, noul at 0.5, rounded score). */
10
+ {
11
+ kind: "judge";
12
+ }
13
+ /** pick: the chosen option names an item by its position, or none. */
14
+ | {
15
+ kind: "pick";
16
+ options: string[];
17
+ none: string | null;
18
+ }
19
+ /** route: the chosen branch, or the unsure branch when the choice's confidence is below `gte`. */
20
+ | {
21
+ kind: "route";
22
+ unsure: {
23
+ gte: number;
24
+ branch: string;
25
+ } | null;
26
+ }
27
+ /** sift: an item is kept when its `keep` measure meets `gte`; every item without a keep rule. */
28
+ | {
29
+ kind: "sift";
30
+ items: number;
31
+ ids: string[];
32
+ keep: {
33
+ id: string;
34
+ measure: "confidence" | "value";
35
+ gte: number;
36
+ } | null;
37
+ }
38
+ /** ask: the predicate holds when p_yes meets `gte`. */
39
+ | {
40
+ kind: "ask";
41
+ gte: number;
42
+ }
43
+ /** verify: a noul question fails when p_yes is below its threshold (null: not judged, an empty field); a failed
44
+ * question the submission holds is doubted, a failed one it lacks is unmet. */
45
+ | {
46
+ kind: "verify";
47
+ thresholds: Record<string, number | null>;
48
+ present: string[];
49
+ };
50
+ /** One stored decision row. */
51
+ export type DecisionRow = {
52
+ v: typeof DECISION_ROW_VERSION;
53
+ at: string;
54
+ node: string;
55
+ kind: "judge" | "pick" | "sift" | "route" | "ask" | "verify";
56
+ item: number | null;
57
+ execution_path: string | null;
58
+ request_sha256: string | null;
59
+ request_bytes: number;
60
+ model: string | null;
61
+ questions: Record<string, unknown>;
62
+ answers: Record<string, unknown>;
63
+ rule: DecisionRowRule | null;
64
+ /** What the run did with the answers; null when the node did not act on them. */
65
+ action: unknown;
66
+ usage: {
67
+ input_tokens: number;
68
+ output_tokens: number;
69
+ } | null;
70
+ cost_usd: number | null;
71
+ latency_ms: number;
72
+ /** The request's error, as its receipt kept it: whole up to 64 KB, a longer one cut there with `error_truncated`. */
73
+ error?: string;
74
+ error_truncated?: boolean;
75
+ /** How the request ended (`answered`, `failed` or `cancelled`); absent on a row written before it was kept. */
76
+ status?: "answered" | "failed" | "cancelled";
77
+ /** The provider that answered, when the host's judge names it or the node pins it. */
78
+ provider?: string;
79
+ /** The sources the provider grounded its answers in, as the receipt has them; absent when it gave none. */
80
+ evidence?: Array<{
81
+ url: string;
82
+ title: string | null;
83
+ excerpts: string[];
84
+ scope: string;
85
+ }>;
86
+ /** The questions whose answer came back as a refusal. */
87
+ refused?: string[];
88
+ /** For each choice and score answer, whether its confidence is the provider's own or was derived. */
89
+ confidence_source?: Record<string, string>;
90
+ /** The images the request carried, by digest (token, reference, SHA-256, type, size), never their bytes. */
91
+ images?: Array<{
92
+ token: string;
93
+ ref: string;
94
+ sha256: string | null;
95
+ mime: string | null;
96
+ bytes: number | null;
97
+ }>;
98
+ /** The state the judge saw, or past 64 KB of JSON the first 64 KB of its text, with `state_truncated` saying which. */
99
+ state?: unknown;
100
+ state_truncated?: boolean;
101
+ /** The request's spend is on its frozen driver's state, so a cost fold counts it there, not here. */
102
+ driver_spend?: true;
103
+ /** The receipt's id, its place among its node's requests, the digest of the state it was asked with, and the key of
104
+ * the workflow run that asked it. A row that carries all four is the whole receipt again, so that run, resumed, can be
105
+ * answered from it (`decisionRecovery`); another run in the same Session never is. */
106
+ decision_id?: string;
107
+ request?: {
108
+ index: number;
109
+ count: number;
110
+ items?: number[];
111
+ };
112
+ state_sha256?: string;
113
+ run_key?: string;
114
+ /** The id its host admitted the request under before sending it, when the host admits its requests so that one the run
115
+ * stopped before it answered is still counted. The row settles that admission in the row's own commit: a cost fold
116
+ * counts an admission no row names, and never one a row names. */
117
+ admission?: string;
118
+ /** How the cost was reached (reported by the provider, estimated by the host, unknown), when the judge said. */
119
+ cost_basis?: "reported" | "estimate" | "unknown";
120
+ };
121
+ /** How many rows the keyed form holds: its next key. A few bytes, so rewriting it at every commit costs the same at every count. */
122
+ export declare const DECISION_COUNT_DOC = "agentrun.decisions.count";
123
+ /** A keyed row's key: its place, zero-padded so the keys sort in commit order. */
124
+ export declare const decisionKey: (place: number) => string;
125
+ /** Commit one row, appended after every row committed before it. */
126
+ export declare function appendDecision(harness: Pick<Harness, "commit">, row: DecisionRow, context?: Context): Promise<void>;
127
+ /** Every row the run's Session holds, in commit order. */
128
+ export declare function readDecisions(read: DocumentReader, context?: Context): Promise<DecisionRow[]>;
129
+ /** The rows from place `from` on and the place after the last: only the new ones are read, so a reader that keeps `next`
130
+ * reads each row once. */
131
+ export declare function readDecisionsFrom(read: Pick<DocumentReader, "snapshot">, from: number, context?: Context): Promise<{
132
+ rows: DecisionRow[];
133
+ next: number;
134
+ }>;
@@ -0,0 +1,46 @@
1
+ // A run's decision rows as pi-durable stores them, one row per typed question the run asked, in commit order: the KEYED
2
+ // family, one document of kind `agentrun.decisions` per row, written once. The row is a stored format (version 1); it
3
+ // does not change with the interpreter: a host maps `@parcha/agentrun-dsl`'s `DecisionReceipt` to a row, with the facts only
4
+ // the host has (the request's size and metering, whether the node acted on the answers), and this module stores and reads
5
+ // rows without looking inside them.
6
+ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
7
+ import { defineDoc, defineDocFamily } from "@earendil-works/pi-durable";
8
+ /** The session document that holds a run's decision rows. */
9
+ export const DECISION_RECEIPTS_DOC = "agentrun.decisions";
10
+ /** The stored row's version. */
11
+ export const DECISION_ROW_VERSION = 1;
12
+ /** The keyed form: one document per row, of the same kind, keyed by the row's place in the run's rows (`keyOf`), written once. The
13
+ * document's value is exactly the row. */
14
+ const DecisionRowDoc = defineDocFamily({ kind: DECISION_RECEIPTS_DOC, version: 1, scope: "session", family: true, initial: () => ({}), checkpointWhen: () => false });
15
+ /** How many rows the keyed form holds: its next key. A few bytes, so rewriting it at every commit costs the same at every count. */
16
+ export const DECISION_COUNT_DOC = "agentrun.decisions.count";
17
+ const DecisionCountDoc = defineDoc({ kind: DECISION_COUNT_DOC, version: 1, scope: "session", initial: () => ({ count: 0 }), checkpointWhen: () => false });
18
+ /** A keyed row's key: its place, zero-padded so the keys sort in commit order. */
19
+ export const decisionKey = (place) => String(place).padStart(8, "0");
20
+ /** Commit one row, appended after every row committed before it. */
21
+ export async function appendDecision(harness, row, context = BACKGROUND_CONTEXT) {
22
+ const stored = JSON.parse(JSON.stringify(row));
23
+ await harness.commit(async (tx) => {
24
+ const count = await tx.doc(DecisionCountDoc);
25
+ const place = count.count;
26
+ count.count = place + 1;
27
+ Object.assign(await tx.doc(DecisionRowDoc, decisionKey(place), null), stored);
28
+ }, context);
29
+ }
30
+ /** Every row the run's Session holds, in commit order. */
31
+ export async function readDecisions(read, context = BACKGROUND_CONTEXT) {
32
+ return (await readDecisionsFrom(read, 0, context)).rows;
33
+ }
34
+ /** The rows from place `from` on and the place after the last: only the new ones are read, so a reader that keeps `next`
35
+ * reads each row once. */
36
+ export async function readDecisionsFrom(read, from, context = BACKGROUND_CONTEXT) {
37
+ const total = (await read.snapshot(DecisionCountDoc, context))?.count ?? 0;
38
+ const rows = [];
39
+ for (let at = from; at < total; at += 64) {
40
+ const batch = await Promise.all(Array.from({ length: Math.min(64, total - at) }, (_, i) => read.snapshot(DecisionRowDoc, decisionKey(at + i), context)));
41
+ for (const doc of batch)
42
+ if (doc !== undefined)
43
+ rows.push(doc);
44
+ }
45
+ return { rows, next: total };
46
+ }
@@ -0,0 +1,5 @@
1
+ import { type PiRunner } from './runner.js';
2
+ import type { PiHostContext, PiHostRunnerOptions, PiSessionFactory } from './types.js';
3
+ export declare const PI_MODEL_SETUP_MESSAGE = "AgentRun requires an active Pi model. Use /login to connect a provider, then /model to select it. Try /agentrun demo without model access.";
4
+ export declare function createPiHostSessionFactory(context: PiHostContext): PiSessionFactory;
5
+ export declare function createPiHostRunner(context: PiHostContext, options?: PiHostRunnerOptions): PiRunner;
@@ -0,0 +1,85 @@
1
+ import { Agent } from '@earendil-works/pi-agent-core';
2
+ import { SUBMIT_TOOL } from './host-tools.js';
3
+ import { createPiRunner } from './runner.js';
4
+ import { workflowToolContext } from './tool-context.js';
5
+ import { OperatorError } from './operator-error.js';
6
+ export const PI_MODEL_SETUP_MESSAGE = 'AgentRun requires an active Pi model. Use /login to connect a provider, then /model to select it. Try /agentrun demo without model access.';
7
+ function selectedModel(context) {
8
+ const model = context.model;
9
+ if (!model)
10
+ throw new OperatorError(PI_MODEL_SETUP_MESSAGE);
11
+ if (!context.modelRegistry || typeof context.modelRegistry.streamSimple !== 'function' || typeof context.modelRegistry.getAll !== 'function') {
12
+ throw new OperatorError('AgentRun requires the host public model registry');
13
+ }
14
+ if (!context.modelRegistry.getAll().some(known => known.id === model.id && known.provider === model.provider && known.api === model.api)) {
15
+ throw new OperatorError(PI_MODEL_SETUP_MESSAGE);
16
+ }
17
+ return model;
18
+ }
19
+ export function createPiHostSessionFactory(context) {
20
+ const model = selectedModel(context);
21
+ const stream = context.modelRegistry.streamSimple.bind(context.modelRegistry);
22
+ const toolContext = workflowToolContext(context);
23
+ return async (options) => {
24
+ if (options.model !== model)
25
+ throw new Error('The child session must use the captured active Pi model');
26
+ let delivered = false, turns = 0;
27
+ const allowed = new Set(options.tools);
28
+ const tools = options.customTools.filter(tool => allowed.has(tool.name)).map(tool => ({
29
+ name: tool.name, label: tool.label, description: tool.description,
30
+ parameters: tool.parameters,
31
+ async execute(id, args, signal, onUpdate) {
32
+ const result = await tool.execute(id, args, signal, onUpdate, toolContext);
33
+ if (tool.name === SUBMIT_TOOL && result.details?.accepted === true)
34
+ delivered = true;
35
+ return result;
36
+ },
37
+ }));
38
+ const agent = new Agent({
39
+ initialState: { model, thinkingLevel: options.thinkingLevel, systemPrompt: options.resourceLoader.getSystemPrompt() ?? '', tools },
40
+ streamFn: (_model, transcript, streamOptions) => stream(model, transcript, streamOptions),
41
+ toolExecution: 'sequential',
42
+ finishTurn: () => {
43
+ turns++;
44
+ if (delivered || (options.maxTurns !== undefined && turns >= options.maxTurns))
45
+ return { action: 'end' };
46
+ },
47
+ });
48
+ let disposed = false;
49
+ const unsubscribers = new Set();
50
+ return { session: {
51
+ async prompt(text) {
52
+ if (disposed)
53
+ throw new Error('Pi host child session is disposed');
54
+ await agent.prompt(text);
55
+ },
56
+ subscribe(listener) {
57
+ if (disposed)
58
+ throw new Error('Pi host child session is disposed');
59
+ const unsubscribe = agent.subscribe(event => { listener(event); });
60
+ unsubscribers.add(unsubscribe);
61
+ return () => { unsubscribe(); unsubscribers.delete(unsubscribe); };
62
+ },
63
+ async abort() { agent.abort(); },
64
+ dispose() {
65
+ if (disposed)
66
+ return;
67
+ disposed = true;
68
+ agent.abort();
69
+ agent.clearAllQueues();
70
+ for (const unsubscribe of unsubscribers)
71
+ unsubscribe();
72
+ unsubscribers.clear();
73
+ },
74
+ } };
75
+ };
76
+ }
77
+ export function createPiHostRunner(context, options = {}) {
78
+ const model = selectedModel(context);
79
+ // The host session's thinking level is not a node's: a node that names none thinks at medium, unless the caller
80
+ // passes its own `thinkingLevel`.
81
+ return createPiRunner({
82
+ ...options, model, cwd: options.cwd ?? context.cwd,
83
+ sessionFactory: createPiHostSessionFactory(context),
84
+ });
85
+ }
@@ -0,0 +1,3 @@
1
+ /** The tool a workflow node delivers its result with (the runner's and the durable record tool's), so no host tool may
2
+ * take its name. */
3
+ export declare const SUBMIT_TOOL = "submit";
@@ -0,0 +1,3 @@
1
+ /** The tool a workflow node delivers its result with (the runner's and the durable record tool's), so no host tool may
2
+ * take its name. */
3
+ export const SUBMIT_TOOL = 'submit';