@aiready/context-analyzer 0.9.41 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/.turbo/turbo-build.log +10 -10
  2. package/.turbo/turbo-test.log +21 -20
  3. package/dist/chunk-4SYIJ7CU.mjs +1538 -0
  4. package/dist/chunk-4XQVYYPC.mjs +1470 -0
  5. package/dist/chunk-5CLU3HYU.mjs +1475 -0
  6. package/dist/chunk-5K73Q3OQ.mjs +1520 -0
  7. package/dist/chunk-6AVS4KTM.mjs +1536 -0
  8. package/dist/chunk-6I4552YB.mjs +1467 -0
  9. package/dist/chunk-6LPITDKG.mjs +1539 -0
  10. package/dist/chunk-AECWO7NQ.mjs +1539 -0
  11. package/dist/chunk-AJC3FR6G.mjs +1509 -0
  12. package/dist/chunk-CVGIDSMN.mjs +1522 -0
  13. package/dist/chunk-DXG5NIYL.mjs +1527 -0
  14. package/dist/chunk-G3CCJCBI.mjs +1521 -0
  15. package/dist/chunk-GFADGYXZ.mjs +1752 -0
  16. package/dist/chunk-GTRIBVS6.mjs +1467 -0
  17. package/dist/chunk-H4HWBQU6.mjs +1530 -0
  18. package/dist/chunk-JH535NPP.mjs +1619 -0
  19. package/dist/chunk-KGFWKSGJ.mjs +1442 -0
  20. package/dist/chunk-N2GQWNFG.mjs +1527 -0
  21. package/dist/chunk-NQA3F2HJ.mjs +1532 -0
  22. package/dist/chunk-NXXQ2U73.mjs +1467 -0
  23. package/dist/chunk-QDGPR3L6.mjs +1518 -0
  24. package/dist/chunk-SAVOSPM3.mjs +1522 -0
  25. package/dist/chunk-SIX4KMF2.mjs +1468 -0
  26. package/dist/chunk-SPAM2YJE.mjs +1537 -0
  27. package/dist/chunk-UG7OPVHB.mjs +1521 -0
  28. package/dist/chunk-VIJTZPBI.mjs +1470 -0
  29. package/dist/chunk-W37E7MW5.mjs +1403 -0
  30. package/dist/chunk-W76FEISE.mjs +1538 -0
  31. package/dist/chunk-WCFQYXQA.mjs +1532 -0
  32. package/dist/chunk-XY77XABG.mjs +1545 -0
  33. package/dist/chunk-YCGDIGOG.mjs +1467 -0
  34. package/dist/cli.js +768 -1160
  35. package/dist/cli.mjs +1 -1
  36. package/dist/index.d.mts +196 -64
  37. package/dist/index.d.ts +196 -64
  38. package/dist/index.js +937 -1209
  39. package/dist/index.mjs +65 -3
  40. package/package.json +2 -2
  41. package/src/__tests__/contract.test.ts +38 -0
  42. package/src/analyzer.ts +143 -2177
  43. package/src/ast-utils.ts +94 -0
  44. package/src/classifier.ts +497 -0
  45. package/src/cluster-detector.ts +100 -0
  46. package/src/defaults.ts +59 -0
  47. package/src/graph-builder.ts +272 -0
  48. package/src/index.ts +30 -519
  49. package/src/metrics.ts +231 -0
  50. package/src/remediation.ts +139 -0
  51. package/src/scoring.ts +12 -34
  52. package/src/semantic-analysis.ts +192 -126
  53. package/src/summary.ts +168 -0
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  analyzeContext,
4
4
  generateSummary
5
- } from "./chunk-EBXG2Q5Y.mjs";
5
+ } from "./chunk-GFADGYXZ.mjs";
6
6
 
7
7
  // src/cli.ts
8
8
  import { Command } from "commander";
package/dist/index.d.mts CHANGED
@@ -122,104 +122,236 @@ interface TypeDependency {
122
122
  usedBy: string[];
123
123
  }
124
124
 
