@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
@@ -490,7 +490,7 @@ async function pinOf({ store, claim, grants, githubMcpOrigin = GITHUB_MCP_ORIGIN
490
490
  const listed = at?.tools.find((one) => one.name === tool);
491
491
  if (!at || !listed)
492
492
  throw new McpClaimRefused(`The MCP tool ${name} was not pinned when this agent's revision was saved, so this run cannot call it. Save the agent again to pin it. Nothing was sent.`);
493
- const kept = (pinned[server] ??= { url: at.url, tools: [] });
493
+ const kept = (pinned[server] ??= { url: at.url, tools: [], ...(at.meter ? { meter: at.meter } : {}) });
494
494
  if (!kept.tools.some((one) => one.name === listed.name))
495
495
  kept.tools.push(listed);
496
496
  const price = at.prices && Object.hasOwn(at.prices, listed.name) ? at.prices[listed.name] : undefined;
@@ -1,6 +1,9 @@
1
1
  import type { HostTool } from "@parcha/agentrun-kernel";
2
2
  import type { Harness } from "@earendil-works/pi-durable";
3
3
  import { type McpGatewayOptions } from "../mcp-gateway.js";
4
+ import { type MediaReader } from "../fal-price.js";
5
+ import { type WebFake } from "../web-fake.js";
6
+ import type { SaveSlots } from "../web-save.js";
4
7
  import { type OAuthNetwork } from "../mcp-oauth.js";
5
8
  import type { Store, TriggerSettings } from "../store/index.js";
6
9
  import { type ApprovalPrice, type ToolEffect } from "../tool-gate.js";
@@ -56,6 +59,9 @@ export interface McpForClaimOptions {
56
59
  connectMs?: number;
57
60
  };
58
61
  readonly githubTimer?: GithubTimer;
62
+ /** Whether the run has a spend cap, and the reader of a metered job's input media (McpGatewayOptions). */
63
+ readonly capped?: McpGatewayOptions["capped"];
64
+ readonly media?: McpGatewayOptions["media"];
59
65
  /** Each credential value the claim opens, refreshes or mints, for the run's redactors (mcp-claim.ts `hold`). */
60
66
  readonly hold?: (values: string[]) => void;
61
67
  }
@@ -83,6 +89,9 @@ export interface ClaimMcp {
83
89
  /** Drops every credential held: the pass ended, the claim is lost, or its signal aborted. */
84
90
  release(): void;
85
91
  }
92
+ /** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
93
+ * module, else the public network), in `slots`. */
94
+ export declare const mediaForClaim: (env: NodeJS.ProcessEnv, web?: WebFake, slots?: SaveSlots) => MediaReader;
86
95
  /** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
87
96
  export declare function catalogSessionNames(catalog: Pick<ClaimMcp, "tools" | "catalogOf"> | undefined, grant: string): string[];
88
97
  /** The run's MCP for one claim: undefined when it grants no MCP tool. Throws McpClaimRefused (a granted tool its pin lacks,
@@ -1,6 +1,10 @@
1
1
  import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
2
2
  import { wireName } from "../catalog.js";
3
3
  import { mcpGateway } from "../mcp-gateway.js";
4
+ import { meterFor, publicMedia } from "../fal-price.js";
5
+ import { FAUX_ENV } from "../model.js";
6
+ import { fetchOptions } from "../web-fetch-direct.js";
7
+ import { fakeSaveOptions } from "../web-fake.js";
4
8
  import { dialAt, mcpServerAt, systemNetwork } from "../mcp-oauth.js";
5
9
  import { privateOAuthHosts } from "../mcp-private-hosts.js";
6
10
  import { mcpNameOf } from "../tool-names.js";
@@ -9,6 +13,9 @@ import { mcpClaim } from "./mcp-claim.js";
9
13
  import { registryListing } from "../mcp-pin-first.js";
10
14
  import { heldOrThrow } from "./held.js";
11
15
  import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
16
+ /** A claim's reader of a metered job's input media: through the guard web_save downloads by (an eval's web fake, a faux
17
+ * module, else the public network), in `slots`. */
18
+ export const mediaForClaim = (env, web, slots) => publicMedia(async () => (web ? fakeSaveOptions(web) : fetchOptions(env, FAUX_ENV)), slots);
12
19
  /** The wire names a subagent's `grant` gives of the run's MCP and monid tools, by the gate's keys; else the grant's own. */
13
20
  export function catalogSessionNames(catalog, grant) {
14
21
  const given = (catalog?.tools ?? []).flatMap((tool) => (permissionKeys(catalog.catalogOf(tool.name) ?? "").includes(grant) ? [tool.name] : []));
@@ -68,9 +75,14 @@ export async function mcpForClaim(options) {
68
75
  },
69
76
  beforeCall: step.beforeCall,
70
77
  work: options.work,
78
+ // fal's submission keys are scoped to the run (fal-price.ts falKeys): the same on every claim of it, so a retry after
79
+ // a resume still dedupes.
80
+ run: options.claim.runId,
71
81
  commit: () => (change) => options.harness.commit(change, BACKGROUND_CONTEXT),
72
82
  ...(options.fetch ? { fetch: options.fetch } : {}),
73
83
  ...(options.callBounds ? { bounds: options.callBounds } : {}),
84
+ ...(options.capped ? { capped: options.capped } : {}),
85
+ ...(options.media ? { media: options.media } : {}),
74
86
  });
