@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37

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 (325) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +158 -52
  3. package/dist/attach-conformance-cli.d.ts +1 -0
  4. package/dist/attach-conformance-cli.js +18 -0
  5. package/dist/attach-conformance.d.ts +25 -0
  6. package/dist/attach-conformance.js +343 -0
  7. package/dist/browser-cost.d.ts +1 -1
  8. package/dist/browser-live.d.ts +20 -8
  9. package/dist/browser-live.js +50 -27
  10. package/dist/cap.d.ts +0 -17
  11. package/dist/cap.js +0 -91
  12. package/dist/catalog.d.ts +1 -12
  13. package/dist/catalog.js +3 -33
  14. package/dist/cli.js +13 -4
  15. package/dist/composio-preset.d.ts +36 -0
  16. package/dist/composio-preset.js +179 -0
  17. package/dist/computer-attach.d.ts +125 -0
  18. package/dist/computer-attach.js +330 -0
  19. package/dist/computer-calls.d.ts +48 -0
  20. package/dist/computer-calls.js +126 -0
  21. package/dist/computer-channel.d.ts +57 -0
  22. package/dist/computer-channel.js +115 -0
  23. package/dist/computer-commands.d.ts +1 -1
  24. package/dist/computer-held-routes.d.ts +35 -0
  25. package/dist/computer-held-routes.js +106 -0
  26. package/dist/computer-held.d.ts +48 -0
  27. package/dist/computer-held.js +87 -0
  28. package/dist/computer-keys.d.ts +21 -1
  29. package/dist/computer-keys.js +53 -11
  30. package/dist/computer-live.d.ts +160 -0
  31. package/dist/computer-live.js +643 -0
  32. package/dist/computer-view.d.ts +13 -0
  33. package/dist/computer-view.js +50 -3
  34. package/dist/computer-viewer.d.ts +6 -0
  35. package/dist/computer-viewer.js +297 -0
  36. package/dist/computers.d.ts +33 -7
  37. package/dist/computers.js +50 -8
  38. package/dist/console/assets/index-Cn6JX1uH.js +563 -0
  39. package/dist/console/assets/index-DRN62V5v.css +1 -0
  40. package/dist/console/index.html +2 -2
  41. package/dist/faux-computers.d.ts +9 -20
  42. package/dist/faux-computers.js +53 -25
  43. package/dist/github-connection.d.ts +10 -2
  44. package/dist/github-connection.js +65 -2
  45. package/dist/github-faux.js +1 -1
  46. package/dist/graph-view.d.ts +1 -1
  47. package/dist/harness.d.ts +1 -0
  48. package/dist/harness.js +35 -1
  49. package/dist/host-tools.d.ts +1 -1
  50. package/dist/hosted-search.d.ts +5 -4
  51. package/dist/hosted-search.js +2 -7
  52. package/dist/import-sources.d.ts +10 -0
  53. package/dist/import-sources.js +44 -2
  54. package/dist/import.d.ts +3 -3
  55. package/dist/import.js +37 -6
  56. package/dist/learn/check.d.ts +4 -1
  57. package/dist/learn/check.js +1 -1
  58. package/dist/learn/commit.d.ts +4 -2
  59. package/dist/learn/commit.js +5 -5
  60. package/dist/learn/folder.d.ts +6 -0
  61. package/dist/learn/folder.js +4 -1
  62. package/dist/learn/general.d.ts +66 -0
  63. package/dist/learn/general.js +73 -0
  64. package/dist/learn/grade.d.ts +4 -0
  65. package/dist/learn/grade.js +22 -1
  66. package/dist/learn/reflect.d.ts +10 -1
  67. package/dist/learn/reflect.js +14 -4
  68. package/dist/learn/skills.d.ts +33 -5
  69. package/dist/learn/skills.js +53 -7
  70. package/dist/learned-workflow.d.ts +24 -0
  71. package/dist/learned-workflow.js +66 -3
  72. package/dist/learning-batch.d.ts +283 -0
  73. package/dist/learning-batch.js +574 -0
  74. package/dist/learning-evals.d.ts +33 -0
  75. package/dist/learning-evals.js +98 -0
  76. package/dist/learning-routes.d.ts +25 -2
  77. package/dist/learning-routes.js +39 -6
  78. package/dist/learning-words.d.ts +6 -0
  79. package/dist/learning-words.js +6 -0
  80. package/dist/learning.d.ts +28 -15
  81. package/dist/learning.js +84 -44
  82. package/dist/live/stream.js +6 -3
  83. package/dist/live/translate.d.ts +4 -3
  84. package/dist/live/translate.js +8 -4
  85. package/dist/live-reach.d.ts +37 -0
  86. package/dist/live-reach.js +62 -0
  87. package/dist/mcp-gateway.d.ts +9 -0
  88. package/dist/mcp-gateway.js +60 -11
  89. package/dist/mcp-oauth.d.ts +57 -7
  90. package/dist/mcp-oauth.js +133 -18
  91. package/dist/mcp-private-hosts.d.ts +4 -4
  92. package/dist/mcp-private-hosts.js +20 -12
  93. package/dist/mcp-probe.d.ts +19 -2
  94. package/dist/mcp-probe.js +44 -9
  95. package/dist/mcp-secret-writes.js +4 -0
  96. package/dist/mcp-servers-store.d.ts +38 -15
  97. package/dist/mcp-servers-store.js +112 -20
  98. package/dist/mcp-store.d.ts +10 -4
  99. package/dist/mcp-store.js +17 -6
  100. package/dist/model-form.d.ts +26 -0
  101. package/dist/model-form.js +80 -0
  102. package/dist/model.js +23 -10
  103. package/dist/openapi.js +386 -21
  104. package/dist/page.d.ts +18 -0
  105. package/dist/page.js +48 -20
  106. package/dist/paid-calls.d.ts +1 -1
  107. package/dist/place-offers.d.ts +2 -3
  108. package/dist/place-offers.js +3 -7
  109. package/dist/place.js +1 -2
  110. package/dist/print.d.ts +15 -1
  111. package/dist/print.js +14 -3
  112. package/dist/propose.d.ts +3 -0
  113. package/dist/propose.js +13 -5
  114. package/dist/provider.js +3 -2
  115. package/dist/reflect-range.d.ts +8 -1
  116. package/dist/reflect-range.js +1 -1
  117. package/dist/run-launch.d.ts +14 -2
  118. package/dist/run-launch.js +9 -4
  119. package/dist/run-learning-served.d.ts +2 -2
  120. package/dist/run-reads-over-store.d.ts +1 -1
  121. package/dist/run-repo.d.ts +20 -0
  122. package/dist/run-repo.js +63 -0
  123. package/dist/run-timeline-served.d.ts +1 -1
  124. package/dist/run-view.d.ts +3 -3
  125. package/dist/run-view.js +14 -7
  126. package/dist/runner/adapter-loop.d.ts +23 -7
  127. package/dist/runner/adapter-loop.js +648 -62
  128. package/dist/runner/adapter-run-spec.d.ts +11 -3
  129. package/dist/runner/adapter-run-spec.js +77 -22
  130. package/dist/runner/adapters/pi-computer.d.ts +7 -0
  131. package/dist/runner/adapters/pi-computer.js +43 -0
  132. package/dist/runner/adapters/pi.d.ts +9 -4
  133. package/dist/runner/adapters/pi.js +76 -14
  134. package/dist/runner/beside.d.ts +7 -3
  135. package/dist/runner/beside.js +21 -11
  136. package/dist/runner/claim-secrets.d.ts +4 -0
  137. package/dist/runner/claim-secrets.js +6 -1
  138. package/dist/runner/cli-run-spec.d.ts +20 -3
  139. package/dist/runner/cli-run-spec.js +113 -43
  140. package/dist/runner/commands.d.ts +3 -1
  141. package/dist/runner/commands.js +28 -3
  142. package/dist/runner/computer-channel.d.ts +34 -0
  143. package/dist/runner/computer-channel.js +61 -0
  144. package/dist/runner/conformance/harness.js +80 -14
  145. package/dist/runner/conformance/subject.d.ts +1 -1
  146. package/dist/runner/dispatch.js +3 -0
  147. package/dist/runner/end-of-run.d.ts +22 -12
  148. package/dist/runner/end-of-run.js +38 -16
  149. package/dist/runner/github-app.d.ts +2 -1
  150. package/dist/runner/github-app.js +4 -2
  151. package/dist/runner/harness-loops.js +15 -1
  152. package/dist/runner/held-run.d.ts +65 -0
  153. package/dist/runner/held-run.js +158 -0
  154. package/dist/runner/journal-kinds.d.ts +20 -1
  155. package/dist/runner/journal-kinds.js +14 -0
  156. package/dist/runner/journal-reader.d.ts +5 -4
  157. package/dist/runner/journal-reader.js +12 -10
  158. package/dist/runner/learning-ask.d.ts +7 -1
  159. package/dist/runner/learning-ask.js +21 -6
  160. package/dist/runner/learning-dispatch.d.ts +22 -0
  161. package/dist/runner/learning-dispatch.js +77 -10
  162. package/dist/runner/learning-end.d.ts +22 -1
  163. package/dist/runner/learning-end.js +92 -12
  164. package/dist/runner/learning-factory.d.ts +1 -1
  165. package/dist/runner/learning-factory.js +11 -5
  166. package/dist/runner/learning-loop.d.ts +67 -7
  167. package/dist/runner/learning-loop.js +173 -21
  168. package/dist/runner/learning-seed.d.ts +7 -0
  169. package/dist/runner/learning-seed.js +13 -0
  170. package/dist/runner/live-ticker.js +1 -0
  171. package/dist/runner/loop-contract.d.ts +8 -1
  172. package/dist/runner/loop.d.ts +5 -1
  173. package/dist/runner/loop.js +2 -1
  174. package/dist/runner/main.d.ts +13 -1
  175. package/dist/runner/main.js +27 -5
  176. package/dist/runner/mcp-claim.d.ts +10 -7
  177. package/dist/runner/mcp-claim.js +113 -24
  178. package/dist/runner/mcp-github.js +1 -1
  179. package/dist/runner/mcp-run.d.ts +5 -5
  180. package/dist/runner/mcp-run.js +15 -3
  181. package/dist/runner/metrics.d.ts +11 -2
  182. package/dist/runner/metrics.js +12 -2
  183. package/dist/runner/pr-checkout.d.ts +1 -0
  184. package/dist/runner/pr-checkout.js +1 -1
  185. package/dist/runner/reflect-hook.d.ts +18 -0
  186. package/dist/runner/reflect-hook.js +20 -8
  187. package/dist/runner/runner.d.ts +26 -0
  188. package/dist/runner/runner.js +184 -15
  189. package/dist/runner/scratch-sweep.d.ts +13 -0
  190. package/dist/runner/scratch-sweep.js +62 -0
  191. package/dist/runner/sessions.d.ts +1 -1
  192. package/dist/runner/store-port.d.ts +4 -2
  193. package/dist/runner/store-secrets.js +4 -3
  194. package/dist/runner/subagent.js +3 -1
  195. package/dist/runner/workflow-host.d.ts +6 -1
  196. package/dist/runner/workflow-host.js +1 -1
  197. package/dist/runner/workflow-loop.d.ts +1 -1
  198. package/dist/runner/workflow-spec.d.ts +14 -2
  199. package/dist/runner/workflow-spec.js +56 -20
  200. package/dist/runs-over-store.d.ts +6 -1
  201. package/dist/runs-over-store.js +38 -9
  202. package/dist/seal-key.js +3 -3
  203. package/dist/sealed-settings-store.d.ts +5 -2
  204. package/dist/sealed-settings-store.js +10 -4
  205. package/dist/secret-writes.d.ts +5 -4
  206. package/dist/secret-writes.js +5 -4
  207. package/dist/server-secrets-store.d.ts +4 -3
  208. package/dist/server-secrets-store.js +15 -9
  209. package/dist/server-secrets.js +3 -2
  210. package/dist/server.d.ts +43 -14
  211. package/dist/server.js +472 -126
  212. package/dist/settings-wake.d.ts +21 -0
  213. package/dist/settings-wake.js +59 -0
  214. package/dist/standard-webhooks.d.ts +4 -1
  215. package/dist/standard-webhooks.js +8 -4
  216. package/dist/store/command-wake.d.ts +12 -0
  217. package/dist/store/command-wake.js +37 -0
  218. package/dist/store/dialect.d.ts +6 -0
  219. package/dist/store/dialect.js +5 -0
  220. package/dist/store/index.d.ts +1 -1
  221. package/dist/store/journal/storage.d.ts +3 -2
  222. package/dist/store/journal/storage.js +13 -5
  223. package/dist/store/postgres/dialect.js +4 -0
  224. package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
  225. package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
  226. package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
  227. package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
  228. package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
  229. package/dist/store/schema.d.ts +1 -1
  230. package/dist/store/schema.js +77 -8
  231. package/dist/store/sqlite/run-patch.d.ts +7 -5
  232. package/dist/store/sqlite/run-patch.js +28 -13
  233. package/dist/store/sqlite/store.js +272 -54
  234. package/dist/store/store.d.ts +268 -9
  235. package/dist/store/store.js +12 -1
  236. package/dist/store-reads/cap.d.ts +1 -1
  237. package/dist/store-reads/cap.js +8 -1
  238. package/dist/store-reads/decisions.d.ts +2 -2
  239. package/dist/store-reads/decisions.js +1 -1
  240. package/dist/store-reads/import-summary.d.ts +1 -1
  241. package/dist/store-reads/journal.d.ts +5 -4
  242. package/dist/store-reads/journal.js +73 -15
  243. package/dist/store-reads/learning.d.ts +20 -4
  244. package/dist/store-reads/learning.js +74 -18
  245. package/dist/store-reads/runs.d.ts +1 -1
  246. package/dist/store-reads/workflow.d.ts +1 -1
  247. package/dist/store-view.d.ts +5 -0
  248. package/dist/store-view.js +26 -11
  249. package/dist/template-eval.js +6 -4
  250. package/dist/template-github-permissions.d.ts +22 -8
  251. package/dist/template-github-permissions.js +35 -15
  252. package/dist/timeline/timeline.d.ts +27 -0
  253. package/dist/timeline/timeline.js +10 -9
  254. package/dist/timeline/util.d.ts +4 -0
  255. package/dist/timeline/util.js +14 -0
  256. package/dist/tool-budget.d.ts +19 -7
  257. package/dist/tool-budget.js +14 -8
  258. package/dist/tool-gate.d.ts +16 -9
  259. package/dist/tool-gate.js +53 -42
  260. package/dist/tool-plane.d.ts +16 -12
  261. package/dist/tool-plane.js +9 -4
  262. package/dist/tools.d.ts +13 -4
  263. package/dist/tools.js +13 -4
  264. package/dist/trigger-adapter.d.ts +4 -0
  265. package/dist/trigger-secrets-shown.d.ts +2 -2
  266. package/dist/trigger-secrets-shown.js +1 -1
  267. package/dist/trigger-signatures.d.ts +25 -6
  268. package/dist/trigger-signatures.js +41 -7
  269. package/dist/trigger-targets.d.ts +2 -0
  270. package/dist/trigger-targets.js +1 -0
  271. package/dist/trigger-webhook.js +5 -2
  272. package/dist/triggers.d.ts +7 -3
  273. package/dist/triggers.js +35 -5
  274. package/dist/turns.js +16 -1
  275. package/dist/validate.js +11 -1
  276. package/dist/web-fetch.d.ts +1 -1
  277. package/dist/web-search.d.ts +10 -5
  278. package/dist/web-search.js +7 -6
  279. package/dist/webhooks.d.ts +145 -102
  280. package/dist/webhooks.js +559 -322
  281. package/dist/workflow/decisions.d.ts +1 -1
  282. package/dist/workflow/node-runner.d.ts +2 -1
  283. package/dist/workflow/node.d.ts +2 -1
  284. package/dist/workflow/node.js +3 -1
  285. package/dist/workflow/pi-versions.d.ts +23 -0
  286. package/dist/workflow/pi-versions.js +57 -0
  287. package/dist/workflow/record-tool.d.ts +2 -1
  288. package/dist/workflow/store.d.ts +1 -1
  289. package/dist/workflow/task.js +3 -2
  290. package/dist/workflow-run.d.ts +1 -1
  291. package/dist/workspace/attached-computers.d.ts +41 -0
  292. package/dist/workspace/attached-computers.js +114 -0
  293. package/dist/workspace/computer-deps.d.ts +16 -9
  294. package/dist/workspace/computer-deps.js +19 -7
  295. package/dist/workspace/computer-for-claim.d.ts +17 -8
  296. package/dist/workspace/computer-for-claim.js +62 -21
  297. package/dist/workspace/computer-hold.d.ts +11 -27
  298. package/dist/workspace/computer-hold.js +36 -56
  299. package/dist/workspace/computer-ledger.d.ts +3 -1
  300. package/dist/workspace/computer-ledger.js +4 -0
  301. package/dist/workspace/computer-mcp.d.ts +25 -0
  302. package/dist/workspace/computer-mcp.js +41 -0
  303. package/dist/workspace/computer-ports.d.ts +4 -13
  304. package/dist/workspace/computer-ports.js +4 -107
  305. package/dist/workspace/computer-script.d.ts +37 -0
  306. package/dist/workspace/computer-script.js +138 -0
  307. package/dist/workspace/executors.d.ts +1 -1
  308. package/dist/workspace/index.d.ts +4 -2
  309. package/dist/workspace/index.js +3 -1
  310. package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
  311. package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
  312. package/dist/workspace/resolve-computer.d.ts +3 -0
  313. package/dist/workspace/resolve-computer.js +8 -2
  314. package/dist/workspace/run-tools.d.ts +32 -15
  315. package/dist/workspace/run-tools.js +23 -30
  316. package/package.json +19 -16
  317. package/templates/market-monitor/agent.md +1 -1
  318. package/dist/console/assets/index-BI4Byidu.js +0 -550
  319. package/dist/console/assets/index-C19gUF2n.css +0 -1
  320. package/dist/run-db.d.ts +0 -53
  321. package/dist/run-db.js +0 -116
  322. package/dist/workflow/readers.d.ts +0 -36
  323. package/dist/workflow/readers.js +0 -145
  324. package/dist/workflow/wal.d.ts +0 -11
  325. package/dist/workflow/wal.js +0 -106
