@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
@@ -0,0 +1,61 @@
1
+ import { callRecordOf, unrecorded } from "../computer-calls.js";
2
+ import { PROTOCOL_METHODS } from "../computer-channel.js";
3
+ /** The loop's computer for a claim's (computerForClaim's `computer` and `held`): none for no computer or a browser. */
4
+ export function loopComputerOf(computer, held) {
5
+ if (!computer || computer.kind === "browser")
6
+ return undefined;
7
+ return {
8
+ kind: computer.kind,
9
+ client: computer.computer.client,
10
+ ...("hello" in computer ? { hello: computer.hello } : {}),
11
+ ...(held && held.kind === computer.kind ? { hold: held.hold } : {}),
12
+ };
13
+ }
14
+ /** A computer_call row's call, or why it is refused (a row the server wrote is always one; a hand-made one may not be). */
15
+ export function channelCallOf(command) {
16
+ const body = (command.body ?? {});
17
+ if (typeof body.method !== "string" || !PROTOCOL_METHODS.includes(body.method))
18
+ return { refused: `${JSON.stringify(body.method ?? null)} is not a computer protocol method.` };
19
+ // The params come as one JSON text (computer-channel.ts callComputer): an object, or none.
20
+ let params = {};
21
+ if (body.params !== undefined) {
22
+ try {
23
+ params = typeof body.params === "string" ? JSON.parse(body.params) : undefined;
24
+ }
25
+ catch {
26
+ params = undefined;
27
+ }
28
+ }
29
+ if (!params || typeof params !== "object" || Array.isArray(params))
30
+ return { refused: "The call's params are not a JSON object's text." };
31
+ return { method: body.method, params: params };
32
+ }
33
+ const words = (error) => (error instanceof Error ? error.message : String(error));
34
+ /**
35
+ * Runs `call` on `computer` and answers what came of it; never throws. While a person holds the computer the call waits,
36
+ * as the agent's calls do, and counts as in flight once it runs, so a take asked meanwhile waits for it. `signal` bounds
37
+ * the whole of it (the loop's: CALL_MS, and the claim's): a wait or a call it cuts answers `timeout`, a call whose client
38
+ * failed answers `gone`. The call is no tool call's, so it is recorded on none.
39
+ */
40
+ export async function runChannelCall(computer, call, signal, now = Date.now) {
41
+ const started = performance.now();
42
+ let answer;
43
+ let leave;
44
+ try {
45
+ leave = computer.hold ? await computer.hold.enter(signal) : undefined;
46
+ answer = (await unrecorded(() => computer.client.call(call.method, call.params, { signal })));
47
+ // A client answers its signal's abort with an error answer of its own (the daemon client's), never a throw: the same
48
+ // `timeout` as a wait the signal cut.
49
+ if (!answer.ok && signal.aborted)
50
+ answer = { ok: false, error: { code: "timeout", message: `the call did not end in time: ${words(signal.reason)}` } };
51
+ }
52
+ catch (error) {
53
+ answer = signal.aborted
54
+ ? { ok: false, error: { code: "timeout", message: leave || !computer.hold ? `the call did not end in time: ${words(signal.reason)}` : `a person held the run's computer for the whole of the call's time: ${words(signal.reason)}` } }
55
+ : { ok: false, error: { code: "gone", message: words(error) } };
56
+ }
57
+ finally {
58
+ leave?.();
59
+ }
60
+ return { answer, record: callRecordOf(call.method, call.params, answer, performance.now() - started), at: now() };
61
+ }
@@ -16,7 +16,7 @@ import { fileURLToPath } from "node:url";
16
16
  import { tmpdir } from "node:os";
17
17
  import { join } from "node:path";
18
18
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
19
- import { AnswerTaken, dropPostgresSchema, openPostgresStore, openStore, RunFinal, storeTarget } from "../../store/index.js";
19
+ import { AnswerTaken, dropPostgresSchema, openPostgresStore, openStore, RunFinal, storeTarget, Unanswered } from "../../store/index.js";
20
20
  import { sendCommand } from "../commands.js";
21
21
  import { callsOf, journalRecords, messagesOf } from "../journal-reader.js";
22
22
  import { KINDS, MESSAGE_SENT_AGAIN } from "../journal-kinds.js";
