@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/bound-files.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// The file tools of a run whose box binds its work/ from this machine (Docker here): read, write and edit run on this
|
|
2
|
-
// machine, on the bind's source, and not as commands in the box, which cost one `docker exec` or more each (half a second
|
|
3
|
-
// and up on real Docker). bash stays in the box. This holds only where the confinement walks held directory handles
|
|
4
|
-
// (workspace.ts writesHeld: Linux's /proc/self/fd): a command in the box runs beside these tools and can plant a link, a
|
|
5
|
-
// hard link or a swapped directory at any moment, and only a walk on held handles refuses a swap between the check and
|
|
6
|
-
// the use. Elsewhere (macOS, a box that binds nothing, Daytona's) all four stay in the box (coding-tools.ts).
|
|
7
|
-
//
|
|
8
|
-
// Nothing a box's command makes in work/ is followed or taken. Every path is work/ joined with its own names, and a link
|
|
9
|
-
// anywhere on the way is refused, even one pointing inside work/. Only a regular file with one hard link is read or
|
|
10
|
-
// written. A write goes through a temporary file renamed over the old one, keeping its mode (workspace.ts
|
|
11
|
-
// writeWorkFile). work/ itself must be its own canonical path: the directory the box was given (run-box.ts
|
|
12
|
-
// mountSource). The model names the box's paths (BOX_WORK), mapped one for one onto the bind's source; every path and
|
|
13
|
-
// message it gets back names the box's, never this machine's.
|
|
14
|
-
import { realpathSync } from "node:fs";
|
|
15
|
-
import { posix } from "node:path";
|
|
16
|
-
import { err, ExecutionError, FileError, ok } from "@earendil-works/pi-durable/env";
|
|
17
|
-
import { NodeExecutionEnv } from "@earendil-works/pi-durable/env/node";
|
|
18
|
-
import { PathOutsideWorkError } from "@parcha/pi-durable-disk";
|
|
19
|
-
import { BOX_WORK } from "./place.js";
|
|
20
|
-
import { openWorkFile, WorkRefused, writeWorkFile } from "./workspace.js";
|
|
21
|
-
/** What a refusal tells the model, by the path it named: what is wrong, and that bash, in the box, can still reach it. */
|
|
22
|
-
const REFUSED = {
|
|
23
|
-
link: (path) => `${path}: refused: a link is on the way to it, or it is one, and read, write and edit follow no link in this run's work/ (bash, in the box, can)`,
|
|
24
|
-
hard_link: (path) => `${path}: refused: it has another hard link, and read, write and edit take only a file with one (bash, in the box, can)`,
|
|
25
|
-
not_regular: (path) => `${path}: refused: it is not a regular file`,
|
|
26
|
-
unreadable: (path) => `${path}: refused: this server may not read it (a command in the box made it private)`,
|
|
27
|
-
over_cap: (path) => `${path}: refused: it is too large`,
|
|
28
|
-
unheld: (path) => `${path}: refused: this host reaches the run's directories by path`,
|
|
29
|
-
};
|
|
30
|
-
const NODE_CODES = { ENOENT: "not_found", EACCES: "permission_denied", EPERM: "permission_denied", ENOTDIR: "not_directory", EISDIR: "is_directory", ELOOP: "invalid" };
|
|
31
|
-
/** A box run's read, write and edit environment on this machine's `hostWork` (canonical: the bind's source), naming the
|
|
32
|
-
* box's paths. Its shell runs nothing, and only the operations those tools make are offered. */
|
|
33
|
-
export function boundFiles(hostWork) {
|
|
34
|
-
// pi's own implementation, only ever handed a checked handle's /proc/self/fd entry, which names that inode and no path.
|
|
35
|
-
const node = new NodeExecutionEnv({ cwd: hostWork });
|
|
36
|
-
/** `text` with this machine's work/ named as the box names it. */
|
|
37
|
-
const boxed = (text) => text.split(`${hostWork}/`).join(`${BOX_WORK}/`).split(hostWork).join(BOX_WORK);
|
|
38
|
-
// The confinement's typed refusal, its message naming no path: the tools name it by the path the call gave
|
|
39
|
-
// (workspace-paths.ts asGivenRefusals). It crosses from pi-durable-disk's pi-durable as a value, typed on this side.
|
|
40
|
-
const outside = (path) => new PathOutsideWorkError(path, "outside_work", "outside the workspace");
|
|
41
|
-
/** `path` as an absolute path of the box, or the refusal of one outside its work/. */
|
|
42
|
-
const absolute = (path) => {
|
|
43
|
-
const abs = posix.resolve(BOX_WORK, path);
|
|
44
|
-
return abs === BOX_WORK || abs.startsWith(`${BOX_WORK}/`) ? ok(abs) : err(outside(path));
|
|
45
|
-
};
|
|
46
|
-
const failure = (error, path) => {
|
|
47
|
-
if (error instanceof WorkRefused) {
|
|
48
|
-
if (error.reason === "missing")
|
|
49
|
-
return new FileError("not_found", `ENOENT: no such file or directory, open '${path}'`, path);
|
|
50
|
-
return new FileError("permission_denied", REFUSED[error.reason](path), path);
|
|
51
|
-
}
|
|
52
|
-
if (error instanceof FileError)
|
|
53
|
-
return new FileError(error.code, boxed(error.message), path, error);
|
|
54
|
-
const code = error?.code;
|
|
55
|
-
return new FileError((code && NODE_CODES[code]) || "unknown", boxed(error?.message ?? String(error)), path);
|
|
56
|
-
};
|
|
57
|
-
/** The work/ the box was given: refused when it is no longer its own canonical path (swapped for a link). */
|
|
58
|
-
const root = () => {
|
|
59
|
-
if (realpathSync(hostWork) !== hostWork)
|
|
60
|
-
throw new WorkRefused(".", "link");
|
|
61
|
-
};
|
|
62
|
-
/** `use` on the file at `path`, opened held: a regular file with one link, reached through no link. */
|
|
63
|
-
async function opened(path, use) {
|
|
64
|
-
const abs = absolute(path);
|
|
65
|
-
if (!abs.ok)
|
|
66
|
-
return abs;
|
|
67
|
-
const rel = posix.relative(BOX_WORK, abs.value);
|
|
68
|
-
if (rel === "")
|
|
69
|
-
return err(new FileError("is_directory", `${abs.value}: is the run's work directory, not a file`, abs.value));
|
|
70
|
-
try {
|
|
71
|
-
root();
|
|
72
|
-
const { handle, stats } = await openWorkFile(hostWork, rel);
|
|
73
|
-
try {
|
|
74
|
-
return ok(await use(handle, stats, abs.value));
|
|
75
|
-
}
|
|
76
|
-
finally {
|
|
77
|
-
await handle.close().catch(() => undefined);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return err(failure(error, abs.value));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/** pi's reader of a checked handle, its info naming the box's path. */
|
|
85
|
-
const reader = async (handle, abs, context) => {
|
|
86
|
-
const made = await node.openBinaryReader(`/proc/self/fd/${handle.fd}`, undefined, context);
|
|
87
|
-
if (!made.ok)
|
|
88
|
-
throw made.error;
|
|
89
|
-
const inner = made.value;
|
|
90
|
-
return {
|
|
91
|
-
info: async (at) => {
|
|
92
|
-
const info = await inner.info(at);
|
|
93
|
-
return info.ok ? ok({ ...info.value, name: posix.basename(abs), path: abs }) : err(failure(info.error, abs));
|
|
94
|
-
},
|
|
95
|
-
read: (offset, length, at) => inner.read(offset, length, at),
|
|
96
|
-
scanLines: (options, at) => inner.scanLines(options, at),
|
|
97
|
-
close: (at) => inner.close(at),
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
/** An operation read, write and edit never make: refused, so nothing else of this machine is reached through it. */
|
|
101
|
-
const unoffered = (name) => async () => err(new FileError("not_supported", `${name} is not offered here: a box run's file tools on this machine read, write and edit, and bash runs in the box`));
|
|
102
|
-
return {
|
|
103
|
-
id: `bound-work:${hostWork}`,
|
|
104
|
-
cwd: BOX_WORK,
|
|
105
|
-
absolutePath: async (path) => absolute(path),
|
|
106
|
-
joinPath: async (parts) => ok(posix.join(...parts)),
|
|
107
|
-
// The mutation queue then keys a file by its absolute path: a link is never followed here, so that is the file.
|
|
108
|
-
canonicalPath: unoffered("canonicalPath"),
|
|
109
|
-
exists: async (path) => {
|
|
110
|
-
const abs = absolute(path);
|
|
111
|
-
if (!abs.ok)
|
|
112
|
-
return abs;
|
|
113
|
-
const found = await opened(abs.value, async () => true);
|
|
114
|
-
// A file refused is there: the operation that follows says why.
|
|
115
|
-
return found.ok || found.error.code !== "not_found" ? ok(true) : ok(false);
|
|
116
|
-
},
|
|
117
|
-
fileInfo: (path) => opened(path, async (_handle, info, abs) => ({ name: posix.basename(abs), path: abs, kind: "file", size: info.size, mtimeMs: info.mtimeMs })),
|
|
118
|
-
readTextFile: (path, context) => opened(path, (handle) => handle.readFile({ encoding: "utf8", ...(context.abortSignal ? { signal: context.abortSignal } : {}) })),
|
|
119
|
-
readBinaryFile: (path, context) => opened(path, async (handle) => new Uint8Array(await handle.readFile(context.abortSignal ? { signal: context.abortSignal } : {}))),
|
|
120
|
-
openBinaryReader: (path, _options, context) => opened(path, (handle, _info, abs) => reader(handle, abs, context)),
|
|
121
|
-
openTextLineReader: (path, context) => opened(path, async (handle, _info, abs) => {
|
|
122
|
-
const made = await node.openTextLineReader(`/proc/self/fd/${handle.fd}`, context);
|
|
123
|
-
if (!made.ok)
|
|
124
|
-
throw failure(made.error, abs);
|
|
125
|
-
return made.value;
|
|
126
|
-
}),
|
|
127
|
-
readTextLines: (path, options, context) => opened(path, async (handle, _info, abs) => {
|
|
128
|
-
const read = await node.readTextLines(`/proc/self/fd/${handle.fd}`, options, context);
|
|
129
|
-
if (!read.ok)
|
|
130
|
-
throw failure(read.error, abs);
|
|
131
|
-
return read.value;
|
|
132
|
-
}),
|
|
133
|
-
writeFile: async (path, content) => {
|
|
134
|
-
const abs = absolute(path);
|
|
135
|
-
if (!abs.ok)
|
|
136
|
-
return abs;
|
|
137
|
-
const rel = posix.relative(BOX_WORK, abs.value);
|
|
138
|
-
if (rel === "")
|
|
139
|
-
return err(new FileError("is_directory", `${abs.value}: is the run's work directory, not a file`, abs.value));
|
|
140
|
-
try {
|
|
141
|
-
root();
|
|
142
|
-
// A new file as a box's command would make it (0644); one already there keeps its mode.
|
|
143
|
-
await writeWorkFile(hostWork, rel, typeof content === "string" ? Buffer.from(content) : content, 0o644, true);
|
|
144
|
-
return ok(undefined);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
return err(failure(error, abs.value));
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
appendFile: unoffered("appendFile"),
|
|
151
|
-
truncateFile: unoffered("truncateFile"),
|
|
152
|
-
flushFile: unoffered("flushFile"),
|
|
153
|
-
renameFile: unoffered("renameFile"),
|
|
154
|
-
listDir: unoffered("listDir"),
|
|
155
|
-
openDirReader: unoffered("openDirReader"),
|
|
156
|
-
watch: unoffered("watch"),
|
|
157
|
-
createDir: unoffered("createDir"),
|
|
158
|
-
remove: unoffered("remove"),
|
|
159
|
-
createTempDir: unoffered("createTempDir"),
|
|
160
|
-
createTempFile: unoffered("createTempFile"),
|
|
161
|
-
exec: async () => err(new ExecutionError("shell_unavailable", "this environment runs no command: bash runs in the box")),
|
|
162
|
-
cleanup: async () => undefined,
|
|
163
|
-
};
|
|
164
|
-
}
|
package/dist/bounds.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export declare class RequestBounds {
|
|
2
|
-
/** The newest entry read, by id: an entry at or before it is read again, and changes nothing. */
|
|
3
|
-
private seen;
|
|
4
|
-
/** Each request in flight that names itself: a harness request, by `<key>:<request>`, and a pi side request, by
|
|
5
|
-
* `side:<requestId>`; its bound. */
|
|
6
|
-
private harness;
|
|
7
|
-
/** Each harness request booked before its cost, by `<key>:<request>`: its bound, served as in flight until its late
|
|
8
|
-
* cost comes, and never holding the ended bounds back. */
|
|
9
|
-
private awaiting;
|
|
10
|
-
/** pi's one generation request in flight: its bound. */
|
|
11
|
-
private pi;
|
|
12
|
-
/** The bounds of the requests that ended since the run's cost last fit its cap, together. */
|
|
13
|
-
private since;
|
|
14
|
-
/** What the run has spent by the entries read, as the cap reads each entry's cost. */
|
|
15
|
-
private spent;
|
|
16
|
-
/** Reads `entries` of the run's root, each once, against the run's `cap` (none: no overshoot to explain). */
|
|
17
|
-
note(entries: readonly unknown[], cap?: number): void;
|
|
18
|
-
private noteOne;
|
|
19
|
-
private closeHarness;
|
|
20
|
-
private closePi;
|
|
21
|
-
/** The bounds of the requests in flight, together: those whose cost may still be a miss. */
|
|
22
|
-
inFlight(): number;
|
|
23
|
-
/** The bounds of the requests that ended since the run's cost last fit its cap, together: how far a cache miss among
|
|
24
|
-
* them may have taken the run past its cap. */
|
|
25
|
-
ended(): number;
|
|
26
|
-
}
|
package/dist/bounds.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
// The bounds of a run's model requests (cap.ts BOUND_FIELD: the most a cache miss can make one cost beyond what its cap
|
|
2
|
-
// held it at), as its root's entries say them: what the run's cost serves as in flight (overshoot_bound_usd), and what the
|
|
3
|
-
// over-cap row and the run's end read as the bound of the requests that ended since its cost last fit its cap.
|
|
4
|
-
//
|
|
5
|
-
// The server reads a run's entries live and then again whole (a reconnect's snapshot, the settle's and a load's full read
|
|
6
|
-
// of the store): each entry changes the bounds once, by its id, as turns.ts reads them. A harness request (its start mark
|
|
7
|
-
// names its session `key` and `request`, harness-app.ts) closes when its own answer is booked, by the BOOKED marker that
|
|
8
|
-
// names it, in whatever order answers come; one booked before its cost came in stays open until its late cost does. pi's
|
|
9
|
-
// generation requests go one at a time on the root: one closes on its end mark or its answer (a second close, a stopped
|
|
10
|
-
// request's aborted entry after its end mark, closes nothing), never on a lost attempt's end mark (`lost`, written before
|
|
11
|
-
// pi-ai tries again within the same request: its answer, or its own end, still comes), and a start while one is still
|
|
12
|
-
// open says that one was cut
|
|
13
|
-
// (a crash: the next process sends the next request): pi-agent-core's loop awaits each answer before it runs that
|
|
14
|
-
// answer's tool calls and sends the next (agent-loop.js runLoop). pi's side requests (a label for `request`: a summary, a
|
|
15
|
-
// hosted search's, a learned workflow node's) run inside tool calls, which pi runs side by side (agent.js toolExecution
|
|
16
|
-
// "parallel"): each closes by its own `requestId`, on its end mark or its cost. A refusal's own start mark holds none.
|
|
17
|
-
//
|
|
18
|
-
// A request that will never end must not pin the bounds for the run's life. A pi side request is over once the run sends
|
|
19
|
-
// its next turn or harness request: pi-agent-core awaits the turn's tool calls (agent-loop.js:165, `await
|
|
20
|
-
// executeToolCalls`, inside which every side request runs) before it sends the next (:141), so one still open then died
|
|
21
|
-
// with its process (an OOM kill inside the tool call, before its cost mark): its hold is booked, it has no cost to come, and
|
|
22
|
-
// its bound is dropped, never summed. A harness request booked before its cost keeps its bound served as in flight (its
|
|
23
|
-
// cost may still be a miss), apart from the requests whose answers are still to come: it never holds the ended bounds
|
|
24
|
-
// back from starting afresh, since its bound joins them in the very entry that brings its late cost, so it counts when,
|
|
25
|
-
// and only when, its cost does, whatever came between (harness answers and late costs come in any order). That cost
|
|
26
|
-
// always comes while the run lives: in its process (harness-app.ts priceLate), or at the next open, which writes every
|
|
27
|
-
// booked request the root has at unknown cost before any new request; a run no process holds serves no bound (runs.ts).
|
|
28
|
-
//
|
|
29
|
-
// The bounds that ended count from the newest entry at which what the run had spent (the cap's own reading of an entry's
|
|
30
|
-
// cost, cap.ts costOf) fit its cap with no request in flight: read live or whole after a restart, the same entries keep
|
|
31
|
-
// the same bounds.
|
|
32
|
-
import { REQUEST_COST, REQUEST_COST_LATE, REQUEST_ENDED, REQUEST_STARTED } from "@parcha/pi-durable-agent/timeline";
|
|
33
|
-
import { BOUND_FIELD, CAP_REFUSED_FIELD, costOf, FIT_TOLERANCE } from "./cap.js";
|
|
34
|
-
import { ADAPTER_API, BOOKED } from "./turn-end.js";
|
|
35
|
-
import { isObject } from "./validate.js";
|
|
36
|
-
const boundOf = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0);
|
|
37
|
-
export class RequestBounds {
|
|
38
|
-
/** The newest entry read, by id: an entry at or before it is read again, and changes nothing. */
|
|
39
|
-
seen = -Infinity;
|
|
40
|
-
/** Each request in flight that names itself: a harness request, by `<key>:<request>`, and a pi side request, by
|
|
41
|
-
* `side:<requestId>`; its bound. */
|
|
42
|
-
harness = new Map();
|
|
43
|
-
/** Each harness request booked before its cost, by `<key>:<request>`: its bound, served as in flight until its late
|
|
44
|
-
* cost comes, and never holding the ended bounds back. */
|
|
45
|
-
awaiting = new Map();
|
|
46
|
-
/** pi's one generation request in flight: its bound. */
|
|
47
|
-
pi;
|
|
48
|
-
/** The bounds of the requests that ended since the run's cost last fit its cap, together. */
|
|
49
|
-
since = 0;
|
|
50
|
-
/** What the run has spent by the entries read, as the cap reads each entry's cost. */
|
|
51
|
-
spent = 0;
|
|
52
|
-
/** Reads `entries` of the run's root, each once, against the run's `cap` (none: no overshoot to explain). */
|
|
53
|
-
note(entries, cap) {
|
|
54
|
-
for (const value of entries) {
|
|
55
|
-
if (!isObject(value))
|
|
56
|
-
continue;
|
|
57
|
-
if (typeof value.id === "number") {
|
|
58
|
-
if (value.id <= this.seen)
|
|
59
|
-
continue;
|
|
60
|
-
this.seen = value.id;
|
|
61
|
-
}
|
|
62
|
-
this.noteOne(value);
|
|
63
|
-
this.spent += costOf(value);
|
|
64
|
-
// The run's cost fits its cap here, and no request is in flight whose cost is still to come: the bounds that ended so
|
|
65
|
-
// far explain no overshoot to come.
|
|
66
|
-
if (cap === undefined || (this.spent <= cap + FIT_TOLERANCE && this.pi === undefined && this.harness.size === 0))
|
|
67
|
-
this.since = 0;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
noteOne(value) {
|
|
71
|
-
const data = isObject(value.data) ? value.data : {};
|
|
72
|
-
const side = typeof data.request === "string";
|
|
73
|
-
const harnessKey = typeof data.key === "string" && typeof data.request === "number" ? `${data.key}:${data.request}` : side && typeof data.requestId === "string" ? `side:${data.requestId}` : undefined;
|
|
74
|
-
const message = Array.isArray(value.model) && isObject(value.model[0]) ? value.model[0] : undefined;
|
|
75
|
-
if (value.kind === REQUEST_STARTED) {
|
|
76
|
-
if (data[CAP_REFUSED_FIELD] === true)
|
|
77
|
-
return;
|
|
78
|
-
// A turn or harness request: every side request still open died with its process (above).
|
|
79
|
-
// This assumes no harness runs a second request loop inside a tool call: Claude Code runs with its builtins off, or
|
|
80
|
-
// with CLAUDE_BUILTINS_OFF keeping Task and Agent off, and Codex with multi_agent and agents off. Should either get
|
|
81
|
-
// native subagents, a side request could still be live at a root start, and this drop rule needs another look.
|
|
82
|
-
if (!side)
|
|
83
|
-
for (const key of [...this.harness.keys()])
|
|
84
|
-
if (key.startsWith("side:"))
|
|
85
|
-
this.harness.delete(key);
|
|
86
|
-
if (harnessKey)
|
|
87
|
-
this.harness.set(harnessKey, boundOf(data[BOUND_FIELD]));
|
|
88
|
-
else if (side)
|
|
89
|
-
return;
|
|
90
|
-
// A pi request still open when the next starts was cut by a crash: booked at its hold, it ends with no cost of its own.
|
|
91
|
-
else
|
|
92
|
-
this.pi = boundOf(data[BOUND_FIELD]);
|
|
93
|
-
}
|
|
94
|
-
else if (value.kind === BOOKED && harnessKey) {
|
|
95
|
-
if (data.unpriced !== true)
|
|
96
|
-
this.closeHarness(harnessKey);
|
|
97
|
-
else if (this.harness.has(harnessKey)) {
|
|
98
|
-
this.awaiting.set(harnessKey, this.harness.get(harnessKey));
|
|
99
|
-
this.harness.delete(harnessKey);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (value.kind === REQUEST_COST_LATE && harnessKey && this.awaiting.has(harnessKey)) {
|
|
103
|
-
this.since += this.awaiting.get(harnessKey);
|
|
104
|
-
this.awaiting.delete(harnessKey);
|
|
105
|
-
}
|
|
106
|
-
else if ((value.kind === REQUEST_COST_LATE || value.kind === REQUEST_COST || value.kind === REQUEST_ENDED) && harnessKey)
|
|
107
|
-
this.closeHarness(harnessKey);
|
|
108
|
-
else if (value.kind === REQUEST_ENDED && !side && !harnessKey && data.lost !== true)
|
|
109
|
-
this.closePi();
|
|
110
|
-
// A harness answer is closed by its BOOKED marker; pi's answer (or pi's error for a request that never left, which
|
|
111
|
-
// finds none open) closes pi's.
|
|
112
|
-
else if (value.kind === "pi.assistant" && message && message.api !== ADAPTER_API)
|
|
113
|
-
this.closePi();
|
|
114
|
-
}
|
|
115
|
-
closeHarness(key) {
|
|
116
|
-
const bound = this.harness.get(key);
|
|
117
|
-
if (bound === undefined)
|
|
118
|
-
return;
|
|
119
|
-
this.harness.delete(key);
|
|
120
|
-
this.since += bound;
|
|
121
|
-
}
|
|
122
|
-
closePi() {
|
|
123
|
-
if (this.pi === undefined)
|
|
124
|
-
return;
|
|
125
|
-
this.since += this.pi;
|
|
126
|
-
this.pi = undefined;
|
|
127
|
-
}
|
|
128
|
-
/** The bounds of the requests in flight, together: those whose cost may still be a miss. */
|
|
129
|
-
inFlight() {
|
|
130
|
-
return [...this.harness.values(), ...this.awaiting.values()].reduce((sum, usd) => sum + usd, this.pi ?? 0);
|
|
131
|
-
}
|
|
132
|
-
/** The bounds of the requests that ended since the run's cost last fit its cap, together: how far a cache miss among
|
|
133
|
-
* them may have taken the run past its cap. */
|
|
134
|
-
ended() {
|
|
135
|
-
return this.since;
|
|
136
|
-
}
|
|
137
|
-
}
|
package/dist/coding-tools.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import { type Extension, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
-
import { SHELL_TOOLS } from "./background.js";
|
|
4
|
-
import { type Place } from "./place.js";
|
|
5
|
-
/** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
|
|
6
|
-
* call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
|
|
7
|
-
export declare const CodingTools: Extension;
|
|
8
|
-
/** The tools that run a command in the box, never on this machine: bash, and the background tools (background.ts). */
|
|
9
|
-
export { SHELL_TOOLS };
|
|
10
|
-
/** The tools a box runs, by name: pi's four and the background tools. */
|
|
11
|
-
export declare const BOXED_TOOLS: readonly string[];
|
|
12
|
-
/** A run's coding tools and the extension a conversation selects for them. */
|
|
13
|
-
export type CodingSource = {
|
|
14
|
-
readonly extension: Extension;
|
|
15
|
-
readonly tools: readonly ToolRegistration[];
|
|
16
|
-
};
|
|
17
|
-
/** The environment a boxed tool's call runs on: the run's box's (run-box.ts). `note` writes a row on the run's timeline
|
|
18
|
-
* while the box is being had (its image still coming). `hostWork`: the run's own work/ on this machine, the source the
|
|
19
|
-
* box binds at BOX_WORK; `bound`, whether the box's provider binds it there (Docker does). */
|
|
20
|
-
export type BoxedEnv = {
|
|
21
|
-
env(context: Context, note?: (summary: string) => Promise<void>): Promise<unknown>;
|
|
22
|
-
hostWork?: string;
|
|
23
|
-
bound?(): Promise<boolean>;
|
|
24
|
-
leftEnded?(context: Context): Promise<void>; /** Once, what the model is told of a box this process made in place of an earlier one's (run-box.ts BOX_REPLACED_NOTE). */
|
|
25
|
-
replaced?(): string | undefined;
|
|
26
|
-
};
|
|
27
|
-
/** A call's answer with what `box` has to tell the model first, once (its box replaced since the run's last process),
|
|
28
|
-
* asked once the box is had: its first line, in the output an answer with no content of its own is made of, and a text
|
|
29
|
-
* part before the answer's `output` blocks. */
|
|
30
|
-
export declare function withBoxNote<T>(box: Pick<BoxedEnv, "replaced">, output: (chunk: string) => void, call: () => Promise<T>): Promise<T>;
|
|
31
|
-
/** A boxed file tool's path as the box names it, or undefined when it leaves the box's work dir (`~` and `file:`
|
|
32
|
-
* included). A path under the run's own host work dir (another harness's cwd can name one) is the same file at
|
|
33
|
-
* BOX_WORK, the bind renamed one for one; every other host path (the data root, another run) is never taken for a box
|
|
34
|
-
* path. */
|
|
35
|
-
export declare function boxPath(path: string, hostWork?: string): string | undefined;
|
|
36
|
-
/** bash's timeout, in seconds: the default when a call names none, and the most any call gets (Claude Code's own 120 s
|
|
37
|
-
* and 600 s). A command that needs longer is a background process (bash_background). */
|
|
38
|
-
export declare const BASH_DEFAULT_TIMEOUT_S = 120;
|
|
39
|
-
export declare const BASH_MAX_TIMEOUT_S = 600;
|
|
40
|
-
/** The largest image read hands the model, in bytes: 3.75 MiB, whose base64 is the 5 MiB the strictest platform a
|
|
41
|
-
* harness sends images to takes (the claude-agent adapter's CLAUDE_AGENT_MAX_IMAGE_BYTES, Amazon Bedrock's). */
|
|
42
|
-
export declare const READ_IMAGE_MAX_BYTES = 3932160;
|
|
43
|
-
/** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
|
|
44
|
-
* each with its arguments, output and replay as pi ships it and its environment the box's, and the background tools
|
|
45
|
-
* (background.ts), each call a command in the box. A file tool's path stays in the box's work dir; bash's command is
|
|
46
|
-
* the box's own. */
|
|
47
|
-
export declare function codingSource(place: Place, box?: BoxedEnv): CodingSource;
|
package/dist/coding-tools.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// The coding tools a run's process registers: pi's (ArchilCodingTools, `read` declared replay-safe) without `bash`. A
|
|
2
|
-
// run gets no shell on this machine, so this is the only coding-tools extension serve installs (app.ts, tools.ts) and
|
|
3
|
-
// the only one its host tools are taken from (host-tools.ts). The tools left are pi's own, with only their execute
|
|
4
|
-
// wrapped so a refusal names the path the call gave (asGivenRefusals), and the extension keeps everything else pi's
|
|
5
|
-
// carries (its name, so a conversation selects it as before).
|
|
6
|
-
//
|
|
7
|
-
// A run whose place is a box gets codingSource's instead: pi's own read, write, edit and bash, and the background tools
|
|
8
|
-
// (background.ts), each call made on the box's environment (run-box.ts), so the shell exists only in the box. One source feeds pi's tool table (tools.ts,
|
|
9
|
-
// app.ts) and another harness's host tools (host-tools.ts).
|
|
10
|
-
//
|
|
11
|
-
// Where the box binds the run's work/ from this machine and the confinement holds directory handles (Docker on Linux),
|
|
12
|
-
// read, write and edit run on this machine instead, on the bind's source (bound-files.ts): a command in the box costs
|
|
13
|
-
// far more than a file read. bash and the background tools always run in the box, and every tool of any other box (or of
|
|
14
|
-
// any host that reaches directories by path) does too.
|
|
15
|
-
import { posix } from "node:path";
|
|
16
|
-
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
17
|
-
import { FileError } from "@earendil-works/pi-durable/env";
|
|
18
|
-
import { HOST_PHASE } from "@parcha/pi-durable-agent/timeline";
|
|
19
|
-
import { ArchilCodingTools } from "@parcha/pi-durable-disk";
|
|
20
|
-
import { BACKGROUND_TOOLS, backgroundTools, SHELL_TOOLS } from "./background.js";
|
|
21
|
-
import { boundFiles } from "./bound-files.js";
|
|
22
|
-
import { BOX_WORK } from "./place.js";
|
|
23
|
-
import { forModelBlocks } from "./result.js";
|
|
24
|
-
import { asGivenRefusals, refuseOutsideWorkspace } from "./workspace-paths.js";
|
|
25
|
-
import { writesHeld } from "./workspace.js";
|
|
26
|
-
const pis = ArchilCodingTools;
|
|
27
|
-
/** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
|
|
28
|
-
* call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
|
|
29
|
-
export const CodingTools = { ...pis, tools: asGivenRefusals((pis.tools ?? []).filter((tool) => tool.name !== "bash")) };
|
|
30
|
-
/** pi's tools a box runs, by name. */
|
|
31
|
-
const PI_BOXED = ["read", "write", "edit", "bash"];
|
|
32
|
-
/** The tools that run a command in the box, never on this machine: bash, and the background tools (background.ts). */
|
|
33
|
-
export { SHELL_TOOLS };
|
|
34
|
-
/** The tools a box runs, by name: pi's four and the background tools. */
|
|
35
|
-
export const BOXED_TOOLS = [...PI_BOXED, ...BACKGROUND_TOOLS];
|
|
36
|
-
/** A call's answer with what `box` has to tell the model first, once (its box replaced since the run's last process),
|
|
37
|
-
* asked once the box is had: its first line, in the output an answer with no content of its own is made of, and a text
|
|
38
|
-
* part before the answer's `output` blocks. */
|
|
39
|
-
export async function withBoxNote(box, output, call) {
|
|
40
|
-
const note = box.replaced?.();
|
|
41
|
-
if (!note)
|
|
42
|
-
return call();
|
|
43
|
-
output(`${note}\n`);
|
|
44
|
-
const result = await call();
|
|
45
|
-
// Before the answer's model blocks, under `output` (pi's result key).
|
|
46
|
-
const fields = result;
|
|
47
|
-
return fields && Array.isArray(fields.output) ? { ...result, output: [{ type: "text", text: note }, ...fields.output] } : result;
|
|
48
|
-
}
|
|
49
|
-
/** A failed call's error with what the file environment said, where pi's message gives only its code (edit's "Error
|
|
50
|
-
* code: permission_denied."), so the model reads why and what it can do. */
|
|
51
|
-
const withCause = (error) => {
|
|
52
|
-
const cause = error?.cause;
|
|
53
|
-
return error instanceof Error && cause instanceof FileError && !error.message.includes(cause.message) ? new Error(`${error.message} ${cause.message}`, { cause }) : error;
|
|
54
|
-
};
|
|
55
|
-
/** A boxed file tool's path as the box names it, or undefined when it leaves the box's work dir (`~` and `file:`
|
|
56
|
-
* included). A path under the run's own host work dir (another harness's cwd can name one) is the same file at
|
|
57
|
-
* BOX_WORK, the bind renamed one for one; every other host path (the data root, another run) is never taken for a box
|
|
58
|
-
* path. */
|
|
59
|
-
export function boxPath(path, hostWork) {
|
|
60
|
-
if (/^(~|file:)/.test(path))
|
|
61
|
-
return undefined;
|
|
62
|
-
const named = hostWork && (path === hostWork || path.startsWith(`${hostWork}/`)) ? `${BOX_WORK}${path.slice(hostWork.length)}` : path;
|
|
63
|
-
const at = posix.resolve(BOX_WORK, named);
|
|
64
|
-
return at === BOX_WORK || at.startsWith(`${BOX_WORK}/`) ? named : undefined;
|
|
65
|
-
}
|
|
66
|
-
/** bash's timeout, in seconds: the default when a call names none, and the most any call gets (Claude Code's own 120 s
|
|
67
|
-
* and 600 s). A command that needs longer is a background process (bash_background). */
|
|
68
|
-
export const BASH_DEFAULT_TIMEOUT_S = 120;
|
|
69
|
-
export const BASH_MAX_TIMEOUT_S = 600;
|
|
70
|
-
const BASH_TIMEOUT_WORDS = `Timeout in seconds: ${BASH_DEFAULT_TIMEOUT_S} s by default, at most ${BASH_MAX_TIMEOUT_S} s; for longer work use bash_background.`;
|
|
71
|
-
const BASH_TIMEOUT_SENTENCE = ` Each command is stopped after ${BASH_DEFAULT_TIMEOUT_S} s by default, at most ${BASH_MAX_TIMEOUT_S} s; for longer work use bash_background.`;
|
|
72
|
-
const capWords = (asked) => `bash runs a command for at most ${BASH_MAX_TIMEOUT_S} s: this one ran with ${BASH_MAX_TIMEOUT_S} s, not the ${asked} s asked. For longer work use bash_background.`;
|
|
73
|
-
/** pi's bash with its timeout said and kept: the description and the timeout's own words name the default and the
|
|
74
|
-
* ceiling, a call with none runs at the default, and one asking for more runs at the ceiling and says so (a diagnostic
|
|
75
|
-
* when it ends, its error when it times out). Its schema's shape is pi's; only words change. */
|
|
76
|
-
function boundedBash(tool) {
|
|
77
|
-
const parameters = tool.parameters;
|
|
78
|
-
const timeout = parameters.properties?.timeout;
|
|
79
|
-
return {
|
|
80
|
-
...tool,
|
|
81
|
-
description: `${tool.description}${BASH_TIMEOUT_SENTENCE}`,
|
|
82
|
-
parameters: (timeout ? { ...parameters, properties: { ...parameters.properties, timeout: { ...timeout, description: BASH_TIMEOUT_WORDS } } } : parameters),
|
|
83
|
-
execute: async (args, api, context) => {
|
|
84
|
-
const asked = args?.timeout;
|
|
85
|
-
const capped = typeof asked === "number" && asked > BASH_MAX_TIMEOUT_S;
|
|
86
|
-
const timeoutS = typeof asked === "number" ? Math.min(asked, BASH_MAX_TIMEOUT_S) : BASH_DEFAULT_TIMEOUT_S;
|
|
87
|
-
try {
|
|
88
|
-
const result = await tool.execute({ ...args, timeout: timeoutS }, api, context);
|
|
89
|
-
return capped ? { ...result, diagnostics: [...(result.diagnostics ?? []), { severity: "warn", code: "timeout_capped", message: capWords(asked) }] } : result;
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
if (capped && error instanceof Error && /timed out/i.test(error.message))
|
|
93
|
-
throw new Error(`${error.message}. ${capWords(asked)}`, { cause: error });
|
|
94
|
-
throw error;
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/** The image types read opens, by extension; the bytes must say the same (imageTypeOf). */
|
|
100
|
-
const IMAGE_EXTENSIONS = { png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp" };
|
|
101
|
-
/** The largest image read hands the model, in bytes: 3.75 MiB, whose base64 is the 5 MiB the strictest platform a
|
|
102
|
-
* harness sends images to takes (the claude-agent adapter's CLAUDE_AGENT_MAX_IMAGE_BYTES, Amazon Bedrock's). */
|
|
103
|
-
export const READ_IMAGE_MAX_BYTES = 3_932_160;
|
|
104
|
-
/** The box's side of an image read: at most `$2` bytes of `$1`, as base64 (env.exec answers in text). A file over the
|
|
105
|
-
* bound never leaves the box whole: the server holds one byte past it at most, and refuses it. */
|
|
106
|
-
const READ_IMAGE_SCRIPT = '[ -f "$1" ] && [ -r "$1" ] || exit 6; head -c "$2" -- "$1" | base64';
|
|
107
|
-
/** At most `limit` bytes of the box's `path`, read in the box, or undefined when it can't be read there. */
|
|
108
|
-
async function boxBytes(env, path, limit, context) {
|
|
109
|
-
let out = "";
|
|
110
|
-
const ran = await env.exec(["sh", "-c", READ_IMAGE_SCRIPT, "agentrun-read-image", path, String(limit)], {
|
|
111
|
-
timeout: 30,
|
|
112
|
-
onOutput: (text, _context, info) => {
|
|
113
|
-
if (info.stream === "stdout")
|
|
114
|
-
out += text;
|
|
115
|
-
},
|
|
116
|
-
}, context);
|
|
117
|
-
if (!ran.ok || ran.value.exitCode !== 0)
|
|
118
|
-
return undefined;
|
|
119
|
-
return new Uint8Array(Buffer.from(out.replace(/\s+/g, ""), "base64"));
|
|
120
|
-
}
|
|
121
|
-
const READ_IMAGE_SENTENCE = " It also opens an image (png, jpg, gif, webp) at any path in the run's box, such as one rendered to /tmp, and returns it as an image; any other file only inside work/.";
|
|
122
|
-
/** The image type the bytes say they are, or undefined: the magic bytes of PNG, JPEG, GIF and WebP. */
|
|
123
|
-
function imageTypeOf(bytes) {
|
|
124
|
-
const at = (offset, ...values) => values.every((value, index) => bytes[offset + index] === value);
|
|
125
|
-
if (at(0, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a))
|
|
126
|
-
return "image/png";
|
|
127
|
-
if (at(0, 0xff, 0xd8, 0xff))
|
|
128
|
-
return "image/jpeg";
|
|
129
|
-
if (at(0, 0x47, 0x49, 0x46, 0x38))
|
|
130
|
-
return "image/gif";
|
|
131
|
-
if (at(0, 0x52, 0x49, 0x46, 0x46) && at(8, 0x57, 0x45, 0x42, 0x50))
|
|
132
|
-
return "image/webp";
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
/** A path read may open as an image anywhere in the box: an absolute box path (not `~`, not a URL) whose extension is an
|
|
136
|
-
* image's. */
|
|
137
|
-
const boxImagePath = (path) => path.startsWith("/") && !path.startsWith("//") && IMAGE_EXTENSIONS[posix.extname(path).slice(1).toLowerCase()] !== undefined;
|
|
138
|
-
/** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
|
|
139
|
-
* each with its arguments, output and replay as pi ships it and its environment the box's, and the background tools
|
|
140
|
-
* (background.ts), each call a command in the box. A file tool's path stays in the box's work dir; bash's command is
|
|
141
|
-
* the box's own. */
|
|
142
|
-
export function codingSource(place, box) {
|
|
143
|
-
if (place.mode === "runner")
|
|
144
|
-
return { extension: CodingTools, tools: CodingTools.tools ?? [] };
|
|
145
|
-
if (!box)
|
|
146
|
-
throw new Error("a run whose place is a box needs its box for its coding tools");
|
|
147
|
-
const here = box.hostWork && writesHeld() ? boundFiles(box.hostWork) : undefined;
|
|
148
|
-
const boxed = (pis.tools ?? []).filter((tool) => PI_BOXED.includes(tool.name)).map((tool) => (tool.name === "bash" ? boundedBash(tool) : tool.name === "read" ? { ...tool, description: `${tool.description}${READ_IMAGE_SENTENCE}` } : tool));
|
|
149
|
-
const tools = asGivenRefusals([...boxed, ...backgroundTools()].map((tool) => ({
|
|
150
|
-
...tool,
|
|
151
|
-
execute: async (args, api, context) => {
|
|
152
|
-
// A file tool's path in the box's words, or refused as the confined tools refuse (refuseOutsideWorkspace): named
|
|
153
|
-
// by the path the call gave and no other, the box's work dir included.
|
|
154
|
-
const path = args?.path;
|
|
155
|
-
const inBox = typeof path === "string" ? boxPath(path, box.hostWork) : undefined;
|
|
156
|
-
// read opens an image anywhere in the box (a render in /tmp): read through the box itself, never on this machine,
|
|
157
|
-
// and only when the bytes are an image's; anything else outside work/ is refused as before.
|
|
158
|
-
if (tool.name === "read" && typeof path === "string" && inBox === undefined && boxImagePath(path)) {
|
|
159
|
-
const note = (summary) => api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary } })), context);
|
|
160
|
-
const bytes = await boxBytes((await box.env(context, note)), path, READ_IMAGE_MAX_BYTES + 1, context);
|
|
161
|
-
// Said as what it is: a path the box could not read (no such file, no permission), or bytes that are no image's.
|
|
162
|
-
if (!bytes)
|
|
163
|
-
throw new Error(`${path} could not be read in the box`);
|
|
164
|
-
const mimeType = imageTypeOf(bytes);
|
|
165
|
-
if (!mimeType)
|
|
166
|
-
throw new Error(`${path} is not an image`);
|
|
167
|
-
if (bytes.byteLength > READ_IMAGE_MAX_BYTES)
|
|
168
|
-
throw new Error(`${path} is an image over read's ${READ_IMAGE_MAX_BYTES} bytes: scale it down first (for example with ffmpeg in bash).`);
|
|
169
|
-
// A line naming it, then the image: an answer is never an empty text, on pi or on another harness (host-tools.ts).
|
|
170
|
-
return forModelBlocks([{ type: "text", text: `${path}: ${mimeType}, ${bytes.byteLength} bytes` }, { type: "image", data: Buffer.from(bytes).toString("base64"), mimeType }]);
|
|
171
|
-
}
|
|
172
|
-
if (typeof path === "string" && inBox === undefined)
|
|
173
|
-
refuseOutsideWorkspace(path);
|
|
174
|
-
const given = inBox === undefined ? args : { ...args, path: inBox };
|
|
175
|
-
// read, write and edit on this machine's work/, where the box binds it; no box is made for them. A box an earlier
|
|
176
|
-
// process left has its left commands killed first, so none of them changes work/ under these tools.
|
|
177
|
-
if (here && !SHELL_TOOLS.includes(tool.name) && (await box.bound?.()) === true) {
|
|
178
|
-
await box.leftEnded?.(context);
|
|
179
|
-
return withBoxNote(box, api.output, () => tool.execute(given, { ...api, env: here }, context).catch((error) => Promise.reject(withCause(error))));
|
|
180
|
-
}
|
|
181
|
-
// A row the box's wait writes goes on the run's root, as a host's phase (pi-durable-agent's timeline shows it).
|
|
182
|
-
const note = (summary) => api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary } })), context);
|
|
183
|
-
const env = await box.env(context, note);
|
|
184
|
-
return withBoxNote(box, api.output, () => tool.execute(given, { ...api, env: env }, context));
|
|
185
|
-
},
|
|
186
|
-
})));
|
|
187
|
-
// The permission gate (allow, ask, deny) wraps this source: the one call it takes, whichever of the two lands second.
|
|
188
|
-
return { extension: { ...pis, tools }, tools };
|
|
189
|
-
}
|
package/dist/computer-adb.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** adb's env: the host bash's PATH, and a HOME and a TMPDIR (paths only). Nothing else, whatever this process holds. */
|
|
2
|
-
export declare function adbEnv(dirs?: {
|
|
3
|
-
readonly home?: string;
|
|
4
|
-
readonly tmpdir?: string;
|
|
5
|
-
}): Readonly<Record<string, string>>;
|
|
6
|
-
/** The phone provider's adb: the computer library's adbCli at `path`, spawned from adbEnv() alone. */
|
|
7
|
-
export declare function phoneAdb<A>(adbCli: (path: string, options: {
|
|
8
|
-
readonly env: Readonly<Record<string, string>>;
|
|
9
|
-
}) => A, path: string, dirs?: {
|
|
10
|
-
readonly home?: string;
|
|
11
|
-
readonly tmpdir?: string;
|
|
12
|
-
}): A;
|
package/dist/computer-adb.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// The phone provider's adb, wherever serve builds that provider (the claim's computerForClaim and Settings → Computers'
|
|
2
|
-
// test): one helper both use. The computer library spawns adb from the env it is given, so adb is given a fixed, minimal
|
|
3
|
-
// env (PATH, HOME, TMPDIR), never this process's: no vendor key and no seal key reaches adb, as none reaches the host's
|
|
4
|
-
// bash (workspace/hands.ts shellEnv).
|
|
5
|
-
import { homedir, tmpdir } from "node:os";
|
|
6
|
-
import { shellEnv } from "./workspace/hands.js";
|
|
7
|
-
/** adb's env: the host bash's PATH, and a HOME and a TMPDIR (paths only). Nothing else, whatever this process holds. */
|
|
8
|
-
export function adbEnv(dirs = {}) {
|
|
9
|
-
return Object.freeze({ PATH: shellEnv().PATH, HOME: dirs.home ?? homedir(), TMPDIR: dirs.tmpdir ?? tmpdir() });
|
|
10
|
-
}
|
|
11
|
-
/** The phone provider's adb: the computer library's adbCli at `path`, spawned from adbEnv() alone. */
|
|
12
|
-
export function phoneAdb(adbCli, path, dirs = {}) {
|
|
13
|
-
return adbCli(path, { env: adbEnv(dirs) });
|
|
14
|
-
}
|