@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.41

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 (126) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +78 -15
  3. package/dist/api-only.d.ts +3 -1
  4. package/dist/api-only.js +4 -2
  5. package/dist/api-token.d.ts +30 -0
  6. package/dist/api-token.js +89 -0
  7. package/dist/cli.js +19 -5
  8. package/dist/composio-made.d.ts +54 -0
  9. package/dist/composio-made.js +83 -0
  10. package/dist/composio-preset.d.ts +16 -8
  11. package/dist/composio-preset.js +106 -43
  12. package/dist/composio-triggers.d.ts +7 -2
  13. package/dist/composio-triggers.js +13 -7
  14. package/dist/computer-attach.d.ts +29 -11
  15. package/dist/computer-attach.js +141 -47
  16. package/dist/computer-keys.d.ts +4 -0
  17. package/dist/computer-keys.js +5 -0
  18. package/dist/computers.d.ts +11 -1
  19. package/dist/computers.js +21 -12
  20. package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
  21. package/dist/console/assets/index-COGhx_2Z.js +711 -0
  22. package/dist/console/index.html +2 -2
  23. package/dist/decisions.js +9 -2
  24. package/dist/eval-feed.d.ts +26 -0
  25. package/dist/eval-feed.js +68 -0
  26. package/dist/eval-mailbox.d.ts +4 -1
  27. package/dist/eval-mailbox.js +11 -3
  28. package/dist/exa-keyless.d.ts +1 -1
  29. package/dist/exa-keyless.js +1 -1
  30. package/dist/feed/feed-faux.d.ts +62 -0
  31. package/dist/feed/feed-faux.js +123 -0
  32. package/dist/feed/fetch.d.ts +41 -0
  33. package/dist/feed/fetch.js +128 -0
  34. package/dist/feed/parse.d.ts +41 -0
  35. package/dist/feed/parse.js +300 -0
  36. package/dist/learn/check.d.ts +3 -1
  37. package/dist/learn/check.js +57 -2
  38. package/dist/learn/compile.js +1 -1
  39. package/dist/learned-nodes.d.ts +21 -4
  40. package/dist/learned-nodes.js +21 -8
  41. package/dist/learned-workflow.d.ts +3 -3
  42. package/dist/learned-workflow.js +14 -5
  43. package/dist/mcp-oauth.d.ts +15 -1
  44. package/dist/mcp-oauth.js +39 -5
  45. package/dist/mcp-pin-first.d.ts +4 -2
  46. package/dist/mcp-pin-first.js +4 -3
  47. package/dist/mcp-servers-store.d.ts +58 -5
  48. package/dist/mcp-servers-store.js +136 -17
  49. package/dist/mcp.d.ts +2 -2
  50. package/dist/mcp.js +2 -2
  51. package/dist/observation/http.d.ts +4 -1
  52. package/dist/observation/http.js +5 -4
  53. package/dist/openapi.js +46 -12
  54. package/dist/print.d.ts +6 -3
  55. package/dist/print.js +4 -2
  56. package/dist/run-labels.d.ts +23 -0
  57. package/dist/run-labels.js +79 -0
  58. package/dist/run-secrets.js +12 -4
  59. package/dist/runner/adapter-loop.js +91 -10
  60. package/dist/runner/adapter-run-spec.d.ts +4 -0
  61. package/dist/runner/adapter-run-spec.js +38 -31
  62. package/dist/runner/beside.d.ts +6 -3
  63. package/dist/runner/beside.js +9 -7
  64. package/dist/runner/cli-run-spec.js +32 -26
  65. package/dist/runner/conformance/harness.js +69 -14
  66. package/dist/runner/conformance/subject.d.ts +4 -1
  67. package/dist/runner/main.d.ts +1 -1
  68. package/dist/runner/main.js +2 -2
  69. package/dist/runner/mcp-claim.d.ts +3 -0
  70. package/dist/runner/mcp-claim.js +1 -1
  71. package/dist/runner/mcp-run.d.ts +4 -0
  72. package/dist/runner/mcp-run.js +5 -3
  73. package/dist/runner/model-route.d.ts +4 -2
  74. package/dist/runner/model-route.js +8 -8
  75. package/dist/runner/promotion.d.ts +8 -0
  76. package/dist/runner/promotion.js +43 -1
  77. package/dist/runner/workflow-first.d.ts +6 -5
  78. package/dist/runner/workflow-first.js +9 -7
  79. package/dist/runs-over-store.js +5 -2
  80. package/dist/sdk/runs.d.ts +7 -1
  81. package/dist/sdk/runs.js +19 -6
  82. package/dist/secret-cut.js +3 -1
  83. package/dist/secrets.js +3 -1
  84. package/dist/server.d.ts +27 -2
  85. package/dist/server.js +168 -50
  86. package/dist/store/dialect.d.ts +3 -0
  87. package/dist/store/dialect.js +1 -0
  88. package/dist/store/index.d.ts +1 -1
  89. package/dist/store/postgres/dialect.js +1 -0
  90. package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
  91. package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
  92. package/dist/store/schema.d.ts +9 -0
  93. package/dist/store/schema.js +26 -2
  94. package/dist/store/sqlite/connection.js +11 -3
  95. package/dist/store/sqlite/run-patch.d.ts +2 -1
  96. package/dist/store/sqlite/run-patch.js +3 -2
  97. package/dist/store/sqlite/store.js +64 -10
  98. package/dist/store/store.d.ts +38 -1
  99. package/dist/store-reads/journal.js +2 -1
  100. package/dist/store-reads/learning.js +6 -1
  101. package/dist/store-reads/runs.d.ts +4 -3
  102. package/dist/store-reads/runs.js +3 -2
  103. package/dist/store-view.js +4 -2
  104. package/dist/template-eval.d.ts +4 -0
  105. package/dist/template-eval.js +127 -50
  106. package/dist/templates.d.ts +10 -0
  107. package/dist/templates.js +75 -17
  108. package/dist/timeline/origin.d.ts +1 -1
  109. package/dist/timeline/origin.js +2 -2
  110. package/dist/trigger-adapter.d.ts +9 -4
  111. package/dist/trigger-adapters.js +2 -1
  112. package/dist/trigger-feed.d.ts +12 -0
  113. package/dist/trigger-feed.js +371 -0
  114. package/dist/triggers.d.ts +2 -1
  115. package/dist/triggers.js +23 -5
  116. package/dist/webhooks.js +9 -5
  117. package/dist/workspace/computer-deps.d.ts +5 -1
  118. package/dist/workspace/computer-deps.js +2 -2
  119. package/dist/workspace/index.d.ts +1 -0
  120. package/dist/workspace/index.js +2 -0
  121. package/dist/workspace/resolve-computer.d.ts +32 -3
  122. package/dist/workspace/resolve-computer.js +47 -9
  123. package/launcher/agentrun-serve +6 -1
  124. package/package.json +10 -9
  125. package/templates/README.md +27 -2
  126. package/dist/console/assets/index-Jbxjcmdp.js +0 -705
