@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.44
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 +105 -0
- package/README.md +213 -24
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.js +1 -1
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +8 -4
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +17 -1
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +28 -9
- package/dist/learning-cost.d.ts +100 -0
- package/dist/learning-cost.js +116 -1
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +17 -0
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +115 -39
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +6 -0
- package/dist/runner/adapter-loop.js +9 -2
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +70 -23
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +4 -0
- package/dist/runner/audit.js +15 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +5 -2
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +32 -13
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +7 -3
- package/dist/runner/harness-loops.js +30 -8
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learning-end.d.ts +3 -0
- package/dist/runner/learning-end.js +4 -0
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +24 -7
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +5 -0
- package/dist/runner/promotion.js +46 -7
- package/dist/runner/reflect-hook.d.ts +4 -0
- package/dist/runner/reflect-hook.js +22 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +457 -120
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +118 -16
- package/dist/store/store.d.ts +38 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +41 -2
- package/dist/store-reads/learning.js +158 -5
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -11
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/package.json +10 -9
- package/dist/console/assets/index-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.js +0 -711
package/dist/console/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>AgentRun</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-nB9kTfIN.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BUktRvS-.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/errors.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export declare const ERROR_STATUS: {
|
|
|
54
54
|
readonly external_body_conflict: 409;
|
|
55
55
|
readonly learned_not_active: 409;
|
|
56
56
|
readonly replay_conflict: 409;
|
|
57
|
+
readonly model_key_required: 422;
|
|
57
58
|
};
|
|
58
59
|
export type ErrorCode = keyof typeof ERROR_STATUS;
|
|
59
60
|
/** A field that is missing or wrong. `example`: a value the field accepts, read from the request body's schema (explain.ts). */
|
package/dist/errors.js
CHANGED
|
@@ -75,6 +75,9 @@ export const ERROR_STATUS = {
|
|
|
75
75
|
// A replay its owner asked of a learned workflow's revision that cannot start now (runner/promotion.ts askReplay): one
|
|
76
76
|
// replays already, another revision of it replays, it is promoted, or no graded input fits it.
|
|
77
77
|
replay_conflict: 409,
|
|
78
|
+
// A run start, or a message that would start a turn, with no model_key where the server holds no key for the run's
|
|
79
|
+
// model (run-model-key.ts): nothing to spend, so refused before any model call.
|
|
80
|
+
model_key_required: 422,
|
|
78
81
|
};
|
|
79
82
|
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed"]);
|
|
80
83
|
export class ApiError extends Error {
|
package/dist/harness-table.d.ts
CHANGED
|
@@ -4,8 +4,13 @@ import type { AdapterNeeds } from "./adapters.js";
|
|
|
4
4
|
import { type HarnessInstallEntry, type HarnessPins } from "./harness-install.js";
|
|
5
5
|
import { type ModelChoice } from "./provider.js";
|
|
6
6
|
import type { SkillCheck } from "./skills.js";
|
|
7
|
+
import type { RunnerHarness } from "./runner/adapters/index.js";
|
|
7
8
|
/** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
|
|
8
9
|
export declare const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
10
|
+
/** The harness modules the owner names (the server's `harnessModules`), as a JSON array of absolute paths: each adds
|
|
11
|
+
* harnesses of its own to the table, under a test runner or not, and never replaces a built-in one. The server sets it
|
|
12
|
+
* from its options alone (model.ts withoutFaux drops an operator's). */
|
|
13
|
+
export declare const HARNESS_MODULES_ENV = "AGENTRUN_HARNESS_MODULES";
|
|
9
14
|
/** Why a harness cannot run here, in words a person can act on, and the model keys any one of which would let it
|
|
10
15
|
* (HarnessUnavailable's `keys`). */
|
|
11
16
|
export type Refusal = {
|
|
@@ -18,8 +23,27 @@ export type SessionRoute = {
|
|
|
18
23
|
api: AdapterFacts["wire"];
|
|
19
24
|
options: Pick<ModelProxyOptions, "policy" | "model" | "origin" | "credential" | "price">;
|
|
20
25
|
};
|
|
26
|
+
/** What a harness promises, as capabilities show it (each a person can rely on, measured, never named): how a run resumes
|
|
27
|
+
* after a crash (`exact`: its state mirrored into the journal; `load`: the agent's own session load; `restart`: the turn
|
|
28
|
+
* restarts with a recovery note), what holds its tool calls (`every_call`: each blocks until journaled; `permission`: the
|
|
29
|
+
* agent's permission requests; `config`: its built-ins are off by its config, our tools gated), and who pays for its
|
|
30
|
+
* model (`proxy`: through the session's proxy, on this server's cap; `plan`: the vendor bills the person's own plan). */
|
|
31
|
+
export type HarnessPromises = {
|
|
32
|
+
readonly resume: "exact" | "load" | "restart";
|
|
33
|
+
readonly tool_gate: "every_call" | "permission" | "config";
|
|
34
|
+
readonly billing: "proxy" | "plan";
|
|
35
|
+
};
|
|
36
|
+
/** The native harnesses' promises: pi and the three CLI adapters. */
|
|
37
|
+
export declare const NATIVE_PROMISES: HarnessPromises;
|
|
21
38
|
export interface HarnessEntry {
|
|
22
39
|
readonly id: string;
|
|
40
|
+
/** Its name in a sentence ("Pi", "Claude"): an adapter's facts' label. */
|
|
41
|
+
readonly label: string;
|
|
42
|
+
/** What it promises (HarnessPromises). Absent: a native harness's (NATIVE_PROMISES). */
|
|
43
|
+
readonly promises?: HarnessPromises;
|
|
44
|
+
/** The runner's harness for it (runner/adapters/index.ts RunnerHarness): absent on a built-in, whose runner is the
|
|
45
|
+
* runner's own (RUNNER_HARNESSES); a harness module's entry brings its own. */
|
|
46
|
+
readonly runner?: RunnerHarness;
|
|
23
47
|
/** Whether it takes a message mid-turn; else a message waits for the turn's end. */
|
|
24
48
|
readonly steer: boolean;
|
|
25
49
|
/** What one of its runs reserves in memory while its process lives, in MiB (host.ts). */
|
|
@@ -58,13 +82,37 @@ export interface HarnessEntry {
|
|
|
58
82
|
export type HarnessTableModule = {
|
|
59
83
|
entries(builtins: Readonly<Record<string, HarnessEntry>>): Record<string, Partial<HarnessEntry>>;
|
|
60
84
|
};
|
|
61
|
-
/** The table `env` runs on: the built-in entries,
|
|
62
|
-
*
|
|
63
|
-
*
|
|
85
|
+
/** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
|
|
86
|
+
* server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
|
|
87
|
+
* harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
|
|
88
|
+
* whole entries of new ids: one whose id is not one the API carries (HARNESS_ID_PATTERN), naming a name serve's own runs
|
|
89
|
+
* carry or every object has (RESERVED_HARNESS_IDS: a learning run's `learning` would reach the learning loop, and
|
|
90
|
+
* `constructor` would read Object's own member where serve looks a harness up in a plain object), naming a built-in harness, an
|
|
91
|
+
* id another module adds, or an entry missing a member is refused by name, so no module changes what a built-in harness
|
|
92
|
+
* is (grep pins claude-agent). Loaded once per setting. */
|
|
64
93
|
export declare function harnessTable(env: NodeJS.ProcessEnv): Readonly<Record<string, HarnessEntry>>;
|
|
94
|
+
/** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
|
|
95
|
+
export declare const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
|
|
96
|
+
/** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
|
|
97
|
+
* when neither names one. */
|
|
98
|
+
export declare const harnessModulesOf: (given: readonly string[] | undefined, env: NodeJS.ProcessEnv) => string[];
|
|
99
|
+
/** Each harness module `names` names, as the absolute path HARNESS_MODULES_ENV carries: a path as it resolves; a package
|
|
100
|
+
* from `<data>/harnesses` (where its owner installs it: npm install --prefix <data>/harnesses <package>), else from
|
|
101
|
+
* where the server runs. One that resolves nowhere refuses the start, naming the command that installs it. */
|
|
102
|
+
export declare function harnessModulePaths(names: readonly string[], data: string): string[];
|
|
103
|
+
/** HARNESS_MODULES_ENV for the harness modules `names` names: none for none. */
|
|
104
|
+
export declare const harnessModulesEnv: (names: readonly string[], data: string) => NodeJS.ProcessEnv;
|
|
105
|
+
/** The ids of the harnesses `env`'s table has, in its order: the built-in ones (pi first), then those its modules add. */
|
|
106
|
+
export declare const harnessIds: (env: NodeJS.ProcessEnv) => readonly string[];
|
|
65
107
|
/** The built-in entry of harness `id` (none: the default, pi), for what a test's entry never changes: its memory (host.ts),
|
|
66
108
|
* which a stand-in reserves as the harness it stands in for does, so tests admit as a real server does. */
|
|
67
109
|
export declare const builtinHarness: (id: string | undefined) => HarnessEntry | undefined;
|
|
110
|
+
/** The owner's table on `env`: the built-in entries and those its harness modules add (HARNESS_MODULES_ENV), never a test
|
|
111
|
+
* table's. What a run weighs and whether one fits (host.ts, runner/memory-claim.ts) read it, so a test's stand-in admits
|
|
112
|
+
* as the built-in harness it stands in for, and a module's harness as its entry declares. */
|
|
113
|
+
export declare const ownerTable: (env: NodeJS.ProcessEnv) => Readonly<Record<string, HarnessEntry>>;
|
|
114
|
+
/** The entry of harness `id` (none: the default, pi) on the owner's table (ownerTable); undefined for one it has not. */
|
|
115
|
+
export declare const ownerHarness: (env: NodeJS.ProcessEnv, id: string | undefined) => HarnessEntry | undefined;
|
|
68
116
|
/** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
|
|
69
117
|
export declare const harnessOf: (env: NodeJS.ProcessEnv, id: string | undefined) => HarnessEntry | undefined;
|
|
70
118
|
/** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
|
package/dist/harness-table.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
// these by id: what a test stands in for is an entry, never a branch here or anywhere else. The server sets the variable
|
|
9
9
|
// from its options alone (model.ts withoutFaux), so an operator's environment never loads a module.
|
|
10
10
|
import { createRequire } from "node:module";
|
|
11
|
-
import { resolve } from "node:path";
|
|
11
|
+
import { join, resolve } from "node:path";
|
|
12
12
|
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
13
13
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
14
14
|
import { facts as openCodeFacts } from "./harness-opencode/facts.js";
|
|
15
|
-
import { DEFAULT_HARNESS, PLAN_HARNESSES } from "./harness.js";
|
|
15
|
+
import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
16
16
|
import { HARNESS_INSTALLS } from "./harness-install.js";
|
|
17
17
|
import { chooseModel } from "./model.js";
|
|
18
18
|
import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
|
|
@@ -20,6 +20,12 @@ import { WIRES } from "./wires.js";
|
|
|
20
20
|
import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
|
|
21
21
|
/** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
|
|
22
22
|
export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
23
|
+
/** The harness modules the owner names (the server's `harnessModules`), as a JSON array of absolute paths: each adds
|
|
24
|
+
* harnesses of its own to the table, under a test runner or not, and never replaces a built-in one. The server sets it
|
|
25
|
+
* from its options alone (model.ts withoutFaux drops an operator's). */
|
|
26
|
+
export const HARNESS_MODULES_ENV = "AGENTRUN_HARNESS_MODULES";
|
|
27
|
+
/** The native harnesses' promises: pi and the three CLI adapters. */
|
|
28
|
+
export const NATIVE_PROMISES = Object.freeze({ resume: "exact", tool_gate: "every_call", billing: "proxy" });
|
|
23
29
|
// The memory one run of each harness reserves while its process lives, in MiB (each entry's runMib, an adapter's from its
|
|
24
30
|
// facts): what admission counts (host.ts).
|
|
25
31
|
// Measured 2026-11-03 on 529c3882e with the pinned binaries' sha256 checked a chunk at a time, not read whole: a
|
|
@@ -41,6 +47,7 @@ export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
|
41
47
|
/** pi: the run's own process, on its own models. */
|
|
42
48
|
const PI = Object.freeze({
|
|
43
49
|
id: DEFAULT_HARNESS,
|
|
50
|
+
label: "Pi",
|
|
44
51
|
steer: true,
|
|
45
52
|
runMib: 128,
|
|
46
53
|
oneAlwaysFits: true,
|
|
@@ -60,6 +67,7 @@ function adapterEntry(facts, make, extra = {}) {
|
|
|
60
67
|
const onPlan = PLAN_HARNESSES.includes(id);
|
|
61
68
|
const entry = {
|
|
62
69
|
id,
|
|
70
|
+
label: facts.label,
|
|
63
71
|
steer: facts.steer,
|
|
64
72
|
runMib: facts.runMib,
|
|
65
73
|
oneAlwaysFits: false,
|
|
@@ -122,27 +130,107 @@ const BUILTIN = Object.freeze({
|
|
|
122
130
|
});
|
|
123
131
|
const loaded = new Map();
|
|
124
132
|
const requireHere = createRequire(import.meta.url);
|
|
125
|
-
/** The
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
/** The members a harness module's new entry gives: what the table's readers ask of every entry. */
|
|
134
|
+
const WHOLE = Object.freeze(["label", "steer", "runMib", "oneAlwaysFits", "runs", "onWire", "model", "priceModel", "refusal", "runner"]);
|
|
135
|
+
/** The entries module `path` gives (HarnessTableModule), `named` saying which setting named it. */
|
|
136
|
+
function entriesOf(path, named) {
|
|
137
|
+
const module = requireHere(resolve(path));
|
|
138
|
+
if (typeof module.entries !== "function")
|
|
139
|
+
throw new Error(`${named} names ${path}, which exports no entries(builtins)`);
|
|
140
|
+
return module.entries(BUILTIN);
|
|
141
|
+
}
|
|
142
|
+
/** The harness modules `env` names (HARNESS_MODULES_ENV): none when it names none. */
|
|
143
|
+
function modulesOf(env) {
|
|
144
|
+
const given = env[HARNESS_MODULES_ENV];
|
|
145
|
+
if (!given)
|
|
146
|
+
return [];
|
|
147
|
+
const paths = JSON.parse(given);
|
|
148
|
+
if (!Array.isArray(paths) || !paths.every((path) => typeof path === "string"))
|
|
149
|
+
throw new Error(`${HARNESS_MODULES_ENV} is a JSON array of module paths`);
|
|
150
|
+
return paths;
|
|
151
|
+
}
|
|
152
|
+
const harnessId = new RegExp(HARNESS_ID_PATTERN);
|
|
153
|
+
/** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
|
|
154
|
+
* server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
|
|
155
|
+
* harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
|
|
156
|
+
* whole entries of new ids: one whose id is not one the API carries (HARNESS_ID_PATTERN), naming a name serve's own runs
|
|
157
|
+
* carry or every object has (RESERVED_HARNESS_IDS: a learning run's `learning` would reach the learning loop, and
|
|
158
|
+
* `constructor` would read Object's own member where serve looks a harness up in a plain object), naming a built-in harness, an
|
|
159
|
+
* id another module adds, or an entry missing a member is refused by name, so no module changes what a built-in harness
|
|
160
|
+
* is (grep pins claude-agent). Loaded once per setting. */
|
|
128
161
|
export function harnessTable(env) {
|
|
129
162
|
const path = env.NODE_TEST_CONTEXT ? env[HARNESS_TABLE_ENV] : undefined;
|
|
130
|
-
|
|
163
|
+
const modules = modulesOf(env);
|
|
164
|
+
if (!path && !modules.length)
|
|
131
165
|
return BUILTIN;
|
|
132
|
-
|
|
166
|
+
const key = JSON.stringify([path ?? null, modules]);
|
|
167
|
+
let table = loaded.get(key);
|
|
133
168
|
if (!table) {
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
169
|
+
const built = { ...BUILTIN };
|
|
170
|
+
if (path)
|
|
171
|
+
for (const [id, entry] of Object.entries(entriesOf(path, HARNESS_TABLE_ENV)))
|
|
172
|
+
built[id] = Object.freeze({ ...BUILTIN[id], ...entry, id });
|
|
173
|
+
for (const module of modules) {
|
|
174
|
+
for (const [id, entry] of Object.entries(entriesOf(module, HARNESS_MODULES_ENV))) {
|
|
175
|
+
if (!harnessId.test(id))
|
|
176
|
+
throw new Error(`harness module ${module} names ${id}, which is not a harness id: an id matches ${HARNESS_ID_PATTERN}`);
|
|
177
|
+
if (RESERVED_HARNESS_IDS.includes(id))
|
|
178
|
+
throw new Error(`harness module ${module} names ${id}, a name serve's own runs carry or every object already has: a module's harness takes none of ${RESERVED_HARNESS_IDS.join(", ")}`);
|
|
179
|
+
if (Object.hasOwn(BUILTIN, id))
|
|
180
|
+
throw new Error(`harness module ${module} names ${id}, a built-in harness: a module adds a harness and never replaces one`);
|
|
181
|
+
if (Object.hasOwn(built, id))
|
|
182
|
+
throw new Error(`harness module ${module} names ${id}, which another module already adds`);
|
|
183
|
+
const missing = WHOLE.filter((member) => entry[member] === undefined);
|
|
184
|
+
if (missing.length)
|
|
185
|
+
throw new Error(`harness module ${module}: its entry ${id} lacks ${missing.join(", ")}`);
|
|
186
|
+
built[id] = Object.freeze({ ...entry, id });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
table = Object.freeze(built);
|
|
190
|
+
loaded.set(key, table);
|
|
140
191
|
}
|
|
141
192
|
return table;
|
|
142
193
|
}
|
|
194
|
+
/** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
|
|
195
|
+
export const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
|
|
196
|
+
/** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
|
|
197
|
+
* when neither names one. */
|
|
198
|
+
export const harnessModulesOf = (given, env) => given?.length ? [...given] : (env[HARNESS_MODULES_SETTING] ?? "").split(",").map((name) => name.trim()).filter(Boolean);
|
|
199
|
+
/** Each harness module `names` names, as the absolute path HARNESS_MODULES_ENV carries: a path as it resolves; a package
|
|
200
|
+
* from `<data>/harnesses` (where its owner installs it: npm install --prefix <data>/harnesses <package>), else from
|
|
201
|
+
* where the server runs. One that resolves nowhere refuses the start, naming the command that installs it. */
|
|
202
|
+
export function harnessModulePaths(names, data) {
|
|
203
|
+
return names.map((name) => {
|
|
204
|
+
if (name.startsWith("/") || name.startsWith("."))
|
|
205
|
+
return resolve(name);
|
|
206
|
+
for (const from of [join(resolve(data), "harnesses", "package.json"), join(process.cwd(), "package.json")]) {
|
|
207
|
+
try {
|
|
208
|
+
return createRequire(from).resolve(name);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
// Not there: the next place.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
throw new Error(`harness module ${name} is not installed: npm install --prefix ${join(resolve(data), "harnesses")} ${name}`);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/** HARNESS_MODULES_ENV for the harness modules `names` names: none for none. */
|
|
218
|
+
export const harnessModulesEnv = (names, data) => (names.length ? { [HARNESS_MODULES_ENV]: JSON.stringify(harnessModulePaths(names, data)) } : {});
|
|
219
|
+
/** The ids of the harnesses `env`'s table has, in its order: the built-in ones (pi first), then those its modules add. */
|
|
220
|
+
export const harnessIds = (env) => Object.keys(harnessTable(env));
|
|
143
221
|
/** The built-in entry of harness `id` (none: the default, pi), for what a test's entry never changes: its memory (host.ts),
|
|
144
222
|
* which a stand-in reserves as the harness it stands in for does, so tests admit as a real server does. */
|
|
145
223
|
export const builtinHarness = (id) => BUILTIN[id ?? DEFAULT_HARNESS];
|
|
224
|
+
/** The owner's table on `env`: the built-in entries and those its harness modules add (HARNESS_MODULES_ENV), never a test
|
|
225
|
+
* table's. What a run weighs and whether one fits (host.ts, runner/memory-claim.ts) read it, so a test's stand-in admits
|
|
226
|
+
* as the built-in harness it stands in for, and a module's harness as its entry declares. */
|
|
227
|
+
export const ownerTable = (env) => harnessTable(env[HARNESS_MODULES_ENV] ? { [HARNESS_MODULES_ENV]: env[HARNESS_MODULES_ENV] } : {});
|
|
228
|
+
/** The entry of harness `id` (none: the default, pi) on the owner's table (ownerTable); undefined for one it has not. */
|
|
229
|
+
export const ownerHarness = (env, id) => {
|
|
230
|
+
const table = ownerTable(env);
|
|
231
|
+
const key = id ?? DEFAULT_HARNESS;
|
|
232
|
+
return Object.hasOwn(table, key) ? table[key] : undefined;
|
|
233
|
+
};
|
|
146
234
|
/** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
|
|
147
235
|
export const harnessOf = (env, id) => harnessTable(env)[id ?? DEFAULT_HARNESS];
|
|
148
236
|
/** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
|
package/dist/harness.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
import type { HarnessPromises } from "./harness-table.js";
|
|
2
|
+
/** The built-in harnesses' ids, in the table's order (harness-table.ts BUILTIN; harness-one-table.test.mjs holds them
|
|
3
|
+
* equal): the ids a definition may name on any server, and the type of a built-in one. What a server runs is its table's
|
|
4
|
+
* (harnessIds), which an owner's harness module may add to. */
|
|
1
5
|
export declare const HARNESSES: readonly ["pi", "claude-agent", "codex", "opencode"];
|
|
2
6
|
export type HarnessId = (typeof HARNESSES)[number];
|
|
3
7
|
export declare const DEFAULT_HARNESS: HarnessId;
|
|
8
|
+
/** What a harness id is, as the API says it (openapi.ts): a harness module's id that is not one refuses the start. */
|
|
9
|
+
export declare const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
10
|
+
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
11
|
+
* `learning`, a learning run's launch harness, which the runner's loop choice keys on (harness-loops.ts,
|
|
12
|
+
* learning-factory.ts LEARNING_HARNESS) and the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
13
|
+
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
14
|
+
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
15
|
+
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
16
|
+
export declare const RESERVED_HARNESS_IDS: readonly string[];
|
|
4
17
|
/** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
|
|
5
18
|
* API as the plan takes them. The others need a model key. */
|
|
6
19
|
export declare const PLAN_HARNESSES: readonly string[];
|
|
@@ -13,8 +26,12 @@ export declare const PLAN_HARNESSES: readonly string[];
|
|
|
13
26
|
* server's own: capabilities never serve it. */
|
|
14
27
|
/** `installs`: `on_first_use` on claude-agent or codex while its CLI is not installed in this server's data: its first run
|
|
15
28
|
* (or the first agent made on it) installs it (harness-install.ts). */
|
|
29
|
+
/** `id`: one of the table's (harness-table.ts harnessIds): a built-in one (HARNESSES) or one an owner's harness module adds.
|
|
30
|
+
* `label`: its name in a sentence. `promises`: what it promises (HarnessPromises), as capabilities show it. */
|
|
16
31
|
export type HarnessOffer = {
|
|
17
|
-
id:
|
|
32
|
+
id: string;
|
|
33
|
+
label: string;
|
|
34
|
+
promises: HarnessPromises;
|
|
18
35
|
available: boolean;
|
|
19
36
|
steer: boolean;
|
|
20
37
|
reason?: string;
|
package/dist/harness.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// capabilities, and a revision naming one it does not run saves with a warning and is refused at run time.
|
|
1
|
+
/** The built-in harnesses' ids, in the table's order (harness-table.ts BUILTIN; harness-one-table.test.mjs holds them
|
|
2
|
+
* equal): the ids a definition may name on any server, and the type of a built-in one. What a server runs is its table's
|
|
3
|
+
* (harnessIds), which an owner's harness module may add to. */
|
|
5
4
|
export const HARNESSES = ["pi", "claude-agent", "codex", "opencode"];
|
|
6
5
|
export const DEFAULT_HARNESS = "pi";
|
|
6
|
+
/** What a harness id is, as the API says it (openapi.ts): a harness module's id that is not one refuses the start. */
|
|
7
|
+
export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
8
|
+
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
9
|
+
* `learning`, a learning run's launch harness, which the runner's loop choice keys on (harness-loops.ts,
|
|
10
|
+
* learning-factory.ts LEARNING_HARNESS) and the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
11
|
+
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
12
|
+
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
13
|
+
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
14
|
+
export const RESERVED_HARNESS_IDS = Object.freeze([
|
|
15
|
+
"learning", "sdk", "workflow", "claude-agent-sdk", "codex-sdk",
|
|
16
|
+
...Object.getOwnPropertyNames(Object.prototype).filter((name) => new RegExp(HARNESS_ID_PATTERN).test(name)),
|
|
17
|
+
]);
|
|
7
18
|
/** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
|
|
8
19
|
* API as the plan takes them. The others need a model key. */
|
|
9
20
|
export const PLAN_HARNESSES = Object.freeze(["pi", "codex"]);
|
|
@@ -29,25 +40,26 @@ export function harnessOffers(env) {
|
|
|
29
40
|
const { hostMemory, neverFits } = await import("./host.js");
|
|
30
41
|
const memory = hostMemory();
|
|
31
42
|
const { harnessInstalled } = await import("./adapters.js");
|
|
32
|
-
const { harnessOf } = await import("./harness-table.js");
|
|
33
|
-
const probed = await Promise.all(
|
|
43
|
+
const { harnessIds, harnessOf, NATIVE_PROMISES } = await import("./harness-table.js");
|
|
44
|
+
const probed = await Promise.all(harnessIds(env).map(async (id) => {
|
|
34
45
|
const entry = harnessOf(env, id);
|
|
46
|
+
const named = { label: entry.label, promises: entry.promises ?? NATIVE_PROMISES };
|
|
35
47
|
// The start's probe: these offers hold until a restart (server.ts), so the reason says so where installing fixes it.
|
|
36
48
|
// Claude Code not installed yet says so (its install probes the offers again).
|
|
37
49
|
const firstUse = entry.installs && !(await harnessInstalled(entry, env)) ? { installs: "on_first_use" } : {};
|
|
38
50
|
const refused = await entry.refusal(env, undefined, { atStart: true });
|
|
39
51
|
if (refused !== undefined)
|
|
40
|
-
return { id, available: false, steer: entry.steer, ...refused, ...firstUse };
|
|
52
|
+
return { id, ...named, available: false, steer: entry.steer, ...refused, ...firstUse };
|
|
41
53
|
// Available: which model keys run it here is what it would ask for with none of them (a key's row names it only
|
|
42
54
|
// when that key is one), so a row reads the same before and after another provider's key is saved.
|
|
43
55
|
const keyless = await entry.refusal(await withoutModelKeys(env), undefined, { atStart: true });
|
|
44
|
-
return { id, available: true, steer: entry.steer, ...(keyless?.keys?.length ? { keys: keyless.keys } : {}), ...firstUse };
|
|
56
|
+
return { id, ...named, available: true, steer: entry.steer, ...(keyless?.keys?.length ? { keys: keyless.keys } : {}), ...firstUse };
|
|
45
57
|
}));
|
|
46
58
|
// A harness that runs here but whose one run is more than this host's memory for runs never starts: said here, so
|
|
47
59
|
// a save warns and a run is refused at once with why (runnable.ts), never a 429 to try again. One that lacks only a
|
|
48
60
|
// key keeps its reason, but no key would run it: it has no `keys`.
|
|
49
61
|
const base = probed.map((offer) => {
|
|
50
|
-
const tooBig = offer.available || offer.keys ? neverFits(offer.id, memory) : undefined;
|
|
62
|
+
const tooBig = offer.available || offer.keys ? neverFits(offer.id, memory, env) : undefined;
|
|
51
63
|
if (!tooBig)
|
|
52
64
|
return offer;
|
|
53
65
|
const { keys: _keys, ...rest } = offer;
|
package/dist/host.d.ts
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import { statfs } from "node:fs/promises";
|
|
2
2
|
import type { Store } from "./store/index.js";
|
|
3
3
|
/** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
|
|
4
|
-
* never go to (runner/main.ts runnerLoopback)
|
|
5
|
-
|
|
4
|
+
* never go to (runner/main.ts runnerLoopback); and the free disk under the data directory below which health fails,
|
|
5
|
+
* unless the server says otherwise. Both live in listen-first.ts, which the CLI loads before the rest of the server. */
|
|
6
|
+
export { DEFAULT_PORT, MIN_FREE_MIB } from "./listen-first.js";
|
|
6
7
|
/** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
|
|
7
8
|
* 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
|
|
8
9
|
* reserved for the high end, 81, plus 47 (+58%), since what it holds grows with the agents and runs it keeps. That is
|
|
9
10
|
* with the pinned binaries' sha256 checked a chunk at a time: a start that reads the codex binary (294 MB) and the
|
|
10
11
|
* claude-agent CLI (230 MB) whole sat at 341 to 348 MB on a host of 1 GB or less. */
|
|
11
12
|
export declare const SERVER_MIB = 128;
|
|
12
|
-
/** Free disk under the data directory below which health fails, unless the server says otherwise. */
|
|
13
|
-
export declare const MIN_FREE_MIB = 64;
|
|
14
13
|
/** The memory this server may use: its container's limit when it has one (cgroup), else the machine's. */
|
|
15
14
|
export declare function hostMemory(): number;
|
|
16
15
|
/** The memory runs may hold on a host of `memory` bytes, in MiB: all of it less the server's own. */
|
|
17
16
|
export declare const runsMemoryMib: (memory: number) => number;
|
|
18
|
-
/** What a run of `harness` reserves, in MiB
|
|
19
|
-
|
|
17
|
+
/** What a run of `harness` reserves, in MiB: its entry's on the owner's table of `env` (harness-table.ts ownerHarness: a
|
|
18
|
+
* built-in's, or what a harness module declares; a test's stand-in reserves as the built-in it stands in for). A harness
|
|
19
|
+
* outside that table (no saved revision names one) reserves the most a built-in one does. */
|
|
20
|
+
export declare const runMibOf: (harness: string | undefined, env?: NodeJS.ProcessEnv) => number;
|
|
20
21
|
/** How many runs of `harness` alone fit on a host of `memory` bytes. One whose entry says one always fits (pi, the
|
|
21
22
|
* default) always has one place, as before runs were admitted by memory: a server too small for even that still runs
|
|
22
|
-
* one at a time. */
|
|
23
|
-
export declare function runsThatFit(harness: string, memory: number): number;
|
|
23
|
+
* one at a time. `env`: whose owner's table says what a run weighs (runMibOf). */
|
|
24
|
+
export declare function runsThatFit(harness: string, memory: number, env?: NodeJS.ProcessEnv): number;
|
|
24
25
|
/** The default cap on how many runs at once: as many pi runs, the smallest, as fit. */
|
|
25
26
|
export declare const defaultMaxRuns: (memory: number) => number;
|
|
26
|
-
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits.
|
|
27
|
-
|
|
27
|
+
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits. `env`: whose
|
|
28
|
+
* owner's table says what each run weighs (runMibOf), and which harnesses the words list. */
|
|
29
|
+
export declare function neverFits(harness: string, memory: number, env?: NodeJS.ProcessEnv): string | undefined;
|
|
28
30
|
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. A runner
|
|
29
31
|
* holds at most this many; a run past it waits queued, never refused for a place. */
|
|
30
32
|
export declare function maxRunsOf(env: NodeJS.ProcessEnv, given?: number): number;
|
package/dist/host.js
CHANGED
|
@@ -6,10 +6,11 @@ import { statfs } from "node:fs/promises";
|
|
|
6
6
|
import { totalmem } from "node:os";
|
|
7
7
|
import { REQUEST_BUSY_MS, whenFree } from "./agents.js";
|
|
8
8
|
import { DEFAULT_HARNESS, HARNESSES } from "./harness.js";
|
|
9
|
-
import { builtinHarness } from "./harness-table.js";
|
|
9
|
+
import { builtinHarness, ownerHarness, ownerTable } from "./harness-table.js";
|
|
10
10
|
/** The port a server listens on unless --port says otherwise (cli.ts), and the one a standalone runner's loopback reads
|
|
11
|
-
* never go to (runner/main.ts runnerLoopback)
|
|
12
|
-
|
|
11
|
+
* never go to (runner/main.ts runnerLoopback); and the free disk under the data directory below which health fails,
|
|
12
|
+
* unless the server says otherwise. Both live in listen-first.ts, which the CLI loads before the rest of the server. */
|
|
13
|
+
export { DEFAULT_PORT, MIN_FREE_MIB } from "./listen-first.js";
|
|
13
14
|
const MiB = 2 ** 20;
|
|
14
15
|
/** Memory the server keeps for itself, before any run, in MiB. Measured with the runs' (harness-table.ts): the server's anon
|
|
15
16
|
* 3 s after its start, 32 starts at limits of 512M to 2048M, was 58 to 81 MB, with no peak at the start over that;
|
|
@@ -17,8 +18,6 @@ const MiB = 2 ** 20;
|
|
|
17
18
|
* with the pinned binaries' sha256 checked a chunk at a time: a start that reads the codex binary (294 MB) and the
|
|
18
19
|
* claude-agent CLI (230 MB) whole sat at 341 to 348 MB on a host of 1 GB or less. */
|
|
19
20
|
export const SERVER_MIB = 128;
|
|
20
|
-
/** Free disk under the data directory below which health fails, unless the server says otherwise. */
|
|
21
|
-
export const MIN_FREE_MIB = 64;
|
|
22
21
|
/** The memory this server may use: its container's limit when it has one (cgroup), else the machine's. */
|
|
23
22
|
export function hostMemory() {
|
|
24
23
|
const total = totalmem();
|
|
@@ -27,14 +26,16 @@ export function hostMemory() {
|
|
|
27
26
|
}
|
|
28
27
|
/** The memory runs may hold on a host of `memory` bytes, in MiB: all of it less the server's own. */
|
|
29
28
|
export const runsMemoryMib = (memory) => Math.floor(memory / MiB) - SERVER_MIB;
|
|
30
|
-
/** What a run of `harness` reserves, in MiB
|
|
31
|
-
|
|
29
|
+
/** What a run of `harness` reserves, in MiB: its entry's on the owner's table of `env` (harness-table.ts ownerHarness: a
|
|
30
|
+
* built-in's, or what a harness module declares; a test's stand-in reserves as the built-in it stands in for). A harness
|
|
31
|
+
* outside that table (no saved revision names one) reserves the most a built-in one does. */
|
|
32
|
+
export const runMibOf = (harness, env = {}) => ownerHarness(env, harness)?.runMib ?? Math.max(...HARNESSES.map((id) => builtinHarness(id).runMib));
|
|
32
33
|
/** How many runs of `harness` alone fit on a host of `memory` bytes. One whose entry says one always fits (pi, the
|
|
33
34
|
* default) always has one place, as before runs were admitted by memory: a server too small for even that still runs
|
|
34
|
-
* one at a time. */
|
|
35
|
-
export function runsThatFit(harness, memory) {
|
|
36
|
-
const fit = Math.max(0, Math.floor(runsMemoryMib(memory) / runMibOf(harness)));
|
|
37
|
-
return
|
|
35
|
+
* one at a time. `env`: whose owner's table says what a run weighs (runMibOf). */
|
|
36
|
+
export function runsThatFit(harness, memory, env = {}) {
|
|
37
|
+
const fit = Math.max(0, Math.floor(runsMemoryMib(memory) / runMibOf(harness, env)));
|
|
38
|
+
return ownerHarness(env, harness)?.oneAlwaysFits ? Math.max(1, fit) : fit;
|
|
38
39
|
}
|
|
39
40
|
/** The default cap on how many runs at once: as many pi runs, the smallest, as fit. */
|
|
40
41
|
export const defaultMaxRuns = (memory) => runsThatFit(DEFAULT_HARNESS, memory);
|
|
@@ -43,12 +44,13 @@ const sizeOf = (mib) => `${Math.round(mib)} MB`;
|
|
|
43
44
|
const aRun = (harness) => `${/^[aeiou]/i.test(harness) ? "an" : "a"} ${harness} run`;
|
|
44
45
|
/** "pi", "pi and codex", "pi, claude-agent and codex". */
|
|
45
46
|
const listed = (names) => (names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names.join(""));
|
|
46
|
-
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits.
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits. `env`: whose
|
|
48
|
+
* owner's table says what each run weighs (runMibOf), and which harnesses the words list. */
|
|
49
|
+
export function neverFits(harness, memory, env = {}) {
|
|
50
|
+
if (runsThatFit(harness, memory, env) > 0)
|
|
49
51
|
return undefined;
|
|
50
|
-
const fit =
|
|
51
|
-
return `This server has ${sizeOf(memory / MiB)} of memory and keeps ${sizeOf(SERVER_MIB)} for itself; ${aRun(harness)} needs about ${sizeOf(runMibOf(harness))} more, so it can't start here. ${listed(fit)} runs fit.`;
|
|
52
|
+
const fit = Object.keys(ownerTable(env)).filter((id) => runsThatFit(id, memory, env) > 0);
|
|
53
|
+
return `This server has ${sizeOf(memory / MiB)} of memory and keeps ${sizeOf(SERVER_MIB)} for itself; ${aRun(harness)} needs about ${sizeOf(runMibOf(harness, env))} more, so it can't start here. ${listed(fit)} runs fit.`;
|
|
52
54
|
}
|
|
53
55
|
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. A runner
|
|
54
56
|
* holds at most this many; a run past it waits queued, never refused for a place. */
|
package/dist/import-worker.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./quiet-sqlite-warning.js";
|
|
2
|
+
import { type ImportCandidate } from "./import.js";
|
|
2
3
|
/** `secrets`: the server's own, cut out of everything the import writes and never put in an environment; the seal key
|
|
3
4
|
* among them, so the worker opens the saved tool keys the import cuts too (read over the port from the server's store). */
|
|
4
5
|
export type ImportTask = {
|
|
@@ -7,12 +8,14 @@ export type ImportTask = {
|
|
|
7
8
|
home: string;
|
|
8
9
|
temp?: string;
|
|
9
10
|
secrets?: Record<string, string>;
|
|
11
|
+
projects?: readonly string[];
|
|
10
12
|
};
|
|
11
13
|
/** `took`: what this start's import took (stopped too: what it took before it stopped), its agents by id, so the server
|
|
12
14
|
* adds it to what earlier starts took. */
|
|
13
15
|
export type ImportAnswer = {
|
|
14
16
|
projects: number;
|
|
15
17
|
sessions: number;
|
|
18
|
+
candidates: ImportCandidate[];
|
|
16
19
|
} | {
|
|
17
20
|
took: {
|
|
18
21
|
agents: string[];
|
package/dist/import-worker.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// Setup's import of this machine's sessions, on a worker thread: node:sqlite's wait for a busy store and the parsing of
|
|
2
2
|
// every session line happen here, so neither holds up a request the server answers. `plan` counts what an import would
|
|
3
|
-
// take
|
|
3
|
+
// take, and names its projects for the owner to choose from; `import` takes it, only the projects chosen when some were
|
|
4
|
+
// (`projects`). The message "stop" ends either between two files or two sessions; what is written stays, and
|
|
4
5
|
// the next import goes on from there. Its one message back is its answer.
|
|
5
6
|
// Before anything loads node:sqlite, as in the server's own thread: its ExperimentalWarning is not the server's to print.
|
|
6
7
|
import "./quiet-sqlite-warning.js";
|
|
7
8
|
import { parentPort, workerData } from "node:worker_threads";
|
|
8
|
-
import { ownSecrets, planImport, runImport } from "./import.js";
|
|
9
|
+
import { candidatesOf, ownSecrets, planImport, runImport, sessionsOf } from "./import.js";
|
|
9
10
|
import { importStoreProxy } from "./import-proxy.js";
|
|
10
11
|
import { toolKeysOverStore } from "./tool-keys-store.js";
|
|
11
|
-
const { task, data, home, temp, secrets = {} } = workerData;
|
|
12
|
+
const { task, data, home, temp, secrets = {}, projects } = workerData;
|
|
12
13
|
const stop = new AbortController();
|
|
13
14
|
parentPort.on("message", (message) => void (message === "stop" && stop.abort()));
|
|
14
15
|
// The port does not keep the thread alive on its own: the task does (the proxy references it only while it waits for the
|
|
@@ -25,7 +26,7 @@ const answer = async () => {
|
|
|
25
26
|
// A count keeps no transcript: no key scan (a whole history read through secretlint at every start).
|
|
26
27
|
const plan = await planImport({ ...options, keys: false });
|
|
27
28
|
// Sessions as the import takes them: a session written in several files (a resumed thread) is one run.
|
|
28
|
-
return stop.signal.aborted ? { stopped: true } : { projects: plan.projects.length, sessions: plan.projects.reduce((n, p) => n +
|
|
29
|
+
return stop.signal.aborted ? { stopped: true } : { projects: plan.projects.length, sessions: plan.projects.reduce((n, p) => n + sessionsOf(p.sessions).length, 0), candidates: candidatesOf(plan, env) };
|
|
29
30
|
}
|
|
30
31
|
// No store of its own: the worker reaches the server's one open store over the port. The server holds the exclusive owner
|
|
31
32
|
// lock, so a second opener here would be refused; every read and write the import needs crosses the port instead.
|
|
@@ -35,7 +36,8 @@ const answer = async () => {
|
|
|
35
36
|
const keys = toolKeysOverStore(store, env, () => { });
|
|
36
37
|
await keys.load();
|
|
37
38
|
// The secrets this server made and keeps, read from the store as the import starts: cut by their values too.
|
|
38
|
-
|
|
39
|
+
// The owner's choice, when the setup named projects: nothing of another project is read for keys or written.
|
|
40
|
+
const taking = { ...options, stored: keys.values(), own: await ownSecrets(store, data, env), ...(projects ? { only: projects } : {}) };
|
|
39
41
|
const report = await runImport(store, await planImport(taking, store), taking);
|
|
40
42
|
const took = { agents: report.agents.filter((a) => a.runs > 0).map((a) => a.id), runs: report.agents.reduce((n, a) => n + a.runs, 0), skipped: report.skipped.length };
|
|
41
43
|
return stop.signal.aborted ? { took, stopped: true } : { took };
|
package/dist/import.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ export declare const IMPORT_ASKED = ".import-at-setup";
|
|
|
39
39
|
export declare const LIVE_MS: number;
|
|
40
40
|
/** The most of one session file read. */
|
|
41
41
|
export declare const MAX_SESSION_BYTES: number;
|
|
42
|
+
/** The most of one run read together: its session's files and its subagents'. A run is held in memory whole while its
|
|
43
|
+
* keys are found and it is written, so one over this is left out whole (never cut short), whatever the history's size. */
|
|
44
|
+
export declare const MAX_RUN_BYTES: number;
|
|
45
|
+
/** The most projects a count names for the owner to choose from: the latest active. */
|
|
46
|
+
export declare const MAX_CANDIDATES = 500;
|
|
42
47
|
/** The most of one instructions or skill file read, and of one agent's skill files together. */
|
|
43
48
|
export declare const MAX_FILE_BYTES: number;
|
|
44
49
|
export declare const MAX_SKILL_BYTES: number;
|
|
@@ -72,6 +77,19 @@ export type ImportOptions = {
|
|
|
72
77
|
keys?: boolean;
|
|
73
78
|
/** Read each session's turns while planning, and measure it (`Plan.found`): what a dry run's summary counts. */
|
|
74
79
|
measure?: boolean;
|
|
80
|
+
/** The owner's choice: only the projects of these agent ids (`agentIdOf`, as a count's candidates name them) are
|
|
81
|
+
* planned, so only they are read for keys and written. Absent: every project. */
|
|
82
|
+
only?: readonly string[];
|
|
83
|
+
};
|
|
84
|
+
/** A project a count found, for the owner to choose: the agent it would become (`id`), its folder, how many sessions
|
|
85
|
+
* an import would take from it, by which tools, and when the latest of them ended. */
|
|
86
|
+
export type ImportCandidate = {
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
path: string;
|
|
90
|
+
sessions: number;
|
|
91
|
+
sources: Source[];
|
|
92
|
+
last_active: string | null;
|
|
75
93
|
};
|
|
76
94
|
/** Why a session file or a project's file is left out, by kind, as the left-out counts group them (leftOutLines). */
|
|
77
95
|
export type LeftOut = "gone" | "temp" | "live" | "large" | "unread" | "no-project" | "no-words" | "copies" | "vanished" | "file";
|
|
@@ -122,11 +140,14 @@ export type ImportReport = {
|
|
|
122
140
|
* known format secretlint found. */
|
|
123
141
|
secretsRemoved?: number;
|
|
124
142
|
};
|
|
143
|
+
/** The projects of `plan` for the owner to choose from, the latest active first (then by folder), at most MAX_CANDIDATES.
|
|
144
|
+
* With `env`, the values of its keys are cut from a name and a folder as the import cuts them. */
|
|
145
|
+
export declare function candidatesOf(plan: Pick<Plan, "projects">, env?: NodeJS.ProcessEnv): ImportCandidate[];
|
|
125
146
|
export declare const agentIdOf: (cwd: string) => string;
|
|
126
147
|
/** What an import would take: the sessions under `home`, by project, with what it leaves out and why. Keeps no turns
|
|
127
148
|
* (with `measure`, only until each session is measured), and reads no file `store`'s imports already read whole and
|
|
128
149
|
* that has not changed since. */
|
|
129
|
-
export declare function planImport({ home, sources, all, deleted, now, temp: tempDir, measure, env, stored, own, signal, keys: scan, onKeys }: ImportOptions, store?: ImportStore): Promise<Plan>;
|
|
150
|
+
export declare function planImport({ home, sources, all, deleted, now, temp: tempDir, measure, env, stored, own, signal, keys: scan, onKeys, only }: ImportOptions, store?: ImportStore): Promise<Plan>;
|
|
130
151
|
/** The subagents tied to no session: each one's tokens and tool calls, for a summary's totals, each response once. */
|
|
131
152
|
export declare function untiedFound(plan: Plan): Promise<Found[]>;
|
|
132
153
|
/** The sessions `files` write, as the import takes them: one per source and session id, however many files write it
|