claude-cortex 1.0.0

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.
Files changed (102) hide show
  1. package/README.md +291 -0
  2. package/dist/api/events.d.ts +134 -0
  3. package/dist/api/events.d.ts.map +1 -0
  4. package/dist/api/events.js +73 -0
  5. package/dist/api/events.js.map +1 -0
  6. package/dist/api/visualization-server.d.ts +11 -0
  7. package/dist/api/visualization-server.d.ts.map +1 -0
  8. package/dist/api/visualization-server.js +653 -0
  9. package/dist/api/visualization-server.js.map +1 -0
  10. package/dist/context/project-context.d.ts +57 -0
  11. package/dist/context/project-context.d.ts.map +1 -0
  12. package/dist/context/project-context.js +135 -0
  13. package/dist/context/project-context.js.map +1 -0
  14. package/dist/database/init.d.ts +49 -0
  15. package/dist/database/init.d.ts.map +1 -0
  16. package/dist/database/init.js +336 -0
  17. package/dist/database/init.js.map +1 -0
  18. package/dist/embeddings/generator.d.ts +20 -0
  19. package/dist/embeddings/generator.d.ts.map +1 -0
  20. package/dist/embeddings/generator.js +77 -0
  21. package/dist/embeddings/generator.js.map +1 -0
  22. package/dist/embeddings/index.d.ts +2 -0
  23. package/dist/embeddings/index.d.ts.map +1 -0
  24. package/dist/embeddings/index.js +2 -0
  25. package/dist/embeddings/index.js.map +1 -0
  26. package/dist/errors.d.ts +74 -0
  27. package/dist/errors.d.ts.map +1 -0
  28. package/dist/errors.js +131 -0
  29. package/dist/errors.js.map +1 -0
  30. package/dist/index.d.ts +16 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +83 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/memory/activation.d.ts +69 -0
  35. package/dist/memory/activation.d.ts.map +1 -0
  36. package/dist/memory/activation.js +168 -0
  37. package/dist/memory/activation.js.map +1 -0
  38. package/dist/memory/consolidate.d.ts +96 -0
  39. package/dist/memory/consolidate.d.ts.map +1 -0
  40. package/dist/memory/consolidate.js +400 -0
  41. package/dist/memory/consolidate.js.map +1 -0
  42. package/dist/memory/contradiction.d.ts +69 -0
  43. package/dist/memory/contradiction.d.ts.map +1 -0
  44. package/dist/memory/contradiction.js +286 -0
  45. package/dist/memory/contradiction.js.map +1 -0
  46. package/dist/memory/decay.d.ts +62 -0
  47. package/dist/memory/decay.d.ts.map +1 -0
  48. package/dist/memory/decay.js +184 -0
  49. package/dist/memory/decay.js.map +1 -0
  50. package/dist/memory/salience.d.ts +36 -0
  51. package/dist/memory/salience.d.ts.map +1 -0
  52. package/dist/memory/salience.js +200 -0
  53. package/dist/memory/salience.js.map +1 -0
  54. package/dist/memory/similarity.d.ts +57 -0
  55. package/dist/memory/similarity.d.ts.map +1 -0
  56. package/dist/memory/similarity.js +114 -0
  57. package/dist/memory/similarity.js.map +1 -0
  58. package/dist/memory/store.d.ts +170 -0
  59. package/dist/memory/store.d.ts.map +1 -0
  60. package/dist/memory/store.js +973 -0
  61. package/dist/memory/store.js.map +1 -0
  62. package/dist/memory/types.d.ts +91 -0
  63. package/dist/memory/types.d.ts.map +1 -0
  64. package/dist/memory/types.js +30 -0
  65. package/dist/memory/types.js.map +1 -0
  66. package/dist/server.d.ts +12 -0
  67. package/dist/server.d.ts.map +1 -0
  68. package/dist/server.js +466 -0
  69. package/dist/server.js.map +1 -0
  70. package/dist/tools/context.d.ts +135 -0
  71. package/dist/tools/context.d.ts.map +1 -0
  72. package/dist/tools/context.js +273 -0
  73. package/dist/tools/context.js.map +1 -0
  74. package/dist/tools/forget.d.ts +53 -0
  75. package/dist/tools/forget.d.ts.map +1 -0
  76. package/dist/tools/forget.js +179 -0
  77. package/dist/tools/forget.js.map +1 -0
  78. package/dist/tools/recall.d.ts +74 -0
  79. package/dist/tools/recall.d.ts.map +1 -0
  80. package/dist/tools/recall.js +140 -0
  81. package/dist/tools/recall.js.map +1 -0
  82. package/dist/tools/remember.d.ts +65 -0
  83. package/dist/tools/remember.d.ts.map +1 -0
  84. package/dist/tools/remember.js +147 -0
  85. package/dist/tools/remember.js.map +1 -0
  86. package/dist/worker/brain-worker.d.ts +100 -0
  87. package/dist/worker/brain-worker.d.ts.map +1 -0
  88. package/dist/worker/brain-worker.js +261 -0
  89. package/dist/worker/brain-worker.js.map +1 -0
  90. package/dist/worker/link-discovery.d.ts +47 -0
  91. package/dist/worker/link-discovery.d.ts.map +1 -0
  92. package/dist/worker/link-discovery.js +103 -0
  93. package/dist/worker/link-discovery.js.map +1 -0
  94. package/dist/worker/predictive-consolidation.d.ts +46 -0
  95. package/dist/worker/predictive-consolidation.d.ts.map +1 -0
  96. package/dist/worker/predictive-consolidation.js +110 -0
  97. package/dist/worker/predictive-consolidation.js.map +1 -0
  98. package/dist/worker/types.d.ts +91 -0
  99. package/dist/worker/types.d.ts.map +1 -0
  100. package/dist/worker/types.js +22 -0
  101. package/dist/worker/types.js.map +1 -0
  102. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # Claude Cortex 🧠
