@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
@@ -5,6 +5,7 @@ import type { SealedKeys } from "../store/store.js";
5
5
  import type { Revision } from "../agent-rows.js";
6
6
  import type { HeldRedact } from "./redact.js";
7
7
  import { type HeldModelKey } from "../run-model-key.js";
8
+ import { type RunModelKey } from "../store/seal.js";
8
9
  /** What claimSecrets reads the keys from: the one store (its sealed keys) and the runner's seal key, and the runner's base
9
10
  * environment (its own, with no server secret in it: those are the store's). */
10
11
  export interface ClaimSecretsDeps {
@@ -48,7 +49,7 @@ export declare const MODEL_KEY_NAMES: readonly string[];
48
49
  * and a provider the runner holds any key of gets none of its saved ones.
49
50
  * The keys added are never enumerable either: a spread of the result, or a spawn given it, carries none of them. */
50
51
  export declare function withModelKeys(env: NodeJS.ProcessEnv, opened: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
51
- /** Every model key the server holds, for a model route with no revision to scope it by (a learning run's grade): each
52
+ /** Every model key the server holds, for a model route with no revision to scope it by (an SDK run's compile turn): each
52
53
  * by its name from `deps.env` first, then the store's sealed value, as claimSecrets reads them. */
53
54
  export declare function savedModelKeys(deps: ClaimSecretsDeps): Promise<NodeJS.ProcessEnv>;
54
55
  /** A run's own model key, held by its claim (run-model-key.ts): `fresh()` opens it from the run's launch again (a message's
@@ -60,6 +61,18 @@ export interface ClaimModelKey extends HeldModelKey {
60
61
  /** Calls `listener` with the key now and with each new one fresh() opens: the run's redactors hold every key it held. */
61
62
  watch(listener: (key: string) => void): void;
62
63
  }
64
+ /** Run `runId`'s own model key as its launch's sealed column holds it, opened under `deps.sealKey`: none for a launch that
65
+ * holds none (or no launch row: a test's, an import's). Throws, in words, where the launch does not open. */
66
+ export declare function openRunModelKey(deps: {
67
+ readonly store: {
68
+ readonly runs: {
69
+ launch(runId: string): Promise<{
70
+ readonly sealed: Uint8Array | null;
71
+ }>;
72
+ };
73
+ };
74
+ readonly sealKey: Buffer | undefined;
75
+ }, runId: string): Promise<RunModelKey | undefined>;
63
76
  /**
64
77
  * The run's own model key for claim `runId`, opened from its launch's sealed column under the runner's seal key (the
65
78
  * server sealed it there with mcp_auth, store/seal.ts). Undefined only where the server has no gateway and the run holds
@@ -84,8 +97,11 @@ export declare function holdRunKey(redact: HeldRedact, runKey: ClaimModelKey): v
84
97
  /** Whether the claim opened a key of the run's own at its start: its routes then carry that key alone, its tools hold no
85
98
  * model key, and no saved key is read for it. */
86
99
  export declare const keyedAtClaim: (runKey: ClaimModelKey | undefined) => boolean;
100
+ /** Whether the server has a gateway (AGENT_MODEL_BASE_URL) and holds no key for it, in the runner's environment or saved:
101
+ * claimSpendOff's spend with no key to pay it. */
102
+ export declare function serverKeyless(deps: ClaimSecretsDeps): Promise<boolean>;
87
103
  /** Why the claim's model spend after the run's turn, or beside it on runs the runner starts (a shadow audit, a replay
88
- * check, the learning run's grade), is skipped: `what` the work, asked when that spend would start. A run that brought
104
+ * check), is skipped: `what` the work, asked when that spend would start. A run that brought
89
105
  * its own key, at its start or with a message since (everHeld): that key is erased with its turn's end and the server's
90
106
  * never pays for it (runKeyEndedFor). Else, a server that holds no gateway key (the runner's environment or
91
107
  * Settings → Model keys) has none to spend (noServerKeyWords). Undefined where it runs. */
@@ -13,6 +13,7 @@ import { DECISION_KEYS, withoutSecrets } from "../secrets.js";
13
13
  import { getSealedKey } from "../server-keys.js";
14
14
  import { PLAN_PROVIDER, planOf, planReaderOf, withPlan } from "../chatgpt-plan.js";
15
15
  import { handsParallel } from "../tool-plane.js";
16
+ import { held, held as runnerSeam } from "./held.js";
16
17
  import { noServerKeyWords, runKeyEndedFor, runModelOrigin, withRunModelKey, withRunModelKeyLater } from "../run-model-key.js";
17
18
  import { openRunLaunch } from "../store/seal.js";
18
19
  import { StoreLaunchMissing } from "../store/store.js";
@@ -103,6 +104,10 @@ export async function learnedDecisionKeys(deps, workflows, allowed) {
103
104
  export async function hostDecisionKeys(deps, providers) {
104
105
  if (!providers.length)
105
106
  return {};
107
+ // A run's own process holds no seal key: its runner reads them (held.ts).
108
+ const at = deps.sealKey ? undefined : held();
109
+ if (at)
110
+ return at.decisionKeys(providers);
106
111
  return decisionKeysFor(await workingEnv(deps), { providers, parallelWeb: false });
107
112
  }
108
113
  /** The model keys the host's models of `tiers` need (model.ts modelKeys: each one's provider's, or the gateway's), read as
@@ -112,6 +117,12 @@ export async function hostDecisionKeys(deps, providers) {
112
117
  export async function tierModelKeys(deps, tiers) {
113
118
  if (!tiers.length)
114
119
  return {};
120
+ // A run's own process holds no seal key: its runner reads them, the plan's reader with them (held.ts).
121
+ const at = deps.sealKey ? undefined : held();
122
+ if (at) {
123
+ const given = await at.tierModelKeys(tiers);
124
+ return given.plan ? withPlan({ ...given.keys }, given.plan) : { ...given.keys };
125
+ }
115
126
  const working = await workingEnv(deps);
116
127
  const out = {};
117
128
  for (const name of modelKeys(working, undefined, tiers))
@@ -157,10 +168,12 @@ export function withModelKeys(env, opened) {
157
168
  // The claim's ChatGPT sign-in (claimSecrets), else the runner's own.
158
169
  return withPlan(out, planOf(opened) ?? planOf(env));
159
170
  }
160
- /** Every model key the server holds, for a model route with no revision to scope it by (a learning run's grade): each
171
+ /** Every model key the server holds, for a model route with no revision to scope it by (an SDK run's compile turn): each
161
172
  * by its name from `deps.env` first, then the store's sealed value, as claimSecrets reads them. */
162
173
  export async function savedModelKeys(deps) {
163
- const out = {};
174
+ // A run's own process holds no seal key: what its runner hands a claim whose routes read them (held.ts savedModelKeys).
175
+ const at = deps.sealKey ? undefined : held();
176
+ const out = at ? { ...(await at.savedModelKeys()) } : {};
164
177
  for (const name of MODEL_KEY_NAMES) {
165
178
  const value = deps.env?.[name] || (deps.sealKey ? await getSealedKey(deps.store, deps.sealKey, name) : undefined);
166
179
  if (value !== undefined)
@@ -171,6 +184,21 @@ export async function savedModelKeys(deps) {
171
184
  /** How many times fresh() reads a run's launch before it gives up, and the first wait between reads (doubled each time). */
172
185
  const FRESH_TRIES = 3;
173
186
  const FRESH_WAIT_MS = 50;
187
+ /** Run `runId`'s own model key as its launch's sealed column holds it, opened under `deps.sealKey`: none for a launch that
188
+ * holds none (or no launch row: a test's, an import's). Throws, in words, where the launch does not open. */
189
+ export async function openRunModelKey(deps, runId) {
190
+ const sealed = await deps.store.runs.launch(runId).then((launch) => launch.sealed, (error) => {
191
+ if (error instanceof StoreLaunchMissing)
192
+ return null;
193
+ throw error;
194
+ });
195
+ if (sealed === null)
196
+ return undefined;
197
+ const opened = deps.sealKey ? openRunLaunch(deps.sealKey, runId, sealed) : undefined;
198
+ if (!opened)
199
+ throw new Error("This run's launch secrets do not open with this runner's seal key: its model key is not sent.");
200
+ return opened.model;
201
+ }
174
202
  /**
175
203
  * The run's own model key for claim `runId`, opened from its launch's sealed column under the runner's seal key (the
176
204
  * server sealed it there with mcp_auth, store/seal.ts). Undefined only where the server has no gateway and the run holds
@@ -181,20 +209,9 @@ const FRESH_WAIT_MS = 50;
181
209
  */
182
210
  export async function claimModelKey(deps, runId) {
183
211
  const origin = runModelOrigin(deps.env ?? {});
184
- const open = async () => {
185
- // A run with no launch row (one no start wrote: a test's, an import's) holds no key of its own.
186
- const sealed = await deps.store.runs.launch(runId).then((launch) => launch.sealed, (error) => {
187
- if (error instanceof StoreLaunchMissing)
188
- return null;
189
- throw error;
190
- });
191
- if (sealed === null)
192
- return undefined;
193
- const opened = deps.sealKey ? openRunLaunch(deps.sealKey, runId, sealed) : undefined;
194
- if (!opened)
195
- throw new Error("This run's launch secrets do not open with this runner's seal key: its model key is not sent.");
196
- return opened.model;
197
- };
212
+ // A run's own process holds no seal key: its runner opens the claim's own launch, whatever run id this one names (held.ts).
213
+ const at = deps.sealKey ? undefined : runnerSeam();
214
+ const open = () => (at ? at.runModelKey() : openRunModelKey(deps, runId));
198
215
  let held = await open();
199
216
  if (held && held.origin !== origin)
200
217
  throw new Error(`This run's model key was handed for the gateway at ${held.origin}, and AGENT_MODEL_BASE_URL names ${origin ?? "none"} here now: the key is never sent anywhere else.`);
@@ -245,13 +262,20 @@ export function holdRunKey(redact, runKey) {
245
262
  /** Whether the claim opened a key of the run's own at its start: its routes then carry that key alone, its tools hold no
246
263
  * model key, and no saved key is read for it. */
247
264
  export const keyedAtClaim = (runKey) => runKey?.key() !== undefined;
265
+ /** Whether the server has a gateway (AGENT_MODEL_BASE_URL) and holds no key for it, in the runner's environment or saved:
266
+ * claimSpendOff's spend with no key to pay it. */
267
+ export async function serverKeyless(deps) {
268
+ return runModelOrigin(deps.env ?? {}) !== undefined && !(await savedModelKeys(deps))[GATEWAY_KEY_ENV];
269
+ }
248
270
  /** Why the claim's model spend after the run's turn, or beside it on runs the runner starts (a shadow audit, a replay
249
- * check, the learning run's grade), is skipped: `what` the work, asked when that spend would start. A run that brought
271
+ * check), is skipped: `what` the work, asked when that spend would start. A run that brought
250
272
  * its own key, at its start or with a message since (everHeld): that key is erased with its turn's end and the server's
251
273
  * never pays for it (runKeyEndedFor). Else, a server that holds no gateway key (the runner's environment or
252
274
  * Settings → Model keys) has none to spend (noServerKeyWords). Undefined where it runs. */
253
275
  export async function claimSpendOff(deps, runKey) {
254
- const keyless = runModelOrigin(deps.env ?? {}) !== undefined && !(await savedModelKeys(deps))[GATEWAY_KEY_ENV];
276
+ // A run's own process holds no seal key, nor every saved key: its runner says whether the server holds a gateway key.
277
+ const at = deps.sealKey ? undefined : held();
278
+ const keyless = at ? await at.serverKeyless() : await serverKeyless(deps);
255
279
  return (what) => (runKey?.everHeld() ? runKeyEndedFor(what) : keyless ? noServerKeyWords(what) : undefined);
256
280
  }
257
281
  /** The env a claimed run's model routes read: the run's own key alone where the claim opened one (withRunModelKey); else
@@ -21,7 +21,7 @@ import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
21
21
  import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
22
22
  import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
23
23
  import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
24
- import { claimSettled, installDirOf, installForClaim, installingWords } from "../harness-install.js";
24
+ import { claimSettled, claudeCliIn, installDirOf, installForClaim, installingWords } from "../harness-install.js";
25
25
  import { HarnessUnavailable } from "../provider.js";
26
26
  import { effortGuidance } from "../effort-guidance.js";
27
27
  import { outputContract } from "../answer-json.js";
@@ -42,13 +42,13 @@ import { recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.j
42
42
  import { openRunWorkspace } from "../workspace/run-workspace.js";
43
43
  import { layOwnSkills } from "../workspace/revision-skills.js";
44
44
  import { runTools, withKindTools } from "../workspace/run-tools.js";
45
- import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
45
+ import { archilWhereHeld, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
46
46
  import { loadArchilSettings } from "../archil-settings.js";
47
47
  import { settingOfDefinition } from "../computer-setting.js";
48
48
  import { computerKeptWords, computerReadyWords, computerReplacedNote, computerStartingWords, imageWaitWords } from "../workspace/computer-deps.js";
49
49
  import { hadComputer } from "./computer-journal.js";
50
50
  import { hostLifecycle } from "./adapter-loop.js";
51
- import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
51
+ import { adapterRunGate, answersCut, buildToolHost, capModelOf as capModelOfRoute, claimLiveAt, hostToolCtxOf, learnedTierRoutes, learnedTiers, learnedWorkflowHostTool, learnsWorkflows, mcpReachOf, modelAskOf, PI_WIRES, webHostTools } from "./adapter-run-spec.js";
52
52
  import { openTierProxies } from "./adapters/pi.js";
53
53
  import { signInReads } from "../sign-ins-store.js";
54
54
  import { isWebHostTool } from "../tool-list.js";
@@ -56,7 +56,8 @@ import { hostToolOf } from "../host-tools.js";
56
56
  import { ASK_TOOL, askPerson } from "../tools.js";
57
57
  import { fakedPlane } from "../web-fake.js";
58
58
  import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
59
- import { mcpForClaim } from "./mcp-run.js";
59
+ import { mcpWhereHeld } from "./mcp-run.js";
60
+ import { held as runnerSeam, heldSignInReads } from "./held.js";
60
61
  import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
61
62
  import { decisionProvidersIn } from "../decisions.js";
62
63
  import { resolveHarness } from "./adapters/index.js";
@@ -64,13 +65,15 @@ import { entriesOf } from "./loop.js";
64
65
  import { bookedSpend, cliModelWorked, cliRunMetrics, endCostOf, runCostOf } from "./metrics.js";
65
66
  import { journalEntries } from "./journal-reader.js";
66
67
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
67
- import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
68
- import { pathMetrics, workflowFirstOf } from "./workflow-first.js";
69
- import { AUDIT_PARKED, settleAudits, withAudit } from "./audit.js";
70
- import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
68
+ import { replayCallsOver } from "./promotion.js";
69
+ import { learnedFirstWhereHeld } from "./learned-first.js";
70
+ import { pathMetrics } from "./workflow-first.js";
71
+ import { AUDIT_PARKED, withAudit } from "./audit.js";
72
+ import { runPathOverStore } from "../store-reads/learning.js";
71
73
  import { specBuilt } from "./spec-holds.js";
72
74
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
73
75
  import { planBeforeRun, PLAN_PROVIDER } from "../chatgpt-plan.js";
76
+ import { CLAUDE_LOGIN_PROVIDER, loginBeforeRun, loginCli, loginForRun, withClaudeLogin } from "../claude-login.js";
74
77
  import { heldSpecOf } from "./held-run.js";
75
78
  import { loopComputerOf } from "./computer-channel.js";
76
79
  import { githubAppAccess } from "./github-app.js";
@@ -121,7 +124,7 @@ export function capModelOf(id, wire, listed, unpriced, plan = false) {
121
124
  function chosenCapModel(entry, env, chosen, wire) {
122
125
  const priced = entry.priceModel(env, chosen.model);
123
126
  const listed = chosen.models.getModel(priced.provider, priced.modelId);
124
- return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER);
127
+ return capModelOf(priced.modelId, wire, listed, chosen.unpriced.has(priced.modelId) || listed === undefined, priced.provider === PLAN_PROVIDER || priced.provider === CLAUDE_LOGIN_PROVIDER);
125
128
  }
126
129
  /** The model a run of the CLI harness `entry` on `ref` (a revision's model; none, this host's default for it) is capped
127
130
  * at here, as its run's spec prices it (modelsOf, chosenCapModel), before any run: a save's cap warning (cap-short.ts)
@@ -209,6 +212,11 @@ async function rmEmptyParents(parents) {
209
212
  const code = error.code;
210
213
  if (code === "ENOTEMPTY" || code === "EEXIST")
211
214
  return;
215
+ // A folder this process may not remove ends the climb: a run's own process on a slot (run-child-host.ts) removes
216
+ // its harness folder, and the run's scratch folder and its agent's are its runner's, which sweeps them after the
217
+ // slot's reap.
218
+ if (code === "EACCES" || code === "EPERM")
219
+ return;
212
220
  // Already gone (a sweep cut off after it, or never made): the folder above it may still be left empty.
213
221
  if (code !== "ENOENT")
214
222
  throw error;
@@ -319,7 +327,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
319
327
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
320
328
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
321
329
  redact.hold(values); };
322
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
330
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
323
331
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
324
332
  holds.hold({ passed: mcp });
325
333
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -334,7 +342,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
334
342
  // fake) is spread into the mount, so no test reaches the real control plane. TODO(k2 lazy mint): the mint moves into
335
343
  // computerForClaim (a mounting computer only), with the ttl the run's lifetime bound (not this fixed figure). As pi does.
336
344
  // 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.
337
- : 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 } : {}) });
345
+ : 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 } : {}) });
338
346
  // Each resource is held the moment it exists (spec-holds.ts): a throw after it lets it go. The claim's Archil keys go
339
347
  // from memory last, once nothing more reads the disk.
340
348
  holds.hold({ archil, keys: archil });
@@ -347,7 +355,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
347
355
  // The pull request's checkout, when the revision asks for one, as the pi spec makes it (pr-checkout.ts).
348
356
  const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
349
357
  holds.hold({ checkout });
350
- await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
358
+ // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
359
+ if (!(deps.sealKey === undefined && runnerSeam()))
360
+ await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
351
361
  // The run's skills and its learning seed laid before its computer exists, as the pi spec lays them (adapter-run-spec.ts):
352
362
  // on Archil the computer's mount takes the disk's write delegation, and a lay over the disk's file API after it is
353
363
  // refused (409) while the mount holds it.
@@ -356,21 +366,12 @@ async function cliSpec(launch, run, deps, claim, holds) {
356
366
  // The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts), with the kind's
357
367
  // skill of a desktop or a phone (the revision's computer setting), in the harness's skill list beside the revision's.
358
368
  const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
359
- // A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
360
- // the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
369
+ // A learning run's seed read as the pi spec reads it (runner/learning-seed.ts): its learned workflows, the ones
370
+ // learned_workflow runs.
361
371
  const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
362
372
  const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
363
373
  const seedLaid = start && !seedFailed(start)
364
- ? await layLearningSeed({
365
- work: ws.workspace,
366
- seed: start.seed,
367
- folder: learningFolder,
368
- own: Object.keys(revisionRow.skills ?? {}),
369
- shown,
370
- log,
371
- ...(start.notesOnly ? { workflows: false } : {}),
372
- ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
373
- })
374
+ ? await layLearningSeed({ seed: start.seed, folder: learningFolder, shown, log, ...(start.noWorkflows ? { workflows: false } : {}) })
374
375
  : undefined;
375
376
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
376
377
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
@@ -419,9 +420,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
419
420
  // those it would refuse, and is handed the rest), the output schema it answers in (answer-json.ts outputContract, as the
420
421
  // pi spec gives it), then the effort guidance.
421
422
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
422
- const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
423
+ const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section) : (body.instructions ?? "");
423
424
  const check = await entry.skillCheck?.();
424
- const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills, ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
425
+ const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills], ws.workspace, check, { onDemand: readsFiles(granted) });
425
426
  const guidance = effortGuidance(launch.effort);
426
427
  // The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
427
428
  // environment main's server gives its runs: the server's data directory named (DATA_ENV), so the CLI's install is
@@ -443,9 +444,17 @@ async function cliSpec(launch, run, deps, claim, holds) {
443
444
  if (runKey)
444
445
  holdRunKey(redact, runKey);
445
446
  }
446
- const env = cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey);
447
+ // Claude Code's login on this machine, where the owner turned it on for claude-agent here (claude-login.ts): the run
448
+ // carries only where it is, and its CLI says it is signed in before the run starts. A run that brought its own key
449
+ // runs on that key, and a run in a sandbox place on the model keys.
450
+ const login = keyed ? undefined : await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, launch.place);
451
+ const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey), login);
447
452
  const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
448
453
  await planBeforeRun(env, chosen.model);
454
+ if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
455
+ const claude = await import("@parcha/agentrun-harness-claude");
456
+ await loginBeforeRun(login, loginCli(claudeCliIn(installDirOf(deps.data, name), claude.claudeAgentPlatform()), env), (cli, at) => claude.claudeLoginStatus(cli, at, env.PATH ? { path: env.PATH } : {}));
457
+ }
449
458
  // The CLI's own process (the Claude CLI, Codex, OpenCode) starts under the no_new_privs pi's commands start under
450
459
  // (adapters.ts' noNewPrivsPrefix): on Linux, setpriv --no-new-privs, so a setuid program or file capability it
451
460
  // or a command it runs reaches grants nothing; none on macOS. Where setpriv is not usable the run is refused, in pi's words.
@@ -453,7 +462,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
453
462
  // The run's clock: a template eval case's (EvalFakes.now), else the real one. Its environment line and the harness's own
454
463
  // turn date (claude-agent's dateLine) read it.
455
464
  const now = fakes?.now;
456
- const zone = await runZone(deps.store, launch.inputOrigin);
465
+ // A run's own process reads no trigger's row: its runner answers the zone (held.ts runZone).
466
+ const seam = deps.sealKey ? undefined : runnerSeam();
467
+ const zone = seam ? await seam.runZone() : await runZone(deps.store, launch.inputOrigin);
457
468
  const built = await entry.adapter(env, { zone, model: chosen.model, models: chosen.models, unpriced: chosen.unpriced, ...(confine ? { confine } : {}), ...(native.length ? { skills: native } : {}), ...(now ? { now: () => now } : {}) });
458
469
  // The harness's own session options, its private directory and its working directory (SessionIO's dir and cwd, which
459
470
  // every CLI adapter reads), set on its open here, so the loop lends the session nothing of its own. A turn that ends on
@@ -516,8 +527,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
516
527
  const tierRoute = tierRoutes.get(by);
517
528
  return tierRoute && tierRoute.model === id ? capModelOfRoute(tierRoute) : undefined;
518
529
  },
519
- // What its learning runs' grades and its audit's shadow took beside it, read by every gate with its own sessions
520
- // (none: it queues none).
530
+ // What its audit's shadow took beside it, read by every gate with its own sessions (none: it starts none).
521
531
  ...(besideOf ? { beside: besideOf } : {}),
522
532
  // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
523
533
  freeRequests: freeModelRequestsOf(deps.env),
@@ -561,32 +571,26 @@ async function cliSpec(launch, run, deps, claim, holds) {
561
571
  // The keys the claim hands the run (its web tools and its learned workflow's call nodes run on them): never learned
562
572
  // (learningEndOfRun).
563
573
  let handedKeys = [];
564
- // A replay run lays only the workflow it replays (runner/promotion.ts replayLaid).
565
- const laidFlows = replayLaid(launch, seedLaid?.workflows ?? []);
566
574
  // The learned workflow the run starts on, before its agent's first turn, when one fits its input (workflow-first.ts),
567
575
  // chosen before the learned_workflow tool is bound, so the tool runs the text that serves. Only a promoted digest
568
576
  // serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
569
577
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
570
578
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the agent takes the run.
571
579
  // The audits that finished since are written first (runner/audit.ts settleAudits): a hold they make decides this claim.
572
- // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit, a replay check and
573
- // the learning run's grade are skipped, in words, where the run brought its own key or the server holds none.
580
+ // Model spend beside the run that its caller's key does not pay for (claimSpendOff): a shadow audit and a replay check
581
+ // are skipped, in words, where the run brought its own key or the server holds none.
574
582
  const spendOff = await claimSpendOff({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, runKey);
575
583
  const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
576
- if (launch.learning && !launch.replay && !launch.audit)
577
- await settleAudits(audits);
578
- const promotion = claimPromotion({
579
- store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff,
580
- });
581
- const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
582
- // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
583
- await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
584
+ // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
585
+ // them (held.ts learnedFirst), over the workflows it reads at the claim's seed itself.
586
+ 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 ?? []);
587
+ const firstChoice = learned.choice;
584
588
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
585
- // answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
586
- const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
589
+ // answered from that recording (runner/promotion.ts replayCallsOver, learn/replay-calls.ts).
590
+ const replay = learned.recorded ? await replayCallsOver(deps.store, claim.runId, new Map(learned.recorded)) : undefined;
587
591
  const { serve: workflowFirst, revise: workflowRevise } = firstChoice;
588
592
  // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
589
- const workflows = await toolFlowsFor(promotion, launch, laidFlows, firstChoice);
593
+ const workflows = learned.workflows;
590
594
  const learns = learnsWorkflows(revision.kind, workflows);
591
595
  if (webNames.length || learns) {
592
596
  // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
@@ -607,7 +611,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
607
611
  toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
608
612
  if (webNames.length) {
609
613
  life = hostLifecycle();
610
- const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach });
614
+ const liveAt = await claimLiveAt(deps, claim.runId);
615
+ const host = buildToolHost({ root, workspace: ws.workspace, claim, env: toolEnv, run, store: deps.store, sealKey: deps.sealKey, life, redact: held, launch, toolSettings: body.toolSettings, ...(fakes ? { fakes } : {}), ...reach, ...(liveAt ? { liveAt } : {}) });
611
616
  gate.askedOn(host);
612
617
  webTools = await webHostTools(host, granted, ctx);
613
618
  }
@@ -652,21 +657,20 @@ async function cliSpec(launch, run, deps, claim, holds) {
652
657
  };
653
658
  // A typed input's other fields follow its content as one json block (inputMessage).
654
659
  const input = await firstMessage(inputMessage(launch.input), ws.workspace);
655
- // The run's end-of-run step, when it learns, the same as the pi spec's: the reflect-and-propose turn over the run's
656
- // store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this claim's
657
- // Archil disk — so the proposal is checked against the seed in the run's own Workspace, never this machine's local path.
660
+ // The run's end-of-run step, when it learns, the same as the pi spec's: the compile turn and the owner's correction over
661
+ // the run's store, its learning folder where the run's place keeps it — Mode 1 under the data directory, Mode 2 on this
662
+ // claim's Archil disk — so the draft is checked against the seed in the run's own Workspace, never this machine's local path.
658
663
  // 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.
659
664
  // A run the promoted workflow answered (path `workflow`) starts its shadow audit after the step, drawn at 1 in k (runner/audit.ts
660
665
  // withAudit): at its end, so the shadow's cap is what the run's own left.
661
666
  const endOfRun = launch.replay || launch.audit ? undefined : withAudit(learningEndOfRun(launch, {
662
667
  store: deps.store,
663
668
  data: deps.data,
664
- spendOff,
665
669
  ...(deps.env ? { env: deps.env } : {}),
666
670
  // What the run must never learn beside the runner's secrets: the keys its claim handed it, every secret the server
667
671
  // keeps sealed (storeSecrets: the run's redactor holds the same list), and its sign-in's pointers, read back from the
668
672
  // store's sign-ins under the seal key (learning-run.ts refused, on the runner).
669
- signIns: signInReads(deps.store, deps.sealKey),
673
+ signIns: deps.sealKey ? signInReads(deps.store, deps.sealKey) : heldSignInReads(),
670
674
  handed: handedKeys,
671
675
  stored: () => storeSecrets(deps.store, deps.sealKey, deps.data),
672
676
  log,
@@ -57,6 +57,12 @@ export type Seen = {
57
57
  epoch: number;
58
58
  };
59
59
  };
60
+ /** What the process wrote after it said it stops at the point, in its file's order (each line is appended synchronously),
61
+ * or everything when it never said so. One millisecond of the clock can hold the loop's last write before the stop and
62
+ * the case's going on both, so the order, not the time, says which side of the stop a write is on. */
63
+ export declare function afterStop<T extends {
64
+ type?: string;
65
+ }>(events: readonly T[]): readonly T[];
60
66
  /**
61
67
  * The claim's fence, as the stalled process's own events show it: once it went on (`continuedAt`, its lease run out and no
62
68
  * one holding the run yet), its old loop's writes under the claim it was held under are each refused by the fence, by name (ClaimLost
@@ -384,6 +384,13 @@ async function world(subject, t, timing = STEADY) {
384
384
  };
385
385
  return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), liveRows, servedRows };
386
386
  }
387
+ /** What the process wrote after it said it stops at the point, in its file's order (each line is appended synchronously),
388
+ * or everything when it never said so. One millisecond of the clock can hold the loop's last write before the stop and
389
+ * the case's going on both, so the order, not the time, says which side of the stop a write is on. */
390
+ export function afterStop(events) {
391
+ const stop = events.findIndex((event) => event.type === "stopping");
392
+ return stop < 0 ? events : events.slice(stop + 1);
393
+ }
387
394
  /**
388
395
  * The claim's fence, as the stalled process's own events show it: once it went on (`continuedAt`, its lease run out and no
389
396
  * one holding the run yet), its old loop's writes under the claim it was held under are each refused by the fence, by name (ClaimLost
@@ -396,8 +403,10 @@ export function fenceHeld(events, continuedAt) {
396
403
  // process's first claim before the point and take the run again, so the held loop's epoch need not be its first.
397
404
  const heldFrom = events.find((event) => event.type === "stopping")?.at ?? continuedAt;
398
405
  const first = events.filter((event) => event.type === "claimed" && (event.at ?? 0) <= heldFrom).at(-1)?.claim?.epoch;
399
- const old = events.filter((event) => (event.at ?? 0) >= continuedAt && event.epoch === first && (event.type === "commit-landed" || event.type === "commit-refused"));
406
+ const after = afterStop(events);
407
+ const old = after.filter((event) => (event.at ?? 0) >= continuedAt && event.epoch === first && (event.type === "commit-landed" || event.type === "commit-refused"));
400
408
  const lost = events.find((event) => event.type === "claim-lost" && event.epoch === first);
409
+ const lostOnceOn = after.find((event) => event.type === "claim-lost" && event.epoch === first && (event.at ?? 0) >= continuedAt);
401
410
  for (const landed of old.filter((event) => event.type === "commit-landed")) {
402
411
  const when = lost?.at !== undefined ? `${landed.at - lost.at} ms after its claim was lost` : `${landed.at - continuedAt} ms after it went on, its lease run out`;
403
412
  assert.fail(`an epoch-${first} commit landed ${when}: ${history}`);
@@ -406,7 +415,7 @@ export function fenceHeld(events, continuedAt) {
406
415
  // before any write (a loaded box), or the loop's write is tried and refused. The store's refusal of a write past the
407
416
  // lease is held on its own, deterministically (store-claim-lease).
408
417
  if (old.length === 0) {
409
- assert.ok(lost !== undefined && (lost.at ?? 0) >= continuedAt, `the old loop neither tried a write nor was stopped by its claim lost once it went on: ${history}`);
418
+ assert.ok(lostOnceOn !== undefined, `the old loop neither tried a write nor was stopped by its claim lost once it went on: ${history}`);
410
419
  return;
411
420
  }
412
421
  assert.ok(old.every((event) => event.name === "ClaimLost" || event.name === "Fenced"), `each was refused by the claim's fence, by name: ${history}`);
@@ -552,8 +561,9 @@ async function processCrashThenResume(subject, t, tool, point, { stall = false }
552
561
  child.kill("SIGCONT");
553
562
  // The fence first, before anything waits on the process's death: its old loop's first write once it went on (landed or
554
563
  // refused), or the process's end, bounded. The old loop's epoch is the claim it was held under.
564
+ // A write after the stop (afterStop): one that landed before it, in the millisecond the case went on, is not one.
555
565
  const outcome = (event) => (event.at ?? 0) >= continuedAt && (event.type === "commit-landed" || event.type === "commit-refused");
556
- await until(() => child.exitCode !== null || child.signalCode !== null || childEvents(eventsFile).some((event) => outcome(event)), "the old loop writes once it goes on, or the process ends", 15_000);
566
+ await until(() => child.exitCode !== null || child.signalCode !== null || afterStop(childEvents(eventsFile)).some(outcome), "the old loop writes once it goes on, or the process ends", 15_000);
557
567
  fenceHeld(childEvents(eventsFile), continuedAt);
558
568
  }
559
569
  // The process's unanswered first claim (its events file) is run out while the case waits for its death.
@@ -701,8 +711,9 @@ const CASES = [
701
711
  await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet });
702
712
  await w.began(slowStarted, "the slow tool to start");
703
713
  const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "check the totals" } });
704
- // One command poll and then some: the steer reaches the loop while the tool runs.
705
- await sleep(TIMING.commandPollMs * 4);
714
+ // The tool goes on once the loop has answered the steer: the turn in flight has it, never a timer (as in
715
+ // message-mid-turn-kept). A steer that reaches a CLI only after the tool's end is the next turn by its facts.
716
+ await until(() => w.answered(steer.id), "the steer placed by the loop mid-turn");
706
717
  letSlowGo();
707
718
  await w.ended("ended");
708
719
  const { calls, messages } = await w.read();
@@ -9,8 +9,8 @@ export interface DispatchDeps {
9
9
  }>;
10
10
  /** The loop factory for a run launched with `harness`, built from its `launch` record and its run id (so the resolver may
11
11
  * read the run's revision — a workflow revision runs on the workflow loop whatever its harness name), or undefined when
12
- * this runner does not run it (the run fails in words). pi is the adapter loop with adapterRunSpecFromLaunch; a built-in
13
- * learning run names "learning"; the CLI harnesses name their own. May be async (the revision read). */
12
+ * this runner does not run it (the run fails in words). pi is the adapter loop with adapterRunSpecFromLaunch; the CLI
13
+ * harnesses name their own. May be async (the revision read). */
14
14
  resolve(harness: string, launch: RunLaunch, runId: string): LoopFactory | undefined | Promise<LoopFactory | undefined>;
15
15
  }
16
16
  /** A launch naming a harness this runner does not run. */
@@ -2,16 +2,16 @@
2
2
  export declare const REFLECT_PREFIX = "learn-reflect-";
3
3
  /** The label a reader puts on the end-of-run turn's rows and messages: the server's (learning.ts LEARNING_LABEL). */
4
4
  export declare const REFLECT_LABEL = "learning";
5
- /** The end-of-run turn's request id, one per round of a run, and one per `step` of a round (a turn of its own after the
6
- * look-back: the compile turn's attempts, `compile-<n>`): pi answers a repeat of it from its submission, so a turn
7
- * asked again on a later claim is never asked of the model twice. A run's first end is round 1; an end after a
8
- * follow-up opened the run again is the next round, whose turn is asked of the model anew under an id of its own. The
9
- * server's own prefix, so the run's readers tell the turn's rows apart by it (reflectRanges). */
5
+ /** The end-of-run turn's request id, one per round of a run, and one per `step` of a round (the compile turn's attempts,
6
+ * `compile-<n>`): pi answers a repeat of it from its submission, so a turn asked again on a later claim is never asked of
7
+ * the model twice. A run's first end is round 1; an end after a follow-up opened the run again is the next round, whose
8
+ * turn is asked of the model anew under an id of its own. The server's own prefix, so the run's readers tell the turn's
9
+ * rows apart by it (reflectRanges). */
10
10
  export declare const reflectRequestId: (runId: string, again?: boolean, round?: number, step?: string) => string;
11
11
  /** The suffix of the end-of-run turn's re-ask's request id (EndOfRunTurn ask's `again`): one per round too, so a repeat
12
12
  * is answered from its submission, never asked of the model twice. */
13
13
  export declare const REFLECT_AGAIN = ":again";
14
- /** The round shared by its look-back, re-ask and compile attempts, for range and durable accounting reads. */
14
+ /** The round shared by its re-ask and compile attempts, for range and durable accounting reads. */
15
15
  export declare const reflectRoundId: (requestId: string) => string;
16
16
  /** One round of a run's end-of-run turn in its journal: `from`, the entry its input placed (the turn's first); `until`, the
17
17
  * run's end entry that closed it, once written. Every entry between is the turn's. */
@@ -36,14 +36,6 @@ export declare function reflectRanges(submissions: readonly {
36
36
  }[]): ReflectRange[];
37
37
  /** Whether entry `entry` (a number) is one of `ranges`' end-of-run turns. */
38
38
  export declare const inReflect: (ranges: readonly ReflectRange[], entry: number) => boolean;
39
- /** The refusal of the end-of-run turn's write or edit under work/.learning/: the tool gate's one text (NOTE_ONLY_TEXT), so
40
- * the adapter loop's refusal and the gate's are the same words. */
41
- export { NOTE_ONLY_TEXT as REFLECT_NOTE_ONLY } from "../tool-gate.js";
42
- /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then lexically),
43
- * names work/.learning/ or a path under it: by the run's `work` (when the loop knows it), or the box's. */
44
- export declare function underLearning(work: string | undefined, args: unknown): boolean;
45
- /** The tools whose write the end-of-run turn is refused under work/.learning/. */
46
- export declare const WRITES: Set<string>;
47
39
  /** The text an answer entry gave (pi's assistant entry): the text parts of the messages it adds to the model's context,
48
40
  * joined. */
49
41
  export declare function answerText(entry: {