@parcha/agentrun-serve 0.1.0-beta.42 → 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 +126 -0
- package/README.md +221 -31
- 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/decisions.js +0 -4
- 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-sources.js +25 -5
- 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/audit.d.ts +123 -0
- package/dist/learn/audit.js +159 -0
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.d.ts +50 -74
- package/dist/learn/compile.js +90 -124
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/folder.d.ts +9 -0
- package/dist/learn/folder.js +13 -2
- package/dist/learn/promote.d.ts +92 -200
- package/dist/learn/promote.js +65 -187
- package/dist/learn/replay-calls.d.ts +5 -0
- package/dist/learn/replay-calls.js +12 -1
- package/dist/learn/secrets.d.ts +8 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +19 -5
- package/dist/learn/workflow-nodes.d.ts +23 -3
- package/dist/learn/workflow-nodes.js +30 -12
- package/dist/learned-nodes.d.ts +9 -34
- package/dist/learned-nodes.js +11 -23
- package/dist/learned-workflow.d.ts +6 -8
- package/dist/learned-workflow.js +18 -57
- package/dist/learning-batch.d.ts +13 -5
- package/dist/learning-batch.js +34 -8
- package/dist/learning-cost.d.ts +111 -4
- package/dist/learning-cost.js +120 -3
- 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 +18 -1
- package/dist/learning-setting.d.ts +16 -1
- package/dist/learning-setting.js +34 -2
- 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 +203 -87
- 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-launch.d.ts +6 -3
- package/dist/run-launch.js +2 -0
- 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 +10 -0
- package/dist/runner/adapter-loop.js +26 -4
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +83 -25
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +68 -0
- package/dist/runner/audit.js +349 -0
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +6 -3
- 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 +44 -15
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +8 -7
- package/dist/runner/harness-loops.js +31 -23
- package/dist/runner/journal-kinds.d.ts +5 -7
- package/dist/runner/journal-kinds.js +0 -7
- package/dist/runner/learning-dispatch.d.ts +0 -16
- package/dist/runner/learning-dispatch.js +4 -47
- package/dist/runner/learning-end.d.ts +55 -13
- package/dist/runner/learning-end.js +128 -44
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +1 -4
- package/dist/runner/learning-loop.d.ts +2 -38
- package/dist/runner/learning-loop.js +8 -116
- 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 +25 -8
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +55 -54
- package/dist/runner/promotion.js +232 -585
- package/dist/runner/reflect-hook.d.ts +14 -0
- package/dist/runner/reflect-hook.js +28 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-first.d.ts +6 -5
- package/dist/runner/workflow-first.js +17 -12
- 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 +516 -134
- 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 +119 -16
- package/dist/store/store.d.ts +41 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +57 -7
- package/dist/store-reads/learning.js +194 -28
- package/dist/store-reads/loop.d.ts +4 -39
- package/dist/store-reads/loop.js +10 -79
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -1
- 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/dist/workspace/run-tools.d.ts +1 -1
- package/dist/workspace/run-tools.js +14 -3
- package/package.json +10 -9
- package/dist/console/assets/index-C3gNPz58.css +0 -1
- package/dist/console/assets/index-DYJ_wj27.js +0 -711
- package/dist/learn/general.d.ts +0 -69
- package/dist/learn/general.js +0 -75
- package/dist/learn/refit.d.ts +0 -48
- package/dist/learn/refit.js +0 -264
- package/dist/runner/step-guard.d.ts +0 -62
- package/dist/runner/step-guard.js +0 -93
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/decisions.js
CHANGED
|
@@ -152,10 +152,6 @@ export function providersNamed(nodes) {
|
|
|
152
152
|
}
|
|
153
153
|
if (node.verify)
|
|
154
154
|
ids.add(DEFAULT_DECISION_PROVIDER);
|
|
155
|
-
// A step guard that reads Jev (runner/step-guard.ts) asks Jev, whatever provider its node names.
|
|
156
|
-
const signal = node.guard?.signal;
|
|
157
|
-
if (signal === "jev" || signal === "both")
|
|
158
|
-
ids.add("jev");
|
|
159
155
|
}
|
|
160
156
|
return [...ids];
|
|
161
157
|
}
|
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-sources.js
CHANGED
|
@@ -166,7 +166,7 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
166
166
|
activeMs: 0,
|
|
167
167
|
copies: 0,
|
|
168
168
|
};
|
|
169
|
-
|
|
169
|
+
let turns = [];
|
|
170
170
|
let first;
|
|
171
171
|
let last;
|
|
172
172
|
const names = new Map();
|
|
@@ -175,14 +175,17 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
175
175
|
const current = { keyed: new Map(), seen: seen ?? new Set(), copied: new Set() };
|
|
176
176
|
const codex = { events: false, held: [], records: false, responses: new Set(), items: new Map(), results: new Map() };
|
|
177
177
|
const titles = { summaries: [], uuids: new Set() };
|
|
178
|
-
const
|
|
178
|
+
const rememberUser = (turn) => {
|
|
179
179
|
if (turn.role === "user") {
|
|
180
180
|
session.users += 1;
|
|
181
181
|
session.firstPrompt ??= turn.text;
|
|
182
182
|
session.titleText ??= personsWords(turn.text);
|
|
183
183
|
}
|
|
184
|
+
};
|
|
185
|
+
const add = (turn) => {
|
|
186
|
+
rememberUser(turn);
|
|
184
187
|
if (keep)
|
|
185
|
-
turns.
|
|
188
|
+
turns.push(turn);
|
|
186
189
|
};
|
|
187
190
|
const record = source === "claude-code" ? claudeRecord : source === "codex" ? codexRecord : piRecord;
|
|
188
191
|
const lines = createInterface({
|
|
@@ -216,8 +219,25 @@ export async function readSession(file, source, { turns: keep = true, seen } = {
|
|
|
216
219
|
}
|
|
217
220
|
// Older Codex writes each of the person's turns twice, as a user_message event and as a user message; current Codex
|
|
218
221
|
// writes the user message alone. One source per file, so no turn counts twice.
|
|
219
|
-
if (!codex.events)
|
|
220
|
-
|
|
222
|
+
if (!codex.events && codex.held.length) {
|
|
223
|
+
// Held indexes refer to the non-user turns as read. Merge both ordered lists once: inserting each user into
|
|
224
|
+
// the middle of the transcript shifts its remaining turns again and again on a long current-Codex session.
|
|
225
|
+
const ordered = [];
|
|
226
|
+
let next = 0;
|
|
227
|
+
for (const { index, turn } of codex.held) {
|
|
228
|
+
rememberUser(turn);
|
|
229
|
+
if (keep) {
|
|
230
|
+
while (next < index)
|
|
231
|
+
ordered.push(turns[next++]);
|
|
232
|
+
ordered.push(turn);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (keep) {
|
|
236
|
+
while (next < turns.length)
|
|
237
|
+
ordered.push(turns[next++]);
|
|
238
|
+
turns = ordered;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
221
241
|
if (!session.id)
|
|
222
242
|
session.id = source === "pi" ? basename(file, ".jsonl").split("_").pop() : basename(file, ".jsonl");
|
|
223
243
|
const sourceTitle = titles.custom ?? titles.ai ?? titles.summaries.findLast(({ leaf }) => leaf === undefined || titles.uuids.has(leaf))?.title;
|
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[];
|