@@ -45,8 +45,8 @@ import { ClaimRefused } from "./loop-contract.js";
45
45
  import { bookedSpend, cliRunMetrics, endCostOf, runCostOf, runMetrics } from "./metrics.js";
46
46
  import { journalEntries } from "./journal-reader.js";
47
47
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
48
- import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid } from "./promotion.js";
49
- import { laidFor, pathMetrics, servedOf, workflowFirstOf } from "./workflow-first.js";
48
+ import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
49
+ import { pathMetrics, servedOf, workflowFirstOf } from "./workflow-first.js";
50
50
  import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
51
51
  import { specBuilt } from "./spec-holds.js";
52
52
  import { archilClaim, MOUNT_TTL_MS } from "../workspace/archil-claim.js";
@@ -262,13 +262,43 @@ async function adapterSpec(launch, run, deps, claim, holds) {
262
262
  // person's stop ends the fetch at once (run.stopped).
263
263
  const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
264
264
  holds.hold({ checkout });
265
+ // The run's skills and its learning seed, laid in its folder through the run's Workspace now, before its computer
266
+ // exists: on Archil the computer's mount of the folder takes the disk's write delegation, and from then on every write
267
+ // over the disk's file API is refused (409) while the mount holds it, so a lay after the mount fails the run. The lay
268
+ // reads nothing of the computer: the kind skill is the revision's computer setting's kind. A later claim lays only what
269
+ // is not there yet (layOwnSkills keeps every folder an earlier claim laid).
270
+ // The launch's learning start (none: the run does not learn), decided once at launch.
271
+ const start = learningStartOf(launch);
272
+ // The revision's own skills are laid in the run's .agents/skills/ before they are read (main's server start laid them;
273
+ // on the one store the claim does), from the revision row's texts (the body keeps only each file's SHA-256): each
274
+ // folder not there yet, never over a learned skill or an earlier claim's. A desktop or a phone (the revision's computer
275
+ // setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
276
+ const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
277
+ // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
278
+ // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
279
+ // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
280
+ // before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
281
+ const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
282
+ const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
283
+ const seedLaid = start && !seedFailed(start)
284
+ ? await layLearningSeed({
285
+ work: ws.workspace,
286
+ seed: start.seed,
287
+ folder: learningFolder,
288
+ own: Object.keys(revisionRow.skills ?? {}),
289
+ shown,
290
+ log,
291
+ ...(start.notesOnly ? { workflows: false } : {}),
292
+ ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
293
+ })
294
+ : undefined;
265
295
  // The run's MCP for this claim (mcp-run.ts mcpForClaim): its pin, the one its revision's save made, read, its
266
296
  // credentials opened under the server's seal key into this claim's memory, one gateway for the claim. First, before
267
297
  // anything the spec would have to let go: a refusal (a granted tool its pin does not hold, a pinned meta tool) ends the run in its
268
298
  // words before the session opens. The seal key is the runner's own (deps.sealKey), not re-read from the environment.
269
299
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactor.
270
300
  const hold = (values) => cut.hold(values);
271
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.mcpLoopback ? { loopback: true } : {}) });
301
+ const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => ws.workspace, launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.mcpLoopback ? { loopback: true } : {}), ...(deps.mcpOwn ? { own: deps.mcpOwn } : {}) });
272
302
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
273
303
  holds.hold({ passed: mcp });
274
304
  // The run's computer, from the one shared claim-time function (the CLI spec takes the same): none for a runner place, a
