@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.45

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 (346) hide show
  1. package/CHANGELOG.md +131 -5
  2. package/README.md +371 -300
  3. package/dist/acp-package.d.ts +28 -0
  4. package/dist/acp-package.js +23 -0
  5. package/dist/adapter-facts.d.ts +8 -1
  6. package/dist/adapter-facts.js +9 -1
  7. package/dist/adapters.d.ts +5 -0
  8. package/dist/adapters.js +36 -3
  9. package/dist/agent-delete.d.ts +50 -0
  10. package/dist/agent-delete.js +125 -0
  11. package/dist/agents-store.d.ts +9 -3
  12. package/dist/agents-store.js +22 -8
  13. package/dist/agents.d.ts +5 -1
  14. package/dist/agents.js +8 -4
  15. package/dist/api-only.d.ts +8 -3
  16. package/dist/api-only.js +10 -4
  17. package/dist/archil-routes.d.ts +5 -1
  18. package/dist/archil-routes.js +57 -2
  19. package/dist/browser-wait-ended.d.ts +2 -0
  20. package/dist/browser-wait-ended.js +2 -0
  21. package/dist/calendar/ics-faux.d.ts +3 -1
  22. package/dist/calendar/ics-faux.js +12 -2
  23. package/dist/calendar/tools.js +5 -2
  24. package/dist/chatgpt-plan.js +3 -1
  25. package/dist/claude-login.d.ts +135 -0
  26. package/dist/claude-login.js +244 -0
  27. package/dist/cli.js +52 -16
  28. package/dist/composio-preset.js +69 -7
  29. package/dist/composio-triggers.d.ts +14 -0
  30. package/dist/composio-triggers.js +79 -15
  31. package/dist/computer-attach.d.ts +40 -5
  32. package/dist/computer-attach.js +130 -15
  33. package/dist/computer-keys.d.ts +3 -0
  34. package/dist/computer-keys.js +7 -1
  35. package/dist/computer-live.js +3 -2
  36. package/dist/computers.d.ts +21 -10
  37. package/dist/computers.js +39 -28
  38. package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
  39. package/dist/console/assets/index-DaFsZuzQ.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/decisions.d.ts +1 -1
  42. package/dist/dial-relay.d.ts +29 -0
  43. package/dist/dial-relay.js +94 -0
  44. package/dist/email/tools.js +10 -5
  45. package/dist/env-proxy.d.ts +2 -0
  46. package/dist/env-proxy.js +35 -0
  47. package/dist/errors.d.ts +3 -1
  48. package/dist/errors.js +7 -4
  49. package/dist/faux-computers.d.ts +8 -2
  50. package/dist/faux-computers.js +83 -6
  51. package/dist/harness-archive.d.ts +67 -0
  52. package/dist/harness-archive.js +177 -0
  53. package/dist/harness-goose.d.ts +34 -0
  54. package/dist/harness-goose.js +87 -0
  55. package/dist/harness-install.d.ts +21 -0
  56. package/dist/harness-install.js +24 -11
  57. package/dist/harness-opencode/adapter.js +1 -1
  58. package/dist/harness-table.d.ts +9 -1
  59. package/dist/harness-table.js +20 -3
  60. package/dist/harness.d.ts +1 -2
  61. package/dist/harness.js +3 -4
  62. package/dist/host.js +2 -1
  63. package/dist/key-check.js +3 -0
  64. package/dist/learn/audit.d.ts +6 -6
  65. package/dist/learn/audit.js +3 -7
  66. package/dist/learn/check.d.ts +23 -89
  67. package/dist/learn/check.js +57 -335
  68. package/dist/learn/commit.d.ts +63 -90
  69. package/dist/learn/commit.js +124 -316
  70. package/dist/learn/compile.d.ts +53 -50
  71. package/dist/learn/compile.js +87 -102
  72. package/dist/learn/corrections.d.ts +13 -0
  73. package/dist/learn/corrections.js +23 -0
  74. package/dist/learn/delete.d.ts +5 -5
  75. package/dist/learn/delete.js +8 -10
  76. package/dist/learn/folder.d.ts +35 -47
  77. package/dist/learn/folder.js +118 -134
  78. package/dist/learn/index.d.ts +3 -5
  79. package/dist/learn/index.js +6 -9
  80. package/dist/learn/learning.sh +45 -15
  81. package/dist/learn/promote.d.ts +13 -1
  82. package/dist/learn/promote.js +9 -0
  83. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  84. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  85. package/dist/learn/workflow-nodes.js +1 -1
  86. package/dist/learned-workflow.js +2 -2
  87. package/dist/learning-cost.d.ts +38 -24
  88. package/dist/learning-cost.js +41 -24
  89. package/dist/learning-routes.d.ts +91 -170
  90. package/dist/learning-routes.js +183 -421
  91. package/dist/learning-run.d.ts +19 -40
  92. package/dist/learning-run.js +23 -93
  93. package/dist/learning-setting.d.ts +4 -4
  94. package/dist/learning-setting.js +6 -6
  95. package/dist/learning-words.d.ts +28 -74
  96. package/dist/learning-words.js +64 -162
  97. package/dist/learning.d.ts +61 -392
  98. package/dist/learning.js +101 -651
  99. package/dist/live-reach.d.ts +25 -2
  100. package/dist/live-reach.js +46 -4
  101. package/dist/llms.txt +1 -1
  102. package/dist/local-models.d.ts +3 -11
  103. package/dist/local-models.js +5 -6
  104. package/dist/mcp-servers-store.d.ts +4 -4
  105. package/dist/model-form.js +6 -5
  106. package/dist/model.d.ts +4 -0
  107. package/dist/model.js +26 -9
  108. package/dist/native/binding.js +1 -1
  109. package/dist/native/connection.js +1 -1
  110. package/dist/native/discovery.js +1 -1
  111. package/dist/native/instructions.d.ts +3 -0
  112. package/dist/native/instructions.js +5 -3
  113. package/dist/native/remote-worker-bridge.js +9 -43
  114. package/dist/native/remote.d.ts +8 -15
  115. package/dist/native/remote.js +3 -3
  116. package/dist/native/schema.js +1 -1
  117. package/dist/native/types.d.ts +2 -2
  118. package/dist/openapi.js +268 -316
  119. package/dist/paid-calls.d.ts +8 -0
  120. package/dist/paid-calls.js +20 -0
  121. package/dist/particle-provider.d.ts +11 -0
  122. package/dist/particle-provider.js +135 -0
  123. package/dist/port-models.d.ts +12 -4
  124. package/dist/port-models.js +28 -11
  125. package/dist/print.d.ts +27 -0
  126. package/dist/print.js +21 -0
  127. package/dist/provider.d.ts +7 -0
  128. package/dist/provider.js +15 -1
  129. package/dist/reflect-range.js +2 -3
  130. package/dist/run-launch.d.ts +14 -28
  131. package/dist/run-launch.js +9 -12
  132. package/dist/run-learning-served.d.ts +15 -89
  133. package/dist/run-listing.d.ts +34 -0
  134. package/dist/run-listing.js +128 -0
  135. package/dist/run-model-key.js +1 -1
  136. package/dist/run-timeline-served.js +5 -3
  137. package/dist/run-trace.d.ts +97 -0
  138. package/dist/run-trace.js +253 -0
  139. package/dist/run-view.d.ts +15 -0
  140. package/dist/run-view.js +9 -0
  141. package/dist/runnable.js +2 -1
  142. package/dist/runner/adapter-loop.d.ts +8 -6
  143. package/dist/runner/adapter-loop.js +16 -12
  144. package/dist/runner/adapter-run-spec.d.ts +16 -4
  145. package/dist/runner/adapter-run-spec.js +64 -58
  146. package/dist/runner/adapters/index.js +22 -0
  147. package/dist/runner/adapters/pi.d.ts +4 -12
  148. package/dist/runner/adapters/pi.js +2 -2
  149. package/dist/runner/audit.d.ts +1 -1
  150. package/dist/runner/audit.js +16 -8
  151. package/dist/runner/beside.d.ts +6 -2
  152. package/dist/runner/beside.js +38 -9
  153. package/dist/runner/claim-secrets.d.ts +18 -2
  154. package/dist/runner/claim-secrets.js +42 -18
  155. package/dist/runner/cli-run-spec.js +55 -51
  156. package/dist/runner/conformance/harness.d.ts +6 -0
  157. package/dist/runner/conformance/harness.js +16 -5
  158. package/dist/runner/dispatch.d.ts +2 -2
  159. package/dist/runner/end-of-run.d.ts +6 -14
  160. package/dist/runner/end-of-run.js +8 -33
  161. package/dist/runner/feedback-round.d.ts +2 -2
  162. package/dist/runner/feedback-round.js +7 -7
  163. package/dist/runner/github-app.js +3 -1
  164. package/dist/runner/harness-loops.d.ts +0 -8
  165. package/dist/runner/harness-loops.js +11 -59
  166. package/dist/runner/held.d.ts +170 -0
  167. package/dist/runner/held.js +57 -0
  168. package/dist/runner/journal-kinds.d.ts +2 -3
  169. package/dist/runner/journal-kinds.js +2 -3
  170. package/dist/runner/learned-first.d.ts +40 -0
  171. package/dist/runner/learned-first.js +32 -0
  172. package/dist/runner/learning-end.d.ts +77 -69
  173. package/dist/runner/learning-end.js +250 -303
  174. package/dist/runner/learning-seed.d.ts +15 -33
  175. package/dist/runner/learning-seed.js +24 -45
  176. package/dist/runner/loop-contract.d.ts +2 -3
  177. package/dist/runner/main.d.ts +17 -9
  178. package/dist/runner/main.js +63 -20
  179. package/dist/runner/mcp-run.d.ts +11 -0
  180. package/dist/runner/mcp-run.js +67 -0
  181. package/dist/runner/memory-claim.d.ts +10 -5
  182. package/dist/runner/memory-claim.js +12 -6
  183. package/dist/runner/model-route.d.ts +7 -4
  184. package/dist/runner/model-route.js +22 -10
  185. package/dist/runner/native-loop.d.ts +0 -7
  186. package/dist/runner/native-loop.js +9 -101
  187. package/dist/runner/promotion.d.ts +8 -6
  188. package/dist/runner/promotion.js +19 -12
  189. package/dist/runner/reflect-hook.d.ts +64 -95
  190. package/dist/runner/reflect-hook.js +112 -225
  191. package/dist/runner/run-channel.d.ts +43 -0
  192. package/dist/runner/run-channel.js +467 -0
  193. package/dist/runner/run-child-host.d.ts +169 -0
  194. package/dist/runner/run-child-host.js +1222 -0
  195. package/dist/runner/run-child.d.ts +1 -0
  196. package/dist/runner/run-child.js +254 -0
  197. package/dist/runner/run-errors.d.ts +2 -0
  198. package/dist/runner/run-errors.js +20 -0
  199. package/dist/runner/runner.js +1 -5
  200. package/dist/runner/sdk-ask.d.ts +78 -0
  201. package/dist/runner/sdk-ask.js +158 -0
  202. package/dist/runner/sdk-loop.d.ts +2 -4
  203. package/dist/runner/sdk-loop.js +29 -49
  204. package/dist/runner/store-secrets.d.ts +5 -3
  205. package/dist/runner/store-secrets.js +5 -1
  206. package/dist/runner/workflow-first.d.ts +5 -0
  207. package/dist/runner/workflow-first.js +4 -0
  208. package/dist/runner/workflow-spec.js +7 -2
  209. package/dist/runs-over-store.d.ts +16 -28
  210. package/dist/runs-over-store.js +31 -38
  211. package/dist/sdk/runs.d.ts +6 -11
  212. package/dist/sdk/runs.js +20 -41
  213. package/dist/sdk/schema.js +3 -4
  214. package/dist/seal-key.d.ts +5 -0
  215. package/dist/seal-key.js +7 -0
  216. package/dist/secrets.d.ts +3 -0
  217. package/dist/secrets.js +16 -3
  218. package/dist/server.d.ts +55 -33
  219. package/dist/server.js +685 -320
  220. package/dist/sign-ins-store.d.ts +8 -0
  221. package/dist/sign-ins-store.js +36 -1
  222. package/dist/skills.js +1 -1
  223. package/dist/store/index.d.ts +2 -2
  224. package/dist/store/index.js +1 -1
  225. package/dist/store/journal/storage.js +3 -0
  226. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  227. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  228. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  229. package/dist/store/schema.d.ts +53 -4
  230. package/dist/store/schema.js +137 -6
  231. package/dist/store/sqlite/connection.d.ts +2 -0
  232. package/dist/store/sqlite/connection.js +3 -1
  233. package/dist/store/sqlite/run-patch.d.ts +0 -17
  234. package/dist/store/sqlite/run-patch.js +4 -33
  235. package/dist/store/sqlite/store.js +246 -63
  236. package/dist/store/sqlite/worker.js +25 -0
  237. package/dist/store/store.d.ts +193 -36
  238. package/dist/store/store.js +25 -3
  239. package/dist/store-reads/learning.d.ts +102 -204
  240. package/dist/store-reads/learning.js +159 -321
  241. package/dist/store-reads/loop.d.ts +0 -1
  242. package/dist/store-reads/loop.js +1 -1
  243. package/dist/store-view.d.ts +29 -1
  244. package/dist/store-view.js +97 -31
  245. package/dist/template-eval.d.ts +3 -6
  246. package/dist/template-eval.js +22 -36
  247. package/dist/templates.d.ts +2 -1
  248. package/dist/templates.js +6 -3
  249. package/dist/timeline/index.d.ts +1 -1
  250. package/dist/timeline/index.js +1 -1
  251. package/dist/timeline/timeline.d.ts +5 -1
  252. package/dist/timeline/timeline.js +16 -0
  253. package/dist/tool-gate.d.ts +0 -7
  254. package/dist/tool-gate.js +1 -15
  255. package/dist/tool-keys-store.d.ts +1 -1
  256. package/dist/tool-keys.d.ts +6 -4
  257. package/dist/tool-keys.js +12 -6
  258. package/dist/tools.d.ts +2 -2
  259. package/dist/tools.js +11 -4
  260. package/dist/triggers.d.ts +60 -5
  261. package/dist/triggers.js +123 -18
  262. package/dist/validate.js +1 -1
  263. package/dist/webhooks.d.ts +4 -1
  264. package/dist/webhooks.js +11 -4
  265. package/dist/workspace/agent-computer.d.ts +2 -0
  266. package/dist/workspace/agent-computer.js +2 -0
  267. package/dist/workspace/archil-claim.d.ts +7 -0
  268. package/dist/workspace/archil-claim.js +29 -0
  269. package/dist/workspace/archil.d.ts +9 -1
  270. package/dist/workspace/archil.js +165 -3
  271. package/dist/workspace/attach.d.ts +3 -1
  272. package/dist/workspace/attach.js +2 -0
  273. package/dist/workspace/attached-computers.d.ts +16 -5
  274. package/dist/workspace/attached-computers.js +25 -9
  275. package/dist/workspace/computer-deps.js +1 -1
  276. package/dist/workspace/computer-for-claim.d.ts +7 -3
  277. package/dist/workspace/computer-for-claim.js +119 -22
  278. package/dist/workspace/computer-hold.js +2 -1
  279. package/dist/workspace/computer-kept.d.ts +11 -1
  280. package/dist/workspace/computer-kept.js +24 -3
  281. package/dist/workspace/resolve-computer.d.ts +33 -19
  282. package/dist/workspace/resolve-computer.js +172 -64
  283. package/dist/workspace/revision-skills.d.ts +1 -2
  284. package/dist/workspace/revision-skills.js +3 -4
  285. package/dist/workspace/run-workspace.d.ts +1 -1
  286. package/dist/workspace/run-workspace.js +5 -0
  287. package/dist/workspace/synced-folder.d.ts +85 -0
  288. package/dist/workspace/synced-folder.js +230 -0
  289. package/dist/workspace/workspace.d.ts +4 -0
  290. package/launcher/agentrun-serve +1 -1
  291. package/package.json +10 -10
  292. package/templates/README.md +7 -7
  293. package/templates/inbound-lead/agent.md +3 -3
  294. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  295. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  296. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  297. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  298. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  299. package/templates/inbound-lead/lead.schema.json +6 -5
  300. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  301. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  302. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  303. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  304. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  305. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  306. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  307. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  308. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  309. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  310. package/dist/console/assets/index-BUktRvS-.css +0 -1
  311. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  312. package/dist/learn/grade.d.ts +0 -138
  313. package/dist/learn/grade.js +0 -682
  314. package/dist/learn/notes.d.ts +0 -81
  315. package/dist/learn/notes.js +0 -178
  316. package/dist/learn/reflect.d.ts +0 -77
  317. package/dist/learn/reflect.js +0 -228
  318. package/dist/learn/relevance.d.ts +0 -24
  319. package/dist/learn/relevance.js +0 -91
  320. package/dist/learn/seed-check.d.ts +0 -74
  321. package/dist/learn/seed-check.js +0 -103
  322. package/dist/learning-batch.d.ts +0 -291
  323. package/dist/learning-batch.js +0 -600
  324. package/dist/learning-evals.d.ts +0 -35
  325. package/dist/learning-evals.js +0 -99
  326. package/dist/native/context.d.ts +0 -6
  327. package/dist/native/context.js +0 -22
  328. package/dist/propose.d.ts +0 -52
  329. package/dist/propose.js +0 -224
  330. package/dist/runner/learning-ask.d.ts +0 -47
  331. package/dist/runner/learning-ask.js +0 -128
  332. package/dist/runner/learning-dispatch.d.ts +0 -45
  333. package/dist/runner/learning-dispatch.js +0 -99
  334. package/dist/runner/learning-factory.d.ts +0 -16
  335. package/dist/runner/learning-factory.js +0 -50
  336. package/dist/runner/learning-loop.d.ts +0 -273
  337. package/dist/runner/learning-loop.js +0 -521
  338. package/dist/usage.d.ts +0 -11
  339. package/dist/usage.js +0 -11
  340. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  341. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  342. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  343. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  344. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  345. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  346. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -18,7 +18,7 @@ import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } fro
