@kodus/kodus-graph 0.2.12 → 0.2.13
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.
|
@@ -90,6 +90,15 @@ export function formatPrompt(output) {
|
|
|
90
90
|
lines.push('');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
// ── Imports for changed files (helps agent spot missing/new dependencies) ──
|
|
94
|
+
const importLines = buildImportsSection(output, analysis);
|
|
95
|
+
if (importLines.length > 0) {
|
|
96
|
+
lines.push('IMPORTS:');
|
|
97
|
+
for (const line of importLines) {
|
|
98
|
+
lines.push(line);
|
|
99
|
+
}
|
|
100
|
+
lines.push('');
|
|
101
|
+
}
|
|
93
102
|
// ── Hierarchy (compact) ──
|
|
94
103
|
if (analysis.inheritance.length > 0) {
|
|
95
104
|
lines.push('HIERARCHY:');
|
|
@@ -216,3 +225,53 @@ function buildSiblingMap(analysis, output) {
|
|
|
216
225
|
}
|
|
217
226
|
return result;
|
|
218
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Build compact IMPORTS section for changed files.
|
|
230
|
+
* Shows each import edge from a changed file with:
|
|
231
|
+
* - NEW tag if the import was added in this change (not in oldGraph)
|
|
232
|
+
* - ⚠ UNRESOLVED if the import target has no corresponding node in the graph
|
|
233
|
+
* Groups by source file for readability.
|
|
234
|
+
*/
|
|
235
|
+
function buildImportsSection(output, analysis) {
|
|
236
|
+
const changedFiles = new Set(analysis.structural_diff.changed_files);
|
|
237
|
+
// Collect IMPORTS edges from changed files
|
|
238
|
+
const importEdges = output.graph.edges.filter((e) => e.kind === 'IMPORTS' && changedFiles.has(e.file_path));
|
|
239
|
+
if (importEdges.length === 0) {
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
// Set of new import edges (added in this diff)
|
|
243
|
+
const newImportKeys = new Set(analysis.structural_diff.edges.added
|
|
244
|
+
.filter((e) => e.kind === 'IMPORTS')
|
|
245
|
+
.map((e) => `${e.source_qualified}→${e.target_qualified}`));
|
|
246
|
+
// Set of all node qualified names — to detect unresolved targets
|
|
247
|
+
const allNodes = new Set(output.graph.nodes.map((n) => n.qualified_name));
|
|
248
|
+
// Group by source file
|
|
249
|
+
const byFile = new Map();
|
|
250
|
+
for (const edge of importEdges) {
|
|
251
|
+
const existing = byFile.get(edge.file_path) || [];
|
|
252
|
+
existing.push(edge);
|
|
253
|
+
byFile.set(edge.file_path, existing);
|
|
254
|
+
}
|
|
255
|
+
const lines = [];
|
|
256
|
+
for (const [filePath, edges] of byFile) {
|
|
257
|
+
for (const edge of edges) {
|
|
258
|
+
const key = `${edge.source_qualified}→${edge.target_qualified}`;
|
|
259
|
+
const tags = [];
|
|
260
|
+
if (newImportKeys.has(key)) {
|
|
261
|
+
tags.push('NEW');
|
|
262
|
+
}
|
|
263
|
+
// Check if target exists as a node in the graph
|
|
264
|
+
// For IMPORTS, target_qualified is usually "file::Symbol".
|
|
265
|
+
// If neither the exact target nor any node starting with the target exists, it's unresolved.
|
|
266
|
+
const targetExists = allNodes.has(edge.target_qualified) ||
|
|
267
|
+
// Also check if the target is a file-level reference (e.g. "src/utils.ts::default")
|
|
268
|
+
[...allNodes].some((qn) => qn.startsWith(`${edge.target_qualified}::`));
|
|
269
|
+
if (!targetExists) {
|
|
270
|
+
tags.push('⚠ UNRESOLVED');
|
|
271
|
+
}
|
|
272
|
+
const tagStr = tags.length > 0 ? ` (${tags.join(', ')})` : '';
|
|
273
|
+
lines.push(` ${filePath} → ${shortName(edge.target_qualified)}${tagStr}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return lines;
|
|
277
|
+
}
|
package/package.json
CHANGED