@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31
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 +238 -0
- package/README.md +739 -116
- package/dist/adapters.d.ts +35 -6
- package/dist/adapters.js +152 -26
- package/dist/agents.d.ts +18 -7
- package/dist/agents.js +19 -10
- package/dist/app.js +101 -26
- package/dist/background.d.ts +29 -0
- package/dist/background.js +397 -0
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +99 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +9 -7
- package/dist/box-relay-vm.d.ts +84 -0
- package/dist/box-relay-vm.js +410 -0
- package/dist/box-relay.d.ts +8 -5
- package/dist/box-relay.js +14 -9
- package/dist/boxes.d.ts +28 -5
- package/dist/boxes.js +44 -18
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +130 -21
- package/dist/cap.js +339 -67
- package/dist/cli.js +30 -4
- package/dist/coding-tools.d.ts +7 -3
- package/dist/coding-tools.js +16 -10
- package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
- package/dist/console/assets/index-CnJBf7Lc.js +486 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-rows.d.ts +11 -3
- package/dist/decision-rows.js +18 -11
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -2
- package/dist/files.d.ts +9 -1
- package/dist/files.js +10 -2
- package/dist/grade.d.ts +11 -11
- package/dist/grade.js +43 -55
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +7 -5
- package/dist/graph-view.js +10 -3
- package/dist/harness-app.d.ts +4 -2
- package/dist/harness-app.js +110 -19
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +4 -1
- package/dist/harness.js +5 -2
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/host-tools.d.ts +12 -2
- package/dist/host-tools.js +26 -12
- package/dist/host.js +6 -2
- package/dist/hosted-search.js +5 -1
- package/dist/import.d.ts +2 -2
- package/dist/import.js +4 -3
- package/dist/key-check.d.ts +3 -2
- package/dist/key-check.js +7 -3
- package/dist/key-refusal.js +8 -4
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/check.d.ts +10 -1
- package/dist/learn/check.js +19 -1
- package/dist/learn/grade.d.ts +6 -2
- package/dist/learn/grade.js +28 -14
- package/dist/learn/index.d.ts +3 -3
- package/dist/learn/index.js +3 -3
- package/dist/learn/notes.js +2 -1
- package/dist/learn/reflect.d.ts +2 -2
- package/dist/learn/reflect.js +53 -5
- package/dist/learn/secrets.js +28 -8
- package/dist/learn/skills.d.ts +19 -4
- package/dist/learn/skills.js +95 -6
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +8 -6
- package/dist/learning-run.js +70 -27
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +34 -13
- package/dist/learning.d.ts +52 -3
- package/dist/learning.js +204 -4
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +33 -9
- package/dist/mcp-servers.js +58 -10
- package/dist/mcp.js +5 -5
- package/dist/model.d.ts +13 -11
- package/dist/model.js +11 -10
- package/dist/openapi/agentrun-v2.openapi.json +1 -0
- package/dist/openapi.js +407 -54
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/paid-calls.d.ts +5 -1
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -0
- package/dist/place.d.ts +29 -5
- package/dist/place.js +51 -11
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +38 -8
- package/dist/request-start.d.ts +12 -4
- package/dist/request-start.js +139 -15
- package/dist/run-box.d.ts +56 -4
- package/dist/run-box.js +183 -23
- package/dist/runnable.d.ts +13 -3
- package/dist/runnable.js +63 -6
- package/dist/runs.d.ts +266 -37
- package/dist/runs.js +884 -90
- package/dist/secrets.d.ts +27 -0
- package/dist/secrets.js +38 -2
- package/dist/server.d.ts +141 -36
- package/dist/server.js +562 -118
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +16 -4
- package/dist/skills.js +35 -7
- package/dist/stats.d.ts +7 -2
- package/dist/stats.js +28 -7
- package/dist/tool-gate.d.ts +281 -0
- package/dist/tool-gate.js +585 -0
- package/dist/tool-keys.d.ts +48 -11
- package/dist/tool-keys.js +46 -8
- package/dist/tool-plane.d.ts +116 -27
- package/dist/tool-plane.js +232 -50
- package/dist/tools.d.ts +69 -14
- package/dist/tools.js +148 -26
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +3 -2
- package/dist/turn-end.js +3 -2
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -2
- package/dist/web-fetch.js +3 -3
- package/dist/webhooks.d.ts +11 -4
- package/dist/webhooks.js +17 -1
- package/launcher/agentrun-serve +1 -1
- package/package.json +16 -14
- package/dist/console/assets/index-BN7oVcO4.js +0 -445
- package/dist/console/assets/index-By-jkqki.css +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
|
|
2
|
+
export interface OpenCodePins {
|
|
3
|
+
/** The release `opencode --version` must report. */
|
|
4
|
+
version: string;
|
|
5
|
+
/** The binary's sha256 for each platform package the pins list; a package not listed is unchecked here. */
|
|
6
|
+
sha256: Readonly<Record<string, string>>;
|
|
7
|
+
}
|
|
8
|
+
/** The pins this package holds. */
|
|
9
|
+
export declare const openCodePins: () => OpenCodePins;
|
|
10
|
+
/**
|
|
11
|
+
* The binary at `found.path` checked against `pins`, in order: its platform package's version, the binary's sha256 (its
|
|
12
|
+
* package's pin, or for a binary named by OPENCODE_BIN the pin of any package this machine may run, when the pins list
|
|
13
|
+
* one), then the version it reports. Returns the path, or the typed error (not thrown) naming the
|
|
14
|
+
* pin, what was expected and what was found. No path, or a binary that cannot be read or run, is `OpenCodeNotInstalled`.
|
|
15
|
+
* The path is made absolute first, from this process's working directory: a session starts the binary from its own
|
|
16
|
+
* directory, where a relative `OPENCODE_BIN` names nothing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function verifyOpenCodeBinary(found: {
|
|
19
|
+
path: string;
|
|
20
|
+
pkg?: string;
|
|
21
|
+
packageVersion?: string;
|
|
22
|
+
} | undefined, pins?: OpenCodePins): {
|
|
23
|
+
path: string;
|
|
24
|
+
} | OpenCodePinMismatch | OpenCodeNotInstalled;
|
|
25
|
+
/** This machine's OpenCode checked against the pins: its path, or the typed error thrown. */
|
|
26
|
+
export declare function verifyOpenCode(found?: {
|
|
27
|
+
path: string;
|
|
28
|
+
pkg?: string;
|
|
29
|
+
packageVersion?: string;
|
|
30
|
+
} | undefined, pins?: OpenCodePins): {
|
|
31
|
+
path: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The installed OpenCode checked against the pins (src/versions.ts) before anything runs, with the typed errors a host
|
|
2
|
+
// maps to a run's failure line. Written for AgentRun.
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join, resolve } from "node:path";
|
|
7
|
+
import { env } from "node:process";
|
|
8
|
+
import { checkedOnce, sha256OfFile } from "@parcha/agentrun-kernel/host";
|
|
9
|
+
import { findOpenCode, openCodePackages } from "./binary.js";
|
|
10
|
+
import { OPENCODE_BINARY_SHA256, OPENCODE_VERSION, OpenCodeNotInstalled, OpenCodePinMismatch } from "./versions.js";
|
|
11
|
+
/** The pins this package holds. */
|
|
12
|
+
export const openCodePins = () => ({ version: OPENCODE_VERSION, sha256: OPENCODE_BINARY_SHA256 });
|
|
13
|
+
/**
|
|
14
|
+
* The binary at `found.path` checked against `pins`, in order: its platform package's version, the binary's sha256 (its
|
|
15
|
+
* package's pin, or for a binary named by OPENCODE_BIN the pin of any package this machine may run, when the pins list
|
|
16
|
+
* one), then the version it reports. Returns the path, or the typed error (not thrown) naming the
|
|
17
|
+
* pin, what was expected and what was found. No path, or a binary that cannot be read or run, is `OpenCodeNotInstalled`.
|
|
18
|
+
* The path is made absolute first, from this process's working directory: a session starts the binary from its own
|
|
19
|
+
* directory, where a relative `OPENCODE_BIN` names nothing.
|
|
20
|
+
*/
|
|
21
|
+
export function verifyOpenCodeBinary(found, pins = openCodePins()) {
|
|
22
|
+
if (!found)
|
|
23
|
+
return new OpenCodeNotInstalled("no OpenCode binary found for this platform, and OPENCODE_BIN is not set");
|
|
24
|
+
const path = resolve(found.path);
|
|
25
|
+
if (!existsSync(path))
|
|
26
|
+
return new OpenCodeNotInstalled(`no file at ${path}`);
|
|
27
|
+
if (found.packageVersion !== undefined && found.packageVersion !== pins.version)
|
|
28
|
+
return new OpenCodePinMismatch("package_version", pins.version, found.packageVersion, path);
|
|
29
|
+
// A binary from a platform package is checked against that package's pin; one named by OPENCODE_BIN (no package) against
|
|
30
|
+
// the pins of every package this machine may run.
|
|
31
|
+
const expected = (found.pkg ? [found.pkg] : openCodePackages()).map((pkg) => pins.sha256[pkg]).filter((sha) => typeof sha === "string");
|
|
32
|
+
// Hashed a chunk at a time, and checked once per binary in this process while it stays the same file, unchanged (the
|
|
33
|
+
// kernel's checkedOnce): a host that checks it for each model it resolves, and a run's process that makes its adapter,
|
|
34
|
+
// check it once.
|
|
35
|
+
return checkedOnce(path, JSON.stringify({ version: pins.version, expected }), () => checkBinary(path, pins.version, expected), (result) => !(result instanceof Error));
|
|
36
|
+
}
|
|
37
|
+
/** The binary at `path` (absolute, there) against the sha256 values it may have and the version it must report. */
|
|
38
|
+
function checkBinary(path, version, expected) {
|
|
39
|
+
if (expected.length) {
|
|
40
|
+
let sha256;
|
|
41
|
+
try {
|
|
42
|
+
sha256 = sha256OfFile(path);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return new OpenCodeNotInstalled(`${path} could not be read: ${String(error?.message ?? error).slice(0, 120)}`);
|
|
46
|
+
}
|
|
47
|
+
if (!expected.includes(sha256))
|
|
48
|
+
return new OpenCodePinMismatch("binary_sha256", expected[0], sha256, path);
|
|
49
|
+
}
|
|
50
|
+
let reported;
|
|
51
|
+
// A private home, removed after: `--version` makes OpenCode's directories, and reads no config and writes no state of
|
|
52
|
+
// the host's.
|
|
53
|
+
const home = mkdtempSync(join(tmpdir(), "agentrun-opencode-version-"));
|
|
54
|
+
try {
|
|
55
|
+
const dirs = { HOME: home, XDG_CONFIG_HOME: join(home, "config"), XDG_DATA_HOME: join(home, "data"), XDG_CACHE_HOME: join(home, "cache"), XDG_STATE_HOME: join(home, "state") };
|
|
56
|
+
reported = execFileSync(path, ["--version"], { env: { PATH: env.PATH ?? "/usr/bin:/bin", ...dirs, OPENCODE_DISABLE_AUTOUPDATE: "1" }, cwd: home, encoding: "utf8", timeout: 20_000 }).trim();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
return new OpenCodeNotInstalled(`${path} could not be run: ${String(error?.message ?? error).slice(0, 120)}`);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
rmSync(home, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
const said = /^(\d+\.\d+\.\d+\S*)$/.exec(reported)?.[1] ?? JSON.stringify(reported.slice(0, 60));
|
|
65
|
+
if (said !== version)
|
|
66
|
+
return new OpenCodePinMismatch("version", version, said, path);
|
|
67
|
+
return { path };
|
|
68
|
+
}
|
|
69
|
+
/** This machine's OpenCode checked against the pins: its path, or the typed error thrown. */
|
|
70
|
+
export function verifyOpenCode(found = findOpenCode(), pins = openCodePins()) {
|
|
71
|
+
const result = verifyOpenCodeBinary(found, pins);
|
|
72
|
+
if (result instanceof Error)
|
|
73
|
+
throw result;
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { OPENCODE_VERSION } from "./binary.js";
|
|
2
|
+
/** The OpenCode CLI release this adapter is built and tested with (`opencode --version` prints it). */
|
|
3
|
+
export { OPENCODE_VERSION };
|
|
4
|
+
/** The install line for the pinned release (npm installs this platform's binary package with it). */
|
|
5
|
+
export declare const OPENCODE_INSTALL = "npm install --save-exact opencode-ai@1.19.5";
|
|
6
|
+
/**
|
|
7
|
+
* npm's integrity of the pinned launcher and of each platform package, as the registry publishes them. npm checks a
|
|
8
|
+
* download against the lockfile's copy of these; test/pins.test.mjs keeps the repository's lockfile equal to them.
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPENCODE_NPM_INTEGRITY: Readonly<Record<string, string>>;
|
|
11
|
+
/** The sha256 of the pinned native binary (`bin/opencode` in the platform package), per platform package, read from the
|
|
12
|
+
* packages those integrities name as npm installed them on Linux x64 (the two builds ship the same file). A binary from
|
|
13
|
+
* a package listed here runs only if it matches; one from a package not listed is checked by its package's version and
|
|
14
|
+
* the version it reports, and npm checked its package against the integrity above when it installed it. */
|
|
15
|
+
export declare const OPENCODE_BINARY_SHA256: Readonly<Record<string, string>>;
|
|
16
|
+
/** Which pin a mismatch is about: the binary's sha256, the version it reports, or the platform package's version. */
|
|
17
|
+
export type OpenCodePin = "binary_sha256" | "version" | "package_version";
|
|
18
|
+
/** The installed OpenCode is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
19
|
+
export declare class OpenCodePinMismatch extends Error {
|
|
20
|
+
readonly pin: OpenCodePin;
|
|
21
|
+
readonly expected: string;
|
|
22
|
+
readonly found: string;
|
|
23
|
+
readonly path?: string | undefined;
|
|
24
|
+
readonly code = "OPENCODE_PIN_MISMATCH";
|
|
25
|
+
constructor(pin: OpenCodePin, expected: string, found: string, path?: string | undefined);
|
|
26
|
+
}
|
|
27
|
+
/** No OpenCode binary to run: the host has not installed `opencode-ai` (or this platform's package), or the binary
|
|
28
|
+
* named could not be run. */
|
|
29
|
+
export declare class OpenCodeNotInstalled extends Error {
|
|
30
|
+
readonly detail?: string | undefined;
|
|
31
|
+
readonly code = "OPENCODE_NOT_INSTALLED";
|
|
32
|
+
constructor(detail?: string | undefined);
|
|
33
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The OpenCode build this adapter is pinned to and checked against, and the typed errors a host maps to a run's failure
|
|
2
|
+
// line when the installed build is not it. Written for AgentRun.
|
|
3
|
+
//
|
|
4
|
+
// The pin is exact: the adapter mirrors OpenCode's own per-session event log into the session's records and gives it
|
|
5
|
+
// back to a new process (`/sync/replay`), and that log's shape is OpenCode's internal one, which any release may change.
|
|
6
|
+
import { OPENCODE_VERSION } from "./binary.js";
|
|
7
|
+
/** The OpenCode CLI release this adapter is built and tested with (`opencode --version` prints it). */
|
|
8
|
+
export { OPENCODE_VERSION };
|
|
9
|
+
/** The install line for the pinned release (npm installs this platform's binary package with it). */
|
|
10
|
+
export const OPENCODE_INSTALL = `npm install --save-exact opencode-ai@${OPENCODE_VERSION}`;
|
|
11
|
+
/**
|
|
12
|
+
* npm's integrity of the pinned launcher and of each platform package, as the registry publishes them. npm checks a
|
|
13
|
+
* download against the lockfile's copy of these; test/pins.test.mjs keeps the repository's lockfile equal to them.
|
|
14
|
+
*/
|
|
15
|
+
export const OPENCODE_NPM_INTEGRITY = Object.freeze({
|
|
16
|
+
"opencode-ai": "sha512-tEqMvQahfhdDj8vceYpXtoIrvjPXm5XRfetWnPN5YISueU7adNx9JcUA3zZ+2GKuDVgDpGdQe1ZLtCZDjqodvA==",
|
|
17
|
+
"opencode-linux-x64": "sha512-i1qh7VooLGML9xX6ud93y0JA8j/1aPeDYRKjsmYXrJX1TjIWHgBBMkEbEJPZthpWbsJg//XfBgR6Kb7+NPaJiQ==",
|
|
18
|
+
"opencode-linux-x64-baseline": "sha512-9kA+st3XXtCXMPx5f3Ld1u19uoHTO2u2Btt8a2cqhJ4GIqVbD1mXLevj3LHFEmtuQoFGk+UstGnl38sCqXj5sQ==",
|
|
19
|
+
"opencode-linux-x64-musl": "sha512-y6nUbH3ViajN37KaVVy0/KnWv/i48Bx5QPv9Ul9ONJya1ossV7CHVb+ZNFc61M5GqlVtjCvZV7T0eBMqhJG7mg==",
|
|
20
|
+
"opencode-linux-x64-baseline-musl": "sha512-kwt6hmTaI6nujjAzdAkXv3j2rDzXNOMfMk8Jf8bwacHtwUl8CWA2psDVg3nWyb4zByAa6F1jSIlmHCPHBq1K/Q==",
|
|
21
|
+
"opencode-linux-arm64": "sha512-u2HFRI6v1nNMVKiV34An8XrGBxJeZ+RCg2tYu3SqlGODKqKsr5RoEbaX1tnsfGb+rETh9AJVX9kS8dSZXPufsA==",
|
|
22
|
+
"opencode-linux-arm64-musl": "sha512-YxvpVPJ/jeevV93DVRiuOVbhkoJAuwQUadPDHPaw65aZkAKZ6OE7XySwCS+Rjlhzt7fPryisvAOjUtZkwfMBuQ==",
|
|
23
|
+
"opencode-darwin-x64": "sha512-+DO7IMPTCrX12UJXnL4pL3ckcwR6BR6f6tA9QIlVQ5nZx66T5U7FRMJT4n5rsOnJxLM/pZ2vfX1G8vrnvXO8FA==",
|
|
24
|
+
"opencode-darwin-x64-baseline": "sha512-rftvAoHBWPVkvwBLr3SQWRZvcIjyMTN0SlhMzlt+lgvoQBBGNEmZQ/7sS/Ux1oHsJV/++UDuLVso4n5L95YD5Q==",
|
|
25
|
+
"opencode-darwin-arm64": "sha512-0MbSbKkmwVHtgP31GJyyECe6QVy4T7W4Wp7s2TsmXHTPPyf01ne3dWSX97X9dkNK28Lc6kt+zMPQUP/9GgDLZg==",
|
|
26
|
+
"opencode-windows-x64": "sha512-xCVbrA8A/qQTAdBIKyhK5tx3/mcq18yF82Mi8phry0MJb2631nnnpxF9m6FFfWAVHyer4qFGrO7hbWXesHQ1Gg==",
|
|
27
|
+
"opencode-windows-x64-baseline": "sha512-yRHN+TsfLjfLmdQVAVWqTGfGP1yq8YtUFy9Jw33XhlPIp77slBdCJrj2PC4amuEl6BJtaIQDhDFbpJ8+a5z7Qw==",
|
|
28
|
+
"opencode-windows-arm64": "sha512-aySF/MDji5KO3I5yl9Ec4g8kW/QIx4Jj5FXwBhh/FrDu0w6L8HAOGH7cyjFb3t8TW7pxRkH3Ei3rfkWAE7cScw==",
|
|
29
|
+
});
|
|
30
|
+
/** The sha256 of the pinned native binary (`bin/opencode` in the platform package), per platform package, read from the
|
|
31
|
+
* packages those integrities name as npm installed them on Linux x64 (the two builds ship the same file). A binary from
|
|
32
|
+
* a package listed here runs only if it matches; one from a package not listed is checked by its package's version and
|
|
33
|
+
* the version it reports, and npm checked its package against the integrity above when it installed it. */
|
|
34
|
+
export const OPENCODE_BINARY_SHA256 = Object.freeze({
|
|
35
|
+
"opencode-linux-x64": "7df4e4136301f16589b0f30bf91a61380fca5f8ef22dd36570f5ebe1d4ec802c",
|
|
36
|
+
"opencode-linux-x64-baseline": "7df4e4136301f16589b0f30bf91a61380fca5f8ef22dd36570f5ebe1d4ec802c",
|
|
37
|
+
});
|
|
38
|
+
/** The installed OpenCode is not the build this adapter is pinned to and checked with: nothing runs. */
|
|
39
|
+
export class OpenCodePinMismatch extends Error {
|
|
40
|
+
pin;
|
|
41
|
+
expected;
|
|
42
|
+
found;
|
|
43
|
+
path;
|
|
44
|
+
code = "OPENCODE_PIN_MISMATCH";
|
|
45
|
+
constructor(pin, expected, found, path) {
|
|
46
|
+
super(`opencode: the OpenCode ${pin === "package_version" ? "platform package" : "binary"}${path ? ` at ${path}` : ""} is not the pinned build: its ${pin.replace("_", " ")} is ${found}, not ${expected}`);
|
|
47
|
+
this.pin = pin;
|
|
48
|
+
this.expected = expected;
|
|
49
|
+
this.found = found;
|
|
50
|
+
this.path = path;
|
|
51
|
+
this.name = "OpenCodePinMismatch";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** No OpenCode binary to run: the host has not installed `opencode-ai` (or this platform's package), or the binary
|
|
55
|
+
* named could not be run. */
|
|
56
|
+
export class OpenCodeNotInstalled extends Error {
|
|
57
|
+
detail;
|
|
58
|
+
code = "OPENCODE_NOT_INSTALLED";
|
|
59
|
+
constructor(detail) {
|
|
60
|
+
super(`opencode: OpenCode ${OPENCODE_VERSION} is not installed${detail ? ` (${detail})` : ""}; ${OPENCODE_INSTALL}`);
|
|
61
|
+
this.detail = detail;
|
|
62
|
+
this.name = "OpenCodeNotInstalled";
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/harness.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const HARNESSES: readonly ["pi", "claude-agent", "codex"];
|
|
1
|
+
export declare const HARNESSES: readonly ["pi", "claude-agent", "codex", "opencode"];
|
|
2
2
|
export type HarnessId = (typeof HARNESSES)[number];
|
|
3
3
|
export declare const DEFAULT_HARNESS: HarnessId;
|
|
4
4
|
/** The memory one run of each harness reserves while its process lives, in MiB: what admission counts (host.ts).
|
|
@@ -10,6 +10,9 @@ export declare const DEFAULT_HARNESS: HarnessId;
|
|
|
10
10
|
* pi: n=1 106, 106; n=3 96, 99 MB a run → 128 (+21%)
|
|
11
11
|
* codex: n=1 132, 143; n=3 120, 131 MB a run → 192 (+34%)
|
|
12
12
|
* claude-agent: n=1 215, 208; n=3 211, 208 MB a run → 288 (+34%)
|
|
13
|
+
* opencode: n=1 524, 501; n=3 509, 514 MB a run → 704 (+34%), measured the same way 2026-11-04 on the pinned
|
|
14
|
+
* OpenCode 1.19.5 (its own process, a Bun binary, is most of it; at a 1024M limit two runs were
|
|
15
|
+
* OOM-killed, and at 512M one short run completed)
|
|
13
16
|
* The margin covers a longer conversation than the probe's three steps; the CLI harnesses (codex, claude-agent) grow
|
|
14
17
|
* more with one, so theirs is larger. At a 512M limit the same build completed pi x3, codex x2 and claude-agent x1
|
|
15
18
|
* (and x2). A check that reads a binary whole adds its size to the server and to each run (294 MB for codex, 230 MB
|
package/dist/harness.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// one of the run adapters. A revision keeps the harness it names; the default is never stored, so a revision written
|
|
3
3
|
// before this field existed and one that names pi are the same revision. Which harnesses this server runs is said in
|
|
4
4
|
// capabilities, and a revision naming one it does not run saves with a warning and is refused at run time.
|
|
5
|
-
export const HARNESSES = ["pi", "claude-agent", "codex"];
|
|
5
|
+
export const HARNESSES = ["pi", "claude-agent", "codex", "opencode"];
|
|
6
6
|
export const DEFAULT_HARNESS = "pi";
|
|
7
7
|
/** The memory one run of each harness reserves while its process lives, in MiB: what admission counts (host.ts).
|
|
8
8
|
* Measured 2026-11-03 on 529c3882e with the pinned binaries' sha256 checked a chunk at a time, not read whole: a
|
|
@@ -13,12 +13,15 @@ export const DEFAULT_HARNESS = "pi";
|
|
|
13
13
|
* pi: n=1 106, 106; n=3 96, 99 MB a run → 128 (+21%)
|
|
14
14
|
* codex: n=1 132, 143; n=3 120, 131 MB a run → 192 (+34%)
|
|
15
15
|
* claude-agent: n=1 215, 208; n=3 211, 208 MB a run → 288 (+34%)
|
|
16
|
+
* opencode: n=1 524, 501; n=3 509, 514 MB a run → 704 (+34%), measured the same way 2026-11-04 on the pinned
|
|
17
|
+
* OpenCode 1.19.5 (its own process, a Bun binary, is most of it; at a 1024M limit two runs were
|
|
18
|
+
* OOM-killed, and at 512M one short run completed)
|
|
16
19
|
* The margin covers a longer conversation than the probe's three steps; the CLI harnesses (codex, claude-agent) grow
|
|
17
20
|
* more with one, so theirs is larger. At a 512M limit the same build completed pi x3, codex x2 and claude-agent x1
|
|
18
21
|
* (and x2). A check that reads a binary whole adds its size to the server and to each run (294 MB for codex, 230 MB
|
|
19
22
|
* for the claude-agent CLI), and these sizes do not cover it. The faux model and the faux
|
|
20
23
|
* harness reserve the size of the harness they stand in for, so tests admit as a real server does. */
|
|
21
|
-
export const RUN_MIB = { pi: 128, "claude-agent": 288, codex: 192 };
|
|
24
|
+
export const RUN_MIB = { pi: 128, "claude-agent": 288, codex: 192, opencode: 704 };
|
|
22
25
|
/** Whether a harness takes a message mid-turn: pi does; another harness's run queues it for the turn's end. */
|
|
23
26
|
export const steersMidTurn = (id) => id === DEFAULT_HARNESS;
|
|
24
27
|
/** A module whose `script(spec)` scripts run-adapters' faux harness: with it, every harness but pi runs on that faux
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
|
|
2
|
+
* header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
|
|
3
|
+
export declare function hostName(header: string | undefined): string | undefined;
|
|
4
|
+
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
5
|
+
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
6
|
+
* front of it sends. */
|
|
7
|
+
export declare function loopbackNames(host: string, allowHosts?: readonly string[], publicUrl?: string): Set<string>;
|
|
8
|
+
/** What a refused request is told: the names that work and how to add one. It never repeats the Host it was sent. */
|
|
9
|
+
export declare const HOST_FIX = "this server answers at localhost or 127.0.0.1, on any port (a tunnel such as ssh -L 7340:localhost:7340 works); to serve it at a name of its own, start it with AGENTRUN_PUBLIC_URL=https://<name> or --allow-host <name>";
|
|
10
|
+
/** The page a browser gets for a refused Host: fixed text, under the console's CSP (page.ts). Its addresses carry no
|
|
11
|
+
* scheme: a published package names no loopback URL (scripts/verify-packages.mjs). */
|
|
12
|
+
export declare const HOST_REFUSED_PAGE = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><title>AgentRun: open it at localhost</title></head>\n<body>\n<h1>Open AgentRun at localhost</h1>\n<p>This AgentRun server answers only at a name on its own machine, so it refused the address this page was opened at.</p>\n<p>Open it at <code>localhost:<port></code> or <code>127.0.0.1:<port></code>, with the port you reached it on. From another computer, a tunnel works at any local port: <code>ssh -L 7340:localhost:7340 <server></code>, then open <code>localhost:7340</code> in the browser.</p>\n<p>To serve it at a name of its own (behind HTTPS, for example), start it with <code>AGENTRUN_PUBLIC_URL=https://<name></code>, or add the name with <code>--allow-host <name></code>.</p>\n</body></html>\n";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The Host check of a server on loopback (server.ts), the guard against DNS rebinding: a page on a name of its own, its
|
|
2
|
+
// address rebound to 127.0.0.1, calling this server from the person's browser. The name is what tells that page apart, so
|
|
3
|
+
// the check is on the name alone. The port is not part of it: through a tunnel (`ssh -L 8080:localhost:7340`), a proxy in
|
|
4
|
+
// front, or a server that took the next free port, a browser sends the port it opened, which is not the server's, and a
|
|
5
|
+
// page that rebound its name gains nothing from any port.
|
|
6
|
+
/** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
|
|
7
|
+
* header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
|
|
8
|
+
export function hostName(header) {
|
|
9
|
+
const match = /^(\[[0-9a-f:.]+\]|[a-z0-9._-]+)(?::(\d{1,5}))?$/.exec(String(header ?? "").trim().toLowerCase());
|
|
10
|
+
return match && (match[2] === undefined || Number(match[2]) <= 65535) ? match[1] : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
13
|
+
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
14
|
+
* front of it sends. */
|
|
15
|
+
export function loopbackNames(host, allowHosts = [], publicUrl) {
|
|
16
|
+
const own = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
17
|
+
const names = ["localhost", "127.0.0.1", "[::1]", own, ...allowHosts];
|
|
18
|
+
if (publicUrl !== undefined && URL.canParse(publicUrl))
|
|
19
|
+
names.push(new URL(publicUrl).hostname);
|
|
20
|
+
return new Set(names.map(hostName).filter((name) => name !== undefined));
|
|
21
|
+
}
|
|
22
|
+
/** What a refused request is told: the names that work and how to add one. It never repeats the Host it was sent. */
|
|
23
|
+
export const HOST_FIX = "this server answers at localhost or 127.0.0.1, on any port (a tunnel such as ssh -L 7340:localhost:7340 works); to serve it at a name of its own, start it with AGENTRUN_PUBLIC_URL=https://<name> or --allow-host <name>";
|
|
24
|
+
/** The page a browser gets for a refused Host: fixed text, under the console's CSP (page.ts). Its addresses carry no
|
|
25
|
+
* scheme: a published package names no loopback URL (scripts/verify-packages.mjs). */
|
|
26
|
+
export const HOST_REFUSED_PAGE = `<!doctype html>
|
|
27
|
+
<html lang="en"><head><meta charset="utf-8"><title>AgentRun: open it at localhost</title></head>
|
|
28
|
+
<body>
|
|
29
|
+
<h1>Open AgentRun at localhost</h1>
|
|
30
|
+
<p>This AgentRun server answers only at a name on its own machine, so it refused the address this page was opened at.</p>
|
|
31
|
+
<p>Open it at <code>localhost:<port></code> or <code>127.0.0.1:<port></code>, with the port you reached it on. From another computer, a tunnel works at any local port: <code>ssh -L 7340:localhost:7340 <server></code>, then open <code>localhost:7340</code> in the browser.</p>
|
|
32
|
+
<p>To serve it at a name of its own (behind HTTPS, for example), start it with <code>AGENTRUN_PUBLIC_URL=https://<name></code>, or add the name with <code>--allow-host <name></code>.</p>
|
|
33
|
+
</body></html>
|
|
34
|
+
`;
|
package/dist/host-tools.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ import type { Context } from "@earendil-works/chord";
|
|
|
2
2
|
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { DurableRun } from "@parcha/pi-durable-disk";
|
|
5
|
+
import type { Park, RunGate } from "./tool-gate.js";
|
|
5
6
|
export { workspaceRelative } from "./workspace-paths.js";
|
|
6
|
-
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
7
|
+
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
8
|
+
* `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL, named here as a string so the modules do not import
|
|
9
|
+
* each other) is never run again. */
|
|
7
10
|
export declare const REPLAY: Record<string, "safe" | "never">;
|
|
8
11
|
/** pi's limits on a tool's output (its DEFAULT_MAX_BYTES and DEFAULT_MAX_LINES), unless the tool names its own: read's
|
|
9
12
|
* head and bash's tail are held to them (the host-bounds test reads pi's own words for them). */
|
|
@@ -17,4 +20,11 @@ export type ToolResults = Map<string, {
|
|
|
17
20
|
text: string;
|
|
18
21
|
isError: boolean;
|
|
19
22
|
}>;
|
|
20
|
-
|
|
23
|
+
/** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
|
|
24
|
+
* passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
|
|
25
|
+
* gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
|
|
26
|
+
* learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
|
|
27
|
+
export declare function hostTools(run: DurableRun, names: readonly string[], context: Context, results: ToolResults, coding?: readonly ToolRegistration[], gated?: {
|
|
28
|
+
gate: RunGate;
|
|
29
|
+
park: Park;
|
|
30
|
+
}, extra?: readonly ToolRegistration[]): HostTool[];
|
package/dist/host-tools.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
// The host tools of a run on a harness other than pi: its coding tools, from the run's coding source (coding-tools.ts:
|
|
2
|
-
// pi's own read, write and edit on the run's environment, or in a box those
|
|
3
|
-
// their confinement and their refusals are pi's, word for word, pi's web_fetch (also under
|
|
4
|
-
// fetch_page), the public-host guard included, web_search, and monid's three (monid.ts), which stay on this machine.
|
|
2
|
+
// pi's own read, write and edit on the run's environment, or in a box those, bash and the background tools on the
|
|
3
|
+
// box's), so their arguments, their confinement and their refusals are pi's, word for word, pi's web_fetch (also under
|
|
4
|
+
// its legacy name, fetch_page), the public-host guard included, web_search, and monid's three (monid.ts), which stay on this machine.
|
|
5
5
|
// pi's tools take only the environment, their output and their diagnostics from a call's API, and a paid one its call's
|
|
6
6
|
// id and the run's store, so that is all a call here gives them: the output's tail or head as the tool keeps it (pi's
|
|
7
|
-
// limits), then the diagnostics, also when the tool failed. read, the web tools, monid.discover
|
|
8
|
-
// run again after a crash; write, edit, bash
|
|
9
|
-
//
|
|
10
|
-
// to the harness under its wire name (catalog.ts: `monid.run` is `monid_run`), which the harness calls and journals. A
|
|
7
|
+
// limits), then the diagnostics, also when the tool failed. read, the web tools, monid.discover, monid.inspect,
|
|
8
|
+
// bash_output and bash_list may run again after a crash; write, edit, bash, monid.run, bash_background, bash_input and
|
|
9
|
+
// bash_signal never: the kernel records each one's intent before it runs, and a call a crash cut off is answered
|
|
10
|
+
// interrupted, not run again. A tool is named by its catalog name here and goes to the harness under its wire name (catalog.ts: `monid.run` is `monid_run`), which the harness calls and journals. A
|
|
11
11
|
// refusal, an error and a write's or edit's result name a path in the workspace relative to it (`hello.md`), never by
|
|
12
|
-
// the server's data directory (`workspaceRelative`); in a box they name the box's paths.
|
|
12
|
+
// the server's data directory (`workspaceRelative`); in a box they name the box's paths. Each call passes the run's tool
|
|
13
|
+
// gate first (tool-gate.ts): a denied call is refused, an asked one parked, and the harness is told so it ends the turn.
|
|
13
14
|
import { StringDecoder } from "node:string_decoder";
|
|
14
15
|
import { withAbortSignal } from "@earendil-works/chord/context";
|
|
15
16
|
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
@@ -23,8 +24,10 @@ import { WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
|
|
|
23
24
|
import { WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
24
25
|
import { realOf, workspaceRelative } from "./workspace-paths.js";
|
|
25
26
|
export { workspaceRelative } from "./workspace-paths.js";
|
|
26
|
-
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
27
|
-
|
|
27
|
+
/** Each tool a harness other than pi runs here, by catalog name, and whether a call a crash cut off may run again.
|
|
28
|
+
* `learned_workflow` (learned-workflow.ts LEARNED_WORKFLOW_TOOL, named here as a string so the modules do not import
|
|
29
|
+
* each other) is never run again. */
|
|
30
|
+
export const REPLAY = { read: "safe", write: "never", edit: "never", bash: "never", [FETCH_PAGE_TOOL]: "safe", [WEB_FETCH_TOOL]: "safe", [WEB_SEARCH_TOOL]: "safe", "monid.discover": "safe", "monid.inspect": "safe", "monid.run": "never", bash_background: "never", bash_output: "safe", bash_input: "never", bash_signal: "never", bash_list: "safe", learned_workflow: "never" };
|
|
28
31
|
/** pi's limits on a tool's output (its DEFAULT_MAX_BYTES and DEFAULT_MAX_LINES), unless the tool names its own: read's
|
|
29
32
|
* head and bash's tail are held to them (the host-bounds test reads pi's own words for them). */
|
|
30
33
|
export const MAX_BYTES = 50 * 1024;
|
|
@@ -91,7 +94,11 @@ function bounded(limits) {
|
|
|
91
94
|
/** The tools whose result is pi's own words about a path (`Successfully wrote to <path>`), never a file's text. */
|
|
92
95
|
const SAYS_PATH = new Set(["write", "edit"]);
|
|
93
96
|
const textOf = (content) => Array.isArray(content) ? content.map((block) => (block && typeof block === "object" && "text" in block && typeof block.text === "string" ? block.text : "")).join("") : "";
|
|
94
|
-
|
|
97
|
+
/** The host tools `names` names, on the run's coding source `coding`. `gated`: the run's tool gate, which every call
|
|
98
|
+
* passes, and the park it takes (harness-app.ts), told of a call it parked, whose turn the harness ends; none (the
|
|
99
|
+
* gate's own run of an approved call), each call runs as asked. `extra`: the run's own tools beyond the table (its
|
|
100
|
+
* learned_workflow, learned-workflow.ts), which the gate passes like the rest. */
|
|
101
|
+
export function hostTools(run, names, context, results, coding = CodingTools.tools ?? [], gated, extra = []) {
|
|
95
102
|
// The coding source gives the coding tools and nothing else: the network tools are this machine's own, below.
|
|
96
103
|
const stray = coding.map((tool) => tool.name).filter((name) => !BOXED_TOOLS.includes(name));
|
|
97
104
|
if (stray.length)
|
|
@@ -102,7 +109,8 @@ export function hostTools(run, names, context, results, coding = CodingTools.too
|
|
|
102
109
|
// never in its environment, and its long answers go in the run's work/, the claim's as pi's (`where.work`), read at
|
|
103
110
|
// the call. They are outside the coding source, which holds the coding tools only.
|
|
104
111
|
const monid = names.some((name) => name.startsWith("monid.")) ? monidTools(withSecrets(process.env), () => run.claim.work) : [];
|
|
105
|
-
|
|
112
|
+
// `extra`: the run's own tools beyond the table, its learned_workflow (learned-workflow.ts) when its pin names one.
|
|
113
|
+
const tools = new Map([...coding, ...web, ...monid, ...extra].map((tool) => [tool.name, tool]));
|
|
106
114
|
return names.flatMap((name) => {
|
|
107
115
|
// The registrations are keyed by their wire names: the same name for every tool here but monid's.
|
|
108
116
|
const tool = tools.get(wireName(name));
|
|
@@ -115,6 +123,12 @@ export function hostTools(run, names, context, results, coding = CodingTools.too
|
|
|
115
123
|
inputSchema: tool.parameters,
|
|
116
124
|
replay,
|
|
117
125
|
async call(args, { callId, signal }) {
|
|
126
|
+
const refused = await gated?.gate.enter(name, args, callId, gated.park);
|
|
127
|
+
if (refused) {
|
|
128
|
+
const answer = { text: refused.text, isError: refused.isError };
|
|
129
|
+
results.set(callId, answer);
|
|
130
|
+
return answer;
|
|
131
|
+
}
|
|
118
132
|
const out = bounded(tool.outputLimits);
|
|
119
133
|
const notes = [];
|
|
120
134
|
const env = await run.env({ conversationId: ROOT_CONVERSATION_ID, read: undefined }, context);
|
package/dist/host.js
CHANGED
|
@@ -35,17 +35,21 @@ export function runsThatFit(harness, memory) {
|
|
|
35
35
|
/** The default cap on how many runs at once: as many pi runs, the smallest, as fit. */
|
|
36
36
|
export const defaultMaxRuns = (memory) => runsThatFit(DEFAULT_HARNESS, memory);
|
|
37
37
|
const sizeOf = (mib) => `${Math.round(mib)} MB`;
|
|
38
|
+
/** "a pi run", "an opencode run". */
|
|
39
|
+
const aRun = (harness) => `${/^[aeiou]/i.test(harness) ? "an" : "a"} ${harness} run`;
|
|
40
|
+
/** "pi", "pi and codex", "pi, claude-agent and codex". */
|
|
41
|
+
const listed = (names) => (names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names.join(""));
|
|
38
42
|
/** Why no run of `harness` can ever start on a host of `memory` bytes, in words; undefined when one fits. */
|
|
39
43
|
export function neverFits(harness, memory) {
|
|
40
44
|
if (runsThatFit(harness, memory) > 0)
|
|
41
45
|
return undefined;
|
|
42
46
|
const fit = HARNESSES.filter((id) => runsThatFit(id, memory) > 0);
|
|
43
|
-
return `This server has ${sizeOf(memory / MiB)} of memory and keeps ${sizeOf(SERVER_MIB)} for itself;
|
|
47
|
+
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.`;
|
|
44
48
|
}
|
|
45
49
|
/** Why a run of `harness` cannot start now, with `heldMib` of the memory for runs held: the memory runs hold, in words. */
|
|
46
50
|
export function memoryFull(harness, memory, heldMib) {
|
|
47
51
|
const free = Math.max(0, runsMemoryMib(memory) - heldMib);
|
|
48
|
-
return `This server's memory is held by the runs it has going:
|
|
52
|
+
return `This server's memory is held by the runs it has going: ${aRun(harness)} needs about ${sizeOf(runMibOf(harness))}, and ${sizeOf(free)} of the ${sizeOf(runsMemoryMib(memory))} it has for runs is free; start this one when another ends.`;
|
|
49
53
|
}
|
|
50
54
|
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. The
|
|
51
55
|
* memory each run reserves is checked beside it (runs.ts): both apply. */
|
package/dist/hosted-search.js
CHANGED
|
@@ -91,7 +91,11 @@ function reader(anthropic) {
|
|
|
91
91
|
* run's models, at most `n` results: a Search. `models`: the run's (searchOn). */
|
|
92
92
|
export async function hostedSearch(query, n, ref, signal, models = runModels) {
|
|
93
93
|
const slash = ref?.indexOf("/") ?? -1;
|
|
94
|
-
const
|
|
94
|
+
const provider = ref && slash > 0 ? ref.slice(0, slash) : undefined;
|
|
95
|
+
const id = ref && slash > 0 ? ref.slice(slash + 1) : undefined;
|
|
96
|
+
// The name as written, else Anthropic's own id for it (dots as dashes, as claude-agent prepares a dotted name:
|
|
97
|
+
// adapters.ts claudeModelId), the one the run's models hold.
|
|
98
|
+
const model = models && provider && id ? (models.getModel(provider, id) ?? (provider === "anthropic" ? models.getModel(provider, id.replaceAll(".", "-")) : undefined)) : undefined;
|
|
95
99
|
if (!models || !model)
|
|
96
100
|
return { error: `web_search has no model to search on in this run${ref ? ` (${ref})` : ""}` };
|
|
97
101
|
const anthropic = model.api === "anthropic-messages";
|
package/dist/import.d.ts
CHANGED
|
@@ -113,8 +113,8 @@ export declare function projectFiles(cwd: string, skipped: Skipped[]): Promise<{
|
|
|
113
113
|
skills: Record<string, string>;
|
|
114
114
|
}>;
|
|
115
115
|
/** The secrets this server made and keeps in data directory `data`, by value: its API token (`ar_local_...`) and its
|
|
116
|
-
* door token (server.ts), its sign-in sessions' secret (owner.ts)
|
|
117
|
-
* webhooks.ts), opened with the seal key of `env`, so left out when that key is not there. One pasted into a session is
|
|
116
|
+
* door token (server.ts), its sign-in sessions' secret (owner.ts), its webhook's signing secret (`whsec_...`;
|
|
117
|
+
* webhooks.ts) and each webhook trigger's (trigger-secrets.ts), opened with the seal key of `env`, so left out when that key is not there. One pasted into a session is
|
|
118
118
|
* this server's own, so an import cuts it wherever it is, as it cuts the environment's keys. Not among them: a run's own
|
|
119
119
|
* door token (one file a run; not read at each import), and a key-shaped value this server did not make (a `whsec_`
|
|
120
120
|
* from elsewhere). A webhook secret that does not open is said to `say`, as ToolKeys says a saved key that does not:
|
package/dist/import.js
CHANGED
|
@@ -26,6 +26,7 @@ import { REDACTED, secretCut, secretsIn } from "./secret-cut.js";
|
|
|
26
26
|
import { SECRET_NAMES, withSecrets } from "./secrets.js";
|
|
27
27
|
import { SEAL_KEY_ENV, ToolKeys } from "./tool-keys.js";
|
|
28
28
|
import { WEBHOOK_FILE, webhookSecretIn } from "./webhooks.js";
|
|
29
|
+
import { triggerSecretsIn } from "./trigger-secrets.js";
|
|
29
30
|
import { readWorkBytes, WorkRefused, walkWork } from "./workspace.js";
|
|
30
31
|
/** In the data directory while an import the owner asked for at setup has not ended: the server's next start goes on with it. */
|
|
31
32
|
export const IMPORT_ASKED = ".import-at-setup";
|
|
@@ -818,8 +819,8 @@ async function writeMeta(dir, session, read, json) {
|
|
|
818
819
|
await chmod(metaPath, 0o600);
|
|
819
820
|
}
|
|
820
821
|
/** The secrets this server made and keeps in data directory `data`, by value: its API token (`ar_local_...`) and its
|
|
821
|
-
* door token (server.ts), its sign-in sessions' secret (owner.ts)
|
|
822
|
-
* webhooks.ts), opened with the seal key of `env`, so left out when that key is not there. One pasted into a session is
|
|
822
|
+
* door token (server.ts), its sign-in sessions' secret (owner.ts), its webhook's signing secret (`whsec_...`;
|
|
823
|
+
* webhooks.ts) and each webhook trigger's (trigger-secrets.ts), opened with the seal key of `env`, so left out when that key is not there. One pasted into a session is
|
|
823
824
|
* this server's own, so an import cuts it wherever it is, as it cuts the environment's keys. Not among them: a run's own
|
|
824
825
|
* door token (one file a run; not read at each import), and a key-shaped value this server did not make (a `whsec_`
|
|
825
826
|
* from elsewhere). A webhook secret that does not open is said to `say`, as ToolKeys says a saved key that does not:
|
|
@@ -836,7 +837,7 @@ export function ownSecrets(data, env, say = () => { }) {
|
|
|
836
837
|
const webhook = webhookSecretIn(data, env);
|
|
837
838
|
if (webhook && "signing" in webhook)
|
|
838
839
|
say({ condition: webhook.signing, name: SEAL_KEY_ENV, file: join(data, WEBHOOK_FILE), effect: "this server's webhook secret cannot be read, so the import does not cut it" });
|
|
839
|
-
const values = [read(TOKEN_FILE), read(DOOR_TOKEN_FILE), read(SESSION_SECRET_FILE), webhook && "secret" in webhook ? webhook.secret : ""];
|
|
840
|
+
const values = [read(TOKEN_FILE), read(DOOR_TOKEN_FILE), read(SESSION_SECRET_FILE), webhook && "secret" in webhook ? webhook.secret : "", ...triggerSecretsIn(data, env)];
|
|
840
841
|
return [...new Set(values)].filter((value) => value.length >= 8 && !/\s/.test(value));
|
|
841
842
|
}
|
|
842
843
|
/** The plan, into `store`: the agents it does not hold, and the runs it does not. A run an earlier import made whose
|
package/dist/key-check.d.ts
CHANGED
|
@@ -28,9 +28,10 @@ export declare const KEY_CHECKS: Record<string, (key: string, env: NodeJS.Proces
|
|
|
28
28
|
* list models, which the 401 rule would refuse. */
|
|
29
29
|
export declare const NOT_CHECKED: Record<string, string>;
|
|
30
30
|
/** `row`'s key checked against its provider through `fetcher` (undefined: a faux server with no fake for it, so no call
|
|
31
|
-
* is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait.
|
|
31
|
+
* is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait. A refusal names the key as
|
|
32
|
+
* `name` (the server's own key, by its variable), else "this key" (the one a PUT sends). */
|
|
32
33
|
export declare function checkKey(row: {
|
|
33
34
|
id: string;
|
|
34
35
|
label: string;
|
|
35
|
-
}, key: string, env: NodeJS.ProcessEnv, fetcher: typeof fetch | undefined | null, ms?: number, stop?: AbortSignal): Promise<CheckOutcome>;
|
|
36
|
+
}, key: string, env: NodeJS.ProcessEnv, fetcher: typeof fetch | undefined | null, ms?: number, stop?: AbortSignal, name?: string): Promise<CheckOutcome>;
|
|
36
37
|
export {};
|
package/dist/key-check.js
CHANGED
|
@@ -29,6 +29,9 @@ export const KEY_CHECKS = {
|
|
|
29
29
|
// A list of the key's projects: Browserbase bills a session's browser time and proxy bandwidth, and this opens no
|
|
30
30
|
// session (https://docs.browserbase.com/reference/api/list-projects, https://docs.browserbase.com/account/billing/plans).
|
|
31
31
|
browserbase: (key, env) => ({ url: `${base(env.BROWSERBASE_BASE_URL, "https://api.browserbase.com")}/v1/projects`, headers: { "x-bb-api-key": key } }),
|
|
32
|
+
// A list of the key's browser sessions, one at most: Kernel bills a browser's running time, and this starts none
|
|
33
|
+
// (https://www.kernel.sh/docs/api-reference/browsers/list-browser-sessions, https://www.kernel.sh/docs/info/pricing).
|
|
34
|
+
kernel: (key, env) => ({ url: `${base(env.KERNEL_BASE_URL, "https://api.onkernel.com")}/browsers?limit=1`, headers: { authorization: `Bearer ${key}` } }),
|
|
32
35
|
// A list of the account's models: TypeSafe prices a System One request's input tokens
|
|
33
36
|
// (https://docs.typesafe.ai/api/list-models, https://docs.typesafe.ai/models).
|
|
34
37
|
typesafe: (key, env) => ({ url: `${base(env.TYPESAFE_BASE_URL, "https://api.typesafe.ai")}/v1/models`, headers: { authorization: `Bearer ${key}` } }),
|
|
@@ -65,8 +68,9 @@ function quoted(text, key) {
|
|
|
65
68
|
return sentence;
|
|
66
69
|
}
|
|
67
70
|
/** `row`'s key checked against its provider through `fetcher` (undefined: a faux server with no fake for it, so no call
|
|
68
|
-
* is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait.
|
|
69
|
-
|
|
71
|
+
* is made), in at most `ms`, and no longer than `stop` (the server closing) lets it wait. A refusal names the key as
|
|
72
|
+
* `name` (the server's own key, by its variable), else "this key" (the one a PUT sends). */
|
|
73
|
+
export async function checkKey(row, key, env, fetcher, ms = CHECK_MS, stop, name = "this key") {
|
|
70
74
|
const at = new Date().toISOString();
|
|
71
75
|
const notChecked = (reason) => ({ state: "not_checked", reason, at });
|
|
72
76
|
if (Object.hasOwn(NOT_CHECKED, row.id))
|
|
@@ -101,7 +105,7 @@ export async function checkKey(row, key, env, fetcher, ms = CHECK_MS, stop) {
|
|
|
101
105
|
// 401 whose body is cut off or stalls past the deadline still refuses the key.
|
|
102
106
|
const said = quoted(await res.text().catch(() => ""), key);
|
|
103
107
|
if (status === 401)
|
|
104
|
-
return { state: "refused", message: `${row.label} refused
|
|
108
|
+
return { state: "refused", message: `${row.label} refused ${name} (401${said ? `: ${said}` : ""})` };
|
|
105
109
|
if (status === 403)
|
|
106
110
|
return notChecked(`${row.label} would not answer the check (403${said ? `: ${said}` : ""}); the key may still work for its tools`);
|
|
107
111
|
return notChecked(`${row.label} answered ${status}${said ? ` (${said})` : ""}`);
|
package/dist/key-refusal.js
CHANGED
|
@@ -19,8 +19,8 @@ export function runKeyOf(env, harness = DEFAULT_HARNESS, ref) {
|
|
|
19
19
|
return row(provider === "openrouter" || openRouterOnly("claude-agent", env) ? "openrouter" : "anthropic");
|
|
20
20
|
if (env.AGENT_MODEL_BASE_URL)
|
|
21
21
|
return gateway;
|
|
22
|
-
if (harness === "codex")
|
|
23
|
-
return row(provider === "openrouter" || openRouterOnly(
|
|
22
|
+
if (harness === "codex" || harness === "opencode")
|
|
23
|
+
return row(provider === "openrouter" || openRouterOnly(harness, env) ? "openrouter" : "openai");
|
|
24
24
|
return provider === undefined ? undefined : row(provider);
|
|
25
25
|
}
|
|
26
26
|
/** The provider's own words after its 401: the message of the JSON it answered, else the text, its status word and any
|
|
@@ -112,8 +112,12 @@ export function redactedOutput(value, secrets) {
|
|
|
112
112
|
return redactedAnswer(value, secrets);
|
|
113
113
|
// A held value can be all digits (a gateway's key), and a record can quote it as a number: one whose digits hold a held
|
|
114
114
|
// value, by the same rule as a string's, is withheld as "[redacted]". A boolean's text is shorter than any held value.
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
// A number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy).
|
|
116
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
117
|
+
const text = String(value);
|
|
118
|
+
const held = redactedAnswer(text, secrets) !== text || secrets.some((secret) => secret.trim() !== "" && Number(secret) === Number(value));
|
|
119
|
+
return held ? "[redacted]" : value;
|
|
120
|
+
}
|
|
117
121
|
if (Array.isArray(value))
|
|
118
122
|
return value.map((item) => redactedOutput(item, secrets));
|
|
119
123
|
if (value && typeof value === "object") {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Each tool key a person may save, fixed here: its fields (BROWSERBASE_PROJECT_ID is no secret, and is kept the same
|
|
2
|
+
* way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision provider. */
|
|
3
|
+
export declare const TOOL_KEY_ROWS: readonly [{
|
|
4
|
+
readonly id: "parallel";
|
|
5
|
+
readonly kind: "tool";
|
|
6
|
+
readonly label: "Parallel";
|
|
7
|
+
readonly fields: readonly ["PARALLEL_API_KEY"];
|
|
8
|
+
readonly unlocks: readonly ["web_fetch", "web_search", "decisions.parallel"];
|
|
9
|
+
}, {
|
|
10
|
+
readonly id: "monid";
|
|
11
|
+
readonly kind: "tool";
|
|
12
|
+
readonly label: "Monid";
|
|
13
|
+
readonly fields: readonly ["MONID_API_KEY"];
|
|
14
|
+
readonly unlocks: readonly ["monid.discover", "monid.inspect", "monid.run"];
|
|
15
|
+
}, {
|
|
16
|
+
readonly id: "browserbase";
|
|
17
|
+
readonly kind: "tool";
|
|
18
|
+
readonly label: "Browserbase";
|
|
19
|
+
readonly fields: readonly ["BROWSERBASE_API_KEY", "BROWSERBASE_PROJECT_ID"];
|
|
20
|
+
readonly unlocks: readonly ["browser"];
|
|
21
|
+
}, {
|
|
22
|
+
readonly id: "kernel";
|
|
23
|
+
readonly kind: "tool";
|
|
24
|
+
readonly label: "Kernel";
|
|
25
|
+
readonly fields: readonly ["KERNEL_API_KEY"];
|
|
26
|
+
readonly unlocks: readonly ["browser"];
|
|
27
|
+
}, {
|
|
28
|
+
readonly id: "typesafe";
|
|
29
|
+
readonly kind: "tool";
|
|
30
|
+
readonly label: "TypeSafe (Jev)";
|
|
31
|
+
readonly fields: readonly ["TYPESAFE_API_KEY"];
|
|
32
|
+
readonly unlocks: readonly ["decisions.jev"];
|
|
33
|
+
}];
|
|
34
|
+
/** What `vars` (the variables a tool needs that this server does not hold) are, as a person fixes them: each savable
|
|
35
|
+
* key's "a <Label> key: save one in Settings → Tool keys (or set <VARS> where the server starts)", then any variable no
|
|
36
|
+
* key saves, to set where the server starts. */
|
|
37
|
+
export declare function keyNeeded(vars: readonly string[]): string;
|