18
18
  import { inspectWorkflow } from "@parcha/agentrun-dsl";
19
19
  import { decisionProvidersIn } from "../decisions.js";
20
20
  import { dropLiveViewer, putLiveViewer } from "../browser-live.js";
21
- import { runnerLiveOf } from "../live-reach.js";
21
+ import { liveForRun, runnerLiveOf } from "../live-reach.js";
22
22
  import { llmTiers, nodeTiers, thinkingLevel, TIERS, tierModelOf, workflowNodes } from "../model.js";
23
23
  import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
24
24
  import { learningStartOf, seedFailed } from "../run-launch.js";
@@ -50,7 +50,8 @@ import { handedSignInReadsBack, signInReads } from "../sign-ins-store.js";
50
50
  import { UNREADABLE_SIGN_IN } from "../run-view.js";
51
51
  import { durableWait } from "../workflow/pi-versions.js";
52
52
  import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, savedModelKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
53
- import { catalogSessionNames, mcpForClaim } from "./mcp-run.js";
53
+ import { catalogSessionNames, mcpWhereHeld } from "./mcp-run.js";
54
+ import { held as runnerSeam, heldOrThrow, heldSignInReads } from "./held.js";
54
55
  import { hostLifecycle } from "./adapter-loop.js";
55
56
  import { RUNNER_HARNESSES } from "./adapters/index.js";
