@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
package/dist/runner/runner.js
CHANGED
|
@@ -12,8 +12,9 @@ import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
|
12
12
|
import { COMMAND_KINDS, endedReason } from "./commands.js";
|
|
13
13
|
import { KINDS, withdrawnAnswers } from "./journal-kinds.js";
|
|
14
14
|
import { journalEntries } from "./journal-reader.js";
|
|
15
|
-
import {
|
|
15
|
+
import { ClaimRefused, stopEnd } from "./loop-contract.js";
|
|
16
16
|
import { isFenced } from "./store-port.js";
|
|
17
|
+
import { clearWaitEnded } from "../browser-wait-ended.js";
|
|
17
18
|
import { heldRedactor, processSecretRedactor } from "./redact.js";
|
|
18
19
|
import { withLiveTicker } from "./live-ticker.js";
|
|
19
20
|
/** Most runs a runner holds at once, unless told (RunnerOptions.loops). */
|
|
@@ -30,6 +31,8 @@ export const runnerCloseBoundMs = (drainMs) => drainMs + RUNNER_LEASE_MS - RUNNE
|
|
|
30
31
|
export const RUNNER_RENEW_EVERY_MS = 10_000;
|
|
31
32
|
/** A runner's name when none is given: its host, its process and a part of a random id. */
|
|
32
33
|
export const runnerName = () => `${hostname()}:${process.pid}:${randomUUID().slice(0, 8)}`;
|
|
34
|
+
/** A failed end's code when the claim was refused for good before any loop started (loop-contract's ClaimRefused). */
|
|
35
|
+
const CLAIM_REFUSED = "claim-refused";
|
|
33
36
|
/** The untaken row a run ends on when no loop can: a cancel before a stop (it ends the run for good, in its words). */
|
|
34
37
|
const endingRow = (untaken) => untaken.find((row) => row.kind === "cancel") ?? untaken.find((row) => row.kind === "stop");
|
|
35
38
|
/** A commit by a loop whose claim this runner gave up: refused before it reaches the store. */
|
|
@@ -292,18 +295,23 @@ export function startRunner(options) {
|
|
|
292
295
|
* the run row alone (runs.update, the same take in its one transaction), unless the end is a stop that may withdraw a
|
|
293
296
|
* call (one waits, or the journal could not be read to say none does): that end is never written without its withdrawal,
|
|
294
297
|
* so it throws EndNotWithdrawn and the run is left as it stands, not final, its stop untaken (endRefused retries it). A
|
|
295
|
-
* lost claim (Fenced) writes neither.
|
|
298
|
+
* lost claim (Fenced) writes neither. A person's stop written on the row alone keeps no outcome 'stopped': with no end
|
|
299
|
+
* in its journal, a reopen would find no turn to follow (its next claim would read the run as never started), so it
|
|
300
|
+
* reads as a stop that is over (cancelled), as it read before a stop and a cancel were told apart.
|
|
296
301
|
*/
|
|
297
302
|
const endRun = async (claim, given, take, withdrawnAs = "withdrawn") => {
|
|
298
303
|
// Why the run ended, as its end and its row say it: cut of every secret the runner holds (an error's text may echo one).
|
|
299
304
|
const data = { ...given, summary: redact(given.summary) };
|
|
300
305
|
// Unknown means it may withdraw: false only once the journal was read and no call of it waits.
|
|
301
306
|
let mayWithdraw = data.state === "stopped";
|
|
307
|
+
// A run whose journal holds no conversation never sent a request: its end carries a cost of $0, as a loop's end does.
|
|
308
|
+
let neverSent = false;
|
|
302
309
|
try {
|
|
303
310
|
const journal = store.journal(claim);
|
|
304
311
|
const [root] = (await journal.scanConversations({}, 1, undefined, BACKGROUND_CONTEXT)).items;
|
|
305
312
|
if (!root)
|
|
306
313
|
mayWithdraw = false;
|
|
314
|
+
neverSent = !root;
|
|
307
315
|
const writes = [];
|
|
308
316
|
let conversationId = root?.id;
|
|
309
317
|
if (conversationId === undefined) {
|
|
@@ -322,7 +330,7 @@ export function startRunner(options) {
|
|
|
322
330
|
}
|
|
323
331
|
const id = (await journal.mintId());
|
|
324
332
|
writes.push({ type: "entry", value: { id, conversationId, kind: KINDS.end, data: data } });
|
|
325
|
-
journal.stage({ run: { state: data.state, summary: data.summary }, effect: id, ...(take.length ? { take: take.map((command) => ({ command, effect: id })) } : {}) });
|
|
333
|
+
journal.stage({ run: { state: data.state, summary: data.summary, ...(data.outcome ? { outcome: data.outcome } : {}), ...(neverSent ? { costUsd: 0 } : {}) }, effect: id, ...(take.length ? { take: take.map((command) => ({ command, effect: id })) } : {}) });
|
|
326
334
|
const result = await journal.commit([writes], () => { }, BACKGROUND_CONTEXT);
|
|
327
335
|
if (result.stored !== 1)
|
|
328
336
|
throw result.refused ?? new Error("the run's end was not stored");
|
|
@@ -332,14 +340,22 @@ export function startRunner(options) {
|
|
|
332
340
|
throw error;
|
|
333
341
|
if (mayWithdraw)
|
|
334
342
|
throw new EndNotWithdrawn(claim.runId, error);
|
|
335
|
-
await store.runs.update(claim, { state: data.state, summary: data.summary }, take.length ? { take } : undefined);
|
|
343
|
+
await store.runs.update(claim, { state: data.state, summary: data.summary, ...(data.outcome === "cancelled" ? { outcome: data.outcome } : {}) }, take.length ? { take } : undefined);
|
|
336
344
|
}
|
|
345
|
+
// An ended run's Screen has no ended-while-waiting state to keep (browser-wait-ended.ts): its row goes with the end.
|
|
346
|
+
if (store.settings)
|
|
347
|
+
await clearWaitEnded(store.settings, claim.runId, claim.epoch).catch(() => undefined);
|
|
337
348
|
};
|
|
338
349
|
/** Ends the run under `claim` stopped on its untaken `stop` (or cancel) row (endRun). False when that end may withdraw a
|
|
339
350
|
* call and the journal would not take it or could not be read: the refusal is then the run's (endRefused). */
|
|
340
351
|
const endStopped = async (claim, stop) => {
|
|
341
352
|
try {
|
|
342
|
-
|
|
353
|
+
// A learning run is never reopened (reopenableWhere), so its person's stop keeps no outcome 'stopped' (which would
|
|
354
|
+
// read it waiting on a message for good): it reads stopped, as the learning loop's own stop end leaves it.
|
|
355
|
+
const end = stopEnd(stop.kind === "cancel");
|
|
356
|
+
const launch = end.outcome === "stopped" ? await store.runs.launch?.(claim.runId).catch(() => undefined) : undefined;
|
|
357
|
+
const learning = launch?.body?.harness === "learning";
|
|
358
|
+
await endRun(claim, learning ? { state: end.state, summary: end.summary } : end, [stop.id], stop.kind === "cancel" ? "canceled" : "withdrawn");
|
|
343
359
|
return true;
|
|
344
360
|
}
|
|
345
361
|
catch (error) {
|
|
@@ -376,7 +392,9 @@ export function startRunner(options) {
|
|
|
376
392
|
const why = message(refused.cause);
|
|
377
393
|
if (tries >= endRetryCapFrom + endRetryAtCap) {
|
|
378
394
|
emit({ type: "error", runId: claim.runId, step: "end", message: `run ${claim.runId} ended without withdrawing: journal unreadable or refusing (after ${tries} tries; the last: ${why})` });
|
|
379
|
-
|
|
395
|
+
// On its row alone, so no outcome 'stopped' (endRun): a run whose journal never took its end is never reopened.
|
|
396
|
+
const end = stopEnd(stop.kind === "cancel");
|
|
397
|
+
await store.runs.update(claim, { state: end.state, summary: redact(end.summary), ...(end.outcome === "cancelled" ? { outcome: end.outcome } : {}) }, { take: [stop.id] });
|
|
380
398
|
await releaseStopped(claim, stop);
|
|
381
399
|
return;
|
|
382
400
|
}
|
|
@@ -386,6 +404,16 @@ export function startRunner(options) {
|
|
|
386
404
|
await store.release(claim, { backoffUntil: now() + wait });
|
|
387
405
|
emit({ type: "released", runId: claim.runId, epoch: claim.epoch, end: "interrupted" });
|
|
388
406
|
};
|
|
407
|
+
/** Whether the run under `claim` never started: its journal has no conversation yet, so no input of it went out. A
|
|
408
|
+
* journal that cannot be read says no (the claim's loop applies the stop as it would). */
|
|
409
|
+
const neverStarted = async (claim) => {
|
|
410
|
+
try {
|
|
411
|
+
return (await store.journal(claim).scanConversations({}, 1, undefined, BACKGROUND_CONTEXT)).items.length === 0;
|
|
412
|
+
}
|
|
413
|
+
catch {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
389
417
|
/** A claim of a run whose stopped end was refused (its untaken stop row has tries): it only ends the run, with no loop,
|
|
390
418
|
* so no turn, model request or tool runs on a run that is stopping. */
|
|
391
419
|
const endRetried = async (claim, stop) => {
|
|
@@ -425,7 +453,8 @@ export function startRunner(options) {
|
|
|
425
453
|
// with why, and a person can raise again or stop it (#1944-5). A claim its spec refuses (ClaimRefused: a handed
|
|
426
454
|
// sign-in that won't read back, an MCP pin refused) never comes here: the loop writes that end itself, final, the run
|
|
427
455
|
// failed in the refusal's words.
|
|
428
|
-
|
|
456
|
+
// A claim refused for good (CLAIM_REFUSED) is no resume to try again: it fails the run below, parked or not.
|
|
457
|
+
if (threw && end.state === "failed" && claim.from === "parked" && end.error.code !== CLAIM_REFUSED)
|
|
429
458
|
return await resumeFailed(held, end.error.message);
|
|
430
459
|
if (threw && end.state === "failed") {
|
|
431
460
|
// A loop that failed with no end written: a person's stop waiting now is the run's end (stopped, its row taken),
|
|
@@ -448,6 +477,9 @@ export function startRunner(options) {
|
|
|
448
477
|
if (row.refused === reason)
|
|
449
478
|
emit({ type: "refused", runId: claim.runId, commandId: row.id, reason });
|
|
450
479
|
}
|
|
480
|
+
// The run's end (a normal completion among them) leaves no browser-released message behind for a follow-up (browser-wait-ended.ts).
|
|
481
|
+
if (store.settings)
|
|
482
|
+
await clearWaitEnded(store.settings, claim.runId, claim.epoch).catch(() => undefined);
|
|
451
483
|
}
|
|
452
484
|
await store.flush();
|
|
453
485
|
// A loop that ended interrupted with no stop asked of it (its Session closed itself) is released with a backoff that
|
|
@@ -515,14 +547,24 @@ export function startRunner(options) {
|
|
|
515
547
|
const delivered = new Promise((resolve) => (firstDelivered = resolve));
|
|
516
548
|
// Set below, once held is made: the loop's end commit lands only after start(), well after.
|
|
517
549
|
let ending = () => { };
|
|
550
|
+
// Set below, once held is made: the loop asks deliverNow only once its first turn has ended, well after.
|
|
551
|
+
let heldNow;
|
|
518
552
|
const loop = loopsOf({
|
|
519
553
|
journal: (forClaim) => fenced(store.journal(forClaim), fence, forClaim.runId, () => ending()),
|
|
520
554
|
flush: () => store.flush(),
|
|
521
555
|
signal: abort.signal,
|
|
522
556
|
delivered,
|
|
557
|
+
// A delivery under way first (its rows are the loop's already), then one more read of the run's new rows.
|
|
558
|
+
deliverNow: async () => {
|
|
559
|
+
if (!heldNow)
|
|
560
|
+
return;
|
|
561
|
+
await heldNow.inFlight?.catch(() => undefined);
|
|
562
|
+
await deliver(heldNow);
|
|
563
|
+
},
|
|
523
564
|
redact,
|
|
524
565
|
});
|
|
525
566
|
const held = { claim, loop, fence, abort, cursor: 0, stopping: false, ending: false, sealed: false, renewing: false, delivering: false, mib };
|
|
567
|
+
heldNow = held;
|
|
526
568
|
// The loop's own end landed: the run is ending from here, its teardown included (no renew, no lost claim).
|
|
527
569
|
ending = () => {
|
|
528
570
|
held.ending = true;
|
|
@@ -539,7 +581,9 @@ export function startRunner(options) {
|
|
|
539
581
|
}
|
|
540
582
|
catch (error) {
|
|
541
583
|
threw = true;
|
|
542
|
-
|
|
584
|
+
// A claim refused before any loop could start (the dispatch's ClaimRefused: a harness this host never holds) is
|
|
585
|
+
// for good: the run fails in its words, whatever woke it.
|
|
586
|
+
end = { state: "failed", error: { code: error instanceof ClaimRefused ? CLAIM_REFUSED : "loop-threw", message: message(error) } };
|
|
543
587
|
}
|
|
544
588
|
await finish(held, end, threw);
|
|
545
589
|
})();
|
|
@@ -560,14 +604,20 @@ export function startRunner(options) {
|
|
|
560
604
|
const sentAt = clock.now();
|
|
561
605
|
const weights = new Map();
|
|
562
606
|
const claims = memory ? await claimByMemory(memory, free, weights) : await store.runs.claimMany(name, free, { leaseMs });
|
|
563
|
-
// A
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
|
|
567
|
-
|
|
607
|
+
// A claim whose run must only end, with no loop (endRetried), so no turn, model request or tool runs on it:
|
|
608
|
+
// - a run stopped or cancelled while it had not started: claimed from queued, or claimed from running when an earlier
|
|
609
|
+
// claim was lost before the run's journal had anything (its runner gone before it wrote a word). Nothing of it
|
|
610
|
+
// starts now, not even its first input: a loop started first would send that input before the stop reached it;
|
|
611
|
+
// - a run whose untaken stop row has tries, which failed to apply that stop before. Either source of tries counts: a
|
|
612
|
+
// refused stopped end (endRefused, released running) or a failed resume (resumeFailed's store.retry, released
|
|
613
|
+
// parked).
|
|
614
|
+
// One read of those claims' rows, made only when the batch has a queued or a released run.
|
|
615
|
+
const reread = claims.filter((claim) => claim.from === "queued" || claim.from === "running" || claim.from === "parked");
|
|
616
|
+
const rows = reread.length ? await store.commandsOf(reread.map((claim) => ({ runId: claim.runId, after: 0 }))) : new Map();
|
|
568
617
|
for (const claim of claims) {
|
|
569
618
|
const stop = endingRow((rows.get(claim.runId) ?? []).filter((row) => row.takenAt === null));
|
|
570
|
-
|
|
619
|
+
const endsOnly = stop !== undefined && (claim.from === "queued" || stop.tries > 0 || (claim.from === "running" && (await neverStarted(claim))));
|
|
620
|
+
if (stop && endsOnly && !closed && !killed && !runs.has(claim.runId)) {
|
|
571
621
|
const ending = endRetried(claim, stop);
|
|
572
622
|
endings.add(ending);
|
|
573
623
|
void ending.finally(() => endings.delete(ending));
|
|
@@ -658,6 +708,52 @@ export function startRunner(options) {
|
|
|
658
708
|
};
|
|
659
709
|
poll();
|
|
660
710
|
commandTimer = setTimeout(deliverAll, commandPollMs);
|
|
711
|
+
/** The untaken stop or cancel row each of `going` ends on (endingRow: a cancel before a stop), past its cursor, by run id:
|
|
712
|
+
* the close's one read of their rows (store.commandsOf), after the deliveries in flight. The whole of it is bounded by
|
|
713
|
+
* the stop margin, so a store that stalls never holds the shutdown: a read that fails or runs past it is said, and those
|
|
714
|
+
* runs are released for a shutdown as before, their rows untaken for the next claim. */
|
|
715
|
+
const closingEnds = async (going) => {
|
|
716
|
+
const ends = new Map();
|
|
717
|
+
if (going.length === 0)
|
|
718
|
+
return ends;
|
|
719
|
+
const read = async () => {
|
|
720
|
+
// A delivery in flight finishes first: it may be handing on that same row.
|
|
721
|
+
await Promise.all(going.map((held) => held.inFlight?.catch(() => undefined)));
|
|
722
|
+
const still = going.filter((held) => !held.stopping && !held.ending && !held.fence.lost);
|
|
723
|
+
if (still.length === 0)
|
|
724
|
+
return ends;
|
|
725
|
+
const rows = await store.commandsOf(still.map((held) => ({ runId: held.claim.runId, after: held.cursor })));
|
|
726
|
+
const found = new Map();
|
|
727
|
+
for (const held of still) {
|
|
728
|
+
const end = endingRow((rows.get(held.claim.runId) ?? []).filter((row) => row.takenAt === null));
|
|
729
|
+
if (end)
|
|
730
|
+
found.set(held.claim.runId, end);
|
|
731
|
+
}
|
|
732
|
+
return found;
|
|
733
|
+
};
|
|
734
|
+
let bound;
|
|
735
|
+
// Within the close's stop window (the lease less its margin), whatever the margin.
|
|
736
|
+
const boundMs = Math.min(stopMarginMs, leaseMs - stopMarginMs);
|
|
737
|
+
const late = new Promise((resolve) => (bound = setTimeout(() => resolve("late"), boundMs)));
|
|
738
|
+
// A read that fails after the bound is never an unhandled rejection: the close has moved on without it.
|
|
739
|
+
const reading = read();
|
|
740
|
+
reading.catch(() => undefined);
|
|
741
|
+
try {
|
|
742
|
+
const found = await Promise.race([reading, late]);
|
|
743
|
+
if (found !== "late")
|
|
744
|
+
return found;
|
|
745
|
+
for (const held of going)
|
|
746
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: `the close's read of its stop rows took longer than ${boundMs} ms: released for the next claim` });
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
for (const held of going)
|
|
750
|
+
emit({ type: "error", runId: held.claim.runId, step: "commands", message: message(error) });
|
|
751
|
+
}
|
|
752
|
+
finally {
|
|
753
|
+
clearTimeout(bound);
|
|
754
|
+
}
|
|
755
|
+
return ends;
|
|
756
|
+
};
|
|
661
757
|
const stopTimers = () => {
|
|
662
758
|
clearTimeout(pollTimer);
|
|
663
759
|
clearTimeout(commandTimer);
|
|
@@ -689,17 +785,38 @@ export function startRunner(options) {
|
|
|
689
785
|
draining = false;
|
|
690
786
|
clearTimeout(commandTimer);
|
|
691
787
|
const live = [...runs.values()].filter((held) => !held.fence.lost);
|
|
788
|
+
// One window for the stop after the drain, the one runnerCloseBoundMs counts (the lease less its margin): the read
|
|
789
|
+
// below and the loops' stop share it, so the close is never longer than a deployment's stop grace allows for.
|
|
790
|
+
const stopBy = Date.now() + leaseMs - stopMarginMs;
|
|
791
|
+
// A stop or cancel a person sent before the close is the run's end, never a resume: one no delivery has handed on
|
|
792
|
+
// yet (the command poll's tick had not come) is read here, once, for every run still going, and stops its loop as
|
|
793
|
+
// its delivery would. Its end is in the store when the close is done, and the next start never resumes the turn.
|
|
794
|
+
const ends = await closingEnds(live.filter((held) => !held.ending && !held.stopping));
|
|
692
795
|
for (const held of live) {
|
|
693
|
-
if (
|
|
694
|
-
|
|
695
|
-
|
|
796
|
+
if (held.ending)
|
|
797
|
+
continue;
|
|
798
|
+
const end = ends.get(held.claim.runId);
|
|
799
|
+
if (end && !held.stopping) {
|
|
800
|
+
held.cursor = Math.max(held.cursor, end.id);
|
|
801
|
+
stopLoop(held, { kind: "command", commandId: end.id, ...(end.kind === "cancel" ? { cancel: true } : {}) });
|
|
696
802
|
}
|
|
803
|
+
// A loop a stop or cancel already stops writes that end: it is never cut for the close.
|
|
804
|
+
if (held.stopping)
|
|
805
|
+
continue;
|
|
806
|
+
stopLoop(held, { kind: "shutdown" });
|
|
807
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
697
808
|
}
|
|
698
|
-
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out
|
|
809
|
+
// Claims are renewed while the loops stop; a loop that never stops is given up when its claim would run out (the end
|
|
810
|
+
// of the window the read above began).
|
|
699
811
|
let timeout;
|
|
700
|
-
const late = new Promise((resolve) => (timeout = setTimeout(resolve,
|
|
812
|
+
const late = new Promise((resolve) => (timeout = setTimeout(resolve, Math.max(0, stopBy - Date.now()))));
|
|
701
813
|
await Promise.race([Promise.all([...live.map((held) => held.done), ...endings]), late]);
|
|
702
814
|
clearTimeout(timeout);
|
|
815
|
+
// A loop still going at the window's end (one a stop row stops, whose signal was kept whole for its end) has its
|
|
816
|
+
// signal aborted before its claim is given up: no request of it outlives the close.
|
|
817
|
+
for (const held of live)
|
|
818
|
+
if (!held.ending && !held.abort.signal.aborted)
|
|
819
|
+
held.abort.abort(new Error("the runner is closing"));
|
|
703
820
|
for (const held of runs.values())
|
|
704
821
|
held.fence.lost = true;
|
|
705
822
|
stopTimers();
|
|
@@ -3,6 +3,10 @@ type Held = {
|
|
|
3
3
|
readonly tools?: {
|
|
4
4
|
end(): Promise<void>;
|
|
5
5
|
};
|
|
6
|
+
/** The run's checkout of its pull request (pr-checkout.ts), removed from its folder while the Workspace still answers. */
|
|
7
|
+
readonly checkout?: {
|
|
8
|
+
end(): Promise<void>;
|
|
9
|
+
} | undefined;
|
|
6
10
|
readonly computer?: {
|
|
7
11
|
release(): Promise<void>;
|
|
8
12
|
};
|
|
@@ -16,6 +20,11 @@ type Held = {
|
|
|
16
20
|
readonly keys?: {
|
|
17
21
|
release(): void;
|
|
18
22
|
} | undefined;
|
|
23
|
+
/** The CLI's files on this machine for this claim (its private folder in the run's scratch), swept once the rest is let
|
|
24
|
+
* go: every claim lays its own again, the harness's state coming back from the run's journal. */
|
|
25
|
+
readonly scratch?: {
|
|
26
|
+
sweep(): Promise<void>;
|
|
27
|
+
} | undefined;
|
|
19
28
|
/** What the spec hands the loop, which lets it go itself (the claim's MCP): let go here only when the build throws. */
|
|
20
29
|
readonly passed?: {
|
|
21
30
|
release(): void;
|
|
@@ -28,9 +37,10 @@ export declare class SpecHolds {
|
|
|
28
37
|
logTo(log: (line: string) => void): void;
|
|
29
38
|
/** `parts`, held from now until the release. */
|
|
30
39
|
hold(parts: Held): void;
|
|
31
|
-
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the
|
|
32
|
-
* mount credential (idempotent: the computer's release revokes it too), the
|
|
33
|
-
* where they are held. A second call waits for the first and
|
|
40
|
+
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the pull request's
|
|
41
|
+
* checkout removed, the computer, the Archil mount credential (idempotent: the computer's release revokes it too), the
|
|
42
|
+
* Workspace's end, the CLI's scratch, then the claim's keys where they are held. A second call waits for the first and
|
|
43
|
+
* does nothing more. */
|
|
34
44
|
release(): Promise<void>;
|
|
35
45
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
36
46
|
releasePassed(): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// What a run's spec holds from its claim until its release: the run's tools, its
|
|
2
|
-
// and its Workspace, each kept here as the spec builder makes it (adapter-run-spec.ts and
|
|
3
|
-
// release lets them go, in that order, each step's failure logged and the next still taken.
|
|
4
|
-
// part-way never hands the loop a spec to release, so specBuilt lets go what was made by then, the
|
|
5
|
-
// the builder's own error unchanged: a credential minted for the run is revoked and a computer made
|
|
6
|
-
// left to the credential's 24 h ttl or the computer's lifetime. Each is let go at most once.
|
|
1
|
+
// What a run's spec holds from its claim until its release: the run's tools, its pull request's checkout, its computer,
|
|
2
|
+
// its Archil mount credential and its Workspace, each kept here as the spec builder makes it (adapter-run-spec.ts and
|
|
3
|
+
// cli-run-spec.ts). The spec's release lets them go, in that order, each step's failure logged and the next still taken.
|
|
4
|
+
// A builder that throws part-way never hands the loop a spec to release, so specBuilt lets go what was made by then, the
|
|
5
|
+
// same way, and throws the builder's own error unchanged: a credential minted for the run is revoked and a computer made
|
|
6
|
+
// for it let go, never left to the credential's 24 h ttl or the computer's lifetime. Each is let go at most once.
|
|
7
7
|
const words = (error) => error?.message ?? String(error);
|
|
8
8
|
/** The parts a run's spec holds, and their one release. */
|
|
9
9
|
export class SpecHolds {
|
|
@@ -18,19 +18,22 @@ export class SpecHolds {
|
|
|
18
18
|
hold(parts) {
|
|
19
19
|
this.#held = { ...this.#held, ...parts };
|
|
20
20
|
}
|
|
21
|
-
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the
|
|
22
|
-
* mount credential (idempotent: the computer's release revokes it too), the
|
|
23
|
-
* where they are held. A second call waits for the first and
|
|
21
|
+
/** Everything held let go, once: the tools' end (background processes ended, scratch swept), the pull request's
|
|
22
|
+
* checkout removed, the computer, the Archil mount credential (idempotent: the computer's release revokes it too), the
|
|
23
|
+
* Workspace's end, the CLI's scratch, then the claim's keys where they are held. A second call waits for the first and
|
|
24
|
+
* does nothing more. */
|
|
24
25
|
release() {
|
|
25
26
|
return (this.#released ??= this.#releaseAll());
|
|
26
27
|
}
|
|
27
28
|
async #releaseAll() {
|
|
28
|
-
const { tools, computer, archil, ws, keys } = this.#held;
|
|
29
|
+
const { tools, checkout, computer, archil, ws, scratch, keys } = this.#held;
|
|
29
30
|
const log = this.#log;
|
|
30
31
|
await tools?.end().catch((error) => log(`the run's tools' end failed: ${words(error)}`));
|
|
32
|
+
await checkout?.end().catch((error) => log(words(error)));
|
|
31
33
|
await computer?.release().catch((error) => log(`the run's computer could not be let go: ${words(error)}`));
|
|
32
34
|
await archil?.revoke().catch((error) => log(`the run's Archil mount credential could not be revoked: ${words(error)}`));
|
|
33
35
|
await ws?.end().catch((error) => log(`the run's workspace end failed: ${words(error)}`));
|
|
36
|
+
await scratch?.sweep().catch((error) => log(`the run's scratch folder could not be swept: ${words(error)}`));
|
|
34
37
|
keys?.release();
|
|
35
38
|
}
|
|
36
39
|
/** What the spec would have handed the loop, let go: only a build that throws calls it. */
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { type Store } from "../store/store.js";
|
|
2
2
|
export type RunnerStore = Pick<Store, "claim" | "renew" | "renewMany" | "release" | "journal" | "flush" | "commands" | "commandsOf" | "take" | "retry"> & {
|
|
3
|
-
readonly runs: Pick<Store["runs"], "claimMany" | "claimable" | "update"
|
|
3
|
+
readonly runs: Pick<Store["runs"], "claimMany" | "claimable" | "update"> & Partial<Pick<Store["runs"], "launch">>;
|
|
4
4
|
/** The runs' live view (run_live): the runner's live ticker writes each run's held state there. A store without it (a
|
|
5
5
|
* test's) has no live view. */
|
|
6
6
|
readonly live?: Store["live"];
|
|
7
|
+
/** The server's settings, for the one the runner removes at a run's end (browser-wait-ended.ts). A store without it (a
|
|
8
|
+
* test's) keeps none. */
|
|
9
|
+
readonly settings?: Store["settings"];
|
|
7
10
|
};
|
|
8
11
|
/** The store's fence: a write under an epoch that moved. */
|
|
9
12
|
export declare function isFenced(error: unknown): boolean;
|
|
@@ -50,6 +50,22 @@ function jsonSecrets(text) {
|
|
|
50
50
|
walk(value);
|
|
51
51
|
return out;
|
|
52
52
|
}
|
|
53
|
+
/** A launch's sealed JSON: its own listed values (jsonSecrets), and each handed MCP credential's headers (store/seal.ts
|
|
54
|
+
* sealRunMcpAuth: `{"mcp": {"<server>": {"headers": {...}}}}`), as a saved server's are listed. */
|
|
55
|
+
function launchSecrets(text) {
|
|
56
|
+
const out = jsonSecrets(text);
|
|
57
|
+
let mcp;
|
|
58
|
+
try {
|
|
59
|
+
mcp = JSON.parse(text)?.mcp;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
if (mcp && typeof mcp === "object")
|
|
65
|
+
for (const entry of Object.values(mcp))
|
|
66
|
+
out.push(...jsonSecrets(JSON.stringify(entry)));
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
53
69
|
/** A PEM key whole, and each of its base64 lines (the short last one too), as the server lists one (sealed-settings-store.ts). */
|
|
54
70
|
const pemForms = (value) => [value, ...value.split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("-----"))];
|
|
55
71
|
/** What of one opened sealed value is a secret to hold, by its plane: `listed` with the server list's floor and spellings,
|
|
@@ -66,7 +82,7 @@ function secretsOf(row, plain, adapters) {
|
|
|
66
82
|
case "mcp_oauth_pending":
|
|
67
83
|
return { listed: jsonSecrets(plain), whole: [] };
|
|
68
84
|
case "run_launch":
|
|
69
|
-
return { listed: plain.trimStart().startsWith("{") ?
|
|
85
|
+
return { listed: plain.trimStart().startsWith("{") ? launchSecrets(plain) : [plain], whole: [] };
|
|
70
86
|
default:
|
|
71
87
|
return { listed: [plain], whole: [] };
|
|
72
88
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ModelRef, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
2
|
+
export declare const SUBAGENT_TOOL = "subagent";
|
|
3
|
+
/** The tiers a call may name for its child (its definition's model_tiers, else this server's tier); a call that names
|
|
4
|
+
* none runs its child on the agent's own model. */
|
|
5
|
+
export declare const SUBAGENT_TIERS: readonly ["fast", "strong"];
|
|
6
|
+
export type SubagentTier = (typeof SUBAGENT_TIERS)[number];
|
|
7
|
+
/** How many of a run's children work at once; a call past it waits for a slot. */
|
|
8
|
+
export declare const SUBAGENT_PARALLEL = 4;
|
|
9
|
+
/** A child's instructions: the call's prompt is its whole task. Nothing of the parent's prompt is carried over. */
|
|
10
|
+
export declare const SUBAGENT_INSTRUCTIONS = "You are a subagent. The message you are given is your whole task: do it with the tools you have, then answer. Your last message is returned, as it is, to the agent that called you.";
|
|
11
|
+
/** The thinking levels a call may give its child (`effort`); absent, the child thinks at the agent's own level. */
|
|
12
|
+
export declare const SUBAGENT_EFFORTS: readonly ["low", "medium", "high"];
|
|
13
|
+
/** A tier's model in this run: its ref in the run's models (adapters/pi.ts tierProvider), or why the tier has none here. */
|
|
14
|
+
export type TierModel = {
|
|
15
|
+
readonly ref: ModelRef;
|
|
16
|
+
} | {
|
|
17
|
+
readonly why: string;
|
|
18
|
+
};
|
|
19
|
+
export type SubagentOptions = {
|
|
20
|
+
/** The tools the agent was granted, by catalog name (`read`, `mcp:github/get_file_contents`): a call's subset of them. */
|
|
21
|
+
readonly granted: readonly string[];
|
|
22
|
+
/** A granted tool's names in the run's session (catalog.ts wireName; the browser's registrations for `browser`). */
|
|
23
|
+
readonly sessionNames: (catalog: string) => readonly string[];
|
|
24
|
+
/** The tier's model, resolved at the claim. */
|
|
25
|
+
readonly tier: (tier: SubagentTier) => TierModel;
|
|
26
|
+
/** Words before a child's own instructions (the environment line), when the host has any. */
|
|
27
|
+
readonly preamble?: string;
|
|
28
|
+
/** The agent's tool-call budget (definition.max_tool_calls, tool-budget.ts), per conversation: a call's own narrows it
|
|
29
|
+
* for its child, never widens it. */
|
|
30
|
+
readonly toolCalls?: number;
|
|
31
|
+
};
|
|
32
|
+
/** `text` within the host's bound on a tool result (HOST_RESULT_MAX_CHARS), saying where it was cut. */
|
|
33
|
+
export declare function boundedAnswer(text: string): string;
|
|
34
|
+
/** The catalog names of `asked` (each a catalog or session name of a granted tool) and the session names the child gets,
|
|
35
|
+
* or what is wrong with them. A catalog name gives every session name of its tool (`browser`: each browser tool); a
|
|
36
|
+
* session name gives that one alone (`browser_read`: never the rest of the browser's). */
|
|
37
|
+
export declare function chosenTools(asked: readonly string[], options: Pick<SubagentOptions, "granted" | "sessionNames">): {
|
|
38
|
+
catalog: string[];
|
|
39
|
+
names: string[];
|
|
40
|
+
} | {
|
|
41
|
+
refused: string;
|
|
42
|
+
};
|
|
43
|
+
/** The subagent tool: one of the session's own tools (adapters/pi.ts `tools`), so it needs no extension of its own. */
|
|
44
|
+
export declare function subagentTool(options: SubagentOptions): ToolRegistration;
|