@aiready/context-analyzer 0.21.9 → 0.21.11
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 +25 -26
- package/.turbo/turbo-test.log +39 -41
- package/dist/chunk-BW463GQB.mjs +1767 -0
- package/dist/chunk-CAX2MOUZ.mjs +1801 -0
- package/dist/chunk-J5TA3AZU.mjs +1795 -0
- package/dist/chunk-UXC6QUZ7.mjs +1801 -0
- package/dist/chunk-WTQJNY4U.mjs +1785 -0
- package/dist/chunk-XBFM2Z4O.mjs +1792 -0
- package/dist/cli.js +319 -243
- package/dist/cli.mjs +38 -24
- package/dist/index.d.mts +141 -32
- package/dist/index.d.ts +141 -32
- package/dist/index.js +340 -239
- package/dist/index.mjs +55 -16
- package/package.json +2 -2
- package/src/__tests__/cluster-detector.test.ts +5 -8
- package/src/__tests__/fragmentation-coupling.test.ts +6 -3
- package/src/analyzer.ts +1 -224
- package/src/ast-utils.ts +12 -2
- package/src/classifier.ts +11 -0
- package/src/cli-definition.ts +61 -0
- package/src/cli.ts +2 -44
- package/src/cluster-detector.ts +22 -5
- package/src/graph-builder.ts +31 -6
- package/src/heuristics.ts +188 -89
- package/src/mapper.ts +118 -0
- package/src/metrics.ts +34 -20
- package/src/orchestrator.ts +136 -0
- package/src/remediation.ts +15 -1
- package/src/scoring.ts +93 -19
- package/src/semantic-analysis.ts +58 -12
- package/src/summary.ts +4 -0
- package/src/types.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ interface ContextAnalysisResult {
|
|
|
69
69
|
* Classification of file type for analysis context
|
|
70
70
|
* Helps distinguish real issues from false positives
|
|
71
71
|
*/
|
|
72
|
-
type FileClassification = 'barrel-export' | 'type-definition' | 'cohesive-module' | 'utility-module' | 'service-file' | 'lambda-handler' | 'email-template' | 'parser-file' | 'nextjs-page' | 'mixed-concerns' | 'unknown';
|
|
72
|
+
type FileClassification = 'barrel-export' | 'type-definition' | 'cohesive-module' | 'utility-module' | 'service-file' | 'lambda-handler' | 'email-template' | 'parser-file' | 'nextjs-page' | 'spoke-module' | 'mixed-concerns' | 'unknown';
|
|
73
73
|
interface ModuleCluster {
|
|
74
74
|
domain: string;
|
|
75
75
|
files: string[];
|
|
@@ -169,10 +169,7 @@ interface TypeDependency {
|
|
|
169
169
|
* @param options - Additional options for cohesion calculation
|
|
170
170
|
* @returns Cohesion score between 0 and 1
|
|
171
171
|
*/
|
|
172
|
-
declare function calculateCohesion(exports:
|
|
173
|
-
/**
|
|
174
|
-
* Analyze AI context window cost for a codebase
|
|
175
|
-
*/
|
|
172
|
+
declare function calculateCohesion(exports: any[], filePath?: string, options?: any): number;
|
|
176
173
|
/**
|
|
177
174
|
* Performs deep context analysis of a project.
|
|
178
175
|
* Scans files, builds a dependency graph, calculates context budgets,
|
|
@@ -184,43 +181,66 @@ declare function calculateCohesion(exports: ExportInfo[], filePath?: string, opt
|
|
|
184
181
|
declare function analyzeContext(options: ContextAnalyzerOptions): Promise<ContextAnalysisResult[]>;
|
|
185
182
|
|
|
186
183
|
/**
|
|
187
|
-
* Auto-detect domain keywords from workspace folder structure
|
|
184
|
+
* Auto-detect domain keywords from workspace folder structure.
|
|
185
|
+
*
|
|
186
|
+
* @param files - Array of file contents to analyze for folder patterns.
|
|
187
|
+
* @returns Array of singularized domain keywords.
|
|
188
188
|
*/
|
|
189
189
|
declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
|
|
190
190
|
/**
|
|
191
|
-
* Build a dependency graph from file contents
|
|
191
|
+
* Build a dependency graph from file contents, resolving imports and extracting metadata.
|
|
192
|
+
*
|
|
193
|
+
* @param files - Array of file contents to process.
|
|
194
|
+
* @param options - Optional configuration for domain detection.
|
|
195
|
+
* @returns Complete dependency graph with nodes, edges, and semantic matrices.
|
|
192
196
|
*/
|
|
193
197
|
declare function buildDependencyGraph(files: FileContent[], options?: {
|
|
194
198
|
domainKeywords?: string[];
|
|
195
199
|
}): DependencyGraph;
|
|
196
200
|
/**
|
|
197
|
-
* Calculate the maximum depth of import tree for a file
|
|
201
|
+
* Calculate the maximum depth of the import tree for a specific file.
|
|
202
|
+
*
|
|
203
|
+
* @param file - File path to start depth calculation from.
|
|
204
|
+
* @param graph - The dependency graph.
|
|
205
|
+
* @param visited - Optional set to track visited nodes during traversal.
|
|
206
|
+
* @param depth - Current recursion depth.
|
|
207
|
+
* @returns Maximum depth of the import chain.
|
|
198
208
|
*/
|
|
199
209
|
declare function calculateImportDepth(file: string, graph: DependencyGraph, visited?: Set<string>, depth?: number): number;
|
|
200
210
|
/**
|
|
201
|
-
*
|
|
211
|
+
* Retrieve all transitive dependencies for a specific file.
|
|
212
|
+
*
|
|
213
|
+
* @param file - File path to analyze.
|
|
214
|
+
* @param graph - The dependency graph.
|
|
215
|
+
* @param visited - Optional set to track visited nodes.
|
|
216
|
+
* @returns Array of all reachable file paths.
|
|
202
217
|
*/
|
|
203
218
|
declare function getTransitiveDependencies(file: string, graph: DependencyGraph, visited?: Set<string>): string[];
|
|
204
219
|
/**
|
|
205
|
-
* Calculate total context budget (tokens needed to understand this file)
|
|
220
|
+
* Calculate total context budget (tokens needed to understand this file and its dependencies).
|
|
221
|
+
*
|
|
222
|
+
* @param file - File path to calculate budget for.
|
|
223
|
+
* @param graph - The dependency graph.
|
|
224
|
+
* @returns Total token count including recursive dependencies.
|
|
206
225
|
*/
|
|
207
226
|
declare function calculateContextBudget(file: string, graph: DependencyGraph): number;
|
|
208
227
|
/**
|
|
209
|
-
* Detect circular dependencies
|
|
228
|
+
* Detect circular dependencies (cycles) within the dependency graph.
|
|
229
|
+
*
|
|
230
|
+
* @param graph - The dependency graph to scan.
|
|
231
|
+
* @returns Array of dependency cycles (each cycle is an array of file paths).
|
|
210
232
|
*/
|
|
211
233
|
declare function detectCircularDependencies(graph: DependencyGraph): string[][];
|
|
212
234
|
|
|
213
|
-
/**
|
|
214
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
215
|
-
*/
|
|
216
235
|
/**
|
|
217
236
|
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
218
237
|
* shared imports, and internal structure. High cohesion indicates
|
|
219
238
|
* a well-focused module that is easy for AI models to reason about.
|
|
220
239
|
*
|
|
221
|
-
* @param exports - Exported symbols and their metadata
|
|
222
|
-
* @param
|
|
223
|
-
* @
|
|
240
|
+
* @param exports - Exported symbols and their metadata.
|
|
241
|
+
* @param filePath - Optional file path for context.
|
|
242
|
+
* @param options - Optional configuration for weights and co-usage context.
|
|
243
|
+
* @returns Cohesion score between 0 and 1.
|
|
224
244
|
*/
|
|
225
245
|
declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
|
|
226
246
|
coUsageMatrix?: Map<string, Map<string, number>>;
|
|
@@ -232,10 +252,19 @@ declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: str
|
|
|
232
252
|
}): number;
|
|
233
253
|
/**
|
|
234
254
|
* Calculate structural cohesion for a file based on co-usage patterns.
|
|
255
|
+
*
|
|
256
|
+
* @param file - The file path to analyze.
|
|
257
|
+
* @param coUsageMatrix - Matrix of files frequently imported together.
|
|
258
|
+
* @returns Cohesion score between 0 and 1 based on co-usage distribution.
|
|
235
259
|
*/
|
|
236
260
|
declare function calculateStructuralCohesionFromCoUsage(file: string, coUsageMatrix?: Map<string, Map<string, number>>): number;
|
|
237
261
|
/**
|
|
238
262
|
* Calculate fragmentation score (how scattered is a domain)
|
|
263
|
+
*
|
|
264
|
+
* @param files - List of files belonging to the domain.
|
|
265
|
+
* @param domain - The domain identifier.
|
|
266
|
+
* @param options - Optional calculation parameters (log scale, thresholds).
|
|
267
|
+
* @returns Fragmentation score from 0 (perfect) to 1 (highly scattered).
|
|
239
268
|
*/
|
|
240
269
|
declare function calculateFragmentation(files: string[], domain: string, options?: {
|
|
241
270
|
useLogScale?: boolean;
|
|
@@ -244,11 +273,17 @@ declare function calculateFragmentation(files: string[], domain: string, options
|
|
|
244
273
|
dependencyCount?: number;
|
|
245
274
|
}): number;
|
|
246
275
|
/**
|
|
247
|
-
* Calculate path entropy for a set of files
|
|
276
|
+
* Calculate path entropy for a set of files to measure directory distribution.
|
|
277
|
+
*
|
|
278
|
+
* @param files - Array of file paths.
|
|
279
|
+
* @returns Entropy score representing the spread across directories.
|
|
248
280
|
*/
|
|
249
281
|
declare function calculatePathEntropy(files: string[]): number;
|
|
250
282
|
/**
|
|
251
|
-
* Calculate directory-distance metric based on common ancestor depth
|
|
283
|
+
* Calculate directory-distance metric based on common ancestor depth.
|
|
284
|
+
*
|
|
285
|
+
* @param files - Array of file paths to compare.
|
|
286
|
+
* @returns Normalized distance metric (0-1).
|
|
252
287
|
*/
|
|
253
288
|
declare function calculateDirectoryDistance(files: string[]): number;
|
|
254
289
|
|
|
@@ -265,6 +300,7 @@ declare const Classification: {
|
|
|
265
300
|
PARSER: "parser-file";
|
|
266
301
|
COHESIVE_MODULE: "cohesive-module";
|
|
267
302
|
UTILITY_MODULE: "utility-module";
|
|
303
|
+
SPOKE_MODULE: "spoke-module";
|
|
268
304
|
MIXED_CONCERNS: "mixed-concerns";
|
|
269
305
|
UNKNOWN: "unknown";
|
|
270
306
|
};
|
|
@@ -308,10 +344,19 @@ declare function detectModuleClusters(graph: DependencyGraph, options?: {
|
|
|
308
344
|
|
|
309
345
|
/**
|
|
310
346
|
* Get classification-specific recommendations
|
|
347
|
+
*
|
|
348
|
+
* @param classification - The identified type of file (e.g., 'barrel-export', 'utility-module').
|
|
349
|
+
* @param file - File path or identifier.
|
|
350
|
+
* @param issues - Initial list of issues to supplement.
|
|
351
|
+
* @returns Array of tailored recommendations.
|
|
311
352
|
*/
|
|
312
353
|
declare function getClassificationRecommendations(classification: FileClassification, file: string, issues: string[]): string[];
|
|
313
354
|
/**
|
|
314
|
-
* Generate general context recommendations
|
|
355
|
+
* Generate general context recommendations based on cross-tool metrics and thresholds.
|
|
356
|
+
*
|
|
357
|
+
* @param metrics - Object containing context budget, depth, circular dependencies, cohesion, and fragmentation.
|
|
358
|
+
* @param thresholds - Configurable limits for each metric.
|
|
359
|
+
* @returns Object with recommendations array, issues array, and overall severity level.
|
|
315
360
|
*/
|
|
316
361
|
declare function getGeneralRecommendations(metrics: {
|
|
317
362
|
contextBudget: number;
|
|
@@ -331,9 +376,23 @@ declare function getGeneralRecommendations(metrics: {
|
|
|
331
376
|
};
|
|
332
377
|
|
|
333
378
|
/**
|
|
334
|
-
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
379
|
+
* Calculate AI Readiness Score for context efficiency (0-100).
|
|
380
|
+
*
|
|
381
|
+
* Evaluates how efficiently an AI model can process the project's code context
|
|
382
|
+
* based on token budgets, import depth, and file fragmentation.
|
|
383
|
+
*
|
|
384
|
+
* @param summary - Consolidated context summary from the scan.
|
|
385
|
+
* @param costConfig - Optional configuration for business value calculations.
|
|
386
|
+
* @returns Standardized scoring output for the context analyzer tool.
|
|
387
|
+
* @lastUpdated 2026-03-18
|
|
335
388
|
*/
|
|
336
389
|
declare function calculateContextScore(summary: ContextSummary, costConfig?: Partial<CostConfig>): ToolScoringOutput;
|
|
390
|
+
/**
|
|
391
|
+
* Maps a numerical score to a human-readable rating slug.
|
|
392
|
+
*
|
|
393
|
+
* @param score - The 0-100 readiness score.
|
|
394
|
+
* @returns A formatted rating string (e.g., "excellent", "at risk").
|
|
395
|
+
*/
|
|
337
396
|
declare function mapScoreToRating(score: number): string;
|
|
338
397
|
|
|
339
398
|
/**
|
|
@@ -347,46 +406,96 @@ declare function getSmartDefaults(directory: string, userOptions: Partial<Contex
|
|
|
347
406
|
|
|
348
407
|
/**
|
|
349
408
|
* Generate summary of context analysis results
|
|
409
|
+
*
|
|
410
|
+
* @param results - Array of individual file analysis results.
|
|
411
|
+
* @param options - Optional scan configuration for context extraction.
|
|
412
|
+
* @returns A consolidated summary of the entire context scan.
|
|
350
413
|
*/
|
|
351
414
|
declare function generateSummary(results: ContextAnalysisResult[], options?: any): ContextSummary;
|
|
352
415
|
|
|
353
416
|
/**
|
|
354
|
-
* Build co-usage matrix: track which files are imported together
|
|
355
|
-
*
|
|
356
|
-
* @
|
|
417
|
+
* Build co-usage matrix: track which files are imported together frequently.
|
|
418
|
+
*
|
|
419
|
+
* @param graph - The dependency graph to analyze.
|
|
420
|
+
* @returns Map of file path to nested map of related files and their co-occurrence counts.
|
|
357
421
|
*/
|
|
358
422
|
declare function buildCoUsageMatrix(graph: DependencyGraph): Map<string, Map<string, number>>;
|
|
359
423
|
/**
|
|
360
|
-
* Extract type dependencies from AST exports
|
|
361
|
-
*
|
|
362
|
-
* @
|
|
424
|
+
* Extract type dependencies from AST exports to build a type-based relationship graph.
|
|
425
|
+
*
|
|
426
|
+
* @param graph - The dependency graph to analyze.
|
|
427
|
+
* @returns Map of type reference names to sets of files that consume or export them.
|
|
363
428
|
*/
|
|
364
429
|
declare function buildTypeGraph(graph: DependencyGraph): Map<string, Set<string>>;
|
|
365
430
|
/**
|
|
366
|
-
* Find semantic clusters using co-usage patterns
|
|
367
|
-
*
|
|
368
|
-
* @param
|
|
369
|
-
* @
|
|
431
|
+
* Find semantic clusters using frequently occurring co-usage patterns.
|
|
432
|
+
*
|
|
433
|
+
* @param coUsageMatrix - The co-usage matrix from buildCoUsageMatrix.
|
|
434
|
+
* @param minCoUsage - Minimum co-usage count to consider a strong relationship (default: 3).
|
|
435
|
+
* @returns Map of cluster representative files to their associated cluster members.
|
|
370
436
|
*/
|
|
371
437
|
declare function findSemanticClusters(coUsageMatrix: Map<string, Map<string, number>>, minCoUsage?: number): Map<string, string[]>;
|
|
372
438
|
/**
|
|
373
|
-
* Infer domain from semantic analysis (co-usage + types)
|
|
439
|
+
* Infer domain from semantic analysis (co-usage + types) to identify logical modules.
|
|
440
|
+
*
|
|
441
|
+
* @param file - The file path to infer domain for.
|
|
442
|
+
* @param exportName - The specific export identifier.
|
|
443
|
+
* @param graph - The full dependency graph.
|
|
444
|
+
* @param coUsageMatrix - Matrix of files frequently imported together.
|
|
445
|
+
* @param typeGraph - Map of type references to files.
|
|
446
|
+
* @param exportTypeRefs - Optional list of types referenced by the export.
|
|
447
|
+
* @returns Array of potential domain assignments with confidence scores.
|
|
374
448
|
*/
|
|
375
449
|
declare function inferDomainFromSemantics(file: string, exportName: string, graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, exportTypeRefs?: string[]): DomainAssignment[];
|
|
450
|
+
/**
|
|
451
|
+
* Calculate confidence score for a domain assignment based on signals.
|
|
452
|
+
*
|
|
453
|
+
* @param signals - The set of semantic signals detected for a domain.
|
|
454
|
+
* @returns Numerical confidence score (0-1).
|
|
455
|
+
*/
|
|
376
456
|
declare function calculateDomainConfidence(signals: DomainSignals): number;
|
|
377
457
|
/**
|
|
378
458
|
* Regex-based export extraction (legacy/fallback)
|
|
459
|
+
*
|
|
460
|
+
* @param content - Source code content.
|
|
461
|
+
* @param filePath - Optional file path for domain context.
|
|
462
|
+
* @param domainOptions - Optional overrides for domain keywords.
|
|
463
|
+
* @param fileImports - Optional list of actual imports for semantic context.
|
|
464
|
+
* @returns Array of extracted export information.
|
|
379
465
|
*/
|
|
380
466
|
declare function extractExports(content: string, filePath?: string, domainOptions?: {
|
|
381
467
|
domainKeywords?: string[];
|
|
382
468
|
}, fileImports?: string[]): ExportInfo[];
|
|
383
469
|
/**
|
|
384
470
|
* Infer domain from name, path, or imports
|
|
471
|
+
*
|
|
472
|
+
* @param name - The identifier name to analyze.
|
|
473
|
+
* @param filePath - Optional file path for structure context.
|
|
474
|
+
* @param domainOptions - Optional overrides for domain keywords.
|
|
475
|
+
* @param fileImports - Optional list of imports for domain context.
|
|
476
|
+
* @returns The inferred domain name (string).
|
|
385
477
|
*/
|
|
386
478
|
declare function inferDomain(name: string, filePath?: string, domainOptions?: {
|
|
387
479
|
domainKeywords?: string[];
|
|
388
480
|
}, fileImports?: string[]): string;
|
|
481
|
+
/**
|
|
482
|
+
* Retrieve co-usage data for a specific file.
|
|
483
|
+
*
|
|
484
|
+
* @param file - The file path to look up.
|
|
485
|
+
* @param coUsageMatrix - The global co-usage matrix.
|
|
486
|
+
* @returns Formatted co-usage data object.
|
|
487
|
+
*/
|
|
389
488
|
declare function getCoUsageData(file: string, coUsageMatrix: Map<string, Map<string, number>>): CoUsageData;
|
|
489
|
+
/**
|
|
490
|
+
* Identify candidates for module consolidation based on high co-usage or shared types.
|
|
491
|
+
*
|
|
492
|
+
* @param graph - The dependency graph.
|
|
493
|
+
* @param coUsageMatrix - Matrix of frequently paired files.
|
|
494
|
+
* @param typeGraph - Map of shared type references.
|
|
495
|
+
* @param minCoUsage - Minimum co-usage count threshold.
|
|
496
|
+
* @param minSharedTypes - Minimum shared types threshold.
|
|
497
|
+
* @returns Array of consolidation candidates sorted by strength.
|
|
498
|
+
*/
|
|
390
499
|
declare function findConsolidationCandidates(graph: DependencyGraph, coUsageMatrix: Map<string, Map<string, number>>, typeGraph: Map<string, Set<string>>, minCoUsage?: number, minSharedTypes?: number): any[];
|
|
391
500
|
|
|
392
501
|
/**
|