@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.45
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 +131 -5
- package/README.md +371 -300
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +52 -16
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +87 -102
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +13 -1
- package/dist/learn/promote.js +9 -0
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +268 -316
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +16 -8
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +63 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +8 -6
- package/dist/runner/promotion.js +19 -12
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1222 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +685 -320
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +60 -5
- package/dist/triggers.js +123 -18
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/faux-computers.js
CHANGED
|
@@ -2,14 +2,22 @@
|
|
|
2
2
|
// faux model module stands in for a model. The console's real-browser flows drive Settings → Computers and a run's
|
|
3
3
|
// desktop with it, with no Docker, no provider and no key that means anything. Only --faux reaches this module.
|
|
4
4
|
//
|
|
5
|
-
//
|
|
5
|
+
// Four providers, in the computer package's registry shape (SETTING_KINDS, PROVIDERS, servingRefusals):
|
|
6
6
|
// - faux-sandbox: a sandbox with one key, FAUX_SANDBOX_KEY. Ready once the key is saved; its test then passes. It starts
|
|
7
7
|
// no computer.
|
|
8
8
|
// - faux-broken: a sandbox with no key, whose test always fails: it is never reached. It starts no computer.
|
|
9
9
|
// - faux-desktop: a desktop with no key. Its run computer answers screen.shot (a plain grey screen) and input.actions
|
|
10
10
|
// (each action done, none performed). Its watch gives the run's live view grey frames and takes its input, so a --faux
|
|
11
11
|
// run's desktop is watched and taken over through the same proxied viewer a real one's is; the release ends it.
|
|
12
|
+
// - faux-dial: a desktop with no key whose machine dials this server, as Fly Machines' and Cloudflare's do (its
|
|
13
|
+
// descriptor's connect is "dial"). Its launch mints the machine a token through the runner's HostedDial, and a machine
|
|
14
|
+
// in this process dials the dial's public address at /v2/computers/attach with it, as agentrun-dial does, answering
|
|
15
|
+
// hello, ping, screen.shot (a grey screen) and input.actions; the run's computer calls go over the socket the runner's
|
|
16
|
+
// hub took. No dial, or one with no public address: its launch refuses in words, as the computer package's does.
|
|
17
|
+
import { randomBytes } from "node:crypto";
|
|
12
18
|
import { crc32, deflateSync } from "node:zlib";
|
|
19
|
+
import { ATTACH_PATH, ATTACH_SUBPROTOCOL, MAX_LINE_BYTES } from "@parcha/agentrun-computer";
|
|
20
|
+
import { WebSocket } from "ws";
|
|
13
21
|
// The computer package's setting kinds and servingRefusals, as its kinds.ts gives them (the swap to its exports
|
|
14
22
|
// replaces these two with the package's own).
|
|
15
23
|
const SETTING_KINDS = {
|
|
@@ -43,15 +51,17 @@ const PROVIDERS = [
|
|
|
43
51
|
entry({ id: "faux-sandbox", label: "Faux sandbox", keys: [{ name: "FAUX_SANDBOX_KEY", required: true }], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
|
|
44
52
|
entry({ id: "faux-broken", label: "Faux broken", keys: [], mounts: ["bind"], metered: false, capabilities: [SANDBOX] }),
|
|
45
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] }),
|
|
46
55
|
];
|
|
47
56
|
const KEYS = {
|
|
48
|
-
keys: { "faux-sandbox": [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], "faux-broken": [], "faux-desktop": [] },
|
|
49
|
-
labels: { "faux-sandbox": "Faux sandbox", "faux-broken": "Faux broken", "faux-desktop": "Faux desktop" },
|
|
57
|
+
keys: { "faux-sandbox": [{ name: "FAUX_SANDBOX_KEY", option: "apiKey", required: true }], "faux-broken": [], "faux-desktop": [], "faux-dial": [] },
|
|
58
|
+
labels: { "faux-sandbox": "Faux sandbox", "faux-broken": "Faux broken", "faux-desktop": "Faux desktop", "faux-dial": "Faux dial" },
|
|
50
59
|
};
|
|
51
|
-
/** Each faux provider's account test: faux-sandbox and faux-
|
|
60
|
+
/** Each faux provider's account test: faux-sandbox, faux-desktop and faux-dial answer, faux-broken is never reached. */
|
|
52
61
|
const FACTORIES = {
|
|
53
62
|
"faux-sandbox": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux sandbox: the faux account answered (no computer was made)" } }) }),
|
|
54
63
|
"faux-desktop": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux desktop: the faux account answered (no computer was made)" } }) }),
|
|
64
|
+
"faux-dial": () => ({ testConnection: async () => ({ ok: true, value: { detail: "Faux dial: the faux account answered (no computer was made)" } }) }),
|
|
55
65
|
"faux-broken": () => ({ testConnection: async () => ({ ok: false, error: { code: "unreachable", message: "faux-broken is --faux's broken provider: it never answers" } }) }),
|
|
56
66
|
};
|
|
57
67
|
/** A PNG of one grey colour, `width` by `height`. */
|
|
@@ -77,6 +87,9 @@ const WIDTH = 1280;
|
|
|
77
87
|
const HEIGHT = 800;
|
|
78
88
|
/** How long a faux desktop's watch waits after a frame's ack before it gives the next. */
|
|
79
89
|
const FRAME_MS = 1_000;
|
|
90
|
+
/** How long a faux dial machine's launch waits for its socket in the dial's hub; and its token's life. */
|
|
91
|
+
const DIAL_WAIT_MS = 10_000;
|
|
92
|
+
const DIAL_LIFE_MS = 60 * 60_000;
|
|
80
93
|
/** --faux's computers: the server's Settings → Computers and start check read them, and its runner's claim launches them. */
|
|
81
94
|
export function fauxComputers() {
|
|
82
95
|
let started = 0;
|
|
@@ -146,14 +159,78 @@ export function fauxComputers() {
|
|
|
146
159
|
},
|
|
147
160
|
};
|
|
148
161
|
}
|
|
162
|
+
/** A faux dial machine for a run: its token minted through `dial`, its socket dialled to the dial's public address, and
|
|
163
|
+
* the run's calls over the connection the dial's hub gives once it attached; its release revokes the token and ends
|
|
164
|
+
* the socket. Refused in words where the machine has nowhere to dial, or did not attach within DIAL_WAIT_MS. */
|
|
165
|
+
async function fauxDial(dial, run) {
|
|
166
|
+
// The computer package's words for a dial provider with no dial (hosted/provider.ts #dialed).
|
|
167
|
+
if (dial === undefined)
|
|
168
|
+
throw new Error("Faux dial machines dial in to this server, and this runner runs in a process of its own, with no attach hub to take their socket: start the image with the server options alone, without server-and-runner (outside the image: agentrun-serve without --no-runner)");
|
|
169
|
+
if (!dial.url)
|
|
170
|
+
throw new Error("Faux dial machines dial in to this server, which has no public address: set AGENTRUN_PUBLIC_URL");
|
|
171
|
+
const name = `faux-dial-${randomBytes(6).toString("hex")}`;
|
|
172
|
+
const token = await dial.tokens.mint(name, { kind: "desktop", os: "linux", arch: "amd64", expiresAt: new Date(Date.now() + DIAL_LIFE_MS), ...(run !== undefined ? { run } : {}) });
|
|
173
|
+
const png = greyPng(WIDTH, HEIGHT);
|
|
174
|
+
const hello = { protocol: "0.2", version: "faux", os: "linux", kind: "desktop", arch: "amd64", groups: [...DESKTOP_GROUPS], screen: { width: WIDTH, height: HEIGHT, scale: 1 } };
|
|
175
|
+
const machine = new WebSocket(`${dial.url.replace(/^http/, "ws")}${ATTACH_PATH}`, ATTACH_SUBPROTOCOL, { headers: { authorization: `Bearer ${token}` }, maxPayload: MAX_LINE_BYTES, perMessageDeflate: false });
|
|
176
|
+
let refused;
|
|
177
|
+
machine.on("error", (error) => void (refused ??= error.message));
|
|
178
|
+
machine.once("unexpected-response", (_req, res) => {
|
|
179
|
+
const words = [];
|
|
180
|
+
res.on("data", (chunk) => words.push(chunk));
|
|
181
|
+
res.on("end", () => void (refused ??= `HTTP ${res.statusCode}: ${Buffer.concat(words).toString("utf8")}`));
|
|
182
|
+
res.on("error", () => void (refused ??= `HTTP ${res.statusCode}`));
|
|
183
|
+
});
|
|
184
|
+
machine.on("message", (data, binary) => {
|
|
185
|
+
if (binary)
|
|
186
|
+
return;
|
|
187
|
+
let message;
|
|
188
|
+
try {
|
|
189
|
+
message = JSON.parse(String(data));
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (message.id === undefined || typeof message.method !== "string")
|
|
195
|
+
return;
|
|
196
|
+
const answer = (reply) => machine.readyState === WebSocket.OPEN && machine.send(JSON.stringify({ jsonrpc: "2.0", id: message.id, ...reply }));
|
|
197
|
+
if (message.method === "hello")
|
|
198
|
+
return answer({ result: hello });
|
|
199
|
+
if (message.method === "ping")
|
|
200
|
+
return answer({ result: {} });
|
|
201
|
+
if (message.method === "screen.shot")
|
|
202
|
+
return answer({ result: { id: `${name}-shot`, data: png.toString("base64"), eof: true, size: png.length, width: WIDTH, height: HEIGHT } });
|
|
203
|
+
if (message.method === "input.actions")
|
|
204
|
+
return answer({ result: { done: Array.isArray(message.params?.actions) ? message.params.actions.length : 0 } });
|
|
205
|
+
return answer({ error: { code: -32601, message: `the faux dial machine has no ${message.method}` } });
|
|
206
|
+
});
|
|
207
|
+
const release = async () => {
|
|
208
|
+
machine.close(1000, "released");
|
|
209
|
+
await dial.tokens.revoke(name).catch(() => undefined);
|
|
210
|
+
dial.hub.revoke(name, `${name} was released`);
|
|
211
|
+
};
|
|
212
|
+
const until = Date.now() + DIAL_WAIT_MS;
|
|
213
|
+
for (;;) {
|
|
214
|
+
const connection = dial.hub.connection(name);
|
|
215
|
+
if (connection)
|
|
216
|
+
return { id: name, groups: [...DESKTOP_GROUPS], hello: connection.hello, client: connection.client, release };
|
|
217
|
+
if (refused !== undefined || Date.now() >= until) {
|
|
218
|
+
await release();
|
|
219
|
+
throw new Error(refused === undefined ? `the faux dial machine ${name} did not dial ${dial.url} within ${DIAL_WAIT_MS / 1000} s` : `the faux dial machine ${name}'s dial to ${dial.url} was refused: ${refused}`);
|
|
220
|
+
}
|
|
221
|
+
await new Promise((done) => setTimeout(done, 25));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
149
224
|
return {
|
|
150
225
|
kinds: { SETTING_KINDS, PROVIDERS, servingRefusals },
|
|
151
226
|
factories: FACTORIES,
|
|
152
227
|
keyTable: KEYS,
|
|
153
|
-
async launch(entryOf, spec) {
|
|
228
|
+
async launch(entryOf, spec, given = {}) {
|
|
154
229
|
if (entryOf.id === "faux-desktop" && spec.kind === "desktop")
|
|
155
230
|
return fauxDesktop();
|
|
156
|
-
|
|
231
|
+
if (entryOf.id === "faux-dial" && spec.kind === "desktop")
|
|
232
|
+
return fauxDial(given.dial, spec.run);
|
|
233
|
+
throw new Error(`${entryOf.label} starts no computer: under --faux, only Faux desktop and Faux dial do (set this agent's computer to desktop on one of them, or none)`);
|
|
157
234
|
},
|
|
158
235
|
owns: (provider) => PROVIDERS.some((one) => one.id === provider),
|
|
159
236
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** The codes an archive install's failures carry (ArchiveInstallFailed). */
|
|
2
|
+
export declare const ARCHIVE_CODES: Readonly<{
|
|
3
|
+
/** The pin has no archive for this platform, or no binary digest to check what it unpacks to. */
|
|
4
|
+
readonly platform: "HARNESS_PLATFORM_UNSUPPORTED";
|
|
5
|
+
/** The archive could not be downloaded: the network, a status other than 200, a size past the limit. */
|
|
6
|
+
readonly download: "HARNESS_DOWNLOAD_FAILED";
|
|
7
|
+
/** The archive downloaded is not the pin's: its sha256 differs. */
|
|
8
|
+
readonly archive: "HARNESS_ARCHIVE_MISMATCH";
|
|
9
|
+
/** tar could not unpack the verified archive, or it holds no binary at the pin's path. */
|
|
10
|
+
readonly unpack: "HARNESS_UNPACK_FAILED";
|
|
11
|
+
/** The binary the archive unpacked to is not the pin's: its sha256 differs. */
|
|
12
|
+
readonly binary: "HARNESS_BINARY_MISMATCH";
|
|
13
|
+
/** Another install into the same data directory is running. */
|
|
14
|
+
readonly busy: "HARNESS_INSTALL_BUSY";
|
|
15
|
+
}>;
|
|
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). */
|
|
18
|
+
export type ArchiveRelease = {
|
|
19
|
+
readonly url: string;
|
|
20
|
+
readonly format: string;
|
|
21
|
+
readonly sha256: string;
|
|
22
|
+
readonly cmd: string;
|
|
23
|
+
readonly binarySha256?: string;
|
|
24
|
+
};
|
|
25
|
+
/** A harness installed from an archive: its id and name, its pin, and the command that installs it (said on every failure). */
|
|
26
|
+
export type ArchiveHarness = {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
readonly retry: string;
|
|
30
|
+
readonly pin: {
|
|
31
|
+
readonly version: string;
|
|
32
|
+
readonly archives: Readonly<Partial<Record<string, ArchiveRelease>>>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** A failed install, by its code (ARCHIVE_CODES): its message says why, and the command that tries again. */
|
|
36
|
+
export declare class ArchiveInstallFailed extends Error {
|
|
37
|
+
readonly code: ArchiveCode;
|
|
38
|
+
constructor(code: ArchiveCode, why: string, retry: string);
|
|
39
|
+
}
|
|
40
|
+
/** The largest archive an install takes: Goose's is about 60 MB. */
|
|
41
|
+
export declare const ARCHIVE_MAX_BYTES: number;
|
|
42
|
+
/** The most the download, and then tar, may each take. */
|
|
43
|
+
export declare const ARCHIVE_TIMEOUT_MS: number;
|
|
44
|
+
/** This host's platform as the ACP registry names it (`linux-x86_64`), or undefined for one it does not list. */
|
|
45
|
+
export declare function archivePlatform(platform?: string, arch?: string): string | undefined;
|
|
46
|
+
export interface ArchiveInstallOptions {
|
|
47
|
+
/** The platform, as the registry names it. Default this host's (archivePlatform). */
|
|
48
|
+
platform?: string;
|
|
49
|
+
/** For tests: the fetch the archive is downloaded with. */
|
|
50
|
+
fetch?: typeof fetch;
|
|
51
|
+
/** The tar that unpacks it. Default `tar` on PATH. */
|
|
52
|
+
tar?: string;
|
|
53
|
+
/** The environment tar's PATH is read from. Default process.env. Nothing else of it reaches tar. */
|
|
54
|
+
env?: NodeJS.ProcessEnv;
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
maxBytes?: number;
|
|
57
|
+
/** Hears each step once it holds: `downloaded` (and its digest checked), `unpacked`, `verified` (the binary's digest). */
|
|
58
|
+
onStep?: (step: "downloaded" | "unpacked" | "verified") => void | Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/** Installs `harness` into `dir` (`<data>/harnesses/<id>`) from its pin's archive for this platform: downloaded, checked,
|
|
61
|
+
* unpacked beside `dir`, its binary checked, then renamed into place and made read-only. `already` when the pinned binary
|
|
62
|
+
* is in place (nothing is downloaded); `now` once this install put it there. Rejects with ArchiveInstallFailed, `dir` as it
|
|
63
|
+
* was. */
|
|
64
|
+
export declare function installArchive(harness: ArchiveHarness, dir: string, options?: ArchiveInstallOptions): Promise<{
|
|
65
|
+
installed: "already" | "now";
|
|
66
|
+
binary: string;
|
|
67
|
+
}>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// An archive harness (Goose), installed by its owner: `agentrun harness install goose` (cli.ts install-harness), never on
|
|
2
|
+
// a first use and never on a run's path. The release is the one its pin names (the ACP registry's archive for this
|
|
3
|
+
// platform: its URL and sha256, and the sha256 of the binary it unpacks to), and it lands whole or not at all, as a
|
|
4
|
+
// first-use install does (harness-install.ts):
|
|
5
|
+
// - the archive is downloaded with node's fetch into a fresh folder beside `<data>/harnesses/<harness>`, its sha256
|
|
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`, a fixed argument list, no shell, an
|
|
8
|
+
// environment of PATH alone): node has no bzip2 of its own, and the repository carries none;
|
|
9
|
+
// - the binary's sha256 is checked there against the pin, and only then is the folder renamed into place and made
|
|
10
|
+
// read-only. What was there before goes aside first, then away;
|
|
11
|
+
// - a crash part way leaves that fresh folder (its name the sweep's) and never a half install: the next install removes it.
|
|
12
|
+
// One install at a time on a data directory, under the hold first-use installs take (takeHold). The installer is handed no
|
|
13
|
+
// key of the server's: fetch carries no header of ours, and tar's environment is PATH alone.
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
15
|
+
import { execFile } from "node:child_process";
|
|
16
|
+
import { createReadStream, createWriteStream, existsSync } from "node:fs";
|
|
17
|
+
import { lstat, mkdir, mkdtemp, rename } from "node:fs/promises";
|
|
18
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
19
|
+
import { Readable, Transform } from "node:stream";
|
|
20
|
+
import { pipeline } from "node:stream/promises";
|
|
21
|
+
import { leftoverPrefix, releaseHold, removeLeftover, sweepLeftovers, takeHold, writable } from "./harness-install.js";
|
|
22
|
+
/** The codes an archive install's failures carry (ArchiveInstallFailed). */
|
|
23
|
+
export const ARCHIVE_CODES = Object.freeze({
|
|
24
|
+
/** The pin has no archive for this platform, or no binary digest to check what it unpacks to. */
|
|
25
|
+
platform: "HARNESS_PLATFORM_UNSUPPORTED",
|
|
26
|
+
/** The archive could not be downloaded: the network, a status other than 200, a size past the limit. */
|
|
27
|
+
download: "HARNESS_DOWNLOAD_FAILED",
|
|
28
|
+
/** The archive downloaded is not the pin's: its sha256 differs. */
|
|
29
|
+
archive: "HARNESS_ARCHIVE_MISMATCH",
|
|
30
|
+
/** tar could not unpack the verified archive, or it holds no binary at the pin's path. */
|
|
31
|
+
unpack: "HARNESS_UNPACK_FAILED",
|
|
32
|
+
/** The binary the archive unpacked to is not the pin's: its sha256 differs. */
|
|
33
|
+
binary: "HARNESS_BINARY_MISMATCH",
|
|
34
|
+
/** Another install into the same data directory is running. */
|
|
35
|
+
busy: "HARNESS_INSTALL_BUSY",
|
|
36
|
+
});
|
|
37
|
+
/** A failed install, by its code (ARCHIVE_CODES): its message says why, and the command that tries again. */
|
|
38
|
+
export class ArchiveInstallFailed extends Error {
|
|
39
|
+
code;
|
|
40
|
+
constructor(code, why, retry) {
|
|
41
|
+
super(`${code}: ${why}. Try again with: ${retry}`);
|
|
42
|
+
this.code = code;
|
|
43
|
+
this.name = "ArchiveInstallFailed";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The largest archive an install takes: Goose's is about 60 MB. */
|
|
47
|
+
export const ARCHIVE_MAX_BYTES = 512 * 1024 * 1024;
|
|
48
|
+
/** The most the download, and then tar, may each take. */
|
|
49
|
+
export const ARCHIVE_TIMEOUT_MS = 10 * 60_000;
|
|
50
|
+
/** This host's platform as the ACP registry names it (`linux-x86_64`), or undefined for one it does not list. */
|
|
51
|
+
export function archivePlatform(platform = process.platform, arch = process.arch) {
|
|
52
|
+
const os = platform === "darwin" ? "darwin" : platform === "linux" ? "linux" : platform === "win32" ? "windows" : undefined;
|
|
53
|
+
const cpu = arch === "arm64" ? "aarch64" : arch === "x64" ? "x86_64" : undefined;
|
|
54
|
+
return os && cpu ? `${os}-${cpu}` : undefined;
|
|
55
|
+
}
|
|
56
|
+
/** The sha256 of the file at `path`, read a chunk at a time. */
|
|
57
|
+
async function digestOf(path) {
|
|
58
|
+
const hash = createHash("sha256");
|
|
59
|
+
await pipeline(createReadStream(path), hash);
|
|
60
|
+
return hash.digest("hex");
|
|
61
|
+
}
|
|
62
|
+
/** The binary's path under `root`, from the pin's `cmd` (`./goose`): refused when it would leave `root`. */
|
|
63
|
+
function binaryUnder(root, cmd) {
|
|
64
|
+
const path = resolve(root, cmd);
|
|
65
|
+
const inside = relative(root, path);
|
|
66
|
+
return inside && inside !== ".." && !inside.startsWith(`..${sep}`) ? path : undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Installs `harness` into `dir` (`<data>/harnesses/<id>`) from its pin's archive for this platform: downloaded, checked,
|
|
69
|
+
* unpacked beside `dir`, its binary checked, then renamed into place and made read-only. `already` when the pinned binary
|
|
70
|
+
* is in place (nothing is downloaded); `now` once this install put it there. Rejects with ArchiveInstallFailed, `dir` as it
|
|
71
|
+
* was. */
|
|
72
|
+
export async function installArchive(harness, dir, options = {}) {
|
|
73
|
+
const fail = (code, why) => new ArchiveInstallFailed(code, why, harness.retry);
|
|
74
|
+
const named = `${harness.label} ${harness.pin.version}`;
|
|
75
|
+
const platform = options.platform ?? archivePlatform();
|
|
76
|
+
const release = platform ? harness.pin.archives[platform] : undefined;
|
|
77
|
+
if (!platform || !release)
|
|
78
|
+
throw fail(ARCHIVE_CODES.platform, `${named} has no release pinned for ${platform ?? `${process.platform}-${process.arch}`}`);
|
|
79
|
+
if (!release.binarySha256)
|
|
80
|
+
throw fail(ARCHIVE_CODES.platform, `${named}'s binary on ${platform} has no sha256 pinned, so what its archive unpacks to cannot be checked`);
|
|
81
|
+
if (release.format !== "tar.bz2")
|
|
82
|
+
throw fail(ARCHIVE_CODES.platform, `${named}'s archive on ${platform} is ${release.format}, and this installer unpacks tar.bz2 alone`);
|
|
83
|
+
const binary = binaryUnder(dir, release.cmd);
|
|
84
|
+
if (!binary)
|
|
85
|
+
throw fail(ARCHIVE_CODES.platform, `${named}'s pinned path ${release.cmd} is not inside its folder`);
|
|
86
|
+
const pinned = release.binarySha256;
|
|
87
|
+
/** Whether the pinned binary is in place: a file whose sha256 is the pin's. */
|
|
88
|
+
const inPlace = async () => (await lstat(binary).catch(() => undefined)) !== undefined && (await digestOf(binary).catch(() => undefined)) === pinned;
|
|
89
|
+
if (await inPlace())
|
|
90
|
+
return { installed: "already", binary };
|
|
91
|
+
const parent = dirname(dir);
|
|
92
|
+
await mkdir(parent, { recursive: true });
|
|
93
|
+
const token = await takeHold(dir);
|
|
94
|
+
if (!token)
|
|
95
|
+
throw fail(ARCHIVE_CODES.busy, `another install into ${parent} is running; wait for it to end`);
|
|
96
|
+
let work;
|
|
97
|
+
try {
|
|
98
|
+
// Installed by another while this one waited for the hold: nothing to do.
|
|
99
|
+
if (await inPlace())
|
|
100
|
+
return { installed: "already", binary };
|
|
101
|
+
// What an earlier install left part way (a crash between the unpack and the rename): never read, removed now.
|
|
102
|
+
await sweepLeftovers(dir);
|
|
103
|
+
work = await mkdtemp(join(parent, leftoverPrefix(dir)));
|
|
104
|
+
const archive = join(work, "archive.tar.bz2");
|
|
105
|
+
const timeoutMs = options.timeoutMs ?? ARCHIVE_TIMEOUT_MS;
|
|
106
|
+
const maxBytes = options.maxBytes ?? ARCHIVE_MAX_BYTES;
|
|
107
|
+
// The download, hashed as it is written; refused past its limit.
|
|
108
|
+
const hash = createHash("sha256");
|
|
109
|
+
let bytes = 0;
|
|
110
|
+
try {
|
|
111
|
+
const response = await (options.fetch ?? fetch)(release.url, { redirect: "follow", signal: AbortSignal.timeout(timeoutMs) });
|
|
112
|
+
if (response.status !== 200 || !response.body) {
|
|
113
|
+
await response.body?.cancel().catch(() => undefined);
|
|
114
|
+
throw new Error(`${release.url} answered ${response.status}`);
|
|
115
|
+
}
|
|
116
|
+
const length = Number(response.headers.get("content-length"));
|
|
117
|
+
if (Number.isFinite(length) && length > maxBytes)
|
|
118
|
+
throw new Error(`${release.url} is ${length} bytes, past the ${maxBytes} an archive may be`);
|
|
119
|
+
const counted = new Transform({
|
|
120
|
+
transform(chunk, _encoding, done) {
|
|
121
|
+
bytes += chunk.length;
|
|
122
|
+
if (bytes > maxBytes)
|
|
123
|
+
return done(new Error(`${release.url} ran past the ${maxBytes} bytes an archive may be`));
|
|
124
|
+
hash.update(chunk);
|
|
125
|
+
done(null, chunk);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
await pipeline(Readable.fromWeb(response.body), counted, createWriteStream(archive, { mode: 0o600 }));
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
const cause = error.cause;
|
|
132
|
+
throw fail(ARCHIVE_CODES.download, `${named}'s archive could not be downloaded from ${release.url}: ${error.message}${cause ? ` (${cause.code ?? cause.message})` : ""}`);
|
|
133
|
+
}
|
|
134
|
+
const got = hash.digest("hex");
|
|
135
|
+
if (got !== release.sha256)
|
|
136
|
+
throw fail(ARCHIVE_CODES.archive, `${named}'s archive from ${release.url} has sha256 ${got}, and the pin is ${release.sha256}; it was not unpacked`);
|
|
137
|
+
await options.onStep?.("downloaded");
|
|
138
|
+
// Unpacked by tar, verified archive only, into a folder of its own inside the fresh one.
|
|
139
|
+
const tree = join(work, "tree");
|
|
140
|
+
await mkdir(tree);
|
|
141
|
+
const PATH = (options.env ?? process.env).PATH ?? "/usr/bin:/bin";
|
|
142
|
+
await new Promise((done, reject) => {
|
|
143
|
+
execFile(options.tar ?? "tar", ["-xjf", archive, "-C", tree, "--no-same-owner", "--no-same-permissions"], { env: { PATH, LC_ALL: "C" }, timeout: timeoutMs, maxBuffer: 1024 * 1024 }, (error, _stdout, stderr) => {
|
|
144
|
+
if (error)
|
|
145
|
+
reject(fail(ARCHIVE_CODES.unpack, `tar could not unpack ${named}'s archive: ${String(stderr).trim() || error.message}`));
|
|
146
|
+
else
|
|
147
|
+
done();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
await options.onStep?.("unpacked");
|
|
151
|
+
// The binary, a regular file at the pin's path, checked before anything puts it in place.
|
|
152
|
+
const unpacked = binaryUnder(tree, release.cmd);
|
|
153
|
+
const found = await lstat(unpacked).catch(() => undefined);
|
|
154
|
+
if (!found?.isFile())
|
|
155
|
+
throw fail(ARCHIVE_CODES.unpack, `${named}'s archive holds no file at ${release.cmd}`);
|
|
156
|
+
const binarySha = await digestOf(unpacked);
|
|
157
|
+
if (binarySha !== pinned)
|
|
158
|
+
throw fail(ARCHIVE_CODES.binary, `${named}'s binary from its archive has sha256 ${binarySha}, and the pin is ${pinned}; it was not put in place`);
|
|
159
|
+
await options.onStep?.("verified");
|
|
160
|
+
// Into place whole: what was there (a binary that is not the pin's, a folder by hand) goes aside first, then away.
|
|
161
|
+
const old = existsSync(dir) ? `${work}-old` : undefined;
|
|
162
|
+
if (old)
|
|
163
|
+
await rename(dir, old);
|
|
164
|
+
await rename(tree, dir);
|
|
165
|
+
// Read-only once in place; the binary is checked against the pin again before each run (gooseAdapter).
|
|
166
|
+
await writable(dir, false);
|
|
167
|
+
if (old)
|
|
168
|
+
await removeLeftover(old);
|
|
169
|
+
return { installed: "now", binary };
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
// The fresh folder (the archive, and the tree when it never went into place) goes either way.
|
|
173
|
+
if (work)
|
|
174
|
+
await removeLeftover(work);
|
|
175
|
+
await releaseHold(dir, token).catch(() => undefined);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type AcpPackage } from "./acp-package.js";
|
|
2
|
+
import { type ArchiveInstallOptions } from "./harness-archive.js";
|
|
3
|
+
export declare const GOOSE_ID = "goose";
|
|
4
|
+
/** Why Goose does not run here: a code (HARNESS_NOT_INSTALLED, ACP_BINARY_MISMATCH, ACP_BINARY_UNPINNED, ...) and words
|
|
5
|
+
* that start with it and end with the command that installs it. */
|
|
6
|
+
export type GooseMissing = {
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
};
|
|
10
|
+
/** Goose's folder in `data`, and its binary there. */
|
|
11
|
+
export declare const gooseDirOf: (data: string) => string;
|
|
12
|
+
export declare const gooseBinaryOf: (data: string) => string;
|
|
13
|
+
/** The agentrun command's own data directory, where `npx @parcha/agentrun` keeps its server's store (~/.agentrun: not the
|
|
14
|
+
* server's own default, defaultData), and so where `agentrun harness install` installs with no --data. */
|
|
15
|
+
export declare const commandData: (env: NodeJS.ProcessEnv) => string;
|
|
16
|
+
/** The command that installs Goose into `data`: naming it with --data unless it is the agentrun command's own (commandData). */
|
|
17
|
+
export declare function gooseInstallLine(acp: AcpPackage, data: string, env?: NodeJS.ProcessEnv): string;
|
|
18
|
+
/** Why Goose is not listed here (HarnessEntry.hidden): not installed, or not the pinned binary, in words that end with what
|
|
19
|
+
* to do, restarting AgentRun included (its harnesses are read at its start). Undefined once it is installed and verified.
|
|
20
|
+
* The binary's sha256 is kept once per file identity (the package's check), so only the first look reads it. */
|
|
21
|
+
export declare function gooseHidden(env: NodeJS.ProcessEnv): string | undefined;
|
|
22
|
+
/** Why Goose cannot run here, its binary checked off the event loop; undefined when it can (with the binary to run). */
|
|
23
|
+
export declare function gooseMissing(env: NodeJS.ProcessEnv): Promise<{
|
|
24
|
+
missing: GooseMissing;
|
|
25
|
+
} | {
|
|
26
|
+
binary: string;
|
|
27
|
+
sha256: string;
|
|
28
|
+
}>;
|
|
29
|
+
/** Installs the pinned Goose into `data` (agentrun-serve install-harness goose). */
|
|
30
|
+
export declare function installGoose(data: string, options?: ArchiveInstallOptions, env?: NodeJS.ProcessEnv): Promise<{
|
|
31
|
+
installed: "already" | "now";
|
|
32
|
+
binary: string;
|
|
33
|
+
version: string;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Goose on this server: where its owner installs it (`<data>/harnesses/goose/goose`, by `agentrun harness install goose`,
|
|
2
|
+
// harness-archive.ts), the command that does, and whether the binary there is the pinned one. Nothing here downloads:
|
|
3
|
+
// a run, a save and the start's probe only look at what is installed, and say the command where it is not.
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join, resolve } from "node:path";
|
|
7
|
+
import { acpPackage } from "./acp-package.js";
|
|
8
|
+
import { installArchive } from "./harness-archive.js";
|
|
9
|
+
import { installDirOf, shellWord } from "./harness-install.js";
|
|
10
|
+
import { DATA_ENV, defaultData } from "./server-fs.js";
|
|
11
|
+
export const GOOSE_ID = "goose";
|
|
12
|
+
/** The data directory `env` names (the server's own, else the default one). */
|
|
13
|
+
const dataOf = (env) => env[DATA_ENV] || defaultData(env);
|
|
14
|
+
/** Goose's folder in `data`, and its binary there. */
|
|
15
|
+
export const gooseDirOf = (data) => installDirOf(data, GOOSE_ID);
|
|
16
|
+
export const gooseBinaryOf = (data) => join(gooseDirOf(data), GOOSE_ID);
|
|
17
|
+
/** The agentrun command's own data directory, where `npx @parcha/agentrun` keeps its server's store (~/.agentrun: not the
|
|
18
|
+
* server's own default, defaultData), and so where `agentrun harness install` installs with no --data. */
|
|
19
|
+
export const commandData = (env) => join(env.HOME || homedir(), ".agentrun");
|
|
20
|
+
/** The command that installs Goose into `data`: naming it with --data unless it is the agentrun command's own (commandData). */
|
|
21
|
+
export function gooseInstallLine(acp, data, env = process.env) {
|
|
22
|
+
return resolve(data) === commandData(env) ? acp.GOOSE_INSTALL : `${acp.GOOSE_INSTALL} --data ${shellWord(data)}`;
|
|
23
|
+
}
|
|
24
|
+
/** What is known of Goose in `env`'s data before its binary is read: why it is missing, or the binary and the digest it
|
|
25
|
+
* must have, with how a refused check is said. */
|
|
26
|
+
function lookup(env) {
|
|
27
|
+
const acp = acpPackage();
|
|
28
|
+
if (!acp)
|
|
29
|
+
return { missing: { code: "HARNESS_NOT_INSTALLED", message: "HARNESS_NOT_INSTALLED: Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this server" } };
|
|
30
|
+
const data = dataOf(env);
|
|
31
|
+
const binary = gooseBinaryOf(data);
|
|
32
|
+
const line = gooseInstallLine(acp, data, env);
|
|
33
|
+
const { version, archives } = acp.GOOSE_PIN;
|
|
34
|
+
const platform = acp.acpPlatform();
|
|
35
|
+
const sha256 = platform ? archives[platform]?.binarySha256 : undefined;
|
|
36
|
+
if (!sha256)
|
|
37
|
+
return { missing: { code: "ACP_BINARY_UNPINNED", message: `ACP_BINARY_UNPINNED: Goose ${version} has no binary pinned for ${platform ?? `${process.platform}-${process.arch}`}, so it does not run here` } };
|
|
38
|
+
if (!existsSync(binary))
|
|
39
|
+
return { missing: { code: acp.GOOSE_NOT_INSTALLED, message: `${acp.GOOSE_NOT_INSTALLED}: Goose ${version} is not installed in ${gooseDirOf(data)}. Install it with: ${line}` } };
|
|
40
|
+
return {
|
|
41
|
+
acp, binary, sha256,
|
|
42
|
+
refused: (error) => {
|
|
43
|
+
const code = error?.code;
|
|
44
|
+
return { code: typeof code === "string" ? code : acp.GOOSE_NOT_INSTALLED, message: `${error.message}. Install Goose ${version} again with: ${line}` };
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Why Goose is not listed here (HarnessEntry.hidden): not installed, or not the pinned binary, in words that end with what
|
|
49
|
+
* to do, restarting AgentRun included (its harnesses are read at its start). Undefined once it is installed and verified.
|
|
50
|
+
* The binary's sha256 is kept once per file identity (the package's check), so only the first look reads it. */
|
|
51
|
+
export function gooseHidden(env) {
|
|
52
|
+
const found = lookup(env);
|
|
53
|
+
let missing;
|
|
54
|
+
if ("missing" in found)
|
|
55
|
+
missing = found.missing;
|
|
56
|
+
else {
|
|
57
|
+
try {
|
|
58
|
+
found.acp.verifyPinnedBinary(found.binary, found.sha256);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
missing = found.refused(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return missing && `${missing.message}; then restart AgentRun.`;
|
|
65
|
+
}
|
|
66
|
+
/** Why Goose cannot run here, its binary checked off the event loop; undefined when it can (with the binary to run). */
|
|
67
|
+
export async function gooseMissing(env) {
|
|
68
|
+
const found = lookup(env);
|
|
69
|
+
if ("missing" in found)
|
|
70
|
+
return found;
|
|
71
|
+
try {
|
|
72
|
+
await found.acp.verifyPinnedBinaryAsync(found.binary, found.sha256);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return { missing: found.refused(error) };
|
|
76
|
+
}
|
|
77
|
+
return { binary: found.binary, sha256: found.sha256 };
|
|
78
|
+
}
|
|
79
|
+
/** Installs the pinned Goose into `data` (agentrun-serve install-harness goose). */
|
|
80
|
+
export async function installGoose(data, options = {}, env = process.env) {
|
|
81
|
+
const acp = acpPackage();
|
|
82
|
+
if (!acp)
|
|
83
|
+
throw new Error("Goose's adapter (@parcha/agentrun-harness-acp) is not installed beside this server, so it has no pin to install from");
|
|
84
|
+
const { id, version, archives } = acp.GOOSE_PIN;
|
|
85
|
+
const platform = acp.acpPlatform();
|
|
86
|
+
return { version, ...(await installArchive({ id, label: "Goose", retry: gooseInstallLine(acp, data, env), pin: { version, archives } }, gooseDirOf(data), { ...(platform ? { platform } : {}), ...options })) };
|
|
87
|
+
}
|
|
@@ -24,6 +24,8 @@ export declare const harnessesOf: (data: string) => string;
|
|
|
24
24
|
export declare const installDirOf: (data: string, harness: string) => string;
|
|
25
25
|
/** What a run shows while its harness installs (a `phase` row of its timeline). */
|
|
26
26
|
export declare const installingWords: (label: string) => string;
|
|
27
|
+
/** `word` as a shell reads it back: as it is when it holds nothing a shell would read, else single-quoted. */
|
|
28
|
+
export declare const shellWord: (word: string) => string;
|
|
27
29
|
/** The command that installs a harness by hand into `dir`, as a first use does: the lock and the package.json it locks
|
|
28
30
|
* copied into a fresh directory beside `dir`, `npm ci` there with no package's install script and with the optional
|
|
29
31
|
* platform package that holds the CLI (whatever the person's npm config omits), and only then that directory put in
|
|
@@ -41,6 +43,8 @@ export declare function installLine(dir: string, lock: string): string;
|
|
|
41
43
|
export declare function inTree(dir: string, specifier: string): string | undefined;
|
|
42
44
|
/** The Claude Agent SDK's package. */
|
|
43
45
|
export declare const CLAUDE_SDK = "@anthropic-ai/claude-agent-sdk";
|
|
46
|
+
/** The CLI an install in `dir` holds for `platform` (the SDK's platform package's). */
|
|
47
|
+
export declare const claudeCliIn: (dir: string, platform: string) => string | undefined;
|
|
44
48
|
/** The SDK as installed in `dir`, checked: its package.json names it at `version`, and its entry resolves inside it. */
|
|
45
49
|
export declare function installedSdk(dir: string, version: string): {
|
|
46
50
|
entry: string;
|
|
@@ -88,6 +92,23 @@ export declare function npmInstall(entry: HarnessInstallEntry, dir: string, pins
|
|
|
88
92
|
signal?: AbortSignal;
|
|
89
93
|
onKilled?: () => void;
|
|
90
94
|
}): Promise<void>;
|
|
95
|
+
/** `path` and all under it made writable, then removed (retried a few times: a file can still be closing). One that can't
|
|
96
|
+
* be removed now (an orphaned npm of a crashed server still writing into it, a folder that can't be read) stays: removing
|
|
97
|
+
* what an install leaves is housekeeping, and never fails an install or hides why one failed. */
|
|
98
|
+
export declare function removeLeftover(path: string): Promise<void>;
|
|
99
|
+
/** The prefix of every directory an install into `dir` works in beside it (its staging, and the install it replaces). */
|
|
100
|
+
export declare const leftoverPrefix: (dir: string) => string;
|
|
101
|
+
/** What installs into `dir` left beside it (a staging directory of an install cut short, an install replaced), each
|
|
102
|
+
* removed if it can be now (removeLeftover). Only under the install's hold (takeHold): an install that runs works in a
|
|
103
|
+
* directory of that very prefix. Never fails. */
|
|
104
|
+
export declare function sweepLeftovers(dir: string): Promise<void>;
|
|
105
|
+
/** Every file and directory under `dir` (no link followed) made writable by its owner, or read-only for everyone and
|
|
106
|
+
* readable by everyone: a folder entered and listed, a file read, one its owner may run run by all. */
|
|
107
|
+
export declare function writable(dir: string, on: boolean): Promise<void>;
|
|
108
|
+
/** An installed harness at `dir` (a link to it followed) made readable by every user, never writable: what an install
|
|
109
|
+
* from before installs were shared left its owner's alone (its top folder 0500, as its staging was made). Once its top
|
|
110
|
+
* folder is readable by all, it is taken as shared and not walked again. None there: nothing to do. */
|
|
111
|
+
export declare function shareInstall(dir: string): Promise<void>;
|
|
91
112
|
/** How long npm has to exit after a SIGTERM before it gets SIGKILL. Once npm writes (its reify), a SIGTERM only marks
|
|
92
113
|
* it: npm finishes the step under way, which waits on every tarball, before it rolls back and exits, so a slow tarball
|
|
93
114
|
* would hold a server's close. npm writes only into the staging directory, which the install removes. */
|
package/dist/harness-install.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { spawn } from "node:child_process";
|
|
24
24
|
import { randomUUID } from "node:crypto";
|
|
25
25
|
import { existsSync, readFileSync, readlinkSync, realpathSync, statSync } from "node:fs";
|
|
26
|
-
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
26
|
+
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, symlink, writeFile } from "node:fs/promises";
|
|
27
27
|
import { hostname } from "node:os";
|
|
28
28
|
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
29
29
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -40,7 +40,8 @@ export const harnessesOf = (data) => join(data, HARNESSES_DIR);
|
|
|
40
40
|
export const installDirOf = (data, harness) => join(harnessesOf(data), harness);
|
|
41
41
|
/** What a run shows while its harness installs (a `phase` row of its timeline). */
|
|
42
42
|
export const installingWords = (label) => `Installing ${label} (first use)…`;
|
|
43
|
-
|
|
43
|
+
/** `word` as a shell reads it back: as it is when it holds nothing a shell would read, else single-quoted. */
|
|
44
|
+
export const shellWord = (word) => (/^[\w@%+=:,./-]+$/.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`);
|
|
44
45
|
/** The command that installs a harness by hand into `dir`, as a first use does: the lock and the package.json it locks
|
|
45
46
|
* copied into a fresh directory beside `dir`, `npm ci` there with no package's install script and with the optional
|
|
46
47
|
* platform package that holds the CLI (whatever the person's npm config omits), and only then that directory put in
|
|
@@ -169,7 +170,7 @@ export const CLAUDE_SDK = "@anthropic-ai/claude-agent-sdk";
|
|
|
169
170
|
/** The MCP library the SDK serves a session's tools with: its peer, installed beside it. */
|
|
170
171
|
const MCP_PARTS = ["@modelcontextprotocol/sdk/server/mcp.js", "@modelcontextprotocol/sdk/types.js"];
|
|
171
172
|
/** The CLI an install in `dir` holds for `platform` (the SDK's platform package's). */
|
|
172
|
-
const claudeCliIn = (dir, platform) => fileInPackage(dir, `@anthropic-ai/claude-agent-sdk-${platform}`, process.platform === "win32" ? "claude.exe" : "claude");
|
|
173
|
+
export const claudeCliIn = (dir, platform) => fileInPackage(dir, `@anthropic-ai/claude-agent-sdk-${platform}`, process.platform === "win32" ? "claude.exe" : "claude");
|
|
173
174
|
/** The SDK as installed in `dir`, checked: its package.json names it at `version`, and its entry resolves inside it. */
|
|
174
175
|
export function installedSdk(dir, version) {
|
|
175
176
|
if (versionIn(dir, CLAUDE_SDK) !== version)
|
|
@@ -278,8 +279,9 @@ export async function npmInstall(entry, dir, pins, { lock = entry.lock, env = pr
|
|
|
278
279
|
if (old)
|
|
279
280
|
await rename(dir, old);
|
|
280
281
|
await rename(staging, dir);
|
|
281
|
-
// Read-only once in place: a write into it by mistake fails
|
|
282
|
-
//
|
|
282
|
+
// Read-only once in place, and readable by every user: a write into it by mistake fails, and a run's process (a slot's
|
|
283
|
+
// user of its own, run-child-host.ts) loads it. (The server's own uid could change that back; each CLI's sha256 is
|
|
284
|
+
// checked at every run.)
|
|
283
285
|
await writable(dir, false);
|
|
284
286
|
// The install is in: the one it replaced goes now if it can, else it stays aside (its name the sweep's) for later.
|
|
285
287
|
if (old)
|
|
@@ -294,22 +296,23 @@ export async function npmInstall(entry, dir, pins, { lock = entry.lock, env = pr
|
|
|
294
296
|
/** `path` and all under it made writable, then removed (retried a few times: a file can still be closing). One that can't
|
|
295
297
|
* be removed now (an orphaned npm of a crashed server still writing into it, a folder that can't be read) stays: removing
|
|
296
298
|
* what an install leaves is housekeeping, and never fails an install or hides why one failed. */
|
|
297
|
-
async function removeLeftover(path) {
|
|
299
|
+
export async function removeLeftover(path) {
|
|
298
300
|
await writable(path, true).then(() => rm(path, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 })).catch(() => undefined);
|
|
299
301
|
}
|
|
300
302
|
/** The prefix of every directory an install into `dir` works in beside it (its staging, and the install it replaces). */
|
|
301
|
-
const leftoverPrefix = (dir) => `.${basename(dir)}-`;
|
|
303
|
+
export const leftoverPrefix = (dir) => `.${basename(dir)}-`;
|
|
302
304
|
/** What installs into `dir` left beside it (a staging directory of an install cut short, an install replaced), each
|
|
303
305
|
* removed if it can be now (removeLeftover). Only under the install's hold (takeHold): an install that runs works in a
|
|
304
306
|
* directory of that very prefix. Never fails. */
|
|
305
|
-
async function sweepLeftovers(dir) {
|
|
307
|
+
export async function sweepLeftovers(dir) {
|
|
306
308
|
const prefix = leftoverPrefix(dir);
|
|
307
309
|
for (const name of await readdir(dirname(dir)).catch(() => []))
|
|
308
310
|
if (name.startsWith(prefix))
|
|
309
311
|
await removeLeftover(join(dirname(dir), name));
|
|
310
312
|
}
|
|
311
|
-
/** Every file and directory under `dir` (no link followed) made writable by its owner, or read-only for everyone
|
|
312
|
-
|
|
313
|
+
/** Every file and directory under `dir` (no link followed) made writable by its owner, or read-only for everyone and
|
|
314
|
+
* readable by everyone: a folder entered and listed, a file read, one its owner may run run by all. */
|
|
315
|
+
export async function writable(dir, on) {
|
|
313
316
|
const walk = async (path) => {
|
|
314
317
|
const st = await lstat(path).catch(() => undefined);
|
|
315
318
|
if (!st || st.isSymbolicLink())
|
|
@@ -320,10 +323,20 @@ async function writable(dir, on) {
|
|
|
320
323
|
for (const name of await readdir(path))
|
|
321
324
|
await walk(join(path, name));
|
|
322
325
|
if (!on)
|
|
323
|
-
await chmod(path, st.mode & ~0o222);
|
|
326
|
+
await chmod(path, (st.mode & ~0o222) | 0o444 | (st.isDirectory() || st.mode & 0o100 ? 0o111 : 0));
|
|
324
327
|
};
|
|
325
328
|
await walk(dir);
|
|
326
329
|
}
|
|
330
|
+
/** An installed harness at `dir` (a link to it followed) made readable by every user, never writable: what an install
|
|
331
|
+
* from before installs were shared left its owner's alone (its top folder 0500, as its staging was made). Once its top
|
|
332
|
+
* folder is readable by all, it is taken as shared and not walked again. None there: nothing to do. */
|
|
333
|
+
export async function shareInstall(dir) {
|
|
334
|
+
const at = await realpath(dir).catch(() => undefined);
|
|
335
|
+
const st = at === undefined ? undefined : await lstat(at).catch(() => undefined);
|
|
336
|
+
if (!at || !st?.isDirectory() || (st.mode & 0o555) === 0o555)
|
|
337
|
+
return;
|
|
338
|
+
await writable(at, false);
|
|
339
|
+
}
|
|
327
340
|
/** How long npm has to exit after a SIGTERM before it gets SIGKILL. Once npm writes (its reify), a SIGTERM only marks
|
|
328
341
|
* it: npm finishes the step under way, which waits on every tarball, before it rolls back and exits, so a slow tarball
|
|
329
342
|
* would hold a server's close. npm writes only into the staging directory, which the install removes. */
|