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

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 (350) hide show
  1. package/CHANGELOG.md +148 -5
  2. package/README.md +385 -305
  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 +62 -19
  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-C2MYaUBa.css +1 -0
  39. package/dist/console/assets/index-CZZeCReB.js +701 -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/import.d.ts +10 -0
  64. package/dist/import.js +28 -8
  65. package/dist/key-check.js +3 -0
  66. package/dist/learn/audit.d.ts +6 -6
  67. package/dist/learn/audit.js +3 -7
  68. package/dist/learn/check.d.ts +23 -89
  69. package/dist/learn/check.js +57 -335
  70. package/dist/learn/commit.d.ts +63 -90
  71. package/dist/learn/commit.js +124 -316
  72. package/dist/learn/compile.d.ts +53 -50
  73. package/dist/learn/compile.js +89 -104
  74. package/dist/learn/corrections.d.ts +13 -0
  75. package/dist/learn/corrections.js +23 -0
  76. package/dist/learn/delete.d.ts +5 -5
  77. package/dist/learn/delete.js +8 -10
  78. package/dist/learn/folder.d.ts +35 -47
  79. package/dist/learn/folder.js +118 -134
  80. package/dist/learn/index.d.ts +3 -5
  81. package/dist/learn/index.js +6 -9
  82. package/dist/learn/learning.sh +45 -15
  83. package/dist/learn/promote.d.ts +23 -5
  84. package/dist/learn/promote.js +40 -2
  85. package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
  86. package/dist/learn/{skills.js → workflow-draft.js} +48 -58
  87. package/dist/learn/workflow-nodes.js +1 -1
  88. package/dist/learned-workflow.js +2 -2
  89. package/dist/learning-cost.d.ts +38 -24
  90. package/dist/learning-cost.js +41 -24
  91. package/dist/learning-routes.d.ts +91 -170
  92. package/dist/learning-routes.js +183 -421
  93. package/dist/learning-run.d.ts +19 -40
  94. package/dist/learning-run.js +23 -93
  95. package/dist/learning-setting.d.ts +21 -10
  96. package/dist/learning-setting.js +47 -11
  97. package/dist/learning-words.d.ts +28 -74
  98. package/dist/learning-words.js +64 -162
  99. package/dist/learning.d.ts +61 -392
  100. package/dist/learning.js +101 -651
  101. package/dist/live-reach.d.ts +25 -2
  102. package/dist/live-reach.js +46 -4
  103. package/dist/llms.txt +1 -1
  104. package/dist/local-models.d.ts +3 -11
  105. package/dist/local-models.js +5 -6
  106. package/dist/mcp-servers-store.d.ts +4 -4
  107. package/dist/model-form.js +6 -5
  108. package/dist/model.d.ts +4 -0
  109. package/dist/model.js +26 -9
  110. package/dist/native/binding.js +1 -1
  111. package/dist/native/connection.js +1 -1
  112. package/dist/native/discovery.js +1 -1
  113. package/dist/native/instructions.d.ts +3 -0
  114. package/dist/native/instructions.js +5 -3
  115. package/dist/native/remote-worker-bridge.js +9 -43
  116. package/dist/native/remote.d.ts +8 -15
  117. package/dist/native/remote.js +3 -3
  118. package/dist/native/schema.js +1 -1
  119. package/dist/native/types.d.ts +2 -2
  120. package/dist/openapi.js +273 -319
  121. package/dist/paid-calls.d.ts +8 -0
  122. package/dist/paid-calls.js +20 -0
  123. package/dist/particle-provider.d.ts +11 -0
  124. package/dist/particle-provider.js +135 -0
  125. package/dist/port-models.d.ts +12 -4
  126. package/dist/port-models.js +28 -11
  127. package/dist/print.d.ts +27 -0
  128. package/dist/print.js +21 -0
  129. package/dist/provider.d.ts +7 -0
  130. package/dist/provider.js +15 -1
  131. package/dist/reflect-range.js +2 -3
  132. package/dist/run-launch.d.ts +14 -28
  133. package/dist/run-launch.js +9 -12
  134. package/dist/run-learning-served.d.ts +15 -89
  135. package/dist/run-listing.d.ts +34 -0
  136. package/dist/run-listing.js +128 -0
  137. package/dist/run-model-key.js +1 -1
  138. package/dist/run-timeline-served.js +5 -3
  139. package/dist/run-trace.d.ts +97 -0
  140. package/dist/run-trace.js +253 -0
  141. package/dist/run-view.d.ts +15 -0
  142. package/dist/run-view.js +9 -0
  143. package/dist/runnable.js +2 -1
  144. package/dist/runner/adapter-loop.d.ts +8 -6
  145. package/dist/runner/adapter-loop.js +16 -12
  146. package/dist/runner/adapter-run-spec.d.ts +16 -4
  147. package/dist/runner/adapter-run-spec.js +64 -58
  148. package/dist/runner/adapters/index.js +22 -0
  149. package/dist/runner/adapters/pi.d.ts +4 -12
  150. package/dist/runner/adapters/pi.js +2 -2
  151. package/dist/runner/audit.d.ts +1 -1
  152. package/dist/runner/audit.js +30 -13
  153. package/dist/runner/beside.d.ts +6 -2
  154. package/dist/runner/beside.js +38 -9
  155. package/dist/runner/claim-secrets.d.ts +18 -2
  156. package/dist/runner/claim-secrets.js +42 -18
  157. package/dist/runner/cli-run-spec.js +55 -51
  158. package/dist/runner/conformance/harness.d.ts +6 -0
  159. package/dist/runner/conformance/harness.js +35 -13
  160. package/dist/runner/conformance/subject.d.ts +6 -0
  161. package/dist/runner/dispatch.d.ts +2 -2
  162. package/dist/runner/end-of-run.d.ts +6 -14
  163. package/dist/runner/end-of-run.js +8 -33
  164. package/dist/runner/feedback-round.d.ts +2 -2
  165. package/dist/runner/feedback-round.js +7 -7
  166. package/dist/runner/github-app.js +3 -1
  167. package/dist/runner/harness-loops.d.ts +0 -8
  168. package/dist/runner/harness-loops.js +11 -59
  169. package/dist/runner/held.d.ts +170 -0
  170. package/dist/runner/held.js +57 -0
  171. package/dist/runner/journal-kinds.d.ts +2 -3
  172. package/dist/runner/journal-kinds.js +2 -3
  173. package/dist/runner/learned-first.d.ts +40 -0
  174. package/dist/runner/learned-first.js +32 -0
  175. package/dist/runner/learning-end.d.ts +77 -69
  176. package/dist/runner/learning-end.js +250 -303
  177. package/dist/runner/learning-seed.d.ts +15 -33
  178. package/dist/runner/learning-seed.js +24 -45
  179. package/dist/runner/loop-contract.d.ts +2 -3
  180. package/dist/runner/main.d.ts +17 -9
  181. package/dist/runner/main.js +82 -20
  182. package/dist/runner/mcp-run.d.ts +11 -0
  183. package/dist/runner/mcp-run.js +67 -0
  184. package/dist/runner/memory-claim.d.ts +10 -5
  185. package/dist/runner/memory-claim.js +12 -6
  186. package/dist/runner/model-route.d.ts +7 -4
  187. package/dist/runner/model-route.js +22 -10
  188. package/dist/runner/native-loop.d.ts +0 -7
  189. package/dist/runner/native-loop.js +9 -101
  190. package/dist/runner/promotion.d.ts +12 -8
  191. package/dist/runner/promotion.js +37 -28
  192. package/dist/runner/reflect-hook.d.ts +64 -95
  193. package/dist/runner/reflect-hook.js +112 -225
  194. package/dist/runner/run-channel.d.ts +43 -0
  195. package/dist/runner/run-channel.js +467 -0
  196. package/dist/runner/run-child-host.d.ts +169 -0
  197. package/dist/runner/run-child-host.js +1230 -0
  198. package/dist/runner/run-child.d.ts +1 -0
  199. package/dist/runner/run-child.js +254 -0
  200. package/dist/runner/run-errors.d.ts +2 -0
  201. package/dist/runner/run-errors.js +20 -0
  202. package/dist/runner/runner.js +1 -5
  203. package/dist/runner/sdk-ask.d.ts +78 -0
  204. package/dist/runner/sdk-ask.js +158 -0
  205. package/dist/runner/sdk-loop.d.ts +2 -4
  206. package/dist/runner/sdk-loop.js +29 -49
  207. package/dist/runner/store-secrets.d.ts +5 -3
  208. package/dist/runner/store-secrets.js +5 -1
  209. package/dist/runner/workflow-first.d.ts +5 -0
  210. package/dist/runner/workflow-first.js +4 -0
  211. package/dist/runner/workflow-spec.js +7 -2
  212. package/dist/runs-over-store.d.ts +16 -28
  213. package/dist/runs-over-store.js +31 -38
  214. package/dist/sdk/runs.d.ts +6 -11
  215. package/dist/sdk/runs.js +20 -41
  216. package/dist/sdk/schema.js +3 -4
  217. package/dist/seal-key.d.ts +5 -0
  218. package/dist/seal-key.js +7 -0
  219. package/dist/secrets.d.ts +3 -0
  220. package/dist/secrets.js +16 -3
  221. package/dist/server.d.ts +55 -33
  222. package/dist/server.js +689 -322
  223. package/dist/sign-ins-store.d.ts +8 -0
  224. package/dist/sign-ins-store.js +36 -1
  225. package/dist/skills.js +1 -1
  226. package/dist/store/index.d.ts +2 -2
  227. package/dist/store/index.js +1 -1
  228. package/dist/store/journal/storage.js +3 -0
  229. package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
  230. package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
  231. package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
  232. package/dist/store/schema.d.ts +53 -4
  233. package/dist/store/schema.js +137 -6
  234. package/dist/store/sqlite/connection.d.ts +2 -0
  235. package/dist/store/sqlite/connection.js +3 -1
  236. package/dist/store/sqlite/run-patch.d.ts +0 -17
  237. package/dist/store/sqlite/run-patch.js +4 -33
  238. package/dist/store/sqlite/store.js +246 -63
  239. package/dist/store/sqlite/worker.js +25 -0
  240. package/dist/store/store.d.ts +193 -36
  241. package/dist/store/store.js +25 -3
  242. package/dist/store-reads/learning.d.ts +102 -204
  243. package/dist/store-reads/learning.js +159 -321
  244. package/dist/store-reads/loop.d.ts +0 -1
  245. package/dist/store-reads/loop.js +1 -1
  246. package/dist/store-view.d.ts +29 -1
  247. package/dist/store-view.js +97 -31
  248. package/dist/template-eval.d.ts +3 -6
  249. package/dist/template-eval.js +22 -36
  250. package/dist/templates.d.ts +8 -4
  251. package/dist/templates.js +44 -6
  252. package/dist/timeline/index.d.ts +1 -1
  253. package/dist/timeline/index.js +1 -1
  254. package/dist/timeline/timeline.d.ts +5 -1
  255. package/dist/timeline/timeline.js +16 -0
  256. package/dist/tool-gate.d.ts +0 -7
  257. package/dist/tool-gate.js +1 -15
  258. package/dist/tool-keys-store.d.ts +1 -1
  259. package/dist/tool-keys.d.ts +6 -4
  260. package/dist/tool-keys.js +12 -6
  261. package/dist/tools.d.ts +2 -2
  262. package/dist/tools.js +11 -4
  263. package/dist/triggers.d.ts +65 -6
  264. package/dist/triggers.js +125 -19
  265. package/dist/validate.js +1 -1
  266. package/dist/webhooks.d.ts +7 -2
  267. package/dist/webhooks.js +12 -5
  268. package/dist/workspace/agent-computer.d.ts +2 -0
  269. package/dist/workspace/agent-computer.js +2 -0
  270. package/dist/workspace/archil-claim.d.ts +7 -0
  271. package/dist/workspace/archil-claim.js +29 -0
  272. package/dist/workspace/archil.d.ts +9 -1
  273. package/dist/workspace/archil.js +165 -3
  274. package/dist/workspace/attach.d.ts +3 -1
  275. package/dist/workspace/attach.js +2 -0
  276. package/dist/workspace/attached-computers.d.ts +16 -5
  277. package/dist/workspace/attached-computers.js +25 -9
  278. package/dist/workspace/computer-deps.js +1 -1
  279. package/dist/workspace/computer-for-claim.d.ts +7 -3
  280. package/dist/workspace/computer-for-claim.js +119 -22
  281. package/dist/workspace/computer-hold.js +2 -1
  282. package/dist/workspace/computer-kept.d.ts +11 -1
  283. package/dist/workspace/computer-kept.js +24 -3
  284. package/dist/workspace/resolve-computer.d.ts +33 -19
  285. package/dist/workspace/resolve-computer.js +172 -64
  286. package/dist/workspace/revision-skills.d.ts +1 -2
  287. package/dist/workspace/revision-skills.js +3 -4
  288. package/dist/workspace/run-workspace.d.ts +1 -1
  289. package/dist/workspace/run-workspace.js +5 -0
  290. package/dist/workspace/synced-folder.d.ts +85 -0
  291. package/dist/workspace/synced-folder.js +230 -0
  292. package/dist/workspace/workspace.d.ts +4 -0
  293. package/launcher/agentrun-serve +1 -1
  294. package/package.json +10 -10
  295. package/templates/README.md +8 -8
  296. package/templates/inbound-lead/agent.md +5 -4
  297. package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
  298. package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
  299. package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
  300. package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
  301. package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
  302. package/templates/inbound-lead/lead.schema.json +6 -5
  303. package/templates/inbound-lead/rules/RUBRIC.md +4 -4
  304. package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
  305. package/templates/kyb/agent.md +2 -1
  306. package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
  307. package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
  308. package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
  309. package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
  310. package/templates/release-notes/evals/learned-style/case.yaml +4 -4
  311. package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
  312. package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
  313. package/templates/release-notes/evals/learned-style/prompt.md +1 -1
  314. package/dist/console/assets/index-BUktRvS-.css +0 -1
  315. package/dist/console/assets/index-nB9kTfIN.js +0 -711
  316. package/dist/learn/grade.d.ts +0 -138
  317. package/dist/learn/grade.js +0 -682
  318. package/dist/learn/notes.d.ts +0 -81
  319. package/dist/learn/notes.js +0 -178
  320. package/dist/learn/reflect.d.ts +0 -77
  321. package/dist/learn/reflect.js +0 -228
  322. package/dist/learn/relevance.d.ts +0 -24
  323. package/dist/learn/relevance.js +0 -91
  324. package/dist/learn/seed-check.d.ts +0 -74
  325. package/dist/learn/seed-check.js +0 -103
  326. package/dist/learning-batch.d.ts +0 -291
  327. package/dist/learning-batch.js +0 -600
  328. package/dist/learning-evals.d.ts +0 -35
  329. package/dist/learning-evals.js +0 -99
  330. package/dist/native/context.d.ts +0 -6
  331. package/dist/native/context.js +0 -22
  332. package/dist/propose.d.ts +0 -52
  333. package/dist/propose.js +0 -224
  334. package/dist/runner/learning-ask.d.ts +0 -47
  335. package/dist/runner/learning-ask.js +0 -128
  336. package/dist/runner/learning-dispatch.d.ts +0 -45
  337. package/dist/runner/learning-dispatch.js +0 -99
  338. package/dist/runner/learning-factory.d.ts +0 -16
  339. package/dist/runner/learning-factory.js +0 -50
  340. package/dist/runner/learning-loop.d.ts +0 -273
  341. package/dist/runner/learning-loop.js +0 -521
  342. package/dist/usage.d.ts +0 -11
  343. package/dist/usage.js +0 -11
  344. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
  345. package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
  346. package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
  347. package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
  348. package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
  349. package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
  350. package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
