@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
package/dist/workspace/local.js
CHANGED
|
@@ -6,8 +6,18 @@
|
|
|
6
6
|
// a folder swapped for a link after the walk is never followed: the read, write, rename, unlink, readdir, mkdir and
|
|
7
7
|
// exec's working directory all go through the handle. The last part is opened with O_NOFOLLOW, or acted on by a call
|
|
8
8
|
// that does not follow it (rename, unlink, rmdir), after an lstat refuses a link there. A recursive remove walks the
|
|
9
|
-
// tree by handles too, and removes a link it meets, never what it points at.
|
|
10
|
-
//
|
|
9
|
+
// tree by handles too, and removes a link it meets, never what it points at.
|
|
10
|
+
//
|
|
11
|
+
// Elsewhere (macOS: Docker Desktop binds the run's folder, so a box process can swap a folder in it for a link) there
|
|
12
|
+
// is no /proc/self/fd, and node has no openat, so later calls resolve the path again. There every open (each folder the
|
|
13
|
+
// walk holds, and each file a read, write, append or grep opens) refuses a link anywhere below the root, not only at
|
|
14
|
+
// the end (beneath.ts: macOS's O_NOFOLLOW_ANY): a folder swapped for a link before or during the open is ELOOP, so
|
|
15
|
+
// ESCAPE, and what the handle holds was reached through real folders of the root's at the open itself. Nothing is
|
|
16
|
+
// resolved again after it, so a swap after the open, or one that comes and goes, changes nothing a read returns. A
|
|
17
|
+
// call that acts on a name instead (unlink, rmdir, rename, readdir, lstat, mkdir, exec's cwd) checks, just before,
|
|
18
|
+
// that its folder's path opens the same way to the folder held: a link swapped in by then is ESCAPE. What remains is
|
|
19
|
+
// the gap between that check and the call itself, which only an unlinkat or a fchdir closes. The path-resolving branch
|
|
20
|
+
// is chosen by `procFd`, so a test runs it on Linux too.
|
|
11
21
|
//
|
|
12
22
|
// Durability. write is a temporary file in the same folder (O_EXCL), its bytes, fsync, rename over the name, then fsync
|
|
13
23
|
// of the folder. append is O_APPEND, its bytes, fdatasync, and the folder's fsync when it made the file. mkdir fsyncs
|
|
@@ -28,6 +38,7 @@ import { access, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir
|
|
|
28
38
|
import { join } from "node:path";
|
|
29
39
|
import { Worker } from "node:worker_threads";
|
|
30
40
|
import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
|
|
41
|
+
import { openBeneath } from "./beneath.js";
|
|
31
42
|
import { relativeSegments } from "./paths.js";
|
|
32
43
|
import { abortError, EXEC_OUTPUT_MAX, GREP_FILE_MAX, GREP_LINE_MAX, GREP_MAX, GREP_TIME_MS, READ_MAX, WorkspaceError, } from "./workspace.js";
|
|
33
44
|
const { O_APPEND, O_CREAT, O_DIRECTORY, O_EXCL, O_NOFOLLOW, O_NONBLOCK, O_RDONLY, O_RDWR, O_WRONLY } = constants;
|
|
@@ -72,64 +83,151 @@ const bytesOf = (data) => {
|
|
|
72
83
|
throw new WorkspaceError("REFUSED", "data is bytes (a Uint8Array) or a string");
|
|
73
84
|
};
|
|
74
85
|
const byName = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
86
|
+
/** A link swapped in on the way to `path` since it was walked: ESCAPE. */
|
|
87
|
+
const swapped = (path) => new WorkspaceError("ESCAPE", `${show(path)} runs through a symbolic link swapped in on the way, and a workspace follows none`, { path });
|
|
75
88
|
/** A folder held open. On Linux a name in it resolves through /proc/self/fd/<fd>, inside the folder the handle holds,
|
|
76
|
-
* never through the folder's path again; elsewhere through its path
|
|
89
|
+
* never through the folder's path again; elsewhere through its path: opened through no link (open), and each other
|
|
90
|
+
* act checked first (confirm). */
|
|
77
91
|
class Held {
|
|
78
92
|
handle;
|
|
79
93
|
abs;
|
|
80
|
-
|
|
94
|
+
reach;
|
|
95
|
+
constructor(handle, abs, reach) {
|
|
81
96
|
this.handle = handle;
|
|
82
97
|
this.abs = abs;
|
|
98
|
+
this.reach = reach;
|
|
99
|
+
}
|
|
100
|
+
/** The folder's path below the root ("" for the root). */
|
|
101
|
+
get below() {
|
|
102
|
+
return this.abs === this.reach.root ? "" : this.abs.slice(this.reach.root.length + 1);
|
|
83
103
|
}
|
|
84
104
|
/** The folder itself, as a path a call (or exec's cwd) can take. */
|
|
85
105
|
get self() {
|
|
86
|
-
return
|
|
106
|
+
return this.reach.procFd ? `/proc/self/fd/${this.handle.fd}` : this.abs;
|
|
87
107
|
}
|
|
88
108
|
/** Entry `name` of the folder. */
|
|
89
109
|
at(name) {
|
|
90
|
-
return
|
|
110
|
+
return this.reach.procFd ? `/proc/self/fd/${this.handle.fd}/${name}` : join(this.abs, name);
|
|
111
|
+
}
|
|
112
|
+
/** Entry `name` opened with `flags`. Off /proc/self/fd through no link anywhere below the root (beneath.ts): a link
|
|
113
|
+
* on the way, a folder swapped for one, fails ELOOP, so what opens is under the root. */
|
|
114
|
+
open(name, flags, mode) {
|
|
115
|
+
if (this.reach.procFd)
|
|
116
|
+
return open(this.at(name), flags, mode);
|
|
117
|
+
return openBeneath(this.reach.root, this.below === "" ? name : `${this.below}/${name}`, flags, mode);
|
|
118
|
+
}
|
|
119
|
+
/** Off /proc/self/fd, that this folder's path still opens, through no link, to the folder held (dev and inode), else
|
|
120
|
+
* ESCAPE (NOT_FOUND when it is gone): run just before each call that resolves a name in it again. On Linux there is
|
|
121
|
+
* nothing to check. */
|
|
122
|
+
async confirm(path) {
|
|
123
|
+
if (this.reach.procFd)
|
|
124
|
+
return;
|
|
125
|
+
let there;
|
|
126
|
+
try {
|
|
127
|
+
there = await openBeneath(this.reach.root, this.below, DIR_FLAGS);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (errno(error) === "ELOOP")
|
|
131
|
+
throw swapped(path);
|
|
132
|
+
throw failed(error, path);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const [held, now] = await Promise.all([this.handle.stat(), there.stat()]);
|
|
136
|
+
if (now.dev !== held.dev || now.ino !== held.ino)
|
|
137
|
+
throw swapped(path);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
await there.close();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Makes entry `name`, the file `made` just made by `open`, durable: syncs the folder it was made in. On Linux that is
|
|
144
|
+
* the folder held. Elsewhere `open` went by the folder's path, which may name another folder under the root by now
|
|
145
|
+
* (one put in its place), so the folder the path opens now, through no link, is synced, once its `name` is that very
|
|
146
|
+
* file (dev and inode); else ESCAPE, as for any swap. */
|
|
147
|
+
async syncMade(name, made, path) {
|
|
148
|
+
if (this.reach.procFd)
|
|
149
|
+
return this.handle.sync();
|
|
150
|
+
let parent;
|
|
151
|
+
let entry;
|
|
152
|
+
try {
|
|
153
|
+
parent = await openBeneath(this.reach.root, this.below, DIR_FLAGS);
|
|
154
|
+
entry = await openBeneath(this.reach.root, this.below === "" ? name : `${this.below}/${name}`, O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
155
|
+
const now = await entry.stat();
|
|
156
|
+
if (now.dev !== made.dev || now.ino !== made.ino)
|
|
157
|
+
throw swapped(path);
|
|
158
|
+
await parent.sync();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
throw errno(error) === "ELOOP" ? swapped(path) : error;
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
await entry?.close();
|
|
165
|
+
await parent?.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** `fn`, its folder confirmed before and after: what it read was read in the folder held. */
|
|
169
|
+
async confirmed(path, fn) {
|
|
170
|
+
await this.confirm(path);
|
|
171
|
+
const result = await fn();
|
|
172
|
+
await this.confirm(path);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
/** Folder `name` of this one, just opened as `handle` (by `open`), held. The caller still owns the handle (it closes
|
|
176
|
+
* it, whether this resolves or not). */
|
|
177
|
+
async hold(handle, name) {
|
|
178
|
+
const next = new Held(handle, join(this.abs, name), this.reach);
|
|
179
|
+
await this.reach.onHeld?.(next.abs);
|
|
180
|
+
return next;
|
|
91
181
|
}
|
|
92
182
|
}
|
|
93
|
-
/** Everything in held folder `dir` removed, folders by handle: a link is removed, never followed.
|
|
94
|
-
|
|
95
|
-
|
|
183
|
+
/** Everything in held folder `dir` removed, folders by handle: a link is removed, never followed. Off /proc/self/fd,
|
|
184
|
+
* each name is acted on only once its folder is confirmed (Held.confirm), and each folder is entered by Held.open. */
|
|
185
|
+
async function emptyTree(dir, path) {
|
|
186
|
+
for (const name of await dir.confirmed(path, () => readdir(dir.self))) {
|
|
187
|
+
await dir.confirm(path);
|
|
96
188
|
const stats = await lstatOrNot(dir.at(name));
|
|
97
189
|
if (stats === undefined)
|
|
98
190
|
continue;
|
|
99
191
|
if (!stats.isDirectory()) {
|
|
192
|
+
// Not a folder (a file, or a link: unlink removes the link itself, never what it points at).
|
|
193
|
+
await dir.confirm(path);
|
|
100
194
|
await unlink(dir.at(name));
|
|
101
195
|
continue;
|
|
102
196
|
}
|
|
103
197
|
let handle;
|
|
104
198
|
try {
|
|
105
|
-
handle = await
|
|
199
|
+
handle = await dir.open(name, DIR_FLAGS);
|
|
106
200
|
}
|
|
107
201
|
catch (error) {
|
|
108
202
|
if (errno(error) !== "ENOTDIR" && errno(error) !== "ELOOP")
|
|
109
203
|
throw error;
|
|
204
|
+
await dir.confirm(path);
|
|
110
205
|
await unlink(dir.at(name));
|
|
111
206
|
continue;
|
|
112
207
|
}
|
|
113
208
|
try {
|
|
114
|
-
await emptyTree(
|
|
209
|
+
await emptyTree(await dir.hold(handle, name), path);
|
|
115
210
|
}
|
|
116
211
|
finally {
|
|
117
212
|
await handle.close();
|
|
118
213
|
}
|
|
214
|
+
await dir.confirm(path);
|
|
119
215
|
await rmdir(dir.at(name));
|
|
120
216
|
}
|
|
121
217
|
}
|
|
122
218
|
class LocalWorkspace {
|
|
123
219
|
#root;
|
|
124
|
-
#
|
|
125
|
-
|
|
220
|
+
#options;
|
|
221
|
+
#reach;
|
|
222
|
+
constructor(root, options) {
|
|
126
223
|
this.#root = root;
|
|
224
|
+
this.#options = options;
|
|
127
225
|
}
|
|
128
226
|
/** The root, its links resolved once (the root itself is trusted; nothing below it is), held open. */
|
|
129
227
|
async #openRoot() {
|
|
130
228
|
try {
|
|
131
|
-
this.#
|
|
132
|
-
return new Held(await open(this.#
|
|
229
|
+
this.#reach ??= { root: await realpath(this.#root), procFd: this.#options.procFd ?? LINUX, ...(this.#options.onHeld ? { onHeld: this.#options.onHeld } : {}) };
|
|
230
|
+
return new Held(await open(this.#reach.root, DIR_FLAGS), this.#reach.root, this.#reach);
|
|
133
231
|
}
|
|
134
232
|
catch (error) {
|
|
135
233
|
throw new WorkspaceError("UNAVAILABLE", `the workspace's folder ${this.#root} is not there`, { cause: error });
|
|
@@ -157,13 +255,14 @@ class LocalWorkspace {
|
|
|
157
255
|
let handle;
|
|
158
256
|
for (let made = false; handle === undefined;) {
|
|
159
257
|
try {
|
|
160
|
-
handle = await
|
|
258
|
+
handle = await dir.open(name, DIR_FLAGS);
|
|
161
259
|
}
|
|
162
260
|
catch (error) {
|
|
163
261
|
const code = errno(error);
|
|
164
262
|
if (code === "ENOENT" && options.make && !made) {
|
|
165
263
|
made = true;
|
|
166
264
|
try {
|
|
265
|
+
await dir.confirm(path);
|
|
167
266
|
await makeDir(dir.at(name), 0o777);
|
|
168
267
|
await dir.handle.sync();
|
|
169
268
|
}
|
|
@@ -183,7 +282,14 @@ class LocalWorkspace {
|
|
|
183
282
|
throw new WorkspaceError(options.make ? "EXISTS" : i === count - 1 ? options.notDir ?? "NOT_FOUND" : "NOT_FOUND", `${show(part)} is not a directory`, { path });
|
|
184
283
|
}
|
|
185
284
|
}
|
|
186
|
-
|
|
285
|
+
let next;
|
|
286
|
+
try {
|
|
287
|
+
next = await dir.hold(handle, name);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
await handle.close().catch(() => undefined);
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
187
293
|
await dir.handle.close();
|
|
188
294
|
dir = next;
|
|
189
295
|
}
|
|
@@ -205,7 +311,7 @@ class LocalWorkspace {
|
|
|
205
311
|
return this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
206
312
|
let handle;
|
|
207
313
|
try {
|
|
208
|
-
handle = await
|
|
314
|
+
handle = await dir.open(segments.at(-1), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
209
315
|
}
|
|
210
316
|
catch (error) {
|
|
211
317
|
throw failed(error, path);
|
|
@@ -241,19 +347,20 @@ class LocalWorkspace {
|
|
|
241
347
|
const name = segments.at(-1);
|
|
242
348
|
await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
243
349
|
try {
|
|
244
|
-
const existing = await lstatOrNot(dir.at(name));
|
|
350
|
+
const existing = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
|
|
245
351
|
if (existing?.isSymbolicLink())
|
|
246
352
|
throw escape(path, path);
|
|
247
353
|
if (existing !== undefined && !existing.isFile())
|
|
248
354
|
throw new WorkspaceError("REFUSED", `${show(path)} is ${existing.isDirectory() ? "a directory" : "not a file"}`, { path });
|
|
249
355
|
const temp = `.workspace-${randomBytes(8).toString("hex")}.tmp`;
|
|
250
|
-
const handle = await
|
|
356
|
+
const handle = await dir.open(temp, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
251
357
|
try {
|
|
252
358
|
if (existing !== undefined)
|
|
253
359
|
await handle.chmod(existing.mode & 0o777);
|
|
254
360
|
await handle.writeFile(bytes);
|
|
255
361
|
await handle.sync();
|
|
256
362
|
await handle.close();
|
|
363
|
+
await dir.confirm(path);
|
|
257
364
|
await rename(dir.at(temp), dir.at(name));
|
|
258
365
|
}
|
|
259
366
|
catch (error) {
|
|
@@ -277,23 +384,25 @@ class LocalWorkspace {
|
|
|
277
384
|
let made = false;
|
|
278
385
|
let handle;
|
|
279
386
|
try {
|
|
280
|
-
handle = await
|
|
387
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
|
|
281
388
|
}
|
|
282
389
|
catch (error) {
|
|
283
390
|
if (errno(error) !== "ENOENT")
|
|
284
391
|
throw error;
|
|
285
392
|
try {
|
|
286
|
-
handle = await
|
|
393
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
287
394
|
made = true;
|
|
288
395
|
}
|
|
289
396
|
catch (again) {
|
|
290
397
|
if (errno(again) !== "EEXIST")
|
|
291
398
|
throw again;
|
|
292
|
-
handle = await
|
|
399
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
|
|
293
400
|
}
|
|
294
401
|
}
|
|
402
|
+
let stats;
|
|
295
403
|
try {
|
|
296
|
-
|
|
404
|
+
stats = await handle.stat();
|
|
405
|
+
if (!stats.isFile())
|
|
297
406
|
throw new WorkspaceError("REFUSED", `${show(path)} is not a file`, { path });
|
|
298
407
|
await handle.writeFile(bytes);
|
|
299
408
|
await handle.datasync();
|
|
@@ -302,7 +411,7 @@ class LocalWorkspace {
|
|
|
302
411
|
await handle.close();
|
|
303
412
|
}
|
|
304
413
|
if (made)
|
|
305
|
-
await dir.
|
|
414
|
+
await dir.syncMade(target, stats, path);
|
|
306
415
|
}
|
|
307
416
|
catch (error) {
|
|
308
417
|
throw failed(error, path);
|
|
@@ -321,7 +430,7 @@ class LocalWorkspace {
|
|
|
321
430
|
try {
|
|
322
431
|
return await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
323
432
|
try {
|
|
324
|
-
const stats = await lstatOrNot(dir.at(segments.at(-1)));
|
|
433
|
+
const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(segments.at(-1))));
|
|
325
434
|
return stats === undefined ? undefined : of(stats);
|
|
326
435
|
}
|
|
327
436
|
catch (error) {
|
|
@@ -340,7 +449,8 @@ class LocalWorkspace {
|
|
|
340
449
|
const segments = relativeSegments(dir);
|
|
341
450
|
return this.#in(dir, segments, segments.length, async (held) => {
|
|
342
451
|
try {
|
|
343
|
-
|
|
452
|
+
// Off /proc/self/fd the folder is confirmed before and after: a listing of a folder swapped in is ESCAPE.
|
|
453
|
+
const entries = await held.confirmed(dir, async () => Promise.all((await readdir(held.self)).map(async (name) => {
|
|
344
454
|
const stats = await lstatOrNot(held.at(name));
|
|
345
455
|
if (stats?.isDirectory())
|
|
346
456
|
return { name, kind: "dir", size: 0, mtimeMs: stats.mtimeMs };
|
|
@@ -349,7 +459,7 @@ class LocalWorkspace {
|
|
|
349
459
|
// Only a flag for the listing: the read itself is what refuses (REFUSED, permission denied).
|
|
350
460
|
const readable = await access(held.at(name), constants.R_OK).then(() => true, () => false);
|
|
351
461
|
return { name, kind: "file", size: stats.size, mtimeMs: stats.mtimeMs, ...(readable ? {} : { unreadable: true }) };
|
|
352
|
-
}));
|
|
462
|
+
})));
|
|
353
463
|
return entries.filter((entry) => entry !== undefined).sort((a, b) => byName(a.name, b.name));
|
|
354
464
|
}
|
|
355
465
|
catch (error) {
|
|
@@ -377,12 +487,16 @@ class LocalWorkspace {
|
|
|
377
487
|
const from = options.path ?? "";
|
|
378
488
|
const segments = relativeSegments(from);
|
|
379
489
|
const job = { pattern, glob: options.glob, limit: Math.min(max, GREP_MAX), fileMax: GREP_FILE_MAX, lineMax: GREP_LINE_MAX, probe: BINARY_PROBE };
|
|
380
|
-
|
|
490
|
+
// Off /proc/self/fd the worker opens each entry through no link below the root, as a read does (grep-worker.ts).
|
|
491
|
+
const search = async (dir, rel, only) => {
|
|
492
|
+
await dir.confirm(from);
|
|
493
|
+
return LocalWorkspace.#searchIn({ ...job, dir: dir.self, rel, procFd: dir.reach.procFd, root: dir.reach.root, ...(only === undefined ? {} : { only }) }, Math.min(timeMs, GREP_TIME_MS));
|
|
494
|
+
};
|
|
381
495
|
if (segments.length === 0)
|
|
382
496
|
return this.#in(from, segments, 0, (root) => search(root, ""));
|
|
383
497
|
return this.#in(from, segments, segments.length - 1, async (parent) => {
|
|
384
498
|
const name = segments.at(-1);
|
|
385
|
-
const stats = await lstatOrNot(parent.at(name)).catch((error) => { throw failed(error, from); });
|
|
499
|
+
const stats = await parent.confirmed(from, () => lstatOrNot(parent.at(name))).catch((error) => { throw failed(error, from); });
|
|
386
500
|
if (stats === undefined)
|
|
387
501
|
throw new WorkspaceError("NOT_FOUND", `${show(from)} is not there`, { path: from });
|
|
388
502
|
if (stats.isSymbolicLink())
|
|
@@ -391,9 +505,9 @@ class LocalWorkspace {
|
|
|
391
505
|
return search(parent, segments.join("/"), name);
|
|
392
506
|
if (!stats.isDirectory())
|
|
393
507
|
throw new WorkspaceError("REFUSED", `${show(from)} is neither a file nor a directory`, { path: from });
|
|
394
|
-
const handle = await
|
|
508
|
+
const handle = await parent.open(name, DIR_FLAGS).catch((error) => { throw failed(error, from); });
|
|
395
509
|
try {
|
|
396
|
-
return await search(
|
|
510
|
+
return await search(await parent.hold(handle, name), segments.join("/"));
|
|
397
511
|
}
|
|
398
512
|
finally {
|
|
399
513
|
await handle.close();
|
|
@@ -438,23 +552,26 @@ class LocalWorkspace {
|
|
|
438
552
|
try {
|
|
439
553
|
await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
440
554
|
try {
|
|
441
|
-
const stats = await lstatOrNot(dir.at(name));
|
|
555
|
+
const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
|
|
442
556
|
if (stats === undefined)
|
|
443
557
|
throw new WorkspaceError("NOT_FOUND", `${show(path)} is not there`, { path });
|
|
444
558
|
if (stats.isSymbolicLink())
|
|
445
559
|
throw escape(path, path);
|
|
446
|
-
if (!stats.isDirectory())
|
|
560
|
+
if (!stats.isDirectory()) {
|
|
561
|
+
await dir.confirm(path);
|
|
447
562
|
await unlink(dir.at(name));
|
|
563
|
+
}
|
|
448
564
|
else {
|
|
449
565
|
if (options.recursive) {
|
|
450
|
-
const handle = await
|
|
566
|
+
const handle = await dir.open(name, DIR_FLAGS);
|
|
451
567
|
try {
|
|
452
|
-
await emptyTree(
|
|
568
|
+
await emptyTree(await dir.hold(handle, name), path);
|
|
453
569
|
}
|
|
454
570
|
finally {
|
|
455
571
|
await handle.close();
|
|
456
572
|
}
|
|
457
573
|
}
|
|
574
|
+
await dir.confirm(path);
|
|
458
575
|
await rmdir(dir.at(name));
|
|
459
576
|
}
|
|
460
577
|
await dir.handle.sync();
|
|
@@ -489,8 +606,9 @@ class LocalWorkspace {
|
|
|
489
606
|
const { signal } = options;
|
|
490
607
|
if (signal?.aborted)
|
|
491
608
|
throw abortError(signal);
|
|
492
|
-
// The child starts in the held folder itself (/proc/self/fd/<fd> on Linux), held until the child is done.
|
|
493
|
-
|
|
609
|
+
// The child starts in the held folder itself (/proc/self/fd/<fd> on Linux), held until the child is done. Off
|
|
610
|
+
// /proc/self/fd its path is confirmed just before the spawn.
|
|
611
|
+
return this.#in(cwd, segments, segments.length, (dir) => dir.confirm(cwd).then(() => new Promise((resolve, reject) => {
|
|
494
612
|
if (signal?.aborted)
|
|
495
613
|
return reject(abortError(signal));
|
|
496
614
|
const child = spawn(argv[0], argv.slice(1), {
|
|
@@ -574,7 +692,7 @@ class LocalWorkspace {
|
|
|
574
692
|
child.stdin.on("error", () => undefined);
|
|
575
693
|
child.stdin.end(Buffer.from(options.stdin.buffer, options.stdin.byteOffset, options.stdin.byteLength));
|
|
576
694
|
}
|
|
577
|
-
}), { notDir: "REFUSED" });
|
|
695
|
+
})), { notDir: "REFUSED" });
|
|
578
696
|
}
|
|
579
697
|
/** No computer: every background call is refused in words. */
|
|
580
698
|
process = noProcesses;
|
|
@@ -596,11 +714,10 @@ class LocalWorkspace {
|
|
|
596
714
|
async #syncUp(path, only) {
|
|
597
715
|
const segments = relativeSegments(path);
|
|
598
716
|
const entry = await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
599
|
-
const at = dir.at(segments.at(-1));
|
|
600
717
|
for (const flags of [O_RDONLY, O_WRONLY]) {
|
|
601
718
|
let handle;
|
|
602
719
|
try {
|
|
603
|
-
handle = await open(at, flags | O_NOFOLLOW | O_NONBLOCK);
|
|
720
|
+
handle = await dir.open(segments.at(-1), flags | O_NOFOLLOW | O_NONBLOCK);
|
|
604
721
|
}
|
|
605
722
|
catch (error) {
|
|
606
723
|
if (errno(error) === "ENOENT" || errno(error) === "ELOOP")
|
|
@@ -625,8 +742,9 @@ class LocalWorkspace {
|
|
|
625
742
|
return entry;
|
|
626
743
|
}
|
|
627
744
|
}
|
|
628
|
-
/** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
|
|
629
|
-
|
|
745
|
+
/** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
|
|
746
|
+
* `options` are a test's: the path-resolving branch forced, and a hook where a swap would land. */
|
|
747
|
+
export const localWorkspace = (root, options = {}) => new LocalWorkspace(root, options);
|
|
630
748
|
/** `work` as a Workspace: a folder of this machine, by its path, becomes its LocalWorkspace. For the callers that still
|
|
631
749
|
* hand a run's folder by its path (the run's start and its process), until they hand the run's Workspace. */
|
|
632
750
|
export const workspaceAt = (work) => (typeof work === "string" ? localWorkspace(work) : work);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
1
|
+
import type { ShellPlace } from "@parcha/agentrun-kernel/kernel";
|
|
2
|
+
import { type ComputerClient, type ComputerSettingKind, type GpuSpec, type Group, type KindCapabilities, type MountReadBack, type MountSpec, type ProviderEntry, type Result } from "@parcha/agentrun-computer";
|
|
3
|
+
import { type DockerDaemon } from "../docker-daemon.js";
|
|
3
4
|
import type { MountCheck } from "./attach.js";
|
|
4
5
|
import type { RunComputer } from "./run-tools.js";
|
|
5
6
|
import type { Workspace } from "./workspace.js";
|
|
6
7
|
/** The setting kind (what an agent is given, not a computer's capabilities().kind), a machine's kind and groups, and one
|
|
7
8
|
* provider of the kind registry: the computer module's own types. Where a run's shell is: the kernel registry's. */
|
|
8
9
|
export type { ComputerSettingKind, KindCapabilities, ProviderEntry, ShellPlace };
|
|
9
|
-
/** An agent's computer setting. */
|
|
10
|
+
/** An agent's computer setting: a sandbox's may ask for GPUs. */
|
|
10
11
|
export type ComputerSetting = {
|
|
11
12
|
readonly kind: string;
|
|
12
13
|
readonly provider?: string | null;
|
|
14
|
+
readonly gpu?: GpuSpec;
|
|
13
15
|
};
|
|
14
16
|
/** The computer module's kind registry (src/kinds.ts), by its own names: the setting kinds, why a machine does not serve
|
|
15
17
|
* one (servingRefusals, whose words a refusal here carries), and the providers. */
|
|
@@ -19,25 +21,50 @@ export type KindRegistry = {
|
|
|
19
21
|
readonly PROVIDERS: readonly ProviderEntry[];
|
|
20
22
|
};
|
|
21
23
|
/** A computer a provider started for the run: its ref, its computerd client and what it offers (sandbox, desktop,
|
|
22
|
-
* phone), the read-back of its mount (when mounted), its
|
|
24
|
+
* phone), the read-back of its mount (when mounted), and its release. A browser is started by none: the claim gives
|
|
25
|
+
* the run's browser tool its provider (`browser`), which opens each session at the tool's first call, and the release
|
|
26
|
+
* lets go of any the tool left open. */
|
|
23
27
|
export type LaunchedComputer = {
|
|
24
28
|
readonly id: string;
|
|
25
29
|
readonly groups: readonly (Group | string)[];
|
|
26
30
|
readonly client?: ComputerClient;
|
|
27
31
|
readBack?(): Promise<Result<MountReadBack>>;
|
|
28
|
-
|
|
32
|
+
readonly browser?: ClaimBrowser;
|
|
29
33
|
release(): Promise<void>;
|
|
30
34
|
};
|
|
35
|
+
/** A browser computer's provider as the run's browser tool opens its sessions through it: each session one computer of
|
|
36
|
+
* the provider's, made under the run's labels and the tool's tag (so a create whose answer was lost is found again),
|
|
37
|
+
* its CDP URL read through the provider's connect at each attach (a secret: it goes only to the driver), and released
|
|
38
|
+
* when the tool lets it go. Errors carry the provider's words, and its code. So the session's time is the time the
|
|
39
|
+
* tool holds it, which is what the run's spend books. */
|
|
40
|
+
export type ClaimBrowser = {
|
|
41
|
+
/** The provider's id: the session's price and its name. */
|
|
42
|
+
readonly provider: string;
|
|
43
|
+
/** The longest a session lives, in seconds. */
|
|
44
|
+
readonly maxLifetimeS: number;
|
|
45
|
+
/** Makes a session for `tag`, to live at most `lifetimeS`: its computer's id. */
|
|
46
|
+
open(tag: string, lifetimeS: number, signal?: AbortSignal): Promise<string>;
|
|
47
|
+
/** The sessions made for `tag`, by id. */
|
|
48
|
+
find(tag: string, signal?: AbortSignal): Promise<string[]>;
|
|
49
|
+
/** The session's CDP URL now. */
|
|
50
|
+
url(id: string): Promise<string>;
|
|
51
|
+
/** Ends the session; one already gone is ended. */
|
|
52
|
+
close(id: string): Promise<void>;
|
|
53
|
+
};
|
|
31
54
|
/** The claim's side: the keys saved for a provider (Settings → Computers; values, never shown), and the launch of one
|
|
32
55
|
* computer of the kind, with the run's folder as its mount when it mounts it. A launch that fails throws its words. */
|
|
33
56
|
export type ClaimSide = {
|
|
34
57
|
keysOf(provider: string): Promise<Readonly<Record<string, string>>>;
|
|
35
58
|
/** Whether a provider that binds a folder of this machine (Docker) answers here now: the Mode 1 default asks it. */
|
|
36
59
|
answers(provider: string): Promise<boolean>;
|
|
60
|
+
/** Its daemon's answer (docker-daemon.ts), asked when a launch on such a provider fails: none answering is refused in
|
|
61
|
+
* the one wording a run's start and Settings → Computers say (noDockerWords). Absent: the launch's own words. */
|
|
62
|
+
daemon?(provider: string): Promise<DockerDaemon>;
|
|
37
63
|
launch(entry: ProviderEntry, spec: {
|
|
38
64
|
readonly kind: ComputerSettingKind;
|
|
39
65
|
readonly keys: Readonly<Record<string, string>>;
|
|
40
66
|
readonly mount?: MountSpec;
|
|
67
|
+
readonly gpu?: GpuSpec;
|
|
41
68
|
readonly signal?: AbortSignal;
|
|
42
69
|
}): Promise<LaunchedComputer>;
|
|
43
70
|
};
|
|
@@ -47,15 +74,28 @@ export type Port = "files" | "exec" | "processes" | "screen" | "input" | "phone"
|
|
|
47
74
|
/** A provider's keys as the claim reads them: each key its registry entry declares, by `keyOf` (the server's reader:
|
|
48
75
|
* key-meta.ts keyReader, the environment's value, else the saved one); a key with no value is left out. */
|
|
49
76
|
export declare const providerKeys: (registry: Pick<KindRegistry, "PROVIDERS">, keyOf: (name: string) => Promise<string | undefined>) => ClaimSide["keysOf"];
|
|
77
|
+
/** Whether a provider's computers run only on the vendor's own network: the network forms it declares (its module's
|
|
78
|
+
* NETWORK, its capabilities().network) are "open" alone, as a cloud phone's and a hosted browser's are. */
|
|
79
|
+
export declare const vendorNetworkOnly: (network: readonly string[] | undefined) => boolean;
|
|
80
|
+
/** Whether a provider's computers can't have no network: it declares its network forms and "none" isn't one (a cloud
|
|
81
|
+
* phone, a hosted browser, Local Chrome). */
|
|
82
|
+
export declare const needsNetwork: (network: readonly string[] | undefined) => boolean;
|
|
83
|
+
/** Why a computer that needs a network is refused where this server's AGENTRUN_BOX_ALLOW is none, in words that name the
|
|
84
|
+
* fix: the operator said no network at all, and the computer can't run without one. */
|
|
85
|
+
export declare const noNetworkRefusal: (label: string, kind: string) => string;
|
|
50
86
|
/** Whether an agent's computer `setting` can be had in `mode` now, by the answers the claim gives (resolveComputer: the
|
|
51
87
|
* kind, the provider and what it serves, the mode's mount, the provider's keys by `keyOf`): ok, or its refusal in words
|
|
52
88
|
* that name the fix. Nothing starts. A run's start asks it before the run is made (runnable.ts).
|
|
53
89
|
*
|
|
54
|
-
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
|
|
90
|
+
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's
|
|
91
|
+
* daemon check, docker-daemon.ts). Any computer on such a provider, a sandbox or a desktop in either mode, is refused
|
|
92
|
+
* here, at the start, where the claim would only fail to launch it: no daemon at all in the one wording Settings →
|
|
93
|
+
* Computers and the claim say (noDockerWords), another reason in its own words. Asked here, not in resolveComputer: the
|
|
94
|
+
* claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
|
|
95
|
+
*
|
|
96
|
+
* `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
|
|
97
|
+
* "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
|
|
98
|
+
export declare function computerReadiness(setting: ComputerSetting, mode: 1 | 2, registry: KindRegistry, keyOf: (name: string) => Promise<string | undefined>, answers?: (provider: string) => DockerDaemon | Promise<DockerDaemon>, boxAllow?: readonly string[] | "none"): Promise<{
|
|
59
99
|
readonly ok: true;
|
|
60
100
|
} | {
|
|
61
101
|
readonly refused: string;
|