@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
@@ -18,11 +18,11 @@ import { join } from "node:path";
18
18
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
19
19
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
20
20
  import { checkRaise, followUpOf, parkOf } from "@parcha/agentrun-kernel/kernel/cap";
21
- import { noNewPrivsPrefix } from "@parcha/pi-durable-disk/internals";
22
- import { confineOf, thinkingFor } from "../adapters.js";
23
- import { installDirOf, installingWords, installSettled } from "../harness-install.js";
21
+ import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
22
+ import { claimSettled, installDirOf, installForClaim, installingWords } from "../harness-install.js";
24
23
  import { HarnessUnavailable } from "../provider.js";
25
24
  import { effortGuidance } from "../effort-guidance.js";
25
+ import { wireName } from "../catalog.js";
26
26
  import { environmentLine } from "../environment.js";
27
27
  import { harnessOf } from "../harness-table.js";
28
28
  import { laidLearned, learningFolderOf, secretsShown } from "../learning.js";
@@ -42,21 +42,23 @@ import { layOwnSkills } from "../workspace/revision-skills.js";
42
42
  import { runTools, withKindTools } from "../workspace/run-tools.js";
43
43
  import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
44
44
  import { loadArchilSettings } from "../archil-settings.js";
45
- import { imageWaitWords } from "../workspace/computer-deps.js";
45
+ import { computerReadyWords, imageWaitWords } from "../workspace/computer-deps.js";
46
46
  import { hostLifecycle } from "./adapter-loop.js";
47
47
  import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, modelAskOf, PI_WIRES, webHostTools, webToolNames } from "./adapter-run-spec.js";
48
48
  import { openTierProxies } from "./adapters/pi.js";
49
49
  import { signInReads } from "../sign-ins-store.js";
50
+ import { mcpServersOf } from "../tool-gate.js";
50
51
  import { claimSecrets, learnedDecisionKeys, tierModelKeys, withModelKeys } from "./claim-secrets.js";
51
52
  import { mcpForClaim } from "./mcp-run.js";
52
53
  import { TOOL_PLANE_ENV } from "../tool-plane.js";
53
54
  import { resolveHarness } from "./adapters/index.js";
54
55
  import { entriesOf } from "./loop.js";
55
- import { bookedSpend, cliRunMetrics } from "./metrics.js";
56
+ import { bookedSpend, cliModelWorked, cliRunMetrics } from "./metrics.js";
56
57
  import { journalEntries } from "./journal-reader.js";
57
58
  import { specBuilt } from "./spec-holds.js";
58
59
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
59
60
  import { githubAppAccess } from "./github-app.js";
61
+ import { prCheckoutForClaim } from "./pr-checkout.js";
60
62
  import { holdStored, storeSecrets } from "./store-secrets.js";
61
63
  import { bashPolicyOf } from "../bash-read-only.js";
62
64
  /** What a CLI harness refuses of an agent's computer, in words: a browser, which only pi's browser tool drives. */
@@ -105,6 +107,21 @@ function cliRunEnv(env, data, claimed = {}) {
105
107
  Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
106
108
  return out;
107
109
  }
110
+ /** `tools` in the order the agent grants them (`granted`, catalog names; a tool is listed by its catalog name's wire
111
+ * name), as main listed a CLI run's tools to its harness: each granted tool where its grant is, and a tool the grant
112
+ * does not name (one a granted tool or the run's computer brings beside it) right after the tool listed before it. Ties
113
+ * keep the order given. */
114
+ export function inGrantOrder(tools, granted) {
115
+ const at = new Map(granted.map((name, index) => [wireName(name), index]));
116
+ let last = -1;
117
+ const keyed = tools.map((tool, given) => {
118
+ const index = at.get(tool.name);
119
+ if (index !== undefined)
120
+ last = index;
121
+ return { tool, key: index ?? last + 0.5, given };
122
+ });
123
+ return keyed.sort((a, b) => a.key - b.key || a.given - b.given).map(({ tool }) => tool);
124
+ }
108
125
  /** A claim's private folder removed, then each of `parents` in order while it is empty: one another claim of the run has
109
126
  * laid things in since (a follow-up's) stays, with what is in it. */
