@cleocode/core 2026.9.8 → 2026.9.9
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/audit/reconstruct.d.ts +13 -43
- package/dist/audit/reconstruct.d.ts.map +1 -1
- package/dist/audit/reconstruct.js +295 -290
- package/dist/audit/reconstruct.js.map +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +8 -2
- package/dist/bootstrap.js.map +1 -1
- package/dist/dispatch/mutate-projection.d.ts.map +1 -1
- package/dist/dispatch/mutate-projection.js +12 -0
- package/dist/dispatch/mutate-projection.js.map +1 -1
- package/dist/dispatch/mvi-projection.d.ts +29 -6
- package/dist/dispatch/mvi-projection.d.ts.map +1 -1
- package/dist/dispatch/mvi-projection.js +109 -139
- package/dist/dispatch/mvi-projection.js.map +1 -1
- package/dist/docs/docs-read-model.d.ts +3 -2
- package/dist/docs/docs-read-model.d.ts.map +1 -1
- package/dist/docs/docs-read-model.js +4 -3
- package/dist/docs/docs-read-model.js.map +1 -1
- package/dist/docs/export-document.js +5100 -2297
- package/dist/docs/export-document.js.map +3 -3
- package/dist/docs/projection.d.ts +67 -0
- package/dist/docs/projection.d.ts.map +1 -0
- package/dist/docs/projection.js +370 -0
- package/dist/docs/projection.js.map +1 -0
- package/dist/doctor/acceptance-drift.d.ts +6 -2
- package/dist/doctor/acceptance-drift.d.ts.map +1 -1
- package/dist/doctor/acceptance-drift.js +43 -5
- package/dist/doctor/acceptance-drift.js.map +1 -1
- package/dist/doctor/knowledge-summary.d.ts +41 -0
- package/dist/doctor/knowledge-summary.d.ts.map +1 -0
- package/dist/doctor/knowledge-summary.js +81 -0
- package/dist/doctor/knowledge-summary.js.map +1 -0
- package/dist/doctor/knowledge.d.ts +192 -0
- package/dist/doctor/knowledge.d.ts.map +1 -0
- package/dist/doctor/knowledge.js +1864 -0
- package/dist/doctor/knowledge.js.map +1 -0
- package/dist/git/work-tree.d.ts +64 -0
- package/dist/git/work-tree.d.ts.map +1 -0
- package/dist/git/work-tree.js +111 -0
- package/dist/git/work-tree.js.map +1 -0
- package/dist/hooks/handlers/task-hooks.d.ts +8 -5
- package/dist/hooks/handlers/task-hooks.d.ts.map +1 -1
- package/dist/hooks/handlers/task-hooks.js +15 -60
- package/dist/hooks/handlers/task-hooks.js.map +1 -1
- package/dist/identity/cleo-identity.d.ts +13 -0
- package/dist/identity/cleo-identity.d.ts.map +1 -1
- package/dist/identity/cleo-identity.js +20 -6
- package/dist/identity/cleo-identity.js.map +1 -1
- package/dist/injection.d.ts.map +1 -1
- package/dist/injection.js +29 -13
- package/dist/injection.js.map +1 -1
- package/dist/internal.d.ts +2 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -0
- package/dist/internal.js.map +1 -1
- package/dist/lifecycle/verification/satisfies-validator.d.ts.map +1 -1
- package/dist/lifecycle/verification/satisfies-validator.js +124 -120
- package/dist/lifecycle/verification/satisfies-validator.js.map +1 -1
- package/dist/llm/plugin-facade.js +4018 -1726
- package/dist/llm/plugin-facade.js.map +3 -3
- package/dist/memory/brain-backfill.d.ts +27 -12
- package/dist/memory/brain-backfill.d.ts.map +1 -1
- package/dist/memory/brain-backfill.js +325 -134
- package/dist/memory/brain-backfill.js.map +1 -1
- package/dist/memory/brain-doctor.d.ts +21 -0
- package/dist/memory/brain-doctor.d.ts.map +1 -1
- package/dist/memory/brain-doctor.js +111 -53
- package/dist/memory/brain-doctor.js.map +1 -1
- package/dist/memory/brain-links.d.ts.map +1 -1
- package/dist/memory/brain-links.js +31 -4
- package/dist/memory/brain-links.js.map +1 -1
- package/dist/memory/brain-reasoning.d.ts.map +1 -1
- package/dist/memory/brain-reasoning.js +28 -2
- package/dist/memory/brain-reasoning.js.map +1 -1
- package/dist/memory/brain-reconciler.d.ts +14 -19
- package/dist/memory/brain-reconciler.d.ts.map +1 -1
- package/dist/memory/brain-reconciler.js +70 -97
- package/dist/memory/brain-reconciler.js.map +1 -1
- package/dist/memory/brain-search.d.ts +2 -0
- package/dist/memory/brain-search.d.ts.map +1 -1
- package/dist/memory/brain-search.js +59 -29
- package/dist/memory/brain-search.js.map +1 -1
- package/dist/memory/brain-similarity.d.ts.map +1 -1
- package/dist/memory/brain-similarity.js +5 -4
- package/dist/memory/brain-similarity.js.map +1 -1
- package/dist/memory/brain-stub-prune.d.ts +31 -9
- package/dist/memory/brain-stub-prune.d.ts.map +1 -1
- package/dist/memory/brain-stub-prune.js +65 -18
- package/dist/memory/brain-stub-prune.js.map +1 -1
- package/dist/memory/brain-writer-handlers.d.ts +10 -1
- package/dist/memory/brain-writer-handlers.d.ts.map +1 -1
- package/dist/memory/brain-writer-handlers.js +23 -3
- package/dist/memory/brain-writer-handlers.js.map +1 -1
- package/dist/memory/brain-writer-thread.d.ts +11 -1
- package/dist/memory/brain-writer-thread.d.ts.map +1 -1
- package/dist/memory/brain-writer-thread.js +87 -20
- package/dist/memory/brain-writer-thread.js.map +1 -1
- package/dist/memory/brain-writer-worker.js +8 -1
- package/dist/memory/brain-writer-worker.js.map +1 -1
- package/dist/memory/decision-cross-link.d.ts +39 -0
- package/dist/memory/decision-cross-link.d.ts.map +1 -1
- package/dist/memory/decision-cross-link.js +316 -0
- package/dist/memory/decision-cross-link.js.map +1 -1
- package/dist/memory/decisions.d.ts +4 -1
- package/dist/memory/decisions.d.ts.map +1 -1
- package/dist/memory/decisions.js +7 -24
- package/dist/memory/decisions.js.map +1 -1
- package/dist/memory/dispatch-trace.d.ts +12 -5
- package/dist/memory/dispatch-trace.d.ts.map +1 -1
- package/dist/memory/dispatch-trace.js +17 -7
- package/dist/memory/dispatch-trace.js.map +1 -1
- package/dist/memory/eligibility.d.ts +51 -0
- package/dist/memory/eligibility.d.ts.map +1 -0
- package/dist/memory/eligibility.js +77 -0
- package/dist/memory/eligibility.js.map +1 -0
- package/dist/memory/engine-compat.d.ts +2 -0
- package/dist/memory/engine-compat.d.ts.map +1 -1
- package/dist/memory/engine-compat.js +10 -0
- package/dist/memory/engine-compat.js.map +1 -1
- package/dist/memory/extraction-gate.d.ts +21 -7
- package/dist/memory/extraction-gate.d.ts.map +1 -1
- package/dist/memory/extraction-gate.js +178 -216
- package/dist/memory/extraction-gate.js.map +1 -1
- package/dist/memory/graph-auto-populate.d.ts +38 -5
- package/dist/memory/graph-auto-populate.d.ts.map +1 -1
- package/dist/memory/graph-auto-populate.js +182 -60
- package/dist/memory/graph-auto-populate.js.map +1 -1
- package/dist/memory/graph-memory-bridge.d.ts +14 -1
- package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
- package/dist/memory/graph-memory-bridge.js +66 -28
- package/dist/memory/graph-memory-bridge.js.map +1 -1
- package/dist/memory/index.d.ts +1 -19
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +1 -50
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/learnings.d.ts.map +1 -1
- package/dist/memory/learnings.js +2 -23
- package/dist/memory/learnings.js.map +1 -1
- package/dist/memory/manifest-filter.d.ts +21 -0
- package/dist/memory/manifest-filter.d.ts.map +1 -0
- package/dist/memory/manifest-filter.js +51 -0
- package/dist/memory/manifest-filter.js.map +1 -0
- package/dist/memory/manifest-ingestion.d.ts +28 -30
- package/dist/memory/manifest-ingestion.d.ts.map +1 -1
- package/dist/memory/manifest-ingestion.js +104 -235
- package/dist/memory/manifest-ingestion.js.map +1 -1
- package/dist/memory/observer-reflector.d.ts +2 -0
- package/dist/memory/observer-reflector.d.ts.map +1 -1
- package/dist/memory/observer-reflector.js +6 -49
- package/dist/memory/observer-reflector.js.map +1 -1
- package/dist/memory/patterns.d.ts +10 -0
- package/dist/memory/patterns.d.ts.map +1 -1
- package/dist/memory/patterns.js +25 -33
- package/dist/memory/patterns.js.map +1 -1
- package/dist/memory/pipeline-manifest-sqlite.d.ts +72 -9
- package/dist/memory/pipeline-manifest-sqlite.d.ts.map +1 -1
- package/dist/memory/pipeline-manifest-sqlite.js +508 -412
- package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
- package/dist/memory/retrieval/build-retrieval-bundle.d.ts.map +1 -1
- package/dist/memory/retrieval/build-retrieval-bundle.js +16 -15
- package/dist/memory/retrieval/build-retrieval-bundle.js.map +1 -1
- package/dist/memory/retrieval/fetch.d.ts +7 -0
- package/dist/memory/retrieval/fetch.d.ts.map +1 -1
- package/dist/memory/retrieval/fetch.js +14 -11
- package/dist/memory/retrieval/fetch.js.map +1 -1
- package/dist/memory/retrieval/observe.d.ts +7 -1
- package/dist/memory/retrieval/observe.d.ts.map +1 -1
- package/dist/memory/retrieval/observe.js +58 -4
- package/dist/memory/retrieval/observe.js.map +1 -1
- package/dist/memory/retrieval/search.d.ts +14 -1
- package/dist/memory/retrieval/search.d.ts.map +1 -1
- package/dist/memory/retrieval/search.js +133 -69
- package/dist/memory/retrieval/search.js.map +1 -1
- package/dist/memory/retrieval/telemetry.d.ts +31 -0
- package/dist/memory/retrieval/telemetry.d.ts.map +1 -0
- package/dist/memory/retrieval/telemetry.js +53 -0
- package/dist/memory/retrieval/telemetry.js.map +1 -0
- package/dist/nexus/analyze-orchestrator.d.ts +41 -9
- package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
- package/dist/nexus/analyze-orchestrator.js +257 -58
- package/dist/nexus/analyze-orchestrator.js.map +1 -1
- package/dist/nexus/api-contracts.d.ts +2 -6
- package/dist/nexus/api-contracts.d.ts.map +1 -1
- package/dist/nexus/api-contracts.js +11 -2
- package/dist/nexus/api-contracts.js.map +1 -1
- package/dist/nexus/context.d.ts.map +1 -1
- package/dist/nexus/context.js +14 -37
- package/dist/nexus/context.js.map +1 -1
- package/dist/nexus/diff.d.ts.map +1 -1
- package/dist/nexus/diff.js +2 -1
- package/dist/nexus/diff.js.map +1 -1
- package/dist/nexus/identity.d.ts +29 -3
- package/dist/nexus/identity.d.ts.map +1 -1
- package/dist/nexus/identity.js +63 -12
- package/dist/nexus/identity.js.map +1 -1
- package/dist/nexus/impact.d.ts +21 -19
- package/dist/nexus/impact.d.ts.map +1 -1
- package/dist/nexus/impact.js +96 -192
- package/dist/nexus/impact.js.map +1 -1
- package/dist/nexus/knowledge.d.ts +80 -0
- package/dist/nexus/knowledge.d.ts.map +1 -0
- package/dist/nexus/knowledge.js +786 -0
- package/dist/nexus/knowledge.js.map +1 -0
- package/dist/nexus/living-brain.d.ts +8 -5
- package/dist/nexus/living-brain.d.ts.map +1 -1
- package/dist/nexus/living-brain.js +252 -188
- package/dist/nexus/living-brain.js.map +1 -1
- package/dist/nexus/registry.d.ts +11 -2
- package/dist/nexus/registry.d.ts.map +1 -1
- package/dist/nexus/registry.js +144 -128
- package/dist/nexus/registry.js.map +1 -1
- package/dist/nexus/source-roots.d.ts +16 -0
- package/dist/nexus/source-roots.d.ts.map +1 -0
- package/dist/nexus/source-roots.js +174 -0
- package/dist/nexus/source-roots.js.map +1 -0
- package/dist/nexus/task-evidence.d.ts +22 -0
- package/dist/nexus/task-evidence.d.ts.map +1 -0
- package/dist/nexus/task-evidence.js +210 -0
- package/dist/nexus/task-evidence.js.map +1 -0
- package/dist/nexus/tasks-bridge.d.ts +14 -7
- package/dist/nexus/tasks-bridge.d.ts.map +1 -1
- package/dist/nexus/tasks-bridge.js +81 -40
- package/dist/nexus/tasks-bridge.js.map +1 -1
- package/dist/orchestrate/lifecycle-ops.d.ts.map +1 -1
- package/dist/orchestrate/lifecycle-ops.js +170 -120
- package/dist/orchestrate/lifecycle-ops.js.map +1 -1
- package/dist/orchestrate/query-ops.d.ts +6 -7
- package/dist/orchestrate/query-ops.d.ts.map +1 -1
- package/dist/orchestrate/query-ops.js +509 -532
- package/dist/orchestrate/query-ops.js.map +1 -1
- package/dist/orchestration/bootstrap.d.ts +15 -1
- package/dist/orchestration/bootstrap.d.ts.map +1 -1
- package/dist/orchestration/bootstrap.js +21 -10
- package/dist/orchestration/bootstrap.js.map +1 -1
- package/dist/orchestration/index.d.ts +35 -3
- package/dist/orchestration/index.d.ts.map +1 -1
- package/dist/orchestration/index.js +64 -35
- package/dist/orchestration/index.js.map +1 -1
- package/dist/orchestration/lead-rollup.d.ts +24 -1
- package/dist/orchestration/lead-rollup.d.ts.map +1 -1
- package/dist/orchestration/lead-rollup.js +31 -11
- package/dist/orchestration/lead-rollup.js.map +1 -1
- package/dist/orchestration/spawn-prompt.d.ts.map +1 -1
- package/dist/orchestration/spawn-prompt.js +16 -41
- package/dist/orchestration/spawn-prompt.js.map +1 -1
- package/dist/orchestration/unblock.d.ts +15 -1
- package/dist/orchestration/unblock.d.ts.map +1 -1
- package/dist/orchestration/unblock.js +23 -12
- package/dist/orchestration/unblock.js.map +1 -1
- package/dist/orchestration/validate-spawn.d.ts.map +1 -1
- package/dist/orchestration/validate-spawn.js +3 -3
- package/dist/orchestration/validate-spawn.js.map +1 -1
- package/dist/orchestration/waves.d.ts +29 -13
- package/dist/orchestration/waves.d.ts.map +1 -1
- package/dist/orchestration/waves.js +43 -55
- package/dist/orchestration/waves.js.map +1 -1
- package/dist/paths.d.ts +17 -163
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +145 -496
- package/dist/paths.js.map +1 -1
- package/dist/project-info.d.ts +2 -11
- package/dist/project-info.d.ts.map +1 -1
- package/dist/project-info.js +3 -31
- package/dist/project-info.js.map +1 -1
- package/dist/project-scope.d.ts +239 -0
- package/dist/project-scope.d.ts.map +1 -0
- package/dist/project-scope.js +473 -0
- package/dist/project-scope.js.map +1 -0
- package/dist/release/pr-evidence.d.ts +16 -3
- package/dist/release/pr-evidence.d.ts.map +1 -1
- package/dist/release/pr-evidence.js +53 -7
- package/dist/release/pr-evidence.js.map +1 -1
- package/dist/render/nexus/graph/index.d.ts.map +1 -1
- package/dist/render/nexus/graph/index.js +4 -2
- package/dist/render/nexus/graph/index.js.map +1 -1
- package/dist/render/orchestration/audit-reconstruct.d.ts +11 -0
- package/dist/render/orchestration/audit-reconstruct.d.ts.map +1 -1
- package/dist/render/orchestration/audit-reconstruct.js +21 -6
- package/dist/render/orchestration/audit-reconstruct.js.map +1 -1
- package/dist/render/tasks/show.js +2 -1
- package/dist/render/tasks/show.js.map +1 -1
- package/dist/resources/spawn-wrapper.d.ts +82 -14
- package/dist/resources/spawn-wrapper.d.ts.map +1 -1
- package/dist/resources/spawn-wrapper.js +585 -27
- package/dist/resources/spawn-wrapper.js.map +1 -1
- package/dist/selfimprove/fix-gen.js +4026 -1734
- package/dist/selfimprove/fix-gen.js.map +3 -3
- package/dist/sequence/index.d.ts.map +1 -1
- package/dist/sequence/index.js +76 -68
- package/dist/sequence/index.js.map +1 -1
- package/dist/session/canon-lint.d.ts +24 -3
- package/dist/session/canon-lint.d.ts.map +1 -1
- package/dist/session/canon-lint.js +72 -31
- package/dist/session/canon-lint.js.map +1 -1
- package/dist/session/engine-ops.d.ts +1 -4
- package/dist/session/engine-ops.d.ts.map +1 -1
- package/dist/session/engine-ops.js +6 -2
- package/dist/session/engine-ops.js.map +1 -1
- package/dist/sessions/briefing.d.ts +11 -1
- package/dist/sessions/briefing.d.ts.map +1 -1
- package/dist/sessions/briefing.js +76 -8
- package/dist/sessions/briefing.js.map +1 -1
- package/dist/sessions/handoff.d.ts +3 -1
- package/dist/sessions/handoff.d.ts.map +1 -1
- package/dist/sessions/handoff.js +2 -0
- package/dist/sessions/handoff.js.map +1 -1
- package/dist/shutdown-deadline.d.ts +24 -33
- package/dist/shutdown-deadline.d.ts.map +1 -1
- package/dist/shutdown-deadline.js +71 -14
- package/dist/shutdown-deadline.js.map +1 -1
- package/dist/shutdown.d.ts +21 -10
- package/dist/shutdown.d.ts.map +1 -1
- package/dist/shutdown.js +89 -42
- package/dist/shutdown.js.map +1 -1
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +1 -1
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/orchestrator/validator.d.ts +87 -20
- package/dist/skills/orchestrator/validator.d.ts.map +1 -1
- package/dist/skills/orchestrator/validator.js +330 -241
- package/dist/skills/orchestrator/validator.js.map +1 -1
- package/dist/store/agent-resolver.d.ts.map +1 -1
- package/dist/store/agent-resolver.js +16 -9
- package/dist/store/agent-resolver.js.map +1 -1
- package/dist/store/attachment-store.d.ts +4 -1
- package/dist/store/attachment-store.d.ts.map +1 -1
- package/dist/store/attachment-store.js +20 -3
- package/dist/store/attachment-store.js.map +1 -1
- package/dist/store/background-jobs.d.ts +426 -105
- package/dist/store/background-jobs.d.ts.map +1 -1
- package/dist/store/background-jobs.js +1208 -252
- package/dist/store/background-jobs.js.map +1 -1
- package/dist/store/background-ops.d.ts +145 -8
- package/dist/store/background-ops.d.ts.map +1 -1
- package/dist/store/background-ops.js +459 -15
- package/dist/store/background-ops.js.map +1 -1
- package/dist/store/backup-inspect.d.ts +48 -4
- package/dist/store/backup-inspect.d.ts.map +1 -1
- package/dist/store/backup-inspect.js +384 -4
- package/dist/store/backup-inspect.js.map +1 -1
- package/dist/store/converters.d.ts.map +1 -1
- package/dist/store/converters.js +19 -2
- package/dist/store/converters.js.map +1 -1
- package/dist/store/data-accessor.d.ts +9 -1
- package/dist/store/data-accessor.d.ts.map +1 -1
- package/dist/store/data-accessor.js +22 -5
- package/dist/store/data-accessor.js.map +1 -1
- package/dist/store/data-safety-central.d.ts.map +1 -1
- package/dist/store/data-safety-central.js +272 -232
- package/dist/store/data-safety-central.js.map +1 -1
- package/dist/store/db-helpers.d.ts +19 -3
- package/dist/store/db-helpers.d.ts.map +1 -1
- package/dist/store/db-helpers.js +42 -58
- package/dist/store/db-helpers.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts +63 -4
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +166 -19
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/exodus/archive.d.ts +21 -7
- package/dist/store/exodus/archive.d.ts.map +1 -1
- package/dist/store/exodus/archive.js +60 -18
- package/dist/store/exodus/archive.js.map +1 -1
- package/dist/store/exodus/migrate.d.ts.map +1 -1
- package/dist/store/exodus/migrate.js +27 -23
- package/dist/store/exodus/migrate.js.map +1 -1
- package/dist/store/exodus/on-open.d.ts +16 -27
- package/dist/store/exodus/on-open.d.ts.map +1 -1
- package/dist/store/exodus/on-open.js +121 -169
- package/dist/store/exodus/on-open.js.map +1 -1
- package/dist/store/exodus/recovery.d.ts +90 -0
- package/dist/store/exodus/recovery.d.ts.map +1 -0
- package/dist/store/exodus/recovery.js +434 -0
- package/dist/store/exodus/recovery.js.map +1 -0
- package/dist/store/exodus/types.d.ts +15 -0
- package/dist/store/exodus/types.d.ts.map +1 -1
- package/dist/store/memory-accessor.d.ts +52 -3
- package/dist/store/memory-accessor.d.ts.map +1 -1
- package/dist/store/memory-accessor.js +122 -7
- package/dist/store/memory-accessor.js.map +1 -1
- package/dist/store/nexus-sqlite.d.ts +24 -6
- package/dist/store/nexus-sqlite.d.ts.map +1 -1
- package/dist/store/nexus-sqlite.js +39 -20
- package/dist/store/nexus-sqlite.js.map +1 -1
- package/dist/store/ports/domain-binding.d.ts.map +1 -1
- package/dist/store/ports/domain-binding.js +27 -5
- package/dist/store/ports/domain-binding.js.map +1 -1
- package/dist/store/schema/background-jobs.d.ts +181 -2
- package/dist/store/schema/background-jobs.d.ts.map +1 -1
- package/dist/store/schema/background-jobs.js +27 -3
- package/dist/store/schema/background-jobs.js.map +1 -1
- package/dist/store/schema/cleo-global/skills.d.ts +2 -2
- package/dist/store/schema/cleo-project/lifecycle.d.ts +2 -2
- package/dist/store/schema/cleo-project/runtime.d.ts +1 -1
- package/dist/store/schema/cleo-project/tasks-core.d.ts +1 -1
- package/dist/store/schema/lifecycle.d.ts +2 -2
- package/dist/store/schema/skills-schema.d.ts +2 -2
- package/dist/store/schema/tasks.d.ts +1 -1
- package/dist/store/session-store.d.ts +3 -1
- package/dist/store/session-store.d.ts.map +1 -1
- package/dist/store/session-store.js +252 -207
- package/dist/store/session-store.js.map +1 -1
- package/dist/store/sqlite-data-accessor.d.ts +39 -4
- package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
- package/dist/store/sqlite-data-accessor.js +689 -527
- package/dist/store/sqlite-data-accessor.js.map +1 -1
- package/dist/store/tasks-sqlite.d.ts +3 -1
- package/dist/store/tasks-sqlite.d.ts.map +1 -1
- package/dist/store/tasks-sqlite.js +309 -279
- package/dist/store/tasks-sqlite.js.map +1 -1
- package/dist/store/validation-schemas.d.ts +8 -8
- package/dist/store/writer-lease.d.ts +80 -8
- package/dist/store/writer-lease.d.ts.map +1 -1
- package/dist/store/writer-lease.js +503 -134
- package/dist/store/writer-lease.js.map +1 -1
- package/dist/system/audit.d.ts +2 -1
- package/dist/system/audit.d.ts.map +1 -1
- package/dist/system/audit.js +118 -71
- package/dist/system/audit.js.map +1 -1
- package/dist/system/backup.d.ts.map +1 -1
- package/dist/system/backup.js +5 -5
- package/dist/system/backup.js.map +1 -1
- package/dist/system/inject-generate.js +1 -1
- package/dist/task-work/index.d.ts +3 -0
- package/dist/task-work/index.d.ts.map +1 -1
- package/dist/task-work/index.js +34 -37
- package/dist/task-work/index.js.map +1 -1
- package/dist/tasks/ac-coverage-gate.d.ts.map +1 -1
- package/dist/tasks/ac-coverage-gate.js +4 -0
- package/dist/tasks/ac-coverage-gate.js.map +1 -1
- package/dist/tasks/ac-immutability.d.ts +7 -4
- package/dist/tasks/ac-immutability.d.ts.map +1 -1
- package/dist/tasks/ac-immutability.js +19 -17
- package/dist/tasks/ac-immutability.js.map +1 -1
- package/dist/tasks/ac-table.d.ts +5 -5
- package/dist/tasks/ac-table.d.ts.map +1 -1
- package/dist/tasks/ac-table.js +26 -12
- package/dist/tasks/ac-table.js.map +1 -1
- package/dist/tasks/acceptance-input.d.ts +52 -0
- package/dist/tasks/acceptance-input.d.ts.map +1 -0
- package/dist/tasks/acceptance-input.js +259 -0
- package/dist/tasks/acceptance-input.js.map +1 -0
- package/dist/tasks/add.d.ts +67 -29
- package/dist/tasks/add.d.ts.map +1 -1
- package/dist/tasks/add.js +255 -97
- package/dist/tasks/add.js.map +1 -1
- package/dist/tasks/complete.d.ts +16 -1
- package/dist/tasks/complete.d.ts.map +1 -1
- package/dist/tasks/complete.js +152 -55
- package/dist/tasks/complete.js.map +1 -1
- package/dist/tasks/decompose.d.ts +103 -0
- package/dist/tasks/decompose.d.ts.map +1 -0
- package/dist/tasks/decompose.js +224 -0
- package/dist/tasks/decompose.js.map +1 -0
- package/dist/tasks/delete.d.ts +5 -8
- package/dist/tasks/delete.d.ts.map +1 -1
- package/dist/tasks/delete.js +4 -3
- package/dist/tasks/delete.js.map +1 -1
- package/dist/tasks/dependency-check.d.ts +59 -0
- package/dist/tasks/dependency-check.d.ts.map +1 -1
- package/dist/tasks/dependency-check.js +73 -0
- package/dist/tasks/dependency-check.js.map +1 -1
- package/dist/tasks/deps-ready.d.ts +13 -1
- package/dist/tasks/deps-ready.d.ts.map +1 -1
- package/dist/tasks/deps-ready.js +16 -5
- package/dist/tasks/deps-ready.js.map +1 -1
- package/dist/tasks/engine-converters.d.ts +7 -0
- package/dist/tasks/engine-converters.d.ts.map +1 -1
- package/dist/tasks/engine-converters.js +8 -1
- package/dist/tasks/engine-converters.js.map +1 -1
- package/dist/tasks/evidence.d.ts +54 -26
- package/dist/tasks/evidence.d.ts.map +1 -1
- package/dist/tasks/evidence.js +292 -40
- package/dist/tasks/evidence.js.map +1 -1
- package/dist/tasks/find.d.ts +16 -12
- package/dist/tasks/find.d.ts.map +1 -1
- package/dist/tasks/find.js +107 -93
- package/dist/tasks/find.js.map +1 -1
- package/dist/tasks/gate-runner.d.ts +88 -14
- package/dist/tasks/gate-runner.d.ts.map +1 -1
- package/dist/tasks/gate-runner.js +596 -253
- package/dist/tasks/gate-runner.js.map +1 -1
- package/dist/tasks/hierarchy-policy.d.ts +8 -0
- package/dist/tasks/hierarchy-policy.d.ts.map +1 -1
- package/dist/tasks/hierarchy-policy.js +9 -2
- package/dist/tasks/hierarchy-policy.js.map +1 -1
- package/dist/tasks/hierarchy.d.ts +67 -1
- package/dist/tasks/hierarchy.d.ts.map +1 -1
- package/dist/tasks/hierarchy.js +81 -1
- package/dist/tasks/hierarchy.js.map +1 -1
- package/dist/tasks/index.d.ts +3 -0
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/index.js +3 -0
- package/dist/tasks/index.js.map +1 -1
- package/dist/tasks/infer-add-params.d.ts +1 -20
- package/dist/tasks/infer-add-params.d.ts.map +1 -1
- package/dist/tasks/infer-add-params.js +2 -203
- package/dist/tasks/infer-add-params.js.map +1 -1
- package/dist/tasks/list.d.ts +7 -2
- package/dist/tasks/list.d.ts.map +1 -1
- package/dist/tasks/list.js +24 -36
- package/dist/tasks/list.js.map +1 -1
- package/dist/tasks/ops.d.ts +6 -61
- package/dist/tasks/ops.d.ts.map +1 -1
- package/dist/tasks/ops.js +5 -53
- package/dist/tasks/ops.js.map +1 -1
- package/dist/tasks/plan.d.ts +15 -1
- package/dist/tasks/plan.d.ts.map +1 -1
- package/dist/tasks/plan.js +23 -25
- package/dist/tasks/plan.js.map +1 -1
- package/dist/tasks/population.d.ts +46 -0
- package/dist/tasks/population.d.ts.map +1 -0
- package/dist/tasks/population.js +88 -0
- package/dist/tasks/population.js.map +1 -0
- package/dist/tasks/reconcile-scope.d.ts +157 -0
- package/dist/tasks/reconcile-scope.d.ts.map +1 -0
- package/dist/tasks/reconcile-scope.js +242 -0
- package/dist/tasks/reconcile-scope.js.map +1 -0
- package/dist/tasks/req.d.ts +51 -12
- package/dist/tasks/req.d.ts.map +1 -1
- package/dist/tasks/req.js +125 -69
- package/dist/tasks/req.js.map +1 -1
- package/dist/tasks/session-scope.d.ts +6 -31
- package/dist/tasks/session-scope.d.ts.map +1 -1
- package/dist/tasks/session-scope.js +3 -17
- package/dist/tasks/session-scope.js.map +1 -1
- package/dist/tasks/severity-attestation.d.ts +39 -10
- package/dist/tasks/severity-attestation.d.ts.map +1 -1
- package/dist/tasks/severity-attestation.js +75 -36
- package/dist/tasks/severity-attestation.js.map +1 -1
- package/dist/tasks/task-next.d.ts +5 -0
- package/dist/tasks/task-next.d.ts.map +1 -1
- package/dist/tasks/task-next.js +10 -9
- package/dist/tasks/task-next.js.map +1 -1
- package/dist/tasks/task-reparent.d.ts.map +1 -1
- package/dist/tasks/task-reparent.js +3 -13
- package/dist/tasks/task-reparent.js.map +1 -1
- package/dist/tasks/update.d.ts +20 -43
- package/dist/tasks/update.d.ts.map +1 -1
- package/dist/tasks/update.js +64 -49
- package/dist/tasks/update.js.map +1 -1
- package/dist/validation/engine-ops.d.ts +17 -1
- package/dist/validation/engine-ops.d.ts.map +1 -1
- package/dist/validation/engine-ops.js +149 -11
- package/dist/validation/engine-ops.js.map +1 -1
- package/dist/workgraph/reparent-preflight.d.ts +1 -1
- package/dist/workgraph/reparent-preflight.d.ts.map +1 -1
- package/dist/workgraph/reparent-preflight.js +6 -1
- package/dist/workgraph/reparent-preflight.js.map +1 -1
- package/dist/workgraph/scaffold-apply.d.ts.map +1 -1
- package/dist/workgraph/scaffold-apply.js +81 -76
- package/dist/workgraph/scaffold-apply.js.map +1 -1
- package/dist/workgraph/structure-validation.d.ts +1 -1
- package/dist/workgraph/structure-validation.d.ts.map +1 -1
- package/dist/workgraph/structure-validation.js +6 -1
- package/dist/workgraph/structure-validation.js.map +1 -1
- package/migrations/drizzle-tasks/20260919180000_t12263-job-ownership-fences/migration.sql +34 -0
- package/migrations/drizzle-tasks/20260919184500_t12265-durable-pending-proposals/migration.sql +4 -0
- package/package.json +18 -13
- package/schemas/config.schema.json +2 -2
- package/templates/CLEO-INJECTION.md +103 -101
|
@@ -17,12 +17,18 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { eq } from 'drizzle-orm';
|
|
19
19
|
import { getLogger } from '../logger.js';
|
|
20
|
+
import { captureProjectScope, getProjectRoot, worktreeScope } from '../project-scope.js';
|
|
20
21
|
import { checkSequence, repairSequence } from '../sequence/index.js';
|
|
21
22
|
import { gitCheckpoint } from './git-checkpoint.js';
|
|
22
23
|
import { getDb } from './sqlite.js';
|
|
23
24
|
import { vacuumIntoBackup } from './sqlite-backup.js';
|
|
24
25
|
import * as schema from './tasks-schema.js';
|
|
25
26
|
const log = getLogger('data-safety');
|
|
27
|
+
/** Bind explicit ownership before the first asynchronous safety or callback step. */
|
|
28
|
+
function inSafetyScope(cwd, operation) {
|
|
29
|
+
const scope = captureProjectScope(cwd ?? getProjectRoot(), worktreeScope.getStore());
|
|
30
|
+
return worktreeScope.run(scope, () => operation(scope.worktreeRoot));
|
|
31
|
+
}
|
|
26
32
|
/** Safety violation error */
|
|
27
33
|
export class DataSafetyError extends Error {
|
|
28
34
|
code;
|
|
@@ -127,21 +133,25 @@ async function verifyArchiveFile(data, accessor, options) {
|
|
|
127
133
|
* Safe wrapper for DataAccessor.saveSessions()
|
|
128
134
|
*/
|
|
129
135
|
export async function safeSaveSessions(accessor, data, cwd, options) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
136
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
137
|
+
const opts = { ...DEFAULT_SAFETY, ...options };
|
|
138
|
+
await accessor.saveSessions(data);
|
|
139
|
+
stats.writes++;
|
|
140
|
+
await verifySessions(data, accessor, opts);
|
|
141
|
+
await checkpoint(`saved Sessions (${data.length} sessions)`, cwd, opts);
|
|
142
|
+
});
|
|
135
143
|
}
|
|
136
144
|
/**
|
|
137
145
|
* Safe wrapper for DataAccessor.saveArchive()
|
|
138
146
|
*/
|
|
139
147
|
export async function safeSaveArchive(accessor, data, cwd, options) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
149
|
+
const opts = { ...DEFAULT_SAFETY, ...options };
|
|
150
|
+
await accessor.saveArchive(data);
|
|
151
|
+
stats.writes++;
|
|
152
|
+
await verifyArchiveFile(data, accessor, opts);
|
|
153
|
+
await checkpoint(`saved Archive (${data.archivedTasks.length} tasks)`, cwd, opts);
|
|
154
|
+
});
|
|
145
155
|
}
|
|
146
156
|
/**
|
|
147
157
|
* Safe wrapper for single-task write operations (T5034).
|
|
@@ -155,14 +165,16 @@ export async function safeSaveArchive(accessor, data, cwd, options) {
|
|
|
155
165
|
* itself is a targeted SQL operation that either succeeds or throws.
|
|
156
166
|
*/
|
|
157
167
|
export async function safeSingleTaskWrite(_accessor, taskId, writeFn, cwd, options) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
169
|
+
const opts = { ...DEFAULT_SAFETY, ...options };
|
|
170
|
+
// 1. Validate sequence
|
|
171
|
+
await ensureSequenceValid(cwd, opts);
|
|
172
|
+
// 2. Perform targeted write
|
|
173
|
+
await writeFn();
|
|
174
|
+
stats.writes++;
|
|
175
|
+
// 3. Checkpoint (lightweight — no full-file verify)
|
|
176
|
+
await checkpoint(`single-task ${taskId}`, cwd, opts);
|
|
177
|
+
});
|
|
166
178
|
}
|
|
167
179
|
/**
|
|
168
180
|
* Safe wrapper for DataAccessor.appendLog()
|
|
@@ -171,77 +183,83 @@ export async function safeSingleTaskWrite(_accessor, taskId, writeFn, cwd, optio
|
|
|
171
183
|
* but we still checkpoint to ensure data is committed.
|
|
172
184
|
*/
|
|
173
185
|
export async function safeAppendLog(accessor, entry, cwd, options) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
186
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
187
|
+
const opts = { ...DEFAULT_SAFETY, ...options, verify: false }; // Logs don't need verification
|
|
188
|
+
await accessor.appendLog(entry);
|
|
189
|
+
stats.writes++;
|
|
190
|
+
await checkpoint('log entry', cwd, opts);
|
|
191
|
+
});
|
|
178
192
|
}
|
|
179
193
|
/**
|
|
180
194
|
* Run comprehensive data integrity check.
|
|
181
195
|
* Validates all data files and sequence consistency.
|
|
182
196
|
*/
|
|
183
197
|
export async function runDataIntegrityCheck(accessor, cwd) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
199
|
+
const errors = [];
|
|
200
|
+
const warnings = [];
|
|
201
|
+
// 1. Check sequence
|
|
202
|
+
try {
|
|
203
|
+
const seqCheck = await checkSequence(cwd);
|
|
204
|
+
if (!seqCheck.valid) {
|
|
205
|
+
errors.push(`Sequence invalid: counter=${seqCheck.counter}, maxId=T${seqCheck.maxIdInData}`);
|
|
206
|
+
// Try to repair
|
|
207
|
+
const repair = await repairSequence(cwd);
|
|
208
|
+
if (repair.repaired) {
|
|
209
|
+
warnings.push(`Auto-repaired sequence: ${repair.oldCounter} -> ${repair.newCounter}`);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
errors.push('Sequence auto-repair failed');
|
|
213
|
+
}
|
|
195
214
|
}
|
|
196
|
-
|
|
197
|
-
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
errors.push(`Sequence check failed: ${String(err)}`);
|
|
218
|
+
}
|
|
219
|
+
// 2. Verify task data can be queried
|
|
220
|
+
try {
|
|
221
|
+
const count = await accessor.countTasks();
|
|
222
|
+
if (count < 0) {
|
|
223
|
+
errors.push('Task count returned negative value');
|
|
198
224
|
}
|
|
199
225
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
errors.push(`Sequence check failed: ${String(err)}`);
|
|
203
|
-
}
|
|
204
|
-
// 2. Verify task data can be queried
|
|
205
|
-
try {
|
|
206
|
-
const count = await accessor.countTasks();
|
|
207
|
-
if (count < 0) {
|
|
208
|
-
errors.push('Task count returned negative value');
|
|
226
|
+
catch (err) {
|
|
227
|
+
errors.push(`Task data query failed: ${String(err)}`);
|
|
209
228
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const sessions = await accessor.loadSessions();
|
|
216
|
-
if (!Array.isArray(sessions)) {
|
|
217
|
-
errors.push('Sessions data is not an array');
|
|
229
|
+
try {
|
|
230
|
+
const sessions = await accessor.loadSessions();
|
|
231
|
+
if (!Array.isArray(sessions)) {
|
|
232
|
+
errors.push('Sessions data is not an array');
|
|
233
|
+
}
|
|
218
234
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
errors.push(`Sessions load failed: ${String(err)}`);
|
|
222
|
-
}
|
|
223
|
-
// 3. Check for checkpoint recency
|
|
224
|
-
if (stats.lastCheckpoint) {
|
|
225
|
-
const minutesSinceCheckpoint = (Date.now() - stats.lastCheckpoint.getTime()) / 60000;
|
|
226
|
-
if (minutesSinceCheckpoint > 60) {
|
|
227
|
-
warnings.push(`Last checkpoint was ${Math.round(minutesSinceCheckpoint)} minutes ago`);
|
|
235
|
+
catch (err) {
|
|
236
|
+
errors.push(`Sessions load failed: ${String(err)}`);
|
|
228
237
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
238
|
+
// 3. Check for checkpoint recency
|
|
239
|
+
if (stats.lastCheckpoint) {
|
|
240
|
+
const minutesSinceCheckpoint = (Date.now() - stats.lastCheckpoint.getTime()) / 60000;
|
|
241
|
+
if (minutesSinceCheckpoint > 60) {
|
|
242
|
+
warnings.push(`Last checkpoint was ${Math.round(minutesSinceCheckpoint)} minutes ago`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
passed: errors.length === 0,
|
|
247
|
+
errors,
|
|
248
|
+
warnings,
|
|
249
|
+
stats: getSafetyStats(),
|
|
250
|
+
};
|
|
251
|
+
});
|
|
236
252
|
}
|
|
237
253
|
/**
|
|
238
254
|
* Force immediate checkpoint.
|
|
239
255
|
* Use before destructive operations.
|
|
240
256
|
*/
|
|
241
257
|
export async function forceSafetyCheckpoint(context, cwd) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
258
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
259
|
+
log.info({ context }, 'Forcing checkpoint');
|
|
260
|
+
await gitCheckpoint('manual', context, cwd);
|
|
261
|
+
vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
|
|
262
|
+
});
|
|
245
263
|
}
|
|
246
264
|
/**
|
|
247
265
|
* Disable all safety for current process.
|
|
@@ -292,202 +310,222 @@ export class SafetyError extends Error {
|
|
|
292
310
|
* @throws SafetyError if task exists and strict mode is enabled
|
|
293
311
|
*/
|
|
294
312
|
export async function checkTaskExists(taskId, cwd, config = {}) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
313
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
314
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
315
|
+
if (!cfg.detectCollisions)
|
|
316
|
+
return false;
|
|
317
|
+
const db = await getDb(cwd);
|
|
318
|
+
const existing = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
|
|
319
|
+
const exists = existing.length > 0;
|
|
320
|
+
if (exists && cfg.strictMode) {
|
|
321
|
+
throw new SafetyError(`Task ID collision detected: ${taskId} already exists`, 'COLLISION_DETECTED', { taskId, existingTask: existing[0] });
|
|
322
|
+
}
|
|
323
|
+
return exists;
|
|
324
|
+
});
|
|
305
325
|
}
|
|
306
326
|
/**
|
|
307
327
|
* Verify a task was actually written to the database.
|
|
308
328
|
* @throws SafetyError if verification fails
|
|
309
329
|
*/
|
|
310
330
|
export async function verifyTaskWrite(taskId, expectedData, cwd, config = {}) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
|
|
331
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
332
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
333
|
+
if (!cfg.verifyWrites)
|
|
334
|
+
return true;
|
|
335
|
+
const db = await getDb(cwd);
|
|
336
|
+
const rows = await db.select().from(schema.tasks).where(eq(schema.tasks.id, taskId)).all();
|
|
337
|
+
if (rows.length === 0) {
|
|
338
|
+
if (cfg.strictMode) {
|
|
339
|
+
throw new SafetyError(`Write verification failed: Task ${taskId} not found after write`, 'WRITE_VERIFICATION_FAILED', { taskId });
|
|
340
|
+
}
|
|
341
|
+
return false;
|
|
319
342
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
343
|
+
// Verify expected data if provided
|
|
344
|
+
if (expectedData) {
|
|
345
|
+
const row = rows[0];
|
|
346
|
+
for (const [key, value] of Object.entries(expectedData)) {
|
|
347
|
+
if (value !== undefined && row[key] !== value) {
|
|
348
|
+
if (cfg.strictMode) {
|
|
349
|
+
throw new SafetyError(`Write verification failed: Task ${taskId} field ${key} mismatch`, 'WRITE_VERIFICATION_MISMATCH', { taskId, field: key, expected: value, actual: row[key] });
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
329
352
|
}
|
|
330
|
-
return false;
|
|
331
353
|
}
|
|
332
354
|
}
|
|
333
|
-
|
|
334
|
-
|
|
355
|
+
return true;
|
|
356
|
+
});
|
|
335
357
|
}
|
|
336
358
|
/**
|
|
337
359
|
* Validate and repair sequence if necessary.
|
|
338
360
|
* @returns true if sequence was valid or successfully repaired
|
|
339
361
|
*/
|
|
340
362
|
export async function validateAndRepairSequence(cwd, config = {}) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
363
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
364
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
365
|
+
if (!cfg.validateSequence)
|
|
366
|
+
return { valid: true, repaired: false };
|
|
367
|
+
try {
|
|
368
|
+
const check = await checkSequence(cwd);
|
|
369
|
+
if (check.valid) {
|
|
370
|
+
return { valid: true, repaired: false };
|
|
371
|
+
}
|
|
372
|
+
// Sequence is behind, repair it
|
|
373
|
+
const repair = await repairSequence(cwd);
|
|
374
|
+
if (repair.repaired) {
|
|
375
|
+
log.warn({ oldCounter: repair.oldCounter, newCounter: repair.newCounter }, 'Sequence repaired');
|
|
376
|
+
return {
|
|
377
|
+
valid: true,
|
|
378
|
+
repaired: true,
|
|
379
|
+
oldCounter: repair.oldCounter,
|
|
380
|
+
newCounter: repair.newCounter,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
// repairSequence returning repaired:false means "already valid, nothing to do"
|
|
347
384
|
return { valid: true, repaired: false };
|
|
348
385
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return {
|
|
354
|
-
valid: true,
|
|
355
|
-
repaired: true,
|
|
356
|
-
oldCounter: repair.oldCounter,
|
|
357
|
-
newCounter: repair.newCounter,
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
// repairSequence returning repaired:false means "already valid, nothing to do"
|
|
361
|
-
return { valid: true, repaired: false };
|
|
362
|
-
}
|
|
363
|
-
catch (err) {
|
|
364
|
-
if (cfg.strictMode) {
|
|
365
|
-
throw new SafetyError(`Sequence validation failed: ${String(err)}`, 'SEQUENCE_VALIDATION_FAILED', { error: String(err) });
|
|
386
|
+
catch (err) {
|
|
387
|
+
if (cfg.strictMode) {
|
|
388
|
+
throw new SafetyError(`Sequence validation failed: ${String(err)}`, 'SEQUENCE_VALIDATION_FAILED', { error: String(err) });
|
|
389
|
+
}
|
|
390
|
+
return { valid: false, repaired: false };
|
|
366
391
|
}
|
|
367
|
-
|
|
368
|
-
}
|
|
392
|
+
});
|
|
369
393
|
}
|
|
370
394
|
/**
|
|
371
395
|
* Trigger auto-checkpoint after a successful task write.
|
|
372
396
|
*/
|
|
373
397
|
export async function triggerCheckpoint(context, cwd, config = {}) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
398
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
399
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
400
|
+
if (!cfg.autoCheckpoint)
|
|
401
|
+
return;
|
|
402
|
+
try {
|
|
403
|
+
await gitCheckpoint('auto', context, cwd);
|
|
404
|
+
}
|
|
405
|
+
catch (err) {
|
|
406
|
+
// Checkpoint failures are non-fatal but should be logged
|
|
407
|
+
log.warn({ err }, 'Checkpoint failed (non-fatal)');
|
|
408
|
+
}
|
|
409
|
+
vacuumIntoBackup({ cwd }).catch(() => { }); // non-fatal SQLite snapshot
|
|
410
|
+
});
|
|
385
411
|
}
|
|
386
412
|
/**
|
|
387
413
|
* Safely create a task with all safety mechanisms.
|
|
388
414
|
* Wraps the actual createTask operation.
|
|
389
415
|
*/
|
|
390
416
|
export async function safeCreateTask(createFn, task, cwd, config = {}) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
417
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
418
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
419
|
+
// 1. Validate sequence before creation
|
|
420
|
+
if (cfg.validateSequence) {
|
|
421
|
+
await validateAndRepairSequence(cwd, config);
|
|
422
|
+
}
|
|
423
|
+
// 2. Check for collisions
|
|
424
|
+
if (cfg.detectCollisions) {
|
|
425
|
+
await checkTaskExists(task.id, cwd, config);
|
|
426
|
+
}
|
|
427
|
+
// 3. Perform the actual creation
|
|
428
|
+
const result = await createFn();
|
|
429
|
+
// 4. Trigger checkpoint
|
|
430
|
+
if (cfg.autoCheckpoint) {
|
|
431
|
+
await triggerCheckpoint(`created ${task.id}`, cwd, config);
|
|
432
|
+
}
|
|
433
|
+
return result;
|
|
434
|
+
});
|
|
407
435
|
}
|
|
408
436
|
/**
|
|
409
437
|
* Safely update a task with all safety mechanisms.
|
|
410
438
|
*/
|
|
411
439
|
export async function safeUpdateTask(updateFn, taskId, _updates, cwd, config = {}) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
440
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
441
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
442
|
+
// 1. Perform the actual update
|
|
443
|
+
const result = await updateFn();
|
|
444
|
+
if (!result)
|
|
445
|
+
return null;
|
|
446
|
+
// 2. Trigger checkpoint
|
|
447
|
+
if (cfg.autoCheckpoint) {
|
|
448
|
+
await triggerCheckpoint(`updated ${taskId}`, cwd, config);
|
|
449
|
+
}
|
|
450
|
+
return result;
|
|
451
|
+
});
|
|
422
452
|
}
|
|
423
453
|
/**
|
|
424
454
|
* Safely delete a task with all safety mechanisms.
|
|
425
455
|
*/
|
|
426
456
|
export async function safeDeleteTask(deleteFn, taskId, cwd, config = {}) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
457
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
458
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
459
|
+
// 1. Perform the actual deletion
|
|
460
|
+
const result = await deleteFn();
|
|
461
|
+
if (!result)
|
|
462
|
+
return false;
|
|
463
|
+
// 2. Trigger checkpoint
|
|
464
|
+
if (cfg.autoCheckpoint) {
|
|
465
|
+
await triggerCheckpoint(`deleted ${taskId}`, cwd, config);
|
|
466
|
+
}
|
|
467
|
+
return result;
|
|
468
|
+
});
|
|
437
469
|
}
|
|
438
470
|
/**
|
|
439
471
|
* Verify a session write landed in the database.
|
|
440
472
|
* @throws SafetyError if verification fails in strict mode
|
|
441
473
|
*/
|
|
442
474
|
export async function verifySessionWrite(sessionId, cwd, config = {}) {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
if (
|
|
454
|
-
|
|
475
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
476
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
477
|
+
if (!cfg.verifyWrites)
|
|
478
|
+
return true;
|
|
479
|
+
const db = await getDb(cwd);
|
|
480
|
+
const rows = await db
|
|
481
|
+
.select()
|
|
482
|
+
.from(schema.sessions)
|
|
483
|
+
.where(eq(schema.sessions.id, sessionId))
|
|
484
|
+
.all();
|
|
485
|
+
if (rows.length === 0) {
|
|
486
|
+
if (cfg.strictMode) {
|
|
487
|
+
throw new SafetyError(`Write verification failed: Session ${sessionId} not found after write`, 'SESSION_WRITE_VERIFICATION_FAILED', { sessionId });
|
|
488
|
+
}
|
|
489
|
+
return false;
|
|
455
490
|
}
|
|
456
|
-
return
|
|
457
|
-
}
|
|
458
|
-
return true;
|
|
491
|
+
return true;
|
|
492
|
+
});
|
|
459
493
|
}
|
|
460
494
|
/**
|
|
461
495
|
* Safely create a session with all safety mechanisms.
|
|
462
496
|
*/
|
|
463
497
|
export async function safeCreateSession(createFn, session, cwd, config = {}) {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
498
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
499
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
500
|
+
// 1. Perform the actual creation
|
|
501
|
+
const result = await createFn();
|
|
502
|
+
// 2. Verify the write
|
|
503
|
+
if (cfg.verifyWrites) {
|
|
504
|
+
await verifySessionWrite(session.id, cwd, config);
|
|
505
|
+
}
|
|
506
|
+
// 3. Trigger checkpoint
|
|
507
|
+
if (cfg.autoCheckpoint) {
|
|
508
|
+
await triggerCheckpoint(`session ${session.id} started`, cwd, config);
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
511
|
+
});
|
|
476
512
|
}
|
|
477
513
|
/**
|
|
478
514
|
* Force a checkpoint before destructive operations.
|
|
479
515
|
* Use this before migrations, bulk updates, etc.
|
|
480
516
|
*/
|
|
481
517
|
export async function forceCheckpointBeforeOperation(operation, cwd) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
518
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
519
|
+
log.info({ operation }, 'Forcing checkpoint before operation');
|
|
520
|
+
try {
|
|
521
|
+
await gitCheckpoint('manual', `pre-${operation}`, cwd);
|
|
522
|
+
}
|
|
523
|
+
catch (err) {
|
|
524
|
+
log.error({ err }, 'Failed to create pre-operation checkpoint');
|
|
525
|
+
// Don't throw - checkpoint failures shouldn't block operations
|
|
526
|
+
}
|
|
527
|
+
vacuumIntoBackup({ cwd, force: true }).catch(() => { }); // non-fatal SQLite snapshot
|
|
528
|
+
});
|
|
491
529
|
}
|
|
492
530
|
/**
|
|
493
531
|
* Run a sequence-focused integrity check keyed only by working directory.
|
|
@@ -497,30 +535,32 @@ export async function forceCheckpointBeforeOperation(operation, cwd) {
|
|
|
497
535
|
* only. Retained for the lightweight `cwd`-only integrity probe.
|
|
498
536
|
*/
|
|
499
537
|
export async function runSequenceIntegrityCheck(cwd) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
538
|
+
return inSafetyScope(cwd, async (cwd) => {
|
|
539
|
+
const issues = [];
|
|
540
|
+
const repairs = [];
|
|
541
|
+
// 1. Check sequence
|
|
542
|
+
try {
|
|
543
|
+
const seqCheck = await checkSequence(cwd);
|
|
544
|
+
if (!seqCheck.valid) {
|
|
545
|
+
issues.push(`Sequence invalid: counter ${seqCheck.counter} < max ID T${seqCheck.maxIdInData}`);
|
|
546
|
+
// Auto-repair
|
|
547
|
+
const repair = await repairSequence(cwd);
|
|
548
|
+
if (repair.repaired) {
|
|
549
|
+
repairs.push(`Sequence repaired: ${repair.oldCounter} -> ${repair.newCounter}`);
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
issues.push('Sequence repair failed');
|
|
553
|
+
}
|
|
514
554
|
}
|
|
515
555
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
};
|
|
556
|
+
catch (err) {
|
|
557
|
+
issues.push(`Sequence check failed: ${String(err)}`);
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
passed: issues.length === repairs.length,
|
|
561
|
+
issues,
|
|
562
|
+
repairs,
|
|
563
|
+
};
|
|
564
|
+
});
|
|
525
565
|
}
|
|
526
566
|
//# sourceMappingURL=data-safety-central.js.map
|