@@ -420,31 +450,6 @@ async function adapterSpec(launch, run, deps, claim, holds) {
420
450
  delete toolEnv[TOOL_PLANE_ENV];
421
451
  if (launch.plane && Object.keys(launch.plane).length)
422
452
  toolEnv[TOOL_PLANE_ENV] = JSON.stringify(launch.plane);
423
- // The launch's learning start (none: the run does not learn), decided once at launch.
424
- const start = learningStartOf(launch);
425
- // The revision's own skills are laid in the run's .agents/skills/ before they are read (main's server start laid them;
426
- // on the one store the claim does), from the revision row's texts (the body keeps only each file's SHA-256): each
427
- // folder not there yet, never over a learned skill or an earlier claim's. A desktop or a phone (the revision's computer
428
- // setting, the one computerForClaim starts) brings its kind's skill, named in the prompt beside the revision's own.
429
- const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
430
- // A learning run's seed, read once from its learning folder where the run's place keeps it: its notes in .learning/
431
- // and its learned skills beside the revision's own (runner/learning-seed.ts), cut of the server's secrets, the learned
432
- // skills then in the skill list the prompt names, its learned workflows the ones its learned_workflow tool runs. Laid
433
- // before the run's tools are bound. A learning fault, or a seed that failed (seedFailed), lays nothing.
434
- const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
435
- const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
436
- const seedLaid = start && !seedFailed(start)
437
- ? await layLearningSeed({
438
- work: ws.workspace,
439
- seed: start.seed,
440
- folder: learningFolder,
441
- own: Object.keys(revisionRow.skills ?? {}),
442
- shown,
443
- log,
444
- ...(start.notesOnly ? { workflows: false } : {}),
445
- ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
446
- })
447
- : undefined;
448
453
  // The decision keys its learned workflows' typed questions need (claim-secrets.ts learnedDecisionKeys), read once the lay
449
454
  // chose them, scoped as the revision's own: each provider the run's gate does not deny, held by the run's one redactor,
450
455
  // onto the tools' environment alone. The model's route was built on the revision's keys above, so a decision key never
@@ -456,16 +461,18 @@ async function adapterSpec(launch, run, deps, claim, holds) {
456
461
  // serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
457
462
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
458
463
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the run asks for its revision.
459
- const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(claimPromotion({
464
+ const promotion = claimPromotion({
460
465
  store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
461
- })), revision.body.outputSchema) : {};
466
+ });
467
+ const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
462
468
  // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
463
469
  await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
464
470
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
465
471
  // answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
466
472
  const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
467
473
  const { serve: workflowFirst, revise: workflowRevise } = firstChoice;
468
- const workflows = laidFor(laidFlows, firstChoice);
474
+ // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
475
+ const workflows = await toolFlowsFor(promotion, launch, laidFlows, firstChoice);
469
476
  // A tier a learned workflow's node names and the host has a model of: none can't be reached is left as `why`, and its
470
477
  // node fails in those words (learnedWorkflowHostTool), never on another model.
471
478
  const tierUnreachable = new Map();
@@ -27,15 +27,18 @@ export declare function besideStopping(server: {
27
27
  * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
28
28
  * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
29
29
  * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
30
- * holds each paired computer's socket in this process, so a run here takes one. Returns the runner and a close() that
31
- * stops both and closes its store. */
32
- export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor, hub, mcpLoopback, evalFakes, harnessInstall, onLine }?: {
30
+ * holds each paired computer's socket in this process, so a run here takes one. `dial`: the server's (Serve.dial), which
31
+ * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
32
+ * and a close() that stops both and closes its store. */
33
+ export declare function runnerBeside(dataDir: string, { loops, drainMs, env, janitor, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine }?: {
33
34
  loops?: number;
34
35
  drainMs?: number;
35
36
  env?: NodeJS.ProcessEnv;
36
37
  janitor?: boolean;
37
38
  hub?: import("@parcha/agentrun-computer").AttachHub;
39
+ dial?: import("@parcha/agentrun-computer").HostedDial;
38
40
  mcpLoopback?: boolean;
41
+ mcpOwn?: readonly string[];
39
42
  evalFakes?: (agentId: string) => import("./adapter-run-spec.js").EvalFakes | undefined;
40
43
  harnessInstall?: import("../harness-install.js").HarnessInstaller;
41
44
  onLine?: (line: string) => void;
@@ -28,9 +28,10 @@ export function besideStopping(server, held, drainMs) {
28
28
  * caller hands its own: the template eval's in-process server, its faux's). `loops` and `drainMs`: the runner's
29
29
  * (RunnerOptions), the CLI start's from the server's flags (besideRunnerOptions). `janitor`: run the computer janitor
30
30
  * too (workspace/computer-janitor.ts), as the CLI's start asks. `hub`: the server's AttachHub (Serve.attachHub), which
31
- * holds each paired computer's socket in this process, so a run here takes one. Returns the runner and a close() that
32
- * stops both and closes its store. */
33
- export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub, mcpLoopback, evalFakes, harnessInstall, onLine } = {}) {
31
+ * holds each paired computer's socket in this process, so a run here takes one. `dial`: the server's (Serve.dial), which
32
+ * a remote provider's create takes, so a machine that dials the server lands in this process's hub. Returns the runner
33
+ * and a close() that stops both and closes its store. */
34
+ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub, dial, mcpLoopback, mcpOwn, evalFakes, harnessInstall, onLine } = {}) {
34
35
  const { runnerName, startRunner } = await import("./runner.js");
35
36
  const { dispatchRunner } = await import("./harness-loops.js");
36
37
  const { routeOf } = await import("./model-route.js");
@@ -60,14 +61,15 @@ export async function runnerBeside(dataDir, { loops, drainMs, env, janitor, hub,
60
61
  const { hostAddressesOnce } = await import("../docker-host-addresses.js");
61
62
  const { PROVIDERS } = await import("@parcha/agentrun-computer");
62
63
  const { hostCommandRefusals } = await import("../computers.js");
63
- const computers = runnerComputers(store, runs, seal.key, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(hub ? { hub } : {}) });
64
+ const computers = runnerComputers(store, runs, seal.key, { dockerPaths: () => dockerPathsForRuns(runs, dataDir), hostAddresses: () => hostAddressesOnce(runs), hostWhy: hostCommandRefusals(PROVIDERS, process.env.PATH), ...(hub ? { hub } : {}), ...(dial ? { dial } : {}) });
64
65
  // `mcpLoopback`: the server beside it is a local install (Serve.localInstall), so its runs may reach an MCP server on
65
- // loopback; any other runner's runs never do. A run's log lines (a learning run's skipped generality check) go to
66
+ // loopback; any other runner's runs never do. `mcpOwn`: that server's own addresses (Serve.own), whose ports a run's
67
+ // loopback read never goes to. A run's log lines (a learning run's skipped generality check) go to
66
68
  // stderr with the runner's other lines. `evalFakes`: the template eval's fakes (EvalFakes: a case's web, now, monid and
67
69
  // email), by the agent each of its runs is of; only the eval, in its own process, hands them. `harnessInstall`: what a
68
70
  // claim's first-use install installs with (the eval's sharedInstaller, which the server beside it takes too).
69
71
  const { installForClaim } = await import("../harness-install.js");
70
- const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), ...(evalFakes ? { evalFakes } : {}), ...(harnessInstall ? { installForClaim: (entry, dir, pins, given) => installForClaim(entry, dir, pins, { ...given, install: harnessInstall }) } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) });
72
+ const createLoop = dispatchRunner({ env: runs, data: dataDir, journal: (claim) => store.journal(claim), store, sealKey: seal.key, routeOf, computerForClaim: computers.computerForClaim, computerDeps: computers.computerDeps, ...(mcpLoopback ? { mcpLoopback: true } : {}), ...(mcpOwn ? { mcpOwn } : {}), ...(evalFakes ? { evalFakes } : {}), ...(harnessInstall ? { installForClaim: (entry, dir, pins, given) => installForClaim(entry, dir, pins, { ...given, install: harnessInstall }) } : {}), log: (line) => console.error(`agentrun-serve runner: ${line}`) });
71
73
  // It claims by the host's memory as well as by --max-runs (memory-claim.ts): a heavy harness's run waits queued for room.
72
74
  const { runnerMemory } = await import("./memory-claim.js");
73
75
  // Before it claims: the scratch folders of runs that ended after their runner died (scratch-sweep.ts).
@@ -109,7 +111,7 @@ export async function serveWithRunner(options) {
109
111
  const { besideRunEnv } = await import("./main.js");
110
112
  const { loops, drainMs } = besideRunnerOptions(options, process.env);
111
113
  const serve = await startServe(options);
112
- const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), hub: serve.attachHub, mcpLoopback: serve.localInstall, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
114
+ const beside = await runnerBeside(options.data, { loops, drainMs, env: besideRunEnv(process.env, fauxEnvOf(options)), hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ...(options.log ? { onLine: options.log } : {}) }).catch(async (error) => {
113
115
  await serve.close();
114
116
  throw error;
115
117
  });
@@ -63,8 +63,8 @@ import { entriesOf } from "./loop.js";
63
63
  import { bookedSpend, cliModelWorked, cliRunMetrics, endCostOf, runCostOf } from "./metrics.js";
64
64
  import { journalEntries } from "./journal-reader.js";
65
65
  import { hashedMcpOf, piShaped } from "../store-reads/journal.js";
66
- import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid } from "./promotion.js";
67
- import { laidFor, pathMetrics, workflowFirstOf } from "./workflow-first.js";
66
+ import { claimPromotion, promotionGate, replayCallsFor, replayClaimed, replayLaid, toolFlowsFor } from "./promotion.js";
67
+ import { pathMetrics, workflowFirstOf } from "./workflow-first.js";
68
68
  import { pastRunsOverStore, runPathOverStore } from "../store-reads/learning.js";