110
127
  export async function sweepScratch(dir, parents) {
@@ -153,13 +170,6 @@ async function cliSpec(launch, run, deps, claim, holds) {
153
170
  const body = (revisionRow.body ?? {});
154
171
  const revision = { kind: revisionRow.kind, body };
155
172
  const granted = body.tools ?? [];
156
- // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
157
- // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
158
- // First, before the session opens: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its words.
159
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold: (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
160
- redact.hold(values); } }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
161
- // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
162
- holds.hold({ passed: mcp });
163
173
  // The harness: the launch's, else the revision's. Its table entry (facts, model choice, adapter, skill check), read from
164
174
  // the run's environment table as main does (harnessOf: the built-in entries, a test's module merged over them under a
165
175
  // test runner; anywhere else it is the built-ins), and the runner's record mode for it.
@@ -172,10 +182,53 @@ async function cliSpec(launch, run, deps, claim, holds) {
172
182
  // The level the harness thinks at: the run's effort, else above its highest (codex stops at xhigh) its highest. The
173
183
  // run's metrics name this level, the one it ran at, never a level the harness has not.
174
184
  const thinking = launch.effort ? thinkingFor(facts, launch.effort) : undefined;
185
+ // A harness that installs on first use (claude-agent, codex) and is not installed whole in this server's data: the claim
186
+ // waits for the install running now (the server starts one at an agent's save), or, with none running (none started, or
187
+ // one cut short or failed before this claim), installs it itself. One install at a time on this data, which every claim
188
+ // that needs it waits for (harness-install.ts installForClaim), bounded by the install's own limit. The wait is said on
189
+ // the run's timeline as it starts, its root made first (a CLI run's root is its record's, which the loop would make once
190
+ // the session opens), so the row shows while it waits. First, before the run's MCP claim: its OAuth tokens are read
191
+ // after a wait that may outlive them. A stop of the run ends its wait at once; an install that fails fails the run in the
192
+ // install's own words. A test's stand-in that runs in place of the CLI (adapters.ts standsIn) loads nothing installed:
193
+ // its claim waits for an install that runs, as any claim does, but starts none of its own.
194
+ if (entry.installs && entry.pins) {
195
+ const installs = entry.installs;
196
+ const pins = entry.pins;
197
+ const dir = installDirOf(deps.data, name);
198
+ const waitOn = run.stopped ?? run.signal;
199
+ let saying;
200
+ const say = () => (saying ??= (async () => {
201
+ await run.harness.root(context);
202
+ run.phase?.(installingWords(installs.label));
203
+ })().catch((error) => log(`the run's install wait was not said on its timeline: ${error?.message ?? String(error)}`)));
204
+ let waited = false;
205
+ const settled = await (deps.installSettled ?? claimSettled)(installs, dir, await pins(), { ...(waitOn ? { signal: waitOn } : {}), onWait: () => void ((waited = true), say()) });
206
+ // The install it waited for failed: the run fails in its words. An earlier one that failed before this claim is tried again.
207
+ if (typeof settled === "object" && waited)
208
+ throw new HarnessUnavailable(settled.failed, "install");
209
+ if (settled !== "installed" && !standsIn(name, deps.env ?? {})) {
210
+ await say();
211
+ const lock = deps.harnessLocks?.[name];
212
+ await (deps.installForClaim ?? installForClaim)(installs, dir, pins, { ...(lock ? { lock } : {}), ...(waitOn ? { signal: waitOn } : {}) }).catch((error) => {
213
+ if (waitOn?.aborted)
214
+ throw error;
215
+ throw new HarnessUnavailable(error.message, "install");
216
+ });
217
+ }
218
+ }
219
+ // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin made at the first claim or read as written, its
220
+ // credentials opened under the runner's seal key (deps.sealKey) into this claim's memory, one gateway for the claim.
221
+ // Before the session opens: a refusal (a pin that cannot be made, a pinned meta tool) ends the run in its words.
222
+ // A credential the claim opens mid-run (a GitHub App token, a per_run server's handed one) joins the run's redactors.
223
+ const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
224
+ redact.hold(values); };
225
+ const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}) });
226
+ // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
227
+ holds.hold({ passed: mcp });
175
228
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
176
229
  // on the claim's Archil disk (archil-claim.ts: its keys from the store's sealed rows, under the runner's seal key, in
177
230
  // this claim's memory only, dropped at the release); else Mode 1, the run's local folder.
178
- const archilSettings = await loadArchilSettings(deps.store);
231
+ const archilSettings = await loadArchilSettings(deps.store, deps.env);
179
232
  const mode = archilSettings === undefined ? 1 : 2;
180
233
  const archil = archilSettings === undefined
181
234
  ? undefined
@@ -183,7 +236,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
183
236
  // named for the run and this claim's epoch; revoke at the run's end (below). mountControl (a test's loopback control-plane
184
237
  // fake) is spread into the mount, so no test reaches the real control plane. TODO(k2 lazy mint): the mint moves into
185
238
  // computerForClaim (a mounting computer only), with the ttl the run's lifetime bound (not this fixed figure). As pi does.
