@aiready/context-analyzer 0.21.8 → 0.21.10
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 +11 -11
- package/.turbo/turbo-test.log +26 -26
- package/dist/cli.js +37 -23
- package/dist/cli.mjs +37 -23
- package/dist/index.d.mts +138 -27
- package/dist/index.d.ts +138 -27
- package/dist/index.js +54 -15
- package/dist/index.mjs +54 -15
- package/package.json +2 -2
- package/src/ast-utils.ts +12 -2
- package/src/cli-definition.ts +61 -0
- package/src/cli.ts +2 -44
- package/src/graph-builder.ts +31 -6
- package/src/heuristics.ts +38 -8
- package/src/metrics.ts +21 -8
- package/src/remediation.ts +10 -1
- package/src/scoring.ts +93 -19
- package/src/semantic-analysis.ts +58 -12
- package/src/summary.ts +4 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/context-analyzer@0.21.
|
|
3
|
+
> @aiready/context-analyzer@0.21.10 build /Users/pengcao/projects/aiready/packages/context-analyzer
|
|
4
4
|
> tsup src/index.ts src/cli.ts --format cjs,esm --dts
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
[34mCLI[39m Target: es2020
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[32mCJS[39m [1mdist/cli.js [22m[
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
-
[32mESM[39m [1mdist/cli.mjs [22m[32m4.
|
|
16
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m9.27 KB[39m
|
|
17
|
-
[32mESM[39m [1mdist/python-context-3GZKN3LR.mjs [22m[32m4.47 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/cli.js [22m[32m66.15 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m78.58 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 219ms
|
|
15
|
+
[32mESM[39m [1mdist/cli.mjs [22m[32m4.38 KB[39m
|
|
18
16
|
[32mESM[39m [1mdist/chunk-D25B5LZR.mjs [22m[32m57.60 KB[39m
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m10.53 KB[39m
|
|
19
18
|
[32mESM[39m [1mdist/chunk-64U3PNO3.mjs [22m[32m2.65 KB[39m
|
|
20
|
-
[32mESM[39m
|
|
19
|
+
[32mESM[39m [1mdist/python-context-3GZKN3LR.mjs [22m[32m4.47 KB[39m
|
|
20
|
+
[32mESM[39m ⚡️ Build success in 220ms
|
|
21
21
|
DTS Build start
|
|
22
|
-
DTS ⚡️ Build success in
|
|
22
|
+
DTS ⚡️ Build success in 5273ms
|
|
23
23
|
DTS dist/cli.d.ts 20.00 B
|
|
24
|
-
DTS dist/index.d.ts
|
|
24
|
+
DTS dist/index.d.ts 20.88 KB
|
|
25
25
|
DTS dist/cli.d.mts 20.00 B
|
|
26
|
-
DTS dist/index.d.mts
|
|
26
|
+
DTS dist/index.d.mts 20.88 KB
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/context-analyzer@0.21.
|
|
3
|
+
> @aiready/context-analyzer@0.21.9 test /Users/pengcao/projects/aiready/packages/context-analyzer
|
|
4
4
|
> vitest run
|
|
5
5
|
|
|
6
6
|
[?25l
|
|
7
7
|
[1m[46m RUN [49m[22m [36mv4.0.18 [39m[90m/Users/pengcao/projects/aiready/packages/context-analyzer[39m
|
|
8
8
|
|
|
9
|
+
[32m✓[39m dist/__tests__/scoring.test.js [2m([22m[2m15 tests[22m[2m)[22m[32m 215[2mms[22m[39m
|
|
10
|
+
[32m✓[39m dist/__tests__/fragmentation-coupling.test.js [2m([22m[2m2 tests[22m[2m)[22m[32m 72[2mms[22m[39m
|
|
11
|
+
[32m✓[39m dist/__tests__/analyzer.test.js [2m([22m[2m14 tests[22m[2m)[22m[32m 85[2mms[22m[39m
|
|
12
|
+
[32m✓[39m dist/__tests__/auto-detection.test.js [2m([22m[2m8 tests[22m[2m)[22m[32m 183[2mms[22m[39m
|
|
13
|
+
[32m✓[39m dist/__tests__/contract.test.js [2m([22m[2m1 test[22m[2m)[22m[32m 167[2mms[22m[39m
|
|
14
|
+
[32m✓[39m src/__tests__/file-classification.test.ts [2m([22m[2m63 tests[22m[2m)[22m[32m 19[2mms[22m[39m
|
|
15
|
+
[32m✓[39m src/__tests__/auto-detection.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 29[2mms[22m[39m
|
|
16
|
+
[32m✓[39m src/__tests__/provider.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 4[2mms[22m[39m
|
|
17
|
+
[32m✓[39m src/__tests__/contract.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m 62[2mms[22m[39m
|
|
18
|
+
[32m✓[39m src/__tests__/fragmentation-coupling.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 66[2mms[22m[39m
|
|
19
|
+
[32m✓[39m src/__tests__/analyzer.test.ts [2m([22m[2m14 tests[22m[2m)[22m[32m 20[2mms[22m[39m
|
|
9
20
|
[32m✓[39m dist/__tests__/remediation.test.js [2m([22m[2m6 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
10
21
|
[32m✓[39m src/__tests__/remediation.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
11
|
-
[32m✓[39m
|
|
12
|
-
[32m✓[39m
|
|
13
|
-
[32m✓[39m dist/__tests__/
|
|
14
|
-
[32m✓[39m dist/__tests__/
|
|
15
|
-
[32m✓[39m
|
|
16
|
-
[32m✓[39m
|
|
17
|
-
[32m✓[39m src/__tests__/file-classification.test.ts [2m([22m[2m63 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
18
|
-
[32m✓[39m src/__tests__/fragmentation-coupling.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 12[2mms[22m[39m
|
|
19
|
-
[32m✓[39m src/__tests__/auto-detection.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 17[2mms[22m[39m
|
|
20
|
-
[32m✓[39m src/__tests__/contract.test.ts [2m([22m[2m1 test[22m[2m)[22m[32m 50[2mms[22m[39m
|
|
21
|
-
[32m✓[39m src/__tests__/analyzer.test.ts [2m([22m[2m14 tests[22m[2m)[22m[32m 23[2mms[22m[39m
|
|
22
|
-
[32m✓[39m dist/__tests__/provider.test.js [2m([22m[2m2 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
23
|
-
[32m✓[39m dist/__tests__/file-classification.test.js [2m([22m[2m63 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
24
|
-
[32m✓[39m dist/__tests__/cluster-detector.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
25
|
-
[32m✓[39m src/__tests__/structural-cohesion.test.ts [2m([22m[2m4 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
26
|
-
[32m✓[39m dist/__tests__/scoring.test.js [2m([22m[2m15 tests[22m[2m)[22m[32m 8[2mms[22m[39m
|
|
27
|
-
[32m✓[39m src/__tests__/provider.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
28
|
-
[32m✓[39m dist/__tests__/structural-cohesion.test.js [2m([22m[2m4 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
29
|
-
[32m✓[39m dist/__tests__/fragmentation-log.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
30
|
-
[32m✓[39m dist/__tests__/fragmentation-advanced.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
22
|
+
[32m✓[39m dist/__tests__/file-classification.test.js [2m([22m[2m63 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
23
|
+
[32m✓[39m src/__tests__/scoring.test.ts [2m([22m[2m15 tests[22m[2m)[22m[32m 4[2mms[22m[39m
|
|
24
|
+
[32m✓[39m dist/__tests__/provider.test.js [2m([22m[2m2 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
25
|
+
[32m✓[39m dist/__tests__/fragmentation-log.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
26
|
+
[32m✓[39m src/__tests__/cluster-detector.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
27
|
+
[32m✓[39m dist/__tests__/cluster-detector.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 20[2mms[22m[39m
|
|
31
28
|
[32m✓[39m dist/__tests__/enhanced-cohesion.test.js [2m([22m[2m6 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
32
|
-
[32m✓[39m src/__tests__/
|
|
33
|
-
[32m✓[39m src/__tests__/
|
|
34
|
-
[32m✓[39m
|
|
29
|
+
[32m✓[39m src/__tests__/structural-cohesion.test.ts [2m([22m[2m4 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
30
|
+
[32m✓[39m src/__tests__/enhanced-cohesion.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
31
|
+
[32m✓[39m dist/__tests__/fragmentation-advanced.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
32
|
+
[32m✓[39m dist/__tests__/structural-cohesion.test.js [2m([22m[2m4 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
33
|
+
[32m✓[39m src/__tests__/fragmentation-advanced.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
34
|
+
[32m✓[39m src/__tests__/fragmentation-log.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
35
35
|
|
|
36
36
|
[2m Test Files [22m [1m[32m26 passed[39m[22m[90m (26)[39m
|
|
37
37
|
[2m Tests [22m [1m[32m260 passed[39m[22m[90m (260)[39m
|
|
38
|
-
[2m Start at [22m 10:
|
|
39
|
-
[2m Duration [22m
|
|
38
|
+
[2m Start at [22m 10:12:34
|
|
39
|
+
[2m Duration [22m 8.91s[2m (transform 10.79s, setup 0ms, import 61.94s, tests 991ms, environment 14ms)[22m
|
|
40
40
|
|
|
41
41
|
[?25h
|
package/dist/cli.js
CHANGED
|
@@ -1927,29 +1927,43 @@ async function contextActionHandler(directory, options) {
|
|
|
1927
1927
|
}
|
|
1928
1928
|
}
|
|
1929
1929
|
|
|
1930
|
+
// src/cli-definition.ts
|
|
1931
|
+
function defineContextCommand(program2) {
|
|
1932
|
+
program2.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText(
|
|
1933
|
+
"after",
|
|
1934
|
+
"\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings"
|
|
1935
|
+
).argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
|
|
1936
|
+
"--max-context <number>",
|
|
1937
|
+
"Maximum acceptable context budget (tokens)"
|
|
1938
|
+
).option(
|
|
1939
|
+
"--min-cohesion <number>",
|
|
1940
|
+
"Minimum acceptable cohesion score (0-1)"
|
|
1941
|
+
).option(
|
|
1942
|
+
"--max-fragmentation <number>",
|
|
1943
|
+
"Maximum acceptable fragmentation (0-1)"
|
|
1944
|
+
).option(
|
|
1945
|
+
"--focus <type>",
|
|
1946
|
+
"Analysis focus: fragmentation, cohesion, depth, all"
|
|
1947
|
+
).option("--include-node-modules", "Include node_modules in analysis").option(
|
|
1948
|
+
"--include <patterns>",
|
|
1949
|
+
"File patterns to include (comma-separated)"
|
|
1950
|
+
).option(
|
|
1951
|
+
"--exclude <patterns>",
|
|
1952
|
+
"File patterns to exclude (comma-separated)"
|
|
1953
|
+
).option(
|
|
1954
|
+
"--max-results <number>",
|
|
1955
|
+
"Maximum number of results to show in console output"
|
|
1956
|
+
).option(
|
|
1957
|
+
"-o, --output <format>",
|
|
1958
|
+
"Output format: console, json, html",
|
|
1959
|
+
"console"
|
|
1960
|
+
).option("--output-file <path>", "Output file path (for json/html)").option(
|
|
1961
|
+
"--interactive",
|
|
1962
|
+
"Run interactive setup to suggest excludes and focus areas"
|
|
1963
|
+
).action(contextActionHandler);
|
|
1964
|
+
}
|
|
1965
|
+
|
|
1930
1966
|
// src/cli.ts
|
|
1931
1967
|
var program = new import_commander.Command();
|
|
1932
|
-
program
|
|
1933
|
-
"after",
|
|
1934
|
-
"\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings"
|
|
1935
|
-
).argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
|
|
1936
|
-
"--max-context <number>",
|
|
1937
|
-
"Maximum acceptable context budget (tokens)"
|
|
1938
|
-
).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)").option(
|
|
1939
|
-
"--max-fragmentation <number>",
|
|
1940
|
-
"Maximum acceptable fragmentation (0-1)"
|
|
1941
|
-
).option(
|
|
1942
|
-
"--focus <type>",
|
|
1943
|
-
"Analysis focus: fragmentation, cohesion, depth, all"
|
|
1944
|
-
).option("--include-node-modules", "Include node_modules in analysis").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option(
|
|
1945
|
-
"--max-results <number>",
|
|
1946
|
-
"Maximum number of results to show in console output"
|
|
1947
|
-
).option(
|
|
1948
|
-
"-o, --output <format>",
|
|
1949
|
-
"Output format: console, json, html",
|
|
1950
|
-
"console"
|
|
1951
|
-
).option("--output-file <path>", "Output file path (for json/html)").option(
|
|
1952
|
-
"--interactive",
|
|
1953
|
-
"Run interactive setup to suggest excludes and focus areas"
|
|
1954
|
-
).action(contextActionHandler);
|
|
1968
|
+
defineContextCommand(program);
|
|
1955
1969
|
program.parse(process.argv);
|
package/dist/cli.mjs
CHANGED
|
@@ -90,29 +90,43 @@ async function contextActionHandler(directory, options) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// src/cli-definition.ts
|
|
94
|
+
function defineContextCommand(program2) {
|
|
95
|
+
program2.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText(
|
|
96
|
+
"after",
|
|
97
|
+
"\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings"
|
|
98
|
+
).argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
|
|
99
|
+
"--max-context <number>",
|
|
100
|
+
"Maximum acceptable context budget (tokens)"
|
|
101
|
+
).option(
|
|
102
|
+
"--min-cohesion <number>",
|
|
103
|
+
"Minimum acceptable cohesion score (0-1)"
|
|
104
|
+
).option(
|
|
105
|
+
"--max-fragmentation <number>",
|
|
106
|
+
"Maximum acceptable fragmentation (0-1)"
|
|
107
|
+
).option(
|
|
108
|
+
"--focus <type>",
|
|
109
|
+
"Analysis focus: fragmentation, cohesion, depth, all"
|
|
110
|
+
).option("--include-node-modules", "Include node_modules in analysis").option(
|
|
111
|
+
"--include <patterns>",
|
|
112
|
+
"File patterns to include (comma-separated)"
|
|
113
|
+
).option(
|
|
114
|
+
"--exclude <patterns>",
|
|
115
|
+
"File patterns to exclude (comma-separated)"
|
|
116
|
+
).option(
|
|
117
|
+
"--max-results <number>",
|
|
118
|
+
"Maximum number of results to show in console output"
|
|
119
|
+
).option(
|
|
120
|
+
"-o, --output <format>",
|
|
121
|
+
"Output format: console, json, html",
|
|
122
|
+
"console"
|
|
123
|
+
).option("--output-file <path>", "Output file path (for json/html)").option(
|
|
124
|
+
"--interactive",
|
|
125
|
+
"Run interactive setup to suggest excludes and focus areas"
|
|
126
|
+
).action(contextActionHandler);
|
|
127
|
+
}
|
|
128
|
+
|
|
93
129
|
// src/cli.ts
|
|
94
130
|
var program = new Command();
|
|
95
|
-
program
|
|
96
|
-
"after",
|
|
97
|
-
"\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings"
|
|
98
|
-
).argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
|
|
99
|
-
"--max-context <number>",
|
|
100
|
-
"Maximum acceptable context budget (tokens)"
|
|
101
|
-
).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)").option(
|
|
102
|
-
"--max-fragmentation <number>",
|
|
103
|
-
"Maximum acceptable fragmentation (0-1)"
|
|
104
|
-
).option(
|
|
105
|
-
"--focus <type>",
|
|
106
|
-
"Analysis focus: fragmentation, cohesion, depth, all"
|
|
107
|
-
).option("--include-node-modules", "Include node_modules in analysis").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option(
|
|
108
|
-
"--max-results <number>",
|
|
109
|
-
"Maximum number of results to show in console output"
|
|
110
|
-
).option(
|
|
111
|
-
"-o, --output <format>",
|
|
112
|
-
"Output format: console, json, html",
|
|
113
|
-
"console"
|
|
114
|
-
).option("--output-file <path>", "Output file path (for json/html)").option(
|
|
115
|
-
"--interactive",
|
|
116
|
-
"Run interactive setup to suggest excludes and focus areas"
|
|
117
|
-
).action(contextActionHandler);
|
|
131
|
+
defineContextCommand(program);
|
|
118
132
|
program.parse(process.argv);
|
package/dist/index.d.mts
CHANGED
|
@@ -184,43 +184,66 @@ declare function calculateCohesion(exports: ExportInfo[], filePath?: string, opt
|
|
|
184
184
|
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
185
185
|
|
|
186
186
|
/**
|
|
187
|
-
* Auto-detect domain keywords from workspace folder structure
|
|
187
|
+
* Auto-detect domain keywords from workspace folder structure.
|
|
188
|
+
*
|
|
189
|
+
* @param files - Array of file contents to analyze for folder patterns.
|
|
190
|
+
* @returns Array of singularized domain keywords.
|
|
188
191
|
*/
|
|
189
192
|
declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
|
|
190
193
|
/**
|
|
191
|
-
* Build a dependency graph from file contents
|
|
194
|
+
* Build a dependency graph from file contents, resolving imports and extracting metadata.
|
|
195
|
+
*
|
|
196
|
+
* @param files - Array of file contents to process.
|
|
197
|
+
* @param options - Optional configuration for domain detection.
|
|
198
|
+
* @returns Complete dependency graph with nodes, edges, and semantic matrices.
|
|
192
199
|
*/
|
|
193
200
|
declare function buildDependencyGraph(files: FileContent[], options?: {
|
|
194
201
|
domainKeywords?: string[];
|
|
195
202
|
}): DependencyGraph;
|
|
196
203
|
/**
|
|
197
|
-
* Calculate the maximum depth of import tree for a file
|
|
204
|
+
* Calculate the maximum depth of the import tree for a specific file.
|
|
205
|
+
*
|
|
206
|
+
* @param file - File path to start depth calculation from.
|
|
207
|
+
* @param graph - The dependency graph.
|
|
208
|
+
* @param visited - Optional set to track visited nodes during traversal.
|
|
209
|
+
* @param depth - Current recursion depth.
|
|
210
|
+
* @returns Maximum depth of the import chain.
|
|
198
211
|
*/
|
|
199
212
|
declare function calculateImportDepth(file: string, graph: DependencyGraph, visited?: Set<string>, depth?: number): number;
|
|
200
213
|
/**
|
|
201
|
-
*
|
|
214
|
+
* Retrieve all transitive dependencies for a specific file.
|
|
215
|
+
*
|
|
216
|
+
* @param file - File path to analyze.
|
|
217
|
+
* @param graph - The dependency graph.
|
|
218
|
+
* @param visited - Optional set to track visited nodes.
|
|
219
|
+
* @returns Array of all reachable file paths.
|
|
202
220
|
*/
|
|
203
221
|
declare function getTransitiveDependencies(file: string, graph: DependencyGraph, visited?: Set<string>): string[];
|
|
204
222
|
/**
|
|
205
|
-
* Calculate total context budget (tokens needed to understand this file)
|
|
223
|
+
* Calculate total context budget (tokens needed to understand this file and its dependencies).
|
|
224
|
+
*
|
|
225
|
+
* @param file - File path to calculate budget for.
|
|
226
|
+
* @param graph - The dependency graph.
|
|
227
|
+
* @returns Total token count including recursive dependencies.
|
|
206
228
|
*/
|
|
207
229
|
declare function calculateContextBudget(file: string, graph: DependencyGraph): number;
|
|
208
230
|
/**
|
|
209
|
-
* Detect circular dependencies
|
|
231
|
+
* Detect circular dependencies (cycles) within the dependency graph.
|
|
232
|
+
*
|
|
233
|
+
* @param graph - The dependency graph to scan.
|
|
234
|
+
* @returns Array of dependency cycles (each cycle is an array of file paths).
|
|
210
235
|
*/
|
|
211
236
|
declare function detectCircularDependencies(graph: DependencyGraph): string[][];
|
|
212
237
|
|
|
213
|
-
/**
|
|
214
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
215
|
-
*/
|
|
216
238
|
/**
|
|
217
239
|
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
218
240
|
* shared imports, and internal structure. High cohesion indicates
|
|
219
241
|
* a well-focused module that is easy for AI models to reason about.
|
|
220
242
|
*
|
|
221
|
-
* @param exports - Exported symbols and their metadata
|
|
222
|
-
* @param
|
|
223
|
-
* @
|
|
243
|
+
* @param exports - Exported symbols and their metadata.
|
|
244
|
+
* @param filePath - Optional file path for context.
|
|
245
|
+
* @param options - Optional configuration for weights and co-usage context.
|
|
246
|
+
* @returns Cohesion score between 0 and 1.
|
|
224
247
|
*/
|
|
225
248
|
declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
|
|
226
249
|
coUsageMatrix?: Map<string, Map<string, number>>;
|
|
@@ -232,10 +255,19 @@ declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: str
|
|
|
232
255
|
}): number;
|
|
233
256
|
/**
|
|
234
257
|
* Calculate structural cohesion for a file based on co-usage patterns.
|
|
258
|
+
*
|
|
259
|
+
* @param file - The file path to analyze.
|
|
260
|
+
* @param coUsageMatrix - Matrix of files frequently imported together.
|
|
261
|
+
* @returns Cohesion score between 0 and 1 based on co-usage distribution.
|
|
235
262
|
*/
|
|
236
263
|
declare function calculateStructuralCohesionFromCoUsage(file: string, coUsageMatrix?: Map<string, Map<string, number>>): number;
|
|
237
264
|
/**
|
|
238
265
|
* Calculate fragmentation score (how scattered is a domain)
|
|
266
|
+
*
|
|
267
|
+
* @param files - List of files belonging to the domain.
|
|
268
|
+
* @param domain - The domain identifier.
|
|
269
|
+
* @param options - Optional calculation parameters (log scale, thresholds).
|
|
270
|
+
* @returns Fragmentation score from 0 (perfect) to 1 (highly scattered).
|
|
239
271
|
*/
|
|
240
272
|
declare function calculateFragmentation(files: string[], domain: string, options?: {
|
|
241
273
|
useLogScale?: boolean;
|
|
@@ -244,11 +276,17 @@ declare function calculateFragmentation(files: string[], domain: string, options
|
|
|
244
276
|
dependencyCount?: number;
|
|
245
277
|
}): number;
|
|
246
278
|
/**
|
|
247
|
-
* Calculate path entropy for a set of files
|
|
279
|
+
* Calculate path entropy for a set of files to measure directory distribution.
|
|
280
|
+
*
|
|
281
|
+
* @param files - Array of file paths.
|
|
282
|
+
* @returns Entropy score representing the spread across directories.
|
|
248
283
|
*/
|
|
249
284
|
declare function calculatePathEntropy(files: string[]): number;
|
|
250
285
|
/**
|
|
251
|
-
* Calculate directory-distance metric based on common ancestor depth
|
|
286
|
+
* Calculate directory-distance metric based on common ancestor depth.
|
|
287
|
+
*
|
|
288
|
+
* @param files - Array of file paths to compare.
|
|
289
|
+
* @returns Normalized distance metric (0-1).
|
|
252
290
|
*/
|
|
253
291
|
declare function calculateDirectoryDistance(files: string[]): number;
|
|
254
292
|
|
|
@@ -308,10 +346,19 @@ declare function detectModuleClusters(graph: DependencyGraph, options?: {
|
|
|
308
346
|
|
|
309
347
|
/**
|
|
310
348
|
* Get classification-specific recommendations
|
|
349
|
+
*
|
|
350
|
+
* @param classification - The identified type of file (e.g., 'barrel-export', 'utility-module').
|
|
351
|
+
* @param file - File path or identifier.
|
|
352
|
+
* @param issues - Initial list of issues to supplement.
|
|
353
|
+
* @returns Array of tailored recommendations.
|
|
311
354
|
*/
|
|
312
355
|
declare function getClassificationRecommendations(classification: FileClassification, file: string, issues: string[]): string[];
|
|
313
356
|
/**
|
|
314
|
-
* Generate general context recommendations
|
|
357
|
+
* Generate general context recommendations based on cross-tool metrics and thresholds.
|
|
358
|
+
*
|
|
359
|
+
* @param metrics - Object containing context budget, depth, circular dependencies, cohesion, and fragmentation.
|
|
360
|
+
* @param thresholds - Configurable limits for each metric.
|
|
361
|
+
* @returns Object with recommendations array, issues array, and overall severity level.
|
|
315
362
|
*/
|
|
316
363
|
declare function getGeneralRecommendations(metrics: {
|
|
317
364
|
contextBudget: number;
|
|
@@ -331,9 +378,23 @@ declare function getGeneralRecommendations(metrics: {
|
|
|
331
378
|
};
|
|
332
379
|
|
|
333
380
|
/**
|
|
334
|
-
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
381
|
+
* Calculate AI Readiness Score for context efficiency (0-100).
|
|
382
|
+
*
|
|
383
|
+
* Evaluates how efficiently an AI model can process the project's code context
|
|
384
|
+
* based on token budgets, import depth, and file fragmentation.
|
|
385
|
+
*
|
|
386
|
+
* @param summary - Consolidated context summary from the scan.
|
|
387
|
+
* @param costConfig - Optional configuration for business value calculations.
|
|
388
|
+
* @returns Standardized scoring output for the context analyzer tool.
|
|
389
|
+
* @lastUpdated 2026-03-18
|
|
335
390
|
*/
|
|
336
391
|
declare function calculateContextScore(summary: ContextSummary, costConfig?: Partial<CostConfig>): ToolScoringOutput;
|
|
392
|
+
/**
|
|
393
|
+
* Maps a numerical score to a human-readable rating slug.
|
|
394
|
+
*
|
|
395
|
+
* @param score - The 0-100 readiness score.
|
|
396
|
+
* @returns A formatted rating string (e.g., "excellent", "at risk").
|
|
397
|
+
*/
|
|
337
398
|
declare function mapScoreToRating(score: number): string;
|
|
338
399
|
|
|
339
400
|
/**
|
|
@@ -347,46 +408,96 @@ declare function getSmartDefaults(directory: string, userOptions: Partial<Contex
|
|
|
347
408
|
|
|
348
409
|
/**
|
|
349
410
|
* Generate summary of context analysis results
|
|
411
|
+
*
|
|
412
|
+
* @param results - Array of individual file analysis results.
|
|
413
|
+
* @param options - Optional scan configuration for context extraction.
|
|
414
|
+
* @returns A consolidated summary of the entire context scan.
|
|
350
415
|
*/
|
|
351
416
|
declare function generateSummary(results: ContextAnalysisResult[], options?: any): ContextSummary;
|
|
352
417
|
|
|
353
418
|
/**
|
|
354
|
-
* Build co-usage matrix: track which files are imported together
|
|
355
|
-
*
|
|
356
|
-
* @
|
|
419
|
+
* Build co-usage matrix: track which files are imported together frequently.
|
|
420
|
+
*
|
|
421
|
+
* @param graph - The dependency graph to analyze.
|
|
422
|
+
* @returns Map of file path to nested map of related files and their co-occurrence counts.
|
|
357
423
|
*/
|
|
358
424
|
declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
|
|
359
425
|
/**
|
|
360
|
-
* Extract type dependencies from AST exports
|
|
361
|
-
*
|
|
362
|
-
* @
|
|
426
|
+
* Extract type dependencies from AST exports to build a type-based relationship graph.
|
|
427
|
+
*
|
|
428
|
+
* @param graph - The dependency graph to analyze.
|
|
429
|
+
* @returns Map of type reference names to sets of files that consume or export them.
|
|
363
430
|
*/
|
|
364
431
|
declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
|
|
365
432
|
/**
|
|
366
|
-
* Find semantic clusters using co-usage patterns
|
|
367
|
-
*
|
|
368
|
-
* @param
|
|
369
|
-
* @
|
|
433
|
+
* Find semantic clusters using frequently occurring co-usage patterns.
|
|
434
|
+
*
|
|
435
|
+
* @param coUsageMatrix - The co-usage matrix from buildCoUsageMatrix.
|
|
436
|
+
* @param minCoUsage - Minimum co-usage count to consider a strong relationship (default: 3).
|
|
437
|
+
* @returns Map of cluster representative files to their associated cluster members.
|
|
370
438
|
*/
|
|
371
439
|
declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
|
|
372
440
|
/**
|
|
373
|
-
* Infer domain from semantic analysis (co-usage + types)
|
|
441
|
+
* Infer domain from semantic analysis (co-usage + types) to identify logical modules.
|
|
442
|
+
*
|
|
443
|
+
* @param file - The file path to infer domain for.
|
|
444
|
+
* @param exportName - The specific export identifier.
|
|
445
|
+
* @param graph - The full dependency graph.
|
|
446
|
+
* @param coUsageMatrix - Matrix of files frequently imported together.
|
|
447
|
+
* @param typeGraph - Map of type references to files.
|
|
448
|
+
* @param exportTypeRefs - Optional list of types referenced by the export.
|
|
449
|
+
* @returns Array of potential domain assignments with confidence scores.
|
|
374
450
|
*/
|
|
375
451
|
declare function inferDomainFromSemantics(file: string, exportName: string, graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, exportTypeRefs?: string[]): DomainAssignment[];
|
|
452
|
+
/**
|
|
453
|
+
* Calculate confidence score for a domain assignment based on signals.
|
|
454
|
+
*
|
|
455
|
+
* @param signals - The set of semantic signals detected for a domain.
|
|
456
|
+
* @returns Numerical confidence score (0-1).
|
|
457
|
+
*/
|
|
376
458
|
declare function calculateDomainConfidence(signals: DomainSignals): number;
|
|
377
459
|
/**
|
|
378
460
|
* Regex-based export extraction (legacy/fallback)
|
|
461
|
+
*
|
|
462
|
+
* @param content - Source code content.
|
|
463
|
+
* @param filePath - Optional file path for domain context.
|
|
464
|
+
* @param domainOptions - Optional overrides for domain keywords.
|
|
465
|
+
* @param fileImports - Optional list of actual imports for semantic context.
|
|
466
|
+
* @returns Array of extracted export information.
|
|
379
467
|
*/
|
|
380
468
|
declare function extractExports(content: string, filePath?: string, domainOptions?: {
|
|
381
469
|
domainKeywords?: string[];
|
|
382
470
|
}, fileImports?: string[]): ExportInfo[];
|
|
383
471
|
/**
|
|
384
472
|
* Infer domain from name, path, or imports
|
|
473
|
+
*
|
|
474
|
+
* @param name - The identifier name to analyze.
|
|
475
|
+
* @param filePath - Optional file path for structure context.
|
|
476
|
+
* @param domainOptions - Optional overrides for domain keywords.
|
|
477
|
+
* @param fileImports - Optional list of imports for domain context.
|
|
478
|
+
* @returns The inferred domain name (string).
|
|
385
479
|
*/
|
|
386
480
|
declare function inferDomain(name: string, filePath?: string, domainOptions?: {
|
|
387
481
|
domainKeywords?: string[];
|
|
388
482
|
}, fileImports?: string[]): string;
|
|
483
|
+
/**
|
|
484
|
+
* Retrieve co-usage data for a specific file.
|
|
485
|
+
*
|
|
486
|
+
* @param file - The file path to look up.
|
|
487
|
+
* @param coUsageMatrix - The global co-usage matrix.
|
|
488
|
+
* @returns Formatted co-usage data object.
|
|
489
|
+
*/
|
|
389
490
|
declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
|
|
491
|
+
/**
|
|
492
|
+
* Identify candidates for module consolidation based on high co-usage or shared types.
|
|
493
|
+
*
|
|
494
|
+
* @param graph - The dependency graph.
|
|
495
|
+
* @param coUsageMatrix - Matrix of frequently paired files.
|
|
496
|
+
* @param typeGraph - Map of shared type references.
|
|
497
|
+
* @param minCoUsage - Minimum co-usage count threshold.
|
|
498
|
+
* @param minSharedTypes - Minimum shared types threshold.
|
|
499
|
+
* @returns Array of consolidation candidates sorted by strength.
|
|
500
|
+
*/
|
|
390
501
|
declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
|
|
391
502
|
|
|
392
503
|
/**
|