125
+ interface FileContent {
126
+ file: string;
127
+ content: string;
128
+ }
129
+ /**
130
+ * Auto-detect domain keywords from workspace folder structure
131
+ */
132
+ declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
133
+ /**
134
+ * Build a dependency graph from file contents
135
+ */
136
+ declare function buildDependencyGraph(files: FileContent[], options?: {
137
+ domainKeywords?: string[];
138
+ }): DependencyGraph;
139
+ /**
140
+ * Extract imports from file content using regex
141
+ */
142
+ declare function extractImportsFromContent(content: string): string[];
143
+ /**
144
+ * Calculate the maximum depth of import tree for a file
145
+ */
146
+ declare function calculateImportDepth(file: string, graph: DependencyGraph, visited?: Set<string>, depth?: number): number;
147
+ /**
148
+ * Get all transitive dependencies for a file
149
+ */
150
+ declare function getTransitiveDependencies(file: string, graph: DependencyGraph, visited?: Set<string>): string[];
151
+ /**
152
+ * Calculate total context budget (tokens needed to understand this file)
153
+ */
154
+ declare function calculateContextBudget(file: string, graph: DependencyGraph): number;
155
+ /**
156
+ * Detect circular dependencies
157
+ */
158
+ declare function detectCircularDependencies(graph: DependencyGraph): string[][];
159
+
160
+ /**
161
+ * Calculate cohesion score (how related are exports in a file)
162
+ */
163
+ declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
164
+ coUsageMatrix?: Map<string, Map<string, number>>;
165
+ weights?: {
166
+ importBased?: number;
167
+ structural?: number;
168
+ domainBased?: number;
169
+ };
170
+ }): number;
171
+ /**
172
+ * Calculate structural cohesion for a file based on co-usage patterns.
173
+ */
174
+ declare function calculateStructuralCohesionFromCoUsage(file: string, coUsageMatrix?: Map<string, Map<string, number>>): number;
175
+ /**
176
+ * Calculate fragmentation score (how scattered is a domain)
177
+ */
178
+ declare function calculateFragmentation(files: string[], domain: string, options?: {
179
+ useLogScale?: boolean;
180
+ logBase?: number;
181
+ sharedImportRatio?: number;
182
+ dependencyCount?: number;
183
+ }): number;
184
+ /**
185
+ * Calculate path entropy for a set of files
186
+ */
187
+ declare function calculatePathEntropy(files: string[]): number;
188
+ /**
189
+ * Calculate directory-distance metric based on common ancestor depth
190
+ */
191
+ declare function calculateDirectoryDistance(files: string[]): number;
192
+
193
+ /**
194
+ * Classify a file into a specific type for better analysis context
195
+ */
196
+ declare function classifyFile(node: DependencyNode, cohesionScore?: number, domains?: string[]): FileClassification;
197
+ /**
198
+ * Detect if a file is a barrel export (index.ts)
199
+ */
200
+ declare function isBarrelExport(node: DependencyNode): boolean;
201
+ /**
202
+ * Detect if a file is primarily type definitions
203
+ */
204
+ declare function isTypeDefinition(node: DependencyNode): boolean;
205
+ /**
206
+ * Detect if a file is a utility module
207
+ */
208
+ declare function isUtilityModule(node: DependencyNode): boolean;
209
+ /**
210
+ * Detect if a file is a Lambda/API handler
211
+ */
212
+ declare function isLambdaHandler(node: DependencyNode): boolean;
213
+ /**
214
+ * Detect if a file is a service file
215
+ */
216
+ declare function isServiceFile(node: DependencyNode): boolean;
125
217
  /**
126
- * Classify a file based on its characteristics to help distinguish
127
- * real issues from false positives.
128
- *
129
- * Classification types:
130
- * - barrel-export: Re-exports from other modules (index.ts files)
131
- * - type-definition: Primarily type/interface definitions
132
- * - cohesive-module: Single domain, high cohesion (acceptable large files)
133
- * - utility-module: Utility/helper files with cohesive purpose despite multi-domain
134
- * - service-file: Service files orchestrating multiple dependencies
135
- * - lambda-handler: Lambda/API handlers with single business purpose
136
- * - email-template: Email templates/layouts with structural cohesion
137
- * - parser-file: Parser/transformer files with single transformation purpose
138
- * - mixed-concerns: Multiple domains, potential refactoring candidate
139
- * - unknown: Unable to classify
140
- */
141
- declare function classifyFile(node: DependencyNode, cohesionScore: number, domains: string[]): FileClassification;
218
+ * Detect if a file is an email template/layout
219
+ */
220
+ declare function isEmailTemplate(node: DependencyNode): boolean;
221
+ /**
222
+ * Detect if a file is a parser/transformer
223
+ */
224
+ declare function isParserFile(node: DependencyNode): boolean;
225
+ /**
226
+ * Detect if a file is a session/state management file
227
+ */
228
+ declare function isSessionFile(node: DependencyNode): boolean;
229
+ /**
230
+ * Detect if a file is a configuration or schema file
231
+ */
232
+ declare function isConfigFile(node: DependencyNode): boolean;
233
+ /**
234
+ * Detect if a file is a Next.js App Router page
235
+ */
236
+ declare function isNextJsPage(node: DependencyNode): boolean;
237
+ /**
238
+ * Adjust cohesion score based on file classification
239
+ */
240
+ declare function adjustCohesionForClassification(baseCohesion: number, classification: FileClassification, node?: DependencyNode): number;
142
241
  /**
143
242
  * Adjust fragmentation score based on file classification
144
- *
145
- * This reduces false positives by:
146
- * - Ignoring fragmentation for barrel exports (they're meant to aggregate)
147
- * - Ignoring fragmentation for type definitions (centralized types are good)
148
- * - Reducing fragmentation for cohesive modules (large but focused is OK)
149
- * - Reducing fragmentation for utility/service/handler/template files
150
243
  */
