@esankhan3/anvil-knowledge-core 0.3.14 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/cross-repo-detector.test.d.ts +9 -0
- package/dist/__tests__/cross-repo-detector.test.d.ts.map +1 -0
- package/dist/__tests__/cross-repo-detector.test.js +105 -0
- package/dist/__tests__/cross-repo-detector.test.js.map +1 -0
- 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 +34 -1
- 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/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 +672 -812
- package/dist/cross-repo-detector.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 +29 -14
- 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 +184 -22
- package/dist/vector-store.js.map +1 -1
- package/package.json +4 -3
|
@@ -48,854 +48,401 @@ 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
|
-
/(?:topic|TOPIC|channel|CHANNEL|event|EVENT)\s*[:=]\s*['"`]([a-zA-Z0-9._-]+)['"`]/g,
|
|
109
|
+
/(?:topic|TOPIC|channel|CHANNEL|event|EVENT|queue|Queue|QUEUE)\w*\s*[:=]\s*['"`]([a-zA-Z0-9._-]+)['"`]/g,
|
|
110
|
+
// Spring AMQP / RabbitMQ
|
|
111
|
+
/convertAndSend\s*\(\s*"([a-zA-Z0-9._-]+)"/g,
|
|
112
|
+
/@RabbitListener\s*\([^)]*queues\s*=\s*"([a-zA-Z0-9._-]+)"/g,
|
|
207
113
|
/(?:subscribe|publish|emit|on)\s*\(\s*['"`]([a-zA-Z0-9._-]+)['"`]/g,
|
|
208
114
|
];
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
for (const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
});
|
|
115
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
116
|
+
const ext = extname(f);
|
|
117
|
+
return ['.ts', '.js', '.py', '.go', '.java'].includes(ext);
|
|
118
|
+
}, 3000);
|
|
119
|
+
const eventMap = {};
|
|
120
|
+
for (const filePath of sourceFiles) {
|
|
121
|
+
const content = safeReadFile(filePath);
|
|
122
|
+
for (const pattern of eventPatterns) {
|
|
123
|
+
pattern.lastIndex = 0;
|
|
124
|
+
let match;
|
|
125
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
126
|
+
const eventName = match[1];
|
|
127
|
+
// Filter out overly generic names
|
|
128
|
+
// Must contain a separator so bare words are rejected; dots, dashes and underscores all count
|
|
129
|
+
if (eventName.length > 3 && /^[a-z0-9]+(?:[._-][a-z0-9]+)+$/i.test(eventName) && !(eventName in eventMap)) {
|
|
130
|
+
eventMap[eventName] = filePath;
|
|
253
131
|
}
|
|
254
132
|
}
|
|
255
133
|
}
|
|
256
134
|
}
|
|
257
|
-
return
|
|
135
|
+
return eventMap;
|
|
258
136
|
}
|
|
259
|
-
|
|
260
|
-
// Strategy 5: API endpoint matching (route defs vs HTTP client calls)
|
|
261
|
-
// ---------------------------------------------------------------------------
|
|
262
|
-
function detectApiEndpoints(repos) {
|
|
263
|
-
const edges = [];
|
|
137
|
+
function extractApiEndpoints(repoPath) {
|
|
264
138
|
// Route definition patterns
|
|
265
139
|
const routeDefPatterns = [
|
|
266
140
|
/(?:app|router)\.(get|post|put|patch|delete)\s*\(\s*['"`](\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
267
141
|
/@(Get|Post|Put|Patch|Delete)\s*\(\s*['"`](\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
142
|
+
// Go: r.Path("/x"), http.HandleFunc("/x", …), r.Handle("/x", …)
|
|
143
|
+
/\.(Path|HandleFunc|Handle)\s*\(\s*"(\/[a-zA-Z0-9/:._{}-]+)"/g,
|
|
144
|
+
// Spring MVC: @RequestMapping(value = "/x"), @GetMapping("/x"), …
|
|
145
|
+
/@(RequestMapping|GetMapping|PostMapping|PutMapping|PatchMapping|DeleteMapping)\s*\((?:[^)]*?(?:value|path)\s*=\s*)?"(\/[a-zA-Z0-9/:._{}-]+)"/g,
|
|
268
146
|
];
|
|
269
147
|
// HTTP client call patterns
|
|
270
148
|
const httpCallPatterns = [
|
|
271
149
|
/(?:axios|fetch|http|client)\.(get|post|put|patch|delete)\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
272
150
|
/fetch\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
151
|
+
// Service-name URLs built by hand: "http://user/customers", `http://user%s/login`, `http://user${domain}/cards`
|
|
152
|
+
/["'`]https?:\/\/[a-z][a-z0-9-]*(?:%s|\$\{[^}]*\})?(\/[a-zA-Z0-9/:._-]+)["'`]/g,
|
|
153
|
+
// Java URI builders: new ServiceUri(new Hostname("payment"), …, "/paymentAuth")
|
|
154
|
+
/Hostname\s*\(\s*"[a-z][a-z0-9-]*"\s*\)[^;]*?"(\/[a-zA-Z0-9/:._{}-]+)"/g,
|
|
273
155
|
];
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
for (const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
}
|
|
156
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
157
|
+
const ext = extname(f);
|
|
158
|
+
// Go and Java services define routes too (gorilla/mux, net/http, Spring MVC)
|
|
159
|
+
return ['.ts', '.js', '.go', '.java'].includes(ext);
|
|
160
|
+
}, 3000);
|
|
161
|
+
const routes = {};
|
|
162
|
+
const clients = {};
|
|
163
|
+
for (const filePath of sourceFiles) {
|
|
164
|
+
const content = safeReadFile(filePath);
|
|
165
|
+
for (const pattern of routeDefPatterns) {
|
|
166
|
+
pattern.lastIndex = 0;
|
|
167
|
+
let match;
|
|
168
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
169
|
+
// Normalize path: strip params to base pattern
|
|
170
|
+
// Patterns with a single capture group (e.g. bare fetch('/x')) put the path in match[1]
|
|
171
|
+
const routePath = (match[2] ?? match[1]).replace(/:[a-zA-Z]+/g, ':param');
|
|
172
|
+
if (!(routePath in routes))
|
|
173
|
+
routes[routePath] = filePath;
|
|
328
174
|
}
|
|
329
175
|
}
|
|
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
|
-
}
|
|
176
|
+
for (const pattern of httpCallPatterns) {
|
|
177
|
+
pattern.lastIndex = 0;
|
|
178
|
+
let match;
|
|
179
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
180
|
+
const clientPath = (match[2] ?? match[1]).replace(/:[a-zA-Z]+/g, ':param');
|
|
181
|
+
if (!(clientPath in clients))
|
|
182
|
+
clients[clientPath] = filePath;
|
|
357
183
|
}
|
|
358
184
|
}
|
|
359
185
|
}
|
|
360
|
-
return
|
|
186
|
+
return { routes, clients };
|
|
361
187
|
}
|
|
362
|
-
|
|
363
|
-
// Strategy 7: gRPC/Proto Service Detection
|
|
364
|
-
// ---------------------------------------------------------------------------
|
|
365
|
-
function detectGrpcServices(repos) {
|
|
366
|
-
const edges = [];
|
|
188
|
+
function extractGrpc(repoPath) {
|
|
367
189
|
const serviceDefPattern = /service\s+(\w+)\s*\{[^}]*rpc\s+(\w+)/gs;
|
|
368
190
|
const tsClientPattern = /import\s*\{[^}]*(\w+)Client[^}]*\}\s*from\s*['"][^'"]*_grpc_pb['"]/g;
|
|
369
191
|
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;
|
|
192
|
+
// Scan .proto files for service definitions
|
|
193
|
+
const protoFiles = walkFiles(repoPath, (f) => extname(f) === '.proto', 500);
|
|
194
|
+
const defs = {};
|
|
195
|
+
for (const filePath of protoFiles) {
|
|
196
|
+
const content = safeReadFile(filePath);
|
|
197
|
+
serviceDefPattern.lastIndex = 0;
|
|
198
|
+
let match;
|
|
199
|
+
while ((match = serviceDefPattern.exec(content)) !== null) {
|
|
200
|
+
defs[match[1]] = filePath;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// Scan source files for client usage
|
|
204
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
205
|
+
const ext = extname(f);
|
|
206
|
+
return ['.ts', '.js', '.go'].includes(ext);
|
|
207
|
+
}, 3000);
|
|
208
|
+
const clients = {};
|
|
209
|
+
for (const filePath of sourceFiles) {
|
|
210
|
+
const content = safeReadFile(filePath);
|
|
211
|
+
tsClientPattern.lastIndex = 0;
|
|
212
|
+
let match;
|
|
213
|
+
while ((match = tsClientPattern.exec(content)) !== null) {
|
|
214
|
+
clients[match[1]] = filePath;
|
|
215
|
+
}
|
|
216
|
+
goClientPattern.lastIndex = 0;
|
|
217
|
+
while ((match = goClientPattern.exec(content)) !== null) {
|
|
218
|
+
clients[match[1]] = filePath;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { defs, clients };
|
|
428
222
|
}
|
|
429
|
-
|
|
430
|
-
// Strategy 8: Database Schema Correlation
|
|
431
|
-
// ---------------------------------------------------------------------------
|
|
432
|
-
function detectDatabaseSchemas(repos) {
|
|
433
|
-
const edges = [];
|
|
223
|
+
function extractDbTables(repoPath) {
|
|
434
224
|
const sqlCreatePattern = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?["`]?(\w+)["`]?/gi;
|
|
435
|
-
|
|
225
|
+
// Upper-case SQL keywords only: a case-insensitive scan turned every Python/JS
|
|
226
|
+
// `from x import` and `import y from 'z'` into a "shared table" named x / z.
|
|
227
|
+
const sqlQueryPattern = /\b(?:FROM|INTO|JOIN|UPDATE)\s+["`]?([a-z_][a-z0-9_]*)["`]?/g;
|
|
436
228
|
const typeormPattern = /@Entity\s*\(\s*['"`](\w+)['"`]\s*\)/g;
|
|
437
229
|
const gormPattern = /TableName\s*\(\s*\)\s*string\s*\{\s*return\s*["'](\w+)["']/g;
|
|
438
230
|
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
|
-
});
|
|
231
|
+
const tableMap = {};
|
|
232
|
+
// SQL migration files
|
|
233
|
+
const sqlFiles = walkFiles(repoPath, (f) => {
|
|
234
|
+
const lower = f.toLowerCase();
|
|
235
|
+
return lower.endsWith('.sql') || lower.includes('migration');
|
|
236
|
+
}, 1000);
|
|
237
|
+
// Source files for ORM patterns and raw queries
|
|
238
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
239
|
+
const ext = extname(f);
|
|
240
|
+
return ['.ts', '.js', '.go', '.py', '.java'].includes(ext);
|
|
241
|
+
}, 3000);
|
|
242
|
+
const allFiles = [...sqlFiles, ...sourceFiles];
|
|
243
|
+
const patterns = [sqlCreatePattern, sqlQueryPattern, typeormPattern, gormPattern, sequelizePattern];
|
|
244
|
+
const skipTables = new Set(['information_schema', 'pg_catalog', 'dual', 'sqlite_master', 'schema_migrations']);
|
|
245
|
+
for (const filePath of allFiles) {
|
|
246
|
+
const content = safeReadFile(filePath);
|
|
247
|
+
for (const pattern of patterns) {
|
|
248
|
+
pattern.lastIndex = 0;
|
|
249
|
+
let match;
|
|
250
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
251
|
+
const tableName = match[1].toLowerCase();
|
|
252
|
+
if (tableName.length > 2 && !skipTables.has(tableName) && !(tableName in tableMap)) {
|
|
253
|
+
tableMap[tableName] = filePath;
|
|
491
254
|
}
|
|
492
255
|
}
|
|
493
256
|
}
|
|
494
257
|
}
|
|
495
|
-
return
|
|
258
|
+
return tableMap;
|
|
496
259
|
}
|
|
497
|
-
|
|
498
|
-
// Strategy 9: Redis Key Pattern Detection
|
|
499
|
-
// ---------------------------------------------------------------------------
|
|
500
|
-
function detectRedisKeyPatterns(repos) {
|
|
501
|
-
const edges = [];
|
|
260
|
+
function extractRedisPrefixes(repoPath) {
|
|
502
261
|
const redisPatterns = [
|
|
503
262
|
/(?:redis|cache|rdb)\.(get|set|del|hget|hset|sadd|srem)\s*\(\s*(?:ctx,\s*)?['"`]([a-zA-Z0-9_:-]+)/g,
|
|
504
263
|
/(?:redis|cache|rdb)\.(?:Get|Set|Del|HGet|HSet)\s*\(\s*ctx\s*,\s*["']([a-zA-Z0-9_:-]+)/g,
|
|
505
264
|
];
|
|
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
|
-
});
|
|
265
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
266
|
+
const ext = extname(f);
|
|
267
|
+
return ['.ts', '.js', '.go', '.py', '.java'].includes(ext);
|
|
268
|
+
}, 3000);
|
|
269
|
+
const prefixMap = {};
|
|
270
|
+
for (const filePath of sourceFiles) {
|
|
271
|
+
const content = safeReadFile(filePath);
|
|
272
|
+
for (const pattern of redisPatterns) {
|
|
273
|
+
pattern.lastIndex = 0;
|
|
274
|
+
let match;
|
|
275
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
276
|
+
// Extract the key — could be in group 2 (first pattern) or group 1 (second pattern)
|
|
277
|
+
const key = match[2] ?? match[1];
|
|
278
|
+
// Extract prefix: everything before first interpolation marker or take full key up to second colon
|
|
279
|
+
const colonParts = key.split(':');
|
|
280
|
+
const prefix = colonParts.length >= 2
|
|
281
|
+
? `${colonParts[0]}:${colonParts[1]}`
|
|
282
|
+
: key;
|
|
283
|
+
if (prefix.length > 3 && !(prefix in prefixMap)) {
|
|
284
|
+
prefixMap[prefix] = filePath;
|
|
553
285
|
}
|
|
554
286
|
}
|
|
555
287
|
}
|
|
556
288
|
}
|
|
557
|
-
return
|
|
289
|
+
return prefixMap;
|
|
558
290
|
}
|
|
559
|
-
|
|
560
|
-
// Strategy 10: S3/GCS Bucket Detection
|
|
561
|
-
// ---------------------------------------------------------------------------
|
|
562
|
-
function detectS3Buckets(repos) {
|
|
563
|
-
const edges = [];
|
|
291
|
+
function extractBuckets(repoPath) {
|
|
564
292
|
const s3Patterns = [
|
|
565
293
|
/s3\.(?:putObject|getObject|deleteObject|upload|headObject)\s*\(\s*\{[^}]*Bucket\s*:\s*['"`]([a-zA-Z0-9._-]+)['"`]/gs,
|
|
566
294
|
/new\s+(?:S3|AWS\.S3)\s*\([^)]*\)[^;]*\.(?:putObject|getObject)\s*\(\s*\{[^}]*Bucket\s*:\s*['"`]([a-zA-Z0-9._-]+)['"`]/gs,
|
|
567
295
|
/storage\.bucket\s*\(\s*['"`]([a-zA-Z0-9._-]+)['"`]\s*\)/g,
|
|
568
296
|
];
|
|
569
297
|
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;
|
|
298
|
+
const bucketMap = {};
|
|
299
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
300
|
+
const ext = extname(f);
|
|
301
|
+
return ['.ts', '.js', '.go', '.py', '.java', '.env', '.yaml', '.yml'].includes(ext)
|
|
302
|
+
|| f.endsWith('.env.example') || f.endsWith('.env.template');
|
|
303
|
+
}, 3000);
|
|
304
|
+
for (const filePath of sourceFiles) {
|
|
305
|
+
const content = safeReadFile(filePath);
|
|
306
|
+
for (const pattern of s3Patterns) {
|
|
307
|
+
pattern.lastIndex = 0;
|
|
591
308
|
let match;
|
|
592
|
-
while ((match =
|
|
309
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
593
310
|
const bucket = match[1];
|
|
594
|
-
if (bucket && bucket
|
|
595
|
-
bucketMap
|
|
596
|
-
}
|
|
311
|
+
if (bucket && !(bucket in bucketMap))
|
|
312
|
+
bucketMap[bucket] = filePath;
|
|
597
313
|
}
|
|
598
314
|
}
|
|
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
|
-
}
|
|
315
|
+
envBucketPattern.lastIndex = 0;
|
|
316
|
+
let match;
|
|
317
|
+
while ((match = envBucketPattern.exec(content)) !== null) {
|
|
318
|
+
const bucket = match[1];
|
|
319
|
+
if (bucket && bucket.length > 3 && !(bucket in bucketMap))
|
|
320
|
+
bucketMap[bucket] = filePath;
|
|
622
321
|
}
|
|
623
322
|
}
|
|
624
|
-
return
|
|
323
|
+
return bucketMap;
|
|
625
324
|
}
|
|
626
|
-
|
|
627
|
-
// Strategy 11: OpenAPI Schema References
|
|
628
|
-
// ---------------------------------------------------------------------------
|
|
629
|
-
function detectOpenApiSchemas(repos) {
|
|
630
|
-
const edges = [];
|
|
325
|
+
function extractOpenApi(repoPath) {
|
|
631
326
|
const openApiFileNames = ['openapi.yaml', 'openapi.yml', 'openapi.json', 'swagger.yaml', 'swagger.yml', 'swagger.json'];
|
|
632
327
|
const pathPattern = /^\s*(?:\/[a-zA-Z0-9/:._{}*-]+)\s*:/gm;
|
|
633
328
|
const jsonPathPattern = /"(\/[a-zA-Z0-9/:._{}*-]+)"\s*:/g;
|
|
634
|
-
// repo -> endpoint paths -> filePath
|
|
635
|
-
const repoApiPaths = new Map();
|
|
636
329
|
// HTTP client patterns (complement to Strategy 5)
|
|
637
330
|
const httpCallPatterns = [
|
|
638
331
|
/(?:axios|fetch|http|client|httpGet|httpPost|httpPut|httpDelete)\s*\(\s*[^,]*?,?\s*['"`](\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
639
332
|
/fetch\s*\(\s*[`'"](?:https?:\/\/[^/]*?)?(\/[a-zA-Z0-9/:._-]+)['"`]/g,
|
|
640
333
|
];
|
|
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
|
-
}
|
|
334
|
+
const specPaths = {};
|
|
335
|
+
const specFiles = walkFiles(repoPath, (f) => {
|
|
336
|
+
const basename = f.split('/').pop() ?? '';
|
|
337
|
+
return openApiFileNames.includes(basename);
|
|
338
|
+
}, 200);
|
|
339
|
+
for (const filePath of specFiles) {
|
|
340
|
+
const content = safeReadFile(filePath);
|
|
341
|
+
if (filePath.endsWith('.json')) {
|
|
342
|
+
jsonPathPattern.lastIndex = 0;
|
|
343
|
+
let match;
|
|
344
|
+
while ((match = jsonPathPattern.exec(content)) !== null) {
|
|
345
|
+
const path = match[1].replace(/\{[^}]+\}/g, ':param');
|
|
346
|
+
if (!(path in specPaths))
|
|
347
|
+
specPaths[path] = filePath;
|
|
693
348
|
}
|
|
694
349
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
350
|
+
else {
|
|
351
|
+
pathPattern.lastIndex = 0;
|
|
352
|
+
let match;
|
|
353
|
+
while ((match = pathPattern.exec(content)) !== null) {
|
|
354
|
+
const rawPath = match[0].trim().replace(/:$/, '').trim();
|
|
355
|
+
if (rawPath.startsWith('/')) {
|
|
356
|
+
const normalized = rawPath.replace(/\{[^}]+\}/g, ':param');
|
|
357
|
+
if (!(normalized in specPaths))
|
|
358
|
+
specPaths[normalized] = filePath;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
// Scan for HTTP client calls
|
|
364
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
365
|
+
const ext = extname(f);
|
|
366
|
+
return ['.ts', '.js'].includes(ext);
|
|
367
|
+
}, 3000);
|
|
368
|
+
const httpCalls = {};
|
|
369
|
+
for (const filePath of sourceFiles) {
|
|
370
|
+
const content = safeReadFile(filePath);
|
|
371
|
+
for (const pattern of httpCallPatterns) {
|
|
372
|
+
pattern.lastIndex = 0;
|
|
373
|
+
let match;
|
|
374
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
375
|
+
const callPath = (match[2] ?? match[1]).replace(/:[a-zA-Z]+/g, ':param');
|
|
376
|
+
if (!(callPath in httpCalls))
|
|
377
|
+
httpCalls[callPath] = filePath;
|
|
715
378
|
}
|
|
716
379
|
}
|
|
717
380
|
}
|
|
718
|
-
return
|
|
381
|
+
return { specPaths, httpCalls };
|
|
719
382
|
}
|
|
720
|
-
|
|
721
|
-
// Strategy 12: Docker Compose Service Links
|
|
722
|
-
// ---------------------------------------------------------------------------
|
|
723
|
-
function detectDockerComposeLinks(repos) {
|
|
724
|
-
const edges = [];
|
|
383
|
+
function extractComposeRefs(repoPath) {
|
|
725
384
|
const composeFiles = ['docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'];
|
|
726
|
-
// Extract service names and their dependencies from compose files
|
|
727
385
|
// Simplified YAML parsing via regex (no YAML parser dependency)
|
|
728
|
-
const serviceBlockPattern = /^\s{2}(\w[\w.-]*)\s*:/gm;
|
|
729
386
|
const dependsOnPattern = /depends_on\s*:\s*\n((?:\s+-\s+\w[\w.-]*\n?)+)/gm;
|
|
730
387
|
const dependsOnItemPattern = /^\s+-\s+(\w[\w.-]*)/gm;
|
|
731
388
|
const linksPattern = /links\s*:\s*\n((?:\s+-\s+\w[\w.-]*(?::\w[\w.-]*)?\n?)+)/gm;
|
|
732
389
|
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;
|
|
390
|
+
const refs = [];
|
|
391
|
+
const foundFiles = walkFiles(repoPath, (f) => {
|
|
392
|
+
const basename = f.split('/').pop() ?? '';
|
|
393
|
+
return composeFiles.includes(basename);
|
|
394
|
+
}, 50);
|
|
395
|
+
for (const filePath of foundFiles) {
|
|
396
|
+
const content = safeReadFile(filePath);
|
|
397
|
+
dependsOnPattern.lastIndex = 0;
|
|
398
|
+
let match;
|
|
399
|
+
while ((match = dependsOnPattern.exec(content)) !== null) {
|
|
400
|
+
const block = match[1];
|
|
401
|
+
dependsOnItemPattern.lastIndex = 0;
|
|
402
|
+
let dep;
|
|
403
|
+
while ((dep = dependsOnItemPattern.exec(block)) !== null) {
|
|
404
|
+
refs.push({ file: filePath, service: dep[1], evidence: `Docker Compose depends_on: ${dep[1]}` });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
linksPattern.lastIndex = 0;
|
|
408
|
+
while ((match = linksPattern.exec(content)) !== null) {
|
|
409
|
+
const block = match[1];
|
|
410
|
+
linksItemPattern.lastIndex = 0;
|
|
411
|
+
let link;
|
|
412
|
+
while ((link = linksItemPattern.exec(block)) !== null) {
|
|
413
|
+
refs.push({ file: filePath, service: link[1], evidence: `Docker Compose link: ${link[1]}` });
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return refs;
|
|
815
418
|
}
|
|
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;
|
|
419
|
+
function extractK8sRefs(repoPath) {
|
|
823
420
|
const svcRefPattern = /["'](\w[\w.-]*)\.(\w[\w.-]*)\.svc(?:\.cluster\.local)?["']/g;
|
|
824
421
|
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;
|
|
422
|
+
const refs = [];
|
|
423
|
+
const k8sFiles = walkFiles(repoPath, (f) => {
|
|
424
|
+
const ext = extname(f);
|
|
425
|
+
if (ext !== '.yaml' && ext !== '.yml')
|
|
426
|
+
return false;
|
|
427
|
+
const lower = f.toLowerCase();
|
|
428
|
+
return lower.includes('k8s') || lower.includes('deploy') || lower.includes('manifests')
|
|
429
|
+
|| lower.includes('kustomiz') || lower.includes('kubernetes') || lower.includes('helm');
|
|
430
|
+
}, 500);
|
|
431
|
+
for (const filePath of k8sFiles) {
|
|
432
|
+
const content = safeReadFile(filePath);
|
|
433
|
+
svcRefPattern.lastIndex = 0;
|
|
434
|
+
let match;
|
|
435
|
+
while ((match = svcRefPattern.exec(content)) !== null) {
|
|
436
|
+
refs.push({ file: filePath, service: match[1], evidence: `K8s service DNS: ${match[1]}.${match[2]}.svc` });
|
|
437
|
+
}
|
|
438
|
+
envServiceUrlPattern.lastIndex = 0;
|
|
439
|
+
while ((match = envServiceUrlPattern.exec(content)) !== null) {
|
|
440
|
+
refs.push({ file: filePath, service: match[1], evidence: `K8s env service ref: ${match[1]}` });
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return refs;
|
|
893
444
|
}
|
|
894
|
-
|
|
895
|
-
// Strategy 14: Shared Constants & Magic Strings
|
|
896
|
-
// ---------------------------------------------------------------------------
|
|
897
|
-
function detectSharedConstants(repos) {
|
|
898
|
-
const edges = [];
|
|
445
|
+
function extractConstants(repoPath) {
|
|
899
446
|
const tsConstPattern = /export\s+const\s+(\w+)\s*=\s*['"`]([^'"`]+)['"`]/g;
|
|
900
447
|
const goConstPattern = /(?:const|var)\s+(\w+)\s*=\s*["']([^"']+)["']/g;
|
|
901
448
|
// A string constant is "interesting" if it looks like an identifier
|
|
@@ -905,81 +452,366 @@ function detectSharedConstants(repos) {
|
|
|
905
452
|
// Must contain dots, slashes, or colons — signals structured identifiers
|
|
906
453
|
return /[./:]+/.test(value);
|
|
907
454
|
}
|
|
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
|
-
}
|
|
455
|
+
const constMap = {};
|
|
456
|
+
const sourceFiles = walkFiles(repoPath, (f) => {
|
|
457
|
+
const ext = extname(f);
|
|
458
|
+
return ['.ts', '.js', '.go'].includes(ext);
|
|
459
|
+
}, 3000);
|
|
460
|
+
for (const filePath of sourceFiles) {
|
|
461
|
+
const content = safeReadFile(filePath);
|
|
462
|
+
const patterns = [tsConstPattern, goConstPattern];
|
|
463
|
+
for (const pattern of patterns) {
|
|
464
|
+
pattern.lastIndex = 0;
|
|
465
|
+
let match;
|
|
466
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
467
|
+
const constName = match[1];
|
|
468
|
+
const constValue = match[2];
|
|
469
|
+
if (isInterestingConstant(constValue) && !(constValue in constMap)) {
|
|
470
|
+
constMap[constValue] = { name: constName, filePath };
|
|
928
471
|
}
|
|
929
472
|
}
|
|
930
473
|
}
|
|
931
|
-
repoConstants.set(repo.name, constMap);
|
|
932
474
|
}
|
|
933
|
-
|
|
475
|
+
return constMap;
|
|
476
|
+
}
|
|
477
|
+
/** Scan one repo's working tree into the serializable signal bundle. Pure
|
|
478
|
+
* CPU + local FS — safe to run in a worker thread while the clone exists. */
|
|
479
|
+
export function extractCrossRepoSignals(repoPath) {
|
|
480
|
+
const api = extractApiEndpoints(repoPath);
|
|
481
|
+
const grpc = extractGrpc(repoPath);
|
|
482
|
+
const openapi = extractOpenApi(repoPath);
|
|
483
|
+
return {
|
|
484
|
+
npmDeps: extractNpmDeps(repoPath),
|
|
485
|
+
types: extractTypes(repoPath),
|
|
486
|
+
envVars: extractEnvVars(repoPath),
|
|
487
|
+
events: extractEvents(repoPath),
|
|
488
|
+
apiRoutes: api.routes,
|
|
489
|
+
apiClients: api.clients,
|
|
490
|
+
grpcDefs: grpc.defs,
|
|
491
|
+
grpcClients: grpc.clients,
|
|
492
|
+
dbTables: extractDbTables(repoPath),
|
|
493
|
+
redisPrefixes: extractRedisPrefixes(repoPath),
|
|
494
|
+
buckets: extractBuckets(repoPath),
|
|
495
|
+
apiSpecPaths: openapi.specPaths,
|
|
496
|
+
httpCalls: openapi.httpCalls,
|
|
497
|
+
composeRefs: extractComposeRefs(repoPath),
|
|
498
|
+
k8sRefs: extractK8sRefs(repoPath),
|
|
499
|
+
constants: extractConstants(repoPath),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
// ---------------------------------------------------------------------------
|
|
503
|
+
// CORRELATE — persisted signals across repos → edges (no filesystem)
|
|
504
|
+
// ---------------------------------------------------------------------------
|
|
505
|
+
/** Symmetric pairwise join over a per-repo string→file map. */
|
|
506
|
+
function joinPairwise(perRepo, makeEdge) {
|
|
507
|
+
const edges = [];
|
|
508
|
+
const repoNames = [...perRepo.keys()];
|
|
934
509
|
for (let i = 0; i < repoNames.length; i++) {
|
|
935
510
|
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
|
-
}
|
|
511
|
+
const a = perRepo.get(repoNames[i]);
|
|
512
|
+
const b = perRepo.get(repoNames[j]);
|
|
513
|
+
for (const [key, fileA] of Object.entries(a)) {
|
|
514
|
+
const fileB = b[key];
|
|
515
|
+
if (fileB !== undefined)
|
|
516
|
+
edges.push(makeEdge(repoNames[i], repoNames[j], key, fileA, fileB));
|
|
953
517
|
}
|
|
954
518
|
}
|
|
955
519
|
}
|
|
956
520
|
return edges;
|
|
957
521
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
522
|
+
/** Directional join: providers (defs/routes/specs) × consumers (clients). */
|
|
523
|
+
function joinProviderConsumer(providers, consumers, makeEdge) {
|
|
524
|
+
const edges = [];
|
|
525
|
+
for (const [providerRepo, provided] of providers) {
|
|
526
|
+
for (const [consumerRepo, consumed] of consumers) {
|
|
527
|
+
if (providerRepo === consumerRepo)
|
|
528
|
+
continue;
|
|
529
|
+
for (const [key, providerFile] of Object.entries(provided)) {
|
|
530
|
+
const consumerFile = consumed[key];
|
|
531
|
+
if (consumerFile !== undefined)
|
|
532
|
+
edges.push(makeEdge(providerRepo, consumerRepo, key, providerFile, consumerFile));
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return edges;
|
|
537
|
+
}
|
|
538
|
+
/** Repo-name lookup used by compose/k8s service-name matching. Also maps
|
|
539
|
+
* suffixed variants: "mta-routing-engine" matches "routing-engine". */
|
|
540
|
+
function buildRepoNameMap(repoNames) {
|
|
541
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
542
|
+
const map = new Map();
|
|
543
|
+
for (const name of repoNames) {
|
|
544
|
+
map.set(normalize(name), name);
|
|
545
|
+
const parts = name.split(/[-_]/);
|
|
546
|
+
if (parts.length > 1) {
|
|
547
|
+
for (let k = 1; k < parts.length; k++) {
|
|
548
|
+
const suffix = parts.slice(k).join('-');
|
|
549
|
+
if (suffix.length > 3)
|
|
550
|
+
map.set(normalize(suffix), name);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return map;
|
|
555
|
+
}
|
|
556
|
+
function pick(signals, field) {
|
|
557
|
+
const out = new Map();
|
|
558
|
+
for (const [name, s] of signals) {
|
|
559
|
+
const v = s[field];
|
|
560
|
+
if (v && Object.keys(v).length > 0)
|
|
561
|
+
out.set(name, v);
|
|
562
|
+
}
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
/** Join persisted per-repo signals into cross-repo edges. Pure data — a
|
|
566
|
+
* partial cycle correlates fresh + stored signals without any working tree. */
|
|
567
|
+
export function correlateCrossRepoEdges(signals, workspaceMaps) {
|
|
962
568
|
const allEdges = [];
|
|
963
569
|
const strategies = [
|
|
964
|
-
{
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
570
|
+
{
|
|
571
|
+
name: 'shared-npm-deps',
|
|
572
|
+
fn: () => {
|
|
573
|
+
const perRepo = new Map();
|
|
574
|
+
for (const [name, s] of signals) {
|
|
575
|
+
if (s.npmDeps?.length)
|
|
576
|
+
perRepo.set(name, Object.fromEntries(s.npmDeps.map((d) => [d, 'package.json'])));
|
|
577
|
+
}
|
|
578
|
+
return joinPairwise(perRepo, (a, b, dep) => ({
|
|
579
|
+
sourceRepo: a,
|
|
580
|
+
sourceNode: `package.json::${dep}`,
|
|
581
|
+
targetRepo: b,
|
|
582
|
+
targetNode: `package.json::${dep}`,
|
|
583
|
+
edgeType: 'npm-dep',
|
|
584
|
+
evidence: `Shared scoped dependency: ${dep}`,
|
|
585
|
+
confidence: 0.7,
|
|
586
|
+
}));
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: 'shared-types',
|
|
591
|
+
fn: () => joinPairwise(pick(signals, 'types'), (a, b, typeName, fileA, fileB) => ({
|
|
592
|
+
sourceRepo: a,
|
|
593
|
+
sourceNode: `${fileA}::${typeName}`,
|
|
594
|
+
targetRepo: b,
|
|
595
|
+
targetNode: `${fileB}::${typeName}`,
|
|
596
|
+
edgeType: 'shared-type',
|
|
597
|
+
evidence: `Shared type: ${typeName}`,
|
|
598
|
+
confidence: 0.9,
|
|
599
|
+
})),
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
name: 'env-var-correlation',
|
|
603
|
+
fn: () => {
|
|
604
|
+
const perRepo = new Map();
|
|
605
|
+
for (const [name, s] of signals) {
|
|
606
|
+
if (s.envVars?.length)
|
|
607
|
+
perRepo.set(name, Object.fromEntries(s.envVars.map((v) => [v, 'env'])));
|
|
608
|
+
}
|
|
609
|
+
return joinPairwise(perRepo, (a, b, v) => ({
|
|
610
|
+
sourceRepo: a,
|
|
611
|
+
sourceNode: `env::${v}`,
|
|
612
|
+
targetRepo: b,
|
|
613
|
+
targetNode: `env::${v}`,
|
|
614
|
+
edgeType: 'env-var',
|
|
615
|
+
evidence: `Shared env var: ${v}`,
|
|
616
|
+
confidence: 0.6,
|
|
617
|
+
}));
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
name: 'event-schemas',
|
|
622
|
+
fn: () => joinPairwise(pick(signals, 'events'), (a, b, eventName, fileA, fileB) => ({
|
|
623
|
+
sourceRepo: a,
|
|
624
|
+
sourceNode: `${fileA}::${eventName}`,
|
|
625
|
+
targetRepo: b,
|
|
626
|
+
targetNode: `${fileB}::${eventName}`,
|
|
627
|
+
edgeType: 'event-schema',
|
|
628
|
+
evidence: `Shared event/topic: ${eventName}`,
|
|
629
|
+
confidence: 0.85,
|
|
630
|
+
})),
|
|
631
|
+
},
|
|
632
|
+
{
|
|
633
|
+
name: 'api-endpoints',
|
|
634
|
+
fn: () => joinProviderConsumer(pick(signals, 'apiRoutes'), pick(signals, 'apiClients'), (routeRepo, clientRepo, routePath, routeFile, clientFile) => ({
|
|
635
|
+
sourceRepo: clientRepo,
|
|
636
|
+
sourceNode: `${clientFile}::${routePath}`,
|
|
637
|
+
targetRepo: routeRepo,
|
|
638
|
+
targetNode: `${routeFile}::${routePath}`,
|
|
639
|
+
edgeType: 'http',
|
|
640
|
+
evidence: `API endpoint: ${routePath}`,
|
|
641
|
+
confidence: 0.8,
|
|
642
|
+
})),
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
name: 'workspace-deps',
|
|
646
|
+
fn: () => {
|
|
647
|
+
// Intra-repo edges between sibling workspace packages — needs only the
|
|
648
|
+
// (persisted) workspace map, no tree.
|
|
649
|
+
const edges = [];
|
|
650
|
+
for (const [repoName, wsMap] of workspaceMaps ?? new Map()) {
|
|
651
|
+
if (wsMap.packages.length < 2)
|
|
652
|
+
continue; // not a meaningful workspace
|
|
653
|
+
for (const pkg of wsMap.packages) {
|
|
654
|
+
for (const depName of pkg.dependencies) {
|
|
655
|
+
const target = wsMap.nameToPackage.get(depName);
|
|
656
|
+
if (target && target.name !== pkg.name) {
|
|
657
|
+
edges.push({
|
|
658
|
+
sourceRepo: repoName,
|
|
659
|
+
sourceNode: `pkg::${pkg.name}`,
|
|
660
|
+
targetRepo: repoName,
|
|
661
|
+
targetNode: `pkg::${target.name}`,
|
|
662
|
+
edgeType: 'workspace-dep',
|
|
663
|
+
evidence: `${pkg.name} depends on ${target.name} (${pkg.manifestFile})`,
|
|
664
|
+
confidence: 1.0,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return edges;
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
name: 'grpc-services',
|
|
675
|
+
fn: () => joinProviderConsumer(pick(signals, 'grpcDefs'), pick(signals, 'grpcClients'), (defRepo, clientRepo, serviceName, defFile, clientFile) => ({
|
|
676
|
+
sourceRepo: clientRepo,
|
|
677
|
+
sourceNode: `${clientFile}::${serviceName}Client`,
|
|
678
|
+
targetRepo: defRepo,
|
|
679
|
+
targetNode: `${defFile}::${serviceName}`,
|
|
680
|
+
edgeType: 'grpc',
|
|
681
|
+
evidence: `gRPC service: ${serviceName}`,
|
|
682
|
+
confidence: 0.9,
|
|
683
|
+
})),
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
name: 'database-schemas',
|
|
687
|
+
fn: () => joinPairwise(pick(signals, 'dbTables'), (a, b, tableName, fileA, fileB) => ({
|
|
688
|
+
sourceRepo: a,
|
|
689
|
+
sourceNode: `${fileA}::${tableName}`,
|
|
690
|
+
targetRepo: b,
|
|
691
|
+
targetNode: `${fileB}::${tableName}`,
|
|
692
|
+
edgeType: 'database',
|
|
693
|
+
evidence: `Shared table: ${tableName}`,
|
|
694
|
+
confidence: 0.85,
|
|
695
|
+
})),
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
name: 'redis-key-patterns',
|
|
699
|
+
fn: () => joinPairwise(pick(signals, 'redisPrefixes'), (a, b, prefix, fileA, fileB) => ({
|
|
700
|
+
sourceRepo: a,
|
|
701
|
+
sourceNode: `${fileA}::redis:${prefix}`,
|
|
702
|
+
targetRepo: b,
|
|
703
|
+
targetNode: `${fileB}::redis:${prefix}`,
|
|
704
|
+
edgeType: 'redis',
|
|
705
|
+
evidence: `Shared Redis key prefix: ${prefix}`,
|
|
706
|
+
confidence: 0.75,
|
|
707
|
+
})),
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
name: 's3-buckets',
|
|
711
|
+
fn: () => joinPairwise(pick(signals, 'buckets'), (a, b, bucket, fileA, fileB) => ({
|
|
712
|
+
sourceRepo: a,
|
|
713
|
+
sourceNode: `${fileA}::s3:${bucket}`,
|
|
714
|
+
targetRepo: b,
|
|
715
|
+
targetNode: `${fileB}::s3:${bucket}`,
|
|
716
|
+
edgeType: 's3',
|
|
717
|
+
evidence: `Shared bucket: ${bucket}`,
|
|
718
|
+
confidence: 0.8,
|
|
719
|
+
})),
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
name: 'openapi-schemas',
|
|
723
|
+
fn: () => joinProviderConsumer(pick(signals, 'apiSpecPaths'), pick(signals, 'httpCalls'), (specRepo, clientRepo, apiPath, specFile, clientFile) => ({
|
|
724
|
+
sourceRepo: clientRepo,
|
|
725
|
+
sourceNode: `${clientFile}::${apiPath}`,
|
|
726
|
+
targetRepo: specRepo,
|
|
727
|
+
targetNode: `${specFile}::${apiPath}`,
|
|
728
|
+
edgeType: 'api-contract',
|
|
729
|
+
evidence: `OpenAPI endpoint: ${apiPath}`,
|
|
730
|
+
confidence: 0.9,
|
|
731
|
+
})),
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
name: 'docker-compose-links',
|
|
735
|
+
fn: () => {
|
|
736
|
+
const edges = [];
|
|
737
|
+
const repoNameMap = buildRepoNameMap([...signals.keys()]);
|
|
738
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
739
|
+
for (const [repoName, s] of signals) {
|
|
740
|
+
for (const ref of s.composeRefs ?? []) {
|
|
741
|
+
const targetRepo = repoNameMap.get(normalize(ref.service));
|
|
742
|
+
if (targetRepo && targetRepo !== repoName) {
|
|
743
|
+
edges.push({
|
|
744
|
+
sourceRepo: repoName,
|
|
745
|
+
sourceNode: `${ref.file}::compose`,
|
|
746
|
+
targetRepo,
|
|
747
|
+
targetNode: `service::${ref.service}`,
|
|
748
|
+
edgeType: 'http',
|
|
749
|
+
evidence: ref.evidence,
|
|
750
|
+
confidence: 0.85,
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
return edges;
|
|
756
|
+
},
|
|
757
|
+
},
|
|
758
|
+
{
|
|
759
|
+
name: 'k8s-service-refs',
|
|
760
|
+
fn: () => {
|
|
761
|
+
const edges = [];
|
|
762
|
+
const repoNameMap = buildRepoNameMap([...signals.keys()]);
|
|
763
|
+
const normalize = (name) => name.toLowerCase().replace(/[-_.]/g, '-');
|
|
764
|
+
for (const [repoName, s] of signals) {
|
|
765
|
+
for (const ref of s.k8sRefs ?? []) {
|
|
766
|
+
const targetRepo = repoNameMap.get(normalize(ref.service));
|
|
767
|
+
if (targetRepo && targetRepo !== repoName) {
|
|
768
|
+
edges.push({
|
|
769
|
+
sourceRepo: repoName,
|
|
770
|
+
sourceNode: `${ref.file}::${ref.evidence.startsWith('K8s env') ? 'k8s-env' : 'k8s-ref'}`,
|
|
771
|
+
targetRepo,
|
|
772
|
+
targetNode: `k8s-service::${ref.service}`,
|
|
773
|
+
edgeType: 'http',
|
|
774
|
+
evidence: ref.evidence,
|
|
775
|
+
confidence: 0.8,
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return edges;
|
|
781
|
+
},
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
name: 'shared-constants',
|
|
785
|
+
fn: () => {
|
|
786
|
+
const edges = [];
|
|
787
|
+
const repoNames = [...signals.keys()].filter((n) => signals.get(n).constants && Object.keys(signals.get(n).constants).length > 0);
|
|
788
|
+
for (let i = 0; i < repoNames.length; i++) {
|
|
789
|
+
for (let j = i + 1; j < repoNames.length; j++) {
|
|
790
|
+
const constsA = signals.get(repoNames[i]).constants;
|
|
791
|
+
const constsB = signals.get(repoNames[j]).constants;
|
|
792
|
+
for (const [value, infoA] of Object.entries(constsA)) {
|
|
793
|
+
const infoB = constsB[value];
|
|
794
|
+
if (infoB) {
|
|
795
|
+
edges.push({
|
|
796
|
+
sourceRepo: repoNames[i],
|
|
797
|
+
sourceNode: `${infoA.filePath}::${infoA.name}`,
|
|
798
|
+
targetRepo: repoNames[j],
|
|
799
|
+
targetNode: `${infoB.filePath}::${infoB.name}`,
|
|
800
|
+
edgeType: 'shared-constant',
|
|
801
|
+
evidence: `Shared constant value: "${value}" (${infoA.name} / ${infoB.name})`,
|
|
802
|
+
confidence: 0.7,
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
return edges;
|
|
809
|
+
},
|
|
810
|
+
},
|
|
978
811
|
];
|
|
979
812
|
for (const strategy of strategies) {
|
|
980
813
|
try {
|
|
981
|
-
|
|
982
|
-
allEdges.push(...edges);
|
|
814
|
+
allEdges.push(...strategy.fn());
|
|
983
815
|
}
|
|
984
816
|
catch {
|
|
985
817
|
// Individual strategy failure should not block others
|
|
@@ -987,4 +819,32 @@ export async function detectCrossRepoEdges(repos, workspaceMaps) {
|
|
|
987
819
|
}
|
|
988
820
|
return allEdges;
|
|
989
821
|
}
|
|
822
|
+
// ---------------------------------------------------------------------------
|
|
823
|
+
// Main entry point — tree-based wrapper (extract every repo, then correlate)
|
|
824
|
+
// ---------------------------------------------------------------------------
|
|
825
|
+
export async function detectCrossRepoEdges(repos, workspaceMaps) {
|
|
826
|
+
const signals = new Map();
|
|
827
|
+
for (const repo of repos) {
|
|
828
|
+
try {
|
|
829
|
+
signals.set(repo.name, extractCrossRepoSignals(repo.path));
|
|
830
|
+
}
|
|
831
|
+
catch {
|
|
832
|
+
// A single unreadable repo should not block the others
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
// Workspace maps: fall back to a fresh tree scan per repo (today's behavior
|
|
836
|
+
// for callers that do not thread the maps through).
|
|
837
|
+
const wsMaps = new Map(workspaceMaps ?? []);
|
|
838
|
+
for (const repo of repos) {
|
|
839
|
+
if (!wsMaps.has(repo.name)) {
|
|
840
|
+
try {
|
|
841
|
+
const ws = detectWorkspace(repo.path);
|
|
842
|
+
if (ws.packages.length > 0)
|
|
843
|
+
wsMaps.set(repo.name, ws);
|
|
844
|
+
}
|
|
845
|
+
catch { /* non-fatal */ }
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return correlateCrossRepoEdges(signals, wsMaps);
|
|
849
|
+
}
|
|
990
850
|
//# sourceMappingURL=cross-repo-detector.js.map
|