@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,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalTaskAttachmentStore —— D-1 附件店的 local 形(seamless-local-cloud 铁律:StoreBackend
|
|
3
|
+
* kind tidb|pg|local 三态,附件面不得 cloud-only)。
|
|
4
|
+
*
|
|
5
|
+
* 布局:`<root>/attachments/<id>.json`(meta)+ `<id>.bin`(bytes)。id=uuidv7(server 铸,不含用户
|
|
6
|
+
* 输入 ⇒ 文件名安全);meta 内含 owner/session 轴,门在读侧比对(单机单进程,无并发租户;SQL 店才是
|
|
7
|
+
* 多租户形)。写=tmp+rename 原子(半写行不可见);索引=首次使用时全目录水合进内存 Map,之后同进程
|
|
8
|
+
* 内存权威(local 模式规模小;跨进程并发不在 local 契约内——与 file-run-store 同口径)。
|
|
9
|
+
*/
|
|
1
10
|
import { promises as fsp } from "node:fs";
|
|
2
11
|
import { join } from "node:path";
|
|
3
|
-
const ID_RE = /^[0-9a-f-]{16,64}$/i;
|
|
12
|
+
const ID_RE = /^[0-9a-f-]{16,64}$/i; // uuid 形(server 铸);水合时非此形的文件一律跳过
|
|
4
13
|
export class LocalTaskAttachmentStore {
|
|
5
14
|
dir;
|
|
6
15
|
metas;
|
|
@@ -24,10 +33,12 @@ export class LocalTaskAttachmentStore {
|
|
|
24
33
|
m.set(id, meta);
|
|
25
34
|
}
|
|
26
35
|
catch {
|
|
36
|
+
/* 半写/损坏 meta:跳过(bin 无 meta 即孤儿,reap 收) */
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
catch {
|
|
41
|
+
/* 目录不存在 = 空店 */
|
|
31
42
|
}
|
|
32
43
|
this.metas = m;
|
|
33
44
|
return m;
|
|
@@ -40,6 +51,7 @@ export class LocalTaskAttachmentStore {
|
|
|
40
51
|
const metaTmp = join(this.dir, `${rec.id}.json.tmp`);
|
|
41
52
|
await fsp.writeFile(binTmp, Buffer.from(content));
|
|
42
53
|
await fsp.rename(binTmp, join(this.dir, `${rec.id}.bin`));
|
|
54
|
+
// meta 后落:meta 在场 ⇒ bytes 必在场(读侧无半态)
|
|
43
55
|
await fsp.writeFile(metaTmp, JSON.stringify(meta));
|
|
44
56
|
await fsp.rename(metaTmp, join(this.dir, `${rec.id}.json`));
|
|
45
57
|
metas.set(rec.id, { ...meta });
|
|
@@ -56,7 +68,7 @@ export class LocalTaskAttachmentStore {
|
|
|
56
68
|
return new Uint8Array(await fsp.readFile(join(this.dir, `${id}.bin`)));
|
|
57
69
|
}
|
|
58
70
|
catch {
|
|
59
|
-
return null;
|
|
71
|
+
return null; // meta 在 bytes 丢(外力删档)——按不存在答,不抛
|
|
60
72
|
}
|
|
61
73
|
}
|
|
62
74
|
async persistMeta(m) {
|
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MailboxStore SQL twins(design/151 S3c server pg 半场,[1530] 提货单①)——core teammate 信箱
|
|
3
|
+
* (SendMessage 链)的 TiDB/PG 双方言实现。挂载缝 = S3c 行为车的 `RunnerDeps.mailboxStore`(core
|
|
4
|
+
* 命名预告,[1530]§三);本文件先就绪 store 半场,行为车到货接线。
|
|
5
|
+
*
|
|
6
|
+
* 语义真源 = core `InMemoryMailboxStore`(dist/core/mailbox-store.js)+ [1530] 定谳(core 1.372
|
|
7
|
+
* 终版文本,conformance 无两可):
|
|
8
|
+
* 1. **同主重 claim = 续期 + 纳新**(crash-retry 正形):活 lease 只挡**别的** owner;同 owner 任意
|
|
9
|
+
* 时刻重 claim 重设 TTL 并拿到当前全部未 ack 消息(maxSeq 随最新行走)。
|
|
10
|
+
* 2. **seq = 盒生命周期内不复用**:box 行携 `next_seq`,分配与 append 同事务;`drop`/`reap` 删整盒
|
|
11
|
+
* (含 box 行)= 生命周期终结,重建从 1(core 定谳:行随盒亡,dedup 键携 handle)。
|
|
12
|
+
* 3. **ack 无 owner 守卫**(信任 claim 赢者链):`seq <= upToSeq` 删行;lease 的 `maxSeq <= upToSeq`
|
|
13
|
+
* 时顺带清 lease(全量 ack = 释放)。
|
|
14
|
+
* 4. **lease 过期判 = 严格 `expiresAt > now` 才挡**;`releaseLease` 只在 owner 匹配时清。
|
|
15
|
+
* 5. `peekCount` 含已 lease 消息(可见性 ≠ lease 态);空盒 claim = null(box 行在而消息 0 也 null)。
|
|
16
|
+
* 6. **reap = SQL 全量真扫**(core File 实现只扫已加载盒 = 进程内 backstop,[1530] 确认 SQL 是全量
|
|
17
|
+
* 真扫的正确层):`maxAgeMs` 缺省 → 0;按盒 newest `sentAt < now - maxAgeMs` 删整盒;空盒(有
|
|
18
|
+
* box 行无消息)不删(InMemory 同形——`newest === undefined` 不删)。
|
|
19
|
+
*
|
|
20
|
+
* 键列 = 字节等价(TiDB VARBINARY / PG COLLATE "C",roster F2 案):scope/handle/lease_owner 的
|
|
21
|
+
* `=` 必须纯字节——PAD SPACE 近撞不得穿隔离/抢别人 lease。PG unstorable bytes([1439] 三层定谳):
|
|
22
|
+
* `content` 是消息**内容面**(收件人将读到、注入对话)→ 与 PG 转录 payload 同族 lossy(pgSanitizeText,
|
|
23
|
+
* U+FFFD 标记,内容不失行);**身份键 scope/handle/owner/from 拒绝式**(pgHasUnstorable →
|
|
24
|
+
* PgUnstorableError fail-loud——attribution/路由键清洗形变 = 行与查询键错位,协议数据同向)。TiDB
|
|
25
|
+
* 侧 LONGTEXT/VARBINARY verbatim(replay 面定谳)。
|
|
26
|
+
*
|
|
27
|
+
* 并发正确性(InMemory 单进程无此象限、SQL 多副本有;发车复审 F2/F3/F4 批):
|
|
28
|
+
* - **锁序统一「盒行 → 消息行」**(append/claim/ack/drop/reap 五面同序)——ack/drop/reap 原为
|
|
29
|
+
* 消息先行,与 claim 的盒先行构成 ABBA 死锁形;统一后同盒并发只在盒行锁上排队。
|
|
30
|
+
* - drop/reap 先删/锁**盒行**再动消息:反序留「消息已删、盒行未删」窗,并发 append 完整穿过后
|
|
31
|
+
* 盒重建会撞存活的孤儿消息行(PK 冲突→此后 append 永久失败)。
|
|
32
|
+
* - reap 候删 = 事务外粗筛 + 事务内**逐盒锁定重验**(当前读 newest):窗内新到的消息救活盒,
|
|
33
|
+
* 绝不连带删信;盒行已被并发 drop = 跳过不计。
|
|
34
|
+
* - append 的 ensure 与 FOR UPDATE 之间被并发 drop 提交 = 同事务内重建一次(语义 = drop 后重建,
|
|
35
|
+
* seq 从 1)。键长 > 190 字节写入即拒(fail-loud)——TiDB `INSERT IGNORE` 会把超长键**静默截断**,
|
|
36
|
+
* 截断键与全长查询参数字节比对恒 miss(分配读空行崩/隔离键错位)。
|
|
37
|
+
*/
|
|
1
38
|
import type { Pool as MySqlPool } from "mysql2/promise";
|
|
2
39
|
import type { Pool as PgPool } from "pg";
|
|
3
40
|
import type { MailboxLease, MailboxStore } from "@sema-agent/core";
|
|
@@ -27,6 +64,7 @@ export declare class PgMailboxStore implements MailboxStore {
|
|
|
27
64
|
private readonly pool;
|
|
28
65
|
constructor(pool: PgPool);
|
|
29
66
|
private tx;
|
|
67
|
+
/** 身份键拒绝式([1439] 协议纪律):scope/handle/owner/from 清洗形变 = 路由/attribution 错位。 */
|
|
30
68
|
private assertIdentity;
|
|
31
69
|
append(scope: string, handle: string, msg: {
|
|
32
70
|
from?: string;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { pgHasUnstorable, pgSanitizeText, PgUnstorableError } from "./pg-safe-json.js";
|
|
2
2
|
export const MAILBOX_TABLE = "mailboxes";
|
|
3
3
|
export const MAILBOX_MSG_TABLE = "mailbox_messages";
|
|
4
|
+
/** InMemory append 同文案形(default-deny 谓词精神:无 scope 的盒=路由不明,写入即拒)。 */
|
|
4
5
|
function assertScope(scope) {
|
|
5
6
|
if (scope === undefined || scope === "") {
|
|
6
7
|
throw new Error("MailboxStore.append: refusing a message without a scope");
|
|
7
8
|
}
|
|
8
9
|
}
|
|
10
|
+
/** 键长守卫(复审 F5):TiDB `INSERT IGNORE` 对超 190 字节键**静默截断**(warning 降级)——截断键
|
|
11
|
+
* 与全长参数的字节比对恒 miss(seq 分配读空行 TypeError / 隔离键错位);PG 侧是干净 22001,同点
|
|
12
|
+
* 提前拒 = 双方言同文案 fail-loud。 */
|
|
9
13
|
function assertKeyBytes(what, v) {
|
|
10
14
|
if (Buffer.byteLength(v, "utf8") > 190) {
|
|
11
15
|
throw new Error(`MailboxStore: ${what} exceeds the 190-byte key column (refusing — a truncated key would desync from its byte-exact lookups)`);
|
|
@@ -23,6 +27,8 @@ function rowToMessage(r) {
|
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
29
|
export async function ensureTiDBMailboxSchema(pool) {
|
|
30
|
+
// VARBINARY 键列(bg-agent/roster 同案);lease_owner 同为字节等价(claim 的 owner 比对是身份判)。
|
|
31
|
+
// content LONGTEXT:消息正文可超 64K TEXT(转录段落/大 diff 转述)。
|
|
26
32
|
await pool.query(`CREATE TABLE IF NOT EXISTS ${MAILBOX_TABLE} (
|
|
27
33
|
scope_key VARBINARY(190) NOT NULL,
|
|
28
34
|
handle VARBINARY(190) NOT NULL,
|
|
@@ -91,10 +97,14 @@ export class TiDBMailboxStore {
|
|
|
91
97
|
assertScope(scope);
|
|
92
98
|
assertKeyBytes("scope", scope);
|
|
93
99
|
assertKeyBytes("handle", handle);
|
|
100
|
+
// ensure-first 形:先幂等 INSERT IGNORE 建盒(next_seq=1,首条/drop 后重建同臂)再 FOR UPDATE——
|
|
101
|
+
// 「无行 FOR UPDATE + INSERT」的并发死锁/dup 撞车形整个消掉;seq 分配与 append 同事务(定谳 2)。
|
|
94
102
|
return this.tx(async (c) => {
|
|
95
103
|
await c.query(`INSERT IGNORE INTO ${MAILBOX_TABLE} (scope_key, handle, scope, next_seq) VALUES (?, ?, ?, 1)`, [scope, handle, scope]);
|
|
96
104
|
let [rows] = (await c.query(`SELECT next_seq FROM ${MAILBOX_TABLE} WHERE scope_key = ? AND handle = ? FOR UPDATE`, [scope, handle]));
|
|
97
105
|
if (rows.length === 0) {
|
|
106
|
+
// ensure 与锁之间盒被并发 drop/reap 提交(复审 #5 窗)——同事务重建一次(语义 = drop 后重建,
|
|
107
|
+
// seq 从 1;同事务内自插行必可见,再空 = 真障碍 fail-loud)。
|
|
98
108
|
await c.query(`INSERT IGNORE INTO ${MAILBOX_TABLE} (scope_key, handle, scope, next_seq) VALUES (?, ?, ?, 1)`, [scope, handle, scope]);
|
|
99
109
|
[rows] = (await c.query(`SELECT next_seq FROM ${MAILBOX_TABLE} WHERE scope_key = ? AND handle = ? FOR UPDATE`, [scope, handle]));
|
|
100
110
|
}
|
|
@@ -110,24 +120,35 @@ export class TiDBMailboxStore {
|
|
|
110
120
|
if (boxes.length === 0)
|
|
111
121
|
return null;
|
|
112
122
|
const box = boxes[0];
|
|
123
|
+
// 定谳 4:严格 expiresAt > now 才挡;定谳 1:同 owner 恒续期(字节等价比对——VARBINARY 读回 Buffer)。
|
|
124
|
+
// 残余记账(F7 TiDB 臂):owner 含 lone surrogate 时 mysql2 编码层塌缩 U+FFFD,读回串 ≠ 原参数
|
|
125
|
+
// → 同主续期被误拒(fail-closed 向,无越权);owner 是内部 mint 的 worker id(ASCII 域),接受。
|
|
113
126
|
if (box.lease_owner !== null &&
|
|
114
127
|
Number(box.lease_expires_at_ms) > now &&
|
|
115
128
|
bufToStr(box.lease_owner) !== owner) {
|
|
116
129
|
return null;
|
|
117
130
|
}
|
|
131
|
+
// FOR UPDATE = 当前读:TiDB 悲观事务的普通 SELECT 按 start_ts 快照(task-list twin 同案)——
|
|
132
|
+
// 锁到 box 行后消息集必须读「现在」,否则 drop+重建窗内老消息混进新盒 lease(maxSeq 错位)。
|
|
118
133
|
const [msgs] = (await c.query(`SELECT seq, from_id, content, sent_at_ms FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? ORDER BY seq FOR UPDATE`, [scope, handle]));
|
|
119
134
|
if (msgs.length === 0)
|
|
120
|
-
return null;
|
|
135
|
+
return null; // 定谳 5:空盒 claim = null(box 行在也 null)
|
|
121
136
|
const maxSeq = Number(msgs[msgs.length - 1].seq);
|
|
122
137
|
await c.query(`UPDATE ${MAILBOX_TABLE} SET lease_owner = ?, lease_expires_at_ms = ?, lease_max_seq = ? WHERE scope_key = ? AND handle = ?`, [owner, now + ttlMs, maxSeq, scope, handle]);
|
|
123
138
|
return { messages: msgs.map(rowToMessage), maxSeq };
|
|
124
139
|
});
|
|
125
140
|
}
|
|
126
141
|
async ack(scope, handle, owner, upToSeq) {
|
|
142
|
+
// MB1/core 1.452 BREAKING:ack 带 **owner 围栏**(core InMemory 同语义:lease 缺席或 owner 不符 ⇒
|
|
143
|
+
// 整个 ack no-op,一条消息都不删——原「定谳 3 无守卫,信任 claim 赢者链」被 [1937] MB1 推翻:
|
|
144
|
+
// 任何人可删别人租约内消息)。锁序仍=盒行先(复审 F3 ABBA 死锁形);盒不存在=SELECT 空 ⇒ no-op。
|
|
127
145
|
await this.tx(async (c) => {
|
|
128
146
|
const [rows] = (await c.query(`SELECT lease_owner FROM ${MAILBOX_TABLE} WHERE scope_key = ? AND handle = ? FOR UPDATE`, [scope, handle]));
|
|
147
|
+
// 🔴 真双库抓的坑(2026-07-28,mock 无法抓):lease_owner 是 VARBINARY,mysql2 读回 **Buffer**——
|
|
148
|
+
// `Buffer !== string` 恒真 ⇒ 首版围栏把正主也拒了(所有 ack 恒 no-op)。bufToStr 字节等价比对,
|
|
149
|
+
// claim 的定谳 1 同坑同解(:186)。
|
|
129
150
|
if (rows.length === 0 || rows[0].lease_owner == null || bufToStr(rows[0].lease_owner) !== owner)
|
|
130
|
-
return;
|
|
151
|
+
return; // 围栏:非当前持租者 ⇒ no-op
|
|
131
152
|
await c.query(`DELETE FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ? AND seq <= ?`, [scope, handle, upToSeq]);
|
|
132
153
|
await c.query(`UPDATE ${MAILBOX_TABLE} SET lease_owner = NULL, lease_expires_at_ms = NULL, lease_max_seq = NULL
|
|
133
154
|
WHERE scope_key = ? AND handle = ? AND lease_max_seq IS NOT NULL AND lease_max_seq <= ?`, [scope, handle, upToSeq]);
|
|
@@ -142,6 +163,8 @@ export class TiDBMailboxStore {
|
|
|
142
163
|
return Number(rows[0].n);
|
|
143
164
|
}
|
|
144
165
|
async drop(scope, handle) {
|
|
166
|
+
// 整盒删含 box 行 = seq 生命周期终结(定谳 2;重建从 1)。**盒行先删**(锁序统一 + F2:反序在
|
|
167
|
+
// 「消息已删、盒未删」窗放并发 append 穿过 → 盒重建撞孤儿消息行 PK,append 从此永败)。
|
|
145
168
|
await this.tx(async (c) => {
|
|
146
169
|
await c.query(`DELETE FROM ${MAILBOX_TABLE} WHERE scope_key = ? AND handle = ?`, [scope, handle]);
|
|
147
170
|
await c.query(`DELETE FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? AND handle = ?`, [scope, handle]);
|
|
@@ -151,6 +174,9 @@ export class TiDBMailboxStore {
|
|
|
151
174
|
if (opts?.maxAgeMs === undefined)
|
|
152
175
|
return 0;
|
|
153
176
|
const cutoff = now - opts.maxAgeMs;
|
|
177
|
+
// 全量真扫(定谳 6):事务外粗筛(索引面)+ 事务内逐盒「锁盒行 → 当前读重验 newest」(复审
|
|
178
|
+
// F2/F4:粗筛与删除之间窗内新到的消息必须救活盒,绝不连带删信;GROUP BY 不能 FOR UPDATE,
|
|
179
|
+
// 重验用 ORDER BY … LIMIT 1 当前读)。空盒不删(newest 无行);盒行已被并发 drop = 跳过。
|
|
154
180
|
const [cands] = (await this.pool.query(`SELECT handle FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = ? GROUP BY handle HAVING MAX(sent_at_ms) < ?`, [scope, cutoff]));
|
|
155
181
|
if (cands.length === 0)
|
|
156
182
|
return 0;
|
|
@@ -193,6 +219,7 @@ export class PgMailboxStore {
|
|
|
193
219
|
c.release();
|
|
194
220
|
}
|
|
195
221
|
}
|
|
222
|
+
/** 身份键拒绝式([1439] 协议纪律):scope/handle/owner/from 清洗形变 = 路由/attribution 错位。 */
|
|
196
223
|
assertIdentity(what, v) {
|
|
197
224
|
if (v !== undefined && pgHasUnstorable(v))
|
|
198
225
|
throw new PgUnstorableError(`mailbox ${what}`);
|
|
@@ -202,9 +229,10 @@ export class PgMailboxStore {
|
|
|
202
229
|
this.assertIdentity("scope", scope);
|
|
203
230
|
this.assertIdentity("handle", handle);
|
|
204
231
|
this.assertIdentity("from", msg.from);
|
|
205
|
-
const content = pgSanitizeText(msg.content);
|
|
232
|
+
const content = pgSanitizeText(msg.content); // 内容面 lossy(U+FFFD 标记,与 PG 转录 payload 同族)
|
|
206
233
|
assertKeyBytes("scope", scope);
|
|
207
234
|
assertKeyBytes("handle", handle);
|
|
235
|
+
// ensure-first 形(TiDB 同注):幂等建盒再 FOR UPDATE,死锁/dup 撞车形消。
|
|
208
236
|
return this.tx(async (c) => {
|
|
209
237
|
await c.query(`INSERT INTO ${MAILBOX_TABLE} (scope_key, handle, scope, next_seq) VALUES ($1, $2, $3, 1) ON CONFLICT (scope_key, handle) DO NOTHING`, [
|
|
210
238
|
scope,
|
|
@@ -213,6 +241,7 @@ export class PgMailboxStore {
|
|
|
213
241
|
]);
|
|
214
242
|
let { rows } = await c.query(`SELECT next_seq FROM ${MAILBOX_TABLE} WHERE scope_key = $1 AND handle = $2 FOR UPDATE`, [scope, handle]);
|
|
215
243
|
if (rows.length === 0) {
|
|
244
|
+
// ensure 与锁之间盒被并发 drop/reap 提交(TiDB 同注)——同事务重建一次。
|
|
216
245
|
await c.query(`INSERT INTO ${MAILBOX_TABLE} (scope_key, handle, scope, next_seq) VALUES ($1, $2, $3, 1) ON CONFLICT (scope_key, handle) DO NOTHING`, [
|
|
217
246
|
scope,
|
|
218
247
|
handle,
|
|
@@ -227,7 +256,7 @@ export class PgMailboxStore {
|
|
|
227
256
|
});
|
|
228
257
|
}
|
|
229
258
|
async claimLease(scope, handle, owner, ttlMs, now = Date.now()) {
|
|
230
|
-
this.assertIdentity("owner", owner);
|
|
259
|
+
this.assertIdentity("owner", owner); // 复审 F7:lease 排他键同为身份键,裸 22021/塌缩比对都不许
|
|
231
260
|
return this.tx(async (c) => {
|
|
232
261
|
const { rows: boxes } = await c.query(`SELECT lease_owner, lease_expires_at_ms FROM ${MAILBOX_TABLE} WHERE scope_key = $1 AND handle = $2 FOR UPDATE`, [scope, handle]);
|
|
233
262
|
if (boxes.length === 0)
|
|
@@ -244,17 +273,19 @@ export class PgMailboxStore {
|
|
|
244
273
|
});
|
|
245
274
|
}
|
|
246
275
|
async ack(scope, handle, owner, upToSeq) {
|
|
276
|
+
// MB1 owner 围栏(TiDB 孪生同注);锁序=盒行先(F3 ABBA 死锁形消)。
|
|
247
277
|
await this.tx(async (c) => {
|
|
248
278
|
const r = (await c.query(`SELECT lease_owner FROM ${MAILBOX_TABLE} WHERE scope_key = $1 AND handle = $2 FOR UPDATE`, [scope, handle]));
|
|
279
|
+
// PG 列是 VARCHAR COLLATE "C"(读回 string,无 TiDB 臂的 Buffer 坑),bufToStr 幂等包一层求同形。
|
|
249
280
|
if (r.rows.length === 0 || r.rows[0].lease_owner == null || bufToStr(r.rows[0].lease_owner) !== owner)
|
|
250
|
-
return;
|
|
281
|
+
return; // 围栏:非当前持租者 ⇒ no-op
|
|
251
282
|
await c.query(`DELETE FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = $1 AND handle = $2 AND seq <= $3`, [scope, handle, upToSeq]);
|
|
252
283
|
await c.query(`UPDATE ${MAILBOX_TABLE} SET lease_owner = NULL, lease_expires_at_ms = NULL, lease_max_seq = NULL
|
|
253
284
|
WHERE scope_key = $1 AND handle = $2 AND lease_max_seq IS NOT NULL AND lease_max_seq <= $3`, [scope, handle, upToSeq]);
|
|
254
285
|
});
|
|
255
286
|
}
|
|
256
287
|
async releaseLease(scope, handle, owner) {
|
|
257
|
-
this.assertIdentity("owner", owner);
|
|
288
|
+
this.assertIdentity("owner", owner); // F7 同注
|
|
258
289
|
await this.pool.query(`UPDATE ${MAILBOX_TABLE} SET lease_owner = NULL, lease_expires_at_ms = NULL, lease_max_seq = NULL
|
|
259
290
|
WHERE scope_key = $1 AND handle = $2 AND lease_owner = $3`, [scope, handle, owner]);
|
|
260
291
|
}
|
|
@@ -263,6 +294,7 @@ export class PgMailboxStore {
|
|
|
263
294
|
return Number(rows[0].n);
|
|
264
295
|
}
|
|
265
296
|
async drop(scope, handle) {
|
|
297
|
+
// 盒行先删(TiDB 同注,F2 孤儿消息行窗关死)。
|
|
266
298
|
await this.tx(async (c) => {
|
|
267
299
|
await c.query(`DELETE FROM ${MAILBOX_TABLE} WHERE scope_key = $1 AND handle = $2`, [scope, handle]);
|
|
268
300
|
await c.query(`DELETE FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = $1 AND handle = $2`, [scope, handle]);
|
|
@@ -272,6 +304,7 @@ export class PgMailboxStore {
|
|
|
272
304
|
if (opts?.maxAgeMs === undefined)
|
|
273
305
|
return 0;
|
|
274
306
|
const cutoff = now - opts.maxAgeMs;
|
|
307
|
+
// 事务外粗筛 + 事务内逐盒锁定重验(TiDB 同注,F2/F4:窗内新信救活盒,不丢信)。
|
|
275
308
|
const { rows: cands } = await this.pool.query(`SELECT handle FROM ${MAILBOX_MSG_TABLE} WHERE scope_key = $1 GROUP BY handle HAVING MAX(sent_at_ms) < $2`, [scope, cutoff]);
|
|
276
309
|
if (cands.length === 0)
|
|
277
310
|
return 0;
|
|
@@ -1,21 +1,43 @@
|
|
|
1
1
|
import type { MemoryHistoryAppendRow } from "./memory-sync-store-pg.js";
|
|
2
2
|
import type { PgEmbedder, PgQueryFn } from "./pg-query.js";
|
|
3
3
|
import type { MemoryBackend, MemoryEntry, MemoryEntryHeader, NotePatch, PatchReport, ScoredMemoryEntry } from "@sema-agent/core";
|
|
4
|
+
/** Table names (single source). Deliberately DISJOINT from the legacy `agent_memory*` tables —
|
|
5
|
+
* the retired MemoryStore plane and this entry plane must never cross-write. */
|
|
4
6
|
export declare const PG_MEMORY_ENGINE_TABLES: {
|
|
5
7
|
readonly entries: "agent_memory_engine_entries";
|
|
6
8
|
readonly cursors: "agent_memory_engine_cursors";
|
|
7
9
|
};
|
|
10
|
+
/** Options for {@link ensurePgMemoryEngineSchema} — same `memoryVector` contract as PgAgentSchemaOptions. */
|
|
8
11
|
export interface PgMemoryEngineSchemaOptions {
|
|
12
|
+
/** Omitted → `jsonb` embedding column (portable). `{ dimensions, pgvector: true }` → `CREATE EXTENSION
|
|
13
|
+
* vector` + a `vector(d)` column (native `<=>`). Pick once; keep the backend options consistent. */
|
|
9
14
|
memoryVector?: {
|
|
10
15
|
dimensions: number;
|
|
11
16
|
pgvector?: boolean;
|
|
12
17
|
};
|
|
13
18
|
}
|
|
19
|
+
/** Idempotent DDL for the entry plane. Call once at startup (or run through your migration tool). */
|
|
14
20
|
export declare function ensurePgMemoryEngineSchema(query: PgQueryFn, opts?: PgMemoryEngineSchemaOptions): Promise<void>;
|
|
21
|
+
/** Options for {@link PgMemoryEngineBackend}. */
|
|
15
22
|
export interface PgMemoryEngineBackendOptions {
|
|
23
|
+
/** Entries are embedded on add/update and `search` ranks by cosine distance. Absent → lexical floor. */
|
|
16
24
|
embedder?: PgEmbedder;
|
|
25
|
+
/** `true` → rank in SQL via pgvector `<=>` (schema must carry `memoryVector: { pgvector: true }`).
|
|
26
|
+
* Same migration note as PgMemoryStoreOptions: the SQL path EXCLUDES rows without an embedding —
|
|
27
|
+
* backfill before enabling. Requires `embedder`. */
|
|
17
28
|
pgvectorSql?: boolean;
|
|
29
|
+
/** Clock injection (file-backend precedent) — drives `mtime_ms`. Default `Date.now`. */
|
|
18
30
|
now?: () => number;
|
|
31
|
+
/** 142-S5.1 history write point (改动 vs origin): OPTIONAL audit sink — every APPLIED
|
|
32
|
+
* patch appends one `agent_memory_engine_history` row (add=chain head/update=prevRev link/
|
|
33
|
+
* delete=tombstone) AFTER its entry write commits. Absent → byte-equal legacy behavior (additive).
|
|
34
|
+
* ⚠️ 同事务诚实记档:the 142-S4 design draft says "同事务追加", but this backend's ONLY DB seam is
|
|
35
|
+
* a bare `PgQueryFn` — with a pooled query fn, BEGIN/COMMIT statements may land on DIFFERENT
|
|
36
|
+
* connections, so a true transaction would require refactoring the constructor to a client-checkout
|
|
37
|
+
* seam (breaks the origin-core@3071dd3 minimal-diff move-in discipline).
|
|
38
|
+
* Chosen trade-off: entry write commits first, history append is BEST-EFFORT
|
|
39
|
+
* (failure = swallow + console.warn) — history is the AUDIT face, not the correctness face: a lost
|
|
40
|
+
* history row loses an audit line, never data (the entries table stays the single truth). */
|
|
19
41
|
history?: {
|
|
20
42
|
appendHistory(rows: readonly MemoryHistoryAppendRow[]): Promise<void>;
|
|
21
43
|
};
|
|
@@ -26,10 +48,15 @@ export declare class PgMemoryEngineBackend implements MemoryBackend {
|
|
|
26
48
|
private readonly pgvectorSql;
|
|
27
49
|
private readonly clock;
|
|
28
50
|
private readonly history?;
|
|
51
|
+
/** Cumulative lost-row count — audit-line breakage must itself be auditable. */
|
|
29
52
|
private historyRowsLost;
|
|
53
|
+
/** design/81 rung indicator — same semantics as PgMemoryStore.vectorMode. */
|
|
30
54
|
get vectorMode(): "native" | "portable" | "lexical";
|
|
31
55
|
constructor(query: PgQueryFn, opts?: PgMemoryEngineBackendOptions);
|
|
56
|
+
/** The embed/search haystack — BYTE-EQUAL to FileBackend's lexical haystack (file-backend search). */
|
|
32
57
|
private haystackOf;
|
|
58
|
+
/** Dimension-guarded embedding parameter (mirrors PgMemoryStore.embeddingParam — wrong-length ⇒ null,
|
|
59
|
+
* the row falls open to the lexical stand-in instead of poisoning reads). */
|
|
33
60
|
private embeddingParam;
|
|
34
61
|
private headerFromRow;
|
|
35
62
|
private entryFromRow;
|
|
@@ -40,6 +67,9 @@ export declare class PgMemoryEngineBackend implements MemoryBackend {
|
|
|
40
67
|
}): Promise<ScoredMemoryEntry[]>;
|
|
41
68
|
applyPatches(patches: readonly NotePatch[]): Promise<PatchReport>;
|
|
42
69
|
private applyOne;
|
|
70
|
+
/** When the conditional write returns zero rows (a write landed inside the
|
|
71
|
+
* SELECT→write window), the report's `currentRev` must be the rev NOW — re-reporting the pre-race
|
|
72
|
+
* SELECT value could claim `baseRev === currentRev` alongside a "rev mismatch" reason. */
|
|
43
73
|
private freshRev;
|
|
44
74
|
getConsolidationCursor(scope: string): Promise<string | undefined>;
|
|
45
75
|
setConsolidationCursor(scope: string, cursor: string): Promise<void>;
|