@@ -13,6 +13,7 @@
13
13
  // merge's call merges once.
14
14
  import { BACKGROUND_CONTEXT, withAbortSignal } from "@earendil-works/chord/context";
15
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
+ import { GENERAL_NO_BUDGET, GENERAL_THRESHOLD, ONE_CASE } from "../learn/general.js";
16
17
  import { CONTRADICTED_REASON, CONTRADICTED_TWICE_REASON, CONTRADICTION_ASK, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "../learn/grade.js";
17
18
  import { mergedNote, parseNoteFile, ruleOf } from "../learn/notes.js";
18
19
  import { learnedPlace } from "../learn/skills.js";
@@ -26,6 +27,32 @@ export const GRADE_MAX_TOKENS = 16_000;
26
27
  /** A folder the merge could not reach (the workspace or its exec down): the run parks and is retried after this, doubling
27
28
  * per try up to the last. */
28
29
  export const UNAVAILABLE_BACKOFF_MS = [30_000, 120_000, 600_000, 1_800_000];
30
+ /** A grader call its learning run's cap refused before it was sent (learning-ask.ts bookedAsk: the run's cap left, its
31
+ * launch's max_cost_usd): nothing of it was spent, and the grade is skipped, said so (said.noRoomToGrade), never run past
32
+ * the cap, never a failure. `forGood`: no room could ever send it (its spend or price unknown), not only none now. */
33
+ export class GradeOverCap extends Error {
34
+ forGood;
35
+ booked;
36
+ /** `booked`: the grade's records when it was refused (GradeBooked), what it spent before it. */
37
+ constructor(message, forGood, booked) {
38
+ super(message);
39
+ this.forGood = forGood;
40
+ this.booked = booked;
41
+ this.name = "GradeOverCap";
42
+ }
43
+ }
44
+ /** A generality check its learning run's cap refused before any of its requests left (learning-dispatch.ts general: its
45
+ * worst case over the cap left): nothing of it was sent or spent, and it is skipped as `unchecked` "no_budget"
46
+ * (GENERAL_NO_BUDGET), said so, the grader then judged against the cap on its own. `forGood`: no room could ever send it
47
+ * (its provider's price unknown here), not only none now. */
48
+ export class GeneralOverCap extends Error {
49
+ forGood;
50
+ constructor(message, forGood) {
51
+ super(message);
52
+ this.forGood = forGood;
53
+ this.name = "GeneralOverCap";
54
+ }
55
+ }
29
56
  const ROOT = ROOT_CONVERSATION_ID;
30
57
  /** The graded item a proposal's file is judged as (grade.ts itemOf): a draft's README.md with its workflow.json, every
31
58
  * other file as itself. */
@@ -130,7 +157,7 @@ const itemsByFile = (verdict) => {
130
157
  * the origin its item gives (`you` for the user's own words, else the run's) and held for its owner's OK when its item
131
158
  * is pending; a skill's SKILL.md or a draft's README.md held when its item is (a draft's workflow.json is held by its
132
159
  * README); and the seed the source run started from, so a skill's or draft's file changed on main since is a conflict. */
133
- export function mergeChangeOf(runId, merging, verdict, graded) {
160
+ export function mergeChangeOf(runId, merging, verdict, graded, round = 1) {
134
161
  const judged = itemsByFile(verdict);
135
162
  const notes = merging.notes.map(({ file, text }) => ({ path: file, text: mergedNote(text, { origin: judged.get(file)?.origin ?? "run" }) }));
136
163
  const files = (merging.files ?? []).map(({ file, text }) => ({ path: file, text }));
@@ -142,7 +169,7 @@ export function mergeChangeOf(runId, merging, verdict, graded) {
142
169
  // main already holds the same rule of as a note (dropped unsaid), so no old skill stays served beside its note.
143
170
  const retire = verdict.items.flatMap((item) => (item.note && (item.keep || item.why === SAME_NOTE) && learnedPlace(item.file)?.kind === "skill" ? [{ skill: item.file, note: item.note.file, rule: ruleOfText(item.note.file, item.note.text) }] : []));
144
171
  return {
145
- kind: "merge", runId, reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
172
+ kind: "merge", runId, ...(round > 1 ? { round } : {}), reason: verdict.reason || "The grader kept every new note.", files: [...notes, ...files],
146
173
  ...(held.length ? { held } : {}), graded, ...(merging.seed ? { seed: merging.seed } : {}), ...(retire.length ? { retire } : {}),
147
174
  };
148
175
  }
@@ -278,7 +305,8 @@ export function createLearningLoop(learning) {
278
305
  await append(KINDS.learningDropped, { source: "", reason: "no_source", detail: said.stopped(STOPPED.notChecked) }, "failed");
279
306
  return { state: "failed", error: { code: "learning_no_source", message: "the learning run names no run that learned" } };
280
307
  }
281
- const kept = await learning.proposal(source.runId);
308
+ const round = source.round ?? 1;
309
+ const kept = await learning.proposal(source.runId, round);
282
310
  if (!kept) {
283
311
  await append(KINDS.learningDropped, { source: source.runId, reason: "no_proposal", detail: said.stopped(STOPPED.notChecked) }, "ended");
284
312
  return { state: "ended" };
@@ -311,22 +339,131 @@ export function createLearningLoop(learning) {
311
339
  // A note named like one main holds now is settled alone, out of the grade (readMain's `taken`); the rest is
312
340
  // graded. Nothing left to grade keeps nothing.
313
341
  const taken = new Map((main.taken ?? []).map(({ path, reason }) => [path, reason]));
314
- const grading = proposal.notes.filter(({ file }) => !taken.has(file));
342
+ let grading = proposal.notes.filter(({ file }) => !taken.has(file));
315
343
  const settledItems = [...taken].map(([file, reason]) => ({ file, keep: false, question: "Duplicate", why: reason === "same" ? SAME_NOTE : NOTE_NAME_TAKEN(file.replace(/\.md$/, "")) }));
344
+ // What the grader spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
345
+ // added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
346
+ let usd = 0;
347
+ let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
348
+ // What the generality pre-check's Jev requests spent (its kept dollars, null once unknown), outside the
349
+ // grader's records, and the most they may have spent (`beside`: those dollars, else their worst case), which
350
+ // each grader call's room under the cap leaves out. The grade ends with both: Jev's and the grader's.
351
+ let checkUsd = 0;
352
+ let beside = 0;
353
+ const spent = () => (checkUsd === null || usd === null ? null : checkUsd + usd);
354
+ // The generality pre-check: a note Jev scores under the bar rests on its one input, and is dropped before the
355
+ // grader reads it, its why said with the grader's items. Jev down or not set up here: every note is graded.
356
+ let screened = false;
357
+ // Why the check could not run, kept on the grade's (or the drop's) entry: never a silent skip.
358
+ let unchecked;
359
+ if (grading.length && learning.general) {
360
+ const threshold = learning.generalThreshold ?? GENERAL_THRESHOLD;
361
+ const input = proposal.asked?.[0] ?? proposal.triggered?.[0]?.text;
362
+ // The check is paid and Jev dedupes none, so it is made durable as the grade's ask is (learning-ask.ts
363
+ // bookedAsk): marked sent before its requests leave, and its end kept before the grader starts. A restart
364
+ // reuses a check that ended, paying nothing again; one an earlier attempt sent with no end after it was cut,
365
+ // what it spent is unknown (null, as a cut grade request is booked before it is asked again), and it is
366
+ // asked again with that unknown kept.
367
+ let ended = [...entries].reverse().find((entry) => entry.kind === KINDS.learningGeneral)?.data;
368
+ if (!ended) {
369
+ const sentMarks = entries.filter((entry) => entry.kind === KINDS.learningGeneralSent);
370
+ const cut = sentMarks.length > 0;
371
+ if (cut)
372
+ learning.log?.(`learning run ${claim.runId}: a generality check an earlier attempt sent was cut, so what it spent is unknown; it is asked again`);
373
+ // Under a cap: the most the cut attempts' requests may have spent (each mark's worst case), and this one's.
374
+ const cutHeld = sentMarks.reduce((sum, entry) => sum + (entry.data?.held ?? 0), 0);
375
+ let sentHeld = 0;
376
+ let checked;
377
+ let failed;
378
+ let overCap;
379
+ try {
380
+ checked = await learning.general(grading, { ...(source.instructions ? { job: source.instructions } : {}), ...(input !== undefined ? { input } : {}) }, AbortSignal.any([deps.signal, stopAsk.signal]), source.runId, async (held) => {
381
+ sentHeld += held ?? 0;
382
+ await append(KINDS.learningGeneralSent, { source: source.runId, ...(held !== undefined ? { held } : {}) });
383
+ await deps.flush();
384
+ }, cutHeld);
385
+ }
386
+ catch (error) {
387
+ // Cut by a stop, a lost claim or a shutdown: what it sent spent what nobody knows. A stop row ends the run
388
+ // stopped with that unknown; otherwise nothing more is written, and the next attempt finds it sent with no
389
+ // end, books it unknown and asks again.
390
+ if (stopped || deps.signal.aborted) {
391
+ spend = null;
392
+ return (await halted()) ?? { state: "interrupted" };
393
+ }
394
+ // No room under the run's cap for its worst case: nothing sent, skipped, said so (never silent), and the
395
+ // grader judged against the cap on its own.
396
+ if (error instanceof GeneralOverCap)
397
+ overCap = error;
398
+ else {
399
+ // Its requests were sent and one failed: what they spent is unknown, never 0 (as an ask that fails is).
400
+ // Its error is kept and logged cut of the runner's secrets (LoopDeps.redact).
401
+ const message = error?.message ?? String(error);
402
+ failed = deps.redact ? deps.redact(message) : message;
403
+ learning.log?.(`learning run ${claim.runId}: the generality check could not run, so the grader reads every note: ${failed}`);
404
+ }
405
+ }
406
+ const held = cutHeld + sentHeld;
407
+ const bound = held > 0 ? { held } : {};
408
+ if (checked)
409
+ ended = { source: source.runId, scores: checked.scores, usd: cut ? null : checked.usd, ...bound };
410
+ else if (overCap) {
411
+ learning.log?.(`learning run ${claim.runId}: the generality check has no room under the cap (${overCap.message}), so the grader reads every note`);
412
+ ended = { source: source.runId, unchecked: GENERAL_NO_BUDGET, usd: cut ? null : 0, ...bound };
413
+ }
414
+ else if (failed !== undefined)
415
+ ended = { source: source.runId, unchecked: failed, usd: null, ...bound };
416
+ else if (cut)
417
+ ended = { source: source.runId, unchecked: "no Jev is set up on this host now", usd: null, ...bound };
418
+ // Kept, durably, before the grader starts: a restart from here on asks Jev nothing.
419
+ if (ended) {
420
+ await append(KINDS.learningGeneral, ended);
421
+ await deps.flush();
422
+ }
423
+ }
424
+ if (ended) {
425
+ checkUsd = ended.usd;
426
+ beside = ended.usd ?? ended.held ?? 0;
427
+ if (ended.unchecked !== undefined)
428
+ unchecked = ended.unchecked;
429
+ if (ended.scores) {
430
+ screened = true;
431
+ const scores = ended.scores;
432
+ const below = grading.filter(({ file }) => typeof scores[file] === "number" && scores[file] < threshold);
433
+ settledItems.push(...below.map(({ file }) => ({ file, keep: false, question: "General", why: ONE_CASE(scores[file], threshold) })));
434
+ grading = grading.filter((note) => !below.includes(note));
435
+ }
436
+ }
437
+ }
438
+ // The notes the graded ones supersede, of those main gave: a dropped note's are not the grade's.
439
+ const replacing = new Set(grading.flatMap((note) => { const parsed = parseNoteFile(note.file, note.text); return Array.isArray(parsed) ? [] : parsed.supersedes; }));
440
+ const superseded = main.superseded.filter(({ file }) => replacing.has(file));
316
441
  if (!grading.length && !proposal.files?.length) {
317
- const verdict = { merge: false, reason: "Every new note is named like one the agent holds now.", items: settledItems };
318
- await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)) }, "ended");
442
+ const verdict = { merge: false, reason: settledItems.some(({ question }) => question === "General") ? "No new note holds beyond the one input it came from, or each is named like one the agent holds now." : "Every new note is named like one the agent holds now.", items: settledItems };
443
+ // A proposal the generality check emptied is recorded as a grade (its verdict, each item's why, what the check
444
+ // spent) before it is dropped, so the run's learning reads why each note was left out.
445
+ if (screened)
446
+ await append(KINDS.learningGraded, { source: source.runId, verdict, usd: spent(), tokens, graded: main.graded });
447
+ await append(KINDS.learningDropped, { source: source.runId, reason: "grader", detail: notKept(verdict, lostOf(proposal)), usd: spent(), tokens }, "ended");
319
448
  return { state: "ended" };
320
449
  }
321
450
  const items = gradedItems(grading, (proposal.files ?? []));
322
451
  const prompt = gradePrompt({
323
- run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded: main.superseded, proposed: grading,
452
+ run: source.runId, ...(source.instructions ? { instructions: source.instructions } : {}), active: main.active, superseded, proposed: grading,
324
453
  ...(proposal.files?.length ? { files: proposal.files } : {}), ...(proposal.dryRuns ? { dryRuns: proposal.dryRuns } : {}), ...(proposal.drafted?.length ? { drafted: proposal.drafted } : {}), ...(proposal.asked ? { asked: proposal.asked } : {}), ...(proposal.triggered ? { triggered: proposal.triggered } : {}), ...(proposal.held ? { held: proposal.held } : {}),
325
454
  });
326
- // What the grade spends, as the server's grade counted it (grade.ts counter): each ask's dollars and tokens
327
- // added, either unknown (null) once any ask's is, and an ask that fails spent what nobody knows.
328
- let usd = 0;
329
- let tokens = { input: 0, cache_read: 0, cache_write: 0, output: 0 };
455
+ /** The asks of this attempt that answered: the records holding more requests than these is an earlier attempt's. */
456
+ let answered = 0;
457
+ // Once an ask read the grade's records (`booked`), its dollars are theirs: an earlier attempt's requests counted too.
458
+ const fromRecords = (booked) => {
459
+ if (!booked)
460
+ return;
461
+ usd = booked.usd;
462
+ // A request an earlier attempt sent (a restart before the grade was saved): its dollars are in the records,
463
+ // its tokens in nothing this attempt read, so they are unknown, never none.
464
+ if (booked.turns > answered)
465
+ tokens = null;
466
+ };
330
467
  // `again`: what the grade is told after its last answer, below the same prompt.
331
468
  const ask = async (again) => {
332
469
  // Stopped before this ask: nothing is sent, so nothing of it is spent (what it spent stays as it was).
@@ -335,16 +472,24 @@ export function createLearningLoop(learning) {
335
472
  const timer = AbortSignal.timeout(GRADE_TIMEOUT_MS);
336
473
  let answer;
337
474
  try {
338
- answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
475
+ answer = await learning.ask({ prompt: again ? `${prompt}\n\n${again}` : prompt, maxTokens: GRADE_MAX_TOKENS, ...(beside > 0 ? { beside } : {}) }, AbortSignal.any([deps.signal, timer, stopAsk.signal]), { journal: () => deps.journal(claim), flush: () => deps.flush() });
339
476
  }
340
477
  catch (error) {
341
- usd = null;
342
- tokens = null;
478
+ // A call the cap refused was never sent: it spent nothing, and what the grade spent before it stands, as its
479
+ // records hold it (an earlier attempt's included).
480
+ if (error instanceof GradeOverCap)
481
+ fromRecords(error.booked);
482
+ else {
483
+ usd = null;
484
+ tokens = null;
485
+ }
343
486
  throw error;
344
487
  }
488
+ answered += 1;
345
489
  usd = usd === null || answer.usd === null || !Number.isFinite(answer.usd) ? null : usd + answer.usd;
346
490
  const more = answer.tokens ?? null;
347
491
  tokens = tokens === null || more === null ? null : { input: tokens.input + more.input, cache_read: tokens.cache_read + more.cache_read, cache_write: tokens.cache_write + more.cache_write, output: tokens.output + more.output };
492
+ fromRecords(answer.booked);
348
493
  return answer.text;
349
494
  };
350
495
  let verdict;
@@ -362,19 +507,26 @@ export function createLearningLoop(learning) {
362
507
  }
363
508
  }
364
509
  catch (error) {
365
- // What the asks spent: a cut one's unknown (null), kept on a stopped run's row as on a dropped one's.
366
- spend = usd;
510
+ // What the asks spent (and the check before them): a cut one's unknown (null), kept on a stopped run's row as
511
+ // on a dropped one's.
512
+ spend = spent();
367
513
  const end = await halted();
368
514
  if (end)
369
515
  return end;
370
- await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd, tokens }, "ended");
516
+ // No room under the run's cap for the grade (a call the cap refused): skipped, said so, with what it spent
517
+ // before (an earlier ask's), never a failure and never past the cap.
518
+ if (error instanceof GradeOverCap) {
519
+ await append(KINDS.learningDropped, { source: source.runId, reason: "no_budget", detail: error.forGood ? said.gradeUncapped : said.noRoomToGrade, usd: spent(), tokens, ...(unchecked !== undefined ? { unchecked } : {}) }, "ended");
520
+ return { state: "ended" };
521
+ }
522
+ await append(KINDS.learningDropped, { source: source.runId, reason: "grade_failed", detail: said.stopped(STOPPED.noReview), usd: spent(), tokens, ...(unchecked !== undefined ? { unchecked } : {}) }, "ended");
371
523
  void error;
372
524
  return { state: "ended" };
373
525
  }