@@ -177,8 +177,21 @@ async function world(subject, t, timing = STEADY) {
177
177
  if (target.kind === "postgres")
178
178
  await dropPostgresSchema(target.url, storeEnv.AGENTRUN_STORE_SCHEMA);
179
179
  });
180
- await server.agents.create({ id: "agent-1", name: "Conformance" }, { id: "rev-1", kind: "agentic", body: { instructions: "Follow the script." } });
181
- await server.runs.create({ id: RUN, agentId: "agent-1", revisionId: "rev-1" });
180
+ // A setup write the store left unanswered (Unanswered: a stalled box, past the commit's bound) is an unknown outcome,
181
+ // never a failure: its row is read, and the write made again only when it did not land.
182
+ const settled = async (write, landed) => {
183
+ try {
184
+ await write();
185
+ }
186
+ catch (error) {
187
+ if (!(error instanceof Unanswered))
188
+ throw error;
189
+ if (!(await landed()))
190
+ await write();
191
+ }
192
+ };
193
+ await settled(() => server.agents.create({ id: "agent-1", name: "Conformance" }, { id: "rev-1", kind: "agentic", body: { instructions: "Follow the script." } }), () => server.agents.get("agent-1"));
194
+ await settled(() => server.runs.create({ id: RUN, agentId: "agent-1", revisionId: "rev-1" }), () => server.runs.get(RUN));
182
195
  /** The command rows a runner has handed to a loop's command(): with the loop, whether or not taken yet. */
183
196
  const handed = new Set();
184
197
  /** Each runner's claims in flight (store.runs.claimMany), by its name: what claimsSettled waits for. */
@@ -206,6 +219,7 @@ async function world(subject, t, timing = STEADY) {
206
219
  get(target, property) {
207
220
  if (property === "runs")
208
221
  return runs;
222
+ // answerOf and watchCommands pass through as every method does: bound to the store.
209
223
  const value = Reflect.get(target, property, target);
210
224
  return typeof value === "function" ? value.bind(target) : value;
211
225
  },
@@ -267,13 +281,56 @@ async function world(subject, t, timing = STEADY) {
267
281
  const answers = entries.entries.filter((entry) => entry.kind === KINDS.answer).map((entry) => entry.data);
268
282
  return { calls: subject.readCalls ? await subject.readCalls(journal, BACKGROUND_CONTEXT) : callsOf(entries), messages: messagesOf(entries), answers };
269
283
  };
284
+ /** A claim whose COMMIT the store left unanswered (Unanswered: it may have landed) holds the run under a lease the case
285
+ * made steady (STEADY), so nothing else would take it back: the runner said so (its poll's error), and that claim is run
286
+ * out (runOut) as a lost one is, once per such word; the runner then claims the run again. */
287
+ // Handled words are counted per source: `events` (this process's runners) and `more` (a runner process's events file).
288
+ // One shared total would lose the child's words once the child exits and its events stop being passed, so a later
289
+ // unanswered claim of the replacement runner would count as already handled and never run out.
290
+ let ranOutHere = 0;
291
+ let ranOutMore = 0;
292
+ const runOutUnknown = (more = []) => {
293
+ // Only a claim's own word (the poll's error): an unanswered renew says the same words while its loop is still held, and
294
+ // running that claim out would take a healthy loop's lease.
295
+ const unanswered = (list) => list.filter((event) => {
296
+ const seen = event;
297
+ return seen.step === "poll" && /did not answer its commit/.test(String(seen.message ?? ""));
298
+ }).length;
299
+ const here = unanswered(events);
300
+ const there = unanswered(more);
301
+ if (here > ranOutHere || there > ranOutMore) {
302
+ ranOutHere = Math.max(ranOutHere, here);
303
+ ranOutMore = Math.max(ranOutMore, there);
304
+ runOut();
305
+ }
306
+ };
270
307
  const ended = (state, ms = 15_000) => until(async () => {
308
+ runOutUnknown();
271
309
  const row = await run();
272
310
  return row.state === state && row.runner === null && row;
273
311
  }, `the run ${state} and released`, ms).catch(async (error) => {
274
312
  const row = await run();
275
313
  throw new Error(`${error.message}; the run is ${row.state} (runner ${row.runner}, epoch ${row.epoch}); the runners said ${JSON.stringify(events)}`);
276
314
  });
315
+ /** Waits for `started` (a tool's first call, the event this case's next step needs), bounded by EVENT_WAIT_MS and naming
316
+ * what never came, with the run and what the runners said. It waits on the real signal, never a bare await: a run that
317
+ * ended without it, or a claim that never reached the tool, fails the case at once, not at the case's 180 s bound.
318
+ * An unanswered claim is run out while it waits (runOutUnknown). */
319
+ const began = async (started, what, ms = EVENT_WAIT_MS) => {
320
+ let done = false;
321
+ void started.then(() => (done = true));
322
+ await until(async () => {
323
+ if (done)
324
+ return true;
325
+ runOutUnknown();
326
+ const row = await run();
327
+ if (["ended", "failed", "stopped"].includes(row.state))
328
+ throw new Error(`the run ${row.state} before ${what}`);
329
+ return false;
330
+ }, what, ms).catch((error) => {
331
+ throw new Error(`${error.message}; the runners said ${JSON.stringify(events)}`);
332
+ });
333
+ };
277
334
  /** The run's timeline as its live view shows it: every stored commit through the live translate (live/translate.ts),
278
335
  * its events through the timeline's own reducer, as the console reads them. */
279
336
  const liveRows = async () => {
@@ -300,7 +357,7 @@ async function world(subject, t, timing = STEADY) {
300
357
  assert.ok(ask, "the run wrote its ask");
301
358
  return String(ask.data.callId);
302
359
  };
303
- return { dir, storeUrl: url, storeEnv, clockFile, runOut, claimsSettled, server, start, run, read, ended, commandRow, askedCall, events, handedOver: (id) => handed.has(id), liveRows };
360
+ return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), liveRows };
304
361
  }
