@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.
- package/README.md +575 -292
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/brain/auto-setup.d.ts +54 -0
- package/dist/brain/auto-setup.d.ts.map +1 -0
- package/dist/brain/auto-setup.js +660 -0
- package/dist/brain/auto-setup.js.map +1 -0
- package/dist/brain/brain-portability.d.ts +81 -0
- package/dist/brain/brain-portability.d.ts.map +1 -0
- package/dist/brain/brain-portability.js +329 -0
- package/dist/brain/brain-portability.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/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/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 +12 -0
- package/dist/brain/mcp-server.d.ts.map +1 -1
- package/dist/brain/mcp-server.js +396 -37
- 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/plugin-system.d.ts +97 -0
- package/dist/brain/plugin-system.d.ts.map +1 -0
- package/dist/brain/plugin-system.js +404 -0
- package/dist/brain/plugin-system.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/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 +444 -3
- package/dist/cli.js.map +1 -1
- package/dist/dashboard/server.d.ts +4 -0
- package/dist/dashboard/server.d.ts.map +1 -1
- package/dist/dashboard/server.js +453 -330
- package/dist/dashboard/server.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +284 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +28 -4
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: {
|
|
@@ -2428,7 +2428,7 @@ const v5Cmd = new Command('v5')
|
|
|
2428
2428
|
const program = new Command();
|
|
2429
2429
|
program
|
|
2430
2430
|
.name('shadow-brain')
|
|
2431
|
-
.description('Shadow Brain v5.0.
|
|
2431
|
+
.description('Shadow Brain v5.0.1 — Infinite Intelligence Layer for AI Coding Agents with Zero-Config Setup, MCP Server, Rich Dashboard, Hierarchical Memory, Context Recall, Consensus & Collective Learning')
|
|
2432
2432
|
.version(VERSION);
|
|
2433
2433
|
program.addCommand(startCmd);
|
|
2434
2434
|
program.addCommand(reviewCmd);
|
|
@@ -2488,5 +2488,446 @@ program.addCommand(recallCmd);
|
|
|
2488
2488
|
program.addCommand(consensusCmd);
|
|
2489
2489
|
program.addCommand(collectiveCmd);
|
|
2490
2490
|
program.addCommand(v5Cmd);
|
|
2491
|
+
// ─── v5.0.1 COMMANDS ────────────────────────────────────────────────────────────
|
|
2492
|
+
// off — Stop Shadow Brain (alias for killing the process, clean shutdown)
|
|
2493
|
+
const offCmd = new Command('off')
|
|
2494
|
+
.description('Stop Shadow Brain and clean up')
|
|
2495
|
+
.action(async () => {
|
|
2496
|
+
console.log(chalk.magenta.bold('\n SHADOW BRAIN v' + VERSION + ' — Shutting down'));
|
|
2497
|
+
try {
|
|
2498
|
+
const { default: execaDefault } = await import('execa');
|
|
2499
|
+
const exec = execaDefault;
|
|
2500
|
+
try {
|
|
2501
|
+
if (process.platform === 'win32') {
|
|
2502
|
+
await exec('taskkill', ['/F', '/IM', 'node.exe', '/FI', 'WINDOWTITLE eq shadow-brain*'], { reject: false });
|
|
2503
|
+
}
|
|
2504
|
+
else {
|
|
2505
|
+
await exec('pkill', ['-f', 'shadow-brain'], { reject: false });
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
catch { /* no process found */ }
|
|
2509
|
+
console.log(chalk.green(' Shadow Brain stopped successfully.'));
|
|
2510
|
+
}
|
|
2511
|
+
catch {
|
|
2512
|
+
console.log(chalk.yellow(' No running Shadow Brain instance found.'));
|
|
2513
|
+
}
|
|
2514
|
+
process.exit(0);
|
|
2515
|
+
});
|
|
2516
|
+
// ask — Natural language query against brain state
|
|
2517
|
+
const askCmd = new Command('ask')
|
|
2518
|
+
.description('Ask Shadow Brain a question about your project')
|
|
2519
|
+
.argument('<question>', 'Natural language question')
|
|
2520
|
+
.option('-p, --provider <provider>', 'LLM provider')
|
|
2521
|
+
.option('-m, --model <model>', 'LLM model')
|
|
2522
|
+
.action(async (question, opts) => {
|
|
2523
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Ask`));
|
|
2524
|
+
console.log(chalk.dim(' Question: ') + chalk.cyan(question));
|
|
2525
|
+
try {
|
|
2526
|
+
const brainConfig = mergeConfig({ ...opts, projectDir: process.cwd() });
|
|
2527
|
+
const orchestrator = new Orchestrator(brainConfig);
|
|
2528
|
+
await orchestrator.start();
|
|
2529
|
+
// Get project context and build a prompt
|
|
2530
|
+
const status = orchestrator.getStatus();
|
|
2531
|
+
const prompt = `You are Shadow Brain, an expert AI coding intelligence layer. Based on the following project context, answer the user's question concisely.\n\nProject: ${status.projectDir}\nProvider: ${status.provider}\nHealth Score: ${status.healthScore || 'N/A'}\nInsights Generated: ${status.insightsGenerated}\nFiles Reviewed: ${status.filesReviewed}\n\nQuestion: ${question}\n\nAnswer:`;
|
|
2532
|
+
// Use the LLM client directly via the analyzer's prompt builder
|
|
2533
|
+
const llm = new (await import('./brain/llm-client.js')).LLMClient({
|
|
2534
|
+
provider: brainConfig.provider,
|
|
2535
|
+
apiKey: brainConfig.apiKey,
|
|
2536
|
+
model: brainConfig.model,
|
|
2537
|
+
});
|
|
2538
|
+
const answer = await llm.complete(prompt);
|
|
2539
|
+
console.log(chalk.green('\n ' + answer));
|
|
2540
|
+
await orchestrator.stop();
|
|
2541
|
+
}
|
|
2542
|
+
catch (err) {
|
|
2543
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2544
|
+
process.exit(1);
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
// export — Export brain state
|
|
2548
|
+
const exportCmd = new Command('export')
|
|
2549
|
+
.description('Export full brain state to a portable JSON file')
|
|
2550
|
+
.option('-o, --output <dir>', 'Output directory for the export')
|
|
2551
|
+
.action(async (opts) => {
|
|
2552
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Export`));
|
|
2553
|
+
try {
|
|
2554
|
+
const { BrainPortability } = await import('./brain/brain-portability.js');
|
|
2555
|
+
const portability = new BrainPortability(process.cwd(), opts.output);
|
|
2556
|
+
const result = await portability.exportBrain();
|
|
2557
|
+
console.log(chalk.green(' Brain state exported successfully!'));
|
|
2558
|
+
console.log(chalk.dim(' File: ') + chalk.cyan(result.filePath));
|
|
2559
|
+
console.log(chalk.dim(' Size: ') + chalk.cyan((result.sizeBytes / 1024).toFixed(1) + ' KB'));
|
|
2560
|
+
console.log(chalk.dim(' SHA-256: ') + chalk.dim(result.checksum.slice(0, 16) + '...'));
|
|
2561
|
+
}
|
|
2562
|
+
catch (err) {
|
|
2563
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2564
|
+
process.exit(1);
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
// import — Import brain state
|
|
2568
|
+
const importCmd = new Command('import')
|
|
2569
|
+
.description('Import brain state from an export file')
|
|
2570
|
+
.argument('<file>', 'Path to the export JSON file')
|
|
2571
|
+
.option('--merge', 'Merge with existing state instead of replacing')
|
|
2572
|
+
.option('--skip <modules>', 'Comma-separated list of modules to skip')
|
|
2573
|
+
.action(async (file, opts) => {
|
|
2574
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Import`));
|
|
2575
|
+
try {
|
|
2576
|
+
const { BrainPortability } = await import('./brain/brain-portability.js');
|
|
2577
|
+
const portability = new BrainPortability(process.cwd());
|
|
2578
|
+
const result = await portability.importBrain(file, {
|
|
2579
|
+
merge: opts.merge || false,
|
|
2580
|
+
skipModules: opts.skip?.split(',') || [],
|
|
2581
|
+
});
|
|
2582
|
+
console.log(chalk.green(' Brain state imported successfully!'));
|
|
2583
|
+
console.log(chalk.dim(' Imported: ') + chalk.green(result.imported.join(', ') || 'none'));
|
|
2584
|
+
console.log(chalk.dim(' Skipped: ') + chalk.yellow(result.skipped.join(', ') || 'none'));
|
|
2585
|
+
if (result.errors.length > 0) {
|
|
2586
|
+
console.log(chalk.dim(' Errors: ') + chalk.red(result.errors.join('; ')));
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
catch (err) {
|
|
2590
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2591
|
+
process.exit(1);
|
|
2592
|
+
}
|
|
2593
|
+
});
|
|
2594
|
+
// plugin — Manage plugins
|
|
2595
|
+
const pluginCmd = new Command('plugin')
|
|
2596
|
+
.description('Manage Shadow Brain plugins')
|
|
2597
|
+
.addCommand(new Command('list')
|
|
2598
|
+
.description('List installed plugins')
|
|
2599
|
+
.action(async () => {
|
|
2600
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Plugins`));
|
|
2601
|
+
try {
|
|
2602
|
+
const { PluginSystem } = await import('./brain/plugin-system.js');
|
|
2603
|
+
const ps = new PluginSystem(process.cwd());
|
|
2604
|
+
await ps.loadAll();
|
|
2605
|
+
const plugins = ps.getPlugins();
|
|
2606
|
+
if (plugins.length === 0) {
|
|
2607
|
+
console.log(chalk.dim(' No plugins found.'));
|
|
2608
|
+
console.log(chalk.dim(' Add plugins to: ') + chalk.cyan('shadow-brain-plugins/'));
|
|
2609
|
+
return;
|
|
2610
|
+
}
|
|
2611
|
+
for (const p of plugins) {
|
|
2612
|
+
const status = p.enabled ? chalk.green('active') : chalk.red('disabled');
|
|
2613
|
+
console.log(` ${status} ${chalk.bold(p.manifest.name)} v${p.manifest.version} — ${chalk.dim(p.manifest.description)}`);
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
catch (err) {
|
|
2617
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2618
|
+
}
|
|
2619
|
+
}))
|
|
2620
|
+
.addCommand(new Command('create')
|
|
2621
|
+
.description('Create a new plugin from template')
|
|
2622
|
+
.argument('<name>', 'Plugin name')
|
|
2623
|
+
.action(async (name) => {
|
|
2624
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Create Plugin`));
|
|
2625
|
+
try {
|
|
2626
|
+
const { PluginSystem } = await import('./brain/plugin-system.js');
|
|
2627
|
+
const ps = new PluginSystem(process.cwd());
|
|
2628
|
+
const dir = ps.createTemplate(name);
|
|
2629
|
+
console.log(chalk.green(' Plugin template created!'));
|
|
2630
|
+
console.log(chalk.dim(' Directory: ') + chalk.cyan(dir));
|
|
2631
|
+
console.log(chalk.dim(' Edit manifest.json and index.js to customize.'));
|
|
2632
|
+
}
|
|
2633
|
+
catch (err) {
|
|
2634
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2635
|
+
process.exit(1);
|
|
2636
|
+
}
|
|
2637
|
+
}))
|
|
2638
|
+
.addCommand(new Command('stats')
|
|
2639
|
+
.description('Show plugin system statistics')
|
|
2640
|
+
.action(async () => {
|
|
2641
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — Plugin Stats`));
|
|
2642
|
+
try {
|
|
2643
|
+
const { PluginSystem } = await import('./brain/plugin-system.js');
|
|
2644
|
+
const ps = new PluginSystem(process.cwd());
|
|
2645
|
+
await ps.loadAll();
|
|
2646
|
+
const stats = ps.getStats();
|
|
2647
|
+
console.log(chalk.dim(' Total plugins: ') + chalk.cyan(String(stats.totalPlugins)));
|
|
2648
|
+
console.log(chalk.dim(' Enabled: ') + chalk.green(String(stats.enabledPlugins)));
|
|
2649
|
+
console.log(chalk.dim(' Disabled: ') + chalk.red(String(stats.disabledPlugins)));
|
|
2650
|
+
console.log(chalk.dim(' Total hooks: ') + chalk.cyan(String(stats.totalHooks)));
|
|
2651
|
+
if (Object.keys(stats.hooksByEvent).length > 0) {
|
|
2652
|
+
console.log(chalk.dim(' Hooks by event:'));
|
|
2653
|
+
for (const [event, count] of Object.entries(stats.hooksByEvent)) {
|
|
2654
|
+
console.log(` ${chalk.cyan(event)}: ${count}`);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
catch (err) {
|
|
2659
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2660
|
+
}
|
|
2661
|
+
}));
|
|
2662
|
+
program.addCommand(offCmd);
|
|
2663
|
+
program.addCommand(askCmd);
|
|
2664
|
+
program.addCommand(exportCmd);
|
|
2665
|
+
program.addCommand(importCmd);
|
|
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);
|
|
2491
2932
|
program.parse();
|
|
2492
2933
|
//# sourceMappingURL=cli.js.map
|