@cleocode/core 2026.4.42 → 2026.4.43
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/conduit/factory.d.ts +10 -5
- package/dist/conduit/factory.d.ts.map +1 -1
- package/dist/index.js +71 -7
- package/dist/index.js.map +3 -3
- package/dist/init.d.ts.map +1 -1
- package/dist/store/brain-sqlite.d.ts.map +1 -1
- package/package.json +13 -8
- package/src/conduit/factory.ts +20 -17
- package/src/init.ts +14 -0
- package/src/store/__tests__/git-checkpoint.test.ts +12 -15
- package/src/store/brain-sqlite.ts +12 -0
- package/dist/adapters/adapter-registry.js +0 -64
- package/dist/adapters/adapter-registry.js.map +0 -1
- package/dist/adapters/discovery.js +0 -83
- package/dist/adapters/discovery.js.map +0 -1
- package/dist/adapters/index.js +0 -9
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/manager.js +0 -260
- package/dist/adapters/manager.js.map +0 -1
- package/dist/admin/export-tasks.js +0 -171
- package/dist/admin/export-tasks.js.map +0 -1
- package/dist/admin/export.js +0 -103
- package/dist/admin/export.js.map +0 -1
- package/dist/admin/help.js +0 -106
- package/dist/admin/help.js.map +0 -1
- package/dist/admin/import-tasks.js +0 -182
- package/dist/admin/import-tasks.js.map +0 -1
- package/dist/admin/import.js +0 -129
- package/dist/admin/import.js.map +0 -1
- package/dist/admin/index.js +0 -13
- package/dist/admin/index.js.map +0 -1
- package/dist/adrs/find.js +0 -134
- package/dist/adrs/find.js.map +0 -1
- package/dist/adrs/index.js +0 -15
- package/dist/adrs/index.js.map +0 -1
- package/dist/adrs/link-pipeline.js +0 -160
- package/dist/adrs/link-pipeline.js.map +0 -1
- package/dist/adrs/list.js +0 -43
- package/dist/adrs/list.js.map +0 -1
- package/dist/adrs/parse.js +0 -51
- package/dist/adrs/parse.js.map +0 -1
- package/dist/adrs/show.js +0 -22
- package/dist/adrs/show.js.map +0 -1
- package/dist/adrs/sync.js +0 -232
- package/dist/adrs/sync.js.map +0 -1
- package/dist/adrs/types.js +0 -9
- package/dist/adrs/types.js.map +0 -1
- package/dist/adrs/validate.js +0 -57
- package/dist/adrs/validate.js.map +0 -1
- package/dist/agents/agent-registry.js +0 -288
- package/dist/agents/agent-registry.js.map +0 -1
- package/dist/agents/agent-schema.js +0 -82
- package/dist/agents/agent-schema.js.map +0 -1
- package/dist/agents/capacity.js +0 -116
- package/dist/agents/capacity.js.map +0 -1
- package/dist/agents/execution-learning.js +0 -474
- package/dist/agents/execution-learning.js.map +0 -1
- package/dist/agents/health-monitor.js +0 -217
- package/dist/agents/health-monitor.js.map +0 -1
- package/dist/agents/index.js +0 -29
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/registry.js +0 -314
- package/dist/agents/registry.js.map +0 -1
- package/dist/agents/retry.js +0 -215
- package/dist/agents/retry.js.map +0 -1
- package/dist/audit-prune.js +0 -94
- package/dist/audit-prune.js.map +0 -1
- package/dist/audit.js +0 -68
- package/dist/audit.js.map +0 -1
- package/dist/backfill/index.js +0 -229
- package/dist/backfill/index.js.map +0 -1
- package/dist/bootstrap.js +0 -435
- package/dist/bootstrap.js.map +0 -1
- package/dist/caamp/adapter.js +0 -259
- package/dist/caamp/adapter.js.map +0 -1
- package/dist/caamp/capability-check.js +0 -38
- package/dist/caamp/capability-check.js.map +0 -1
- package/dist/caamp/index.js +0 -21
- package/dist/caamp/index.js.map +0 -1
- package/dist/caamp-init.js +0 -16
- package/dist/caamp-init.js.map +0 -1
- package/dist/cleo.js +0 -322
- package/dist/cleo.js.map +0 -1
- package/dist/code/index.js +0 -14
- package/dist/code/index.js.map +0 -1
- package/dist/code/outline.js +0 -165
- package/dist/code/outline.js.map +0 -1
- package/dist/code/parser.js +0 -420
- package/dist/code/parser.js.map +0 -1
- package/dist/code/search.js +0 -135
- package/dist/code/search.js.map +0 -1
- package/dist/code/unfold.js +0 -155
- package/dist/code/unfold.js.map +0 -1
- package/dist/codebase-map/analyzers/architecture.js +0 -129
- package/dist/codebase-map/analyzers/architecture.js.map +0 -1
- package/dist/codebase-map/analyzers/concerns.js +0 -122
- package/dist/codebase-map/analyzers/concerns.js.map +0 -1
- package/dist/codebase-map/analyzers/conventions.js +0 -149
- package/dist/codebase-map/analyzers/conventions.js.map +0 -1
- package/dist/codebase-map/analyzers/integrations.js +0 -108
- package/dist/codebase-map/analyzers/integrations.js.map +0 -1
- package/dist/codebase-map/analyzers/stack.js +0 -117
- package/dist/codebase-map/analyzers/stack.js.map +0 -1
- package/dist/codebase-map/analyzers/structure.js +0 -137
- package/dist/codebase-map/analyzers/structure.js.map +0 -1
- package/dist/codebase-map/analyzers/testing.js +0 -118
- package/dist/codebase-map/analyzers/testing.js.map +0 -1
- package/dist/codebase-map/index.js +0 -57
- package/dist/codebase-map/index.js.map +0 -1
- package/dist/codebase-map/store.js +0 -122
- package/dist/codebase-map/store.js.map +0 -1
- package/dist/codebase-map/summary.js +0 -152
- package/dist/codebase-map/summary.js.map +0 -1
- package/dist/compliance/index.js +0 -288
- package/dist/compliance/index.js.map +0 -1
- package/dist/compliance/protocol-enforcement.js +0 -332
- package/dist/compliance/protocol-enforcement.js.map +0 -1
- package/dist/compliance/protocol-rules.js +0 -786
- package/dist/compliance/protocol-rules.js.map +0 -1
- package/dist/compliance/protocol-types.js +0 -79
- package/dist/compliance/protocol-types.js.map +0 -1
- package/dist/compliance/store.js +0 -53
- package/dist/compliance/store.js.map +0 -1
- package/dist/conduit/conduit-client.js +0 -107
- package/dist/conduit/conduit-client.js.map +0 -1
- package/dist/conduit/factory.js +0 -52
- package/dist/conduit/factory.js.map +0 -1
- package/dist/conduit/http-transport.js +0 -155
- package/dist/conduit/http-transport.js.map +0 -1
- package/dist/conduit/index.js +0 -15
- package/dist/conduit/index.js.map +0 -1
- package/dist/conduit/local-transport.js +0 -255
- package/dist/conduit/local-transport.js.map +0 -1
- package/dist/conduit/sse-transport.js +0 -299
- package/dist/conduit/sse-transport.js.map +0 -1
- package/dist/config/build-config.js +0 -29
- package/dist/config/build-config.js.map +0 -1
- package/dist/config.js +0 -407
- package/dist/config.js.map +0 -1
- package/dist/constants.js +0 -18
- package/dist/constants.js.map +0 -1
- package/dist/context/index.js +0 -137
- package/dist/context/index.js.map +0 -1
- package/dist/crypto/credentials.js +0 -219
- package/dist/crypto/credentials.js.map +0 -1
- package/dist/discovery.js +0 -182
- package/dist/discovery.js.map +0 -1
- package/dist/engine-result.js +0 -12
- package/dist/engine-result.js.map +0 -1
- package/dist/error-catalog.js +0 -404
- package/dist/error-catalog.js.map +0 -1
- package/dist/error-registry.js +0 -393
- package/dist/error-registry.js.map +0 -1
- package/dist/errors.js +0 -173
- package/dist/errors.js.map +0 -1
- package/dist/hooks/handlers/agent-hooks.js +0 -106
- package/dist/hooks/handlers/agent-hooks.js.map +0 -1
- package/dist/hooks/handlers/conduit-hooks.js +0 -229
- package/dist/hooks/handlers/conduit-hooks.js.map +0 -1
- package/dist/hooks/handlers/context-hooks.js +0 -111
- package/dist/hooks/handlers/context-hooks.js.map +0 -1
- package/dist/hooks/handlers/error-hooks.js +0 -52
- package/dist/hooks/handlers/error-hooks.js.map +0 -1
- package/dist/hooks/handlers/file-hooks.js +0 -104
- package/dist/hooks/handlers/file-hooks.js.map +0 -1
- package/dist/hooks/handlers/handler-helpers.js +0 -61
- package/dist/hooks/handlers/handler-helpers.js.map +0 -1
- package/dist/hooks/handlers/index.js +0 -37
- package/dist/hooks/handlers/index.js.map +0 -1
- package/dist/hooks/handlers/intelligence-hooks.js +0 -69
- package/dist/hooks/handlers/intelligence-hooks.js.map +0 -1
- package/dist/hooks/handlers/memory-bridge-refresh.js +0 -42
- package/dist/hooks/handlers/memory-bridge-refresh.js.map +0 -1
- package/dist/hooks/handlers/notification-hooks.js +0 -62
- package/dist/hooks/handlers/notification-hooks.js.map +0 -1
- package/dist/hooks/handlers/session-hooks.js +0 -190
- package/dist/hooks/handlers/session-hooks.js.map +0 -1
- package/dist/hooks/handlers/task-hooks.js +0 -90
- package/dist/hooks/handlers/task-hooks.js.map +0 -1
- package/dist/hooks/handlers/watchdog-hooks.js +0 -162
- package/dist/hooks/handlers/watchdog-hooks.js.map +0 -1
- package/dist/hooks/handlers/work-capture-hooks.js +0 -165
- package/dist/hooks/handlers/work-capture-hooks.js.map +0 -1
- package/dist/hooks/index.js +0 -13
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/payload-schemas.js +0 -220
- package/dist/hooks/payload-schemas.js.map +0 -1
- package/dist/hooks/provider-hooks.js +0 -66
- package/dist/hooks/provider-hooks.js.map +0 -1
- package/dist/hooks/registry.js +0 -229
- package/dist/hooks/registry.js.map +0 -1
- package/dist/hooks/types.js +0 -66
- package/dist/hooks/types.js.map +0 -1
- package/dist/hooks.js +0 -136
- package/dist/hooks.js.map +0 -1
- package/dist/init.js +0 -942
- package/dist/init.js.map +0 -1
- package/dist/inject/index.js +0 -82
- package/dist/inject/index.js.map +0 -1
- package/dist/injection.js +0 -377
- package/dist/injection.js.map +0 -1
- package/dist/intelligence/adaptive-validation.js +0 -497
- package/dist/intelligence/adaptive-validation.js.map +0 -1
- package/dist/intelligence/impact.js +0 -675
- package/dist/intelligence/impact.js.map +0 -1
- package/dist/intelligence/index.js +0 -22
- package/dist/intelligence/index.js.map +0 -1
- package/dist/intelligence/patterns.js +0 -492
- package/dist/intelligence/patterns.js.map +0 -1
- package/dist/intelligence/prediction.js +0 -499
- package/dist/intelligence/prediction.js.map +0 -1
- package/dist/intelligence/types.js +0 -13
- package/dist/intelligence/types.js.map +0 -1
- package/dist/internal.js +0 -324
- package/dist/internal.js.map +0 -1
- package/dist/issue/create.js +0 -121
- package/dist/issue/create.js.map +0 -1
- package/dist/issue/diagnostics.js +0 -59
- package/dist/issue/diagnostics.js.map +0 -1
- package/dist/issue/index.js +0 -10
- package/dist/issue/index.js.map +0 -1
- package/dist/issue/template-parser.js +0 -267
- package/dist/issue/template-parser.js.map +0 -1
- package/dist/json-schema-validator.js +0 -76
- package/dist/json-schema-validator.js.map +0 -1
- package/dist/lib/index.js +0 -11
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/retry.js +0 -152
- package/dist/lib/retry.js.map +0 -1
- package/dist/lib/tree-sitter-languages.js +0 -75
- package/dist/lib/tree-sitter-languages.js.map +0 -1
- package/dist/lifecycle/chain-composition.js +0 -152
- package/dist/lifecycle/chain-composition.js.map +0 -1
- package/dist/lifecycle/chain-store.js +0 -246
- package/dist/lifecycle/chain-store.js.map +0 -1
- package/dist/lifecycle/consolidate-rcasd.js +0 -352
- package/dist/lifecycle/consolidate-rcasd.js.map +0 -1
- package/dist/lifecycle/default-chain.js +0 -176
- package/dist/lifecycle/default-chain.js.map +0 -1
- package/dist/lifecycle/evidence.js +0 -180
- package/dist/lifecycle/evidence.js.map +0 -1
- package/dist/lifecycle/frontmatter.js +0 -363
- package/dist/lifecycle/frontmatter.js.map +0 -1
- package/dist/lifecycle/index.js +0 -756
- package/dist/lifecycle/index.js.map +0 -1
- package/dist/lifecycle/pipeline.js +0 -656
- package/dist/lifecycle/pipeline.js.map +0 -1
- package/dist/lifecycle/rcasd-index.js +0 -326
- package/dist/lifecycle/rcasd-index.js.map +0 -1
- package/dist/lifecycle/rcasd-paths.js +0 -220
- package/dist/lifecycle/rcasd-paths.js.map +0 -1
- package/dist/lifecycle/resume.js +0 -864
- package/dist/lifecycle/resume.js.map +0 -1
- package/dist/lifecycle/stage-artifacts.js +0 -94
- package/dist/lifecycle/stage-artifacts.js.map +0 -1
- package/dist/lifecycle/stage-guidance.js +0 -234
- package/dist/lifecycle/stage-guidance.js.map +0 -1
- package/dist/lifecycle/stages.js +0 -534
- package/dist/lifecycle/stages.js.map +0 -1
- package/dist/lifecycle/state-machine.js +0 -516
- package/dist/lifecycle/state-machine.js.map +0 -1
- package/dist/lifecycle/tessera-engine.js +0 -249
- package/dist/lifecycle/tessera-engine.js.map +0 -1
- package/dist/logger.js +0 -140
- package/dist/logger.js.map +0 -1
- package/dist/memory/anthropic-key-resolver.js +0 -105
- package/dist/memory/anthropic-key-resolver.js.map +0 -1
- package/dist/memory/auto-extract.js +0 -77
- package/dist/memory/auto-extract.js.map +0 -1
- package/dist/memory/brain-backfill.js +0 -389
- package/dist/memory/brain-backfill.js.map +0 -1
- package/dist/memory/brain-consolidator.js +0 -294
- package/dist/memory/brain-consolidator.js.map +0 -1
- package/dist/memory/brain-embedding.js +0 -66
- package/dist/memory/brain-embedding.js.map +0 -1
- package/dist/memory/brain-lifecycle.js +0 -818
- package/dist/memory/brain-lifecycle.js.map +0 -1
- package/dist/memory/brain-links.js +0 -161
- package/dist/memory/brain-links.js.map +0 -1
- package/dist/memory/brain-maintenance.js +0 -114
- package/dist/memory/brain-maintenance.js.map +0 -1
- package/dist/memory/brain-migration.js +0 -149
- package/dist/memory/brain-migration.js.map +0 -1
- package/dist/memory/brain-purge.js +0 -243
- package/dist/memory/brain-purge.js.map +0 -1
- package/dist/memory/brain-reasoning.js +0 -215
- package/dist/memory/brain-reasoning.js.map +0 -1
- package/dist/memory/brain-retrieval.js +0 -1044
- package/dist/memory/brain-retrieval.js.map +0 -1
- package/dist/memory/brain-row-types.js +0 -10
- package/dist/memory/brain-row-types.js.map +0 -1
- package/dist/memory/brain-search.js +0 -613
- package/dist/memory/brain-search.js.map +0 -1
- package/dist/memory/brain-similarity.js +0 -145
- package/dist/memory/brain-similarity.js.map +0 -1
- package/dist/memory/claude-mem-migration.js +0 -277
- package/dist/memory/claude-mem-migration.js.map +0 -1
- package/dist/memory/decisions.js +0 -236
- package/dist/memory/decisions.js.map +0 -1
- package/dist/memory/embedding-local.js +0 -102
- package/dist/memory/embedding-local.js.map +0 -1
- package/dist/memory/embedding-queue.js +0 -271
- package/dist/memory/embedding-queue.js.map +0 -1
- package/dist/memory/embedding-worker.js +0 -58
- package/dist/memory/embedding-worker.js.map +0 -1
- package/dist/memory/engine-compat.js +0 -1597
- package/dist/memory/engine-compat.js.map +0 -1
- package/dist/memory/extraction-gate.js +0 -459
- package/dist/memory/extraction-gate.js.map +0 -1
- package/dist/memory/graph-auto-populate.js +0 -148
- package/dist/memory/graph-auto-populate.js.map +0 -1
- package/dist/memory/graph-memory-bridge.js +0 -519
- package/dist/memory/graph-memory-bridge.js.map +0 -1
- package/dist/memory/graph-queries.js +0 -290
- package/dist/memory/graph-queries.js.map +0 -1
- package/dist/memory/index.js +0 -1146
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/learnings.js +0 -197
- package/dist/memory/learnings.js.map +0 -1
- package/dist/memory/llm-extraction.js +0 -425
- package/dist/memory/llm-extraction.js.map +0 -1
- package/dist/memory/memory-bridge.js +0 -382
- package/dist/memory/memory-bridge.js.map +0 -1
- package/dist/memory/mental-model-injection.js +0 -61
- package/dist/memory/mental-model-injection.js.map +0 -1
- package/dist/memory/mental-model-queue.js +0 -211
- package/dist/memory/mental-model-queue.js.map +0 -1
- package/dist/memory/observer-reflector.js +0 -626
- package/dist/memory/observer-reflector.js.map +0 -1
- package/dist/memory/patterns.js +0 -192
- package/dist/memory/patterns.js.map +0 -1
- package/dist/memory/pipeline-manifest-sqlite.js +0 -975
- package/dist/memory/pipeline-manifest-sqlite.js.map +0 -1
- package/dist/memory/quality-feedback.js +0 -449
- package/dist/memory/quality-feedback.js.map +0 -1
- package/dist/memory/quality-scoring.js +0 -182
- package/dist/memory/quality-scoring.js.map +0 -1
- package/dist/memory/session-memory.js +0 -331
- package/dist/memory/session-memory.js.map +0 -1
- package/dist/memory/sleep-consolidation.js +0 -706
- package/dist/memory/sleep-consolidation.js.map +0 -1
- package/dist/memory/temporal-supersession.js +0 -403
- package/dist/memory/temporal-supersession.js.map +0 -1
- package/dist/metrics/ab-test.js +0 -260
- package/dist/metrics/ab-test.js.map +0 -1
- package/dist/metrics/aggregation.js +0 -363
- package/dist/metrics/aggregation.js.map +0 -1
- package/dist/metrics/common.js +0 -64
- package/dist/metrics/common.js.map +0 -1
- package/dist/metrics/enums.js +0 -78
- package/dist/metrics/enums.js.map +0 -1
- package/dist/metrics/index.js +0 -19
- package/dist/metrics/index.js.map +0 -1
- package/dist/metrics/model-provider-registry.js +0 -88
- package/dist/metrics/model-provider-registry.js.map +0 -1
- package/dist/metrics/otel-integration.js +0 -263
- package/dist/metrics/otel-integration.js.map +0 -1
- package/dist/metrics/provider-detection.js +0 -103
- package/dist/metrics/provider-detection.js.map +0 -1
- package/dist/metrics/token-estimation.js +0 -253
- package/dist/metrics/token-estimation.js.map +0 -1
- package/dist/metrics/token-service.js +0 -450
- package/dist/metrics/token-service.js.map +0 -1
- package/dist/migration/agent-outputs.js +0 -316
- package/dist/migration/agent-outputs.js.map +0 -1
- package/dist/migration/checksum.js +0 -92
- package/dist/migration/checksum.js.map +0 -1
- package/dist/migration/index.js +0 -282
- package/dist/migration/index.js.map +0 -1
- package/dist/migration/logger.js +0 -360
- package/dist/migration/logger.js.map +0 -1
- package/dist/migration/preflight.js +0 -9
- package/dist/migration/preflight.js.map +0 -1
- package/dist/migration/state.js +0 -421
- package/dist/migration/state.js.map +0 -1
- package/dist/migration/validate.js +0 -241
- package/dist/migration/validate.js.map +0 -1
- package/dist/mvi-helpers.js +0 -73
- package/dist/mvi-helpers.js.map +0 -1
- package/dist/nexus/deps.js +0 -375
- package/dist/nexus/deps.js.map +0 -1
- package/dist/nexus/discover.js +0 -288
- package/dist/nexus/discover.js.map +0 -1
- package/dist/nexus/hash.js +0 -10
- package/dist/nexus/hash.js.map +0 -1
- package/dist/nexus/index.js +0 -40
- package/dist/nexus/index.js.map +0 -1
- package/dist/nexus/migrate-json-to-sqlite.js +0 -115
- package/dist/nexus/migrate-json-to-sqlite.js.map +0 -1
- package/dist/nexus/nexus-bridge.js +0 -321
- package/dist/nexus/nexus-bridge.js.map +0 -1
- package/dist/nexus/permissions.js +0 -105
- package/dist/nexus/permissions.js.map +0 -1
- package/dist/nexus/query.js +0 -175
- package/dist/nexus/query.js.map +0 -1
- package/dist/nexus/registry.js +0 -584
- package/dist/nexus/registry.js.map +0 -1
- package/dist/nexus/sharing/index.js +0 -288
- package/dist/nexus/sharing/index.js.map +0 -1
- package/dist/nexus/transfer-types.js +0 -8
- package/dist/nexus/transfer-types.js.map +0 -1
- package/dist/nexus/transfer.js +0 -271
- package/dist/nexus/transfer.js.map +0 -1
- package/dist/nexus/workspace.js +0 -355
- package/dist/nexus/workspace.js.map +0 -1
- package/dist/observability/index.js +0 -103
- package/dist/observability/index.js.map +0 -1
- package/dist/observability/log-filter.js +0 -63
- package/dist/observability/log-filter.js.map +0 -1
- package/dist/observability/log-parser.js +0 -99
- package/dist/observability/log-parser.js.map +0 -1
- package/dist/observability/log-reader.js +0 -139
- package/dist/observability/log-reader.js.map +0 -1
- package/dist/observability/types.js +0 -19
- package/dist/observability/types.js.map +0 -1
- package/dist/orchestration/analyze.js +0 -107
- package/dist/orchestration/analyze.js.map +0 -1
- package/dist/orchestration/bootstrap.js +0 -132
- package/dist/orchestration/bootstrap.js.map +0 -1
- package/dist/orchestration/context.js +0 -56
- package/dist/orchestration/context.js.map +0 -1
- package/dist/orchestration/critical-path.js +0 -100
- package/dist/orchestration/critical-path.js.map +0 -1
- package/dist/orchestration/hierarchy.js +0 -183
- package/dist/orchestration/hierarchy.js.map +0 -1
- package/dist/orchestration/index.js +0 -287
- package/dist/orchestration/index.js.map +0 -1
- package/dist/orchestration/parallel.js +0 -89
- package/dist/orchestration/parallel.js.map +0 -1
- package/dist/orchestration/protocol-validators.js +0 -815
- package/dist/orchestration/protocol-validators.js.map +0 -1
- package/dist/orchestration/skill-ops.js +0 -98
- package/dist/orchestration/skill-ops.js.map +0 -1
- package/dist/orchestration/status.js +0 -107
- package/dist/orchestration/status.js.map +0 -1
- package/dist/orchestration/unblock.js +0 -103
- package/dist/orchestration/unblock.js.map +0 -1
- package/dist/orchestration/validate-spawn.js +0 -67
- package/dist/orchestration/validate-spawn.js.map +0 -1
- package/dist/orchestration/waves.js +0 -86
- package/dist/orchestration/waves.js.map +0 -1
- package/dist/otel/index.js +0 -163
- package/dist/otel/index.js.map +0 -1
- package/dist/output.js +0 -164
- package/dist/output.js.map +0 -1
- package/dist/pagination.js +0 -64
- package/dist/pagination.js.map +0 -1
- package/dist/paths.js +0 -882
- package/dist/paths.js.map +0 -1
- package/dist/phases/deps.js +0 -372
- package/dist/phases/deps.js.map +0 -1
- package/dist/phases/index.js +0 -349
- package/dist/phases/index.js.map +0 -1
- package/dist/pipeline/index.js +0 -10
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/phase.js +0 -45
- package/dist/pipeline/phase.js.map +0 -1
- package/dist/platform.js +0 -211
- package/dist/platform.js.map +0 -1
- package/dist/project-info.js +0 -84
- package/dist/project-info.js.map +0 -1
- package/dist/reconciliation/index.js +0 -10
- package/dist/reconciliation/index.js.map +0 -1
- package/dist/reconciliation/link-store.js +0 -175
- package/dist/reconciliation/link-store.js.map +0 -1
- package/dist/reconciliation/reconciliation-engine.js +0 -298
- package/dist/reconciliation/reconciliation-engine.js.map +0 -1
- package/dist/release/artifacts.js +0 -427
- package/dist/release/artifacts.js.map +0 -1
- package/dist/release/changelog-writer.js +0 -151
- package/dist/release/changelog-writer.js.map +0 -1
- package/dist/release/channel.js +0 -144
- package/dist/release/channel.js.map +0 -1
- package/dist/release/ci.js +0 -166
- package/dist/release/ci.js.map +0 -1
- package/dist/release/github-pr.js +0 -225
- package/dist/release/github-pr.js.map +0 -1
- package/dist/release/guards.js +0 -116
- package/dist/release/guards.js.map +0 -1
- package/dist/release/index.js +0 -22
- package/dist/release/index.js.map +0 -1
- package/dist/release/release-config.js +0 -158
- package/dist/release/release-config.js.map +0 -1
- package/dist/release/release-manifest.js +0 -1019
- package/dist/release/release-manifest.js.map +0 -1
- package/dist/release/version-bump.js +0 -255
- package/dist/release/version-bump.js.map +0 -1
- package/dist/remote/index.js +0 -257
- package/dist/remote/index.js.map +0 -1
- package/dist/repair.js +0 -130
- package/dist/repair.js.map +0 -1
- package/dist/research/index.js +0 -2
- package/dist/research/index.js.map +0 -1
- package/dist/roadmap/index.js +0 -59
- package/dist/roadmap/index.js.map +0 -1
- package/dist/routing/capability-matrix.js +0 -1556
- package/dist/routing/capability-matrix.js.map +0 -1
- package/dist/routing/index.js +0 -9
- package/dist/routing/index.js.map +0 -1
- package/dist/scaffold.js +0 -1798
- package/dist/scaffold.js.map +0 -1
- package/dist/schema-management.js +0 -295
- package/dist/schema-management.js.map +0 -1
- package/dist/security/index.js +0 -9
- package/dist/security/index.js.map +0 -1
- package/dist/security/input-sanitization.js +0 -326
- package/dist/security/input-sanitization.js.map +0 -1
- package/dist/sequence/index.js +0 -295
- package/dist/sequence/index.js.map +0 -1
- package/dist/sessions/assumptions.js +0 -54
- package/dist/sessions/assumptions.js.map +0 -1
- package/dist/sessions/briefing.js +0 -377
- package/dist/sessions/briefing.js.map +0 -1
- package/dist/sessions/context-alert.js +0 -222
- package/dist/sessions/context-alert.js.map +0 -1
- package/dist/sessions/context-inject.js +0 -61
- package/dist/sessions/context-inject.js.map +0 -1
- package/dist/sessions/context-monitor.js +0 -98
- package/dist/sessions/context-monitor.js.map +0 -1
- package/dist/sessions/decisions.js +0 -65
- package/dist/sessions/decisions.js.map +0 -1
- package/dist/sessions/find.js +0 -65
- package/dist/sessions/find.js.map +0 -1
- package/dist/sessions/handoff.js +0 -328
- package/dist/sessions/handoff.js.map +0 -1
- package/dist/sessions/hitl-warnings.js +0 -254
- package/dist/sessions/hitl-warnings.js.map +0 -1
- package/dist/sessions/index.js +0 -327
- package/dist/sessions/index.js.map +0 -1
- package/dist/sessions/session-archive.js +0 -40
- package/dist/sessions/session-archive.js.map +0 -1
- package/dist/sessions/session-cleanup.js +0 -59
- package/dist/sessions/session-cleanup.js.map +0 -1
- package/dist/sessions/session-drift.js +0 -134
- package/dist/sessions/session-drift.js.map +0 -1
- package/dist/sessions/session-enforcement.js +0 -144
- package/dist/sessions/session-enforcement.js.map +0 -1
- package/dist/sessions/session-grade.js +0 -253
- package/dist/sessions/session-grade.js.map +0 -1
- package/dist/sessions/session-history.js +0 -42
- package/dist/sessions/session-history.js.map +0 -1
- package/dist/sessions/session-id.js +0 -81
- package/dist/sessions/session-id.js.map +0 -1
- package/dist/sessions/session-memory-bridge.js +0 -30
- package/dist/sessions/session-memory-bridge.js.map +0 -1
- package/dist/sessions/session-show.js +0 -24
- package/dist/sessions/session-show.js.map +0 -1
- package/dist/sessions/session-stats.js +0 -69
- package/dist/sessions/session-stats.js.map +0 -1
- package/dist/sessions/session-suspend.js +0 -39
- package/dist/sessions/session-suspend.js.map +0 -1
- package/dist/sessions/session-switch.js +0 -51
- package/dist/sessions/session-switch.js.map +0 -1
- package/dist/sessions/session-view.js +0 -76
- package/dist/sessions/session-view.js.map +0 -1
- package/dist/sessions/snapshot.js +0 -213
- package/dist/sessions/snapshot.js.map +0 -1
- package/dist/sessions/statusline-setup.js +0 -85
- package/dist/sessions/statusline-setup.js.map +0 -1
- package/dist/sessions/types.js +0 -8
- package/dist/sessions/types.js.map +0 -1
- package/dist/skills/agents/config.js +0 -94
- package/dist/skills/agents/config.js.map +0 -1
- package/dist/skills/agents/install.js +0 -116
- package/dist/skills/agents/install.js.map +0 -1
- package/dist/skills/agents/registry.js +0 -161
- package/dist/skills/agents/registry.js.map +0 -1
- package/dist/skills/discovery.js +0 -333
- package/dist/skills/discovery.js.map +0 -1
- package/dist/skills/dispatch.js +0 -347
- package/dist/skills/dispatch.js.map +0 -1
- package/dist/skills/dynamic-skill-generator.js +0 -87
- package/dist/skills/dynamic-skill-generator.js.map +0 -1
- package/dist/skills/index.js +0 -44
- package/dist/skills/index.js.map +0 -1
- package/dist/skills/injection/subagent.js +0 -195
- package/dist/skills/injection/subagent.js.map +0 -1
- package/dist/skills/injection/token.js +0 -260
- package/dist/skills/injection/token.js.map +0 -1
- package/dist/skills/install.js +0 -40
- package/dist/skills/install.js.map +0 -1
- package/dist/skills/manifests/contribution.js +0 -175
- package/dist/skills/manifests/contribution.js.map +0 -1
- package/dist/skills/manifests/research.js +0 -281
- package/dist/skills/manifests/research.js.map +0 -1
- package/dist/skills/manifests/resolver.js +0 -146
- package/dist/skills/manifests/resolver.js.map +0 -1
- package/dist/skills/marketplace.js +0 -90
- package/dist/skills/marketplace.js.map +0 -1
- package/dist/skills/orchestrator/spawn.js +0 -178
- package/dist/skills/orchestrator/spawn.js.map +0 -1
- package/dist/skills/orchestrator/startup.js +0 -451
- package/dist/skills/orchestrator/startup.js.map +0 -1
- package/dist/skills/orchestrator/validator.js +0 -301
- package/dist/skills/orchestrator/validator.js.map +0 -1
- package/dist/skills/precedence-integration.js +0 -73
- package/dist/skills/precedence-integration.js.map +0 -1
- package/dist/skills/precedence-types.js +0 -16
- package/dist/skills/precedence-types.js.map +0 -1
- package/dist/skills/routing-table.js +0 -63
- package/dist/skills/routing-table.js.map +0 -1
- package/dist/skills/skill-paths.js +0 -217
- package/dist/skills/skill-paths.js.map +0 -1
- package/dist/skills/test-utility.js +0 -55
- package/dist/skills/test-utility.js.map +0 -1
- package/dist/skills/types.js +0 -118
- package/dist/skills/types.js.map +0 -1
- package/dist/skills/validation.js +0 -183
- package/dist/skills/validation.js.map +0 -1
- package/dist/skills/version.js +0 -57
- package/dist/skills/version.js.map +0 -1
- package/dist/snapshot/index.js +0 -188
- package/dist/snapshot/index.js.map +0 -1
- package/dist/spawn/adapter-registry.js +0 -246
- package/dist/spawn/adapter-registry.js.map +0 -1
- package/dist/spawn/index.js +0 -10
- package/dist/spawn/index.js.map +0 -1
- package/dist/stats/index.js +0 -350
- package/dist/stats/index.js.map +0 -1
- package/dist/stats/workflow-telemetry.js +0 -400
- package/dist/stats/workflow-telemetry.js.map +0 -1
- package/dist/sticky/archive.js +0 -47
- package/dist/sticky/archive.js.map +0 -1
- package/dist/sticky/convert.js +0 -235
- package/dist/sticky/convert.js.map +0 -1
- package/dist/sticky/create.js +0 -48
- package/dist/sticky/create.js.map +0 -1
- package/dist/sticky/id.js +0 -35
- package/dist/sticky/id.js.map +0 -1
- package/dist/sticky/index.js +0 -16
- package/dist/sticky/index.js.map +0 -1
- package/dist/sticky/list.js +0 -57
- package/dist/sticky/list.js.map +0 -1
- package/dist/sticky/purge.js +0 -45
- package/dist/sticky/purge.js.map +0 -1
- package/dist/sticky/show.js +0 -42
- package/dist/sticky/show.js.map +0 -1
- package/dist/sticky/types.js +0 -10
- package/dist/sticky/types.js.map +0 -1
- package/dist/store/agent-registry-accessor.js +0 -886
- package/dist/store/agent-registry-accessor.js.map +0 -1
- package/dist/store/api-key-kdf.js +0 -84
- package/dist/store/api-key-kdf.js.map +0 -1
- package/dist/store/atomic.js +0 -167
- package/dist/store/atomic.js.map +0 -1
- package/dist/store/backup-crypto.js +0 -184
- package/dist/store/backup-crypto.js.map +0 -1
- package/dist/store/backup-pack.js +0 -581
- package/dist/store/backup-pack.js.map +0 -1
- package/dist/store/backup-unpack.js +0 -449
- package/dist/store/backup-unpack.js.map +0 -1
- package/dist/store/backup.js +0 -94
- package/dist/store/backup.js.map +0 -1
- package/dist/store/brain-accessor.js +0 -429
- package/dist/store/brain-accessor.js.map +0 -1
- package/dist/store/brain-schema.js +0 -579
- package/dist/store/brain-schema.js.map +0 -1
- package/dist/store/brain-sqlite.js +0 -297
- package/dist/store/brain-sqlite.js.map +0 -1
- package/dist/store/cache.js +0 -168
- package/dist/store/cache.js.map +0 -1
- package/dist/store/chain-schema.js +0 -51
- package/dist/store/chain-schema.js.map +0 -1
- package/dist/store/cleanup-legacy.js +0 -171
- package/dist/store/cleanup-legacy.js.map +0 -1
- package/dist/store/conduit-sqlite.js +0 -570
- package/dist/store/conduit-sqlite.js.map +0 -1
- package/dist/store/converters.js +0 -124
- package/dist/store/converters.js.map +0 -1
- package/dist/store/cross-db-cleanup.js +0 -319
- package/dist/store/cross-db-cleanup.js.map +0 -1
- package/dist/store/data-accessor.js +0 -26
- package/dist/store/data-accessor.js.map +0 -1
- package/dist/store/data-safety-central.js +0 -269
- package/dist/store/data-safety-central.js.map +0 -1
- package/dist/store/data-safety.js +0 -274
- package/dist/store/data-safety.js.map +0 -1
- package/dist/store/db-helpers.js +0 -224
- package/dist/store/db-helpers.js.map +0 -1
- package/dist/store/export.js +0 -155
- package/dist/store/export.js.map +0 -1
- package/dist/store/file-utils.js +0 -270
- package/dist/store/file-utils.js.map +0 -1
- package/dist/store/git-checkpoint.js +0 -365
- package/dist/store/git-checkpoint.js.map +0 -1
- package/dist/store/global-salt.js +0 -147
- package/dist/store/global-salt.js.map +0 -1
- package/dist/store/import-logging.js +0 -139
- package/dist/store/import-logging.js.map +0 -1
- package/dist/store/import-remap.js +0 -145
- package/dist/store/import-remap.js.map +0 -1
- package/dist/store/import-sort.js +0 -121
- package/dist/store/import-sort.js.map +0 -1
- package/dist/store/index.js +0 -29
- package/dist/store/index.js.map +0 -1
- package/dist/store/json.js +0 -208
- package/dist/store/json.js.map +0 -1
- package/dist/store/lifecycle-store.js +0 -249
- package/dist/store/lifecycle-store.js.map +0 -1
- package/dist/store/lock.js +0 -70
- package/dist/store/lock.js.map +0 -1
- package/dist/store/migrate-signaldock-to-conduit.js +0 -562
- package/dist/store/migrate-signaldock-to-conduit.js.map +0 -1
- package/dist/store/migration-manager.js +0 -288
- package/dist/store/migration-manager.js.map +0 -1
- package/dist/store/migration-sqlite.js +0 -676
- package/dist/store/migration-sqlite.js.map +0 -1
- package/dist/store/nexus-schema.js +0 -268
- package/dist/store/nexus-schema.js.map +0 -1
- package/dist/store/nexus-sqlite.js +0 -242
- package/dist/store/nexus-sqlite.js.map +0 -1
- package/dist/store/nexus-validation-schemas.js +0 -40
- package/dist/store/nexus-validation-schemas.js.map +0 -1
- package/dist/store/parsers.js +0 -37
- package/dist/store/parsers.js.map +0 -1
- package/dist/store/project-detect.js +0 -457
- package/dist/store/project-detect.js.map +0 -1
- package/dist/store/provider.js +0 -101
- package/dist/store/provider.js.map +0 -1
- package/dist/store/regenerators.js +0 -207
- package/dist/store/regenerators.js.map +0 -1
- package/dist/store/restore-conflict-report.js +0 -206
- package/dist/store/restore-conflict-report.js.map +0 -1
- package/dist/store/restore-json-merge.js +0 -454
- package/dist/store/restore-json-merge.js.map +0 -1
- package/dist/store/safety-data-accessor.js +0 -257
- package/dist/store/safety-data-accessor.js.map +0 -1
- package/dist/store/schema.js +0 -7
- package/dist/store/schema.js.map +0 -1
- package/dist/store/session-store.js +0 -219
- package/dist/store/session-store.js.map +0 -1
- package/dist/store/signaldock-sqlite.js +0 -550
- package/dist/store/signaldock-sqlite.js.map +0 -1
- package/dist/store/sqlite-backup.js +0 -498
- package/dist/store/sqlite-backup.js.map +0 -1
- package/dist/store/sqlite-data-accessor.js +0 -787
- package/dist/store/sqlite-data-accessor.js.map +0 -1
- package/dist/store/sqlite.js +0 -483
- package/dist/store/sqlite.js.map +0 -1
- package/dist/store/status-registry.js +0 -8
- package/dist/store/status-registry.js.map +0 -1
- package/dist/store/t310-readiness.js +0 -115
- package/dist/store/t310-readiness.js.map +0 -1
- package/dist/store/task-store.js +0 -358
- package/dist/store/task-store.js.map +0 -1
- package/dist/store/tasks-schema.js +0 -610
- package/dist/store/tasks-schema.js.map +0 -1
- package/dist/store/typed-query.js +0 -15
- package/dist/store/typed-query.js.map +0 -1
- package/dist/store/validation-schemas.js +0 -278
- package/dist/store/validation-schemas.js.map +0 -1
- package/dist/system/archive-analytics.js +0 -277
- package/dist/system/archive-analytics.js.map +0 -1
- package/dist/system/archive-stats.js +0 -64
- package/dist/system/archive-stats.js.map +0 -1
- package/dist/system/audit.js +0 -145
- package/dist/system/audit.js.map +0 -1
- package/dist/system/backup.js +0 -280
- package/dist/system/backup.js.map +0 -1
- package/dist/system/cleanup.js +0 -134
- package/dist/system/cleanup.js.map +0 -1
- package/dist/system/dependencies.js +0 -466
- package/dist/system/dependencies.js.map +0 -1
- package/dist/system/health.js +0 -1206
- package/dist/system/health.js.map +0 -1
- package/dist/system/index.js +0 -18
- package/dist/system/index.js.map +0 -1
- package/dist/system/inject-generate.js +0 -122
- package/dist/system/inject-generate.js.map +0 -1
- package/dist/system/labels.js +0 -38
- package/dist/system/labels.js.map +0 -1
- package/dist/system/metrics.js +0 -61
- package/dist/system/metrics.js.map +0 -1
- package/dist/system/migrate.js +0 -43
- package/dist/system/migrate.js.map +0 -1
- package/dist/system/platform-paths.js +0 -80
- package/dist/system/platform-paths.js.map +0 -1
- package/dist/system/runtime.js +0 -161
- package/dist/system/runtime.js.map +0 -1
- package/dist/system/safestop.js +0 -89
- package/dist/system/safestop.js.map +0 -1
- package/dist/system/storage-preflight.js +0 -123
- package/dist/system/storage-preflight.js.map +0 -1
- package/dist/task-work/index.js +0 -159
- package/dist/task-work/index.js.map +0 -1
- package/dist/tasks/add.js +0 -837
- package/dist/tasks/add.js.map +0 -1
- package/dist/tasks/analyze.js +0 -85
- package/dist/tasks/analyze.js.map +0 -1
- package/dist/tasks/archive.js +0 -90
- package/dist/tasks/archive.js.map +0 -1
- package/dist/tasks/atomicity.js +0 -83
- package/dist/tasks/atomicity.js.map +0 -1
- package/dist/tasks/cancel-ops.js +0 -83
- package/dist/tasks/cancel-ops.js.map +0 -1
- package/dist/tasks/complete.js +0 -248
- package/dist/tasks/complete.js.map +0 -1
- package/dist/tasks/crossref-extract.js +0 -73
- package/dist/tasks/crossref-extract.js.map +0 -1
- package/dist/tasks/delete-preview.js +0 -192
- package/dist/tasks/delete-preview.js.map +0 -1
- package/dist/tasks/delete.js +0 -120
- package/dist/tasks/delete.js.map +0 -1
- package/dist/tasks/deletion-strategy.js +0 -200
- package/dist/tasks/deletion-strategy.js.map +0 -1
- package/dist/tasks/dependency-check.js +0 -278
- package/dist/tasks/dependency-check.js.map +0 -1
- package/dist/tasks/deps-ready.js +0 -32
- package/dist/tasks/deps-ready.js.map +0 -1
- package/dist/tasks/enforcement.js +0 -86
- package/dist/tasks/enforcement.js.map +0 -1
- package/dist/tasks/epic-enforcement.js +0 -294
- package/dist/tasks/epic-enforcement.js.map +0 -1
- package/dist/tasks/find.js +0 -163
- package/dist/tasks/find.js.map +0 -1
- package/dist/tasks/graph-cache.js +0 -127
- package/dist/tasks/graph-cache.js.map +0 -1
- package/dist/tasks/graph-ops.js +0 -173
- package/dist/tasks/graph-ops.js.map +0 -1
- package/dist/tasks/graph-rag.js +0 -328
- package/dist/tasks/graph-rag.js.map +0 -1
- package/dist/tasks/hierarchy-policy.js +0 -149
- package/dist/tasks/hierarchy-policy.js.map +0 -1
- package/dist/tasks/hierarchy.js +0 -185
- package/dist/tasks/hierarchy.js.map +0 -1
- package/dist/tasks/id-generator.js +0 -65
- package/dist/tasks/id-generator.js.map +0 -1
- package/dist/tasks/index.js +0 -14
- package/dist/tasks/index.js.map +0 -1
- package/dist/tasks/labels.js +0 -55
- package/dist/tasks/labels.js.map +0 -1
- package/dist/tasks/list.js +0 -75
- package/dist/tasks/list.js.map +0 -1
- package/dist/tasks/phase-tracking.js +0 -133
- package/dist/tasks/phase-tracking.js.map +0 -1
- package/dist/tasks/pipeline-stage.js +0 -248
- package/dist/tasks/pipeline-stage.js.map +0 -1
- package/dist/tasks/plan.js +0 -268
- package/dist/tasks/plan.js.map +0 -1
- package/dist/tasks/relates.js +0 -101
- package/dist/tasks/relates.js.map +0 -1
- package/dist/tasks/show.js +0 -83
- package/dist/tasks/show.js.map +0 -1
- package/dist/tasks/size-weighting.js +0 -86
- package/dist/tasks/size-weighting.js.map +0 -1
- package/dist/tasks/staleness.js +0 -86
- package/dist/tasks/staleness.js.map +0 -1
- package/dist/tasks/task-ops.js +0 -1741
- package/dist/tasks/task-ops.js.map +0 -1
- package/dist/tasks/update.js +0 -303
- package/dist/tasks/update.js.map +0 -1
- package/dist/templates/index.js +0 -10
- package/dist/templates/index.js.map +0 -1
- package/dist/templates/parser.js +0 -254
- package/dist/templates/parser.js.map +0 -1
- package/dist/ui/aliases.js +0 -153
- package/dist/ui/aliases.js.map +0 -1
- package/dist/ui/changelog.js +0 -184
- package/dist/ui/changelog.js.map +0 -1
- package/dist/ui/command-registry.js +0 -168
- package/dist/ui/command-registry.js.map +0 -1
- package/dist/ui/flags.js +0 -94
- package/dist/ui/flags.js.map +0 -1
- package/dist/ui/index.js +0 -24
- package/dist/ui/index.js.map +0 -1
- package/dist/upgrade.js +0 -1371
- package/dist/upgrade.js.map +0 -1
- package/dist/validation/chain-validation.js +0 -146
- package/dist/validation/chain-validation.js.map +0 -1
- package/dist/validation/compliance.js +0 -155
- package/dist/validation/compliance.js.map +0 -1
- package/dist/validation/docs-sync.js +0 -212
- package/dist/validation/docs-sync.js.map +0 -1
- package/dist/validation/doctor/checks.js +0 -1069
- package/dist/validation/doctor/checks.js.map +0 -1
- package/dist/validation/doctor/index.js +0 -9
- package/dist/validation/doctor/index.js.map +0 -1
- package/dist/validation/doctor/project-cache.js +0 -160
- package/dist/validation/doctor/project-cache.js.map +0 -1
- package/dist/validation/doctor/utils.js +0 -155
- package/dist/validation/doctor/utils.js.map +0 -1
- package/dist/validation/engine.js +0 -914
- package/dist/validation/engine.js.map +0 -1
- package/dist/validation/gap-check.js +0 -175
- package/dist/validation/gap-check.js.map +0 -1
- package/dist/validation/index.js +0 -40
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/manifest.js +0 -237
- package/dist/validation/manifest.js.map +0 -1
- package/dist/validation/operation-gate-validators.js +0 -724
- package/dist/validation/operation-gate-validators.js.map +0 -1
- package/dist/validation/operation-verification-gates.js +0 -532
- package/dist/validation/operation-verification-gates.js.map +0 -1
- package/dist/validation/param-utils.js +0 -141
- package/dist/validation/param-utils.js.map +0 -1
- package/dist/validation/protocol-common.js +0 -300
- package/dist/validation/protocol-common.js.map +0 -1
- package/dist/validation/protocols/_shared.js +0 -82
- package/dist/validation/protocols/_shared.js.map +0 -1
- package/dist/validation/protocols/architecture-decision.js +0 -31
- package/dist/validation/protocols/architecture-decision.js.map +0 -1
- package/dist/validation/protocols/artifact-publish.js +0 -28
- package/dist/validation/protocols/artifact-publish.js.map +0 -1
- package/dist/validation/protocols/consensus.js +0 -41
- package/dist/validation/protocols/consensus.js.map +0 -1
- package/dist/validation/protocols/contribution.js +0 -27
- package/dist/validation/protocols/contribution.js.map +0 -1
- package/dist/validation/protocols/decomposition.js +0 -28
- package/dist/validation/protocols/decomposition.js.map +0 -1
- package/dist/validation/protocols/implementation.js +0 -24
- package/dist/validation/protocols/implementation.js.map +0 -1
- package/dist/validation/protocols/provenance.js +0 -29
- package/dist/validation/protocols/provenance.js.map +0 -1
- package/dist/validation/protocols/release.js +0 -29
- package/dist/validation/protocols/release.js.map +0 -1
- package/dist/validation/protocols/research.js +0 -24
- package/dist/validation/protocols/research.js.map +0 -1
- package/dist/validation/protocols/specification.js +0 -27
- package/dist/validation/protocols/specification.js.map +0 -1
- package/dist/validation/protocols/testing.js +0 -30
- package/dist/validation/protocols/testing.js.map +0 -1
- package/dist/validation/protocols/validation.js +0 -30
- package/dist/validation/protocols/validation.js.map +0 -1
- package/dist/validation/schema-integrity.js +0 -170
- package/dist/validation/schema-integrity.js.map +0 -1
- package/dist/validation/schema-validator.js +0 -176
- package/dist/validation/schema-validator.js.map +0 -1
- package/dist/validation/validate-ops.js +0 -937
- package/dist/validation/validate-ops.js.map +0 -1
- package/dist/validation/validation-rules.js +0 -226
- package/dist/validation/validation-rules.js.map +0 -1
- package/dist/validation/verification.js +0 -321
- package/dist/validation/verification.js.map +0 -1
- package/migrations/drizzle-nexus/20260412000001_t529-nexus-graph-tables/migration.sql +0 -49
|
@@ -1,1044 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BRAIN Retrieval Operations — 3-layer pattern (search -> timeline -> fetch).
|
|
3
|
-
*
|
|
4
|
-
* Provides token-efficient memory access modeled after claude-mem's
|
|
5
|
-
* search/timeline/get_observations workflow:
|
|
6
|
-
*
|
|
7
|
-
* 1. searchBrainCompact — lightweight index (IDs + titles, ~50 tokens/hit)
|
|
8
|
-
* 2. timelineBrain — chronological context around an anchor entry
|
|
9
|
-
* 3. fetchBrainEntries — full details for a filtered set of IDs
|
|
10
|
-
* 4. observeBrain — unified save (observations table)
|
|
11
|
-
*
|
|
12
|
-
* Wave 2A provides the core implementations; Wave 2B wires them through
|
|
13
|
-
* the dispatch layer (engine-compat -> domain handler -> CLI gateway).
|
|
14
|
-
*
|
|
15
|
-
* @task T5131 T5132 T5133 T5134 T5135
|
|
16
|
-
* @epic T5149
|
|
17
|
-
*/
|
|
18
|
-
import { createHash } from 'node:crypto';
|
|
19
|
-
import { memoryFindHitNext } from '../mvi-helpers.js';
|
|
20
|
-
import { getBrainAccessor } from '../store/brain-accessor.js';
|
|
21
|
-
import { sessionExistsInTasksDb } from '../store/cross-db-cleanup.js';
|
|
22
|
-
import { getDb } from '../store/sqlite.js';
|
|
23
|
-
import { typedAll } from '../store/typed-query.js';
|
|
24
|
-
import { embedText, isEmbeddingAvailable } from './brain-embedding.js';
|
|
25
|
-
import { hybridSearch, searchBrain } from './brain-search.js';
|
|
26
|
-
import { searchSimilar } from './brain-similarity.js';
|
|
27
|
-
import { addGraphEdge, upsertGraphNode } from './graph-auto-populate.js';
|
|
28
|
-
import { computeObservationQuality } from './quality-scoring.js';
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// Layer 1: Compact Search
|
|
31
|
-
// ============================================================================
|
|
32
|
-
/**
|
|
33
|
-
* Token-efficient compact search across BRAIN tables.
|
|
34
|
-
* Returns index-level hits (~50 tokens per result).
|
|
35
|
-
*
|
|
36
|
-
* Delegates to searchBrain() from brain-search.ts for FTS5/LIKE search,
|
|
37
|
-
* then projects results to a compact format with optional date filtering.
|
|
38
|
-
*
|
|
39
|
-
* @param projectRoot - Project root directory
|
|
40
|
-
* @param params - Search parameters
|
|
41
|
-
* @returns Compact search results with token estimate
|
|
42
|
-
*/
|
|
43
|
-
export async function searchBrainCompact(projectRoot, params) {
|
|
44
|
-
const { query, limit, tables, dateStart, dateEnd, agent, useRRF = true } = params;
|
|
45
|
-
if (!query?.trim()) {
|
|
46
|
-
return { results: [], total: 0, tokensEstimated: 0 };
|
|
47
|
-
}
|
|
48
|
-
const effectiveLimit = limit ?? 10;
|
|
49
|
-
// T418: agent filter always forces FTS-only on observations table
|
|
50
|
-
const agentFilter = agent !== undefined && agent !== null;
|
|
51
|
-
// ----- RRF path (default) -----
|
|
52
|
-
if (useRRF && !agentFilter) {
|
|
53
|
-
// Run FTS (for dates + table-level data) and RRF fusion in parallel.
|
|
54
|
-
// FTS gives us row-level dates; RRF gives us the fused ranking order.
|
|
55
|
-
const [ftsResult, rrfResults] = await Promise.all([
|
|
56
|
-
searchBrain(projectRoot, query, { limit: effectiveLimit * 3, tables }).catch(() => ({
|
|
57
|
-
decisions: [],
|
|
58
|
-
patterns: [],
|
|
59
|
-
learnings: [],
|
|
60
|
-
observations: [],
|
|
61
|
-
})),
|
|
62
|
-
hybridSearch(query, projectRoot, { limit: effectiveLimit * 2 }),
|
|
63
|
-
]);
|
|
64
|
-
// Build a date map from FTS rows (id -> date string)
|
|
65
|
-
const dateMap = new Map();
|
|
66
|
-
for (const d of ftsResult.decisions) {
|
|
67
|
-
const raw = d;
|
|
68
|
-
dateMap.set(d.id, (d.createdAt ?? raw['created_at']) || '');
|
|
69
|
-
}
|
|
70
|
-
for (const p of ftsResult.patterns) {
|
|
71
|
-
const raw = p;
|
|
72
|
-
dateMap.set(p.id, (p.extractedAt ?? raw['extracted_at']) || '');
|
|
73
|
-
}
|
|
74
|
-
for (const l of ftsResult.learnings) {
|
|
75
|
-
const raw = l;
|
|
76
|
-
dateMap.set(l.id, (l.createdAt ?? raw['created_at']) || '');
|
|
77
|
-
}
|
|
78
|
-
for (const o of ftsResult.observations) {
|
|
79
|
-
const raw = o;
|
|
80
|
-
dateMap.set(o.id, (o.createdAt ?? raw['created_at']) || '');
|
|
81
|
-
}
|
|
82
|
-
// Apply table filter when specified (map singular type names to plural table names)
|
|
83
|
-
const singularToTable = {
|
|
84
|
-
decision: 'decisions',
|
|
85
|
-
pattern: 'patterns',
|
|
86
|
-
learning: 'learnings',
|
|
87
|
-
observation: 'observations',
|
|
88
|
-
};
|
|
89
|
-
let results = rrfResults
|
|
90
|
-
.map((r) => ({
|
|
91
|
-
id: r.id,
|
|
92
|
-
type: r.type,
|
|
93
|
-
title: r.title.slice(0, 80),
|
|
94
|
-
date: dateMap.get(r.id) ?? '',
|
|
95
|
-
relevance: r.score,
|
|
96
|
-
}))
|
|
97
|
-
.filter((r) => {
|
|
98
|
-
// Only include items that the FTS scan returned (ensures quality gating is respected)
|
|
99
|
-
return dateMap.has(r.id);
|
|
100
|
-
});
|
|
101
|
-
if (tables && tables.length > 0) {
|
|
102
|
-
results = results.filter((r) => tables.includes(singularToTable[r.type]));
|
|
103
|
-
}
|
|
104
|
-
// Apply date filters client-side
|
|
105
|
-
if (dateStart)
|
|
106
|
-
results = results.filter((r) => !r.date || r.date >= dateStart);
|
|
107
|
-
if (dateEnd)
|
|
108
|
-
results = results.filter((r) => !r.date || r.date <= dateEnd);
|
|
109
|
-
results = results.slice(0, effectiveLimit);
|
|
110
|
-
for (const hit of results) {
|
|
111
|
-
hit._next = memoryFindHitNext(hit.id);
|
|
112
|
-
}
|
|
113
|
-
if (results.length > 0) {
|
|
114
|
-
const returnedIds = results.map((r) => r.id);
|
|
115
|
-
setImmediate(() => {
|
|
116
|
-
incrementCitationCounts(projectRoot, returnedIds).catch(() => { });
|
|
117
|
-
logRetrieval(projectRoot, query, returnedIds, 'find-rrf', results.length * 50).catch(() => { });
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
return { results, total: results.length, tokensEstimated: results.length * 50 };
|
|
121
|
-
}
|
|
122
|
-
// ----- FTS-only path (useRRF=false or agent filter) -----
|
|
123
|
-
const effectiveTables = agentFilter
|
|
124
|
-
? ['observations']
|
|
125
|
-
: tables;
|
|
126
|
-
const searchResult = await searchBrain(projectRoot, query, {
|
|
127
|
-
limit: effectiveLimit,
|
|
128
|
-
tables: effectiveTables,
|
|
129
|
-
});
|
|
130
|
-
// Project full results to compact format.
|
|
131
|
-
// Note: searchBrain() returns rows from raw SQL (nativeDb) which use
|
|
132
|
-
// snake_case column names, but the TypeScript types are camelCase.
|
|
133
|
-
// We handle both naming conventions for robustness.
|
|
134
|
-
let results = [];
|
|
135
|
-
if (!agentFilter) {
|
|
136
|
-
for (const d of searchResult.decisions) {
|
|
137
|
-
const raw = d;
|
|
138
|
-
results.push({
|
|
139
|
-
id: d.id,
|
|
140
|
-
type: 'decision',
|
|
141
|
-
title: d.decision.slice(0, 80),
|
|
142
|
-
date: (d.createdAt ?? raw['created_at']) || '',
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
for (const p of searchResult.patterns) {
|
|
146
|
-
const raw = p;
|
|
147
|
-
results.push({
|
|
148
|
-
id: p.id,
|
|
149
|
-
type: 'pattern',
|
|
150
|
-
title: p.pattern.slice(0, 80),
|
|
151
|
-
date: (p.extractedAt ?? raw['extracted_at']) || '',
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
for (const l of searchResult.learnings) {
|
|
155
|
-
const raw = l;
|
|
156
|
-
results.push({
|
|
157
|
-
id: l.id,
|
|
158
|
-
type: 'learning',
|
|
159
|
-
title: l.insight.slice(0, 80),
|
|
160
|
-
date: (l.createdAt ?? raw['created_at']) || '',
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
for (const o of searchResult.observations) {
|
|
165
|
-
const raw = o;
|
|
166
|
-
// T418: apply agent post-filter when specified
|
|
167
|
-
if (agentFilter) {
|
|
168
|
-
const rowAgent = o.agent ?? raw['agent'] ?? null;
|
|
169
|
-
if (rowAgent !== agent)
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
results.push({
|
|
173
|
-
id: o.id,
|
|
174
|
-
type: 'observation',
|
|
175
|
-
title: o.title.slice(0, 80),
|
|
176
|
-
date: (o.createdAt ?? raw['created_at']) || '',
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
// Apply date filters client-side if provided
|
|
180
|
-
if (dateStart)
|
|
181
|
-
results = results.filter((r) => r.date >= dateStart);
|
|
182
|
-
if (dateEnd)
|
|
183
|
-
results = results.filter((r) => r.date <= dateEnd);
|
|
184
|
-
// Enrich each hit with _next progressive disclosure directives
|
|
185
|
-
for (const hit of results) {
|
|
186
|
-
hit._next = memoryFindHitNext(hit.id);
|
|
187
|
-
}
|
|
188
|
-
// Citation tracking + retrieval logging (non-blocking)
|
|
189
|
-
if (results.length > 0) {
|
|
190
|
-
const returnedIds = results.map((r) => r.id);
|
|
191
|
-
setImmediate(() => {
|
|
192
|
-
incrementCitationCounts(projectRoot, returnedIds).catch(() => { });
|
|
193
|
-
logRetrieval(projectRoot, query, returnedIds, 'find', results.length * 50).catch(() => { });
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return {
|
|
197
|
-
results,
|
|
198
|
-
total: results.length,
|
|
199
|
-
tokensEstimated: results.length * 50,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
// ============================================================================
|
|
203
|
-
// Layer 2: Timeline
|
|
204
|
-
// ============================================================================
|
|
205
|
-
/**
|
|
206
|
-
* Determine the entry type from its ID prefix.
|
|
207
|
-
*
|
|
208
|
-
* Conventions:
|
|
209
|
-
* - D... -> decision (D001, D-xxx)
|
|
210
|
-
* - P... -> pattern (P001, P-xxx)
|
|
211
|
-
* - L... -> learning (L001, L-xxx)
|
|
212
|
-
* - O... or CM-... -> observation (O-xxx, CM-xxx)
|
|
213
|
-
*/
|
|
214
|
-
function parseIdPrefix(id) {
|
|
215
|
-
if (id.startsWith('D-') || /^D\d/.test(id))
|
|
216
|
-
return 'decision';
|
|
217
|
-
if (id.startsWith('P-') || /^P\d/.test(id))
|
|
218
|
-
return 'pattern';
|
|
219
|
-
if (id.startsWith('L-') || /^L\d/.test(id))
|
|
220
|
-
return 'learning';
|
|
221
|
-
if (id.startsWith('O-') || id.startsWith('O') || id.startsWith('CM-'))
|
|
222
|
-
return 'observation';
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Get chronological context around an anchor entry.
|
|
227
|
-
* Fetches the anchor's full data, then queries all 4 BRAIN tables
|
|
228
|
-
* via UNION ALL to find chronological neighbors.
|
|
229
|
-
*
|
|
230
|
-
* @param projectRoot - Project root directory
|
|
231
|
-
* @param params - Timeline parameters with anchor ID and depth
|
|
232
|
-
* @returns Anchor entry data with surrounding chronological entries
|
|
233
|
-
*/
|
|
234
|
-
export async function timelineBrain(projectRoot, params) {
|
|
235
|
-
const { anchor: anchorId, depthBefore = 3, depthAfter = 3 } = params;
|
|
236
|
-
// Ensure DB is initialized
|
|
237
|
-
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
238
|
-
await getBrainDb(projectRoot);
|
|
239
|
-
const nativeDb = getBrainNativeDb();
|
|
240
|
-
if (!nativeDb) {
|
|
241
|
-
return { anchor: null, before: [], after: [] };
|
|
242
|
-
}
|
|
243
|
-
// Determine anchor type and fetch it via accessor
|
|
244
|
-
const anchorType = parseIdPrefix(anchorId);
|
|
245
|
-
if (!anchorType) {
|
|
246
|
-
return { anchor: null, before: [], after: [] };
|
|
247
|
-
}
|
|
248
|
-
const accessor = await getBrainAccessor(projectRoot);
|
|
249
|
-
let anchorData = null;
|
|
250
|
-
let anchorDate = null;
|
|
251
|
-
switch (anchorType) {
|
|
252
|
-
case 'decision': {
|
|
253
|
-
const row = await accessor.getDecision(anchorId);
|
|
254
|
-
if (row) {
|
|
255
|
-
anchorData = row;
|
|
256
|
-
anchorDate = row.createdAt;
|
|
257
|
-
}
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
case 'pattern': {
|
|
261
|
-
const row = await accessor.getPattern(anchorId);
|
|
262
|
-
if (row) {
|
|
263
|
-
anchorData = row;
|
|
264
|
-
anchorDate = row.extractedAt;
|
|
265
|
-
}
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case 'learning': {
|
|
269
|
-
const row = await accessor.getLearning(anchorId);
|
|
270
|
-
if (row) {
|
|
271
|
-
anchorData = row;
|
|
272
|
-
anchorDate = row.createdAt;
|
|
273
|
-
}
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case 'observation': {
|
|
277
|
-
const row = await accessor.getObservation(anchorId);
|
|
278
|
-
if (row) {
|
|
279
|
-
anchorData = row;
|
|
280
|
-
anchorDate = row.createdAt;
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (!anchorData || !anchorDate) {
|
|
286
|
-
return { anchor: null, before: [], after: [] };
|
|
287
|
-
}
|
|
288
|
-
// UNION ALL across all 4 tables to get chronological neighbors.
|
|
289
|
-
// Excludes the anchor itself.
|
|
290
|
-
const beforeRows = typedAll(nativeDb.prepare(`
|
|
291
|
-
SELECT id, 'decision' AS type, created_at AS date FROM brain_decisions WHERE created_at < ? AND id != ?
|
|
292
|
-
UNION ALL
|
|
293
|
-
SELECT id, 'pattern' AS type, extracted_at AS date FROM brain_patterns WHERE extracted_at < ? AND id != ?
|
|
294
|
-
UNION ALL
|
|
295
|
-
SELECT id, 'learning' AS type, created_at AS date FROM brain_learnings WHERE created_at < ? AND id != ?
|
|
296
|
-
UNION ALL
|
|
297
|
-
SELECT id, 'observation' AS type, created_at AS date FROM brain_observations WHERE created_at < ? AND id != ?
|
|
298
|
-
ORDER BY date DESC
|
|
299
|
-
LIMIT ?
|
|
300
|
-
`), anchorDate, anchorId, anchorDate, anchorId, anchorDate, anchorId, anchorDate, anchorId, depthBefore);
|
|
301
|
-
const afterRows = typedAll(nativeDb.prepare(`
|
|
302
|
-
SELECT id, 'decision' AS type, created_at AS date FROM brain_decisions WHERE created_at > ? AND id != ?
|
|
303
|
-
UNION ALL
|
|
304
|
-
SELECT id, 'pattern' AS type, extracted_at AS date FROM brain_patterns WHERE extracted_at > ? AND id != ?
|
|
305
|
-
UNION ALL
|
|
306
|
-
SELECT id, 'learning' AS type, created_at AS date FROM brain_learnings WHERE created_at > ? AND id != ?
|
|
307
|
-
UNION ALL
|
|
308
|
-
SELECT id, 'observation' AS type, created_at AS date FROM brain_observations WHERE created_at > ? AND id != ?
|
|
309
|
-
ORDER BY date ASC
|
|
310
|
-
LIMIT ?
|
|
311
|
-
`), anchorDate, anchorId, anchorDate, anchorId, anchorDate, anchorId, anchorDate, anchorId, depthAfter);
|
|
312
|
-
return {
|
|
313
|
-
anchor: { id: anchorId, type: anchorType, data: anchorData },
|
|
314
|
-
before: beforeRows.map((r) => ({ id: r.id, type: r.type, date: r.date })),
|
|
315
|
-
after: afterRows.map((r) => ({ id: r.id, type: r.type, date: r.date })),
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
// ============================================================================
|
|
319
|
-
// Layer 3: Batch Fetch
|
|
320
|
-
// ============================================================================
|
|
321
|
-
/**
|
|
322
|
-
* Batch-fetch full details by IDs.
|
|
323
|
-
* Groups IDs by prefix to query the correct tables via BrainDataAccessor.
|
|
324
|
-
*
|
|
325
|
-
* @param projectRoot - Project root directory
|
|
326
|
-
* @param params - Fetch parameters with IDs
|
|
327
|
-
* @returns Full entry data for each found ID, plus not-found list
|
|
328
|
-
*/
|
|
329
|
-
export async function fetchBrainEntries(projectRoot, params) {
|
|
330
|
-
const { ids } = params;
|
|
331
|
-
if (!ids || ids.length === 0) {
|
|
332
|
-
return { results: [], notFound: [], tokensEstimated: 0 };
|
|
333
|
-
}
|
|
334
|
-
const accessor = await getBrainAccessor(projectRoot);
|
|
335
|
-
// Group IDs by type prefix
|
|
336
|
-
const decisionIds = [];
|
|
337
|
-
const patternIds = [];
|
|
338
|
-
const learningIds = [];
|
|
339
|
-
const observationIds = [];
|
|
340
|
-
const unknownIds = [];
|
|
341
|
-
for (const id of ids) {
|
|
342
|
-
const type = parseIdPrefix(id);
|
|
343
|
-
switch (type) {
|
|
344
|
-
case 'decision':
|
|
345
|
-
decisionIds.push(id);
|
|
346
|
-
break;
|
|
347
|
-
case 'pattern':
|
|
348
|
-
patternIds.push(id);
|
|
349
|
-
break;
|
|
350
|
-
case 'learning':
|
|
351
|
-
learningIds.push(id);
|
|
352
|
-
break;
|
|
353
|
-
case 'observation':
|
|
354
|
-
observationIds.push(id);
|
|
355
|
-
break;
|
|
356
|
-
default:
|
|
357
|
-
unknownIds.push(id);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const results = [];
|
|
361
|
-
const notFound = [...unknownIds];
|
|
362
|
-
// Fetch decisions
|
|
363
|
-
for (const id of decisionIds) {
|
|
364
|
-
const row = await accessor.getDecision(id);
|
|
365
|
-
if (row) {
|
|
366
|
-
results.push({ id, type: 'decision', data: row });
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
notFound.push(id);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
// Fetch patterns
|
|
373
|
-
for (const id of patternIds) {
|
|
374
|
-
const row = await accessor.getPattern(id);
|
|
375
|
-
if (row) {
|
|
376
|
-
results.push({ id, type: 'pattern', data: row });
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
notFound.push(id);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
// Fetch learnings
|
|
383
|
-
for (const id of learningIds) {
|
|
384
|
-
const row = await accessor.getLearning(id);
|
|
385
|
-
if (row) {
|
|
386
|
-
results.push({ id, type: 'learning', data: row });
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
notFound.push(id);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
// Fetch observations
|
|
393
|
-
for (const id of observationIds) {
|
|
394
|
-
const row = await accessor.getObservation(id);
|
|
395
|
-
if (row) {
|
|
396
|
-
results.push({ id, type: 'observation', data: row });
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
notFound.push(id);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
// Citation tracking + retrieval logging (non-blocking)
|
|
403
|
-
if (results.length > 0) {
|
|
404
|
-
const fetchedIds = results.map((r) => r.id);
|
|
405
|
-
setImmediate(() => {
|
|
406
|
-
incrementCitationCounts(projectRoot, fetchedIds).catch(() => { });
|
|
407
|
-
logRetrieval(projectRoot, fetchedIds.join(','), fetchedIds, 'fetch', results.length * 500).catch(() => { });
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
return {
|
|
411
|
-
results,
|
|
412
|
-
notFound,
|
|
413
|
-
tokensEstimated: results.length * 500,
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
// ============================================================================
|
|
417
|
-
// Observe (Unified Save)
|
|
418
|
-
// ============================================================================
|
|
419
|
-
/**
|
|
420
|
-
* Keyword patterns for auto-classifying observation type from text.
|
|
421
|
-
*/
|
|
422
|
-
const TYPE_KEYWORDS = [
|
|
423
|
-
{ keywords: ['bug', 'fix', 'error', 'crash'], type: 'bugfix' },
|
|
424
|
-
{ keywords: ['refactor', 'rename', 'extract', 'move'], type: 'refactor' },
|
|
425
|
-
{ keywords: ['add', 'create', 'implement', 'new'], type: 'feature' },
|
|
426
|
-
{ keywords: ['decide', 'chose', 'pick', 'instead'], type: 'decision' },
|
|
427
|
-
{ keywords: ['update', 'change', 'modify', 'upgrade'], type: 'change' },
|
|
428
|
-
];
|
|
429
|
-
/**
|
|
430
|
-
* Auto-classify observation type from text using keyword matching.
|
|
431
|
-
*/
|
|
432
|
-
function classifyObservationType(text) {
|
|
433
|
-
const lower = text.toLowerCase();
|
|
434
|
-
for (const { keywords, type } of TYPE_KEYWORDS) {
|
|
435
|
-
for (const keyword of keywords) {
|
|
436
|
-
if (lower.includes(keyword)) {
|
|
437
|
-
return type;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
return 'discovery';
|
|
442
|
-
}
|
|
443
|
-
/** Monotonic counter to prevent ID collisions within the same millisecond. */
|
|
444
|
-
let observeSeq = 0;
|
|
445
|
-
/**
|
|
446
|
-
* Save an observation to the BRAIN observations table.
|
|
447
|
-
* Replaces the external claude-mem save_observation pattern.
|
|
448
|
-
*
|
|
449
|
-
* Auto-classifies type from text if not provided. Generates a
|
|
450
|
-
* unique ID with O- prefix + base36 timestamp.
|
|
451
|
-
*
|
|
452
|
-
* @param projectRoot - Project root directory
|
|
453
|
-
* @param params - Observation data
|
|
454
|
-
* @returns Created observation ID, type, and timestamp
|
|
455
|
-
*/
|
|
456
|
-
export async function observeBrain(projectRoot, params) {
|
|
457
|
-
const { text, title: titleParam, type: typeParam, project, sourceSessionId, sourceType, agent, sourceConfidence: sourceConfidenceParam, } = params;
|
|
458
|
-
if (!text?.trim()) {
|
|
459
|
-
throw new Error('Observation text is required');
|
|
460
|
-
}
|
|
461
|
-
const type = typeParam ?? classifyObservationType(text);
|
|
462
|
-
const title = titleParam ?? text.slice(0, 120);
|
|
463
|
-
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
464
|
-
// T549 Wave 1-A: Tier routing for observations.
|
|
465
|
-
// Observations always start as short-term episodic entries.
|
|
466
|
-
// sourceConfidence routing (spec §4.1 Decision Tree):
|
|
467
|
-
// - sourceType 'manual' → 'owner' (owner-stated facts skip short-term in consolidator)
|
|
468
|
-
// - sourceType 'session-debrief' → 'task-outcome' (synthesized summaries)
|
|
469
|
-
// - otherwise → 'agent' (default for all hook/agent writes)
|
|
470
|
-
// Source confidence routing (spec §4.1 Decision Tree):
|
|
471
|
-
// - sourceType 'manual' → 'owner' (owner-stated facts are ground truth)
|
|
472
|
-
// - sourceType 'session-debrief' → 'task-outcome' (verified by completion)
|
|
473
|
-
// - otherwise → 'agent' (default for all hook/agent writes)
|
|
474
|
-
// Owner and task-outcome sources are auto-verified as ground truth.
|
|
475
|
-
// Agent-inferred entries start unverified — consolidator promotes via corroboration.
|
|
476
|
-
const resolvedSourceConfidence = sourceConfidenceParam ??
|
|
477
|
-
(sourceType === 'manual'
|
|
478
|
-
? 'owner'
|
|
479
|
-
: sourceType === 'session-debrief'
|
|
480
|
-
? 'task-outcome'
|
|
481
|
-
: 'agent');
|
|
482
|
-
const memoryTier = 'short';
|
|
483
|
-
const memoryType = 'episodic';
|
|
484
|
-
const verified = resolvedSourceConfidence === 'owner' || resolvedSourceConfidence === 'task-outcome';
|
|
485
|
-
// Content-hash dedup: SHA-256 prefix of title+text
|
|
486
|
-
const contentHash = createHash('sha256')
|
|
487
|
-
.update(title + text)
|
|
488
|
-
.digest('hex')
|
|
489
|
-
.slice(0, 16);
|
|
490
|
-
// Check for recent duplicate (same content within last 30 seconds)
|
|
491
|
-
const { getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
492
|
-
const nativeDb = getBrainNativeDb();
|
|
493
|
-
if (nativeDb) {
|
|
494
|
-
const cutoff = new Date(Date.now() - 30000).toISOString().replace('T', ' ').slice(0, 19);
|
|
495
|
-
const existing = typedAll(nativeDb.prepare('SELECT id, type, created_at FROM brain_observations WHERE content_hash = ? AND created_at > ?'), contentHash, cutoff);
|
|
496
|
-
if (existing.length > 0) {
|
|
497
|
-
return {
|
|
498
|
-
id: existing[0].id,
|
|
499
|
-
type: existing[0].type,
|
|
500
|
-
createdAt: existing[0].created_at,
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
// Write-guard: validate cross-db session reference before inserting
|
|
505
|
-
let validSessionId = sourceSessionId ?? null;
|
|
506
|
-
if (validSessionId) {
|
|
507
|
-
try {
|
|
508
|
-
const tasksDb = await getDb(projectRoot);
|
|
509
|
-
if (!(await sessionExistsInTasksDb(validSessionId, tasksDb))) {
|
|
510
|
-
validSessionId = null;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
catch {
|
|
514
|
-
// Best-effort: if tasks.db unavailable, null out the reference
|
|
515
|
-
validSessionId = null;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
// Compute quality score from text richness, title length, and T549 source multiplier.
|
|
519
|
-
const qualityScore = computeObservationQuality({
|
|
520
|
-
text,
|
|
521
|
-
title,
|
|
522
|
-
sourceConfidence: resolvedSourceConfidence,
|
|
523
|
-
memoryTier,
|
|
524
|
-
});
|
|
525
|
-
const id = `O-${Date.now().toString(36)}-${(observeSeq++ % 1000).toString(36)}`;
|
|
526
|
-
const accessor = await getBrainAccessor(projectRoot);
|
|
527
|
-
const row = await accessor.addObservation({
|
|
528
|
-
id,
|
|
529
|
-
type,
|
|
530
|
-
title,
|
|
531
|
-
narrative: text,
|
|
532
|
-
contentHash,
|
|
533
|
-
project: project ?? null,
|
|
534
|
-
sourceSessionId: validSessionId,
|
|
535
|
-
sourceType: sourceType ?? 'agent',
|
|
536
|
-
agent: agent ?? null,
|
|
537
|
-
qualityScore,
|
|
538
|
-
createdAt: now,
|
|
539
|
-
// T549 Wave 1-A: tier/type/confidence assigned at write time
|
|
540
|
-
memoryTier,
|
|
541
|
-
memoryType,
|
|
542
|
-
sourceConfidence: resolvedSourceConfidence,
|
|
543
|
-
verified,
|
|
544
|
-
});
|
|
545
|
-
// Populate embedding if provider is available (T5387).
|
|
546
|
-
// Fire-and-forget: embedding runs in the background so it never blocks the CLI.
|
|
547
|
-
// The observation is already saved above — if embedding fails, the observation
|
|
548
|
-
// still exists, just without vector similarity search capability. (T027)
|
|
549
|
-
if (isEmbeddingAvailable()) {
|
|
550
|
-
setImmediate(() => {
|
|
551
|
-
embedText(text)
|
|
552
|
-
.then((vector) => {
|
|
553
|
-
if (vector && nativeDb) {
|
|
554
|
-
nativeDb
|
|
555
|
-
.prepare('INSERT OR REPLACE INTO brain_embeddings (id, embedding) VALUES (?, ?)')
|
|
556
|
-
.run(id, Buffer.from(vector.buffer));
|
|
557
|
-
}
|
|
558
|
-
})
|
|
559
|
-
.catch(() => {
|
|
560
|
-
// Silently skip embedding failures — observation is already persisted
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
// Regenerate memory bridge for high-value observation types (T5240).
|
|
565
|
-
// Only learning and decision types trigger bridge refresh to avoid excessive writes.
|
|
566
|
-
if (type === 'decision') {
|
|
567
|
-
import('./memory-bridge.js')
|
|
568
|
-
.then(({ refreshMemoryBridge }) => refreshMemoryBridge(projectRoot))
|
|
569
|
-
.catch(() => {
|
|
570
|
-
/* Memory bridge refresh is best-effort */
|
|
571
|
-
});
|
|
572
|
-
}
|
|
573
|
-
// Auto-link observation to the currently focused task when a session is active. (T141)
|
|
574
|
-
// This is a fire-and-forget side effect — linking failure MUST NOT block the return.
|
|
575
|
-
if (validSessionId) {
|
|
576
|
-
autoLinkObservationToTask(projectRoot, row.id, accessor).catch(() => {
|
|
577
|
-
/* Auto-linking is best-effort */
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
// Auto-populate graph node + edges for this observation (best-effort, T537).
|
|
581
|
-
try {
|
|
582
|
-
await upsertGraphNode(projectRoot, `observation:${row.id}`, 'observation', row.title.substring(0, 200), row.qualityScore ?? 0.5, row.narrative ?? row.title, { sourceType: row.sourceType, agent: row.agent ?? undefined });
|
|
583
|
-
// Link observation → session when the observation has a session context.
|
|
584
|
-
if (validSessionId) {
|
|
585
|
-
await upsertGraphNode(projectRoot, `session:${validSessionId}`, 'session', validSessionId, 0.8, '');
|
|
586
|
-
await addGraphEdge(projectRoot, `observation:${row.id}`, `session:${validSessionId}`, 'produced_by', 1.0, 'auto:observe');
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
catch {
|
|
590
|
-
/* Graph population is best-effort — never block the primary return */
|
|
591
|
-
}
|
|
592
|
-
return {
|
|
593
|
-
id: row.id,
|
|
594
|
-
type: row.type,
|
|
595
|
-
createdAt: row.createdAt,
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
/**
|
|
599
|
-
* Auto-link a newly created observation to the currently focused task.
|
|
600
|
-
*
|
|
601
|
-
* Queries the active session via sessionStatus() and reads taskWork.taskId.
|
|
602
|
-
* If a task is focused, inserts a brain_memory_links row linking the
|
|
603
|
-
* observation to that task with linkType 'produced_by'.
|
|
604
|
-
*
|
|
605
|
-
* All failures are silently swallowed — this is a best-effort side effect.
|
|
606
|
-
*
|
|
607
|
-
* @param projectRoot - Project root directory
|
|
608
|
-
* @param observationId - ID of the newly created observation
|
|
609
|
-
* @param accessor - BrainDataAccessor to use for the link insert
|
|
610
|
-
*/
|
|
611
|
-
async function autoLinkObservationToTask(projectRoot, observationId, accessor) {
|
|
612
|
-
const { sessionStatus } = await import('../sessions/index.js');
|
|
613
|
-
const session = await sessionStatus(projectRoot);
|
|
614
|
-
if (!session)
|
|
615
|
-
return;
|
|
616
|
-
const taskId = session.taskWork?.taskId;
|
|
617
|
-
if (!taskId)
|
|
618
|
-
return;
|
|
619
|
-
await accessor.addLink({
|
|
620
|
-
memoryType: 'observation',
|
|
621
|
-
memoryId: observationId,
|
|
622
|
-
taskId,
|
|
623
|
-
linkType: 'produced_by',
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
/**
|
|
627
|
-
* Backfill embeddings for existing observations that lack them.
|
|
628
|
-
*
|
|
629
|
-
* Iterates through observations not yet in brain_embeddings and
|
|
630
|
-
* generates vectors using the registered embedding provider.
|
|
631
|
-
* Processes in batches to avoid memory pressure.
|
|
632
|
-
*
|
|
633
|
-
* An optional {@link PopulateEmbeddingsOptions.onProgress} callback is called
|
|
634
|
-
* after each observation is attempted, enabling callers to report progress.
|
|
635
|
-
*
|
|
636
|
-
* @param projectRoot - Project root directory
|
|
637
|
-
* @param options - Optional batch size and progress callback
|
|
638
|
-
* @returns Count of processed, skipped, and errored observations
|
|
639
|
-
*
|
|
640
|
-
* @epic T134
|
|
641
|
-
* @task T142
|
|
642
|
-
*/
|
|
643
|
-
export async function populateEmbeddings(projectRoot, options) {
|
|
644
|
-
if (!isEmbeddingAvailable()) {
|
|
645
|
-
return { processed: 0, skipped: 0, errors: 0 };
|
|
646
|
-
}
|
|
647
|
-
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
648
|
-
await getBrainDb(projectRoot);
|
|
649
|
-
const nativeDb = getBrainNativeDb();
|
|
650
|
-
if (!nativeDb) {
|
|
651
|
-
return { processed: 0, skipped: 0, errors: 0 };
|
|
652
|
-
}
|
|
653
|
-
const batchSize = options?.batchSize ?? 50;
|
|
654
|
-
const { onProgress } = options ?? {};
|
|
655
|
-
let processed = 0;
|
|
656
|
-
let skipped = 0;
|
|
657
|
-
let errors = 0;
|
|
658
|
-
// Find observations without embeddings
|
|
659
|
-
const rows = typedAll(nativeDb.prepare(`
|
|
660
|
-
SELECT o.id, o.narrative, o.title
|
|
661
|
-
FROM brain_observations o
|
|
662
|
-
LEFT JOIN brain_embeddings e ON o.id = e.id
|
|
663
|
-
WHERE e.id IS NULL AND o.narrative IS NOT NULL
|
|
664
|
-
ORDER BY o.created_at DESC
|
|
665
|
-
`));
|
|
666
|
-
const total = rows.length;
|
|
667
|
-
let attempted = 0;
|
|
668
|
-
for (let i = 0; i < rows.length; i += batchSize) {
|
|
669
|
-
const batch = rows.slice(i, i + batchSize);
|
|
670
|
-
for (const row of batch) {
|
|
671
|
-
try {
|
|
672
|
-
const vector = await embedText(row.narrative || row.title);
|
|
673
|
-
if (vector) {
|
|
674
|
-
nativeDb
|
|
675
|
-
.prepare('INSERT OR REPLACE INTO brain_embeddings (id, embedding) VALUES (?, ?)')
|
|
676
|
-
.run(row.id, Buffer.from(vector.buffer));
|
|
677
|
-
processed++;
|
|
678
|
-
}
|
|
679
|
-
else {
|
|
680
|
-
skipped++;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
catch {
|
|
684
|
-
errors++;
|
|
685
|
-
}
|
|
686
|
-
attempted++;
|
|
687
|
-
onProgress?.(attempted, total);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
return { processed, skipped, errors };
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* Budget-aware hybrid retrieval combining FTS5, vector KNN, and graph neighbor scores.
|
|
694
|
-
*
|
|
695
|
-
* Strategy (parallel where possible):
|
|
696
|
-
* A. FTS5 BM25 search (always) — keyword precision (50% weight)
|
|
697
|
-
* B. Vector KNN search (optional) — semantic recall (40% weight, skipped if no embeddings)
|
|
698
|
-
* C. Graph neighbors (optional) — associative context (10% weight, skipped if graph empty)
|
|
699
|
-
*
|
|
700
|
-
* Score fusion: final = (fts*0.50 + vec*0.40 + graph*0.10) × qualityScore
|
|
701
|
-
* Recency boost: +0.05 for entries updated in last 7 days.
|
|
702
|
-
* Type priority: procedural entries get +0.10 (always-useful rules).
|
|
703
|
-
*
|
|
704
|
-
* Budget enforcement:
|
|
705
|
-
* - Rank top-50 candidates by fused score.
|
|
706
|
-
* - Walk list, accumulate token cost (≈ textLen/4), stop at budget.
|
|
707
|
-
* - Episodic entries dropped first when budget is tight.
|
|
708
|
-
*
|
|
709
|
-
* Citation tracking: increments citationCount for returned entries in background (setImmediate).
|
|
710
|
-
*
|
|
711
|
-
* @param projectRoot - Project root directory
|
|
712
|
-
* @param query - Text to search for
|
|
713
|
-
* @param tokenBudget - Maximum tokens to spend on results (default 500)
|
|
714
|
-
* @param options - Optional filters (types, tiers, verified)
|
|
715
|
-
* @returns Retrieved entries within budget with token accounting
|
|
716
|
-
*/
|
|
717
|
-
export async function retrieveWithBudget(projectRoot, query, tokenBudget = 500, options) {
|
|
718
|
-
if (!query?.trim()) {
|
|
719
|
-
return { entries: [], tokensUsed: 0, tokensRemaining: tokenBudget, excluded: 0 };
|
|
720
|
-
}
|
|
721
|
-
// -------------------------------------------------------------------------
|
|
722
|
-
// Run search strategies in parallel
|
|
723
|
-
// -------------------------------------------------------------------------
|
|
724
|
-
const [ftsResult, vecResults, graphNeighbors] = await Promise.all([
|
|
725
|
-
// A. FTS5
|
|
726
|
-
searchBrain(projectRoot, query, { limit: 30 }).catch(() => ({
|
|
727
|
-
decisions: [],
|
|
728
|
-
patterns: [],
|
|
729
|
-
learnings: [],
|
|
730
|
-
observations: [],
|
|
731
|
-
})),
|
|
732
|
-
// B. Vector KNN (degrades gracefully when unavailable)
|
|
733
|
-
searchSimilar(query, projectRoot, 20).catch(() => []),
|
|
734
|
-
// C. Graph neighbors from top FTS hit
|
|
735
|
-
Promise.resolve([]),
|
|
736
|
-
]);
|
|
737
|
-
const candidateMap = new Map();
|
|
738
|
-
// FTS results (normalized score 0.5 starting point — BM25 doesn't give 0..1)
|
|
739
|
-
const FTS_BASE = 0.5;
|
|
740
|
-
for (const d of ftsResult.decisions) {
|
|
741
|
-
const raw = d;
|
|
742
|
-
const id = d.id;
|
|
743
|
-
const tier = (d.memoryTier ?? raw['memory_tier']) || undefined;
|
|
744
|
-
const mtype = (d.memoryType ?? raw['memory_type']) || undefined;
|
|
745
|
-
const updatedAt = (d.updatedAt ?? raw['updated_at']) || undefined;
|
|
746
|
-
candidateMap.set(id, {
|
|
747
|
-
id,
|
|
748
|
-
type: 'decision',
|
|
749
|
-
title: d.decision.slice(0, 120),
|
|
750
|
-
text: `${d.decision} — ${d.rationale}`,
|
|
751
|
-
ftsScore: FTS_BASE,
|
|
752
|
-
vecScore: 0,
|
|
753
|
-
graphScore: 0,
|
|
754
|
-
qualityScore: d.qualityScore ?? 0.5,
|
|
755
|
-
memoryTier: tier,
|
|
756
|
-
memoryType: mtype,
|
|
757
|
-
updatedAt,
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
for (const p of ftsResult.patterns) {
|
|
761
|
-
const raw = p;
|
|
762
|
-
const id = p.id;
|
|
763
|
-
const tier = (p.memoryTier ?? raw['memory_tier']) || undefined;
|
|
764
|
-
const mtype = (p.memoryType ?? raw['memory_type']) || undefined;
|
|
765
|
-
const updatedAt = (p.updatedAt ?? raw['updated_at']) || undefined;
|
|
766
|
-
candidateMap.set(id, {
|
|
767
|
-
id,
|
|
768
|
-
type: 'pattern',
|
|
769
|
-
title: p.pattern.slice(0, 120),
|
|
770
|
-
text: `${p.pattern} — ${p.context}`,
|
|
771
|
-
ftsScore: FTS_BASE,
|
|
772
|
-
vecScore: 0,
|
|
773
|
-
graphScore: 0,
|
|
774
|
-
qualityScore: p.qualityScore ?? 0.5,
|
|
775
|
-
memoryTier: tier,
|
|
776
|
-
memoryType: mtype,
|
|
777
|
-
updatedAt,
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
for (const l of ftsResult.learnings) {
|
|
781
|
-
const raw = l;
|
|
782
|
-
const id = l.id;
|
|
783
|
-
const tier = (l.memoryTier ?? raw['memory_tier']) || undefined;
|
|
784
|
-
const mtype = (l.memoryType ?? raw['memory_type']) || undefined;
|
|
785
|
-
const updatedAt = (l.updatedAt ?? raw['updated_at']) || undefined;
|
|
786
|
-
candidateMap.set(id, {
|
|
787
|
-
id,
|
|
788
|
-
type: 'learning',
|
|
789
|
-
title: l.insight.slice(0, 120),
|
|
790
|
-
text: `${l.insight} (source: ${l.source})`,
|
|
791
|
-
ftsScore: FTS_BASE,
|
|
792
|
-
vecScore: 0,
|
|
793
|
-
graphScore: 0,
|
|
794
|
-
qualityScore: l.qualityScore ?? 0.5,
|
|
795
|
-
memoryTier: tier,
|
|
796
|
-
memoryType: mtype,
|
|
797
|
-
updatedAt,
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
for (const o of ftsResult.observations) {
|
|
801
|
-
const raw = o;
|
|
802
|
-
const id = o.id;
|
|
803
|
-
const tier = (o.memoryTier ?? raw['memory_tier']) || undefined;
|
|
804
|
-
const mtype = (o.memoryType ?? raw['memory_type']) || undefined;
|
|
805
|
-
const updatedAt = (o.updatedAt ?? raw['updated_at']) || undefined;
|
|
806
|
-
candidateMap.set(id, {
|
|
807
|
-
id,
|
|
808
|
-
type: 'observation',
|
|
809
|
-
title: o.title.slice(0, 120),
|
|
810
|
-
text: o.narrative ?? o.title,
|
|
811
|
-
ftsScore: FTS_BASE,
|
|
812
|
-
vecScore: 0,
|
|
813
|
-
graphScore: 0,
|
|
814
|
-
qualityScore: o.qualityScore ?? 0.5,
|
|
815
|
-
memoryTier: tier,
|
|
816
|
-
memoryType: mtype,
|
|
817
|
-
updatedAt,
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
// B. Merge vector scores (distance → similarity: similarity = 1 - distance)
|
|
821
|
-
for (const v of vecResults) {
|
|
822
|
-
const simScore = Math.max(0, 1 - v.distance);
|
|
823
|
-
const existing = candidateMap.get(v.id);
|
|
824
|
-
if (existing) {
|
|
825
|
-
existing.vecScore = simScore;
|
|
826
|
-
}
|
|
827
|
-
else {
|
|
828
|
-
candidateMap.set(v.id, {
|
|
829
|
-
id: v.id,
|
|
830
|
-
type: v.type,
|
|
831
|
-
title: v.title.slice(0, 120),
|
|
832
|
-
text: v.text,
|
|
833
|
-
ftsScore: 0,
|
|
834
|
-
vecScore: simScore,
|
|
835
|
-
graphScore: 0,
|
|
836
|
-
qualityScore: 0.5,
|
|
837
|
-
memoryTier: undefined,
|
|
838
|
-
memoryType: undefined,
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
// C. Merge graph scores
|
|
843
|
-
for (const g of graphNeighbors) {
|
|
844
|
-
const existing = candidateMap.get(g.id);
|
|
845
|
-
if (existing) {
|
|
846
|
-
existing.graphScore = g.graphScore;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
// -------------------------------------------------------------------------
|
|
850
|
-
// Score fusion + ranking
|
|
851
|
-
// -------------------------------------------------------------------------
|
|
852
|
-
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
|
|
853
|
-
.toISOString()
|
|
854
|
-
.replace('T', ' ')
|
|
855
|
-
.slice(0, 19);
|
|
856
|
-
const candidates = Array.from(candidateMap.values()).map((c) => {
|
|
857
|
-
// Fused score
|
|
858
|
-
let score = c.ftsScore * 0.5 + c.vecScore * 0.4 + c.graphScore * 0.1;
|
|
859
|
-
// Quality multiplier
|
|
860
|
-
score *= c.qualityScore;
|
|
861
|
-
// Recency boost for recently-updated entries
|
|
862
|
-
if (c.updatedAt && c.updatedAt >= sevenDaysAgo) {
|
|
863
|
-
score += 0.05;
|
|
864
|
-
}
|
|
865
|
-
// Type priority boost for procedural entries (always-useful rules)
|
|
866
|
-
if (c.memoryType === 'procedural' || c.type === 'pattern') {
|
|
867
|
-
score += 0.1;
|
|
868
|
-
}
|
|
869
|
-
return { ...c, score };
|
|
870
|
-
});
|
|
871
|
-
// -------------------------------------------------------------------------
|
|
872
|
-
// Apply option filters (types, tiers, verified)
|
|
873
|
-
// -------------------------------------------------------------------------
|
|
874
|
-
// We'll apply verified filter by checking the DB if requested
|
|
875
|
-
let filtered = candidates;
|
|
876
|
-
if (options?.types && options.types.length > 0) {
|
|
877
|
-
const allowedTypes = new Set(options.types);
|
|
878
|
-
filtered = filtered.filter((c) => {
|
|
879
|
-
if (!c.memoryType)
|
|
880
|
-
return true; // unknown type — include
|
|
881
|
-
return allowedTypes.has(c.memoryType);
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
if (options?.tiers && options.tiers.length > 0) {
|
|
885
|
-
const allowedTiers = new Set(options.tiers);
|
|
886
|
-
filtered = filtered.filter((c) => {
|
|
887
|
-
if (!c.memoryTier)
|
|
888
|
-
return true; // unknown tier — include
|
|
889
|
-
return allowedTiers.has(c.memoryTier);
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
// -------------------------------------------------------------------------
|
|
893
|
-
// Sort: procedural first, then by score descending
|
|
894
|
-
// -------------------------------------------------------------------------
|
|
895
|
-
filtered.sort((a, b) => {
|
|
896
|
-
const aProcedural = a.memoryType === 'procedural' || a.type === 'pattern' ? 1 : 0;
|
|
897
|
-
const bProcedural = b.memoryType === 'procedural' || b.type === 'pattern' ? 1 : 0;
|
|
898
|
-
if (aProcedural !== bProcedural)
|
|
899
|
-
return bProcedural - aProcedural;
|
|
900
|
-
return b.score - a.score;
|
|
901
|
-
});
|
|
902
|
-
// Cap candidate list at top 50
|
|
903
|
-
const topCandidates = filtered.slice(0, 50);
|
|
904
|
-
// -------------------------------------------------------------------------
|
|
905
|
-
// Budget enforcement — episodic entries are dropped first when budget tight
|
|
906
|
-
// -------------------------------------------------------------------------
|
|
907
|
-
// Sort for budget walk: procedural first, semantic second, episodic last
|
|
908
|
-
const typeOrder = (c) => {
|
|
909
|
-
if (c.memoryType === 'procedural' || c.type === 'pattern')
|
|
910
|
-
return 0;
|
|
911
|
-
if (c.memoryType === 'semantic' || c.type === 'decision' || c.type === 'learning')
|
|
912
|
-
return 1;
|
|
913
|
-
return 2; // episodic
|
|
914
|
-
};
|
|
915
|
-
const budgetOrdered = [...topCandidates].sort((a, b) => {
|
|
916
|
-
const orderDiff = typeOrder(a) - typeOrder(b);
|
|
917
|
-
if (orderDiff !== 0)
|
|
918
|
-
return orderDiff;
|
|
919
|
-
return b.score - a.score;
|
|
920
|
-
});
|
|
921
|
-
const result = [];
|
|
922
|
-
let tokensUsed = 0;
|
|
923
|
-
let excluded = 0;
|
|
924
|
-
for (const candidate of budgetOrdered) {
|
|
925
|
-
const entryTokens = Math.ceil(candidate.text.length / 4);
|
|
926
|
-
if (tokensUsed + entryTokens > tokenBudget) {
|
|
927
|
-
excluded++;
|
|
928
|
-
continue;
|
|
929
|
-
}
|
|
930
|
-
result.push({
|
|
931
|
-
id: candidate.id,
|
|
932
|
-
type: candidate.type,
|
|
933
|
-
title: candidate.title,
|
|
934
|
-
text: candidate.text,
|
|
935
|
-
score: candidate.score,
|
|
936
|
-
tokensEstimated: entryTokens,
|
|
937
|
-
memoryTier: candidate.memoryTier,
|
|
938
|
-
memoryType: candidate.memoryType,
|
|
939
|
-
});
|
|
940
|
-
tokensUsed += entryTokens;
|
|
941
|
-
}
|
|
942
|
-
// -------------------------------------------------------------------------
|
|
943
|
-
// Citation tracking — non-blocking background increment
|
|
944
|
-
// -------------------------------------------------------------------------
|
|
945
|
-
if (result.length > 0) {
|
|
946
|
-
const returnedIds = result.map((e) => e.id);
|
|
947
|
-
setImmediate(() => {
|
|
948
|
-
incrementCitationCounts(projectRoot, returnedIds).catch(() => {
|
|
949
|
-
/* best-effort */
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
return {
|
|
954
|
-
entries: result,
|
|
955
|
-
tokensUsed,
|
|
956
|
-
tokensRemaining: tokenBudget - tokensUsed,
|
|
957
|
-
excluded,
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
// ============================================================================
|
|
961
|
-
// Citation Count Increment (non-blocking helper)
|
|
962
|
-
// ============================================================================
|
|
963
|
-
/**
|
|
964
|
-
* Increment citationCount for a list of entry IDs.
|
|
965
|
-
*
|
|
966
|
-
* Routes each ID to the correct table based on its ID prefix. All updates
|
|
967
|
-
* are best-effort — errors are silently swallowed.
|
|
968
|
-
*
|
|
969
|
-
* @param projectRoot - Project root for brain.db resolution
|
|
970
|
-
* @param ids - Entry IDs whose citation counts should be incremented
|
|
971
|
-
*/
|
|
972
|
-
async function incrementCitationCounts(projectRoot, ids) {
|
|
973
|
-
if (ids.length === 0)
|
|
974
|
-
return;
|
|
975
|
-
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
976
|
-
await getBrainDb(projectRoot);
|
|
977
|
-
const nativeDb = getBrainNativeDb();
|
|
978
|
-
if (!nativeDb)
|
|
979
|
-
return;
|
|
980
|
-
const now = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
981
|
-
for (const id of ids) {
|
|
982
|
-
let table;
|
|
983
|
-
if (id.startsWith('D-') || /^D\d/.test(id)) {
|
|
984
|
-
table = 'brain_decisions';
|
|
985
|
-
}
|
|
986
|
-
else if (id.startsWith('P-') || /^P\d/.test(id)) {
|
|
987
|
-
table = 'brain_patterns';
|
|
988
|
-
}
|
|
989
|
-
else if (id.startsWith('L-') || /^L\d/.test(id)) {
|
|
990
|
-
table = 'brain_learnings';
|
|
991
|
-
}
|
|
992
|
-
else {
|
|
993
|
-
table = 'brain_observations';
|
|
994
|
-
}
|
|
995
|
-
try {
|
|
996
|
-
nativeDb
|
|
997
|
-
.prepare(`UPDATE ${table} SET citation_count = citation_count + 1, updated_at = ? WHERE id = ?`)
|
|
998
|
-
.run(now, id);
|
|
999
|
-
}
|
|
1000
|
-
catch {
|
|
1001
|
-
/* best-effort — column may not exist in older schemas */
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
* Log a retrieval event to brain_retrieval_log for co-retrieval analysis.
|
|
1007
|
-
*
|
|
1008
|
-
* Creates the table on first use if it doesn't exist (self-healing).
|
|
1009
|
-
* Best-effort: errors are silently swallowed.
|
|
1010
|
-
*/
|
|
1011
|
-
async function logRetrieval(projectRoot, query, entryIds, source, tokensUsed) {
|
|
1012
|
-
if (entryIds.length === 0)
|
|
1013
|
-
return;
|
|
1014
|
-
const { getBrainDb, getBrainNativeDb } = await import('../store/brain-sqlite.js');
|
|
1015
|
-
await getBrainDb(projectRoot);
|
|
1016
|
-
const nativeDb = getBrainNativeDb();
|
|
1017
|
-
if (!nativeDb)
|
|
1018
|
-
return;
|
|
1019
|
-
// Self-healing: create table if not exists
|
|
1020
|
-
const createSql = 'CREATE TABLE IF NOT EXISTS brain_retrieval_log (' +
|
|
1021
|
-
'id INTEGER PRIMARY KEY AUTOINCREMENT,' +
|
|
1022
|
-
'query TEXT NOT NULL,' +
|
|
1023
|
-
'entry_ids TEXT NOT NULL,' +
|
|
1024
|
-
'entry_count INTEGER NOT NULL,' +
|
|
1025
|
-
'source TEXT NOT NULL,' +
|
|
1026
|
-
'tokens_used INTEGER,' +
|
|
1027
|
-
"created_at TEXT NOT NULL DEFAULT (datetime('now'))" +
|
|
1028
|
-
')';
|
|
1029
|
-
try {
|
|
1030
|
-
nativeDb.prepare(createSql).run();
|
|
1031
|
-
}
|
|
1032
|
-
catch {
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
try {
|
|
1036
|
-
nativeDb
|
|
1037
|
-
.prepare('INSERT INTO brain_retrieval_log (query, entry_ids, entry_count, source, tokens_used) VALUES (?, ?, ?, ?, ?)')
|
|
1038
|
-
.run(query, entryIds.join(','), entryIds.length, source, tokensUsed ?? null);
|
|
1039
|
-
}
|
|
1040
|
-
catch {
|
|
1041
|
-
/* best-effort */
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
//# sourceMappingURL=brain-retrieval.js.map
|