@@ -209,6 +209,10 @@ async function world(subject, t, timing = STEADY) {
209
209
  const handed = new Set();
210
210
  /** The command rows a loop's command() has answered: a steer it took is with the session by then (a CLI's has it). */
211
211
  const answered = new Set();
212
+ /** What each command row's command() said, in order (taken, later or refused with its reason, or what it threw): for a
213
+ * case's failure message to name the branch a command took, never asserted on. */
214
+ const outcomes = new Map();
215
+ const outcomeSaid = (id, said) => outcomes.set(id, [...(outcomes.get(id) ?? []), said]);
212
216
  /** Each runner's claims in flight (store.runs.claimMany), by its name: what claimsSettled waits for. */
213
217
  const claiming = new Map();
214
218
  /** `store` as runner `name` is handed it: the same store, its claims in flight counted (claiming). */
@@ -282,7 +286,10 @@ async function world(subject, t, timing = STEADY) {
282
286
  command: (command) => {
283
287
  handed.add(command.id);
284
288
  const outcome = loop.command(command);
285
- void Promise.resolve(outcome).then(() => answered.add(command.id), () => undefined);
289
+ void Promise.resolve(outcome).then((said) => {
290
+ outcomeSaid(command.id, said === null || typeof said !== "object" ? String(said) : "taken" in said ? "taken" : "later" in said ? `later: ${said.later}` : `refused: ${said.refused}`);
291
+ answered.add(command.id);
292
+ }, (error) => outcomeSaid(command.id, `threw ${error?.name ?? String(error)}`));
286
293
  return outcome;
287
294
  },
288
295
  };
@@ -382,7 +389,14 @@ async function world(subject, t, timing = STEADY) {
382
389
  assert.ok(ask, "the run wrote its ask");
383
390
  return String(ask.data.callId);
384
391
  };
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 };
392
+ 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), outcomeOf: (id) => (outcomes.get(id) ?? ["not answered"]).join(", then "), liveRows, servedRows };
393
+ }
394
+ /** What the process wrote after it said it stops at the point, in its file's order (each line is appended synchronously),
395
+ * or everything when it never said so. One millisecond of the clock can hold the loop's last write before the stop and
396
+ * the case's going on both, so the order, not the time, says which side of the stop a write is on. */
397
+ export function afterStop(events) {
398
+ const stop = events.findIndex((event) => event.type === "stopping");
399
+ return stop < 0 ? events : events.slice(stop + 1);
386
400
  }
