@sema-agent/server 1.322.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 +59 -3
- 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,7 @@
|
|
|
1
1
|
export const TASK_ATTACHMENT_TABLE = "task_attachment";
|
|
2
|
+
/** 物化相对路径(确定性,notice 与真实写盘共用一份推导——两处各算一遍会漂):按 listBySession 序
|
|
3
|
+
* (created_at_ms, id)分配 `attachments/<name>`;同名撞车时后者前缀 id 头 8 位。名字在上传时已
|
|
4
|
+
* 消毒为安全 basename([A-Za-z0-9._-]),拼接后仍是安全相对路径。 */
|
|
2
5
|
export function materializedRelPaths(atts) {
|
|
3
6
|
const used = new Set();
|
|
4
7
|
const out = new Map();
|
|
@@ -23,6 +26,9 @@ function rowToRecord(r) {
|
|
|
23
26
|
...(r.bound_at_ms !== null && r.bound_at_ms !== undefined ? { boundAtMs: Number(r.bound_at_ms) } : {}),
|
|
24
27
|
};
|
|
25
28
|
}
|
|
29
|
+
/** 半场②(提交时绑定 + objective 告知)的可测核。fresh 腿硬验证(未知/他人 id → throw(mapTo400));
|
|
30
|
+
* resume 腿降级(warn+跳过——4xx 会砖存量 task;记录不可变 ⇒ 在场行的 notice 字节恒稳)。
|
|
31
|
+
* notice 路径从**绑定后的全 session 集**推导(与物化共用 materializedRelPaths),只罗列本次引用的文件。 */
|
|
26
32
|
export async function bindAttachmentsForTask(opts) {
|
|
27
33
|
const found = [];
|
|
28
34
|
for (const id of opts.ids) {
|
|
@@ -41,6 +47,8 @@ export async function bindAttachmentsForTask(opts) {
|
|
|
41
47
|
const lines = found.map((r) => `- ${paths.get(r.id) ?? `attachments/${r.name}`} (${r.mime}, ${r.sizeBytes} bytes)`);
|
|
42
48
|
return { notice: `[attachments] ${found.length} uploaded file(s) are available in the \`attachments/\` directory of your working directory:\n${lines.join("\n")}` };
|
|
43
49
|
}
|
|
50
|
+
/** 半场③(env 建立时物化)的可测核。**fail-loud**:objective 已宣告文件在场,静默缺文件=模型按幻影
|
|
51
|
+
* 文件行动,比 env 建立失败更糟 ⇒ 任一写失败即 throw。幂等:重建沙箱/resume 重写同路径同字节。 */
|
|
44
52
|
export async function materializeAttachmentsInto(env, store, sessionId) {
|
|
45
53
|
const atts = await store.listBySession(sessionId);
|
|
46
54
|
if (atts.length === 0)
|
|
@@ -94,6 +102,7 @@ export async function ensurePgTaskAttachmentSchema(q) {
|
|
|
94
102
|
await q(`CREATE INDEX IF NOT EXISTS idx_att_session ON ${TASK_ATTACHMENT_TABLE} (session_id)`);
|
|
95
103
|
await q(`CREATE INDEX IF NOT EXISTS idx_att_unbound ON ${TASK_ATTACHMENT_TABLE} (created_at_ms)`);
|
|
96
104
|
}
|
|
105
|
+
/** bytes → 4 MiB 块序列(共享切块器,两方言 + 完整性校验共用)。 */
|
|
97
106
|
export class TiDBTaskAttachmentStore {
|
|
98
107
|
pool;
|
|
99
108
|
bytes;
|
|
@@ -102,6 +111,8 @@ export class TiDBTaskAttachmentStore {
|
|
|
102
111
|
this.bytes = bytes;
|
|
103
112
|
}
|
|
104
113
|
async put(rec) {
|
|
114
|
+
// 次序=bytes 先、meta 后:meta 行在场 ⇒ 对象在场(读侧无半态)。对象键=sha256(去重;
|
|
115
|
+
// MinioBlobBackend putBlob 幂等,重复内容=同键重放)。半途崩溃只留无 meta 的对象——经 API 不可达。
|
|
105
116
|
await this.bytes.putBlob(rec.sha256, rec.content);
|
|
106
117
|
await this.pool.execute(`INSERT INTO ${TASK_ATTACHMENT_TABLE} (${COLS}) VALUES (?,?,?,?,?,?,?,?,?)`, [rec.id, rec.owner, rec.name, rec.mime, rec.sha256, rec.sizeBytes, rec.sessionId ?? null, rec.createdAtMs, rec.boundAtMs ?? null]);
|
|
107
118
|
}
|
|
@@ -110,12 +121,15 @@ export class TiDBTaskAttachmentStore {
|
|
|
110
121
|
return rows.length ? rowToRecord(rows[0]) : null;
|
|
111
122
|
}
|
|
112
123
|
async getContent(owner, id) {
|
|
113
|
-
const meta = await this.get(owner, id);
|
|
124
|
+
const meta = await this.get(owner, id); // owner 门先过(对象键是 sha,不携 owner——门恒在 meta)
|
|
114
125
|
if (!meta)
|
|
115
126
|
return null;
|
|
116
|
-
const b = await this.bytes.getBlob(meta.sha256);
|
|
127
|
+
const b = await this.bytes.getBlob(meta.sha256); // 实现内含 sha 校验(损坏/污染 ⇒ undefined)
|
|
117
128
|
return b && b.byteLength === meta.sizeBytes ? b : null;
|
|
118
129
|
}
|
|
130
|
+
/** 零引用对象删除(best-effort):meta 已删后,sha 仍被其他行引用则对象保留(跨行去重共享)。
|
|
131
|
+
* 失败只吞不抛——E21 purge 不被对象存储抖动卡死(blob-backend 异步删裁定同旨);无 meta 的对象
|
|
132
|
+
* 经 API 不可达,彻底清收敛记 follow-up。 */
|
|
119
133
|
async deleteBytesIfUnreferenced(shas) {
|
|
120
134
|
for (const sha of new Set(shas)) {
|
|
121
135
|
try {
|
|
@@ -124,6 +138,7 @@ export class TiDBTaskAttachmentStore {
|
|
|
124
138
|
await this.bytes.deleteBlobs([sha]);
|
|
125
139
|
}
|
|
126
140
|
catch {
|
|
141
|
+
/* best-effort(见上) */
|
|
127
142
|
}
|
|
128
143
|
}
|
|
129
144
|
}
|
|
@@ -159,10 +174,17 @@ export class TiDBTaskAttachmentStore {
|
|
|
159
174
|
await this.deleteBytesIfUnreferenced(rows.map((r) => r.sha256));
|
|
160
175
|
return res.affectedRows ?? 0;
|
|
161
176
|
}
|
|
177
|
+
/** D-1 孤儿对象彻底 GC(clay 拍 2026-07-28):对象存储列举 × meta 行对账。判据保守三层:
|
|
178
|
+
* ①只删**真列举到**且 ②零 meta 行引用 且 ③LastModified 过 grace 的对象(上传先行窗口:对象先落、
|
|
179
|
+
* meta 行后写——grace 护住 put 竞态,宁漏勿误删,下轮再收);列举失败=整轮 throw(调用方 catch,
|
|
180
|
+
* 「列不出来」绝不当「没有孤儿」)。 */
|
|
162
181
|
async sweepOrphanObjects(graceMs, nowMs = Date.now()) {
|
|
163
182
|
const lister = this.bytes;
|
|
164
183
|
if (typeof lister.listObjects !== "function")
|
|
165
|
-
return 0;
|
|
184
|
+
return 0; // 无列举面=无孤儿类(local/桩)
|
|
185
|
+
// 🔴 复审 F2:**边列举边消费**——grace 判据是「对象年龄」不是「孤儿性」,稳态下整个存量语料
|
|
186
|
+
// (凡超过 grace)都会先进候选集;攒满再分批 ⇒ 内存与语料同阶(20 万对象实测堆 Δ58MB,百万级
|
|
187
|
+
// ≈290MB,且每 tick 每副本各一份)。改成满 200 就消费,峰值降到 O(200)。
|
|
166
188
|
let removed = 0;
|
|
167
189
|
let batch = [];
|
|
168
190
|
const flush = async () => {
|
|
@@ -170,6 +192,11 @@ export class TiDBTaskAttachmentStore {
|
|
|
170
192
|
return;
|
|
171
193
|
const referenced = await this.referencedShas(batch);
|
|
172
194
|
const orphans = batch.filter((h) => !referenced.has(h));
|
|
195
|
+
// 🔴 复审 B-F1(数据安全):**删前逐对象复查**。grace 只在列举时刻判过一次,而
|
|
196
|
+
// 「referencedShas 判零引用 → deleteBlobs」之间落地的同 sha 上传(内容去重 ⇒ 同 key)会让
|
|
197
|
+
// meta 行在场而对象被本轮删掉 = 永久丢字节(getContent 恒 null、物化 fail-loud)。put 会 PUT
|
|
198
|
+
// 同键刷新 LastModified,所以删前再 HEAD 一次即可识别;窗口压到 HEAD→DELETE 毫秒级。
|
|
199
|
+
// 无 headObject 面 ⇒ 保守**不删**(宁留孤儿不误删)。
|
|
173
200
|
const safe = await this.filterStillOrphan(orphans, graceMs, nowMs);
|
|
174
201
|
if (safe.length > 0)
|
|
175
202
|
removed += await this.bytes.deleteBlobs(safe);
|
|
@@ -185,6 +212,7 @@ export class TiDBTaskAttachmentStore {
|
|
|
185
212
|
await flush();
|
|
186
213
|
return removed;
|
|
187
214
|
}
|
|
215
|
+
/** sweep 的引用对账半场:批内 sha 中仍有 meta 行的子集(单 IN 查询;DISTINCT 免重复行膨胀)。 */
|
|
188
216
|
async referencedShas(shas) {
|
|
189
217
|
if (shas.length === 0)
|
|
190
218
|
return new Set();
|
|
@@ -192,6 +220,8 @@ export class TiDBTaskAttachmentStore {
|
|
|
192
220
|
const [rows] = await this.pool.query(`SELECT DISTINCT sha256 FROM ${TASK_ATTACHMENT_TABLE} WHERE sha256 IN (${ph})`, shas);
|
|
193
221
|
return new Set(rows.map((r) => String(r.sha256)));
|
|
194
222
|
}
|
|
223
|
+
/** 删前复查(复审 B-F1):只保留「HEAD 仍在 且 LastModified 仍过 grace」的 hash。无 headObject
|
|
224
|
+
* 面 ⇒ 返回空集(保守不删);HEAD 抛错 ⇒ 该对象本轮跳过(下轮再收)。 */
|
|
195
225
|
async filterStillOrphan(hashes, graceMs, nowMs) {
|
|
196
226
|
if (hashes.length === 0)
|
|
197
227
|
return [];
|
|
@@ -206,6 +236,7 @@ export class TiDBTaskAttachmentStore {
|
|
|
206
236
|
out.push(h);
|
|
207
237
|
}
|
|
208
238
|
catch {
|
|
239
|
+
/* 复查失败=本轮跳过(宁漏勿误删) */
|
|
209
240
|
}
|
|
210
241
|
}
|
|
211
242
|
return out;
|
|
@@ -219,6 +250,7 @@ export class PgTaskAttachmentStore {
|
|
|
219
250
|
this.bytes = bytes;
|
|
220
251
|
}
|
|
221
252
|
async put(rec) {
|
|
253
|
+
// bytes 先、meta 后(TiDB 同姿,注同)
|
|
222
254
|
await this.bytes.putBlob(rec.sha256, rec.content);
|
|
223
255
|
await this.q(`INSERT INTO ${TASK_ATTACHMENT_TABLE} (${COLS}) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`, [rec.id, rec.owner, rec.name, rec.mime, rec.sha256, rec.sizeBytes, rec.sessionId ?? null, rec.createdAtMs, rec.boundAtMs ?? null]);
|
|
224
256
|
}
|
|
@@ -241,12 +273,14 @@ export class PgTaskAttachmentStore {
|
|
|
241
273
|
await this.bytes.deleteBlobs([sha]);
|
|
242
274
|
}
|
|
243
275
|
catch {
|
|
276
|
+
/* best-effort(TiDB 同注) */
|
|
244
277
|
}
|
|
245
278
|
}
|
|
246
279
|
}
|
|
247
280
|
async bind(owner, ids, sessionId, boundAtMs) {
|
|
248
281
|
if (ids.length === 0)
|
|
249
282
|
return 0;
|
|
283
|
+
// PgQueryFn 有意无 rowCount(pg-query.ts 契约)⇒ RETURNING id 数行
|
|
250
284
|
const res = await this.q(`UPDATE ${TASK_ATTACHMENT_TABLE} SET session_id = $1, bound_at_ms = $2 WHERE owner = $3 AND id = ANY($4::varchar[]) RETURNING id`, [sessionId, boundAtMs, owner, ids]);
|
|
251
285
|
return res.rows.length;
|
|
252
286
|
}
|
|
@@ -271,10 +305,14 @@ export class PgTaskAttachmentStore {
|
|
|
271
305
|
await this.deleteBytesIfUnreferenced(res.rows.map((r) => r.sha256));
|
|
272
306
|
return res.rows.length;
|
|
273
307
|
}
|
|
308
|
+
/** D-1 孤儿对象彻底 GC —— twin of the TiDB store(判据三层同注:真列举/零引用/过 grace)。 */
|
|
274
309
|
async sweepOrphanObjects(graceMs, nowMs = Date.now()) {
|
|
275
310
|
const lister = this.bytes;
|
|
276
311
|
if (typeof lister.listObjects !== "function")
|
|
277
312
|
return 0;
|
|
313
|
+
// 🔴 复审 F2:**边列举边消费**——grace 判据是「对象年龄」不是「孤儿性」,稳态下整个存量语料
|
|
314
|
+
// (凡超过 grace)都会先进候选集;攒满再分批 ⇒ 内存与语料同阶(20 万对象实测堆 Δ58MB,百万级
|
|
315
|
+
// ≈290MB,且每 tick 每副本各一份)。改成满 200 就消费,峰值降到 O(200)。
|
|
278
316
|
let removed = 0;
|
|
279
317
|
let batch = [];
|
|
280
318
|
const flush = async () => {
|
|
@@ -282,6 +320,11 @@ export class PgTaskAttachmentStore {
|
|
|
282
320
|
return;
|
|
283
321
|
const referenced = await this.referencedShas(batch);
|
|
284
322
|
const orphans = batch.filter((h) => !referenced.has(h));
|
|
323
|
+
// 🔴 复审 B-F1(数据安全):**删前逐对象复查**。grace 只在列举时刻判过一次,而
|
|
324
|
+
// 「referencedShas 判零引用 → deleteBlobs」之间落地的同 sha 上传(内容去重 ⇒ 同 key)会让
|
|
325
|
+
// meta 行在场而对象被本轮删掉 = 永久丢字节(getContent 恒 null、物化 fail-loud)。put 会 PUT
|
|
326
|
+
// 同键刷新 LastModified,所以删前再 HEAD 一次即可识别;窗口压到 HEAD→DELETE 毫秒级。
|
|
327
|
+
// 无 headObject 面 ⇒ 保守**不删**(宁留孤儿不误删)。
|
|
285
328
|
const safe = await this.filterStillOrphan(orphans, graceMs, nowMs);
|
|
286
329
|
if (safe.length > 0)
|
|
287
330
|
removed += await this.bytes.deleteBlobs(safe);
|
|
@@ -304,6 +347,8 @@ export class PgTaskAttachmentStore {
|
|
|
304
347
|
const r = await this.q(`SELECT DISTINCT sha256 FROM ${TASK_ATTACHMENT_TABLE} WHERE sha256 IN (${ph})`, shas);
|
|
305
348
|
return new Set(r.rows.map((row) => String(row.sha256)));
|
|
306
349
|
}
|
|
350
|
+
/** 删前复查(复审 B-F1):只保留「HEAD 仍在 且 LastModified 仍过 grace」的 hash。无 headObject
|
|
351
|
+
* 面 ⇒ 返回空集(保守不删);HEAD 抛错 ⇒ 该对象本轮跳过(下轮再收)。 */
|
|
307
352
|
async filterStillOrphan(hashes, graceMs, nowMs) {
|
|
308
353
|
if (hashes.length === 0)
|
|
309
354
|
return [];
|
|
@@ -318,6 +363,7 @@ export class PgTaskAttachmentStore {
|
|
|
318
363
|
out.push(h);
|
|
319
364
|
}
|
|
320
365
|
catch {
|
|
366
|
+
/* 复查失败=本轮跳过(宁漏勿误删) */
|
|
321
367
|
}
|
|
322
368
|
}
|
|
323
369
|
return out;
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TaskListStore SQL twins(design/151 S3c server pg 半场,[1530] 提货单②)——core 团队共享任务
|
|
3
|
+
* 清单(TaskCreate/TaskUpdate/TaskList 工具族)的 TiDB/PG 双方言实现。挂载缝 = S3c 行为车定
|
|
4
|
+
* (createTaskListTools(store) 已收 store 参数);本文件先就绪 store 半场。
|
|
5
|
+
*
|
|
6
|
+
* 语义真源 = core file 实现(dist/stores/file/task-list-store.js,durable 对 durable)+ [1530] 定谳:
|
|
7
|
+
* 1. **`mutate` 必须后端事务原子**(接口 JSDoc codex S4 F2 句):read-modify-write 全序列进一个
|
|
8
|
+
* 事务;分区锁 = meta 行 `SELECT … FOR UPDATE`(天然 advisory lock,同清单 mutate 串行)。
|
|
9
|
+
* 2. **nextId 只增不回退、与分配同事务**(删最高 id 不复用):`task_list_meta` 单行携 `next_id`,
|
|
10
|
+
* **永不从存量 MAX 派生**。
|
|
11
|
+
* 3. metadata = JSON 列(`assertJsonMetadata` 在 set 面拦,file/memory 同形);id 任意 string
|
|
12
|
+
* (工具层走 allocateId 产数字串,接口不排除外部 id)。
|
|
13
|
+
*
|
|
14
|
+
* `list` 序:两个 core 参照本就不同(memory=Map 纯插入序;file=JS 对象序 = integer-like 键数字
|
|
15
|
+
* 升序、其余按插入序殿后)——SQL twin 对齐 **file 形**(durable 参照):`id_num` 物化列(canonical
|
|
16
|
+
* array-index 形才非 NULL)数字升序,非数字 id 按 `sort_seq`(插入序)殿后。set 覆盖已有 id 保位
|
|
17
|
+
* (sort_seq 不变)= 两参照一致的保位语义。`sort_seq` 从 **meta 行计数器同事务分配**(复审 F6:
|
|
18
|
+
* TiDB AUTO_INCREMENT 按 tidb-server 分段缓存,跨节点不单调——「插入序」在多网关部署下会倒序;
|
|
19
|
+
* meta 计数器 = allocateId 同姿势,真单调;覆盖写浪费一个号,单调性无损)。
|
|
20
|
+
*
|
|
21
|
+
* 分区键 `listKey` = 构造参数(file 形的 root 目录对位):谁的清单由挂载点决定(per-team 组装,
|
|
22
|
+
* S3c 行为车),store 层只管字节隔离(VARBINARY / COLLATE "C",roster F2 案)。PG unstorable
|
|
23
|
+
* bytes([1439]):item 正文(subject/description/metadata)= 内容面 lossy(pgSafeJsonStringify,
|
|
24
|
+
* U+FFFD);**身份键 listKey/id 拒绝式**(清洗形变 = 行与查询键错位)。TiDB verbatim。
|
|
25
|
+
*/
|
|
1
26
|
import type { Pool as MySqlPool } from "mysql2/promise";
|
|
2
27
|
import type { Pool as PgPool } from "pg";
|
|
3
28
|
import { type TaskListStore } from "@sema-agent/core";
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
// assertJsonMetadata:core 1.374 起包根导出([1531]§一3——私拷镜像即换,DURABLE_AGENT_HANDLE_RE 同姿势)。
|
|
1
2
|
import { assertJsonMetadata } from "@sema-agent/core";
|
|
2
3
|
import { pgHasUnstorable, pgSafeJsonStringify, PgUnstorableError } from "./pg-safe-json.js";
|
|
3
4
|
export const TASK_LIST_META_TABLE = "task_list_meta";
|
|
4
5
|
export const TASK_LIST_ITEMS_TABLE = "task_list_items";
|
|
6
|
+
/** JS 对象 integer-like(array-index)键判別——file 参照的遍历序里数字升序的那一族:canonical
|
|
7
|
+
* 十进制、0 ≤ n < 2^32-1。"01"/"1e3"/负数/超界 = 普通串键(插入序殿后)。 */
|
|
5
8
|
function arrayIndexOf(id) {
|
|
6
9
|
if (!/^(0|[1-9][0-9]*)$/.test(id))
|
|
7
10
|
return null;
|
|
@@ -11,12 +14,16 @@ function arrayIndexOf(id) {
|
|
|
11
14
|
function parseItem(v) {
|
|
12
15
|
return JSON.parse(String(v));
|
|
13
16
|
}
|
|
17
|
+
/** 键长守卫(mailbox twin F5 同案):TiDB `INSERT IGNORE` 对超 190 字节键静默截断——截断 listKey
|
|
18
|
+
* 与全长查询参数字节比对恒 miss(mutate 拿不到分区锁 = 无锁运行)。构造点一次拒清。item 的 id
|
|
19
|
+
* 列超长走非 IGNORE 语句 = 两方言原生 fail-loud,无需前置守卫。 */
|
|
14
20
|
function assertListKeyBytes(listKey) {
|
|
15
21
|
if (Buffer.byteLength(listKey, "utf8") > 190) {
|
|
16
22
|
throw new Error(`TaskListStore: listKey exceeds the 190-byte key column (refusing — a truncated key would desync from its byte-exact lookups)`);
|
|
17
23
|
}
|
|
18
24
|
}
|
|
19
25
|
export async function ensureTiDBTaskListSchema(pool) {
|
|
26
|
+
// next_sort = sort_seq 计数器(F6:不用 AUTO_INCREMENT——TiDB 分段缓存跨节点不单调)。
|
|
20
27
|
await pool.query(`CREATE TABLE IF NOT EXISTS ${TASK_LIST_META_TABLE} (
|
|
21
28
|
list_key VARBINARY(190) NOT NULL,
|
|
22
29
|
next_id BIGINT NOT NULL,
|
|
@@ -48,11 +55,14 @@ export async function ensurePgTaskListSchema(q) {
|
|
|
48
55
|
PRIMARY KEY (list_key, id)
|
|
49
56
|
)`);
|
|
50
57
|
}
|
|
58
|
+
/** meta 行 ensure(ensure-first 形:先幂等 INSERT 再 FOR UPDATE——「无行 FOR UPDATE + INSERT」的
|
|
59
|
+
* 经典并发死锁/dup 撞车形整个消掉;mutate 已持 meta 行锁时重入 = 同事务无害)。 */
|
|
51
60
|
async function ensureMeta(exec, dialect, listKey) {
|
|
52
61
|
await exec(dialect === "tidb"
|
|
53
62
|
? `INSERT IGNORE INTO ${TASK_LIST_META_TABLE} (list_key, next_id, next_sort) VALUES (?, 1, 1)`
|
|
54
63
|
: `INSERT INTO ${TASK_LIST_META_TABLE} (list_key, next_id, next_sort) VALUES ($1, 1, 1) ON CONFLICT (list_key) DO NOTHING`, [listKey]);
|
|
55
64
|
}
|
|
65
|
+
/** 事务内的 nextId 分配(定谳 2:与分配同事务、永不 MAX 派生)。 */
|
|
56
66
|
async function allocateOn(exec, dialect, listKey) {
|
|
57
67
|
await ensureMeta(exec, dialect, listKey);
|
|
58
68
|
const rows = await exec(dialect === "tidb"
|
|
@@ -64,6 +74,8 @@ async function allocateOn(exec, dialect, listKey) {
|
|
|
64
74
|
: `UPDATE ${TASK_LIST_META_TABLE} SET next_id = $1 WHERE list_key = $2`, [id + 1, listKey]);
|
|
65
75
|
return String(id);
|
|
66
76
|
}
|
|
77
|
+
/** 事务内的 set(F6:sort_seq 从 meta 计数器分配,与写同事务——meta 行锁顺带把同清单写串行;
|
|
78
|
+
* 覆盖写时 ON DUPLICATE/CONFLICT 不动 sort_seq(保位),浪费的号只增不回,单调性无损)。 */
|
|
67
79
|
async function setOn(exec, dialect, listKey, id, itemJson) {
|
|
68
80
|
await ensureMeta(exec, dialect, listKey);
|
|
69
81
|
const rows = await exec(dialect === "tidb"
|
|
@@ -101,6 +113,9 @@ export function createTiDBTaskListStore(pool, listKey) {
|
|
|
101
113
|
const [rows] = (await q.query(sql, params));
|
|
102
114
|
return rows;
|
|
103
115
|
};
|
|
116
|
+
// mutate 事务内的读必须**当前读**(FOR UPDATE):TiDB 悲观事务的普通 SELECT 按 start_ts 快照读
|
|
117
|
+
// (事务开始时点)——分区锁串行后普通读仍看见开锁前的旧值,read-modify-write 静默丢更新(真双库
|
|
118
|
+
// 套件抓获:8 并发 increment 终值 1)。MySQL 的快照点(首次快照读)不同但同修;顶层单语句无此臂。
|
|
104
119
|
const build = (q, inTx) => ({
|
|
105
120
|
get: async (id) => {
|
|
106
121
|
const [rows] = (await q.query(`SELECT item_json FROM ${TASK_LIST_ITEMS_TABLE} WHERE list_key = ? AND id = ?${inTx ? " FOR UPDATE" : ""}`, [listKey, id]));
|
|
@@ -125,6 +140,7 @@ export function createTiDBTaskListStore(pool, listKey) {
|
|
|
125
140
|
? {}
|
|
126
141
|
: {
|
|
127
142
|
mutate: (fn) => tx(async (c) => {
|
|
143
|
+
// 分区锁(定谳 1):ensure + FOR UPDATE——同 listKey 的并发 mutate 在此串行。
|
|
128
144
|
await ensureMeta(execOn(c), "tidb", listKey);
|
|
129
145
|
await c.query(`SELECT next_id FROM ${TASK_LIST_META_TABLE} WHERE list_key = ? FOR UPDATE`, [listKey]);
|
|
130
146
|
return fn(build(c, true));
|
|
@@ -157,12 +173,17 @@ export function createPgTaskListStore(pool, listKey) {
|
|
|
157
173
|
const res = await q.query(sql, params);
|
|
158
174
|
return res.rows;
|
|
159
175
|
};
|
|
176
|
+
// 事务内当前读(TiDB 侧同注——PG READ COMMITTED 语句级快照本已看见锁前提交,FOR UPDATE 统一
|
|
177
|
+
// 双方言姿势,顺带把行锁真拿住)。
|
|
160
178
|
const build = (q, inTx) => ({
|
|
161
179
|
get: async (id) => {
|
|
162
180
|
const { rows } = await q.query(`SELECT item_json FROM ${TASK_LIST_ITEMS_TABLE} WHERE list_key = $1 AND id = $2${inTx ? " FOR UPDATE" : ""}`, [listKey, id]);
|
|
163
181
|
return rows.length > 0 ? parseItem(rows[0].item_json) : undefined;
|
|
164
182
|
},
|
|
165
183
|
set: async (id, item) => {
|
|
184
|
+
// 身份/引用键拒绝式(复审 F8):行键 id 之外,blob 内的 item.id/owner(工具层 ifOwnerIs 守卫
|
|
185
|
+
// 的比对对象)与 blocks/blockedBy(id 引用)清洗形变会与真实键错位——同落拒绝层;正文
|
|
186
|
+
// (subject/description/metadata)维持内容面 lossy。
|
|
166
187
|
if (pgHasUnstorable(id) ||
|
|
167
188
|
pgHasUnstorable(item.id) ||
|
|
168
189
|
(item.owner !== undefined && pgHasUnstorable(item.owner)) ||
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编 — see src/plugins/approval-store-sql.ts for the
|
|
3
|
+
* implementation, now SINGLE-FILE DUAL-DIALECT). Class name, ctor arity, and every exported
|
|
4
|
+
* type/helper stay EXACTLY as they were so no consumer (store-backend.ts, src/index.ts, the
|
|
5
|
+
* approval/audit/security-coverage suites) has to move.
|
|
6
|
+
*/
|
|
1
7
|
export { TiDBApprovalStore, mapRow, type ApprovalRow, type ApprovalStatus, } from "./approval-store-sql.js";
|
|
2
8
|
//# sourceMappingURL=tidb-approval-store.d.ts.map
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 收编 — see src/plugins/approval-store-sql.ts for the
|
|
3
|
+
* implementation, now SINGLE-FILE DUAL-DIALECT). Class name, ctor arity, and every exported
|
|
4
|
+
* type/helper stay EXACTLY as they were so no consumer (store-backend.ts, src/index.ts, the
|
|
5
|
+
* approval/audit/security-coverage suites) has to move.
|
|
6
|
+
*/
|
|
1
7
|
export { TiDBApprovalStore, mapRow, } from "./approval-store-sql.js";
|
|
2
8
|
//# sourceMappingURL=tidb-approval-store.js.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shim (design/158 A12 收编) — the real implementation moved to breaker-state-sql.ts
|
|
3
|
+
* (single-file dual-dialect: `SqlBreakerState` + the `TiDBBreakerState`/`PgBreakerState` ctor subclasses).
|
|
4
|
+
* Kept so every consumer's `from "./tidb-breaker-state.js"` import keeps working unchanged.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBBreakerState } from "./breaker-state-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-breaker-state.d.ts.map
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export shim (design/158 A12 收编) — the real implementation moved to breaker-state-sql.ts
|
|
3
|
+
* (single-file dual-dialect: `SqlBreakerState` + the `TiDBBreakerState`/`PgBreakerState` ctor subclasses).
|
|
4
|
+
* Kept so every consumer's `from "./tidb-breaker-state.js"` import keeps working unchanged.
|
|
5
|
+
*/
|
|
1
6
|
export { TiDBBreakerState } from "./breaker-state-sql.js";
|
|
2
7
|
//# sourceMappingURL=tidb-breaker-state.js.map
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) `CheckpointStore` — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `checkpoint-store-sql.ts` (design/158 A12 定型半场). This file is the historical import path: the class
|
|
4
|
+
* name, ctor shape and the backend-NEUTRAL helpers the LOCAL twin shares (TERMINAL_BACKSTOP_MS /
|
|
5
|
+
* TERMINAL_GRACE_MS / tokenFingerprint / boundedToolInput / PendingCheckpoint) are re-exported unchanged,
|
|
6
|
+
* so local-checkpoint-store.ts, store-backend.ts, the dogfood script and every suite are untouched.
|
|
7
|
+
*/
|
|
1
8
|
export { TiDBCheckpointStore, SqlCheckpointStore, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS, tokenFingerprint, boundedToolInput, type PendingCheckpoint, } from "./checkpoint-store-sql.js";
|
|
2
9
|
//# sourceMappingURL=tidb-checkpoint-store.d.ts.map
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) `CheckpointStore` — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `checkpoint-store-sql.ts` (design/158 A12 定型半场). This file is the historical import path: the class
|
|
4
|
+
* name, ctor shape and the backend-NEUTRAL helpers the LOCAL twin shares (TERMINAL_BACKSTOP_MS /
|
|
5
|
+
* TERMINAL_GRACE_MS / tokenFingerprint / boundedToolInput / PendingCheckpoint) are re-exported unchanged,
|
|
6
|
+
* so local-checkpoint-store.ts, store-backend.ts, the dogfood script and every suite are untouched.
|
|
7
|
+
*/
|
|
1
8
|
export { TiDBCheckpointStore, SqlCheckpointStore, TERMINAL_BACKSTOP_MS, TERMINAL_GRACE_MS, tokenFingerprint, boundedToolInput, } from "./checkpoint-store-sql.js";
|
|
2
9
|
//# sourceMappingURL=tidb-checkpoint-store.js.map
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-replica per-key CUMULATIVE cost quota (design/30 P0-1). A thin {@link QuotaTracker} over the
|
|
3
|
+
* shared {@link WriteBehindCounter}: atomic write-behind aggregation, eventually consistent (SOFT
|
|
4
|
+
* limiting — boundary overspend is bounded by the flush interval and backstopped by the HARD per-task
|
|
5
|
+
* `maxCostUsd` gate). `scope_key` is opaque (principal today; team/feature later — design/30 N3).
|
|
6
|
+
*/
|
|
1
7
|
import type { Pool } from "mysql2/promise";
|
|
2
8
|
import type { QuotaDecision, QuotaTracker } from "../observability/cost-quota.js";
|
|
3
9
|
import { type CounterDegradeHook } from "./write-behind-counter.js";
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 定型半场) — the real implementation collapsed into
|
|
3
|
+
* `file-snapshot-store-sql.ts` (single file, dual dialect). Kept so every existing import path
|
|
4
|
+
* (store-backend.ts, the migration script, the contract/integration/minio-equivalence suites) is
|
|
5
|
+
* untouched: same class name, same ctor arity, same exported surface.
|
|
6
|
+
*/
|
|
1
7
|
export { TiDBFileSnapshotStore } from "./file-snapshot-store-sql.js";
|
|
2
8
|
//# sourceMappingURL=tidb-file-snapshot-store.d.ts.map
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin re-export shim (design/158 A12 定型半场) — the real implementation collapsed into
|
|
3
|
+
* `file-snapshot-store-sql.ts` (single file, dual dialect). Kept so every existing import path
|
|
4
|
+
* (store-backend.ts, the migration script, the contract/integration/minio-equivalence suites) is
|
|
5
|
+
* untouched: same class name, same ctor arity, same exported surface.
|
|
6
|
+
*/
|
|
1
7
|
export { TiDBFileSnapshotStore } from "./file-snapshot-store-sql.js";
|
|
2
8
|
//# sourceMappingURL=tidb-file-snapshot-store.js.map
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) BAKE store — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `image-bake-store-sql.ts` (design/158 A12 定型半场). This file is the historical import path: the
|
|
4
|
+
* class name, ctor shape and every re-exported contract are unchanged, so no consumer moved.
|
|
5
|
+
*
|
|
6
|
+
* New code should import from `./image-bake-store-sql.js` (both dialects) and take its CONTRACTS from
|
|
7
|
+
* `./store-contracts.js` (backend-neutral, design/158 A3 沉底).
|
|
8
|
+
*/
|
|
1
9
|
export { TiDBImageBake, SqlImageBake } from "./image-bake-store-sql.js";
|
|
2
10
|
export type { BakeStatus, BakeState, BakeErrorCode, BakeRecord, BakeEvent, CreateBakeInput, BakeTerminal, BakeRow, } from "./store-contracts.js";
|
|
3
11
|
export { mapBakeRow as mapRow, BAKE_SELECT_COLS as SELECT_COLS } from "./store-contracts.js";
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) BAKE store — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `image-bake-store-sql.ts` (design/158 A12 定型半场). This file is the historical import path: the
|
|
4
|
+
* class name, ctor shape and every re-exported contract are unchanged, so no consumer moved.
|
|
5
|
+
*
|
|
6
|
+
* New code should import from `./image-bake-store-sql.js` (both dialects) and take its CONTRACTS from
|
|
7
|
+
* `./store-contracts.js` (backend-neutral, design/158 A3 沉底).
|
|
8
|
+
*/
|
|
1
9
|
export { TiDBImageBake, SqlImageBake } from "./image-bake-store-sql.js";
|
|
2
10
|
export { mapBakeRow as mapRow, BAKE_SELECT_COLS as SELECT_COLS } from "./store-contracts.js";
|
|
3
11
|
//# sourceMappingURL=tidb-image-bake.js.map
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox-image-pool INDEX store (IMAGE-API-DESIGN.md §1, pool design §8).
|
|
3
|
+
*
|
|
4
|
+
* Thin re-export shim (design/158 A12 定型半场): the real implementation is the single-file dual-dialect
|
|
5
|
+
* `image-index-sql.ts` (`SqlImageIndex` + this file's `TiDBImageIndex` ctor subclass). Class name, ctor
|
|
6
|
+
* arity, and the exported type/helper surface are UNCHANGED — every consumer (store-backend.ts, the unit +
|
|
7
|
+
* real-DB integration suites) imports from here exactly as before.
|
|
8
|
+
*/
|
|
1
9
|
export { TiDBImageIndex } from "./image-index-sql.js";
|
|
2
10
|
export type { ImageNestedBuildMode, ImageCapabilities, ImagePodContract, ImageStatus, ImageVisibility, ImageIndexEntry, ImageIndexUpsert, ImageViewer, ImageListFilter, ImageRow, } from "./store-contracts.js";
|
|
3
11
|
export { mapImageRow as mapRow } from "./store-contracts.js";
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox-image-pool INDEX store (IMAGE-API-DESIGN.md §1, pool design §8).
|
|
3
|
+
*
|
|
4
|
+
* Thin re-export shim (design/158 A12 定型半场): the real implementation is the single-file dual-dialect
|
|
5
|
+
* `image-index-sql.ts` (`SqlImageIndex` + this file's `TiDBImageIndex` ctor subclass). Class name, ctor
|
|
6
|
+
* arity, and the exported type/helper surface are UNCHANGED — every consumer (store-backend.ts, the unit +
|
|
7
|
+
* real-DB integration suites) imports from here exactly as before.
|
|
8
|
+
*/
|
|
1
9
|
export { TiDBImageIndex } from "./image-index-sql.js";
|
|
2
10
|
export { mapImageRow as mapRow } from "./store-contracts.js";
|
|
3
11
|
//# sourceMappingURL=tidb-image-index.js.map
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) outcome ledger — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `outcome-ledger-sql.ts` (design/158 A12 定型半场), alongside its PG twin so the dialect deltas
|
|
4
|
+
* (placeholders, JSON encode, the AVG boolean-coercion divergence) read side by side instead of
|
|
5
|
+
* drifting across two files.
|
|
6
|
+
*
|
|
7
|
+
* This file is the historical import path: class name, ctor shape, the shared types and the pure
|
|
8
|
+
* helpers (`taskSignature` / `deriveOutcome` / `coreOutcomeToLedgerRow`) are unchanged, so
|
|
9
|
+
* store-backend.ts, the pg twin, and every suite are untouched.
|
|
10
|
+
*/
|
|
1
11
|
export { TiDBOutcomeLedger, taskSignature, deriveOutcome, coreOutcomeToLedgerRow, type MechanicalOutcome, type LlmAssistedOutcome, type SignatureInputs, type RunStatus, type TaskOutcome, } from "./outcome-ledger-sql.js";
|
|
2
12
|
//# sourceMappingURL=tidb-outcome-ledger.d.ts.map
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MySQL-protocol (TiDB) outcome ledger — the implementation now lives in the single-file dual-dialect
|
|
3
|
+
* `outcome-ledger-sql.ts` (design/158 A12 定型半场), alongside its PG twin so the dialect deltas
|
|
4
|
+
* (placeholders, JSON encode, the AVG boolean-coercion divergence) read side by side instead of
|
|
5
|
+
* drifting across two files.
|
|
6
|
+
*
|
|
7
|
+
* This file is the historical import path: class name, ctor shape, the shared types and the pure
|
|
8
|
+
* helpers (`taskSignature` / `deriveOutcome` / `coreOutcomeToLedgerRow`) are unchanged, so
|
|
9
|
+
* store-backend.ts, the pg twin, and every suite are untouched.
|
|
10
|
+
*/
|
|
1
11
|
export { TiDBOutcomeLedger, taskSignature, deriveOutcome, coreOutcomeToLedgerRow, } from "./outcome-ledger-sql.js";
|
|
2
12
|
//# sourceMappingURL=tidb-outcome-ledger.js.map
|
|
@@ -1,11 +1,67 @@
|
|
|
1
1
|
import mysql from "mysql2/promise";
|
|
2
2
|
import type { Pool, PoolConnection } from "mysql2/promise";
|
|
3
3
|
import type { ServiceConfig } from "../config-types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Shared TiDB (MySQL wire-compatible) connection pool for the durable Session center (L1).
|
|
6
|
+
* Owned by `main.ts`; closed on shutdown.
|
|
7
|
+
*
|
|
8
|
+
* Read/write pool — this is the persistence center. (The SQL *tool* given to the model must use a
|
|
9
|
+
* separate read-only pool/credential; never hand this pool to a tool.)
|
|
10
|
+
*/
|
|
11
|
+
/** Build the mysql2 pool options from TiDB config (pure → unit-testable apart from the live connection). */
|
|
4
12
|
export declare function tidbPoolOptions(tidb: NonNullable<ServiceConfig["tidb"]>): mysql.PoolOptions;
|
|
5
13
|
export declare function createTidbPool(config: ServiceConfig): Pool;
|
|
14
|
+
/**
|
|
15
|
+
* Idempotent schema. `session_event` is the append-only L1 event log (positional slicing by
|
|
16
|
+
* `(session_id, seq)`); `session_meta` holds the branch leaf + the optimistic-lock counter
|
|
17
|
+
* (`leaf_seq`) + tenant `owner`.
|
|
18
|
+
*
|
|
19
|
+
* ── SCHEMA POLICY (clay 裁,2026-07-26) ─────────────────────────────────────────────────────────────
|
|
20
|
+
* 本仓 schema 的唯一真源 = **这份代码**(此数组 + `pg-pool.ts` 的 PG 孪生)。口径:
|
|
21
|
+
*
|
|
22
|
+
* 1. **删库重建,不做增量。** 尚未上生产、单人本地,存量库一律 DROP DATABASE 重建;因此这里**不再保留
|
|
23
|
+
* 任何 `ALTER TABLE` 增量 seam**。历史上的 21 条 ADD COLUMN / 3 条 CREATE INDEX / 1 条 MODIFY COLUMN
|
|
24
|
+
* 已于 2026-07-26 全部折进下面的 `CREATE TABLE`(它们承载的语义已逐条搬成列上的行内注释 —— 那些注释
|
|
25
|
+
* 是 pre-migration 行为契约的**唯一书面记录**,删注释 = 丢语义)。
|
|
26
|
+
* 2. **不许再新增 `ALTER TABLE` seam。** 要改列/加列/改可空性 ⇒ 直接改下面的 `CREATE TABLE`,然后重建库。
|
|
27
|
+
* (再开增量通道就等于把「代码是真源」变回「代码 + 一串按时间排的补丁才是真源」。)
|
|
28
|
+
* 3. 生成的全集 SQL 基线导出到 `docs/schema/baseline-mysql.sql`(由本数组机器生成;它是**产物**,不是真源
|
|
29
|
+
* —— 冲突时以本文件为准并重新生成)。
|
|
30
|
+
*
|
|
31
|
+
* 注意:`ensureSchema` 仍然保留(建表 + advisory lock + image_bake_admit 种子行),只是语句数组现在是纯
|
|
32
|
+
* CREATE,不再有 information_schema 探针。
|
|
33
|
+
*/
|
|
6
34
|
export declare const SCHEMA_STATEMENTS: readonly string[];
|
|
35
|
+
/** Named MySQL/TiDB advisory lock that serializes the whole `ensureSchema` DDL run (see below). */
|
|
7
36
|
export declare const ENSURE_SCHEMA_LOCK = "sema_ensure_schema";
|
|
37
|
+
/** Acquire {@link ENSURE_SCHEMA_LOCK} on `conn` (the lock is CONNECTION-level, so the caller MUST then run all the
|
|
38
|
+
* serialized work on this SAME connection and release with {@link releaseEnsureSchemaLock}). Returns whether it was
|
|
39
|
+
* acquired. Exported so test setup that does ad-hoc DDL (e.g. a DROP-then-recreate) can serialize against
|
|
40
|
+
* ensureSchema runs using the IDENTICAL lock.
|
|
41
|
+
*
|
|
42
|
+
* Under heavy concurrency (the integration suite fans ~20 callers at the SAME named lock; or a fleet boots N
|
|
43
|
+
* replicas at once) a BLOCKING GET_LOCK(name, 30) would park ~19 sessions in a pessimistic WAIT on TiDB's advisory-
|
|
44
|
+
* lock row — which both exhausts TiDB's "pessimistic lock retry limit" (surfacing as a thrown error) AND starves the
|
|
45
|
+
* app's OWN `SELECT … FOR UPDATE` paths (image-bake admission/lease) of pessimistic-lock budget. So we acquire
|
|
46
|
+
* NON-BLOCKING (GET_LOCK(name, 0) returns 0 immediately if held) and POLL with jittered backoff: one holder, the
|
|
47
|
+
* rest sleeping (not blocked in-DB). Return false only after exhausting retries (the caller then DEGRADES to
|
|
48
|
+
* unserialized rather than blocking boot forever — the DDL is still individually idempotent). */
|
|
8
49
|
export declare function acquireEnsureSchemaLock(conn: PoolConnection, tag?: string): Promise<boolean>;
|
|
50
|
+
/** Release {@link ENSURE_SCHEMA_LOCK} on `conn` (best-effort — the lock also auto-frees when the connection closes). */
|
|
9
51
|
export declare function releaseEnsureSchemaLock(conn: PoolConnection, tag?: string): Promise<void>;
|
|
52
|
+
/** Create tables if absent (+ seed the image-bake admission sentinel). Safe to call on every startup.
|
|
53
|
+
*
|
|
54
|
+
* Per the SCHEMA POLICY on {@link SCHEMA_STATEMENTS} this is a pure CREATE run — there are NO additive
|
|
55
|
+
* ALTER/CREATE-INDEX seams and no information_schema probes any more (2026-07-26): the schema contract is
|
|
56
|
+
* drop-and-recreate, so every column / index / nullability lives in its `CREATE TABLE`. Do not reintroduce a
|
|
57
|
+
* migration loop here; change the CREATE and rebuild the database.
|
|
58
|
+
*
|
|
59
|
+
* Concurrency: callers run this concurrently — tests fan ALL integration suites out in parallel (each
|
|
60
|
+
* beforeAll calls ensureSchema), and in production every replica calls it at boot (`--scale service=4`).
|
|
61
|
+
* Concurrent DDL on the SAME table makes TiDB race in its schema catalog. We serialize the entire run
|
|
62
|
+
* behind {@link ENSURE_SCHEMA_LOCK} (a named GET_LOCK), which is CONNECTION-level — so the lock AND every
|
|
63
|
+
* DDL statement run on the one connection we hold here (pooled `pool.query` could land on a different
|
|
64
|
+
* connection and silently void the lock). The DDL semantics are unchanged; only the timing is serialized.
|
|
65
|
+
*/
|
|
10
66
|
export declare function ensureSchema(pool: Pool): Promise<void>;
|
|
11
67
|
//# sourceMappingURL=tidb-pool.d.ts.map
|