@esankhan3/anvil-knowledge-core 0.3.13 → 0.4.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/dist/__tests__/chunker.test.js +15 -0
- package/dist/__tests__/chunker.test.js.map +1 -1
- package/dist/__tests__/literal-tier-integration.test.d.ts +7 -0
- package/dist/__tests__/literal-tier-integration.test.d.ts.map +1 -0
- package/dist/__tests__/literal-tier-integration.test.js +84 -0
- package/dist/__tests__/literal-tier-integration.test.js.map +1 -0
- package/dist/__tests__/partial-cycle-chunks.test.d.ts +15 -0
- package/dist/__tests__/partial-cycle-chunks.test.d.ts.map +1 -0
- package/dist/__tests__/partial-cycle-chunks.test.js +133 -0
- package/dist/__tests__/partial-cycle-chunks.test.js.map +1 -0
- package/dist/__tests__/retriever-fusion.test.js +101 -4
- package/dist/__tests__/retriever-fusion.test.js.map +1 -1
- package/dist/__tests__/storage-graph-accessor.test.d.ts +11 -0
- package/dist/__tests__/storage-graph-accessor.test.d.ts.map +1 -0
- package/dist/__tests__/storage-graph-accessor.test.js +70 -0
- package/dist/__tests__/storage-graph-accessor.test.js.map +1 -0
- package/dist/__tests__/storage-mongo-blob.test.d.ts +11 -0
- package/dist/__tests__/storage-mongo-blob.test.d.ts.map +1 -0
- package/dist/__tests__/storage-mongo-blob.test.js +118 -0
- package/dist/__tests__/storage-mongo-blob.test.js.map +1 -0
- package/dist/__tests__/storage-ports.test.d.ts +9 -0
- package/dist/__tests__/storage-ports.test.d.ts.map +1 -0
- package/dist/__tests__/storage-ports.test.js +276 -0
- package/dist/__tests__/storage-ports.test.js.map +1 -0
- package/dist/__tests__/storage-profile-helpers.test.d.ts +7 -0
- package/dist/__tests__/storage-profile-helpers.test.d.ts.map +1 -0
- package/dist/__tests__/storage-profile-helpers.test.js +50 -0
- package/dist/__tests__/storage-profile-helpers.test.js.map +1 -0
- package/dist/__tests__/storage-vector-integration.test.d.ts +15 -0
- package/dist/__tests__/storage-vector-integration.test.d.ts.map +1 -0
- package/dist/__tests__/storage-vector-integration.test.js +196 -0
- package/dist/__tests__/storage-vector-integration.test.js.map +1 -0
- package/dist/__tests__/vector-recall.test.d.ts +15 -0
- package/dist/__tests__/vector-recall.test.d.ts.map +1 -0
- package/dist/__tests__/vector-recall.test.js +94 -0
- package/dist/__tests__/vector-recall.test.js.map +1 -0
- package/dist/__tests__/writer-remote-pipeline.test.d.ts +2 -0
- package/dist/__tests__/writer-remote-pipeline.test.d.ts.map +1 -0
- package/dist/__tests__/writer-remote-pipeline.test.js +39 -0
- package/dist/__tests__/writer-remote-pipeline.test.js.map +1 -0
- package/dist/chunker.d.ts.map +1 -1
- package/dist/chunker.js +8 -4
- package/dist/chunker.js.map +1 -1
- package/dist/config.d.ts +69 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -1
- package/dist/cross-repo-detector.d.ts +70 -0
- package/dist/cross-repo-detector.d.ts.map +1 -1
- package/dist/cross-repo-detector.js +654 -810
- package/dist/cross-repo-detector.js.map +1 -1
- package/dist/file-walker.d.ts +3 -0
- package/dist/file-walker.d.ts.map +1 -1
- package/dist/file-walker.js +24 -1
- package/dist/file-walker.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +17 -1
- package/dist/indexer.d.ts.map +1 -1
- package/dist/indexer.js +355 -93
- package/dist/indexer.js.map +1 -1
- package/dist/project-graph-builder.d.ts +8 -5
- package/dist/project-graph-builder.d.ts.map +1 -1
- package/dist/project-graph-builder.js +66 -66
- package/dist/project-graph-builder.js.map +1 -1
- package/dist/query-router.d.ts +7 -5
- package/dist/query-router.d.ts.map +1 -1
- package/dist/query-router.js +16 -50
- package/dist/query-router.js.map +1 -1
- package/dist/repo-pipeline.d.ts +27 -2
- package/dist/repo-pipeline.d.ts.map +1 -1
- package/dist/repo-pipeline.js +66 -11
- package/dist/repo-pipeline.js.map +1 -1
- package/dist/repo-profiler.d.ts +9 -4
- package/dist/repo-profiler.d.ts.map +1 -1
- package/dist/repo-profiler.js +49 -41
- package/dist/repo-profiler.js.map +1 -1
- package/dist/retriever.d.ts +4 -5
- package/dist/retriever.d.ts.map +1 -1
- package/dist/retriever.js +81 -17
- package/dist/retriever.js.map +1 -1
- package/dist/storage/fs-blob-store.d.ts +31 -0
- package/dist/storage/fs-blob-store.d.ts.map +1 -0
- package/dist/storage/fs-blob-store.js +163 -0
- package/dist/storage/fs-blob-store.js.map +1 -0
- package/dist/storage/index.d.ts +11 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +4 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/mongo-blob-store.d.ts +50 -0
- package/dist/storage/mongo-blob-store.d.ts.map +1 -0
- package/dist/storage/mongo-blob-store.js +264 -0
- package/dist/storage/mongo-blob-store.js.map +1 -0
- package/dist/storage/ports.d.ts +135 -0
- package/dist/storage/ports.d.ts.map +1 -0
- package/dist/storage/ports.js +12 -0
- package/dist/storage/ports.js.map +1 -0
- package/dist/storage/resolve.d.ts +78 -0
- package/dist/storage/resolve.d.ts.map +1 -0
- package/dist/storage/resolve.js +208 -0
- package/dist/storage/resolve.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/vector-recall.d.ts +30 -0
- package/dist/vector-recall.d.ts.map +1 -0
- package/dist/vector-recall.js +32 -0
- package/dist/vector-recall.js.map +1 -0
- package/dist/vector-store.d.ts +61 -10
- package/dist/vector-store.d.ts.map +1 -1
- package/dist/vector-store.js +188 -23
- package/dist/vector-store.js.map +1 -1
- package/package.json +4 -3
|
@@ -48,219 +48,89 @@ function safeReadFile(filePath) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
// ---------------------------------------------------------------------------
|
|
51
|
-
//
|
|
51
|
+
// EXTRACT — one repo's tree → serializable signals
|
|
52
52
|
// ---------------------------------------------------------------------------
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
...Object.keys(pkg.peerDependencies ?? {}),
|
|
67
|
-
]);
|
|
68
|
-
// Filter to scoped/workspace packages (likely internal)
|
|
69
|
-
const orgDeps = new Set([...allDeps].filter(d => d.startsWith('@')));
|
|
70
|
-
repoDeps.set(repo.name, orgDeps);
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
// Malformed package.json
|
|
74
|
-
}
|
|
53
|
+
function extractNpmDeps(repoPath) {
|
|
54
|
+
const content = safeReadFile(join(repoPath, 'package.json'));
|
|
55
|
+
if (!content)
|
|
56
|
+
return [];
|
|
57
|
+
try {
|
|
58
|
+
const pkg = JSON.parse(content);
|
|
59
|
+
const allDeps = new Set([
|
|
60
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
61
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
62
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
63
|
+
]);
|
|
64
|
+
// Filter to scoped/workspace packages (likely internal)
|
|
65
|
+
return [...allDeps].filter((d) => d.startsWith('@'));
|
|
75
66
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
79
|
-
const nameA = repoNames[i];
|
|
80
|
-
const nameB = repoNames[j];
|
|
81
|
-
const depsA = repoDeps.get(nameA);
|
|
82
|
-
const depsB = repoDeps.get(nameB);
|
|
83
|
-
for (const dep of depsA) {
|
|
84
|
-
if (depsB.has(dep)) {
|
|
85
|
-
edges.push({
|
|
86
|
-
sourceRepo: nameA,
|
|
87
|
-
sourceNode: `package.json::${dep}`,
|
|
88
|
-
targetRepo: nameB,
|
|
89
|
-
targetNode: `package.json::${dep}`,
|
|
90
|
-
edgeType: 'npm-dep',
|
|
91
|
-
evidence: `Shared scoped dependency: ${dep}`,
|
|
92
|
-
confidence: 0.7,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
67
|
+
catch {
|
|
68
|
+
return []; // Malformed package.json
|
|
97
69
|
}
|
|
98
|
-
return edges;
|
|
99
70
|
}
|
|
100
|
-
|
|
101
|
-
// Strategy 2: Shared TypeScript types
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
function detectSharedTypes(repos) {
|
|
104
|
-
const edges = [];
|
|
71
|
+
function extractTypes(repoPath) {
|
|
105
72
|
const typeExportPattern = /export\s+(?:interface|type)\s+(\w+)/g;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
repoTypes.set(repo.name, typeMap);
|
|
125
|
-
}
|
|
126
|
-
const repoNames = [...repoTypes.keys()];
|
|
127
|
-
for (let i = 0; i < repoNames.length; i++) {
|
|
128
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
129
|
-
const nameA = repoNames[i];
|
|
130
|
-
const nameB = repoNames[j];
|
|
131
|
-
const typesA = repoTypes.get(nameA);
|
|
132
|
-
const typesB = repoTypes.get(nameB);
|
|
133
|
-
for (const [typeName, fileA] of typesA) {
|
|
134
|
-
const fileB = typesB.get(typeName);
|
|
135
|
-
if (fileB) {
|
|
136
|
-
edges.push({
|
|
137
|
-
sourceRepo: nameA,
|
|
138
|
-
sourceNode: `${fileA}::${typeName}`,
|
|
139
|
-
targetRepo: nameB,
|
|
140
|
-
targetNode: `${fileB}::${typeName}`,
|
|
141
|
-
edgeType: 'shared-type',
|
|
142
|
-
evidence: `Shared type: ${typeName}`,
|
|
143
|
-
confidence: 0.9,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return edges;
|
|
73
|
+
const tsFiles = walkFiles(repoPath, (f) => {
|
|
74
|
+
const ext = extname(f);
|
|
75
|
+
return ext === '.ts' || ext === '.d.ts';
|
|
76
|
+
}, 2000);
|
|
77
|
+
const typeMap = {};
|
|
78
|
+
for (const filePath of tsFiles) {
|
|
79
|
+
const content = safeReadFile(filePath);
|
|
80
|
+
let match;
|
|
81
|
+
typeExportPattern.lastIndex = 0;
|
|
82
|
+
while ((match = typeExportPattern.exec(content)) !== null) {
|
|
83
|
+
const typeName = match[1];
|
|
84
|
+
if (!(typeName in typeMap))
|
|
85
|
+
typeMap[typeName] = filePath;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return typeMap;
|
|
150
89
|
}
|
|
151
|
-
|
|
152
|
-
// Strategy 3: Environment variable correlation
|
|
153
|
-
// ---------------------------------------------------------------------------
|
|
154
|
-
function detectEnvVarCorrelation(repos) {
|
|
155
|
-
const edges = [];
|
|
90
|
+
function extractEnvVars(repoPath) {
|
|
156
91
|
const envFileNames = ['.env.example', '.env.template', '.env.sample'];
|
|
157
92
|
const envVarPattern = /^([A-Z][A-Z0-9_]{2,})=/gm;
|
|
158
|
-
const
|
|
159
|
-
for (const
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
while ((match = envVarPattern.exec(content)) !== null) {
|
|
168
|
-
vars.add(match[1]);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (vars.size > 0) {
|
|
172
|
-
repoEnvVars.set(repo.name, vars);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const repoNames = [...repoEnvVars.keys()];
|
|
176
|
-
for (let i = 0; i < repoNames.length; i++) {
|
|
177
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
178
|
-
const nameA = repoNames[i];
|
|
179
|
-
const nameB = repoNames[j];
|
|
180
|
-
const varsA = repoEnvVars.get(nameA);
|
|
181
|
-
const varsB = repoEnvVars.get(nameB);
|
|
182
|
-
for (const v of varsA) {
|
|
183
|
-
if (varsB.has(v)) {
|
|
184
|
-
edges.push({
|
|
185
|
-
sourceRepo: nameA,
|
|
186
|
-
sourceNode: `env::${v}`,
|
|
187
|
-
targetRepo: nameB,
|
|
188
|
-
targetNode: `env::${v}`,
|
|
189
|
-
edgeType: 'env-var',
|
|
190
|
-
evidence: `Shared env var: ${v}`,
|
|
191
|
-
confidence: 0.6,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
93
|
+
const vars = new Set();
|
|
94
|
+
for (const envFile of envFileNames) {
|
|
95
|
+
const content = safeReadFile(join(repoPath, envFile));
|
|
96
|
+
if (!content)
|
|
97
|
+
continue;
|
|
98
|
+
let match;
|
|
99
|
+
envVarPattern.lastIndex = 0;
|
|
100
|
+
while ((match = envVarPattern.exec(content)) !== null) {
|
|
101
|
+
vars.add(match[1]);
|
|
195
102
|
}
|
|
196
103
|
}
|
|
197
|
-
return
|
|
104
|
+
return [...vars];
|
|
198
105
|
}
|
|
199
|
-
|
|
200
|
-
// Strategy 4: Event schema detection (topics, channels, events in constants)
|
|
201
|
-
// ---------------------------------------------------------------------------
|
|
202
|
-
function detectEventSchemas(repos) {
|
|
203
|
-
const edges = [];
|
|
106
|
+
function extractEvents(repoPath) {
|
|
204
107
|
// Match patterns like: TOPIC = 'user.created', channel: 'orders', event: 'payment_completed'
|
|
205
108
|
const eventPatterns = [
|
|
206
109
|
/(?:topic|TOPIC|channel|CHANNEL|event|EVENT)\s*[:=]\s*['"`]([a-zA-Z0-9._-]+)['"`]/g,
|
|
207
110
|
/(?:subscribe|publish|emit|on)\s*\(\s*['"`]([a-zA-Z0-9._-]+)['"`]/g,
|
|
208
111
|
];
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
for (const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (eventName.length > 3 && eventName.includes('.')) {
|
|
225
|
-
if (!eventMap.has(eventName)) {
|
|
226
|
-
eventMap.set(eventName, filePath);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
repoEvents.set(repo.name, eventMap);
|
|
233
|
-
}
|
|
234
|
-
const repoNames = [...repoEvents.keys()];
|
|
235
|
-
for (let i = 0; i < repoNames.length; i++) {
|
|
236
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
237
|
-
const nameA = repoNames[i];
|
|
238
|
-
const nameB = repoNames[j];
|
|
239
|
-
const eventsA = repoEvents.get(nameA);
|
|
240
|
-
const eventsB = repoEvents.get(nameB);
|
|
241
|
-
for (const [eventName, fileA] of eventsA) {
|
|
242
|
-
const fileB = eventsB.get(eventName);
|
|
243
|
-
if (fileB) {
|
|
244
|
-
edges.push({
|
|
245
|
-
sourceRepo: nameA,
|
|
246
|
-
sourceNode: `${fileA}::${eventName}`,
|
|
247
|
-
targetRepo: nameB,
|
|
248
|
-
targetNode: `${fileB}::${eventName}`,
|
|
249
|
-
edgeType: 'event-schema',
|
|
250
|
-
evidence: `Shared event/topic: ${eventName}`,
|
|
251
|
-
confidence: 0.85,
|
|
252
|
-
});
|
|
112
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
113
|
+
const ext = extname(f);
|
|
114
|
+
return ['.ts', '.js', '.py', '.go', '.java'].includes(ext);
|
|
115
|
+
}, 3000);
|
|
116
|
+
const eventMap = {};
|
|
117
|
+
for (const filePath of sourceFiles) {
|
|
118
|
+
const content = safeReadFile(filePath);
|
|
119
|
+
for (const pattern of eventPatterns) {
|
|
120
|
+
pattern.lastIndex = 0;
|
|
121
|
+
let match;
|
|
122
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
123
|
+
const eventName = match[1];
|
|
124
|
+
// Filter out overly generic names
|
|
125
|
+
if (eventName.length > 3 && eventName.includes('.') && !(eventName in eventMap)) {
|
|
126
|
+
eventMap[eventName] = filePath;
|
|
253
127
|
}
|
|
254
128
|
}
|
|
255
129
|
}
|
|
256
130
|
}
|
|
257
|
-
return
|
|
131
|
+
return eventMap;
|
|
258
132
|
}
|
|
259
|
-
|
|
260
|
-
// Strategy 5: API endpoint matching (route defs vs HTTP client calls)
|
|
261
|
-
// ---------------------------------------------------------------------------
|
|
262
|
-
function detectApiEndpoints(repos) {
|
|
263
|
-
const edges = [];
|
|
133
|
+
function extractApiEndpoints(repoPath) {
|
|
264
134
|
// Route definition patterns
|
|
265
135
|
const routeDefPatterns = [
|
|
266
136
|
/(?:app|router)\.(get|post|put|patch|delete)\s*\(\s*['"`](\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
@@ -271,631 +141,292 @@ function detectApiEndpoints(repos) {
|
|
|
271
141
|
/(?:axios|fetch|http|client)\.(get|post|put|patch|delete)\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
272
142
|
/fetch\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
273
143
|
];
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const routePath = match[2].replace(/:[a-zA-Z]+/g, ':param');
|
|
291
|
-
if (!routes.has(routePath)) {
|
|
292
|
-
routes.set(routePath, filePath);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
for (const pattern of httpCallPatterns) {
|
|
297
|
-
pattern.lastIndex = 0;
|
|
298
|
-
let match;
|
|
299
|
-
while ((match = pattern.exec(content)) !== null) {
|
|
300
|
-
const clientPath = match[2].replace(/:[a-zA-Z]+/g, ':param');
|
|
301
|
-
if (!clients.has(clientPath)) {
|
|
302
|
-
clients.set(clientPath, filePath);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
repoRoutes.set(repo.name, routes);
|
|
308
|
-
repoClients.set(repo.name, clients);
|
|
309
|
-
}
|
|
310
|
-
// Match routes in one repo to client calls in another
|
|
311
|
-
for (const [routeRepo, routes] of repoRoutes) {
|
|
312
|
-
for (const [clientRepo, clients] of repoClients) {
|
|
313
|
-
if (routeRepo === clientRepo)
|
|
314
|
-
continue;
|
|
315
|
-
for (const [routePath, routeFile] of routes) {
|
|
316
|
-
const clientFile = clients.get(routePath);
|
|
317
|
-
if (clientFile) {
|
|
318
|
-
edges.push({
|
|
319
|
-
sourceRepo: clientRepo,
|
|
320
|
-
sourceNode: `${clientFile}::${routePath}`,
|
|
321
|
-
targetRepo: routeRepo,
|
|
322
|
-
targetNode: `${routeFile}::${routePath}`,
|
|
323
|
-
edgeType: 'http',
|
|
324
|
-
evidence: `API endpoint: ${routePath}`,
|
|
325
|
-
confidence: 0.8,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
144
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
145
|
+
const ext = extname(f);
|
|
146
|
+
return ['.ts', '.js'].includes(ext);
|
|
147
|
+
}, 3000);
|
|
148
|
+
const routes = {};
|
|
149
|
+
const clients = {};
|
|
150
|
+
for (const filePath of sourceFiles) {
|
|
151
|
+
const content = safeReadFile(filePath);
|
|
152
|
+
for (const pattern of routeDefPatterns) {
|
|
153
|
+
pattern.lastIndex = 0;
|
|
154
|
+
let match;
|
|
155
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
156
|
+
// Normalize path: strip params to base pattern
|
|
157
|
+
const routePath = match[2].replace(/:[a-zA-Z]+/g, ':param');
|
|
158
|
+
if (!(routePath in routes))
|
|
159
|
+
routes[routePath] = filePath;
|
|
328
160
|
}
|
|
329
161
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
const edges = [];
|
|
338
|
-
for (const repo of repos) {
|
|
339
|
-
const wsMap = workspaceMaps?.get(repo.name) ?? detectWorkspace(repo.path);
|
|
340
|
-
if (wsMap.packages.length < 2)
|
|
341
|
-
continue; // not a meaningful workspace
|
|
342
|
-
// For each package, check if its manifest deps reference a sibling package
|
|
343
|
-
for (const pkg of wsMap.packages) {
|
|
344
|
-
for (const depName of pkg.dependencies) {
|
|
345
|
-
const target = wsMap.nameToPackage.get(depName);
|
|
346
|
-
if (target && target.name !== pkg.name) {
|
|
347
|
-
edges.push({
|
|
348
|
-
sourceRepo: repo.name,
|
|
349
|
-
sourceNode: `pkg::${pkg.name}`,
|
|
350
|
-
targetRepo: repo.name,
|
|
351
|
-
targetNode: `pkg::${target.name}`,
|
|
352
|
-
edgeType: 'workspace-dep',
|
|
353
|
-
evidence: `${pkg.name} depends on ${target.name} (${pkg.manifestFile})`,
|
|
354
|
-
confidence: 1.0,
|
|
355
|
-
});
|
|
356
|
-
}
|
|
162
|
+
for (const pattern of httpCallPatterns) {
|
|
163
|
+
pattern.lastIndex = 0;
|
|
164
|
+
let match;
|
|
165
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
166
|
+
const clientPath = match[2].replace(/:[a-zA-Z]+/g, ':param');
|
|
167
|
+
if (!(clientPath in clients))
|
|
168
|
+
clients[clientPath] = filePath;
|
|
357
169
|
}
|
|
358
170
|
}
|
|
359
171
|
}
|
|
360
|
-
return
|
|
172
|
+
return { routes, clients };
|
|
361
173
|
}
|
|
362
|
-
|
|
363
|
-
// Strategy 7: gRPC/Proto Service Detection
|
|
364
|
-
// ---------------------------------------------------------------------------
|
|
365
|
-
function detectGrpcServices(repos) {
|
|
366
|
-
const edges = [];
|
|
174
|
+
function extractGrpc(repoPath) {
|
|
367
175
|
const serviceDefPattern = /service\s+(\w+)\s*\{[^}]*rpc\s+(\w+)/gs;
|
|
368
176
|
const tsClientPattern = /import\s*\{[^}]*(\w+)Client[^}]*\}\s*from\s*['"][^'"]*_grpc_pb['"]/g;
|
|
369
177
|
const goClientPattern = /pb\.New(\w+)Client\s*\(/g;
|
|
370
|
-
//
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
for (const
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
while ((match = goClientPattern.exec(content)) !== null) {
|
|
401
|
-
serviceClients.set(match[1], filePath);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
repoServiceClients.set(repo.name, serviceClients);
|
|
405
|
-
}
|
|
406
|
-
// Match service defs in one repo with client usage in another
|
|
407
|
-
for (const [defRepo, defs] of repoServiceDefs) {
|
|
408
|
-
for (const [clientRepo, clients] of repoServiceClients) {
|
|
409
|
-
if (defRepo === clientRepo)
|
|
410
|
-
continue;
|
|
411
|
-
for (const [serviceName, defFile] of defs) {
|
|
412
|
-
const clientFile = clients.get(serviceName);
|
|
413
|
-
if (clientFile) {
|
|
414
|
-
edges.push({
|
|
415
|
-
sourceRepo: clientRepo,
|
|
416
|
-
sourceNode: `${clientFile}::${serviceName}Client`,
|
|
417
|
-
targetRepo: defRepo,
|
|
418
|
-
targetNode: `${defFile}::${serviceName}`,
|
|
419
|
-
edgeType: 'grpc',
|
|
420
|
-
evidence: `gRPC service: ${serviceName}`,
|
|
421
|
-
confidence: 0.9,
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
return edges;
|
|
178
|
+
// Scan .proto files for service definitions
|
|
179
|
+
const protoFiles = walkFiles(repoPath, (f) => extname(f) === '.proto', 500);
|
|
180
|
+
const defs = {};
|
|
181
|
+
for (const filePath of protoFiles) {
|
|
182
|
+
const content = safeReadFile(filePath);
|
|
183
|
+
serviceDefPattern.lastIndex = 0;
|
|
184
|
+
let match;
|
|
185
|
+
while ((match = serviceDefPattern.exec(content)) !== null) {
|
|
186
|
+
defs[match[1]] = filePath;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Scan source files for client usage
|
|
190
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
191
|
+
const ext = extname(f);
|
|
192
|
+
return ['.ts', '.js', '.go'].includes(ext);
|
|
193
|
+
}, 3000);
|
|
194
|
+
const clients = {};
|
|
195
|
+
for (const filePath of sourceFiles) {
|
|
196
|
+
const content = safeReadFile(filePath);
|
|
197
|
+
tsClientPattern.lastIndex = 0;
|
|
198
|
+
let match;
|
|
199
|
+
while ((match = tsClientPattern.exec(content)) !== null) {
|
|
200
|
+
clients[match[1]] = filePath;
|
|
201
|
+
}
|
|
202
|
+
goClientPattern.lastIndex = 0;
|
|
203
|
+
while ((match = goClientPattern.exec(content)) !== null) {
|
|
204
|
+
clients[match[1]] = filePath;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { defs, clients };
|
|
428
208
|
}
|
|
429
|
-
|
|
430
|
-
// Strategy 8: Database Schema Correlation
|
|
431
|
-
// ---------------------------------------------------------------------------
|
|
432
|
-
function detectDatabaseSchemas(repos) {
|
|
433
|
-
const edges = [];
|
|
209
|
+
function extractDbTables(repoPath) {
|
|
434
210
|
const sqlCreatePattern = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?["`]?(\w+)["`]?/gi;
|
|
435
211
|
const sqlQueryPattern = /(?:FROM|INTO|JOIN|UPDATE)\s+["`]?(\w+)["`]?/gi;
|
|
436
212
|
const typeormPattern = /@Entity\s*\(\s*['"`](\w+)['"`]\s*\)/g;
|
|
437
213
|
const gormPattern = /TableName\s*\(\s*\)\s*string\s*\{\s*return\s*["'](\w+)["']/g;
|
|
438
214
|
const sequelizePattern = /sequelize\.define\s*\(\s*['"`](\w+)['"`]/g;
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
for (const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if (tableName.length > 2 && !skipTables.has(tableName)) {
|
|
463
|
-
if (!tableMap.has(tableName)) {
|
|
464
|
-
tableMap.set(tableName, filePath);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
repoTables.set(repo.name, tableMap);
|
|
471
|
-
}
|
|
472
|
-
const repoNames = [...repoTables.keys()];
|
|
473
|
-
for (let i = 0; i < repoNames.length; i++) {
|
|
474
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
475
|
-
const nameA = repoNames[i];
|
|
476
|
-
const nameB = repoNames[j];
|
|
477
|
-
const tablesA = repoTables.get(nameA);
|
|
478
|
-
const tablesB = repoTables.get(nameB);
|
|
479
|
-
for (const [tableName, fileA] of tablesA) {
|
|
480
|
-
const fileB = tablesB.get(tableName);
|
|
481
|
-
if (fileB) {
|
|
482
|
-
edges.push({
|
|
483
|
-
sourceRepo: nameA,
|
|
484
|
-
sourceNode: `${fileA}::${tableName}`,
|
|
485
|
-
targetRepo: nameB,
|
|
486
|
-
targetNode: `${fileB}::${tableName}`,
|
|
487
|
-
edgeType: 'database',
|
|
488
|
-
evidence: `Shared table: ${tableName}`,
|
|
489
|
-
confidence: 0.85,
|
|
490
|
-
});
|
|
215
|
+
const tableMap = {};
|
|
216
|
+
// SQL migration files
|
|
217
|
+
const sqlFiles = walkFiles(repoPath, (f) => {
|
|
218
|
+
const lower = f.toLowerCase();
|
|
219
|
+
return lower.endsWith('.sql') || lower.includes('migration');
|
|
220
|
+
}, 1000);
|
|
221
|
+
// Source files for ORM patterns and raw queries
|
|
222
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
223
|
+
const ext = extname(f);
|
|
224
|
+
return ['.ts', '.js', '.go', '.py', '.java'].includes(ext);
|
|
225
|
+
}, 3000);
|
|
226
|
+
const allFiles = [...sqlFiles, ...sourceFiles];
|
|
227
|
+
const patterns = [sqlCreatePattern, sqlQueryPattern, typeormPattern, gormPattern, sequelizePattern];
|
|
228
|
+
const skipTables = new Set(['information_schema', 'pg_catalog', 'dual', 'sqlite_master', 'schema_migrations']);
|
|
229
|
+
for (const filePath of allFiles) {
|
|
230
|
+
const content = safeReadFile(filePath);
|
|
231
|
+
for (const pattern of patterns) {
|
|
232
|
+
pattern.lastIndex = 0;
|
|
233
|
+
let match;
|
|
234
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
235
|
+
const tableName = match[1].toLowerCase();
|
|
236
|
+
if (tableName.length > 2 && !skipTables.has(tableName) && !(tableName in tableMap)) {
|
|
237
|
+
tableMap[tableName] = filePath;
|
|
491
238
|
}
|
|
492
239
|
}
|
|
493
240
|
}
|
|
494
241
|
}
|
|
495
|
-
return
|
|
242
|
+
return tableMap;
|
|
496
243
|
}
|
|
497
|
-
|
|
498
|
-
// Strategy 9: Redis Key Pattern Detection
|
|
499
|
-
// ---------------------------------------------------------------------------
|
|
500
|
-
function detectRedisKeyPatterns(repos) {
|
|
501
|
-
const edges = [];
|
|
244
|
+
function extractRedisPrefixes(repoPath) {
|
|
502
245
|
const redisPatterns = [
|
|
503
246
|
/(?:redis|cache|rdb)\.(get|set|del|hget|hset|sadd|srem)\s*\(\s*(?:ctx,\s*)?['"`]([a-zA-Z0-9_:-]+)/g,
|
|
504
247
|
/(?:redis|cache|rdb)\.(?:Get|Set|Del|HGet|HSet)\s*\(\s*ctx\s*,\s*["']([a-zA-Z0-9_:-]+)/g,
|
|
505
248
|
];
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const
|
|
513
|
-
for (const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
if (prefix.length > 3 && !prefixMap.has(prefix)) {
|
|
527
|
-
prefixMap.set(prefix, filePath);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
repoKeyPrefixes.set(repo.name, prefixMap);
|
|
533
|
-
}
|
|
534
|
-
const repoNames = [...repoKeyPrefixes.keys()];
|
|
535
|
-
for (let i = 0; i < repoNames.length; i++) {
|
|
536
|
-
for (let j = i + 1; j < repoNames.length; j++) {
|
|
537
|
-
const nameA = repoNames[i];
|
|
538
|
-
const nameB = repoNames[j];
|
|
539
|
-
const prefixesA = repoKeyPrefixes.get(nameA);
|
|
540
|
-
const prefixesB = repoKeyPrefixes.get(nameB);
|
|
541
|
-
for (const [prefix, fileA] of prefixesA) {
|
|
542
|
-
const fileB = prefixesB.get(prefix);
|
|
543
|
-
if (fileB) {
|
|
544
|
-
edges.push({
|
|
545
|
-
sourceRepo: nameA,
|
|
546
|
-
sourceNode: `${fileA}::redis:${prefix}`,
|
|
547
|
-
targetRepo: nameB,
|
|
548
|
-
targetNode: `${fileB}::redis:${prefix}`,
|
|
549
|
-
edgeType: 'redis',
|
|
550
|
-
evidence: `Shared Redis key prefix: ${prefix}`,
|
|
551
|
-
confidence: 0.75,
|
|
552
|
-
});
|
|
249
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
250
|
+
const ext = extname(f);
|
|
251
|
+
return ['.ts', '.js', '.go', '.py', '.java'].includes(ext);
|
|
252
|
+
}, 3000);
|
|
253
|
+
const prefixMap = {};
|
|
254
|
+
for (const filePath of sourceFiles) {
|
|
255
|
+
const content = safeReadFile(filePath);
|
|
256
|
+
for (const pattern of redisPatterns) {
|
|
257
|
+
pattern.lastIndex = 0;
|
|
258
|
+
let match;
|
|
259
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
260
|
+
// Extract the key — could be in group 2 (first pattern) or group 1 (second pattern)
|
|
261
|
+
const key = match[2] ?? match[1];
|
|
262
|
+
// Extract prefix: everything before first interpolation marker or take full key up to second colon
|
|
263
|
+
const colonParts = key.split(':');
|
|
264
|
+
const prefix = colonParts.length >= 2
|
|
265
|
+
? `${colonParts[0]}:${colonParts[1]}`
|
|
266
|
+
: key;
|
|
267
|
+
if (prefix.length > 3 && !(prefix in prefixMap)) {
|
|
268
|
+
prefixMap[prefix] = filePath;
|
|
553
269
|
}
|
|
554
270
|
}
|
|
555
271
|
}
|
|
556
272
|
}
|
|
557
|
-
return
|
|
273
|
+
return prefixMap;
|
|
558
274
|
}
|
|
559
|
-
|
|
560
|
-
// Strategy 10: S3/GCS Bucket Detection
|
|
561
|
-
// ---------------------------------------------------------------------------
|
|
562
|
-
function detectS3Buckets(repos) {
|
|
563
|
-
const edges = [];
|
|
275
|
+
function extractBuckets(repoPath) {
|
|
564
276
|
const s3Patterns = [
|
|
565
277
|
/s3\.(?:putObject|getObject|deleteObject|upload|headObject)\s*\(\s*\{[^}]*Bucket\s*:\s*['"`]([a-zA-Z0-9._-]+)['"`]/gs,
|
|
566
278
|
/new\s+(?:S3|AWS\.S3)\s*\([^)]*\)[^;]*\.(?:putObject|getObject)\s*\(\s*\{[^}]*Bucket\s*:\s*['"`]([a-zA-Z0-9._-]+)['"`]/gs,
|
|
567
279
|
/storage\.bucket\s*\(\s*['"`]([a-zA-Z0-9._-]+)['"`]\s*\)/g,
|
|
568
280
|
];
|
|
569
281
|
const envBucketPattern = /(?:S3_BUCKET|GCS_BUCKET|BUCKET_NAME|AWS_BUCKET)\s*=\s*['"`]?([a-zA-Z0-9._-]+)['"`]?/g;
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
for (const
|
|
579
|
-
|
|
580
|
-
for (const pattern of s3Patterns) {
|
|
581
|
-
pattern.lastIndex = 0;
|
|
582
|
-
let match;
|
|
583
|
-
while ((match = pattern.exec(content)) !== null) {
|
|
584
|
-
const bucket = match[1];
|
|
585
|
-
if (bucket && !bucketMap.has(bucket)) {
|
|
586
|
-
bucketMap.set(bucket, filePath);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
envBucketPattern.lastIndex = 0;
|
|
282
|
+
const bucketMap = {};
|
|
283
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
284
|
+
const ext = extname(f);
|
|
285
|
+
return ['.ts', '.js', '.go', '.py', '.java', '.env', '.yaml', '.yml'].includes(ext)
|
|
286
|
+
|| f.endsWith('.env.example') || f.endsWith('.env.template');
|
|
287
|
+
}, 3000);
|
|
288
|
+
for (const filePath of sourceFiles) {
|
|
289
|
+
const content = safeReadFile(filePath);
|
|
290
|
+
for (const pattern of s3Patterns) {
|
|
291
|
+
pattern.lastIndex = 0;
|
|
591
292
|
let match;
|
|
592
|
-
while ((match =
|
|
293
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
593
294
|
const bucket = match[1];
|
|
594
|
-
if (bucket && bucket
|
|
595
|
-
bucketMap
|
|
596
|
-
}
|
|
295
|
+
if (bucket && !(bucket in bucketMap))
|
|
296
|
+
bucketMap[bucket] = filePath;
|
|
597
297
|
}
|
|
598
298
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const nameB = repoNames[j];
|
|
606
|
-
const bucketsA = repoBuckets.get(nameA);
|
|
607
|
-
const bucketsB = repoBuckets.get(nameB);
|
|
608
|
-
for (const [bucket, fileA] of bucketsA) {
|
|
609
|
-
const fileB = bucketsB.get(bucket);
|
|
610
|
-
if (fileB) {
|
|
611
|
-
edges.push({
|
|
612
|
-
sourceRepo: nameA,
|
|
613
|
-
sourceNode: `${fileA}::s3:${bucket}`,
|
|
614
|
-
targetRepo: nameB,
|
|
615
|
-
targetNode: `${fileB}::s3:${bucket}`,
|
|
616
|
-
edgeType: 's3',
|
|
617
|
-
evidence: `Shared bucket: ${bucket}`,
|
|
618
|
-
confidence: 0.8,
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
}
|
|
299
|
+
envBucketPattern.lastIndex = 0;
|
|
300
|
+
let match;
|
|
301
|
+
while ((match = envBucketPattern.exec(content)) !== null) {
|
|
302
|
+
const bucket = match[1];
|
|
303
|
+
if (bucket && bucket.length > 3 && !(bucket in bucketMap))
|
|
304
|
+
bucketMap[bucket] = filePath;
|
|
622
305
|
}
|
|
623
306
|
}
|
|
624
|
-
return
|
|
307
|
+
return bucketMap;
|
|
625
308
|
}
|
|
626
|
-
|
|
627
|
-
// Strategy 11: OpenAPI Schema References
|
|
628
|
-
// ---------------------------------------------------------------------------
|
|
629
|
-
function detectOpenApiSchemas(repos) {
|
|
630
|
-
const edges = [];
|
|
309
|
+
function extractOpenApi(repoPath) {
|
|
631
310
|
const openApiFileNames = ['openapi.yaml', 'openapi.yml', 'openapi.json', 'swagger.yaml', 'swagger.yml', 'swagger.json'];
|
|
632
311
|
const pathPattern = /^\s*(?:\/[a-zA-Z0-9/:._{}*-]+)\s*:/gm;
|
|
633
312
|
const jsonPathPattern = /"(\/[a-zA-Z0-9/:._{}*-]+)"\s*:/g;
|
|
634
|
-
// repo -> endpoint paths -> filePath
|
|
635
|
-
const repoApiPaths = new Map();
|
|
636
313
|
// HTTP client patterns (complement to Strategy 5)
|
|
637
314
|
const httpCallPatterns = [
|
|
638
315
|
/(?:axios|fetch|http|client|httpGet|httpPost|httpPut|httpDelete)\s*\(\s*[^,]*?,?\s*['"`](\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
639
316
|
/fetch\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
640
317
|
];
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const path = match[1].replace(/\{[^}]+\}/g, ':param');
|
|
656
|
-
if (!apiPaths.has(path)) {
|
|
657
|
-
apiPaths.set(path, filePath);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
pathPattern.lastIndex = 0;
|
|
663
|
-
let match;
|
|
664
|
-
while ((match = pathPattern.exec(content)) !== null) {
|
|
665
|
-
const rawPath = match[0].trim().replace(/:$/, '').trim();
|
|
666
|
-
if (rawPath.startsWith('/')) {
|
|
667
|
-
const normalized = rawPath.replace(/\{[^}]+\}/g, ':param');
|
|
668
|
-
if (!apiPaths.has(normalized)) {
|
|
669
|
-
apiPaths.set(normalized, filePath);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
repoApiPaths.set(repo.name, apiPaths);
|
|
676
|
-
// Scan for HTTP client calls
|
|
677
|
-
const sourceFiles = walkFiles(repo.path, (f) => {
|
|
678
|
-
const ext = extname(f);
|
|
679
|
-
return ['.ts', '.js'].includes(ext);
|
|
680
|
-
}, 3000);
|
|
681
|
-
const httpCalls = new Map();
|
|
682
|
-
for (const filePath of sourceFiles) {
|
|
683
|
-
const content = safeReadFile(filePath);
|
|
684
|
-
for (const pattern of httpCallPatterns) {
|
|
685
|
-
pattern.lastIndex = 0;
|
|
686
|
-
let match;
|
|
687
|
-
while ((match = pattern.exec(content)) !== null) {
|
|
688
|
-
const callPath = (match[2] ?? match[1]).replace(/:[a-zA-Z]+/g, ':param');
|
|
689
|
-
if (!httpCalls.has(callPath)) {
|
|
690
|
-
httpCalls.set(callPath, filePath);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
318
|
+
const specPaths = {};
|
|
319
|
+
const specFiles = walkFiles(repoPath, (f) => {
|
|
320
|
+
const basename = f.split('/').pop() ?? '';
|
|
321
|
+
return openApiFileNames.includes(basename);
|
|
322
|
+
}, 200);
|
|
323
|
+
for (const filePath of specFiles) {
|
|
324
|
+
const content = safeReadFile(filePath);
|
|
325
|
+
if (filePath.endsWith('.json')) {
|
|
326
|
+
jsonPathPattern.lastIndex = 0;
|
|
327
|
+
let match;
|
|
328
|
+
while ((match = jsonPathPattern.exec(content)) !== null) {
|
|
329
|
+
const path = match[1].replace(/\{[^}]+\}/g, ':param');
|
|
330
|
+
if (!(path in specPaths))
|
|
331
|
+
specPaths[path] = filePath;
|
|
693
332
|
}
|
|
694
333
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
334
|
+
else {
|
|
335
|
+
pathPattern.lastIndex = 0;
|
|
336
|
+
let match;
|
|
337
|
+
while ((match = pathPattern.exec(content)) !== null) {
|
|
338
|
+
const rawPath = match[0].trim().replace(/:$/, '').trim();
|
|
339
|
+
if (rawPath.startsWith('/')) {
|
|
340
|
+
const normalized = rawPath.replace(/\{[^}]+\}/g, ':param');
|
|
341
|
+
if (!(normalized in specPaths))
|
|
342
|
+
specPaths[normalized] = filePath;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// Scan for HTTP client calls
|
|
348
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
349
|
+
const ext = extname(f);
|
|
350
|
+
return ['.ts', '.js'].includes(ext);
|
|
351
|
+
}, 3000);
|
|
352
|
+
const httpCalls = {};
|
|
353
|
+
for (const filePath of sourceFiles) {
|
|
354
|
+
const content = safeReadFile(filePath);
|
|
355
|
+
for (const pattern of httpCallPatterns) {
|
|
356
|
+
pattern.lastIndex = 0;
|
|
357
|
+
let match;
|
|
358
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
359
|
+
const callPath = (match[2] ?? match[1]).replace(/:[a-zA-Z]+/g, ':param');
|
|
360
|
+
if (!(callPath in httpCalls))
|
|
361
|
+
httpCalls[callPath] = filePath;
|
|
715
362
|
}
|
|
716
363
|
}
|
|
717
364
|
}
|
|
718
|
-
return
|
|
365
|
+
return { specPaths, httpCalls };
|
|
719
366
|
}
|
|
720
|
-
|
|
721
|
-
// Strategy 12: Docker Compose Service Links
|
|
722
|
-
// ---------------------------------------------------------------------------
|
|
723
|
-
function detectDockerComposeLinks(repos) {
|
|
724
|
-
const edges = [];
|
|
367
|
+
function extractComposeRefs(repoPath) {
|
|
725
368
|
const composeFiles = ['docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'];
|
|
726
|
-
// Extract service names and their dependencies from compose files
|
|
727
369
|
// Simplified YAML parsing via regex (no YAML parser dependency)
|
|
728
|
-
const serviceBlockPattern = /^\s{2}(\w[\w.-]*)\s*:/gm;
|
|
729
370
|
const dependsOnPattern = /depends_on\s*:\s*\n((?:\s+-\s+\w[\w.-]*\n?)+)/gm;
|
|
730
371
|
const dependsOnItemPattern = /^\s+-\s+(\w[\w.-]*)/gm;
|
|
731
372
|
const linksPattern = /links\s*:\s*\n((?:\s+-\s+\w[\w.-]*(?::\w[\w.-]*)?\n?)+)/gm;
|
|
732
373
|
const linksItemPattern = /^\s+-\s+(\w[\w.-]*)/gm;
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const services = new Set();
|
|
762
|
-
let match;
|
|
763
|
-
while ((match = serviceBlockPattern.exec(content)) !== null) {
|
|
764
|
-
services.add(match[1]);
|
|
765
|
-
}
|
|
766
|
-
// Extract depends_on links
|
|
767
|
-
dependsOnPattern.lastIndex = 0;
|
|
768
|
-
while ((match = dependsOnPattern.exec(content)) !== null) {
|
|
769
|
-
const block = match[1];
|
|
770
|
-
dependsOnItemPattern.lastIndex = 0;
|
|
771
|
-
let dep;
|
|
772
|
-
while ((dep = dependsOnItemPattern.exec(block)) !== null) {
|
|
773
|
-
const depService = dep[1];
|
|
774
|
-
const normalizedDep = normalizeServiceName(depService);
|
|
775
|
-
const targetRepo = repoNameMap.get(normalizedDep);
|
|
776
|
-
if (targetRepo && targetRepo !== repo.name) {
|
|
777
|
-
edges.push({
|
|
778
|
-
sourceRepo: repo.name,
|
|
779
|
-
sourceNode: `${filePath}::compose`,
|
|
780
|
-
targetRepo,
|
|
781
|
-
targetNode: `service::${depService}`,
|
|
782
|
-
edgeType: 'http',
|
|
783
|
-
evidence: `Docker Compose depends_on: ${depService}`,
|
|
784
|
-
confidence: 0.85,
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
// Extract links
|
|
790
|
-
linksPattern.lastIndex = 0;
|
|
791
|
-
while ((match = linksPattern.exec(content)) !== null) {
|
|
792
|
-
const block = match[1];
|
|
793
|
-
linksItemPattern.lastIndex = 0;
|
|
794
|
-
let link;
|
|
795
|
-
while ((link = linksItemPattern.exec(block)) !== null) {
|
|
796
|
-
const linkService = link[1];
|
|
797
|
-
const normalizedLink = normalizeServiceName(linkService);
|
|
798
|
-
const targetRepo = repoNameMap.get(normalizedLink);
|
|
799
|
-
if (targetRepo && targetRepo !== repo.name) {
|
|
800
|
-
edges.push({
|
|
801
|
-
sourceRepo: repo.name,
|
|
802
|
-
sourceNode: `${filePath}::compose`,
|
|
803
|
-
targetRepo,
|
|
804
|
-
targetNode: `service::${linkService}`,
|
|
805
|
-
edgeType: 'http',
|
|
806
|
-
evidence: `Docker Compose link: ${linkService}`,
|
|
807
|
-
confidence: 0.85,
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
return edges;
|
|
374
|
+
const refs = [];
|
|
375
|
+
const foundFiles = walkFiles(repoPath, (f) => {
|
|
376
|
+
const basename = f.split('/').pop() ?? '';
|
|
377
|
+
return composeFiles.includes(basename);
|
|
378
|
+
}, 50);
|
|
379
|
+
for (const filePath of foundFiles) {
|
|
380
|
+
const content = safeReadFile(filePath);
|
|
381
|
+
dependsOnPattern.lastIndex = 0;
|
|
382
|
+
let match;
|
|
383
|
+
while ((match = dependsOnPattern.exec(content)) !== null) {
|
|
384
|
+
const block = match[1];
|
|
385
|
+
dependsOnItemPattern.lastIndex = 0;
|
|
386
|
+
let dep;
|
|
387
|
+
while ((dep = dependsOnItemPattern.exec(block)) !== null) {
|
|
388
|
+
refs.push({ file: filePath, service: dep[1], evidence: `Docker Compose depends_on: ${dep[1]}` });
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
linksPattern.lastIndex = 0;
|
|
392
|
+
while ((match = linksPattern.exec(content)) !== null) {
|
|
393
|
+
const block = match[1];
|
|
394
|
+
linksItemPattern.lastIndex = 0;
|
|
395
|
+
let link;
|
|
396
|
+
while ((link = linksItemPattern.exec(block)) !== null) {
|
|
397
|
+
refs.push({ file: filePath, service: link[1], evidence: `Docker Compose link: ${link[1]}` });
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return refs;
|
|
815
402
|
}
|
|
816
|
-
|
|
817
|
-
// Strategy 13: Kubernetes Service References
|
|
818
|
-
// ---------------------------------------------------------------------------
|
|
819
|
-
function detectK8sServiceRefs(repos) {
|
|
820
|
-
const edges = [];
|
|
821
|
-
const k8sServicePattern = /kind:\s*Service\s[\s\S]*?name:\s*["']?(\w[\w.-]*)["']?/gm;
|
|
822
|
-
const k8sDeployPattern = /kind:\s*Deployment\s[\s\S]*?name:\s*["']?(\w[\w.-]*)["']?/gm;
|
|
403
|
+
function extractK8sRefs(repoPath) {
|
|
823
404
|
const svcRefPattern = /["'](\w[\w.-]*)\.(\w[\w.-]*)\.svc(?:\.cluster\.local)?["']/g;
|
|
824
405
|
const envServiceUrlPattern = /(?:SERVICE_HOST|SERVICE_URL|_HOST|_URL)\s*:\s*["']?(\w[\w.-]*)(?:\.[\w.-]+)?\.svc/g;
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const lower = f.toLowerCase();
|
|
848
|
-
return lower.includes('k8s') || lower.includes('deploy') || lower.includes('manifests')
|
|
849
|
-
|| lower.includes('kustomiz') || lower.includes('kubernetes') || lower.includes('helm');
|
|
850
|
-
}, 500);
|
|
851
|
-
for (const filePath of k8sFiles) {
|
|
852
|
-
const content = safeReadFile(filePath);
|
|
853
|
-
// Extract service references via .svc DNS
|
|
854
|
-
svcRefPattern.lastIndex = 0;
|
|
855
|
-
let match;
|
|
856
|
-
while ((match = svcRefPattern.exec(content)) !== null) {
|
|
857
|
-
const svcName = match[1];
|
|
858
|
-
const normalized = normalizeK8sName(svcName);
|
|
859
|
-
const targetRepo = repoNameMap.get(normalized);
|
|
860
|
-
if (targetRepo && targetRepo !== repo.name) {
|
|
861
|
-
edges.push({
|
|
862
|
-
sourceRepo: repo.name,
|
|
863
|
-
sourceNode: `${filePath}::k8s-ref`,
|
|
864
|
-
targetRepo,
|
|
865
|
-
targetNode: `k8s-service::${svcName}`,
|
|
866
|
-
edgeType: 'http',
|
|
867
|
-
evidence: `K8s service DNS: ${svcName}.${match[2]}.svc`,
|
|
868
|
-
confidence: 0.8,
|
|
869
|
-
});
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
// Extract env var service references
|
|
873
|
-
envServiceUrlPattern.lastIndex = 0;
|
|
874
|
-
while ((match = envServiceUrlPattern.exec(content)) !== null) {
|
|
875
|
-
const svcName = match[1];
|
|
876
|
-
const normalized = normalizeK8sName(svcName);
|
|
877
|
-
const targetRepo = repoNameMap.get(normalized);
|
|
878
|
-
if (targetRepo && targetRepo !== repo.name) {
|
|
879
|
-
edges.push({
|
|
880
|
-
sourceRepo: repo.name,
|
|
881
|
-
sourceNode: `${filePath}::k8s-env`,
|
|
882
|
-
targetRepo,
|
|
883
|
-
targetNode: `k8s-service::${svcName}`,
|
|
884
|
-
edgeType: 'http',
|
|
885
|
-
evidence: `K8s env service ref: ${svcName}`,
|
|
886
|
-
confidence: 0.8,
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
return edges;
|
|
406
|
+
const refs = [];
|
|
407
|
+
const k8sFiles = walkFiles(repoPath, (f) => {
|
|
408
|
+
const ext = extname(f);
|
|
409
|
+
if (ext !== '.yaml' && ext !== '.yml')
|
|
410
|
+
return false;
|
|
411
|
+
const lower = f.toLowerCase();
|
|
412
|
+
return lower.includes('k8s') || lower.includes('deploy') || lower.includes('manifests')
|
|
413
|
+
|| lower.includes('kustomiz') || lower.includes('kubernetes') || lower.includes('helm');
|
|
414
|
+
}, 500);
|
|
415
|
+
for (const filePath of k8sFiles) {
|
|
416
|
+
const content = safeReadFile(filePath);
|
|
417
|
+
svcRefPattern.lastIndex = 0;
|
|
418
|
+
let match;
|
|
419
|
+
while ((match = svcRefPattern.exec(content)) !== null) {
|
|
420
|
+
refs.push({ file: filePath, service: match[1], evidence: `K8s service DNS: ${match[1]}.${match[2]}.svc` });
|
|
421
|
+
}
|
|
422
|
+
envServiceUrlPattern.lastIndex = 0;
|
|
423
|
+
while ((match = envServiceUrlPattern.exec(content)) !== null) {
|
|
424
|
+
refs.push({ file: filePath, service: match[1], evidence: `K8s env service ref: ${match[1]}` });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return refs;
|
|
893
428
|
}
|
|
894
|
-
|
|
895
|
-
// Strategy 14: Shared Constants & Magic Strings
|
|
896
|
-
// ---------------------------------------------------------------------------
|
|
897
|
-
function detectSharedConstants(repos) {
|
|
898
|
-
const edges = [];
|
|
429
|
+
function extractConstants(repoPath) {
|
|
899
430
|
const tsConstPattern = /export\s+const\s+(\w+)\s*=\s*['"`]([^'"`]+)['"`]/g;
|
|
900
431
|
const goConstPattern = /(?:const|var)\s+(\w+)\s*=\s*["']([^"']+)["']/g;
|
|
901
432
|
// A string constant is "interesting" if it looks like an identifier
|
|
@@ -905,81 +436,366 @@ function detectSharedConstants(repos) {
|
|
|
905
436
|
// Must contain dots, slashes, or colons — signals structured identifiers
|
|
906
437
|
return /[./:]+/.test(value);
|
|
907
438
|
}
|
|
908
|
-
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
for (const
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
const constValue = match[2];
|
|
925
|
-
if (isInterestingConstant(constValue) && !constMap.has(constValue)) {
|
|
926
|
-
constMap.set(constValue, { name: constName, filePath });
|
|
927
|
-
}
|
|
439
|
+
const constMap = {};
|
|
440
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
441
|
+
const ext = extname(f);
|
|
442
|
+
return ['.ts', '.js', '.go'].includes(ext);
|
|
443
|
+
}, 3000);
|
|
444
|
+
for (const filePath of sourceFiles) {
|
|
445
|
+
const content = safeReadFile(filePath);
|
|
446
|
+
const patterns = [tsConstPattern, goConstPattern];
|
|
447
|
+
for (const pattern of patterns) {
|
|
448
|
+
pattern.lastIndex = 0;
|
|
449
|
+
let match;
|
|
450
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
451
|
+
const constName = match[1];
|
|
452
|
+
const constValue = match[2];
|
|
453
|
+
if (isInterestingConstant(constValue) && !(constValue in constMap)) {
|
|
454
|
+
constMap[constValue] = { name: constName, filePath };
|
|
928
455
|
}
|
|
929
456
|
}
|
|
930
457
|
}
|
|
931
|
-
repoConstants.set(repo.name, constMap);
|
|
932
458
|
}
|
|
933
|
-
|
|
459
|
+
return constMap;
|
|
460
|
+
}
|
|
461
|
+
/** Scan one repo's working tree into the serializable signal bundle. Pure
|
|
462
|
+
* CPU + local FS — safe to run in a worker thread while the clone exists. */
|
|
463
|
+
export function extractCrossRepoSignals(repoPath) {
|
|
464
|
+
const api = extractApiEndpoints(repoPath);
|
|
465
|
+
const grpc = extractGrpc(repoPath);
|
|
466
|
+
const openapi = extractOpenApi(repoPath);
|
|
467
|
+
return {
|
|
468
|
+
npmDeps: extractNpmDeps(repoPath),
|
|
469
|
+
types: extractTypes(repoPath),
|
|
470
|
+
envVars: extractEnvVars(repoPath),
|
|
471
|
+
events: extractEvents(repoPath),
|
|
472
|
+
apiRoutes: api.routes,
|
|
473
|
+
apiClients: api.clients,
|
|
474
|
+
grpcDefs: grpc.defs,
|
|
475
|
+
grpcClients: grpc.clients,
|
|
476
|
+
dbTables: extractDbTables(repoPath),
|
|
477
|
+
redisPrefixes: extractRedisPrefixes(repoPath),
|
|
478
|
+
buckets: extractBuckets(repoPath),
|
|
479
|
+
apiSpecPaths: openapi.specPaths,
|
|
480
|
+
httpCalls: openapi.httpCalls,
|
|
481
|
+
composeRefs: extractComposeRefs(repoPath),
|
|
482
|
+
k8sRefs: extractK8sRefs(repoPath),
|
|
483
|
+
constants: extractConstants(repoPath),
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
// ---------------------------------------------------------------------------
|
|
487
|
+
// CORRELATE — persisted signals across repos → edges (no filesystem)
|
|
488
|
+
// ---------------------------------------------------------------------------
|
|
489
|
+
/** Symmetric pairwise join over a per-repo string→file map. */
|
|
490
|
+
function joinPairwise(perRepo, makeEdge) {
|
|
491
|
+
const edges = [];
|
|
492
|
+
const repoNames = [...perRepo.keys()];
|
|
934
493
|
for (let i = 0; i < repoNames.length; i++) {
|
|
935
494
|
for (let j = i + 1; j < repoNames.length; j++) {
|
|
936
|
-
const
|
|
937
|
-
const
|
|
938
|
-
const
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
if (infoB) {
|
|
943
|
-
edges.push({
|
|
944
|
-
sourceRepo: nameA,
|
|
945
|
-
sourceNode: `${infoA.filePath}::${infoA.name}`,
|
|
946
|
-
targetRepo: nameB,
|
|
947
|
-
targetNode: `${infoB.filePath}::${infoB.name}`,
|
|
948
|
-
edgeType: 'shared-constant',
|
|
949
|
-
evidence: `Shared constant value: "${value}" (${infoA.name} / ${infoB.name})`,
|
|
950
|
-
confidence: 0.7,
|
|
951
|
-
});
|
|
952
|
-
}
|
|
495
|
+
const a = perRepo.get(repoNames[i]);
|
|
496
|
+
const b = perRepo.get(repoNames[j]);
|
|
497
|
+
for (const [key, fileA] of Object.entries(a)) {
|
|
498
|
+
const fileB = b[key];
|
|
499
|
+
if (fileB !== undefined)
|
|
500
|
+
edges.push(makeEdge(repoNames[i], repoNames[j], key, fileA, fileB));
|
|
953
501
|
}
|
|
954
502
|
}
|
|
955
503
|
}
|
|
956
504
|
return edges;
|
|
957
505
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
506
|
+
/** Directional join: providers (defs/routes/specs) × consumers (clients). */
|
|
507
|
+
function joinProviderConsumer(providers, consumers, makeEdge) {
|
|
508
|
+
const edges = [];
|
|
509
|
+
for (const [providerRepo, provided] of providers) {
|
|
510
|
+
for (const [consumerRepo, consumed] of consumers) {
|
|
511
|
+
if (providerRepo === consumerRepo)
|
|
512
|
+
continue;
|
|
513
|
+
for (const [key, providerFile] of Object.entries(provided)) {
|
|
514
|
+
const consumerFile = consumed[key];
|
|
515
|
+
if (consumerFile !== undefined)
|
|
516
|
+
edges.push(makeEdge(providerRepo, consumerRepo, key, providerFile, consumerFile));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return edges;
|
|
521
|
+
}
|
|
522
|
+
/** Repo-name lookup used by compose/k8s service-name matching. Also maps
|
|
523
|
+
* suffixed variants: "mta-routing-engine" matches "routing-engine". */
|
|
524
|
+
function buildRepoNameMap(repoNames) {
|
|
525
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
526
|
+
const map = new Map();
|
|
527
|
+
for (const name of repoNames) {
|
|
528
|
+
map.set(normalize(name), name);
|
|
529
|
+
const parts = name.split(/[-_]/);
|
|
530
|
+
if (parts.length > 1) {
|
|
531
|
+
for (let k = 1; k < parts.length; k++) {
|
|
532
|
+
const suffix = parts.slice(k).join('-');
|
|
533
|
+
if (suffix.length > 3)
|
|
534
|
+
map.set(normalize(suffix), name);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return map;
|
|
539
|
+
}
|
|
540
|
+
function pick(signals, field) {
|
|
541
|
+
const out = new Map();
|
|
542
|
+
for (const [name, s] of signals) {
|
|
543
|
+
const v = s[field];
|
|
544
|
+
if (v && Object.keys(v).length > 0)
|
|
545
|
+
out.set(name, v);
|
|
546
|
+
}
|
|
547
|
+
return out;
|
|
548
|
+
}
|
|
549
|
+
/** Join persisted per-repo signals into cross-repo edges. Pure data — a
|
|
550
|
+
* partial cycle correlates fresh + stored signals without any working tree. */
|
|
551
|
+
export function correlateCrossRepoEdges(signals, workspaceMaps) {
|
|
962
552
|
const allEdges = [];
|
|
963
553
|
const strategies = [
|
|
964
|
-
{
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
554
|
+
{
|
|
555
|
+
name: 'shared-npm-deps',
|
|
556
|
+
fn: () => {
|
|
557
|
+
const perRepo = new Map();
|
|
558
|
+
for (const [name, s] of signals) {
|
|
559
|
+
if (s.npmDeps?.length)
|
|
560
|
+
perRepo.set(name, Object.fromEntries(s.npmDeps.map((d) => [d, 'package.json'])));
|
|
561
|
+
}
|
|
562
|
+
return joinPairwise(perRepo, (a, b, dep) => ({
|
|
563
|
+
sourceRepo: a,
|
|
564
|
+
sourceNode: `package.json::${dep}`,
|
|
565
|
+
targetRepo: b,
|
|
566
|
+
targetNode: `package.json::${dep}`,
|
|
567
|
+
edgeType: 'npm-dep',
|
|
568
|
+
evidence: `Shared scoped dependency: ${dep}`,
|
|
569
|
+
confidence: 0.7,
|
|
570
|
+
}));
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: 'shared-types',
|
|
575
|
+
fn: () => joinPairwise(pick(signals, 'types'), (a, b, typeName, fileA, fileB) => ({
|
|
576
|
+
sourceRepo: a,
|
|
577
|
+
sourceNode: `${fileA}::${typeName}`,
|
|
578
|
+
targetRepo: b,
|
|
579
|
+
targetNode: `${fileB}::${typeName}`,
|
|
580
|
+
edgeType: 'shared-type',
|
|
581
|
+
evidence: `Shared type: ${typeName}`,
|
|
582
|
+
confidence: 0.9,
|
|
583
|
+
})),
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
name: 'env-var-correlation',
|
|
587
|
+
fn: () => {
|
|
588
|
+
const perRepo = new Map();
|
|
589
|
+
for (const [name, s] of signals) {
|
|
590
|
+
if (s.envVars?.length)
|
|
591
|
+
perRepo.set(name, Object.fromEntries(s.envVars.map((v) => [v, 'env'])));
|
|
592
|
+
}
|
|
593
|
+
return joinPairwise(perRepo, (a, b, v) => ({
|
|
594
|
+
sourceRepo: a,
|
|
595
|
+
sourceNode: `env::${v}`,
|
|
596
|
+
targetRepo: b,
|
|
597
|
+
targetNode: `env::${v}`,
|
|
598
|
+
edgeType: 'env-var',
|
|
599
|
+
evidence: `Shared env var: ${v}`,
|
|
600
|
+
confidence: 0.6,
|
|
601
|
+
}));
|
|
602
|
+
},
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
name: 'event-schemas',
|
|
606
|
+
fn: () => joinPairwise(pick(signals, 'events'), (a, b, eventName, fileA, fileB) => ({
|
|
607
|
+
sourceRepo: a,
|
|
608
|
+
sourceNode: `${fileA}::${eventName}`,
|
|
609
|
+
targetRepo: b,
|
|
610
|
+
targetNode: `${fileB}::${eventName}`,
|
|
611
|
+
edgeType: 'event-schema',
|
|
612
|
+
evidence: `Shared event/topic: ${eventName}`,
|
|
613
|
+
confidence: 0.85,
|
|
614
|
+
})),
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
name: 'api-endpoints',
|
|
618
|
+
fn: () => joinProviderConsumer(pick(signals, 'apiRoutes'), pick(signals, 'apiClients'), (routeRepo, clientRepo, routePath, routeFile, clientFile) => ({
|
|
619
|
+
sourceRepo: clientRepo,
|
|
620
|
+
sourceNode: `${clientFile}::${routePath}`,
|
|
621
|
+
targetRepo: routeRepo,
|
|
622
|
+
targetNode: `${routeFile}::${routePath}`,
|
|
623
|
+
edgeType: 'http',
|
|
624
|
+
evidence: `API endpoint: ${routePath}`,
|
|
625
|
+
confidence: 0.8,
|
|
626
|
+
})),
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
name: 'workspace-deps',
|
|
630
|
+
fn: () => {
|
|
631
|
+
// Intra-repo edges between sibling workspace packages — needs only the
|
|
632
|
+
// (persisted) workspace map, no tree.
|
|
633
|
+
const edges = [];
|
|
634
|
+
for (const [repoName, wsMap] of workspaceMaps ?? new Map()) {
|
|
635
|
+
if (wsMap.packages.length < 2)
|
|
636
|
+
continue; // not a meaningful workspace
|
|
637
|
+
for (const pkg of wsMap.packages) {
|
|
638
|
+
for (const depName of pkg.dependencies) {
|
|
639
|
+
const target = wsMap.nameToPackage.get(depName);
|
|
640
|
+
if (target && target.name !== pkg.name) {
|
|
641
|
+
edges.push({
|
|
642
|
+
sourceRepo: repoName,
|
|
643
|
+
sourceNode: `pkg::${pkg.name}`,
|
|
644
|
+
targetRepo: repoName,
|
|
645
|
+
targetNode: `pkg::${target.name}`,
|
|
646
|
+
edgeType: 'workspace-dep',
|
|
647
|
+
evidence: `${pkg.name} depends on ${target.name} (${pkg.manifestFile})`,
|
|
648
|
+
confidence: 1.0,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return edges;
|
|
655
|
+
},
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: 'grpc-services',
|
|
659
|
+
fn: () => joinProviderConsumer(pick(signals, 'grpcDefs'), pick(signals, 'grpcClients'), (defRepo, clientRepo, serviceName, defFile, clientFile) => ({
|
|
660
|
+
sourceRepo: clientRepo,
|
|
661
|
+
sourceNode: `${clientFile}::${serviceName}Client`,
|
|
662
|
+
targetRepo: defRepo,
|
|
663
|
+
targetNode: `${defFile}::${serviceName}`,
|
|
664
|
+
edgeType: 'grpc',
|
|
665
|
+
evidence: `gRPC service: ${serviceName}`,
|
|
666
|
+
confidence: 0.9,
|
|
667
|
+
})),
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
name: 'database-schemas',
|
|
671
|
+
fn: () => joinPairwise(pick(signals, 'dbTables'), (a, b, tableName, fileA, fileB) => ({
|
|
672
|
+
sourceRepo: a,
|
|
673
|
+
sourceNode: `${fileA}::${tableName}`,
|
|
674
|
+
targetRepo: b,
|
|
675
|
+
targetNode: `${fileB}::${tableName}`,
|
|
676
|
+
edgeType: 'database',
|
|
677
|
+
evidence: `Shared table: ${tableName}`,
|
|
678
|
+
confidence: 0.85,
|
|
679
|
+
})),
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
name: 'redis-key-patterns',
|
|
683
|
+
fn: () => joinPairwise(pick(signals, 'redisPrefixes'), (a, b, prefix, fileA, fileB) => ({
|
|
684
|
+
sourceRepo: a,
|
|
685
|
+
sourceNode: `${fileA}::redis:${prefix}`,
|
|
686
|
+
targetRepo: b,
|
|
687
|
+
targetNode: `${fileB}::redis:${prefix}`,
|
|
688
|
+
edgeType: 'redis',
|
|
689
|
+
evidence: `Shared Redis key prefix: ${prefix}`,
|
|
690
|
+
confidence: 0.75,
|
|
691
|
+
})),
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
name: 's3-buckets',
|
|
695
|
+
fn: () => joinPairwise(pick(signals, 'buckets'), (a, b, bucket, fileA, fileB) => ({
|
|
696
|
+
sourceRepo: a,
|
|
697
|
+
sourceNode: `${fileA}::s3:${bucket}`,
|
|
698
|
+
targetRepo: b,
|
|
699
|
+
targetNode: `${fileB}::s3:${bucket}`,
|
|
700
|
+
edgeType: 's3',
|
|
701
|
+
evidence: `Shared bucket: ${bucket}`,
|
|
702
|
+
confidence: 0.8,
|
|
703
|
+
})),
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
name: 'openapi-schemas',
|
|
707
|
+
fn: () => joinProviderConsumer(pick(signals, 'apiSpecPaths'), pick(signals, 'httpCalls'), (specRepo, clientRepo, apiPath, specFile, clientFile) => ({
|
|
708
|
+
sourceRepo: clientRepo,
|
|
709
|
+
sourceNode: `${clientFile}::${apiPath}`,
|
|
710
|
+
targetRepo: specRepo,
|
|
711
|
+
targetNode: `${specFile}::${apiPath}`,
|
|
712
|
+
edgeType: 'api-contract',
|
|
713
|
+
evidence: `OpenAPI endpoint: ${apiPath}`,
|
|
714
|
+
confidence: 0.9,
|
|
715
|
+
})),
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
name: 'docker-compose-links',
|
|
719
|
+
fn: () => {
|
|
720
|
+
const edges = [];
|
|
721
|
+
const repoNameMap = buildRepoNameMap([...signals.keys()]);
|
|
722
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
723
|
+
for (const [repoName, s] of signals) {
|
|
724
|
+
for (const ref of s.composeRefs ?? []) {
|
|
725
|
+
const targetRepo = repoNameMap.get(normalize(ref.service));
|
|
726
|
+
if (targetRepo && targetRepo !== repoName) {
|
|
727
|
+
edges.push({
|
|
728
|
+
sourceRepo: repoName,
|
|
729
|
+
sourceNode: `${ref.file}::compose`,
|
|
730
|
+
targetRepo,
|
|
731
|
+
targetNode: `service::${ref.service}`,
|
|
732
|
+
edgeType: 'http',
|
|
733
|
+
evidence: ref.evidence,
|
|
734
|
+
confidence: 0.85,
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return edges;
|
|
740
|
+
},
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
name: 'k8s-service-refs',
|
|
744
|
+
fn: () => {
|
|
745
|
+
const edges = [];
|
|
746
|
+
const repoNameMap = buildRepoNameMap([...signals.keys()]);
|
|
747
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
748
|
+
for (const [repoName, s] of signals) {
|
|
749
|
+
for (const ref of s.k8sRefs ?? []) {
|
|
750
|
+
const targetRepo = repoNameMap.get(normalize(ref.service));
|
|
751
|
+
if (targetRepo && targetRepo !== repoName) {
|
|
752
|
+
edges.push({
|
|
753
|
+
sourceRepo: repoName,
|
|
754
|
+
sourceNode: `${ref.file}::${ref.evidence.startsWith('K8s env') ? 'k8s-env' : 'k8s-ref'}`,
|
|
755
|
+
targetRepo,
|
|
756
|
+
targetNode: `k8s-service::${ref.service}`,
|
|
757
|
+
edgeType: 'http',
|
|
758
|
+
evidence: ref.evidence,
|
|
759
|
+
confidence: 0.8,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return edges;
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
name: 'shared-constants',
|
|
769
|
+
fn: () => {
|
|
770
|
+
const edges = [];
|
|
771
|
+
const repoNames = [...signals.keys()].filter((n) => signals.get(n).constants && Object.keys(signals.get(n).constants).length > 0);
|
|
772
|
+
for (let i = 0; i < repoNames.length; i++) {
|
|
773
|
+
for (let j = i + 1; j < repoNames.length; j++) {
|
|
774
|
+
const constsA = signals.get(repoNames[i]).constants;
|
|
775
|
+
const constsB = signals.get(repoNames[j]).constants;
|
|
776
|
+
for (const [value, infoA] of Object.entries(constsA)) {
|
|
777
|
+
const infoB = constsB[value];
|
|
778
|
+
if (infoB) {
|
|
779
|
+
edges.push({
|
|
780
|
+
sourceRepo: repoNames[i],
|
|
781
|
+
sourceNode: `${infoA.filePath}::${infoA.name}`,
|
|
782
|
+
targetRepo: repoNames[j],
|
|
783
|
+
targetNode: `${infoB.filePath}::${infoB.name}`,
|
|
784
|
+
edgeType: 'shared-constant',
|
|
785
|
+
evidence: `Shared constant value: "${value}" (${infoA.name} / ${infoB.name})`,
|
|
786
|
+
confidence: 0.7,
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return edges;
|
|
793
|
+
},
|
|
794
|
+
},
|
|
978
795
|
];
|
|
979
796
|
for (const strategy of strategies) {
|
|
980
797
|
try {
|
|
981
|
-
|
|
982
|
-
allEdges.push(...edges);
|
|
798
|
+
allEdges.push(...strategy.fn());
|
|
983
799
|
}
|
|
984
800
|
catch {
|
|
985
801
|
// Individual strategy failure should not block others
|
|
@@ -987,4 +803,32 @@ export async function detectCrossRepoEdges(repos, workspaceMaps) {
|
|
|
987
803
|
}
|
|
988
804
|
return allEdges;
|
|
989
805
|
}
|
|
806
|
+
// ---------------------------------------------------------------------------
|
|
807
|
+
// Main entry point — tree-based wrapper (extract every repo, then correlate)
|
|
808
|
+
// ---------------------------------------------------------------------------
|
|
809
|
+
export async function detectCrossRepoEdges(repos, workspaceMaps) {
|
|
810
|
+
const signals = new Map();
|
|
811
|
+
for (const repo of repos) {
|
|
812
|
+
try {
|
|
813
|
+
signals.set(repo.name, extractCrossRepoSignals(repo.path));
|
|
814
|
+
}
|
|
815
|
+
catch {
|
|
816
|
+
// A single unreadable repo should not block the others
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
// Workspace maps: fall back to a fresh tree scan per repo (today's behavior
|
|
820
|
+
// for callers that do not thread the maps through).
|
|
821
|
+
const wsMaps = new Map(workspaceMaps ?? []);
|
|
822
|
+
for (const repo of repos) {
|
|
823
|
+
if (!wsMaps.has(repo.name)) {
|
|
824
|
+
try {
|
|
825
|
+
const ws = detectWorkspace(repo.path);
|
|
826
|
+
if (ws.packages.length > 0)
|
|
827
|
+
wsMaps.set(repo.name, ws);
|
|
828
|
+
}
|
|
829
|
+
catch { /* non-fatal */ }
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return correlateCrossRepoEdges(signals, wsMaps);
|
|
833
|
+
}
|
|
990
834
|
//# sourceMappingURL=cross-repo-detector.js.map
|