@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.60
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 +402 -1
- package/README.md +516 -190
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/api-only.d.ts +2 -2
- package/dist/api-only.js +3 -3
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +7 -0
- package/dist/chatgpt-plan.js +35 -11
- package/dist/claude-login-token.d.ts +20 -11
- package/dist/claude-login-token.js +175 -107
- package/dist/claude-login.d.ts +124 -33
- package/dist/claude-login.js +562 -85
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-QnwGVBeU.js +166 -0
- package/dist/console/assets/index-DZi-muIj.js +629 -0
- package/dist/console/assets/share-pz61zIn9.js +6 -0
- package/dist/console/assets/styles-CcceGcu2.js +291 -0
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +10 -8
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +21 -6
- package/dist/harness.js +6 -2
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +20 -8
- package/dist/import.js +448 -187
- package/dist/key-refusal.d.ts +14 -2
- package/dist/key-refusal.js +97 -33
- package/dist/learn/audit.d.ts +28 -27
- package/dist/learn/audit.js +87 -62
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +9 -6
- package/dist/learn/compile.js +51 -28
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +119 -102
- package/dist/learn/promote.js +119 -262
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +22 -2
- package/dist/mcp-gateway.js +85 -11
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +290 -79
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +58 -34
- package/dist/place-offers.js +96 -54
- package/dist/place.d.ts +41 -20
- package/dist/place.js +97 -47
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +42 -9
- package/dist/redact/match.js +356 -54
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-launch.js +16 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +8 -5
- package/dist/runnable.js +26 -9
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +73 -46
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +10 -9
- package/dist/runner/audit.js +64 -67
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +87 -58
- package/dist/runner/compare-end.d.ts +2 -3
- package/dist/runner/compare-end.js +30 -11
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.js +3 -4
- package/dist/runner/held.d.ts +5 -12
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +8 -2
- package/dist/runner/journal-kinds.js +23 -5
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +23 -7
- package/dist/runner/learning-end.d.ts +14 -24
- package/dist/runner/learning-end.js +52 -94
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +13 -12
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/mcp-run.d.ts +4 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +12 -11
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +39 -36
- package/dist/runner/promotion.js +168 -112
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +21 -14
- package/dist/runner/run-child-host.js +187 -141
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +3 -4
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +10 -12
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +26 -7
- package/dist/sdk/runs.js +194 -78
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +55 -9
- package/dist/secrets.js +345 -21
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +10 -3
- package/dist/server-keys.js +16 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +30 -18
- package/dist/server.js +520 -238
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +60 -11
- package/dist/store/schema.js +147 -17
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +9 -0
- package/dist/store/sqlite/store.js +194 -46
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +286 -38
- package/dist/store/store.js +27 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +50 -45
- package/dist/store-reads/learning.js +153 -116
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +49 -17
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +54 -13
- package/dist/tool-plane.js +103 -32
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +34 -0
- package/dist/web-holds.js +89 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +76 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +38 -18
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +19 -4
- package/dist/workspace/computer-providers.js +40 -6
- package/dist/workspace/index.d.ts +2 -3
- package/dist/workspace/index.js +2 -3
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +7 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -14
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
|
@@ -12,8 +12,8 @@ import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
|
12
12
|
import { claimFence, storeNow } from "../fence.js";
|
|
13
13
|
import { JOURNAL_FIRST_ID, RunStorage } from "../journal/storage.js";
|
|
14
14
|
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
15
|
-
import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_AGENT, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS,
|
|
16
|
-
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
|
|
15
|
+
import { COMMANDS_ONE_ANSWER, COMPUTER_INTERVALS, COMPUTER_INTERVALS_ADDED, COMPUTER_INTERVALS_RUN, DDL, diskUpgrade, HAND_BACKS, HAND_BACKS_AT, HAND_BACKS_KEPT_MS, HAND_BACKS_RUN, IMPORTED_TEMPLATES, LEARNING_LEDGER, LEARNING_LEDGER_ADDED, LEARNING_LEDGER_AGENT, LEARNING_LEDGER_BY_HAND, LEARNING_ROWS, LEARNING_SPEND, LEARNING_SPEND_AGENT, LEARNING_SPEND_OF_RUN, ledgerUpgrade, learningRowsUpgrade, listingUpgrade, MINTED_TOKENS, purgeUpgrade, relayUpgrade, NATIVE_COMMANDS_INDEX, PI_TABLE, PI_TABLES, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUN_ATTEMPTS, RUNNERS, RUNNERS_ADDED, RUN_LAUNCH_CENSUS, RUN_LAUNCH_CENSUS_ERASED, RUN_LAUNCH_CENSUS_ERASED_MADE, RUN_LAUNCH_CENSUS_SETTLE, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION, SETTLED_LIST_STATUS, STORE_META_LEDGER_BACKFILLED, TRIGGERS_TEMPLATE_ID } from "../schema.js";
|
|
16
|
+
import { ActiveRuns, AgentArchived, AgentDeleting, AgentPurged, CommandTaken, ExternalBodyConflict, Fenced, FiringMoved, RunFinal, RunPurged, RunnerBelowFloor, RunsMadeFromLeft, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreAwaitsServer, StoreBusy, StoreConstraint, StoreFromEarlierVersion, TriggerFull, TriggersLeft, UPLOAD_PREFIX, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, KEPT_PREFIX, RUNNER_ROWS_KEPT_MS, RUNNER_STALE_MS, tombstoneMetrics, } from "../store.js";
|
|
17
17
|
/** The run a launch body is made from (Runs.madeFrom): the run whose input it replays (`replay.of`) or audits (`audit.of`). */
|
|
18
18
|
const madeOf = (body) => {
|
|
19
19
|
for (const link of ["replay", "audit"]) {
|
|
@@ -31,10 +31,13 @@ const seqOf = (cursor) => {
|
|
|
31
31
|
};
|
|
32
32
|
import { cleanText, settledBody } from "../dialect.js";
|
|
33
33
|
import { inMemory } from "./memory.js";
|
|
34
|
+
import { dropAgentLearning, dropRunLearning, learningRows } from "./learning-rows.js";
|
|
34
35
|
import { Connection, DEFAULT_BUSY_TIMEOUT_MS } from "./connection.js";
|
|
35
|
-
import { applyRunPatch, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
36
|
+
import { applyRunPatch, backfillLedger, BY_HAND_BEFORE, EXACT_COST_USD, NOT_A_LEARNING_RUN, recordLedger, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
36
37
|
import { launchDiskOf, readableJson, readLaunch, readLearningStarts, readSeededBefore, readUsageMetadata, writeLaunch, writeLaunchSealed } from "./run-launch.js";
|
|
37
38
|
import { canonical } from "../agent-body.js";
|
|
39
|
+
import { mcpRecordKeys } from "../mcp-record-keys.js";
|
|
40
|
+
import { workflowCallsIn } from "../../learning-cost.js";
|
|
38
41
|
import { readProjectCheckpoints } from "./project-checkpoints.js";
|
|
39
42
|
import { aadOf, sealedAt } from "../seal.js";
|
|
40
43
|
/** Registry writers UPDATE/DELETE this same row, so a prepared cutover and a credential/catalog edit serialize. */
|
|
@@ -69,9 +72,18 @@ async function checkSettingsGuards(tx, guards = [], message = "The source grant
|
|
|
69
72
|
export const DEFAULT_LEASE_MS = 30_000;
|
|
70
73
|
/** The store's file in its data directory: only the store names it. */
|
|
71
74
|
export const STORE_FILE = "store.sqlite";
|
|
75
|
+
/** The oldest schema version this release brings up to SCHEMA_VERSION in place at its server's open (version 11,
|
|
76
|
+
* 0.1.0-beta.44 and before): every version from it to the one before SCHEMA_VERSION is upgraded, each step by the
|
|
77
|
+
* version it starts from; an older one is refused (SchemaVersionUnknown). The window follows SCHEMA_VERSION, so a new
|
|
78
|
+
* version never drops the one before it. */
|
|
79
|
+
export const OLDEST_UPGRADED = 11;
|
|
72
80
|
/** No audit's shadow run (learn/audit.ts SHADOW_PREFIX "audit."): the prefix compared as it is, which LIKE does not on
|
|
73
81
|
* SQLite (it folds case). */
|
|
74
82
|
const NOT_A_SHADOW_RUN = "substr(runs.id, 1, 6) <> 'audit.'";
|
|
83
|
+
/** A runs list's `model` (ListedFilter.model, `provider/model`) as SQL taking the model as its one `?`: the runs that sent at
|
|
84
|
+
* least one request to it, a key of the requests their metrics count per model (metrics.models), exactly (no prefix, no case
|
|
85
|
+
* folding). A run with no metrics yet sent none. */
|
|
86
|
+
const runUsedModel = (d) => d.jsonObjectHasKey("runs.metrics", ["models"]);
|
|
75
87
|
/** A runner holds the run's claim at `now` (SQL), and the run is not over. */
|
|
76
88
|
const heldAt = (now) => `(runs.runner IS NOT NULL AND runs.claimed_until >= ${now} AND runs.state NOT IN ('ended', 'stopped', 'failed'))`;
|
|
77
89
|
/** The run's listing is behind at `now` (SQL; its parameters twice, `params`): built before the latest write that moved
|
|
@@ -154,8 +166,9 @@ const claimableIn = (d, n, claimer) => {
|
|
|
154
166
|
};
|
|
155
167
|
};
|
|
156
168
|
/** The run's computer is kept at its park (its KEPT_PREFIX row) pinned to a runner other than `claimer` that is still
|
|
157
|
-
* there
|
|
158
|
-
* claiming (refused NULL); the keep neither ending nor ended, and its `until`
|
|
169
|
+
* there (KEPT_PREFIX says what that means: its runners row seen within RUNNER_STALE_MS at the deadlines' clock `n`,
|
|
170
|
+
* under the incarnation the row names) and claiming (refused NULL); the keep neither ending nor ended, and its `until`
|
|
171
|
+
* ahead, on the same clock it was stamped on. That runner's Docker engine or
|
|
159
172
|
* attach hub holds the machine, so only it can take it back (workspace/computer-kept.ts pinnedOf); once any of these
|
|
160
173
|
* stops holding, any runner claims the run. Read in the claim's own statement, so no check-then-act gap. A row with no
|
|
161
174
|
* runner (a computer any runner reaches: an exec vendor's, a phone; or one an earlier build kept) pins nothing. */
|
|
@@ -267,6 +280,10 @@ async function versionOf(db) {
|
|
|
267
280
|
* (webhook.json, webhook-outbox.json) do not refuse the directory either: nothing reads them, and the webhook, now in
|
|
268
281
|
* the store, is set again. */
|
|
269
282
|
const EARLIER_ROOT_FILES = ["mcp-servers.json", "triggers.json", "tool-keys.json", "trigger-secrets.json", ".door-token"];
|
|
283
|
+
/** The store's earlier versions the server upgrades in place at its open (openSqliteStore), which a runner waits for
|
|
284
|
+
* (StoreAwaitsServer); store-schema reports from the same set. Every version from OLDEST_UPGRADED to the one before
|
|
285
|
+
* SCHEMA_VERSION, so a new version never drops the one before it. */
|
|
286
|
+
export const SQLITE_UPGRADES = new Set(Array.from({ length: SCHEMA_VERSION - OLDEST_UPGRADED }, (_, i) => OLDEST_UPGRADED + i));
|
|
270
287
|
/** The columns a runner of this build needs that an earlier build of this same version may not have: the server adds each
|
|
271
288
|
* at its start (openSqliteStore), and a runner on a file without one waits for that server (StoreAwaitsServer, in `why`'s
|
|
272
289
|
* words; exit 3). store-schema reads the same list, so its report says "waits" where the runner would. */
|
|
@@ -282,8 +299,9 @@ export const SQLITE_RUNNER_NEEDS = [
|
|
|
282
299
|
{ table: "hand_backs", columns: ["run_id"], why: "keep each runner's version and slots, and each hand-back (runners.version, runners.slots, hand_backs)" },
|
|
283
300
|
{ table: "run_attempts", columns: ["run_id"], why: "keep each claim's turn and attempt (run_attempts)" },
|
|
284
301
|
// A run's end writes its ledger row and spend rows (run-patch.ts applyRunPatch) in its own transaction.
|
|
285
|
-
{ table: "learning_ledger", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
|
|
302
|
+
{ table: "learning_ledger", columns: ["run_id", ...Object.keys(LEARNING_LEDGER_ADDED)], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
|
|
286
303
|
{ table: "learning_spend", columns: ["run_id"], why: "write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)" },
|
|
304
|
+
{ table: "learning_saves", columns: ["merge_key"], why: "keep each agent's learning as rows (learning_saves, learning_items, learning_records)" },
|
|
287
305
|
];
|
|
288
306
|
/** What a runner of this build waits for on a file of this version (SQLITE_RUNNER_NEEDS' first missing column's `why`),
|
|
289
307
|
* or undefined when it opens; `columnsOf` reads a table's columns. */
|
|
@@ -420,10 +438,17 @@ export async function openSqliteStore(options) {
|
|
|
420
438
|
// it. Version 12 names no minting runner on a machine's token and keeps no runner's relay: the server adds them
|
|
421
439
|
// (schema.ts relayUpgrade). Version 13 keeps no purge time on a run or an agent: the server adds them (schema.ts
|
|
422
440
|
// purgeUpgrade). Version 14 keeps no disk on a run: the server adds it and writes each run's from its launch (schema.ts
|
|
423
|
-
// diskUpgrade).
|
|
424
|
-
|
|
441
|
+
// diskUpgrade). Version 15 keeps each ledger row's epoch: the server repairs the rows that release could leave wrong
|
|
442
|
+
// and drops it (the ledger's step below, then ledgerUpgrade). Version 16 keeps no learning as rows: the server adds
|
|
443
|
+
// them (schema.ts learningRowsUpgrade), last. A runner refuses each version of SQLITE_UPGRADES until that server has,
|
|
444
|
+
// and a runner of 15, whose end writes the epoch, refuses 16 and later (SchemaVersionUnknown), or stops at its next
|
|
445
|
+
// floor read. A later version is refused too, a runner in words that name its floor (a SQLite runner opens only its
|
|
446
|
+
// own version, so the floor is the version): RunnerBelowFloor.
|
|
447
|
+
const upgrading = found !== null && SQLITE_UPGRADES.has(found);
|
|
425
448
|
if (upgrading && role === "runner")
|
|
426
449
|
throw new StoreAwaitsServer(`bring this store from version ${found} to ${SCHEMA_VERSION}`);
|
|
450
|
+
if (role === "runner" && found !== null && found > SCHEMA_VERSION)
|
|
451
|
+
throw new RunnerBelowFloor(file, found, SCHEMA_VERSION, found);
|
|
427
452
|
if (found !== SCHEMA_VERSION && !upgrading)
|
|
428
453
|
throw new SchemaVersionUnknown(file, found, SCHEMA_VERSION);
|
|
429
454
|
const columns = new Set((await connection.all("SELECT name FROM pragma_table_info('revisions')")).map((column) => column.name));
|
|
@@ -458,12 +483,20 @@ export async function openSqliteStore(options) {
|
|
|
458
483
|
await connection.write([{ sql: RUNS_LABELS }], { full: true });
|
|
459
484
|
}
|
|
460
485
|
// An earlier build of this version kept no census on a run's launch (schema.ts RUN_LAUNCH_CENSUS): the server adds the
|
|
461
|
-
// column, nullable
|
|
462
|
-
//
|
|
486
|
+
// column, nullable: every run ended before reads as never handed a secret, and a launch that holds one now as not yet
|
|
487
|
+
// counted (its end counts it). A runner writes it at each end, so it waits for that server.
|
|
463
488
|
if (!(await connection.all("SELECT name FROM pragma_table_info('run_launch')")).some((column) => column.name === "census")) {
|
|
464
489
|
if (role === "runner")
|
|
465
490
|
throw new StoreAwaitsServer("add each run's census");
|
|
466
|
-
await connection.write([{ sql: RUN_LAUNCH_CENSUS }
|
|
491
|
+
await connection.write([{ sql: RUN_LAUNCH_CENSUS }], { full: true });
|
|
492
|
+
}
|
|
493
|
+
// A store no server of this build opened yet holds no RUN_LAUNCH_CENSUS_ERASED (an end that erases sealed bytes with
|
|
494
|
+
// no census, as an earlier runner's does, writes "unscanned"). The server makes it, and in the same write settles each
|
|
495
|
+
// "pending" 0.1.0-beta.57 left (RUN_LAUNCH_CENSUS_SETTLE), so a run live at the upgrade is counted at its end. Every
|
|
496
|
+
// later open reads only that the trigger is there. A runner leaves both: an end over a "pending" writes the marker,
|
|
497
|
+
// and its files are withheld, never read uncut.
|
|
498
|
+
if (role === "server" && (await connection.all(RUN_LAUNCH_CENSUS_ERASED_MADE)).length === 0) {
|
|
499
|
+
await connection.write([{ sql: RUN_LAUNCH_CENSUS_SETTLE }, { sql: RUN_LAUNCH_CENSUS_ERASED }], { full: true });
|
|
467
500
|
}
|
|
468
501
|
// An earlier build of this version kept no package mark on a trigger (schema.ts TRIGGERS_TEMPLATE_ID): the server adds
|
|
469
502
|
// the column, nullable, every trigger made before reading as no package's. A runner reads each trigger through it, so
|
|
@@ -491,10 +524,19 @@ export async function openSqliteStore(options) {
|
|
|
491
524
|
throw new StoreAwaitsServer("keep each claim's turn and attempt (run_attempts)");
|
|
492
525
|
}
|
|
493
526
|
// A run's end writes its ledger row and spend rows (schema.ts LEARNING_LEDGER, LEARNING_SPEND) in its own transaction:
|
|
494
|
-
// a runner waits for the server that adds the tables (STORE_DDL at its start).
|
|
495
|
-
|
|
527
|
+
// a runner waits for the server that adds the tables (STORE_DDL at its start) and their columns (LEARNING_LEDGER_ADDED).
|
|
528
|
+
// The `epoch` version 15 kept on the ledger, which this build's end does not write, is the version's: a runner
|
|
529
|
+
// refuses 15 above.
|
|
530
|
+
const metaColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('store_meta')")).map((column) => column.name));
|
|
531
|
+
const ledgerColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('learning_ledger')")).map((column) => column.name));
|
|
532
|
+
if (role === "runner" && ((await connection.all("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name IN ('learning_ledger', 'learning_spend')")).length < 2 || Object.keys(LEARNING_LEDGER_ADDED).some((column) => !ledgerColumns.has(column)))) {
|
|
496
533
|
throw new StoreAwaitsServer("write each run's learning ledger row and spend at its end (learning_ledger, learning_spend)");
|
|
497
534
|
}
|
|
535
|
+
// A run's merge and purge write the agent's learning rows (schema.ts LEARNING_ROWS) in their own transactions: a runner
|
|
536
|
+
// waits for the server that adds the tables.
|
|
537
|
+
if (role === "runner" && (await connection.all("SELECT name FROM pragma_table_info('learning_saves')")).length === 0) {
|
|
538
|
+
throw new StoreAwaitsServer("keep each agent's learning as rows (learning_saves, learning_items, learning_records)");
|
|
539
|
+
}
|
|
498
540
|
// The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
|
|
499
541
|
// migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
|
|
500
542
|
// An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
|
|
@@ -531,13 +573,18 @@ export async function openSqliteStore(options) {
|
|
|
531
573
|
{ sql: COMPUTER_INTERVALS_RUN },
|
|
532
574
|
// Nor any claim's turn and attempt (schema.ts RUN_ATTEMPTS): a claim made before it has no row.
|
|
533
575
|
{ sql: RUN_ATTEMPTS },
|
|
534
|
-
// Nor any learning ledger (schema.ts LEARNING_LEDGER, LEARNING_SPEND
|
|
535
|
-
// its
|
|
576
|
+
// Nor any learning ledger (schema.ts LEARNING_LEDGER, LEARNING_SPEND; version 15's, with each row's `epoch`, is
|
|
577
|
+
// repaired and its epoch dropped by ledgerUpgrade below). Nor the mark that every ended run has its row
|
|
578
|
+
// (STORE_META_LEDGER_BACKFILLED), nor the by-hand index (LEARNING_LEDGER_BY_HAND).
|
|
579
|
+
...(metaColumns.has("ledger_backfilled") ? [] : [{ sql: STORE_META_LEDGER_BACKFILLED }]),
|
|
536
580
|
{ sql: LEARNING_LEDGER },
|
|
537
581
|
{ sql: LEARNING_LEDGER_AGENT },
|
|
582
|
+
{ sql: LEARNING_LEDGER_BY_HAND },
|
|
538
583
|
{ sql: LEARNING_SPEND },
|
|
539
584
|
{ sql: LEARNING_SPEND_AGENT },
|
|
540
585
|
{ sql: LEARNING_SPEND_OF_RUN },
|
|
586
|
+
// Nor any agent's learning as rows (schema.ts LEARNING_ROWS): learning kept before it is not read.
|
|
587
|
+
...LEARNING_ROWS.map((sql) => ({ sql })),
|
|
541
588
|
{ sql: NATIVE_COMMANDS_INDEX },
|
|
542
589
|
], { full: true });
|
|
543
590
|
// A computer_intervals an earlier build of this version made has no disk or booked time (schema.ts
|
|
@@ -552,21 +599,37 @@ export async function openSqliteStore(options) {
|
|
|
552
599
|
const runnersMissing = Object.entries(RUNNERS_ADDED).filter(([column]) => !runnersNow.has(column)).map(([, sql]) => ({ sql }));
|
|
553
600
|
if (runnersMissing.length > 0)
|
|
554
601
|
await connection.write(runnersMissing, { full: true });
|
|
602
|
+
// A learning_ledger an earlier build of this version made keeps no calls (schema.ts LEARNING_LEDGER_ADDED): added
|
|
603
|
+
// where missing, its rows' calls none until their run's next end. Before the open's backfill (backfillLedger below),
|
|
604
|
+
// whose rows recordLedger writes with their calls.
|
|
605
|
+
const ledgerNow = new Set((await connection.all("SELECT name FROM pragma_table_info('learning_ledger')")).map((column) => column.name));
|
|
606
|
+
const ledgerMissing = Object.entries(LEARNING_LEDGER_ADDED).filter(([column]) => !ledgerNow.has(column)).map(([, sql]) => ({ sql }));
|
|
607
|
+
if (ledgerMissing.length > 0)
|
|
608
|
+
await connection.write(ledgerMissing, { full: true });
|
|
555
609
|
await backfillNativeCommandOwners(connection);
|
|
556
|
-
|
|
610
|
+
// Here `found` is SCHEMA_VERSION or a version in the window (any other was refused above): each step runs for the
|
|
611
|
+
// versions before the one that first kept what it adds.
|
|
612
|
+
if (found <= 11) {
|
|
557
613
|
const present = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
|
|
558
614
|
await connection.write(listingUpgrade(present).map((sql) => ({ sql })), { full: true });
|
|
559
615
|
}
|
|
560
|
-
if (found
|
|
616
|
+
if (found <= 12) {
|
|
561
617
|
const minted = new Set((await connection.all("SELECT name FROM pragma_table_info('minted_tokens')")).map((column) => column.name));
|
|
562
618
|
await connection.write(relayUpgrade(minted).map((sql) => ({ sql })), { full: true });
|
|
563
619
|
}
|
|
564
|
-
if (upgrading) {
|
|
620
|
+
if (upgrading && found !== null) {
|
|
565
621
|
const named = async (table) => new Set((await connection.all(`SELECT name FROM pragma_table_info('${table}')`)).map((column) => column.name));
|
|
566
|
-
if (found
|
|
622
|
+
if (found <= 13)
|
|
567
623
|
await connection.write(purgeUpgrade(await named("runs"), await named("agents")).map((sql) => ({ sql })), { full: true });
|
|
568
|
-
|
|
624
|
+
if (found <= 14)
|
|
625
|
+
await connection.write(diskUpgrade(await named("runs")).map((sql) => ({ sql })), { full: true });
|
|
626
|
+
if (found <= 15)
|
|
627
|
+
await connection.write(ledgerUpgrade(await named("learning_ledger")).map((sql) => ({ sql })), { full: true });
|
|
628
|
+
// Last: ledgerUpgrade writes 16, and the rows step writes 17 after it.
|
|
629
|
+
await connection.write(learningRowsUpgrade().map((sql) => ({ sql })), { full: true });
|
|
569
630
|
}
|
|
631
|
+
// Every run an earlier build ended gets its ledger row once, here, on the schema this build reads.
|
|
632
|
+
await backfillLedger(connection, options.now ?? Date.now);
|
|
570
633
|
}
|
|
571
634
|
}
|
|
572
635
|
catch (error) {
|
|
@@ -656,7 +719,7 @@ async function dropLedger(tx, runId) {
|
|
|
656
719
|
}
|
|
657
720
|
/** A run's content in every table that keeps it by the run's id, gone: what a run's purge (Runs.purge) and its delete
|
|
658
721
|
* (Runs.remove) both drop. A table added for a run's content goes here, so neither path leaves it behind. */
|
|
659
|
-
async function dropRunContent(tx, runId) {
|
|
722
|
+
async function dropRunContent(tx, runId, at) {
|
|
660
723
|
for (const table of PI_TABLES)
|
|
661
724
|
await tx.run(`DELETE FROM ${table} WHERE run_id = ?`, runId);
|
|
662
725
|
await tx.run("DELETE FROM commands WHERE run_id = ?", runId);
|
|
@@ -672,11 +735,19 @@ async function dropRunContent(tx, runId) {
|
|
|
672
735
|
await tx.run("DELETE FROM hand_backs WHERE run_id = ?", runId);
|
|
673
736
|
// Its claims' attempts: what each cost is in its tombstone's money, and no read of a purged run splits it.
|
|
674
737
|
await tx.run("DELETE FROM run_attempts WHERE run_id = ?", runId);
|
|
738
|
+
// What it learned and what its agent's learning kept of it (learning-rows.ts dropRunLearning), its agent's alone,
|
|
739
|
+
// under the lock a save of that agent's learning takes: the purge is a save of its own at `at`.
|
|
740
|
+
const agentId = (await tx.get("SELECT agent_id FROM runs WHERE id = ?", runId))?.agent_id;
|
|
741
|
+
if (agentId !== undefined) {
|
|
742
|
+
await tx.dialect.lockKey(tx, `learning:${agentId}`);
|
|
743
|
+
await dropRunLearning(tx, agentId, runId, at);
|
|
744
|
+
}
|
|
675
745
|
}
|
|
676
|
-
/** An agent's own rows no tombstone keeps (its learning, its saved sign-ins
|
|
677
|
-
* purge (Agents.purge) and its delete (Agents.remove) both drop. */
|
|
746
|
+
/** An agent's own rows no tombstone keeps (its learning, under its learning locks: dropAgentLearning; its saved sign-ins
|
|
747
|
+
* and their tombstones), gone: what an agent's purge (Agents.purge) and its delete (Agents.remove) both drop. */
|
|
678
748
|
async function dropAgentPrivate(tx, agentId) {
|
|
679
749
|
await tx.run("DELETE FROM learning WHERE agent_id = ?", agentId);
|
|
750
|
+
await dropAgentLearning(tx, agentId);
|
|
680
751
|
await tx.run("DELETE FROM sign_ins WHERE agent_id = ?", agentId);
|
|
681
752
|
await tx.run("DELETE FROM sign_in_tombstones WHERE agent_id = ?", agentId);
|
|
682
753
|
}
|
|
@@ -1378,10 +1449,12 @@ class SqliteStore {
|
|
|
1378
1449
|
projectCheckpoints: (filter) => readProjectCheckpoints(db, filter),
|
|
1379
1450
|
learningStarts: (agentId) => readLearningStarts(db, agentId, NOT_A_LEARNING_RUN),
|
|
1380
1451
|
seededBefore: (agentId, at) => readSeededBefore(db, agentId, at),
|
|
1381
|
-
list: async ({ agentId, revisionId, state, archived, labels, disk, limit, purged = false }) => {
|
|
1452
|
+
list: async ({ agentId, revisionId, state, archived, labels, disk, limit, purged = false, scope, before }) => {
|
|
1382
1453
|
// A built-in learning run (a run's grade and merge, queued with its kept learning) is no run of a person's: no list,
|
|
1383
1454
|
// count, stat or notice names it. A purged run is a tombstone: only the readers that sum or count ask for it.
|
|
1384
|
-
|
|
1455
|
+
// The Agent Factory's active scope alone lists a learning run: there it is an execution like any other. Its review
|
|
1456
|
+
// scope keeps the runs list's boundary (listed, below): no learning run and no audit's shadow run.
|
|
1457
|
+
const where = [...(scope === "active" ? [] : [NOT_A_LEARNING_RUN]), ...(scope === "review" ? [NOT_A_SHADOW_RUN] : []), ...(purged ? [] : ["purged_at IS NULL"])];
|
|
1385
1458
|
const params = [];
|
|
1386
1459
|
if (agentId !== undefined)
|
|
1387
1460
|
(where.push("agent_id = ?"), params.push(agentId));
|
|
@@ -1398,6 +1471,18 @@ class SqliteStore {
|
|
|
1398
1471
|
where.push("disk IS NULL");
|
|
1399
1472
|
else if (disk !== undefined)
|
|
1400
1473
|
(where.push("disk = ?"), params.push(disk));
|
|
1474
|
+
// Factory visibility is selected before the page limit: an old parked run must not disappear behind newer
|
|
1475
|
+
// history. A person's stopped agentic turn remains continuable; an imported session never executes here.
|
|
1476
|
+
if (scope !== undefined) {
|
|
1477
|
+
where.push("imported_from IS NULL");
|
|
1478
|
+
where.push(scope === "active"
|
|
1479
|
+
? `(state IN ('queued', 'running', 'parked') OR (state = 'stopped' AND outcome = 'stopped' AND ${NOT_A_LEARNING_RUN} AND ${NOT_A_SHADOW_RUN} AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')))`
|
|
1480
|
+
: "((state = 'ended' AND outcome = 'escalated') OR state = 'failed') AND archived_at IS NULL AND NOT EXISTS (SELECT 1 FROM agents WHERE agents.id = runs.agent_id AND agents.archived_at IS NOT NULL)");
|
|
1481
|
+
}
|
|
1482
|
+
if (before !== undefined) {
|
|
1483
|
+
where.push("(started_at < ? OR (started_at = ? AND id < ?))");
|
|
1484
|
+
params.push(before.startedAt, before.startedAt, before.id);
|
|
1485
|
+
}
|
|
1401
1486
|
const bounded = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0;
|
|
1402
1487
|
if (bounded)
|
|
1403
1488
|
params.push(limit);
|
|
@@ -1406,7 +1491,7 @@ class SqliteStore {
|
|
|
1406
1491
|
},
|
|
1407
1492
|
// A list's page from the rows alone: filtered, ordered and cut to the page in the query, one read whatever the number
|
|
1408
1493
|
// of runs, each row with its listing (schema.ts RUN_LISTING_COLUMNS) and its agent's archive time.
|
|
1409
|
-
listed: async ({ agentId, revisionId, labels, source, archived, status, going, after, limit, offset = 0 }) => {
|
|
1494
|
+
listed: async ({ agentId, revisionId, labels, source, startedFrom, startedBefore, model, archived, status, going, after, limit, offset = 0 }) => {
|
|
1410
1495
|
const n = clock();
|
|
1411
1496
|
const behind = listingBehind(n.sql);
|
|
1412
1497
|
// Neither a built-in learning run nor an audit's shadow run (learn/audit.ts SHADOW_PREFIX, matched as it is, case and all).
|
|
@@ -1422,6 +1507,13 @@ class SqliteStore {
|
|
|
1422
1507
|
where.push("runs.imported_from IS NULL");
|
|
1423
1508
|
else if (source !== undefined)
|
|
1424
1509
|
(where.push(`${d.jsonText("runs.imported_from", ["source"])} = ?`), params.push(source));
|
|
1510
|
+
// The window [startedFrom, startedBefore): a run started at its start is in it, one started at its end is not.
|
|
1511
|
+
if (startedFrom !== undefined)
|
|
1512
|
+
(where.push("runs.started_at >= ?"), params.push(startedFrom));
|
|
1513
|
+
if (startedBefore !== undefined)
|
|
1514
|
+
(where.push("runs.started_at < ?"), params.push(startedBefore));
|
|
1515
|
+
if (model !== undefined)
|
|
1516
|
+
(where.push(runUsedModel(d)), params.push(model));
|
|
1425
1517
|
where.push(`COALESCE(runs.archived_at, agents.archived_at) IS ${archived ? "NOT NULL" : "NULL"}`, "runs.purged_at IS NULL");
|
|
1426
1518
|
if (status !== undefined)
|
|
1427
1519
|
(where.push("runs.list_status = ?"), params.push(status));
|
|
@@ -1441,6 +1533,20 @@ class SqliteStore {
|
|
|
1441
1533
|
more: rows.length > limit,
|
|
1442
1534
|
};
|
|
1443
1535
|
},
|
|
1536
|
+
// The same columns `listed` reads beside a row, for the runs named: one read, whatever their journals. A purged run
|
|
1537
|
+
// is a tombstone, as it is to `listed`: it keeps no listing, and none is built for it.
|
|
1538
|
+
listings: async (runIds) => {
|
|
1539
|
+
if (runIds.length === 0)
|
|
1540
|
+
return [];
|
|
1541
|
+
const n = clock();
|
|
1542
|
+
const behind = listingBehind(n.sql);
|
|
1543
|
+
const rows = await db.all(`SELECT runs.id, agents.archived_at AS agent_archived_at, runs.listing, runs.list_mark, ${behind.sql} AS behind
|
|
1544
|
+
FROM runs JOIN agents ON agents.id = runs.agent_id WHERE runs.purged_at IS NULL AND runs.id IN (${runIds.map(() => "?").join(", ")})`, ...behind.params(n.params), ...runIds);
|
|
1545
|
+
return rows.map((row) => ({
|
|
1546
|
+
id: row.id, agentArchivedAt: row.agent_archived_at, listMark: Number(row.list_mark), behind: Boolean(Number(row.behind)),
|
|
1547
|
+
listing: row.listing === null ? null : JSON.parse(row.listing),
|
|
1548
|
+
}));
|
|
1549
|
+
},
|
|
1444
1550
|
counts: async (agentId) => {
|
|
1445
1551
|
const [row] = await db.all(`SELECT COUNT(*) AS count, SUM(CASE WHEN runs.state IN ('queued', 'running', 'parked')
|
|
1446
1552
|
OR (runs.state = 'stopped' AND runs.outcome = 'stopped' AND runs.imported_from IS NULL AND revisions.kind = 'agentic') THEN 1 ELSE 0 END) AS live
|
|
@@ -1459,10 +1565,10 @@ class SqliteStore {
|
|
|
1459
1565
|
) AS behind ORDER BY held, started_at DESC, id DESC LIMIT ? OFFSET ?`, ...n.params, ...n.params, ...n.params, ...n.params, ...n.params, limit, offset);
|
|
1460
1566
|
return rows.map((row) => ({ id: row.id, mark: Number(row.mark), held: Boolean(Number(row.held)) }));
|
|
1461
1567
|
},
|
|
1462
|
-
putListing: async (runId, mark, { item, cut, status, live, until, flags }) => {
|
|
1568
|
+
putListing: async (runId, mark, { item, cut, status, live, until, flags, factory }) => {
|
|
1463
1569
|
const [result] = await db.write([{
|
|
1464
1570
|
sql: "UPDATE runs SET listing = ?, list_status = ?, listing_mark = ?, listing_live = ?, listing_until = ?, listing_flags = ? WHERE id = ? AND list_mark = ? RETURNING id",
|
|
1465
|
-
params: [json({ item, cut }), status, mark, live ? 1 : 0, until, flags, runId, mark],
|
|
1571
|
+
params: [json({ item, cut, ...(factory !== undefined ? { factory } : {}) }), status, mark, live ? 1 : 0, until, flags, runId, mark],
|
|
1466
1572
|
}]);
|
|
1467
1573
|
return (result?.rows.length ?? 0) > 0;
|
|
1468
1574
|
},
|
|
@@ -1553,7 +1659,7 @@ class SqliteStore {
|
|
|
1553
1659
|
}
|
|
1554
1660
|
if (left.length)
|
|
1555
1661
|
throw new RunsMadeFromLeft(runId, left);
|
|
1556
|
-
await dropRunContent(tx, runId);
|
|
1662
|
+
await dropRunContent(tx, runId, now());
|
|
1557
1663
|
// What names it, let go: a trigger's last run, the firing that started it (its key and status kept, so it never
|
|
1558
1664
|
// fires again; the event it was given, its payload and attributes, gone), a firing's wait behind it (the
|
|
1559
1665
|
// trigger's room is read again, as for a run that ended), the run a machine's token was minted for.
|
|
@@ -1587,7 +1693,7 @@ class SqliteStore {
|
|
|
1587
1693
|
return;
|
|
1588
1694
|
if (!FINAL_STATES.includes(run.state))
|
|
1589
1695
|
throw new StoreConstraint(`run ${runId} is ${run.state}: only a final run is removed`);
|
|
1590
|
-
await dropRunContent(tx, runId);
|
|
1696
|
+
await dropRunContent(tx, runId, now());
|
|
1591
1697
|
await tx.run("DELETE FROM learning_proposals WHERE run_id = ?", runId);
|
|
1592
1698
|
// Its ledger row and every spend row it booked or that audits it, as a purge takes them.
|
|
1593
1699
|
await dropLedger(tx, runId);
|
|
@@ -1711,6 +1817,10 @@ class SqliteStore {
|
|
|
1711
1817
|
* writes or removes the row, so an owner's save, which drops the mark in the transaction that writes its row
|
|
1712
1818
|
* (dropTokensMark), never lands in between. */
|
|
1713
1819
|
const recordJson = readableJson(d, "settings.value");
|
|
1820
|
+
/** A new row's created_at, its two `?` now and three the name's record keys (mcpRecordKeys) then now again: now, or past
|
|
1821
|
+
* every `of` the name's records still hold, even within its millisecond or on a clock stepped back. created_at is the
|
|
1822
|
+
* row's identity (the `of` its records name): a record about an earlier row of the name is never a later row's. */
|
|
1823
|
+
const madeAfterRecords = `${d.greatest}(${d.bigintParam}, COALESCE((SELECT MAX(${d.jsonNumber(recordJson, ["of"])}) FROM settings WHERE settings.key IN (?, ?, ?)), ${d.bigintParam} - 1) + 1)`;
|
|
1714
1824
|
const tokensMarked = `EXISTS (SELECT 1 FROM settings WHERE settings.key = ? AND ${d.jsonText(recordJson, ["by"])} = 'token' AND ${d.jsonValue(recordJson, ["of"])} = CAST(mcp_servers.created_at AS TEXT))`;
|
|
1715
1825
|
/** A write of the saved server `name` that the token's mark decides (McpTokensMark, McpOwnersMark): one transaction that
|
|
1716
1826
|
* first holds the server's lock. SQLite's one writer holds it already; on Postgres it makes the token's statement wait
|
|
@@ -1745,7 +1855,8 @@ class SqliteStore {
|
|
|
1745
1855
|
const left = sealed !== null && typeof tokenLeftMs === "number" && Number.isFinite(tokenLeftMs) ? tokenLeftMs : null;
|
|
1746
1856
|
const stamp = clock();
|
|
1747
1857
|
// updated_at defaults to now (a save or a sign-in); a refresh passes the kept one so it is not read as an edit.
|
|
1748
|
-
// listed_at is the tools' listing time, now unless given.
|
|
1858
|
+
// listed_at is the tools' listing time, now unless given. A save's moves past the row's own, in the statement that
|
|
1859
|
+
// writes it (lastEdit), even within its millisecond: a refresh that read the row compares it, and must see the save.
|
|
1749
1860
|
const updated = updatedAt ?? at;
|
|
1750
1861
|
const listed = listedAt ?? at;
|
|
1751
1862
|
// The credential's own time: now for a put that writes one, unless the caller says it kept the sealed one (its
|
|
@@ -1757,25 +1868,29 @@ class SqliteStore {
|
|
|
1757
1868
|
const statement = expected !== undefined && expected !== null
|
|
1758
1869
|
? {
|
|
1759
1870
|
sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, sealed = ?, refresh_holder = NULL, refresh_until = NULL,
|
|
1760
|
-
updated_at =
|
|
1871
|
+
updated_at = ${lastEdit(updatedAt, "?")}, listed_at = ?, credential_changed_at = ?, token_until = ${stamp.sql} + ${d.bigintParam}
|
|
1761
1872
|
WHERE name = ? AND auth = ? AND sealed IS ${expected.sealed ? "NOT NULL" : "NULL"} AND ${expected.changedAt === null ? "credential_changed_at IS NULL" : "credential_changed_at = ?"}${tokens ? ` AND ${tokensMarked}` : ""}
|
|
1762
1873
|
RETURNING ${mcpServerColumnsAt(stamp)}`,
|
|
1763
1874
|
params: [...values, updated, listed, credentialAt, ...stamp.params, left, name, expected.auth, ...(expected.changedAt === null ? [] : [expected.changedAt]), ...(tokens ? [tokens.record] : []), ...stamp.params],
|
|
1764
1875
|
}
|
|
1765
1876
|
: {
|
|
1766
|
-
sql: `INSERT INTO mcp_servers (name, url, auth, protocol, tools, prices, server_info, instructions, sealed, created_at, updated_at, listed_at, credential_changed_at, token_until) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
1877
|
+
sql: `INSERT INTO mcp_servers (name, url, auth, protocol, tools, prices, server_info, instructions, sealed, created_at, updated_at, listed_at, credential_changed_at, token_until) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ${madeAfterRecords}, ?, ?, ?, ${stamp.sql} + ${d.bigintParam})
|
|
1767
1878
|
ON CONFLICT (name) DO UPDATE SET url = excluded.url, auth = excluded.auth, protocol = excluded.protocol, tools = excluded.tools,
|
|
1768
|
-
prices = excluded.prices, server_info = excluded.server_info, instructions = excluded.instructions, sealed = excluded.sealed, refresh_holder = NULL, refresh_until = NULL, updated_at = excluded.updated_at, listed_at = excluded.listed_at, credential_changed_at = excluded.credential_changed_at, token_until = excluded.token_until
|
|
1879
|
+
prices = excluded.prices, server_info = excluded.server_info, instructions = excluded.instructions, sealed = excluded.sealed, refresh_holder = NULL, refresh_until = NULL, updated_at = ${lastEdit(updatedAt, "excluded.updated_at")}, listed_at = excluded.listed_at, credential_changed_at = excluded.credential_changed_at, token_until = excluded.token_until
|
|
1769
1880
|
${expected === null ? "WHERE 1 = 0" : ""}
|
|
1770
1881
|
RETURNING ${mcpServerColumnsAt(stamp)}`,
|
|
1771
|
-
params: [name, ...values, at, updated, listed, credentialAt, ...stamp.params, left, ...stamp.params],
|
|
1882
|
+
params: [name, ...values, at, ...mcpRecordKeys(name), at, updated, listed, credentialAt, ...stamp.params, left, ...stamp.params],
|
|
1772
1883
|
};
|
|
1773
1884
|
const written = await writeMcpRow(name, statement, tokens, owns);
|
|
1774
1885
|
return written && mcpServerOf(written);
|
|
1775
1886
|
};
|
|
1887
|
+
/** A server row's updated_at as a write sets it to `value` (SQL): kept as given when the caller passes the one it read
|
|
1888
|
+
* (`given`, a refresh: not an edit), else past the row's own (mcp_servers.updated_at, the row before the write) by at
|
|
1889
|
+
* least 1 ms, so two saves in one millisecond are still two edits a compare-and-set tells apart. */
|
|
1890
|
+
const lastEdit = (given, value) => (given === undefined ? `${d.greatest}(${value}, mcp_servers.updated_at + 1)` : value);
|
|
1776
1891
|
/** `statement`, the write of server `name`'s row, answering the row it wrote (RETURNING): alone, or, when the token's mark
|
|
1777
1892
|
* decides it (`tokens`, `owns`), in one transaction under the server's lock (underMcpLock), the owner's dropping the
|
|
1778
|
-
* mark once its row is written and only then. */
|
|
1893
|
+
* mark once its row is written and only then, the token's first save writing its record (`tokens.made`) there too. */
|
|
1779
1894
|
const writeMcpRow = async (name, statement, tokens, owns) => {
|
|
1780
1895
|
if (!tokens && !owns)
|
|
1781
1896
|
return (await db.write([statement]))[0].rows[0];
|
|
@@ -1783,6 +1898,10 @@ class SqliteStore {
|
|
|
1783
1898
|
const row = (await tx.step(statement)).rows[0];
|
|
1784
1899
|
if (row && owns)
|
|
1785
1900
|
await dropTokensMark(tx, owns, mcpServerOf(row).createdAt);
|
|
1901
|
+
if (row && tokens?.made) {
|
|
1902
|
+
const encoded = json(tokens.made(mcpServerOf(row)));
|
|
1903
|
+
await tx.run("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", tokens.record, encoded, nativeCommandOwner(tokens.record, encoded), now());
|
|
1904
|
+
}
|
|
1786
1905
|
return row;
|
|
1787
1906
|
});
|
|
1788
1907
|
};
|
|
@@ -1794,16 +1913,19 @@ class SqliteStore {
|
|
|
1794
1913
|
this.mcp = {
|
|
1795
1914
|
put: async (row) => (await putServer(row, undefined)),
|
|
1796
1915
|
putIfCredential: (row, expected, tokens, owns) => putServer(row, expected, tokens, owns),
|
|
1797
|
-
// One statement compares the
|
|
1798
|
-
// in a gap and is then written over
|
|
1916
|
+
// One statement compares the row as read (its credential, address, auth type and last edit) and writes, as
|
|
1917
|
+
// keepRefreshed: no read between, so a refresh's keep never lands in a gap and is then written over, and a save with no
|
|
1918
|
+
// credential (the sealed column the same after it), whether it moved the row or only repriced it, is never written
|
|
1919
|
+
// back over: every save moves updated_at, past the row's own even within its millisecond (lastEdit). The credential's
|
|
1920
|
+
// columns and the refresh lease are not in its SET.
|
|
1799
1921
|
rewrite: async ({ name, url, auth, protocol = null, tools, prices = null, serverInfo = null, instructions = null, listedAt, updatedAt }, seen, owns) => {
|
|
1800
1922
|
const at = now();
|
|
1801
1923
|
const stamp = clock();
|
|
1802
1924
|
const row = await writeMcpRow(name, {
|
|
1803
|
-
sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, updated_at =
|
|
1804
|
-
WHERE name = ? AND ${d.nullSafeEquals("sealed")}
|
|
1925
|
+
sql: `UPDATE mcp_servers SET url = ?, auth = ?, protocol = ?, tools = ?, prices = ?, server_info = ?, instructions = ?, updated_at = ${lastEdit(updatedAt, "?")}, listed_at = ?
|
|
1926
|
+
WHERE name = ? AND ${d.nullSafeEquals("sealed")} AND url = ? AND auth = ? AND updated_at = ?
|
|
1805
1927
|
RETURNING ${mcpServerColumnsAt(stamp)}`,
|
|
1806
|
-
params: [url, auth, protocol, json(tools), json(prices), serverInfo === null ? null : json(serverInfo), instructions, updatedAt ?? at, listedAt ?? at, name, seen, ...stamp.params],
|
|
1928
|
+
params: [url, auth, protocol, json(tools), json(prices), serverInfo === null ? null : json(serverInfo), instructions, updatedAt ?? at, listedAt ?? at, name, seen.sealed, seen.url, seen.auth, seen.updatedAt, ...stamp.params],
|
|
1807
1929
|
}, undefined, owns);
|
|
1808
1930
|
return row && mcpServerOf(row);
|
|
1809
1931
|
},
|
|
@@ -1935,6 +2057,7 @@ class SqliteStore {
|
|
|
1935
2057
|
// A purged run's kept learning is its state alone (Runs.purge), for the learning meter: no reader of learning reads it.
|
|
1936
2058
|
const NOT_PURGED = "NOT EXISTS (SELECT 1 FROM runs WHERE runs.id = learning_proposals.run_id AND runs.purged_at IS NOT NULL)";
|
|
1937
2059
|
this.learning = {
|
|
2060
|
+
...learningRows(db, now),
|
|
1938
2061
|
// A round asked for, else the run's newest.
|
|
1939
2062
|
proposal: async (runId, round) => {
|
|
1940
2063
|
const row = round === undefined
|
|
@@ -1972,15 +2095,17 @@ class SqliteStore {
|
|
|
1972
2095
|
const rowsOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND run_id IN (${list})`, params: [...runIds] };
|
|
1973
2096
|
const spendOf = runIds === undefined ? { sql: "", params: [] } : { sql: ` AND (run_id IN (${list}) OR of_run IN (${list}))`, params: [...runIds, ...runIds] };
|
|
1974
2097
|
const text = "CAST(NULL AS TEXT)", whole = "CAST(NULL AS BIGINT)", usd = "CAST(NULL AS DOUBLE PRECISION)";
|
|
1975
|
-
const parts = await db.all(`SELECT 'row' AS part, run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost,
|
|
2098
|
+
const parts = await db.all(`SELECT 'row' AS part, run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost, workflow_calls, ${text} AS kind, ${whole} AS round, ${text} AS of_run, ${usd} AS usd
|
|
1976
2099
|
FROM learning_ledger WHERE agent_id = ?${rowsOf.sql}
|
|
1977
2100
|
UNION ALL
|
|
1978
|
-
SELECT 'spend' AS part, run_id, agent_id, ${whole}, ${text}, workflow, digest, ${text}, ${usd}, ${usd}, ${text}, ${
|
|
2101
|
+
SELECT 'spend' AS part, run_id, agent_id, ${whole}, ${text}, workflow, digest, ${text}, ${usd}, ${usd}, ${text}, ${text}, kind, round, of_run, usd
|
|
1979
2102
|
FROM learning_spend WHERE agent_id = ?${spendOf.sql}`, agentId, ...rowsOf.params, agentId, ...spendOf.params);
|
|
1980
2103
|
const usdOf = (value) => (value === null ? null : Number(value));
|
|
1981
2104
|
const rows = parts.filter((one) => one.part === "row").map((row) => ({
|
|
1982
2105
|
runId: row.run_id, agentId: row.agent_id, startedAt: Number(row.started_at), path: row.path, workflow: row.workflow, digest: row.digest,
|
|
1983
|
-
notServed: row.not_served, jobUsd: usdOf(row.job_usd), lookBackUsd: usdOf(row.look_back_usd), cost: row.cost,
|
|
2106
|
+
notServed: row.not_served, jobUsd: usdOf(row.job_usd), lookBackUsd: usdOf(row.look_back_usd), cost: row.cost,
|
|
2107
|
+
// Its calls as its end wrote them (record), each checked again as read.
|
|
2108
|
+
workflowCalls: workflowCallsIn({ workflow_calls: JSON.parse(row.workflow_calls ?? "[]") }),
|
|
1984
2109
|
}));
|
|
1985
2110
|
const spend = parts.filter((one) => one.part === "spend").map((row) => ({
|
|
1986
2111
|
runId: row.run_id, round: Number(row.round), agentId: row.agent_id, kind: row.kind, ofRun: row.of_run, workflow: row.workflow, digest: row.digest, usd: usdOf(row.usd),
|
|
@@ -1991,6 +2116,10 @@ class SqliteStore {
|
|
|
1991
2116
|
spend: spend.sort((a, b) => byText(a.runId, b.runId) || byText(a.kind, b.kind) || a.round - b.round),
|
|
1992
2117
|
};
|
|
1993
2118
|
},
|
|
2119
|
+
byHandBefore: async (agentId, before, limit) => {
|
|
2120
|
+
const rows = await db.all(BY_HAND_BEFORE, agentId, before.startedAt, before.id, limit);
|
|
2121
|
+
return rows.map((row) => ({ id: row.run_id, startedAt: Number(row.started_at), jobUsd: Number(row.job_usd) }));
|
|
2122
|
+
},
|
|
1994
2123
|
};
|
|
1995
2124
|
this.settings = {
|
|
1996
2125
|
get: async (key) => {
|
|
@@ -2001,7 +2130,7 @@ class SqliteStore {
|
|
|
2001
2130
|
const encoded = json(value);
|
|
2002
2131
|
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()] }]);
|
|
2003
2132
|
},
|
|
2004
|
-
putIfAbsent: async (key, value, capacity) => {
|
|
2133
|
+
putIfAbsent: async (key, value, capacity, claim) => {
|
|
2005
2134
|
const encoded = json(value);
|
|
2006
2135
|
if (capacity !== undefined) {
|
|
2007
2136
|
if (typeof capacity.prefix !== "string" || !capacity.prefix || capacity.prefix.includes("\0") || !key.startsWith(capacity.prefix) || !Number.isSafeInteger(capacity.limit) || capacity.limit < 1)
|
|
@@ -2010,6 +2139,9 @@ class SqliteStore {
|
|
|
2010
2139
|
// SQLite holds its writer lock already; Postgres holds this schema's prefix lock until commit. The count
|
|
2011
2140
|
// and insertion cannot interleave with another bounded insertion, even through an independent store handle.
|
|
2012
2141
|
await d.lockKey(tx, `settings.capacity:${capacity.prefix}`);
|
|
2142
|
+
// Settings precede the run's claim lock, as in replaceIf.
|
|
2143
|
+
if (claim)
|
|
2144
|
+
await underClaim(tx, claim, now);
|
|
2013
2145
|
const existing = await tx.get("SELECT value FROM settings WHERE key = ?", key);
|
|
2014
2146
|
if (existing !== undefined)
|
|
2015
2147
|
return JSON.parse(existing.value);
|
|
@@ -2031,6 +2163,14 @@ class SqliteStore {
|
|
|
2031
2163
|
return saved === undefined ? undefined : JSON.parse(saved.value);
|
|
2032
2164
|
});
|
|
2033
2165
|
}
|
|
2166
|
+
// Under a claim: the claim's fence and the insert in one transaction, so a claim that lost the run writes nothing.
|
|
2167
|
+
if (claim)
|
|
2168
|
+
return db.transaction(async (tx) => {
|
|
2169
|
+
const at = await underClaim(tx, claim, now);
|
|
2170
|
+
await tx.run("INSERT INTO settings (key, value, connector_id, updated_at) VALUES (?, ?, ?, ?) ON CONFLICT (key) DO NOTHING", key, encoded, nativeCommandOwner(key, encoded), at);
|
|
2171
|
+
const saved = await tx.get("SELECT value FROM settings WHERE key = ?", key);
|
|
2172
|
+
return saved === undefined ? undefined : JSON.parse(saved.value);
|
|
2173
|
+
});
|
|
2034
2174
|
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()] }]);
|
|
2035
2175
|
const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
|
|
2036
2176
|
return row === undefined ? undefined : JSON.parse(row.value);
|
|
@@ -2098,6 +2238,10 @@ class SqliteStore {
|
|
|
2098
2238
|
put: async (name, sealed) => {
|
|
2099
2239
|
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()] }]);
|
|
2100
2240
|
},
|
|
2241
|
+
putIfAbsent: async (name, sealed) => {
|
|
2242
|
+
const [result] = await db.write([{ sql: "INSERT INTO sealed_keys (name, sealed, updated_at) VALUES (?, ?, ?) ON CONFLICT (name) DO NOTHING", params: [name, sealed, now()] }]);
|
|
2243
|
+
return result.changes === 1;
|
|
2244
|
+
},
|
|
2101
2245
|
replaceIf: async (name, was, sealed) => {
|
|
2102
2246
|
const [result] = await db.write([{ sql: "UPDATE sealed_keys SET sealed = ?, updated_at = ? WHERE name = ? AND sealed = ?", params: [sealed, now(), name, was] }]);
|
|
2103
2247
|
return result.changes === 1;
|
|
@@ -2860,7 +3004,11 @@ class SqliteStore {
|
|
|
2860
3004
|
VALUES (?, ?, ?, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING ${this.#db.dialect.insertedRow} AS inserted_rowid, ${RUN_COLUMNS}`, run.id, run.agentId, run.revisionId, state, run.costUsd ?? null, run.metrics === undefined || run.metrics === null ? null : json(run.metrics), run.summary ?? null, run.outcome ?? null, JSON.stringify(run.importedFrom), launchDiskOf(run.launch), run.startedAt, run.endedAt ?? at);
|
|
2861
3005
|
await writeLaunch(tx, run.id, run.launch, at);
|
|
2862
3006
|
await new RunStorage(this.#db, { runId: run.id, epoch: 0 }, this.#now).applyIn(tx, run.transcript, row.inserted_rowid ?? "this-transaction");
|
|
2863
|
-
|
|
3007
|
+
// Its ledger row, as an end writes one (applyRunPatch), in this same commit.
|
|
3008
|
+
const imported = runOf(row);
|
|
3009
|
+
if (FINAL_STATES.includes(imported.state))
|
|
3010
|
+
await recordLedger(tx, imported, at);
|
|
3011
|
+
return imported;
|
|
2864
3012
|
});
|
|
2865
3013
|
}
|
|
2866
3014
|
async take(claim, commandId, outcome = "taken", reason) {
|
|
@@ -21,9 +21,7 @@ import { migrationsIn, runnerFloorOf, runnerOn } from "./postgres/migrate.js";
|
|
|
21
21
|
import { STORE_CONNECT_TIMEOUT_MS } from "./postgres/connection.js";
|
|
22
22
|
import { storePlace, storeTarget } from "./open.js";
|
|
23
23
|
import { SCHEMA_VERSION } from "./schema.js";
|
|
24
|
-
import { earlierVersionIn, runnerWaitsFor, STORE_FILE } from "./sqlite/store.js";
|
|
25
|
-
/** The SQLite store's versions the server upgrades in place (sqlite/store.ts openSqliteStore). */
|
|
26
|
-
const SQLITE_UPGRADES = new Set([11, 12, 13, 14]);
|
|
24
|
+
import { earlierVersionIn, runnerWaitsFor, SQLITE_UPGRADES, STORE_FILE } from "./sqlite/store.js";
|
|
27
25
|
/** What a build that knows `build` does with a store at `state`, on `kind`. `earlier`: the data directory holds an earlier
|
|
28
26
|
* version's files (SQLite only), which this build's server refuses to start beside (StoreFromEarlierVersion). `awaits`:
|
|
29
27
|
* on SQLite at this build's version, a column this build's runner needs that the file lacks (SQLITE_RUNNER_NEEDS), which
|
|
@@ -34,7 +32,8 @@ export function storeSchemaReport(target, state, build, earlier = false, awaits
|
|
|
34
32
|
? "refuses"
|
|
35
33
|
: version === null ? "sets up" : version === build ? "opens" : version > build ? "refuses" : target.kind === "postgres" || SQLITE_UPGRADES.has(version) ? "migrates" : "refuses";
|
|
36
34
|
// A SQLite runner opens only its own version: its floor is the version (sqlite/store.ts schemaState).
|
|
37
|
-
// On SQLite a runner waits only for a version its server upgrades in place (
|
|
35
|
+
// On SQLite a runner waits only for a version its server upgrades in place (SQLITE_UPGRADES), and refuses any other
|
|
36
|
+
// earlier one.
|
|
38
37
|
const runner = target.kind === "sqlite" && version !== null && version < build && !SQLITE_UPGRADES.has(version)
|
|
39
38
|
? "refused"
|
|
40
39
|
: awaits && version === build ? "waits" : runnerOn(target.kind === "sqlite" ? { version, runnerFloor: version } : state, build);
|