75
87
  const catalog = new Map();
76
88
  const declared = new Map();
@@ -105,7 +117,10 @@ export async function mcpForClaim(options) {
105
117
  const pinned = parsed && Object.hasOwn(pin, parsed.server) ? pin[parsed.server] : undefined;
106
118
  if (!pinned?.tools.some((tool) => tool.name === parsed.tool))
107
119
  return undefined;
108
- return pinned.prices && Object.hasOwn(pinned.prices, parsed.tool) ? pinned.prices[parsed.tool] : "not metered";
120
+ if (pinned.prices && Object.hasOwn(pinned.prices, parsed.tool))
121
+ return pinned.prices[parsed.tool];
122
+ // A metered server's job is priced from its input, when the call runs: no price to show before it.
123
+ return meterFor(pinned)?.bills(parsed.tool) ? undefined : "not metered";
109
124
  },
110
125
  effectOf: (name) => pinnedEffect(pin, name),
111
126
  fresh: () => step.fresh(),
@@ -17,7 +17,7 @@ import { randomUUID } from "node:crypto";
17
17
  import { calculateCost } from "@earendil-works/pi-ai";
18
18
  import { onOpenRouter, openRouterAttribution, ROUTE_ORIGIN, streamErrorOf } from "@parcha/agentrun-kernel/host";
19
19
  import { chooseModel, MODEL_PROVIDER, runModels } from "../model.js";
20
- import { providerFor } from "../provider.js";
20
+ import { gatewayHeadersAt, providerFor } from "../provider.js";
21
21
  import { keepText, runnerSecrets, secretRedactor } from "./redact.js";
22
22
  import { callsOfText, toolsAsText } from "./text-tools.js";
23
23
  /** The wires a caller of routeOf speaks when it names none: Anthropic's Messages alone. */