387
401
  /**
388
402
  * The claim's fence, as the stalled process's own events show it: once it went on (`continuedAt`, its lease run out and no
@@ -396,8 +410,10 @@ export function fenceHeld(events, continuedAt) {
396
410
  // process's first claim before the point and take the run again, so the held loop's epoch need not be its first.
397
411
  const heldFrom = events.find((event) => event.type === "stopping")?.at ?? continuedAt;
398
412
  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"));
413
+ const after = afterStop(events);
414
+ const old = after.filter((event) => (event.at ?? 0) >= continuedAt && event.epoch === first && (event.type === "commit-landed" || event.type === "commit-refused"));
400
415
  const lost = events.find((event) => event.type === "claim-lost" && event.epoch === first);
416
+ const lostOnceOn = after.find((event) => event.type === "claim-lost" && event.epoch === first && (event.at ?? 0) >= continuedAt);
401
417
  for (const landed of old.filter((event) => event.type === "commit-landed")) {
402
418
  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
419
  assert.fail(`an epoch-${first} commit landed ${when}: ${history}`);
@@ -406,7 +422,7 @@ export function fenceHeld(events, continuedAt) {
406
422
  // 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
423
  // lease is held on its own, deterministically (store-claim-lease).
408
424
  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}`);
425
+ assert.ok(lostOnceOn !== undefined, `the old loop neither tried a write nor was stopped by its claim lost once it went on: ${history}`);
410
426
  return;
411
427
  }
412
428
  assert.ok(old.every((event) => event.name === "ClaimLost" || event.name === "Fenced"), `each was refused by the claim's fence, by name: ${history}`);
@@ -552,8 +568,9 @@ async function processCrashThenResume(subject, t, tool, point, { stall = false }
552
568
  child.kill("SIGCONT");
553
569
  // The fence first, before anything waits on the process's death: its old loop's first write once it went on (landed or
554
570
  // refused), or the process's end, bounded. The old loop's epoch is the claim it was held under.
571
+ // A write after the stop (afterStop): one that landed before it, in the millisecond the case went on, is not one.
555
572
  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);
573
+ 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
574
  fenceHeld(childEvents(eventsFile), continuedAt);
558
575
  }
559
576
  // The process's unanswered first claim (its events file) is run out while the case waits for its death.
@@ -698,11 +715,16 @@ const CASES = [
698
715
  async body(subject, t) {
699
716
  const w = await world(subject, t);
700
717
  const { tools, letSlowGo, slowStarted } = suiteTools();
701
- await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet });
718
+ // What the subject's model was handed, and at what priority, when it can say: a failure names it with the loop's
719
+ // outcome for the steer, so the branch that placed it is on the record (a CLI's own turn after the call reads `echo:`).
720
+ const received = [];
721
+ await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet, received: (message) => void received.push({ ...message }) });
702
722
  await w.began(slowStarted, "the slow tool to start");
703
723
  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);
724
+ const why = () => `the loop's outcome for the steer: ${w.outcomeOf(steer.id)}; the model was handed: ${JSON.stringify(received)}`;
725
+ // The tool goes on once the loop has answered the steer: the turn in flight has it, never a timer (as in
726
+ // message-mid-turn-kept). A steer that reaches a CLI only after the tool's end is the next turn by its facts.
727
+ await until(() => w.answered(steer.id), "the steer placed by the loop mid-turn");
706
728
  letSlowGo();
707
729
  await w.ended("ended");
708
730
  const { calls, messages } = await w.read();
@@ -712,11 +734,11 @@ const CASES = [
712
734
  // Everything the model said once the call started. What it said with the call, before the call's row (a CLI's
713
735
  // "Calling slow."), is that step's, as deny-note reads it; the step after the call said only the steer.
714
736
  const said = messages.filter((message) => message.role === "model" && message.entry > slow.startEntry);
715
- assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}`);
716
- assert.ok(steered.entry > slow.endEntry, "after the tool's end: mid-turn, not lost");
717
- assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}`);
718
- assert.ok(said[0].entry > steered.entry);
719
- assert.ok((await w.commandRow(steer.id)).takenAt !== null, "the steer row is taken");
737
+ assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}; ${why()}`);
738
+ assert.ok(steered.entry > slow.endEntry, `after the tool's end: mid-turn, not lost; ${why()}`);
739
+ assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}; ${why()}`);
740
+ assert.ok(said[0].entry > steered.entry, why());
741
+ assert.ok((await w.commandRow(steer.id)).takenAt !== null, `the steer row is taken; ${why()}`);
720
742
  },
721
743
  },
722
744
  {
@@ -61,6 +61,12 @@ export interface ConformanceSetup {
61
61
  readonly hooks: KernelHooks;
62
62
  /** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
63
63
  readonly agentId?: string;
64
+ /** Called with each message the subject's model is handed, when the subject can see it (a stand-in's fake reports what
65
+ * it consumed and at what priority): for a case's failure message to name, never asserted on. */
66
+ readonly received?: (message: {
67
+ readonly text: string;
68
+ readonly priority?: string;
69
+ }) => void;
64
70
  }