151
244
  declare function adjustFragmentationForClassification(baseFragmentation: number, classification: FileClassification): number;
152
245
 
246
+ /**
247
+ * Group files by domain to detect module clusters
248
+ */
249
+ declare function detectModuleClusters(graph: DependencyGraph, options?: {
250
+ useLogScale?: boolean;
251
+ }): ModuleCluster[];
252
+
253
+ /**
254
+ * Get classification-specific recommendations
255
+ */
256
+ declare function getClassificationRecommendations(classification: FileClassification, file: string, issues: string[]): string[];
257
+ /**
258
+ * Generate general context recommendations
259
+ */
260
+ declare function getGeneralRecommendations(metrics: {
261
+ contextBudget: number;
262
+ importDepth: number;
263
+ circularDeps: string[][];
264
+ cohesionScore: number;
265
+ fragmentationScore: number;
266
+ }, thresholds: {
267
+ maxContextBudget: number;
268
+ maxDepth: number;
269
+ minCohesion: number;
270
+ maxFragmentation: number;
271
+ }): {
272
+ recommendations: string[];
273
+ issues: string[];
274
+ severity: any;
275
+ };
276
+
277
+ /**
278
+ * Calculate cohesion score (how related are exports in a file)
279
+ * Legacy wrapper for backward compatibility with exact test expectations
280
+ */
281
+ declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
282
+ /**
283
+ * Analyze issues for a single file
284
+ */
285
+ declare function analyzeIssues(params: {
286
+ file: string;
287
+ importDepth: number;
288
+ contextBudget: number;
289
+ cohesionScore: number;
290
+ fragmentationScore: number;
291
+ maxDepth: number;
292
+ maxContextBudget: number;
293
+ minCohesion: number;
294
+ maxFragmentation: number;
295
+ circularDeps: string[][];
296
+ }): {
297
+ severity: ContextAnalysisResult['severity'];
298
+ issues: string[];
299
+ recommendations: string[];
300
+ potentialSavings: number;
301
+ };
302
+
153
303
  /**
154
304
  * Calculate AI Readiness Score for context efficiency (0-100)
155
- *
156
- * Based on:
157
- * - Average context budget (tokens needed to understand files)
158
- * - Import depth (dependency chain length)
159
- * - Fragmentation score (code organization)
160
- * - Critical/major issues
161
- *
162
- * Includes business value metrics:
163
- * - Estimated monthly cost of context waste
164
- * - Estimated developer hours to fix
165
305
  */
166
306
  declare function calculateContextScore(summary: ContextSummary, costConfig?: Partial<CostConfig>): ToolScoringOutput;
307
+ declare function mapScoreToRating(score: number): string;
308
+
309
+ /**
310
+ * Generate smart defaults for context analysis based on repository size
311
+ * Automatically tunes thresholds to target ~10 most serious issues
312
+ */
313
+ declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
314
+
315
+ /**
316
+ * Generate summary of context analysis results
317
+ */
318
+ declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
167
319
 
168
320
  /**
169
321
  * Build co-usage matrix: track which files are imported together
170
- *
171
- * Files frequently imported together likely belong to the same semantic domain
172
322
  */
