@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52

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 (232) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/README.md +236 -30
  3. package/dist/adapters.js +1 -1
  4. package/dist/agent-delete.d.ts +13 -2
  5. package/dist/agent-delete.js +14 -5
  6. package/dist/agents-store.d.ts +5 -1
  7. package/dist/agents-store.js +17 -7
  8. package/dist/api-only.d.ts +6 -3
  9. package/dist/api-only.js +8 -5
  10. package/dist/archil-routes.d.ts +1 -0
  11. package/dist/archil-routes.js +28 -2
  12. package/dist/capacity.d.ts +50 -0
  13. package/dist/capacity.js +49 -0
  14. package/dist/cli-learning/claude-wire.d.ts +41 -0
  15. package/dist/cli-learning/claude-wire.js +258 -0
  16. package/dist/cli-learning/cli.d.ts +11 -0
  17. package/dist/cli-learning/cli.js +241 -0
  18. package/dist/cli-learning/codex-worktree.d.ts +10 -0
  19. package/dist/cli-learning/codex-worktree.js +119 -0
  20. package/dist/cli-learning/connections.d.ts +62 -0
  21. package/dist/cli-learning/connections.js +87 -0
  22. package/dist/cli-learning/entry.d.ts +1 -0
  23. package/dist/cli-learning/entry.js +4 -0
  24. package/dist/cli-learning/evidence.d.ts +78 -0
  25. package/dist/cli-learning/evidence.js +492 -0
  26. package/dist/cli-learning/hook.d.ts +33 -0
  27. package/dist/cli-learning/hook.js +544 -0
  28. package/dist/cli-learning/install.d.ts +33 -0
  29. package/dist/cli-learning/install.js +335 -0
  30. package/dist/cli-learning/observation-proof.d.ts +14 -0
  31. package/dist/cli-learning/observation-proof.js +10 -0
  32. package/dist/cli-learning/policy.d.ts +48 -0
  33. package/dist/cli-learning/policy.js +363 -0
  34. package/dist/cli-learning/schema.d.ts +16 -0
  35. package/dist/cli-learning/schema.js +27 -0
  36. package/dist/cli-learning/state.d.ts +23 -0
  37. package/dist/cli-learning/state.js +61 -0
  38. package/dist/cli.js +24 -2
  39. package/dist/computer-setting.d.ts +8 -0
  40. package/dist/computer-setting.js +11 -0
  41. package/dist/computers.d.ts +6 -2
  42. package/dist/computers.js +2 -2
  43. package/dist/console/assets/index-B-D0EM3j.js +733 -0
  44. package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
  45. package/dist/console/index.html +2 -2
  46. package/dist/email/email-faux.d.ts +3 -1
  47. package/dist/email/email-faux.js +3 -2
  48. package/dist/email/routes.js +22 -12
  49. package/dist/fal-price.d.ts +76 -0
  50. package/dist/fal-price.js +368 -0
  51. package/dist/harness-install.d.ts +6 -2
  52. package/dist/harness-install.js +40 -8
  53. package/dist/harness.d.ts +1 -1
  54. package/dist/harness.js +2 -2
  55. package/dist/learn/commit.d.ts +5 -0
  56. package/dist/learn/commit.js +4 -1
  57. package/dist/learn/compile.d.ts +13 -5
  58. package/dist/learn/compile.js +24 -7
  59. package/dist/learn/delete.d.ts +12 -6
  60. package/dist/learn/delete.js +17 -11
  61. package/dist/learn/folder.d.ts +11 -0
  62. package/dist/learn/folder.js +20 -3
  63. package/dist/learn/learning-of.d.ts +8 -0
  64. package/dist/learn/learning-of.js +8 -0
  65. package/dist/learn/learning.sh +14 -1
  66. package/dist/learn/promote.d.ts +51 -7
  67. package/dist/learn/promote.js +51 -8
  68. package/dist/learn/secrets.js +14 -3
  69. package/dist/learning-reset.d.ts +18 -0
  70. package/dist/learning-reset.js +115 -0
  71. package/dist/learning-routes.d.ts +1 -1
  72. package/dist/learning-words.d.ts +6 -1
  73. package/dist/learning-words.js +6 -1
  74. package/dist/learning.d.ts +8 -6
  75. package/dist/learning.js +5 -4
  76. package/dist/llms.txt +1 -0
  77. package/dist/mcp-gateway.d.ts +39 -2
  78. package/dist/mcp-gateway.js +41 -10
  79. package/dist/mcp-pin-first.js +3 -2
  80. package/dist/mcp-private-hosts.d.ts +24 -3
  81. package/dist/mcp-private-hosts.js +53 -3
  82. package/dist/mcp-servers-store.d.ts +1 -0
  83. package/dist/mcp-servers-store.js +2 -1
  84. package/dist/media-duration.d.ts +2 -0
  85. package/dist/media-duration.js +136 -0
  86. package/dist/model-gateway.d.ts +2 -0
  87. package/dist/model-gateway.js +3 -1
  88. package/dist/native/runtimes.d.ts +2 -0
  89. package/dist/native/runtimes.js +2 -0
  90. package/dist/observation/learning.d.ts +32 -0
  91. package/dist/observation/learning.js +66 -0
  92. package/dist/observation/observer.d.ts +8 -1
  93. package/dist/observation/observer.js +89 -9
  94. package/dist/observation/schema.js +12 -4
  95. package/dist/observation/usage-identity.d.ts +9 -0
  96. package/dist/observation/usage-identity.js +11 -0
  97. package/dist/openapi.js +133 -24
  98. package/dist/provider.d.ts +8 -0
  99. package/dist/provider.js +14 -2
  100. package/dist/refusal-words.d.ts +0 -3
  101. package/dist/refusal-words.js +0 -3
  102. package/dist/request-metadata.d.ts +20 -0
  103. package/dist/request-metadata.js +24 -0
  104. package/dist/run-launch.d.ts +27 -4
  105. package/dist/run-launch.js +18 -3
  106. package/dist/run-learning-served.d.ts +2 -2
  107. package/dist/run-usage.d.ts +48 -4
  108. package/dist/run-usage.js +156 -39
  109. package/dist/run-view.d.ts +2 -0
  110. package/dist/run-view.js +8 -7
  111. package/dist/runner/adapter-loop.d.ts +3 -1
  112. package/dist/runner/adapter-loop.js +41 -35
  113. package/dist/runner/adapter-run-spec.d.ts +1 -1
  114. package/dist/runner/adapter-run-spec.js +15 -15
  115. package/dist/runner/audit.d.ts +8 -3
  116. package/dist/runner/audit.js +21 -6
  117. package/dist/runner/beside.d.ts +13 -0
  118. package/dist/runner/beside.js +27 -8
  119. package/dist/runner/claim-secrets.d.ts +2 -1
  120. package/dist/runner/claim-secrets.js +5 -3
  121. package/dist/runner/cli-run-spec.d.ts +1 -1
  122. package/dist/runner/cli-run-spec.js +14 -13
  123. package/dist/runner/conformance/harness.js +4 -2
  124. package/dist/runner/disk-free.d.ts +44 -0
  125. package/dist/runner/disk-free.js +96 -0
  126. package/dist/runner/dispatch.js +4 -2
  127. package/dist/runner/feedback-round.d.ts +12 -8
  128. package/dist/runner/feedback-round.js +16 -30
  129. package/dist/runner/harness-loops.js +8 -3
  130. package/dist/runner/journal-kinds.d.ts +4 -1
  131. package/dist/runner/learning-end.d.ts +2 -1
  132. package/dist/runner/learning-end.js +51 -22
  133. package/dist/runner/main.d.ts +17 -6
  134. package/dist/runner/main.js +187 -45
  135. package/dist/runner/mcp-claim.js +1 -1
  136. package/dist/runner/mcp-run.d.ts +9 -0
  137. package/dist/runner/mcp-run.js +16 -1
  138. package/dist/runner/model-route.js +7 -4
  139. package/dist/runner/presence.d.ts +11 -2
  140. package/dist/runner/presence.js +31 -3
  141. package/dist/runner/promotion.d.ts +40 -21
  142. package/dist/runner/promotion.js +130 -59
  143. package/dist/runner/run-child-host.d.ts +12 -15
  144. package/dist/runner/run-child-host.js +52 -112
  145. package/dist/runner/run-errors.js +2 -0
  146. package/dist/runner/runner-check.d.ts +51 -0
  147. package/dist/runner/runner-check.js +206 -0
  148. package/dist/runner/runner-metrics.d.ts +19 -0
  149. package/dist/runner/runner-metrics.js +49 -0
  150. package/dist/runner/runner.d.ts +37 -0
  151. package/dist/runner/runner.js +58 -6
  152. package/dist/runner/sdk-loop.d.ts +2 -2
  153. package/dist/runner/sdk-loop.js +37 -25
  154. package/dist/runner/store-port.d.ts +3 -0
  155. package/dist/runner/workflow-spec.js +3 -3
  156. package/dist/runs-over-store.d.ts +13 -3
  157. package/dist/runs-over-store.js +71 -16
  158. package/dist/sdk/check.d.ts +6 -5
  159. package/dist/sdk/check.js +17 -16
  160. package/dist/sdk/runs.d.ts +22 -2
  161. package/dist/sdk/runs.js +167 -82
  162. package/dist/server.d.ts +3 -0
  163. package/dist/server.js +230 -43
  164. package/dist/skills/agentrun-serve/SKILL.md +52 -7
  165. package/dist/start-switches.js +2 -0
  166. package/dist/stats.d.ts +4 -0
  167. package/dist/stats.js +1 -1
  168. package/dist/store/agent-body.d.ts +16 -0
  169. package/dist/store/agent-body.js +20 -3
  170. package/dist/store/dialect.d.ts +2 -0
  171. package/dist/store/dialect.js +1 -0
  172. package/dist/store/index.d.ts +3 -3
  173. package/dist/store/index.js +2 -2
  174. package/dist/store/journal/storage.d.ts +2 -0
  175. package/dist/store/journal/storage.js +2 -1
  176. package/dist/store/postgres/connection.d.ts +5 -2
  177. package/dist/store/postgres/connection.js +19 -7
  178. package/dist/store/postgres/dialect.js +1 -0
  179. package/dist/store/postgres/migrate.d.ts +30 -0
  180. package/dist/store/postgres/migrate.js +72 -5
  181. package/dist/store/postgres/migration-lint.d.ts +8 -0
  182. package/dist/store/postgres/migration-lint.js +119 -0
  183. package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
  184. package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
  185. package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
  186. package/dist/store/postgres/store.d.ts +8 -3
  187. package/dist/store/postgres/store.js +31 -11
  188. package/dist/store/schema.d.ts +32 -2
  189. package/dist/store/schema.js +74 -5
  190. package/dist/store/sqlite/run-launch.d.ts +31 -1
  191. package/dist/store/sqlite/run-launch.js +111 -2
  192. package/dist/store/sqlite/run-patch.d.ts +2 -1
  193. package/dist/store/sqlite/run-patch.js +4 -3
  194. package/dist/store/sqlite/store.d.ts +17 -0
  195. package/dist/store/sqlite/store.js +226 -37
  196. package/dist/store/store-schema.d.ts +34 -0
  197. package/dist/store/store-schema.js +125 -0
  198. package/dist/store/store.d.ts +120 -5
  199. package/dist/store/store.js +13 -0
  200. package/dist/store-reads/analytics.d.ts +3 -2
  201. package/dist/store-reads/analytics.js +20 -8
  202. package/dist/store-reads/learning.d.ts +12 -8
  203. package/dist/store-reads/learning.js +33 -24
  204. package/dist/store-reads/loop.d.ts +4 -3
  205. package/dist/store-reads/loop.js +7 -5
  206. package/dist/store-view.d.ts +4 -3
  207. package/dist/store-view.js +11 -7
  208. package/dist/template-eval.js +4 -4
  209. package/dist/templates.d.ts +6 -2
  210. package/dist/templates.js +7 -5
  211. package/dist/timeline/labels.js +1 -1
  212. package/dist/tool-gate.d.ts +4 -2
  213. package/dist/tools.js +1 -1
  214. package/dist/unified-usage.d.ts +24 -0
  215. package/dist/unified-usage.js +400 -0
  216. package/dist/uploads-archil.d.ts +100 -0
  217. package/dist/uploads-archil.js +431 -0
  218. package/dist/uploads.d.ts +52 -1
  219. package/dist/uploads.js +186 -108
  220. package/dist/validate.js +5 -1
  221. package/dist/web-save.d.ts +3 -0
  222. package/dist/web-save.js +17 -2
  223. package/dist/workspace/archil-disk.d.ts +6 -5
  224. package/dist/workspace/archil-disk.js +27 -12
  225. package/dist/workspace/archil-exec.js +1 -1
  226. package/dist/workspace/archil.js +4 -3
  227. package/dist/workspace/revision-skills.js +24 -11
  228. package/dist/workspace/synced-folder.d.ts +3 -3
  229. package/dist/workspace/synced-folder.js +7 -6
  230. package/package.json +10 -10
  231. package/skills/agentrun-serve/SKILL.md +52 -7
  232. package/dist/console/assets/index-D7G6o-1E.js +0 -720
