cortex-mcp 2.4.0 → 2.6.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.
- package/CHANGELOG.md +49 -1
- package/README.md +35 -39
- package/dist/memory/access-pattern-tracker.d.ts +51 -0
- package/dist/memory/access-pattern-tracker.d.ts.map +1 -0
- package/dist/memory/access-pattern-tracker.js +92 -0
- package/dist/memory/access-pattern-tracker.js.map +1 -0
- package/dist/memory/auto-learner.d.ts.map +1 -1
- package/dist/memory/auto-learner.js +33 -2
- package/dist/memory/auto-learner.js.map +1 -1
- package/dist/memory/cross-memory-linker.d.ts +18 -0
- package/dist/memory/cross-memory-linker.d.ts.map +1 -0
- package/dist/memory/cross-memory-linker.js +115 -0
- package/dist/memory/cross-memory-linker.js.map +1 -0
- package/dist/memory/daily-diary.d.ts +30 -0
- package/dist/memory/daily-diary.d.ts.map +1 -0
- package/dist/memory/daily-diary.js +159 -0
- package/dist/memory/daily-diary.js.map +1 -0
- package/dist/memory/embedding-cache.d.ts +32 -0
- package/dist/memory/embedding-cache.d.ts.map +1 -0
- package/dist/memory/embedding-cache.js +76 -0
- package/dist/memory/embedding-cache.js.map +1 -0
- package/dist/memory/memory-decay.d.ts.map +1 -1
- package/dist/memory/memory-decay.js +23 -6
- package/dist/memory/memory-decay.js.map +1 -1
- package/dist/memory/memory-export-md.d.ts +12 -0
- package/dist/memory/memory-export-md.d.ts.map +1 -0
- package/dist/memory/memory-export-md.js +188 -0
- package/dist/memory/memory-export-md.js.map +1 -0
- package/dist/memory/memory-ranker.d.ts.map +1 -1
- package/dist/memory/memory-ranker.js +7 -2
- package/dist/memory/memory-ranker.js.map +1 -1
- package/dist/memory/mmr-reranker.d.ts +39 -0
- package/dist/memory/mmr-reranker.d.ts.map +1 -0
- package/dist/memory/mmr-reranker.js +115 -0
- package/dist/memory/mmr-reranker.js.map +1 -0
- package/dist/memory/query-expansion.d.ts +28 -0
- package/dist/memory/query-expansion.d.ts.map +1 -0
- package/dist/memory/query-expansion.js +140 -0
- package/dist/memory/query-expansion.js.map +1 -0
- package/dist/memory/soul-manager.d.ts +30 -0
- package/dist/memory/soul-manager.d.ts.map +1 -0
- package/dist/memory/soul-manager.js +171 -0
- package/dist/memory/soul-manager.js.map +1 -0
- package/dist/server/mcp-handler.d.ts.map +1 -1
- package/dist/server/mcp-handler.js +119 -48
- package/dist/server/mcp-handler.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Cortex MCP Server are documented here.
|
|
4
4
|
|
|
5
|
-
## [2.
|
|
5
|
+
## [2.4.0] -- 2026-03-03
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Independent importance scoring** — Memories scored by type (CORRECTION=0.85, INSIGHT=0.55) + content signal boosts (file paths, error keywords, version numbers)
|
|
10
|
+
- **Topic tag extraction** — Auto-tags memories with technologies, domains, and actions (`['typescript', 'auth', 'database', 'testing']`)
|
|
11
|
+
- **FTS resolved filter** — Full-text search excludes resolved-tagged memories from results
|
|
12
|
+
- **Code block safety** — `splitSentences` strips ``` fenced blocks and inline code before extraction
|
|
13
|
+
- **Dashboard auto-refresh** — Auto-refreshes every 30 seconds via meta tag
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **Action field** — Now stores source (`auto_learn:decision`) instead of duplicating intent content
|
|
18
|
+
|
|
19
|
+
## [2.3.1] -- 2026-03-03
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
|
|
23
|
+
- **Dead code: `event-bus.ts`** — 60 lines, 0 imports anywhere in codebase
|
|
24
|
+
- **Dead method: `cleanFTSQuery()`** — Unused private method in hybrid-retriever.ts
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **Memory decay Step 5** — Deactivate resolved memories >7 days old
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **Lint** — Prefixed unused `_confidence` parameter in completion-resolver.ts
|
|
33
|
+
- **README** — Updated "What's New in v2.0" → "What's New in v2.3"
|
|
34
|
+
|
|
35
|
+
## [2.3.0] -- 2026-03-03
|
|
36
|
+
|
|
37
|
+
### Fixed (Critical Brain Bugs)
|
|
38
|
+
|
|
39
|
+
- **Markdown bullet extraction** — `splitSentences()` now splits on newlines and bullets, not just periods. 4x more memories extracted from AI responses
|
|
40
|
+
- **Solo developer capture** — Added "I used/chose/picked" patterns (was only "we used")
|
|
41
|
+
- **DECISION vs CORRECTION misclassification** — Raised DECISION confidence to 0.78 (was 0.70, CORRECTION's "instead of" won at 0.75)
|
|
42
|
+
- **Completion resolver wired** — `completion-resolver.ts` was dead code, now integrated into `handleAutoLearn`
|
|
43
|
+
- **Ranker resolved penalty** — Resolved-tagged memories score 85% lower (0.15x multiplier)
|
|
44
|
+
- **Context builder filter** — Excludes resolved memories from context output
|
|
45
|
+
|
|
46
|
+
## [2.2.0] -- 2026-03-02
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- **20 MCP tools** — Added `review_code`, `pre_check`, `check_impact`, `resume_work`
|
|
51
|
+
- **Attention ranking** — Debugging context boosts bug-fix memories, coding boosts conventions
|
|
52
|
+
- **Meta-memory** — Knowledge gap detection for files with zero memories
|
|
53
|
+
- **Memory consolidation** — Duplicate memories merge, keeping highest importance
|
|
6
54
|
|
|
7
55
|
### Fixed
|
|
8
56
|
|
package/README.md
CHANGED
|
@@ -10,18 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
Cortex is an MCP (Model Context Protocol) server that provides persistent, intelligent memory to any AI coding assistant — Cursor, Claude Code, Windsurf, Cline, or any MCP-compatible tool.
|
|
12
12
|
|
|
13
|
-
## What's New in v2.
|
|
14
|
-
|
|
13
|
+
## What's New in v2.4
|
|
14
|
+
|
|
15
|
+
- **🧠 Smart importance scoring** — Memories ranked by type (CORRECTION > INSIGHT) + content signals (file paths, error keywords boost importance)
|
|
16
|
+
- **🏷️ Auto topic tags** — Memories auto-tagged with technologies, domains, and actions (`['typescript', 'auth', 'database']`)
|
|
17
|
+
- **🏁 Task completion tracking** — Say "finished SEO work" and old SEO memories get demoted automatically
|
|
18
|
+
- **🔍 Resolved memory filtering** — FTS search, ranker, and context builder all exclude completed work
|
|
19
|
+
- **🛡️ Code block safety** — Auto-learn no longer extracts from code blocks (no `const foo = bar()` as memories)
|
|
20
|
+
- **📊 Dashboard auto-refresh** — Updates every 30 seconds
|
|
15
21
|
- **Free LLM integration** — Add `OPENROUTER_API_KEY` for 3x smarter memory extraction (zero cost!)
|
|
16
|
-
-
|
|
17
|
-
- **💡 Tip of the day** — Random useful memory surfaced every session
|
|
22
|
+
- **40+ auto-learn patterns** — Captures decisions, corrections, conventions, bug fixes from AI responses
|
|
18
23
|
- **Error fingerprints** — Auto-captures stack traces, TS errors, npm failures for instant fix recall
|
|
19
24
|
- **Success tracking** — Detects "that worked!" and stores proven approaches
|
|
20
|
-
- **Project memory filtering** — Memories boosted for current project, penalized for others
|
|
21
|
-
- **Git-enhanced resume** — Shows recent commits when resuming work
|
|
22
25
|
- **Brain Health Score** — Gamified 0-100 score with grades (Newborn → Genius)
|
|
23
|
-
- **
|
|
24
|
-
- **Cross-platform fixes** — Windows-compatible git commands, proper stderr handling
|
|
26
|
+
- **Git-enhanced resume** — Shows recent commits + branch context when resuming work
|
|
25
27
|
|
|
26
28
|
See [CHANGELOG.md](CHANGELOG.md) for full details.
|
|
27
29
|
|
|
@@ -126,16 +128,6 @@ Then add to your MCP config:
|
|
|
126
128
|
|
|
127
129
|
Restart your IDE and Cortex is active.
|
|
128
130
|
|
|
129
|
-
### Option 3: Direct Download (Binaries)
|
|
130
|
-
|
|
131
|
-
No Node.js required. Download from the latest release:
|
|
132
|
-
|
|
133
|
-
- [Windows](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/releases/latest/download/cortex-win.exe)
|
|
134
|
-
- [macOS](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/releases/latest/download/cortex-macos)
|
|
135
|
-
- [Linux](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/releases/latest/download/cortex-linux)
|
|
136
|
-
|
|
137
|
-
Then configure your MCP client to run the executable directly.
|
|
138
|
-
|
|
139
131
|
### Try the Demo
|
|
140
132
|
|
|
141
133
|
See Cortex in action without any AI client:
|
|
@@ -168,26 +160,30 @@ Step-by-step instructions for your IDE: **[Cursor · Claude Code · Windsurf ·
|
|
|
168
160
|
| **Setup** | `npm i -g cortex-mcp` + 1 config line | Varies |
|
|
169
161
|
| **Offline** | 100% local SQLite (no API key needed) | Often requires API |
|
|
170
162
|
|
|
171
|
-
###
|
|
172
|
-
|
|
173
|
-
| Tool | Purpose
|
|
174
|
-
| ----------------- |
|
|
175
|
-
| `force_recall` | Full brain dump at conversation start (12+ layer pipeline)
|
|
176
|
-
| `recall_memory` | Search memories by topic (FTS + vector + graph)
|
|
177
|
-
| `store_memory` | Store a decision, correction, convention, or bug fix
|
|
178
|
-
| `quick_store` | One-liner memory storage with auto-classification
|
|
179
|
-
| `auto_learn` | Extract memories from AI responses automatically
|
|
180
|
-
| `scan_project` | Scan project structure, stack, git, exports, architecture
|
|
181
|
-
| `verify_code` | Check if imports/exports/env vars actually exist
|
|
182
|
-
| `verify_files` | Check if file paths are real or hallucinated
|
|
183
|
-
| `get_context` | Get compressed context for current file
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
188
|
-
| `
|
|
189
|
-
| `
|
|
190
|
-
| `
|
|
163
|
+
### 20 MCP Tools
|
|
164
|
+
|
|
165
|
+
| Tool | Purpose |
|
|
166
|
+
| ----------------- | ---------------------------------------------------------------------------------- |
|
|
167
|
+
| `force_recall` | Full brain dump at conversation start (12+ layer pipeline) |
|
|
168
|
+
| `recall_memory` | Search memories by topic (FTS + vector + graph) |
|
|
169
|
+
| `store_memory` | Store a decision, correction, convention, or bug fix |
|
|
170
|
+
| `quick_store` | One-liner memory storage with auto-classification |
|
|
171
|
+
| `auto_learn` | Extract memories from AI responses automatically |
|
|
172
|
+
| `scan_project` | Scan project structure, stack, git, exports, architecture |
|
|
173
|
+
| `verify_code` | Check if imports/exports/env vars actually exist |
|
|
174
|
+
| `verify_files` | Check if file paths are real or hallucinated |
|
|
175
|
+
| `get_context` | Get compressed context for current file |
|
|
176
|
+
| `review_code` | Review code against stored conventions and past bug patterns |
|
|
177
|
+
| `pre_check` | Pre-flight check before editing — get all conventions and past bugs for a file |
|
|
178
|
+
| `check_impact` | Impact analysis — check which files depend on the file you plan to modify |
|
|
179
|
+
| `resume_work` | Resume after a break — get last session summary, recent corrections, pending tasks |
|
|
180
|
+
| `get_stats` | Memory database statistics |
|
|
181
|
+
| `list_memories` | List all active memories |
|
|
182
|
+
| `update_memory` | Update an existing memory |
|
|
183
|
+
| `delete_memory` | Delete a memory |
|
|
184
|
+
| `export_memories` | Export all memories to JSON |
|
|
185
|
+
| `import_memories` | Import memories from JSON |
|
|
186
|
+
| `health_check` | Server health check |
|
|
191
187
|
|
|
192
188
|
### 12+ Layer Brain Pipeline
|
|
193
189
|
|
|
@@ -369,7 +365,7 @@ graph TB
|
|
|
369
365
|
- **Windows**: Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
|
370
366
|
- **macOS**: Run `xcode-select --install`
|
|
371
367
|
- **Linux**: Run `sudo apt-get install build-essential python3`
|
|
372
|
-
|
|
368
|
+
</details>
|
|
373
369
|
|
|
374
370
|
<details>
|
|
375
371
|
<summary><strong>License key not working</strong></summary>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access Pattern Tracker — Learns which memory types each user actually uses.
|
|
3
|
+
*
|
|
4
|
+
* Tracks recall/search patterns and builds a personal preference profile.
|
|
5
|
+
* The ranker uses this to boost memory types the user accesses most often.
|
|
6
|
+
*
|
|
7
|
+
* Example: If a user recalls CORRECTION memories 5x more than INSIGHT,
|
|
8
|
+
* future results boost CORRECTIONs so the brain feels personalized.
|
|
9
|
+
*/
|
|
10
|
+
import { MemoryStore } from '../db/memory-store';
|
|
11
|
+
export interface AccessProfile {
|
|
12
|
+
typeCounts: Record<string, number>;
|
|
13
|
+
totalAccesses: number;
|
|
14
|
+
lastUpdated: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Record that the user accessed a memory of a given type.
|
|
18
|
+
* Called whenever recall_memory, force_recall, or pre_check returns results.
|
|
19
|
+
*/
|
|
20
|
+
export declare function recordAccess(type: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Record accesses for a batch of recalled memories.
|
|
23
|
+
*/
|
|
24
|
+
export declare function recordBatchAccess(memories: Array<{
|
|
25
|
+
type: string;
|
|
26
|
+
}>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get a personalized boost multiplier for a memory type.
|
|
29
|
+
* Types the user accesses frequently get boosted (up to 1.8x).
|
|
30
|
+
* Types never accessed stay at 1.0x (neutral).
|
|
31
|
+
*
|
|
32
|
+
* Uses frequency ratio: (type_count / total) normalized to 1.0-1.8 range.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getPersonalBoost(type: string): number;
|
|
35
|
+
/**
|
|
36
|
+
* Get the full access profile (for dashboard/stats).
|
|
37
|
+
*/
|
|
38
|
+
export declare function getAccessProfile(): AccessProfile;
|
|
39
|
+
/**
|
|
40
|
+
* Try to load access profile from stored memories (persistence across restarts).
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadAccessProfile(memoryStore: MemoryStore): void;
|
|
43
|
+
/**
|
|
44
|
+
* Get top accessed types (for diagnostics).
|
|
45
|
+
*/
|
|
46
|
+
export declare function getTopTypes(n?: number): Array<{
|
|
47
|
+
type: string;
|
|
48
|
+
count: number;
|
|
49
|
+
boost: number;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=access-pattern-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-pattern-tracker.d.ts","sourceRoot":"","sources":["../../src/memory/access-pattern-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC1B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACvB;AASD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI/C;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAIzE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYrD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAkBhE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,GAAE,MAAU,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAShG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordAccess = recordAccess;
|
|
4
|
+
exports.recordBatchAccess = recordBatchAccess;
|
|
5
|
+
exports.getPersonalBoost = getPersonalBoost;
|
|
6
|
+
exports.getAccessProfile = getAccessProfile;
|
|
7
|
+
exports.loadAccessProfile = loadAccessProfile;
|
|
8
|
+
exports.getTopTypes = getTopTypes;
|
|
9
|
+
// In-memory access profile (persisted via session tracker)
|
|
10
|
+
let accessProfile = {
|
|
11
|
+
typeCounts: {},
|
|
12
|
+
totalAccesses: 0,
|
|
13
|
+
lastUpdated: Date.now(),
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Record that the user accessed a memory of a given type.
|
|
17
|
+
* Called whenever recall_memory, force_recall, or pre_check returns results.
|
|
18
|
+
*/
|
|
19
|
+
function recordAccess(type) {
|
|
20
|
+
accessProfile.typeCounts[type] = (accessProfile.typeCounts[type] || 0) + 1;
|
|
21
|
+
accessProfile.totalAccesses++;
|
|
22
|
+
accessProfile.lastUpdated = Date.now();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Record accesses for a batch of recalled memories.
|
|
26
|
+
*/
|
|
27
|
+
function recordBatchAccess(memories) {
|
|
28
|
+
for (const m of memories) {
|
|
29
|
+
recordAccess(m.type);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get a personalized boost multiplier for a memory type.
|
|
34
|
+
* Types the user accesses frequently get boosted (up to 1.8x).
|
|
35
|
+
* Types never accessed stay at 1.0x (neutral).
|
|
36
|
+
*
|
|
37
|
+
* Uses frequency ratio: (type_count / total) normalized to 1.0-1.8 range.
|
|
38
|
+
*/
|
|
39
|
+
function getPersonalBoost(type) {
|
|
40
|
+
if (accessProfile.totalAccesses < 10)
|
|
41
|
+
return 1.0; // Not enough data yet
|
|
42
|
+
const typeCount = accessProfile.typeCounts[type] || 0;
|
|
43
|
+
const frequency = typeCount / accessProfile.totalAccesses;
|
|
44
|
+
// Expected frequency if all types were equal (~20% with 5 types)
|
|
45
|
+
const expectedFreq = 0.2;
|
|
46
|
+
// Boost = 1.0 + (frequency - expected) * scale, clamped to [0.7, 1.8]
|
|
47
|
+
const boost = 1.0 + (frequency - expectedFreq) * 4.0;
|
|
48
|
+
return Math.max(0.7, Math.min(1.8, boost));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get the full access profile (for dashboard/stats).
|
|
52
|
+
*/
|
|
53
|
+
function getAccessProfile() {
|
|
54
|
+
return { ...accessProfile };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Try to load access profile from stored memories (persistence across restarts).
|
|
58
|
+
*/
|
|
59
|
+
function loadAccessProfile(memoryStore) {
|
|
60
|
+
try {
|
|
61
|
+
const profileMemories = memoryStore.getByType('INSIGHT', 100);
|
|
62
|
+
// Reconstruct from access_count of each type
|
|
63
|
+
const all = memoryStore.getActive(500);
|
|
64
|
+
const typeCounts = {};
|
|
65
|
+
let total = 0;
|
|
66
|
+
for (const m of all) {
|
|
67
|
+
const count = m.accessCount || 0;
|
|
68
|
+
if (count > 0) {
|
|
69
|
+
typeCounts[m.type] = (typeCounts[m.type] || 0) + count;
|
|
70
|
+
total += count;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (total > 0) {
|
|
74
|
+
accessProfile = { typeCounts, totalAccesses: total, lastUpdated: Date.now() };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { /* fresh install, no data yet */ }
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get top accessed types (for diagnostics).
|
|
81
|
+
*/
|
|
82
|
+
function getTopTypes(n = 5) {
|
|
83
|
+
return Object.entries(accessProfile.typeCounts)
|
|
84
|
+
.sort(([, a], [, b]) => b - a)
|
|
85
|
+
.slice(0, n)
|
|
86
|
+
.map(([type, count]) => ({
|
|
87
|
+
type,
|
|
88
|
+
count,
|
|
89
|
+
boost: getPersonalBoost(type),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=access-pattern-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-pattern-tracker.js","sourceRoot":"","sources":["../../src/memory/access-pattern-tracker.ts"],"names":[],"mappings":";;AA4BA,oCAIC;AAKD,8CAIC;AASD,4CAYC;AAKD,4CAEC;AAKD,8CAkBC;AAKD,kC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,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC;KAChC,CAAC,CAAC,CAAC;AACZ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-learner.d.ts","sourceRoot":"","sources":["../../src/memory/auto-learner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,GACnF,gBAAgB,GAAG,eAAe,GAAG,QAAQ,GAAG,cAAc,CAAC;AAErE,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAClB;AAmRD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"auto-learner.d.ts","sourceRoot":"","sources":["../../src/memory/auto-learner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,SAAS,GACnF,gBAAgB,GAAG,eAAe,GAAG,QAAQ,GAAG,cAAc,CAAC;AAErE,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAClB;AAmRD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,CA0D/D"}
|
|
@@ -262,7 +262,8 @@ function extractMemories(text) {
|
|
|
262
262
|
const sentences = splitSentences(text);
|
|
263
263
|
const results = [];
|
|
264
264
|
const seen = new Set();
|
|
265
|
-
for (
|
|
265
|
+
for (let i = 0; i < sentences.length; i++) {
|
|
266
|
+
const sentence = sentences[i];
|
|
266
267
|
// Collect ALL matching patterns for this sentence
|
|
267
268
|
const candidates = [];
|
|
268
269
|
for (const pattern of PATTERNS) {
|
|
@@ -295,14 +296,44 @@ function extractMemories(text) {
|
|
|
295
296
|
if (seen.has(key))
|
|
296
297
|
continue;
|
|
297
298
|
seen.add(key);
|
|
299
|
+
// --- NEW: Extract real reasoning from context ---
|
|
300
|
+
const reason = extractReason(sentence, sentences, i) || best.reason;
|
|
298
301
|
results.push({
|
|
299
302
|
type: best.type,
|
|
300
303
|
content,
|
|
301
304
|
confidence: best.confidence,
|
|
302
|
-
reason
|
|
305
|
+
reason,
|
|
303
306
|
});
|
|
304
307
|
}
|
|
305
308
|
// Return only high-confidence matches (avoid noise)
|
|
306
309
|
return results.filter(r => r.confidence >= 0.55);
|
|
307
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Extract the REAL reason from context — looks for "because", "since", "due to" etc.
|
|
313
|
+
* If the reason clause is in the same sentence, extract it.
|
|
314
|
+
* If it's in the next sentence, grab that as context.
|
|
315
|
+
*/
|
|
316
|
+
function extractReason(sentence, allSentences, index) {
|
|
317
|
+
// Check for inline reasoning: "X because Y", "X since Y", "X due to Y"
|
|
318
|
+
const reasonPatterns = [
|
|
319
|
+
/\b(?:because|since|as)\s+(.{10,120})/i,
|
|
320
|
+
/\b(?:due to|caused by|in order to|so that)\s+(.{10,100})/i,
|
|
321
|
+
/\b(?:the reason (?:is|was|being))\s+(.{10,100})/i,
|
|
322
|
+
/\b(?:this (?:is|was) (?:because|needed|required|necessary))\s+(.{10,100})/i,
|
|
323
|
+
];
|
|
324
|
+
for (const pat of reasonPatterns) {
|
|
325
|
+
const match = sentence.match(pat);
|
|
326
|
+
if (match && match[1]) {
|
|
327
|
+
return match[1].replace(/\s+/g, ' ').trim().slice(0, 120);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// Check next sentence for reasoning context
|
|
331
|
+
if (index + 1 < allSentences.length) {
|
|
332
|
+
const next = allSentences[index + 1];
|
|
333
|
+
if (/^(because|since|this is because|the reason|due to|otherwise)/i.test(next.trim())) {
|
|
334
|
+
return next.trim().slice(0, 120);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
308
339
|
//# sourceMappingURL=auto-learner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-learner.js","sourceRoot":"","sources":["../../src/memory/auto-learner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AA6RH,
|
|
1
|
+
{"version":3,"file":"auto-learner.js","sourceRoot":"","sources":["../../src/memory/auto-learner.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AA6RH,0CA0DC;AA3UD,iFAAiF;AAEjF,MAAM,QAAQ,GAKT;IACG,wEAAwE;IACxE;QACI,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACL,4EAA4E;YAC5E,gGAAgG;YAChG,yCAAyC;YACzC,6EAA6E;YAC7E,uEAAuE;YACvE,kEAAkE;SACrE;QACD,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,kCAAkC;KAC7C;IAED,4DAA4D;IAC5D;QACI,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACL,gIAAgI;YAChI,yFAAyF;YACzF,wEAAwE;YACxE,6DAA6D;YAC7D,+DAA+D;YAC/D,sEAAsE;YACtE,iEAAiE;SACpE;QACD,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,gCAAgC;KAC3C;IAED,4DAA4D;IAC5D;QACI,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACL,yEAAyE;YACzE,4EAA4E;YAC5E,8EAA8E;SACjF;QACD,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,6CAA6C;KACxD;IAED,0CAA0C;IAC1C;QACI,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACL,4FAA4F;YAC5F,8EAA8E;YAC9E,4EAA4E;SAC/E;QACD,UAAU,EAAE,IAAI;QACh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C,IAAI,KAAK,GAAG,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC;QAClC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QACrC,IAAI,+DAA+D,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YACpF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-Memory Linker — Automatically creates edges between related memories.
|
|
3
|
+
*
|
|
4
|
+
* When a new memory is stored, this module finds existing memories that share
|
|
5
|
+
* topics, files, or keywords and creates graph edges between them.
|
|
6
|
+
*
|
|
7
|
+
* This transforms isolated memories into a connected knowledge graph.
|
|
8
|
+
* When the user asks "tell me about auth", they get a connected story
|
|
9
|
+
* instead of random fragments.
|
|
10
|
+
*/
|
|
11
|
+
import { MemoryStore } from '../db/memory-store';
|
|
12
|
+
import type { MemoryUnit } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* After storing a new memory, auto-link it to related existing memories.
|
|
15
|
+
* Uses 3 signals: shared files, shared tags, and word overlap.
|
|
16
|
+
*/
|
|
17
|
+
export declare function autoLinkMemory(memoryStore: MemoryStore, newMemory: MemoryUnit): number;
|
|
18
|
+
//# sourceMappingURL=cross-memory-linker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-memory-linker.d.ts","sourceRoot":"","sources":["../../src/memory/cross-memory-linker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,UAAU,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,GAAG,MAAM,CAyEtF"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.autoLinkMemory = autoLinkMemory;
|
|
4
|
+
/**
|
|
5
|
+
* After storing a new memory, auto-link it to related existing memories.
|
|
6
|
+
* Uses 3 signals: shared files, shared tags, and word overlap.
|
|
7
|
+
*/
|
|
8
|
+
function autoLinkMemory(memoryStore, newMemory) {
|
|
9
|
+
let linksCreated = 0;
|
|
10
|
+
try {
|
|
11
|
+
// 1. Find memories sharing the same files
|
|
12
|
+
const fileRelated = [];
|
|
13
|
+
if (newMemory.relatedFiles && newMemory.relatedFiles.length > 0) {
|
|
14
|
+
for (const file of newMemory.relatedFiles.slice(0, 3)) {
|
|
15
|
+
const basename = file.split(/[/\\]/).pop() || file;
|
|
16
|
+
const related = memoryStore.getByFile(basename, 10);
|
|
17
|
+
for (const m of related) {
|
|
18
|
+
if (m.id !== newMemory.id && m.isActive) {
|
|
19
|
+
fileRelated.push(m);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// 2. Find memories sharing tags
|
|
25
|
+
const tagRelated = [];
|
|
26
|
+
const newTags = parseTags(newMemory.tags);
|
|
27
|
+
if (newTags.length > 0) {
|
|
28
|
+
for (const tag of newTags.slice(0, 3)) {
|
|
29
|
+
try {
|
|
30
|
+
const tagged = memoryStore.findByTag(tag, 10);
|
|
31
|
+
for (const m of tagged) {
|
|
32
|
+
if (m.id !== newMemory.id && m.isActive) {
|
|
33
|
+
tagRelated.push(m);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch { /* tag search might fail */ }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// 3. Compute word overlap with recent memories
|
|
41
|
+
const newWords = extractKeywords(newMemory.intent);
|
|
42
|
+
const recentMemories = memoryStore.getActive(50);
|
|
43
|
+
const wordRelated = [];
|
|
44
|
+
for (const m of recentMemories) {
|
|
45
|
+
if (m.id === newMemory.id)
|
|
46
|
+
continue;
|
|
47
|
+
const mWords = extractKeywords(m.intent);
|
|
48
|
+
const overlap = wordOverlap(newWords, mWords);
|
|
49
|
+
if (overlap >= 0.3) { // 30%+ word overlap → related
|
|
50
|
+
wordRelated.push(m);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Deduplicate and create edges
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
const candidates = [...fileRelated, ...tagRelated, ...wordRelated];
|
|
56
|
+
for (const related of candidates) {
|
|
57
|
+
if (seen.has(related.id))
|
|
58
|
+
continue;
|
|
59
|
+
seen.add(related.id);
|
|
60
|
+
if (linksCreated >= 5)
|
|
61
|
+
break; // Max 5 links per memory
|
|
62
|
+
const edgeType = fileRelated.includes(related) ? 'same_file' :
|
|
63
|
+
tagRelated.includes(related) ? 'same_topic' : 'similar';
|
|
64
|
+
try {
|
|
65
|
+
memoryStore.addEdge({
|
|
66
|
+
sourceId: newMemory.id,
|
|
67
|
+
targetId: related.id,
|
|
68
|
+
edgeType,
|
|
69
|
+
weight: edgeType === 'same_file' ? 0.9 :
|
|
70
|
+
edgeType === 'same_topic' ? 0.7 : 0.5,
|
|
71
|
+
});
|
|
72
|
+
linksCreated++;
|
|
73
|
+
}
|
|
74
|
+
catch { /* edge might already exist */ }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch { /* don't break memory storage if linking fails */ }
|
|
78
|
+
return linksCreated;
|
|
79
|
+
}
|
|
80
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
81
|
+
function parseTags(tags) {
|
|
82
|
+
if (!tags)
|
|
83
|
+
return [];
|
|
84
|
+
if (Array.isArray(tags))
|
|
85
|
+
return tags;
|
|
86
|
+
if (typeof tags === 'string') {
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(tags);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
function extractKeywords(text) {
|
|
97
|
+
const STOP = new Set(['the', 'a', 'an', 'is', 'are', 'was', 'were', 'to', 'of', 'in',
|
|
98
|
+
'for', 'on', 'with', 'at', 'by', 'from', 'use', 'always', 'never', 'should',
|
|
99
|
+
'must', 'not', 'do', 'be', 'it', 'this', 'that', 'and', 'or', 'but', 'we', 'i']);
|
|
100
|
+
return new Set(text.toLowerCase()
|
|
101
|
+
.replace(/[^a-z0-9\s]/g, ' ')
|
|
102
|
+
.split(/\s+/)
|
|
103
|
+
.filter(w => w.length > 2 && !STOP.has(w)));
|
|
104
|
+
}
|
|
105
|
+
function wordOverlap(a, b) {
|
|
106
|
+
if (a.size === 0 || b.size === 0)
|
|
107
|
+
return 0;
|
|
108
|
+
let shared = 0;
|
|
109
|
+
for (const word of a) {
|
|
110
|
+
if (b.has(word))
|
|
111
|
+
shared++;
|
|
112
|
+
}
|
|
113
|
+
return shared / Math.min(a.size, b.size);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=cross-memory-linker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-memory-linker.js","sourceRoot":"","sources":["../../src/memory/cross-memory-linker.ts"],"names":[],"mappings":";;AAiBA,wCAyEC;AA7ED;;;GAGG;AACH,SAAgB,cAAc,CAAC,WAAwB,EAAE,SAAqB;IAC1E,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,IAAI,CAAC;QACD,0CAA0C;QAC1C,MAAM,WAAW,GAAiB,EAAE,CAAC;QACrC,IAAI,SAAS,CAAC,YAAY,IAAI,SAAS,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9D,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CA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,cAAc,EAAE,GAAG,CAAC;SAC5B,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACjD,CAAC;AACN,CAAC;AAED,SAAS,WAAW,CAAC,CAAc,EAAE,CAAc;IAC/C,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface DiaryEntry {
|
|
2
|
+
type: 'decision' | 'correction' | 'bug_fix' | 'convention' | 'insight' | 'task' | 'file_change';
|
|
3
|
+
content: string;
|
|
4
|
+
file?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Append an entry to today's diary.
|
|
8
|
+
*/
|
|
9
|
+
export declare function appendDiaryEntry(entry: DiaryEntry): void;
|
|
10
|
+
/**
|
|
11
|
+
* Get diary content for a specific date.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getDiaryForDate(date: string): string | null;
|
|
14
|
+
/**
|
|
15
|
+
* Get the last N days of diary entries combined.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getRecentDiary(days?: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* Format diary context for injection into force_recall.
|
|
20
|
+
* Returns last 2 days of diary, condensed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatDiaryContext(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get diary stats for dashboard.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getDiaryStats(): {
|
|
27
|
+
totalDays: number;
|
|
28
|
+
todayEntries: number;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=daily-diary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-diary.d.ts","sourceRoot":"","sources":["../../src/memory/daily-diary.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,aAAa,CAAC;IAChG,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAoBxD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,GAAE,MAAU,GAAG,MAAM,CAevD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAU3C;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAY3E"}
|