cortex-mcp 2.8.0 → 3.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 (202) hide show
  1. package/CHANGELOG.md +305 -58
  2. package/README.md +394 -227
  3. package/dist/cli/setup.js +58 -60
  4. package/dist/cli/setup.js.map +1 -1
  5. package/dist/config/config.js +2 -2
  6. package/dist/config/config.js.map +1 -1
  7. package/dist/db/database.d.ts +8 -0
  8. package/dist/db/database.d.ts.map +1 -1
  9. package/dist/db/database.js +35 -54
  10. package/dist/db/database.js.map +1 -1
  11. package/dist/db/event-log.d.ts +4 -0
  12. package/dist/db/event-log.d.ts.map +1 -1
  13. package/dist/db/event-log.js +14 -10
  14. package/dist/db/event-log.js.map +1 -1
  15. package/dist/db/memory-store.d.ts +30 -3
  16. package/dist/db/memory-store.d.ts.map +1 -1
  17. package/dist/db/memory-store.js +153 -55
  18. package/dist/db/memory-store.js.map +1 -1
  19. package/dist/embedding-worker.js +1 -1
  20. package/dist/embedding-worker.js.map +1 -1
  21. package/dist/hooks/git-capture.js +3 -3
  22. package/dist/hooks/git-hooks.js +5 -2
  23. package/dist/mcp-stdio.js +70 -15
  24. package/dist/mcp-stdio.js.map +1 -1
  25. package/dist/memory/access-pattern-tracker.d.ts +51 -0
  26. package/dist/memory/access-pattern-tracker.d.ts.map +1 -0
  27. package/dist/memory/access-pattern-tracker.js +92 -0
  28. package/dist/memory/access-pattern-tracker.js.map +1 -0
  29. package/dist/memory/anticipation-engine.d.ts.map +1 -1
  30. package/dist/memory/anticipation-engine.js +18 -10
  31. package/dist/memory/anticipation-engine.js.map +1 -1
  32. package/dist/memory/auto-learner.d.ts.map +1 -1
  33. package/dist/memory/auto-learner.js +192 -45
  34. package/dist/memory/auto-learner.js.map +1 -1
  35. package/dist/memory/completion-resolver.d.ts +38 -0
  36. package/dist/memory/completion-resolver.d.ts.map +1 -0
  37. package/dist/memory/completion-resolver.js +127 -0
  38. package/dist/memory/completion-resolver.js.map +1 -0
  39. package/dist/memory/confidence-decay.d.ts.map +1 -1
  40. package/dist/memory/confidence-decay.js +13 -9
  41. package/dist/memory/confidence-decay.js.map +1 -1
  42. package/dist/memory/convention-detector.d.ts +11 -0
  43. package/dist/memory/convention-detector.d.ts.map +1 -0
  44. package/dist/memory/convention-detector.js +294 -0
  45. package/dist/memory/convention-detector.js.map +1 -0
  46. package/dist/memory/correction-detector.d.ts +33 -0
  47. package/dist/memory/correction-detector.d.ts.map +1 -0
  48. package/dist/memory/correction-detector.js +129 -0
  49. package/dist/memory/correction-detector.js.map +1 -0
  50. package/dist/memory/cross-memory-linker.d.ts +18 -0
  51. package/dist/memory/cross-memory-linker.d.ts.map +1 -0
  52. package/dist/memory/cross-memory-linker.js +115 -0
  53. package/dist/memory/cross-memory-linker.js.map +1 -0
  54. package/dist/memory/daily-diary.d.ts +30 -0
  55. package/dist/memory/daily-diary.d.ts.map +1 -0
  56. package/dist/memory/daily-diary.js +159 -0
  57. package/dist/memory/daily-diary.js.map +1 -0
  58. package/dist/memory/embedding-cache.d.ts +32 -0
  59. package/dist/memory/embedding-cache.d.ts.map +1 -0
  60. package/dist/memory/embedding-cache.js +76 -0
  61. package/dist/memory/embedding-cache.js.map +1 -0
  62. package/dist/memory/embedding-manager.d.ts.map +1 -1
  63. package/dist/memory/embedding-manager.js +6 -4
  64. package/dist/memory/embedding-manager.js.map +1 -1
  65. package/dist/memory/error-learner.d.ts +26 -0
  66. package/dist/memory/error-learner.d.ts.map +1 -0
  67. package/dist/memory/error-learner.js +145 -0
  68. package/dist/memory/error-learner.js.map +1 -0
  69. package/dist/memory/export-import.js +2 -2
  70. package/dist/memory/export-import.js.map +1 -1
  71. package/dist/memory/file-relationships.d.ts +47 -0
  72. package/dist/memory/file-relationships.d.ts.map +1 -0
  73. package/dist/memory/file-relationships.js +130 -0
  74. package/dist/memory/file-relationships.js.map +1 -0
  75. package/dist/memory/git-memory.d.ts.map +1 -1
  76. package/dist/memory/git-memory.js +20 -26
  77. package/dist/memory/git-memory.js.map +1 -1
  78. package/dist/memory/impact-analyzer.d.ts +16 -0
  79. package/dist/memory/impact-analyzer.d.ts.map +1 -0
  80. package/dist/memory/impact-analyzer.js +189 -0
  81. package/dist/memory/impact-analyzer.js.map +1 -0
  82. package/dist/memory/instructions-generator.d.ts +30 -0
  83. package/dist/memory/instructions-generator.d.ts.map +1 -0
  84. package/dist/memory/instructions-generator.js +117 -0
  85. package/dist/memory/instructions-generator.js.map +1 -0
  86. package/dist/memory/learning-rate.js +8 -7
  87. package/dist/memory/learning-rate.js.map +1 -1
  88. package/dist/memory/llm-enhancer.d.ts +2 -14
  89. package/dist/memory/llm-enhancer.d.ts.map +1 -1
  90. package/dist/memory/llm-enhancer.js +66 -46
  91. package/dist/memory/llm-enhancer.js.map +1 -1
  92. package/dist/memory/memory-cache.d.ts.map +1 -1
  93. package/dist/memory/memory-cache.js +10 -0
  94. package/dist/memory/memory-cache.js.map +1 -1
  95. package/dist/memory/memory-consolidator.d.ts.map +1 -1
  96. package/dist/memory/memory-consolidator.js +20 -14
  97. package/dist/memory/memory-consolidator.js.map +1 -1
  98. package/dist/memory/memory-decay.d.ts.map +1 -1
  99. package/dist/memory/memory-decay.js +82 -52
  100. package/dist/memory/memory-decay.js.map +1 -1
  101. package/dist/memory/memory-export-md.d.ts +12 -0
  102. package/dist/memory/memory-export-md.d.ts.map +1 -0
  103. package/dist/memory/memory-export-md.js +188 -0
  104. package/dist/memory/memory-export-md.js.map +1 -0
  105. package/dist/memory/memory-quality.d.ts +1 -1
  106. package/dist/memory/memory-quality.d.ts.map +1 -1
  107. package/dist/memory/memory-quality.js +13 -27
  108. package/dist/memory/memory-quality.js.map +1 -1
  109. package/dist/memory/memory-ranker.d.ts.map +1 -1
  110. package/dist/memory/memory-ranker.js +12 -3
  111. package/dist/memory/memory-ranker.js.map +1 -1
  112. package/dist/memory/meta-memory.js +3 -3
  113. package/dist/memory/meta-memory.js.map +1 -1
  114. package/dist/memory/mmr-reranker.d.ts +39 -0
  115. package/dist/memory/mmr-reranker.d.ts.map +1 -0
  116. package/dist/memory/mmr-reranker.js +115 -0
  117. package/dist/memory/mmr-reranker.js.map +1 -0
  118. package/dist/memory/pre-flight.d.ts +24 -0
  119. package/dist/memory/pre-flight.d.ts.map +1 -0
  120. package/dist/memory/pre-flight.js +121 -0
  121. package/dist/memory/pre-flight.js.map +1 -0
  122. package/dist/memory/preference-learner.d.ts +28 -0
  123. package/dist/memory/preference-learner.d.ts.map +1 -0
  124. package/dist/memory/preference-learner.js +144 -0
  125. package/dist/memory/preference-learner.js.map +1 -0
  126. package/dist/memory/query-expansion.d.ts +28 -0
  127. package/dist/memory/query-expansion.d.ts.map +1 -0
  128. package/dist/memory/query-expansion.js +140 -0
  129. package/dist/memory/query-expansion.js.map +1 -0
  130. package/dist/memory/regression-guard.d.ts +35 -0
  131. package/dist/memory/regression-guard.d.ts.map +1 -0
  132. package/dist/memory/regression-guard.js +90 -0
  133. package/dist/memory/regression-guard.js.map +1 -0
  134. package/dist/memory/resume-work.d.ts +37 -0
  135. package/dist/memory/resume-work.d.ts.map +1 -0
  136. package/dist/memory/resume-work.js +141 -0
  137. package/dist/memory/resume-work.js.map +1 -0
  138. package/dist/memory/session-tracker.d.ts +2 -0
  139. package/dist/memory/session-tracker.d.ts.map +1 -1
  140. package/dist/memory/session-tracker.js +26 -8
  141. package/dist/memory/session-tracker.js.map +1 -1
  142. package/dist/memory/soul-manager.d.ts +30 -0
  143. package/dist/memory/soul-manager.d.ts.map +1 -0
  144. package/dist/memory/soul-manager.js +171 -0
  145. package/dist/memory/soul-manager.js.map +1 -0
  146. package/dist/memory/success-tracker.d.ts +33 -0
  147. package/dist/memory/success-tracker.d.ts.map +1 -0
  148. package/dist/memory/success-tracker.js +75 -0
  149. package/dist/memory/success-tracker.js.map +1 -0
  150. package/dist/memory/temporal-engine.d.ts.map +1 -1
  151. package/dist/memory/temporal-engine.js +9 -13
  152. package/dist/memory/temporal-engine.js.map +1 -1
  153. package/dist/memory/tool-recommender.d.ts +29 -0
  154. package/dist/memory/tool-recommender.d.ts.map +1 -0
  155. package/dist/memory/tool-recommender.js +117 -0
  156. package/dist/memory/tool-recommender.js.map +1 -0
  157. package/dist/memory/usage-stats.d.ts +98 -0
  158. package/dist/memory/usage-stats.d.ts.map +1 -0
  159. package/dist/memory/usage-stats.js +345 -0
  160. package/dist/memory/usage-stats.js.map +1 -0
  161. package/dist/retrieval/hybrid-retriever.d.ts +0 -2
  162. package/dist/retrieval/hybrid-retriever.d.ts.map +1 -1
  163. package/dist/retrieval/hybrid-retriever.js +3 -13
  164. package/dist/retrieval/hybrid-retriever.js.map +1 -1
  165. package/dist/scanners/architecture-graph.js +2 -2
  166. package/dist/scanners/architecture-graph.js.map +1 -1
  167. package/dist/scanners/code-verifier.d.ts +1 -0
  168. package/dist/scanners/code-verifier.d.ts.map +1 -1
  169. package/dist/scanners/code-verifier.js +14 -14
  170. package/dist/scanners/code-verifier.js.map +1 -1
  171. package/dist/scanners/context-builder.d.ts.map +1 -1
  172. package/dist/scanners/context-builder.js +33 -45
  173. package/dist/scanners/context-builder.js.map +1 -1
  174. package/dist/scanners/export-map.js +2 -2
  175. package/dist/scanners/export-map.js.map +1 -1
  176. package/dist/scanners/project-scanner.js +2 -2
  177. package/dist/scanners/project-scanner.js.map +1 -1
  178. package/dist/security/encryption.js +1 -1
  179. package/dist/security/encryption.js.map +1 -1
  180. package/dist/security/feature-gate.d.ts.map +1 -1
  181. package/dist/security/feature-gate.js +62 -20
  182. package/dist/security/feature-gate.js.map +1 -1
  183. package/dist/security/license.js +282 -35
  184. package/dist/security/license.js.map +1 -1
  185. package/dist/security/rate-limiter.d.ts +4 -3
  186. package/dist/security/rate-limiter.d.ts.map +1 -1
  187. package/dist/security/rate-limiter.js +11 -29
  188. package/dist/security/rate-limiter.js.map +1 -1
  189. package/dist/server/dashboard.js +166 -327
  190. package/dist/server/dashboard.js.map +1 -1
  191. package/dist/server/mcp-handler.d.ts.map +1 -1
  192. package/dist/server/mcp-handler.js +991 -1019
  193. package/dist/server/mcp-handler.js.map +1 -1
  194. package/dist/utils/extract-tags.d.ts +16 -0
  195. package/dist/utils/extract-tags.d.ts.map +1 -0
  196. package/dist/utils/extract-tags.js +40 -0
  197. package/dist/utils/extract-tags.js.map +1 -0
  198. package/package.json +18 -8
  199. package/dist/core/event-bus.d.ts +0 -19
  200. package/dist/core/event-bus.d.ts.map +0 -1
  201. package/dist/core/event-bus.js +0 -51
  202. package/dist/core/event-bus.js.map +0 -1