186
- : await archilClaim({ settings: archilSettings, keys: deps.store.sealedKeys, sealKey: deps.sealKey, signal: run.signal ?? new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS, ...(deps.mountControl ?? {}) }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
239
+ // The disk is the run's (run-disk.ts): its launch record's, else its agent's, made on its first run that needs one.
240
+ : await archilClaim({ settings: archilSettings, keys: deps.store.sealedKeys, sealKey: deps.sealKey, signal: run.signal ?? new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS, ...(deps.mountControl ?? {}) }, run: { agentId: runRow.agentId, ...(launch.archilDisk ? { launch: launch.archilDisk } : {}), store: deps.store }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
187
241
  // Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go. The claim's Archil keys go
188
242
  // from memory last, once nothing more reads the disk.
189
243
  holds.hold({ archil, keys: archil });
@@ -192,16 +246,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
192
246
  ? await openRunWorkspace({ mode: 1, agentId: runRow.agentId, runId: claim.runId, data: deps.data, log })
193
247
  : await openRunWorkspace({ mode: 2, agentId: runRow.agentId, runId: claim.runId, archil, log });
194
248
  holds.hold({ ws });
249
+ // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
250
+ const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
251
+ holds.hold({ checkout });
195
252
  if (launch.files?.length)
196
253
  await copyRunFiles(deps.data, claim.runId, ws.workspace, launch.files);
197
254
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
198
255
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
199
- const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
256
+ const computer = await deps.computerForClaim({ runId: claim.runId, epoch: claim.epoch, agentId: runRow.agentId, revisionId: runRow.revisionId, place: launch.place, ...(launch.computer !== undefined ? { computer: launch.computer } : {}) }, deps.store,
200
257
  // revokeMount removes the run's Archil mount credential at the computer's release (and if a start fails after a mint); the
201
- // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does.
258
+ // run's end revokes it too, so it goes on every outcome even with no computer. Idempotent. As the pi spec does, with
259
+ // what became of the agent's own computer said on the run's timeline.
202
260
  // A browser computer is driven by the browser tool, which runs on pi's native route alone: a CLI's run of an agent
203
261
  // whose computer is a browser is refused in words at its claim, before anything is made.
204
- { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)) } : {}) });
262
+ { ...deps.computerDeps, mode, workspace: ws.workspace, sealKey: deps.sealKey, refuseKind: cliRefusesKind, ...(archil ? { revokeMount: () => archil.revoke() } : {}), ...(run.phase ? { onImageWait: (making, image) => run.phase?.(imageWaitWords(making, image)), onConnected: (said) => run.phase?.(computerReadyWords(said)), onComputerNote: (words) => run.phase?.(words) } : {}) });
205
263
  holds.hold({ computer });
206
264
  // The CLI works in the run's scratch folder on this machine (its working directory), its own files (home, state, the
207
265
  // skills laid for it) in this claim's private folder inside it, never on the run's disk. The scratch is an alias of the
@@ -248,6 +306,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
248
306
  own: Object.keys(revisionRow.skills ?? {}),
249
307
  shown: async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true }),
250
308
  log,
309
+ ...(start.notesOnly ? { workflows: false } : {}),
251
310
  })
252
311
  : undefined;
253
312
  const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
@@ -264,19 +323,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
264
323
  holdClaimed(redact, claimed);
265
324
  const env = cliRunEnv(deps.env, deps.data, claimed);
266
325
  const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
267
- // A harness that installs on first use, whose install is running now (the server started it at an agent's save, or a
268
- // run's start): the claim waits for it, bounded by the install's own limit, saying so on the run's timeline, and runs on
269
- // it. A stop of the run ends the wait at once (the install goes on). An install that failed fails the run in its own
270
- // words; with none running, the adapter says what is missing, as before.
271
- if (entry.installs && entry.pins) {
272
- const installs = entry.installs;
273
- const waitOn = run.stopped ?? run.signal;
274
- const settled = await (deps.installSettled ?? installSettled)(installs, installDirOf(deps.data, name), await entry.pins(), { ...(waitOn ? { signal: waitOn } : {}), onWait: () => run.phase?.(installingWords(installs.label)) });
275
- if (typeof settled === "object")
276
- throw new HarnessUnavailable(settled.failed, "install");
277
- }
278
326
  // The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
279
- // (pi-durable-disk's noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
327
+ // (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
280
328
  // or a command it runs reaches grants nothing; none on macOS. Where setpriv is not usable the run is refused, in pi's words.
281
329
  const confine = confineOf(noNewPrivsPrefix());
282
330
  const built = await entry.adapter(env, { model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}) });
@@ -354,8 +402,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
354
402
  };
355
403
  // The gate before a call's intent, the same as the pi spec: the revision's tool settings over the store's, read from the
356
404
  // store at each decide — adapterRunGate (RunGate.decide: deny with its words, a pin, allow, ask). The end-of-run turn's
357
- // refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's.
358
- const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell);
405
+ // refusal of writes under .learning/ is the adapter loop's own (it knows the turn), never a file's. The run's MCP servers
406
+ // (mcpServersOf its grants) hold a harness's own name for an MCP tool to that tool's settings.
407
+ const gate = await adapterRunGate(deps.store, claim, revision, ws.workspace, tools.shell, mcpServersOf(granted));
359
408
  // The run's tools: the kernel registry's hands on its Workspace (and computer); the web host tools it is granted
360
409
  // (web_fetch, web_search, monid), bound by the binding the pi spec uses (webHostTools) on the ToolHost the pi spec builds
361
410
  // (buildToolHost); and the learned_workflow tool when the run has it (learnsWorkflows: its revision is agentic and the
@@ -420,18 +469,18 @@ async function cliSpec(launch, run, deps, claim, holds) {
420
469
  }
421
470
  }
422
471
  // The gate asks a learned_workflow call about its workflow's MCP nodes (adapterRunGate); they run through the run's
423
- // own MCP as the loop wraps it.
472
+ // own MCP as the loop wraps it. Its model nodes run on the session's one model: what each node's trace says it ran on.
424
473
  gate.learn(workflows);
425
- learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}) });
474
+ learnedTool = await learnedWorkflowHostTool({ run, kind: revision.kind, granted, plane: launch.plane, env: toolEnv, work: root, workflows, permissions: gate.permissions, ctx, tiers, ...(mcp ? { mcp } : {}), modelName: () => chosen.model.modelId });
426
475
  }
427
476
  }
