@sema-agent/server 7.146.0 → 7.147.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/MIGRATION.md +384 -0
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/USAGE.md +170 -66
- package/deploy/facts/lanes.json +7 -0
- package/deploy/sema-up/README.md +2 -2
- package/deploy/sema-up/chart/templates/_helpers.tpl +22 -0
- package/deploy/sema-up/chart/templates/server-v4pro.yaml +5 -4
- package/deploy/sema-up/chart/templates/server.yaml +5 -4
- package/deploy/sema-up/chart/values.yaml +1 -1
- package/deploy/sema-up/cluster-up.sh +2 -1
- package/deploy/sema-up/lib/flagshape.sh +4 -0
- package/deploy/sema-up/lib/lanes.json +2 -5
- package/deploy/sema-up/sema-up.sh +12 -9
- package/deploy/sema-up/stack/compose.yaml +5 -4
- package/deploy/sema-up/stack/sema-stack-cluster.yaml +4 -3
- package/dist/approval-card.d.ts +4 -4
- package/dist/approval.d.ts +3 -3
- package/dist/audit.js +2 -2
- package/dist/bench/s1/live-deps.js +3 -1
- package/dist/boot/crash-last.js +2 -1
- package/dist/boot/device-lane.js +5 -5
- package/dist/boot/engine-lease.d.ts +12 -11
- package/dist/boot/execution-env.d.ts +2 -1
- package/dist/boot/execution-env.js +45 -33
- package/dist/boot/execution-lane.d.ts +37 -9
- package/dist/boot/execution-lane.js +74 -20
- package/dist/boot/exit-boundary.d.ts +1 -1
- package/dist/boot/exit-last.js +2 -1
- package/dist/boot/governance-seams.d.ts +2 -2
- package/dist/boot/leader.js +1 -1
- package/dist/boot/memory-boundary.d.ts +11 -11
- package/dist/boot/memory-boundary.js +3 -3
- package/dist/boot/memory-consolidation.d.ts +13 -24
- package/dist/boot/memory-consolidation.js +0 -13
- package/dist/boot/org-memory.js +3 -2
- package/dist/boot/parked-revive-gate.d.ts +1 -1
- package/dist/boot/parked-revive-gate.js +1 -1
- package/dist/boot/reapers.js +1 -1
- package/dist/boot/resolve-spec.js +91 -111
- package/dist/boot/retention-lane.d.ts +4 -42
- package/dist/boot/session-faces.d.ts +1 -0
- package/dist/boot/session-faces.js +8 -2
- package/dist/boot/stage-01-config.d.ts +1 -1
- package/dist/boot/stage-01-config.js +6 -2
- package/dist/boot/stage-02-web-admin-pull.d.ts +1 -1
- package/dist/boot/stage-02-web-admin-pull.js +10 -8
- package/dist/boot/stage-03-store-backend.d.ts +1 -1
- package/dist/boot/stage-04-stores.d.ts +1 -1
- package/dist/boot/stage-05-execution-env.d.ts +2 -2
- package/dist/boot/stage-05-execution-env.js +3 -3
- package/dist/boot/stage-06-runners.d.ts +3 -3
- package/dist/boot/stage-06-runners.js +1 -3
- package/dist/boot/stage-07-capability-layer.d.ts +3 -3
- package/dist/boot/stage-07-capability-layer.js +4 -9
- package/dist/boot/stage-08-reapers.d.ts +3 -3
- package/dist/boot/stage-09-leader.d.ts +4 -3
- package/dist/boot/stage-10-http-server.d.ts +4 -3
- package/dist/boot/stage-10-http-server.js +2 -1
- package/dist/boot/stores.d.ts +9 -0
- package/dist/boot/stores.js +18 -7
- package/dist/boot/web-admin.js +3 -3
- package/dist/capabilities/center-plugins.d.ts +2 -0
- package/dist/capabilities/center-plugins.js +6 -2
- package/dist/capabilities/composite-members.d.ts +1 -0
- package/dist/capabilities/composite-members.js +1 -0
- package/dist/capabilities/execution-lane.d.ts +7 -7
- package/dist/capabilities/execution-lane.js +2 -2
- package/dist/capabilities/hands-lane.d.ts +1 -1
- package/dist/capabilities/scenarios.d.ts +32 -18
- package/dist/capabilities/scenarios.js +13 -9
- package/dist/capabilities/settings-contract.d.ts +29 -0
- package/dist/capabilities/settings-contract.js +14 -0
- package/dist/capabilities/skills.d.ts +5 -5
- package/dist/capability-facts.d.ts +38 -0
- package/dist/capability-facts.js +34 -1
- package/dist/center-credential-renewer.js +3 -2
- package/dist/config-catalog.js +6 -5
- package/dist/config-invariants.d.ts +18 -3
- package/dist/config-invariants.js +36 -19
- package/dist/config-lkg.d.ts +1 -1
- package/dist/config-lkg.js +5 -6
- package/dist/config-provider.js +2 -0
- package/dist/config-types.d.ts +190 -186
- package/dist/config.d.ts +68 -5
- package/dist/config.js +80 -54
- package/dist/degenerate-instrument.js +1 -1
- package/dist/deploy-facts.js +3 -2
- package/dist/deployment-shape.d.ts +21 -12
- package/dist/deployment-shape.js +24 -6
- package/dist/env-facts.d.ts +7 -5
- package/dist/env-facts.js +10 -6
- package/dist/execution-config-root.d.ts +5 -5
- package/dist/execution-config-root.js +5 -5
- package/dist/execution-env-purpose.d.ts +14 -0
- package/dist/execution-env-purpose.js +29 -0
- package/dist/execution-lane-caps.d.ts +49 -86
- package/dist/execution-lane-caps.js +52 -62
- package/dist/execution-placement.d.ts +18 -2
- package/dist/execution-placement.js +19 -0
- package/dist/file-history-disclosure.d.ts +2 -2
- package/dist/fleet/drain-entry.d.ts +17 -10
- package/dist/fleet/drain-entry.js +1 -1
- package/dist/fleet/serving-lease.js +3 -4
- package/dist/history-anchor.d.ts +22 -0
- package/dist/history-anchor.js +14 -0
- package/dist/hooks/command-spawn.d.ts +1 -4
- package/dist/hooks/command-spawn.js +0 -11
- package/dist/hooks/hook-runner.d.ts +52 -8
- package/dist/hooks/hook-runner.js +160 -36
- package/dist/http/approval-sweeps.d.ts +2 -5
- package/dist/http/approval-sweeps.js +3 -2
- package/dist/http/checkpoint-ctx.d.ts +17 -0
- package/dist/http/checkpoint-ctx.js +6 -0
- package/dist/http/claim-latency.d.ts +10 -0
- package/dist/http/claim-latency.js +12 -0
- package/dist/http/dispatch.js +1 -1
- package/dist/http/durable-run-leg.js +2 -1
- package/dist/http/execution-context.d.ts +3 -1
- package/dist/http/execution-context.js +4 -0
- package/dist/http/memory-compliance-failure-reply.d.ts +1 -1
- package/dist/http/memory-compliance-failure-reply.js +3 -0
- package/dist/http/memory-store-refusal-reply.d.ts +3 -3
- package/dist/http/memory-store-refusal-reply.js +3 -0
- package/dist/http/owner-access.d.ts +11 -0
- package/dist/http/owner-access.js +7 -4
- package/dist/http/principal-gate.d.ts +3 -14
- package/dist/http/principal-gate.js +0 -13
- package/dist/http/request-guards.d.ts +1 -1
- package/dist/http/resume-legs.d.ts +7 -10
- package/dist/http/resume-legs.js +79 -50
- package/dist/http/rewind-files-reply.d.ts +34 -0
- package/dist/http/rewind-files-reply.js +36 -0
- package/dist/http/route-ctx.d.ts +32 -16
- package/dist/http/route-table.js +2 -0
- package/dist/http/routes/approvals-assistant.js +5 -25
- package/dist/http/routes/capabilities.js +8 -2
- package/dist/http/routes/devices.js +1 -1
- package/dist/http/routes/memory-origin.d.ts +1 -1
- package/dist/http/routes/notify-wake.js +2 -1
- package/dist/http/routes/projects.d.ts +70 -0
- package/dist/http/routes/projects.js +86 -0
- package/dist/http/routes/rules.js +30 -2
- package/dist/http/routes/runs.js +8 -8
- package/dist/http/routes/session-sync.js +27 -10
- package/dist/http/routes/sessions.d.ts +7 -1
- package/dist/http/routes/sessions.js +104 -2
- package/dist/http/routes/tasks.js +9 -3
- package/dist/http/server.d.ts +24 -10
- package/dist/http/server.js +17 -6
- package/dist/http/stored-body-replay.d.ts +5 -3
- package/dist/http/stored-body-replay.js +10 -1
- package/dist/http/wire-types.d.ts +19 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/instruction-source-notice.d.ts +1 -1
- package/dist/memory-embedder-reembed.d.ts +38 -0
- package/dist/memory-embedder-reembed.js +20 -0
- package/dist/memory-incident-sink.d.ts +0 -28
- package/dist/memory-incident-sink.js +5 -0
- package/dist/memory-scope.d.ts +2 -2
- package/dist/memory-scope.js +1 -1
- package/dist/memory-store-refusal.d.ts +17 -4
- package/dist/memory-store-refusal.js +1 -1
- package/dist/memory-sync-client.d.ts +2 -0
- package/dist/memory-sync-client.js +13 -11
- package/dist/memory-sync.js +1 -1
- package/dist/model-compat.d.ts +35 -21
- package/dist/model-compat.js +49 -21
- package/dist/model-entry-refusal.d.ts +11 -1
- package/dist/model-entry-refusal.js +7 -0
- package/dist/namespaced-rule-name.d.ts +18 -1
- package/dist/namespaced-rule-name.js +12 -0
- package/dist/observability/fail-open.d.ts +17 -9
- package/dist/observability/fail-open.js +17 -9
- package/dist/observability/metrics.d.ts +2 -0
- package/dist/observability/metrics.js +2 -0
- package/dist/observability/secret-env-scrub.d.ts +30 -4
- package/dist/observability/secret-env-scrub.js +15 -3
- package/dist/orchestration/workflow-agent-session-index.d.ts +7 -12
- package/dist/orchestration/workflow-agent-session-index.js +1 -6
- package/dist/orchestration/workflow-completion-inbox.d.ts +26 -6
- package/dist/orchestration/workflow-completion-inbox.js +63 -45
- package/dist/org-memory-admission.d.ts +5 -2
- package/dist/org-memory-admission.js +25 -10
- package/dist/parked-decide.d.ts +33 -26
- package/dist/parked-decide.js +36 -44
- package/dist/plugins/approval-ask-store-file.d.ts +10 -2
- package/dist/plugins/approval-ask-store-file.js +37 -4
- package/dist/plugins/approval-ask-store-memory.d.ts +5 -3
- package/dist/plugins/approval-ask-store-memory.js +11 -2
- package/dist/plugins/approval-ask-store-sql.d.ts +3 -0
- package/dist/plugins/approval-ask-store-sql.js +3 -1
- package/dist/plugins/blob-backend.d.ts +38 -195
- package/dist/plugins/blob-backend.js +33 -229
- package/dist/plugins/caching-session-store.d.ts +9 -4
- package/dist/plugins/checkpoint-index-columns.d.ts +1 -1
- package/dist/plugins/checkpoint-index-columns.js +3 -2
- package/dist/plugins/checkpoint-store-face.d.ts +1 -1
- package/dist/plugins/device-store-sql.d.ts +2 -2
- package/dist/plugins/device-store-sql.js +5 -10
- package/dist/plugins/execution-lane-rename-m40.d.ts +20 -0
- package/dist/plugins/execution-lane-rename-m40.js +10 -0
- package/dist/plugins/execution-placement-sql.d.ts +63 -88
- package/dist/plugins/execution-placement-sql.js +94 -54
- package/dist/plugins/file-run-store.d.ts +26 -12
- package/dist/plugins/file-run-store.js +63 -63
- package/dist/plugins/imported-layer-root-retirement.d.ts +17 -8
- package/dist/plugins/imported-layer-root-retirement.js +4 -8
- package/dist/plugins/inbox-payload-column.d.ts +14 -0
- package/dist/plugins/inbox-payload-column.js +13 -0
- package/dist/plugins/local-checkpoint-store.d.ts +5 -0
- package/dist/plugins/local-checkpoint-store.js +11 -7
- package/dist/plugins/local-data-dir-modes-m39.d.ts +48 -0
- package/dist/plugins/local-data-dir-modes-m39.js +182 -0
- package/dist/plugins/local-engine-high-water.d.ts +11 -0
- package/dist/plugins/local-engine-high-water.js +59 -0
- package/dist/plugins/local-session-store.d.ts +91 -25
- package/dist/plugins/local-session-store.js +124 -45
- package/dist/plugins/local-task-attachment-store.d.ts +2 -0
- package/dist/plugins/local-task-attachment-store.js +10 -11
- package/dist/plugins/memory-embedder-fingerprint.d.ts +33 -10
- package/dist/plugins/memory-embedder-fingerprint.js +52 -12
- package/dist/plugins/memory-embedder.d.ts +1 -1
- package/dist/plugins/memory-embedder.js +2 -2
- package/dist/plugins/memory-engine-pg.d.ts +4 -3
- package/dist/plugins/memory-engine-pg.js +4 -4
- package/dist/plugins/memory-engine-sql-apply.d.ts +13 -4
- package/dist/plugins/memory-engine-sql-apply.js +1 -1
- package/dist/plugins/memory-engine-tidb.d.ts +8 -5
- package/dist/plugins/memory-engine-tidb.js +7 -8
- package/dist/plugins/one-time-migrations.d.ts +145 -35
- package/dist/plugins/one-time-migrations.js +272 -120
- package/dist/plugins/owner-only-file-mode.d.ts +29 -0
- package/dist/plugins/owner-only-file-mode.js +141 -0
- package/dist/plugins/permission-rule-store-file.d.ts +8 -8
- package/dist/plugins/permission-rule-store-file.js +14 -2
- package/dist/plugins/pg-pool.d.ts +2 -1
- package/dist/plugins/pg-pool.js +11 -4
- package/dist/plugins/release-version.d.ts +20 -0
- package/dist/plugins/release-version.js +28 -0
- package/dist/plugins/remote-env-adb.d.ts +20 -4
- package/dist/plugins/remote-env-adb.js +39 -11
- package/dist/plugins/remote-env-e2b.d.ts +12 -3
- package/dist/plugins/remote-env-e2b.js +6 -4
- package/dist/plugins/remote-env-host.d.ts +9 -1
- package/dist/plugins/remote-env-host.js +6 -5
- package/dist/plugins/remote-env-k8s.d.ts +5 -2
- package/dist/plugins/remote-env-k8s.js +15 -4
- package/dist/plugins/remote-env-local-docker.d.ts +4 -1
- package/dist/plugins/remote-env-local-docker.js +3 -3
- package/dist/plugins/remote-env-ssh.d.ts +8 -2
- package/dist/plugins/remote-env-ssh.js +26 -24
- package/dist/plugins/remote-shell.d.ts +59 -30
- package/dist/plugins/remote-shell.js +175 -62
- package/dist/plugins/retention-declaration.d.ts +37 -0
- package/dist/plugins/retention-declaration.js +9 -0
- package/dist/plugins/retention-deployment.d.ts +126 -0
- package/dist/plugins/retention-deployment.js +88 -0
- package/dist/plugins/retention-lane-store-sql.d.ts +74 -4
- package/dist/plugins/retention-lane-store-sql.js +103 -1
- package/dist/plugins/retention-sql.d.ts +29 -0
- package/dist/plugins/retention-sql.js +8 -0
- package/dist/plugins/schema-consistency.d.ts +0 -6
- package/dist/plugins/schema-consistency.js +1 -2
- package/dist/plugins/schema-ensure-legs.d.ts +1 -1
- package/dist/plugins/schema-ensure-legs.js +11 -1
- package/dist/plugins/session-ext-table.d.ts +74 -0
- package/dist/plugins/session-ext-table.js +121 -0
- package/dist/plugins/session-fork.d.ts +1 -1
- package/dist/plugins/session-row-sql.d.ts +8 -7
- package/dist/plugins/session-row-sql.js +15 -7
- package/dist/plugins/session-store-sql.d.ts +131 -0
- package/dist/plugins/session-store-sql.js +298 -0
- package/dist/plugins/session-workspace-cell.d.ts +2 -2
- package/dist/plugins/session-workspace-cell.js +2 -2
- package/dist/plugins/shared-memory-store-sql.d.ts +10 -0
- package/dist/plugins/shared-memory-store-sql.js +13 -13
- package/dist/plugins/snapshot-bucket-presence.js +1 -1
- package/dist/plugins/sql-driver.d.ts +23 -7
- package/dist/plugins/sql-driver.js +41 -8
- package/dist/plugins/sql-errors.d.ts +5 -2
- package/dist/plugins/sql-errors.js +4 -0
- package/dist/plugins/store-backend.d.ts +35 -8
- package/dist/plugins/store-backend.js +184 -62
- package/dist/plugins/store-contracts.d.ts +9 -2
- package/dist/plugins/store-contracts.js +1 -0
- package/dist/plugins/task-attachment-store.d.ts +6 -8
- package/dist/plugins/task-attachment-store.js +15 -10
- package/dist/plugins/task-list-store-sql.d.ts +1 -1
- package/dist/plugins/text-column-capacity.d.ts +21 -0
- package/dist/plugins/text-column-capacity.js +5 -0
- package/dist/plugins/tidb-pool.d.ts +3 -2
- package/dist/plugins/tidb-pool.js +19 -31
- package/dist/plugins/user-input-ledger-sql.d.ts +1 -1
- package/dist/read-face-posture.d.ts +6 -6
- package/dist/read-face-posture.js +2 -2
- package/dist/request-value-closure.d.ts +5 -5
- package/dist/request-value-closure.js +1 -1
- package/dist/rules-consent.d.ts +41 -13
- package/dist/rules-consent.js +101 -53
- package/dist/run-local.js +17 -13
- package/dist/runs.d.ts +48 -30
- package/dist/runs.js +26 -16
- package/dist/runtime-caps-resolver.d.ts +15 -8
- package/dist/runtime-caps-resolver.js +14 -10
- package/dist/sealed-key-layout.d.ts +2 -3
- package/dist/sealed-key-layout.js +0 -1
- package/dist/sealed-key.js +7 -5
- package/dist/security.d.ts +5 -3
- package/dist/sema-config-dir.js +2 -2
- package/dist/server-secret-env.d.ts +2 -0
- package/dist/service-version.d.ts +2 -1
- package/dist/service-version.js +2 -2
- package/dist/session-error-wire.d.ts +1 -1
- package/dist/session-incarnation.d.ts +8 -5
- package/dist/session-resident-background.d.ts +85 -32
- package/dist/session-resident-background.js +75 -7
- package/dist/session-row.d.ts +1 -1
- package/dist/session-sync-kernel.d.ts +1 -1
- package/dist/session-workspace.d.ts +11 -2
- package/dist/session-workspace.js +5 -0
- package/dist/sighup-idle.d.ts +1 -1
- package/dist/store-posture.d.ts +2 -1
- package/dist/stored-request-hooks-m20.d.ts +3 -2
- package/dist/stored-request-hooks-m20.js +19 -14
- package/dist/stores-sql/blob-index-sql.d.ts +148 -0
- package/dist/stores-sql/blob-index-sql.js +154 -0
- package/dist/stores-sql/checkpoint-store-sql.d.ts +1 -1
- package/dist/stores-sql/checkpoint-store-sql.js +11 -27
- package/dist/{plugins → stores-sql}/file-history-store-sql.d.ts +23 -11
- package/dist/{plugins → stores-sql}/file-history-store-sql.js +23 -18
- package/dist/{plugins → stores-sql}/pg-session-storage.d.ts +23 -76
- package/dist/{plugins → stores-sql}/pg-session-storage.js +80 -209
- package/dist/{plugins → stores-sql}/retention-store-sql.d.ts +123 -217
- package/dist/{plugins → stores-sql}/retention-store-sql.js +66 -190
- package/dist/{plugins → stores-sql}/session-event-payload.d.ts +1 -1
- package/dist/{plugins → stores-sql}/session-event-payload.js +1 -1
- package/dist/stores-sql/session-policy-store-sql.d.ts +1 -1
- package/dist/stores-sql/session-write-hooks.d.ts +59 -0
- package/dist/stores-sql/session-write-hooks.js +2 -0
- package/dist/{plugins → stores-sql}/tidb-session-storage.d.ts +10 -11
- package/dist/{plugins → stores-sql}/tidb-session-storage.js +10 -21
- package/dist/{plugins → stores-sql}/tidb-session-store.d.ts +32 -122
- package/dist/{plugins → stores-sql}/tidb-session-store.js +71 -171
- package/dist/stores-sql/tool-result-store-sql.d.ts +1 -1
- package/dist/stores-sql/tool-result-store-sql.js +1 -1
- package/dist/stores-sql/windowed-session-storage.d.ts +56 -0
- package/dist/stores-sql/windowed-session-storage.js +61 -0
- package/dist/task-a2a.d.ts +7 -1
- package/dist/task-a2a.js +15 -14
- package/dist/task-cwd.d.ts +11 -3
- package/dist/task-cwd.js +17 -1
- package/dist/task-mcp.d.ts +10 -2
- package/dist/task-mcp.js +13 -16
- package/dist/task-settings.d.ts +9 -4
- package/dist/task-settings.js +17 -6
- package/dist/tool-approval.d.ts +21 -8
- package/dist/tool-approval.js +10 -6
- package/dist/trace/core-keyset-guard.d.ts +9 -3
- package/dist/trace/engine-notice-wire.d.ts +1 -1
- package/dist/trace/engine-notice-wire.js +2 -0
- package/dist/trace/exit-seat.d.ts +23 -1
- package/dist/trace/exit-seat.js +3 -0
- package/dist/trace/project.d.ts +33 -16
- package/dist/trace/project.js +12 -9
- package/dist/trace/redact.d.ts +1 -1
- package/dist/trace/redact.js +61 -73
- package/dist/trace/self-minted-wire.d.ts +263 -10
- package/dist/trace/self-minted-wire.js +90 -2
- package/dist/trace/sema-provenance.d.ts +45 -41
- package/dist/trace/sema-provenance.js +81 -10
- package/dist/trace/task-notification-facets.d.ts +70 -2
- package/dist/trace/task-notification-facets.js +71 -1
- package/dist/trace/wire-projection-faces.d.ts +38 -2
- package/dist/trace/wire-projection-faces.js +26 -1
- package/dist/unread-request-members.d.ts +66 -0
- package/dist/unread-request-members.js +41 -0
- package/dist/user-input-ledger.d.ts +2 -2
- package/dist/web-admin-client/apply-effective.js +22 -26
- package/dist/web-admin-client/candidate-gate.d.ts +35 -3
- package/dist/web-admin-client/candidate-gate.js +53 -5
- package/dist/web-admin-client/center-request.d.ts +4 -1
- package/dist/web-admin-client/center-request.js +2 -1
- package/dist/web-admin-client/effective-keys.js +0 -1
- package/dist/web-admin-client/facade.d.ts +1 -1
- package/dist/web-admin-client/http-client.d.ts +1 -0
- package/dist/web-admin-client/http-client.js +17 -9
- package/dist/web-admin-client/restart-signal.js +5 -2
- package/dist/web-admin-client/skills-mcp.d.ts +20 -6
- package/dist/web-admin-client/skills-mcp.js +26 -21
- package/dist/web-admin-client/types.d.ts +34 -49
- package/docs/DEVICE-EXECUTOR-PROTOCOL.md +2 -2
- package/package.json +13 -12
- package/scripts/drain-check-local.mjs +2 -28
- package/scripts/drain-check.mysql.sql +2 -18
- package/scripts/drain-check.pg.sql +2 -18
- package/wire-changes/server@7.147.0.json +813 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { captureFileBackupViaEnv, applyFileRestoreViaEnv, fileHistoryModeProvenDifferent, worldStillMatchesMint, annulProofFailure, boundaryPublishVerdict, fileHistoryDescribeTrackKey, fileHistoryTrackKeyOf, fileHistoryResolveTrackKey, fileHistoryExportDigest, validateFileHistoryExport, resolveFileHistoryRetention, fileHistoryBoundariesToKeep, } from "@sema-agent/core";
|
|
3
|
-
import { BlobTooLargeError,
|
|
4
|
-
import { mysqlDriver, pgDriver } from "
|
|
5
|
-
import { isMissingColumnError, retryOnDeadlock } from "
|
|
6
|
-
import { describeProbedTableDrift } from "
|
|
3
|
+
import { BlobTooLargeError, SqlBlobIndex } from "./blob-index-sql.js";
|
|
4
|
+
import { mysqlDriver, pgDriver } from "../plugins/sql-driver.js";
|
|
5
|
+
import { isMissingColumnError, retryOnDeadlock } from "../plugins/sql-errors.js";
|
|
6
|
+
import { describeProbedTableDrift } from "../plugins/schema-drift-sentence.js";
|
|
7
7
|
import { recordFailOpen } from "../observability/fail-open.js";
|
|
8
8
|
import { foldCaughtFailure } from "../file-history-disclosure.js";
|
|
9
9
|
export const FILE_HISTORY_BLOB_TABLE = "file_history_blob";
|
|
@@ -28,17 +28,22 @@ export class SqlFileHistoryStore {
|
|
|
28
28
|
pool;
|
|
29
29
|
blobExchange = {
|
|
30
30
|
put: (hash, bytes) => this.putExchangedBlob(hash, bytes),
|
|
31
|
-
get: (hash) => this.blobs.
|
|
32
|
-
has: (hashes) => this.blobs.
|
|
31
|
+
get: (hash) => this.blobs.get(hash),
|
|
32
|
+
has: (hashes) => this.blobs.has([...hashes]),
|
|
33
33
|
};
|
|
34
34
|
blobs;
|
|
35
35
|
spentAttempts = new Set();
|
|
36
36
|
activeAttempts = new Set();
|
|
37
37
|
boundaryKeep;
|
|
38
|
-
constructor(db, pool,
|
|
38
|
+
constructor(db, pool, opts) {
|
|
39
39
|
this.db = db;
|
|
40
40
|
this.pool = pool;
|
|
41
|
-
this.blobs =
|
|
41
|
+
this.blobs = new SqlBlobIndex(this.db.dialect, this.pool, {
|
|
42
|
+
table: FILE_HISTORY_BLOB_TABLE,
|
|
43
|
+
...(opts?.blobs !== undefined ? { bytes: opts.blobs } : {}),
|
|
44
|
+
...(opts?.blobSqlMaxBytes !== undefined ? { maxBytes: opts.blobSqlMaxBytes } : {}),
|
|
45
|
+
...(opts?.log !== undefined ? { log: opts.log } : {}),
|
|
46
|
+
});
|
|
42
47
|
this.boundaryKeep = resolveFileHistoryRetention(this.db.dialect === "mysql" ? "TiDBFileHistoryStore" : "PgFileHistoryStore", opts?.retention);
|
|
43
48
|
}
|
|
44
49
|
q(mysql, pg) {
|
|
@@ -95,7 +100,7 @@ export class SqlFileHistoryStore {
|
|
|
95
100
|
const baseAvailable = cap.state !== "unreadable";
|
|
96
101
|
let v1;
|
|
97
102
|
if (cap.state === "file") {
|
|
98
|
-
await this.blobs.
|
|
103
|
+
await this.blobs.put(cap.hash, cap.bytes);
|
|
99
104
|
v1 = { blobHash: cap.hash, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) };
|
|
100
105
|
}
|
|
101
106
|
else if (cap.state === "absent") {
|
|
@@ -344,7 +349,7 @@ export class SqlFileHistoryStore {
|
|
|
344
349
|
staged.set(t.keyHash, { kind: "unchanged", version: last.version });
|
|
345
350
|
continue;
|
|
346
351
|
}
|
|
347
|
-
await this.blobs.
|
|
352
|
+
await this.blobs.put(cap.hash, cap.bytes);
|
|
348
353
|
staged.set(t.keyHash, { kind: "changed", blobHash: cap.hash, ...(cap.mode !== undefined ? { mode: cap.mode } : {}), ...(cap.parentIdent !== undefined ? { parentIdent: cap.parentIdent } : {}) });
|
|
349
354
|
}
|
|
350
355
|
const verdict = boundaryPublishVerdict({ aborted: signal?.aborted === true });
|
|
@@ -471,7 +476,7 @@ export class SqlFileHistoryStore {
|
|
|
471
476
|
if (rec.blobHash === null)
|
|
472
477
|
target = { absent: true };
|
|
473
478
|
else {
|
|
474
|
-
const bytes = await this.blobs.
|
|
479
|
+
const bytes = await this.blobs.get(rec.blobHash);
|
|
475
480
|
if (bytes === undefined) {
|
|
476
481
|
ledger.failed.push({ path: t.trackKey, reason: `blob ${rec.blobHash} missing (store integrity)` });
|
|
477
482
|
continue;
|
|
@@ -594,14 +599,14 @@ export class SqlFileHistoryStore {
|
|
|
594
599
|
const orphans = rows.map((r) => String(r.blob_hash));
|
|
595
600
|
if (orphans.length === 0)
|
|
596
601
|
return 0;
|
|
597
|
-
return this.blobs.
|
|
602
|
+
return this.blobs.sweep(orphans);
|
|
598
603
|
}
|
|
599
604
|
async putExchangedBlob(hash, bytes) {
|
|
600
605
|
if (sha256hex(bytes) !== hash) {
|
|
601
606
|
return { ok: false, error: { code: "adopt_failed", message: `blob ${hash}: the bytes do not hash to this address — nothing stored`, permanence: "terminal" } };
|
|
602
607
|
}
|
|
603
608
|
try {
|
|
604
|
-
await this.blobs.
|
|
609
|
+
await this.blobs.put(hash, bytes);
|
|
605
610
|
return { ok: true };
|
|
606
611
|
}
|
|
607
612
|
catch (err) {
|
|
@@ -760,7 +765,7 @@ export class SqlFileHistoryStore {
|
|
|
760
765
|
if (existing !== null && !sameGraph) {
|
|
761
766
|
return { ok: false, error: { code: "conflict", message: `importHistory target "${scope}" already holds a DIFFERENT history — a first import requires an empty target and a retry is legal only for the identical envelope (atomic visibility prevents half-graphs; this law prevents publishing the wrong complete graph over locally-grown history)` } };
|
|
762
767
|
}
|
|
763
|
-
const verified = await this.verifySourceBlobs(data, srcGetBlob, sameGraph ? undefined : (hash, bytes) => this.blobs.
|
|
768
|
+
const verified = await this.verifySourceBlobs(data, srcGetBlob, sameGraph ? undefined : (hash, bytes) => this.blobs.put(hash, bytes));
|
|
764
769
|
if (!verified.ok)
|
|
765
770
|
return verified;
|
|
766
771
|
if (sameGraph)
|
|
@@ -813,13 +818,13 @@ export class SqlFileHistoryStore {
|
|
|
813
818
|
}
|
|
814
819
|
}
|
|
815
820
|
export class TiDBFileHistoryStore extends SqlFileHistoryStore {
|
|
816
|
-
constructor(pool,
|
|
817
|
-
super(mysqlDriver(pool), pool,
|
|
821
|
+
constructor(pool, opts) {
|
|
822
|
+
super(mysqlDriver(pool), pool, opts);
|
|
818
823
|
}
|
|
819
824
|
}
|
|
820
825
|
export class PgFileHistoryStore extends SqlFileHistoryStore {
|
|
821
|
-
constructor(pool,
|
|
822
|
-
super(pgDriver(pool), pool,
|
|
826
|
+
constructor(pool, opts) {
|
|
827
|
+
super(pgDriver(pool), pool, opts);
|
|
823
828
|
}
|
|
824
829
|
}
|
|
825
830
|
export async function assertFileHistorySchema(query, dialect) {
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type AcquiredSession, type PlacedSessionRow, type SessionHead, type SessionMetadata, type SessionPlacementRecord, type SessionStore, type SessionTreeEntry, type SessionWriteOptions } from "@sema-agent/core";
|
|
2
2
|
import type { Pool, PoolClient } from "pg";
|
|
3
|
-
import
|
|
4
|
-
import { type
|
|
5
|
-
import { type PlacementAcquireOpts } from "./session-placement.js";
|
|
3
|
+
import { WindowedSessionStorage } from "./windowed-session-storage.js";
|
|
4
|
+
import { type PlacementAcquireOpts } from "../plugins/session-placement.js";
|
|
6
5
|
import { type StagingHandle } from "../session-sync-kernel.js";
|
|
7
|
-
import { type InstructionSourceBaseline } from "../instruction-source-notice.js";
|
|
8
|
-
import type { SessionWorkspace } from "../session-workspace.js";
|
|
9
6
|
import type { RetentionDeclaration } from "@sema-agent/core";
|
|
10
|
-
import {
|
|
11
|
-
import { type
|
|
12
|
-
import { type
|
|
7
|
+
import type { SessionWriteHooks } from "./session-write-hooks.js";
|
|
8
|
+
import { type IndexSpec } from "../plugins/ensure-index.js";
|
|
9
|
+
import { type ForkPlacement, type ForkTarget, type ForkToOutcome } from "../plugins/session-fork.js";
|
|
13
10
|
/**
|
|
14
11
|
* PG-dialect DDL for the L1 session log, translated from tidb-pool.ts SCHEMA_STATEMENTS:
|
|
15
12
|
* JSON→JSONB, DATETIME(3)→TIMESTAMPTZ(3), inline `KEY`/`UNIQUE KEY`→separate CREATE INDEX (UNIQUE for uq_session_event_entry).
|
|
@@ -23,12 +20,12 @@ export declare const SESSION_INDEXES: readonly IndexSpec[];
|
|
|
23
20
|
/** Idempotent schema apply for this store's tables (the test calls this; production aggregation is separate). */
|
|
24
21
|
export declare function ensureSchema(pool: Pool | PoolClient): Promise<void>;
|
|
25
22
|
/**
|
|
26
|
-
* PostgreSQL-backed
|
|
23
|
+
* PostgreSQL-backed session storage — the durable L1 event log for one session (the window view and its reads: {@link WindowedSessionStorage}).
|
|
27
24
|
*
|
|
28
25
|
* Behaviourally identical to {@link TiDBSessionStorage}; see that file's class doc for the F2/F3 seams. The only
|
|
29
26
|
* differences are dialectal (placeholders, `IS NOT DISTINCT FROM`, jsonb, rowCount, transaction handle).
|
|
30
27
|
*/
|
|
31
|
-
export declare class PgSessionStorage extends
|
|
28
|
+
export declare class PgSessionStorage extends WindowedSessionStorage {
|
|
32
29
|
private readonly pool;
|
|
33
30
|
private readonly sessionId;
|
|
34
31
|
private readonly floorSeq;
|
|
@@ -40,16 +37,14 @@ export declare class PgSessionStorage extends BaseSessionStorage {
|
|
|
40
37
|
static wake(pool: Pool, sessionId: string): Promise<PgSessionStorage | null>;
|
|
41
38
|
/** The bounded-window floor = last compaction's firstKeptEntryId (and its seq). @see TiDBSessionStorage.computeFloor */
|
|
42
39
|
private static computeFloor;
|
|
43
|
-
/** Sub-floor lookups (e.g. a label target) aren't in the loaded tail —
|
|
44
|
-
|
|
45
|
-
appendEntry(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
|
|
46
|
-
setLeafId(leafId: string | null, opts?: SessionWriteOptions): Promise<void>;
|
|
40
|
+
/** Sub-floor lookups (e.g. a label target) aren't in the loaded tail — read the durable log. */
|
|
41
|
+
protected readBelowFloor(id: string): Promise<SessionTreeEntry | undefined>;
|
|
47
42
|
/**
|
|
48
43
|
* Atomically: CAS the meta leaf (+bump leaf_seq), then append the event at the new seq.
|
|
49
44
|
* The `(session_id, seq)` primary key is the backstop — a racing writer that grabbed the same
|
|
50
45
|
* seq makes our INSERT fail with a duplicate-key (23505), which we translate to a conflict too.
|
|
51
46
|
*/
|
|
52
|
-
|
|
47
|
+
protected persist(entry: SessionTreeEntry, opts?: SessionWriteOptions): Promise<void>;
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
50
|
* PostgreSQL-backed {@link SessionStore} — the PG twin of {@link TiDBSessionStore}. Maps the
|
|
@@ -57,7 +52,7 @@ export declare class PgSessionStorage extends BaseSessionStorage {
|
|
|
57
52
|
*/
|
|
58
53
|
export declare class PgSessionStore implements SessionStore {
|
|
59
54
|
private readonly pool;
|
|
60
|
-
/** 托管留存声明 = 装配交给它的词(TiDB 孪生同格)。读法见 `retention-
|
|
55
|
+
/** 托管留存声明 = 装配交给它的词(TiDB 孪生同格)。读法见 `retention-declaration.ts` 的 {@link MANAGED_RETENTION}。 */
|
|
61
56
|
readonly retention: RetentionDeclaration;
|
|
62
57
|
/** [ref] C18(core 5.48.0 [ref]):placement 声明(TiDB 孪生同格,义务逐条见
|
|
63
58
|
* `src/plugins/session-placement.ts` 顶注)。 */
|
|
@@ -70,12 +65,11 @@ export declare class PgSessionStore implements SessionStore {
|
|
|
70
65
|
readonly durability: "durable";
|
|
71
66
|
/** In-flight acquisitions keyed by id, so concurrent acquire(sameId) in one process share one. */
|
|
72
67
|
private readonly pending;
|
|
73
|
-
/**
|
|
74
|
-
readonly
|
|
75
|
-
|
|
76
|
-
private readonly db;
|
|
77
|
-
constructor(pool: Pool, opts?: {
|
|
68
|
+
/** 部署的事务内钩(TiDB 孪生同格,`session-write-hooks.ts`)。 */
|
|
69
|
+
private readonly hooks;
|
|
70
|
+
constructor(pool: Pool, opts: {
|
|
78
71
|
readonly retention?: RetentionDeclaration;
|
|
72
|
+
readonly hooks: SessionWriteHooks;
|
|
79
73
|
});
|
|
80
74
|
acquire(sessionId?: string, opts?: PlacementAcquireOpts): Promise<AcquiredSession>;
|
|
81
75
|
private load;
|
|
@@ -107,53 +101,6 @@ export declare class PgSessionStore implements SessionStore {
|
|
|
107
101
|
private deletePlacedSession;
|
|
108
102
|
/** [ref]:placed id 拒绝 session-sync 的整段换装(TiDB 孪生 {@link TiDBSessionStore.assertNotPlaced} 同义)。 */
|
|
109
103
|
private assertNotPlaced;
|
|
110
|
-
/** @see TiDBSessionStore.listSessions — session identity from session_meta (owner-filtered), task_run LEFT JOIN for preview. */
|
|
111
|
-
listSessions(opts: {
|
|
112
|
-
owner?: string;
|
|
113
|
-
includeUnowned?: boolean;
|
|
114
|
-
cursor?: {
|
|
115
|
-
lastActivityAt: string;
|
|
116
|
-
sessionId: string;
|
|
117
|
-
};
|
|
118
|
-
limit: number;
|
|
119
|
-
q?: string;
|
|
120
|
-
}): Promise<SessionSummary[]>;
|
|
121
|
-
/** @see TiDBSessionStore.listSessionRows — the PG twin. */
|
|
122
|
-
listSessionRows(opts: {
|
|
123
|
-
owner?: string;
|
|
124
|
-
includeUnowned?: boolean;
|
|
125
|
-
cursor?: {
|
|
126
|
-
lastActivityAt: string;
|
|
127
|
-
sessionId: string;
|
|
128
|
-
};
|
|
129
|
-
limit: number;
|
|
130
|
-
q?: string;
|
|
131
|
-
}): Promise<Array<SessionRowAnswer<SessionSummary>>>;
|
|
132
|
-
/** @see TiDBSessionStore.sessionSummaryOf — the PG twin (same projection, run-preview subqueries scoped to the id). */
|
|
133
|
-
sessionSummaryOf(sessionId: string): Promise<SessionSummary | undefined>;
|
|
134
|
-
/** @see TiDBSessionStore.listRowOf — the PG twin. */
|
|
135
|
-
private listRowOf;
|
|
136
|
-
/** @see TiDBSessionStore.writeSessionRowCells — the PG twin (the same SQL half, `session-row-sql.ts`; only the statement text differs). */
|
|
137
|
-
writeSessionRowCells(sessionId: string, cells: SessionRowPatch, how: ClientSessionRowWrite): Promise<SessionRowWriteOutcome<SessionSummary>>;
|
|
138
|
-
writeSessionRowCells(sessionId: string, cells: SessionRowPatch, how: ReplaySessionRowWrite): Promise<ReplaySessionRowWriteOutcome<SessionSummary>>;
|
|
139
|
-
/** @see TiDBSessionStore.selectListRows — the PG twin. `where` already carries `$n` placeholders numbered over `params`;
|
|
140
|
-
* the run scope and the LIMIT take the next numbers (PG binds by number, so text order does not matter). */
|
|
141
|
-
private selectListRows;
|
|
142
|
-
/** @see TiDBSessionStore.probeTitle — the PG twin. */
|
|
143
|
-
probeTitle(sessionId: string): Promise<"none" | "untitled" | "titled">;
|
|
144
|
-
/** @see TiDBSessionStore.setTitleIfNull — the PG twin (the auto-titler's NULL-only write). */
|
|
145
|
-
setTitleIfNull(sessionId: string, title: string): Promise<boolean>;
|
|
146
|
-
/** @see TiDBSessionStore.readInstructionSource — the PG twin. */
|
|
147
|
-
readInstructionSource(sessionId: string): Promise<InstructionSourceBaseline>;
|
|
148
|
-
/** @see TiDBSessionStore.recordInstructionSource — the PG twin (same CAS predicate, same per-query timeout; node-pg's
|
|
149
|
-
* `query_timeout` rejects AND pg-pool destroys that client, so a lock-stuck baseline write does not keep a pooled
|
|
150
|
-
* connection). */
|
|
151
|
-
recordInstructionSource(sessionId: string, expected: InstructionSourceBaseline, source: string | null): Promise<void>;
|
|
152
|
-
/** @see TiDBSessionStore.readSessionWorkspace — the PG twin (same projection-as-text, same cell owner). */
|
|
153
|
-
readSessionWorkspace(sessionId: string): Promise<SessionWorkspace | undefined>;
|
|
154
|
-
/** @see TiDBSessionStore.recordSessionWorkspace — the PG twin (whole-cell overwrite fenced to the occupant; `pgSafeJsonStringify` + `::jsonb`, like every PG JSON write;
|
|
155
|
-
* the general query surface — the pool-wide `DB_QUERY_TIMEOUT_MS` server-side `statement_timeout` bounds it, no per-call client timer). */
|
|
156
|
-
recordSessionWorkspace(sessionId: string, incarnation: string, workspace: SessionWorkspace): Promise<void>;
|
|
157
104
|
/** @see TiDBSessionStore.fork — core 契约 `fork(sourceId, owner?, opts?)` = {@link forkTo} 的投影(新铸 uuidv7 目标,`forkByFreshId`;三店同一只;`opts.placement` 进委派分区)。 */
|
|
158
105
|
fork(sourceId: string, owner?: string | null, opts?: {
|
|
159
106
|
placement?: ForkPlacement;
|
|
@@ -181,16 +128,16 @@ export declare class PgSessionStore implements SessionStore {
|
|
|
181
128
|
}): Promise<AsyncIterable<SessionTreeEntry> | null>;
|
|
182
129
|
/** @see TiDBSessionStore.importEntries — 2c session-sync IMPORT: core `validateEntriesForImport` gate FIRST (fail-closed),
|
|
183
130
|
* then persist its verbatim output (re-seq dense from 0, ids/parents/payload/ts unchanged) in ONE txn, **lock-or-create, meta first**
|
|
184
|
-
* (
|
|
131
|
+
* (占行 → 锁行判是不是本次占下的 → 部署的事务内钩 `import` → 事件);owner = the RE-STAMPED authenticated principal (never the bundle's). */
|
|
185
132
|
importEntries(sessionId: string, owner: string | null, entries: SessionTreeEntry[]): Promise<void>;
|
|
186
|
-
/** @see TiDBSessionStore.replaceEntries — 2c (§7/§8) IDEMPOTENT REPLACE: core `validateEntriesForImport` gate FIRST
|
|
187
|
-
* (
|
|
188
|
-
*
|
|
189
|
-
* ONE txn. Safe to run OVER an existing session (fast-forward / §8 retry)
|
|
133
|
+
/** @see TiDBSessionStore.replaceEntries — 2c (§7/§8) IDEMPOTENT REPLACE: core `validateEntriesForImport` gate FIRST (fail-closed), then the row
|
|
134
|
+
* (absent ⇒ created as a fresh occupant; existing ⇒ rewritten in place only when it is the importer's — `owner IS NOT DISTINCT FROM $n`, the PG
|
|
135
|
+
* `<=>` — and not a delegation transcript; the occupant keeps its incarnation and deployment cells), then the SHARED body (the hook, then the old
|
|
136
|
+
* events out and the new ones in), ALL in ONE txn. Safe to run OVER an existing session (fast-forward / §8 retry). */
|
|
190
137
|
replaceEntries(sessionId: string, owner: string | null, entries: SessionTreeEntry[]): Promise<void>;
|
|
191
138
|
/** @see TiDBSessionStore.writeImportedLog — the shared write half of importEntries / replaceEntries (ONE source, no drift):
|
|
192
|
-
* session_meta FIRST (create = occupy the row, an existing one ⇒ refused; replace =
|
|
193
|
-
*
|
|
139
|
+
* session_meta FIRST (create = occupy the row, an existing one ⇒ refused; replace = owner-guarded in-place rewrite of the locked row),
|
|
140
|
+
* the deployment's transaction hook `import` on THIS connection, then the entries re-seq dense from 0 (ids/parents/payload/ts verbatim).
|
|
194
141
|
* Runs inside the caller's open txn (`conn` already in BEGIN); the caller owns COMMIT/ROLLBACK + the validate gate. */
|
|
195
142
|
private writeImportedLog;
|
|
196
143
|
/** @see TiDBSessionStore.beginImportStaging — 2c P1d-β PUSH staging: stream batches into the shadow id
|