@cleocode/core 2026.4.7 → 2026.4.11
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/adapters/adapter-registry.js +64 -0
- package/dist/adapters/adapter-registry.js.map +1 -0
- package/dist/adapters/discovery.js +83 -0
- package/dist/adapters/discovery.js.map +1 -0
- package/dist/adapters/index.js +9 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/manager.js +260 -0
- package/dist/adapters/manager.js.map +1 -0
- package/dist/admin/export-tasks.js +171 -0
- package/dist/admin/export-tasks.js.map +1 -0
- package/dist/admin/export.js +103 -0
- package/dist/admin/export.js.map +1 -0
- package/dist/admin/help.js +106 -0
- package/dist/admin/help.js.map +1 -0
- package/dist/admin/import-tasks.js +182 -0
- package/dist/admin/import-tasks.js.map +1 -0
- package/dist/admin/import.js +129 -0
- package/dist/admin/import.js.map +1 -0
- package/dist/admin/index.js +13 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/adrs/find.js +134 -0
- package/dist/adrs/find.js.map +1 -0
- package/dist/adrs/index.js +15 -0
- package/dist/adrs/index.js.map +1 -0
- package/dist/adrs/link-pipeline.js +160 -0
- package/dist/adrs/link-pipeline.js.map +1 -0
- package/dist/adrs/list.js +43 -0
- package/dist/adrs/list.js.map +1 -0
- package/dist/adrs/parse.js +51 -0
- package/dist/adrs/parse.js.map +1 -0
- package/dist/adrs/show.js +22 -0
- package/dist/adrs/show.js.map +1 -0
- package/dist/adrs/sync.js +188 -0
- package/dist/adrs/sync.js.map +1 -0
- package/dist/adrs/types.js +9 -0
- package/dist/adrs/types.js.map +1 -0
- package/dist/adrs/validate.js +57 -0
- package/dist/adrs/validate.js.map +1 -0
- package/dist/agents/agent-registry.js +288 -0
- package/dist/agents/agent-registry.js.map +1 -0
- package/dist/agents/agent-schema.d.ts +2 -2
- package/dist/agents/agent-schema.js +82 -0
- package/dist/agents/agent-schema.js.map +1 -0
- package/dist/agents/capacity.js +116 -0
- package/dist/agents/capacity.js.map +1 -0
- package/dist/agents/execution-learning.js +474 -0
- package/dist/agents/execution-learning.js.map +1 -0
- package/dist/agents/health-monitor.js +217 -0
- package/dist/agents/health-monitor.js.map +1 -0
- package/dist/agents/index.js +29 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/registry.js +314 -0
- package/dist/agents/registry.js.map +1 -0
- package/dist/agents/retry.js +215 -0
- package/dist/agents/retry.js.map +1 -0
- package/dist/audit-prune.js +94 -0
- package/dist/audit-prune.js.map +1 -0
- package/dist/audit.js +68 -0
- package/dist/audit.js.map +1 -0
- package/dist/backfill/index.js +229 -0
- package/dist/backfill/index.js.map +1 -0
- package/dist/bootstrap.js +344 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/caamp/adapter.js +259 -0
- package/dist/caamp/adapter.js.map +1 -0
- package/dist/caamp/capability-check.js +38 -0
- package/dist/caamp/capability-check.js.map +1 -0
- package/dist/caamp/index.js +21 -0
- package/dist/caamp/index.js.map +1 -0
- package/dist/caamp-init.js +16 -0
- package/dist/caamp-init.js.map +1 -0
- package/dist/cleo.js +322 -0
- package/dist/cleo.js.map +1 -0
- package/dist/code/index.js +10 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/outline.js +165 -0
- package/dist/code/outline.js.map +1 -0
- package/dist/code/parser.js +295 -0
- package/dist/code/parser.js.map +1 -0
- package/dist/code/search.js +135 -0
- package/dist/code/search.js.map +1 -0
- package/dist/code/unfold.js +155 -0
- package/dist/code/unfold.js.map +1 -0
- package/dist/codebase-map/analyzers/architecture.js +130 -0
- package/dist/codebase-map/analyzers/architecture.js.map +1 -0
- package/dist/codebase-map/analyzers/concerns.js +122 -0
- package/dist/codebase-map/analyzers/concerns.js.map +1 -0
- package/dist/codebase-map/analyzers/conventions.js +149 -0
- package/dist/codebase-map/analyzers/conventions.js.map +1 -0
- package/dist/codebase-map/analyzers/integrations.js +108 -0
- package/dist/codebase-map/analyzers/integrations.js.map +1 -0
- package/dist/codebase-map/analyzers/stack.js +117 -0
- package/dist/codebase-map/analyzers/stack.js.map +1 -0
- package/dist/codebase-map/analyzers/structure.js +137 -0
- package/dist/codebase-map/analyzers/structure.js.map +1 -0
- package/dist/codebase-map/analyzers/testing.js +118 -0
- package/dist/codebase-map/analyzers/testing.js.map +1 -0
- package/dist/codebase-map/index.js +57 -0
- package/dist/codebase-map/index.js.map +1 -0
- package/dist/codebase-map/store.js +122 -0
- package/dist/codebase-map/store.js.map +1 -0
- package/dist/codebase-map/summary.js +152 -0
- package/dist/codebase-map/summary.js.map +1 -0
- package/dist/compliance/index.js +288 -0
- package/dist/compliance/index.js.map +1 -0
- package/dist/compliance/protocol-enforcement.js +332 -0
- package/dist/compliance/protocol-enforcement.js.map +1 -0
- package/dist/compliance/protocol-rules.js +786 -0
- package/dist/compliance/protocol-rules.js.map +1 -0
- package/dist/compliance/protocol-types.js +79 -0
- package/dist/compliance/protocol-types.js.map +1 -0
- package/dist/compliance/store.js +53 -0
- package/dist/compliance/store.js.map +1 -0
- package/dist/conduit/conduit-client.js +107 -0
- package/dist/conduit/conduit-client.js.map +1 -0
- package/dist/conduit/factory.js +52 -0
- package/dist/conduit/factory.js.map +1 -0
- package/dist/conduit/http-transport.js +155 -0
- package/dist/conduit/http-transport.js.map +1 -0
- package/dist/conduit/index.js +15 -0
- package/dist/conduit/index.js.map +1 -0
- package/dist/conduit/local-transport.js +245 -0
- package/dist/conduit/local-transport.js.map +1 -0
- package/dist/conduit/sse-transport.js +299 -0
- package/dist/conduit/sse-transport.js.map +1 -0
- package/dist/config/build-config.js +29 -0
- package/dist/config/build-config.js.map +1 -0
- package/dist/config.js +401 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -0
- package/dist/context/index.js +137 -0
- package/dist/context/index.js.map +1 -0
- package/dist/crypto/credentials.js +191 -0
- package/dist/crypto/credentials.js.map +1 -0
- package/dist/discovery.js +182 -0
- package/dist/discovery.js.map +1 -0
- package/dist/engine-result.js +12 -0
- package/dist/engine-result.js.map +1 -0
- package/dist/error-catalog.js +404 -0
- package/dist/error-catalog.js.map +1 -0
- package/dist/error-registry.js +393 -0
- package/dist/error-registry.js.map +1 -0
- package/dist/errors.js +167 -0
- package/dist/errors.js.map +1 -0
- package/dist/hooks/handlers/agent-hooks.js +106 -0
- package/dist/hooks/handlers/agent-hooks.js.map +1 -0
- package/dist/hooks/handlers/context-hooks.js +111 -0
- package/dist/hooks/handlers/context-hooks.js.map +1 -0
- package/dist/hooks/handlers/error-hooks.js +52 -0
- package/dist/hooks/handlers/error-hooks.js.map +1 -0
- package/dist/hooks/handlers/file-hooks.js +104 -0
- package/dist/hooks/handlers/file-hooks.js.map +1 -0
- package/dist/hooks/handlers/handler-helpers.js +61 -0
- package/dist/hooks/handlers/handler-helpers.js.map +1 -0
- package/dist/hooks/handlers/index.js +28 -0
- package/dist/hooks/handlers/index.js.map +1 -0
- package/dist/hooks/handlers/memory-bridge-refresh.js +42 -0
- package/dist/hooks/handlers/memory-bridge-refresh.js.map +1 -0
- package/dist/hooks/handlers/notification-hooks.js +62 -0
- package/dist/hooks/handlers/notification-hooks.js.map +1 -0
- package/dist/hooks/handlers/session-hooks.d.ts +21 -0
- package/dist/hooks/handlers/session-hooks.d.ts.map +1 -1
- package/dist/hooks/handlers/session-hooks.js +142 -0
- package/dist/hooks/handlers/session-hooks.js.map +1 -0
- package/dist/hooks/handlers/task-hooks.js +65 -0
- package/dist/hooks/handlers/task-hooks.js.map +1 -0
- package/dist/hooks/handlers/work-capture-hooks.js +165 -0
- package/dist/hooks/handlers/work-capture-hooks.js.map +1 -0
- package/dist/hooks/index.js +13 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/payload-schemas.d.ts +2 -2
- package/dist/hooks/payload-schemas.js +220 -0
- package/dist/hooks/payload-schemas.js.map +1 -0
- package/dist/hooks/provider-hooks.js +66 -0
- package/dist/hooks/provider-hooks.js.map +1 -0
- package/dist/hooks/registry.js +229 -0
- package/dist/hooks/registry.js.map +1 -0
- package/dist/hooks/types.js +66 -0
- package/dist/hooks/types.js.map +1 -0
- package/dist/hooks.js +136 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.js +3361 -3095
- package/dist/index.js.map +4 -4
- package/dist/init.js +852 -0
- package/dist/init.js.map +1 -0
- package/dist/inject/index.js +82 -0
- package/dist/inject/index.js.map +1 -0
- package/dist/injection.js +343 -0
- package/dist/injection.js.map +1 -0
- package/dist/intelligence/adaptive-validation.js +497 -0
- package/dist/intelligence/adaptive-validation.js.map +1 -0
- package/dist/intelligence/impact.js +675 -0
- package/dist/intelligence/impact.js.map +1 -0
- package/dist/intelligence/index.js +22 -0
- package/dist/intelligence/index.js.map +1 -0
- package/dist/intelligence/patterns.js +492 -0
- package/dist/intelligence/patterns.js.map +1 -0
- package/dist/intelligence/prediction.js +499 -0
- package/dist/intelligence/prediction.js.map +1 -0
- package/dist/intelligence/types.js +13 -0
- package/dist/intelligence/types.js.map +1 -0
- package/dist/internal.d.ts +7 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +299 -0
- package/dist/internal.js.map +1 -0
- package/dist/issue/create.js +121 -0
- package/dist/issue/create.js.map +1 -0
- package/dist/issue/diagnostics.js +59 -0
- package/dist/issue/diagnostics.js.map +1 -0
- package/dist/issue/index.js +10 -0
- package/dist/issue/index.js.map +1 -0
- package/dist/issue/template-parser.js +267 -0
- package/dist/issue/template-parser.js.map +1 -0
- package/dist/json-schema-validator.js +76 -0
- package/dist/json-schema-validator.js.map +1 -0
- package/dist/lib/index.js +11 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/retry.js +152 -0
- package/dist/lib/retry.js.map +1 -0
- package/dist/lib/tree-sitter-languages.js +71 -0
- package/dist/lib/tree-sitter-languages.js.map +1 -0
- package/dist/lifecycle/chain-composition.js +152 -0
- package/dist/lifecycle/chain-composition.js.map +1 -0
- package/dist/lifecycle/chain-store.js +246 -0
- package/dist/lifecycle/chain-store.js.map +1 -0
- package/dist/lifecycle/consolidate-rcasd.js +352 -0
- package/dist/lifecycle/consolidate-rcasd.js.map +1 -0
- package/dist/lifecycle/default-chain.js +176 -0
- package/dist/lifecycle/default-chain.js.map +1 -0
- package/dist/lifecycle/evidence.js +180 -0
- package/dist/lifecycle/evidence.js.map +1 -0
- package/dist/lifecycle/frontmatter.js +363 -0
- package/dist/lifecycle/frontmatter.js.map +1 -0
- package/dist/lifecycle/index.js +756 -0
- package/dist/lifecycle/index.js.map +1 -0
- package/dist/lifecycle/pipeline.js +656 -0
- package/dist/lifecycle/pipeline.js.map +1 -0
- package/dist/lifecycle/rcasd-index.js +326 -0
- package/dist/lifecycle/rcasd-index.js.map +1 -0
- package/dist/lifecycle/rcasd-paths.js +220 -0
- package/dist/lifecycle/rcasd-paths.js.map +1 -0
- package/dist/lifecycle/resume.js +864 -0
- package/dist/lifecycle/resume.js.map +1 -0
- package/dist/lifecycle/stage-artifacts.js +94 -0
- package/dist/lifecycle/stage-artifacts.js.map +1 -0
- package/dist/lifecycle/stage-guidance.js +234 -0
- package/dist/lifecycle/stage-guidance.js.map +1 -0
- package/dist/lifecycle/stages.js +534 -0
- package/dist/lifecycle/stages.js.map +1 -0
- package/dist/lifecycle/state-machine.js +516 -0
- package/dist/lifecycle/state-machine.js.map +1 -0
- package/dist/lifecycle/tessera-engine.js +249 -0
- package/dist/lifecycle/tessera-engine.js.map +1 -0
- package/dist/logger.js +140 -0
- package/dist/logger.js.map +1 -0
- package/dist/memory/auto-extract.js +177 -0
- package/dist/memory/auto-extract.js.map +1 -0
- package/dist/memory/brain-embedding.js +66 -0
- package/dist/memory/brain-embedding.js.map +1 -0
- package/dist/memory/brain-lifecycle.js +298 -0
- package/dist/memory/brain-lifecycle.js.map +1 -0
- package/dist/memory/brain-links.js +161 -0
- package/dist/memory/brain-links.js.map +1 -0
- package/dist/memory/brain-maintenance.js +114 -0
- package/dist/memory/brain-maintenance.js.map +1 -0
- package/dist/memory/brain-migration.js +149 -0
- package/dist/memory/brain-migration.js.map +1 -0
- package/dist/memory/brain-reasoning.js +215 -0
- package/dist/memory/brain-reasoning.js.map +1 -0
- package/dist/memory/brain-retrieval.js +542 -0
- package/dist/memory/brain-retrieval.js.map +1 -0
- package/dist/memory/brain-row-types.js +10 -0
- package/dist/memory/brain-row-types.js.map +1 -0
- package/dist/memory/brain-search.js +519 -0
- package/dist/memory/brain-search.js.map +1 -0
- package/dist/memory/brain-similarity.js +145 -0
- package/dist/memory/brain-similarity.js.map +1 -0
- package/dist/memory/claude-mem-migration.js +277 -0
- package/dist/memory/claude-mem-migration.js.map +1 -0
- package/dist/memory/decisions.js +162 -0
- package/dist/memory/decisions.js.map +1 -0
- package/dist/memory/embedding-local.js +97 -0
- package/dist/memory/embedding-local.js.map +1 -0
- package/dist/memory/embedding-queue.js +271 -0
- package/dist/memory/embedding-queue.js.map +1 -0
- package/dist/memory/embedding-worker.js +58 -0
- package/dist/memory/embedding-worker.js.map +1 -0
- package/dist/memory/engine-compat.js +1397 -0
- package/dist/memory/engine-compat.js.map +1 -0
- package/dist/memory/index.js +1140 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/learnings.d.ts +4 -4
- package/dist/memory/learnings.js +121 -0
- package/dist/memory/learnings.js.map +1 -0
- package/dist/memory/memory-bridge.js +370 -0
- package/dist/memory/memory-bridge.js.map +1 -0
- package/dist/memory/patterns.d.ts +6 -6
- package/dist/memory/patterns.js +122 -0
- package/dist/memory/patterns.js.map +1 -0
- package/dist/memory/pipeline-manifest-sqlite.js +975 -0
- package/dist/memory/pipeline-manifest-sqlite.js.map +1 -0
- package/dist/memory/session-memory.js +331 -0
- package/dist/memory/session-memory.js.map +1 -0
- package/dist/metrics/ab-test.js +260 -0
- package/dist/metrics/ab-test.js.map +1 -0
- package/dist/metrics/aggregation.js +363 -0
- package/dist/metrics/aggregation.js.map +1 -0
- package/dist/metrics/common.js +64 -0
- package/dist/metrics/common.js.map +1 -0
- package/dist/metrics/enums.js +78 -0
- package/dist/metrics/enums.js.map +1 -0
- package/dist/metrics/index.js +19 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/model-provider-registry.js +88 -0
- package/dist/metrics/model-provider-registry.js.map +1 -0
- package/dist/metrics/otel-integration.js +263 -0
- package/dist/metrics/otel-integration.js.map +1 -0
- package/dist/metrics/provider-detection.js +103 -0
- package/dist/metrics/provider-detection.js.map +1 -0
- package/dist/metrics/token-estimation.js +253 -0
- package/dist/metrics/token-estimation.js.map +1 -0
- package/dist/metrics/token-service.js +450 -0
- package/dist/metrics/token-service.js.map +1 -0
- package/dist/migration/agent-outputs.js +316 -0
- package/dist/migration/agent-outputs.js.map +1 -0
- package/dist/migration/checksum.js +92 -0
- package/dist/migration/checksum.js.map +1 -0
- package/dist/migration/index.js +282 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/migration/logger.js +360 -0
- package/dist/migration/logger.js.map +1 -0
- package/dist/migration/preflight.js +9 -0
- package/dist/migration/preflight.js.map +1 -0
- package/dist/migration/state.js +421 -0
- package/dist/migration/state.js.map +1 -0
- package/dist/migration/validate.js +241 -0
- package/dist/migration/validate.js.map +1 -0
- package/dist/mvi-helpers.js +74 -0
- package/dist/mvi-helpers.js.map +1 -0
- package/dist/nexus/deps.js +375 -0
- package/dist/nexus/deps.js.map +1 -0
- package/dist/nexus/discover.js +288 -0
- package/dist/nexus/discover.js.map +1 -0
- package/dist/nexus/hash.js +10 -0
- package/dist/nexus/hash.js.map +1 -0
- package/dist/nexus/index.js +40 -0
- package/dist/nexus/index.js.map +1 -0
- package/dist/nexus/migrate-json-to-sqlite.js +115 -0
- package/dist/nexus/migrate-json-to-sqlite.js.map +1 -0
- package/dist/nexus/permissions.js +105 -0
- package/dist/nexus/permissions.js.map +1 -0
- package/dist/nexus/query.js +175 -0
- package/dist/nexus/query.js.map +1 -0
- package/dist/nexus/registry.js +584 -0
- package/dist/nexus/registry.js.map +1 -0
- package/dist/nexus/sharing/index.js +288 -0
- package/dist/nexus/sharing/index.js.map +1 -0
- package/dist/nexus/transfer-types.js +8 -0
- package/dist/nexus/transfer-types.js.map +1 -0
- package/dist/nexus/transfer.js +263 -0
- package/dist/nexus/transfer.js.map +1 -0
- package/dist/nexus/workspace.js +355 -0
- package/dist/nexus/workspace.js.map +1 -0
- package/dist/observability/index.js +103 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/log-filter.js +63 -0
- package/dist/observability/log-filter.js.map +1 -0
- package/dist/observability/log-parser.js +99 -0
- package/dist/observability/log-parser.js.map +1 -0
- package/dist/observability/log-reader.js +139 -0
- package/dist/observability/log-reader.js.map +1 -0
- package/dist/observability/types.js +19 -0
- package/dist/observability/types.js.map +1 -0
- package/dist/orchestration/analyze.js +107 -0
- package/dist/orchestration/analyze.js.map +1 -0
- package/dist/orchestration/bootstrap.js +132 -0
- package/dist/orchestration/bootstrap.js.map +1 -0
- package/dist/orchestration/context.js +56 -0
- package/dist/orchestration/context.js.map +1 -0
- package/dist/orchestration/critical-path.js +100 -0
- package/dist/orchestration/critical-path.js.map +1 -0
- package/dist/orchestration/hierarchy.js +183 -0
- package/dist/orchestration/hierarchy.js.map +1 -0
- package/dist/orchestration/index.js +287 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/parallel.js +89 -0
- package/dist/orchestration/parallel.js.map +1 -0
- package/dist/orchestration/protocol-validators.js +815 -0
- package/dist/orchestration/protocol-validators.js.map +1 -0
- package/dist/orchestration/skill-ops.js +98 -0
- package/dist/orchestration/skill-ops.js.map +1 -0
- package/dist/orchestration/status.js +107 -0
- package/dist/orchestration/status.js.map +1 -0
- package/dist/orchestration/unblock.js +103 -0
- package/dist/orchestration/unblock.js.map +1 -0
- package/dist/orchestration/validate-spawn.js +67 -0
- package/dist/orchestration/validate-spawn.js.map +1 -0
- package/dist/orchestration/waves.js +86 -0
- package/dist/orchestration/waves.js.map +1 -0
- package/dist/otel/index.js +163 -0
- package/dist/otel/index.js.map +1 -0
- package/dist/output.js +164 -0
- package/dist/output.js.map +1 -0
- package/dist/pagination.js +64 -0
- package/dist/pagination.js.map +1 -0
- package/dist/paths.d.ts +39 -9
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +776 -0
- package/dist/paths.js.map +1 -0
- package/dist/phases/deps.js +372 -0
- package/dist/phases/deps.js.map +1 -0
- package/dist/phases/index.js +349 -0
- package/dist/phases/index.js.map +1 -0
- package/dist/pipeline/index.js +10 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/phase.js +45 -0
- package/dist/pipeline/phase.js.map +1 -0
- package/dist/platform.js +211 -0
- package/dist/platform.js.map +1 -0
- package/dist/project-info.js +84 -0
- package/dist/project-info.js.map +1 -0
- package/dist/reconciliation/index.js +10 -0
- package/dist/reconciliation/index.js.map +1 -0
- package/dist/reconciliation/link-store.js +129 -0
- package/dist/reconciliation/link-store.js.map +1 -0
- package/dist/reconciliation/reconciliation-engine.js +298 -0
- package/dist/reconciliation/reconciliation-engine.js.map +1 -0
- package/dist/release/artifacts.js +427 -0
- package/dist/release/artifacts.js.map +1 -0
- package/dist/release/changelog-writer.js +151 -0
- package/dist/release/changelog-writer.js.map +1 -0
- package/dist/release/channel.js +144 -0
- package/dist/release/channel.js.map +1 -0
- package/dist/release/ci.js +166 -0
- package/dist/release/ci.js.map +1 -0
- package/dist/release/github-pr.js +225 -0
- package/dist/release/github-pr.js.map +1 -0
- package/dist/release/guards.js +116 -0
- package/dist/release/guards.js.map +1 -0
- package/dist/release/index.js +22 -0
- package/dist/release/index.js.map +1 -0
- package/dist/release/release-config.js +158 -0
- package/dist/release/release-config.js.map +1 -0
- package/dist/release/release-manifest.js +1019 -0
- package/dist/release/release-manifest.js.map +1 -0
- package/dist/release/version-bump.js +255 -0
- package/dist/release/version-bump.js.map +1 -0
- package/dist/remote/index.js +257 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/repair.js +130 -0
- package/dist/repair.js.map +1 -0
- package/dist/research/index.js +2 -0
- package/dist/research/index.js.map +1 -0
- package/dist/roadmap/index.js +59 -0
- package/dist/roadmap/index.js.map +1 -0
- package/dist/routing/capability-matrix.js +1556 -0
- package/dist/routing/capability-matrix.js.map +1 -0
- package/dist/routing/index.js +9 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/scaffold.d.ts +15 -2
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +1759 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/schema-management.js +295 -0
- package/dist/schema-management.js.map +1 -0
- package/dist/security/index.js +9 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/input-sanitization.js +321 -0
- package/dist/security/input-sanitization.js.map +1 -0
- package/dist/sequence/index.js +295 -0
- package/dist/sequence/index.js.map +1 -0
- package/dist/sessions/assumptions.js +54 -0
- package/dist/sessions/assumptions.js.map +1 -0
- package/dist/sessions/briefing.js +377 -0
- package/dist/sessions/briefing.js.map +1 -0
- package/dist/sessions/context-alert.js +222 -0
- package/dist/sessions/context-alert.js.map +1 -0
- package/dist/sessions/context-inject.js +61 -0
- package/dist/sessions/context-inject.js.map +1 -0
- package/dist/sessions/context-monitor.js +98 -0
- package/dist/sessions/context-monitor.js.map +1 -0
- package/dist/sessions/decisions.js +65 -0
- package/dist/sessions/decisions.js.map +1 -0
- package/dist/sessions/find.js +65 -0
- package/dist/sessions/find.js.map +1 -0
- package/dist/sessions/handoff.js +328 -0
- package/dist/sessions/handoff.js.map +1 -0
- package/dist/sessions/hitl-warnings.js +254 -0
- package/dist/sessions/hitl-warnings.js.map +1 -0
- package/dist/sessions/index.js +327 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/session-archive.js +40 -0
- package/dist/sessions/session-archive.js.map +1 -0
- package/dist/sessions/session-cleanup.js +59 -0
- package/dist/sessions/session-cleanup.js.map +1 -0
- package/dist/sessions/session-drift.js +134 -0
- package/dist/sessions/session-drift.js.map +1 -0
- package/dist/sessions/session-enforcement.js +144 -0
- package/dist/sessions/session-enforcement.js.map +1 -0
- package/dist/sessions/session-grade.js +253 -0
- package/dist/sessions/session-grade.js.map +1 -0
- package/dist/sessions/session-history.js +42 -0
- package/dist/sessions/session-history.js.map +1 -0
- package/dist/sessions/session-id.js +81 -0
- package/dist/sessions/session-id.js.map +1 -0
- package/dist/sessions/session-memory-bridge.js +52 -0
- package/dist/sessions/session-memory-bridge.js.map +1 -0
- package/dist/sessions/session-show.js +24 -0
- package/dist/sessions/session-show.js.map +1 -0
- package/dist/sessions/session-stats.js +69 -0
- package/dist/sessions/session-stats.js.map +1 -0
- package/dist/sessions/session-suspend.js +39 -0
- package/dist/sessions/session-suspend.js.map +1 -0
- package/dist/sessions/session-switch.js +51 -0
- package/dist/sessions/session-switch.js.map +1 -0
- package/dist/sessions/session-view.js +76 -0
- package/dist/sessions/session-view.js.map +1 -0
- package/dist/sessions/snapshot.js +213 -0
- package/dist/sessions/snapshot.js.map +1 -0
- package/dist/sessions/statusline-setup.js +85 -0
- package/dist/sessions/statusline-setup.js.map +1 -0
- package/dist/sessions/types.js +8 -0
- package/dist/sessions/types.js.map +1 -0
- package/dist/skills/agents/config.js +94 -0
- package/dist/skills/agents/config.js.map +1 -0
- package/dist/skills/agents/install.js +116 -0
- package/dist/skills/agents/install.js.map +1 -0
- package/dist/skills/agents/registry.js +161 -0
- package/dist/skills/agents/registry.js.map +1 -0
- package/dist/skills/discovery.js +333 -0
- package/dist/skills/discovery.js.map +1 -0
- package/dist/skills/dispatch.js +347 -0
- package/dist/skills/dispatch.js.map +1 -0
- package/dist/skills/dynamic-skill-generator.js +87 -0
- package/dist/skills/dynamic-skill-generator.js.map +1 -0
- package/dist/skills/index.js +44 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/injection/subagent.js +195 -0
- package/dist/skills/injection/subagent.js.map +1 -0
- package/dist/skills/injection/token.js +260 -0
- package/dist/skills/injection/token.js.map +1 -0
- package/dist/skills/install.js +40 -0
- package/dist/skills/install.js.map +1 -0
- package/dist/skills/manifests/contribution.js +175 -0
- package/dist/skills/manifests/contribution.js.map +1 -0
- package/dist/skills/manifests/research.js +281 -0
- package/dist/skills/manifests/research.js.map +1 -0
- package/dist/skills/manifests/resolver.js +146 -0
- package/dist/skills/manifests/resolver.js.map +1 -0
- package/dist/skills/marketplace.js +90 -0
- package/dist/skills/marketplace.js.map +1 -0
- package/dist/skills/orchestrator/spawn.js +178 -0
- package/dist/skills/orchestrator/spawn.js.map +1 -0
- package/dist/skills/orchestrator/startup.js +451 -0
- package/dist/skills/orchestrator/startup.js.map +1 -0
- package/dist/skills/orchestrator/validator.js +301 -0
- package/dist/skills/orchestrator/validator.js.map +1 -0
- package/dist/skills/precedence-integration.js +73 -0
- package/dist/skills/precedence-integration.js.map +1 -0
- package/dist/skills/precedence-types.js +16 -0
- package/dist/skills/precedence-types.js.map +1 -0
- package/dist/skills/routing-table.js +63 -0
- package/dist/skills/routing-table.js.map +1 -0
- package/dist/skills/skill-paths.js +217 -0
- package/dist/skills/skill-paths.js.map +1 -0
- package/dist/skills/test-utility.js +55 -0
- package/dist/skills/test-utility.js.map +1 -0
- package/dist/skills/types.js +118 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/skills/validation.js +183 -0
- package/dist/skills/validation.js.map +1 -0
- package/dist/skills/version.js +57 -0
- package/dist/skills/version.js.map +1 -0
- package/dist/snapshot/index.js +188 -0
- package/dist/snapshot/index.js.map +1 -0
- package/dist/spawn/adapter-registry.js +246 -0
- package/dist/spawn/adapter-registry.js.map +1 -0
- package/dist/spawn/index.js +10 -0
- package/dist/spawn/index.js.map +1 -0
- package/dist/stats/index.js +343 -0
- package/dist/stats/index.js.map +1 -0
- package/dist/stats/workflow-telemetry.js +400 -0
- package/dist/stats/workflow-telemetry.js.map +1 -0
- package/dist/sticky/archive.js +47 -0
- package/dist/sticky/archive.js.map +1 -0
- package/dist/sticky/convert.js +235 -0
- package/dist/sticky/convert.js.map +1 -0
- package/dist/sticky/create.js +48 -0
- package/dist/sticky/create.js.map +1 -0
- package/dist/sticky/id.js +35 -0
- package/dist/sticky/id.js.map +1 -0
- package/dist/sticky/index.js +16 -0
- package/dist/sticky/index.js.map +1 -0
- package/dist/sticky/list.js +44 -0
- package/dist/sticky/list.js.map +1 -0
- package/dist/sticky/purge.js +45 -0
- package/dist/sticky/purge.js.map +1 -0
- package/dist/sticky/show.js +42 -0
- package/dist/sticky/show.js.map +1 -0
- package/dist/sticky/types.js +10 -0
- package/dist/sticky/types.js.map +1 -0
- package/dist/store/agent-registry-accessor.js +265 -0
- package/dist/store/agent-registry-accessor.js.map +1 -0
- package/dist/store/atomic.js +167 -0
- package/dist/store/atomic.js.map +1 -0
- package/dist/store/backup.js +94 -0
- package/dist/store/backup.js.map +1 -0
- package/dist/store/brain-accessor.js +397 -0
- package/dist/store/brain-accessor.js.map +1 -0
- package/dist/store/brain-schema.d.ts +8 -8
- package/dist/store/brain-schema.js +215 -0
- package/dist/store/brain-schema.js.map +1 -0
- package/dist/store/brain-sqlite.js +222 -0
- package/dist/store/brain-sqlite.js.map +1 -0
- package/dist/store/cache.js +168 -0
- package/dist/store/cache.js.map +1 -0
- package/dist/store/chain-schema.js +51 -0
- package/dist/store/chain-schema.js.map +1 -0
- package/dist/store/cleanup-legacy.d.ts +128 -0
- package/dist/store/cleanup-legacy.d.ts.map +1 -0
- package/dist/store/converters.js +124 -0
- package/dist/store/converters.js.map +1 -0
- package/dist/store/cross-db-cleanup.js +319 -0
- package/dist/store/cross-db-cleanup.js.map +1 -0
- package/dist/store/data-accessor.js +26 -0
- package/dist/store/data-accessor.js.map +1 -0
- package/dist/store/data-safety-central.js +269 -0
- package/dist/store/data-safety-central.js.map +1 -0
- package/dist/store/data-safety.js +274 -0
- package/dist/store/data-safety.js.map +1 -0
- package/dist/store/db-helpers.js +224 -0
- package/dist/store/db-helpers.js.map +1 -0
- package/dist/store/export.js +155 -0
- package/dist/store/export.js.map +1 -0
- package/dist/store/file-utils.js +270 -0
- package/dist/store/file-utils.js.map +1 -0
- package/dist/store/git-checkpoint.js +365 -0
- package/dist/store/git-checkpoint.js.map +1 -0
- package/dist/store/import-logging.js +139 -0
- package/dist/store/import-logging.js.map +1 -0
- package/dist/store/import-remap.js +145 -0
- package/dist/store/import-remap.js.map +1 -0
- package/dist/store/import-sort.js +121 -0
- package/dist/store/import-sort.js.map +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +29 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/json.js +208 -0
- package/dist/store/json.js.map +1 -0
- package/dist/store/lifecycle-store.js +249 -0
- package/dist/store/lifecycle-store.js.map +1 -0
- package/dist/store/lock.js +70 -0
- package/dist/store/lock.js.map +1 -0
- package/dist/store/migration-manager.js +151 -0
- package/dist/store/migration-manager.js.map +1 -0
- package/dist/store/migration-sqlite.js +676 -0
- package/dist/store/migration-sqlite.js.map +1 -0
- package/dist/store/nexus-schema.js +62 -0
- package/dist/store/nexus-schema.js.map +1 -0
- package/dist/store/nexus-sqlite.d.ts +14 -2
- package/dist/store/nexus-sqlite.d.ts.map +1 -1
- package/dist/store/nexus-sqlite.js +217 -0
- package/dist/store/nexus-sqlite.js.map +1 -0
- package/dist/store/nexus-validation-schemas.js +40 -0
- package/dist/store/nexus-validation-schemas.js.map +1 -0
- package/dist/store/parsers.js +37 -0
- package/dist/store/parsers.js.map +1 -0
- package/dist/store/project-detect.js +457 -0
- package/dist/store/project-detect.js.map +1 -0
- package/dist/store/provider.js +101 -0
- package/dist/store/provider.js.map +1 -0
- package/dist/store/safety-data-accessor.js +257 -0
- package/dist/store/safety-data-accessor.js.map +1 -0
- package/dist/store/schema.js +7 -0
- package/dist/store/schema.js.map +1 -0
- package/dist/store/session-store.js +219 -0
- package/dist/store/session-store.js.map +1 -0
- package/dist/store/signaldock-sqlite.js +400 -0
- package/dist/store/signaldock-sqlite.js.map +1 -0
- package/dist/store/sqlite-backup.d.ts +121 -10
- package/dist/store/sqlite-backup.d.ts.map +1 -1
- package/dist/store/sqlite-backup.js +241 -0
- package/dist/store/sqlite-backup.js.map +1 -0
- package/dist/store/sqlite-data-accessor.js +787 -0
- package/dist/store/sqlite-data-accessor.js.map +1 -0
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +481 -0
- package/dist/store/sqlite.js.map +1 -0
- package/dist/store/status-registry.js +8 -0
- package/dist/store/status-registry.js.map +1 -0
- package/dist/store/task-store.js +358 -0
- package/dist/store/task-store.js.map +1 -0
- package/dist/store/tasks-schema.d.ts +8 -8
- package/dist/store/tasks-schema.js +610 -0
- package/dist/store/tasks-schema.js.map +1 -0
- package/dist/store/typed-query.js +15 -0
- package/dist/store/typed-query.js.map +1 -0
- package/dist/store/validation-schemas.d.ts +37 -37
- package/dist/store/validation-schemas.js +278 -0
- package/dist/store/validation-schemas.js.map +1 -0
- package/dist/system/archive-analytics.js +277 -0
- package/dist/system/archive-analytics.js.map +1 -0
- package/dist/system/archive-stats.js +64 -0
- package/dist/system/archive-stats.js.map +1 -0
- package/dist/system/audit.js +145 -0
- package/dist/system/audit.js.map +1 -0
- package/dist/system/backup.d.ts +91 -3
- package/dist/system/backup.d.ts.map +1 -1
- package/dist/system/backup.js +280 -0
- package/dist/system/backup.js.map +1 -0
- package/dist/system/cleanup.js +134 -0
- package/dist/system/cleanup.js.map +1 -0
- package/dist/system/health.js +1100 -0
- package/dist/system/health.js.map +1 -0
- package/dist/system/index.js +18 -0
- package/dist/system/index.js.map +1 -0
- package/dist/system/inject-generate.js +122 -0
- package/dist/system/inject-generate.js.map +1 -0
- package/dist/system/labels.js +38 -0
- package/dist/system/labels.js.map +1 -0
- package/dist/system/metrics.js +61 -0
- package/dist/system/metrics.js.map +1 -0
- package/dist/system/migrate.js +43 -0
- package/dist/system/migrate.js.map +1 -0
- package/dist/system/platform-paths.js +80 -0
- package/dist/system/platform-paths.js.map +1 -0
- package/dist/system/runtime.js +161 -0
- package/dist/system/runtime.js.map +1 -0
- package/dist/system/safestop.js +99 -0
- package/dist/system/safestop.js.map +1 -0
- package/dist/system/storage-preflight.js +123 -0
- package/dist/system/storage-preflight.js.map +1 -0
- package/dist/task-work/index.js +159 -0
- package/dist/task-work/index.js.map +1 -0
- package/dist/tasks/add.js +661 -0
- package/dist/tasks/add.js.map +1 -0
- package/dist/tasks/analyze.js +85 -0
- package/dist/tasks/analyze.js.map +1 -0
- package/dist/tasks/archive.js +90 -0
- package/dist/tasks/archive.js.map +1 -0
- package/dist/tasks/atomicity.js +83 -0
- package/dist/tasks/atomicity.js.map +1 -0
- package/dist/tasks/cancel-ops.js +83 -0
- package/dist/tasks/cancel-ops.js.map +1 -0
- package/dist/tasks/complete.js +211 -0
- package/dist/tasks/complete.js.map +1 -0
- package/dist/tasks/crossref-extract.js +73 -0
- package/dist/tasks/crossref-extract.js.map +1 -0
- package/dist/tasks/delete-preview.js +192 -0
- package/dist/tasks/delete-preview.js.map +1 -0
- package/dist/tasks/delete.js +120 -0
- package/dist/tasks/delete.js.map +1 -0
- package/dist/tasks/deletion-strategy.js +200 -0
- package/dist/tasks/deletion-strategy.js.map +1 -0
- package/dist/tasks/dependency-check.js +278 -0
- package/dist/tasks/dependency-check.js.map +1 -0
- package/dist/tasks/deps-ready.js +32 -0
- package/dist/tasks/deps-ready.js.map +1 -0
- package/dist/tasks/enforcement.js +86 -0
- package/dist/tasks/enforcement.js.map +1 -0
- package/dist/tasks/epic-enforcement.js +294 -0
- package/dist/tasks/epic-enforcement.js.map +1 -0
- package/dist/tasks/find.js +154 -0
- package/dist/tasks/find.js.map +1 -0
- package/dist/tasks/graph-cache.js +127 -0
- package/dist/tasks/graph-cache.js.map +1 -0
- package/dist/tasks/graph-ops.js +171 -0
- package/dist/tasks/graph-ops.js.map +1 -0
- package/dist/tasks/graph-rag.js +328 -0
- package/dist/tasks/graph-rag.js.map +1 -0
- package/dist/tasks/hierarchy-policy.js +149 -0
- package/dist/tasks/hierarchy-policy.js.map +1 -0
- package/dist/tasks/hierarchy.js +185 -0
- package/dist/tasks/hierarchy.js.map +1 -0
- package/dist/tasks/id-generator.js +65 -0
- package/dist/tasks/id-generator.js.map +1 -0
- package/dist/tasks/index.js +14 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/labels.js +52 -0
- package/dist/tasks/labels.js.map +1 -0
- package/dist/tasks/list.js +75 -0
- package/dist/tasks/list.js.map +1 -0
- package/dist/tasks/phase-tracking.js +133 -0
- package/dist/tasks/phase-tracking.js.map +1 -0
- package/dist/tasks/pipeline-stage.js +248 -0
- package/dist/tasks/pipeline-stage.js.map +1 -0
- package/dist/tasks/plan.js +268 -0
- package/dist/tasks/plan.js.map +1 -0
- package/dist/tasks/relates.js +89 -0
- package/dist/tasks/relates.js.map +1 -0
- package/dist/tasks/show.js +80 -0
- package/dist/tasks/show.js.map +1 -0
- package/dist/tasks/size-weighting.js +86 -0
- package/dist/tasks/size-weighting.js.map +1 -0
- package/dist/tasks/staleness.js +86 -0
- package/dist/tasks/staleness.js.map +1 -0
- package/dist/tasks/task-ops.js +1741 -0
- package/dist/tasks/task-ops.js.map +1 -0
- package/dist/tasks/update.js +277 -0
- package/dist/tasks/update.js.map +1 -0
- package/dist/templates/index.js +10 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/parser.js +254 -0
- package/dist/templates/parser.js.map +1 -0
- package/dist/ui/aliases.js +153 -0
- package/dist/ui/aliases.js.map +1 -0
- package/dist/ui/changelog.js +184 -0
- package/dist/ui/changelog.js.map +1 -0
- package/dist/ui/command-registry.js +168 -0
- package/dist/ui/command-registry.js.map +1 -0
- package/dist/ui/flags.js +94 -0
- package/dist/ui/flags.js.map +1 -0
- package/dist/ui/index.js +24 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/upgrade.js +1148 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/validation/chain-validation.js +146 -0
- package/dist/validation/chain-validation.js.map +1 -0
- package/dist/validation/compliance.js +155 -0
- package/dist/validation/compliance.js.map +1 -0
- package/dist/validation/docs-sync.js +212 -0
- package/dist/validation/docs-sync.js.map +1 -0
- package/dist/validation/doctor/checks.js +1069 -0
- package/dist/validation/doctor/checks.js.map +1 -0
- package/dist/validation/doctor/index.js +9 -0
- package/dist/validation/doctor/index.js.map +1 -0
- package/dist/validation/doctor/project-cache.js +160 -0
- package/dist/validation/doctor/project-cache.js.map +1 -0
- package/dist/validation/doctor/utils.js +155 -0
- package/dist/validation/doctor/utils.js.map +1 -0
- package/dist/validation/engine.js +902 -0
- package/dist/validation/engine.js.map +1 -0
- package/dist/validation/gap-check.js +175 -0
- package/dist/validation/gap-check.js.map +1 -0
- package/dist/validation/index.js +40 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/manifest.js +237 -0
- package/dist/validation/manifest.js.map +1 -0
- package/dist/validation/operation-gate-validators.js +724 -0
- package/dist/validation/operation-gate-validators.js.map +1 -0
- package/dist/validation/operation-verification-gates.js +532 -0
- package/dist/validation/operation-verification-gates.js.map +1 -0
- package/dist/validation/param-utils.js +139 -0
- package/dist/validation/param-utils.js.map +1 -0
- package/dist/validation/protocol-common.js +300 -0
- package/dist/validation/protocol-common.js.map +1 -0
- package/dist/validation/protocols/_shared.js +75 -0
- package/dist/validation/protocols/_shared.js.map +1 -0
- package/dist/validation/protocols/architecture-decision.js +31 -0
- package/dist/validation/protocols/architecture-decision.js.map +1 -0
- package/dist/validation/protocols/artifact-publish.js +28 -0
- package/dist/validation/protocols/artifact-publish.js.map +1 -0
- package/dist/validation/protocols/consensus.js +41 -0
- package/dist/validation/protocols/consensus.js.map +1 -0
- package/dist/validation/protocols/contribution.js +27 -0
- package/dist/validation/protocols/contribution.js.map +1 -0
- package/dist/validation/protocols/decomposition.js +28 -0
- package/dist/validation/protocols/decomposition.js.map +1 -0
- package/dist/validation/protocols/implementation.js +24 -0
- package/dist/validation/protocols/implementation.js.map +1 -0
- package/dist/validation/protocols/provenance.js +29 -0
- package/dist/validation/protocols/provenance.js.map +1 -0
- package/dist/validation/protocols/release.js +29 -0
- package/dist/validation/protocols/release.js.map +1 -0
- package/dist/validation/protocols/research.js +24 -0
- package/dist/validation/protocols/research.js.map +1 -0
- package/dist/validation/protocols/specification.js +27 -0
- package/dist/validation/protocols/specification.js.map +1 -0
- package/dist/validation/protocols/testing.js +30 -0
- package/dist/validation/protocols/testing.js.map +1 -0
- package/dist/validation/protocols/validation.js +30 -0
- package/dist/validation/protocols/validation.js.map +1 -0
- package/dist/validation/schema-integrity.js +170 -0
- package/dist/validation/schema-integrity.js.map +1 -0
- package/dist/validation/schema-validator.js +176 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/dist/validation/validate-ops.js +937 -0
- package/dist/validation/validate-ops.js.map +1 -0
- package/dist/validation/validation-rules.js +226 -0
- package/dist/validation/validation-rules.js.map +1 -0
- package/dist/validation/verification.js +321 -0
- package/dist/validation/verification.js.map +1 -0
- package/package.json +10 -8
- package/src/__tests__/paths-walkup.test.ts +305 -0
- package/src/__tests__/paths.test.ts +61 -17
- package/src/hooks/handlers/session-hooks.ts +42 -0
- package/src/internal.ts +19 -2
- package/src/paths.ts +91 -14
- package/src/scaffold.ts +22 -3
- package/src/store/__tests__/cleanup-legacy.test.ts +268 -0
- package/src/store/__tests__/database-topology-integration.test.ts +504 -0
- package/src/store/__tests__/sqlite-backup-global.test.ts +281 -0
- package/src/store/__tests__/sqlite-backup.test.ts +118 -10
- package/src/store/cleanup-legacy.ts +208 -0
- package/src/store/index.ts +7 -0
- package/src/store/nexus-sqlite.ts +32 -3
- package/src/store/sqlite-backup.ts +368 -37
- package/src/store/sqlite.ts +19 -3
- package/src/system/__tests__/backup.test.ts +237 -0
- package/src/system/backup.ts +248 -28
- package/templates/cleo-gitignore +19 -3
|
@@ -0,0 +1,1397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Engine Compatibility Layer — Brain.db Cognitive Memory
|
|
3
|
+
*
|
|
4
|
+
* Async wrappers around brain.db cognitive memory functions that return
|
|
5
|
+
* EngineResult<T> format for consumption by the dispatch layer.
|
|
6
|
+
*
|
|
7
|
+
* After the memory domain cutover (T5241), this file contains ONLY
|
|
8
|
+
* brain.db-backed operations. Manifest operations moved to
|
|
9
|
+
* pipeline-manifest-compat.ts, and context injection moved to
|
|
10
|
+
* sessions/context-inject.ts.
|
|
11
|
+
*
|
|
12
|
+
* @task T5241
|
|
13
|
+
* @epic T5149
|
|
14
|
+
*/
|
|
15
|
+
import { getProjectRoot } from '../paths.js';
|
|
16
|
+
// BRAIN accessor for direct table queries (T5241)
|
|
17
|
+
import { getBrainAccessor } from '../store/brain-accessor.js';
|
|
18
|
+
import { getAccessor } from '../store/data-accessor.js';
|
|
19
|
+
import { linkMemoryToTask, unlinkMemoryFromTask } from './brain-links.js';
|
|
20
|
+
// BRAIN retrieval imports (T5131-T5135)
|
|
21
|
+
import { fetchBrainEntries, observeBrain, searchBrainCompact, timelineBrain, } from './brain-retrieval.js';
|
|
22
|
+
import { learningStats, searchLearnings, storeLearning, } from './learnings.js';
|
|
23
|
+
// BRAIN memory imports (T4770)
|
|
24
|
+
import { patternStats, searchPatterns, storePattern, } from './patterns.js';
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// Internal helpers
|
|
27
|
+
// ============================================================================
|
|
28
|
+
function resolveRoot(projectRoot) {
|
|
29
|
+
return projectRoot || getProjectRoot();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse brain.db entry ID prefix to determine the table type.
|
|
33
|
+
*
|
|
34
|
+
* Conventions:
|
|
35
|
+
* - D... -> decision (D001, D-xxx)
|
|
36
|
+
* - P... -> pattern (P001, P-xxx)
|
|
37
|
+
* - L... -> learning (L001, L-xxx)
|
|
38
|
+
* - O... or CM-... -> observation (O-xxx, CM-xxx)
|
|
39
|
+
*/
|
|
40
|
+
function parseIdPrefix(id) {
|
|
41
|
+
if (id.startsWith('D-') || /^D\d/.test(id))
|
|
42
|
+
return 'decision';
|
|
43
|
+
if (id.startsWith('P-') || /^P\d/.test(id))
|
|
44
|
+
return 'pattern';
|
|
45
|
+
if (id.startsWith('L-') || /^L\d/.test(id))
|
|
46
|
+
return 'learning';
|
|
47
|
+
if (id.startsWith('O-') || id.startsWith('O') || id.startsWith('CM-'))
|
|
48
|
+
return 'observation';
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
// ============================================================================
|
|
52
|
+
// Brain.db Entry Lookup
|
|
53
|
+
// ============================================================================
|
|
54
|
+
/**
|
|
55
|
+
* Look up a brain.db entry by ID.
|
|
56
|
+
*
|
|
57
|
+
* @param entryId - Brain entry ID with type prefix (D-, P-, L-, O-, or CM-)
|
|
58
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
59
|
+
* @returns EngineResult containing the typed entry data on success
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* Parses the ID prefix to determine the entry type (decision, pattern, learning,
|
|
63
|
+
* or observation) and queries the corresponding brain.db table.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const result = await memoryShow('O-abc123', '/project');
|
|
68
|
+
* if (result.success) console.log(result.data.type, result.data.entry);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export async function memoryShow(entryId, projectRoot) {
|
|
72
|
+
if (!entryId) {
|
|
73
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'entryId is required' } };
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const root = resolveRoot(projectRoot);
|
|
77
|
+
const entryType = parseIdPrefix(entryId);
|
|
78
|
+
if (!entryType) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: {
|
|
82
|
+
code: 'E_INVALID_INPUT',
|
|
83
|
+
message: `Unknown entry ID format: '${entryId}'. Expected prefix D-, P-, L-, or O-`,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const accessor = await getBrainAccessor(root);
|
|
88
|
+
switch (entryType) {
|
|
89
|
+
case 'decision': {
|
|
90
|
+
const row = await accessor.getDecision(entryId);
|
|
91
|
+
if (!row) {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
error: { code: 'E_NOT_FOUND', message: `Decision '${entryId}' not found in brain.db` },
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return { success: true, data: { type: 'decision', entry: row } };
|
|
98
|
+
}
|
|
99
|
+
case 'pattern': {
|
|
100
|
+
const row = await accessor.getPattern(entryId);
|
|
101
|
+
if (!row) {
|
|
102
|
+
return {
|
|
103
|
+
success: false,
|
|
104
|
+
error: { code: 'E_NOT_FOUND', message: `Pattern '${entryId}' not found in brain.db` },
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return { success: true, data: { type: 'pattern', entry: row } };
|
|
108
|
+
}
|
|
109
|
+
case 'learning': {
|
|
110
|
+
const row = await accessor.getLearning(entryId);
|
|
111
|
+
if (!row) {
|
|
112
|
+
return {
|
|
113
|
+
success: false,
|
|
114
|
+
error: { code: 'E_NOT_FOUND', message: `Learning '${entryId}' not found in brain.db` },
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return { success: true, data: { type: 'learning', entry: row } };
|
|
118
|
+
}
|
|
119
|
+
case 'observation': {
|
|
120
|
+
const row = await accessor.getObservation(entryId);
|
|
121
|
+
if (!row) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: {
|
|
125
|
+
code: 'E_NOT_FOUND',
|
|
126
|
+
message: `Observation '${entryId}' not found in brain.db`,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { success: true, data: { type: 'observation', entry: row } };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
error: {
|
|
138
|
+
code: 'E_BRAIN_SHOW',
|
|
139
|
+
message: error instanceof Error ? error.message : String(error),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// ============================================================================
|
|
145
|
+
// Brain.db Aggregate Stats
|
|
146
|
+
// ============================================================================
|
|
147
|
+
/**
|
|
148
|
+
* Aggregate stats from brain.db across all tables.
|
|
149
|
+
*
|
|
150
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
151
|
+
* @returns EngineResult with observation, decision, pattern, and learning counts
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Queries each brain.db table for row counts and returns a combined statistics object.
|
|
155
|
+
* Returns zero counts if brain.db is not initialized.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const result = await memoryBrainStats('/project');
|
|
160
|
+
* if (result.success) console.log(result.data.observations);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export async function memoryBrainStats(projectRoot) {
|
|
164
|
+
try {
|
|
165
|
+
const root = resolveRoot(projectRoot);
|
|
166
|
+
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
167
|
+
await getBrainDb(root);
|
|
168
|
+
const nativeDb = getBrainNativeDb();
|
|
169
|
+
if (!nativeDb) {
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
data: {
|
|
173
|
+
observations: 0,
|
|
174
|
+
decisions: 0,
|
|
175
|
+
patterns: 0,
|
|
176
|
+
learnings: 0,
|
|
177
|
+
total: 0,
|
|
178
|
+
message: 'brain.db not initialized',
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const obsCount = nativeDb.prepare('SELECT COUNT(*) AS cnt FROM brain_observations').get().cnt;
|
|
183
|
+
const decCount = nativeDb.prepare('SELECT COUNT(*) AS cnt FROM brain_decisions').get().cnt;
|
|
184
|
+
const patCount = nativeDb.prepare('SELECT COUNT(*) AS cnt FROM brain_patterns').get().cnt;
|
|
185
|
+
const learnCount = nativeDb.prepare('SELECT COUNT(*) AS cnt FROM brain_learnings').get().cnt;
|
|
186
|
+
return {
|
|
187
|
+
success: true,
|
|
188
|
+
data: {
|
|
189
|
+
observations: obsCount,
|
|
190
|
+
decisions: decCount,
|
|
191
|
+
patterns: patCount,
|
|
192
|
+
learnings: learnCount,
|
|
193
|
+
total: obsCount + decCount + patCount + learnCount,
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: {
|
|
201
|
+
code: 'E_BRAIN_STATS',
|
|
202
|
+
message: error instanceof Error ? error.message : String(error),
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// ============================================================================
|
|
208
|
+
// Brain.db Decision Operations
|
|
209
|
+
// ============================================================================
|
|
210
|
+
/**
|
|
211
|
+
* Search decisions in brain.db.
|
|
212
|
+
*
|
|
213
|
+
* @param params - Search parameters (query, limit, etc.)
|
|
214
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
215
|
+
* @returns EngineResult with matching decision entries
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* Queries the brain.db decisions table with optional text filtering and pagination.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const result = await memoryDecisionFind({ query: 'auth' }, '/project');
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export async function memoryDecisionFind(params, projectRoot) {
|
|
226
|
+
try {
|
|
227
|
+
const root = resolveRoot(projectRoot);
|
|
228
|
+
const accessor = await getBrainAccessor(root);
|
|
229
|
+
if (params.query) {
|
|
230
|
+
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
231
|
+
await getBrainDb(root);
|
|
232
|
+
const nativeDb = getBrainNativeDb();
|
|
233
|
+
if (!nativeDb) {
|
|
234
|
+
return { success: true, data: { decisions: [], total: 0 } };
|
|
235
|
+
}
|
|
236
|
+
const likePattern = `%${params.query}%`;
|
|
237
|
+
const limit = params.limit ?? 20;
|
|
238
|
+
const rows = nativeDb
|
|
239
|
+
.prepare(`
|
|
240
|
+
SELECT * FROM brain_decisions
|
|
241
|
+
WHERE decision LIKE ? OR rationale LIKE ?
|
|
242
|
+
ORDER BY created_at DESC
|
|
243
|
+
LIMIT ?
|
|
244
|
+
`)
|
|
245
|
+
.all(likePattern, likePattern, limit);
|
|
246
|
+
return { success: true, data: { decisions: rows, total: rows.length } };
|
|
247
|
+
}
|
|
248
|
+
const decisions = await accessor.findDecisions({
|
|
249
|
+
contextTaskId: params.taskId,
|
|
250
|
+
limit: params.limit ?? 20,
|
|
251
|
+
});
|
|
252
|
+
return { success: true, data: { decisions, total: decisions.length } };
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: {
|
|
258
|
+
code: 'E_DECISION_FIND',
|
|
259
|
+
message: error instanceof Error ? error.message : String(error),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Store a decision to brain.db.
|
|
266
|
+
*
|
|
267
|
+
* @param params - Decision data including title, rationale, and alternatives
|
|
268
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
269
|
+
* @returns EngineResult with the stored decision ID
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* Creates a new decision entry in brain.db with a D-prefixed ID.
|
|
273
|
+
* Optionally refreshes the memory bridge after storing.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const result = await memoryDecisionStore({ title: 'Use SQLite', rationale: 'Embedded, fast' }, '/project');
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export async function memoryDecisionStore(params, projectRoot) {
|
|
281
|
+
if (!params.decision) {
|
|
282
|
+
return {
|
|
283
|
+
success: false,
|
|
284
|
+
error: { code: 'E_INVALID_INPUT', message: 'decision text is required' },
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
if (!params.rationale) {
|
|
288
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'rationale is required' } };
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
const root = resolveRoot(projectRoot);
|
|
292
|
+
const accessor = await getBrainAccessor(root);
|
|
293
|
+
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
294
|
+
const id = `D-${Date.now().toString(36)}`;
|
|
295
|
+
const row = await accessor.addDecision({
|
|
296
|
+
id,
|
|
297
|
+
type: 'technical',
|
|
298
|
+
decision: params.decision,
|
|
299
|
+
rationale: params.rationale,
|
|
300
|
+
confidence: 'medium',
|
|
301
|
+
outcome: 'pending',
|
|
302
|
+
alternativesJson: params.alternatives ? JSON.stringify(params.alternatives) : null,
|
|
303
|
+
contextTaskId: params.taskId ?? null,
|
|
304
|
+
contextEpicId: null,
|
|
305
|
+
contextPhase: null,
|
|
306
|
+
createdAt: now,
|
|
307
|
+
});
|
|
308
|
+
return {
|
|
309
|
+
success: true,
|
|
310
|
+
data: {
|
|
311
|
+
id: row.id,
|
|
312
|
+
type: row.type,
|
|
313
|
+
decision: row.decision,
|
|
314
|
+
createdAt: row.createdAt,
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
return {
|
|
320
|
+
success: false,
|
|
321
|
+
error: {
|
|
322
|
+
code: 'E_DECISION_STORE',
|
|
323
|
+
message: error instanceof Error ? error.message : String(error),
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// ============================================================================
|
|
329
|
+
// BRAIN Retrieval Operations (T5131-T5135) — Renamed from brain.* to flat ops
|
|
330
|
+
// ============================================================================
|
|
331
|
+
/**
|
|
332
|
+
* Token-efficient brain search returning compact results.
|
|
333
|
+
*
|
|
334
|
+
* @param params - Search parameters including query string and limit
|
|
335
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
336
|
+
* @returns EngineResult with compact search hits (IDs and titles)
|
|
337
|
+
*
|
|
338
|
+
* @remarks
|
|
339
|
+
* Designed for the cheapest-first retrieval pattern. Returns minimal fields
|
|
340
|
+
* per hit to conserve tokens. Use memoryFetch for full entry details.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```typescript
|
|
344
|
+
* const result = await memoryFind({ query: 'authentication', limit: 10 }, '/project');
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
export async function memoryFind(params, projectRoot) {
|
|
348
|
+
try {
|
|
349
|
+
const root = resolveRoot(projectRoot);
|
|
350
|
+
const result = await searchBrainCompact(root, {
|
|
351
|
+
query: params.query,
|
|
352
|
+
limit: params.limit,
|
|
353
|
+
tables: params.tables,
|
|
354
|
+
dateStart: params.dateStart,
|
|
355
|
+
dateEnd: params.dateEnd,
|
|
356
|
+
});
|
|
357
|
+
return { success: true, data: result };
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
return {
|
|
361
|
+
success: false,
|
|
362
|
+
error: {
|
|
363
|
+
code: 'E_BRAIN_SEARCH',
|
|
364
|
+
message: error instanceof Error ? error.message : String(error),
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Chronological context around a brain entry anchor.
|
|
371
|
+
*
|
|
372
|
+
* @param params - Timeline parameters including anchor ID and window size
|
|
373
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
374
|
+
* @returns EngineResult with chronologically ordered entries around the anchor
|
|
375
|
+
*
|
|
376
|
+
* @remarks
|
|
377
|
+
* Retrieves entries before and after a given anchor ID for temporal context.
|
|
378
|
+
* Useful for understanding the sequence of observations and decisions.
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* const result = await memoryTimeline({ anchorId: 'O-abc123', window: 5 }, '/project');
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
385
|
+
export async function memoryTimeline(params, projectRoot) {
|
|
386
|
+
try {
|
|
387
|
+
const root = resolveRoot(projectRoot);
|
|
388
|
+
const result = await timelineBrain(root, {
|
|
389
|
+
anchor: params.anchor,
|
|
390
|
+
depthBefore: params.depthBefore,
|
|
391
|
+
depthAfter: params.depthAfter,
|
|
392
|
+
});
|
|
393
|
+
return { success: true, data: result };
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
return {
|
|
397
|
+
success: false,
|
|
398
|
+
error: {
|
|
399
|
+
code: 'E_BRAIN_TIMELINE',
|
|
400
|
+
message: error instanceof Error ? error.message : String(error),
|
|
401
|
+
},
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Batch fetch brain entries by IDs.
|
|
407
|
+
*
|
|
408
|
+
* @param params - Fetch parameters including an array of entry IDs
|
|
409
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
410
|
+
* @returns EngineResult with full entry details for each requested ID
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* Use after memoryFind to retrieve full details for specific entries.
|
|
414
|
+
* Part of the 3-layer retrieval pattern: search -> filter -> fetch.
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const result = await memoryFetch({ ids: ['O-abc123', 'D-def456'] }, '/project');
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
export async function memoryFetch(params, projectRoot) {
|
|
422
|
+
try {
|
|
423
|
+
const root = resolveRoot(projectRoot);
|
|
424
|
+
const result = await fetchBrainEntries(root, { ids: params.ids });
|
|
425
|
+
return { success: true, data: result };
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
return {
|
|
429
|
+
success: false,
|
|
430
|
+
error: {
|
|
431
|
+
code: 'E_BRAIN_FETCH',
|
|
432
|
+
message: error instanceof Error ? error.message : String(error),
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Save an observation to brain.db.
|
|
439
|
+
*
|
|
440
|
+
* @param params - Observation data including text, title, and optional tags
|
|
441
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
442
|
+
* @returns EngineResult with the stored observation ID
|
|
443
|
+
*
|
|
444
|
+
* @remarks
|
|
445
|
+
* Creates a new observation entry in brain.db with an O-prefixed ID.
|
|
446
|
+
* Optionally refreshes the memory bridge after storing.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```typescript
|
|
450
|
+
* const result = await memoryObserve({ text: 'Auth uses JWT', title: 'Auth discovery' }, '/project');
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
export async function memoryObserve(params, projectRoot) {
|
|
454
|
+
try {
|
|
455
|
+
const root = resolveRoot(projectRoot);
|
|
456
|
+
const result = await observeBrain(root, {
|
|
457
|
+
text: params.text,
|
|
458
|
+
title: params.title,
|
|
459
|
+
type: params.type,
|
|
460
|
+
project: params.project,
|
|
461
|
+
sourceSessionId: params.sourceSessionId,
|
|
462
|
+
sourceType: params.sourceType,
|
|
463
|
+
});
|
|
464
|
+
return { success: true, data: result };
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
return {
|
|
468
|
+
success: false,
|
|
469
|
+
error: {
|
|
470
|
+
code: 'E_BRAIN_OBSERVE',
|
|
471
|
+
message: error instanceof Error ? error.message : String(error),
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
// ============================================================================
|
|
477
|
+
// BRAIN Pattern Operations (T4770)
|
|
478
|
+
// ============================================================================
|
|
479
|
+
/**
|
|
480
|
+
* Store a pattern to BRAIN memory.
|
|
481
|
+
*
|
|
482
|
+
* @param params - Pattern data including pattern string, type, and confidence
|
|
483
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
484
|
+
* @returns EngineResult with the stored pattern ID
|
|
485
|
+
*
|
|
486
|
+
* @remarks
|
|
487
|
+
* Persists a detected pattern (success or failure) to brain.db for future scoring.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* const result = await memoryPatternStore({ pattern: 'migration', type: 'success' }, '/project');
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
export async function memoryPatternStore(params, projectRoot) {
|
|
495
|
+
try {
|
|
496
|
+
const root = resolveRoot(projectRoot);
|
|
497
|
+
const result = await storePattern(root, params);
|
|
498
|
+
return { success: true, data: result };
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
return {
|
|
502
|
+
success: false,
|
|
503
|
+
error: {
|
|
504
|
+
code: 'E_PATTERN_STORE',
|
|
505
|
+
message: error instanceof Error ? error.message : String(error),
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Search patterns in BRAIN memory.
|
|
512
|
+
*
|
|
513
|
+
* @param params - Search parameters including query and type filter
|
|
514
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
515
|
+
* @returns EngineResult with matching pattern entries
|
|
516
|
+
*
|
|
517
|
+
* @remarks
|
|
518
|
+
* Queries the brain.db patterns table with optional type filtering.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```typescript
|
|
522
|
+
* const result = await memoryPatternFind({ type: 'success', limit: 10 }, '/project');
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
export async function memoryPatternFind(params, projectRoot) {
|
|
526
|
+
try {
|
|
527
|
+
const root = resolveRoot(projectRoot);
|
|
528
|
+
const results = await searchPatterns(root, params);
|
|
529
|
+
return { success: true, data: { patterns: results, total: results.length } };
|
|
530
|
+
}
|
|
531
|
+
catch (error) {
|
|
532
|
+
return {
|
|
533
|
+
success: false,
|
|
534
|
+
error: {
|
|
535
|
+
code: 'E_PATTERN_SEARCH',
|
|
536
|
+
message: error instanceof Error ? error.message : String(error),
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Get pattern memory statistics.
|
|
543
|
+
*
|
|
544
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
545
|
+
* @returns EngineResult with pattern counts by type and overall totals
|
|
546
|
+
*
|
|
547
|
+
* @remarks
|
|
548
|
+
* Aggregates pattern data from brain.db to provide type distribution and counts.
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* ```typescript
|
|
552
|
+
* const result = await memoryPatternStats('/project');
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
export async function memoryPatternStats(projectRoot) {
|
|
556
|
+
try {
|
|
557
|
+
const root = resolveRoot(projectRoot);
|
|
558
|
+
const stats = await patternStats(root);
|
|
559
|
+
return { success: true, data: stats };
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
return {
|
|
563
|
+
success: false,
|
|
564
|
+
error: {
|
|
565
|
+
code: 'E_PATTERN_STATS',
|
|
566
|
+
message: error instanceof Error ? error.message : String(error),
|
|
567
|
+
},
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
// ============================================================================
|
|
572
|
+
// BRAIN Learning Operations (T4770)
|
|
573
|
+
// ============================================================================
|
|
574
|
+
/**
|
|
575
|
+
* Store a learning to BRAIN memory.
|
|
576
|
+
*
|
|
577
|
+
* @param params - Learning data including text and confidence level
|
|
578
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
579
|
+
* @returns EngineResult with the stored learning ID
|
|
580
|
+
*
|
|
581
|
+
* @remarks
|
|
582
|
+
* Creates a new learning entry in brain.db with an L-prefixed ID.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* const result = await memoryLearningStore({ text: 'Drizzle v1 requires beta flag' }, '/project');
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
export async function memoryLearningStore(params, projectRoot) {
|
|
590
|
+
try {
|
|
591
|
+
const root = resolveRoot(projectRoot);
|
|
592
|
+
const result = await storeLearning(root, params);
|
|
593
|
+
return { success: true, data: result };
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
return {
|
|
597
|
+
success: false,
|
|
598
|
+
error: {
|
|
599
|
+
code: 'E_LEARNING_STORE',
|
|
600
|
+
message: error instanceof Error ? error.message : String(error),
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Search learnings in BRAIN memory.
|
|
607
|
+
*
|
|
608
|
+
* @param params - Search parameters including query and limit
|
|
609
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
610
|
+
* @returns EngineResult with matching learning entries
|
|
611
|
+
*
|
|
612
|
+
* @remarks
|
|
613
|
+
* Queries the brain.db learnings table with optional text filtering.
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```typescript
|
|
617
|
+
* const result = await memoryLearningFind({ query: 'drizzle' }, '/project');
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
export async function memoryLearningFind(params, projectRoot) {
|
|
621
|
+
try {
|
|
622
|
+
const root = resolveRoot(projectRoot);
|
|
623
|
+
const results = await searchLearnings(root, params);
|
|
624
|
+
return { success: true, data: { learnings: results, total: results.length } };
|
|
625
|
+
}
|
|
626
|
+
catch (error) {
|
|
627
|
+
return {
|
|
628
|
+
success: false,
|
|
629
|
+
error: {
|
|
630
|
+
code: 'E_LEARNING_SEARCH',
|
|
631
|
+
message: error instanceof Error ? error.message : String(error),
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Get learning memory statistics.
|
|
638
|
+
*
|
|
639
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
640
|
+
* @returns EngineResult with learning counts and confidence distribution
|
|
641
|
+
*
|
|
642
|
+
* @remarks
|
|
643
|
+
* Aggregates learning data from brain.db to provide totals and breakdowns.
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* ```typescript
|
|
647
|
+
* const result = await memoryLearningStats('/project');
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
export async function memoryLearningStats(projectRoot) {
|
|
651
|
+
try {
|
|
652
|
+
const root = resolveRoot(projectRoot);
|
|
653
|
+
const stats = await learningStats(root);
|
|
654
|
+
return { success: true, data: stats };
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
return {
|
|
658
|
+
success: false,
|
|
659
|
+
error: {
|
|
660
|
+
code: 'E_LEARNING_STATS',
|
|
661
|
+
message: error instanceof Error ? error.message : String(error),
|
|
662
|
+
},
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
// ============================================================================
|
|
667
|
+
// BRAIN Advanced Queries & Links (T5241)
|
|
668
|
+
// ============================================================================
|
|
669
|
+
/**
|
|
670
|
+
* Find contradictory entries in brain.db.
|
|
671
|
+
*
|
|
672
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
673
|
+
* @returns EngineResult with pairs of contradicting observations
|
|
674
|
+
*
|
|
675
|
+
* @remarks
|
|
676
|
+
* Scans brain.db for observations that contradict each other based on
|
|
677
|
+
* semantic similarity and opposing sentiment or content.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```typescript
|
|
681
|
+
* const result = await memoryContradictions('/project');
|
|
682
|
+
* if (result.success) console.log(result.data.contradictions);
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
export async function memoryContradictions(projectRoot) {
|
|
686
|
+
try {
|
|
687
|
+
const root = resolveRoot(projectRoot);
|
|
688
|
+
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
689
|
+
await getBrainDb(root);
|
|
690
|
+
const nativeDb = getBrainNativeDb();
|
|
691
|
+
if (!nativeDb) {
|
|
692
|
+
return { success: true, data: { contradictions: [] } };
|
|
693
|
+
}
|
|
694
|
+
// Negation patterns for detecting contradictions (adapted from manifest logic)
|
|
695
|
+
const negationPairs = [
|
|
696
|
+
[/\bdoes NOT\b/i, /\bdoes\b(?!.*\bnot\b)/i],
|
|
697
|
+
[/\bcannot\b/i, /\bcan\b(?!.*\bnot\b)/i],
|
|
698
|
+
[/\bno\s+\w+\s+required\b/i, /\brequired\b(?!.*\bno\b)/i],
|
|
699
|
+
[
|
|
700
|
+
/\bnot\s+(?:available|supported|possible|recommended)\b/i,
|
|
701
|
+
/\b(?:available|supported|possible|recommended)\b(?!.*\bnot\b)/i,
|
|
702
|
+
],
|
|
703
|
+
[/\bwithout\b/i, /\brequires?\b/i],
|
|
704
|
+
[/\bavoid\b/i, /\buse\b/i],
|
|
705
|
+
[/\bdeprecated\b/i, /\brecommended\b/i],
|
|
706
|
+
[/\banti-pattern\b/i, /\bbest practice\b/i],
|
|
707
|
+
];
|
|
708
|
+
// Fetch all decisions with context for comparison
|
|
709
|
+
const decisions = nativeDb
|
|
710
|
+
.prepare(`
|
|
711
|
+
SELECT id, type, decision, rationale, context_task_id, created_at
|
|
712
|
+
FROM brain_decisions
|
|
713
|
+
ORDER BY created_at DESC
|
|
714
|
+
`)
|
|
715
|
+
.all();
|
|
716
|
+
// Fetch all patterns
|
|
717
|
+
const patterns = nativeDb
|
|
718
|
+
.prepare(`
|
|
719
|
+
SELECT id, type, pattern, context, anti_pattern, created_at
|
|
720
|
+
FROM brain_patterns
|
|
721
|
+
ORDER BY created_at DESC
|
|
722
|
+
`)
|
|
723
|
+
.all();
|
|
724
|
+
// Fetch all learnings
|
|
725
|
+
const learnings = nativeDb
|
|
726
|
+
.prepare(`
|
|
727
|
+
SELECT id, insight, source, created_at
|
|
728
|
+
FROM brain_learnings
|
|
729
|
+
ORDER BY created_at DESC
|
|
730
|
+
`)
|
|
731
|
+
.all();
|
|
732
|
+
const contradictions = [];
|
|
733
|
+
const seenPairs = new Set();
|
|
734
|
+
// Helper to create sorted pair key
|
|
735
|
+
const pairKey = (idA, idB) => (idA < idB ? `${idA}::${idB}` : `${idB}::${idA}`);
|
|
736
|
+
// Check decisions against each other (grouped by task context)
|
|
737
|
+
const decisionsByTask = new Map();
|
|
738
|
+
for (const d of decisions) {
|
|
739
|
+
const key = d.context_task_id;
|
|
740
|
+
if (!decisionsByTask.has(key))
|
|
741
|
+
decisionsByTask.set(key, []);
|
|
742
|
+
decisionsByTask.get(key).push(d);
|
|
743
|
+
}
|
|
744
|
+
for (const [taskId, taskDecisions] of decisionsByTask) {
|
|
745
|
+
if (taskDecisions.length < 2)
|
|
746
|
+
continue;
|
|
747
|
+
for (let i = 0; i < taskDecisions.length; i++) {
|
|
748
|
+
for (let j = i + 1; j < taskDecisions.length; j++) {
|
|
749
|
+
const a = taskDecisions[i];
|
|
750
|
+
const b = taskDecisions[j];
|
|
751
|
+
const key = pairKey(a.id, b.id);
|
|
752
|
+
if (seenPairs.has(key))
|
|
753
|
+
continue;
|
|
754
|
+
const contentA = `${a.decision} ${a.rationale}`;
|
|
755
|
+
const contentB = `${b.decision} ${b.rationale}`;
|
|
756
|
+
for (const [patternNeg, patternPos] of negationPairs) {
|
|
757
|
+
if ((patternNeg.test(contentA) && patternPos.test(contentB)) ||
|
|
758
|
+
(patternPos.test(contentA) && patternNeg.test(contentB))) {
|
|
759
|
+
seenPairs.add(key);
|
|
760
|
+
contradictions.push({
|
|
761
|
+
entryA: {
|
|
762
|
+
id: a.id,
|
|
763
|
+
type: 'decision',
|
|
764
|
+
content: a.decision,
|
|
765
|
+
createdAt: a.created_at,
|
|
766
|
+
},
|
|
767
|
+
entryB: {
|
|
768
|
+
id: b.id,
|
|
769
|
+
type: 'decision',
|
|
770
|
+
content: b.decision,
|
|
771
|
+
createdAt: b.created_at,
|
|
772
|
+
},
|
|
773
|
+
context: taskId || undefined,
|
|
774
|
+
conflictDetails: `Negation pattern: "${contentA.slice(0, 80)}..." vs "${contentB.slice(0, 80)}..."`,
|
|
775
|
+
});
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
// Check patterns with anti-patterns
|
|
783
|
+
for (const p of patterns) {
|
|
784
|
+
if (p.anti_pattern) {
|
|
785
|
+
contradictions.push({
|
|
786
|
+
entryA: { id: p.id, type: 'pattern', content: p.pattern, createdAt: p.created_at },
|
|
787
|
+
entryB: {
|
|
788
|
+
id: p.id,
|
|
789
|
+
type: 'anti-pattern',
|
|
790
|
+
content: p.anti_pattern,
|
|
791
|
+
createdAt: p.created_at,
|
|
792
|
+
},
|
|
793
|
+
conflictDetails: `Pattern defines its own anti-pattern`,
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
// Check learnings against each other
|
|
798
|
+
for (let i = 0; i < learnings.length; i++) {
|
|
799
|
+
for (let j = i + 1; j < learnings.length; j++) {
|
|
800
|
+
const a = learnings[i];
|
|
801
|
+
const b = learnings[j];
|
|
802
|
+
const key = pairKey(a.id, b.id);
|
|
803
|
+
if (seenPairs.has(key))
|
|
804
|
+
continue;
|
|
805
|
+
for (const [patternNeg, patternPos] of negationPairs) {
|
|
806
|
+
if ((patternNeg.test(a.insight) && patternPos.test(b.insight)) ||
|
|
807
|
+
(patternPos.test(a.insight) && patternNeg.test(b.insight))) {
|
|
808
|
+
seenPairs.add(key);
|
|
809
|
+
contradictions.push({
|
|
810
|
+
entryA: { id: a.id, type: 'learning', content: a.insight, createdAt: a.created_at },
|
|
811
|
+
entryB: { id: b.id, type: 'learning', content: b.insight, createdAt: b.created_at },
|
|
812
|
+
conflictDetails: `Learning contradiction detected`,
|
|
813
|
+
});
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return { success: true, data: { contradictions } };
|
|
820
|
+
}
|
|
821
|
+
catch (error) {
|
|
822
|
+
return {
|
|
823
|
+
success: false,
|
|
824
|
+
error: {
|
|
825
|
+
code: 'E_CONTRADICTIONS',
|
|
826
|
+
message: error instanceof Error ? error.message : String(error),
|
|
827
|
+
},
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Find superseded entries in brain.db.
|
|
833
|
+
*
|
|
834
|
+
* Identifies entries that have been superseded by newer entries on the same topic.
|
|
835
|
+
*
|
|
836
|
+
* @param params - Superseded search parameters
|
|
837
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
838
|
+
* @returns EngineResult with superseded entry pairs and their replacements
|
|
839
|
+
*
|
|
840
|
+
* @remarks
|
|
841
|
+
* Scans brain.db for entries where a newer observation or decision covers
|
|
842
|
+
* the same topic, rendering the older entry obsolete.
|
|
843
|
+
*
|
|
844
|
+
* For brain.db, we group by:
|
|
845
|
+
* - Decisions: type + contextTaskId/contextEpicId
|
|
846
|
+
* - Patterns: type + context (first 100 chars for similarity)
|
|
847
|
+
* - Learnings: source + applicableTypes
|
|
848
|
+
* - Observations: type + project
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```typescript
|
|
852
|
+
* const result = await memorySuperseded({ type: 'decision' }, '/project');
|
|
853
|
+
* ```
|
|
854
|
+
*/
|
|
855
|
+
export async function memorySuperseded(params, projectRoot) {
|
|
856
|
+
try {
|
|
857
|
+
const root = resolveRoot(projectRoot);
|
|
858
|
+
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
859
|
+
await getBrainDb(root);
|
|
860
|
+
const nativeDb = getBrainNativeDb();
|
|
861
|
+
if (!nativeDb) {
|
|
862
|
+
return { success: true, data: { superseded: [] } };
|
|
863
|
+
}
|
|
864
|
+
const superseded = [];
|
|
865
|
+
// Helper to normalize and group by key
|
|
866
|
+
const addSuperseded = (entries, groupKey) => {
|
|
867
|
+
if (entries.length < 2)
|
|
868
|
+
return;
|
|
869
|
+
// Sort by creation date (oldest first)
|
|
870
|
+
const sorted = [...entries].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
871
|
+
// All but the newest are superseded by the newest
|
|
872
|
+
const newest = sorted[sorted.length - 1];
|
|
873
|
+
for (let i = 0; i < sorted.length - 1; i++) {
|
|
874
|
+
superseded.push({
|
|
875
|
+
oldEntry: sorted[i],
|
|
876
|
+
replacement: newest,
|
|
877
|
+
grouping: groupKey,
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
// === DECISIONS: Group by type + contextTaskId/contextEpicId ===
|
|
882
|
+
const decisionGroups = new Map();
|
|
883
|
+
const decisionQuery = params?.type
|
|
884
|
+
? `SELECT id, type, decision, context_task_id, context_epic_id, created_at
|
|
885
|
+
FROM brain_decisions WHERE type = ? ORDER BY created_at DESC`
|
|
886
|
+
: `SELECT id, type, decision, context_task_id, context_epic_id, created_at
|
|
887
|
+
FROM brain_decisions ORDER BY created_at DESC`;
|
|
888
|
+
const decisionParams = params?.type ? [params.type] : [];
|
|
889
|
+
const decisions = nativeDb.prepare(decisionQuery).all(...decisionParams);
|
|
890
|
+
for (const d of decisions) {
|
|
891
|
+
const contextKey = d.context_task_id || d.context_epic_id || 'general';
|
|
892
|
+
const groupKey = `decision:${d.type}:${contextKey}`;
|
|
893
|
+
if (!decisionGroups.has(groupKey))
|
|
894
|
+
decisionGroups.set(groupKey, []);
|
|
895
|
+
decisionGroups.get(groupKey).push({
|
|
896
|
+
id: d.id,
|
|
897
|
+
type: d.type,
|
|
898
|
+
createdAt: d.created_at,
|
|
899
|
+
summary: d.decision.slice(0, 100),
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
for (const [key, entries] of decisionGroups) {
|
|
903
|
+
addSuperseded(entries, key);
|
|
904
|
+
}
|
|
905
|
+
// === PATTERNS: Group by type + context (first 100 chars for similarity) ===
|
|
906
|
+
const patternGroups = new Map();
|
|
907
|
+
const patternQuery = params?.type
|
|
908
|
+
? `SELECT id, type, pattern, context, extracted_at
|
|
909
|
+
FROM brain_patterns WHERE type = ? ORDER BY extracted_at DESC`
|
|
910
|
+
: `SELECT id, type, pattern, context, extracted_at
|
|
911
|
+
FROM brain_patterns ORDER BY extracted_at DESC`;
|
|
912
|
+
const patternParams = params?.type ? [params.type] : [];
|
|
913
|
+
const patterns = nativeDb.prepare(patternQuery).all(...patternParams);
|
|
914
|
+
for (const p of patterns) {
|
|
915
|
+
// Use first 80 chars of context as grouping key for similarity
|
|
916
|
+
const contextKey = p.context?.slice(0, 80) || 'unknown';
|
|
917
|
+
const groupKey = `pattern:${p.type}:${contextKey}`;
|
|
918
|
+
if (!patternGroups.has(groupKey))
|
|
919
|
+
patternGroups.set(groupKey, []);
|
|
920
|
+
patternGroups.get(groupKey).push({
|
|
921
|
+
id: p.id,
|
|
922
|
+
type: p.type,
|
|
923
|
+
createdAt: p.extracted_at,
|
|
924
|
+
summary: p.pattern.slice(0, 100),
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
for (const [key, entries] of patternGroups) {
|
|
928
|
+
addSuperseded(entries, key);
|
|
929
|
+
}
|
|
930
|
+
// === LEARNINGS: Group by source + applicableTypes ===
|
|
931
|
+
const learningGroups = new Map();
|
|
932
|
+
const learningQuery = `SELECT id, source, insight, applicable_types_json, created_at
|
|
933
|
+
FROM brain_learnings ORDER BY created_at DESC`;
|
|
934
|
+
const learnings = nativeDb.prepare(learningQuery).all();
|
|
935
|
+
for (const l of learnings) {
|
|
936
|
+
const applicableTypes = l.applicable_types_json
|
|
937
|
+
? JSON.parse(l.applicable_types_json).slice(0, 2).join(',')
|
|
938
|
+
: 'general';
|
|
939
|
+
const groupKey = `learning:${l.source}:${applicableTypes}`;
|
|
940
|
+
if (!learningGroups.has(groupKey))
|
|
941
|
+
learningGroups.set(groupKey, []);
|
|
942
|
+
learningGroups.get(groupKey).push({
|
|
943
|
+
id: l.id,
|
|
944
|
+
type: 'learning',
|
|
945
|
+
createdAt: l.created_at,
|
|
946
|
+
summary: l.insight.slice(0, 100),
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
for (const [key, entries] of learningGroups) {
|
|
950
|
+
addSuperseded(entries, key);
|
|
951
|
+
}
|
|
952
|
+
// === OBSERVATIONS: Group by type + project ===
|
|
953
|
+
const observationGroups = new Map();
|
|
954
|
+
const observationQuery = params?.type
|
|
955
|
+
? `SELECT id, type, title, project, created_at
|
|
956
|
+
FROM brain_observations WHERE type = ? ORDER BY created_at DESC`
|
|
957
|
+
: `SELECT id, type, title, project, created_at
|
|
958
|
+
FROM brain_observations ORDER BY created_at DESC`;
|
|
959
|
+
const observationParams = params?.type ? [params.type] : [];
|
|
960
|
+
const observations = nativeDb.prepare(observationQuery).all(...observationParams);
|
|
961
|
+
for (const o of observations) {
|
|
962
|
+
const projectKey = params?.project ? params.project : o.project || 'general';
|
|
963
|
+
const groupKey = `observation:${o.type}:${projectKey}`;
|
|
964
|
+
if (!observationGroups.has(groupKey))
|
|
965
|
+
observationGroups.set(groupKey, []);
|
|
966
|
+
observationGroups.get(groupKey).push({
|
|
967
|
+
id: o.id,
|
|
968
|
+
type: o.type,
|
|
969
|
+
createdAt: o.created_at,
|
|
970
|
+
summary: o.title.slice(0, 100),
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
for (const [key, entries] of observationGroups) {
|
|
974
|
+
addSuperseded(entries, key);
|
|
975
|
+
}
|
|
976
|
+
return { success: true, data: { superseded, total: superseded.length } };
|
|
977
|
+
}
|
|
978
|
+
catch (error) {
|
|
979
|
+
return {
|
|
980
|
+
success: false,
|
|
981
|
+
error: {
|
|
982
|
+
code: 'E_MEMORY_SUPERSEDED',
|
|
983
|
+
message: error instanceof Error ? error.message : String(error),
|
|
984
|
+
},
|
|
985
|
+
};
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Link a brain entry to a task.
|
|
990
|
+
*
|
|
991
|
+
* @param params - Link parameters including entryId and taskId
|
|
992
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
993
|
+
* @returns EngineResult confirming the link was created
|
|
994
|
+
*
|
|
995
|
+
* @remarks
|
|
996
|
+
* Creates an association between a brain.db entry and a task in tasks.db.
|
|
997
|
+
* Used for traceability between memory entries and the work they relate to.
|
|
998
|
+
*
|
|
999
|
+
* @example
|
|
1000
|
+
* ```typescript
|
|
1001
|
+
* const result = await memoryLink({ entryId: 'O-abc123', taskId: 'T042' }, '/project');
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
export async function memoryLink(params, projectRoot) {
|
|
1005
|
+
if (!params.taskId || !params.entryId) {
|
|
1006
|
+
return {
|
|
1007
|
+
success: false,
|
|
1008
|
+
error: { code: 'E_INVALID_INPUT', message: 'taskId and entryId are required' },
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
const entryType = parseIdPrefix(params.entryId);
|
|
1012
|
+
if (!entryType) {
|
|
1013
|
+
return {
|
|
1014
|
+
success: false,
|
|
1015
|
+
error: { code: 'E_INVALID_INPUT', message: 'Invalid entryId format' },
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
try {
|
|
1019
|
+
const root = resolveRoot(projectRoot);
|
|
1020
|
+
await linkMemoryToTask(root, entryType, params.entryId, params.taskId, 'applies_to');
|
|
1021
|
+
return {
|
|
1022
|
+
success: true,
|
|
1023
|
+
data: { linked: true, taskId: params.taskId, entryId: params.entryId },
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
catch (error) {
|
|
1027
|
+
return {
|
|
1028
|
+
success: false,
|
|
1029
|
+
error: {
|
|
1030
|
+
code: 'E_MEMORY_LINK',
|
|
1031
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1032
|
+
},
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Remove a link between a brain entry and a task.
|
|
1038
|
+
*
|
|
1039
|
+
* @param params - Unlink parameters including entryId and taskId
|
|
1040
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1041
|
+
* @returns EngineResult confirming the link was removed
|
|
1042
|
+
*
|
|
1043
|
+
* @remarks
|
|
1044
|
+
* Removes the association created by memoryLink. Idempotent if the link
|
|
1045
|
+
* does not exist.
|
|
1046
|
+
*
|
|
1047
|
+
* @example
|
|
1048
|
+
* ```typescript
|
|
1049
|
+
* const result = await memoryUnlink({ entryId: 'O-abc123', taskId: 'T042' }, '/project');
|
|
1050
|
+
* ```
|
|
1051
|
+
*/
|
|
1052
|
+
export async function memoryUnlink(params, projectRoot) {
|
|
1053
|
+
if (!params.taskId || !params.entryId) {
|
|
1054
|
+
return {
|
|
1055
|
+
success: false,
|
|
1056
|
+
error: { code: 'E_INVALID_INPUT', message: 'taskId and entryId are required' },
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
const entryType = parseIdPrefix(params.entryId);
|
|
1060
|
+
if (!entryType) {
|
|
1061
|
+
return {
|
|
1062
|
+
success: false,
|
|
1063
|
+
error: { code: 'E_INVALID_INPUT', message: 'Invalid entryId format' },
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
try {
|
|
1067
|
+
const root = resolveRoot(projectRoot);
|
|
1068
|
+
await unlinkMemoryFromTask(root, entryType, params.entryId, params.taskId, 'applies_to');
|
|
1069
|
+
return {
|
|
1070
|
+
success: true,
|
|
1071
|
+
data: { unlinked: true, taskId: params.taskId, entryId: params.entryId },
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
catch (error) {
|
|
1075
|
+
return {
|
|
1076
|
+
success: false,
|
|
1077
|
+
error: {
|
|
1078
|
+
code: 'E_MEMORY_UNLINK',
|
|
1079
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1080
|
+
},
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
// ============================================================================
|
|
1085
|
+
// PageIndex Graph Operations (T5385)
|
|
1086
|
+
// ============================================================================
|
|
1087
|
+
/**
|
|
1088
|
+
* Add a node or edge to the PageIndex graph.
|
|
1089
|
+
*
|
|
1090
|
+
* @param params - Graph add parameters (node data or edge endpoints)
|
|
1091
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1092
|
+
* @returns EngineResult confirming the node or edge was added
|
|
1093
|
+
*
|
|
1094
|
+
* @remarks
|
|
1095
|
+
* Supports adding both nodes (concepts) and edges (relationships) to the
|
|
1096
|
+
* brain.db knowledge graph (PageIndex).
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```typescript
|
|
1100
|
+
* const result = await memoryGraphAdd({ type: 'node', label: 'auth', nodeType: 'concept' }, '/project');
|
|
1101
|
+
* ```
|
|
1102
|
+
*/
|
|
1103
|
+
export async function memoryGraphAdd(params, projectRoot) {
|
|
1104
|
+
try {
|
|
1105
|
+
const root = resolveRoot(projectRoot);
|
|
1106
|
+
const accessor = await getBrainAccessor(root);
|
|
1107
|
+
// Edge mode: fromId + toId + edgeType
|
|
1108
|
+
if (params.fromId && params.toId && params.edgeType) {
|
|
1109
|
+
const edge = await accessor.addPageEdge({
|
|
1110
|
+
fromId: params.fromId,
|
|
1111
|
+
toId: params.toId,
|
|
1112
|
+
edgeType: params.edgeType,
|
|
1113
|
+
weight: params.weight,
|
|
1114
|
+
});
|
|
1115
|
+
return { success: true, data: { type: 'edge', edge } };
|
|
1116
|
+
}
|
|
1117
|
+
// Node mode: nodeId + nodeType + label
|
|
1118
|
+
if (params.nodeId && params.nodeType && params.label) {
|
|
1119
|
+
const node = await accessor.addPageNode({
|
|
1120
|
+
id: params.nodeId,
|
|
1121
|
+
nodeType: params.nodeType,
|
|
1122
|
+
label: params.label,
|
|
1123
|
+
metadataJson: params.metadataJson,
|
|
1124
|
+
});
|
|
1125
|
+
return { success: true, data: { type: 'node', node } };
|
|
1126
|
+
}
|
|
1127
|
+
return {
|
|
1128
|
+
success: false,
|
|
1129
|
+
error: {
|
|
1130
|
+
code: 'E_INVALID_INPUT',
|
|
1131
|
+
message: 'Provide (nodeId + nodeType + label) for a node or (fromId + toId + edgeType) for an edge',
|
|
1132
|
+
},
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
catch (error) {
|
|
1136
|
+
return {
|
|
1137
|
+
success: false,
|
|
1138
|
+
error: {
|
|
1139
|
+
code: 'E_GRAPH_ADD',
|
|
1140
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1141
|
+
},
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Get a node and its edges from the PageIndex graph.
|
|
1147
|
+
*
|
|
1148
|
+
* @param params - Parameters including the node ID to look up
|
|
1149
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1150
|
+
* @returns EngineResult with the node data and its connected edges
|
|
1151
|
+
*
|
|
1152
|
+
* @remarks
|
|
1153
|
+
* Returns the full node record plus all edges where the node appears as
|
|
1154
|
+
* either source or target.
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* ```typescript
|
|
1158
|
+
* const result = await memoryGraphShow({ nodeId: 'auth' }, '/project');
|
|
1159
|
+
* ```
|
|
1160
|
+
*/
|
|
1161
|
+
export async function memoryGraphShow(params, projectRoot) {
|
|
1162
|
+
if (!params.nodeId) {
|
|
1163
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'nodeId is required' } };
|
|
1164
|
+
}
|
|
1165
|
+
try {
|
|
1166
|
+
const root = resolveRoot(projectRoot);
|
|
1167
|
+
const accessor = await getBrainAccessor(root);
|
|
1168
|
+
const node = await accessor.getPageNode(params.nodeId);
|
|
1169
|
+
if (!node) {
|
|
1170
|
+
return {
|
|
1171
|
+
success: false,
|
|
1172
|
+
error: { code: 'E_NOT_FOUND', message: `Node '${params.nodeId}' not found` },
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
const edges = await accessor.getPageEdges(params.nodeId, 'both');
|
|
1176
|
+
return { success: true, data: { node, edges } };
|
|
1177
|
+
}
|
|
1178
|
+
catch (error) {
|
|
1179
|
+
return {
|
|
1180
|
+
success: false,
|
|
1181
|
+
error: {
|
|
1182
|
+
code: 'E_GRAPH_SHOW',
|
|
1183
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1184
|
+
},
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Get neighbor nodes from the PageIndex graph.
|
|
1190
|
+
*
|
|
1191
|
+
* @param params - Parameters including the node ID and optional depth
|
|
1192
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1193
|
+
* @returns EngineResult with neighboring nodes and connecting edges
|
|
1194
|
+
*
|
|
1195
|
+
* @remarks
|
|
1196
|
+
* Traverses the knowledge graph outward from a given node to find related
|
|
1197
|
+
* concepts within the specified depth.
|
|
1198
|
+
*
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```typescript
|
|
1201
|
+
* const result = await memoryGraphNeighbors({ nodeId: 'auth', depth: 2 }, '/project');
|
|
1202
|
+
* ```
|
|
1203
|
+
*/
|
|
1204
|
+
export async function memoryGraphNeighbors(params, projectRoot) {
|
|
1205
|
+
if (!params.nodeId) {
|
|
1206
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'nodeId is required' } };
|
|
1207
|
+
}
|
|
1208
|
+
try {
|
|
1209
|
+
const root = resolveRoot(projectRoot);
|
|
1210
|
+
const accessor = await getBrainAccessor(root);
|
|
1211
|
+
const neighbors = await accessor.getNeighbors(params.nodeId, params.edgeType);
|
|
1212
|
+
return { success: true, data: { neighbors, total: neighbors.length } };
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
return {
|
|
1216
|
+
success: false,
|
|
1217
|
+
error: {
|
|
1218
|
+
code: 'E_GRAPH_NEIGHBORS',
|
|
1219
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1220
|
+
},
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
// ============================================================================
|
|
1225
|
+
// BRAIN Reasoning & Hybrid Search Operations (T5388-T5393)
|
|
1226
|
+
// ============================================================================
|
|
1227
|
+
/**
|
|
1228
|
+
* Causal trace through task dependency chains.
|
|
1229
|
+
*
|
|
1230
|
+
* @param params - Parameters including the entry or task ID to trace
|
|
1231
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1232
|
+
* @returns EngineResult with the causal chain explaining why something happened
|
|
1233
|
+
*
|
|
1234
|
+
* @remarks
|
|
1235
|
+
* Traces backward through task dependencies and brain entries to build
|
|
1236
|
+
* an explanation chain for a given decision or observation.
|
|
1237
|
+
*
|
|
1238
|
+
* @example
|
|
1239
|
+
* ```typescript
|
|
1240
|
+
* const result = await memoryReasonWhy({ id: 'D-abc123' }, '/project');
|
|
1241
|
+
* ```
|
|
1242
|
+
*/
|
|
1243
|
+
export async function memoryReasonWhy(params, projectRoot) {
|
|
1244
|
+
if (!params.taskId) {
|
|
1245
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'taskId is required' } };
|
|
1246
|
+
}
|
|
1247
|
+
try {
|
|
1248
|
+
const root = resolveRoot(projectRoot);
|
|
1249
|
+
const taskAccessor = await getAccessor(root);
|
|
1250
|
+
const { reasonWhy } = await import('./brain-reasoning.js');
|
|
1251
|
+
const result = await reasonWhy(params.taskId, root, taskAccessor);
|
|
1252
|
+
return { success: true, data: result };
|
|
1253
|
+
}
|
|
1254
|
+
catch (error) {
|
|
1255
|
+
return {
|
|
1256
|
+
success: false,
|
|
1257
|
+
error: {
|
|
1258
|
+
code: 'E_REASON_WHY',
|
|
1259
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1260
|
+
},
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Find semantically similar entries.
|
|
1266
|
+
*
|
|
1267
|
+
* @param params - Parameters including the source entry ID or query text
|
|
1268
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1269
|
+
* @returns EngineResult with entries ranked by semantic similarity
|
|
1270
|
+
*
|
|
1271
|
+
* @remarks
|
|
1272
|
+
* Uses embedding vectors or text similarity to find brain entries that are
|
|
1273
|
+
* semantically close to the given reference.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```typescript
|
|
1277
|
+
* const result = await memoryReasonSimilar({ id: 'O-abc123', limit: 5 }, '/project');
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
export async function memoryReasonSimilar(params, projectRoot) {
|
|
1281
|
+
if (!params.entryId) {
|
|
1282
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'entryId is required' } };
|
|
1283
|
+
}
|
|
1284
|
+
try {
|
|
1285
|
+
const root = resolveRoot(projectRoot);
|
|
1286
|
+
const { reasonSimilar } = await import('./brain-reasoning.js');
|
|
1287
|
+
const results = await reasonSimilar(params.entryId, root, params.limit);
|
|
1288
|
+
return { success: true, data: { results, total: results.length } };
|
|
1289
|
+
}
|
|
1290
|
+
catch (error) {
|
|
1291
|
+
return {
|
|
1292
|
+
success: false,
|
|
1293
|
+
error: {
|
|
1294
|
+
code: 'E_REASON_SIMILAR',
|
|
1295
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1296
|
+
},
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Hybrid search across FTS5, vector, and graph.
|
|
1302
|
+
*
|
|
1303
|
+
* @param params - Search parameters including query and optional mode/limit
|
|
1304
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1305
|
+
* @returns EngineResult with merged and ranked results from all search backends
|
|
1306
|
+
*
|
|
1307
|
+
* @remarks
|
|
1308
|
+
* Combines full-text search (FTS5), vector similarity, and graph traversal
|
|
1309
|
+
* to produce comprehensive search results with merged relevance scoring.
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* const result = await memorySearchHybrid({ query: 'authentication flow' }, '/project');
|
|
1314
|
+
* ```
|
|
1315
|
+
*/
|
|
1316
|
+
export async function memorySearchHybrid(params, projectRoot) {
|
|
1317
|
+
if (!params.query) {
|
|
1318
|
+
return { success: false, error: { code: 'E_INVALID_INPUT', message: 'query is required' } };
|
|
1319
|
+
}
|
|
1320
|
+
try {
|
|
1321
|
+
const root = resolveRoot(projectRoot);
|
|
1322
|
+
const { hybridSearch } = await import('./brain-search.js');
|
|
1323
|
+
const results = await hybridSearch(params.query, root, {
|
|
1324
|
+
ftsWeight: params.ftsWeight,
|
|
1325
|
+
vecWeight: params.vecWeight,
|
|
1326
|
+
graphWeight: params.graphWeight,
|
|
1327
|
+
limit: params.limit,
|
|
1328
|
+
});
|
|
1329
|
+
return { success: true, data: { results, total: results.length } };
|
|
1330
|
+
}
|
|
1331
|
+
catch (error) {
|
|
1332
|
+
return {
|
|
1333
|
+
success: false,
|
|
1334
|
+
error: {
|
|
1335
|
+
code: 'E_HYBRID_SEARCH',
|
|
1336
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1337
|
+
},
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* Remove a node or edge from the PageIndex graph.
|
|
1343
|
+
*
|
|
1344
|
+
* @param params - Parameters specifying the node or edge to remove
|
|
1345
|
+
* @param projectRoot - Optional project root path; defaults to resolved root
|
|
1346
|
+
* @returns EngineResult confirming the removal
|
|
1347
|
+
*
|
|
1348
|
+
* @remarks
|
|
1349
|
+
* Removes a node (and its connected edges) or a specific edge from the
|
|
1350
|
+
* brain.db knowledge graph.
|
|
1351
|
+
*
|
|
1352
|
+
* @example
|
|
1353
|
+
* ```typescript
|
|
1354
|
+
* const result = await memoryGraphRemove({ type: 'node', nodeId: 'stale-concept' }, '/project');
|
|
1355
|
+
* ```
|
|
1356
|
+
*/
|
|
1357
|
+
export async function memoryGraphRemove(params, projectRoot) {
|
|
1358
|
+
try {
|
|
1359
|
+
const root = resolveRoot(projectRoot);
|
|
1360
|
+
const accessor = await getBrainAccessor(root);
|
|
1361
|
+
// Edge removal: fromId + toId + edgeType
|
|
1362
|
+
if (params.fromId && params.toId && params.edgeType) {
|
|
1363
|
+
await accessor.removePageEdge(params.fromId, params.toId, params.edgeType);
|
|
1364
|
+
return {
|
|
1365
|
+
success: true,
|
|
1366
|
+
data: {
|
|
1367
|
+
removed: 'edge',
|
|
1368
|
+
fromId: params.fromId,
|
|
1369
|
+
toId: params.toId,
|
|
1370
|
+
edgeType: params.edgeType,
|
|
1371
|
+
},
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
// Node removal: nodeId (cascades edges)
|
|
1375
|
+
if (params.nodeId) {
|
|
1376
|
+
await accessor.removePageNode(params.nodeId);
|
|
1377
|
+
return { success: true, data: { removed: 'node', nodeId: params.nodeId } };
|
|
1378
|
+
}
|
|
1379
|
+
return {
|
|
1380
|
+
success: false,
|
|
1381
|
+
error: {
|
|
1382
|
+
code: 'E_INVALID_INPUT',
|
|
1383
|
+
message: 'Provide nodeId to remove a node or (fromId + toId + edgeType) to remove an edge',
|
|
1384
|
+
},
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1387
|
+
catch (error) {
|
|
1388
|
+
return {
|
|
1389
|
+
success: false,
|
|
1390
|
+
error: {
|
|
1391
|
+
code: 'E_GRAPH_REMOVE',
|
|
1392
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1393
|
+
},
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
//# sourceMappingURL=engine-compat.js.map
|