@theihtisham/agent-shadow-brain 5.0.1 → 5.2.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 (74) hide show
  1. package/README.md +1159 -888
  2. package/dist/adapters/copilot.d.ts +14 -0
  3. package/dist/adapters/copilot.d.ts.map +1 -0
  4. package/dist/adapters/copilot.js +93 -0
  5. package/dist/adapters/copilot.js.map +1 -0
  6. package/dist/adapters/cursor.d.ts +13 -0
  7. package/dist/adapters/cursor.d.ts.map +1 -0
  8. package/dist/adapters/cursor.js +96 -0
  9. package/dist/adapters/cursor.js.map +1 -0
  10. package/dist/adapters/index.d.ts +4 -1
  11. package/dist/adapters/index.d.ts.map +1 -1
  12. package/dist/adapters/index.js +7 -3
  13. package/dist/adapters/index.js.map +1 -1
  14. package/dist/adapters/windsurf.d.ts +14 -0
  15. package/dist/adapters/windsurf.d.ts.map +1 -0
  16. package/dist/adapters/windsurf.js +107 -0
  17. package/dist/adapters/windsurf.js.map +1 -0
  18. package/dist/brain/code-dna.d.ts +70 -0
  19. package/dist/brain/code-dna.d.ts.map +1 -0
  20. package/dist/brain/code-dna.js +611 -0
  21. package/dist/brain/code-dna.js.map +1 -0
  22. package/dist/brain/fine-tuning-engine.d.ts +99 -0
  23. package/dist/brain/fine-tuning-engine.d.ts.map +1 -0
  24. package/dist/brain/fine-tuning-engine.js +681 -0
  25. package/dist/brain/fine-tuning-engine.js.map +1 -0
  26. package/dist/brain/global-brain.d.ts +56 -0
  27. package/dist/brain/global-brain.d.ts.map +1 -0
  28. package/dist/brain/global-brain.js +324 -0
  29. package/dist/brain/global-brain.js.map +1 -0
  30. package/dist/brain/intent-engine.d.ts +64 -0
  31. package/dist/brain/intent-engine.d.ts.map +1 -0
  32. package/dist/brain/intent-engine.js +374 -0
  33. package/dist/brain/intent-engine.js.map +1 -0
  34. package/dist/brain/l0-cache.d.ts +40 -0
  35. package/dist/brain/l0-cache.d.ts.map +1 -0
  36. package/dist/brain/l0-cache.js +176 -0
  37. package/dist/brain/l0-cache.js.map +1 -0
  38. package/dist/brain/lsp-server.d.ts +62 -0
  39. package/dist/brain/lsp-server.d.ts.map +1 -0
  40. package/dist/brain/lsp-server.js +480 -0
  41. package/dist/brain/lsp-server.js.map +1 -0
  42. package/dist/brain/mcp-server.d.ts +4 -0
  43. package/dist/brain/mcp-server.d.ts.map +1 -1
  44. package/dist/brain/mcp-server.js +91 -0
  45. package/dist/brain/mcp-server.js.map +1 -1
  46. package/dist/brain/orchestrator.d.ts +13 -0
  47. package/dist/brain/orchestrator.d.ts.map +1 -1
  48. package/dist/brain/orchestrator.js +25 -1
  49. package/dist/brain/orchestrator.js.map +1 -1
  50. package/dist/brain/session-hooks.d.ts +28 -0
  51. package/dist/brain/session-hooks.d.ts.map +1 -0
  52. package/dist/brain/session-hooks.js +475 -0
  53. package/dist/brain/session-hooks.js.map +1 -0
  54. package/dist/brain/smart-cache.d.ts +100 -0
  55. package/dist/brain/smart-cache.d.ts.map +1 -0
  56. package/dist/brain/smart-cache.js +417 -0
  57. package/dist/brain/smart-cache.js.map +1 -0
  58. package/dist/brain/subconscious.d.ts +34 -0
  59. package/dist/brain/subconscious.d.ts.map +1 -0
  60. package/dist/brain/subconscious.js +275 -0
  61. package/dist/brain/subconscious.js.map +1 -0
  62. package/dist/brain/temporal-intelligence.d.ts +89 -0
  63. package/dist/brain/temporal-intelligence.d.ts.map +1 -0
  64. package/dist/brain/temporal-intelligence.js +378 -0
  65. package/dist/brain/temporal-intelligence.js.map +1 -0
  66. package/dist/cli.js +434 -4
  67. package/dist/cli.js.map +1 -1
  68. package/dist/index.d.ts +8 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +8 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/types.d.ts +333 -1
  73. package/dist/types.d.ts.map +1 -1
  74. package/package.json +46 -10