69
69
  import { specBuilt } from "./spec-holds.js";
70
70
  import { heldRedactor, holdClaimed, runnerSecrets, secretRedactor } from "./redact.js";
@@ -314,7 +314,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
314
314
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
315
315
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
316
316
  redact.hold(values); };
317
- const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.mcpLoopback ? { loopback: true } : {}) });
317
+ const mcp = await mcpForClaim({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...(deps.mcpLoopback ? { loopback: true } : {}), ...(deps.mcpOwn ? { own: deps.mcpOwn } : {}) });
318
318
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
319
319
  holds.hold({ passed: mcp });
320
320
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -343,6 +343,30 @@ async function cliSpec(launch, run, deps, claim, holds) {
343
343
  const checkout = body.checkout === "pull_request" ? await prCheckoutForClaim(deps, ws.workspace, launch, cut, run.stopped ?? run.signal, (part) => holds.hold({ checkout: part })) : undefined;
344
344
  holds.hold({ checkout });
345
345
  await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
346
+ // The run's skills and its learning seed laid before its computer exists, as the pi spec lays them (adapter-run-spec.ts):
347
+ // on Archil the computer's mount takes the disk's write delegation, and a lay over the disk's file API after it is
348
+ // refused (409) while the mount holds it.
349
+ // The launch's learning start (none: the run does not learn), decided once at launch.
350
+ const start = learningStartOf(launch);
351
+ // The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts), with the kind's
352
+ // skill of a desktop or a phone (the revision's computer setting), in the harness's skill list beside the revision's.
353
+ const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
354
+ // A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
355
+ // the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
356
+ const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
357
+ const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
358
+ const seedLaid = start && !seedFailed(start)
359
+ ? await layLearningSeed({
360
+ work: ws.workspace,
361
+ seed: start.seed,
362
+ folder: learningFolder,
363
+ own: Object.keys(revisionRow.skills ?? {}),
364
+ shown,
365
+ log,
366
+ ...(start.notesOnly ? { workflows: false } : {}),
367
+ ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
368
+ })
369
+ : undefined;
346
370
  // The run's computer, from the one shared claim-time function (the pi spec takes the same): none for a runner place.
347
371
  // It throws computer_unavailable (nothing made) when the computer cannot be had: the run fails in its words.
348
372
  const claimSignal = run.stopped ?? run.signal;
@@ -388,29 +412,9 @@ async function cliSpec(launch, run, deps, claim, holds) {
388
412
  // own skills through systemOf with the harness's own check (a harness that loads skills itself keeps in the prompt only
389
413
  // those it would refuse, and is handed the rest), the output schema it answers in (answer-json.ts outputContract, as the
390
414
  // pi spec gives it), then the effort guidance.
391
- const start = learningStartOf(launch);
392
415
  // A start whose seed failed tells the run nothing: it is never asked what to keep (learning-end.ts drops it).
393
416
  const laid = start && !seedFailed(start) ? laidLearned(body.instructions ?? "", start.section, start.use === true) : (body.instructions ?? "");
394
417
  const check = await entry.skillCheck?.();
395
- // The revision's own skills laid before they are read, as the pi spec lays them (adapter-run-spec.ts), with the kind's
396
- // skill of a desktop or a phone (the revision's computer setting), in the harness's skill list beside the revision's.
397
- const kindSkills = await layOwnSkills(ws.workspace, (revisionRow.skills ?? {}), { computer: settingOfDefinition(body)?.computer.kind });
398
- // A learning run's seed laid as the pi spec lays it (runner/learning-seed.ts), its learned skills then in the skill list
399
- // the harness is handed (its native skills, or the prompt's), its learned workflows the ones learned_workflow runs.
400
- const shown = async () => secretsShown(runnerSecrets(deps.env, await storeSecrets(deps.store, deps.sealKey, deps.data)), { local: true });
401
- const learningFolder = () => (archil === undefined ? learningFolderOf(deps.data, runRow.agentId) : learningWorkspace({ mode: "archil", agentId: runRow.agentId, archil }));
402
- const seedLaid = start && !seedFailed(start)
403
- ? await layLearningSeed({
404
- work: ws.workspace,
405
- seed: start.seed,
406
- folder: learningFolder,
407
- own: Object.keys(revisionRow.skills ?? {}),
408
- shown,
409
- log,
410
- ...(start.notesOnly ? { workflows: false } : {}),
411
- ...(start.notesLeftOut?.length ? { notesLeftOut: start.notesLeftOut } : {}),
412
- })
413
- : undefined;
414
418
  const { system: instructions, native } = await systemOf(laid, [...Object.keys(body.skills ?? {}), ...kindSkills, ...(seedLaid?.skills ?? [])], ws.workspace, check, { onDemand: readsFiles(granted) });
415
419
  const guidance = effortGuidance(launch.effort);
416
420
  // The run's model (the launch's, pinned at start, else the revision's) and its adapter, as main builds them, on the
@@ -547,16 +551,18 @@ async function cliSpec(launch, run, deps, claim, holds) {
547
551
  // serves (runner/promotion.ts: replayed on the agent's graded inputs first, or promoted on its dry run with fewer than
548
552
  // five); while the folder's revision replays or is held, the champion (the digest promoted last) serves in its place
549
553
  // (laidFor). Or the one the money rule stopped, over the agent's past runs (costLineOf): the run asks for its revision.
550
- const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(claimPromotion({
554
+ const promotion = claimPromotion({
551
555
  store: deps.store, agentId: runRow.agentId, runId: claim.runId, revisionId: runRow.revisionId, launch, context, log, folder: learningFolder, shown, sealKey: deps.sealKey,
552
- })), revision.body.outputSchema) : {};
556
+ });
557
+ const firstChoice = learnsWorkflows(revision.kind, laidFlows) ? await workflowFirstOf(revision.kind, laidFlows, launch, log, () => pastRunsOverStore(deps.store, runRow.agentId), promotionGate(promotion), revision.body.outputSchema) : {};
553
558
  // A replay run runs only its revision, while it still replays: else its claim is refused (the run ends failed, no agent).
554
559
  await replayClaimed(deps.store, runRow.agentId, claim.runId, launch, firstChoice);
555
560
  // A replay run's call nodes: reads live through a cache seeded from the graded run's recorded calls, writes only ever
556
561
  // answered from that recording (runner/promotion.ts replayCallsFor, learn/replay-calls.ts).
557
562
  const replay = await replayCallsFor(deps.store, claim.runId, launch, context);
558
563
  const { serve: workflowFirst, revise: workflowRevise } = firstChoice;
559
- const workflows = laidFor(laidFlows, firstChoice);
564
+ // The tool runs what serves, never a revision not promoted (runner/promotion.ts toolFlowsFor).
565
+ const workflows = await toolFlowsFor(promotion, launch, laidFlows, firstChoice);
560
566
  const learns = learnsWorkflows(revision.kind, workflows);
561
567
  if (webNames.length || learns) {
562
568
  // The claim's keys (above, already held by the redactors), a copy of its own for the tools' plane below.
@@ -132,6 +132,7 @@ function crashAt(point, holder) {
132
132
  beforeIntent: async () => (point === "beforeIntent" ? crash() : undefined),
133
133
  beforeResult: async () => (point === "beforeResult" ? crash() : undefined),
134
134
  afterMessageSent: async () => (point === "afterMessageSent" ? crash() : undefined),
135
+ afterSteerPlaced: async () => (point === "afterSteerPlaced" ? crash() : undefined),
135
136
  };
136
137
  }
137
138
  /** The Postgres store each registered subject's worlds open (registerHarnessConformance's `storeUrl`), by the subject
@@ -206,6 +207,8 @@ async function world(subject, t, timing = STEADY) {
206
207
  await settled(() => server.runs.create({ id: RUN, agentId: "agent-1", revisionId: "rev-1" }), () => server.runs.get(RUN));
207
208
  /** The command rows a runner has handed to a loop's command(): with the loop, whether or not taken yet. */
208
209
  const handed = new Set();
210
+ /** The command rows a loop's command() has answered: a steer it took is with the session by then (a CLI's has it). */
211
+ const answered = new Set();
209
212
  /** Each runner's claims in flight (store.runs.claimMany), by its name: what claimsSettled waits for. */
210
213
  const claiming = new Map();
211
214
  /** `store` as runner `name` is handed it: the same store, its claims in flight counted (claiming). */
@@ -274,7 +277,15 @@ async function world(subject, t, timing = STEADY) {
274
277
  },
275
278
  }),