173
323
  declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
174
324
  /**
175
325
  * Extract type dependencies from AST exports
176
- *
177
- * Files that share types are semantically related
178
326
  */
179
327
  declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
180
328
  /**
181
329
  * Find semantic clusters using co-usage patterns
182
- *
183
- * Files with high co-usage counts belong in the same cluster
184
330
  */
185
331
  declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
186
- /**
187
- * Calculate confidence score for domain assignment based on multiple signals
188
- */
189
- declare function calculateDomainConfidence(signals: DomainSignals): number;
190
332
  /**
191
333
  * Infer domain from semantic analysis (co-usage + types)
192
- *
193
- * This replaces the folder-based heuristic with actual code relationships
194
334
  */
195
335
  declare function inferDomainFromSemantics(file: string, exportName: string, graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, exportTypeRefs?: string[]): DomainAssignment[];
336
+ declare function calculateDomainConfidence(signals: DomainSignals): number;
196
337
  /**
197
- * Get co-usage data for a specific file
338
+ * Regex-based export extraction (legacy/fallback)
198
339
  */
199
- declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
340
+ declare function extractExports(content: string, filePath?: string, domainOptions?: {
341
+ domainKeywords?: string[];
342
+ }, fileImports?: string[]): ExportInfo[];
200
343
  /**
201
- * Find files that should be consolidated based on semantic similarity
202
- *
203
- * High co-usage + shared types = strong consolidation candidate
344
+ * Infer domain from name, path, or imports
204
345
  */
205
- declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): Array<{
206
- files: string[];
207
- reason: string;
208
- strength: number;
209
- }>;
346
+ declare function inferDomain(name: string, filePath?: string, domainOptions?: {
347
+ domainKeywords?: string[];
348
+ }, fileImports?: string[]): string;
349
+ declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
350
+ declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
210
351
 
211
- /**
212
- * Generate smart defaults for context analysis based on repository size
213
- * Automatically tunes thresholds to target ~10 most serious issues
214
- */
215
- declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
216
352
  /**
217
353
  * Analyze AI context window cost for a codebase
218
354
  */
219
355
  declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
220
- /**
221
- * Generate summary of context analysis results
222
- */
223
- declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
224
356
 
225
- export { type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, type ContextSummary, type DomainAssignment, type DomainSignals, type FileClassification, type ModuleCluster, type TypeDependency, adjustFragmentationForClassification, analyzeContext, buildCoUsageMatrix, buildTypeGraph, calculateContextScore, calculateDomainConfidence, classifyFile, findConsolidationCandidates, findSemanticClusters, generateSummary, getCoUsageData, getSmartDefaults, inferDomainFromSemantics };
357
+ export { type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, type ExportInfo, type FileClassification, type ModuleCluster, type TypeDependency, adjustCohesionForClassification, adjustFragmentationForClassification, analyzeContext, analyzeIssues, buildCoUsageMatrix, buildDependencyGraph, buildTypeGraph, calculateCohesion, calculateContextBudget, calculateContextScore, calculateDirectoryDistance, calculateDomainConfidence, calculateEnhancedCohesion, calculateFragmentation, calculateImportDepth, calculatePathEntropy, calculateStructuralCohesionFromCoUsage, classifyFile, detectCircularDependencies, detectModuleClusters, extractDomainKeywordsFromPaths, extractExports, extractImportsFromContent, findConsolidationCandidates, findSemanticClusters, generateSummary, getClassificationRecommendations, getCoUsageData, getGeneralRecommendations, getSmartDefaults, getTransitiveDependencies, inferDomain, inferDomainFromSemantics, isBarrelExport, isConfigFile, isEmailTemplate, isLambdaHandler, isNextJsPage, isParserFile, isServiceFile, isSessionFile, isTypeDefinition, isUtilityModule, mapScoreToRating };
package/dist/index.d.ts CHANGED
@@ -122,104 +122,236 @@ interface TypeDependency {
122
122
  usedBy: string[];
123
123
  }
124
124
 