56
57
  import { DEFAULT_HARNESS } from "../harness.js";
@@ -60,12 +61,13 @@ import { ClaimRefused } from "./loop-contract.js";
60
61
  import { bookedSpend, cliRunMetrics, endCostOf, runCostOf, runMetrics } from "./metrics.js";
61
62
  import { journalEntries } from "./journal-reader.js";
62
63
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
63
- import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
64
- import { pathMetrics, servedOf, workflowFirstOf } from "./workflow-first.js";
65
- import { AUDIT_PARKED, settleAudits, withAudit } from "./audit.js";
66
- import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
64
+ import { replayCallsOver } from "./promotion.js";
65
+ import { learnedFirstWhereHeld } from "./learned-first.js";
66
+ import { pathMetrics, servedOf } from "./workflow-first.js";
67
+ import { AUDIT_PARKED, withAudit } from "./audit.js";
68
+ import { runPathOverStore } from "../store-reads/learning.js";
67
69
  import { specBuilt } from "./spec-holds.js";
68
- import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
70
+ import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
69
71
  import { loadArchilSettings } from "../archil-settings.js";
70
72
  import { settingOfDefinition } from "../computer-setting.js";
71
73
  import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
@@ -111,6 +113,11 @@ export function capModelOf(route) {
111
113
  // The cap reads a request's provider overhead by the route's own wire (providerInputOverhead).
112
114
  return { id: route.model, api: route.provider.api, price, outputCeiling: route.outputCeiling ?? null };
113
115
  }
116
+ /** Particle requests are never automatically replayed after an uncertain failure. Retry is a harness-wide setting,
117
+ * so a claim with any Particle route disables it for all its conversations, including subagents on other tiers. */
118
+ export function modelRetryOf(routes) {
119
+ return [...routes].some((route) => route.like?.translatedChatCompletions) ? { retry: { enabled: false } } : {};
120
+ }
114
121
  /** The key of a subagent tier's route in a run's tier routes and proxies (a key of its own, never a learned workflow's
115
122
  * tier: those nodes keep their own route and fallback). */
