@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
@@ -5,13 +5,17 @@ import { answeredUnpriced, modelPortFor, RUNNER_RECORDS, sessionSpendOf } from "
5
5
  import { ASK_PERSON_WAITING, capNowOf, endedAnswer, KINDS, MESSAGE_SENT_AGAIN, withdrawnAnswers } from "./journal-kinds.js";
6
6
  import { endedOnTurnEndingTool, HOST_PHASE, MESSAGE_ORIGIN, originOf, RUN_RESUMED } from "../timeline/index.js";
7
7
  import { raiseFollowUpId } from "../run-view.js";
8
+ /** The root entries a claim writes before its turn, whatever the run's turns are (its session's key, a phase row, a
9
+ * takeover's note, its computer's hold, the learning seed it laid): read past when a claim asks whether the run's root ends
10
+ * on its end (a fresh reopen). */
11
+ const CLAIM_BOOKKEEPING = new Set([KINDS.sessionKey, HOST_PHASE, RUN_RESUMED, KINDS.learningLaid, "computer.hold"]);
8
12
  /** A raised run's follow-up is the server's message (the kernel cap's followUpOf), never the person's. */
9
13
  const CAP_RAISED_ORIGIN = { kind: "server", reason: "cap_raised" };
10
- import { ClaimRefused, deniedText, endedBy, noteOf } from "./loop-contract.js";
14
+ import { ClaimRefused, deniedText, noteOf, stopEnd } from "./loop-contract.js";
11
15
  import { deniedText as setToDenyText, ENDED_WHILE_WAITING, refusedText, STOPPED_WHILE_WAITING } from "../refusal-words.js";
12
16
  import { ADAPTER_API } from "../turn-end.js";
13
17
  import { answerText, REFLECT_NOTE_ONLY, reflectRequestId, underLearning, WRITES } from "./end-of-run.js";
