@girardelli/architect 1.3.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +111 -112
- package/dist/agent-generator.d.ts +95 -0
- package/dist/agent-generator.d.ts.map +1 -0
- package/dist/agent-generator.js +1295 -0
- package/dist/agent-generator.js.map +1 -0
- package/dist/cli.js +76 -2
- package/dist/cli.js.map +1 -1
- package/dist/html-reporter.d.ts +8 -2
- package/dist/html-reporter.d.ts.map +1 -1
- package/dist/html-reporter.js +470 -5
- package/dist/html-reporter.js.map +1 -1
- package/dist/index.d.ts +26 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/refactor-engine.d.ts +18 -0
- package/dist/refactor-engine.d.ts.map +1 -0
- package/dist/refactor-engine.js +86 -0
- package/dist/refactor-engine.js.map +1 -0
- package/dist/refactor-reporter.d.ts +20 -0
- package/dist/refactor-reporter.d.ts.map +1 -0
- package/dist/refactor-reporter.js +389 -0
- package/dist/refactor-reporter.js.map +1 -0
- package/dist/rules/barrel-optimizer.d.ts +13 -0
- package/dist/rules/barrel-optimizer.d.ts.map +1 -0
- package/dist/rules/barrel-optimizer.js +77 -0
- package/dist/rules/barrel-optimizer.js.map +1 -0
- package/dist/rules/dead-code-detector.d.ts +21 -0
- package/dist/rules/dead-code-detector.d.ts.map +1 -0
- package/dist/rules/dead-code-detector.js +117 -0
- package/dist/rules/dead-code-detector.js.map +1 -0
- package/dist/rules/hub-splitter.d.ts +13 -0
- package/dist/rules/hub-splitter.d.ts.map +1 -0
- package/dist/rules/hub-splitter.js +110 -0
- package/dist/rules/hub-splitter.js.map +1 -0
- package/dist/rules/import-organizer.d.ts +13 -0
- package/dist/rules/import-organizer.d.ts.map +1 -0
- package/dist/rules/import-organizer.js +85 -0
- package/dist/rules/import-organizer.js.map +1 -0
- package/dist/rules/module-grouper.d.ts +13 -0
- package/dist/rules/module-grouper.d.ts.map +1 -0
- package/dist/rules/module-grouper.js +110 -0
- package/dist/rules/module-grouper.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent-generator.ts +1401 -0
- package/src/cli.ts +83 -2
- package/src/html-reporter.ts +496 -6
- package/src/index.ts +39 -1
- package/src/refactor-engine.ts +117 -0
- package/src/refactor-reporter.ts +408 -0
- package/src/rules/barrel-optimizer.ts +97 -0
- package/src/rules/dead-code-detector.ts +132 -0
- package/src/rules/hub-splitter.ts +123 -0
- package/src/rules/import-organizer.ts +98 -0
- package/src/rules/module-grouper.ts +124 -0
- package/src/types.ts +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel-optimizer.d.ts","sourceRoot":"","sources":["../../src/rules/barrel-optimizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAExF;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IACtD,IAAI,SAAsB;IAC1B,IAAI,EAAG,CAAC,CAAU;IAElB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAEjC;IAEH,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,EAAE;CAgFrE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { basename, dirname } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Barrel Optimizer Rule (Tier 1)
|
|
4
|
+
* Analyzes barrel files (__init__.py, index.ts) and suggests optimization.
|
|
5
|
+
* Barrel files that re-export everything create unnecessary coupling.
|
|
6
|
+
*/
|
|
7
|
+
export class BarrelOptimizerRule {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = 'barrel-optimizer';
|
|
10
|
+
this.tier = 1;
|
|
11
|
+
}
|
|
12
|
+
analyze(report, projectPath) {
|
|
13
|
+
const steps = [];
|
|
14
|
+
// Find barrel files in the dependency graph
|
|
15
|
+
const barrelNodes = report.dependencyGraph.nodes.filter((n) => BarrelOptimizerRule.BARREL_FILES.has(basename(n)));
|
|
16
|
+
for (const barrel of barrelNodes) {
|
|
17
|
+
// Count how many things this barrel re-exports (outgoing edges)
|
|
18
|
+
const outgoing = report.dependencyGraph.edges.filter((e) => e.from === barrel);
|
|
19
|
+
const incoming = report.dependencyGraph.edges.filter((e) => e.to === barrel);
|
|
20
|
+
if (outgoing.length < 3)
|
|
21
|
+
continue;
|
|
22
|
+
// Check for "pass-through" pattern: files import from barrel
|
|
23
|
+
// but barrel just re-exports from siblings
|
|
24
|
+
const siblingDir = dirname(barrel);
|
|
25
|
+
const siblingExports = outgoing.filter((e) => dirname(e.to) === siblingDir);
|
|
26
|
+
const operations = [];
|
|
27
|
+
// Suggest direct imports instead of barrel
|
|
28
|
+
for (const consumer of incoming) {
|
|
29
|
+
const consumedModules = outgoing
|
|
30
|
+
.filter((e) => {
|
|
31
|
+
// Check if consumer actually needs this module
|
|
32
|
+
return report.dependencyGraph.edges.some((edge) => edge.from === consumer.from && edge.to === e.to);
|
|
33
|
+
})
|
|
34
|
+
.map((e) => e.to);
|
|
35
|
+
if (consumedModules.length > 0) {
|
|
36
|
+
operations.push({
|
|
37
|
+
type: 'MODIFY',
|
|
38
|
+
path: consumer.from,
|
|
39
|
+
description: `Replace barrel import from \`${basename(barrel)}\` with direct imports: ${consumedModules.map((m) => basename(m)).join(', ')}`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Suggest simplifying the barrel
|
|
44
|
+
if (siblingExports.length > 5) {
|
|
45
|
+
operations.push({
|
|
46
|
+
type: 'MODIFY',
|
|
47
|
+
path: barrel,
|
|
48
|
+
description: `Simplify ${basename(barrel)}: only re-export public API (${siblingExports.length} re-exports detected, consider reducing)`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (operations.length > 0) {
|
|
52
|
+
steps.push({
|
|
53
|
+
id: 0,
|
|
54
|
+
tier: 1,
|
|
55
|
+
rule: this.name,
|
|
56
|
+
priority: outgoing.length >= 8 ? 'HIGH' : 'MEDIUM',
|
|
57
|
+
title: `Optimize barrel: ${barrel}`,
|
|
58
|
+
description: `\`${barrel}\` re-exports ${outgoing.length} modules. ` +
|
|
59
|
+
`This creates a "Shotgun Surgery" risk — any change propagates widely.`,
|
|
60
|
+
rationale: `Barrel files that re-export everything make it hard to tree-shake unused code ` +
|
|
61
|
+
`and create implicit dependencies. Direct imports make dependency relationships explicit ` +
|
|
62
|
+
`and reduce the blast radius of changes.`,
|
|
63
|
+
operations,
|
|
64
|
+
scoreImpact: [
|
|
65
|
+
{ metric: 'coupling', before: report.score.breakdown.coupling, after: Math.min(95, report.score.breakdown.coupling + 10) },
|
|
66
|
+
{ metric: 'layering', before: report.score.breakdown.layering, after: Math.min(95, report.score.breakdown.layering + 5) },
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return steps;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
BarrelOptimizerRule.BARREL_FILES = new Set([
|
|
75
|
+
'__init__.py', 'index.ts', 'index.js', 'index.tsx', 'index.jsx',
|
|
76
|
+
]);
|
|
77
|
+
//# sourceMappingURL=barrel-optimizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"barrel-optimizer.js","sourceRoot":"","sources":["../../src/rules/barrel-optimizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGzC;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACE,SAAI,GAAG,kBAAkB,CAAC;QAC1B,SAAI,GAAG,CAAU,CAAC;IAsFpB,CAAC;IAhFC,OAAO,CAAC,MAAsB,EAAE,WAAmB;QACjD,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,4CAA4C;QAC5C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AE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,EAAE,CAAC,EAAE;wBAC1H,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE;qBAC1H;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;;AAnFuB,gCAAY,GAAG,IAAI,GAAG,CAAC;IAC7C,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW;CAChE,CAAC,AAFkC,CAEjC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AnalysisReport, RefactorRule, RefactorStep } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Dead Code Detector Rule (Tier 1)
|
|
4
|
+
* Finds files with no incoming edges (nobody imports them)
|
|
5
|
+
* and exports that are never used.
|
|
6
|
+
*
|
|
7
|
+
* Handles both path-style (deepguard/report.py) and
|
|
8
|
+
* dot-notation (deepguard.report) references.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DeadCodeDetectorRule implements RefactorRule {
|
|
11
|
+
name: string;
|
|
12
|
+
tier: 1;
|
|
13
|
+
private static readonly ENTRY_POINTS;
|
|
14
|
+
analyze(report: AnalysisReport, projectPath: string): RefactorStep[];
|
|
15
|
+
/**
|
|
16
|
+
* Generate dot-notation variants for a file path.
|
|
17
|
+
* "deepguard/report.py" → ["deepguard.report", ".report"]
|
|
18
|
+
*/
|
|
19
|
+
private getDotVariants;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=dead-code-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dead-code-detector.d.ts","sourceRoot":"","sources":["../../src/rules/dead-code-detector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAExF;;;;;;;GAOG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,IAAI,SAAwB;IAC5B,IAAI,EAAG,CAAC,CAAU;IAElB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAIjC;IAEH,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,EAAE;IA0FpE;;;OAGG;IACH,OAAO,CAAC,cAAc;CAgBvB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { basename } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Dead Code Detector Rule (Tier 1)
|
|
4
|
+
* Finds files with no incoming edges (nobody imports them)
|
|
5
|
+
* and exports that are never used.
|
|
6
|
+
*
|
|
7
|
+
* Handles both path-style (deepguard/report.py) and
|
|
8
|
+
* dot-notation (deepguard.report) references.
|
|
9
|
+
*/
|
|
10
|
+
export class DeadCodeDetectorRule {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.name = 'dead-code-detector';
|
|
13
|
+
this.tier = 1;
|
|
14
|
+
}
|
|
15
|
+
analyze(report, projectPath) {
|
|
16
|
+
const steps = [];
|
|
17
|
+
const edges = report.dependencyGraph.edges;
|
|
18
|
+
// Build a set of ALL referenced targets (both path and dot-notation)
|
|
19
|
+
const allTargets = new Set();
|
|
20
|
+
const allSources = new Set();
|
|
21
|
+
for (const edge of edges) {
|
|
22
|
+
allTargets.add(edge.to);
|
|
23
|
+
allSources.add(edge.from);
|
|
24
|
+
}
|
|
25
|
+
// Only consider actual files (with path separators) as candidates
|
|
26
|
+
const fileNodes = report.dependencyGraph.nodes.filter((n) => n.includes('/') || n.includes('\\'));
|
|
27
|
+
// Build incoming edge count considering dot-notation matches
|
|
28
|
+
const incomingCount = {};
|
|
29
|
+
for (const file of fileNodes) {
|
|
30
|
+
incomingCount[file] = 0;
|
|
31
|
+
// Direct incoming edges
|
|
32
|
+
for (const edge of edges) {
|
|
33
|
+
if (edge.to === file) {
|
|
34
|
+
incomingCount[file]++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Check dot-notation references:
|
|
38
|
+
// deepguard/report.py might be referenced as deepguard.report or .report
|
|
39
|
+
const dotVariants = this.getDotVariants(file);
|
|
40
|
+
for (const variant of dotVariants) {
|
|
41
|
+
if (allTargets.has(variant)) {
|
|
42
|
+
incomingCount[file]++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Find orphan files
|
|
47
|
+
const orphans = [];
|
|
48
|
+
for (const [file, count] of Object.entries(incomingCount)) {
|
|
49
|
+
const fileName = basename(file);
|
|
50
|
+
// Skip entry points and config files
|
|
51
|
+
if (DeadCodeDetectorRule.ENTRY_POINTS.has(fileName))
|
|
52
|
+
continue;
|
|
53
|
+
if (fileName.startsWith('__'))
|
|
54
|
+
continue;
|
|
55
|
+
if (fileName.startsWith('.'))
|
|
56
|
+
continue;
|
|
57
|
+
if (fileName.endsWith('.test.ts') || fileName.endsWith('.spec.ts'))
|
|
58
|
+
continue;
|
|
59
|
+
if (fileName.endsWith('_test.py') || fileName.endsWith('.test.py'))
|
|
60
|
+
continue;
|
|
61
|
+
// Also skip if the file has outgoing edges (it's active code)
|
|
62
|
+
if (allSources.has(file))
|
|
63
|
+
continue;
|
|
64
|
+
if (count === 0) {
|
|
65
|
+
orphans.push(file);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (orphans.length > 0) {
|
|
69
|
+
const operations = orphans.map((file) => ({
|
|
70
|
+
type: 'DELETE',
|
|
71
|
+
path: file,
|
|
72
|
+
description: `\`${basename(file)}\` has no incoming dependencies — verify if still needed`,
|
|
73
|
+
}));
|
|
74
|
+
steps.push({
|
|
75
|
+
id: 0,
|
|
76
|
+
tier: 1,
|
|
77
|
+
rule: this.name,
|
|
78
|
+
priority: orphans.length >= 3 ? 'MEDIUM' : 'LOW',
|
|
79
|
+
title: `Review ${orphans.length} potentially unused file(s)`,
|
|
80
|
+
description: `Found ${orphans.length} file(s) with no incoming dependencies: ` +
|
|
81
|
+
`${orphans.map((f) => `\`${basename(f)}\``).join(', ')}. ` +
|
|
82
|
+
`These may be dead code or missing from the module's public API.`,
|
|
83
|
+
rationale: `Files with zero incoming edges are either entry points (already excluded), ` +
|
|
84
|
+
`or potentially dead code. Removing dead code reduces maintenance burden ` +
|
|
85
|
+
`and improves modularity scores.`,
|
|
86
|
+
operations,
|
|
87
|
+
scoreImpact: [
|
|
88
|
+
{ metric: 'modularity', before: report.score.breakdown.modularity, after: Math.min(95, report.score.breakdown.modularity + 5) },
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return steps;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Generate dot-notation variants for a file path.
|
|
96
|
+
* "deepguard/report.py" → ["deepguard.report", ".report"]
|
|
97
|
+
*/
|
|
98
|
+
getDotVariants(filePath) {
|
|
99
|
+
const variants = [];
|
|
100
|
+
const withoutExt = filePath.replace(/\.[^.]+$/, '');
|
|
101
|
+
const dotPath = withoutExt.replace(/[/\\]/g, '.');
|
|
102
|
+
variants.push(dotPath);
|
|
103
|
+
// Relative dot-notation: .report
|
|
104
|
+
const parts = filePath.split('/');
|
|
105
|
+
if (parts.length >= 2) {
|
|
106
|
+
const lastPart = parts[parts.length - 1].replace(/\.[^.]+$/, '');
|
|
107
|
+
variants.push(`.${lastPart}`);
|
|
108
|
+
}
|
|
109
|
+
return variants;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
DeadCodeDetectorRule.ENTRY_POINTS = new Set([
|
|
113
|
+
'main.py', 'cli.py', 'app.py', 'manage.py', 'wsgi.py', 'asgi.py',
|
|
114
|
+
'main.ts', 'main.js', 'app.ts', 'app.js', 'server.ts', 'server.js',
|
|
115
|
+
'index.html', 'setup.py', 'setup.cfg', 'pyproject.toml',
|
|
116
|
+
]);
|
|
117
|
+
//# sourceMappingURL=dead-code-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dead-code-detector.js","sourceRoot":"","sources":["../../src/rules/dead-code-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAGhC;;;;;;;GAOG;AACH,MAAM,OAAO,oBAAoB;IAAjC;QACE,SAAI,GAAG,oBAAoB,CAAC;QAC5B,SAAI,GAAG,CAAU,CAAC;IAsHpB,CAAC;IA9GC,OAAO,CAAC,MAAsB,EAAE,WAAmB;QACjD,MAAM,KAAK,GAAmB,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC;QAE3C,qEAAqE;QACrE,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxB,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAED,kEAAkE;QAClE,MAAM,SAAS,GAAG,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CACnD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAC3C,CAAC;QAEF,6DAA6D;QAC7D,MAAM,aAAa,GAA2B,EAAE,CAAC;QAEjD,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC7B,aAAa,CA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,CAAC;IAED;;;OAGG;IACK,cAAc,CAAC,QAAgB;QACrC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAElD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvB,iCAAiC;QACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YACjE,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;;AAnHuB,iCAAY,GAAG,IAAI,GAAG,CAAC;IAC7C,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS;IAChE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW;IAClE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB;CACxD,CAAC,AAJkC,CAIjC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AnalysisReport, RefactorRule, RefactorStep } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hub Splitter Rule (Tier 1)
|
|
4
|
+
* Detects files with many connections and generates split plans.
|
|
5
|
+
* A "hub" is a file that many other files depend on, creating tight coupling.
|
|
6
|
+
*/
|
|
7
|
+
export declare class HubSplitterRule implements RefactorRule {
|
|
8
|
+
name: string;
|
|
9
|
+
tier: 1;
|
|
10
|
+
analyze(report: AnalysisReport, projectPath: string): RefactorStep[];
|
|
11
|
+
private groupDependents;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=hub-splitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub-splitter.d.ts","sourceRoot":"","sources":["../../src/rules/hub-splitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAExF;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,IAAI,SAAkB;IACtB,IAAI,EAAG,CAAC,CAAU;IAElB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,EAAE;IA4FpE,OAAO,CAAC,eAAe;CAkBxB"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { basename, dirname } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Hub Splitter Rule (Tier 1)
|
|
4
|
+
* Detects files with many connections and generates split plans.
|
|
5
|
+
* A "hub" is a file that many other files depend on, creating tight coupling.
|
|
6
|
+
*/
|
|
7
|
+
export class HubSplitterRule {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = 'hub-splitter';
|
|
10
|
+
this.tier = 1;
|
|
11
|
+
}
|
|
12
|
+
analyze(report, projectPath) {
|
|
13
|
+
const steps = [];
|
|
14
|
+
// Count connections per node
|
|
15
|
+
const connectionCount = {};
|
|
16
|
+
for (const edge of report.dependencyGraph.edges) {
|
|
17
|
+
if (!connectionCount[edge.from])
|
|
18
|
+
connectionCount[edge.from] = { incoming: [], outgoing: [] };
|
|
19
|
+
if (!connectionCount[edge.to])
|
|
20
|
+
connectionCount[edge.to] = { incoming: [], outgoing: [] };
|
|
21
|
+
connectionCount[edge.from].outgoing.push(edge.to);
|
|
22
|
+
connectionCount[edge.to].incoming.push(edge.from);
|
|
23
|
+
}
|
|
24
|
+
// Find hubs (5+ incoming connections, not barrel files)
|
|
25
|
+
const barrelFiles = new Set(['__init__.py', 'index.ts', 'index.js', 'index.tsx', 'mod.rs']);
|
|
26
|
+
for (const [file, connections] of Object.entries(connectionCount)) {
|
|
27
|
+
const fileName = basename(file);
|
|
28
|
+
if (barrelFiles.has(fileName))
|
|
29
|
+
continue;
|
|
30
|
+
if (connections.incoming.length < 5)
|
|
31
|
+
continue;
|
|
32
|
+
const operations = [];
|
|
33
|
+
// Determine if this is a dot-notation module or a real file
|
|
34
|
+
const isDotNotation = !file.includes('/') && !file.includes('\\');
|
|
35
|
+
const moduleName = isDotNotation
|
|
36
|
+
? file.split('.').pop() || file
|
|
37
|
+
: fileName.replace(/\.[^.]+$/, '');
|
|
38
|
+
const moduleDir = isDotNotation
|
|
39
|
+
? file.split('.').slice(0, -1).join('/')
|
|
40
|
+
: dirname(file);
|
|
41
|
+
const ext = isDotNotation ? 'py' : (fileName.split('.').pop() || 'py');
|
|
42
|
+
// Analyze what dependents import to suggest groupings
|
|
43
|
+
const dependentGroups = this.groupDependents(connections.incoming);
|
|
44
|
+
// Suggest splitting into domain modules
|
|
45
|
+
if (dependentGroups.length >= 2) {
|
|
46
|
+
for (const group of dependentGroups) {
|
|
47
|
+
const newFileName = `${moduleName}_${group.name}.${ext}`;
|
|
48
|
+
const newPath = moduleDir ? `${moduleDir}/${newFileName}` : newFileName;
|
|
49
|
+
operations.push({
|
|
50
|
+
type: 'CREATE',
|
|
51
|
+
path: newPath,
|
|
52
|
+
description: `Create \`${newFileName}\` with functionality used by: ${group.dependents.join(', ')}`,
|
|
53
|
+
content: ext === 'py'
|
|
54
|
+
? `"""${moduleName}_${group.name} — extracted from ${moduleName}."""\n# Used by: ${group.dependents.join(', ')}\n`
|
|
55
|
+
: `// ${moduleName}_${group.name} — extracted from ${moduleName}\n// Used by: ${group.dependents.join(', ')}\n`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Update imports in all dependents
|
|
59
|
+
for (const dependent of connections.incoming) {
|
|
60
|
+
operations.push({
|
|
61
|
+
type: 'MODIFY',
|
|
62
|
+
path: dependent,
|
|
63
|
+
description: `Update imports in \`${basename(dependent)}\` to use new split modules`,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Mark original for refactoring
|
|
67
|
+
operations.push({
|
|
68
|
+
type: 'MODIFY',
|
|
69
|
+
path: isDotNotation ? `${moduleDir}/${moduleName}.${ext}` : file,
|
|
70
|
+
description: `Refactor \`${moduleName}.${ext}\` — extract grouped functionality to new modules`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (operations.length > 0) {
|
|
74
|
+
steps.push({
|
|
75
|
+
id: 0,
|
|
76
|
+
tier: 1,
|
|
77
|
+
rule: this.name,
|
|
78
|
+
priority: connections.incoming.length >= 8 ? 'CRITICAL' : 'HIGH',
|
|
79
|
+
title: `Split hub file: ${moduleName}.${ext}`,
|
|
80
|
+
description: `\`${file}\` has ${connections.incoming.length} incoming connections. ` +
|
|
81
|
+
`Split into ${dependentGroups.length} focused modules to reduce coupling.`,
|
|
82
|
+
rationale: `High fan-in (${connections.incoming.length} files depend on this) creates a bottleneck. ` +
|
|
83
|
+
`Changes to this file ripple to ${connections.incoming.length} other files. ` +
|
|
84
|
+
`Splitting by usage pattern reduces blast radius.`,
|
|
85
|
+
operations,
|
|
86
|
+
scoreImpact: [
|
|
87
|
+
{ metric: 'coupling', before: report.score.breakdown.coupling, after: Math.min(95, report.score.breakdown.coupling + 15) },
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return steps;
|
|
93
|
+
}
|
|
94
|
+
groupDependents(dependents) {
|
|
95
|
+
// Group by top-level directory
|
|
96
|
+
const groups = {};
|
|
97
|
+
for (const dep of dependents) {
|
|
98
|
+
const parts = dep.includes('/') ? dep.split('/') : dep.split('.');
|
|
99
|
+
const groupName = parts.length >= 2 ? parts[parts.length - 2] : 'core';
|
|
100
|
+
if (!groups[groupName])
|
|
101
|
+
groups[groupName] = [];
|
|
102
|
+
groups[groupName].push(basename(dep));
|
|
103
|
+
}
|
|
104
|
+
return Object.entries(groups).map(([name, deps]) => ({
|
|
105
|
+
name,
|
|
106
|
+
dependents: deps,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=hub-splitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub-splitter.js","sourceRoot":"","sources":["../../src/rules/hub-splitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAQ,MAAM,MAAM,CAAC;AAG/C;;;;GAIG;AACH,MAAM,OAAO,eAAe;IAA5B;QACE,SAAI,GAAG,cAAc,CAAC;QACtB,SAAI,GAAG,CAAU,CAAC;IAgHpB,CAAC;IA9GC,OAAO,CAAC,MAAsB,EAAE,WAAmB;QACjD,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,6BAA6B;QAC7B,MAAM,eAAe,GAA+D,EAAE,CAAC;QAEvF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YAChD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAC7F,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACzF,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClD,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,C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AAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClE,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YACvE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;gBAAE,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;YAC/C,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI;YACJ,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AnalysisReport, RefactorRule, RefactorStep } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Import Organizer Rule (Tier 1)
|
|
4
|
+
* Detects files that import from too many different modules (cross-boundary).
|
|
5
|
+
* Suggests dependency injection or facade patterns.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ImportOrganizerRule implements RefactorRule {
|
|
8
|
+
name: string;
|
|
9
|
+
tier: 1;
|
|
10
|
+
analyze(report: AnalysisReport, projectPath: string): RefactorStep[];
|
|
11
|
+
private generateFacadeContent;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=import-organizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-organizer.d.ts","sourceRoot":"","sources":["../../src/rules/import-organizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAExF;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,YAAY;IACtD,IAAI,SAAsB;IAC1B,IAAI,EAAG,CAAC,CAAU;IAElB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,EAAE;IAuEpE,OAAO,CAAC,qBAAqB;CAc9B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { basename, dirname } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Import Organizer Rule (Tier 1)
|
|
4
|
+
* Detects files that import from too many different modules (cross-boundary).
|
|
5
|
+
* Suggests dependency injection or facade patterns.
|
|
6
|
+
*/
|
|
7
|
+
export class ImportOrganizerRule {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = 'import-organizer';
|
|
10
|
+
this.tier = 1;
|
|
11
|
+
}
|
|
12
|
+
analyze(report, projectPath) {
|
|
13
|
+
const steps = [];
|
|
14
|
+
// Find files that import from many different directories
|
|
15
|
+
const crossBoundary = {};
|
|
16
|
+
for (const edge of report.dependencyGraph.edges) {
|
|
17
|
+
const fromDir = dirname(edge.from);
|
|
18
|
+
const toDir = dirname(edge.to);
|
|
19
|
+
if (!crossBoundary[edge.from]) {
|
|
20
|
+
crossBoundary[edge.from] = { targets: new Set(), dirs: new Set() };
|
|
21
|
+
}
|
|
22
|
+
crossBoundary[edge.from].targets.add(edge.to);
|
|
23
|
+
if (fromDir !== toDir) {
|
|
24
|
+
crossBoundary[edge.from].dirs.add(toDir);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Files importing from 3+ different directories
|
|
28
|
+
const violators = Object.entries(crossBoundary)
|
|
29
|
+
.filter(([_, data]) => data.dirs.size >= 3)
|
|
30
|
+
.sort((a, b) => b[1].dirs.size - a[1].dirs.size);
|
|
31
|
+
for (const [file, data] of violators) {
|
|
32
|
+
const operations = [];
|
|
33
|
+
const fileName = basename(file);
|
|
34
|
+
const fileDir = dirname(file);
|
|
35
|
+
// Suggest creating a facade/service layer
|
|
36
|
+
const ext = fileName.split('.').pop() || 'py';
|
|
37
|
+
const nameBase = fileName.replace(/\.[^.]+$/, '');
|
|
38
|
+
const facadePath = `${fileDir}/${nameBase}_deps.${ext}`;
|
|
39
|
+
operations.push({
|
|
40
|
+
type: 'CREATE',
|
|
41
|
+
path: facadePath,
|
|
42
|
+
description: `Create dependency facade \`${basename(facadePath)}\` — centralizes ${data.dirs.size} cross-module imports`,
|
|
43
|
+
content: this.generateFacadeContent(ext, Array.from(data.targets), Array.from(data.dirs)),
|
|
44
|
+
});
|
|
45
|
+
operations.push({
|
|
46
|
+
type: 'MODIFY',
|
|
47
|
+
path: file,
|
|
48
|
+
description: `Refactor \`${fileName}\` to import from local facade instead of ${data.dirs.size} different modules`,
|
|
49
|
+
});
|
|
50
|
+
steps.push({
|
|
51
|
+
id: 0,
|
|
52
|
+
tier: 1,
|
|
53
|
+
rule: this.name,
|
|
54
|
+
priority: data.dirs.size >= 5 ? 'HIGH' : 'MEDIUM',
|
|
55
|
+
title: `Reduce cross-boundary imports: ${fileName}`,
|
|
56
|
+
description: `\`${file}\` imports from ${data.dirs.size} different modules: ` +
|
|
57
|
+
`${Array.from(data.dirs).map((d) => `\`${d}\``).join(', ')}. ` +
|
|
58
|
+
`Consider using a facade or dependency injection.`,
|
|
59
|
+
rationale: `Files with imports scattered across many modules have high afferent coupling. ` +
|
|
60
|
+
`A facade centralizes these dependencies, making the file easier to test (mock one facade) ` +
|
|
61
|
+
`and reducing the impact of changes in dependent modules.`,
|
|
62
|
+
operations,
|
|
63
|
+
scoreImpact: [
|
|
64
|
+
{ metric: 'cohesion', before: report.score.breakdown.cohesion, after: Math.min(95, report.score.breakdown.cohesion + 5) },
|
|
65
|
+
{ metric: 'coupling', before: report.score.breakdown.coupling, after: Math.min(95, report.score.breakdown.coupling + 5) },
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return steps;
|
|
70
|
+
}
|
|
71
|
+
generateFacadeContent(ext, targets, dirs) {
|
|
72
|
+
if (ext === 'py') {
|
|
73
|
+
const imports = targets
|
|
74
|
+
.map((t) => `# from ${t.replace(/\//g, '.')} import ...`)
|
|
75
|
+
.join('\n');
|
|
76
|
+
return `"""Dependency facade — centralizes cross-module imports."""\n\n${imports}\n\n# Re-export what ${dirs.length} modules need\n`;
|
|
77
|
+
}
|
|
78
|
+
// JS/TS
|
|
79
|
+
const imports = targets
|
|
80
|
+
.map((t) => `// export { ... } from '${t}';`)
|
|
81
|
+
.join('\n');
|
|
82
|
+
return `/**\n * Dependency facade — centralizes cross-module imports.\n */\n\n${imports}\n`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=import-organizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-organizer.js","sourceRoot":"","sources":["../../src/rules/import-organizer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGzC;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACE,SAAI,GAAG,kBAAkB,CAAC;QAC1B,SAAI,GAAG,CAAU,CAAC;IAuFpB,CAAC;IArFC,OAAO,CAAC,MAAsB,EAAE,WAAmB;QACjD,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,yDAAyD;QACzD,MAAM,aAAa,GAAgE,EAAE,CAAC;QAEtF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAE/B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CA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U,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE;oBACzH,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE;iBAC1H;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,qBAAqB,CAAC,GAAW,EAAE,OAAiB,EAAE,IAAc;QAC1E,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,MAAM,OAAO,GAAG,OAAO;iBACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,aAAa,CAAC;iBACxD,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,OAAO,kEAAkE,OAAO,wBAAwB,IAAI,CAAC,MAAM,iBAAiB,CAAC;QACvI,CAAC;QAED,QAAQ;QACR,MAAM,OAAO,GAAG,OAAO;aACpB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,2BAA2B,CAAC,IAAI,CAAC;aAC5C,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,OAAO,yEAAyE,OAAO,IAAI,CAAC;IAC9F,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AnalysisReport, RefactorRule, RefactorStep } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Module Grouper Rule (Tier 1)
|
|
4
|
+
* Analyzes which files are frequently imported together and suggests
|
|
5
|
+
* grouping them into cohesive modules/packages.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ModuleGrouperRule implements RefactorRule {
|
|
8
|
+
name: string;
|
|
9
|
+
tier: 1;
|
|
10
|
+
analyze(report: AnalysisReport, projectPath: string): RefactorStep[];
|
|
11
|
+
private suggestModuleName;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=module-grouper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-grouper.d.ts","sourceRoot":"","sources":["../../src/rules/module-grouper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAExF;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACpD,IAAI,SAAoB;IACxB,IAAI,EAAG,CAAC,CAAU;IAElB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,YAAY,EAAE;IAqGpE,OAAO,CAAC,iBAAiB;CAU1B"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { basename, dirname, join } from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Module Grouper Rule (Tier 1)
|
|
4
|
+
* Analyzes which files are frequently imported together and suggests
|
|
5
|
+
* grouping them into cohesive modules/packages.
|
|
6
|
+
*/
|
|
7
|
+
export class ModuleGrouperRule {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.name = 'module-grouper';
|
|
10
|
+
this.tier = 1;
|
|
11
|
+
}
|
|
12
|
+
analyze(report, projectPath) {
|
|
13
|
+
const steps = [];
|
|
14
|
+
// Build co-import matrix: which files are imported together?
|
|
15
|
+
const coImportCount = {};
|
|
16
|
+
// For each source file, see what it imports
|
|
17
|
+
const importsBySource = {};
|
|
18
|
+
for (const edge of report.dependencyGraph.edges) {
|
|
19
|
+
if (!importsBySource[edge.from])
|
|
20
|
+
importsBySource[edge.from] = [];
|
|
21
|
+
importsBySource[edge.from].push(edge.to);
|
|
22
|
+
}
|
|
23
|
+
// Count co-imports
|
|
24
|
+
for (const [source, targets] of Object.entries(importsBySource)) {
|
|
25
|
+
for (let i = 0; i < targets.length; i++) {
|
|
26
|
+
for (let j = i + 1; j < targets.length; j++) {
|
|
27
|
+
const a = targets[i];
|
|
28
|
+
const b = targets[j];
|
|
29
|
+
if (!coImportCount[a])
|
|
30
|
+
coImportCount[a] = {};
|
|
31
|
+
if (!coImportCount[b])
|
|
32
|
+
coImportCount[b] = {};
|
|
33
|
+
coImportCount[a][b] = (coImportCount[a][b] || 0) + 1;
|
|
34
|
+
coImportCount[b][a] = (coImportCount[b][a] || 0) + 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// Find clusters: files that are always imported together
|
|
39
|
+
const clusters = [];
|
|
40
|
+
const visited = new Set();
|
|
41
|
+
for (const [fileA, partners] of Object.entries(coImportCount)) {
|
|
42
|
+
if (visited.has(fileA))
|
|
43
|
+
continue;
|
|
44
|
+
const strongPartners = Object.entries(partners)
|
|
45
|
+
.filter(([_, count]) => count >= 2)
|
|
46
|
+
.sort((a, b) => b[1] - a[1]);
|
|
47
|
+
if (strongPartners.length >= 2) {
|
|
48
|
+
const cluster = [fileA, ...strongPartners.map(([f]) => f)];
|
|
49
|
+
const inSameDir = cluster.every((f) => dirname(f) === dirname(cluster[0]));
|
|
50
|
+
// Only suggest if NOT already in the same directory
|
|
51
|
+
if (!inSameDir) {
|
|
52
|
+
const score = strongPartners.reduce((sum, [_, c]) => sum + c, 0);
|
|
53
|
+
clusters.push({ files: cluster, coImportScore: score });
|
|
54
|
+
cluster.forEach((f) => visited.add(f));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Generate steps for each cluster
|
|
59
|
+
for (const cluster of clusters.slice(0, 3)) {
|
|
60
|
+
const operations = [];
|
|
61
|
+
const clusterName = this.suggestModuleName(cluster.files);
|
|
62
|
+
const targetDir = `${dirname(cluster.files[0])}/${clusterName}`;
|
|
63
|
+
// Create new module directory
|
|
64
|
+
operations.push({
|
|
65
|
+
type: 'CREATE',
|
|
66
|
+
path: `${targetDir}/__init__.py`,
|
|
67
|
+
description: `Create new module \`${clusterName}/\` to group ${cluster.files.length} co-dependent files`,
|
|
68
|
+
content: `"""Module ${clusterName} — grouped by co-import pattern."""\n`,
|
|
69
|
+
});
|
|
70
|
+
// Move files
|
|
71
|
+
for (const file of cluster.files) {
|
|
72
|
+
const newPath = join(targetDir, basename(file));
|
|
73
|
+
operations.push({
|
|
74
|
+
type: 'MOVE',
|
|
75
|
+
path: file,
|
|
76
|
+
newPath,
|
|
77
|
+
description: `Move \`${basename(file)}\` → \`${clusterName}/${basename(file)}\``,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
steps.push({
|
|
81
|
+
id: 0,
|
|
82
|
+
tier: 1,
|
|
83
|
+
rule: this.name,
|
|
84
|
+
priority: 'MEDIUM',
|
|
85
|
+
title: `Group co-dependent files into \`${clusterName}/\``,
|
|
86
|
+
description: `Files ${cluster.files.map((f) => `\`${basename(f)}\``).join(', ')} ` +
|
|
87
|
+
`are frequently imported together (co-import score: ${cluster.coImportScore}). ` +
|
|
88
|
+
`Grouping them improves cohesion.`,
|
|
89
|
+
rationale: `Files that are frequently imported together belong in the same module. ` +
|
|
90
|
+
`This improves discoverability and reduces the cognitive load of understanding ` +
|
|
91
|
+
`which files work together.`,
|
|
92
|
+
operations,
|
|
93
|
+
scoreImpact: [
|
|
94
|
+
{ metric: 'cohesion', before: report.score.breakdown.cohesion, after: Math.min(95, report.score.breakdown.cohesion + 10) },
|
|
95
|
+
{ metric: 'modularity', before: report.score.breakdown.modularity, after: Math.min(95, report.score.breakdown.modularity + 5) },
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return steps;
|
|
100
|
+
}
|
|
101
|
+
suggestModuleName(files) {
|
|
102
|
+
// Try to infer a common theme from filenames
|
|
103
|
+
const names = files.map((f) => basename(f).replace(/\.[^.]+$/, '').toLowerCase());
|
|
104
|
+
const commonParts = names[0].split(/[_-]/).filter((part) => names.every((n) => n.includes(part)));
|
|
105
|
+
if (commonParts.length > 0)
|
|
106
|
+
return commonParts[0];
|
|
107
|
+
return 'shared';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=module-grouper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-grouper.js","sourceRoot":"","sources":["../../src/rules/module-grouper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAG/C;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QACE,SAAI,GAAG,gBAAgB,CAAC;QACxB,SAAI,GAAG,CAAU,CAAC;IAiHpB,CAAC;IA/GC,OAAO,CAAC,MAAsB,EAAE,WAAmB;QACjD,MAAM,KAAK,GAAmB,EAAE,CAAC;QAEjC,6DAA6D;QAC7D,MAAM,aAAa,GAA2C,EAAE,CAAC;QAEjE,4CAA4C;QAC5C,MAAM,eAAe,GAA6B,EAAE,CAAC;QACrD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;YAChD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACjE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,mBAAmB;QACnB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;YAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACxC,KAAK,IAAI,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