@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.47
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 +164 -1
- package/NOTICE +4 -0
- package/README.md +267 -40
- package/dist/acp-package.d.ts +35 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +5 -2
- package/dist/adapter-facts.js +6 -3
- package/dist/adapters.d.ts +7 -0
- package/dist/adapters.js +39 -0
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +7 -10
- package/dist/archil-routes.js +2 -1
- package/dist/cap.js +12 -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-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +9 -75
- package/dist/computers.js +20 -66
- package/dist/console/assets/index-BBFzAxLB.js +715 -0
- package/dist/console/assets/index-BRi-Rgq6.css +1 -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 +73 -0
- package/dist/harness-check.js +489 -0
- package/dist/harness-cursor.d.ts +45 -0
- package/dist/harness-cursor.js +121 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +357 -0
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +62 -2
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +3 -2
- 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 +1 -0
- package/dist/key-refusal.js +8 -3
- 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 +69 -2
- package/dist/learn/promote.js +95 -3
- 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-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 +1 -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 +22 -8
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +2 -1
- package/dist/model.js +9 -7
- 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 +322 -39
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +8 -0
- package/dist/page.js +9 -1
- 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 +6 -4
- package/dist/runner/adapter-loop.d.ts +10 -7
- package/dist/runner/adapter-loop.js +57 -22
- package/dist/runner/adapter-run-spec.d.ts +12 -0
- package/dist/runner/adapter-run-spec.js +40 -6
- package/dist/runner/adapters/index.js +16 -0
- 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 +15 -7
- 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/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/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +41 -0
- package/dist/runner/presence.js +89 -0
- package/dist/runner/promotion.d.ts +9 -4
- package/dist/runner/promotion.js +33 -14
- 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/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/runs-over-store.d.ts +6 -2
- package/dist/runs-over-store.js +14 -4
- package/dist/sdk/runs.d.ts +1 -1
- package/dist/sdk/runs.js +6 -1
- package/dist/sdk/schema.js +1 -1
- 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 +31 -2
- package/dist/server.js +322 -51
- 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 +106 -27
- package/dist/store/store.d.ts +75 -23
- 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 +123 -14
- package/dist/store-view.js +154 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/timeline/timeline.js +18 -0
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.js +2 -2
- 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 +1 -1
- package/dist/trigger-targets.js +19 -8
- package/dist/triggers.d.ts +2 -2
- 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 +18 -14
- package/dist/workspace/resolve-computer.js +47 -60
- 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 +10 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Cursor on this server: where its owner installs it (`<data>/harnesses/cursor`, by `agentrun harness install cursor`,
|
|
2
|
+
// harness-archive.ts), the command that does, whether what is there is the pinned release (its launcher and every file
|
|
3
|
+
// beside it), the key it runs on (CURSOR_API_KEY, the owner's), the limits a run of it stops at and the card its owner
|
|
4
|
+
// reads. Nothing here downloads: a run, a save and the start's probe only look at what is installed, and say the command
|
|
5
|
+
// where it is not. Cursor's model is Cursor's, billed to the owner's Cursor plan: no request of it reaches a proxy of ours.
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { join, resolve } from "node:path";
|
|
8
|
+
import { acpPackage } from "./acp-package.js";
|
|
9
|
+
import { commandData } from "./harness-goose.js";
|
|
10
|
+
import { installArchive } from "./harness-archive.js";
|
|
11
|
+
import { installDirOf, shellWord } from "./harness-install.js";
|
|
12
|
+
import { DATA_ENV, defaultData } from "./server-fs.js";
|
|
13
|
+
export const CURSOR_ID = "cursor";
|
|
14
|
+
/** The key Cursor runs on: the owner's Cursor API key, read by name, handed to Cursor's runs and no other. */
|
|
15
|
+
export const CURSOR_KEY = "CURSOR_API_KEY";
|
|
16
|
+
/** The owner's limits for a run of Cursor (CURSOR_LIMITS, the package's, by default): its turns and its tool calls. */
|
|
17
|
+
export const CURSOR_MAX_TURNS_ENV = "AGENTRUN_CURSOR_MAX_TURNS";
|
|
18
|
+
export const CURSOR_MAX_TOOL_CALLS_ENV = "AGENTRUN_CURSOR_MAX_TOOL_CALLS";
|
|
19
|
+
/** The provider a Cursor model is named under (`cursor/<model>`, `cursor/default` for Cursor's own default). */
|
|
20
|
+
export const CURSOR_PROVIDER = "cursor";
|
|
21
|
+
export const CURSOR_DEFAULT_MODEL = "default";
|
|
22
|
+
const dataOf = (env) => env[DATA_ENV] || defaultData(env);
|
|
23
|
+
/** Cursor's folder in `data`. Its launcher is at the pin's `cmd` inside it (`./dist-package/cursor-agent`). */
|
|
24
|
+
export const cursorDirOf = (data) => installDirOf(data, CURSOR_ID);
|
|
25
|
+
/** The command that installs Cursor into `data`: naming it with --data unless it is the agentrun command's own. */
|
|
26
|
+
export function cursorInstallLine(acp, data, env = process.env) {
|
|
27
|
+
return resolve(data) === commandData(env) ? acp.CURSOR_INSTALL : `${acp.CURSOR_INSTALL} --data ${shellWord(data)}`;
|
|
28
|
+
}
|
|
29
|
+
/** The limits a run of Cursor stops at on `env`: the owner's (CURSOR_MAX_TURNS_ENV, CURSOR_MAX_TOOL_CALLS_ENV), else the
|
|
30
|
+
* package's. A setting that is no whole number is refused by name. */
|
|
31
|
+
export function cursorLimitsOf(acp, env) {
|
|
32
|
+
const read = (name, fallback, least) => {
|
|
33
|
+
const given = env[name];
|
|
34
|
+
if (given === undefined || given === "")
|
|
35
|
+
return fallback;
|
|
36
|
+
const n = Number(given);
|
|
37
|
+
if (!/^\d+$/.test(given.trim()) || !Number.isSafeInteger(n) || n < least)
|
|
38
|
+
throw new Error(`${name} is ${JSON.stringify(given)}: set it to a whole number of at least ${least}, or unset it for ${fallback}`);
|
|
39
|
+
return n;
|
|
40
|
+
};
|
|
41
|
+
return { maxTurns: read(CURSOR_MAX_TURNS_ENV, acp.CURSOR_LIMITS.maxTurns, 1), maxToolCalls: read(CURSOR_MAX_TOOL_CALLS_ENV, acp.CURSOR_LIMITS.maxToolCalls, 0) };
|
|
42
|
+
}
|
|
43
|
+
/** The card Cursor's owner reads (capabilities' harness `card`), with this server's limits; none where Cursor's adapter is
|
|
44
|
+
* not beside the server, or its limits are set wrong (its refusal says so). */
|
|
45
|
+
export function cursorCardOf(env) {
|
|
46
|
+
const acp = acpPackage();
|
|
47
|
+
if (!acp)
|
|
48
|
+
return undefined;
|
|
49
|
+
try {
|
|
50
|
+
return acp.cursorCard(cursorLimitsOf(acp, env));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** What is known of Cursor in `env`'s data before its files are read: why it is missing, or its launcher, its folder and
|
|
57
|
+
* the digests they must have, with how a refused check is said. */
|
|
58
|
+
function lookup(env) {
|
|
59
|
+
const acp = acpPackage();
|
|
60
|
+
if (!acp)
|
|
61
|
+
return { missing: { code: "HARNESS_NOT_INSTALLED", message: "HARNESS_NOT_INSTALLED: Cursor's adapter (@parcha/agentrun-harness-acp) is not installed beside this server" } };
|
|
62
|
+
const data = dataOf(env);
|
|
63
|
+
const root = cursorDirOf(data);
|
|
64
|
+
const line = cursorInstallLine(acp, data, env);
|
|
65
|
+
const { version } = acp.CURSOR_PIN;
|
|
66
|
+
const platform = acp.acpPlatform();
|
|
67
|
+
const release = acp.cursorRelease(platform);
|
|
68
|
+
if (!release)
|
|
69
|
+
return { missing: { code: "ACP_BINARY_UNPINNED", message: `ACP_BINARY_UNPINNED: Cursor ${version} has no release pinned for ${platform ?? `${process.platform}-${process.arch}`}, so it does not run here` } };
|
|
70
|
+
const binary = join(root, release.cmd);
|
|
71
|
+
if (!existsSync(binary))
|
|
72
|
+
return { missing: { code: acp.CURSOR_CODES.notInstalled, message: `${acp.CURSOR_CODES.notInstalled}: Cursor ${version} is not installed in ${root}. Install it with: ${line}` } };
|
|
73
|
+
return {
|
|
74
|
+
acp, binary, root, launcher: release.binarySha256, tree: release.treeSha256,
|
|
75
|
+
refused: (error) => {
|
|
76
|
+
const code = error?.code;
|
|
77
|
+
return { code: typeof code === "string" ? code : acp.CURSOR_CODES.notInstalled, message: `${error.message}. Install Cursor ${version} again with: ${line}` };
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Why Cursor is not listed here (HarnessEntry.hidden): not installed, or its launcher not the pinned one, in words that end
|
|
82
|
+
* with what to do, restarting AgentRun included. Undefined once it is installed. The files beside the launcher are
|
|
83
|
+
* checked off the event loop, by cursorMissing at each run and the start's probe. */
|
|
84
|
+
export function cursorHidden(env) {
|
|
85
|
+
const found = lookup(env);
|
|
86
|
+
let missing;
|
|
87
|
+
if ("missing" in found)
|
|
88
|
+
missing = found.missing;
|
|
89
|
+
else {
|
|
90
|
+
try {
|
|
91
|
+
found.acp.verifyPinnedBinary(found.binary, found.launcher);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
missing = found.refused(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return missing && `${missing.message}; then restart AgentRun.`;
|
|
98
|
+
}
|
|
99
|
+
/** Why Cursor cannot run here, its launcher and every file beside it checked off the event loop; else its launcher. */
|
|
100
|
+
export async function cursorMissing(env) {
|
|
101
|
+
const found = lookup(env);
|
|
102
|
+
if ("missing" in found)
|
|
103
|
+
return found;
|
|
104
|
+
try {
|
|
105
|
+
await found.acp.verifyPinnedBinaryAsync(found.binary, found.launcher);
|
|
106
|
+
await found.acp.verifyPinnedTree(found.root, found.tree);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return { missing: found.refused(error) };
|
|
110
|
+
}
|
|
111
|
+
return { binary: found.binary };
|
|
112
|
+
}
|
|
113
|
+
/** Installs the pinned Cursor into `data` (agentrun-serve install-harness cursor). */
|
|
114
|
+
export async function installCursor(data, options = {}, env = process.env) {
|
|
115
|
+
const acp = acpPackage();
|
|
116
|
+
if (!acp)
|
|
117
|
+
throw new Error("Cursor's adapter (@parcha/agentrun-harness-acp) is not installed beside this server, so it has no pin to install from");
|
|
118
|
+
const { id, version, archives } = acp.CURSOR_PIN;
|
|
119
|
+
const platform = acp.acpPlatform();
|
|
120
|
+
return { version, ...(await installArchive({ id, label: "Cursor", retry: cursorInstallLine(acp, data, env), pin: { version, archives }, tree: (root) => acp.treeDigest(root) }, cursorDirOf(data), { ...(platform ? { platform } : {}), ...options })) };
|
|
121
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type ArchiveFormat, type ArchiveInstallOptions, type ArchiveRelease } from "./harness-archive.js";
|
|
2
|
+
/** The codes a refused recipe carries, one per rule, and one for a file that is not a recipe at all. */
|
|
3
|
+
export declare const RECIPE_CODES: Readonly<{
|
|
4
|
+
/** Not JSON, not an object, or a field missing, of the wrong type, or unknown. */
|
|
5
|
+
readonly invalid: "RECIPE_INVALID";
|
|
6
|
+
/** Rule 1: a key that is not the harness's own. */
|
|
7
|
+
readonly keys: "RECIPE_KEY_NOT_OWN";
|
|
8
|
+
/** Rule 2: a binary that is not a registry archive pinned by its sha256. */
|
|
9
|
+
readonly binary: "RECIPE_BINARY_UNPINNED";
|
|
10
|
+
/** Rule 3: a file, a state folder or the binary outside its private place. */
|
|
11
|
+
readonly paths: "RECIPE_PATH_OUTSIDE";
|
|
12
|
+
/** Rule 4: an install step of the recipe's own. */
|
|
13
|
+
readonly install: "RECIPE_INSTALLS_ITSELF";
|
|
14
|
+
/** Rule 5: an environment beyond the allowlist and the recipe's own literal values. */
|
|
15
|
+
readonly env: "RECIPE_ENV_NOT_ALLOWLIST";
|
|
16
|
+
}>;
|
|
17
|
+
export type RecipeCode = (typeof RECIPE_CODES)[keyof typeof RECIPE_CODES];
|
|
18
|
+
/** One platform's release of the agent, copied from its ACP registry entry (`distribution.binary.<platform>`). */
|
|
19
|
+
export type RecipeArchive = ArchiveRelease & {
|
|
20
|
+
readonly format: ArchiveFormat;
|
|
21
|
+
};
|
|
22
|
+
/** The variables a proxy-billed agent may read the proxy's address from: Goose's, and the Anthropic SDKs'. */
|
|
23
|
+
export declare const PROXY_HOST_ENVS: readonly string[];
|
|
24
|
+
/** The variables the agent's environment gets from the adapter and the model proxy, never from a recipe, by part: what
|
|
25
|
+
* it takes from the host (`inherited`, run-adapters-acp's INHERITED_ENV), what the adapter sets for the private HOME
|
|
26
|
+
* (`reserved`, its RESERVED_ENV), and the proxy's address and key (`proxy`). The loader refuses a recipe that names one;
|
|
27
|
+
* the check's env_allowlist expects each. */
|
|
28
|
+
export declare const AGENT_VARS: Readonly<Record<"inherited" | "reserved" | "proxy", readonly string[]>>;
|
|
29
|
+
/** How the agent's model is billed. `proxy`: it speaks Anthropic's Messages API to the address in `hostEnv` (default
|
|
30
|
+
* ANTHROPIC_HOST) with ANTHROPIC_API_KEY, both the session's model proxy's (the run's cap and books hold), and reads the
|
|
31
|
+
* run's model from `env`. `plan`: the vendor bills the owner's plan on the recipe's own keys; the adapter stops the run
|
|
32
|
+
* at these limits. */
|
|
33
|
+
export type RecipeModel = {
|
|
34
|
+
readonly billing: "proxy";
|
|
35
|
+
readonly wire: "anthropic-messages";
|
|
36
|
+
readonly env: string;
|
|
37
|
+
readonly hostEnv?: "ANTHROPIC_HOST" | "ANTHROPIC_BASE_URL";
|
|
38
|
+
} | {
|
|
39
|
+
readonly billing: "plan";
|
|
40
|
+
readonly maxTurns: number;
|
|
41
|
+
readonly maxToolCalls: number;
|
|
42
|
+
readonly hosts?: readonly string[];
|
|
43
|
+
};
|
|
44
|
+
/** A recipe file, as the loader passes it. */
|
|
45
|
+
export interface Recipe {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly label: string;
|
|
48
|
+
readonly release: {
|
|
49
|
+
readonly registry: string;
|
|
50
|
+
readonly version: string;
|
|
51
|
+
readonly archives: Readonly<Record<string, RecipeArchive>>;
|
|
52
|
+
};
|
|
53
|
+
readonly args: readonly string[];
|
|
54
|
+
readonly keys: readonly string[];
|
|
55
|
+
readonly env: Readonly<Record<string, string>>;
|
|
56
|
+
readonly model: RecipeModel;
|
|
57
|
+
readonly files: Readonly<Record<string, string>>;
|
|
58
|
+
readonly state: readonly string[];
|
|
59
|
+
readonly declares: {
|
|
60
|
+
readonly load: boolean;
|
|
61
|
+
readonly mcp: "http" | "stdio";
|
|
62
|
+
};
|
|
63
|
+
readonly quirks: {
|
|
64
|
+
readonly mcpCall?: "match" | "mint";
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** A recipe the loader refused: `code` is the first problem's, and the message says every one. */
|
|
68
|
+
export declare class RecipeRefused extends Error {
|
|
69
|
+
readonly code: RecipeCode;
|
|
70
|
+
readonly problems: readonly {
|
|
71
|
+
code: RecipeCode;
|
|
72
|
+
words: string;
|
|
73
|
+
}[];
|
|
74
|
+
constructor(code: RecipeCode, problems: readonly {
|
|
75
|
+
code: RecipeCode;
|
|
76
|
+
words: string;
|
|
77
|
+
}[]);
|
|
78
|
+
}
|
|
79
|
+
/** Whether `name` is a key the server holds for anything but this harness: the launcher's secrets (model providers, the
|
|
80
|
+
* gateway, tools, computers, serve's own) and every AGENTRUN_ and AGENT_MODEL_ name. */
|
|
81
|
+
export declare const serverKey: (name: string) => boolean;
|
|
82
|
+
/** `path` inside HOME, or undefined when it leaves it (absolute, `..`, or empty); a `$HOME/` prefix is HOME. */
|
|
83
|
+
export declare function insideHome(path: string): string | undefined;
|
|
84
|
+
/** Every problem with `parsed` as a recipe, by its rule's code. */
|
|
85
|
+
export declare function recipeProblems(parsed: unknown): {
|
|
86
|
+
code: RecipeCode;
|
|
87
|
+
words: string;
|
|
88
|
+
}[];
|
|
89
|
+
/** The recipe in `text`, or RecipeRefused with every problem. */
|
|
90
|
+
export declare function parseRecipe(text: string): Recipe;
|
|
91
|
+
/** The recipe file at `path`, read and loaded. */
|
|
92
|
+
export declare function loadRecipe(path: string): {
|
|
93
|
+
recipe: Recipe;
|
|
94
|
+
file: string;
|
|
95
|
+
sha256: string;
|
|
96
|
+
};
|
|
97
|
+
/** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
|
|
98
|
+
export declare const releaseFor: (recipe: Recipe, platform?: string | undefined) => RecipeArchive | undefined;
|
|
99
|
+
/** The owner's command that installs the recipe at `file` into `data`. */
|
|
100
|
+
export declare const recipeInstallLine: (file: string, data: string, env?: NodeJS.ProcessEnv) => string;
|
|
101
|
+
/** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
|
|
102
|
+
export declare const recipeBinaryOf: (data: string, recipe: Recipe, release: RecipeArchive) => string;
|
|
103
|
+
/** Where the first sha256 of a binary the recipe does not pin is kept: beside the harnesses' folders, never inside the
|
|
104
|
+
* one an install replaces, so a reinstall that unpacks a different binary is seen. One per id, version and platform. */
|
|
105
|
+
export declare const firstSeenOf: (data: string, recipe: Recipe, platform: string) => string;
|
|
106
|
+
/** A first-seen digest record in a file of its own (one line, the sha256), written once and never over another's. */
|
|
107
|
+
export declare function firstSeenRecord(file: string): {
|
|
108
|
+
read(): string | undefined;
|
|
109
|
+
write(sha256: string): void;
|
|
110
|
+
};
|
|
111
|
+
/** The sha256 the installed binary must have: the recipe's pin, else the first one its install recorded; undefined when it
|
|
112
|
+
* pins none and none was recorded (never installed by the owner's command). */
|
|
113
|
+
export declare function pinnedDigest(data: string, recipe: Recipe, release: RecipeArchive, platform: string): {
|
|
114
|
+
sha256: string;
|
|
115
|
+
by: "recipe" | "first-seen";
|
|
116
|
+
} | undefined;
|
|
117
|
+
/** Installs the recipe's release into `<data>/harnesses/<id>` (the owner's command, rule 4): its archive downloaded and
|
|
118
|
+
* checked against the recipe's sha256, unpacked, and its binary checked against the recipe's pin, or recorded as the
|
|
119
|
+
* first one seen where the recipe pins none (a later one that differs is refused). */
|
|
120
|
+
export declare function installRecipe(recipe: Recipe, file: string, data: string, options?: ArchiveInstallOptions, env?: NodeJS.ProcessEnv): Promise<{
|
|
121
|
+
installed: "already" | "now";
|
|
122
|
+
binary: string;
|
|
123
|
+
version: string;
|
|
124
|
+
pinnedBy: "recipe" | "recorded" | "first-seen";
|
|
125
|
+
}>;
|
|
126
|
+
/** The owner's command that checks the recipe at `file`, installed into `data`. */
|
|
127
|
+
export declare const recipeCheckLine: (file: string, data: string, env?: NodeJS.ProcessEnv) => string;
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
// A harness recipe (door 1 of bring your own harness): a JSON file that says how to run an ACP agent AgentRun does not
|
|
2
|
+
// ship, read by the one loader here. Goose's recipe (run-adapters-acp's recipes/goose.json) and its owner's install
|
|
3
|
+
// (harness-goose.ts) are the path this generalizes: a recipe file its owner points at goes through the same five rules,
|
|
4
|
+
// each refused by a code of its own (RECIPE_CODES) before anything is downloaded or started:
|
|
5
|
+
// 1. Own keys only. `keys` names the keys saved for this harness alone (a vendor's API key). A key the server holds for
|
|
6
|
+
// anything else (the launcher's secrets: every model provider's, the gateway's, the tools', the computers', serve's
|
|
7
|
+
// own) is refused, and `env` names no key at all: a value in a recipe file is plain text.
|
|
8
|
+
// 2. A pinned binary. The binary is the release's archive for this platform, as the ACP registry lists it: an https URL
|
|
9
|
+
// and its sha256. A recipe names no command, path or binary of its own. The binary's own sha256 is pinned when the
|
|
10
|
+
// recipe gives it; where it does not (the registry lists only the archive's), the install records the first one it
|
|
11
|
+
// unpacks from the verified archive (harness-archive.ts binaryRecord, the one first-seen path), and a binary that
|
|
12
|
+
// differs from it later is refused by the installer's code (HARNESS_BINARY_MISMATCH). The archive is in a format the
|
|
13
|
+
// installer unpacks (ARCHIVE_FORMATS: tar.bz2, tar.gz).
|
|
14
|
+
// 3. Private paths. The files it writes and the state it keeps are paths inside the session's private HOME; the binary
|
|
15
|
+
// is a path inside its own folder.
|
|
16
|
+
// 4. The owner installs it. Only `agentrun harness install --recipe FILE` downloads and unpacks it (installRecipe), into
|
|
17
|
+
// `<data>/harnesses/<id>`. A check or a run that finds it missing says that command and downloads nothing; a recipe
|
|
18
|
+
// names no install step, script or hook of its own.
|
|
19
|
+
// 5. An allowlist environment. The agent's process gets the adapter's allowlist (PATH, LANG, TZ), its private HOME and
|
|
20
|
+
// tmp, the recipe's literal `env`, its own keys, and the proxy's address: nothing else of the host's. A recipe cannot
|
|
21
|
+
// ask for more (no inherit or pass-through field), names none of the variables the adapter or the proxy sets, and
|
|
22
|
+
// writes its values out (no `$NAME` for the host to fill in).
|
|
23
|
+
// Nothing here reads the network or starts a process.
|
|
24
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
25
|
+
import { createHash } from "node:crypto";
|
|
26
|
+
import { isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
27
|
+
import { HARNESS_ID_PATTERN, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
28
|
+
import { ARCHIVE_FORMATS, archivePlatform, installArchive } from "./harness-archive.js";
|
|
29
|
+
import { BUILTIN_HARNESS_IDS } from "./harness-table.js";
|
|
30
|
+
import { commandData } from "./harness-goose.js";
|
|
31
|
+
import { harnessesOf, installDirOf, shellWord } from "./harness-install.js";
|
|
32
|
+
import { keyShaped } from "./secret-name.js";
|
|
33
|
+
import { SECRET_NAMES } from "./secrets.js";
|
|
34
|
+
/** The codes a refused recipe carries, one per rule, and one for a file that is not a recipe at all. */
|
|
35
|
+
export const RECIPE_CODES = Object.freeze({
|
|
36
|
+
/** Not JSON, not an object, or a field missing, of the wrong type, or unknown. */
|
|
37
|
+
invalid: "RECIPE_INVALID",
|
|
38
|
+
/** Rule 1: a key that is not the harness's own. */
|
|
39
|
+
keys: "RECIPE_KEY_NOT_OWN",
|
|
40
|
+
/** Rule 2: a binary that is not a registry archive pinned by its sha256. */
|
|
41
|
+
binary: "RECIPE_BINARY_UNPINNED",
|
|
42
|
+
/** Rule 3: a file, a state folder or the binary outside its private place. */
|
|
43
|
+
paths: "RECIPE_PATH_OUTSIDE",
|
|
44
|
+
/** Rule 4: an install step of the recipe's own. */
|
|
45
|
+
install: "RECIPE_INSTALLS_ITSELF",
|
|
46
|
+
/** Rule 5: an environment beyond the allowlist and the recipe's own literal values. */
|
|
47
|
+
env: "RECIPE_ENV_NOT_ALLOWLIST",
|
|
48
|
+
});
|
|
49
|
+
/** The variables a proxy-billed agent may read the proxy's address from: Goose's, and the Anthropic SDKs'. */
|
|
50
|
+
export const PROXY_HOST_ENVS = Object.freeze(["ANTHROPIC_HOST", "ANTHROPIC_BASE_URL"]);
|
|
51
|
+
/** The variables the agent's environment gets from the adapter and the model proxy, never from a recipe, by part: what
|
|
52
|
+
* it takes from the host (`inherited`, run-adapters-acp's INHERITED_ENV), what the adapter sets for the private HOME
|
|
53
|
+
* (`reserved`, its RESERVED_ENV), and the proxy's address and key (`proxy`). The loader refuses a recipe that names one;
|
|
54
|
+
* the check's env_allowlist expects each. */
|
|
55
|
+
export const AGENT_VARS = Object.freeze({
|
|
56
|
+
inherited: Object.freeze(["PATH", "LANG", "TZ"]),
|
|
57
|
+
reserved: Object.freeze(["HOME", "TMPDIR", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME", "GIT_CEILING_DIRECTORIES"]),
|
|
58
|
+
proxy: Object.freeze([...PROXY_HOST_ENVS, "ANTHROPIC_API_KEY"]),
|
|
59
|
+
});
|
|
60
|
+
/** A host a plan-billed agent's vendor is on, as model.hosts names it: a lowercase host name, with an optional port. */
|
|
61
|
+
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}))?$/;
|
|
62
|
+
const vendorHost = (host) => {
|
|
63
|
+
const port = VENDOR_HOST.exec(host)?.[1];
|
|
64
|
+
return VENDOR_HOST.test(host) && (port === undefined || Number(port) <= 65535);
|
|
65
|
+
};
|
|
66
|
+
/** A recipe the loader refused: `code` is the first problem's, and the message says every one. */
|
|
67
|
+
export class RecipeRefused extends Error {
|
|
68
|
+
code;
|
|
69
|
+
problems;
|
|
70
|
+
constructor(code, problems) {
|
|
71
|
+
super(`${code}: ${problems.map((p) => (p.code === code ? p.words : `${p.code}: ${p.words}`)).join("; ")}`);
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.problems = problems;
|
|
74
|
+
this.name = "RecipeRefused";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** The fields a recipe has. */
|
|
78
|
+
const FIELDS = new Set(["id", "label", "release", "args", "keys", "env", "model", "files", "state", "declares", "quirks", "description", "$schema"]);
|
|
79
|
+
/** Fields that would run something of the recipe's own at install or start (rule 4). */
|
|
80
|
+
const INSTALL_FIELDS = new Set(["install", "installCommand", "postinstall", "preinstall", "setup", "script", "scripts", "run", "hooks", "update"]);
|
|
81
|
+
/** Fields that would name a binary other than the release's archive (rule 2). */
|
|
82
|
+
const BINARY_FIELDS = new Set(["command", "binary", "path", "bin", "executable", "exec"]);
|
|
83
|
+
/** Fields that would pass the host's environment through (rule 5). */
|
|
84
|
+
const ENV_FIELDS = new Set(["inheritEnv", "passEnv", "envFrom", "inherit", "envPassthrough", "passthroughEnv"]);
|
|
85
|
+
/** Every variable of AGENT_VARS. */
|
|
86
|
+
const SET_BY_ADAPTER = new Set(Object.values(AGENT_VARS).flat());
|
|
87
|
+
const ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
88
|
+
const SHA256 = /^[0-9a-f]{64}$/;
|
|
89
|
+
const ARCHIVE_FIELDS = new Set(["url", "format", "sha256", "cmd", "binarySha256"]);
|
|
90
|
+
/** A value the host would fill in from its own environment: `$NAME` or `${NAME}`. */
|
|
91
|
+
const EXPANDS = /\$(?:\{[^}]*\}|[A-Za-z_])/;
|
|
92
|
+
/** Whether `name` is a key the server holds for anything but this harness: the launcher's secrets (model providers, the
|
|
93
|
+
* gateway, tools, computers, serve's own) and every AGENTRUN_ and AGENT_MODEL_ name. */
|
|
94
|
+
export const serverKey = (name) => SECRET_NAMES.includes(name) || name.startsWith("AGENTRUN_") || name.startsWith("AGENT_MODEL_");
|
|
95
|
+
/** `path` inside HOME, or undefined when it leaves it (absolute, `..`, or empty); a `$HOME/` prefix is HOME. */
|
|
96
|
+
export function insideHome(path) {
|
|
97
|
+
const bare = path.startsWith("$HOME/") ? path.slice("$HOME/".length) : path;
|
|
98
|
+
if (!bare || isAbsolute(bare))
|
|
99
|
+
return undefined;
|
|
100
|
+
const clean = normalize(bare);
|
|
101
|
+
if (clean === "." || clean === ".." || clean.startsWith(`..${sep}`))
|
|
102
|
+
return undefined;
|
|
103
|
+
return clean;
|
|
104
|
+
}
|
|
105
|
+
const isPlain = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106
|
+
const strings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
107
|
+
/** Every problem with `parsed` as a recipe, by its rule's code. */
|
|
108
|
+
export function recipeProblems(parsed) {
|
|
109
|
+
const problems = [];
|
|
110
|
+
const say = (code, words) => problems.push({ code, words });
|
|
111
|
+
if (!isPlain(parsed))
|
|
112
|
+
return [{ code: RECIPE_CODES.invalid, words: "a recipe is a JSON object" }];
|
|
113
|
+
const r = parsed;
|
|
114
|
+
for (const field of Object.keys(r)) {
|
|
115
|
+
if (FIELDS.has(field))
|
|
116
|
+
continue;
|
|
117
|
+
if (INSTALL_FIELDS.has(field))
|
|
118
|
+
say(RECIPE_CODES.install, `"${field}": a recipe runs no install step of its own; its owner installs its release with agentrun harness install --recipe`);
|
|
119
|
+
else if (BINARY_FIELDS.has(field))
|
|
120
|
+
say(RECIPE_CODES.binary, `"${field}": a recipe names no binary of its own; the binary is its release's archive, pinned by sha256`);
|
|
121
|
+
else if (ENV_FIELDS.has(field))
|
|
122
|
+
say(RECIPE_CODES.env, `"${field}": the agent's environment is an allowlist; name each variable and its value in env`);
|
|
123
|
+
else
|
|
124
|
+
say(RECIPE_CODES.invalid, `"${field}" is not a recipe field`);
|
|
125
|
+
}
|
|
126
|
+
const idPattern = new RegExp(HARNESS_ID_PATTERN);
|
|
127
|
+
if (typeof r.id !== "string" || !idPattern.test(r.id))
|
|
128
|
+
say(RECIPE_CODES.invalid, `id must match ${HARNESS_ID_PATTERN}`);
|
|
129
|
+
else if (BUILTIN_HARNESS_IDS.includes(r.id) || RESERVED_HARNESS_IDS.includes(r.id))
|
|
130
|
+
say(RECIPE_CODES.invalid, `id ${r.id} is a harness AgentRun already has, or a name its runs carry; give yours its own`);
|
|
131
|
+
if (typeof r.label !== "string" || !r.label.trim() || r.label.length > 80)
|
|
132
|
+
say(RECIPE_CODES.invalid, "label is the harness's name in a sentence, 1 to 80 characters");
|
|
133
|
+
// Rule 2: the release.
|
|
134
|
+
const release = r.release;
|
|
135
|
+
if (!isPlain(release))
|
|
136
|
+
say(RECIPE_CODES.binary, "release names the agent's registry id, its version and an archive per platform with its sha256");
|
|
137
|
+
else {
|
|
138
|
+
for (const field of Object.keys(release))
|
|
139
|
+
if (!["registry", "version", "archives"].includes(field))
|
|
140
|
+
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`);
|
|
141
|
+
if (typeof release.registry !== "string" || !/^[a-z0-9][a-z0-9._-]{0,63}$/.test(release.registry))
|
|
142
|
+
say(RECIPE_CODES.invalid, "release.registry is the agent's id in the ACP registry");
|
|
143
|
+
if (typeof release.version !== "string" || !/^[0-9A-Za-z][0-9A-Za-z.+_-]{0,63}$/.test(release.version))
|
|
144
|
+
say(RECIPE_CODES.invalid, "release.version is the registry's version string");
|
|
145
|
+
if (!isPlain(release.archives) || !Object.keys(release.archives).length)
|
|
146
|
+
say(RECIPE_CODES.binary, "release.archives names at least one platform's archive (linux-x86_64, darwin-aarch64, ...)");
|
|
147
|
+
else {
|
|
148
|
+
for (const [platform, archive] of Object.entries(release.archives)) {
|
|
149
|
+
const at = `release.archives["${platform}"]`;
|
|
150
|
+
if (!/^(darwin|linux|windows)-(aarch64|x86_64)$/.test(platform))
|
|
151
|
+
say(RECIPE_CODES.invalid, `${at}: a platform is named as the registry names it (linux-x86_64)`);
|
|
152
|
+
if (!isPlain(archive)) {
|
|
153
|
+
say(RECIPE_CODES.binary, `${at} is { url, format, sha256, cmd }`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
for (const field of Object.keys(archive))
|
|
157
|
+
if (!ARCHIVE_FIELDS.has(field))
|
|
158
|
+
say(INSTALL_FIELDS.has(field) ? RECIPE_CODES.install : RECIPE_CODES.binary, `${at}.${field} is not an archive field`);
|
|
159
|
+
let url;
|
|
160
|
+
try {
|
|
161
|
+
url = typeof archive.url === "string" ? new URL(archive.url) : undefined;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
url = undefined;
|
|
165
|
+
}
|
|
166
|
+
if (!url || url.protocol !== "https:" || url.username || url.password)
|
|
167
|
+
say(RECIPE_CODES.binary, `${at}.url must be the registry's https URL of the archive`);
|
|
168
|
+
if (typeof archive.sha256 !== "string" || !SHA256.test(archive.sha256))
|
|
169
|
+
say(RECIPE_CODES.binary, `${at}.sha256 must be the archive's sha256 as the registry lists it, 64 lowercase hex digits`);
|
|
170
|
+
if (archive.binarySha256 !== undefined && (typeof archive.binarySha256 !== "string" || !SHA256.test(archive.binarySha256)))
|
|
171
|
+
say(RECIPE_CODES.binary, `${at}.binarySha256, when given, is the unpacked binary's sha256, 64 lowercase hex digits`);
|
|
172
|
+
if (!ARCHIVE_FORMATS.includes(archive.format))
|
|
173
|
+
say(RECIPE_CODES.binary, `${at}.format: the installer unpacks ${ARCHIVE_FORMATS.join(" and ")} archives alone`);
|
|
174
|
+
if (typeof archive.cmd !== "string" || !archive.cmd || isAbsolute(archive.cmd) || !insideHome(archive.cmd))
|
|
175
|
+
say(RECIPE_CODES.paths, `${at}.cmd is the binary's path inside the archive (./agent), never one outside it`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (r.args !== undefined && !strings(r.args))
|
|
180
|
+
say(RECIPE_CODES.invalid, "args is a list of strings");
|
|
181
|
+
// Rule 1: keys.
|
|
182
|
+
if (r.keys !== undefined && !strings(r.keys))
|
|
183
|
+
say(RECIPE_CODES.keys, "keys is a list of the key names saved for this harness alone");
|
|
184
|
+
else
|
|
185
|
+
for (const name of r.keys ?? []) {
|
|
186
|
+
if (!ENV_NAME.test(name))
|
|
187
|
+
say(RECIPE_CODES.keys, `the key ${JSON.stringify(name)} is not a variable name`);
|
|
188
|
+
else if (serverKey(name))
|
|
189
|
+
say(RECIPE_CODES.keys, `${name} is a key this server holds for something else; a recipe names only keys saved for its own harness`);
|
|
190
|
+
else if (SET_BY_ADAPTER.has(name))
|
|
191
|
+
say(RECIPE_CODES.env, `${name} is set by the adapter or the proxy, never by a key`);
|
|
192
|
+
}
|
|
193
|
+
// Rule 5: env, with rule 1 for a key named in it.
|
|
194
|
+
const keys = new Set(strings(r.keys) ? r.keys : []);
|
|
195
|
+
if (r.env !== undefined && !isPlain(r.env))
|
|
196
|
+
say(RECIPE_CODES.env, "env is an object of variable names and their literal values");
|
|
197
|
+
else
|
|
198
|
+
for (const [name, value] of Object.entries(r.env ?? {})) {
|
|
199
|
+
if (!ENV_NAME.test(name))
|
|
200
|
+
say(RECIPE_CODES.env, `the env name ${JSON.stringify(name)} is not a variable name`);
|
|
201
|
+
else if (serverKey(name) || keyShaped(name) || keys.has(name))
|
|
202
|
+
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`);
|
|
203
|
+
else if (SET_BY_ADAPTER.has(name))
|
|
204
|
+
say(RECIPE_CODES.env, `env names ${name}, which the adapter or the proxy sets`);
|
|
205
|
+
if (typeof value !== "string")
|
|
206
|
+
say(RECIPE_CODES.env, `env.${name} must be a string`);
|
|
207
|
+
else if (EXPANDS.test(value))
|
|
208
|
+
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`);
|
|
209
|
+
}
|
|
210
|
+
// The model: who bills it.
|
|
211
|
+
const model = r.model;
|
|
212
|
+
if (!isPlain(model))
|
|
213
|
+
say(RECIPE_CODES.invalid, 'model is { "billing": "proxy", "wire": "anthropic-messages", "env": NAME } or { "billing": "plan", "maxTurns": N, "maxToolCalls": M }');
|
|
214
|
+
else if (model.billing === "proxy") {
|
|
215
|
+
if (model.wire !== "anthropic-messages")
|
|
216
|
+
say(RECIPE_CODES.invalid, 'a proxy-billed agent speaks Anthropic\'s Messages API: model.wire is "anthropic-messages"');
|
|
217
|
+
if (typeof model.env !== "string" || !ENV_NAME.test(model.env))
|
|
218
|
+
say(RECIPE_CODES.invalid, "model.env names the variable the agent reads its model from");
|
|
219
|
+
else if (SET_BY_ADAPTER.has(model.env) || serverKey(model.env) || keyShaped(model.env))
|
|
220
|
+
say(RECIPE_CODES.env, `model.env names ${model.env}, which is the adapter's, the proxy's or a key`);
|
|
221
|
+
else if (isPlain(r.env) && model.env in r.env)
|
|
222
|
+
say(RECIPE_CODES.env, `env names ${model.env}, which the run's model sets`);
|
|
223
|
+
if (model.hostEnv !== undefined && !PROXY_HOST_ENVS.includes(model.hostEnv))
|
|
224
|
+
say(RECIPE_CODES.env, `model.hostEnv is the variable the agent reads the proxy's address from: ${PROXY_HOST_ENVS.join(" or ")}`);
|
|
225
|
+
for (const field of Object.keys(model))
|
|
226
|
+
if (!["billing", "wire", "env", "hostEnv"].includes(field))
|
|
227
|
+
say(RECIPE_CODES.invalid, `model.${field} is not a field of proxy billing`);
|
|
228
|
+
}
|
|
229
|
+
else if (model.billing === "plan") {
|
|
230
|
+
if (!Number.isInteger(model.maxTurns) || model.maxTurns < 1)
|
|
231
|
+
say(RECIPE_CODES.invalid, "plan billing needs maxTurns, a whole number of turns of at least 1");
|
|
232
|
+
if (!Number.isInteger(model.maxToolCalls) || model.maxToolCalls < 0)
|
|
233
|
+
say(RECIPE_CODES.invalid, "plan billing needs maxToolCalls, a whole number of calls");
|
|
234
|
+
if (!strings(r.keys) || !r.keys.length)
|
|
235
|
+
say(RECIPE_CODES.keys, "a plan-billed agent runs on its vendor's key: name it in keys");
|
|
236
|
+
if (model.hosts !== undefined && (!strings(model.hosts) || model.hosts.length > 16 || !model.hosts.every(vendorHost)))
|
|
237
|
+
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)");
|
|
238
|
+
for (const field of Object.keys(model))
|
|
239
|
+
if (!["billing", "maxTurns", "maxToolCalls", "hosts"].includes(field))
|
|
240
|
+
say(RECIPE_CODES.invalid, `model.${field} is not a field of plan billing`);
|
|
241
|
+
}
|
|
242
|
+
else
|
|
243
|
+
say(RECIPE_CODES.invalid, 'model.billing is "proxy" or "plan"');
|
|
244
|
+
// Rule 3: files and state.
|
|
245
|
+
if (r.files !== undefined && !isPlain(r.files))
|
|
246
|
+
say(RECIPE_CODES.paths, "files is an object of paths in the private HOME and their contents");
|
|
247
|
+
else
|
|
248
|
+
for (const [path, content] of Object.entries(r.files ?? {})) {
|
|
249
|
+
if (!insideHome(path))
|
|
250
|
+
say(RECIPE_CODES.paths, `the file ${JSON.stringify(path)} must be a path inside the session's private HOME`);
|
|
251
|
+
if (typeof content !== "string")
|
|
252
|
+
say(RECIPE_CODES.invalid, `the file ${JSON.stringify(path)}'s content must be a string`);
|
|
253
|
+
}
|
|
254
|
+
if (r.state !== undefined && !strings(r.state))
|
|
255
|
+
say(RECIPE_CODES.paths, "state is a list of folders in the private HOME");
|
|
256
|
+
else
|
|
257
|
+
for (const path of r.state ?? [])
|
|
258
|
+
if (!insideHome(path))
|
|
259
|
+
say(RECIPE_CODES.paths, `the state folder ${JSON.stringify(path)} must be inside the session's private HOME`);
|
|
260
|
+
const declares = r.declares;
|
|
261
|
+
if (!isPlain(declares) || typeof declares.load !== "boolean" || (declares.mcp !== "http" && declares.mcp !== "stdio"))
|
|
262
|
+
say(RECIPE_CODES.invalid, 'declares is { "load": true or false, "mcp": "http" or "stdio" }');
|
|
263
|
+
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")))
|
|
264
|
+
say(RECIPE_CODES.invalid, 'quirks is { "mcpCall": "match" or "mint" }');
|
|
265
|
+
if (r.description !== undefined && typeof r.description !== "string")
|
|
266
|
+
say(RECIPE_CODES.invalid, "description is a string");
|
|
267
|
+
return problems;
|
|
268
|
+
}
|
|
269
|
+
/** The recipe in `text`, or RecipeRefused with every problem. */
|
|
270
|
+
export function parseRecipe(text) {
|
|
271
|
+
let parsed;
|
|
272
|
+
try {
|
|
273
|
+
parsed = JSON.parse(text);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `not JSON (${error.message})` }]);
|
|
277
|
+
}
|
|
278
|
+
const problems = recipeProblems(parsed);
|
|
279
|
+
if (problems.length)
|
|
280
|
+
throw new RecipeRefused(problems[0].code, problems);
|
|
281
|
+
const r = parsed;
|
|
282
|
+
return Object.freeze({
|
|
283
|
+
id: r.id,
|
|
284
|
+
label: r.label,
|
|
285
|
+
release: r.release,
|
|
286
|
+
args: r.args ?? [],
|
|
287
|
+
keys: r.keys ?? [],
|
|
288
|
+
env: r.env ?? {},
|
|
289
|
+
model: r.model,
|
|
290
|
+
files: Object.fromEntries(Object.entries(r.files ?? {}).map(([path, content]) => [insideHome(path), content])),
|
|
291
|
+
state: (r.state ?? []).map((path) => insideHome(path)),
|
|
292
|
+
declares: r.declares,
|
|
293
|
+
quirks: r.quirks ?? {},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/** The recipe file at `path`, read and loaded. */
|
|
297
|
+
export function loadRecipe(path) {
|
|
298
|
+
const file = resolve(path);
|
|
299
|
+
let text;
|
|
300
|
+
try {
|
|
301
|
+
text = readFileSync(file, "utf8");
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `the recipe file ${file} cannot be read (${error.code ?? error.message})` }]);
|
|
305
|
+
}
|
|
306
|
+
return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex") };
|
|
307
|
+
}
|
|
308
|
+
/** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
|
|
309
|
+
export const releaseFor = (recipe, platform = archivePlatform()) => (platform ? recipe.release.archives[platform] : undefined);
|
|
310
|
+
/** The owner's command that installs the recipe at `file` into `data`. */
|
|
311
|
+
export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
|
312
|
+
/** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
|
|
313
|
+
export const recipeBinaryOf = (data, recipe, release) => join(installDirOf(data, recipe.id), insideHome(release.cmd));
|
|
314
|
+
/** Where the first sha256 of a binary the recipe does not pin is kept: beside the harnesses' folders, never inside the
|
|
315
|
+
* one an install replaces, so a reinstall that unpacks a different binary is seen. One per id, version and platform. */
|
|
316
|
+
export const firstSeenOf = (data, recipe, platform) => join(harnessesOf(data), ".first-seen", `${recipe.id}@${recipe.release.version}-${platform}.sha256`);
|
|
317
|
+
/** A first-seen digest record in a file of its own (one line, the sha256), written once and never over another's. */
|
|
318
|
+
export function firstSeenRecord(file) {
|
|
319
|
+
return {
|
|
320
|
+
read() {
|
|
321
|
+
if (!existsSync(file))
|
|
322
|
+
return undefined;
|
|
323
|
+
const recorded = readFileSync(file, "utf8").trim();
|
|
324
|
+
if (!SHA256.test(recorded))
|
|
325
|
+
throw new Error(`the recorded digest in ${file} is not a sha256`);
|
|
326
|
+
return recorded;
|
|
327
|
+
},
|
|
328
|
+
write(sha256) {
|
|
329
|
+
mkdirSync(join(file, ".."), { recursive: true, mode: 0o700 });
|
|
330
|
+
writeFileSync(file, `${sha256}\n`, { mode: 0o600, flag: "wx" });
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/** The sha256 the installed binary must have: the recipe's pin, else the first one its install recorded; undefined when it
|
|
335
|
+
* pins none and none was recorded (never installed by the owner's command). */
|
|
336
|
+
export function pinnedDigest(data, recipe, release, platform) {
|
|
337
|
+
if (release.binarySha256)
|
|
338
|
+
return { sha256: release.binarySha256, by: "recipe" };
|
|
339
|
+
const recorded = firstSeenRecord(firstSeenOf(data, recipe, platform)).read();
|
|
340
|
+
return recorded ? { sha256: recorded, by: "first-seen" } : undefined;
|
|
341
|
+
}
|
|
342
|
+
/** Installs the recipe's release into `<data>/harnesses/<id>` (the owner's command, rule 4): its archive downloaded and
|
|
343
|
+
* checked against the recipe's sha256, unpacked, and its binary checked against the recipe's pin, or recorded as the
|
|
344
|
+
* first one seen where the recipe pins none (a later one that differs is refused). */
|
|
345
|
+
export async function installRecipe(recipe, file, data, options = {}, env = process.env) {
|
|
346
|
+
const platform = options.platform ?? archivePlatform();
|
|
347
|
+
const release = releaseFor(recipe, platform);
|
|
348
|
+
const record = platform ? firstSeenRecord(firstSeenOf(data, recipe, platform)) : undefined;
|
|
349
|
+
const binary = release && !release.binarySha256 && record ? { binaryRecord: record } : {};
|
|
350
|
+
const before = release && !release.binarySha256 ? record?.read() : undefined;
|
|
351
|
+
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 });
|
|
352
|
+
// What the binary was held to: the recipe's pin, the first digest an earlier install recorded, or this one's, recorded now.
|
|
353
|
+
const pinnedBy = release?.binarySha256 ? "recipe" : before ? "first-seen" : "recorded";
|
|
354
|
+
return { version: recipe.release.version, pinnedBy, ...done };
|
|
355
|
+
}
|
|
356
|
+
/** The owner's command that checks the recipe at `file`, installed into `data`. */
|
|
357
|
+
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
|
@@ -80,12 +80,24 @@ export interface HarnessEntry {
|
|
|
80
80
|
* undefined while it is. One its owner installs (Goose: harness-goose.ts) is listed only once it is there and verified.
|
|
81
81
|
* It is still in the table, so a run or a save naming it is refused with these words. */
|
|
82
82
|
hidden?(env: NodeJS.ProcessEnv): string | undefined;
|
|
83
|
+
/** 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
|
|
84
|
+
* other harness never is (run-secrets.ts keysFor). */
|
|
85
|
+
readonly ownKeys?: readonly string[];
|
|
86
|
+
/** What its owner reads before running it (capabilities' `card`): who bills it, what stops it, whose terms it runs
|
|
87
|
+
* under. None for a harness that runs on this server's keys and cap. */
|
|
88
|
+
card?(env: NodeJS.ProcessEnv): string | undefined;
|
|
83
89
|
}
|
|
84
90
|
/** What a test's table module exports: entries by id, each merged over the built-in one of that id (all of it, for one
|
|
85
91
|
* the server has none of), given the built-ins to build on. Loaded with require: the module has no top-level await. */
|
|
86
92
|
export type HarnessTableModule = {
|
|
87
93
|
entries(builtins: Readonly<Record<string, HarnessEntry>>): Record<string, Partial<HarnessEntry>>;
|
|
88
94
|
};
|
|
95
|
+
/** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
|
|
96
|
+
* server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
|
|
97
|
+
export declare const BUILTIN_OWN_KEYS: readonly string[];
|
|
98
|
+
/** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
|
|
99
|
+
* needs it too): a recipe or module never takes one (harness-recipe.ts). */
|
|
100
|
+
export declare const BUILTIN_HARNESS_IDS: readonly string[];
|
|
89
101
|
/** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
|
|
90
102
|
* 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
103
|
* harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
|