@parcha/agentrun-serve 0.1.0-beta.35 → 0.1.0-beta.37
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 +298 -0
- package/README.md +417 -219
- package/dist/adapters.d.ts +12 -2
- package/dist/adapters.js +27 -2
- package/dist/agent-rows.d.ts +2 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +9 -4
- 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 +79 -7
- package/dist/archil-settings.js +140 -14
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- 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/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 +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- 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 +12 -57
- package/dist/cap.js +20 -160
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +17 -26
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +38 -1
- package/dist/computer-view.d.ts +24 -2
- package/dist/computer-view.js +51 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +79 -12
- package/dist/computers.js +147 -28
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.js +5 -5
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +56 -24
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/github.d.ts +22 -2
- package/dist/github.js +42 -8
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-view.d.ts +3 -1
- package/dist/graph-view.js +25 -1
- 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.d.ts +1 -0
- package/dist/harness.js +36 -2
- package/dist/host-tools.d.ts +9 -10
- package/dist/host-tools.js +7 -7
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +11 -2
- package/dist/learn/check.js +124 -6
- package/dist/learn/commit.d.ts +43 -7
- package/dist/learn/commit.js +166 -22
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +37 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +22 -1
- package/dist/learn/grade.js +107 -16
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning.sh +12 -1
- package/dist/learn/notes.d.ts +3 -0
- package/dist/learn/notes.js +3 -0
- package/dist/learn/reflect.d.ts +14 -2
- package/dist/learn/reflect.js +54 -30
- package/dist/learn/skills.d.ts +37 -5
- package/dist/learn/skills.js +60 -7
- package/dist/learned-nodes.d.ts +6 -2
- package/dist/learned-workflow.d.ts +43 -9
- package/dist/learned-workflow.js +128 -37
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +32 -4
- package/dist/learning-routes.js +48 -12
- package/dist/learning-words.d.ts +9 -0
- package/dist/learning-words.js +12 -2
- package/dist/learning.d.ts +39 -19
- package/dist/learning.js +88 -46
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +27 -3
- package/dist/mcp-probe.js +106 -29
- package/dist/mcp-secret-writes.js +8 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +120 -23
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.d.ts +5 -5
- package/dist/model.js +29 -16
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +586 -64
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/paid-calls.js +1 -1
- package/dist/place-offers.d.ts +96 -0
- package/dist/place-offers.js +202 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +21 -32
- package/dist/port-models.d.ts +2 -1
- package/dist/port-models.js +5 -3
- package/dist/print.d.ts +16 -9
- package/dist/print.js +15 -17
- package/dist/propose.d.ts +4 -0
- package/dist/propose.js +34 -11
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-launch.d.ts +28 -3
- package/dist/run-launch.js +14 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +56 -44
- package/dist/run-view.d.ts +8 -5
- package/dist/run-view.js +18 -10
- package/dist/runnable.d.ts +2 -2
- package/dist/runnable.js +6 -2
- package/dist/runner/adapter-loop.d.ts +39 -8
- package/dist/runner/adapter-loop.js +770 -83
- package/dist/runner/adapter-run-spec.d.ts +36 -7
- package/dist/runner/adapter-run-spec.js +171 -37
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +20 -7
- package/dist/runner/adapters/pi.js +111 -26
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +26 -12
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +27 -3
- package/dist/runner/cli-run-spec.js +198 -74
- package/dist/runner/commands.d.ts +8 -2
- package/dist/runner/commands.js +31 -6
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.d.ts +0 -1
- package/dist/runner/conformance/harness.js +87 -18
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +6 -4
- package/dist/runner/harness-loops.js +16 -2
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +35 -6
- package/dist/runner/journal-kinds.js +20 -1
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +37 -1
- package/dist/runner/learning-end.js +115 -14
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +15 -5
- package/dist/runner/learning-loop.d.ts +139 -7
- package/dist/runner/learning-loop.js +369 -32
- package/dist/runner/learning-seed.d.ts +9 -0
- package/dist/runner/learning-seed.js +14 -1
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +16 -1
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +10 -2
- package/dist/runner/loop.js +22 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +38 -6
- package/dist/runner/mcp-claim.d.ts +11 -4
- package/dist/runner/mcp-claim.js +140 -23
- package/dist/runner/mcp-github.d.ts +4 -2
- package/dist/runner/mcp-github.js +1 -8
- package/dist/runner/mcp-run.d.ts +6 -4
- package/dist/runner/mcp-run.js +16 -3
- package/dist/runner/metrics.d.ts +15 -2
- package/dist/runner/metrics.js +21 -2
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +60 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +19 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +231 -27
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/spec-holds.d.ts +8 -3
- package/dist/runner/spec-holds.js +12 -10
- package/dist/runner/store-port.d.ts +7 -2
- package/dist/runner/store-secrets.js +21 -4
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +190 -0
- package/dist/runner/workflow-host.d.ts +24 -3
- package/dist/runner/workflow-host.js +24 -4
- package/dist/runner/workflow-loop.d.ts +6 -3
- package/dist/runner/workflow-loop.js +9 -8
- package/dist/runner/workflow-spec.d.ts +39 -15
- package/dist/runner/workflow-spec.js +143 -40
- package/dist/runs-over-store.d.ts +16 -6
- package/dist/runs-over-store.js +145 -29
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +75 -63
- package/dist/server.js +712 -316
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/agent-body.d.ts +9 -2
- package/dist/store/agent-body.js +16 -8
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/deadline.js +9 -5
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +4 -4
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +15 -6
- package/dist/store/postgres/connection.js +9 -4
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +85 -13
- 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 -47
- package/dist/store/sqlite/run-patch.d.ts +25 -7
- package/dist/store/sqlite/run-patch.js +58 -14
- package/dist/store/sqlite/store.js +331 -59
- package/dist/store/store.d.ts +330 -21
- package/dist/store/store.js +34 -2
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +2 -4
- package/dist/store-reads/cap.js +16 -7
- package/dist/store-reads/decisions.d.ts +3 -3
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +118 -27
- package/dist/store-reads/learning.d.ts +34 -4
- package/dist/store-reads/learning.js +137 -23
- package/dist/store-reads/runs.d.ts +7 -5
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +70 -29
- package/dist/template-eval.js +8 -5
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/templates.d.ts +64 -0
- package/dist/templates.js +101 -16
- package/dist/timeline/timeline.d.ts +30 -1
- package/dist/timeline/timeline.js +29 -13
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +27 -7
- package/dist/tool-budget.js +21 -9
- package/dist/tool-gate.d.ts +23 -10
- package/dist/tool-gate.js +60 -44
- package/dist/tool-plane.d.ts +46 -28
- package/dist/tool-plane.js +73 -31
- package/dist/tools.d.ts +31 -38
- package/dist/tools.js +117 -74
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +26 -6
- package/dist/trigger-signatures.js +44 -8
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +10 -6
- package/dist/triggers.js +37 -7
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/turns.js +16 -1
- package/dist/usage-lines.d.ts +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.js +41 -4
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +147 -103
- package/dist/webhooks.js +564 -324
- 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 +113 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +89 -0
- package/dist/workflow/node.js +101 -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 +32 -0
- package/dist/workflow/pi-versions.js +65 -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 +77 -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 +412 -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-run.d.ts +2 -2
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +11 -0
- package/dist/workspace/archil-claim.js +18 -10
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.js +2 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +32 -17
- package/dist/workspace/computer-deps.js +37 -14
- package/dist/workspace/computer-for-claim.d.ts +58 -13
- package/dist/workspace/computer-for-claim.js +267 -26
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +5 -1
- package/dist/workspace/computer-ledger.js +11 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +7 -4
- package/dist/workspace/index.js +4 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +45 -11
- package/dist/workspace/resolve-computer.js +72 -14
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +35 -18
- package/dist/workspace/run-tools.js +24 -29
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace.js +1 -1
- package/package.json +19 -21
- package/templates/README.md +9 -6
- 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/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/market-monitor/agent.md +1 -1
- 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 -71
- package/dist/budget.js +0 -199
- package/dist/console/assets/index-B7NKTU8E.css +0 -1
- package/dist/console/assets/index-CXZMgJE7.js +0 -550
- 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/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Store } from "./store/index.js";
|
|
2
|
+
import type { ToolSettingsMap, ToolSettingsRead } from "./tool-plane.js";
|
|
3
|
+
/** The store slice a wake reads and writes: the parked runs, their pinned revisions and journals, and the wake itself. */
|
|
4
|
+
export type WakeStore = Pick<Store, "runs" | "agents" | "readJournal">;
|
|
5
|
+
/** Whether a save changed any tool key's permission (added, removed or changed). It does not predict which edit flips a
|
|
6
|
+
* call's answer (an exact `ask` under a wildcard `deny` flips when only the wildcard moves): it only skips a save that
|
|
7
|
+
* touches no permission at all (a provider alone, a pin). The per-run decision is permissionFrom's. Approvals live on the
|
|
8
|
+
* run's revision, not in the server's settings, so a save cannot change them. */
|
|
9
|
+
export declare function permissionsChanged(before: ToolSettingsMap, after: ToolSettingsMap): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Wakes every parked run with a call waiting on its person whose tool reads allow now on the run's pinned revision: its
|
|
12
|
+
* own tool settings and approvals over the server's `read` (tool-gate.ts permissionFrom, the gate's one rule, a deny set
|
|
13
|
+
* on the server absolute). A run whose waiting calls all still read ask or deny is left parked, never claimed. Answers
|
|
14
|
+
* the runs woken.
|
|
15
|
+
*
|
|
16
|
+
* The run's gate stays the judge: the claim reads the settings again at the call, so a run woken here whose call reads
|
|
17
|
+
* otherwise by then (a pin, a setting changed since) parks again or is refused, in the gate's words. Where the server
|
|
18
|
+
* can't tell the run's answer, nothing is woken: settings that do not read (the gate holds to its last good read), and a
|
|
19
|
+
* shell tool on its default, which is where the run's shell is (no computer: bash asks).
|
|
20
|
+
*/
|
|
21
|
+
export declare function wakeAnsweredBySetting(store: WakeStore, read: ToolSettingsRead, before: ToolSettingsMap): Promise<string[]>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// A change of the server's tool settings (PUT /settings/tools) wakes the runs parked on an ask it answers. A call a person
|
|
2
|
+
// was asked about and has not answered, whose tool now reads allow, is answered by the setting at the run's next claim
|
|
3
|
+
// (runner/adapter-loop.ts allowedBySetting: the ask closes "Allowed by the tool's setting" and the call runs). That claim
|
|
4
|
+
// came only with a person's answer or another command; here the flip itself brings it, by the store's wake (runs.wake),
|
|
5
|
+
// so the run goes on at once. No second resume path: the claim is any claim, and its gate decides as it always does.
|
|
6
|
+
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
7
|
+
import { approvalsOf } from "./approvals.js";
|
|
8
|
+
import { answersOf, asksOf } from "./run-view.js";
|
|
9
|
+
import { journalEntries } from "./runner/journal-reader.js";
|
|
10
|
+
import { permissionFrom, SHELL_FAMILY } from "./tool-gate.js";
|
|
11
|
+
/** Whether a save changed any tool key's permission (added, removed or changed). It does not predict which edit flips a
|
|
12
|
+
* call's answer (an exact `ask` under a wildcard `deny` flips when only the wildcard moves): it only skips a save that
|
|
13
|
+
* touches no permission at all (a provider alone, a pin). The per-run decision is permissionFrom's. Approvals live on the
|
|
14
|
+
* run's revision, not in the server's settings, so a save cannot change them. */
|
|
15
|
+
export function permissionsChanged(before, after) {
|
|
16
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
17
|
+
if (before[key]?.permission !== after[key]?.permission)
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Wakes every parked run with a call waiting on its person whose tool reads allow now on the run's pinned revision: its
|
|
24
|
+
* own tool settings and approvals over the server's `read` (tool-gate.ts permissionFrom, the gate's one rule, a deny set
|
|
25
|
+
* on the server absolute). A run whose waiting calls all still read ask or deny is left parked, never claimed. Answers
|
|
26
|
+
* the runs woken.
|
|
27
|
+
*
|
|
28
|
+
* The run's gate stays the judge: the claim reads the settings again at the call, so a run woken here whose call reads
|
|
29
|
+
* otherwise by then (a pin, a setting changed since) parks again or is refused, in the gate's words. Where the server
|
|
30
|
+
* can't tell the run's answer, nothing is woken: settings that do not read (the gate holds to its last good read), and a
|
|
31
|
+
* shell tool on its default, which is where the run's shell is (no computer: bash asks).
|
|
32
|
+
*/
|
|
33
|
+
export async function wakeAnsweredBySetting(store, read, before) {
|
|
34
|
+
if (read.unreadable)
|
|
35
|
+
return [];
|
|
36
|
+
// A save that changed no permission (a provider alone, a pin) answers no ask: no run is listed, no journal read.
|
|
37
|
+
if (!permissionsChanged(before, read.settings))
|
|
38
|
+
return [];
|
|
39
|
+
const server = read.settings;
|
|
40
|
+
const woken = [];
|
|
41
|
+
for (const run of await store.runs.list({ state: "parked" })) {
|
|
42
|
+
const entries = await journalEntries(store.readJournal(run.id), BACKGROUND_CONTEXT);
|
|
43
|
+
const answers = answersOf(entries);
|
|
44
|
+
// The ask names the call by its settings key (a shell tool by its own name), as the gate's askedAs gives it.
|
|
45
|
+
const waiting = [...asksOf(entries).values()].filter((ask) => !ask.resolved && !(ask.id in answers)).map((ask) => ask.tool);
|
|
46
|
+
if (waiting.length === 0)
|
|
47
|
+
continue;
|
|
48
|
+
const revision = await store.agents.revision(run.revisionId);
|
|
49
|
+
const body = (revision?.body ?? {});
|
|
50
|
+
const agent = (body.toolSettings ?? {});
|
|
51
|
+
const allowed = waiting.some((tool) => {
|
|
52
|
+
const { permission, from } = permissionFrom(tool, server, agent, approvalsOf(body.approvals));
|
|
53
|
+
return permission === "allow" && !(from === "default" && Object.hasOwn(SHELL_FAMILY, tool));
|
|
54
|
+
});
|
|
55
|
+
if (allowed && (await store.runs.wake(run.id)))
|
|
56
|
+
woken.push(run.id);
|
|
57
|
+
}
|
|
58
|
+
return woken;
|
|
59
|
+
}
|
|
@@ -27,4 +27,7 @@ export declare const signatureOf: (secret: string, id: string, timestamp: string
|
|
|
27
27
|
export declare function headersRefusal(headers: Record<string, string | string[] | undefined>, nowMs: number): string | undefined;
|
|
28
28
|
/** Why a request is not signed by `secret`, or undefined when it is: `webhook-signature` lists signatures, space
|
|
29
29
|
* separated, and any one that matches passes; the timestamp is within HOOK_TOLERANCE_S; the key has MIN_KEY_BYTES. */
|
|
30
|
-
export declare
|
|
30
|
+
export declare const verify: (secret: string, headers: Record<string, string | string[] | undefined>, body: Buffer, nowMs: number) => string | undefined;
|
|
31
|
+
/** `verify` under key bytes the caller derived from its secret: Standard Webhooks' are the secret's decoded `whsec_`
|
|
32
|
+
* key; a sender that signs the same message under the secret string's UTF-8 bytes (Composio's) passes those. */
|
|
33
|
+
export declare function verifyWithKey(key: Buffer, headers: Record<string, string | string[] | undefined>, body: Buffer, nowMs: number): string | undefined;
|
|
@@ -22,7 +22,8 @@ export const mintSecret = () => `${SECRET_PREFIX}${randomBytes(32).toString("bas
|
|
|
22
22
|
const keyOf = (secret) => Buffer.from(secret.startsWith(SECRET_PREFIX) ? secret.slice(SECRET_PREFIX.length) : secret, "base64");
|
|
23
23
|
/** How many bytes `value` holds as a key: a `whsec_` secret's decoded key, any other value's UTF-8. */
|
|
24
24
|
export const keyBytes = (value) => (value.startsWith(SECRET_PREFIX) ? keyOf(value).length : Buffer.byteLength(value, "utf8"));
|
|
25
|
-
const
|
|
25
|
+
const hmacWith = (key, id, timestamp, body) => createHmac("sha256", key).update(`${id}.${timestamp}.`).update(body).digest();
|
|
26
|
+
const hmacOf = (secret, id, timestamp, body) => hmacWith(keyOf(secret), id, timestamp, body);
|
|
26
27
|
/** Each spelling of `value` a cut needs beyond the ones redaction derives of any text (learn/secrets.ts redactSecrets:
|
|
27
28
|
* as written, its hex, its base64): for a `whsec_` secret, itself, its key as written after the prefix, that key as
|
|
28
29
|
* base64url (- and _ for + and /, no padding), and the key's bytes as hex, in either case; each padded one printed
|
|
@@ -54,19 +55,22 @@ export function headersRefusal(headers, nowMs) {
|
|
|
54
55
|
}
|
|
55
56
|
/** Why a request is not signed by `secret`, or undefined when it is: `webhook-signature` lists signatures, space
|
|
56
57
|
* separated, and any one that matches passes; the timestamp is within HOOK_TOLERANCE_S; the key has MIN_KEY_BYTES. */
|
|
57
|
-
export
|
|
58
|
+
export const verify = (secret, headers, body, nowMs) => verifyWithKey(keyOf(secret), headers, body, nowMs);
|
|
59
|
+
/** `verify` under key bytes the caller derived from its secret: Standard Webhooks' are the secret's decoded `whsec_`
|
|
60
|
+
* key; a sender that signs the same message under the secret string's UTF-8 bytes (Composio's) passes those. */
|
|
61
|
+
export function verifyWithKey(key, headers, body, nowMs) {
|
|
58
62
|
const early = headersRefusal(headers, nowMs);
|
|
59
63
|
if (early)
|
|
60
64
|
return early;
|
|
61
65
|
const [id, timestamp, signatures] = ["webhook-id", "webhook-timestamp", "webhook-signature"].map((name) => headers[name]);
|
|
62
|
-
const expected =
|
|
66
|
+
const expected = hmacWith(key, id, timestamp, body);
|
|
63
67
|
// Compared all the same, so a short key costs what a good one does; it fails after.
|
|
64
68
|
const matched = signatures.split(" ").some((part) => {
|
|
65
69
|
const [version, signature] = part.split(",");
|
|
66
70
|
const given = Buffer.from(signature ?? "", "base64");
|
|
67
71
|
return version === "v1" && given.length === expected.length && timingSafeEqual(given, expected);
|
|
68
72
|
});
|
|
69
|
-
if (
|
|
73
|
+
if (key.length < MIN_KEY_BYTES)
|
|
70
74
|
return "short_key";
|
|
71
75
|
return matched ? undefined : "bad_signature";
|
|
72
76
|
}
|
|
@@ -37,28 +37,33 @@ export type RevisionComputer = {
|
|
|
37
37
|
type: string;
|
|
38
38
|
count: number;
|
|
39
39
|
};
|
|
40
|
+
persistent?: boolean;
|
|
40
41
|
};
|
|
41
42
|
/** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
|
|
42
43
|
* pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
|
|
43
44
|
* canonicalToolSettings, the one copy). The store body holds it as it is given; this validator never reimplements it. */
|
|
44
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>>;
|
|
45
48
|
export type AgenticBody = {
|
|
46
49
|
instructions: string;
|
|
47
50
|
skills: Record<string, string>;
|
|
48
51
|
tools: string[];
|
|
49
52
|
model?: string;
|
|
53
|
+
modelTiers?: ModelTiers;
|
|
50
54
|
thinking?: string;
|
|
51
55
|
prompts?: Record<string, PromptVariant>;
|
|
52
56
|
harness?: string;
|
|
53
57
|
place?: RevisionPlace;
|
|
54
58
|
computer?: RevisionComputer;
|
|
55
|
-
learning?: boolean;
|
|
59
|
+
learning?: boolean | "notes";
|
|
56
60
|
toolSettings?: ToolSettings;
|
|
57
61
|
maxCostUsd?: number;
|
|
58
62
|
capMode?: string;
|
|
59
63
|
approvals?: "ask" | "never";
|
|
60
64
|
outputSchema?: Record<string, unknown>;
|
|
61
65
|
maxToolCalls?: number;
|
|
66
|
+
checkout?: "pull_request";
|
|
62
67
|
};
|
|
63
68
|
export type WorkflowBody = {
|
|
64
69
|
workflow: Record<string, unknown>;
|
|
@@ -80,18 +85,20 @@ export type RevisionBodyInput = {
|
|
|
80
85
|
skills?: Record<string, string>;
|
|
81
86
|
tools?: string[];
|
|
82
87
|
model?: string;
|
|
88
|
+
modelTiers?: ModelTiers;
|
|
83
89
|
thinking?: string;
|
|
84
90
|
prompts?: Record<string, PromptVariant>;
|
|
85
91
|
harness?: string;
|
|
86
92
|
place?: unknown;
|
|
87
93
|
computer?: unknown;
|
|
88
|
-
learning?: boolean;
|
|
94
|
+
learning?: boolean | "notes";
|
|
89
95
|
toolSettings?: ToolSettings;
|
|
90
96
|
maxCostUsd?: number;
|
|
91
97
|
capMode?: string;
|
|
92
98
|
approvals?: "ask" | "never";
|
|
93
99
|
outputSchema?: Record<string, unknown>;
|
|
94
100
|
maxToolCalls?: number;
|
|
101
|
+
checkout?: "pull_request";
|
|
95
102
|
} | {
|
|
96
103
|
kind: "workflow";
|
|
97
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,20 +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?, image?, gpu?}`, nothing else: kind and provider ids,
|
|
48
|
-
* with no spaces around it,
|
|
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
|
const image = isObject(computer) ? computer.image : undefined;
|
|
51
52
|
const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
|
|
52
|
-
if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || Object.keys(computer).some((key) => key !== "kind" && key !== "provider" && key !== "image" && key !== "gpu"))
|
|
53
|
-
invalid("the computer is not {kind, provider?, image?, gpu?}, kind and provider each an id (lowercase letters, digits and dashes), image a name");
|
|
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");
|
|
54
55
|
const ok = computer;
|
|
55
56
|
const gpu = ok.gpu;
|
|
56
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)) {
|
|
57
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");
|
|
58
59
|
}
|
|
59
60
|
const kept = gpu;
|
|
60
|
-
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 } } : {}) };
|
|
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 } : {}) };
|
|
61
62
|
}
|
|
62
63
|
/** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
|
|
63
64
|
* write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
|
|
@@ -109,10 +110,14 @@ export function bodyOf(input) {
|
|
|
109
110
|
for (const field of ["model", "thinking"])
|
|
110
111
|
if (input[field] !== undefined && (typeof input[field] !== "string" || input[field] === ""))
|
|
111
112
|
invalid(`the ${field} is not a non-empty string`);
|
|
112
|
-
if (input.learning !== undefined && typeof input.learning !== "boolean")
|
|
113
|
-
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\"");
|
|
114
115
|
if (input.outputSchema !== undefined && !isObject(input.outputSchema))
|
|
115
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");
|
|
116
121
|
if (input.maxToolCalls !== undefined && !(Number.isSafeInteger(input.maxToolCalls) && input.maxToolCalls > 0))
|
|
117
122
|
invalid("the maxToolCalls is not a whole number above 0");
|
|
118
123
|
const body = {
|
|
@@ -120,12 +125,15 @@ export function bodyOf(input) {
|
|
|
120
125
|
skills: skillShas,
|
|
121
126
|
tools: [...tools],
|
|
122
127
|
...(input.model !== undefined ? { model: input.model } : {}),
|
|
128
|
+
...(input.modelTiers !== undefined ? { modelTiers: Object.fromEntries(Object.entries(input.modelTiers).sort(([a], [b]) => a.localeCompare(b))) } : {}),
|
|
123
129
|
...(input.thinking !== undefined ? { thinking: input.thinking } : {}),
|
|
124
130
|
...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
|
|
125
131
|
...host,
|
|
126
132
|
...(input.learning !== undefined ? { learning: input.learning } : {}),
|
|
127
133
|
// The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
|
|
128
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 } : {}),
|
|
129
137
|
// The tool calls each conversation of its runs may make (tool-budget.ts).
|
|
130
138
|
...(input.maxToolCalls !== undefined ? { maxToolCalls: input.maxToolCalls } : {}),
|
|
131
139
|
// The agent's unattended policy (PR #2003): the runner's gate reads it from the revision body at claim (`unattended`
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** What woke a listener: a command row was written for the run, or one was taken, refused or answered. */
|
|
2
|
+
export interface CommandWake {
|
|
3
|
+
readonly runId: string;
|
|
4
|
+
readonly what: "written" | "answered";
|
|
5
|
+
}
|
|
6
|
+
type Listener = (event: CommandWake) => void;
|
|
7
|
+
/** Subscribes `listener` to the commands of the data at `where`; answers the unsubscribe. */
|
|
8
|
+
export declare function watchCommandsAt(where: string, listener: Listener): () => void;
|
|
9
|
+
/** Tells the listeners of `where` about `events`, after the write committed: asynchronously, each listener's throw
|
|
10
|
+
* swallowed, so a write never waits on or fails with a listener. */
|
|
11
|
+
export declare function wakeCommands(where: string, ...events: readonly CommandWake[]): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// A wake for command rows: a hint to read now, not a source of truth. An in-process bus keyed by a store's `where` (two
|
|
2
|
+
// handles on the same data share one), so a write through one handle wakes the readers of the others without waiting for
|
|
3
|
+
// their poll. It reaches handles in this process only: a row another process writes wakes nothing here, and the reader's
|
|
4
|
+
// poll finds it.
|
|
5
|
+
const listeners = new Map();
|
|
6
|
+
/** Subscribes `listener` to the commands of the data at `where`; answers the unsubscribe. */
|
|
7
|
+
export function watchCommandsAt(where, listener) {
|
|
8
|
+
let set = listeners.get(where);
|
|
9
|
+
if (set === undefined)
|
|
10
|
+
listeners.set(where, (set = new Set()));
|
|
11
|
+
const mine = set;
|
|
12
|
+
mine.add(listener);
|
|
13
|
+
return () => {
|
|
14
|
+
mine.delete(listener);
|
|
15
|
+
if (mine.size === 0 && listeners.get(where) === mine)
|
|
16
|
+
listeners.delete(where);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Tells the listeners of `where` about `events`, after the write committed: asynchronously, each listener's throw
|
|
20
|
+
* swallowed, so a write never waits on or fails with a listener. */
|
|
21
|
+
export function wakeCommands(where, ...events) {
|
|
22
|
+
const set = listeners.get(where);
|
|
23
|
+
if (set === undefined || events.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
queueMicrotask(() => {
|
|
26
|
+
for (const listener of [...set]) {
|
|
27
|
+
for (const event of events) {
|
|
28
|
+
try {
|
|
29
|
+
listener(event);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// A listener's failure is its own.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
package/dist/store/deadline.js
CHANGED
|
@@ -12,6 +12,10 @@ export const STALL_MS = 50;
|
|
|
12
12
|
* deadline or across it, and is not counted. A wait of the transaction's own (a call awaited inside it) leaves the
|
|
13
13
|
* loop free, so it counts in full and is refused on time. */
|
|
14
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];
|
|
15
19
|
const start = performance.now();
|
|
16
20
|
let last = start;
|
|
17
21
|
let held = 0;
|
|
@@ -23,19 +27,19 @@ export function runnableDeadline(ms, expire) {
|
|
|
23
27
|
last = now;
|
|
24
28
|
return now;
|
|
25
29
|
};
|
|
26
|
-
const ticks =
|
|
30
|
+
const ticks = every(look, TICK_MS);
|
|
27
31
|
let timer;
|
|
28
32
|
const check = () => {
|
|
29
33
|
const left = ms - (look() - start - held);
|
|
30
34
|
if (left <= 0)
|
|
31
35
|
return expire();
|
|
32
|
-
timer =
|
|
36
|
+
timer = after(check, Math.ceil(left));
|
|
33
37
|
};
|
|
34
|
-
timer =
|
|
38
|
+
timer = after(check, ms);
|
|
35
39
|
return {
|
|
36
40
|
clear: () => {
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
stop(ticks);
|
|
42
|
+
cancel(timer);
|
|
39
43
|
},
|
|
40
44
|
held: () => {
|
|
41
45
|
look();
|
package/dist/store/dialect.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export interface Dialect {
|
|
|
12
12
|
jsonArrayHas(column: string): string;
|
|
13
13
|
/** The length of the JSON array in TEXT column `column`. */
|
|
14
14
|
jsonArrayLength(column: string): string;
|
|
15
|
+
/** The JSON object in TEXT column `column` without its top-level `key`. */
|
|
16
|
+
jsonWithout(column: string, key: string): string;
|
|
15
17
|
/** trigger_firings' insertion order: the tie-break of rows written in the same ms. */
|
|
16
18
|
readonly firingOrder: string;
|
|
17
19
|
/** No row limit, before an OFFSET. */
|
|
@@ -57,3 +59,7 @@ export interface Dialect {
|
|
|
57
59
|
export declare function cleanText(text: string): string;
|
|
58
60
|
/** SQLite: one writer at a time (BEGIN IMMEDIATE), so every lock is already held. */
|
|
59
61
|
export declare const SQLITE: Dialect;
|
|
62
|
+
/** The SET fragment every statement that settles command rows (taken or refused) carries: a computer call's params go
|
|
63
|
+
* with its settling, so text an owner typed or wrote through the computer call channel (a password, a credential's file)
|
|
64
|
+
* never stays in the store once the call is done. The row keeps its method. */
|
|
65
|
+
export declare const settledBody: (dialect: Dialect) => string;
|
package/dist/store/dialect.js
CHANGED
|
@@ -16,6 +16,7 @@ export const SQLITE = {
|
|
|
16
16
|
jsonNotFalse: (column, path) => `json_extract(${column}, ${jsonPath(path)}) IS NOT 0`,
|
|
17
17
|
jsonArrayHas: (column) => `EXISTS (SELECT 1 FROM json_each(${column}) WHERE value = ?)`,
|
|
18
18
|
jsonArrayLength: (column) => `json_array_length(${column})`,
|
|
19
|
+
jsonWithout: (column, key) => `json_remove(${column}, ${jsonPath([key])})`,
|
|
19
20
|
firingOrder: "rowid",
|
|
20
21
|
limitAll: "LIMIT -1",
|
|
21
22
|
nullSafeEquals: (column) => `${column} IS ?`,
|
|
@@ -30,3 +31,7 @@ export const SQLITE = {
|
|
|
30
31
|
lockRow: async () => undefined,
|
|
31
32
|
lockKey: async () => undefined,
|
|
32
33
|
};
|
|
34
|
+
/** The SET fragment every statement that settles command rows (taken or refused) carries: a computer call's params go
|
|
35
|
+
* with its settling, so text an owner typed or wrote through the computer call channel (a password, a credential's file)
|
|
36
|
+
* never stays in the store once the call is done. The row keeps its method. */
|
|
37
|
+
export const settledBody = (dialect) => `body = CASE WHEN kind = 'computer_call' THEN ${dialect.jsonWithout("body", "params")} ELSE body END`;
|
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";
|
|
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";
|
|
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
|
+
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, 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, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, 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, 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";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Context
|
|
1
|
+
import type { Context } from "@earendil-works/chord/context";
|
|
2
|
+
import type { JsonValue } from "@earendil-works/chord/json";
|
|
2
3
|
import { type CommitResult, type ConversationId, type ConversationQuery, type ConversationRecord, type Cursor, type DocumentAddress, type DocumentId, type DocumentPoint, type DocumentQuery, type DocumentRecord, type EntryId, type EntryQuery, type EntryRecord, type Id, type Page, type Seq, type StorageWrite, type StoredDocument, type SubmissionId, type SubmissionQuery, type SubmissionRecord, type TaskId, type TaskQuery, type TaskRecord } from "@earendil-works/pi-durable";
|
|
3
4
|
import { type Dialect } from "../dialect.js";
|
|
4
5
|
import type { StoreConnection } from "../sqlite/connection.js";
|
|
@@ -51,7 +52,7 @@ export declare class RunStorage implements Journal {
|
|
|
51
52
|
#private;
|
|
52
53
|
/** The journal of `claim`'s run on `db` (the store's connection, its schema in place). Its id namespace is read, and made
|
|
53
54
|
* on first use, by its first commit or mintId. `now`: the store's clock (epoch ms). */
|
|
54
|
-
constructor(db: JournalConnection, claim: JournalClaim, now?: () => number, onClose?: () => void);
|
|
55
|
+
constructor(db: JournalConnection, claim: JournalClaim, now?: () => number, onClose?: () => void, where?: string);
|
|
55
56
|
/** The journal of `claim`'s run on `db`, its id namespace read (and made on first use). */
|
|
56
57
|
static open(db: JournalConnection, claim: JournalClaim, now?: () => number): Promise<RunStorage>;
|
|
57
58
|
/** Whether the journal is closed (store.journal hands out a new one then). */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { apply } from "@earendil-works/chord/delta";
|
|
2
2
|
import { StorageRequestError, } from "@earendil-works/pi-durable";
|
|
3
|
+
import { wakeCommands } from "../command-wake.js";
|
|
3
4
|
import { PI_TABLE as T } from "../schema.js";
|
|
4
|
-
import { SQLITE } from "../dialect.js";
|
|
5
|
+
import { settledBody, SQLITE } from "../dialect.js";
|
|
5
6
|
import { claimFence, storeNow } from "../fence.js";
|
|
6
7
|
import { applyRunPatch, refuseLeftovers } from "../sqlite/run-patch.js";
|
|
7
8
|
import { CommandTaken, Fenced } from "../store.js";
|
|
@@ -130,6 +131,8 @@ export class RunStorage {
|
|
|
130
131
|
#staged;
|
|
131
132
|
/** Commands staged to be taken, each with the record of its effect: taken only by the commit that stores that record. */
|
|
132
133
|
#takes = new Map();
|
|
134
|
+
/** The store's identity (Store.where): where a commit that answers a command wakes the readers in this process. */
|
|
135
|
+
#where;
|
|
133
136
|
/** Ids this journal minted and has not yet written: the only ones a staged take may name as its effect. */
|
|
134
137
|
#minted = new Set();
|
|
135
138
|
#closed = false;
|
|
@@ -140,8 +143,9 @@ export class RunStorage {
|
|
|
140
143
|
#readsDrained;
|
|
141
144
|
/** The journal of `claim`'s run on `db` (the store's connection, its schema in place). Its id namespace is read, and made
|
|
142
145
|
* on first use, by its first commit or mintId. `now`: the store's clock (epoch ms). */
|
|
143
|
-
constructor(db, claim, now = Date.now, onClose) {
|
|
146
|
+
constructor(db, claim, now = Date.now, onClose, where) {
|
|
144
147
|
this.#db = db;
|
|
148
|
+
this.#where = where;
|
|
145
149
|
this.#dialect = db.dialect ?? SQLITE;
|
|
146
150
|
this.#read = readsOf(db);
|
|
147
151
|
this.#runId = claim.runId;
|
|
@@ -212,7 +216,7 @@ export class RunStorage {
|
|
|
212
216
|
}
|
|
213
217
|
}
|
|
214
218
|
for (const take of staged.take ?? [])
|
|
215
|
-
this.#takes.set(take.command, Number(take.effect));
|
|
219
|
+
this.#takes.set(take.command, { effect: Number(take.effect), answer: take.answer === undefined ? null : JSON.stringify(take.answer) });
|
|
216
220
|
// A stage that names a run patch or rows replaces the ones staged before; one that only takes leaves them.
|
|
217
221
|
if (staged.run !== undefined || staged.also !== undefined)
|
|
218
222
|
this.#staged = { ...(staged.run !== undefined ? { run: staged.run } : {}), ...(staged.also !== undefined ? { also: staged.also } : {}), effect: Number(staged.effect) };
|
|
@@ -295,7 +299,7 @@ export class RunStorage {
|
|
|
295
299
|
seqs.push(seq);
|
|
296
300
|
candidateNextId = Math.max(candidateNextId, this.#candidateNextId(writes));
|
|
297
301
|
// A take whose effect this stored batch newly writes is this commit's, and so is the staged patch.
|
|
298
|
-
for (const [command, effect] of this.#takes)
|
|
302
|
+
for (const [command, { effect }] of this.#takes)
|
|
299
303
|
if (fresh.has(effect) && !taking.includes(command))
|
|
300
304
|
taking.push(command);
|
|
301
305
|
if (staged?.effect !== undefined && fresh.has(staged.effect))
|
|
@@ -310,13 +314,14 @@ export class RunStorage {
|
|
|
310
314
|
await applyRunPatch(tx, { runId: this.#runId, epoch: this.#epoch }, staged?.run ?? {}, staged?.also ?? [], now, this.#dialect);
|
|
311
315
|
}
|
|
312
316
|
for (const commandId of taking) {
|
|
313
|
-
if ((await tx.runCounted(
|
|
317
|
+
if ((await tx.runCounted(`UPDATE commands SET taken_at = ?, answer = ?, ${settledBody(this.#dialect)} WHERE id = ? AND run_id = ? AND taken_at IS NULL`, now, this.#takes.get(commandId)?.answer ?? null, commandId, this.#runId)) === 0) {
|
|
314
318
|
throw new CommandTaken(this.#runId, commandId);
|
|
315
319
|
}
|
|
316
320
|
}
|
|
317
321
|
// A run patch that made the run final: its other untaken rows are refused in this commit, after its own takes.
|
|
322
|
+
// A person's message that came while it was ending opens a completed run again instead (refuseLeftovers).
|
|
318
323
|
if (patching)
|
|
319
|
-
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now);
|
|
324
|
+
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now, this.#dialect);
|
|
320
325
|
}
|
|
321
326
|
});
|
|
322
327
|
this.#nextId = Math.max(this.#nextId, candidateNextId);
|
|
@@ -336,6 +341,10 @@ export class RunStorage {
|
|
|
336
341
|
// Taken with their effects, now durable: no longer waiting.
|
|
337
342
|
for (const command of taking)
|
|
338
343
|
this.#takes.delete(command);
|
|
344
|
+
// A command taken, or a run gone final (its leftover rows refused): the readers of those answers in this process wake.
|
|
345
|
+
if (this.#where !== undefined && (taking.length > 0 || (patching && ["ended", "stopped", "failed"].includes(staged?.run?.state ?? "")))) {
|
|
346
|
+
wakeCommands(this.#where, { runId: this.#runId, what: "answered" });
|
|
347
|
+
}
|
|
339
348
|
// COMMIT returned: the stored batches are durable (to the store's synchronous level; flush makes them so on disk).
|
|
340
349
|
for (const [index, seq] of seqs.entries())
|
|
341
350
|
receive(index, seq);
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import pg from "pg";
|
|
8
8
|
import { runnableDeadline } from "../deadline.js";
|
|
9
9
|
import { cleanText } from "../dialect.js";
|
|
10
|
-
import {
|
|
10
|
+
import { ONE_ANSWER_INDEX } from "../schema.js";
|
|
11
|
+
import { AnswerTaken, Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned } from "../store.js";
|
|
11
12
|
import { DEFAULT_TRANSACTION_DEADLINE_MS } from "../sqlite/connection.js";
|
|
12
13
|
import { postgresDialect } from "./dialect.js";
|
|
13
14
|
/** Which store this is, as two opens of the same data agree on it (StoreConnection.where): "postgres:" and the URL's host
|
|
@@ -208,14 +209,18 @@ function bound(value) {
|
|
|
208
209
|
const returnsRows = (sql) => /^\s*(?:SELECT|WITH)\b/i.test(sql) || /\bRETURNING\b/i.test(sql);
|
|
209
210
|
/** Postgres's integrity SQLSTATEs, by the rule they name. */
|
|
210
211
|
const RULES = { "23514": "check", "23505": "unique", "23503": "foreign_key", "23502": "not_null" };
|
|
211
|
-
/** A unique violation's table and
|
|
212
|
-
* 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. */
|
|
213
216
|
async function withUnique(error, cause, columnsOf) {
|
|
214
217
|
const e = cause;
|
|
215
218
|
if (!(error instanceof StoreConstraint) || error.rule !== "unique" || !e?.table || !e.constraint)
|
|
216
219
|
return error;
|
|
220
|
+
if (e.constraint === ONE_ANSWER_INDEX)
|
|
221
|
+
return new AnswerTaken(error.message, e.constraint);
|
|
217
222
|
const columns = await columnsOf(e.constraint).catch(() => []);
|
|
218
|
-
return
|
|
223
|
+
return new StoreConstraint(error.message, { rule: "unique", index: e.constraint, ...(columns.length ? { unique: { table: e.table, columns } } : {}) });
|
|
219
224
|
}
|
|
220
225
|
/** A Postgres error as the store's own: a refused row StoreConstraint, a lock or a conflict StoreBusy. */
|
|
221
226
|
/** Whether `error` says the database ended the session (its idle-in-transaction timeout, SQLSTATE 25P03), or that the
|
|
@@ -13,6 +13,10 @@ export function postgresDialect(schema, { testClock = false } = {}) {
|
|
|
13
13
|
jsonNotFalse: (column, keys) => `COALESCE((${column}::json #> ${path(keys)})::text NOT IN ('false', '0'), TRUE)`,
|
|
14
14
|
jsonArrayHas: (column) => `EXISTS (SELECT 1 FROM json_array_elements_text(${column}::json) AS element(value) WHERE element.value = ?)`,
|
|
15
15
|
jsonArrayLength: (column) => `json_array_length(${column}::json)`,
|
|
16
|
+
// Through jsonb, the one place: a body that loses a key is never read for its key order. Every Postgres JSON function
|
|
17
|
+
// decodes the whole document's strings, so a body holding a string jsonb refuses (an escaped NUL, a lone surrogate)
|
|
18
|
+
// fails it: a computer call's params are written as one JSON text (computer-channel.ts), whose escapes jsonb keeps.
|
|
19
|
+
jsonWithout: (column, key) => `(${column}::jsonb - '${key.replaceAll("'", "''")}')::text`,
|
|
16
20
|
firingOrder: "ord",
|
|
17
21
|
limitAll: "LIMIT ALL",
|
|
18
22
|
nullSafeEquals: (column) => `${column} IS NOT DISTINCT FROM ?`,
|
|
@@ -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;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 5: a run's learning is kept by round, as store/schema.ts keeps it on SQLite
|
|
2
|
+
-- (version 7). A run's first end is round 1; each end after a follow-up opened the run again looks back once more, a
|
|
3
|
+
-- round of its own, beside the rounds before it. Applied once, after 0004, inside the transaction migrate.ts opens. Never
|
|
4
|
+
-- edit this file once applied: a change is a new file.
|
|
5
|
+
--
|
|
6
|
+
-- learning_proposals_pkey is Postgres's name for 0001's primary key on run_id.
|
|
7
|
+
-- Safe to apply again (a store whose later migrations are unrecorded re-applies them from the first one it cannot vouch for): every statement here is idempotent.
|
|
8
|
+
|
|
9
|
+
ALTER TABLE learning_proposals ADD COLUMN IF NOT EXISTS round BIGINT NOT NULL DEFAULT 1 CHECK (round >= 1);
|
|
10
|
+
ALTER TABLE learning_proposals ALTER COLUMN round DROP DEFAULT;
|
|
11
|
+
ALTER TABLE learning_proposals DROP CONSTRAINT IF EXISTS learning_proposals_pkey;
|
|
12
|
+
ALTER TABLE learning_proposals ADD PRIMARY KEY (run_id, round);
|
|
13
|
+
|
|
14
|
+
UPDATE store_meta SET schema_version = 5 WHERE singleton = 1;
|