116
123
  const SUBAGENT_ROUTE = "subagent-";
@@ -240,7 +247,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
240
247
  throw new Error(`run ${claim.runId}: its row is gone from the store`);
241
248
  // A run handed a browser sign-in this runner can't read back (its seal does not open here, or nothing of it is kept):
242
249
  // what it said could repeat a pointer nothing can cut, so it ends failed at its claim, in main's words (runs.ts).
243
- if (!(await handedSignInReadsBack(deps.store, deps.sealKey, runRow)))
250
+ if (!(await (deps.sealKey ? handedSignInReadsBack(deps.store, deps.sealKey, runRow) : heldOrThrow("a handed sign-in's read-back").signInReadsBack())))
244
251
  throw new ClaimRefused(UNREADABLE_SIGN_IN);
245
252
  const revisionRow = await deps.store.agents.revision(runRow.revisionId);
246
253
  if (!revisionRow)
@@ -263,7 +270,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
263
270
  // with no computer makes no control-plane call. mountControl (a test's loopback control-plane fake) is spread into the
264
271
  // mount, so no test reaches the real control plane. MOUNT_TTL_MS is the credential's safety net (its computer's 24 h bound), not its lifetime.
265
272
  // 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.
266
- : 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 } : {}) });
273
+ : await archilWhereHeld({ 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 } : {}) });
267
274
  // Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go.
268
275
  holds.hold({ archil });
269
276
  // The run's Workspace at the claim: Mode 1 the run's local folder (made here, the server's start made it before); Mode 2
@@ -274,8 +281,10 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
274
281
  holds.hold({ ws });
275
282
  // The run's uploaded files, copied into its work/inputs/ before the first turn, from what its start held for it, once
276
283
  // per run (uploads.ts copyRunFiles), and its opening message saved beside them as inputs/message.md (placeRunInputs);
277
- // a copy that fails ends the run failed, saying why.
278
- await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
284
+ // a copy that fails ends the run failed, saying why. A run's own process copies nothing: its runner placed them before
285
+ // the process started (run-child-host.ts), as the server's held uploads are never the run's to read.
286
+ if (!(deps.sealKey === undefined && runnerSeam()))
287
+ await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
279
288
  // The pull request's checkout, when the revision asks for one (pr-checkout.ts): the server's own fetch before the first
280
289
  // turn, with the GitHub App's read-only token for that one repository (or none); the run is told what it holds, or why
281
290
  // there is none. Held from the fetch's start, so the release (after the tools' end) removes it however the claim ends; a
@@ -291,26 +300,16 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
291
300
  const start = learningStartOf(launch);
292
301
  // The revision's own skills are laid in the run's .agents/skills/ before they are read (main's server start laid them;
293
302
  // on the one store the claim does), from the revision row's texts (the body keeps only each file's SHA-256): each
294
- // folder not there yet, never over a learned skill or an earlier claim's. A desktop or a phone (the revision's computer
303
+ // folder not there yet, never over an earlier claim's. A desktop or a phone (the revision's computer
295
304
  // setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
296
305
  const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
297
- // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
298
- // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
299
- // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
300
- // before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
306
+ // A learning run's seed, read once from its learning folder where the run's place keeps it (runner/learning-seed.ts):
307
+ // its learned workflows, cut of the server's secrets, the ones its learned_workflow tool runs. Read before the run's
308
+ // tools are bound. A learning fault, or a seed that failed (seedFailed), gives none.
301
309
  const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
302
310
  const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
303
311
  const seedLaid = start && !seedFailed(start)
304
- ? await layLearningSeed({
305
- work: ws.workspace,
306
- seed: start.seed,
307
- folder: learningFolder,
308
- own: Object.keys(revisionRow.skills ?? {}),
309
- shown,
310
- log,
311
- ...(start.notesOnly ? { workflows: false } : {}),
312
- ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
313
- })
312
+ ? await layLearningSeed({ seed: start.seed, folder: learningFolder, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
314
313
  : undefined;
315
314
  // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
316
315
  // credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
@@ -318,7 +317,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
318
317
  // words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
319
318
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
320
319
  const hold = (values) => cut.hold(values);
321
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, 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, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
320
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, 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, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
322
321
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
323
322
  holds.hold({ passed: mcp });
324
323
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
@@ -468,8 +467,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
468
467
  const tierRoute = tierRoutes.get(by);
469
468
  return tierRoute && tierRoute.model === id ? capModelOf(tierRoute) : undefined;
470
469
  },
471
- // What its learning runs' grades and its audit's shadow took beside it, read by every gate with its own sessions
472
- // (none: it queues none).
470
+ // What its audit's shadow took beside it, read by every gate with its own sessions (none: it starts none).
473
471
  ...(besideOf ? { beside: besideOf } : {}),
474
472
  // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
475
473
  freeRequests: freeModelRequestsOf(deps.env),
@@ -497,32 +495,26 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
497
495
  // chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
498
496
  // onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
499
497
  // becomes its model's.
500
- // A replay run lays only the workflow it replays (runner/promotion.ts replayLaid).
501
- const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
502
498
  // The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
503
499
  // chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
504
500
  // serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
505
501
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
506
502
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
507
503
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
508
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit, a replay check and
509
- // the learning run's grade are skipped, in words, where the run brought its own key or the server holds none.
504
+ // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
505
+ // are skipped, in words, where the run brought its own key or the server holds none.
510
506
  const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
511
507
  const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
512
- if (launch.learning && !launch.replay && !launch.audit)
513
- await settleAudits(audits);
514
- const promotion = claimPromotion({
515
- store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff,
516
- });
517
- const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
518
- // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
519
- await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
508
+ // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
509
+ // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
510
+ const learned = await learnedFirstWhereHeld(deps, { agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, kind: revision.kind, outputSchema: revision.body.outputSchema, launch, context, log, folder: learningFolder, shown, spendOff }, seedLaid?.workflows ?? []);
511
+ const firstChoice = learned.choice;
520
512
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
521
- // answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
522
- const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
513
+ // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
514
+ const replay = learned.recorded ? await replayCallsOver(deps.store, claim.runId, new Map(learned.recorded)) : undefined;
523
515
  const { serve: workflowFirst, revise: workflowRevise } = firstChoice;
524
516
  // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
525
- const workflows = await toolFlowsFor(promotion, launch, laidFlows, firstChoice);
517
+ const workflows = learned.workflows;
526
518
  // A tier a learned workflow's node names and the host has a model of: none can't be reached is left as `why`, and its
527
519
  // node fails in those words (learnedWorkflowHostTool), never on another model.
528
520
  const tierUnreachable = new Map();
@@ -553,7 +545,8 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
553
545
  // An agent whose computer is a browser the claim started gets the browser tool on that one session (tools.ts).
554
546
  const claimBrowser = computer.computer?.kind === "browser" ? computer.computer.browser : undefined;
555
547
  const fakes = deps.evalFakes?.(runRow.agentId);
556
- const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
548
+ const liveAt = await claimLiveAt(deps, claim.runId);
549
+ const host = { ...buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: cut, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}) }), ...(claimBrowser ? { browserComputer: claimBrowser } : {}) };
557
550
  gate.askedOn(host);
558
551
  // The run's tools. The hands (read/write/edit/bash and the background tools) are the kernel registry's over the run's
