@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +211 -1
- package/NOTICE +4 -0
- package/README.md +350 -53
- package/dist/acp-package.d.ts +53 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +3 -4
- package/dist/adapter-facts.js +4 -4
- package/dist/adapters.d.ts +3 -5
- package/dist/adapters.js +1 -31
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/answer-json.d.ts +10 -0
- package/dist/answer-json.js +24 -0
- package/dist/api-only.d.ts +11 -11
- package/dist/api-only.js +16 -11
- package/dist/archil-routes.js +2 -1
- package/dist/browser-live.d.ts +9 -4
- package/dist/browser-live.js +18 -5
- package/dist/cap.js +10 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +109 -41
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-routes.d.ts +8 -5
- package/dist/computer-routes.js +7 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +14 -76
- package/dist/computers.js +24 -68
- package/dist/conformance.d.ts +4 -0
- package/dist/conformance.js +6 -0
- package/dist/console/assets/index-CTGegcKt.css +1 -0
- package/dist/console/assets/index-D1Se6mgG.js +715 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +75 -0
- package/dist/harness-check.js +518 -0
- package/dist/harness-cursor.d.ts +28 -0
- package/dist/harness-cursor.js +42 -0
- package/dist/harness-goose.d.ts +4 -29
- package/dist/harness-goose.js +6 -86
- package/dist/harness-module.d.ts +4 -0
- package/dist/harness-module.js +1 -0
- package/dist/harness-owned.d.ts +52 -0
- package/dist/harness-owned.js +92 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +335 -0
- package/dist/harness-table.d.ts +120 -5
- package/dist/harness-table.js +280 -6
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +5 -4
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +24 -4
- package/dist/import.js +108 -26
- package/dist/key-refusal.d.ts +3 -1
- package/dist/key-refusal.js +26 -5
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +12 -5
- package/dist/learn/promote.d.ts +80 -2
- package/dist/learn/promote.js +95 -3
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +23 -0
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-model.d.ts +18 -0
- package/dist/learning-model.js +77 -0
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +2 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +30 -16
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +5 -3
- package/dist/model.js +26 -18
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +356 -43
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +9 -0
- package/dist/page.js +10 -2
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +7 -4
- package/dist/run-trace.js +6 -3
- package/dist/runner/adapter-loop.d.ts +14 -8
- package/dist/runner/adapter-loop.js +58 -24
- package/dist/runner/adapter-run-spec.d.ts +15 -2
- package/dist/runner/adapter-run-spec.js +48 -10
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +6 -26
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +15 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +22 -10
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/conformance/host-tools.d.ts +4 -0
- package/dist/runner/conformance/host-tools.js +14 -0
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +62 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/meta-tools.js +4 -2
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +44 -0
- package/dist/runner/presence.js +96 -0
- package/dist/runner/promotion.d.ts +70 -7
- package/dist/runner/promotion.js +178 -28
- package/dist/runner/run-child-host.js +40 -10
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/sdk-loop.js +25 -1
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +12 -4
- package/dist/sdk/check.d.ts +31 -0
- package/dist/sdk/check.js +58 -0
- package/dist/sdk/runs.d.ts +11 -3
- package/dist/sdk/runs.js +90 -15
- package/dist/sdk/schema.js +12 -4
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +34 -2
- package/dist/server.js +437 -90
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +112 -28
- package/dist/store/store.d.ts +78 -24
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +125 -14
- package/dist/store-view.js +156 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/template-eval.js +5 -2
- package/dist/template-github-permissions.d.ts +5 -1
- package/dist/template-github-permissions.js +7 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/timeline/timeline.js +30 -0
- package/dist/tool-gate.d.ts +8 -4
- package/dist/tool-gate.js +6 -7
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.d.ts +4 -0
- package/dist/tool-plane.js +12 -12
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +12 -3
- package/dist/trigger-targets.js +90 -10
- package/dist/triggers.d.ts +2 -2
- package/dist/validate.js +5 -1
- package/dist/viewer-credential.d.ts +25 -0
- package/dist/viewer-credential.js +51 -0
- package/dist/webhooks.d.ts +82 -8
- package/dist/webhooks.js +128 -45
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +23 -14
- package/dist/workspace/resolve-computer.js +66 -61
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +18 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/templates/code-review/agent.md +2 -3
- package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
- package/templates/code-review/evals/other-repo/case.yaml +0 -1
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
package/dist/console/index.html
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>AgentRun</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-D1Se6mgG.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="./assets/index-CTGegcKt.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Store } from "./store/store.js";
|
|
2
|
+
/** Runs read per page. */
|
|
3
|
+
export declare const COST_HEAL_PAGE = 100;
|
|
4
|
+
export type CostHealCount = {
|
|
5
|
+
readonly read: number;
|
|
6
|
+
readonly healed: number;
|
|
7
|
+
readonly failed: number;
|
|
8
|
+
};
|
|
9
|
+
/** Reads every ended run whose stored cost is unknown, a page at a time, healing each its booking prices. */
|
|
10
|
+
export declare function healEndedCosts(store: Store, { stopped, page }?: {
|
|
11
|
+
stopped?: () => boolean;
|
|
12
|
+
page?: number;
|
|
13
|
+
}): Promise<CostHealCount>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { healedOverStore } from "./store-view.js";
|
|
2
|
+
/** Runs read per page. */
|
|
3
|
+
export const COST_HEAL_PAGE = 100;
|
|
4
|
+
/** Reads every ended run whose stored cost is unknown, a page at a time, healing each its booking prices. */
|
|
5
|
+
export async function healEndedCosts(store, { stopped = () => false, page = COST_HEAL_PAGE } = {}) {
|
|
6
|
+
let [read, healed, failed] = [0, 0, 0];
|
|
7
|
+
let after;
|
|
8
|
+
for (;;) {
|
|
9
|
+
const ids = await store.runs.costUnknown({ limit: page, ...(after === undefined ? {} : { after }) });
|
|
10
|
+
for (const id of ids) {
|
|
11
|
+
if (stopped())
|
|
12
|
+
return { read, healed, failed };
|
|
13
|
+
read += 1;
|
|
14
|
+
try {
|
|
15
|
+
if (await healedOverStore(store, id))
|
|
16
|
+
healed += 1;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
failed += 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (ids.length < page)
|
|
23
|
+
return { read, healed, failed };
|
|
24
|
+
after = ids[ids.length - 1];
|
|
25
|
+
await new Promise((next) => setImmediate(next));
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/dial-relay.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type HostedDial } from "@parcha/agentrun-computer";
|
|
2
2
|
import { type AttachTiming } from "./computer-attach.js";
|
|
3
|
+
import type { Presence } from "./runner/presence.js";
|
|
3
4
|
import type { Store } from "./store/index.js";
|
|
4
5
|
/** A runner's relay: its HostedDial for its providers, where its listener answers, and its close. */
|
|
5
6
|
export interface RunnerRelay {
|
|
@@ -7,14 +8,17 @@ export interface RunnerRelay {
|
|
|
7
8
|
readonly incarnation: string;
|
|
8
9
|
readonly host: string;
|
|
9
10
|
readonly port: number;
|
|
10
|
-
/** Its listener and every socket it took closed, its row
|
|
11
|
+
/** Its listener and every socket it took closed, and its runner's row answering nowhere (the row stays its presence's). */
|
|
11
12
|
close(): Promise<void>;
|
|
12
13
|
}
|
|
13
14
|
export interface RunnerRelayOptions {
|
|
14
|
-
readonly store: Pick<Store, "mintedTokens" | "pairedComputers"
|
|
15
|
+
readonly store: Pick<Store, "mintedTokens" | "pairedComputers">;
|
|
15
16
|
readonly sealKey: Buffer;
|
|
16
17
|
/** The runner's name, as its claims and its row carry it. */
|
|
17
18
|
readonly runner: string;
|
|
19
|
+
/** The runner's word that it is there (runner/presence.ts): its incarnation is the relay's, and its row says where the
|
|
20
|
+
* relay answers. */
|
|
21
|
+
readonly presence: Pick<Presence, "incarnation" | "relay">;
|
|
18
22
|
/** AGENTRUN_PUBLIC_URL (or RENDER_EXTERNAL_URL), AGENTRUN_RUNNER_LIVE_HOST and AGENTRUN_RUNNER_LIVE_BIND. */
|
|
19
23
|
readonly env: NodeJS.ProcessEnv;
|
|
20
24
|
/** Told each line worth saying (a machine attached, refused); never a token. */
|
package/dist/dial-relay.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// (AGENTRUN_PUBLIC_URL, as the server reads it), `tokens` are minted into the shared store with the runner's name and
|
|
7
7
|
// this incarnation on each row (computer-attach.ts `owner`), and `hub` is the runner's own AttachHub. It serves that hub
|
|
8
8
|
// on a private attach listener: on loopback beside its server, or on its live host (AGENTRUN_RUNNER_LIVE_HOST,
|
|
9
|
-
// live-reach.ts) where it runs on another host, and
|
|
10
|
-
//
|
|
9
|
+
// live-reach.ts) where it runs on another host, and says where on the runner's row in the store (runners, through its
|
|
10
|
+
// presence: runner/presence.ts), which the presence renews; its incarnation is the presence's, one per runner process.
|
|
11
|
+
// The server's attach upgrade looks a token up, sees another runner owns it, and opens a socket to that
|
|
11
12
|
// runner's listener (computer-attach.ts relayDial) with the proxy's proof under the seal key (live-reach.ts relayProof).
|
|
12
13
|
// The listener answers nothing without a good, fresh proof it has not taken before, for this token, this runner and
|
|
13
14
|
// this incarnation, on loopback too, and its attach routes take only a token whose row names this runner and
|
|
@@ -15,10 +16,9 @@
|
|
|
15
16
|
//
|
|
16
17
|
// A runner with no public address keeps no relay: its dial providers still refuse (hosted/provider.ts), and the server's
|
|
17
18
|
// Settings → Computers still says so (computers.ts runs_refused).
|
|
18
|
-
import { randomUUID } from "node:crypto";
|
|
19
19
|
import { createServer } from "node:http";
|
|
20
20
|
import { ATTACH_PATH, AttachHub } from "@parcha/agentrun-computer";
|
|
21
|
-
import { bearerOf, createAttachRoutes,
|
|
21
|
+
import { bearerOf, createAttachRoutes, sha256Hex } from "./computer-attach.js";
|
|
22
22
|
import { LOOPBACK, relayKeyOf, relayProofs, runnerLiveOf } from "./live-reach.js";
|
|
23
23
|
import { logLine } from "./print.js";
|
|
24
24
|
/** The server's public address as this runner's environment names it (cli.ts reads the same two), or undefined. */
|
|
@@ -32,9 +32,9 @@ export async function startRunnerRelay(options) {
|
|
|
32
32
|
const url = publicUrlOf(options.env);
|
|
33
33
|
if (url === undefined)
|
|
34
34
|
return undefined;
|
|
35
|
-
const { store, runner, now = Date.now } = options;
|
|
35
|
+
const { store, runner, presence, now = Date.now } = options;
|
|
36
36
|
const log = options.log ?? (() => { });
|
|
37
|
-
const incarnation =
|
|
37
|
+
const { incarnation } = presence;
|
|
38
38
|
const live = runnerLiveOf(options.env, options.sealKey);
|
|
39
39
|
const host = live?.host ?? LOOPBACK;
|
|
40
40
|
const hub = new AttachHub();
|
|
@@ -69,16 +69,14 @@ export async function startRunnerRelay(options) {
|
|
|
69
69
|
server.closeAllConnections();
|
|
70
70
|
await new Promise((resolve) => server.close(() => resolve()));
|
|
71
71
|
};
|
|
72
|
+
// Said on the runner's row, which its presence renews: a runner that died without its close reads as gone with it.
|
|
72
73
|
try {
|
|
73
|
-
await
|
|
74
|
+
await presence.relay({ host, port });
|
|
74
75
|
}
|
|
75
76
|
catch (error) {
|
|
76
77
|
await shut();
|
|
77
78
|
throw error;
|
|
78
79
|
}
|
|
79
|
-
// Said again on its interval, so the server takes a runner that died without its close as gone (RELAY_STALE_MS).
|
|
80
|
-
const renew = setInterval(() => void store.runnerRelays.seen(runner, incarnation).catch(() => undefined), RELAY_RENEW_MS);
|
|
81
|
-
renew.unref();
|
|
82
80
|
let closing;
|
|
83
81
|
return {
|
|
84
82
|
dial: { url, tokens: routes.machineTokens, hub },
|
|
@@ -86,8 +84,7 @@ export async function startRunnerRelay(options) {
|
|
|
86
84
|
host,
|
|
87
85
|
port,
|
|
88
86
|
close: () => (closing ??= (async () => {
|
|
89
|
-
|
|
90
|
-
await store.runnerRelays.remove(runner, incarnation).catch(() => undefined);
|
|
87
|
+
await presence.relay(null).catch(() => undefined);
|
|
91
88
|
await shut();
|
|
92
89
|
})()),
|
|
93
90
|
};
|
package/dist/email/routes.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// nothing, for the saved account or the one in the body; nothing is saved
|
|
9
9
|
// The mail libraries load at the test only (mail.ts), never with the server.
|
|
10
10
|
import { invalid } from "../errors.js";
|
|
11
|
-
import { registerSecretWrite } from "../secret-writes.js";
|
|
11
|
+
import { registerSecretPage, registerSecretWrite } from "../secret-writes.js";
|
|
12
12
|
import { isObject } from "../validate.js";
|
|
13
13
|
import { accountOf, accountView, NO_ACCOUNT, openAccount, removeAccount, saveAccount } from "./account.js";
|
|
14
14
|
import { messages } from "./names.js";
|
|
@@ -16,6 +16,7 @@ import { messages } from "./names.js";
|
|
|
16
16
|
export const EMAIL_ROUTES = new Set(["getEmailAccount", "saveEmailAccount", "deleteEmailAccount", "testEmailAccount"]);
|
|
17
17
|
for (const operation of EMAIL_ROUTES)
|
|
18
18
|
registerSecretWrite(operation, () => true);
|
|
19
|
+
registerSecretPage([...EMAIL_ROUTES], "/#/settings/email");
|
|
19
20
|
/** `n` messages, in words. */
|
|
20
21
|
/** One route's answer (the dispatch sends it 200; DELETE's is undefined, 204). A body that does not read is 422. */
|
|
21
22
|
export async function emailRoute(deps, name, body) {
|
package/dist/errors.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export declare const ERROR_STATUS: {
|
|
|
32
32
|
readonly key_set_by_server: 409;
|
|
33
33
|
readonly budget_reached: 409;
|
|
34
34
|
readonly webhook_off: 409;
|
|
35
|
+
readonly slack_off: 409;
|
|
35
36
|
readonly precondition_required: 428;
|
|
36
37
|
readonly auth_required: 422;
|
|
37
38
|
readonly not_mcp: 422;
|
|
@@ -57,6 +58,7 @@ export declare const ERROR_STATUS: {
|
|
|
57
58
|
readonly runs_in_flight: 409;
|
|
58
59
|
readonly learning_busy: 409;
|
|
59
60
|
readonly model_key_required: 422;
|
|
61
|
+
readonly runner_refused: 503;
|
|
60
62
|
};
|
|
61
63
|
export type ErrorCode = keyof typeof ERROR_STATUS;
|
|
62
64
|
/** A field that is missing or wrong. `example`: a value the field accepts, read from the request body's schema (explain.ts). */
|
package/dist/errors.js
CHANGED
|
@@ -40,6 +40,7 @@ export const ERROR_STATUS = {
|
|
|
40
40
|
key_set_by_server: 409,
|
|
41
41
|
budget_reached: 409,
|
|
42
42
|
webhook_off: 409,
|
|
43
|
+
slack_off: 409,
|
|
43
44
|
precondition_required: 428,
|
|
44
45
|
auth_required: 422,
|
|
45
46
|
not_mcp: 422,
|
|
@@ -81,6 +82,10 @@ export const ERROR_STATUS = {
|
|
|
81
82
|
// A run start, or a message that would start a turn, with no model_key where the server holds no key for the run's
|
|
82
83
|
// model (run-model-key.ts): nothing to spend, so refused before any model call.
|
|
83
84
|
model_key_required: 422,
|
|
85
|
+
// A run start while every runner here refused to claim any run (runner/presence.ts): its run isolation refused
|
|
86
|
+
// (run-child-host.ts runIsolationOf), in the runner's words and their fix. Not retryable: it stays so until the runner
|
|
87
|
+
// is started again as the words say.
|
|
88
|
+
runner_refused: 503,
|
|
84
89
|
};
|
|
85
90
|
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy"]);
|
|
86
91
|
export class ApiError extends Error {
|
package/dist/exa-keyless.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const EXA_SEARCH_TOOL = "web_search_exa";
|
|
|
7
7
|
export declare const FAUX_EXA_ENV = "AGENTRUN_SERVE_FAUX_EXA";
|
|
8
8
|
/** What a search answers when Exa's free limit holds after the one retry. Exa's own words name a fix (an API key in
|
|
9
9
|
* its MCP URL) that means nothing to a person here, so they are never passed on. */
|
|
10
|
-
export declare const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings \u2192 MCP servers and grant the agent its web_search; or add a Parallel key in Settings \u2192
|
|
10
|
+
export declare const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings \u2192 MCP servers and grant the agent its web_search; or add a Parallel key in Settings \u2192 API Keys to search with a key.";
|
|
11
11
|
/** A search Exa refused for its free limit (`retryAfterS`, the wait it named, when it named one) or for the connection
|
|
12
12
|
* (403): a reason another provider may get past, which the caller reads before the model reads `error` alone. */
|
|
13
13
|
export type ExaLimited = {
|
package/dist/exa-keyless.js
CHANGED
|
@@ -33,7 +33,7 @@ const ACCEPT = "application/json, text/event-stream";
|
|
|
33
33
|
const MAX_BYTES = 1 << 20;
|
|
34
34
|
/** What a search answers when Exa's free limit holds after the one retry. Exa's own words name a fix (an API key in
|
|
35
35
|
* its MCP URL) that means nothing to a person here, so they are never passed on. */
|
|
36
|
-
export const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings → MCP servers and grant the agent its web_search; or add a Parallel key in Settings →
|
|
36
|
+
export const RATE_LIMITED = "Free web search is rate-limited right now. Try again in a minute; add the free Parallel Search server in Settings → MCP servers and grant the agent its web_search; or add a Parallel key in Settings → API Keys to search with a key.";
|
|
37
37
|
/** The most of Exa's own words a failure quotes: the first sentence of its first line, cut on a word. */
|
|
38
38
|
const SAID_MAX = 120;
|
|
39
39
|
/** A failure Exa answered, in our words: the first sentence of its text, short and quoted. Its later lines (a fix for its
|
package/dist/faux-computers.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { type HostedDial } from "@parcha/agentrun-computer";
|
|
1
|
+
import { type HostedDial, type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
2
|
import type { KeyTable, ProviderFactories } from "./computer-keys.js";
|
|
3
|
-
import type { KindRegistry, ProviderEntry } from "./computers.js";
|
|
4
3
|
import type { WatchOf } from "./workspace/computer-for-claim.js";
|
|
5
|
-
import type { ComputerSettingKind, LaunchedComputer } from "./workspace/resolve-computer.js";
|
|
4
|
+
import type { ComputerSettingKind, KindRegistry, LaunchedComputer } from "./workspace/resolve-computer.js";
|
|
6
5
|
/** A started faux desktop: the claim's LaunchedComputer, with its provider's watch of its screen (ComputerProvider.watch
|
|
7
6
|
* bound to it), which feeds the run's proxied live view (computer-live.ts) as a real desktop's does. */
|
|
8
7
|
export type FauxDesktop = LaunchedComputer & {
|
package/dist/faux-computers.js
CHANGED
|
@@ -16,42 +16,20 @@
|
|
|
16
16
|
// hub took. No dial, or one with no public address: its launch refuses in words, as the computer package's does.
|
|
17
17
|
import { randomBytes } from "node:crypto";
|
|
18
18
|
import { crc32, deflateSync } from "node:zlib";
|
|
19
|
-
import { ATTACH_PATH, ATTACH_SUBPROTOCOL, MAX_LINE_BYTES } from "@parcha/agentrun-computer";
|
|
19
|
+
import { ATTACH_PATH, ATTACH_SUBPROTOCOL, MAX_LINE_BYTES, SETTING_KIND_NAMES, SETTING_KINDS, servingRefusals } from "@parcha/agentrun-computer";
|
|
20
20
|
import { WebSocket } from "ws";
|
|
21
|
-
// The computer package's setting kinds and servingRefusals, as its kinds.ts gives them (the swap to its exports
|
|
22
|
-
// replaces these two with the package's own).
|
|
23
|
-
const SETTING_KINDS = {
|
|
24
|
-
none: { machineKinds: [], required: [], optional: [] },
|
|
25
|
-
sandbox: { machineKinds: ["linux"], required: ["exec", "files", "processes"], optional: [] },
|
|
26
|
-
desktop: { machineKinds: ["desktop"], required: ["screen", "input.pointer", "input.keys"], optional: ["exec", "files", "processes", "apps", "ui", "stream"] },
|
|
27
|
-
phone: { machineKinds: ["android", "ios"], required: ["screen", "input.touch", "apps"], optional: ["input.keys", "apps.install", "ui", "stream"] },
|
|
28
|
-
browser: { machineKinds: ["browser"], required: ["cdp"], optional: ["stream", "downloads"] },
|
|
29
|
-
};
|
|
30
|
-
const KIND_NAMES = Object.keys(SETTING_KINDS);
|
|
31
|
-
function servingRefusals(capabilities, kind) {
|
|
32
|
-
const spec = Object.hasOwn(SETTING_KINDS, kind) ? SETTING_KINDS[kind] : undefined;
|
|
33
|
-
if (spec === undefined)
|
|
34
|
-
return [`${JSON.stringify(kind)} is not a setting kind: ${KIND_NAMES.join(", ")}`];
|
|
35
|
-
if (spec.machineKinds.length === 0)
|
|
36
|
-
return [`kind ${kind} is no computer: no provider serves it`];
|
|
37
|
-
const refusals = [];
|
|
38
|
-
if (!spec.machineKinds.includes(capabilities.kind))
|
|
39
|
-
refusals.push(`kind ${kind} is a ${spec.machineKinds.join(" or ")} machine, not a ${capabilities.kind} one`);
|
|
40
|
-
const groups = (Array.isArray(capabilities.groups) ? capabilities.groups : []);
|
|
41
|
-
const missing = spec.required.filter((group) => !groups.includes(group));
|
|
42
|
-
if (missing.length > 0)
|
|
43
|
-
refusals.push(`kind ${kind} needs groups ${missing.join(", ")}, which the provider does not declare`);
|
|
44
|
-
return refusals;
|
|
45
|
-
}
|
|
46
21
|
const SANDBOX = { kind: "linux", groups: ["exec", "files", "processes"] };
|
|
47
22
|
const DESKTOP_GROUPS = ["screen", "input.pointer", "input.keys"];
|
|
48
23
|
const DESKTOP = { kind: "desktop", groups: [...DESKTOP_GROUPS] };
|
|
49
|
-
const entry = (fields) => ({ ...fields, kinds:
|
|
24
|
+
const entry = (fields) => ({ ...fields, kinds: SETTING_KIND_NAMES.filter((kind) => fields.capabilities.some((one) => servingRefusals(one, kind).length === 0)) });
|
|
25
|
+
// A faux computer takes this server's allow-list as it is, none or the list, so Settings says nothing of its network and
|
|
26
|
+
// AGENTRUN_BOX_ALLOW none never refuses it.
|
|
27
|
+
const NETWORK = ["none", "allow"];
|
|
50
28
|
const PROVIDERS = [
|
|
51
|
-
entry({ id: "faux-sandbox", label: "Faux sandbox", keys: [{ name: "FAUX_SANDBOX_KEY", required: true }], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
|
|
52
|
-
entry({ id: "faux-broken", label: "Faux broken", keys: [], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
|
|
53
|
-
entry({ id: "faux-desktop", label: "Faux desktop", keys: [], mounts: [], metered: false, capabilities: [DESKTOP] }),
|
|
54
|
-
entry({ id: "faux-dial", label: "Faux dial", connect: "dial", keys: [], mounts: [], metered: false, capabilities: [DESKTOP] }),
|
|
29
|
+
entry({ id: "faux-sandbox", label: "Faux sandbox", keys: [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], mounts: ["bind"], network: NETWORK, metered: false, capabilities: [SANDBOX] }),
|
|
30
|
+
entry({ id: "faux-broken", label: "Faux broken", keys: [], mounts: ["bind"], network: NETWORK, metered: false, capabilities: [SANDBOX] }),
|
|
31
|
+
entry({ id: "faux-desktop", label: "Faux desktop", keys: [], mounts: [], network: NETWORK, metered: false, capabilities: [DESKTOP] }),
|
|
32
|
+
entry({ id: "faux-dial", label: "Faux dial", connect: "dial", keys: [], mounts: [], network: NETWORK, metered: false, capabilities: [DESKTOP] }),
|
|
55
33
|
];
|
|
56
34
|
const KEYS = {
|
|
57
35
|
keys: { "faux-sandbox": [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], "faux-broken": [], "faux-desktop": [], "faux-dial": [] },
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
7
7
|
import { ApiError, invalid } from "./errors.js";
|
|
8
8
|
import { appJwt, GITHUB_FIELDS, GITHUB_SCOPE, GITHUB_WEB, githubCall, githubTargetOf, mintInstallationToken } from "./github.js";
|
|
9
|
-
import { registerSecretWrite } from "./secret-writes.js";
|
|
9
|
+
import { registerSecretPage, registerSecretWrite } from "./secret-writes.js";
|
|
10
10
|
import { isObject } from "./validate.js";
|
|
11
11
|
// Connecting a GitHub App seals its key and webhook secret (the webhook secret signs every GitHub delivery this server
|
|
12
12
|
// takes), and disconnecting drops them: each a secret write, from the owner's session alone, whatever its request.
|
|
13
13
|
registerSecretWrite("connectGitHub", () => true);
|
|
14
14
|
registerSecretWrite("disconnectGitHub", () => true);
|
|
15
|
+
registerSecretPage(["connectGitHub", "disconnectGitHub"], "/#/settings/github");
|
|
15
16
|
/** What every GitHub App Connect GitHub makes asks of the repositories it is installed on (its manifest's
|
|
16
17
|
* default_permissions): the least its templates need. Applying a template warns from each installation's real permissions
|
|
17
18
|
* (installationPermissions, template-github-permissions.ts), never from this. */
|
|
@@ -14,15 +14,18 @@ export declare const ARCHIVE_CODES: Readonly<{
|
|
|
14
14
|
readonly busy: "HARNESS_INSTALL_BUSY";
|
|
15
15
|
}>;
|
|
16
16
|
export type ArchiveCode = (typeof ARCHIVE_CODES)[keyof typeof ARCHIVE_CODES];
|
|
17
|
-
/** One platform's release, as a pin holds it (the ACP registry's: acp's AcpArchivePin).
|
|
17
|
+
/** One platform's release, as a pin holds it (the ACP registry's: acp's AcpArchivePin). `treeSha256`: the digest of
|
|
18
|
+
* every file it unpacks to (acp's treeDigest), for a binary that is a launcher of the code beside it (Cursor's). */
|
|
18
19
|
export type ArchiveRelease = {
|
|
19
20
|
readonly url: string;
|
|
20
21
|
readonly format: string;
|
|
21
22
|
readonly sha256: string;
|
|
22
23
|
readonly cmd: string;
|
|
23
24
|
readonly binarySha256?: string;
|
|
25
|
+
readonly treeSha256?: string;
|
|
24
26
|
};
|
|
25
|
-
/** A harness installed from an archive: its id and name, its pin, and the command that installs it (said on every failure).
|
|
27
|
+
/** A harness installed from an archive: its id and name, its pin, and the command that installs it (said on every failure).
|
|
28
|
+
* `tree`: how a tree's digest is taken (acp's treeDigest), needed where a release pins one. */
|
|
26
29
|
export type ArchiveHarness = {
|
|
27
30
|
readonly id: string;
|
|
28
31
|
readonly label: string;
|
|
@@ -31,7 +34,12 @@ export type ArchiveHarness = {
|
|
|
31
34
|
readonly version: string;
|
|
32
35
|
readonly archives: Readonly<Partial<Record<string, ArchiveRelease>>>;
|
|
33
36
|
};
|
|
37
|
+
readonly tree?: (root: string) => Promise<string>;
|
|
34
38
|
};
|
|
39
|
+
/** An archive format this installer unpacks. */
|
|
40
|
+
export type ArchiveFormat = "tar.bz2" | "tar.gz";
|
|
41
|
+
/** The formats this installer unpacks, the one list a recipe's loader checks a release against (harness-recipe.ts). */
|
|
42
|
+
export declare const ARCHIVE_FORMATS: readonly ArchiveFormat[];
|
|
35
43
|
/** A failed install, by its code (ARCHIVE_CODES): its message says why, and the command that tries again. */
|
|
36
44
|
export declare class ArchiveInstallFailed extends Error {
|
|
37
45
|
readonly code: ArchiveCode;
|
|
@@ -43,6 +51,8 @@ export declare const ARCHIVE_MAX_BYTES: number;
|
|
|
43
51
|
export declare const ARCHIVE_TIMEOUT_MS: number;
|
|
44
52
|
/** This host's platform as the ACP registry names it (`linux-x86_64`), or undefined for one it does not list. */
|
|
45
53
|
export declare function archivePlatform(platform?: string, arch?: string): string | undefined;
|
|
54
|
+
/** The sha256 of the file at `path`, read a chunk at a time. */
|
|
55
|
+
export declare function digestOf(path: string): Promise<string>;
|
|
46
56
|
export interface ArchiveInstallOptions {
|
|
47
57
|
/** The platform, as the registry names it. Default this host's (archivePlatform). */
|
|
48
58
|
platform?: string;
|
|
@@ -56,6 +66,13 @@ export interface ArchiveInstallOptions {
|
|
|
56
66
|
maxBytes?: number;
|
|
57
67
|
/** Hears each step once it holds: `downloaded` (and its digest checked), `unpacked`, `verified` (the binary's digest). */
|
|
58
68
|
onStep?: (step: "downloaded" | "unpacked" | "verified") => void | Promise<void>;
|
|
69
|
+
/** For a release whose binary has no sha256 pinned (a recipe's, where the registry lists only the archive's): the record
|
|
70
|
+
* of the first one unpacked from its verified archive. With none recorded, this install records its binary's; with one,
|
|
71
|
+
* a binary that differs is refused (HARNESS_BINARY_MISMATCH). Without it, such a release is refused. */
|
|
72
|
+
binaryRecord?: {
|
|
73
|
+
read(): string | undefined;
|
|
74
|
+
write(sha256: string): void;
|
|
75
|
+
};
|
|
59
76
|
}
|
|
60
77
|
/** Installs `harness` into `dir` (`<data>/harnesses/<id>`) from its pin's archive for this platform: downloaded, checked,
|
|
61
78
|
* unpacked beside `dir`, its binary checked, then renamed into place and made read-only. `already` when the pinned binary
|
package/dist/harness-archive.js
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
// first-use install does (harness-install.ts):
|
|
5
5
|
// - the archive is downloaded with node's fetch into a fresh folder beside `<data>/harnesses/<harness>`, its sha256
|
|
6
6
|
// taken as it arrives, and refused unless it is the pin's before anything reads it;
|
|
7
|
-
// - the verified archive is unpacked there by the system's tar (`tar -xjf
|
|
8
|
-
// environment of PATH alone): node has no bzip2 of its own, and the
|
|
9
|
-
//
|
|
10
|
-
//
|
|
7
|
+
// - the verified archive is unpacked there by the system's tar (`tar -xjf` for Goose's tar.bz2, `-xzf` for Cursor's
|
|
8
|
+
// tar.gz; a fixed argument list, no shell, an environment of PATH alone): node has no bzip2 of its own, and the
|
|
9
|
+
// repository carries none;
|
|
10
|
+
// - the binary's sha256 is checked there against the pin, and where the pin holds one the digest of every file beside
|
|
11
|
+
// it (Cursor's launcher runs its own node on a hundred files of code), and only then is the folder renamed into place
|
|
12
|
+
// and made read-only. What was there before goes aside first, then away;
|
|
11
13
|
// - a crash part way leaves that fresh folder (its name the sweep's) and never a half install: the next install removes it.
|
|
12
14
|
// One install at a time on a data directory, under the hold first-use installs take (takeHold). The installer is handed no
|
|
13
15
|
// key of the server's: fetch carries no header of ours, and tar's environment is PATH alone.
|
|
@@ -34,6 +36,10 @@ export const ARCHIVE_CODES = Object.freeze({
|
|
|
34
36
|
/** Another install into the same data directory is running. */
|
|
35
37
|
busy: "HARNESS_INSTALL_BUSY",
|
|
36
38
|
});
|
|
39
|
+
/** How tar unpacks each format this installer takes: node has neither bzip2 nor a tar of its own. */
|
|
40
|
+
const TAR_FLAG = Object.freeze({ "tar.bz2": "-xjf", "tar.gz": "-xzf" });
|
|
41
|
+
/** The formats this installer unpacks, the one list a recipe's loader checks a release against (harness-recipe.ts). */
|
|
42
|
+
export const ARCHIVE_FORMATS = Object.freeze(Object.keys(TAR_FLAG));
|
|
37
43
|
/** A failed install, by its code (ARCHIVE_CODES): its message says why, and the command that tries again. */
|
|
38
44
|
export class ArchiveInstallFailed extends Error {
|
|
39
45
|
code;
|
|
@@ -54,7 +60,7 @@ export function archivePlatform(platform = process.platform, arch = process.arch
|
|
|
54
60
|
return os && cpu ? `${os}-${cpu}` : undefined;
|
|
55
61
|
}
|
|
56
62
|
/** The sha256 of the file at `path`, read a chunk at a time. */
|
|
57
|
-
async function digestOf(path) {
|
|
63
|
+
export async function digestOf(path) {
|
|
58
64
|
const hash = createHash("sha256");
|
|
59
65
|
await pipeline(createReadStream(path), hash);
|
|
60
66
|
return hash.digest("hex");
|
|
@@ -76,16 +82,24 @@ export async function installArchive(harness, dir, options = {}) {
|
|
|
76
82
|
const release = platform ? harness.pin.archives[platform] : undefined;
|
|
77
83
|
if (!platform || !release)
|
|
78
84
|
throw fail(ARCHIVE_CODES.platform, `${named} has no release pinned for ${platform ?? `${process.platform}-${process.arch}`}`);
|
|
79
|
-
if (!release.binarySha256)
|
|
85
|
+
if (!release.binarySha256 && !options.binaryRecord)
|
|
80
86
|
throw fail(ARCHIVE_CODES.platform, `${named}'s binary on ${platform} has no sha256 pinned, so what its archive unpacks to cannot be checked`);
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
const flag = TAR_FLAG[release.format];
|
|
88
|
+
if (!flag || !Object.hasOwn(TAR_FLAG, release.format))
|
|
89
|
+
throw fail(ARCHIVE_CODES.platform, `${named}'s archive on ${platform} is ${release.format}, and this installer unpacks ${ARCHIVE_FORMATS.join(" and ")} alone`);
|
|
90
|
+
if (release.treeSha256 && !harness.tree)
|
|
91
|
+
throw fail(ARCHIVE_CODES.platform, `${named}'s files on ${platform} are pinned by a tree digest, and this install was given no way to take one`);
|
|
83
92
|
const binary = binaryUnder(dir, release.cmd);
|
|
84
93
|
if (!binary)
|
|
85
94
|
throw fail(ARCHIVE_CODES.platform, `${named}'s pinned path ${release.cmd} is not inside its folder`);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
// The pin's digest, else the first one recorded (none before the first install).
|
|
96
|
+
const pinned = release.binarySha256 ?? options.binaryRecord?.read();
|
|
97
|
+
/** Whether the pinned binary is in place: a file whose sha256 is the pin's, in a folder whose tree is the pin's where
|
|
98
|
+
* it pins one. */
|
|
99
|
+
const inPlace = async () => pinned !== undefined &&
|
|
100
|
+
(await lstat(binary).catch(() => undefined)) !== undefined &&
|
|
101
|
+
(await digestOf(binary).catch(() => undefined)) === pinned &&
|
|
102
|
+
(!release.treeSha256 || (await harness.tree(dir).catch(() => undefined)) === release.treeSha256);
|
|
89
103
|
if (await inPlace())
|
|
90
104
|
return { installed: "already", binary };
|
|
91
105
|
const parent = dirname(dir);
|
|
@@ -101,7 +115,7 @@ export async function installArchive(harness, dir, options = {}) {
|
|
|
101
115
|
// What an earlier install left part way (a crash between the unpack and the rename): never read, removed now.
|
|
102
116
|
await sweepLeftovers(dir);
|
|
103
117
|
work = await mkdtemp(join(parent, leftoverPrefix(dir)));
|
|
104
|
-
const archive = join(work,
|
|
118
|
+
const archive = join(work, `archive.${release.format}`);
|
|
105
119
|
const timeoutMs = options.timeoutMs ?? ARCHIVE_TIMEOUT_MS;
|
|
106
120
|
const maxBytes = options.maxBytes ?? ARCHIVE_MAX_BYTES;
|
|
107
121
|
// The download, hashed as it is written; refused past its limit.
|
|
@@ -140,7 +154,7 @@ export async function installArchive(harness, dir, options = {}) {
|
|
|
140
154
|
await mkdir(tree);
|
|
141
155
|
const PATH = (options.env ?? process.env).PATH ?? "/usr/bin:/bin";
|
|
142
156
|
await new Promise((done, reject) => {
|
|
143
|
-
execFile(options.tar ?? "tar", [
|
|
157
|
+
execFile(options.tar ?? "tar", [flag, archive, "-C", tree, "--no-same-owner", "--no-same-permissions"], { env: { PATH, LC_ALL: "C" }, timeout: timeoutMs, maxBuffer: 1024 * 1024 }, (error, _stdout, stderr) => {
|
|
144
158
|
if (error)
|
|
145
159
|
reject(fail(ARCHIVE_CODES.unpack, `tar could not unpack ${named}'s archive: ${String(stderr).trim() || error.message}`));
|
|
146
160
|
else
|
|
@@ -154,8 +168,28 @@ export async function installArchive(harness, dir, options = {}) {
|
|
|
154
168
|
if (!found?.isFile())
|
|
155
169
|
throw fail(ARCHIVE_CODES.unpack, `${named}'s archive holds no file at ${release.cmd}`);
|
|
156
170
|
const binarySha = await digestOf(unpacked);
|
|
157
|
-
if (
|
|
158
|
-
|
|
171
|
+
if (pinned === undefined) {
|
|
172
|
+
// The first binary unpacked from the verified archive: recorded, so a later one that differs is refused. A record
|
|
173
|
+
// another install wrote first holds.
|
|
174
|
+
try {
|
|
175
|
+
options.binaryRecord.write(binarySha);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
if (error?.code !== "EEXIST")
|
|
179
|
+
throw error;
|
|
180
|
+
const first = options.binaryRecord.read();
|
|
181
|
+
if (first !== binarySha)
|
|
182
|
+
throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the first one recorded is ${first}; it was not put in place`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (binarySha !== pinned)
|
|
186
|
+
throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the ${release.binarySha256 ? "pin" : "first one recorded"} is ${pinned}; it was not put in place`);
|
|
187
|
+
// Every file beside it, where the pin holds their digest: a launcher's code is as much the harness as the launcher.
|
|
188
|
+
if (release.treeSha256) {
|
|
189
|
+
const treeSha = await harness.tree(tree);
|
|
190
|
+
if (treeSha !== release.treeSha256)
|
|
191
|
+
throw fail(ARCHIVE_CODES.binary, `${named}'s files from its archive have the tree sha256 ${treeSha}, and the pin is ${release.treeSha256}; they were not put in place`);
|
|
192
|
+
}
|
|
159
193
|
await options.onStep?.("verified");
|
|
160
194
|
// Into place whole: what was there (a binary that is not the pin's, a folder by hand) goes aside first, then away.
|
|
161
195
|
const old = existsSync(dir) ? `${work}-old` : undefined;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export declare const CHECK_DEFAULT_CAP_USD = 0.25;
|
|
2
|
+
export interface HarnessCheckOptions {
|
|
3
|
+
/** The recipe file. */
|
|
4
|
+
recipe: string;
|
|
5
|
+
/** The data directory its owner installed it into. */
|
|
6
|
+
data: string;
|
|
7
|
+
/** The run's model, `provider/model-id` (a proxy-billed recipe needs one). */
|
|
8
|
+
model?: string;
|
|
9
|
+
/** The process's environment with its secrets (withSecrets): the provider's key, the recipe's own keys. */
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
/** The most the check may spend, USD. */
|
|
12
|
+
capUsd?: number;
|
|
13
|
+
platform?: string;
|
|
14
|
+
/** For tests: the fetch the model proxy forwards with. */
|
|
15
|
+
fetch?: typeof fetch;
|
|
16
|
+
/** Each step as it happens, a line of words. */
|
|
17
|
+
say?: (line: string) => void;
|
|
18
|
+
turnMs?: number;
|
|
19
|
+
}
|
|
20
|
+
type Check = {
|
|
21
|
+
ok: boolean | null;
|
|
22
|
+
[field: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
export interface HarnessCheckReport {
|
|
25
|
+
ok: boolean;
|
|
26
|
+
recipe: {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
file: string;
|
|
30
|
+
sha256: string;
|
|
31
|
+
} | {
|
|
32
|
+
file: string;
|
|
33
|
+
};
|
|
34
|
+
refused?: {
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
};
|
|
38
|
+
platform?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
binary?: {
|
|
41
|
+
path: string;
|
|
42
|
+
sha256: string;
|
|
43
|
+
pinnedBy: "recipe" | "first-seen";
|
|
44
|
+
};
|
|
45
|
+
stage2?: Record<string, Check>;
|
|
46
|
+
stage3?: Record<string, Check>;
|
|
47
|
+
facts?: {
|
|
48
|
+
resume: "load" | "restart" | "unknown";
|
|
49
|
+
tool_gate: "permission" | "config";
|
|
50
|
+
billing: "proxy" | "plan";
|
|
51
|
+
};
|
|
52
|
+
gate?: {
|
|
53
|
+
permissionsAsked: {
|
|
54
|
+
toolCallId: unknown;
|
|
55
|
+
kind: unknown;
|
|
56
|
+
}[];
|
|
57
|
+
asked: {
|
|
58
|
+
tool: string;
|
|
59
|
+
answer: string;
|
|
60
|
+
}[];
|
|
61
|
+
};
|
|
62
|
+
spendUsd?: number | null;
|
|
63
|
+
checkedAt: string;
|
|
64
|
+
failures: string[];
|
|
65
|
+
}
|
|
66
|
+
/** Runs the check. Never throws for what it judges: a refused recipe, a missing install or a failed stage is in the
|
|
67
|
+
* report (`ok: false`, `failures`). Every string of the report and every line it says has the server's secrets and the
|
|
68
|
+
* recipe's keys cut (runner/redact.ts secretRedactor), so an agent's words in it (a failed turn's stderr, a refusal, a
|
|
69
|
+
* log line) never carry a key out to the report's file or the terminal. */
|
|
70
|
+
export declare function harnessCheck(options: HarnessCheckOptions): Promise<HarnessCheckReport>;
|
|
71
|
+
/** The three facts and the verdict, as the command prints them. */
|
|
72
|
+
export declare function printedFacts(report: HarnessCheckReport): string[];
|
|
73
|
+
/** Writes the report to `file`. */
|
|
74
|
+
export declare const writeReport: (file: string, report: HarnessCheckReport) => Promise<void>;
|
|
75
|
+
export {};
|