@parcha/agentrun-serve 0.1.0-beta.32 → 0.1.0-beta.34
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 +270 -0
- package/README.md +343 -246
- package/dist/adapters.d.ts +0 -7
- package/dist/adapters.js +11 -22
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +14 -0
- package/dist/api-only.js +33 -0
- package/dist/archil-routes.d.ts +1 -1
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-egress-vm.d.ts +0 -8
- package/dist/box-egress-vm.js +0 -10
- package/dist/box-egress.d.ts +0 -4
- package/dist/box-egress.js +1 -16
- package/dist/box-paths.d.ts +25 -2
- package/dist/box-paths.js +79 -11
- package/dist/box-relay.d.ts +0 -11
- package/dist/box-relay.js +0 -20
- package/dist/box-settings.d.ts +26 -0
- package/dist/box-settings.js +63 -0
- package/dist/boxes.d.ts +21 -1
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +94 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -53
- package/dist/browser-person.js +94 -279
- package/dist/budget.d.ts +0 -4
- package/dist/budget.js +0 -7
- package/dist/cap.d.ts +8 -12
- package/dist/cap.js +12 -27
- package/dist/cli.js +61 -20
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +31 -3
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/daytona-api.d.ts +0 -11
- package/dist/daytona-api.js +1 -82
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/docker-host-addresses.d.ts +37 -0
- package/dist/docker-host-addresses.js +110 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -11
- package/dist/files.js +2 -21
- package/dist/github-connection.d.ts +2 -2
- package/dist/github-connection.js +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +22 -5
- package/dist/harness-install.js +98 -20
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/harness.d.ts +4 -3
- package/dist/harness.js +16 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +62 -24
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +8 -1
- package/dist/learn/secrets.js +95 -15
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +37 -5
- package/dist/learned-workflow.js +106 -12
- package/dist/learning-routes.d.ts +16 -49
- package/dist/learning-routes.js +46 -36
- package/dist/learning-run.d.ts +6 -250
- package/dist/learning-run.js +11 -665
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +13 -3
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -52
- package/dist/mcp-gateway.js +44 -148
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +13 -15
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +124 -50
- package/dist/page.d.ts +1 -3
- package/dist/page.js +9 -19
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +28 -62
- package/dist/pause.d.ts +0 -2
- package/dist/pause.js +1 -8
- package/dist/place.d.ts +0 -5
- package/dist/place.js +0 -10
- package/dist/print.d.ts +2 -1
- package/dist/print.js +4 -2
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -13
- package/dist/run-db.js +2 -41
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +46 -2
- package/dist/run-learning-served.js +26 -7
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +33 -0
- package/dist/run-secrets.js +53 -0
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +19 -5
- package/dist/run-view.d.ts +12 -17
- package/dist/run-view.js +29 -28
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +14 -3
- package/dist/runner/adapter-loop.js +464 -62
- package/dist/runner/adapter-run-spec.d.ts +29 -8
- package/dist/runner/adapter-run-spec.js +96 -37
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +15 -1
- package/dist/runner/adapters/pi.js +19 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +54 -12
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +49 -15
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +60 -17
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +30 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/live-ticker.d.ts +1 -1
- package/dist/runner/live-ticker.js +28 -4
- package/dist/runner/loop-contract.d.ts +3 -2
- package/dist/runner/main.d.ts +64 -10
- package/dist/runner/main.js +165 -27
- package/dist/runner/mcp-claim.d.ts +1 -1
- package/dist/runner/mcp-claim.js +2 -3
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +154 -11
- package/dist/runner/redact.d.ts +8 -2
- package/dist/runner/redact.js +11 -2
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +68 -26
- package/dist/runs-over-store.d.ts +8 -3
- package/dist/runs-over-store.js +76 -19
- package/dist/seal-key.d.ts +54 -15
- package/dist/seal-key.js +232 -82
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/secrets.d.ts +2 -10
- package/dist/secrets.js +21 -17
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +10 -32
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -33
- package/dist/server.d.ts +26 -44
- package/dist/server.js +229 -142
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +3 -3
- package/dist/store/open.d.ts +18 -5
- package/dist/store/open.js +23 -3
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +27 -3
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +64 -20
- package/dist/store/store.d.ts +38 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +25 -6
- package/dist/store-reads/journal.js +173 -21
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +91 -23
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +9 -104
- package/dist/tool-keys.js +15 -271
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +31 -19
- package/dist/tools.js +101 -108
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-schedule.js +2 -1
- package/dist/trigger-secrets-shown.js +5 -1
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +52 -5
- package/dist/workspace/computer-deps.js +154 -19
- package/dist/workspace/computer-for-claim.d.ts +19 -14
- package/dist/workspace/computer-for-claim.js +77 -16
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/computer-providers.d.ts +6 -2
- package/dist/workspace/computer-providers.js +1 -1
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +4 -3
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -17
- package/dist/workspace.js +3 -99
- package/launcher/agentrun-serve +6 -33
- package/package.json +14 -14
- package/templates/README.md +9 -3
- package/templates/inbound-lead/agent.md +1 -1
- package/templates/kyb/agent.md +1 -1
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/app.d.ts +0 -5
- package/dist/app.js +0 -514
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/bounds.d.ts +0 -26
- package/dist/bounds.js +0 -137
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-35-7aeIZ.js +0 -519
- package/dist/console/assets/index-Cejbov-Y.css +0 -1
- package/dist/content-filter.d.ts +0 -7
- package/dist/content-filter.js +0 -23
- package/dist/disk.d.ts +0 -33
- package/dist/disk.js +0 -85
- package/dist/door-line.d.ts +0 -23
- package/dist/door-line.js +0 -83
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/harness-app.d.ts +0 -69
- package/dist/harness-app.js +0 -1162
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/request-start.d.ts +0 -27
- package/dist/request-start.js +0 -381
- package/dist/run-box.d.ts +0 -205
- package/dist/run-box.js +0 -661
- package/dist/run-holder.d.ts +0 -52
- package/dist/run-holder.js +0 -139
- package/dist/runs.d.ts +0 -1200
- package/dist/runs.js +0 -4103
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -178
- package/dist/served-only.d.ts +0 -5
- package/dist/served-only.js +0 -12
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { checkGpu } from "@parcha/agentrun-computer";
|
|
2
|
+
import { noDockerWords } from "../docker-daemon.js";
|
|
1
3
|
/** A provider's keys as the claim reads them: each key its registry entry declares, by `keyOf` (the server's reader:
|
|
2
4
|
* key-meta.ts keyReader, the environment's value, else the saved one); a key with no value is left out. */
|
|
3
5
|
export const providerKeys = (registry, keyOf) => async (provider) => {
|
|
@@ -9,15 +11,28 @@ export const providerKeys = (registry, keyOf) => async (provider) => {
|
|
|
9
11
|
}
|
|
10
12
|
return keys;
|
|
11
13
|
};
|
|
14
|
+
/** Whether a provider's computers run only on the vendor's own network: the network forms it declares (its module's
|
|
15
|
+
* NETWORK, its capabilities().network) are "open" alone, as a cloud phone's and a hosted browser's are. */
|
|
16
|
+
export const vendorNetworkOnly = (network) => network !== undefined && network.length > 0 && network.every((one) => one === "open");
|
|
17
|
+
/** Whether a provider's computers can't have no network: it declares its network forms and "none" isn't one (a cloud
|
|
18
|
+
* phone, a hosted browser, Local Chrome). */
|
|
19
|
+
export const needsNetwork = (network) => network !== undefined && network.length > 0 && !network.includes("none");
|
|
20
|
+
/** Why a computer that needs a network is refused where this server's AGENTRUN_BOX_ALLOW is none, in words that name the
|
|
21
|
+
* fix: the operator said no network at all, and the computer can't run without one. */
|
|
22
|
+
export const noNetworkRefusal = (label, kind) => `This agent's computer is a ${label} ${kind}, which needs a network (the vendor's own, or public addresses from this machine), and this server's AGENTRUN_BOX_ALLOW is none (no network): pick a computer that runs with no network in ${SETTINGS}, or set AGENTRUN_BOX_ALLOW to a host list.`;
|
|
12
23
|
/** Whether an agent's computer `setting` can be had in `mode` now, by the answers the claim gives (resolveComputer: the
|
|
13
24
|
* kind, the provider and what it serves, the mode's mount, the provider's keys by `keyOf`): ok, or its refusal in words
|
|
14
25
|
* that name the fix. Nothing starts. A run's start asks it before the run is made (runnable.ts).
|
|
15
26
|
*
|
|
16
|
-
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
27
|
+
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's
|
|
28
|
+
* daemon check, docker-daemon.ts). Any computer on such a provider, a sandbox or a desktop in either mode, is refused
|
|
29
|
+
* here, at the start, where the claim would only fail to launch it: no daemon at all in the one wording Settings →
|
|
30
|
+
* Computers and the claim say (noDockerWords), another reason in its own words. Asked here, not in resolveComputer: the
|
|
31
|
+
* claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
|
|
32
|
+
*
|
|
33
|
+
* `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
|
|
34
|
+
* "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
|
|
35
|
+
export async function computerReadiness(setting, mode, registry, keyOf, answers, boxAllow) {
|
|
21
36
|
const resolved = await resolveComputer(setting, mode, registry, {
|
|
22
37
|
keysOf: providerKeys(registry, keyOf),
|
|
23
38
|
// A setting is given, so the Mode 1 default (the only asker) is never read; and nothing is launched.
|
|
@@ -27,10 +42,16 @@ export async function computerReadiness(setting, mode, registry, keyOf, answers)
|
|
|
27
42
|
if ("refused" in resolved)
|
|
28
43
|
return { refused: resolved.refused };
|
|
29
44
|
const entry = registry.PROVIDERS.find((one) => one.id === resolved.provider);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
if (entry && entry.mounts.includes("bind") && answers) {
|
|
46
|
+
const said = await answers(entry.id);
|
|
47
|
+
// It names the box whose probe said no (a refusal's details.box), as the box check did.
|
|
48
|
+
if (!said.up && said.absent)
|
|
49
|
+
return { refused: noDockerWords(resolved.kind, registry.PROVIDERS, mode), box: entry.id };
|
|
50
|
+
if (!said.up)
|
|
51
|
+
return { refused: `This agent's computer is a ${entry.label} ${resolved.kind}, and this server cannot run it: ${said.reason.replace(/[.!?]+$/, "")}.`, box: entry.id };
|
|
52
|
+
}
|
|
53
|
+
if (boxAllow === "none" && entry && needsNetwork(entry.network))
|
|
54
|
+
return { refused: noNetworkRefusal(entry.label, resolved.kind) };
|
|
34
55
|
return { ok: true };
|
|
35
56
|
}
|
|
36
57
|
const SETTINGS = "Settings → Computers";
|
|
@@ -134,6 +155,15 @@ export async function resolveComputer(given, mode, registry, side) {
|
|
|
134
155
|
return { refused: `Mode 2 keeps workspaces on Archil; a local Docker computer can't mount them. Pick a remote sandbox for this agent's computer in ${SETTINGS}, or no computer.` };
|
|
135
156
|
return { refused: `A ${entry.label} sandbox can't mount the run's folder from Archil: pick another sandbox for this agent's computer in ${SETTINGS}.` };
|
|
136
157
|
}
|
|
158
|
+
// Its GPUs, a sandbox's alone: in checkGpu's words, against what the configuration that serves it declares, with the
|
|
159
|
+
// mode's folder as the mount it takes (a sandbox here always mounts it).
|
|
160
|
+
const gpu = kind === "sandbox" && setting.gpu ? setting.gpu : undefined;
|
|
161
|
+
if (gpu) {
|
|
162
|
+
const offered = serving.find((one) => one.gpu !== undefined) ?? serving[0];
|
|
163
|
+
const [refusal] = checkGpu(gpu, offered, { kind: mode === 1 ? "bind" : "archil" });
|
|
164
|
+
if (refusal)
|
|
165
|
+
return { refused: `A ${entry.label} sandbox can't have this agent's GPUs: ${refusal.message}. Change the GPUs or the provider for this agent's computer in ${SETTINGS}.` };
|
|
166
|
+
}
|
|
137
167
|
// Its keys: every required one saved, before anything starts; only declared names go to the provider.
|
|
138
168
|
const saved = await side.keysOf(entry.id);
|
|
139
169
|
const has = (name) => typeof saved[name] === "string" && saved[name] !== "";
|
|
@@ -154,9 +184,13 @@ export async function resolveComputer(given, mode, registry, side) {
|
|
|
154
184
|
const mount = mounts ? await workspace.mountSpec() : undefined;
|
|
155
185
|
let launched;
|
|
156
186
|
try {
|
|
157
|
-
launched = await side.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(signal ? { signal } : {}) });
|
|
187
|
+
launched = await side.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(gpu ? { gpu: { type: gpu.type, count: gpu.count } } : {}), ...(signal ? { signal } : {}) });
|
|
158
188
|
}
|
|
159
189
|
catch (error) {
|
|
190
|
+
// A provider that binds a folder of this machine (Docker) whose daemon does not answer: the one wording.
|
|
191
|
+
const said = entry.mounts.includes("bind") && side.daemon ? await side.daemon(entry.id).catch(() => undefined) : undefined;
|
|
192
|
+
if (said && !said.up && said.absent)
|
|
193
|
+
throw unavailable(noDockerWords(kind, registry.PROVIDERS, mode));
|
|
160
194
|
throw unavailable(`${entry.label} could not start a ${kind} computer: ${error instanceof Error ? error.message : String(error)}`);
|
|
161
195
|
}
|
|
162
196
|
const computer = runComputerOf(kind, launched, mounts ? check : undefined);
|
|
@@ -171,8 +205,9 @@ export async function resolveComputer(given, mode, registry, side) {
|
|
|
171
205
|
/** The started computer as runTools takes it, or what it lacks, in words. */
|
|
172
206
|
function runComputerOf(kind, launched, check) {
|
|
173
207
|
const groups = launched.groups;
|
|
208
|
+
// The run's browser tool opens a browser's sessions through its provider.
|
|
174
209
|
if (kind === "browser")
|
|
175
|
-
return launched.
|
|
210
|
+
return launched.browser ? { kind, browser: launched.browser } : "it gave no CDP connection";
|
|
176
211
|
const { client } = launched;
|
|
177
212
|
if (!client)
|
|
178
213
|
return "it gave no computer protocol client";
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
2
|
import type { HostTool } from "@parcha/agentrun-kernel";
|
|
3
|
-
import { type CapabilityKind, type
|
|
3
|
+
import { type CapabilityKind, type Registry } from "@parcha/agentrun-kernel/kernel";
|
|
4
4
|
import type { ComputerClient, Group } from "@parcha/agentrun-computer";
|
|
5
|
-
import type { Park, RunGate } from "../tool-gate.js";
|
|
6
5
|
import type { AttachableComputer, MountCheck } from "./attach.js";
|
|
7
6
|
import { type PiAnswer, type PiExecutor } from "./executors.js";
|
|
8
7
|
import { type Hands } from "./hands.js";
|
|
9
|
-
import { type ShellPlace } from "./resolve-computer.js";
|
|
8
|
+
import { type ClaimBrowser, type ShellPlace } from "./resolve-computer.js";
|
|
10
9
|
import type { Workspace } from "./workspace.js";
|
|
11
10
|
/**
|
|
12
11
|
* The run's computer, as runTools takes it, by its kind:
|
|
@@ -15,7 +14,8 @@ import type { Workspace } from "./workspace.js";
|
|
|
15
14
|
* - desktop: a screen and input; the folder is attached only when its provider mounts it (`check` given) and it offers
|
|
16
15
|
* files and exec;
|
|
17
16
|
* - phone: a screen, touch and apps; never attached;
|
|
18
|
-
* - browser: its CDP
|
|
17
|
+
* - browser: what the run's browser tool drives it by (its CDP URL through its provider); no tools of the registry's,
|
|
18
|
+
* never attached.
|
|
19
19
|
* `groups`: what the computer offers (its hello's groups), which fill its kind's ports.
|
|
20
20
|
*/
|
|
21
21
|
export type RunComputer = {
|
|
@@ -35,7 +35,7 @@ export type RunComputer = {
|
|
|
35
35
|
readonly groups: readonly Group[];
|
|
36
36
|
} | {
|
|
37
37
|
readonly kind: "browser";
|
|
38
|
-
readonly
|
|
38
|
+
readonly browser: ClaimBrowser;
|
|
39
39
|
};
|
|
40
40
|
/** A desktop's or a phone's ports as a person's hold on the computer gives them back: each call made while the person
|
|
41
41
|
* holds it waits for hand-back; a read then runs, an action then is refused (the take-over's own words). With them, the
|
|
@@ -105,17 +105,12 @@ export type ToolResults = Map<string, {
|
|
|
105
105
|
}>;
|
|
106
106
|
/**
|
|
107
107
|
* `registry`'s tools that `names` names, in that order, bound to `run`: each as the kernel's HostTool, which an adapter's
|
|
108
|
-
* session takes.
|
|
109
|
-
* run of an approved call): a refused one runs nothing, a parked one says it waits. Then the registry runs it on the
|
|
108
|
+
* session takes. The run's gate decided the call before its intent (the adapter loop's). The registry runs it on the
|
|
110
109
|
* run's hands, and its answer is the text a model reads (executors.ts answerText): the output, the failure's words, the
|
|
111
110
|
* diagnostics; in a failure, a write's or an edit's answer a path in the run's folder is named relative to it. A
|
|
112
111
|
* failure the registry throws is the answer's text. `results` keeps each answer by its call id.
|
|
113
112
|
*/
|
|
114
113
|
export declare function bindTools(run: RunHands, registry: RunRegistry, names: readonly string[], options?: {
|
|
115
|
-
readonly gated?: {
|
|
116
|
-
readonly gate: RunGate;
|
|
117
|
-
readonly park: Park;
|
|
118
|
-
};
|
|
119
114
|
readonly results?: ToolResults;
|
|
120
115
|
}): HostTool[];
|
|
121
116
|
/** A run's tools: what E2's harness start calls runTools for. */
|
|
@@ -125,46 +120,33 @@ export type RunTools = {
|
|
|
125
120
|
/** The run's registry: the kernel's definitions, words and limits, over this run's hands and executors. */
|
|
126
121
|
readonly registry: Registry;
|
|
127
122
|
readonly hands: Hands;
|
|
123
|
+
/** Where the run's shell is (runHands' shell): its gate reads its defaults by it (tool-gate.ts defaultPermission). */
|
|
124
|
+
readonly shell: ShellPlace;
|
|
128
125
|
/** The tools the claimed computer brings by its kind, as its groups offer them: a desktop's (desktop_screen,
|
|
129
126
|
* desktop_input, computer_request_handoff) or a phone's, by the kernel registry's own list. None with no computer, for
|
|
130
127
|
* a sandbox, or for a browser (its own binding lists its tools). An agent names its computer, never these tools
|
|
131
128
|
* (definition.tools refuses them), so a run binds them beside what it was granted (withKindTools). */
|
|
132
129
|
readonly kindTools: readonly string[];
|
|
133
130
|
/** The registry's tools `names` names, as the kernel's HostTool an adapter's session takes, each call through the
|
|
134
|
-
* run's gate
|
|
135
|
-
hostTools(names: readonly string[],
|
|
136
|
-
readonly gate: RunGate;
|
|
137
|
-
readonly park: Park;
|
|
138
|
-
}, results?: ToolResults): HostTool[];
|
|
131
|
+
* run's gate decided before its intent, each answer kept in `results` (bindTools). */
|
|
132
|
+
hostTools(names: readonly string[], results?: ToolResults): HostTool[];
|
|
139
133
|
/** The run's end, before the computer is let go: its background processes ended (TERM, then KILL 3 s later; none with
|
|
140
134
|
* no computer), then bash's full outputs and TMPDIR swept. */
|
|
141
135
|
end(): Promise<void>;
|
|
142
136
|
};
|
|
143
|
-
/** A browser computer's tools as the run's start gives them: pi-browser's runs by tool name (over hands.browser), and
|
|
144
|
-
* what the browser offers, which lists browser_downloads, browser_upload and browser_request_handoff (pi-browser's
|
|
145
|
-
* listedFor). */
|
|
146
|
-
export type RunBrowser = {
|
|
147
|
-
readonly executors: Readonly<Record<string, Executor>>;
|
|
148
|
-
readonly offers: {
|
|
149
|
-
readonly downloads: boolean;
|
|
150
|
-
readonly upload: boolean;
|
|
151
|
-
readonly handoff: boolean;
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
137
|
/**
|
|
155
138
|
* A run's tools on `workspace`, attached to `computer` when its kind has files and exec and its provider mounts the
|
|
156
139
|
* folder (RunComputer). `computer.check` is the mount check attach runs (attach.ts MountCheck: `{ readBackOf, epoch }`),
|
|
157
140
|
* which the caller builds with the claim's epoch, so a read-back under another epoch is refused. `options.mode`: 1, or 2
|
|
158
141
|
* (the run's folder on Archil); `options.aliases`: other absolute names of the run's folder a tool call may give (the
|
|
159
|
-
* harness's scratch folder)
|
|
160
|
-
*
|
|
161
|
-
*
|
|
142
|
+
* harness's scratch folder). The tools' definitions, words and limits come only from the kernel's registry; this binds
|
|
143
|
+
* their executors to the run. A browser computer brings none of the registry's: the run's browser tool (tools.ts,
|
|
144
|
+
* pi-browser's durable extension) drives it.
|
|
162
145
|
*/
|
|
163
146
|
export declare function runTools(workspace: Workspace, computer: RunComputer | undefined, options: {
|
|
164
147
|
readonly mode: 1 | 2;
|
|
165
148
|
readonly context: Context;
|
|
166
149
|
readonly aliases?: readonly string[];
|
|
167
|
-
readonly browser?: RunBrowser;
|
|
168
150
|
readonly hold?: RunHold;
|
|
169
151
|
}): Promise<RunTools>;
|
|
170
152
|
/** The names a run binds as host tools: what it was granted, then the tools its claimed computer brings by its kind
|
|
@@ -15,7 +15,7 @@ function mountedIn(computer) {
|
|
|
15
15
|
return undefined;
|
|
16
16
|
}
|
|
17
17
|
/** The kind's ports, as the computer's groups offer them, the kinds whose tools the run gets (a desktop's with a screen
|
|
18
|
-
* and input, a phone's with a screen and touch
|
|
18
|
+
* and input, a phone's with a screen and touch; a browser's none), and the kind's tools its groups do not offer: a
|
|
19
19
|
* phone's tree without apps.ui_tree, its keys without input.keys (an iPhone's today). */
|
|
20
20
|
function portsOf(computer) {
|
|
21
21
|
if (computer?.kind === "desktop") {
|
|
@@ -31,8 +31,6 @@ function portsOf(computer) {
|
|
|
31
31
|
const keys = computer.groups.includes("input.keys");
|
|
32
32
|
return { ports: { phone: phoneOf(computer.computer.client, { tree, keys }) }, kinds: ["phone"], without: [...(tree ? [] : ["phone_tree"]), ...(keys ? [] : ["phone_key"])] };
|
|
33
33
|
}
|
|
34
|
-
if (computer?.kind === "browser")
|
|
35
|
-
return { ports: { browser: { connect: computer.connect } }, kinds: ["browser"], without: [] };
|
|
36
34
|
return { ports: {}, kinds: [], without: [] };
|
|
37
35
|
}
|
|
38
36
|
/** The run's scratch in its own folder: bash's TMPDIR. */
|
|
@@ -86,8 +84,7 @@ export async function runHands(workspace, computer, options) {
|
|
|
86
84
|
const SAYS_PATH = new Set(["write", "edit"]);
|
|
87
85
|
/**
|
|
88
86
|
* `registry`'s tools that `names` names, in that order, bound to `run`: each as the kernel's HostTool, which an adapter's
|
|
89
|
-
* session takes.
|
|
90
|
-
* run of an approved call): a refused one runs nothing, a parked one says it waits. Then the registry runs it on the
|
|
87
|
+
* session takes. The run's gate decided the call before its intent (the adapter loop's). The registry runs it on the
|
|
91
88
|
* run's hands, and its answer is the text a model reads (executors.ts answerText): the output, the failure's words, the
|
|
92
89
|
* diagnostics; in a failure, a write's or an edit's answer a path in the run's folder is named relative to it. A
|
|
93
90
|
* failure the registry throws is the answer's text. `results` keeps each answer by its call id.
|
|
@@ -104,14 +101,7 @@ export function bindTools(run, registry, names, options = {}) {
|
|
|
104
101
|
description: def.description,
|
|
105
102
|
inputSchema: def.parameters,
|
|
106
103
|
replay: def.replaySafe ? "safe" : "never",
|
|
107
|
-
async call(args, { callId, signal,
|
|
108
|
-
// A replay (the kernel's attempt above 0) may follow an attempt that was sent: the gate's refusal then says so.
|
|
109
|
-
const refused = await options.gated?.gate.enter(name, args, callId, options.gated.park, (attempt ?? 0) > 0 ? { replayed: true } : {});
|
|
110
|
-
if (refused) {
|
|
111
|
-
const answer = { text: refused.text, isError: refused.isError === true };
|
|
112
|
-
options.results?.set(callId, answer);
|
|
113
|
-
return refused.parked ? { ...answer, parked: true } : answer;
|
|
114
|
-
}
|
|
104
|
+
async call(args, { callId, signal, model, output }) {
|
|
115
105
|
let given;
|
|
116
106
|
try {
|
|
117
107
|
// The calling model and the call's output stream, as the session gave them: pi's read sizes an image by the
|
|
@@ -136,28 +126,21 @@ export function bindTools(run, registry, names, options = {}) {
|
|
|
136
126
|
* folder (RunComputer). `computer.check` is the mount check attach runs (attach.ts MountCheck: `{ readBackOf, epoch }`),
|
|
137
127
|
* which the caller builds with the claim's epoch, so a read-back under another epoch is refused. `options.mode`: 1, or 2
|
|
138
128
|
* (the run's folder on Archil); `options.aliases`: other absolute names of the run's folder a tool call may give (the
|
|
139
|
-
* harness's scratch folder)
|
|
140
|
-
*
|
|
141
|
-
*
|
|
129
|
+
* harness's scratch folder). The tools' definitions, words and limits come only from the kernel's registry; this binds
|
|
130
|
+
* their executors to the run. A browser computer brings none of the registry's: the run's browser tool (tools.ts,
|
|
131
|
+
* pi-browser's durable extension) drives it.
|
|
142
132
|
*/
|
|
143
133
|
export async function runTools(workspace, computer, options) {
|
|
144
134
|
const run = await runHands(workspace, computer, options);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const { BROWSER_TOOLS, listedFor } = await import("@parcha/pi-browser");
|
|
148
|
-
const offers = options.browser?.offers;
|
|
149
|
-
const browserTools = run.kinds.includes("browser") ? BROWSER_TOOLS.filter((contract) => listedFor(contract, offers ?? { downloads: false, upload: false, handoff: false })) : BROWSER_TOOLS;
|
|
150
|
-
const registry = createRegistry({
|
|
151
|
-
maxExecS: run.maxExecS, shell: run.shell, kinds: run.kinds, browserTools, without: run.without,
|
|
152
|
-
executors: { ...run.executors, ...(options.browser ? { browser: options.browser.executors } : {}) },
|
|
153
|
-
});
|
|
154
|
-
const brought = new Set(run.kinds.filter((kind) => kind !== "browser").flatMap((kind) => capabilityToolDefs(kind).map((def) => def.name)));
|
|
135
|
+
const registry = createRegistry({ maxExecS: run.maxExecS, shell: run.shell, kinds: run.kinds, without: run.without, executors: run.executors });
|
|
136
|
+
const brought = new Set(run.kinds.flatMap((kind) => capabilityToolDefs(kind).map((def) => def.name)));
|
|
155
137
|
return {
|
|
156
138
|
workspace: run.workspace,
|
|
157
139
|
registry,
|
|
158
140
|
hands: run.hands,
|
|
141
|
+
shell: run.shell,
|
|
159
142
|
kindTools: registry.list().map((def) => def.name).filter((name) => brought.has(name)),
|
|
160
|
-
hostTools: (names,
|
|
143
|
+
hostTools: (names, results) => bindTools(run, registry, names, results ? { results } : {}),
|
|
161
144
|
async end() {
|
|
162
145
|
await endBackground(run.hands);
|
|
163
146
|
await run.sweep();
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import type { ToolRegistration } from "@earendil-works/pi-durable";
|
|
2
1
|
export { realOf, workspaceRelative } from "./workspace/paths.js";
|
|
3
|
-
/**
|
|
4
|
-
* Refuses `given`, a path a call gave that leaves the workspace, in the one words every refusal uses:
|
|
5
|
-
* `<given>: outside the workspace`, and no other path (not the workspace, a box's work dir, or where it resolves). It is
|
|
6
|
-
* the confinement's typed refusal (`PathOutsideWorkError`, `outside_work`), so its type tells it from any other error.
|
|
7
|
-
* For a tool that checks a path itself (a box's file tools); pi's own tools refuse through the confinement, named by
|
|
8
|
-
* `asGivenRefusals`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function refuseOutsideWorkspace(given: string): never;
|
|
11
|
-
/**
|
|
12
|
-
* pi's file `tools`, each with its confinement's refusal named by the path the call gave, as it gave it:
|
|
13
|
-
* `../../.token: outside the workspace`. The confinement names no path itself: pi's tools resolve a path against the
|
|
14
|
-
* workspace before they ask for it, so every path it sees is the host's own (`<data>/runs/.token`), and the call's
|
|
15
|
-
* `path` is the only one the model gave. A refusal is told by its type (`PathOutsideWorkError`), never by its text; one
|
|
16
|
-
* already named (`refuseOutsideWorkspace`), every other error, and every result are the tool's own.
|
|
17
|
-
*/
|
|
18
|
-
export declare function asGivenRefusals(tools: readonly ToolRegistration[]): ToolRegistration[];
|
|
19
2
|
/** How a run's rows name a file path, a whole path (never a text): one in the run's directory relative to its workspace
|
|
20
3
|
* (`<run>/work`: `hello.md`, `.`, `../work 2024/a.md`, `..`), and any other path, or one that is not absolute, exactly
|
|
21
4
|
* as given. Checked against the workspace as serve names it and as the kernel resolves it (a harness's CLI sends the
|
package/dist/workspace-paths.js
CHANGED
|
@@ -1,50 +1,10 @@
|
|
|
1
1
|
// How serve names a path in the run's workspace to a person or a model: relative to the workspace, never by the server's
|
|
2
2
|
// data directory. The rule is one for every place that shows a path: a host tool's error or write result
|
|
3
|
-
// (host-tools.ts), and a
|
|
4
|
-
// outside the workspace names the path the call gave, as it gave it, and no other (`asGivenRefusals`), wherever the
|
|
5
|
-
// coding tools come from (coding-tools.ts: pi's own runs and the other harnesses' host tools, on the runner and in a box).
|
|
3
|
+
// (host-tools.ts), and a row's file path (rowPaths).
|
|
6
4
|
import { dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
7
|
-
import { PathOutsideWorkError } from "@parcha/pi-durable-disk";
|
|
8
5
|
import { realOf } from "./workspace/paths.js";
|
|
9
6
|
// How a text names the run's folder, and a path as the kernel resolves it, are the Workspace's (workspace/paths.ts).
|
|
10
7
|
export { realOf, workspaceRelative } from "./workspace/paths.js";
|
|
11
|
-
/** A refusal already named by the path the call gave: `asGivenRefusals` passes it on as it is. */
|
|
12
|
-
class GivenPathRefusal extends PathOutsideWorkError {
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Refuses `given`, a path a call gave that leaves the workspace, in the one words every refusal uses:
|
|
16
|
-
* `<given>: outside the workspace`, and no other path (not the workspace, a box's work dir, or where it resolves). It is
|
|
17
|
-
* the confinement's typed refusal (`PathOutsideWorkError`, `outside_work`), so its type tells it from any other error.
|
|
18
|
-
* For a tool that checks a path itself (a box's file tools); pi's own tools refuse through the confinement, named by
|
|
19
|
-
* `asGivenRefusals`.
|
|
20
|
-
*/
|
|
21
|
-
export function refuseOutsideWorkspace(given) {
|
|
22
|
-
throw new GivenPathRefusal(given, "outside_work", `${given}: outside the workspace`);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* pi's file `tools`, each with its confinement's refusal named by the path the call gave, as it gave it:
|
|
26
|
-
* `../../.token: outside the workspace`. The confinement names no path itself: pi's tools resolve a path against the
|
|
27
|
-
* workspace before they ask for it, so every path it sees is the host's own (`<data>/runs/.token`), and the call's
|
|
28
|
-
* `path` is the only one the model gave. A refusal is told by its type (`PathOutsideWorkError`), never by its text; one
|
|
29
|
-
* already named (`refuseOutsideWorkspace`), every other error, and every result are the tool's own.
|
|
30
|
-
*/
|
|
31
|
-
export function asGivenRefusals(tools) {
|
|
32
|
-
return tools.map((tool) => ({
|
|
33
|
-
...tool,
|
|
34
|
-
async execute(args, api, context) {
|
|
35
|
-
try {
|
|
36
|
-
return await tool.execute(args, api, context);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
const reason = error instanceof PathOutsideWorkError ? error.reason : undefined;
|
|
40
|
-
const given = args?.path;
|
|
41
|
-
if (reason === undefined || error instanceof GivenPathRefusal || typeof given !== "string" || given === "")
|
|
42
|
-
throw error;
|
|
43
|
-
throw new GivenPathRefusal(given, reason, `${given}: ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
8
|
/** How a run's rows name a file path, a whole path (never a text): one in the run's directory relative to its workspace
|
|
49
9
|
* (`<run>/work`: `hello.md`, `.`, `../work 2024/a.md`, `..`), and any other path, or one that is not absolute, exactly
|
|
50
10
|
* as given. Checked against the workspace as serve names it and as the kernel resolves it (a harness's CLI sends the
|
package/dist/workspace.d.ts
CHANGED
|
@@ -34,8 +34,6 @@ export declare function openWorkFile(work: string, rel: string): Promise<{
|
|
|
34
34
|
handle: FileHandle;
|
|
35
35
|
stats: Stats;
|
|
36
36
|
}>;
|
|
37
|
-
/** `rel` under `work` as text, read as `openWorkFile` reads it. */
|
|
38
|
-
export declare function readWorkText(work: string, rel: string): Promise<string>;
|
|
39
37
|
/** `rel` under `work`, its bytes, read as `openWorkFile` reads it; refused ("over_cap") when larger than `maxBytes`. */
|
|
40
38
|
export declare function readWorkBytes(work: string, rel: string, { maxBytes }: {
|
|
41
39
|
maxBytes: number;
|
|
@@ -54,21 +52,6 @@ export declare function walkWork(work: string, visit: (path: string, stats: Stat
|
|
|
54
52
|
depth?: number;
|
|
55
53
|
refused?: (path: string, reason: RefusedReason) => void;
|
|
56
54
|
}): Promise<void>;
|
|
57
|
-
/**
|
|
58
|
-
* Writes `bytes` to `rel` under `work` whole and durably (files.ts writeDurable), as a file of `mode`: through a temporary
|
|
59
|
-
* file in the same directory, a dot-name of the server's own, renamed over the file. The directories on the way are made
|
|
60
|
-
* when missing, and each is synced into its parent before this resolves. A link on the way or at the file, or a directory
|
|
61
|
-
* there, is refused: never followed and never replaced. Answers the stats of the file this call wrote. `asTool`, a run's
|
|
62
|
-
* file tool writing a bound box's work/ (bound-files.ts): a file with another hard link is refused, a file already there
|
|
63
|
-
* keeps its mode, and a new one gets `mode` as given, whatever this process's umask.
|
|
64
|
-
*/
|
|
65
|
-
export declare function writeWorkFile(work: string, rel: string, bytes: Uint8Array, mode?: number, asTool?: boolean): Promise<Stats>;
|
|
66
|
-
/** Removes the regular file `rel` under `work`, reached through no link: refused when it is missing, a link, or not a
|
|
67
|
-
* regular file. A directory it leaves empty stays. */
|
|
68
|
-
export declare function removeWorkFile(work: string, rel: string): Promise<void>;
|
|
69
55
|
/** Throws unless the kernel refuses a hard link to a file the linker cannot write (fs.protected_hardlinks = 1): with a
|
|
70
56
|
* run's commands under a uid of their own, it keeps them from linking this server's files into their workspace. */
|
|
71
57
|
export declare function assertHardlinkProtection(read?: () => string): void;
|
|
72
|
-
/** Does nothing: the run's host tools file through its Workspace, and nothing copies their files into a remote box any
|
|
73
|
-
* more. Kept only so the run's start (app.ts) compiles until its rewrite drops the call. */
|
|
74
|
-
export declare function mirrorWrites(_work: string, _mirror: (path: string, data: string | Uint8Array) => Promise<void>): void;
|
package/dist/workspace.js
CHANGED
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
// check and the open is refused, not followed. On top of it: the path must be the root joined with its own names (a link
|
|
5
5
|
// anywhere on the way, even one pointing inside the root, is refused), only regular files and directories are read, and a
|
|
6
6
|
// file with a second hard link is refused, since it could be one of this server's own files linked in.
|
|
7
|
-
import { randomBytes } from "node:crypto";
|
|
8
7
|
import { closeSync, constants, openSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
9
|
-
import { access, lstat, readdir
|
|
10
|
-
import {
|
|
11
|
-
import { Confinement } from "
|
|
12
|
-
import { syncDir, writeDurable } from "./files.js";
|
|
8
|
+
import { access, lstat, readdir } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { Confinement } from "./confine.js";
|
|
13
11
|
/** A path under work/ this server does not read, and why. */
|
|
14
12
|
export class WorkRefused extends Error {
|
|
15
13
|
path;
|
|
@@ -90,16 +88,6 @@ export async function openWorkFile(work, rel) {
|
|
|
90
88
|
await pin.close();
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
|
-
/** `rel` under `work` as text, read as `openWorkFile` reads it. */
|
|
94
|
-
export async function readWorkText(work, rel) {
|
|
95
|
-
const { handle } = await openWorkFile(work, rel);
|
|
96
|
-
try {
|
|
97
|
-
return await handle.readFile("utf8");
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
await handle.close();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
91
|
/** `rel` under `work`, its bytes, read as `openWorkFile` reads it; refused ("over_cap") when larger than `maxBytes`. */
|
|
104
92
|
export async function readWorkBytes(work, rel, { maxBytes }) {
|
|
105
93
|
const { handle, stats } = await openWorkFile(work, rel);
|
|
@@ -202,87 +190,6 @@ export async function walkWork(work, visit, { skip = () => false, depth = WALK_D
|
|
|
202
190
|
};
|
|
203
191
|
await into("", 0);
|
|
204
192
|
}
|
|
205
|
-
/** A write's or a removal's failure that is a refusal: a link on the way (the confinement's refusal), a directory that
|
|
206
|
-
* is missing or this server may not enter, or a file where a directory is on the way (a directory where the file is).
|
|
207
|
-
* Any other failure, a full disk say, is thrown as it is. */
|
|
208
|
-
const REFUSALS = { permission_denied: "link", ELOOP: "link", ENOENT: "missing", EACCES: "unreadable", ENOTDIR: "not_regular", EISDIR: "not_regular" };
|
|
209
|
-
const refusing = (rel) => (error) => {
|
|
210
|
-
const reason = error instanceof WorkRefused ? error.reason : REFUSALS[error?.code ?? ""];
|
|
211
|
-
throw reason ? new WorkRefused(rel, reason) : error;
|
|
212
|
-
};
|
|
213
|
-
/** Pins the directory holding `rel` under `work` for writing, every directory on the way reached through no link (and,
|
|
214
|
-
* with `parents`, made when missing). Close the pin. */
|
|
215
|
-
async function pinForWrite(work, rel, parents) {
|
|
216
|
-
if (!writesHeld())
|
|
217
|
-
throw new WorkRefused(rel, "unheld");
|
|
218
|
-
const { real, confinement } = confinementOf(work);
|
|
219
|
-
const abs = join(real, rel);
|
|
220
|
-
const refuse = refusing(rel);
|
|
221
|
-
// Checked before the walk makes any directory, so none is made through a link.
|
|
222
|
-
const { canonical } = await confinement.locate(abs, rel, "write", false).catch(refuse);
|
|
223
|
-
if (canonical !== abs)
|
|
224
|
-
throw new WorkRefused(rel, "link");
|
|
225
|
-
// Whether the walk is to make a directory (the file's own is missing).
|
|
226
|
-
const making = parents && !(await lstat(dirname(abs)).catch(() => null));
|
|
227
|
-
const pin = await confinement.pinEntry(abs, rel, { access: "write", follow: false, parents }).catch(refuse);
|
|
228
|
-
if (pin.canonical !== abs) {
|
|
229
|
-
await pin.close();
|
|
230
|
-
throw new WorkRefused(rel, "link");
|
|
231
|
-
}
|
|
232
|
-
return { pin, refuse, real, making };
|
|
233
|
-
}
|
|
234
|
-
/** What is at the pinned entry, by lstat: nothing (undefined), else a regular file, or refused. */
|
|
235
|
-
async function entryOf(pin, refuse, rel) {
|
|
236
|
-
const stats = await lstat(pin.entry).catch((error) => (error?.code === "ENOENT" ? undefined : refuse(error)));
|
|
237
|
-
if (stats && !stats.isFile())
|
|
238
|
-
throw new WorkRefused(rel, stats.isSymbolicLink() ? "link" : "not_regular");
|
|
239
|
-
return stats;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Writes `bytes` to `rel` under `work` whole and durably (files.ts writeDurable), as a file of `mode`: through a temporary
|
|
243
|
-
* file in the same directory, a dot-name of the server's own, renamed over the file. The directories on the way are made
|
|
244
|
-
* when missing, and each is synced into its parent before this resolves. A link on the way or at the file, or a directory
|
|
245
|
-
* there, is refused: never followed and never replaced. Answers the stats of the file this call wrote. `asTool`, a run's
|
|
246
|
-
* file tool writing a bound box's work/ (bound-files.ts): a file with another hard link is refused, a file already there
|
|
247
|
-
* keeps its mode, and a new one gets `mode` as given, whatever this process's umask.
|
|
248
|
-
*/
|
|
249
|
-
export async function writeWorkFile(work, rel, bytes, mode = 0o600, asTool = false) {
|
|
250
|
-
const { pin, refuse, real, making } = await pinForWrite(work, rel, true);
|
|
251
|
-
try {
|
|
252
|
-
const before = await entryOf(pin, refuse, rel);
|
|
253
|
-
if (asTool && before && before.nlink !== 1)
|
|
254
|
-
throw new WorkRefused(rel, "hard_link");
|
|
255
|
-
const kept = asTool && before ? before.mode & 0o777 : mode;
|
|
256
|
-
// A link swapped in after that check is replaced by the rename, never written through.
|
|
257
|
-
const stats = await writeDurable(pin.entry, bytes, kept, `${pin.dir}/.agentrun-${process.pid}-${randomBytes(6).toString("hex")}.tmp`, asTool).catch(refuse);
|
|
258
|
-
// writeDurable synced the file's own directory; a directory made above it survives a crash once its parent is synced.
|
|
259
|
-
if (making) {
|
|
260
|
-
let at = real;
|
|
261
|
-
for (const name of dirname(rel).split("/")) {
|
|
262
|
-
await syncDir(at);
|
|
263
|
-
at = join(at, name);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return stats;
|
|
267
|
-
}
|
|
268
|
-
finally {
|
|
269
|
-
await pin.close();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/** Removes the regular file `rel` under `work`, reached through no link: refused when it is missing, a link, or not a
|
|
273
|
-
* regular file. A directory it leaves empty stays. */
|
|
274
|
-
export async function removeWorkFile(work, rel) {
|
|
275
|
-
const { pin, refuse } = await pinForWrite(work, rel, false);
|
|
276
|
-
try {
|
|
277
|
-
if (!(await entryOf(pin, refuse, rel)))
|
|
278
|
-
throw new WorkRefused(rel, "missing");
|
|
279
|
-
// unlink never follows the name it removes: a link swapped in after the check is removed, not its target.
|
|
280
|
-
await unlink(pin.entry).catch(refuse);
|
|
281
|
-
}
|
|
282
|
-
finally {
|
|
283
|
-
await pin.close();
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
193
|
/** Throws unless the kernel refuses a hard link to a file the linker cannot write (fs.protected_hardlinks = 1): with a
|
|
287
194
|
* run's commands under a uid of their own, it keeps them from linking this server's files into their workspace. */
|
|
288
195
|
export function assertHardlinkProtection(read = () => readFileSync("/proc/sys/fs/protected_hardlinks", "utf8")) {
|
|
@@ -296,6 +203,3 @@ export function assertHardlinkProtection(read = () => readFileSync("/proc/sys/fs
|
|
|
296
203
|
if (value !== "1")
|
|
297
204
|
throw new Error(`agentrun-serve: fs.protected_hardlinks is ${value}, not 1; a run's workspace could hold a link to this server's files`);
|
|
298
205
|
}
|
|
299
|
-
/** Does nothing: the run's host tools file through its Workspace, and nothing copies their files into a remote box any
|
|
300
|
-
* more. Kept only so the run's start (app.ts) compiles until its rewrite drops the call. */
|
|
301
|
-
export function mirrorWrites(_work, _mirror) { }
|
package/launcher/agentrun-serve
CHANGED
|
@@ -7,17 +7,15 @@
|
|
|
7
7
|
#
|
|
8
8
|
# Each secret named below that is set goes into one pipe as NAME=VALUE and a NUL, AGENTRUN_SECRETS_LEN bytes in all,
|
|
9
9
|
# on fd AGENTRUN_SECRETS_FD; the server reads exactly that many bytes first thing and closes the pipe. First, each
|
|
10
|
-
# secret moves out of the environment into this shell's own memory, so no process it starts (
|
|
11
|
-
#
|
|
10
|
+
# secret moves out of the environment into this shell's own memory, so no process it starts (mktemp, mkfifo, rm, env)
|
|
11
|
+
# inherits one; only this launcher's own initial environment, gone at the exec, ever held them. The
|
|
12
12
|
# pipe is a FIFO whose name is gone before any secret is written, and only this shell writes it, with its builtin
|
|
13
13
|
# printf; `env -u` drops every name from what COMMAND inherits too. The condition: this runs before any run's process
|
|
14
14
|
# exists. A process of the same user started earlier could open the FIFO while it is named.
|
|
15
15
|
#
|
|
16
|
-
# AGENTRUN_SEAL_KEY, the key the server keeps
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
# 0600 in a 0700 directory, written by this shell's printf, never on a command line. It is outside the data directory
|
|
20
|
-
# on purpose: a copy of that holds the tool keys as ciphertext alone.
|
|
16
|
+
# AGENTRUN_SEAL_KEY, the key the server keeps every secret under (src/seal-key.ts), is one of them. Not set, the
|
|
17
|
+
# server keeps its own in seal/seal.key in its data directory, beside the store, made at its first start: this launcher
|
|
18
|
+
# neither makes nor reads one.
|
|
21
19
|
#
|
|
22
20
|
# AGENTRUN_STORE_URL, the store's connection, is one too: its URL may hold the database's password. The server and the
|
|
23
21
|
# runner each read it from what they were handed (secrets.ts secret), and no run is handed it.
|
|
@@ -50,32 +48,7 @@ locale=${LC_ALL-}
|
|
|
50
48
|
locale_set=${LC_ALL+x}
|
|
51
49
|
LC_ALL=C
|
|
52
50
|
|
|
53
|
-
# Every other process this launcher starts, it starts here, before it writes a secret.
|
|
54
|
-
# not given.
|
|
55
|
-
config=${XDG_CONFIG_HOME:-${HOME:+$HOME/.config}}
|
|
56
|
-
if [ -z "${agentrun_secret_AGENTRUN_SEAL_KEY+x}" ] && [ -n "$config" ]; then
|
|
57
|
-
keys=$config/agentrun
|
|
58
|
-
# Its own directory, when the person made it with a plain mkdir (0755) and no key is there yet: tightened to 0700
|
|
59
|
-
# before a key is written in it, only when it is this user's. An existing key's directory is never changed, nor a
|
|
60
|
-
# symlink's target, which may be shared (the key check below refuses a linked directory anyway).
|
|
61
|
-
if [ ! -e "$keys/seal.key" ] && [ ! -L "$keys" ] && [ -d "$keys" ] && [ -O "$keys" ]; then
|
|
62
|
-
case $(ls -ld "$keys" 2>/dev/null) in d???------*) ;; *) chmod 700 "$keys" 2>/dev/null || : ;; esac
|
|
63
|
-
fi
|
|
64
|
-
# Made whole beside its name, then linked to it, which fails if another start made it first: each start reads one.
|
|
65
|
-
if [ ! -e "$keys/seal.key" ] && (umask 077 && mkdir -p "$keys") && made=$(head -c 32 /dev/urandom | base64) && [ ${#made} -eq 44 ]; then
|
|
66
|
-
(umask 077 && printf '%s\n' "$made" >"$keys/seal.key.$$" && { ln "$keys/seal.key.$$" "$keys/seal.key" 2>/dev/null || :; }) || :
|
|
67
|
-
rm -f "$keys/seal.key.$$"
|
|
68
|
-
fi
|
|
69
|
-
made=
|
|
70
|
-
# Only a key no other user can read, in a directory no other user can: one they can is refused, never changed.
|
|
71
|
-
case $(ls -ld "$keys" 2>/dev/null):$(ls -l "$keys/seal.key" 2>/dev/null) in
|
|
72
|
-
d???------*:-??-------*) IFS= read -r agentrun_secret_AGENTRUN_SEAL_KEY <"$keys/seal.key" || : ;;
|
|
73
|
-
esac
|
|
74
|
-
if [ -z "${agentrun_secret_AGENTRUN_SEAL_KEY:-}" ]; then
|
|
75
|
-
unset agentrun_secret_AGENTRUN_SEAL_KEY
|
|
76
|
-
echo "agentrun-serve: no seal key in $keys/seal.key (none, or another user can read it or its directory), so the server keeps no tool key and no MCP server credential: make the file 0600 and its directory 0700 (chmod 700 $keys; chmod 600 $keys/seal.key), or remove it to have a new one made at the next start" >&2
|
|
77
|
-
fi
|
|
78
|
-
fi
|
|
51
|
+
# Every other process this launcher starts, it starts here, before it writes a secret.
|
|
79
52
|
dir=$(mktemp -d "${TMPDIR:-/tmp}/agentrun-serve.XXXXXX")
|
|
80
53
|
mkfifo -m 600 "$dir/secrets"
|
|
81
54
|
exec 3<>"$dir/secrets"
|