305
362
  /**
306
363
  * The claim's fence, as the stalled process's own events show it: once it went on (`continuedAt`, its lease run out and no
@@ -392,7 +449,8 @@ async function crashThenResume(subject, t, tool, point) {
392
449
  const script = [{ call: tool }, { say: "done" }];
393
450
  const holder = {};
394
451
  await w.start("runner-a", { script, tools, hooks: crashAt(point, holder) }, holder);
395
- await until(() => holder.crashed, `the crash at ${point}`, EVENT_WAIT_MS);
452
+ // An unanswered first claim is run out while it waits: it never reaches the crash point otherwise.
453
+ await until(() => (w.runOutUnknown(), holder.crashed), `the crash at ${point}`, EVENT_WAIT_MS);
396
454
  // The crashed runner's claim runs out (the stores' clock moves past its until), and runner-b takes the run over. First
397
455
  // the claim its poll had in flight when it died settles, on the clock it was sent at (claimsSettled).
398
456
  await w.claimsSettled("runner-a");
@@ -461,7 +519,7 @@ async function processCrashThenResume(subject, t, tool, point, { stall = false }
461
519
  // box paused it, so no real lease has to run out.
462
520
  let continuedAt = 0;
463
521
  if (stall) {
464
- await until(() => childEvents(eventsFile).some((event) => event.type === "stopping"), `the runner process stops at ${point}`, EVENT_WAIT_MS);
522
+ await until(() => (w.runOutUnknown(childEvents(eventsFile)), childEvents(eventsFile).some((event) => event.type === "stopping")), `the runner process stops at ${point}`, EVENT_WAIT_MS);
465
523
  // Its word is not the stop: a SIGCONT sent between the two is lost, and the process stays stopped for good. It goes
466
524
  // on only once the kernel says it is stopped.
467
525
  await until(() => processStopped(child.pid), `the runner process is stopped (its state "T") at ${point}`, EVENT_WAIT_MS);
@@ -474,7 +532,15 @@ async function processCrashThenResume(subject, t, tool, point, { stall = false }
474
532
  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);
475
533
  fenceHeld(childEvents(eventsFile), continuedAt);
476
534
  }
477
- const exit = (await Promise.race([exited, sleep(EVENT_WAIT_MS).then(() => ["timeout", null])]));
535
+ // The process's unanswered first claim (its events file) is run out while the case waits for its death.
536
+ let waiting = true;
537
+ const recovering = (async () => {
538
+ for (const until = Date.now() + EVENT_WAIT_MS; waiting && Date.now() < until; await sleep(50))
539
+ w.runOutUnknown(childEvents(eventsFile));
540
+ return ["timeout", null];
541
+ })();
542
+ const exit = (await Promise.race([exited, recovering]));
543
+ waiting = false;
478
544
  // What the process did, when it did not die where it should: its claims, lost claims, commits (landed or refused, by
479
545
  // epoch), the tool's runs and the run's row.
480
546
  if (exit[1] !== "SIGKILL") {
@@ -609,7 +675,7 @@ const CASES = [
609
675
  const w = await world(subject, t);
610
676
  const { tools, letSlowGo, slowStarted } = suiteTools();
611
677
  await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet });
612
- await slowStarted;
678
+ await w.began(slowStarted, "the slow tool to start");
613
679
  const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "check the totals" } });
614
680
  // One command poll and then some: the steer reaches the loop while the tool runs.
615
681
  await sleep(TIMING.commandPollMs * 4);
@@ -642,7 +708,7 @@ const CASES = [
642
708
  // sent as a turn of its own, that message (the last the person sent).
643
709
  const script = [{ call: "slow" }, { sayLastSteer: true }, ...(steers ? [] : texts.map(() => ({ sayLastSteer: true })))];
644
710
  await w.start("runner-a", { script, tools, hooks: quiet });
645
- await slowStarted;
711
+ await w.began(slowStarted, "the slow tool to start");
646
712
  const rows = [];
647
713
  for (const text of texts)
648
714
  rows.push(await sendCommand(w.server, RUN, { kind: "steer", body: { text } }));
@@ -680,12 +746,12 @@ const CASES = [
680
746
  const script = [{ call: "slow" }, { sayLastSteer: true }, { sayLastSteer: true }, { sayLastSteer: true }];
681
747
  const holder = {};
682
748
  await w.start("runner-a", { script, tools, hooks: crashAt("afterMessageSent", holder) }, holder);
683
- await slowStarted;
749
+ await w.began(slowStarted, "the slow tool to start");
684
750
  const row = await sendCommand(w.server, RUN, { kind: "steer", body: { text } });
685
751
  await until(() => w.handedOver(row.id), "the message handed to the loop mid-turn");
686
752
  letSlowGo();
687
753
  // runner-a dies once the session holds the message, before the commit that records it and takes its row.
688
- await until(() => holder.crashed, "the crash after the message was sent", EVENT_WAIT_MS);
754
+ await until(() => (w.runOutUnknown(), holder.crashed), "the crash after the message was sent", EVENT_WAIT_MS);
689
755
  assert.equal((await w.commandRow(row.id)).takenAt, null, "the row is untaken when runner-a is lost");
690
756
  await w.claimsSettled("runner-a");
691
757
  w.runOut();
@@ -716,7 +782,7 @@ const CASES = [
716
782
  const w = await world(subject, t);
717
783
  const { tools, slowStarted } = suiteTools();
718
784
  await w.start("runner-a", { script: [{ call: "slow" }, { say: "never" }], tools, hooks: quiet });
719
- await slowStarted;
785
+ await w.began(slowStarted, "the slow tool to start");
720
786
  const stop = await sendCommand(w.server, RUN, { kind: "stop" });
721
787
  const row = await w.ended("stopped");
722
788
  const { calls, messages } = await w.read();
@@ -744,7 +810,7 @@ const CASES = [
744
810
  const w = await world(subject, t);
745
811
  const { tools, slowStarted } = suiteTools();
746
812
  await w.start("runner-a", { script: [{ call: "slow" }, { say: "never" }], tools, hooks: quiet });
747
- await slowStarted;
813
+ await w.began(slowStarted, "the slow tool to start");
748
814
  const cancel = await sendCommand(w.server, RUN, { kind: "cancel" });
749
815
  const row = await w.ended("stopped");
750
816
  const { calls, messages } = await w.read();
@@ -809,7 +875,7 @@ const CASES = [
809
875
  const w = await world(subject, t);
810
876
  const { tools, letSlowGo, slowStarted } = suiteTools();
811
877
  await w.start("runner-a", { script: [{ call: "slow" }, { sayLastSteer: true }], tools, hooks: quiet });
812
- await slowStarted;
878
+ await w.began(slowStarted, "the slow tool to start");
813
879
  const origin = { kind: "trigger", trigger_id: "trigger-1", source: "webhook", owner: false };
814
880
  const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "a new order came in", origin } });
815
881
  // The tool goes on once the steer is with the loop: the turn in flight has it, never a timer.
@@ -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 { CallRecord } from "../journal-reader.js";
3
3
  import type { Journal, LoopFactory } from "../loop-contract.js";
4
4
  /** One step of the model's script: call a tool, say a text, or say the text of the last steer it was given. */
