@parcha/agentrun-serve 0.1.0-beta.37 → 0.1.0-beta.39
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 +700 -0
- package/README.md +441 -177
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +1 -3
- package/dist/agents-store.d.ts +35 -3
- package/dist/agents-store.js +48 -23
- 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/bash-read-only.js +2 -1
- package/dist/browser-cost.js +52 -93
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -400
- package/dist/cap.js +6 -942
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +2 -6
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +25 -0
- package/dist/composio-preset.js +51 -8
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.d.ts +36 -24
- package/dist/computer-calls.js +110 -27
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +12 -2
- package/dist/computer-live.js +21 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +15 -2
- package/dist/computer-setting.js +20 -4
- package/dist/computer-view.d.ts +18 -2
- package/dist/computer-view.js +21 -6
- package/dist/computer-viewer.js +40 -13
- package/dist/computers.d.ts +8 -2
- package/dist/computers.js +18 -8
- package/dist/console/assets/index-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.d.ts +2 -0
- package/dist/console-links.js +6 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/decisions.js +4 -0
- package/dist/email/account.d.ts +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/faux-computers.js +4 -2
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -22
- package/dist/harness-opencode/facts.js +5 -4
- package/dist/harness-opencode/host/policy.d.ts +4 -5
- package/dist/harness-opencode/host/policy.js +14 -33
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.d.ts +0 -2
- package/dist/harness-table.js +8 -7
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/host-tools.d.ts +1 -5
- package/dist/host-tools.js +7 -10
- package/dist/hosted-search.d.ts +3 -3
- package/dist/hosted-search.js +51 -32
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/key-words.d.ts +3 -2
- package/dist/key-words.js +4 -2
- package/dist/learn/check.d.ts +24 -4
- package/dist/learn/check.js +340 -7
- package/dist/learn/commit.d.ts +10 -0
- package/dist/learn/commit.js +18 -4
- package/dist/learn/compile.d.ts +250 -0
- package/dist/learn/compile.js +507 -0
- package/dist/learn/general.d.ts +3 -0
- package/dist/learn/general.js +4 -2
- package/dist/learn/grade.d.ts +5 -1
- package/dist/learn/grade.js +11 -7
- package/dist/learn/notes.d.ts +8 -0
- package/dist/learn/notes.js +18 -0
- package/dist/learn/promote.d.ts +308 -0
- package/dist/learn/promote.js +321 -0
- package/dist/learn/refit.d.ts +48 -0
- package/dist/learn/refit.js +264 -0
- package/dist/learn/reflect.d.ts +5 -25
- package/dist/learn/reflect.js +14 -131
- package/dist/learn/replay-calls.d.ts +63 -0
- package/dist/learn/replay-calls.js +158 -0
- package/dist/learn/skills.d.ts +19 -16
- package/dist/learn/skills.js +157 -53
- package/dist/learn/workflow-nodes.d.ts +15 -0
- package/dist/learn/workflow-nodes.js +44 -0
- package/dist/learned-nodes.d.ts +58 -2
- package/dist/learned-nodes.js +68 -5
- package/dist/learned-workflow.d.ts +58 -32
- package/dist/learned-workflow.js +215 -77
- package/dist/learning-batch.d.ts +2 -2
- package/dist/learning-batch.js +4 -4
- package/dist/learning-cost.d.ts +41 -11
- package/dist/learning-cost.js +31 -13
- package/dist/learning-routes.d.ts +12 -2
- package/dist/learning-routes.js +34 -6
- package/dist/learning-words.d.ts +8 -1
- package/dist/learning-words.js +11 -1
- package/dist/learning.d.ts +26 -1
- package/dist/learning.js +7 -4
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/llm.js +0 -3
- package/dist/local-models.d.ts +33 -2
- package/dist/local-models.js +43 -5
- package/dist/mcp-gateway.d.ts +12 -20
- package/dist/mcp-gateway.js +16 -44
- package/dist/mcp-oauth.d.ts +5 -0
- package/dist/mcp-oauth.js +1 -1
- package/dist/mcp-pin-first.d.ts +37 -0
- package/dist/mcp-pin-first.js +113 -0
- package/dist/mcp-probe.d.ts +8 -9
- package/dist/mcp-probe.js +16 -33
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +102 -26
- package/dist/mcp-servers-store.js +151 -25
- package/dist/mcp-sources.d.ts +39 -0
- package/dist/mcp-sources.js +74 -0
- package/dist/mcp-store.d.ts +11 -0
- package/dist/mcp-store.js +16 -2
- 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 +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +39 -6
- package/dist/model.js +171 -32
- package/dist/monid.d.ts +50 -29
- package/dist/monid.js +234 -143
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +705 -126
- package/dist/paid-calls.d.ts +34 -32
- package/dist/paid-calls.js +52 -104
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +7 -2
- package/dist/port-models.js +5 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +8 -3
- package/dist/propose.js +28 -7
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +17 -2
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/reflect-range.js +2 -1
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/rows.d.ts +5 -3
- package/dist/rows.js +15 -4
- package/dist/run-launch.d.ts +23 -1
- package/dist/run-launch.js +17 -4
- package/dist/run-learning-served.d.ts +84 -0
- package/dist/run-manifest.d.ts +8 -0
- package/dist/run-manifest.js +33 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-secrets.js +2 -3
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +12 -10
- package/dist/run-view.d.ts +59 -41
- package/dist/run-view.js +128 -64
- package/dist/runnable.d.ts +13 -8
- package/dist/runnable.js +77 -60
- package/dist/runner/adapter-loop.d.ts +60 -15
- package/dist/runner/adapter-loop.js +1406 -464
- package/dist/runner/adapter-run-spec.d.ts +45 -14
- package/dist/runner/adapter-run-spec.js +200 -116
- package/dist/runner/adapters/pi.d.ts +40 -7
- package/dist/runner/adapters/pi.js +149 -38
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +150 -66
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +5 -3
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.d.ts +3 -0
- package/dist/runner/conformance/harness.js +149 -5
- package/dist/runner/conformance/subject.d.ts +11 -4
- package/dist/runner/end-of-run.d.ts +8 -5
- package/dist/runner/end-of-run.js +11 -6
- package/dist/runner/feedback-round.d.ts +79 -0
- package/dist/runner/feedback-round.js +127 -0
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +55 -13
- package/dist/runner/journal-kinds.js +19 -0
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +58 -19
- package/dist/runner/learning-end.js +316 -115
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +21 -1
- package/dist/runner/learning-loop.js +24 -6
- package/dist/runner/learning-seed.d.ts +4 -0
- package/dist/runner/learning-seed.js +14 -0
- package/dist/runner/loop-contract.d.ts +19 -3
- package/dist/runner/loop.d.ts +34 -1
- package/dist/runner/loop.js +55 -1
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-claim.d.ts +5 -1
- package/dist/runner/mcp-claim.js +66 -50
- package/dist/runner/mcp-run.d.ts +20 -53
- package/dist/runner/mcp-run.js +22 -88
- package/dist/runner/meta-tools.d.ts +44 -0
- package/dist/runner/meta-tools.js +344 -0
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +128 -42
- package/dist/runner/model-route.d.ts +12 -3
- package/dist/runner/model-route.js +149 -19
- package/dist/runner/monid-run.d.ts +18 -0
- package/dist/runner/monid-run.js +170 -0
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +146 -0
- package/dist/runner/promotion.js +803 -0
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.d.ts +36 -21
- package/dist/runner/reflect-hook.js +147 -49
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +34 -8
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/sessions.d.ts +8 -3
- package/dist/runner/sessions.js +5 -1
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/step-guard.d.ts +62 -0
- package/dist/runner/step-guard.js +93 -0
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/subagent.d.ts +0 -3
- package/dist/runner/subagent.js +7 -12
- package/dist/runner/workflow-first.d.ts +226 -0
- package/dist/runner/workflow-first.js +293 -0
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +32 -19
- package/dist/runner/workflow-spec.d.ts +5 -1
- package/dist/runner/workflow-spec.js +63 -48
- package/dist/runs-over-store.d.ts +41 -4
- package/dist/runs-over-store.js +64 -22
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +108 -20
- package/dist/server.js +874 -157
- package/dist/settings-wake.d.ts +8 -6
- package/dist/settings-wake.js +13 -7
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +22 -7
- package/dist/store/agent-body.js +23 -14
- package/dist/store/command-wake.d.ts +3 -2
- package/dist/store/command-wake.js +4 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/connection.js +3 -1
- 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/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.js +3 -0
- package/dist/store/schema.d.ts +16 -0
- package/dist/store/schema.js +47 -8
- 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 +8 -1
- package/dist/store/sqlite/run-patch.js +33 -10
- package/dist/store/sqlite/store.js +184 -28
- package/dist/store/store.d.ts +98 -21
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +30 -1
- package/dist/store-reads/journal.js +141 -83
- package/dist/store-reads/learning.d.ts +179 -13
- package/dist/store-reads/learning.js +230 -68
- package/dist/store-reads/loop.d.ts +61 -0
- package/dist/store-reads/loop.js +111 -0
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +3 -2
- package/dist/store-view.js +109 -37
- package/dist/template-eval.d.ts +87 -16
- package/dist/template-eval.js +605 -120
- package/dist/template-github-permissions.d.ts +2 -2
- package/dist/template-github-permissions.js +2 -1
- 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 +274 -52
- package/dist/templates.js +670 -201
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/computer.d.ts +48 -0
- package/dist/timeline/computer.js +169 -0
- package/dist/timeline/index.d.ts +7 -5
- package/dist/timeline/index.js +7 -5
- package/dist/timeline/labels.d.ts +11 -4
- package/dist/timeline/labels.js +122 -8
- package/dist/timeline/origin.d.ts +20 -6
- package/dist/timeline/origin.js +13 -6
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +76 -20
- package/dist/timeline/timeline.js +184 -39
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +103 -76
- package/dist/tool-gate.js +200 -127
- package/dist/tool-keys.d.ts +4 -1
- package/dist/tool-keys.js +8 -3
- package/dist/tool-list.d.ts +29 -0
- package/dist/tool-list.js +50 -0
- package/dist/tool-names.d.ts +76 -0
- package/dist/tool-names.js +101 -0
- package/dist/tool-plane.d.ts +34 -28
- package/dist/tool-plane.js +72 -37
- package/dist/tools.d.ts +59 -15
- package/dist/tools.js +46 -42
- package/dist/trigger-adapter.d.ts +85 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +228 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +94 -9
- package/dist/triggers.js +263 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.d.ts +15 -7
- package/dist/validate.js +91 -50
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +6 -8
- package/dist/web-fetch.js +10 -53
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +25 -9
- package/dist/workspace/computer-deps.js +82 -38
- package/dist/workspace/computer-for-claim.d.ts +60 -4
- package/dist/workspace/computer-for-claim.js +203 -45
- package/dist/workspace/computer-hold.js +7 -1
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +31 -11
- package/dist/workspace/kind-skills/phone/SKILL.md +29 -14
- package/dist/workspace/local.js +2 -2
- package/dist/workspace/resolve-computer.d.ts +33 -1
- package/dist/workspace/resolve-computer.js +37 -16
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +40 -23
- package/dist/workspace/run-tools.js +46 -19
- package/dist/wrap-up.d.ts +35 -0
- package/dist/wrap-up.js +48 -0
- package/launcher/agentrun-serve +4 -2
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +220 -60
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +46 -16
- 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 +3 -3
- 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/off-by-one/graders/no-repo-reads.md +2 -1
- 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/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -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 +5 -4
- package/templates/code-review/skills/review/REVIEWER.md +5 -4
- package/templates/code-review/skills/review/SKILL.md +11 -6
- 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 +5 -4
- 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 +5 -4
- 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-Cn6JX1uH.js +0 -563
- package/dist/console/assets/index-DRN62V5v.css +0 -1
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -7
- package/dist/runner/adapters/pi-computer.js +0 -43
- package/dist/tool-blurbs.d.ts +0 -4
- package/dist/tool-blurbs.js +0 -28
- package/dist/tool-budget.d.ts +0 -38
- package/dist/tool-budget.js +0 -62
- package/dist/workspace/computer-script.d.ts +0 -37
- package/dist/workspace/computer-script.js +0 -138
- 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
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
import { existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { DatabaseSync } from "node:sqlite";
|
|
10
|
+
import { backfillNativeCommandOwners, nativeCommandOwner, validConnectorId } from '../native-command-owner.js';
|
|
10
11
|
import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
11
12
|
import { claimFence, storeNow } from "../fence.js";
|
|
12
13
|
import { RunStorage } from "../journal/storage.js";
|
|
13
|
-
import { COMMANDS_ONE_ANSWER, DDL, SCHEMA_VERSION } from "../schema.js";
|
|
14
|
+
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, NATIVE_COMMANDS_INDEX, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, SCHEMA_VERSION } from "../schema.js";
|
|
14
15
|
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, } from "../store.js";
|
|
15
16
|
/** The seq a run-change cursor names (Runs.changedSince): only a cursor this store handed back, a whole number. */
|
|
16
17
|
const seqOf = (cursor) => {
|
|
@@ -20,7 +21,7 @@ const seqOf = (cursor) => {
|
|
|
20
21
|
};
|
|
21
22
|
import { settledBody } from "../dialect.js";
|
|
22
23
|
import { Connection } from "./connection.js";
|
|
23
|
-
import { applyRunPatch, NOT_A_LEARNING_RUN, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
24
|
+
import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
24
25
|
import { readLaunch, writeLaunch } from "./run-launch.js";
|
|
25
26
|
import { canonical } from "../agent-body.js";
|
|
26
27
|
import { aadOf, sealedAt } from "../seal.js";
|
|
@@ -54,7 +55,7 @@ function triggerSet(patch, at) {
|
|
|
54
55
|
return { set: pairs.map(([column]) => `${column} = ?`).join(", "), params: pairs.map(([, value]) => value) };
|
|
55
56
|
}
|
|
56
57
|
const AGENT_COLUMNS = "id, name, description, current_revision, created_at, archived_at, external_ref";
|
|
57
|
-
const REVISION_COLUMNS = "id, agent_id, parent_id, kind, body, skills, note, package, created_at, external_version";
|
|
58
|
+
const REVISION_COLUMNS = "id, agent_id, parent_id, kind, body, skills, note, package, created_at, external_version, mcp_pin, monid_pin";
|
|
58
59
|
const COMMAND_COLUMNS = "id, run_id, kind, body, created_at, taken_at, refused, tries";
|
|
59
60
|
const TRIGGER_COLUMNS = "id, agent_id, name, enabled, source, target, next_at, last_run_id, catchup_window_s, failures_in_a_row, disabled, max_active_runs, created_at, updated_at";
|
|
60
61
|
const FINAL = FINAL_STATES.map((state) => `'${state}'`).join(", ");
|
|
@@ -97,6 +98,7 @@ const agentOf = (r) => ({ id: r.id, name: r.name, description: r.description, cu
|
|
|
97
98
|
const revisionOf = (r) => ({
|
|
98
99
|
id: r.id, agentId: r.agent_id, parent: r.parent_id, kind: r.kind, body: JSON.parse(r.body), skills: r.skills === null ? null : JSON.parse(r.skills),
|
|
99
100
|
note: r.note, package: r.package === null ? null : JSON.parse(r.package), createdAt: r.created_at, externalVersion: r.external_version,
|
|
101
|
+
mcpPin: r.mcp_pin === null ? null : JSON.parse(r.mcp_pin), monidPin: r.monid_pin === null ? null : JSON.parse(r.monid_pin),
|
|
100
102
|
});
|
|
101
103
|
const commandOf = (r) => ({ id: r.id, runId: r.run_id, kind: r.kind, body: JSON.parse(r.body), createdAt: r.created_at, takenAt: r.taken_at, refused: r.refused, tries: r.tries });
|
|
102
104
|
const triggerOf = (r) => ({
|
|
@@ -105,6 +107,8 @@ const triggerOf = (r) => ({
|
|
|
105
107
|
createdAt: r.created_at, updatedAt: r.updated_at,
|
|
106
108
|
});
|
|
107
109
|
const json = (value) => JSON.stringify(value ?? null);
|
|
110
|
+
/** A revision's MCP pin as its column keeps it: JSON, or null for none. */
|
|
111
|
+
const pinText = (pin) => (pin === undefined || pin === null ? null : JSON.stringify(pin));
|
|
108
112
|
const removedOf = (r) => r && { url: r.url, sealed: r.sealed === null ? null : Uint8Array.from(r.sealed) };
|
|
109
113
|
const MCP_SERVER_COLUMNS = "name, url, auth, protocol, tools, prices, server_info, instructions, sealed, refresh_holder, refresh_until, created_at, updated_at, listed_at, credential_changed_at, token_until";
|
|
110
114
|
/** The columns of an MCP server row read at the deadlines' clock `n` (fence.ts storeNow) in the same statement: `read_at`,
|
|
@@ -122,7 +126,7 @@ const mcpServerOf = (r, at = Number(r.read_at)) => ({
|
|
|
122
126
|
tokenUntil: r.token_until === null ? null : Number(r.token_until),
|
|
123
127
|
createdAt: r.created_at, updatedAt: r.updated_at, listedAt: r.listed_at, credentialChangedAt: r.credential_changed_at,
|
|
124
128
|
});
|
|
125
|
-
const mcpPinOf = (r) => ({ runId: r.run_id, body: JSON.parse(r.
|
|
129
|
+
const mcpPinOf = (r) => ({ runId: r.run_id, body: JSON.parse(r.mcp_pin), pinnedAt: Number(r.created_at) });
|
|
126
130
|
const settingOf = (r) => ({ key: r.key, value: JSON.parse(r.value), updatedAt: r.updated_at });
|
|
127
131
|
const sealedKeyOf = (r) => ({ name: r.name, sealed: Uint8Array.from(r.sealed), updatedAt: r.updated_at });
|
|
128
132
|
const ledgerRowOf = (r) => ({ provider: r.provider, sessionId: r.session_id, labels: JSON.parse(r.labels), detail: JSON.parse(r.detail), updatedAt: r.updated_at });
|
|
@@ -243,19 +247,47 @@ export async function openSqliteStore(options) {
|
|
|
243
247
|
}
|
|
244
248
|
if (found !== SCHEMA_VERSION)
|
|
245
249
|
throw new SchemaVersionUnknown(file, found, SCHEMA_VERSION);
|
|
250
|
+
const columns = new Set((await connection.all("SELECT name FROM pragma_table_info('revisions')")).map((column) => column.name));
|
|
251
|
+
if (role === "runner" && (!columns.has("mcp_pin") || !columns.has("monid_pin")))
|
|
252
|
+
throw new Error("Start the AgentRun server to install MCP and Monid revision metadata before opening a runner. The runner does not upgrade this store.");
|
|
253
|
+
const nativeOwners = (await connection.all("PRAGMA table_info(settings)")).some(column => column.name === 'connector_id');
|
|
254
|
+
if (!nativeOwners) {
|
|
255
|
+
if (role === 'runner')
|
|
256
|
+
throw new Error('Native command ownership metadata is not prepared. Start this build’s server before its runners.');
|
|
257
|
+
await connection.write([{ sql: 'ALTER TABLE settings ADD COLUMN connector_id TEXT' }], { full: true });
|
|
258
|
+
}
|
|
259
|
+
// An earlier build of this version kept no bound beside a run's cost (schema.ts RUNS_COST_UPPER_BOUND): the server adds
|
|
260
|
+
// it, every run it ended reading 0, and a runner, which writes it at each end, waits for that server.
|
|
261
|
+
const costBound = (await connection.all("SELECT name FROM pragma_table_info('runs')")).some((column) => column.name === "cost_upper_bound");
|
|
262
|
+
if (!costBound) {
|
|
263
|
+
if (role === "runner")
|
|
264
|
+
throw new Error("Start the AgentRun server to add the bound beside each run's cost before opening a runner. The runner does not upgrade this store.");
|
|
265
|
+
await connection.write([{ sql: RUNS_COST_UPPER_BOUND }], { full: true });
|
|
266
|
+
}
|
|
246
267
|
// The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
|
|
247
268
|
// migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
|
|
248
269
|
// An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
|
|
249
270
|
// counted refused answers: the server rebuilds it, so a second answer to one approval is refused on every store. A
|
|
250
271
|
// store such a build left may hold two unrefused answers to one approval: the earliest stands (the one the runner
|
|
251
272
|
// acted on) and each later one is refused in the same write, before the index, so the store opens. None is deleted.
|
|
273
|
+
// An earlier build of this version pinned each run's MCP tools at its first claim (mcp_pins) and kept no pin on a
|
|
274
|
+
// revision: the server adds revisions.mcp_pin (schema.ts REVISIONS_MCP_PIN) and drops mcp_pins. A revision saved
|
|
275
|
+
// before has no MCP pin until its first managed run here pins it (Agents.pinOnce); no run's pin moves to a revision.
|
|
276
|
+
// Monid pins are also nullable revision metadata; adding the column infers no pin from a historical body.
|
|
252
277
|
if (role === "server") {
|
|
253
278
|
await connection.write([
|
|
279
|
+
...(columns.has("mcp_pin") ? [] : [{ sql: REVISIONS_MCP_PIN }]),
|
|
280
|
+
...(columns.has("monid_pin") ? [] : [{ sql: REVISIONS_MONID_PIN }]),
|
|
281
|
+
{ sql: "DROP TABLE IF EXISTS mcp_pins" },
|
|
254
282
|
{ sql: "DROP TABLE IF EXISTS browser_viewers" },
|
|
255
283
|
{ sql: SECOND_ANSWERS_REFUSED, params: [(options.now ?? Date.now)()] },
|
|
256
284
|
{ sql: "DROP INDEX IF EXISTS commands_one_answer" },
|
|
257
285
|
{ sql: COMMANDS_ONE_ANSWER },
|
|
286
|
+
// An earlier build of this version kept no imported template packages (schema.ts IMPORTED_TEMPLATES).
|
|
287
|
+
{ sql: IMPORTED_TEMPLATES },
|
|
288
|
+
{ sql: NATIVE_COMMANDS_INDEX },
|
|
258
289
|
], { full: true });
|
|
290
|
+
await backfillNativeCommandOwners(connection);
|
|
259
291
|
}
|
|
260
292
|
}
|
|
261
293
|
catch (error) {
|
|
@@ -333,6 +365,7 @@ class SqliteStore {
|
|
|
333
365
|
sealedKeys;
|
|
334
366
|
computerLedger;
|
|
335
367
|
pairedComputers;
|
|
368
|
+
importedTemplates;
|
|
336
369
|
triggerSettings;
|
|
337
370
|
channels;
|
|
338
371
|
mcpOauth;
|
|
@@ -374,7 +407,7 @@ class SqliteStore {
|
|
|
374
407
|
throw new StoreConstraint(`no agent ${agentId}`);
|
|
375
408
|
if (ifCurrent !== undefined && agent.current_revision !== ifCurrent)
|
|
376
409
|
throw new RevisionMoved(agentId, agent.current_revision);
|
|
377
|
-
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", revision.id, agentId, agent.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, revision.package === undefined ? null : json(revision.package), at);
|
|
410
|
+
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, created_at, mcp_pin, monid_pin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revision.id, agentId, agent.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, revision.package === undefined ? null : json(revision.package), at, pinText(revision.mcpPin), pinText(revision.monidPin));
|
|
378
411
|
await tx.run("UPDATE agents SET current_revision = ? WHERE id = ?", revision.id, agentId);
|
|
379
412
|
};
|
|
380
413
|
const writeScopes = async (tx, triggerId, scopes) => {
|
|
@@ -433,6 +466,10 @@ class SqliteStore {
|
|
|
433
466
|
return row && agentOf(row);
|
|
434
467
|
},
|
|
435
468
|
hasExternalVersion: async (agentId, version) => (await db.get("SELECT id FROM revisions WHERE agent_id = ? AND external_version = ?", agentId, version)) !== undefined,
|
|
469
|
+
externalRevision: async (agentId, version) => {
|
|
470
|
+
const row = await db.get(`SELECT ${REVISION_COLUMNS} FROM revisions WHERE agent_id = ? AND external_version = ?`, agentId, version);
|
|
471
|
+
return row && revisionOf(row);
|
|
472
|
+
},
|
|
436
473
|
list: async ({ archived = false } = {}) => (await db.all(`SELECT ${AGENT_COLUMNS} FROM agents WHERE archived_at IS ${archived ? "NOT NULL" : "NULL"} ORDER BY created_at, id`)).map(agentOf),
|
|
437
474
|
archive: async (id, archived, why) => db.transaction(async (tx) => {
|
|
438
475
|
const at = now();
|
|
@@ -458,6 +495,15 @@ class SqliteStore {
|
|
|
458
495
|
return row && revisionOf(row);
|
|
459
496
|
},
|
|
460
497
|
revisions: async (agentId) => (await db.all(`SELECT ${REVISION_COLUMNS} FROM revisions WHERE agent_id = ? ORDER BY created_at, id`, agentId)).map(revisionOf),
|
|
498
|
+
// Written only while the revision has none (the one place a revision changes after its save), then read back in the
|
|
499
|
+
// same transaction: the pin that stood, this one or another first run's.
|
|
500
|
+
pinOnce: async (revisionId, pin) => {
|
|
501
|
+
const row = await db.transaction(async (tx) => {
|
|
502
|
+
await tx.run("UPDATE revisions SET mcp_pin = ? WHERE id = ? AND mcp_pin IS NULL", pinText(pin), revisionId);
|
|
503
|
+
return tx.get("SELECT mcp_pin FROM revisions WHERE id = ?", revisionId);
|
|
504
|
+
});
|
|
505
|
+
return row?.mcp_pin == null ? null : JSON.parse(row.mcp_pin);
|
|
506
|
+
},
|
|
461
507
|
};
|
|
462
508
|
this.templates = {
|
|
463
509
|
apply: async (agent, revision, triggers, idempotencyKey) => db.transaction(async (tx) => {
|
|
@@ -699,7 +745,7 @@ class SqliteStore {
|
|
|
699
745
|
await writeScopes(tx, triggerId, []);
|
|
700
746
|
});
|
|
701
747
|
},
|
|
702
|
-
fire: async (firing, run, { launch } = {}) => db.transaction(async (tx) => {
|
|
748
|
+
fire: async (firing, run, { launch } = {}) => this.#queued(await db.transaction(async (tx) => {
|
|
703
749
|
const at = now();
|
|
704
750
|
await d.lockRow(tx, "triggers", "id", firing.triggerId);
|
|
705
751
|
// Never a run of an archived agent: the archive's commit is read here, in the transaction that would start it.
|
|
@@ -717,7 +763,7 @@ class SqliteStore {
|
|
|
717
763
|
if ((await tx.runCounted("UPDATE triggers SET last_run_id = ?, failures_in_a_row = 0, updated_at = ? WHERE id = ?", run.id, at, firing.triggerId)) === 0)
|
|
718
764
|
throw new StoreConstraint(`no trigger ${firing.triggerId}`);
|
|
719
765
|
return runOf(row);
|
|
720
|
-
}),
|
|
766
|
+
})),
|
|
721
767
|
};
|
|
722
768
|
this.runs = {
|
|
723
769
|
create: async ({ id, agentId, revisionId, origin }, launch) => {
|
|
@@ -726,7 +772,7 @@ class SqliteStore {
|
|
|
726
772
|
if (origin || launch) {
|
|
727
773
|
// The run, its origin and its launch row in one transaction: the key -> run link holds even if the kept response
|
|
728
774
|
// never lands, and a run never exists without the launch it was started with.
|
|
729
|
-
return db.transaction(async (tx) => {
|
|
775
|
+
return this.#queued(await db.transaction(async (tx) => {
|
|
730
776
|
const at = now();
|
|
731
777
|
const row = await tx.get(insert, id, agentId, revisionId, at);
|
|
732
778
|
if (origin)
|
|
@@ -734,14 +780,14 @@ class SqliteStore {
|
|
|
734
780
|
if (launch)
|
|
735
781
|
await writeLaunch(tx, id, launch, at);
|
|
736
782
|
return runOf(row);
|
|
737
|
-
});
|
|
783
|
+
}));
|
|
738
784
|
}
|
|
739
785
|
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, now()] }]);
|
|
740
|
-
return runOf(result.rows[0]);
|
|
786
|
+
return this.#queued(runOf(result.rows[0]));
|
|
741
787
|
},
|
|
742
788
|
createInline: async ({ agent, revision, run, launch }) => {
|
|
743
789
|
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
744
|
-
|
|
790
|
+
const made = await db.transaction(async (tx) => {
|
|
745
791
|
const at = now();
|
|
746
792
|
// Hold the external reference, so two first uses of the same expert serialize (SQLite's one writer already does).
|
|
747
793
|
await d.lockKey(tx, `external:${agent.ref}`);
|
|
@@ -759,7 +805,7 @@ class SqliteStore {
|
|
|
759
805
|
}
|
|
760
806
|
else {
|
|
761
807
|
revisionId = revision.id;
|
|
762
|
-
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, external_version, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revisionId, mapped.id, mapped.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, null, revision.version, at);
|
|
808
|
+
await tx.run("INSERT INTO revisions (id, agent_id, parent_id, kind, body, skills, note, package, external_version, created_at, mcp_pin, monid_pin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", revisionId, mapped.id, mapped.current_revision, revision.kind, json(revision.body), revision.skills === undefined || revision.skills === null ? null : json(revision.skills), revision.note ?? null, null, revision.version, at, pinText(revision.mcpPin), pinText(revision.monidPin));
|
|
763
809
|
await tx.run("UPDATE agents SET current_revision = ?, name = ?, description = ? WHERE id = ?", revisionId, agent.name, agent.description ?? null, mapped.id);
|
|
764
810
|
}
|
|
765
811
|
// The run, its origin and its launch, in the same transaction as the agent and the revision.
|
|
@@ -769,6 +815,7 @@ class SqliteStore {
|
|
|
769
815
|
await writeLaunch(tx, run.id, launch, at);
|
|
770
816
|
return runOf(row);
|
|
771
817
|
});
|
|
818
|
+
return this.#queued(made);
|
|
772
819
|
},
|
|
773
820
|
get: async (id) => {
|
|
774
821
|
const row = await db.get(`SELECT ${RUN_COLUMNS} FROM runs WHERE id = ?`, id);
|
|
@@ -973,16 +1020,11 @@ class SqliteStore {
|
|
|
973
1020
|
const row = await db.get(`SELECT url, auth, credential_changed_at, token_until, ${at.sql} AS read_at FROM mcp_servers WHERE name = ?`, ...at.params, name);
|
|
974
1021
|
return row && { url: row.url, auth: row.auth, credentialChangedAt: row.credential_changed_at === null ? null : Number(row.credential_changed_at), tokenLeftMs: row.token_until === null ? null : Number(row.token_until) - Number(row.read_at), tokenUntil: row.token_until === null ? null : Number(row.token_until) };
|
|
975
1022
|
},
|
|
1023
|
+
// The run's revision's, as its save pinned it: one row read, by the run's revision.
|
|
976
1024
|
pin: async (runId) => {
|
|
977
|
-
const row = await db.get("SELECT run_id,
|
|
1025
|
+
const row = await db.get("SELECT runs.id AS run_id, revisions.mcp_pin, revisions.created_at FROM runs JOIN revisions ON revisions.id = runs.revision_id WHERE runs.id = ? AND revisions.mcp_pin IS NOT NULL", runId);
|
|
978
1026
|
return row && mcpPinOf(row);
|
|
979
1027
|
},
|
|
980
|
-
pinOnce: (claim, body) => db.transaction(async (tx) => {
|
|
981
|
-
// Under the claim's epoch and its lease: a runner paused past its lease pins nothing.
|
|
982
|
-
await underClaim(tx, claim, now);
|
|
983
|
-
await tx.run("INSERT INTO mcp_pins (run_id, body, pinned_at) VALUES (?, ?, ?) ON CONFLICT (run_id) DO NOTHING", claim.runId, json(body), now());
|
|
984
|
-
return mcpPinOf((await tx.get("SELECT run_id, body, pinned_at FROM mcp_pins WHERE run_id = ?", claim.runId)));
|
|
985
|
-
}),
|
|
986
1028
|
// The credential as read is compared by its bytes (`sealed IS ?`, NULL included): updated_at can repeat within a ms.
|
|
987
1029
|
leaseRefresh: async (name, { seen, holder, ms = MCP_REFRESH_LEASE_MS }) => {
|
|
988
1030
|
if (!(Number.isFinite(ms) && ms > MCP_REFRESH_CALL_MS)) {
|
|
@@ -1090,7 +1132,7 @@ class SqliteStore {
|
|
|
1090
1132
|
},
|
|
1091
1133
|
proposals: async (agentId, { limit = 100 } = {}) => (await db.all(`SELECT ${PROPOSAL_COLUMNS} FROM learning_proposals WHERE agent_id = ? ORDER BY created_at DESC, run_id DESC, round DESC LIMIT ?`, agentId, limit)).map(proposalOf),
|
|
1092
1134
|
spend: async ({ from, to }) => {
|
|
1093
|
-
const rows = await db.all(`SELECT lp.agent_id, lp.proposal, lp.created_at, lp.learning_run_id, lr.state AS run_state, lr.ended_at AS run_ended_at, lr
|
|
1135
|
+
const rows = await db.all(`SELECT lp.agent_id, lp.proposal, lp.created_at, lp.learning_run_id, lr.state AS run_state, lr.ended_at AS run_ended_at, ${EXACT_COST_USD("lr")} AS run_cost_usd
|
|
1094
1136
|
FROM learning_proposals lp
|
|
1095
1137
|
JOIN runs src ON src.id = lp.run_id
|
|
1096
1138
|
LEFT JOIN runs lr ON lr.id = lp.learning_run_id
|
|
@@ -1107,7 +1149,7 @@ class SqliteStore {
|
|
|
1107
1149
|
});
|
|
1108
1150
|
},
|
|
1109
1151
|
spentBeside: async (runId, { beforeRound } = {}) => {
|
|
1110
|
-
const rows = await db.all(`SELECT lr.state, lr
|
|
1152
|
+
const rows = await db.all(`SELECT lr.state, ${EXACT_COST_USD("lr")} AS cost_usd, rl.body
|
|
1111
1153
|
FROM learning_proposals lp
|
|
1112
1154
|
LEFT JOIN runs lr ON lr.id = lp.learning_run_id
|
|
1113
1155
|
LEFT JOIN run_launch rl ON rl.run_id = lp.learning_run_id
|
|
@@ -1136,16 +1178,52 @@ class SqliteStore {
|
|
|
1136
1178
|
return row === undefined ? undefined : JSON.parse(row.value);
|
|
1137
1179
|
},
|
|
1138
1180
|
put: async (key, value) => {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1181
|
+
const encoded = json(value);
|
|
1182
|
+
await db.write([{ sql: "INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value, connector_id = excluded.connector_id, updated_at = excluded.updated_at", params: [key, encoded, nativeCommandOwner(key, encoded), now()] }]);
|
|
1183
|
+
},
|
|
1184
|
+
putIfAbsent: async (key, value, capacity) => {
|
|
1185
|
+
const encoded = json(value);
|
|
1186
|
+
if (capacity !== undefined) {
|
|
1187
|
+
if (typeof capacity.prefix !== "string" || !capacity.prefix || capacity.prefix.includes("\0") || !key.startsWith(capacity.prefix) || !Number.isSafeInteger(capacity.limit) || capacity.limit < 1)
|
|
1188
|
+
throw new TypeError("settings capacity requires a matching nonempty prefix and a positive safe integer limit");
|
|
1189
|
+
return db.transaction(async (tx) => {
|
|
1190
|
+
// SQLite holds its writer lock already; Postgres holds this schema's prefix lock until commit. The count
|
|
1191
|
+
// and insertion cannot interleave with another bounded insertion, even through an independent store handle.
|
|
1192
|
+
await d.lockKey(tx, `settings.capacity:${capacity.prefix}`);
|
|
1193
|
+
const existing = await tx.get("SELECT value FROM settings WHERE key = ?", key);
|
|
1194
|
+
if (existing !== undefined)
|
|
1195
|
+
return JSON.parse(existing.value);
|
|
1196
|
+
// Match Settings.all's literal prefix range: use the key index and never parse values or treat _/% as LIKE.
|
|
1197
|
+
const points = Array.from(capacity.prefix);
|
|
1198
|
+
let upper;
|
|
1199
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
1200
|
+
const cp = points[i].codePointAt(0);
|
|
1201
|
+
if (cp < 0x10ffff) {
|
|
1202
|
+
upper = points.slice(0, i).join("") + String.fromCodePoint(cp + 1);
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const count = await tx.get(`SELECT count(*) AS n FROM settings WHERE key >= ?${upper === undefined ? "" : " AND key < ?"} AND substr(key, 1, length(?)) = ?`, capacity.prefix, ...(upper === undefined ? [] : [upper]), capacity.prefix, capacity.prefix);
|
|
1207
|
+
if (Number(count?.n ?? 0) >= capacity.limit)
|
|
1208
|
+
return undefined;
|
|
1209
|
+
await tx.run("INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO NOTHING", key, encoded, nativeCommandOwner(key, encoded), now());
|
|
1210
|
+
const saved = await tx.get("SELECT value FROM settings WHERE key = ?", key);
|
|
1211
|
+
return saved === undefined ? undefined : JSON.parse(saved.value);
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
await db.write([{ sql: "INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO NOTHING", params: [key, encoded, nativeCommandOwner(key, encoded), now()] }]);
|
|
1143
1215
|
const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
|
|
1144
1216
|
return row === undefined ? undefined : JSON.parse(row.value);
|
|
1145
1217
|
},
|
|
1146
1218
|
// `was` is compared as the JSON text put wrote: a row read and parsed gives the same text back, its keys in order.
|
|
1147
|
-
replaceIf: async (key, was, value) => {
|
|
1148
|
-
const
|
|
1219
|
+
replaceIf: async (key, was, value, claim) => {
|
|
1220
|
+
const encoded = json(value);
|
|
1221
|
+
if (claim)
|
|
1222
|
+
return db.transaction(async (tx) => {
|
|
1223
|
+
const at = await underClaim(tx, claim, now);
|
|
1224
|
+
return await tx.runCounted("UPDATE settings SET value = ?, connector_id = ?, updated_at = ? WHERE key = ? AND value = ?", encoded, nativeCommandOwner(key, encoded), at, key, json(was)) === 1;
|
|
1225
|
+
});
|
|
1226
|
+
const [result] = await db.write([{ sql: "UPDATE settings SET value = ?, connector_id = ?, updated_at = ? WHERE key = ? AND value = ?", params: [encoded, nativeCommandOwner(key, encoded), now(), key, json(was)] }]);
|
|
1149
1227
|
return result.changes === 1;
|
|
1150
1228
|
},
|
|
1151
1229
|
removeIf: async (key, was) => {
|
|
@@ -1155,7 +1233,38 @@ class SqliteStore {
|
|
|
1155
1233
|
remove: async (key) => {
|
|
1156
1234
|
await db.write([{ sql: "DELETE FROM settings WHERE key = ?", params: [key] }]);
|
|
1157
1235
|
},
|
|
1158
|
-
all: async () =>
|
|
1236
|
+
all: async (filter) => {
|
|
1237
|
+
const clauses = [], params = [];
|
|
1238
|
+
if (filter?.connectorId !== undefined && !validConnectorId(filter.connectorId))
|
|
1239
|
+
return [];
|
|
1240
|
+
if (filter) {
|
|
1241
|
+
// Both stores order keys by bytes (Postgres settings.key is COLLATE C). This range also enables namespace indexes.
|
|
1242
|
+
const points = Array.from(filter.prefix);
|
|
1243
|
+
let upper;
|
|
1244
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
1245
|
+
const cp = points[i].codePointAt(0);
|
|
1246
|
+
if (cp < 0x10ffff) {
|
|
1247
|
+
upper = points.slice(0, i).join("") + String.fromCodePoint(cp + 1);
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
clauses.push("key >= ?");
|
|
1252
|
+
params.push(filter.prefix);
|
|
1253
|
+
if (upper !== undefined) {
|
|
1254
|
+
clauses.push("key < ?");
|
|
1255
|
+
params.push(upper);
|
|
1256
|
+
}
|
|
1257
|
+
clauses.push("substr(key, 1, length(?)) = ?");
|
|
1258
|
+
params.push(filter.prefix, filter.prefix);
|
|
1259
|
+
}
|
|
1260
|
+
const selection = `SELECT key, value, updated_at FROM settings${clauses.length ? ` WHERE ${clauses.join(" AND ")}` : ""}`;
|
|
1261
|
+
// Disjoint indexed branches: an OR lets SQLite choose a namespace scan over every connector's payload.
|
|
1262
|
+
// Null metadata is a legacy write racing setup; strict JS verification below never widens its owner.
|
|
1263
|
+
const query = filter?.connectorId === undefined ? `${selection} ORDER BY key` : `${selection} AND connector_id = ? UNION ALL ${selection} AND connector_id IS NULL ORDER BY key`;
|
|
1264
|
+
const values = filter?.connectorId === undefined ? params : [...params, filter.connectorId, ...params];
|
|
1265
|
+
const rows = await db.all(query, ...values);
|
|
1266
|
+
return rows.filter(row => filter?.connectorId === undefined || nativeCommandOwner(row.key, row.value) === filter.connectorId).map(settingOf);
|
|
1267
|
+
},
|
|
1159
1268
|
};
|
|
1160
1269
|
this.sealedKeys = {
|
|
1161
1270
|
get: async (name) => {
|
|
@@ -1165,9 +1274,20 @@ class SqliteStore {
|
|
|
1165
1274
|
put: async (name, sealed) => {
|
|
1166
1275
|
await db.write([{ sql: "INSERT INTO sealed_keys (name, sealed, updated_at) VALUES (?, ?, ?) ON CONFLICT (name) DO UPDATE SET sealed = excluded.sealed, updated_at = excluded.updated_at", params: [name, sealed, now()] }]);
|
|
1167
1276
|
},
|
|
1277
|
+
replaceIf: async (name, was, sealed) => {
|
|
1278
|
+
const [result] = await db.write([{ sql: "UPDATE sealed_keys SET sealed = ?, updated_at = ? WHERE name = ? AND sealed = ?", params: [sealed, now(), name, was] }]);
|
|
1279
|
+
return result.changes === 1;
|
|
1280
|
+
},
|
|
1168
1281
|
remove: async (name) => {
|
|
1169
1282
|
await db.write([{ sql: "DELETE FROM sealed_keys WHERE name = ?", params: [name] }]);
|
|
1170
1283
|
},
|
|
1284
|
+
removeIf: async (name, was) => {
|
|
1285
|
+
const [result] = await db.write([{ sql: "DELETE FROM sealed_keys WHERE name = ? AND sealed = ?", params: [name, was] }]);
|
|
1286
|
+
return result.changes === 1;
|
|
1287
|
+
},
|
|
1288
|
+
// The deadlines' clock (fence.ts storeNow): read from the database where the dialect names its clock (Postgres),
|
|
1289
|
+
// else the store's own.
|
|
1290
|
+
clock: async () => (d.nowSql ? Number((await db.get(`SELECT ${d.nowSql} AS now`)).now) : now()),
|
|
1171
1291
|
all: async () => (await db.all("SELECT name, sealed, updated_at FROM sealed_keys ORDER BY name")).map(sealedKeyOf),
|
|
1172
1292
|
};
|
|
1173
1293
|
this.computerLedger = {
|
|
@@ -1229,6 +1349,21 @@ class SqliteStore {
|
|
|
1229
1349
|
return (result?.changes ?? 0) === 1;
|
|
1230
1350
|
},
|
|
1231
1351
|
};
|
|
1352
|
+
this.importedTemplates = {
|
|
1353
|
+
list: async () => (await db.all("SELECT id, source, sha, publisher, files, imported_at FROM imported_templates ORDER BY id")).map((row) => ({
|
|
1354
|
+
id: row.id, source: row.source, sha: row.sha, publisher: row.publisher, files: JSON.parse(row.files), importedAt: row.imported_at,
|
|
1355
|
+
})),
|
|
1356
|
+
put: async ({ id, source, sha, publisher, files }) => {
|
|
1357
|
+
await db.write([{
|
|
1358
|
+
sql: "INSERT INTO imported_templates (id, source, sha, publisher, files, imported_at) VALUES (?, ?, ?, ?, ?, ?) ON CONFLICT (id) DO UPDATE SET source = excluded.source, sha = excluded.sha, publisher = excluded.publisher, files = excluded.files, imported_at = excluded.imported_at",
|
|
1359
|
+
params: [id, source, sha, publisher, JSON.stringify(files), now()],
|
|
1360
|
+
}]);
|
|
1361
|
+
},
|
|
1362
|
+
remove: async (id) => {
|
|
1363
|
+
const [result] = await db.write([{ sql: "DELETE FROM imported_templates WHERE id = ?", params: [id] }]);
|
|
1364
|
+
return (result?.changes ?? 0) === 1;
|
|
1365
|
+
},
|
|
1366
|
+
};
|
|
1232
1367
|
this.triggerSettings = {
|
|
1233
1368
|
get: async (adapter) => (await db.all("SELECT adapter, scope, field, sealed, updated_at FROM trigger_settings WHERE adapter = ? ORDER BY scope, field", adapter)).map(triggerSettingOf),
|
|
1234
1369
|
put: async ({ adapter, scope, field, sealed }) => {
|
|
@@ -1584,6 +1719,11 @@ class SqliteStore {
|
|
|
1584
1719
|
watchCommands(listener) {
|
|
1585
1720
|
return watchCommandsAt(this.where, listener);
|
|
1586
1721
|
}
|
|
1722
|
+
/** `run`, just committed queued: this process's runners are told it is claimable now (watchCommands' "queued"). */
|
|
1723
|
+
#queued(run) {
|
|
1724
|
+
wakeCommands(this.where, { runId: run.id, what: "queued" });
|
|
1725
|
+
return run;
|
|
1726
|
+
}
|
|
1587
1727
|
async answerOf(runId, commandId) {
|
|
1588
1728
|
// Read and cleared in one transaction, so two readers never both get it. A refused row never holds one.
|
|
1589
1729
|
const text = await this.#db.transaction(async (tx) => {
|
|
@@ -1619,6 +1759,22 @@ class SqliteStore {
|
|
|
1619
1759
|
const at = this.#now();
|
|
1620
1760
|
const state = run.state ?? "ended";
|
|
1621
1761
|
return this.#db.transaction(async (tx) => {
|
|
1762
|
+
for (const guard of [...(run.settingsGuards ?? [])].sort((a, b) => a.key.localeCompare(b.key))) {
|
|
1763
|
+
// A no-op update takes the row's write lock on both SQLite and Postgres until the import commits. A source
|
|
1764
|
+
// revoke/disconnect either commits first and refuses this write, or waits for this already-started import.
|
|
1765
|
+
const setting = await tx.get("UPDATE settings SET value = value WHERE key = ? RETURNING value", guard.key);
|
|
1766
|
+
const value = setting === undefined ? undefined : JSON.parse(setting.value);
|
|
1767
|
+
if (!value || Object.entries(guard.fields).some(([field, expected]) => JSON.stringify(value[field]) !== JSON.stringify(expected))) {
|
|
1768
|
+
throw new StoreConstraint("The source import grant changed before the history write committed.");
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
if (run.requireActiveAgent) {
|
|
1772
|
+
// Archive updates this same row. It either commits first and refuses this import, or waits for this
|
|
1773
|
+
// already-admitted history transaction; a read outside the transaction cannot establish that order.
|
|
1774
|
+
const agent = await tx.get("UPDATE agents SET archived_at = archived_at WHERE id = ? AND archived_at IS NULL RETURNING id", run.agentId);
|
|
1775
|
+
if (!agent)
|
|
1776
|
+
throw new StoreConstraint("The agent was archived before the history write committed.");
|
|
1777
|
+
}
|
|
1622
1778
|
// The ended run row, its launch row and its transcript's journal, all in this one transaction (the server's own
|
|
1623
1779
|
// writer): a crash between them leaves nothing. The run is created at epoch 0 with no runner, and the journal's fence
|
|
1624
1780
|
// passes for that one row, by the rowid its insert returned (the claim fence's inserted-here form).
|