package/README.md CHANGED
@@ -1,888 +1,1159 @@
1
- <div align="center">
2
-
3
- <img src="docs/images/v5-banner.svg" alt="Agent Shadow Brain v5.0.1 — Infinite Intelligence Edition" width="100%">
4
-
5
- <br/>
6
-
7
- [![npm version](https://img.shields.io/npm/v/@theihtisham/agent-shadow-brain?color=a855f7&labelColor=1a0a2e&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@theihtisham/agent-shadow-brain)
8
- [![npm downloads](https://img.shields.io/npm/dt/@theihtisham/agent-shadow-brain?color=06b6d4&labelColor=1a0a2e&style=for-the-badge)](https://www.npmjs.com/package/@theihtisham/agent-shadow-brain)
9
- [![license](https://img.shields.io/badge/license-MIT-8b5cf6?labelColor=1a0a2e&style=for-the-badge)](https://github.com/theihtisham/agent-shadow-brain/blob/master/LICENSE)
10
- [![node](https://img.shields.io/badge/node-%3E%3D18-22c55e?labelColor=1a0a2e&style=for-the-badge&logo=node.js)](https://nodejs.org/)
11
- [![GitHub stars](https://img.shields.io/github/stars/theihtisham/agent-shadow-brain?color=f59e0b&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham/agent-shadow-brain/stargazers)
12
- [![arXiv](https://img.shields.io/badge/arXiv-2504.17033-ef4444?labelColor=1a0a2e&style=for-the-badge)](https://arxiv.org/abs/2504.17033)
13
- [![ICLR 2026](https://img.shields.io/badge/ICLR-2026_TurboQuant-06b6d4?labelColor=1a0a2e&style=for-the-badge)](https://openreview.net/forum?id=TbqSEUXWaO)
14
- [![Zero Config](https://img.shields.io/badge/zero-config-auto_setup-22c55e?labelColor=1a0a2e&style=for-the-badge)](#)
15
- [![MCP](https://img.shields.io/badge/MCP-Cursor_+_Claude-8b5cf6?labelColor=1a0a2e&style=for-the-badge)](#)
16
- [![Dashboard](https://img.shields.io/badge/dashboard-real_time-06b6d4?labelColor=1a0a2e&style=for-the-badge)](#)
17
-
18
- <br/>
19
-
20
- ### **The World's #1 Infinite-Intelligence AI Coding Brain**
21
-
22
- **Shadow Brain** is a zero-config, self-evolving, infinite-memory intelligence layer that makes **every AI coding agent** write better, safer, faster code. Install it once, and it automatically detects your project, your AI tools, your frameworks — and starts making your agents smarter forever.
23
-
24
- > **v5.0.1 — Infinite Intelligence Edition**: Zero-config auto-setup with MCP server for **Claude Code + Cursor + 8 AI tools**, rich web dashboard with real-time WebSocket updates, natural language brain queries, plugin system, brain export/import for team sync, git hook integration, and all v5.0.0 infinite intelligence features — 4-tier hierarchical memory, context-triggered associative recall, multi-agent consensus, collective cross-project learning, TurboQuant 6x compression, SSSP routing, self-evolving genetic rules, adversarial hallucination defense, swarm intelligence, knowledge graph with PageRank, and predictive bug forecasting.
25
-
26
- [**Install Now**](#-getting-started-30-seconds) · [**Dashboard**](#-web-dashboard) · [**v5.0.1 New**](#-v501-whats-new) · [**Algorithms**](#-algorithms--research) · [**CLI Reference**](#-cli-reference) · [**Architecture**](#-architecture)
27
-
28
- </div>
29
-
30
- ---
31
-
32
- ## The Problem
33
-
34
- You use AI coding agents. They're powerful, but:
35
-
36
- | Problem | Impact |
37
- |---|---|
38
- | Agents **forget everything** between sessions | Same mistakes, zero learning |
39
- | Multiple agents **don't communicate** | Claude doesn't know what Cursor learned |
40
- | Generated code has **hallucinations** | LLMs fabricate APIs that don't exist |
41
- | No **cross-session memory** | Every conversation starts from zero |
42
- | No **cross-project learning** | Discoveries in one project don't help others |
43
- | Setup is **complicated** | 30 minutes of config before anything works |
44
- | Each tool needs **separate config** | Claude, Cursor, Cline all need different setup |
45
-
46
- ## The Solution
47
-
48
- **Shadow Brain v5.0.1** — zero-config, auto-detecting, infinite-intelligence shadow layer:
49
-
50
- ```
51
- ┌──────────────┐ auto-detect ┌──────────────────────────────────────────┐
52
- │ AI Agents │ ◀──────────────── │ SHADOW BRAIN v5.0.1 │
53
- │ Claude Code │ MCP auto-install │ │
54
- │ Cursor │ zero-config │ ┌─ ZERO-CONFIG (v5.0.1 NEW) ────────┐ │
55
- │ Kilo Code │ │ │ Auto-detect project, tools, langs │ │
56
- │ Cline │ watches │ │ MCP server for ALL AI tools │ │
57
- │ OpenCode │ ──────────────▶ │ │ Rich web dashboard (real-time) │ │
58
- │ Codex │ file changes │ │ Natural language brain queries │ │
59
- │ Roo Code │ git commits │ │ Plugin system + export/import │ │
60
- │ Aider │ activity │ └────────────────────────────────────┘ │
61
- │ Windsurf │ │ ┌─ INFINITE MEMORY (v5.0.0) ────────┐ │
62
- └──────────────┘ │ │ 4-tier hierarchical compression │ │
63
- ▲ │ │ Context-triggered recall │ │
64
- │ │ │ Multi-agent consensus + trust │ │
65
- │ │ │ Collective cross-project learning │ │
66
- │ │ └────────────────────────────────────┘ │
67
- │ │ ┌─ HYPER-INTELLIGENCE (v4) ──────────┐ │
68
- │ │ │ TurboQuant 6x Compression │ │
69
- │ │ │ SSSP BMSSP Quantum Routing │ │
70
- │ │ │ Self-Evolution + CAIP + Swarm │ │
71
- │ │ │ PageRank + Predictive + Adversarial │ │
72
- └──────────────────────────┴──────────────────────────────────────────┘
73
- ```
74
-
75
- ---
76
-
77
- ## v5.0.1 — What's New
78
-
79
- ### Zero-Config Auto-Setup
80
-
81
- Install it. That's it. Shadow Brain automatically:
82
-
83
- - Detects your project type (frontend, backend, fullstack, mobile, game, systems, data-science)
84
- - Detects 25+ languages, 15+ frameworks, 5+ build tools, 5+ test frameworks
85
- - Detects which AI tools are installed (Claude Code, Cursor, Kilo Code, Cline, OpenCode, Codex, Aider, Windsurf)
86
- - Auto-installs MCP server configuration for every detected AI tool
87
- - Auto-installs git pre-commit and pre-push hooks
88
- - Generates an optimal brain config based on project complexity
89
-
90
- ```bash
91
- npm install @theihtisham/agent-shadow-brain
92
- # → Shadow Brain v5.0.1 auto-configured for my-app (fullstack)
93
- # → AI tools detected: Claude Code, Cursor
94
- # → Run: shadow-brain start
95
- ```
96
-
97
- ### MCP Server — Works with EVERY AI Tool
98
-
99
- The brain exposes itself as a **Model Context Protocol (MCP) server** with 19 tools that any AI tool can call:
100
-
101
- | MCP Tool | What It Does |
102
- |---|---|
103
- | `brain_status` | Get full brain status |
104
- | `brain_analyze` | Trigger code analysis |
105
- | `brain_health` | Get health score (A-F) |
106
- | `brain_insights` | Get recent insights |
107
- | `brain_fixes` | Get smart fix suggestions |
108
- | `brain_memory_store` | Store knowledge in hierarchical memory |
109
- | `brain_memory_search` | Search across all memory tiers |
110
- | `brain_memory_stats` | Memory compression statistics |
111
- | `brain_recall` | Context-triggered associative recall |
112
- | `brain_consensus_propose` | Submit a proposal for agent consensus |
113
- | `brain_consensus_vote` | Vote on a pending proposal |
114
- | `brain_collective_propose` | Propose a cross-project rule |
115
- | `brain_collective_search` | Search collective learning rules |
116
- | `brain_turbo_search` | Semantic search in compressed memory |
117
- | `brain_predict` | Predict bug risk for files |
118
- | `brain_graph_query` | Query knowledge graph |
119
- | `brain_defense_scan` | Scan for hallucination patterns |
120
- | `brain_evolve_status` | Get self-evolution status |
121
- | `brain_dashboard_url` | Get dashboard URL |
122
-
123
- Works with **Claude Code**, **Cursor**, **Kilo Code**, **Cline**, **OpenCode**, and any MCP-compatible AI tool.
124
-
125
- ```bash
126
- # Start MCP server (auto-started by AI tools)
127
- shadow-brain mcp
128
-
129
- # Cursor compatibility (root path POST + /v1/chat)
130
- # Claude Code compatibility (JSON-RPC 2.0 over stdio/HTTP)
131
- ```
132
-
133
- ### Rich Web Dashboard
134
-
135
- Real-time browser dashboard at `http://localhost:7341` with WebSocket live updates:
136
-
137
- - **Stats Topbar**: 8 live counters — Insights, Fixes, Memory KB, Modules, AI Tools, Evolution Gen, Swarm Convergence, Turbo Compression
138
- - **Health Score**: A-F grading with dimension breakdown (Security, Quality, Performance, Architecture, Maintainability, Test Coverage)
139
- - **Memory Tiers**: Visual bars showing Raw (50K), Summary (10K), Pattern (2K), Principle (500) with Turbo compression ratio
140
- - **Live Insights Stream**: Real-time feed of brain insights with priority badges
141
- - **Smart Fixes**: Actionable fix suggestions with file/line references
142
- - **AI Tools Panel**: 8 tools showing connected/detected status
143
- - **Brain Modules**: 13 modules with active/idle/error indicators
144
- - **Control Buttons**: Trigger analysis on-demand, refresh data
145
-
146
- ```bash
147
- shadow-brain start . # Dashboard auto-starts at http://localhost:7341
148
- shadow-brain dash . # Dashboard only mode
149
- ```
150
-
151
- ### Natural Language Queries
152
-
153
- Ask your brain questions in plain English:
154
-
155
- ```bash
156
- shadow-brain ask "What security issues exist in the auth module?"
157
- shadow-brain ask "Which files have the highest bug risk?"
158
- shadow-brain ask "What patterns have we learned about React hooks?"
159
- ```
160
-
161
- ### Brain Export/Import — Team Sync
162
-
163
- Export your brain state and share it with your team:
164
-
165
- ```bash
166
- shadow-brain export # Full export with all modules
167
- shadow-brain export -o ./team-brain # Custom output directory
168
- shadow-brain import brain-export.json # Import + merge
169
- shadow-brain import brain-export.json --merge --skip swarm,evolution
170
- ```
171
-
172
- ### Plugin System
173
-
174
- Extend Shadow Brain with custom plugins:
175
-
176
- ```bash
177
- shadow-brain plugin list # List installed plugins
178
- shadow-brain plugin create my-plugin # Create from template
179
- shadow-brain plugin stats # Plugin system statistics
180
- ```
181
-
182
- Plugins can hook into `pre-analysis` and `post-analysis` pipelines to add custom insights, filter results, or integrate with external services.
183
-
184
- ### 5 New Commands
185
-
186
- ```bash
187
- shadow-brain off # Clean shutdown
188
- shadow-brain ask "..." # Natural language query
189
- shadow-brain export # Export brain state
190
- shadow-brain import FILE # Import brain state
191
- shadow-brain plugin CMD # Plugin management
192
- ```
193
-
194
- ---
195
-
196
- ## Getting Started — 30 Seconds
197
-
198
- ```bash
199
- # Install globally
200
- npm install -g @theihtisham/agent-shadow-brain
201
-
202
- # Or use npx (no install needed)
203
- npx @theihtisham/agent-shadow-brain start .
204
- ```
205
-
206
- That's literally it. Shadow Brain will:
207
- 1. **Auto-detect** your project, languages, frameworks, AI tools (zero config)
208
- 2. **Auto-install** MCP server config for Claude Code, Cursor, Kilo Code, Cline, etc.
209
- 3. **Auto-install** git hooks for pre-commit and pre-push
210
- 4. Watch your project files for changes
211
- 5. Analyze every change with LLM + 13 brain modules
212
- 6. Inject expert insights into your agent's memory
213
- 7. Store all knowledge in hierarchical memory for infinite retention
214
- 8. Activate past memories automatically based on context
215
- 9. Share verified patterns across projects via collective learning
216
- 10. Compress knowledge with TurboQuant for infinite retention
217
- 11. Evolve its own rules via genetic algorithm
218
- 12. Share insights across agents via CAIP
219
- 13. Detect hallucinations with adversarial verification
220
- 14. Run consensus when multiple agents disagree
221
- 15. Serve a rich web dashboard at `localhost:7341`
222
-
223
- ### Quick Review (No Watch Mode)
224
-
225
- ```bash
226
- shadow-brain review . # One-shot analysis
227
- shadow-brain review . --show-health # + health score
228
- shadow-brain review . --show-fixes # + fix suggestions
229
- shadow-brain review . --output json # JSON for scripting
230
- ```
231
-
232
- ---
233
-
234
- ## Web Dashboard
235
-
236
- The v5.0.1 dashboard provides a real-time view into your brain:
237
-
238
- ```
239
- ┌──────────────────────────────────────────────────────────────────────────┐
240
- │ Shadow Brain v5.0.1 [Analyze] [↻] │
241
- ├──────────────────────────────────────────────────────────────────────────┤
242
- │ Insights: 142 │ Fixes: 38 │ Memory: 247KB │ Modules: 13/13 │ ... │
243
- ├──────────────┬─────────────────────────────────────┬───────────────────┤
244
- │ Health: 87% │ Live Insights Stream │ AI Tools │
245
- │ ████████░░ │ ● [HIGH] SQL injection in login.ts │ ● Claude Code ✓ │
246
- │ Security: A │ ● [MED] Missing error handling │ ● Cursor ✓ │
247
- │ Quality: B+ │ ● [LOW] Unused import in utils │ ● Kilo Code ✓ │
248
- │ Perf: A- │ ● [CRIT] Exposed API key │ ● Cline — │
249
- │ Arch: B │ │ ● OpenCode — │
250
- │ Maintain: A ├─────────────────────────────────────┤ ● Codex — │
251
- │ Tests: C+ │ Smart Fixes │ ● Aider — │
252
- │ │ 1. Add parameterized query... │ ● Windsurf — │
253
- ├──────────────┤ 2. Wrap in try/catch with... ├───────────────────┤
254
- │ Memory Tiers │ 3. Remove unused import on L42 │ Brain Modules │
255
- │ Raw: 8421 │ │ ● Hierarchical ✓ │
256
- │ Summ: 1203 │ │ ● TurboMemory ✓ │
257
- │ Patt: 187 │ │ ● Consensus ✓ │
258
- │ Princ: 24 │ │ ● Swarm ✓ │
259
- │ Turbo: 6.2x │ │ ● Evolution ✓ │
260
- │ │ │ ● Adversarial ✓ │
261
- └──────────────┴─────────────────────────────────────┴───────────────────┘
262
- ```
263
-
264
- ---
265
-
266
- ## v5.0.0 Infinite Intelligence Engine
267
-
268
- ### 4 Breakthrough Modules
269
-
270
- <table>
271
- <tr>
272
- <td width="50%">
273
-
274
- ### Infinite Memory Layer
275
-
276
- **Hierarchical Memory Compression** — 4-tier pyramid that never forgets.
277
-
278
- Knowledge flows through compression tiers as it ages:
279
- - **Raw** (50K entries) — full detail, hot path
280
- - **Summary** (10K) — condensed key points
281
- - **Pattern** (2K) — recurring patterns extracted
282
- - **Principle** (500) — timeless design rules
283
-
284
- Drill-down and drill-up between tiers. Older knowledge compresses, never deletes.
285
-
286
- ```bash
287
- shadow-brain memory stats # 4 tiers | 12,847 entries
288
- shadow-brain memory store "..." # Store new knowledge
289
- shadow-brain memory search "auth" # Cross-tier semantic search
290
- ```
291
-
292
- **Context-Triggered Associative Recall** — memories that activate themselves.
293
-
294
- Instead of requiring explicit search queries, this engine monitors your current work context and automatically surfaces relevant past knowledge:
295
- - File path pattern matching (editing `auth/*.ts` → security memories)
296
- - Keyword detection (typing "database" → SQL pattern memories)
297
- - Category association (bug-fix context → past fix patterns)
298
- - Co-occurrence networks (memories activated together strengthen their link)
299
- - Learned trigger patterns that improve with use
300
-
301
- ```bash
302
- shadow-brain recall . --file src/auth/login.ts --keywords "jwt,session"
303
- # → Activates 8 memories | Top: "JWT rotation pattern (92%)"
304
- ```
305
-
306
- </td>
307
- <td width="50%">
308
-
309
- ### Multi-Agent Intelligence Layer
310
-
311
- **Consensus Engine** — voting, trust scoring, conflict resolution.
312
-
313
- When multiple AI agents observe the same codebase, they may produce conflicting insights. This engine:
314
- 1. Collects proposals from agents
315
- 2. Opens voting windows (agree/disagree/abstain with confidence)
316
- 3. Computes trust-weighted agreement scores
317
- 4. Resolves conflicts via confidence intervals
318
- 5. Tracks long-term agent trust based on proposal accuracy
319
-
320
- ```bash
321
- shadow-brain consensus status
322
- shadow-brain consensus propose "Use bcrypt for all password hashing" security 0.95
323
- shadow-brain consensus vote <id> agree 0.9 "Industry standard"
324
- shadow-brain consensus results
325
- ```
326
-
327
- **Collective Learning** — discoveries flow across all projects.
328
-
329
- When you discover a pattern in Project A, it becomes a verified rule available in Project B:
330
- - Rule proposal with evidence and verification
331
- - Viral propagation across connected brain instances
332
- - Accuracy tracking per rule (tested vs. false positive)
333
- - Category-based organization (security, performance, architecture...)
334
- - Trust scores for rule sources
335
-
336
- ```bash
337
- shadow-brain collective status
338
- shadow-brain collective propose "Always validate file upload MIME types" security
339
- shadow-brain collective search performance
340
- ```
341
-
342
- </td>
343
- </tr>
344
- </table>
345
-
346
- ---
347
-
348
- ## v4.0.0 Hyper-Intelligence Engine
349
-
350
- ### 8 Breakthrough Modules (included in v5.0.1)
351
-
352
- <table>
353
- <tr>
354
- <td width="50%">
355
-
356
- ### Quantum Memory Layer
357
-
358
- **TurboQuant Infinite Memory** — never forget anything, ever.
359
-
360
- Based on Google Research's **TurboQuant** (ICLR 2026):
361
- - **PolarQuant**: 2 bits per dimension (polar coordinate quantization)
362
- - **QJL Residual**: 1 bit per dimension (random rotation + sign)
363
- - **Total**: 3 bits/dim = **6x compression** with <1% accuracy loss
364
- - **Result**: Infinite retention — old knowledge is compressed, never deleted
365
-
366
- ```bash
367
- shadow-brain turbo stats
368
- shadow-brain turbo search "authentication patterns"
369
- ```
370
-
371
- **SSSP Quantum Router** — deterministic shortest-path message routing.
372
-
373
- Based on **"Breaking the Sorting Barrier"** (arXiv 2504.17033, Duan et al.):
374
- - **BMSSP Algorithm**: O(m log<sup>2/3</sup> n) — breaks the sorting barrier
375
- - **Deterministic**: No randomization, provably correct
376
-
377
- ```bash
378
- shadow-brain route status
379
- shadow-brain route find node-A node-B
380
- ```
381
-
382
- </td>
383
- <td width="50%">
384
-
385
- ### Self-Evolution Layer
386
-
387
- **Genetic Algorithm Self-Evolution** — rules that write themselves.
388
-
389
- - **Population**: 50 genetic rule chromosomes
390
- - **Selection**: Tournament (k=5) — survival of the fittest
391
- - **Crossover**: Single-point recombination
392
- - **Mutation**: Gaussian noise (Box-Muller transform, sigma=0.1)
393
- - **Fitness**: accuracy x coverage x (1 / falsePositiveRate)
394
-
395
- ```bash
396
- shadow-brain evolve status
397
- shadow-brain evolve run
398
- shadow-brain evolve best-rules security
399
- ```
400
-
401
- **Cross-Agent Intelligence Protocol (CAIP)** — agents that talk to each other.
402
-
403
- Your Claude Code session learns what your Cursor session discovered:
404
- - Zero-config broadcast protocol
405
- - Agent identification + insight tagging
406
- - Multi-agent consensus building
407
-
408
- ```bash
409
- shadow-brain caip status
410
- shadow-brain caip broadcast "Security pattern detected"
411
- ```
412
-
413
- </td>
414
- </tr>
415
- <tr>
416
- <td width="50%">
417
-
418
- ### Defense & Trust Layer
419
-
420
- **Adversarial Hallucination Defense** — trust nothing, verify everything.
421
-
422
- - Cross-reference every critical insight against actual code
423
- - Evidence scoring with confidence thresholds
424
- - Verdict: `real` | `hallucinated` | `uncertain`
425
-
426
- ```bash
427
- shadow-brain defense status
428
- shadow-brain defense scan "This API endpoint exists at /api/v2/users"
429
- ```
430
-
431
- **Swarm Intelligence** — Ant Colony Optimization for file prioritization.
432
-
433
- - Pheromone deposit: +3 for critical, +2 for high, +1 for medium
434
- - Evaporation: decay over time to avoid staleness
435
-
436
- ```bash
437
- shadow-brain swarm status
438
- shadow-brain swarm priorities
439
- ```
440
-
441
- </td>
442
- <td width="50%">
443
-
444
- ### Analytics & Prediction Layer
445
-
446
- **Knowledge Graph + PageRank** — code impact radar.
447
-
448
- - Identify high-impact files (change one, break many)
449
- - Cycle detection in dependency graphs
450
- - Entity extraction with file/line tracking
451
-
452
- ```bash
453
- shadow-brain graph build .
454
- shadow-brain graph pagerank
455
- shadow-brain graph cycles
456
- ```
457
-
458
- **Predictive Engine** — predict bugs before they happen.
459
-
460
- - Bug risk scoring: `low` | `medium` | `high` | `critical`
461
- - Technical debt forecasting
462
- - Anomaly detection in change patterns
463
-
464
- ```bash
465
- shadow-brain predict bugs .
466
- ```
467
-
468
- </td>
469
- </tr>
470
- </table>
471
-
472
- ---
473
-
474
- ## Algorithms & Research
475
-
476
- Shadow Brain v5.0.1 implements algorithms from **peer-reviewed research**:
477
-
478
- | Algorithm | Paper / Origin | Application | Complexity |
479
- |---|---|---|---|
480
- | **Hierarchical Compression** | Novel 4-tier system | Infinite memory with drill-down | O(n) per tier |
481
- | **Associative Recall** | Spreading activation model | Context-triggered memory activation | O(n x k) |
482
- | **Consensus Protocol** | Byzantine fault tolerance | Multi-agent agreement with trust | O(v x log v) |
483
- | **TurboQuant** | Google Research, ICLR 2026 | Vector compression (PolarQuant + QJL) | O(n) per vector |
484
- | **BMSSP (SSSP)** | arXiv 2504.17033, Duan et al. | Neural mesh message routing | O(m log<sup>2/3</sup> n) |
485
- | **Shannon Entropy** | Claude Shannon, 1948 | Cross-project insight relevance scoring | O(n) |
486
- | **Bayesian Inference** | Thomas Bayes, 1763 | Confidence updating, meta-learning | O(1) per update |
487
- | **Cosine Similarity** | Vector space model | Knowledge deduplication | O(d) per pair |
488
- | **PageRank** | Brin & Page, 1998 | Code entity impact analysis | O(V + E) per iteration |
489
- | **Tarjan's SCC** | Robert Tarjan, 1972 | Dependency cycle detection | O(V + E) |
490
- | **Winnowing** | Schleimer et al., 2003 | Code duplicate fingerprinting | O(n) |
491
- | **Box-Muller** | Box & Muller, 1958 | Gaussian mutation in genetic algorithm | O(1) per sample |
492
- | **Ant Colony (ACO)** | Dorigo, 1992 | File priority pheromone system | O(n x m) |
493
- | **Tournament Selection** | Goldberg, 1989 | Genetic rule selection (k=5) | O(k) per selection |
494
-
495
- ### TurboQuant Pipeline Detail
496
-
497
- ```
498
- Input Vector (64-dim, float64)
499
- |
500
- v
501
- +-------------+
502
- | PolarQuant |-- Cartesian -> Polar coordinates
503
- | 2 bits/dim |-- Quantize angles to 4 levels (2 bits each)
504
- +------+-------+ Pack into Uint8Array
505
- |
506
- v
507
- +-------------+
508
- | QJL Residual|-- Random rotation (Hadamard-like)
509
- | 1 bit/dim |-- Sign extraction (1 bit per dim)
510
- +------+-------+ Pack into Uint8Array
511
- |
512
- v
513
- TurboVector { polar: Uint8Array, qjl: Uint8Array, dim: number, radius: number }
514
- = 3 bits/dim total = 6x compression from float64
515
- = ZERO FORGETTING -- compressed knowledge stays searchable forever
516
- ```
517
-
518
- ---
519
-
520
- ## Features
521
-
522
- <table>
523
- <tr>
524
- <td width="25%">
525
-
526
- ### Zero Config (v5.0.1)
527
- - Auto-detect project + tools
528
- - MCP for ALL AI tools
529
- - Rich web dashboard
530
- - Natural language queries
531
- - Plugin system
532
- - Brain export/import
533
- - Git hook auto-install
534
-
535
- </td>
536
- <td width="25%">
537
-
538
- ### Infinite Intelligence (v5)
539
- - 4-tier hierarchical memory
540
- - Context-triggered recall
541
- - Multi-agent consensus
542
- - Collective cross-project learning
543
-
544
- </td>
545
- <td width="25%">
546
-
547
- ### Hyper-Intelligence (v4)
548
- - TurboQuant infinite memory
549
- - SSSP quantum routing
550
- - Self-evolving genetic rules
551
- - Cross-agent protocol (CAIP)
552
- - Adversarial defense
553
- - Swarm intelligence (ACO)
554
- - Knowledge Graph + PageRank
555
- - Predictive bug forecasting
556
-
557
- </td>
558
- <td width="25%">
559
-
560
- ### Developer Experience
561
- - **50+ CLI commands**
562
- - MCP Server (19 tools)
563
- - Web dashboard (real-time)
564
- - Terminal UI (Ink/React)
565
- - Pre-commit hooks
566
- - GitHub Actions CI
567
- - Plugin architecture
568
-
569
- </td>
570
- </tr>
571
- </table>
572
-
573
- ---
574
-
575
- ## Architecture
576
-
577
- ### v5.0.1 Module Map (16 modules)
578
-
579
- | Module | File | What It Does | Since |
580
- |---|---|---|---|
581
- | **Auto Setup** | `brain/auto-setup.ts` | Zero-config project + tool detection | v5.0.1 |
582
- | **MCP Server** | `brain/mcp-server.ts` | 19-tool MCP server for all AI tools | v5.0.1 |
583
- | **Plugin System** | `brain/plugin-system.ts` | Hookable analysis pipeline | v5.0.1 |
584
- | **Brain Portability** | `brain/brain-portability.ts` | Export/import brain state | v5.0.1 |
585
- | **Dashboard** | `dashboard/server.ts` | Real-time WebSocket dashboard | v5.0.1 |
586
- | **Hierarchical Memory** | `brain/hierarchical-memory.ts` | 4-tier infinite memory | v5.0.0 |
587
- | **Context Recall** | `brain/context-recall.ts` | Associative memory activation | v5.0.0 |
588
- | **Consensus Engine** | `brain/consensus-engine.ts` | Multi-agent voting + trust | v5.0.0 |
589
- | **Collective Learning** | `brain/collective-learning.ts` | Cross-project rule sharing | v5.0.0 |
590
- | **TurboMemory** | `brain/turbo-memory.ts` | 6x compressed infinite memory | v4.0.0 |
591
- | **SSSP Router** | `brain/sssp-router.ts` | Sub-sorting routing | v4.0.0 |
592
- | **Self-Evolution** | `brain/self-evolution.ts` | Genetic rule optimization | v4.0.0 |
593
- | **Cross-Agent** | `brain/cross-agent-protocol.ts` | Multi-agent broadcast | v4.0.0 |
594
- | **Adversarial** | `brain/adversarial-defense.ts` | Hallucination detection | v4.0.0 |
595
- | **Swarm** | `brain/swarm-intelligence.ts` | File priority pheromones | v4.0.0 |
596
- | **Knowledge Graph** | `brain/knowledge-graph.ts` | PageRank impact analysis | v4.0.0 |
597
- | **Predictive** | `brain/predictive-engine.ts` | Bug risk & debt forecasting | v4.0.0 |
598
-
599
- ---
600
-
601
- ## CLI Reference
602
-
603
- ### Core Commands
604
-
605
- | Command | Description |
606
- |---|---|
607
- | `shadow-brain start [dir]` | Start real-time watching + dashboard + MCP |
608
- | `shadow-brain off` | Clean shutdown |
609
- | `shadow-brain review [dir]` | One-shot code analysis |
610
- | `shadow-brain health [dir]` | Health score (A-F grading) |
611
- | `shadow-brain fix [dir]` | Smart fix suggestions |
612
- | `shadow-brain report [dir]` | HTML/MD/JSON reports |
613
- | `shadow-brain metrics [dir]` | Code metrics |
614
- | `shadow-brain scan [dir]` | Vulnerability scanner |
615
- | `shadow-brain pr [dir]` | Generate PR description |
616
- | `shadow-brain commit-msg [dir]` | Generate commit message |
617
- | `shadow-brain ci [dir]` | GitHub Actions workflow |
618
- | `shadow-brain hook [dir]` | Pre-commit hook |
619
- | `shadow-brain dash [dir]` | Web dashboard |
620
- | `shadow-brain mcp` | MCP server mode |
621
- | `shadow-brain inject <msg>` | Inject into agent memory |
622
- | `shadow-brain status` | Current configuration |
623
- | `shadow-brain setup` | Interactive setup wizard |
624
- | `shadow-brain doctor` | Health check & diagnostics |
625
- | `shadow-brain ask <question>` | Natural language brain query |
626
-
627
- ### v5.0.1 Commands (NEW)
628
-
629
- | Command | Description |
630
- |---|---|
631
- | `shadow-brain off` | Clean shutdown of all brain processes |
632
- | `shadow-brain ask <question>` | Natural language query to the brain |
633
- | `shadow-brain export [-o dir]` | Export full brain state to JSON |
634
- | `shadow-brain import <file> [--merge]` | Import brain state |
635
- | `shadow-brain plugin list` | List installed plugins |
636
- | `shadow-brain plugin create <name>` | Create plugin from template |
637
- | `shadow-brain plugin stats` | Plugin system statistics |
638
-
639
- ### v5.0.0 Infinite Intelligence Commands
640
-
641
- | Command | Description |
642
- |---|---|
643
- | `shadow-brain memory stats` | 4-tier hierarchical memory stats |
644
- | `shadow-brain memory store <text>` | Store knowledge at raw tier |
645
- | `shadow-brain memory search <query>` | Cross-tier semantic search |
646
- | `shadow-brain recall . --file <f>` | Context-triggered associative recall |
647
- | `shadow-brain consensus status` | Multi-agent consensus stats |
648
- | `shadow-brain consensus propose <text> <cat> <conf>` | Submit proposal for voting |
649
- | `shadow-brain consensus vote <id> <vote> <conf> <reason>` | Vote on a proposal |
650
- | `shadow-brain consensus results` | All resolved proposals |
651
- | `shadow-brain collective status` | Cross-project rule stats |
652
- | `shadow-brain collective propose <text> <cat>` | Propose a collective rule |
653
- | `shadow-brain collective search <cat>` | Search collective rules by category |
654
- | `shadow-brain v5 [dir]` | Run ALL v5.0.0 analyses |
655
-
656
- ### v4.0.0 Hyper-Intelligence Commands
657
-
658
- | Command | Description |
659
- |---|---|
660
- | `shadow-brain turbo stats` | TurboQuant infinite memory stats |
661
- | `shadow-brain turbo search <q>` | Semantic search compressed memory |
662
- | `shadow-brain route status` | SSSP routing status |
663
- | `shadow-brain route find <from> <to>` | Shortest path query |
664
- | `shadow-brain caip status` | Cross-agent protocol status |
665
- | `shadow-brain caip broadcast <msg>` | Broadcast to all agents |
666
- | `shadow-brain evolve status` | Genetic algorithm generation stats |
667
- | `shadow-brain evolve run` | Trigger evolution cycle |
668
- | `shadow-brain evolve best-rules [cat]` | Top evolved rules by category |
669
- | `shadow-brain predict bugs [dir]` | Bug risk prediction |
670
- | `shadow-brain graph build [dir]` | Build knowledge graph + PageRank |
671
- | `shadow-brain swarm status` | Swarm convergence + priorities |
672
- | `shadow-brain swarm priorities` | File hotspot ranking |
673
- | `shadow-brain defense status` | Adversarial defense statistics |
674
- | `shadow-brain defense scan <text>` | Scan text for hallucination patterns |
675
- | `shadow-brain v4 [dir]` | Run ALL v4.0.0 analyses |
676
-
677
- ---
678
-
679
- ## Programmatic API
680
-
681
- ```typescript
682
- import {
683
- Orchestrator,
684
- AutoSetup,
685
- PluginSystem,
686
- BrainPortability,
687
- HierarchicalMemory,
688
- ContextRecall,
689
- ConsensusEngine,
690
- CollectiveLearning,
691
- TurboMemory,
692
- SSSPRouter,
693
- SelfEvolution,
694
- CrossAgentProtocol,
695
- AdversarialDefense,
696
- SwarmIntelligence,
697
- KnowledgeGraph,
698
- PredictiveEngine,
699
- NeuralMesh,
700
- } from '@theihtisham/agent-shadow-brain';
701
-
702
- // v5.0.1 — Zero-config auto-setup
703
- const setup = new AutoSetup('./my-project');
704
- const config = await setup.detect();
705
- // → { projectType: 'fullstack', languages: ['typescript','python'], frameworks: ['next.js'], aiTools: [...] }
706
- await setup.installMCPForTools(['Claude Code', 'Cursor']);
707
- await setup.installGitHooks();
708
-
709
- // Create the brain
710
- const brain = new Orchestrator({
711
- provider: 'anthropic',
712
- projectDir: './my-project',
713
- agents: ['claude-code', 'cursor', 'cline'],
714
- watchMode: true,
715
- autoInject: true,
716
- brainPersonality: 'balanced',
717
- });
718
-
719
- // v5.0.1 — Plugin system
720
- const plugins = new PluginSystem('./my-project');
721
- await plugins.loadAll();
722
- await plugins.preAnalysis({ files: ['src/auth.ts'], projectDir: './my-project' });
723
-
724
- // v5.0.1 — Brain portability
725
- const porter = new BrainPortability('./my-project');
726
- const { filePath, sizeBytes, checksum } = await porter.exportBrain();
727
-
728
- // v5.0.0 — Infinite Intelligence
729
- const hmem = new HierarchicalMemory();
730
- await hmem.store('JWT rotation pattern: rotate every 24h with refresh tokens', 'security', 0.9);
731
- const results = hmem.search('jwt');
732
-
733
- const recall = new ContextRecall(hmem);
734
- const activated = recall.recall({
735
- currentFile: 'src/auth/login.ts',
736
- currentCategory: 'security',
737
- recentEdits: ['src/auth/login.ts', 'src/middleware/auth.ts'],
738
- projectType: 'node',
739
- keywords: ['jwt', 'authentication', 'session'],
740
- });
741
-
742
- const consensus = new ConsensusEngine('my-agent');
743
- const proposalId = consensus.propose('Use bcrypt cost factor 12', 'security', 0.95);
744
-
745
- // Start everything
746
- await brain.start();
747
- ```
748
-
749
- ---
750
-
751
- ## Health Score System
752
-
753
- | Dimension | Weight | Checks |
754
- |---|---|---|
755
- | Security | 25% | Vulnerabilities, secrets, exposed keys |
756
- | Quality | 25% | Code smells, anti-patterns, complexity |
757
- | Performance | 15% | N+1 queries, memory leaks, blocking ops |
758
- | Architecture | 15% | Coupling, cohesion, dependencies |
759
- | Maintainability | 10% | Duplication, file sizes, comments |
760
- | Test Coverage | 10% | Test presence, assertion quality |
761
-
762
- ---
763
-
764
- ## Version History
765
-
766
- ### v5.0.1 — Zero-Config Intelligence Edition (Current)
767
- - **Zero-Config Auto-Setup** — auto-detect project, AI tools, languages, frameworks; auto-install MCP config + git hooks
768
- - **MCP Server** — 19-tool Model Context Protocol server for Claude Code, Cursor, and all AI tools
769
- - **Rich Web Dashboard** — real-time WebSocket dashboard with 8 panels (health, memory tiers, insights, fixes, AI tools, modules, stats, controls)
770
- - **Natural Language Queries** — `shadow-brain ask "..."` for plain-English brain interaction
771
- - **Plugin System** — hookable analysis pipeline with npm plugin discovery
772
- - **Brain Export/Import** — full brain state portability for team sync and backup
773
- - **5 new CLI commands** — off, ask, export, import, plugin
774
- - **Cursor MCP Compatibility** — root path POST + /v1/chat endpoint support
775
- - **Postinstall Auto-Setup** — runs automatically after npm install
776
- - **50+ npm keywords** for discoverability
777
- - All v5.0.0 and v4.0.0 features included and enhanced
778
-
779
- ### v5.0.0 — Infinite Intelligence Edition
780
- - **Hierarchical Memory Compression** — 4-tier pyramid (raw -> summary -> pattern -> principle) with drill-down/up
781
- - **Context-Triggered Associative Recall** — automatic memory activation based on file paths, keywords, categories
782
- - **Multi-Agent Consensus Protocol** — trust-weighted voting, confidence intervals, conflict resolution
783
- - **Collective Cross-Project Learning** — verified rule sharing, viral propagation, accuracy tracking
784
- - **5 new CLI commands** — memory, recall, consensus, collective, v5
785
-
786
- ### v4.0.0 — Hyper-Intelligence Edition
787
- - **TurboQuant Infinite Memory** — 6x compression, zero forgetting (Google Research, ICLR 2026)
788
- - **SSSP BMSSP Routing** — O(m log<sup>2/3</sup>n) deterministic routing (arXiv 2504.17033)
789
- - **Self-Evolving Genetic Rules** — tournament selection, Gaussian mutation, Bayesian meta-learning
790
- - **Cross-Agent Intelligence Protocol** — 7 agents share insights in real-time
791
- - **Adversarial Hallucination Defense** — cross-reference verification, evidence scoring
792
- - **Swarm Intelligence** — Ant Colony pheromone file prioritization
793
- - **Knowledge Graph + PageRank** — code impact radar with d=0.85 damping
794
- - **Predictive Engine** — bug risk scoring, debt forecasting, anomaly detection
795
-
796
- ### v3.0.0 — Hyper-Intelligence Edition
797
- - Cognitive load analysis, security audit engine, influence map
798
-
799
- ### v2.1.0 — Quantum Neural Mesh
800
- - Cross-session shared intelligence, Shannon entropy, cosine similarity, Bayesian confidence
801
-
802
- ### v2.0.0 — Super-Intelligence Edition
803
- - Semantic analyzer, dependency graph, code similarity, MCP Server, team mode
804
-
805
- ### v1.x — Foundation
806
- - 7 agent adapters, health scoring, smart fixes, vulnerability scanning, CI/CD
807
-
808
- ---
809
-
810
- ## Supported Agents & Tools
811
-
812
- | Agent | Status | MCP Support | Injection Target |
813
- |---|---|---|---|
814
- | [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | Full Support | Auto-install | `CLAUDE.md`, `.claude/` |
815
- | [Cursor](https://cursor.sh/) | Full Support | Auto-install | `.cursor/mcp.json` |
816
- | [Kilo Code](https://kilocode.ai/) | Full Support | Auto-install | `.kilocode/rules.md` |
817
- | [Cline](https://github.com/cline/cline) | Full Support | Auto-install | `.clinerules` |
818
- | [OpenCode](https://github.com/opencode-ai/opencode) | Full Support | Yes | `AGENT.md` |
819
- | [Codex](https://github.com/openai/codex) | Full Support | Yes | `AGENTS.md` |
820
- | [Roo Code](https://roocode.com/) | Full Support | Yes | `.roo/rules.md` |
821
- | [Aider](https://aider.chat/) | Full Support | Yes | `.aider.conf.yml` |
822
- | [Windsurf](https://codeium.com/windsurf) | Detection | Yes | `.windsurfrules` |
823
-
824
- ---
825
-
826
- ## Development
827
-
828
- ```bash
829
- git clone https://github.com/theihtisham/agent-shadow-brain.git
830
- cd agent-shadow-brain
831
- npm install
832
- npm run build
833
- npm test
834
- ```
835
-
836
- ---
837
-
838
- ## Roadmap
839
-
840
- - [x] ~~MCP Server, multi-project, team mode~~ (v2.0)
841
- - [x] ~~Cross-session neural mesh~~ (v2.1)
842
- - [x] ~~TurboQuant infinite memory~~ (v4.0)
843
- - [x] ~~SSSP quantum routing~~ (v4.0)
844
- - [x] ~~Self-evolving rules~~ (v4.0)
845
- - [x] ~~Cross-agent protocol~~ (v4.0)
846
- - [x] ~~Adversarial hallucination defense~~ (v4.0)
847
- - [x] ~~Hierarchical memory compression~~ (v5.0)
848
- - [x] ~~Context-triggered associative recall~~ (v5.0)
849
- - [x] ~~Multi-agent consensus protocol~~ (v5.0)
850
- - [x] ~~Collective cross-project learning~~ (v5.0)
851
- - [x] ~~Zero-config auto-setup~~ (v5.0.1)
852
- - [x] ~~MCP server for Cursor + all tools~~ (v5.0.1)
853
- - [x] ~~Rich web dashboard with real-time WebSocket~~ (v5.0.1)
854
- - [x] ~~Plugin system + brain export/import~~ (v5.0.1)
855
- - [ ] **IDE extensions** — VS Code extension for inline insights
856
- - [ ] **Custom LLM fine-tuning** — train on your codebase patterns
857
- - [ ] **Docker image** — one-command containerized deployment
858
- - [ ] **Language server** — LSP protocol for real-time feedback
859
- - [ ] **Web dashboard v3** — collaborative team dashboard
860
-
861
- ---
862
-
863
- ## License
864
-
865
- MIT License — see [LICENSE](LICENSE) for details.
866
-
867
- ---
868
-
869
- ## Author
870
-
871
- **theihtisham**
872
-
873
- [![GitHub](https://img.shields.io/badge/GitHub-theihtisham-181717?style=flat-square&logo=github)](https://github.com/theihtisham)
874
- [![npm](https://img.shields.io/badge/npm-@theihtisham-CB3837?style=flat-square&logo=npm)](https://www.npmjs.com/~theihtisham)
875
-
876
- ---
877
-
878
- <div align="center">
879
-
880
- ### If Shadow Brain makes your AI agents smarter, give it a star
881
-
882
- [![Star History Chart](https://api.star-history.com/svg?repos=theihtisham/agent-shadow-brain&type=Date)](https://star-history.com/#theihtisham/agent-shadow-brain&Date)
883
-
884
- **Built with brains by [theihtisham](https://github.com/theihtisham)**
885
-
886
- **Topics:** `ai` `artificial-intelligence` `llm` `claude-code` `cursor` `cline` `kilo-code` `codex` `roo-code` `aider` `opencode` `windsurf` `code-review` `static-analysis` `developer-tools` `npm-package` `typescript` `ollama` `openai` `anthropic` `code-quality` `security-scanner` `health-score` `smart-fix` `vulnerability-scanner` `pattern-learning` `agent-tools` `ai-agent` `code-metrics` `pre-commit-hook` `github-actions` `developer-productivity` `neural-mesh` `quantum-computing` `shannon-entropy` `bayesian-inference` `mcp-server` `model-context-protocol` `semantic-analysis` `dependency-graph` `turboquant` `sssp-algorithm` `genetic-algorithm` `swarm-intelligence` `pagerank` `knowledge-graph` `hallucination-detection` `cross-agent` `self-evolving` `predictive-engine` `ant-colony` `infinite-memory` `vector-compression` `iclr-2026` `arxiv` `super-intelligence` `hyper-intelligence` `autonomous-agents` `ai-engineering` `agentic-coding` `vibe-coding` `cursor-ai` `zero-config` `auto-setup` `dashboard` `plugin-system` `brain-export` `natural-language` `real-time` `websocket` `team-collaboration` `ci-cd` `open-source` `trending` `hierarchical-memory` `context-recall` `consensus-engine` `collective-learning` `infinite-intelligence` `coding-assistant`
887
-
888
- </div>
1
+ <div align="center">
2
+
3
+ <img src="banner.svg" alt="Agent Shadow Brain v5.2.0 — Subconscious Singularity Edition" width="100%">
4
+
5
+ <br/>
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@theihtisham/agent-shadow-brain?color=a855f7&labelColor=1a0a2e&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@theihtisham/agent-shadow-brain)
8
+ [![npm downloads](https://img.shields.io/npm/dt/@theihtisham/agent-shadow-brain?color=06b6d4&labelColor=1a0a2e&style=for-the-badge)](https://www.npmjs.com/package/@theihtisham/agent-shadow-brain)
9
+ [![npm weekly](https://img.shields.io/npm/dw/@theihtisham/agent-shadow-brain?color=10b981&labelColor=1a0a2e&style=for-the-badge&label=weekly)](https://www.npmjs.com/package/@theihtisham/agent-shadow-brain)
10
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/@theihtisham/agent-shadow-brain?color=f472b6&labelColor=1a0a2e&style=for-the-badge&label=size)](https://bundlephobia.com/package/@theihtisham/agent-shadow-brain)
11
+ [![license](https://img.shields.io/badge/license-MIT-8b5cf6?labelColor=1a0a2e&style=for-the-badge)](https://github.com/theihtisham/agent-shadow-brain/blob/master/LICENSE)
12
+ [![node](https://img.shields.io/badge/node-%3E%3D18-22c55e?labelColor=1a0a2e&style=for-the-badge&logo=node.js)](https://nodejs.org/)
13
+ [![TypeScript](https://img.shields.io/badge/TypeScript-100%25-3178c6?labelColor=1a0a2e&style=for-the-badge&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
14
+ [![GitHub stars](https://img.shields.io/github/stars/theihtisham/agent-shadow-brain?color=f59e0b&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham/agent-shadow-brain/stargazers)
15
+ [![GitHub forks](https://img.shields.io/github/forks/theihtisham/agent-shadow-brain?color=818cf8&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham/agent-shadow-brain/network)
16
+ [![GitHub issues](https://img.shields.io/github/issues/theihtisham/agent-shadow-brain?color=ef4444&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham/agent-shadow-brain/issues)
17
+ [![GitHub last commit](https://img.shields.io/github/last-commit/theihtisham/agent-shadow-brain?color=22d3ee&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham/agent-shadow-brain/commits)
18
+ [![GitHub repo size](https://img.shields.io/github/repo-size/theihtisham/agent-shadow-brain?color=a78bfa&labelColor=1a0a2e&style=for-the-badge)](https://github.com/theihtisham/agent-shadow-brain)
19
+ [![arXiv](https://img.shields.io/badge/arXiv-2504.17033-ef4444?labelColor=1a0a2e&style=for-the-badge&logo=arxiv)](https://arxiv.org/abs/2504.17033)
20
+ [![ICLR 2026](https://img.shields.io/badge/ICLR-2026_TurboQuant-06b6d4?labelColor=1a0a2e&style=for-the-badge)](https://openreview.net/forum?id=TbqSEUXWaO)
21
+ [![Zero Config](https://img.shields.io/badge/zero--config-auto_setup-22c55e?labelColor=1a0a2e&style=for-the-badge&logo=rocket)](#)
22
+ [![MCP](https://img.shields.io/badge/MCP-19_tools-8b5cf6?labelColor=1a0a2e&style=for-the-badge&logo=anthropic)](#)
23
+ [![Dashboard](https://img.shields.io/badge/dashboard-real_time-06b6d4?labelColor=1a0a2e&style=for-the-badge&logo=firefoxbrowser)](#)
24
+ [![LSP](https://img.shields.io/badge/LSP-built_in-f97316?labelColor=1a0a2e&style=for-the-badge&logo=visual-studio-code)](#)
25
+ [![Brain Modules](https://img.shields.io/badge/brain_modules-26-ec4899?labelColor=1a0a2e&style=for-the-badge&logo=brain)](#-architecture)
26
+ [![CLI Commands](https://img.shields.io/badge/CLI-70%2B_commands-eab308?labelColor=1a0a2e&style=for-the-badge&logo=windowsterminal)](#-cli-reference)
27
+ [![AI Agents](https://img.shields.io/badge/agents-10_supported-14b8a6?labelColor=1a0a2e&style=for-the-badge&logo=openai)](#)
28
+ [![Singleton Brain](https://img.shields.io/badge/singleton-global_brain-a855f7?labelColor=1a0a2e&style=for-the-badge&logo=databricks)](#-1-singleton-global-brain)
29
+ [![Subconscious](https://img.shields.io/badge/subconscious-proactive-ec4899?labelColor=1a0a2e&style=for-the-badge&logo=brain)](#-2-subconscious-engine)
30
+ [![L0 Cache](https://img.shields.io/badge/L0_cache-%3C1ms-22d3ee?labelColor=1a0a2e&style=for-the-badge&logo=lightning)](#-4-l0-sub-millisecond-cache)
31
+ [![Auto-Attach](https://img.shields.io/badge/attach--all-one_command-f59e0b?labelColor=1a0a2e&style=for-the-badge&logo=rocket)](#-3-universal-bootstrap-attach-all)
32
+ [![Self Evolving](https://img.shields.io/badge/self--evolving-genetic_AI-d946ef?labelColor=1a0a2e&style=for-the-badge&logo=dna)](#)
33
+ [![Infinite Memory](https://img.shields.io/badge/memory-infinite-facc15?labelColor=1a0a2e&style=for-the-badge&logo=databricks)](#)
34
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-22c55e?labelColor=1a0a2e&style=for-the-badge&logo=git)](https://github.com/theihtisham/agent-shadow-brain/pulls)
35
+ [![Made with Love](https://img.shields.io/badge/made_with-%E2%9D%A4%EF%B8%8F-ef4444?labelColor=1a0a2e&style=for-the-badge)](#)
36
+ [![Follow](https://img.shields.io/github/followers/theihtisham?label=follow&color=a855f7&labelColor=1a0a2e&style=for-the-badge&logo=github)](https://github.com/theihtisham)
37
+
38
+ <br/>
39
+
40
+ ### **One Brain. Every Agent. Every Project. Every Session. Forever.**
41
+
42
+ **Agent Shadow Brain** is the singleton intelligence layer that makes **every AI coding agent** smarter — Claude Code, Cursor, Cline, Codex, GitHub Copilot, Windsurf, Kilo Code, Roo Code, OpenCode, Aider — all sharing the same brain. What one agent learns, every agent knows. What you discover in project A is available in project B. Forever.
43
+
44
+ > **v5.2.0 — Subconscious Singularity Edition**: One command — `npx @theihtisham/agent-shadow-brain attach-all` — auto-detects every AI agent installed on your machine and wires them to a singleton global brain. Every new session, every agent, every project: Shadow Brain proactively injects the most relevant context **before the agent asks**. Your agents stop forgetting. They stop hallucinating. They start collaborating across tools.
45
+
46
+ ```bash
47
+ # 30-second install. Every agent on your machine becomes smarter.
48
+ npx @theihtisham/agent-shadow-brain attach-all
49
+ ```
50
+
51
+ [**30-Second Install**](#-getting-started-30-seconds) · [**The Singularity**](#-v520--what-makes-it-singular) · [**Live Dashboard**](#-web-dashboard) · [**Algorithms**](#-algorithms--research) · [**70+ CLI Commands**](#-cli-reference) · [**Architecture**](#-architecture) · [**Star on GitHub ⭐**](https://github.com/theihtisham/agent-shadow-brain)
52
+
53
+ </div>
54
+
55
+ ---
56
+
57
+ ## ⚡ Why Shadow Brain Exists
58
+
59
+ | Without Shadow Brain | With Shadow Brain |
60
+ |---|---|
61
+ | Every new session, your agent starts from zero | Agent gets a 2K-token briefing of relevant context **before it asks** |
62
+ | Cursor learns something — Claude doesn't know | One singleton brain — what one agent learns, all agents know |
63
+ | Discoveries in project A don't help project B | Cross-project memory federation by default |
64
+ | Each AI tool needs its own setup | One command attaches every agent |
65
+ | Agents hallucinate APIs that don't exist | Adversarial defense + multi-agent consensus voting |
66
+ | Your codebase patterns are reinvented daily | Code DNA fingerprinting enforces your style across all agents |
67
+ | 30 minutes of config before anything works | Zero config, auto-detect, instant value |
68
+
69
+ ## 🚀 v5.2.0 — What Makes It Singular
70
+
71
+ ### 🧠 1. Singleton Global Brain
72
+
73
+ One database (`~/.shadow-brain/global.db`) is the **source of truth** for every project and every agent on your machine. Project-scoped views give each project its own namespace, but the data lives in one place. SQLite WAL mode + write queue handle concurrent multi-agent writes safely. Auto-vacuum at 500MB, auto-prune at 1GB.
74
+
75
+ ```bash
76
+ shadow-brain global stats # See cross-project, cross-agent stats
77
+ shadow-brain global recall # Search across every project + every agent
78
+ ```
79
+
80
+ ### 💭 2. Subconscious Engine
81
+
82
+ Every time any agent starts a new session, the Subconscious **proactively injects** a tight briefing of:
83
+ - Recent decisions made in this project (last 24h)
84
+ - Active tasks (TODOs, in-progress items)
85
+ - Similar past work from other projects
86
+ - Cross-agent insights (what Claude learned that Cursor should know)
87
+ - Warnings and known pitfalls
88
+
89
+ Hard-capped at 2K tokens. Relevance-ranked. The agent doesn't have to ask — the brain surfaces it implicitly. Like human intuition.
90
+
91
+ ```bash
92
+ shadow-brain subconscious inject # See what your agent gets
93
+ shadow-brain subconscious configure --budget 3000 # Tune the budget
94
+ ```
95
+
96
+ ### 🪝 3. Universal Bootstrap (`attach-all`)
97
+
98
+ One command. Detects every AI agent installed on your machine. Installs the right hook for each one's native mechanism:
99
+
100
+ | Agent | Hook Mechanism |
101
+ |---|---|
102
+ | **Claude Code** | `~/.claude/settings.json` → `hooks.SessionStart` |
103
+ | **Cursor** | `.cursor/rules/shadow-brain.md` + `.cursor/mcp.json` |
104
+ | **Cline** | `~/.vscode/.../cline_mcp_settings.json` |
105
+ | **Windsurf** | `.windsurfrules` + `~/.windsurf/mcp.json` |
106
+ | **Codex** | `~/.codex/config.json` |
107
+ | **Kilo Code** | `~/.kilocode/settings.json` |
108
+ | **OpenCode** | `~/.opencode/settings.json` |
109
+ | **Roo Code** | `~/.roocode/mcp.json` |
110
+ | **Aider** | `~/.aider.conf.yml` `read:` directive |
111
+ | **GitHub Copilot** | `.github/copilot-instructions.md` |
112
+
113
+ ```bash
114
+ shadow-brain attach-all # Wire every detected agent
115
+ shadow-brain attach-all --dry-run # See what would be wired
116
+ ```
117
+
118
+ ### ⚡ 4. L0 Sub-Millisecond Cache
119
+
120
+ In-memory hot tier sits in front of the singleton brain. Hot recalls return in **<1ms**. Byte-budgeted (default 64MB), LRU-evicted, per-namespace. Tracks every access in nanoseconds.
121
+
122
+ ```bash
123
+ shadow-brain global cache # Hit rate, top keys, ns-latency
124
+ ```
125
+
126
+ ### 🎯 5. First-Class Adapters for Every Major Agent
127
+
128
+ Cursor, Windsurf, and Copilot were stub aliases in v5.1.1. In v5.2.0 they each have **dedicated adapters** matching their actual file layouts, conversation parsers, and injection mechanisms.
129
+
130
+ ---
131
+
132
+ ---
133
+
134
+ ## The Problem
135
+
136
+ You use AI coding agents. They're powerful, but:
137
+
138
+ | Problem | Impact |
139
+ |---|---|
140
+ | Agents **forget everything** between sessions | Same mistakes, zero learning |
141
+ | Multiple agents **don't communicate** | Claude doesn't know what Cursor learned |
142
+ | Generated code has **hallucinations** | LLMs fabricate APIs that don't exist |
143
+ | No **cross-session memory** | Every conversation starts from zero |
144
+ | No **cross-project learning** | Discoveries in one project don't help others |
145
+ | Setup is **complicated** | 30 minutes of config before anything works |
146
+ | Each tool needs **separate config** | Claude, Cursor, Cline all need different setup |
147
+
148
+ ## The Solution
149
+
150
+ **Shadow Brain v5.1.1** — zero-config, auto-detecting, infinite-intelligence shadow layer:
151
+
152
+ ```
153
+ ┌──────────────┐ auto-detect ┌──────────────────────────────────────────┐
154
+ │ AI Agents │ ◀──────────────── │ SHADOW BRAIN v5.1.1 │
155
+ │ Claude Code │ MCP auto-install │ │
156
+ │ Cursor │ zero-config │ ┌─ HYPER-COGNITIVE (v5.1.1 NEW) ────┐ │
157
+ │ Kilo Code │ │ │ Built-in LSP Server (stdio+TCP) │ │
158
+ │ Cline │ watches │ │ Custom LLM Fine-Tuning Engine │ │
159
+ │ OpenCode │ ──────────────▶ │ │ Smart Cache (hot/warm/cold tiers) │ │
160
+ │ Codex │ file changes │ │ Intent Engine (NLP commands) │ │
161
+ │ Roo Code │ git commits │ │ Code DNA (9-gene fingerprinting) │ │
162
+ │ Aider │ activity │ │ Temporal Intelligence (velocity) │ │
163
+ │ Windsurf │ │ └────────────────────────────────────┘ │
164
+ └──────────────┘ │ ┌─ ZERO-CONFIG (v5.0.1) ─────────────┐ │
165
+ ▲ │ │ Auto-detect + MCP + Dashboard │ │
166
+ │ │ │ Plugins + Export/Import + Hooks │ │
167
+ │ │ └────────────────────────────────────┘ │
168
+ │ │ ┌─ INFINITE MEMORY (v5.0.0) ────────┐ │
169
+ │ │ │ 4-tier hierarchical compression │ │
170
+ │ │ │ Context-triggered recall │ │
171
+ │ │ │ Multi-agent consensus + trust │ │
172
+ │ │ │ Collective cross-project learning │ │
173
+ │ │ └────────────────────────────────────┘ │
174
+ │ │ ┌─ HYPER-INTELLIGENCE (v4) ──────────┐ │
175
+ │ │ │ TurboQuant 6x Compression │ │
176
+ │ │ │ SSSP BMSSP Quantum Routing │ │
177
+ │ │ │ Self-Evolution + CAIP + Swarm │ │
178
+ │ │ │ PageRank + Predictive + Adversarial │ │
179
+ └──────────────────────────┴──────────────────────────────────────────┘
180
+ ```
181
+
182
+ ---
183
+
184
+ ## v5.1.1 — What's New
185
+
186
+ ### 6 Hyper-Cognitive Brain Modules
187
+
188
+ <table>
189
+ <tr>
190
+ <td width="50%">
191
+
192
+ ### Built-in LSP Server
193
+
194
+ **Language Server Protocol** — real-time IDE feedback without external tools.
195
+
196
+ Pure Node.js LSP server supporting stdio and TCP transport modes:
197
+ - **Diagnostics**: pushes brain insights as IDE warnings/errors
198
+ - **Hover**: shows code health info on hover
199
+ - **Code Actions**: quick-fix suggestions from brain analysis
200
+ - **Zero dependency**: no external LSP libraries required
201
+
202
+ ```bash
203
+ shadow-brain lsp --stdio # stdio mode (for editors)
204
+ shadow-brain lsp --tcp 2087 # TCP mode (for remote)
205
+ ```
206
+
207
+ ### Custom LLM Fine-Tuning Engine
208
+
209
+ **Train on your codebase** — your brain learns YOUR patterns.
210
+
211
+ Automatic training data generation from code changes, insights, and fixes:
212
+ - **Pair extraction**: before/after code → training pairs
213
+ - **Pattern mining**: recurring fix patterns → fine-tune examples
214
+ - **JSONL export**: ready for OpenAI, Anthropic, or local fine-tuning
215
+ - **Quality scoring**: only high-confidence pairs enter the dataset
216
+
217
+ ```bash
218
+ shadow-brain fine-tune status # Training data stats
219
+ shadow-brain fine-tune generate [dir] # Generate training pairs
220
+ shadow-brain fine-tune export [path] # Export JSONL dataset
221
+ ```
222
+
223
+ </td>
224
+ <td width="50%">
225
+
226
+ ### Smart Cache (Multi-Tier)
227
+
228
+ **Hot/Warm/Cold** — intelligent caching with predictive prefetch.
229
+
230
+ Three-tier LRU cache with automatic promotion and demotion:
231
+ - **Hot tier**: 200 entries, fastest access
232
+ - **Warm tier**: 1000 entries, promoted on repeated access
233
+ - **Cold tier**: 5000 entries, compressed storage
234
+ - **Predictive prefetch**: co-access graph predicts what you'll need next
235
+ - **Tag-based invalidation**: invalidate by category
236
+
237
+ ```bash
238
+ shadow-brain cache stats # Hit rate, tier sizes, memory usage
239
+ shadow-brain cache clear # Clear all tiers
240
+ ```
241
+
242
+ ### Intent Engine
243
+
244
+ **Natural language → brain actions** — understand what you mean.
245
+
246
+ Multi-strategy NLP command understanding:
247
+ - **Keyword matching**: fast path for common commands
248
+ - **Fuzzy matching**: handles typos and variations
249
+ - **Context-aware**: uses current file/project context
250
+ - **Confidence scoring**: routes to best-matching action
251
+
252
+ ```bash
253
+ shadow-brain intent "find security bugs" # Maps to: analyze + security filter
254
+ shadow-brain intent "show hot files" # Maps to: temporal + heatmap
255
+ ```
256
+
257
+ </td>
258
+ </tr>
259
+ <tr>
260
+ <td width="50%">
261
+
262
+ ### Code DNA Fingerprinting
263
+
264
+ **9-gene analysis** — every file gets a unique genetic profile.
265
+
266
+ Analyzes code across 9 gene categories to create a structural fingerprint:
267
+ - **Structure genes**: classes, functions, nesting depth
268
+ - **Complexity genes**: cyclomatic complexity, cognitive load
269
+ - **Style genes**: naming conventions, formatting patterns
270
+ - **Dependency genes**: import graph, coupling metrics
271
+ - **Evolution genes**: change frequency, stability score
272
+ - **Similarity matching**: find structurally similar files across projects
273
+
274
+ ```bash
275
+ shadow-brain dna analyze [dir] # Generate DNA profiles
276
+ shadow-brain dna compare f1 f2 # Compare two file fingerprints
277
+ shadow-brain dna similar [file] # Find similar files
278
+ ```
279
+
280
+ </td>
281
+ <td width="50%">
282
+
283
+ ### Temporal Intelligence
284
+
285
+ **Time-series code evolution** — velocity tracking & bug prediction.
286
+
287
+ Continuous monitoring of code change patterns over time:
288
+ - **Velocity metrics**: daily/weekly/monthly rates with trend detection
289
+ - **File heatmaps**: hotness scoring, churn risk, stability
290
+ - **Bug prediction**: 5-factor probability model per file
291
+ - **Anomaly detection**: burst detection, drought alerts, unusual hours
292
+ - **Peak analysis**: identifies your most productive hours and days
293
+
294
+ ```bash
295
+ shadow-brain temporal stats # Velocity, anomalies, predictions
296
+ shadow-brain temporal hot # Top 10 hottest files
297
+ shadow-brain temporal predict # Bug risk predictions
298
+ shadow-brain temporal timeline # Recent event timeline
299
+ ```
300
+
301
+ </td>
302
+ </tr>
303
+ </table>
304
+
305
+ ---
306
+
307
+ ## v5.0.1 — What's New
308
+
309
+ ### Zero-Config Auto-Setup
310
+
311
+ Install it. That's it. Shadow Brain automatically:
312
+
313
+ - Detects your project type (frontend, backend, fullstack, mobile, game, systems, data-science)
314
+ - Detects 25+ languages, 15+ frameworks, 5+ build tools, 5+ test frameworks
315
+ - Detects which AI tools are installed (Claude Code, Cursor, Kilo Code, Cline, OpenCode, Codex, Aider, Windsurf)
316
+ - Auto-installs MCP server configuration for every detected AI tool
317
+ - Auto-installs git pre-commit and pre-push hooks
318
+ - Generates an optimal brain config based on project complexity
319
+
320
+ ```bash
321
+ npm install @theihtisham/agent-shadow-brain
322
+ # → Shadow Brain v5.1.1 auto-configured for my-app (fullstack)
323
+ # → AI tools detected: Claude Code, Cursor
324
+ # → Run: shadow-brain start
325
+ ```
326
+
327
+ ### MCP Server — Works with EVERY AI Tool
328
+
329
+ The brain exposes itself as a **Model Context Protocol (MCP) server** with 19 tools that any AI tool can call:
330
+
331
+ | MCP Tool | What It Does |
332
+ |---|---|
333
+ | `brain_status` | Get full brain status |
334
+ | `brain_analyze` | Trigger code analysis |
335
+ | `brain_health` | Get health score (A-F) |
336
+ | `brain_insights` | Get recent insights |
337
+ | `brain_fixes` | Get smart fix suggestions |
338
+ | `brain_memory_store` | Store knowledge in hierarchical memory |
339
+ | `brain_memory_search` | Search across all memory tiers |
340
+ | `brain_memory_stats` | Memory compression statistics |
341
+ | `brain_recall` | Context-triggered associative recall |
342
+ | `brain_consensus_propose` | Submit a proposal for agent consensus |
343
+ | `brain_consensus_vote` | Vote on a pending proposal |
344
+ | `brain_collective_propose` | Propose a cross-project rule |
345
+ | `brain_collective_search` | Search collective learning rules |
346
+ | `brain_turbo_search` | Semantic search in compressed memory |
347
+ | `brain_predict` | Predict bug risk for files |
348
+ | `brain_graph_query` | Query knowledge graph |
349
+ | `brain_defense_scan` | Scan for hallucination patterns |
350
+ | `brain_evolve_status` | Get self-evolution status |
351
+ | `brain_dashboard_url` | Get dashboard URL |
352
+
353
+ Works with **Claude Code**, **Cursor**, **Kilo Code**, **Cline**, **OpenCode**, and any MCP-compatible AI tool.
354
+
355
+ ```bash
356
+ # Start MCP server (auto-started by AI tools)
357
+ shadow-brain mcp
358
+
359
+ # Cursor compatibility (root path POST + /v1/chat)
360
+ # Claude Code compatibility (JSON-RPC 2.0 over stdio/HTTP)
361
+ ```
362
+
363
+ ### Rich Web Dashboard
364
+
365
+ Real-time browser dashboard at `http://localhost:7341` with WebSocket live updates:
366
+
367
+ - **Stats Topbar**: 8 live counters — Insights, Fixes, Memory KB, Modules, AI Tools, Evolution Gen, Swarm Convergence, Turbo Compression
368
+ - **Health Score**: A-F grading with dimension breakdown (Security, Quality, Performance, Architecture, Maintainability, Test Coverage)
369
+ - **Memory Tiers**: Visual bars showing Raw (50K), Summary (10K), Pattern (2K), Principle (500) with Turbo compression ratio
370
+ - **Live Insights Stream**: Real-time feed of brain insights with priority badges
371
+ - **Smart Fixes**: Actionable fix suggestions with file/line references
372
+ - **AI Tools Panel**: 8 tools showing connected/detected status
373
+ - **Brain Modules**: 13 modules with active/idle/error indicators
374
+ - **Control Buttons**: Trigger analysis on-demand, refresh data
375
+
376
+ ```bash
377
+ shadow-brain start . # Dashboard auto-starts at http://localhost:7341
378
+ shadow-brain dash . # Dashboard only mode
379
+ ```
380
+
381
+ ### Natural Language Queries
382
+
383
+ Ask your brain questions in plain English:
384
+
385
+ ```bash
386
+ shadow-brain ask "What security issues exist in the auth module?"
387
+ shadow-brain ask "Which files have the highest bug risk?"
388
+ shadow-brain ask "What patterns have we learned about React hooks?"
389
+ ```
390
+
391
+ ### Brain Export/Import — Team Sync
392
+
393
+ Export your brain state and share it with your team:
394
+
395
+ ```bash
396
+ shadow-brain export # Full export with all modules
397
+ shadow-brain export -o ./team-brain # Custom output directory
398
+ shadow-brain import brain-export.json # Import + merge
399
+ shadow-brain import brain-export.json --merge --skip swarm,evolution
400
+ ```
401
+
402
+ ### Plugin System
403
+
404
+ Extend Shadow Brain with custom plugins:
405
+
406
+ ```bash
407
+ shadow-brain plugin list # List installed plugins
408
+ shadow-brain plugin create my-plugin # Create from template
409
+ shadow-brain plugin stats # Plugin system statistics
410
+ ```
411
+
412
+ Plugins can hook into `pre-analysis` and `post-analysis` pipelines to add custom insights, filter results, or integrate with external services.
413
+
414
+ ### 5 New Commands
415
+
416
+ ```bash
417
+ shadow-brain off # Clean shutdown
418
+ shadow-brain ask "..." # Natural language query
419
+ shadow-brain export # Export brain state
420
+ shadow-brain import FILE # Import brain state
421
+ shadow-brain plugin CMD # Plugin management
422
+ ```
423
+
424
+ ---
425
+
426
+ ## Getting Started — 30 Seconds
427
+
428
+ ```bash
429
+ # Install globally
430
+ npm install -g @theihtisham/agent-shadow-brain
431
+
432
+ # Or use npx (no install needed)
433
+ npx @theihtisham/agent-shadow-brain start .
434
+ ```
435
+
436
+ That's literally it. Shadow Brain will:
437
+ 1. **Auto-detect** your project, languages, frameworks, AI tools (zero config)
438
+ 2. **Auto-install** MCP server config for Claude Code, Cursor, Kilo Code, Cline, etc.
439
+ 3. **Auto-install** git hooks for pre-commit and pre-push
440
+ 4. Watch your project files for changes
441
+ 5. Analyze every change with LLM + 22 brain modules
442
+ 6. Inject expert insights into your agent's memory
443
+ 7. Store all knowledge in hierarchical memory for infinite retention
444
+ 8. Activate past memories automatically based on context
445
+ 9. Share verified patterns across projects via collective learning
446
+ 10. Compress knowledge with TurboQuant for infinite retention
447
+ 11. Evolve its own rules via genetic algorithm
448
+ 12. Share insights across agents via CAIP
449
+ 13. Detect hallucinations with adversarial verification
450
+ 14. Run consensus when multiple agents disagree
451
+ 15. Serve a rich web dashboard at `localhost:7341`
452
+
453
+ ### Quick Review (No Watch Mode)
454
+
455
+ ```bash
456
+ shadow-brain review . # One-shot analysis
457
+ shadow-brain review . --show-health # + health score
458
+ shadow-brain review . --show-fixes # + fix suggestions
459
+ shadow-brain review . --output json # JSON for scripting
460
+ ```
461
+
462
+ ---
463
+
464
+ ## Web Dashboard
465
+
466
+ The v5.1.1 dashboard provides a real-time view into your brain:
467
+
468
+ ```
469
+ ┌──────────────────────────────────────────────────────────────────────────┐
470
+ │ Shadow Brain v5.1.1 [Analyze] [↻] │
471
+ ├──────────────────────────────────────────────────────────────────────────┤
472
+ │ Insights: 142 │ Fixes: 38 │ Memory: 247KB │ Modules: 22/22 │ ... │
473
+ ├──────────────┬─────────────────────────────────────┬───────────────────┤
474
+ │ Health: 87% │ Live Insights Stream │ AI Tools │
475
+ │ ████████░░ │ ● [HIGH] SQL injection in login.ts │ ● Claude Code ✓ │
476
+ │ Security: A │ ● [MED] Missing error handling │ ● Cursor ✓ │
477
+ │ Quality: B+ │ ● [LOW] Unused import in utils │ ● Kilo Code ✓ │
478
+ │ Perf: A- │ ● [CRIT] Exposed API key │ ● Cline — │
479
+ │ Arch: B │ │ ● OpenCode — │
480
+ │ Maintain: A ├─────────────────────────────────────┤ ● Codex — │
481
+ │ Tests: C+ │ Smart Fixes │ ● Aider — │
482
+ │ │ 1. Add parameterized query... │ ● Windsurf — │
483
+ ├──────────────┤ 2. Wrap in try/catch with... ├───────────────────┤
484
+ │ Memory Tiers │ 3. Remove unused import on L42 │ Brain Modules │
485
+ │ Raw: 8421 │ │ ● Hierarchical ✓ │
486
+ │ Summ: 1203 │ │ ● TurboMemory ✓ │
487
+ │ Patt: 187 │ │ ● Consensus ✓ │
488
+ │ Princ: 24 │ │ ● Swarm ✓ │
489
+ │ Turbo: 6.2x │ │ ● Evolution ✓ │
490
+ │ │ │ ● Adversarial ✓ │
491
+ └──────────────┴─────────────────────────────────────┴───────────────────┘
492
+ ```
493
+
494
+ ---
495
+
496
+ ## v5.0.0 Infinite Intelligence Engine
497
+
498
+ ### 4 Breakthrough Modules
499
+
500
+ <table>
501
+ <tr>
502
+ <td width="50%">
503
+
504
+ ### Infinite Memory Layer
505
+
506
+ **Hierarchical Memory Compression** — 4-tier pyramid that never forgets.
507
+
508
+ Knowledge flows through compression tiers as it ages:
509
+ - **Raw** (50K entries) — full detail, hot path
510
+ - **Summary** (10K) — condensed key points
511
+ - **Pattern** (2K) — recurring patterns extracted
512
+ - **Principle** (500) — timeless design rules
513
+
514
+ Drill-down and drill-up between tiers. Older knowledge compresses, never deletes.
515
+
516
+ ```bash
517
+ shadow-brain memory stats # 4 tiers | 12,847 entries
518
+ shadow-brain memory store "..." # Store new knowledge
519
+ shadow-brain memory search "auth" # Cross-tier semantic search
520
+ ```
521
+
522
+ **Context-Triggered Associative Recall** — memories that activate themselves.
523
+
524
+ Instead of requiring explicit search queries, this engine monitors your current work context and automatically surfaces relevant past knowledge:
525
+ - File path pattern matching (editing `auth/*.ts` → security memories)
526
+ - Keyword detection (typing "database" → SQL pattern memories)
527
+ - Category association (bug-fix context → past fix patterns)
528
+ - Co-occurrence networks (memories activated together strengthen their link)
529
+ - Learned trigger patterns that improve with use
530
+
531
+ ```bash
532
+ shadow-brain recall . --file src/auth/login.ts --keywords "jwt,session"
533
+ # → Activates 8 memories | Top: "JWT rotation pattern (92%)"
534
+ ```
535
+
536
+ </td>
537
+ <td width="50%">
538
+
539
+ ### Multi-Agent Intelligence Layer
540
+
541
+ **Consensus Engine** — voting, trust scoring, conflict resolution.
542
+
543
+ When multiple AI agents observe the same codebase, they may produce conflicting insights. This engine:
544
+ 1. Collects proposals from agents
545
+ 2. Opens voting windows (agree/disagree/abstain with confidence)
546
+ 3. Computes trust-weighted agreement scores
547
+ 4. Resolves conflicts via confidence intervals
548
+ 5. Tracks long-term agent trust based on proposal accuracy
549
+
550
+ ```bash
551
+ shadow-brain consensus status
552
+ shadow-brain consensus propose "Use bcrypt for all password hashing" security 0.95
553
+ shadow-brain consensus vote <id> agree 0.9 "Industry standard"
554
+ shadow-brain consensus results
555
+ ```
556
+
557
+ **Collective Learning** — discoveries flow across all projects.
558
+
559
+ When you discover a pattern in Project A, it becomes a verified rule available in Project B:
560
+ - Rule proposal with evidence and verification
561
+ - Viral propagation across connected brain instances
562
+ - Accuracy tracking per rule (tested vs. false positive)
563
+ - Category-based organization (security, performance, architecture...)
564
+ - Trust scores for rule sources
565
+
566
+ ```bash
567
+ shadow-brain collective status
568
+ shadow-brain collective propose "Always validate file upload MIME types" security
569
+ shadow-brain collective search performance
570
+ ```
571
+
572
+ </td>
573
+ </tr>
574
+ </table>
575
+
576
+ ---
577
+
578
+ ## v4.0.0 Hyper-Intelligence Engine
579
+
580
+ ### 8 Breakthrough Modules (included in v5.1.1)
581
+
582
+ <table>
583
+ <tr>
584
+ <td width="50%">
585
+
586
+ ### Quantum Memory Layer
587
+
588
+ **TurboQuant Infinite Memory** — never forget anything, ever.
589
+
590
+ Based on Google Research's **TurboQuant** (ICLR 2026):
591
+ - **PolarQuant**: 2 bits per dimension (polar coordinate quantization)
592
+ - **QJL Residual**: 1 bit per dimension (random rotation + sign)
593
+ - **Total**: 3 bits/dim = **6x compression** with <1% accuracy loss
594
+ - **Result**: Infinite retention — old knowledge is compressed, never deleted
595
+
596
+ ```bash
597
+ shadow-brain turbo stats
598
+ shadow-brain turbo search "authentication patterns"
599
+ ```
600
+
601
+ **SSSP Quantum Router** — deterministic shortest-path message routing.
602
+
603
+ Based on **"Breaking the Sorting Barrier"** (arXiv 2504.17033, Duan et al.):
604
+ - **BMSSP Algorithm**: O(m log<sup>2/3</sup> n) — breaks the sorting barrier
605
+ - **Deterministic**: No randomization, provably correct
606
+
607
+ ```bash
608
+ shadow-brain route status
609
+ shadow-brain route find node-A node-B
610
+ ```
611
+
612
+ </td>
613
+ <td width="50%">
614
+
615
+ ### Self-Evolution Layer
616
+
617
+ **Genetic Algorithm Self-Evolution** — rules that write themselves.
618
+
619
+ - **Population**: 50 genetic rule chromosomes
620
+ - **Selection**: Tournament (k=5) — survival of the fittest
621
+ - **Crossover**: Single-point recombination
622
+ - **Mutation**: Gaussian noise (Box-Muller transform, sigma=0.1)
623
+ - **Fitness**: accuracy x coverage x (1 / falsePositiveRate)
624
+
625
+ ```bash
626
+ shadow-brain evolve status
627
+ shadow-brain evolve run
628
+ shadow-brain evolve best-rules security
629
+ ```
630
+
631
+ **Cross-Agent Intelligence Protocol (CAIP)** — agents that talk to each other.
632
+
633
+ Your Claude Code session learns what your Cursor session discovered:
634
+ - Zero-config broadcast protocol
635
+ - Agent identification + insight tagging
636
+ - Multi-agent consensus building
637
+
638
+ ```bash
639
+ shadow-brain caip status
640
+ shadow-brain caip broadcast "Security pattern detected"
641
+ ```
642
+
643
+ </td>
644
+ </tr>
645
+ <tr>
646
+ <td width="50%">
647
+
648
+ ### Defense & Trust Layer
649
+
650
+ **Adversarial Hallucination Defense** — trust nothing, verify everything.
651
+
652
+ - Cross-reference every critical insight against actual code
653
+ - Evidence scoring with confidence thresholds
654
+ - Verdict: `real` | `hallucinated` | `uncertain`
655
+
656
+ ```bash
657
+ shadow-brain defense status
658
+ shadow-brain defense scan "This API endpoint exists at /api/v2/users"
659
+ ```
660
+
661
+ **Swarm Intelligence** — Ant Colony Optimization for file prioritization.
662
+
663
+ - Pheromone deposit: +3 for critical, +2 for high, +1 for medium
664
+ - Evaporation: decay over time to avoid staleness
665
+
666
+ ```bash
667
+ shadow-brain swarm status
668
+ shadow-brain swarm priorities
669
+ ```
670
+
671
+ </td>
672
+ <td width="50%">
673
+
674
+ ### Analytics & Prediction Layer
675
+
676
+ **Knowledge Graph + PageRank** — code impact radar.
677
+
678
+ - Identify high-impact files (change one, break many)
679
+ - Cycle detection in dependency graphs
680
+ - Entity extraction with file/line tracking
681
+
682
+ ```bash
683
+ shadow-brain graph build .
684
+ shadow-brain graph pagerank
685
+ shadow-brain graph cycles
686
+ ```
687
+
688
+ **Predictive Engine** — predict bugs before they happen.
689
+
690
+ - Bug risk scoring: `low` | `medium` | `high` | `critical`
691
+ - Technical debt forecasting
692
+ - Anomaly detection in change patterns
693
+
694
+ ```bash
695
+ shadow-brain predict bugs .
696
+ ```
697
+
698
+ </td>
699
+ </tr>
700
+ </table>
701
+
702
+ ---
703
+
704
+ ## Algorithms & Research
705
+
706
+ Shadow Brain v5.1.1 implements algorithms from **peer-reviewed research**:
707
+
708
+ | Algorithm | Paper / Origin | Application | Complexity |
709
+ |---|---|---|---|
710
+ | **Hierarchical Compression** | Novel 4-tier system | Infinite memory with drill-down | O(n) per tier |
711
+ | **Associative Recall** | Spreading activation model | Context-triggered memory activation | O(n x k) |
712
+ | **Consensus Protocol** | Byzantine fault tolerance | Multi-agent agreement with trust | O(v x log v) |
713
+ | **TurboQuant** | Google Research, ICLR 2026 | Vector compression (PolarQuant + QJL) | O(n) per vector |
714
+ | **BMSSP (SSSP)** | arXiv 2504.17033, Duan et al. | Neural mesh message routing | O(m log<sup>2/3</sup> n) |
715
+ | **Shannon Entropy** | Claude Shannon, 1948 | Cross-project insight relevance scoring | O(n) |
716
+ | **Bayesian Inference** | Thomas Bayes, 1763 | Confidence updating, meta-learning | O(1) per update |
717
+ | **Cosine Similarity** | Vector space model | Knowledge deduplication | O(d) per pair |
718
+ | **PageRank** | Brin & Page, 1998 | Code entity impact analysis | O(V + E) per iteration |
719
+ | **Tarjan's SCC** | Robert Tarjan, 1972 | Dependency cycle detection | O(V + E) |
720
+ | **Winnowing** | Schleimer et al., 2003 | Code duplicate fingerprinting | O(n) |
721
+ | **Box-Muller** | Box & Muller, 1958 | Gaussian mutation in genetic algorithm | O(1) per sample |
722
+ | **Ant Colony (ACO)** | Dorigo, 1992 | File priority pheromone system | O(n x m) |
723
+ | **Tournament Selection** | Goldberg, 1989 | Genetic rule selection (k=5) | O(k) per selection |
724
+
725
+ ### TurboQuant Pipeline Detail
726
+
727
+ ```
728
+ Input Vector (64-dim, float64)
729
+ |
730
+ v
731
+ +-------------+
732
+ | PolarQuant |-- Cartesian -> Polar coordinates
733
+ | 2 bits/dim |-- Quantize angles to 4 levels (2 bits each)
734
+ +------+-------+ Pack into Uint8Array
735
+ |
736
+ v
737
+ +-------------+
738
+ | QJL Residual|-- Random rotation (Hadamard-like)
739
+ | 1 bit/dim |-- Sign extraction (1 bit per dim)
740
+ +------+-------+ Pack into Uint8Array
741
+ |
742
+ v
743
+ TurboVector { polar: Uint8Array, qjl: Uint8Array, dim: number, radius: number }
744
+ = 3 bits/dim total = 6x compression from float64
745
+ = ZERO FORGETTING -- compressed knowledge stays searchable forever
746
+ ```
747
+
748
+ ---
749
+
750
+ ## Features
751
+
752
+ <table>
753
+ <tr>
754
+ <td width="20%">
755
+
756
+ ### Hyper-Cognitive (v5.1.1)
757
+ - Built-in LSP Server
758
+ - Custom LLM Fine-Tuning
759
+ - Smart Cache (3-tier)
760
+ - Intent Engine (NLP)
761
+ - Code DNA Fingerprinting
762
+ - Temporal Intelligence
763
+
764
+ </td>
765
+ <td width="20%">
766
+
767
+ ### Zero Config (v5.0.1)
768
+ - Auto-detect project + tools
769
+ - MCP for ALL AI tools
770
+ - Rich web dashboard
771
+ - Natural language queries
772
+ - Plugin system
773
+ - Brain export/import
774
+ - Git hook auto-install
775
+
776
+ </td>
777
+ <td width="20%">
778
+
779
+ ### Infinite Intelligence (v5)
780
+ - 4-tier hierarchical memory
781
+ - Context-triggered recall
782
+ - Multi-agent consensus
783
+ - Collective cross-project learning
784
+
785
+ </td>
786
+ <td width="20%">
787
+
788
+ ### Hyper-Intelligence (v4)
789
+ - TurboQuant infinite memory
790
+ - SSSP quantum routing
791
+ - Self-evolving genetic rules
792
+ - Cross-agent protocol (CAIP)
793
+ - Adversarial defense
794
+ - Swarm intelligence (ACO)
795
+ - Knowledge Graph + PageRank
796
+ - Predictive bug forecasting
797
+
798
+ </td>
799
+ <td width="20%">
800
+
801
+ ### Developer Experience
802
+ - **60+ CLI commands**
803
+ - MCP Server (19 tools)
804
+ - Built-in LSP Server
805
+ - Web dashboard (real-time)
806
+ - Terminal UI (Ink/React)
807
+ - Pre-commit hooks
808
+ - GitHub Actions CI
809
+ - Plugin architecture
810
+
811
+ </td>
812
+ </tr>
813
+ </table>
814
+
815
+ ---
816
+
817
+ ## Architecture
818
+
819
+ ### v5.1.1 Module Map (22 modules)
820
+
821
+ | Module | File | What It Does | Since |
822
+ |---|---|---|---|
823
+ | **LSP Server** | `brain/lsp-server.ts` | Built-in Language Server Protocol (stdio+TCP) | v5.1.1 |
824
+ | **Fine-Tuning Engine** | `brain/fine-tuning-engine.ts` | Custom LLM training data generation | v5.1.1 |
825
+ | **Smart Cache** | `brain/smart-cache.ts` | Multi-tier caching with predictive prefetch | v5.1.1 |
826
+ | **Intent Engine** | `brain/intent-engine.ts` | Natural language command understanding | v5.1.1 |
827
+ | **Code DNA** | `brain/code-dna.ts` | 9-gene code fingerprinting + similarity | v5.1.1 |
828
+ | **Temporal Intelligence** | `brain/temporal-intelligence.ts` | Velocity tracking, heatmaps, bug prediction | v5.1.1 |
829
+ | **Auto Setup** | `brain/auto-setup.ts` | Zero-config project + tool detection | v5.0.1 |
830
+ | **MCP Server** | `brain/mcp-server.ts` | 19-tool MCP server for all AI tools | v5.0.1 |
831
+ | **Plugin System** | `brain/plugin-system.ts` | Hookable analysis pipeline | v5.0.1 |
832
+ | **Brain Portability** | `brain/brain-portability.ts` | Export/import brain state | v5.0.1 |
833
+ | **Dashboard** | `dashboard/server.ts` | Real-time WebSocket dashboard | v5.0.1 |
834
+ | **Hierarchical Memory** | `brain/hierarchical-memory.ts` | 4-tier infinite memory | v5.0.0 |
835
+ | **Context Recall** | `brain/context-recall.ts` | Associative memory activation | v5.0.0 |
836
+ | **Consensus Engine** | `brain/consensus-engine.ts` | Multi-agent voting + trust | v5.0.0 |
837
+ | **Collective Learning** | `brain/collective-learning.ts` | Cross-project rule sharing | v5.0.0 |
838
+ | **TurboMemory** | `brain/turbo-memory.ts` | 6x compressed infinite memory | v4.0.0 |
839
+ | **SSSP Router** | `brain/sssp-router.ts` | Sub-sorting routing | v4.0.0 |
840
+ | **Self-Evolution** | `brain/self-evolution.ts` | Genetic rule optimization | v4.0.0 |
841
+ | **Cross-Agent** | `brain/cross-agent-protocol.ts` | Multi-agent broadcast | v4.0.0 |
842
+ | **Adversarial** | `brain/adversarial-defense.ts` | Hallucination detection | v4.0.0 |
843
+ | **Swarm** | `brain/swarm-intelligence.ts` | File priority pheromones | v4.0.0 |
844
+ | **Knowledge Graph** | `brain/knowledge-graph.ts` | PageRank impact analysis | v4.0.0 |
845
+ | **Predictive** | `brain/predictive-engine.ts` | Bug risk & debt forecasting | v4.0.0 |
846
+
847
+ ---
848
+
849
+ ## CLI Reference
850
+
851
+ ### Core Commands
852
+
853
+ | Command | Description |
854
+ |---|---|
855
+ | `shadow-brain start [dir]` | Start real-time watching + dashboard + MCP |
856
+ | `shadow-brain off` | Clean shutdown |
857
+ | `shadow-brain review [dir]` | One-shot code analysis |
858
+ | `shadow-brain health [dir]` | Health score (A-F grading) |
859
+ | `shadow-brain fix [dir]` | Smart fix suggestions |
860
+ | `shadow-brain report [dir]` | HTML/MD/JSON reports |
861
+ | `shadow-brain metrics [dir]` | Code metrics |
862
+ | `shadow-brain scan [dir]` | Vulnerability scanner |
863
+ | `shadow-brain pr [dir]` | Generate PR description |
864
+ | `shadow-brain commit-msg [dir]` | Generate commit message |
865
+ | `shadow-brain ci [dir]` | GitHub Actions workflow |
866
+ | `shadow-brain hook [dir]` | Pre-commit hook |
867
+ | `shadow-brain dash [dir]` | Web dashboard |
868
+ | `shadow-brain mcp` | MCP server mode |
869
+ | `shadow-brain inject <msg>` | Inject into agent memory |
870
+ | `shadow-brain status` | Current configuration |
871
+ | `shadow-brain setup` | Interactive setup wizard |
872
+ | `shadow-brain doctor` | Health check & diagnostics |
873
+ | `shadow-brain ask <question>` | Natural language brain query |
874
+
875
+ ### v5.1.1 Hyper-Cognitive Commands (NEW)
876
+
877
+ | Command | Description |
878
+ |---|---|
879
+ | `shadow-brain lsp [--stdio\|--tcp PORT]` | Start built-in LSP server |
880
+ | `shadow-brain fine-tune status` | Fine-tuning training data stats |
881
+ | `shadow-brain fine-tune generate [dir]` | Generate training pairs from code |
882
+ | `shadow-brain fine-tune export [path]` | Export JSONL dataset for fine-tuning |
883
+ | `shadow-brain cache stats` | Smart cache hit rate, tier sizes, memory |
884
+ | `shadow-brain cache clear` | Clear all cache tiers |
885
+ | `shadow-brain intent <text>` | Parse natural language intent |
886
+ | `shadow-brain dna analyze [dir]` | Generate Code DNA profiles |
887
+ | `shadow-brain dna compare <f1> <f2>` | Compare two file fingerprints |
888
+ | `shadow-brain dna similar <file>` | Find structurally similar files |
889
+ | `shadow-brain temporal stats` | Velocity, anomalies, predictions |
890
+ | `shadow-brain temporal hot` | Top 10 hottest files by churn |
891
+ | `shadow-brain temporal predict` | Bug risk predictions |
892
+ | `shadow-brain temporal timeline` | Recent event timeline |
893
+
894
+ ### v5.0.1 Commands
895
+
896
+ | Command | Description |
897
+ |---|---|
898
+ | `shadow-brain off` | Clean shutdown of all brain processes |
899
+ | `shadow-brain ask <question>` | Natural language query to the brain |
900
+ | `shadow-brain export [-o dir]` | Export full brain state to JSON |
901
+ | `shadow-brain import <file> [--merge]` | Import brain state |
902
+ | `shadow-brain plugin list` | List installed plugins |
903
+ | `shadow-brain plugin create <name>` | Create plugin from template |
904
+ | `shadow-brain plugin stats` | Plugin system statistics |
905
+
906
+ ### v5.0.0 Infinite Intelligence Commands
907
+
908
+ | Command | Description |
909
+ |---|---|
910
+ | `shadow-brain memory stats` | 4-tier hierarchical memory stats |
911
+ | `shadow-brain memory store <text>` | Store knowledge at raw tier |
912
+ | `shadow-brain memory search <query>` | Cross-tier semantic search |
913
+ | `shadow-brain recall . --file <f>` | Context-triggered associative recall |
914
+ | `shadow-brain consensus status` | Multi-agent consensus stats |
915
+ | `shadow-brain consensus propose <text> <cat> <conf>` | Submit proposal for voting |
916
+ | `shadow-brain consensus vote <id> <vote> <conf> <reason>` | Vote on a proposal |
917
+ | `shadow-brain consensus results` | All resolved proposals |
918
+ | `shadow-brain collective status` | Cross-project rule stats |
919
+ | `shadow-brain collective propose <text> <cat>` | Propose a collective rule |
920
+ | `shadow-brain collective search <cat>` | Search collective rules by category |
921
+ | `shadow-brain v5 [dir]` | Run ALL v5.0.0 analyses |
922
+
923
+ ### v4.0.0 Hyper-Intelligence Commands
924
+
925
+ | Command | Description |
926
+ |---|---|
927
+ | `shadow-brain turbo stats` | TurboQuant infinite memory stats |
928
+ | `shadow-brain turbo search <q>` | Semantic search compressed memory |
929
+ | `shadow-brain route status` | SSSP routing status |
930
+ | `shadow-brain route find <from> <to>` | Shortest path query |
931
+ | `shadow-brain caip status` | Cross-agent protocol status |
932
+ | `shadow-brain caip broadcast <msg>` | Broadcast to all agents |
933
+ | `shadow-brain evolve status` | Genetic algorithm generation stats |
934
+ | `shadow-brain evolve run` | Trigger evolution cycle |
935
+ | `shadow-brain evolve best-rules [cat]` | Top evolved rules by category |
936
+ | `shadow-brain predict bugs [dir]` | Bug risk prediction |
937
+ | `shadow-brain graph build [dir]` | Build knowledge graph + PageRank |
938
+ | `shadow-brain swarm status` | Swarm convergence + priorities |
939
+ | `shadow-brain swarm priorities` | File hotspot ranking |
940
+ | `shadow-brain defense status` | Adversarial defense statistics |
941
+ | `shadow-brain defense scan <text>` | Scan text for hallucination patterns |
942
+ | `shadow-brain v4 [dir]` | Run ALL v4.0.0 analyses |
943
+
944
+ ---
945
+
946
+ ## Programmatic API
947
+
948
+ ```typescript
949
+ import {
950
+ Orchestrator,
951
+ // v5.1.1 — Hyper-Cognitive modules
952
+ LSPServer,
953
+ FineTuningEngine,
954
+ SmartCache,
955
+ IntentEngine,
956
+ CodeDNA,
957
+ TemporalIntelligence,
958
+ // v5.0.1 — Zero-Config modules
959
+ AutoSetup,
960
+ PluginSystem,
961
+ BrainPortability,
962
+ // v5.0.0 — Infinite Intelligence modules
963
+ HierarchicalMemory,
964
+ ContextRecall,
965
+ ConsensusEngine,
966
+ CollectiveLearning,
967
+ // v4.0.0 — Hyper-Intelligence modules
968
+ TurboMemory,
969
+ SSSPRouter,
970
+ SelfEvolution,
971
+ CrossAgentProtocol,
972
+ AdversarialDefense,
973
+ SwarmIntelligence,
974
+ KnowledgeGraph,
975
+ PredictiveEngine,
976
+ NeuralMesh,
977
+ } from '@theihtisham/agent-shadow-brain';
978
+
979
+ // v5.1.1 — Built-in LSP server
980
+ const lsp = new LSPServer('./my-project');
981
+ lsp.start({ mode: 'tcp', port: 2087 }); // or { mode: 'stdio' }
982
+
983
+ // v5.1.1 — Smart Cache
984
+ const cache = new SmartCache({ maxHotEntries: 200, enablePrefetch: true });
985
+ cache.set('analysis:auth', analysisResult, { ttl: 300_000, tags: ['security'] });
986
+ const cached = cache.get('analysis:auth');
987
+
988
+ // v5.1.1 — Temporal Intelligence
989
+ const temporal = new TemporalIntelligence('./my-project');
990
+ temporal.recordCommit(['src/auth.ts'], 'fix: JWT rotation');
991
+ const velocity = temporal.getVelocity(); // { daily, weekly, trend: 'accelerating' }
992
+ const bugRisks = temporal.predictBugs(10);
993
+
994
+ // v5.1.1 — Code DNA
995
+ const dna = new CodeDNA('./my-project');
996
+ const profile = await dna.analyze('src/auth.ts');
997
+ const similar = await dna.findSimilar('src/auth.ts', 5);
998
+
999
+ // v5.0.1 — Zero-config auto-setup
1000
+ const setup = new AutoSetup('./my-project');
1001
+ const config = await setup.detect();
1002
+ // → { projectType: 'fullstack', languages: ['typescript','python'], frameworks: ['next.js'], aiTools: [...] }
1003
+ await setup.installMCPForTools(['Claude Code', 'Cursor']);
1004
+ await setup.installGitHooks();
1005
+
1006
+ // Create the brain
1007
+ const brain = new Orchestrator({
1008
+ provider: 'anthropic',
1009
+ projectDir: './my-project',
1010
+ agents: ['claude-code', 'cursor', 'cline'],
1011
+ watchMode: true,
1012
+ autoInject: true,
1013
+ brainPersonality: 'balanced',
1014
+ });
1015
+
1016
+ // v5.0.1 — Plugin system
1017
+ const plugins = new PluginSystem('./my-project');
1018
+ await plugins.loadAll();
1019
+ await plugins.preAnalysis({ files: ['src/auth.ts'], projectDir: './my-project' });
1020
+
1021
+ // v5.0.1 — Brain portability
1022
+ const porter = new BrainPortability('./my-project');
1023
+ const { filePath, sizeBytes, checksum } = await porter.exportBrain();
1024
+
1025
+ // v5.0.0 — Infinite Intelligence
1026
+ const hmem = new HierarchicalMemory();
1027
+ await hmem.store('JWT rotation pattern: rotate every 24h with refresh tokens', 'security', 0.9);
1028
+ const results = hmem.search('jwt');
1029
+
1030
+ const recall = new ContextRecall(hmem);
1031
+ const activated = recall.recall({
1032
+ currentFile: 'src/auth/login.ts',
1033
+ currentCategory: 'security',
1034
+ recentEdits: ['src/auth/login.ts', 'src/middleware/auth.ts'],
1035
+ projectType: 'node',
1036
+ keywords: ['jwt', 'authentication', 'session'],
1037
+ });
1038
+
1039
+ const consensus = new ConsensusEngine('my-agent');
1040
+ const proposalId = consensus.propose('Use bcrypt cost factor 12', 'security', 0.95);
1041
+
1042
+ // Start everything
1043
+ await brain.start();
1044
+ ```
1045
+
1046
+ ---
1047
+
1048
+ ## Health Score System
1049
+
1050
+ | Dimension | Weight | Checks |
1051
+ |---|---|---|
1052
+ | Security | 25% | Vulnerabilities, secrets, exposed keys |
1053
+ | Quality | 25% | Code smells, anti-patterns, complexity |
1054
+ | Performance | 15% | N+1 queries, memory leaks, blocking ops |
1055
+ | Architecture | 15% | Coupling, cohesion, dependencies |
1056
+ | Maintainability | 10% | Duplication, file sizes, comments |
1057
+ | Test Coverage | 10% | Test presence, assertion quality |
1058
+
1059
+ ---
1060
+
1061
+ ## Version History
1062
+
1063
+ > **Full changelogs, migration guides, and detailed release notes:** [`docs/versions/`](docs/versions/)
1064
+ >
1065
+ > **Compact changelog:** [`CHANGELOG.md`](CHANGELOG.md)
1066
+
1067
+ | Version | Codename | Date | Highlights |
1068
+ |---|---|---|---|
1069
+ | **[v5.1.1](docs/versions/v5.1.1.md)** | Hyper-Cognitive | 2026-04-18 | LSP Server, Fine-Tuning Engine, Smart Cache, Intent Engine, Code DNA, Temporal Intelligence |
1070
+ | **[v5.0.1](docs/versions/v5.0.1.md)** | Zero-Config | 2026-04-15 | Auto-Setup, MCP Server (19 tools), Dashboard, NLP Queries, Plugin System |
1071
+ | **[v5.0.0](docs/versions/v5.0.0.md)** | Infinite Intelligence | 2026-04-12 | Hierarchical Memory, Associative Recall, Multi-Agent Consensus, Collective Learning |
1072
+ | **[v4.0.0](docs/versions/v4.0.0.md)** | Hyper-Intelligence | 2026-04-08 | TurboQuant, SSSP Routing, Self-Evolution, CAIP, Adversarial Defense, Swarm, Knowledge Graph |
1073
+ | **[v3.0.0](docs/versions/v3.0.0.md)** | Hyper-Intelligence | 2026-04-01 | Cognitive Load Analysis, Security Audit Engine, Influence Map |
1074
+ | **[v2.1.0](docs/versions/v2.1.0.md)** | Quantum Neural Mesh | 2026-03-25 | Shannon Entropy, Cosine Similarity, Bayesian Confidence |
1075
+ | **[v2.0.0](docs/versions/v2.0.0.md)** | Super-Intelligence | 2026-03-18 | Semantic Analyzer, Dependency Graph, Code Similarity, MCP Server |
1076
+ | **[v1.0.0](docs/versions/v1.0.0.md)** | Foundation | 2026-02-28 | 7 Agent Adapters, Health Scoring, Smart Fixes, Vulnerability Scanning |
1077
+
1078
+ ---
1079
+
1080
+ ## Supported Agents & Tools
1081
+
1082
+ | Agent | Status | MCP Support | Injection Target |
1083
+ |---|---|---|---|
1084
+ | [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | Full Support | Auto-install | `CLAUDE.md`, `.claude/` |
1085
+ | [Cursor](https://cursor.sh/) | Full Support | Auto-install | `.cursor/mcp.json` |
1086
+ | [Kilo Code](https://kilocode.ai/) | Full Support | Auto-install | `.kilocode/rules.md` |
1087
+ | [Cline](https://github.com/cline/cline) | Full Support | Auto-install | `.clinerules` |
1088
+ | [OpenCode](https://github.com/opencode-ai/opencode) | Full Support | Yes | `AGENT.md` |
1089
+ | [Codex](https://github.com/openai/codex) | Full Support | Yes | `AGENTS.md` |
1090
+ | [Roo Code](https://roocode.com/) | Full Support | Yes | `.roo/rules.md` |
1091
+ | [Aider](https://aider.chat/) | Full Support | Yes | `.aider.conf.yml` |
1092
+ | [Windsurf](https://codeium.com/windsurf) | Detection | Yes | `.windsurfrules` |
1093
+
1094
+ ---
1095
+
1096
+ ## Development
1097
+
1098
+ ```bash
1099
+ git clone https://github.com/theihtisham/agent-shadow-brain.git
1100
+ cd agent-shadow-brain
1101
+ npm install
1102
+ npm run build
1103
+ npm test
1104
+ ```
1105
+
1106
+ ---
1107
+
1108
+ ## Roadmap
1109
+
1110
+ - [x] ~~MCP Server, multi-project, team mode~~ (v2.0)
1111
+ - [x] ~~Cross-session neural mesh~~ (v2.1)
1112
+ - [x] ~~TurboQuant infinite memory~~ (v4.0)
1113
+ - [x] ~~SSSP quantum routing~~ (v4.0)
1114
+ - [x] ~~Self-evolving rules~~ (v4.0)
1115
+ - [x] ~~Cross-agent protocol~~ (v4.0)
1116
+ - [x] ~~Adversarial hallucination defense~~ (v4.0)
1117
+ - [x] ~~Hierarchical memory compression~~ (v5.0)
1118
+ - [x] ~~Context-triggered associative recall~~ (v5.0)
1119
+ - [x] ~~Multi-agent consensus protocol~~ (v5.0)
1120
+ - [x] ~~Collective cross-project learning~~ (v5.0)
1121
+ - [x] ~~Zero-config auto-setup~~ (v5.0.1)
1122
+ - [x] ~~MCP server for Cursor + all tools~~ (v5.0.1)
1123
+ - [x] ~~Rich web dashboard with real-time WebSocket~~ (v5.0.1)
1124
+ - [x] ~~Plugin system + brain export/import~~ (v5.0.1)
1125
+ - [x] ~~Custom LLM fine-tuning~~ (v5.1.1)
1126
+ - [x] ~~Language server (LSP)~~ (v5.1.1)
1127
+ - [x] ~~Web dashboard v3~~ (v5.1.1)
1128
+ - [ ] **Visual Studio Code integration** — inline insight overlays
1129
+ - [ ] **Multi-model orchestration** — route insights through multiple LLMs
1130
+ - [ ] **Real-time collaboration** — team brain with live cursors
1131
+
1132
+ ---
1133
+
1134
+ ## License
1135
+
1136
+ MIT License — see [LICENSE](LICENSE) for details.
1137
+
1138
+ ---
1139
+
1140
+ ## Author
1141
+
1142
+ **theihtisham**
1143
+
1144
+ [![GitHub](https://img.shields.io/badge/GitHub-theihtisham-181717?style=flat-square&logo=github)](https://github.com/theihtisham)
1145
+ [![npm](https://img.shields.io/badge/npm-@theihtisham-CB3837?style=flat-square&logo=npm)](https://www.npmjs.com/~theihtisham)
1146
+
1147
+ ---
1148
+
1149
+ <div align="center">
1150
+
1151
+ ### If Shadow Brain makes your AI agents smarter, give it a star
1152
+
1153
+ [![Star History Chart](https://api.star-history.com/svg?repos=theihtisham/agent-shadow-brain&type=Date)](https://star-history.com/#theihtisham/agent-shadow-brain&Date)
1154
+
1155
+ **Built with brains by [theihtisham](https://github.com/theihtisham)**
1156
+
1157
+ **Topics:** `ai` `artificial-intelligence` `llm` `claude-code` `cursor` `cline` `kilo-code` `codex` `roo-code` `aider` `opencode` `windsurf` `code-review` `static-analysis` `developer-tools` `npm-package` `typescript` `ollama` `openai` `anthropic` `code-quality` `security-scanner` `health-score` `smart-fix` `vulnerability-scanner` `pattern-learning` `agent-tools` `ai-agent` `code-metrics` `pre-commit-hook` `github-actions` `developer-productivity` `neural-mesh` `quantum-computing` `shannon-entropy` `bayesian-inference` `mcp-server` `model-context-protocol` `semantic-analysis` `dependency-graph` `turboquant` `sssp-algorithm` `genetic-algorithm` `swarm-intelligence` `pagerank` `knowledge-graph` `hallucination-detection` `cross-agent` `self-evolving` `predictive-engine` `ant-colony` `infinite-memory` `vector-compression` `iclr-2026` `arxiv` `super-intelligence` `hyper-intelligence` `autonomous-agents` `ai-engineering` `agentic-coding` `vibe-coding` `cursor-ai` `zero-config` `auto-setup` `dashboard` `plugin-system` `brain-export` `natural-language` `real-time` `websocket` `team-collaboration` `ci-cd` `open-source` `trending` `hierarchical-memory` `context-recall` `consensus-engine` `collective-learning` `infinite-intelligence` `coding-assistant` `lsp-server` `language-server-protocol` `fine-tuning` `smart-cache` `intent-engine` `code-dna` `temporal-intelligence` `hyper-cognitive`
1158
+
1159
+ </div>