428
477
  const session = {
429
478
  key: `run:${claim.runId}`,
430
479
  label: runRow.agentId,
431
- system: [environmentLine(), instructions, guidance].filter((line) => Boolean(line)),
480
+ system: [environmentLine(), checkout?.note, instructions, guidance].filter((line) => Boolean(line)),
432
481
  // The web tools and the learned workflow's call nodes run on the claim's keys: their answers pass the runner's one
433
- // redactor, as pi's do.
434
- tools: [...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))],
482
+ // redactor, as pi's do. Listed in the order the agent grants them, as main lists a CLI run's tools.
483
+ tools: inGrantOrder([...tools.hostTools(withKindTools(granted, tools), results), ...[...webTools, ...(learnedTool ? [learnedTool] : [])].map((tool) => answersCut(tool, held))], granted),
435
484
  context: "fresh",
436
485
  ...(thinking ? { thinking } : {}),
437
486
  };
@@ -472,6 +521,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
472
521
  // The web tools' install lifecycle, run by the adapter loop, as the pi spec's (they register none today).
473
522
  ...(life ? { lifecycle: life } : {}),
474
523
  agentId: runRow.agentId,
524
+ // The run's desktop or phone and the person's hold on it, as the claim made them (as the pi spec gives them).
525
+ ...(computer.held ? { computer: computer.held } : {}),
475
526
  workRoot: root,
476
527
  // Where the CLI works (its working directory, the run's folder to its file tools): what its absolute paths are read
477
528
  // against on the run's rows.
@@ -487,14 +538,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
487
538
  const all = (await journalEntries(deps.journal(claim), context));
488
539
  const booked = bookedSpend(all, "model");
489
540
  const metrics = cliRunMetrics(entries, booked, { ...(thinking ? { effort: thinking } : {}), model: `${chosen.model.provider}/${chosen.model.modelId}` });
490
- const model = booked.usd;
541
+ // A run whose model answered or called a tool with no request booked (its requests went past its model proxy) spent
542
+ // what no booking read: unknown, never the $0 an empty booking sums to.
543
+ const model = booked.requests === 0 && cliModelWorked(entries) ? null : booked.usd;
491
544
  const decisions = bookedSpend(all, "decisions").usd;
492
545
  const costUsd = model === null || decisions === null ? null : model + decisions;
493
546
  // Its paid tool calls (a Parallel extract or search, a monid call), booked on the run's one ledger in their own
494
547
  // session, are the run's cost too, as the pi spec's.
495
548
  const paid = run.ledger?.paid ? run.ledger.paid.spentUsd() : 0;
496
549
  const total = costUsd === null || paid === null ? null : costUsd + paid;
497
- return { ...(total !== null ? { costUsd: total } : {}), metrics };
550
+ // An unknown cost is written as null, never left out: a follow-up's end clears the cost an earlier end stored.
551
+ return { costUsd: total, metrics };
498
552
  },
499
553
  // The run's Archil mount credential is revoked at its end on every outcome, even with no computer (idempotent with
500
554
  // the computer's release). A run that minted none revokes nothing.
@@ -13,11 +13,15 @@ export interface CommandSink {
13
13
  command(runId: string, command: {
14
14
  kind: string;
15
15
  body: Record<string, unknown>;
16
+ }, options?: {
17
+ launchSealed?: Uint8Array;
16
18
  }): Promise<Command>;
17
19
  }
18
20
  /** Inserts a command row for a run, after checking its kind and body. Rejects RunFinal (from the store) when the run is
19
21
  * final, and a TypeError for a kind or body no runner would take. */
20
- export declare function sendCommand(store: CommandSink, runId: string, input: CommandInput): Promise<Command>;
22
+ export declare function sendCommand(store: CommandSink, runId: string, input: CommandInput, options?: {
23
+ launchSealed?: Uint8Array;
24
+ }): Promise<Command>;
21
25
  /** The reason a command still untaken when its run ended is refused with: the store's own words (the write that makes a
22
26
  * run final refuses such rows itself). */
23
27
  export { endedReason } from "../store/store.js";
