@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48
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 +211 -1
- package/NOTICE +4 -0
- package/README.md +350 -53
- package/dist/acp-package.d.ts +53 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +3 -4
- package/dist/adapter-facts.js +4 -4
- package/dist/adapters.d.ts +3 -5
- package/dist/adapters.js +1 -31
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/answer-json.d.ts +10 -0
- package/dist/answer-json.js +24 -0
- package/dist/api-only.d.ts +11 -11
- package/dist/api-only.js +16 -11
- package/dist/archil-routes.js +2 -1
- package/dist/browser-live.d.ts +9 -4
- package/dist/browser-live.js +18 -5
- package/dist/cap.js +10 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +109 -41
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-routes.d.ts +8 -5
- package/dist/computer-routes.js +7 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +14 -76
- package/dist/computers.js +24 -68
- package/dist/conformance.d.ts +4 -0
- package/dist/conformance.js +6 -0
- package/dist/console/assets/index-CTGegcKt.css +1 -0
- package/dist/console/assets/index-D1Se6mgG.js +715 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +75 -0
- package/dist/harness-check.js +518 -0
- package/dist/harness-cursor.d.ts +28 -0
- package/dist/harness-cursor.js +42 -0
- package/dist/harness-goose.d.ts +4 -29
- package/dist/harness-goose.js +6 -86
- package/dist/harness-module.d.ts +4 -0
- package/dist/harness-module.js +1 -0
- package/dist/harness-owned.d.ts +52 -0
- package/dist/harness-owned.js +92 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +335 -0
- package/dist/harness-table.d.ts +120 -5
- package/dist/harness-table.js +280 -6
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +5 -4
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +24 -4
- package/dist/import.js +108 -26
- package/dist/key-refusal.d.ts +3 -1
- package/dist/key-refusal.js +26 -5
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +12 -5
- package/dist/learn/promote.d.ts +80 -2
- package/dist/learn/promote.js +95 -3
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +23 -0
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-model.d.ts +18 -0
- package/dist/learning-model.js +77 -0
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +2 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +30 -16
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +5 -3
- package/dist/model.js +26 -18
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +356 -43
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +9 -0
- package/dist/page.js +10 -2
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +7 -4
- package/dist/run-trace.js +6 -3
- package/dist/runner/adapter-loop.d.ts +14 -8
- package/dist/runner/adapter-loop.js +58 -24
- package/dist/runner/adapter-run-spec.d.ts +15 -2
- package/dist/runner/adapter-run-spec.js +48 -10
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +6 -26
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +15 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +22 -10
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/conformance/host-tools.d.ts +4 -0
- package/dist/runner/conformance/host-tools.js +14 -0
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +62 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/meta-tools.js +4 -2
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +44 -0
- package/dist/runner/presence.js +96 -0
- package/dist/runner/promotion.d.ts +70 -7
- package/dist/runner/promotion.js +178 -28
- package/dist/runner/run-child-host.js +40 -10
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/sdk-loop.js +25 -1
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +12 -4
- package/dist/sdk/check.d.ts +31 -0
- package/dist/sdk/check.js +58 -0
- package/dist/sdk/runs.d.ts +11 -3
- package/dist/sdk/runs.js +90 -15
- package/dist/sdk/schema.js +12 -4
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +34 -2
- package/dist/server.js +437 -90
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +112 -28
- package/dist/store/store.d.ts +78 -24
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +125 -14
- package/dist/store-view.js +156 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/template-eval.js +5 -2
- package/dist/template-github-permissions.d.ts +5 -1
- package/dist/template-github-permissions.js +7 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/timeline/timeline.js +30 -0
- package/dist/tool-gate.d.ts +8 -4
- package/dist/tool-gate.js +6 -7
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.d.ts +4 -0
- package/dist/tool-plane.js +12 -12
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +12 -3
- package/dist/trigger-targets.js +90 -10
- package/dist/triggers.d.ts +2 -2
- package/dist/validate.js +5 -1
- package/dist/viewer-credential.d.ts +25 -0
- package/dist/viewer-credential.js +51 -0
- package/dist/webhooks.d.ts +82 -8
- package/dist/webhooks.js +128 -45
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +23 -14
- package/dist/workspace/resolve-computer.js +66 -61
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +18 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/templates/code-review/agent.md +2 -3
- package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
- package/templates/code-review/evals/other-repo/case.yaml +0 -1
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// A harness recipe (HARNESS.md#a-recipe): the one loader, refusing by RECIPE_CODES before anything is downloaded.
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
5
|
+
import { HARNESS_ID_PATTERN, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
6
|
+
import { ARCHIVE_FORMATS, archivePlatform, installArchive } from "./harness-archive.js";
|
|
7
|
+
import { BUILTIN_HARNESS_IDS } from "./harness-table.js";
|
|
8
|
+
import { commandData } from "./harness-owned.js";
|
|
9
|
+
import { harnessesOf, installDirOf, shellWord } from "./harness-install.js";
|
|
10
|
+
import { keyShaped } from "./secret-name.js";
|
|
11
|
+
import { SECRET_NAMES } from "./secrets.js";
|
|
12
|
+
/** The codes a refused recipe carries, one per rule, and one for a file that is not a recipe at all. */
|
|
13
|
+
export const RECIPE_CODES = Object.freeze({
|
|
14
|
+
/** Not JSON, not an object, or a field missing, of the wrong type, or unknown. */
|
|
15
|
+
invalid: "RECIPE_INVALID",
|
|
16
|
+
/** Rule 1: a key that is not the harness's own. */
|
|
17
|
+
keys: "RECIPE_KEY_NOT_OWN",
|
|
18
|
+
/** Rule 2: a binary that is not a registry archive pinned by its sha256. */
|
|
19
|
+
binary: "RECIPE_BINARY_UNPINNED",
|
|
20
|
+
/** Rule 3: a file, a state folder or the binary outside its private place. */
|
|
21
|
+
paths: "RECIPE_PATH_OUTSIDE",
|
|
22
|
+
/** Rule 4: an install step of the recipe's own. */
|
|
23
|
+
install: "RECIPE_INSTALLS_ITSELF",
|
|
24
|
+
/** Rule 5: an environment beyond the allowlist and the recipe's own literal values. */
|
|
25
|
+
env: "RECIPE_ENV_NOT_ALLOWLIST",
|
|
26
|
+
});
|
|
27
|
+
/** The variables a proxy-billed agent may read the proxy's address from: Goose's, and the Anthropic SDKs'. */
|
|
28
|
+
export const PROXY_HOST_ENVS = Object.freeze(["ANTHROPIC_HOST", "ANTHROPIC_BASE_URL"]);
|
|
29
|
+
/** The variables the agent's environment gets from the adapter and the model proxy, never from a recipe, by part: what
|
|
30
|
+
* it takes from the host (`inherited`, run-adapters-acp's INHERITED_ENV), what the adapter sets for the private HOME
|
|
31
|
+
* (`reserved`, its RESERVED_ENV), and the proxy's address and key (`proxy`). The loader refuses a recipe that names one;
|
|
32
|
+
* the check's env_allowlist expects each. */
|
|
33
|
+
export const AGENT_VARS = Object.freeze({
|
|
34
|
+
inherited: Object.freeze(["PATH", "LANG", "TZ"]),
|
|
35
|
+
reserved: Object.freeze(["HOME", "TMPDIR", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME", "GIT_CEILING_DIRECTORIES"]),
|
|
36
|
+
proxy: Object.freeze([...PROXY_HOST_ENVS, "ANTHROPIC_API_KEY"]),
|
|
37
|
+
});
|
|
38
|
+
/** A host a plan-billed agent's vendor is on, as model.hosts names it: a lowercase host name, with an optional port. */
|
|
39
|
+
const VENDOR_HOST = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::([1-9][0-9]{0,4}))?$/;
|
|
40
|
+
const vendorHost = (host) => {
|
|
41
|
+
const port = VENDOR_HOST.exec(host)?.[1];
|
|
42
|
+
return VENDOR_HOST.test(host) && (port === undefined || Number(port) <= 65535);
|
|
43
|
+
};
|
|
44
|
+
/** A recipe the loader refused: `code` is the first problem's, and the message says every one. */
|
|
45
|
+
export class RecipeRefused extends Error {
|
|
46
|
+
code;
|
|
47
|
+
problems;
|
|
48
|
+
constructor(code, problems) {
|
|
49
|
+
super(`${code}: ${problems.map((p) => (p.code === code ? p.words : `${p.code}: ${p.words}`)).join("; ")}`);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.problems = problems;
|
|
52
|
+
this.name = "RecipeRefused";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** The fields a recipe has. */
|
|
56
|
+
const FIELDS = new Set(["id", "label", "release", "args", "keys", "env", "model", "files", "state", "declares", "quirks", "description", "$schema"]);
|
|
57
|
+
/** Fields that would run something of the recipe's own at install or start (rule 4). */
|
|
58
|
+
const INSTALL_FIELDS = new Set(["install", "installCommand", "postinstall", "preinstall", "setup", "script", "scripts", "run", "hooks", "update"]);
|
|
59
|
+
/** Fields that would name a binary other than the release's archive (rule 2). */
|
|
60
|
+
const BINARY_FIELDS = new Set(["command", "binary", "path", "bin", "executable", "exec"]);
|
|
61
|
+
/** Fields that would pass the host's environment through (rule 5). */
|
|
62
|
+
const ENV_FIELDS = new Set(["inheritEnv", "passEnv", "envFrom", "inherit", "envPassthrough", "passthroughEnv"]);
|
|
63
|
+
/** Every variable of AGENT_VARS. */
|
|
64
|
+
const SET_BY_ADAPTER = new Set(Object.values(AGENT_VARS).flat());
|
|
65
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
66
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
67
|
+
const ARCHIVE_FIELDS = new Set(["url", "format", "sha256", "cmd", "binarySha256"]);
|
|
68
|
+
/** A value the host would fill in from its own environment: `$NAME` or `${NAME}`. */
|
|
69
|
+
const EXPANDS = /\$(?:\{[^}]*\}|[A-Za-z_])/;
|
|
70
|
+
/** Whether `name` is a key the server holds for anything but this harness: the launcher's secrets (model providers, the
|
|
71
|
+
* gateway, tools, computers, serve's own) and every AGENTRUN_ and AGENT_MODEL_ name. */
|
|
72
|
+
export const serverKey = (name) => SECRET_NAMES.includes(name) || name.startsWith("AGENTRUN_") || name.startsWith("AGENT_MODEL_");
|
|
73
|
+
/** `path` inside HOME, or undefined when it leaves it (absolute, `..`, or empty); a `$HOME/` prefix is HOME. */
|
|
74
|
+
export function insideHome(path) {
|
|
75
|
+
const bare = path.startsWith("$HOME/") ? path.slice("$HOME/".length) : path;
|
|
76
|
+
if (!bare || isAbsolute(bare))
|
|
77
|
+
return undefined;
|
|
78
|
+
const clean = normalize(bare);
|
|
79
|
+
if (clean === "." || clean === ".." || clean.startsWith(`..${sep}`))
|
|
80
|
+
return undefined;
|
|
81
|
+
return clean;
|
|
82
|
+
}
|
|
83
|
+
const isPlain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
84
|
+
const strings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
85
|
+
/** Every problem with `parsed` as a recipe, by its rule's code. */
|
|
86
|
+
export function recipeProblems(parsed) {
|
|
87
|
+
const problems = [];
|
|
88
|
+
const say = (code, words) => problems.push({ code, words });
|
|
89
|
+
if (!isPlain(parsed))
|
|
90
|
+
return [{ code: RECIPE_CODES.invalid, words: "a recipe is a JSON object" }];
|
|
91
|
+
const r = parsed;
|
|
92
|
+
for (const field of Object.keys(r)) {
|
|
93
|
+
if (FIELDS.has(field))
|
|
94
|
+
continue;
|
|
95
|
+
if (INSTALL_FIELDS.has(field))
|
|
96
|
+
say(RECIPE_CODES.install, `"${field}": a recipe runs no install step of its own; its owner installs its release with agentrun harness install --recipe`);
|
|
97
|
+
else if (BINARY_FIELDS.has(field))
|
|
98
|
+
say(RECIPE_CODES.binary, `"${field}": a recipe names no binary of its own; the binary is its release's archive, pinned by sha256`);
|
|
99
|
+
else if (ENV_FIELDS.has(field))
|
|
100
|
+
say(RECIPE_CODES.env, `"${field}": the agent's environment is an allowlist; name each variable and its value in env`);
|
|
101
|
+
else
|
|
102
|
+
say(RECIPE_CODES.invalid, `"${field}" is not a recipe field`);
|
|
103
|
+
}
|
|
104
|
+
const idPattern = new RegExp(HARNESS_ID_PATTERN);
|
|
105
|
+
if (typeof r.id !== "string" || !idPattern.test(r.id))
|
|
106
|
+
say(RECIPE_CODES.invalid, `id must match ${HARNESS_ID_PATTERN}`);
|
|
107
|
+
else if (BUILTIN_HARNESS_IDS.includes(r.id) || RESERVED_HARNESS_IDS.includes(r.id))
|
|
108
|
+
say(RECIPE_CODES.invalid, `id ${r.id} is a harness AgentRun already has, or a name its runs carry; give yours its own`);
|
|
109
|
+
if (typeof r.label !== "string" || !r.label.trim() || r.label.length > 80)
|
|
110
|
+
say(RECIPE_CODES.invalid, "label is the harness's name in a sentence, 1 to 80 characters");
|
|
111
|
+
// Rule 2: the release.
|
|
112
|
+
const release = r.release;
|
|
113
|
+
if (!isPlain(release))
|
|
114
|
+
say(RECIPE_CODES.binary, "release names the agent's registry id, its version and an archive per platform with its sha256");
|
|
115
|
+
else {
|
|
116
|
+
for (const field of Object.keys(release))
|
|
117
|
+
if (!["registry", "version", "archives"].includes(field))
|
|
118
|
+
say(BINARY_FIELDS.has(field) ? RECIPE_CODES.binary : INSTALL_FIELDS.has(field) ? RECIPE_CODES.install : RECIPE_CODES.invalid, `release.${field} is not a release field`);
|
|
119
|
+
if (typeof release.registry !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(release.registry))
|
|
120
|
+
say(RECIPE_CODES.invalid, "release.registry is the agent's id in the ACP registry");
|
|
121
|
+
if (typeof release.version !== "string" || !/^[0-9A-Za-z][0-9A-Za-z.+_-]{0,63}$/.test(release.version))
|
|
122
|
+
say(RECIPE_CODES.invalid, "release.version is the registry's version string");
|
|
123
|
+
if (!isPlain(release.archives) || !Object.keys(release.archives).length)
|
|
124
|
+
say(RECIPE_CODES.binary, "release.archives names at least one platform's archive (linux-x86_64, darwin-aarch64, ...)");
|
|
125
|
+
else {
|
|
126
|
+
for (const [platform, archive] of Object.entries(release.archives)) {
|
|
127
|
+
const at = `release.archives["${platform}"]`;
|
|
128
|
+
if (!/^(darwin|linux|windows)-(aarch64|x86_64)$/.test(platform))
|
|
129
|
+
say(RECIPE_CODES.invalid, `${at}: a platform is named as the registry names it (linux-x86_64)`);
|
|
130
|
+
if (!isPlain(archive)) {
|
|
131
|
+
say(RECIPE_CODES.binary, `${at} is { url, format, sha256, cmd }`);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
for (const field of Object.keys(archive))
|
|
135
|
+
if (!ARCHIVE_FIELDS.has(field))
|
|
136
|
+
say(INSTALL_FIELDS.has(field) ? RECIPE_CODES.install : RECIPE_CODES.binary, `${at}.${field} is not an archive field`);
|
|
137
|
+
let url;
|
|
138
|
+
try {
|
|
139
|
+
url = typeof archive.url === "string" ? new URL(archive.url) : undefined;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
url = undefined;
|
|
143
|
+
}
|
|
144
|
+
if (!url || url.protocol !== "https:" || url.username || url.password)
|
|
145
|
+
say(RECIPE_CODES.binary, `${at}.url must be the registry's https URL of the archive`);
|
|
146
|
+
if (typeof archive.sha256 !== "string" || !SHA256.test(archive.sha256))
|
|
147
|
+
say(RECIPE_CODES.binary, `${at}.sha256 must be the archive's sha256 as the registry lists it, 64 lowercase hex digits`);
|
|
148
|
+
if (archive.binarySha256 !== undefined && (typeof archive.binarySha256 !== "string" || !SHA256.test(archive.binarySha256)))
|
|
149
|
+
say(RECIPE_CODES.binary, `${at}.binarySha256, when given, is the unpacked binary's sha256, 64 lowercase hex digits`);
|
|
150
|
+
if (!ARCHIVE_FORMATS.includes(archive.format))
|
|
151
|
+
say(RECIPE_CODES.binary, `${at}.format: the installer unpacks ${ARCHIVE_FORMATS.join(" and ")} archives alone`);
|
|
152
|
+
if (typeof archive.cmd !== "string" || !archive.cmd || isAbsolute(archive.cmd) || !insideHome(archive.cmd))
|
|
153
|
+
say(RECIPE_CODES.paths, `${at}.cmd is the binary's path inside the archive (./agent), never one outside it`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (r.args !== undefined && !strings(r.args))
|
|
158
|
+
say(RECIPE_CODES.invalid, "args is a list of strings");
|
|
159
|
+
// Rule 1: keys.
|
|
160
|
+
if (r.keys !== undefined && !strings(r.keys))
|
|
161
|
+
say(RECIPE_CODES.keys, "keys is a list of the key names saved for this harness alone");
|
|
162
|
+
else
|
|
163
|
+
for (const name of r.keys ?? []) {
|
|
164
|
+
if (!ENV_NAME.test(name))
|
|
165
|
+
say(RECIPE_CODES.keys, `the key ${JSON.stringify(name)} is not a variable name`);
|
|
166
|
+
else if (serverKey(name))
|
|
167
|
+
say(RECIPE_CODES.keys, `${name} is a key this server holds for something else; a recipe names only keys saved for its own harness`);
|
|
168
|
+
else if (SET_BY_ADAPTER.has(name))
|
|
169
|
+
say(RECIPE_CODES.env, `${name} is set by the adapter or the proxy, never by a key`);
|
|
170
|
+
}
|
|
171
|
+
// Rule 5: env, with rule 1 for a key named in it.
|
|
172
|
+
const keys = new Set(strings(r.keys) ? r.keys : []);
|
|
173
|
+
if (r.env !== undefined && !isPlain(r.env))
|
|
174
|
+
say(RECIPE_CODES.env, "env is an object of variable names and their literal values");
|
|
175
|
+
else
|
|
176
|
+
for (const [name, value] of Object.entries(r.env ?? {})) {
|
|
177
|
+
if (!ENV_NAME.test(name))
|
|
178
|
+
say(RECIPE_CODES.env, `the env name ${JSON.stringify(name)} is not a variable name`);
|
|
179
|
+
else if (serverKey(name) || keyShaped(name) || keys.has(name))
|
|
180
|
+
say(RECIPE_CODES.keys, `env names ${name}, a key: a key is never written in a recipe; name it in keys, and only a key of this harness's own`);
|
|
181
|
+
else if (SET_BY_ADAPTER.has(name))
|
|
182
|
+
say(RECIPE_CODES.env, `env names ${name}, which the adapter or the proxy sets`);
|
|
183
|
+
if (typeof value !== "string")
|
|
184
|
+
say(RECIPE_CODES.env, `env.${name} must be a string`);
|
|
185
|
+
else if (EXPANDS.test(value))
|
|
186
|
+
say(RECIPE_CODES.env, `env.${name} reads the host's environment ($NAME); write the value out, as nothing of the host's environment reaches the agent`);
|
|
187
|
+
}
|
|
188
|
+
// The model: who bills it.
|
|
189
|
+
const model = r.model;
|
|
190
|
+
if (!isPlain(model))
|
|
191
|
+
say(RECIPE_CODES.invalid, 'model is { "billing": "proxy", "wire": "anthropic-messages", "env": NAME } or { "billing": "plan", "maxTurns": N, "maxToolCalls": M }');
|
|
192
|
+
else if (model.billing === "proxy") {
|
|
193
|
+
if (model.wire !== "anthropic-messages")
|
|
194
|
+
say(RECIPE_CODES.invalid, 'a proxy-billed agent speaks Anthropic\'s Messages API: model.wire is "anthropic-messages"');
|
|
195
|
+
if (typeof model.env !== "string" || !ENV_NAME.test(model.env))
|
|
196
|
+
say(RECIPE_CODES.invalid, "model.env names the variable the agent reads its model from");
|
|
197
|
+
else if (SET_BY_ADAPTER.has(model.env) || serverKey(model.env) || keyShaped(model.env))
|
|
198
|
+
say(RECIPE_CODES.env, `model.env names ${model.env}, which is the adapter's, the proxy's or a key`);
|
|
199
|
+
else if (isPlain(r.env) && model.env in r.env)
|
|
200
|
+
say(RECIPE_CODES.env, `env names ${model.env}, which the run's model sets`);
|
|
201
|
+
if (model.hostEnv !== undefined && !PROXY_HOST_ENVS.includes(model.hostEnv))
|
|
202
|
+
say(RECIPE_CODES.env, `model.hostEnv is the variable the agent reads the proxy's address from: ${PROXY_HOST_ENVS.join(" or ")}`);
|
|
203
|
+
for (const field of Object.keys(model))
|
|
204
|
+
if (!["billing", "wire", "env", "hostEnv"].includes(field))
|
|
205
|
+
say(RECIPE_CODES.invalid, `model.${field} is not a field of proxy billing`);
|
|
206
|
+
}
|
|
207
|
+
else if (model.billing === "plan") {
|
|
208
|
+
if (!Number.isInteger(model.maxTurns) || model.maxTurns < 1)
|
|
209
|
+
say(RECIPE_CODES.invalid, "plan billing needs maxTurns, a whole number of turns of at least 1");
|
|
210
|
+
if (!Number.isInteger(model.maxToolCalls) || model.maxToolCalls < 0)
|
|
211
|
+
say(RECIPE_CODES.invalid, "plan billing needs maxToolCalls, a whole number of calls");
|
|
212
|
+
if (!strings(r.keys) || !r.keys.length)
|
|
213
|
+
say(RECIPE_CODES.keys, "a plan-billed agent runs on its vendor's key: name it in keys");
|
|
214
|
+
if (model.hosts !== undefined && (!strings(model.hosts) || model.hosts.length > 16 || !model.hosts.every(vendorHost)))
|
|
215
|
+
say(RECIPE_CODES.invalid, "model.hosts lists at most 16 hosts the vendor's model is on, each a host name with an optional :port from 1 to 65535 (default 443)");
|
|
216
|
+
for (const field of Object.keys(model))
|
|
217
|
+
if (!["billing", "maxTurns", "maxToolCalls", "hosts"].includes(field))
|
|
218
|
+
say(RECIPE_CODES.invalid, `model.${field} is not a field of plan billing`);
|
|
219
|
+
}
|
|
220
|
+
else
|
|
221
|
+
say(RECIPE_CODES.invalid, 'model.billing is "proxy" or "plan"');
|
|
222
|
+
// Rule 3: files and state.
|
|
223
|
+
if (r.files !== undefined && !isPlain(r.files))
|
|
224
|
+
say(RECIPE_CODES.paths, "files is an object of paths in the private HOME and their contents");
|
|
225
|
+
else
|
|
226
|
+
for (const [path, content] of Object.entries(r.files ?? {})) {
|
|
227
|
+
if (!insideHome(path))
|
|
228
|
+
say(RECIPE_CODES.paths, `the file ${JSON.stringify(path)} must be a path inside the session's private HOME`);
|
|
229
|
+
if (typeof content !== "string")
|
|
230
|
+
say(RECIPE_CODES.invalid, `the file ${JSON.stringify(path)}'s content must be a string`);
|
|
231
|
+
}
|
|
232
|
+
if (r.state !== undefined && !strings(r.state))
|
|
233
|
+
say(RECIPE_CODES.paths, "state is a list of folders in the private HOME");
|
|
234
|
+
else
|
|
235
|
+
for (const path of r.state ?? [])
|
|
236
|
+
if (!insideHome(path))
|
|
237
|
+
say(RECIPE_CODES.paths, `the state folder ${JSON.stringify(path)} must be inside the session's private HOME`);
|
|
238
|
+
const declares = r.declares;
|
|
239
|
+
if (!isPlain(declares) || typeof declares.load !== "boolean" || (declares.mcp !== "http" && declares.mcp !== "stdio"))
|
|
240
|
+
say(RECIPE_CODES.invalid, 'declares is { "load": true or false, "mcp": "http" or "stdio" }');
|
|
241
|
+
if (r.quirks !== undefined && (!isPlain(r.quirks) || Object.keys(r.quirks).some((k) => k !== "mcpCall") || (r.quirks.mcpCall !== undefined && r.quirks.mcpCall !== "match" && r.quirks.mcpCall !== "mint")))
|
|
242
|
+
say(RECIPE_CODES.invalid, 'quirks is { "mcpCall": "match" or "mint" }');
|
|
243
|
+
if (r.description !== undefined && typeof r.description !== "string")
|
|
244
|
+
say(RECIPE_CODES.invalid, "description is a string");
|
|
245
|
+
return problems;
|
|
246
|
+
}
|
|
247
|
+
/** The recipe in `text`, or RecipeRefused with every problem. */
|
|
248
|
+
export function parseRecipe(text) {
|
|
249
|
+
let parsed;
|
|
250
|
+
try {
|
|
251
|
+
parsed = JSON.parse(text);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `not JSON (${error.message})` }]);
|
|
255
|
+
}
|
|
256
|
+
const problems = recipeProblems(parsed);
|
|
257
|
+
if (problems.length)
|
|
258
|
+
throw new RecipeRefused(problems[0].code, problems);
|
|
259
|
+
const r = parsed;
|
|
260
|
+
return Object.freeze({
|
|
261
|
+
id: r.id,
|
|
262
|
+
label: r.label,
|
|
263
|
+
release: r.release,
|
|
264
|
+
args: r.args ?? [],
|
|
265
|
+
keys: r.keys ?? [],
|
|
266
|
+
env: r.env ?? {},
|
|
267
|
+
model: r.model,
|
|
268
|
+
files: Object.fromEntries(Object.entries(r.files ?? {}).map(([path, content]) => [insideHome(path), content])),
|
|
269
|
+
state: (r.state ?? []).map((path) => insideHome(path)),
|
|
270
|
+
declares: r.declares,
|
|
271
|
+
quirks: r.quirks ?? {},
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/** The recipe file at `path`, read and loaded. */
|
|
275
|
+
export function loadRecipe(path) {
|
|
276
|
+
const file = resolve(path);
|
|
277
|
+
let text;
|
|
278
|
+
try {
|
|
279
|
+
text = readFileSync(file, "utf8");
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `the recipe file ${file} cannot be read (${error.code ?? error.message})` }]);
|
|
283
|
+
}
|
|
284
|
+
return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex") };
|
|
285
|
+
}
|
|
286
|
+
/** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
|
|
287
|
+
export const releaseFor = (recipe, platform = archivePlatform()) => (platform ? recipe.release.archives[platform] : undefined);
|
|
288
|
+
/** The owner's command that installs the recipe at `file` into `data`. */
|
|
289
|
+
export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
|
290
|
+
/** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
|
|
291
|
+
export const recipeBinaryOf = (data, recipe, release) => join(installDirOf(data, recipe.id), insideHome(release.cmd));
|
|
292
|
+
/** Where the first sha256 of a binary the recipe does not pin is kept: beside the harnesses' folders, never inside the
|
|
293
|
+
* one an install replaces, so a reinstall that unpacks a different binary is seen. One per id, version and platform. */
|
|
294
|
+
export const firstSeenOf = (data, recipe, platform) => join(harnessesOf(data), ".first-seen", `${recipe.id}@${recipe.release.version}-${platform}.sha256`);
|
|
295
|
+
/** A first-seen digest record in a file of its own (one line, the sha256), written once and never over another's. */
|
|
296
|
+
export function firstSeenRecord(file) {
|
|
297
|
+
return {
|
|
298
|
+
read() {
|
|
299
|
+
if (!existsSync(file))
|
|
300
|
+
return undefined;
|
|
301
|
+
const recorded = readFileSync(file, "utf8").trim();
|
|
302
|
+
if (!SHA256.test(recorded))
|
|
303
|
+
throw new Error(`the recorded digest in ${file} is not a sha256`);
|
|
304
|
+
return recorded;
|
|
305
|
+
},
|
|
306
|
+
write(sha256) {
|
|
307
|
+
mkdirSync(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
308
|
+
writeFileSync(file, `${sha256}\n`, { mode: 0o600, flag: "wx" });
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/** The sha256 the installed binary must have: the recipe's pin, else the first one its install recorded; undefined when it
|
|
313
|
+
* pins none and none was recorded (never installed by the owner's command). */
|
|
314
|
+
export function pinnedDigest(data, recipe, release, platform) {
|
|
315
|
+
if (release.binarySha256)
|
|
316
|
+
return { sha256: release.binarySha256, by: "recipe" };
|
|
317
|
+
const recorded = firstSeenRecord(firstSeenOf(data, recipe, platform)).read();
|
|
318
|
+
return recorded ? { sha256: recorded, by: "first-seen" } : undefined;
|
|
319
|
+
}
|
|
320
|
+
/** Installs the recipe's release into `<data>/harnesses/<id>` (the owner's command, rule 4): its archive downloaded and
|
|
321
|
+
* checked against the recipe's sha256, unpacked, and its binary checked against the recipe's pin, or recorded as the
|
|
322
|
+
* first one seen where the recipe pins none (a later one that differs is refused). */
|
|
323
|
+
export async function installRecipe(recipe, file, data, options = {}, env = process.env) {
|
|
324
|
+
const platform = options.platform ?? archivePlatform();
|
|
325
|
+
const release = releaseFor(recipe, platform);
|
|
326
|
+
const record = platform ? firstSeenRecord(firstSeenOf(data, recipe, platform)) : undefined;
|
|
327
|
+
const binary = release && !release.binarySha256 && record ? { binaryRecord: record } : {};
|
|
328
|
+
const before = release && !release.binarySha256 ? record?.read() : undefined;
|
|
329
|
+
const done = await installArchive({ id: recipe.id, label: recipe.label, retry: recipeInstallLine(file, data, env), pin: { version: recipe.release.version, archives: recipe.release.archives } }, installDirOf(data, recipe.id), { ...options, ...binary });
|
|
330
|
+
// What the binary was held to: the recipe's pin, the first digest an earlier install recorded, or this one's, recorded now.
|
|
331
|
+
const pinnedBy = release?.binarySha256 ? "recipe" : before ? "first-seen" : "recorded";
|
|
332
|
+
return { version: recipe.release.version, pinnedBy, ...done };
|
|
333
|
+
}
|
|
334
|
+
/** The owner's command that checks the recipe at `file`, installed into `data`. */
|
|
335
|
+
export const recipeCheckLine = (file, data, env = process.env) => `agentrun harness-check --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
package/dist/harness-table.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AdapterFacts, AgentAdapter } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { ModelProxyOptions } from "@parcha/agentrun-kernel/host";
|
|
3
|
+
import type { AcpProxy, AcpRecipe } from "@parcha/agentrun-harness-acp";
|
|
3
4
|
import type { AdapterNeeds } from "./adapters.js";
|
|
4
5
|
import { type HarnessInstallEntry, type HarnessPins } from "./harness-install.js";
|
|
5
6
|
import { type ModelChoice } from "./provider.js";
|
|
@@ -41,8 +42,9 @@ export interface HarnessEntry {
|
|
|
41
42
|
readonly label: string;
|
|
42
43
|
/** What it promises (HarnessPromises). Absent: a native harness's (NATIVE_PROMISES). */
|
|
43
44
|
readonly promises?: HarnessPromises;
|
|
44
|
-
/** The runner's harness for it (runner/adapters/index.ts RunnerHarness):
|
|
45
|
-
*
|
|
45
|
+
/** The runner's harness for it (runner/adapters/index.ts RunnerHarness): ON_TABLE on an entry moduleEntryOf builds (a
|
|
46
|
+
* module's, Goose's); absent on another built-in, whose runner is the runner's own (RUNNER_HARNESSES), else ON_TABLE
|
|
47
|
+
* for one run from its facts and adapter (Cursor). */
|
|
46
48
|
readonly runner?: RunnerHarness;
|
|
47
49
|
/** Whether it takes a message mid-turn; else a message waits for the turn's end. */
|
|
48
50
|
readonly steer: boolean;
|
|
@@ -80,12 +82,120 @@ export interface HarnessEntry {
|
|
|
80
82
|
* undefined while it is. One its owner installs (Goose: harness-goose.ts) is listed only once it is there and verified.
|
|
81
83
|
* It is still in the table, so a run or a save naming it is refused with these words. */
|
|
82
84
|
hidden?(env: NodeJS.ProcessEnv): string | undefined;
|
|
85
|
+
/** The secrets that are this harness's own (Cursor's CURSOR_API_KEY): a run of it is handed them, and a run of any
|
|
86
|
+
* other harness never is (run-secrets.ts keysFor). Only a built-in's count, each for that built-in alone
|
|
87
|
+
* (builtinOwns): a module's entry that names a key here moves no key from another harness's run, and one naming a
|
|
88
|
+
* built-in's (BUILTIN_OWN_KEYS) is refused at load (HARNESS_KEY_OWNED). */
|
|
89
|
+
readonly ownKeys?: readonly string[];
|
|
90
|
+
/** What its owner reads before running it (capabilities' `card`): who bills it, what stops it, whose terms it runs
|
|
91
|
+
* under. None for a harness that runs on this server's keys and cap. */
|
|
92
|
+
card?(env: NodeJS.ProcessEnv): string | undefined;
|
|
83
93
|
}
|
|
84
|
-
/** What a
|
|
85
|
-
* the
|
|
94
|
+
/** What one run of a module's adapter harness is given (HarnessModuleKit.adapterEntry): the model as its provider names it,
|
|
95
|
+
* where the session's proxy forwards it (origin, credential, auth), the price of a request's usage, a log, the
|
|
96
|
+
* confinement its process starts under, and the skills it loads itself. serve chooses each from the run's model and
|
|
97
|
+
* this server's keys (providerFor), as it does for the built-in harnesses. */
|
|
98
|
+
export interface ModuleLaunch {
|
|
99
|
+
readonly model: string;
|
|
100
|
+
readonly provider: {
|
|
101
|
+
readonly origin: string;
|
|
102
|
+
readonly credential: () => string | Promise<string>;
|
|
103
|
+
readonly auth?: "bearer" | "x-api-key";
|
|
104
|
+
};
|
|
105
|
+
readonly price: (model: string, usage: {
|
|
106
|
+
input: number;
|
|
107
|
+
output: number;
|
|
108
|
+
cacheRead?: number;
|
|
109
|
+
cacheWrite?: number;
|
|
110
|
+
}) => number | null;
|
|
111
|
+
readonly log: (message: string, fields?: Record<string, unknown>) => void;
|
|
112
|
+
readonly confine?: AdapterNeeds["confine"];
|
|
113
|
+
/** The run's skills its skillCheck accepted, taken out of the prompt for the harness to load itself; only with a
|
|
114
|
+
* skillCheck (adapterEntry's), and only when the run has some. */
|
|
115
|
+
readonly skills?: AdapterNeeds["skills"];
|
|
116
|
+
/** The server's environment, for the module's own settings (its binary's path, say). */
|
|
117
|
+
readonly env: NodeJS.ProcessEnv;
|
|
118
|
+
}
|
|
119
|
+
/** What an ACP agent's module gives acpEntry: its facts, its recipe for a run (the binary, the run's model), and the model
|
|
120
|
+
* proxy each of its processes reaches the session's booking through (its wire's policy: what may leave on this server's
|
|
121
|
+
* key). It promises tool calls through its permission asks, billing through the proxy, and the resume `resume` says. */
|
|
122
|
+
export interface AcpEntryOptions extends ModuleChecks {
|
|
123
|
+
readonly facts: AdapterFacts;
|
|
124
|
+
/** How its run resumes after a crash, as capabilities show it: "restart" (the default, never wrong: a new session
|
|
125
|
+
* with the conversation so far) or "load" (the agent's own session/load), which its recipe must declare
|
|
126
|
+
* (`declares.load`), else its first launch is refused (HARNESS_RESUME_UNDECLARED). */
|
|
127
|
+
readonly resume?: "load" | "restart";
|
|
128
|
+
recipe(launch: ModuleLaunch): AcpRecipe;
|
|
129
|
+
proxy(launch: ModuleLaunch): AcpProxy;
|
|
130
|
+
beforeStart?(command: string): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
/** What a module's harness lacks that no model key gives it, asked before its model key, as the built-in harnesses ask
|
|
133
|
+
* for their binary first. */
|
|
134
|
+
export interface ModuleChecks {
|
|
135
|
+
/** Why it cannot run on `env` whatever key is saved (its binary is not where its setting says, say), in words that end
|
|
136
|
+
* with what to do; undefined when nothing is missing. Its offer then says this and names no key, where without it a
|
|
137
|
+
* harness that lacks both would be offered as one a key runs. An error it throws whose `code` is one its facts'
|
|
138
|
+
* `install.codes` name is refused with that fix (install, pins), so the start's reason says to restart once fixed. */
|
|
139
|
+
missing?(env: NodeJS.ProcessEnv): string | undefined | Promise<string | undefined>;
|
|
140
|
+
}
|
|
141
|
+
/** What serve hands a harness module beside the built-ins (HarnessTableModule.entries' second argument): the builders the
|
|
142
|
+
* built-in harnesses are made with, so a module's entry chooses models, refuses and is offered as theirs are, on the
|
|
143
|
+
* running server's own copy, never a second serve's. */
|
|
144
|
+
export interface HarnessModuleKit {
|
|
145
|
+
/** An adapter harness's whole entry: its models are its wire's vendor's (WIRES), its key rows those that run them, its
|
|
146
|
+
* refusal the adapter's own check. `adapter` builds its adapter for one run. */
|
|
147
|
+
adapterEntry(facts: AdapterFacts, adapter: (launch: ModuleLaunch) => AgentAdapter | Promise<AgentAdapter>, extra?: Pick<HarnessEntry, "skillCheck" | "promises"> & ModuleChecks): HarnessEntry;
|
|
148
|
+
/** An ACP agent's whole entry, on serve's own ACP adapter (@parcha/agentrun-harness-acp): adapterEntry over acpAdapter. */
|
|
149
|
+
acpEntry(options: AcpEntryOptions): HarnessEntry;
|
|
150
|
+
}
|
|
151
|
+
/** What a harness module (and a test's table module) exports: entries by id, given the built-ins to build on and the kit
|
|
152
|
+
* (HarnessModuleKit). A test's are merged over the built-in one of that id (all of it, for one the server has none of);
|
|
153
|
+
* a harness module's add whole entries of new ids. Loaded with require: the module has no top-level await. */
|
|
86
154
|
export type HarnessTableModule = {
|
|
87
|
-
entries(builtins: Readonly<Record<string, HarnessEntry
|
|
155
|
+
entries(builtins: Readonly<Record<string, HarnessEntry>>, kit: HarnessModuleKit): Record<string, Partial<HarnessEntry>>;
|
|
88
156
|
};
|
|
157
|
+
/** What serve's own check of a recipe (harness-check.ts) gives acpEntryOf beside a module's options, so it runs the
|
|
158
|
+
* launch a server runs and still reads it: the log every launch writes to (the check reads the adapter's `acp:` lines).
|
|
159
|
+
* Never the kit's: a module's launches log as their harness. */
|
|
160
|
+
export interface AcpEntryHost {
|
|
161
|
+
readonly log?: ModuleLaunch["log"];
|
|
162
|
+
}
|
|
163
|
+
/** The runner of an entry run on serve's table (its facts' adapter, cli-run-spec.ts), never by a runner's adapter of its
|
|
164
|
+
* own: a module's, and Goose's and Cursor's (resolveHarness). Its adapter says so if it is ever asked. The loop keeps the
|
|
165
|
+
* run's record, as for every CLI harness. */
|
|
166
|
+
export declare const ON_TABLE: RunnerHarness;
|
|
167
|
+
/** The code a module's ACP entry is refused by at its first launch when it promises resume "load" and its recipe
|
|
168
|
+
* declares no session/load (AcpEntryOptions.resume). */
|
|
169
|
+
export declare const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
|
|
170
|
+
/** What a run of a plan-billed ACP agent is given (acpEntryOf's plan branch): its model as its vendor names it (`default`
|
|
171
|
+
* for the vendor's own), a log, the confinement its process starts under and the server's environment. No provider or
|
|
172
|
+
* price: its vendor bills its owner's plan, and no request of it reaches a proxy of ours. */
|
|
173
|
+
export type PlanLaunch = Omit<ModuleLaunch, "provider" | "price" | "skills">;
|
|
174
|
+
/** What serve gives acpEntryOf for an ACP agent billed to its owner's plan (its facts' wire `plan`): Cursor's entry and
|
|
175
|
+
* harness-check's plan-billed recipes. Not the kit's: a module's acpEntry is proxy-billed. `missing` may throw a
|
|
176
|
+
* HarnessUnavailable of its own, which keeps the fix (install, pins) it names; `recipe` may throw one too (a key unset). */
|
|
177
|
+
export interface AcpPlanEntryOptions extends ModuleChecks, Pick<HarnessEntry, "ownKeys" | "card" | "hidden"> {
|
|
178
|
+
readonly facts: AdapterFacts;
|
|
179
|
+
recipe(launch: PlanLaunch): AcpRecipe | Promise<AcpRecipe>;
|
|
180
|
+
beforeStart?(command: string): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
/** An ACP agent's whole entry on serve's own ACP adapter, by its facts' wire: proxy-billed (a module's, a proxy-billed
|
|
183
|
+
* recipe's) or billed to its owner's plan (Cursor's, a plan-billed recipe's). The one way an ACP agent other than the
|
|
184
|
+
* built-in Goose starts. A module's acpEntry is the proxy-billed one alone. */
|
|
185
|
+
export declare function acpEntryOf(options: AcpEntryOptions, host?: AcpEntryHost): HarnessEntry;
|
|
186
|
+
export declare function acpEntryOf(options: AcpPlanEntryOptions, host?: AcpEntryHost): HarnessEntry;
|
|
187
|
+
/** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
|
|
188
|
+
* server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
|
|
189
|
+
export declare const BUILTIN_OWN_KEYS: readonly string[];
|
|
190
|
+
/** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
|
|
191
|
+
* needs it too): a recipe or module never takes one (harness-recipe.ts). */
|
|
192
|
+
export declare const BUILTIN_HARNESS_IDS: readonly string[];
|
|
193
|
+
/** Whether built-in harness `id` owns secret `key`: its own built-in entry names it in ownKeys. By the pair, so a key one
|
|
194
|
+
* built-in owns never crosses to another built-in, a module's entry or a test's; and none is owned where its harness's
|
|
195
|
+
* package is not beside serve (run-secrets.ts keysFor). */
|
|
196
|
+
export declare function builtinOwns(id: string, key: string): boolean;
|
|
197
|
+
/** The code a harness module's entry is refused by when its ownKeys names a key a built-in harness owns (BUILTIN_OWN_KEYS). */
|
|
198
|
+
export declare const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
|
|
89
199
|
/** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
|
|
90
200
|
* server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
|
|
91
201
|
* harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
|
|
@@ -121,6 +231,11 @@ export declare const builtinHarness: (id: string | undefined) => HarnessEntry |
|
|
|
121
231
|
export declare const ownerTable: (env: NodeJS.ProcessEnv) => Readonly<Record<string, HarnessEntry>>;
|
|
122
232
|
/** The entry of harness `id` (none: the default, pi) on the owner's table (ownerTable); undefined for one it has not. */
|
|
123
233
|
export declare const ownerHarness: (env: NodeJS.ProcessEnv, id: string | undefined) => HarnessEntry | undefined;
|
|
234
|
+
/** The facts of harness `id`'s adapter on the owner's table (ownerTable: the built-in harnesses and those `env`'s modules
|
|
235
|
+
* add, never a test table's, so a stand-in keeps the facts of the harness it stands in for). Every reader of a harness's
|
|
236
|
+
* facts by id asks here: its models (model-form.ts), its key rows (model.ts), its search and tool names (tool-plane.ts,
|
|
237
|
+
* tool-gate.ts). Undefined for pi, for a module's harness that gives none, and for an id the table has none of. */
|
|
238
|
+
export declare const factsOf: (env: NodeJS.ProcessEnv, id: string | undefined) => AdapterFacts | undefined;
|
|
124
239
|
/** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
|
|
125
240
|
export declare const harnessOf: (env: NodeJS.ProcessEnv, id: string | undefined) => HarnessEntry | undefined;
|
|
126
241
|
/** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
|