374
526
  if (settledItems.length)
375
527
  verdict = { ...verdict, items: [...verdict.items, ...settledItems] };
376
- graded = { source: source.runId, verdict, usd, tokens, graded: main.graded };
377
- spend = usd;
528
+ graded = { source: source.runId, verdict, usd: spent(), tokens, graded: main.graded, ...(unchecked !== undefined ? { unchecked } : {}) };
529
+ spend = graded.usd;
378
530
  await append(KINDS.learningGraded, graded);
379
531
  // The verdict is durable before the merge, its side effect.
380
532
  await deps.flush();
@@ -393,7 +545,7 @@ export function createLearningLoop(learning) {
393
545
  let onMain = {};
394
546
  let already = false;
395
547
  try {
396
- const merge = await learning.merged(ws, source.runId, notePaths);
548
+ const merge = await learning.merged(ws, source.runId, notePaths, source.round);
397
549
  already = merge !== undefined;
398
550
  onMain = merge ? merge.texts : notePaths.length ? await learning.mainTexts(ws, notePaths) : {};
399
551
  }
@@ -405,7 +557,7 @@ export function createLearningLoop(learning) {
405
557
  const taken = already ? { verdict: oneItemAFile(proposal, graded.verdict), replace: [], graded: {} } : takenOnMain(proposal, graded.verdict, onMain);
406
558
  const verdict = taken.verdict;
407
559
  const merging = keptOf(proposal, verdict);
408
- const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded });
560
+ const change = mergeChangeOf(source.runId, merging, verdict, { ...graded.graded, ...taken.graded }, round);
409
561
  // Nothing new left to merge: dropped, unless the grader kept a re-filed skill whose rule main already holds as a