@@ -17,7 +17,7 @@ function bodyProblem(kind, body) {
17
17
  case "steer":
18
18
  if (!text(body.text))
19
19
  return "a steer needs its text";
20
- // A trigger's message names who wrote it, as the Timeline shows it (pi-durable-agent's originOf): never a person's.
20
+ // A trigger's message names who wrote it, as the Timeline shows it: never a person's.
21
21
  return body.origin === undefined || originOf(body.origin) !== undefined ? undefined : "a steer's origin is a message origin (a trigger's, or the server's)";
22
22
  case "approve":
23
23
  case "deny":
@@ -52,7 +52,7 @@ function bodyProblem(kind, body) {
52
52
  }
53
53
  /** Inserts a command row for a run, after checking its kind and body. Rejects RunFinal (from the store) when the run is
54
54
  * final, and a TypeError for a kind or body no runner would take. */
55
- export async function sendCommand(store, runId, input) {
55
+ export async function sendCommand(store, runId, input, options) {
56
56
  if (!COMMAND_KINDS.has(input.kind)) {
57
57
  throw new TypeError(`a command's kind is one of ${[...COMMAND_KINDS].join(", ")}, not ${JSON.stringify(input.kind)}`);
58
58
  }
@@ -60,7 +60,7 @@ export async function sendCommand(store, runId, input) {
60
60
  const problem = bodyProblem(input.kind, body);
61
61
  if (problem)
62
62
  throw new TypeError(problem);
63
- return store.command(runId, { kind: input.kind, body });
63
+ return store.command(runId, { kind: input.kind, body }, ...(options ? [options] : []));
64
64
  }
65
65
  /** The reason a command still untaken when its run ended is refused with: the store's own words (the write that makes a
66
66
  * run final refuses such rows itself). */
@@ -87,4 +87,3 @@ export declare function registerHarnessConformance(given: ConformanceSubject, {
87
87
  test: TestFunction;
88
88
  storeUrl?: string;
89
89
  }): void;
90
- export declare const CONFORMANCE_CASES: readonly ConformanceCase[];
@@ -16,7 +16,7 @@ import { fileURLToPath } from "node:url";
16
16
  import { tmpdir } from "node:os";
17
17
  import { join } from "node:path";
18
18
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
19
- import { dropPostgresSchema, openPostgresStore, openStore, RunFinal, StoreConstraint, storeTarget } from "../../store/index.js";
19
+ import { AnswerTaken, dropPostgresSchema, openPostgresStore, openStore, RunFinal, storeTarget } from "../../store/index.js";
20
20
  import { sendCommand } from "../commands.js";
21
21
  import { callsOf, journalRecords, messagesOf } from "../journal-reader.js";
22
22
  import { KINDS, MESSAGE_SENT_AGAIN } from "../journal-kinds.js";
@@ -724,6 +724,8 @@ const CASES = [
724
724
  assert.equal(messages.some((message) => message.text === "never"), false, "the turn did not go on");
725
725
  // Why it stopped is on the run row, staged in the end commit: one place for every harness.
726
726
  assert.match(row.summary ?? "", /stopped/, `the run says why it stopped: ${JSON.stringify(row.summary)}`);
727
+ // A person's stop, told from a cancel in the store: its turn is over, not the run (a message reopens it).
728
+ assert.equal(row.outcome, "stopped", `the run's outcome says a person stopped it: ${JSON.stringify(row)}`);
727
729
  assert.ok(row.endedAt !== null, "its end commit stamped ended_at");
728
730
  assert.ok((await w.commandRow(stop.id)).takenAt !== null, "the stop row is taken");
729
731
  // The live timeline: one row says the person stopped it, worded the same on every harness, and nothing a person
@@ -748,8 +750,9 @@ const CASES = [
748
750
  const { calls, messages } = await w.read();
749
751
  assert.ok(calls.every((call) => call.status !== "pending"), `no call left pending: ${JSON.stringify(calls)}`);
750
752
  assert.equal(messages.some((message) => message.text === "never"), false, "the turn did not go on");
751
- // The end main's cancel writes: stopped, its summary "cancelled", staged in the end commit.
753
+ // The end main's cancel writes: stopped, its summary "cancelled" and its outcome 'cancelled', staged in the end commit.
752
754
  assert.equal(row.summary, CANCELLED, `the run says it was cancelled: ${JSON.stringify(row)}`);
755
+ assert.equal(row.outcome, "cancelled", `the run's outcome says it was cancelled: ${JSON.stringify(row)}`);
753
756
  const taken = await w.commandRow(cancel.id);
754
757
  assert.ok(taken.takenAt !== null && taken.refused === null, `the cancel row is taken, not refused: ${JSON.stringify(taken)}`);
755
758
  await assert.rejects(sendCommand(w.server, RUN, { kind: "steer", body: { text: "go on" } }), RunFinal, "a cancelled run takes no more messages");
@@ -766,6 +769,7 @@ const CASES = [
766
769
  const cancel = await sendCommand(w.server, RUN, { kind: "cancel" });
767
770
  const row = await w.ended("stopped");
768
771
  assert.equal(row.summary, CANCELLED, `the run says it was cancelled: ${JSON.stringify(row)}`);
772
+ assert.equal(row.outcome, "cancelled", `the run's outcome says it was cancelled: ${JSON.stringify(row)}`);
769
773
  assert.equal(ran.asked, 0, "the asked call never ran");
770
774
  const taken = await w.commandRow(cancel.id);
771
775
  assert.ok(taken.takenAt !== null && taken.refused === null, `the cancel row is taken, not refused: ${JSON.stringify(taken)}`);
@@ -872,7 +876,7 @@ const CASES = [
872
876
  await w.ended("parked");
873
877
  const callId = await w.askedCall();
874
878
  const first = await sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } });
875
- await assert.rejects(sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } }), StoreConstraint, "a second answer to one approval is never written");
879
+ await assert.rejects(sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } }), AnswerTaken, "a second answer to one approval is never written: the store says it is answered already");
876
880
  await w.ended("ended");
877
881
  assert.equal(ran.asked, 1, "the call ran once");
878
882
  assert.equal((await w.commandRow(first.id)).refused, null, "the first approve answered it");