65
71
  export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "steer-placed-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run" | "meta-search" | "meta-call-park" | "meta-call-deny" | "meta-codemode-park" | "meta-codemode-stop" | "meta-codemode-crash";
66
72
  export interface ConformanceSubject {
@@ -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: {
@@ -1,18 +1,15 @@
1
- // The runner's half of the end-of-run turn (the learning lane's reflect turn): its request id, the words a write or edit
2
- // of its under work/.learning/ is refused with, and the path rule that refuses it. Its notes are kept only from its
3
- // answer's note blocks, never from a file it writes there. The words and the rule are the tool gate's own
4
- // (tool-gate.ts NOTE_ONLY_TEXT, underLearning), kept equal by a test.
5
- import { posix, resolve, sep, join } from "node:path";
1
+ // The runner's half of the end-of-run turn (the learning lane's compile turn): its request id, and where its rounds are
2
+ // in a run's journal.
6
3
  import { KINDS } from "./journal-kinds.js";
7
4
  /** The prefix of the end-of-run turn's request id: the server's own (turns.ts REFLECT_REQUEST). */
8
5
  export const REFLECT_PREFIX = "learn-reflect-";
9
6
  /** The label a reader puts on the end-of-run turn's rows and messages: the server's (learning.ts LEARNING_LABEL). */
10
7
  export const REFLECT_LABEL = "learning";
11
- /** 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
12
- * look-back: the compile turn's attempts, `compile-<n>`): pi answers a repeat of it from its submission, so a turn
13
- * 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
14
- * 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
15
- * server's own prefix, so the run's readers tell the turn's rows apart by it (reflectRanges). */
8
+ /** 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,
9
+ * `compile-<n>`): pi answers a repeat of it from its submission, so a turn asked again on a later claim is never asked of
10
+ * 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
11
+ * 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
12
+ * rows apart by it (reflectRanges). */
16
13
  export const reflectRequestId = (runId, again = false, round = 1, step) => `${REFLECT_PREFIX}${runId}${round > 1 ? `${REFLECT_ROUND}${round}` : ""}${step !== undefined ? `:${step}` : again ? REFLECT_AGAIN : ""}`;
17
14
  /** 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
18
15
  * is answered from its submission, never asked of the model twice. */
@@ -21,7 +18,7 @@ export const REFLECT_AGAIN = ":again";
21
18
  const REFLECT_ROUND = ":round-";
22
19
  /** What a round's re-ask or step adds to its request id (reflectRequestId): the round is the id without it. */
23
20
  const REFLECT_STEP = /:(?:again|compile-\d+)$/;
24
- /** The round shared by its look-back, re-ask and compile attempts, for range and durable accounting reads. */
21
+ /** The round shared by its re-ask and compile attempts, for range and durable accounting reads. */
25
22
  export const reflectRoundId = (requestId) => requestId.replace(REFLECT_STEP, "");
26
23
  /** Each round of the end-of-run turn in a run's journal, oldest first: each begins at the entry its input placed, from the
27
24
  * input submissions under its request ids (its re-ask's within it); else, on a CLI harness, at the turn's prompt the CLI
@@ -54,28 +51,6 @@ export function reflectRanges(submissions, entries = []) {
54
51
  }
55
52
  /** Whether entry `entry` (a number) is one of `ranges`' end-of-run turns. */
56
53
  export const inReflect = (ranges, entry) => ranges.some(({ from, until }) => entry >= from && (until === undefined || entry <= until));
57
- /** 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
58
- * the adapter loop's refusal and the gate's are the same words. */
59
- export { NOTE_ONLY_TEXT as REFLECT_NOTE_ONLY } from "../tool-gate.js";
60
- /** The folder of a run's copy of what its agent learned, relative to its work. */
61
- const LEARNED_DIR = ".learning";
62
- /** A computer's work folder, as a box names it. */
63
- const BOX_WORK = "/workspace";
64
- /** The work a relative path resolves against when the run's own work folder is not known to the loop. */
65
- const NO_WORK = "/.agentrun-run-work";
66
- /** Whether `args.path`, as a file tool resolves it (a leading `@` dropped, Unicode spaces made plain, then lexically),
67
- * names work/.learning/ or a path under it: by the run's `work` (when the loop knows it), or the box's. */
68
- export function underLearning(work, args) {
69
- const path = args?.path;
70
- if (typeof path !== "string")
71
- return false;
72
- const plain = path.replace(/[  -    ]/g, " ").replace(/^@/, "");
73
- const under = (base, at) => at === join(base, LEARNED_DIR) || at.startsWith(`${join(base, LEARNED_DIR)}${sep}`);
74
- const root = work ?? NO_WORK;
75
- return under(resolve(root), resolve(root, plain)) || under(BOX_WORK, posix.resolve(BOX_WORK, plain));
76
- }
77
- /** The tools whose write the end-of-run turn is refused under work/.learning/. */
78
- export const WRITES = new Set(["write", "edit"]);
79
54
  /** The text an answer entry gave (pi's assistant entry): the text parts of the messages it adds to the model's context,
80
55
  * joined. */
81
56
  export function answerText(entry) {
@@ -2,7 +2,7 @@ import { type Grade } from "../learn/promote.js";
2
2
  import type { RunPath } from "../learning-cost.js";
3
3
  import { type RunLaunch } from "../run-launch.js";
4
4
  import { type Command, type Store } from "../store/store.js";
5
- export declare const FEEDBACK_ROUNDS: readonly ["look_back"];
5
+ export declare const FEEDBACK_ROUNDS: readonly ["correction"];
6
6
  export type FeedbackRound = (typeof FEEDBACK_ROUNDS)[number];
7
7
  /** A feedback round, as its steer's body carries it (`feedback`) and its FEEDBACK entry keeps it: the round, whether the
8
8
  * grade said right, and the grade's words (`text`). */
@@ -11,7 +11,7 @@ export interface FeedbackData {
11
11
  readonly correct: boolean;
12
12
  readonly text: string;
13
13
  }
14
- /** What a grade asks for: `look_back` for a graded run the agent finished when the grade has words, else none
14
+ /** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
15
15
  * (undefined): a run its learned workflow answered alone opens none, right or wrong (its grade is kept). A replay run
16
16
  * is never graded. */
17
17
  export declare function feedbackRoundOf(grade: {
@@ -2,10 +2,10 @@
2
2
  // learning, and how the run's next end reads it. The run's path is who wrote its final answer, so a grade never makes
3
3
  // the agent answer the job again:
4
4
  // - a run its learned workflow answered alone (path `workflow`), graded right or wrong: the grade is kept and nothing else happens: no round, no turn, $0. One wrong answer is one sample;
5
- // - a run the agent finished (path `agent` or `handed_back`) graded with words (`label`): a look-back round on them
6
- // (#2579's later round, notes). The run opens again on it: the grade's words are on its record, the agent is asked no
7
- // turn of the job's, and the run goes straight to its end-of-run turn, which reads the words. Its spend is learning
8
- // spend.
5
+ // - a run the agent finished (path `agent` or `handed_back`) graded with words (`label`): a correction round on them.
6
+ // The run opens again on it: the grade's words are on its record, the agent is asked no turn of the job's, and the
7
+ // run goes straight to its end-of-run step, which appends the words to corrections.md as one line (and compiles, when
8
+ // a compile is due). Its spend is learning spend.
9
9
  // A grade with neither asks for nothing more. The server writes the round's steer (server.ts gradeRun, runs.reopen); the
10
10
  // adapter loop takes it (adapter-loop.ts steer: a FEEDBACK entry, no turn), and the end-of-run step reads it
11
11
  // (learning-end.ts: heard, never "nothing new"; adapter-loop.ts askEndOfRun: feedbackAsk before the prompt).
@@ -14,12 +14,12 @@ import { readLaunchBody } from "../run-launch.js";
14
14
  import { RunFinal } from "../store/store.js";
15
15
  import { KINDS } from "./journal-kinds.js";
16
16
  import { commandRequest } from "./loop.js";
17
- export const FEEDBACK_ROUNDS = ["look_back"];
18
- /** What a grade asks for: `look_back` for a graded run the agent finished when the grade has words, else none
17
+ export const FEEDBACK_ROUNDS = ["correction"];
18
+ /** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
19
19
  * (undefined): a run its learned workflow answered alone opens none, right or wrong (its grade is kept). A replay run
20
20
  * is never graded. */
21
21
  export function feedbackRoundOf(grade, label) {
22
- return (grade.path === "agent" || grade.path === "handed_back") && label ? "look_back" : undefined;
22
+ return (grade.path === "agent" || grade.path === "handed_back") && label ? "correction" : undefined;
23
23
  }
24
24
  /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
25
25
  * message API never does), else undefined. */
@@ -8,6 +8,7 @@
8
8
  import { unseal } from "../sealing.js";
9
9
  import { GITHUB_API, GITHUB_FIELDS, GITHUB_SCOPE, githubCall, githubTargetOf, mintInstallationToken } from "../github.js";
10
10
  import { isObject } from "../validate.js";
11
+ import { held } from "./held.js";
11
12
  const ADAPTER = "github";
12
13
  const aad = (field) => `trigger_settings|${ADAPTER}|${GITHUB_SCOPE}|${field}`;
13
14
  /** The server's App as the store holds it now, opened with `sealKey`: its id and private key, or undefined when there is none
@@ -37,8 +38,9 @@ async function appOf(store, sealKey) {
37
38
  * the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
38
39
  * joins the run's redactor (its `cut`), the first and every one after. */
39
40
  export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold, repo } = {}) {
41
+ // A run's own process holds no seal key: its runner's access for the claim's own launch, which mints there (held.ts).
40
42
  if (!sealKey)
41
- return undefined;
43
+ return held()?.githubAppAccess();
42
44
  const app = await appOf(store, sealKey);
43
45
  if (!app)
44
46
  return undefined;
@@ -1,7 +1,5 @@
1
1
  import type { RunLaunch } from "../run-launch.js";
2
2
  import { type AdapterSpecDeps } from "./adapter-run-spec.js";
3
- import { type GradeRouteAsk } from "./learning-dispatch.js";
4
- import type { GraderRoute } from "./learning-ask.js";
5
3
  import { ClaimRefused, type LoopFactory } from "./loop-contract.js";
6
4
  /** A claimed run whose harness this host's memory never holds: its message is the host's words (neverFits). A claim
7
5
  * refused for good, so a parked run it wakes fails too, never retried as a resume (runner.ts finish). */
@@ -11,12 +9,6 @@ export declare class NeverFits extends ClaimRefused {
11
9
  /** The dispatch's `resolve`, built from the runner's deps: it reads the run's revision (for a workflow revision) and
12
10
  * returns the loop the run runs on, or undefined when this runner does not run it (the dispatch fails it in words). */
13
11
  export declare function resolveRunnerLoop(deps: AdapterSpecDeps): (harness: string, launch: RunLaunch, runId: string) => Promise<LoopFactory | undefined>;
14
- /** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
15
- * one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
16
- * is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
17
- * by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
18
- * the default tier. */
19
- export declare function gradeRouteFor(grade: GradeRouteAsk, env: NodeJS.ProcessEnv, routeOf: AdapterSpecDeps["routeOf"]): Promise<GraderRoute>;
20
12
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
21
13
  * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
22
14
  * start and the test server pass this to startRunner. */
@@ -1,13 +1,10 @@
1
- import { createSdkLoop, sdkSourceInstructions } from "./sdk-loop.js";
2
- import { sdkOf } from "../sdk/runs.js";
3
- import { createNativeLoop, nativeLearningLoop, nativeSourceInstructions } from "./native-loop.js";
4
- import { nativeOf } from "../native/binding.js";
1
+ import { createSdkLoop } from "./sdk-loop.js";
2
+ import { createNativeLoop } from "./native-loop.js";
5
3
  // The runner's dispatch switch (design 2.1: "the runner takes every run"): which loop a claimed run runs, by its revision
6
4
  // and the harness its launch names. The runner holds one dispatch loop (dispatch.ts) for every run; at the claim the
7
5
  // dispatch reads the launch and asks this switch for the run's inner loop:
8
6
  // - a workflow revision runs on the workflow loop (createWorkflowLoop), whatever its harness name (a workflow's default
9
7
  // harness is pi), so the revision is read here to tell it from an agentic pi run;
10
- // - a built-in learning run (its launch names harness "learning") runs on the learning loop;
11
8
  // - pi runs on the kernel's adapter loop with the run's pi spec (adapterRunSpecFromLaunch), and so does a harness a
12
9
  // module adds with no adapter facts of its own, on its runner's adapter;
13
10
  // - a CLI harness (claude-agent, codex, opencode) runs on the adapter loop with its own adapter;
@@ -21,7 +18,7 @@ import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
21
18
  import { noServerKeyFor } from "../run-model-key.js";
22
19
  import { createDispatchLoop } from "./dispatch.js";
23
20
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
24
- import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
21
+ import { askRouteOf } from "./sdk-ask.js";
25
22
  import { ClaimRefused } from "./loop-contract.js";
26
23
  import { createWorkflowLoop, isWorkflowRevision } from "./workflow-loop.js";
27
24
  import { workflowSpecOf } from "./workflow-spec.js";
@@ -45,56 +42,23 @@ export function resolveRunnerLoop(deps) {
45
42
  // store-secrets.ts), and every one the server keeps is held by the run's one redactor.
46
43
  return createWorkflowLoop(workflowSpecOf({ store: deps.store, sealKey: deps.sealKey, data: deps.data, ...(deps.env ? { env: deps.env } : {}) }));
47
44
  }
48
- if (harness !== "learning" && launch.sdk)
45
+ // A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
46
+ // start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
47
+ if (launch.sdk)
49
48
  return createSdkLoop(launch, deps, async () => {
50
49
  const base = deps.env ?? process.env;
51
- // An SDK run's look-back runs after its backend reported it complete, on no run's key: on a server that holds no
52
- // gateway key it is skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
53
50
  const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
54
- const off = noServerKeyFor(env, "An SDK run's look-back");
51
+ // It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
52
+ // skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
53
+ const off = noServerKeyFor(env, "An SDK run's compile turn");
55
54
  if (off) {
56
55
  deps.log?.(off);
57
56
  throw new Error(off);
58
57
  }
59
- return gradeRouteFor({ model: launch.learning.gradeModel, agentId: run.agentId }, env, deps.routeOf);
58
+ return askRouteOf(launch.learning.model, env, (model) => deps.routeOf(model, env, "default", PI_WIRES));
60
59
  });
61
- if (harness !== "learning" && launch.native)
60
+ if (launch.native)
62
61
  return createNativeLoop(launch, deps);
63
- if (harness === "learning") {
64
- const native = nativeOf(revision?.body);
65
- if (native && !launch.model)
66
- return nativeLearningLoop(deps, native);
67
- // A built-in learning run on the learning loop: its grade goes through the runner's one model route, on the grade
68
- // model its launch names (none: the agent's own), at that route's price (learning-dispatch.ts).
69
- return learningLoopOf({
70
- store: deps.store,
71
- data: deps.data,
72
- ...(sdkOf(revision?.body) ? { sourceInstructions: (runId) => sdkSourceInstructions(deps.store, runId) } : {}),
73
- ...(native ? { sourceInstructions: (runId) => nativeSourceInstructions(deps.store, runId) } : {}),
74
- // The grader speaks the route's wire, as pi does (learning-ask.ts: pi.ts policyFor and port-models.ts
75
- // sessionProvider), so its route is asked on pi's wires; a model on neither keeps the route's Messages translation.
76
- // A grade model whose vendor this host reaches only through OpenRouter goes there as main's grade does
77
- // (gradeRouteOf): OpenRouter's key its one credential, priced at OpenRouter's price.
78
- // The grade's model, main's order (gradeModelFor): the grade model the server names, else the agent's own.
79
- // Its model's key from the runner's environment, else the one saved in Settings → Model keys (savedModelKeys), read
80
- // at each grade, so a key saved with no restart grades the next learning run.
81
- routeOf: async (grade) => {
82
- const base = deps.env ?? process.env;
83
- // A learning run grades after its source run's turn ended, on no run's key (a run that brought its own queues no
84
- // grade: learning-end.ts spendOff): on a server that holds no gateway key it is skipped in words
85
- // (run-model-key.ts noServerKeyFor). Nothing is sent; the learning run ends dropped.
86
- const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
87
- const off = noServerKeyFor(env, "A learning run's grade");
88
- if (off) {
89
- deps.log?.(off);
90
- throw new Error(off);
91
- }
92
- return gradeRouteFor(grade, env, deps.routeOf);
93
- },
94
- ...(deps.log ? { log: deps.log } : {}),
95
- ...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
96
- });
97
- }
98
62
  // The harness's own entry decides which spec builds the run, by what the entry gives and never the harness's name: an
99
63
  // entry with an adapter's facts and serve's own adapter for it (the CLI harnesses) runs the CLI spec (cli-run-spec.ts);
100
64
  // any other (pi, or a harness module's entry that gives only the required members) runs the run spec
@@ -122,18 +86,6 @@ export function resolveRunnerLoop(deps) {
122
86
  return undefined;
123
87
  };
124
88
  }
125
- /** The route a grade asks for (gradeModelFor: the grade model the server named, else the agent's own), from the runner's
126
- * one route (`routeOf`), through gradeRouteOf. A grade model the server named (--grade-model, else AGENT_MODEL_STRONG)
127
- * is the strong tier's: it goes with that tier's settings, sent whole as AGENT_MODEL_STRONG is (never cut to its bare id
128
- * by AGENT_MODEL_GATEWAY_IDS) and priced at AGENT_MODEL_STRONG_PRICE. The agent's own model goes as its runs' does, on
129
- * the default tier. */
130
- export function gradeRouteFor(grade, env, routeOf) {
131
- return gradeRouteOf(gradeModelFor(grade), env, (model) => (grade.model !== undefined && model === grade.model
132
- // The runner's environment under the grader as its strong model: every key it holds read through it, a non-enumerable
133
- // one (a launcher-held or Settings key) too, which a copy would drop.
134
- ? routeOf(undefined, Object.create(env, { AGENT_MODEL_STRONG: { value: model, enumerable: true } }), "strong", PI_WIRES)
135
- : routeOf(model, env, "default", PI_WIRES)));
136
- }
137
89
  /** The loop factory the runner holds for every run (its createLoop), built from the runner's deps over the one store: the
138
90
  * dispatch (dispatch.ts) reads each run's launch and asks resolveRunnerLoop for its harness loop. The server
139
91
  * start and the test server pass this to startRunner. */
@@ -0,0 +1,170 @@
1
+ import type { PlanReader } from "../chatgpt-plan.js";
2
+ import type { Tier } from "../model.js";
3
+ import type { RunSignIn } from "../sign-ins-store.js";
4
+ import type { LiveHandover } from "../browser-live.js";
5
+ import type { ApprovalPrice, ToolEffect } from "../tool-gate.js";
6
+ import type { OpenedAccount } from "../email/account.js";
7
+ import type { SavedCalendar } from "../calendar/address.js";
8
+ import type { Workspace } from "../workspace/workspace.js";
9
+ import type { GithubAppAccessAt } from "./github-app.js";
10
+ import type { HarnessInstallEntry, HarnessPins } from "../harness-install.js";
11
+ import type { AlsoRow } from "../store/store.js";
12
+ import type { RunModelKey } from "../store/seal.js";
13
+ import type { EndOfRunKept, EndOfRunTurn } from "./loop-contract.js";
14
+ import type { LearnedFirst } from "./learned-first.js";
15
+ /** One MCP tool of the claim, its call made by the runner (mcp-run.ts mcpForClaim), with what the gate reads of it. */
16
+ export interface HeldMcpTool {
17
+ readonly name: string;
18
+ readonly description: string;
19
+ readonly inputSchema: unknown;
20
+ readonly catalog: string;
21
+ readonly arguments?: readonly string[];
22
+ readonly price?: ApprovalPrice;
23
+ readonly effect?: ToolEffect;
24
+ call(args: unknown, context: {
25
+ readonly signal?: AbortSignal;
26
+ readonly callId?: string;
27
+ }): Promise<{
28
+ text: string;
29
+ isError?: true;
30
+ }>;
31
+ }
32
+ /** The claim's MCP as the runner holds it: its tools, and its credentials' refresh and release. */
33
+ export interface HeldMcp {
34
+ readonly tools: readonly HeldMcpTool[];
35
+ fresh(): Promise<void>;
36
+ release(): Promise<void>;
37
+ }
38
+ /** What the run's process gives mcpForClaim on the runner: its grants and harness are its revision's, which the runner
39
+ * reads itself. */
40
+ export interface HeldMcpAsk {
41
+ /** The run's journal commit, for a call's record on the run's root (mcp-gateway.ts commit): an entry appended. */
42
+ readonly appendRoot: (entry: unknown) => Promise<void>;
43
+ }
44
+ /** What the run's process gives the runner's computerForClaim (workspace/computer-for-claim.ts): its callbacks only. The
45
+ * run, its epoch, its folder, its mode and its revision are the runner's own reads of the claim. */
46
+ export interface HeldComputerAsk {
47
+ readonly hadComputer: () => Promise<boolean>;
48
+ readonly signal?: AbortSignal;
49
+ readonly say?: (words: string) => void;
50
+ readonly onImageWait?: (making: boolean, image: string) => void;
51
+ readonly onStarting?: (said: string) => void;
52
+ readonly onConnected?: (said: string) => void;
53
+ readonly onComputerNote?: (words: string) => void;
54
+ }
55
+ export interface Held {
56
+ /** The ChatGPT sign-in's reader (chatgpt-plan.ts planReaderOf), for a run whose models reach the plan; else none. */
57
+ plan(): Promise<PlanReader | undefined>;
58
+ /** Whether a browser sign-in handed to the run reads back here (sign-ins-store.ts handedSignInReadsBack). */
59
+ signInReadsBack(): Promise<boolean>;
60
+ /** The run's browser sign-in for vendor `resolution` (sign-ins-store.ts runSignIn). */
61
+ runSignIn(resolution: string): Promise<RunSignIn | undefined>;
62
+ /** The run's kept sign-in marked verified at `at` (sign-ins-store.ts verifyRunSignIn). */
63
+ verifySignIn(kept: RunSignIn, at: number): Promise<boolean>;
64
+ /** The claim's MCP (mcp-run.ts mcpForClaim); none when its revision grants no MCP tool. */
65
+ mcp(ask: HeldMcpAsk): Promise<HeldMcp | undefined>;
66
+ /** The GitHub App's access for the run's pull-request checkout (pr-checkout.ts): none unless its revision checks one
67
+ * out and its launch's payload names the pull request. Its mint makes a token of that repository alone, contents
68
+ * read, whatever the process names; its MCP mints on the runner (mcp). */
69
+ githubAppAccess(): Promise<GithubAppAccessAt | undefined>;
70
+ /** Every saved model key, for a run whose routes have no revision to scope them by (a subagent's tiers, a grade). */
71
+ savedModelKeys(): Promise<Record<string, string>>;
72
+ /** The model keys the host's models of `tiers` need (claim-secrets.ts tierModelKeys), the plan's reader with them: of
73
+ * the tiers the claim's learned workflows name, as the runner chose them (learnedFirst), alone. */
74
+ tierModelKeys(tiers: readonly Tier[]): Promise<{
75
+ readonly keys: Record<string, string>;
76
+ readonly plan?: PlanReader;
77
+ }>;
78
+ /** The run's own model key, opened from the claim's run's launch (claim-secrets.ts claimModelKey): none where it holds
79
+ * none; throws, in words, where the launch does not open under the runner's seal key. Asked again for each message's
80
+ * key (ClaimModelKey.fresh). */
81
+ runModelKey(): Promise<RunModelKey | undefined>;
82
+ /** Whether the server has a gateway and holds no key for it (claim-secrets.ts serverKeyless): a boolean, never a key. */
83
+ serverKeyless(): Promise<boolean>;
84
+ /** The zone the claim's run's day is told in (environment.ts runZone): its trigger's, read by the runner from the
85
+ * claim's own launch, else the server's. A zone's name, never the trigger's row. */
86
+ runZone(): Promise<string>;
87
+ /** The host's keys of the decision providers `providers` (claim-secrets.ts hostDecisionKeys): of the providers the
88
+ * claim's learned workflows' questions name, as the runner chose them (learnedFirst), alone. */
89
+ decisionKeys(providers: readonly string[]): Promise<Record<string, string>>;
90
+ /** A browser session's viewer handed over, and taken back (browser-live.ts). */
91
+ liveViewerPut(handover: LiveHandover): Promise<boolean>;
92
+ liveViewerDrop(tag?: string): Promise<void>;
93
+ /** The MCP credentials run `from` was handed, sealed again for run `id`, a run this one starts (promotion.ts,
94
+ * audit.ts): none unless `from` is the claim's own run. */
95
+ handOn(from: string, id: string): Promise<Uint8Array | undefined>;
96
+ /** The run's agent's live sign-in pointer for `resolution`, and its forgotten ones (sign-ins-store.ts signInReads): what
97
+ * its learning end holds to refuse a pointer in what the run learned. */
98
+ signInPeek(resolution: string): Promise<unknown>;
99
+ signInForgotten(resolution: string): Promise<unknown>;
100
+ /** The server's email account, opened, for a run whose revision grants an email tool; else none. */
101
+ emailAccount(): Promise<OpenedAccount | undefined>;
102
+ /** The server's calendar, opened, for a run whose revision grants calendar_events; else none. */
103
+ calendar(): Promise<SavedCalendar | undefined>;
104
+ /** A call of the run's agent's learning folder (learn/folder.ts), the runner's own Workspace of it, held to what a
105
+ * run's learning does there (run-child-host.ts learningCall). */
106
+ learning(method: string, args: readonly unknown[]): Promise<unknown>;
107
+ /** The harness `name`'s install for the claim (harness-install.ts installForClaim), run by the runner. */
108
+ install(name: string, signal?: AbortSignal): Promise<void>;
109
+ /** The claim's computer (workspace/computer-for-claim.ts), made and held by the runner. */
110
+ computer(ask: HeldComputerAsk): Promise<unknown>;
111
+ /** A Mode 2 claim: the run's folder on its Archil disk, as the runner opens it; its mount credential's revoke. */
112
+ archil(): Promise<{
113
+ readonly workspace: Workspace;
114
+ revoke(): Promise<void>;
115
+ inherit(): Promise<void>;
116
+ release(): Promise<void>;
117
+ } | undefined>;
118
+ /** The claim's end-of-run step (learning-end.ts learningEndOfRun), run by the runner over its own reads of the claim:
119
+ * what the run's learning must never keep is every secret the runner holds, which no run's process is given. Its
120
+ * turns are asked through `input.ask`, the run's own session; `input.keptOf` is read once, for the round the runner
121
+ * reads. */
122
+ endOfRun(input: HeldEndOfRunInput): Promise<{
123
+ readonly also: readonly AlsoRow[];
124
+ } | undefined>;
125
+ /** The claim's learned first choice (learned-first.ts learnedFirst), run by the runner over the workflows it reads at the
126
+ * claim's seed: `laid` says only whether the process's seed lay laid any (false: none is laid). Its audits, promotion
127
+ * and replay reads are the runner's. */
128
+ learnedFirst(ask: {
129
+ readonly laid: boolean;
130
+ }): Promise<LearnedFirst>;
131
+ /** The runner's live address (live-reach.ts runnerLiveOf) with the claim's own proof key (liveForRun): what proves a
132
+ * request for this run's viewers alone. None on a runner on its server's machine. */
133
+ liveAt(): Promise<{
134
+ readonly host: string;
135
+ readonly bind: string;
136
+ readonly key: Uint8Array;
137
+ } | undefined>;
138
+ }
139
+ /** What a run's process hands its runner for the end-of-run step: EndOfRunTurn's input, its keptOf asked over the
140
+ * channel (so answered later). */
141
+ export type HeldEndOfRunInput = Omit<Parameters<EndOfRunTurn>[0], "keptOf"> & {
142
+ readonly keptOf?: (round: number) => Promise<EndOfRunKept | undefined>;
143
+ };
144
+ /** Sets this process's runner seam: run-child.ts, once, before the run's loop starts. */
145
+ export declare function setHeld(held: Held): void;
146
+ /** This process's runner seam: set in a run's own process, never in a runner or a server. */
147
+ export declare function held(): Held | undefined;
148
+ /** This process's runner seam, where a caller with no seal key needs one: a runner or a server that reaches here with
149
+ * no key is a bug, said in words, never a quiet answer of nothing. */
150
+ export declare function heldOrThrow(what: string): Held;
151
+ /** signInReads (sign-ins-store.ts) in a run's own process: the claim's agent's, read by its runner. */
152
+ export declare function heldSignInReads(): {
153
+ peek(agentId: string, resolution: string): Promise<never>;
154
+ forgotten(agentId: string, resolution: string): Promise<never>;
155
+ };
156
+ /** The agent's learning folder in a run's own process (learn/folder.ts learningWorkspace): each call made by its runner on
157
+ * the folder of the claim's agent (Held.learning), whatever place this process names. No background program, mount or
158
+ * attach: a learning folder has none. */
159
+ export declare function heldLearningFolder(): {
160
+ readonly workspace: Workspace;
161
+ end(): Promise<void>;
162
+ };
163
+ /** A learning run's end-of-run step in a run's own process (learning-end.ts learningEndOfRun): its runner's
164
+ * (Held.endOfRun), whatever deps the process would have built it with. */
165
+ export declare function heldEndOfRun(): EndOfRunTurn;
166
+ /** A runner's install of a harness, as a run's process asks it (AdapterSpecDeps.installForClaim): the harness's name
167
+ * alone crosses; the runner reads its entry, folder and pins itself. */
168
+ export declare const heldInstall: (entry: HarnessInstallEntry, _dir: string, _pins: () => Promise<HarnessPins>, given?: {
169
+ signal?: AbortSignal;
170
+ }) => Promise<void>;