| 342 | } |
| 343 | |
| 344 | function formatGraph(result: ScanResult): string { |
| 345 | const lines: string[] = ["# Dependency Graph", ""]; |
| 346 | |
| 347 | lines.push("## Most Imported Files (change these carefully)", ""); |
| 348 | for (const hf of result.graph.hotFiles) { |
| 349 | lines.push(`- \`${hf.file}\` — imported by **${hf.importedBy}** files`); |
| 350 | } |
| 351 | lines.push(""); |
| 352 | |
| 353 | // Show top import edges grouped by target |
| 354 | const edgesByTarget = new Map<string, string[]>(); |
| 355 | for (const edge of result.graph.edges) { |
| 356 | if (!edgesByTarget.has(edge.to)) edgesByTarget.set(edge.to, []); |
| 357 | edgesByTarget.get(edge.to)!.push(edge.from); |
| 358 | } |
| 359 | |
| 360 | const topTargets = Array.from(edgesByTarget.entries()) |
| 361 | .sort((a, b) => b[1].length - a[1].length) |
| 362 | .slice(0, 10); |
| 363 | |
| 364 | if (topTargets.length > 0) { |
| 365 | lines.push("## Import Map (who imports what)", ""); |
| 366 | for (const [target, importers] of topTargets) { |
| 367 | const shown = importers.slice(0, 5); |
| 368 | const more = importers.length > 5 ? ` +${importers.length - 5} more` : ""; |
| 369 | lines.push(`- \`${target}\` ← ${shown.map((i) => `\`${i}\``).join(", ")}${more}`); |
| 370 | } |
| 371 | lines.push(""); |
| 372 | } |
| 373 | |
| 374 | return lines.join("\n"); |
| 375 | } |
| 376 | |
| 377 | function formatCombined( |
| 378 | result: ScanResult, |