codereview-aia 0.1.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.
- package/.cr-aia.yml +23 -0
- package/.crignore +0 -0
- package/dist/index.js +27 -0
- package/package.json +85 -0
- package/src/analysis/FindingsExtractor.ts +431 -0
- package/src/analysis/ai-detection/analyzers/BaseAnalyzer.ts +267 -0
- package/src/analysis/ai-detection/analyzers/DocumentationAnalyzer.ts +622 -0
- package/src/analysis/ai-detection/analyzers/GitHistoryAnalyzer.ts +430 -0
- package/src/analysis/ai-detection/core/AIDetectionEngine.ts +467 -0
- package/src/analysis/ai-detection/types/DetectionTypes.ts +406 -0
- package/src/analysis/ai-detection/utils/SubmissionConverter.ts +390 -0
- package/src/analysis/context/ReviewContext.ts +378 -0
- package/src/analysis/context/index.ts +7 -0
- package/src/analysis/index.ts +8 -0
- package/src/analysis/tokens/TokenAnalysisFormatter.ts +154 -0
- package/src/analysis/tokens/TokenAnalyzer.ts +747 -0
- package/src/analysis/tokens/index.ts +8 -0
- package/src/clients/base/abstractClient.ts +190 -0
- package/src/clients/base/httpClient.ts +160 -0
- package/src/clients/base/index.ts +12 -0
- package/src/clients/base/modelDetection.ts +107 -0
- package/src/clients/base/responseProcessor.ts +586 -0
- package/src/clients/factory/clientFactory.ts +55 -0
- package/src/clients/factory/index.ts +8 -0
- package/src/clients/implementations/index.ts +8 -0
- package/src/clients/implementations/openRouterClient.ts +411 -0
- package/src/clients/openRouterClient.ts +863 -0
- package/src/clients/openRouterClientWrapper.ts +44 -0
- package/src/clients/utils/directoryStructure.ts +52 -0
- package/src/clients/utils/index.ts +11 -0
- package/src/clients/utils/languageDetection.ts +44 -0
- package/src/clients/utils/promptFormatter.ts +105 -0
- package/src/clients/utils/promptLoader.ts +53 -0
- package/src/clients/utils/tokenCounter.ts +297 -0
- package/src/core/ApiClientSelector.ts +37 -0
- package/src/core/ConfigurationService.ts +591 -0
- package/src/core/ConsolidationService.ts +423 -0
- package/src/core/InteractiveDisplayManager.ts +81 -0
- package/src/core/OutputManager.ts +275 -0
- package/src/core/ReviewGenerator.ts +140 -0
- package/src/core/fileDiscovery.ts +237 -0
- package/src/core/handlers/EstimationHandler.ts +104 -0
- package/src/core/handlers/FileProcessingHandler.ts +204 -0
- package/src/core/handlers/OutputHandler.ts +125 -0
- package/src/core/handlers/ReviewExecutor.ts +104 -0
- package/src/core/reviewOrchestrator.ts +333 -0
- package/src/core/utils/ModelInfoUtils.ts +56 -0
- package/src/formatters/outputFormatter.ts +62 -0
- package/src/formatters/utils/IssueFormatters.ts +83 -0
- package/src/formatters/utils/JsonFormatter.ts +77 -0
- package/src/formatters/utils/MarkdownFormatters.ts +609 -0
- package/src/formatters/utils/MetadataFormatter.ts +269 -0
- package/src/formatters/utils/ModelInfoExtractor.ts +115 -0
- package/src/index.ts +27 -0
- package/src/plugins/PluginInterface.ts +50 -0
- package/src/plugins/PluginManager.ts +126 -0
- package/src/prompts/PromptManager.ts +69 -0
- package/src/prompts/cache/PromptCache.ts +50 -0
- package/src/prompts/promptText/common/variables/css-frameworks.json +33 -0
- package/src/prompts/promptText/common/variables/framework-versions.json +45 -0
- package/src/prompts/promptText/frameworks/react/comprehensive.hbs +19 -0
- package/src/prompts/promptText/languages/css/comprehensive.hbs +18 -0
- package/src/prompts/promptText/languages/generic/comprehensive.hbs +20 -0
- package/src/prompts/promptText/languages/html/comprehensive.hbs +18 -0
- package/src/prompts/promptText/languages/javascript/comprehensive.hbs +18 -0
- package/src/prompts/promptText/languages/python/comprehensive.hbs +18 -0
- package/src/prompts/promptText/languages/typescript/comprehensive.hbs +18 -0
- package/src/runtime/auth/service.ts +58 -0
- package/src/runtime/auth/session.ts +103 -0
- package/src/runtime/auth/types.ts +11 -0
- package/src/runtime/cliEntry.ts +196 -0
- package/src/runtime/errors.ts +13 -0
- package/src/runtime/fileCollector.ts +188 -0
- package/src/runtime/manifest.ts +64 -0
- package/src/runtime/openrouterProxy.ts +45 -0
- package/src/runtime/proxyConfig.ts +94 -0
- package/src/runtime/proxyEnvironment.ts +71 -0
- package/src/runtime/reportMerge.ts +102 -0
- package/src/runtime/reporting/markdownReportBuilder.ts +138 -0
- package/src/runtime/reporting/reportDataCollector.ts +234 -0
- package/src/runtime/reporting/summaryGenerator.ts +86 -0
- package/src/runtime/reviewPipeline.ts +155 -0
- package/src/runtime/runAiCodeReview.ts +153 -0
- package/src/runtime/runtimeConfig.ts +5 -0
- package/src/runtime/ui/Layout.tsx +57 -0
- package/src/runtime/ui/RuntimeApp.tsx +150 -0
- package/src/runtime/ui/inkModules.ts +73 -0
- package/src/runtime/ui/screens/AuthScreen.tsx +128 -0
- package/src/runtime/ui/screens/ModeSelection.tsx +52 -0
- package/src/runtime/ui/screens/ProgressScreen.tsx +55 -0
- package/src/runtime/ui/screens/ResultsScreen.tsx +76 -0
- package/src/strategies/ArchitecturalReviewStrategy.ts +54 -0
- package/src/strategies/CodingTestReviewStrategy.ts +920 -0
- package/src/strategies/ConsolidatedReviewStrategy.ts +59 -0
- package/src/strategies/ExtractPatternsReviewStrategy.ts +64 -0
- package/src/strategies/MultiPassReviewStrategy.ts +785 -0
- package/src/strategies/ReviewStrategy.ts +64 -0
- package/src/strategies/StrategyFactory.ts +79 -0
- package/src/strategies/index.ts +14 -0
- package/src/tokenizers/baseTokenizer.ts +61 -0
- package/src/tokenizers/gptTokenizer.ts +27 -0
- package/src/tokenizers/index.ts +8 -0
- package/src/types/apiResponses.ts +40 -0
- package/src/types/cli.ts +24 -0
- package/src/types/common.ts +39 -0
- package/src/types/configuration.ts +201 -0
- package/src/types/handlebars.d.ts +5 -0
- package/src/types/patch.d.ts +25 -0
- package/src/types/review.ts +294 -0
- package/src/types/reviewContext.d.ts +65 -0
- package/src/types/reviewSchema.ts +181 -0
- package/src/types/structuredReview.ts +167 -0
- package/src/types/tokenAnalysis.ts +56 -0
- package/src/utils/FileReader.ts +93 -0
- package/src/utils/FileWriter.ts +76 -0
- package/src/utils/PathGenerator.ts +97 -0
- package/src/utils/api/apiUtils.ts +14 -0
- package/src/utils/api/index.ts +1 -0
- package/src/utils/apiErrorHandler.ts +287 -0
- package/src/utils/ciDataCollector.ts +252 -0
- package/src/utils/codingTestConfigLoader.ts +466 -0
- package/src/utils/dependencies/aiDependencyAnalyzer.ts +454 -0
- package/src/utils/detection/frameworkDetector.ts +879 -0
- package/src/utils/detection/index.ts +10 -0
- package/src/utils/detection/projectTypeDetector.ts +518 -0
- package/src/utils/diagramGenerator.ts +206 -0
- package/src/utils/errorLogger.ts +60 -0
- package/src/utils/estimationUtils.ts +407 -0
- package/src/utils/fileFilters.ts +373 -0
- package/src/utils/fileSystem.ts +57 -0
- package/src/utils/index.ts +36 -0
- package/src/utils/logger.ts +240 -0
- package/src/utils/pathValidator.ts +98 -0
- package/src/utils/priorityFilter.ts +59 -0
- package/src/utils/projectDocs.ts +189 -0
- package/src/utils/promptPaths.ts +29 -0
- package/src/utils/promptTemplateManager.ts +157 -0
- package/src/utils/review/consolidateReview.ts +553 -0
- package/src/utils/review/fixDisplay.ts +100 -0
- package/src/utils/review/fixImplementation.ts +61 -0
- package/src/utils/review/index.ts +36 -0
- package/src/utils/review/interactiveProcessing.ts +294 -0
- package/src/utils/review/progressTracker.ts +296 -0
- package/src/utils/review/reviewExtraction.ts +382 -0
- package/src/utils/review/types.ts +46 -0
- package/src/utils/reviewActionHandler.ts +18 -0
- package/src/utils/reviewParser.ts +253 -0
- package/src/utils/sanitizer.ts +238 -0
- package/src/utils/smartFileSelector.ts +255 -0
- package/src/utils/templateLoader.ts +514 -0
- package/src/utils/treeGenerator.ts +153 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +59 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Base analyzer class for AI detection patterns.
|
|
3
|
+
*
|
|
4
|
+
* This module provides the abstract base class that all specific analyzers extend,
|
|
5
|
+
* ensuring consistent interface and common functionality across different analysis types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
CodeSubmission,
|
|
10
|
+
DetectedPattern,
|
|
11
|
+
DetectionConfig,
|
|
12
|
+
PatternDetectionResult,
|
|
13
|
+
} from '../types/DetectionTypes';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Abstract base class for all AI detection analyzers
|
|
17
|
+
*/
|
|
18
|
+
export abstract class BaseAnalyzer {
|
|
19
|
+
protected config: DetectionConfig;
|
|
20
|
+
protected startTime = 0;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create a new base analyzer
|
|
24
|
+
* @param config Detection configuration
|
|
25
|
+
*/
|
|
26
|
+
constructor(config: DetectionConfig) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Analyze the submission for AI-generated patterns
|
|
32
|
+
* @param submission Code submission to analyze
|
|
33
|
+
* @returns Analysis result specific to this analyzer
|
|
34
|
+
*/
|
|
35
|
+
abstract analyze(submission: CodeSubmission): Promise<any>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the analyzer name
|
|
39
|
+
* @returns Analyzer identifier
|
|
40
|
+
*/
|
|
41
|
+
abstract getAnalyzerName(): string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if this analyzer is enabled in configuration
|
|
45
|
+
* @returns True if analyzer should run
|
|
46
|
+
*/
|
|
47
|
+
isEnabled(): boolean {
|
|
48
|
+
return this.config.enabledAnalyzers.includes(this.getAnalyzerName() as any);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Start timing analysis
|
|
53
|
+
*/
|
|
54
|
+
protected startTimer(): void {
|
|
55
|
+
this.startTime = Date.now();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get elapsed time since timer start
|
|
60
|
+
* @returns Elapsed time in milliseconds
|
|
61
|
+
*/
|
|
62
|
+
protected getElapsedTime(): number {
|
|
63
|
+
return Date.now() - this.startTime;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create a detected pattern object
|
|
68
|
+
* @param id Pattern identifier
|
|
69
|
+
* @param name Human-readable name
|
|
70
|
+
* @param confidence Confidence level
|
|
71
|
+
* @param score Numerical score
|
|
72
|
+
* @param description Pattern description
|
|
73
|
+
* @param evidenceData Supporting evidence
|
|
74
|
+
* @returns Detected pattern object
|
|
75
|
+
*/
|
|
76
|
+
protected createDetectedPattern(
|
|
77
|
+
id: string,
|
|
78
|
+
name: string,
|
|
79
|
+
confidence: 'high' | 'medium' | 'low',
|
|
80
|
+
score: number,
|
|
81
|
+
description: string,
|
|
82
|
+
evidenceData: Record<string, any>,
|
|
83
|
+
): DetectedPattern {
|
|
84
|
+
return {
|
|
85
|
+
id,
|
|
86
|
+
name,
|
|
87
|
+
confidence,
|
|
88
|
+
score: Math.min(1.0, Math.max(0.0, score)), // Clamp between 0 and 1
|
|
89
|
+
evidence: {
|
|
90
|
+
type: this.getAnalyzerName() as any,
|
|
91
|
+
data: evidenceData,
|
|
92
|
+
context: `Detected by ${this.getAnalyzerName()} analyzer`,
|
|
93
|
+
},
|
|
94
|
+
description,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Create a pattern detection result
|
|
100
|
+
* @param detected Whether pattern was detected
|
|
101
|
+
* @param score Confidence score
|
|
102
|
+
* @param evidence Supporting evidence
|
|
103
|
+
* @returns Pattern detection result
|
|
104
|
+
*/
|
|
105
|
+
protected createPatternResult(
|
|
106
|
+
detected: boolean,
|
|
107
|
+
score: number,
|
|
108
|
+
evidence?: Record<string, any>,
|
|
109
|
+
): PatternDetectionResult {
|
|
110
|
+
return {
|
|
111
|
+
detected,
|
|
112
|
+
score: Math.min(1.0, Math.max(0.0, score)),
|
|
113
|
+
evidence,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Calculate uniformity of a numeric array
|
|
119
|
+
* Used for detecting suspiciously uniform patterns in code
|
|
120
|
+
* @param values Array of numeric values
|
|
121
|
+
* @returns Uniformity score from 0.0 to 1.0 (higher = more uniform)
|
|
122
|
+
*/
|
|
123
|
+
protected calculateUniformity(values: number[]): number {
|
|
124
|
+
if (values.length < 2) return 0;
|
|
125
|
+
|
|
126
|
+
const mean = values.reduce((sum, val) => sum + val, 0) / values.length;
|
|
127
|
+
const variance = values.reduce((sum, val) => sum + (val - mean) ** 2, 0) / values.length;
|
|
128
|
+
const standardDeviation = Math.sqrt(variance);
|
|
129
|
+
|
|
130
|
+
// Convert to uniformity score (inverse of coefficient of variation)
|
|
131
|
+
if (mean === 0) return 1; // All values are 0, perfectly uniform
|
|
132
|
+
const coefficientOfVariation = standardDeviation / mean;
|
|
133
|
+
|
|
134
|
+
// Return uniformity score (higher = more uniform)
|
|
135
|
+
return Math.max(0, 1 - Math.min(1, coefficientOfVariation));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Calculate variance of a numeric array
|
|
140
|
+
* @param values Array of numeric values
|
|
141
|
+
* @param mean Pre-calculated mean (optional)
|
|
142
|
+
* @returns Variance value
|
|
143
|
+
*/
|
|
144
|
+
protected calculateVariance(values: number[], mean?: number): number {
|
|
145
|
+
if (values.length < 2) return 0;
|
|
146
|
+
|
|
147
|
+
const avgValue = mean ?? values.reduce((sum, val) => sum + val, 0) / values.length;
|
|
148
|
+
return values.reduce((sum, val) => sum + (val - avgValue) ** 2, 0) / values.length;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Extract sections from markdown or text content
|
|
153
|
+
* @param content Text content to analyze
|
|
154
|
+
* @returns Array of section headers found
|
|
155
|
+
*/
|
|
156
|
+
protected extractSections(content: string): string[] {
|
|
157
|
+
const sections: string[] = [];
|
|
158
|
+
const lines = content.split('\n');
|
|
159
|
+
|
|
160
|
+
for (const line of lines) {
|
|
161
|
+
const trimmed = line.trim();
|
|
162
|
+
|
|
163
|
+
// Markdown headers
|
|
164
|
+
if (trimmed.startsWith('#')) {
|
|
165
|
+
const headerText = trimmed.replace(/^#+\s*/, '').replace(/\s*#+\s*$/, '');
|
|
166
|
+
if (headerText) {
|
|
167
|
+
sections.push(headerText);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Underlined headers (=== or ---)
|
|
172
|
+
else if (trimmed.match(/^[=-]{3,}$/)) {
|
|
173
|
+
const prevLineIdx = lines.indexOf(line) - 1;
|
|
174
|
+
if (prevLineIdx >= 0) {
|
|
175
|
+
const prevLine = lines[prevLineIdx].trim();
|
|
176
|
+
if (prevLine && !prevLine.startsWith('#')) {
|
|
177
|
+
sections.push(prevLine);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return sections;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Count badges in markdown content
|
|
188
|
+
* @param content Markdown content
|
|
189
|
+
* @returns Number of badges found
|
|
190
|
+
*/
|
|
191
|
+
protected countBadges(content: string): number {
|
|
192
|
+
// Common badge patterns
|
|
193
|
+
const badgePatterns = [
|
|
194
|
+
/!\[.*?\]\(https:\/\/img\.shields\.io/g,
|
|
195
|
+
/!\[.*?\]\(https:\/\/badge\.fury\.io/g,
|
|
196
|
+
/!\[.*?\]\(https:\/\/travis-ci/g,
|
|
197
|
+
/!\[.*?\]\(https:\/\/ci\.appveyor/g,
|
|
198
|
+
/!\[.*?\]\(https:\/\/codecov\.io/g,
|
|
199
|
+
/!\[.*?\]\(https:\/\/coveralls\.io/g,
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
let badgeCount = 0;
|
|
203
|
+
for (const pattern of badgePatterns) {
|
|
204
|
+
const matches = content.match(pattern);
|
|
205
|
+
if (matches) {
|
|
206
|
+
badgeCount += matches.length;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return badgeCount;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Count generic phrases that suggest AI generation
|
|
215
|
+
* @param content Text content to analyze
|
|
216
|
+
* @returns Number of generic phrases found
|
|
217
|
+
*/
|
|
218
|
+
protected countGenericPhrases(content: string): number {
|
|
219
|
+
const genericPhrases = [
|
|
220
|
+
/this project provides/gi,
|
|
221
|
+
/easy to use/gi,
|
|
222
|
+
/getting started/gi,
|
|
223
|
+
/simply install/gi,
|
|
224
|
+
/contributions are welcome/gi,
|
|
225
|
+
/feel free to/gi,
|
|
226
|
+
/comprehensive solution/gi,
|
|
227
|
+
/powerful and flexible/gi,
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
let phraseCount = 0;
|
|
231
|
+
for (const pattern of genericPhrases) {
|
|
232
|
+
const matches = content.match(pattern);
|
|
233
|
+
if (matches) {
|
|
234
|
+
phraseCount += matches.length;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return phraseCount;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Validate that a score is within valid range
|
|
243
|
+
* @param score Score to validate
|
|
244
|
+
* @returns Clamped score between 0.0 and 1.0
|
|
245
|
+
*/
|
|
246
|
+
protected validateScore(score: number): number {
|
|
247
|
+
return Math.min(1.0, Math.max(0.0, score));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Check if analysis should timeout
|
|
252
|
+
* @returns True if analysis has exceeded time limit
|
|
253
|
+
*/
|
|
254
|
+
protected shouldTimeout(): boolean {
|
|
255
|
+
return this.getElapsedTime() > this.config.maxAnalysisTime;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Create timeout error
|
|
260
|
+
* @returns Error object for timeout
|
|
261
|
+
*/
|
|
262
|
+
protected createTimeoutError(): Error {
|
|
263
|
+
return new Error(
|
|
264
|
+
`${this.getAnalyzerName()} analysis timed out after ${this.config.maxAnalysisTime}ms`,
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
}
|