@theihtisham/agent-shadow-brain 2.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +443 -602
  2. package/dist/brain/accessibility-checker.d.ts +10 -0
  3. package/dist/brain/accessibility-checker.d.ts.map +1 -0
  4. package/dist/brain/accessibility-checker.js +379 -0
  5. package/dist/brain/accessibility-checker.js.map +1 -0
  6. package/dist/brain/adversarial-defense.d.ts +57 -0
  7. package/dist/brain/adversarial-defense.d.ts.map +1 -0
  8. package/dist/brain/adversarial-defense.js +303 -0
  9. package/dist/brain/adversarial-defense.js.map +1 -0
  10. package/dist/brain/api-contract-analyzer.d.ts +19 -0
  11. package/dist/brain/api-contract-analyzer.d.ts.map +1 -0
  12. package/dist/brain/api-contract-analyzer.js +251 -0
  13. package/dist/brain/api-contract-analyzer.js.map +1 -0
  14. package/dist/brain/ast-analyzer.d.ts +23 -0
  15. package/dist/brain/ast-analyzer.d.ts.map +1 -0
  16. package/dist/brain/ast-analyzer.js +462 -0
  17. package/dist/brain/ast-analyzer.js.map +1 -0
  18. package/dist/brain/code-age-analyzer.d.ts +11 -0
  19. package/dist/brain/code-age-analyzer.d.ts.map +1 -0
  20. package/dist/brain/code-age-analyzer.js +152 -0
  21. package/dist/brain/code-age-analyzer.js.map +1 -0
  22. package/dist/brain/cognitive-load.d.ts +27 -0
  23. package/dist/brain/cognitive-load.d.ts.map +1 -0
  24. package/dist/brain/cognitive-load.js +304 -0
  25. package/dist/brain/cognitive-load.js.map +1 -0
  26. package/dist/brain/config-drift-detector.d.ts +13 -0
  27. package/dist/brain/config-drift-detector.d.ts.map +1 -0
  28. package/dist/brain/config-drift-detector.js +198 -0
  29. package/dist/brain/config-drift-detector.js.map +1 -0
  30. package/dist/brain/cross-agent-protocol.d.ts +48 -0
  31. package/dist/brain/cross-agent-protocol.d.ts.map +1 -0
  32. package/dist/brain/cross-agent-protocol.js +306 -0
  33. package/dist/brain/cross-agent-protocol.js.map +1 -0
  34. package/dist/brain/dead-code-eliminator.d.ts +16 -0
  35. package/dist/brain/dead-code-eliminator.d.ts.map +1 -0
  36. package/dist/brain/dead-code-eliminator.js +359 -0
  37. package/dist/brain/dead-code-eliminator.js.map +1 -0
  38. package/dist/brain/env-analyzer.d.ts +13 -0
  39. package/dist/brain/env-analyzer.d.ts.map +1 -0
  40. package/dist/brain/env-analyzer.js +277 -0
  41. package/dist/brain/env-analyzer.js.map +1 -0
  42. package/dist/brain/i18n-detector.d.ts +12 -0
  43. package/dist/brain/i18n-detector.d.ts.map +1 -0
  44. package/dist/brain/i18n-detector.js +242 -0
  45. package/dist/brain/i18n-detector.js.map +1 -0
  46. package/dist/brain/influence-map.d.ts +31 -0
  47. package/dist/brain/influence-map.d.ts.map +1 -0
  48. package/dist/brain/influence-map.js +375 -0
  49. package/dist/brain/influence-map.js.map +1 -0
  50. package/dist/brain/knowledge-graph.d.ts +56 -0
  51. package/dist/brain/knowledge-graph.d.ts.map +1 -0
  52. package/dist/brain/knowledge-graph.js +427 -0
  53. package/dist/brain/knowledge-graph.js.map +1 -0
  54. package/dist/brain/learning-engine.d.ts +11 -0
  55. package/dist/brain/learning-engine.d.ts.map +1 -1
  56. package/dist/brain/learning-engine.js +44 -1
  57. package/dist/brain/learning-engine.js.map +1 -1
  58. package/dist/brain/license-compliance.d.ts +13 -0
  59. package/dist/brain/license-compliance.d.ts.map +1 -0
  60. package/dist/brain/license-compliance.js +213 -0
  61. package/dist/brain/license-compliance.js.map +1 -0
  62. package/dist/brain/llm-client.d.ts.map +1 -1
  63. package/dist/brain/llm-client.js +3 -0
  64. package/dist/brain/llm-client.js.map +1 -1
  65. package/dist/brain/mutation-advisor.d.ts +11 -0
  66. package/dist/brain/mutation-advisor.d.ts.map +1 -0
  67. package/dist/brain/mutation-advisor.js +154 -0
  68. package/dist/brain/mutation-advisor.js.map +1 -0
  69. package/dist/brain/neural-mesh.d.ts +9 -1
  70. package/dist/brain/neural-mesh.d.ts.map +1 -1
  71. package/dist/brain/neural-mesh.js +75 -16
  72. package/dist/brain/neural-mesh.js.map +1 -1
  73. package/dist/brain/orchestrator.d.ts +71 -2
  74. package/dist/brain/orchestrator.d.ts.map +1 -1
  75. package/dist/brain/orchestrator.js +383 -3
  76. package/dist/brain/orchestrator.js.map +1 -1
  77. package/dist/brain/pattern-memory.d.ts +8 -3
  78. package/dist/brain/pattern-memory.d.ts.map +1 -1
  79. package/dist/brain/pattern-memory.js +71 -3
  80. package/dist/brain/pattern-memory.js.map +1 -1
  81. package/dist/brain/predictive-engine.d.ts +45 -0
  82. package/dist/brain/predictive-engine.d.ts.map +1 -0
  83. package/dist/brain/predictive-engine.js +238 -0
  84. package/dist/brain/predictive-engine.js.map +1 -0
  85. package/dist/brain/security-audit.d.ts +20 -0
  86. package/dist/brain/security-audit.d.ts.map +1 -0
  87. package/dist/brain/security-audit.js +340 -0
  88. package/dist/brain/security-audit.js.map +1 -0
  89. package/dist/brain/self-evolution.d.ts +53 -0
  90. package/dist/brain/self-evolution.d.ts.map +1 -0
  91. package/dist/brain/self-evolution.js +278 -0
  92. package/dist/brain/self-evolution.js.map +1 -0
  93. package/dist/brain/sssp-router.d.ts +58 -0
  94. package/dist/brain/sssp-router.d.ts.map +1 -0
  95. package/dist/brain/sssp-router.js +295 -0
  96. package/dist/brain/sssp-router.js.map +1 -0
  97. package/dist/brain/swarm-intelligence.d.ts +48 -0
  98. package/dist/brain/swarm-intelligence.d.ts.map +1 -0
  99. package/dist/brain/swarm-intelligence.js +215 -0
  100. package/dist/brain/swarm-intelligence.js.map +1 -0
  101. package/dist/brain/turbo-memory.d.ts +56 -0
  102. package/dist/brain/turbo-memory.d.ts.map +1 -0
  103. package/dist/brain/turbo-memory.js +388 -0
  104. package/dist/brain/turbo-memory.js.map +1 -0
  105. package/dist/cli.js +744 -3
  106. package/dist/cli.js.map +1 -1
  107. package/dist/index.d.ts +19 -1
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +21 -1
  110. package/dist/index.js.map +1 -1
  111. package/dist/types.d.ts +422 -2
  112. package/dist/types.d.ts.map +1 -1
  113. package/dist/ui/dashboard.d.ts.map +1 -1
  114. package/dist/ui/dashboard.js +20 -3
  115. package/dist/ui/dashboard.js.map +1 -1
  116. package/package.json +16 -7
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // src/cli.ts — CLI entry point for Shadow Brain v2.1.0
2
+ // src/cli.ts — CLI entry point for Shadow Brain v4.0.0
3
3
  import { Command } from 'commander';