@@ -898,7 +902,7 @@ const CASES = [
898
902
  const won = settled.filter((r) => r.status === "fulfilled");
899
903
  const lost = settled.filter((r) => r.status === "rejected");
900
904
  assert.equal(won.length, 1, `one answer is written, not both: ${JSON.stringify(settled.map((r) => r.status))}`);
901
- assert.ok(lost[0]?.reason instanceof StoreConstraint, `the other is refused by the store: ${String(lost[0]?.reason)}`);
905
+ assert.ok(lost[0]?.reason instanceof AnswerTaken, `the other is refused by the store as answered already (AnswerTaken), never a bare constraint: ${String(lost[0]?.reason)}`);
902
906
  await w.ended("ended");
903
907
  const winner = won[0].value;
904
908
  assert.equal(ran.asked, winner.kind === "approve" ? 1 : 0, "the run acted on the answer written, never the other");
@@ -1035,4 +1039,3 @@ export function registerHarnessConformance(given, { test, storeUrl }) {
1035
1039
  test(`${subject.name}: ${entry.title}`, { timeout: CASE_TIMEOUT_MS, ...(skip ? { skip } : {}) }, (t) => entry.body(subject, t));
1036
1040
  }
1037
1041
  }
1038
- export const CONFORMANCE_CASES = CASES.map((entry) => entry.id);
@@ -47,12 +47,12 @@ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB
47
47
  api,
48
48
  target,
49
49
  // The App read again before each mint: one disconnected or replaced since the claim makes no token for this run.
50
- mint: async (to) => {
50
+ mint: async (to, permissions) => {
51
51
  // A read that fails throws on: the step's github_failed path keeps the token held until it expires, never a disconnect.
52
52
  const still = await appOf(store, sealKey);
53
53
  if (!still || still.appId !== app.appId || still.pem !== app.pem)
54
54
  return { ok: false, reason: "disconnected", message: "the GitHub App was disconnected or replaced on this server" };
55
- const minted = await mintInstallationToken(api, app.appId, app.pem, to, now());
55
+ const minted = await mintInstallationToken(api, app.appId, app.pem, to, now(), permissions);
56
56
  if (minted.ok)
57
57
  hold?.([minted.token]);
58
58
  return minted;
@@ -78,7 +78,7 @@ export function resolveRunnerLoop(deps) {
78
78
  // run that does not learn supplies none. The same for the pi and the CLI spec.
79
79
  return createAdapterLoop((claim, adapterRun) => runner.record === "loop"
80
80
  ? cliRunSpecFromLaunch(launch, adapterRun, deps, claim)
81
- : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim));
81
+ : adapterRunSpecFromLaunch(launch, adapterRun, deps, claim), deps.modelRetry ?? {});
82
82
  }
83
83
  return undefined;
84
84
  };