package/README.md CHANGED
@@ -1,227 +1,394 @@
1
- # 🧠 Cortex MCP — Persistent Memory for AI Coding Assistants
2
-
3
- > **Give your AI a brain that never forgets.**
4
- > Cortex injects context from every past session directly into your AI's LLM requests — automatically.
5
-
6
- [![npm](https://img.shields.io/npm/v/cortex-mcp)](https://www.npmjs.com/package/cortex-mcp)
7
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
8
- [![100% Free](https://img.shields.io/badge/price-100%25%20FREE-brightgreen)](https://www.npmjs.com/package/cortex-mcp)
9
-
10
- ---
11
-
12
- ## What Is Cortex?
13
-
14
- Every time you close your IDE, your AI forgets everything. Every decision, every bug fix, every convention — gone.
15
-
16
- **Cortex solves this.** It's a local MCP server that:
17
- - Stores everything your AI learns about your project
18
- - Automatically injects the right memories into every conversation
19
- - Learns passively by reading your AI's own responses
20
- - Never needs an API key, never phones home, never loses your data
21
-
22
- **Fully local. Fully free. No account. No limits.**
23
-
24
- ---
25
-
26
- ## Quick Start (30 seconds)
27
-
28
- ```bash
29
- # Install globally
30
- npm install -g cortex-mcp
31
-
32
- # Auto-configure your AI client (Cursor, Claude, Windsurf, Copilot...)
33
- cd your-project
34
- cortex-setup
35
- ```
36
-
37
- That's it. Restart your AI client and Cortex is active.
38
-
39
- ---
40
-
41
- ## Supported AI Clients
42
-
43
- | Client | Auto-configured by `cortex-setup` |
44
- |--------|----------------------------------|
45
- | **Cursor** | ✅ |
46
- | **Claude Desktop** | ✅ |
47
- | **GitHub Copilot (VS Code)** | ✅ |
48
- | **Windsurf** | ✅ |
49
- | **Zed** | ✅ |
50
- | **Antigravity / Gemini** | ✅ |
51
- | Any MCP-compatible client | ✅ Manual config |
52
-
53
- ---
54
-
55
- ## How It Works
56
-
57
- ```
58
- Your AI responds → Cortex reads the response → Extracts decisions, corrections, bug fixes
59
-
60
- Next conversation → Cortex injects relevant memories → AI already knows your project
61
- ```
62
-
63
- **No manual work required.** Every session builds the brain automatically.
64
-
65
- ---
66
-
67
- ## All 30 Tools (All Free)
68
-
69
- ### Core Memory
70
- | Tool | What it does |
71
- |------|-------------|
72
- | `store_memory` | Store a decision, correction, convention, or bug fix |
73
- | `recall_memory` | Search memories by topic, file, or type |
74
- | `force_recall` | At session start — returns ALL critical context + topic search |
75
- | `auto_learn` | After every AI reply — auto-extracts memories from text |
76
- | `quick_store` | One-line shortcut for fast memory storage |
77
-
78
- ### Memory Management
79
- | Tool | What it does |
80
- |------|-------------|
81
- | `list_memories` | List all active memories, filterable by type |
82
- | `update_memory` | Edit an existing memory |
83
- | `delete_memory` | Remove a memory permanently |
84
- | `pin_memory` | Pin a memory so it's ALWAYS injected (for critical rules) |
85
- | `unpin_memory` | Unpin a previously pinned memory |
86
- | `undo_last` | Undo the last N stored memories |
87
- | `clear_memories` | Bulk delete by type or age |
88
- | `thumbs_up` | Mark a memory as useful (boosts importance) |
89
- | `thumbs_down` | Mark a memory as wrong (demotes/removes it) |
90
- | `get_related_memories` | Follow graph edges to find connected memories |
91
-
92
- ### Time & History
93
- | Tool | What it does |
94
- |------|-------------|
95
- | `search_timeline` | Search memories by date range ("what did we decide last week?") |
96
- | `get_daily_summary` | Read or generate a summary of today's/any day's memories |
97
-
98
- ### Project Intelligence
99
- | Tool | What it does |
100
- |------|-------------|
101
- | `scan_project` | Scan source code and auto-create memories from comments & structure |
102
- | `get_context` | Get full brain context for the current file/topic |
103
- | `get_stats` | Stats about the brain (memory count, types, health) |
104
- | `analytics` | Deep analytics — distribution, most accessed, feedback scores |
105
-
106
- ### Code Safety (Anti-Hallucination)
107
- | Tool | What it does |
108
- |------|-------------|
109
- | `verify_code` | Checks if packages exist in package.json before suggesting imports |
110
- | `verify_files` | Confirms file paths are real before referencing them |
111
- | `search_by_file` | Find all memories related to a specific file |
112
-
113
- ### Backup & Portability
114
- | Tool | What it does |
115
- |------|-------------|
116
- | `backup_brain` | Creates a timestamped `.db` copy of the entire memory database |
117
- | `export_memories` | Export all memories to a shareable JSON file |
118
- | `import_memories` | Import memories from a JSON file (skip duplicates) |
119
-
120
- ### Health & Maintenance
121
- | Tool | What it does |
122
- |------|-------------|
123
- | `health_check` | Server health, embedding status, vector search status |
124
- | `repair_brain` | Rebuild FTS index, integrity check, VACUUM, fix orphaned data |
125
- | `detect_conflicts` | Find contradictory memories (e.g. "use X" vs "avoid X") |
126
- | `suggest_cleanup` | Identify stale low-value memories you should delete |
127
-
128
- ---
129
-
130
- ## Memory Types
131
-
132
- Cortex organizes everything into 5 types:
133
-
134
- | Type | What gets stored | Auto-detected from |
135
- |------|-----------------|-------------------|
136
- | `correction` | "Don't do X", "Wrong approach was Y" | Words like "never", "don't use", "avoid" |
137
- | `decision` | "We chose X over Y because Z" | "We decided", "going with", "chosen" |
138
- | `convention` | "Always use X for Y in this project" | "always", "must", "convention", "standard" |
139
- | `bug_fix` | "Bug was X, fixed by Y" | "root cause", "fixed by", "was crashing" |
140
- | `insight` | "Key thing to know: X" | "important", "worth noting", "key insight" |
141
-
142
- Plus 4 additional auto-detected types: `failed_attempt`, `business_rule`, `gotcha`, `current_task`
143
-
144
- ---
145
-
146
- ## Web Dashboard
147
-
148
- When Cortex is running, open **http://localhost:3456** to:
149
- - View all memories organized by type
150
- - Search and filter in real-time
151
- - Delete or pin memories from the UI
152
- - Export your brain as JSON
153
- - See live stats (auto-refreshes every 30 seconds)
154
-
155
- ---
156
-
157
- ## Git Integration
158
-
159
- `cortex-setup` automatically installs git hooks that capture:
160
- - Every commit (type + message + files changed)
161
- - Every branch switch
162
- - Every merge
163
-
164
- So your AI knows your recent git history automatically.
165
-
166
- ---
167
-
168
- ## Environment Variables
169
-
170
- ```bash
171
- CORTEX_PORT=4000 # Dashboard port (default: 3456)
172
- CORTEX_DEBUG=1 # Enable file logging (cortex.log)
173
- CORTEX_MAX_CONTEXT_CHARS=12000 # Context size injected per request (default: 12000)
174
- OPENAI_API_KEY=sk-... # Enable LLM-enhanced memory classification
175
- ANTHROPIC_API_KEY=sk-ant-.. # Alternative LLM provider (Claude)
176
- CORTEX_LLM_BASE_URL=http://localhost:11434 # Ollama or any OpenAI-compatible API
177
- ```
178
-
179
- ---
180
-
181
- ## Data & Privacy
182
-
183
- - **100% local.** All memories stored in `.ai/brain-data/` inside your project folder.
184
- - **Zero telemetry.** No analytics, no phone-home, no account required.
185
- - **Offline-first.** Works with no internet. LLM key optional (uses fast regex-based classification otherwise).
186
- - **Open source.** MIT license.
187
-
188
- ---
189
-
190
- ## Manual Configuration
191
-
192
- If `cortex-setup` doesn't detect your client, add this to your MCP config:
193
-
194
- ```json
195
- {
196
- "mcpServers": {
197
- "cortex": {
198
- "command": "npx",
199
- "args": ["-y", "cortex-mcp"]
200
- }
201
- }
202
- }
203
- ```
204
-
205
- ---
206
-
207
- ## Limits (Auto-Reset Every 24 Hours)
208
-
209
- | Operation | Daily Limit |
210
- |-----------|------------|
211
- | Store memory | 500/day |
212
- | Auto-learn calls | 1,000/day |
213
- | Total tool calls | 5,000/day |
214
-
215
- All limits reset automatically every 24 hours. No manual restart needed.
216
-
217
- ---
218
-
219
- ## Built By
220
-
221
- **Perla Jaswanth Kumar** [GitHub](https://github.com/jaswanthkumarj1234-beep/cortex-mcp)
222
- Website: [cortex-website-theta.vercel.app](https://cortex-website-theta.vercel.app)
223
- Issues: [GitHub Issues](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/issues)
224
-
225
- ---
226
-
227
- *Cortex is 100% free and open source. Give your AI a brain. It's about time.*
1
+ # Cortex MCP — Persistent AI Memory
2
+
3
+ [![npm version](https://img.shields.io/npm/v/cortex-mcp.svg)](https://www.npmjs.com/package/cortex-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/cortex-mcp.svg)](https://www.npmjs.com/package/cortex-mcp)
5
+ [![CI](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/jaswanthkumarj1234-beep/cortex-mcp/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D20-brightgreen.svg)](https://nodejs.org/)
8
+
9
+ > Give your AI coding assistant a brain that remembers across sessions.
10
+
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
+
13
+ ## What's New in v2.6 — OpenClaw-Style Autonomous Brain
14
+
15
+ - **🧠 SOUL.md** — Persistent AI identity file, auto-learns from your top memories
16
+ - **📓 Daily Diary** Timestamped Markdown logs of every session's decisions and insights
17
+ - **📄 MEMORY.md** Human-readable knowledge export, auto-synced with the database
18
+ - **🎯 MMR Re-ranking** Maximal Marginal Relevance ensures diverse search results (λ=0.7)
19
+ - **⚡ Embedding Cache** LRU cache (256 entries) skips redundant vector computations
20
+ - **🔍 Query Expansion** 40+ synonym groups + alternative query generation for zero-result fallback
21
+ - **👤 Access Pattern Tracking** — Learns which memory types you use most, boosts them 0.7x–1.8x
22
+ - **🔗 Cross-Memory Linking** Auto-links related memories by files, tags, and word overlap
23
+ - **⏳ Two-Tier Decay** — Transactional memories (INSIGHT) decay at 5 days, operational (DECISION/CORRECTION) protected for 60 days
24
+ - **🤖 100% Autonomous** — All features run automatically on download, zero config needed
25
+
26
+ See [CHANGELOG.md](CHANGELOG.md) for full details.
27
+
28
+ ## The Problem
29
+
30
+ Every time you start a new conversation, your AI assistant forgets everything:
31
+
32
+ - Coding conventions you already explained
33
+ - Bugs you already fixed
34
+ - Decisions you already made
35
+ - What files you were working on
36
+
37
+ **Cortex solves this.** It stores, ranks, and proactively recalls context so your AI never starts from zero.
38
+
39
+ ## Quick Start
40
+
41
+ ### Option 1: npx (recommended — always up to date)
42
+
43
+ Add to your MCP config (no install needed, auto-updates on every launch):
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "cortex": {
49
+ "command": "npx",
50
+ "args": ["-y", "cortex-mcp@latest"],
51
+ "transportType": "stdio"
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ ### 🧠 Supercharge with Free LLM (Optional)
58
+
59
+ Add a **free** OpenRouter API key to make Cortex 3x smarter at extracting knowledge:
60
+
61
+ ```json
62
+ {
63
+ "mcpServers": {
64
+ "cortex": {
65
+ "command": "npx",
66
+ "args": ["-y", "cortex-mcp@latest"],
67
+ "transportType": "stdio",
68
+ "env": {
69
+ "OPENROUTER_API_KEY": "sk-or-v1-your-key-here"
70
+ }
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ **How to get a free key:**
77
+
78
+ 1. Go to [openrouter.ai/keys](https://openrouter.ai/keys)
79
+ 2. Create a free account
80
+ 3. Generate an API key
81
+ 4. Paste it in the config above
82
+
83
+ **What it enables:** When regex can't extract patterns from your conversation, Cortex uses a free LLM (Llama 4 Scout) to catch implicit decisions, preferences, and architecture knowledge that keywords miss. Without it, ~70% of conversations produce no memories. With it, that drops to ~20%.
84
+
85
+ ### Option 2: Global install
86
+
87
+ ```bash
88
+ npm install -g cortex-mcp
89
+ ```
90
+
91
+ Then add to your MCP config:
92
+
93
+ ```json
94
+ {
95
+ "mcpServers": {
96
+ "cortex": {
97
+ "command": "cortex-mcp",
98
+ "transportType": "stdio"
99
+ }
100
+ }
101
+ }
102
+ ```
103
+
104
+ ### Option 2: Clone from source
105
+
106
+ ```bash
107
+ git clone https://github.com/jaswanthkumarj1234-beep/cortex-mcp.git
108
+ cd cognitive-memory
109
+ npm install
110
+ npm run build
111
+ ```
112
+
113
+ Then add to your MCP config:
114
+
115
+ ```json
116
+ {
117
+ "mcpServers": {
118
+ "cortex": {
119
+ "command": "node",
120
+ "args": ["<path-to>/cognitive-memory/dist/mcp-stdio.js"],
121
+ "transportType": "stdio"
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ Restart your IDE and Cortex is active.
128
+
129
+ ### Try the Demo
130
+
131
+ See Cortex in action without any AI client:
132
+
133
+ ```bash
134
+ npm run demo # Interactive demo store, search, dedup
135
+ npm run benchmark # Performance benchmark — write, read, FTS ops/sec
136
+ ```
137
+
138
+ ### IDE-Specific Setup Guides
139
+
140
+ Step-by-step instructions for your IDE: **[Cursor · Claude Code · Windsurf · Cline · Copilot](docs/ide-setup.md)**
141
+
142
+ ### Recipes & Use Cases
143
+
144
+ 10 practical examples: **[docs/recipes.md](docs/recipes.md)** — conventions, bug tracking, anti-hallucination, team onboarding, and more.
145
+
146
+ ## Features
147
+
148
+ ### Why Cortex?
149
+
150
+ | Feature | Cortex | Other MCP memory servers |
151
+ | --------------------------- | :------------------------------------------------------: | :----------------------: |
152
+ | **Retrieval** | Hybrid (FTS + Vector + Graph) | Usually FTS only |
153
+ | **Auto-learning** | Extracts memories from AI responses | Manual store only |
154
+ | **Hallucination detection** | `verify_code` + `verify_files` | No |
155
+ | **Git integration** | Auto-captures commits, diffs, branch context | No |
156
+ | **Cognitive features** | Decay, attention, contradiction detection, consolidation | No |
157
+ | **Brain pipeline** | 12+ layer context injection | Simple key-value recall |
158
+ | **Setup** | `npm i -g cortex-mcp` + 1 config line | Varies |
159
+ | **Offline** | 100% local SQLite (no API key needed) | Often requires API |
160
+
161
+ ### 20 MCP Tools
162
+
163
+ | Tool | Purpose |
164
+ | ----------------- | ---------------------------------------------------------------------------------- |
165
+ | `force_recall` | Full brain dump at conversation start (12+ layer pipeline) |
166
+ | `recall_memory` | Search memories by topic (FTS + vector + graph) |
167
+ | `store_memory` | Store a decision, correction, convention, or bug fix |
168
+ | `quick_store` | One-liner memory storage with auto-classification |
169
+ | `auto_learn` | Extract memories from AI responses automatically |
170
+ | `scan_project` | Scan project structure, stack, git, exports, architecture |
171
+ | `verify_code` | Check if imports/exports/env vars actually exist |
172
+ | `verify_files` | Check if file paths are real or hallucinated |
173
+ | `get_context` | Get compressed context for current file |
174
+ | `review_code` | Review code against stored conventions and past bug patterns |
175
+ | `pre_check` | Pre-flight check before editing — get all conventions and past bugs for a file |
176
+ | `check_impact` | Impact analysis check which files depend on the file you plan to modify |
177
+ | `resume_work` | Resume after a break — get last session summary, recent corrections, pending tasks |
178
+ | `get_stats` | Memory database statistics |
179
+ | `list_memories` | List all active memories |
180
+ | `update_memory` | Update an existing memory |
181
+ | `delete_memory` | Delete a memory |
182
+ | `export_memories` | Export all memories to JSON |
183
+ | `import_memories` | Import memories from JSON |
184
+ | `health_check` | Server health check |
185
+
186
+ ### 14-Layer Brain Pipeline
187
+
188
+ Every conversation starts with `force_recall`, which runs 14 layers (layers 6-12 run **in parallel** for speed):
189
+
190
+ | Layer | Feature | Parallel? |
191
+ | :---: | ------------------------------------------------------------- | :-------: |
192
+ | Soul | SOUL.md persistent AI identity and preferences | — |
193
+ | 0 | Session management — track what you're working on | — |
194
+ | 0.5 | Day 1 auto-scan — scan project on first run | — |
195
+ | 1 | Maintenance — decay, consolidate, soul-learn, MEMORY.md sync | — |
196
+ | 2 | Attention focus — detect debugging vs coding vs reviewing | — |
197
+ | 3 | Session continuity — resume where you left off | — |
198
+ | 4 | Hot corrections — frequently-corrected topics | — |
199
+ | 5 | Core context — corrections, decisions, conventions, bug fixes | — |
200
+ | 6 | Anticipation — proactive recall based on current file | ✅ |
201
+ | 7 | Temporal — what changed today, yesterday, this week | ✅ |
202
+ | 7.5 | Daily Diary — recent session logs in Markdown | ✅ |
203
+ | 8 | Workspace git — branch, recent commits, diffs | ✅ |
204
+ | 8.5 | Git memory — auto-capture commits + file changes | ✅ |
205
+ | 9 | Topic search — FTS + vector + MMR diversity + personal boost | ✅ |
206
+ | 10 | Knowledge gaps — flag files with zero memories | ✅ |
207
+ | 11 | Export map all functions/classes (anti-hallucination) | ✅ |
208
+ | 12 | Architecture graph — layers, circular deps, API endpoints | ✅ |
209
+
210
+ ### Cognitive Features
211
+
212
+ - **Confidence decay** — old unused memories fade, frequently accessed ones strengthen
213
+ - **Attention ranking** debugging context boosts bug-fix memories, coding boosts conventions
214
+ - **Contradiction detection** — new memories automatically supersede conflicting old ones
215
+ - **Memory consolidation** similar memories merge into higher-level insights
216
+ - **Cross-session threading** — related sessions link by topic overlap
217
+ - **Learning rate** — topics corrected 3+ times get CRITICAL priority
218
+
219
+ ### Performance & Reliability
220
+
221
+ - **`force_recall` latency**: ~3-5s first call, instant on cache hit (v1.2 — was 15-19s)
222
+ - **`recall_memory` latency**: <1ms average (local SQLite + WAL)
223
+ - **Throughput**: 1800+ ops/sec (verified via Soak Test)
224
+ - **Stability**: Zero memory leaks over sustained operation
225
+ - **Protocol**: Full JSON-RPC 2.0 compliance (passed E2E suite)
226
+ - **CI**: Tested on Node 18, 20, 22 with lint + build + E2E on every push
227
+
228
+ ### Anti-Hallucination
229
+
230
+ - Deep export map scans every source file for all exported functions, classes, types
231
+ - When AI references a function that doesn't exist, `verify_code` suggests the closest real match
232
+ - Architecture graph shows actual project layers and dependencies
233
+
234
+ ## Optional: LLM Enhancement
235
+
236
+ Cortex works fully without any API key. Optionally, add an LLM key for smarter memory extraction:
237
+
238
+ ```bash
239
+ # Option 1: OpenAI
240
+ set OPENAI_API_KEY=sk-your-key
241
+
242
+ # Option 2: Anthropic
243
+ set ANTHROPIC_API_KEY=sk-ant-your-key
244
+
245
+ # Option 3: Local (Ollama, free)
246
+ set CORTEX_LLM_KEY=ollama
247
+ set CORTEX_LLM_BASE_URL=http://localhost:11434
248
+ ```
249
+
250
+ ## Memory Types
251
+
252
+ | Type | Use For |
253
+ | ------------------- | --------------------------------------------------- |
254
+ | `CORRECTION` | "Don't use var, use const" |
255
+ | `DECISION` | "We chose PostgreSQL over MongoDB" |
256
+ | `CONVENTION` | "All API routes start with /api/v1" |
257
+ | `BUG_FIX` | "Fixed race condition in auth middleware" |
258
+ | `INSIGHT` | "The codebase uses a layered architecture" |
259
+ | `FAILED_SUGGESTION` | "Tried Redis caching, too complex for this project" |
260
+ | `PROVEN_PATTERN` | "useDebounce hook works well for search inputs" |
261
+
262
+ ## Architecture
263
+
264
+ ```
265
+ src/
266
+ ├── server/ # MCP handler (12+ layer brain pipeline) + dashboard
267
+ ├── memory/ # 25+ cognitive modules (decay, MMR, embedding cache, soul, diary, etc.)
268
+ ├── scanners/ # Project scanner, code verifier, export map, architecture graph
269
+ ├── db/ # SQLite storage, event log
270
+ ├── security/ # Rate limiter, encryption
271
+ ├── hooks/ # Git capture
272
+ ├── config/ # Configuration
273
+ └── cli/ # Setup wizard
274
+ ```
275
+
276
+ ## Pricing & Features
277
+
278
+ Cortex is open core. The basic version is free forever. To unlock deep cognitive features, upgrade to PRO.
279
+
280
+ | Feature | FREE (npm install) | PRO ($9/mo) |
281
+ | ----------------------------------- | :----------------: | :---------: |
282
+ | **Memory Capacity** | ∞ Unlimited | ∞ Unlimited |
283
+ | **Brain Layers** | 12+ (Full) | 12+ (Full) |
284
+ | **All 16 Tools** | Yes | Yes |
285
+ | **Auto-Learn** | Yes | Yes |
286
+ | **Export Map (Anti-Hallucination)** | Yes | Yes |
287
+ | **Architecture Graph** | Yes | Yes |
288
+ | **Git Memory** | Yes | Yes |
289
+ | **Confidence Decay** | Yes | Yes |
290
+ | **Contradiction Detection** | Yes | Yes |
291
+ | **Priority Support** | — | Yes |
292
+
293
+ > **Launch Edition**: All features are currently free. Get started now and lock in lifetime access.
294
+
295
+ ### Activate PRO
296
+
297
+ 1. Get a license key from your [Cortex AI Dashboard](https://cortex-ai-iota.vercel.app/dashboard)
298
+ 2. Set it in your environment:
299
+
300
+ ```bash
301
+ # Option A: Environment variable
302
+ export CORTEX_LICENSE_KEY=CORTEX-XXXX-XXXX-XXXX-XXXX
303
+
304
+ # Option B: License file
305
+ echo CORTEX-XXXX-XXXX-XXXX-XXXX > ~/.cortex/license
306
+ ```
307
+
308
+ 3. Restart your IDE / MCP server.
309
+
310
+ ## Architecture
311
+
312
+ ```mermaid
313
+ graph TB
314
+ AI["AI Client (Cursor, Claude, etc.)"]
315
+ MCP["MCP Server (stdio)"]
316
+ ML["Memory Layer"]
317
+ DB["SQLite Database"]
318
+ SEC["Security Layer"]
319
+ API["License API"]
320
+
321
+ AI -->|"JSON-RPC via stdio"| MCP
322
+ MCP --> ML
323
+ ML --> DB
324
+ MCP --> SEC
325
+ SEC -->|"verify license"| API
326
+
327
+ subgraph "Memory Layer"
328
+ ML --> EMB["Embedding Manager"]
329
+ ML --> AL["Auto-Learner"]
330
+ ML --> QG["Quality Gates"]
331
+ ML --> TD["Temporal Decay"]
332
+ end
333
+
334
+ subgraph "Retrieval"
335
+ ML --> HR["Hybrid Retriever"]
336
+ HR --> VS["Vector Search"]
337
+ HR --> FTS["Full-Text Search"]
338
+ HR --> RR["Recency Ranker"]
339
+ end
340
+ ```
341
+
342
+ ## FAQ / Troubleshooting
343
+
344
+ <details>
345
+ <summary><strong>Cortex doesn't start or my AI client can't connect</strong></summary>
346
+
347
+ 1. Make sure Node.js >=18 is installed: `node --version`
348
+ 2. Try running manually: `npx cortex-mcp` — check stderr for errors
349
+ 3. Check if another Cortex instance is running on the same workspace
350
+ 4. Delete the cache and restart: `rm -rf .ai/brain-data`
351
+ </details>
352
+
353
+ <details>
354
+ <summary><strong>Memories aren't being recalled</strong></summary>
355
+
356
+ 1. Confirm your AI client's system prompt includes the Cortex rules (run `cortex-setup` to install them)
357
+ 2. Check the dashboard at `http://localhost:3456` to see stored memories
358
+ 3. Verify memories exist: the AI should call `force_recall` at conversation start
359
+ </details>
360
+
361
+ <details>
362
+ <summary><strong>"better-sqlite3" build errors on install</strong></summary>
363
+
364
+ `better-sqlite3` requires a C++ compiler:
365
+
366
+ - **Windows**: Install [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
367
+ - **macOS**: Run `xcode-select --install`
368
+ - **Linux**: Run `sudo apt-get install build-essential python3`
369
+ </details>
370
+
371
+ <details>
372
+ <summary><strong>License key not working</strong></summary>
373
+
374
+ 1. Verify the key format: `CORTEX-XXXX-XXXX-XXXX-XXXX`
375
+ 2. Check your internet connection (license is verified online on first use)
376
+ 3. Clear the cache: `rm ~/.cortex/license-cache.json`
377
+ 4. Try setting it via environment variable: `export CORTEX_LICENSE_KEY=CORTEX-...`
378
+ </details>
379
+
380
+ <details>
381
+ <summary><strong>Dashboard not loading</strong></summary>
382
+
383
+ 1. Default port is 3456. Check if something else is using it: `lsof -i :3456`
384
+ 2. Set a custom port: `export CORTEX_PORT=4000`
385
+ 3. The dashboard URL is shown in your AI client's stderr on startup
386
+ </details>
387
+
388
+ ## Contributing
389
+
390
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding conventions, and the PR process.
391
+
392
+ ## License
393
+
394
+ MIT