@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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 +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +69 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- 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 +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- 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 +24 -0
- package/dist/turn-end.js +15 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +189 -0
- package/dist/webhooks.js +503 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export declare const HARNESSES: readonly ["pi", "claude-agent", "codex", "opencode"];
|
|
2
|
+
export type HarnessId = (typeof HARNESSES)[number];
|
|
3
|
+
export declare const DEFAULT_HARNESS: HarnessId;
|
|
4
|
+
/** The memory one run of each harness reserves while its process lives, in MiB: what admission counts (host.ts).
|
|
5
|
+
* Measured 2026-11-03 on 529c3882e with the pinned binaries' sha256 checked a chunk at a time, not read whole: a
|
|
6
|
+
* real server in a cgroup of its own (MemoryMax 2048M, no swap), models on a loopback stand-in, one agent with read
|
|
7
|
+
* and write asked to write a file, read it back and answer; the cgroup's anon (memory.stat) sampled every 100 ms. A
|
|
8
|
+
* run's size is (the most anon with the runs going − the server's own after boot) / n, for n = 1 and n = 3, twice
|
|
9
|
+
* each, and the largest of the four is kept. The server's own growth while it serves the runs is in it.
|
|
10
|
+
* pi: n=1 106, 106; n=3 96, 99 MB a run → 128 (+21%)
|
|
11
|
+
* codex: n=1 132, 143; n=3 120, 131 MB a run → 192 (+34%)
|
|
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)
|
|
16
|
+
* The margin covers a longer conversation than the probe's three steps; the CLI harnesses (codex, claude-agent) grow
|
|
17
|
+
* more with one, so theirs is larger. At a 512M limit the same build completed pi x3, codex x2 and claude-agent x1
|
|
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
|
|
19
|
+
* for the claude-agent CLI), and these sizes do not cover it. The faux model and the faux
|
|
20
|
+
* harness reserve the size of the harness they stand in for, so tests admit as a real server does. */
|
|
21
|
+
export declare const RUN_MIB: Readonly<Record<HarnessId, number>>;
|
|
22
|
+
/** One harness as capabilities lists it: whether this server runs it, and when not, why; and whether it takes a message
|
|
23
|
+
* mid-turn (`steer`), or queues it for the turn's end. */
|
|
24
|
+
/** `default_model`: the model this server runs for the harness when a definition names none (`provider/model-id`), or
|
|
25
|
+
* null when it runs none there; harnessOffers sets it. `keys`, on one unavailable only for want of a model key: the keys
|
|
26
|
+
* any one of which, saved, lets it run here, so a key's row names it before it is saved (tool-keys.ts' rowUnlocks).
|
|
27
|
+
* The server's own: capabilities never serve it. */
|
|
28
|
+
export type HarnessOffer = {
|
|
29
|
+
id: HarnessId;
|
|
30
|
+
available: boolean;
|
|
31
|
+
steer: boolean;
|
|
32
|
+
reason?: string;
|
|
33
|
+
default_model?: string | null;
|
|
34
|
+
keys?: readonly string[];
|
|
35
|
+
};
|
|
36
|
+
/** A harness as capabilities list it: an offer with its `default_model` resolved (harnessOffers), never left out, and
|
|
37
|
+
* the memory a run of it reserves (`run_memory_mib`). */
|
|
38
|
+
export type HarnessCapability = HarnessOffer & {
|
|
39
|
+
default_model: string | null;
|
|
40
|
+
run_memory_mib: number;
|
|
41
|
+
};
|
|
42
|
+
/** Whether a harness takes a message mid-turn: pi does; another harness's run queues it for the turn's end. */
|
|
43
|
+
export declare const steersMidTurn: (id: string) => boolean;
|
|
44
|
+
/** A module whose `script(spec)` scripts run-adapters' faux harness: with it, every harness but pi runs on that faux
|
|
45
|
+
* harness, as `--faux` runs pi on the faux model. */
|
|
46
|
+
export declare const FAUX_HARNESS_ENV = "AGENTRUN_SERVE_FAUX_HARNESS";
|
|
47
|
+
/** What this server offers of each harness. */
|
|
48
|
+
export declare function harnessesOf(env: NodeJS.ProcessEnv): HarnessOffer[];
|
|
49
|
+
/** What this server offers of each harness, checked once per environment: each adapter's package, pins and endpoint,
|
|
50
|
+
* on a model of the harness's own provider (adapters.ts), and whether one of its runs fits in this host's memory at all
|
|
51
|
+
* (host.ts). Whether a revision's model fits its harness is that revision's (runnable.ts). */
|
|
52
|
+
export declare function harnessOffers(env: NodeJS.ProcessEnv): Promise<HarnessCapability[]>;
|
|
53
|
+
/** The harness a stored body names, as answers show it. */
|
|
54
|
+
export declare const harnessOfBody: (body: {
|
|
55
|
+
harness?: string;
|
|
56
|
+
}) => string;
|
package/dist/harness.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The harness that runs a revision: pi (pi-durable-disk's, the default and the one a revision that names none gets) or
|
|
2
|
+
// one of the run adapters. A revision keeps the harness it names; the default is never stored, so a revision written
|
|
3
|
+
// before this field existed and one that names pi are the same revision. Which harnesses this server runs is said in
|
|
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", "opencode"];
|
|
6
|
+
export const DEFAULT_HARNESS = "pi";
|
|
7
|
+
/** The memory one run of each harness reserves while its process lives, in MiB: what admission counts (host.ts).
|
|
8
|
+
* Measured 2026-11-03 on 529c3882e with the pinned binaries' sha256 checked a chunk at a time, not read whole: a
|
|
9
|
+
* real server in a cgroup of its own (MemoryMax 2048M, no swap), models on a loopback stand-in, one agent with read
|
|
10
|
+
* and write asked to write a file, read it back and answer; the cgroup's anon (memory.stat) sampled every 100 ms. A
|
|
11
|
+
* run's size is (the most anon with the runs going − the server's own after boot) / n, for n = 1 and n = 3, twice
|
|
12
|
+
* each, and the largest of the four is kept. The server's own growth while it serves the runs is in it.
|
|
13
|
+
* pi: n=1 106, 106; n=3 96, 99 MB a run → 128 (+21%)
|
|
14
|
+
* codex: n=1 132, 143; n=3 120, 131 MB a run → 192 (+34%)
|
|
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)
|
|
19
|
+
* The margin covers a longer conversation than the probe's three steps; the CLI harnesses (codex, claude-agent) grow
|
|
20
|
+
* more with one, so theirs is larger. At a 512M limit the same build completed pi x3, codex x2 and claude-agent x1
|
|
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
|
|
22
|
+
* for the claude-agent CLI), and these sizes do not cover it. The faux model and the faux
|
|
23
|
+
* harness reserve the size of the harness they stand in for, so tests admit as a real server does. */
|
|
24
|
+
export const RUN_MIB = { pi: 128, "claude-agent": 288, codex: 192, opencode: 704 };
|
|
25
|
+
/** Whether a harness takes a message mid-turn: pi does; another harness's run queues it for the turn's end. */
|
|
26
|
+
export const steersMidTurn = (id) => id === DEFAULT_HARNESS;
|
|
27
|
+
/** A module whose `script(spec)` scripts run-adapters' faux harness: with it, every harness but pi runs on that faux
|
|
28
|
+
* harness, as `--faux` runs pi on the faux model. */
|
|
29
|
+
export const FAUX_HARNESS_ENV = "AGENTRUN_SERVE_FAUX_HARNESS";
|
|
30
|
+
/** What this server offers of each harness. */
|
|
31
|
+
export function harnessesOf(env) {
|
|
32
|
+
return HARNESSES.map((id) => (id === DEFAULT_HARNESS || env[FAUX_HARNESS_ENV] ? { id, available: true, steer: steersMidTurn(id) } : { id, available: false, steer: steersMidTurn(id), reason: `This server does not run ${id} yet.` }));
|
|
33
|
+
}
|
|
34
|
+
const offered = new WeakMap();
|
|
35
|
+
/** What this server offers of each harness, checked once per environment: each adapter's package, pins and endpoint,
|
|
36
|
+
* on a model of the harness's own provider (adapters.ts), and whether one of its runs fits in this host's memory at all
|
|
37
|
+
* (host.ts). Whether a revision's model fits its harness is that revision's (runnable.ts). */
|
|
38
|
+
export function harnessOffers(env) {
|
|
39
|
+
let offers = offered.get(env);
|
|
40
|
+
if (!offers) {
|
|
41
|
+
offers = (async () => {
|
|
42
|
+
const { hostMemory, neverFits } = await import("./host.js");
|
|
43
|
+
const memory = hostMemory();
|
|
44
|
+
const probed = env[FAUX_HARNESS_ENV] ? harnessesOf(env) : await (async () => {
|
|
45
|
+
const { harnessRefusal } = await import("./adapters.js");
|
|
46
|
+
return Promise.all(HARNESSES.map(async (id) => {
|
|
47
|
+
if (id === DEFAULT_HARNESS)
|
|
48
|
+
return { id, available: true, steer: true };
|
|
49
|
+
// The start's probe: these offers hold until a restart (server.ts), so the reason says so where installing fixes it.
|
|
50
|
+
const refused = await harnessRefusal(id, env, undefined, { atStart: true });
|
|
51
|
+
return refused === undefined ? { id, available: true, steer: steersMidTurn(id) } : { id, available: false, steer: steersMidTurn(id), ...refused };
|
|
52
|
+
}));
|
|
53
|
+
})();
|
|
54
|
+
// A harness that runs here but whose one run is more than this host's memory for runs never starts: said here, so
|
|
55
|
+
// 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
|
|
56
|
+
// key keeps its reason, but no key would run it: it has no `keys`.
|
|
57
|
+
const base = probed.map((offer) => {
|
|
58
|
+
const tooBig = offer.available || offer.keys ? neverFits(offer.id, memory) : undefined;
|
|
59
|
+
if (!tooBig)
|
|
60
|
+
return offer;
|
|
61
|
+
const { keys: _keys, ...rest } = offer;
|
|
62
|
+
return offer.available ? { ...rest, available: false, reason: tooBig } : rest;
|
|
63
|
+
});
|
|
64
|
+
// Each harness's model when a definition names none, as a save and a run resolve it (runnable.ts): none for a
|
|
65
|
+
// harness that does not run here, or that no model here would run on.
|
|
66
|
+
const { harnessModel } = await import("./runnable.js");
|
|
67
|
+
return Promise.all(base.map(async (offer) => {
|
|
68
|
+
const resolved = offer.available ? await harnessModel(env, offer.id, undefined, true) : undefined;
|
|
69
|
+
return { ...offer, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, run_memory_mib: RUN_MIB[offer.id] };
|
|
70
|
+
}));
|
|
71
|
+
})();
|
|
72
|
+
offered.set(env, offers);
|
|
73
|
+
}
|
|
74
|
+
return offers;
|
|
75
|
+
}
|
|
76
|
+
/** The harness a stored body names, as answers show it. */
|
|
77
|
+
export const harnessOfBody = (body) => body.harness ?? DEFAULT_HARNESS;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BigIntStats } from "node:fs";
|
|
2
|
+
import { ApiError } from "./errors.js";
|
|
3
|
+
/** A file path as the URL sends it, each segment percent-decoded. */
|
|
4
|
+
export declare function decodedPath(raw: string): string;
|
|
5
|
+
/** `rel`, refused unless it is a relative path of names; a segment that starts with . is `own`'s. */
|
|
6
|
+
export declare function checkedPath(rel: string, own: string): string;
|
|
7
|
+
/** `name` as a disk that folds names could take it: its compatibility form, upper then lower case, and without combining
|
|
8
|
+
* marks, so ı, İ, ſ, the Kelvin sign and fullwidth letters fold as the ASCII letters they stand for. */
|
|
9
|
+
export declare const foldName: (name: string) => string;
|
|
10
|
+
/** The name of `owned` that `path` is at or under, if any: its first segment, on the path as normalized, folded. */
|
|
11
|
+
export declare function ownedBy(owned: readonly string[], path: string): string | undefined;
|
|
12
|
+
/** The host-owned path of the home that `path` is at or under, if any (files.ts HOME_HOST_OWNED). */
|
|
13
|
+
export declare const hostOwnedOf: (path: string) => string | undefined;
|
|
14
|
+
/** Where this server serves a host-owned path of a home to read, when it does: `/v2/agents/{id}/learning`, the learning
|
|
15
|
+
* API, which redacts its notes. */
|
|
16
|
+
export type OwnedReadAt = (owned: string) => string | undefined;
|
|
17
|
+
/** The refusal of a read, write or delete at or under the host-owned path `owned`: never raw here. A read names the
|
|
18
|
+
* route that serves it (`readAt`) only when this server has one, so it never points at a 404. */
|
|
19
|
+
export declare function hostOwnedRefusal(owned: string, agentId: string, write: boolean, readAt?: OwnedReadAt): ApiError;
|
|
20
|
+
/** A path in an agent's home as its routes take it, checked as a run's file path is, made of plain segments, and at most
|
|
21
|
+
* 1024 characters with no segment over 255 bytes. Anything at or under a host-owned path is refused, read or written,
|
|
22
|
+
* so `./learning/x`, `a/../LeArNiNg/x` and `Learning/x` are refused as learning/ is; and a write goes no deeper than the
|
|
23
|
+
* list does. */
|
|
24
|
+
export declare function homePath(raw: string, agentId: string, write: boolean, readAt?: OwnedReadAt): string;
|
|
25
|
+
/** The host-owned path of `home` that the first segment of `rel` (a path homePath took) is on this disk, if any: both
|
|
26
|
+
* there, and one entry. A disk that takes another spelling for a host-owned name answers so, whatever the spelling. */
|
|
27
|
+
export declare function ownedByIdentity(home: string, rel: string, owned?: readonly string[], stat?: (path: string) => Promise<Pick<BigIntStats, "dev" | "ino"> | null>): Promise<string | undefined>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
2
|
+
import { join, posix } from "node:path";
|
|
3
|
+
import { ApiError } from "./errors.js";
|
|
4
|
+
import { HOME_HOST_OWNED } from "./files.js";
|
|
5
|
+
import { WALK_DEPTH } from "./workspace.js";
|
|
6
|
+
/** A file path as the URL sends it, each segment percent-decoded. */
|
|
7
|
+
export function decodedPath(raw) {
|
|
8
|
+
try {
|
|
9
|
+
return raw.split("/").map(decodeURIComponent).join("/");
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
throw new ApiError("invalid_file_path", "the path is not percent-encoded right");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** `rel`, refused unless it is a relative path of names; a segment that starts with . is `own`'s. */
|
|
16
|
+
export function checkedPath(rel, own) {
|
|
17
|
+
const parts = rel.split("/");
|
|
18
|
+
if (!rel || rel.startsWith("/") || rel.includes("\\") || rel.includes("\0") || parts.some((p) => p === "" || p === "." || p === ".."))
|
|
19
|
+
throw new ApiError("invalid_file_path", "the path has an empty, . or .. segment, a backslash, a NUL or a leading /");
|
|
20
|
+
if (parts.some((p) => p.startsWith(".")))
|
|
21
|
+
throw new ApiError("system_file_forbidden", `a path segment that starts with . is ${own}`);
|
|
22
|
+
return rel;
|
|
23
|
+
}
|
|
24
|
+
const IGNORABLE = /\p{Default_Ignorable_Code_Point}/u;
|
|
25
|
+
/** Whether `segment` is plain text: its own NFC form, with no default-ignorable code point. A disk may take two
|
|
26
|
+
* spellings that differ only in such code points for one name; a plain segment is the one spelling. */
|
|
27
|
+
const plainSegment = (segment) => segment === segment.normalize("NFC") && !IGNORABLE.test(segment);
|
|
28
|
+
const MARKS = /\p{M}/gu;
|
|
29
|
+
/** `name` as a disk that folds names could take it: its compatibility form, upper then lower case, and without combining
|
|
30
|
+
* marks, so ı, İ, ſ, the Kelvin sign and fullwidth letters fold as the ASCII letters they stand for. */
|
|
31
|
+
export const foldName = (name) => name.normalize("NFKC").toUpperCase().toLowerCase().normalize("NFD").replace(MARKS, "");
|
|
32
|
+
/** The name of `owned` that `path` is at or under, if any: its first segment, on the path as normalized, folded. */
|
|
33
|
+
export function ownedBy(owned, path) {
|
|
34
|
+
const first = foldName(posix.normalize(path).replace(/^\/+/, "").split("/")[0]);
|
|
35
|
+
return owned.find((name) => foldName(name) === first);
|
|
36
|
+
}
|
|
37
|
+
/** The host-owned path of the home that `path` is at or under, if any (files.ts HOME_HOST_OWNED). */
|
|
38
|
+
export const hostOwnedOf = (path) => ownedBy(HOME_HOST_OWNED, path);
|
|
39
|
+
/** The refusal of a read, write or delete at or under the host-owned path `owned`: never raw here. A read names the
|
|
40
|
+
* route that serves it (`readAt`) only when this server has one, so it never points at a 404. */
|
|
41
|
+
export function hostOwnedRefusal(owned, agentId, write, readAt) {
|
|
42
|
+
const route = readAt?.(owned);
|
|
43
|
+
const message = write ? `${owned}/ is written by the server, not through the API` : route ? `the server keeps ${owned}/ for itself: read it through ${route}` : `the server keeps ${owned}/ for itself; this server has no ${owned} API yet`;
|
|
44
|
+
return new ApiError("system_file_forbidden", message, { details: { reason: "host_owned" } });
|
|
45
|
+
}
|
|
46
|
+
/** A path in an agent's home as its routes take it, checked as a run's file path is, made of plain segments, and at most
|
|
47
|
+
* 1024 characters with no segment over 255 bytes. Anything at or under a host-owned path is refused, read or written,
|
|
48
|
+
* so `./learning/x`, `a/../LeArNiNg/x` and `Learning/x` are refused as learning/ is; and a write goes no deeper than the
|
|
49
|
+
* list does. */
|
|
50
|
+
export function homePath(raw, agentId, write, readAt) {
|
|
51
|
+
const rel = decodedPath(raw);
|
|
52
|
+
if (!rel.split("/").every(plainSegment))
|
|
53
|
+
throw new ApiError("invalid_file_path", "a path segment must be plain text (NFC, no invisible characters)");
|
|
54
|
+
const owned = hostOwnedOf(rel);
|
|
55
|
+
if (owned)
|
|
56
|
+
throw hostOwnedRefusal(owned, agentId, write, readAt);
|
|
57
|
+
checkedPath(rel, "the server's own, not a file of the home");
|
|
58
|
+
if (rel.length > 1024 || rel.split("/").some((p) => Buffer.byteLength(p) > 255))
|
|
59
|
+
throw new ApiError("invalid_file_path", "the path is over 1024 characters, or a segment of it over 255 bytes");
|
|
60
|
+
if (write && rel.split("/").length - 1 > WALK_DEPTH)
|
|
61
|
+
throw new ApiError("invalid_file_path", `a file is written at most ${WALK_DEPTH} directories deep, as deep as the list goes`);
|
|
62
|
+
return rel;
|
|
63
|
+
}
|
|
64
|
+
/** Whether two stats are of one entry on disk: the same device and inode. */
|
|
65
|
+
const sameEntry = (a, b) => a.dev === b.dev && a.ino === b.ino;
|
|
66
|
+
/** The host-owned path of `home` that the first segment of `rel` (a path homePath took) is on this disk, if any: both
|
|
67
|
+
* there, and one entry. A disk that takes another spelling for a host-owned name answers so, whatever the spelling. */
|
|
68
|
+
export async function ownedByIdentity(home, rel, owned = HOME_HOST_OWNED, stat = (path) => lstat(path, { bigint: true }).catch(() => null)) {
|
|
69
|
+
const first = await stat(join(home, rel.split("/")[0]));
|
|
70
|
+
if (!first)
|
|
71
|
+
return undefined;
|
|
72
|
+
for (const name of owned) {
|
|
73
|
+
const entry = await stat(join(home, name));
|
|
74
|
+
if (entry && sameEntry(first, entry))
|
|
75
|
+
return name;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
4
|
+
import type { DurableRun } from "@parcha/pi-durable-disk";
|
|
5
|
+
import type { Park, RunGate } from "./tool-gate.js";
|
|
6
|
+
export { workspaceRelative } from "./workspace-paths.js";
|
|
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. */
|
|
10
|
+
export declare const REPLAY: Record<string, "safe" | "never">;
|
|
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
|
|
12
|
+
* head and bash's tail are held to them (the host-bounds test reads pi's own words for them). */
|
|
13
|
+
export declare const MAX_BYTES: number;
|
|
14
|
+
export declare const MAX_LINES = 2000;
|
|
15
|
+
/** `bytes` (UTF-8) cut to at most `max` bytes, its tail or its head, at a character boundary: a character the limit
|
|
16
|
+
* would split is left out whole, so the text never ends or starts in a U+FFFD. */
|
|
17
|
+
export declare function cutUtf8(bytes: Uint8Array, max: number, tail: boolean): Uint8Array;
|
|
18
|
+
/** One call's result, kept by its call id for the run's timeline (an adapter's tool_end carries none). */
|
|
19
|
+
export type ToolResults = Map<string, {
|
|
20
|
+
text: string;
|
|
21
|
+
isError: boolean;
|
|
22
|
+
}>;
|
|
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[];
|