125
+ interface FileContent {
126
+ file: string;
127
+ content: string;
128
+ }
129
+ /**
130
+ * Auto-detect domain keywords from workspace folder structure
131
+ */
132
+ declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
133
+ /**
134
+ * Build a dependency graph from file contents
135
+ */
136
+ declare function buildDependencyGraph(files: FileContent[], options?: {
137
+ domainKeywords?: string[];
138
+ }): DependencyGraph;
139
+ /**
140
+ * Extract imports from file content using regex
141
+ */
142
+ declare function extractImportsFromContent(content: string): string[];
143
+ /**
144
+ * Calculate the maximum depth of import tree for a file
145
+ */
146
+ declare function calculateImportDepth(file: string, graph: DependencyGraph, visited?: Set<string>, depth?: number): number;
147
+ /**
148
+ * Get all transitive dependencies for a file
149
+ */
150
+ declare function getTransitiveDependencies(file: string, graph: DependencyGraph, visited?: Set<string>): string[];
151
+ /**
152
+ * Calculate total context budget (tokens needed to understand this file)
153
+ */
154
+ declare function calculateContextBudget(file: string, graph: DependencyGraph): number;
155
+ /**
156
+ * Detect circular dependencies
157
+ */
158
+ declare function detectCircularDependencies(graph: DependencyGraph): string[][];
159
+
160
+ /**
161
+ * Calculate cohesion score (how related are exports in a file)
162
+ */
163
+ declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
164
+ coUsageMatrix?: Map<string, Map<string, number>>;
165
+ weights?: {
166
+ importBased?: number;
167
+ structural?: number;
168
+ domainBased?: number;
169
+ };
170
+ }): number;
171
+ /**
172
+ * Calculate structural cohesion for a file based on co-usage patterns.
173
+ */
174
+ declare function calculateStructuralCohesionFromCoUsage(file: string, coUsageMatrix?: Map<string, Map<string, number>>): number;
175
+ /**
176
+ * Calculate fragmentation score (how scattered is a domain)
177
+ */
178
+ declare function calculateFragmentation(files: string[], domain: string, options?: {
179
+ useLogScale?: boolean;
180
+ logBase?: number;
181
+ sharedImportRatio?: number;
182
+ dependencyCount?: number;
183
+ }): number;
184
+ /**
185
+ * Calculate path entropy for a set of files
186
+ */
187
+ declare function calculatePathEntropy(files: string[]): number;
188
+ /**
189
+ * Calculate directory-distance metric based on common ancestor depth
190
+ */
191
+ declare function calculateDirectoryDistance(files: string[]): number;
192
+
193
+ /**
194
+ * Classify a file into a specific type for better analysis context
195
+ */
196
+ declare function classifyFile(node: DependencyNode, cohesionScore?: number, domains?: string[]): FileClassification;
197
+ /**
198
+ * Detect if a file is a barrel export (index.ts)
199
+ */
200
+ declare function isBarrelExport(node: DependencyNode): boolean;
201
+ /**
202
+ * Detect if a file is primarily type definitions
203
+ */
204
+ declare function isTypeDefinition(node: DependencyNode): boolean;
205
+ /**
206
+ * Detect if a file is a utility module
207
+ */
208
+ declare function isUtilityModule(node: DependencyNode): boolean;
209
+ /**
210
+ * Detect if a file is a Lambda/API handler
211
+ */
212
+ declare function isLambdaHandler(node: DependencyNode): boolean;
213
+ /**
214
+ * Detect if a file is a service file
215
+ */
216
+ declare function isServiceFile(node: DependencyNode): boolean;
125
217
  /**
126
- * Classify a file based on its characteristics to help distinguish
127
- * real issues from false positives.
128
- *
129
- * Classification types:
130
- * - barrel-export: Re-exports from other modules (index.ts files)
131
- * - type-definition: Primarily type/interface definitions
132
- * - cohesive-module: Single domain, high cohesion (acceptable large files)
133
- * - utility-module: Utility/helper files with cohesive purpose despite multi-domain
134
- * - service-file: Service files orchestrating multiple dependencies
135
- * - lambda-handler: Lambda/API handlers with single business purpose
136
- * - email-template: Email templates/layouts with structural cohesion
137
- * - parser-file: Parser/transformer files with single transformation purpose
138
- * - mixed-concerns: Multiple domains, potential refactoring candidate
139
- * - unknown: Unable to classify
140
- */
141
- declare function classifyFile(node: DependencyNode, cohesionScore: number, domains: string[]): FileClassification;
218
+ * Detect if a file is an email template/layout
219
+ */
220
+ declare function isEmailTemplate(node: DependencyNode): boolean;
221
+ /**
222
+ * Detect if a file is a parser/transformer
223
+ */
224
+ declare function isParserFile(node: DependencyNode): boolean;
225
+ /**
226
+ * Detect if a file is a session/state management file
227
+ */
228
+ declare function isSessionFile(node: DependencyNode): boolean;
229
+ /**
230
+ * Detect if a file is a configuration or schema file
231
+ */
232
+ declare function isConfigFile(node: DependencyNode): boolean;
233
+ /**
234
+ * Detect if a file is a Next.js App Router page
235
+ */
236
+ declare function isNextJsPage(node: DependencyNode): boolean;
237
+ /**
238
+ * Adjust cohesion score based on file classification
239
+ */
240
+ declare function adjustCohesionForClassification(baseCohesion: number, classification: FileClassification, node?: DependencyNode): number;
142
241
  /**
143
242
  * Adjust fragmentation score based on file classification
144
- *
145
- * This reduces false positives by:
146
- * - Ignoring fragmentation for barrel exports (they're meant to aggregate)
147
- * - Ignoring fragmentation for type definitions (centralized types are good)
148
- * - Reducing fragmentation for cohesive modules (large but focused is OK)
149
- * - Reducing fragmentation for utility/service/handler/template files
150
243
  */
