@aiready/context-analyzer 0.21.5 → 0.21.7
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/.aiready/aiready-report-20260314-222254.json +39216 -0
- package/.aiready/aiready-report-20260314-223947.json +3413 -0
- package/.aiready/aiready-report-20260314-224112.json +3413 -0
- package/.aiready/aiready-report-20260314-224302.json +2973 -0
- package/.aiready/aiready-report-20260314-224939.json +3092 -0
- package/.aiready/aiready-report-20260314-225154.json +3092 -0
- package/.turbo/turbo-build.log +26 -24
- package/.turbo/turbo-lint.log +5 -6
- package/.turbo/turbo-test.log +41 -119
- package/dist/__tests__/analyzer.test.js +55 -14
- package/dist/__tests__/analyzer.test.js.map +1 -1
- package/dist/__tests__/cluster-detector.test.d.ts +2 -0
- package/dist/__tests__/cluster-detector.test.d.ts.map +1 -0
- package/dist/__tests__/cluster-detector.test.js +121 -0
- package/dist/__tests__/cluster-detector.test.js.map +1 -0
- package/dist/__tests__/contract.test.d.ts +2 -0
- package/dist/__tests__/contract.test.d.ts.map +1 -0
- package/dist/__tests__/contract.test.js +59 -0
- package/dist/__tests__/contract.test.js.map +1 -0
- package/dist/__tests__/enhanced-cohesion.test.js +12 -2
- package/dist/__tests__/enhanced-cohesion.test.js.map +1 -1
- package/dist/__tests__/file-classification.test.d.ts +2 -0
- package/dist/__tests__/file-classification.test.d.ts.map +1 -0
- package/dist/__tests__/file-classification.test.js +749 -0
- package/dist/__tests__/file-classification.test.js.map +1 -0
- package/dist/__tests__/fragmentation-advanced.test.js +2 -8
- package/dist/__tests__/fragmentation-advanced.test.js.map +1 -1
- package/dist/__tests__/fragmentation-coupling.test.js +2 -2
- package/dist/__tests__/fragmentation-coupling.test.js.map +1 -1
- package/dist/__tests__/fragmentation-log.test.js +3 -7
- package/dist/__tests__/fragmentation-log.test.js.map +1 -1
- package/dist/__tests__/provider.test.d.ts +2 -0
- package/dist/__tests__/provider.test.d.ts.map +1 -0
- package/dist/__tests__/provider.test.js +72 -0
- package/dist/__tests__/provider.test.js.map +1 -0
- package/dist/__tests__/remediation.test.d.ts +2 -0
- package/dist/__tests__/remediation.test.d.ts.map +1 -0
- package/dist/__tests__/remediation.test.js +61 -0
- package/dist/__tests__/remediation.test.js.map +1 -0
- package/dist/__tests__/scoring.test.js +196 -16
- package/dist/__tests__/scoring.test.js.map +1 -1
- package/dist/__tests__/structural-cohesion.test.js +8 -2
- package/dist/__tests__/structural-cohesion.test.js.map +1 -1
- package/dist/analyzer.d.ts +31 -94
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +260 -678
- package/dist/analyzer.js.map +1 -1
- package/dist/analyzers/python-context.d.ts.map +1 -1
- package/dist/analyzers/python-context.js +10 -8
- package/dist/analyzers/python-context.js.map +1 -1
- package/dist/ast-utils.d.ts +16 -0
- package/dist/ast-utils.d.ts.map +1 -0
- package/dist/ast-utils.js +81 -0
- package/dist/ast-utils.js.map +1 -0
- package/dist/chunk-2HE27YEV.mjs +1739 -0
- package/dist/chunk-64U3PNO3.mjs +94 -0
- package/dist/chunk-CDIVYADN.mjs +2110 -0
- package/dist/chunk-D25B5LZR.mjs +1739 -0
- package/dist/chunk-D3SIHB2V.mjs +2118 -0
- package/dist/chunk-FNPSK3CG.mjs +1760 -0
- package/dist/chunk-GXTGOLZT.mjs +92 -0
- package/dist/chunk-KDUUZQBK.mjs +1692 -0
- package/dist/chunk-KWIS5FQP.mjs +1739 -0
- package/dist/chunk-LERPI33Y.mjs +2060 -0
- package/dist/chunk-MZP3G7TF.mjs +2118 -0
- package/dist/chunk-NOHK5DLU.mjs +2173 -0
- package/dist/chunk-ORLC5Y4J.mjs +1787 -0
- package/dist/chunk-OTCQL7DY.mjs +2045 -0
- package/dist/chunk-RRB2C34Q.mjs +1738 -0
- package/dist/chunk-SFK6XTJE.mjs +2110 -0
- package/dist/chunk-U5R2FTCR.mjs +1803 -0
- package/dist/chunk-UU4HZ7ZT.mjs +1849 -0
- package/dist/chunk-WKOZOHOU.mjs +2060 -0
- package/dist/chunk-XIXAWCMS.mjs +1760 -0
- package/dist/chunk-XTAXUNQN.mjs +1742 -0
- package/dist/classifier.d.ts +114 -0
- package/dist/classifier.d.ts.map +1 -0
- package/dist/classifier.js +439 -0
- package/dist/classifier.js.map +1 -0
- package/dist/cli.js +681 -1170
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +63 -533
- package/dist/cluster-detector.d.ts +8 -0
- package/dist/cluster-detector.d.ts.map +1 -0
- package/dist/cluster-detector.js +70 -0
- package/dist/cluster-detector.js.map +1 -0
- package/dist/defaults.d.ts +7 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +54 -0
- package/dist/defaults.js.map +1 -0
- package/dist/graph-builder.d.ts +33 -0
- package/dist/graph-builder.d.ts.map +1 -0
- package/dist/graph-builder.js +225 -0
- package/dist/graph-builder.js.map +1 -0
- package/dist/index.d.mts +93 -106
- package/dist/index.d.ts +93 -106
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +932 -745
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +262 -28
- package/dist/metrics.d.ts +34 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +170 -0
- package/dist/metrics.js.map +1 -0
- package/dist/provider.d.ts +6 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +48 -0
- package/dist/provider.js.map +1 -0
- package/dist/python-context-3GZKN3LR.mjs +162 -0
- package/dist/python-context-O2EN3M6Z.mjs +162 -0
- package/dist/remediation.d.ts +25 -0
- package/dist/remediation.d.ts.map +1 -0
- package/dist/remediation.js +98 -0
- package/dist/remediation.js.map +1 -0
- package/dist/scoring.d.ts +3 -7
- package/dist/scoring.d.ts.map +1 -1
- package/dist/scoring.js +57 -48
- package/dist/scoring.js.map +1 -1
- package/dist/semantic-analysis.d.ts +12 -23
- package/dist/semantic-analysis.d.ts.map +1 -1
- package/dist/semantic-analysis.js +172 -110
- package/dist/semantic-analysis.js.map +1 -1
- package/dist/summary.d.ts +6 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +92 -0
- package/dist/summary.js.map +1 -0
- package/dist/types.d.ts +9 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/output-formatter.d.ts +14 -0
- package/dist/utils/output-formatter.d.ts.map +1 -0
- package/dist/utils/output-formatter.js +338 -0
- package/dist/utils/output-formatter.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/analyzer.test.ts +1 -1
- package/src/__tests__/auto-detection.test.ts +1 -1
- package/src/__tests__/contract.test.ts +1 -1
- package/src/__tests__/enhanced-cohesion.test.ts +1 -1
- package/src/__tests__/file-classification.test.ts +1 -1
- package/src/__tests__/fragmentation-advanced.test.ts +1 -1
- package/src/__tests__/fragmentation-coupling.test.ts +1 -1
- package/src/__tests__/fragmentation-log.test.ts +1 -1
- package/src/__tests__/provider.test.ts +1 -1
- package/src/__tests__/structural-cohesion.test.ts +1 -1
- package/src/analyzer.ts +112 -317
- package/src/analyzers/python-context.ts +7 -76
- package/src/ast-utils.ts +2 -2
- package/src/classifier.ts +13 -328
- package/src/cli-action.ts +110 -0
- package/src/cli.ts +3 -701
- package/src/cluster-detector.ts +28 -1
- package/src/defaults.ts +3 -0
- package/src/graph-builder.ts +10 -91
- package/src/heuristics.ts +216 -0
- package/src/index.ts +6 -0
- package/src/issue-analyzer.ts +158 -0
- package/src/metrics.ts +9 -0
- package/src/scoring.ts +3 -5
- package/src/semantic-analysis.ts +8 -14
- package/src/summary.ts +62 -106
- package/src/types.ts +52 -20
- package/src/utils/dependency-graph-utils.ts +126 -0
- package/src/utils/output-formatter.ts +411 -0
- package/src/utils/string-utils.ts +21 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,36 +1,68 @@
|
|
|
1
|
-
import { ToolProvider, Severity, ScanOptions, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Severity, ScanOptions, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Context Analyzer Tool Provider
|
|
5
5
|
*/
|
|
6
6
|
declare const ContextAnalyzerProvider: ToolProvider;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Options for the Context Analyzer tool.
|
|
10
|
+
* Controls thresholds for import depth, context budget, and cohesion.
|
|
11
|
+
*/
|
|
8
12
|
interface ContextAnalyzerOptions extends ScanOptions {
|
|
13
|
+
/** Maximum acceptable import depth (default: 5) */
|
|
9
14
|
maxDepth?: number;
|
|
15
|
+
/** Maximum acceptable token budget for a single context (default: 25000) */
|
|
10
16
|
maxContextBudget?: number;
|
|
17
|
+
/** Minimum acceptable cohesion score between 0 and 1 (default: 0.6) */
|
|
11
18
|
minCohesion?: number;
|
|
19
|
+
/** Maximum acceptable fragmentation score between 0 and 1 (default: 0.5) */
|
|
12
20
|
maxFragmentation?: number;
|
|
21
|
+
/** Analysis focus area: fragmentation, cohesion, depth, or all (default: 'all') */
|
|
13
22
|
focus?: 'fragmentation' | 'cohesion' | 'depth' | 'all';
|
|
23
|
+
/** Whether to include node_modules in the analysis (default: false) */
|
|
14
24
|
includeNodeModules?: boolean;
|
|
15
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The result of a context analysis for a single file or module.
|
|
28
|
+
* Includes metrics for tokens, dependencies, cohesion, and AI impact.
|
|
29
|
+
*/
|
|
16
30
|
interface ContextAnalysisResult {
|
|
31
|
+
/** The file path being analyzed */
|
|
17
32
|
file: string;
|
|
33
|
+
/** Total number of tokens in this file */
|
|
18
34
|
tokenCost: number;
|
|
35
|
+
/** Total lines of code in the file */
|
|
19
36
|
linesOfCode: number;
|
|
37
|
+
/** Maximum depth of the import tree for this file */
|
|
20
38
|
importDepth: number;
|
|
39
|
+
/** Total number of transitive dependencies */
|
|
21
40
|
dependencyCount: number;
|
|
41
|
+
/** List of all files in the dependency tree */
|
|
22
42
|
dependencyList: string[];
|
|
43
|
+
/** Detected circular dependency chains */
|
|
23
44
|
circularDeps: string[][];
|
|
45
|
+
/** Cohesion score from 0 to 1 (1 is perfect cohesion) */
|
|
24
46
|
cohesionScore: number;
|
|
47
|
+
/** Detected domain categories for the module */
|
|
25
48
|
domains: string[];
|
|
49
|
+
/** Number of exported symbols */
|
|
26
50
|
exportCount: number;
|
|
51
|
+
/** Total tokens required to understand this file and all its dependencies */
|
|
27
52
|
contextBudget: number;
|
|
53
|
+
/** Fragmentation score from 0 to 1 (0 is well-grouped) */
|
|
28
54
|
fragmentationScore: number;
|
|
55
|
+
/** List of files that should be loaded together for full context */
|
|
29
56
|
relatedFiles: string[];
|
|
57
|
+
/** The semantic classification of the file (e.g. 'barrel-export', 'service-file') */
|
|
30
58
|
fileClassification: FileClassification;
|
|
59
|
+
/** Overall severity of identified issues */
|
|
31
60
|
severity: Severity | 'critical' | 'major' | 'minor' | 'info';
|
|
61
|
+
/** List of specific structural problems found */
|
|
32
62
|
issues: string[];
|
|
63
|
+
/** Actionable suggestions for improving context readiness */
|
|
33
64
|
recommendations: string[];
|
|
65
|
+
/** Estimated tokens that could be saved by following recommendations */
|
|
34
66
|
potentialSavings: number;
|
|
35
67
|
}
|
|
36
68
|
/**
|
|
@@ -128,10 +160,29 @@ interface TypeDependency {
|
|
|
128
160
|
usedBy: string[];
|
|
129
161
|
}
|
|
130
162
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Calculate cohesion score (how related are exports in a file).
|
|
165
|
+
* Legacy wrapper for backward compatibility with exact test expectations.
|
|
166
|
+
*
|
|
167
|
+
* @param exports - List of exported symbols
|
|
168
|
+
* @param filePath - Path to the file being analyzed
|
|
169
|
+
* @param options - Additional options for cohesion calculation
|
|
170
|
+
* @returns Cohesion score between 0 and 1
|
|
171
|
+
*/
|
|
172
|
+
declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
|
|
173
|
+
/**
|
|
174
|
+
* Analyze AI context window cost for a codebase
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Performs deep context analysis of a project.
|
|
178
|
+
* Scans files, builds a dependency graph, calculates context budgets,
|
|
179
|
+
* and identifies structural issues like high fragmentation or depth.
|
|
180
|
+
*
|
|
181
|
+
* @param options - Analysis parameters including root directory and focus areas
|
|
182
|
+
* @returns Comprehensive analysis results with metrics and identified issues
|
|
183
|
+
*/
|
|
184
|
+
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
185
|
+
|
|
135
186
|
/**
|
|
136
187
|
* Auto-detect domain keywords from workspace folder structure
|
|
137
188
|
*/
|
|
@@ -162,6 +213,15 @@ declare function detectCircularDependencies(graph: DependencyGraph): string[][];
|
|
|
162
213
|
/**
|
|
163
214
|
* Calculate cohesion score (how related are exports in a file)
|
|
164
215
|
*/
|
|
216
|
+
/**
|
|
217
|
+
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
218
|
+
* shared imports, and internal structure. High cohesion indicates
|
|
219
|
+
* a well-focused module that is easy for AI models to reason about.
|
|
220
|
+
*
|
|
221
|
+
* @param exports - Exported symbols and their metadata
|
|
222
|
+
* @param imports - Imported symbols and their sources
|
|
223
|
+
* @returns Cohesion score between 0 and 1
|
|
224
|
+
*/
|
|
165
225
|
declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
|
|
166
226
|
coUsageMatrix?: Map<string, Map<string, number>>;
|
|
167
227
|
weights?: {
|
|
@@ -217,76 +277,6 @@ declare const Classification: {
|
|
|
217
277
|
* @returns The determined file classification
|
|
218
278
|
*/
|
|
219
279
|
declare function classifyFile(node: DependencyNode, cohesionScore?: number, domains?: string[]): FileClassification;
|
|
220
|
-
/**
|
|
221
|
-
* Detect if a file is a barrel export (index.ts)
|
|
222
|
-
*
|
|
223
|
-
* @param node The dependency node to check
|
|
224
|
-
* @returns True if the file appears to be a barrel export
|
|
225
|
-
*/
|
|
226
|
-
declare function isBarrelExport(node: DependencyNode): boolean;
|
|
227
|
-
/**
|
|
228
|
-
* Detect if a file is primarily type definitions
|
|
229
|
-
*
|
|
230
|
-
* @param node The dependency node to check
|
|
231
|
-
* @returns True if the file appears to be primarily types
|
|
232
|
-
*/
|
|
233
|
-
declare function isTypeDefinition(node: DependencyNode): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Detect if a file is a utility module
|
|
236
|
-
*
|
|
237
|
-
* @param node The dependency node to check
|
|
238
|
-
* @returns True if the file appears to be a utility module
|
|
239
|
-
*/
|
|
240
|
-
declare function isUtilityModule(node: DependencyNode): boolean;
|
|
241
|
-
/**
|
|
242
|
-
* Detect if a file is a Lambda/API handler
|
|
243
|
-
*
|
|
244
|
-
* @param node The dependency node to check
|
|
245
|
-
* @returns True if the file appears to be a Lambda handler
|
|
246
|
-
*/
|
|
247
|
-
declare function isLambdaHandler(node: DependencyNode): boolean;
|
|
248
|
-
/**
|
|
249
|
-
* Detect if a file is a service file
|
|
250
|
-
*
|
|
251
|
-
* @param node The dependency node to check
|
|
252
|
-
* @returns True if the file appears to be a service file
|
|
253
|
-
*/
|
|
254
|
-
declare function isServiceFile(node: DependencyNode): boolean;
|
|
255
|
-
/**
|
|
256
|
-
* Detect if a file is an email template/layout
|
|
257
|
-
*
|
|
258
|
-
* @param node The dependency node to check
|
|
259
|
-
* @returns True if the file appears to be an email template
|
|
260
|
-
*/
|
|
261
|
-
declare function isEmailTemplate(node: DependencyNode): boolean;
|
|
262
|
-
/**
|
|
263
|
-
* Detect if a file is a parser/transformer
|
|
264
|
-
*
|
|
265
|
-
* @param node The dependency node to check
|
|
266
|
-
* @returns True if the file appears to be a parser
|
|
267
|
-
*/
|
|
268
|
-
declare function isParserFile(node: DependencyNode): boolean;
|
|
269
|
-
/**
|
|
270
|
-
* Detect if a file is a session/state management file
|
|
271
|
-
*
|
|
272
|
-
* @param node The dependency node to check
|
|
273
|
-
* @returns True if the file appears to be a session/state file
|
|
274
|
-
*/
|
|
275
|
-
declare function isSessionFile(node: DependencyNode): boolean;
|
|
276
|
-
/**
|
|
277
|
-
* Detect if a file is a configuration or schema file
|
|
278
|
-
*
|
|
279
|
-
* @param node The dependency node to check
|
|
280
|
-
* @returns True if the file appears to be a config file
|
|
281
|
-
*/
|
|
282
|
-
declare function isConfigFile(node: DependencyNode): boolean;
|
|
283
|
-
/**
|
|
284
|
-
* Detect if a file is a Next.js App Router page
|
|
285
|
-
*
|
|
286
|
-
* @param node The dependency node to check
|
|
287
|
-
* @returns True if the file appears to be a Next.js page
|
|
288
|
-
*/
|
|
289
|
-
declare function isNextJsPage(node: DependencyNode): boolean;
|
|
290
280
|
/**
|
|
291
281
|
* Adjust cohesion score based on file classification
|
|
292
282
|
*
|
|
@@ -307,6 +297,10 @@ declare function adjustFragmentationForClassification(baseFragmentation: number,
|
|
|
307
297
|
|
|
308
298
|
/**
|
|
309
299
|
* Group files by domain to detect module clusters
|
|
300
|
+
* @param graph - The dependency graph to analyze
|
|
301
|
+
* @param options - Optional configuration options
|
|
302
|
+
* @param options.useLogScale - Whether to use logarithmic scaling for calculations
|
|
303
|
+
* @returns Array of module clusters
|
|
310
304
|
*/
|
|
311
305
|
declare function detectModuleClusters(graph: DependencyGraph, options?: {
|
|
312
306
|
useLogScale?: boolean;
|
|
@@ -336,36 +330,6 @@ declare function getGeneralRecommendations(metrics: {
|
|
|
336
330
|
severity: any;
|
|
337
331
|
};
|
|
338
332
|
|
|
339
|
-
/**
|
|
340
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
341
|
-
* Legacy wrapper for backward compatibility with exact test expectations
|
|
342
|
-
*/
|
|
343
|
-
declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
|
|
344
|
-
/**
|
|
345
|
-
* Analyze issues for a single file
|
|
346
|
-
*/
|
|
347
|
-
declare function analyzeIssues(params: {
|
|
348
|
-
file: string;
|
|
349
|
-
importDepth: number;
|
|
350
|
-
contextBudget: number;
|
|
351
|
-
cohesionScore: number;
|
|
352
|
-
fragmentationScore: number;
|
|
353
|
-
maxDepth: number;
|
|
354
|
-
maxContextBudget: number;
|
|
355
|
-
minCohesion: number;
|
|
356
|
-
maxFragmentation: number;
|
|
357
|
-
circularDeps: string[][];
|
|
358
|
-
}): {
|
|
359
|
-
severity: Severity;
|
|
360
|
-
issues: string[];
|
|
361
|
-
recommendations: string[];
|
|
362
|
-
potentialSavings: number;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Analyze AI context window cost for a codebase
|
|
366
|
-
*/
|
|
367
|
-
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
368
|
-
|
|
369
333
|
/**
|
|
370
334
|
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
371
335
|
*/
|
|
@@ -375,6 +339,9 @@ declare function mapScoreToRating(score: number): string;
|
|
|
375
339
|
/**
|
|
376
340
|
* Generate smart defaults for context analysis based on repository size
|
|
377
341
|
* Automatically tunes thresholds to target ~10 most serious issues
|
|
342
|
+
* @param directory - The root directory to analyze
|
|
343
|
+
* @param userOptions - Partial user-provided options to merge with defaults
|
|
344
|
+
* @returns Complete ContextAnalyzerOptions with smart defaults
|
|
378
345
|
*/
|
|
379
346
|
declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
|
|
380
347
|
|
|
@@ -385,14 +352,21 @@ declare function generateSummary(results: ContextAnalysisResult[], options?: any
|
|
|
385
352
|
|
|
386
353
|
/**
|
|
387
354
|
* Build co-usage matrix: track which files are imported together
|
|
355
|
+
* @param graph - The dependency graph to analyze
|
|
356
|
+
* @returns Map of file to co-usage counts
|
|
388
357
|
*/
|
|
389
358
|
declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
|
|
390
359
|
/**
|
|
391
360
|
* Extract type dependencies from AST exports
|
|
361
|
+
* @param graph - The dependency graph to analyze
|
|
362
|
+
* @returns Map of type references to files that use them
|
|
392
363
|
*/
|
|
393
364
|
declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
|
|
394
365
|
/**
|
|
395
366
|
* Find semantic clusters using co-usage patterns
|
|
367
|
+
* @param coUsageMatrix - The co-usage matrix from buildCoUsageMatrix
|
|
368
|
+
* @param minCoUsage - Minimum co-usage count to consider (default: 3)
|
|
369
|
+
* @returns Map of cluster representative files to their cluster members
|
|
396
370
|
*/
|
|
397
371
|
declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
|
|
398
372
|
/**
|
|
@@ -415,4 +389,17 @@ declare function inferDomain(name: string, filePath?: string, domainOptions?: {
|
|
|
415
389
|
declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
|
|
416
390
|
declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
|
|
417
391
|
|
|
418
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Display analysis report in console
|
|
394
|
+
*/
|
|
395
|
+
declare function displayConsoleReport(summary: ReturnType<typeof generateSummary>, results: Awaited<ReturnType<typeof analyzeContext>>, maxResults?: number): void;
|
|
396
|
+
/**
|
|
397
|
+
* Generate HTML report
|
|
398
|
+
*/
|
|
399
|
+
declare function generateHTMLReport(summary: ReturnType<typeof generateSummary>, results: Awaited<ReturnType<typeof analyzeContext>>): string;
|
|
400
|
+
/**
|
|
401
|
+
* Interactive setup: detect common frameworks and suggest excludes & focus areas
|
|
402
|
+
*/
|
|
403
|
+
declare function runInteractiveSetup(directory: string, current: any): Promise<any>;
|
|
404
|
+
|
|
405
|
+
export { Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, type ExportInfo, type FileClassification, type ModuleCluster, 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, mapScoreToRating, runInteractiveSetup };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,68 @@
|
|
|
1
|
-
import { ToolProvider, Severity, ScanOptions, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
1
|
+
import { ToolProvider, Severity, ScanOptions, FileContent, CostConfig, ToolScoringOutput } from '@aiready/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Context Analyzer Tool Provider
|
|
5
5
|
*/
|
|
6
6
|
declare const ContextAnalyzerProvider: ToolProvider;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Options for the Context Analyzer tool.
|
|
10
|
+
* Controls thresholds for import depth, context budget, and cohesion.
|
|
11
|
+
*/
|
|
8
12
|
interface ContextAnalyzerOptions extends ScanOptions {
|
|
13
|
+
/** Maximum acceptable import depth (default: 5) */
|
|
9
14
|
maxDepth?: number;
|
|
15
|
+
/** Maximum acceptable token budget for a single context (default: 25000) */
|
|
10
16
|
maxContextBudget?: number;
|
|
17
|
+
/** Minimum acceptable cohesion score between 0 and 1 (default: 0.6) */
|
|
11
18
|
minCohesion?: number;
|
|
19
|
+
/** Maximum acceptable fragmentation score between 0 and 1 (default: 0.5) */
|
|
12
20
|
maxFragmentation?: number;
|
|
21
|
+
/** Analysis focus area: fragmentation, cohesion, depth, or all (default: 'all') */
|
|
13
22
|
focus?: 'fragmentation' | 'cohesion' | 'depth' | 'all';
|
|
23
|
+
/** Whether to include node_modules in the analysis (default: false) */
|
|
14
24
|
includeNodeModules?: boolean;
|
|
15
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The result of a context analysis for a single file or module.
|
|
28
|
+
* Includes metrics for tokens, dependencies, cohesion, and AI impact.
|
|
29
|
+
*/
|
|
16
30
|
interface ContextAnalysisResult {
|
|
31
|
+
/** The file path being analyzed */
|
|
17
32
|
file: string;
|
|
33
|
+
/** Total number of tokens in this file */
|
|
18
34
|
tokenCost: number;
|
|
35
|
+
/** Total lines of code in the file */
|
|
19
36
|
linesOfCode: number;
|
|
37
|
+
/** Maximum depth of the import tree for this file */
|
|
20
38
|
importDepth: number;
|
|
39
|
+
/** Total number of transitive dependencies */
|
|
21
40
|
dependencyCount: number;
|
|
41
|
+
/** List of all files in the dependency tree */
|
|
22
42
|
dependencyList: string[];
|
|
43
|
+
/** Detected circular dependency chains */
|
|
23
44
|
circularDeps: string[][];
|
|
45
|
+
/** Cohesion score from 0 to 1 (1 is perfect cohesion) */
|
|
24
46
|
cohesionScore: number;
|
|
47
|
+
/** Detected domain categories for the module */
|
|
25
48
|
domains: string[];
|
|
49
|
+
/** Number of exported symbols */
|
|
26
50
|
exportCount: number;
|
|
51
|
+
/** Total tokens required to understand this file and all its dependencies */
|
|
27
52
|
contextBudget: number;
|
|
53
|
+
/** Fragmentation score from 0 to 1 (0 is well-grouped) */
|
|
28
54
|
fragmentationScore: number;
|
|
55
|
+
/** List of files that should be loaded together for full context */
|
|
29
56
|
relatedFiles: string[];
|
|
57
|
+
/** The semantic classification of the file (e.g. 'barrel-export', 'service-file') */
|
|
30
58
|
fileClassification: FileClassification;
|
|
59
|
+
/** Overall severity of identified issues */
|
|
31
60
|
severity: Severity | 'critical' | 'major' | 'minor' | 'info';
|
|
61
|
+
/** List of specific structural problems found */
|
|
32
62
|
issues: string[];
|
|
63
|
+
/** Actionable suggestions for improving context readiness */
|
|
33
64
|
recommendations: string[];
|
|
65
|
+
/** Estimated tokens that could be saved by following recommendations */
|
|
34
66
|
potentialSavings: number;
|
|
35
67
|
}
|
|
36
68
|
/**
|
|
@@ -128,10 +160,29 @@ interface TypeDependency {
|
|
|
128
160
|
usedBy: string[];
|
|
129
161
|
}
|
|
130
162
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Calculate cohesion score (how related are exports in a file).
|
|
165
|
+
* Legacy wrapper for backward compatibility with exact test expectations.
|
|
166
|
+
*
|
|
167
|
+
* @param exports - List of exported symbols
|
|
168
|
+
* @param filePath - Path to the file being analyzed
|
|
169
|
+
* @param options - Additional options for cohesion calculation
|
|
170
|
+
* @returns Cohesion score between 0 and 1
|
|
171
|
+
*/
|
|
172
|
+
declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
|
|
173
|
+
/**
|
|
174
|
+
* Analyze AI context window cost for a codebase
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Performs deep context analysis of a project.
|
|
178
|
+
* Scans files, builds a dependency graph, calculates context budgets,
|
|
179
|
+
* and identifies structural issues like high fragmentation or depth.
|
|
180
|
+
*
|
|
181
|
+
* @param options - Analysis parameters including root directory and focus areas
|
|
182
|
+
* @returns Comprehensive analysis results with metrics and identified issues
|
|
183
|
+
*/
|
|
184
|
+
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
185
|
+
|
|
135
186
|
/**
|
|
136
187
|
* Auto-detect domain keywords from workspace folder structure
|
|
137
188
|
*/
|
|
@@ -162,6 +213,15 @@ declare function detectCircularDependencies(graph: DependencyGraph): string[][];
|
|
|
162
213
|
/**
|
|
163
214
|
* Calculate cohesion score (how related are exports in a file)
|
|
164
215
|
*/
|
|
216
|
+
/**
|
|
217
|
+
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
218
|
+
* shared imports, and internal structure. High cohesion indicates
|
|
219
|
+
* a well-focused module that is easy for AI models to reason about.
|
|
220
|
+
*
|
|
221
|
+
* @param exports - Exported symbols and their metadata
|
|
222
|
+
* @param imports - Imported symbols and their sources
|
|
223
|
+
* @returns Cohesion score between 0 and 1
|
|
224
|
+
*/
|
|
165
225
|
declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
|
|
166
226
|
coUsageMatrix?: Map<string, Map<string, number>>;
|
|
167
227
|
weights?: {
|
|
@@ -217,76 +277,6 @@ declare const Classification: {
|
|
|
217
277
|
* @returns The determined file classification
|
|
218
278
|
*/
|
|
219
279
|
declare function classifyFile(node: DependencyNode, cohesionScore?: number, domains?: string[]): FileClassification;
|
|
220
|
-
/**
|
|
221
|
-
* Detect if a file is a barrel export (index.ts)
|
|
222
|
-
*
|
|
223
|
-
* @param node The dependency node to check
|
|
224
|
-
* @returns True if the file appears to be a barrel export
|
|
225
|
-
*/
|
|
226
|
-
declare function isBarrelExport(node: DependencyNode): boolean;
|
|
227
|
-
/**
|
|
228
|
-
* Detect if a file is primarily type definitions
|
|
229
|
-
*
|
|
230
|
-
* @param node The dependency node to check
|
|
231
|
-
* @returns True if the file appears to be primarily types
|
|
232
|
-
*/
|
|
233
|
-
declare function isTypeDefinition(node: DependencyNode): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Detect if a file is a utility module
|
|
236
|
-
*
|
|
237
|
-
* @param node The dependency node to check
|
|
238
|
-
* @returns True if the file appears to be a utility module
|
|
239
|
-
*/
|
|
240
|
-
declare function isUtilityModule(node: DependencyNode): boolean;
|
|
241
|
-
/**
|
|
242
|
-
* Detect if a file is a Lambda/API handler
|
|
243
|
-
*
|
|
244
|
-
* @param node The dependency node to check
|
|
245
|
-
* @returns True if the file appears to be a Lambda handler
|
|
246
|
-
*/
|
|
247
|
-
declare function isLambdaHandler(node: DependencyNode): boolean;
|
|
248
|
-
/**
|
|
249
|
-
* Detect if a file is a service file
|
|
250
|
-
*
|
|
251
|
-
* @param node The dependency node to check
|
|
252
|
-
* @returns True if the file appears to be a service file
|
|
253
|
-
*/
|
|
254
|
-
declare function isServiceFile(node: DependencyNode): boolean;
|
|
255
|
-
/**
|
|
256
|
-
* Detect if a file is an email template/layout
|
|
257
|
-
*
|
|
258
|
-
* @param node The dependency node to check
|
|
259
|
-
* @returns True if the file appears to be an email template
|
|
260
|
-
*/
|
|
261
|
-
declare function isEmailTemplate(node: DependencyNode): boolean;
|
|
262
|
-
/**
|
|
263
|
-
* Detect if a file is a parser/transformer
|
|
264
|
-
*
|
|
265
|
-
* @param node The dependency node to check
|
|
266
|
-
* @returns True if the file appears to be a parser
|
|
267
|
-
*/
|
|
268
|
-
declare function isParserFile(node: DependencyNode): boolean;
|
|
269
|
-
/**
|
|
270
|
-
* Detect if a file is a session/state management file
|
|
271
|
-
*
|
|
272
|
-
* @param node The dependency node to check
|
|
273
|
-
* @returns True if the file appears to be a session/state file
|
|
274
|
-
*/
|
|
275
|
-
declare function isSessionFile(node: DependencyNode): boolean;
|
|
276
|
-
/**
|
|
277
|
-
* Detect if a file is a configuration or schema file
|
|
278
|
-
*
|
|
279
|
-
* @param node The dependency node to check
|
|
280
|
-
* @returns True if the file appears to be a config file
|
|
281
|
-
*/
|
|
282
|
-
declare function isConfigFile(node: DependencyNode): boolean;
|
|
283
|
-
/**
|
|
284
|
-
* Detect if a file is a Next.js App Router page
|
|
285
|
-
*
|
|
286
|
-
* @param node The dependency node to check
|
|
287
|
-
* @returns True if the file appears to be a Next.js page
|
|
288
|
-
*/
|
|
289
|
-
declare function isNextJsPage(node: DependencyNode): boolean;
|
|
290
280
|
/**
|
|
291
281
|
* Adjust cohesion score based on file classification
|
|
292
282
|
*
|
|
@@ -307,6 +297,10 @@ declare function adjustFragmentationForClassification(baseFragmentation: number,
|
|
|
307
297
|
|
|
308
298
|
/**
|
|
309
299
|
* Group files by domain to detect module clusters
|
|
300
|
+
* @param graph - The dependency graph to analyze
|
|
301
|
+
* @param options - Optional configuration options
|
|
302
|
+
* @param options.useLogScale - Whether to use logarithmic scaling for calculations
|
|
303
|
+
* @returns Array of module clusters
|
|
310
304
|
*/
|
|
311
305
|
declare function detectModuleClusters(graph: DependencyGraph, options?: {
|
|
312
306
|
useLogScale?: boolean;
|
|
@@ -336,36 +330,6 @@ declare function getGeneralRecommendations(metrics: {
|
|
|
336
330
|
severity: any;
|
|
337
331
|
};
|
|
338
332
|
|
|
339
|
-
/**
|
|
340
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
341
|
-
* Legacy wrapper for backward compatibility with exact test expectations
|
|
342
|
-
*/
|
|
343
|
-
declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
|
|
344
|
-
/**
|
|
345
|
-
* Analyze issues for a single file
|
|
346
|
-
*/
|
|
347
|
-
declare function analyzeIssues(params: {
|
|
348
|
-
file: string;
|
|
349
|
-
importDepth: number;
|
|
350
|
-
contextBudget: number;
|
|
351
|
-
cohesionScore: number;
|
|
352
|
-
fragmentationScore: number;
|
|
353
|
-
maxDepth: number;
|
|
354
|
-
maxContextBudget: number;
|
|
355
|
-
minCohesion: number;
|
|
356
|
-
maxFragmentation: number;
|
|
357
|
-
circularDeps: string[][];
|
|
358
|
-
}): {
|
|
359
|
-
severity: Severity;
|
|
360
|
-
issues: string[];
|
|
361
|
-
recommendations: string[];
|
|
362
|
-
potentialSavings: number;
|
|
363
|
-
};
|
|
364
|
-
/**
|
|
365
|
-
* Analyze AI context window cost for a codebase
|
|
366
|
-
*/
|
|
367
|
-
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
368
|
-
|
|
369
333
|
/**
|
|
370
334
|
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
371
335
|
*/
|
|
@@ -375,6 +339,9 @@ declare function mapScoreToRating(score: number): string;
|
|
|
375
339
|
/**
|
|
376
340
|
* Generate smart defaults for context analysis based on repository size
|
|
377
341
|
* Automatically tunes thresholds to target ~10 most serious issues
|
|
342
|
+
* @param directory - The root directory to analyze
|
|
343
|
+
* @param userOptions - Partial user-provided options to merge with defaults
|
|
344
|
+
* @returns Complete ContextAnalyzerOptions with smart defaults
|
|
378
345
|
*/
|
|
379
346
|
declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
|
|
380
347
|
|
|
@@ -385,14 +352,21 @@ declare function generateSummary(results: ContextAnalysisResult[], options?: any
|
|
|
385
352
|
|
|
386
353
|
/**
|
|
387
354
|
* Build co-usage matrix: track which files are imported together
|
|
355
|
+
* @param graph - The dependency graph to analyze
|
|
356
|
+
* @returns Map of file to co-usage counts
|
|
388
357
|
*/
|
|
389
358
|
declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
|
|
390
359
|
/**
|
|
391
360
|
* Extract type dependencies from AST exports
|
|
361
|
+
* @param graph - The dependency graph to analyze
|
|
362
|
+
* @returns Map of type references to files that use them
|
|
392
363
|
*/
|
|
393
364
|
declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
|
|
394
365
|
/**
|
|
395
366
|
* Find semantic clusters using co-usage patterns
|
|
367
|
+
* @param coUsageMatrix - The co-usage matrix from buildCoUsageMatrix
|
|
368
|
+
* @param minCoUsage - Minimum co-usage count to consider (default: 3)
|
|
369
|
+
* @returns Map of cluster representative files to their cluster members
|
|
396
370
|
*/
|
|
397
371
|
declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
|
|
398
372
|
/**
|
|
@@ -415,4 +389,17 @@ declare function inferDomain(name: string, filePath?: string, domainOptions?: {
|
|
|
415
389
|
declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
|
|
416
390
|
declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
|
|
417
391
|
|
|
418
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Display analysis report in console
|
|
394
|
+
*/
|
|
395
|
+
declare function displayConsoleReport(summary: ReturnType<typeof generateSummary>, results: Awaited<ReturnType<typeof analyzeContext>>, maxResults?: number): void;
|
|
396
|
+
/**
|
|
397
|
+
* Generate HTML report
|
|
398
|
+
*/
|
|
399
|
+
declare function generateHTMLReport(summary: ReturnType<typeof generateSummary>, results: Awaited<ReturnType<typeof analyzeContext>>): string;
|
|
400
|
+
/**
|
|
401
|
+
* Interactive setup: detect common frameworks and suggest excludes & focus areas
|
|
402
|
+
*/
|
|
403
|
+
declare function runInteractiveSetup(directory: string, current: any): Promise<any>;
|
|
404
|
+
|
|
405
|
+
export { Classification, type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, ContextAnalyzerProvider, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, type ExportInfo, type FileClassification, type ModuleCluster, 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, mapScoreToRating, runInteractiveSetup };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAKrD,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
|