@@ -169,5 +169,8 @@ function dispatchLoop(deps, loopDeps) {
169
169
  earlyStop ??= reason;
170
170
  await started?.catch(() => undefined);
171
171
  },
172
+ keepsComputer(reason) {
173
+ return inner?.keepsComputer?.(reason) ?? false;
174
+ },
172
175
  };
173
176
  }
@@ -2,19 +2,27 @@
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 run: pi answers a repeat of it from its submission, so a turn asked again
6
- * on a later claim is never asked of the model twice. The server's own prefix, so the run's readers tell the turn's
7
- * rows apart by it (reflectFrom). */
8
- export declare const reflectRequestId: (runId: string, again?: boolean) => string;
9
- /** The suffix of the end-of-run turn's re-ask's request id (EndOfRunTurn ask's `again`): one per run too, so a repeat
5
+ /** The end-of-run turn's request id, one per round of a run: pi answers a repeat of it from its submission, so a turn
6
+ * 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 follow-up
7
+ * opened the run again is the next round, whose turn is asked of the model anew under an id of its own. The server's own
8
+ * prefix, so the run's readers tell the turn's rows apart by it (reflectRanges). */
9
+ export declare const reflectRequestId: (runId: string, again?: boolean, round?: number) => string;
10
+ /** 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
10
11
  * is answered from its submission, never asked of the model twice. */
