@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.
- package/CHANGELOG.md +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
package/dist/runner/mcp-claim.js
CHANGED
|
@@ -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;
|
package/dist/runner/mcp-run.d.ts
CHANGED
|
@@ -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,
|
package/dist/runner/mcp-run.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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),
|
|
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. */
|
package/dist/runner/presence.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
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
|
|
101
|
-
*
|
|
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
|
|
126
|
-
*
|
|
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
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
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
|
|
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):
|
|
171
|
-
*
|
|
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,
|
|
176
|
-
*
|
|
177
|
-
*
|
|
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
|