@aiready/core 0.9.22 → 0.9.25

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.
@@ -0,0 +1,547 @@
1
+ interface AnalysisResult {
2
+ fileName: string;
3
+ issues: Issue[];
4
+ metrics: Metrics;
5
+ }
6
+ interface Issue {
7
+ type: IssueType;
8
+ severity: 'critical' | 'major' | 'minor' | 'info';
9
+ message: string;
10
+ location: Location;
11
+ suggestion?: string;
12
+ }
13
+ type IssueType = 'duplicate-pattern' | 'context-fragmentation' | 'doc-drift' | 'naming-inconsistency' | 'naming-quality' | 'pattern-inconsistency' | 'architecture-inconsistency' | 'dead-code' | 'circular-dependency' | 'missing-types';
14
+ interface Location {
15
+ file: string;
16
+ line: number;
17
+ column?: number;
18
+ endLine?: number;
19
+ endColumn?: number;
20
+ }
21
+ interface Metrics {
22
+ tokenCost?: number;
23
+ complexityScore?: number;
24
+ consistencyScore?: number;
25
+ docFreshnessScore?: number;
26
+ estimatedMonthlyCost?: number;
27
+ estimatedDeveloperHours?: number;
28
+ comprehensionDifficultyIndex?: number;
29
+ }
30
+ /**
31
+ * Cost estimation configuration
32
+ */
33
+ interface CostConfig {
34
+ /** Price per 1K tokens (default: $0.01 for GPT-4) */
35
+ pricePer1KTokens: number;
36
+ /** Average AI queries per developer per day */
37
+ queriesPerDevPerDay: number;
38
+ /** Number of developers on the team */
39
+ developerCount: number;
40
+ /** Days per month (default: 30) */
41
+ daysPerMonth: number;
42
+ }
43
+ /**
44
+ * Productivity impact estimates
45
+ */
46
+ interface ProductivityImpact {
47
+ /** Estimated hours to fix all issues */
48
+ totalHours: number;
49
+ /** Average hourly rate for developers */
50
+ hourlyRate: number;
51
+ /** Estimated total fix cost */
52
+ totalCost: number;
53
+ /** Breakdown by severity */
54
+ bySeverity: {
55
+ critical: {
56
+ hours: number;
57
+ cost: number;
58
+ };
59
+ major: {
60
+ hours: number;
61
+ cost: number;
62
+ };
63
+ minor: {
64
+ hours: number;
65
+ cost: number;
66
+ };
67
+ };
68
+ }
69
+ /**
70
+ * AI acceptance rate prediction
71
+ * Based on research correlating code quality to AI suggestion acceptance
72
+ */
73
+ interface AcceptancePrediction {
74
+ /** Predicted acceptance rate (0-1) */
75
+ rate: number;
76
+ /** Confidence level (0-1) */
77
+ confidence: number;
78
+ /** Factors affecting acceptance */
79
+ factors: {
80
+ name: string;
81
+ impact: number;
82
+ }[];
83
+ }
84
+ /**
85
+ * Comprehension difficulty score (future-proof abstraction)
86
+ * Normalized 0-100 scale: lower = easier for AI to understand
87
+ */
88
+ interface ComprehensionDifficulty {
89
+ /** Overall difficulty score (0-100) */
90
+ score: number;
91
+ /** Factors contributing to difficulty */
92
+ factors: {
93
+ name: string;
94
+ contribution: number;
95
+ description: string;
96
+ }[];
97
+ /** Interpretation */
98
+ rating: 'trivial' | 'easy' | 'moderate' | 'difficult' | 'expert';
99
+ }
100
+ /**
101
+ * Extended report with business metrics
102
+ */
103
+ interface BusinessReport extends Report {
104
+ businessMetrics: {
105
+ /** Estimated monthly cost impact of AI context waste */
106
+ estimatedMonthlyCost: number;
107
+ /** Estimated developer hours to address issues */
108
+ estimatedDeveloperHours: number;
109
+ /** Predicted AI suggestion acceptance rate */
110
+ aiAcceptanceRate: number;
111
+ /** Comprehension difficulty assessment */
112
+ comprehensionDifficulty: ComprehensionDifficulty;
113
+ /** Timestamp for trend tracking */
114
+ period?: string;
115
+ };
116
+ }
117
+ interface ScanOptions {
118
+ rootDir: string;
119
+ include?: string[];
120
+ exclude?: string[];
121
+ maxDepth?: number;
122
+ }
123
+ interface AIReadyConfig {
124
+ scan?: {
125
+ include?: string[];
126
+ exclude?: string[];
127
+ tools?: string[];
128
+ };
129
+ tools?: {
130
+ 'pattern-detect'?: {
131
+ enabled?: boolean;
132
+ scoreWeight?: number;
133
+ minSimilarity?: number;
134
+ minLines?: number;
135
+ batchSize?: number;
136
+ approx?: boolean;
137
+ minSharedTokens?: number;
138
+ maxCandidatesPerBlock?: number;
139
+ streamResults?: boolean;
140
+ maxResults?: number;
141
+ };
142
+ 'context-analyzer'?: {
143
+ enabled?: boolean;
144
+ scoreWeight?: number;
145
+ maxDepth?: number;
146
+ maxContextBudget?: number;
147
+ minCohesion?: number;
148
+ maxFragmentation?: number;
149
+ focus?: 'fragmentation' | 'cohesion' | 'depth' | 'all';
150
+ includeNodeModules?: boolean;
151
+ maxResults?: number;
152
+ domainKeywords?: string[];
153
+ domainPatterns?: string[];
154
+ pathDomainMap?: Record<string, string>;
155
+ };
156
+ 'consistency'?: {
157
+ enabled?: boolean;
158
+ scoreWeight?: number;
159
+ acceptedAbbreviations?: string[];
160
+ shortWords?: string[];
161
+ disableChecks?: ('single-letter' | 'abbreviation' | 'convention-mix' | 'unclear' | 'poor-naming')[];
162
+ };
163
+ [toolName: string]: {
164
+ enabled?: boolean;
165
+ scoreWeight?: number;
166
+ [key: string]: any;
167
+ } | undefined;
168
+ };
169
+ scoring?: {
170
+ threshold?: number;
171
+ showBreakdown?: boolean;
172
+ compareBaseline?: string;
173
+ saveTo?: string;
174
+ };
175
+ output?: {
176
+ format?: 'console' | 'json' | 'html';
177
+ file?: string;
178
+ };
179
+ visualizer?: {
180
+ groupingDirs?: string[];
181
+ graph?: {
182
+ maxNodes?: number;
183
+ maxEdges?: number;
184
+ };
185
+ };
186
+ }
187
+ interface Report {
188
+ summary: {
189
+ totalFiles: number;
190
+ totalIssues: number;
191
+ criticalIssues: number;
192
+ majorIssues: number;
193
+ };
194
+ results: AnalysisResult[];
195
+ metrics: {
196
+ overallScore: number;
197
+ tokenCostTotal: number;
198
+ avgConsistency: number;
199
+ };
200
+ }
201
+ /**
202
+ * Severity levels for issues
203
+ */
204
+ type GraphIssueSeverity = 'critical' | 'major' | 'minor' | 'info';
205
+ /**
206
+ * Base graph node
207
+ */
208
+ interface GraphNode {
209
+ id: string;
210
+ label: string;
211
+ path?: string;
212
+ size?: number;
213
+ value?: number;
214
+ color?: string;
215
+ group?: string;
216
+ x?: number;
217
+ y?: number;
218
+ }
219
+ /**
220
+ * Graph edge between nodes
221
+ */
222
+ interface GraphEdge {
223
+ source: string | GraphNode;
224
+ target: string | GraphNode;
225
+ type?: string;
226
+ weight?: number;
227
+ }
228
+ /**
229
+ * Graph metadata
230
+ */
231
+ interface GraphMetadata {
232
+ projectName?: string;
233
+ timestamp: string;
234
+ totalFiles: number;
235
+ totalDependencies: number;
236
+ analysisTypes: string[];
237
+ criticalIssues: number;
238
+ majorIssues: number;
239
+ minorIssues: number;
240
+ infoIssues: number;
241
+ }
242
+ /**
243
+ * Complete graph data structure for visualization
244
+ */
245
+ interface GraphData {
246
+ nodes: GraphNode[];
247
+ edges: GraphEdge[];
248
+ clusters?: {
249
+ id: string;
250
+ name: string;
251
+ nodeIds: string[];
252
+ }[];
253
+ issues?: {
254
+ id: string;
255
+ type: string;
256
+ severity: GraphIssueSeverity;
257
+ nodeIds: string[];
258
+ message: string;
259
+ }[];
260
+ metadata: GraphMetadata;
261
+ }
262
+
263
+ /**
264
+ * Language-agnostic AST and parser interfaces for multi-language support
265
+ *
266
+ * This module provides abstractions for parsing different programming languages
267
+ * while maintaining a consistent interface for analysis tools.
268
+ */
269
+ /**
270
+ * Supported programming languages
271
+ */
272
+ declare enum Language {
273
+ TypeScript = "typescript",
274
+ JavaScript = "javascript",
275
+ Python = "python",
276
+ Java = "java",
277
+ Go = "go",
278
+ Rust = "rust",
279
+ CSharp = "csharp"
280
+ }
281
+ /**
282
+ * File extensions mapped to languages
283
+ */
284
+ declare const LANGUAGE_EXTENSIONS: Record<string, Language>;
285
+ /**
286
+ * Location information in source code
287
+ */
288
+ interface SourceLocation {
289
+ line: number;
290
+ column: number;
291
+ }
292
+ interface SourceRange {
293
+ start: SourceLocation;
294
+ end: SourceLocation;
295
+ }
296
+ /**
297
+ * Common AST node type (language-agnostic)
298
+ */
299
+ interface CommonASTNode {
300
+ type: string;
301
+ loc?: SourceRange;
302
+ raw?: any;
303
+ }
304
+ /**
305
+ * Export information (function, class, variable, etc.)
306
+ */
307
+ interface ExportInfo {
308
+ name: string;
309
+ type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default' | 'variable';
310
+ loc?: SourceRange;
311
+ /** Imports used within this export */
312
+ imports?: string[];
313
+ /** Dependencies on other exports in same file */
314
+ dependencies?: string[];
315
+ /** TypeScript types referenced */
316
+ typeReferences?: string[];
317
+ /** For methods: parent class name */
318
+ parentClass?: string;
319
+ /** For functions/methods: parameters */
320
+ parameters?: string[];
321
+ /** Visibility (public, private, protected) */
322
+ visibility?: 'public' | 'private' | 'protected';
323
+ }
324
+ /**
325
+ * Import information
326
+ */
327
+ interface ImportInfo {
328
+ /** Module being imported from */
329
+ source: string;
330
+ /** What's being imported */
331
+ specifiers: string[];
332
+ /** Is this a type-only import (TypeScript) */
333
+ isTypeOnly?: boolean;
334
+ /** Location in source */
335
+ loc?: SourceRange;
336
+ }
337
+ /**
338
+ * Parse result containing exports and imports
339
+ */
340
+ interface ParseResult {
341
+ exports: ExportInfo[];
342
+ imports: ImportInfo[];
343
+ /** Language of the parsed file */
344
+ language: Language;
345
+ /** Any parse warnings (non-fatal) */
346
+ warnings?: string[];
347
+ }
348
+ /**
349
+ * Naming convention rules per language
350
+ */
351
+ interface NamingConvention {
352
+ /** Allowed variable naming patterns */
353
+ variablePattern: RegExp;
354
+ /** Allowed function naming patterns */
355
+ functionPattern: RegExp;
356
+ /** Allowed class naming patterns */
357
+ classPattern: RegExp;
358
+ /** Allowed constant naming patterns */
359
+ constantPattern: RegExp;
360
+ /** Language-specific exceptions (e.g., __init__ in Python) */
361
+ exceptions?: string[];
362
+ }
363
+ /**
364
+ * Language-specific configuration
365
+ */
366
+ interface LanguageConfig {
367
+ language: Language;
368
+ /** File extensions for this language */
369
+ extensions: string[];
370
+ /** Naming conventions */
371
+ namingConventions: NamingConvention;
372
+ /** Common abbreviations allowed */
373
+ allowedAbbreviations?: string[];
374
+ /** Language-specific keywords to ignore */
375
+ keywords?: string[];
376
+ }
377
+ /**
378
+ * Abstract interface for language parsers
379
+ * Each language implementation should implement this interface
380
+ */
381
+ interface LanguageParser {
382
+ /** Language this parser handles */
383
+ readonly language: Language;
384
+ /** File extensions this parser supports */
385
+ readonly extensions: string[];
386
+ /**
387
+ * Parse source code and extract structure
388
+ * @param code - Source code to parse
389
+ * @param filePath - Path to the file (for context)
390
+ * @returns Parse result with exports and imports
391
+ * @throws ParseError if code has syntax errors
392
+ */
393
+ parse(code: string, filePath: string): ParseResult;
394
+ /**
395
+ * Get naming conventions for this language
396
+ */
397
+ getNamingConventions(): NamingConvention;
398
+ /**
399
+ * Check if this parser can handle a file
400
+ * @param filePath - File path to check
401
+ */
402
+ canHandle(filePath: string): boolean;
403
+ }
404
+ /**
405
+ * Parser error with location information
406
+ */
407
+ declare class ParseError extends Error {
408
+ readonly filePath: string;
409
+ readonly loc?: SourceLocation | undefined;
410
+ constructor(message: string, filePath: string, loc?: SourceLocation | undefined);
411
+ }
412
+ /**
413
+ * Statistics about parsed code
414
+ */
415
+ interface ParseStatistics {
416
+ language: Language;
417
+ filesAnalyzed: number;
418
+ totalExports: number;
419
+ totalImports: number;
420
+ parseErrors: number;
421
+ warnings: number;
422
+ }
423
+
424
+ /**
425
+ * AI Readiness Scoring System
426
+ *
427
+ * Provides dynamic, composable scoring across multiple analysis tools.
428
+ * Each tool contributes a 0-100 score with configurable weights.
429
+ */
430
+ interface ToolScoringOutput {
431
+ /** Unique tool identifier (e.g., "pattern-detect") */
432
+ toolName: string;
433
+ /** Normalized 0-100 score for this tool */
434
+ score: number;
435
+ /** Raw metrics used to calculate the score */
436
+ rawMetrics: Record<string, any>;
437
+ /** Factors that influenced the score */
438
+ factors: Array<{
439
+ name: string;
440
+ impact: number;
441
+ description: string;
442
+ }>;
443
+ /** Actionable recommendations with estimated impact */
444
+ recommendations: Array<{
445
+ action: string;
446
+ estimatedImpact: number;
447
+ priority: 'high' | 'medium' | 'low';
448
+ }>;
449
+ }
450
+ interface ScoringResult {
451
+ /** Overall AI Readiness Score (0-100) */
452
+ overall: number;
453
+ /** Rating category */
454
+ rating: 'Excellent' | 'Good' | 'Fair' | 'Needs Work' | 'Critical';
455
+ /** Timestamp of score calculation */
456
+ timestamp: string;
457
+ /** Tools that contributed to this score */
458
+ toolsUsed: string[];
459
+ /** Breakdown by tool */
460
+ breakdown: ToolScoringOutput[];
461
+ /** Calculation details */
462
+ calculation: {
463
+ formula: string;
464
+ weights: Record<string, number>;
465
+ normalized: string;
466
+ };
467
+ }
468
+ interface ScoringConfig {
469
+ /** Minimum passing score (exit code 1 if below) */
470
+ threshold?: number;
471
+ /** Show detailed breakdown in output */
472
+ showBreakdown?: boolean;
473
+ /** Path to baseline JSON for comparison */
474
+ compareBaseline?: string;
475
+ /** Auto-save score to this path */
476
+ saveTo?: string;
477
+ }
478
+ /**
479
+ * Default weights for known tools.
480
+ * New tools get weight of 10 if not specified.
481
+ */
482
+ declare const DEFAULT_TOOL_WEIGHTS: Record<string, number>;
483
+ /**
484
+ * Tool name normalization map (shorthand -> full name)
485
+ */
486
+ declare const TOOL_NAME_MAP: Record<string, string>;
487
+ /**
488
+ * Normalize tool name from shorthand to full name
489
+ */
490
+ declare function normalizeToolName(shortName: string): string;
491
+ /**
492
+ * Get tool weight with fallback priority:
493
+ * 1. CLI override
494
+ * 2. Tool config scoreWeight
495
+ * 3. Default weight
496
+ * 4. 10 (for unknown tools)
497
+ */
498
+ declare function getToolWeight(toolName: string, toolConfig?: {
499
+ scoreWeight?: number;
500
+ }, cliOverride?: number): number;
501
+ /**
502
+ * Parse weight string from CLI (e.g., "patterns:50,context:30")
503
+ */
504
+ declare function parseWeightString(weightStr?: string): Map<string, number>;
505
+ /**
506
+ * Calculate overall AI Readiness Score from multiple tool scores.
507
+ *
508
+ * Formula: Σ(tool_score × tool_weight) / Σ(active_tool_weights)
509
+ *
510
+ * This allows dynamic composition - score adjusts automatically
511
+ * based on which tools actually ran.
512
+ */
513
+ declare function calculateOverallScore(toolOutputs: Map<string, ToolScoringOutput>, config?: any, cliWeights?: Map<string, number>): ScoringResult;
514
+ /**
515
+ * Convert numeric score to rating category
516
+ */
517
+ declare function getRating(score: number): ScoringResult['rating'];
518
+ /**
519
+ * Get rating emoji and color for display
520
+ */
521
+ declare function getRatingDisplay(rating: ScoringResult['rating']): {
522
+ emoji: string;
523
+ color: string;
524
+ };
525
+ /**
526
+ * Format score for display with rating
527
+ */
528
+ declare function formatScore(result: ScoringResult): string;
529
+ /**
530
+ * Format individual tool score for display
531
+ */
532
+ declare function formatToolScore(output: ToolScoringOutput): string;
533
+
534
+ /**
535
+ * Visualization utilities for generating HTML from graph data
536
+ */
537
+
538
+ /**
539
+ * Generate HTML visualization from graph data
540
+ * Creates an interactive HTML page with a canvas-based graph visualization
541
+ *
542
+ * @param graph - The graph data to visualize
543
+ * @returns HTML string representing the interactive visualization
544
+ */
545
+ declare function generateHTML(graph: GraphData): string;
546
+
547
+ export { type AIReadyConfig, type AcceptancePrediction, type AnalysisResult, type BusinessReport, type CommonASTNode, type ComprehensionDifficulty, type CostConfig, DEFAULT_TOOL_WEIGHTS, type ExportInfo, type GraphData, type GraphEdge, type GraphIssueSeverity, type GraphMetadata, type GraphNode, type ImportInfo, type Issue, type IssueType, LANGUAGE_EXTENSIONS, Language, type LanguageConfig, type LanguageParser, type Location, type Metrics, type NamingConvention, ParseError, type ParseResult, type ParseStatistics, type ProductivityImpact, type Report, type ScanOptions, type ScoringConfig, type ScoringResult, type SourceLocation, type SourceRange, TOOL_NAME_MAP, type ToolScoringOutput, calculateOverallScore, formatScore, formatToolScore, generateHTML, getRating, getRatingDisplay, getToolWeight, normalizeToolName, parseWeightString };