@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
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 +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- 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/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- 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/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- 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 +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- 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 +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- 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 +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- 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 +13 -2
- package/dist/store/agent-body.js +19 -4
- 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/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/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- 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/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- 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 +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
package/dist/runner/metrics.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ export declare function storedBasisOf(metrics: unknown, usd: number | null | und
|
|
|
61
61
|
* booking's. `side`: of the model requests, those booked as side calls (another model than the session's, or the host's
|
|
62
62
|
* own, as a learned workflow's node is: the proxy's `side`/`host`), which no answer of a pi run carries. */
|
|
63
63
|
export declare function bookedSpend(entries: readonly EntryLike[], which: "model" | "paid" | "decisions" | "side"): BookedSpend;
|
|
64
|
+
/** The run's decisions whose ids are in `ids` (each booked as `decision:<id>`), as bookedSpend reads its decisions, with
|
|
65
|
+
* every other decision left out: the ones a vendor charged as a paid call (store-reads/decisions.ts
|
|
66
|
+
* parallelChargedDecisions), which the run's tools figures count beside its paid tool calls. */
|
|
67
|
+
export declare function bookedDecisionsOf(entries: readonly EntryLike[], ids: ReadonlySet<string>): BookedSpend;
|
|
64
68
|
/** A cost of charges as a usage row or a run's cost block says it (costsofar/1, cutathold/1), by the kernel's one rule
|
|
65
69
|
* (costOfParts) over `parts`, its float noise rounded off (floatNoiseOff): `usd` their sum, `upper_bound` when it counts
|
|
66
70
|
* a cut request at its hold, with `so_far_usd` the charges' own figures alone and `unpriced` how many it counts at their
|
package/dist/runner/metrics.js
CHANGED
|
@@ -148,6 +148,15 @@ export function bookedSpend(entries, which) {
|
|
|
148
148
|
}
|
|
149
149
|
return { usd: unpriced ? null : known + bounded, known, bounded, unpriced, atMost, requests, unmetered, models, tokens, priced: { reported, estimated }, ...(requests > 0 && free === requests ? { free: true } : {}) };
|
|
150
150
|
}
|
|
151
|
+
/** The run's decisions whose ids are in `ids` (each booked as `decision:<id>`), as bookedSpend reads its decisions, with
|
|
152
|
+
* every other decision left out: the ones a vendor charged as a paid call (store-reads/decisions.ts
|
|
153
|
+
* parallelChargedDecisions), which the run's tools figures count beside its paid tool calls. */
|
|
154
|
+
export function bookedDecisionsOf(entries, ids) {
|
|
155
|
+
const turnOf = (e) => `${String(e.conversationId)}:${String(e.data?.turn)}`;
|
|
156
|
+
const named = (e) => e.data?.model;
|
|
157
|
+
const kept = new Set(entries.filter((e) => e.kind === RUNNER_RECORDS.request && typeof named(e) === "string" && named(e).startsWith("decision:") && ids.has(named(e).slice("decision:".length))).map(turnOf));
|
|
158
|
+
return bookedSpend(entries.filter((e) => !(e.kind === RUNNER_RECORDS.request || e.kind === RUNNER_RECORDS.turn) || kept.has(turnOf(e))), "decisions");
|
|
159
|
+
}
|
|
151
160
|
/** A sum of charges with its float noise rounded off, nothing more (as the decisions row rounds, decision-rows.ts): a
|
|
152
161
|
* decision costs millionths of a dollar, so a sum rounded to the millionth would lose it. */
|
|
153
162
|
const floatNoiseOff = (usd) => Math.round(usd * 1e12) / 1e12;
|
|
@@ -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;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Duplex } from "node:stream";
|
|
2
2
|
import type { Workspace } from "../workspace/workspace.js";
|
|
3
3
|
import { type AdapterSpecDeps } from "./adapter-run-spec.js";
|
|
4
4
|
import type { Held } from "./held.js";
|
|
5
5
|
import { type Claim, type LoopFactory } from "./loop-contract.js";
|
|
6
|
+
import { Channel } from "./run-channel.js";
|
|
7
|
+
import { type RunBigWrites } from "./big-writes.js";
|
|
8
|
+
import { type SaveSlots } from "../web-save.js";
|
|
6
9
|
import { type RunLaunch } from "../run-launch.js";
|
|
7
10
|
/** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
|
|
8
11
|
export declare const RUNAS_HELPER = "/usr/local/bin/agentrun-runas";
|
|
@@ -70,19 +73,16 @@ export declare class SlotHold {
|
|
|
70
73
|
}
|
|
71
74
|
/** The run's own top folders: its folder (work and recordings beneath it) and its scratch folder. */
|
|
72
75
|
export declare const runTops: (data: string, agentId: string, runId: string) => string[];
|
|
73
|
-
/**
|
|
74
|
-
* the
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/** The other slots that own an entry anywhere under `dir`, as the helper's reown walks it: the whole tree, a symlink
|
|
79
|
-
* never followed (an lstat's, never a directory). `statOf`: the stat it reads (a test's). */
|
|
80
|
-
export declare function slotsUnder(dir: string, slot: number, statOf?: (path: string) => Promise<Stats>): Promise<number[]>;
|
|
76
|
+
/** At a claim, before anything of the run is placed: its top folders and everything in them the server's user's again
|
|
77
|
+
* (the helper's `own runner`), whoever an earlier claim left them to. Throws, in words, when they could not be. */
|
|
78
|
+
export declare function takeBackRunFolders(isolation: Extract<RunIsolation, {
|
|
79
|
+
kind: "uid";
|
|
80
|
+
}>, tops: readonly string[]): Promise<void>;
|
|
81
81
|
/** After the run's process ended: every process of the slot's uid killed, its files in the shared temporary folders
|
|
82
|
-
* removed,
|
|
83
|
-
*
|
|
84
|
-
* the uid is left, and says so
|
|
85
|
-
* again by this runner). */
|
|
82
|
+
* removed, and its top folders with everything in them given back to the server's user (the helper's `own runner`:
|
|
83
|
+
* the server's uid and group, folders 2770), which the slot's next run cannot enter. Whether the reap held: the helper
|
|
84
|
+
* kills until no process of the uid is left, and says so, and the folders were given back; false when a process still
|
|
85
|
+
* is, or either step could not run (the slot is then never run on again by this runner). */
|
|
86
86
|
export declare function reapSlot(isolation: Extract<RunIsolation, {
|
|
87
87
|
kind: "uid";
|
|
88
88
|
}>, slot: number, tops: readonly string[], log: (line: string) => void): Promise<boolean>;
|
|
@@ -118,10 +118,11 @@ interface ClaimReads {
|
|
|
118
118
|
readonly claimed: NodeJS.ProcessEnv;
|
|
119
119
|
}
|
|
120
120
|
/** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
|
|
121
|
-
* runner's own reads of the claim; every argument from the run's process is checked or ignored.
|
|
121
|
+
* runner's own reads of the claim; every argument from the run's process is checked or ignored. `bigs`: the run's pieced
|
|
122
|
+
* writes (big-writes.ts), let go at the claim's release and, by the caller, when the run's channel ends. */
|
|
122
123
|
export declare function heldFor(deps: AdapterSpecDeps & {
|
|
123
124
|
readonly sealKey: Buffer;
|
|
124
|
-
}, reads: ClaimReads, cut: (text: string) => string, log: (line: string) => void): {
|
|
125
|
+
}, reads: ClaimReads, cut: (text: string) => string, log: (line: string) => void, bigs?: RunBigWrites): {
|
|
125
126
|
held: Held;
|
|
126
127
|
inputs(): Promise<void>;
|
|
127
128
|
release(): Promise<void>;
|
|
@@ -149,9 +150,10 @@ export declare const childArgv: () => string[];
|
|
|
149
150
|
* A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
|
|
150
151
|
* and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
|
|
151
152
|
* run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
|
|
152
|
-
* its inbox. A
|
|
153
|
+
* its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
|
|
154
|
+
* A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
|
|
153
155
|
* connectors, whose rows are the server's. */
|
|
154
|
-
export declare const runsInRunner: (harness: string, launch: Pick<RunLaunch, "sdk" | "native">) => boolean;
|
|
156
|
+
export declare const runsInRunner: (harness: string, launch: Pick<RunLaunch, "sdk" | "native" | "cli_learning">) => boolean;
|
|
155
157
|
/** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
|
|
156
158
|
export declare const LOGIN_NEEDS_SERVER_USER = "A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set AGENTRUN_RUN_USER=same, or give the run a model_key.";
|
|
157
159
|
/** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
|
|
@@ -166,4 +168,12 @@ export declare function staysInRunner(deps: Pick<AdapterSpecDeps, "store" | "dat
|
|
|
166
168
|
/** The runner's loop factory where each run is a process of its own: a ChildLoop per claim, but for a run that stays in
|
|
167
169
|
* the runner (staysInRunner). */
|
|
168
170
|
export declare function childLoops(options: ChildLoopsOptions): LoopFactory;
|
|
171
|
+
/** The runner's side of a run's channel over `socket`. Each call of the run's process runs inside the ledger of the tool
|
|
172
|
+
* call it was made in (paid-calls.ts). web_save's slots are `gate`, this runner's one (save-slots.ts); the channel's end
|
|
173
|
+
* (the run's end, or its process gone) gives back every slot the run held or waited for, and lets go of every pieced write
|
|
174
|
+
* of the run's `bigs` (big-writes.ts), held or waiting. `maxFrame`: the channel's (a test's), default MAX_FRAME. */
|
|
175
|
+
export declare function runChannel(socket: Duplex, onClose: (why: Error) => void, gate?: SaveSlots, more?: {
|
|
176
|
+
readonly bigs?: RunBigWrites;
|
|
177
|
+
readonly maxFrame?: number;
|
|
178
|
+
}): Channel;
|
|
169
179
|
export {};
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
// opens for the claim (held.ts), never the key. The runner keeps the claim, its renewals, its commands and its end.
|
|
7
7
|
//
|
|
8
8
|
// Where the image's helper can switch (agentrun-runas, root:node 0750 with file capabilities), each of the runner's claim
|
|
9
|
-
// slots runs as a uid of its own (1001 + slot), in
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
9
|
+
// slots runs as a uid of its own (1001 + slot), in its own group alone. While a run holds its slot, its folders are the
|
|
10
|
+
// slot's uid's and the runner's group's (2770, setgid, the helper's `own <slot>`), which the server's user reads through
|
|
11
|
+
// that one group: the server's user is in no slot's group, and no slot is in the server's, so one run can read neither
|
|
12
|
+
// another run's folder nor, being another uid, its memory. A slot is reaped at each run's end (every process of its uid
|
|
13
|
+
// killed, its files in /tmp removed), and its folders are given back to the server's user (`own runner`), so the slot's
|
|
14
|
+
// next run reaches nothing of them.
|
|
13
15
|
import { execFile, spawn } from "node:child_process";
|
|
14
16
|
import { existsSync } from "node:fs";
|
|
15
|
-
import { chmod,
|
|
17
|
+
import { chmod, mkdir, rm } from "node:fs/promises";
|
|
16
18
|
import { dirname, join } from "node:path";
|
|
17
19
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
18
20
|
import { encode, SECRET_NAMES, SECRETS_FD_ENV, SECRETS_LEN_ENV, withoutSecrets } from "../secrets.js";
|
|
@@ -51,7 +53,7 @@ import { liveForRun, runnerLiveOf } from "../live-reach.js";
|
|
|
51
53
|
import { learningFolderOf, secretsShown } from "../learning.js";
|
|
52
54
|
import { learningStartOf, seedFailed } from "../run-launch.js";
|
|
53
55
|
import { messageText } from "../run-manifest.js";
|
|
54
|
-
import { placeRunInputs } from "../uploads.js";
|
|
56
|
+
import { filesToCopy, placeRunInputs } from "../uploads.js";
|
|
55
57
|
import { withAudit } from "./audit.js";
|
|
56
58
|
import { compareEndOfRun } from "./compare-end.js";
|
|
57
59
|
import { learnedFirst } from "./learned-first.js";
|
|
@@ -66,6 +68,9 @@ import { heardComputerHold } from "./computer-journal.js";
|
|
|
66
68
|
import { ClaimRefused } from "./loop-contract.js";
|
|
67
69
|
import { Channel, ChannelClosed } from "./run-channel.js";
|
|
68
70
|
import { registerRunErrors } from "./run-errors.js";
|
|
71
|
+
import { exposeSaveSlots } from "./save-slots.js";
|
|
72
|
+
import { runBigWrites } from "./big-writes.js";
|
|
73
|
+
import { SERVER_SLOTS } from "../web-save.js";
|
|
69
74
|
import { readLaunchBody } from "../run-launch.js";
|
|
70
75
|
import { SUBAGENT_TOOL } from "./subagent.js";
|
|
71
76
|
/** The image's helper that starts a run's process as its slot's uid (packages/serve/runas). */
|
|
@@ -262,121 +267,51 @@ const runParents = (data, agentId, runId) => {
|
|
|
262
267
|
const scratch = scratchFolder(data, agentId, runId);
|
|
263
268
|
return [data, join(data, "disk"), join(data, "disk", "agents"), join(data, "disk", "agents", agentDirName(agentId)), dirname(top), join(data, "scratch"), dirname(scratch)];
|
|
264
269
|
};
|
|
265
|
-
/** Before the run's process starts on `slot`: its parents traverse-only, its
|
|
266
|
-
*
|
|
270
|
+
/** Before the run's process starts on `slot`: its parents traverse-only, the folders its process opens first made (its
|
|
271
|
+
* folder, its recordings and its temporary folder, its TMPDIR), and its top folders with everything in them given to the
|
|
272
|
+
* slot (the helper's `own <slot>`: the slot's uid, the runner's group, folders 2770). What an earlier claim's slot left,
|
|
273
|
+
* and what the server's user placed at this claim, is the slot's with the rest. */
|
|
267
274
|
async function layRunFolders(isolation, data, agentId, runId, slot) {
|
|
268
275
|
for (const parent of runParents(data, agentId, runId)) {
|
|
269
276
|
await mkdir(parent, { recursive: true });
|
|
270
277
|
await chmod(parent, 0o711);
|
|
271
278
|
}
|
|
272
|
-
const
|
|
273
|
-
for (const
|
|
274
|
-
await mkdir(top, { recursive: true });
|
|
275
|
-
await chown(top, process.getuid(), gid);
|
|
276
|
-
await chmod(top, 0o2770);
|
|
277
|
-
// An earlier claim of this run on another slot left its files that slot's: given to this one, so the run reads and
|
|
278
|
-
// writes what it wrote before.
|
|
279
|
-
for (const other of await slotsUnder(top, slot)) {
|
|
280
|
-
const moved = await execText(isolation.helper, ["reown", String(other), String(slot), top], 120_000);
|
|
281
|
-
if (moved.code !== 0)
|
|
282
|
-
throw new Error(`the run's folder could not be given to its slot: ${moved.stderr.trim()}`);
|
|
283
|
-
}
|
|
284
|
-
// What the server's user made there (a run's inputs placed at this claim, an earlier run's folders on a volume from
|
|
285
|
-
// before runs had slots of their own): the slot group's, so the run writes there too.
|
|
286
|
-
await toSlotGroup(top, gid);
|
|
287
|
-
}
|
|
288
|
-
// The folders the run's process opens first, made here in the slot's group (setgid): its folder, its recordings and its
|
|
289
|
-
// temporary folder (its TMPDIR), each one the server reads through the group as the run writes it.
|
|
290
|
-
for (const folder of [runFolder(data, agentId, runId), recordingsFolder(data, agentId, runId), join(scratchFolder(data, agentId, runId), "tmp")]) {
|
|
279
|
+
const tops = runTops(data, agentId, runId);
|
|
280
|
+
for (const folder of [...tops, runFolder(data, agentId, runId), recordingsFolder(data, agentId, runId), join(scratchFolder(data, agentId, runId), "tmp")])
|
|
291
281
|
await mkdir(folder, { recursive: true });
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
await chown(folder, process.getuid(), gid);
|
|
296
|
-
await chmod(folder, 0o2770);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/** Every entry under `dir` the server's user owns, given to group `gid` as the helper's reown gives a slot's: a folder
|
|
300
|
-
* the group's to enter and write (2770), a file's owner bits copied to the group, none for others. The whole tree, a
|
|
301
|
-
* symlink never followed nor changed (an lstat's). Run while no process of the slot is alive (after its reap), so
|
|
302
|
-
* nothing it walks is swapped under it. */
|
|
303
|
-
export async function toSlotGroup(dir, gid) {
|
|
304
|
-
const me = process.getuid();
|
|
305
|
-
const walk = async (at) => {
|
|
306
|
-
let names;
|
|
307
|
-
try {
|
|
308
|
-
names = await readdir(at);
|
|
309
|
-
}
|
|
310
|
-
catch {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
for (const name of names) {
|
|
314
|
-
const path = join(at, name);
|
|
315
|
-
const stat = await lstat(path).catch(() => undefined);
|
|
316
|
-
if (!stat || stat.isSymbolicLink())
|
|
317
|
-
continue;
|
|
318
|
-
if (stat.uid === me) {
|
|
319
|
-
await lchown(path, me, gid);
|
|
320
|
-
const owner = stat.mode & 0o700;
|
|
321
|
-
await chmod(path, stat.isDirectory() ? 0o2770 : owner | (owner >> 3));
|
|
322
|
-
}
|
|
323
|
-
if (stat.isDirectory())
|
|
324
|
-
await walk(path);
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
await walk(dir);
|
|
328
|
-
}
|
|
329
|
-
/** The other slots that own an entry anywhere under `dir`, as the helper's reown walks it: the whole tree, a symlink
|
|
330
|
-
* never followed (an lstat's, never a directory). `statOf`: the stat it reads (a test's). */
|
|
331
|
-
export async function slotsUnder(dir, slot, statOf = lstat) {
|
|
332
|
-
const found = new Set();
|
|
333
|
-
const look = async (at) => {
|
|
334
|
-
let names;
|
|
335
|
-
try {
|
|
336
|
-
names = await readdir(at);
|
|
337
|
-
}
|
|
338
|
-
catch {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
for (const name of names) {
|
|
342
|
-
const path = join(at, name);
|
|
343
|
-
const stat = await statOf(path).catch(() => undefined);
|
|
344
|
-
if (!stat)
|
|
345
|
-
continue;
|
|
346
|
-
const other = stat.uid - FIRST_RUN_ID;
|
|
347
|
-
if (other >= 0 && other < RUN_SLOTS && other !== slot)
|
|
348
|
-
found.add(other);
|
|
349
|
-
if (stat.isDirectory())
|
|
350
|
-
await look(path);
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
await look(dir);
|
|
354
|
-
return [...found];
|
|
282
|
+
const given = await execText(isolation.helper, ["own", String(slot), ...tops], 120_000);
|
|
283
|
+
if (given.code !== 0)
|
|
284
|
+
throw new Error(`the run's folders could not be given to its slot: ${given.stderr.trim() || `${isolation.helper} own exited ${given.code}`}`);
|
|
355
285
|
}
|
|
356
286
|
/** The host's shared folders a slot's uid can leave a file in, each swept at its reap (/var/lock is /run/lock's link on
|
|
357
287
|
* Debian, swept as itself where it is a folder of its own). SysV IPC is not swept. */
|
|
358
288
|
const SWEPT = ["/tmp", "/var/tmp", "/dev/shm", "/run/lock", "/var/lock", "/dev/mqueue"];
|
|
289
|
+
/** At a claim, before anything of the run is placed: its top folders and everything in them the server's user's again
|
|
290
|
+
* (the helper's `own runner`), whoever an earlier claim left them to. Throws, in words, when they could not be. */
|
|
291
|
+
export async function takeBackRunFolders(isolation, tops) {
|
|
292
|
+
const taken = await execText(isolation.helper, ["own", "runner", ...tops], 120_000);
|
|
293
|
+
if (taken.code !== 0)
|
|
294
|
+
throw new Error(`the run's folders could not be taken back from the slot an earlier claim left them to: ${taken.stderr.trim() || `${isolation.helper} own exited ${taken.code}`}`);
|
|
295
|
+
}
|
|
359
296
|
/** After the run's process ended: every process of the slot's uid killed, its files in the shared temporary folders
|
|
360
|
-
* removed,
|
|
361
|
-
*
|
|
362
|
-
* the uid is left, and says so
|
|
363
|
-
* again by this runner). */
|
|
297
|
+
* removed, and its top folders with everything in them given back to the server's user (the helper's `own runner`:
|
|
298
|
+
* the server's uid and group, folders 2770), which the slot's next run cannot enter. Whether the reap held: the helper
|
|
299
|
+
* kills until no process of the uid is left, and says so, and the folders were given back; false when a process still
|
|
300
|
+
* is, or either step could not run (the slot is then never run on again by this runner). */
|
|
364
301
|
export async function reapSlot(isolation, slot, tops, log) {
|
|
365
|
-
const
|
|
366
|
-
const reaped = await execText(isolation.helper, args, 120_000);
|
|
302
|
+
const reaped = await execText(isolation.helper, ["reap", String(slot), ...SWEPT.flatMap((dir) => ["--sweep", dir])], 120_000);
|
|
367
303
|
if (reaped.code !== 0)
|
|
368
304
|
log(`slot ${slot}'s reap said: ${reaped.stderr.trim()}`);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
log(`the run's folder ${top} was not given back to the server: ${error.message}`);
|
|
305
|
+
// Given back whether or not the reap held: a process of the slot's uid still alive then reaches its folders no more.
|
|
306
|
+
let back = true;
|
|
307
|
+
if (tops.length) {
|
|
308
|
+
const given = await execText(isolation.helper, ["own", "runner", ...tops], 120_000);
|
|
309
|
+
if (given.code !== 0) {
|
|
310
|
+
log(`slot ${slot}'s folders were not all given back to the server: ${given.stderr.trim()}`);
|
|
311
|
+
back = false;
|
|
377
312
|
}
|
|
378
313
|
}
|
|
379
|
-
return reaped.code === 0;
|
|
314
|
+
return reaped.code === 0 && back;
|
|
380
315
|
}
|
|
381
316
|
/** After a reap that held: the run's scratch folder as a claim's end in the runner's own process leaves it (cli-run-spec.ts
|
|
382
317
|
* sweepScratch), with the temporary folder the runner laid for its process (its TMPDIR) gone too. The agent's folder
|
|
@@ -627,14 +562,15 @@ async function readOf(reads, method, args) {
|
|
|
627
562
|
/** The email tools a revision may grant. */
|
|
628
563
|
const grantsEmail = (granted) => granted.some((tool) => tool.startsWith("email_"));
|
|
629
564
|
/** Held (held.ts) for one claim, on the runner: each answer the claim's own, read with the runner's seal key from the
|
|
630
|
-
* runner's own reads of the claim; every argument from the run's process is checked or ignored.
|
|
631
|
-
|
|
565
|
+
* runner's own reads of the claim; every argument from the run's process is checked or ignored. `bigs`: the run's pieced
|
|
566
|
+
* writes (big-writes.ts), let go at the claim's release and, by the caller, when the run's channel ends. */
|
|
567
|
+
export function heldFor(deps, reads, cut, log, bigs = runBigWrites()) {
|
|
632
568
|
const { claim, run, launch, revision, claimed } = reads;
|
|
633
569
|
const sealKey = deps.sealKey;
|
|
634
570
|
const store = deps.store;
|
|
635
571
|
const granted = revision.body.tools ?? [];
|
|
636
572
|
const keys = { store, sealKey, env: deps.env };
|
|
637
|
-
const releases = [];
|
|
573
|
+
const releases = [() => bigs.close()];
|
|
638
574
|
const fromGitHub = launch.inputOrigin?.kind === "trigger" && launch.inputOrigin.source === "github";
|
|
639
575
|
const github = () => githubAppAccess(store, sealKey, launch.input, { ...(deps.githubApi ? { api: deps.githubApi } : {}), fromGitHub, ...(launch.repo !== undefined ? { repo: launch.repo } : {}) });
|
|
640
576
|
/** Mode 2's Archil claim, made once for the claim on the runner, its folder the run's. */
|
|
@@ -643,7 +579,7 @@ export function heldFor(deps, reads, cut, log) {
|
|
|
643
579
|
const settings = await loadArchilSettings(store, deps.env);
|
|
644
580
|
if (settings === undefined)
|
|
645
581
|
return undefined;
|
|
646
|
-
const made = await archilClaim({ settings, keys: store.sealedKeys, sealKey, signal: new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS, ...(deps.mountControl
|
|
582
|
+
const made = await archilClaim({ settings, keys: store.sealedKeys, sealKey, signal: new AbortController().signal, env: deps.env, mount: { runId: claim.runId, epoch: claim.epoch, ttlMs: MOUNT_TTL_MS }, ...(deps.mountControl ? { control: deps.mountControl } : {}), run: { agentId: run.agentId, ...(launch.archilDisk ? { launch: launch.archilDisk } : {}), store }, ...(deps.makeArchilDisk ? { makeDisk: deps.makeArchilDisk } : {}) });
|
|
647
583
|
releases.push(() => made.release());
|
|
648
584
|
return made;
|
|
649
585
|
})());
|
|
@@ -798,7 +734,8 @@ export function heldFor(deps, reads, cut, log) {
|
|
|
798
734
|
return undefined;
|
|
799
735
|
const ws = await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
|
|
800
736
|
releases.push(() => ws.end());
|
|
801
|
-
|
|
737
|
+
// A write bigger than the channel's frame is pulled in pieces and written here, on this Workspace (big-writes.ts).
|
|
738
|
+
return { workspace: ws.workspace, pieces: bigs.pieces(ws.workspace), revoke: () => made.revoke(), inherit: async () => made.inherit(), release: async () => { } };
|
|
802
739
|
},
|
|
803
740
|
endOfRun: async (input) => {
|
|
804
741
|
// 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
|
|
@@ -883,7 +820,7 @@ export function heldFor(deps, reads, cut, log) {
|
|
|
883
820
|
? await openRunWorkspace({ mode: 1, agentId: run.agentId, runId: claim.runId, data: deps.data, log })
|
|
884
821
|
: await openRunWorkspace({ mode: 2, agentId: run.agentId, runId: claim.runId, archil: made, log });
|
|
885
822
|
try {
|
|
886
|
-
await placeRunInputs(deps.data, claim.runId, ws.workspace, launch
|
|
823
|
+
await placeRunInputs(deps.data, claim.runId, ws.workspace, filesToCopy(launch), messageText(launch.input));
|
|
887
824
|
}
|
|
888
825
|
finally {
|
|
889
826
|
await ws.end();
|
|
@@ -946,9 +883,10 @@ export const childArgv = () => [process.execPath, "--import", new URL("../secret
|
|
|
946
883
|
* A built-in learning run (its launch names harness "learning"): its grade is one ask through the runner's model route,
|
|
947
884
|
* and its one write is the merge into the agent's learning folder, which no run's process may write. An SDK backend
|
|
948
885
|
* run (launch.sdk): its agent runs in the caller's application, and its loop here reads the evidence it posts and closes
|
|
949
|
-
* its inbox. A
|
|
886
|
+
* its inbox. A CLI capture (launch.cli_learning) likewise only receives source evidence and serves owner corrections.
|
|
887
|
+
* A native run (launch.native): its agent is the source machine's own sign-in, reached through the server's
|
|
950
888
|
* connectors, whose rows are the server's. */
|
|
951
|
-
export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native);
|
|
889
|
+
export const runsInRunner = (harness, launch) => harness === "learning" || Boolean(launch.sdk) || Boolean(launch.native) || Boolean(launch.cli_learning);
|
|
952
890
|
/** The words a run on Claude Code's login on this machine is refused in where each run is a user of its own. */
|
|
953
891
|
export const LOGIN_NEEDS_SERVER_USER = `A run on Claude Code's login on this machine needs runs under the server's own user, and this runner runs each run as a user of its own: set ${RUN_USER_ENV}=same, or give the run a model_key.`;
|
|
954
892
|
/** Whether run `runId` stays in its runner's process: runsInRunner's, and a workflow run on a server with a documents
|
|
@@ -1009,6 +947,16 @@ function childEnv(base, keys, extra) {
|
|
|
1009
947
|
delete env[name];
|
|
1010
948
|
return { ...env, ...extra, [SECRETS_FD_ENV]: "3", [SECRETS_LEN_ENV]: String(keys.length) };
|
|
1011
949
|
}
|
|
950
|
+
/** The runner's side of a run's channel over `socket`. Each call of the run's process runs inside the ledger of the tool
|
|
951
|
+
* call it was made in (paid-calls.ts). web_save's slots are `gate`, this runner's one (save-slots.ts); the channel's end
|
|
952
|
+
* (the run's end, or its process gone) gives back every slot the run held or waited for, and lets go of every pieced write
|
|
953
|
+
* of the run's `bigs` (big-writes.ts), held or waiting. `maxFrame`: the channel's (a test's), default MAX_FRAME. */
|
|
954
|
+
export function runChannel(socket, onClose, gate = SERVER_SLOTS, more = {}) {
|
|
955
|
+
let saves;
|
|
956
|
+
const channel = new Channel(socket, { onClose: (why) => { onClose(why); saves?.(); more.bigs?.close(); }, within: withinCarried, ...(more.maxFrame ? { maxFrame: more.maxFrame } : {}) });
|
|
957
|
+
saves = exposeSaveSlots(channel, gate);
|
|
958
|
+
return channel;
|
|
959
|
+
}
|
|
1012
960
|
function childLoop(options, slots, loopDeps) {
|
|
1013
961
|
const { deps, isolation } = options;
|
|
1014
962
|
const cut = loopDeps.redact ?? ((text) => text);
|
|
@@ -1120,10 +1068,17 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1120
1068
|
if (isolation.kind === "uid" && slot !== undefined)
|
|
1121
1069
|
hold = new SlotHold(slot, isolation.helper, log);
|
|
1122
1070
|
const tops = runTops(deps.data, runRow.agentId, claim.runId);
|
|
1123
|
-
|
|
1071
|
+
// The run's pieced writes (big-writes.ts): let go when its channel ends, or at the claim's release.
|
|
1072
|
+
const bigs = runBigWrites();
|
|
1073
|
+
const heldSide = heldFor({ ...deps, env: claimEnv }, { claim, run: runRow, launch, revision, claimed: gatewayKey ? withGatewayKey(claimed, gatewayKey) : claimed }, cut, log, bigs);
|
|
1124
1074
|
try {
|
|
1125
1075
|
let extra = {};
|
|
1126
1076
|
let argv = [...(options.argv ?? childArgv())];
|
|
1077
|
+
// A claim that resumes a run whose last runner ended before giving its folders back finds them its last slot's,
|
|
1078
|
+
// perhaps shut (a run's own chmod 700): taken back first, so the inputs and folders below are laid as the
|
|
1079
|
+
// server's, then given to this slot.
|
|
1080
|
+
if (isolation.kind === "uid" && slot !== undefined)
|
|
1081
|
+
await takeBackRunFolders(isolation, tops);
|
|
1127
1082
|
// The run's uploads and opening message, placed by the runner before its process starts (their hold is the
|
|
1128
1083
|
// server's alone), then given to the slot with its folders.
|
|
1129
1084
|
await heldSide.inputs();
|
|
@@ -1151,8 +1106,7 @@ function childLoop(options, slots, loopDeps) {
|
|
|
1151
1106
|
keyPipe.end(keys);
|
|
1152
1107
|
const socket = child.stdio[4];
|
|
1153
1108
|
let broke;
|
|
1154
|
-
|
|
1155
|
-
channel = new Channel(socket, { onClose: (why) => void (broke ??= why), within: withinCarried });
|
|
1109
|
+
channel = runChannel(socket, (why) => void (broke ??= why), SERVER_SLOTS, { bigs });
|
|
1156
1110
|
const bound = { claim, agentId: runRow.agentId, revisionId: runRow.revisionId };
|
|
1157
1111
|
channel.expose("store", (method, args) => storeCall(deps.store, method, args, bound, log));
|
|
1158
1112
|
channel.expose("journal", journalTarget(loopDeps.journal(claim), cut));
|
package/dist/runner/run-child.js
CHANGED
|
@@ -16,6 +16,7 @@ import { routeOf } from "./model-route.js";
|
|
|
16
16
|
import { heldRedactor, processSecretRedactor } from "./redact.js";
|
|
17
17
|
import { Channel } from "./run-channel.js";
|
|
18
18
|
import { registerRunErrors } from "./run-errors.js";
|
|
19
|
+
import { remoteSaveSlots } from "./save-slots.js";
|
|
19
20
|
import { runEnv } from "./main.js";
|
|
20
21
|
import { carriedLedger } from "../paid-calls.js";
|
|
21
22
|
import { heldHands } from "../workspace/computer-hold.js";
|
|
@@ -179,6 +180,8 @@ function childDeps(init, store, journal, held) {
|
|
|
179
180
|
computerForClaim,
|
|
180
181
|
computerDeps: {},
|
|
181
182
|
installForClaim: heldInstall,
|
|
183
|
+
// web_save's download slots are the runner's, shared by all its runs (save-slots.ts).
|
|
184
|
+
saveSlots: remoteSaveSlots(channel),
|
|
182
185
|
...(init.githubApi ? { githubApi: init.githubApi } : {}),
|
|
183
186
|
...(init.githubWeb ? { githubWeb: init.githubWeb } : {}),
|
|
184
187
|
...(init.githubMcpOrigin ? { githubMcpOrigin: init.githubMcpOrigin } : {}),
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError } from "@earendil-works/pi-durable";
|
|
5
5
|
import { CommandTaken, Fenced, RunFinal, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreLaunchMissing, StoreWorkerLost } from "../store/store.js";
|
|
6
6
|
import { Unanswered } from "../store/postgres/connection.js";
|
|
7
|
+
import { WorkspaceError } from "../workspace/workspace.js";
|
|
7
8
|
import { LaunchUnreadable, UnknownHarness } from "./dispatch.js";
|
|
8
9
|
import { NeverFits } from "./harness-loops.js";
|
|
9
10
|
import { ClaimRefused } from "./loop-contract.js";
|
|
@@ -16,5 +17,6 @@ export function registerRunErrors() {
|
|
|
16
17
|
ClaimRefused, NeverFits, McpClaimRefused, ClaimLost, UnknownHarness, LaunchUnreadable,
|
|
17
18
|
Fenced, CommandTaken, RunFinal, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreLaunchMissing, StoreWorkerLost, Unanswered,
|
|
18
19
|
ConversationBusy, ConversationIdle, ReadAfterWrite, ReadOnlySession, SessionFailed, StorageRequestError,
|
|
20
|
+
WorkspaceError,
|
|
19
21
|
});
|
|
20
22
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Settings } from "../store/store.js";
|
|
2
|
+
/** The store.settings key a server keeps the names of its run-facing environment under at each start: `{ v: 1, names }`. */
|
|
3
|
+
export declare const RUN_ENV_KEY = "server.run_env";
|
|
4
|
+
export declare const STORE_URL_ENV = "AGENTRUN_STORE_URL";
|
|
5
|
+
/** Whether `name` is one a run's claim reads from its runner's environment (FIXED, or an upstream's address). */
|
|
6
|
+
export declare const runFacing: (name: string) => boolean;
|
|
7
|
+
/** The run-facing names `read` holds, sorted: of FIXED and of `listed` (the environment's own names, for its upstreams). */
|
|
8
|
+
export declare function runFacingNames(read: (name: string) => string | undefined, listed: Iterable<string>): string[];
|
|
9
|
+
/** The server's start: the names of its run-facing environment, replacing the last start's. Names only, never a value. */
|
|
10
|
+
export declare function recordRunEnv(store: {
|
|
11
|
+
settings: Pick<Settings, "put">;
|
|
12
|
+
}, names: readonly string[]): Promise<void>;
|
|
13
|
+
/** The names the server kept at its last start (recordRunEnv), or undefined when it kept none (a server older than this). */
|
|
14
|
+
export declare function serverRunEnv(store: {
|
|
15
|
+
settings: Pick<Settings, "get">;
|
|
16
|
+
}): Promise<string[] | undefined>;
|
|
17
|
+
/** One line of the check: a name (or what it checked, for the heartbeat) and its state, with why. Never a value. */
|
|
18
|
+
export type CheckRow = {
|
|
19
|
+
readonly state: "ok" | "missing" | "bad" | "skipped" | "warn";
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly why: string;
|
|
22
|
+
};
|
|
23
|
+
/** States that fail the check. */
|
|
24
|
+
export declare const failing: (row: CheckRow) => boolean;
|
|
25
|
+
export interface RunnerEnvCheckOptions {
|
|
26
|
+
/** --data, when given: a SQLite store and the seal key's file are read there when the environment names neither. */
|
|
27
|
+
readonly dataDir?: string;
|
|
28
|
+
/** The runner's environment (AGENTRUN_STORE_SCHEMA and every name it lists). */
|
|
29
|
+
readonly env: NodeJS.ProcessEnv;
|
|
30
|
+
/** A name's value as the runner would read it: its secret handed over by the launcher, else its environment's. */
|
|
31
|
+
readonly read: (name: string) => string | undefined;
|
|
32
|
+
/** Whether a TCP connect to `host`:`port` is answered within `ms` (a test's stand-in). */
|
|
33
|
+
readonly answers?: (host: string, port: number, ms: number) => Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
/** How long a forwarder has to answer the check's connect. */
|
|
36
|
+
export declare const FORWARDER_MS = 2000;
|
|
37
|
+
/** Whether `host`:`port` takes a TCP connection within `ms`. */
|
|
38
|
+
export declare function tcpAnswers(host: string, port: number, ms: number): Promise<boolean>;
|
|
39
|
+
/** `value`'s host and port when it is an http(s) URL on this machine's loopback, else undefined. */
|
|
40
|
+
export declare function loopbackTarget(value: string): {
|
|
41
|
+
host: string;
|
|
42
|
+
port: number;
|
|
43
|
+
} | undefined;
|
|
44
|
+
/** The runner's environment checked (the header's contract), one row per name. The store is opened as a runner, with a
|
|
45
|
+
* pool of one, and closed before this returns. */
|
|
46
|
+
export declare function checkRunnerEnv(options: RunnerEnvCheckOptions): Promise<CheckRow[]>;
|
|
47
|
+
/** The check's lines: one per row (its state, its name, why), then the outcome. */
|
|
48
|
+
export declare function checkLines(rows: readonly CheckRow[]): {
|
|
49
|
+
lines: string[];
|
|
50
|
+
ok: boolean;
|
|
51
|
+
};
|