@theihtisham/agent-shadow-brain 3.0.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/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/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/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/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/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 +24 -2
- package/dist/brain/orchestrator.d.ts.map +1 -1
- package/dist/brain/orchestrator.js +208 -4
- 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 +339 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +272 -1
- 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
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// src/brain/influence-map.ts — Code change influence mapping
|
|
2
|
+
// v3.1.0 — Predicts which files are affected by changes using import graph analysis
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
const IGNORE_DIRS = new Set([
|
|
6
|
+
'node_modules', '.git', 'dist', 'build', 'out', 'coverage', '.next', '.nuxt', '.cache',
|
|
7
|
+
]);
|
|
8
|
+
const CODE_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx', '.py', '.rs', '.go', '.java']);
|
|
9
|
+
export class InfluenceMapper {
|
|
10
|
+
constructor(projectDir) {
|
|
11
|
+
this.graph = new Map();
|
|
12
|
+
this.projectDir = projectDir;
|
|
13
|
+
}
|
|
14
|
+
async analyzeProject(maxFiles = 300) {
|
|
15
|
+
const files = this.collectFiles(this.projectDir, maxFiles);
|
|
16
|
+
const insights = [];
|
|
17
|
+
// Build the import graph
|
|
18
|
+
this.buildGraph(files);
|
|
19
|
+
// Find high-influence files (files imported by many others)
|
|
20
|
+
const influenceMap = this.calculateInfluenceScores();
|
|
21
|
+
// Generate insights for high-influence files
|
|
22
|
+
const highInfluence = influenceMap
|
|
23
|
+
.filter(f => f.score >= 5)
|
|
24
|
+
.sort((a, b) => b.score - a.score)
|
|
25
|
+
.slice(0, 20);
|
|
26
|
+
if (highInfluence.length > 0) {
|
|
27
|
+
insights.push({
|
|
28
|
+
type: 'architecture',
|
|
29
|
+
priority: 'medium',
|
|
30
|
+
title: `[architecture] ${highInfluence.length} high-influence files detected (change impact analysis)`,
|
|
31
|
+
content: `Import graph analysis found ${highInfluence.length} files with high change influence.\n` +
|
|
32
|
+
` Total files in graph: ${this.graph.size}\n` +
|
|
33
|
+
` These files affect many others when changed:\n` +
|
|
34
|
+
highInfluence.map(f => ` - ${f.file} (influence: ${f.score}, imported by ${this.graph.get(f.file)?.importedBy.size || 0} files)`).join('\n') +
|
|
35
|
+
`\n Changes to these files require thorough testing of dependent modules.`,
|
|
36
|
+
files: highInfluence.map(f => f.file),
|
|
37
|
+
timestamp: new Date(),
|
|
38
|
+
confidence: 0.8,
|
|
39
|
+
metadata: {
|
|
40
|
+
totalFiles: this.graph.size,
|
|
41
|
+
highInfluenceFiles: highInfluence.map(f => ({
|
|
42
|
+
file: f.file,
|
|
43
|
+
score: f.score,
|
|
44
|
+
dependents: this.graph.get(f.file)?.importedBy.size || 0,
|
|
45
|
+
})),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Detect potential orphan files
|
|
50
|
+
const orphans = [...this.graph.values()].filter(node => node.imports.size === 0 && node.importedBy.size === 0);
|
|
51
|
+
if (orphans.length > 0 && orphans.length < this.graph.size * 0.5) {
|
|
52
|
+
insights.push({
|
|
53
|
+
type: 'architecture',
|
|
54
|
+
priority: 'low',
|
|
55
|
+
title: `[architecture] ${orphans.length} orphan files (no import relationships)`,
|
|
56
|
+
content: `${orphans.length} files have no detected import relationships.\n` +
|
|
57
|
+
` These may be: entry points, standalone scripts, or dead code.\n` +
|
|
58
|
+
` Files: ${orphans.slice(0, 10).map(o => o.path).join(', ')}${orphans.length > 10 ? ' ...' : ''}`,
|
|
59
|
+
files: orphans.map(o => o.path).slice(0, 20),
|
|
60
|
+
timestamp: new Date(),
|
|
61
|
+
confidence: 0.6,
|
|
62
|
+
metadata: { orphanCount: orphans.length },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return insights;
|
|
66
|
+
}
|
|
67
|
+
analyzeInfluence(changedFiles) {
|
|
68
|
+
const affectedMap = new Map();
|
|
69
|
+
for (const changedFile of changedFiles) {
|
|
70
|
+
const relPath = this.toRelative(changedFile);
|
|
71
|
+
// 1. Direct reverse dependencies (weight 3)
|
|
72
|
+
const directDeps = this.getReverseDependencies(relPath);
|
|
73
|
+
for (const dep of directDeps) {
|
|
74
|
+
if (!affectedMap.has(dep)) {
|
|
75
|
+
affectedMap.set(dep, { score: 0, reasons: new Set() });
|
|
76
|
+
}
|
|
77
|
+
const entry = affectedMap.get(dep);
|
|
78
|
+
entry.score += 3;
|
|
79
|
+
entry.reasons.add(`directly imports ${relPath}`);
|
|
80
|
+
}
|
|
81
|
+
// 2. Transitive (indirect) dependencies (weight 1)
|
|
82
|
+
const transitiveDeps = this.getTransitiveReverseDependencies(relPath, new Set(), 0, 3);
|
|
83
|
+
for (const dep of transitiveDeps) {
|
|
84
|
+
if (directDeps.has(dep))
|
|
85
|
+
continue; // already counted as direct
|
|
86
|
+
if (!affectedMap.has(dep)) {
|
|
87
|
+
affectedMap.set(dep, { score: 0, reasons: new Set() });
|
|
88
|
+
}
|
|
89
|
+
const entry = affectedMap.get(dep);
|
|
90
|
+
entry.score += 1;
|
|
91
|
+
entry.reasons.add(`indirectly depends on ${relPath}`);
|
|
92
|
+
}
|
|
93
|
+
// 3. Test file correlation (weight 2)
|
|
94
|
+
const testFile = this.findTestCorrelation(relPath);
|
|
95
|
+
if (testFile && this.graph.has(testFile)) {
|
|
96
|
+
if (!affectedMap.has(testFile)) {
|
|
97
|
+
affectedMap.set(testFile, { score: 0, reasons: new Set() });
|
|
98
|
+
}
|
|
99
|
+
const entry = affectedMap.get(testFile);
|
|
100
|
+
entry.score += 2;
|
|
101
|
+
entry.reasons.add(`test file for ${relPath}`);
|
|
102
|
+
}
|
|
103
|
+
// Also check if the changed file IS a test file — mark the source
|
|
104
|
+
const sourceFile = this.findSourceForTest(relPath);
|
|
105
|
+
if (sourceFile && this.graph.has(sourceFile)) {
|
|
106
|
+
if (!affectedMap.has(sourceFile)) {
|
|
107
|
+
affectedMap.set(sourceFile, { score: 0, reasons: new Set() });
|
|
108
|
+
}
|
|
109
|
+
const entry = affectedMap.get(sourceFile);
|
|
110
|
+
entry.score += 2;
|
|
111
|
+
entry.reasons.add(`source file tested by ${relPath}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Sort by score descending, take top 20
|
|
115
|
+
const affected = [...affectedMap.entries()]
|
|
116
|
+
.map(([file, data]) => ({
|
|
117
|
+
file,
|
|
118
|
+
score: data.score,
|
|
119
|
+
reasons: [...data.reasons],
|
|
120
|
+
}))
|
|
121
|
+
.sort((a, b) => b.score - a.score)
|
|
122
|
+
.slice(0, 20);
|
|
123
|
+
const maxScore = affected.length > 0 ? affected[0].score : 0;
|
|
124
|
+
const riskLevel = maxScore >= 15 ? 'high' : maxScore >= 8 ? 'medium' : 'low';
|
|
125
|
+
return {
|
|
126
|
+
changedFiles: changedFiles.map(f => this.toRelative(f)),
|
|
127
|
+
affectedFiles: affected,
|
|
128
|
+
totalReachable: affectedMap.size,
|
|
129
|
+
riskLevel,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
buildGraph(files) {
|
|
133
|
+
this.graph.clear();
|
|
134
|
+
// Phase 1: Create nodes
|
|
135
|
+
for (const filePath of files) {
|
|
136
|
+
const relPath = path.relative(this.projectDir, filePath).replace(/\\/g, '/');
|
|
137
|
+
this.graph.set(relPath, {
|
|
138
|
+
path: relPath,
|
|
139
|
+
imports: new Set(),
|
|
140
|
+
importedBy: new Set(),
|
|
141
|
+
testCorrelation: this.inferTestFile(relPath),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
// Phase 2: Extract imports and build edges
|
|
145
|
+
for (const filePath of files) {
|
|
146
|
+
const relPath = path.relative(this.projectDir, filePath).replace(/\\/g, '/');
|
|
147
|
+
const imports = this.extractImports(filePath, relPath);
|
|
148
|
+
const node = this.graph.get(relPath);
|
|
149
|
+
if (!node)
|
|
150
|
+
continue;
|
|
151
|
+
for (const importPath of imports) {
|
|
152
|
+
node.imports.add(importPath);
|
|
153
|
+
const targetNode = this.graph.get(importPath);
|
|
154
|
+
if (targetNode) {
|
|
155
|
+
targetNode.importedBy.add(relPath);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
extractImports(filePath, relPath) {
|
|
161
|
+
let content;
|
|
162
|
+
try {
|
|
163
|
+
content = fs.readFileSync(filePath, 'utf-8');
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
const ext = path.extname(filePath);
|
|
169
|
+
const dir = path.dirname(relPath);
|
|
170
|
+
const imports = [];
|
|
171
|
+
if (['.ts', '.tsx', '.js', '.jsx'].includes(ext)) {
|
|
172
|
+
// ESM: import ... from './foo'
|
|
173
|
+
const esmPattern = /import\s+(?:type\s+)?(?:[\w{},\s*]*\s+from\s+)?['"]([^'"]+)['"]/g;
|
|
174
|
+
let match;
|
|
175
|
+
while ((match = esmPattern.exec(content)) !== null) {
|
|
176
|
+
const resolved = this.resolveImport(match[1], dir, ext);
|
|
177
|
+
if (resolved)
|
|
178
|
+
imports.push(resolved);
|
|
179
|
+
}
|
|
180
|
+
// Dynamic imports: import('./foo')
|
|
181
|
+
const dynamicPattern = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
182
|
+
while ((match = dynamicPattern.exec(content)) !== null) {
|
|
183
|
+
const resolved = this.resolveImport(match[1], dir, ext);
|
|
184
|
+
if (resolved)
|
|
185
|
+
imports.push(resolved);
|
|
186
|
+
}
|
|
187
|
+
// CJS: require('./foo')
|
|
188
|
+
const cjsPattern = /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
189
|
+
while ((match = cjsPattern.exec(content)) !== null) {
|
|
190
|
+
const resolved = this.resolveImport(match[1], dir, ext);
|
|
191
|
+
if (resolved)
|
|
192
|
+
imports.push(resolved);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (ext === '.py') {
|
|
196
|
+
const pyPattern = /(?:from|import)\s+([.\w]+)/g;
|
|
197
|
+
let match;
|
|
198
|
+
while ((match = pyPattern.exec(content)) !== null) {
|
|
199
|
+
const resolved = this.resolvePythonImport(match[1], dir);
|
|
200
|
+
if (resolved)
|
|
201
|
+
imports.push(resolved);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (ext === '.go') {
|
|
205
|
+
// Go imports are in import blocks
|
|
206
|
+
const goPattern = /"([^"]+)"/g;
|
|
207
|
+
const importBlock = content.match(/import\s*\([\s\S]*?\)/);
|
|
208
|
+
let match;
|
|
209
|
+
if (importBlock) {
|
|
210
|
+
while ((match = goPattern.exec(importBlock[0])) !== null) {
|
|
211
|
+
// Go uses module paths, limited local resolution
|
|
212
|
+
const localPath = match[1].replace(/\/.*$/, '');
|
|
213
|
+
if (this.graph.has(localPath))
|
|
214
|
+
imports.push(localPath);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return [...new Set(imports)];
|
|
219
|
+
}
|
|
220
|
+
resolveImport(importPath, fromDir, ext) {
|
|
221
|
+
// Only resolve relative imports (not node_modules or packages)
|
|
222
|
+
if (!importPath.startsWith('.'))
|
|
223
|
+
return null;
|
|
224
|
+
const extensions = ['.ts', '.tsx', '.js', '.jsx', '/index.ts', '/index.tsx', '/index.js', '/index.jsx'];
|
|
225
|
+
// Normalize the path
|
|
226
|
+
let resolved = path.normalize(path.join(fromDir, importPath)).replace(/\\/g, '/');
|
|
227
|
+
// Try exact path first
|
|
228
|
+
if (this.graph.has(resolved))
|
|
229
|
+
return resolved;
|
|
230
|
+
// Try with extensions
|
|
231
|
+
for (const tryExt of extensions) {
|
|
232
|
+
const candidate = resolved + tryExt;
|
|
233
|
+
if (this.graph.has(candidate))
|
|
234
|
+
return candidate;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
resolvePythonImport(importPath, fromDir) {
|
|
239
|
+
const parts = importPath.split('.');
|
|
240
|
+
const candidates = [
|
|
241
|
+
parts.join('/') + '.py',
|
|
242
|
+
path.join(...parts.slice(0, -1), '__init__.py'),
|
|
243
|
+
];
|
|
244
|
+
for (const candidate of candidates) {
|
|
245
|
+
if (this.graph.has(candidate))
|
|
246
|
+
return candidate;
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
getReverseDependencies(filePath) {
|
|
251
|
+
const node = this.graph.get(filePath);
|
|
252
|
+
if (!node)
|
|
253
|
+
return new Set();
|
|
254
|
+
return new Set(node.importedBy);
|
|
255
|
+
}
|
|
256
|
+
getTransitiveReverseDependencies(filePath, visited, depth, maxDepth) {
|
|
257
|
+
const result = new Set();
|
|
258
|
+
if (depth >= maxDepth)
|
|
259
|
+
return result;
|
|
260
|
+
const node = this.graph.get(filePath);
|
|
261
|
+
if (!node)
|
|
262
|
+
return result;
|
|
263
|
+
for (const dep of node.importedBy) {
|
|
264
|
+
if (visited.has(dep))
|
|
265
|
+
continue;
|
|
266
|
+
visited.add(dep);
|
|
267
|
+
result.add(dep);
|
|
268
|
+
// Recurse to find transitive deps
|
|
269
|
+
const transitive = this.getTransitiveReverseDependencies(dep, visited, depth + 1, maxDepth);
|
|
270
|
+
for (const t of transitive) {
|
|
271
|
+
result.add(t);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
inferTestFile(relPath) {
|
|
277
|
+
const ext = path.extname(relPath);
|
|
278
|
+
const base = relPath.replace(ext, '');
|
|
279
|
+
const testPatterns = [
|
|
280
|
+
`${base}.test${ext}`,
|
|
281
|
+
`${base}.spec${ext}`,
|
|
282
|
+
`${base}.test.ts`,
|
|
283
|
+
`${base}.spec.ts`,
|
|
284
|
+
`tests/${base}.test${ext}`,
|
|
285
|
+
`test/${base}.test${ext}`,
|
|
286
|
+
`__tests__/${base}.test${ext}`,
|
|
287
|
+
];
|
|
288
|
+
for (const pattern of testPatterns) {
|
|
289
|
+
if (this.graph.has(pattern))
|
|
290
|
+
return pattern;
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
findTestCorrelation(relPath) {
|
|
295
|
+
const node = this.graph.get(relPath);
|
|
296
|
+
if (node?.testCorrelation)
|
|
297
|
+
return node.testCorrelation;
|
|
298
|
+
// Try inferring
|
|
299
|
+
return this.inferTestFile(relPath);
|
|
300
|
+
}
|
|
301
|
+
findSourceForTest(testPath) {
|
|
302
|
+
// Reverse: given a test file, find the source
|
|
303
|
+
const testMatch = testPath.match(/^(.+?)(?:\.test|\.spec|_test|Test)(\.\w+)$/);
|
|
304
|
+
if (!testMatch)
|
|
305
|
+
return null;
|
|
306
|
+
const sourcePath = testMatch[1] + testMatch[2];
|
|
307
|
+
if (this.graph.has(sourcePath))
|
|
308
|
+
return sourcePath;
|
|
309
|
+
// Try common extensions
|
|
310
|
+
const ext = testMatch[2];
|
|
311
|
+
const base = testMatch[1];
|
|
312
|
+
const candidates = [base + ext, base + '.ts', base + '.tsx', base + '.js'];
|
|
313
|
+
for (const candidate of candidates) {
|
|
314
|
+
if (this.graph.has(candidate))
|
|
315
|
+
return candidate;
|
|
316
|
+
}
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
calculateInfluenceScores() {
|
|
320
|
+
const scores = [];
|
|
321
|
+
for (const [file, node] of this.graph) {
|
|
322
|
+
let score = 0;
|
|
323
|
+
// Direct dependents
|
|
324
|
+
score += node.importedBy.size * 3;
|
|
325
|
+
// Transitive reach
|
|
326
|
+
const transitive = this.getTransitiveReverseDependencies(file, new Set([file]), 0, 2);
|
|
327
|
+
score += transitive.size * 1;
|
|
328
|
+
// Is imported by many = higher influence
|
|
329
|
+
// Is a hub (imports many + imported by many) = higher influence
|
|
330
|
+
if (node.imports.size > 3 && node.importedBy.size > 3) {
|
|
331
|
+
score += 5;
|
|
332
|
+
}
|
|
333
|
+
scores.push({ file, score });
|
|
334
|
+
}
|
|
335
|
+
return scores;
|
|
336
|
+
}
|
|
337
|
+
toRelative(filePath) {
|
|
338
|
+
if (path.isAbsolute(filePath)) {
|
|
339
|
+
return path.relative(this.projectDir, filePath).replace(/\\/g, '/');
|
|
340
|
+
}
|
|
341
|
+
return filePath.replace(/\\/g, '/');
|
|
342
|
+
}
|
|
343
|
+
collectFiles(dir, maxFiles) {
|
|
344
|
+
const results = [];
|
|
345
|
+
const walk = (currentDir, depth) => {
|
|
346
|
+
if (results.length >= maxFiles || depth > 10)
|
|
347
|
+
return;
|
|
348
|
+
let entries;
|
|
349
|
+
try {
|
|
350
|
+
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
for (const entry of entries) {
|
|
356
|
+
if (results.length >= maxFiles)
|
|
357
|
+
return;
|
|
358
|
+
if (entry.name.startsWith('.'))
|
|
359
|
+
continue;
|
|
360
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
361
|
+
if (entry.isDirectory()) {
|
|
362
|
+
if (IGNORE_DIRS.has(entry.name))
|
|
363
|
+
continue;
|
|
364
|
+
walk(fullPath, depth + 1);
|
|
365
|
+
}
|
|
366
|
+
else if (entry.isFile() && CODE_EXTENSIONS.has(path.extname(entry.name))) {
|
|
367
|
+
results.push(fullPath);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
walk(dir, 0);
|
|
372
|
+
return results;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
//# sourceMappingURL=influence-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"influence-map.js","sourceRoot":"","sources":["../../src/brain/influence-map.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,oFAAoF;AAGpF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ;CACvF,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAyB9F,MAAM,OAAO,eAAe;IAI1B,YAAY,UAAkB;QAFtB,UAAK,GAA0B,IAAI,GAAG,EAAE,CAAC;QAG/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,cAA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AC,KAAK,CAAC,IAAI,CAAC;wBAAE,SAAS;oBAC1C,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;gBAC5B,CAAC;qBAAM,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;oBAC3E,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACb,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KGEntity, KGRelation, KGGraph, PageRankResult } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Knowledge Graph — maps your entire codebase as a living graph.
|
|
4
|
+
*
|
|
5
|
+
* Entity extraction: Parse source files for functions, classes, interfaces,
|
|
6
|
+
* modules, variables (exported only).
|
|
7
|
+
*
|
|
8
|
+
* Relations: calls, imports, extends, implements, uses, tests
|
|
9
|
+
*
|
|
10
|
+
* PageRank: Damping factor 0.85, convergence < 0.0001, max 100 iterations.
|
|
11
|
+
* Result: normalized score 0-1 for each entity.
|
|
12
|
+
*
|
|
13
|
+
* Use cases:
|
|
14
|
+
* - Most critical functions to test (high PageRank)
|
|
15
|
+
* - Orphan code (zero in-degree, zero PageRank)
|
|
16
|
+
* - Circular dependency detection (cycles)
|
|
17
|
+
* - Impact analysis: what breaks if X changes?
|
|
18
|
+
*/
|
|
19
|
+
export declare class KnowledgeGraph {
|
|
20
|
+
private graph;
|
|
21
|
+
private projectDir;
|
|
22
|
+
constructor(projectDir: string);
|
|
23
|
+
/** Build the knowledge graph from project source files */
|
|
24
|
+
build(): Promise<KGGraph>;
|
|
25
|
+
/** Add a single entity */
|
|
26
|
+
addEntity(entity: KGEntity): void;
|
|
27
|
+
/** Add a relation */
|
|
28
|
+
addRelation(relation: KGRelation): void;
|
|
29
|
+
/** Extract code entities from source file content */
|
|
30
|
+
private extractEntities;
|
|
31
|
+
/** Extract relations between entities based on imports, calls, etc. */
|
|
32
|
+
private extractRelations;
|
|
33
|
+
/**
|
|
34
|
+
* Compute PageRank scores for all entities.
|
|
35
|
+
* Damping factor: 0.85, convergence: < 0.0001, max iterations: 100.
|
|
36
|
+
*/
|
|
37
|
+
pageRank(iterations?: number): PageRankResult;
|
|
38
|
+
/** Get top-N most important entities by PageRank */
|
|
39
|
+
getTopEntities(topN?: number): KGEntity[];
|
|
40
|
+
/** Find entities impacted by a change to the given entity */
|
|
41
|
+
getImpactedBy(entityId: string): KGEntity[];
|
|
42
|
+
private findDownstream;
|
|
43
|
+
/** Find circular dependencies */
|
|
44
|
+
findCycles(): string[][];
|
|
45
|
+
/** Get graph statistics */
|
|
46
|
+
getStats(): {
|
|
47
|
+
entities: number;
|
|
48
|
+
relations: number;
|
|
49
|
+
avgPageRank: number;
|
|
50
|
+
orphanCount: number;
|
|
51
|
+
};
|
|
52
|
+
private findSourceFiles;
|
|
53
|
+
private saveToDisk;
|
|
54
|
+
private loadFromDisk;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=knowledge-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge-graph.d.ts","sourceRoot":"","sources":["../../src/brain/knowledge-graph.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI5E;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,UAAU,CAAS;gBAEf,UAAU,EAAE,MAAM;IAa9B,0DAA0D;IACpD,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;IA+B/B,0BAA0B;IAC1B,SAAS,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI;IAIjC,qBAAqB;IACrB,WAAW,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI;IAMvC,qDAAqD;IACrD,OAAO,CAAC,eAAe;IA4FvB,uEAAuE;IACvE,OAAO,CAAC,gBAAgB;IAmDxB;;;OAGG;IACH,QAAQ,CAAC,UAAU,GAAE,MAAY,GAAG,cAAc;IAsGlD,oDAAoD;IACpD,cAAc,CAAC,IAAI,GAAE,MAAW,GAAG,QAAQ,EAAE;IAM7C,6DAA6D;IAC7D,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE;IAS3C,OAAO,CAAC,cAAc;IAWtB,iCAAiC;IACjC,UAAU,IAAI,MAAM,EAAE,EAAE;IAsCxB,2BAA2B;IAC3B,QAAQ,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAa7F,OAAO,CAAC,eAAe;YAsBT,UAAU;IAyBxB,OAAO,CAAC,YAAY;CAgBrB"}
|