@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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProviderStreams } from "@earendil-works/pi-ai";
|
|
2
|
+
/** Why `image` (pi-ai's image part) cannot be attached to a model request; undefined when it can. */
|
|
3
|
+
export declare function unattachable(image: {
|
|
4
|
+
readonly data?: unknown;
|
|
5
|
+
readonly mimeType?: unknown;
|
|
6
|
+
}): string | undefined;
|
|
7
|
+
/** The text a model is sent in place of an image that cannot be attached. */
|
|
8
|
+
export declare const notAttached: (why: string) => string;
|
|
9
|
+
/** `context` with each image part that cannot be attached (unattachable) replaced by a text saying why; `context` itself
|
|
10
|
+
* when every image can be. */
|
|
11
|
+
export declare function attachableImages<C extends {
|
|
12
|
+
readonly messages: readonly unknown[];
|
|
13
|
+
}>(context: C): C;
|
|
14
|
+
/** `api` whose every request is sent with its images checked (attachableImages). */
|
|
15
|
+
export declare function attachingImages(api: ProviderStreams): ProviderStreams;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { imageSizeOf } from "@parcha/agentrun-kernel/host";
|
|
2
|
+
/** The first bytes of each image type every provider takes, by its MIME type. */
|
|
3
|
+
const SIGNATURES = {
|
|
4
|
+
"image/png": (head) => head.length >= 8 && head.readUInt32BE(0) === 0x89504e47 && head.readUInt32BE(4) === 0x0d0a1a0a,
|
|
5
|
+
"image/jpeg": (head) => head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff,
|
|
6
|
+
"image/gif": (head) => head.toString("latin1", 0, 4) === "GIF8",
|
|
7
|
+
"image/webp": (head) => head.toString("latin1", 0, 4) === "RIFF" && head.toString("latin1", 8, 12) === "WEBP",
|
|
8
|
+
};
|
|
9
|
+
const BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
10
|
+
/** Why `image` (pi-ai's image part) cannot be attached to a model request; undefined when it can. */
|
|
11
|
+
export function unattachable(image) {
|
|
12
|
+
const { data, mimeType } = image;
|
|
13
|
+
if (typeof mimeType !== "string" || !Object.hasOwn(SIGNATURES, mimeType))
|
|
14
|
+
return `its type ${JSON.stringify(mimeType ?? null)} is not PNG, JPEG, GIF or WebP`;
|
|
15
|
+
if (typeof data !== "string" || data.length === 0)
|
|
16
|
+
return "it is empty";
|
|
17
|
+
if (data.length % 4 !== 0 || !BASE64.test(data))
|
|
18
|
+
return "its data is not base64";
|
|
19
|
+
if (!SIGNATURES[mimeType](Buffer.from(data.slice(0, 16), "base64")))
|
|
20
|
+
return `its bytes are not a ${mimeType}`;
|
|
21
|
+
if (!imageSizeOf(data))
|
|
22
|
+
return `its ${mimeType} header does not say its size`;
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The text a model is sent in place of an image that cannot be attached. */
|
|
26
|
+
export const notAttached = (why) => `[the image could not be attached: ${why}]`;
|
|
27
|
+
/** `context` with each image part that cannot be attached (unattachable) replaced by a text saying why; `context` itself
|
|
28
|
+
* when every image can be. */
|
|
29
|
+
export function attachableImages(context) {
|
|
30
|
+
let changed = false;
|
|
31
|
+
const messages = context.messages.map((message) => {
|
|
32
|
+
const content = message.content;
|
|
33
|
+
if (!Array.isArray(content))
|
|
34
|
+
return message;
|
|
35
|
+
let replaced = false;
|
|
36
|
+
const parts = content.map((part) => {
|
|
37
|
+
if (!part || typeof part !== "object" || part.type !== "image")
|
|
38
|
+
return part;
|
|
39
|
+
const why = unattachable(part);
|
|
40
|
+
if (why === undefined)
|
|
41
|
+
return part;
|
|
42
|
+
replaced = true;
|
|
43
|
+
return { type: "text", text: notAttached(why) };
|
|
44
|
+
});
|
|
45
|
+
if (!replaced)
|
|
46
|
+
return message;
|
|
47
|
+
changed = true;
|
|
48
|
+
return { ...message, content: parts };
|
|
49
|
+
});
|
|
50
|
+
return changed ? { ...context, messages } : context;
|
|
51
|
+
}
|
|
52
|
+
/** `api` whose every request is sent with its images checked (attachableImages). */
|
|
53
|
+
export function attachingImages(api) {
|
|
54
|
+
return {
|
|
55
|
+
...api,
|
|
56
|
+
stream: (model, context, options) => api.stream(model, attachableImages(context), options),
|
|
57
|
+
streamSimple: (model, context, options) => api.streamSimple(model, attachableImages(context), options),
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/background.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Context } from "@earendil-works/chord";
|
|
2
1
|
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
-
import type { BoxProvider } from "@parcha/pi-transport";
|
|
4
2
|
/** The most background processes that run at once in one run's box. */
|
|
5
3
|
export declare const BACKGROUND_MAX = 8;
|
|
6
4
|
/** The most bytes of output one background process's log keeps: later output is dropped, and the process runs on. */
|
|
@@ -23,7 +21,3 @@ export declare const BACKGROUND_TOOLS: readonly ["bash_background", "bash_output
|
|
|
23
21
|
export declare const SHELL_TOOLS: readonly string[];
|
|
24
22
|
/** The background tools, each run on the environment its call gives (the box's, coding-tools.ts). */
|
|
25
23
|
export declare const backgroundTools: () => ToolRegistration[];
|
|
26
|
-
/** The run's end: every background process still running in run `runId`'s box (found by `label`) is sent TERM, then
|
|
27
|
-
* KILL after 3 s, and marked as ended at the run's end, so its runner writes its exit code and its log is whole before
|
|
28
|
-
* the box is pulled and destroyed. How many it ended; a run with no box ends none. */
|
|
29
|
-
export declare function endBackground(boxes: BoxProvider, label: Record<string, string>, context: Context): Promise<number>;
|
package/dist/background.js
CHANGED
|
@@ -386,31 +386,3 @@ const bashList = defineTool({
|
|
|
386
386
|
});
|
|
387
387
|
/** The background tools, each run on the environment its call gives (the box's, coding-tools.ts). */
|
|
388
388
|
export const backgroundTools = () => [bashBackground, bashOutput, bashInput, bashSignal, bashList];
|
|
389
|
-
/** The run's end: every background process still running in run `runId`'s box (found by `label`) is sent TERM, then
|
|
390
|
-
* KILL after 3 s, and marked as ended at the run's end, so its runner writes its exit code and its log is whole before
|
|
391
|
-
* the box is pulled and destroyed. How many it ended; a run with no box ends none. */
|
|
392
|
-
export async function endBackground(boxes, label, context) {
|
|
393
|
-
const { finish } = await import("@parcha/pi-transport");
|
|
394
|
-
const listed = await boxes.list(label, context);
|
|
395
|
-
if (!listed.ok)
|
|
396
|
-
throw listed.error;
|
|
397
|
-
let ended = 0;
|
|
398
|
-
for (const ref of listed.value) {
|
|
399
|
-
const attached = await boxes.attach(ref.id, context);
|
|
400
|
-
if (!attached.ok)
|
|
401
|
-
throw attached.error;
|
|
402
|
-
if (!attached.value)
|
|
403
|
-
continue;
|
|
404
|
-
const started = await attached.value.exec(["sh", "-c", SCRIPT, "agentrun-background", BOX_WORK, "end"], { timeoutMs: 20_000 }, context);
|
|
405
|
-
if (!started.ok)
|
|
406
|
-
throw started.error;
|
|
407
|
-
const done = await finish(started.value);
|
|
408
|
-
if (!done.ok)
|
|
409
|
-
throw done.error;
|
|
410
|
-
const said = new TextDecoder().decode(done.value.stdout).trim();
|
|
411
|
-
if (done.value.exitCode !== 0)
|
|
412
|
-
throw new Error(`ending the box's background processes failed (exit code ${done.value.exitCode}): ${done.value.stderr.trim().slice(0, 300)}`);
|
|
413
|
-
ended += Number(/^ended (\d+)/.exec(said)?.[1] ?? 0);
|
|
414
|
-
}
|
|
415
|
-
return ended;
|
|
416
|
-
}
|
package/dist/bash-read-only.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
/** The policies an agent may set on bash (tool_settings.bash.policy). */
|
|
2
2
|
export declare const BASH_POLICIES: readonly ["read-only"];
|
|
3
3
|
export type BashPolicy = (typeof BASH_POLICIES)[number];
|
|
4
|
+
/** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
|
|
5
|
+
* value, a policy this server does not know too (the gate refuses its every call; policyEnv holds its shell all the same). */
|
|
6
|
+
export declare function bashPolicyOf(toolSettings: unknown): string | undefined;
|
|
7
|
+
/** The command-line config a shell under a policy gives git (GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n). */
|
|
8
|
+
export declare const POLICY_GIT_CONFIG: readonly (readonly [string, string])[];
|
|
9
|
+
/** What a shell under bash policy `policy` adds to the run's fixed environment (hands.ts shellEnv): git's config locked
|
|
10
|
+
* down (POLICY_GIT_CONFIG and the variables above); nothing without a policy. */
|
|
11
|
+
export declare function policyEnv(policy: string | undefined): Readonly<Record<string, string>>;
|
|
12
|
+
/** The oldest git that holds the whole lock-down (attr.tree). */
|
|
13
|
+
export declare const POLICY_GIT_FLOOR = "2.43";
|
|
14
|
+
/** What a shell under bash policy `policy` runs before the command, on a line of its own: `git` as a function that runs
|
|
15
|
+
* git only at POLICY_GIT_FLOOR or later. Empty without a policy. POSIX sh, for bash and the sh fallback alike. */
|
|
16
|
+
export declare function policyPrelude(policy: string | undefined): string;
|
|
4
17
|
/** The programs a read-only command may run. */
|
|
5
18
|
export declare const PROGRAMS: ReadonlySet<string>;
|
|
6
19
|
/** The programs a command may pipe into: filters of their input. */
|
package/dist/bash-read-only.js
CHANGED
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
// runs one command in the foreground); bash_output, bash_list and bash_signal, which reach only processes this run
|
|
36
36
|
// started, pass. A CLI harness's own shell call (codex's `shell`, an argv) is read as the command it runs.
|
|
37
37
|
//
|
|
38
|
+
// - The shell's environment: a shell under a policy runs git with its config locked down (policyEnv, below): no
|
|
39
|
+
// system or global config, and command-line config that turns off what a repository's config could run.
|
|
40
|
+
//
|
|
38
41
|
// What it does not hold: the policy reads bash alone. An agent that may also write or edit can change what a read
|
|
39
42
|
// program obeys (a repository's .git/config names programs git runs), so a read-only agent's tools are read and bash.
|
|
40
43
|
// The never-open list refuses a command that names such a file; it is no fence around the folder's contents: a recursive
|
|
@@ -43,6 +46,80 @@
|
|
|
43
46
|
import { posix } from "node:path";
|
|
44
47
|
/** The policies an agent may set on bash (tool_settings.bash.policy). */
|
|
45
48
|
export const BASH_POLICIES = ["read-only"];
|
|
49
|
+
/** An agent's bash policy as its own tool settings write it (tool_settings.bash.policy), or undefined for none: any
|
|
50
|
+
* value, a policy this server does not know too (the gate refuses its every call; policyEnv holds its shell all the same). */
|
|
51
|
+
export function bashPolicyOf(toolSettings) {
|
|
52
|
+
const bash = typeof toolSettings === "object" && toolSettings !== null ? toolSettings.bash : undefined;
|
|
53
|
+
const policy = typeof bash === "object" && bash !== null ? bash.policy : undefined;
|
|
54
|
+
return policy === undefined ? undefined : String(policy);
|
|
55
|
+
}
|
|
56
|
+
// git's config under a policy. The policy refuses `git -c`, `--config-env`, `--ext-diff`, `--textconv` and `--paginate`,
|
|
57
|
+
// but git also reads config from files, and config can name a program git runs on a plain read (core.fsmonitor on
|
|
58
|
+
// status and diff, core.pager, a hook on an index write, a diff or filter driver that an attribute attaches to a path, a
|
|
59
|
+
// signature program for log's %G?, a transport for a partial clone's lazy fetch). A checkout of someone else's code can
|
|
60
|
+
// hold such config: a bare repository planted in the tree, found when a command runs from inside it. So a shell under a
|
|
61
|
+
// policy runs git with:
|
|
62
|
+
// - no system or global config (the image's and HOME's are no business of a read);
|
|
63
|
+
// - command-line config (GIT_CONFIG_COUNT, which outranks every file) turning those programs off: no fsmonitor, hooks
|
|
64
|
+
// from /dev/null, cat as the pager, attributes from an empty tree and no attributes file (so no in-tree .gitattributes
|
|
65
|
+
// attaches a textconv, external diff or filter driver), a bare repository only when named (safe.bareRepository,
|
|
66
|
+
// which git reads from command-line config, never a repository's own), no transport at all, and no signature program;
|
|
67
|
+
// - GIT_PAGER and PAGER cat, no prompt, no optional lock (status leaves the index unwritten) and no lazy fetch.
|
|
68
|
+
// The config needs git 2.43 (attr.tree; safe.bareRepository is 2.38), and an older git ignores what it does not know,
|
|
69
|
+
// so a shell under a policy runs with a prelude (policyPrelude) defining `git` as a function that runs git only at 2.43
|
|
70
|
+
// or later and otherwise refuses, in words, before anything runs: fail closed, never a read with half the lock-down.
|
|
71
|
+
// Archil's stock exec image has git 2.34 (archil.ts), so a Mode 2 server runs its execs in DEFAULT_ARCHIL_EXEC_IMAGE
|
|
72
|
+
// (archil-settings.ts, git 2.47) unless the owner saved another, which needs git 2.43 too. The model cannot step around the function: the policy refuses `command`, a path to a program, `$`,
|
|
73
|
+
// `unset` and every program but git by name.
|
|
74
|
+
// What config cannot turn off: diff.external (an empty value makes git diff fail; git has no unset on the command
|
|
75
|
+
// line). It needs a repository's own config, which the policy never lets a command write and safe.bareRepository keeps
|
|
76
|
+
// a planted repository from supplying.
|
|
77
|
+
/** The empty tree's id, as attr.tree's value: attributes read from no tree (an id that does not resolve, a sha256
|
|
78
|
+
* repository's case, reads as the empty tree too). */
|
|
79
|
+
const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
80
|
+
/** The command-line config a shell under a policy gives git (GIT_CONFIG_KEY_n / GIT_CONFIG_VALUE_n). */
|
|
81
|
+
export const POLICY_GIT_CONFIG = [
|
|
82
|
+
["core.fsmonitor", "false"],
|
|
83
|
+
["core.hooksPath", "/dev/null"],
|
|
84
|
+
["core.pager", "cat"],
|
|
85
|
+
["core.attributesFile", "/dev/null"],
|
|
86
|
+
["attr.tree", EMPTY_TREE],
|
|
87
|
+
["safe.bareRepository", "explicit"],
|
|
88
|
+
["protocol.allow", "never"],
|
|
89
|
+
["log.showSignature", "false"],
|
|
90
|
+
["gpg.program", "false"],
|
|
91
|
+
["gpg.openpgp.program", "false"],
|
|
92
|
+
["gpg.x509.program", "false"],
|
|
93
|
+
["gpg.ssh.program", "false"],
|
|
94
|
+
];
|
|
95
|
+
/** What a shell under bash policy `policy` adds to the run's fixed environment (hands.ts shellEnv): git's config locked
|
|
96
|
+
* down (POLICY_GIT_CONFIG and the variables above); nothing without a policy. */
|
|
97
|
+
export function policyEnv(policy) {
|
|
98
|
+
if (policy === undefined)
|
|
99
|
+
return {};
|
|
100
|
+
return {
|
|
101
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
102
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
103
|
+
GIT_ATTR_NOSYSTEM: "1",
|
|
104
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
105
|
+
GIT_PAGER: "cat",
|
|
106
|
+
PAGER: "cat",
|
|
107
|
+
GIT_OPTIONAL_LOCKS: "0",
|
|
108
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
109
|
+
GIT_CONFIG_COUNT: String(POLICY_GIT_CONFIG.length),
|
|
110
|
+
...Object.fromEntries(POLICY_GIT_CONFIG.flatMap(([key, value], n) => [[`GIT_CONFIG_KEY_${n}`, key], [`GIT_CONFIG_VALUE_${n}`, value]])),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** The oldest git that holds the whole lock-down (attr.tree). */
|
|
114
|
+
export const POLICY_GIT_FLOOR = "2.43";
|
|
115
|
+
// `git version` at the floor or later: 2.43-2.49, 2.50-2.99, 2.100 and up, 3 and up.
|
|
116
|
+
const GIT_AT_FLOOR = `"git version 2.4"[3-9]*|"git version 2."[5-9][0-9]*|"git version 2."[1-9][0-9][0-9]*|"git version "[3-9]*|"git version "[1-9][0-9]*`;
|
|
117
|
+
const GIT_FUNCTION = `git() { case "$(command git version 2>/dev/null)" in ${GIT_AT_FLOOR}) command git "$@" ;; *) echo "git refused: this agent's bash policy needs git ${POLICY_GIT_FLOOR} or later to keep a repository's config from running a program, and this shell has $(command git version 2>/dev/null || echo no git); nothing ran." >&2; return 126 ;; esac; }`;
|
|
118
|
+
/** What a shell under bash policy `policy` runs before the command, on a line of its own: `git` as a function that runs
|
|
119
|
+
* git only at POLICY_GIT_FLOOR or later. Empty without a policy. POSIX sh, for bash and the sh fallback alike. */
|
|
120
|
+
export function policyPrelude(policy) {
|
|
121
|
+
return policy === undefined ? "" : `${GIT_FUNCTION}\n`;
|
|
122
|
+
}
|
|
46
123
|
/** The programs a read-only command may run. */
|
|
47
124
|
export const PROGRAMS = new Set(["git", "grep", "egrep", "fgrep", "rg", "sed", "ls", "cat", "head", "tail", "wc", "nl", "sort", "uniq", "cut", "tr", "find", "diff", "basename", "dirname", "true", "echo"]);
|
|
48
125
|
/** The programs a command may pipe into: filters of their input. */
|
package/dist/box-image.d.ts
CHANGED
|
@@ -1,98 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { type BoxOffer } from "./boxes.js";
|
|
3
|
-
/** The setting that names another image for Docker boxes than this server's own. */
|
|
1
|
+
/** The setting that names another image for Docker computers than the computer package's own. */
|
|
4
2
|
export declare const DOCKER_IMAGE_ENV = "AGENTRUN_DOCKER_IMAGE";
|
|
5
|
-
/** What the default image has, in words. */
|
|
6
|
-
export declare const RECIPE_HAS = "python, git, curl, node, npm, rg";
|
|
7
|
-
/** The base the default image builds from: `python:3.12-slim`, pinned to the multi-arch index digest Docker Hub served
|
|
8
|
-
* for that tag on 2026-11-03, so a build gets the same base wherever it runs. To move it, read the tag's index digest
|
|
9
|
-
* again (an anonymous pull token from auth.docker.io for `repository:library/python:pull`, then a HEAD of
|
|
10
|
-
* registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
|
|
11
|
-
* `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does the image's tag
|
|
12
|
-
* (DEFAULT_DOCKER_IMAGE), so every server builds the new one at its next start. */
|
|
13
|
-
export declare const BOX_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
|
|
14
|
-
/** The default image's recipe: a Dockerfile that needs no other file, written alone into a private context directory for
|
|
15
|
-
* each build (buildContext). Its hash names the image. */
|
|
16
|
-
export declare const BOX_RECIPE: string;
|
|
17
|
-
/** The label the built image carries: its recipe's sha256. */
|
|
18
|
-
export declare const RECIPE_LABEL = "agentrun.box-image";
|
|
19
|
-
export declare const RECIPE_HASH: string;
|
|
20
|
-
/** The default image: this server's own, built from BOX_RECIPE, its tag the recipe's hash. */
|
|
21
|
-
export declare const DEFAULT_DOCKER_IMAGE: string;
|
|
22
|
-
/** The image a Docker box starts from on a server or a run with `env`. */
|
|
23
|
-
export declare const boxImageOf: (env: NodeJS.ProcessEnv) => string;
|
|
24
|
-
/** Where the image's state is kept for the run's processes, in the data directory. */
|
|
25
|
-
export declare const IMAGE_STATE_FILE = "box-image.json";
|
|
26
|
-
/** How long the start's pull, or build, may take; past it, it is stopped and docker is unavailable. */
|
|
27
|
-
export declare const PULL_TIMEOUT_MS: number;
|
|
28
|
-
export declare const BUILD_TIMEOUT_MS: number;
|
|
29
|
-
/** How long Docker may take to say whether it has the image. */
|
|
30
|
-
export declare const INSPECT_TIMEOUT_MS = 5000;
|
|
31
|
-
/** How long past the pull's deadline a run still waits on a file that says preparing: the server's own timer ends the
|
|
32
|
-
* pull at the deadline, so only a server that is gone leaves the file saying preparing after it. */
|
|
33
|
-
export declare const STALE_AFTER_MS = 30000;
|
|
34
|
-
/** How long after a failed build or pull it is tried once more. */
|
|
35
|
-
export declare const RETRY_AFTER_MS = 5000;
|
|
36
|
-
/** How long the server's close waits for the image's last record to be saved, so a docker that hangs cannot hold it. */
|
|
37
|
-
export declare const CLOSE_WAIT_MS = 5000;
|
|
38
|
-
/** The image's state: `ready`; `preparing` while the server pulls it; `unavailable`, with why. */
|
|
39
|
-
export type ImageState = {
|
|
40
|
-
state: "ready";
|
|
41
|
-
} | {
|
|
42
|
-
state: "preparing";
|
|
43
|
-
reason: string;
|
|
44
|
-
} | {
|
|
45
|
-
state: "unavailable";
|
|
46
|
-
reason: string;
|
|
47
|
-
};
|
|
48
|
-
/** The file's record: the image, its state, and while it is coming, the time it is stopped by (`until`, epoch ms) and
|
|
49
|
-
* the timeline row a run that waits for it writes (`row`). `writer`: the server that wrote it, its pid and start time,
|
|
50
|
-
* where /proc gives that. */
|
|
51
|
-
export type ImageRecord = {
|
|
52
|
-
image: string;
|
|
53
|
-
state: ImageState["state"];
|
|
54
|
-
reason?: string;
|
|
55
|
-
until?: number;
|
|
56
|
-
row?: string;
|
|
57
|
-
writer?: {
|
|
58
|
-
pid: number;
|
|
59
|
-
startTime: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
export type DockerImage = {
|
|
63
|
-
readonly image: string;
|
|
64
|
-
/** The state now. */
|
|
65
|
-
state(): ImageState;
|
|
66
|
-
/** Settles with the state once it is ready or unavailable. */
|
|
67
|
-
readonly settled: Promise<ImageState>;
|
|
68
|
-
/** Stops a build or pull in progress and waits, at most CLOSE_WAIT_MS, for its last record to be saved: the server's
|
|
69
|
-
* close (and a start that failed) calls it before the data directory's lock goes, so no record of this server lands
|
|
70
|
-
* after the next one took the lock. */
|
|
71
|
-
close(): Promise<void>;
|
|
72
|
-
};
|
|
73
|
-
/** Removes the record: this server has no Docker box, so no run waits on its image. */
|
|
74
|
-
export declare const clearImage: (data: string) => Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* The image's readiness on this server: asked of Docker now (within INSPECT_TIMEOUT_MS), and when Docker has none (or,
|
|
77
|
-
* for the default, has one of another recipe), built from BOX_RECIPE or pulled, in the background, within its bound; a
|
|
78
|
-
* try that fails, but not for want of time, is made once more, `retryAfterMs` later. `onChange` is told each state after
|
|
79
|
-
* the first. The record in the data directory follows the state.
|
|
80
|
-
*/
|
|
81
|
-
export declare function dockerImage(env: NodeJS.ProcessEnv, data: string, image: string, options?: {
|
|
82
|
-
pullTimeoutMs?: number;
|
|
83
|
-
buildTimeoutMs?: number;
|
|
84
|
-
inspectTimeoutMs?: number;
|
|
85
|
-
retryAfterMs?: number;
|
|
86
|
-
onChange?: (state: ImageState, ms: number) => void;
|
|
87
|
-
warn?: (message: string) => void;
|
|
88
|
-
}): Promise<DockerImage>;
|
|
89
|
-
/** Docker's offer with the image's state on it: available while it is ready or preparing, else unavailable with why. */
|
|
90
|
-
export declare function withImage(offer: BoxOffer, image: ImageState): BoxOffer;
|
|
91
|
-
/**
|
|
92
|
-
* Before a run's box is made from `image`: returns once the server's record says the image is ready, or says nothing
|
|
93
|
-
* of it (no record, another image); waits while it says the image is being built or pulled, telling `note` once, as the
|
|
94
|
-
* run's timeline row; and throws, with the server's reason, when that failed, and saying to restart the server when the
|
|
95
|
-
* server that was making it is gone (its writer, or where that cannot be told, its deadline). A cancel of `context`
|
|
96
|
-
* ends the wait.
|
|
97
|
-
*/
|
|
98
|
-
export declare function awaitImage(data: string, image: string, context: Context, note: (summary: string) => Promise<void> | void): Promise<void>;
|
package/dist/box-image.js
CHANGED
|
@@ -1,285 +1,5 @@
|
|
|
1
|
-
// The image a Docker
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// when the recipe changes. AGENTRUN_DOCKER_IMAGE names another image instead, which is pulled when Docker has none.
|
|
6
|
-
//
|
|
7
|
-
// Once docker answers its probe (boxes.ts), the server asks Docker for the image (`docker image inspect`). When Docker has
|
|
8
|
-
// it (the built one with this recipe's hash), the box is ready. When not, the server builds or pulls it once, in the
|
|
9
|
-
// background, within BUILD_TIMEOUT_MS or PULL_TIMEOUT_MS: docker is then available and preparing ("building the box
|
|
10
|
-
// image (...)", "pulling <image>"), and ready once the image is in. A build or pull that fails is tried once more,
|
|
11
|
-
// RETRY_AFTER_MS later, docker preparing meanwhile with why ("trying once more: <the failure>"); one that fails again, or
|
|
12
|
-
// does not finish in time, makes docker unavailable with the reason, until a restart tries again. Docker's own output
|
|
13
|
-
// is never in a reason, as for the probes: the reason says what kind of failure it was, and what to do. The build
|
|
14
|
-
// reaches the network (the base image, apt); a box never does by Docker's network (`--network none`, run-box.ts), only,
|
|
15
|
-
// with the server's host list, through its egress proxy (box-egress.ts).
|
|
16
|
-
//
|
|
17
|
-
// The state is written to IMAGE_STATE_FILE in the data directory at each change, for the run's processes: a run's first
|
|
18
|
-
// box create reads it there (awaitImage, from run-box.ts) and, while the image is coming, waits for it, with one row on
|
|
19
|
-
// the run's timeline, instead of a `docker run` that pulls inside the tool call. Each record names its writer, the server
|
|
20
|
-
// (its pid and start time). A server that went away mid-way (killed, or closed while the image came) leaves the file
|
|
21
|
-
// saying preparing: a run that reads it once that writer is gone (the check box/sweep.ts makes of a box record's writer),
|
|
22
|
-
// or past its deadline where the writer cannot be told (no /proc), stops waiting and fails its call in words that say to
|
|
23
|
-
// restart the server, which builds or pulls the image again; never the `docker run` of an image that is not there.
|
|
24
|
-
import { execFile } from "node:child_process";
|
|
25
|
-
import { createHash } from "node:crypto";
|
|
26
|
-
import { chmod, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
27
|
-
import { tmpdir } from "node:os";
|
|
28
|
-
import { join } from "node:path";
|
|
29
|
-
import { startTimeOf, writerGone } from "./box/sweep.js";
|
|
30
|
-
import { BOX_KEYS } from "./boxes.js";
|
|
31
|
-
/** The setting that names another image for Docker boxes than this server's own. */
|
|
1
|
+
// The image a run's Docker computer starts from, when the owner names one: AGENTRUN_DOCKER_IMAGE. Unset, the Docker
|
|
2
|
+
// provider builds its own from the computer package's recipe (DOCKER_RECIPE) on first use, and a run waiting on that
|
|
3
|
+
// build shows it on its timeline (workspace/computer-deps.ts imageWaitWords). Nothing is built or pulled at the start.
|
|
4
|
+
/** The setting that names another image for Docker computers than the computer package's own. */
|
|
32
5
|
export const DOCKER_IMAGE_ENV = "AGENTRUN_DOCKER_IMAGE";
|
|
33
|
-
/** What the default image has, in words. */
|
|
34
|
-
export const RECIPE_HAS = "python, git, curl, node, npm, rg";
|
|
35
|
-
/** The base the default image builds from: `python:3.12-slim`, pinned to the multi-arch index digest Docker Hub served
|
|
36
|
-
* for that tag on 2026-11-03, so a build gets the same base wherever it runs. To move it, read the tag's index digest
|
|
37
|
-
* again (an anonymous pull token from auth.docker.io for `repository:library/python:pull`, then a HEAD of
|
|
38
|
-
* registry-1.docker.io/v2/library/python/manifests/3.12-slim accepting an OCI index or a manifest list: its
|
|
39
|
-
* `docker-content-digest`), and put it here. The recipe's hash changes with it, and so does the image's tag
|
|
40
|
-
* (DEFAULT_DOCKER_IMAGE), so every server builds the new one at its next start. */
|
|
41
|
-
export const BOX_BASE = "python:3.12-slim@sha256:b18b261e1b4974b4f321451ad5251ded85abb22c2b8b262da527dda1d031ab30";
|
|
42
|
-
/** The default image's recipe: a Dockerfile that needs no other file, written alone into a private context directory for
|
|
43
|
-
* each build (buildContext). Its hash names the image. */
|
|
44
|
-
export const BOX_RECIPE = [
|
|
45
|
-
`FROM ${BOX_BASE}`,
|
|
46
|
-
"RUN apt-get update \\",
|
|
47
|
-
" && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git curl ca-certificates nodejs npm ripgrep socat \\",
|
|
48
|
-
" && rm -rf /var/lib/apt/lists/*",
|
|
49
|
-
"",
|
|
50
|
-
].join("\n");
|
|
51
|
-
/** The label the built image carries: its recipe's sha256. */
|
|
52
|
-
export const RECIPE_LABEL = "agentrun.box-image";
|
|
53
|
-
export const RECIPE_HASH = createHash("sha256").update(BOX_RECIPE).digest("hex");
|
|
54
|
-
/** The default image: this server's own, built from BOX_RECIPE, its tag the recipe's hash. */
|
|
55
|
-
export const DEFAULT_DOCKER_IMAGE = `agentrun-box:${RECIPE_HASH.slice(0, 12)}`;
|
|
56
|
-
/** The image a Docker box starts from on a server or a run with `env`. */
|
|
57
|
-
export const boxImageOf = (env) => env[DOCKER_IMAGE_ENV] || DEFAULT_DOCKER_IMAGE;
|
|
58
|
-
/** Where the image's state is kept for the run's processes, in the data directory. */
|
|
59
|
-
export const IMAGE_STATE_FILE = "box-image.json";
|
|
60
|
-
/** How long the start's pull, or build, may take; past it, it is stopped and docker is unavailable. */
|
|
61
|
-
export const PULL_TIMEOUT_MS = 10 * 60_000;
|
|
62
|
-
export const BUILD_TIMEOUT_MS = 10 * 60_000;
|
|
63
|
-
/** How long Docker may take to say whether it has the image. */
|
|
64
|
-
export const INSPECT_TIMEOUT_MS = 5_000;
|
|
65
|
-
/** How long past the pull's deadline a run still waits on a file that says preparing: the server's own timer ends the
|
|
66
|
-
* pull at the deadline, so only a server that is gone leaves the file saying preparing after it. */
|
|
67
|
-
export const STALE_AFTER_MS = 30_000;
|
|
68
|
-
/** How long after a failed build or pull it is tried once more. */
|
|
69
|
-
export const RETRY_AFTER_MS = 5_000;
|
|
70
|
-
/** How long the server's close waits for the image's last record to be saved, so a docker that hangs cannot hold it. */
|
|
71
|
-
export const CLOSE_WAIT_MS = 5_000;
|
|
72
|
-
/** How often a waiting run reads the file again. */
|
|
73
|
-
const POLL_MS = 250;
|
|
74
|
-
/** `docker` with `args`, in the server's environment without the boxes' keys, nothing on its stdin, killed after
|
|
75
|
-
* `timeoutMs` or on `signal`. */
|
|
76
|
-
function docker(env, args, timeoutMs, options = {}) {
|
|
77
|
-
const dockerEnv = Object.fromEntries(Object.entries(env).filter(([name]) => !BOX_KEYS.includes(name)));
|
|
78
|
-
return new Promise((resolve) => {
|
|
79
|
-
const child = execFile("docker", args, { env: dockerEnv, timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: 32 * 1024 * 1024, ...(options.signal ? { signal: options.signal } : {}) }, (error, stdout, stderr) => {
|
|
80
|
-
const failed = error;
|
|
81
|
-
resolve({ code: !failed ? 0 : failed.killed ? "timeout" : typeof failed.code === "number" ? failed.code : (failed.code ?? failed.name), stdout: String(stdout), stderr: String(stderr) });
|
|
82
|
-
});
|
|
83
|
-
child.stdin?.on("error", () => undefined);
|
|
84
|
-
child.stdin?.end();
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
/** Seconds or minutes, in words. */
|
|
88
|
-
const span = (ms) => (ms >= 60_000 && ms % 60_000 === 0 ? `${ms / 60_000} min` : `${Math.round(ms / 1000)} s`);
|
|
89
|
-
const exitOf = (answer) => (typeof answer.code === "number" ? `exit ${answer.code}` : answer.code);
|
|
90
|
-
const UNREACHABLE = /dial tcp|no such host|i\/o timeout|connection refused|network is unreachable|TLS handshake timeout|Client\.Timeout|Temporary failure resolving|Could not resolve|Could not connect/i;
|
|
91
|
-
const reasonOf = (failure) => `${failure.cause}: ${failure.next}`;
|
|
92
|
-
/** Why the build of the default image failed, and the next step. */
|
|
93
|
-
function buildFailure(answer, timeoutMs) {
|
|
94
|
-
const next = `set ${DOCKER_IMAGE_ENV} to an image this machine has, or restart the server to build it again`;
|
|
95
|
-
if (answer.code === "timeout")
|
|
96
|
-
return { cause: `the build of the box image did not finish within ${span(timeoutMs)}`, next };
|
|
97
|
-
if (/no space left on device/i.test(answer.stderr))
|
|
98
|
-
return { cause: "the build of the box image ran out of disk space", next: "free some, then restart the server" };
|
|
99
|
-
// A base that could not be fetched for want of a network says so in both ways: the network is the cause.
|
|
100
|
-
if (UNREACHABLE.test(answer.stderr))
|
|
101
|
-
return { cause: "the build of the box image could not reach the network (it pulls python:3.12-slim and installs git, curl, nodejs, npm, ripgrep and socat with apt)", next };
|
|
102
|
-
if (/pull access denied|manifest unknown|not found: manifest|failed to resolve source metadata|failed to fetch anonymous token/i.test(answer.stderr))
|
|
103
|
-
return { cause: "the build of the box image could not pull its base, python:3.12-slim", next };
|
|
104
|
-
if (/Unable to locate package|has no installation candidate|E: Package/i.test(answer.stderr))
|
|
105
|
-
return { cause: "apt could not install what the box image needs (git, curl, nodejs, npm, ripgrep, socat)", next };
|
|
106
|
-
return { cause: `docker build of the box image failed (${exitOf(answer)})`, next };
|
|
107
|
-
}
|
|
108
|
-
/** Why a pull failed, and the next step. */
|
|
109
|
-
function pullFailure(image, answer, timeoutMs) {
|
|
110
|
-
const see = `run \`docker pull ${image}\` on this machine to see why, then restart the server`;
|
|
111
|
-
if (answer.code === "timeout")
|
|
112
|
-
return { cause: `the pull of ${image} did not finish within ${span(timeoutMs)}`, next: `run \`docker pull ${image}\` on this machine, then restart the server` };
|
|
113
|
-
if (/pull access denied|unauthorized|authentication required|denied:/i.test(answer.stderr))
|
|
114
|
-
return { cause: `the registry refused the pull of ${image} (no such repository, or it needs a docker login)`, next: see };
|
|
115
|
-
if (/manifest unknown|manifest for .* not found|not found: manifest/i.test(answer.stderr))
|
|
116
|
-
return { cause: `the registry has no ${image}`, next: "name an image it has in AGENTRUN_DOCKER_IMAGE, then restart the server" };
|
|
117
|
-
if (UNREACHABLE.test(answer.stderr))
|
|
118
|
-
return { cause: `the registry could not be reached to pull ${image}`, next: see };
|
|
119
|
-
return { cause: `docker pull ${image} failed (${exitOf(answer)})`, next: see };
|
|
120
|
-
}
|
|
121
|
-
/** This process, as a record names its writer: its pid and start time, where /proc gives that (Linux). */
|
|
122
|
-
function self() {
|
|
123
|
-
const startTime = startTimeOf(process.pid);
|
|
124
|
-
return startTime ? { writer: { pid: process.pid, startTime } } : {};
|
|
125
|
-
}
|
|
126
|
-
/** Writes the record for the run's processes, whole or not at all, naming this server as its writer. */
|
|
127
|
-
async function record(data, value) {
|
|
128
|
-
const file = join(data, IMAGE_STATE_FILE);
|
|
129
|
-
await writeFile(`${file}.partial`, `${JSON.stringify({ ...value, ...self() })}\n`, { mode: 0o600 });
|
|
130
|
-
await rename(`${file}.partial`, file);
|
|
131
|
-
}
|
|
132
|
-
/** Removes the record: this server has no Docker box, so no run waits on its image. */
|
|
133
|
-
export const clearImage = (data) => rm(join(data, IMAGE_STATE_FILE), { force: true });
|
|
134
|
-
/** `docker build` of the default image: BOX_RECIPE written alone as `Dockerfile` into a fresh directory of its own (0700,
|
|
135
|
-
* under TMPDIR), which is the build's context and is removed when the build ends, however it ends. A file on disk, not
|
|
136
|
-
* stdin, so what was built can be read where it was built. */
|
|
137
|
-
async function buildContext(env, image, timeoutMs, signal) {
|
|
138
|
-
const dir = await mkdtemp(join(env.TMPDIR || tmpdir(), "agentrun-box-"));
|
|
139
|
-
try {
|
|
140
|
-
await chmod(dir, 0o700);
|
|
141
|
-
await writeFile(join(dir, "Dockerfile"), BOX_RECIPE, { mode: 0o600 });
|
|
142
|
-
return await docker(env, ["build", "--quiet", "--label", `${RECIPE_LABEL}=${RECIPE_HASH}`, "--tag", image, dir], timeoutMs, { signal });
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
await rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/** The labels of `image` as `docker image inspect` gives them, or none when it has none. */
|
|
149
|
-
const labelsOf = (stdout) => {
|
|
150
|
-
try {
|
|
151
|
-
const value = JSON.parse(stdout.trim() || "null");
|
|
152
|
-
return value && typeof value === "object" ? value : {};
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
return {};
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* The image's readiness on this server: asked of Docker now (within INSPECT_TIMEOUT_MS), and when Docker has none (or,
|
|
160
|
-
* for the default, has one of another recipe), built from BOX_RECIPE or pulled, in the background, within its bound; a
|
|
161
|
-
* try that fails, but not for want of time, is made once more, `retryAfterMs` later. `onChange` is told each state after
|
|
162
|
-
* the first. The record in the data directory follows the state.
|
|
163
|
-
*/
|
|
164
|
-
export async function dockerImage(env, data, image, options = {}) {
|
|
165
|
-
const built = image === DEFAULT_DOCKER_IMAGE;
|
|
166
|
-
const timeoutMs = built ? (options.buildTimeoutMs ?? BUILD_TIMEOUT_MS) : (options.pullTimeoutMs ?? PULL_TIMEOUT_MS);
|
|
167
|
-
let state;
|
|
168
|
-
const write = (extra = {}) => record(data, { image, state: state.state, ...("reason" in state ? { reason: state.reason } : {}), ...extra }).catch(() => undefined);
|
|
169
|
-
const inspected = await docker(env, ["image", "inspect", "--format", "{{json .Config.Labels}}", image], options.inspectTimeoutMs ?? INSPECT_TIMEOUT_MS);
|
|
170
|
-
const controller = new AbortController();
|
|
171
|
-
// Docker says `No such image`; Podman, standing in for it, `image not known`.
|
|
172
|
-
const missing = inspected.code !== 0 && /no such image|image not known/i.test(inspected.stderr);
|
|
173
|
-
if (inspected.code === 0 && (!built || labelsOf(inspected.stdout)[RECIPE_LABEL] === RECIPE_HASH))
|
|
174
|
-
state = { state: "ready" };
|
|
175
|
-
else if (inspected.code !== 0 && !missing) {
|
|
176
|
-
const why = inspected.code === "timeout" ? `did not answer within ${span(options.inspectTimeoutMs ?? INSPECT_TIMEOUT_MS)}` : `failed (${exitOf(inspected)})`;
|
|
177
|
-
state = { state: "unavailable", reason: `docker image inspect ${image} ${why}: run it on this machine as this server's user to see why, then restart the server` };
|
|
178
|
-
}
|
|
179
|
-
else
|
|
180
|
-
state = { state: "preparing", reason: built ? `building the box image (${RECIPE_HAS})` : `pulling ${image}` };
|
|
181
|
-
if (state.state !== "preparing") {
|
|
182
|
-
await write();
|
|
183
|
-
const settled = state;
|
|
184
|
-
return { image, state: () => settled, settled: Promise.resolve(settled), close: async () => undefined };
|
|
185
|
-
}
|
|
186
|
-
const started = Date.now();
|
|
187
|
-
const row = built ? `Preparing the box image: building it (${RECIPE_HAS})…` : `Preparing the box image: pulling ${image}…`;
|
|
188
|
-
await write({ until: started + timeoutMs, row });
|
|
189
|
-
const retryAfterMs = options.retryAfterMs ?? RETRY_AFTER_MS;
|
|
190
|
-
// The build's network is Docker's default, for the base image and apt; a box made from it has none of Docker's (run-box.ts).
|
|
191
|
-
const attempt = () => built
|
|
192
|
-
? buildContext(env, image, timeoutMs, controller.signal).catch((error) => ({ code: error.code ?? error.name, stdout: "", stderr: "" }))
|
|
193
|
-
: docker(env, ["pull", "--quiet", image], timeoutMs, { signal: controller.signal });
|
|
194
|
-
const failure = (answer) => (built ? buildFailure(answer, timeoutMs) : pullFailure(image, answer, timeoutMs));
|
|
195
|
-
const settled = attempt().then(async (first) => {
|
|
196
|
-
let answer = first;
|
|
197
|
-
// One try more, after a pause, for a failure that may pass (the network, the registry); not for one that already
|
|
198
|
-
// took the whole bound.
|
|
199
|
-
if (answer.code !== 0 && answer.code !== "timeout" && !controller.signal.aborted) {
|
|
200
|
-
state = { state: "preparing", reason: `trying once more: ${failure(answer).cause}` };
|
|
201
|
-
// A record of the retry that cannot be saved leaves the first try's: a run keeps waiting on it, as this server
|
|
202
|
-
// that wrote it still runs (a named writer decides, not its deadline). Removed, it would send a waiting run to a
|
|
203
|
-
// `docker run` of an image that is not there yet.
|
|
204
|
-
await write({ until: Date.now() + retryAfterMs + timeoutMs, row });
|
|
205
|
-
options.onChange?.(state, Date.now() - started);
|
|
206
|
-
await sleep(retryAfterMs, controller.signal).catch(() => undefined);
|
|
207
|
-
if (!controller.signal.aborted)
|
|
208
|
-
answer = await attempt();
|
|
209
|
-
}
|
|
210
|
-
if (controller.signal.aborted)
|
|
211
|
-
return state;
|
|
212
|
-
state = answer.code === 0 ? { state: "ready" } : { state: "unavailable", reason: reasonOf(failure(answer)) };
|
|
213
|
-
// A final state that cannot be written leaves no record: a run then makes its box as it would with none, never
|
|
214
|
-
// waiting on the `preparing` the record last said.
|
|
215
|
-
await record(data, { image, state: state.state, ...("reason" in state ? { reason: state.reason } : {}) }).catch(async (error) => {
|
|
216
|
-
await clearImage(data).catch(() => undefined);
|
|
217
|
-
options.warn?.(`the record of the box image's state could not be written (${error.code ?? error.name}), so it was removed: runs make their boxes without waiting on it`);
|
|
218
|
-
});
|
|
219
|
-
options.onChange?.(state, Date.now() - started);
|
|
220
|
-
return state;
|
|
221
|
-
});
|
|
222
|
-
const close = async () => {
|
|
223
|
-
controller.abort();
|
|
224
|
-
// A build or pull that ended just before the abort may be saving its last record: that save ends first, within bound.
|
|
225
|
-
let timer;
|
|
226
|
-
await Promise.race([settled.then(() => undefined, () => undefined), new Promise((resolve) => (timer = setTimeout(resolve, CLOSE_WAIT_MS)))]);
|
|
227
|
-
clearTimeout(timer);
|
|
228
|
-
};
|
|
229
|
-
return { image, state: () => state, settled, close };
|
|
230
|
-
}
|
|
231
|
-
/** Docker's offer with the image's state on it: available while it is ready or preparing, else unavailable with why. */
|
|
232
|
-
export function withImage(offer, image) {
|
|
233
|
-
if (!offer.available)
|
|
234
|
-
return offer;
|
|
235
|
-
if (image.state === "ready")
|
|
236
|
-
return { ...offer, state: "ready" };
|
|
237
|
-
return { id: offer.id, available: image.state === "preparing", state: image.state, reason: image.reason };
|
|
238
|
-
}
|
|
239
|
-
/** The record the server left, or undefined when there is none or it is not one. */
|
|
240
|
-
async function recordIn(data) {
|
|
241
|
-
try {
|
|
242
|
-
const value = JSON.parse(await readFile(join(data, IMAGE_STATE_FILE), "utf8"));
|
|
243
|
-
return typeof value?.image === "string" && typeof value.state === "string" ? value : undefined;
|
|
244
|
-
}
|
|
245
|
-
catch {
|
|
246
|
-
return undefined;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
250
|
-
if (signal?.aborted)
|
|
251
|
-
return reject(signal.reason ?? new Error("aborted"));
|
|
252
|
-
const timer = setTimeout(() => (signal?.removeEventListener("abort", stop), resolve()), ms);
|
|
253
|
-
const stop = () => (clearTimeout(timer), reject(signal?.reason ?? new Error("aborted")));
|
|
254
|
-
signal?.addEventListener("abort", stop, { once: true });
|
|
255
|
-
});
|
|
256
|
-
/**
|
|
257
|
-
* Before a run's box is made from `image`: returns once the server's record says the image is ready, or says nothing
|
|
258
|
-
* of it (no record, another image); waits while it says the image is being built or pulled, telling `note` once, as the
|
|
259
|
-
* run's timeline row; and throws, with the server's reason, when that failed, and saying to restart the server when the
|
|
260
|
-
* server that was making it is gone (its writer, or where that cannot be told, its deadline). A cancel of `context`
|
|
261
|
-
* ends the wait.
|
|
262
|
-
*/
|
|
263
|
-
export async function awaitImage(data, image, context, note) {
|
|
264
|
-
let noted = false;
|
|
265
|
-
for (;;) {
|
|
266
|
-
const at = await recordIn(data);
|
|
267
|
-
if (!at || at.image !== image || at.state === "ready")
|
|
268
|
-
return;
|
|
269
|
-
if (at.state === "unavailable")
|
|
270
|
-
throw new Error(`its image ${image} is not ready: ${at.reason ?? "the server could not make it ready"}`);
|
|
271
|
-
if (typeof at.until !== "number")
|
|
272
|
-
return;
|
|
273
|
-
// Its writer named, that decides: a server that runs is still making the image. Only where it cannot be told does
|
|
274
|
-
// the deadline.
|
|
275
|
-
if (at.writer ? writerGone(at.writer) : Date.now() > at.until + STALE_AFTER_MS) {
|
|
276
|
-
const making = image === DEFAULT_DOCKER_IMAGE ? ["building", "build"] : ["pulling", "pull"];
|
|
277
|
-
throw new Error(`its image ${image} is not ready: the server stopped while ${making[0]} it: restart the server to ${making[1]} it again`);
|
|
278
|
-
}
|
|
279
|
-
if (!noted) {
|
|
280
|
-
noted = true;
|
|
281
|
-
await Promise.resolve(note(at.row ?? `Preparing the box image ${image}…`)).catch(() => undefined);
|
|
282
|
-
}
|
|
283
|
-
await sleep(POLL_MS, context.abortSignal);
|
|
284
|
-
}
|
|
285
|
-
}
|