squish-memory 1.2.0 → 1.2.1
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/bin/squish-mcp.mjs +40 -42
- package/core/scheduler/cron-scheduler.ts +10 -1
- package/core/worker.ts +10 -1
- package/package.json +119 -119
- package/packages/mcp/src/index.ts +99 -36
- package/dist/config.d.ts +0 -106
- package/dist/config.js +0 -194
- package/dist/core/adapters/config/claude-code.d.ts +0 -45
- package/dist/core/adapters/config/claude-code.js +0 -113
- package/dist/core/adapters/config/cursor.d.ts +0 -26
- package/dist/core/adapters/config/cursor.js +0 -74
- package/dist/core/adapters/config/opencode.d.ts +0 -23
- package/dist/core/adapters/config/opencode.js +0 -73
- package/dist/core/adapters/config/windsurf.d.ts +0 -26
- package/dist/core/adapters/config/windsurf.js +0 -74
- package/dist/core/adapters/index.d.ts +0 -45
- package/dist/core/adapters/index.js +0 -84
- package/dist/core/adapters/scripts/install-adapter.d.ts +0 -19
- package/dist/core/adapters/scripts/install-adapter.js +0 -149
- package/dist/core/adapters/timeline.d.ts +0 -23
- package/dist/core/adapters/timeline.js +0 -88
- package/dist/core/adapters/types.d.ts +0 -137
- package/dist/core/adapters/types.js +0 -50
- package/dist/core/agent-preferences.d.ts +0 -16
- package/dist/core/agent-preferences.js +0 -124
- package/dist/core/algorithms/analytics/token-estimator.d.ts +0 -50
- package/dist/core/algorithms/analytics/token-estimator.js +0 -154
- package/dist/core/algorithms/detection/hash-filters.d.ts +0 -47
- package/dist/core/algorithms/detection/hash-filters.js +0 -190
- package/dist/core/algorithms/detection/semantic-ranker.d.ts +0 -32
- package/dist/core/algorithms/detection/semantic-ranker.js +0 -118
- package/dist/core/algorithms/detection/two-stage-detector.d.ts +0 -52
- package/dist/core/algorithms/detection/two-stage-detector.js +0 -299
- package/dist/core/algorithms/handlers/approve-merge.d.ts +0 -22
- package/dist/core/algorithms/handlers/approve-merge.js +0 -179
- package/dist/core/algorithms/handlers/detect-duplicates.d.ts +0 -47
- package/dist/core/algorithms/handlers/detect-duplicates.js +0 -145
- package/dist/core/algorithms/handlers/get-stats.d.ts +0 -39
- package/dist/core/algorithms/handlers/get-stats.js +0 -88
- package/dist/core/algorithms/handlers/list-proposals.d.ts +0 -45
- package/dist/core/algorithms/handlers/list-proposals.js +0 -83
- package/dist/core/algorithms/handlers/preview-merge.d.ts +0 -39
- package/dist/core/algorithms/handlers/preview-merge.js +0 -93
- package/dist/core/algorithms/handlers/reject-merge.d.ts +0 -28
- package/dist/core/algorithms/handlers/reject-merge.js +0 -69
- package/dist/core/algorithms/handlers/reverse-merge.d.ts +0 -21
- package/dist/core/algorithms/handlers/reverse-merge.js +0 -121
- package/dist/core/algorithms/index.d.ts +0 -21
- package/dist/core/algorithms/index.js +0 -26
- package/dist/core/algorithms/operations/cache-maintenance.d.ts +0 -12
- package/dist/core/algorithms/operations/cache-maintenance.js +0 -157
- package/dist/core/algorithms/safety/safety-checks.d.ts +0 -18
- package/dist/core/algorithms/safety/safety-checks.js +0 -179
- package/dist/core/algorithms/strategies/merge-strategies.d.ts +0 -50
- package/dist/core/algorithms/strategies/merge-strategies.js +0 -288
- package/dist/core/algorithms/types.d.ts +0 -125
- package/dist/core/algorithms/types.js +0 -5
- package/dist/core/algorithms/utils/response-builder.d.ts +0 -28
- package/dist/core/algorithms/utils/response-builder.js +0 -37
- package/dist/core/associations.d.ts +0 -33
- package/dist/core/associations.js +0 -284
- package/dist/core/autosave.d.ts +0 -19
- package/dist/core/autosave.js +0 -16
- package/dist/core/beliefs/decay.d.ts +0 -27
- package/dist/core/beliefs/decay.js +0 -217
- package/dist/core/beliefs/extractor.d.ts +0 -9
- package/dist/core/beliefs/extractor.js +0 -113
- package/dist/core/beliefs/store.d.ts +0 -46
- package/dist/core/beliefs/store.js +0 -466
- package/dist/core/beliefs/types.d.ts +0 -28
- package/dist/core/beliefs/types.js +0 -2
- package/dist/core/commands/mcp-server.d.ts +0 -2
- package/dist/core/commands/mcp-server.js +0 -6
- package/dist/core/commands/remember.d.ts +0 -24
- package/dist/core/commands/remember.js +0 -144
- package/dist/core/compression.d.ts +0 -45
- package/dist/core/compression.js +0 -160
- package/dist/core/consolidation.d.ts +0 -37
- package/dist/core/consolidation.js +0 -248
- package/dist/core/context/agent-context.d.ts +0 -106
- package/dist/core/context/agent-context.js +0 -274
- package/dist/core/context/context-paging.d.ts +0 -80
- package/dist/core/context/context-paging.js +0 -328
- package/dist/core/context/context-window.d.ts +0 -40
- package/dist/core/context/context-window.js +0 -177
- package/dist/core/context/context.d.ts +0 -7
- package/dist/core/context/context.js +0 -22
- package/dist/core/embeddings/embeddings.d.ts +0 -29
- package/dist/core/embeddings/embeddings.js +0 -546
- package/dist/core/embeddings/google-multimodal.d.ts +0 -14
- package/dist/core/embeddings/google-multimodal.js +0 -146
- package/dist/core/embeddings/local-embeddings.d.ts +0 -11
- package/dist/core/embeddings/local-embeddings.js +0 -11
- package/dist/core/embeddings/qmd-client.d.ts +0 -136
- package/dist/core/embeddings/qmd-client.js +0 -403
- package/dist/core/embeddings/transformers-local.d.ts +0 -64
- package/dist/core/embeddings/transformers-local.js +0 -213
- package/dist/core/embeddings.d.ts +0 -2
- package/dist/core/embeddings.js +0 -3
- package/dist/core/error-handling.d.ts +0 -63
- package/dist/core/error-handling.js +0 -173
- package/dist/core/graph/entity-deduplicator.d.ts +0 -24
- package/dist/core/graph/entity-deduplicator.js +0 -183
- package/dist/core/graph/graph-builder.d.ts +0 -46
- package/dist/core/graph/graph-builder.js +0 -174
- package/dist/core/graph/graph-traversal.d.ts +0 -80
- package/dist/core/graph/graph-traversal.js +0 -315
- package/dist/core/graph/index.d.ts +0 -19
- package/dist/core/graph/index.js +0 -13
- package/dist/core/graph/llm-entity-extractor.d.ts +0 -49
- package/dist/core/graph/llm-entity-extractor.js +0 -313
- package/dist/core/graph/multi-hop-retrieval.d.ts +0 -48
- package/dist/core/graph/multi-hop-retrieval.js +0 -215
- package/dist/core/graph/relationship-extractor.d.ts +0 -48
- package/dist/core/graph/relationship-extractor.js +0 -351
- package/dist/core/hooks/agent-hooks.d.ts +0 -83
- package/dist/core/hooks/agent-hooks.js +0 -521
- package/dist/core/hooks/auto-tagger.d.ts +0 -19
- package/dist/core/hooks/auto-tagger.js +0 -155
- package/dist/core/hooks/capture-filter.d.ts +0 -41
- package/dist/core/hooks/capture-filter.js +0 -128
- package/dist/core/hot-cache.d.ts +0 -86
- package/dist/core/hot-cache.js +0 -285
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -11
- package/dist/core/ingestion/agent-memory.d.ts +0 -22
- package/dist/core/ingestion/agent-memory.js +0 -109
- package/dist/core/ingestion/core-memory.d.ts +0 -78
- package/dist/core/ingestion/core-memory.js +0 -226
- package/dist/core/ingestion/learnings.d.ts +0 -57
- package/dist/core/ingestion/learnings.js +0 -205
- package/dist/core/ingestion/signal-engine.d.ts +0 -41
- package/dist/core/ingestion/signal-engine.js +0 -201
- package/dist/core/integrations/obsidian-vault.d.ts +0 -31
- package/dist/core/integrations/obsidian-vault.js +0 -156
- package/dist/core/layers/generator.d.ts +0 -25
- package/dist/core/layers/generator.js +0 -76
- package/dist/core/lib/db-client.d.ts +0 -114
- package/dist/core/lib/db-client.js +0 -130
- package/dist/core/lib/parse-embedding.d.ts +0 -9
- package/dist/core/lib/parse-embedding.js +0 -58
- package/dist/core/lib/schemas.d.ts +0 -132
- package/dist/core/lib/schemas.js +0 -87
- package/dist/core/lib/types.d.ts +0 -45
- package/dist/core/lib/types.js +0 -6
- package/dist/core/lib/utils.d.ts +0 -18
- package/dist/core/lib/utils.js +0 -145
- package/dist/core/lib/validation.d.ts +0 -38
- package/dist/core/lib/validation.js +0 -151
- package/dist/core/lifecycle.d.ts +0 -25
- package/dist/core/lifecycle.js +0 -292
- package/dist/core/logger.d.ts +0 -17
- package/dist/core/logger.js +0 -46
- package/dist/core/mcp/client.d.ts +0 -17
- package/dist/core/mcp/client.js +0 -101
- package/dist/core/mcp/index.d.ts +0 -6
- package/dist/core/mcp/index.js +0 -6
- package/dist/core/mcp/server.d.ts +0 -18
- package/dist/core/mcp/server.js +0 -157
- package/dist/core/mcp/standalone-server.d.ts +0 -13
- package/dist/core/mcp/standalone-server.js +0 -46
- package/dist/core/mcp/tools.d.ts +0 -7
- package/dist/core/mcp/tools.js +0 -278
- package/dist/core/mcp/types.d.ts +0 -87
- package/dist/core/mcp/types.js +0 -48
- package/dist/core/memory/bridge-discovery.d.ts +0 -50
- package/dist/core/memory/bridge-discovery.js +0 -291
- package/dist/core/memory/categorizer.d.ts +0 -27
- package/dist/core/memory/categorizer.js +0 -306
- package/dist/core/memory/conflict-detector.d.ts +0 -7
- package/dist/core/memory/conflict-detector.js +0 -43
- package/dist/core/memory/consolidation.d.ts +0 -42
- package/dist/core/memory/consolidation.js +0 -277
- package/dist/core/memory/context-collector.d.ts +0 -10
- package/dist/core/memory/context-collector.js +0 -56
- package/dist/core/memory/contradiction-resolver.d.ts +0 -40
- package/dist/core/memory/contradiction-resolver.js +0 -368
- package/dist/core/memory/edit-workflow.d.ts +0 -19
- package/dist/core/memory/edit-workflow.js +0 -120
- package/dist/core/memory/entity-extractor.d.ts +0 -37
- package/dist/core/memory/entity-extractor.js +0 -350
- package/dist/core/memory/entity-resolver.d.ts +0 -23
- package/dist/core/memory/entity-resolver.js +0 -64
- package/dist/core/memory/explain.d.ts +0 -18
- package/dist/core/memory/explain.js +0 -92
- package/dist/core/memory/fact-deriver.d.ts +0 -31
- package/dist/core/memory/fact-deriver.js +0 -236
- package/dist/core/memory/fact-extractor.d.ts +0 -24
- package/dist/core/memory/fact-extractor.js +0 -89
- package/dist/core/memory/feedback-tracker.d.ts +0 -12
- package/dist/core/memory/feedback-tracker.js +0 -155
- package/dist/core/memory/hooks.d.ts +0 -88
- package/dist/core/memory/hooks.js +0 -174
- package/dist/core/memory/hybrid-retrieval.d.ts +0 -27
- package/dist/core/memory/hybrid-retrieval.js +0 -37
- package/dist/core/memory/hybrid-scorer.d.ts +0 -40
- package/dist/core/memory/hybrid-scorer.js +0 -267
- package/dist/core/memory/hybrid-search.d.ts +0 -23
- package/dist/core/memory/hybrid-search.js +0 -596
- package/dist/core/memory/importance.d.ts +0 -46
- package/dist/core/memory/importance.js +0 -241
- package/dist/core/memory/index.d.ts +0 -9
- package/dist/core/memory/index.js +0 -11
- package/dist/core/memory/loader.d.ts +0 -31
- package/dist/core/memory/loader.js +0 -141
- package/dist/core/memory/markdown/markdown-storage.d.ts +0 -72
- package/dist/core/memory/markdown/markdown-storage.js +0 -243
- package/dist/core/memory/memories.d.ts +0 -43
- package/dist/core/memory/memories.js +0 -452
- package/dist/core/memory/memory-lifecycle.d.ts +0 -8
- package/dist/core/memory/memory-lifecycle.js +0 -47
- package/dist/core/memory/memory-manager.d.ts +0 -15
- package/dist/core/memory/memory-manager.js +0 -46
- package/dist/core/memory/migrate.d.ts +0 -21
- package/dist/core/memory/migrate.js +0 -134
- package/dist/core/memory/normalization.d.ts +0 -7
- package/dist/core/memory/normalization.js +0 -26
- package/dist/core/memory/path-strengthener.d.ts +0 -39
- package/dist/core/memory/path-strengthener.js +0 -150
- package/dist/core/memory/progressive-disclosure.d.ts +0 -43
- package/dist/core/memory/progressive-disclosure.js +0 -280
- package/dist/core/memory/query-processor.d.ts +0 -21
- package/dist/core/memory/query-processor.js +0 -106
- package/dist/core/memory/query-rewriter.d.ts +0 -13
- package/dist/core/memory/query-rewriter.js +0 -118
- package/dist/core/memory/response-analyzer.d.ts +0 -9
- package/dist/core/memory/response-analyzer.js +0 -61
- package/dist/core/memory/retrieval-feedback.d.ts +0 -70
- package/dist/core/memory/retrieval-feedback.js +0 -213
- package/dist/core/memory/serialization.d.ts +0 -10
- package/dist/core/memory/serialization.js +0 -84
- package/dist/core/memory/stale-cleaner.d.ts +0 -26
- package/dist/core/memory/stale-cleaner.js +0 -97
- package/dist/core/memory/stats.d.ts +0 -32
- package/dist/core/memory/stats.js +0 -143
- package/dist/core/memory/telemetry.d.ts +0 -69
- package/dist/core/memory/telemetry.js +0 -313
- package/dist/core/memory/temporal-facts.d.ts +0 -41
- package/dist/core/memory/temporal-facts.js +0 -283
- package/dist/core/memory/temporal-parser.d.ts +0 -32
- package/dist/core/memory/temporal-parser.js +0 -385
- package/dist/core/memory/trigger-detector.d.ts +0 -21
- package/dist/core/memory/trigger-detector.js +0 -79
- package/dist/core/memory/write-gate.d.ts +0 -54
- package/dist/core/memory/write-gate.js +0 -210
- package/dist/core/places/index.d.ts +0 -14
- package/dist/core/places/index.js +0 -14
- package/dist/core/places/memory-places.d.ts +0 -68
- package/dist/core/places/memory-places.js +0 -261
- package/dist/core/places/places.d.ts +0 -88
- package/dist/core/places/places.js +0 -314
- package/dist/core/places/rules.d.ts +0 -74
- package/dist/core/places/rules.js +0 -240
- package/dist/core/places/walking.d.ts +0 -56
- package/dist/core/places/walking.js +0 -121
- package/dist/core/projects.d.ts +0 -17
- package/dist/core/projects.js +0 -116
- package/dist/core/redis.d.ts +0 -11
- package/dist/core/redis.js +0 -69
- package/dist/core/responses.d.ts +0 -96
- package/dist/core/responses.js +0 -122
- package/dist/core/runtime/trust-report.d.ts +0 -102
- package/dist/core/runtime/trust-report.js +0 -107
- package/dist/core/runtime/trust-state.d.ts +0 -12
- package/dist/core/runtime/trust-state.js +0 -309
- package/dist/core/scheduler/cron-scheduler.d.ts +0 -32
- package/dist/core/scheduler/cron-scheduler.js +0 -493
- package/dist/core/scheduler/heartbeat.d.ts +0 -11
- package/dist/core/scheduler/heartbeat.js +0 -73
- package/dist/core/scheduler/index.d.ts +0 -8
- package/dist/core/scheduler/index.js +0 -8
- package/dist/core/scheduler/job-runner.d.ts +0 -11
- package/dist/core/scheduler/job-runner.js +0 -164
- package/dist/core/search/conversations.d.ts +0 -25
- package/dist/core/search/conversations.js +0 -110
- package/dist/core/search/entities.d.ts +0 -12
- package/dist/core/search/entities.js +0 -31
- package/dist/core/search/folder-context.d.ts +0 -25
- package/dist/core/search/folder-context.js +0 -119
- package/dist/core/search/graph-boost.d.ts +0 -7
- package/dist/core/search/graph-boost.js +0 -23
- package/dist/core/search/index.d.ts +0 -4
- package/dist/core/search/index.js +0 -5
- package/dist/core/search/qmd-wrapper.d.ts +0 -36
- package/dist/core/search/qmd-wrapper.js +0 -58
- package/dist/core/security/encrypt.d.ts +0 -6
- package/dist/core/security/encrypt.js +0 -47
- package/dist/core/security/governance.d.ts +0 -26
- package/dist/core/security/governance.js +0 -79
- package/dist/core/security/privacy.d.ts +0 -23
- package/dist/core/security/privacy.js +0 -82
- package/dist/core/security/secret-detector.d.ts +0 -32
- package/dist/core/security/secret-detector.js +0 -88
- package/dist/core/session/auto-load.d.ts +0 -6
- package/dist/core/session/auto-load.js +0 -144
- package/dist/core/session/entity-tracker.d.ts +0 -62
- package/dist/core/session/entity-tracker.js +0 -287
- package/dist/core/session/index.d.ts +0 -7
- package/dist/core/session/index.js +0 -7
- package/dist/core/session/reference-resolver.d.ts +0 -26
- package/dist/core/session/reference-resolver.js +0 -121
- package/dist/core/session/self-iteration-job.d.ts +0 -35
- package/dist/core/session/self-iteration-job.js +0 -387
- package/dist/core/session/session-hooks.d.ts +0 -18
- package/dist/core/session/session-hooks.js +0 -58
- package/dist/core/session/types.d.ts +0 -26
- package/dist/core/session/types.js +0 -10
- package/dist/core/session/working-set.d.ts +0 -50
- package/dist/core/session/working-set.js +0 -212
- package/dist/core/snapshots/cleanup.d.ts +0 -9
- package/dist/core/snapshots/cleanup.js +0 -12
- package/dist/core/snapshots/comparison.d.ts +0 -19
- package/dist/core/snapshots/comparison.js +0 -43
- package/dist/core/snapshots/creation.d.ts +0 -13
- package/dist/core/snapshots/creation.js +0 -117
- package/dist/core/snapshots/retrieval.d.ts +0 -7
- package/dist/core/snapshots/retrieval.js +0 -41
- package/dist/core/snapshots/stats.d.ts +0 -11
- package/dist/core/snapshots/stats.js +0 -52
- package/dist/core/storage/cache.d.ts +0 -13
- package/dist/core/storage/cache.js +0 -202
- package/dist/core/storage/database.d.ts +0 -12
- package/dist/core/storage/database.js +0 -12
- package/dist/core/summarization/cleanup.d.ts +0 -9
- package/dist/core/summarization/cleanup.js +0 -12
- package/dist/core/summarization/queries.d.ts +0 -9
- package/dist/core/summarization/queries.js +0 -28
- package/dist/core/summarization/stats.d.ts +0 -14
- package/dist/core/summarization/stats.js +0 -52
- package/dist/core/summarization/strategies.d.ts +0 -24
- package/dist/core/summarization/strategies.js +0 -28
- package/dist/core/summarization.d.ts +0 -37
- package/dist/core/summarization.js +0 -188
- package/dist/core/temporal-facts.d.ts +0 -54
- package/dist/core/temporal-facts.js +0 -193
- package/dist/core/tracing/collector.d.ts +0 -111
- package/dist/core/tracing/collector.js +0 -350
- package/dist/core/tracing/visualizer.d.ts +0 -32
- package/dist/core/tracing/visualizer.js +0 -165
- package/dist/core/utils/cleanup-operations.d.ts +0 -13
- package/dist/core/utils/cleanup-operations.js +0 -44
- package/dist/core/utils/content-extraction.d.ts +0 -19
- package/dist/core/utils/content-extraction.js +0 -75
- package/dist/core/utils/filter-builder.d.ts +0 -13
- package/dist/core/utils/filter-builder.js +0 -44
- package/dist/core/utils/history-traversal.d.ts +0 -13
- package/dist/core/utils/history-traversal.js +0 -50
- package/dist/core/utils/memory-operations.d.ts +0 -17
- package/dist/core/utils/memory-operations.js +0 -43
- package/dist/core/utils/query-operations.d.ts +0 -18
- package/dist/core/utils/query-operations.js +0 -65
- package/dist/core/utils/summarization-helpers.d.ts +0 -17
- package/dist/core/utils/summarization-helpers.js +0 -33
- package/dist/core/utils/temporal-queries.d.ts +0 -13
- package/dist/core/utils/temporal-queries.js +0 -27
- package/dist/core/utils/vector-operations.d.ts +0 -71
- package/dist/core/utils/vector-operations.js +0 -129
- package/dist/core/utils/version-management.d.ts +0 -9
- package/dist/core/utils/version-management.js +0 -61
- package/dist/core/worker.d.ts +0 -82
- package/dist/core/worker.js +0 -272
- package/dist/db/adapter.d.ts +0 -7
- package/dist/db/adapter.js +0 -175
- package/dist/db/bootstrap.d.ts +0 -11
- package/dist/db/bootstrap.js +0 -1034
- package/dist/db/drizzle/schema-sqlite.d.ts +0 -5538
- package/dist/db/drizzle/schema-sqlite.js +0 -763
- package/dist/db/drizzle/schema.d.ts +0 -4734
- package/dist/db/drizzle/schema.js +0 -859
- package/dist/db/drizzle.config.d.ts +0 -3
- package/dist/db/drizzle.config.js +0 -12
- package/dist/db/index.d.ts +0 -7
- package/dist/db/index.js +0 -89
- package/dist/db/migrations/associations.d.ts +0 -6
- package/dist/db/migrations/associations.js +0 -29
- package/dist/db/migrations/beliefs.d.ts +0 -10
- package/dist/db/migrations/beliefs.js +0 -76
- package/dist/db/migrations/core-memory.d.ts +0 -6
- package/dist/db/migrations/core-memory.js +0 -29
- package/dist/db/migrations/fts.d.ts +0 -6
- package/dist/db/migrations/fts.js +0 -52
- package/dist/db/migrations/index.d.ts +0 -25
- package/dist/db/migrations/index.js +0 -51
- package/dist/db/migrations/indexes.d.ts +0 -6
- package/dist/db/migrations/indexes.js +0 -30
- package/dist/db/migrations/learnings.d.ts +0 -7
- package/dist/db/migrations/learnings.js +0 -26
- package/dist/db/migrations/maintenance.d.ts +0 -6
- package/dist/db/migrations/maintenance.js +0 -61
- package/dist/db/migrations/memories.d.ts +0 -7
- package/dist/db/migrations/memories.js +0 -16
- package/dist/db/migrations/memory-places.d.ts +0 -6
- package/dist/db/migrations/memory-places.js +0 -29
- package/dist/db/migrations/places.d.ts +0 -6
- package/dist/db/migrations/places.js +0 -43
- package/dist/db/migrations/projects.d.ts +0 -3
- package/dist/db/migrations/projects.js +0 -13
- package/dist/db/migrations/tier-conversion.d.ts +0 -7
- package/dist/db/migrations/tier-conversion.js +0 -20
- package/dist/db/neon.d.ts +0 -8
- package/dist/db/neon.js +0 -20
- package/dist/db/schema/beliefs.d.ts +0 -9
- package/dist/db/schema/beliefs.js +0 -46
- package/dist/db/schema/generator.d.ts +0 -38
- package/dist/db/schema/generator.js +0 -108
- package/dist/db/schema/index.d.ts +0 -39
- package/dist/db/schema/index.js +0 -51
- package/dist/db/schema/learnings.d.ts +0 -7
- package/dist/db/schema/learnings.js +0 -30
- package/dist/db/schema/memories.d.ts +0 -7
- package/dist/db/schema/memories.js +0 -81
- package/dist/db/schema/projects.d.ts +0 -4
- package/dist/db/schema/projects.js +0 -31
- package/dist/db/schema/tables/context-sessions.d.ts +0 -9
- package/dist/db/schema/tables/context-sessions.js +0 -37
- package/dist/db/schema/tables/conversations.d.ts +0 -9
- package/dist/db/schema/tables/conversations.js +0 -47
- package/dist/db/schema/tables/core-memory.d.ts +0 -9
- package/dist/db/schema/tables/core-memory.js +0 -41
- package/dist/db/schema/tables/entities.d.ts +0 -9
- package/dist/db/schema/tables/entities.js +0 -39
- package/dist/db/schema/tables/entity-relations.d.ts +0 -9
- package/dist/db/schema/tables/entity-relations.js +0 -31
- package/dist/db/schema/tables/learnings.d.ts +0 -9
- package/dist/db/schema/tables/learnings.js +0 -66
- package/dist/db/schema/tables/memories.d.ts +0 -9
- package/dist/db/schema/tables/memories.js +0 -161
- package/dist/db/schema/tables/memory-associations.d.ts +0 -9
- package/dist/db/schema/tables/memory-associations.js +0 -39
- package/dist/db/schema/tables/memory-hash-cache.d.ts +0 -9
- package/dist/db/schema/tables/memory-hash-cache.js +0 -29
- package/dist/db/schema/tables/memory-merge-history.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-history.js +0 -33
- package/dist/db/schema/tables/memory-merge-proposals.d.ts +0 -9
- package/dist/db/schema/tables/memory-merge-proposals.js +0 -39
- package/dist/db/schema/tables/messages.d.ts +0 -9
- package/dist/db/schema/tables/messages.js +0 -41
- package/dist/db/schema/tables/namespaces.d.ts +0 -9
- package/dist/db/schema/tables/namespaces.js +0 -37
- package/dist/db/schema/tables/projects.d.ts +0 -9
- package/dist/db/schema/tables/projects.js +0 -31
- package/dist/db/schema/tables/users.d.ts +0 -9
- package/dist/db/schema/tables/users.js +0 -27
- package/dist/db/schema.d.ts +0 -3
- package/dist/db/schema.js +0 -11
- package/dist/db/supabase.d.ts +0 -9
- package/dist/db/supabase.js +0 -24
- package/dist/packages/mcp/src/index.d.ts +0 -3
- package/dist/packages/mcp/src/index.js +0 -733
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory Association Graph (Waypoint Graph)
|
|
3
|
-
* Tracks co-occurrence and relationships between memories
|
|
4
|
-
*/
|
|
5
|
-
import { eq, and, or, desc, inArray, sql } from 'drizzle-orm';
|
|
6
|
-
import { getDb } from '../db/index.js';
|
|
7
|
-
import { getSchema } from '../db/schema.js';
|
|
8
|
-
import { logger } from './logger.js';
|
|
9
|
-
/**
|
|
10
|
-
* Create or update an association between two memories
|
|
11
|
-
*/
|
|
12
|
-
export async function createAssociation(fromMemoryId, toMemoryId, type, weight = 1) {
|
|
13
|
-
try {
|
|
14
|
-
const db = await getDb();
|
|
15
|
-
const schema = await getSchema();
|
|
16
|
-
// Check if association already exists
|
|
17
|
-
const existing = await db
|
|
18
|
-
.select()
|
|
19
|
-
.from(schema.memoryAssociations)
|
|
20
|
-
.where(and(eq(schema.memoryAssociations.fromMemoryId, fromMemoryId), eq(schema.memoryAssociations.toMemoryId, toMemoryId)))
|
|
21
|
-
.limit(1);
|
|
22
|
-
if (existing.length > 0) {
|
|
23
|
-
// Update weight and coactivation count
|
|
24
|
-
await db
|
|
25
|
-
.update(schema.memoryAssociations)
|
|
26
|
-
.set({
|
|
27
|
-
weight: existing[0].weight + weight,
|
|
28
|
-
coactivationCount: existing[0].coactivationCount + 1,
|
|
29
|
-
lastCoactivatedAt: new Date(),
|
|
30
|
-
})
|
|
31
|
-
.where(eq(schema.memoryAssociations.id, existing[0].id));
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
// Create new association
|
|
35
|
-
await db.insert(schema.memoryAssociations).values({
|
|
36
|
-
fromMemoryId,
|
|
37
|
-
toMemoryId,
|
|
38
|
-
associationType: type,
|
|
39
|
-
weight,
|
|
40
|
-
coactivationCount: 1,
|
|
41
|
-
lastCoactivatedAt: new Date(),
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
logger.error('Error creating association', error);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Auto-link memories that share entities
|
|
51
|
-
* Called after storing a memory to link it to related memories
|
|
52
|
-
*/
|
|
53
|
-
export async function autoLinkByEntities(newMemoryId, entityNames, projectId) {
|
|
54
|
-
if (entityNames.length === 0)
|
|
55
|
-
return 0;
|
|
56
|
-
try {
|
|
57
|
-
const db = await getDb();
|
|
58
|
-
const schema = await getSchema();
|
|
59
|
-
// Find existing memories that contain any of these entity names
|
|
60
|
-
// Use simple LIKE query for matching
|
|
61
|
-
const conditions = entityNames.slice(0, 5).map(name => sql `LOWER(m.content) LIKE ${'%' + name + '%'}`);
|
|
62
|
-
const existing = await db
|
|
63
|
-
.select({
|
|
64
|
-
id: schema.memories.id,
|
|
65
|
-
content: schema.memories.content
|
|
66
|
-
})
|
|
67
|
-
.from(schema.memories)
|
|
68
|
-
.where(and(eq(schema.memories.projectId, projectId), sql `(${conditions.join(' OR ')})`, sql `id != ${newMemoryId}`))
|
|
69
|
-
.limit(10);
|
|
70
|
-
// Create associations for matching memories
|
|
71
|
-
let linked = 0;
|
|
72
|
-
for (const mem of existing) {
|
|
73
|
-
try {
|
|
74
|
-
await createAssociation(newMemoryId, mem.id, 'relates_to', 0.5);
|
|
75
|
-
linked++;
|
|
76
|
-
}
|
|
77
|
-
catch (e) {
|
|
78
|
-
// Skip duplicates
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return linked;
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
logger.error('Error auto-linking by entities', error);
|
|
85
|
-
return 0;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export async function trackCoactivation(memoryIds) {
|
|
89
|
-
if (memoryIds.length < 2)
|
|
90
|
-
return;
|
|
91
|
-
try {
|
|
92
|
-
const db = await getDb();
|
|
93
|
-
const schema = await getSchema();
|
|
94
|
-
const now = new Date();
|
|
95
|
-
// Generate all pairs
|
|
96
|
-
const pairs = [];
|
|
97
|
-
for (let i = 0; i < memoryIds.length; i++) {
|
|
98
|
-
for (let j = i + 1; j < memoryIds.length; j++) {
|
|
99
|
-
pairs.push({ from: memoryIds[i], to: memoryIds[j] });
|
|
100
|
-
pairs.push({ from: memoryIds[j], to: memoryIds[i] }); // Bidirectional
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (pairs.length === 0)
|
|
104
|
-
return;
|
|
105
|
-
// Batch check existing associations with single SELECT
|
|
106
|
-
const pairIds = pairs.map(p => ({ from: p.from, to: p.to }));
|
|
107
|
-
// Check which pairs already exist
|
|
108
|
-
const existingPairs = await db
|
|
109
|
-
.select({ fromId: schema.memoryAssociations.fromMemoryId, toId: schema.memoryAssociations.toMemoryId })
|
|
110
|
-
.from(schema.memoryAssociations)
|
|
111
|
-
.where(or(...pairIds.map((p) => and(eq(schema.memoryAssociations.fromMemoryId, p.from), eq(schema.memoryAssociations.toMemoryId, p.to)))));
|
|
112
|
-
const existingMap = new Set(existingPairs.map((p) => `${p.fromId}:${p.toId}`));
|
|
113
|
-
// Separate into new pairs and existing pairs
|
|
114
|
-
const newPairs = [];
|
|
115
|
-
const existingPairsToUpdate = [];
|
|
116
|
-
for (const pair of pairs) {
|
|
117
|
-
const key = `${pair.from}:${pair.to}`;
|
|
118
|
-
if (existingMap.has(key)) {
|
|
119
|
-
existingPairsToUpdate.push(key);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
newPairs.push({
|
|
123
|
-
fromMemoryId: pair.from,
|
|
124
|
-
toMemoryId: pair.to,
|
|
125
|
-
associationType: 'co_occurred',
|
|
126
|
-
weight: 1,
|
|
127
|
-
coactivationCount: 1,
|
|
128
|
-
lastCoactivatedAt: now,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Bulk insert new associations
|
|
133
|
-
if (newPairs.length > 0) {
|
|
134
|
-
const BATCH_SIZE = 100;
|
|
135
|
-
for (let i = 0; i < newPairs.length; i += BATCH_SIZE) {
|
|
136
|
-
const batch = newPairs.slice(i, i + BATCH_SIZE);
|
|
137
|
-
try {
|
|
138
|
-
// For PostgreSQL with ON CONFLICT support
|
|
139
|
-
if (db.insert && db.onConflict) {
|
|
140
|
-
await db
|
|
141
|
-
.insert(schema.memoryAssociations)
|
|
142
|
-
.values(batch)
|
|
143
|
-
.onConflict({
|
|
144
|
-
target: [schema.memoryAssociations.fromMemoryId, schema.memoryAssociations.toMemoryId],
|
|
145
|
-
set: {
|
|
146
|
-
weight: sql.raw('EXCLUDED.weight'),
|
|
147
|
-
coactivationCount: sql.raw('EXCLUDED.coactivation_count'),
|
|
148
|
-
lastCoactivatedAt: now,
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
.catch(() => {
|
|
152
|
-
// Fallback for SQLite
|
|
153
|
-
return db.insert(schema.memoryAssociations).values(batch);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Direct insert for SQLite
|
|
158
|
-
await db.insert(schema.memoryAssociations).values(batch);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
logger.error('Error inserting batch of associations', { batchSize: batch.length, error });
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Bulk update existing associations
|
|
167
|
-
if (existingPairsToUpdate.length > 0) {
|
|
168
|
-
const BATCH_SIZE = 100;
|
|
169
|
-
for (let i = 0; i < existingPairsToUpdate.length; i += BATCH_SIZE) {
|
|
170
|
-
const batch = existingPairsToUpdate.slice(i, i + BATCH_SIZE);
|
|
171
|
-
// Extract from/to pairs for this batch
|
|
172
|
-
const batchPairs = batch.map(key => {
|
|
173
|
-
const [from, to] = key.split(':');
|
|
174
|
-
return { from, to };
|
|
175
|
-
});
|
|
176
|
-
try {
|
|
177
|
-
for (const pair of batchPairs) {
|
|
178
|
-
await db
|
|
179
|
-
.update(schema.memoryAssociations)
|
|
180
|
-
.set({
|
|
181
|
-
weight: sql `${schema.memoryAssociations.weight} + 1`,
|
|
182
|
-
coactivationCount: sql `${schema.memoryAssociations.coactivationCount} + 1`,
|
|
183
|
-
lastCoactivatedAt: now,
|
|
184
|
-
})
|
|
185
|
-
.where(and(eq(schema.memoryAssociations.fromMemoryId, pair.from), eq(schema.memoryAssociations.toMemoryId, pair.to)));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
logger.error('Error updating batch of associations', { batchSize: batch.length, error });
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
logger.debug('Coactivation tracked', {
|
|
194
|
-
totalPairs: pairs.length,
|
|
195
|
-
newAssociations: newPairs.length,
|
|
196
|
-
updatedAssociations: existingPairsToUpdate.length,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
logger.error('Error tracking coactivation', error);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Get related memories via the association graph
|
|
205
|
-
*/
|
|
206
|
-
export async function getRelatedMemories(memoryId, limit = 10) {
|
|
207
|
-
try {
|
|
208
|
-
const db = await getDb();
|
|
209
|
-
const schema = await getSchema();
|
|
210
|
-
// Get all associated memories, sorted by weight
|
|
211
|
-
const associations = await db
|
|
212
|
-
.select()
|
|
213
|
-
.from(schema.memoryAssociations)
|
|
214
|
-
.where(or(eq(schema.memoryAssociations.fromMemoryId, memoryId), eq(schema.memoryAssociations.toMemoryId, memoryId)))
|
|
215
|
-
.orderBy(desc(schema.memoryAssociations.weight))
|
|
216
|
-
.limit(limit);
|
|
217
|
-
const relatedIds = associations.map((a) => a.fromMemoryId === memoryId ? a.toMemoryId : a.fromMemoryId);
|
|
218
|
-
if (relatedIds.length === 0)
|
|
219
|
-
return [];
|
|
220
|
-
// Fetch the actual memories
|
|
221
|
-
return await db
|
|
222
|
-
.select()
|
|
223
|
-
.from(schema.memories)
|
|
224
|
-
.where(inArray(schema.memories.id, relatedIds));
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
logger.error('Error getting related memories', error);
|
|
228
|
-
return [];
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Prune weak associations (weight < threshold)
|
|
233
|
-
*/
|
|
234
|
-
export async function pruneWeakAssociations(weightThreshold = 5) {
|
|
235
|
-
try {
|
|
236
|
-
const db = await getDb();
|
|
237
|
-
const schema = await getSchema();
|
|
238
|
-
const result = await db
|
|
239
|
-
.delete(schema.memoryAssociations)
|
|
240
|
-
.where(schema.memoryAssociations.weight <= weightThreshold);
|
|
241
|
-
return result?.rowCount || 0;
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
logger.error('Error pruning weak associations', error);
|
|
245
|
-
return 0;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Get association statistics
|
|
250
|
-
*/
|
|
251
|
-
export async function getAssociationStats() {
|
|
252
|
-
try {
|
|
253
|
-
const db = await getDb();
|
|
254
|
-
const schema = await getSchema();
|
|
255
|
-
const associations = await db
|
|
256
|
-
.select()
|
|
257
|
-
.from(schema.memoryAssociations);
|
|
258
|
-
const stats = {
|
|
259
|
-
totalAssociations: associations.length,
|
|
260
|
-
byType: {},
|
|
261
|
-
avgWeight: 0,
|
|
262
|
-
maxWeight: 0,
|
|
263
|
-
};
|
|
264
|
-
let totalWeight = 0;
|
|
265
|
-
for (const assoc of associations) {
|
|
266
|
-
stats.byType[assoc.associationType] = (stats.byType[assoc.associationType] || 0) + 1;
|
|
267
|
-
totalWeight += assoc.weight;
|
|
268
|
-
if (assoc.weight > stats.maxWeight)
|
|
269
|
-
stats.maxWeight = assoc.weight;
|
|
270
|
-
}
|
|
271
|
-
stats.avgWeight = associations.length > 0 ? totalWeight / associations.length : 0;
|
|
272
|
-
return stats;
|
|
273
|
-
}
|
|
274
|
-
catch (error) {
|
|
275
|
-
logger.error('Error getting association stats', error);
|
|
276
|
-
return {
|
|
277
|
-
totalAssociations: 0,
|
|
278
|
-
byType: {},
|
|
279
|
-
avgWeight: 0,
|
|
280
|
-
maxWeight: 0,
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
//# sourceMappingURL=associations.js.map
|
package/dist/core/autosave.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export declare function getDefaultAutosaveHook(): {
|
|
2
|
-
getMessageCount: () => number;
|
|
3
|
-
updateConfig: (opts?: {
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
messageCount?: number;
|
|
6
|
-
hooks?: string[];
|
|
7
|
-
}) => void;
|
|
8
|
-
getConfig: () => {
|
|
9
|
-
enabled: boolean;
|
|
10
|
-
messageCount: number;
|
|
11
|
-
hooks: string[];
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare function createAutosaveConfig(): {
|
|
15
|
-
enabled: boolean;
|
|
16
|
-
messageCount: number;
|
|
17
|
-
hooks: string[];
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=autosave.d.ts.map
|
package/dist/core/autosave.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Autosave functionality placeholder
|
|
2
|
-
export function getDefaultAutosaveHook() {
|
|
3
|
-
let config = { enabled: false, messageCount: 10, hooks: [] };
|
|
4
|
-
return {
|
|
5
|
-
getMessageCount: () => 0,
|
|
6
|
-
updateConfig: (opts) => {
|
|
7
|
-
if (opts)
|
|
8
|
-
Object.assign(config, opts);
|
|
9
|
-
},
|
|
10
|
-
getConfig: () => ({ ...config })
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export function createAutosaveConfig() {
|
|
14
|
-
return { enabled: false, messageCount: 10, hooks: [] };
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=autosave.js.map
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
interface DecayStats {
|
|
2
|
-
decayed: number;
|
|
3
|
-
sourceCountUpdated: number;
|
|
4
|
-
errors: string[];
|
|
5
|
-
}
|
|
6
|
-
export declare function applyBeliefDecay(projectId?: string): Promise<DecayStats>;
|
|
7
|
-
/**
|
|
8
|
-
* Get beliefs that need attention (low confidence, disputed, or stale)
|
|
9
|
-
*/
|
|
10
|
-
export declare function getProblemBeliefs(projectId: string, options?: {
|
|
11
|
-
minDaysSinceConfirmation?: number;
|
|
12
|
-
confidenceThreshold?: number;
|
|
13
|
-
}): Promise<Array<{
|
|
14
|
-
id: string;
|
|
15
|
-
type: string;
|
|
16
|
-
statement: string;
|
|
17
|
-
confidence: number;
|
|
18
|
-
status: string;
|
|
19
|
-
lastConfirmedAt: Date | null;
|
|
20
|
-
issue: string;
|
|
21
|
-
}>>;
|
|
22
|
-
/**
|
|
23
|
-
* Reinforce a belief (increase confidence when re-referenced)
|
|
24
|
-
*/
|
|
25
|
-
export declare function reinforceBelief(beliefId: string, boostAmount?: number): Promise<boolean>;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=decay.d.ts.map
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { getDbClient } from '../lib/db-client.js';
|
|
2
|
-
import { logger } from './logger.js';
|
|
3
|
-
/**
|
|
4
|
-
* Belief Decay Engine
|
|
5
|
-
*
|
|
6
|
-
* Manages confidence decay for beliefs over time
|
|
7
|
-
* Formula: newConfidence = oldConfidence * (1 - decayRate/100)^(daysSinceLastConfirmation / halfLife)
|
|
8
|
-
* - Default 30 days half-life (belief confidence halves every 30 days without reinforcement)
|
|
9
|
-
* - Disputed beliefs decay faster
|
|
10
|
-
* - Beliefs with more sources decay slower
|
|
11
|
-
*/
|
|
12
|
-
const DEFAULT_BELIEF_HALF_LIFE = 30; // days
|
|
13
|
-
const DISPUTE_DECAY_MULTIPLIER = 1.5; // disputes decay 1.5x faster
|
|
14
|
-
const SOURCE_BOOST_THRESHOLD = 3; // 3+ sources = slower decay
|
|
15
|
-
export async function applyBeliefDecay(projectId) {
|
|
16
|
-
const stats = { decayed: 0, sourceCountUpdated: 0, errors: [] };
|
|
17
|
-
try {
|
|
18
|
-
const { raw } = await getDbClient();
|
|
19
|
-
const sqlite = raw.$client;
|
|
20
|
-
const isPg = typeof raw.query === 'function';
|
|
21
|
-
if (!sqlite && !isPg) {
|
|
22
|
-
logger.warn('No database client available for belief decay');
|
|
23
|
-
return stats;
|
|
24
|
-
}
|
|
25
|
-
const now = Date.now();
|
|
26
|
-
if (isPg) {
|
|
27
|
-
// PostgreSQL version
|
|
28
|
-
const pg = raw;
|
|
29
|
-
// Get all active beliefs
|
|
30
|
-
const beliefResult = await pg.query(`SELECT id, confidence, belief_decay_rate, last_confirmed_at, status, source_count
|
|
31
|
-
FROM beliefs WHERE project_id = $1 AND status = 'active'`, [projectId]);
|
|
32
|
-
for (const belief of beliefResult.rows) {
|
|
33
|
-
try {
|
|
34
|
-
const lastConfirmed = belief.last_confirmed_at ? new Date(belief.last_confirmed_at).getTime() : new Date(belief.created_at).getTime();
|
|
35
|
-
const daysSince = Math.max(0, (now - lastConfirmed) / (24 * 60 * 60 * 1000));
|
|
36
|
-
// Get source count for this belief
|
|
37
|
-
const sourceResult = await pg.query(`SELECT COUNT(*) as cnt FROM belief_memory_sources WHERE belief_id = $1`, [belief.id]);
|
|
38
|
-
const sourceCount = parseInt(sourceResult.rows[0]?.cnt ?? 1);
|
|
39
|
-
// Calculate decay rate (disputes decay faster)
|
|
40
|
-
const baseDecayRate = belief.belief_decay_rate ?? DEFAULT_BELIEF_HALF_LIFE;
|
|
41
|
-
const decayMultiplier = belief.status === 'disputed' ? DISPUTE_DECAY_MULTIPLIER : 1;
|
|
42
|
-
const sourceMultiplier = sourceCount >= SOURCE_BOOST_THRESHOLD ? 0.8 : 1;
|
|
43
|
-
const effectiveHalfLife = baseDecayRate * decayMultiplier * sourceMultiplier;
|
|
44
|
-
// Apply exponential decay: confidence = initial * (0.5)^(days/halfLife)
|
|
45
|
-
const newConfidence = Math.round(belief.confidence * Math.pow(0.5, daysSince / effectiveHalfLife));
|
|
46
|
-
if (newConfidence < belief.confidence) {
|
|
47
|
-
await pg.query(`UPDATE beliefs SET confidence = $1, updated_at = NOW() WHERE id = $2`, [newConfidence, belief.id]);
|
|
48
|
-
stats.decayed++;
|
|
49
|
-
}
|
|
50
|
-
if (sourceCount !== belief.source_count) {
|
|
51
|
-
await pg.query(`UPDATE beliefs SET source_count = $1 WHERE id = $2`, [sourceCount, belief.id]);
|
|
52
|
-
stats.sourceCountUpdated++;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (err) {
|
|
56
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
57
|
-
stats.errors.push(`Belief ${belief.id}: ${msg}`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else if (sqlite) {
|
|
62
|
-
// SQLite version
|
|
63
|
-
const beliefs = sqlite.prepare(`
|
|
64
|
-
SELECT id, confidence, belief_decay_rate, last_confirmed_at, status, source_count, created_at
|
|
65
|
-
FROM beliefs WHERE project_id = ? AND status = 'active'
|
|
66
|
-
`).all(projectId);
|
|
67
|
-
for (const belief of beliefs) {
|
|
68
|
-
try {
|
|
69
|
-
const lastConfirmed = belief.last_confirmed_at
|
|
70
|
-
? belief.last_confirmed_at
|
|
71
|
-
: belief.created_at;
|
|
72
|
-
const daysSince = Math.max(0, (now - lastConfirmed) / (24 * 60 * 60 * 1000));
|
|
73
|
-
// Get source count
|
|
74
|
-
const sourceResult = sqlite.prepare(`SELECT COUNT(*) as cnt FROM belief_memory_sources WHERE belief_id = ?`).get(belief.id);
|
|
75
|
-
const sourceCount = sourceResult?.cnt ?? 1;
|
|
76
|
-
// Calculate decay rate
|
|
77
|
-
const baseDecayRate = belief.belief_decay_rate ?? DEFAULT_BELIEF_HALF_LIFE;
|
|
78
|
-
const decayMultiplier = belief.status === 'disputed' ? DISPUTE_DECAY_MULTIPLIER : 1;
|
|
79
|
-
const sourceMultiplier = sourceCount >= SOURCE_BOOST_THRESHOLD ? 0.8 : 1;
|
|
80
|
-
const effectiveHalfLife = baseDecayRate * decayMultiplier * sourceMultiplier;
|
|
81
|
-
const newConfidence = Math.round(belief.confidence * Math.pow(0.5, daysSince / effectiveHalfLife));
|
|
82
|
-
if (newConfidence < belief.confidence) {
|
|
83
|
-
sqlite.prepare(`
|
|
84
|
-
UPDATE beliefs SET confidence = ?, updated_at = ?
|
|
85
|
-
WHERE id = ?
|
|
86
|
-
`).run(newConfidence, Math.floor(now / 1000), belief.id);
|
|
87
|
-
stats.decayed++;
|
|
88
|
-
}
|
|
89
|
-
if (sourceCount !== belief.source_count) {
|
|
90
|
-
sqlite.prepare(`
|
|
91
|
-
UPDATE beliefs SET source_count = ? WHERE id = ?
|
|
92
|
-
`).run(sourceCount, belief.id);
|
|
93
|
-
stats.sourceCountUpdated++;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
98
|
-
stats.errors.push(`Belief ${belief.id}: ${msg}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
logger.info('Belief decay applied', stats);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
106
|
-
logger.error('Belief decay failed', { error: msg });
|
|
107
|
-
stats.errors.push(msg);
|
|
108
|
-
}
|
|
109
|
-
return stats;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Get beliefs that need attention (low confidence, disputed, or stale)
|
|
113
|
-
*/
|
|
114
|
-
export async function getProblemBeliefs(projectId, options) {
|
|
115
|
-
const problems = [];
|
|
116
|
-
try {
|
|
117
|
-
const { raw } = await getDbClient();
|
|
118
|
-
const sqlite = raw.$client;
|
|
119
|
-
const isPg = typeof raw.query === 'function';
|
|
120
|
-
const minDays = options?.minDaysSinceConfirmation ?? 30;
|
|
121
|
-
const confThreshold = options?.confidenceThreshold ?? 20;
|
|
122
|
-
const now = Date.now();
|
|
123
|
-
if (isPg) {
|
|
124
|
-
const pg = raw;
|
|
125
|
-
const result = await pg.query(`SELECT id, belief_type, statement, confidence, status, last_confirmed_at, created_at
|
|
126
|
-
FROM beliefs WHERE project_id = $1`, [projectId]);
|
|
127
|
-
for (const belief of result.rows) {
|
|
128
|
-
const lastConfirmed = belief.last_confirmed_at ? new Date(belief.last_confirmed_at) : new Date(belief.created_at);
|
|
129
|
-
const daysSince = (now - lastConfirmed.getTime()) / (24 * 60 * 60 * 1000);
|
|
130
|
-
let issue = '';
|
|
131
|
-
if (belief.status === 'disputed')
|
|
132
|
-
issue = 'disputed';
|
|
133
|
-
else if (belief.confidence < confThreshold)
|
|
134
|
-
issue = `low confidence (${belief.confidence})`;
|
|
135
|
-
else if (daysSince > minDays)
|
|
136
|
-
issue = `stale (${Math.round(daysSince)} days)`;
|
|
137
|
-
if (issue) {
|
|
138
|
-
problems.push({
|
|
139
|
-
id: belief.id,
|
|
140
|
-
type: belief.belief_type,
|
|
141
|
-
statement: belief.statement,
|
|
142
|
-
confidence: belief.confidence,
|
|
143
|
-
status: belief.status,
|
|
144
|
-
lastConfirmedAt: belief.last_confirmed_at,
|
|
145
|
-
issue,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else if (sqlite) {
|
|
151
|
-
const beliefs = sqlite.prepare(`
|
|
152
|
-
SELECT id, belief_type, statement, confidence, status, last_confirmed_at, created_at
|
|
153
|
-
FROM beliefs WHERE project_id = ?
|
|
154
|
-
`).all(projectId);
|
|
155
|
-
for (const belief of beliefs) {
|
|
156
|
-
const lastConfirmed = belief.last_confirmed_at
|
|
157
|
-
? new Date(belief.last_confirmed_at * 1000)
|
|
158
|
-
: new Date(belief.created_at * 1000);
|
|
159
|
-
const daysSince = (now - lastConfirmed.getTime()) / (24 * 60 * 60 * 1000);
|
|
160
|
-
let issue = '';
|
|
161
|
-
if (belief.status === 'disputed')
|
|
162
|
-
issue = 'disputed';
|
|
163
|
-
else if (belief.confidence < confThreshold)
|
|
164
|
-
issue = `low confidence (${belief.confidence})`;
|
|
165
|
-
else if (daysSince > minDays)
|
|
166
|
-
issue = `stale (${Math.round(daysSince)} days)`;
|
|
167
|
-
if (issue) {
|
|
168
|
-
problems.push({
|
|
169
|
-
id: belief.id,
|
|
170
|
-
type: belief.belief_type,
|
|
171
|
-
statement: belief.statement,
|
|
172
|
-
confidence: belief.confidence,
|
|
173
|
-
status: belief.status,
|
|
174
|
-
lastConfirmedAt: belief.last_confirmed_at ? new Date(belief.last_confirmed_at * 1000) : null,
|
|
175
|
-
issue,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
logger.error('Failed to get problem beliefs', error);
|
|
183
|
-
}
|
|
184
|
-
return problems;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Reinforce a belief (increase confidence when re-referenced)
|
|
188
|
-
*/
|
|
189
|
-
export async function reinforceBelief(beliefId, boostAmount = 5) {
|
|
190
|
-
try {
|
|
191
|
-
const { raw } = await getDbClient();
|
|
192
|
-
const isPg = typeof raw.query === 'function';
|
|
193
|
-
if (isPg) {
|
|
194
|
-
await raw.query(`UPDATE beliefs SET
|
|
195
|
-
confidence = LEAST(100, confidence + $1),
|
|
196
|
-
last_confirmed_at = NOW(),
|
|
197
|
-
updated_at = NOW()
|
|
198
|
-
WHERE id = $2`, [boostAmount, beliefId]);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
const sqlite = raw.$client;
|
|
202
|
-
sqlite.prepare(`
|
|
203
|
-
UPDATE beliefs SET
|
|
204
|
-
confidence = MIN(100, confidence + ?),
|
|
205
|
-
last_confirmed_at = ?,
|
|
206
|
-
updated_at = ?
|
|
207
|
-
WHERE id = ?
|
|
208
|
-
`).run(boostAmount, Math.floor(Date.now() / 1000), Math.floor(Date.now() / 1000), beliefId);
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
catch (error) {
|
|
213
|
-
logger.error('Failed to reinforce belief', { beliefId, error });
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
//# sourceMappingURL=decay.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { MemoryType } from '../memory/memories.js';
|
|
2
|
-
import type { ExtractedBelief } from './types.js';
|
|
3
|
-
export declare function extractBeliefsFromMemory(input: {
|
|
4
|
-
memoryId: string;
|
|
5
|
-
content: string;
|
|
6
|
-
type: MemoryType | string;
|
|
7
|
-
metadata?: Record<string, unknown> | null;
|
|
8
|
-
}): ExtractedBelief[];
|
|
9
|
-
//# sourceMappingURL=extractor.d.ts.map
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
function cleanStatement(input) {
|
|
2
|
-
return input
|
|
3
|
-
.replace(/^(decision:|constraint:|state change:|reject(?:ed)?:|failure:|preference:)\s*/i, '')
|
|
4
|
-
.replace(/\s+/g, ' ')
|
|
5
|
-
.trim();
|
|
6
|
-
}
|
|
7
|
-
function splitReason(text) {
|
|
8
|
-
const match = text.match(/^(.*?)(?:\s+because\s+|\s+due to\s+)(.+)$/i);
|
|
9
|
-
if (!match)
|
|
10
|
-
return { statement: cleanStatement(text) };
|
|
11
|
-
return {
|
|
12
|
-
statement: cleanStatement(match[1]),
|
|
13
|
-
reason: cleanStatement(match[2]),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function deriveConfidence(type, hasReason) {
|
|
17
|
-
const base = type === 'decision' ? 0.84 :
|
|
18
|
-
type === 'preference' ? 0.8 :
|
|
19
|
-
type === 'failure_cause' ? 0.82 :
|
|
20
|
-
type === 'constraint' ? 0.78 :
|
|
21
|
-
type === 'state_change' ? 0.76 :
|
|
22
|
-
0.74;
|
|
23
|
-
return hasReason ? Math.min(0.95, base + 0.05) : base;
|
|
24
|
-
}
|
|
25
|
-
export function extractBeliefsFromMemory(input) {
|
|
26
|
-
const text = input.content.trim();
|
|
27
|
-
const lowered = text.toLowerCase();
|
|
28
|
-
const beliefs = [];
|
|
29
|
-
const addBelief = (belief) => {
|
|
30
|
-
const cleanedStatement = cleanStatement(belief.statement);
|
|
31
|
-
if (!cleanedStatement || cleanedStatement.length < 8)
|
|
32
|
-
return;
|
|
33
|
-
beliefs.push({
|
|
34
|
-
...belief,
|
|
35
|
-
statement: cleanedStatement,
|
|
36
|
-
confidence: belief.confidence ?? deriveConfidence(belief.type, Boolean(belief.reason)),
|
|
37
|
-
sourceMemoryIds: [input.memoryId],
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
if (input.type === 'decision' || /\b(decision:|decided to|we chose|going with|final decision)\b/i.test(text)) {
|
|
41
|
-
const { statement, reason } = splitReason(text);
|
|
42
|
-
addBelief({
|
|
43
|
-
type: 'decision',
|
|
44
|
-
statement,
|
|
45
|
-
reason,
|
|
46
|
-
status: 'active',
|
|
47
|
-
evidenceSummary: text,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (input.type === 'preference' || /\b(prefers?|likes?|dislikes?|hates?)\b/i.test(text)) {
|
|
51
|
-
const { statement, reason } = splitReason(text);
|
|
52
|
-
addBelief({
|
|
53
|
-
type: 'preference',
|
|
54
|
-
statement,
|
|
55
|
-
reason,
|
|
56
|
-
status: 'active',
|
|
57
|
-
evidenceSummary: text,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
const failureMatch = text.match(/\b(?:failed|failure|broke|error)\b.*?(?:because|due to)\s+(.+)/i);
|
|
61
|
-
if (failureMatch) {
|
|
62
|
-
addBelief({
|
|
63
|
-
type: 'failure_cause',
|
|
64
|
-
statement: cleanStatement(text.split(/(?:because|due to)/i)[0] ?? text),
|
|
65
|
-
reason: cleanStatement(failureMatch[1]),
|
|
66
|
-
status: 'active',
|
|
67
|
-
evidenceSummary: text,
|
|
68
|
-
edges: [{ type: 'causes', targetStatement: cleanStatement(failureMatch[1]) }],
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (/\b(constraint:|must not|cannot|can't|blocked by|required to|needs to)\b/i.test(text)) {
|
|
72
|
-
addBelief({
|
|
73
|
-
type: 'constraint',
|
|
74
|
-
statement: text,
|
|
75
|
-
status: 'active',
|
|
76
|
-
evidenceSummary: text,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
const stateMatch = text.match(/\b(?:state changed from|changed from)\s+(.+?)\s+to\s+(.+?)(?:\s+after\s+(.+))?$/i);
|
|
80
|
-
if (stateMatch) {
|
|
81
|
-
addBelief({
|
|
82
|
-
type: 'state_change',
|
|
83
|
-
statement: `${cleanStatement(stateMatch[1])} -> ${cleanStatement(stateMatch[2])}`,
|
|
84
|
-
reason: stateMatch[3] ? cleanStatement(stateMatch[3]) : undefined,
|
|
85
|
-
status: 'active',
|
|
86
|
-
evidenceSummary: text,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
const disputePatterns = [
|
|
90
|
-
/\b(reject|rejected|do not use|don't use|instead of)\b/i,
|
|
91
|
-
/\bbandaid\b/i,
|
|
92
|
-
];
|
|
93
|
-
if (disputePatterns.some((pattern) => pattern.test(text))) {
|
|
94
|
-
const sentence = text.split(/[.!?]/).find((part) => /reject|bandaid|instead of|do not use|don't use/i.test(part)) ?? text;
|
|
95
|
-
addBelief({
|
|
96
|
-
type: 'dispute',
|
|
97
|
-
statement: sentence,
|
|
98
|
-
status: 'disputed',
|
|
99
|
-
evidenceSummary: text,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const deduped = new Map();
|
|
103
|
-
for (const belief of beliefs) {
|
|
104
|
-
const key = `${belief.type}:${belief.statement.toLowerCase()}`;
|
|
105
|
-
if (!deduped.has(key))
|
|
106
|
-
deduped.set(key, belief);
|
|
107
|
-
}
|
|
108
|
-
if (deduped.size === 0 && !/\b(because|due to|prefer|decision|constraint|changed from|reject)\b/.test(lowered)) {
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
return [...deduped.values()];
|
|
112
|
-
}
|
|
113
|
-
//# sourceMappingURL=extractor.js.map
|