@theihtisham/agent-shadow-brain 5.0.0 → 5.1.1

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 (61) hide show
  1. package/README.md +575 -292
  2. package/dist/adapters/index.d.ts.map +1 -1
  3. package/dist/adapters/index.js +1 -0
  4. package/dist/adapters/index.js.map +1 -1
  5. package/dist/brain/auto-setup.d.ts +54 -0
  6. package/dist/brain/auto-setup.d.ts.map +1 -0
  7. package/dist/brain/auto-setup.js +660 -0
  8. package/dist/brain/auto-setup.js.map +1 -0
  9. package/dist/brain/brain-portability.d.ts +81 -0
  10. package/dist/brain/brain-portability.d.ts.map +1 -0
  11. package/dist/brain/brain-portability.js +329 -0
  12. package/dist/brain/brain-portability.js.map +1 -0
  13. package/dist/brain/code-dna.d.ts +70 -0
  14. package/dist/brain/code-dna.d.ts.map +1 -0
  15. package/dist/brain/code-dna.js +611 -0
  16. package/dist/brain/code-dna.js.map +1 -0
  17. package/dist/brain/fine-tuning-engine.d.ts +99 -0
  18. package/dist/brain/fine-tuning-engine.d.ts.map +1 -0
  19. package/dist/brain/fine-tuning-engine.js +681 -0
  20. package/dist/brain/fine-tuning-engine.js.map +1 -0
  21. package/dist/brain/intent-engine.d.ts +64 -0
  22. package/dist/brain/intent-engine.d.ts.map +1 -0
  23. package/dist/brain/intent-engine.js +374 -0
  24. package/dist/brain/intent-engine.js.map +1 -0
  25. package/dist/brain/lsp-server.d.ts +62 -0
  26. package/dist/brain/lsp-server.d.ts.map +1 -0
  27. package/dist/brain/lsp-server.js +480 -0
  28. package/dist/brain/lsp-server.js.map +1 -0
  29. package/dist/brain/mcp-server.d.ts +12 -0
  30. package/dist/brain/mcp-server.d.ts.map +1 -1
  31. package/dist/brain/mcp-server.js +396 -37
  32. package/dist/brain/mcp-server.js.map +1 -1
  33. package/dist/brain/orchestrator.d.ts +13 -0
  34. package/dist/brain/orchestrator.d.ts.map +1 -1
  35. package/dist/brain/orchestrator.js +25 -1
  36. package/dist/brain/orchestrator.js.map +1 -1
  37. package/dist/brain/plugin-system.d.ts +97 -0
  38. package/dist/brain/plugin-system.d.ts.map +1 -0
  39. package/dist/brain/plugin-system.js +404 -0
  40. package/dist/brain/plugin-system.js.map +1 -0
  41. package/dist/brain/smart-cache.d.ts +100 -0
  42. package/dist/brain/smart-cache.d.ts.map +1 -0
  43. package/dist/brain/smart-cache.js +417 -0
  44. package/dist/brain/smart-cache.js.map +1 -0
  45. package/dist/brain/temporal-intelligence.d.ts +89 -0
  46. package/dist/brain/temporal-intelligence.d.ts.map +1 -0
  47. package/dist/brain/temporal-intelligence.js +378 -0
  48. package/dist/brain/temporal-intelligence.js.map +1 -0
  49. package/dist/cli.js +444 -3
  50. package/dist/cli.js.map +1 -1
  51. package/dist/dashboard/server.d.ts +4 -0
  52. package/dist/dashboard/server.d.ts.map +1 -1
  53. package/dist/dashboard/server.js +453 -330
  54. package/dist/dashboard/server.js.map +1 -1
  55. package/dist/index.d.ts +11 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +12 -1
  58. package/dist/index.js.map +1 -1
  59. package/dist/types.d.ts +284 -1
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +28 -4
@@ -1,5 +1,6 @@
1
1
  // src/brain/mcp-server.ts — JSON-RPC 2.0 MCP server over HTTP
2
2
  // Exposes analysis tools via Model Context Protocol
3
+ // v5.0.1 — Infinite Intelligence Edition (Cursor + Claude Code + Kilo Code compatible)
3
4
  import * as http from 'http';