151
244
  declare function adjustFragmentationForClassification(baseFragmentation: number, classification: FileClassification): number;
152
245
 
246
+ /**
247
+ * Group files by domain to detect module clusters
248
+ */
249
+ declare function detectModuleClusters(graph: DependencyGraph, options?: {
250
+ useLogScale?: boolean;
251
+ }): ModuleCluster[];
252
+
253
+ /**
254
+ * Get classification-specific recommendations
255
+ */
256
+ declare function getClassificationRecommendations(classification: FileClassification, file: string, issues: string[]): string[];
257
+ /**
258
+ * Generate general context recommendations
259
+ */
260
+ declare function getGeneralRecommendations(metrics: {
261
+ contextBudget: number;
262
+ importDepth: number;
263
+ circularDeps: string[][];
264
+ cohesionScore: number;
265
+ fragmentationScore: number;
266
+ }, thresholds: {
267
+ maxContextBudget: number;
268
+ maxDepth: number;
269
+ minCohesion: number;
270
+ maxFragmentation: number;
271
+ }): {
272
+ recommendations: string[];
273
+ issues: string[];
274
+ severity: any;
275
+ };
276
+
277
+ /**
278
+ * Calculate cohesion score (how related are exports in a file)
279
+ * Legacy wrapper for backward compatibility with exact test expectations
280
+ */
281
+ declare function calculateCohesion(exports: ExportInfo[], filePath?: string, options?: any): number;
282
+ /**
283
+ * Analyze issues for a single file
284
+ */
285
+ declare function analyzeIssues(params: {
286
+ file: string;
287
+ importDepth: number;
288
+ contextBudget: number;
289
+ cohesionScore: number;
290
+ fragmentationScore: number;
291
+ maxDepth: number;
292
+ maxContextBudget: number;
293
+ minCohesion: number;
294
+ maxFragmentation: number;
295
+ circularDeps: string[][];
296
+ }): {
297
+ severity: ContextAnalysisResult['severity'];
298
+ issues: string[];
299
+ recommendations: string[];
300
+ potentialSavings: number;
301
+ };
302
+
153
303
  /**
154
304
  * Calculate AI Readiness Score for context efficiency (0-100)
155
- *
156
- * Based on:
157
- * - Average context budget (tokens needed to understand files)
158
- * - Import depth (dependency chain length)
159
- * - Fragmentation score (code organization)
160
- * - Critical/major issues
161
- *
162
- * Includes business value metrics:
163
- * - Estimated monthly cost of context waste
164
- * - Estimated developer hours to fix
165
305
  */
166
306
  declare function calculateContextScore(summary: ContextSummary, costConfig?: Partial<CostConfig>): ToolScoringOutput;
307
+ declare function mapScoreToRating(score: number): string;
308
+
309
+ /**
310
+ * Generate smart defaults for context analysis based on repository size
311
+ * Automatically tunes thresholds to target ~10 most serious issues
312
+ */
313
+ declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
314
+
315
+ /**
316
+ * Generate summary of context analysis results
317
+ */
318
+ declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
167
319
 