276
279
  });
277
- return { ...loop, command: (command) => (handed.add(command.id), loop.command(command)) };
280
+ return {
281
+ ...loop,
282
+ command: (command) => {
283
+ handed.add(command.id);
284
+ const outcome = loop.command(command);
285
+ void Promise.resolve(outcome).then(() => answered.add(command.id), () => undefined);
286
+ return outcome;
287
+ },
288
+ };
278
289
  };
279
290
  const runner = startRunner({ store: claimsCounted(store, name), createLoop: observedLoop, name, ...TIMING, ...timing, onEvent: (event) => events.push({ runner: name, at: Date.now(), ...event }) });
280
291
  runners.push(runner);
@@ -371,7 +382,7 @@ async function world(subject, t, timing = STEADY) {
371
382
  assert.ok(ask, "the run wrote its ask");
372
383
  return String(ask.data.callId);
373
384
  };
374
- return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), liveRows, servedRows };
385
+ return { dir, storeUrl: url, storeEnv, clockFile, runOut, runOutUnknown, claimsSettled, server, start, run, read, ended, began, commandRow, askedCall, events, handedOver: (id) => handed.has(id), answered: (id) => answered.has(id), liveRows, servedRows };
375
386
  }
376
387
  /**
377
388
  * The claim's fence, as the stalled process's own events show it: once it went on (`continuedAt`, its lease run out and no
@@ -697,11 +708,13 @@ const CASES = [
697
708
  const { calls, messages } = await w.read();
698
709
  const slow = calls.find((call) => call.tool === "slow");
699
710
  const steered = messages.find((message) => message.role === "steer");
700
- const said = messages.filter((message) => message.role === "model");
701
711
  assert.ok(slow?.endEntry !== undefined && slow.status === "done", `slow ran to its end: ${JSON.stringify(calls)}`);
712
+ // Everything the model said once the call started. What it said with the call, before the call's row (a CLI's
713
+ // "Calling slow."), is that step's, as deny-note reads it; the step after the call said only the steer.
714
+ const said = messages.filter((message) => message.role === "model" && message.entry > slow.startEntry);
702
715
  assert.equal(steered?.text, "check the totals", `the steer is in the journal: ${JSON.stringify(messages)}`);
703
716
  assert.ok(steered.entry > slow.endEntry, "after the tool's end: mid-turn, not lost");
704
- assert.deepEqual(said.map((message) => message.text), ["check the totals"], "the next step saw it");
717
+ assert.deepEqual(said.map((message) => message.text), ["check the totals"], `the next step saw it: ${JSON.stringify(messages)}`);
705
718
  assert.ok(said[0].entry > steered.entry);
706
719
  assert.ok((await w.commandRow(steer.id)).takenAt !== null, "the steer row is taken");
707
720
  },
@@ -725,8 +738,9 @@ const CASES = [
725
738
  const rows = [];
726
739
  for (const text of texts)
727
740
  rows.push(await sendCommand(w.server, RUN, { kind: "steer", body: { text } }));
728
- // The tool goes on once every message is with the loop: the turn in flight has them, never a timer.
729
- await until(() => rows.every((row) => w.handedOver(row.id)), "the messages handed to the loop mid-turn");
741
+ // The tool goes on once the loop has answered every message: the turn in flight has them, never a timer. (Handed to
742
+ // the loop is not enough: a CLI's steer is with the CLI only once the loop's steer() returns.)
743
+ await until(() => rows.every((row) => w.answered(row.id)), "the messages placed by the loop mid-turn");
730
744
  letSlowGo();
731
745
  await w.ended("ended");
732
746
  const { calls, messages } = await w.read();
@@ -788,6 +802,37 @@ const CASES = [
788
802
  assert.ok(!rows.slice(0, at).some((one) => one.kind === "user_message" && one.text === text), `no row of the message before the notice: ${shown}`);
789
803
  },
790
804
  },
805
+ {
806
+ id: "steer-placed-crash",
807
+ title: "a steer placed by a runner lost before its row was taken reaches the model once, and the next runner takes its row",
808
+ async body(subject, t) {
809
+ const w = await world(subject, t);
810
+ const { tools, letSlowGo, slowStarted } = suiteTools();
811
+ const text = "check the totals";
812
+ // The call, then what the model says after it, then what it says on the resume that follows the crash: each the
813
+ // steer it was given, when it was given one.
814
+ const script = [{ call: "slow" }, { sayLastSteer: true }, { sayLastSteer: true }];
815
+ const holder = {};
816
+ await w.start("runner-a", { script, tools, hooks: crashAt("afterSteerPlaced", holder) }, holder);
817
+ await w.began(slowStarted, "the slow tool to start");
818
+ const row = await sendCommand(w.server, RUN, { kind: "steer", body: { text } });
819
+ // runner-a dies once its session holds the steer, while the tool it was sent during still runs, before the commit
820
+ // that records it and takes its row.
821
+ await until(() => (w.runOutUnknown(), holder.crashed), "the crash after the steer was placed", EVENT_WAIT_MS);
822
+ assert.equal((await w.commandRow(row.id)).takenAt, null, "the row is untaken when runner-a is lost");
823
+ await w.claimsSettled("runner-a");
824
+ w.runOut();
825
+ letSlowGo();
826
+ await w.start("runner-b", { script, tools, hooks: quiet });
827
+ await w.ended("ended", EVENT_WAIT_MS);
828
+ const { messages } = await w.read();
829
+ const sent = messages.filter((message) => message.role !== "model" && message.text === text);
830
+ assert.equal(sent.length, 1, `the steer is on the record once: ${JSON.stringify(messages)}`);
831
+ assert.ok(messages.some((message) => message.role === "model" && message.text.includes(text) && message.entry > sent[0].entry), `the model answered it: ${JSON.stringify(messages)}`);
832
+ const taken = await w.commandRow(row.id);
833
+ assert.ok(taken.takenAt !== null && taken.refused === null, `its row is taken by runner-b: ${JSON.stringify(taken)}`);
834
+ },
835
+ },
791
836
  {
792
837
  id: "stop-ends-turn",
793
838
  title: "stop ends the turn; the run says why",
@@ -891,15 +936,20 @@ const CASES = [
891
936
  await w.began(slowStarted, "the slow tool to start");
892
937
  const origin = { kind: "trigger", trigger_id: "trigger-1", source: "webhook", owner: false };
893
938
  const steer = await sendCommand(w.server, RUN, { kind: "steer", body: { text: "a new order came in", origin } });
894
- // The tool goes on once the steer is with the loop: the turn in flight has it, never a timer.
895
- await until(() => w.handedOver(steer.id), "the steer handed to the loop");
939
+ // The tool goes on once the loop has answered the steer: the turn in flight has it, never a timer.
940
+ await until(() => w.answered(steer.id), "the steer placed by the loop");
896
941
  letSlowGo();
897
942
  await w.ended("ended");
898
- const { messages } = await w.read();
943
+ const { calls, messages } = await w.read();
899
944
  const steered = messages.find((message) => message.text === "a new order came in" && message.role !== "model");
900
945
  assert.deepEqual(steered?.origin, origin, `the message keeps its origin: ${JSON.stringify(messages)}`);
901
- const said = messages.filter((message) => message.role === "model").map((message) => message.text);
902
- assert.deepEqual(said, ["a new order came in"], "the model read it as any message");
946
+ // Everything the model said once the call started (what it said with the call, before its row, is that step's, as in
947
+ // steer-mid-turn): only its answer to the steer, after it.
948
+ const slow = calls.find((call) => call.tool === "slow");
949
+ assert.ok(slow, `slow is on the record: ${JSON.stringify(calls)}`);
950
+ const said = messages.filter((message) => message.role === "model" && message.entry > slow.startEntry);
951
+ assert.deepEqual(said.map((message) => message.text), ["a new order came in"], `the model read it as any message: ${JSON.stringify(messages)}`);
952
+ assert.ok(said[0].entry > steered.entry, `it answered after the steer: ${JSON.stringify(messages)}`);
903
953
  },
904
954
  },
905
955
  {
@@ -1192,7 +1242,8 @@ async function modelSaid(w) {
1192
1242
  const { messages } = await w.read();
1193
1243
  return messages.filter((message) => message.role === "model").map((message) => message.text).join("\n");
1194
1244
  }
1195
- const STEERS_IN_TURN = "it places a message sent mid-turn in the turn in flight, its row taken in its submission's commit, so it never sends one as a turn of its own (message-resent-after-crash)";
1245
+ const STEERS_IN_TURN = "it places a message sent mid-turn in the turn in flight, so it never sends one as a turn of its own (message-resent-after-crash; a runner lost after placing a steer is steer-placed-crash)";
1246
+ const STEER_TAKEN_WITH_PLACEMENT = "it takes a steer's row in the commit that places it (its submission's), so no runner is lost between the placement and the take (steer-placed-crash)";
1196
1247
  const CLI_NEVER_RERUNS = "a CLI never reruns a call that started; only the model calls again (its adapter's facts: rerunsStarted false)";
1197
1248
  /** The cases a harness's declared facts rule out, each with why: what it does by design, not what it cannot model yet. */