4
4
  import chalk from 'chalk';
5
5
  import Conf from 'conf';
@@ -7,7 +7,7 @@ import * as fs from 'fs';
7
7
  import * as path from 'path';
8
8
  import { Orchestrator } from './brain/orchestrator.js';
9
9
  import { detectRunningAgents, createAdapter } from './adapters/index.js';
10
- const VERSION = '2.1.0';
10
+ const VERSION = '4.0.0';
11
11
  const config = new Conf({
12
12
  projectName: 'shadow-brain',
13
13
  defaults: {
@@ -1298,6 +1298,7 @@ meshCmd.command('status')
1298
1298
  try {
1299
1299
  const { NeuralMesh } = await import('./brain/neural-mesh.js');
1300
1300
  const mesh = new NeuralMesh(process.cwd());
1301
+ await mesh.connect();
1301
1302
  const state = mesh.getMeshState();
1302
1303
  console.log(chalk.magenta.bold('\n QUANTUM NEURAL MESH Status\n'));
1303
1304
  console.log(chalk.bold(' Quantum State:'), state.quantumState === 'coherent'
@@ -1339,6 +1340,7 @@ meshCmd.command('insights')
1339
1340
  try {
1340
1341
  const { NeuralMesh } = await import('./brain/neural-mesh.js');
1341
1342
  const mesh = new NeuralMesh(process.cwd());
1343
+ await mesh.connect();
1342
1344
  const insights = mesh.getCrossSessionInsights(parseInt(opts.limit));
1343
1345
  if (opts.json) {
1344
1346
  console.log(JSON.stringify(insights, null, 2));
@@ -1371,6 +1373,7 @@ meshCmd.command('knowledge')
1371
1373
  try {
1372
1374
  const { NeuralMesh } = await import('./brain/neural-mesh.js');
1373
1375
  const mesh = new NeuralMesh(process.cwd());
1376
+ await mesh.connect();
1374
1377
  let knowledge = mesh.getSharedKnowledge(parseInt(opts.limit));
1375
1378
  if (opts.category) {
1376
1379
  knowledge = knowledge.filter(k => k.category === opts.category);
@@ -1403,6 +1406,7 @@ meshCmd.command('nodes')
1403
1406
  try {
1404
1407
  const { NeuralMesh } = await import('./brain/neural-mesh.js');
1405
1408
  const mesh = new NeuralMesh(process.cwd());
1409
+ await mesh.connect();
1406
1410
  const nodes = mesh.getConnectedNodes();
1407
1411
  if (opts.json) {
1408
1412
  console.log(JSON.stringify(nodes, null, 2));
@@ -1433,6 +1437,7 @@ meshCmd.command('aggregate')
1433
1437
  try {
1434
1438
  const { NeuralMesh } = await import('./brain/neural-mesh.js');
1435
1439
  const mesh = new NeuralMesh(process.cwd());
1440
+ await mesh.connect();
1436
1441
  const agg = mesh.getAggregatedInsights();
1437
1442
  if (!agg) {
1438
1443
  console.log(chalk.dim('\n No mesh data available.\n'));
@@ -1460,11 +1465,725 @@ meshCmd.command('aggregate')
1460
1465
  process.exit(1);
1461
1466
  }
1462
1467
  });
1468
+ // ─── AST (Complexity Analysis) ────────────────────────────────────────────────
1469
+ const astCmd = new Command('ast')
1470
+ .description('Run AST-level complexity analysis — cyclomatic complexity, nesting, function size')
1471
+ .argument('[project-dir]', 'Project directory', process.cwd())
1472
+ .option('--json', 'Output as JSON')
1473
+ .option('--max-files <n>', 'Max files to analyze', '200')
1474
+ .action(async (projectDir, opts) => {
1475
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1476
+ const orchestrator = new Orchestrator(brainConfig);
1477
+ try {
1478
+ console.log(chalk.cyan(' Running AST complexity analysis...'));
1479
+ const insights = await orchestrator.runASTAnalysis(parseInt(opts.maxFiles));
1480
+ if (opts.json) {
1481
+ console.log(JSON.stringify(insights, null, 2));
1482
+ return;
1483
+ }
1484
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN AST Analysis (${insights.length} findings)\n`));
1485
+ if (insights.length === 0) {
1486
+ console.log(chalk.green(' No complexity issues detected!'));
1487
+ return;
1488
+ }
1489
+ for (const insight of insights) {
1490
+ const color = insight.priority === 'critical' ? 'red' : insight.priority === 'high' ? 'yellow' : 'blue';
1491
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1492
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1493
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1494
+ console.log();
1495
+ }
1496
+ }
1497
+ catch (err) {
1498
+ console.error(chalk.red(' Error:'), err.message);
1499
+ process.exit(1);
1500
+ }
1501
+ });
1502
+ // ─── A11Y (Accessibility Audit) ──────────────────────────────────────────────
1503
+ const a11yCmd = new Command('a11y')
1504
+ .description('Run WCAG accessibility audit on frontend code')
1505
+ .argument('[project-dir]', 'Project directory', process.cwd())
1506
+ .option('--json', 'Output as JSON')
1507
+ .option('--max-files <n>', 'Max files to analyze', '200')
1508
+ .action(async (projectDir, opts) => {
1509
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1510
+ const orchestrator = new Orchestrator(brainConfig);
1511
+ try {
1512
+ console.log(chalk.cyan(' Running accessibility audit...'));
1513
+ const insights = await orchestrator.runA11yCheck(parseInt(opts.maxFiles));
1514
+ if (opts.json) {
1515
+ console.log(JSON.stringify(insights, null, 2));
1516
+ return;
1517
+ }
1518
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Accessibility Audit (${insights.length} issues)\n`));
1519
+ if (insights.length === 0) {
1520
+ console.log(chalk.green(' No accessibility issues found!'));
1521
+ return;
1522
+ }
1523
+ for (const insight of insights) {
1524
+ const color = insight.priority === 'critical' ? 'red' : insight.priority === 'high' ? 'yellow' : 'blue';
1525
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1526
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1527
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1528
+ console.log();
1529
+ }
1530
+ }
1531
+ catch (err) {
1532
+ console.error(chalk.red(' Error:'), err.message);
1533
+ process.exit(1);
1534
+ }
1535
+ });
1536
+ // ─── I18N (Internationalization) ──────────────────────────────────────────────
1537
+ const i18nCmd = new Command('i18n')
1538
+ .description('Check internationalization readiness — hardcoded strings, locale support')
1539
+ .argument('[project-dir]', 'Project directory', process.cwd())
1540
+ .option('--json', 'Output as JSON')
1541
+ .option('--max-files <n>', 'Max files to analyze', '200')
1542
+ .action(async (projectDir, opts) => {
1543
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1544
+ const orchestrator = new Orchestrator(brainConfig);
1545
+ try {
1546
+ console.log(chalk.cyan(' Running i18n readiness check...'));
1547
+ const insights = await orchestrator.runI18nAnalysis(parseInt(opts.maxFiles));
1548
+ if (opts.json) {
1549
+ console.log(JSON.stringify(insights, null, 2));
1550
+ return;
1551
+ }
1552
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN i18n Analysis (${insights.length} findings)\n`));
1553
+ if (insights.length === 0) {
1554
+ console.log(chalk.green(' No i18n issues found!'));
1555
+ return;
1556
+ }
1557
+ for (const insight of insights) {
1558
+ const color = insight.priority === 'high' ? 'yellow' : 'blue';
1559
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1560
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1561
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1562
+ console.log();
1563
+ }
1564
+ }
1565
+ catch (err) {
1566
+ console.error(chalk.red(' Error:'), err.message);
1567
+ process.exit(1);
1568
+ }
1569
+ });
1570
+ // ─── DEAD-CODE ────────────────────────────────────────────────────────────────
1571
+ const deadCodeCmd = new Command('dead-code')
1572
+ .description('Detect dead code — unreachable code, unused exports, unused variables')
1573
+ .argument('[project-dir]', 'Project directory', process.cwd())
1574
+ .option('--json', 'Output as JSON')
1575
+ .option('--max-files <n>', 'Max files to analyze', '200')
1576
+ .action(async (projectDir, opts) => {
1577
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1578
+ const orchestrator = new Orchestrator(brainConfig);
1579
+ try {
1580
+ console.log(chalk.cyan(' Scanning for dead code...'));
1581
+ const insights = await orchestrator.runDeadCodeAnalysis(parseInt(opts.maxFiles));
1582
+ if (opts.json) {
1583
+ console.log(JSON.stringify(insights, null, 2));
1584
+ return;
1585
+ }
1586
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Dead Code Detection (${insights.length} findings)\n`));
1587
+ if (insights.length === 0) {
1588
+ console.log(chalk.green(' No dead code detected!'));
1589
+ return;
1590
+ }
1591
+ for (const insight of insights) {
1592
+ const color = insight.priority === 'high' ? 'yellow' : 'blue';
1593
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1594
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1595
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1596
+ console.log();
1597
+ }
1598
+ }
1599
+ catch (err) {
1600
+ console.error(chalk.red(' Error:'), err.message);
1601
+ process.exit(1);
1602
+ }
1603
+ });
1604
+ // ─── MUTATION (Mutation Testing Advisor) ──────────────────────────────────────
1605
+ const mutationCmd = new Command('mutation')
1606
+ .description('Suggest mutation testing cases — tests that would catch real bugs')
1607
+ .argument('[project-dir]', 'Project directory', process.cwd())
1608
+ .option('--json', 'Output as JSON')
1609
+ .option('--max-files <n>', 'Max files to analyze', '200')
1610
+ .action(async (projectDir, opts) => {
1611
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1612
+ const orchestrator = new Orchestrator(brainConfig);
1613
+ try {
1614
+ console.log(chalk.cyan(' Running mutation testing advisor...'));
1615
+ const insights = await orchestrator.runMutationAnalysis(parseInt(opts.maxFiles));
1616
+ if (opts.json) {
1617
+ console.log(JSON.stringify(insights, null, 2));
1618
+ return;
1619
+ }
1620
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Mutation Advisor (${insights.length} suggestions)\n`));
1621
+ if (insights.length === 0) {
1622
+ console.log(chalk.green(' No mutation suggestions — code looks well-tested or analysis found nothing!'));
1623
+ return;
1624
+ }
1625
+ for (const insight of insights) {
1626
+ const color = insight.priority === 'high' ? 'yellow' : 'blue';
1627
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1628
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1629
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1630
+ console.log();
1631
+ }
1632
+ }
1633
+ catch (err) {
1634
+ console.error(chalk.red(' Error:'), err.message);
1635
+ process.exit(1);
1636
+ }
1637
+ });
1638
+ // ─── CODE-AGE ─────────────────────────────────────────────────────────────────
1639
+ const codeAgeCmd = new Command('code-age')
1640
+ .description('Analyze code freshness — stale files, ownership, change frequency')
1641
+ .argument('[project-dir]', 'Project directory', process.cwd())
1642
+ .option('--json', 'Output as JSON')
1643
+ .action(async (projectDir, opts) => {
1644
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1645
+ const orchestrator = new Orchestrator(brainConfig);
1646
+ try {
1647
+ console.log(chalk.cyan(' Analyzing code age and freshness...'));
1648
+ const insights = await orchestrator.runCodeAgeAnalysis();
1649
+ if (opts.json) {
1650
+ console.log(JSON.stringify(insights, null, 2));
1651
+ return;
1652
+ }
1653
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Code Age Analysis (${insights.length} findings)\n`));
1654
+ if (insights.length === 0) {
1655
+ console.log(chalk.green(' Code looks fresh and well-maintained!'));
1656
+ return;
1657
+ }
1658
+ for (const insight of insights) {
1659
+ const color = insight.priority === 'high' ? 'yellow' : 'blue';
1660
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1661
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1662
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1663
+ console.log();
1664
+ }
1665
+ }
1666
+ catch (err) {
1667
+ console.error(chalk.red(' Error:'), err.message);
1668
+ process.exit(1);
1669
+ }
1670
+ });
1671
+ // ─── API (API Contract Analysis) ──────────────────────────────────────────────
1672
+ const apiCmd = new Command('api')
1673
+ .description('Analyze API contracts — endpoint discovery, security, consistency')
1674
+ .argument('[project-dir]', 'Project directory', process.cwd())
1675
+ .option('--json', 'Output as JSON')
1676
+ .option('--max-files <n>', 'Max files to analyze', '200')
1677
+ .action(async (projectDir, opts) => {
1678
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1679
+ const orchestrator = new Orchestrator(brainConfig);
1680
+ try {
1681
+ console.log(chalk.cyan(' Running API contract analysis...'));
1682
+ const insights = await orchestrator.runAPIContractAnalysis(parseInt(opts.maxFiles));
1683
+ if (opts.json) {
1684
+ console.log(JSON.stringify(insights, null, 2));
1685
+ return;
1686
+ }
1687
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN API Contract Analysis (${insights.length} findings)\n`));
1688
+ if (insights.length === 0) {
1689
+ console.log(chalk.green(' No API contract issues detected!'));
1690
+ return;
1691
+ }
1692
+ for (const insight of insights) {
1693
+ const color = insight.priority === 'critical' ? 'red' : insight.priority === 'high' ? 'yellow' : 'blue';
1694
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1695
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1696
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1697
+ console.log();
1698
+ }
1699
+ }
1700
+ catch (err) {
1701
+ console.error(chalk.red(' Error:'), err.message);
1702
+ process.exit(1);
1703
+ }
1704
+ });
1705
+ // ─── ENV (Environment Variable Analysis) ──────────────────────────────────────
1706
+ const envCmd = new Command('env')
1707
+ .description('Analyze environment variables — secrets, validation, naming conventions')
1708
+ .argument('[project-dir]', 'Project directory', process.cwd())
1709
+ .option('--json', 'Output as JSON')
1710
+ .option('--max-files <n>', 'Max files to analyze', '200')
1711
+ .action(async (projectDir, opts) => {
1712
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1713
+ const orchestrator = new Orchestrator(brainConfig);
1714
+ try {
1715
+ console.log(chalk.cyan(' Analyzing environment variables...'));
1716
+ const insights = await orchestrator.runEnvAnalysis(parseInt(opts.maxFiles));
1717
+ if (opts.json) {
1718
+ console.log(JSON.stringify(insights, null, 2));
1719
+ return;
1720
+ }
1721
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Environment Analysis (${insights.length} findings)\n`));
1722
+ if (insights.length === 0) {
1723
+ console.log(chalk.green(' No environment variable issues detected!'));
1724
+ return;
1725
+ }
1726
+ for (const insight of insights) {
1727
+ const color = insight.priority === 'critical' ? 'red' : insight.priority === 'high' ? 'yellow' : 'blue';
1728
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1729
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1730
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1731
+ console.log();
1732
+ }
1733
+ }
1734
+ catch (err) {
1735
+ console.error(chalk.red(' Error:'), err.message);
1736
+ process.exit(1);
1737
+ }
1738
+ });
1739
+ // ─── LICENSE (License Compliance) ─────────────────────────────────────────────
1740
+ const licenseCmd = new Command('license')
1741
+ .description('Audit dependency licenses — restricted, copyleft, unknown licenses')
1742
+ .argument('[project-dir]', 'Project directory', process.cwd())
1743
+ .option('--json', 'Output as JSON')
1744
+ .action(async (projectDir, opts) => {
1745
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1746
+ const orchestrator = new Orchestrator(brainConfig);
1747
+ try {
1748
+ console.log(chalk.cyan(' Running license compliance audit...'));
1749
+ const insights = await orchestrator.runLicenseCompliance();
1750
+ if (opts.json) {
1751
+ console.log(JSON.stringify(insights, null, 2));
1752
+ return;
1753
+ }
1754
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN License Compliance (${insights.length} findings)\n`));
1755
+ if (insights.length === 0) {
1756
+ console.log(chalk.green(' All dependency licenses are compliant!'));
1757
+ return;
1758
+ }
1759
+ for (const insight of insights) {
1760
+ const color = insight.priority === 'critical' ? 'red' : insight.priority === 'high' ? 'yellow' : 'blue';
1761
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1762
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1763
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1764
+ console.log();
1765
+ }
1766
+ }
1767
+ catch (err) {
1768
+ console.error(chalk.red(' Error:'), err.message);
1769
+ process.exit(1);
1770
+ }
1771
+ });
1772
+ // ─── CONFIG-DRIFT ─────────────────────────────────────────────────────────────
1773
+ const configDriftCmd = new Command('config-drift')
1774
+ .description('Detect configuration drift — missing configs, inconsistent settings')
1775
+ .argument('[project-dir]', 'Project directory', process.cwd())
1776
+ .option('--json', 'Output as JSON')
1777
+ .action(async (projectDir, opts) => {
1778
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1779
+ const orchestrator = new Orchestrator(brainConfig);
1780
+ try {
1781
+ console.log(chalk.cyan(' Detecting configuration drift...'));
1782
+ const insights = await orchestrator.runConfigDriftDetection();
1783
+ if (opts.json) {
1784
+ console.log(JSON.stringify(insights, null, 2));
1785
+ return;
1786
+ }
1787
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN Config Drift Detection (${insights.length} findings)\n`));
1788
+ if (insights.length === 0) {
1789
+ console.log(chalk.green(' No configuration drift detected!'));
1790
+ return;
1791
+ }
1792
+ for (const insight of insights) {
1793
+ const color = insight.priority === 'high' ? 'yellow' : 'blue';
1794
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1795
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1796
+ console.log(` ${insight.content.slice(0, 200)}${insight.content.length > 200 ? '...' : ''}`);
1797
+ console.log();
1798
+ }
1799
+ }
1800
+ catch (err) {
1801
+ console.error(chalk.red(' Error:'), err.message);
1802
+ process.exit(1);
1803
+ }
1804
+ });
1805
+ // ─── HYPER (Full Hyper-Analysis) ──────────────────────────────────────────────
1806
+ const hyperCmd = new Command('hyper')
1807
+ .description('Run ALL v3.0.0 hyper-intelligence analyses at once')
1808
+ .argument('[project-dir]', 'Project directory', process.cwd())
1809
+ .option('--json', 'Output as JSON')
1810
+ .option('--max-files <n>', 'Max files per analysis', '200')
1811
+ .action(async (projectDir, opts) => {
1812
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
1813
+ const orchestrator = new Orchestrator(brainConfig);
1814
+ try {
1815
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Hyper-Intelligence Full Scan\n`));
1816
+ console.log(chalk.cyan(' Running all 10 hyper-intelligence modules in parallel...'));
1817
+ console.log(chalk.dim(' This may take a moment for large projects.\n'));
1818
+ const results = await orchestrator.runFullHyperAnalysis({
1819
+ maxFiles: parseInt(opts.maxFiles),
1820
+ });
1821
+ if (opts.json) {
1822
+ console.log(JSON.stringify(results, null, 2));
1823
+ return;
1824
+ }
1825
+ const modules = [
1826
+ { name: 'ast', label: 'AST Complexity', insights: results.ast },
1827
+ { name: 'a11y', label: 'Accessibility (WCAG)', insights: results.a11y },
1828
+ { name: 'i18n', label: 'Internationalization', insights: results.i18n },
1829
+ { name: 'deadCode', label: 'Dead Code', insights: results.deadCode },
1830
+ { name: 'mutation', label: 'Mutation Testing', insights: results.mutation },
1831
+ { name: 'codeAge', label: 'Code Age', insights: results.codeAge },
1832
+ { name: 'apiContract', label: 'API Contracts', insights: results.apiContract },
1833
+ { name: 'env', label: 'Environment Variables', insights: results.env },
1834
+ { name: 'license', label: 'License Compliance', insights: results.license },
1835
+ { name: 'configDrift', label: 'Config Drift', insights: results.configDrift },
1836
+ ];
1837
+ for (const mod of modules) {
1838
+ const count = mod.insights.length;
1839
+ const color = count === 0 ? 'green' : count < 5 ? 'yellow' : 'red';
1840
+ const icon = count === 0 ? '✓' : '⚠';
1841
+ console.log(chalk ` {${color}.bold ${icon}} ${chalk.bold(mod.label)}: ${count} finding(s)`);
1842
+ }
1843
+ console.log(chalk.bold(`\n Total findings: ${results.total}\n`));
1844
+ // Show critical/high priority details
1845
+ const allCritical = modules.flatMap(m => m.insights.filter(i => i.priority === 'critical' || i.priority === 'high'));
1846
+ if (allCritical.length > 0) {
1847
+ console.log(chalk.red.bold(` Critical/High Priority (${allCritical.length}):\n`));
1848
+ for (const insight of allCritical.slice(0, 20)) {
1849
+ const color = insight.priority === 'critical' ? 'red' : 'yellow';
1850
+ console.log(chalk ` {${color}.bold [${insight.priority.toUpperCase()}]} ${insight.title}`);
1851
+ console.log(chalk.dim(` Files: ${insight.files?.join(', ') || 'none'}`));
1852
+ console.log();
1853
+ }
1854
+ }
1855
+ }
1856
+ catch (err) {
1857
+ console.error(chalk.red(' Error:'), err.message);
1858
+ process.exit(1);
1859
+ }
1860
+ });
1861
+ // ── v4.0.0 Hyper-Intelligence Commands ──────────────────────────────────────────
1862
+ const turboCmd = new Command('turbo')
1863
+ .description('v4.0.0 Infinite memory via TurboQuant (6x compression)')
1864
+ .addCommand(new Command('stats')
1865
+ .description('Show TurboMemory compression stats')
1866
+ .action(async () => {
1867
+ const { TurboMemory } = await import('./brain/turbo-memory.js');
1868
+ const tm = new TurboMemory();
1869
+ const stats = tm.stats();
1870
+ console.log(chalk.magenta.bold('\n TURBO MEMORY — Infinite Retention Stats\n'));
1871
+ console.log(chalk ` {cyan Entries:} ${stats.totalEntries}`);
1872
+ console.log(chalk ` {cyan Compression:} ${(stats.compressionRatio * 100).toFixed(1)}% (6x from 16-bit baseline)`);
1873
+ console.log(chalk ` {cyan Memory Used:} ${stats.memoryUsedMB.toFixed(2)} MB`);
1874
+ console.log(chalk ` {cyan Hot Cache Hit Rate:} ${(stats.hitRate * 100).toFixed(1)}%`);
1875
+ console.log(chalk ` {cyan Retention:} ${stats.retentionDays === Infinity ? 'Infinite' : stats.retentionDays + ' days'}\n`);
1876
+ }))
1877
+ .addCommand(new Command('search')
1878
+ .description('Search TurboMemory by vector similarity')
1879
+ .argument('<query>', 'Search query text')
1880
+ .action(async (query) => {
1881
+ const { TurboMemory } = await import('./brain/turbo-memory.js');
1882
+ const tm = new TurboMemory();
1883
+ // Simple hash-based vector for query
1884
+ const vector = new Array(64).fill(0);
1885
+ const words = query.toLowerCase().split(/\W+/).filter(w => w.length > 2);
1886
+ for (const word of words) {
1887
+ let hash = 0;
1888
+ for (let i = 0; i < word.length; i++) {
1889
+ hash = ((hash << 5) - hash) + word.charCodeAt(i);
1890
+ hash = hash & hash;
1891
+ }
1892
+ vector[Math.abs(hash) % 64] += 1;
1893
+ }
1894
+ const max = Math.max(...vector, 1);
1895
+ const normalized = vector.map(v => v / max);
1896
+ const results = await tm.search(normalized, 10);
1897
+ console.log(chalk.magenta.bold(`\n TURBO SEARCH: "${query}"\n`));
1898
+ if (results.length === 0) {
1899
+ console.log(chalk.dim(' No results found.'));
1900
+ }
1901
+ for (const r of results.slice(0, 10)) {
1902
+ console.log(chalk ` {cyan Key:} ${r.key}`);
1903
+ console.log(chalk ` {dim Metadata:} ${JSON.stringify(r.metadata)}`);
1904
+ console.log(chalk ` {dim Accessed:} ${r.accessCount} times\n`);
1905
+ }
1906
+ }));
1907
+ const routeCmd = new Command('route')
1908
+ .description('v4.0.0 SSSP-based message routing (arXiv 2504.17033)')
1909
+ .addCommand(new Command('status')
1910
+ .description('Show SSSP router status')
1911
+ .action(() => {
1912
+ console.log(chalk.magenta.bold('\n SSSP ROUTER — O(m log^(2/3) n) Deterministic SSSP\n'));
1913
+ console.log(chalk.cyan(' Algorithm: BMSSP (Breaking the Sorting Barrier)'));
1914
+ console.log(chalk.cyan(' Complexity: O(m log^(2/3) n) — sublogarithmic'));
1915
+ console.log(chalk.cyan(' Reference: arXiv 2504.17033 (Duan et al.)'));
1916
+ console.log(chalk.cyan(' Status: Ready for graph construction\n'));
1917
+ }))
1918
+ .addCommand(new Command('find')
1919
+ .description('Find shortest path between two nodes')
1920
+ .argument('<from>', 'Source node ID')
1921
+ .argument('<to>', 'Target node ID')
1922
+ .action(async (from, to) => {
1923
+ const { SSSPRouter } = await import('./brain/sssp-router.js');
1924
+ const router = new SSSPRouter();
1925
+ // Build a simple demo graph
1926
+ router.buildGraph([
1927
+ { id: from, connections: [{ targetId: to, latency: 1 }] },
1928
+ { id: to, connections: [] },
1929
+ ]);
1930
+ const path = router.route(from, to);
1931
+ if (path && path.length > 0) {
1932
+ console.log(chalk.green(`\n Route: ${from} → ${to}`));
1933
+ console.log(chalk.cyan(` Path: ${path.join(' → ')}`));
1934
+ }
1935
+ else {
1936
+ console.log(chalk.red(`\n No route found from ${from} to ${to}`));
1937
+ }
1938
+ }));
1939
+ const caipCmd = new Command('caip')
1940
+ .description('v4.0.0 Cross-Agent Intelligence Protocol')
1941
+ .addCommand(new Command('status')
1942
+ .description('Show CAIP connection status')
1943
+ .action(async () => {
1944
+ const { CrossAgentProtocol } = await import('./brain/cross-agent-protocol.js');
1945
+ const caip = new CrossAgentProtocol();
1946
+ const agents = caip.getConnectedAgents?.() ?? [];
1947
+ console.log(chalk.magenta.bold('\n CROSS-AGENT INTELLIGENCE PROTOCOL\n'));
1948
+ console.log(chalk ` {cyan Connected Agents:} ${agents.length}`);
1949
+ for (const agent of agents) {
1950
+ console.log(chalk ` {green ●} ${agent}`);
1951
+ }
1952
+ if (agents.length === 0) {
1953
+ console.log(chalk.dim(' No agents connected. Start a session to begin broadcasting.'));
1954
+ }
1955
+ console.log();
1956
+ }))
1957
+ .addCommand(new Command('broadcast')
1958
+ .description('Broadcast a message to all connected agents')
1959
+ .argument('<message>', 'Message to broadcast')
1960
+ .action(async (message) => {
1961
+ const { CrossAgentProtocol } = await import('./brain/cross-agent-protocol.js');
1962
+ const caip = new CrossAgentProtocol();
1963
+ await caip.start().catch(() => { });
1964
+ await caip.broadcast('claude-code', { type: 'manual', message });
1965
+ console.log(chalk.green(`\n Broadcast sent: "${message}"\n`));
1966
+ await caip.stop().catch(() => { });
1967
+ }));
1968
+ const evolveCmd = new Command('evolve')
1969
+ .description('v4.0.0 Self-Evolving Genetic Algorithm')
1970
+ .addCommand(new Command('status')
1971
+ .description('Show evolution snapshot')
1972
+ .action(async () => {
1973
+ const { SelfEvolution } = await import('./brain/self-evolution.js');
1974
+ const evolution = new SelfEvolution();
1975
+ const snapshot = evolution.getSnapshot?.();
1976
+ console.log(chalk.magenta.bold('\n SELF-EVOLUTION ENGINE\n'));
1977
+ if (snapshot) {
1978
+ console.log(chalk ` {cyan Generation:} ${snapshot.generation ?? 0}`);
1979
+ console.log(chalk ` {cyan Population:} ${snapshot.population?.length ?? 0} rules`);
1980
+ console.log(chalk ` {cyan Best Fitness:} ${snapshot.bestFitness?.toFixed(3) ?? 'N/A'}`);
1981
+ console.log(chalk ` {cyan Avg Fitness:} ${snapshot.avgFitness?.toFixed(3) ?? 'N/A'}`);
1982
+ console.log(chalk ` {cyan Elite Count:} ${snapshot.eliteCount ?? 0}\n`);
1983
+ }
1984
+ else {
1985
+ console.log(chalk.dim(' No evolution data yet. Run analysis to start evolving rules.\n'));
1986
+ }
1987
+ }))
1988
+ .addCommand(new Command('run')
1989
+ .description('Force an evolution cycle')
1990
+ .action(async () => {
1991
+ const { SelfEvolution } = await import('./brain/self-evolution.js');
1992
+ const evolution = new SelfEvolution();
1993
+ await evolution.evolve([]);
1994
+ const snapshot = evolution.getSnapshot?.();
1995
+ console.log(chalk.green.bold('\n Evolution cycle complete.'));
1996
+ console.log(chalk ` {cyan Generation:} ${snapshot?.generation ?? 1}`);
1997
+ console.log(chalk ` {cyan Best Fitness:} ${snapshot?.bestFitness?.toFixed(3) ?? 'N/A'}\n`);
1998
+ }))
1999
+ .addCommand(new Command('best-rules')
2000
+ .description('Show best evolved rules')
2001
+ .argument('[category]', 'Filter by category', 'all')
2002
+ .action(async (category) => {
2003
+ const { SelfEvolution } = await import('./brain/self-evolution.js');
2004
+ const evolution = new SelfEvolution();
2005
+ const rules = evolution.getBestRules?.(category, 10) ?? [];
2006
+ console.log(chalk.magenta.bold(`\n BEST EVOLVED RULES (${category})\n`));
2007
+ if (rules.length === 0) {
2008
+ console.log(chalk.dim(' No rules yet. Evolution needs data from analysis sessions.'));
2009
+ }
2010
+ for (const rule of rules) {
2011
+ console.log(chalk ` {cyan Fitness:} ${rule.fitness?.toFixed(3) ?? 'N/A'} | {cyan Gen:} ${rule.generation ?? 0} | {cyan Mutations:} ${rule.mutations ?? 0}`);
2012
+ console.log(chalk.dim(` ${JSON.stringify(rule).slice(0, 120)}`));
2013
+ console.log();
2014
+ }
2015
+ }));
2016
+ const predictCmd = new Command('predict')
2017
+ .description('v4.0.0 Predictive Engine — bug risk & tech debt forecasting')
2018
+ .addCommand(new Command('bugs')
2019
+ .description('Score files for bug risk')
2020
+ .argument('[dir]', 'Project directory', process.cwd())
2021
+ .action(async (dir) => {
2022
+ const { PredictiveEngine } = await import('./brain/predictive-engine.js');
2023
+ const { CodeMetricsEngine } = await import('./brain/code-metrics.js');
2024
+ const engine = new PredictiveEngine();
2025
+ const metrics = new CodeMetricsEngine(dir).compute();
2026
+ const files = fs.readdirSync(dir, { recursive: true })
2027
+ .filter((f) => /\.(ts|js|tsx|jsx)$/.test(String(f)))
2028
+ .slice(0, 50)
2029
+ .map((f) => ({
2030
+ file: String(f), lastModified: new Date(), daysSinceModification: 0,
2031
+ linesChangedRecently: 0, stalenessScore: 0, risk: 'fresh',
2032
+ authors: [], churnRate: 0,
2033
+ }));
2034
+ const risks = engine.scoreBugRisk(files, metrics);
2035
+ console.log(chalk.magenta.bold('\n BUG RISK PREDICTION\n'));
2036
+ const sorted = risks.sort((a, b) => (b.confidence || 0) - (a.confidence || 0));
2037
+ for (const risk of sorted.slice(0, 20)) {
2038
+ const color = risk.riskLevel === 'critical' ? 'red' : risk.riskLevel === 'high' ? 'yellow' : 'green';
2039
+ console.log(chalk ` {${color}.bold [${(risk.riskLevel || 'low').toUpperCase()}]} ${risk.file}`);
2040
+ console.log(chalk.dim(` Factors: ${(risk.factors || []).join(', ')} | Confidence: ${((risk.confidence || 0) * 100).toFixed(0)}%`));
2041
+ }
2042
+ console.log();
2043
+ }));
2044
+ const graphCmd = new Command('graph')
2045
+ .description('v4.0.0 Knowledge Graph with PageRank')
2046
+ .addCommand(new Command('build')
2047
+ .description('Build knowledge graph from project')
2048
+ .argument('[dir]', 'Project directory', process.cwd())
2049
+ .action(async (dir) => {
2050
+ const { KnowledgeGraph } = await import('./brain/knowledge-graph.js');
2051
+ const kg = new KnowledgeGraph(dir);
2052
+ await kg.build();
2053
+ const stats = kg.getStats?.() ?? {};
2054
+ console.log(chalk.green.bold('\n Knowledge Graph Built'));
2055
+ console.log(chalk ` {cyan Entities:} ${stats.entityCount ?? 0}`);
2056
+ console.log(chalk ` {cyan Relations:} ${stats.relationCount ?? 0}\n`);
2057
+ }));
2058
+ const swarmCmd = new Command('swarm')
2059
+ .description('v4.0.0 Swarm Intelligence — Ant Colony file prioritization')
2060
+ .addCommand(new Command('status')
2061
+ .description('Show swarm convergence state')
2062
+ .action(async () => {
2063
+ const { SwarmIntelligence } = await import('./brain/swarm-intelligence.js');
2064
+ const swarm = new SwarmIntelligence();
2065
+ const state = swarm.getState?.();
2066
+ console.log(chalk.magenta.bold('\n SWARM INTELLIGENCE\n'));
2067
+ if (state) {
2068
+ console.log(chalk ` {cyan Convergence:} ${state.convergenceScore?.toFixed(3) ?? 'N/A'}`);
2069
+ console.log(chalk ` {cyan Pheromone Trails:} ${state.trailCount ?? 0}`);
2070
+ console.log(chalk ` {cyan Tasks:} ${state.taskCount ?? 0}\n`);
2071
+ }
2072
+ else {
2073
+ console.log(chalk.dim(' Swarm not initialized. Run analysis to begin.\n'));
2074
+ }
2075
+ }))
2076
+ .addCommand(new Command('priorities')
2077
+ .description('Show high-priority files from swarm analysis')
2078
+ .action(async () => {
2079
+ const { SwarmIntelligence } = await import('./brain/swarm-intelligence.js');
2080
+ const swarm = new SwarmIntelligence();
2081
+ const files = swarm.getHighPriorityFiles?.(20) ?? [];
2082
+ console.log(chalk.magenta.bold('\n SWARM PRIORITIES\n'));
2083
+ if (files.length === 0) {
2084
+ console.log(chalk.dim(' No priorities yet. Run analysis to deposit pheromones.'));
2085
+ }
2086
+ for (const f of files) {
2087
+ console.log(chalk ` {yellow ●} ${f}`);
2088
+ }
2089
+ console.log();
2090
+ }));
2091
+ const defenseCmd = new Command('defense')
2092
+ .description('v4.0.0 Adversarial Hallucination Defense')
2093
+ .addCommand(new Command('status')
2094
+ .description('Show defense statistics')
2095
+ .action(async () => {
2096
+ const { AdversarialDefense } = await import('./brain/adversarial-defense.js');
2097
+ const defense = new AdversarialDefense();
2098
+ const stats = defense.getDefenseStats?.() ?? null;
2099
+ console.log(chalk.magenta.bold('\n ADVERSARIAL DEFENSE\n'));
2100
+ if (stats) {
2101
+ console.log(chalk ` {cyan Total Verifications:} ${stats.totalChecked}`);
2102
+ console.log(chalk ` {cyan Flagged:} ${stats.flagged}`);
2103
+ console.log(chalk ` {cyan Blocked:} ${stats.blocked}`);
2104
+ console.log(chalk ` {cyan False Positives:} ${stats.falsePositives}`);
2105
+ console.log(chalk ` {cyan Accuracy:} ${(stats.accuracy * 100).toFixed(1)}%\n`);
2106
+ }
2107
+ else {
2108
+ console.log(chalk ` {dim No defense statistics available yet.}\n`);
2109
+ }
2110
+ }))
2111
+ .addCommand(new Command('scan')
2112
+ .description('Scan a text for hallucination patterns')
2113
+ .argument('<text>', 'Text to scan')
2114
+ .action(async (text) => {
2115
+ const { AdversarialDefense } = await import('./brain/adversarial-defense.js');
2116
+ const defense = new AdversarialDefense();
2117
+ const insight = {
2118
+ type: 'warning', priority: 'high', title: text, content: text,
2119
+ files: [], timestamp: new Date(),
2120
+ };
2121
+ const flag = await defense.verifyInsight(insight, process.cwd());
2122
+ if (flag) {
2123
+ console.log(chalk ` {red.bold ⚠ HALLUCINATION DETECTED}`);
2124
+ console.log(chalk ` {dim Verdict:} ${flag.verdict}`);
2125
+ console.log(chalk ` {dim Confidence:} ${((flag.confidence || 0) * 100).toFixed(0)}%\n`);
2126
+ }
2127
+ else {
2128
+ console.log(chalk.green.bold('\n ✓ No hallucination patterns detected.\n'));
2129
+ }
2130
+ }));
2131
+ const v4Cmd = new Command('v4')
2132
+ .description('Run ALL v4.0.0 hyper-intelligence analyses at once')
2133
+ .argument('[project-dir]', 'Project directory', process.cwd())
2134
+ .option('--json', 'Output as JSON')
2135
+ .action(async (projectDir, opts) => {
2136
+ const brainConfig = mergeConfig({ projectDir, watchMode: false });
2137
+ const orchestrator = new Orchestrator(brainConfig);
2138
+ try {
2139
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — v4.0.0 Hyper-Intelligence Full Scan\n`));
2140
+ console.log(chalk.cyan(' Running ALL v3.0.0 + v4.0.0 modules in parallel...'));
2141
+ console.log(chalk.dim(' TurboQuant | SSSP | CAIP | Self-Evolution | Predictive | Knowledge Graph | Swarm | Adversarial\n'));
2142
+ const results = await orchestrator.runFullHyperAnalysis();
2143
+ if (opts.json) {
2144
+ console.log(JSON.stringify(results, null, 2));
2145
+ return;
2146
+ }
2147
+ // v3.0.0 modules
2148
+ const v3Modules = [
2149
+ { name: 'ast', label: 'AST Complexity', insights: results.ast },
2150
+ { name: 'a11y', label: 'Accessibility (WCAG)', insights: results.a11y },
2151
+ { name: 'i18n', label: 'Internationalization', insights: results.i18n },
2152
+ { name: 'deadCode', label: 'Dead Code', insights: results.deadCode },
2153
+ { name: 'mutation', label: 'Mutation Testing', insights: results.mutation },
2154
+ { name: 'codeAge', label: 'Code Age', insights: results.codeAge },
2155
+ { name: 'apiContract', label: 'API Contracts', insights: results.apiContract },
2156
+ { name: 'env', label: 'Environment Variables', insights: results.env },
2157
+ { name: 'license', label: 'License Compliance', insights: results.license },
2158
+ { name: 'configDrift', label: 'Config Drift', insights: results.configDrift },
2159
+ ];
2160
+ console.log(chalk.bold(' v3.0.0 Modules:'));
2161
+ for (const mod of v3Modules) {
2162
+ const count = mod.insights.length;
2163
+ const color = count === 0 ? 'green' : count < 5 ? 'yellow' : 'red';
2164
+ const icon = count === 0 ? '✓' : '⚠';
2165
+ console.log(chalk ` {${color}.bold ${icon}} ${chalk.bold(mod.label)}: ${count} finding(s)`);
2166
+ }
2167
+ // v4.0.0 results
2168
+ console.log(chalk.bold('\n v4.0.0 Hyper-Intelligence:'));
2169
+ const turbo = results.turboMemoryStats;
2170
+ console.log(chalk ` {cyan TurboQuant:} ${turbo ? `${turbo.totalEntries} entries, ${(turbo.compressionRatio * 100).toFixed(1)}% compressed, ${turbo.memoryUsedMB.toFixed(2)} MB` : 'N/A'}`);
2171
+ console.log(chalk ` {cyan Swarm:} convergence ${results.swarmState?.convergenceScore?.toFixed(3) ?? 'N/A'}`);
2172
+ console.log(chalk ` {cyan Evolution:} gen ${results.evolutionSnapshot?.generation ?? 0}, fitness ${results.evolutionSnapshot?.bestFitness?.toFixed(3) ?? 'N/A'}`);
2173
+ console.log(chalk ` {cyan Knowledge Graph:} ${results.knowledgeGraphEntityCount} entities`);
2174
+ console.log(chalk ` {cyan Adversarial Defense:} ${results.defenseStats?.length ?? 0} verifications`);
2175
+ console.log(chalk.bold(`\n Total v3 findings: ${results.total}\n`));
2176
+ }
2177
+ catch (err) {
2178
+ console.error(chalk.red(' Error:'), err.message);
2179
+ process.exit(1);
2180
+ }
2181
+ });
1463
2182
  // ─── MAIN ─────────────────────────────────────────────────────────────────────
