@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.47
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 +164 -1
- package/NOTICE +4 -0
- package/README.md +267 -40
- package/dist/acp-package.d.ts +35 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +5 -2
- package/dist/adapter-facts.js +6 -3
- package/dist/adapters.d.ts +7 -0
- package/dist/adapters.js +39 -0
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +7 -10
- package/dist/archil-routes.js +2 -1
- package/dist/cap.js +12 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +109 -41
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +9 -75
- package/dist/computers.js +20 -66
- package/dist/console/assets/index-BBFzAxLB.js +715 -0
- package/dist/console/assets/index-BRi-Rgq6.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +73 -0
- package/dist/harness-check.js +489 -0
- package/dist/harness-cursor.d.ts +45 -0
- package/dist/harness-cursor.js +121 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +357 -0
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +62 -2
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +3 -2
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +24 -4
- package/dist/import.js +108 -26
- package/dist/key-refusal.d.ts +1 -0
- package/dist/key-refusal.js +8 -3
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +12 -5
- package/dist/learn/promote.d.ts +69 -2
- package/dist/learn/promote.js +95 -3
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +1 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +22 -8
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +2 -1
- package/dist/model.js +9 -7
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +322 -39
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +8 -0
- package/dist/page.js +9 -1
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +6 -4
- package/dist/runner/adapter-loop.d.ts +10 -7
- package/dist/runner/adapter-loop.js +57 -22
- package/dist/runner/adapter-run-spec.d.ts +12 -0
- package/dist/runner/adapter-run-spec.js +40 -6
- package/dist/runner/adapters/index.js +16 -0
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +15 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +15 -7
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +62 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +41 -0
- package/dist/runner/presence.js +89 -0
- package/dist/runner/promotion.d.ts +9 -4
- package/dist/runner/promotion.js +33 -14
- package/dist/runner/run-child-host.js +40 -10
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runs-over-store.d.ts +6 -2
- package/dist/runs-over-store.js +14 -4
- package/dist/sdk/runs.d.ts +1 -1
- package/dist/sdk/runs.js +6 -1
- package/dist/sdk/schema.js +1 -1
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +31 -2
- package/dist/server.js +322 -51
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +106 -27
- package/dist/store/store.d.ts +75 -23
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +123 -14
- package/dist/store-view.js +154 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/timeline/timeline.js +18 -0
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.js +2 -2
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +19 -8
- package/dist/triggers.d.ts +2 -2
- package/dist/webhooks.d.ts +82 -8
- package/dist/webhooks.js +128 -45
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +18 -14
- package/dist/workspace/resolve-computer.js +47 -60
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
package/dist/runner/metrics.js
CHANGED
|
@@ -13,6 +13,37 @@ import { DECISION_SESSION, TOOL_SESSION } from "@parcha/agentrun-kernel/kernel/c
|
|
|
13
13
|
import { KINDS, WORKFLOW_SESSION } from "./journal-kinds.js";
|
|
14
14
|
import { anthropicModelId } from "../provider.js";
|
|
15
15
|
import { WORKFLOW_FIRST, WORKFLOW_FIRST_CALL } from "./workflow-first.js";
|
|
16
|
+
/** How a run's cost was reached, by how its model requests were priced: `reported` when every request priced had the
|
|
17
|
+
* provider's or its gateway's own figure (LiteLLM's `x-litellm-response-cost`, OpenRouter's usage `cost`); `estimate`
|
|
18
|
+
* when any was priced from a price table (the catalog, AGENT_MODEL_PRICE, a cut request's hold); `unpriced` when no
|
|
19
|
+
* request was priced (none was sent, or none had a figure). The run's cost block (`cost.basis`), its stored metrics
|
|
20
|
+
* (`costBasis`) and the sums over runs (GET /stats, GET /usage) say it in these words. */
|
|
21
|
+
export const COST_BASES = ["reported", "estimate", "unpriced"];
|
|
22
|
+
/** The basis of a booking's model requests (bookedSpend "model"): COST_BASES. */
|
|
23
|
+
export const costBasisOf = (spend) => (spend.priced.estimated > 0 ? "estimate" : spend.priced.reported > 0 ? "reported" : "unpriced");
|
|
24
|
+
/** The basis of a sum of costs: `estimate` when any is, else `reported` when any is, else `unpriced`. */
|
|
25
|
+
export function joinedBasis(bases) {
|
|
26
|
+
let reported = false;
|
|
27
|
+
for (const basis of bases) {
|
|
28
|
+
if (basis === "estimate")
|
|
29
|
+
return "estimate";
|
|
30
|
+
if (basis === "reported")
|
|
31
|
+
reported = true;
|
|
32
|
+
}
|
|
33
|
+
return reported ? "reported" : "unpriced";
|
|
34
|
+
}
|
|
35
|
+
/** A run's basis as its end stored it (its metrics' `costBasis`); an imported run's catalog estimate (import.ts stores
|
|
36
|
+
* `costBasis: "catalog"` beside `costUsdEst`, the figure store-reads/runs.ts costOfRun reads) is an `estimate`, at $0 too;
|
|
37
|
+
* a run that stored none (one that ended before the end stored it, a workflow's, a native, SDK or imported run's: their
|
|
38
|
+
* figures are the harness's) is an `estimate` when it cost anything, else `unpriced`. */
|
|
39
|
+
export function storedBasisOf(metrics, usd) {
|
|
40
|
+
const stored = metrics?.costBasis;
|
|
41
|
+
if (COST_BASES.includes(stored))
|
|
42
|
+
return stored;
|
|
43
|
+
if (stored === "catalog" && typeof usd === "number")
|
|
44
|
+
return "estimate";
|
|
45
|
+
return typeof usd === "number" && usd > 0 ? "estimate" : "unpriced";
|
|
46
|
+
}
|
|
16
47
|
/** The conversation each of the run's sessions books in, by its key: the first `agentrun.session.key` entry naming it. */
|
|
17
48
|
function sessionConversations(entries) {
|
|
18
49
|
const out = new Map();
|
|
@@ -61,6 +92,8 @@ export function bookedSpend(entries, which) {
|
|
|
61
92
|
let unmetered = 0;
|
|
62
93
|
let free = 0;
|
|
63
94
|
let atMost = 0;
|
|
95
|
+
let reported = 0;
|
|
96
|
+
let estimated = 0;
|
|
64
97
|
const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
65
98
|
// Each request is booked once, as the kernel's sessionSpendOf reads it: a second runner.turn of a turn already booked
|
|
66
99
|
// (two bookings of one session that each read it open, a cut written twice) counts no money and no request again.
|
|
@@ -96,6 +129,16 @@ export function bookedSpend(entries, which) {
|
|
|
96
129
|
(bounded += own.usd), (atMost += 1);
|
|
97
130
|
else
|
|
98
131
|
known += own.usd;
|
|
132
|
+
// How its figure was reached (costBasisOf): a price table's (the proxy's `estimated`, or a hold), or the provider's own
|
|
133
|
+
// (the proxy keeps the table's figure beside a reported one, `tableUsd`). A native or SDK task's one booking for the whole
|
|
134
|
+
// task (`aggregate`, native-loop.ts and sdk-loop.ts) carries its harness's own figure, an estimate. A plan's request
|
|
135
|
+
// costs no dollars: neither.
|
|
136
|
+
if (own.usd !== null && d.billing !== "plan") {
|
|
137
|
+
if (own.atMost || d.estimated === true || d.aggregate === true)
|
|
138
|
+
estimated += 1;
|
|
139
|
+
else if (d.tableUsd !== undefined)
|
|
140
|
+
reported += 1;
|
|
141
|
+
}
|
|
99
142
|
// The booking keeps a request's usage only when it reported some (runner.ts tokensOf): one with none is unmetered.
|
|
100
143
|
if (d.usage === undefined)
|
|
101
144
|
unmetered += 1;
|
|
@@ -103,7 +146,7 @@ export function bookedSpend(entries, which) {
|
|
|
103
146
|
if (typeof d.usage?.[key] === "number")
|
|
104
147
|
tokens[key] += d.usage[key];
|
|
105
148
|
}
|
|
106
|
-
return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, ...(requests > 0 && free === requests ? { free: true } : {}) };
|
|
149
|
+
return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, priced: { reported, estimated }, ...(requests > 0 && free === requests ? { free: true } : {}) };
|
|
107
150
|
}
|
|
108
151
|
/** A sum of charges with its float noise rounded off, nothing more (as the decisions row rounds, decision-rows.ts): a
|
|
109
152
|
* decision costs millionths of a dollar, so a sum rounded to the millionth would lose it. */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Runners } from "../store/store.js";
|
|
2
|
+
/** How often a runner says again that it is there. */
|
|
3
|
+
export declare const PRESENCE_RENEW_MS = 10000;
|
|
4
|
+
/** How old a runner's word can be and still count: three renewals missed. */
|
|
5
|
+
export declare const PRESENCE_STALE_MS: number;
|
|
6
|
+
/** Where a runner's relay takes the dials the server relays to it (dial-relay.ts). */
|
|
7
|
+
export interface RelayAt {
|
|
8
|
+
readonly host: string;
|
|
9
|
+
readonly port: number;
|
|
10
|
+
}
|
|
11
|
+
/** A runner's word kept in the store until its close. */
|
|
12
|
+
export interface Presence {
|
|
13
|
+
/** The runner's process since its start, on its row: its relay's minted tokens and proofs name the same one. */
|
|
14
|
+
readonly incarnation: string;
|
|
15
|
+
/** Says on its row where its relay answers (`at`), or that it answers nowhere (null, the relay's close), and keeps that
|
|
16
|
+
* through every put again. Rejects when that write fails, which the renewals then try again. */
|
|
17
|
+
relay(at: RelayAt | null): Promise<void>;
|
|
18
|
+
/** Stops renewing it and removes the row (its incarnation's alone). */
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
/** Stops renewing it and leaves the row to go stale, as a crash would. */
|
|
21
|
+
stop(): void;
|
|
22
|
+
}
|
|
23
|
+
/** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
|
|
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
|
|
25
|
+
* live; its relay's place is written on its own row only. A write that
|
|
26
|
+
* fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
|
|
27
|
+
* 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 }?: {
|
|
29
|
+
renewMs?: number;
|
|
30
|
+
warn?: (line: string) => void;
|
|
31
|
+
incarnation?: string;
|
|
32
|
+
}): Presence;
|
|
33
|
+
/** 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
|
+
* seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
|
|
35
|
+
export declare function runnersRefused(runners: Pick<Runners, "live">, staleMs?: number): Promise<string | undefined>;
|
|
36
|
+
/** The code a run fails with when no runner here could take it (its error's code, and a launch's refusal's). */
|
|
37
|
+
export declare const RUNNER_REFUSED_CODE = "runner_refused";
|
|
38
|
+
/** The summary of a queued run failed because no runner here can take it (Runs.failUnclaimed): the code, then `words`. */
|
|
39
|
+
export declare const refusedEnd: (words: string) => string;
|
|
40
|
+
/** The words of a summary refusedEnd wrote, or undefined for any other (store-view.ts errorOfRow). */
|
|
41
|
+
export declare const refusedEndMessage: (summary: string | null | undefined) => string | undefined;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Each runner's word that it is there (store `runners`), and what the server makes of them: whether any runner here can take
|
|
2
|
+
// a run. A runner that claims keeps a row with no refusal for as long as it runs (startRunner); a runner whose run isolation
|
|
3
|
+
// was refused (run-child-host.ts runIsolationOf) keeps one with its words, beside a server (cli.ts, through Serve.refuseRuns)
|
|
4
|
+
// or in a process of its own (runner/main.ts), so a server in another process, or on another host over one Postgres, reads
|
|
5
|
+
// it. A runner in a process of its own with a relay (dial-relay.ts) says on the same row where its relay answers, under the
|
|
6
|
+
// same incarnation (runner/main.ts makes one per process), so the server relays a dial only to a runner this row says is
|
|
7
|
+
// there. Each row is renewed every PRESENCE_RENEW_MS and read as gone once it is PRESENCE_STALE_MS old: a runner that died
|
|
8
|
+
// without its close stops counting within that. While every runner still there refused, and one at least is, the server
|
|
9
|
+
// refuses a launch in their words (runs-over-store.ts prepareLaunch), says so in capabilities and health, and fails the
|
|
10
|
+
// runs still queued (server.ts). With no runner there at all (a server with --no-runner and its runner not started yet),
|
|
11
|
+
// it refuses nothing: runs queue for the runner to come, as before.
|
|
12
|
+
import { randomUUID } from "node:crypto";
|
|
13
|
+
/** How often a runner says again that it is there. */
|
|
14
|
+
export const PRESENCE_RENEW_MS = 10_000;
|
|
15
|
+
/** How old a runner's word can be and still count: three renewals missed. */
|
|
16
|
+
export const PRESENCE_STALE_MS = 3 * PRESENCE_RENEW_MS;
|
|
17
|
+
/** Keeps `runner`'s row in `runners` (refused: its words, or null for a runner that claims), renewed every `renewMs`; put
|
|
18
|
+
* again when it went (a row pruned, a store restored), never over a later process's of the same name while that one is
|
|
19
|
+
* live; its relay's place is written on its own row only. A write that
|
|
20
|
+
* fails is tried again at the next renewal: it never stops the runner, and `warn` hears it once. `incarnation` is the
|
|
21
|
+
* runner process's one (runner/main.ts hands its relay the same), a new one by default. */
|
|
22
|
+
export function keepPresence(runners, runner, refused, { renewMs = PRESENCE_RENEW_MS, warn = (_line) => { }, incarnation = randomUUID() } = {}) {
|
|
23
|
+
let warned = false;
|
|
24
|
+
const failed = (error) => {
|
|
25
|
+
if (warned)
|
|
26
|
+
return;
|
|
27
|
+
warned = true;
|
|
28
|
+
warn(`could not say in the store that runner ${runner} is there: ${error instanceof Error ? error.message : String(error)}`);
|
|
29
|
+
};
|
|
30
|
+
let at = null;
|
|
31
|
+
const row = () => ({ runner, incarnation, refused, host: at?.host ?? null, port: at?.port ?? null });
|
|
32
|
+
// Its first put takes the name over from an earlier process's row. Every write after it (a renewal's put again, the
|
|
33
|
+
// relay's place) touches its own row only, or puts one where no other process of the name is live (Runners
|
|
34
|
+
// putUnlessLive): an older process overlapping a restart never takes the later one's row back, nor clears its relay.
|
|
35
|
+
const again = () => runners.putUnlessLive(row(), PRESENCE_STALE_MS);
|
|
36
|
+
let writing = runners.put(row()).catch(failed);
|
|
37
|
+
const timer = setInterval(() => {
|
|
38
|
+
writing = writing.then(async () => {
|
|
39
|
+
if (!(await runners.seen(runner, incarnation)))
|
|
40
|
+
await again();
|
|
41
|
+
}).catch(failed);
|
|
42
|
+
}, renewMs);
|
|
43
|
+
timer.unref();
|
|
44
|
+
let stopped = false;
|
|
45
|
+
return {
|
|
46
|
+
incarnation,
|
|
47
|
+
relay(next) {
|
|
48
|
+
at = next;
|
|
49
|
+
// Once closed or stopped it writes nothing more: a relay's close after its presence's never puts the row back.
|
|
50
|
+
if (stopped)
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
// After any write in flight, so a renewal's put never lands over it with the place before.
|
|
53
|
+
const wrote = writing.then(async () => {
|
|
54
|
+
if (!(await runners.relayAt(runner, incarnation, next)))
|
|
55
|
+
await again();
|
|
56
|
+
});
|
|
57
|
+
writing = wrote.catch(failed);
|
|
58
|
+
return wrote;
|
|
59
|
+
},
|
|
60
|
+
async close() {
|
|
61
|
+
if (stopped)
|
|
62
|
+
return;
|
|
63
|
+
stopped = true;
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
await writing;
|
|
66
|
+
await runners.remove(runner, incarnation).catch(() => undefined);
|
|
67
|
+
},
|
|
68
|
+
stop() {
|
|
69
|
+
stopped = true;
|
|
70
|
+
clearInterval(timer);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** Why no runner here can take a run, in the runners' own words, or undefined while one can (or none is there): the rows
|
|
75
|
+
* seen within `staleMs` on the store's clock (Runners.live), when there is one at least and every one refused. */
|
|
76
|
+
export async function runnersRefused(runners, staleMs = PRESENCE_STALE_MS) {
|
|
77
|
+
const live = await runners.live(staleMs);
|
|
78
|
+
if (live.length === 0 || live.some((row) => row.refused === null))
|
|
79
|
+
return undefined;
|
|
80
|
+
const reasons = [...new Set(live.map((row) => row.refused))];
|
|
81
|
+
return `No runner of this server can take a run: ${reasons.join(" ")}`;
|
|
82
|
+
}
|
|
83
|
+
/** The code a run fails with when no runner here could take it (its error's code, and a launch's refusal's). */
|
|
84
|
+
export const RUNNER_REFUSED_CODE = "runner_refused";
|
|
85
|
+
const REFUSED_END = `${RUNNER_REFUSED_CODE}: `;
|
|
86
|
+
/** The summary of a queued run failed because no runner here can take it (Runs.failUnclaimed): the code, then `words`. */
|
|
87
|
+
export const refusedEnd = (words) => `${REFUSED_END}${words}`;
|
|
88
|
+
/** The words of a summary refusedEnd wrote, or undefined for any other (store-view.ts errorOfRow). */
|
|
89
|
+
export const refusedEndMessage = (summary) => typeof summary === "string" && summary.startsWith(REFUSED_END) ? summary.slice(REFUSED_END.length) : undefined;
|
|
@@ -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 PromotionRecord, type ReplayOutcomes, type ReplayScore } from "../learn/promote.js";
|
|
7
|
+
import { type CheckBar, type Compared, type PromotionRecord, 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";
|
|
@@ -85,8 +85,11 @@ export declare const promotionGate: (deps: PromotionDeps) => Promoted;
|
|
|
85
85
|
export declare const DSL_REFUSES = "this release's workflow DSL refuses it";
|
|
86
86
|
/** The words a stopped check's record starts with when it had nothing to check its draft on. */
|
|
87
87
|
export declare const NOTHING_TO_CHECK = "nothing to check it on";
|
|
88
|
-
/** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none
|
|
89
|
-
|
|
88
|
+
/** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none: only a
|
|
89
|
+
* check no grader compared (no agree_on, and no fast model to read the answers). */
|
|
90
|
+
export declare const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
|
|
91
|
+
/** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
|
|
92
|
+
export declare const differentDecisionWords: (k: number, n: number, example: string | undefined) => string;
|
|
90
93
|
/** One input a check ran its draft on: the agent's run (`of`) and its input, the agent's recorded answer, and what the
|
|
91
94
|
* draft did: its answer when it answered alone, why it handed the input back, or failed (or skipped a write). A
|
|
92
95
|
* reserved input whose replay run was never created, or never ended, by the check's deadline failed (`unstarted` for
|
|
@@ -100,9 +103,11 @@ type CheckRow = {
|
|
|
100
103
|
readonly escalated?: string;
|
|
101
104
|
readonly skipped?: Skipped;
|
|
102
105
|
readonly unstarted?: true;
|
|
106
|
+
readonly compared?: Compared;
|
|
103
107
|
};
|
|
104
108
|
/** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
|
|
105
|
-
* with the agent's recorded answer (learn/promote.ts
|
|
109
|
+
* with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
|
|
110
|
+
* when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
|
|
106
111
|
* 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
|
|
107
112
|
* agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
|
|
108
113
|
* nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
|
package/dist/runner/promotion.js
CHANGED
|
@@ -7,9 +7,10 @@ import { FINAL_STATES, RunFinal, StoreConstraint } from "../store/store.js";
|
|
|
7
7
|
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
8
8
|
import { isCliRecord, piShaped, runEntries, runTimeline } from "../store-reads/journal.js";
|
|
9
9
|
import { pinAnnotations, recordedCalls, replayCalls, SKIPPED_WRITE, toolClassOf, toolWord, unmarkedWords } from "../learn/replay-calls.js";
|
|
10
|
+
import { listed } from "../learning-words.js";
|
|
10
11
|
import { isObject } from "../validate.js";
|
|
11
12
|
import { agentRun, lastOwnRuns, newCompileAttempt } from "../learn/compile.js";
|
|
12
|
-
import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf,
|
|
13
|
+
import { checkPasses, checkShares, CHECK_TEXT_MAX, championOf, compareAnswers, comparedOf, promotionOf, promotionsOf, recordPromotion, replayingOf, skippedToolsOf } from "../learn/promote.js";
|
|
13
14
|
import { sendCommand } from "./commands.js";
|
|
14
15
|
import { ClaimRefused } from "./loop-contract.js";
|
|
15
16
|
import { readSnapshot } from "../learn/folder.js";
|
|
@@ -365,8 +366,11 @@ async function startCheck(deps, workflow, digest) {
|
|
|
365
366
|
}
|
|
366
367
|
/** The words a stopped check's record starts with when it had nothing to check its draft on. */
|
|
367
368
|
export const NOTHING_TO_CHECK = "nothing to check it on";
|
|
368
|
-
/** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none
|
|
369
|
-
|
|
369
|
+
/** What a held check compared on the whole answer says when it answered some inputs alone and agreed on none: only a
|
|
370
|
+
* check no grader compared (no agree_on, and no fast model to read the answers). */
|
|
371
|
+
export const NEVER_WORD_FOR_WORD = "its answers never matched the agent's word for word, and no fast model compared their decisions (a learning agent with no agree_on wants one: AGENT_MODEL_FAST, or its model_tiers.fast); name the fields that carry the decision (learning.agree_on)";
|
|
372
|
+
/** What a held check the grader compared says of the inputs it disagreed on: k of n, with one of the decisions. */
|
|
373
|
+
export const differentDecisionWords = (k, n, example) => `its answers reached a different decision from the agent's on ${k} of ${n}${example ? ` (for example: ${example})` : ""}`;
|
|
370
374
|
/** Stops a draft its check had nothing to run on (`why`: no input of the agent's it takes, or every input skipped at a
|
|
371
375
|
* write): held, never promoted unchecked, its record `stopped` (nothing compiles again until a hold or its owner acts)
|
|
372
376
|
* and naming the cause, which the compile's draft errors show (store-reads/loop.ts). It asks no recompile: a revision
|
|
@@ -418,7 +422,10 @@ async function checkRows(deps, record) {
|
|
|
418
422
|
}
|
|
419
423
|
const outcome = outcomeOf(run);
|
|
420
424
|
const stoppedAt = outcome === "skipped_write" ? metricsOf(run).replay?.skipped : undefined;
|
|
425
|
+
// The grader's verdict on this pair, asked at the replay run's end (runner/compare-end.ts).
|
|
426
|
+
const compared = outcome === "answered" ? comparedOf(metricsOf(run).replay?.compared) : undefined;
|
|
421
427
|
rows.push({
|
|
428
|
+
...(compared ? { compared } : {}),
|
|
422
429
|
of: replayed, input: inputText(launch.input), agent: await answerOf(store, replayed, context), outcome,
|
|
423
430
|
answer: outcome === "answered" ? await answerOf(store, run.id, context) : null,
|
|
424
431
|
...(outcome === "handed_back" ? { escalated: (await handedBackOf(store, run.id, context)) ?? "" } : {}),
|
|
@@ -459,7 +466,8 @@ async function settleCheck(deps, workflow, digest, record) {
|
|
|
459
466
|
return decided.record?.decided === "replaying" ? undefined : decided.record;
|
|
460
467
|
}
|
|
461
468
|
/** Decides a check on its rows: each input it ran on (a skipped write is none) agreed when the draft answered it alone
|
|
462
|
-
* with the agent's recorded answer (learn/promote.ts
|
|
469
|
+
* with the agent's recorded answer (learn/promote.ts compareAnswers, the audit's one comparison: on the bar's agree_on
|
|
470
|
+
* when it names fields, else equal, or the same decision by the grader's verdict its replay run kept), alone
|
|
463
471
|
* 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
|
|
464
472
|
* agent's next run's compile turn reads as data (its one recompile); a recompile's check that holds it too stops:
|
|
465
473
|
* nothing compiles again. No grade, refit, queue or second replay. Kept only while `still` holds of the digest's record
|
|
@@ -468,17 +476,25 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
|
|
|
468
476
|
const now = deps.now ?? Date.now;
|
|
469
477
|
const ran = read.rows.filter((row) => row.outcome !== "skipped_write");
|
|
470
478
|
const alone = (row) => row.outcome === "answered";
|
|
471
|
-
// Compared on the bar's agree_on when it names paths (the definition's), else the
|
|
472
|
-
|
|
479
|
+
// Compared on the bar's agree_on when it names paths (the definition's), else equal answers agree and the grader's
|
|
480
|
+
// verdict decides the rest; with no grader (no fast model), the whole answer.
|
|
481
|
+
const compared = new Map(ran.map((row) => [row, compareAnswers(row.answer, row.agent, bar.agree_on, row.compared)]));
|
|
482
|
+
const agrees = (row) => alone(row) && compared.get(row).same;
|
|
473
483
|
const score = { n: ran.length, agreed: ran.filter(agrees).length, alone: ran.filter(alone).length };
|
|
474
484
|
const ok = checkPasses(score, bar);
|
|
485
|
+
// The fast model that compared, when it read any input's answers.
|
|
486
|
+
const grader = [...compared.values()].find((one) => one.grader !== undefined)?.grader;
|
|
475
487
|
// Each text is cut of the host's secrets whole, then shortened (learn/secrets.ts excerptShown).
|
|
476
488
|
const shown = await deps.shown();
|
|
477
489
|
const cut = (text) => excerptShown(text, shown, CHECK_TEXT_MAX);
|
|
478
|
-
const disagreements = ran.filter((row) => !agrees(row)).map((row) =>
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
490
|
+
const disagreements = ran.filter((row) => !agrees(row)).map((row) => {
|
|
491
|
+
const differs = row.outcome === "answered" ? compared.get(row).differs_on : undefined;
|
|
492
|
+
return {
|
|
493
|
+
run: row.of, input: cut(row.input), agent: row.agent === null ? null : cut(row.agent),
|
|
494
|
+
...(row.outcome === "answered" ? { draft: cut(row.answer ?? "") } : row.outcome === "handed_back" ? { escalated: cut(row.escalated ?? "") } : { failed: true }),
|
|
495
|
+
...(differs ? { differs_on: cut(differs) } : {}),
|
|
496
|
+
};
|
|
497
|
+
});
|
|
482
498
|
const stopped = !ok && bar.attempt === 2;
|
|
483
499
|
const pct = (value) => `${(value * 100).toFixed(1)}%`;
|
|
484
500
|
const shares = checkShares(score);
|
|
@@ -501,11 +517,14 @@ export async function decideCheck(deps, name, digest, bar, read, still, extra) {
|
|
|
501
517
|
// and the words say none ran.
|
|
502
518
|
const said = read.unstarted === score.n
|
|
503
519
|
? `none of its ${plural(score.n, "check run")} started by the check's deadline (its launch was interrupted: the server stopped after reserving it, say): nothing was checked`
|
|
504
|
-
: `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)}), and ${score.agreed} of those said what the agent said${bar.agree_on?.length ? ` on ${
|
|
505
|
-
//
|
|
506
|
-
|
|
520
|
+
: `checked on ${score.n} of the agent's inputs: answered ${score.alone} alone (${pct(shares.alone)}, the bar ${pct(bar.alone_min)}), and ${score.agreed} of those said what the agent said${bar.agree_on?.length ? ` on ${listed(bar.agree_on)}` : grader ? `, compared by the fast model (${grader})` : ""} (${pct(shares.agreement)}, the bar ${pct(bar.agree_min)})${aside ? ` (${aside})` : ""}`;
|
|
521
|
+
// The grader compared: how many answered alone reached another decision, with one it named. Compared whole and never
|
|
522
|
+
// once the same (no grader): free text two runs never repeat, most likely, so the owner is told what to set.
|
|
523
|
+
const differed = score.alone - score.agreed;
|
|
524
|
+
const example = disagreements.find((one) => one.differs_on !== undefined)?.differs_on;
|
|
525
|
+
const verbatim = ok || bar.agree_on?.length ? "" : grader ? (differed > 0 ? `; ${differentDecisionWords(differed, score.alone, example)}` : "") : score.alone > 0 && score.agreed === 0 ? `; ${NEVER_WORD_FOR_WORD}` : "";
|
|
507
526
|
const reason = ok ? `${said}: promoted` : stopped ? `${said}: held${verbatim}, and this was the recompile's check, so it stops: nothing compiles again until a hold or its owner acts` : `${said}: held${verbatim}; the agent's next run recompiles it once with the inputs it did not agree on`;
|
|
508
|
-
const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}) };
|
|
527
|
+
const check = { ...bar, ...score, ...numbers, ...(disagreements.length ? { disagreements } : {}), ...(stopped ? { stopped: true } : {}), ...(grader ? { grader } : {}) };
|
|
509
528
|
const decided = await recordPromotion(deps.store.settings, deps.agentId, { workflow: name, digest, at: iso(now()), decided: ok ? "promote" : "hold", reason, check, ...seedOf(deps), ...extra }, still);
|
|
510
529
|
if (decided.won)
|
|
511
530
|
deps.log(`workflow-first: ${name} at ${digest} ${ok ? "promoted" : "held"}: ${reason}`);
|
|
@@ -31,7 +31,8 @@ import { DECISION_PROVIDER_KEYS } from "../tool-plane.js";
|
|
|
31
31
|
import { learningEndOfRun } from "./learning-end.js";
|
|
32
32
|
import { runnerSecrets } from "./redact.js";
|
|
33
33
|
import { storeSecrets } from "./store-secrets.js";
|
|
34
|
-
import { FAUX_ENV } from "../model.js";
|
|
34
|
+
import { FAUX_ENV, GATEWAY_KEY_ENV } from "../model.js";
|
|
35
|
+
import { SAVED_GATEWAY_ENV, savedGatewayIn } from "../model-gateway.js";
|
|
35
36
|
import { FAUX_VENDOR_API_ENV } from "../tools.js";
|
|
36
37
|
import { withinCarried } from "../paid-calls.js";
|
|
37
38
|
import { openRunMcpAuth, sealRunMcpAuth } from "../store/seal.js";
|
|
@@ -52,14 +53,16 @@ import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
|
52
53
|
import { messageText } from "../run-manifest.js";
|
|
53
54
|
import { placeRunInputs } from "../uploads.js";
|
|
54
55
|
import { withAudit } from "./audit.js";
|
|
56
|
+
import { compareEndOfRun } from "./compare-end.js";
|
|
55
57
|
import { learnedFirst } from "./learned-first.js";
|
|
56
58
|
import { workflowsAt } from "./learning-seed.js";
|
|
57
59
|
import { heldMcpOf, mcpForClaim } from "./mcp-run.js";
|
|
58
60
|
import { learnedTiers, learnsWorkflows, mcpReachOf } from "./adapter-run-spec.js";
|
|
59
61
|
import { createDispatchLoop } from "./dispatch.js";
|
|
60
|
-
import { resolveRunnerLoop } from "./harness-loops.js";
|
|
62
|
+
import { resolveRunnerLoop, withSavedGatewayDeps } from "./harness-loops.js";
|
|
61
63
|
import { isWorkflowRevision } from "./workflow-loop.js";
|
|
62
64
|
import { loginForRun } from "../claude-login.js";
|
|
65
|
+
import { heardComputerHold } from "./computer-journal.js";
|
|
63
66
|
import { ClaimRefused } from "./loop-contract.js";
|
|
64
67
|
import { Channel, ChannelClosed } from "./run-channel.js";
|
|
65
68
|
import { registerRunErrors } from "./run-errors.js";
|
|
@@ -738,6 +741,8 @@ export function heldFor(deps, reads, cut, log) {
|
|
|
738
741
|
runZone: () => runZone(store, launch.inputOrigin),
|
|
739
742
|
liveViewerPut: (handover) => putLiveViewer(store, sealKey, claim, handover),
|
|
740
743
|
liveViewerDrop: (tag) => dropLiveViewer(store, claim, tag),
|
|
744
|
+
// The claim's own run, whatever the process names: its view on this runner hears the change.
|
|
745
|
+
computerHold: async (change) => heardComputerHold(claim.runId, change, cut),
|
|
741
746
|
handOn: async (from, id) => {
|
|
742
747
|
if (from !== claim.runId || typeof id !== "string")
|
|
743
748
|
return undefined;
|
|
@@ -799,9 +804,17 @@ export function heldFor(deps, reads, cut, log) {
|
|
|
799
804
|
// The step as the run's spec builds it in a runner (adapter-run-spec.ts), over the runner's reads of the claim: what
|
|
800
805
|
// the run must never learn is every secret this runner holds, the keys its claim handed it, every secret the server
|
|
801
806
|
// keeps sealed and its sign-in's pointers, none of which the run's process is given.
|
|
802
|
-
// A replay run or an audit's shadow run
|
|
803
|
-
|
|
804
|
-
|
|
807
|
+
// A replay run or an audit's shadow run learns nothing at its end, as the run's spec says (adapter-run-spec.ts): it
|
|
808
|
+
// compares its answer with the other one through its grader, handed in by the run's process (runner/compare-end.ts).
|
|
809
|
+
// This runner reads both answers and the learning ledger, which no run's process may.
|
|
810
|
+
if (launch.replay || launch.audit) {
|
|
811
|
+
const compare = compareEndOfRun(launch, { store, folder: await folderNow(), log, redact: cut });
|
|
812
|
+
const grade = input.grade;
|
|
813
|
+
const rows = compare && grade && typeof input.grader === "string"
|
|
814
|
+
? await compare({ runId: claim.runId, agentId: run.agentId, claim, outcome: input.outcome === "failed" ? "failed" : "completed", ...(input.cut === undefined ? {} : { cut: "faulted" }), grader: input.grader, grade: (request) => grade(request), ask: input.ask, signal: input.signal })
|
|
815
|
+
: undefined;
|
|
816
|
+
return rows?.compared ? { also: [], compared: dataOnly(rows.compared) } : undefined;
|
|
817
|
+
}
|
|
805
818
|
const made = await archilOf();
|
|
806
819
|
// The audit's spend, skipped as the run's spec skips it (claim-secrets.ts claimSpendOff): over the claim's own key.
|
|
807
820
|
const spendOff = await claimSpendOff(keys, await claimModelKey(keys, claim.runId));
|
|
@@ -977,6 +990,13 @@ export function childLoops(options) {
|
|
|
977
990
|
});
|
|
978
991
|
}
|
|
979
992
|
registerRunErrors();
|
|
993
|
+
/** `claimed` with the saved gateway's key beside its own (the runner's reads of what the run must never keep, heldFor):
|
|
994
|
+
* a copy, every property as it is (its non-enumerable keys and the sign-in's reader too), the key non-enumerable. */
|
|
995
|
+
function withGatewayKey(claimed, key) {
|
|
996
|
+
const out = Object.defineProperties({}, Object.getOwnPropertyDescriptors(claimed));
|
|
997
|
+
Object.defineProperty(out, GATEWAY_KEY_ENV, { value: key, enumerable: false, writable: false, configurable: false });
|
|
998
|
+
return out;
|
|
999
|
+
}
|
|
980
1000
|
/** The environment a run's process starts with: the runner's run environment's plain values (runEnv: its secrets are
|
|
981
1001
|
* not enumerable, so none is here), no key-shaped name, and where its keys come from. */
|
|
982
1002
|
function childEnv(base, keys, extra) {
|
|
@@ -1057,17 +1077,26 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1057
1077
|
if (!revisionRow)
|
|
1058
1078
|
throw new Error(`run ${claim.runId}: its revision ${runRow.revisionId} is gone from the store`);
|
|
1059
1079
|
const revision = { kind: revisionRow.kind, body: (revisionRow.body ?? {}) };
|
|
1080
|
+
// The model gateway saved in the console, read from the store now and laid over this claim's environment, as a run
|
|
1081
|
+
// in this process has it laid (harness-loops.ts): the run's process reads no store row of it and holds no seal key.
|
|
1082
|
+
const claimDeps = await withSavedGatewayDeps(deps);
|
|
1083
|
+
const claimEnv = claimDeps.env ?? {};
|
|
1084
|
+
const savedGateway = savedGatewayIn(claimEnv);
|
|
1060
1085
|
// The run's own keys: those its claim opens (claim-secrets.ts), the one list its loop in this process read.
|
|
1061
|
-
const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env:
|
|
1086
|
+
const claimed = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, launch);
|
|
1062
1087
|
// With them, its revision's own model's (a launch pinned at its start to another model, a --faux start's, is still
|
|
1063
1088
|
// handed its agent's model's key, as a run's own process was handed it before: run-secrets.ts secretsFor).
|
|
1064
|
-
const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env:
|
|
1089
|
+
const ofRevision = await claimSecrets({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }, revisionRow, { ...(launch.plane ? { plane: launch.plane } : {}) });
|
|
1065
1090
|
// A run that holds a model key of its own (model_key, its launch's) spends that key alone: its process is handed
|
|
1066
1091
|
// none of the server's model keys, as its spec drops them from its tools' (claim-secrets.ts withoutModelKeys).
|
|
1067
1092
|
// Copies: the runner's own reads (heldFor's `claimed`: what the run's learning must never keep) stay whole.
|
|
1068
1093
|
const keyed = (await openRunModelKey({ store: deps.store, sealKey: deps.sealKey }, claim.runId)) !== undefined;
|
|
1069
1094
|
const toProcess = keyed ? [withoutModelKeys({ ...claimed }), withoutModelKeys({ ...ofRevision })] : [claimed, ofRevision];
|
|
1070
|
-
|
|
1095
|
+
// The saved gateway's key, kept off the claim's tool keys (claimSecrets), is handed for the run's model routes alone,
|
|
1096
|
+
// read as the server's model keys are (savedModelKeys, over the claim's environment the gateway was laid over), as a
|
|
1097
|
+
// run in this process reads it from its environment by name; none to a run that brings its own key.
|
|
1098
|
+
const gatewayKey = savedGateway ? (keyed ? {} : await savedModelKeys({ store: deps.store, sealKey: deps.sealKey, env: claimEnv }))[GATEWAY_KEY_ENV] || undefined : undefined;
|
|
1099
|
+
const handed = (name) => (name === GATEWAY_KEY_ENV && savedGateway ? gatewayKey : toProcess.map((from) => from[name]).find((value) => typeof value === "string" && value !== ""));
|
|
1071
1100
|
const keys = encode(SECRET_NAMES.flatMap((name) => {
|
|
1072
1101
|
const value = handed(name);
|
|
1073
1102
|
return value === undefined ? [] : [[name, value]];
|
|
@@ -1091,7 +1120,7 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1091
1120
|
if (isolation.kind === "uid" && slot !== undefined)
|
|
1092
1121
|
hold = new SlotHold(slot, isolation.helper, log);
|
|
1093
1122
|
const tops = runTops(deps.data, runRow.agentId, claim.runId);
|
|
1094
|
-
const heldSide = heldFor(deps, { claim, run: runRow, launch, revision, claimed }, cut, log);
|
|
1123
|
+
const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed }, cut, log);
|
|
1095
1124
|
try {
|
|
1096
1125
|
let extra = {};
|
|
1097
1126
|
let argv = [...(options.argv ?? childArgv())];
|
|
@@ -1105,7 +1134,8 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1105
1134
|
extra = { TMPDIR: tmp, HOME: scratch };
|
|
1106
1135
|
argv = [isolation.helper, "run", String(slot), "--keep-fd", "3", "--keep-fd", "4", "--", ...argv];
|
|
1107
1136
|
}
|
|
1108
|
-
|
|
1137
|
+
// The saved gateway's address and models go as plain variables (childEnv), and its mark says they are the saved one.
|
|
1138
|
+
const env = childEnv(claimEnv, keys, savedGateway ? { ...extra, [SAVED_GATEWAY_ENV]: "1" } : extra);
|
|
1109
1139
|
const [program, ...rest] = argv;
|
|
1110
1140
|
child = spawn(program, rest, { stdio: ["ignore", "inherit", "inherit", "pipe", "pipe"], env, detached: true });
|
|
1111
1141
|
exited = new Promise((resolve) => {
|
package/dist/runner/runner.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type RunnerStore } from "./store-port.js";
|
|
|
3
3
|
import { type RunState } from "../store/store.js";
|
|
4
4
|
import { type Redact } from "./redact.js";
|
|
5
5
|
import { type LiveTickerOptions } from "./live-ticker.js";
|
|
6
|
+
import { type Presence } from "./presence.js";
|
|
6
7
|
/** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
|
|
7
8
|
/** A final run's status as its end line says it: the store holds a cancel as state 'stopped' with outcome 'cancelled', so
|
|
8
9
|
* the outcome tells a cancel from a person's resumable stop. */
|
|
@@ -42,6 +43,10 @@ export interface RunnerOptions {
|
|
|
42
43
|
live?: false | LiveTickerOptions;
|
|
43
44
|
/** This runner's name in the runs it claims (runs.runner). Default: host, pid and a random part. */
|
|
44
45
|
name?: string;
|
|
46
|
+
/** Its word in the store that it is there (presence.ts), kept by its caller (runner/main.ts, whose relay says where it
|
|
47
|
+
* answers on the same row, under the same incarnation): used as is, never closed here. Default: one of its own,
|
|
48
|
+
* removed at its close. */
|
|
49
|
+
presence?: Presence;
|
|
45
50
|
/** Most runs held at once. */
|
|
46
51
|
loops?: number;
|
|
47
52
|
/** How long a claim lasts unless renewed. */
|
package/dist/runner/runner.js
CHANGED
|
@@ -24,6 +24,7 @@ import { Unanswered } from "../store/postgres/connection.js";
|
|
|
24
24
|
import { clearWaitEnded } from "../browser-wait-ended.js";
|
|
25
25
|
import { heldRedactor, processSecretRedactor } from "./redact.js";
|
|
26
26
|
import { withLiveTicker } from "./live-ticker.js";
|
|
27
|
+
import { keepPresence } from "./presence.js";
|
|
27
28
|
/** Tries of the re-read after a claim or release commit was answered Unanswered (the commit may have landed). */
|
|
28
29
|
const UNKNOWN_READS = 5;
|
|
29
30
|
/** Passes of the sweep after a claim answered Unanswered: the commit may still be on its way when the first read comes back
|
|
@@ -927,6 +928,9 @@ export function startRunner(options) {
|
|
|
927
928
|
else
|
|
928
929
|
poll();
|
|
929
930
|
};
|
|
931
|
+
// Its word in the store that a runner that claims is here (presence.ts), for as long as it runs: a server reads a
|
|
932
|
+
// refusal left by an earlier runner as over once this is there. One its caller keeps is its caller's to close.
|
|
933
|
+
const presence = options.presence ? undefined : store.runners ? keepPresence(store.runners, name, null, { warn: (line) => emit({ type: "error", step: "presence", message: line }) }) : undefined;
|
|
930
934
|
poll();
|
|
931
935
|
commandTimer = setTimeout(deliverAll, commandPollMs);
|
|
932
936
|
// A run queued in this process is claimed now (claimNow). A command written for a run this runner holds is handed on
|
|
@@ -1067,11 +1071,15 @@ export function startRunner(options) {
|
|
|
1067
1071
|
// The live view's last tick, once every loop has ended or been given up: a draining run kept its live view to the
|
|
1068
1072
|
// end of its loop.
|
|
1069
1073
|
await ticker?.close();
|
|
1074
|
+
// It claims no more: its word that it is here goes.
|
|
1075
|
+
await presence?.close();
|
|
1070
1076
|
},
|
|
1071
1077
|
kill() {
|
|
1072
1078
|
killed = true;
|
|
1073
1079
|
closed = true;
|
|
1074
1080
|
stopTimers();
|
|
1081
|
+
// A crash says nothing more: its word goes stale, as a dead runner's does.
|
|
1082
|
+
presence?.stop();
|
|
1075
1083
|
// A crash writes nothing more: the live view's ticker stops at once, beside a new holder of its runs.
|
|
1076
1084
|
ticker?.stop();
|
|
1077
1085
|
},
|
|
@@ -9,6 +9,9 @@ export type RunnerStore = Pick<Store, "claim" | "renew" | "renewMany" | "release
|
|
|
9
9
|
/** The server's settings, for the one the runner removes at a run's end (browser-wait-ended.ts). A store without it (a
|
|
10
10
|
* test's) keeps none. */
|
|
11
11
|
readonly settings?: Store["settings"];
|
|
12
|
+
/** Every runner's word that it is there (runner/presence.ts): the runner keeps its own for as long as it runs. A store
|
|
13
|
+
* without it (a test's) keeps none. */
|
|
14
|
+
readonly runners?: Store["runners"];
|
|
12
15
|
};
|
|
13
16
|
/** The store's fence: a write under an epoch that moved. */
|
|
14
17
|
export declare function isFenced(error: unknown): boolean;
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// echoes it back. One read of the store across all its planes (store.sealedSecrets): tool, model, computer and Archil keys,
|
|
6
6
|
// the email account's password alone (its row holds the account whole), and the ChatGPT sign-in's access and refresh tokens each alone, renewed by whichever process holds the store (sealed_keys); MCP credentials, their headers' values and OAuth tokens and client secret (mcp_servers), and a sign-in in
|
|
7
7
|
// flight (mcp_oauth_pending); each trigger source's settings, a webhook trigger's signing secret and the GitHub App's key
|
|
8
|
-
// and webhook secret among them,
|
|
9
|
-
// but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
|
|
8
|
+
// and webhook secret among them, the outbound webhook's signing secret and Slack's incoming-webhook URL (whole and its
|
|
9
|
+
// token alone, slack-url.ts), each it held before too (trigger_settings), but a field its source marks public; browser sign-in pointers, live and forgotten; live viewer tokens; a launch's sealed
|
|
10
10
|
// part (a run's handed MCP credentials and its own model key). Beside the store, what the data directory keeps where the runner shares it (server-secrets.ts besideTheStore: the
|
|
11
11
|
// owner's API token and the sign-in session secret). Each value in every spelling the server's list has
|
|
12
12
|
// (standard-webhooks.ts secretForms), a PEM key whole and line by line. A value that does not open under the runner's key
|
|
@@ -15,8 +15,10 @@ import { CHATGPT_PLAN_ROW } from "../chatgpt-plan.js";
|
|
|
15
15
|
import { calendarRowSecrets } from "../calendar/address.js";
|
|
16
16
|
import { CALENDAR_ROW } from "../calendar/names.js";
|
|
17
17
|
import { accountRowSecrets, EMAIL_ACCOUNT_ROW } from "../email/account.js";
|
|
18
|
+
import { GATEWAY_KEY_ROW, gatewayKeyRowSecrets } from "../model-gateway.js";
|
|
18
19
|
import { unseal } from "../sealing.js";
|
|
19
20
|
import { besideTheStore, ServerSecrets } from "../server-secrets.js";
|
|
21
|
+
import { SLACK_CHANNEL, slackUrlForms } from "../slack-url.js";
|
|
20
22
|
import { TRIGGER_ADAPTERS } from "../trigger-adapters.js";
|
|
21
23
|
/** The keys of a sealed JSON value that hold secrets: OAuth tokens, a client's secret, a PKCE verifier. */
|
|
22
24
|
const JSON_SECRETS = ["access_token", "refresh_token", "id_token", "client_secret", "verifier"];
|
|
@@ -56,8 +58,9 @@ function jsonSecrets(text) {
|
|
|
56
58
|
return out;
|
|
57
59
|
}
|
|
58
60
|
/** A launch's sealed JSON: its own listed values (jsonSecrets), each handed MCP credential's headers (store/seal.ts
|
|
59
|
-
* sealRunLaunch: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed,
|
|
60
|
-
*
|
|
61
|
+
* sealRunLaunch: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed, each per-run Composio
|
|
62
|
+
* binding's user and account (`{"mcp": {"<server>": {"composio": {"user_id", "connected_account_id"}}}}`), and the run's
|
|
63
|
+
* own model key (`{"model": {"key": "..."}}`). */
|
|
61
64
|
function launchSecrets(text) {
|
|
62
65
|
const out = jsonSecrets(text);
|
|
63
66
|
let opened;
|
|
@@ -68,9 +71,15 @@ function launchSecrets(text) {
|
|
|
68
71
|
return out;
|
|
69
72
|
}
|
|
70
73
|
const mcp = opened?.mcp;
|
|
71
|
-
if (mcp && typeof mcp === "object")
|
|
72
|
-
for (const entry of Object.values(mcp))
|
|
74
|
+
if (mcp && typeof mcp === "object") {
|
|
75
|
+
for (const entry of Object.values(mcp)) {
|
|
73
76
|
out.push(...jsonSecrets(JSON.stringify(entry)));
|
|
77
|
+
const binding = entry?.composio;
|
|
78
|
+
for (const value of [binding?.user_id, binding?.connected_account_id])
|
|
79
|
+
if (typeof value === "string")
|
|
80
|
+
out.push(value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
74
83
|
if (typeof opened?.model?.key === "string")
|
|
75
84
|
out.push(opened.model.key);
|
|
76
85
|
return out;
|
|
@@ -93,6 +102,9 @@ const pemForms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.t
|
|
|
93
102
|
function secretsOf(row, plain, adapters) {
|
|
94
103
|
switch (row.plane) {
|
|
95
104
|
case "trigger_settings": {
|
|
105
|
+
// Slack's URL (live or retired): the URL whole and its token alone, as the server lists it.
|
|
106
|
+
if (row.where.adapter === SLACK_CHANNEL)
|
|
107
|
+
return { listed: slackUrlForms(plain), whole: [] };
|
|
96
108
|
const spec = adapters.find((adapter) => adapter.id === row.where.adapter)?.settings?.fields[row.where.field ?? ""];
|
|
97
109
|
if (spec?.public)
|
|
98
110
|
return { listed: [], whole: [] };
|
|
@@ -104,7 +116,7 @@ function secretsOf(row, plain, adapters) {
|
|
|
104
116
|
case "run_launch":
|
|
105
117
|
return { listed: plain.trimStart().startsWith("{") ? launchSecrets(plain) : [plain], whole: [] };
|
|
106
118
|
case "sealed_keys":
|
|
107
|
-
return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : row.where.name === CALENDAR_ROW ? calendarRowSecrets(plain) : [plain], whole: [] };
|
|
119
|
+
return { listed: row.where.name === CHATGPT_PLAN_ROW ? planSecrets(plain) : row.where.name === EMAIL_ACCOUNT_ROW ? accountRowSecrets(plain) : row.where.name === CALENDAR_ROW ? calendarRowSecrets(plain) : row.where.name === GATEWAY_KEY_ROW ? gatewayKeyRowSecrets(plain) : [plain], whole: [] };
|
|
108
120
|
default:
|
|
109
121
|
return { listed: [plain], whole: [] };
|
|
110
122
|
}
|