@aiready/context-analyzer 0.22.4 → 0.22.6
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 +13 -13
- package/.turbo/turbo-test.log +23 -23
- package/dist/chunk-6FQYIG6I.mjs +1298 -0
- package/dist/chunk-M2EGQ36M.mjs +1304 -0
- package/dist/chunk-P74BO725.mjs +1296 -0
- package/dist/cli-action-3CWN7PBE.mjs +95 -0
- package/dist/cli-action-MLFCIW2O.mjs +95 -0
- package/dist/cli-action-VCXBZGZP.mjs +95 -0
- package/dist/cli.js +12 -7
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.js +17 -8
- package/dist/index.mjs +2 -2
- package/dist/orchestrator-3ERQS3NW.mjs +10 -0
- package/dist/orchestrator-5AL3XBPZ.mjs +10 -0
- package/dist/orchestrator-KMAKMHTD.mjs +10 -0
- package/package.json +2 -2
- package/src/ast-utils.ts +2 -2
- package/src/cli-action.ts +3 -3
- package/src/cluster-detector.ts +3 -1
- package/src/graph-builder.ts +6 -2
- package/src/metrics.ts +2 -2
- package/src/orchestrator.ts +4 -2
- package/src/provider.ts +7 -3
- package/src/remediation.ts +5 -1
- package/src/semantic/domain-inference.ts +17 -6
- package/src/types.ts +2 -11
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
displayConsoleReport,
|
|
3
|
+
generateHTMLReport,
|
|
4
|
+
runInteractiveSetup
|
|
5
|
+
} from "./chunk-J3SZQZNU.mjs";
|
|
6
|
+
import {
|
|
7
|
+
analyzeContext
|
|
8
|
+
} from "./chunk-6FQYIG6I.mjs";
|
|
9
|
+
import "./chunk-64U3PNO3.mjs";
|
|
10
|
+
import {
|
|
11
|
+
generateSummary
|
|
12
|
+
} from "./chunk-BQCISA2F.mjs";
|
|
13
|
+
import "./chunk-EMYD7NS6.mjs";
|
|
14
|
+
|
|
15
|
+
// src/cli-action.ts
|
|
16
|
+
import {
|
|
17
|
+
loadMergedConfig,
|
|
18
|
+
handleJSONOutput,
|
|
19
|
+
handleCLIError,
|
|
20
|
+
getElapsedTime,
|
|
21
|
+
resolveOutputPath
|
|
22
|
+
} from "@aiready/core";
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
import { writeFileSync } from "fs";
|
|
25
|
+
async function contextActionHandler(directory, options) {
|
|
26
|
+
console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
try {
|
|
29
|
+
const defaults = {
|
|
30
|
+
maxDepth: 5,
|
|
31
|
+
maxContextBudget: 1e4,
|
|
32
|
+
minCohesion: 0.6,
|
|
33
|
+
maxFragmentation: 0.5,
|
|
34
|
+
focus: "all",
|
|
35
|
+
includeNodeModules: false,
|
|
36
|
+
include: void 0,
|
|
37
|
+
exclude: void 0,
|
|
38
|
+
maxResults: 10
|
|
39
|
+
};
|
|
40
|
+
let finalOptions = await loadMergedConfig(directory, defaults, {
|
|
41
|
+
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
|
|
42
|
+
maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
|
|
43
|
+
minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
|
|
44
|
+
maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
|
|
45
|
+
focus: options.focus || void 0,
|
|
46
|
+
includeNodeModules: options.includeNodeModules,
|
|
47
|
+
include: options.include?.split(","),
|
|
48
|
+
exclude: options.exclude?.split(","),
|
|
49
|
+
maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
|
|
50
|
+
});
|
|
51
|
+
if (options.interactive) {
|
|
52
|
+
finalOptions = await runInteractiveSetup(directory, finalOptions);
|
|
53
|
+
}
|
|
54
|
+
const results = await analyzeContext(finalOptions);
|
|
55
|
+
const summary = generateSummary(results, finalOptions);
|
|
56
|
+
const duration = getElapsedTime(startTime);
|
|
57
|
+
if (options.output === "json") {
|
|
58
|
+
handleJSONOutput(
|
|
59
|
+
{
|
|
60
|
+
summary: {
|
|
61
|
+
...summary,
|
|
62
|
+
executionTime: duration,
|
|
63
|
+
config: {
|
|
64
|
+
scan: { tools: ["context"] },
|
|
65
|
+
tools: { context: finalOptions }
|
|
66
|
+
},
|
|
67
|
+
toolConfigs: { context: finalOptions }
|
|
68
|
+
},
|
|
69
|
+
context: { results }
|
|
70
|
+
},
|
|
71
|
+
options.outputFile
|
|
72
|
+
);
|
|
73
|
+
} else if (options.output === "html") {
|
|
74
|
+
const html = generateHTMLReport(summary, results);
|
|
75
|
+
const outputPath = resolveOutputPath(
|
|
76
|
+
directory,
|
|
77
|
+
options.outputFile,
|
|
78
|
+
"context-report.html"
|
|
79
|
+
);
|
|
80
|
+
writeFileSync(outputPath, html, "utf-8");
|
|
81
|
+
console.log(chalk.green(`
|
|
82
|
+
\u2705 HTML report saved to: ${outputPath}`));
|
|
83
|
+
} else {
|
|
84
|
+
displayConsoleReport(summary, results, finalOptions.maxResults);
|
|
85
|
+
console.log(chalk.dim(`
|
|
86
|
+
\u2728 Analysis completed in ${duration}ms
|
|
87
|
+
`));
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
handleCLIError(error, "context-analyzer");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
contextActionHandler
|
|
95
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
displayConsoleReport,
|
|
3
|
+
generateHTMLReport,
|
|
4
|
+
runInteractiveSetup
|
|
5
|
+
} from "./chunk-J3SZQZNU.mjs";
|
|
6
|
+
import {
|
|
7
|
+
analyzeContext
|
|
8
|
+
} from "./chunk-P74BO725.mjs";
|
|
9
|
+
import "./chunk-64U3PNO3.mjs";
|
|
10
|
+
import {
|
|
11
|
+
generateSummary
|
|
12
|
+
} from "./chunk-BQCISA2F.mjs";
|
|
13
|
+
import "./chunk-EMYD7NS6.mjs";
|
|
14
|
+
|
|
15
|
+
// src/cli-action.ts
|
|
16
|
+
import {
|
|
17
|
+
loadMergedConfig,
|
|
18
|
+
handleJSONOutput,
|
|
19
|
+
handleCLIError,
|
|
20
|
+
getElapsedTime,
|
|
21
|
+
resolveOutputPath
|
|
22
|
+
} from "@aiready/core";
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
import { writeFileSync } from "fs";
|
|
25
|
+
async function contextActionHandler(directory, options) {
|
|
26
|
+
console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
try {
|
|
29
|
+
const defaults = {
|
|
30
|
+
maxDepth: 5,
|
|
31
|
+
maxContextBudget: 1e4,
|
|
32
|
+
minCohesion: 0.6,
|
|
33
|
+
maxFragmentation: 0.5,
|
|
34
|
+
focus: "all",
|
|
35
|
+
includeNodeModules: false,
|
|
36
|
+
include: void 0,
|
|
37
|
+
exclude: void 0,
|
|
38
|
+
maxResults: 10
|
|
39
|
+
};
|
|
40
|
+
let finalOptions = await loadMergedConfig(directory, defaults, {
|
|
41
|
+
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
|
|
42
|
+
maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
|
|
43
|
+
minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
|
|
44
|
+
maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
|
|
45
|
+
focus: options.focus || void 0,
|
|
46
|
+
includeNodeModules: options.includeNodeModules,
|
|
47
|
+
include: options.include?.split(","),
|
|
48
|
+
exclude: options.exclude?.split(","),
|
|
49
|
+
maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
|
|
50
|
+
});
|
|
51
|
+
if (options.interactive) {
|
|
52
|
+
finalOptions = await runInteractiveSetup(directory, finalOptions);
|
|
53
|
+
}
|
|
54
|
+
const results = await analyzeContext(finalOptions);
|
|
55
|
+
const summary = generateSummary(results, finalOptions);
|
|
56
|
+
const duration = getElapsedTime(startTime);
|
|
57
|
+
if (options.output === "json") {
|
|
58
|
+
handleJSONOutput(
|
|
59
|
+
{
|
|
60
|
+
summary: {
|
|
61
|
+
...summary,
|
|
62
|
+
executionTime: duration,
|
|
63
|
+
config: {
|
|
64
|
+
scan: { tools: ["context"] },
|
|
65
|
+
tools: { context: finalOptions }
|
|
66
|
+
},
|
|
67
|
+
toolConfigs: { context: finalOptions }
|
|
68
|
+
},
|
|
69
|
+
context: { results }
|
|
70
|
+
},
|
|
71
|
+
options.outputFile
|
|
72
|
+
);
|
|
73
|
+
} else if (options.output === "html") {
|
|
74
|
+
const html = generateHTMLReport(summary, results);
|
|
75
|
+
const outputPath = resolveOutputPath(
|
|
76
|
+
directory,
|
|
77
|
+
options.outputFile,
|
|
78
|
+
"context-report.html"
|
|
79
|
+
);
|
|
80
|
+
writeFileSync(outputPath, html, "utf-8");
|
|
81
|
+
console.log(chalk.green(`
|
|
82
|
+
\u2705 HTML report saved to: ${outputPath}`));
|
|
83
|
+
} else {
|
|
84
|
+
displayConsoleReport(summary, results, finalOptions.maxResults);
|
|
85
|
+
console.log(chalk.dim(`
|
|
86
|
+
\u2728 Analysis completed in ${duration}ms
|
|
87
|
+
`));
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
handleCLIError(error, "context-analyzer");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
contextActionHandler
|
|
95
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
displayConsoleReport,
|
|
3
|
+
generateHTMLReport,
|
|
4
|
+
runInteractiveSetup
|
|
5
|
+
} from "./chunk-J3SZQZNU.mjs";
|
|
6
|
+
import {
|
|
7
|
+
analyzeContext
|
|
8
|
+
} from "./chunk-M2EGQ36M.mjs";
|
|
9
|
+
import "./chunk-64U3PNO3.mjs";
|
|
10
|
+
import {
|
|
11
|
+
generateSummary
|
|
12
|
+
} from "./chunk-BQCISA2F.mjs";
|
|
13
|
+
import "./chunk-EMYD7NS6.mjs";
|
|
14
|
+
|
|
15
|
+
// src/cli-action.ts
|
|
16
|
+
import {
|
|
17
|
+
loadMergedConfig,
|
|
18
|
+
handleJSONOutput,
|
|
19
|
+
handleCLIError,
|
|
20
|
+
getElapsedTime,
|
|
21
|
+
resolveOutputPath
|
|
22
|
+
} from "@aiready/core";
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
import { writeFileSync } from "fs";
|
|
25
|
+
async function contextActionHandler(directory, options) {
|
|
26
|
+
console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
try {
|
|
29
|
+
const defaults = {
|
|
30
|
+
maxDepth: 5,
|
|
31
|
+
maxContextBudget: 1e4,
|
|
32
|
+
minCohesion: 0.6,
|
|
33
|
+
maxFragmentation: 0.5,
|
|
34
|
+
focus: "all",
|
|
35
|
+
includeNodeModules: false,
|
|
36
|
+
include: void 0,
|
|
37
|
+
exclude: void 0,
|
|
38
|
+
maxResults: 10
|
|
39
|
+
};
|
|
40
|
+
let finalOptions = await loadMergedConfig(directory, defaults, {
|
|
41
|
+
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
|
|
42
|
+
maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
|
|
43
|
+
minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
|
|
44
|
+
maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
|
|
45
|
+
focus: options.focus || void 0,
|
|
46
|
+
includeNodeModules: options.includeNodeModules,
|
|
47
|
+
include: options.include?.split(","),
|
|
48
|
+
exclude: options.exclude?.split(","),
|
|
49
|
+
maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
|
|
50
|
+
});
|
|
51
|
+
if (options.interactive) {
|
|
52
|
+
finalOptions = await runInteractiveSetup(directory, finalOptions);
|
|
53
|
+
}
|
|
54
|
+
const results = await analyzeContext(finalOptions);
|
|
55
|
+
const summary = generateSummary(results, finalOptions);
|
|
56
|
+
const duration = getElapsedTime(startTime);
|
|
57
|
+
if (options.output === "json") {
|
|
58
|
+
handleJSONOutput(
|
|
59
|
+
{
|
|
60
|
+
summary: {
|
|
61
|
+
...summary,
|
|
62
|
+
executionTime: duration,
|
|
63
|
+
config: {
|
|
64
|
+
scan: { tools: ["context"] },
|
|
65
|
+
tools: { context: finalOptions }
|
|
66
|
+
},
|
|
67
|
+
toolConfigs: { context: finalOptions }
|
|
68
|
+
},
|
|
69
|
+
context: { results }
|
|
70
|
+
},
|
|
71
|
+
options.outputFile
|
|
72
|
+
);
|
|
73
|
+
} else if (options.output === "html") {
|
|
74
|
+
const html = generateHTMLReport(summary, results);
|
|
75
|
+
const outputPath = resolveOutputPath(
|
|
76
|
+
directory,
|
|
77
|
+
options.outputFile,
|
|
78
|
+
"context-report.html"
|
|
79
|
+
);
|
|
80
|
+
writeFileSync(outputPath, html, "utf-8");
|
|
81
|
+
console.log(chalk.green(`
|
|
82
|
+
\u2705 HTML report saved to: ${outputPath}`));
|
|
83
|
+
} else {
|
|
84
|
+
displayConsoleReport(summary, results, finalOptions.maxResults);
|
|
85
|
+
console.log(chalk.dim(`
|
|
86
|
+
\u2728 Analysis completed in ${duration}ms
|
|
87
|
+
`));
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
handleCLIError(error, "context-analyzer");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
contextActionHandler
|
|
95
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -410,8 +410,9 @@ function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGr
|
|
|
410
410
|
const coNode = graph.nodes.get(coFile);
|
|
411
411
|
if (coNode) {
|
|
412
412
|
for (const exp of coNode.exports) {
|
|
413
|
-
|
|
414
|
-
|
|
413
|
+
const expAny = exp;
|
|
414
|
+
if (expAny.inferredDomain && expAny.inferredDomain !== "unknown") {
|
|
415
|
+
const domain = expAny.inferredDomain;
|
|
415
416
|
if (!domainSignals.has(domain)) {
|
|
416
417
|
domainSignals.set(domain, {
|
|
417
418
|
coUsage: false,
|
|
@@ -435,8 +436,9 @@ function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGr
|
|
|
435
436
|
const typeNode = graph.nodes.get(typeFile);
|
|
436
437
|
if (typeNode) {
|
|
437
438
|
for (const exp of typeNode.exports) {
|
|
438
|
-
|
|
439
|
-
|
|
439
|
+
const expAny = exp;
|
|
440
|
+
if (expAny.inferredDomain && expAny.inferredDomain !== "unknown") {
|
|
441
|
+
const domain = expAny.inferredDomain;
|
|
440
442
|
if (!domainSignals.has(domain)) {
|
|
441
443
|
domainSignals.set(domain, {
|
|
442
444
|
coUsage: false,
|
|
@@ -709,9 +711,10 @@ async function buildDependencyGraph(files, options) {
|
|
|
709
711
|
typeGraph,
|
|
710
712
|
exp.typeReferences
|
|
711
713
|
);
|
|
712
|
-
|
|
714
|
+
const expAny = exp;
|
|
715
|
+
expAny.domains = semanticAssignments;
|
|
713
716
|
if (semanticAssignments.length > 0) {
|
|
714
|
-
|
|
717
|
+
expAny.inferredDomain = semanticAssignments[0].domain;
|
|
715
718
|
}
|
|
716
719
|
}
|
|
717
720
|
}
|
|
@@ -1528,7 +1531,9 @@ function mapNodeToResult(node, graph, clusters, allCircularDeps, options) {
|
|
|
1528
1531
|
cohesionScore,
|
|
1529
1532
|
domains: Array.from(
|
|
1530
1533
|
new Set(
|
|
1531
|
-
node.exports.flatMap(
|
|
1534
|
+
node.exports.flatMap(
|
|
1535
|
+
(e) => e.domains?.map((d) => d.domain) || []
|
|
1536
|
+
)
|
|
1532
1537
|
)
|
|
1533
1538
|
),
|
|
1534
1539
|
exportCount: node.exports.length,
|
package/dist/cli.mjs
CHANGED
|
@@ -37,7 +37,7 @@ function defineContextCommand(program2) {
|
|
|
37
37
|
"--interactive",
|
|
38
38
|
"Run interactive setup to suggest excludes and focus areas"
|
|
39
39
|
).action(async (directory, options) => {
|
|
40
|
-
const { contextActionHandler } = await import("./cli-action-
|
|
40
|
+
const { contextActionHandler } = await import("./cli-action-VCXBZGZP.mjs");
|
|
41
41
|
await contextActionHandler(directory, options);
|
|
42
42
|
});
|
|
43
43
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ToolProvider, Severity, ScanOptions, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Severity, ScanOptions, ExportInfo, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
2
|
+
export { ExportInfo } from '@aiready/core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Context Analyzer Tool Provider
|
|
@@ -128,15 +129,6 @@ interface DependencyNode {
|
|
|
128
129
|
exportedBy?: string[];
|
|
129
130
|
sharedTypes?: string[];
|
|
130
131
|
}
|
|
131
|
-
interface ExportInfo {
|
|
132
|
-
name: string;
|
|
133
|
-
type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default';
|
|
134
|
-
inferredDomain?: string;
|
|
135
|
-
domains?: DomainAssignment[];
|
|
136
|
-
imports?: string[];
|
|
137
|
-
dependencies?: string[];
|
|
138
|
-
typeReferences?: string[];
|
|
139
|
-
}
|
|
140
132
|
interface DomainAssignment {
|
|
141
133
|
domain: string;
|
|
142
134
|
confidence: number;
|
|
@@ -648,4 +640,4 @@ declare function generateHTMLReport(summary: ReturnType<typeof generateSummary>,
|
|
|
648
640
|
*/
|
|
649
641
|
declare function runInteractiveSetup(directory: string, current: any): Promise<any>;
|
|
650
642
|
|
|
651
|
-
export { BARREL_EXPORT_MIN_EXPORTS, BARREL_EXPORT_TOKEN_LIMIT, CONFIG_NAME_PATTERNS, Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, EMAIL_NAME_PATTERNS, type
|
|
643
|
+
export { BARREL_EXPORT_MIN_EXPORTS, BARREL_EXPORT_TOKEN_LIMIT, CONFIG_NAME_PATTERNS, Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, EMAIL_NAME_PATTERNS, type FileClassification, HANDLER_NAME_PATTERNS, type MappingOptions, type ModuleCluster, NEXTJS_METADATA_EXPORTS, PARSER_NAME_PATTERNS, SERVICE_NAME_PATTERNS, SESSION_NAME_PATTERNS, type TypeDependency, adjustCohesionForClassification, adjustFragmentationForClassification, analyzeContext, buildCoUsageMatrix, buildDependencyGraph, buildTypeGraph, calculateCohesion, calculateContextBudget, calculateContextScore, calculateDirectoryDistance, calculateDomainConfidence, calculateEnhancedCohesion, calculateFragmentation, calculateImportDepth, calculatePathEntropy, calculateStructuralCohesionFromCoUsage, classifyFile, detectCircularDependencies, detectModuleClusters, displayConsoleReport, extractDomainKeywordsFromPaths, extractExports, findConsolidationCandidates, findSemanticClusters, generateHTMLReport, generateSummary, getClassificationRecommendations, getCoUsageData, getGeneralRecommendations, getSmartDefaults, getTransitiveDependencies, inferDomain, inferDomainFromSemantics, isBarrelExport, isBoilerplateBarrel, isConfigFile, isEmailTemplate, isHubAndSpokeFile, isLambdaHandler, isNextJsPage, isParserFile, isServiceFile, isSessionFile, isTypeDefinition, isUtilityModule, mapScoreToRating, runInteractiveSetup };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ToolProvider, Severity, ScanOptions, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Severity, ScanOptions, ExportInfo, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
2
|
+
export { ExportInfo } from '@aiready/core';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Context Analyzer Tool Provider
|
|
@@ -128,15 +129,6 @@ interface DependencyNode {
|
|
|
128
129
|
exportedBy?: string[];
|
|
129
130
|
sharedTypes?: string[];
|
|
130
131
|
}
|
|
131
|
-
interface ExportInfo {
|
|
132
|
-
name: string;
|
|
133
|
-
type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default';
|
|
134
|
-
inferredDomain?: string;
|
|
135
|
-
domains?: DomainAssignment[];
|
|
136
|
-
imports?: string[];
|
|
137
|
-
dependencies?: string[];
|
|
138
|
-
typeReferences?: string[];
|
|
139
|
-
}
|
|
140
132
|
interface DomainAssignment {
|
|
141
133
|
domain: string;
|
|
142
134
|
confidence: number;
|
|
@@ -648,4 +640,4 @@ declare function generateHTMLReport(summary: ReturnType<typeof generateSummary>,
|
|
|
648
640
|
*/
|
|
649
641
|
declare function runInteractiveSetup(directory: string, current: any): Promise<any>;
|
|
650
642
|
|
|
651
|
-
export { BARREL_EXPORT_MIN_EXPORTS, BARREL_EXPORT_TOKEN_LIMIT, CONFIG_NAME_PATTERNS, Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, EMAIL_NAME_PATTERNS, type
|
|
643
|
+
export { BARREL_EXPORT_MIN_EXPORTS, BARREL_EXPORT_TOKEN_LIMIT, CONFIG_NAME_PATTERNS, Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, EMAIL_NAME_PATTERNS, type FileClassification, HANDLER_NAME_PATTERNS, type MappingOptions, type ModuleCluster, NEXTJS_METADATA_EXPORTS, PARSER_NAME_PATTERNS, SERVICE_NAME_PATTERNS, SESSION_NAME_PATTERNS, type TypeDependency, adjustCohesionForClassification, adjustFragmentationForClassification, analyzeContext, buildCoUsageMatrix, buildDependencyGraph, buildTypeGraph, calculateCohesion, calculateContextBudget, calculateContextScore, calculateDirectoryDistance, calculateDomainConfidence, calculateEnhancedCohesion, calculateFragmentation, calculateImportDepth, calculatePathEntropy, calculateStructuralCohesionFromCoUsage, classifyFile, detectCircularDependencies, detectModuleClusters, displayConsoleReport, extractDomainKeywordsFromPaths, extractExports, findConsolidationCandidates, findSemanticClusters, generateHTMLReport, generateSummary, getClassificationRecommendations, getCoUsageData, getGeneralRecommendations, getSmartDefaults, getTransitiveDependencies, inferDomain, inferDomainFromSemantics, isBarrelExport, isBoilerplateBarrel, isConfigFile, isEmailTemplate, isHubAndSpokeFile, isLambdaHandler, isNextJsPage, isParserFile, isServiceFile, isSessionFile, isTypeDefinition, isUtilityModule, mapScoreToRating, runInteractiveSetup };
|
package/dist/index.js
CHANGED
|
@@ -476,8 +476,9 @@ function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGr
|
|
|
476
476
|
const coNode = graph.nodes.get(coFile);
|
|
477
477
|
if (coNode) {
|
|
478
478
|
for (const exp of coNode.exports) {
|
|
479
|
-
|
|
480
|
-
|
|
479
|
+
const expAny = exp;
|
|
480
|
+
if (expAny.inferredDomain && expAny.inferredDomain !== "unknown") {
|
|
481
|
+
const domain = expAny.inferredDomain;
|
|
481
482
|
if (!domainSignals.has(domain)) {
|
|
482
483
|
domainSignals.set(domain, {
|
|
483
484
|
coUsage: false,
|
|
@@ -501,8 +502,9 @@ function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGr
|
|
|
501
502
|
const typeNode = graph.nodes.get(typeFile);
|
|
502
503
|
if (typeNode) {
|
|
503
504
|
for (const exp of typeNode.exports) {
|
|
504
|
-
|
|
505
|
-
|
|
505
|
+
const expAny = exp;
|
|
506
|
+
if (expAny.inferredDomain && expAny.inferredDomain !== "unknown") {
|
|
507
|
+
const domain = expAny.inferredDomain;
|
|
506
508
|
if (!domainSignals.has(domain)) {
|
|
507
509
|
domainSignals.set(domain, {
|
|
508
510
|
coUsage: false,
|
|
@@ -775,9 +777,10 @@ async function buildDependencyGraph(files, options) {
|
|
|
775
777
|
typeGraph,
|
|
776
778
|
exp.typeReferences
|
|
777
779
|
);
|
|
778
|
-
|
|
780
|
+
const expAny = exp;
|
|
781
|
+
expAny.domains = semanticAssignments;
|
|
779
782
|
if (semanticAssignments.length > 0) {
|
|
780
|
-
|
|
783
|
+
expAny.inferredDomain = semanticAssignments[0].domain;
|
|
781
784
|
}
|
|
782
785
|
}
|
|
783
786
|
}
|
|
@@ -1408,7 +1411,11 @@ function getGeneralRecommendations(metrics, thresholds) {
|
|
|
1408
1411
|
);
|
|
1409
1412
|
if (severity === "info") severity = "minor";
|
|
1410
1413
|
}
|
|
1411
|
-
return {
|
|
1414
|
+
return {
|
|
1415
|
+
recommendations,
|
|
1416
|
+
issues,
|
|
1417
|
+
severity
|
|
1418
|
+
};
|
|
1412
1419
|
}
|
|
1413
1420
|
var init_remediation = __esm({
|
|
1414
1421
|
"src/remediation.ts"() {
|
|
@@ -1644,7 +1651,9 @@ function mapNodeToResult(node, graph, clusters, allCircularDeps, options) {
|
|
|
1644
1651
|
cohesionScore,
|
|
1645
1652
|
domains: Array.from(
|
|
1646
1653
|
new Set(
|
|
1647
|
-
node.exports.flatMap(
|
|
1654
|
+
node.exports.flatMap(
|
|
1655
|
+
(e) => e.domains?.map((d) => d.domain) || []
|
|
1656
|
+
)
|
|
1648
1657
|
)
|
|
1649
1658
|
),
|
|
1650
1659
|
exportCount: node.exports.length,
|
package/dist/index.mjs
CHANGED
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
isSessionFile,
|
|
49
49
|
isTypeDefinition,
|
|
50
50
|
isUtilityModule
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-M2EGQ36M.mjs";
|
|
52
52
|
import "./chunk-64U3PNO3.mjs";
|
|
53
53
|
import {
|
|
54
54
|
generateSummary
|
|
@@ -265,7 +265,7 @@ var ContextAnalyzerProvider = {
|
|
|
265
265
|
id: ToolName2.ContextAnalyzer,
|
|
266
266
|
alias: ["context", "fragmentation", "budget"],
|
|
267
267
|
async analyze(options) {
|
|
268
|
-
const { analyzeContext: analyzeContext2 } = await import("./orchestrator-
|
|
268
|
+
const { analyzeContext: analyzeContext2 } = await import("./orchestrator-KMAKMHTD.mjs");
|
|
269
269
|
const { generateSummary: generateSummary2 } = await import("./summary-7PZVW72O.mjs");
|
|
270
270
|
const results = await analyzeContext2(options);
|
|
271
271
|
const summary = generateSummary2(results, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/context-analyzer",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.6",
|
|
4
4
|
"description": "AI context window cost analysis - detect fragmented code, deep import chains, and expensive context budgets",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"commander": "^14.0.0",
|
|
50
50
|
"chalk": "^5.3.0",
|
|
51
51
|
"prompts": "^2.4.2",
|
|
52
|
-
"@aiready/core": "0.24.
|
|
52
|
+
"@aiready/core": "0.24.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^24.0.0",
|
package/src/ast-utils.ts
CHANGED
|
@@ -29,7 +29,7 @@ export async function extractExportsWithAST(
|
|
|
29
29
|
|
|
30
30
|
return astExports.map((exp) => ({
|
|
31
31
|
name: exp.name,
|
|
32
|
-
type: exp.type as
|
|
32
|
+
type: exp.type as ExportInfo['type'],
|
|
33
33
|
inferredDomain: inferDomain(
|
|
34
34
|
exp.name,
|
|
35
35
|
filePath,
|
|
@@ -38,7 +38,7 @@ export async function extractExportsWithAST(
|
|
|
38
38
|
),
|
|
39
39
|
imports: exp.imports,
|
|
40
40
|
dependencies: exp.dependencies,
|
|
41
|
-
typeReferences:
|
|
41
|
+
typeReferences: exp.typeReferences,
|
|
42
42
|
}));
|
|
43
43
|
} catch {
|
|
44
44
|
// Ultimate fallback
|
package/src/cli-action.ts
CHANGED
|
@@ -40,7 +40,7 @@ export async function contextActionHandler(directory: string, options: any) {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
// Load and merge config with CLI options
|
|
43
|
-
let finalOptions =
|
|
43
|
+
let finalOptions = await loadMergedConfig(directory, defaults, {
|
|
44
44
|
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : undefined,
|
|
45
45
|
maxContextBudget: options.maxContext
|
|
46
46
|
? parseInt(options.maxContext)
|
|
@@ -58,7 +58,7 @@ export async function contextActionHandler(directory: string, options: any) {
|
|
|
58
58
|
include: options.include?.split(','),
|
|
59
59
|
exclude: options.exclude?.split(','),
|
|
60
60
|
maxResults: options.maxResults ? parseInt(options.maxResults) : undefined,
|
|
61
|
-
})
|
|
61
|
+
});
|
|
62
62
|
|
|
63
63
|
// Interactive setup if requested
|
|
64
64
|
if (options.interactive) {
|
|
@@ -66,7 +66,7 @@ export async function contextActionHandler(directory: string, options: any) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Run analysis
|
|
69
|
-
const results = await analyzeContext(finalOptions);
|
|
69
|
+
const results = await analyzeContext(finalOptions as any);
|
|
70
70
|
const summary = generateSummary(results, finalOptions);
|
|
71
71
|
|
|
72
72
|
const duration = getElapsedTime(startTime);
|
package/src/cluster-detector.ts
CHANGED
|
@@ -19,7 +19,9 @@ export function detectModuleClusters(
|
|
|
19
19
|
const domainMap = new Map<string, string[]>();
|
|
20
20
|
|
|
21
21
|
for (const [file, node] of graph.nodes.entries()) {
|
|
22
|
-
const primaryDomain =
|
|
22
|
+
const primaryDomain =
|
|
23
|
+
(node.exports[0] as { inferredDomain?: string })?.inferredDomain ||
|
|
24
|
+
'unknown';
|
|
23
25
|
if (!domainMap.has(primaryDomain)) {
|
|
24
26
|
domainMap.set(primaryDomain, []);
|
|
25
27
|
}
|
package/src/graph-builder.ts
CHANGED
|
@@ -189,9 +189,13 @@ export async function buildDependencyGraph(
|
|
|
189
189
|
typeGraph,
|
|
190
190
|
exp.typeReferences
|
|
191
191
|
);
|
|
192
|
-
|
|
192
|
+
const expAny = exp as {
|
|
193
|
+
inferredDomain?: string;
|
|
194
|
+
domains?: Array<{ domain: string }>;
|
|
195
|
+
};
|
|
196
|
+
expAny.domains = semanticAssignments;
|
|
193
197
|
if (semanticAssignments.length > 0) {
|
|
194
|
-
|
|
198
|
+
expAny.inferredDomain = semanticAssignments[0].domain;
|
|
195
199
|
}
|
|
196
200
|
}
|
|
197
201
|
}
|
package/src/metrics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { calculateImportSimilarity, isTestFile } from '@aiready/core';
|
|
2
|
-
import type { ExportInfo } from '
|
|
2
|
+
import type { ExportInfo } from '@aiready/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
@@ -29,7 +29,7 @@ export function calculateEnhancedCohesion(
|
|
|
29
29
|
if (filePath && isTestFile(filePath)) return 1;
|
|
30
30
|
|
|
31
31
|
// 1. Domain-based cohesion using entropy
|
|
32
|
-
const domains = exports.map((e) => e.inferredDomain || 'unknown');
|
|
32
|
+
const domains = exports.map((e: any) => e.inferredDomain || 'unknown');
|
|
33
33
|
const domainCounts = new Map<string, number>();
|
|
34
34
|
for (const domain of domains)
|
|
35
35
|
domainCounts.set(domain, (domainCounts.get(domain) || 0) + 1);
|
package/src/orchestrator.ts
CHANGED
|
@@ -56,7 +56,7 @@ function mapNodeToResult(
|
|
|
56
56
|
const rawCohesionScore = calculateEnhancedCohesion(
|
|
57
57
|
node.exports,
|
|
58
58
|
file,
|
|
59
|
-
options as
|
|
59
|
+
options as unknown as Record<string, unknown>
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
// Initial classification
|
|
@@ -108,7 +108,9 @@ function mapNodeToResult(
|
|
|
108
108
|
cohesionScore,
|
|
109
109
|
domains: Array.from(
|
|
110
110
|
new Set(
|
|
111
|
-
node.exports.flatMap(
|
|
111
|
+
node.exports.flatMap(
|
|
112
|
+
(e: any) => e.domains?.map((d: any) => d.domain) || []
|
|
113
|
+
)
|
|
112
114
|
)
|
|
113
115
|
),
|
|
114
116
|
exportCount: node.exports.length,
|