4
5
  export class MCPServer {
5
6
  constructor(orchestrator, options) {
@@ -19,6 +20,18 @@ export class MCPServer {
19
20
  semantic: this.handleSemantic.bind(this),
20
21
  deps: this.handleDeps.bind(this),
21
22
  learn: this.handleLearn.bind(this),
23
+ memory: this.handleMemory.bind(this),
24
+ recall: this.handleRecall.bind(this),
25
+ consensus: this.handleConsensus.bind(this),
26
+ turbo: this.handleTurbo.bind(this),
27
+ swarm: this.handleSwarm.bind(this),
28
+ evolution: this.handleEvolution.bind(this),
29
+ knowledge_graph: this.handleKnowledgeGraph.bind(this),
30
+ predict: this.handlePredict.bind(this),
31
+ ask: this.handleAsk.bind(this),
32
+ status: this.handleStatus.bind(this),
33
+ modules: this.handleModules.bind(this),
34
+ auto_config: this.handleAutoConfig.bind(this),
22
35
  };
23
36
  }
24
37
  async start() {
@@ -28,27 +41,44 @@ export class MCPServer {
28
41
  return;
29
42
  }
30
43
  const url = new URL(req.url, `http://${req.headers.host}`);
31
- // CORS headers
44
+ // CORS headers — permissive for Cursor, Claude Code, and other AI tools
32
45
  res.setHeader('Access-Control-Allow-Origin', '*');
33
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
34
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
46
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE');
47
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Accept');
48
+ res.setHeader('Access-Control-Max-Age', '86400');
35
49
  if (req.method === 'OPTIONS') {
36
50
  res.writeHead(204);
37
51
  res.end();
38
52
  return;
39
53
  }
40
- if (req.method === 'POST' && url.pathname === '/mcp') {
54
+ if (req.method === 'POST' && (url.pathname === '/mcp' || url.pathname === '/')) {
41
55
  await this.handleHTTPMCPRequest(req, res);
42
56
  }
43
57
  else if (req.method === 'GET' && url.pathname === '/sse') {
44
58
  this.handleSSEConnection(req, res);
45
59
  }
60
+ else if (req.method === 'GET' && url.pathname === '/health') {
61
+ // Lightweight health endpoint for tool connectivity checks
62
+ this.sendJSON(res, 200, {
63
+ status: 'ok',
64
+ version: '5.0.1',
65
+ uptime: process.uptime(),
66
+ tools: Object.keys(this.toolHandlers).length,
67
+ });
68
+ }
69
+ else if (req.method === 'POST' && url.pathname === '/v1/chat') {
70
+ // Cursor compatibility — some versions POST to /v1/chat
71
+ await this.handleHTTPMCPRequest(req, res);
72
+ }
46
73
  else {
47
74
  this.sendJSON(res, 404, {
48
75
  error: 'Not found',
49
76
  endpoints: {
50
77
  'POST /mcp': 'JSON-RPC 2.0 MCP handler',
78
+ 'POST /': 'JSON-RPC 2.0 MCP handler (root path for Cursor)',
79
+ 'POST /v1/chat': 'Cursor compatibility endpoint',
51
80
  'GET /sse': 'Server-Sent Events for real-time updates',
81
+ 'GET /health': 'Health check endpoint',
52
82
  },
53
83
  });
54
84
  }
@@ -62,7 +92,6 @@ export class MCPServer {
62
92
  });
63
93
  }
64
94
  async stop() {
65
- // Close all SSE clients
66
95
  for (const [id, client] of this.sseClients) {
67
96
  try {
68
97
  client.res.write('event: close\ndata: {"reason":"server shutting down"}\n\n');
@@ -86,7 +115,6 @@ export class MCPServer {
86
115
  }
87
116
  }
88
117
  async handleRequest(request) {
89
- // Validate JSON-RPC version
90
118
  if (request.jsonrpc !== '2.0') {
91
119
  return this.makeError(request.id, -32600, 'Invalid Request: jsonrpc must be "2.0"');
92
120
  }
@@ -95,6 +123,9 @@ export class MCPServer {
95
123
  switch (method) {
96
124
  case 'initialize':
97
125
  return this.makeResult(request.id, this.handleInitialize());
126
+ case 'notifications/initialized':
127
+ // Cursor sends this after initialize — acknowledge silently
128
+ return this.makeResult(request.id, {});
98
129
  case 'tools/list':
99
130
  return this.makeResult(request.id, { tools: this.getToolDefinitions() });
100
131
  case 'resources/list':
@@ -130,10 +161,12 @@ export class MCPServer {
130
161
  tools: { listChanged: false },
131
162
  resources: { subscribe: false, listChanged: false },
132
163
  prompts: { listChanged: false },
164
+ logging: {},
133
165
  },
134
166
  serverInfo: {
135
167
  name: 'agent-shadow-brain',
136
- version: '2.0.0',
168
+ version: '5.0.1',
169
+ description: 'World\'s #1 AI coding intelligence layer — infinite memory, multi-agent consensus, self-evolving',
137
170
  },
138
171
  };
139
172
  }
@@ -155,7 +188,6 @@ export class MCPServer {
155
188
  async handleHealth(params) {
156
189
  const healthScore = await this.orchestrator.getHealthScore();
157
190
  const currentScore = healthScore.overall;
158
- // Broadcast health change via SSE if score changed significantly
159
191
  if (this.lastHealthScore !== null && Math.abs(currentScore - this.lastHealthScore) >= 5) {
160
192
  this.broadcastSSE('health-change', {
161
193
  previous: this.lastHealthScore,
@@ -206,7 +238,6 @@ export class MCPServer {
206
238
  async handleSemantic(params) {
207
239
  const maxFiles = params.maxFiles ?? 100;
208
240
  const result = await this.orchestrator.getSemanticInsights(maxFiles);
209
- // Convert Map to serializable object
210
241
  const symbolsObj = {};
211
242
  if (result.symbols instanceof Map) {
212
243
  for (const [file, syms] of result.symbols) {
@@ -242,6 +273,238 @@ export class MCPServer {
242
273
  lessons: lessons,
243
274
  };
244
275
  }
276
+ async handleMemory(params) {
277
+ const action = params.action ?? 'stats';
278
+ const hm = this.orchestrator.hierarchicalMemory;
279
+ if (!hm)
280
+ return { error: 'Hierarchical memory not initialized' };
281
+ switch (action) {
282
+ case 'stats':
283
+ return hm.getStats?.() || { entries: 0 };
284
+ case 'store': {
285
+ const { content, category, importance } = params;
286
+ const id = hm.store?.(content, category, importance ?? 0.5);
287
+ return { id, stored: true };
288
+ }
289
+ case 'retrieve': {
290
+ const { tier, limit } = params;
291
+ const entries = hm.getByTier?.(tier) || [];
292
+ return { entries: entries.slice(0, limit ?? 50) };
293
+ }
294
+ case 'search': {
295
+ const { query, topK } = params;
296
+ // Use context recall for semantic search
297
+ const cr = this.orchestrator.contextRecall;
298
+ if (cr) {
299
+ const results = cr.recall({ keywords: query.split(' ') }, topK ?? 10);
300
+ return { results };
301
+ }
302
+ return { results: [] };
303
+ }
304
+ default:
305
+ return { error: `Unknown memory action: ${action}` };
306
+ }
307
+ }
308
+ async handleRecall(params) {
309
+ const context = {
310
+ currentFile: params.file,
311
+ currentCategory: params.category,
312
+ projectType: params.projectType,
313
+ keywords: params.keywords || [],
314
+ };
315
+ const cr = this.orchestrator.contextRecall;
316
+ if (!cr)
317
+ return { results: [], error: 'Context recall not initialized' };
318
+ const results = cr.recall(context, params.topK ?? 20);
319
+ return {
320
+ count: results.length,
321
+ results: results.map((r) => ({
322
+ content: r.entry?.content?.slice(0, 200),
323
+ relevanceScore: r.relevanceScore,
324
+ triggers: r.activatedTriggers?.slice(0, 5),
325
+ })),
326
+ };
327
+ }
328
+ async handleConsensus(params) {
329
+ const ce = this.orchestrator.consensusEngine;
330
+ if (!ce)
331
+ return { error: 'Consensus engine not initialized' };
332
+ const action = params.action ?? 'stats';
333
+ switch (action) {
334
+ case 'stats':
335
+ return ce.getStats?.() || {};
336
+ case 'propose': {
337
+ const id = ce.propose?.(params.content, params.category, params.confidence ?? 0.5, params.evidence || []);
338
+ return { proposalId: id };
339
+ }
340
+ case 'trust':
341
+ return ce.getTrustScores?.() || [];
342
+ default:
343
+ return { error: `Unknown consensus action: ${action}` };
344
+ }
345
+ }
346
+ async handleTurbo(params) {
347
+ const tm = this.orchestrator.turboMemory;
348
+ if (!tm)
349
+ return { error: 'TurboMemory not initialized' };
350
+ const action = params.action ?? 'stats';
351
+ switch (action) {
352
+ case 'stats':
353
+ return tm.stats?.() || {};
354
+ case 'search': {
355
+ const results = tm.search?.(params.query, params.topK ?? 10);
356
+ return { results: results || [] };
357
+ }
358
+ default:
359
+ return { error: `Unknown turbo action: ${action}` };
360
+ }
361
+ }
362
+ async handleSwarm(params) {
363
+ const si = this.orchestrator.swarmIntelligence;
364
+ if (!si)
365
+ return { error: 'Swarm intelligence not initialized' };
366
+ const action = params.action ?? 'state';
367
+ switch (action) {
368
+ case 'state':
369
+ return si.getState?.() || {};
370
+ case 'priorities': {
371
+ const files = si.getHighPriorityFiles?.(params.count ?? 10);
372
+ return { files: files || [] };
373
+ }
374
+ default:
375
+ return { error: `Unknown swarm action: ${action}` };
376
+ }
377
+ }
378
+ async handleEvolution(params) {
379
+ const se = this.orchestrator.selfEvolution;
380
+ if (!se)
381
+ return { error: 'Self-evolution not initialized' };
382
+ const action = params.action ?? 'snapshot';
383
+ switch (action) {
384
+ case 'snapshot':
385
+ return se.getSnapshot?.() || {};
386
+ case 'best_rules': {
387
+ const rules = se.getBestRules?.(params.category ?? 'all', params.count ?? 10);
388
+ return { rules: rules || [] };
389
+ }
390
+ default:
391
+ return { error: `Unknown evolution action: ${action}` };
392
+ }
393
+ }
394
+ async handleKnowledgeGraph(params) {
395
+ const kg = this.orchestrator.knowledgeGraph;
396
+ if (!kg)
397
+ return { error: 'Knowledge graph not initialized' };
398
+ const action = params.action ?? 'stats';
399
+ switch (action) {
400
+ case 'stats':
401
+ return kg.getStats?.() || {};
402
+ case 'top_entities': {
403
+ const entities = kg.getTopEntities?.(params.count ?? 20);
404
+ return { entities: entities || [] };
405
+ }
406
+ default:
407
+ return { error: `Unknown knowledge graph action: ${action}` };
408
+ }
409
+ }
410
+ async handlePredict(params) {
411
+ const pe = this.orchestrator.predictiveEngine;
412
+ if (!pe)
413
+ return { error: 'Predictive engine not initialized' };
414
+ return {
415
+ predictionAvailable: true,
416
+ note: 'Use the predict CLI command for full bug/debt risk scoring',
417
+ };
418
+ }
419
+ async handleAsk(params) {
420
+ const query = params.query;
421
+ if (!query)
422
+ return { error: 'Missing query parameter' };
423
+ // Natural language query — combine recall + search
424
+ const keywords = query.toLowerCase().split(/\s+/).filter(w => w.length > 2);
425
+ const results = [];
426
+ // Context recall
427
+ const cr = this.orchestrator.contextRecall;
428
+ if (cr) {
429
+ const recallResults = cr.recall({ keywords }, 10);
430
+ for (const r of recallResults.slice(0, 5)) {
431
+ results.push({
432
+ source: 'memory',
433
+ content: r.entry?.content?.slice(0, 300),
434
+ relevance: r.relevanceScore,
435
+ });
436
+ }
437
+ }
438
+ // Pattern memory
439
+ const pm = this.orchestrator.patternMemory;
440
+ if (pm) {
441
+ const patterns = pm.getPatternInsights?.(keywords.join(' '));
442
+ if (patterns) {
443
+ for (const p of patterns.slice(0, 3)) {
444
+ results.push({ source: 'pattern', content: p });
445
+ }
446
+ }
447
+ }
448
+ return {
449
+ query,
450
+ resultCount: results.length,
451
+ results,
452
+ };
453
+ }
454
+ async handleStatus(params) {
455
+ const status = this.orchestrator.getStatus?.() || {};
456
+ return {
457
+ version: '5.0.1',
458
+ ...status,
459
+ };
460
+ }
461
+ async handleModules(params) {
462
+ const status = this.orchestrator.getStatus?.() || {};
463
+ const modules = [];
464
+ const moduleList = [
465
+ { key: 'hierarchicalMemory', name: 'Hierarchical Memory' },
466
+ { key: 'patternMemory', name: 'Pattern Memory' },
467
+ { key: 'learningEngine', name: 'Learning Engine' },
468
+ { key: 'neuralMesh', name: 'Neural Mesh' },
469
+ { key: 'consensusEngine', name: 'Consensus Engine' },
470
+ { key: 'contextRecall', name: 'Context Recall' },
471
+ { key: 'turboMemory', name: 'TurboMemory' },
472
+ { key: 'ssspRouter', name: 'SSSP Router' },
473
+ { key: 'selfEvolution', name: 'Self Evolution' },
474
+ { key: 'predictiveEngine', name: 'Predictive Engine' },
475
+ { key: 'knowledgeGraph', name: 'Knowledge Graph' },
476
+ { key: 'swarmIntelligence', name: 'Swarm Intelligence' },
477
+ { key: 'adversarialDefense', name: 'Adversarial Defense' },
478
+ ];
479
+ for (const mod of moduleList) {
480
+ const instance = this.orchestrator[mod.key];
481
+ modules.push({
482
+ name: mod.name,
483
+ version: '5.0.1',
484
+ status: instance ? 'active' : 'idle',
485
+ });
486
+ }
487
+ return { modules, totalModules: modules.length, activeModules: modules.filter(m => m.status === 'active').length };
488
+ }
489
+ async handleAutoConfig(params) {
490
+ // Trigger auto-detection — useful for MCP tools to discover project info
491
+ try {
492
+ const { AutoSetup } = await import('./auto-setup.js');
493
+ const setup = new AutoSetup(this.orchestrator.config?.projectDir || process.cwd());
494
+ const result = await setup.detect();
495
+ return {
496
+ project: result.projectName,
497
+ type: result.projectType,
498
+ languages: result.languages,
499
+ frameworks: result.frameworks,
500
+ aiTools: result.aiTools.filter(t => t.detected).map(t => t.name),
501
+ packageManager: result.packageManager,
502
+ };
503
+ }
504
+ catch {
505
+ return { error: 'Auto-setup module not available' };
506
+ }
507
+ }
245
508
  // ── Tool Definitions ───────────────────────────────────────────────────
246
509
  getToolDefinitions() {
247
510
  return [
@@ -251,66 +514,165 @@ export class MCPServer {
251
514
  inputSchema: {
252
515
  type: 'object',
253
516
  properties: {
254
- maxFiles: {
255
- type: 'number',
256
- description: 'Maximum number of insights to return (default: 50)',
257
- },
517
+ maxFiles: { type: 'number', description: 'Maximum number of insights to return (default: 50)' },
258
518
  },
259
519
  },
260
520
  },
261
521
  {
262
522
  name: 'health',
263
523
  description: 'Get the current project health score with detailed breakdown',
524
+ inputSchema: { type: 'object', properties: {} },
525
+ },
526
+ {
527
+ name: 'fixes',
528
+ description: 'Get smart fix suggestions for current code issues',
529
+ inputSchema: { type: 'object', properties: {} },
530
+ },
531
+ {
532
+ name: 'metrics',
533
+ description: 'Get code metrics: LOC, complexity, language breakdown',
534
+ inputSchema: { type: 'object', properties: {} },
535
+ },
536
+ {
537
+ name: 'semantic',
538
+ description: 'Get semantic analysis: symbols, unused exports, dead code',
264
539
  inputSchema: {
265
540
  type: 'object',
266
- properties: {},
541
+ properties: {
542
+ maxFiles: { type: 'number', description: 'Maximum files to analyze (default: 100)' },
543
+ },
267
544
  },
268
545
  },
269
546
  {
270
- name: 'fixes',
271
- description: 'Get smart fix suggestions for current code issues',
547
+ name: 'deps',
548
+ description: 'Get dependency graph: imports, cycles, orphans, hubs',
549
+ inputSchema: { type: 'object', properties: {} },
550
+ },
551
+ {
552
+ name: 'learn',
553
+ description: 'Run a learning cycle to extract patterns and lessons from the project',
554
+ inputSchema: { type: 'object', properties: {} },
555
+ },
556
+ {
557
+ name: 'memory',
558
+ description: 'Manage infinite hierarchical memory — store, retrieve, search, stats',
272
559
  inputSchema: {
273
560
  type: 'object',
274
- properties: {},
561
+ properties: {
562
+ action: { type: 'string', enum: ['stats', 'store', 'retrieve', 'search'], description: 'Action to perform (default: stats)' },
563
+ content: { type: 'string', description: 'Content to store (for store action)' },
564
+ category: { type: 'string', description: 'Category for storage/retrieval' },
565
+ importance: { type: 'number', description: 'Importance 0-1 (for store action)' },
566
+ tier: { type: 'string', enum: ['raw', 'summary', 'pattern', 'principle'], description: 'Memory tier to retrieve' },
567
+ query: { type: 'string', description: 'Search query (for search action)' },
568
+ topK: { type: 'number', description: 'Max results to return' },
569
+ },
275
570
  },
276
571
  },
277
572
  {
278
- name: 'metrics',
279
- description: 'Get code metrics: LOC, complexity, language breakdown',
573
+ name: 'recall',
574
+ description: 'Context-triggered associative recall — activate memories based on current work context',
280
575
  inputSchema: {
281
576
  type: 'object',
282
- properties: {},
577
+ properties: {
578
+ file: { type: 'string', description: 'Current file being edited' },
579
+ category: { type: 'string', description: 'Current work category' },
580
+ projectType: { type: 'string', description: 'Project type' },
581
+ keywords: { type: 'array', items: { type: 'string' }, description: 'Keywords from current context' },
582
+ topK: { type: 'number', description: 'Max results (default: 20)' },
583
+ },
283
584
  },
284
585
  },
285
586
  {
286
- name: 'semantic',
287
- description: 'Get semantic analysis: symbols, unused exports, dead code',
587
+ name: 'consensus',
588
+ description: 'Multi-agent consensus protocol — propose, vote, trust scores',
288
589
  inputSchema: {
289
590
  type: 'object',
290
591
  properties: {
291
- maxFiles: {
292
- type: 'number',
293
- description: 'Maximum files to analyze (default: 100)',
294
- },
592
+ action: { type: 'string', enum: ['stats', 'propose', 'trust'], description: 'Action (default: stats)' },
593
+ content: { type: 'string', description: 'Proposal content (for propose action)' },
594
+ category: { type: 'string', description: 'Proposal category' },
595
+ confidence: { type: 'number', description: 'Confidence 0-1' },
295
596
  },
296
597
  },
297
598
  },
298
599
  {
299
- name: 'deps',
300
- description: 'Get dependency graph: imports, cycles, orphans, hubs',
600
+ name: 'turbo',
601
+ description: 'TurboQuant 6x compressed vector memory — stats and semantic search',
301
602
  inputSchema: {
302
603
  type: 'object',
303
- properties: {},
604
+ properties: {
605
+ action: { type: 'string', enum: ['stats', 'search'], description: 'Action (default: stats)' },
606
+ query: { type: 'string', description: 'Search query' },
607
+ topK: { type: 'number', description: 'Max results' },
608
+ },
304
609
  },
305
610
  },
306
611
  {
307
- name: 'learn',
308
- description: 'Run a learning cycle to extract patterns and lessons from the project',
612
+ name: 'swarm',
613
+ description: 'Swarm intelligence (Ant Colony) — file prioritization via pheromone trails',
309
614
  inputSchema: {
310
615
  type: 'object',
311
- properties: {},
616
+ properties: {
617
+ action: { type: 'string', enum: ['state', 'priorities'], description: 'Action (default: state)' },
618
+ count: { type: 'number', description: 'Number of priority files (default: 10)' },
619
+ },
620
+ },
621
+ },
622
+ {
623
+ name: 'evolution',
624
+ description: 'Self-evolving genetic rules — view evolution snapshot and best rules',
625
+ inputSchema: {
626
+ type: 'object',
627
+ properties: {
628
+ action: { type: 'string', enum: ['snapshot', 'best_rules'], description: 'Action (default: snapshot)' },
629
+ category: { type: 'string', description: 'Category for best rules' },
630
+ count: { type: 'number', description: 'Number of rules to return' },
631
+ },
632
+ },
633
+ },
634
+ {
635
+ name: 'knowledge_graph',
636
+ description: 'Knowledge graph with PageRank — code entity importance and relationships',
637
+ inputSchema: {
638
+ type: 'object',
639
+ properties: {
640
+ action: { type: 'string', enum: ['stats', 'top_entities'], description: 'Action (default: stats)' },
641
+ count: { type: 'number', description: 'Number of entities to return' },
642
+ },
312
643
  },
313
644
  },
645
+ {
646
+ name: 'predict',
647
+ description: 'Predictive bug forecasting — check bug risk and debt predictions',
648
+ inputSchema: { type: 'object', properties: {} },
649
+ },
650
+ {
651
+ name: 'ask',
652
+ description: 'Natural language query — ask the brain anything about the project',
653
+ inputSchema: {
654
+ type: 'object',
655
+ properties: {
656
+ query: { type: 'string', description: 'Natural language question about the project' },
657
+ },
658
+ required: ['query'],
659
+ },
660
+ },
661
+ {
662
+ name: 'status',
663
+ description: 'Get full Shadow Brain status — version, modules, health, stats',
664
+ inputSchema: { type: 'object', properties: {} },
665
+ },
666
+ {
667
+ name: 'modules',
668
+ description: 'List all brain modules with their activation status',
669
+ inputSchema: { type: 'object', properties: {} },
670
+ },
671
+ {
672
+ name: 'auto_config',
673
+ description: 'Auto-detect project configuration — languages, frameworks, AI tools',
674
+ inputSchema: { type: 'object', properties: {} },
675
+ },
314
676
  ];
315
677
  }
316
678
  // ── HTTP Handling ──────────────────────────────────────────────────────
@@ -328,7 +690,6 @@ export class MCPServer {
328
690
  });
329
691
  return;
330
692
  }
331
- // Support batch requests
332
693
  if (Array.isArray(parsed)) {
333
694
  const results = await Promise.all(parsed.map((r) => this.handleRequest(r)));
334
695
  this.sendJSON(res, 200, results);
@@ -345,11 +706,9 @@ export class MCPServer {
345
706
  Connection: 'keep-alive',
346
707
  'Access-Control-Allow-Origin': '*',
347
708
  });
348
- // Send initial connection event
349
- res.write(`event: connected\ndata: {"clientId":"${clientId}"}\n\n`);
709
+ res.write(`event: connected\ndata: {"clientId":"${clientId}","version":"5.0.1"}\n\n`);
350
710
  const client = { res, id: clientId };
351
711
  this.sseClients.set(clientId, client);
352
- // Handle client disconnect
353
712
  req.on('close', () => {
354
713
  this.sseClients.delete(clientId);
355
714
  });
@@ -374,7 +733,7 @@ export class MCPServer {
374
733
  return new Promise((resolve, reject) => {
375
734
  const chunks = [];
376
735
  let size = 0;
377
- const maxSize = 10 * 1024 * 1024; // 10 MB limit
736
+ const maxSize = 10 * 1024 * 1024;
378
737
  req.on('data', (chunk) => {
379
738
  size += chunk.length;
380
739
  if (size > maxSize) {