@theihtisham/agent-shadow-brain 5.0.1 → 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 (38) hide show
  1. package/README.md +244 -37
  2. package/dist/brain/code-dna.d.ts +70 -0
  3. package/dist/brain/code-dna.d.ts.map +1 -0
  4. package/dist/brain/code-dna.js +611 -0
  5. package/dist/brain/code-dna.js.map +1 -0
  6. package/dist/brain/fine-tuning-engine.d.ts +99 -0
  7. package/dist/brain/fine-tuning-engine.d.ts.map +1 -0
  8. package/dist/brain/fine-tuning-engine.js +681 -0
  9. package/dist/brain/fine-tuning-engine.js.map +1 -0
  10. package/dist/brain/intent-engine.d.ts +64 -0
  11. package/dist/brain/intent-engine.d.ts.map +1 -0
  12. package/dist/brain/intent-engine.js +374 -0
  13. package/dist/brain/intent-engine.js.map +1 -0
  14. package/dist/brain/lsp-server.d.ts +62 -0
  15. package/dist/brain/lsp-server.d.ts.map +1 -0
  16. package/dist/brain/lsp-server.js +480 -0
  17. package/dist/brain/lsp-server.js.map +1 -0
  18. package/dist/brain/orchestrator.d.ts +13 -0
  19. package/dist/brain/orchestrator.d.ts.map +1 -1
  20. package/dist/brain/orchestrator.js +25 -1
  21. package/dist/brain/orchestrator.js.map +1 -1
  22. package/dist/brain/smart-cache.d.ts +100 -0
  23. package/dist/brain/smart-cache.d.ts.map +1 -0
  24. package/dist/brain/smart-cache.js +417 -0
  25. package/dist/brain/smart-cache.js.map +1 -0
  26. package/dist/brain/temporal-intelligence.d.ts +89 -0
  27. package/dist/brain/temporal-intelligence.d.ts.map +1 -0
  28. package/dist/brain/temporal-intelligence.js +378 -0
  29. package/dist/brain/temporal-intelligence.js.map +1 -0
  30. package/dist/cli.js +267 -2
  31. package/dist/cli.js.map +1 -1
  32. package/dist/index.d.ts +8 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +8 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/types.d.ts +205 -0
  37. package/dist/types.d.ts.map +1 -1
  38. package/package.json +2 -2
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 v5.0.1
2
+ // src/cli.ts — CLI entry point for Shadow Brain v5.1.1
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 = '5.0.1';
10
+ const VERSION = '5.1.1';
11
11
  const config = new Conf({
12
12
  projectName: 'shadow-brain',
13
13
  defaults: {
@@ -2664,5 +2664,270 @@ program.addCommand(askCmd);
2664
2664
  program.addCommand(exportCmd);
2665
2665
  program.addCommand(importCmd);
2666
2666
  program.addCommand(pluginCmd);
2667
+ // ── v5.1.1 Commands ─────────────────────────────────────────────────────
2668
+ const lspCmd = new Command('lsp')
2669
+ .description('Start the built-in Language Server Protocol server')
2670
+ .option('--port <port>', 'TCP port for LSP server', '7343')
2671
+ .option('--stdio', 'Use stdio transport instead of TCP')
2672
+ .action(async (opts) => {
2673
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — LSP Server`));
2674
+ try {
2675
+ const { LSPServer } = await import('./brain/lsp-server.js');
2676
+ const lsp = new LSPServer(process.cwd());
2677
+ if (opts.stdio) {
2678
+ console.log(chalk.cyan(' Starting LSP server (stdio mode)...'));
2679
+ lsp.startStdio();
2680
+ }
2681
+ else {
2682
+ const port = parseInt(opts.port, 10);
2683
+ console.log(chalk.cyan(` Starting LSP server on port ${port}...`));
2684
+ lsp.startTCP(port);
2685
+ }
2686
+ console.log(chalk.green(' LSP server running. Connect your editor.'));
2687
+ console.log(chalk.dim(' Features: diagnostics, hover, completions, code actions'));
2688
+ }
2689
+ catch (err) {
2690
+ console.error(chalk.red(' Error:'), err.message);
2691
+ process.exit(1);
2692
+ }
2693
+ });
2694
+ const finetuneCmd = new Command('fine-tune')
2695
+ .description('Train the brain on your codebase patterns')
2696
+ .addCommand(new Command('train')
2697
+ .description('Train on the current project')
2698
+ .option('--dir <directory>', 'Directory to train on')
2699
+ .action(async (opts) => {
2700
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Fine-Tuning Engine`));
2701
+ try {
2702
+ const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
2703
+ const ft = new FineTuningEngine(opts.dir || process.cwd());
2704
+ console.log(chalk.cyan(' Training on codebase patterns...'));
2705
+ await ft.trainOnDirectory(opts.dir);
2706
+ await ft.save();
2707
+ const stats = ft.stats();
2708
+ console.log(chalk.green(' Training complete!'));
2709
+ console.log(chalk.dim(' Patterns: ') + chalk.cyan(String(stats.totalPatterns)));
2710
+ console.log(chalk.dim(' Training points: ') + chalk.cyan(String(stats.totalTrainingPoints)));
2711
+ console.log(chalk.dim(' Models: ') + chalk.cyan(String(stats.models)));
2712
+ console.log(chalk.dim(' Accuracy: ') + chalk.cyan(`${(stats.accuracy * 100).toFixed(1)}%`));
2713
+ }
2714
+ catch (err) {
2715
+ console.error(chalk.red(' Error:'), err.message);
2716
+ }
2717
+ }))
2718
+ .addCommand(new Command('stats')
2719
+ .description('Show fine-tuning statistics')
2720
+ .action(async () => {
2721
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Fine-Tune Stats`));
2722
+ try {
2723
+ const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
2724
+ const ft = new FineTuningEngine(process.cwd());
2725
+ await ft.load();
2726
+ const stats = ft.stats();
2727
+ console.log(chalk.dim(' Patterns: ') + chalk.cyan(String(stats.totalPatterns)));
2728
+ console.log(chalk.dim(' Training points: ') + chalk.cyan(String(stats.totalTrainingPoints)));
2729
+ console.log(chalk.dim(' Models: ') + chalk.cyan(String(stats.models)));
2730
+ console.log(chalk.dim(' Accuracy: ') + chalk.cyan(`${(stats.accuracy * 100).toFixed(1)}%`));
2731
+ if (stats.lastTrainingRun) {
2732
+ console.log(chalk.dim(' Last trained: ') + chalk.cyan(new Date(stats.lastTrainingRun).toLocaleString()));
2733
+ }
2734
+ if (stats.topPatterns.length > 0) {
2735
+ console.log(chalk.dim('\n Top patterns:'));
2736
+ for (const p of stats.topPatterns.slice(0, 5)) {
2737
+ console.log(` ${chalk.yellow(p.type)} (${p.count}x)`);
2738
+ }
2739
+ }
2740
+ }
2741
+ catch (err) {
2742
+ console.error(chalk.red(' Error:'), err.message);
2743
+ }
2744
+ }))
2745
+ .addCommand(new Command('suggest')
2746
+ .description('Get code suggestions based on trained model')
2747
+ .argument('[context]', 'Context for suggestions', '')
2748
+ .action(async (context) => {
2749
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Code Suggestions`));
2750
+ try {
2751
+ const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
2752
+ const ft = new FineTuningEngine(process.cwd());
2753
+ await ft.load();
2754
+ const suggestions = ft.suggest(context || 'general');
2755
+ if (suggestions.length === 0) {
2756
+ console.log(chalk.dim(' No suggestions yet. Run: shadow-brain fine-tune train'));
2757
+ return;
2758
+ }
2759
+ for (const s of suggestions) {
2760
+ console.log(` ${chalk.cyan(s.category)} ${chalk.white(s.text)} (${chalk.dim(`${(s.confidence * 100).toFixed(0)}%`)})`);
2761
+ }
2762
+ }
2763
+ catch (err) {
2764
+ console.error(chalk.red(' Error:'), err.message);
2765
+ }
2766
+ }));
2767
+ const cacheCmd = new Command('cache')
2768
+ .description('Smart cache management')
2769
+ .addCommand(new Command('stats')
2770
+ .description('Show cache statistics')
2771
+ .action(async () => {
2772
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Smart Cache`));
2773
+ try {
2774
+ const { SmartCache } = await import('./brain/smart-cache.js');
2775
+ const cache = new SmartCache();
2776
+ const stats = cache.stats();
2777
+ console.log(chalk.dim(' Hot: ') + chalk.red(String(stats.hotEntries)));
2778
+ console.log(chalk.dim(' Warm: ') + chalk.yellow(String(stats.warmEntries)));
2779
+ console.log(chalk.dim(' Cold: ') + chalk.blue(String(stats.coldEntries)));
2780
+ console.log(chalk.dim(' Hit rate: ') + chalk.green(`${(stats.hitRate * 100).toFixed(1)}%`));
2781
+ console.log(chalk.dim(' Memory: ') + chalk.cyan(`${stats.memoryUsageMB} MB`));
2782
+ console.log(chalk.dim(' Prefetch hits: ') + chalk.cyan(String(stats.prefetchHits)));
2783
+ }
2784
+ catch (err) {
2785
+ console.error(chalk.red(' Error:'), err.message);
2786
+ }
2787
+ }));
2788
+ const intentCmd = new Command('intent')
2789
+ .description('Developer intent prediction')
2790
+ .addCommand(new Command('stats')
2791
+ .description('Show intent prediction statistics')
2792
+ .action(async () => {
2793
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Intent Engine`));
2794
+ try {
2795
+ const { IntentEngine } = await import('./brain/intent-engine.js');
2796
+ const ie = new IntentEngine();
2797
+ const stats = ie.stats();
2798
+ console.log(chalk.dim(' Predictions: ') + chalk.cyan(String(stats.totalPredictions)));
2799
+ console.log(chalk.dim(' Accuracy: ') + chalk.green(`${(stats.accuracy * 100).toFixed(1)}%`));
2800
+ console.log(chalk.dim(' Avg confidence: ') + chalk.cyan(`${(stats.avgConfidence * 100).toFixed(1)}%`));
2801
+ if (stats.topIntents.length > 0) {
2802
+ console.log(chalk.dim('\n Top intents:'));
2803
+ for (const a of stats.topIntents.slice(0, 5)) {
2804
+ console.log(` ${chalk.yellow(a.action)}: ${a.count}`);
2805
+ }
2806
+ }
2807
+ }
2808
+ catch (err) {
2809
+ console.error(chalk.red(' Error:'), err.message);
2810
+ }
2811
+ }));
2812
+ const dnaCmd = new Command('dna')
2813
+ .description('Code DNA fingerprinting and style analysis')
2814
+ .addCommand(new Command('profile')
2815
+ .description('Build a DNA profile of the project')
2816
+ .option('--name <name>', 'Profile name', 'default')
2817
+ .action(async (opts) => {
2818
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Code DNA`));
2819
+ try {
2820
+ const { CodeDNA } = await import('./brain/code-dna.js');
2821
+ const dna = new CodeDNA(process.cwd());
2822
+ console.log(chalk.cyan(' Building DNA profile...'));
2823
+ const profile = await dna.buildProfile(opts.name);
2824
+ console.log(chalk.green(' Profile built!'));
2825
+ console.log(chalk.dim(' Files analyzed: ') + chalk.cyan(String(profile.fileCount)));
2826
+ console.log(chalk.dim(' Genes tracked: ') + chalk.cyan(String(profile.genes.size)));
2827
+ console.log(chalk.dim('\n Gene highlights:'));
2828
+ for (const g of Array.from(profile.genes.values()).slice(0, 8)) {
2829
+ const bar = '█'.repeat(Math.round(g.value * 10)) + '░'.repeat(10 - Math.round(g.value * 10));
2830
+ console.log(` ${chalk.dim(g.category.padEnd(16))} ${chalk.yellow(g.trait.padEnd(24))} ${chalk.cyan(bar)} ${(g.value * 100).toFixed(0)}%`);
2831
+ }
2832
+ }
2833
+ catch (err) {
2834
+ console.error(chalk.red(' Error:'), err.message);
2835
+ }
2836
+ }))
2837
+ .addCommand(new Command('consistency')
2838
+ .description('Check code style consistency')
2839
+ .action(async () => {
2840
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Style Consistency`));
2841
+ try {
2842
+ const { CodeDNA } = await import('./brain/code-dna.js');
2843
+ const dna = new CodeDNA(process.cwd());
2844
+ console.log(chalk.cyan(' Analyzing consistency...'));
2845
+ const report = await dna.checkConsistency();
2846
+ const scoreColor = report.overall > 0.8 ? chalk.green : report.overall > 0.6 ? chalk.yellow : chalk.red;
2847
+ console.log(chalk.dim(' Overall score: ') + scoreColor(`${(report.overall * 100).toFixed(1)}%`));
2848
+ if (report.recommendations.length > 0) {
2849
+ console.log(chalk.dim('\n Recommendations:'));
2850
+ for (const r of report.recommendations.slice(0, 5)) {
2851
+ console.log(` ${chalk.yellow('→')} ${r}`);
2852
+ }
2853
+ }
2854
+ }
2855
+ catch (err) {
2856
+ console.error(chalk.red(' Error:'), err.message);
2857
+ }
2858
+ }));
2859
+ const temporalCmd = new Command('temporal')
2860
+ .description('Temporal code evolution analysis')
2861
+ .addCommand(new Command('velocity')
2862
+ .description('Show development velocity')
2863
+ .action(async () => {
2864
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Velocity`));
2865
+ try {
2866
+ const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
2867
+ const ti = new TemporalIntelligence(process.cwd());
2868
+ const velocity = ti.getVelocity();
2869
+ const trendIcon = velocity.trend === 'accelerating' ? '🚀' : velocity.trend === 'stable' ? '→' : velocity.trend === 'decelerating' ? '↓' : '⏸';
2870
+ console.log(chalk.dim(' Daily events: ') + chalk.cyan(String(velocity.daily)));
2871
+ console.log(chalk.dim(' Weekly events: ') + chalk.cyan(String(velocity.weekly)));
2872
+ console.log(chalk.dim(' Monthly events: ') + chalk.cyan(String(velocity.monthly)));
2873
+ console.log(chalk.dim(' Trend: ') + chalk.yellow(`${trendIcon} ${velocity.trend} (${(velocity.trendConfidence * 100).toFixed(0)}%)`));
2874
+ }
2875
+ catch (err) {
2876
+ console.error(chalk.red(' Error:'), err.message);
2877
+ }
2878
+ }))
2879
+ .addCommand(new Command('hotfiles')
2880
+ .description('Show most active files')
2881
+ .option('-n <count>', 'Number of files', '10')
2882
+ .action(async (opts) => {
2883
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Hot Files`));
2884
+ try {
2885
+ const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
2886
+ const ti = new TemporalIntelligence(process.cwd());
2887
+ const hot = ti.getHotFiles(parseInt(opts.n || '10', 10));
2888
+ if (hot.length === 0) {
2889
+ console.log(chalk.dim(' No file history yet. Run analysis first.'));
2890
+ return;
2891
+ }
2892
+ for (const f of hot) {
2893
+ const bar = '█'.repeat(Math.round(f.hotness * 10)) + '░'.repeat(10 - Math.round(f.hotness * 10));
2894
+ console.log(` ${chalk.red(bar)} ${chalk.dim(`${(f.hotness * 100).toFixed(0)}%`.padStart(4))} ${chalk.white(f.file)}`);
2895
+ }
2896
+ }
2897
+ catch (err) {
2898
+ console.error(chalk.red(' Error:'), err.message);
2899
+ }
2900
+ }))
2901
+ .addCommand(new Command('predict-bugs')
2902
+ .description('Predict bug-prone files')
2903
+ .option('-n <count>', 'Number of predictions', '10')
2904
+ .action(async (opts) => {
2905
+ console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Bug Predictions`));
2906
+ try {
2907
+ const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
2908
+ const ti = new TemporalIntelligence(process.cwd());
2909
+ const bugs = ti.predictBugs(parseInt(opts.n || '10', 10));
2910
+ if (bugs.length === 0) {
2911
+ console.log(chalk.dim(' No predictions available. Need more history.'));
2912
+ return;
2913
+ }
2914
+ for (const b of bugs) {
2915
+ const risk = b.probability > 0.7 ? chalk.red : b.probability > 0.4 ? chalk.yellow : chalk.green;
2916
+ console.log(` ${risk(`${(b.probability * 100).toFixed(0)}%`.padStart(4))} ${chalk.white(b.file)}`);
2917
+ for (const f of b.factors) {
2918
+ console.log(` ${chalk.dim('→')} ${chalk.dim(f)}`);
2919
+ }
2920
+ }
2921
+ }
2922
+ catch (err) {
2923
+ console.error(chalk.red(' Error:'), err.message);
2924
+ }
2925
+ }));
2926
+ program.addCommand(lspCmd);
2927
+ program.addCommand(finetuneCmd);
2928
+ program.addCommand(cacheCmd);
2929
+ program.addCommand(intentCmd);
2930
+ program.addCommand(dnaCmd);
2931
+ program.addCommand(temporalCmd);
2667
2932
  program.parse();
2668
2933
  //# sourceMappingURL=cli.js.map