@parcha/agentrun-serve 0.1.0-beta.52 → 0.1.0-beta.53
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 +122 -1
- package/README.md +213 -24
- package/dist/agent-delete.d.ts +5 -6
- package/dist/agent-delete.js +30 -67
- package/dist/agent-package.d.ts +71 -0
- package/dist/agent-package.js +345 -0
- package/dist/agents-store.d.ts +26 -20
- package/dist/agents-store.js +41 -33
- package/dist/api-only.d.ts +26 -6
- package/dist/api-only.js +35 -13
- package/dist/claude-login.d.ts +1 -0
- package/dist/claude-login.js +1 -1
- package/dist/cli-learning/cli.d.ts +3 -0
- package/dist/cli-learning/cli.js +17 -3
- package/dist/cli-learning/connections.js +3 -2
- package/dist/cli-learning/schema.js +2 -1
- package/dist/cli.js +70 -7
- package/dist/composio-preset.d.ts +2 -1
- package/dist/composio-preset.js +4 -3
- package/dist/composio-triggers.d.ts +4 -0
- package/dist/composio-triggers.js +4 -1
- package/dist/computer-needs.d.ts +32 -0
- package/dist/computer-needs.js +80 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +8 -1
- package/dist/console/assets/index-BFgyZzF_.js +734 -0
- package/dist/console/assets/index-DbilxljH.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +1 -0
- package/dist/console-links.js +2 -0
- package/dist/env-switch.d.ts +14 -0
- package/dist/env-switch.js +23 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/eval-previous.js +4 -3
- package/dist/fal-price.js +10 -13
- package/dist/handed-secret.d.ts +4 -0
- package/dist/handed-secret.js +10 -0
- package/dist/harness-archive.d.ts +15 -5
- package/dist/harness-archive.js +71 -34
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +36 -95
- package/dist/harness-egress.d.ts +23 -0
- package/dist/harness-egress.js +69 -0
- package/dist/harness-recipe-entry.d.ts +71 -0
- package/dist/harness-recipe-entry.js +184 -0
- package/dist/harness-recipe.d.ts +73 -6
- package/dist/harness-recipe.js +185 -31
- package/dist/harness-sign-in.d.ts +29 -0
- package/dist/harness-sign-in.js +122 -0
- package/dist/harness-table.d.ts +21 -0
- package/dist/harness-table.js +58 -3
- package/dist/harness-zip.d.ts +6 -0
- package/dist/harness-zip.js +203 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.js +36 -0
- package/dist/learn/commit.d.ts +14 -1
- package/dist/learn/commit.js +156 -1
- package/dist/learn/compile.js +22 -8
- package/dist/learn/folder.d.ts +5 -0
- package/dist/learn/folder.js +10 -1
- package/dist/learn/learning.sh +15 -3
- package/dist/learn/promote.d.ts +2 -2
- package/dist/learn/secrets.js +30 -7
- package/dist/learning-routes.d.ts +23 -11
- package/dist/learning-routes.js +110 -20
- package/dist/learning.d.ts +9 -6
- package/dist/learning.js +9 -4
- package/dist/mcp-gateway.js +15 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +7 -2
- package/dist/mcp-resources.d.ts +44 -0
- package/dist/mcp-resources.js +100 -0
- package/dist/mcp-servers-store.d.ts +16 -12
- package/dist/model.d.ts +4 -4
- package/dist/model.js +6 -6
- package/dist/native/cli.js +9 -2
- package/dist/native/connection.d.ts +2 -2
- package/dist/native/connection.js +5 -2
- package/dist/native/discovery.d.ts +2 -0
- package/dist/native/discovery.js +10 -6
- package/dist/native/remote-worker-bridge.js +36 -4
- package/dist/native/remote.d.ts +18 -1
- package/dist/native/remote.js +126 -37
- package/dist/native/schema.d.ts +6 -0
- package/dist/native/schema.js +31 -6
- package/dist/native/source-account.d.ts +13 -0
- package/dist/native/source-account.js +114 -0
- package/dist/native/source-capture-hooks.d.ts +5 -0
- package/dist/native/source-capture-hooks.js +102 -0
- package/dist/native/source-mcp-selection.d.ts +13 -0
- package/dist/native/source-mcp-selection.js +72 -0
- package/dist/native/source-runtime-tools.d.ts +19 -0
- package/dist/native/source-runtime-tools.js +103 -0
- package/dist/native/source-snapshot-types.d.ts +138 -0
- package/dist/native/source-snapshot-types.js +12 -0
- package/dist/native/source-snapshot.d.ts +8 -0
- package/dist/native/source-snapshot.js +1201 -0
- package/dist/observation/learning.js +3 -2
- package/dist/openapi.js +167 -36
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +12 -0
- package/dist/purged-workflow.js +43 -0
- package/dist/run-keys.d.ts +46 -0
- package/dist/run-keys.js +109 -0
- package/dist/run-launch.d.ts +16 -1
- package/dist/run-launch.js +30 -1
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-model-key.d.ts +2 -2
- package/dist/run-model-key.js +5 -5
- package/dist/run-secrets.d.ts +2 -0
- package/dist/run-secrets.js +7 -4
- package/dist/run-view.d.ts +17 -0
- package/dist/run-view.js +25 -1
- package/dist/runner/adapter-loop.d.ts +11 -3
- package/dist/runner/adapter-loop.js +138 -22
- package/dist/runner/adapter-run-spec.js +25 -12
- package/dist/runner/audit.d.ts +2 -0
- package/dist/runner/audit.js +9 -1
- package/dist/runner/beside.js +2 -1
- package/dist/runner/claim-secrets.d.ts +29 -3
- package/dist/runner/claim-secrets.js +38 -4
- package/dist/runner/cli-run-spec.js +23 -12
- package/dist/runner/harness-loops.d.ts +6 -0
- package/dist/runner/harness-loops.js +11 -1
- package/dist/runner/held.d.ts +4 -0
- package/dist/runner/journal-kinds.d.ts +2 -0
- package/dist/runner/learned-first.d.ts +2 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +7 -2
- package/dist/runner/learning-end.js +22 -10
- package/dist/runner/learning-seed.d.ts +9 -3
- package/dist/runner/learning-seed.js +2 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +20 -13
- package/dist/runner/mcp-claim.js +6 -1
- package/dist/runner/mcp-run.d.ts +10 -7
- package/dist/runner/mcp-run.js +3 -5
- package/dist/runner/monid-run.js +9 -11
- package/dist/runner/project-checkpoint.d.ts +35 -0
- package/dist/runner/project-checkpoint.js +116 -0
- package/dist/runner/project-drain.d.ts +8 -0
- package/dist/runner/project-drain.js +25 -0
- package/dist/runner/project-host.d.ts +10 -0
- package/dist/runner/project-host.js +52 -0
- package/dist/runner/promotion.d.ts +14 -6
- package/dist/runner/promotion.js +98 -41
- package/dist/runner/redact.d.ts +13 -0
- package/dist/runner/redact.js +67 -1
- package/dist/runner/run-channel.d.ts +9 -0
- package/dist/runner/run-channel.js +15 -2
- package/dist/runner/run-child-host.d.ts +8 -4
- package/dist/runner/run-child-host.js +171 -41
- package/dist/runner/run-errors.js +2 -2
- package/dist/runner/runner-check.js +5 -2
- package/dist/runner/runner.js +26 -9
- package/dist/runner/store-secrets.js +7 -3
- package/dist/runner/workflow-first.d.ts +4 -0
- package/dist/runner/workflow-first.js +13 -0
- package/dist/runner/workflow-loop.d.ts +2 -1
- package/dist/runner/workflow-loop.js +2 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.d.ts +34 -6
- package/dist/runs-over-store.js +133 -25
- package/dist/sdk/runs.d.ts +11 -1
- package/dist/sdk/runs.js +117 -26
- package/dist/sdk/schema.js +12 -2
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +68 -32
- package/dist/server.js +600 -110
- package/dist/skills/agentrun-serve/SKILL.md +2 -1
- package/dist/source-sync/adoption.d.ts +15 -0
- package/dist/source-sync/adoption.js +36 -0
- package/dist/source-sync/auxiliary.d.ts +23 -0
- package/dist/source-sync/auxiliary.js +64 -0
- package/dist/source-sync/capture-git.d.ts +5 -0
- package/dist/source-sync/capture-git.js +272 -0
- package/dist/source-sync/capture-project.d.ts +53 -0
- package/dist/source-sync/capture-project.js +206 -0
- package/dist/source-sync/capture-refusal.d.ts +7 -0
- package/dist/source-sync/capture-refusal.js +16 -0
- package/dist/source-sync/capture.d.ts +11 -0
- package/dist/source-sync/capture.js +22 -0
- package/dist/source-sync/checkpoint-gate.d.ts +21 -0
- package/dist/source-sync/checkpoint-gate.js +52 -0
- package/dist/source-sync/checkpoints.d.ts +66 -0
- package/dist/source-sync/checkpoints.js +168 -0
- package/dist/source-sync/claim.d.ts +11 -0
- package/dist/source-sync/claim.js +48 -0
- package/dist/source-sync/destination.d.ts +47 -0
- package/dist/source-sync/destination.js +239 -0
- package/dist/source-sync/io.d.ts +15 -0
- package/dist/source-sync/io.js +52 -0
- package/dist/source-sync/local.d.ts +43 -0
- package/dist/source-sync/local.js +229 -0
- package/dist/source-sync/prepare.d.ts +59 -0
- package/dist/source-sync/prepare.js +93 -0
- package/dist/source-sync/projects.d.ts +61 -0
- package/dist/source-sync/projects.js +130 -0
- package/dist/source-sync/registry.d.ts +95 -0
- package/dist/source-sync/registry.js +226 -0
- package/dist/source-sync/service.d.ts +33 -0
- package/dist/source-sync/service.js +118 -0
- package/dist/source-sync/skill-edits.d.ts +12 -0
- package/dist/source-sync/skill-edits.js +122 -0
- package/dist/source-sync/snapshots.d.ts +48 -0
- package/dist/source-sync/snapshots.js +448 -0
- package/dist/source-sync/types.d.ts +9 -0
- package/dist/source-sync/types.js +14 -0
- package/dist/source-sync/workspace.d.ts +66 -0
- package/dist/source-sync/workspace.js +273 -0
- package/dist/store/agent-body.d.ts +4 -0
- package/dist/store/agent-body.js +16 -5
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +2 -1
- package/dist/store/seal.d.ts +5 -1
- package/dist/store/seal.js +12 -3
- package/dist/store/sqlite/project-checkpoints.d.ts +11 -0
- package/dist/store/sqlite/project-checkpoints.js +70 -0
- package/dist/store/sqlite/run-launch.d.ts +4 -12
- package/dist/store/sqlite/run-launch.js +5 -19
- package/dist/store/sqlite/store.js +224 -170
- package/dist/store/store.d.ts +116 -39
- package/dist/store/store.js +14 -1
- package/dist/store-reads/learning.d.ts +2 -2
- package/dist/store-view.d.ts +3 -1
- package/dist/store-view.js +17 -5
- package/dist/template-import.d.ts +10 -2
- package/dist/template-import.js +116 -13
- package/dist/templates.d.ts +26 -5
- package/dist/templates.js +62 -10
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +8 -0
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +8 -8
- package/dist/trigger-launch-hook.d.ts +47 -0
- package/dist/trigger-launch-hook.js +90 -0
- package/dist/trigger-targets.d.ts +14 -1
- package/dist/trigger-targets.js +20 -0
- package/dist/triggers.d.ts +54 -5
- package/dist/triggers.js +143 -8
- package/dist/uploads-archil.js +1 -1
- package/dist/uploads.js +1 -1
- package/dist/validate.js +1 -2
- package/dist/workspace/computer-for-claim.d.ts +2 -0
- package/dist/workspace/computer-for-claim.js +43 -0
- package/dist/workspace/paths.d.ts +6 -0
- package/dist/workspace/paths.js +6 -0
- package/dist/workspace/resolve-computer.d.ts +1 -0
- package/dist/workspace/run-tools.d.ts +2 -0
- package/dist/workspace/run-tools.js +8 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +2 -1
- package/templates/README.md +5 -2
- package/dist/console/assets/index-B-D0EM3j.js +0 -733
- package/dist/console/assets/index-DlQepP2J.css +0 -1
package/dist/harness-check.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { egressProxy } from "./harness-egress.js";
|
|
1
2
|
export declare const CHECK_DEFAULT_CAP_USD = 0.25;
|
|
2
3
|
export interface HarnessCheckOptions {
|
|
3
4
|
/** The recipe file. */
|
|
@@ -63,6 +64,7 @@ export interface HarnessCheckReport {
|
|
|
63
64
|
checkedAt: string;
|
|
64
65
|
failures: string[];
|
|
65
66
|
}
|
|
67
|
+
export { egressProxy };
|
|
66
68
|
/** Runs the check. Never throws for what it judges: a refused recipe, a missing install or a failed stage is in the
|
|
67
69
|
* report (`ok: false`, `failures`). Every string of the report and every line it says has the server's secrets and the
|
|
68
70
|
* recipe's keys cut (runner/redact.ts secretRedactor), so an agent's words in it (a failed turn's stderr, a refusal, a
|
|
@@ -72,4 +74,3 @@ export declare function harnessCheck(options: HarnessCheckOptions): Promise<Harn
|
|
|
72
74
|
export declare function printedFacts(report: HarnessCheckReport): string[];
|
|
73
75
|
/** Writes the report to `file`. */
|
|
74
76
|
export declare const writeReport: (file: string, report: HarnessCheckReport) => Promise<void>;
|
|
75
|
-
export {};
|
package/dist/harness-check.js
CHANGED
|
@@ -17,25 +17,21 @@ import { spawnSync } from "node:child_process";
|
|
|
17
17
|
import { randomBytes } from "node:crypto";
|
|
18
18
|
import { existsSync, readFileSync } from "node:fs";
|
|
19
19
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
20
|
-
import { createServer } from "node:http";
|
|
21
|
-
import { connect as netConnect } from "node:net";
|
|
22
20
|
import { tmpdir } from "node:os";
|
|
23
21
|
import { join } from "node:path";
|
|
24
22
|
import { modelPortFor, SessionFenced } from "@parcha/agentrun-kernel";
|
|
25
23
|
import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
26
24
|
import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
|
|
27
25
|
import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
|
|
26
|
+
import { egressProxy, egressVars } from "./harness-egress.js";
|
|
28
27
|
import { installDirOf } from "./harness-install.js";
|
|
29
|
-
import { AGENT_VARS, loadRecipe, pinnedDigest, recipeBinaryOf, recipeInstallLine, RecipeRefused, releaseFor } from "./harness-recipe.js";
|
|
30
|
-
import {
|
|
28
|
+
import { AGENT_VARS, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeInstallLine, RecipeRefused, releaseFor, writeChecked } from "./harness-recipe.js";
|
|
29
|
+
import { recipeEntryOf } from "./harness-recipe-entry.js";
|
|
31
30
|
import { providerModels } from "./model.js";
|
|
32
31
|
import { capModelOf } from "./runner/cli-run-spec.js";
|
|
33
32
|
import { keyShaped } from "./secret-name.js";
|
|
34
33
|
import { secretRedactor } from "./runner/redact.js";
|
|
35
34
|
import { hostSecrets, SECRET_NAMES } from "./secrets.js";
|
|
36
|
-
/** The proxy variables the check points at its own egress proxy, in both cases, whatever the recipe sets. */
|
|
37
|
-
const EGRESS_VARS = ["HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy"];
|
|
38
|
-
const NO_PROXY_VARS = ["NO_PROXY", "no_proxy"];
|
|
39
35
|
/** What a shell sets for itself when the binary is a script (its working directory, its depth): never the host's. */
|
|
40
36
|
const SHELL_OWN = ["PWD", "OLDPWD", "SHLVL", "_"];
|
|
41
37
|
export const CHECK_DEFAULT_CAP_USD = 0.25;
|
|
@@ -64,50 +60,7 @@ function checkStore() {
|
|
|
64
60
|
},
|
|
65
61
|
};
|
|
66
62
|
}
|
|
67
|
-
|
|
68
|
-
/** A loopback HTTP proxy that records what the agent reaches for beyond loopback. It tunnels a CONNECT to one of `vendor`
|
|
69
|
-
* (a plan-billed recipe's model.hosts, `host` for port 443 or `host:port`) and refuses everything else. */
|
|
70
|
-
async function egressProxy(vendor = []) {
|
|
71
|
-
const asked = [];
|
|
72
|
-
const sockets = new Set();
|
|
73
|
-
const allowed = new Set(vendor.map((host) => (host.includes(":") ? host : `${host}:443`)));
|
|
74
|
-
const server = createServer((req, res) => {
|
|
75
|
-
asked.push({ method: req.method ?? "GET", target: req.url ?? "", tunneled: false });
|
|
76
|
-
res.writeHead(403).end();
|
|
77
|
-
});
|
|
78
|
-
server.on("connect", (req, socket, head) => {
|
|
79
|
-
const target = req.url ?? "";
|
|
80
|
-
const tunneled = allowed.has(target);
|
|
81
|
-
asked.push({ method: "CONNECT", target, tunneled });
|
|
82
|
-
if (!tunneled)
|
|
83
|
-
return void socket.end("HTTP/1.1 403 Forbidden\r\ncontent-length: 0\r\n\r\n");
|
|
84
|
-
const at = target.lastIndexOf(":");
|
|
85
|
-
const upstream = netConnect({ host: target.slice(0, at), port: Number(target.slice(at + 1)) }, () => {
|
|
86
|
-
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
87
|
-
if (head.length)
|
|
88
|
-
upstream.write(head);
|
|
89
|
-
upstream.pipe(socket);
|
|
90
|
-
socket.pipe(upstream);
|
|
91
|
-
});
|
|
92
|
-
sockets.add(upstream);
|
|
93
|
-
upstream.on("close", () => (sockets.delete(upstream), socket.destroy()));
|
|
94
|
-
upstream.on("error", () => socket.end("HTTP/1.1 502 Bad Gateway\r\ncontent-length: 0\r\n\r\n"));
|
|
95
|
-
socket.on("error", () => upstream.destroy());
|
|
96
|
-
socket.on("close", () => upstream.destroy());
|
|
97
|
-
});
|
|
98
|
-
server.on("connection", (socket) => (sockets.add(socket), socket.on("close", () => sockets.delete(socket))));
|
|
99
|
-
await new Promise((resolve) => server.listen(0, LOOPBACK, resolve));
|
|
100
|
-
const port = server.address().port;
|
|
101
|
-
return {
|
|
102
|
-
url: `http://${LOOPBACK}:${port}`,
|
|
103
|
-
asked,
|
|
104
|
-
close: () => new Promise((resolve) => {
|
|
105
|
-
for (const socket of sockets)
|
|
106
|
-
socket.destroy();
|
|
107
|
-
server.close(() => resolve());
|
|
108
|
-
}),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
63
|
+
export { egressProxy };
|
|
111
64
|
/** A process's environment, by name, from /proc (Linux); undefined elsewhere or once it is gone. */
|
|
112
65
|
function environOf(pid) {
|
|
113
66
|
try {
|
|
@@ -203,6 +156,10 @@ async function checkRun(options, held) {
|
|
|
203
156
|
const head = { recipe: { id: recipe.id, label: recipe.label, file: loaded.file, sha256: loaded.sha256 }, checkedAt };
|
|
204
157
|
const refuse = (code, message) => ({ ok: false, ...head, refused: { code, message: `${code}: ${message}` }, failures: [`${code}: ${message}`] });
|
|
205
158
|
say(`${recipe.label}: the recipe holds the five rules (${loaded.file})`);
|
|
159
|
+
// What the agent runs on: the recipe's keys, read from this shell, alone (a proxy-billed one's: none, the model proxy's).
|
|
160
|
+
// A check never runs on its owner's own sign-in, which a schedule, a check and a shared server never take
|
|
161
|
+
// (HARNESS.md#sign-in): a plan-billed recipe whose key is not set here is refused before its agent starts.
|
|
162
|
+
const route = { on: "keys" };
|
|
206
163
|
// Stage 2's pins: the installed binary, the one the owner's install put there. Nothing is downloaded here.
|
|
207
164
|
const platform = options.platform ?? archivePlatform();
|
|
208
165
|
const release = releaseFor(recipe, platform);
|
|
@@ -220,6 +177,17 @@ async function checkRun(options, held) {
|
|
|
220
177
|
const acp = acpPackage();
|
|
221
178
|
if (!acp)
|
|
222
179
|
return refuse("HARNESS_NOT_INSTALLED", `the ACP adapter (${ACP_PACKAGE}) is not installed beside this server`);
|
|
180
|
+
// Every file beside the binary (a launcher's code, a server's sidecar): the recipe's treeSha256, else the tree its
|
|
181
|
+
// install recorded. One installed before trees were recorded is installed again, so nothing in it runs unpinned.
|
|
182
|
+
const installed = installDirOf(options.data, recipe.id);
|
|
183
|
+
const treePin = pinnedTree(options.data, recipe, release, platform);
|
|
184
|
+
if (!treePin)
|
|
185
|
+
return refuse("HARNESS_NOT_INSTALLED", `${recipe.label} ${recipe.release.version}'s files beside its binary were never recorded by its install, so they cannot be checked. Install it again with: ${line}`);
|
|
186
|
+
const treeNow = async () => acp.treeDigest(installed).catch(() => undefined);
|
|
187
|
+
const treeFound = await treeNow();
|
|
188
|
+
if (treeFound !== treePin.sha256)
|
|
189
|
+
return refuse(ARCHIVE_CODES.binary, `${installed} has the tree sha256 ${treeFound ?? "(unreadable)"}, and ${treePin.by === "recipe" ? "the recipe pins" : "its first install recorded"} ${treePin.sha256}. Install it again with: ${line}`);
|
|
190
|
+
say(`${recipe.label}: every file beside the binary is the pinned tree (${treePin.by === "recipe" ? "the recipe's treeSha256" : "the tree its install recorded"})`);
|
|
223
191
|
// The run's model, for a recipe billed through the proxy: named here; its key, the login refusal and its price are its
|
|
224
192
|
// entry's (below), as a server's are.
|
|
225
193
|
const env = options.env;
|
|
@@ -275,26 +243,11 @@ async function checkRun(options, held) {
|
|
|
275
243
|
// The values of every key the host holds, the server's own included: withSecrets keeps those off its enumeration, so
|
|
276
244
|
// each is read by name.
|
|
277
245
|
const hostKeys = keyValues(env, recipe.keys);
|
|
278
|
-
const childVars = { ...recipe.env };
|
|
279
|
-
for (const name of EGRESS_VARS)
|
|
280
|
-
childVars[name] = egress.url;
|
|
281
|
-
for (const name of NO_PROXY_VARS)
|
|
282
|
-
childVars[name] = `${LOOPBACK},localhost`; // key-gate: loopback-rule the hosts the agent reaches without the refusing proxy: the model proxy and MCP on this machine
|
|
246
|
+
const childVars = { ...recipe.env, ...egressVars(egress.url) };
|
|
283
247
|
// The run's model id reaches a proxy-billed agent under the variable its recipe names.
|
|
284
248
|
const modelVar = recipe.model.billing === "proxy" ? recipe.model.env : undefined;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
label: recipe.label,
|
|
288
|
-
command: binary,
|
|
289
|
-
args: [...recipe.args],
|
|
290
|
-
env: { ...childVars, ...(modelVar && model !== undefined ? { [modelVar]: model } : {}) },
|
|
291
|
-
keys: [...recipe.keys],
|
|
292
|
-
files: { ...recipe.files },
|
|
293
|
-
state: [...recipe.state],
|
|
294
|
-
declares: { ...recipe.declares },
|
|
295
|
-
billing: recipe.model.billing === "proxy" ? { kind: "proxy" } : { kind: "plan", maxTurns: recipe.model.maxTurns, maxToolCalls: recipe.model.maxToolCalls },
|
|
296
|
-
...(recipe.quirks.mcpCall ? { quirks: { mcpCall: recipe.quirks.mcpCall } } : {}),
|
|
297
|
-
});
|
|
249
|
+
// The plan's model, where the recipe names one: chosen among those the agent lists (session/set_model).
|
|
250
|
+
const planModel = recipe.model.billing === "plan" ? recipe.model.id : undefined;
|
|
298
251
|
const starts = [];
|
|
299
252
|
// Each start of the agent's process checks the pin again: a binary swapped after the check began never runs.
|
|
300
253
|
const beforeStart = async (command) => {
|
|
@@ -302,31 +255,14 @@ async function checkRun(options, held) {
|
|
|
302
255
|
starts.push(now);
|
|
303
256
|
if (now !== pin.sha256)
|
|
304
257
|
throw new Error(`${ARCHIVE_CODES.binary}: ${command} changed after the check began (sha256 ${now})`);
|
|
258
|
+
const tree = await treeNow();
|
|
259
|
+
if (tree !== treePin.sha256)
|
|
260
|
+
throw new Error(`${ARCHIVE_CODES.binary}: the files beside ${command} changed after the check began (tree sha256 ${tree ?? "(unreadable)"})`);
|
|
305
261
|
};
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const proxyAt = recipe.model.billing === "proxy" ? (recipe.model.hostEnv ?? "ANTHROPIC_HOST") : "ANTHROPIC_HOST";
|
|
311
|
-
const entry = needs ? acpEntryOf({
|
|
312
|
-
facts: { ...acp.gooseFacts, id: recipe.id, label: recipe.label },
|
|
313
|
-
recipe: (launch) => acpRecipeOf(launch.model),
|
|
314
|
-
proxy: (launch) => {
|
|
315
|
-
const messagesProxy = acp.gooseProxy({ model: launch.model, provider: launch.provider, price: launch.price, log: launch.log, fetch: recording });
|
|
316
|
-
return async (session) => {
|
|
317
|
-
// The proxy's own address, under proxyAt, beside the key that opens it alone (never a provider's).
|
|
318
|
-
const started = await messagesProxy(session);
|
|
319
|
-
const { ANTHROPIC_HOST: address, ...opens } = started.env;
|
|
320
|
-
return { env: { ...opens, [proxyAt]: address }, close: started.close };
|
|
321
|
-
};
|
|
322
|
-
},
|
|
323
|
-
beforeStart,
|
|
324
|
-
}, { log }) : acpEntryOf({
|
|
325
|
-
facts: { ...acp.cursorFacts, id: recipe.id, label: recipe.label },
|
|
326
|
-
recipe: () => acpRecipeOf(),
|
|
327
|
-
beforeStart,
|
|
328
|
-
}, { log });
|
|
329
|
-
const planNeeds = { model: { provider: recipe.id, modelId: "default" }, models: { getModel: () => undefined } };
|
|
262
|
+
// The recipe's entry as a server builds it (harness-recipe-entry.ts), on this check's route, log, variables (its egress
|
|
263
|
+
// proxy) and recording fetch.
|
|
264
|
+
const entry = recipeEntryOf({ recipe, binary, release, route: () => route, beforeStart, vars: () => childVars, fetch: recording, log });
|
|
265
|
+
const planNeeds = { model: { provider: recipe.id, modelId: planModel ?? "default" }, models: { getModel: () => undefined } };
|
|
330
266
|
const adapterFor = async () => entry.adapter(hostEnv, needs ?? planNeeds);
|
|
331
267
|
// The first runner's adapter is made before any turn, so a model this server can't run is refused before the agent
|
|
332
268
|
// starts; with it, the cap's model, priced here or refused.
|
|
@@ -409,8 +345,9 @@ async function checkRun(options, held) {
|
|
|
409
345
|
stage2.tools_off = { ok: null, why: "plan billing: the vendor's model requests never reach this host, so the tools it offers are not seen" };
|
|
410
346
|
// Stage 2: the environment is the allowlist.
|
|
411
347
|
if (environ) {
|
|
412
|
-
// The recipe's keys too: the adapter hands each over
|
|
413
|
-
|
|
348
|
+
// The recipe's keys too: the adapter hands each over under the name its agent reads (recipe.keyEnv, else its own),
|
|
349
|
+
// never through childVars.
|
|
350
|
+
const expected = new Set([...Object.values(AGENT_VARS).flat(), ...Object.keys(childVars), ...(modelVar ? [modelVar] : []), ...recipe.keys.map((name) => recipe.keyEnv[name] ?? name), ...SHELL_OWN]);
|
|
414
351
|
const extra = Object.keys(environ).filter((name) => !expected.has(name)).sort();
|
|
415
352
|
const leaked = Object.entries(environ).filter(([, value]) => hostKeys.includes(value) || value === canary).map(([name]) => name).sort();
|
|
416
353
|
stage2.env_allowlist = { ok: extra.length === 0 && leaked.length === 0, names: Object.keys(environ).sort(), beyondAllowlist: extra, hostSecretsSeen: leaked };
|
|
@@ -482,6 +419,10 @@ async function checkRun(options, held) {
|
|
|
482
419
|
for (const name of ["mcp_tool", "resume", "denied_call", "other_runner"])
|
|
483
420
|
if (!(name in stage3) && !failures.some((f) => f.startsWith("the check stopped")))
|
|
484
421
|
failures.push(`stage3.${name} did not run`);
|
|
422
|
+
// A pass is noted on the data directory, by digest, for a server that names the recipe (harness-recipe-entry.ts
|
|
423
|
+
// recipeServerEntry): it runs this recipe, binary and tree, and no other.
|
|
424
|
+
if (failures.length === 0)
|
|
425
|
+
writeChecked(options.data, recipe.id, { recipe: loaded.sha256, binary: pin.sha256, tree: treePin.sha256, version: recipe.release.version, platform });
|
|
485
426
|
return {
|
|
486
427
|
ok: failures.length === 0,
|
|
487
428
|
...head,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The proxy variables the agent is pointed at the egress proxy by, whatever the recipe sets. */
|
|
2
|
+
export declare const EGRESS_VARS: string[];
|
|
3
|
+
export declare const NO_PROXY_VARS: string[];
|
|
4
|
+
/** The variables that send the agent's requests beyond loopback to the proxy at `url`, and the hosts it reaches on this
|
|
5
|
+
* machine without it (the model proxy, MCP) around it. */
|
|
6
|
+
export declare function egressVars(url: string): Record<string, string>;
|
|
7
|
+
export interface EgressProxy {
|
|
8
|
+
readonly url: string;
|
|
9
|
+
/** What a client asked it for (harness-check's report); empty where it was started with `record` false. */
|
|
10
|
+
readonly asked: {
|
|
11
|
+
method: string;
|
|
12
|
+
target: string;
|
|
13
|
+
tunneled: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
/** A loopback HTTP proxy that tunnels a CONNECT to one of `vendor` (a plan-billed recipe's model.hosts, `host` for port
|
|
18
|
+
* 443 or `host:port`) and refuses everything else. `record`: keep what it is asked (a check's, for its report; a
|
|
19
|
+
* server's keeps nothing, so its memory never grows with its runs). `unref`: it never holds its process open. */
|
|
20
|
+
export declare function egressProxy(vendor?: readonly string[], { record, unref }?: {
|
|
21
|
+
record?: boolean;
|
|
22
|
+
unref?: boolean;
|
|
23
|
+
}): Promise<EgressProxy>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// What a recipe's agent reaches beyond loopback (HARNESS.md#a-recipe): a loopback HTTP proxy that tunnels a CONNECT to
|
|
2
|
+
// one of the hosts a plan-billed recipe's model.hosts names and refuses everything else. harness-check runs one per check
|
|
3
|
+
// and lists what it saw; a server runs one per recipe for its runs, so model.hosts holds on a run as on the check.
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import { connect as netConnect } from "node:net";
|
|
6
|
+
/** The proxy variables the agent is pointed at the egress proxy by, whatever the recipe sets. */
|
|
7
|
+
export const EGRESS_VARS = ["HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy"];
|
|
8
|
+
export const NO_PROXY_VARS = ["NO_PROXY", "no_proxy"];
|
|
9
|
+
const LOOPBACK = "127.0.0.1"; // key-gate: loopback-rule the one address the refusing egress proxy listens on
|
|
10
|
+
/** The variables that send the agent's requests beyond loopback to the proxy at `url`, and the hosts it reaches on this
|
|
11
|
+
* machine without it (the model proxy, MCP) around it. */
|
|
12
|
+
export function egressVars(url) {
|
|
13
|
+
const vars = {};
|
|
14
|
+
for (const name of EGRESS_VARS)
|
|
15
|
+
vars[name] = url;
|
|
16
|
+
for (const name of NO_PROXY_VARS)
|
|
17
|
+
vars[name] = `${LOOPBACK},localhost`; // key-gate: loopback-rule the hosts the agent reaches without the refusing proxy: the model proxy and MCP on this machine
|
|
18
|
+
return vars;
|
|
19
|
+
}
|
|
20
|
+
/** A loopback HTTP proxy that tunnels a CONNECT to one of `vendor` (a plan-billed recipe's model.hosts, `host` for port
|
|
21
|
+
* 443 or `host:port`) and refuses everything else. `record`: keep what it is asked (a check's, for its report; a
|
|
22
|
+
* server's keeps nothing, so its memory never grows with its runs). `unref`: it never holds its process open. */
|
|
23
|
+
export async function egressProxy(vendor = [], { record = true, unref = false } = {}) {
|
|
24
|
+
const asked = [];
|
|
25
|
+
const note = (entry) => void (record && asked.push(entry));
|
|
26
|
+
const sockets = new Set();
|
|
27
|
+
const allowed = new Set(vendor.map((host) => (host.includes(":") ? host : `${host}:443`)));
|
|
28
|
+
const server = createServer((req, res) => {
|
|
29
|
+
// A client of a proxy names where it goes (absolute-form); a request for a path alone (origin-form) is one to this
|
|
30
|
+
// port as a server, such as another process's poll of a port this proxy reused: refused, and not the agent's.
|
|
31
|
+
if (!(req.url ?? "").startsWith("/"))
|
|
32
|
+
note({ method: req.method ?? "GET", target: req.url ?? "", tunneled: false });
|
|
33
|
+
res.writeHead(403).end();
|
|
34
|
+
});
|
|
35
|
+
server.on("connect", (req, socket, head) => {
|
|
36
|
+
const target = req.url ?? "";
|
|
37
|
+
const tunneled = allowed.has(target);
|
|
38
|
+
note({ method: "CONNECT", target, tunneled });
|
|
39
|
+
if (!tunneled)
|
|
40
|
+
return void socket.end("HTTP/1.1 403 Forbidden\r\ncontent-length: 0\r\n\r\n");
|
|
41
|
+
const at = target.lastIndexOf(":");
|
|
42
|
+
const upstream = netConnect({ host: target.slice(0, at), port: Number(target.slice(at + 1)) }, () => {
|
|
43
|
+
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
44
|
+
if (head.length)
|
|
45
|
+
upstream.write(head);
|
|
46
|
+
upstream.pipe(socket);
|
|
47
|
+
socket.pipe(upstream);
|
|
48
|
+
});
|
|
49
|
+
sockets.add(upstream);
|
|
50
|
+
upstream.on("close", () => (sockets.delete(upstream), socket.destroy()));
|
|
51
|
+
upstream.on("error", () => socket.end("HTTP/1.1 502 Bad Gateway\r\ncontent-length: 0\r\n\r\n"));
|
|
52
|
+
socket.on("error", () => upstream.destroy());
|
|
53
|
+
socket.on("close", () => upstream.destroy());
|
|
54
|
+
});
|
|
55
|
+
server.on("connection", (socket) => (sockets.add(socket), socket.on("close", () => sockets.delete(socket))));
|
|
56
|
+
await new Promise((resolve) => server.listen(0, LOOPBACK, resolve));
|
|
57
|
+
if (unref)
|
|
58
|
+
server.unref();
|
|
59
|
+
const port = server.address().port;
|
|
60
|
+
return {
|
|
61
|
+
url: `http://${LOOPBACK}:${port}`,
|
|
62
|
+
asked,
|
|
63
|
+
close: () => new Promise((resolve) => {
|
|
64
|
+
for (const socket of sockets)
|
|
65
|
+
socket.destroy();
|
|
66
|
+
server.close(() => resolve());
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AcpRecipe } from "@parcha/agentrun-harness-acp";
|
|
2
|
+
import { type Recipe, type RecipeArchive } from "./harness-recipe.js";
|
|
3
|
+
import { type AcpEntryHost, type HarnessEntry } from "./harness-table.js";
|
|
4
|
+
/** A recipe with a sign-in on a server started with --harness-sign-in, whose owner has not signed its agent in on this
|
|
5
|
+
* data directory. */
|
|
6
|
+
export declare const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
|
|
7
|
+
/** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
|
|
8
|
+
* it would run (harness-recipe.ts checkedOf). */
|
|
9
|
+
export declare const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
|
|
10
|
+
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone: this server saves none yet (the
|
|
11
|
+
* cut every child's environment takes keeps the server's own out), so it runs under harness-check, or on its owner's
|
|
12
|
+
* own sign-in on their own machine (--harness-sign-in). */
|
|
13
|
+
export declare const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
|
|
14
|
+
/** What a recipe's agent runs on: its keys (each read by its saved name where it runs; none for a proxy-billed agent,
|
|
15
|
+
* on the model proxy), or its owner's own sign-in, whose folder (`home`) the agent is handed by signIn.homeArg. */
|
|
16
|
+
export type RecipeRoute = {
|
|
17
|
+
readonly on: "keys";
|
|
18
|
+
} | {
|
|
19
|
+
readonly on: "sign-in";
|
|
20
|
+
readonly home: string;
|
|
21
|
+
};
|
|
22
|
+
/** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
|
|
23
|
+
* saved for its harness alone, which come first wherever they are saved; none are yet (HARNESS_KEYS_NOT_SAVED). Its
|
|
24
|
+
* owner's own sign-in only where `signIn` (the server's --harness-sign-in: one owner, on their own machine, its runs as
|
|
25
|
+
* its own user, which the start proved) and only for a person's run (a scheduled or triggered one is refused at its
|
|
26
|
+
* claim, run-child-host.ts staysInRunner). harness-check never takes this route: it runs on the recipe's keys alone. */
|
|
27
|
+
export declare function serverRoute(recipe: Recipe, file: string, data: string, env: NodeJS.ProcessEnv, { signIn }: {
|
|
28
|
+
signIn: boolean;
|
|
29
|
+
}): RecipeRoute | {
|
|
30
|
+
refused: string;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
/** The ACP adapter's recipe for one start of `recipe`'s agent on `route`: the installed `binary`, the platform's own
|
|
34
|
+
* arguments where its release lists them (else the recipe's), and on the sign-in its folder after them. On its keys:
|
|
35
|
+
* each under the name its agent reads, and the method it signs in with on them. On the sign-in: no key, no
|
|
36
|
+
* authenticate, and nothing the agent prints kept (stderr "none"), since no cut knows its token. `vars` are the
|
|
37
|
+
* caller's beside the recipe's env (harness-check's egress proxy); `model` the run's (a proxy-billed agent's under
|
|
38
|
+
* model.env; a plan's chosen among those it lists, the recipe's model.id where the run names its default). */
|
|
39
|
+
export declare function acpRecipeFor(recipe: Recipe, binary: string, release: RecipeArchive, route: RecipeRoute, { vars, model }?: {
|
|
40
|
+
vars?: Readonly<Record<string, string>>;
|
|
41
|
+
model?: string;
|
|
42
|
+
}): AcpRecipe;
|
|
43
|
+
/** What recipeEntryOf builds `recipe`'s entry from: its installed `binary` and `release`, the route of each start (it
|
|
44
|
+
* may throw a HarnessUnavailable), the check before each start, and what harness-check adds (its log, its variables,
|
|
45
|
+
* the fetch its model proxy records with). `missing` and `hidden` are a server's (recipeServerEntry). */
|
|
46
|
+
export interface RecipeEntryOptions extends AcpEntryHost {
|
|
47
|
+
readonly recipe: Recipe;
|
|
48
|
+
readonly binary: string;
|
|
49
|
+
readonly release: RecipeArchive;
|
|
50
|
+
route(env: NodeJS.ProcessEnv): RecipeRoute;
|
|
51
|
+
beforeStart(command: string): Promise<void>;
|
|
52
|
+
/** The variables beside the recipe's env at each start: the egress proxy's (harness-egress.ts egressVars). */
|
|
53
|
+
vars(): Readonly<Record<string, string>>;
|
|
54
|
+
readonly fetch?: typeof fetch;
|
|
55
|
+
missing?(env: NodeJS.ProcessEnv): Promise<string | undefined>;
|
|
56
|
+
hidden?(env: NodeJS.ProcessEnv): string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** `recipe`'s whole entry, as an ACP agent outside the built-ins starts (harness-table.ts acpEntryOf). Proxy-billed: as a
|
|
59
|
+
* module's, its model and key chosen and a login refused there, its price, the adapter over its recipe and the
|
|
60
|
+
* session's model proxy (the one on Anthropic's Messages there is, Goose's policy, its address under the variable the
|
|
61
|
+
* recipe names). Billed to its plan: as Cursor's, on the model the recipe names or its vendor's own default. */
|
|
62
|
+
export declare function recipeEntryOf(options: RecipeEntryOptions): HarnessEntry;
|
|
63
|
+
/** The entry of the recipe at `file` on a server whose data directory is `data` (harness-table.ts HARNESS_RECIPES_ENV),
|
|
64
|
+
* loaded under its five rules when the table is (a refused one refuses the start, in words). It runs only on the
|
|
65
|
+
* install its owner made and checked: hidden, and each run refused, with the command that fixes it, until the binary
|
|
66
|
+
* and every file beside it are the pinned ones and a harness-check passed for this very recipe, binary and tree
|
|
67
|
+
* (HARNESS_NOT_CHECKED). Each start of its agent checks the binary and the tree against their pins again. It runs on
|
|
68
|
+
* the route serverRoute gives, its owner's sign-in only where `signIn` (--harness-sign-in). */
|
|
69
|
+
export declare function recipeServerEntry(file: string, data: string, { signIn }?: {
|
|
70
|
+
signIn?: boolean;
|
|
71
|
+
}): HarnessEntry;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// A recipe's harness entry (HARNESS.md#a-recipe), built once for both of its uses: `agentrun harness-check`, which runs
|
|
2
|
+
// it for real and judges it on its keys, and a server that names it (--harness-recipe), whose runs start it the same way
|
|
3
|
+
// (serverRoute). Only a single-owner server on its owner's own machine (--harness-sign-in) runs one on its owner's own
|
|
4
|
+
// sign-in, handing the agent the folder's path and nothing else. AgentRun never reads, refreshes or sends the agent's
|
|
5
|
+
// token (HARNESS.md#sign-in): nothing here opens a file at all.
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
|
|
8
|
+
import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
|
|
9
|
+
import { egressProxy, egressVars } from "./harness-egress.js";
|
|
10
|
+
import { installDirOf } from "./harness-install.js";
|
|
11
|
+
import { checkedOf, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeCheckLine, recipeInstallLine, recipeSignInLine, releaseFor, signedIn, signInHomeOf } from "./harness-recipe.js";
|
|
12
|
+
import { acpEntryOf } from "./harness-table.js";
|
|
13
|
+
import { HarnessUnavailable } from "./provider.js";
|
|
14
|
+
/** A recipe with a sign-in on a server started with --harness-sign-in, whose owner has not signed its agent in on this
|
|
15
|
+
* data directory. */
|
|
16
|
+
export const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
|
|
17
|
+
/** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
|
|
18
|
+
* it would run (harness-recipe.ts checkedOf). */
|
|
19
|
+
export const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
|
|
20
|
+
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone: this server saves none yet (the
|
|
21
|
+
* cut every child's environment takes keeps the server's own out), so it runs under harness-check, or on its owner's
|
|
22
|
+
* own sign-in on their own machine (--harness-sign-in). */
|
|
23
|
+
export const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
|
|
24
|
+
/** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
|
|
25
|
+
* saved for its harness alone, which come first wherever they are saved; none are yet (HARNESS_KEYS_NOT_SAVED). Its
|
|
26
|
+
* owner's own sign-in only where `signIn` (the server's --harness-sign-in: one owner, on their own machine, its runs as
|
|
27
|
+
* its own user, which the start proved) and only for a person's run (a scheduled or triggered one is refused at its
|
|
28
|
+
* claim, run-child-host.ts staysInRunner). harness-check never takes this route: it runs on the recipe's keys alone. */
|
|
29
|
+
export function serverRoute(recipe, file, data, env, { signIn }) {
|
|
30
|
+
if (recipe.model.billing === "proxy")
|
|
31
|
+
return { on: "keys" };
|
|
32
|
+
if (signIn && recipe.signIn) {
|
|
33
|
+
if (signedIn(data, recipe))
|
|
34
|
+
return { on: "sign-in", home: signInHomeOf(data, recipe.id) };
|
|
35
|
+
return { refused: HARNESS_NOT_SIGNED_IN, message: `${recipe.label} runs on this server on its owner's own sign-in (--harness-sign-in), and its agent is not signed in here: sign it in with: ${recipeSignInLine(file, data, env)}` };
|
|
36
|
+
}
|
|
37
|
+
const own = recipe.signIn ? "; on your own machine alone, a server started with --harness-sign-in runs it on your own sign-in" : "";
|
|
38
|
+
return { refused: HARNESS_KEYS_NOT_SAVED, message: `${recipe.label} runs on its keys (${recipe.keys.join(", ")}) saved for this harness alone, and this server saves no harness's keys yet: check it with harness-check, where its keys are read from your shell${own}` };
|
|
39
|
+
}
|
|
40
|
+
/** The ACP adapter's recipe for one start of `recipe`'s agent on `route`: the installed `binary`, the platform's own
|
|
41
|
+
* arguments where its release lists them (else the recipe's), and on the sign-in its folder after them. On its keys:
|
|
42
|
+
* each under the name its agent reads, and the method it signs in with on them. On the sign-in: no key, no
|
|
43
|
+
* authenticate, and nothing the agent prints kept (stderr "none"), since no cut knows its token. `vars` are the
|
|
44
|
+
* caller's beside the recipe's env (harness-check's egress proxy); `model` the run's (a proxy-billed agent's under
|
|
45
|
+
* model.env; a plan's chosen among those it lists, the recipe's model.id where the run names its default). */
|
|
46
|
+
export function acpRecipeFor(recipe, binary, release, route, { vars = {}, model } = {}) {
|
|
47
|
+
const modelVar = recipe.model.billing === "proxy" ? recipe.model.env : undefined;
|
|
48
|
+
const planModel = recipe.model.billing === "plan" ? (model === undefined || model === "default" ? recipe.model.id : model) : undefined;
|
|
49
|
+
return {
|
|
50
|
+
id: recipe.id,
|
|
51
|
+
label: recipe.label,
|
|
52
|
+
command: binary,
|
|
53
|
+
args: [...(release.args ?? recipe.args), ...(route.on === "sign-in" ? [recipe.signIn.homeArg, route.home] : [])],
|
|
54
|
+
env: { ...recipe.env, ...vars, ...(modelVar && model !== undefined ? { [modelVar]: model } : {}) },
|
|
55
|
+
...(route.on === "sign-in"
|
|
56
|
+
? { keys: [], stderr: "none" }
|
|
57
|
+
: {
|
|
58
|
+
keys: [...recipe.keys],
|
|
59
|
+
...(Object.keys(recipe.keyEnv).length ? { keyEnv: { ...recipe.keyEnv } } : {}),
|
|
60
|
+
...(recipe.keyMethod ? { authMethod: recipe.keyMethod } : {}),
|
|
61
|
+
}),
|
|
62
|
+
...(planModel ? { model: planModel } : {}),
|
|
63
|
+
files: { ...recipe.files },
|
|
64
|
+
state: [...recipe.state],
|
|
65
|
+
declares: { ...recipe.declares },
|
|
66
|
+
billing: recipe.model.billing === "proxy" ? { kind: "proxy" } : { kind: "plan", maxTurns: recipe.model.maxTurns, maxToolCalls: recipe.model.maxToolCalls },
|
|
67
|
+
...(recipe.quirks.mcpCall ? { quirks: { mcpCall: recipe.quirks.mcpCall } } : {}),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** `recipe`'s whole entry, as an ACP agent outside the built-ins starts (harness-table.ts acpEntryOf). Proxy-billed: as a
|
|
71
|
+
* module's, its model and key chosen and a login refused there, its price, the adapter over its recipe and the
|
|
72
|
+
* session's model proxy (the one on Anthropic's Messages there is, Goose's policy, its address under the variable the
|
|
73
|
+
* recipe names). Billed to its plan: as Cursor's, on the model the recipe names or its vendor's own default. */
|
|
74
|
+
export function recipeEntryOf(options) {
|
|
75
|
+
const { recipe, binary, release } = options;
|
|
76
|
+
const acp = acpPackage();
|
|
77
|
+
if (!acp)
|
|
78
|
+
throw new HarnessUnavailable(`${recipe.label}'s recipe runs on the ACP adapter (${ACP_PACKAGE}), which is not installed beside this server`);
|
|
79
|
+
const host = options.log ? { log: options.log } : {};
|
|
80
|
+
const checks = options.missing ? { missing: options.missing } : {};
|
|
81
|
+
const entry = recipe.model.billing === "proxy"
|
|
82
|
+
? acpEntryOf({
|
|
83
|
+
facts: { ...acp.gooseFacts, id: recipe.id, label: recipe.label },
|
|
84
|
+
recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env), { vars: options.vars(), model: launch.model }),
|
|
85
|
+
proxy: (launch) => {
|
|
86
|
+
const hostEnv = recipe.model.billing === "proxy" ? (recipe.model.hostEnv ?? "ANTHROPIC_HOST") : "ANTHROPIC_HOST";
|
|
87
|
+
const messagesProxy = acp.gooseProxy({ model: launch.model, provider: launch.provider, price: launch.price, log: launch.log, ...(options.fetch ? { fetch: options.fetch } : {}) });
|
|
88
|
+
return async (session) => {
|
|
89
|
+
// The proxy's own address, under the recipe's variable, beside the key that opens it alone (never a provider's).
|
|
90
|
+
const started = await messagesProxy(session);
|
|
91
|
+
const { ANTHROPIC_HOST: address, ...opens } = started.env;
|
|
92
|
+
return { env: { ...opens, [hostEnv]: address }, close: started.close };
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
beforeStart: options.beforeStart,
|
|
96
|
+
...checks,
|
|
97
|
+
}, host)
|
|
98
|
+
: acpEntryOf({
|
|
99
|
+
facts: { ...acp.cursorFacts, id: recipe.id, label: recipe.label },
|
|
100
|
+
recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env), { vars: options.vars(), model: launch.model }),
|
|
101
|
+
beforeStart: options.beforeStart,
|
|
102
|
+
...checks,
|
|
103
|
+
...(options.hidden ? { hidden: options.hidden } : {}),
|
|
104
|
+
}, host);
|
|
105
|
+
return options.hidden && entry.hidden === undefined ? Object.freeze({ ...entry, hidden: options.hidden }) : entry;
|
|
106
|
+
}
|
|
107
|
+
/** The entry of the recipe at `file` on a server whose data directory is `data` (harness-table.ts HARNESS_RECIPES_ENV),
|
|
108
|
+
* loaded under its five rules when the table is (a refused one refuses the start, in words). It runs only on the
|
|
109
|
+
* install its owner made and checked: hidden, and each run refused, with the command that fixes it, until the binary
|
|
110
|
+
* and every file beside it are the pinned ones and a harness-check passed for this very recipe, binary and tree
|
|
111
|
+
* (HARNESS_NOT_CHECKED). Each start of its agent checks the binary and the tree against their pins again. It runs on
|
|
112
|
+
* the route serverRoute gives, its owner's sign-in only where `signIn` (--harness-sign-in). */
|
|
113
|
+
export function recipeServerEntry(file, data, { signIn = false } = {}) {
|
|
114
|
+
const loaded = loadRecipe(file);
|
|
115
|
+
const { recipe } = loaded;
|
|
116
|
+
const platform = archivePlatform();
|
|
117
|
+
const release = releaseFor(recipe, platform);
|
|
118
|
+
if (!platform || !release)
|
|
119
|
+
throw new Error(`harness recipe ${loaded.file}: ${recipe.label} ${recipe.release.version} has no release for ${platform ?? `${process.platform}-${process.arch}`}`);
|
|
120
|
+
const binary = recipeBinaryOf(data, recipe, release);
|
|
121
|
+
const installed = installDirOf(data, recipe.id);
|
|
122
|
+
const route = (env) => serverRoute(recipe, loaded.file, data, env, { signIn });
|
|
123
|
+
/** Why it cannot run on `env`, in words that end with the command that fixes it; undefined when it can. Nothing is
|
|
124
|
+
* digested here (each start is, beforeStart): the pins and the check's note are compared. */
|
|
125
|
+
const why = (env) => {
|
|
126
|
+
const pin = pinnedDigest(data, recipe, release, platform);
|
|
127
|
+
const tree = pinnedTree(data, recipe, release, platform);
|
|
128
|
+
if (!existsSync(binary) || !pin || !tree)
|
|
129
|
+
return `HARNESS_NOT_INSTALLED: ${recipe.label} ${recipe.release.version} is not installed in ${installed}. Install it with: ${recipeInstallLine(loaded.file, data, env)}`;
|
|
130
|
+
const checked = checkedOf(data, recipe.id);
|
|
131
|
+
if (!checked || checked.recipe !== loaded.sha256 || checked.binary !== pin.sha256 || checked.tree !== tree.sha256 || checked.platform !== platform) {
|
|
132
|
+
return `${HARNESS_NOT_CHECKED}: ${recipe.label} runs on this server once harness-check passes for this recipe and this install${checked ? " (the recipe or its install changed since the last check that passed)" : ""}. Check it with: ${recipeCheckLine(loaded.file, data, env)}`;
|
|
133
|
+
}
|
|
134
|
+
const on = route(env);
|
|
135
|
+
return "refused" in on ? `${on.refused}: ${on.message}` : undefined;
|
|
136
|
+
};
|
|
137
|
+
// What its runs' agents reach beyond loopback, as on its check: the hosts a plan-billed recipe's model.hosts names,
|
|
138
|
+
// tunneled, and nothing else (a proxy-billed agent's model is the model proxy, on loopback). One proxy for the recipe's
|
|
139
|
+
// runs in this process, started before its first agent does (in `missing`, which every start asks first), keeping no
|
|
140
|
+
// list of what it was asked.
|
|
141
|
+
const hosts = recipe.model.billing === "plan" ? (recipe.model.hosts ?? []) : [];
|
|
142
|
+
let egress;
|
|
143
|
+
let egressUrl;
|
|
144
|
+
return recipeEntryOf({
|
|
145
|
+
recipe,
|
|
146
|
+
binary,
|
|
147
|
+
release,
|
|
148
|
+
vars: () => {
|
|
149
|
+
if (!egressUrl)
|
|
150
|
+
throw new HarnessUnavailable(`${recipe.label}'s egress proxy is not running, so its agent does not start`);
|
|
151
|
+
return egressVars(egressUrl);
|
|
152
|
+
},
|
|
153
|
+
route: (env) => {
|
|
154
|
+
const on = route(env);
|
|
155
|
+
if ("refused" in on)
|
|
156
|
+
throw new HarnessUnavailable(`${on.refused}: ${on.message}`);
|
|
157
|
+
return on;
|
|
158
|
+
},
|
|
159
|
+
// The binary and every file beside it, digested again before each start: one swapped since the check never runs.
|
|
160
|
+
beforeStart: async (command) => {
|
|
161
|
+
const pin = pinnedDigest(data, recipe, release, platform);
|
|
162
|
+
const tree = pinnedTree(data, recipe, release, platform);
|
|
163
|
+
const now = await digestOf(command).catch(() => undefined);
|
|
164
|
+
if (!pin || now !== pin.sha256)
|
|
165
|
+
throw new Error(`${ARCHIVE_CODES.binary}: ${command} has sha256 ${now ?? "(unreadable)"}, not its pin's. Install it again with: ${recipeInstallLine(loaded.file, data)}`);
|
|
166
|
+
const files = await acpPackage().treeDigest(installed).catch(() => undefined);
|
|
167
|
+
if (!tree || files !== tree.sha256)
|
|
168
|
+
throw new Error(`${ARCHIVE_CODES.binary}: the files beside ${command} have the tree sha256 ${files ?? "(unreadable)"}, not their pin's. Install it again with: ${recipeInstallLine(loaded.file, data)}`);
|
|
169
|
+
},
|
|
170
|
+
missing: async (env) => {
|
|
171
|
+
const lacks = why(env);
|
|
172
|
+
if (lacks)
|
|
173
|
+
return lacks;
|
|
174
|
+
// A start that failed is tried again at the next run, never kept.
|
|
175
|
+
egress ??= egressProxy(hosts, { record: false, unref: true }).catch((error) => {
|
|
176
|
+
egress = undefined;
|
|
177
|
+
throw error;
|
|
178
|
+
});
|
|
179
|
+
egressUrl ??= (await egress).url;
|
|
180
|
+
return undefined;
|
|
181
|
+
},
|
|
182
|
+
hidden: why,
|
|
183
|
+
});
|
|
184
|
+
}
|