@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- 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 +62 -19
- 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-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -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/import.d.ts +10 -0
- package/dist/import.js +28 -8
- 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 +89 -104
- 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 +23 -5
- package/dist/learn/promote.js +40 -2
- 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 +21 -10
- package/dist/learning-setting.js +47 -11
- 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 +273 -319
- 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 +30 -13
- 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 +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- 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 +82 -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 +12 -8
- package/dist/runner/promotion.js +37 -28
- 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 +1230 -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 +689 -322
- 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 +8 -4
- package/dist/templates.js +44 -6
- 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 +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- 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 +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- 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/kyb/agent.md +2 -1
- 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
|
@@ -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. */
|
|
@@ -17,7 +17,7 @@ import { serialWriter, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
|
17
17
|
import { openCodeHarness, sentSubmissions } from "./harness.js";
|
|
18
18
|
import { openCodePolicy, TOOL_PREFIX } from "./host/policy.js";
|
|
19
19
|
import { verifyOpenCode } from "./verify.js";
|
|
20
|
-
import { learnedFront } from "../learn/
|
|
20
|
+
import { learnedFront } from "../learn/workflow-draft.js";
|
|
21
21
|
/** A name OpenCode keeps whole for an MCP tool (it turns anything else into `_`), short enough that `hands_<name>` is a
|
|
22
22
|
* function name the Responses API takes (at most 64). */
|
|
23
23
|
const TOOL_NAME = new RegExp(`^[A-Za-z0-9_-]{1,${64 - TOOL_PREFIX.length}}$`);
|
package/dist/harness-table.d.ts
CHANGED
|
@@ -76,6 +76,10 @@ export interface HarnessEntry {
|
|
|
76
76
|
skillCheck?(): Promise<SkillCheck | undefined>;
|
|
77
77
|
/** What its first-use install needs (installs). */
|
|
78
78
|
pins?(): Promise<HarnessPins>;
|
|
79
|
+
/** Why it is not listed on `env` (harnessIds: capabilities, the tools' harnesses), in words that end with what to do;
|
|
80
|
+
* undefined while it is. One its owner installs (Goose: harness-goose.ts) is listed only once it is there and verified.
|
|
81
|
+
* It is still in the table, so a run or a save naming it is refused with these words. */
|
|
82
|
+
hidden?(env: NodeJS.ProcessEnv): string | undefined;
|
|
79
83
|
}
|
|
80
84
|
/** What a test's table module exports: entries by id, each merged over the built-in one of that id (all of it, for one
|
|
81
85
|
* the server has none of), given the built-ins to build on. Loaded with require: the module has no top-level await. */
|
|
@@ -102,8 +106,12 @@ export declare const harnessModulesOf: (given: readonly string[] | undefined, en
|
|
|
102
106
|
export declare function harnessModulePaths(names: readonly string[], data: string): string[];
|
|
103
107
|
/** HARNESS_MODULES_ENV for the harness modules `names` names: none for none. */
|
|
104
108
|
export declare const harnessModulesEnv: (names: readonly string[], data: string) => NodeJS.ProcessEnv;
|
|
105
|
-
/** The ids of the harnesses `env`'s table
|
|
109
|
+
/** The ids of the harnesses `env`'s table lists, in its order: the built-in ones (pi first), then those its modules add;
|
|
110
|
+
* not one its entry hides on `env` (HarnessEntry.hidden: Goose until it is installed). */
|
|
106
111
|
export declare const harnessIds: (env: NodeJS.ProcessEnv) => readonly string[];
|
|
112
|
+
/** The ids of every harness `env`'s table has, hidden ones too: those a definition may name (a save warns of a hidden one,
|
|
113
|
+
* a run is refused with why). */
|
|
114
|
+
export declare const tableIds: (env: NodeJS.ProcessEnv) => readonly string[];
|
|
107
115
|
/** The built-in entry of harness `id` (none: the default, pi), for what a test's entry never changes: its memory (host.ts),
|
|
108
116
|
* which a stand-in reserves as the harness it stands in for does, so tests admit as a real server does. */
|
|
109
117
|
export declare const builtinHarness: (id: string | undefined) => HarnessEntry | undefined;
|
package/dist/harness-table.js
CHANGED
|
@@ -12,6 +12,8 @@ import { join, resolve } from "node:path";
|
|
|
12
12
|
import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
13
13
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
14
14
|
import { facts as openCodeFacts } from "./harness-opencode/facts.js";
|
|
15
|
+
import { GOOSE_FACTS } from "./adapter-facts.js";
|
|
16
|
+
import { gooseHidden } from "./harness-goose.js";
|
|
15
17
|
import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
16
18
|
import { HARNESS_INSTALLS } from "./harness-install.js";
|
|
17
19
|
import { chooseModel } from "./model.js";
|
|
@@ -84,6 +86,9 @@ function adapterEntry(facts, make, extra = {}) {
|
|
|
84
86
|
route: async (env, needs) => {
|
|
85
87
|
const { nativeOptions, priceOf } = await import("./adapters.js");
|
|
86
88
|
const provider = providerFor(wire, env, needs.model, id);
|
|
89
|
+
// A person's Claude Code login is its CLI's alone: no request of serve's own goes on it.
|
|
90
|
+
if (provider.login)
|
|
91
|
+
throw new HarnessUnavailable(`${id} runs on Claude Code's login on this machine, which only its CLI uses: this request needs a model key.`);
|
|
87
92
|
const policy = facts.policy({ model: provider.modelId, tools: [], auth: provider.auth, ...nativeOptions(facts, env), ...(provider.billing === "plan" ? { plan: true } : {}) });
|
|
88
93
|
return { api: wire, options: { policy, model: provider.modelId, origin: provider.origin, credential: async () => provider.credential(), price: priceOf({ ...needs, model: provider.priceModel }) } };
|
|
89
94
|
},
|
|
@@ -122,11 +127,19 @@ const BUILTIN = Object.freeze({
|
|
|
122
127
|
[openCodeFacts.id]: adapterEntry(openCodeFacts, async (env, needs) => (await import("./adapters.js")).opencodeOf(env, needs), {
|
|
123
128
|
// Checked as OpenCode is handed them (servedSkills, opencodeOf's): one size check on what it gets.
|
|
124
129
|
skillCheck: async () => {
|
|
125
|
-
const [{ packageSkillCheck }, { servedSkills }] = await Promise.all([import("./adapters.js"), import("./learn/
|
|
130
|
+
const [{ packageSkillCheck }, { servedSkills }] = await Promise.all([import("./adapters.js"), import("./learn/workflow-draft.js")]);
|
|
126
131
|
const check = await packageSkillCheck(() => import("./harness-opencode/index.js"));
|
|
127
132
|
return check && ((skills) => check(servedSkills(skills)));
|
|
128
133
|
},
|
|
129
134
|
}),
|
|
135
|
+
// Goose, over ACP, where its package is beside serve (acp-package.ts): its owner installs its pinned binary
|
|
136
|
+
// (`agentrun harness install goose`, harness-goose.ts), never a run; listed only once it is installed and verified.
|
|
137
|
+
...(GOOSE_FACTS ? {
|
|
138
|
+
[GOOSE_FACTS.id]: adapterEntry(GOOSE_FACTS, async (env, needs) => (await import("./adapters.js")).gooseOf(env, needs), {
|
|
139
|
+
promises: Object.freeze({ resume: "load", tool_gate: "permission", billing: "proxy" }),
|
|
140
|
+
hidden: gooseHidden,
|
|
141
|
+
}),
|
|
142
|
+
} : {}),
|
|
130
143
|
});
|
|
131
144
|
const loaded = new Map();
|
|
132
145
|
const requireHere = createRequire(import.meta.url);
|
|
@@ -216,8 +229,12 @@ export function harnessModulePaths(names, data) {
|
|
|
216
229
|
}
|
|
217
230
|
/** HARNESS_MODULES_ENV for the harness modules `names` names: none for none. */
|
|
218
231
|
export const harnessModulesEnv = (names, data) => (names.length ? { [HARNESS_MODULES_ENV]: JSON.stringify(harnessModulePaths(names, data)) } : {});
|
|
219
|
-
/** The ids of the harnesses `env`'s table
|
|
220
|
-
|
|
232
|
+
/** The ids of the harnesses `env`'s table lists, in its order: the built-in ones (pi first), then those its modules add;
|
|
233
|
+
* not one its entry hides on `env` (HarnessEntry.hidden: Goose until it is installed). */
|
|
234
|
+
export const harnessIds = (env) => Object.entries(harnessTable(env)).filter(([, entry]) => entry.hidden?.(env) === undefined).map(([id]) => id);
|
|
235
|
+
/** The ids of every harness `env`'s table has, hidden ones too: those a definition may name (a save warns of a hidden one,
|
|
236
|
+
* a run is refused with why). */
|
|
237
|
+
export const tableIds = (env) => Object.keys(harnessTable(env));
|
|
221
238
|
/** The built-in entry of harness `id` (none: the default, pi), for what a test's entry never changes: its memory (host.ts),
|
|
222
239
|
* which a stand-in reserves as the harness it stands in for does, so tests admit as a real server does. */
|
|
223
240
|
export const builtinHarness = (id) => BUILTIN[id ?? DEFAULT_HARNESS];
|
package/dist/harness.d.ts
CHANGED
|
@@ -8,8 +8,7 @@ export declare const DEFAULT_HARNESS: HarnessId;
|
|
|
8
8
|
/** What a harness id is, as the API says it (openapi.ts): a harness module's id that is not one refuses the start. */
|
|
9
9
|
export declare const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
10
10
|
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
11
|
-
* `learning`,
|
|
12
|
-
* learning-factory.ts LEARNING_HARNESS) and the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
11
|
+
* `learning`, the launch harness the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
13
12
|
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
14
13
|
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
15
14
|
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
package/dist/harness.js
CHANGED
|
@@ -6,8 +6,7 @@ export const DEFAULT_HARNESS = "pi";
|
|
|
6
6
|
/** What a harness id is, as the API says it (openapi.ts): a harness module's id that is not one refuses the start. */
|
|
7
7
|
export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
8
8
|
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
9
|
-
* `learning`,
|
|
10
|
-
* learning-factory.ts LEARNING_HARNESS) and the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
9
|
+
* `learning`, the launch harness the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
11
10
|
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
12
11
|
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
13
12
|
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
@@ -86,9 +85,9 @@ export function harnessOffers(env) {
|
|
|
86
85
|
// lacks only a key is (a save warns of that, never refuses).
|
|
87
86
|
const { MODEL_REF } = await import("./validate.js");
|
|
88
87
|
const { providerFor, HarnessUnavailable } = await import("./provider.js");
|
|
89
|
-
const {
|
|
88
|
+
const { adapterFactsOf } = await import("./adapter-facts.js");
|
|
90
89
|
const { FAUX_ENV } = await import("./model.js");
|
|
91
|
-
const facts =
|
|
90
|
+
const facts = adapterFactsOf(offer.id);
|
|
92
91
|
for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
|
|
93
92
|
if (!MODEL_REF.test(id))
|
|
94
93
|
continue;
|
package/dist/host.js
CHANGED
|
@@ -49,7 +49,8 @@ const listed = (names) => (names.length > 1 ? `${names.slice(0, -1).join(", ")}
|
|
|
49
49
|
export function neverFits(harness, memory, env = {}) {
|
|
50
50
|
if (runsThatFit(harness, memory, env) > 0)
|
|
51
51
|
return undefined;
|
|
52
|
-
|
|
52
|
+
// Those the server lists (an entry it hides, Goose before it is installed, is never named: harness-table.ts hidden).
|
|
53
|
+
const fit = Object.entries(ownerTable(env)).filter(([id, entry]) => entry.hidden?.(env) === undefined && runsThatFit(id, memory, env) > 0).map(([id]) => id);
|
|
53
54
|
return `This server has ${sizeOf(memory / MiB)} of memory and keeps ${sizeOf(SERVER_MIB)} for itself; ${aRun(harness)} needs about ${sizeOf(runMibOf(harness, env))} more, so it can't start here. ${listed(fit)} runs fit.`;
|
|
54
55
|
}
|
|
55
56
|
/** The cap on how many runs at once: `given`, else `AGENTRUN_MAX_RUNS`, else the default for this host's memory. A runner
|
package/dist/import.d.ts
CHANGED
|
@@ -136,6 +136,13 @@ export type ImportReport = {
|
|
|
136
136
|
}[];
|
|
137
137
|
skipped: Skipped[];
|
|
138
138
|
already: number;
|
|
139
|
+
/** Each session model a new revision does not pin (no model catalog here lists it): the agent's folder, the source, the
|
|
140
|
+
* model. The agent runs on the server's default for its harness. */
|
|
141
|
+
modelsLeftOut?: {
|
|
142
|
+
cwd: string;
|
|
143
|
+
source: Source;
|
|
144
|
+
model: string;
|
|
145
|
+
}[];
|
|
139
146
|
/** Keys and tokens cut out of what it wrote (secret-cut.ts): the environment's values, the saved keys, and those of a
|
|
140
147
|
* known format secretlint found. */
|
|
141
148
|
secretsRemoved?: number;
|
|
@@ -171,6 +178,9 @@ export declare function transcriptOf(session: Session, cut: (value: unknown) =>
|
|
|
171
178
|
batches: StorageWrite[][];
|
|
172
179
|
entries: EntryLike[];
|
|
173
180
|
};
|
|
181
|
+
/** What an imported agent is told when its project has no CLAUDE.md or AGENTS.md (or the harness's own file): an agentic
|
|
182
|
+
* revision with no instructions is refused every run (runnable.ts), so an import never writes one. */
|
|
183
|
+
export declare const importedInstructions: (project: string, source: Source) => string;
|
|
174
184
|
/** The secrets this server made and keeps, by value: its API token and its sign-in sessions' secret (still files beside the
|
|
175
185
|
* store), and its webhook's signing secret (`whsec_...`; webhooks.ts) and every value a trigger source keeps sealed, as
|
|
176
186
|
* store rows (server-secrets-store.ts), opened with the seal key of `env`, which the caller has (a dry run over a store
|