168
320
  /**
169
321
  * Build co-usage matrix: track which files are imported together
170
- *
171
- * Files frequently imported together likely belong to the same semantic domain
172
322
  */
173
323
  declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
174
324
  /**
175
325
  * Extract type dependencies from AST exports
176
- *
177
- * Files that share types are semantically related
178
326
  */
179
327
  declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
180
328
  /**
181
329
  * Find semantic clusters using co-usage patterns
182
- *
183
- * Files with high co-usage counts belong in the same cluster
184
330
  */
185
331
  declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
186
- /**
187
- * Calculate confidence score for domain assignment based on multiple signals
188
- */
189
- declare function calculateDomainConfidence(signals: DomainSignals): number;
190
332
  /**
191
333
  * Infer domain from semantic analysis (co-usage + types)
192
- *
193
- * This replaces the folder-based heuristic with actual code relationships
194
334
  */
195
335
  declare function inferDomainFromSemantics(file: string, exportName: string, graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, exportTypeRefs?: string[]): DomainAssignment[];
336
+ declare function calculateDomainConfidence(signals: DomainSignals): number;
196
337
  /**
197
- * Get co-usage data for a specific file
338
+ * Regex-based export extraction (legacy/fallback)
198
339
  */
199
- declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
340
+ declare function extractExports(content: string, filePath?: string, domainOptions?: {
341
+ domainKeywords?: string[];
342
+ }, fileImports?: string[]): ExportInfo[];
200
343
  /**
201
- * Find files that should be consolidated based on semantic similarity
202
- *
203
- * High co-usage + shared types = strong consolidation candidate
344
+ * Infer domain from name, path, or imports
204
345
  */
205
- declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): Array<{
206
- files: string[];
207
- reason: string;
208
- strength: number;
209
- }>;
346
+ declare function inferDomain(name: string, filePath?: string, domainOptions?: {
347
+ domainKeywords?: string[];
348
+ }, fileImports?: string[]): string;
349
+ declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
350
+ declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
210
351
 
211
- /**
212
- * Generate smart defaults for context analysis based on repository size
213
- * Automatically tunes thresholds to target ~10 most serious issues
214
- */
215
- declare function getSmartDefaults(directory: string, userOptions: Partial<ContextAnalyzerOptions>): Promise<ContextAnalyzerOptions>;
216
352
  /**
217
353
  * Analyze AI context window cost for a codebase
218
354
  */
219
355
  declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
220
- /**
221
- * Generate summary of context analysis results
222
- */
223
- declare function generateSummary(results: ContextAnalysisResult[]): ContextSummary;
224
356
 
225
- export { type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, type ContextSummary, type DomainAssignment, type DomainSignals, type FileClassification, type ModuleCluster, type TypeDependency, adjustFragmentationForClassification, analyzeContext, buildCoUsageMatrix, buildTypeGraph, calculateContextScore, calculateDomainConfidence, classifyFile, findConsolidationCandidates, findSemanticClusters, generateSummary, getCoUsageData, getSmartDefaults, inferDomainFromSemantics };
357
+ export { type CoUsageData, type ContextAnalysisResult, type ContextAnalyzerOptions, type ContextSummary, type DependencyGraph, type DependencyNode, type DomainAssignment, type DomainSignals, type ExportInfo, type FileClassification, type ModuleCluster, type TypeDependency, adjustCohesionForClassification, adjustFragmentationForClassification, analyzeContext, analyzeIssues, buildCoUsageMatrix, buildDependencyGraph, buildTypeGraph, calculateCohesion, calculateContextBudget, calculateContextScore, calculateDirectoryDistance, calculateDomainConfidence, calculateEnhancedCohesion, calculateFragmentation, calculateImportDepth, calculatePathEntropy, calculateStructuralCohesionFromCoUsage, classifyFile, detectCircularDependencies, detectModuleClusters, extractDomainKeywordsFromPaths, extractExports, extractImportsFromContent, findConsolidationCandidates, findSemanticClusters, generateSummary, getClassificationRecommendations, getCoUsageData, getGeneralRecommendations, getSmartDefaults, getTransitiveDependencies, inferDomain, inferDomainFromSemantics, isBarrelExport, isConfigFile, isEmailTemplate, isLambdaHandler, isNextJsPage, isParserFile, isServiceFile, isSessionFile, isTypeDefinition, isUtilityModule, mapScoreToRating };