@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.
- package/README.md +443 -602
- package/dist/brain/accessibility-checker.d.ts +10 -0
- package/dist/brain/accessibility-checker.d.ts.map +1 -0
- package/dist/brain/accessibility-checker.js +379 -0
- package/dist/brain/accessibility-checker.js.map +1 -0
- package/dist/brain/adversarial-defense.d.ts +57 -0
- package/dist/brain/adversarial-defense.d.ts.map +1 -0
- package/dist/brain/adversarial-defense.js +303 -0
- package/dist/brain/adversarial-defense.js.map +1 -0
- package/dist/brain/api-contract-analyzer.d.ts +19 -0
- package/dist/brain/api-contract-analyzer.d.ts.map +1 -0
- package/dist/brain/api-contract-analyzer.js +251 -0
- package/dist/brain/api-contract-analyzer.js.map +1 -0
- package/dist/brain/ast-analyzer.d.ts +23 -0
- package/dist/brain/ast-analyzer.d.ts.map +1 -0
- package/dist/brain/ast-analyzer.js +462 -0
- package/dist/brain/ast-analyzer.js.map +1 -0
- package/dist/brain/code-age-analyzer.d.ts +11 -0
- package/dist/brain/code-age-analyzer.d.ts.map +1 -0
- package/dist/brain/code-age-analyzer.js +152 -0
- package/dist/brain/code-age-analyzer.js.map +1 -0
- package/dist/brain/cognitive-load.d.ts +27 -0
- package/dist/brain/cognitive-load.d.ts.map +1 -0
- package/dist/brain/cognitive-load.js +304 -0
- package/dist/brain/cognitive-load.js.map +1 -0
- package/dist/brain/config-drift-detector.d.ts +13 -0
- package/dist/brain/config-drift-detector.d.ts.map +1 -0
- package/dist/brain/config-drift-detector.js +198 -0
- package/dist/brain/config-drift-detector.js.map +1 -0
- package/dist/brain/cross-agent-protocol.d.ts +48 -0
- package/dist/brain/cross-agent-protocol.d.ts.map +1 -0
- package/dist/brain/cross-agent-protocol.js +306 -0
- package/dist/brain/cross-agent-protocol.js.map +1 -0
- package/dist/brain/dead-code-eliminator.d.ts +16 -0
- package/dist/brain/dead-code-eliminator.d.ts.map +1 -0
- package/dist/brain/dead-code-eliminator.js +359 -0
- package/dist/brain/dead-code-eliminator.js.map +1 -0
- package/dist/brain/env-analyzer.d.ts +13 -0
- package/dist/brain/env-analyzer.d.ts.map +1 -0
- package/dist/brain/env-analyzer.js +277 -0
- package/dist/brain/env-analyzer.js.map +1 -0
- package/dist/brain/i18n-detector.d.ts +12 -0
- package/dist/brain/i18n-detector.d.ts.map +1 -0
- package/dist/brain/i18n-detector.js +242 -0
- package/dist/brain/i18n-detector.js.map +1 -0
- package/dist/brain/influence-map.d.ts +31 -0
- package/dist/brain/influence-map.d.ts.map +1 -0
- package/dist/brain/influence-map.js +375 -0
- package/dist/brain/influence-map.js.map +1 -0
- package/dist/brain/knowledge-graph.d.ts +56 -0
- package/dist/brain/knowledge-graph.d.ts.map +1 -0
- package/dist/brain/knowledge-graph.js +427 -0
- package/dist/brain/knowledge-graph.js.map +1 -0
- package/dist/brain/learning-engine.d.ts +11 -0
- package/dist/brain/learning-engine.d.ts.map +1 -1
- package/dist/brain/learning-engine.js +44 -1
- package/dist/brain/learning-engine.js.map +1 -1
- package/dist/brain/license-compliance.d.ts +13 -0
- package/dist/brain/license-compliance.d.ts.map +1 -0
- package/dist/brain/license-compliance.js +213 -0
- package/dist/brain/license-compliance.js.map +1 -0
- package/dist/brain/llm-client.d.ts.map +1 -1
- package/dist/brain/llm-client.js +3 -0
- package/dist/brain/llm-client.js.map +1 -1
- package/dist/brain/mutation-advisor.d.ts +11 -0
- package/dist/brain/mutation-advisor.d.ts.map +1 -0
- package/dist/brain/mutation-advisor.js +154 -0
- package/dist/brain/mutation-advisor.js.map +1 -0
- package/dist/brain/neural-mesh.d.ts +9 -1
- package/dist/brain/neural-mesh.d.ts.map +1 -1
- package/dist/brain/neural-mesh.js +75 -16
- package/dist/brain/neural-mesh.js.map +1 -1
- package/dist/brain/orchestrator.d.ts +71 -2
- package/dist/brain/orchestrator.d.ts.map +1 -1
- package/dist/brain/orchestrator.js +383 -3
- package/dist/brain/orchestrator.js.map +1 -1
- package/dist/brain/pattern-memory.d.ts +8 -3
- package/dist/brain/pattern-memory.d.ts.map +1 -1
- package/dist/brain/pattern-memory.js +71 -3
- package/dist/brain/pattern-memory.js.map +1 -1
- package/dist/brain/predictive-engine.d.ts +45 -0
- package/dist/brain/predictive-engine.d.ts.map +1 -0
- package/dist/brain/predictive-engine.js +238 -0
- package/dist/brain/predictive-engine.js.map +1 -0
- package/dist/brain/security-audit.d.ts +20 -0
- package/dist/brain/security-audit.d.ts.map +1 -0
- package/dist/brain/security-audit.js +340 -0
- package/dist/brain/security-audit.js.map +1 -0
- package/dist/brain/self-evolution.d.ts +53 -0
- package/dist/brain/self-evolution.d.ts.map +1 -0
- package/dist/brain/self-evolution.js +278 -0
- package/dist/brain/self-evolution.js.map +1 -0
- package/dist/brain/sssp-router.d.ts +58 -0
- package/dist/brain/sssp-router.d.ts.map +1 -0
- package/dist/brain/sssp-router.js +295 -0
- package/dist/brain/sssp-router.js.map +1 -0
- package/dist/brain/swarm-intelligence.d.ts +48 -0
- package/dist/brain/swarm-intelligence.d.ts.map +1 -0
- package/dist/brain/swarm-intelligence.js +215 -0
- package/dist/brain/swarm-intelligence.js.map +1 -0
- package/dist/brain/turbo-memory.d.ts +56 -0
- package/dist/brain/turbo-memory.d.ts.map +1 -0
- package/dist/brain/turbo-memory.js +388 -0
- package/dist/brain/turbo-memory.js.map +1 -0
- package/dist/cli.js +744 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +422 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/dashboard.d.ts.map +1 -1
- package/dist/ui/dashboard.js +20 -3
- package/dist/ui/dashboard.js.map +1 -1
- package/package.json +16 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/brain/orchestrator.ts — Central brain loop: watchers → analyzer → adapters
|
|
2
|
-
//
|
|
2
|
+
// v4.0.0 — Hyper-Intelligence Edition
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
4
|
import * as crypto from 'crypto';
|
|
5
5
|
import { LLMClient } from './llm-client.js';
|
|
@@ -29,9 +29,29 @@ import { MCPServer } from './mcp-server.js';
|
|
|
29
29
|
import { TeamMode } from './team-mode.js';
|
|
30
30
|
import { MultiProjectManager } from './multi-project.js';
|
|
31
31
|
import { NeuralMesh } from './neural-mesh.js';
|
|
32
|
+
// v3.0.0 Hyper-Intelligence Modules
|
|
33
|
+
import { ASTAnalyzer } from './ast-analyzer.js';
|
|
34
|
+
import { AccessibilityChecker } from './accessibility-checker.js';
|
|
35
|
+
import { I18nDetector } from './i18n-detector.js';
|
|
36
|
+
import { DeadCodeEliminator } from './dead-code-eliminator.js';
|
|
37
|
+
import { MutationAdvisor } from './mutation-advisor.js';
|
|
38
|
+
import { CodeAgeAnalyzer } from './code-age-analyzer.js';
|
|
39
|
+
import { APIContractAnalyzer } from './api-contract-analyzer.js';
|
|
40
|
+
import { EnvAnalyzer } from './env-analyzer.js';
|
|
41
|
+
import { LicenseCompliance } from './license-compliance.js';
|
|
42
|
+
import { ConfigDriftDetector } from './config-drift-detector.js';
|
|
32
43
|
import { FileWatcher } from '../watchers/file-watcher.js';
|
|
33
44
|
import { GitWatcher } from '../watchers/git-watcher.js';
|
|
34
45
|
import { createAdapter, detectRunningAgents } from '../adapters/index.js';
|
|
46
|
+
// v4.0.0 Hyper-Intelligence Modules
|
|
47
|
+
import { TurboMemory } from './turbo-memory.js';
|
|
48
|
+
import { SSSPRouter } from './sssp-router.js';
|
|
49
|
+
import { CrossAgentProtocol } from './cross-agent-protocol.js';
|
|
50
|
+
import { SelfEvolution } from './self-evolution.js';
|
|
51
|
+
import { PredictiveEngine } from './predictive-engine.js';
|
|
52
|
+
import { KnowledgeGraph } from './knowledge-graph.js';
|
|
53
|
+
import { SwarmIntelligence } from './swarm-intelligence.js';
|
|
54
|
+
import { AdversarialDefense } from './adversarial-defense.js';
|
|
35
55
|
export class Orchestrator extends EventEmitter {
|
|
36
56
|
constructor(config) {
|
|
37
57
|
super();
|
|
@@ -42,10 +62,12 @@ export class Orchestrator extends EventEmitter {
|
|
|
42
62
|
this.multiProject = null;
|
|
43
63
|
// v2.1.0 Quantum Neural Mesh
|
|
44
64
|
this.neuralMesh = null;
|
|
65
|
+
this.knowledgeGraph = null;
|
|
45
66
|
this.running = false;
|
|
46
67
|
this.analyzing = false;
|
|
47
68
|
this.pendingChanges = [];
|
|
48
69
|
this.debounceTimer = null;
|
|
70
|
+
this.evolutionTimer = null;
|
|
49
71
|
this.currentSession = null;
|
|
50
72
|
this.startTime = 0;
|
|
51
73
|
this.lastHealthScore = null;
|
|
@@ -87,6 +109,26 @@ export class Orchestrator extends EventEmitter {
|
|
|
87
109
|
this.perfProfiler = new PerformanceProfiler(config.projectDir);
|
|
88
110
|
this.contextCompletion = new ContextCompletionEngine(config.projectDir);
|
|
89
111
|
this.learningEngine = new LearningEngine(config.projectDir, this.llmClient);
|
|
112
|
+
// v3.0.0 Hyper-Intelligence Modules
|
|
113
|
+
this.astAnalyzer = new ASTAnalyzer(config.projectDir);
|
|
114
|
+
this.a11yChecker = new AccessibilityChecker(config.projectDir);
|
|
115
|
+
this.i18nDetector = new I18nDetector(config.projectDir);
|
|
116
|
+
this.deadCodeEliminator = new DeadCodeEliminator(config.projectDir);
|
|
117
|
+
this.mutationAdvisor = new MutationAdvisor(config.projectDir);
|
|
118
|
+
this.codeAgeAnalyzer = new CodeAgeAnalyzer(config.projectDir);
|
|
119
|
+
this.apiContractAnalyzer = new APIContractAnalyzer(config.projectDir);
|
|
120
|
+
this.envAnalyzer = new EnvAnalyzer(config.projectDir);
|
|
121
|
+
this.licenseCompliance = new LicenseCompliance(config.projectDir);
|
|
122
|
+
this.configDriftDetector = new ConfigDriftDetector(config.projectDir);
|
|
123
|
+
// v4.0.0 Hyper-Intelligence Modules
|
|
124
|
+
this.turboMemory = new TurboMemory();
|
|
125
|
+
this.ssspRouter = new SSSPRouter();
|
|
126
|
+
this.crossAgentProtocol = new CrossAgentProtocol();
|
|
127
|
+
this.selfEvolution = new SelfEvolution();
|
|
128
|
+
this.predictiveEngine = new PredictiveEngine();
|
|
129
|
+
this.knowledgeGraph = new KnowledgeGraph(config.projectDir);
|
|
130
|
+
this.swarmIntelligence = new SwarmIntelligence();
|
|
131
|
+
this.adversarialDefense = new AdversarialDefense();
|
|
90
132
|
// Load project config and setup notifier if configured
|
|
91
133
|
const projectConfig = this.projectConfigLoader.load();
|
|
92
134
|
if (projectConfig.notifications) {
|
|
@@ -147,6 +189,28 @@ export class Orchestrator extends EventEmitter {
|
|
|
147
189
|
});
|
|
148
190
|
}
|
|
149
191
|
this.emit('agents-detected', { adapters: this.adapters });
|
|
192
|
+
// v4.0.0: Start Cross-Agent Protocol
|
|
193
|
+
await this.crossAgentProtocol.start().catch(() => { });
|
|
194
|
+
// v4.0.0: Initialize swarm with project files
|
|
195
|
+
try {
|
|
196
|
+
const projectContext = await this.contextBuilder.build([]);
|
|
197
|
+
const projectFiles = projectContext.recentFiles || projectContext.structure || [];
|
|
198
|
+
if (projectFiles.length > 0) {
|
|
199
|
+
const paths = projectFiles.slice(0, 200).map((f) => typeof f === 'string' ? f : f.path || f.name || '');
|
|
200
|
+
this.swarmIntelligence.initialize(paths.filter(Boolean));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch { /* swarm init is best-effort */ }
|
|
204
|
+
// v4.0.0: Periodic self-evolution (every 30 minutes)
|
|
205
|
+
this.evolutionTimer = setInterval(async () => {
|
|
206
|
+
try {
|
|
207
|
+
await this.selfEvolution.evolve(this.currentSession?.insights || []);
|
|
208
|
+
if (this.knowledgeGraph) {
|
|
209
|
+
await this.knowledgeGraph.build().catch(() => { });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch { /* evolution runs silently */ }
|
|
213
|
+
}, 30 * 60 * 1000);
|
|
150
214
|
if (this.config.watchMode) {
|
|
151
215
|
this.setupWatchers();
|
|
152
216
|
this.running = true;
|
|
@@ -175,6 +239,12 @@ export class Orchestrator extends EventEmitter {
|
|
|
175
239
|
if (this.neuralMesh) {
|
|
176
240
|
await this.neuralMesh.disconnect().catch(() => { });
|
|
177
241
|
}
|
|
242
|
+
// v4.0.0: Cross-Agent Protocol shutdown + evolution timer cleanup
|
|
243
|
+
await this.crossAgentProtocol.stop().catch(() => { });
|
|
244
|
+
if (this.evolutionTimer) {
|
|
245
|
+
clearInterval(this.evolutionTimer);
|
|
246
|
+
this.evolutionTimer = null;
|
|
247
|
+
}
|
|
178
248
|
this.emit('stopped');
|
|
179
249
|
}
|
|
180
250
|
async reviewOnce() {
|
|
@@ -198,6 +268,28 @@ export class Orchestrator extends EventEmitter {
|
|
|
198
268
|
activity: activities,
|
|
199
269
|
agentMemory,
|
|
200
270
|
});
|
|
271
|
+
// v4.0.0: Adversarial defense — verify critical/high insights
|
|
272
|
+
const verifiedInsights = [];
|
|
273
|
+
for (const insight of insights) {
|
|
274
|
+
if (insight.priority === 'critical' || insight.priority === 'high') {
|
|
275
|
+
try {
|
|
276
|
+
const flag = await this.adversarialDefense.verifyInsight(insight, this.config.projectDir);
|
|
277
|
+
if (!flag || flag.verdict === 'real') {
|
|
278
|
+
verifiedInsights.push(insight);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
insight.adversarialFlag = flag;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
verifiedInsights.push(insight); // trust on error
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
verifiedInsights.push(insight);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
insights = verifiedInsights;
|
|
201
293
|
// ── Apply framework-specific rules ─────────────────────────────────
|
|
202
294
|
const framework = detectFramework(context.structure || [], {}, context.language || []);
|
|
203
295
|
if (framework !== 'unknown') {
|
|
@@ -264,6 +356,12 @@ export class Orchestrator extends EventEmitter {
|
|
|
264
356
|
this.neuralMesh.broadcastHealth(healthScore.overall);
|
|
265
357
|
}
|
|
266
358
|
}
|
|
359
|
+
// v4.0.0: Cross-agent broadcast
|
|
360
|
+
await this.crossAgentProtocol.broadcast('claude-code', {
|
|
361
|
+
type: 'insights',
|
|
362
|
+
insights: insights.slice(0, 5),
|
|
363
|
+
healthScore: healthScore.overall,
|
|
364
|
+
}).catch(() => { });
|
|
267
365
|
return insights;
|
|
268
366
|
}
|
|
269
367
|
/** Generate a full report (HTML/markdown/JSON) */
|
|
@@ -560,10 +658,87 @@ export class Orchestrator extends EventEmitter {
|
|
|
560
658
|
return [];
|
|
561
659
|
return this.neuralMesh.getConnectedNodes();
|
|
562
660
|
}
|
|
661
|
+
// ── v3.0.0: Hyper-Intelligence Methods ────────────────────────────────
|
|
662
|
+
/** AST-level complexity analysis — functions, cyclomatic complexity, nesting */
|
|
663
|
+
async runASTAnalysis(maxFiles) {
|
|
664
|
+
return this.astAnalyzer.analyzeProject(maxFiles);
|
|
665
|
+
}
|
|
666
|
+
/** WCAG accessibility audit for frontend code */
|
|
667
|
+
async runA11yCheck(maxFiles) {
|
|
668
|
+
return this.a11yChecker.analyzeProject(maxFiles);
|
|
669
|
+
}
|
|
670
|
+
/** Internationalization readiness detection */
|
|
671
|
+
async runI18nAnalysis(maxFiles) {
|
|
672
|
+
return this.i18nDetector.analyzeProject(maxFiles);
|
|
673
|
+
}
|
|
674
|
+
/** Dead code elimination — unreachable code, unused exports */
|
|
675
|
+
async runDeadCodeAnalysis(maxFiles) {
|
|
676
|
+
return this.deadCodeEliminator.analyzeProject(maxFiles);
|
|
677
|
+
}
|
|
678
|
+
/** Mutation testing advisor — suggests test-killing mutations */
|
|
679
|
+
async runMutationAnalysis(maxFiles) {
|
|
680
|
+
return this.mutationAdvisor.analyzeProject(maxFiles);
|
|
681
|
+
}
|
|
682
|
+
/** Code age analysis — stale files, ownership, freshness */
|
|
683
|
+
async runCodeAgeAnalysis() {
|
|
684
|
+
return this.codeAgeAnalyzer.analyzeProject();
|
|
685
|
+
}
|
|
686
|
+
/** API contract analysis — endpoint discovery and security audit */
|
|
687
|
+
async runAPIContractAnalysis(maxFiles) {
|
|
688
|
+
return this.apiContractAnalyzer.analyzeProject(maxFiles);
|
|
689
|
+
}
|
|
690
|
+
/** Environment variable analysis — secrets, validation, naming */
|
|
691
|
+
async runEnvAnalysis(maxFiles) {
|
|
692
|
+
return this.envAnalyzer.analyzeProject(maxFiles);
|
|
693
|
+
}
|
|
694
|
+
/** License compliance audit — restricted, copyleft, unknown licenses */
|
|
695
|
+
async runLicenseCompliance() {
|
|
696
|
+
return this.licenseCompliance.analyzeProject();
|
|
697
|
+
}
|
|
698
|
+
/** Configuration drift detection — missing configs, tsconfig, gitignore */
|
|
699
|
+
async runConfigDriftDetection() {
|
|
700
|
+
return this.configDriftDetector.analyzeProject();
|
|
701
|
+
}
|
|
702
|
+
/** Run ALL v3.0.0 + v4.0.0 hyper-intelligence analyses at once */
|
|
703
|
+
async runFullHyperAnalysis(opts) {
|
|
704
|
+
const maxFiles = opts?.maxFiles ?? 200;
|
|
705
|
+
const [ast, a11y, i18n, deadCode, mutation, codeAge, apiContract, env, license, configDrift] = await Promise.all([
|
|
706
|
+
this.runASTAnalysis(maxFiles).catch(() => []),
|
|
707
|
+
this.runA11yCheck(maxFiles).catch(() => []),
|
|
708
|
+
this.runI18nAnalysis(maxFiles).catch(() => []),
|
|
709
|
+
this.runDeadCodeAnalysis(maxFiles).catch(() => []),
|
|
710
|
+
this.runMutationAnalysis(maxFiles).catch(() => []),
|
|
711
|
+
this.runCodeAgeAnalysis().catch(() => []),
|
|
712
|
+
this.runAPIContractAnalysis(maxFiles).catch(() => []),
|
|
713
|
+
this.runEnvAnalysis(maxFiles).catch(() => []),
|
|
714
|
+
this.runLicenseCompliance().catch(() => []),
|
|
715
|
+
this.runConfigDriftDetection().catch(() => []),
|
|
716
|
+
]);
|
|
717
|
+
// v4.0.0 analyses
|
|
718
|
+
const turboMemoryStats = this.turboMemory?.stats() ?? null;
|
|
719
|
+
const swarmState = this.swarmIntelligence?.getState?.() ?? null;
|
|
720
|
+
const defenseStats = this.adversarialDefense?.getDefenseStats?.() ?? null;
|
|
721
|
+
const evolutionSnapshot = this.selfEvolution?.getSnapshot?.() ?? null;
|
|
722
|
+
let knowledgeGraphEntityCount = 0;
|
|
723
|
+
try {
|
|
724
|
+
if (this.knowledgeGraph) {
|
|
725
|
+
await this.knowledgeGraph.build();
|
|
726
|
+
const kgStats = this.knowledgeGraph.getStats?.();
|
|
727
|
+
knowledgeGraphEntityCount = kgStats?.entities ?? 0;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
catch { /* best-effort */ }
|
|
731
|
+
return {
|
|
732
|
+
ast, a11y, i18n, deadCode, mutation, codeAge, apiContract, env, license, configDrift,
|
|
733
|
+
turboMemoryStats, swarmState, defenseStats, evolutionSnapshot, knowledgeGraphEntityCount,
|
|
734
|
+
total: ast.length + a11y.length + i18n.length + deadCode.length + mutation.length +
|
|
735
|
+
codeAge.length + apiContract.length + env.length + license.length + configDrift.length,
|
|
736
|
+
};
|
|
737
|
+
}
|
|
563
738
|
getStatus() {
|
|
564
739
|
return {
|
|
565
740
|
running: this.running,
|
|
566
|
-
version: '
|
|
741
|
+
version: '4.0.0',
|
|
567
742
|
agents: this.adapters.map(a => `${a.displayName} (${a.name})`),
|
|
568
743
|
insightsGenerated: this.currentSession?.insights.length || 0,
|
|
569
744
|
filesReviewed: this.currentSession?.filesReviewed || 0,
|
|
@@ -591,6 +766,18 @@ export class Orchestrator extends EventEmitter {
|
|
|
591
766
|
neuralMeshEnabled: this.neuralMesh !== null,
|
|
592
767
|
meshNodeId: this.neuralMesh?.getNodeId()?.slice(0, 8) ?? null,
|
|
593
768
|
meshNodeCount: this.neuralMesh?.getConnectedNodes()?.length ?? 0,
|
|
769
|
+
// v3.0.0
|
|
770
|
+
hyperModules: [
|
|
771
|
+
'ast', 'a11y', 'i18n', 'dead-code', 'mutation', 'code-age',
|
|
772
|
+
'api-contract', 'env', 'license', 'config-drift',
|
|
773
|
+
],
|
|
774
|
+
// v4.0.0 Hyper-Intelligence
|
|
775
|
+
turboMemoryStats: this.turboMemory?.stats() ?? null,
|
|
776
|
+
caipConnectedAgents: this.crossAgentProtocol?.getConnectedAgents?.() ?? [],
|
|
777
|
+
evolutionGeneration: this.selfEvolution?.getSnapshot?.()?.generation ?? 0,
|
|
778
|
+
swarmConvergence: this.swarmIntelligence?.getState?.()?.convergenceScore ?? 0,
|
|
779
|
+
knowledgeGraphEntities: this.knowledgeGraph ? (this.knowledgeGraph.getStats?.()?.entityCount ?? 0) : 0,
|
|
780
|
+
adversarialStats: this.adversarialDefense?.getDefenseStats?.() ?? null,
|
|
594
781
|
};
|
|
595
782
|
}
|
|
596
783
|
setupWatchers() {
|
|
@@ -670,7 +857,7 @@ export class Orchestrator extends EventEmitter {
|
|
|
670
857
|
}
|
|
671
858
|
}
|
|
672
859
|
// Enhance with pattern memory insights
|
|
673
|
-
const patternInsights = this.patternMemory.getPatternInsights(changes);
|
|
860
|
+
const patternInsights = await this.patternMemory.getPatternInsights(changes);
|
|
674
861
|
insights.push(...patternInsights);
|
|
675
862
|
// ── Apply custom rules ────────────────────────────────────────
|
|
676
863
|
const customInsights = this.customRulesEngine.applyRules(changes);
|
|
@@ -683,6 +870,18 @@ export class Orchestrator extends EventEmitter {
|
|
|
683
870
|
for (const insight of insights) {
|
|
684
871
|
this.patternMemory.recordErrorPattern(insight);
|
|
685
872
|
}
|
|
873
|
+
// v4.0.0: Store patterns in TurboMemory for infinite retention
|
|
874
|
+
try {
|
|
875
|
+
for (const change of changes.slice(0, 30)) {
|
|
876
|
+
const text = change.path + ' ' + (change.content || '').slice(0, 200);
|
|
877
|
+
const vector = this.textToVector(text);
|
|
878
|
+
await this.turboMemory.store(change.path, vector, {
|
|
879
|
+
type: 'file_change',
|
|
880
|
+
insightCount: insights.length,
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
catch { /* TurboMemory storage is best-effort */ }
|
|
686
885
|
// ── v2.0.0: Super-Intelligence Enhancements ────────────────────
|
|
687
886
|
// Type safety analysis on changed TypeScript files
|
|
688
887
|
const tsFiles = changes.filter(c => c.path.endsWith('.ts') || c.path.endsWith('.tsx'));
|
|
@@ -731,6 +930,144 @@ export class Orchestrator extends EventEmitter {
|
|
|
731
930
|
}
|
|
732
931
|
}
|
|
733
932
|
catch { /* skip learning failures */ }
|
|
933
|
+
// ── v3.0.0: Hyper-Intelligence Enhancements ────────────────────
|
|
934
|
+
// AST complexity analysis on changed TypeScript files
|
|
935
|
+
if (tsFiles.length > 0) {
|
|
936
|
+
try {
|
|
937
|
+
for (const f of tsFiles.slice(0, 5)) {
|
|
938
|
+
const funcs = this.astAnalyzer.extractFunctionInfo(f.path);
|
|
939
|
+
for (const fn of funcs) {
|
|
940
|
+
if (fn.cyclomaticComplexity > 10) {
|
|
941
|
+
insights.push({
|
|
942
|
+
type: 'warning',
|
|
943
|
+
priority: fn.cyclomaticComplexity > 20 ? 'high' : 'medium',
|
|
944
|
+
title: `[ast] High complexity in ${fn.name}() — cyclomatic: ${fn.cyclomaticComplexity}`,
|
|
945
|
+
content: `Function "${fn.name}" in ${f.path} has cyclomatic complexity of ${fn.cyclomaticComplexity}. ` +
|
|
946
|
+
`Consider breaking it into smaller functions. ` +
|
|
947
|
+
`Parameters: ${fn.params}, Lines: ${fn.endLine - fn.startLine}, Nesting: ${fn.nestingDepth}`,
|
|
948
|
+
files: [f.path],
|
|
949
|
+
timestamp: new Date(),
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
catch { /* skip AST failures */ }
|
|
956
|
+
}
|
|
957
|
+
// Accessibility check on changed frontend files
|
|
958
|
+
const frontendFiles = changes.filter(c => /\.(tsx|jsx|vue|svelte|html)$/.test(c.path) && c.content);
|
|
959
|
+
if (frontendFiles.length > 0) {
|
|
960
|
+
try {
|
|
961
|
+
for (const f of frontendFiles.slice(0, 5)) {
|
|
962
|
+
const a11yIssues = this.a11yChecker.analyzeFile(f.path);
|
|
963
|
+
for (const issue of a11yIssues) {
|
|
964
|
+
insights.push({
|
|
965
|
+
type: 'a11y',
|
|
966
|
+
priority: issue.severity === 'critical' ? 'critical' : issue.severity === 'serious' ? 'high' : issue.severity === 'moderate' ? 'medium' : 'low',
|
|
967
|
+
title: `[a11y] ${issue.message}`,
|
|
968
|
+
content: `${issue.message}\nRule: ${issue.rule} (WCAG ${issue.wcagCriterion} Level ${issue.wcagLevel})\nSuggestion: ${issue.suggestion}`,
|
|
969
|
+
files: [f.path],
|
|
970
|
+
timestamp: new Date(),
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
catch { /* skip a11y failures */ }
|
|
976
|
+
}
|
|
977
|
+
// i18n detection on frontend files
|
|
978
|
+
if (frontendFiles.length > 0) {
|
|
979
|
+
try {
|
|
980
|
+
for (const f of frontendFiles.slice(0, 5)) {
|
|
981
|
+
const i18nIssues = this.i18nDetector.analyzeFile(f.path, false);
|
|
982
|
+
for (const issue of i18nIssues) {
|
|
983
|
+
insights.push({
|
|
984
|
+
type: 'i18n',
|
|
985
|
+
priority: issue.severity === 'high' ? 'high' : 'medium',
|
|
986
|
+
title: `[i18n] ${issue.content}`,
|
|
987
|
+
content: `${issue.content}\nType: ${issue.type}\nSuggestion: ${issue.suggestion}`,
|
|
988
|
+
files: [f.path],
|
|
989
|
+
timestamp: new Date(),
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
catch { /* skip i18n failures */ }
|
|
995
|
+
}
|
|
996
|
+
// Env secret scan on changed files
|
|
997
|
+
try {
|
|
998
|
+
for (const change of changes.filter(c => c.content).slice(0, 10)) {
|
|
999
|
+
const secretPatterns = [
|
|
1000
|
+
/(?:api[_-]?key|secret|token|password)\s*[:=]\s*["'][^"']{8,}["']/gi,
|
|
1001
|
+
/(?:mongodb|postgres|mysql|redis):\/\/[^\s"']+/gi,
|
|
1002
|
+
];
|
|
1003
|
+
for (const regex of secretPatterns) {
|
|
1004
|
+
regex.lastIndex = 0;
|
|
1005
|
+
if (regex.test(change.content) && !change.content.includes('process.env')) {
|
|
1006
|
+
insights.push({
|
|
1007
|
+
type: 'env',
|
|
1008
|
+
priority: 'critical',
|
|
1009
|
+
title: `[env] Hardcoded secret in ${change.path}`,
|
|
1010
|
+
content: 'Never hardcode secrets in source code. Use environment variables or a secret manager.',
|
|
1011
|
+
files: [change.path],
|
|
1012
|
+
timestamp: new Date(),
|
|
1013
|
+
confidence: 0.95,
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
catch { /* skip env scan failures */ }
|
|
1020
|
+
// ── v4.0.0: Hyper-Intelligence Enhancements ────────────────────
|
|
1021
|
+
// Knowledge Graph build + PageRank
|
|
1022
|
+
try {
|
|
1023
|
+
if (this.knowledgeGraph) {
|
|
1024
|
+
await this.knowledgeGraph.build();
|
|
1025
|
+
const topEntities = this.knowledgeGraph.getTopEntities(10);
|
|
1026
|
+
const changedPaths = new Set(changes.map(c => c.path));
|
|
1027
|
+
for (const entity of topEntities) {
|
|
1028
|
+
const entityFile = entity.file || '';
|
|
1029
|
+
if (entityFile && changedPaths.has(entityFile)) {
|
|
1030
|
+
insights.push({
|
|
1031
|
+
priority: 'medium',
|
|
1032
|
+
type: 'pattern',
|
|
1033
|
+
title: `[graph] High-impact entity: ${entity.name}`,
|
|
1034
|
+
content: `${entity.name} in ${entityFile} has PageRank score ${entity.pageRankScore?.toFixed(3) || 'N/A'} — changes here ripple across the codebase`,
|
|
1035
|
+
files: [entityFile],
|
|
1036
|
+
timestamp: new Date(),
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
catch { /* knowledge graph is best-effort */ }
|
|
1043
|
+
// Predictive Engine — Bug Risk + Debt Forecast
|
|
1044
|
+
try {
|
|
1045
|
+
const codeAgeFiles = changes.filter(c => c.content).slice(0, 20).map(c => ({
|
|
1046
|
+
file: c.path,
|
|
1047
|
+
lastModified: new Date(),
|
|
1048
|
+
daysSinceModification: 0,
|
|
1049
|
+
linesChangedRecently: 1,
|
|
1050
|
+
stalenessScore: 0,
|
|
1051
|
+
risk: 'fresh',
|
|
1052
|
+
authors: [],
|
|
1053
|
+
churnRate: 0,
|
|
1054
|
+
}));
|
|
1055
|
+
const metrics = this.lastMetrics;
|
|
1056
|
+
if (codeAgeFiles.length > 0 && metrics) {
|
|
1057
|
+
const bugRisks = this.predictiveEngine.scoreBugRisk(codeAgeFiles, metrics);
|
|
1058
|
+
for (const risk of bugRisks.filter(r => r.riskLevel === 'high' || r.riskLevel === 'critical')) {
|
|
1059
|
+
insights.push({
|
|
1060
|
+
priority: (risk.riskLevel === 'critical' ? 'high' : 'medium'),
|
|
1061
|
+
type: 'warning',
|
|
1062
|
+
title: `[predict] Bug risk in ${risk.file}: ${risk.riskLevel}`,
|
|
1063
|
+
content: `Risk factors: ${risk.factors.join(', ')}. Confidence: ${(risk.confidence * 100).toFixed(0)}%`,
|
|
1064
|
+
files: [risk.file],
|
|
1065
|
+
timestamp: new Date(),
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
catch { /* predictive engine is best-effort */ }
|
|
734
1071
|
for (const insight of insights) {
|
|
735
1072
|
insight.timestamp = new Date();
|
|
736
1073
|
}
|
|
@@ -755,6 +1092,18 @@ export class Orchestrator extends EventEmitter {
|
|
|
755
1092
|
this.currentSession.insights = this.currentSession.insights.slice(-100);
|
|
756
1093
|
}
|
|
757
1094
|
}
|
|
1095
|
+
// v4.0.0: Swarm pheromone update
|
|
1096
|
+
try {
|
|
1097
|
+
for (const insight of insights) {
|
|
1098
|
+
const files = insight.files || [];
|
|
1099
|
+
if (files.length > 0) {
|
|
1100
|
+
const strength = (insight.priority === 'critical' ? 3 : insight.priority === 'high' ? 2 : 1) * 1.5;
|
|
1101
|
+
this.swarmIntelligence.depositPheromone(files, strength);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
this.swarmIntelligence.evaporate();
|
|
1105
|
+
}
|
|
1106
|
+
catch { /* swarm update is best-effort */ }
|
|
758
1107
|
this.emit('insights', { insights });
|
|
759
1108
|
// ── v2.1.0: Neural Mesh Broadcasting ────────────────────────────
|
|
760
1109
|
if (this.neuralMesh && this.neuralMesh.isRunning()) {
|
|
@@ -771,6 +1120,22 @@ export class Orchestrator extends EventEmitter {
|
|
|
771
1120
|
this.neuralMesh.broadcastPattern(insight.title, insight.type);
|
|
772
1121
|
}
|
|
773
1122
|
}
|
|
1123
|
+
// v4.0.0: Cross-agent broadcast + self-evolution meta-learning
|
|
1124
|
+
try {
|
|
1125
|
+
const boostPacket = {
|
|
1126
|
+
insights: insights.slice(0, 3),
|
|
1127
|
+
healthScore: healthScore.overall,
|
|
1128
|
+
contextSummary: changes.map(c => c.path).slice(0, 10).join(', '),
|
|
1129
|
+
};
|
|
1130
|
+
await this.crossAgentProtocol.broadcast('claude-code', boostPacket);
|
|
1131
|
+
}
|
|
1132
|
+
catch { /* cross-agent broadcast is best-effort */ }
|
|
1133
|
+
try {
|
|
1134
|
+
for (const insight of insights) {
|
|
1135
|
+
this.selfEvolution.updateMetaLearning(`${insight.type}:${insight.priority}`, insight.priority !== 'low');
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
catch { /* self-evolution is best-effort */ }
|
|
774
1139
|
}
|
|
775
1140
|
catch (err) {
|
|
776
1141
|
this.emit('error', { error: err });
|
|
@@ -837,5 +1202,20 @@ export class Orchestrator extends EventEmitter {
|
|
|
837
1202
|
}
|
|
838
1203
|
return changes;
|
|
839
1204
|
}
|
|
1205
|
+
/** v4.0.0: Simple text-to-vector for TurboMemory compatibility */
|
|
1206
|
+
textToVector(text, dimensions = 64) {
|
|
1207
|
+
const vector = new Array(dimensions).fill(0);
|
|
1208
|
+
const words = text.toLowerCase().split(/\W+/).filter(w => w.length > 2);
|
|
1209
|
+
for (const word of words) {
|
|
1210
|
+
let hash = 0;
|
|
1211
|
+
for (let i = 0; i < word.length; i++) {
|
|
1212
|
+
hash = ((hash << 5) - hash) + word.charCodeAt(i);
|
|
1213
|
+
hash = hash & hash;
|
|
1214
|
+
}
|
|
1215
|
+
vector[Math.abs(hash) % dimensions] += 1;
|
|
1216
|
+
}
|
|
1217
|
+
const max = Math.max(...vector, 1);
|
|
1218
|
+
return vector.map(v => v / max);
|
|
1219
|
+
}
|
|
840
1220
|
}
|
|
841
1221
|
//# sourceMappingURL=orchestrator.js.map
|