2
+
3
+ **Brain-like memory system for Claude Code** - Solves the context compaction and memory persistence problems.
4
+
5
+ ## The Problem
6
+
7
+ Claude Code has fundamental limitations:
8
+
9
+ 1. **Context Window Exhaustion** - Long sessions hit token limits
10
+ 2. **Compaction Loss** - When context is summarized, important details are lost
11
+ 3. **No Persistence** - Knowledge doesn't survive across sessions
12
+
13
+ ## The Solution
14
+
15
+ Claude Memory works like a human brain:
16
+
17
+ - **Short-term memory** - Session-level, high detail, decays fast
18
+ - **Long-term memory** - Cross-session, consolidated, persists
19
+ - **Episodic memory** - Specific events and successful patterns
20
+ - **Salience detection** - Automatically identifies what's worth remembering
21
+ - **Temporal decay** - Memories fade but can be reinforced through access
22
+ - **Consolidation** - Like sleep, moves worthy memories to long-term storage
23
+
24
+ ## Quick Start
25
+
26
+ ### 1. Install
27
+
28
+ **Option A: Install via npm (Recommended)**
29
+
30
+ ```bash
31
+ npm install -g claude-cortex
32
+ ```
33
+
34
+ **Option B: Use with npx (no install)**
35
+
36
+ Configure directly in `.mcp.json` (see step 2).
37
+
38
+ **Option C: From source**
39
+
40
+ ```bash
41
+ git clone https://github.com/mkdelta221/claude-cortex.git
42
+ cd claude-cortex
43
+ npm install
44
+ npm run build
45
+ ```
46
+
47
+ ### 2. Configure Claude Code
48
+
49
+ **Option A: Project-scoped (recommended for testing)**
50
+
51
+ Create `.mcp.json` in your project directory:
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "memory": {
57
+ "type": "stdio",
58
+ "command": "npx",
59
+ "args": ["-y", "claude-cortex"]
60
+ }
61
+ }
62
+ }
63
+ ```
64
+
65
+ **Option B: Global (all projects)**
66
+
67
+ Create `~/.claude/.mcp.json` with the same content.
68
+
69
+ After adding the config, restart Claude Code and approve the MCP server when prompted.
70
+
71
+ ### 3. Configure PreCompact Hook (Recommended)
72
+
73
+ Add to `~/.claude/settings.json` for automatic memory extraction before compaction:
74
+
75
+ ```json
76
+ {
77
+ "hooks": {
78
+ "PreCompact": [
79
+ {
80
+ "matcher": "",
81
+ "hooks": [
82
+ {
83
+ "type": "command",
84
+ "command": "npx -y claude-cortex-hook pre-compact"
85
+ }
86
+ ]
87
+ }
88
+ ]
89
+ }
90
+ }
91
+ ```
92
+
93
+ This ensures important context is auto-saved before any compaction event.
94
+
95
+ ### 3. Use It
96
+
97
+ The memory system integrates seamlessly with Claude Code. Here are the key tools:
98
+
99
+ #### Remember Something
100
+ ```
101
+ Claude, remember that we're using PostgreSQL for the database.
102
+ ```
103
+
104
+ #### Recall Information
105
+ ```
106
+ Claude, what do you know about our database setup?
107
+ ```
108
+
109
+ #### Get Context (Key for Compaction!)
110
+ ```
111
+ Claude, get the context for this project.
112
+ ```
113
+
114
+ ## Tools
115
+
116
+ | Tool | Description |
117
+ |------|-------------|
118
+ | `remember` | Store a memory with auto-categorization and salience detection |
119
+ | `recall` | Search and retrieve memories (semantic search, filters) |
120
+ | `forget` | Delete memories (single or bulk, with safety confirmations) |
121
+ | `get_context` | **THE KEY TOOL** - Get relevant context, especially after compaction |
122
+ | `start_session` | Start a session, get project context |
123
+ | `end_session` | End session, trigger consolidation |
124
+ | `consolidate` | Run memory consolidation manually |
125
+ | `memory_stats` | View memory statistics |
126
+ | `export_memories` | Export as JSON for backup |
127
+ | `import_memories` | Import from JSON |
128
+
129
+ ## Resources
130
+
131
+ The server also exposes MCP resources:
132
+
133
+ | Resource | Description |
134
+ |----------|-------------|
135
+ | `memory://context` | Current memory context summary |
136
+ | `memory://important` | High-priority memories |
137
+ | `memory://recent` | Recently accessed memories |
138
+
139
+ ## How It Works
140
+
141
+ ### Salience Detection
142
+
143
+ Not everything is worth remembering. The system scores information on:
144
+
145
+ | Factor | Weight | Example |
146
+ |--------|--------|---------|
147
+ | Explicit request | 1.0 | "Remember this" |
148
+ | Architecture decision | 0.9 | "We're using microservices" |
149
+ | Error resolution | 0.8 | "Fixed by updating X" |
150
+ | Code pattern | 0.7 | "Use this approach for auth" |
151
+ | User preference | 0.7 | "Always use strict mode" |
152
+ | Code references | 0.5 | Mentions specific files/functions |
153
+ | Emotional markers | 0.5 | "Important", "critical" |
154
+
155
+ ### Temporal Decay
156
+
157
+ Like human memory:
158
+
159
+ ```
160
+ score = base_salience × (0.995 ^ hours_since_access)
161
+ ```
162
+
163
+ - **Decay**: Memories fade over time
164
+ - **Reinforcement**: Each access boosts score by 1.2×
165
+ - **Consolidation**: Frequently accessed short-term → long-term
166
+
167
+ ### Memory Types
168
+
169
+ | Type | Decay Rate | Use Case |
170
+ |------|------------|----------|
171
+ | Short-term | Fast (hourly) | Current session, debugging |
172
+ | Long-term | Slow (daily) | Architecture, patterns |
173
+ | Episodic | Medium | Specific events, learnings |
174
+
175
+ ## Solving the Compaction Problem
176
+
177
+ When Claude Code compacts context:
178
+
179
+ 1. **Before compaction** - The PreCompact hook **automatically extracts** important content
180
+ 2. **After compaction** - Use `get_context` to restore what's relevant
181
+
182
+ ### Automatic Memory Extraction (PreCompact Hook)
183
+
184
+ The system includes a hook that runs before every context compaction:
185
+
186
+ ```
187
+ 🧠 AUTO-MEMORY: 3 important items were automatically saved before compaction.
188
+ After compaction, use 'get_context' to retrieve your memories.
189
+ ```
190
+
191
+ **What gets auto-extracted:**
192
+ - Decisions: "decided to...", "going with...", "chose..."
193
+ - Error fixes: "fixed by...", "the solution was...", "root cause..."
194
+ - Learnings: "learned that...", "discovered...", "turns out..."
195
+ - Architecture: "the architecture uses...", "design pattern..."
196
+ - Preferences: "always...", "never...", "prefer to..."
197
+ - Important notes: "important:", "remember:", "key point..."
198
+
199
+ Auto-extracted memories are:
200
+ - Tagged with `auto-extracted` for easy filtering
201
+ - Scored using salience detection (only high-scoring items saved)
202
+ - Limited to 5 per compaction to avoid noise
203
+
204
+ ### Example Workflow
205
+
206
+ ```
207
+ # Session starts
208
+ Claude: Let me get the project context.
209
+ [Calls get_context tool]
210
+ > Found: PostgreSQL database, React frontend, auth uses JWT...
211
+
212
+ # Work happens, context grows...
213
+
214
+ # Compaction occurs, context is lost!
215
+
216
+ # You notice Claude forgot something:
217
+ You: Claude, what database are we using?
218
+ Claude: Let me check my memory.
219
+ [Calls recall tool with query "database"]
220
+ > Found: "Using PostgreSQL for the database" (architecture, 95% salience)
221
+ ```
222
+
223
+ ## Configuration
224
+
225
+ ### Database Location
226
+
227
+ Default: `~/.claude-cortex/memories.db` (with fallback to legacy `~/.claude-memory/` for existing users)
228
+
229
+ Custom location:
230
+ ```bash
231
+ node dist/index.js --db /path/to/custom.db
232
+ ```
233
+
234
+ Or in Claude config:
235
+ ```json
236
+ {
237
+ "mcpServers": {
238
+ "memory": {
239
+ "command": "node",
240
+ "args": ["/path/to/dist/index.js", "--db", "/path/to/custom.db"]
241
+ }
242
+ }
243
+ }
244
+ ```
245
+
246
+ ### Tuning Parameters
247
+
248
+ In `src/memory/types.ts`:
249
+
250
+ ```typescript
251
+ export const DEFAULT_CONFIG = {
252
+ decayRate: 0.995, // Per-hour decay factor
253
+ reinforcementFactor: 1.2, // Access boost
254
+ salienceThreshold: 0.3, // Min score to keep
255
+ consolidationThreshold: 0.6, // Min for STM→LTM
256
+ maxShortTermMemories: 100,
257
+ maxLongTermMemories: 1000,
258
+ autoConsolidateHours: 4,
259
+ };
260
+ ```
261
+
262
+ ## Development
263
+
264
+ ```bash
265
+ # Install dependencies
266
+ npm install
267
+
268
+ # Development mode (with tsx)
269
+ npm run dev
270
+
271
+ # Build
272
+ npm run build
273
+
274
+ # Watch mode
275
+ npm run watch
276
+ ```
277
+
278
+ ## How This Differs from Other Solutions
279
+
280
+ | Feature | Claude Memory | Other MCP Memory Tools |
281
+ |---------|--------------|------------------------|
282
+ | Salience detection | ✅ Auto-detects importance | ❌ Manual only |
283
+ | Temporal decay | ✅ Memories fade naturally | ❌ Static storage |
284
+ | Consolidation | ✅ STM → LTM promotion | ❌ Flat storage |
285
+ | Context injection | ✅ `get_context` tool | ❌ Manual recall |
286
+ | Semantic search | ✅ FTS5 full-text | Varies |
287
+ | Episodic memory | ✅ Event/pattern storage | ❌ Usually missing |
288
+
289
+ ## License
290
+
291
+ MIT
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Event Emitter for Memory Events
3
+ *
4
+ * Broadcasts memory changes to connected WebSocket clients
5
+ * for real-time visualization updates.
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ import { Memory, ConsolidationResult } from '../memory/types.js';
9
+ export type MemoryEventType = 'memory_created' | 'memory_accessed' | 'memory_updated' | 'memory_deleted' | 'consolidation_complete' | 'decay_tick' | 'session_started' | 'session_ended' | 'worker_light_tick' | 'worker_medium_tick' | 'link_discovered' | 'predictive_consolidation';
10
+ export interface MemoryEvent {
11
+ type: MemoryEventType;
12
+ timestamp: string;
13
+ data: unknown;
14
+ }
15
+ export interface MemoryCreatedEvent extends MemoryEvent {
16
+ type: 'memory_created';
17
+ data: {
18
+ memory: Memory;
19
+ };
20
+ }
21
+ export interface MemoryAccessedEvent extends MemoryEvent {
22
+ type: 'memory_accessed';
23
+ data: {
24
+ memoryId: number;
25
+ memory: Memory;
26
+ newSalience: number;
27
+ };
28
+ }
29
+ export interface MemoryUpdatedEvent extends MemoryEvent {
30
+ type: 'memory_updated';
31
+ data: {
32
+ memory: Memory;
33
+ };
34
+ }
35
+ export interface MemoryDeletedEvent extends MemoryEvent {
36
+ type: 'memory_deleted';
37
+ data: {
38
+ memoryId: number;
39
+ title: string;
40
+ };
41
+ }
42
+ export interface ConsolidationEvent extends MemoryEvent {
43
+ type: 'consolidation_complete';
44
+ data: ConsolidationResult & {
45
+ promotedMemories: number[];
46
+ deletedMemories: number[];
47
+ };
48
+ }
49
+ export interface DecayTickEvent extends MemoryEvent {
50
+ type: 'decay_tick';
51
+ data: {
52
+ updates: Array<{
53
+ memoryId: number;
54
+ oldScore: number;
55
+ newScore: number;
56
+ }>;
57
+ };
58
+ }
59
+ export interface WorkerLightTickEvent extends MemoryEvent {
60
+ type: 'worker_light_tick';
61
+ data: {
62
+ activationsPruned: number;
63
+ predictiveConsolidation: ConsolidationResult | null;
64
+ timestamp: string;
65
+ };
66
+ }
67
+ export interface WorkerMediumTickEvent extends MemoryEvent {
68
+ type: 'worker_medium_tick';
69
+ data: {
70
+ linksDiscovered: number;
71
+ contradictionsFound: number;
72
+ contradictionsLinked: number;
73
+ memoriesScanned: number;
74
+ timestamp: string;
75
+ };
76
+ }
77
+ export interface LinkDiscoveredEvent extends MemoryEvent {
78
+ type: 'link_discovered';
79
+ data: {
80
+ sourceId: number;
81
+ targetId: number;
82
+ relationship: string;
83
+ strength: number;
84
+ };
85
+ }
86
+ export interface PredictiveConsolidationEvent extends MemoryEvent {
87
+ type: 'predictive_consolidation';
88
+ data: {
89
+ trigger: string;
90
+ urgency: string;
91
+ result: ConsolidationResult;
92
+ };
93
+ }
94
+ declare class MemoryEventEmitter extends EventEmitter {
95
+ emit(event: MemoryEventType, data: MemoryEvent['data']): boolean;
96
+ onMemoryEvent(callback: (event: MemoryEvent) => void): void;
97
+ offMemoryEvent(callback: (event: MemoryEvent) => void): void;
98
+ }
99
+ export declare const memoryEvents: MemoryEventEmitter;
100
+ export declare function emitMemoryCreated(memory: Memory): void;
101
+ export declare function emitMemoryAccessed(memory: Memory, newSalience: number): void;
102
+ export declare function emitMemoryUpdated(memory: Memory): void;
103
+ export declare function emitMemoryDeleted(memoryId: number, title: string): void;
104
+ export declare function emitConsolidation(result: ConsolidationResult, promotedMemories?: number[], deletedMemories?: number[]): void;
105
+ export declare function emitDecayTick(updates: Array<{
106
+ memoryId: number;
107
+ oldScore: number;
108
+ newScore: number;
109
+ }>): void;
110
+ export declare function emitWorkerLightTick(data: {
111
+ activationsPruned: number;
112
+ predictiveConsolidation: ConsolidationResult | null;
113
+ timestamp: Date;
114
+ }): void;
115
+ export declare function emitWorkerMediumTick(data: {
116
+ linksDiscovered: number;
117
+ contradictionsFound: number;
118
+ contradictionsLinked: number;
119
+ memoriesScanned: number;
120
+ timestamp: Date;
121
+ }): void;
122
+ export declare function emitLinkDiscovered(data: {
123
+ sourceId: number;
124
+ targetId: number;
125
+ relationship: string;
126
+ strength: number;
127
+ }): void;
128
+ export declare function emitPredictiveConsolidation(data: {
129
+ trigger: string;
130
+ urgency: string;
131
+ result: ConsolidationResult;
132
+ }): void;
133
+ export {};
134
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/api/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,MAAM,MAAM,eAAe,GACvB,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,GAChB,gBAAgB,GAChB,wBAAwB,GACxB,YAAY,GACZ,iBAAiB,GACjB,eAAe,GAEf,mBAAmB,GACnB,oBAAoB,GACpB,iBAAiB,GACjB,0BAA0B,CAAC;AAE/B,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,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AG,IAAI,CAEP"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Event Emitter for Memory Events
3
+ *
4
+ * Broadcasts memory changes to connected WebSocket clients
5
+ * for real-time visualization updates.
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ // Global event emitter for memory events
9
+ class MemoryEventEmitter extends EventEmitter {
10
+ emit(event, data) {
11
+ const payload = {
12
+ type: event,
13
+ timestamp: new Date().toISOString(),
14
+ data,
15
+ };
16
+ return super.emit('memory_event', payload);
17
+ }
18
+ onMemoryEvent(callback) {
19
+ this.on('memory_event', callback);
20
+ }
21
+ offMemoryEvent(callback) {
22
+ this.off('memory_event', callback);
23
+ }
24
+ }
25
+ // Singleton instance
26
+ export const memoryEvents = new MemoryEventEmitter();
27
+ // Helper functions to emit events
28
+ export function emitMemoryCreated(memory) {
29
+ memoryEvents.emit('memory_created', { memory });
30
+ }
31
+ export function emitMemoryAccessed(memory, newSalience) {
32
+ memoryEvents.emit('memory_accessed', {
33
+ memoryId: memory.id,
34
+ memory,
35
+ newSalience,
36
+ });
37
+ }
38
+ export function emitMemoryUpdated(memory) {
39
+ memoryEvents.emit('memory_updated', { memory });
40
+ }
41
+ export function emitMemoryDeleted(memoryId, title) {
42
+ memoryEvents.emit('memory_deleted', { memoryId, title });
43
+ }
44
+ export function emitConsolidation(result, promotedMemories = [], deletedMemories = []) {
45
+ memoryEvents.emit('consolidation_complete', {
46
+ ...result,
47
+ promotedMemories,
48
+ deletedMemories,
49
+ });
50
+ }
51
+ export function emitDecayTick(updates) {
52
+ memoryEvents.emit('decay_tick', { updates });
53
+ }
54
+ // Phase 4: Worker event emitters
55
+ export function emitWorkerLightTick(data) {
56
+ memoryEvents.emit('worker_light_tick', {
57
+ ...data,
58
+ timestamp: data.timestamp.toISOString(),
59
+ });
60
+ }
61
+ export function emitWorkerMediumTick(data) {
62
+ memoryEvents.emit('worker_medium_tick', {
63
+ ...data,
64
+ timestamp: data.timestamp.toISOString(),
65
+ });
66
+ }
67
+ export function emitLinkDiscovered(data) {
68
+ memoryEvents.emit('link_discovered', data);
69
+ }
70
+ export function emitPredictiveConsolidation(data) {
71
+ memoryEvents.emit('predictive_consolidation', data);
72
+ }
73
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/api/events.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAkHtC,yCAAyC;AACzC,MAAM,kBAAmB,SAAQ,YAAY;IAC3C,IAAI,CAAC,KAAsB,EAAE,IAAyB;QACpD,MAAM,OAAO,GAAgB;YAC3B,IAAI,EAAE,KAAK;YACX,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI;SACL,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,aAAa,CAAC,QAAsC;QAClD,IAAI,CAAC,EAAE,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,cAAc,CAAC,QAAsC;QACnD,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAErD,kCAAkC;AAClC,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,WAAmB;IACpE,YAAY,CAAC,IAAI,CAAC,iBAAiB,EAAE;QACnC,QAAQ,EAAE,MAAM,CAAC,EAAE;QACnB,MAAM;QACN,WAAW;KACZ,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,YA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ocket for the Brain Dashboard.
5
+ * Runs alongside or instead of the MCP server.
6
+ */
7
+ /**
8
+ * Start the visualization API server
9
+ */
10
+ export declare function startVisualizationServer(dbPath?: string): void;
11
+ //# sourceMappingURL=visualization-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visualization-server.d.ts","sourceRoot":"","sources":["../../src/api/visualization-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqCH;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CA0rB9D"}