1464
2183
  const program = new Command();
1465
2184
  program
1466
2185
  .name('shadow-brain')
1467
- .description('Shadow Brain v2.1.0 — Super-Intelligence Layer for AI Coding Agents with Quantum Neural Mesh')
2186
+ .description('Shadow Brain v4.0.0 — Hyper-Intelligence Layer for AI Coding Agents with Infinite Memory & Self-Evolution')
1468
2187
  .version(VERSION);
1469
2188
  program.addCommand(startCmd);
1470
2189
  program.addCommand(reviewCmd);
@@ -1497,5 +2216,27 @@ program.addCommand(contextCmd);
1497
2216
  program.addCommand(learnCmd);
1498
2217
  // v2.1.0 commands
1499
2218
  program.addCommand(meshCmd);
2219
+ // v3.0.0 hyper-intelligence commands
2220
+ program.addCommand(astCmd);
2221
+ program.addCommand(a11yCmd);
2222
+ program.addCommand(i18nCmd);
2223
+ program.addCommand(deadCodeCmd);
2224
+ program.addCommand(mutationCmd);
2225
+ program.addCommand(codeAgeCmd);
2226
+ program.addCommand(apiCmd);
2227
+ program.addCommand(envCmd);
2228
+ program.addCommand(licenseCmd);
2229
+ program.addCommand(configDriftCmd);
2230
+ program.addCommand(hyperCmd);
2231
+ // v4.0.0 hyper-intelligence commands
2232
+ program.addCommand(turboCmd);
2233
+ program.addCommand(routeCmd);
2234
+ program.addCommand(caipCmd);
2235
+ program.addCommand(evolveCmd);
2236
+ program.addCommand(predictCmd);
2237
+ program.addCommand(graphCmd);
2238
+ program.addCommand(swarmCmd);
2239
+ program.addCommand(defenseCmd);
2240
+ program.addCommand(v4Cmd);
1500
2241
  program.parse();
1501
2242
  //# sourceMappingURL=cli.js.map