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,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review type definitions for cr-aia.
|
|
3
|
+
*
|
|
4
|
+
* The fork keeps only the options we rely on while trimming unrelated commentary.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { CostInfo } from '../clients/utils/tokenCounter';
|
|
8
|
+
import type { OutputFormat } from './common';
|
|
9
|
+
|
|
10
|
+
// Re-export CostInfo for convenience
|
|
11
|
+
export type { CostInfo } from '../clients/utils/tokenCounter';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Types of code reviews that can be performed
|
|
15
|
+
*/
|
|
16
|
+
export type ReviewType =
|
|
17
|
+
| 'quick-fixes'
|
|
18
|
+
| 'architectural'
|
|
19
|
+
| 'security'
|
|
20
|
+
| 'performance'
|
|
21
|
+
| 'unused-code'
|
|
22
|
+
| 'focused-unused-code'
|
|
23
|
+
| 'code-tracing-unused-code'
|
|
24
|
+
| 'consolidated'
|
|
25
|
+
| 'best-practices'
|
|
26
|
+
| 'evaluation'
|
|
27
|
+
| 'extract-patterns'
|
|
28
|
+
| 'coding-test'
|
|
29
|
+
| 'ai-integration'
|
|
30
|
+
| 'cloud-native'
|
|
31
|
+
| 'developer-experience'
|
|
32
|
+
| 'comprehensive';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Options for code reviews
|
|
36
|
+
*/
|
|
37
|
+
export interface ReviewOptions {
|
|
38
|
+
/** Type of review to perform */
|
|
39
|
+
type: ReviewType;
|
|
40
|
+
/** Output format */
|
|
41
|
+
output?: OutputFormat | 'none';
|
|
42
|
+
/** Directory to save review output */
|
|
43
|
+
outputDir?: string;
|
|
44
|
+
/** Model to use for the review */
|
|
45
|
+
model?: string;
|
|
46
|
+
/** Model to use for consolidating multi-pass reviews (defaults to main model) */
|
|
47
|
+
writerModel?: string;
|
|
48
|
+
/** Whether to include test files in the review */
|
|
49
|
+
includeTests?: boolean;
|
|
50
|
+
/** Whether to include project documentation in the review context */
|
|
51
|
+
includeProjectDocs?: boolean;
|
|
52
|
+
/** Whether to include dependency analysis in the review */
|
|
53
|
+
includeDependencyAnalysis?: boolean;
|
|
54
|
+
/** Whether to run in interactive mode */
|
|
55
|
+
interactive?: boolean;
|
|
56
|
+
/** Whether to test API connections before running the review */
|
|
57
|
+
testApi?: boolean;
|
|
58
|
+
/** Whether to estimate token usage and cost without performing the review */
|
|
59
|
+
estimate?: boolean;
|
|
60
|
+
/** Whether to use multi-pass review for large codebases */
|
|
61
|
+
multiPass?: boolean;
|
|
62
|
+
/** Whether to force single-pass review even if token analysis suggests multiple passes are needed */
|
|
63
|
+
forceSinglePass?: boolean;
|
|
64
|
+
/** Context maintenance factor for multi-pass reviews (0-1) */
|
|
65
|
+
contextMaintenanceFactor?: number;
|
|
66
|
+
/** Whether to skip confirmation prompts */
|
|
67
|
+
noConfirm?: boolean;
|
|
68
|
+
/** Whether to enable debug logging */
|
|
69
|
+
debug?: boolean;
|
|
70
|
+
/** Programming language of the code being reviewed */
|
|
71
|
+
language?: string;
|
|
72
|
+
/** Framework used in the code being reviewed */
|
|
73
|
+
framework?: string;
|
|
74
|
+
/** CI/CD data (TypeScript errors, lint errors) - internal use only */
|
|
75
|
+
ciData?: any;
|
|
76
|
+
/** Path to a custom prompt file */
|
|
77
|
+
promptFile?: string;
|
|
78
|
+
/** Prompt fragments to inject into the review */
|
|
79
|
+
promptFragments?: Array<{
|
|
80
|
+
content: string;
|
|
81
|
+
position: 'start' | 'middle' | 'end';
|
|
82
|
+
priority?: number;
|
|
83
|
+
}>;
|
|
84
|
+
/** Prompt strategy to use */
|
|
85
|
+
promptStrategy?: string;
|
|
86
|
+
/** Whether to use cache for prompts */
|
|
87
|
+
useCache?: boolean;
|
|
88
|
+
/** Whether to automatically fix issues */
|
|
89
|
+
autoFix?: boolean;
|
|
90
|
+
/** Whether to use ts-prune for unused code detection */
|
|
91
|
+
useTsPrune?: boolean;
|
|
92
|
+
/** Whether to use ESLint for code analysis */
|
|
93
|
+
useEslint?: boolean;
|
|
94
|
+
/** Whether to trace code execution */
|
|
95
|
+
traceCode?: boolean;
|
|
96
|
+
/** UI language for output messages */
|
|
97
|
+
uiLanguage?: string;
|
|
98
|
+
/** Target file or directory (used internally) */
|
|
99
|
+
target?: string;
|
|
100
|
+
/** Schema instructions for structured output */
|
|
101
|
+
schemaInstructions?: string;
|
|
102
|
+
/** Examples for prompts */
|
|
103
|
+
examples?: any[];
|
|
104
|
+
/** Whether to prompt for all issues */
|
|
105
|
+
promptAll?: boolean;
|
|
106
|
+
/** Whether to skip specific file content */
|
|
107
|
+
skipFileContent?: boolean;
|
|
108
|
+
/** Whether this is a consolidation pass */
|
|
109
|
+
isConsolidation?: boolean;
|
|
110
|
+
/** Project name */
|
|
111
|
+
projectName?: string;
|
|
112
|
+
/** Strategy override */
|
|
113
|
+
strategy?: string;
|
|
114
|
+
/** Whether to suppress output */
|
|
115
|
+
quiet?: boolean;
|
|
116
|
+
/** Whether to focus on specific aspects */
|
|
117
|
+
focused?: boolean;
|
|
118
|
+
/** Whether to use consolidated review */
|
|
119
|
+
consolidated?: boolean;
|
|
120
|
+
/** Whether to generate Mermaid architecture diagrams */
|
|
121
|
+
diagram?: boolean;
|
|
122
|
+
/** Force maximum tokens per batch (for testing consolidation) */
|
|
123
|
+
batchTokenLimit?: number;
|
|
124
|
+
|
|
125
|
+
// Coding test specific options
|
|
126
|
+
/** Path to assignment description file */
|
|
127
|
+
assignmentFile?: string;
|
|
128
|
+
/** URL to assignment description */
|
|
129
|
+
assignmentUrl?: string;
|
|
130
|
+
/** Inline assignment description */
|
|
131
|
+
assignmentText?: string;
|
|
132
|
+
/** Path to custom evaluation template */
|
|
133
|
+
evaluationTemplate?: string;
|
|
134
|
+
/** URL to evaluation template */
|
|
135
|
+
templateUrl?: string;
|
|
136
|
+
/** Path to scoring rubric file */
|
|
137
|
+
rubricFile?: string;
|
|
138
|
+
/** Type of assessment */
|
|
139
|
+
assessmentType?: 'coding-challenge' | 'take-home' | 'live-coding' | 'code-review';
|
|
140
|
+
/** Difficulty level */
|
|
141
|
+
difficultyLevel?: 'junior' | 'mid' | 'senior' | 'lead' | 'architect';
|
|
142
|
+
/** Expected completion time in minutes */
|
|
143
|
+
timeLimit?: number;
|
|
144
|
+
|
|
145
|
+
// Evaluation criteria weights
|
|
146
|
+
/** Weight for correctness evaluation (0-100) */
|
|
147
|
+
weightCorrectness?: number;
|
|
148
|
+
/** Weight for code quality evaluation (0-100) */
|
|
149
|
+
weightCodeQuality?: number;
|
|
150
|
+
/** Weight for architecture evaluation (0-100) */
|
|
151
|
+
weightArchitecture?: number;
|
|
152
|
+
/** Weight for performance evaluation (0-100) */
|
|
153
|
+
weightPerformance?: number;
|
|
154
|
+
/** Weight for testing evaluation (0-100) */
|
|
155
|
+
weightTesting?: number;
|
|
156
|
+
|
|
157
|
+
// Evaluation flags
|
|
158
|
+
/** Include documentation assessment */
|
|
159
|
+
evaluateDocumentation?: boolean;
|
|
160
|
+
/** Include git commit history analysis */
|
|
161
|
+
evaluateGitHistory?: boolean;
|
|
162
|
+
/** Focus on edge case handling */
|
|
163
|
+
evaluateEdgeCases?: boolean;
|
|
164
|
+
/** Focus on error handling patterns */
|
|
165
|
+
evaluateErrorHandling?: boolean;
|
|
166
|
+
|
|
167
|
+
// Scoring configuration
|
|
168
|
+
/** Scoring system type */
|
|
169
|
+
scoringSystem?: 'numeric' | 'letter' | 'pass-fail' | 'custom';
|
|
170
|
+
/** Maximum possible score */
|
|
171
|
+
maxScore?: number;
|
|
172
|
+
/** Minimum passing score */
|
|
173
|
+
passingThreshold?: number;
|
|
174
|
+
/** Include detailed score breakdown */
|
|
175
|
+
scoreBreakdown?: boolean;
|
|
176
|
+
|
|
177
|
+
// Feedback options
|
|
178
|
+
/** Feedback detail level */
|
|
179
|
+
feedbackLevel?: 'basic' | 'detailed' | 'comprehensive';
|
|
180
|
+
/** Include code examples in feedback */
|
|
181
|
+
includeExamples?: boolean;
|
|
182
|
+
/** Include improvement suggestions */
|
|
183
|
+
includeSuggestions?: boolean;
|
|
184
|
+
/** Include learning resources */
|
|
185
|
+
includeResources?: boolean;
|
|
186
|
+
|
|
187
|
+
// Constraints
|
|
188
|
+
/** Comma-separated list of allowed libraries */
|
|
189
|
+
allowedLibraries?: string[];
|
|
190
|
+
/** Comma-separated list of forbidden patterns */
|
|
191
|
+
forbiddenPatterns?: string[];
|
|
192
|
+
/** Expected Node.js version */
|
|
193
|
+
nodeVersion?: string;
|
|
194
|
+
/** Expected TypeScript version */
|
|
195
|
+
typescriptVersion?: string;
|
|
196
|
+
/** Memory constraint in MB */
|
|
197
|
+
memoryLimit?: number;
|
|
198
|
+
/** Execution timeout in seconds */
|
|
199
|
+
executionTimeout?: number;
|
|
200
|
+
|
|
201
|
+
/** AI Detection options */
|
|
202
|
+
/** Enable AI-generated code detection */
|
|
203
|
+
enableAiDetection?: boolean;
|
|
204
|
+
/** AI detection confidence threshold (0.0-1.0) */
|
|
205
|
+
aiDetectionThreshold?: number;
|
|
206
|
+
/** Comma-separated list of analyzers to use */
|
|
207
|
+
aiDetectionAnalyzers?: string;
|
|
208
|
+
/** Include AI detection results in the review report */
|
|
209
|
+
aiDetectionIncludeInReport?: boolean;
|
|
210
|
+
/** Automatically fail evaluation if AI-generated code is detected */
|
|
211
|
+
aiDetectionFailOnDetection?: boolean;
|
|
212
|
+
|
|
213
|
+
/** Coding test configuration (internal use) */
|
|
214
|
+
codingTestConfig?: any;
|
|
215
|
+
|
|
216
|
+
/** Metadata about the review (internal use) */
|
|
217
|
+
metadata?: any;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Information about a file to be reviewed
|
|
222
|
+
*/
|
|
223
|
+
export interface FileInfo {
|
|
224
|
+
/** Path to the file */
|
|
225
|
+
path: string;
|
|
226
|
+
/** Relative path to the file from the project root */
|
|
227
|
+
relativePath?: string;
|
|
228
|
+
/** Content of the file */
|
|
229
|
+
content: string;
|
|
230
|
+
/** File extension */
|
|
231
|
+
extension?: string;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Result of a code review
|
|
236
|
+
*/
|
|
237
|
+
export interface ReviewResult {
|
|
238
|
+
/** Content of the review */
|
|
239
|
+
content: string;
|
|
240
|
+
/** Path to the file that was reviewed */
|
|
241
|
+
filePath: string;
|
|
242
|
+
/** Type of review that was performed */
|
|
243
|
+
reviewType: ReviewType;
|
|
244
|
+
/** Timestamp when the review was generated */
|
|
245
|
+
timestamp: string;
|
|
246
|
+
/** Cost information for the review */
|
|
247
|
+
cost?: CostInfo;
|
|
248
|
+
/** Cost information for the review (alias for cost) */
|
|
249
|
+
costInfo?: CostInfo;
|
|
250
|
+
/** Model used for the review */
|
|
251
|
+
modelUsed?: string;
|
|
252
|
+
/** Structured data from the review */
|
|
253
|
+
structuredData?: any;
|
|
254
|
+
/** Metadata about the review */
|
|
255
|
+
metadata?: any;
|
|
256
|
+
/** Tool version used for the review */
|
|
257
|
+
toolVersion?: string;
|
|
258
|
+
/** Command options used for the review */
|
|
259
|
+
commandOptions?: string;
|
|
260
|
+
/** Detected language of the code */
|
|
261
|
+
detectedLanguage?: string;
|
|
262
|
+
/** Detected framework of the code */
|
|
263
|
+
detectedFramework?: string;
|
|
264
|
+
/** Detected framework version */
|
|
265
|
+
frameworkVersion?: string;
|
|
266
|
+
/** Detected CSS frameworks */
|
|
267
|
+
cssFrameworks?: Array<{ name: string; version?: string }>;
|
|
268
|
+
/** Raw API response (for debugging) */
|
|
269
|
+
response?: string;
|
|
270
|
+
/** Output format of the review */
|
|
271
|
+
outputFormat?: OutputFormat;
|
|
272
|
+
/** Project name for the review */
|
|
273
|
+
projectName?: string;
|
|
274
|
+
/** Total number of passes in multi-pass review */
|
|
275
|
+
totalPasses?: number;
|
|
276
|
+
/** Files included in the review */
|
|
277
|
+
files?: FileInfo[];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Cost information for a single pass in a multi-pass review
|
|
282
|
+
*/
|
|
283
|
+
export interface PassCost {
|
|
284
|
+
/** Pass number */
|
|
285
|
+
passNumber: number;
|
|
286
|
+
/** Input tokens for this pass */
|
|
287
|
+
inputTokens: number;
|
|
288
|
+
/** Output tokens for this pass */
|
|
289
|
+
outputTokens: number;
|
|
290
|
+
/** Total tokens for this pass */
|
|
291
|
+
totalTokens: number;
|
|
292
|
+
/** Estimated cost for this pass */
|
|
293
|
+
estimatedCost: number;
|
|
294
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module augmentation that exposes the runtime ReviewContext class to TypeScript.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
declare module '../analysis/context' {
|
|
6
|
+
export enum CodeElementType {
|
|
7
|
+
Function = 'function',
|
|
8
|
+
Class = 'class',
|
|
9
|
+
Interface = 'interface',
|
|
10
|
+
Variable = 'variable',
|
|
11
|
+
Import = 'import',
|
|
12
|
+
ExportedItem = 'exported',
|
|
13
|
+
Component = 'component',
|
|
14
|
+
EntryPoint = 'entryPoint',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CodeElement {
|
|
18
|
+
type: CodeElementType;
|
|
19
|
+
name: string;
|
|
20
|
+
file: string;
|
|
21
|
+
signature?: string;
|
|
22
|
+
importance: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ReviewFinding {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
file?: string;
|
|
29
|
+
severity: number;
|
|
30
|
+
passNumber: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FileSummary {
|
|
34
|
+
path: string;
|
|
35
|
+
type: string;
|
|
36
|
+
description: string;
|
|
37
|
+
keyElements: string[];
|
|
38
|
+
passNumber: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ReviewContext {
|
|
42
|
+
constructor(
|
|
43
|
+
projectName: string,
|
|
44
|
+
reviewType: string,
|
|
45
|
+
files: import('../types/review').FileInfo[],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
startPass(): number;
|
|
49
|
+
getCurrentPass(): number;
|
|
50
|
+
addCodeElement(element: CodeElement): void;
|
|
51
|
+
getCodeElements(): CodeElement[];
|
|
52
|
+
getCodeElementsByType(type: CodeElementType): CodeElement[];
|
|
53
|
+
getCodeElementsInFile(filePath: string): CodeElement[];
|
|
54
|
+
addFinding(finding: ReviewFinding): void;
|
|
55
|
+
getFindings(): ReviewFinding[];
|
|
56
|
+
addFileSummary(summary: FileSummary): void;
|
|
57
|
+
getFileSummary(filePath: string): FileSummary | undefined;
|
|
58
|
+
getAllFileSummaries(): FileSummary[];
|
|
59
|
+
addGeneralNote(note: string): void;
|
|
60
|
+
getGeneralNotes(): string[];
|
|
61
|
+
generateNextPassContext(files: string[], maxContextLength?: number): string;
|
|
62
|
+
toJSON(): Record<string, unknown>;
|
|
63
|
+
static fromJSON(json: Record<string, unknown>): ReviewContext;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured code review schema definitions used by cr-aia prompts and validators.
|
|
3
|
+
*
|
|
4
|
+
* We keep the TypeScript interfaces with matching Zod schemas so the runtime,
|
|
5
|
+
* validator, and prompt generator all stay in sync.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Priority level for code review issues
|
|
12
|
+
*/
|
|
13
|
+
export enum IssuePriority {
|
|
14
|
+
HIGH = 'HIGH',
|
|
15
|
+
MEDIUM = 'MEDIUM',
|
|
16
|
+
LOW = 'LOW',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Zod schema for issue priority
|
|
20
|
+
export const issuePrioritySchema = z.nativeEnum(IssuePriority);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Location of an issue in the code
|
|
24
|
+
*/
|
|
25
|
+
export interface IssueLocation {
|
|
26
|
+
startLine: number;
|
|
27
|
+
endLine: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Zod schema for issue location
|
|
31
|
+
export const issueLocationSchema = z.object({
|
|
32
|
+
startLine: z.number(),
|
|
33
|
+
endLine: z.number(),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A single issue identified in the code review
|
|
38
|
+
*/
|
|
39
|
+
export interface ReviewIssue {
|
|
40
|
+
id: string;
|
|
41
|
+
priority: IssuePriority;
|
|
42
|
+
description: string;
|
|
43
|
+
location: IssueLocation;
|
|
44
|
+
currentCode: string;
|
|
45
|
+
suggestedCode: string;
|
|
46
|
+
explanation: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Zod schema for review issue
|
|
50
|
+
export const reviewIssueSchema = z.object({
|
|
51
|
+
id: z.string(),
|
|
52
|
+
priority: issuePrioritySchema,
|
|
53
|
+
description: z.string(),
|
|
54
|
+
location: issueLocationSchema,
|
|
55
|
+
currentCode: z.string(),
|
|
56
|
+
suggestedCode: z.string(),
|
|
57
|
+
explanation: z.string(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Review results for a single file
|
|
62
|
+
*/
|
|
63
|
+
export interface FileReview {
|
|
64
|
+
filePath: string;
|
|
65
|
+
issues: ReviewIssue[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Zod schema for file review
|
|
69
|
+
export const fileReviewSchema = z.object({
|
|
70
|
+
filePath: z.string(),
|
|
71
|
+
issues: z.array(reviewIssueSchema),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Summary statistics for the code review
|
|
76
|
+
*/
|
|
77
|
+
export interface ReviewSummary {
|
|
78
|
+
highPriorityIssues: number;
|
|
79
|
+
mediumPriorityIssues: number;
|
|
80
|
+
lowPriorityIssues: number;
|
|
81
|
+
totalIssues: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Zod schema for review summary
|
|
85
|
+
export const reviewSummarySchema = z.object({
|
|
86
|
+
highPriorityIssues: z.number(),
|
|
87
|
+
mediumPriorityIssues: z.number(),
|
|
88
|
+
lowPriorityIssues: z.number(),
|
|
89
|
+
totalIssues: z.number(),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Complete code review results
|
|
94
|
+
*/
|
|
95
|
+
export interface CodeReview {
|
|
96
|
+
version: string;
|
|
97
|
+
timestamp: string;
|
|
98
|
+
files: FileReview[];
|
|
99
|
+
summary: ReviewSummary;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Zod schema for code review
|
|
103
|
+
export const codeReviewSchema = z.object({
|
|
104
|
+
version: z.string(),
|
|
105
|
+
timestamp: z.string(),
|
|
106
|
+
files: z.array(fileReviewSchema),
|
|
107
|
+
summary: reviewSummarySchema,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Root object for the code review schema
|
|
112
|
+
*/
|
|
113
|
+
export interface ReviewSchema {
|
|
114
|
+
review: CodeReview;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Zod schema for review schema
|
|
118
|
+
export const reviewSchema = z.object({
|
|
119
|
+
review: codeReviewSchema,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get the schema as a string for inclusion in prompts
|
|
124
|
+
*/
|
|
125
|
+
export function getSchemaAsString(): string {
|
|
126
|
+
return `
|
|
127
|
+
{
|
|
128
|
+
"review": {
|
|
129
|
+
"version": "1.0",
|
|
130
|
+
"timestamp": "2024-04-06T12:00:00Z",
|
|
131
|
+
"files": [
|
|
132
|
+
{
|
|
133
|
+
"filePath": "path/to/file.ts",
|
|
134
|
+
"issues": [
|
|
135
|
+
{
|
|
136
|
+
"id": "ISSUE-1",
|
|
137
|
+
"priority": "HIGH",
|
|
138
|
+
"description": "Description of the issue",
|
|
139
|
+
"location": {
|
|
140
|
+
"startLine": 10,
|
|
141
|
+
"endLine": 15
|
|
142
|
+
},
|
|
143
|
+
"currentCode": "function example() {\\n // Problematic code here\\n}",
|
|
144
|
+
"suggestedCode": "function example() {\\n // Improved code here\\n}",
|
|
145
|
+
"explanation": "Detailed explanation of why this change is recommended"
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"summary": {
|
|
151
|
+
"highPriorityIssues": 1,
|
|
152
|
+
"mediumPriorityIssues": 2,
|
|
153
|
+
"lowPriorityIssues": 3,
|
|
154
|
+
"totalIssues": 6
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get schema instructions for inclusion in prompts
|
|
163
|
+
*/
|
|
164
|
+
export function getSchemaInstructions(): string {
|
|
165
|
+
return `
|
|
166
|
+
IMPORTANT: In interactive mode, you MUST format your response as a valid JSON object following this exact schema:
|
|
167
|
+
|
|
168
|
+
${getSchemaAsString()}
|
|
169
|
+
|
|
170
|
+
Guidelines for filling the schema:
|
|
171
|
+
1. Each issue must have a unique ID (e.g., "ISSUE-1", "ISSUE-2")
|
|
172
|
+
2. Priority must be one of: "HIGH", "MEDIUM", "LOW"
|
|
173
|
+
3. Location should include the start and end line numbers of the affected code
|
|
174
|
+
4. Current code should be the exact code snippet that needs to be changed
|
|
175
|
+
5. Suggested code should be the improved version of the code
|
|
176
|
+
6. Explanation should provide a detailed rationale for the suggested change
|
|
177
|
+
7. The summary should accurately count the number of issues by priority
|
|
178
|
+
|
|
179
|
+
Your response must be valid JSON that can be parsed programmatically. Do not include any text outside of the JSON structure.
|
|
180
|
+
`;
|
|
181
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the structured review output that cr-aia emits.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Priority levels for code review issues
|
|
7
|
+
*/
|
|
8
|
+
export type IssuePriority = 'high' | 'medium' | 'low';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Types of code review issues
|
|
12
|
+
*/
|
|
13
|
+
export type IssueType =
|
|
14
|
+
| 'bug'
|
|
15
|
+
| 'security'
|
|
16
|
+
| 'performance'
|
|
17
|
+
| 'maintainability'
|
|
18
|
+
| 'readability'
|
|
19
|
+
| 'architecture'
|
|
20
|
+
| 'best-practice'
|
|
21
|
+
| 'documentation'
|
|
22
|
+
| 'testing'
|
|
23
|
+
| 'other';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A single code review issue
|
|
27
|
+
*/
|
|
28
|
+
export interface ReviewIssue {
|
|
29
|
+
/**
|
|
30
|
+
* Title of the issue
|
|
31
|
+
*/
|
|
32
|
+
title: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Priority level of the issue
|
|
36
|
+
*/
|
|
37
|
+
priority: IssuePriority;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Type of issue
|
|
41
|
+
*/
|
|
42
|
+
type: IssueType;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* File path where the issue was found
|
|
46
|
+
*/
|
|
47
|
+
filePath: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Line number(s) where the issue was found
|
|
51
|
+
* Can be a single line number or a range (e.g., "10-15")
|
|
52
|
+
*/
|
|
53
|
+
lineNumbers?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Description of the issue
|
|
57
|
+
*/
|
|
58
|
+
description: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Code snippet showing the issue
|
|
62
|
+
*/
|
|
63
|
+
codeSnippet?: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Suggested fix for the issue
|
|
67
|
+
*/
|
|
68
|
+
suggestedFix?: string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Impact of the issue
|
|
72
|
+
*/
|
|
73
|
+
impact?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Grade level types for overall code quality
|
|
78
|
+
*/
|
|
79
|
+
export type GradeLevel =
|
|
80
|
+
| 'A+'
|
|
81
|
+
| 'A'
|
|
82
|
+
| 'A-'
|
|
83
|
+
| 'B+'
|
|
84
|
+
| 'B'
|
|
85
|
+
| 'B-'
|
|
86
|
+
| 'C+'
|
|
87
|
+
| 'C'
|
|
88
|
+
| 'C-'
|
|
89
|
+
| 'D+'
|
|
90
|
+
| 'D'
|
|
91
|
+
| 'D-'
|
|
92
|
+
| 'F';
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Code quality assessment categories
|
|
96
|
+
*/
|
|
97
|
+
export interface GradeCategories {
|
|
98
|
+
/**
|
|
99
|
+
* Code functionality grade
|
|
100
|
+
*/
|
|
101
|
+
functionality?: GradeLevel;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Code quality grade
|
|
105
|
+
*/
|
|
106
|
+
codeQuality?: GradeLevel;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Documentation grade
|
|
110
|
+
*/
|
|
111
|
+
documentation?: GradeLevel;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Testing grade
|
|
115
|
+
*/
|
|
116
|
+
testing?: GradeLevel;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Maintainability grade
|
|
120
|
+
*/
|
|
121
|
+
maintainability?: GradeLevel;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Security grade
|
|
125
|
+
*/
|
|
126
|
+
security?: GradeLevel;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Performance grade
|
|
130
|
+
*/
|
|
131
|
+
performance?: GradeLevel;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Structured code review output
|
|
136
|
+
*/
|
|
137
|
+
export interface StructuredReview {
|
|
138
|
+
/**
|
|
139
|
+
* Overall grade for the codebase
|
|
140
|
+
*/
|
|
141
|
+
grade?: GradeLevel;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Detailed grade breakdown by category
|
|
145
|
+
*/
|
|
146
|
+
gradeCategories?: GradeCategories;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Summary of the code review
|
|
150
|
+
*/
|
|
151
|
+
summary: string;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* List of issues found in the code review
|
|
155
|
+
*/
|
|
156
|
+
issues: ReviewIssue[];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* General recommendations that don't fit into specific issues
|
|
160
|
+
*/
|
|
161
|
+
recommendations?: string[];
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Positive aspects of the code
|
|
165
|
+
*/
|
|
166
|
+
positiveAspects?: string[];
|
|
167
|
+
}
|