@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.38
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 +452 -0
- package/README.md +311 -142
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +39 -14
- package/dist/answer-json.d.ts +34 -1
- package/dist/answer-json.js +91 -9
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- 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/browser-cost.d.ts +1 -1
- package/dist/browser-cost.js +52 -93
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -407
- package/dist/cap.js +4 -1028
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +4 -34
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +53 -0
- package/dist/composio-preset.js +221 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +60 -0
- package/dist/computer-calls.js +209 -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 +165 -0
- package/dist/computer-live.js +655 -0
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +14 -0
- package/dist/computer-view.js +51 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +311 -0
- package/dist/computers.d.ts +37 -8
- package/dist/computers.js +62 -14
- package/dist/console/assets/index-CjqQirbo.css +1 -0
- package/dist/console/assets/index-b6-XY5A9.js +576 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +3 -0
- package/dist/decisions.js +4 -0
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +56 -26
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness-opencode/adapter.js +7 -3
- package/dist/harness-opencode/facts.js +0 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -5
- package/dist/harness-opencode/host/policy.js +8 -32
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +0 -2
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +2 -6
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +5 -6
- package/dist/hosted-search.js +2 -28
- 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/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +13 -5
- package/dist/learn/commit.d.ts +14 -2
- package/dist/learn/commit.js +23 -9
- package/dist/learn/compile.d.ts +243 -0
- package/dist/learn/compile.js +471 -0
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +69 -0
- package/dist/learn/general.js +75 -0
- package/dist/learn/grade.d.ts +5 -1
- package/dist/learn/grade.js +29 -7
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +253 -0
- package/dist/learn/promote.js +428 -0
- package/dist/learn/refit.d.ts +39 -0
- package/dist/learn/refit.js +236 -0
- package/dist/learn/reflect.d.ts +9 -20
- package/dist/learn/reflect.js +18 -125
- package/dist/learn/replay-calls.d.ts +63 -0
- package/dist/learn/replay-calls.js +158 -0
- package/dist/learn/skills.d.ts +50 -14
- package/dist/learn/skills.js +183 -47
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +50 -2
- package/dist/learned-nodes.js +41 -2
- package/dist/learned-workflow.d.ts +43 -3
- package/dist/learned-workflow.js +170 -28
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-cost.d.ts +18 -6
- package/dist/learning-cost.js +15 -7
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +37 -2
- package/dist/learning-routes.js +52 -8
- package/dist/learning-words.d.ts +13 -0
- package/dist/learning-words.js +13 -0
- package/dist/learning.d.ts +55 -17
- package/dist/learning.js +91 -48
- 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/llm.js +0 -3
- package/dist/mcp-gateway.d.ts +21 -20
- package/dist/mcp-gateway.js +76 -55
- package/dist/mcp-oauth.d.ts +62 -7
- package/dist/mcp-oauth.js +134 -19
- package/dist/mcp-pin-first.d.ts +37 -0
- package/dist/mcp-pin-first.js +107 -0
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +27 -11
- package/dist/mcp-probe.js +60 -42
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +115 -25
- package/dist/mcp-servers-store.js +241 -43
- package/dist/mcp-sources.d.ts +39 -0
- package/dist/mcp-sources.js +74 -0
- package/dist/mcp-store.d.ts +21 -4
- package/dist/mcp-store.js +33 -8
- package/dist/mcp-wire.d.ts +22 -0
- package/dist/mcp-wire.js +36 -0
- package/dist/mcp.js +3 -3
- package/dist/meta-tool-names.d.ts +1 -0
- package/dist/meta-tool-names.js +3 -0
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +69 -25
- package/dist/monid.d.ts +51 -25
- package/dist/monid.js +226 -140
- package/dist/openapi.js +694 -59
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +26 -29
- package/dist/paid-calls.js +46 -102
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +10 -1
- package/dist/propose.js +30 -10
- package/dist/provider.js +12 -4
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +3 -2
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +27 -2
- package/dist/run-launch.js +15 -4
- package/dist/run-learning-served.d.ts +13 -2
- package/dist/run-manifest.d.ts +5 -0
- package/dist/run-manifest.js +20 -0
- 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 +2 -3
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +5 -2
- package/dist/run-view.d.ts +19 -8
- package/dist/run-view.js +62 -26
- package/dist/runnable.d.ts +0 -3
- package/dist/runnable.js +37 -29
- package/dist/runner/adapter-loop.d.ts +47 -17
- package/dist/runner/adapter-loop.js +1427 -303
- package/dist/runner/adapter-run-spec.d.ts +23 -9
- package/dist/runner/adapter-run-spec.js +162 -56
- package/dist/runner/adapters/pi-computer.d.ts +9 -0
- package/dist/runner/adapters/pi-computer.js +51 -0
- package/dist/runner/adapters/pi.d.ts +25 -11
- package/dist/runner/adapters/pi.js +168 -45
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- 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 +20 -3
- package/dist/runner/cli-run-spec.js +174 -64
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +62 -0
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +224 -17
- package/dist/runner/conformance/subject.d.ts +12 -5
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +23 -12
- package/dist/runner/end-of-run.js +41 -16
- package/dist/runner/feedback-round.d.ts +52 -0
- package/dist/runner/feedback-round.js +79 -0
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +44 -7
- package/dist/runner/journal-kinds.js +29 -0
- 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 +69 -13
- package/dist/runner/learning-end.js +340 -87
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +86 -8
- package/dist/runner/learning-loop.js +178 -23
- package/dist/runner/learning-seed.d.ts +11 -0
- package/dist/runner/learning-seed.js +27 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +26 -3
- package/dist/runner/loop.d.ts +21 -2
- package/dist/runner/loop.js +23 -2
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +15 -8
- package/dist/runner/mcp-claim.js +176 -71
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +21 -57
- package/dist/runner/mcp-run.js +25 -85
- package/dist/runner/meta-tools.d.ts +37 -0
- package/dist/runner/meta-tools.js +268 -0
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +26 -5
- package/dist/runner/model-route.js +12 -3
- package/dist/runner/monid-run.d.ts +16 -0
- package/dist/runner/monid-run.js +96 -0
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/promotion.d.ts +80 -0
- package/dist/runner/promotion.js +562 -0
- package/dist/runner/reflect-hook.d.ts +46 -13
- package/dist/runner/reflect-hook.js +149 -48
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +208 -17
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +9 -4
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +10 -13
- package/dist/runner/workflow-first.d.ts +216 -0
- package/dist/runner/workflow-first.js +303 -0
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +15 -2
- package/dist/runner/workflow-spec.js +63 -23
- package/dist/runs-over-store.d.ts +17 -3
- package/dist/runs-over-store.js +59 -20
- 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/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 +119 -18
- package/dist/server.js +841 -202
- package/dist/settings-wake.d.ts +23 -0
- package/dist/settings-wake.js +65 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +14 -10
- package/dist/store/command-wake.d.ts +13 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/connection.js +3 -1
- package/dist/store/postgres/dialect.js +4 -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/postgres/migrations/0010_imported_templates.sql +18 -0
- package/dist/store/postgres/migrations/0011_revision_mcp_pin.sql +13 -0
- package/dist/store/schema.d.ts +10 -1
- package/dist/store/schema.js +104 -15
- package/dist/store/sqlite/connection.d.ts +2 -2
- package/dist/store/sqlite/connection.js +2 -2
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +45 -18
- package/dist/store/sqlite/store.js +331 -72
- package/dist/store/store.d.ts +312 -21
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +30 -5
- package/dist/store-reads/journal.js +128 -56
- package/dist/store-reads/learning.d.ts +114 -12
- package/dist/store-reads/learning.js +238 -48
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +6 -0
- package/dist/store-view.js +59 -26
- package/dist/template-eval.d.ts +18 -9
- package/dist/template-eval.js +95 -68
- package/dist/template-github-permissions.d.ts +24 -10
- package/dist/template-github-permissions.js +36 -15
- package/dist/template-import.d.ts +31 -0
- package/dist/template-import.js +121 -0
- package/dist/template-source.d.ts +51 -0
- package/dist/template-source.js +371 -0
- package/dist/templates.d.ts +218 -46
- package/dist/templates.js +493 -181
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +4 -3
- package/dist/timeline/index.js +4 -3
- package/dist/timeline/labels.d.ts +6 -2
- package/dist/timeline/labels.js +93 -2
- package/dist/timeline/origin.d.ts +19 -5
- package/dist/timeline/origin.js +11 -4
- package/dist/timeline/timeline.d.ts +22 -1
- package/dist/timeline/timeline.js +34 -18
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-gate.d.ts +84 -50
- package/dist/tool-gate.js +179 -101
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +26 -0
- package/dist/tool-list.js +43 -0
- package/dist/tool-names.d.ts +71 -0
- package/dist/tool-names.js +99 -0
- package/dist/tool-plane.d.ts +33 -27
- package/dist/tool-plane.js +72 -39
- package/dist/tools.d.ts +32 -7
- package/dist/tools.js +37 -24
- 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 +25 -6
- package/dist/trigger-signatures.js +41 -7
- 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 +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +102 -45
- package/dist/web-fetch.d.ts +2 -8
- package/dist/web-fetch.js +2 -22
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +19 -9
- package/dist/workspace/computer-deps.js +24 -9
- package/dist/workspace/computer-for-claim.d.ts +23 -8
- package/dist/workspace/computer-for-claim.js +92 -33
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +41 -55
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -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 +53 -0
- package/dist/workspace/computer-script.js +172 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +132 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +104 -85
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +24 -1
- package/dist/workspace/resolve-computer.js +40 -16
- package/dist/workspace/run-tools.d.ts +56 -21
- package/dist/workspace/run-tools.js +55 -34
- package/dist/wrap-up.d.ts +21 -0
- package/dist/wrap-up.js +21 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +19 -16
- package/templates/README.md +111 -45
- package/templates/code-review/agent.md +30 -14
- package/templates/code-review/evals/clean-refactor/case.yaml +2 -1
- package/templates/code-review/evals/clean-refactor/graders/head-sha.md +6 -0
- package/templates/code-review/evals/injection/case.yaml +2 -1
- package/templates/code-review/evals/injection/graders/head-sha.md +6 -0
- package/templates/code-review/evals/mentions-defused/case.yaml +2 -2
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -23
- package/templates/code-review/evals/mentions-defused/graders/head-sha.md +6 -0
- package/templates/code-review/evals/never-flag/case.yaml +2 -1
- package/templates/code-review/evals/never-flag/graders/head-sha.md +6 -0
- package/templates/code-review/evals/null-name/case.yaml +2 -1
- package/templates/code-review/evals/null-name/graders/head-sha.md +6 -0
- package/templates/code-review/evals/off-by-one/case.yaml +2 -1
- package/templates/code-review/evals/off-by-one/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/case.yaml +16 -0
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +130 -0
- package/templates/code-review/evals/other-repo/graders/head-sha.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-canary.md +6 -0
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/code-review/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/code-review/evals/other-repo/prompt.md +10 -0
- package/templates/code-review/evals/re-review/case.yaml +2 -1
- package/templates/code-review/evals/re-review/graders/head-sha.md +6 -0
- package/templates/code-review/evals/re-review-open/case.yaml +2 -1
- package/templates/code-review/evals/re-review-open/graders/head-sha.md +6 -0
- package/templates/code-review/evals/repo-rule/case.yaml +2 -1
- package/templates/code-review/evals/repo-rule/graders/head-sha.md +6 -0
- package/templates/code-review/evals/two-defects/case.yaml +2 -1
- package/templates/code-review/evals/two-defects/graders/head-sha.md +6 -0
- package/templates/code-review/rules/CODEREVIEW.md +1 -1
- package/templates/code-review/skills/review/DEEP.md +3 -2
- package/templates/code-review/skills/review/REVIEWER.md +3 -2
- package/templates/code-review/skills/review/SKILL.md +4 -3
- package/templates/code-review/{findings.schema.json → skills/review/findings.schema.json} +1 -0
- package/templates/inbound-lead/agent.md +26 -16
- package/templates/inbound-lead/evals/injection-in-form/graders/no-exfil.md +16 -0
- package/templates/inbound-lead/evals/injection-in-form/prompt.md +2 -2
- package/templates/inbound-lead/evals/write-back/case.yaml +2 -6
- package/templates/inbound-lead/evals/write-back/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back/graders/note-and-score.md +10 -14
- package/templates/inbound-lead/evals/write-back/graders/writes-once.md +7 -0
- package/templates/inbound-lead/evals/write-back/prompt.md +1 -1
- package/templates/inbound-lead/evals/write-back-wrong-record/case.yaml +3 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/fixtures/fake-hubspot.json +34 -225
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/form-id.md +17 -0
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/no-write.md +3 -3
- package/templates/inbound-lead/evals/write-back-wrong-record/prompt.md +2 -2
- package/templates/inbound-lead/skills/lead/SKILL.md +23 -27
- package/templates/kyb/agent.md +15 -5
- package/templates/kyb/evals/adverse-media/prompt.md +2 -7
- package/templates/kyb/evals/canada-active-filed/prompt.md +2 -6
- package/templates/kyb/evals/clean-public-company/prompt.md +2 -6
- package/templates/kyb/evals/injection-in-page/prompt.md +3 -7
- package/templates/kyb/evals/name-collision/prompt.md +2 -6
- package/templates/kyb/evals/no-invention/prompt.md +2 -6
- package/templates/kyb/evals/opensanctions-on/prompt.md +2 -6
- package/templates/kyb/evals/sanctioned-entity/prompt.md +2 -6
- package/templates/kyb/kyb.schema.json +8 -7
- package/templates/kyb/skills/kyb/SKILL.md +9 -6
- package/templates/market-monitor/agent.md +19 -12
- package/templates/market-monitor/evals/post-happens/case.yaml +4 -4
- package/templates/market-monitor/evals/post-happens/fixtures/slack-mcp.json +13 -9
- package/templates/market-monitor/evals/post-happens/graders/post-is-digest.md +1 -1
- package/templates/market-monitor/evals/post-happens/graders/posted-once.md +3 -3
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/templates/release-notes/agent.md +32 -10
- package/templates/release-notes/evals/draft-not-publish/case.yaml +4 -3
- package/templates/release-notes/evals/draft-not-publish/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/every-pr-accounted/case.yaml +2 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +4 -3
- package/templates/release-notes/evals/issue-write-refused/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/late-arrival/case.yaml +6 -5
- package/templates/release-notes/evals/late-arrival/fixtures/github-mcp.json +29 -51
- package/templates/release-notes/evals/learned-style/case.yaml +2 -1
- package/templates/release-notes/evals/no-pr-numbers-on-top/case.yaml +2 -1
- package/templates/release-notes/evals/other-repo/case.yaml +24 -0
- package/templates/release-notes/evals/other-repo/fixtures/github-mcp.json +907 -0
- package/templates/release-notes/evals/other-repo/graders/no-canary.md +7 -0
- package/templates/release-notes/evals/other-repo/graders/no-other-repo.md +8 -0
- package/templates/release-notes/evals/other-repo/graders/refused-not-quoted.md +18 -0
- package/templates/release-notes/evals/other-repo/prompt.md +32 -0
- package/templates/release-notes/evals/upgrade-line/case.yaml +2 -1
- package/templates/release-notes/evals/user-facing-only/case.yaml +2 -1
- package/templates/release-notes/notes.schema.json +1 -1
- package/templates/release-notes/skills/release-notes/SKILL.md +26 -17
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.d.ts +0 -26
- package/dist/tool-budget.js +0 -56
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
- package/templates/code-review/evals/clean-refactor/graders/schema.md +0 -5
- package/templates/code-review/evals/injection/graders/schema.md +0 -5
- package/templates/code-review/evals/mentions-defused/graders/schema.md +0 -5
- package/templates/code-review/evals/never-flag/graders/schema.md +0 -5
- package/templates/code-review/evals/null-name/graders/schema.md +0 -5
- package/templates/code-review/evals/off-by-one/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review/graders/schema.md +0 -5
- package/templates/code-review/evals/re-review-open/graders/schema.md +0 -5
- package/templates/code-review/evals/repo-rule/graders/schema.md +0 -5
- package/templates/code-review/evals/two-defects/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/clear-disqualifier/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/injection-in-form/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/learned-correction/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/strong-fit/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/thin-data/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/schema.md +0 -5
- package/templates/inbound-lead/evals/write-back/graders/writes-twice.md +0 -7
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/proves-record.md +0 -18
- package/templates/inbound-lead/evals/write-back-wrong-record/graders/schema.md +0 -5
- package/templates/kyb/evals/adverse-media/graders/schema.md +0 -5
- package/templates/kyb/evals/canada-active-filed/graders/schema.md +0 -5
- package/templates/kyb/evals/clean-public-company/graders/schema.md +0 -5
- package/templates/kyb/evals/injection-in-page/graders/schema.md +0 -5
- package/templates/kyb/evals/name-collision/graders/schema.md +0 -5
- package/templates/kyb/evals/no-invention/graders/schema.md +0 -5
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +0 -5
- package/templates/kyb/evals/sanctioned-entity/graders/schema.md +0 -5
- package/templates/market-monitor/evals/blocked-source/graders/schema.md +0 -5
- package/templates/market-monitor/evals/every-competitor-named/graders/schema.md +0 -5
- package/templates/market-monitor/evals/learned-preference/graders/schema.md +0 -5
- package/templates/market-monitor/evals/no-repeats/graders/schema.md +0 -5
- package/templates/market-monitor/evals/nothing-changed/graders/schema.md +0 -5
- package/templates/market-monitor/evals/post-happens/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-change/graders/schema.md +0 -5
- package/templates/market-monitor/evals/pricing-moved/graders/schema.md +0 -5
- package/templates/release-notes/evals/draft-not-publish/graders/schema.md +0 -5
- package/templates/release-notes/evals/every-pr-accounted/graders/schema.md +0 -5
- package/templates/release-notes/evals/issue-write-refused/graders/schema.md +0 -5
- package/templates/release-notes/evals/late-arrival/graders/schema.md +0 -5
- package/templates/release-notes/evals/learned-style/graders/schema.md +0 -5
- package/templates/release-notes/evals/no-pr-numbers-on-top/graders/schema.md +0 -5
- package/templates/release-notes/evals/upgrade-line/graders/schema.md +0 -5
- package/templates/release-notes/evals/user-facing-only/graders/schema.md +0 -5
|
@@ -0,0 +1,23 @@
|
|
|
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, MCP pins and journals, and the wake
|
|
4
|
+
* itself. */
|
|
5
|
+
export type WakeStore = Pick<Store, "runs" | "agents" | "readJournal" | "mcp">;
|
|
6
|
+
/** Whether a save changed any tool key's permission (added, removed or changed), or an MCP server's Allow reads
|
|
7
|
+
* (`allow_reads` on its wildcard, which lifts a read-only tool's ask). It does not predict which edit flips a call's
|
|
8
|
+
* answer (an exact `ask` under a wildcard `deny` flips when only the wildcard moves): it only skips a save that touches
|
|
9
|
+
* neither (a provider alone, a pin). The per-run decision is permissionFrom's. Approvals live on the run's revision, not
|
|
10
|
+
* in the server's settings, so a save cannot change them. */
|
|
11
|
+
export declare function permissionsChanged(before: ToolSettingsMap, after: ToolSettingsMap): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Wakes every parked run with a call waiting on its person whose tool reads allow now on the run's pinned revision: its
|
|
14
|
+
* own tool settings and approvals over the server's `read` (tool-gate.ts permissionFrom, the gate's one rule, a deny set
|
|
15
|
+
* on the server absolute). A run whose waiting calls all still read ask or deny is left parked, never claimed. Answers
|
|
16
|
+
* the runs woken.
|
|
17
|
+
*
|
|
18
|
+
* The run's gate stays the judge: the claim reads the settings again at the call, so a run woken here whose call reads
|
|
19
|
+
* otherwise by then (a pin, a setting changed since) parks again or is refused, in the gate's words. Where the server
|
|
20
|
+
* 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
|
|
21
|
+
* shell tool on its default, which is where the run's shell is (no computer: bash asks).
|
|
22
|
+
*/
|
|
23
|
+
export declare function wakeAnsweredBySetting(store: WakeStore, read: ToolSettingsRead, before: ToolSettingsMap): Promise<string[]>;
|
|
@@ -0,0 +1,65 @@
|
|
|
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, pinnedEffect, SHELL_FAMILY } from "./tool-gate.js";
|
|
11
|
+
import { isMcpName } from "./tool-names.js";
|
|
12
|
+
/** Whether a save changed any tool key's permission (added, removed or changed), or an MCP server's Allow reads
|
|
13
|
+
* (`allow_reads` on its wildcard, which lifts a read-only tool's ask). It does not predict which edit flips a call's
|
|
14
|
+
* answer (an exact `ask` under a wildcard `deny` flips when only the wildcard moves): it only skips a save that touches
|
|
15
|
+
* neither (a provider alone, a pin). The per-run decision is permissionFrom's. Approvals live on the run's revision, not
|
|
16
|
+
* in the server's settings, so a save cannot change them. */
|
|
17
|
+
export function permissionsChanged(before, after) {
|
|
18
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
19
|
+
if (before[key]?.permission !== after[key]?.permission || before[key]?.allow_reads !== after[key]?.allow_reads)
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Wakes every parked run with a call waiting on its person whose tool reads allow now on the run's pinned revision: its
|
|
26
|
+
* own tool settings and approvals over the server's `read` (tool-gate.ts permissionFrom, the gate's one rule, a deny set
|
|
27
|
+
* on the server absolute). A run whose waiting calls all still read ask or deny is left parked, never claimed. Answers
|
|
28
|
+
* the runs woken.
|
|
29
|
+
*
|
|
30
|
+
* The run's gate stays the judge: the claim reads the settings again at the call, so a run woken here whose call reads
|
|
31
|
+
* otherwise by then (a pin, a setting changed since) parks again or is refused, in the gate's words. Where the server
|
|
32
|
+
* 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
|
|
33
|
+
* shell tool on its default, which is where the run's shell is (no computer: bash asks).
|
|
34
|
+
*/
|
|
35
|
+
export async function wakeAnsweredBySetting(store, read, before) {
|
|
36
|
+
if (read.unreadable)
|
|
37
|
+
return [];
|
|
38
|
+
// A save that changed no permission (a provider alone, a pin) answers no ask: no run is listed, no journal read.
|
|
39
|
+
if (!permissionsChanged(before, read.settings))
|
|
40
|
+
return [];
|
|
41
|
+
const server = read.settings;
|
|
42
|
+
const woken = [];
|
|
43
|
+
for (const run of await store.runs.list({ state: "parked" })) {
|
|
44
|
+
const entries = await journalEntries(store.readJournal(run.id), BACKGROUND_CONTEXT);
|
|
45
|
+
const answers = answersOf(entries);
|
|
46
|
+
// The ask names the call by its settings key (a shell tool by its own name), as the gate's askedAs gives it.
|
|
47
|
+
const waiting = [...asksOf(entries).values()].filter((ask) => !ask.resolved && !(ask.id in answers)).map((ask) => ask.tool);
|
|
48
|
+
if (waiting.length === 0)
|
|
49
|
+
continue;
|
|
50
|
+
const revision = await store.agents.revision(run.revisionId);
|
|
51
|
+
const body = (revision?.body ?? {});
|
|
52
|
+
const agent = (body.toolSettings ?? {});
|
|
53
|
+
// An MCP call's effect as the run's pin holds it (the gate's ClaimMcp.effectOf reads the same), so Allow reads lifts a
|
|
54
|
+
// read here as the claim's gate will: read once, only for a run with an MCP call waiting.
|
|
55
|
+
const pin = waiting.some(isMcpName) ? (await store.mcp.pin(run.id))?.body : undefined;
|
|
56
|
+
const effectOf = (tool) => (pin ? pinnedEffect(pin, tool) : undefined);
|
|
57
|
+
const allowed = waiting.some((tool) => {
|
|
58
|
+
const { permission, from } = permissionFrom(tool, server, agent, approvalsOf(body.approvals), {}, effectOf(tool));
|
|
59
|
+
return permission === "allow" && !(from === "default" && Object.hasOwn(SHELL_FAMILY, tool));
|
|
60
|
+
});
|
|
61
|
+
if (allowed && (await store.runs.wake(run.id)))
|
|
62
|
+
woken.push(run.id);
|
|
63
|
+
}
|
|
64
|
+
return woken;
|
|
65
|
+
}
|
|
@@ -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
|
}
|
|
@@ -28,7 +28,8 @@ export type RevisionPlace = {
|
|
|
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
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
|
+
* the kind, absent for its default. A desktop's or a phone's surface and exec: how the agent drives it, and whether it
|
|
32
|
+
* may run programs on it. */
|
|
32
33
|
export type RevisionComputer = {
|
|
33
34
|
kind: string;
|
|
34
35
|
provider?: string;
|
|
@@ -38,6 +39,8 @@ export type RevisionComputer = {
|
|
|
38
39
|
count: number;
|
|
39
40
|
};
|
|
40
41
|
persistent?: boolean;
|
|
42
|
+
surface?: "code" | "tools";
|
|
43
|
+
exec?: boolean;
|
|
41
44
|
};
|
|
42
45
|
/** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
|
|
43
46
|
* pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
|
|
@@ -45,6 +48,13 @@ export type RevisionComputer = {
|
|
|
45
48
|
export type ToolSettings = Record<string, unknown>;
|
|
46
49
|
/** The model of each tier an agentic revision names (its definition's `model_tiers`: fast, strong), each "provider/model-id". */
|
|
47
50
|
export type ModelTiers = Partial<Record<"fast" | "strong", string>>;
|
|
51
|
+
/** A revision's monid pin (monid.ts MonidPin): each granted endpoint by its catalog name, as monid listed it at the save.
|
|
52
|
+
* Stamped by the save's check (server.ts saveable), never read from a definition nor shown in one. */
|
|
53
|
+
export type MonidPinBody = Readonly<Record<string, {
|
|
54
|
+
readonly description: string;
|
|
55
|
+
readonly input: Record<string, unknown>;
|
|
56
|
+
readonly usd: number;
|
|
57
|
+
}>>;
|
|
48
58
|
export type AgenticBody = {
|
|
49
59
|
instructions: string;
|
|
50
60
|
skills: Record<string, string>;
|
|
@@ -61,9 +71,10 @@ export type AgenticBody = {
|
|
|
61
71
|
maxCostUsd?: number;
|
|
62
72
|
capMode?: string;
|
|
63
73
|
approvals?: "ask" | "never";
|
|
74
|
+
inputSchema?: Record<string, unknown>;
|
|
64
75
|
outputSchema?: Record<string, unknown>;
|
|
65
|
-
maxToolCalls?: number;
|
|
66
76
|
checkout?: "pull_request";
|
|
77
|
+
monidPin?: MonidPinBody;
|
|
67
78
|
};
|
|
68
79
|
export type WorkflowBody = {
|
|
69
80
|
workflow: Record<string, unknown>;
|
|
@@ -96,8 +107,8 @@ export type RevisionBodyInput = {
|
|
|
96
107
|
maxCostUsd?: number;
|
|
97
108
|
capMode?: string;
|
|
98
109
|
approvals?: "ask" | "never";
|
|
110
|
+
inputSchema?: Record<string, unknown>;
|
|
99
111
|
outputSchema?: Record<string, unknown>;
|
|
100
|
-
maxToolCalls?: number;
|
|
101
112
|
checkout?: "pull_request";
|
|
102
113
|
} | {
|
|
103
114
|
kind: "workflow";
|
package/dist/store/agent-body.js
CHANGED
|
@@ -44,21 +44,25 @@ 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
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
/** The keys a body's computer keeps. */
|
|
48
|
+
const COMPUTER_KEYS = new Set(["kind", "provider", "image", "gpu", "persistent", "surface", "exec"]);
|
|
49
|
+
/** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?, surface?, exec?}`, nothing else: kind
|
|
50
|
+
* and provider ids, image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole count from
|
|
51
|
+
* 1, persistent and exec booleans, and surface code or tools. */
|
|
50
52
|
function computerOf(computer) {
|
|
51
53
|
const image = isObject(computer) ? computer.image : undefined;
|
|
52
54
|
const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const flag = (value) => value === undefined || typeof value === "boolean";
|
|
56
|
+
const surface = isObject(computer) ? computer.surface : undefined;
|
|
57
|
+
if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || !flag(computer.persistent) || !flag(computer.exec) || (surface !== undefined && surface !== "code" && surface !== "tools") || Object.keys(computer).some((key) => !COMPUTER_KEYS.has(key)))
|
|
58
|
+
invalid("the computer is not {kind, provider?, image?, gpu?, persistent?, surface?, exec?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean, surface code or tools, exec a boolean");
|
|
55
59
|
const ok = computer;
|
|
56
60
|
const gpu = ok.gpu;
|
|
57
61
|
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)) {
|
|
58
62
|
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");
|
|
59
63
|
}
|
|
60
64
|
const kept = gpu;
|
|
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 } : {}) };
|
|
65
|
+
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 } : {}), ...(ok.surface !== undefined ? { surface: ok.surface } : {}), ...(ok.exec !== undefined ? { exec: ok.exec } : {}) };
|
|
62
66
|
}
|
|
63
67
|
/** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
|
|
64
68
|
* write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
|
|
@@ -112,14 +116,14 @@ export function bodyOf(input) {
|
|
|
112
116
|
invalid(`the ${field} is not a non-empty string`);
|
|
113
117
|
if (input.learning !== undefined && typeof input.learning !== "boolean" && input.learning !== "notes")
|
|
114
118
|
invalid("learning is not true, false or \"notes\"");
|
|
119
|
+
if (input.inputSchema !== undefined && !isObject(input.inputSchema))
|
|
120
|
+
invalid("the inputSchema is not a JSON object");
|
|
115
121
|
if (input.outputSchema !== undefined && !isObject(input.outputSchema))
|
|
116
122
|
invalid("the outputSchema is not a JSON object");
|
|
117
123
|
if (input.checkout !== undefined && input.checkout !== "pull_request")
|
|
118
124
|
invalid("the checkout is not pull_request");
|
|
119
125
|
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
126
|
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");
|
|
123
127
|
const body = {
|
|
124
128
|
instructions: input.instructions,
|
|
125
129
|
skills: skillShas,
|
|
@@ -130,12 +134,12 @@ export function bodyOf(input) {
|
|
|
130
134
|
...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
|
|
131
135
|
...host,
|
|
132
136
|
...(input.learning !== undefined ? { learning: input.learning } : {}),
|
|
137
|
+
// The JSON Schema each run's input meets (definition.input_schema), checked at every start (validate.ts inputSchemaOf).
|
|
138
|
+
...(input.inputSchema !== undefined ? { inputSchema: structuredClone(input.inputSchema) } : {}),
|
|
133
139
|
// The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
|
|
134
140
|
...(input.outputSchema !== undefined ? { outputSchema: structuredClone(input.outputSchema) } : {}),
|
|
135
141
|
// What the server checks out in each run's folder before its first turn (runner/pr-checkout.ts).
|
|
136
142
|
...(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 } : {}),
|
|
139
143
|
// The agent's unattended policy (PR #2003): the runner's gate reads it from the revision body at claim (`unattended`
|
|
140
144
|
// below: "never" alone is kept).
|
|
141
145
|
...capped,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What woke a listener: a command row was written for the run, or one was taken, refused or answered; or the run was
|
|
2
|
+
* queued (a new run a runner may claim now). */
|
|
3
|
+
export interface CommandWake {
|
|
4
|
+
readonly runId: string;
|
|
5
|
+
readonly what: "written" | "answered" | "queued";
|
|
6
|
+
}
|
|
7
|
+
type Listener = (event: CommandWake) => void;
|
|
8
|
+
/** Subscribes `listener` to the commands of the data at `where`; answers the unsubscribe. */
|
|
9
|
+
export declare function watchCommandsAt(where: string, listener: Listener): () => void;
|
|
10
|
+
/** Tells the listeners of `where` about `events`, after the write committed: asynchronously, each listener's throw
|
|
11
|
+
* swallowed, so a write never waits on or fails with a listener. */
|
|
12
|
+
export declare function wakeCommands(where: string, ...events: readonly CommandWake[]): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// A wake for command rows and new runs: a hint to read now, not a source of truth. An in-process bus keyed by a store's
|
|
2
|
+
// `where` (two handles on the same data share one), so a write through one handle wakes the readers of the others without
|
|
3
|
+
// waiting for their poll. It reaches handles in this process only: a row another process writes wakes nothing here, and
|
|
4
|
+
// the reader's 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/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,5 +1,5 @@
|
|
|
1
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, 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";
|
|
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
3
|
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunMcpAuth, type RunMcpAuth, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
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";
|
|
@@ -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,7 +314,7 @@ 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
|
}
|
|
@@ -337,6 +341,10 @@ export class RunStorage {
|
|
|
337
341
|
// Taken with their effects, now durable: no longer waiting.
|
|
338
342
|
for (const command of taking)
|
|
339
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
|
+
}
|
|
340
348
|
// COMMIT returned: the stored batches are durable (to the store's synchronous level; flush makes them so on disk).
|
|
341
349
|
for (const [index, seq] of seqs.entries())
|
|
342
350
|
receive(index, seq);
|
|
@@ -387,7 +387,9 @@ export class PgConnection {
|
|
|
387
387
|
// connectionTimeoutMillis bounds a new connection's connect and startup, and a wait for a pool client to come free.
|
|
388
388
|
// keepAlive: this end's TCP keepalives, from KEEPALIVE_IDLE_S (pg's default delay, 0, is the OS's 2 h).
|
|
389
389
|
const tcp = { keepAlive: true, keepAliveInitialDelayMillis: KEEPALIVE_IDLE_S * 1_000 };
|
|
390
|
-
|
|
390
|
+
// Every connection named for its schema, as the lease's and the owner lock's are: pg_stat_activity tells which
|
|
391
|
+
// store holds each one.
|
|
392
|
+
const config = { connectionString: url, options: session, types, max: poolSize, allowExitOnIdle: true, application_name: `agentrun-store:${schema}`, connectionTimeoutMillis: connectMs, ...tcp };
|
|
391
393
|
let lock;
|
|
392
394
|
const waitMs = Math.max(0, Math.floor(ownerWaitMs));
|
|
393
395
|
if (owner) {
|
|
@@ -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,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;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 6: the run-change feed (Runs.changedSince), each channel post's tries (the
|
|
2
|
+
-- outbound webhook's deliveries log) and the claim a post's try settles under, as SQLite's schema version 8 has them.
|
|
3
|
+
--
|
|
4
|
+
-- A change is a run reaching a final state, or let go by its runner (parked, or running with none), written by the
|
|
5
|
+
-- trigger below in the transaction of the write that made it. Postgres has many writers, so a sequence alone does not
|
|
6
|
+
-- number changes in commit order: the trigger takes one transaction-scoped advisory lock before it inserts, so two
|
|
7
|
+
-- transactions that each write a change commit them in seq order, and a reader that has read seq n has every change at
|
|
8
|
+
-- or below it. The trigger is deferred to the commit, so the lock is held only while the change is numbered and the
|
|
9
|
+
-- transaction commits: a run's end write and the statements after it never wait on another run's, which would make a
|
|
10
|
+
-- runner of many loops end its runs one at a time.
|
|
11
|
+
CREATE TABLE IF NOT EXISTS run_changes (
|
|
12
|
+
seq BIGSERIAL PRIMARY KEY,
|
|
13
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
14
|
+
state TEXT COLLATE "C" NOT NULL,
|
|
15
|
+
ended_at BIGINT,
|
|
16
|
+
epoch BIGINT NOT NULL,
|
|
17
|
+
runner TEXT COLLATE "C"
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
CREATE OR REPLACE FUNCTION run_changed() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
21
|
+
BEGIN
|
|
22
|
+
PERFORM pg_advisory_xact_lock(hashtext(TG_TABLE_SCHEMA || '.run_changes'));
|
|
23
|
+
EXECUTE format('INSERT INTO %I.run_changes (run_id, state, ended_at, epoch, runner) VALUES ($1, $2, $3, $4, $5)', TG_TABLE_SCHEMA)
|
|
24
|
+
USING NEW.id, NEW.state, NEW.ended_at, NEW.epoch, NEW.runner;
|
|
25
|
+
RETURN NULL;
|
|
26
|
+
END
|
|
27
|
+
$$;
|
|
28
|
+
|
|
29
|
+
DROP TRIGGER IF EXISTS runs_changed ON runs;
|
|
30
|
+
CREATE CONSTRAINT TRIGGER runs_changed AFTER UPDATE OF state, runner ON runs
|
|
31
|
+
DEFERRABLE INITIALLY DEFERRED
|
|
32
|
+
FOR EACH ROW
|
|
33
|
+
WHEN ((OLD.state IS DISTINCT FROM NEW.state OR OLD.runner IS DISTINCT FROM NEW.runner)
|
|
34
|
+
AND (NEW.state IN ('ended', 'stopped', 'failed', 'parked') OR (NEW.state = 'running' AND NEW.runner IS NULL)))
|
|
35
|
+
EXECUTE FUNCTION run_changed();
|
|
36
|
+
|
|
37
|
+
-- A post's try settles under the claim that made it (Channels.settle's fence): the claim's token, kept on the post until
|
|
38
|
+
-- a newer claim or a write outside every claim takes it.
|
|
39
|
+
ALTER TABLE channel_posts ADD COLUMN IF NOT EXISTS claim TEXT COLLATE "C";
|
|
40
|
+
|
|
41
|
+
-- Each try once, by its id: a settle written again (its outcome unknown) logs it once.
|
|
42
|
+
CREATE TABLE IF NOT EXISTS channel_attempts (
|
|
43
|
+
seq BIGSERIAL PRIMARY KEY,
|
|
44
|
+
try_id TEXT COLLATE "C" NOT NULL UNIQUE,
|
|
45
|
+
channel TEXT COLLATE "C" NOT NULL,
|
|
46
|
+
post_id TEXT COLLATE "C" NOT NULL,
|
|
47
|
+
moment TEXT COLLATE "C" NOT NULL,
|
|
48
|
+
at BIGINT NOT NULL,
|
|
49
|
+
status_code BIGINT,
|
|
50
|
+
latency_ms BIGINT NOT NULL,
|
|
51
|
+
error TEXT COLLATE "C",
|
|
52
|
+
retry_at BIGINT,
|
|
53
|
+
redelivery BIGINT NOT NULL CHECK (redelivery IN (0, 1))
|
|
54
|
+
);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS channel_attempts_by_channel ON channel_attempts (channel, seq);
|
|
56
|
+
|
|
57
|
+
UPDATE store_meta SET schema_version = 6 WHERE singleton = 1;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 7: where a live viewer answers when its runner is on another host than the
|
|
2
|
+
-- server (live-reach.ts), as store/schema.ts keeps it on SQLite (version 9). Applied once, after 0006, inside the transaction
|
|
3
|
+
-- migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- computer_viewers.host: the runner's live host (AGENTRUN_RUNNER_LIVE_HOST); null, the server's own machine (loopback).
|
|
6
|
+
-- IF NOT EXISTS: applied again over a store that has it (the migration-0003 repair re-runs every migration after 0002),
|
|
7
|
+
-- it changes nothing.
|
|
8
|
+
|
|
9
|
+
ALTER TABLE computer_viewers ADD COLUMN IF NOT EXISTS host TEXT COLLATE "C";
|
|
10
|
+
|
|
11
|
+
UPDATE store_meta SET schema_version = 7 WHERE singleton = 1;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 8: a person's own computer paired with this server (spec/computer/attach.md),
|
|
2
|
+
-- and the codes that pair one, as store/schema.ts keeps them on SQLite (version 10). Applied once, after 0007, inside the transaction
|
|
3
|
+
-- migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- paired_computers: the token's SHA-256 alone is kept (hex); revoked_at marks a removed computer, whose token dials no more.
|
|
6
|
+
-- pairing_codes: a code's SHA-256 alone (hex), good once until expires_at; a used one is deleted as it pairs. Its id names
|
|
7
|
+
-- the pairing and is kept on the computer it made (paired_computers.pairing_id), so the console that made the code can
|
|
8
|
+
-- tell its own code was used, and by which computer.
|
|
9
|
+
-- Each table is made only where it is missing, so a store whose record of this file was lost applies it again unharmed.
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS paired_computers (
|
|
12
|
+
id TEXT COLLATE "C" PRIMARY KEY,
|
|
13
|
+
name TEXT COLLATE "C" NOT NULL,
|
|
14
|
+
hello TEXT COLLATE "C" NOT NULL CHECK (hello::json IS NOT NULL),
|
|
15
|
+
driver TEXT COLLATE "C" NOT NULL,
|
|
16
|
+
labels TEXT COLLATE "C" NOT NULL CHECK (labels::json IS NOT NULL),
|
|
17
|
+
token_sha256 TEXT COLLATE "C" NOT NULL UNIQUE,
|
|
18
|
+
pairing_id TEXT COLLATE "C" NOT NULL UNIQUE,
|
|
19
|
+
created_at BIGINT NOT NULL,
|
|
20
|
+
seen_at BIGINT,
|
|
21
|
+
revoked_at BIGINT
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
CREATE TABLE IF NOT EXISTS pairing_codes (
|
|
25
|
+
id TEXT COLLATE "C" NOT NULL UNIQUE,
|
|
26
|
+
code_sha256 TEXT COLLATE "C" PRIMARY KEY,
|
|
27
|
+
expires_at BIGINT NOT NULL
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
UPDATE store_meta SET schema_version = 8 WHERE singleton = 1;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 9: a command keeps its answer, as store/schema.ts keeps it on SQLite
|
|
2
|
+
-- (version 11, commands.answer). The runner writes it with the commit that takes the row; the server reads it once and clears it
|
|
3
|
+
-- (Store.answerOf). Applied once, after 0008, inside the transaction migrate.ts opens. Never edit this file once applied: a
|
|
4
|
+
-- change is a new file.
|
|
5
|
+
--
|
|
6
|
+
-- answer: JSON text, NULL until a take writes one and again once it is read.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE commands ADD COLUMN answer TEXT COLLATE "C" CHECK (answer IS NULL OR answer::json IS NOT NULL);
|
|
9
|
+
|
|
10
|
+
UPDATE store_meta SET schema_version = 9 WHERE singleton = 1;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 10: the template packages imported from GitHub (POST /v2/templates/import), as
|
|
2
|
+
-- store/schema.ts keeps them on SQLite (IMPORTED_TEMPLATES). Applied once, after 0009, inside the transaction
|
|
3
|
+
-- migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- imported_templates: one row per package id (github:<owner>/<repo>[/<path>]); files is a JSON object of path to base64,
|
|
6
|
+
-- the package's files as read. The table is made only where it is missing, so a store whose record of this file was lost
|
|
7
|
+
-- applies it again unharmed.
|
|
8
|
+
|
|
9
|
+
CREATE TABLE IF NOT EXISTS imported_templates (
|
|
10
|
+
id TEXT COLLATE "C" PRIMARY KEY,
|
|
11
|
+
source TEXT COLLATE "C" NOT NULL,
|
|
12
|
+
sha TEXT COLLATE "C" NOT NULL,
|
|
13
|
+
publisher TEXT COLLATE "C" NOT NULL,
|
|
14
|
+
files TEXT COLLATE "C" NOT NULL CHECK (files::json IS NOT NULL),
|
|
15
|
+
imported_at BIGINT NOT NULL
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
UPDATE store_meta SET schema_version = 10 WHERE singleton = 1;
|