1198
1249
  export function factsRuleOut(facts) {
@@ -1201,7 +1252,7 @@ export function factsRuleOut(facts) {
1201
1252
  const noSteer = `${facts.id} takes no message mid-turn (its adapter's facts: steer false), so a message sent while it works is never placed in the turn in flight: it is the run's next turn (message-mid-turn-kept)`;
1202
1253
  return {
1203
1254
  // steer-origin steers the turn in flight too: its message is taken mid-turn, or never.
1204
- ...(facts.steer ? {} : { "steer-mid-turn": noSteer, "steer-origin": noSteer }),
1255
+ ...(facts.steer ? {} : { "steer-mid-turn": noSteer, "steer-origin": noSteer, "steer-placed-crash": noSteer }),
1205
1256
  ...(facts.rerunsStarted === false ? { "replay-safe-rerun": CLI_NEVER_RERUNS, "fault-restarts-bounded": CLI_NEVER_RERUNS } : {}),
1206
1257
  // A harness that resumes a cut answer itself never ends a turn on the cut; one whose cut ends its turn never goes on
1207
1258
  // from it in the same turn.
@@ -1242,7 +1293,11 @@ export function registerHarnessConformance(given, { test, storeUrl }) {
1242
1293
  const processCase = entry.id.endsWith("-process");
1243
1294
  // A harness that steers (any whose facts do not say steer false, as message-mid-turn-kept reads them) places a message
1244
1295
  // in the turn in flight, its row taken in the commit of its submission: it never sends one as a turn of its own.
1245
- const byFacts = ruledOut[entry.id] ?? (entry.id === "message-resent-after-crash" && subject.facts?.steer !== false ? STEERS_IN_TURN : undefined);
1296
+ // A harness that steers and is no CLI (whose started calls a restart may run again) takes a steer's row as it places it:
1297
+ // only a CLI's record, written once its model took the steer, leaves a runner to lose between the two.
1298
+ const byFacts = ruledOut[entry.id]
1299
+ ?? (entry.id === "message-resent-after-crash" && subject.facts?.steer !== false ? STEERS_IN_TURN : undefined)
1300
+ ?? (entry.id === "steer-placed-crash" && subject.facts?.rerunsStarted !== false ? STEER_TAKEN_WITH_PLACEMENT : undefined);
1246
1301
  const notYet = subject.unsupported?.[entry.id] ?? (processCase && !subject.process ? "it names no module a runner process can load (subject.process)" : undefined) ?? (subject.metaTools === false && META_CASES.has(entry.id) ? "its loop gives its sessions no tools_search, tools_call or codemode (they are the adapter loop's: runner/meta-tools.ts)" : undefined);
1247
1302
  const onPostgres = storeUrl ? POSTGRES_PENDING[entry.id] : undefined;
1248
1303
  const skip = byFacts ? `${subject.name} does not do this by design: ${byFacts}` : notYet ? `${subject.name} cannot model this yet: ${notYet}` : onPostgres ? `on Postgres, ${onPostgres}` : undefined;
@@ -51,6 +51,9 @@ export interface KernelHooks {
51
51
  /** A message taken mid-turn was sent as a turn of its own (the adapter loop's sendAfterTurn): the session holds it, and
52
52
  * the commit that records it and takes its row has not run yet. */
53
53
  afterMessageSent?(): Promise<void>;
54
+ /** A message steered into the turn in flight was placed (the session holds it under the row's request id), and the
55
+ * commit that takes its row has not run yet: a CLI's waits for its model to take it (the adapter loop's steerCli). */
56
+ afterSteerPlaced?(): Promise<void>;
54
57
  }
55
58
  export interface ConformanceSetup {
56
59
  readonly script: readonly ScriptStep[];
@@ -59,7 +62,7 @@ export interface ConformanceSetup {
59
62
  /** The run's agent, for the subject's spec to name (AdapterRunSpec.agentId): the end-of-run step is asked with it. */
60
63
  readonly agentId?: string;
61
64
  }
62
- export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run" | "meta-search" | "meta-call-park" | "meta-call-deny" | "meta-codemode-park" | "meta-codemode-stop" | "meta-codemode-crash";
65
+ export type ConformanceCase = "crash-before-intent" | "crash-after-intent" | "crash-before-intent-process" | "crash-after-intent-process" | "stalled-past-lease-process" | "replay-safe-rerun" | "steer-mid-turn" | "message-mid-turn-kept" | "message-resent-after-crash" | "steer-placed-crash" | "cancel-ends-for-good" | "cancel-parked" | "deny-note" | "steer-origin" | "stop-ends-turn" | "park-on-ask" | "approval-names-its-call" | "approval-double-click" | "approval-race" | "message-never-answers" | "end-of-run-answer" | "fault-effects-once" | "fault-restarts-bounded" | "length-ends-failed" | "length-mid-run" | "meta-search" | "meta-call-park" | "meta-call-deny" | "meta-codemode-park" | "meta-codemode-stop" | "meta-codemode-crash";
63
66
  export interface ConformanceSubject {
64
67
  /** The harness's name, as the suite's tests are titled. */
65
68
  readonly name: string;
@@ -68,7 +68,7 @@ export declare function runEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
68
68
  * provider loader in place of the computer package's. Under --faux (the runs' environment names the faux model, as a
69
69
  * --faux server's and a `runner --faux` give it), --faux's computers are beside them, as the server's start check
70
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">) => {
71
+ export declare const runnerComputers: (store: Store, env: KeyEnv, sealKey: Buffer, own?: Pick<ComputerDepsOptions, "kinds" | "load" | "dockerPaths" | "hostAddresses" | "hostWhy" | "hub" | "dial">) => {
72
72
  computerForClaim: typeof import("../workspace/computer-deps.js").claimComputer;
73
73
  computerDeps: ComputerDeps;
74
74
  factories: import("../computer-keys.js").ProviderFactories;
@@ -70,9 +70,9 @@ export async function openRunnerStore(dataDir, env, warn, url) {
70
70
  }
71
71
  }
72
72
  /** The runner's own secrets, which a run never gets, not even in the runner's in-process environment: the server's
73
- * token and API key, the seal key (the runner holds it as its sealKey), and the store's connection (its URL holds a
73
+ * tokens (the token and the token list) and API key, the seal key (the runner holds it as its sealKey), and the store's connection (its URL holds a
74
74
  * database password). */
75
- const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
75
+ const RUNNER_ONLY = (name) => name === "AGENTRUN_TOKEN" || name === "AGENTRUN_TOKENS" || name === "AGENTRUN_API_KEY" || name === SEAL_KEY_ENV || name.startsWith("AGENTRUN_STORE_");
76
76
  /** A run's environment as the runner hands its loops (AdapterSpecDeps.env): this process's, less the runner's own
77
77
  * secrets, with every other secret the launcher's pipe handed it (a model key, a tool key, a box key) readable by name
78
78
  * but not enumerable, as secrets.ts withSecrets makes them: code that reads one by name (the model route) finds it, and
@@ -34,6 +34,9 @@ export interface McpClaimOptions {
34
34
  /** Whether this runner may reach a loopback address (McpForClaimOptions.loopback): a refresh's request to a loopback
35
35
  * authorization server is sent only then. Absent, never. */
36
36
  loopback?: boolean;
37
+ /** The own addresses of the local-install server beside this runner (McpForClaimOptions.own): a loopback authorization
38
+ * server on one of their ports is refused, as the server refuses it. */
39
+ own?: readonly string[];
37
40
  /** For a github_app server (auth github_app, nothing sealed): the server's GitHub App mint and the run's repository
38
41
  * (runner/mcp-github.ts). None: such a server's calls are refused in words. */
39
42
  githubApp?: GithubAppAccess;
@@ -117,7 +117,7 @@ export async function mcpClaim(options) {
117
117
  if (!set.tokens.refresh_token)
118
118
  return { refused: true };
119
119
  const call = AbortSignal.timeout(callMs);
120
- const reach = { allowed: await privateOAuthHosts(store), loopback: options.loopback === true };
120
+ const reach = { allowed: await privateOAuthHosts(store), loopback: options.loopback === true, own: options.own ?? [] };
121
121
  for (let tried = 0; tried < tries && !call.aborted; tried++) {
122
122
  // Every try before this one provably never left: nothing is spent.
123
123
  if (stop.aborted)
@@ -38,6 +38,10 @@ export interface McpForClaimOptions {
38
38
  /** Whether this runner may reach an MCP server whose URL is on loopback (AdapterSpecDeps.mcpLoopback): only a runner
39
39
  * beside a local-install server is. Absent, never. */
40
40
  readonly loopback?: boolean;
41
+ /** The own addresses of the local-install server beside this runner (AdapterSpecDeps.mcpOwn, Serve.own): a loopback
42
+ * URL on one of their ports is refused, as the server refuses it, so a run never reaches that server through an MCP
43
+ * server's address, its authorization server's or a pin's listing. */
44
+ readonly own?: readonly string[];
41
45
  /** For tests: the authorization servers' network, a refresh's bound, the gateway's upstream fetch and bounds, and the
42
46
  * timer a github_app token's refresh is armed on. */
43
47
  readonly network?: OAuthNetwork;
@@ -30,10 +30,11 @@ export async function mcpForClaim(options) {
30
30
  sealKey: options.sealKey,
31
31
  signal: held.signal,
32
32
  // A run whose revision has no pin (one made before the upgrade) pins it here, listing as a save does.
33
- pinListing: registryListing(options.store, options.sealKey, { loopback: options.loopback === true, ...(options.network ? { network: options.network } : {}), ...(githubApp ? { githubApp } : {}), ...(options.githubMcpOrigin ? { appOrigin: options.githubMcpOrigin } : {}) }),
33
+ pinListing: registryListing(options.store, options.sealKey, { loopback: options.loopback === true, own: options.own ?? [], ...(options.network ? { network: options.network } : {}), ...(githubApp ? { githubApp } : {}), ...(options.githubMcpOrigin ? { appOrigin: options.githubMcpOrigin } : {}) }),
34
34
  ...(options.bounds ? { bounds: options.bounds } : {}),
35
35
  ...(options.network ? { network: options.network } : {}),
36
36
  ...(options.loopback ? { loopback: true } : {}),
37
+ ...(options.own ? { own: options.own } : {}),
37
38
  ...(githubApp ? { githubApp } : {}),
38
39
  ...(options.githubMcpOrigin ? { githubMcpOrigin: options.githubMcpOrigin } : {}),
39
40
  ...(options.githubTimer ? { githubTimer: options.githubTimer } : {}),
@@ -57,9 +58,10 @@ export async function mcpForClaim(options) {
57
58
  // private-network hosts read now, and dialled at the address checked: a name that resolves somewhere private since the
58
59
  // save, or a host the owner no longer allows, is refused unsent. A URL on loopback is reached only by a runner told
59
60
  // so by the local-install server beside it, in its own process (options.loopback): never by what a store says, so
60
- // one host's local install never opens loopback for another host's runner on a shared store.
61
+ // one host's local install never opens loopback for another host's runner on a shared store; and never at that
62
+ // server's own ports (options.own).
61
63
  reach: async (url, signal) => {
62
- const at = await mcpServerAt(new URL(url), signal, network, { allowed: await privateOAuthHosts(options.store), loopback: options.loopback === true });
64
+ const at = await mcpServerAt(new URL(url), signal, network, { allowed: await privateOAuthHosts(options.store), loopback: options.loopback === true, own: options.own ?? [] });
63
65
  return "refused" in at ? { refused: at.refused } : { send: dialAt(network, at.address, options.fetch ?? fetch) };
64
66
  },
65
67
  beforeCall: step.beforeCall,
@@ -130,8 +130,10 @@ type PiMessage = {
130
130
  export declare function routeOf(model: string | PinnedModel | undefined, env?: NodeJS.ProcessEnv, tier?: Tier, wires?: readonly Wire[], upstream?: typeof fetch, redact?: Redact): Promise<ModelRoute>;
131
131
  /** A fetch that answers Anthropic Messages requests on `target`, through pi-ai's `models`. A provider's error text, which
132
132
  * pi records, goes through `redact` (the runner's one redactor): a provider that echoes its key leaves none there.
133
- * `upstream`: the route's own fetch, for a model that does not speak Messages (absent: the network). */
134
- export declare function messagesFetch(models: PiModels, target: PiModel, redact?: Redact, upstream?: typeof fetch): typeof fetch;
133
+ * `upstream`: the route's own fetch, for a model that does not speak Messages (absent: the network). A request pi-ai
134
+ * sends to OpenRouter carries AgentRun's app attribution unless `env` turns it off (kernel openrouter-attribution.ts),
135
+ * as one the model proxy sends there does; a request to any other provider carries none. */
136
+ export declare function messagesFetch(models: PiModels, target: PiModel, redact?: Redact, upstream?: typeof fetch, env?: NodeJS.ProcessEnv): typeof fetch;
135
137
  /** A text-tools re-ask's output limit: the most tokens it may answer with when what is left of the request's hold is
136
138
  * `leftUsd` (its first try's input as it was billed and its output limit `outputHeld`, less every try so far) and its
137
139
  * input, the prompt `last` was asked with, is priced uncached at the dearer of the input and cache-write prices, as the