@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.35
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 +368 -0
- package/README.md +341 -208
- package/dist/adapters.d.ts +3 -4
- package/dist/adapters.js +18 -15
- package/dist/agent-rows.d.ts +99 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +75 -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 +1 -1
- package/dist/api-only.js +2 -2
- package/dist/archil-settings.d.ts +11 -1
- package/dist/archil-settings.js +10 -0
- package/dist/bash-read-only.d.ts +35 -0
- package/dist/bash-read-only.js +778 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- 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 +95 -51
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/budget.d.ts +0 -5
- package/dist/budget.js +0 -5
- package/dist/cap.d.ts +14 -8
- package/dist/cap.js +19 -9
- package/dist/cli.js +71 -18
- 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.d.ts +20 -10
- package/dist/computer-keys.js +36 -54
- package/dist/computer-setting.d.ts +20 -3
- package/dist/computer-setting.js +58 -10
- package/dist/computers.d.ts +35 -2
- package/dist/computers.js +72 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-B7NKTU8E.css +1 -0
- package/dist/console/assets/index-CXZMgJE7.js +550 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- 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/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +1 -2
- package/dist/errors.js +9 -9
- package/dist/explain.js +3 -1
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +6 -2
- package/dist/github.js +5 -3
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +9 -16
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- 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/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 +14 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +8 -2
- package/dist/learn/check.js +85 -31
- package/dist/learn/folder.d.ts +11 -4
- package/dist/learn/folder.js +17 -19
- package/dist/learn/grade.d.ts +18 -1
- package/dist/learn/grade.js +108 -14
- package/dist/learn/index.d.ts +5 -5
- package/dist/learn/index.js +5 -5
- package/dist/learn/learning.sh +1 -14
- package/dist/learn/notes.d.ts +14 -3
- package/dist/learn/notes.js +16 -6
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +83 -6
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +159 -18
- package/dist/learn/skills.js +644 -64
- package/dist/learned-nodes.d.ts +14 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +41 -6
- package/dist/learned-workflow.js +153 -18
- package/dist/learning-routes.d.ts +49 -4
- package/dist/learning-routes.js +113 -31
- package/dist/learning-run.d.ts +16 -31
- package/dist/learning-run.js +31 -38
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +91 -97
- package/dist/learning.js +176 -320
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +17 -49
- package/dist/mcp-gateway.js +55 -136
- 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 +18 -18
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +9 -7
- package/dist/model.js +51 -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 +156 -58
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +26 -61
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/port-models.d.ts +10 -3
- package/dist/port-models.js +26 -6
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +80 -45
- 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 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +21 -2
- package/dist/run-launch.js +14 -5
- package/dist/run-learning-served.d.ts +21 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +5 -3
- package/dist/run-reads-over-store.js +25 -14
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +27 -6
- package/dist/run-view.d.ts +37 -22
- package/dist/run-view.js +85 -38
- package/dist/runnable.d.ts +21 -10
- package/dist/runnable.js +35 -12
- package/dist/runner/adapter-loop.d.ts +36 -5
- package/dist/runner/adapter-loop.js +663 -69
- package/dist/runner/adapter-run-spec.d.ts +42 -8
- package/dist/runner/adapter-run-spec.js +186 -52
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +40 -2
- package/dist/runner/adapters/pi.js +110 -27
- package/dist/runner/beside.d.ts +38 -3
- package/dist/runner/beside.js +54 -5
- package/dist/runner/claim-secrets.d.ts +16 -1
- package/dist/runner/claim-secrets.js +62 -14
- package/dist/runner/cli-run-spec.d.ts +5 -0
- package/dist/runner/cli-run-spec.js +159 -41
- 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.d.ts +1 -0
- package/dist/runner/conformance/harness.js +123 -13
- 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.d.ts +7 -2
- package/dist/runner/github-app.js +47 -16
- package/dist/runner/harness-loops.d.ts +15 -2
- package/dist/runner/harness-loops.js +38 -2
- package/dist/runner/journal-kinds.d.ts +60 -6
- package/dist/runner/journal-kinds.js +43 -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 +194 -20
- package/dist/runner/learning-loop.d.ts +7 -0
- package/dist/runner/learning-loop.js +36 -8
- package/dist/runner/learning-seed.d.ts +6 -0
- package/dist/runner/learning-seed.js +6 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.d.ts +61 -9
- package/dist/runner/main.js +144 -20
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +7 -3
- package/dist/runner/mcp-github.d.ts +11 -2
- package/dist/runner/mcp-github.js +55 -4
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +16 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +46 -1
- package/dist/runner/metrics.js +156 -1
- package/dist/runner/model-route.d.ts +16 -0
- package/dist/runner/model-route.js +134 -10
- 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 +146 -18
- package/dist/runner/spec-holds.d.ts +7 -2
- package/dist/runner/spec-holds.js +4 -3
- 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-host.d.ts +7 -2
- package/dist/runner/workflow-host.js +3 -1
- package/dist/runner/workflow-loop.d.ts +10 -1
- package/dist/runner/workflow-loop.js +14 -6
- package/dist/runner/workflow-spec.d.ts +21 -0
- package/dist/runner/workflow-spec.js +217 -93
- package/dist/runs-over-store.d.ts +14 -3
- package/dist/runs-over-store.js +100 -23
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +5 -45
- 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/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 +5 -85
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +37 -56
- package/dist/server.js +322 -134
- 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/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +12 -2
- package/dist/store/agent-body.js +22 -4
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +45 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +22 -2
- package/dist/store/postgres/connection.js +211 -41
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- 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 +14 -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 +41 -12
- package/dist/store/store.d.ts +35 -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 +9 -6
- package/dist/store-reads/journal.js +129 -18
- package/dist/store-reads/learning.d.ts +82 -8
- package/dist/store-reads/learning.js +184 -11
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +19 -1
- package/dist/store-view.js +95 -27
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +33 -14
- package/dist/templates.js +82 -46
- 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 +282 -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-budget.d.ts +18 -0
- package/dist/tool-budget.js +50 -0
- package/dist/tool-gate.d.ts +47 -218
- package/dist/tool-gate.js +87 -545
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +23 -52
- 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 +67 -25
- package/dist/tools.js +170 -119
- package/dist/trigger-adapter.d.ts +2 -2
- 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.d.ts +28 -5
- package/dist/uploads.js +83 -10
- package/dist/usage.d.ts +1 -49
- package/dist/usage.js +3 -84
- package/dist/validate.d.ts +4 -0
- package/dist/validate.js +33 -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/archil-claim.d.ts +2 -2
- package/dist/workspace/archil-claim.js +4 -3
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +16 -0
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +26 -9
- package/dist/workspace/computer-deps.js +144 -43
- package/dist/workspace/computer-for-claim.d.ts +17 -14
- package/dist/workspace/computer-for-claim.js +99 -26
- 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-ledger.d.ts +1 -8
- package/dist/workspace/computer-ledger.js +0 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +6 -5
- package/dist/workspace/index.js +4 -4
- package/dist/workspace/local.d.ts +14 -2
- package/dist/workspace/local.js +170 -43
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +55 -10
- package/dist/workspace/resolve-computer.js +66 -14
- package/dist/workspace/run-tools.d.ts +15 -31
- package/dist/workspace/run-tools.js +19 -30
- package/dist/workspace/workspace.d.ts +5 -0
- 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 +4 -110
- package/package.json +14 -14
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -5
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +11 -0
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- 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-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- 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/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- 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,155 @@ 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;
|
|
225
|
+
}
|
|
226
|
+
/** The folder `work` is over, by its path, when it is a LocalWorkspace; undefined for any other Workspace. */
|
|
227
|
+
static folderOf(work) {
|
|
228
|
+
return work instanceof LocalWorkspace ? work.#root : undefined;
|
|
127
229
|
}
|
|
128
230
|
/** The root, its links resolved once (the root itself is trusted; nothing below it is), held open. */
|
|
129
231
|
async #openRoot() {
|
|
130
232
|
try {
|
|
131
|
-
this.#
|
|
132
|
-
return new Held(await open(this.#
|
|
233
|
+
this.#reach ??= { root: await realpath(this.#root), procFd: this.#options.procFd ?? LINUX, ...(this.#options.onHeld ? { onHeld: this.#options.onHeld } : {}) };
|
|
234
|
+
return new Held(await open(this.#reach.root, DIR_FLAGS), this.#reach.root, this.#reach);
|
|
133
235
|
}
|
|
134
236
|
catch (error) {
|
|
135
237
|
throw new WorkspaceError("UNAVAILABLE", `the workspace's folder ${this.#root} is not there`, { cause: error });
|
|
@@ -157,13 +259,14 @@ class LocalWorkspace {
|
|
|
157
259
|
let handle;
|
|
158
260
|
for (let made = false; handle === undefined;) {
|
|
159
261
|
try {
|
|
160
|
-
handle = await
|
|
262
|
+
handle = await dir.open(name, DIR_FLAGS);
|
|
161
263
|
}
|
|
162
264
|
catch (error) {
|
|
163
265
|
const code = errno(error);
|
|
164
266
|
if (code === "ENOENT" && options.make && !made) {
|
|
165
267
|
made = true;
|
|
166
268
|
try {
|
|
269
|
+
await dir.confirm(path);
|
|
167
270
|
await makeDir(dir.at(name), 0o777);
|
|
168
271
|
await dir.handle.sync();
|
|
169
272
|
}
|
|
@@ -183,7 +286,14 @@ class LocalWorkspace {
|
|
|
183
286
|
throw new WorkspaceError(options.make ? "EXISTS" : i === count - 1 ? options.notDir ?? "NOT_FOUND" : "NOT_FOUND", `${show(part)} is not a directory`, { path });
|
|
184
287
|
}
|
|
185
288
|
}
|
|
186
|
-
|
|
289
|
+
let next;
|
|
290
|
+
try {
|
|
291
|
+
next = await dir.hold(handle, name);
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
await handle.close().catch(() => undefined);
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
187
297
|
await dir.handle.close();
|
|
188
298
|
dir = next;
|
|
189
299
|
}
|
|
@@ -205,7 +315,7 @@ class LocalWorkspace {
|
|
|
205
315
|
return this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
206
316
|
let handle;
|
|
207
317
|
try {
|
|
208
|
-
handle = await
|
|
318
|
+
handle = await dir.open(segments.at(-1), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
209
319
|
}
|
|
210
320
|
catch (error) {
|
|
211
321
|
throw failed(error, path);
|
|
@@ -241,19 +351,20 @@ class LocalWorkspace {
|
|
|
241
351
|
const name = segments.at(-1);
|
|
242
352
|
await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
243
353
|
try {
|
|
244
|
-
const existing = await lstatOrNot(dir.at(name));
|
|
354
|
+
const existing = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
|
|
245
355
|
if (existing?.isSymbolicLink())
|
|
246
356
|
throw escape(path, path);
|
|
247
357
|
if (existing !== undefined && !existing.isFile())
|
|
248
358
|
throw new WorkspaceError("REFUSED", `${show(path)} is ${existing.isDirectory() ? "a directory" : "not a file"}`, { path });
|
|
249
359
|
const temp = `.workspace-${randomBytes(8).toString("hex")}.tmp`;
|
|
250
|
-
const handle = await
|
|
360
|
+
const handle = await dir.open(temp, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
251
361
|
try {
|
|
252
362
|
if (existing !== undefined)
|
|
253
363
|
await handle.chmod(existing.mode & 0o777);
|
|
254
364
|
await handle.writeFile(bytes);
|
|
255
365
|
await handle.sync();
|
|
256
366
|
await handle.close();
|
|
367
|
+
await dir.confirm(path);
|
|
257
368
|
await rename(dir.at(temp), dir.at(name));
|
|
258
369
|
}
|
|
259
370
|
catch (error) {
|
|
@@ -277,23 +388,25 @@ class LocalWorkspace {
|
|
|
277
388
|
let made = false;
|
|
278
389
|
let handle;
|
|
279
390
|
try {
|
|
280
|
-
handle = await
|
|
391
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
|
|
281
392
|
}
|
|
282
393
|
catch (error) {
|
|
283
394
|
if (errno(error) !== "ENOENT")
|
|
284
395
|
throw error;
|
|
285
396
|
try {
|
|
286
|
-
handle = await
|
|
397
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
287
398
|
made = true;
|
|
288
399
|
}
|
|
289
400
|
catch (again) {
|
|
290
401
|
if (errno(again) !== "EEXIST")
|
|
291
402
|
throw again;
|
|
292
|
-
handle = await
|
|
403
|
+
handle = await dir.open(target, O_RDWR | O_APPEND | O_NOFOLLOW | O_NONBLOCK);
|
|
293
404
|
}
|
|
294
405
|
}
|
|
406
|
+
let stats;
|
|
295
407
|
try {
|
|
296
|
-
|
|
408
|
+
stats = await handle.stat();
|
|
409
|
+
if (!stats.isFile())
|
|
297
410
|
throw new WorkspaceError("REFUSED", `${show(path)} is not a file`, { path });
|
|
298
411
|
await handle.writeFile(bytes);
|
|
299
412
|
await handle.datasync();
|
|
@@ -302,7 +415,7 @@ class LocalWorkspace {
|
|
|
302
415
|
await handle.close();
|
|
303
416
|
}
|
|
304
417
|
if (made)
|
|
305
|
-
await dir.
|
|
418
|
+
await dir.syncMade(target, stats, path);
|
|
306
419
|
}
|
|
307
420
|
catch (error) {
|
|
308
421
|
throw failed(error, path);
|
|
@@ -321,7 +434,7 @@ class LocalWorkspace {
|
|
|
321
434
|
try {
|
|
322
435
|
return await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
323
436
|
try {
|
|
324
|
-
const stats = await lstatOrNot(dir.at(segments.at(-1)));
|
|
437
|
+
const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(segments.at(-1))));
|
|
325
438
|
return stats === undefined ? undefined : of(stats);
|
|
326
439
|
}
|
|
327
440
|
catch (error) {
|
|
@@ -340,7 +453,8 @@ class LocalWorkspace {
|
|
|
340
453
|
const segments = relativeSegments(dir);
|
|
341
454
|
return this.#in(dir, segments, segments.length, async (held) => {
|
|
342
455
|
try {
|
|
343
|
-
|
|
456
|
+
// Off /proc/self/fd the folder is confirmed before and after: a listing of a folder swapped in is ESCAPE.
|
|
457
|
+
const entries = await held.confirmed(dir, async () => Promise.all((await readdir(held.self)).map(async (name) => {
|
|
344
458
|
const stats = await lstatOrNot(held.at(name));
|
|
345
459
|
if (stats?.isDirectory())
|
|
346
460
|
return { name, kind: "dir", size: 0, mtimeMs: stats.mtimeMs };
|
|
@@ -349,7 +463,7 @@ class LocalWorkspace {
|
|
|
349
463
|
// Only a flag for the listing: the read itself is what refuses (REFUSED, permission denied).
|
|
350
464
|
const readable = await access(held.at(name), constants.R_OK).then(() => true, () => false);
|
|
351
465
|
return { name, kind: "file", size: stats.size, mtimeMs: stats.mtimeMs, ...(readable ? {} : { unreadable: true }) };
|
|
352
|
-
}));
|
|
466
|
+
})));
|
|
353
467
|
return entries.filter((entry) => entry !== undefined).sort((a, b) => byName(a.name, b.name));
|
|
354
468
|
}
|
|
355
469
|
catch (error) {
|
|
@@ -377,12 +491,16 @@ class LocalWorkspace {
|
|
|
377
491
|
const from = options.path ?? "";
|
|
378
492
|
const segments = relativeSegments(from);
|
|
379
493
|
const job = { pattern, glob: options.glob, limit: Math.min(max, GREP_MAX), fileMax: GREP_FILE_MAX, lineMax: GREP_LINE_MAX, probe: BINARY_PROBE };
|
|
380
|
-
|
|
494
|
+
// Off /proc/self/fd the worker opens each entry through no link below the root, as a read does (grep-worker.ts).
|
|
495
|
+
const search = async (dir, rel, only) => {
|
|
496
|
+
await dir.confirm(from);
|
|
497
|
+
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));
|
|
498
|
+
};
|
|
381
499
|
if (segments.length === 0)
|
|
382
500
|
return this.#in(from, segments, 0, (root) => search(root, ""));
|
|
383
501
|
return this.#in(from, segments, segments.length - 1, async (parent) => {
|
|
384
502
|
const name = segments.at(-1);
|
|
385
|
-
const stats = await lstatOrNot(parent.at(name)).catch((error) => { throw failed(error, from); });
|
|
503
|
+
const stats = await parent.confirmed(from, () => lstatOrNot(parent.at(name))).catch((error) => { throw failed(error, from); });
|
|
386
504
|
if (stats === undefined)
|
|
387
505
|
throw new WorkspaceError("NOT_FOUND", `${show(from)} is not there`, { path: from });
|
|
388
506
|
if (stats.isSymbolicLink())
|
|
@@ -391,9 +509,9 @@ class LocalWorkspace {
|
|
|
391
509
|
return search(parent, segments.join("/"), name);
|
|
392
510
|
if (!stats.isDirectory())
|
|
393
511
|
throw new WorkspaceError("REFUSED", `${show(from)} is neither a file nor a directory`, { path: from });
|
|
394
|
-
const handle = await
|
|
512
|
+
const handle = await parent.open(name, DIR_FLAGS).catch((error) => { throw failed(error, from); });
|
|
395
513
|
try {
|
|
396
|
-
return await search(
|
|
514
|
+
return await search(await parent.hold(handle, name), segments.join("/"));
|
|
397
515
|
}
|
|
398
516
|
finally {
|
|
399
517
|
await handle.close();
|
|
@@ -438,23 +556,26 @@ class LocalWorkspace {
|
|
|
438
556
|
try {
|
|
439
557
|
await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
440
558
|
try {
|
|
441
|
-
const stats = await lstatOrNot(dir.at(name));
|
|
559
|
+
const stats = await dir.confirmed(path, () => lstatOrNot(dir.at(name)));
|
|
442
560
|
if (stats === undefined)
|
|
443
561
|
throw new WorkspaceError("NOT_FOUND", `${show(path)} is not there`, { path });
|
|
444
562
|
if (stats.isSymbolicLink())
|
|
445
563
|
throw escape(path, path);
|
|
446
|
-
if (!stats.isDirectory())
|
|
564
|
+
if (!stats.isDirectory()) {
|
|
565
|
+
await dir.confirm(path);
|
|
447
566
|
await unlink(dir.at(name));
|
|
567
|
+
}
|
|
448
568
|
else {
|
|
449
569
|
if (options.recursive) {
|
|
450
|
-
const handle = await
|
|
570
|
+
const handle = await dir.open(name, DIR_FLAGS);
|
|
451
571
|
try {
|
|
452
|
-
await emptyTree(
|
|
572
|
+
await emptyTree(await dir.hold(handle, name), path);
|
|
453
573
|
}
|
|
454
574
|
finally {
|
|
455
575
|
await handle.close();
|
|
456
576
|
}
|
|
457
577
|
}
|
|
578
|
+
await dir.confirm(path);
|
|
458
579
|
await rmdir(dir.at(name));
|
|
459
580
|
}
|
|
460
581
|
await dir.handle.sync();
|
|
@@ -484,13 +605,16 @@ class LocalWorkspace {
|
|
|
484
605
|
const cap = options.maxOutput ?? EXEC_OUTPUT_MAX;
|
|
485
606
|
if (!Number.isSafeInteger(cap) || cap < 0)
|
|
486
607
|
throw new WorkspaceError("REFUSED", "exec's maxOutput is a whole number, 0 or more");
|
|
608
|
+
if (options.network !== undefined)
|
|
609
|
+
throw new WorkspaceError("REFUSED", "a command here runs on this machine, which cannot deny its network: nothing ran");
|
|
487
610
|
const cwd = options.cwd ?? "";
|
|
488
611
|
const segments = relativeSegments(cwd);
|
|
489
612
|
const { signal } = options;
|
|
490
613
|
if (signal?.aborted)
|
|
491
614
|
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
|
-
|
|
615
|
+
// The child starts in the held folder itself (/proc/self/fd/<fd> on Linux), held until the child is done. Off
|
|
616
|
+
// /proc/self/fd its path is confirmed just before the spawn.
|
|
617
|
+
return this.#in(cwd, segments, segments.length, (dir) => dir.confirm(cwd).then(() => new Promise((resolve, reject) => {
|
|
494
618
|
if (signal?.aborted)
|
|
495
619
|
return reject(abortError(signal));
|
|
496
620
|
const child = spawn(argv[0], argv.slice(1), {
|
|
@@ -574,7 +698,7 @@ class LocalWorkspace {
|
|
|
574
698
|
child.stdin.on("error", () => undefined);
|
|
575
699
|
child.stdin.end(Buffer.from(options.stdin.buffer, options.stdin.byteOffset, options.stdin.byteLength));
|
|
576
700
|
}
|
|
577
|
-
}), { notDir: "REFUSED" });
|
|
701
|
+
})), { notDir: "REFUSED" });
|
|
578
702
|
}
|
|
579
703
|
/** No computer: every background call is refused in words. */
|
|
580
704
|
process = noProcesses;
|
|
@@ -596,11 +720,10 @@ class LocalWorkspace {
|
|
|
596
720
|
async #syncUp(path, only) {
|
|
597
721
|
const segments = relativeSegments(path);
|
|
598
722
|
const entry = await this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
599
|
-
const at = dir.at(segments.at(-1));
|
|
600
723
|
for (const flags of [O_RDONLY, O_WRONLY]) {
|
|
601
724
|
let handle;
|
|
602
725
|
try {
|
|
603
|
-
handle = await open(at, flags | O_NOFOLLOW | O_NONBLOCK);
|
|
726
|
+
handle = await dir.open(segments.at(-1), flags | O_NOFOLLOW | O_NONBLOCK);
|
|
604
727
|
}
|
|
605
728
|
catch (error) {
|
|
606
729
|
if (errno(error) === "ENOENT" || errno(error) === "ELOOP")
|
|
@@ -625,8 +748,12 @@ class LocalWorkspace {
|
|
|
625
748
|
return entry;
|
|
626
749
|
}
|
|
627
750
|
}
|
|
628
|
-
/** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
|
|
629
|
-
|
|
751
|
+
/** A Workspace on folder `root` of this machine. The folder must be there when it is first used (else UNAVAILABLE).
|
|
752
|
+
* `options` are a test's: the path-resolving branch forced, and a hook where a swap would land. */
|
|
753
|
+
export const localWorkspace = (root, options = {}) => new LocalWorkspace(root, options);
|
|
754
|
+
/** The folder of this machine that `work` is, by its path: a LocalWorkspace's root; undefined for any other Workspace (a
|
|
755
|
+
* Mode 2 run's folder on its disk, one attached to a computer), whose files no local path reaches. */
|
|
756
|
+
export const localFolderOf = (work) => LocalWorkspace.folderOf(work);
|
|
630
757
|
/** `work` as a Workspace: a folder of this machine, by its path, becomes its LocalWorkspace. For the callers that still
|
|
631
758
|
* hand a run's folder by its path (the run's start and its process), until they hand the run's Workspace. */
|
|
632
759
|
export const workspaceAt = (work) => (typeof work === "string" ? localWorkspace(work) : work);
|
package/dist/workspace/paths.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
// for it
|
|
9
9
|
// and on this machine alone:
|
|
10
10
|
// <data>/scratch/<agent>/<run> a run's scratch folder (scratchFolder): never on the disk above, so in
|
|
11
|
-
// no Workspace: a harness's
|
|
12
|
-
// at
|
|
11
|
+
// no Workspace: a harness's working directory, and its private files
|
|
12
|
+
// in harness/<claim's epoch>, swept at that claim's end
|
|
13
|
+
// (runner/cli-run-spec.ts)
|
|
13
14
|
// <agent> is the id in lower case, a dash, and 16 hex digits of the id's SHA-256, so ids that differ only in case never
|
|
14
15
|
// share a folder on a disk that folds case.
|
|
15
16
|
//
|
|
@@ -15,8 +15,12 @@ export type PiEnvOptions = {
|
|
|
15
15
|
readonly aliases?: readonly string[];
|
|
16
16
|
/** bash's whole environment: nothing of this process's is passed. */
|
|
17
17
|
readonly env: Readonly<Record<string, string>>;
|
|
18
|
+
/** Shell text bash runs before each command string (a bash policy's, bash-read-only.ts policyPrelude). */
|
|
19
|
+
readonly prelude?: string;
|
|
18
20
|
/** bash's deadline when a call names none, in seconds. */
|
|
19
21
|
readonly defaultTimeoutS: number;
|
|
22
|
+
/** Each command's network (a bash policy's on Archil's exec: run-tools.ts). */
|
|
23
|
+
readonly network?: "deny";
|
|
20
24
|
};
|
|
21
25
|
/** pi's ExecutionEnv over `workspace`, the run's folder named `options.cwd`. */
|
|
22
26
|
export declare function piEnv(workspace: Workspace, options: PiEnvOptions): ExecutionEnv;
|
package/dist/workspace/pi-env.js
CHANGED
|
@@ -203,13 +203,14 @@ export function piEnv(workspace, options) {
|
|
|
203
203
|
};
|
|
204
204
|
const run = (argv) => workspace.exec(argv, {
|
|
205
205
|
cwd: where.value, env: { ...options.env, ...(given?.env ?? {}) }, timeoutMs: Math.max(1, Math.round(timeoutS * 1000)), maxOutput: 0,
|
|
206
|
-
...(context.abortSignal ? { signal: context.abortSignal } : {}),
|
|
206
|
+
...(context.abortSignal ? { signal: context.abortSignal } : {}), ...(options.network ? { network: options.network } : {}),
|
|
207
207
|
onOutput: ({ stream, data }) => {
|
|
208
208
|
emit(decoders[stream].decode(data), stream);
|
|
209
209
|
keep(data);
|
|
210
210
|
},
|
|
211
211
|
});
|
|
212
|
-
const
|
|
212
|
+
const line = typeof command === "string" ? `${options.prelude ?? ""}${command}` : undefined;
|
|
213
|
+
const argvs = line !== undefined ? [["bash", "-c", line], ["sh", "-c", line]] : [[...command]];
|
|
213
214
|
let ran;
|
|
214
215
|
try {
|
|
215
216
|
for (const argv of argvs) {
|
|
@@ -1,15 +1,19 @@
|
|
|
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. `image`: the one of the provider's configurations it selects; absent, the default. A
|
|
11
|
+
* sandbox's may ask for GPUs. */
|
|
10
12
|
export type ComputerSetting = {
|
|
11
13
|
readonly kind: string;
|
|
12
14
|
readonly provider?: string | null;
|
|
15
|
+
readonly image?: string;
|
|
16
|
+
readonly gpu?: GpuSpec;
|
|
13
17
|
};
|
|
14
18
|
/** The computer module's kind registry (src/kinds.ts), by its own names: the setting kinds, why a machine does not serve
|
|
15
19
|
* one (servingRefusals, whose words a refusal here carries), and the providers. */
|
|
@@ -19,25 +23,53 @@ export type KindRegistry = {
|
|
|
19
23
|
readonly PROVIDERS: readonly ProviderEntry[];
|
|
20
24
|
};
|
|
21
25
|
/** 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
|
|
26
|
+
* phone), the read-back of its mount (when mounted), and its release. A browser is started by none: the claim gives
|
|
27
|
+
* the run's browser tool its provider (`browser`), which opens each session at the tool's first call, and the release
|
|
28
|
+
* lets go of any the tool left open. */
|
|
23
29
|
export type LaunchedComputer = {
|
|
24
30
|
readonly id: string;
|
|
25
31
|
readonly groups: readonly (Group | string)[];
|
|
26
32
|
readonly client?: ComputerClient;
|
|
27
33
|
readBack?(): Promise<Result<MountReadBack>>;
|
|
28
|
-
|
|
34
|
+
readonly browser?: ClaimBrowser;
|
|
29
35
|
release(): Promise<void>;
|
|
30
36
|
};
|
|
37
|
+
/** A browser computer's provider as the run's browser tool opens its sessions through it: each session one computer of
|
|
38
|
+
* the provider's, made under the run's labels and the tool's tag (so a create whose answer was lost is found again),
|
|
39
|
+
* its CDP URL read through the provider's connect at each attach (a secret: it goes only to the driver), and released
|
|
40
|
+
* when the tool lets it go. Errors carry the provider's words, and its code. So the session's time is the time the
|
|
41
|
+
* tool holds it, which is what the run's spend books. */
|
|
42
|
+
export type ClaimBrowser = {
|
|
43
|
+
/** The provider's id: the session's price and its name. */
|
|
44
|
+
readonly provider: string;
|
|
45
|
+
/** The longest a session lives, in seconds. */
|
|
46
|
+
readonly maxLifetimeS: number;
|
|
47
|
+
/** Makes a session for `tag`, to live at most `lifetimeS`: its computer's id. */
|
|
48
|
+
open(tag: string, lifetimeS: number, signal?: AbortSignal): Promise<string>;
|
|
49
|
+
/** The sessions made for `tag`, by id. */
|
|
50
|
+
find(tag: string, signal?: AbortSignal): Promise<string[]>;
|
|
51
|
+
/** The session's CDP URL now. */
|
|
52
|
+
url(id: string): Promise<string>;
|
|
53
|
+
/** Ends the session; one already gone is ended. */
|
|
54
|
+
close(id: string): Promise<void>;
|
|
55
|
+
};
|
|
31
56
|
/** The claim's side: the keys saved for a provider (Settings → Computers; values, never shown), and the launch of one
|
|
32
57
|
* computer of the kind, with the run's folder as its mount when it mounts it. A launch that fails throws its words. */
|
|
33
58
|
export type ClaimSide = {
|
|
34
59
|
keysOf(provider: string): Promise<Readonly<Record<string, string>>>;
|
|
35
60
|
/** Whether a provider that binds a folder of this machine (Docker) answers here now: the Mode 1 default asks it. */
|
|
36
61
|
answers(provider: string): Promise<boolean>;
|
|
62
|
+
/** Its daemon's answer (docker-daemon.ts), asked when a launch on such a provider fails: none answering is refused in
|
|
63
|
+
* the one wording a run's start and Settings → Computers say (noDockerWords). Absent: the launch's own words. */
|
|
64
|
+
daemon?(provider: string): Promise<DockerDaemon>;
|
|
65
|
+
/** `configuration`: the provider's configuration the setting selected; its options go to the provider with the keys,
|
|
66
|
+
* and its image, when it names one, is the computer's. `gpu`: a sandbox's GPUs, held to that configuration. */
|
|
37
67
|
launch(entry: ProviderEntry, spec: {
|
|
38
68
|
readonly kind: ComputerSettingKind;
|
|
39
69
|
readonly keys: Readonly<Record<string, string>>;
|
|
70
|
+
readonly configuration: KindCapabilities;
|
|
40
71
|
readonly mount?: MountSpec;
|
|
72
|
+
readonly gpu?: GpuSpec;
|
|
41
73
|
readonly signal?: AbortSignal;
|
|
42
74
|
}): Promise<LaunchedComputer>;
|
|
43
75
|
};
|
|
@@ -47,15 +79,28 @@ export type Port = "files" | "exec" | "processes" | "screen" | "input" | "phone"
|
|
|
47
79
|
/** A provider's keys as the claim reads them: each key its registry entry declares, by `keyOf` (the server's reader:
|
|
48
80
|
* key-meta.ts keyReader, the environment's value, else the saved one); a key with no value is left out. */
|
|
49
81
|
export declare const providerKeys: (registry: Pick<KindRegistry, "PROVIDERS">, keyOf: (name: string) => Promise<string | undefined>) => ClaimSide["keysOf"];
|
|
82
|
+
/** Whether a provider's computers run only on the vendor's own network: the network forms it declares (its
|
|
83
|
+
* descriptor's, its capabilities().network) are "open" alone, as a cloud phone's and a hosted browser's are. */
|
|
84
|
+
export declare const vendorNetworkOnly: (network: readonly string[] | undefined) => boolean;
|
|
85
|
+
/** Whether a provider's computers can't have no network: it declares its network forms and "none" isn't one (a cloud
|
|
86
|
+
* phone, a hosted browser, Local Chrome). */
|
|
87
|
+
export declare const needsNetwork: (network: readonly string[] | undefined) => boolean;
|
|
88
|
+
/** Why a computer that needs a network is refused where this server's AGENTRUN_BOX_ALLOW is none, in words that name the
|
|
89
|
+
* fix: the operator said no network at all, and the computer can't run without one. */
|
|
90
|
+
export declare const noNetworkRefusal: (label: string, kind: string) => string;
|
|
50
91
|
/** Whether an agent's computer `setting` can be had in `mode` now, by the answers the claim gives (resolveComputer: the
|
|
51
92
|
* kind, the provider and what it serves, the mode's mount, the provider's keys by `keyOf`): ok, or its refusal in words
|
|
52
93
|
* that name the fix. Nothing starts. A run's start asks it before the run is made (runnable.ts).
|
|
53
94
|
*
|
|
54
|
-
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
|
|
95
|
+
* `answers`: whether a provider that binds a folder of this machine (Docker) answers here now, or why not (the server's
|
|
96
|
+
* daemon check, docker-daemon.ts). Any computer on such a provider, a sandbox or a desktop in either mode, is refused
|
|
97
|
+
* here, at the start, where the claim would only fail to launch it: no daemon at all in the one wording Settings →
|
|
98
|
+
* Computers and the claim say (noDockerWords), another reason in its own words. Asked here, not in resolveComputer: the
|
|
99
|
+
* claim launches it, and asks only once its launch fails (ClaimSide.daemon). Absent: not asked.
|
|
100
|
+
*
|
|
101
|
+
* `boxAllow`: this server's allow setting (box-settings.ts boxAllowOf). Under "none", a computer whose provider makes no
|
|
102
|
+
* "none" is refused (noNetworkRefusal), as the claim refuses it. Absent: not asked. */
|
|
103
|
+
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
104
|
readonly ok: true;
|
|
60
105
|
} | {
|
|
61
106
|
readonly refused: string;
|