@@ -22,7 +22,7 @@ export declare const KINDS: {
22
22
  * a call nor a message, so the reader passes over it. */
23
23
  readonly messageSending: "agentrun.message.sending";
24
24
  /** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
25
- * the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
25
+ * the Timeline's attribution (the timeline reads a host's user entry's own origin). The model
26
26
  * reads it as any message. */
27
27
  readonly input: "agentrun.input";
28
28
  /** A tool call the gate asked a person about: the run parks on it. */
@@ -66,6 +66,11 @@ export declare const KINDS: {
66
66
  * workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
67
67
  * what the run was given. Neither a call nor a message. */
68
68
  readonly learningLaid: "agentrun.learning.laid";
69
+ /** A workflow run's model node's execution, as the runner kept it before running it (workflow-spec.ts onModelNode):
70
+ * `{ path, tier?, model }`, its execution path, the tier it asked for (absent for none) and the model id the run's route
71
+ * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
72
+ * call nor a message. */
73
+ readonly nodeModel: "agentrun.node.model";
69
74
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
70
75
  readonly learningGraded: "agentrun.learning.graded";
71
76
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -144,6 +149,9 @@ export interface BudgetData {
144
149
  };
145
150
  /** The cap's words, as the run row's summary says them. */
146
151
  readonly words: string;
152
+ /** A workflow run's: the label of the node whose step waits at the cap, null when it is not known. Absent on an agentic
153
+ * run's pause. */
154
+ readonly node?: string | null;
147
155
  }
148
156
  export interface CallStartData {
149
157
  readonly callId: string;
@@ -243,10 +251,12 @@ export declare function withdrawnAnswers(entries: readonly {
243
251
  export interface EndData {
244
252
  readonly state: "ended" | "stopped" | "failed";
245
253
  readonly summary?: string;
246
- /** How an ended run ended, set only for an escalation (the store's RunOutcome). */
247
- readonly outcome?: "completed" | "escalated";
248
- /** What the run cost, as its end knows it. */
249
- readonly costUsd?: number;
254
+ /** How the run ended beside its state (the store's RunOutcome): an escalation's 'escalated'; a stopped end's 'stopped'
255
+ * (a person's stop: the turn is over, not the run) or 'cancelled' (stopEnd). */
256
+ readonly outcome?: "completed" | "escalated" | "stopped" | "cancelled";
257
+ /** What the run cost, as its end knows it: null when unknown, which clears a cost an earlier end of the run stored (a
258
+ * follow-up's end). Absent: the stored cost is left as it is. */
259
+ readonly costUsd?: number | null;
250
260
  /** The run's metrics (the old StoredMetrics JSON). */
251
261
  readonly metrics?: unknown;
252
262
  /** A completed workflow run's output: the value at its workflow's output path (readWorkflowRun's `output`, null when it
@@ -22,7 +22,7 @@ export const KINDS = {
22
22
  * a call nor a message, so the reader passes over it. */
23
23
  messageSending: "agentrun.message.sending",
24
24
  /** A pi input the person did not type (a trigger's message): pi's user entry under the host's kind, its `data.origin`
25
- * the Timeline's attribution (pi-durable-agent's originMatcher reads a host's user entry's own origin). The model
25
+ * the Timeline's attribution (the timeline reads a host's user entry's own origin). The model
26
26
  * reads it as any message. */
27
27
  input: "agentrun.input",
28
28
  /** A tool call the gate asked a person about: the run parks on it. */
@@ -66,6 +66,11 @@ export const KINDS = {
66
66
  * workflows its learned_workflow tool runs (`workflows`, by name). Written once per claim, on the root; the newest is
67
67
  * what the run was given. Neither a call nor a message. */
68
68
  learningLaid: "agentrun.learning.laid",
69
+ /** A workflow run's model node's execution, as the runner kept it before running it (workflow-spec.ts onModelNode):
70
+ * `{ path, tier?, model }`, its execution path, the tier it asked for (absent for none) and the model id the run's route
71
+ * sent it to. On the node log (NODE_LOG_SESSION), for GET /runs/{id}/graph's nodes' `model` (graph-view.ts). Neither a
72
+ * call nor a message. */
73
+ nodeModel: "agentrun.node.model",
69
74
  /** A learning run's grade: the verdict and what it spent, written before its merge (a resumed run never asks again). */
70
75
  learningGraded: "agentrun.learning.graded",
71
76
  /** A learning run's merge: the new main and its commit, with the run's end. */
@@ -1,5 +1,6 @@
1
1
  import { type TimelineEvent } from "../timeline/index.js";
2
2
  import { type LearningFolder } from "../learn/folder.js";
3
+ import type { RunPath } from "../learning-cost.js";
3
4
  import { type RunLaunch } from "../run-launch.js";
4
5
  import { type SignInReader } from "../run-view.js";
5
6
  import type { Store } from "../store/store.js";
@@ -28,11 +29,25 @@ export interface LearningEndDeps {
28
29
  /** The end-of-run step for a run launched with `launch`: undefined when its launch records no learning start (a run that
29
30
  * does not learn is asked nothing and keeps nothing), else the reflect hook over the run's store. */
30
31
  export declare function learningEndOfRun(launch: RunLaunch, deps: LearningEndDeps): EndOfRunTurn | undefined;
32
+ /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
33
+ * A harness that names it another way reads as another tool, so its run is asked as before. */
34
+ export declare const LEARNED_NAMES: ReadonlySet<string>;
31
35
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
32
36
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
33
37
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
34
38
  * came in. Anything else is asked its end-of-run turn. */
35
39
  export declare function onlyLearnedWorkflows(rows: readonly TimelineEvent[]): boolean;
40
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
41
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
42
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
43
+ * otherwise, `agent` when it called none. */
44
+ export declare function runPathOf(rows: readonly TimelineEvent[]): RunPath;
45
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
46
+ * or null when it called none by a name. */
47
+ export declare function workflowNameOf(calls: readonly {
48
+ tool: string;
49
+ args: Record<string, unknown>;
50
+ }[]): string | null;
36
51
  /** How many of an agent's latest runs draftForOf reads at most: a skill offered to fewer than DRAFT_AFTER_RUNS of them is
37
52
  * no repeated job. */
38
53
  export declare const DRAFT_SCAN_RUNS = 200;
@@ -64,10 +64,11 @@ export function learningEndOfRun(launch, deps) {
64
64
  // A draft asked for or not never stops the turn: a count that can't be read asks for none.
65
65
  promptFacts: async (runId, agentId) => {
66
66
  const { tools } = await draftTools(deps, runId);
67
- const draftFor = await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
67
+ // A notes run (`learning: "notes"`) is asked for no workflow draft, and its prompt describes none.
68
+ const draftFor = start.notesOnly ? [] : await draftForOf(deps, agentId, runId, start.skills ?? []).catch(() => []);
68
69
  // With a draft asked for, what each tool its call nodes may run takes and gives, in the server's own words.
69
70
  const described = draftFor.length ? await describedOf(tools, deps.store) : [];
70
- return { active: start.seedNotes ?? start.given.length, tools, draftFor, described };
71
+ return { active: start.seedNotes ?? start.given.length, tools, draftFor, described, ...(start.notesOnly ? { workflows: false } : {}) };
71
72
  },
72
73
  asked: async (runId) => {
73
74
  const [entries, reflect] = await Promise.all([runEntries(deps.store, runId, BACKGROUND_CONTEXT), runReflect(deps.store, runId, BACKGROUND_CONTEXT)]);
@@ -97,7 +98,7 @@ export function learningEndOfRun(launch, deps) {
97
98
  check: async ({ runId, agentId, turn, outcome, refuse }) => {
98
99
  if (start.seed === null)
99
100
  throw new Error("the run's learning start names no commit of main to propose against");
100
- return checkedOf(deps, { runId, agentId, seed: start.seed, turn, outcome, refuse });
101
+ return checkedOf(deps, { runId, agentId, seed: start.seed, turn, outcome, refuse, ...(start.notesOnly ? { workflows: false } : {}) });
101
102
  },
102
103
  // The learning run's id, one per run: a replayed end queues the same one (the store adds it once).
103
104
  newRunId: () => `${runId}-learning`,
@@ -117,7 +118,7 @@ export function learningEndOfRun(launch, deps) {
117
118
  }
118
119
  /** learned_workflow by every name a harness calls it: its own, and claude-agent's host-tool alias (`mcp__hands__<name>`).
119
120
  * A harness that names it another way reads as another tool, so its run is asked as before. */
120
- const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
121
+ export const LEARNED_NAMES = new Set([LEARNED_WORKFLOW_TOOL, `mcp__hands__${LEARNED_WORKFLOW_TOOL}`]);
121
122
  /** Whether a run's job, by its timeline `rows` (the end-of-run turn's own, labelled LEARNING_LABEL, left out), gave
122
123
  * nothing new to look back on: it called tools, every one of them learned_workflow (a workflow's own nested calls are
123
124
  * its), each answering; no tool result failed or was refused; no error, approval or wait; and one message, its first,
@@ -137,6 +138,26 @@ export function onlyLearnedWorkflows(rows) {
137
138
  const answered = new Set(results.filter((row) => !row.parent_tool_use_id).map((row) => row.tool_use_id));
138
139
  return calls.every((row) => answered.has(row.tool_use_id));
139
140
  }
141
+ /** The path a run took (learning-cost.ts RunPath), by its timeline `rows` as runTimeline labels them (its end-of-run
142
+ * turn's rows, LEARNING_LABEL, are the learning's and left out): `workflow` when its job did only what
143
+ * onlyLearnedWorkflows asks of a run with nothing new to look back on, `handed_back` when it called a learned workflow
144
+ * otherwise, `agent` when it called none. */
145
+ export function runPathOf(rows) {
146
+ const ran = rows.some((row) => row.agent_label !== LEARNING_LABEL && row.kind === "tool_use" && !row.parent_tool_use_id && LEARNED_NAMES.has(row.tool_name ?? ""));
147
+ if (!ran)
148
+ return "agent";
149
+ return onlyLearnedWorkflows(rows) ? "workflow" : "handed_back";
150
+ }
151
+ /** The learned workflow a run's job called last by its call's `name` (callArgsOf's arguments, in the job's order: `calls`),
152
+ * or null when it called none by a name. */
153
+ export function workflowNameOf(calls) {
154
+ for (let i = calls.length - 1; i >= 0; i--) {
155
+ const call = calls[i];
156
+ if (LEARNED_NAMES.has(call.tool) && typeof call.args.name === "string")
157
+ return call.args.name;
158
+ }
159
+ return null;
160
+ }
140
161
  /** Why each draft of `proposal` waits for its owner's OK whatever the grade: its steps calling an MCP tool with no
141
162
  * declared price (skills.ts unpricedCalls), by its workflow.json's path, from the prices each server's row keeps
142
163
  * (mcp-probe.ts McpPrices). A server the store can't read gives no price: held. */
@@ -291,7 +312,7 @@ async function checkedOf(deps, input) {
291
312
  const folder = deps.learningFolder(input.agentId);
292
313
  let proposed;
293
314
  try {
294
- proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ask: { asked, fits: learnedAskFits } });
315
+ proposed = await proposeRun({ folder: folder.workspace, runDir, seed: input.seed, turn, refuse: input.refuse, outcome: input.outcome, tools, ...(Object.keys(gated).length ? { gated } : {}), ...(Object.keys(deniedBy).length ? { deniedBy } : {}), ask: { asked, fits: learnedAskFits }, ...(input.workflows === false ? { workflows: false } : {}) });
295
316
  }
296
317
  finally {
297
318
  await folder.end();
@@ -6,8 +6,10 @@
6
6
  // (passed in by the runner's wiring);
7
7
  // folder the agent's learning folder in the server's data (learn/folder.ts learningWorkspace), ended after each run;
8
8
  // readMain main as the grader reads it, from the folder's snapshot (learn/commit.ts readMain);
9
- // commit the folder's one write (learn/commit.ts learningCommit).
10
- import { learningCommit, readMain } from "../learn/commit.js";
9
+ // commit the folder's one write (learn/commit.ts learningCommit);
10
+ // merged the run's merge when it is on main already, with the texts its own commit holds (learn/commit.ts mergedAt),
11
+ // for a resume after its commit.
12
+ import { learningCommit, mainTexts, mergedAt, readMain } from "../learn/commit.js";
11
13
  import { learningWorkspace } from "../learn/folder.js";
12
14
  import { createLearningLoop } from "./learning-loop.js";
13
15
  /** The harness a learning run's launch names (store/sqlite/run-patch.ts learningLaunchOf). */
@@ -32,6 +34,8 @@ export function learningLoopFactory(deps) {
32
34
  folder: (agentId) => learningWorkspace({ mode: "local", agentId, data: deps.data, ...(deps.log ? { log: deps.log } : {}) }),
33
35
  readMain: async (ws, proposal) => (await readMain(ws, { notes: proposal.notes })),
34
36
  commit: async (ws, change) => (await learningCommit(ws, change)),
37
+ mainTexts: (ws, paths) => mainTexts(ws, paths),
38
+ merged: (ws, runId, paths) => mergedAt(ws, runId, paths),
35
39
  ...(deps.now ? { now: deps.now } : {}),
36
40
  });
37
41
  }