@aiready/context-analyzer 0.22.15 → 0.22.17
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/.turbo/turbo-build.log +18 -18
- package/.turbo/turbo-format-check.log +1 -1
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +408 -30
- package/.turbo/turbo-type-check.log +1 -1
- package/dist/chunk-2LEHY2GV.mjs +1287 -0
- package/dist/chunk-P2ZQGQAO.mjs +1282 -0
- package/dist/chunk-QGI23DBA.mjs +1282 -0
- package/dist/chunk-QTB4KYCX.mjs +1260 -0
- package/dist/chunk-RQ5BQLT6.mjs +102 -0
- package/dist/chunk-VYFHSGV6.mjs +1283 -0
- package/dist/chunk-WLXLBWDU.mjs +96 -0
- package/dist/chunk-XDYPMFCH.mjs +1250 -0
- package/dist/cli-action-332WE54N.mjs +95 -0
- package/dist/cli-action-7QXG7LHS.mjs +95 -0
- package/dist/cli-action-BIX6TYXF.mjs +95 -0
- package/dist/cli-action-BUGVCH44.mjs +95 -0
- package/dist/cli-action-RO24U52W.mjs +95 -0
- package/dist/cli-action-WAZ5KM6X.mjs +95 -0
- package/dist/cli-action-XDKINE2R.mjs +95 -0
- package/dist/cli-action-Y6VATXMV.mjs +95 -0
- package/dist/cli.js +75 -27
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +71 -25
- package/dist/index.mjs +3 -3
- package/dist/orchestrator-2KQNMO2L.mjs +10 -0
- package/dist/orchestrator-66ZVNOLR.mjs +10 -0
- package/dist/orchestrator-KM2OJPZD.mjs +10 -0
- package/dist/orchestrator-MKDZPRBA.mjs +10 -0
- package/dist/orchestrator-QSHWWBWS.mjs +10 -0
- package/dist/orchestrator-WFQPMNSD.mjs +10 -0
- package/dist/python-context-H2OLC5JN.mjs +162 -0
- package/dist/python-context-OBP7JD5P.mjs +162 -0
- package/package.json +13 -10
- package/src/__tests__/analyzer.test.ts +4 -3
- package/src/__tests__/issue-analyzer.test.ts +4 -2
- package/src/classify/file-classifiers.ts +14 -13
- package/src/cli-action.ts +6 -3
- package/src/graph-builder.ts +43 -8
- package/src/issue-analyzer.ts +19 -7
- package/src/orchestrator.ts +6 -4
- package/src/semantic/domain-inference.ts +1 -1
- package/src/types.ts +2 -0
- package/src/utils/dependency-graph-utils.ts +22 -13
- package/tsconfig.json +2 -1
package/src/issue-analyzer.ts
CHANGED
|
@@ -17,6 +17,7 @@ export { isBuildArtifact };
|
|
|
17
17
|
export function analyzeIssues(params: {
|
|
18
18
|
file: string;
|
|
19
19
|
importDepth: number;
|
|
20
|
+
tokenCost: number;
|
|
20
21
|
contextBudget: number;
|
|
21
22
|
cohesionScore: number;
|
|
22
23
|
fragmentationScore: number;
|
|
@@ -34,6 +35,7 @@ export function analyzeIssues(params: {
|
|
|
34
35
|
const {
|
|
35
36
|
file,
|
|
36
37
|
importDepth,
|
|
38
|
+
tokenCost,
|
|
37
39
|
contextBudget,
|
|
38
40
|
cohesionScore,
|
|
39
41
|
fragmentationScore,
|
|
@@ -74,22 +76,32 @@ export function analyzeIssues(params: {
|
|
|
74
76
|
potentialSavings += contextBudget * 0.15;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
// Check
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
// Check direct file size
|
|
80
|
+
const MAX_FILE_TOKENS = 10000;
|
|
81
|
+
if (tokenCost > MAX_FILE_TOKENS) {
|
|
82
|
+
if (severity !== Severity.Critical) severity = Severity.Major;
|
|
80
83
|
issues.push(
|
|
81
|
-
`
|
|
84
|
+
`File is excessively large (${tokenCost.toLocaleString()} tokens)`
|
|
82
85
|
);
|
|
83
86
|
recommendations.push(
|
|
84
|
-
'Split into smaller modules
|
|
87
|
+
'Split file into smaller, single-responsibility modules'
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Check transitive context budget
|
|
92
|
+
if (contextBudget > maxContextBudget * 1.5) {
|
|
93
|
+
severity = Severity.Critical;
|
|
94
|
+
issues.push(
|
|
95
|
+
`Total context budget ${contextBudget.toLocaleString()} tokens is 50% over limit`
|
|
85
96
|
);
|
|
97
|
+
recommendations.push('Reduce dependency tree width or reduce deep imports');
|
|
86
98
|
potentialSavings += contextBudget * 0.4;
|
|
87
99
|
} else if (contextBudget > maxContextBudget) {
|
|
88
100
|
if (severity !== Severity.Critical) severity = Severity.Major;
|
|
89
101
|
issues.push(
|
|
90
|
-
`
|
|
102
|
+
`Total context budget ${contextBudget.toLocaleString()} exceeds ${maxContextBudget.toLocaleString()}`
|
|
91
103
|
);
|
|
92
|
-
recommendations.push('
|
|
104
|
+
recommendations.push('Optimize dependency graph and reduce deep imports');
|
|
93
105
|
potentialSavings += contextBudget * 0.2;
|
|
94
106
|
}
|
|
95
107
|
|
package/src/orchestrator.ts
CHANGED
|
@@ -76,6 +76,7 @@ function mapNodeToResult(
|
|
|
76
76
|
{
|
|
77
77
|
file,
|
|
78
78
|
importDepth,
|
|
79
|
+
tokenCost,
|
|
79
80
|
contextBudget,
|
|
80
81
|
cohesionScore,
|
|
81
82
|
fragmentationScore,
|
|
@@ -102,8 +103,8 @@ function mapNodeToResult(
|
|
|
102
103
|
tokenCost,
|
|
103
104
|
linesOfCode: node.linesOfCode,
|
|
104
105
|
importDepth,
|
|
105
|
-
dependencyCount: transitiveDeps.
|
|
106
|
-
dependencyList: transitiveDeps,
|
|
106
|
+
dependencyCount: transitiveDeps.size,
|
|
107
|
+
dependencyList: Array.from(transitiveDeps.keys()),
|
|
107
108
|
circularDeps,
|
|
108
109
|
cohesionScore,
|
|
109
110
|
domains: Array.from(
|
|
@@ -166,8 +167,8 @@ export async function analyzeContext(
|
|
|
166
167
|
...scanOptions,
|
|
167
168
|
exclude:
|
|
168
169
|
includeNodeModules && scanOptions.exclude
|
|
169
|
-
? scanOptions.exclude.filter(
|
|
170
|
-
(pattern) => pattern !== '**/node_modules/**'
|
|
170
|
+
? (scanOptions.exclude as string[]).filter(
|
|
171
|
+
(pattern: string) => pattern !== '**/node_modules/**'
|
|
171
172
|
)
|
|
172
173
|
: scanOptions.exclude,
|
|
173
174
|
});
|
|
@@ -197,6 +198,7 @@ export async function analyzeContext(
|
|
|
197
198
|
analyzeIssues({
|
|
198
199
|
file: metric.file,
|
|
199
200
|
importDepth: metric.importDepth,
|
|
201
|
+
tokenCost: metric.contextBudget, // For Python, we use the reported budget as self-cost for now
|
|
200
202
|
contextBudget: metric.contextBudget,
|
|
201
203
|
cohesionScore: metric.cohesion,
|
|
202
204
|
fragmentationScore: 0,
|
package/src/types.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface ContextAnalyzerOptions extends ScanOptions {
|
|
|
18
18
|
focus?: 'fragmentation' | 'cohesion' | 'depth' | 'all';
|
|
19
19
|
/** Whether to include node_modules in the analysis (default: false) */
|
|
20
20
|
includeNodeModules?: boolean;
|
|
21
|
+
/** Maximum number of results to display in console output (default: 10) */
|
|
22
|
+
maxResults?: number;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -31,24 +31,33 @@ export function getTransitiveDependenciesFromEdges(
|
|
|
31
31
|
file: string,
|
|
32
32
|
edges: Map<string, Set<string>>,
|
|
33
33
|
visited = new Set<string>()
|
|
34
|
-
): string
|
|
35
|
-
|
|
34
|
+
): Map<string, number> {
|
|
35
|
+
const result = new Map<string, number>();
|
|
36
|
+
|
|
37
|
+
function dfs(current: string, depth: number) {
|
|
38
|
+
if (visited.has(current)) {
|
|
39
|
+
const existingDepth = result.get(current);
|
|
40
|
+
if (existingDepth !== undefined && depth < existingDepth) {
|
|
41
|
+
result.set(current, depth);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
visited.add(current);
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
if (current !== file) {
|
|
48
|
+
result.set(current, depth);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
const dependencies = edges.get(current);
|
|
52
|
+
if (!dependencies) return;
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
allDeps.push(
|
|
47
|
-
...getTransitiveDependenciesFromEdges(dep, edges, nextVisited)
|
|
48
|
-
);
|
|
54
|
+
for (const dep of dependencies) {
|
|
55
|
+
dfs(dep, depth + 1);
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
|
|
59
|
+
dfs(file, 0);
|
|
60
|
+
return result;
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
export function detectGraphCycles(edges: Map<string, Set<string>>): string[][] {
|