@cleocode/core 2026.10.1 → 2026.10.2
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/build-provenance.json +2 -2
- package/dist/cloud/journal.d.ts +9 -5
- package/dist/cloud/journal.d.ts.map +1 -1
- package/dist/cloud/journal.js +29 -8
- package/dist/cloud/journal.js.map +1 -1
- package/dist/cloud/manifest-check.d.ts +140 -4
- package/dist/cloud/manifest-check.d.ts.map +1 -1
- package/dist/cloud/manifest-check.js +309 -10
- package/dist/cloud/manifest-check.js.map +1 -1
- package/dist/cloud/nexus-attach.d.ts +25 -0
- package/dist/cloud/nexus-attach.d.ts.map +1 -1
- package/dist/cloud/nexus-attach.js +81 -6
- package/dist/cloud/nexus-attach.js.map +1 -1
- package/dist/cloud/nexus-cloud-activity.d.ts +37 -0
- package/dist/cloud/nexus-cloud-activity.d.ts.map +1 -0
- package/dist/cloud/nexus-cloud-activity.js +79 -0
- package/dist/cloud/nexus-cloud-activity.js.map +1 -0
- package/dist/cloud/nexus-cloud-status.d.ts.map +1 -1
- package/dist/cloud/nexus-cloud-status.js +36 -0
- package/dist/cloud/nexus-cloud-status.js.map +1 -1
- package/dist/cloud/nexus-device.d.ts +1 -1
- package/dist/cloud/nexus-enrol.d.ts.map +1 -1
- package/dist/cloud/nexus-enrol.js +5 -0
- package/dist/cloud/nexus-enrol.js.map +1 -1
- package/dist/cloud/nexus-home.d.ts +74 -0
- package/dist/cloud/nexus-home.d.ts.map +1 -0
- package/dist/cloud/nexus-home.js +97 -0
- package/dist/cloud/nexus-home.js.map +1 -0
- package/dist/cloud/nexus-vault-keys.d.ts +129 -0
- package/dist/cloud/nexus-vault-keys.d.ts.map +1 -0
- package/dist/cloud/nexus-vault-keys.js +277 -0
- package/dist/cloud/nexus-vault-keys.js.map +1 -0
- package/dist/cloud/nexus-vault-state.d.ts +121 -0
- package/dist/cloud/nexus-vault-state.d.ts.map +1 -0
- package/dist/cloud/nexus-vault-state.js +274 -0
- package/dist/cloud/nexus-vault-state.js.map +1 -0
- package/dist/cloud/nexus-vault.d.ts +160 -0
- package/dist/cloud/nexus-vault.d.ts.map +1 -0
- package/dist/cloud/nexus-vault.js +1733 -0
- package/dist/cloud/nexus-vault.js.map +1 -0
- package/dist/cloud/signing.d.ts +24 -8
- package/dist/cloud/signing.d.ts.map +1 -1
- package/dist/cloud/signing.js +61 -15
- package/dist/cloud/signing.js.map +1 -1
- package/dist/docs/export-document.js +8137 -3318
- package/dist/docs/export-document.js.map +3 -3
- package/dist/doctor/migrations.d.ts +75 -0
- package/dist/doctor/migrations.d.ts.map +1 -0
- package/dist/doctor/migrations.js +136 -0
- package/dist/doctor/migrations.js.map +1 -0
- package/dist/doctor/sync-sealer.d.ts +48 -0
- package/dist/doctor/sync-sealer.d.ts.map +1 -0
- package/dist/doctor/sync-sealer.js +109 -0
- package/dist/doctor/sync-sealer.js.map +1 -0
- package/dist/doctor/sync-triggers.d.ts +53 -0
- package/dist/doctor/sync-triggers.d.ts.map +1 -0
- package/dist/doctor/sync-triggers.js +157 -0
- package/dist/doctor/sync-triggers.js.map +1 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +5 -1
- package/dist/init.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/llm/plugin-facade.js +8442 -3623
- package/dist/llm/plugin-facade.js.map +3 -3
- package/dist/nexus/projects-clean.d.ts +3 -0
- package/dist/nexus/projects-clean.d.ts.map +1 -1
- package/dist/nexus/projects-clean.js +9 -3
- package/dist/nexus/projects-clean.js.map +1 -1
- package/dist/nexus/registry-roots.d.ts +3 -1
- package/dist/nexus/registry-roots.d.ts.map +1 -1
- package/dist/nexus/registry-roots.js +5 -2
- package/dist/nexus/registry-roots.js.map +1 -1
- package/dist/nexus/registry.d.ts +8 -1
- package/dist/nexus/registry.d.ts.map +1 -1
- package/dist/nexus/registry.js +24 -10
- package/dist/nexus/registry.js.map +1 -1
- package/dist/nexus/workspace.d.ts +4 -1
- package/dist/nexus/workspace.d.ts.map +1 -1
- package/dist/nexus/workspace.js +10 -4
- package/dist/nexus/workspace.js.map +1 -1
- package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
- package/dist/orchestrate/spawn-ops.js +7 -2
- package/dist/orchestrate/spawn-ops.js.map +1 -1
- package/dist/orchestrate/worker-verify.d.ts +121 -12
- package/dist/orchestrate/worker-verify.d.ts.map +1 -1
- package/dist/orchestrate/worker-verify.js +172 -21
- package/dist/orchestrate/worker-verify.js.map +1 -1
- package/dist/orchestration/spawn-prompt.d.ts.map +1 -1
- package/dist/orchestration/spawn-prompt.js +15 -9
- package/dist/orchestration/spawn-prompt.js.map +1 -1
- package/dist/release/ci-evidence.d.ts +9 -0
- package/dist/release/ci-evidence.d.ts.map +1 -1
- package/dist/release/ci-evidence.js +9 -2
- package/dist/release/ci-evidence.js.map +1 -1
- package/dist/resources/backend.d.ts +15 -3
- package/dist/resources/backend.d.ts.map +1 -1
- package/dist/resources/backend.js +7 -3
- package/dist/resources/backend.js.map +1 -1
- package/dist/resources/darwin-backend.d.ts +142 -0
- package/dist/resources/darwin-backend.d.ts.map +1 -0
- package/dist/resources/darwin-backend.js +288 -0
- package/dist/resources/darwin-backend.js.map +1 -0
- package/dist/resources/governor.d.ts +44 -1
- package/dist/resources/governor.d.ts.map +1 -1
- package/dist/resources/governor.js +100 -36
- package/dist/resources/governor.js.map +1 -1
- package/dist/resources/heavy-command.d.ts +132 -0
- package/dist/resources/heavy-command.d.ts.map +1 -0
- package/dist/resources/heavy-command.js +768 -0
- package/dist/resources/heavy-command.js.map +1 -0
- package/dist/resources/monitor.d.ts +50 -1
- package/dist/resources/monitor.d.ts.map +1 -1
- package/dist/resources/monitor.js +83 -1
- package/dist/resources/monitor.js.map +1 -1
- package/dist/resources/run-admission.d.ts +303 -0
- package/dist/resources/run-admission.d.ts.map +1 -0
- package/dist/resources/run-admission.js +648 -0
- package/dist/resources/run-admission.js.map +1 -0
- package/dist/resources/run-class.d.ts +111 -0
- package/dist/resources/run-class.d.ts.map +1 -0
- package/dist/resources/run-class.js +658 -0
- package/dist/resources/run-class.js.map +1 -0
- package/dist/resources/run-governed.d.ts +158 -0
- package/dist/resources/run-governed.d.ts.map +1 -0
- package/dist/resources/run-governed.js +406 -0
- package/dist/resources/run-governed.js.map +1 -0
- package/dist/resources/slot-holder.d.ts +267 -0
- package/dist/resources/slot-holder.d.ts.map +1 -0
- package/dist/resources/slot-holder.js +505 -0
- package/dist/resources/slot-holder.js.map +1 -0
- package/dist/resources/tool-groups.d.ts +74 -0
- package/dist/resources/tool-groups.d.ts.map +1 -0
- package/dist/resources/tool-groups.js +118 -0
- package/dist/resources/tool-groups.js.map +1 -0
- package/dist/routing/build-command-groups.d.ts.map +1 -1
- package/dist/routing/build-command-groups.js +1 -0
- package/dist/routing/build-command-groups.js.map +1 -1
- package/dist/selfimprove/fix-gen.js +8446 -3627
- package/dist/selfimprove/fix-gen.js.map +3 -3
- package/dist/sentient/cross-project-hygiene.d.ts +3 -2
- package/dist/sentient/cross-project-hygiene.d.ts.map +1 -1
- package/dist/sentient/cross-project-hygiene.js +5 -2
- package/dist/sentient/cross-project-hygiene.js.map +1 -1
- package/dist/sentient/state.d.ts +7 -0
- package/dist/sentient/state.d.ts.map +1 -1
- package/dist/sentient/state.js.map +1 -1
- package/dist/sentient/tick.d.ts +14 -2
- package/dist/sentient/tick.d.ts.map +1 -1
- package/dist/sentient/tick.js +63 -4
- package/dist/sentient/tick.js.map +1 -1
- package/dist/store/backup-recover.d.ts.map +1 -1
- package/dist/store/backup-recover.js +5 -0
- package/dist/store/backup-recover.js.map +1 -1
- package/dist/store/data-accessor.d.ts +1 -0
- package/dist/store/data-accessor.d.ts.map +1 -1
- package/dist/store/data-accessor.js +7 -0
- package/dist/store/data-accessor.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts +23 -1
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +126 -36
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/exodus/recovery.d.ts.map +1 -1
- package/dist/store/exodus/recovery.js +15 -0
- package/dist/store/exodus/recovery.js.map +1 -1
- package/dist/store/legacy-tasks-lineage.d.ts.map +1 -1
- package/dist/store/legacy-tasks-lineage.js +5 -0
- package/dist/store/legacy-tasks-lineage.js.map +1 -1
- package/dist/store/lock.d.ts +8 -1
- package/dist/store/lock.d.ts.map +1 -1
- package/dist/store/lock.js +10 -2
- package/dist/store/lock.js.map +1 -1
- package/dist/store/migration-manager.d.ts +5 -0
- package/dist/store/migration-manager.d.ts.map +1 -1
- package/dist/store/migration-manager.js +11 -0
- package/dist/store/migration-manager.js.map +1 -1
- package/dist/store/migration-runner.d.ts +158 -0
- package/dist/store/migration-runner.d.ts.map +1 -0
- package/dist/store/migration-runner.js +493 -0
- package/dist/store/migration-runner.js.map +1 -0
- package/dist/store/portable-bundle-import.d.ts +15 -1
- package/dist/store/portable-bundle-import.d.ts.map +1 -1
- package/dist/store/portable-bundle-import.js +24 -4
- package/dist/store/portable-bundle-import.js.map +1 -1
- package/dist/store/portable-bundle-relocate.d.ts +43 -0
- package/dist/store/portable-bundle-relocate.d.ts.map +1 -1
- package/dist/store/portable-bundle-relocate.js +79 -5
- package/dist/store/portable-bundle-relocate.js.map +1 -1
- package/dist/store/portable-bundle-scan.d.ts +20 -0
- package/dist/store/portable-bundle-scan.d.ts.map +1 -1
- package/dist/store/portable-bundle-scan.js +38 -3
- package/dist/store/portable-bundle-scan.js.map +1 -1
- package/dist/store/portable-bundle.d.ts +33 -0
- package/dist/store/portable-bundle.d.ts.map +1 -1
- package/dist/store/portable-bundle.js +34 -7
- package/dist/store/portable-bundle.js.map +1 -1
- package/dist/store/row-identity-registry.d.ts +137 -7
- package/dist/store/row-identity-registry.d.ts.map +1 -1
- package/dist/store/row-identity-registry.js +364 -9
- package/dist/store/row-identity-registry.js.map +1 -1
- package/dist/store/row-identity.d.ts.map +1 -1
- package/dist/store/row-identity.js +9 -10
- package/dist/store/row-identity.js.map +1 -1
- package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
- package/dist/store/sqlite-data-accessor.js +10 -0
- package/dist/store/sqlite-data-accessor.js.map +1 -1
- package/dist/store/sqlite.d.ts +31 -0
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +5 -1
- package/dist/store/sqlite.js.map +1 -1
- package/dist/store/sync/capture.d.ts +203 -0
- package/dist/store/sync/capture.d.ts.map +1 -0
- package/dist/store/sync/capture.js +562 -0
- package/dist/store/sync/capture.js.map +1 -0
- package/dist/store/sync/clock-store.d.ts.map +1 -1
- package/dist/store/sync/clock-store.js +2 -0
- package/dist/store/sync/clock-store.js.map +1 -1
- package/dist/store/sync/fk-orphans.d.ts +133 -0
- package/dist/store/sync/fk-orphans.d.ts.map +1 -0
- package/dist/store/sync/fk-orphans.js +265 -0
- package/dist/store/sync/fk-orphans.js.map +1 -0
- package/dist/store/sync/flags.d.ts +7 -0
- package/dist/store/sync/flags.d.ts.map +1 -1
- package/dist/store/sync/flags.js +16 -0
- package/dist/store/sync/flags.js.map +1 -1
- package/dist/store/sync/hlc.d.ts.map +1 -1
- package/dist/store/sync/hlc.js +4 -0
- package/dist/store/sync/hlc.js.map +1 -1
- package/dist/store/sync/identity-fill.d.ts +45 -0
- package/dist/store/sync/identity-fill.d.ts.map +1 -0
- package/dist/store/sync/identity-fill.js +85 -0
- package/dist/store/sync/identity-fill.js.map +1 -0
- package/dist/store/sync/machinery.d.ts +27 -0
- package/dist/store/sync/machinery.d.ts.map +1 -0
- package/dist/store/sync/machinery.js +44 -0
- package/dist/store/sync/machinery.js.map +1 -0
- package/dist/store/sync/netting.d.ts +120 -0
- package/dist/store/sync/netting.d.ts.map +1 -0
- package/dist/store/sync/netting.js +336 -0
- package/dist/store/sync/netting.js.map +1 -0
- package/dist/store/sync/replica.d.ts +27 -2
- package/dist/store/sync/replica.d.ts.map +1 -1
- package/dist/store/sync/replica.js +47 -3
- package/dist/store/sync/replica.js.map +1 -1
- package/dist/store/sync/schema.d.ts +12 -0
- package/dist/store/sync/schema.d.ts.map +1 -1
- package/dist/store/sync/schema.js +21 -0
- package/dist/store/sync/schema.js.map +1 -1
- package/dist/store/sync/seal-backlog.d.ts +21 -0
- package/dist/store/sync/seal-backlog.d.ts.map +1 -0
- package/dist/store/sync/seal-backlog.js +24 -0
- package/dist/store/sync/seal-backlog.js.map +1 -0
- package/dist/store/sync/sealer-values.d.ts +34 -0
- package/dist/store/sync/sealer-values.d.ts.map +1 -0
- package/dist/store/sync/sealer-values.js +53 -0
- package/dist/store/sync/sealer-values.js.map +1 -0
- package/dist/store/sync/sealer.d.ts +145 -0
- package/dist/store/sync/sealer.d.ts.map +1 -0
- package/dist/store/sync/sealer.js +906 -0
- package/dist/store/sync/sealer.js.map +1 -0
- package/dist/store/sync/structural.d.ts +63 -0
- package/dist/store/sync/structural.d.ts.map +1 -0
- package/dist/store/sync/structural.js +180 -0
- package/dist/store/sync/structural.js.map +1 -0
- package/dist/store/sync/timestamps.d.ts +92 -0
- package/dist/store/sync/timestamps.d.ts.map +1 -0
- package/dist/store/sync/timestamps.js +228 -0
- package/dist/store/sync/timestamps.js.map +1 -0
- package/dist/store/sync/tombstones.d.ts +75 -0
- package/dist/store/sync/tombstones.d.ts.map +1 -0
- package/dist/store/sync/tombstones.js +103 -0
- package/dist/store/sync/tombstones.js.map +1 -0
- package/dist/store/sync/trigger-classes.d.ts +221 -0
- package/dist/store/sync/trigger-classes.d.ts.map +1 -0
- package/dist/store/sync/trigger-classes.js +441 -0
- package/dist/store/sync/trigger-classes.js.map +1 -0
- package/dist/store/sync/trigger-suspend-at-path.d.ts +23 -0
- package/dist/store/sync/trigger-suspend-at-path.d.ts.map +1 -0
- package/dist/store/sync/trigger-suspend-at-path.js +44 -0
- package/dist/store/sync/trigger-suspend-at-path.js.map +1 -0
- package/dist/store/sync/writer-version.d.ts +43 -0
- package/dist/store/sync/writer-version.d.ts.map +1 -0
- package/dist/store/sync/writer-version.js +90 -0
- package/dist/store/sync/writer-version.js.map +1 -0
- package/dist/store/table-classification.d.ts.map +1 -1
- package/dist/store/table-classification.js +102 -0
- package/dist/store/table-classification.js.map +1 -1
- package/dist/store/trigger-suspend-schema.d.ts +44 -0
- package/dist/store/trigger-suspend-schema.d.ts.map +1 -0
- package/dist/store/trigger-suspend-schema.js +25 -0
- package/dist/store/trigger-suspend-schema.js.map +1 -0
- package/dist/store/vault-manifest.d.ts +365 -0
- package/dist/store/vault-manifest.d.ts.map +1 -0
- package/dist/store/vault-manifest.js +812 -0
- package/dist/store/vault-manifest.js.map +1 -0
- package/dist/store/writer-lease.d.ts +31 -0
- package/dist/store/writer-lease.d.ts.map +1 -1
- package/dist/store/writer-lease.js +65 -2
- package/dist/store/writer-lease.js.map +1 -1
- package/dist/system/health.d.ts.map +1 -1
- package/dist/system/health.js +21 -0
- package/dist/system/health.js.map +1 -1
- package/dist/system/project-health.d.ts.map +1 -1
- package/dist/system/project-health.js +3 -1
- package/dist/system/project-health.js.map +1 -1
- package/dist/tasks/affected-packages.d.ts +58 -0
- package/dist/tasks/affected-packages.d.ts.map +1 -1
- package/dist/tasks/affected-packages.js +75 -6
- package/dist/tasks/affected-packages.js.map +1 -1
- package/dist/tasks/affected-scope.d.ts +150 -23
- package/dist/tasks/affected-scope.d.ts.map +1 -1
- package/dist/tasks/affected-scope.js +320 -32
- package/dist/tasks/affected-scope.js.map +1 -1
- package/dist/tasks/change-set.d.ts +96 -0
- package/dist/tasks/change-set.d.ts.map +1 -1
- package/dist/tasks/change-set.js +169 -4
- package/dist/tasks/change-set.js.map +1 -1
- package/dist/tasks/complete-ci.d.ts +115 -0
- package/dist/tasks/complete-ci.d.ts.map +1 -0
- package/dist/tasks/complete-ci.js +171 -0
- package/dist/tasks/complete-ci.js.map +1 -0
- package/dist/tasks/complete.d.ts.map +1 -1
- package/dist/tasks/complete.js +50 -17
- package/dist/tasks/complete.js.map +1 -1
- package/dist/tasks/compute-task-view.d.ts.map +1 -1
- package/dist/tasks/compute-task-view.js +7 -0
- package/dist/tasks/compute-task-view.js.map +1 -1
- package/dist/tasks/done-plan.d.ts.map +1 -1
- package/dist/tasks/done-plan.js +51 -30
- package/dist/tasks/done-plan.js.map +1 -1
- package/dist/tasks/done-record.d.ts +6 -0
- package/dist/tasks/done-record.d.ts.map +1 -1
- package/dist/tasks/done-record.js +9 -3
- package/dist/tasks/done-record.js.map +1 -1
- package/dist/tasks/evidence.d.ts +3 -2
- package/dist/tasks/evidence.d.ts.map +1 -1
- package/dist/tasks/evidence.js +143 -12
- package/dist/tasks/evidence.js.map +1 -1
- package/dist/tasks/gate-notes.d.ts +22 -0
- package/dist/tasks/gate-notes.d.ts.map +1 -0
- package/dist/tasks/gate-notes.js +33 -0
- package/dist/tasks/gate-notes.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -1
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/index.js +2 -1
- package/dist/tasks/index.js.map +1 -1
- package/dist/tasks/test-run-binding.d.ts +117 -0
- package/dist/tasks/test-run-binding.d.ts.map +1 -0
- package/dist/tasks/test-run-binding.js +365 -0
- package/dist/tasks/test-run-binding.js.map +1 -0
- package/dist/tasks/tool-cache-env.d.ts +123 -0
- package/dist/tasks/tool-cache-env.d.ts.map +1 -0
- package/dist/tasks/tool-cache-env.js +287 -0
- package/dist/tasks/tool-cache-env.js.map +1 -0
- package/dist/tasks/tool-cache-failed-first.d.ts +155 -0
- package/dist/tasks/tool-cache-failed-first.d.ts.map +1 -0
- package/dist/tasks/tool-cache-failed-first.js +285 -0
- package/dist/tasks/tool-cache-failed-first.js.map +1 -0
- package/dist/tasks/tool-cache.d.ts +375 -55
- package/dist/tasks/tool-cache.d.ts.map +1 -1
- package/dist/tasks/tool-cache.js +912 -303
- package/dist/tasks/tool-cache.js.map +1 -1
- package/dist/tasks/tool-resolver.d.ts +4 -3
- package/dist/tasks/tool-resolver.d.ts.map +1 -1
- package/dist/tasks/tool-resolver.js +15 -4
- package/dist/tasks/tool-resolver.js.map +1 -1
- package/dist/tasks/tool-semaphore.d.ts +67 -7
- package/dist/tasks/tool-semaphore.d.ts.map +1 -1
- package/dist/tasks/tool-semaphore.js +134 -56
- package/dist/tasks/tool-semaphore.js.map +1 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +4 -0
- package/dist/upgrade.js.map +1 -1
- package/dist/validation/engine-ops.d.ts +6 -0
- package/dist/validation/engine-ops.d.ts.map +1 -1
- package/dist/validation/engine-ops.js +8 -0
- package/dist/validation/engine-ops.js.map +1 -1
- package/migrations/drizzle-cleo-project/20260930170000_t12819-trigger-suspend-clause/migration.sql +367 -0
- package/migrations/sync-journal/20260930120000_t12343-capture/migration.sql +47 -0
- package/migrations/sync-journal/20261001170000_t12984-sealer/migration.sql +101 -0
- package/package.json +13 -13
- package/templates/CLEO-INJECTION.md +5 -5
- package/templates/CLEO-REFERENCE.md +8 -4
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bracketed migration runner (journal spec §2.3a rules 1–3; T12774,
|
|
3
|
+
* T12781, T12785, T12786, T12795, T12796, T12797, T12809).
|
|
4
|
+
*
|
|
5
|
+
* Drizzle's `migrateSync` runs every pending migration in ONE transaction of
|
|
6
|
+
* its own, with `PRAGMA foreign_keys` left ON (the PRAGMA is a no-op inside a
|
|
7
|
+
* transaction). A table rebuild's `DROP TABLE` therefore cascade-deletes
|
|
8
|
+
* child rows, and nothing can run inside its transaction. This runner keeps
|
|
9
|
+
* drizzle's journal byte-for-byte and replaces the transaction discipline:
|
|
10
|
+
*
|
|
11
|
+
* - **Journal-identical (R5-3).** Pending migrations are selected by NAME
|
|
12
|
+
* (drizzle's `getMigrationsToRun`), each row is written with the RAW file's
|
|
13
|
+
* sha256, `created_at = folderMillis`, `name` and `applied_at`, exactly as
|
|
14
|
+
* `migrateSync` writes it. `reconcileJournal` and drizzle's own
|
|
15
|
+
* `upgradeSyncIfNeeded` run inside the leading bracket, in today's order.
|
|
16
|
+
* Statements run one per `prepare()`, as drizzle's session does.
|
|
17
|
+
* - **One bracket per migration FILE (R6-6).** Each file gets its own
|
|
18
|
+
* `BEGIN IMMEDIATE … COMMIT` and its own journal row.
|
|
19
|
+
* - **FK discipline (A, NEW-1, R5-2, R5-4, NEW-6).** `foreign_keys` is turned
|
|
20
|
+
* OFF before `BEGIN` only for a file that rebuilds a table. For such a file
|
|
21
|
+
* the runner snapshots the FK violations of its scope (rebuilt and
|
|
22
|
+
* DML-touched tables plus their FK children) as a rowid-free multiset,
|
|
23
|
+
* re-checks after the statements, and rolls back on any NEW violation.
|
|
24
|
+
* Pre-existing orphans never block a migration. `finally` restores
|
|
25
|
+
* `foreign_keys`, reads it back and asserts no transaction is open.
|
|
26
|
+
* - **Recovery kept.** A duplicate-column or table-exists error re-runs
|
|
27
|
+
* `reconcileJournal` once and retries, as `migrateWithRetry` does; a BUSY
|
|
28
|
+
* error retries the whole bracket with backoff, never mid-bracket.
|
|
29
|
+
* - **Hooks (D4, NEW-8).** `beforeMigrations` runs before the first bracket
|
|
30
|
+
* (the sealer's pending work and the repair diff for suspect tables, S3);
|
|
31
|
+
* `suspendCapture` / `reinstallCapture` run inside each bracket around the
|
|
32
|
+
* statements (the capture triggers, S2); `afterMigration` runs after each
|
|
33
|
+
* commit (the `chash` re-baseline, S3). All are optional.
|
|
34
|
+
*
|
|
35
|
+
* Drizzle is pinned to {@link PINNED_DRIZZLE_VERSION}; a test fails when the
|
|
36
|
+
* installed version differs, so an upgrade must re-run the parity suite.
|
|
37
|
+
*
|
|
38
|
+
* @task T12796
|
|
39
|
+
* @task T12809
|
|
40
|
+
* @module store/migration-runner
|
|
41
|
+
*/
|
|
42
|
+
import { basename } from 'node:path';
|
|
43
|
+
import { readMigrationFiles } from 'drizzle-orm/migrator';
|
|
44
|
+
import { getMigrationsToRun } from 'drizzle-orm/migrator.utils';
|
|
45
|
+
import { sql } from 'drizzle-orm/sql';
|
|
46
|
+
import { upgradeSyncIfNeeded } from 'drizzle-orm/up-migrations/sqlite';
|
|
47
|
+
import { getLogger } from '../logger.js';
|
|
48
|
+
import { isDuplicateColumnError, isTableAlreadyExistsError, reconcileJournal, sanitizeMigrationStatements, } from './migration-manager.js';
|
|
49
|
+
import { isSqliteBusy } from './with-retry.js';
|
|
50
|
+
import { assertNoPendingMigrationsForWorktreeBuild } from './worktree-build-guard.js';
|
|
51
|
+
/** The drizzle-orm version the runner's journal parity was proven against. */
|
|
52
|
+
export const PINNED_DRIZZLE_VERSION = '1.0.0-rc.4';
|
|
53
|
+
/** The journal table drizzle uses by default. */
|
|
54
|
+
export const MIGRATIONS_TABLE = '__drizzle_migrations';
|
|
55
|
+
const MAX_BUSY_RETRIES = 5;
|
|
56
|
+
const BUSY_BASE_DELAY_MS = 100;
|
|
57
|
+
const BUSY_MAX_DELAY_MS = 2000;
|
|
58
|
+
/**
|
|
59
|
+
* Legacy lineages the runner refuses by folder name (cleo-dev ruling on the
|
|
60
|
+
* S2 runner scope, 2026-09-30). They keep `migrateWithRetry` in their own
|
|
61
|
+
* binders (`sqlite.ts`, `memory-sqlite.ts`, `nexus-sqlite.ts`,
|
|
62
|
+
* `conduit-sqlite.ts`, …); only the consolidated `cleo.db` lineages run
|
|
63
|
+
* bracketed.
|
|
64
|
+
*/
|
|
65
|
+
export const LEGACY_LINEAGES = new Set([
|
|
66
|
+
'drizzle-tasks',
|
|
67
|
+
'drizzle-brain',
|
|
68
|
+
'drizzle-nexus',
|
|
69
|
+
'drizzle-conduit',
|
|
70
|
+
'drizzle-agent-registry',
|
|
71
|
+
'drizzle-skills',
|
|
72
|
+
'drizzle-telemetry',
|
|
73
|
+
'drizzle-signaldock',
|
|
74
|
+
]);
|
|
75
|
+
/** A legacy lineage was handed to the runner. */
|
|
76
|
+
export class LegacyLineageRefusedError extends Error {
|
|
77
|
+
lineage;
|
|
78
|
+
code = 'E_MIGRATION_RUNNER_LEGACY_LINEAGE';
|
|
79
|
+
constructor(lineage) {
|
|
80
|
+
super(`The bracketed migration runner runs only the consolidated cleo.db lineages; refusing legacy lineage ${lineage}`);
|
|
81
|
+
this.lineage = lineage;
|
|
82
|
+
this.name = 'LegacyLineageRefusedError';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** A migration file that introduced a foreign-key violation (rolled back). */
|
|
86
|
+
export class MigrationForeignKeyError extends Error {
|
|
87
|
+
migration;
|
|
88
|
+
violations;
|
|
89
|
+
code = 'E_MIGRATION_FK_VIOLATION';
|
|
90
|
+
constructor(migration, violations) {
|
|
91
|
+
super(`Migration ${migration} would leave ${violations.length} new foreign-key violation(s); ` +
|
|
92
|
+
`rolled back. First: ${violations.slice(0, 3).join('; ')}`);
|
|
93
|
+
this.migration = migration;
|
|
94
|
+
this.violations = violations;
|
|
95
|
+
this.name = 'MigrationForeignKeyError';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** `foreign_keys` could not be restored on a handle after a bracket. */
|
|
99
|
+
export class ForeignKeysNotRestoredError extends Error {
|
|
100
|
+
code = 'E_STORE_FK_OFF';
|
|
101
|
+
constructor(expected, actual) {
|
|
102
|
+
super(`PRAGMA foreign_keys is ${actual} after a migration bracket; expected ${expected}`);
|
|
103
|
+
this.name = 'ForeignKeysNotRestoredError';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const IDENT = String.raw `[\`"[]?(\w+)[\`"\]]?`;
|
|
107
|
+
/** Strip `--` comments so prose never looks like DDL. */
|
|
108
|
+
function code(stmt) {
|
|
109
|
+
return stmt.replace(/--[^\n]*/g, '');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The tables a migration file rebuilds or drops: `CREATE TABLE __new_x`
|
|
113
|
+
* (→ `x`), `DROP TABLE x`, `ALTER TABLE x RENAME TO y` (→ `x`, `y`).
|
|
114
|
+
* Empty for a file that rebuilds nothing.
|
|
115
|
+
*/
|
|
116
|
+
export function rebuiltTables(statements) {
|
|
117
|
+
const out = new Set();
|
|
118
|
+
const final = (t) => t.replace(/^__new_/, '');
|
|
119
|
+
for (const s of statements.map(code)) {
|
|
120
|
+
for (const m of s.matchAll(new RegExp(String.raw `\bCREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?${IDENT}`, 'gi'))) {
|
|
121
|
+
if (m[1].startsWith('__new_'))
|
|
122
|
+
out.add(final(m[1]));
|
|
123
|
+
}
|
|
124
|
+
for (const m of s.matchAll(new RegExp(String.raw `\bDROP\s+TABLE\s+(?:IF\s+EXISTS\s+)?${IDENT}`, 'gi'))) {
|
|
125
|
+
out.add(final(m[1]));
|
|
126
|
+
}
|
|
127
|
+
for (const m of s.matchAll(new RegExp(String.raw `\bALTER\s+TABLE\s+${IDENT}\s+RENAME\s+TO\s+${IDENT}`, 'gi'))) {
|
|
128
|
+
out.add(final(m[1]));
|
|
129
|
+
out.add(final(m[2]));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...out].sort();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Where each table a migration file renames ends up: every `ALTER TABLE a RENAME TO b`, in statement
|
|
136
|
+
* order and composed, so `a → b` then `b → c` gives `a → c` (T13027). Unrenamed tables are absent.
|
|
137
|
+
*/
|
|
138
|
+
export function renamedTables(statements) {
|
|
139
|
+
const out = new Map();
|
|
140
|
+
// Anchored: only a statement that IS the rename counts, never text inside a
|
|
141
|
+
// string literal or another statement's body.
|
|
142
|
+
const rename = new RegExp(String.raw `^\s*ALTER\s+TABLE\s+${IDENT}\s+RENAME\s+TO\s+${IDENT}\s*;?\s*$`, 'i');
|
|
143
|
+
for (const s of statements.map(code)) {
|
|
144
|
+
const m = rename.exec(s);
|
|
145
|
+
if (!m)
|
|
146
|
+
continue;
|
|
147
|
+
const from = m[1];
|
|
148
|
+
const to = m[2];
|
|
149
|
+
const original = [...out.entries()].find(([, now]) => now === from)?.[0] ?? from;
|
|
150
|
+
out.set(original, to);
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
/** The tables a migration's DML writes (INSERT / UPDATE / DELETE / REPLACE). */
|
|
155
|
+
export function dmlTables(statements) {
|
|
156
|
+
const out = new Set();
|
|
157
|
+
for (const s of statements.map(code)) {
|
|
158
|
+
for (const m of s.matchAll(new RegExp(String.raw `\b(?:INSERT(?:\s+OR\s+\w+)?\s+INTO|REPLACE\s+INTO|UPDATE(?:\s+OR\s+\w+)?|DELETE\s+FROM)\s+${IDENT}`, 'gi'))) {
|
|
159
|
+
out.add(m[1].replace(/^__new_/, ''));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return [...out].sort();
|
|
163
|
+
}
|
|
164
|
+
function listTables(db) {
|
|
165
|
+
return db
|
|
166
|
+
.prepare("SELECT name FROM main.sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")
|
|
167
|
+
.all().map((r) => r.name);
|
|
168
|
+
}
|
|
169
|
+
function foreignKeys(db, table) {
|
|
170
|
+
return db.prepare(`PRAGMA main.foreign_key_list("${table}")`).all();
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The FK scope of a rebuild file: the given tables plus every table with a
|
|
174
|
+
* foreign key to one of them (children), restricted to tables that exist.
|
|
175
|
+
*/
|
|
176
|
+
export function foreignKeyScope(db, tables) {
|
|
177
|
+
const all = listTables(db);
|
|
178
|
+
const existing = new Set(all);
|
|
179
|
+
const scope = new Set(tables.filter((t) => existing.has(t)));
|
|
180
|
+
const parents = new Set(tables);
|
|
181
|
+
for (const t of all) {
|
|
182
|
+
if (foreignKeys(db, t).some((fk) => parents.has(fk.table)))
|
|
183
|
+
scope.add(t);
|
|
184
|
+
}
|
|
185
|
+
return [...scope].sort();
|
|
186
|
+
}
|
|
187
|
+
/** SQLite's affinity for a declared column type (§3.1 of the datatype doc). */
|
|
188
|
+
function affinity(declared) {
|
|
189
|
+
const t = declared.toUpperCase();
|
|
190
|
+
if (t.includes('INT'))
|
|
191
|
+
return 'INTEGER';
|
|
192
|
+
if (/CHAR|CLOB|TEXT/.test(t))
|
|
193
|
+
return 'TEXT';
|
|
194
|
+
if (t === '' || t.includes('BLOB'))
|
|
195
|
+
return 'BLOB';
|
|
196
|
+
if (/REAL|FLOA|DOUB/.test(t))
|
|
197
|
+
return 'REAL';
|
|
198
|
+
return 'NUMERIC';
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The foreign-key violations of `tables`, as a multiset keyed by rowid-free
|
|
202
|
+
* identity (R5-2): (table, the child's primary-key values normalized by
|
|
203
|
+
* column affinity — or the whole row for a table without a declared PK,
|
|
204
|
+
* parent table, the child's FK values). Duplicates count.
|
|
205
|
+
*
|
|
206
|
+
* FK column NAMES are not part of the key: a rebuild may rename an FK column
|
|
207
|
+
* while the violation stays the same row and value (T13027). Two orphaned
|
|
208
|
+
* FKs of one row with equal values are still counted twice.
|
|
209
|
+
*/
|
|
210
|
+
export function foreignKeyViolations(db, tables) {
|
|
211
|
+
const out = new Map();
|
|
212
|
+
for (const table of tables) {
|
|
213
|
+
const rows = db.prepare(`PRAGMA main.foreign_key_check("${table}")`).all();
|
|
214
|
+
if (rows.length === 0)
|
|
215
|
+
continue;
|
|
216
|
+
const cols = db.prepare(`PRAGMA main.table_info("${table}")`).all();
|
|
217
|
+
const pkCols = cols.filter((c) => c.pk > 0).sort((a, b) => a.pk - b.pk);
|
|
218
|
+
const keyCols = pkCols.length > 0 ? pkCols : cols;
|
|
219
|
+
const fks = foreignKeys(db, table);
|
|
220
|
+
const seenNoRowid = new Set();
|
|
221
|
+
const enc = (c, alias) => {
|
|
222
|
+
const a = affinity(c.type);
|
|
223
|
+
const ref = `${alias}"${c.name}"`;
|
|
224
|
+
return a === 'BLOB' ? `quote(${ref})` : `quote(CAST(${ref} AS ${a}))`;
|
|
225
|
+
};
|
|
226
|
+
const keySql = (alias) => `json_array(${keyCols.map((c) => enc(c, alias)).join(', ')})`;
|
|
227
|
+
for (const v of rows) {
|
|
228
|
+
const fkCols = fks.filter((f) => f.id === v.fkid).sort((a, b) => a.seq - b.seq);
|
|
229
|
+
const fkSql = (alias) => `json_array(${fkCols.map((f) => `quote(${alias}"${f.from}")`).join(', ')})`;
|
|
230
|
+
let identities;
|
|
231
|
+
if (v.rowid !== null && v.rowid !== undefined) {
|
|
232
|
+
identities = db
|
|
233
|
+
.prepare(`SELECT ${keySql('')} AS k, ${fkSql('')} AS f FROM main."${table}" WHERE rowid = ?`)
|
|
234
|
+
.all(v.rowid);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// WITHOUT ROWID: no rowid to point at; list this FK's violating rows.
|
|
238
|
+
const parentPk = db.prepare(`PRAGMA main.table_info("${v.parent}")`).all()
|
|
239
|
+
.filter((c) => c.pk > 0)
|
|
240
|
+
.sort((a, b) => a.pk - b.pk)
|
|
241
|
+
.map((c) => c.name);
|
|
242
|
+
const match = fkCols
|
|
243
|
+
.map((f, i) => `p."${f.to ?? parentPk[i] ?? f.from}" = c."${f.from}"`)
|
|
244
|
+
.join(' AND ');
|
|
245
|
+
identities = db
|
|
246
|
+
.prepare(`SELECT ${keySql('c.')} AS k, ${fkSql('c.')} AS f FROM main."${table}" c ` +
|
|
247
|
+
`WHERE ${fkCols.map((f) => `c."${f.from}" IS NOT NULL`).join(' AND ')} ` +
|
|
248
|
+
`AND NOT EXISTS (SELECT 1 FROM main."${v.parent}" p WHERE ${match})`)
|
|
249
|
+
.all();
|
|
250
|
+
// foreign_key_check lists one row per violation; this query lists them
|
|
251
|
+
// all at once, so take it for the first report of this FK only.
|
|
252
|
+
if (seenNoRowid.has(v.fkid))
|
|
253
|
+
identities = [];
|
|
254
|
+
seenNoRowid.add(v.fkid);
|
|
255
|
+
}
|
|
256
|
+
for (const id of identities) {
|
|
257
|
+
const key = JSON.stringify([table, id.k, v.parent, id.f]);
|
|
258
|
+
out.set(key, (out.get(key) ?? 0) + 1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A before-snapshot re-keyed to the names its tables have after a file's
|
|
266
|
+
* renames (T13027): child and parent tables move through `renames` when the
|
|
267
|
+
* new name exists afterwards. A table renamed away and dropped (`x → __old_x`
|
|
268
|
+
* in a rebuild) keeps its name, since its rows now live under the old name.
|
|
269
|
+
*/
|
|
270
|
+
export function renameViolations(before, renames, exists) {
|
|
271
|
+
if (renames.size === 0)
|
|
272
|
+
return before;
|
|
273
|
+
const to = (t) => {
|
|
274
|
+
const r = renames.get(t);
|
|
275
|
+
return r !== undefined && exists(r) ? r : t;
|
|
276
|
+
};
|
|
277
|
+
const out = new Map();
|
|
278
|
+
for (const [k, n] of before) {
|
|
279
|
+
const [table, pk, parent, values] = JSON.parse(k);
|
|
280
|
+
const key = JSON.stringify([to(table), pk, to(parent), values]);
|
|
281
|
+
out.set(key, (out.get(key) ?? 0) + n);
|
|
282
|
+
}
|
|
283
|
+
return out;
|
|
284
|
+
}
|
|
285
|
+
/** Keys whose count in `after` exceeds their count in `before`. */
|
|
286
|
+
export function newViolations(before, after) {
|
|
287
|
+
const out = [];
|
|
288
|
+
for (const [k, n] of after) {
|
|
289
|
+
const extra = n - (before.get(k) ?? 0);
|
|
290
|
+
for (let i = 0; i < extra; i++)
|
|
291
|
+
out.push(k);
|
|
292
|
+
}
|
|
293
|
+
return out;
|
|
294
|
+
}
|
|
295
|
+
function sleepMs(ms) {
|
|
296
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.round(ms));
|
|
297
|
+
}
|
|
298
|
+
/** Run `fn`, retrying the whole thing on SQLITE_BUSY with backoff. */
|
|
299
|
+
function withBusyRetry(fn) {
|
|
300
|
+
for (let attempt = 1;; attempt++) {
|
|
301
|
+
try {
|
|
302
|
+
return fn();
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
if (!isSqliteBusy(err) || attempt >= MAX_BUSY_RETRIES)
|
|
306
|
+
throw err;
|
|
307
|
+
sleepMs(Math.min(BUSY_BASE_DELAY_MS * 2 ** (attempt - 1) * (1 + Math.random() * 0.5), BUSY_MAX_DELAY_MS));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function readForeignKeys(db) {
|
|
312
|
+
return Number(db.prepare('PRAGMA foreign_keys').get().foreign_keys);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The leading bracket of a lineage: reconcile (when configured), then
|
|
316
|
+
* drizzle's journal-format upgrade, then create the journal table on a new
|
|
317
|
+
* store. Returns the names already journaled.
|
|
318
|
+
*/
|
|
319
|
+
function leadingBracket(nativeDb,
|
|
320
|
+
// biome-ignore lint/suspicious/noExplicitAny: drizzle's session type is generic over the schema
|
|
321
|
+
db, lineage, migrations) {
|
|
322
|
+
withBusyRetry(() => {
|
|
323
|
+
nativeDb.exec('BEGIN IMMEDIATE');
|
|
324
|
+
try {
|
|
325
|
+
if (lineage.reconcile) {
|
|
326
|
+
reconcileJournal(nativeDb, lineage.folder, lineage.reconcile.existenceTable, lineage.reconcile.logSubsystem, lineage.reconcile.siblings ?? []);
|
|
327
|
+
}
|
|
328
|
+
// Drizzle's own upgrade, with its inner transaction folded into ours.
|
|
329
|
+
const session = db._.session;
|
|
330
|
+
const inBracket = new Proxy(session, {
|
|
331
|
+
get(target, prop, receiver) {
|
|
332
|
+
if (prop === 'transaction')
|
|
333
|
+
return (fn) => fn(receiver);
|
|
334
|
+
return Reflect.get(target, prop, receiver);
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
const { newDb } = upgradeSyncIfNeeded(MIGRATIONS_TABLE, inBracket, migrations);
|
|
338
|
+
if (newDb) {
|
|
339
|
+
session.run(sql `
|
|
340
|
+
CREATE TABLE IF NOT EXISTS ${sql.identifier(MIGRATIONS_TABLE)} (
|
|
341
|
+
id INTEGER PRIMARY KEY,
|
|
342
|
+
hash text NOT NULL,
|
|
343
|
+
created_at numeric,
|
|
344
|
+
name text,
|
|
345
|
+
applied_at TEXT
|
|
346
|
+
)`);
|
|
347
|
+
}
|
|
348
|
+
nativeDb.exec('COMMIT');
|
|
349
|
+
}
|
|
350
|
+
catch (err) {
|
|
351
|
+
if (nativeDb.isTransaction)
|
|
352
|
+
nativeDb.exec('ROLLBACK');
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
function journalRows(nativeDb) {
|
|
358
|
+
return nativeDb
|
|
359
|
+
.prepare(`SELECT id, hash, created_at, name FROM main."${MIGRATIONS_TABLE}"`)
|
|
360
|
+
.all();
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Apply one migration file in its own bracket. Returns whether it ran with
|
|
364
|
+
* foreign keys off.
|
|
365
|
+
*/
|
|
366
|
+
function migrationBracket(nativeDb, migration, hooks) {
|
|
367
|
+
const statements = migration.sql;
|
|
368
|
+
const rebuilt = rebuiltTables(statements);
|
|
369
|
+
const rebuild = rebuilt.length > 0;
|
|
370
|
+
const prev = readForeignKeys(nativeDb);
|
|
371
|
+
let failure;
|
|
372
|
+
let committed = false;
|
|
373
|
+
try {
|
|
374
|
+
if (rebuild)
|
|
375
|
+
nativeDb.exec('PRAGMA foreign_keys = OFF');
|
|
376
|
+
nativeDb.exec('BEGIN IMMEDIATE');
|
|
377
|
+
const scopeTables = [...rebuilt, ...dmlTables(statements)];
|
|
378
|
+
const before = rebuild
|
|
379
|
+
? foreignKeyViolations(nativeDb, foreignKeyScope(nativeDb, scopeTables))
|
|
380
|
+
: new Map();
|
|
381
|
+
hooks.suspendCapture?.(nativeDb);
|
|
382
|
+
for (const stmt of statements)
|
|
383
|
+
nativeDb.prepare(stmt).run();
|
|
384
|
+
nativeDb
|
|
385
|
+
.prepare(`INSERT INTO main."${MIGRATIONS_TABLE}" ("hash", "created_at", "name", "applied_at") values(?, ?, ?, ?)`)
|
|
386
|
+
.run(migration.hash, migration.folderMillis, migration.name ?? null, new Date().toISOString());
|
|
387
|
+
if (rebuild) {
|
|
388
|
+
// Re-scope after the statements: the rebuild may have created tables.
|
|
389
|
+
const after = foreignKeyViolations(nativeDb, foreignKeyScope(nativeDb, scopeTables));
|
|
390
|
+
// A renamed table keeps its pre-existing orphans: compare under the new names (T13027).
|
|
391
|
+
const live = new Set(listTables(nativeDb));
|
|
392
|
+
const renamed = renameViolations(before, renamedTables(statements), (t) => live.has(t));
|
|
393
|
+
const added = newViolations(renamed, after);
|
|
394
|
+
// @sync-invariant none:local-only a migration that adds FK violations is refused locally before commit; schema, not synced rows
|
|
395
|
+
if (added.length > 0)
|
|
396
|
+
throw new MigrationForeignKeyError(migration.name ?? '', added);
|
|
397
|
+
}
|
|
398
|
+
hooks.reinstallCapture?.(nativeDb);
|
|
399
|
+
nativeDb.exec('COMMIT');
|
|
400
|
+
committed = true;
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
failure = err;
|
|
404
|
+
}
|
|
405
|
+
// NEW-6: never leave a pooled handle inside a transaction or with FK off.
|
|
406
|
+
if (nativeDb.isTransaction)
|
|
407
|
+
nativeDb.exec('ROLLBACK');
|
|
408
|
+
nativeDb.exec(`PRAGMA foreign_keys = ${prev}`);
|
|
409
|
+
const now = readForeignKeys(nativeDb);
|
|
410
|
+
if (now !== prev || nativeDb.isTransaction) {
|
|
411
|
+
// @sync-invariant none:local-only the migration runner restores this handle's FK mode; local schema pass
|
|
412
|
+
throw Object.assign(new ForeignKeysNotRestoredError(prev, now), { cause: failure });
|
|
413
|
+
}
|
|
414
|
+
if (!committed)
|
|
415
|
+
throw failure;
|
|
416
|
+
return rebuild;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Apply every pending migration of each lineage, in order, with the journal
|
|
420
|
+
* `migrateSync` would leave, one bracket per file.
|
|
421
|
+
*
|
|
422
|
+
* @param nativeDb - The store handle.
|
|
423
|
+
* @param db - The drizzle wrapper of `nativeDb` (for drizzle's journal upgrade).
|
|
424
|
+
* @param lineages - The lineages sharing the journal, in apply order.
|
|
425
|
+
* @param hooks - Optional D4 hooks.
|
|
426
|
+
*/
|
|
427
|
+
export function runBracketedMigrations(nativeDb,
|
|
428
|
+
// biome-ignore lint/suspicious/noExplicitAny: drizzle's session type is generic over the schema
|
|
429
|
+
db, lineages, hooks = {}) {
|
|
430
|
+
const applied = [];
|
|
431
|
+
const rebuilds = [];
|
|
432
|
+
let hooked = false;
|
|
433
|
+
for (const lineage of lineages) {
|
|
434
|
+
const name = basename(lineage.folder.replace(/[\\/]+$/, ''));
|
|
435
|
+
// @sync-invariant none:local-only refuses a retired migration lineage on this store; local schema pass
|
|
436
|
+
if (LEGACY_LINEAGES.has(name))
|
|
437
|
+
throw new LegacyLineageRefusedError(name);
|
|
438
|
+
}
|
|
439
|
+
for (const lineage of lineages) {
|
|
440
|
+
const raw = readMigrationFiles({ migrationsFolder: lineage.folder });
|
|
441
|
+
// T12687: a worktree build never applies its migrations to a foreign store.
|
|
442
|
+
assertNoPendingMigrationsForWorktreeBuild(nativeDb, raw);
|
|
443
|
+
const migrations = sanitizeMigrationStatements(raw);
|
|
444
|
+
let reconciledDuplicate = false;
|
|
445
|
+
let reconciledExists = false;
|
|
446
|
+
leadingBracket(nativeDb, db, lineage, migrations);
|
|
447
|
+
for (;;) {
|
|
448
|
+
const pending = getMigrationsToRun({
|
|
449
|
+
localMigrations: migrations,
|
|
450
|
+
dbMigrations: journalRows(nativeDb),
|
|
451
|
+
});
|
|
452
|
+
if (pending.length === 0)
|
|
453
|
+
break;
|
|
454
|
+
if (!hooked) {
|
|
455
|
+
hooks.beforeMigrations?.(nativeDb);
|
|
456
|
+
hooked = true;
|
|
457
|
+
}
|
|
458
|
+
const next = pending[0];
|
|
459
|
+
try {
|
|
460
|
+
const rebuild = withBusyRetry(() => migrationBracket(nativeDb, next, hooks));
|
|
461
|
+
applied.push(next.name ?? '');
|
|
462
|
+
if (rebuild)
|
|
463
|
+
rebuilds.push(next.name ?? '');
|
|
464
|
+
hooks.afterMigration?.(nativeDb, { name: next.name ?? '', hash: next.hash });
|
|
465
|
+
}
|
|
466
|
+
catch (err) {
|
|
467
|
+
const dup = isDuplicateColumnError(err) && !reconciledDuplicate;
|
|
468
|
+
const exists = isTableAlreadyExistsError(err) && !reconciledExists;
|
|
469
|
+
if (lineage.reconcile && (dup || exists)) {
|
|
470
|
+
if (dup)
|
|
471
|
+
reconciledDuplicate = true;
|
|
472
|
+
if (exists)
|
|
473
|
+
reconciledExists = true;
|
|
474
|
+
getLogger(lineage.reconcile.logSubsystem).warn({ migration: next.name, message: err.message }, 'Migration hit an already-applied DDL target; reconciling the journal and retrying');
|
|
475
|
+
leadingBracket(nativeDb, db, lineage, migrations);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
throw err;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return { applied, rebuilds };
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Same as {@link runBracketedMigrations} for one lineage, in the shape the
|
|
486
|
+
* callers of `reconcileJournal` + `migrateWithRetry` use today.
|
|
487
|
+
*/
|
|
488
|
+
export function migrateBracketed(
|
|
489
|
+
// biome-ignore lint/suspicious/noExplicitAny: drizzle's session type is generic over the schema
|
|
490
|
+
db, nativeDb, migrationsFolder, existenceTable, logSubsystem, siblings = [], hooks = {}) {
|
|
491
|
+
return runBracketedMigrations(nativeDb, db, [{ folder: migrationsFolder, reconcile: { existenceTable, logSubsystem, siblings } }], hooks);
|
|
492
|
+
}
|
|
493
|
+
//# sourceMappingURL=migration-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-runner.js","sourceRoot":"","sources":["../../src/store/migration-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,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CAAC,CAAC,IAAI,CAC5C,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAG,GAAa,CAAC,OAAO,EAAE,EACzD,mFAAmF,CACpF,CAAC;oBACF,cAAc,CAAC,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;oBAClD,SAAS;gBACX,CAAC;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;AAC9B,gGAAgG;AAChG,EAA2B,EAC3B,QAAsB,EACtB,gBAAwB,EACxB,cAAsB,EACtB,YAAoB,EACpB,WAA8B,EAAE,EAChC,QAA+B,EAAE;IAEjC,OAAO,sBAAsB,CAC3B,QAAQ,EACR,EAAE,EACF,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,CAAC,EACrF,KAAK,CACN,CAAC;AACJ,CAAC"}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* @epic T12317
|
|
23
23
|
* @module store/portable-bundle-import
|
|
24
24
|
*/
|
|
25
|
-
import type { PortableImportResult, PortableImportSectionResult } from '@cleocode/contracts';
|
|
25
|
+
import type { PortableBundleManifest, PortableImportResult, PortableImportSectionResult } from '@cleocode/contracts';
|
|
26
26
|
/** One `--map <old>=<new>` prefix rewrite. */
|
|
27
27
|
export interface PathMapping {
|
|
28
28
|
/** Old absolute prefix. */
|
|
@@ -67,6 +67,20 @@ export interface ImportPortableBundleInput {
|
|
|
67
67
|
* projectId and new root; returns the registry outcome.
|
|
68
68
|
*/
|
|
69
69
|
registerProject?: (projectId: string | null, newRoot: string) => Promise<NonNullable<PortableImportSectionResult['registry']>>;
|
|
70
|
+
/**
|
|
71
|
+
* Called after the staged bundle is extracted and its integrity verified,
|
|
72
|
+
* before anything is placed (T12336). A throw aborts the import with
|
|
73
|
+
* nothing activated: the cloud vault checks the snapshot's per-table counts
|
|
74
|
+
* and hashes here.
|
|
75
|
+
*/
|
|
76
|
+
onStaged?: (extractDir: string, manifest: PortableBundleManifest) => void | Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Plain files this machine keeps, by path in their section (T13005): `keep`
|
|
79
|
+
* leaves the destination's copy where it has one (the bundle's is placed
|
|
80
|
+
* only where it has none); `skip` never places the bundle's copy. Every
|
|
81
|
+
* other file is placed. The cloud vault keeps machine-local files this way.
|
|
82
|
+
*/
|
|
83
|
+
machineLocalFile?: (relPath: string) => 'keep' | 'skip' | null;
|
|
70
84
|
}
|
|
71
85
|
/**
|
|
72
86
|
* Parse `--map` values (`<old>=<new>`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable-bundle-import.d.ts","sourceRoot":"","sources":["../../src/store/portable-bundle-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"portable-bundle-import.d.ts","sourceRoot":"","sources":["../../src/store/portable-bundle-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH,OAAO,KAAK,EAGV,sBAAsB,EACtB,oBAAoB,EACpB,2BAA2B,EAK5B,MAAM,qBAAqB,CAAC;AA4B7B,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC,mBAAmB;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAq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CACxC,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,oBAAoB,CAAC,CAkN/B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,2BAA2B,CAAC,UAAU,CAAC,CAAC,CAAC,CAkB/D"}
|
|
@@ -33,6 +33,7 @@ import { reentryFor, unsealCredentials } from './credential-transfer.js';
|
|
|
33
33
|
import { allSections, computeManifestHash, PortableBundleError } from './portable-bundle.js';
|
|
34
34
|
import { isUnderRoot, relocateDatabase, relocatePath, relocateProjectFiles, } from './portable-bundle-relocate.js';
|
|
35
35
|
import { countRows, integrityCheck, KEY_COUNT_TABLES, sha256File } from './portable-bundle-scan.js';
|
|
36
|
+
import { ensureTriggerSuspendTableAtPath } from './sync/trigger-suspend-at-path.js';
|
|
36
37
|
import { installSchemaWriteGuard } from './worktree-build-guard.js';
|
|
37
38
|
import { assertOwnerStoreRewriteConfirmed } from './worktree-isolation-guard.js';
|
|
38
39
|
const _require = createRequire(import.meta.url);
|
|
@@ -251,11 +252,17 @@ function relocateRegistryRows(stagedGlobalDb, moves) {
|
|
|
251
252
|
}
|
|
252
253
|
return outcomes;
|
|
253
254
|
}
|
|
254
|
-
function placeSection(stagingDir, plan) {
|
|
255
|
+
function placeSection(stagingDir, plan, machineLocalFile) {
|
|
255
256
|
fs.mkdirSync(plan.destDir, { recursive: true });
|
|
257
|
+
const kept = [];
|
|
256
258
|
for (const f of plan.section.files) {
|
|
257
259
|
const src = path.join(stagingDir, f.bundlePath);
|
|
258
260
|
const dst = path.join(plan.destDir, f.relPath);
|
|
261
|
+
const local = machineLocalFile?.(f.relPath) ?? null;
|
|
262
|
+
if (local === 'skip' || (local === 'keep' && fs.existsSync(dst))) {
|
|
263
|
+
kept.push(f.relPath);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
259
266
|
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
260
267
|
fs.copyFileSync(src, dst);
|
|
261
268
|
fs.chmodSync(dst, fs.statSync(src).mode & 0o777);
|
|
@@ -277,7 +284,11 @@ function placeSection(stagingDir, plan) {
|
|
|
277
284
|
fs.rmSync(dst, { force: true });
|
|
278
285
|
fs.symlinkSync(link.target, dst);
|
|
279
286
|
}
|
|
280
|
-
return {
|
|
287
|
+
return {
|
|
288
|
+
files: plan.section.files.length - kept.length,
|
|
289
|
+
dbs: plan.section.databases.length,
|
|
290
|
+
kept,
|
|
291
|
+
};
|
|
281
292
|
}
|
|
282
293
|
/**
|
|
283
294
|
* Re-encrypt one section's sealed credentials under the TARGET home's keys.
|
|
@@ -420,6 +431,8 @@ export async function importPortableBundle(input) {
|
|
|
420
431
|
fs.rmSync(tarPath, { force: true });
|
|
421
432
|
// ----- 2. verify ------------------------------------------------------
|
|
422
433
|
const manifest = await verifyStaged(extractDir);
|
|
434
|
+
if (input.onStaged)
|
|
435
|
+
await input.onStaged(extractDir, manifest);
|
|
423
436
|
// ----- 3. plan + pre-check -------------------------------------------
|
|
424
437
|
const plans = planPlacements(manifest, input, cleoHome, configHome);
|
|
425
438
|
if (input.force !== true)
|
|
@@ -471,9 +484,16 @@ export async function importPortableBundle(input) {
|
|
|
471
484
|
// ----- 5. place + 6. verify counts ------------------------------------
|
|
472
485
|
const sections = [];
|
|
473
486
|
for (const plan of plans) {
|
|
474
|
-
const written = placeSection(extractDir, plan);
|
|
487
|
+
const written = placeSection(extractDir, plan, input.machineLocalFile);
|
|
475
488
|
const counts = compareCounts(plan);
|
|
476
|
-
const hashes = await compareHashes(plan, rewrittenEntries(plan, relocations, registryOutcomes));
|
|
489
|
+
const hashes = await compareHashes(plan, new Set([...rewrittenEntries(plan, relocations, registryOutcomes), ...written.kept]));
|
|
490
|
+
// T12819: a placed project store gets cleo_trigger_suspend, after the
|
|
491
|
+
// count and hash checks (they compare the bundle's own tables).
|
|
492
|
+
for (const d of plan.section.databases) {
|
|
493
|
+
if (path.basename(d.relPath) === 'cleo.db') {
|
|
494
|
+
ensureTriggerSuspendTableAtPath(path.join(plan.destDir, d.relPath));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
477
497
|
const result = {
|
|
478
498
|
kind: plan.kind,
|
|
479
499
|
originalRoot: plan.section.originalRoot,
|