559
552
  // Workspace and computer (runTools.hostTools); the gate is the adapter loop's own (spec.gate), so they run as asked.
@@ -577,12 +570,14 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
577
570
  // outputContract, the CLI spec's too), then the effort guidance (the launch's effort, never this process's environment).
578
571
  // The one path for every harness.
579
572
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
580
- const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
581
- const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills, ...(seedLaid?.skills ?? [])], ws.workspace, { onDemand: readsFiles(granted) });
573
+ const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
574
+ const instructions = await promptOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills], ws.workspace, { onDemand: readsFiles(granted) });
582
575
  const guidance = effortGuidance(launch.effort);
583
576
  // The run's clock: a template eval case's (EvalFakes.now), else the real one.
584
577
  const now = fakes?.now;
585
- const zone = await runZone(deps.store, launch.inputOrigin);
578
+ // A run's own process reads no trigger's row: its runner answers the zone (held.ts runZone).
579
+ const seam = deps.sealKey ? undefined : runnerSeam();
580
+ const zone = seam ? await seam.runZone() : await runZone(deps.store, launch.inputOrigin);
586
581
  const system = [environmentLine(now, zone), checkout?.note, instructions, outputContract(body.outputSchema), guidance].filter((line) => Boolean(line));
587
582
  // The subagent tool, one of the session's own tools (no extension of its own): a child's tools are a subset of the
588
583
  // revision's grants (each by its session name: an MCP tool's wire name, the browser's registrations), its model the
@@ -625,9 +620,9 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
625
620
  // A typed input's other fields follow its content as one json block (inputMessage).
626
621
  const input = await firstMessage(inputMessage(launch.input), ws.workspace);
627
622
  // The run's end-of-run step, when it learns (learningEndOfRun from the launch's learning start; none otherwise): the
628
- // reflect-and-propose turn over the run's store, asked in the end turn while the claim is held (adapter-loop.ts stepOf).
629
- // Its learning folder is where the run's place keeps it — Mode 1 the agent's folder under the data directory, Mode 2 the
630
- // agent's folder on THIS claim's Archil disk (the proposal is checked against the seed on the disk, never this machine's
623
+ // compile turn and the owner's correction over the run's store, asked in the end turn while the claim is held
624
+ // (adapter-loop.ts stepOf). Its learning folder is where the run's place keeps it — Mode 1 the agent's folder under the
625
+ // data directory, Mode 2 the agent's folder on THIS claim's Archil disk (the draft is checked against the seed on the disk, never this machine's
631
626
  // local path) — so the end-of-run step reads the run's own Workspace, the one the run worked in.
632
627
  // A replay run or an audit's shadow run asks nothing at its end: it is the promotion's, never the agent's to learn from.
633
628
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
@@ -635,12 +630,11 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
635
630
  const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
636
631
  store: deps.store,
637
632
  data: deps.data,
638
- spendOff,
639
633
  ...(deps.env ? { env: deps.env } : {}),
640
634
  // What the run must never learn beside the runner's secrets: the keys its claim handed it, every secret the server
641
635
  // keeps sealed (storeSecrets: the run's redactor holds the same list), and its sign-in's pointers, read back from the
642
636
  // store's sign-ins under the seal key (learning-run.ts refused, on the runner).
643
- signIns: signInReads(deps.store, deps.sealKey),
637
+ signIns: deps.sealKey ? signInReads(deps.store, deps.sealKey) : heldSignInReads(),
644
638
  handed: runnerSecrets(toolEnv),
645
639
  stored: () => storeSecrets(deps.store, deps.sealKey, deps.data),
646
640
  log,