14
- import { approvalOf, CLOSE_MS, CUT_STEP_MS, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, Interrupted, KernelFault, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
18
+ import { approvalOf, CLOSE_MS, CUT_STEP_MS, STOP_SETTLE_MS, commandRequest, cutLast, DEFAULT_RESTART_LIMIT, entriesOf, findData, Gate, heldReporter, INPUT_REQUEST, Interrupted, KernelFault, Parked, quiet, restartLimited, writesEntry, writesSubmission } from "./loop.js";
15
19
  import { answerOnce, HAND_BACK, handBackOf } from "./hand-back.js";
16
20
  import { isComputerCommand, journalHold } from "./computer-journal.js";
17
21
  import { COMPUTER_HANDOVER_KIND, COMPUTER_HOLD_KIND } from "../computer-commands.js";
@@ -24,7 +28,7 @@ import { sideEffect } from "./side-effects.js";
24
28
  import { McpClaimRefused } from "./mcp-claim.js";
25
29
  import { Fenced } from "../store/index.js";
26
30
  import { parkedFollowUp } from "./mcp-run.js";
27
- import { TOOL_BUDGET_TEXT, WRAP_UP_TEXT, wrappingUp } from "../tool-budget.js";
31
+ import { budgetOf, TOOL_BUDGET_TEXT, WRAP_UP_TEXT, wrappingUp } from "../tool-budget.js";
28
32
  /** A pause or resume row on an agentic run, refused in main's words (runs.ts pause): only a workflow run pauses. */
29
33
  export const AGENTIC_PAUSE_REFUSED = "Only a workflow run pauses here: an agentic run's turn is stopped with POST /runs/{id}/stop.";
30
34
  /** The request ids of the person's messages placed as turns (loop.ts commandRequest). */
@@ -55,6 +59,15 @@ export function agentConversation(record) {
55
59
  * before the spec's lifecycle was known). Set in the root's creating commit, cleared in the commit that makes them, so a
56
60
  * claim lost in between leaves them to the next claim. */
57
61
  const RootWritesOwed = defineDoc({ kind: "agentrun.root-writes-owed", version: 1, scope: "conversation", history: "latest", fork: "initial", initial: () => ({ owed: false }), checkpointWhen: () => false });
62
+ /** pi's retry of a model request that failed in a way it retries (a provider's 429, overload or 5xx, a dropped connection,
63
+ * a stream cut mid-answer): up to 8 more attempts, 2s doubling to at most 30s apart (about two and a half minutes in all),
64
+ * so a provider's capacity outage of a minute or two is waited out, not the run's end. Each wait is the harness's own
65
+ * durable sleep; a subagent's conversation runs on the same settings. */
66
+ export const MODEL_RETRY = { enabled: true, maxRetries: 8, baseDelayMs: 2_000, maxAgentDelayMs: 30_000 };
67
+ /** pi-ai's retries inside one attempt, of a request the provider refused before any output (a 429 or a 5xx, through the
68
+ * session's proxy, which passes on its retry-after): after the wait the provider asked for, up to 30s, else its own short
69
+ * backoff. Each is a new request through the proxy, judged by the cap and booked as any other: a refusal books nothing. */
70
+ export const MODEL_STREAM = { maxRetries: 2, maxRetryDelayMs: 30_000 };
58
71
  /** The most of a harness's own turn error a failed run's summary keeps. */
59
72
  const TURN_ERROR_MAX = 500;
60
73
  /** A paid call's refusal an earlier claim kept (KINDS.pausePending) whose pause never landed: the newest one with no
@@ -158,6 +171,8 @@ async function openCliRecord(harness, journal, context, now, cwd) {
158
171
  // The command rows a message was about to be sent for (their intent marks): one sent again is a retry.
159
172
  const sending = new Set();
160
173
  let personWritten = false;
174
+ // The request ids of the follow-ups written (followUp): each is written once.
175
+ const followUps = new Set();
161
176
  // Each end-of-run turn's prompt the record wrote as it asked the turn, by its request id: a turn asked again (a later
162
177
  // claim, after a crash in the turn) reuses it, never writes a second.
163
178
  const askedAt = new Map();
@@ -179,6 +194,8 @@ async function openCliRecord(harness, journal, context, now, cwd) {
179
194
  started.set(data.callId, true);
180
195
  else if ((entry.kind === KINDS.message && data.role === "person") || entry.kind === KINDS.input)
181
196
  personWritten = true;
197
+ if ((entry.kind === KINDS.message || entry.kind === KINDS.input) && typeof data.requestId === "string")
198
+ followUps.add(data.requestId);
182
199
  }
183
200
  for (const [callId, ended] of started) {
184
201
  if (ended || (parked.has(callId) && !sent.has(callId)))
@@ -231,6 +248,16 @@ async function openCliRecord(harness, journal, context, now, cwd) {
231
248
  await harness.commit((tx) => tx.appendEntry(root.id, { kind: KINDS.input, data: { origin }, model: [{ role: "user", content: input, timestamp: now() }] }), context);
232
249
  personWritten = true;
233
250
  }),
251
+ followUp: (input, requestId, origin) => inTurn(async () => {
252
+ if (followUps.has(requestId))
253
+ return;
254
+ if (origin)
255
+ await harness.commit((tx) => tx.appendEntry(root.id, { kind: KINDS.input, data: { origin, requestId }, model: [{ role: "user", content: input, timestamp: now() }] }), context);
256
+ else
257
+ await append(KINDS.message, { role: "person", text: input, requestId });
258
+ followUps.add(requestId);
259
+ personWritten = true;
260
+ }),
234
261
  message: (input, origin) => inTurn(async () => {
235
262
  if (origin)
236
263
  await harness.commit((tx) => tx.appendEntry(root.id, { kind: KINDS.input, data: { origin }, model: [{ role: "user", content: input, timestamp: now() }] }), context);
@@ -342,6 +369,8 @@ export function createAdapterLoop(spec, options = {}) {
342
369
  }
343
370
  function adapterLoop(specOf, options, deps) {
344
371
  const restartLimit = options.restartLimit ?? DEFAULT_RESTART_LIMIT;
372
+ const retry = options.retry ?? MODEL_RETRY;
373
+ const stream = options.stream ?? MODEL_STREAM;
345
374
  const now = options.now ?? Date.now;
346
375
  /** The gate's clock as main's card says a time: ISO. */
347
376
  const isoNow = () => new Date(now()).toISOString();
@@ -411,6 +440,10 @@ function adapterLoop(specOf, options, deps) {
411
440
  * Also set while the run waits in its claim on the person's answer to its question (waitInClaim): their message is sent
412
441
  * the same way, as the claim's next turn, and `placed` wakes the wait once it is sent. */
413
442
  let reopen;
443
+ /** A reopen of a run whose session is still new (a person stopped it before its first input was sent): resolved once the
444
+ * person's message is placed as that first input. The claim waits on it, never sending the input they stopped, however
445
+ * late the runner hands the message over. */
446
+ let firstInputPlaced;
414
447
  /** The tool hosts' holds while the run waits in its claim on the person's answer (HostLifecycle.personWait): dropped
415
448
  * once the wait is over, whichever way it ends. */
416
449
  let waitHolds = [];
@@ -634,11 +667,12 @@ function adapterLoop(specOf, options, deps) {
634
667
  if (!gate || !session || gate.sealed)
635
668
  return { later: "the run is parking: the steer waits for its resume" };
636
669
  // The run's job has answered and it is looking back before its end: a person's message is not the end-of-run turn's
637
- // to answer. Left untaken, so the run's end says it came after the answer.
670
+ // to answer. Left untaken, the run's end opens a completed run again with it as a new turn (store run-patch.ts
671
+ // refuseLeftovers).
638
672
  if (reflecting)
639
- return { later: "the run has answered and is ending: the steer is not placed in its end-of-run turn" };
673
+ return { later: "the run has answered and is ending: the message opens it again as a new turn once its end is in" };
640
674
  if (handingBack)
641
- return { later: "the run has answered and waits for its computer to be handed back before it ends: the steer is not placed" };
675
+ return { later: "the run has answered and waits for its computer to be handed back before it ends: the message opens it again as a new turn once its end is in" };
642
676
  const text = typeof command.body?.text === "string" ? command.body.text : "";
643
677
  const requestId = commandRequest(command.id);
644
678
  // A message that answers nothing (a trigger's, answers: false) waits for the turn's end and runs as a turn of its
@@ -657,14 +691,36 @@ function adapterLoop(specOf, options, deps) {
657
691
  return { refused: "The run is waiting on a person." };
658
692
  // A reopened run's follow-up, its session idle: sent as a turn of its own, tracked to its end (as the input and a raise's
659
693
  // follow-up are), its row taken in its submission's commit; the claim waits on it before the run's next end.
660
- if (reopen && !reopen.sent && session.state === "idle") {
694
+ if (reopen && !reopen.sent && (session.state === "idle" || session.state === "new")) {
661
695
  const theSession = session;
662
- // The answer to a wait in the claim: the row's waiting summary goes in its commit.
663
- const taken = gate.expect(writesSubmission(requestId), { take: [command.id], ...(reopen === waitTurn ? { run: { summary: null } } : {}) });
696
+ const theRecord = cliRecord;
697
+ // Who wrote it, when the person did not (a trigger's message that reopened the run): its input is that origin's.
698
+ const by = originOf(command.body?.origin);
699
+ // A run a person stopped before its first input was sent (a stop during a harness's first-use install): its session
700
+ // is new. A stop then means "don't start yet", never "forget what I asked": the run's first turn is one request
701
+ // carrying the original input and then the person's message, under the first input's id. The original input is
702
+ // never sent, or answered, as a turn of its own.
703
+ const first = theSession.state === "new" ? specNow : undefined;
704
+ const sendId = first ? INPUT_REQUEST : requestId;
705
+ const content = first ? `${first.input}\n\n${text}` : text;
706
+ // The row is taken only once the session holds the prompt: pi's in its submission's commit; a CLI's (whose harness
707
+ // writes no submission) in the record's follow-up entry, written right after the send, as sendAfterTurn takes its
708
+ // row. A runner lost between the send and that entry leaves the row untaken, so the next claim sends it again: a
709
+ // follow-up may be sent twice after a crash, never lost. The answer to a wait in the claim: the row's waiting summary
710
+ // goes in that commit too.
711
+ const placedBy = theRecord ? writesEntry(by ? KINDS.input : KINDS.message, (data) => data.requestId === requestId) : writesSubmission(sendId);
712
+ const taken = gate.expect(placedBy, { take: [command.id], ...(reopen === waitTurn ? { run: { summary: null } } : {}) });
664
713
  taken.catch(() => undefined);
665
714
  reopen.sent = (async () => {
666
- await cliRecord?.person(text);
667
- await theSession.send(text, { id: requestId });
715
+ await theSession.send(content, { id: sendId, ...(by ? { origin: by } : {}) });
716
+ // A CLI's record: the original input as its writer's (the launch's origin, else the person's), then the message.
717
+ if (first) {
718
+ if (first.inputOrigin)
719
+ await theRecord?.input(first.input, first.inputOrigin);
720
+ else
721
+ await theRecord?.person(first.input);
722
+ }
723
+ await theRecord?.followUp(text, requestId, by);
668
724
  })();
669
725
  reopen.placed?.();
670
726
  try {
@@ -777,7 +833,7 @@ function adapterLoop(specOf, options, deps) {
777
833
  /** The root a phase is making, awaited before the owed writes are read. */
778
834
  let rootMaking;
779
835
  harness = await Harness.open(gate.journal, {
780
- models: () => models, registry, settings: { restartLimit }, onReport: () => { },
836
+ models: () => models, registry, settings: { restartLimit, retry, stream }, onReport: () => { },
781
837
  // A tool host's onConversation, in each agent conversation's creating commit (the spec's, once it is known: the
782
838
  // root is created when the session opens, after the spec).
783
839
  conversationCreated: async (tx, record) => {
@@ -889,7 +945,7 @@ function adapterLoop(specOf, options, deps) {
889
945
  // A person's stop while the spec was built (it waited on a harness's install): the run ends stopped, in the stop's
890
946
  // words, its row taken; the work it waited on goes on for the next run. A stop wins over the build's own failure.
891
947
  if (stopReason?.kind === "command")
892
- return await writeEnd(harness, await harness.root(context), gate, { state: "stopped", summary: endedBy(stopReason.cancel) }, [stopReason.commandId]);
948
+ return await writeEnd(harness, await harness.root(context), gate, stopEnd(stopReason.cancel), [stopReason.commandId]);
893
949
  // A spec that failed after a phase made the run's root (its computer's image build failed): the end goes on that
894
950
  // root with why (said: cut of every secret the runner holds), as run()'s catch writes it once the session's root
895
951
  // is known, so the timeline keeps the phase row and reads the failure after it.
@@ -1032,6 +1088,11 @@ function adapterLoop(specOf, options, deps) {
1032
1088
  // claim resumes the run parked (an unanswered pause), never ends it as a failed turn. One that cannot land (the
1033
1089
  // journal sealed) is left to the turn's end, as before.
1034
1090
  const park = spec.cap?.park(refusalOf(answer), raisedCapUsd ?? spec.cap.capUsd);
1091
+ // Parking: every later request of this claim is refused in the same words, so nothing more is sent until a raise
1092
+ // (on the next claim) resumes the run. A run's other conversations (a subagent's children) ask in their own
1093
+ // turns; one refused request parks them all, never one alone.
1094
+ if (park?.outcome === "parked")
1095
+ pendingPause ??= answer;
1035
1096
  if (park?.outcome === "parked" && !pausedAtRefusal && harness && gate && !gate.sealed) {
1036
1097
  const on = gate;
1037
1098
  // From here a raise row waits for the next claim (raise): one taken now would answer no pause this claim
@@ -1271,6 +1332,9 @@ function adapterLoop(specOf, options, deps) {
1271
1332
  : undefined;
1272
1333
  session = await spec.adapter.open({ ...spec.session, tools: ownClient ? tools.filter((tool) => !mcpNames.has(tool.name)) : tools, ...(sessionMcp ? { mcp: sessionMcp } : {}) }, io);
1273
1334
  root = await harness.root(context);
1335
+ // The root as the claim found it, before this pass writes anything of its own there (the computer's show-up, a
1336
+ // takeover's note): what the reopen check below reads, so a fresh reopen is told by the run's own last entry.
1337
+ const foundEntries = restarts === 0 ? await entriesOf(gate.journal, root.id, context) : [];
1274
1338
  // The run's desktop or phone: its hold's changes go to the run's journal, through this pass's Harness (under its
1275
1339
  // fence), and the computer shows up, the agent driving.
1276
1340
  computerNow?.detach();
@@ -1309,10 +1373,34 @@ function adapterLoop(specOf, options, deps) {
1309
1373
  const [journalOf, rootOf, laid] = [harness, root, spec.learningLaid];
1310
1374
  await journalOf.commit((tx) => tx.appendEntry(rootOf.id, { kind: KINDS.learningLaid, data: { skills: [...laid.skills], workflows: [...laid.workflows] } }), context);
1311
1375
  }
1312
- // Reopened by a person's follow-up (runs.reopen): its journal holds an end and its session opens idle. Set before the
1313
- // session is ready, so the follow-up's steer, handed over once it is, is sent as this claim's turn.
1314
- if (restarts === 0 && session.state === "idle" && (await entriesOf(gate.journal, root.id, context)).some((entry) => entry.kind === KINDS.end))
1315
- reopen = {};
1376
+ // Reopened by a person's follow-up (runs.reopen, or the end's own reopen): a fresh reopen is a claim whose journal's
1377
+ // root ends on an end entry, with no input of the root in flight. Then any turn its session still reads open is one
1378
+ // that end already closed (a person's stop leaves the turn they stopped open in the session: an interrupt writes no
1379
+ // end there), done and never resumed, so it is settled (settleOpenTurn, as a host done with a stopped turn settles
1380
+ // it), and the session, idle, takes the follow-up as this claim's turn: set before the session is ready, so the
1381
+ // follow-up's steer, handed over once it is, is sent as that turn. A claim that finds the follow-up already under way
1382
+ // (anything on the root after the end, or a root input in flight: a takeover or a drain mid follow-up) is no reopen:
1383
+ // its session recovers that turn as any open turn.
1384
+ if (restarts === 0) {
1385
+ const rootId = root.id;
1386
+ // Read before this claim's own writes (foundEntries), and past the bookkeeping any claim writes on the root before
1387
+ // its turn (its session's key, a phase row, a takeover's note, the computer's hold, the learning seed it laid):
1388
+ // none of them is a turn of the follow-up's.
1389
+ const endsRoot = foundEntries.findLast((entry) => !CLAIM_BOOKKEEPING.has(entry.kind))?.kind === KINDS.end;
1390
+ const inFlight = (await harness.inspect(context)).submissions.some((one) => one.conversationId === rootId && one.type === "input");
1391
+ if (endsRoot && !inFlight && session.state === "open_turn")
1392
+ await session.settleOpenTurn();
1393
+ // A session still new (a person stopped the run before its first input was sent): the follow-up is its first
1394
+ // input, and the input the person stopped is never sent.
1395
+ firstInputPlaced = undefined;
1396
+ if (endsRoot && !inFlight && session.state === "idle")
1397
+ reopen = {};
1398
+ else if (endsRoot && !inFlight && session.state === "new") {
1399
+ const mine = {};
1400
+ firstInputPlaced = new Promise((resolve) => (mine.placed = resolve));
1401
+ reopen = mine;
1402
+ }
1403
+ }
1316
1404
  opened();
1317
1405
  await reportHeld(harness, root.id);
1318
1406
  if (restarts > restartLimit + 1) {
@@ -1331,7 +1419,7 @@ function adapterLoop(specOf, options, deps) {
1331
1419
  // ends as a stop does mid-turn: in the stop's words, its row taken, with what the end-of-run step keeps of a
1332
1420
  // cut run.
1333
1421
  if (stopReason?.kind === "command") {
1334
- return await writeEnd(harness, root, gate, { state: "stopped", summary: endedBy(stopReason.cancel) }, [stopReason.commandId], await cutRows(claim, spec, "stopped"));
1422
+ return await writeEnd(harness, root, gate, stopEnd(stopReason.cancel), [stopReason.commandId], await cutRows(claim, spec, "stopped"));
1335
1423
  }
1336
1424
  const paused = raising.budget;
1337
1425
  const resumes = raising.resumes;
@@ -1382,7 +1470,7 @@ function adapterLoop(specOf, options, deps) {
1382
1470
  // A person's stop (or cancel) waiting here is taken: the run ends stopped, its waiting calls withdrawn in the
1383
1471
  // end's commit. Released parked instead, its untaken stop would have it claimed again at once, and again.
1384
1472
  if (stopReason?.kind === "command")
1385
- return await writeEnd(harness, root, gate, { state: "stopped", summary: endedBy(stopReason.cancel) }, [stopReason.commandId], await cutRows(claim, spec, "stopped"));
1473
+ return await writeEnd(harness, root, gate, stopEnd(stopReason.cancel), [stopReason.commandId], await cutRows(claim, spec, "stopped"));
1386
1474
  gate.seal(new Parked());
1387
1475
  return { state: "parked" };
1388
1476
  }
@@ -1400,6 +1488,12 @@ function adapterLoop(specOf, options, deps) {
1400
1488
  // A steer handed over waits on the session's readiness (resolved above) before it sends: one turn of the event loop
1401
1489
  // lets it get there.
1402
1490
  await new Promise((resolve) => setImmediate(resolve));
1491
+ // A session still new: the message is the run's first input, and nothing else may be sent first. A row the
1492
+ // runner reads on a later poll is waited for (or the run's stop, park or loss).
1493
+ if (firstInputPlaced && !reopen.sent) {
1494
+ const lost = new Promise((resolve) => (deps.signal.aborted ? resolve() : deps.signal.addEventListener("abort", () => resolve(), { once: true })));
1495
+ await Promise.race([firstInputPlaced, stopping, parking, harness.closed.then(() => undefined, () => undefined), lost]);
1496
+ }
1403
1497
  const sent = reopen.sent;
1404
1498
  reopen = undefined;
1405
1499
  if (sent) {
@@ -1409,9 +1503,12 @@ function adapterLoop(specOf, options, deps) {
1409
1503
  }
1410
1504
  // A claim that starts a turn (the input, a recovery, a follow-up) waits for that turn's end: state is the session as
1411
1505
  // open found it, and a CLI adapter reads idle once its turn is sent, so state read after a send says nothing.
1412
- const placed = followedUp || session.state !== "idle";
1413
- if (followedUp) {
1414
- // The follow-up is the turn this claim runs.
1506
+ // A reopen of a session still new whose message was never placed (the run stopped, parked or was lost meanwhile):
1507
+ // nothing is sent, least of all the input the person stopped.
1508
+ const firstUnplaced = firstInputPlaced !== undefined && !followedUp;
1509
+ const placed = followedUp || (session.state !== "idle" && !firstUnplaced);
1510
+ if (followedUp || firstUnplaced) {
1511
+ // The follow-up is the turn this claim runs, or there is none.
1415
1512
  }
1416
1513
  else if (session.state === "new") {
1417
1514
  // A trigger's first input is its origin's (the launch's), never written as the person's.
@@ -1459,12 +1556,12 @@ function adapterLoop(specOf, options, deps) {
1459
1556
  let timer;
1460
1557
  const settled = await Promise.race([settling, new Promise((resolve) => (timer = setTimeout(() => resolve(false), settleMs)))]);
1461
1558
  clearTimeout(timer);
1462
- // A cancel ends the same way, in its own words (main's "cancelled"); the bound is the same.
1463
- const words = endedBy(stopReason.cancel);
1559
+ // A cancel ends the same way, in its own words (main's "cancelled") and its own outcome; the bound is the same.
1560
+ const stopped = stopEnd(stopReason.cancel);
1464
1561
  const cut = await cutRows(claim, spec, "stopped");
1465
1562
  if (!settled)
1466
- return await writeEnd(harness, root, gate, { state: "failed", summary: `${words}, but the turn did not settle within ${settleMs / 1000} s: a tool call ignored its abort` }, [stopReason.commandId], cut);
1467
- return await writeEnd(harness, root, gate, { state: "stopped", summary: words }, [stopReason.commandId], cut);
1563
+ return await writeEnd(harness, root, gate, { state: "failed", summary: `${stopped.summary}, but the turn did not settle within ${settleMs / 1000} s: a tool call ignored its abort` }, [stopReason.commandId], cut);
1564
+ return await writeEnd(harness, root, gate, stopped, [stopReason.commandId], cut);
1468
1565
  }
1469
1566
  // The wait in the claim lapsed before the person answered (the cap had no room for more of their time, or the browser
1470
1567
  // it kept went): the run parks on its question, as it does with nothing open.
@@ -1547,7 +1644,7 @@ function adapterLoop(specOf, options, deps) {
1547
1644
  // has ended, so there is nothing to settle. Read past the narrowing TypeScript did before the delivery.
1548
1645
  const cutBy = stopReason;
1549
1646
  if (cutBy?.kind === "command")
1550
- return await writeEnd(harness, root, gate, { state: "stopped", summary: endedBy(cutBy.cancel) }, [cutBy.commandId], await cutRows(claim, spec, "stopped"));
1647
+ return await writeEnd(harness, root, gate, stopEnd(cutBy.cancel), [cutBy.commandId], await cutRows(claim, spec, "stopped"));
1551
1648
  if (cutBy || deps.signal.aborted)
1552
1649
  return await interrupted(cutBy?.kind ?? "its claim's signal aborted");
1553
1650
  }
@@ -1583,7 +1680,7 @@ function adapterLoop(specOf, options, deps) {
1583
1680
  // Set by stop() during the wait: read past the narrowing TypeScript did before it.
1584
1681
  const cut = stopReason;
1585
1682
  if (cut?.kind === "command")
1586
- return await writeEnd(harness, root, gate, { state: "stopped", summary: endedBy(cut.cancel) }, [cut.commandId], await cutRows(claim, spec, "stopped"));
1683
+ return await writeEnd(harness, root, gate, stopEnd(cut.cancel), [cut.commandId], await cutRows(claim, spec, "stopped"));
1587
1684
  if (cut || deps.signal.aborted)
1588
1685
  return await interrupted(cut?.kind ?? "its claim's signal aborted");
1589
1686
  }
@@ -1591,7 +1688,7 @@ function adapterLoop(specOf, options, deps) {
1591
1688
  // writes no end of the job's (a person's stop ends the run stopped; a lost claim leaves it for the next claim).
1592
1689
  const step = await endOfRunStep(claim, spec, data.state === "failed" ? "failed" : "completed");
1593
1690
  if (step.kind === "stopped")
1594
- return await writeEnd(harness, root, gate, { state: "stopped", summary: endedBy(stopReason?.kind === "command" ? stopReason.cancel : undefined) }, [step.commandId], await cutRows(claim, spec, "stopped-looking"));
1691
+ return await writeEnd(harness, root, gate, stopEnd(stopReason?.kind === "command" ? stopReason.cancel : undefined), [step.commandId], await cutRows(claim, spec, "stopped-looking"));
1595
1692
  if (step.kind === "interrupted")
1596
1693
  return await interrupted(stopReason?.kind ?? "its claim's signal aborted");
1597
1694
  // The end-of-run turn is one more paid answer: one that passed the cap ends the run in the cap's words (overCap,
@@ -1650,7 +1747,8 @@ function adapterLoop(specOf, options, deps) {
1650
1747
  await hooks.beforeIntent(kernelCall);
1651
1748
  // The tool-call budget, before the gate's settings: a call past it is refused in its fixed words, never parked or
1652
1749
  // asked about.
1653
- const budget = spec.gate?.toolCalls;
1750
+ // A conversation's own budget (a subagent's max_tool_calls) narrows the run's, never widens it.
1751
+ const budget = budgetOf(spec.gate?.toolCalls, call.ownBudget ? await call.ownBudget() : undefined);
1654
1752
  if (budget !== undefined && call.callsBefore && (await call.callsBefore(budget)) >= budget)
1655
1753
  return { deny: TOOL_BUDGET_TEXT };
1656
1754
  // The cap's wrap-up, the same way: once the run has taken its share of the cap, every call the model makes is refused
@@ -1931,6 +2029,9 @@ function adapterLoop(specOf, options, deps) {
1931
2029
  if (done)
1932
2030
  return;
1933
2031
  done = true;
2032
+ if (value === "lapsed")
2033
+ for (const hold of waitHolds)
2034
+ hold.confirmed?.();
1934
2035
  endWait(mine);
1935
2036
  resolve(value);
1936
2037
  };
@@ -2,7 +2,7 @@ import type { Context } from "@earendil-works/chord";
2
2
  import { type CapModel } from "@parcha/agentrun-kernel/kernel/cap";
3
3
  import type { HostTool, Wire } from "@parcha/agentrun-kernel";
4
4
  import type { Approvals } from "../approvals.js";
5
- import type { installSettled } from "../harness-install.js";
5
+ import type { installForClaim, installSettled } from "../harness-install.js";
6
6
  import type { LiveHandover, LiveViewerStore } from "../browser-live.js";
7
7
  import { type PinnedModel, type Tier } from "../model.js";
8
8
  import { type RunLaunch } from "../run-launch.js";
@@ -14,12 +14,13 @@ import { type HostToolCtx } from "../host-tools.js";
14
14
  import { type LearnedWorkflow } from "../learning.js";
15
15
  import { type ToolResults } from "../workspace/run-tools.js";
16
16
  import { type ClaimMcp } from "./mcp-run.js";
17
- import { type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
17
+ import { type AdapterLoopOptions, type AdapterRun, type AdapterRunSpec, hostLifecycle } from "./adapter-loop.js";
18
18
  import { type Claim, type Journal } from "./loop-contract.js";
19
19
  import type { ModelRoute } from "./model-route.js";
20
20
  import { type ArchilClaimOptions } from "../workspace/archil-claim.js";
21
21
  import { type claimComputer, type ComputerDeps } from "../workspace/computer-deps.js";
22
22
  import type { RunComputer } from "../workspace/run-tools.js";
23
+ import type { RunComputerHold } from "./computer-journal.js";
23
24
  import type { ShellPlace } from "../workspace/resolve-computer.js";
24
25
  import type { Workspace } from "../workspace/workspace.js";
25
26
  import { type HeldRedact } from "./redact.js";
@@ -44,6 +45,8 @@ export interface ClaimDeps {
44
45
  export interface ClaimComputer {
45
46
  readonly computer?: RunComputer;
46
47
  readonly hold?: unknown;
48
+ /** The run's desktop or phone and the person's hold on it: the spec's `computer` (AdapterRunSpec.computer). */
49
+ readonly held?: RunComputerHold;
47
50
  release(): Promise<void>;
48
51
  }
49
52
  /** The one shared claim-time computer every spec takes (computer-for-claim.ts), passed in by the runner: the composer's
@@ -96,12 +99,27 @@ export interface AdapterSpecDeps {
96
99
  /** How a CLI run's claim waits for its harness's first-use install (harness-install.ts installSettled); a test wraps it
97
100
  * to see the claim reach the wait. Absent, installSettled itself. */
98
101
  readonly installSettled?: typeof installSettled;
102
+ /** How a CLI run's claim installs its harness when nothing installs it (harness-install.ts installForClaim); a test gives
103
+ * its own, so none reaches npm. Absent, installForClaim itself. */
104
+ readonly installForClaim?: typeof installForClaim;
105
+ /** For tests only: the lock a claim's first-use install of each harness installs by (harness-install.ts installForClaim),
106
+ * by harness, as the server's own option of that name gives its installs. The CLI's runner never sets it, and no
107
+ * environment variable, flag or setting maps onto it; absent, the lock AgentRun ships. */
108
+ readonly harnessLocks?: Readonly<Record<string, string>>;
99
109
  /** A test runner's fake GitHub API, where the GitHub App's installation tokens are minted (runner/github-app.ts). Absent,
100
110
  * https://api.github.com: the CLI's runner never sets it, and no environment variable, flag or setting maps onto it. */
101
111
  readonly githubApi?: string;
112
+ /** A test runner's GitHub site, where a run's pull request is checked out from (pr-checkout.ts): a folder of bare
113
+ * repositories, or a git server on loopback. Absent, https://github.com; nothing kept, no environment variable and no
114
+ * flag reaches it. */
115
+ readonly githubWeb?: string;
102
116
  /** A test runner's fake GitHub MCP origin, the one a github_app server may be at (mcp-claim.ts githubMcpOrigin):
103
117
  * for tests only: no environment variable, flag or setting maps onto it; absent, GitHub's hosted MCP (github.ts GITHUB_MCP_ORIGIN). Only a test's in-process runner sets it; the CLI's runner never does. */
104
118
  readonly githubMcpOrigin?: string;
119
+ /** For tests only: the adapter loop's model retry (adapter-loop.ts retry and stream), so a test whose provider fails a run
120
+ * on purpose does not wait out MODEL_RETRY's two and a half minutes. No environment variable, flag or setting maps onto
121
+ * it; absent, MODEL_RETRY and MODEL_STREAM. */
122
+ readonly modelRetry?: Pick<AdapterLoopOptions, "retry" | "stream">;
105
123
  }
106
124
  /** A model as the cap prices it, from the route's catalog cost: its price WITH TIERS (the money rule — a request past a
107
125
  * model's tier is held and booked at the tier, as main's calculateCost does). `api` is the proxy's shape, for the
@@ -157,7 +175,7 @@ export declare function adapterRunGate(store: Pick<Store, "settings">, claim: Pi
157
175
  approvals?: Approvals;
158
176
  maxToolCalls?: number;
159
177
  };
160
- }, root: RunFiles, shell?: ShellPlace): Promise<NonNullable<AdapterRunSpec["gate"]> & {
178
+ }, root: RunFiles, shell?: ShellPlace, mcpServers?: readonly string[]): Promise<NonNullable<AdapterRunSpec["gate"]> & {
161
179
  readonly permissions: RunPermissions;
162
180
  readonly learn: (flows: readonly LearnedWorkflow[]) => void;
163
181
  }>;
@@ -168,7 +186,7 @@ export declare function storeSettings(store: Pick<Store, "settings">): Promise<A
168
186
  * tools) is held until the spec's release; a build that throws part-way lets go what it made by then (spec-holds.ts). */
169
187
  export declare function adapterRunSpecFromLaunch(launch: RunLaunch, run: AdapterRun, deps: AdapterSpecDeps, claim: Claim): Promise<AdapterRunSpec>;
170
188
  /** The host-tool ctx a non-hand tool is wrapped with (host-tools.ts hostToolOf): the run's own Harness (its commit,
171
- * snapshot, conversation and task reads), the results map, and the run's folder as the api env's cwd (a tool reads no
189
+ * snapshot and task reads), the results map, and the run's folder as the api env's cwd (a tool reads no
172
190
  * file environment, so an error names a path relative to it). Shared by the pi spec's bindNonHandTools and the CLI spec's
173
191
  * learned_workflow. */
174
192
  export declare function hostToolCtxOf(run: AdapterRun, context: Context, results: ToolResults, root: string): HostToolCtx;
@@ -217,6 +235,9 @@ export declare function learnedWorkflowHostTool(opts: {
217
235
  /** The claim's MCP (mcp-run.ts mcpForClaim), when its revision grants an MCP tool: its call nodes may name its tools by
218
236
  * catalog name, each run through the run's own MCP as the loop wraps it. */
219
237
  readonly mcp?: Pick<ClaimMcp, "tools" | "catalogOf">;
238
+ /** The model a node on the session's own port runs on (a node of no tier, or of a tier not in `tiers`), as the run's
239
+ * route names it: what its trace says it ran on. A node of a tier in `tiers` names that tier's model. */
240
+ readonly modelName?: (tier: string | undefined) => string | undefined;
220
241
  }): Promise<HostTool | undefined>;
221
242
  /** The run's non-hand tools as HostTool[], bound through the ToolHost seam and wrapped as the hands are (host-tools.ts
222
243
  * hostToolOf): web_fetch, web_search and monid, each by its catalog name under the adapter loop's one gate (`spec.gate`;