410
562
  // note (takenOnMain's SAME_NOTE). Its old SKILL.md is still retired (mergeChangeOf's retire), in a write of that
411
563
  // alone, so no old skill stays served beside the note.
@@ -17,7 +17,14 @@ export interface LearningSeedLay {
17
17
  readonly log: (line: string) => void;
18
18
  /** False for a run of a revision that says `learning: "notes"`: its notes and skills are laid, never a learned workflow. */
19
19
  readonly workflows?: false;
20
+ /** The notes its # Learned section names in no way, over the learning budget (the launch's `notesLeftOut`), by file:
21
+ * said in the run's log, so a run that read only some of what its agent learned says which it did not. */
22
+ readonly notesLeftOut?: readonly string[];
20
23
  }
24
+ /** The most notes the log line names: past it, it says how many more. */
25
+ export declare const LEFT_OUT_NAMED = 100;
26
+ /** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
27
+ export declare const notesLeftOutLine: (files: readonly string[] | undefined) => string | undefined;
21
28
  /** What the claim laid of the run's seed: the seed it read, the learned skills' files it laid, by their paths under
22
29
  * `.agents/skills/`, for the skill list the run's harness is handed beside the revision's own, and the learned workflows
23
30
  * the run's learned_workflow tool runs, cut of the server's secrets as the skills are (none of either when the lay
@@ -1,4 +1,14 @@
1
1
  import { chooseSkills, chooseWorkflows, layLearned, LEARNED_DIR, laySkills, readerOf, seedFrom, takeSkills } from "../learning.js";
2
+ /** The most notes the log line names: past it, it says how many more. */
3
+ export const LEFT_OUT_NAMED = 100;
4
+ /** The run's log line for the notes its # Learned section leaves out, or undefined for none. */
5
+ export const notesLeftOutLine = (files) => {
6
+ if (!files?.length)
7
+ return undefined;
8
+ const named = files.slice(0, LEFT_OUT_NAMED).join(", ");
9
+ const more = files.length > LEFT_OUT_NAMED ? `, and ${files.length - LEFT_OUT_NAMED} more` : "";
10
+ return `starts without ${files.length} of the notes its agent learned in its # Learned section, over the learning budget (the notes that bear most on it are given whole; the rest stay in ${LEARNED_DIR}/): ${named}${more}`;
11
+ };
2
12
  const message = (error) => (error instanceof Error ? error.message : String(error));