@@ -656,6 +650,7 @@ async function adapterSpec(launch, run, deps, claim, holds, runner) {
656
650
  ...(runner.record ? { record: runner.record } : {}),
657
651
  session,
658
652
  input,
653
+ ...modelRetryOf([route, ...tierRoutes.values()]),
659
654
  // A trigger's first input is its origin's, the launch's own owner flag kept (run-launch.ts keepInputOrigin).
660
655
  ...(launch.inputOrigin ? { inputOrigin: launch.inputOrigin } : {}),
661
656
  // The gate's answer with its words (adapterRunGate, RunGate.decide): a deny names where it was set and that nothing was
@@ -861,9 +856,10 @@ export function liveViewersOf(store, sealKey, claim, cut) {
861
856
  return {
862
857
  put: (handover) => {
863
858
  cut.hold([handover.token]);
864
- return putLiveViewer(store, sealKey, claim, handover);
859
+ // A run's own process holds no seal key: its runner seals the hand-over under the claim (held.ts).
860
+ return sealKey ? putLiveViewer(store, sealKey, claim, handover) : heldOrThrow("a browser viewer's hand-over").liveViewerPut(handover);
865
861
  },
866
- drop: (tag) => dropLiveViewer(store, claim, tag),
862
+ drop: (tag) => (sealKey ? dropLiveViewer(store, claim, tag) : heldOrThrow("a browser viewer's drop").liveViewerDrop(tag)),
867
863
  };
868
864
  }
869
865
  /** `tool` with its answer's text, and a throw's message, cut by `cut` (the run's one redactor). A web call's answer is cut
@@ -896,8 +892,7 @@ export function answersCut(tool, cut) {
896
892
  * session's viewer over through (the store, never files), and the run's own Workspace (`workspace`: in Mode 2 its folder
897
893
  * on the run's disk), where a tool files what the run's read finds later. */
898
894
  export function buildToolHost(opts) {
899
- const liveAt = runnerLiveOf(opts.env, opts.sealKey);
900
- const { root, claim, run, life } = opts;
895
+ const { root, claim, run, life, liveAt } = opts;
901
896
  const { web, now, email } = opts.fakes ?? {};
902
897
  return {
903
898
  ...(web ? { web } : {}),
@@ -918,7 +913,7 @@ export function buildToolHost(opts) {
918
913
  ...(run.rowSummaryOn ? { rowSummaryOn: run.rowSummaryOn } : {}),
919
914
  store: opts.store,
920
915
  claim,
921
- sealKey: opts.sealKey,
916
+ ...(opts.sealKey ? { sealKey: opts.sealKey } : {}),
922
917
  // The run's one ledger, as the adapter loop made it over the run's sessions and handed it on the AdapterRun: the
923
918
  // browser holds and settles its calls here (host.ledger.paid), never on this process's own spend, and a refusal at the
924
919
  // cap parks the run (pause). browserListed reads it to fail closed.
@@ -939,6 +934,17 @@ export function buildToolHost(opts) {
939
934
  ...(opts.toolSettings !== undefined ? { toolSettings: opts.toolSettings } : {}),
940
935
  };
941
936
  }
937
+ /** Where the claim's viewers answer on a runner on another host than its server (live-reach.ts runnerLiveOf), under the
938
+ * claim's run's own proof key (liveForRun); none on the server's machine. In a run's own process its runner's
939
+ * (held.ts liveAt): the process holds its run's key, never the runners' shared one. */
940
+ export async function claimLiveAt(deps, runId) {
941
+ if (deps.sealKey) {
942
+ const live = runnerLiveOf(deps.env ?? {}, deps.sealKey);
943
+ return live && liveForRun(live, runId);
944
+ }
945
+ const given = await runnerSeam()?.liveAt();
946
+ return given && { host: given.host, bind: given.bind, key: Buffer.from(given.key) };
947
+ }
942
948
  /** The run's web host tools (tool-list.ts `host` rows: web_fetch, web_search, monid) as HostTool[], each bound through `host` by its
943
949
  * catalog name and wrapped as the hands are (host-tools.ts hostToolOf, with `ctx`), the one binding the pi spec and the
944
950
  * CLI spec share. Each runs under the adapter loop's one gate (spec.gate) on the claim's keys (host.env), and books its
@@ -2,6 +2,8 @@ import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
2
2
  import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
3
3
  import { facts as openCodeFacts } from "../../harness-opencode/facts.js";
4
4
  import { harnessOf } from "../../harness-table.js";
5
+ import { acpPackage } from "../../acp-package.js";
6
+ import { GOOSE_ID } from "../../harness-goose.js";
5
7
  import { piAdapter } from "./pi.js";
6
8
  const CLAUDE_PACKAGE = "@parcha/agentrun-harness-claude";
7
9
  const CODEX_PACKAGE = "@parcha/agentrun-harness-codex";
@@ -73,6 +75,26 @@ export const RUNNER_HARNESSES = {
73
75
  });
74
76
  },
75
77
  },
78
+ // Goose, where its package is beside serve (acp-package.ts): on the binary `extra.binary` names, which its owner
79
+ // installed (harness-goose.ts); a run on serve's table builds its adapter from its entry (adapters.ts gooseOf).
80
+ [GOOSE_ID]: {
81
+ record: "loop",
82
+ adapter: async (launch, extra = {}) => {
83
+ const acp = acpPackage();
84
+ if (!acp)
85
+ throw new Error("Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this runner");
86
+ if (typeof extra.binary !== "string")
87
+ throw new Error("Goose's runner adapter needs the installed binary's path (extra.binary)");
88
+ return acp.gooseAdapter({
89
+ model: launch.model,
90
+ provider: { origin: launch.provider.origin, credential: launch.provider.credential, ...(launch.provider.headers ? { headers: launch.provider.headers } : {}), ...(launch.provider.auth ? { auth: launch.provider.auth } : {}) },
91
+ ...(launch.price ? { price: launch.price } : {}),
92
+ ...(launch.fetch ? { fetch: launch.fetch } : {}),
93
+ sessionsDir: launch.sessionsDir,
94
+ ...extra,
95
+ });
96
+ },
97
+ },
76
98
  };
77
99
  /** The harness the launch names, as `env`'s harness table has it (harness-table.ts harnessOf): a built-in one's runner is
78
100
  * the runner's own (RUNNER_HARNESSES), one a harness module adds brings its own (HarnessEntry.runner). Undefined when
@@ -1,9 +1,9 @@
1
1
  import type { Context } from "@earendil-works/chord/context";
2
2
  import type { Models } from "@earendil-works/pi-ai";
3
3
  import { type Extension, type Harness, type Registry, type ToolRegistration } from "@earendil-works/pi-durable";
4
- import { type AgentAdapter, type SessionIO, type SessionPort, type Wire } from "@parcha/agentrun-kernel";
4
+ import { type AgentAdapter, type SessionIO, type Wire } from "@parcha/agentrun-kernel";
5
5
  import { type ModelProxy, type ProviderPolicy } from "@parcha/agentrun-kernel/host";
6
- import { type ThinkingLevelMap } from "../../port-models.js";
6
+ import { type SessionLike, type SessionModelPort } from "../../port-models.js";
7
7
  import { type CallStatus } from "../journal-kinds.js";
8
8
  import { CALL_REFUSED } from "../../timeline/index.js";
9
9
  import { type ComputerCallRecord } from "../../computer-calls.js";
@@ -64,15 +64,7 @@ export interface PiAdapterOptions {
64
64
  /** The model pi asks for. */
65
65
  readonly model: string;
66
66
  /** The catalog's entry for the model: whether it reasons, its window and its output ceiling, as pi-ai's model of it. */
67
- readonly like?: {
68
- readonly reasoning?: boolean;
69
- readonly contextWindow?: number;
70
- readonly maxTokens?: number;
71
- readonly input?: readonly string[];
72
- readonly inputLimits?: unknown;
73
- readonly developerRole?: boolean;
74
- readonly thinkingLevelMap?: ThinkingLevelMap;
75
- };
67
+ readonly like?: SessionLike;
76
68
  /** The price of a request's usage, for the proxy's booking. */
77
69
  readonly price?: (model: string, usage: never) => number | null;
78
70
  /** The proxy's upstream fetch (a test's scripted origin). */
@@ -113,7 +105,7 @@ export declare function piAdapter(options: PiAdapterOptions): AgentAdapter;
113
105
  export type TierModel = Pick<PiAdapterOptions, "provider" | "model" | "like" | "price" | "fetch">;
114
106
  /** The tier proxies a session holds (openTierProxies): each tier's port for a side request under `label`, and their close. */
115
107
  export interface TierProxies {
116
- port(label: string, tier: string): SessionPort | undefined;
108
+ port(label: string, tier: string): SessionModelPort | undefined;
117
109
  /** Each tier, its route and its proxy: a subagent's child on the tier is sent there on the proxy's own key. */
118
110
  readonly each: readonly (readonly [string, TierModel, ModelProxy])[];
119
111
  close(): Promise<void>;
@@ -120,7 +120,7 @@ export async function openTierProxies(tiers, hooks, redact, tools = []) {
120
120
  return {
121
121
  port: (label, tier) => {
122
122
  const at = open.get(tier);
123
- return at ? { url: at.proxy.url, key: at.proxy.sideKey(label), model: at.route.model, api: at.route.provider.api } : undefined;
123
+ return at ? { url: at.proxy.url, key: at.proxy.sideKey(label), model: at.route.model, api: at.route.provider.api, ...(at.route.like ? { like: at.route.like } : {}) } : undefined;
124
124
  },
125
125
  each: [...open].map(([tier, { proxy, route }]) => [tier, route, proxy]),
126
126
  close,
@@ -413,7 +413,7 @@ async function sessionOn(proxy, options, spec, io, context, tiers) {
413
413
  port: (label, tier) => {
414
414
  if (closed)
415
415
  return undefined;
416
- return tier === undefined ? { url: proxy.url, key: proxy.sideKey(label), model, api } : tiers.port(label, tier);
416
+ return tier === undefined ? { url: proxy.url, key: proxy.sideKey(label), model, api, ...(like ? { like } : {}) } : tiers.port(label, tier);
417
417
  },
418
418
  // A steer: pi places it in the turn in flight, at its next boundary. `id`: its request id (the command's), so the
419
419
  // commit that places it is the one that takes its row. `origin` (a trigger's message): its input is the host's user
@@ -38,7 +38,7 @@ export declare const AUDIT_PARKED = "the audit ended where it would wait on a pe
38
38
  /** The served run's end-of-run step `step` (none for a run that only uses what its agent learned), its audit started
39
39
  * after it (startAudit) on an end the run reached on its own (a cut run starts none): the learned workflow that served
40
40
  * it, read from its journal whatever claim it served on (servedOf), and, for a capped run, what its cap leaves once this
41
- * end is counted (auditRoomOf: its job, its look-back, the grades beside it and the one this end queues). A run that
41
+ * end is counted (auditRoomOf: its job, its follow-ups, its compile turns). A run that
42
42
  * could never be audited (no learning start, or not auditableLaunch) keeps `step` as it is. */
43
43
  export declare function withAudit(step: EndOfRunTurn | undefined, deps: AuditDeps & {
44
44
  readonly launch: RunLaunch;
@@ -2,10 +2,10 @@
2
2
  // startAudit (withAudit: at the served run's end, before the end commits): a run the promoted workflow answered (path
3
3
  // `workflow`; a run it handed back is never drawn and never counts as served) is drawn at 1 in k (auditDrawn, from its id), and a drawn one appends a `started` line to audits.jsonl (with the
4
4
  // promotion serving it and the answer it audits, `turn`: the id of the run's newest answer row now), then starts its
5
- // shadow run: the same agent and revision on the same input with learning off (no seed, no look-back), marked as the
5
+ // shadow run: the same agent and revision on the same input with learning off (no seed, no compile turn), marked as the
6
6
  // audit of the served run (launch.audit), no row of the run list, billed to the agent as learning cost. Its cap is
7
7
  // what the served run's cap left (the two together never pass it; the served run's later gates count it beside them,
8
- // learning-end.ts besideOf); none left, no shadow (`skipped: "no allowance"`). A shadow never waits on a person: where
8
+ // learning-end.ts shadowBesideOf); none left, no shadow (`skipped: "no allowance"`). A shadow never waits on a person: where
9
9
  // it would park (an approval its owner's setting asks, a raise of that cap, a question) it ends at once in
10
10
  // AUDIT_PARKED's words (AdapterRunSpec.neverWaits, the gate untouched: nothing is let through, no one is asked to
11
11
  // answer), and its row is `parked`. Only a run started over the API (no trigger: its context is never rebuilt for a
@@ -25,7 +25,6 @@
25
25
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
26
26
  import { overCapMessage } from "@parcha/agentrun-kernel/kernel/cap";
27
27
  import { auditLoopOf } from "../learning-setting.js";
28
- import { RUN_CAP_MIN_USD } from "../learning-batch.js";
29
28
  import { launchBody, readLaunchBody } from "../run-launch.js";
30
29
  import { runEntries } from "../store-reads/journal.js";
31
30
  import { runPathOverStore } from "../store-reads/learning.js";
@@ -40,6 +39,10 @@ import { excerptShown } from "../learn/secrets.js";
40
39
  import { auditRoomOf } from "./learning-end.js";
41
40
  import { answerOf, answerRowOf } from "./promotion.js";
42
41
  import { servedOf } from "./workflow-first.js";
42
+ import { held, heldEndOfRun } from "./held.js";
43
+ /** The least cap a run can take a step under (cap.ts: the next step needs at least a cent): a shadow with less left
44
+ * is never started. */
45
+ const RUN_CAP_MIN_USD = 0.01;
43
46
  /** The words a second hold within stop_window leaves on its record: what the owner reads. */
44
47
  export const STOPPED_TWICE = "stopped: the workflow disagreed with the agent twice";
45
48
  const iso = (ms) => new Date(ms).toISOString();
@@ -77,21 +80,25 @@ export const AUDIT_PARKED = "the audit ended where it would wait on a person";
77
80
  /** The served run's end-of-run step `step` (none for a run that only uses what its agent learned), its audit started
78
81
  * after it (startAudit) on an end the run reached on its own (a cut run starts none): the learned workflow that served
79
82
  * it, read from its journal whatever claim it served on (servedOf), and, for a capped run, what its cap leaves once this
80
- * end is counted (auditRoomOf: its job, its look-back, the grades beside it and the one this end queues). A run that
83
+ * end is counted (auditRoomOf: its job, its follow-ups, its compile turns). A run that
81
84
  * could never be audited (no learning start, or not auditableLaunch) keeps `step` as it is. */
82
85
  export function withAudit(step, deps) {
83
86
  if (!deps.launch.learning || !auditableLaunch(deps.launch))
84
87
  return step;
88
+ // In a run's own process the whole step is its runner's (held.ts endOfRun), the audit's start with it: it reads the
89
+ // run's journal and writes the ledger and a run, which no run's process may.
90
+ if (held())
91
+ return heldEndOfRun();
85
92
  return async (input) => {
86
93
  const rows = step ? await step(input) : undefined;
87
94
  if (input.cut === undefined)
88
- await auditAtEnd(deps, input.runId, rows?.also ?? []);
95
+ await auditAtEnd(deps, input.runId);
89
96
  return rows;
90
97
  };
91
98
  }
92
99
  /** Only a run the workflow answered is drawn: its path `workflow` by the one classifier its record keeps
93
100
  * (store-reads/learning.ts runPathOverStore, with the run's `redact`), never one it handed back. */
94
- async function auditAtEnd(deps, runId, queued) {
101
+ async function auditAtEnd(deps, runId) {
95
102
  try {
96
103
  const entries = await runEntries(deps.store, runId, BACKGROUND_CONTEXT);
97
104
  const served = servedOf(entries);
@@ -100,7 +107,7 @@ async function auditAtEnd(deps, runId, queued) {
100
107
  if ((await runPathOverStore(deps.store, runId, deps.launch.learning, deps.redact)).path !== "workflow")
101
108
  return;
102
109
  const capUsd = deps.launch.maxCostUsd;
103
- await startAudit({ ...deps, runId, ...(capUsd !== undefined ? { room: () => auditRoomOf(deps.store, runId, capUsd, entries, queued) } : {}) }, { name: served.workflow, digest: served.digest });
110
+ await startAudit({ ...deps, runId, ...(capUsd !== undefined ? { room: () => auditRoomOf(deps.store, runId, capUsd, entries) } : {}) }, { name: served.workflow, digest: served.digest });
104
111
  }
105
112
  catch (error) {
106
113
  deps.log(`workflow-first: the audit of this run did not start (${error?.message ?? error})`);
@@ -193,8 +200,9 @@ export async function startAudit(deps, serve) {
193
200
  }
194
201
  /** The per_run MCP credentials run `from` was handed, sealed for shadow run `id` alone (as a replay run's are). */
195
202
  async function handedTo(deps, from, id) {
203
+ // A run's own process holds no seal key: its runner seals them again, from its own run alone (held.ts handOn).
196
204
  if (!deps.sealKey)
197
- return undefined;
205
+ return held()?.handOn(from, id);
198
206
  const sealed = await deps.store.runs.launch(from).then((one) => one.sealed ?? null, () => null);
199
207
  const handed = sealed === null ? undefined : openRunMcpAuth(deps.sealKey, from, sealed);
200
208
  return handed && Object.keys(handed).length ? sealRunMcpAuth(deps.sealKey, id, handed) : undefined;
@@ -9,6 +9,7 @@ export declare function besideRunnerOptions(serve: {
9
9
  drainTimeout?: string;
10
10
  }, env: NodeJS.ProcessEnv): {
11
11
  loops: number;
12
+ loopsTold: boolean;
12
13
  drainMs: number;
13
14
  };
14
15
  /** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
@@ -29,12 +30,15 @@ export declare function besideStopping(server: {
29
30
  * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
30
31
  * holds each paired computer's socket in this process, so a run here takes one. `dial`: the server's (Serve.dial), which
31
32
  * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
32
- * and a close() that stops both and closes its store. */
33
- export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded }?: {
33
+ * and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
34
+ * isolation a number past the helper's slots is refused rather than cut. */
35
+ export declare function runnerBeside(dataDir: string, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded }?: {
34
36
  loops?: number;
37
+ loopsTold?: boolean;
35
38
  drainMs?: number;
36
39
  env?: NodeJS.ProcessEnv;
37
40
  janitor?: boolean;
41
+ ownProcesses?: boolean;
38
42
  hub?: import("@parcha/agentrun-computer").AttachHub;
39
43
  dial?: import("@parcha/agentrun-computer").HostedDial;
40
44
  mcpLoopback?: boolean;
@@ -14,7 +14,8 @@ export function besideRunnerOptions(serve, env) {
14
14
  const drainMs = durationMs(drainTimeout);
15
15
  if (drainMs === undefined)
16
16
  throw new Error(`the drain timeout ${drainTimeout} is not a duration such as 8s`);
17
- return { loops: maxRunsOf(env, serve.maxRuns), drainMs };
17
+ // `loopsTold`: the number was given (--max-runs, AGENTRUN_MAX_RUNS), not the host's memory's count.
18
+ return { loops: maxRunsOf(env, serve.maxRuns), loopsTold: serve.maxRuns !== undefined || Boolean(env.AGENTRUN_MAX_RUNS), drainMs };
18
19
  }
19
20
  /** What the CLI's stop waits on (stop-signals.ts StopDeps.stopping) with a runner beside the server: the server's runs
20
21
  * and the runs the runner holds, and the longer of the server's bound and the runner's whole close (its drain, then
@@ -30,8 +31,9 @@ export function besideStopping(server, held, drainMs) {
30
31
  * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
31
32
  * holds each paired computer's socket in this process, so a run here takes one. `dial`: the server's (Serve.dial), which
32
33
  * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
33
- * and a close() that stops both and closes its store. */
34
- export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
34
+ * and a close() that stops both and closes its store. `loopsTold`: `loops` was given (besideRunnerOptions), so on uid
35
+ * isolation a number past the helper's slots is refused rather than cut. */
36
+ export async function runnerBeside(dataDir, { loops, loopsTold, drainMs, env, janitor, ownProcesses, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine, onRunEnded } = {}) {
35
37
  const { runnerName, startRunner } = await import("./runner.js");
36
38
  const { dispatchRunner } = await import("./harness-loops.js");
37
39
  const { routeOf } = await import("./model-route.js");
@@ -69,9 +71,34 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub,
69
71
  // email), by the agent each of its runs is of; only the eval, in its own process, hands them. `harnessInstall`: what a
70
72
  // claim's first-use install installs with (the eval's sharedInstaller, which the server beside it takes too).
71
73
  const { installForClaim } = await import("../harness-install.js");
72
- const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), ...(mcpOwn ? { mcpOwn } : {}), ...(evalFakes ? { evalFakes } : {}), ...(harnessInstall ? { installForClaim: (entry, dir, pins, given) => installForClaim(entry, dir, pins, { ...given, install: harnessInstall }) } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) });
73
- // It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
74
- const { runnerMemory } = await import("./memory-claim.js");
74
+ const deps = { env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), ...(mcpOwn ? { mcpOwn } : {}), ...(evalFakes ? { evalFakes } : {}), ...(harnessInstall ? { installForClaim: ((entry, dir, pins, given) => installForClaim(entry, dir, pins, { ...given, install: harnessInstall })) } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) };
75
+ // `ownProcesses`: each run a process of its own (run-child-host.ts), as a user of its own where the image's helper can
76
+ // switch, as the CLI's start runs them; a helper that cannot is refused in words naming the setting. The template eval's
77
+ // runner (its fakes are functions of this process) runs its runs in this one.
78
+ let isolation;
79
+ let held = loops;
80
+ if (ownProcesses && !evalFakes && !harnessInstall) {
81
+ const { isolationLoops, runIsolationOf } = await import("./run-child-host.js");
82
+ try {
83
+ isolation = await runIsolationOf(process.env, loopsTold ? loops : undefined, deps.log);
84
+ }
85
+ catch (error) {
86
+ await store.close();
87
+ seal.release();
88
+ throw error;
89
+ }
90
+ if (loops !== undefined && isolation.kind === "uid" && loops > isolation.slots)
91
+ deps.log(`each run runs as a user of its own, and the helper reaches ${isolation.slots} slots from slot ${isolation.first}: this runner holds at most ${isolation.slots} runs at once`);
92
+ if (loops !== undefined)
93
+ held = isolationLoops(isolation, loops);
94
+ else if (isolation.kind === "uid")
95
+ held = isolation.slots;
96
+ }
97
+ const { childLoops } = await import("./run-child-host.js");
98
+ const createLoop = isolation ? childLoops({ deps, isolation, log: deps.log }) : dispatchRunner(deps);
99
+ // It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room,
100
+ // each run's own process weighed with it.
101
+ const { runnerMemory, RUN_PROCESS_MIB } = await import("./memory-claim.js");
75
102
  // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts).
76
103
  const { sweepEndedScratch } = await import("./scratch-sweep.js");
77
104
  await sweepEndedScratch(store, dataDir, { log: (line) => console.error(`agentrun-serve runner: ${line}`) });
@@ -95,7 +122,7 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub,
95
122
  // A run's end lets go of what its earlier claims' computers left, with the same computers (run-end-computers.ts).
96
123
  const { runEndComputers } = await import("../workspace/run-end-computers.js");
97
124
  const runEnded = runEndComputers({ store, computers: computers.computerDeps, log: (line) => console.error(`agentrun-serve runner: ${line}`) });
98
- const runner = startRunner({ store, name, createLoop, memory: runnerMemory(store, undefined, runs), onEvent: said, runEnded, ...(loops !== undefined ? { loops } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
125
+ const runner = startRunner({ store, name, createLoop, memory: runnerMemory(store, undefined, runs, isolation ? RUN_PROCESS_MIB : 0), onEvent: said, runEnded, ...(held !== undefined ? { loops: held } : {}), ...(drainMs !== undefined ? { drainMs } : {}) });
99
126
  // The computer janitor over the same computers, when the start asks for it: never under --faux. Its lines are the
100
127
  // runner's, on stderr (a stderr whose reader closed loses them, never the process: cli.ts).
101
128
  const { startJanitor } = await import("../workspace/computer-janitor.js");
@@ -112,9 +139,11 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub,
112
139
  export async function serveWithRunner(options) {
113
140
  const { fauxEnvOf, startServe } = await import("../server.js");
114
141
  const { besideRunEnv } = await import("./main.js");
115
- const { loops, drainMs } = besideRunnerOptions(options, process.env);
142
+ const { loops, loopsTold, drainMs } = besideRunnerOptions(options, process.env);
116
143
  const serve = await startServe(options);
117
- const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
144
+ // Each run a process of its own, as a user of its own where the image's helper can switch, as the CLI's start runs
145
+ // them (cli.ts): the isolation the server's capabilities say (runIsolationOf over the same helper) is the runner's.
146
+ const beside = await runnerBeside(options.data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
118
147
  await serve.close();
119
148
  throw error;
120
149
  });