@cleocode/core 2026.10.21 → 2026.10.22
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/STABILITY.md +1 -1
- package/dist/build-provenance.json +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/docs/document-edges.d.ts +38 -0
- package/dist/docs/document-edges.d.ts.map +1 -0
- package/dist/docs/document-edges.js +62 -0
- package/dist/docs/document-edges.js.map +1 -0
- package/dist/docs/projection.d.ts +3 -2
- package/dist/docs/projection.d.ts.map +1 -1
- package/dist/docs/projection.js +33 -36
- package/dist/docs/projection.js.map +1 -1
- package/dist/events/event-bus.d.ts +6 -5
- package/dist/events/event-bus.d.ts.map +1 -1
- package/dist/events/event-bus.js +9 -8
- package/dist/events/event-bus.js.map +1 -1
- package/dist/gateway-client/generated/index.d.ts +2 -2
- package/dist/gateway-client/generated/index.d.ts.map +1 -1
- package/dist/gateway-client/generated/index.js +1 -1
- package/dist/gateway-client/generated/index.js.map +1 -1
- package/dist/gateway-client/generated/namespaces.gen.d.ts +1 -0
- package/dist/gateway-client/generated/namespaces.gen.d.ts.map +1 -1
- package/dist/gateway-client/generated/namespaces.gen.js +2 -1
- package/dist/gateway-client/generated/namespaces.gen.js.map +1 -1
- package/dist/gateway-client/generated/sdk.gen.d.ts +5 -1
- package/dist/gateway-client/generated/sdk.gen.d.ts.map +1 -1
- package/dist/gateway-client/generated/sdk.gen.js +11 -0
- package/dist/gateway-client/generated/sdk.gen.js.map +1 -1
- package/dist/gateway-client/generated/types.gen.d.ts +34 -0
- package/dist/gateway-client/generated/types.gen.d.ts.map +1 -1
- package/dist/git/base-ref.d.ts +81 -0
- package/dist/git/base-ref.d.ts.map +1 -0
- package/dist/git/base-ref.js +135 -0
- package/dist/git/base-ref.js.map +1 -0
- package/dist/git/hooks-install.d.ts +1 -1
- package/dist/git/hooks-install.d.ts.map +1 -1
- package/dist/git/work-tree.d.ts +40 -0
- package/dist/git/work-tree.d.ts.map +1 -1
- package/dist/git/work-tree.js +62 -7
- package/dist/git/work-tree.js.map +1 -1
- package/dist/hooks/handlers/conduit-hooks.d.ts +2 -1
- package/dist/hooks/handlers/conduit-hooks.d.ts.map +1 -1
- package/dist/hooks/handlers/conduit-hooks.js +9 -23
- package/dist/hooks/handlers/conduit-hooks.js.map +1 -1
- package/dist/hooks/handlers/index.d.ts +0 -1
- package/dist/hooks/handlers/index.d.ts.map +1 -1
- package/dist/hooks/handlers/index.js +0 -2
- package/dist/hooks/handlers/index.js.map +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +5 -12
- package/dist/init.js.map +1 -1
- package/dist/internal.d.ts +2 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/lifecycle/index.d.ts +15 -1
- package/dist/lifecycle/index.d.ts.map +1 -1
- package/dist/lifecycle/index.js +12 -6
- package/dist/lifecycle/index.js.map +1 -1
- package/dist/lifecycle/stage-guidance.js +1 -1
- package/dist/lifecycle/stage-guidance.js.map +1 -1
- package/dist/memory/auto-row-quarantine.d.ts +196 -0
- package/dist/memory/auto-row-quarantine.d.ts.map +1 -0
- package/dist/memory/auto-row-quarantine.js +363 -0
- package/dist/memory/auto-row-quarantine.js.map +1 -0
- package/dist/memory/auto-row-rules.d.ts +29 -0
- package/dist/memory/auto-row-rules.d.ts.map +1 -0
- package/dist/memory/auto-row-rules.js +55 -0
- package/dist/memory/auto-row-rules.js.map +1 -0
- package/dist/memory/brain-lifecycle.d.ts.map +1 -1
- package/dist/memory/brain-lifecycle.js +13 -8
- package/dist/memory/brain-lifecycle.js.map +1 -1
- package/dist/memory/brain-search.d.ts +49 -29
- package/dist/memory/brain-search.d.ts.map +1 -1
- package/dist/memory/brain-search.js +159 -156
- package/dist/memory/brain-search.js.map +1 -1
- package/dist/memory/brain-similarity.d.ts +27 -4
- package/dist/memory/brain-similarity.d.ts.map +1 -1
- package/dist/memory/brain-similarity.js +41 -20
- package/dist/memory/brain-similarity.js.map +1 -1
- package/dist/memory/brain-stub-prune.d.ts +13 -0
- package/dist/memory/brain-stub-prune.d.ts.map +1 -1
- package/dist/memory/brain-stub-prune.js +14 -3
- package/dist/memory/brain-stub-prune.js.map +1 -1
- package/dist/memory/brain-writer-handlers.d.ts +3 -7
- package/dist/memory/brain-writer-handlers.d.ts.map +1 -1
- package/dist/memory/brain-writer-handlers.js +5 -20
- package/dist/memory/brain-writer-handlers.js.map +1 -1
- package/dist/memory/brain-writer-thread.d.ts +2 -11
- package/dist/memory/brain-writer-thread.d.ts.map +1 -1
- package/dist/memory/brain-writer-thread.js +20 -78
- package/dist/memory/brain-writer-thread.js.map +1 -1
- package/dist/memory/brain-writer-worker.js +1 -8
- package/dist/memory/brain-writer-worker.js.map +1 -1
- package/dist/memory/dispatch-trace-format.d.ts +13 -14
- package/dist/memory/dispatch-trace-format.d.ts.map +1 -1
- package/dist/memory/dispatch-trace-format.js +13 -14
- package/dist/memory/dispatch-trace-format.js.map +1 -1
- package/dist/memory/eligibility.d.ts +22 -0
- package/dist/memory/eligibility.d.ts.map +1 -1
- package/dist/memory/eligibility.js +36 -0
- package/dist/memory/eligibility.js.map +1 -1
- package/dist/memory/engine-compat.d.ts.map +1 -1
- package/dist/memory/engine-compat.js +11 -1
- package/dist/memory/engine-compat.js.map +1 -1
- package/dist/memory/evidence-graph-links.d.ts +253 -0
- package/dist/memory/evidence-graph-links.d.ts.map +1 -0
- package/dist/memory/evidence-graph-links.js +554 -0
- package/dist/memory/evidence-graph-links.js.map +1 -0
- package/dist/memory/extraction-gate.d.ts +7 -0
- package/dist/memory/extraction-gate.d.ts.map +1 -1
- package/dist/memory/extraction-gate.js +20 -8
- package/dist/memory/extraction-gate.js.map +1 -1
- package/dist/memory/global-brain.d.ts +4 -6
- package/dist/memory/global-brain.d.ts.map +1 -1
- package/dist/memory/global-brain.js +15 -2
- package/dist/memory/global-brain.js.map +1 -1
- package/dist/memory/graph-auto-populate.d.ts +73 -1
- package/dist/memory/graph-auto-populate.d.ts.map +1 -1
- package/dist/memory/graph-auto-populate.js +111 -8
- package/dist/memory/graph-auto-populate.js.map +1 -1
- package/dist/memory/import-from-provider.d.ts +19 -6
- package/dist/memory/import-from-provider.d.ts.map +1 -1
- package/dist/memory/import-from-provider.js +28 -15
- package/dist/memory/import-from-provider.js.map +1 -1
- package/dist/memory/lessons-import.d.ts +175 -0
- package/dist/memory/lessons-import.d.ts.map +1 -0
- package/dist/memory/lessons-import.js +233 -0
- package/dist/memory/lessons-import.js.map +1 -0
- package/dist/memory/lessons.d.ts +67 -0
- package/dist/memory/lessons.d.ts.map +1 -0
- package/dist/memory/lessons.js +121 -0
- package/dist/memory/lessons.js.map +1 -0
- package/dist/memory/memory-bridge.d.ts.map +1 -1
- package/dist/memory/memory-bridge.js +3 -2
- package/dist/memory/memory-bridge.js.map +1 -1
- package/dist/memory/public-api.d.ts.map +1 -1
- package/dist/memory/public-api.js +7 -6
- package/dist/memory/public-api.js.map +1 -1
- package/dist/memory/recall-ranking.d.ts +88 -0
- package/dist/memory/recall-ranking.d.ts.map +1 -0
- package/dist/memory/recall-ranking.js +130 -0
- package/dist/memory/recall-ranking.js.map +1 -0
- package/dist/memory/retrieval/build-retrieval-bundle.js +5 -5
- package/dist/memory/retrieval/build-retrieval-bundle.js.map +1 -1
- package/dist/memory/retrieval/fetch.d.ts +3 -2
- package/dist/memory/retrieval/fetch.d.ts.map +1 -1
- package/dist/memory/retrieval/fetch.js +4 -3
- package/dist/memory/retrieval/fetch.js.map +1 -1
- package/dist/memory/retrieval/observe.d.ts +1 -7
- package/dist/memory/retrieval/observe.d.ts.map +1 -1
- package/dist/memory/retrieval/observe.js +9 -58
- package/dist/memory/retrieval/observe.js.map +1 -1
- package/dist/memory/retrieval/search.d.ts +5 -6
- package/dist/memory/retrieval/search.d.ts.map +1 -1
- package/dist/memory/retrieval/search.js +38 -102
- package/dist/memory/retrieval/search.js.map +1 -1
- package/dist/memory/retrieval/telemetry.d.ts +5 -16
- package/dist/memory/retrieval/telemetry.d.ts.map +1 -1
- package/dist/memory/retrieval/telemetry.js +5 -22
- package/dist/memory/retrieval/telemetry.js.map +1 -1
- package/dist/nexus/analyze-orchestrator.d.ts +15 -0
- package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
- package/dist/nexus/analyze-orchestrator.js +53 -6
- package/dist/nexus/analyze-orchestrator.js.map +1 -1
- package/dist/nexus/brief-map.d.ts +60 -0
- package/dist/nexus/brief-map.d.ts.map +1 -0
- package/dist/nexus/brief-map.js +234 -0
- package/dist/nexus/brief-map.js.map +1 -0
- package/dist/nexus/freshness.d.ts +128 -13
- package/dist/nexus/freshness.d.ts.map +1 -1
- package/dist/nexus/freshness.js +374 -86
- package/dist/nexus/freshness.js.map +1 -1
- package/dist/nexus/graph-manifest.d.ts +47 -0
- package/dist/nexus/graph-manifest.d.ts.map +1 -1
- package/dist/nexus/graph-manifest.js +69 -0
- package/dist/nexus/graph-manifest.js.map +1 -1
- package/dist/nexus/hooks-augment.d.ts.map +1 -1
- package/dist/nexus/hooks-augment.js +7 -3
- package/dist/nexus/hooks-augment.js.map +1 -1
- package/dist/nexus/index-health.d.ts +112 -0
- package/dist/nexus/index-health.d.ts.map +1 -0
- package/dist/nexus/index-health.js +199 -0
- package/dist/nexus/index-health.js.map +1 -0
- package/dist/nexus/living-brain.d.ts.map +1 -1
- package/dist/nexus/living-brain.js +2 -15
- package/dist/nexus/living-brain.js.map +1 -1
- package/dist/nexus/pid-lock.d.ts +50 -0
- package/dist/nexus/pid-lock.d.ts.map +1 -0
- package/dist/nexus/pid-lock.js +135 -0
- package/dist/nexus/pid-lock.js.map +1 -0
- package/dist/nexus/projects-clean.d.ts.map +1 -1
- package/dist/nexus/projects-clean.js +33 -2
- package/dist/nexus/projects-clean.js.map +1 -1
- package/dist/nexus/refresh-child.js +4 -0
- package/dist/nexus/refresh-child.js.map +1 -1
- package/dist/nexus/registry-host.d.ts +70 -0
- package/dist/nexus/registry-host.d.ts.map +1 -0
- package/dist/nexus/registry-host.js +79 -0
- package/dist/nexus/registry-host.js.map +1 -0
- package/dist/nexus/registry.d.ts +37 -0
- package/dist/nexus/registry.d.ts.map +1 -1
- package/dist/nexus/registry.js +49 -1
- package/dist/nexus/registry.js.map +1 -1
- package/dist/nexus/reindex-on-merge.d.ts +94 -0
- package/dist/nexus/reindex-on-merge.d.ts.map +1 -0
- package/dist/nexus/reindex-on-merge.js +192 -0
- package/dist/nexus/reindex-on-merge.js.map +1 -0
- package/dist/orchestrate/handoff-ops.d.ts.map +1 -1
- package/dist/orchestrate/handoff-ops.js +1 -13
- package/dist/orchestrate/handoff-ops.js.map +1 -1
- package/dist/orchestrate/index.d.ts +2 -3
- package/dist/orchestrate/index.d.ts.map +1 -1
- package/dist/orchestrate/index.js +2 -2
- package/dist/orchestrate/index.js.map +1 -1
- package/dist/orchestrate/lifecycle-ops.d.ts +3 -0
- package/dist/orchestrate/lifecycle-ops.d.ts.map +1 -1
- package/dist/orchestrate/lifecycle-ops.js +5 -5
- package/dist/orchestrate/lifecycle-ops.js.map +1 -1
- package/dist/orchestrate/spawn-ops.d.ts +8 -28
- package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
- package/dist/orchestrate/spawn-ops.js +8 -67
- package/dist/orchestrate/spawn-ops.js.map +1 -1
- package/dist/orchestration/lead-rollup.d.ts +7 -0
- package/dist/orchestration/lead-rollup.d.ts.map +1 -1
- package/dist/orchestration/lead-rollup.js.map +1 -1
- package/dist/orchestration/spawn-prompt.d.ts +8 -29
- package/dist/orchestration/spawn-prompt.d.ts.map +1 -1
- package/dist/orchestration/spawn-prompt.js +44 -112
- package/dist/orchestration/spawn-prompt.js.map +1 -1
- package/dist/orchestration/spawn.d.ts +7 -14
- package/dist/orchestration/spawn.d.ts.map +1 -1
- package/dist/orchestration/spawn.js +2 -5
- package/dist/orchestration/spawn.js.map +1 -1
- package/dist/orchestration/wave-topic.d.ts +0 -13
- package/dist/orchestration/wave-topic.d.ts.map +1 -1
- package/dist/orchestration/wave-topic.js +0 -20
- package/dist/orchestration/wave-topic.js.map +1 -1
- package/dist/release/engine-ops.js +2 -2
- package/dist/release/engine-ops.js.map +1 -1
- package/dist/release/github-pr.d.ts +8 -5
- package/dist/release/github-pr.d.ts.map +1 -1
- package/dist/release/github-pr.js +11 -16
- package/dist/release/github-pr.js.map +1 -1
- package/dist/release/plan.d.ts +4 -2
- package/dist/release/plan.d.ts.map +1 -1
- package/dist/release/plan.js +11 -4
- package/dist/release/plan.js.map +1 -1
- package/dist/release/pr-evidence.d.ts +39 -11
- package/dist/release/pr-evidence.d.ts.map +1 -1
- package/dist/release/pr-evidence.js +122 -31
- package/dist/release/pr-evidence.js.map +1 -1
- package/dist/release/reconcile.d.ts +15 -0
- package/dist/release/reconcile.d.ts.map +1 -1
- package/dist/release/reconcile.js +36 -0
- package/dist/release/reconcile.js.map +1 -1
- package/dist/render/brain/index.d.ts +3 -2
- package/dist/render/brain/index.d.ts.map +1 -1
- package/dist/render/brain/index.js +4 -2
- package/dist/render/brain/index.js.map +1 -1
- package/dist/render/brain/migrate-repo-ids.d.ts +19 -0
- package/dist/render/brain/migrate-repo-ids.d.ts.map +1 -0
- package/dist/render/brain/migrate-repo-ids.js +41 -0
- package/dist/render/brain/migrate-repo-ids.js.map +1 -0
- package/dist/render/nexus/graph/index.d.ts.map +1 -1
- package/dist/render/nexus/graph/index.js +10 -1
- package/dist/render/nexus/graph/index.js.map +1 -1
- package/dist/resources/admission-ledger.d.ts +39 -4
- package/dist/resources/admission-ledger.d.ts.map +1 -1
- package/dist/resources/admission-ledger.js +147 -32
- package/dist/resources/admission-ledger.js.map +1 -1
- package/dist/resources/hook-footprint.d.ts +90 -0
- package/dist/resources/hook-footprint.d.ts.map +1 -0
- package/dist/resources/hook-footprint.js +245 -0
- package/dist/resources/hook-footprint.js.map +1 -0
- package/dist/resources/pressure-gate.d.ts +3 -2
- package/dist/resources/pressure-gate.d.ts.map +1 -1
- package/dist/resources/pressure-gate.js +8 -5
- package/dist/resources/pressure-gate.js.map +1 -1
- package/dist/resources/run-admission.d.ts +23 -3
- package/dist/resources/run-admission.d.ts.map +1 -1
- package/dist/resources/run-admission.js +70 -8
- package/dist/resources/run-admission.js.map +1 -1
- package/dist/resources/run-class.d.ts +1 -0
- package/dist/resources/run-class.d.ts.map +1 -1
- package/dist/resources/run-class.js +7 -0
- package/dist/resources/run-class.js.map +1 -1
- package/dist/resources/run-governed.d.ts +13 -1
- package/dist/resources/run-governed.d.ts.map +1 -1
- package/dist/resources/run-governed.js +29 -6
- package/dist/resources/run-governed.js.map +1 -1
- package/dist/resources/top-memory.d.ts +67 -0
- package/dist/resources/top-memory.d.ts.map +1 -0
- package/dist/resources/top-memory.js +143 -0
- package/dist/resources/top-memory.js.map +1 -0
- package/dist/scaffold/global-scaffold.d.ts +6 -1
- package/dist/scaffold/global-scaffold.d.ts.map +1 -1
- package/dist/scaffold/global-scaffold.js +11 -2
- package/dist/scaffold/global-scaffold.js.map +1 -1
- package/dist/scaffold/scaffold-global.d.ts +3 -2
- package/dist/scaffold/scaffold-global.d.ts.map +1 -1
- package/dist/scaffold/scaffold-global.js +3 -2
- package/dist/scaffold/scaffold-global.js.map +1 -1
- package/dist/sentient/ingesters/brain-ingester.d.ts.map +1 -1
- package/dist/sentient/ingesters/brain-ingester.js +2 -1
- package/dist/sentient/ingesters/brain-ingester.js.map +1 -1
- package/dist/session/engine-ops.js +1 -1
- package/dist/session/engine-ops.js.map +1 -1
- package/dist/sessions/briefing.d.ts +26 -0
- package/dist/sessions/briefing.d.ts.map +1 -1
- package/dist/sessions/briefing.js +46 -0
- package/dist/sessions/briefing.js.map +1 -1
- package/dist/sessions/session-end-snapshot.d.ts +1 -1
- package/dist/sessions/session-end-snapshot.js +1 -1
- package/dist/sessions/session-id.d.ts +2 -1
- package/dist/sessions/session-id.d.ts.map +1 -1
- package/dist/sessions/session-id.js +3 -2
- package/dist/sessions/session-id.js.map +1 -1
- package/dist/store/agent-resolver.d.ts +0 -6
- package/dist/store/agent-resolver.d.ts.map +1 -1
- package/dist/store/agent-resolver.js +0 -31
- package/dist/store/agent-resolver.js.map +1 -1
- package/dist/store/memory-accessor.d.ts +45 -2
- package/dist/store/memory-accessor.d.ts.map +1 -1
- package/dist/store/memory-accessor.js +81 -7
- package/dist/store/memory-accessor.js.map +1 -1
- package/dist/store/schema/cleo-shared/brain.d.ts +2 -2
- package/dist/store/schema/memory-schema.d.ts +3 -3
- package/dist/store/schema/memory-schema.d.ts.map +1 -1
- package/dist/store/schema/memory-schema.js +2 -0
- package/dist/store/schema/memory-schema.js.map +1 -1
- package/dist/store/session-store.d.ts +5 -2
- package/dist/store/session-store.d.ts.map +1 -1
- package/dist/store/session-store.js +10 -5
- package/dist/store/session-store.js.map +1 -1
- package/dist/store/sqlite-native.d.ts +5 -4
- package/dist/store/sqlite-native.d.ts.map +1 -1
- package/dist/store/sqlite-native.js +5 -4
- package/dist/store/sqlite-native.js.map +1 -1
- package/dist/store/sync/merge/rules.d.ts.map +1 -1
- package/dist/store/sync/merge/rules.js +4 -3
- package/dist/store/sync/merge/rules.js.map +1 -1
- package/dist/store/validation-schemas.d.ts +1 -0
- package/dist/store/validation-schemas.d.ts.map +1 -1
- package/dist/store/vault-manifest.js +1 -1
- package/dist/store/vault-manifest.js.map +1 -1
- package/dist/system/project-health.d.ts +7 -0
- package/dist/system/project-health.d.ts.map +1 -1
- package/dist/system/project-health.js +13 -0
- package/dist/system/project-health.js.map +1 -1
- package/dist/tasks/add.d.ts.map +1 -1
- package/dist/tasks/add.js +0 -15
- package/dist/tasks/add.js.map +1 -1
- package/dist/tasks/affected-packages.d.ts +26 -11
- package/dist/tasks/affected-packages.d.ts.map +1 -1
- package/dist/tasks/affected-packages.js +54 -17
- package/dist/tasks/affected-packages.js.map +1 -1
- package/dist/tasks/affected-scope.d.ts +24 -0
- package/dist/tasks/affected-scope.d.ts.map +1 -1
- package/dist/tasks/affected-scope.js +57 -0
- package/dist/tasks/affected-scope.js.map +1 -1
- package/dist/tasks/change-set.d.ts +72 -9
- package/dist/tasks/change-set.d.ts.map +1 -1
- package/dist/tasks/change-set.js +227 -20
- package/dist/tasks/change-set.js.map +1 -1
- package/dist/tasks/complete-ci.d.ts.map +1 -1
- package/dist/tasks/complete-ci.js +2 -0
- package/dist/tasks/complete-ci.js.map +1 -1
- package/dist/tasks/complete.d.ts +2 -2
- package/dist/tasks/complete.d.ts.map +1 -1
- package/dist/tasks/complete.js +38 -17
- package/dist/tasks/complete.js.map +1 -1
- package/dist/tasks/done-plan.d.ts.map +1 -1
- package/dist/tasks/done-plan.js +66 -18
- package/dist/tasks/done-plan.js.map +1 -1
- package/dist/tasks/epic-enforcement.d.ts +39 -1
- package/dist/tasks/epic-enforcement.d.ts.map +1 -1
- package/dist/tasks/epic-enforcement.js +46 -2
- package/dist/tasks/epic-enforcement.js.map +1 -1
- package/dist/tasks/evidence.d.ts +74 -22
- package/dist/tasks/evidence.d.ts.map +1 -1
- package/dist/tasks/evidence.js +221 -35
- package/dist/tasks/evidence.js.map +1 -1
- package/dist/tasks/gate-runner.d.ts.map +1 -1
- package/dist/tasks/gate-runner.js +2 -12
- package/dist/tasks/gate-runner.js.map +1 -1
- package/dist/tasks/qa-run-binding.d.ts +2 -0
- package/dist/tasks/qa-run-binding.d.ts.map +1 -1
- package/dist/tasks/qa-run-binding.js +6 -2
- package/dist/tasks/qa-run-binding.js.map +1 -1
- package/dist/tasks/test-run-binding.d.ts +2 -0
- package/dist/tasks/test-run-binding.d.ts.map +1 -1
- package/dist/tasks/test-run-binding.js +8 -3
- package/dist/tasks/test-run-binding.js.map +1 -1
- package/dist/tasks/verification-policy.d.ts +57 -1
- package/dist/tasks/verification-policy.d.ts.map +1 -1
- package/dist/tasks/verification-policy.js +94 -1
- package/dist/tasks/verification-policy.js.map +1 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +2 -15
- package/dist/upgrade.js.map +1 -1
- package/dist/validation/engine-ops.d.ts.map +1 -1
- package/dist/validation/engine-ops.js +39 -19
- package/dist/validation/engine-ops.js.map +1 -1
- package/package.json +13 -13
- package/schemas/config.schema.json +69 -0
- package/templates/CLEO-INJECTION.md +4 -5
- package/templates/CLEO-REFERENCE.md +2 -4
- package/templates/git-hooks/post-merge +25 -0
- package/dist/memory/dispatch-trace.d.ts +0 -44
- package/dist/memory/dispatch-trace.d.ts.map +0 -1
- package/dist/memory/dispatch-trace.js +0 -65
- package/dist/memory/dispatch-trace.js.map +0 -1
- package/dist/memory/retrieval/increment-citation-counts.d.ts +0 -11
- package/dist/memory/retrieval/increment-citation-counts.d.ts.map +0 -1
- package/dist/memory/retrieval/increment-citation-counts.js +0 -43
- package/dist/memory/retrieval/increment-citation-counts.js.map +0 -1
|
@@ -94,6 +94,14 @@ function saveImportHashes(stateFile, hashes) {
|
|
|
94
94
|
// ---------------------------------------------------------------------------
|
|
95
95
|
// Public API
|
|
96
96
|
// ---------------------------------------------------------------------------
|
|
97
|
+
/** Observation type for a provider memory entry (`feedback` entries become learnings). */
|
|
98
|
+
function observeType(entryType) {
|
|
99
|
+
if (entryType === 'project')
|
|
100
|
+
return 'feature';
|
|
101
|
+
if (entryType === 'user')
|
|
102
|
+
return 'change';
|
|
103
|
+
return 'discovery';
|
|
104
|
+
}
|
|
97
105
|
/**
|
|
98
106
|
* Import `*.md` memory files from a provider directory into `brain.db`.
|
|
99
107
|
*
|
|
@@ -146,29 +154,34 @@ export async function importMemoryFiles(opts) {
|
|
|
146
154
|
}
|
|
147
155
|
const entryType = type ?? 'project';
|
|
148
156
|
if (!dryRun) {
|
|
149
|
-
|
|
150
|
-
await dispatch('mutate', 'memory', 'learning.store', {
|
|
157
|
+
const response = entryType === 'feedback'
|
|
158
|
+
? await dispatch('mutate', 'memory', 'learning.store', {
|
|
151
159
|
insight: `[MIGRATED] ${title}: ${fullText}`,
|
|
152
160
|
source: 'manual',
|
|
153
161
|
confidence: 0.8,
|
|
154
162
|
actionable: false,
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
else {
|
|
158
|
-
const observeType = entryType === 'project'
|
|
159
|
-
? 'feature'
|
|
160
|
-
: entryType === 'reference'
|
|
161
|
-
? 'discovery'
|
|
162
|
-
: entryType === 'user'
|
|
163
|
-
? 'change'
|
|
164
|
-
: 'discovery';
|
|
165
|
-
await dispatch('mutate', 'memory', 'observe', {
|
|
163
|
+
})
|
|
164
|
+
: await dispatch('mutate', 'memory', 'observe', {
|
|
166
165
|
text: `[MIGRATED] ${title}: ${fullText}`,
|
|
167
166
|
title: `[MIGRATED] ${title}`,
|
|
168
|
-
type: observeType,
|
|
167
|
+
type: observeType(entryType),
|
|
169
168
|
sourceType: 'manual',
|
|
170
|
-
}
|
|
169
|
+
});
|
|
170
|
+
// T13949: observe refuses a duplicate with E_OBSERVE_NOT_STORED; a merge
|
|
171
|
+
// means the entry is already in BRAIN, so it is skipped, not imported. A
|
|
172
|
+
// deferred or rejected write carries no real id and stays an error.
|
|
173
|
+
if (!response.success &&
|
|
174
|
+
response.error?.code === 'E_OBSERVE_NOT_STORED' &&
|
|
175
|
+
response.error.details?.['gateAction'] === 'merged') {
|
|
176
|
+
importedHashes.add(hash);
|
|
177
|
+
stats.skipped++;
|
|
178
|
+
const existing = response.error.details?.['id'];
|
|
179
|
+
const into = typeof existing === 'string' ? existing : 'an existing entry';
|
|
180
|
+
skippedEntries.push({ file: fileName, reason: `already in BRAIN as ${into}` });
|
|
181
|
+
continue;
|
|
171
182
|
}
|
|
183
|
+
if (!response.success)
|
|
184
|
+
throw new Error(response.error?.message ?? 'Import write failed');
|
|
172
185
|
importedHashes.add(hash);
|
|
173
186
|
}
|
|
174
187
|
stats.imported++;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-from-provider.js","sourceRoot":"","sources":["../../src/memory/import-from-provider.ts"],"names":[],"mappings":"AAAA;;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C,OAAO;oBAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,IAAI,qBAAqB,CAAC,CAAC;gBACzF,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC;YAED,KAAK,CAAC,QAAQ,EAAE,CAAC;YACjB,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QACnE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CAAC,MAAM,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,MAAM;QACN,eAAe;QACf,cAAc;QACd,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time import of a Claude Code memory directory as BRAIN lessons
|
|
3
|
+
* (T13949 part (c), owner decision D11181).
|
|
4
|
+
*
|
|
5
|
+
* A dry run plans every file: which become lessons, which are skipped and why,
|
|
6
|
+
* with the source provenance of each. The plan carries a digest; an apply
|
|
7
|
+
* re-plans the directory and writes only when the digest still matches the
|
|
8
|
+
* approved one, so what is written is exactly what was reviewed. An apply
|
|
9
|
+
* records a receipt (file, sha256, lesson id) before and after writing, and
|
|
10
|
+
* never deletes or edits a source file.
|
|
11
|
+
*
|
|
12
|
+
* Mapping: a `feedback` memory is a process rule and becomes a lesson in the
|
|
13
|
+
* main (global) brain; a `project` memory is a fact about one project and
|
|
14
|
+
* becomes a lesson in that project's brain, so it never reaches other
|
|
15
|
+
* projects' recall or syncs to them. Its frontmatter `description` is the
|
|
16
|
+
* one-line rule (the lesson title) and its body the why. `user` and
|
|
17
|
+
* `reference` memories are not lessons. A memory marked wrong or superseded
|
|
18
|
+
* (its description or first body line starts with PARTLY WRONG, WRONG or
|
|
19
|
+
* SUPERSEDED) and any file the reviewer excludes are skipped. Each lesson's
|
|
20
|
+
* text ends with its provenance line (source file and content hash), so the
|
|
21
|
+
* same file imported twice is deduplicated.
|
|
22
|
+
*
|
|
23
|
+
* Code placed in `packages/core/` per Package-Boundary Check — verified against AGENTS.md.
|
|
24
|
+
*
|
|
25
|
+
* @module memory/lessons-import
|
|
26
|
+
* @task T13949
|
|
27
|
+
*/
|
|
28
|
+
/** Brain a lesson is written to. */
|
|
29
|
+
export type LessonImportScope = 'global' | 'project';
|
|
30
|
+
/** One memory file planned as a lesson. */
|
|
31
|
+
export interface LessonImportCandidate {
|
|
32
|
+
/** File name inside the source directory. */
|
|
33
|
+
file: string;
|
|
34
|
+
/** SHA-256 of the file's bytes. */
|
|
35
|
+
sha256: string;
|
|
36
|
+
/** Frontmatter `name`, when present. */
|
|
37
|
+
name: string | null;
|
|
38
|
+
/** Frontmatter memory type (`feedback` or `project`). */
|
|
39
|
+
memoryType: string;
|
|
40
|
+
/** Brain the lesson is written to: `global` for feedback, `project` for project memories. */
|
|
41
|
+
scope: LessonImportScope;
|
|
42
|
+
/** The one-line rule (lesson title). */
|
|
43
|
+
rule: string;
|
|
44
|
+
/** The why, ending with the provenance line (lesson text). */
|
|
45
|
+
text: string;
|
|
46
|
+
}
|
|
47
|
+
/** A memory file the import leaves out, and why. */
|
|
48
|
+
export interface LessonImportSkip {
|
|
49
|
+
/** File name inside the source directory. */
|
|
50
|
+
file: string;
|
|
51
|
+
/** Why it is not imported. */
|
|
52
|
+
reason: string;
|
|
53
|
+
}
|
|
54
|
+
/** What an import would write. */
|
|
55
|
+
export interface LessonImportPlan {
|
|
56
|
+
/** Absolute source directory. */
|
|
57
|
+
sourceDir: string;
|
|
58
|
+
/** Files that become lessons, sorted by file name. */
|
|
59
|
+
candidates: LessonImportCandidate[];
|
|
60
|
+
/** Files left out, sorted by file name. */
|
|
61
|
+
skipped: LessonImportSkip[];
|
|
62
|
+
/** Digest of the candidate set (file, content hash, scope); an apply must match it. */
|
|
63
|
+
digest: string;
|
|
64
|
+
}
|
|
65
|
+
/** One written lesson in a receipt. */
|
|
66
|
+
export interface LessonImportWrite {
|
|
67
|
+
/** Source file. */
|
|
68
|
+
file: string;
|
|
69
|
+
/** Source content hash. */
|
|
70
|
+
sha256: string;
|
|
71
|
+
/** Brain the lesson was written to. */
|
|
72
|
+
scope: LessonImportScope;
|
|
73
|
+
/** Lesson id in that brain. */
|
|
74
|
+
id: string;
|
|
75
|
+
/** False when the same lesson already existed (the id names that entry). */
|
|
76
|
+
stored: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** Receipt of an applied import. */
|
|
79
|
+
export interface LessonImportReceipt {
|
|
80
|
+
/** Receipt format version. */
|
|
81
|
+
version: 1;
|
|
82
|
+
/** ISO timestamp of the apply. */
|
|
83
|
+
importedAt: string;
|
|
84
|
+
/** `started` before the first write; `complete` after the last. */
|
|
85
|
+
status: 'started' | 'complete';
|
|
86
|
+
/** Absolute source directory. */
|
|
87
|
+
sourceDir: string;
|
|
88
|
+
/** Approved digest. */
|
|
89
|
+
digest: string;
|
|
90
|
+
/** Lessons written (or found already present), in plan order. */
|
|
91
|
+
written: LessonImportWrite[];
|
|
92
|
+
}
|
|
93
|
+
/** An import refused before any write. */
|
|
94
|
+
export declare class LessonImportError extends Error {
|
|
95
|
+
readonly code: 'E_LESSON_IMPORT_SOURCE' | 'E_LESSON_IMPORT_DIGEST_MISMATCH';
|
|
96
|
+
/**
|
|
97
|
+
* @param code - Stable error code.
|
|
98
|
+
* @param message - Human-readable reason.
|
|
99
|
+
*/
|
|
100
|
+
constructor(code: 'E_LESSON_IMPORT_SOURCE' | 'E_LESSON_IMPORT_DIGEST_MISMATCH', message: string);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The Claude Code memory directory of a project: `~/.claude/projects/<root
|
|
104
|
+
* with every path separator replaced by '-'>/memory`.
|
|
105
|
+
*
|
|
106
|
+
* @param projectRoot - Absolute project root.
|
|
107
|
+
* @param home - Home directory (for tests).
|
|
108
|
+
* @returns The directory path; it may not exist.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* defaultLessonImportDir('/Users/me/repo'); // ~/.claude/projects/-Users-me-repo/memory
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function defaultLessonImportDir(projectRoot: string, home?: string): string;
|
|
115
|
+
/**
|
|
116
|
+
* Plan an import: read every `*.md` file except `MEMORY.md` and decide which
|
|
117
|
+
* become lessons, and where. Reads only.
|
|
118
|
+
*
|
|
119
|
+
* @param sourceDir - Memory directory to import.
|
|
120
|
+
* @param options - `exclude`: file names the reviewer dropped; they are skipped
|
|
121
|
+
* before the digest, so the digest pins the final set.
|
|
122
|
+
* @returns The plan with its digest.
|
|
123
|
+
* @throws LessonImportError when the directory does not exist.
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const plan = planLessonImport(defaultLessonImportDir(root), { exclude: ['old.md'] });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function planLessonImport(sourceDir: string, options?: {
|
|
130
|
+
exclude?: readonly string[];
|
|
131
|
+
}): LessonImportPlan;
|
|
132
|
+
/** Writes one lesson to the brain its scope names; injectable for tests. */
|
|
133
|
+
export type LessonWriter = (lesson: {
|
|
134
|
+
text: string;
|
|
135
|
+
title: string;
|
|
136
|
+
scope: LessonImportScope;
|
|
137
|
+
}) => Promise<{
|
|
138
|
+
id: string;
|
|
139
|
+
stored?: boolean;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Apply an approved import: re-plan the directory with the same exclusions,
|
|
143
|
+
* refuse unless the digest still matches, record a receipt, then write each
|
|
144
|
+
* lesson to the main brain (feedback) or the project brain (project).
|
|
145
|
+
*
|
|
146
|
+
* @param projectRoot - Project whose brain receives project lessons.
|
|
147
|
+
* @param sourceDir - Memory directory to import.
|
|
148
|
+
* @param expectDigest - Digest of the approved dry run.
|
|
149
|
+
* @param receiptPath - Where the receipt is written (before the first write).
|
|
150
|
+
* @param options - `exclude` as in the dry run; `write` overrides the brain writers; `now` for tests.
|
|
151
|
+
* @returns The completed receipt.
|
|
152
|
+
* @throws LessonImportError when the directory changed since the approved plan.
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* const receipt = await applyLessonImport(dir, plan.digest, receiptPath);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function applyLessonImport(projectRoot: string, sourceDir: string, expectDigest: string, receiptPath: string, options?: {
|
|
159
|
+
exclude?: readonly string[];
|
|
160
|
+
write?: LessonWriter;
|
|
161
|
+
now?: Date;
|
|
162
|
+
}): Promise<LessonImportReceipt>;
|
|
163
|
+
/**
|
|
164
|
+
* Default receipt path of an applied lessons import.
|
|
165
|
+
*
|
|
166
|
+
* @param projectRoot - Project root.
|
|
167
|
+
* @param importedAt - ISO timestamp of the apply.
|
|
168
|
+
* @returns Absolute path under `.cleo/backups/migrations/`.
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* defaultLessonImportReceiptPath(root, '2026-10-24T00:00:00.000Z');
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function defaultLessonImportReceiptPath(projectRoot: string, importedAt: string): string;
|
|
175
|
+
//# sourceMappingURL=lessons-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lessons-import.d.ts","sourceRoot":"","sources":["../../src/memory/lessons-import.ts"],"names":[],"mappings":"A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CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAO,GAC9E,OAAO,CAAC,mBAAmB,CAAC,CAgD9B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAQ9F"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time import of a Claude Code memory directory as BRAIN lessons
|
|
3
|
+
* (T13949 part (c), owner decision D11181).
|
|
4
|
+
*
|
|
5
|
+
* A dry run plans every file: which become lessons, which are skipped and why,
|
|
6
|
+
* with the source provenance of each. The plan carries a digest; an apply
|
|
7
|
+
* re-plans the directory and writes only when the digest still matches the
|
|
8
|
+
* approved one, so what is written is exactly what was reviewed. An apply
|
|
9
|
+
* records a receipt (file, sha256, lesson id) before and after writing, and
|
|
10
|
+
* never deletes or edits a source file.
|
|
11
|
+
*
|
|
12
|
+
* Mapping: a `feedback` memory is a process rule and becomes a lesson in the
|
|
13
|
+
* main (global) brain; a `project` memory is a fact about one project and
|
|
14
|
+
* becomes a lesson in that project's brain, so it never reaches other
|
|
15
|
+
* projects' recall or syncs to them. Its frontmatter `description` is the
|
|
16
|
+
* one-line rule (the lesson title) and its body the why. `user` and
|
|
17
|
+
* `reference` memories are not lessons. A memory marked wrong or superseded
|
|
18
|
+
* (its description or first body line starts with PARTLY WRONG, WRONG or
|
|
19
|
+
* SUPERSEDED) and any file the reviewer excludes are skipped. Each lesson's
|
|
20
|
+
* text ends with its provenance line (source file and content hash), so the
|
|
21
|
+
* same file imported twice is deduplicated.
|
|
22
|
+
*
|
|
23
|
+
* Code placed in `packages/core/` per Package-Boundary Check — verified against AGENTS.md.
|
|
24
|
+
*
|
|
25
|
+
* @module memory/lessons-import
|
|
26
|
+
* @task T13949
|
|
27
|
+
*/
|
|
28
|
+
import { createHash } from 'node:crypto';
|
|
29
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
|
|
30
|
+
import { homedir } from 'node:os';
|
|
31
|
+
import { dirname, join } from 'node:path';
|
|
32
|
+
import { writeJsonFileAtomic } from '../store/file-utils.js';
|
|
33
|
+
import { parseMemoryFileFrontmatter } from './import-from-provider.js';
|
|
34
|
+
import { lessonRuleError } from './lessons.js';
|
|
35
|
+
/** Where each memory type lands as a lesson; other types are skipped. */
|
|
36
|
+
const LESSON_SCOPE_BY_TYPE = {
|
|
37
|
+
feedback: 'global',
|
|
38
|
+
project: 'project',
|
|
39
|
+
};
|
|
40
|
+
/** A memory its author marked as no longer true. */
|
|
41
|
+
const RETRACTED = /^(?:partly\s+wrong|wrong|superseded)\b/i;
|
|
42
|
+
/**
|
|
43
|
+
* Source type of imported lessons: agent-written memories, so `agent`
|
|
44
|
+
* confidence in both brains. Each lesson's provenance line names its source
|
|
45
|
+
* file.
|
|
46
|
+
*/
|
|
47
|
+
const LESSON_IMPORT_SOURCE_TYPE = 'agent';
|
|
48
|
+
/** A frontmatter scalar without its surrounding YAML quotes. */
|
|
49
|
+
function unquote(value) {
|
|
50
|
+
const text = value.trim();
|
|
51
|
+
if (text.length >= 2 && text.startsWith('"') && text.endsWith('"'))
|
|
52
|
+
return text.slice(1, -1).replace(/\\(["\\])/g, '$1');
|
|
53
|
+
if (text.length >= 2 && text.startsWith("'") && text.endsWith("'"))
|
|
54
|
+
return text.slice(1, -1).replace(/''/g, "'");
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
/** An import refused before any write. */
|
|
58
|
+
export class LessonImportError extends Error {
|
|
59
|
+
code;
|
|
60
|
+
/**
|
|
61
|
+
* @param code - Stable error code.
|
|
62
|
+
* @param message - Human-readable reason.
|
|
63
|
+
*/
|
|
64
|
+
constructor(code, message) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.code = code;
|
|
67
|
+
this.name = 'LessonImportError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The Claude Code memory directory of a project: `~/.claude/projects/<root
|
|
72
|
+
* with every path separator replaced by '-'>/memory`.
|
|
73
|
+
*
|
|
74
|
+
* @param projectRoot - Absolute project root.
|
|
75
|
+
* @param home - Home directory (for tests).
|
|
76
|
+
* @returns The directory path; it may not exist.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* defaultLessonImportDir('/Users/me/repo'); // ~/.claude/projects/-Users-me-repo/memory
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function defaultLessonImportDir(projectRoot, home = homedir()) {
|
|
83
|
+
return join(home, '.claude', 'projects', projectRoot.replace(/[\\/]/g, '-'), 'memory');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Plan an import: read every `*.md` file except `MEMORY.md` and decide which
|
|
87
|
+
* become lessons, and where. Reads only.
|
|
88
|
+
*
|
|
89
|
+
* @param sourceDir - Memory directory to import.
|
|
90
|
+
* @param options - `exclude`: file names the reviewer dropped; they are skipped
|
|
91
|
+
* before the digest, so the digest pins the final set.
|
|
92
|
+
* @returns The plan with its digest.
|
|
93
|
+
* @throws LessonImportError when the directory does not exist.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const plan = planLessonImport(defaultLessonImportDir(root), { exclude: ['old.md'] });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function planLessonImport(sourceDir, options = {}) {
|
|
100
|
+
const excluded = new Set(options.exclude ?? []);
|
|
101
|
+
if (!existsSync(sourceDir))
|
|
102
|
+
// @sync-invariant none:input-shape a missing source directory is refused before any write
|
|
103
|
+
throw new LessonImportError('E_LESSON_IMPORT_SOURCE', `Source directory not found: ${sourceDir}`);
|
|
104
|
+
const candidates = [];
|
|
105
|
+
const skipped = [];
|
|
106
|
+
const files = readdirSync(sourceDir)
|
|
107
|
+
.filter((file) => file.endsWith('.md') && file !== 'MEMORY.md')
|
|
108
|
+
.sort();
|
|
109
|
+
for (const file of files) {
|
|
110
|
+
if (excluded.has(file)) {
|
|
111
|
+
skipped.push({ file, reason: 'excluded by the reviewer' });
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const bytes = readFileSync(join(sourceDir, file));
|
|
115
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
116
|
+
const { name, description, type, body } = parseMemoryFileFrontmatter(bytes.toString('utf-8'));
|
|
117
|
+
const scope = type ? LESSON_SCOPE_BY_TYPE[type] : undefined;
|
|
118
|
+
if (!type || !scope) {
|
|
119
|
+
skipped.push({ file, reason: `memory type ${type ?? '(none)'} is not a lesson` });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const rule = unquote(description ?? name ?? '');
|
|
123
|
+
const firstLine = body
|
|
124
|
+
.trim()
|
|
125
|
+
.split('\n')[0]
|
|
126
|
+
?.replace(/^[#>*\s-]+/, '') ?? '';
|
|
127
|
+
if (RETRACTED.test(rule) || RETRACTED.test(firstLine)) {
|
|
128
|
+
skipped.push({ file, reason: 'marked wrong or superseded by its author' });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const ruleError = lessonRuleError(rule);
|
|
132
|
+
if (ruleError) {
|
|
133
|
+
skipped.push({ file, reason: `no usable one-line rule: ${ruleError}` });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (!body.trim()) {
|
|
137
|
+
skipped.push({ file, reason: 'empty body (no why)' });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const provenance = `Imported from Claude memory ${file} (sha256 ${sha256.slice(0, 16)}).`;
|
|
141
|
+
candidates.push({
|
|
142
|
+
file,
|
|
143
|
+
sha256,
|
|
144
|
+
name: name ?? null,
|
|
145
|
+
memoryType: type,
|
|
146
|
+
scope,
|
|
147
|
+
rule,
|
|
148
|
+
text: `${body.trim()}\n\n${provenance}`,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
const digest = createHash('sha256')
|
|
152
|
+
.update(candidates.map((c) => `${c.file}\0${c.sha256}\0${c.scope}`).join('\n'))
|
|
153
|
+
.digest('hex')
|
|
154
|
+
.slice(0, 16);
|
|
155
|
+
return { sourceDir, candidates, skipped, digest };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Apply an approved import: re-plan the directory with the same exclusions,
|
|
159
|
+
* refuse unless the digest still matches, record a receipt, then write each
|
|
160
|
+
* lesson to the main brain (feedback) or the project brain (project).
|
|
161
|
+
*
|
|
162
|
+
* @param projectRoot - Project whose brain receives project lessons.
|
|
163
|
+
* @param sourceDir - Memory directory to import.
|
|
164
|
+
* @param expectDigest - Digest of the approved dry run.
|
|
165
|
+
* @param receiptPath - Where the receipt is written (before the first write).
|
|
166
|
+
* @param options - `exclude` as in the dry run; `write` overrides the brain writers; `now` for tests.
|
|
167
|
+
* @returns The completed receipt.
|
|
168
|
+
* @throws LessonImportError when the directory changed since the approved plan.
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const receipt = await applyLessonImport(dir, plan.digest, receiptPath);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export async function applyLessonImport(projectRoot, sourceDir, expectDigest, receiptPath, options = {}) {
|
|
175
|
+
const plan = planLessonImport(sourceDir, { exclude: options.exclude ?? [] });
|
|
176
|
+
if (plan.digest !== expectDigest)
|
|
177
|
+
// @sync-invariant none:input-shape the approved plan no longer holds; nothing is written
|
|
178
|
+
throw new LessonImportError('E_LESSON_IMPORT_DIGEST_MISMATCH', `The memory directory now plans digest ${plan.digest}, not the approved ${expectDigest}; run the dry run again`);
|
|
179
|
+
const write = options.write ??
|
|
180
|
+
(async ({ scope, ...lesson }) => {
|
|
181
|
+
const params = { ...lesson, type: 'lesson', sourceType: LESSON_IMPORT_SOURCE_TYPE };
|
|
182
|
+
if (scope === 'global') {
|
|
183
|
+
const { observeGlobalBrain } = await import('./global-brain.js');
|
|
184
|
+
return observeGlobalBrain(params);
|
|
185
|
+
}
|
|
186
|
+
const { observeBrain } = await import('./retrieval/observe.js');
|
|
187
|
+
return observeBrain(projectRoot, params);
|
|
188
|
+
});
|
|
189
|
+
const receipt = {
|
|
190
|
+
version: 1,
|
|
191
|
+
importedAt: (options.now ?? new Date()).toISOString(),
|
|
192
|
+
status: 'started',
|
|
193
|
+
sourceDir: plan.sourceDir,
|
|
194
|
+
digest: plan.digest,
|
|
195
|
+
written: [],
|
|
196
|
+
};
|
|
197
|
+
mkdirSync(dirname(receiptPath), { recursive: true });
|
|
198
|
+
writeJsonFileAtomic(receiptPath, receipt);
|
|
199
|
+
for (const candidate of plan.candidates) {
|
|
200
|
+
const result = await write({
|
|
201
|
+
text: candidate.text,
|
|
202
|
+
title: candidate.rule,
|
|
203
|
+
scope: candidate.scope,
|
|
204
|
+
});
|
|
205
|
+
receipt.written.push({
|
|
206
|
+
file: candidate.file,
|
|
207
|
+
sha256: candidate.sha256,
|
|
208
|
+
scope: candidate.scope,
|
|
209
|
+
id: result.id,
|
|
210
|
+
stored: result.stored !== false,
|
|
211
|
+
});
|
|
212
|
+
// Each write is recorded as it lands, so an interrupted import names every lesson it made.
|
|
213
|
+
writeJsonFileAtomic(receiptPath, receipt);
|
|
214
|
+
}
|
|
215
|
+
const complete = { ...receipt, status: 'complete' };
|
|
216
|
+
writeJsonFileAtomic(receiptPath, complete);
|
|
217
|
+
return complete;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Default receipt path of an applied lessons import.
|
|
221
|
+
*
|
|
222
|
+
* @param projectRoot - Project root.
|
|
223
|
+
* @param importedAt - ISO timestamp of the apply.
|
|
224
|
+
* @returns Absolute path under `.cleo/backups/migrations/`.
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* defaultLessonImportReceiptPath(root, '2026-10-24T00:00:00.000Z');
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export function defaultLessonImportReceiptPath(projectRoot, importedAt) {
|
|
231
|
+
return join(projectRoot, '.cleo', 'backups', 'migrations', `lessons-import-${importedAt.replace(/[:.]/g, '-')}.json`);
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=lessons-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lessons-import.js","sourceRoot":"","sources":["../../src/memory/lessons-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,yEAAyE;AACzE,MAAM,oBAAoB,GAAgD;IACxE,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,SAAS;CACnB,CAAC;AAEF,oDAAoD;AACpD,MAAM,SAAS,GAAG,yCAAyC,CAAC;AAK5D;;;;GAIG;AACH,MAAM,yBAAyB,GAAkD,OAAO,CAAC;AAEzF,gEAAgE;AAChE,SAAS,OAAO,CAAC,KAAa;IAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACvD,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,I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
|
+
* A lesson is an observation of type `lesson`: the title holds the one-line
|
|
6
|
+
* rule and the narrative holds why (the incident). Process lessons default to
|
|
7
|
+
* the global (main) brain so every project and device reads them. The index
|
|
8
|
+
* lists current lessons newest first; an invalidated (superseded) lesson is
|
|
9
|
+
* hidden.
|
|
10
|
+
*
|
|
11
|
+
* Code placed in `packages/core/` per Package-Boundary Check — verified against AGENTS.md.
|
|
12
|
+
*
|
|
13
|
+
* @module memory/lessons
|
|
14
|
+
* @task T13949
|
|
15
|
+
*/
|
|
16
|
+
/** Longest one-line rule a lesson title may hold. */
|
|
17
|
+
export declare const LESSON_RULE_MAX = 200;
|
|
18
|
+
/** Which store a lessons read covers. */
|
|
19
|
+
export type LessonScope = 'project' | 'global' | 'all';
|
|
20
|
+
/** One row of the lessons index. */
|
|
21
|
+
export interface LessonEntry {
|
|
22
|
+
/** Observation id. */
|
|
23
|
+
id: string;
|
|
24
|
+
/** The one-line rule (the observation title). */
|
|
25
|
+
rule: string;
|
|
26
|
+
/** Why: the incident behind the rule (the observation narrative). */
|
|
27
|
+
why: string;
|
|
28
|
+
/** Creation time, SQLite `datetime` shape. */
|
|
29
|
+
createdAt: string;
|
|
30
|
+
/** Store the lesson lives in. */
|
|
31
|
+
scope: 'project' | 'global';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validate the one-line rule of a lesson before it is stored.
|
|
35
|
+
*
|
|
36
|
+
* @param title - The proposed rule; required for a lesson.
|
|
37
|
+
* @returns An error message, or `null` when the rule is acceptable.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* lessonRuleError('Run biome on the exact changed files before push'); // null
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function lessonRuleError(title: string | undefined): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* List current lessons, newest first, from the project brain, the global
|
|
46
|
+
* (main) brain, or both.
|
|
47
|
+
*
|
|
48
|
+
* With scope `all` each store is read on its own: a store that fails is
|
|
49
|
+
* reported to `onStoreError` and the other store's lessons are still listed.
|
|
50
|
+
* When every store fails the call throws one error naming each store's cause,
|
|
51
|
+
* and `onStoreError` is not called.
|
|
52
|
+
*
|
|
53
|
+
* @param projectRoot - Project whose brain is read for `project` / `all`.
|
|
54
|
+
* @param options - `scope` (default `all`), `limit` (default 50) and
|
|
55
|
+
* `onStoreError`, told which store failed under scope `all`.
|
|
56
|
+
* @returns Lessons merged across the requested stores, newest first.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const lessons = await listLessons(root, { scope: 'all', limit: 20 });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function listLessons(projectRoot: string, options?: {
|
|
63
|
+
scope?: LessonScope;
|
|
64
|
+
limit?: number;
|
|
65
|
+
onStoreError?: (scope: 'project' | 'global', error: Error) => void;
|
|
66
|
+
}): Promise<LessonEntry[]>;
|
|
67
|
+
//# sourceMappingURL=lessons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lessons.d.ts","sourceRoot":"","sources":["../../src/memory/lessons.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,qDAAqD;AACrD,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC,yCAAyC;AACzC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEvD,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAOxE;AAoBD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,QAAQ,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC/D,GACL,OAAO,CAAC,WAAW,EAAE,CAAC,CA6CxB"}
|