11
12
  export declare const REFLECT_AGAIN = ":again";
12
- /** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
13
- * turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
14
- * adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
15
- * its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
16
- * end, is the turn's (the server's labelled: after the entry before it). */
17
- export declare function reflectFrom(submissions: readonly {
13
+ /** 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
14
+ * run's end entry that closed it, once written. Every entry between is the turn's. */
15
+ export type ReflectRange = {
16
+ readonly from: number;
17
+ readonly until?: number;
18
+ };
19
+ /** 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
20
+ * input submissions under its request ids (its re-ask's within it); else, on a CLI harness, at the turn's prompt the CLI
21
+ * record wrote as it asked it (`entries`: adapter-loop.ts answering, an end-of-run-turn entry of the person's with its
22
+ * request id, written before the turn's submission, which only its answer writes). Each ends at the first end entry
23
+ * after it (the run's end that round closed with); the newest may not have ended yet. None for a run that asked none.
24
+ * A follow-up's messages, between one round's end and the next round, are no round's. */
25
+ export declare function reflectRanges(submissions: readonly {
18
26
  readonly type?: string;
19
27
  readonly requestId?: string;
20
28
  readonly entry?: unknown;
@@ -22,7 +30,9 @@ export declare function reflectFrom(submissions: readonly {
22
30
  readonly kind?: string;
23
31
  readonly id?: unknown;
24
32
  readonly data?: unknown;
25
- }[]): number | undefined;
33
+ }[]): ReflectRange[];
34
+ /** Whether entry `entry` (a number) is one of `ranges`' end-of-run turns. */
35
+ export declare const inReflect: (ranges: readonly ReflectRange[], entry: number) => boolean;
26
36
  /** 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
27
37
  * the adapter loop's refusal and the gate's are the same words. */
28
38
  export { NOTE_ONLY_TEXT as REFLECT_NOTE_ONLY } from "../tool-gate.js";
@@ -8,25 +8,47 @@ import { KINDS } from "./journal-kinds.js";
8
8
  export const REFLECT_PREFIX = "learn-reflect-";
9
9
  /** The label a reader puts on the end-of-run turn's rows and messages: the server's (learning.ts LEARNING_LABEL). */
10
10
  export const REFLECT_LABEL = "learning";
11
- /** The end-of-run turn's request id, one per run: pi answers a repeat of it from its submission, so a turn asked again
12
- * on a later claim is never asked of the model twice. The server's own prefix, so the run's readers tell the turn's
13
- * rows apart by it (reflectFrom). */
14
- export const reflectRequestId = (runId, again = false) => `${REFLECT_PREFIX}${runId}${again ? REFLECT_AGAIN : ""}`;
15
- /** The suffix of the end-of-run turn's re-ask's request id (EndOfRunTurn ask's `again`): one per run too, so a repeat
11
+ /** The end-of-run turn's request id, one per round of a run: pi answers a repeat of it from its submission, so a turn
12
+ * 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 follow-up
13
+ * opened the run again is the next round, whose turn is asked of the model anew under an id of its own. The server's own
14
+ * prefix, so the run's readers tell the turn's rows apart by it (reflectRanges). */
15
+ export const reflectRequestId = (runId, again = false, round = 1) => `${REFLECT_PREFIX}${runId}${round > 1 ? `${REFLECT_ROUND}${round}` : ""}${again ? REFLECT_AGAIN : ""}`;
16
+ /** 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
16
17
  * is answered from its submission, never asked of the model twice. */
17
18
  export const REFLECT_AGAIN = ":again";
18
- /** Where the end-of-run turn began in a run's journal: the entry its input placed, from the input submission under the
19
- * turn's request id; else, on a CLI harness, the turn's prompt the CLI record wrote as it asked the turn (`entries`:
20
- * adapter-loop.ts asking, an end-of-run-turn entry of the person's, written before the turn's submission, which only
21
- * its answer writes). Undefined before either, or for a run that asked none. Every entry from it on, until the run's
22
- * end, is the turn's (the server's labelled: after the entry before it). */
23
- export function reflectFrom(submissions, entries = []) {
24
- const placed = submissions.filter((record) => record.type === "input" && typeof record.requestId === "string" && record.requestId.startsWith(REFLECT_PREFIX) && record.entry !== undefined);
25
- if (placed.length)
26
- return Math.min(...placed.map((record) => Number(record.entry)));
27
- const asked = entries.find((entry) => entry.kind === KINDS.endOfRunTurn && entry.data?.role === "person");
28
- return asked === undefined ? undefined : Number(asked.id);
19
+ /** What names a later round in the end-of-run turn's request id, before its number. */
20
+ const REFLECT_ROUND = ":round-";
21
+ /** 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
22
+ * input submissions under its request ids (its re-ask's within it); else, on a CLI harness, at the turn's prompt the CLI
23
+ * record wrote as it asked it (`entries`: adapter-loop.ts answering, an end-of-run-turn entry of the person's with its
24
+ * request id, written before the turn's submission, which only its answer writes). Each ends at the first end entry
25
+ * after it (the run's end that round closed with); the newest may not have ended yet. None for a run that asked none.
26
+ * A follow-up's messages, between one round's end and the next round, are no round's. */
27
+ export function reflectRanges(submissions, entries = []) {
28
+ const starts = new Map();
29
+ const note = (requestId, entry) => {
30
+ if (!Number.isFinite(entry))
31
+ return;
32
+ const round = requestId.endsWith(REFLECT_AGAIN) ? requestId.slice(0, -REFLECT_AGAIN.length) : requestId;
33
+ starts.set(round, Math.min(starts.get(round) ?? entry, entry));
34
+ };
35
+ for (const record of submissions) {
36
+ if (record.type === "input" && typeof record.requestId === "string" && record.requestId.startsWith(REFLECT_PREFIX) && record.entry !== undefined)
37
+ note(record.requestId, Number(record.entry));
38
+ }
39
+ for (const entry of entries) {
40
+ const data = entry.data;
41
+ if (entry.kind === KINDS.endOfRunTurn && data?.role === "person" && typeof data.requestId === "string" && data.requestId.startsWith(REFLECT_PREFIX))
42
+ note(data.requestId, Number(entry.id));
43
+ }
44
+ const ends = entries.filter((entry) => entry.kind === KINDS.end).map((entry) => Number(entry.id)).sort((a, b) => a - b);
45
+ return [...starts.values()].sort((a, b) => a - b).map((from) => {
46
+ const until = ends.find((end) => end >= from);
47
+ return until === undefined ? { from } : { from, until };
48
+ });
29
49
  }
50
+ /** Whether entry `entry` (a number) is one of `ranges`' end-of-run turns. */
51
+ export const inReflect = (ranges, entry) => ranges.some(({ from, until }) => entry >= from && (until === undefined || entry <= until));
30
52
  /** 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
31
53
  * the adapter loop's refusal and the gate's are the same words. */
32
54
  export { NOTE_ONLY_TEXT as REFLECT_NOTE_ONLY } from "../tool-gate.js";
@@ -13,9 +13,10 @@ export type GithubAppAccessAt = GithubAppAccess & {
13
13
  * joins the run's redactor (its `cut`), the first and every one after. */
14
14
  export declare function githubAppAccess(store: {
15
15
  readonly triggerSettings: Pick<TriggerSettings, "get">;
16
- }, sealKey: Buffer | undefined, firstInput: unknown, { api, now, fromGitHub, hold }?: {
16
+ }, sealKey: Buffer | undefined, firstInput: unknown, { api, now, fromGitHub, hold, repo }?: {
17
17
  api?: string;
18
18
  now?: () => number;
19
19
  fromGitHub?: boolean;
20
20
  hold?: (values: string[]) => void;
21
+ repo?: string;
21
22
  }): Promise<GithubAppAccessAt | undefined>;
@@ -36,13 +36,15 @@ async function appOf(store, sealKey) {
36
36
  * `fromGitHub`: the run's first input is a github trigger's firing (its launch's inputOrigin), whose payload tag names
37
37
  * the repository and installation; any other run's tag is never read, only its owner's words. `hold`: each token minted
38
38
  * joins the run's redactor (its `cut`), the first and every one after. */
39
- export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold } = {}) {
39
+ export async function githubAppAccess(store, sealKey, firstInput, { api = GITHUB_API, now = Date.now, fromGitHub = false, hold, repo } = {}) {
40
40
  if (!sealKey)
41
41
  return undefined;
42
42
  const app = await appOf(store, sealKey);
43
43
  if (!app)
44
44
  return undefined;
45
- const target = githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput, { payload: fromGitHub });
45
+ // `repo`: the launch's (run-launch.ts repo), which the server checked against the agent's binding at the start: a run a
46
+ // person started with `repo`, or whose agent is bound to one repository. It comes before any URL in the words.
47
+ const target = repo !== undefined ? { repo } : githubTargetOf(isObject(firstInput) ? firstInput.content : firstInput, { payload: fromGitHub });
46
48
  return {
47
49
  api,
48
50
  target,
@@ -11,7 +11,10 @@ import { hostMemory, neverFits } from "../host.js";
11
11
  import { resolveHarness } from "./adapters/index.js";
12
12
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
13
13
  import { createAdapterLoop } from "./adapter-loop.js";
14
- import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
14
+ import { hostDecisionKeys, savedModelKeys, withModelKeys } from "./claim-secrets.js";
15
+ import { decisionProvidersIn, DEFAULT_DECISION_PROVIDER, FAUX_JEV_ENV } from "../decisions.js";
16
+ import { FAUX_ENV } from "../model.js";
17
+ import { generalThresholdOf } from "../learn/general.js";
15
18
  import { createDispatchLoop } from "./dispatch.js";
16
19
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
17
20
  import { gradeModelFor, gradeRouteOf, learningLoopOf } from "./learning-dispatch.js";
@@ -58,6 +61,17 @@ export function resolveRunnerLoop(deps) {
58
61
  },
59
62
  ...(deps.log ? { log: deps.log } : {}),
60
63
  ...(deps.gradeBound ? { gradeBound: deps.gradeBound } : {}),
64
+ // The generality pre-check (learn/general.ts) on this host's Jev, built as a learning end builds its check's
65
+ // decision providers (hostDecisionKeys: the runner's environment first, then the key saved in Settings), on the
66
+ // client and model a workflow's decision node gets when it names none. No Jev key: none asked. A faux host asks only
67
+ // its faux Jev (FAUX_JEV_ENV), as its grade goes only to the faux route: a key it inherited never sends a note out.
68
+ jev: async () => {
69
+ const env = deps.env ?? process.env;
70
+ if (env[FAUX_ENV] && !env[FAUX_JEV_ENV])
71
+ return undefined;
72
+ return (await decisionProvidersIn({ ...env, ...(await hostDecisionKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, [DEFAULT_DECISION_PROVIDER])) }))?.providers[DEFAULT_DECISION_PROVIDER];
73
+ },
74
+ generalThreshold: generalThresholdOf(deps.env ?? process.env),
61
75
  });
62
76
  }
63
77
  // The harness's own entry decides which spec builds the run, by the entry's facts and never the harness's name: an entry
@@ -0,0 +1,65 @@
1
+ import { type HeldRead, type HeldState } from "../computer-held.js";
2
+ import type { LoopComputer } from "./computer-channel.js";
3
+ import type { RootEntry } from "./computer-journal.js";
4
+ import type { Command } from "./loop-contract.js";
5
+ /** A run's held computer, as its spec gives it: the hold's minutes (its computer is the spec's `computer`). */
6
+ export type HeldSpec = {
7
+ readonly minutes: number;
8
+ };
9
+ /** What came of an owner's row: refused in words, or the change to commit (the commit takes the row). */
10
+ export type HeldDecision = {
11
+ readonly refused: string;
12
+ } | {
13
+ readonly write: () => Promise<void>;
14
+ };
15
+ /** How the hold's wait ended: its state moved on (started, or released by the owner or its lapse), or `cut` settled first. */
16
+ export type HeldWait = "moved" | "cut";
17
+ /** The journal's side of a run's held computer, for the pass whose Harness `commit` writes root entries (in one commit, in
18
+ * order). `now` is the clock its entries are stamped with. */
19
+ export declare function journalHeld(spec: HeldSpec, commit: (entries: readonly RootEntry[]) => Promise<void>, now?: () => number): {
20
+ /** The run's computer is up for this pass. `prior`, the run's root entries before it. A run's first pass writes the
21
+ * hold waiting. Every pass starts its own computer (the last pass's went at its close: a new claim, or a restart after
22
+ * a fault within one), so a pass that finds a hold not over finds it gone with the computer that held it, and what
23
+ * the owner set up on it: released, `lost` (the loop ends the run in those words). */
24
+ up(prior: readonly {
25
+ readonly kind: string;
26
+ readonly data?: unknown;
27
+ }[]): Promise<"held" | "lost" | "released">;
28
+ /** Where the hold is now. */
29
+ state: () => HeldState | undefined;
30
+ /** Why the hold ended without a release, if it did. */
31
+ lapse: () => HeldRead["why"];
32
+ /** Before the agent's first input: waits for the owner's start, a release, the hold's lapse, or `cut`. */
33
+ untilStarted: (cut: Promise<unknown>) => Promise<HeldWait>;
34
+ /** The agent's end (or a person's stop of it): the run keeps its computer (the hold ended, the Timeline saying so in
35
+ * `words`) until the owner releases it, the hold lapses, or `cut` settles first (a lost claim, a cancel). A hold
36
+ * already released waits for nothing. */
37
+ heldAtEnd(cut: Promise<unknown>, words?: string): Promise<HeldWait>;
38
+ /** The hold's minutes. */
39
+ minutes: number;
40
+ /** Why an owner's call is refused now: the hold is over (released, lapsed or lost). Undefined while the computer is
41
+ * held: waiting, started or ended. */
42
+ refusesCall(): string | undefined;
43
+ /** An owner's call starts: the hold cannot lapse until every call in flight has ended. */
44
+ callStarted(): void;
45
+ /** An owner's call ended at `at`: the hold's count starts again from it once the last call in flight is done. */
46
+ callEnded(at: number): void;
47
+ /** The hold's count starts again from `at`. */
48
+ touched(at: number): void;
49
+ /** An owner's row: a start or a release. */
50
+ decide(command: Command): HeldDecision;
51
+ /** Whether `data`, a hold or call entry's, is the change row `id` made: the commit that writes it takes the row. */
52
+ madeBy: (data: Record<string, unknown>, id: number) => boolean;
53
+ /** Every commit asked for so far is done. */
54
+ settled: () => Promise<void>;
55
+ };
56
+ export type JournalHeld = ReturnType<typeof journalHeld>;
57
+ /** The spec's `held` for a run whose launch holds its computer (run-launch.ts hold), given the loop's computer: none for a
58
+ * run that holds none, or whose computer speaks no protocol (none, or a browser). */
59
+ export declare function heldSpecOf(launch: {
60
+ readonly hold?: {
61
+ readonly minutes: number;
62
+ };
63
+ }, computer: LoopComputer | undefined): HeldSpec | undefined;
64
+ /** Whether a command row is the owner's, for a held computer. */
65
+ export declare const isHeldCommand: (command: Pick<Command, "kind">) => boolean;