claude-memory-layer 1.0.31 → 1.0.33
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/README.md +9 -2
- package/dist/cli/index.js +1110 -72
- package/dist/cli/index.js.map +4 -4
- package/dist/core/index.js +414 -25
- package/dist/core/index.js.map +2 -2
- package/dist/hooks/post-tool-use.js +416 -27
- package/dist/hooks/post-tool-use.js.map +2 -2
- package/dist/hooks/semantic-daemon.js +416 -27
- package/dist/hooks/semantic-daemon.js.map +2 -2
- package/dist/hooks/session-end.js +416 -27
- package/dist/hooks/session-end.js.map +2 -2
- package/dist/hooks/session-start.js +416 -27
- package/dist/hooks/session-start.js.map +2 -2
- package/dist/hooks/stop.js +416 -27
- package/dist/hooks/stop.js.map +2 -2
- package/dist/hooks/user-prompt-submit.js +504 -34
- package/dist/hooks/user-prompt-submit.js.map +2 -2
- package/dist/index.js +416 -27
- package/dist/index.js.map +2 -2
- package/dist/mcp/index.js +407 -32
- package/dist/mcp/index.js.map +2 -2
- package/dist/server/api/index.js +850 -44
- package/dist/server/api/index.js.map +3 -3
- package/dist/server/index.js +1073 -64
- package/dist/server/index.js.map +3 -3
- package/dist/services/memory-service.js +416 -27
- package/dist/services/memory-service.js.map +2 -2
- package/dist/ui/assets/js/bootstrap.js +2 -0
- package/dist/ui/assets/js/overview.js +166 -3
- package/dist/ui/assets/js/state.js +3 -0
- package/dist/ui/index.html +20 -0
- package/dist/ui/style.css +193 -0
- package/package.json +15 -2
- package/scripts/postinstall-embedding-backend.cjs +16 -12
- package/AGENTS.md +0 -71
- package/CLAUDE.md +0 -30
- package/HANDOFF.md +0 -92
- package/Memo.txt +0 -558
- package/benchmarks/replay/anonymized-real-sessions.json +0 -48
- package/config/kpi-thresholds.json +0 -7
- package/context.md +0 -636
- package/docs/ARCHITECTURE_COMPARISON_AND_RECOMMENDATIONS.md +0 -627
- package/docs/HERMES_MEMORY_INGESTION_ANALYSIS.md +0 -440
- package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +0 -271
- package/docs/MEMORY_USEFULNESS_AUDIT.md +0 -371
- package/docs/MEMORY_USEFULNESS_AUDIT_RAW.json +0 -80
- package/docs/MEMSEARCH_PROJECT_STRUCTURE_ANALYSIS.md +0 -333
- package/docs/MEMU_ADOPTION.md +0 -40
- package/docs/OPERATIONS.md +0 -18
- package/docs/PRODUCT_VALIDATION_MATRIX.md +0 -82
- package/docs/PROJECT_STRUCTURE_ANALYSIS.md +0 -421
- package/docs/REFACTORING_MILESTONES_AND_ISSUES.md +0 -501
- package/docs/REFACTORING_PLAN_THIN_CORE.md +0 -414
- package/docs/REFERENCE_PROJECT_ANALYSES.md +0 -25
- package/docs/SUPERLOCALMEMORY_PROJECT_STRUCTURE_ANALYSIS.md +0 -452
- package/docs/TARGET_ARCHITECTURE_AND_FOLDER_STRUCTURE.md +0 -446
- package/docs/architecture/comparison-index.md +0 -47
- package/docs/reports/codex-real-data-validation-20260505T040447Z.md +0 -46
- package/plan.md +0 -1642
- package/scripts/build.ts +0 -159
- package/scripts/bump-patch-version.sh +0 -18
- package/scripts/delete-unknown-projects.js +0 -154
- package/scripts/fix-sync-gap.js +0 -32
- package/scripts/generate-session-qrels.ts +0 -126
- package/scripts/heartbeat-memory-orchestrator.sh +0 -28
- package/scripts/replay-retrieval-benchmark.ts +0 -69
- package/scripts/report-sync-gap.js +0 -26
- package/scripts/review-queue-auto-resolve.js +0 -21
- package/scripts/sync-gap-auto-heal.sh +0 -17
- package/spec.md +0 -624
- package/specs/20260207-dashboard-upgrade/context.md +0 -38
- package/specs/20260207-dashboard-upgrade/spec.md +0 -96
- package/specs/citations-system/context.md +0 -243
- package/specs/citations-system/plan.md +0 -495
- package/specs/citations-system/spec.md +0 -371
- package/specs/endless-mode/context.md +0 -305
- package/specs/endless-mode/plan.md +0 -620
- package/specs/endless-mode/spec.md +0 -455
- package/specs/entity-edge-model/context.md +0 -401
- package/specs/entity-edge-model/plan.md +0 -459
- package/specs/entity-edge-model/spec.md +0 -391
- package/specs/evidence-aligner-v2/context.md +0 -401
- package/specs/evidence-aligner-v2/plan.md +0 -303
- package/specs/evidence-aligner-v2/spec.md +0 -312
- package/specs/mcp-desktop-integration/context.md +0 -278
- package/specs/mcp-desktop-integration/plan.md +0 -550
- package/specs/mcp-desktop-integration/spec.md +0 -494
- package/specs/memory-utilization-improvements/context.md +0 -145
- package/specs/memory-utilization-improvements/plan.md +0 -361
- package/specs/memory-utilization-improvements/spec.md +0 -361
- package/specs/post-tool-use-hook/context.md +0 -319
- package/specs/post-tool-use-hook/plan.md +0 -469
- package/specs/post-tool-use-hook/spec.md +0 -364
- package/specs/private-tags/context.md +0 -288
- package/specs/private-tags/plan.md +0 -412
- package/specs/private-tags/spec.md +0 -345
- package/specs/progressive-disclosure/context.md +0 -346
- package/specs/progressive-disclosure/plan.md +0 -663
- package/specs/progressive-disclosure/spec.md +0 -415
- package/specs/selective-tool-observation/context.md +0 -100
- package/specs/selective-tool-observation/plan.md +0 -158
- package/specs/selective-tool-observation/spec.md +0 -127
- package/specs/task-entity-system/context.md +0 -297
- package/specs/task-entity-system/plan.md +0 -301
- package/specs/task-entity-system/spec.md +0 -314
- package/specs/thin-core-refactor/context.md +0 -275
- package/specs/thin-core-refactor/plan.md +0 -536
- package/specs/thin-core-refactor/spec.md +0 -465
- package/specs/vector-outbox-v2/context.md +0 -470
- package/specs/vector-outbox-v2/plan.md +0 -562
- package/specs/vector-outbox-v2/spec.md +0 -466
- package/specs/web-viewer-ui/context.md +0 -384
- package/specs/web-viewer-ui/plan.md +0 -797
- package/specs/web-viewer-ui/spec.md +0 -516
- package/src/adapters/claude/capture/index.ts +0 -3
- package/src/adapters/claude/context/index.ts +0 -3
- package/src/adapters/claude/hooks/index.ts +0 -21
- package/src/adapters/claude/hooks/post-tool-use.ts +0 -239
- package/src/adapters/claude/hooks/prompt-injection-policy.ts +0 -104
- package/src/adapters/claude/hooks/semantic-daemon-client.ts +0 -209
- package/src/adapters/claude/hooks/semantic-daemon.ts +0 -283
- package/src/adapters/claude/hooks/session-end.ts +0 -59
- package/src/adapters/claude/hooks/session-start.ts +0 -73
- package/src/adapters/claude/hooks/stop.ts +0 -128
- package/src/adapters/claude/hooks/user-prompt-submit.ts +0 -361
- package/src/adapters/claude/index.ts +0 -4
- package/src/adapters/claude/transcript/index.ts +0 -4
- package/src/adapters/claude/transcript/transcript-reader.ts +0 -57
- package/src/adapters/claude/transcript/turn-reconstructor.ts +0 -65
- package/src/apps/cli/claude-settings-hooks.ts +0 -138
- package/src/apps/cli/codex-import-runner.ts +0 -125
- package/src/apps/cli/codex-validation-output.ts +0 -95
- package/src/apps/cli/hermes-import-runner.ts +0 -130
- package/src/apps/cli/hermes-validation-output.ts +0 -91
- package/src/apps/cli/index.ts +0 -1735
- package/src/apps/cli/mcp-install.ts +0 -106
- package/src/apps/cli/retrieval-disclosure-output.ts +0 -196
- package/src/apps/dashboard/assets/js/bootstrap.js +0 -244
- package/src/apps/dashboard/assets/js/chat.js +0 -373
- package/src/apps/dashboard/assets/js/disclosure.js +0 -232
- package/src/apps/dashboard/assets/js/modals.js +0 -298
- package/src/apps/dashboard/assets/js/overview.js +0 -655
- package/src/apps/dashboard/assets/js/state.js +0 -72
- package/src/apps/dashboard/assets/js/views.js +0 -468
- package/src/apps/dashboard/index.html +0 -543
- package/src/apps/dashboard/index.ts +0 -3
- package/src/apps/dashboard/style.css +0 -1750
- package/src/apps/index.ts +0 -5
- package/src/apps/server/api/chat.ts +0 -244
- package/src/apps/server/api/citations.ts +0 -105
- package/src/apps/server/api/events.ts +0 -137
- package/src/apps/server/api/health.ts +0 -53
- package/src/apps/server/api/index.ts +0 -26
- package/src/apps/server/api/projects.ts +0 -74
- package/src/apps/server/api/search.ts +0 -184
- package/src/apps/server/api/sessions.ts +0 -115
- package/src/apps/server/api/stats.ts +0 -723
- package/src/apps/server/api/turns.ts +0 -143
- package/src/apps/server/api/utils.ts +0 -65
- package/src/apps/server/index.ts +0 -111
- package/src/cli/index.ts +0 -3
- package/src/cli/retrieval-disclosure-output.ts +0 -2
- package/src/compat/index.ts +0 -5
- package/src/core/canonical-key.ts +0 -186
- package/src/core/citation-generator.ts +0 -63
- package/src/core/consolidated-store.ts +0 -356
- package/src/core/consolidation-worker.ts +0 -493
- package/src/core/context-formatter.ts +0 -276
- package/src/core/continuity-manager.ts +0 -341
- package/src/core/db-wrapper.ts +0 -64
- package/src/core/derive/fact-deriver.ts +0 -170
- package/src/core/derive/index.ts +0 -2
- package/src/core/derive/summary-deriver.ts +0 -76
- package/src/core/edge-repo.ts +0 -333
- package/src/core/embedder.ts +0 -4
- package/src/core/engine/embedding-maintenance-service.ts +0 -187
- package/src/core/engine/endless-memory-services.ts +0 -4
- package/src/core/engine/index.ts +0 -19
- package/src/core/engine/memory-engine-services.ts +0 -170
- package/src/core/engine/memory-ingest-service.ts +0 -317
- package/src/core/engine/memory-query-service.ts +0 -173
- package/src/core/engine/memory-runtime-service.ts +0 -162
- package/src/core/engine/memory-service-composition.ts +0 -231
- package/src/core/engine/retrieval-analytics-service.ts +0 -181
- package/src/core/engine/retrieval-disclosure-service.ts +0 -420
- package/src/core/engine/retrieval-orchestrator.ts +0 -377
- package/src/core/engine/retrieval-services.ts +0 -176
- package/src/core/engine/shared-memory-services.ts +0 -4
- package/src/core/entity-repo.ts +0 -349
- package/src/core/event-store.ts +0 -779
- package/src/core/evidence-aligner.ts +0 -635
- package/src/core/external-market-context.ts +0 -582
- package/src/core/graduation-worker.ts +0 -171
- package/src/core/graduation.ts +0 -377
- package/src/core/index.ts +0 -64
- package/src/core/ingest-interceptor.ts +0 -80
- package/src/core/markdown-mirror.ts +0 -70
- package/src/core/matcher.ts +0 -208
- package/src/core/md-mirror.ts +0 -92
- package/src/core/metadata-extractor.ts +0 -203
- package/src/core/model/memory-fact.ts +0 -30
- package/src/core/model/memory-rule.ts +0 -14
- package/src/core/model/memory-summary.ts +0 -21
- package/src/core/model/raw-event.ts +0 -28
- package/src/core/model/retrieval-result.ts +0 -35
- package/src/core/mongo-sync-config.ts +0 -165
- package/src/core/mongo-sync-worker.ts +0 -381
- package/src/core/privacy/filter.ts +0 -190
- package/src/core/privacy/index.ts +0 -20
- package/src/core/privacy/tag-parser.ts +0 -145
- package/src/core/product-validation-matrix.ts +0 -314
- package/src/core/progressive-retriever.ts +0 -414
- package/src/core/registry/project-path.ts +0 -54
- package/src/core/registry/session-registry.ts +0 -69
- package/src/core/replay-evaluator.ts +0 -625
- package/src/core/retrieval-benchmark.ts +0 -117
- package/src/core/retrieval-quality.ts +0 -109
- package/src/core/retriever.ts +0 -800
- package/src/core/session-qrels.ts +0 -360
- package/src/core/shared-event-store.ts +0 -114
- package/src/core/shared-promoter.ts +0 -249
- package/src/core/shared-store.ts +0 -289
- package/src/core/shared-vector-store.ts +0 -203
- package/src/core/sqlite-event-store.ts +0 -1846
- package/src/core/sqlite-wrapper.ts +0 -116
- package/src/core/sync-worker.ts +0 -228
- package/src/core/tag-taxonomy.ts +0 -51
- package/src/core/task/blocker-resolver.ts +0 -333
- package/src/core/task/index.ts +0 -9
- package/src/core/task/task-matcher.ts +0 -240
- package/src/core/task/task-projector.ts +0 -358
- package/src/core/task/task-resolver.ts +0 -421
- package/src/core/turn-state.ts +0 -207
- package/src/core/types.ts +0 -952
- package/src/core/vector-outbox.ts +0 -299
- package/src/core/vector-store.ts +0 -231
- package/src/core/vector-worker.ts +0 -521
- package/src/core/working-set-store.ts +0 -257
- package/src/extensions/endless-memory/endless-memory-services.ts +0 -350
- package/src/extensions/endless-memory/index.ts +0 -1
- package/src/extensions/index.ts +0 -5
- package/src/extensions/mcp/handlers.ts +0 -960
- package/src/extensions/mcp/index.ts +0 -48
- package/src/extensions/mcp/tools.ts +0 -252
- package/src/extensions/shared-memory/index.ts +0 -1
- package/src/extensions/shared-memory/shared-memory-services.ts +0 -211
- package/src/extensions/vector/embedder.ts +0 -234
- package/src/extensions/vector/index.ts +0 -1
- package/src/hooks/post-tool-use.ts +0 -9
- package/src/hooks/semantic-daemon-client.ts +0 -1
- package/src/hooks/semantic-daemon.ts +0 -11
- package/src/hooks/session-end.ts +0 -9
- package/src/hooks/session-start.ts +0 -9
- package/src/hooks/stop.ts +0 -9
- package/src/hooks/user-prompt-submit.ts +0 -9
- package/src/index.ts +0 -13
- package/src/mcp/handlers.ts +0 -2
- package/src/mcp/index.ts +0 -4
- package/src/mcp/tools.ts +0 -2
- package/src/server/api/chat.ts +0 -2
- package/src/server/api/citations.ts +0 -2
- package/src/server/api/events.ts +0 -2
- package/src/server/api/health.ts +0 -2
- package/src/server/api/index.ts +0 -2
- package/src/server/api/projects.ts +0 -2
- package/src/server/api/search.ts +0 -2
- package/src/server/api/sessions.ts +0 -2
- package/src/server/api/stats.ts +0 -2
- package/src/server/api/turns.ts +0 -2
- package/src/server/api/utils.ts +0 -2
- package/src/server/index.ts +0 -2
- package/src/services/bootstrap-organizer.ts +0 -463
- package/src/services/codex-session-history-importer.ts +0 -966
- package/src/services/hermes-session-history-importer.ts +0 -733
- package/src/services/memory-service-config.ts +0 -36
- package/src/services/memory-service-registry.ts +0 -150
- package/src/services/memory-service.ts +0 -688
- package/src/services/session-history-importer.ts +0 -629
- package/tests/README.md +0 -23
- package/tests/adapters/claude/claude-semantic-daemon-adapter.test.ts +0 -54
- package/tests/adapters/claude/claude-transcript-reconstructor.test.ts +0 -98
- package/tests/adapters/claude-hook-prompt-injection-policy.test.ts +0 -99
- package/tests/apps/app-layer-boundary.test.ts +0 -48
- package/tests/apps/claude-settings-hooks.test.ts +0 -107
- package/tests/apps/cli-disclosure-output.test.ts +0 -212
- package/tests/apps/codex-import-runner.test.ts +0 -99
- package/tests/apps/codex-validation-output.test.ts +0 -100
- package/tests/apps/hermes-import-runner.test.ts +0 -99
- package/tests/apps/mcp-install-command.test.ts +0 -59
- package/tests/apps/package-build-entrypoints.test.ts +0 -30
- package/tests/apps/postinstall-embedding-backend.test.ts +0 -185
- package/tests/apps/search-api-disclosure.test.ts +0 -162
- package/tests/apps/stats-api-lightweight.test.ts +0 -67
- package/tests/apps/ui-disclosure-output.test.ts +0 -140
- package/tests/core/bootstrap-organizer.test.ts +0 -111
- package/tests/core/canonical-key.test.ts +0 -101
- package/tests/core/codex-session-history-importer-validation.test.ts +0 -185
- package/tests/core/consolidation-worker.test.ts +0 -75
- package/tests/core/embedding-maintenance-service.test.ts +0 -282
- package/tests/core/evidence-aligner.test.ts +0 -152
- package/tests/core/external-market-context.test.ts +0 -209
- package/tests/core/fact-deriver.test.ts +0 -79
- package/tests/core/hermes-session-history-importer-validation.test.ts +0 -609
- package/tests/core/ingest-interceptor.test.ts +0 -38
- package/tests/core/markdown-mirror.test.ts +0 -85
- package/tests/core/matcher.test.ts +0 -112
- package/tests/core/md-mirror.test.ts +0 -50
- package/tests/core/memory-engine-services.test.ts +0 -240
- package/tests/core/memory-ingest-service.test.ts +0 -296
- package/tests/core/memory-query-service.test.ts +0 -129
- package/tests/core/memory-runtime-service.test.ts +0 -201
- package/tests/core/memory-service-composition.test.ts +0 -192
- package/tests/core/memory-service-config.test.ts +0 -41
- package/tests/core/memory-service-facade.test.ts +0 -30
- package/tests/core/memory-service-registry.test.ts +0 -206
- package/tests/core/product-validation-matrix.test.ts +0 -61
- package/tests/core/project-registry.test.ts +0 -78
- package/tests/core/replay-evaluator.test.ts +0 -181
- package/tests/core/retrieval-analytics-service.test.ts +0 -210
- package/tests/core/retrieval-benchmark.test.ts +0 -93
- package/tests/core/retrieval-disclosure-service.test.ts +0 -264
- package/tests/core/retrieval-orchestrator.test.ts +0 -403
- package/tests/core/retrieval-quality.test.ts +0 -31
- package/tests/core/retrieval-services.test.ts +0 -185
- package/tests/core/retriever-fallback-chain.test.ts +0 -223
- package/tests/core/retriever-strategy-scope.test.ts +0 -164
- package/tests/core/retriever.memu-adoption.test.ts +0 -122
- package/tests/core/session-history-importer-filter.test.ts +0 -78
- package/tests/core/session-qrels.test.ts +0 -250
- package/tests/core/sqlite-event-store-replication.test.ts +0 -127
- package/tests/core/summary-deriver.test.ts +0 -66
- package/tests/extensions/embedder-warning-suppression.test.ts +0 -84
- package/tests/extensions/endless-memory-extension-boundary.test.ts +0 -17
- package/tests/extensions/endless-memory-services.test.ts +0 -325
- package/tests/extensions/mcp-context-tools.test.ts +0 -905
- package/tests/extensions/mcp-extension-boundary.test.ts +0 -21
- package/tests/extensions/mcp-package-build.test.ts +0 -22
- package/tests/extensions/mcp-project-aware-tools.test.ts +0 -102
- package/tests/extensions/shared-memory-extension-boundary.test.ts +0 -24
- package/tests/extensions/shared-memory-services.test.ts +0 -309
- package/tests/extensions/vector-extension-boundary.test.ts +0 -21
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -15
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Consolidated Store
|
|
3
|
-
* Manages long-term integrated memories for Endless Mode
|
|
4
|
-
* Biomimetic: Simulates memory consolidation that occurs during sleep
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { randomUUID } from 'crypto';
|
|
8
|
-
import { dbRun, dbAll, toDate, type Database } from './db-wrapper.js';
|
|
9
|
-
import type {
|
|
10
|
-
ConsolidatedMemory,
|
|
11
|
-
ConsolidatedMemoryInput,
|
|
12
|
-
ConsolidationRule,
|
|
13
|
-
ConsolidationRuleInput
|
|
14
|
-
} from './types.js';
|
|
15
|
-
import { EventStore } from './event-store.js';
|
|
16
|
-
|
|
17
|
-
export class ConsolidatedStore {
|
|
18
|
-
constructor(private eventStore: EventStore) {}
|
|
19
|
-
|
|
20
|
-
private get db(): Database {
|
|
21
|
-
return this.eventStore.getDatabase();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Create a new consolidated memory
|
|
26
|
-
*/
|
|
27
|
-
async create(input: ConsolidatedMemoryInput): Promise<string> {
|
|
28
|
-
const memoryId = randomUUID();
|
|
29
|
-
|
|
30
|
-
await dbRun(
|
|
31
|
-
this.db,
|
|
32
|
-
`INSERT INTO consolidated_memories
|
|
33
|
-
(memory_id, summary, topics, source_events, confidence, created_at)
|
|
34
|
-
VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP)`,
|
|
35
|
-
[
|
|
36
|
-
memoryId,
|
|
37
|
-
input.summary,
|
|
38
|
-
JSON.stringify(input.topics),
|
|
39
|
-
JSON.stringify(input.sourceEvents),
|
|
40
|
-
input.confidence
|
|
41
|
-
]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return memoryId;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Get a consolidated memory by ID
|
|
49
|
-
*/
|
|
50
|
-
async get(memoryId: string): Promise<ConsolidatedMemory | null> {
|
|
51
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
52
|
-
this.db,
|
|
53
|
-
`SELECT * FROM consolidated_memories WHERE memory_id = ?`,
|
|
54
|
-
[memoryId]
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
if (rows.length === 0) return null;
|
|
58
|
-
return this.rowToMemory(rows[0]);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Search consolidated memories by query (simple text search)
|
|
63
|
-
*/
|
|
64
|
-
async search(query: string, options?: { topK?: number }): Promise<ConsolidatedMemory[]> {
|
|
65
|
-
const topK = options?.topK || 5;
|
|
66
|
-
|
|
67
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
68
|
-
this.db,
|
|
69
|
-
`SELECT * FROM consolidated_memories
|
|
70
|
-
WHERE summary LIKE ?
|
|
71
|
-
ORDER BY confidence DESC
|
|
72
|
-
LIMIT ?`,
|
|
73
|
-
[`%${query}%`, topK]
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
return rows.map(this.rowToMemory);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Search by topics
|
|
81
|
-
*/
|
|
82
|
-
async searchByTopics(topics: string[], options?: { topK?: number }): Promise<ConsolidatedMemory[]> {
|
|
83
|
-
const topK = options?.topK || 5;
|
|
84
|
-
|
|
85
|
-
// Build topic filter
|
|
86
|
-
const topicConditions = topics.map(() => `topics LIKE ?`).join(' OR ');
|
|
87
|
-
const topicParams = topics.map(t => `%"${t}"%`);
|
|
88
|
-
|
|
89
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
90
|
-
this.db,
|
|
91
|
-
`SELECT * FROM consolidated_memories
|
|
92
|
-
WHERE ${topicConditions}
|
|
93
|
-
ORDER BY confidence DESC
|
|
94
|
-
LIMIT ?`,
|
|
95
|
-
[...topicParams, topK]
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return rows.map(this.rowToMemory);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get all consolidated memories ordered by confidence
|
|
103
|
-
*/
|
|
104
|
-
async getAll(options?: { limit?: number }): Promise<ConsolidatedMemory[]> {
|
|
105
|
-
const limit = options?.limit || 100;
|
|
106
|
-
|
|
107
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
108
|
-
this.db,
|
|
109
|
-
`SELECT * FROM consolidated_memories
|
|
110
|
-
ORDER BY confidence DESC, created_at DESC
|
|
111
|
-
LIMIT ?`,
|
|
112
|
-
[limit]
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return rows.map(this.rowToMemory);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Get recently created memories
|
|
120
|
-
*/
|
|
121
|
-
async getRecent(options?: { limit?: number; hours?: number }): Promise<ConsolidatedMemory[]> {
|
|
122
|
-
const limit = options?.limit || 10;
|
|
123
|
-
const hours = options?.hours || 24;
|
|
124
|
-
|
|
125
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
126
|
-
this.db,
|
|
127
|
-
`SELECT * FROM consolidated_memories
|
|
128
|
-
WHERE created_at > datetime('now', '-${hours} hours')
|
|
129
|
-
ORDER BY created_at DESC
|
|
130
|
-
LIMIT ?`,
|
|
131
|
-
[limit]
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
return rows.map(this.rowToMemory);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Mark a memory as accessed (tracks usage for importance scoring)
|
|
139
|
-
*/
|
|
140
|
-
async markAccessed(memoryId: string): Promise<void> {
|
|
141
|
-
await dbRun(
|
|
142
|
-
this.db,
|
|
143
|
-
`UPDATE consolidated_memories
|
|
144
|
-
SET accessed_at = CURRENT_TIMESTAMP,
|
|
145
|
-
access_count = access_count + 1
|
|
146
|
-
WHERE memory_id = ?`,
|
|
147
|
-
[memoryId]
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Update confidence score for a memory
|
|
153
|
-
*/
|
|
154
|
-
async updateConfidence(memoryId: string, confidence: number): Promise<void> {
|
|
155
|
-
await dbRun(
|
|
156
|
-
this.db,
|
|
157
|
-
`UPDATE consolidated_memories
|
|
158
|
-
SET confidence = ?
|
|
159
|
-
WHERE memory_id = ?`,
|
|
160
|
-
[confidence, memoryId]
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Delete a consolidated memory
|
|
166
|
-
*/
|
|
167
|
-
async delete(memoryId: string): Promise<void> {
|
|
168
|
-
await dbRun(
|
|
169
|
-
this.db,
|
|
170
|
-
`DELETE FROM consolidated_memories WHERE memory_id = ?`,
|
|
171
|
-
[memoryId]
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Create a long-term rule promoted from stable summaries
|
|
177
|
-
*/
|
|
178
|
-
async createRule(input: ConsolidationRuleInput): Promise<string> {
|
|
179
|
-
const ruleId = randomUUID();
|
|
180
|
-
|
|
181
|
-
await dbRun(
|
|
182
|
-
this.db,
|
|
183
|
-
`INSERT INTO consolidated_rules
|
|
184
|
-
(rule_id, rule, topics, source_memory_ids, source_events, confidence, created_at)
|
|
185
|
-
VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)`,
|
|
186
|
-
[
|
|
187
|
-
ruleId,
|
|
188
|
-
input.rule,
|
|
189
|
-
JSON.stringify(input.topics),
|
|
190
|
-
JSON.stringify(input.sourceMemoryIds),
|
|
191
|
-
JSON.stringify(input.sourceEvents),
|
|
192
|
-
input.confidence
|
|
193
|
-
]
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
return ruleId;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async getRules(options?: { limit?: number }): Promise<ConsolidationRule[]> {
|
|
200
|
-
const limit = options?.limit || 100;
|
|
201
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
202
|
-
this.db,
|
|
203
|
-
`SELECT * FROM consolidated_rules ORDER BY confidence DESC, created_at DESC LIMIT ?`,
|
|
204
|
-
[limit]
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
return rows.map((row) => ({
|
|
208
|
-
ruleId: row.rule_id as string,
|
|
209
|
-
rule: row.rule as string,
|
|
210
|
-
topics: JSON.parse((row.topics as string) || '[]'),
|
|
211
|
-
sourceMemoryIds: JSON.parse((row.source_memory_ids as string) || '[]'),
|
|
212
|
-
sourceEvents: JSON.parse((row.source_events as string) || '[]'),
|
|
213
|
-
confidence: Number(row.confidence ?? 0.5),
|
|
214
|
-
createdAt: toDate(row.created_at) || new Date()
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
async countRules(): Promise<number> {
|
|
219
|
-
const result = await dbAll<{ count: number }>(
|
|
220
|
-
this.db,
|
|
221
|
-
`SELECT COUNT(*) as count FROM consolidated_rules`
|
|
222
|
-
);
|
|
223
|
-
return result[0]?.count || 0;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async hasRuleForSourceMemory(memoryId: string): Promise<boolean> {
|
|
227
|
-
const rows = await dbAll<{ count: number }>(
|
|
228
|
-
this.db,
|
|
229
|
-
`SELECT COUNT(*) as count FROM consolidated_rules WHERE source_memory_ids LIKE ?`,
|
|
230
|
-
[`%"${memoryId}"%`]
|
|
231
|
-
);
|
|
232
|
-
return (rows[0]?.count || 0) > 0;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Get count of consolidated memories
|
|
237
|
-
*/
|
|
238
|
-
async count(): Promise<number> {
|
|
239
|
-
const result = await dbAll<{ count: number }>(
|
|
240
|
-
this.db,
|
|
241
|
-
`SELECT COUNT(*) as count FROM consolidated_memories`
|
|
242
|
-
);
|
|
243
|
-
return result[0]?.count || 0;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Get most accessed memories (for importance scoring)
|
|
248
|
-
*/
|
|
249
|
-
async getMostAccessed(limit: number = 10): Promise<ConsolidatedMemory[]> {
|
|
250
|
-
const rows = await dbAll<Record<string, unknown>>(
|
|
251
|
-
this.db,
|
|
252
|
-
`SELECT * FROM consolidated_memories
|
|
253
|
-
WHERE access_count > 0
|
|
254
|
-
ORDER BY access_count DESC
|
|
255
|
-
LIMIT ?`,
|
|
256
|
-
[limit]
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
return rows.map(this.rowToMemory);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Get statistics about consolidated memories
|
|
264
|
-
*/
|
|
265
|
-
async getStats(): Promise<{
|
|
266
|
-
total: number;
|
|
267
|
-
averageConfidence: number;
|
|
268
|
-
topicCounts: Record<string, number>;
|
|
269
|
-
recentCount: number;
|
|
270
|
-
}> {
|
|
271
|
-
const total = await this.count();
|
|
272
|
-
|
|
273
|
-
const avgResult = await dbAll<{ avg: number | null }>(
|
|
274
|
-
this.db,
|
|
275
|
-
`SELECT AVG(confidence) as avg FROM consolidated_memories`
|
|
276
|
-
);
|
|
277
|
-
const averageConfidence = avgResult[0]?.avg || 0;
|
|
278
|
-
|
|
279
|
-
const recentResult = await dbAll<{ count: number }>(
|
|
280
|
-
this.db,
|
|
281
|
-
`SELECT COUNT(*) as count FROM consolidated_memories
|
|
282
|
-
WHERE created_at > datetime('now', '-24 hours')`
|
|
283
|
-
);
|
|
284
|
-
const recentCount = recentResult[0]?.count || 0;
|
|
285
|
-
|
|
286
|
-
// Get topic counts
|
|
287
|
-
const allMemories = await this.getAll({ limit: 1000 });
|
|
288
|
-
const topicCounts: Record<string, number> = {};
|
|
289
|
-
for (const memory of allMemories) {
|
|
290
|
-
for (const topic of memory.topics) {
|
|
291
|
-
topicCounts[topic] = (topicCounts[topic] || 0) + 1;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return {
|
|
296
|
-
total,
|
|
297
|
-
averageConfidence,
|
|
298
|
-
topicCounts,
|
|
299
|
-
recentCount
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Check if source events are already consolidated
|
|
305
|
-
*/
|
|
306
|
-
async isAlreadyConsolidated(eventIds: string[]): Promise<boolean> {
|
|
307
|
-
for (const eventId of eventIds) {
|
|
308
|
-
const result = await dbAll<{ count: number }>(
|
|
309
|
-
this.db,
|
|
310
|
-
`SELECT COUNT(*) as count FROM consolidated_memories
|
|
311
|
-
WHERE source_events LIKE ?`,
|
|
312
|
-
[`%"${eventId}"%`]
|
|
313
|
-
);
|
|
314
|
-
if ((result[0]?.count || 0) > 0) return true;
|
|
315
|
-
}
|
|
316
|
-
return false;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* Get the last consolidation time
|
|
321
|
-
*/
|
|
322
|
-
async getLastConsolidationTime(): Promise<Date | null> {
|
|
323
|
-
const result = await dbAll<{ created_at: string }>(
|
|
324
|
-
this.db,
|
|
325
|
-
`SELECT created_at FROM consolidated_memories
|
|
326
|
-
ORDER BY created_at DESC
|
|
327
|
-
LIMIT 1`
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
if (result.length === 0) return null;
|
|
331
|
-
return new Date(result[0].created_at);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Convert database row to ConsolidatedMemory
|
|
336
|
-
*/
|
|
337
|
-
private rowToMemory(row: Record<string, unknown>): ConsolidatedMemory {
|
|
338
|
-
return {
|
|
339
|
-
memoryId: row.memory_id as string,
|
|
340
|
-
summary: row.summary as string,
|
|
341
|
-
topics: JSON.parse(row.topics as string || '[]'),
|
|
342
|
-
sourceEvents: JSON.parse(row.source_events as string || '[]'),
|
|
343
|
-
confidence: row.confidence as number,
|
|
344
|
-
createdAt: toDate(row.created_at),
|
|
345
|
-
accessedAt: row.accessed_at ? toDate(row.accessed_at) : undefined,
|
|
346
|
-
accessCount: row.access_count as number || 0
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Create a Consolidated Store instance
|
|
353
|
-
*/
|
|
354
|
-
export function createConsolidatedStore(eventStore: EventStore): ConsolidatedStore {
|
|
355
|
-
return new ConsolidatedStore(eventStore);
|
|
356
|
-
}
|