@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/stop-signals.d.ts
CHANGED
|
@@ -15,8 +15,10 @@ export type StopDeps = {
|
|
|
15
15
|
export declare const REPEAT_MS = 1000;
|
|
16
16
|
/** How long past its runs' drain bound a stop may take before it stops at once. */
|
|
17
17
|
export declare const DEADLINE_MARGIN_MS = 15000;
|
|
18
|
-
/** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once.
|
|
18
|
+
/** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. `askedAt`: when
|
|
19
|
+
* the stop was asked, when earlier than this call (a signal during the start, cli.ts), so a second signal is timed from
|
|
20
|
+
* the first. */
|
|
19
21
|
export declare function stopOnSignals(deps: StopDeps, { repeatMs, marginMs }?: {
|
|
20
22
|
repeatMs?: number | undefined;
|
|
21
23
|
marginMs?: number | undefined;
|
|
22
|
-
}): () => void;
|
|
24
|
+
}): (askedAt?: number) => void;
|
package/dist/stop-signals.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
export const REPEAT_MS = 1_000;
|
|
8
8
|
/** How long past its runs' drain bound a stop may take before it stops at once. */
|
|
9
9
|
export const DEADLINE_MARGIN_MS = 15_000;
|
|
10
|
-
/** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once.
|
|
10
|
+
/** The handler for SIGINT and SIGTERM. It exits once: 0 when the close ends, 130 when it stops at once. `askedAt`: when
|
|
11
|
+
* the stop was asked, when earlier than this call (a signal during the start, cli.ts), so a second signal is timed from
|
|
12
|
+
* the first. */
|
|
11
13
|
export function stopOnSignals(deps, { repeatMs = REPEAT_MS, marginMs = DEADLINE_MARGIN_MS } = {}) {
|
|
12
14
|
const now = deps.now ?? Date.now;
|
|
13
15
|
const setTimer = deps.setTimer ?? ((run, ms) => void setTimeout(run, ms).unref());
|
|
@@ -25,13 +27,13 @@ export function stopOnSignals(deps, { repeatMs = REPEAT_MS, marginMs = DEADLINE_
|
|
|
25
27
|
const { runs } = deps.stopping();
|
|
26
28
|
end(130, `${why}; runs resume on the next start${runs > 0 ? ` (${runs} ${runs === 1 ? "was" : "were"} running)` : ""}`);
|
|
27
29
|
};
|
|
28
|
-
return () => {
|
|
30
|
+
return (askedAt) => {
|
|
29
31
|
if (stopAt !== undefined) {
|
|
30
32
|
if (now() - stopAt >= repeatMs)
|
|
31
33
|
stopNow("stopping now");
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
|
-
stopAt = now();
|
|
36
|
+
stopAt = askedAt ?? now();
|
|
35
37
|
setTimer(() => stopNow("the stop passed its deadline, stopping now"), deps.stopping().boundMs + marginMs);
|
|
36
38
|
void deps.close().then(() => end(0));
|
|
37
39
|
};
|
|
@@ -27,35 +27,43 @@ export type RevisionPlace = {
|
|
|
27
27
|
box?: string;
|
|
28
28
|
};
|
|
29
29
|
/** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows, and a
|
|
30
|
-
* sandbox's GPUs, a type its provider names and how many; `place` is its v2 view.
|
|
30
|
+
* sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. `image`: one the provider offers for
|
|
31
|
+
* the kind, absent for its default. */
|
|
31
32
|
export type RevisionComputer = {
|
|
32
33
|
kind: string;
|
|
33
34
|
provider?: string;
|
|
35
|
+
image?: string;
|
|
34
36
|
gpu?: {
|
|
35
37
|
type: string;
|
|
36
38
|
count: number;
|
|
37
39
|
};
|
|
40
|
+
persistent?: boolean;
|
|
38
41
|
};
|
|
39
42
|
/** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
|
|
40
43
|
* pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
|
|
41
44
|
* canonicalToolSettings, the one copy). The store body holds it as it is given; this validator never reimplements it. */
|
|
42
45
|
export type ToolSettings = Record<string, unknown>;
|
|
46
|
+
/** The model of each tier an agentic revision names (its definition's `model_tiers`: fast, strong), each "provider/model-id". */
|
|
47
|
+
export type ModelTiers = Partial<Record<"fast" | "strong", string>>;
|
|
43
48
|
export type AgenticBody = {
|
|
44
49
|
instructions: string;
|
|
45
50
|
skills: Record<string, string>;
|
|
46
51
|
tools: string[];
|
|
47
52
|
model?: string;
|
|
53
|
+
modelTiers?: ModelTiers;
|
|
48
54
|
thinking?: string;
|
|
49
55
|
prompts?: Record<string, PromptVariant>;
|
|
50
56
|
harness?: string;
|
|
51
57
|
place?: RevisionPlace;
|
|
52
58
|
computer?: RevisionComputer;
|
|
53
|
-
learning?: boolean;
|
|
59
|
+
learning?: boolean | "notes";
|
|
54
60
|
toolSettings?: ToolSettings;
|
|
55
61
|
maxCostUsd?: number;
|
|
56
62
|
capMode?: string;
|
|
57
63
|
approvals?: "ask" | "never";
|
|
58
64
|
outputSchema?: Record<string, unknown>;
|
|
65
|
+
maxToolCalls?: number;
|
|
66
|
+
checkout?: "pull_request";
|
|
59
67
|
};
|
|
60
68
|
export type WorkflowBody = {
|
|
61
69
|
workflow: Record<string, unknown>;
|
|
@@ -77,17 +85,20 @@ export type RevisionBodyInput = {
|
|
|
77
85
|
skills?: Record<string, string>;
|
|
78
86
|
tools?: string[];
|
|
79
87
|
model?: string;
|
|
88
|
+
modelTiers?: ModelTiers;
|
|
80
89
|
thinking?: string;
|
|
81
90
|
prompts?: Record<string, PromptVariant>;
|
|
82
91
|
harness?: string;
|
|
83
92
|
place?: unknown;
|
|
84
93
|
computer?: unknown;
|
|
85
|
-
learning?: boolean;
|
|
94
|
+
learning?: boolean | "notes";
|
|
86
95
|
toolSettings?: ToolSettings;
|
|
87
96
|
maxCostUsd?: number;
|
|
88
97
|
capMode?: string;
|
|
89
98
|
approvals?: "ask" | "never";
|
|
90
99
|
outputSchema?: Record<string, unknown>;
|
|
100
|
+
maxToolCalls?: number;
|
|
101
|
+
checkout?: "pull_request";
|
|
91
102
|
} | {
|
|
92
103
|
kind: "workflow";
|
|
93
104
|
workflow: unknown;
|
package/dist/store/agent-body.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The agent body validator (
|
|
1
|
+
// The agent body validator (with canonical JSON): what
|
|
2
2
|
// a revision's stored body may be, checked before anything is written, so a refusal makes no agent and no revision. It is
|
|
3
3
|
// the one check the control plane runs over a revision's body, kept with the store (A) it writes into. The body keeps a
|
|
4
4
|
// skill path to its text's SHA-256 (two revisions with the same files are one body); the texts ride beside it on the
|
|
@@ -44,18 +44,21 @@ function placeOf(place) {
|
|
|
44
44
|
}
|
|
45
45
|
/** A GPU type as a body keeps it: the vendor's own name ("T4", "A100-80GB", "RTX-PRO-6000"). */
|
|
46
46
|
const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
47
|
-
/** A computer as a body keeps it: `{kind, provider?, gpu?}`, nothing else: kind and provider ids,
|
|
48
|
-
* a GPU type name and a whole count from 1
|
|
47
|
+
/** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?}`, nothing else: kind and provider ids,
|
|
48
|
+
* image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole count from 1, and persistent a
|
|
49
|
+
* boolean. */
|
|
49
50
|
function computerOf(computer) {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const image = isObject(computer) ? computer.image : undefined;
|
|
52
|
+
const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
|
|
53
|
+
if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || (computer.persistent !== undefined && typeof computer.persistent !== "boolean") || Object.keys(computer).some((key) => key !== "kind" && key !== "provider" && key !== "image" && key !== "gpu" && key !== "persistent"))
|
|
54
|
+
invalid("the computer is not {kind, provider?, image?, gpu?, persistent?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean");
|
|
52
55
|
const ok = computer;
|
|
53
56
|
const gpu = ok.gpu;
|
|
54
57
|
if (gpu !== undefined && (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count") || typeof gpu.type !== "string" || !GPU_TYPE.test(gpu.type) || !Number.isSafeInteger(gpu.count) || gpu.count < 1)) {
|
|
55
58
|
invalid("the computer's gpu is not {type, count}: a GPU type name (letters, digits, dots, underscores and dashes) and a whole count from 1");
|
|
56
59
|
}
|
|
57
60
|
const kept = gpu;
|
|
58
|
-
return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}) };
|
|
61
|
+
return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}) };
|
|
59
62
|
}
|
|
60
63
|
/** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
|
|
61
64
|
* write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
|
|
@@ -107,21 +110,32 @@ export function bodyOf(input) {
|
|
|
107
110
|
for (const field of ["model", "thinking"])
|
|
108
111
|
if (input[field] !== undefined && (typeof input[field] !== "string" || input[field] === ""))
|
|
109
112
|
invalid(`the ${field} is not a non-empty string`);
|
|
110
|
-
if (input.learning !== undefined && typeof input.learning !== "boolean")
|
|
111
|
-
invalid("learning is not true or
|
|
113
|
+
if (input.learning !== undefined && typeof input.learning !== "boolean" && input.learning !== "notes")
|
|
114
|
+
invalid("learning is not true, false or \"notes\"");
|
|
112
115
|
if (input.outputSchema !== undefined && !isObject(input.outputSchema))
|
|
113
116
|
invalid("the outputSchema is not a JSON object");
|
|
117
|
+
if (input.checkout !== undefined && input.checkout !== "pull_request")
|
|
118
|
+
invalid("the checkout is not pull_request");
|
|
119
|
+
if (input.modelTiers !== undefined && !(isObject(input.modelTiers) && Object.keys(input.modelTiers).length && Object.entries(input.modelTiers).every(([tier, ref]) => (tier === "fast" || tier === "strong") && typeof ref === "string" && ref !== "")))
|
|
120
|
+
invalid("the modelTiers are not fast and strong to a non-empty model");
|
|
121
|
+
if (input.maxToolCalls !== undefined && !(Number.isSafeInteger(input.maxToolCalls) && input.maxToolCalls > 0))
|
|
122
|
+
invalid("the maxToolCalls is not a whole number above 0");
|
|
114
123
|
const body = {
|
|
115
124
|
instructions: input.instructions,
|
|
116
125
|
skills: skillShas,
|
|
117
126
|
tools: [...tools],
|
|
118
127
|
...(input.model !== undefined ? { model: input.model } : {}),
|
|
128
|
+
...(input.modelTiers !== undefined ? { modelTiers: Object.fromEntries(Object.entries(input.modelTiers).sort(([a], [b]) => a.localeCompare(b))) } : {}),
|
|
119
129
|
...(input.thinking !== undefined ? { thinking: input.thinking } : {}),
|
|
120
130
|
...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
|
|
121
131
|
...host,
|
|
122
132
|
...(input.learning !== undefined ? { learning: input.learning } : {}),
|
|
123
133
|
// The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
|
|
124
134
|
...(input.outputSchema !== undefined ? { outputSchema: structuredClone(input.outputSchema) } : {}),
|
|
135
|
+
// What the server checks out in each run's folder before its first turn (runner/pr-checkout.ts).
|
|
136
|
+
...(input.checkout !== undefined ? { checkout: input.checkout } : {}),
|
|
137
|
+
// The tool calls each conversation of its runs may make (tool-budget.ts).
|
|
138
|
+
...(input.maxToolCalls !== undefined ? { maxToolCalls: input.maxToolCalls } : {}),
|
|
125
139
|
// The agent's unattended policy (PR #2003): the runner's gate reads it from the revision body at claim (`unattended`
|
|
126
140
|
// below: "never" alone is kept).
|
|
127
141
|
...capped,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** How often an open transaction's deadline looks at the process's event loop, and how far past its look a look may
|
|
2
|
+
* come before the gap counts as the process held up (runnableDeadline). */
|
|
3
|
+
export declare const TICK_MS = 50;
|
|
4
|
+
export declare const STALL_MS = 50;
|
|
5
|
+
/** A running deadline: `clear()` stops it; `held()` is the time it gave back so far, the process held up, so a bound
|
|
6
|
+
* reckoned from the deadline's due time (a Postgres commit's) moves with it. A hold that ended since the last look is
|
|
7
|
+
* counted as `held()` reads it, never left for a look that would come after the bound was reckoned. */
|
|
8
|
+
export type RunnableDeadline = {
|
|
9
|
+
clear(): void;
|
|
10
|
+
held(): number;
|
|
11
|
+
};
|
|
12
|
+
/** Calls `expire` once `ms` of the time this process could run have passed, counted from now on the monotonic clock
|
|
13
|
+
* (performance.now: the host's clock set forward or back is never counted). A look every TICK_MS measures the event
|
|
14
|
+
* loop: a gap more than STALL_MS past its look was the process held up by other work (a harness binary hashed, a
|
|
15
|
+
* command run synchronously, the machine holding the process), wherever in the transaction it fell, before its
|
|
16
|
+
* deadline or across it, and is not counted. A wait of the transaction's own (a call awaited inside it) leaves the
|
|
17
|
+
* loop free, so it counts in full and is refused on time. */
|
|
18
|
+
export declare function runnableDeadline(ms: number, expire: () => void): RunnableDeadline;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A store transaction's deadline counted from its begin, the one rule both connections keep (sqlite/connection.ts,
|
|
2
|
+
// postgres/connection.ts): only the time this process could run counts. One counted from its call (a lease's renew, a
|
|
3
|
+
// fromCall transaction) stays each connection's wall-clock timer.
|
|
4
|
+
/** How often an open transaction's deadline looks at the process's event loop, and how far past its look a look may
|
|
5
|
+
* come before the gap counts as the process held up (runnableDeadline). */
|
|
6
|
+
export const TICK_MS = 50;
|
|
7
|
+
export const STALL_MS = 50;
|
|
8
|
+
/** Calls `expire` once `ms` of the time this process could run have passed, counted from now on the monotonic clock
|
|
9
|
+
* (performance.now: the host's clock set forward or back is never counted). A look every TICK_MS measures the event
|
|
10
|
+
* loop: a gap more than STALL_MS past its look was the process held up by other work (a harness binary hashed, a
|
|
11
|
+
* command run synchronously, the machine holding the process), wherever in the transaction it fell, before its
|
|
12
|
+
* deadline or across it, and is not counted. A wait of the transaction's own (a call awaited inside it) leaves the
|
|
13
|
+
* loop free, so it counts in full and is refused on time. */
|
|
14
|
+
export function runnableDeadline(ms, expire) {
|
|
15
|
+
// Cleared with the functions they were set with: a caller that swaps the global timers while a transaction is open
|
|
16
|
+
// (node:test's mocked timers, enabled mid-run) would otherwise clear nothing, and the look's interval would hold the
|
|
17
|
+
// process open for good.
|
|
18
|
+
const [after, every, cancel, stop] = [setTimeout, setInterval, clearTimeout, clearInterval];
|
|
19
|
+
const start = performance.now();
|
|
20
|
+
let last = start;
|
|
21
|
+
let held = 0;
|
|
22
|
+
const look = () => {
|
|
23
|
+
const now = performance.now();
|
|
24
|
+
const gap = now - last - TICK_MS;
|
|
25
|
+
if (gap > STALL_MS)
|
|
26
|
+
held += gap;
|
|
27
|
+
last = now;
|
|
28
|
+
return now;
|
|
29
|
+
};
|
|
30
|
+
const ticks = every(look, TICK_MS);
|
|
31
|
+
let timer;
|
|
32
|
+
const check = () => {
|
|
33
|
+
const left = ms - (look() - start - held);
|
|
34
|
+
if (left <= 0)
|
|
35
|
+
return expire();
|
|
36
|
+
timer = after(check, Math.ceil(left));
|
|
37
|
+
};
|
|
38
|
+
timer = after(check, ms);
|
|
39
|
+
return {
|
|
40
|
+
clear: () => {
|
|
41
|
+
stop(ticks);
|
|
42
|
+
cancel(timer);
|
|
43
|
+
},
|
|
44
|
+
held: () => {
|
|
45
|
+
look();
|
|
46
|
+
return held;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
|
|
1
|
+
export { AgentArchived, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull } from "./store.js";
|
|
2
2
|
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerWrite, NewFiring, NewRevision, NewTrigger, ReleasedState, RevisionRow, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
3
|
-
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, sealColumn, type SealedAt, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
|
|
4
|
-
export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
|
|
3
|
+
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunMcpAuth, type RunMcpAuth, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
|
+
export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type ModelTiers, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
|
|
5
5
|
export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
|
|
6
6
|
export { DDL, PI_DDL, PI_TABLE, PI_TABLES, SCHEMA_VERSION, STORE_DDL } from "./schema.js";
|
|
7
7
|
export { RunStorage } from "./journal/storage.js";
|
package/dist/store/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The one store (design 2.1), for the cutover: nothing on main imports it until then.
|
|
2
|
-
export { AgentArchived, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, TriggerFull } from "./store.js";
|
|
3
|
-
export { aadOf, openMcpCredential, sealColumn, sealedAt, sealMcpCredential, unsealColumn } from "./seal.js";
|
|
2
|
+
export { AgentArchived, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull } from "./store.js";
|
|
3
|
+
export { aadOf, openMcpCredential, openRunMcpAuth, sealColumn, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
4
|
export { AgentBodyInvalid, bodyOf, canonical, isObject, isSkillPath, sha256, } from "./agent-body.js";
|
|
5
5
|
export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
|
|
6
6
|
export { DDL, PI_DDL, PI_TABLE, PI_TABLES, SCHEMA_VERSION, STORE_DDL } from "./schema.js";
|
|
@@ -315,8 +315,9 @@ export class RunStorage {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
// A run patch that made the run final: its other untaken rows are refused in this commit, after its own takes.
|
|
318
|
+
// A person's message that came while it was ending opens a completed run again instead (refuseLeftovers).
|
|
318
319
|
if (patching)
|
|
319
|
-
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now);
|
|
320
|
+
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now, this.#dialect);
|
|
320
321
|
}
|
|
321
322
|
});
|
|
322
323
|
this.#nextId = Math.max(this.#nextId, candidateNextId);
|
|
@@ -58,6 +58,10 @@ export declare class Unanswered extends Error {
|
|
|
58
58
|
* (a runner's 35 s graceful stop, the server's own) instead of exiting, and a lost lock is never a 503 forever. */
|
|
59
59
|
export declare const OWNER_WAIT_MS = 120000;
|
|
60
60
|
export declare function numberParams(sql: string): string;
|
|
61
|
+
/** A Postgres error as the store's own: a refused row StoreConstraint, a lock or a conflict StoreBusy. */
|
|
62
|
+
/** Whether `error` says the database ended the session (its idle-in-transaction timeout, SQLSTATE 25P03), or that the
|
|
63
|
+
* connection is gone and takes no more statements: a transaction's work on it was rolled back by the database. */
|
|
64
|
+
export declare function sessionEnded(error: unknown): boolean;
|
|
61
65
|
export declare class PgConnection implements StoreConnection {
|
|
62
66
|
#private;
|
|
63
67
|
readonly dialect: Dialect;
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
// no row rolls its transaction back with the typed error, as SQLite's worker does. A server's connection also holds the
|
|
6
6
|
// store's owner lock (one server per schema): a session advisory lock on a client of its own, held until close.
|
|
7
7
|
import pg from "pg";
|
|
8
|
+
import { runnableDeadline } from "../deadline.js";
|
|
8
9
|
import { cleanText } from "../dialect.js";
|
|
9
|
-
import {
|
|
10
|
+
import { ONE_ANSWER_INDEX } from "../schema.js";
|
|
11
|
+
import { AnswerTaken, Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned } from "../store.js";
|
|
10
12
|
import { DEFAULT_TRANSACTION_DEADLINE_MS } from "../sqlite/connection.js";
|
|
11
13
|
import { postgresDialect } from "./dialect.js";
|
|
12
14
|
/** Which store this is, as two opens of the same data agree on it (StoreConnection.where): "postgres:" and the URL's host
|
|
@@ -207,16 +209,29 @@ function bound(value) {
|
|
|
207
209
|
const returnsRows = (sql) => /^\s*(?:SELECT|WITH)\b/i.test(sql) || /\bRETURNING\b/i.test(sql);
|
|
208
210
|
/** Postgres's integrity SQLSTATEs, by the rule they name. */
|
|
209
211
|
const RULES = { "23514": "check", "23505": "unique", "23503": "foreign_key", "23502": "not_null" };
|
|
210
|
-
/** A unique violation's table and
|
|
211
|
-
* a primary key's is an index of the same name), read from the catalog by `columnsOf`.
|
|
212
|
+
/** A unique violation's table, columns and index: the table and the index (or constraint) Postgres names, and that
|
|
213
|
+
* index's columns (a UNIQUE's or a primary key's is an index of the same name), read from the catalog by `columnsOf`.
|
|
214
|
+
* A violation of the one-answer index (an answer to an approval answered already) is AnswerTaken. Any other error as it
|
|
215
|
+
* is. */
|
|
212
216
|
async function withUnique(error, cause, columnsOf) {
|
|
213
217
|
const e = cause;
|
|
214
218
|
if (!(error instanceof StoreConstraint) || error.rule !== "unique" || !e?.table || !e.constraint)
|
|
215
219
|
return error;
|
|
220
|
+
if (e.constraint === ONE_ANSWER_INDEX)
|
|
221
|
+
return new AnswerTaken(error.message, e.constraint);
|
|
216
222
|
const columns = await columnsOf(e.constraint).catch(() => []);
|
|
217
|
-
return
|
|
223
|
+
return new StoreConstraint(error.message, { rule: "unique", index: e.constraint, ...(columns.length ? { unique: { table: e.table, columns } } : {}) });
|
|
218
224
|
}
|
|
219
225
|
/** A Postgres error as the store's own: a refused row StoreConstraint, a lock or a conflict StoreBusy. */
|
|
226
|
+
/** Whether `error` says the database ended the session (its idle-in-transaction timeout, SQLSTATE 25P03), or that the
|
|
227
|
+
* connection is gone and takes no more statements: a transaction's work on it was rolled back by the database. */
|
|
228
|
+
export function sessionEnded(error) {
|
|
229
|
+
const e = error;
|
|
230
|
+
if (e?.code === "25P03")
|
|
231
|
+
return true;
|
|
232
|
+
const message = typeof e?.message === "string" ? e.message : "";
|
|
233
|
+
return /not queryable|Connection terminated/i.test(message);
|
|
234
|
+
}
|
|
220
235
|
function typed(error, deadlineMs) {
|
|
221
236
|
// Already the store's own (a failed statement's error, met again at the commit of a callback that caught it).
|
|
222
237
|
if (error instanceof Fenced || error instanceof RunFinal || error instanceof StoreClosed || error instanceof StoreDeadline || error instanceof StoreConstraint || error instanceof StoreBusy || error instanceof Unanswered)
|
|
@@ -518,6 +533,15 @@ export class PgConnection {
|
|
|
518
533
|
}
|
|
519
534
|
let live = true;
|
|
520
535
|
let broken;
|
|
536
|
+
// The database may end the session while the transaction waits between statements (its idle-in-transaction timeout:
|
|
537
|
+
// this process held up past the deadline and its slack): heard here, a statement or the commit after it answers
|
|
538
|
+
// StoreDeadline (home_busy, retryable), since the database rolled the transaction back and nothing of it was written.
|
|
539
|
+
let ended;
|
|
540
|
+
const onEnded = (error) => {
|
|
541
|
+
ended ??= error;
|
|
542
|
+
};
|
|
543
|
+
client.on("error", onEnded);
|
|
544
|
+
const lost = (error) => (ended !== undefined || sessionEnded(error) ? new StoreDeadline(deadlineMs) : undefined);
|
|
521
545
|
const check = () => {
|
|
522
546
|
if (!live)
|
|
523
547
|
throw new Error("the store's transaction is over: its handle takes no more statements");
|
|
@@ -541,9 +565,11 @@ export class PgConnection {
|
|
|
541
565
|
return await step(client, statement, columnsOf, deadlineMs);
|
|
542
566
|
}
|
|
543
567
|
catch (error) {
|
|
544
|
-
// A statement that failed has aborted the transaction: no later statement of it runs.
|
|
545
|
-
|
|
546
|
-
|
|
568
|
+
// A statement that failed has aborted the transaction: no later statement of it runs. On a session the database
|
|
569
|
+
// ended, it is the transaction's deadline.
|
|
570
|
+
const failure = lost(error) ?? error;
|
|
571
|
+
broken ??= failure;
|
|
572
|
+
throw failure;
|
|
547
573
|
}
|
|
548
574
|
};
|
|
549
575
|
const tx = {
|
|
@@ -560,15 +586,26 @@ export class PgConnection {
|
|
|
560
586
|
// drop, a failover) is bounded from its first statement on, not only once BEGIN has answered. Past it the client is
|
|
561
587
|
// let go with the error, which destroys its socket (Postgres rolls a dead session's transaction back), never
|
|
562
588
|
// waiting on a ROLLBACK that a silent connection would never answer.
|
|
589
|
+
// Counted from its begin, the deadline is the time this process could run (store/deadline.ts runnableDeadline, the
|
|
590
|
+
// rule SQLite's keeps): a statement answered while other work held the event loop waited behind it, and that time
|
|
591
|
+
// was no statement's, so a write that was fine is never rolled back for it. Counted from its call (a lease's), it is
|
|
592
|
+
// the wall clock's.
|
|
563
593
|
let timer;
|
|
564
|
-
const deadlineAt =
|
|
594
|
+
const deadlineAt = performance.now() + ms;
|
|
565
595
|
const deadline = new Promise((_, reject) => {
|
|
566
|
-
|
|
596
|
+
const expire = () => reject(new StoreDeadline(deadlineMs));
|
|
597
|
+
if (fromCall) {
|
|
598
|
+
const wall = setTimeout(expire, ms);
|
|
599
|
+
timer = { clear: () => clearTimeout(wall), held: () => 0 };
|
|
600
|
+
}
|
|
601
|
+
else
|
|
602
|
+
timer = runnableDeadline(ms, expire);
|
|
567
603
|
});
|
|
568
604
|
deadline.catch(() => undefined);
|
|
569
605
|
const abandon = (error) => {
|
|
570
606
|
live = false;
|
|
571
|
-
|
|
607
|
+
timer?.clear();
|
|
608
|
+
client.off("error", onEnded);
|
|
572
609
|
// Its socket destroyed here: with no query in flight (a deadline between statements) pg's own end would send a
|
|
573
610
|
// Terminate and wait for a FIN a silent connection never answers.
|
|
574
611
|
client.connection?.stream?.destroy();
|
|
@@ -596,19 +633,32 @@ export class PgConnection {
|
|
|
596
633
|
throw error;
|
|
597
634
|
}
|
|
598
635
|
live = false;
|
|
599
|
-
|
|
636
|
+
timer?.clear();
|
|
637
|
+
client.off("error", onEnded);
|
|
600
638
|
await rollBackAndRelease(client);
|
|
601
639
|
throw error;
|
|
602
640
|
}
|
|
603
641
|
live = false;
|
|
604
|
-
|
|
642
|
+
timer?.clear();
|
|
643
|
+
// Ended before its commit is sent: nothing of it was written, and the commit is never sent on a gone session.
|
|
644
|
+
const endedBefore = ended;
|
|
605
645
|
try {
|
|
646
|
+
if (endedBefore)
|
|
647
|
+
throw endedBefore;
|
|
606
648
|
// A callback that caught a failed statement's error and went on still rolls back: Postgres aborted the transaction.
|
|
607
649
|
if (broken)
|
|
608
650
|
throw broken;
|
|
609
|
-
await answered(client.query("COMMIT"), Math.max(COMMIT_FLOOR_MS, deadlineAt -
|
|
651
|
+
await answered(client.query("COMMIT"), Math.max(COMMIT_FLOOR_MS, deadlineAt + (timer?.held() ?? 0) - performance.now()), "its commit");
|
|
610
652
|
}
|
|
611
653
|
catch (error) {
|
|
654
|
+
if (endedBefore !== undefined || error?.code === "25P03") {
|
|
655
|
+
client.off("error", onEnded);
|
|
656
|
+
client.release(error);
|
|
657
|
+
if (read)
|
|
658
|
+
return value;
|
|
659
|
+
throw new StoreDeadline(deadlineMs);
|
|
660
|
+
}
|
|
661
|
+
client.off("error", onEnded);
|
|
612
662
|
if (error instanceof Unanswered) {
|
|
613
663
|
client.release(error);
|
|
614
664
|
// A read's snapshot has nothing to land: what it read stands.
|
|
@@ -619,6 +669,7 @@ export class PgConnection {
|
|
|
619
669
|
await rollBackAndRelease(client);
|
|
620
670
|
throw typed(error, deadlineMs);
|
|
621
671
|
}
|
|
672
|
+
client.off("error", onEnded);
|
|
622
673
|
client.release();
|
|
623
674
|
return value;
|
|
624
675
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 4: a stopped run says which stop it was in its outcome, as store/schema.ts keeps
|
|
2
|
+
-- it on SQLite: 'stopped' when a person stopped it (its turn is over, not the run: a message reopens it) or 'cancelled'
|
|
3
|
+
-- (over for good), beside an ended run's 'completed' and 'escalated'. Applied once, after 0003, inside the transaction
|
|
4
|
+
-- migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
5
|
+
--
|
|
6
|
+
-- runs_outcome_check is Postgres's name for 0001's column check on runs.outcome.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE runs DROP CONSTRAINT runs_outcome_check;
|
|
9
|
+
ALTER TABLE runs ADD CONSTRAINT runs_outcome_check CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated', 'stopped', 'cancelled'));
|
|
10
|
+
|
|
11
|
+
UPDATE store_meta SET schema_version = 4 WHERE singleton = 1;
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export declare const SCHEMA_VERSION =
|
|
1
|
+
export declare const SCHEMA_VERSION = 6;
|
|
2
2
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
3
3
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
4
4
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
5
5
|
/** One unrefused answer per approval of a run: an answer the runner refused (its run could not resume) holds no place, so
|
|
6
6
|
* the person can answer again. */
|
|
7
|
+
export declare const ONE_ANSWER_INDEX = "commands_one_answer";
|
|
7
8
|
export declare const COMMANDS_ONE_ANSWER = "CREATE UNIQUE INDEX IF NOT EXISTS commands_one_answer ON commands (run_id, json_extract(body, '$.approval')) WHERE kind IN ('approve', 'deny') AND refused IS NULL";
|
|
8
9
|
export declare const STORE_DDL: readonly string[];
|
|
9
10
|
/** pi-durable's journal tables (its SqliteStorage schema, version 2, the `sleeping` task status included; MIT, see NOTICE),
|
package/dist/store/schema.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// The store's one schema, version
|
|
1
|
+
// The store's one schema, version 6 (design 2.1). Nothing migrates into it: the rewrite replaces the old stores, and a store
|
|
2
2
|
// an older build made is refused as a version this build does not know. The server sets it up once at its start (a
|
|
3
3
|
// store_meta row holds the version); a runner refuses a version it does not know. Version 2 adds the computer ledger;
|
|
4
4
|
// version 3 numbers each save of a sign-in (sign_ins.save); version 4 stamps an MCP token's end (mcp_servers.token_until);
|
|
5
|
-
// version 5 maps an externally owned agent (agents.external_ref, revisions.external_version)
|
|
5
|
+
// version 5 maps an externally owned agent (agents.external_ref, revisions.external_version); version 6 tells a person's
|
|
6
|
+
// stop from a cancel (runs.outcome 'stopped' or 'cancelled').
|
|
6
7
|
// Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
|
|
7
8
|
// sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
|
|
8
9
|
// in the clear. Foreign keys are on (the connection's pragma).
|
|
@@ -13,13 +14,14 @@
|
|
|
13
14
|
// learning state, the MCP registry, pending MCP sign-ins, each run's MCP pin, and the computer ledger. PI_DDL is pi-durable's
|
|
14
15
|
// journal tables, keyed by run_id (store/journal): one schema for every run's journal, so a query joins runs and their
|
|
15
16
|
// journals.
|
|
16
|
-
export const SCHEMA_VERSION =
|
|
17
|
+
export const SCHEMA_VERSION = 6;
|
|
17
18
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
18
19
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
19
20
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
20
21
|
/** One unrefused answer per approval of a run: an answer the runner refused (its run could not resume) holds no place, so
|
|
21
22
|
* the person can answer again. */
|
|
22
|
-
export const
|
|
23
|
+
export const ONE_ANSWER_INDEX = "commands_one_answer";
|
|
24
|
+
export const COMMANDS_ONE_ANSWER = `CREATE UNIQUE INDEX IF NOT EXISTS ${ONE_ANSWER_INDEX} ON commands (run_id, json_extract(body, '$.approval')) WHERE kind IN ('approve', 'deny') AND refused IS NULL`;
|
|
23
25
|
const json = (column, nullable = false) => `${column} TEXT${nullable ? "" : " NOT NULL"} CHECK (${column} IS NULL OR json_valid(${column}))`;
|
|
24
26
|
export const STORE_DDL = [
|
|
25
27
|
`CREATE TABLE IF NOT EXISTS store_meta (
|
|
@@ -80,10 +82,11 @@ export const STORE_DDL = [
|
|
|
80
82
|
cost_usd REAL,
|
|
81
83
|
${json("metrics", true)},
|
|
82
84
|
summary TEXT,
|
|
83
|
-
-- How
|
|
84
|
-
-- person, which v2 reads as completed with a review) or 'completed'; null is a plain completion. A
|
|
85
|
-
--
|
|
86
|
-
|
|
85
|
+
-- How the run ended beside its state (RunOutcome). An ended run: 'escalated' (it finished its work and waits for a
|
|
86
|
+
-- person, which v2 reads as completed with a review) or 'completed'; null is a plain completion. A stopped run:
|
|
87
|
+
-- 'stopped' when a person stopped it (its turn is over, not the run: a message reopens it) or 'cancelled' (over for
|
|
88
|
+
-- good). A failed run says so in its state and needs none. Written in the run's end commit (RunPatch.outcome).
|
|
89
|
+
outcome TEXT CHECK (outcome IS NULL OR outcome IN ('completed', 'escalated', 'stopped', 'cancelled')),
|
|
87
90
|
-- When the run itself was archived (its agent's archive is the agent row's): hidden from the default lists, kept.
|
|
88
91
|
archived_at INTEGER,
|
|
89
92
|
-- The session an imported run came from ({source, session}), written by Store.importRun; null for a run started here.
|
package/dist/store/seal.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare const sealedAt: {
|
|
|
13
13
|
signIn: (agentId: string, provider: string) => SealedAt;
|
|
14
14
|
/** A run's computer session's live viewer token (browser-live.ts): one row per run, computer kind and session tag. */
|
|
15
15
|
liveViewer: (runId: string, kind: string, tag: string) => SealedAt;
|
|
16
|
+
/** A run's launch secrets: the MCP credentials its caller handed it for its `per_run` servers (mcp_auth). */
|
|
17
|
+
runLaunch: (runId: string) => SealedAt;
|
|
16
18
|
};
|
|
17
19
|
/** The AAD a value at `at` is sealed under. A part with the separator in it is refused: no two places share an AAD. */
|
|
18
20
|
export declare function aadOf(at: SealedAt): string;
|
|
@@ -46,3 +48,14 @@ export declare function openMcpCredential(key: Buffer, row: {
|
|
|
46
48
|
readonly url: string;
|
|
47
49
|
readonly sealed: Uint8Array | null;
|
|
48
50
|
}): OpenedMcpCredential;
|
|
51
|
+
/** The MCP credentials a run's caller handed it (`mcp_auth` at its start or with a message), by server name: each one's
|
|
52
|
+
* headers and the origin of the server's url when it was handed, so a server moved since never receives them. */
|
|
53
|
+
export type RunMcpAuth = Readonly<Record<string, {
|
|
54
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
55
|
+
readonly origin: string;
|
|
56
|
+
}>>;
|
|
57
|
+
/** Seals a run's handed MCP credentials as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
|
|
58
|
+
export declare function sealRunMcpAuth(key: Buffer, runId: string, auth: RunMcpAuth): Uint8Array;
|
|
59
|
+
/** A run's handed MCP credentials, opened: none when its launch holds none; undefined when the bytes do not open under
|
|
60
|
+
* `key` for this run (sealed for another run, or under another key). */
|
|
61
|
+
export declare function openRunMcpAuth(key: Buffer, runId: string, sealed: Uint8Array | null): RunMcpAuth | undefined;
|
package/dist/store/seal.js
CHANGED
|
@@ -25,6 +25,8 @@ export const sealedAt = {
|
|
|
25
25
|
},
|
|
26
26
|
/** A run's computer session's live viewer token (browser-live.ts): one row per run, computer kind and session tag. */
|
|
27
27
|
liveViewer: (runId, kind, tag) => ({ table: "computer_viewers", row: `${runId}/${kind}:${tag}`, column: "sealed" }),
|
|
28
|
+
/** A run's launch secrets: the MCP credentials its caller handed it for its `per_run` servers (mcp_auth). */
|
|
29
|
+
runLaunch: (runId) => ({ table: "run_launch", row: runId, column: "sealed" }),
|
|
28
30
|
};
|
|
29
31
|
/** The AAD a value at `at` is sealed under. A part with the separator in it is refused: no two places share an AAD. */
|
|
30
32
|
export function aadOf(at) {
|
|
@@ -67,3 +69,20 @@ export function openMcpCredential(key, row) {
|
|
|
67
69
|
}
|
|
68
70
|
return { credential: credential };
|
|
69
71
|
}
|
|
72
|
+
/** Seals a run's handed MCP credentials as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
|
|
73
|
+
export function sealRunMcpAuth(key, runId, auth) {
|
|
74
|
+
return sealColumn(key, sealedAt.runLaunch(runId), JSON.stringify({ mcp: auth }));
|
|
75
|
+
}
|
|
76
|
+
/** A run's handed MCP credentials, opened: none when its launch holds none; undefined when the bytes do not open under
|
|
77
|
+
* `key` for this run (sealed for another run, or under another key). */
|
|
78
|
+
export function openRunMcpAuth(key, runId, sealed) {
|
|
79
|
+
if (sealed === null)
|
|
80
|
+
return {};
|
|
81
|
+
try {
|
|
82
|
+
const opened = JSON.parse(unsealColumn(key, sealedAt.runLaunch(runId), sealed).toString("utf8"));
|
|
83
|
+
return opened.mcp ?? {};
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -4,6 +4,11 @@ import type { Statement, StatementResult } from "./worker.js";
|
|
|
4
4
|
export type { Params, Statement, StatementResult } from "./worker.js";
|
|
5
5
|
/** How long a transaction may stay open (it holds every other call of the process) before it is rolled back. */
|
|
6
6
|
export declare const DEFAULT_TRANSACTION_DEADLINE_MS = 10000;
|
|
7
|
+
/** `error` with its stack naming who held the store: `opened` (its own transaction's opener, when it has one), and every
|
|
8
|
+
* other transaction open in this process with its age. */
|
|
9
|
+
export declare function holderNamed<E extends Error>(error: E, { opened }?: {
|
|
10
|
+
opened?: Error;
|
|
11
|
+
}): E;
|
|
7
12
|
/** A value SQLite takes or gives back (Chord's SqliteValue). */
|
|
8
13
|
export type SqliteValue = null | number | bigint | string | Uint8Array;
|
|
9
14
|
/** Chord's SqliteExecutor: what a database and a transaction handle both do. */
|