@sema-agent/server 1.323.0 → 2.0.0
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/dist/approval-hmac.d.ts +40 -0
- package/dist/approval-hmac.js +67 -0
- package/dist/approval.d.ts +31 -0
- package/dist/approval.js +72 -4
- package/dist/audit.d.ts +26 -0
- package/dist/audit.js +40 -1
- package/dist/auth-bridge.d.ts +10 -0
- package/dist/auth-bridge.js +47 -4
- package/dist/auth-keys.d.ts +19 -0
- package/dist/auth-keys.js +13 -0
- package/dist/bake-runner/main.d.ts +5 -0
- package/dist/bake-runner/main.js +43 -4
- package/dist/bake-runner/protocol.d.ts +57 -0
- package/dist/bake-runner/protocol.js +58 -3
- package/dist/bake-runner/runner.d.ts +54 -0
- package/dist/bake-runner/runner.js +87 -5
- package/dist/bench/l8/artifact.d.ts +63 -0
- package/dist/bench/l8/artifact.js +61 -2
- package/dist/bench/l8/escape.d.ts +36 -0
- package/dist/bench/l8/escape.js +25 -0
- package/dist/bench/l8/index.d.ts +14 -0
- package/dist/bench/l8/index.js +14 -0
- package/dist/bench/l8/probes.d.ts +74 -0
- package/dist/bench/l8/probes.js +60 -0
- package/dist/bench/l8/run-probes.d.ts +43 -0
- package/dist/bench/l8/run-probes.js +45 -2
- package/dist/bench/s1/arms.d.ts +126 -0
- package/dist/bench/s1/arms.js +188 -13
- package/dist/bench/s1/live-deps.d.ts +66 -0
- package/dist/bench/s1/live-deps.js +249 -11
- package/dist/bench/s1/oracle.d.ts +49 -0
- package/dist/bench/s1/oracle.js +36 -1
- package/dist/bench/s1/repair-oracle-adapter.d.ts +33 -0
- package/dist/bench/s1/repair-oracle-adapter.js +30 -0
- package/dist/bench/s1/reviewer.d.ts +38 -0
- package/dist/bench/s1/reviewer.js +34 -0
- package/dist/bench/s1/row.d.ts +77 -0
- package/dist/bench/s1/row.js +62 -0
- package/dist/bench/s1/run-firm.d.ts +47 -0
- package/dist/bench/s1/run-firm.js +70 -4
- package/dist/bench/s1/runner-ctx.d.ts +71 -0
- package/dist/bench/s1/runner-ctx.js +36 -0
- package/dist/bench/s1/tasks.d.ts +108 -0
- package/dist/bench/s1/tasks.js +115 -0
- package/dist/boot-reclaim.d.ts +19 -0
- package/dist/boot-reclaim.js +20 -0
- package/dist/brain.d.ts +25 -0
- package/dist/brain.js +61 -1
- package/dist/budget.d.ts +66 -0
- package/dist/budget.js +128 -4
- package/dist/capabilities/builtin-tools.d.ts +3 -0
- package/dist/capabilities/builtin-tools.js +3 -0
- package/dist/capabilities/center-plugins.d.ts +17 -1
- package/dist/capabilities/center-plugins.js +45 -4
- package/dist/capabilities/center-prompts.d.ts +46 -0
- package/dist/capabilities/center-prompts.js +57 -3
- package/dist/capabilities/code-review-council.d.ts +28 -0
- package/dist/capabilities/code-review-council.js +40 -7
- package/dist/capabilities/collab-wire.d.ts +2 -0
- package/dist/capabilities/collab-workflows.d.ts +7 -0
- package/dist/capabilities/collab-workflows.js +44 -1
- package/dist/capabilities/oa-tools.d.ts +6 -0
- package/dist/capabilities/oa-tools.js +10 -0
- package/dist/capabilities/prompt.d.ts +14 -0
- package/dist/capabilities/prompt.js +14 -0
- package/dist/capabilities/prompts/code-review.d.ts +14 -0
- package/dist/capabilities/prompts/code-review.js +14 -0
- package/dist/capabilities/prompts/identity.d.ts +6 -0
- package/dist/capabilities/prompts/identity.js +6 -0
- package/dist/capabilities/prompts/team.d.ts +4 -0
- package/dist/capabilities/prompts/team.js +4 -0
- package/dist/capabilities/repo-tools.d.ts +11 -0
- package/dist/capabilities/repo-tools.js +8 -0
- package/dist/capabilities/sandbox-file-send.d.ts +95 -0
- package/dist/capabilities/sandbox-file-send.js +91 -3
- package/dist/capabilities/scenarios.d.ts +130 -0
- package/dist/capabilities/scenarios.js +180 -7
- package/dist/capabilities/select-environment-tool.d.ts +7 -0
- package/dist/capabilities/select-environment-tool.js +30 -0
- package/dist/capabilities/send-user-file-tool.d.ts +33 -0
- package/dist/capabilities/send-user-file-tool.js +65 -1
- package/dist/capabilities/skills.d.ts +29 -0
- package/dist/capabilities/skills.js +13 -2
- package/dist/capabilities/team.d.ts +22 -0
- package/dist/capabilities/team.js +22 -2
- package/dist/capabilities/tool-defer.d.ts +26 -0
- package/dist/capabilities/tool-defer.js +3 -0
- package/dist/config-center/apply-effective.d.ts +65 -0
- package/dist/config-center/apply-effective.js +204 -12
- package/dist/config-center/http-client.d.ts +34 -0
- package/dist/config-center/http-client.js +68 -0
- package/dist/config-center/restart-signal.d.ts +22 -0
- package/dist/config-center/restart-signal.js +39 -0
- package/dist/config-center/skills-mcp.d.ts +20 -1
- package/dist/config-center/skills-mcp.js +42 -7
- package/dist/config-center/types.d.ts +92 -1
- package/dist/config-lkg.d.ts +12 -0
- package/dist/config-lkg.js +41 -0
- package/dist/config-provider.d.ts +78 -0
- package/dist/config-provider.js +165 -2
- package/dist/config-types.d.ts +546 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +455 -60
- package/dist/degenerate-instrument.d.ts +38 -0
- package/dist/degenerate-instrument.js +55 -3
- package/dist/elicitation.d.ts +39 -0
- package/dist/elicitation.js +87 -3
- package/dist/env-facts.d.ts +61 -0
- package/dist/env-facts.js +73 -7
- package/dist/fleet/fleet-bus.d.ts +185 -0
- package/dist/fleet/fleet-bus.js +333 -27
- package/dist/fleet/subagent-tail-bus.d.ts +11 -0
- package/dist/fleet/subagent-tail-bus.js +33 -2
- package/dist/fleet-client.d.ts +38 -0
- package/dist/fleet-client.js +44 -9
- package/dist/fleet-lease.d.ts +46 -0
- package/dist/fleet-lease.js +73 -5
- package/dist/hooks/branch-transcript.d.ts +8 -0
- package/dist/hooks/branch-transcript.js +33 -0
- package/dist/hooks/cc-stop-prompt.d.ts +42 -0
- package/dist/hooks/cc-stop-prompt.js +43 -1
- package/dist/hooks/hook-llm.d.ts +15 -0
- package/dist/hooks/hook-llm.js +47 -0
- package/dist/hooks/hook-runner.d.ts +89 -0
- package/dist/hooks/hook-runner.js +327 -18
- package/dist/http/idempotency.d.ts +31 -0
- package/dist/http/idempotency.js +34 -0
- package/dist/http/principal-gate.d.ts +17 -0
- package/dist/http/principal-gate.js +35 -3
- package/dist/http/route-ctx.d.ts +36 -0
- package/dist/http/routes/approvals-assistant.d.ts +25 -0
- package/dist/http/routes/approvals-assistant.js +253 -23
- package/dist/http/routes/attachments.js +22 -4
- package/dist/http/routes/capabilities.d.ts +7 -0
- package/dist/http/routes/capabilities.js +202 -1
- package/dist/http/routes/fleet.d.ts +6 -0
- package/dist/http/routes/fleet.js +94 -5
- package/dist/http/routes/images.d.ts +17 -0
- package/dist/http/routes/images.js +222 -14
- package/dist/http/routes/leader.d.ts +7 -0
- package/dist/http/routes/leader.js +10 -0
- package/dist/http/routes/memory-policy.d.ts +6 -0
- package/dist/http/routes/memory-policy.js +38 -6
- package/dist/http/routes/notify-wake.d.ts +10 -0
- package/dist/http/routes/notify-wake.js +19 -3
- package/dist/http/routes/observability.d.ts +6 -0
- package/dist/http/routes/observability.js +19 -2
- package/dist/http/routes/runs.d.ts +15 -0
- package/dist/http/routes/runs.js +464 -41
- package/dist/http/routes/session-sync.d.ts +15 -0
- package/dist/http/routes/session-sync.js +229 -19
- package/dist/http/routes/sessions-list.d.ts +6 -0
- package/dist/http/routes/sessions-list.js +35 -4
- package/dist/http/routes/sessions.d.ts +14 -0
- package/dist/http/routes/sessions.js +176 -31
- package/dist/http/routes/side-query.d.ts +8 -0
- package/dist/http/routes/side-query.js +26 -1
- package/dist/http/routes/tasks.d.ts +18 -0
- package/dist/http/routes/tasks.js +501 -38
- package/dist/http/routes/trace-usage.d.ts +10 -0
- package/dist/http/routes/trace-usage.js +66 -14
- package/dist/http/routes/workflows.d.ts +12 -0
- package/dist/http/routes/workflows.js +180 -19
- package/dist/http/run-meta.d.ts +11 -0
- package/dist/http/run-meta.js +6 -0
- package/dist/http/send.d.ts +19 -0
- package/dist/http/send.js +11 -0
- package/dist/http/server.d.ts +255 -0
- package/dist/http/server.js +921 -75
- package/dist/http/sse-log.d.ts +15 -0
- package/dist/http/sse-log.js +16 -0
- package/dist/http/tar.d.ts +9 -0
- package/dist/http/tar.js +21 -5
- package/dist/http/wire-gate.d.ts +9 -0
- package/dist/http/wire-gate.js +9 -0
- package/dist/http/wire-types.d.ts +187 -0
- package/dist/http/workspace-content.d.ts +8 -0
- package/dist/http/workspace-content.js +10 -0
- package/dist/images/bake-validate.d.ts +63 -0
- package/dist/images/bake-validate.js +71 -1
- package/dist/images/manifest.d.ts +19 -0
- package/dist/images/manifest.js +6 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +10 -5
- package/dist/key-resolver.d.ts +23 -0
- package/dist/key-resolver.js +27 -2
- package/dist/leader/diffout.d.ts +23 -0
- package/dist/leader/diffout.js +8 -1
- package/dist/leader/diffup.d.ts +32 -0
- package/dist/leader/diffup.js +43 -0
- package/dist/leader/endpoint.d.ts +20 -0
- package/dist/leader/endpoint.js +25 -2
- package/dist/leader/fanout.d.ts +60 -0
- package/dist/leader/fanout.js +29 -3
- package/dist/leader/grader-env-factory.d.ts +74 -0
- package/dist/leader/grader-env-factory.js +62 -3
- package/dist/leader/leader.d.ts +97 -0
- package/dist/leader/leader.js +151 -4
- package/dist/leader/merge.d.ts +94 -0
- package/dist/leader/merge.js +112 -9
- package/dist/leader/planner.d.ts +52 -0
- package/dist/leader/planner.js +47 -3
- package/dist/leader/repair-oracle.d.ts +61 -0
- package/dist/leader/repair-oracle.js +59 -1
- package/dist/leader/repair-wire.d.ts +78 -0
- package/dist/leader/repair-wire.js +79 -2
- package/dist/leader/wire.d.ts +79 -0
- package/dist/leader/wire.js +255 -8
- package/dist/lsp/e2b-bridge.d.ts +16 -0
- package/dist/lsp/e2b-bridge.js +32 -4
- package/dist/lsp/e2b-manager.d.ts +10 -0
- package/dist/lsp/e2b-manager.js +18 -2
- package/dist/lsp/lsp-frames.d.ts +12 -0
- package/dist/lsp/lsp-frames.js +12 -0
- package/dist/lsp/manager.d.ts +12 -0
- package/dist/lsp/manager.js +35 -2
- package/dist/lsp/types.d.ts +10 -0
- package/dist/lsp/ws-transport.d.ts +12 -0
- package/dist/lsp/ws-transport.js +53 -5
- package/dist/lsp-evict.d.ts +14 -0
- package/dist/lsp-evict.js +15 -1
- package/dist/main.js +2132 -96
- package/dist/memory-export.d.ts +1 -0
- package/dist/memory-export.js +4 -0
- package/dist/memory-scope.d.ts +49 -0
- package/dist/memory-scope.js +87 -4
- package/dist/memory-sync-client.d.ts +24 -0
- package/dist/memory-sync-client.js +41 -2
- package/dist/memory-sync.d.ts +23 -0
- package/dist/memory-sync.js +70 -1
- package/dist/model-select.d.ts +39 -0
- package/dist/model-select.js +42 -1
- package/dist/observability/cost-quota.d.ts +20 -0
- package/dist/observability/cost-quota.js +4 -0
- package/dist/observability/cost-taxonomy.d.ts +45 -0
- package/dist/observability/cost-taxonomy.js +34 -0
- package/dist/observability/logger.d.ts +1 -0
- package/dist/observability/logger.js +6 -0
- package/dist/observability/metrics.d.ts +13 -0
- package/dist/observability/metrics.js +63 -0
- package/dist/observability/otel-exporter.d.ts +9 -0
- package/dist/observability/otel-exporter.js +11 -3
- package/dist/observability/principal-context.d.ts +9 -0
- package/dist/observability/principal-context.js +9 -0
- package/dist/observability/prompt-manifest.d.ts +37 -0
- package/dist/observability/prompt-manifest.js +35 -1
- package/dist/observability/rate-limit.d.ts +10 -0
- package/dist/observability/rate-limit.js +1 -0
- package/dist/observability/tool-trace.d.ts +24 -0
- package/dist/observability/tool-trace.js +41 -1
- package/dist/orchestration/hardened-vm-runner.d.ts +107 -0
- package/dist/orchestration/hardened-vm-runner.js +119 -4
- package/dist/orchestration/hardened-vm-worker-runner.d.ts +14 -0
- package/dist/orchestration/hardened-vm-worker-runner.js +26 -1
- package/dist/orchestration/hardened-vm-worker.js +27 -0
- package/dist/orchestration/subagent-steer.d.ts +44 -0
- package/dist/orchestration/subagent-steer.js +45 -1
- package/dist/orchestration/workflow-agent-steer.d.ts +54 -0
- package/dist/orchestration/workflow-agent-steer.js +80 -1
- package/dist/orchestration/workflow-completion-inbox.d.ts +189 -2
- package/dist/orchestration/workflow-completion-inbox.js +283 -32
- package/dist/orchestration/workflow-notify-journal.d.ts +132 -1
- package/dist/orchestration/workflow-notify-journal.js +187 -13
- package/dist/parked-decide.d.ts +61 -0
- package/dist/parked-decide.js +58 -1
- package/dist/per-task-image.d.ts +54 -0
- package/dist/per-task-image.js +41 -0
- package/dist/plan-cache-probe.d.ts +35 -0
- package/dist/plan-cache-probe.js +18 -3
- package/dist/plugins/approval-exemption-store.d.ts +7 -0
- package/dist/plugins/approval-exemption-store.js +28 -2
- package/dist/plugins/approval-store-sql.d.ts +64 -0
- package/dist/plugins/approval-store-sql.js +32 -0
- package/dist/plugins/background-agent-store-sql.d.ts +55 -0
- package/dist/plugins/background-agent-store-sql.js +91 -4
- package/dist/plugins/background-shell-support.d.ts +98 -0
- package/dist/plugins/background-shell-support.js +117 -13
- package/dist/plugins/blob-backend.d.ts +104 -0
- package/dist/plugins/blob-backend.js +163 -6
- package/dist/plugins/breaker-state-sql.d.ts +65 -1
- package/dist/plugins/breaker-state-sql.js +46 -8
- package/dist/plugins/caching-session-store.d.ts +42 -0
- package/dist/plugins/caching-session-store.js +63 -3
- package/dist/plugins/checkpoint-store-sql.d.ts +179 -0
- package/dist/plugins/checkpoint-store-sql.js +239 -11
- package/dist/plugins/file-outcome-sink.d.ts +4 -0
- package/dist/plugins/file-outcome-sink.js +9 -0
- package/dist/plugins/file-resume-anchor-store.d.ts +20 -0
- package/dist/plugins/file-resume-anchor-store.js +43 -4
- package/dist/plugins/file-run-store.d.ts +90 -0
- package/dist/plugins/file-run-store.js +145 -13
- package/dist/plugins/file-snapshot-store-sql.d.ts +133 -1
- package/dist/plugins/file-snapshot-store-sql.js +178 -10
- package/dist/plugins/file-workflow-journal-store.d.ts +10 -0
- package/dist/plugins/file-workflow-journal-store.js +10 -0
- package/dist/plugins/fork-routing-session-store.d.ts +47 -0
- package/dist/plugins/fork-routing-session-store.js +51 -3
- package/dist/plugins/host-platform.d.ts +69 -0
- package/dist/plugins/host-platform.js +81 -2
- package/dist/plugins/image-bake-store-sql.d.ts +136 -1
- package/dist/plugins/image-bake-store-sql.js +241 -7
- package/dist/plugins/image-index-sql.d.ts +46 -0
- package/dist/plugins/image-index-sql.js +113 -4
- package/dist/plugins/k8s-bg-scripts.d.ts +34 -0
- package/dist/plugins/k8s-bg-scripts.js +88 -4
- package/dist/plugins/k8s-exec-protocol.d.ts +33 -0
- package/dist/plugins/k8s-exec-protocol.js +41 -0
- package/dist/plugins/local-checkpoint-store.d.ts +40 -0
- package/dist/plugins/local-checkpoint-store.js +86 -7
- package/dist/plugins/local-session-store.d.ts +157 -0
- package/dist/plugins/local-session-store.js +289 -34
- package/dist/plugins/local-task-attachment-store.js +14 -2
- package/dist/plugins/mailbox-store-sql.d.ts +38 -0
- package/dist/plugins/mailbox-store-sql.js +39 -6
- package/dist/plugins/memory-engine-pg.d.ts +30 -0
- package/dist/plugins/memory-engine-pg.js +122 -4
- package/dist/plugins/memory-engine-tidb.d.ts +26 -0
- package/dist/plugins/memory-engine-tidb.js +115 -5
- package/dist/plugins/memory-engine-vector-util.d.ts +5 -0
- package/dist/plugins/memory-engine-vector-util.js +5 -0
- package/dist/plugins/memory-resume-anchor-store.d.ts +8 -0
- package/dist/plugins/memory-resume-anchor-store.js +17 -0
- package/dist/plugins/memory-run-store.d.ts +63 -0
- package/dist/plugins/memory-run-store.js +73 -8
- package/dist/plugins/memory-session-policy-store.d.ts +17 -0
- package/dist/plugins/memory-session-policy-store.js +17 -0
- package/dist/plugins/memory-sync-store-pg.d.ts +42 -0
- package/dist/plugins/memory-sync-store-pg.js +45 -2
- package/dist/plugins/memory-sync-store-tidb.d.ts +9 -0
- package/dist/plugins/memory-sync-store-tidb.js +31 -1
- package/dist/plugins/outcome-ledger-sql.d.ts +63 -0
- package/dist/plugins/outcome-ledger-sql.js +97 -3
- package/dist/plugins/pg-approval-store.d.ts +7 -0
- package/dist/plugins/pg-approval-store.js +7 -0
- package/dist/plugins/pg-breaker-state.d.ts +6 -0
- package/dist/plugins/pg-breaker-state.js +6 -0
- package/dist/plugins/pg-checkpoint-store.d.ts +8 -0
- package/dist/plugins/pg-checkpoint-store.js +8 -0
- package/dist/plugins/pg-cost-quota.d.ts +17 -0
- package/dist/plugins/pg-cost-quota.js +6 -0
- package/dist/plugins/pg-file-snapshot-store.d.ts +6 -0
- package/dist/plugins/pg-file-snapshot-store.js +6 -0
- package/dist/plugins/pg-image-bake.d.ts +9 -0
- package/dist/plugins/pg-image-bake.js +9 -0
- package/dist/plugins/pg-image-index.d.ts +9 -0
- package/dist/plugins/pg-image-index.js +9 -0
- package/dist/plugins/pg-outcome-ledger.d.ts +9 -0
- package/dist/plugins/pg-outcome-ledger.js +9 -0
- package/dist/plugins/pg-pool.d.ts +50 -0
- package/dist/plugins/pg-pool.js +78 -0
- package/dist/plugins/pg-query.d.ts +11 -0
- package/dist/plugins/pg-rate-limiter.d.ts +23 -0
- package/dist/plugins/pg-rate-limiter.js +12 -2
- package/dist/plugins/pg-resume-anchor-store.d.ts +5 -0
- package/dist/plugins/pg-resume-anchor-store.js +5 -0
- package/dist/plugins/pg-run-store.d.ts +7 -0
- package/dist/plugins/pg-run-store.js +7 -0
- package/dist/plugins/pg-safe-json.d.ts +13 -0
- package/dist/plugins/pg-safe-json.js +40 -4
- package/dist/plugins/pg-session-policy-store.d.ts +5 -0
- package/dist/plugins/pg-session-policy-store.js +5 -0
- package/dist/plugins/pg-session-storage.d.ts +72 -0
- package/dist/plugins/pg-session-storage.js +152 -20
- package/dist/plugins/pg-session-store.d.ts +10 -0
- package/dist/plugins/pg-session-store.js +10 -0
- package/dist/plugins/pg-tool-result-store.d.ts +7 -0
- package/dist/plugins/pg-tool-result-store.js +7 -0
- package/dist/plugins/pg-workflow-journal-store.d.ts +7 -0
- package/dist/plugins/pg-workflow-journal-store.js +7 -0
- package/dist/plugins/pg-workflow-run-store.d.ts +7 -0
- package/dist/plugins/pg-workflow-run-store.js +7 -0
- package/dist/plugins/posix-shell-fs.d.ts +3 -0
- package/dist/plugins/posix-shell-fs.js +31 -1
- package/dist/plugins/remote-env-adb.d.ts +25 -0
- package/dist/plugins/remote-env-adb.js +95 -12
- package/dist/plugins/remote-env-e2b.d.ts +146 -0
- package/dist/plugins/remote-env-e2b.js +371 -40
- package/dist/plugins/remote-env-file-error.d.ts +34 -0
- package/dist/plugins/remote-env-file-error.js +37 -0
- package/dist/plugins/remote-env-host.d.ts +151 -0
- package/dist/plugins/remote-env-host.js +468 -70
- package/dist/plugins/remote-env-k8s.d.ts +135 -0
- package/dist/plugins/remote-env-k8s.js +318 -32
- package/dist/plugins/remote-env-local-docker.d.ts +65 -0
- package/dist/plugins/remote-env-local-docker.js +149 -24
- package/dist/plugins/remote-env-ssh.d.ts +35 -0
- package/dist/plugins/remote-env-ssh.js +117 -20
- package/dist/plugins/remote-scratchpad.d.ts +38 -0
- package/dist/plugins/remote-scratchpad.js +32 -2
- package/dist/plugins/remote-shell.d.ts +22 -0
- package/dist/plugins/remote-shell.js +27 -1
- package/dist/plugins/resume-anchor-store-sql.d.ts +28 -0
- package/dist/plugins/resume-anchor-store-sql.js +11 -0
- package/dist/plugins/roster-store-sql.d.ts +27 -0
- package/dist/plugins/roster-store-sql.js +54 -0
- package/dist/plugins/run-store-sql.d.ts +194 -0
- package/dist/plugins/run-store-sql.js +210 -9
- package/dist/plugins/s3-presign.d.ts +20 -0
- package/dist/plugins/s3-presign.js +49 -2
- package/dist/plugins/scheduler-support.d.ts +12 -0
- package/dist/plugins/scheduler-support.js +75 -3
- package/dist/plugins/send-file-ledger.d.ts +15 -0
- package/dist/plugins/send-file-ledger.js +53 -4
- package/dist/plugins/send-user-file.d.ts +77 -0
- package/dist/plugins/send-user-file.js +92 -4
- package/dist/plugins/session-policy-store-sql.d.ts +15 -0
- package/dist/plugins/session-policy-store-sql.js +75 -3
- package/dist/plugins/session-store.d.ts +45 -0
- package/dist/plugins/session-store.js +51 -0
- package/dist/plugins/sql-driver.d.ts +77 -0
- package/dist/plugins/sql-driver.js +4 -0
- package/dist/plugins/sql-escape.d.ts +8 -0
- package/dist/plugins/sql-escape.js +8 -0
- package/dist/plugins/sql-row-helpers.d.ts +25 -0
- package/dist/plugins/sql-row-helpers.js +25 -0
- package/dist/plugins/store-backend.d.ts +103 -0
- package/dist/plugins/store-backend.js +120 -27
- package/dist/plugins/store-contracts.d.ts +62 -0
- package/dist/plugins/store-contracts.js +3 -0
- package/dist/plugins/task-attachment-store.d.ts +60 -0
- package/dist/plugins/task-attachment-store.js +49 -3
- package/dist/plugins/task-list-store-sql.d.ts +25 -0
- package/dist/plugins/task-list-store-sql.js +21 -0
- package/dist/plugins/tidb-approval-store.d.ts +6 -0
- package/dist/plugins/tidb-approval-store.js +6 -0
- package/dist/plugins/tidb-breaker-state.d.ts +5 -0
- package/dist/plugins/tidb-breaker-state.js +5 -0
- package/dist/plugins/tidb-checkpoint-store.d.ts +7 -0
- package/dist/plugins/tidb-checkpoint-store.js +7 -0
- package/dist/plugins/tidb-cost-quota.d.ts +6 -0
- package/dist/plugins/tidb-cost-quota.js +1 -0
- package/dist/plugins/tidb-file-snapshot-store.d.ts +6 -0
- package/dist/plugins/tidb-file-snapshot-store.js +6 -0
- package/dist/plugins/tidb-image-bake.d.ts +8 -0
- package/dist/plugins/tidb-image-bake.js +8 -0
- package/dist/plugins/tidb-image-index.d.ts +8 -0
- package/dist/plugins/tidb-image-index.js +8 -0
- package/dist/plugins/tidb-outcome-ledger.d.ts +10 -0
- package/dist/plugins/tidb-outcome-ledger.js +10 -0
- package/dist/plugins/tidb-pool.d.ts +56 -0
- package/dist/plugins/tidb-pool.js +181 -1
- package/dist/plugins/tidb-rate-limiter.d.ts +11 -0
- package/dist/plugins/tidb-rate-limiter.js +5 -2
- package/dist/plugins/tidb-resume-anchor-store.d.ts +5 -0
- package/dist/plugins/tidb-resume-anchor-store.js +5 -0
- package/dist/plugins/tidb-run-store.d.ts +7 -0
- package/dist/plugins/tidb-run-store.js +7 -0
- package/dist/plugins/tidb-session-policy-store.d.ts +5 -0
- package/dist/plugins/tidb-session-policy-store.js +5 -0
- package/dist/plugins/tidb-session-storage.d.ts +43 -0
- package/dist/plugins/tidb-session-storage.js +62 -3
- package/dist/plugins/tidb-session-store.d.ts +142 -0
- package/dist/plugins/tidb-session-store.js +264 -16
- package/dist/plugins/tidb-tool-result-store.d.ts +5 -0
- package/dist/plugins/tidb-tool-result-store.js +7 -0
- package/dist/plugins/tidb-workflow-journal-store.d.ts +7 -0
- package/dist/plugins/tidb-workflow-journal-store.js +7 -0
- package/dist/plugins/tidb-workflow-run-store.d.ts +8 -0
- package/dist/plugins/tidb-workflow-run-store.js +8 -0
- package/dist/plugins/tool-result-store-sql.d.ts +58 -0
- package/dist/plugins/tool-result-store-sql.js +38 -2
- package/dist/plugins/web-search.d.ts +35 -0
- package/dist/plugins/web-search.js +45 -9
- package/dist/plugins/workflow-journal-limits.d.ts +10 -0
- package/dist/plugins/workflow-journal-limits.js +10 -0
- package/dist/plugins/workflow-journal-store-sql.d.ts +78 -0
- package/dist/plugins/workflow-journal-store-sql.js +58 -2
- package/dist/plugins/workflow-run-store-sql.d.ts +84 -0
- package/dist/plugins/workflow-run-store-sql.js +84 -6
- package/dist/plugins/worktree-isolation.d.ts +45 -0
- package/dist/plugins/worktree-isolation.js +105 -6
- package/dist/plugins/write-behind-counter.d.ts +56 -1
- package/dist/plugins/write-behind-counter.js +53 -14
- package/dist/principal-jwt.d.ts +24 -0
- package/dist/principal-jwt.js +60 -5
- package/dist/project-memory.d.ts +22 -0
- package/dist/project-memory.js +144 -15
- package/dist/prompts-domain-validate.d.ts +28 -0
- package/dist/prompts-domain-validate.js +42 -1
- package/dist/question.d.ts +33 -0
- package/dist/question.js +69 -2
- package/dist/resource-suspend.d.ts +21 -0
- package/dist/resource-suspend.js +16 -0
- package/dist/router/route-orchestration.d.ts +78 -0
- package/dist/router/route-orchestration.js +77 -0
- package/dist/run-local.d.ts +32 -0
- package/dist/run-local.js +172 -8
- package/dist/runs.d.ts +189 -4
- package/dist/runs.js +465 -24
- package/dist/runtime-caps-resolver.d.ts +106 -0
- package/dist/runtime-caps-resolver.js +89 -4
- package/dist/runtime-governance.d.ts +84 -0
- package/dist/runtime-governance.js +127 -1
- package/dist/sandbox-pkg-source.d.ts +23 -0
- package/dist/sandbox-pkg-source.js +37 -0
- package/dist/sealed-key.d.ts +54 -0
- package/dist/sealed-key.js +68 -3
- package/dist/security.d.ts +108 -0
- package/dist/security.js +145 -6
- package/dist/sema-registry.d.ts +21 -0
- package/dist/sema-registry.js +21 -0
- package/dist/session-leaf-bus.d.ts +31 -0
- package/dist/session-leaf-bus.js +32 -0
- package/dist/session-sync-content.d.ts +46 -0
- package/dist/session-sync-content.js +47 -1
- package/dist/session-sync-kernel.d.ts +89 -0
- package/dist/session-sync-kernel.js +48 -3
- package/dist/session-sync.d.ts +125 -0
- package/dist/session-sync.js +181 -8
- package/dist/session-titler.d.ts +26 -0
- package/dist/session-titler.js +41 -7
- package/dist/session-watch.d.ts +53 -1
- package/dist/session-watch.js +73 -9
- package/dist/sighup-idle.d.ts +30 -0
- package/dist/sighup-idle.js +12 -1
- package/dist/spec-fields.d.ts +91 -3
- package/dist/spec-fields.js +116 -4
- package/dist/task-cwd.d.ts +50 -0
- package/dist/task-cwd.js +68 -1
- package/dist/task-mcp.d.ts +47 -0
- package/dist/task-mcp.js +29 -0
- package/dist/task-settings.d.ts +175 -0
- package/dist/task-settings.js +226 -11
- package/dist/task-workflow.d.ts +67 -0
- package/dist/task-workflow.js +75 -8
- package/dist/tool-approval.d.ts +91 -0
- package/dist/tool-approval.js +215 -0
- package/dist/trace/artifacts.d.ts +9 -0
- package/dist/trace/artifacts.js +30 -5
- package/dist/trace/core-keyset-guard.d.ts +18 -0
- package/dist/trace/ledger-sink.d.ts +43 -0
- package/dist/trace/ledger-sink.js +64 -5
- package/dist/trace/project.d.ts +133 -0
- package/dist/trace/project.js +189 -2
- package/dist/trace/redact.d.ts +19 -0
- package/dist/trace/redact.js +66 -9
- package/dist/usage-analytics.d.ts +26 -0
- package/dist/usage-analytics.js +26 -3
- package/package.json +1 -1
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import mysql from "mysql2/promise";
|
|
2
|
+
/**
|
|
3
|
+
* Shared TiDB (MySQL wire-compatible) connection pool for the durable Session center (L1).
|
|
4
|
+
* Owned by `main.ts`; closed on shutdown.
|
|
5
|
+
*
|
|
6
|
+
* Read/write pool — this is the persistence center. (The SQL *tool* given to the model must use a
|
|
7
|
+
* separate read-only pool/credential; never hand this pool to a tool.)
|
|
8
|
+
*/
|
|
9
|
+
/** Build the mysql2 pool options from TiDB config (pure → unit-testable apart from the live connection). */
|
|
2
10
|
export function tidbPoolOptions(tidb) {
|
|
3
11
|
const { host, port, user, password, database, connectionLimit } = tidb;
|
|
4
12
|
const limit = connectionLimit ?? 10;
|
|
@@ -13,7 +21,15 @@ export function tidbPoolOptions(tidb) {
|
|
|
13
21
|
maxIdle: limit,
|
|
14
22
|
idleTimeout: 60_000,
|
|
15
23
|
enableKeepAlive: true,
|
|
24
|
+
// Bound the acquire backlog. With waitForConnections + the mysql2 default queueLimit:0 (unlimited), a TiDB
|
|
25
|
+
// stall makes EVERY db op queue without bound → all serving hangs indefinitely instead of failing fast. A
|
|
26
|
+
// finite limit (well above a normal burst) lets a sustained stall surface as errors the HTTP layer can map
|
|
27
|
+
// to 5xx, rather than an invisible hang. (Per-query timeouts are the deeper fix: mysql2 has NO pool-level
|
|
28
|
+
// knob — `timeout` is per-query `{sql, timeout}` only — so the S9 write-behind counter family carries its
|
|
29
|
+
// own per-query timeout (write-behind-counter.ts, DB_QUERY_TIMEOUT_MS overrides); the general query surface
|
|
30
|
+
// here keeps relying on this backlog bound. The PG pool DOES have the pool-wide knob — see pgPoolOptions.)
|
|
16
31
|
queueLimit: limit * 32,
|
|
32
|
+
// Persist/return DATETIME in UTC so timestamps are stable across instances/timezones.
|
|
17
33
|
timezone: "Z",
|
|
18
34
|
charset: "utf8mb4",
|
|
19
35
|
};
|
|
@@ -25,6 +41,26 @@ export function createTidbPool(config) {
|
|
|
25
41
|
}
|
|
26
42
|
return mysql.createPool(tidbPoolOptions(config.tidb));
|
|
27
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Idempotent schema. `session_event` is the append-only L1 event log (positional slicing by
|
|
46
|
+
* `(session_id, seq)`); `session_meta` holds the branch leaf + the optimistic-lock counter
|
|
47
|
+
* (`leaf_seq`) + tenant `owner`.
|
|
48
|
+
*
|
|
49
|
+
* ── SCHEMA POLICY (clay 裁,2026-07-26) ─────────────────────────────────────────────────────────────
|
|
50
|
+
* 本仓 schema 的唯一真源 = **这份代码**(此数组 + `pg-pool.ts` 的 PG 孪生)。口径:
|
|
51
|
+
*
|
|
52
|
+
* 1. **删库重建,不做增量。** 尚未上生产、单人本地,存量库一律 DROP DATABASE 重建;因此这里**不再保留
|
|
53
|
+
* 任何 `ALTER TABLE` 增量 seam**。历史上的 21 条 ADD COLUMN / 3 条 CREATE INDEX / 1 条 MODIFY COLUMN
|
|
54
|
+
* 已于 2026-07-26 全部折进下面的 `CREATE TABLE`(它们承载的语义已逐条搬成列上的行内注释 —— 那些注释
|
|
55
|
+
* 是 pre-migration 行为契约的**唯一书面记录**,删注释 = 丢语义)。
|
|
56
|
+
* 2. **不许再新增 `ALTER TABLE` seam。** 要改列/加列/改可空性 ⇒ 直接改下面的 `CREATE TABLE`,然后重建库。
|
|
57
|
+
* (再开增量通道就等于把「代码是真源」变回「代码 + 一串按时间排的补丁才是真源」。)
|
|
58
|
+
* 3. 生成的全集 SQL 基线导出到 `docs/schema/baseline-mysql.sql`(由本数组机器生成;它是**产物**,不是真源
|
|
59
|
+
* —— 冲突时以本文件为准并重新生成)。
|
|
60
|
+
*
|
|
61
|
+
* 注意:`ensureSchema` 仍然保留(建表 + advisory lock + image_bake_admit 种子行),只是语句数组现在是纯
|
|
62
|
+
* CREATE,不再有 information_schema 探针。
|
|
63
|
+
*/
|
|
28
64
|
export const SCHEMA_STATEMENTS = [
|
|
29
65
|
`CREATE TABLE IF NOT EXISTS session_meta (
|
|
30
66
|
session_id VARCHAR(64) NOT NULL,
|
|
@@ -50,6 +86,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
50
86
|
PRIMARY KEY (session_id, seq),
|
|
51
87
|
UNIQUE KEY uk_entry (session_id, entry_id)
|
|
52
88
|
)`,
|
|
89
|
+
// Async run registry (S1) + replayable event log (S2). Any instance can serve a run's status /
|
|
90
|
+
// event replay because both live here, not in a single instance's memory.
|
|
53
91
|
`CREATE TABLE IF NOT EXISTS task_run (
|
|
54
92
|
task_id VARCHAR(64) NOT NULL,
|
|
55
93
|
session_id VARCHAR(64) NOT NULL,
|
|
@@ -98,6 +136,10 @@ export const SCHEMA_STATEMENTS = [
|
|
|
98
136
|
-- ever served an operator's ad-hoc WHERE error_code LIKE 'budget.%', while every task_run write paid its
|
|
99
137
|
-- maintenance cost. If you need that ad-hoc query, build the index temporarily and drop it after.
|
|
100
138
|
)`,
|
|
139
|
+
// Cross-replica circuit-breaker state (1.38). A row per breaker key ("<provider>:<id>"); each
|
|
140
|
+
// replica write-through-caches its trips here and periodically refreshes so a provider outage is
|
|
141
|
+
// learned fleet-wide instead of every replica re-discovering it. Advisory / eventually consistent
|
|
142
|
+
// (last-writer-wins): the breaker is consultative, not a linearizable lock.
|
|
101
143
|
`CREATE TABLE IF NOT EXISTS circuit_breaker (
|
|
102
144
|
breaker_key VARCHAR(190) NOT NULL,
|
|
103
145
|
phase VARCHAR(16) NOT NULL,
|
|
@@ -106,6 +148,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
106
148
|
updated_at DATETIME(3) NOT NULL,
|
|
107
149
|
PRIMARY KEY (breaker_key)
|
|
108
150
|
)`,
|
|
151
|
+
// Cross-replica per-key CUMULATIVE cost quota (design/30 P0-1). One row per (scope_key, aligned window
|
|
152
|
+
// bucket); replicas atomically `micro = micro + delta` (write-behind aggregation), so spend is summed
|
|
153
|
+
// fleet-wide without losing increments. scope_key is opaque (principal today; team/feature later).
|
|
109
154
|
`CREATE TABLE IF NOT EXISTS cost_quota (
|
|
110
155
|
scope_key VARCHAR(190) NOT NULL,
|
|
111
156
|
window_bucket BIGINT NOT NULL,
|
|
@@ -114,6 +159,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
114
159
|
PRIMARY KEY (scope_key, window_bucket),
|
|
115
160
|
KEY idx_window (window_bucket)
|
|
116
161
|
)`,
|
|
162
|
+
// Cross-replica per-key request rate limit (design/30 P0-2) — same write-behind-counter shape as
|
|
163
|
+
// cost_quota (one row per key+aligned-window, atomic n = n + delta). Soft fleet-wide limiting.
|
|
117
164
|
`CREATE TABLE IF NOT EXISTS rate_limit (
|
|
118
165
|
limit_key VARCHAR(190) NOT NULL,
|
|
119
166
|
window_bucket BIGINT NOT NULL,
|
|
@@ -122,6 +169,10 @@ export const SCHEMA_STATEMENTS = [
|
|
|
122
169
|
PRIMARY KEY (limit_key, window_bucket),
|
|
123
170
|
KEY idx_window (window_bucket)
|
|
124
171
|
)`,
|
|
172
|
+
// Durable backing for offloaded large tool results (core 1.47/1.49). One row per offload ref
|
|
173
|
+
// (`tr_<sessionId>_<toolCallId>`, globally unique → PK); content is the full tool output moved out of
|
|
174
|
+
// context. Write-once (INSERT IGNORE); TTL-reaped by created_at (idx_created). LONGTEXT holds large
|
|
175
|
+
// file/diff reads. Lets an async run wake on any replica and still read_tool_result the full text.
|
|
125
176
|
`CREATE TABLE IF NOT EXISTS tool_result (
|
|
126
177
|
ref VARCHAR(190) NOT NULL,
|
|
127
178
|
content LONGTEXT NOT NULL,
|
|
@@ -137,6 +188,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
137
188
|
ts DATETIME(3) NOT NULL,
|
|
138
189
|
PRIMARY KEY (task_id, seq)
|
|
139
190
|
)`,
|
|
191
|
+
// Single-active-run-per-session claim. PRIMARY KEY(session_id) makes the claim a unique-key
|
|
192
|
+
// insert: TiDB enforces it even with no prior row (it lacks InnoDB gap locks, so a
|
|
193
|
+
// SELECT…FOR UPDATE on an empty match would NOT serialize two concurrent zero-prior createRuns).
|
|
140
194
|
`CREATE TABLE IF NOT EXISTS task_active (
|
|
141
195
|
session_id VARCHAR(64) NOT NULL,
|
|
142
196
|
task_id VARCHAR(64) NOT NULL,
|
|
@@ -144,6 +198,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
144
198
|
PRIMARY KEY (session_id),
|
|
145
199
|
KEY idx_task (task_id)
|
|
146
200
|
)`,
|
|
201
|
+
// Human-in-the-loop approval gate (F4). A pending row is durable so an operator's decision can
|
|
202
|
+
// arrive on any instance; the instance running the task polls this row to release its wait.
|
|
147
203
|
`CREATE TABLE IF NOT EXISTS approval (
|
|
148
204
|
id VARCHAR(64) NOT NULL,
|
|
149
205
|
task_id VARCHAR(64) NULL,
|
|
@@ -168,6 +224,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
168
224
|
KEY idx_scope_status (scope, status),
|
|
169
225
|
KEY idx_status (status)
|
|
170
226
|
)`,
|
|
227
|
+
// Durable-checkpoint (core 1.67 / design/45): a policy `ask` persisted as a suspended task so an operator
|
|
228
|
+
// can `resume` it from any replica. `checkpoint` = core's blob + CAS status; `outcome` persisted on resolve
|
|
229
|
+
// (R20 #1). Timestamps are epoch-ms BIGINT (the core Checkpoint uses ms numbers, not DATETIME).
|
|
171
230
|
`CREATE TABLE IF NOT EXISTS checkpoint (
|
|
172
231
|
token VARCHAR(120) NOT NULL,
|
|
173
232
|
scope VARCHAR(190) NOT NULL,
|
|
@@ -223,12 +282,18 @@ export const SCHEMA_STATEMENTS = [
|
|
|
223
282
|
KEY idx_status_deadline (status, deadline),
|
|
224
283
|
KEY idx_session_status (session_id, status)
|
|
225
284
|
)`,
|
|
285
|
+
// Service-side resume rebuild inputs (DURABLE-CHECKPOINT-PLAN §4.4a): sessionId-keyed because core's
|
|
286
|
+
// put(token,cp) can't carry service scenario_ctx. GC'd by the reaper once its checkpoint is gone.
|
|
226
287
|
`CREATE TABLE IF NOT EXISTS checkpoint_ctx (
|
|
227
288
|
session_id VARCHAR(190) NOT NULL,
|
|
228
289
|
ctx JSON NOT NULL,
|
|
229
290
|
updated_at BIGINT NOT NULL,
|
|
230
291
|
PRIMARY KEY (session_id)
|
|
231
292
|
)`,
|
|
293
|
+
// E18 resume-at anchor map: the shell holds live E2 eventIds (never persisted by core); TaskSpec.resumeAt takes a
|
|
294
|
+
// persisted SessionTreeEntry.id. This is the service-owned eventId→entryId translation. Keyed (session_id,event_id)
|
|
295
|
+
// so resolve is a PK point-lookup; entry_id is the resolve target. owner = single-DB-fleet defense-in-depth (the
|
|
296
|
+
// session is already owner-gated at the route + scoped by session_id). GC'd with the session (E21 delete).
|
|
232
297
|
`CREATE TABLE IF NOT EXISTS resume_anchor (
|
|
233
298
|
session_id VARCHAR(64) NOT NULL,
|
|
234
299
|
event_id VARCHAR(64) NOT NULL,
|
|
@@ -238,6 +303,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
238
303
|
PRIMARY KEY (session_id, event_id),
|
|
239
304
|
KEY idx_resume_anchor_session (session_id)
|
|
240
305
|
)`,
|
|
306
|
+
// Per-session per-toolName approval exemption ("本会话不再询问") — an APPROVAL MEMORY the
|
|
307
|
+
// F4 ask-gate consults AFTER deny/neverAuto (both always win). tool_name is CANONICAL space. GC'd with
|
|
308
|
+
// the session (E21 delete). See docs/design/APPROVAL-SESSION-EXEMPTION.md.
|
|
241
309
|
`CREATE TABLE IF NOT EXISTS approval_exemption (
|
|
242
310
|
session_id VARCHAR(64) NOT NULL,
|
|
243
311
|
tool_name VARCHAR(190) NOT NULL,
|
|
@@ -245,6 +313,12 @@ export const SCHEMA_STATEMENTS = [
|
|
|
245
313
|
created_at DATETIME(3) NOT NULL,
|
|
246
314
|
PRIMARY KEY (session_id, tool_name)
|
|
247
315
|
)`,
|
|
316
|
+
// SendUserFile server-side ledger (multi-tenant governance, 1.190.0 [768]②a second half): one row per issued
|
|
317
|
+
// link — the scope↔object mapping the HASHED key segment deliberately hides from URLs (per-tenant list/revoke
|
|
318
|
+
// handle). id = uuidv7 (time-ordered PK = the keyset cursor); scope = VERIFIED principal verbatim ("_" =
|
|
319
|
+
// single-user sentinel); object_key ≤ 207 chars by construction (prefix 9 + seg 32 + uuid 36 + name ≤128 + 2 slashes).
|
|
320
|
+
// No URL column by design (public track reconstructs from bucket+key; presigned URLs decay). See
|
|
321
|
+
// send-file-ledger.ts.
|
|
248
322
|
`CREATE TABLE IF NOT EXISTS sendfile_link (
|
|
249
323
|
id VARCHAR(64) NOT NULL,
|
|
250
324
|
scope VARCHAR(190) NOT NULL,
|
|
@@ -260,6 +334,16 @@ export const SCHEMA_STATEMENTS = [
|
|
|
260
334
|
PRIMARY KEY (id),
|
|
261
335
|
KEY idx_sendfile_link_scope (scope, id)
|
|
262
336
|
)`,
|
|
337
|
+
// E6 durable SessionPolicyStore — operator-tightened per-(session,principal) tool-permission rules (CAS-versioned
|
|
338
|
+
// tighten-only; core reads them at prepare-time, subtract-only). policy_key = sha256(JSON.stringify([sessionId,
|
|
339
|
+
// principal ?? null])) — the SHA of core's exact composite key: a FIXED 64-char PK (an arbitrary-length / JSON-
|
|
340
|
+
// escapable principal can't overflow it, and no PK collation/PAD pitfalls); undefined/null principal collapse to one
|
|
341
|
+
// row, "" stays distinct. session_id is kept as a column for the E21 deleteBySession purge + index. `principal` is
|
|
342
|
+
// stored DENORMALIZED (it is ALSO inside the sha256 policy_key) ONLY so 2c session-sync's listBySession can ENUMERATE
|
|
343
|
+
// a session's per-principal rows (the hash is one-way, so the principal can't be recovered from policy_key).
|
|
344
|
+
// It is NOT part of any key/uniqueness and does NOT participate in the CAS/tighten logic — putRules just writes it.
|
|
345
|
+
// NULL = the session-wide row (principal undefined). VARCHAR(190) bounds it (a longer/escapable principal still keys
|
|
346
|
+
// by the fixed-width hash; this column is enumeration-only, so a truncated value here can't corrupt lookups).
|
|
263
347
|
`CREATE TABLE IF NOT EXISTS session_policy (
|
|
264
348
|
policy_key CHAR(64) NOT NULL,
|
|
265
349
|
session_id VARCHAR(64) NOT NULL,
|
|
@@ -275,6 +359,10 @@ export const SCHEMA_STATEMENTS = [
|
|
|
275
359
|
PRIMARY KEY (policy_key),
|
|
276
360
|
KEY idx_session_policy_session (session_id)
|
|
277
361
|
)`,
|
|
362
|
+
// E19 rewind-files — durable working-tree snapshots keyed by (scope=sessionId, snap_key=SessionTreeEntry.id; same
|
|
363
|
+
// entryId anchor as E18). A per-(scope,key) manifest of relPath→blob_hash + content-addressed blobs (deduped across
|
|
364
|
+
// all snapshots). core's captureManifest/applyManifest do the env walk/restore; this is just the durable persistence.
|
|
365
|
+
// Bounded by DEFAULT_SNAPSHOT_BOUNDS (≤2000 files / 64 MiB, skips .git/node_modules). GC'd with the session (E21).
|
|
278
366
|
`CREATE TABLE IF NOT EXISTS snapshot_manifest (
|
|
279
367
|
scope VARCHAR(64) NOT NULL,
|
|
280
368
|
snap_key VARCHAR(64) NOT NULL,
|
|
@@ -283,6 +371,11 @@ export const SCHEMA_STATEMENTS = [
|
|
|
283
371
|
KEY idx_snapshot_manifest_sk (scope, snap_key),
|
|
284
372
|
KEY idx_snapshot_manifest_blob (blob_hash)
|
|
285
373
|
)`,
|
|
374
|
+
// `bytes` is NULLABLE: a SQL-backend row carries the bytes inline; a MinIO-backend row keeps ONLY the INDEX
|
|
375
|
+
// (blob_hash, byte_len, created_at) here with bytes NULL — the bytes live in MinIO. This INDEX row is what
|
|
376
|
+
// gcOrphanBlobs / reap / deleteBySession (E21 purge) / sweepOrphanBlobs read to compute the orphan/grace SET, so
|
|
377
|
+
// reference-tracking + the created_at grace window work IDENTICALLY for both backends (and an E21 purge can delete
|
|
378
|
+
// the MinIO object, not leak it). See blob-backend.ts MinioBlobBackend.
|
|
286
379
|
`CREATE TABLE IF NOT EXISTS snapshot_blob (
|
|
287
380
|
blob_hash CHAR(64) NOT NULL,
|
|
288
381
|
byte_len BIGINT NOT NULL,
|
|
@@ -298,6 +391,12 @@ export const SCHEMA_STATEMENTS = [
|
|
|
298
391
|
PRIMARY KEY (blob_hash),
|
|
299
392
|
KEY idx_snapshot_blob_created (created_at)
|
|
300
393
|
)`,
|
|
394
|
+
// SVC-2 (core CORE-7) durable WorkflowJournalStore — the cross-replica resume journal for an LLM-authored workflow.
|
|
395
|
+
// One row per (run_id, ordinal): `ordinal` = core's callKeyOrdinal(callKey) (the positional replay index), `result`
|
|
396
|
+
// = JSON.stringify(TaskResult). The (run_id, ordinal) PK makes append IDEMPOTENT (ON DUPLICATE KEY = OVERWRITE /
|
|
397
|
+
// last-write-wins) so a resumed run re-appending its replayed prefix verbatim leaves no dup — the byte-match of
|
|
398
|
+
// core's InMemoryWorkflowJournalStore (byOrdinal.set). LOAD-BEARING (a resume replays it), unlike the best-effort
|
|
399
|
+
// task_event observation log. GC'd by the run reaper (deleteByRun). See tidb-workflow-journal-store.ts.
|
|
301
400
|
`CREATE TABLE IF NOT EXISTS workflow_journal (
|
|
302
401
|
run_id VARCHAR(191) NOT NULL,
|
|
303
402
|
ordinal INT NOT NULL,
|
|
@@ -313,6 +412,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
313
412
|
created_at BIGINT NOT NULL,
|
|
314
413
|
PRIMARY KEY (run_id, ordinal)
|
|
315
414
|
)`,
|
|
415
|
+
// RB-242 / WF2 ([1981] core 拍板 a 形):cross-replica workflow resume admission lease. PK (source_run_id, scope)
|
|
416
|
+
// = the bake-store idem_key precedent — the INSERT either wins the claim or collides with the current holder.
|
|
417
|
+
// TTL is the CRASH backstop only (engine releases on terminal via releaseResumeClaim); see workflow-journal-store-sql.ts.
|
|
316
418
|
`CREATE TABLE IF NOT EXISTS workflow_resume_claim (
|
|
317
419
|
source_run_id VARCHAR(191) NOT NULL,
|
|
318
420
|
scope VARCHAR(190) NOT NULL,
|
|
@@ -320,6 +422,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
320
422
|
claimed_at BIGINT NOT NULL,
|
|
321
423
|
PRIMARY KEY (source_run_id, scope)
|
|
322
424
|
)`,
|
|
425
|
+
// P1 (fleet failover, 2026-07-05): durable cross-replica WorkflowRunStore twin — one row per run, the full
|
|
426
|
+
// WorkflowRun as a JSON blob + extracted index columns; `rev` column = the OCC authority (blob rev overlaid
|
|
427
|
+
// on read). MEDIUMTEXT (16MB) >> the 4MB write guard in the store.
|
|
323
428
|
`CREATE TABLE IF NOT EXISTS workflow_run (
|
|
324
429
|
id VARCHAR(191) NOT NULL,
|
|
325
430
|
scope VARCHAR(190) NOT NULL,
|
|
@@ -332,6 +437,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
332
437
|
KEY idx_wfrun_scope_created (scope, created_at),
|
|
333
438
|
KEY idx_wfrun_scope_status (scope, status)
|
|
334
439
|
)`,
|
|
440
|
+
// P1: cross-replica workflow completion inbox (the push half). seq = insertion order (re-enqueue
|
|
441
|
+
// moves to tail via DELETE+INSERT). summary is bounded upstream (core notifier ≤4000).
|
|
335
442
|
`CREATE TABLE IF NOT EXISTS workflow_completion_inbox (
|
|
336
443
|
seq BIGINT NOT NULL AUTO_INCREMENT,
|
|
337
444
|
session_id VARCHAR(190) NOT NULL,
|
|
@@ -353,6 +460,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
353
460
|
UNIQUE KEY uq_wfinbox_seq (seq),
|
|
354
461
|
KEY idx_wfinbox_session_seq (session_id, seq)
|
|
355
462
|
)`,
|
|
463
|
+
// P1: inbox fences AS ROWS — the actual point of the SQL port: a poll served on replica A must fence the
|
|
464
|
+
// late notify landing on replica B (cross-replica). kind = served (per-runId) | purge (run_id='',
|
|
465
|
+
// session-wide; owner_known=0 → conservative fence-all). Swept opportunistically on every write verb.
|
|
356
466
|
`CREATE TABLE IF NOT EXISTS workflow_inbox_fence (
|
|
357
467
|
session_id VARCHAR(190) NOT NULL,
|
|
358
468
|
kind VARCHAR(8) NOT NULL,
|
|
@@ -363,6 +473,10 @@ export const SCHEMA_STATEMENTS = [
|
|
|
363
473
|
PRIMARY KEY (session_id, kind, run_id),
|
|
364
474
|
KEY idx_wffence_until (until_ms)
|
|
365
475
|
)`,
|
|
476
|
+
// 1.108 review fix (lens③ HIGH): the notify JOURNAL twin — under WORKFLOW_RUN_STORE=auto the run store +
|
|
477
|
+
// inbox were SQL but the notify journal stayed a replica-LOCAL File ledger, so a replica that died with an
|
|
478
|
+
// un-acked notify stranded it forever (at-least-once silently degraded to at-most-once across replica death).
|
|
479
|
+
// One row per STARTED run; acked flips on delivery; the recovery sweep on ANY replica walks acked=0.
|
|
366
480
|
`CREATE TABLE IF NOT EXISTS workflow_notify_journal (
|
|
367
481
|
run_id VARCHAR(191) NOT NULL,
|
|
368
482
|
scope VARCHAR(190) NOT NULL,
|
|
@@ -374,6 +488,13 @@ export const SCHEMA_STATEMENTS = [
|
|
|
374
488
|
PRIMARY KEY (run_id),
|
|
375
489
|
KEY idx_wfnotify_acked (acked)
|
|
376
490
|
)`,
|
|
491
|
+
// Outcome ledger (design/73 §7) — one row per graded task run, keyed by
|
|
492
|
+
// (task_signature, model). v1 is READ-ONLY (dashboard + offline-backtest source); it drives NO
|
|
493
|
+
// automatic policy change — that is flag-gated and must first pass an offline-backtest gate
|
|
494
|
+
// (council blocker 3 / major 7). The hard-signal split is structural, not a convention: `mechanical`
|
|
495
|
+
// columns (oracle/build/merge/cost/turns/route/replan) are the ONLY ones a future self-scheduler may
|
|
496
|
+
// read; `llm_assisted` (stuck/verifier) lives in its JSON blob, dashboard-only, never co-weighted.
|
|
497
|
+
// `outcome` is DERIVED from mechanical fields only (council blocker 1).
|
|
377
498
|
`CREATE TABLE IF NOT EXISTS outcome_ledger (
|
|
378
499
|
id VARCHAR(64) NOT NULL,
|
|
379
500
|
task_signature VARCHAR(190) NOT NULL,
|
|
@@ -402,6 +523,8 @@ export const SCHEMA_STATEMENTS = [
|
|
|
402
523
|
KEY idx_outcome (outcome),
|
|
403
524
|
KEY idx_created (created_at)
|
|
404
525
|
)`,
|
|
526
|
+
// sandbox-image-pool control API (IMAGE-API-DESIGN.md §1 / pool design §8). One row per image DIGEST (the
|
|
527
|
+
// immutable runtime ref); a queryable projection of build.sh's replay-sufficient manifest + the publish lifecycle.
|
|
405
528
|
`CREATE TABLE IF NOT EXISTS sandbox_image_index (
|
|
406
529
|
id VARCHAR(64) NOT NULL,
|
|
407
530
|
profile VARCHAR(64) NOT NULL,
|
|
@@ -430,6 +553,12 @@ export const SCHEMA_STATEMENTS = [
|
|
|
430
553
|
KEY idx_digest (digest),
|
|
431
554
|
KEY idx_tenant (tenant_id, status)
|
|
432
555
|
)`,
|
|
556
|
+
// sandbox-image-pool BAKE job (IMAGE-API-DESIGN.md §P2.6). A dedicated row table — NOT a reuse of task_run
|
|
557
|
+
// (FK-coupled to task_active + the run reaper + /v1/runs list; co-mingling bakes would leak non-task rows into
|
|
558
|
+
// reapStale/listRuns). The reader polls the COARSE 4-value `status` (queued|running|done|failed) for SSE
|
|
559
|
+
// terminality; build.sh's 8-value `state` is denormalized for the UI progress bar ONLY and must NOT drive
|
|
560
|
+
// terminality (P2.3 MUST-FIX — a non-terminal PUSHING/VERIFYING state would truncate the stream before `done`).
|
|
561
|
+
// `argv` is the VETTED, normalized build.sh argv the runner runs (operator free-text never reaches the runner).
|
|
433
562
|
`CREATE TABLE IF NOT EXISTS image_bake (
|
|
434
563
|
bake_id VARCHAR(64) NOT NULL,
|
|
435
564
|
profile VARCHAR(128) NOT NULL,
|
|
@@ -463,6 +592,11 @@ export const SCHEMA_STATEMENTS = [
|
|
|
463
592
|
KEY idx_status (status),
|
|
464
593
|
KEY idx_created (created_at)
|
|
465
594
|
)`,
|
|
595
|
+
// Per-bake replayable event log (P2.6) — run-trace event-log mechanics ((id,seq) PK, ++seq, getEvents(after),
|
|
596
|
+
// maxSeq, retainedFrom→416, heartbeat-not-persisted) WITHOUT the task_event FK coupling. image-api is the SOLE
|
|
597
|
+
// ++seq writer (seq monotonic from 1). `line_ord` is the runner's per-line ordinal — the at-least-once ingest
|
|
598
|
+
// dedupe key (uq_line): a re-sent (bakeId,line_ord) is a no-op (P2.10). `level='raw'` rows are the opt-in
|
|
599
|
+
// build.log tail (?logs=1), pruned on a tighter TTL + evicted first (P2.5/P2.9).
|
|
466
600
|
`CREATE TABLE IF NOT EXISTS image_bake_event (
|
|
467
601
|
bake_id VARCHAR(64) NOT NULL,
|
|
468
602
|
seq INT NOT NULL,
|
|
@@ -474,6 +608,9 @@ export const SCHEMA_STATEMENTS = [
|
|
|
474
608
|
PRIMARY KEY (bake_id, seq),
|
|
475
609
|
UNIQUE KEY uq_line (bake_id, line_ord)
|
|
476
610
|
)`,
|
|
611
|
+
// Single-flight build lease (P2.7, §9). ONE row per builder pool — image-api owns the authoritative lease so the
|
|
612
|
+
// one docker daemon never has two concurrent builds (a prune-behind-lock could evict layers an in-flight build
|
|
613
|
+
// needs). `expires_at` makes a crashed-runner lease stealable (CAS on expiry).
|
|
477
614
|
`CREATE TABLE IF NOT EXISTS image_bake_lease (
|
|
478
615
|
pool VARCHAR(32) NOT NULL DEFAULT 'standard',
|
|
479
616
|
bake_id VARCHAR(64) NOT NULL,
|
|
@@ -481,28 +618,52 @@ export const SCHEMA_STATEMENTS = [
|
|
|
481
618
|
expires_at DATETIME(3) NOT NULL,
|
|
482
619
|
PRIMARY KEY (pool)
|
|
483
620
|
)`,
|
|
621
|
+
// Admission sentinel: ONE always-present row per builder pool, `SELECT … FOR UPDATE`-locked to SERIALIZE the
|
|
622
|
+
// createBakeIfIdle busy-check+insert. A bare conditional INSERT…SELECT WHERE NOT EXISTS does NOT serialize two
|
|
623
|
+
// concurrent admissions under TiDB's REPEATABLE READ (nor PG's READ COMMITTED), so without this lock two keyless
|
|
624
|
+
// POSTs can both admit a non-dryRun bake. Dialect-uniform with the PG twin (pg-image-bake.ts).
|
|
484
625
|
`CREATE TABLE IF NOT EXISTS image_bake_admit (
|
|
485
626
|
pool VARCHAR(32) NOT NULL,
|
|
486
627
|
PRIMARY KEY (pool)
|
|
487
628
|
)`,
|
|
488
629
|
];
|
|
630
|
+
/** Named MySQL/TiDB advisory lock that serializes the whole `ensureSchema` DDL run (see below). */
|
|
489
631
|
export const ENSURE_SCHEMA_LOCK = "sema_ensure_schema";
|
|
632
|
+
/** Acquire {@link ENSURE_SCHEMA_LOCK} on `conn` (the lock is CONNECTION-level, so the caller MUST then run all the
|
|
633
|
+
* serialized work on this SAME connection and release with {@link releaseEnsureSchemaLock}). Returns whether it was
|
|
634
|
+
* acquired. Exported so test setup that does ad-hoc DDL (e.g. a DROP-then-recreate) can serialize against
|
|
635
|
+
* ensureSchema runs using the IDENTICAL lock.
|
|
636
|
+
*
|
|
637
|
+
* Under heavy concurrency (the integration suite fans ~20 callers at the SAME named lock; or a fleet boots N
|
|
638
|
+
* replicas at once) a BLOCKING GET_LOCK(name, 30) would park ~19 sessions in a pessimistic WAIT on TiDB's advisory-
|
|
639
|
+
* lock row — which both exhausts TiDB's "pessimistic lock retry limit" (surfacing as a thrown error) AND starves the
|
|
640
|
+
* app's OWN `SELECT … FOR UPDATE` paths (image-bake admission/lease) of pessimistic-lock budget. So we acquire
|
|
641
|
+
* NON-BLOCKING (GET_LOCK(name, 0) returns 0 immediately if held) and POLL with jittered backoff: one holder, the
|
|
642
|
+
* rest sleeping (not blocked in-DB). Return false only after exhausting retries (the caller then DEGRADES to
|
|
643
|
+
* unserialized rather than blocking boot forever — the DDL is still individually idempotent). */
|
|
490
644
|
export async function acquireEnsureSchemaLock(conn, tag = "ensureSchema") {
|
|
645
|
+
// Initial jitter so ~20 callers firing at t=0 (the integration fan-out, or a synchronized fleet boot) don't all
|
|
646
|
+
// hit the advisory-lock row in the same instant — that synchronized burst is what most provokes TiDB's pessimistic
|
|
647
|
+
// retry-limit. Spreading the first attempt over ~0.4s lets one win cleanly while the rest find it held and poll.
|
|
491
648
|
await new Promise((r) => setTimeout(r, Math.floor(Math.random() * 400)));
|
|
492
649
|
for (let attempt = 0; attempt < 40; attempt++) {
|
|
493
650
|
try {
|
|
494
651
|
const [rows] = await conn.query("SELECT GET_LOCK(?, 0) AS got", [ENSURE_SCHEMA_LOCK]);
|
|
495
652
|
if (Number(rows[0]?.got) === 1)
|
|
496
|
-
return true;
|
|
653
|
+
return true; // acquired (0 = currently held by someone else → poll again)
|
|
497
654
|
}
|
|
498
655
|
catch (err) {
|
|
656
|
+
// A non-blocking GET_LOCK should not normally throw, but TiDB can still surface transient pessimistic-lock
|
|
657
|
+
// contention here — tolerate it (log + keep polling); the DDL is idempotent so a degrade is at worst benign.
|
|
499
658
|
console.warn(`[${tag}] GET_LOCK('${ENSURE_SCHEMA_LOCK}') attempt ${attempt + 1}/40:`, err?.message ?? err);
|
|
500
659
|
}
|
|
660
|
+
// Jittered backoff (~0.1s..0.4s + up to 0.15s jitter) — capped so total worst-case wait ≈ 40 * 0.4s = 16s.
|
|
501
661
|
await new Promise((r) => setTimeout(r, 100 + Math.min(attempt, 3) * 100 + Math.floor(Math.random() * 150)));
|
|
502
662
|
}
|
|
503
663
|
console.warn(`[${tag}] could not acquire '${ENSURE_SCHEMA_LOCK}' after retries`);
|
|
504
664
|
return false;
|
|
505
665
|
}
|
|
666
|
+
/** Release {@link ENSURE_SCHEMA_LOCK} on `conn` (best-effort — the lock also auto-frees when the connection closes). */
|
|
506
667
|
export async function releaseEnsureSchemaLock(conn, tag = "ensureSchema") {
|
|
507
668
|
try {
|
|
508
669
|
await conn.query("SELECT RELEASE_LOCK(?)", [ENSURE_SCHEMA_LOCK]);
|
|
@@ -511,13 +672,32 @@ export async function releaseEnsureSchemaLock(conn, tag = "ensureSchema") {
|
|
|
511
672
|
console.warn(`[${tag}] RELEASE_LOCK('${ENSURE_SCHEMA_LOCK}') failed (lock auto-frees on connection close):`, err);
|
|
512
673
|
}
|
|
513
674
|
}
|
|
675
|
+
/** Create tables if absent (+ seed the image-bake admission sentinel). Safe to call on every startup.
|
|
676
|
+
*
|
|
677
|
+
* Per the SCHEMA POLICY on {@link SCHEMA_STATEMENTS} this is a pure CREATE run — there are NO additive
|
|
678
|
+
* ALTER/CREATE-INDEX seams and no information_schema probes any more (2026-07-26): the schema contract is
|
|
679
|
+
* drop-and-recreate, so every column / index / nullability lives in its `CREATE TABLE`. Do not reintroduce a
|
|
680
|
+
* migration loop here; change the CREATE and rebuild the database.
|
|
681
|
+
*
|
|
682
|
+
* Concurrency: callers run this concurrently — tests fan ALL integration suites out in parallel (each
|
|
683
|
+
* beforeAll calls ensureSchema), and in production every replica calls it at boot (`--scale service=4`).
|
|
684
|
+
* Concurrent DDL on the SAME table makes TiDB race in its schema catalog. We serialize the entire run
|
|
685
|
+
* behind {@link ENSURE_SCHEMA_LOCK} (a named GET_LOCK), which is CONNECTION-level — so the lock AND every
|
|
686
|
+
* DDL statement run on the one connection we hold here (pooled `pool.query` could land on a different
|
|
687
|
+
* connection and silently void the lock). The DDL semantics are unchanged; only the timing is serialized.
|
|
688
|
+
*/
|
|
514
689
|
export async function ensureSchema(pool) {
|
|
515
690
|
const conn = await pool.getConnection();
|
|
691
|
+
// Serialize the whole DDL run behind the named connection-level lock (see acquireEnsureSchemaLock). The first
|
|
692
|
+
// caller does the real CREATEs, the rest wait then find every statement already satisfied (IF NOT EXISTS ⇒ no-op)
|
|
693
|
+
// → no catalog race. On a degrade (lock unavailable after retries) the DDL runs unserialized but every statement
|
|
694
|
+
// is still individually idempotent.
|
|
516
695
|
const locked = await acquireEnsureSchemaLock(conn);
|
|
517
696
|
try {
|
|
518
697
|
for (const stmt of SCHEMA_STATEMENTS) {
|
|
519
698
|
await conn.query(stmt);
|
|
520
699
|
}
|
|
700
|
+
// Seed the always-present image-bake admission sentinel (idempotent) so createBakeIfIdle can FOR UPDATE-lock it.
|
|
521
701
|
await conn.query("INSERT IGNORE INTO image_bake_admit (pool) VALUES ('standard')");
|
|
522
702
|
}
|
|
523
703
|
finally {
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-replica per-key request rate limiter (design/30 P0-2) — a thin {@link RateGate} over the shared
|
|
3
|
+
* {@link WriteBehindCounter}. Like the in-memory {@link RateLimiter}, `check` both COUNTS the request
|
|
4
|
+
* and decides; here the count is summed fleet-wide via atomic write-behind aggregation.
|
|
5
|
+
*
|
|
6
|
+
* **SOFT limiting** (the WriteBehindCounter is eventually consistent): a replica may briefly admit a few
|
|
7
|
+
* requests over the ceiling at a window boundary before peers' counts propagate. That is fine for a
|
|
8
|
+
* fairness / hot-caller cap (the use case here). A HARD global cap would need a linearizable CAS, not
|
|
9
|
+
* write-behind — same trade as the cross-replica circuit breaker and cost quota.
|
|
10
|
+
*/
|
|
1
11
|
import type { Pool } from "mysql2/promise";
|
|
2
12
|
import type { RateDecision, RateGate } from "../observability/rate-limit.js";
|
|
3
13
|
import { type CounterDegradeHook } from "./write-behind-counter.js";
|
|
@@ -6,6 +16,7 @@ export declare class TiDBRateLimiter implements RateGate {
|
|
|
6
16
|
private readonly counter;
|
|
7
17
|
constructor(pool: Pool, limit: number, windowMs?: number, now?: () => number, onDegraded?: CounterDegradeHook, queryTimeoutMs?: number);
|
|
8
18
|
check(key: string): RateDecision;
|
|
19
|
+
/** The flush loop self-reaps old windows; the periodic sweeper has nothing to do for this backend. */
|
|
9
20
|
sweep(): void;
|
|
10
21
|
flush(): Promise<void>;
|
|
11
22
|
refresh(): Promise<void>;
|
|
@@ -9,14 +9,17 @@ export class TiDBRateLimiter {
|
|
|
9
9
|
check(key) {
|
|
10
10
|
if (this.limit <= 0)
|
|
11
11
|
return { allowed: true, retryAfterSec: 0, remaining: Number.POSITIVE_INFINITY };
|
|
12
|
-
const usedBefore = this.counter.used(key);
|
|
13
|
-
this.counter.addLocal(key, 1);
|
|
12
|
+
const usedBefore = this.counter.used(key); // fleet (last refresh) + local pending — soft/eventually consistent
|
|
13
|
+
this.counter.addLocal(key, 1); // count every request, like the in-memory limiter
|
|
14
14
|
return usedBefore < this.limit
|
|
15
15
|
? { allowed: true, retryAfterSec: 0, remaining: this.limit - usedBefore - 1 }
|
|
16
16
|
: { allowed: false, retryAfterSec: Math.max(1, this.counter.retryAfterSec()), remaining: 0 };
|
|
17
17
|
}
|
|
18
|
+
/** The flush loop self-reaps old windows; the periodic sweeper has nothing to do for this backend. */
|
|
18
19
|
sweep() {
|
|
20
|
+
/* no-op */
|
|
19
21
|
}
|
|
22
|
+
// write-behind lifecycle (delegated; exposed for tests/parity)
|
|
20
23
|
flush() {
|
|
21
24
|
return this.counter.flush();
|
|
22
25
|
}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编) — the real implementation moved to the single-file
|
|
3
|
+
* dual-dialect `resume-anchor-store-sql.ts` (shared with the PG twin via `SqlDriver`). Kept so
|
|
4
|
+
* consumers importing this path (store-backend.ts, the resume-anchor integration suite) don't move.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBResumeAnchorStore } from "./resume-anchor-store-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-resume-anchor-store.d.ts.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编) — the real implementation moved to the single-file
|
|
3
|
+
* dual-dialect `resume-anchor-store-sql.ts` (shared with the PG twin via `SqlDriver`). Kept so
|
|
4
|
+
* consumers importing this path (store-backend.ts, the resume-anchor integration suite) don't move.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBResumeAnchorStore } from "./resume-anchor-store-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-resume-anchor-store.js.map
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 定型半场 collapse): the real implementation now lives in
|
|
3
|
+
* `run-store-sql.ts` (single-file dual-dialect — TiDB + PG share one `SqlRunStore` body, dialect deltas
|
|
4
|
+
* kept EXPLICIT per statement). `TiDBRunStore`'s class name/ctor arity/exported types are unchanged so
|
|
5
|
+
* every existing consumer (store-backend.ts, src/index.ts, the run/reaper/session/usage suites) needs
|
|
6
|
+
* ZERO changes. New code should import from `run-store-sql.ts` directly.
|
|
7
|
+
*/
|
|
1
8
|
export { TiDBRunStore } from "./run-store-sql.js";
|
|
2
9
|
export type { RunRecord, SessionSummary, RunEvent } from "./store-contracts.js";
|
|
3
10
|
//# sourceMappingURL=tidb-run-store.d.ts.map
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 定型半场 collapse): the real implementation now lives in
|
|
3
|
+
* `run-store-sql.ts` (single-file dual-dialect — TiDB + PG share one `SqlRunStore` body, dialect deltas
|
|
4
|
+
* kept EXPLICIT per statement). `TiDBRunStore`'s class name/ctor arity/exported types are unchanged so
|
|
5
|
+
* every existing consumer (store-backend.ts, src/index.ts, the run/reaper/session/usage suites) needs
|
|
6
|
+
* ZERO changes. New code should import from `run-store-sql.ts` directly.
|
|
7
|
+
*/
|
|
1
8
|
export { TiDBRunStore } from "./run-store-sql.js";
|
|
2
9
|
//# sourceMappingURL=tidb-run-store.js.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编) — the real implementation lives in the single-file
|
|
3
|
+
* dual-dialect `session-policy-store-sql.ts` (`SqlSessionPolicyStore` + this file's historical
|
|
4
|
+
* `TiDBSessionPolicyStore` ctor subclass). Kept so every consumer's import path is untouched.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBSessionPolicyStore } from "./session-policy-store-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-session-policy-store.d.ts.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编) — the real implementation lives in the single-file
|
|
3
|
+
* dual-dialect `session-policy-store-sql.ts` (`SqlSessionPolicyStore` + this file's historical
|
|
4
|
+
* `TiDBSessionPolicyStore` ctor subclass). Kept so every consumer's import path is untouched.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBSessionPolicyStore } from "./session-policy-store-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-session-policy-store.js.map
|
|
@@ -1,17 +1,60 @@
|
|
|
1
1
|
import { BaseSessionStorage, type PromptEpochDescriptor, type SessionMetadata, type SessionTreeEntry, type SessionWriteOptions } from "@sema-agent/core";
|
|
2
2
|
import type { Pool } from "mysql2/promise";
|
|
3
|
+
/**
|
|
4
|
+
* TiDB-backed {@link BaseSessionStorage} — the durable L1 event log for one session.
|
|
5
|
+
*
|
|
6
|
+
* - `appendEntry` / `setLeafId` persist with an **atomic compare-and-set** on `leaf_seq` + `leaf_id`
|
|
7
|
+
* (core's F2 optimistic-lock seam): a write only lands if the branch leaf is still what the entry
|
|
8
|
+
* was built against. Two stateless runners that both woke the same session can't silently fork —
|
|
9
|
+
* the loser gets `SessionError("conflict")` (catch with `isSessionConflict`).
|
|
10
|
+
* - The in-memory base tree is the wake-time snapshot; every write is also mirrored into it so the
|
|
11
|
+
* live harness keeps reading a consistent view. Wake is **bounded** to `[floor .. leaf]` (F3,
|
|
12
|
+
* core 1.6.0 branch-floor seam); older history is covered by the last compaction's summary.
|
|
13
|
+
*/
|
|
3
14
|
export declare class TiDBSessionStorage extends BaseSessionStorage {
|
|
4
15
|
private readonly pool;
|
|
5
16
|
private readonly sessionId;
|
|
6
17
|
private leafSeq;
|
|
7
18
|
private readonly floorSeq;
|
|
8
19
|
constructor(pool: Pool, sessionId: string, metadata: SessionMetadata, entries: SessionTreeEntry[], leafId: string | null, leafSeq: number, floorEntryId?: string | null, floorSeq?: number);
|
|
20
|
+
/**
|
|
21
|
+
* [976] S3 RB-14 pull seam — `SessionStorage.getEpochAnchor?()`: the nearest epoch carrier BELOW the
|
|
22
|
+
* bounded-wake floor. core's `Session.getPromptEpoch()` (≥1.305) calls this only when the in-window
|
|
23
|
+
* branch walk finds no carrier — i.e. a rewind/resumeAt cut inside the kept tail, where the compaction
|
|
24
|
+
* restatement is a DESCENDANT of the cut and the root pin sits under the floor. Semantics per core's
|
|
25
|
+
* ruling: highest-seq valid carrier below the floor (not an ancestor-chain walk — fallback of last
|
|
26
|
+
* resort); malformed rows are skipped (#13: fall back to the older valid pin — the write gate refuses
|
|
27
|
+
* malformed carriers, so these only exist via out-of-band writes); none ⇒ undefined = a genuine
|
|
28
|
+
* pre-epoch session (core mints legacy_migration, the correct meaning). core re-normalizes whatever we
|
|
29
|
+
* return, so this stays honest even if the two sides ever disagree on strictness.
|
|
30
|
+
*/
|
|
9
31
|
getEpochAnchor(): Promise<PromptEpochDescriptor | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Rebuild a session from its event log (= wake). Returns null if the session does not exist.
|
|
34
|
+
*
|
|
35
|
+
* F3 bounded load: only `[floor .. leaf]` is read, where floor = the last compaction's
|
|
36
|
+
* `firstKeptEntryId` (everything older is represented by that compaction's summary, so it never
|
|
37
|
+
* enters context). No compaction yet → floor=null → full load (the session is still short).
|
|
38
|
+
*
|
|
39
|
+
* This is the durable, bounded-READ equivalent of core's `boundedTail(pathEntries)` (1.42.0): that
|
|
40
|
+
* helper trims a FULL-loaded path in memory, whereas we compute the floor seq first and only `SELECT
|
|
41
|
+
* seq >= floorSeq` — so the head never leaves cold storage. Our sessions are LINEAR (no fork), so
|
|
42
|
+
* seq-order == root→leaf path-order and our `seq >= floorSeq` tail is byte-identical to
|
|
43
|
+
* `boundedTail(path).tail`; the resulting floored `BaseSessionStorage.buildContext()` matches a
|
|
44
|
+
* full-tree wake (core's `session-floor.test.ts`). If branching is ever added, switch to `boundedTail`.
|
|
45
|
+
*/
|
|
10
46
|
static wake(pool: Pool, sessionId: string): Promise<TiDBSessionStorage | null>;
|
|
47
|
+
/** The bounded-window floor = last compaction's firstKeptEntryId (and its seq). */
|
|
11
48
|
private static computeFloor;
|
|
49
|
+
/** Sub-floor lookups (e.g. a label target) aren't in the loaded tail — fall back to the durable log. */
|
|
12
50
|
getEntry(id: string): Promise<SessionTreeEntry | undefined>;
|
|
13
51
|
appendEntry(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
|
|
14
52
|
setLeafId(leafId: string | null, opts?: SessionWriteOptions): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Atomically: CAS the meta leaf (+bump leaf_seq), then append the event at the new seq.
|
|
55
|
+
* The `(session_id, seq)` primary key is the backstop — a racing writer that grabbed the same
|
|
56
|
+
* seq makes our INSERT fail with a duplicate-key, which we translate to a conflict too.
|
|
57
|
+
*/
|
|
15
58
|
private persist;
|
|
16
59
|
}
|
|
17
60
|
//# sourceMappingURL=tidb-session-storage.d.ts.map
|