@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
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 +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +90 -8
- package/dist/archil-settings.js +150 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -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/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- 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 +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- 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/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- 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 +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- 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/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- 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/release-notes/agent.md +11 -0
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { releaseOlder, runLabels } from "@parcha/agentrun-computer";
|
|
1
|
+
import { isBrowserProvider, ownerFilter, releaseOlder, RUN_LABEL, runLabels } from "@parcha/agentrun-computer";
|
|
2
2
|
import { computerOfPlace } from "../computer-setting.js";
|
|
3
3
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
4
4
|
import { getSealedKey } from "../server-keys.js";
|
|
5
|
+
import { agentComputerOf, forgetAgentComputer, holdAgentComputer, keepAgentComputer, liveHolderOf, reconcileAgentComputer, serverIdOf } from "./agent-computer.js";
|
|
5
6
|
import { computerHold, heldHands } from "./computer-hold.js";
|
|
6
7
|
import { storeLedger } from "./computer-ledger.js";
|
|
7
8
|
import { providerKeys, resolveComputer } from "./resolve-computer.js";
|
|
@@ -27,13 +28,17 @@ function phonePlatform(machine, entry) {
|
|
|
27
28
|
const said = machine ?? entry?.capabilities.find((one) => one.kind === "android" || one.kind === "ios")?.kind;
|
|
28
29
|
return said === "ios" ? "ios" : "android";
|
|
29
30
|
}
|
|
30
|
-
/** The image `provider` made ready, when
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/** The image `provider` made ready, when its descriptor declares it prepares its image (`entry.prepareImage`): its
|
|
32
|
+
* prepareImage(), its recipe built when the engine lacks it or its image by name pulled, answering the tag to start
|
|
33
|
+
* from; undefined for any other provider, which starts from its spec's image. A provider whose descriptor declares it
|
|
34
|
+
* and that has none breaks the contract, in words. A failure is the provider's words. `onWait`: told once if the claim
|
|
35
|
+
* waits on a build or a pull. */
|
|
36
|
+
async function readyImage(entry, provider, signal, onWait) {
|
|
37
|
+
if (!entry.prepareImage)
|
|
35
38
|
return undefined;
|
|
36
|
-
|
|
39
|
+
if (provider.prepareImage === undefined)
|
|
40
|
+
throw new Error(`${entry.label}'s descriptor says it prepares its image, but its provider has no prepareImage()`);
|
|
41
|
+
const ready = await provider.prepareImage({ ...(signal ? { signal } : {}), ...(onWait ? { onWait } : {}) });
|
|
37
42
|
if (!ready.ok)
|
|
38
43
|
throw new Error(ready.error.message);
|
|
39
44
|
return ready.value;
|
|
@@ -58,9 +63,19 @@ const labelValue = (value) => value.replace(/[^A-Za-z0-9_.:-]+/g, "_").slice(0,
|
|
|
58
63
|
/** A provider failure as an error with the provider's words and code. */
|
|
59
64
|
const failed = (error) => Object.assign(new Error(error.message), { code: error.code });
|
|
60
65
|
/** A browser computer's provider as the run's browser tool opens its sessions through it (ClaimBrowser): nothing is made
|
|
61
|
-
* at the claim. A session's computer is made at the tool's call, under the run's labels (`spec`'s) and the tool's tag
|
|
62
|
-
*
|
|
63
|
-
|
|
66
|
+
* at the claim. A session's computer is made at the tool's call, under the run's labels (`spec`'s) and the tool's tag,
|
|
67
|
+
* with the session's own options (spec.browser) where the provider declares them (capabilities().browser); its release
|
|
68
|
+
* lets go of every one the tool left open. The claim's browser (the agent's computer) and the tool plane's vendor's
|
|
69
|
+
* (browser-computer.ts planeBrowser) are each one of these. */
|
|
70
|
+
export function claimBrowser(provider, spec) {
|
|
71
|
+
// A run's browser: the claim's spec always carries its lifetime (computerSpecOf); an agent's computer (owner) has none.
|
|
72
|
+
const lifetime = spec.lifetimeMs;
|
|
73
|
+
if (lifetime === undefined)
|
|
74
|
+
throw new TypeError("a run's browser needs lifetimeMs: the claim's spec carries none");
|
|
75
|
+
// A provider of kind browser that declares no session features is opened as one that ends its sessions on a wall clock
|
|
76
|
+
// and takes no option but a viewport.
|
|
77
|
+
const features = provider.capabilities().browser ?? { timeout: "wall-clock" };
|
|
78
|
+
const kept = isBrowserProvider(provider) ? provider.downloads : undefined;
|
|
64
79
|
const open = new Set();
|
|
65
80
|
const release = async (id) => {
|
|
66
81
|
const released = await provider.release({ id, name: id }, "delete");
|
|
@@ -68,13 +83,20 @@ function claimBrowser(provider, spec) {
|
|
|
68
83
|
throw failed(released.error);
|
|
69
84
|
open.delete(id);
|
|
70
85
|
};
|
|
86
|
+
const valueOf = async (result) => {
|
|
87
|
+
const answered = await result;
|
|
88
|
+
if (!answered.ok)
|
|
89
|
+
throw failed(answered.error);
|
|
90
|
+
return answered.value;
|
|
91
|
+
};
|
|
71
92
|
return {
|
|
72
93
|
browser: {
|
|
73
94
|
provider: provider.id,
|
|
74
|
-
maxLifetimeS: Math.floor(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
95
|
+
maxLifetimeS: Math.floor(lifetime / 1000),
|
|
96
|
+
features: structuredClone(features),
|
|
97
|
+
async open(tag, lifetimeS, browser, signal) {
|
|
98
|
+
const lifetimeMs = Math.min(lifetime, Math.max(1, Math.round(lifetimeS)) * 1000);
|
|
99
|
+
const created = await provider.create({ ...spec, lifetimeMs, labels: { ...spec.labels, [SESSION_TAG]: labelValue(tag) }, ...(browser ? { browser } : {}) }, signal ? { signal } : {});
|
|
78
100
|
if (!created.ok)
|
|
79
101
|
throw failed(created.error);
|
|
80
102
|
open.add(created.value.id);
|
|
@@ -86,8 +108,24 @@ function claimBrowser(provider, spec) {
|
|
|
86
108
|
throw failed(listed.error);
|
|
87
109
|
return listed.value.map((one) => one.ref.id);
|
|
88
110
|
},
|
|
111
|
+
async running(id, signal) {
|
|
112
|
+
const found = await provider.attach({ id }, signal ? { signal } : {});
|
|
113
|
+
if (found.ok)
|
|
114
|
+
return true;
|
|
115
|
+
if (found.error.code === "not_found" || found.error.code === "gone")
|
|
116
|
+
return false;
|
|
117
|
+
throw failed(found.error);
|
|
118
|
+
},
|
|
89
119
|
url: (id) => cdpUrlOf(provider, { id, name: id }),
|
|
90
120
|
close: release,
|
|
121
|
+
...(kept && features.downloads
|
|
122
|
+
? {
|
|
123
|
+
downloads: {
|
|
124
|
+
list: (id) => valueOf(kept.list({ id, name: id })),
|
|
125
|
+
read: (id, name, maxBytes) => valueOf(kept.read({ id, name: id }, name, maxBytes)),
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
: {}),
|
|
91
129
|
},
|
|
92
130
|
async release() {
|
|
93
131
|
for (const id of [...open])
|
|
@@ -122,6 +160,7 @@ async function providerLaunch(provider, claim, spec, signal) {
|
|
|
122
160
|
groups: hello.groups,
|
|
123
161
|
// What the machine says it is (a phone's android or ios): its live view's input platform.
|
|
124
162
|
machine: hello.kind,
|
|
163
|
+
hello,
|
|
125
164
|
client,
|
|
126
165
|
async readBack() {
|
|
127
166
|
const attached = await provider.attach({ id: ref.id });
|
|
@@ -137,9 +176,150 @@ async function providerLaunch(provider, claim, spec, signal) {
|
|
|
137
176
|
},
|
|
138
177
|
};
|
|
139
178
|
}
|
|
179
|
+
/** A run state in which the run still holds what it claimed. */
|
|
180
|
+
const LIVE_RUN = new Set(["queued", "running", "parked"]);
|
|
181
|
+
/**
|
|
182
|
+
* The agent's own computer for this claim (a persistent setting): the one its owner's listing finds, attached under this
|
|
183
|
+
* claim, else one made with `spec` (its owner, no lifetime). The record this server keeps names it, held by this run. A
|
|
184
|
+
* computer whose listing names another run that is still going is refused in words naming that run; one a run that ended
|
|
185
|
+
* left running is taken over. Its release detaches it (Orgo's suspend, say), keeping its state for the agent's next run;
|
|
186
|
+
* then the agent's record is reconciled, so an agent that was archived or turned persistent off while the run went has
|
|
187
|
+
* its computer deleted.
|
|
188
|
+
*/
|
|
189
|
+
async function ownedLaunch(provider, claim, spec, context, signal) {
|
|
190
|
+
const { store, agentId } = context;
|
|
191
|
+
// One run at a time, taken in the store before anything is listed or made (agent-computer.ts holdAgentComputer): two
|
|
192
|
+
// runs of the agent that claim at once never both make a computer. With no run rows to read, a holder is still going.
|
|
193
|
+
// The hold is this claim's (its epoch): a later claim of the run takes it over, and this one's end then does nothing.
|
|
194
|
+
const hold = await holdAgentComputer(store, agentId, claim.runId, liveHolderOf(store), { epoch: claim.epoch });
|
|
195
|
+
let launched;
|
|
196
|
+
try {
|
|
197
|
+
launched = await ownedStart(provider, claim, spec, context, hold, signal);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
await hold.letGo().catch(() => undefined);
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
...launched,
|
|
205
|
+
async release() {
|
|
206
|
+
try {
|
|
207
|
+
await launched.release();
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
await hold.letGo();
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** The owned launch once the run holds the agent's computer (ownedLaunch): found and attached, or made; connected. */
|
|
216
|
+
async function ownedStart(provider, claim, spec, context, hold, signal) {
|
|
217
|
+
const call = signal ? { signal } : {};
|
|
218
|
+
const { store, agentId, note } = context;
|
|
219
|
+
const older = await releaseOlder(provider, claim.runId, claim.epoch, call);
|
|
220
|
+
if (!older.ok)
|
|
221
|
+
throw new Error(older.error.message);
|
|
222
|
+
const listed = await provider.list(ownerFilter(context.owner), call);
|
|
223
|
+
if (!listed.ok)
|
|
224
|
+
throw new Error(listed.error.message);
|
|
225
|
+
const record = await agentComputerOf(store, agentId);
|
|
226
|
+
const found = listed.value.find((info) => info.ref.id === record?.id) ?? listed.value[0];
|
|
227
|
+
let ref;
|
|
228
|
+
/** Whether this claim made the computer, or attached the one the agent had. */
|
|
229
|
+
let made;
|
|
230
|
+
if (found) {
|
|
231
|
+
const holder = found.labels[RUN_LABEL];
|
|
232
|
+
if (found.state === "running" && holder !== undefined && holder !== claim.runId) {
|
|
233
|
+
const row = store.runs ? await store.runs.get(holder) : undefined;
|
|
234
|
+
// With no run rows to read, a holder is taken as still going: never two runs on one agent's computer.
|
|
235
|
+
if (!store.runs || (row !== undefined && LIVE_RUN.has(row.state))) {
|
|
236
|
+
throw new Error(`this agent's computer ${found.ref.name} is held by run ${holder}, which is still ${row?.state ?? "going"}: an agent's own computer serves one run at a time. Start this run again once that one ends`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const attached = await provider.attach({ id: found.ref.id }, { claim: { run: claim.runId, epoch: claim.epoch }, ...call });
|
|
240
|
+
if (!attached.ok)
|
|
241
|
+
throw new Error(attached.error.message);
|
|
242
|
+
ref = { id: found.ref.id, name: found.ref.name };
|
|
243
|
+
made = false;
|
|
244
|
+
note(`Attached this agent's computer ${ref.name}, kept from its last run.`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const created = await provider.create(spec, call);
|
|
248
|
+
if (!created.ok)
|
|
249
|
+
throw new Error(created.error.message);
|
|
250
|
+
ref = { id: created.value.id, name: created.value.name };
|
|
251
|
+
made = true;
|
|
252
|
+
note(record
|
|
253
|
+
? `This agent's computer ${record.name} is gone (deleted outside this server): made a new one, ${ref.name}, which later runs get back.`
|
|
254
|
+
: `Made this agent's own computer ${ref.name}: later runs get it back.`);
|
|
255
|
+
}
|
|
256
|
+
// The computer is acquired: its cleanup is in place before anything else is awaited, and whatever fails from here (the
|
|
257
|
+
// hold lost to a later claim included) lets go of exactly what this claim acquired.
|
|
258
|
+
const computer = { provider: context.provider, image: context.image, ...ref };
|
|
259
|
+
// The hold is marked letting go first, so no claim takes it over while the computer is detached. A claim that took it
|
|
260
|
+
// over since (a later claim of this run, resumed, or another run once this one's row ended) has the computer now: it
|
|
261
|
+
// is left as it is.
|
|
262
|
+
const detach = async () => {
|
|
263
|
+
if (!(await hold.releasing()))
|
|
264
|
+
return;
|
|
265
|
+
const released = await provider.release(ref, "detach");
|
|
266
|
+
if (!released.ok)
|
|
267
|
+
throw new Error(released.error.message);
|
|
268
|
+
await keepAgentComputer(store, agentId, computer, "detached");
|
|
269
|
+
await reconcileAgentComputer(store, agentId, async () => provider, hold);
|
|
270
|
+
};
|
|
271
|
+
// A launch that fails: a computer this claim made is deleted under its claim, so one a later claim has taken since (a
|
|
272
|
+
// resume whose owner's listing found it) is left to that claim, and the record goes where it names it; one it attached
|
|
273
|
+
// is detached as at the run's end, where the hold is still this claim's. Throws `error`, with what was let go.
|
|
274
|
+
const abandon = async (error) => {
|
|
275
|
+
const words = error instanceof Error ? error.message : String(error);
|
|
276
|
+
if (!made) {
|
|
277
|
+
const undone = await detach().then(() => undefined, (failed) => (failed instanceof Error ? failed.message : String(failed)));
|
|
278
|
+
throw new Error(undone === undefined ? words : `${words}; and ${ref.name} could not be detached: ${undone}`);
|
|
279
|
+
}
|
|
280
|
+
const deleted = await provider.release(ref, "delete", { claim: { run: claim.runId, epoch: claim.epoch } });
|
|
281
|
+
if (deleted.ok)
|
|
282
|
+
await forgetAgentComputer(store, agentId, ref.id).catch(() => undefined);
|
|
283
|
+
throw new Error(`${words}; ${ref.name}, which this claim made, ${deleted.ok ? "was deleted" : `was not deleted (${deleted.error.message})`}`);
|
|
284
|
+
};
|
|
285
|
+
let connected;
|
|
286
|
+
try {
|
|
287
|
+
// A later claim of this run (or another run, this one's row ended) that took the hold over while this one attached
|
|
288
|
+
// or made the computer has it now: its record is that claim's to write.
|
|
289
|
+
if (!(await hold.holds()))
|
|
290
|
+
throw new Error(`fenced: this agent's computer ${ref.name} was taken over by a later claim while run ${claim.runId}'s claim at epoch ${claim.epoch} ${made ? "made" : "attached"} it; it is left to that claim`);
|
|
291
|
+
await keepAgentComputer(store, agentId, computer, "held", { run: claim.runId });
|
|
292
|
+
const opened = await provider.connect(ref);
|
|
293
|
+
if (!opened.ok)
|
|
294
|
+
throw new Error(opened.error.message);
|
|
295
|
+
connected = opened.value;
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
return abandon(error);
|
|
299
|
+
}
|
|
300
|
+
const { client, hello } = connected;
|
|
301
|
+
return {
|
|
302
|
+
id: ref.id,
|
|
303
|
+
groups: hello.groups,
|
|
304
|
+
machine: hello.kind,
|
|
305
|
+
hello,
|
|
306
|
+
client,
|
|
307
|
+
// An agent's own computer mounts no run's folder (resolve-computer.ts refuses one that would).
|
|
308
|
+
async readBack() {
|
|
309
|
+
return { ok: false, error: { code: "not_found", message: "an agent's own computer mounts no run's folder" } };
|
|
310
|
+
},
|
|
311
|
+
...(watching(provider) ? { watch: (signal) => watching(provider).watch(ref, { signal }) } : {}),
|
|
312
|
+
async release() {
|
|
313
|
+
await connected.close().catch(() => undefined);
|
|
314
|
+
await detach();
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
140
318
|
/** The run's computer for this claim, started and registered; `{ computer: undefined }` for none. Throws with code
|
|
141
319
|
* computer_unavailable and the server's words when the agent's computer cannot be had here. */
|
|
142
|
-
export async function computerForClaim(launch,
|
|
320
|
+
export async function computerForClaim(launch,
|
|
321
|
+
// `settings` and `runs`: the agent's own computer's record and its holder's run row, for a persistent setting alone.
|
|
322
|
+
store, deps) {
|
|
143
323
|
const table = deps.keyTable ?? KEY_TABLE;
|
|
144
324
|
/** The computer this claim started (one per claim): its ref id tags its live view, and its watch feeds it. */
|
|
145
325
|
let made;
|
|
@@ -149,9 +329,12 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
149
329
|
keysOf: providerKeys(deps.kinds, deps.keyOf ?? (async (name) => (deps.sealKey ? await getSealedKey(store, deps.sealKey, name) : undefined))),
|
|
150
330
|
answers: deps.answers ?? (async () => false),
|
|
151
331
|
...(deps.daemon ? { daemon: deps.daemon } : {}),
|
|
152
|
-
async launch(entry, { kind, keys, mount, gpu, signal }) {
|
|
332
|
+
async launch(entry, { kind, keys, configuration, mount, gpu, persistent, signal }) {
|
|
333
|
+
// An agent's own computer needs its agent and the store's record of it; the server's launch (--faux) keeps none.
|
|
334
|
+
if (persistent && (deps.launch || launch.agentId === undefined || store.settings === undefined))
|
|
335
|
+
throw new Error("this run can't keep its agent's own computer here: start it again with persistent off");
|
|
153
336
|
if (deps.launch) {
|
|
154
|
-
const own = await deps.launch(entry, { kind, keys, ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}), ...(signal ? { signal } : {}) });
|
|
337
|
+
const own = await deps.launch(entry, { kind, keys, configuration, ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}), ...(signal ? { signal } : {}) });
|
|
155
338
|
const ownWatch = own.watch;
|
|
156
339
|
made = { id: own.id, ...(ownWatch ? { watch: ownWatch } : {}) };
|
|
157
340
|
madeBy = entry;
|
|
@@ -163,7 +346,9 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
163
346
|
const options = providerOptions(entry.id, keys, deps.settings ?? {}, table);
|
|
164
347
|
if (!options.ok)
|
|
165
348
|
throw new Error(options.error.message);
|
|
166
|
-
|
|
349
|
+
// The configuration the setting selected is built by its own create() options (Orgo's Windows: { os: "windows" }),
|
|
350
|
+
// beside the keys'.
|
|
351
|
+
const provider = await make({ ...options.options, ...configuration.options }, { ledger: storeLedger(store.computerLedger, entry.id), ...(launch.boxAllow === undefined ? {} : { boxAllow: launch.boxAllow }) });
|
|
167
352
|
// What this provider makes, as it declares it: the spec asks for one of its networks, within its lifetime
|
|
168
353
|
// (computer-deps.ts computerSpecOf).
|
|
169
354
|
const { network: networks, maxLifetimeMs } = provider.capabilities();
|
|
@@ -173,11 +358,13 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
173
358
|
...(networks ? { networks } : {}),
|
|
174
359
|
...(typeof maxLifetimeMs === "number" ? { maxLifetimeMs } : {}),
|
|
175
360
|
};
|
|
176
|
-
// A provider that
|
|
177
|
-
// pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
|
|
178
|
-
// run of it unbuilt would be refused.
|
|
179
|
-
|
|
180
|
-
const
|
|
361
|
+
// A provider that declares it prepares its own image (its prepareImage(): its recipe built when the engine lacks it,
|
|
362
|
+
// an image by name pulled) does so first, and the computer starts from the tag it answers: the recipe's tag is in no
|
|
363
|
+
// registry, so a run of it unbuilt would be refused. The spec comes first, so a setting it refuses builds nothing. A
|
|
364
|
+
// configuration that names its image starts from it, else the kind's default.
|
|
365
|
+
const asked = deps.spec(entry, kind, run, configuration.image);
|
|
366
|
+
const ready = await readyImage(entry, provider, signal, deps.onImageWait);
|
|
367
|
+
const spec = { ...asked, ...(ready ? { image: ready } : {}), labels: runLabels(launch.runId, launch.epoch), ...(mount ? { mount } : {}), ...(gpu ? { gpu } : {}) };
|
|
181
368
|
// A browser makes nothing here: the run's browser tool opens each session through it, so a session lives (and is
|
|
182
369
|
// booked) only while the tool holds it.
|
|
183
370
|
if (kind === "browser") {
|
|
@@ -189,9 +376,27 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
189
376
|
madeBy = entry;
|
|
190
377
|
return { id: entry.id, groups: ["cdp"], browser: opened.browser, release: opened.release };
|
|
191
378
|
}
|
|
192
|
-
|
|
379
|
+
let launched;
|
|
380
|
+
if (persistent) {
|
|
381
|
+
// The agent's own: its owner (this server and the agent), and no run deadline (it outlives the run).
|
|
382
|
+
const owner = { agent: launch.agentId, server: await serverIdOf({ settings: store.settings }) };
|
|
383
|
+
const { lifetimeMs: _, ...owned } = spec;
|
|
384
|
+
launched = await ownedLaunch(provider, launch, { ...owned, owner }, {
|
|
385
|
+
store: { settings: store.settings, agents: store.agents, ...(store.runs ? { runs: store.runs } : {}) },
|
|
386
|
+
agentId: launch.agentId,
|
|
387
|
+
owner,
|
|
388
|
+
provider: entry.id,
|
|
389
|
+
image: configuration.image,
|
|
390
|
+
note: deps.onComputerNote ?? (() => { }),
|
|
391
|
+
}, signal);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
launched = await providerLaunch(provider, launch, spec, signal);
|
|
395
|
+
}
|
|
193
396
|
made = { id: launched.id, machine: launched.machine, ...(launched.watch ? { watch: launched.watch } : {}) };
|
|
194
397
|
madeBy = entry;
|
|
398
|
+
const { os, osVersion, arch } = launched.hello;
|
|
399
|
+
deps.onConnected?.({ provider: entry.label, kind: kind, hello: { os, ...(osVersion ? { osVersion } : {}), arch } });
|
|
195
400
|
return launched;
|
|
196
401
|
},
|
|
197
402
|
};
|
|
@@ -203,6 +408,10 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
203
408
|
const refusedKind = deps.refuseKind?.(resolved.kind);
|
|
204
409
|
if (refusedKind)
|
|
205
410
|
throw unavailable(refusedKind);
|
|
411
|
+
// The program its provider runs on this machine (the phone's adb) is checked before anything is rented.
|
|
412
|
+
const hostRefusal = resolved.provider ? deps.hostWhy?.(resolved.provider) : undefined;
|
|
413
|
+
if (hostRefusal)
|
|
414
|
+
throw unavailable(`This agent's computer is a ${resolved.kind} on ${resolved.provider}, and this runner cannot run it: ${hostRefusal.replace(/[.!?]+$/, "")}.`);
|
|
206
415
|
// The run's mount credential (Mode 2), minted when the mount was made: removed with the computer, or at once when the
|
|
207
416
|
// start fails after it was minted.
|
|
208
417
|
const revoke = async () => { await deps.revokeMount?.(); };
|
|
@@ -220,6 +429,7 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
220
429
|
// vendor's URL reaches a person), opened under this claim. A fenced open is a lost claim. The release ends the hold.
|
|
221
430
|
let endHold = () => { };
|
|
222
431
|
let hold;
|
|
432
|
+
let held;
|
|
223
433
|
let view;
|
|
224
434
|
if (computer && (computer.kind === "desktop" || computer.kind === "phone")) {
|
|
225
435
|
const theHold = computerHold();
|
|
@@ -240,11 +450,13 @@ export async function computerForClaim(launch, store, deps) {
|
|
|
240
450
|
// goes; the composer's `ended` ViewEnd maps onto it), the agent's open ask is let go at once, and nothing is taken after.
|
|
241
451
|
endHold = () => theHold.close();
|
|
242
452
|
hold = (ports) => heldHands(ports, theHold);
|
|
453
|
+
held = { kind: computer.kind, hold: theHold };
|
|
243
454
|
}
|
|
244
455
|
let released;
|
|
245
456
|
return {
|
|
246
457
|
...(computer ? { computer } : {}),
|
|
247
458
|
...(hold ? { hold } : {}),
|
|
459
|
+
...(held ? { held } : {}),
|
|
248
460
|
release: (why = "released") => (released ??= (async () => {
|
|
249
461
|
await Promise.resolve(view?.close(why)).catch(() => undefined);
|
|
250
462
|
endHold();
|
|
@@ -10,8 +10,9 @@ export declare const JANITOR_CLOSE_MS = 5000;
|
|
|
10
10
|
* is swept, so a stuck vendor (a Docker command has no timeout of its own) never stops the others or later sweeps. */
|
|
11
11
|
export declare const JANITOR_PROVIDER_MS: number;
|
|
12
12
|
export interface JanitorDeps {
|
|
13
|
-
/** The store: whose runs a computer's run label names, and the phone provider's ledger
|
|
14
|
-
|
|
13
|
+
/** The store: whose runs a computer's run label names, and the phone provider's ledger; with `settings` and `agents`,
|
|
14
|
+
* this server's id and its agents, whose own computers it then sweeps by their owner. */
|
|
15
|
+
readonly store: Pick<Store, "runs" | "computerLedger"> & Partial<Pick<Store, "settings" | "agents">>;
|
|
15
16
|
/** The run's computers as the runner composed them (computer-deps.ts computerDepsFrom): the registry, the provider
|
|
16
17
|
* makers and the key reader. */
|
|
17
18
|
readonly computers: Pick<ComputerDeps, "kinds" | "providers" | "keyOf"> & {
|
|
@@ -18,9 +18,14 @@
|
|
|
18
18
|
// start asks for it (the CLI's runner and the runner subcommand), never under --faux, and never two sweeps at once. Its
|
|
19
19
|
// close cuts a sweep under way and waits for it on a bound of its own (JANITOR_CLOSE_MS), so a stuck vendor call never
|
|
20
20
|
// holds up the runner's stop.
|
|
21
|
-
|
|
21
|
+
//
|
|
22
|
+
// An agent's own computer (a persistent setting, agent-computer.ts) is this server's when its owner names this server's
|
|
23
|
+
// id, never by its run: it goes only when its agent no longer wants it (ownerGoneOf: gone, archived, or no longer
|
|
24
|
+
// persistent on that provider), never by a deadline. Without the store's settings and agents, none is this server's.
|
|
25
|
+
import { epochOf, ok, ownerOf, RUN_HASH_LABEL, RUN_LABEL, runHash, sweep } from "@parcha/agentrun-computer";
|
|
22
26
|
import { KEY_TABLE, providerOptions } from "../computer-keys.js";
|
|
23
27
|
import { FAUX_ENV } from "../model.js";
|
|
28
|
+
import { deleteUnderHold, ownerGoneOf, serverIdOf, wantsOn } from "./agent-computer.js";
|
|
24
29
|
import { storeLedger } from "./computer-ledger.js";
|
|
25
30
|
import { providerKeys } from "./resolve-computer.js";
|
|
26
31
|
/** How often the janitor sweeps after its first sweep at the runner's start. */
|
|
@@ -35,8 +40,15 @@ const runsByHash = (store) => {
|
|
|
35
40
|
return () => (read ??= store.runs.list({}).then((rows) => new Map(rows.map((row) => [runHash(row.id), row.id]))));
|
|
36
41
|
};
|
|
37
42
|
/** Whether a listed computer is this server's and no claim holds it: its run (by its label, or its hash's) is in this
|
|
38
|
-
* store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's.
|
|
39
|
-
|
|
43
|
+
* store, and no claim holds the run now (by the store's clock), or one holds it at a later epoch than the computer's.
|
|
44
|
+
* An agent's own computer (owned, or an owner label, readable or not) is this server's when its owner names
|
|
45
|
+
* `serverId`, whatever its run: the sweep's ownerGone then decides. */
|
|
46
|
+
async function sweepable(store, info, byHash, serverId) {
|
|
47
|
+
const { labels } = info;
|
|
48
|
+
const label = ownerOf(labels);
|
|
49
|
+
const owner = info.owner ?? (label.ok ? label.value : undefined);
|
|
50
|
+
if (info.owned === true || owner !== undefined || !label.ok)
|
|
51
|
+
return serverId !== undefined && owner?.server === serverId;
|
|
40
52
|
const named = labels[RUN_LABEL];
|
|
41
53
|
const hash = labels[RUN_HASH_LABEL];
|
|
42
54
|
const runId = typeof named === "string" && named !== "" ? named : typeof hash === "string" && hash !== "" ? (await byHash()).get(hash) : undefined;
|
|
@@ -55,7 +67,11 @@ async function sweepable(store, labels, byHash) {
|
|
|
55
67
|
}
|
|
56
68
|
/** `provider` as the sweep sees it: its list cut to this server's computers that no claim holds, and no leftovers pass.
|
|
57
69
|
* Each call goes to the provider itself, so its own state is used as it is. */
|
|
58
|
-
function thisServers(provider, store, byHash) {
|
|
70
|
+
function thisServers(provider, store, byHash, serverId) {
|
|
71
|
+
// The agents' own computers the list kept, by id: their delete goes under the agent's hold (deleteUnderHold), which
|
|
72
|
+
// also clears the agent's record of it, so its view no longer shows it deleting.
|
|
73
|
+
const ownedBy = new Map();
|
|
74
|
+
const { settings, agents } = store;
|
|
59
75
|
return {
|
|
60
76
|
id: provider.id,
|
|
61
77
|
version: provider.version,
|
|
@@ -65,15 +81,29 @@ function thisServers(provider, store, byHash) {
|
|
|
65
81
|
attach: (target, context) => provider.attach(target, context),
|
|
66
82
|
network: (ref, policy, context) => provider.network(ref, policy, context),
|
|
67
83
|
connect: (ref) => provider.connect(ref),
|
|
68
|
-
release
|
|
84
|
+
release(ref, how, context) {
|
|
85
|
+
const agent = ownedBy.get(ref.id);
|
|
86
|
+
if (how !== "delete" || agent === undefined || settings === undefined)
|
|
87
|
+
return provider.release(ref, how, context);
|
|
88
|
+
// Asked again under the hold: the agent may want it back since ownerGone was read (this server's owners carry no
|
|
89
|
+
// idle TTL, so that is the one reason the sweep deletes one).
|
|
90
|
+
const due = async () => !agents || !(await wantsOn({ agents }, agent, provider.id));
|
|
91
|
+
return deleteUnderHold({ settings, runs: store.runs }, agent, ref.id, due, () => provider.release(ref, how, context));
|
|
92
|
+
},
|
|
69
93
|
async list(labels, context) {
|
|
70
94
|
const listed = await provider.list(labels, context);
|
|
71
95
|
if (!listed.ok)
|
|
72
96
|
return listed;
|
|
73
97
|
const kept = [];
|
|
74
|
-
for (const info of listed.value)
|
|
75
|
-
if (await sweepable(store, info
|
|
76
|
-
|
|
98
|
+
for (const info of listed.value) {
|
|
99
|
+
if (!(await sweepable(store, info, byHash, serverId)))
|
|
100
|
+
continue;
|
|
101
|
+
const label = ownerOf(info.labels);
|
|
102
|
+
const owner = info.owner ?? (label.ok ? label.value : undefined);
|
|
103
|
+
if (owner !== undefined)
|
|
104
|
+
ownedBy.set(info.ref.id, owner.agent);
|
|
105
|
+
kept.push(info);
|
|
106
|
+
}
|
|
77
107
|
return ok(kept);
|
|
78
108
|
},
|
|
79
109
|
};
|
|
@@ -103,6 +133,9 @@ export async function sweepServerComputers(deps, signal) {
|
|
|
103
133
|
const at = (deps.now ?? Date.now)();
|
|
104
134
|
const keysOf = providerKeys(computers.kinds, computers.keyOf ?? (async () => undefined));
|
|
105
135
|
const byHash = runsByHash(store);
|
|
136
|
+
// This server's id and its agents: its agents' own computers are swept by their owner (ownerGoneOf).
|
|
137
|
+
const { settings, agents } = store;
|
|
138
|
+
const serverId = settings && agents ? await serverIdOf({ settings }) : undefined;
|
|
106
139
|
const out = [];
|
|
107
140
|
for (const entry of computers.kinds.PROVIDERS) {
|
|
108
141
|
if (signal?.aborted)
|
|
@@ -120,7 +153,8 @@ export async function sweepServerComputers(deps, signal) {
|
|
|
120
153
|
// A vendor that ends its own computers needs no janitor.
|
|
121
154
|
if (provider.capabilities().lifetime !== "janitor")
|
|
122
155
|
continue;
|
|
123
|
-
|
|
156
|
+
const ownerGone = serverId !== undefined && settings && agents ? ownerGoneOf({ agents, settings, runs: store.runs }, serverId, entry.id) : undefined;
|
|
157
|
+
out.push({ provider: entry.id, swept: await bounded(deps.providerMs ?? JANITOR_PROVIDER_MS, signal, (cut) => sweep(thisServers(provider, store, byHash, serverId), { now: new Date(at), signal: cut, ...(ownerGone ? { ownerGone } : {}) })) });
|
|
124
158
|
}
|
|
125
159
|
catch (error) {
|
|
126
160
|
out.push({ provider: entry.id, swept: { ok: false, error: { code: "refused", message: error instanceof Error ? error.message : String(error) } } });
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import type { ProviderOptions } from "@parcha/agentrun-computer";
|
|
2
1
|
import type { ComputerLedger } from "../store/store.js";
|
|
3
|
-
/** The phone provider's `ledger` option, and one entry of it, as the computer package's provider registry types them. */
|
|
4
|
-
export type PhoneLedger = NonNullable<ProviderOptions<"phone-harness">["ledger"]>;
|
|
5
|
-
export type PhoneLedgerEntry = Awaited<ReturnType<PhoneLedger["list"]>>[number];
|
|
6
2
|
/** A session's entry as a provider keeps it: its id, our labels, and the provider's own fields. */
|
|
7
3
|
export interface LedgerEntry {
|
|
8
4
|
id: string;
|
|
9
5
|
labels: Record<string, string>;
|
|
10
6
|
}
|
|
11
|
-
/** One provider's ledger, in the shape
|
|
7
|
+
/** One provider's ledger, in the shape a descriptor's `ledger` option takes: put, get, list, remove and swap of its entries. */
|
|
12
8
|
export interface ProviderLedger<E extends LedgerEntry = LedgerEntry> {
|
|
13
9
|
put(entry: E): Promise<void>;
|
|
14
10
|
get(id: string): Promise<E | undefined>;
|
|
15
11
|
list(): Promise<E[]>;
|
|
16
12
|
remove(id: string): Promise<void>;
|
|
13
|
+
/** entry put in place of `was` only while the kept entry is still `was` as read, in one statement: whether it was put. */
|
|
14
|
+
swap(was: E, entry: E): Promise<boolean>;
|
|
17
15
|
}
|
|
18
16
|
/** `provider`'s ledger over the store's computer ledger. */
|
|
19
17
|
export declare function storeLedger<E extends LedgerEntry = LedgerEntry>(ledger: ComputerLedger, provider: string): ProviderLedger<E>;
|
|
20
|
-
/** The phone provider's ledger over the store's computer ledger: what its create() takes as `ledger`. Typed by the
|
|
21
|
-
* provider's own option, so a change to its ledger interface fails this build. */
|
|
22
|
-
export declare const phoneLedger: (ledger: ComputerLedger) => PhoneLedger;
|
|
@@ -12,8 +12,12 @@ export function storeLedger(ledger, provider) {
|
|
|
12
12
|
},
|
|
13
13
|
list: async () => (await ledger.list(provider)).map((row) => entryOf(row)),
|
|
14
14
|
remove: (id) => ledger.remove(provider, id),
|
|
15
|
+
swap: async (was, entry) => {
|
|
16
|
+
const { id: _wasId, labels: wasLabels, ...wasDetail } = was;
|
|
17
|
+
const { id, labels, ...detail } = entry;
|
|
18
|
+
if (was.id !== id)
|
|
19
|
+
return false;
|
|
20
|
+
return ledger.swap(provider, id, { labels: wasLabels, detail: wasDetail }, labels, detail);
|
|
21
|
+
},
|
|
15
22
|
};
|
|
16
23
|
}
|
|
17
|
-
/** The phone provider's ledger over the store's computer ledger: what its create() takes as `ledger`. Typed by the
|
|
18
|
-
* provider's own option, so a change to its ledger interface fails this build. */
|
|
19
|
-
export const phoneLedger = (ledger) => storeLedger(ledger, "phone-harness");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ComputerProvider } from "@parcha/agentrun-computer";
|
|
1
|
+
import { type ComputerProvider, type ProviderEntry } from "@parcha/agentrun-computer";
|
|
2
2
|
import type { ProviderFactories } from "../computer-keys.js";
|
|
3
3
|
import type { ProviderMakers } from "./computer-for-claim.js";
|
|
4
4
|
/** How a provider is built from its id and options: the computer package's providerFor, or a test's stand-in. `claim`:
|
|
@@ -10,7 +10,9 @@ export type ProviderLoad = (id: string, options: Record<string, unknown>, claim?
|
|
|
10
10
|
/** Settings → Computers' factories (createComputerRoutes' `factories`, its account test) from the same makers, so serve
|
|
11
11
|
* builds a provider in one place: each made with its options and `ledgerOf` its id's ledger. */
|
|
12
12
|
export declare function computerProviderFactories(makers: ProviderMakers, ledgerOf: (id: string) => unknown): ProviderFactories;
|
|
13
|
-
/** Every provider the computer package
|
|
14
|
-
|
|
13
|
+
/** Every provider in `entries` (the computer package's PROVIDERS, each from its descriptor), made through `load`
|
|
14
|
+
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one. */
|
|
15
|
+
export declare function computerProviderMakers({ load, entries }?: {
|
|
15
16
|
readonly load?: ProviderLoad;
|
|
17
|
+
readonly entries?: readonly Pick<ProviderEntry, "id" | "ledger">[];
|
|
16
18
|
}): ProviderMakers;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
// The provider makers computerForClaim is handed at the claim (its `providers`): each
|
|
2
|
-
//
|
|
3
|
-
// names), and nothing else.
|
|
4
|
-
//
|
|
5
|
-
|
|
1
|
+
// The provider makers computerForClaim is handed at the claim (its `providers`): each provider the computer package
|
|
2
|
+
// declares, built by its providerFor from the options its saved keys fill (computer-keys.ts providerOptions, by its
|
|
3
|
+
// descriptor's key names), and nothing else. A provider whose descriptor declares a ledger (its sessions carry no labels
|
|
4
|
+
// of their own) is given the store's computer ledger, as the option its descriptor names. No key reaches a provider any
|
|
5
|
+
// other way, and nothing here reads the environment or names a vendor.
|
|
6
|
+
import { PROVIDERS, providerFor } from "@parcha/agentrun-computer";
|
|
6
7
|
/** Settings → Computers' factories (createComputerRoutes' `factories`, its account test) from the same makers, so serve
|
|
7
8
|
* builds a provider in one place: each made with its options and `ledgerOf` its id's ledger. */
|
|
8
9
|
export function computerProviderFactories(makers, ledgerOf) {
|
|
9
10
|
return Object.fromEntries(Object.entries(makers).map(([id, make]) => [id, (options) => make(options, { ledger: ledgerOf(id) })]));
|
|
10
11
|
}
|
|
11
|
-
/** Every provider the computer package
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/** Every provider in `entries` (the computer package's PROVIDERS, each from its descriptor), made through `load`
|
|
13
|
+
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one. */
|
|
14
|
+
export function computerProviderMakers({ load = providerFor, entries = PROVIDERS } = {}) {
|
|
15
|
+
return Object.fromEntries(entries.map(({ id, ledger }) => [
|
|
14
16
|
id,
|
|
15
|
-
(options, extras) => load(id, { ...options, ...(
|
|
17
|
+
(options, extras) => load(id, { ...options, ...(ledger === undefined ? {} : { [ledger.option]: extras.ledger }) }, extras.boxAllow === undefined ? {} : { boxAllow: extras.boxAllow }),
|
|
16
18
|
]));
|
|
17
19
|
}
|
|
@@ -17,9 +17,12 @@ export declare function shellEnv(options?: {
|
|
|
17
17
|
* output goes to its log (the "log" stream is what a read reads); a listing is read to its last page. */
|
|
18
18
|
export declare function processesOf(processes: Processes): KernelProcesses;
|
|
19
19
|
/** The run's hands over `workspace`: its files, its shell with `env` for at most `maxExecS` a command, and the
|
|
20
|
-
* computer's processes when it has one (`processes`, the attached Workspace's)
|
|
20
|
+
* computer's processes when it has one (`processes`, the attached Workspace's); `prelude`, shell text each command runs
|
|
21
|
+
* after (a bash policy's). */
|
|
21
22
|
export declare function handsOf(workspace: Workspace, options: {
|
|
22
23
|
readonly maxExecS: number;
|
|
23
24
|
readonly env: Readonly<Record<string, string>>;
|
|
24
|
-
readonly processes?: Processes;
|
|
25
|
+
readonly processes?: Processes; /** Shell text run before each command (a bash policy's, bash-read-only.ts policyPrelude). */
|
|
26
|
+
readonly prelude?: string; /** Each command's network (a bash policy's on Archil's exec: run-tools.ts). */
|
|
27
|
+
readonly network?: "deny";
|
|
25
28
|
}): Hands;
|
package/dist/workspace/hands.js
CHANGED
|
@@ -71,7 +71,8 @@ export function processesOf(processes) {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
/** The run's hands over `workspace`: its files, its shell with `env` for at most `maxExecS` a command, and the
|
|
74
|
-
* computer's processes when it has one (`processes`, the attached Workspace's)
|
|
74
|
+
* computer's processes when it has one (`processes`, the attached Workspace's); `prelude`, shell text each command runs
|
|
75
|
+
* after (a bash policy's). */
|
|
75
76
|
export function handsOf(workspace, options) {
|
|
76
77
|
return {
|
|
77
78
|
maxExecS: options.maxExecS,
|
|
@@ -100,8 +101,8 @@ export function handsOf(workspace, options) {
|
|
|
100
101
|
if (data !== "" && onOutput)
|
|
101
102
|
onOutput({ stream, data });
|
|
102
103
|
};
|
|
103
|
-
const run = (shell) => workspace.exec([shell, "-c", command], {
|
|
104
|
-
env: options.env, timeoutMs, maxOutput: 0, ...(signal ? { signal } : {}),
|
|
104
|
+
const run = (shell) => workspace.exec([shell, "-c", `${options.prelude ?? ""}${command}`], {
|
|
105
|
+
env: options.env, timeoutMs, maxOutput: 0, ...(signal ? { signal } : {}), ...(options.network ? { network: options.network } : {}),
|
|
105
106
|
onOutput: ({ stream, data }) => emit(stream, decoders[stream].write(Buffer.from(data.buffer, data.byteOffset, data.byteLength))),
|
|
106
107
|
});
|
|
107
108
|
let ran;
|