@theihtisham/agent-shadow-brain 4.0.2 → 5.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.
- package/README.md +288 -154
- package/dist/brain/collective-learning.d.ts +54 -0
- package/dist/brain/collective-learning.d.ts.map +1 -0
- package/dist/brain/collective-learning.js +357 -0
- package/dist/brain/collective-learning.js.map +1 -0
- package/dist/brain/consensus-engine.d.ts +65 -0
- package/dist/brain/consensus-engine.d.ts.map +1 -0
- package/dist/brain/consensus-engine.js +385 -0
- package/dist/brain/consensus-engine.js.map +1 -0
- package/dist/brain/context-recall.d.ts +49 -0
- package/dist/brain/context-recall.d.ts.map +1 -0
- package/dist/brain/context-recall.js +502 -0
- package/dist/brain/context-recall.js.map +1 -0
- package/dist/brain/hierarchical-memory.d.ts +49 -0
- package/dist/brain/hierarchical-memory.d.ts.map +1 -0
- package/dist/brain/hierarchical-memory.js +451 -0
- package/dist/brain/hierarchical-memory.js.map +1 -0
- package/dist/brain/orchestrator.d.ts +34 -0
- package/dist/brain/orchestrator.d.ts.map +1 -1
- package/dist/brain/orchestrator.js +83 -1
- package/dist/brain/orchestrator.js.map +1 -1
- package/dist/cli.js +253 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -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
|
|
2
|
+
// src/cli.ts — CLI entry point for Shadow Brain v5.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 = '
|
|
10
|
+
const VERSION = '5.0.0';
|
|
11
11
|
const config = new Conf({
|
|
12
12
|
projectName: 'shadow-brain',
|
|
13
13
|
defaults: {
|
|
@@ -2179,11 +2179,256 @@ const v4Cmd = new Command('v4')
|
|
|
2179
2179
|
process.exit(1);
|
|
2180
2180
|
}
|
|
2181
2181
|
});
|
|
2182
|
+
// ─── v5.0.0 INFINITE INTELLIGENCE COMMANDS ──────────────────────────────────
|
|
2183
|
+
const memoryCmd = new Command('memory')
|
|
2184
|
+
.description('v5.0.0 — Hierarchical infinite memory (raw → summary → pattern → principle)')
|
|
2185
|
+
.addCommand(new Command('stats')
|
|
2186
|
+
.description('Show hierarchical memory statistics')
|
|
2187
|
+
.action(async () => {
|
|
2188
|
+
const { HierarchicalMemory } = await import('./brain/hierarchical-memory.js');
|
|
2189
|
+
const hm = new HierarchicalMemory();
|
|
2190
|
+
const stats = hm.stats();
|
|
2191
|
+
console.log(chalk.magenta.bold(`\n HIERARCHICAL MEMORY STATS\n`));
|
|
2192
|
+
console.log(chalk ` {cyan Raw entries:} ${stats.rawCount}`);
|
|
2193
|
+
console.log(chalk ` {cyan Summary entries:} ${stats.summaryCount}`);
|
|
2194
|
+
console.log(chalk ` {cyan Pattern entries:} ${stats.patternCount}`);
|
|
2195
|
+
console.log(chalk ` {cyan Principle entries:} ${stats.principleCount}`);
|
|
2196
|
+
console.log(chalk ` {cyan Total entries:} ${stats.totalEntries}`);
|
|
2197
|
+
console.log(chalk ` {cyan Total size:} ${stats.totalSizeMB.toFixed(3)} MB`);
|
|
2198
|
+
console.log(chalk ` {cyan Compression ratio:} ${(stats.compressionRatio * 100).toFixed(1)}%`);
|
|
2199
|
+
console.log(chalk ` {cyan Retention:} INFINITE`);
|
|
2200
|
+
console.log(chalk ` {cyan Drill-down depth:} ${stats.drillDownDepth} tiers\n`);
|
|
2201
|
+
}))
|
|
2202
|
+
.addCommand(new Command('search')
|
|
2203
|
+
.description('Search hierarchical memory')
|
|
2204
|
+
.argument('<query>', 'Search query')
|
|
2205
|
+
.action(async (query) => {
|
|
2206
|
+
const { HierarchicalMemory } = await import('./brain/hierarchical-memory.js');
|
|
2207
|
+
const hm = new HierarchicalMemory();
|
|
2208
|
+
const results = hm.search(query, 10);
|
|
2209
|
+
if (results.length === 0) {
|
|
2210
|
+
console.log(chalk.yellow(' No results found.'));
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
console.log(chalk.magenta.bold(`\n MEMORY SEARCH: "${query}"\n`));
|
|
2214
|
+
for (const entry of results) {
|
|
2215
|
+
const tierColors = { raw: 'dim', summary: 'cyan', pattern: 'magenta', principle: 'green' };
|
|
2216
|
+
const color = tierColors[entry.tier] || 'white';
|
|
2217
|
+
console.log(chalk ` {${color} [${entry.tier.toUpperCase()}]} ${entry.content.slice(0, 120).replace(/\n/g, ' ')}...`);
|
|
2218
|
+
console.log(chalk ` {dim Category: ${entry.category} | Confidence: ${(entry.confidence * 100).toFixed(0)}% | Importance: ${entry.importance.toFixed(2)}}`);
|
|
2219
|
+
}
|
|
2220
|
+
console.log();
|
|
2221
|
+
}))
|
|
2222
|
+
.addCommand(new Command('drilldown')
|
|
2223
|
+
.description('Drill down from a higher-tier entry to raw sources')
|
|
2224
|
+
.argument('<id>', 'Entry ID (first 8 chars)')
|
|
2225
|
+
.action(async (id) => {
|
|
2226
|
+
const { HierarchicalMemory } = await import('./brain/hierarchical-memory.js');
|
|
2227
|
+
const hm = new HierarchicalMemory();
|
|
2228
|
+
const allEntries = [...hm.getByTier('principle'), ...hm.getByTier('pattern'), ...hm.getByTier('summary')];
|
|
2229
|
+
const match = allEntries.find(e => e.id.startsWith(id));
|
|
2230
|
+
if (!match) {
|
|
2231
|
+
console.log(chalk.yellow(' Entry not found.'));
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
const levels = hm.drillDown(match.id);
|
|
2235
|
+
console.log(chalk.magenta.bold(`\n DRILL-DOWN from [${match.tier}] ${match.content.slice(0, 80)}...\n`));
|
|
2236
|
+
for (let i = 0; i < levels.length; i++) {
|
|
2237
|
+
const tier = levels[i][0]?.tier ?? '?';
|
|
2238
|
+
console.log(chalk ` {cyan Level ${i} [${tier}]}: ${levels[i].length} entries`);
|
|
2239
|
+
for (const entry of levels[i].slice(0, 3)) {
|
|
2240
|
+
console.log(chalk ` {dim ${entry.content.slice(0, 100).replace(/\n/g, ' ')}}`);
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
console.log();
|
|
2244
|
+
}));
|
|
2245
|
+
const recallCmd = new Command('recall')
|
|
2246
|
+
.description('v5.0.0 — Context-triggered associative recall')
|
|
2247
|
+
.addCommand(new Command('activate')
|
|
2248
|
+
.description('Activate memories for a specific file/context')
|
|
2249
|
+
.argument('<file>', 'File path or context description')
|
|
2250
|
+
.option('-c, --category <cat>', 'Category filter')
|
|
2251
|
+
.option('-k, --keywords <kw>', 'Comma-separated keywords')
|
|
2252
|
+
.action(async (file, opts) => {
|
|
2253
|
+
const { HierarchicalMemory } = await import('./brain/hierarchical-memory.js');
|
|
2254
|
+
const { ContextRecall } = await import('./brain/context-recall.js');
|
|
2255
|
+
const hm = new HierarchicalMemory();
|
|
2256
|
+
const cr = new ContextRecall(hm);
|
|
2257
|
+
const now = new Date();
|
|
2258
|
+
const results = cr.recall({
|
|
2259
|
+
currentFile: file,
|
|
2260
|
+
currentCategory: opts.category || 'general',
|
|
2261
|
+
recentEdits: [],
|
|
2262
|
+
projectType: 'auto',
|
|
2263
|
+
keywords: opts.keywords?.split(',') || [],
|
|
2264
|
+
timeOfDay: now.getHours(),
|
|
2265
|
+
dayOfWeek: now.getDay(),
|
|
2266
|
+
}, 15);
|
|
2267
|
+
if (results.length === 0) {
|
|
2268
|
+
console.log(chalk.yellow(' No memories activated for this context.'));
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
console.log(chalk.magenta.bold(`\n CONTEXT RECALL: ${file}\n`));
|
|
2272
|
+
console.log(chalk ` {cyan Activated ${results.length} memories}\n`);
|
|
2273
|
+
for (const r of results) {
|
|
2274
|
+
const pct = (r.relevanceScore * 100).toFixed(0);
|
|
2275
|
+
const triggers = r.activatedTriggers.join(', ');
|
|
2276
|
+
console.log(chalk ` {green ${pct}%} [{dim ${r.entry.tier}}] ${r.entry.content.slice(0, 100).replace(/\n/g, ' ')}`);
|
|
2277
|
+
console.log(chalk ` {dim Triggers: ${triggers}}`);
|
|
2278
|
+
}
|
|
2279
|
+
console.log();
|
|
2280
|
+
}))
|
|
2281
|
+
.addCommand(new Command('summary')
|
|
2282
|
+
.description('Get a summary of what the brain knows about current context')
|
|
2283
|
+
.argument('<file>', 'File path')
|
|
2284
|
+
.action(async (file) => {
|
|
2285
|
+
const { HierarchicalMemory } = await import('./brain/hierarchical-memory.js');
|
|
2286
|
+
const { ContextRecall } = await import('./brain/context-recall.js');
|
|
2287
|
+
const hm = new HierarchicalMemory();
|
|
2288
|
+
const cr = new ContextRecall(hm);
|
|
2289
|
+
const summary = cr.getContextSummary({ currentFile: file });
|
|
2290
|
+
console.log(chalk.magenta.bold(`\n CONTEXT SUMMARY\n`));
|
|
2291
|
+
console.log(summary);
|
|
2292
|
+
console.log();
|
|
2293
|
+
}));
|
|
2294
|
+
const consensusCmd = new Command('consensus')
|
|
2295
|
+
.description('v5.0.0 — Multi-agent consensus protocol')
|
|
2296
|
+
.addCommand(new Command('stats')
|
|
2297
|
+
.description('Show consensus engine statistics')
|
|
2298
|
+
.action(async () => {
|
|
2299
|
+
const { ConsensusEngine } = await import('./brain/consensus-engine.js');
|
|
2300
|
+
const ce = new ConsensusEngine();
|
|
2301
|
+
const stats = ce.getStats();
|
|
2302
|
+
console.log(chalk.magenta.bold(`\n CONSENSUS ENGINE STATS\n`));
|
|
2303
|
+
console.log(chalk ` {cyan Total proposals:} ${stats.totalProposals}`);
|
|
2304
|
+
console.log(chalk ` {cyan Accepted:} ${stats.acceptedCount}`);
|
|
2305
|
+
console.log(chalk ` {cyan Rejected:} ${stats.rejectedCount}`);
|
|
2306
|
+
console.log(chalk ` {cyan Conflicts:} ${stats.conflictCount}`);
|
|
2307
|
+
console.log(chalk ` {cyan Pending:} ${stats.pendingCount}`);
|
|
2308
|
+
console.log(chalk ` {cyan Avg agreement:} ${(stats.averageAgreement * 100).toFixed(1)}%`);
|
|
2309
|
+
console.log(chalk ` {cyan Known agents:} ${stats.agentCount}`);
|
|
2310
|
+
if (stats.topTrustedAgents.length > 0) {
|
|
2311
|
+
console.log(chalk `\n {bold Top Trusted Agents:}`);
|
|
2312
|
+
for (const agent of stats.topTrustedAgents) {
|
|
2313
|
+
console.log(chalk ` {green ${agent.agent}}: trust=${(agent.score * 100).toFixed(0)}%, accuracy=${(agent.accuracy * 100).toFixed(0)}%`);
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
console.log();
|
|
2317
|
+
}))
|
|
2318
|
+
.addCommand(new Command('trust')
|
|
2319
|
+
.description('Show trust scores for all agents')
|
|
2320
|
+
.action(async () => {
|
|
2321
|
+
const { ConsensusEngine } = await import('./brain/consensus-engine.js');
|
|
2322
|
+
const ce = new ConsensusEngine();
|
|
2323
|
+
const scores = ce.getTrustScores();
|
|
2324
|
+
if (scores.length === 0) {
|
|
2325
|
+
console.log(chalk.yellow(' No trust scores recorded yet.'));
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
console.log(chalk.magenta.bold(`\n AGENT TRUST SCORES\n`));
|
|
2329
|
+
for (const t of scores) {
|
|
2330
|
+
const bar = '█'.repeat(Math.round(t.score * 20));
|
|
2331
|
+
console.log(chalk ` {cyan ${t.agent.slice(0, 20)}}: ${(t.score * 100).toFixed(0)}% ${bar}`);
|
|
2332
|
+
}
|
|
2333
|
+
console.log();
|
|
2334
|
+
}));
|
|
2335
|
+
const collectiveCmd = new Command('collective')
|
|
2336
|
+
.description('v5.0.0 — Cross-project collective learning')
|
|
2337
|
+
.addCommand(new Command('stats')
|
|
2338
|
+
.description('Show collective learning statistics')
|
|
2339
|
+
.action(async () => {
|
|
2340
|
+
const { CollectiveLearning } = await import('./brain/collective-learning.js');
|
|
2341
|
+
const cl = new CollectiveLearning(process.cwd());
|
|
2342
|
+
const stats = cl.getStats();
|
|
2343
|
+
console.log(chalk.magenta.bold(`\n COLLECTIVE LEARNING STATS\n`));
|
|
2344
|
+
console.log(chalk ` {cyan Total rules:} ${stats.totalRules}`);
|
|
2345
|
+
console.log(chalk ` {cyan Verified rules:} ${stats.verifiedRules}`);
|
|
2346
|
+
console.log(chalk ` {cyan Avg accuracy:} ${(stats.averageAccuracy * 100).toFixed(1)}%`);
|
|
2347
|
+
console.log(chalk ` {cyan Consensus rate:} ${(stats.consensusRate * 100).toFixed(1)}%`);
|
|
2348
|
+
console.log(chalk ` {cyan Network size:} ${stats.networkSize} projects`);
|
|
2349
|
+
console.log(chalk ` {cyan Recent adoptions:} ${stats.recentAdoptions}`);
|
|
2350
|
+
if (stats.topCategories.length > 0) {
|
|
2351
|
+
console.log(chalk `\n {bold Top Categories:}`);
|
|
2352
|
+
for (const cat of stats.topCategories.slice(0, 5)) {
|
|
2353
|
+
console.log(chalk ` ${cat.category}: ${cat.count} rules`);
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
console.log();
|
|
2357
|
+
}))
|
|
2358
|
+
.addCommand(new Command('rules')
|
|
2359
|
+
.description('List verified collective rules')
|
|
2360
|
+
.option('-c, --category <cat>', 'Filter by category')
|
|
2361
|
+
.action(async (opts) => {
|
|
2362
|
+
const { CollectiveLearning } = await import('./brain/collective-learning.js');
|
|
2363
|
+
const cl = new CollectiveLearning(process.cwd());
|
|
2364
|
+
const rules = cl.getVerifiedRules();
|
|
2365
|
+
if (rules.length === 0) {
|
|
2366
|
+
console.log(chalk.yellow(' No verified collective rules yet.'));
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
console.log(chalk.magenta.bold(`\n VERIFIED COLLECTIVE RULES (${rules.length})\n`));
|
|
2370
|
+
for (const rule of rules.slice(0, 20)) {
|
|
2371
|
+
const acc = (rule.accuracy * 100).toFixed(0);
|
|
2372
|
+
const viral = (rule.viralScore * 100).toFixed(0);
|
|
2373
|
+
console.log(chalk ` {green [${rule.category}]} ${rule.content.slice(0, 100)}`);
|
|
2374
|
+
console.log(chalk ` {dim Accuracy: ${acc}% | Viral: ${viral}% | Verified by: ${rule.verifiedBy.length} projects}`);
|
|
2375
|
+
}
|
|
2376
|
+
console.log();
|
|
2377
|
+
}));
|
|
2378
|
+
const v5Cmd = new Command('v5')
|
|
2379
|
+
.description('Run ALL v5.0.0 infinite intelligence analyses at once')
|
|
2380
|
+
.argument('[project-dir]', 'Project directory', process.cwd())
|
|
2381
|
+
.option('--json', 'Output as JSON')
|
|
2382
|
+
.action(async (projectDir, opts) => {
|
|
2383
|
+
const brainConfig = mergeConfig({ projectDir, watchMode: false });
|
|
2384
|
+
const orchestrator = new Orchestrator(brainConfig);
|
|
2385
|
+
try {
|
|
2386
|
+
console.log(chalk.magenta.bold(`\n SHADOW BRAIN v${VERSION} — v5.0.0 Infinite Intelligence Full Scan\n`));
|
|
2387
|
+
console.log(chalk.cyan(' Running ALL modules: v3.0.0 + v4.0.0 + v5.0.0...'));
|
|
2388
|
+
console.log(chalk.dim(' Hierarchical Memory | Context Recall | Consensus | Collective Learning'));
|
|
2389
|
+
console.log(chalk.dim(' TurboQuant | SSSP | CAIP | Self-Evolution | Predictive | Knowledge Graph | Swarm | Adversarial\n'));
|
|
2390
|
+
const results = await orchestrator.runFullHyperAnalysis();
|
|
2391
|
+
// v5.0.0 Infinite Intelligence results
|
|
2392
|
+
const status = orchestrator.getStatus();
|
|
2393
|
+
const hmStats = status.hierarchicalMemoryStats;
|
|
2394
|
+
const crStats = status.contextRecallStats;
|
|
2395
|
+
const ceStats = status.consensusStats;
|
|
2396
|
+
const clStats = status.collectiveLearningStats;
|
|
2397
|
+
console.log(chalk.bold(' v5.0.0 Infinite Intelligence:'));
|
|
2398
|
+
if (hmStats) {
|
|
2399
|
+
console.log(chalk ` {magenta Hierarchical Memory:} ${hmStats.totalEntries} entries (${hmStats.rawCount} raw, ${hmStats.summaryCount} summary, ${hmStats.patternCount} pattern, ${hmStats.principleCount} principle)`);
|
|
2400
|
+
console.log(chalk ` {magenta Compression:} ${(hmStats.compressionRatio * 100).toFixed(1)}% | Retention: INFINITE`);
|
|
2401
|
+
}
|
|
2402
|
+
if (crStats) {
|
|
2403
|
+
console.log(chalk ` {magenta Context Recall:} ${crStats.triggerCount} learned triggers, ${crStats.linkCount} activation links`);
|
|
2404
|
+
}
|
|
2405
|
+
if (ceStats) {
|
|
2406
|
+
console.log(chalk ` {magenta Consensus:} ${ceStats.totalProposals} proposals, ${ceStats.acceptedCount} accepted, ${ceStats.agentCount} agents`);
|
|
2407
|
+
}
|
|
2408
|
+
if (clStats) {
|
|
2409
|
+
console.log(chalk ` {magenta Collective:} ${clStats.totalRules} rules, ${clStats.verifiedRules} verified, ${(clStats.averageAccuracy * 100).toFixed(0)}% avg accuracy`);
|
|
2410
|
+
}
|
|
2411
|
+
// v4.0.0 results
|
|
2412
|
+
console.log(chalk.bold('\n v4.0.0 Hyper-Intelligence:'));
|
|
2413
|
+
const turbo = results.turboMemoryStats;
|
|
2414
|
+
console.log(chalk ` {cyan TurboQuant:} ${turbo ? `${turbo.totalEntries} entries, ${(turbo.compressionRatio * 100).toFixed(1)}% compressed` : 'N/A'}`);
|
|
2415
|
+
console.log(chalk ` {cyan Evolution:} gen ${results.evolutionSnapshot?.generation ?? 0}, fitness ${results.evolutionSnapshot?.bestFitness?.toFixed(3) ?? 'N/A'}`);
|
|
2416
|
+
// v3.0.0 results
|
|
2417
|
+
console.log(chalk.bold(`\n v3.0.0 Findings: ${results.total}\n`));
|
|
2418
|
+
if (opts.json) {
|
|
2419
|
+
console.log(JSON.stringify({ v3: results, v5: { hmStats, crStats, ceStats, clStats } }, null, 2));
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
catch (err) {
|
|
2423
|
+
console.error(chalk.red(' Error:'), err.message);
|
|
2424
|
+
process.exit(1);
|
|
2425
|
+
}
|
|
2426
|
+
});
|
|
2182
2427
|
// ─── MAIN ─────────────────────────────────────────────────────────────────────
|
|
2183
2428
|
const program = new Command();
|
|
2184
2429
|
program
|
|
2185
2430
|
.name('shadow-brain')
|
|
2186
|
-
.description('Shadow Brain
|
|
2431
|
+
.description('Shadow Brain v5.0.0 — Infinite Intelligence Layer for AI Coding Agents with Hierarchical Memory, Context Recall, Consensus & Collective Learning')
|
|
2187
2432
|
.version(VERSION);
|
|
2188
2433
|
program.addCommand(startCmd);
|
|
2189
2434
|
program.addCommand(reviewCmd);
|
|
@@ -2238,5 +2483,10 @@ program.addCommand(graphCmd);
|
|
|
2238
2483
|
program.addCommand(swarmCmd);
|
|
2239
2484
|
program.addCommand(defenseCmd);
|
|
2240
2485
|
program.addCommand(v4Cmd);
|
|
2486
|
+
program.addCommand(memoryCmd);
|
|
2487
|
+
program.addCommand(recallCmd);
|
|
2488
|
+
program.addCommand(consensusCmd);
|
|
2489
|
+
program.addCommand(collectiveCmd);
|
|
2490
|
+
program.addCommand(v5Cmd);
|
|
2241
2491
|
program.parse();
|
|
2242
2492
|
//# sourceMappingURL=cli.js.map
|