@@ -18,7 +18,7 @@ import { stopRunWith } from "../paid-calls.js";
18
18
  import { dirname, join } from "node:path";
19
19
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
20
20
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
21
- import { checkRaise, followUpOf, freeModelRequestsOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
21
+ import { checkRaise, followUpOf, freeRequestLimitOf, parkOf, planCapModel } from "@parcha/agentrun-kernel/kernel/cap";
22
22
  import { PLAN_LIMIT_WORDS } from "@parcha/agentrun-kernel";
23
23
  import { modelWire } from "../wires.js";
24
24
  import { confineOf, noNewPrivsPrefix, standsIn, thinkingFor } from "../adapters.js";
@@ -38,7 +38,7 @@ import { firstMessage, inputMessage, messageText } from "../run-manifest.js";
38
38
  import { learningStartOf, seedFailed } from "../run-launch.js";
39
39
  import { readsFiles, systemOf } from "../skills.js";
40
40
  import { DATA_ENV } from "../server-fs.js";
41
- import { placeRunInputs } from "../uploads.js";
41
+ import { filesToCopy, placeRunInputs } from "../uploads.js";
42
42
  import { recordingsFolder, runFolder, scratchFolder } from "../workspace/paths.js";
43
43
  import { openRunWorkspace } from "../workspace/run-workspace.js";
44
44
  import { layOwnSkills } from "../workspace/revision-skills.js";
@@ -57,7 +57,7 @@ import { hostToolOf } from "../host-tools.js";
57
57
  import { ASK_TOOL, askPerson } from "../tools.js";
58
58
  import { fakedPlane } from "../web-fake.js";
59
59
  import { claimModelEnv, claimModelKey, claimSecrets, claimSpendOff, holdRunKey, keyedAtClaim, hostDecisionKeys, learnedDecisionKeys, tierModelKeys, withoutModelKeys } from "./claim-secrets.js";
60
- import { mcpWhereHeld } from "./mcp-run.js";
60
+ import { mcpWhereHeld, mediaForClaim } from "./mcp-run.js";
61
61
  import { held as runnerSeam, heldSignInReads } from "./held.js";
62
62
  import { DECISION_PROVIDER_KEYS, TOOL_PLANE_ENV } from "../tool-plane.js";
63
63
  import { decisionProvidersIn } from "../decisions.js";
@@ -146,9 +146,10 @@ export async function cliCapModel(entry, env, ref) {
146
146
  * run whose plane resolves it to native gets the harness's own search (#2458), this run's alone; whatever the runner's
147
147
  * own environment says of a plane is never the run's. Whether each search runs is the tool's setting at that search
148
148
  * (SessionIO.permission, the gate), never this plane, which is frozen when the run is made. */
149
- export function cliRunEnv(env, data, claimed = {}, plane, runKey) {
150
- // A run with its own model key: that key alone, in the variables its route sends (claimModelEnv, never enumerable).
151
- const out = claimModelEnv(env ?? {}, claimed, runKey);
149
+ export function cliRunEnv(env, data, claimed = {}, plane, runKey, claim) {
150
+ // A run with its own model key: that key alone, in the variables its route sends (claimModelEnv, never enumerable), and
151
+ // the claim's request metadata beside it (request-metadata.ts, never enumerable either).
152
+ const out = claimModelEnv(env ?? {}, claimed, runKey, claim);
152
153
  Object.defineProperty(out, DATA_ENV, { value: data, enumerable: true, writable: true, configurable: true });
153
154
  delete out[TOOL_PLANE_ENV];
154
155
  if (plane && Object.keys(plane).length)
@@ -330,7 +331,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
330
331
  // A credential the claim opens mid-run (a GitHub App token, a saved or per_run server's) joins the run's redactors.
331
332
  const hold = (values) => { for (const redact of [...(run.redact ? [heldRedactor(run.redact)] : []), cut])
332
333
  redact.hold(values); };
333
- const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach });
334
+ const mcp = await mcpWhereHeld({ claim, store: deps.store, sealKey: deps.sealKey, grants: granted, harness: run.harness, work: () => runFolder(deps.data, runRow.agentId, claim.runId), launchInput: launch.input, hold, githubAppAccess: (store, key, input) => githubAppAccess(store, key, input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub: launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github", hold, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) }), ...(deps.githubMcpOrigin ? { githubMcpOrigin: deps.githubMcpOrigin } : {}), ...reach, capped: () => launch.maxCostUsd !== undefined, media: mediaForClaim(deps.env, web, deps.saveSlots) });
334
335
  // The claim's MCP goes to the loop, which lets it go; a build that throws lets it go itself.
335
336
  holds.hold({ passed: mcp });
336
337
  // The run's mode is the server's: Mode 2 where its Archil settings are saved (archil-settings.ts), the run's folder then
@@ -361,7 +362,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
361
362
  holds.hold({ checkout });
362
363
  // A run's own process copies nothing: its runner placed them before the process started (run-child-host.ts).
363
364
  if (!(deps.sealKey === undefined && runnerSeam()))
364
- await placeRunInputs(deps.data, claim.runId, ws.workspace, launch.files ?? [], messageText(launch.input));
365
+ await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
365
366
  // The run's skills and its learning seed laid before its computer exists, as the pi spec lays them (adapter-run-spec.ts):
366
367
  // on Archil the computer's mount takes the disk's write delegation, and a lay over the disk's file API after it is
367
368
  // refused (409) while the mount holds it.
@@ -452,7 +453,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
452
453
  // carries only where it is, and its CLI says it is signed in before the run starts. A run that brought its own key
453
454
  // runs on that key, and a run in a sandbox place on the model keys.
454
455
  const login = keyed ? undefined : await loginForRun(deps.store.settings, deps.data, deps.env ?? {}, name, launch.place);
455
- const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey), login);
456
+ const env = withClaudeLogin(cliRunEnv(deps.env, deps.data, claimed, launch.plane, runKey, claim), login);
456
457
  const chosen = await modelsOf(entry, env, modelAskOf(launch.model, body.model));
457
458
  await planBeforeRun(env, chosen.model);
458
459
  if (login && entry.priceModel(env, chosen.model).provider === CLAUDE_LOGIN_PROVIDER) {
@@ -533,8 +534,8 @@ async function cliSpec(launch, run, deps, claim, holds) {
533
534
  },
534
535
  // What its audit's shadow took beside it, read by every gate with its own sessions (none: it starts none).
535
536
  ...(besideOf ? { beside: besideOf } : {}),
536
- // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS).
537
- freeRequests: freeModelRequestsOf(deps.env),
537
+ // The most requests on free models it makes, capped or not (AGENTRUN_FREE_MODEL_REQUESTS, or the agent's lower max_requests).
538
+ freeRequests: freeRequestLimitOf(deps.env, body.maxRequests),
538
539
  };
539
540
  const cap = capUsd === undefined
540
541
  ? undefined
@@ -596,7 +597,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
596
597
  const audits = { store: deps.store, agentId: runRow.agentId, revisionId: runRow.revisionId, context, log, folder: learningFolder, shown, sealKey: deps.sealKey, spendOff };
597
598
  // A replay run's or a shadow's grader (runner/compare-end.ts), on a proxy of its own beside the CLI session's, as pi's
598
599
  // is (adapter-run-spec.ts graderRouteOf), reached through the session's port while it is up. None: compared whole.
599
- const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut]) : undefined;
600
+ const graderRoute = launch.replay || launch.audit ? await graderRouteOf(body, keyed, runKey, claimed, cut, log, deps, [held, cut], claim) : undefined;
600
601
  if (graderRoute)
601
602
  tierRoutes.set(GRADER, graderRoute);
602
603
  // Each step writes the store or reads another run (runner/learned-first.ts): in a run's own process its runner takes
@@ -643,7 +644,7 @@ async function cliSpec(launch, run, deps, claim, holds) {
643
644
  const tierKeys = keyed ? {} : await tierModelKeys({ store: deps.store, sealKey: deps.sealKey, env: deps.env }, learnedTiers(workflows));
644
645
  for (const redact of new Set([held, cut]))
645
646
  holdClaimed(redact, tierKeys);
646
- const modelEnv = claimModelEnv(deps.env, { ...claimed, ...tierKeys }, runKey);
647
+ const modelEnv = claimModelEnv(deps.env, { ...claimed, ...tierKeys }, runKey, claim);
647
648
  const tiers = new Map();
648
649
  for (const [tier, routed] of await learnedTierRoutes(workflows, modelEnv, (tier) => deps.routeOf(undefined, modelEnv, tier, PI_WIRES, undefined, cut))) {
649
650
  if ("why" in routed)
@@ -1059,7 +1059,9 @@ const CASES = [
1059
1059
  await w.ended("parked");
1060
1060
  const callId = await w.askedCall();
1061
1061
  // Both sent before either is awaited (on Postgres, each on its own pooled connection). Whichever is written first, the
1062
- // store's one-answer index refuses the other: no order is imposed, so the case holds for either winner.
1062
+ // store refuses the other: no order is imposed, so the case holds for either winner. The other meets the one-answer
1063
+ // index (AnswerTaken) or, when the winner's answer already ended the run, the run's end (RunFinal): which one is
1064
+ // timing, so either stands, and the index itself is approval-double-click's (its call held so the run cannot end).
1063
1065
  const settled = await Promise.allSettled([
1064
1066
  sendCommand(w.server, RUN, { kind: "approve", body: { approval: callId } }),
1065
1067
  sendCommand(w.server, RUN, { kind: "deny", body: { approval: callId } }),
@@ -1067,7 +1069,7 @@ const CASES = [
1067
1069
  const won = settled.filter((r) => r.status === "fulfilled");
1068
1070
  const lost = settled.filter((r) => r.status === "rejected");
1069
1071
  assert.equal(won.length, 1, `one answer is written, not both: ${JSON.stringify(settled.map((r) => r.status))}`);
1070
- assert.ok(lost[0]?.reason instanceof AnswerTaken, `the other is refused by the store as answered already (AnswerTaken), never a bare constraint: ${String(lost[0]?.reason)}`);
1072
+ assert.ok(lost[0]?.reason instanceof AnswerTaken || lost[0]?.reason instanceof RunFinal, `the other is refused by the store, answered already (AnswerTaken) or the run ended on the winner (RunFinal), never a bare constraint: ${String(lost[0]?.reason)}`);
1071
1073
  await w.ended("ended");
1072
1074
  const winner = won[0].value;
1073
1075
  assert.equal(ran.asked, winner.kind === "approve" ? 1 : 0, "the run acted on the answer written, never the other");
@@ -0,0 +1,44 @@
1
+ import type { KeyEnv } from "../key-meta.js";
2
+ import type { Settings } from "../store/store.js";
3
+ /** The file in the server's data root that holds its id (made once, kept across starts). */
4
+ export declare const DATA_ROOT_FILE = "data-root.id";
5
+ /** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
6
+ export declare const DATA_ROOT_KEY = "server.data_root";
7
+ /** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
8
+ export declare function dataRootIdIn(dataDir: string): string | undefined;
9
+ /** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
10
+ * the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
11
+ export declare function recordDataRoot(store: {
12
+ settings: Pick<Settings, "put">;
13
+ }, dataDir: string): Promise<string>;
14
+ /** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
15
+ * last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
16
+ * none started yet), which a caller takes as shared. */
17
+ export declare function sharesServerDisk(store: {
18
+ settings: Pick<Settings, "get">;
19
+ }, dataDir: string): Promise<boolean | undefined>;
20
+ /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
21
+ * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
22
+ * (runner-check.ts RUN_ENV_KEY). */
23
+ export declare function serverInArchilMode(store: {
24
+ settings: Pick<Settings, "get">;
25
+ }): Promise<boolean>;
26
+ /** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
27
+ * whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
28
+ * holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
29
+ * is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
30
+ * on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
31
+ export declare function diskFreeRefusal(store: {
32
+ settings: Pick<Settings, "get">;
33
+ }, dataDir: string, env: KeyEnv, storeKind: string): Promise<string | undefined>;
34
+ /** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
35
+ export declare const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
36
+ /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
37
+ export declare const DISK_FREE_NO_ARCHIL: string;
38
+ /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
39
+ export declare const DISK_FREE_GATE_MS = 5000;
40
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
41
+ * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
42
+ export declare function diskFreeGate(store: {
43
+ settings: Pick<Settings, "get">;
44
+ }, dataDir: string, env: KeyEnv, storeKind: string, now?: () => number): (fresh: boolean) => Promise<string | undefined>;
@@ -0,0 +1,96 @@
1
+ // A runner on a disk of its own (a disk-free runner): `agentrun-serve runner --data D` where D is the runner's own local
2
+ // directory, not the server's, on the Postgres store AGENTRUN_STORE_URL names. Its data directory then holds only what
3
+ // is the runner's: its heartbeat, its runs' uid slots and their scratch, and the harnesses it installs at a claim. It never
4
+ // reads the server's: a run's folder is on Archil (Mode 2), which every machine reaches; Mode 1 keeps it on the server's
5
+ // own disk, which this runner can't see, so a disk-free runner claims nothing while the server is in Mode 1.
6
+ //
7
+ // Which disk is the server's: the server keeps an id of its data root in a file there (DATA_ROOT_FILE, made once) and
8
+ // says it in the store at each start (DATA_ROOT_KEY). A runner whose data directory holds the same id shares the server's
9
+ // disk (the image's server-and-runner, compose's runners on one /data volume); any other runner is disk-free. A store
10
+ // whose server has not said its data root yet (one older than this) is taken as shared, as every runner was before.
11
+ // SQLite is in the data directory, so a runner on it always shares the server's.
12
+ import { randomBytes } from "node:crypto";
13
+ import { readFileSync, writeFileSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ import { ARCHIL_SETTINGS_ENV, loadArchilSettings } from "../archil-settings.js";
16
+ import { serverRunEnv } from "./runner-check.js";
17
+ /** The file in the server's data root that holds its id (made once, kept across starts). */
18
+ export const DATA_ROOT_FILE = "data-root.id";
19
+ /** The store.settings key a server keeps its data root's id under at each start: `{ v: 1, id }`. */
20
+ export const DATA_ROOT_KEY = "server.data_root";
21
+ const ID = /^[0-9a-f]{32}$/;
22
+ /** The id in `dataDir`'s DATA_ROOT_FILE, or undefined when there is none (or it does not read as one). Never made here. */
23
+ export function dataRootIdIn(dataDir) {
24
+ try {
25
+ const id = readFileSync(join(dataDir, DATA_ROOT_FILE), "utf8").trim();
26
+ return ID.test(id) ? id : undefined;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ /** The server's start: its data root's id (the file's, else a new one written there, 0600), said in the store, replacing
33
+ * the last start's. Called once the server holds its data root (server-lock.ts), so no other server writes the file. */
34
+ export async function recordDataRoot(store, dataDir) {
35
+ let id = dataRootIdIn(dataDir);
36
+ if (id === undefined) {
37
+ id = randomBytes(16).toString("hex");
38
+ writeFileSync(join(dataDir, DATA_ROOT_FILE), `${id}\n`, { mode: 0o600 });
39
+ }
40
+ await store.settings.put(DATA_ROOT_KEY, { v: 1, id });
41
+ return id;
42
+ }
43
+ /** Whether a runner on `dataDir` shares its server's disk: true when its data directory holds the id the server said at its
44
+ * last start, false when it holds none or another, and undefined when the store holds none (a server older than this, or
45
+ * none started yet), which a caller takes as shared. */
46
+ export async function sharesServerDisk(store, dataDir) {
47
+ const said = await store.settings.get(DATA_ROOT_KEY);
48
+ const id = typeof said === "object" && said !== null ? said.id : undefined;
49
+ if (typeof id !== "string" || !ID.test(id))
50
+ return undefined;
51
+ return dataRootIdIn(dataDir) === id;
52
+ }
53
+ /** Whether the server is in Mode 2, by what the server holds, never by this runner's environment: the Archil settings
54
+ * saved in the store, or set in the server's own environment, whose names (never values) it says at each start
55
+ * (runner-check.ts RUN_ENV_KEY). */
56
+ export async function serverInArchilMode(store) {
57
+ if ((await loadArchilSettings(store)) !== undefined)
58
+ return true;
59
+ const names = await serverRunEnv(store);
60
+ return names !== undefined && [ARCHIL_SETTINGS_ENV.region, ARCHIL_SETTINGS_ENV.s3Url].every((name) => names.includes(name));
61
+ }
62
+ /** Why a runner on `dataDir` can't serve the runs its store holds now, or undefined while it can. On Postgres, a runner
63
+ * whose `dataDir` is not the server's disk can't while the server keeps runs' folders on that disk (Mode 1: the server
64
+ * holds no Archil settings, saved or in its environment), whatever this runner's environment holds; nor while the server
65
+ * is in Mode 2 by its own environment and this runner holds no Archil settings, so its claim would keep the run's folder
66
+ * on its own disk. On SQLite always undefined: the store is in the data directory, so the runner's is the server's. */
67
+ export async function diskFreeRefusal(store, dataDir, env, storeKind) {
68
+ if (storeKind === "sqlite")
69
+ return undefined;
70
+ if ((await sharesServerDisk(store, dataDir)) !== false)
71
+ return undefined;
72
+ if (!(await serverInArchilMode(store)))
73
+ return DISK_FREE_MODE_1;
74
+ if ((await loadArchilSettings(store, env)) === undefined)
75
+ return DISK_FREE_NO_ARCHIL;
76
+ return undefined;
77
+ }
78
+ /** A disk-free runner's words while the server is in Mode 1: what the runner can't do, why, and the two ways out. */
79
+ export const DISK_FREE_MODE_1 = "this runner's data directory is not the server's, and the server keeps each run's folder on its own disk (Mode 1: the server holds no Archil settings, saved or in its environment), which this runner can't reach. Save the Archil settings so runs' folders are on Archil (Mode 2), or start the runner on the server's data directory.";
80
+ /** A disk-free runner's words while the server is in Mode 2 by its own environment and this runner holds no Archil settings. */
81
+ export const DISK_FREE_NO_ARCHIL = `this runner's data directory is not the server's, and the server keeps each run's folder on Archil (Mode 2) by the Archil settings in its environment, which this runner does not hold. Hand this runner the server's ${ARCHIL_SETTINGS_ENV.region} and ${ARCHIL_SETTINGS_ENV.s3Url} (and ${ARCHIL_SETTINGS_ENV.image} when the server has it), or save the Archil settings in the store.`;
82
+ /** How long a gate's answer is kept between polls (diskFreeGate): a change of mode reaches a runner within this. */
83
+ export const DISK_FREE_GATE_MS = 5_000;
84
+ /** The runner's claim gate (runner.ts claimGate) for a runner on `dataDir`: diskFreeRefusal, its answer kept for
85
+ * DISK_FREE_GATE_MS between polls and read again when asked fresh. */
86
+ export function diskFreeGate(store, dataDir, env, storeKind, now = Date.now) {
87
+ let kept;
88
+ return async (fresh) => {
89
+ const at = now();
90
+ if (!fresh && kept && at - kept.at < DISK_FREE_GATE_MS)
91
+ return kept.words;
92
+ const words = await diskFreeRefusal(store, dataDir, env, storeKind);
93
+ kept = { at, words };
94
+ return words;
95
+ };
96
+ }
@@ -8,7 +8,7 @@
8
8
  // through the inner loop the moment it is chosen. A launch whose harness this runner does not run, or whose body cannot
9
9
  // be read, fails the run in words (the dispatch's start() throws, which the runner records as the run failing).
10
10
  import { harnessOfBody } from "../harness.js";
11
- import { readLaunchBody } from "../run-launch.js";
11
+ import { launchOnItsDisk, readLaunchBody } from "../run-launch.js";
12
12
  /** A launch naming a harness this runner does not run. */
13
13
  export class UnknownHarness extends Error {
14
14
  harness;
@@ -58,7 +58,9 @@ function dispatchLoop(deps, loopDeps) {
58
58
  const innerDeps = { ...loopDeps, delivered: Promise.all([loopDeps.delivered ?? Promise.resolve(), earlyReplayed]).then(() => undefined) };
59
59
  async function begin(claim) {
60
60
  const row = await deps.launchOf(claim.runId);
61
- const launch = readLaunchBody(row.body);
61
+ // The launch as this run runs it: on a named disk, with nothing learned on another disk (launchOnItsDisk).
62
+ const read = readLaunchBody(row.body);
63
+ const launch = read && launchOnItsDisk(read);
62
64
  if (!launch)
63
65
  throw new LaunchUnreadable(claim.runId);
64
66
  const harness = harnessOfBody(row.body);
@@ -15,13 +15,17 @@ export interface KeptEnd {
15
15
  readonly outcome?: EndData["outcome"];
16
16
  readonly endedAt: number;
17
17
  }
18
- /** A feedback round, as its steer's body carries it (`feedback`) and its FEEDBACK entry keeps it: the round, whether the
19
- * grade said right, the grade's words (`text`), and the end the run had when the grade opened it again (`kept`). */
18
+ /** A feedback round, as its FEEDBACK entry keeps it: the round, whether the grade said right, and the grade's words
19
+ * (`text`). */
20
20
  export interface FeedbackData {
21
21
  readonly round: FeedbackRound;
22
22
  readonly correct: boolean;
23
23
  readonly text: string;
24
- readonly kept?: KeptEnd;
24
+ }
25
+ /** A feedback round as its steer's body carries it (`feedback`, beside the words): with the end the run had when the
26
+ * grade opened it again (`kept`), which the steer's taking keeps as the job's end (KINDS.jobEnd, beside FEEDBACK). */
27
+ export interface FeedbackSteer extends FeedbackData {
28
+ readonly kept: KeptEnd;
25
29
  }
26
30
  /** Whether the run's root `entries` hold a job's end kept for its look-back (KINDS.jobEnd) with no run end after it: the
27
31
  * job ended and its look-back is under way, whether or not that look-back has asked anything yet. A follow-up's turn
@@ -31,8 +35,8 @@ export declare function jobEndOpen(entries: readonly {
31
35
  }[]): boolean;
32
36
  /** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
33
37
  * look-back under way, or one whose job's end was never kept):
34
- * - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
35
- * - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
38
+ * - the job's end kept for it (KINDS.jobEnd, with its time), newer than the run's last end: by its claim before the
39
+ * end-of-run step, or for a grade's round by the steer's taking;
36
40
  * - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
37
41
  * A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
38
42
  export declare function keptEndOf(entries: readonly {
@@ -45,9 +49,9 @@ export declare function keptEndOf(entries: readonly {
45
49
  export declare function feedbackRoundOf(grade: {
46
50
  readonly path: RunPath;
47
51
  }, label: string | undefined): FeedbackRound | undefined;
48
- /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
49
- * message API never does), else undefined. */
50
- export declare function feedbackOf(body: unknown): FeedbackData | undefined;
52
+ /** The feedback round a steer's body asks for (`body.feedback`, the server's own: openFeedbackRound writes it with the
53
+ * end it kept, and the message API never does), else undefined. */
54
+ export declare function feedbackOf(body: unknown): FeedbackSteer | undefined;
51
55
  /** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
52
56
  * it, else undefined. */
53
57
  export declare function pendingFeedbackOf(entries: readonly {
@@ -15,18 +15,12 @@ import { RunFinal } from "../store/store.js";
15
15
  import { KINDS } from "./journal-kinds.js";
16
16
  import { commandRequest } from "./loop.js";
17
17
  export const FEEDBACK_ROUNDS = ["correction"];
18
- const END_STATES = ["ended", "stopped", "failed"];
19
- const OUTCOMES = ["completed", "escalated", "stopped", "cancelled"];
20
- /** A kept end as a steer's body or a journal entry holds it, else undefined. */
21
- function keptOf(value) {
22
- const kept = value;
23
- if (!kept || typeof kept !== "object" || !END_STATES.includes(kept.state) || typeof kept.endedAt !== "number")
18
+ /** A feedback round's `round`, `correct` and words, else undefined. */
19
+ function roundOf(fed, text) {
20
+ const round = fed;
21
+ if (!round || typeof round !== "object" || !FEEDBACK_ROUNDS.includes(round.round) || typeof round.correct !== "boolean" || typeof text !== "string")
24
22
  return undefined;
25
- if (kept.summary !== undefined && typeof kept.summary !== "string")
26
- return undefined;
27
- if (kept.outcome !== undefined && !OUTCOMES.includes(kept.outcome))
28
- return undefined;
29
- return { state: kept.state, ...(kept.summary !== undefined ? { summary: kept.summary } : {}), ...(kept.outcome !== undefined ? { outcome: kept.outcome } : {}), endedAt: kept.endedAt };
23
+ return { round: round.round, correct: round.correct, text };
30
24
  }
31
25
  /** The end run `run` has now, as a grade's round keeps it: only one a round opens again (reopenableWhere: ended, or
32
26
  * stopped by a person), with its end time. */
@@ -43,21 +37,16 @@ export function jobEndOpen(entries) {
43
37
  }
44
38
  /** The end run's look-back keeps while it runs, from the run's root `entries` and its command rows, else undefined (no
45
39
  * look-back under way, or one whose job's end was never kept):
46
- * - the job's end its claim kept before the end-of-run step (KINDS.jobEnd, with its time), newer than the run's last end;
47
- * - else the end a grade's round kept, from its FEEDBACK entry newer than the run's last end;
40
+ * - the job's end kept for it (KINDS.jobEnd, with its time), newer than the run's last end: by its claim before the
41
+ * end-of-run step, or for a grade's round by the steer's taking;
48
42
  * - else from the round's steer the grade wrote, not taken yet (the run opened again, no runner on it yet).
49
43
  * A follow-up's own turn keeps none until its job's end is kept: its run reads as going on, as main's does. */
50
44
  export function keptEndOf(entries, commands) {
51
- const last = (kind) => entries.findLastIndex((entry) => entry.kind === kind);
52
- const end = last(KINDS.end);
53
45
  if (jobEndOpen(entries)) {
54
- const data = entries[last(KINDS.jobEnd)].data;
55
- return keptOf(data?.end && data.endedAt !== undefined ? { ...data.end, endedAt: data.endedAt } : undefined);
46
+ const { end, endedAt } = entries.findLast((entry) => entry.kind === KINDS.jobEnd).data;
47
+ return { state: end.state, ...(end.summary !== undefined ? { summary: end.summary } : {}), ...(end.outcome !== undefined ? { outcome: end.outcome } : {}), endedAt };
56
48
  }
57
- const fed = last(KINDS.feedback);
58
- if (fed > end)
59
- return keptOf(entries[fed].data?.kept);
60
- const steer = commands.find((command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body)?.kept !== undefined);
49
+ const steer = commands.find((command) => command.kind === "steer" && command.takenAt === null && command.refused === null && feedbackOf(command.body) !== undefined);
61
50
  return steer ? feedbackOf(steer.body).kept : undefined;
62
51
  }
63
52
  /** What a grade asks for: `correction` for a graded run the agent finished when the grade has words, else none
@@ -66,15 +55,12 @@ export function keptEndOf(entries, commands) {
66
55
  export function feedbackRoundOf(grade, label) {
67
56
  return (grade.path === "agent" || grade.path === "handed_back") && label ? "correction" : undefined;
68
57
  }
69
- /** The feedback round a steer's body asks for (`body.feedback`, the server's own: server.ts gradeRun writes it, and the
70
- * message API never does), else undefined. */
58
+ /** The feedback round a steer's body asks for (`body.feedback`, the server's own: openFeedbackRound writes it with the
59
+ * end it kept, and the message API never does), else undefined. */
71
60
  export function feedbackOf(body) {
72
61
  const fed = body?.feedback;
73
- const text = body?.text;
74
- if (!fed || typeof fed !== "object" || !FEEDBACK_ROUNDS.includes(fed.round) || typeof fed.correct !== "boolean" || typeof text !== "string")
75
- return undefined;
76
- const kept = keptOf(fed.kept);
77
- return { round: fed.round, correct: fed.correct, text, ...(kept ? { kept } : {}) };
62
+ const round = roundOf(fed, body?.text);
63
+ return round && fed?.kept ? { ...round, kept: fed.kept } : undefined;
78
64
  }
79
65
  /** The feedback round the run's root `entries` say its next end closes: its newest FEEDBACK entry when no end came after
80
66
  * it, else undefined. */
@@ -82,7 +68,7 @@ export function pendingFeedbackOf(entries) {
82
68
  const at = entries.findLastIndex((entry) => entry.kind === KINDS.feedback);
83
69
  if (at < 0 || entries.slice(at + 1).some((entry) => entry.kind === KINDS.end))
84
70
  return undefined;
85
- return feedbackOf({ feedback: entries[at].data, text: entries[at].data?.text });
71
+ return roundOf(entries[at].data, entries[at].data?.text);
86
72
  }
87
73
  /** What the end-of-run turn of a feedback round is told before its prompt: the grade and its words. */
88
74
  export function feedbackAsk(feedback) {
@@ -125,7 +111,7 @@ export async function openFeedbackRound(store, grade, label, canTurn = () => tru
125
111
  const launched = await store.runs.launch(grade.run).catch(() => undefined);
126
112
  const launch = launched ? readLaunchBody(launched.body) : undefined;
127
113
  // Source sessions and application-owned SDK tasks cannot consume a managed feedback steer.
128
- if (launch?.native || launch?.sdk)
114
+ if (launch?.native || launch?.sdk || launch?.cli_learning)
129
115
  return null;
130
116
  const learning = launch?.learning;
131
117
  if (!learning || learning.use)
@@ -19,6 +19,7 @@ import { resolveHarness } from "./adapters/index.js";
19
19
  import { adapterRunSpecFromLaunch, PI_WIRES } from "./adapter-run-spec.js";
20
20
  import { createAdapterLoop } from "./adapter-loop.js";
21
21
  import { savedModelKeys, withModelKeys } from "./claim-secrets.js";
22
+ import { withRequestMetadata } from "../request-metadata.js";
22
23
  import { noServerKeyFor } from "../run-model-key.js";
23
24
  import { createDispatchLoop } from "./dispatch.js";
24
25
  import { cliRunSpecFromLaunch } from "./cli-run-spec.js";
@@ -72,10 +73,14 @@ async function loopOn(deps, harness, launch, runId) {
72
73
  }
73
74
  // A backend SDK run's compile turn is asked on the runner's one model route, on the agent's own model (its learning
74
75
  // start's), its key from the runner's environment, else the one saved in Settings → Model keys, read at each ask.
75
- if (launch.sdk)
76
- return createSdkLoop(launch, deps, async () => {
76
+ if (launch.sdk || launch.cli_learning)
77
+ return createSdkLoop(launch, deps, async (claim) => {
78
+ if (launch.cli_learning)
79
+ throw new Error("Connected CLI capture has no workflow execution bridge.");
77
80
  const base = deps.env ?? process.env;
78
- const env = withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base }));
81
+ // Its requests on serve's gateway name the claim's run, turn and attempt, as every other request of a claim does
82
+ // (request-metadata.ts): withModelKeys makes the env this ask's own.
83
+ const env = withRequestMetadata(withModelKeys(base, await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: base })), claim);
79
84
  // It runs after its backend reported the run complete, on no run's key: on a server that holds no gateway key it is
80
85
  // skipped in words (run-model-key.ts noServerKeyFor), nothing sent.
81
86
  const off = noServerKeyFor(env, "An SDK run's compile turn");
@@ -260,6 +260,9 @@ export interface AskData {
260
260
  readonly tool: string;
261
261
  /** The call's input as the gate saw it; null when it had none. */
262
262
  readonly args?: unknown;
263
+ /** Why a call its setting allows asks a person anyway (a tool's own ask, tools.ts ToolEntry.asks): the gate's alone,
264
+ * never one of the call's arguments. */
265
+ readonly because?: string;
263
266
  /** When it was asked (ISO), from the loop's clock; a re-ask on a resume keeps the first. */
264
267
  readonly requestedAt?: string;
265
268
  /** Its approval price (a catalog tool's, the spec's mcp priceOf); null when it has none. */
@@ -348,7 +351,7 @@ export interface EndData {
348
351
  export interface JobEndData {
349
352
  readonly end: EndData;
350
353
  readonly failedWith?: string;
351
- readonly endedAt?: number;
354
+ readonly endedAt: number;
352
355
  }
353
356
  /** An escalated workflow run's review as its end keeps it: the escalation's kind, the escalate node's label (else the node
354
357
  * it escalated at), and its summary (else the run's). Served as the run's `review`, `at` its end. */
@@ -136,7 +136,8 @@ export declare function checkDraftOf(deps: LearningEndDeps, input: {
136
136
  * its reason (DRAFT_FAILED) naming the failed checks. A first compile's earns the one recompile, as a check's hold
137
137
  * does (the agent's next due run compiles once more: learn/compile.ts newCompileAttempt); a recompile's (a revision of
138
138
  * a held workflow, or a new one after a first compile's failed drafts) stops (compileStoppedOf, heldNamesOf): nothing
139
- * compiles it again. One record per run (its digest is the run's), written once: a claim that ends the run again
139
+ * compiles it again. A revision of a connected agent's hold on give-backs is no recompile (runner/promotion.ts
140
+ * reviseAttemptOf). One record per run (its digest is the run's), written once: a claim that ends the run again
140
141
  * writes none. */
141
142
  export declare function recordDraftFailed(deps: Pick<LearningEndDeps, "store" | "log">, input: {
142
143
  runId: string;