@@ -50,14 +50,17 @@ export async function routeOf(model, env = process.env, tier = "default", wires
50
50
  const settings = { ...sees, ...(target.reasoning !== undefined ? { reasoning: target.reasoning } : {}), ...(target.contextWindow ? { contextWindow: target.contextWindow } : {}), ...(target.maxTokens ? { maxTokens: target.maxTokens } : {}), ...(target.thinkingLevelMap ? { thinkingLevelMap: target.thinkingLevelMap } : {}) };
51
51
  const route = { model: chosen.model.modelId, named: `${chosen.model.provider}/${chosen.model.modelId}`, price, cost: target.cost, ...(unpriced.has(chosen.model.modelId) ? { unpriced: true } : {}), outputCeiling: target.maxTokens ?? null, like: sees };
52
52
  // An Anthropic model speaks Messages itself: the network, at its catalog origin, its key read by name per request.
53
+ // Its requests name the claim's run, turn and attempt only where that origin is serve's own gateway (gatewayHeadersAt).
53
54
  if (chosen.model.provider === "anthropic") {
54
- return { ...route, provider: { api: "anthropic-messages", origin: target.baseUrl ?? "https://api.anthropic.com", credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "" } };
55
+ const origin = target.baseUrl ?? "https://api.anthropic.com";
56
+ const headers = gatewayHeadersAt(env, origin);
57
+ return { ...route, provider: { api: "anthropic-messages", origin, credential: () => env.ANTHROPIC_API_KEY ?? env.ANTHROPIC_AUTH_TOKEN ?? "", ...(headers ? { headers } : {}) } };
55
58
  }
56
59
  // A Claude model of serve's gateway (model.ts gatewayWire), for a caller that speaks Messages: the gateway itself, on
57
60
  // Messages, so the prompt cache marks pi-ai puts on the request reach it (provider.ts).
58
61
  if (target.api === "anthropic-messages" && chosen.model.provider === MODEL_PROVIDER && wires.includes("anthropic-messages")) {
59
62
  const to = providerFor("anthropic-messages", env, chosen.model, "pi");
60
- return { ...route, model: to.modelId, provider: { api: "anthropic-messages", origin: to.origin, credential: to.credential, auth: to.auth }, like: settings };
63
+ return { ...route, model: to.modelId, provider: { api: "anthropic-messages", origin: to.origin, credential: to.credential, auth: to.auth, ...(to.headers ? { headers: to.headers } : {}) }, like: settings };
61
64
  }
62
65
  // A model pi-ai speaks Responses to, for a caller that speaks it: that wire itself, where main sends it (provider.ts).
63
66
  if (target.api === "openai-responses" && wires.includes("openai-responses")) {
@@ -68,7 +71,7 @@ export async function routeOf(model, env = process.env, tier = "default", wires
68
71
  const plan = onPlan ? { price: () => null, unpriced: true } : {};
69
72
  return {
70
73
  ...route, model: to.modelId, ...plan,
71
- provider: { api: "openai-responses", origin: to.origin, credential: to.credential, auth: to.auth, ...(onPlan ? { plan: true } : {}), ...(to.refused ? { refused: to.refused } : {}) },
74
+ provider: { api: "openai-responses", origin: to.origin, credential: to.credential, auth: to.auth, ...(to.headers ? { headers: to.headers } : {}), ...(onPlan ? { plan: true } : {}), ...(to.refused ? { refused: to.refused } : {}) },
72
75
  like: onPlan ? { ...settings, developerRole: true } : settings,
73
76
  };
74
77
  }
@@ -3,6 +3,9 @@ import type { Runners } from "../store/store.js";
3
3
  export declare const PRESENCE_RENEW_MS = 10000;
4
4
  /** How old a runner's word can be and still count: three renewals missed. */
5
5
  export declare const PRESENCE_STALE_MS: number;
6
+ /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
7
+ * capacity read (GET /v2/capacity). */
8
+ export declare const RUNNER_VERSION: string;
6
9
  /** Where a runner's relay takes the dials the server relays to it (dial-relay.ts). */
7
10
  export interface RelayAt {
8
11
  readonly host: string;
@@ -15,20 +18,26 @@ export interface Presence {
15
18
  /** Says on its row where its relay answers (`at`), or that it answers nowhere (null, the relay's close), and keeps that
16
19
  * through every put again. Rejects when that write fails, which the renewals then try again. */
17
20
  relay(at: RelayAt | null): Promise<void>;
21
+ /** Says on its row why this runner claims nothing now (`words`), or that it claims again (null), and keeps that through
22
+ * every put again: a runner that cannot serve the runs this store holds for a while (runner.ts claimGate) says so where
23
+ * the server reads it (runnersRefused). Rejects when that write fails, which the renewals then try again. */
24
+ refuse(words: string | null): Promise<void>;
18
25
  /** Stops renewing it and removes the row (its incarnation's alone). */
19
26
  close(): Promise<void>;
20
27
  /** Stops renewing it and leaves the row to go stale, as a crash would. */
21
28
  stop(): void;
22
29
  }
23
- /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
30
+ /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), with this build's version
31
+ * (RUNNER_VERSION) and `slots`, the most runs it holds at once (none for a refusing runner), renewed every `renewMs`; put
24
32
  * again when it went (a row pruned, a store restored), never over a later process's of the same name while that one is
25
33
  * live; its relay's place is written on its own row only. A write that
26
34
  * fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
27
35
  * runner process's one (runner/main.ts hands its relay the same), a new one by default. */
28
- export declare function keepPresence(runners: Runners, runner: string, refused: string | null, { renewMs, warn, incarnation }?: {
36
+ export declare function keepPresence(runners: Runners, runner: string, refused: string | null, { renewMs, warn, incarnation, slots }?: {
29
37
  renewMs?: number;
30
38
  warn?: (line: string) => void;
31
39
  incarnation?: string;
40
+ slots?: number | null;
32
41
  }): Presence;
33
42
  /** Why no runner here can take a run, in the runners' own words, or undefined while one can (or none is there): the rows
34
43
  * seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
@@ -10,17 +10,22 @@
10
10
  // runs still queued (server.ts). With no runner there at all (a server with --no-runner and its runner not started yet),
11
11
  // it refuses nothing: runs queue for the runner to come, as before.
12
12
  import { randomUUID } from "node:crypto";
13
+ import { readFileSync } from "node:fs";
13
14
  import { ApiError } from "../errors.js";
14
15
  /** How often a runner says again that it is there. */
15
16
  export const PRESENCE_RENEW_MS = 10_000;
16
17
  /** How old a runner's word can be and still count: three renewals missed. */
17
18
  export const PRESENCE_STALE_MS = 3 * PRESENCE_RENEW_MS;
18
- /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
19
+ /** This build's version (the serve package's), which every runner says on its row (runners.version) for the server's
20
+ * capacity read (GET /v2/capacity). */
21
+ export const RUNNER_VERSION = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
22
+ /** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), with this build's version
23
+ * (RUNNER_VERSION) and `slots`, the most runs it holds at once (none for a refusing runner), renewed every `renewMs`; put
19
24
  * again when it went (a row pruned, a store restored), never over a later process's of the same name while that one is
20
25
  * live; its relay's place is written on its own row only. A write that
21
26
  * fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
22
27
  * runner process's one (runner/main.ts hands its relay the same), a new one by default. */
23
- export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENEW_MS, warn = (_line) => { }, incarnation = randomUUID() } = {}) {
28
+ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENEW_MS, warn = (_line) => { }, incarnation = randomUUID(), slots = null } = {}) {
24
29
  let warned = false;
25
30
  const failed = (error) => {
26
31
  if (warned)
@@ -29,13 +34,24 @@ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENE
29
34
  warn(`could not say in the store that runner ${runner} is there: ${error instanceof Error ? error.message : String(error)}`);
30
35
  };
31
36
  let at = null;
32
- const row = () => ({ runner, incarnation, refused, host: at?.host ?? null, port: at?.port ?? null });
37
+ let said = refused;
38
+ const row = () => ({ runner, incarnation, refused: said, host: at?.host ?? null, port: at?.port ?? null, version: RUNNER_VERSION, slots });
33
39
  // Its first put takes the name over from an earlier process's row. Every write after it (a renewal, the relay's place:
34
40
  // one Runners.renew, with the place it holds now) touches its own row only, or puts one where no other process of the
35
41
  // name is live (Runners.put unlessLiveMs): an older process overlapping a restart never takes the later one's row back,
36
42
  // nor clears its relay.
37
43
  const again = () => runners.put(row(), { unlessLiveMs: PRESENCE_STALE_MS });
44
+ // A refusal changed (refuse) and not yet on the row: a renewal only marks the row seen, so until a put of the row lands
45
+ // each renewal is that put. A put that fails leaves it unsaid, for the next renewal.
46
+ let unsaid = false;
47
+ const sayRefusal = async () => {
48
+ unsaid = true;
49
+ await again();
50
+ unsaid = false;
51
+ };
38
52
  const renew = async () => {
53
+ if (unsaid)
54
+ return void (await sayRefusal());
39
55
  if (!(await runners.renew(runner, incarnation, at)))
40
56
  await again();
41
57
  };
@@ -57,6 +73,18 @@ export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENE
57
73
  writing = wrote.catch(failed);
58
74
  return wrote;
59
75
  },
76
+ refuse(words) {
77
+ if (words === said)
78
+ return Promise.resolve();
79
+ said = words;
80
+ if (stopped)
81
+ return Promise.resolve();
82
+ // Its words are on the row, not on a renewal (Runners.renew writes the seen time and the relay's place alone): the
83
+ // row is put again, its own incarnation's, never over a later process's of the same name.
84
+ const wrote = writing.then(sayRefusal);
85
+ writing = wrote.catch(failed);
86
+ return wrote;
87
+ },
60
88
  async close() {
61
89
  if (stopped)
62
90
  return;
@@ -4,7 +4,7 @@ import { type RunLaunch } from "../run-launch.js";
4
4
  import { type Store } from "../store/store.js";
5
5
  import { type Recorded, type ReplayCalls, type Skipped } from "../learn/replay-calls.js";
6
6
  import { type Json } from "../validate.js";
7
- import { type CheckBar, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
7
+ import { type CheckBar, type CheckRecord, type CheckTurns, type Compared, type PromotionRecord, recordPromotion, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
8
8
  import { type FirstChoice, type Promoted, type ReplayOutcome } from "./workflow-first.js";
9
9
  import type { LearningFolder } from "../learn/folder.js";
10
10
  import type { Shown } from "../learning.js";
@@ -97,8 +97,9 @@ export declare const DSL_REFUSES = "this release's workflow DSL refuses it";
97
97
  /** Which check of a compile a new revision's is: 2 when the workflow's newest record of another revision is a first
98
98
  * check's hold, an audit's hold or a hold by its reason alone (holdRefused: the DSL refuses a serving revision), or a
99
99
  * first compile's failed draft (this revision is its one recompile), else 1. A stop with nothing checked
100
- * (stopUnchecked) is no first check's hold: it spends no recompile. A workflow's first revision after a first compile
101
- * whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
100
+ * (stopUnchecked) is no first check's hold: it spends no recompile, and neither does a connected agent's hold on its
101
+ * give-backs (heldOnGiveBacks: the revision after it is the same attempt). A workflow's first revision after a first
102
+ * compile whose drafts failed under another name (learn/compile.ts newCompileAttempt) is that compile's recompile too. */
102
103
  export declare function attemptOf(records: readonly PromotionRecord[], name: string, digest: string): 1 | 2;
103
104
  /** The words a stopped check's record starts with when it had nothing to check its draft on. */
104
105
  export declare const NOTHING_TO_CHECK = "nothing to check it on";
@@ -111,7 +112,7 @@ export declare const differentDecisionWords: (k: number, n: number, example: str
111
112
  * draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
112
113
  * reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
113
114
  * the first). */
114
- type CheckRow = {
115
+ export type CheckRow = {
115
116
  readonly of: string;
116
117
  readonly input: string;
117
118
  readonly agent: string | null;
@@ -122,10 +123,8 @@ type CheckRow = {
122
123
  readonly unstarted?: true;
123
124
  readonly compared?: Compared;
124
125
  };
125
- /** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
126
- * with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
127
- * when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
128
- * when it answered it with no escalate and no failed step. Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
126
+ /** Decides a check on its rows, with a connected agent's turns checked before them (`before`), scored on its bar
127
+ * (scoreRows). Promoted when it clears the bar (checkPasses); else held with the inputs it did not agree on, which the
129
128
  * agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
130
129
  * nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
131
130
  * (the one write: of two claims at once, one decides). */
@@ -136,14 +135,20 @@ export declare function decideCheck(deps: DecideDeps, name: string, digest: stri
136
135
  unstarted: number;
137
136
  exactMismatchReason?: string;
138
137
  fresh_reads?: number;
138
+ before?: CheckTurns;
139
139
  }, still: Parameters<typeof recordPromotion>[3], extra: Partial<PromotionRecord>): Promise<import("../learn/promote.js").Recorded>;
140
- /** How many of a connected agent's reserved native turns its check gives back before it stops. A turn is given back
141
- * when it cannot be the check's baseline: cancelled or failed, a learned workflow or nested call in it, redacted
142
- * evidence, no shadow report, or a shadow that did not answer. One or two are ordinary (a person cancels a task, an
143
- * input carries a secret); five say the integration cannot give one (a client with no shadow check, inputs it never
144
- * resolves, a draft whose shadow always refuses), and each reserved turn runs without the champion. The fifth stops it
145
- * with nothing checked (stopUnchecked), which asks no recompile: a revision would have no baseline either. */
140
+ /** How many of a connected agent's reserved native turns its check gives back in a row (failed, a learned workflow or
141
+ * nested call in it, redacted evidence, no shadow report, or a shadow that did not answer; never a cancel, and a turn
142
+ * that lands starts the count again) before it holds the draft, never promoted and never stopped for good, for the next
143
+ * compile to revise and check afresh: five in a row say the integration cannot give a baseline now, not that it never will. */
146
144
  export declare const SDK_CHECK_RELEASES = 5;
145
+ /** Which attempt a revision compile of `held` is when its draft fails its checks (runner/learning-end.ts
146
+ * recordDraftFailed): 2, the recompile, for any hold but a connected agent's on give-backs, which spends none: its
147
+ * check's own attempt, until a revise of it has failed once already (the workflow's newest record that failed draft). */
148
+ export declare function reviseAttemptOf(records: readonly PromotionRecord[], held: {
149
+ readonly workflow: string;
150
+ readonly check?: CheckRecord;
151
+ }): 1 | 2;
147
152
  /** A connected agent's draft reserved on one native turn: what its start hands the caller (sdk/runs.ts receipt). */
148
153
  export type SdkWorkflowCheck = {
149
154
  id: string;
@@ -157,7 +162,7 @@ export declare const sdkInputText: (launch: RunLaunch | undefined) => string;
157
162
  * check on the native turn `runId`: the first the turn takes (`takes`) with no decision yet, or one waiting for a turn,
158
163
  * while no other revision of its workflow is checked; the guarded write keeps one reservation per workflow across
159
164
  * concurrent starts. First each SDK check of a candidate's workflow is moved on: one whose turn is past
160
- * REPLAY_DEADLINE_MS is decided as one failed row (sdkCheckDeadline), and one waiting at a revision the folder moved
165
+ * REPLAY_DEADLINE_MS is one failed row of its turns (sdkCheckDeadline), and one waiting at a revision the folder moved
161
166
  * past is set aside. A managed replay's record (no `via`) is never touched here. */
162
167
  export declare function reserveSdkCheck(deps: DecideDeps, turn: {
163
168
  readonly runId: string;
@@ -166,15 +171,29 @@ export declare function reserveSdkCheck(deps: DecideDeps, turn: {
166
171
  readonly flows: readonly LearnedWorkflow[];
167
172
  readonly takes: (flow: LearnedWorkflow) => boolean;
168
173
  }): Promise<SdkWorkflowCheck | undefined>;
174
+ /** One native turn's row of a connected agent's check: its shadow answered or handed back (sdk/check.ts settleSdkCheck),
175
+ * or the turn did not settle by REPLAY_DEADLINE_MS, a failed row (sdkCheckDeadline). A managed check decides once, on
176
+ * its compile_after inputs, and so does this one: the turn that makes compile_after decides on every turn collected
177
+ * (decideCheck, the same bar); a turn before it is scored and kept (check.turns), the record gives back its reserved
178
+ * turn, and the check waits for the next turn the draft takes, nothing decided or promoted, the agent answering
179
+ * meanwhile. No turn holds it early, as no input of a managed check does. Its rows are never skipped (a shadow stopped
180
+ * at a write gives its turn back), so each is one of the n. Kept only while `still` holds of the digest's record; a
181
+ * check a newer revision overtook keeps no turn (it would hide the newer record), as a release does. */
182
+ export declare function sdkCheckTurn(deps: DecideDeps, record: PromotionRecord & {
183
+ readonly check: CheckRecord;
184
+ }, row: CheckRow, still: Parameters<typeof recordPromotion>[3], read?: {
185
+ exactMismatchReason?: string;
186
+ fresh_reads?: number;
187
+ }): Promise<import("../learn/promote.js").Recorded | undefined>;
169
188
  /** A connected agent's check whose native turn did not settle it by REPLAY_DEADLINE_MS (the backend never completed the
170
- * turn, or the server stopped before the run's end): decided as every check is (decideCheck), on one failed row. Its
171
- * hold asks the one recompile, and a recompile's check that ends here stops (`stopped`): an abandoned check never
172
- * restarts its budget. */
189
+ * turn, or the server stopped before the run's end): one failed row of its turns (sdkCheckTurn), as a managed check's
190
+ * replay run not ended by its deadline is a failed input. The hold the turns end in asks the one recompile, and a
191
+ * recompile's check held so stops (`stopped`): an abandoned check never restarts its budget. */
173
192
  export declare function sdkCheckDeadline(deps: DecideDeps, pending: PromotionRecord): Promise<import("../learn/promote.js").Recorded | undefined>;
174
193
  /** Gives back a connected agent's reserved native turn that cannot be its check's baseline (`cause`): the check waits for
175
- * the next turn the draft takes, nothing decided or promoted, and the turn counts toward SDK_CHECK_RELEASES, whose last
176
- * stops it with nothing checked (stopUnchecked: no recompile). `counted` false: no turn ran (its start was not
177
- * admitted). Kept only while the record is still this reservation. */
194
+ * the next turn the draft takes, nothing decided or promoted, the turns it checked kept on the record. A `counted` turn
195
+ * (not a cancel, not a start that was never admitted) counts toward SDK_CHECK_RELEASES in a row, whose last holds the
196
+ * draft for the next compile, whose revision is checked afresh. Kept only while the record is still this reservation. */
178
197
  export declare function releaseSdkCheck(deps: DecideDeps, record: PromotionRecord, cause: string, counted?: boolean): Promise<import("../learn/promote.js").Recorded | undefined>;
179
198
  /** A run's final answer row, its text whole (its last final answer row that is not its end-of-run turn's), or null: none,
180
199
  * or its record could not be read. `turn`: the row of that id instead (the answer an audit is of, runner/audit.ts), so an