3
13
  /** What a claim laid of a run's learning seed, by name, as the adapter loop records it (KINDS.learningLaid): each learned
4
14
  * skill whose files it laid, and each learned workflow it handed the tool; none when nothing was laid. */
@@ -29,6 +39,9 @@ export async function layLearningSeed(lay) {
29
39
  await laySkills(lay.work, taken, made);
30
40
  for (const path of seed.skipped)
31
41
  lay.log(`its learning folder's ${path} was not read`);
42
+ const leftOut = notesLeftOutLine(lay.notesLeftOut);
43
+ if (leftOut)
44
+ lay.log(leftOut);
32
45
  for (const name of left)
33
46
  lay.log(`starts without the skill ${name} its agent learned: it is over what is left of the learned skills' budget, or holds a secret`);
34
47
  const workflows = lay.workflows === false ? { flows: [], left: [] } : chooseWorkflows(seed, shown);
@@ -95,6 +95,7 @@ export function withLiveTicker(store, createLoop, options = {}) {
95
95
  },
96
96
  command: (command) => loop.command(command),
97
97
  stop: (reason) => loop.stop(reason),
98
+ keepsComputer: (reason) => loop.keepsComputer?.(reason) ?? false,
98
99
  };
99
100
  },
100
101
  close: async () => {
@@ -34,11 +34,14 @@ export type EndOfRunTurn = (input: {
34
34
  /** The run was cut before it could look back: by a person's stop (`stopped`), by one during the end-of-run turn
35
35
  * (`stopped-looking`), or by a fault (`faulted`). The step must not call `ask`: it returns only what a cut run keeps. */
36
36
  readonly cut?: "stopped" | "stopped-looking" | "faulted";
37
- /** `again`: the turn asked once more in the same session (its first answer out of format), as its own request. */
37
+ /** `again`: the turn asked once more in the same session (its first answer out of format), as its own request.
38
+ * `round`: which end of the run this is (1, its first, when absent): an end after a follow-up opened the run again is
39
+ * a later round, asked of the model anew under a request of its own. */
38
40
  ask(prompt: string, opts: {
39
41
  readonly origin: "reflect";
40
42
  readonly deadlineMs: number;
41
43
  readonly again?: true;
44
+ readonly round?: number;
42
45
  }): Promise<EndOfRunAnswer>;
43
46
  readonly signal: AbortSignal;
44
47
  }) => Promise<{
@@ -121,6 +124,10 @@ export interface Loop {
121
124
  command(command: Command): Promise<CommandOutcome>;
122
125
  /** Aborts the in-flight turn; resolves once the loop will write nothing more. */
123
126
  stop(reason: StopReason): Promise<void>;
127
+ /** Whether a person's stop `reason` ends only the agent, the run keeping its computer for its owner (a held computer,
128
+ * computer-held.ts): the runner then goes on handing it rows (the owner's calls and release) until it ends. Absent:
129
+ * never. */
130
+ keepsComputer?(reason: StopReason): boolean;
124
131
  }
125
132
  export interface LoopDeps {
126
133
  /** The run's journal (store.journal(claim)) behind the runner's own fence: after a claim-lost stop, a commit is
@@ -1,4 +1,4 @@
1
- import type { Context } from "@earendil-works/chord";
1
+ import type { Context } from "@earendil-works/chord/context";
2
2
  import { type ConversationId, type EntryRecord, type StorageWrite } from "@earendil-works/pi-durable";
3
3
  import type { KernelHooks, ToolCall } from "./conformance/subject.js";
4
4
  import { type Command, type HeldState, type Journal, type LoopDeps } from "./loop-contract.js";
@@ -29,6 +29,10 @@ type Expected = {
29
29
  readonly run?: Staged["run"];
30
30
  readonly also?: Staged["also"];
31
31
  readonly take?: readonly number[];
32
+ readonly answer?: {
33
+ readonly command: number;
34
+ readonly value: unknown;
35
+ };
32
36
  };
33
37
  /**
34
38
  * The run's journal with the loop's staging matched to commits. stage() replaces what was staged, so the loop never
@@ -94,7 +94,8 @@ function merge(all) {
94
94
  // call where that record's batch was refused.
95
95
  const effect = all.find(({ expected }) => expected.run !== undefined || (expected.also ?? []).length > 0)?.at.id;
96
96
  // Each take keyed to the record its expectation matched: the store writes it only with that record's batch.
97
- const take = all.flatMap(({ expected, at }) => (expected.take ?? []).map((command) => ({ command, effect: at.id })));
97
+ // An answer is a value for one of the expectation's own take ids: it rides on that StagedTake.
98
+ const take = all.flatMap(({ expected, at }) => (expected.take ?? []).map((command) => (expected.answer?.command === command ? { command, effect: at.id, answer: expected.answer.value } : { command, effect: at.id })));
98
99
  return { ...(run ? { run } : {}), ...(also.length ? { also } : {}), ...(effect !== undefined && (run || also.length) ? { effect } : {}), ...(take.length ? { take } : {}) };
99
100
  }
100
101
  /** Whether `batches` write an entry of `kind` whose data `test` accepts. */
@@ -1,5 +1,6 @@
1
1
  import { type Store } from "../store/index.js";
2
- import { type ComputerDeps } from "../workspace/computer-deps.js";
2
+ import { type KeyEnv } from "../key-meta.js";
3
+ import { type ComputerDeps, type ComputerDepsOptions } from "../workspace/computer-deps.js";
3
4
  import type { LoopFactory } from "./loop-contract.js";
4
5
  import { type Runner, type RunnerEvent, type RunnerMemory } from "./runner.js";
5
6
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
@@ -61,6 +62,17 @@ export declare function openRunnerStore(dataDir: string, env: NodeJS.ProcessEnv,
61
62
  * but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
62
63
  * a spread of the object or a spawn given it carries none. */
63
64
  export declare function runEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
65
+ /** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
66
+ * of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
67
+ * runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
68
+ * provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
69
+ * --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
70
+ * reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
71
+ export declare const runnerComputers: (store: Store, env: KeyEnv, sealKey: Buffer, own?: Pick<ComputerDepsOptions, "kinds" | "load" | "dockerPaths" | "hostAddresses" | "hostWhy" | "hub">) => {
72
+ computerForClaim: typeof import("../workspace/computer-deps.js").claimComputer;
73
+ computerDeps: ComputerDeps;
74
+ factories: import("../computer-keys.js").ProviderFactories;
75
+ };
64
76
  /** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
65
77
  * process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
66
78
  * run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
@@ -21,18 +21,23 @@ import { claimInstallsStopped } from "../harness-install.js";
21
21
  import { HARNESS_TABLE_ENV } from "../harness-table.js";
22
22
  import { maxRunsOf } from "../host.js";
23
23
  import { FAUX_ENV, FAUX_PREFIX, withoutFaux } from "../model.js";
24
- import { durationMs } from "../print.js";
24
+ import { durationMs, runLine } from "../print.js";
25
25
  import { bootSealKey } from "../seal-key.js";
26
26
  import { handedSecret, SECRET_NAMES, secret } from "../secrets.js";
27
27
  import { migrationsIn, openStore, SchemaVersionUnknown, storePlace, storeTarget } from "../store/index.js";
28
28
  import { SCHEMA_VERSION } from "../store/schema.js";
29
29
  import { SEAL_KEY_ENV, sealKeyOf } from "../tool-keys.js";
30
+ import { claimViewOpener } from "../computer-live.js";
31
+ import { runnerLiveOf } from "../live-reach.js";
32
+ import { envValue } from "../key-meta.js";
33
+ import { fauxComputers } from "../faux-computers.js";
30
34
  import { computerDepsFrom } from "../workspace/computer-deps.js";
31
35
  import { startJanitor } from "../workspace/computer-janitor.js";
32
36
  import { createDispatchLoop } from "./dispatch.js";
33
37
  import { resolveRunnerLoop } from "./harness-loops.js";
34
38
  import { routeOf } from "./model-route.js";
35
39
  import { runnerMemory } from "./memory-claim.js";
40
+ import { sweepEndedScratch } from "./scratch-sweep.js";
36
41
  import { RUNNER_RENEW_EVERY_MS, runnerName, startRunner } from "./runner.js";
37
42
  export { RUNNER_RENEW_EVERY_MS } from "./runner.js";
38
43
  /** A store this runner cannot use, or arguments it cannot take, in words a person starting it can act on. */
@@ -84,6 +89,15 @@ export function runEnv(env = process.env) {
84
89
  }
85
90
  return out;
86
91
  }
92
+ /** The run's computer at its claim, composed once for a runner (workspace/computer-deps.ts computerDepsFrom), the live view
93
+ * of a desktop or a phone (computer-live.ts openClaimView) with it: runnerLoop's, runnerBeside's and a test's in-process
94
+ * runner's. `own`: where Docker has the data directory and this host's addresses, and a test's kind registry and
95
+ * provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
96
+ * --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
97
+ * reads them (server.ts computerReady): a run on the faux desktop is claimed, and its live view opened, the real way. */
98
+ export const runnerComputers = (store, env, sealKey, own = {}) =>
99
+ // A runner on another host than its server (AGENTRUN_RUNNER_LIVE_HOST): its viewers answer there (live-reach.ts).
100
+ computerDepsFrom({ env, store, sealKey, openComputerView: claimViewOpener(runnerLiveOf(env, sealKey)), ...(envValue(env, FAUX_ENV) ? { faux: fauxComputers() } : {}), ...own });
87
101
  /** The beside-runner's environment (the CLI start's server-and-runner): runEnv of `env` with every test switch this
88
102
  * process inherited taken out (AGENTRUN_SERVE_FAUX*, the harness table: a leftover in a shell would otherwise reach a
89
103
  * run without --faux, as the server's own withoutFaux keeps it from the server), then `switches`, the ones this start
@@ -105,13 +119,17 @@ export function runnerLoop(store, dataDir, env = process.env, booted) {
105
119
  if (!sealKey)
106
120
  throw new RunnerRefused(`A runner needs the server's seal key (${SEAL_KEY_ENV}): start it through the server's launcher, which hands it over.`);
107
121
  const runs = runEnv(env);
108
- // The run's computer at its claim, composed once (workspace/computer-deps.ts): none for the runner's place, a box's
109
- // computer by the agent's setting, its keys read from the run environment first, then the store's sealed rows; a
110
- // Docker computer's mounts by where this process's Docker has the data directory (box-paths.ts), read once.
111
- const computers = computerDepsFrom({ env: runs, store, sealKey, dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
122
+ // The run's computer at its claim, composed once (runnerComputers): none for the runner's place, a box's computer by the
123
+ // agent's setting, its keys read from the run environment first, then the store's sealed rows; a Docker computer's
124
+ // mounts by where this process's Docker has the data directory (box-paths.ts), read once; a desktop's or a phone's live
125
+ // view opened with it.
126
+ const computers = runnerComputers(store, runs, sealKey, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH) });
112
127
  const deps = {
113
128
  env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey, routeOf,
114
129
  computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps,
130
+ // A run's log lines (a learning run's skipped generality check, a sweep that failed) on the runner's stderr, as its
131
+ // warnings are.
132
+ log: (line) => void process.stderr.write(`agentrun-serve runner: ${line}\n`),
115
133
  };
116
134
  return { createLoop: createDispatchLoop({ launchOf: (runId) => store.runs.launch(runId), resolve: resolveRunnerLoop(deps) }), computers: computers.computerDeps, env: runs };
117
135
  }
@@ -177,6 +195,8 @@ export async function startRunnerProcess(options) {
177
195
  // warnings, said where the runner says its others (warn: stderr unless a test gives its own).
178
196
  if (options.janitor && typeof parts !== "function")
179
197
  janitor = startJanitor({ store, computers: parts.computers, env: parts.env, log: warn });
198
+ // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts), said as warnings.
199
+ await sweepEndedScratch(store, options.dataDir, { log: warn });
180
200
  runner = startRunner({
181
201
  store,
182
202
  createLoop,
@@ -333,6 +353,8 @@ function said(name, event) {
333
353
  return `Runner ${name} released ${event.runId} (${event.end})`;
334
354
  if (event.type === "claim-lost")
335
355
  return `Runner ${name} lost its claim on ${event.runId} (${event.why})`;
356
+ if (event.type === "started" || event.type === "ended")
357
+ return runLine(event);
336
358
  return undefined;
337
359
  }
338
360
  /** `agentrun-serve runner ...`: the exit code. 2: bad arguments; 3: a store schema this runner does not know (or none
@@ -27,15 +27,19 @@ export interface McpClaimOptions {
27
27
  now?: () => number;
28
28
  /** The authorization servers' network (mcp-oauth.ts). */
29
29
  network?: OAuthNetwork;
30
+ /** Whether this runner may reach a loopback address (McpForClaimOptions.loopback): a refresh's request to a loopback
31
+ * authorization server is sent only then. Absent, never. */
32
+ loopback?: boolean;
30
33
  /** For a github_app server (auth github_app, nothing sealed): the server's GitHub App mint and the run's repository
31
34
  * (runner/mcp-github.ts). None: such a server's calls are refused in words. */
32
35
  githubApp?: GithubAppAccess;
33
36
  /** For tests only (no environment or CLI flag maps onto it): the one origin a github_app server may have, a fake for
34
37
  * GitHub's hosted MCP (GITHUB_MCP_ORIGIN). */
35
38
  githubMcpOrigin?: string;
36
- /** Each credential value a per_run server's handed headers carry (each header's value, and a Bearer's bare token),
37
- * handed to the run's redactors as the claim opens them: at the claim, and at each fresh() after a message hands the
38
- * run a new one, before any call carries it. */
39
+ /** The run's redactors (runner/redact.ts, the spec's `cut`): every credential value this step hands the gateway (each
40
+ * header's value and a Bearer's bare token: a saved one, a refreshed OAuth token, a minted GitHub App token, a per_run
41
+ * server's handed one at the claim and at each fresh()) is held by them as it is handed over, before any call carries
42
+ * it. None: the gateway's per-call scrub alone. */
39
43
  hold?: (values: string[]) => void;
40
44
  /** For tests: the timer a github_app token's refresh and expiry are armed on. */
41
45
  githubTimer?: GithubTimer;
@@ -50,15 +54,14 @@ export interface McpClaimStep {
50
54
  /** Each pinned server's URL now, with its headers or why they can't be used: the run's gateway's `credentials`, which
51
55
  * it reads at every request, so a refresh or a removal here reaches a gateway already built. */
52
56
  readonly credentials: McpCredentials;
53
- /** Every credential value held, for the redaction set. */
54
- readonly secrets: ReadonlySet<string>;
55
57
  /** Refresh what has expired, and open the credentials again; then confirm the claim. Before a resumed loop's next
56
58
  * model request. */
57
59
  fresh(): Promise<void>;
58
60
  /** Drop every credential held: the loop ended, or the claim is lost. */
59
61
  release(): void;
60
- /** Before each call of `server` (the gateway's beforeCall): a github_app token whose App was disconnected or replaced
61
- * since it was minted is dropped, revoked, and the call refused in words. */
62
+ /** Before each call of `server` (the gateway's beforeCall): its row stamp read (opened again when it changed or its
63
+ * access token near its end refreshed behind the call while still valid, waited on once run out; its entry dropped when it is no longer saved), then a github_app token
64
+ * whose App was disconnected or replaced since it was minted is dropped, revoked, and the call refused in words. */
62
65
  beforeCall(server: string, signal: AbortSignal): Promise<void>;
63
66
  }
64
67
  /** The MCP step of `options.claim`: its pin made or read and checked, its credentials opened (refreshed as due). */