@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.
- package/README.md +1159 -888
- package/dist/adapters/copilot.d.ts +14 -0
- package/dist/adapters/copilot.d.ts.map +1 -0
- package/dist/adapters/copilot.js +93 -0
- package/dist/adapters/copilot.js.map +1 -0
- package/dist/adapters/cursor.d.ts +13 -0
- package/dist/adapters/cursor.d.ts.map +1 -0
- package/dist/adapters/cursor.js +96 -0
- package/dist/adapters/cursor.js.map +1 -0
- package/dist/adapters/index.d.ts +4 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +7 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/windsurf.d.ts +14 -0
- package/dist/adapters/windsurf.d.ts.map +1 -0
- package/dist/adapters/windsurf.js +107 -0
- package/dist/adapters/windsurf.js.map +1 -0
- package/dist/brain/code-dna.d.ts +70 -0
- package/dist/brain/code-dna.d.ts.map +1 -0
- package/dist/brain/code-dna.js +611 -0
- package/dist/brain/code-dna.js.map +1 -0
- package/dist/brain/fine-tuning-engine.d.ts +99 -0
- package/dist/brain/fine-tuning-engine.d.ts.map +1 -0
- package/dist/brain/fine-tuning-engine.js +681 -0
- package/dist/brain/fine-tuning-engine.js.map +1 -0
- package/dist/brain/global-brain.d.ts +56 -0
- package/dist/brain/global-brain.d.ts.map +1 -0
- package/dist/brain/global-brain.js +324 -0
- package/dist/brain/global-brain.js.map +1 -0
- package/dist/brain/intent-engine.d.ts +64 -0
- package/dist/brain/intent-engine.d.ts.map +1 -0
- package/dist/brain/intent-engine.js +374 -0
- package/dist/brain/intent-engine.js.map +1 -0
- package/dist/brain/l0-cache.d.ts +40 -0
- package/dist/brain/l0-cache.d.ts.map +1 -0
- package/dist/brain/l0-cache.js +176 -0
- package/dist/brain/l0-cache.js.map +1 -0
- package/dist/brain/lsp-server.d.ts +62 -0
- package/dist/brain/lsp-server.d.ts.map +1 -0
- package/dist/brain/lsp-server.js +480 -0
- package/dist/brain/lsp-server.js.map +1 -0
- package/dist/brain/mcp-server.d.ts +4 -0
- package/dist/brain/mcp-server.d.ts.map +1 -1
- package/dist/brain/mcp-server.js +91 -0
- package/dist/brain/mcp-server.js.map +1 -1
- package/dist/brain/orchestrator.d.ts +13 -0
- package/dist/brain/orchestrator.d.ts.map +1 -1
- package/dist/brain/orchestrator.js +25 -1
- package/dist/brain/orchestrator.js.map +1 -1
- package/dist/brain/session-hooks.d.ts +28 -0
- package/dist/brain/session-hooks.d.ts.map +1 -0
- package/dist/brain/session-hooks.js +475 -0
- package/dist/brain/session-hooks.js.map +1 -0
- package/dist/brain/smart-cache.d.ts +100 -0
- package/dist/brain/smart-cache.d.ts.map +1 -0
- package/dist/brain/smart-cache.js +417 -0
- package/dist/brain/smart-cache.js.map +1 -0
- package/dist/brain/subconscious.d.ts +34 -0
- package/dist/brain/subconscious.d.ts.map +1 -0
- package/dist/brain/subconscious.js +275 -0
- package/dist/brain/subconscious.js.map +1 -0
- package/dist/brain/temporal-intelligence.d.ts +89 -0
- package/dist/brain/temporal-intelligence.d.ts.map +1 -0
- package/dist/brain/temporal-intelligence.js +378 -0
- package/dist/brain/temporal-intelligence.js.map +1 -0
- package/dist/cli.js +434 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +333 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +46 -10
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.
|
|
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.
|
|
10
|
+
const VERSION = '5.1.1';
|
|
11
11
|
const config = new Conf({
|
|
12
12
|
projectName: 'shadow-brain',
|
|
13
13
|
defaults: {
|
|
@@ -2495,8 +2495,7 @@ const offCmd = new Command('off')
|
|
|
2495
2495
|
.action(async () => {
|
|
2496
2496
|
console.log(chalk.magenta.bold('\n SHADOW BRAIN v' + VERSION + ' — Shutting down'));
|
|
2497
2497
|
try {
|
|
2498
|
-
const {
|
|
2499
|
-
const exec = execaDefault;
|
|
2498
|
+
const { execa: exec } = await import('execa');
|
|
2500
2499
|
try {
|
|
2501
2500
|
if (process.platform === 'win32') {
|
|
2502
2501
|
await exec('taskkill', ['/F', '/IM', 'node.exe', '/FI', 'WINDOWTITLE eq shadow-brain*'], { reject: false });
|
|
@@ -2664,5 +2663,436 @@ program.addCommand(askCmd);
|
|
|
2664
2663
|
program.addCommand(exportCmd);
|
|
2665
2664
|
program.addCommand(importCmd);
|
|
2666
2665
|
program.addCommand(pluginCmd);
|
|
2666
|
+
// ── v5.1.1 Commands ─────────────────────────────────────────────────────
|
|
2667
|
+
const lspCmd = new Command('lsp')
|
|
2668
|
+
.description('Start the built-in Language Server Protocol server')
|
|
2669
|
+
.option('--port <port>', 'TCP port for LSP server', '7343')
|
|
2670
|
+
.option('--stdio', 'Use stdio transport instead of TCP')
|
|
2671
|
+
.action(async (opts) => {
|
|
2672
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — LSP Server`));
|
|
2673
|
+
try {
|
|
2674
|
+
const { LSPServer } = await import('./brain/lsp-server.js');
|
|
2675
|
+
const lsp = new LSPServer(process.cwd());
|
|
2676
|
+
if (opts.stdio) {
|
|
2677
|
+
console.log(chalk.cyan(' Starting LSP server (stdio mode)...'));
|
|
2678
|
+
lsp.startStdio();
|
|
2679
|
+
}
|
|
2680
|
+
else {
|
|
2681
|
+
const port = parseInt(opts.port, 10);
|
|
2682
|
+
console.log(chalk.cyan(` Starting LSP server on port ${port}...`));
|
|
2683
|
+
lsp.startTCP(port);
|
|
2684
|
+
}
|
|
2685
|
+
console.log(chalk.green(' LSP server running. Connect your editor.'));
|
|
2686
|
+
console.log(chalk.dim(' Features: diagnostics, hover, completions, code actions'));
|
|
2687
|
+
}
|
|
2688
|
+
catch (err) {
|
|
2689
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2690
|
+
process.exit(1);
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2693
|
+
const finetuneCmd = new Command('fine-tune')
|
|
2694
|
+
.description('Train the brain on your codebase patterns')
|
|
2695
|
+
.addCommand(new Command('train')
|
|
2696
|
+
.description('Train on the current project')
|
|
2697
|
+
.option('--dir <directory>', 'Directory to train on')
|
|
2698
|
+
.action(async (opts) => {
|
|
2699
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Fine-Tuning Engine`));
|
|
2700
|
+
try {
|
|
2701
|
+
const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
|
|
2702
|
+
const ft = new FineTuningEngine(opts.dir || process.cwd());
|
|
2703
|
+
console.log(chalk.cyan(' Training on codebase patterns...'));
|
|
2704
|
+
await ft.trainOnDirectory(opts.dir);
|
|
2705
|
+
await ft.save();
|
|
2706
|
+
const stats = ft.stats();
|
|
2707
|
+
console.log(chalk.green(' Training complete!'));
|
|
2708
|
+
console.log(chalk.dim(' Patterns: ') + chalk.cyan(String(stats.totalPatterns)));
|
|
2709
|
+
console.log(chalk.dim(' Training points: ') + chalk.cyan(String(stats.totalTrainingPoints)));
|
|
2710
|
+
console.log(chalk.dim(' Models: ') + chalk.cyan(String(stats.models)));
|
|
2711
|
+
console.log(chalk.dim(' Accuracy: ') + chalk.cyan(`${(stats.accuracy * 100).toFixed(1)}%`));
|
|
2712
|
+
}
|
|
2713
|
+
catch (err) {
|
|
2714
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2715
|
+
}
|
|
2716
|
+
}))
|
|
2717
|
+
.addCommand(new Command('stats')
|
|
2718
|
+
.description('Show fine-tuning statistics')
|
|
2719
|
+
.action(async () => {
|
|
2720
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Fine-Tune Stats`));
|
|
2721
|
+
try {
|
|
2722
|
+
const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
|
|
2723
|
+
const ft = new FineTuningEngine(process.cwd());
|
|
2724
|
+
await ft.load();
|
|
2725
|
+
const stats = ft.stats();
|
|
2726
|
+
console.log(chalk.dim(' Patterns: ') + chalk.cyan(String(stats.totalPatterns)));
|
|
2727
|
+
console.log(chalk.dim(' Training points: ') + chalk.cyan(String(stats.totalTrainingPoints)));
|
|
2728
|
+
console.log(chalk.dim(' Models: ') + chalk.cyan(String(stats.models)));
|
|
2729
|
+
console.log(chalk.dim(' Accuracy: ') + chalk.cyan(`${(stats.accuracy * 100).toFixed(1)}%`));
|
|
2730
|
+
if (stats.lastTrainingRun) {
|
|
2731
|
+
console.log(chalk.dim(' Last trained: ') + chalk.cyan(new Date(stats.lastTrainingRun).toLocaleString()));
|
|
2732
|
+
}
|
|
2733
|
+
if (stats.topPatterns.length > 0) {
|
|
2734
|
+
console.log(chalk.dim('\n Top patterns:'));
|
|
2735
|
+
for (const p of stats.topPatterns.slice(0, 5)) {
|
|
2736
|
+
console.log(` ${chalk.yellow(p.type)} (${p.count}x)`);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
catch (err) {
|
|
2741
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2742
|
+
}
|
|
2743
|
+
}))
|
|
2744
|
+
.addCommand(new Command('suggest')
|
|
2745
|
+
.description('Get code suggestions based on trained model')
|
|
2746
|
+
.argument('[context]', 'Context for suggestions', '')
|
|
2747
|
+
.action(async (context) => {
|
|
2748
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Code Suggestions`));
|
|
2749
|
+
try {
|
|
2750
|
+
const { FineTuningEngine } = await import('./brain/fine-tuning-engine.js');
|
|
2751
|
+
const ft = new FineTuningEngine(process.cwd());
|
|
2752
|
+
await ft.load();
|
|
2753
|
+
const suggestions = ft.suggest(context || 'general');
|
|
2754
|
+
if (suggestions.length === 0) {
|
|
2755
|
+
console.log(chalk.dim(' No suggestions yet. Run: shadow-brain fine-tune train'));
|
|
2756
|
+
return;
|
|
2757
|
+
}
|
|
2758
|
+
for (const s of suggestions) {
|
|
2759
|
+
console.log(` ${chalk.cyan(s.category)} ${chalk.white(s.text)} (${chalk.dim(`${(s.confidence * 100).toFixed(0)}%`)})`);
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
catch (err) {
|
|
2763
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2764
|
+
}
|
|
2765
|
+
}));
|
|
2766
|
+
const cacheCmd = new Command('cache')
|
|
2767
|
+
.description('Smart cache management')
|
|
2768
|
+
.addCommand(new Command('stats')
|
|
2769
|
+
.description('Show cache statistics')
|
|
2770
|
+
.action(async () => {
|
|
2771
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Smart Cache`));
|
|
2772
|
+
try {
|
|
2773
|
+
const { SmartCache } = await import('./brain/smart-cache.js');
|
|
2774
|
+
const cache = new SmartCache();
|
|
2775
|
+
const stats = cache.stats();
|
|
2776
|
+
console.log(chalk.dim(' Hot: ') + chalk.red(String(stats.hotEntries)));
|
|
2777
|
+
console.log(chalk.dim(' Warm: ') + chalk.yellow(String(stats.warmEntries)));
|
|
2778
|
+
console.log(chalk.dim(' Cold: ') + chalk.blue(String(stats.coldEntries)));
|
|
2779
|
+
console.log(chalk.dim(' Hit rate: ') + chalk.green(`${(stats.hitRate * 100).toFixed(1)}%`));
|
|
2780
|
+
console.log(chalk.dim(' Memory: ') + chalk.cyan(`${stats.memoryUsageMB} MB`));
|
|
2781
|
+
console.log(chalk.dim(' Prefetch hits: ') + chalk.cyan(String(stats.prefetchHits)));
|
|
2782
|
+
}
|
|
2783
|
+
catch (err) {
|
|
2784
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2785
|
+
}
|
|
2786
|
+
}));
|
|
2787
|
+
const intentCmd = new Command('intent')
|
|
2788
|
+
.description('Developer intent prediction')
|
|
2789
|
+
.addCommand(new Command('stats')
|
|
2790
|
+
.description('Show intent prediction statistics')
|
|
2791
|
+
.action(async () => {
|
|
2792
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Intent Engine`));
|
|
2793
|
+
try {
|
|
2794
|
+
const { IntentEngine } = await import('./brain/intent-engine.js');
|
|
2795
|
+
const ie = new IntentEngine();
|
|
2796
|
+
const stats = ie.stats();
|
|
2797
|
+
console.log(chalk.dim(' Predictions: ') + chalk.cyan(String(stats.totalPredictions)));
|
|
2798
|
+
console.log(chalk.dim(' Accuracy: ') + chalk.green(`${(stats.accuracy * 100).toFixed(1)}%`));
|
|
2799
|
+
console.log(chalk.dim(' Avg confidence: ') + chalk.cyan(`${(stats.avgConfidence * 100).toFixed(1)}%`));
|
|
2800
|
+
if (stats.topIntents.length > 0) {
|
|
2801
|
+
console.log(chalk.dim('\n Top intents:'));
|
|
2802
|
+
for (const a of stats.topIntents.slice(0, 5)) {
|
|
2803
|
+
console.log(` ${chalk.yellow(a.action)}: ${a.count}`);
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
catch (err) {
|
|
2808
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2809
|
+
}
|
|
2810
|
+
}));
|
|
2811
|
+
const dnaCmd = new Command('dna')
|
|
2812
|
+
.description('Code DNA fingerprinting and style analysis')
|
|
2813
|
+
.addCommand(new Command('profile')
|
|
2814
|
+
.description('Build a DNA profile of the project')
|
|
2815
|
+
.option('--name <name>', 'Profile name', 'default')
|
|
2816
|
+
.action(async (opts) => {
|
|
2817
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Code DNA`));
|
|
2818
|
+
try {
|
|
2819
|
+
const { CodeDNA } = await import('./brain/code-dna.js');
|
|
2820
|
+
const dna = new CodeDNA(process.cwd());
|
|
2821
|
+
console.log(chalk.cyan(' Building DNA profile...'));
|
|
2822
|
+
const profile = await dna.buildProfile(opts.name);
|
|
2823
|
+
console.log(chalk.green(' Profile built!'));
|
|
2824
|
+
console.log(chalk.dim(' Files analyzed: ') + chalk.cyan(String(profile.fileCount)));
|
|
2825
|
+
console.log(chalk.dim(' Genes tracked: ') + chalk.cyan(String(profile.genes.size)));
|
|
2826
|
+
console.log(chalk.dim('\n Gene highlights:'));
|
|
2827
|
+
for (const g of Array.from(profile.genes.values()).slice(0, 8)) {
|
|
2828
|
+
const bar = '█'.repeat(Math.round(g.value * 10)) + '░'.repeat(10 - Math.round(g.value * 10));
|
|
2829
|
+
console.log(` ${chalk.dim(g.category.padEnd(16))} ${chalk.yellow(g.trait.padEnd(24))} ${chalk.cyan(bar)} ${(g.value * 100).toFixed(0)}%`);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
catch (err) {
|
|
2833
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2834
|
+
}
|
|
2835
|
+
}))
|
|
2836
|
+
.addCommand(new Command('consistency')
|
|
2837
|
+
.description('Check code style consistency')
|
|
2838
|
+
.action(async () => {
|
|
2839
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Style Consistency`));
|
|
2840
|
+
try {
|
|
2841
|
+
const { CodeDNA } = await import('./brain/code-dna.js');
|
|
2842
|
+
const dna = new CodeDNA(process.cwd());
|
|
2843
|
+
console.log(chalk.cyan(' Analyzing consistency...'));
|
|
2844
|
+
const report = await dna.checkConsistency();
|
|
2845
|
+
const scoreColor = report.overall > 0.8 ? chalk.green : report.overall > 0.6 ? chalk.yellow : chalk.red;
|
|
2846
|
+
console.log(chalk.dim(' Overall score: ') + scoreColor(`${(report.overall * 100).toFixed(1)}%`));
|
|
2847
|
+
if (report.recommendations.length > 0) {
|
|
2848
|
+
console.log(chalk.dim('\n Recommendations:'));
|
|
2849
|
+
for (const r of report.recommendations.slice(0, 5)) {
|
|
2850
|
+
console.log(` ${chalk.yellow('→')} ${r}`);
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
catch (err) {
|
|
2855
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2856
|
+
}
|
|
2857
|
+
}));
|
|
2858
|
+
const temporalCmd = new Command('temporal')
|
|
2859
|
+
.description('Temporal code evolution analysis')
|
|
2860
|
+
.addCommand(new Command('velocity')
|
|
2861
|
+
.description('Show development velocity')
|
|
2862
|
+
.action(async () => {
|
|
2863
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Velocity`));
|
|
2864
|
+
try {
|
|
2865
|
+
const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
|
|
2866
|
+
const ti = new TemporalIntelligence(process.cwd());
|
|
2867
|
+
const velocity = ti.getVelocity();
|
|
2868
|
+
const trendIcon = velocity.trend === 'accelerating' ? '🚀' : velocity.trend === 'stable' ? '→' : velocity.trend === 'decelerating' ? '↓' : '⏸';
|
|
2869
|
+
console.log(chalk.dim(' Daily events: ') + chalk.cyan(String(velocity.daily)));
|
|
2870
|
+
console.log(chalk.dim(' Weekly events: ') + chalk.cyan(String(velocity.weekly)));
|
|
2871
|
+
console.log(chalk.dim(' Monthly events: ') + chalk.cyan(String(velocity.monthly)));
|
|
2872
|
+
console.log(chalk.dim(' Trend: ') + chalk.yellow(`${trendIcon} ${velocity.trend} (${(velocity.trendConfidence * 100).toFixed(0)}%)`));
|
|
2873
|
+
}
|
|
2874
|
+
catch (err) {
|
|
2875
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2876
|
+
}
|
|
2877
|
+
}))
|
|
2878
|
+
.addCommand(new Command('hotfiles')
|
|
2879
|
+
.description('Show most active files')
|
|
2880
|
+
.option('-n <count>', 'Number of files', '10')
|
|
2881
|
+
.action(async (opts) => {
|
|
2882
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Hot Files`));
|
|
2883
|
+
try {
|
|
2884
|
+
const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
|
|
2885
|
+
const ti = new TemporalIntelligence(process.cwd());
|
|
2886
|
+
const hot = ti.getHotFiles(parseInt(opts.n || '10', 10));
|
|
2887
|
+
if (hot.length === 0) {
|
|
2888
|
+
console.log(chalk.dim(' No file history yet. Run analysis first.'));
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
for (const f of hot) {
|
|
2892
|
+
const bar = '█'.repeat(Math.round(f.hotness * 10)) + '░'.repeat(10 - Math.round(f.hotness * 10));
|
|
2893
|
+
console.log(` ${chalk.red(bar)} ${chalk.dim(`${(f.hotness * 100).toFixed(0)}%`.padStart(4))} ${chalk.white(f.file)}`);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
catch (err) {
|
|
2897
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2898
|
+
}
|
|
2899
|
+
}))
|
|
2900
|
+
.addCommand(new Command('predict-bugs')
|
|
2901
|
+
.description('Predict bug-prone files')
|
|
2902
|
+
.option('-n <count>', 'Number of predictions', '10')
|
|
2903
|
+
.action(async (opts) => {
|
|
2904
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Bug Predictions`));
|
|
2905
|
+
try {
|
|
2906
|
+
const { TemporalIntelligence } = await import('./brain/temporal-intelligence.js');
|
|
2907
|
+
const ti = new TemporalIntelligence(process.cwd());
|
|
2908
|
+
const bugs = ti.predictBugs(parseInt(opts.n || '10', 10));
|
|
2909
|
+
if (bugs.length === 0) {
|
|
2910
|
+
console.log(chalk.dim(' No predictions available. Need more history.'));
|
|
2911
|
+
return;
|
|
2912
|
+
}
|
|
2913
|
+
for (const b of bugs) {
|
|
2914
|
+
const risk = b.probability > 0.7 ? chalk.red : b.probability > 0.4 ? chalk.yellow : chalk.green;
|
|
2915
|
+
console.log(` ${risk(`${(b.probability * 100).toFixed(0)}%`.padStart(4))} ${chalk.white(b.file)}`);
|
|
2916
|
+
for (const f of b.factors) {
|
|
2917
|
+
console.log(` ${chalk.dim('→')} ${chalk.dim(f)}`);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
catch (err) {
|
|
2922
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2923
|
+
}
|
|
2924
|
+
}));
|
|
2925
|
+
program.addCommand(lspCmd);
|
|
2926
|
+
program.addCommand(finetuneCmd);
|
|
2927
|
+
program.addCommand(cacheCmd);
|
|
2928
|
+
program.addCommand(intentCmd);
|
|
2929
|
+
program.addCommand(dnaCmd);
|
|
2930
|
+
program.addCommand(temporalCmd);
|
|
2931
|
+
// ─── v5.2.0 — SUBCONSCIOUS SINGULARITY ──────────────────────────────────────
|
|
2932
|
+
const attachCmd = new Command('attach-all')
|
|
2933
|
+
.description('Auto-detect every installed AI agent and install Shadow Brain hooks (v5.2.0)')
|
|
2934
|
+
.argument('[project-dir]', 'Project directory', process.cwd())
|
|
2935
|
+
.option('--dry-run', 'Show what would be attached without installing')
|
|
2936
|
+
.action(async (projectDir, opts) => {
|
|
2937
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Universal Bootstrap`));
|
|
2938
|
+
const { getHookInstaller } = await import('./brain/session-hooks.js');
|
|
2939
|
+
const installer = getHookInstaller();
|
|
2940
|
+
if (opts.dryRun) {
|
|
2941
|
+
const detected = await installer.detectInstalled(projectDir);
|
|
2942
|
+
console.log(chalk.cyan(` Detected agents: ${detected.length}`));
|
|
2943
|
+
for (const agent of detected) {
|
|
2944
|
+
console.log(` ${chalk.green('✓')} ${agent}`);
|
|
2945
|
+
}
|
|
2946
|
+
console.log(chalk.dim('\n Run without --dry-run to install hooks.'));
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
const report = await installer.attachAll(projectDir);
|
|
2950
|
+
console.log(chalk.cyan(` Detected: ${report.detected.length} agents (${report.durationMs}ms)`));
|
|
2951
|
+
for (const agent of report.attached) {
|
|
2952
|
+
console.log(` ${chalk.green('✓')} ${agent} attached`);
|
|
2953
|
+
}
|
|
2954
|
+
for (const fail of report.failed) {
|
|
2955
|
+
console.log(` ${chalk.red('✗')} ${fail.agent}: ${fail.reason}`);
|
|
2956
|
+
}
|
|
2957
|
+
console.log(chalk.dim(`\n ${report.hooks.length} hook(s) installed across ${report.attached.length} agent(s).`));
|
|
2958
|
+
console.log(chalk.dim(' Every agent will now call Shadow Brain on session start.'));
|
|
2959
|
+
});
|
|
2960
|
+
const subconsciousCmd = new Command('subconscious')
|
|
2961
|
+
.description('Manage the Subconscious Engine — proactive context injection')
|
|
2962
|
+
.addCommand(new Command('inject')
|
|
2963
|
+
.description('Generate + emit a session-start briefing for the current agent')
|
|
2964
|
+
.option('--agent <agent>', 'Agent tool name (auto-detected if omitted)')
|
|
2965
|
+
.option('--task <hint>', 'Current task hint for similarity search')
|
|
2966
|
+
.option('--json', 'Output JSON instead of formatted text')
|
|
2967
|
+
.action(async (opts) => {
|
|
2968
|
+
const { getSubconscious } = await import('./brain/subconscious.js');
|
|
2969
|
+
const { GlobalBrain } = await import('./brain/global-brain.js');
|
|
2970
|
+
const projectDir = process.cwd();
|
|
2971
|
+
const projectId = GlobalBrain.projectIdFor(projectDir);
|
|
2972
|
+
let agentTool = opts.agent;
|
|
2973
|
+
if (!agentTool) {
|
|
2974
|
+
const detected = await detectRunningAgents(projectDir);
|
|
2975
|
+
agentTool = detected[0]?.name || 'claude-code';
|
|
2976
|
+
}
|
|
2977
|
+
const sub = getSubconscious();
|
|
2978
|
+
const briefing = await sub.generateBriefing({
|
|
2979
|
+
agentTool,
|
|
2980
|
+
projectDir,
|
|
2981
|
+
projectId,
|
|
2982
|
+
currentTask: opts.task,
|
|
2983
|
+
});
|
|
2984
|
+
if (opts.json) {
|
|
2985
|
+
console.log(JSON.stringify(briefing, null, 2));
|
|
2986
|
+
}
|
|
2987
|
+
else {
|
|
2988
|
+
console.log(briefing.fullText || chalk.dim('(no relevant context yet — brain is empty)'));
|
|
2989
|
+
}
|
|
2990
|
+
}))
|
|
2991
|
+
.addCommand(new Command('status')
|
|
2992
|
+
.description('Show subconscious engine stats')
|
|
2993
|
+
.action(async () => {
|
|
2994
|
+
const { getSubconscious } = await import('./brain/subconscious.js');
|
|
2995
|
+
const stats = getSubconscious().getStats();
|
|
2996
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Subconscious Stats`));
|
|
2997
|
+
console.log(` Total briefings: ${chalk.cyan(stats.totalBriefings)}`);
|
|
2998
|
+
console.log(` Avg tokens: ${chalk.cyan(stats.avgTokenCount.toFixed(0))}`);
|
|
2999
|
+
console.log(` Avg generation: ${chalk.cyan(stats.avgGenerationMs.toFixed(1) + 'ms')}`);
|
|
3000
|
+
console.log(` By agent:`);
|
|
3001
|
+
for (const [agent, count] of Object.entries(stats.byAgent)) {
|
|
3002
|
+
console.log(` ${chalk.dim('•')} ${agent}: ${count}`);
|
|
3003
|
+
}
|
|
3004
|
+
}))
|
|
3005
|
+
.addCommand(new Command('configure')
|
|
3006
|
+
.description('Update subconscious config')
|
|
3007
|
+
.option('--budget <tokens>', 'Token budget (default 2000)')
|
|
3008
|
+
.option('--lookback <hours>', 'Lookback hours (default 24)')
|
|
3009
|
+
.option('--threshold <score>', 'Relevance threshold 0-1')
|
|
3010
|
+
.option('--enable', 'Enable subconscious')
|
|
3011
|
+
.option('--disable', 'Disable subconscious')
|
|
3012
|
+
.action(async (opts) => {
|
|
3013
|
+
const { getSubconscious } = await import('./brain/subconscious.js');
|
|
3014
|
+
const sub = getSubconscious();
|
|
3015
|
+
const patch = {};
|
|
3016
|
+
if (opts.budget)
|
|
3017
|
+
patch.tokenBudget = parseInt(opts.budget, 10);
|
|
3018
|
+
if (opts.lookback)
|
|
3019
|
+
patch.lookbackHours = parseFloat(opts.lookback);
|
|
3020
|
+
if (opts.threshold)
|
|
3021
|
+
patch.relevanceThreshold = parseFloat(opts.threshold);
|
|
3022
|
+
if (opts.enable)
|
|
3023
|
+
patch.enabled = true;
|
|
3024
|
+
if (opts.disable)
|
|
3025
|
+
patch.enabled = false;
|
|
3026
|
+
sub.configure(patch);
|
|
3027
|
+
console.log(chalk.green(' ✓ Subconscious config updated.'));
|
|
3028
|
+
console.log(JSON.stringify(sub.getConfig(), null, 2));
|
|
3029
|
+
}));
|
|
3030
|
+
const globalBrainCmd = new Command('global')
|
|
3031
|
+
.description('Manage the Singleton Global Brain — one brain, all projects, all agents')
|
|
3032
|
+
.addCommand(new Command('stats')
|
|
3033
|
+
.description('Show global brain stats')
|
|
3034
|
+
.action(async () => {
|
|
3035
|
+
const { getGlobalBrain } = await import('./brain/global-brain.js');
|
|
3036
|
+
const brain = getGlobalBrain();
|
|
3037
|
+
await brain.init();
|
|
3038
|
+
const s = brain.getStats();
|
|
3039
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Global Brain`));
|
|
3040
|
+
console.log(` Projects: ${chalk.cyan(s.totalProjects)}`);
|
|
3041
|
+
console.log(` Agents: ${chalk.cyan(s.totalAgents)}`);
|
|
3042
|
+
console.log(` Entries: ${chalk.cyan(s.totalEntries)}`);
|
|
3043
|
+
console.log(` Size: ${chalk.cyan(s.totalSizeMB.toFixed(2) + ' MB')}`);
|
|
3044
|
+
console.log(` Hit rate: ${chalk.cyan((s.hitRate * 100).toFixed(1) + '%')} (${s.hits}/${s.hits + s.misses})`);
|
|
3045
|
+
console.log(` Pending: ${chalk.cyan(s.pendingWrites)}`);
|
|
3046
|
+
console.log(` Uptime: ${chalk.cyan(Math.round(s.uptime / 1000) + 's')}`);
|
|
3047
|
+
console.log(` Last sync: ${chalk.dim(s.lastSync.toISOString())}`);
|
|
3048
|
+
}))
|
|
3049
|
+
.addCommand(new Command('recall')
|
|
3050
|
+
.description('Recall entries from the global brain — works across projects + agents')
|
|
3051
|
+
.option('-q, --query <text>', 'Keyword search')
|
|
3052
|
+
.option('--agent <agent>', 'Filter by agent tool')
|
|
3053
|
+
.option('--category <cat>', 'Filter by category')
|
|
3054
|
+
.option('--limit <n>', 'Max results', '20')
|
|
3055
|
+
.option('--json', 'Output JSON')
|
|
3056
|
+
.action(async (opts) => {
|
|
3057
|
+
const { getGlobalBrain } = await import('./brain/global-brain.js');
|
|
3058
|
+
const brain = getGlobalBrain();
|
|
3059
|
+
await brain.init();
|
|
3060
|
+
const results = brain.recall({
|
|
3061
|
+
keywords: opts.query ? opts.query.split(/\s+/) : undefined,
|
|
3062
|
+
agentTool: opts.agent,
|
|
3063
|
+
category: opts.category,
|
|
3064
|
+
limit: parseInt(opts.limit, 10),
|
|
3065
|
+
});
|
|
3066
|
+
if (opts.json) {
|
|
3067
|
+
console.log(JSON.stringify(results, null, 2));
|
|
3068
|
+
return;
|
|
3069
|
+
}
|
|
3070
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Global Recall (${results.length})`));
|
|
3071
|
+
for (const r of results) {
|
|
3072
|
+
console.log(` ${chalk.cyan('[' + r.agentTool + ']')} ${chalk.dim(r.category)} ${chalk.white(r.content.slice(0, 100))}`);
|
|
3073
|
+
}
|
|
3074
|
+
}))
|
|
3075
|
+
.addCommand(new Command('cache')
|
|
3076
|
+
.description('Show L0 in-memory cache stats')
|
|
3077
|
+
.action(async () => {
|
|
3078
|
+
const { getAllCacheStats } = await import('./brain/l0-cache.js');
|
|
3079
|
+
const all = getAllCacheStats();
|
|
3080
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — L0 Cache`));
|
|
3081
|
+
for (const [name, s] of Object.entries(all)) {
|
|
3082
|
+
console.log(` ${chalk.cyan(name)}: ${s.entries} entries, ${(s.bytesUsed / 1024).toFixed(1)} KB / ${(s.bytesLimit / 1024 / 1024).toFixed(0)} MB, ${(s.hitRate * 100).toFixed(1)}% hits, ${s.avgAccessNs.toFixed(0)}ns avg`);
|
|
3083
|
+
}
|
|
3084
|
+
}))
|
|
3085
|
+
.addCommand(new Command('sync')
|
|
3086
|
+
.description('Force flush of pending writes to disk')
|
|
3087
|
+
.action(async () => {
|
|
3088
|
+
const { getGlobalBrain } = await import('./brain/global-brain.js');
|
|
3089
|
+
const brain = getGlobalBrain();
|
|
3090
|
+
await brain.init();
|
|
3091
|
+
await brain.sync();
|
|
3092
|
+
console.log(chalk.green(' ✓ Synced to disk.'));
|
|
3093
|
+
}));
|
|
3094
|
+
program.addCommand(attachCmd);
|
|
3095
|
+
program.addCommand(subconsciousCmd);
|
|
3096
|
+
program.addCommand(globalBrainCmd);
|
|
2667
3097
|
program.parse();
|
|
2668
3098
|
//# sourceMappingURL=cli.js.map
|