codereview-aia 0.1.2 → 0.1.4

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 (200) hide show
  1. package/dist/analysis/static/wpPhpcsRunner.d.ts +11 -0
  2. package/dist/analysis/static/wpPhpcsRunner.js +219 -0
  3. package/dist/analysis/static/wpPhpcsRunner.js.map +1 -0
  4. package/dist/clients/implementations/openRouterClient.js +2 -2
  5. package/dist/clients/implementations/openRouterClient.js.map +1 -1
  6. package/dist/clients/openRouterClient.js +2 -2
  7. package/dist/clients/openRouterClient.js.map +1 -1
  8. package/dist/clients/utils/promptFormatter.d.ts +3 -2
  9. package/dist/clients/utils/promptFormatter.js +82 -24
  10. package/dist/clients/utils/promptFormatter.js.map +1 -1
  11. package/dist/core/ConfigurationService.d.ts +21 -0
  12. package/dist/core/ConfigurationService.js +39 -0
  13. package/dist/core/ConfigurationService.js.map +1 -1
  14. package/dist/core/handlers/FileProcessingHandler.js +5 -0
  15. package/dist/core/handlers/FileProcessingHandler.js.map +1 -1
  16. package/dist/core/reviewOrchestrator.js +61 -1
  17. package/dist/core/reviewOrchestrator.js.map +1 -1
  18. package/dist/index.d.ts +0 -1
  19. package/dist/index.js +0 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/runtime/cliEntry.js +57 -4
  22. package/dist/runtime/cliEntry.js.map +1 -1
  23. package/dist/runtime/fileCollector.d.ts +10 -1
  24. package/dist/runtime/fileCollector.js +217 -2
  25. package/dist/runtime/fileCollector.js.map +1 -1
  26. package/dist/runtime/reporting/markdownReportBuilder.d.ts +2 -0
  27. package/dist/runtime/reporting/markdownReportBuilder.js +57 -0
  28. package/dist/runtime/reporting/markdownReportBuilder.js.map +1 -1
  29. package/dist/runtime/reviewPipeline.d.ts +22 -3
  30. package/dist/runtime/reviewPipeline.js +46 -7
  31. package/dist/runtime/reviewPipeline.js.map +1 -1
  32. package/dist/runtime/runAiCodeReview.d.ts +19 -1
  33. package/dist/runtime/runAiCodeReview.js +243 -8
  34. package/dist/runtime/runAiCodeReview.js.map +1 -1
  35. package/dist/runtime/ui/RuntimeApp.js +15 -4
  36. package/dist/runtime/ui/RuntimeApp.js.map +1 -1
  37. package/dist/runtime/ui/screens/ProgressScreen.d.ts +6 -1
  38. package/dist/runtime/ui/screens/ProgressScreen.js +28 -2
  39. package/dist/runtime/ui/screens/ProgressScreen.js.map +1 -1
  40. package/dist/runtime/ui/screens/ResultsScreen.js +8 -1
  41. package/dist/runtime/ui/screens/ResultsScreen.js.map +1 -1
  42. package/dist/types/review.d.ts +60 -0
  43. package/dist/utils/detection/frameworkDetector.js +55 -0
  44. package/dist/utils/detection/frameworkDetector.js.map +1 -1
  45. package/dist/utils/promptTemplateManager.js +1 -0
  46. package/dist/utils/promptTemplateManager.js.map +1 -1
  47. package/package.json +13 -10
  48. package/.cr-aia.yml +0 -23
  49. package/.crignore +0 -0
  50. package/src/analysis/FindingsExtractor.ts +0 -431
  51. package/src/analysis/ai-detection/analyzers/BaseAnalyzer.ts +0 -267
  52. package/src/analysis/ai-detection/analyzers/DocumentationAnalyzer.ts +0 -622
  53. package/src/analysis/ai-detection/analyzers/GitHistoryAnalyzer.ts +0 -430
  54. package/src/analysis/ai-detection/core/AIDetectionEngine.ts +0 -467
  55. package/src/analysis/ai-detection/types/DetectionTypes.ts +0 -406
  56. package/src/analysis/ai-detection/utils/SubmissionConverter.ts +0 -390
  57. package/src/analysis/context/ReviewContext.ts +0 -378
  58. package/src/analysis/context/index.ts +0 -7
  59. package/src/analysis/index.ts +0 -8
  60. package/src/analysis/tokens/TokenAnalysisFormatter.ts +0 -154
  61. package/src/analysis/tokens/TokenAnalyzer.ts +0 -747
  62. package/src/analysis/tokens/index.ts +0 -8
  63. package/src/clients/base/abstractClient.ts +0 -190
  64. package/src/clients/base/httpClient.ts +0 -160
  65. package/src/clients/base/index.ts +0 -12
  66. package/src/clients/base/modelDetection.ts +0 -107
  67. package/src/clients/base/responseProcessor.ts +0 -586
  68. package/src/clients/factory/clientFactory.ts +0 -55
  69. package/src/clients/factory/index.ts +0 -8
  70. package/src/clients/implementations/index.ts +0 -8
  71. package/src/clients/implementations/openRouterClient.ts +0 -411
  72. package/src/clients/openRouterClient.ts +0 -863
  73. package/src/clients/openRouterClientWrapper.ts +0 -44
  74. package/src/clients/utils/directoryStructure.ts +0 -52
  75. package/src/clients/utils/index.ts +0 -11
  76. package/src/clients/utils/languageDetection.ts +0 -44
  77. package/src/clients/utils/promptFormatter.ts +0 -105
  78. package/src/clients/utils/promptLoader.ts +0 -53
  79. package/src/clients/utils/tokenCounter.ts +0 -297
  80. package/src/core/ApiClientSelector.ts +0 -37
  81. package/src/core/ConfigurationService.ts +0 -591
  82. package/src/core/ConsolidationService.ts +0 -423
  83. package/src/core/InteractiveDisplayManager.ts +0 -81
  84. package/src/core/OutputManager.ts +0 -275
  85. package/src/core/ReviewGenerator.ts +0 -140
  86. package/src/core/fileDiscovery.ts +0 -237
  87. package/src/core/handlers/EstimationHandler.ts +0 -104
  88. package/src/core/handlers/FileProcessingHandler.ts +0 -204
  89. package/src/core/handlers/OutputHandler.ts +0 -125
  90. package/src/core/handlers/ReviewExecutor.ts +0 -104
  91. package/src/core/reviewOrchestrator.ts +0 -333
  92. package/src/core/utils/ModelInfoUtils.ts +0 -56
  93. package/src/formatters/outputFormatter.ts +0 -62
  94. package/src/formatters/utils/IssueFormatters.ts +0 -83
  95. package/src/formatters/utils/JsonFormatter.ts +0 -77
  96. package/src/formatters/utils/MarkdownFormatters.ts +0 -609
  97. package/src/formatters/utils/MetadataFormatter.ts +0 -269
  98. package/src/formatters/utils/ModelInfoExtractor.ts +0 -115
  99. package/src/index.ts +0 -28
  100. package/src/plugins/PluginInterface.ts +0 -50
  101. package/src/plugins/PluginManager.ts +0 -126
  102. package/src/prompts/PromptManager.ts +0 -69
  103. package/src/prompts/cache/PromptCache.ts +0 -50
  104. package/src/prompts/promptText/common/variables/css-frameworks.json +0 -33
  105. package/src/prompts/promptText/common/variables/framework-versions.json +0 -45
  106. package/src/prompts/promptText/frameworks/react/comprehensive.hbs +0 -19
  107. package/src/prompts/promptText/languages/css/comprehensive.hbs +0 -18
  108. package/src/prompts/promptText/languages/generic/comprehensive.hbs +0 -20
  109. package/src/prompts/promptText/languages/html/comprehensive.hbs +0 -18
  110. package/src/prompts/promptText/languages/javascript/comprehensive.hbs +0 -18
  111. package/src/prompts/promptText/languages/python/comprehensive.hbs +0 -18
  112. package/src/prompts/promptText/languages/typescript/comprehensive.hbs +0 -18
  113. package/src/runtime/auth/service.ts +0 -58
  114. package/src/runtime/auth/session.ts +0 -103
  115. package/src/runtime/auth/types.ts +0 -11
  116. package/src/runtime/cliEntry.ts +0 -196
  117. package/src/runtime/debug/logManager.ts +0 -37
  118. package/src/runtime/errors.ts +0 -13
  119. package/src/runtime/fileCollector.ts +0 -222
  120. package/src/runtime/manifest.ts +0 -64
  121. package/src/runtime/openrouterProxy.ts +0 -45
  122. package/src/runtime/preprod/webCheck.ts +0 -104
  123. package/src/runtime/proxyConfig.ts +0 -94
  124. package/src/runtime/proxyEnvironment.ts +0 -71
  125. package/src/runtime/reportMerge.ts +0 -102
  126. package/src/runtime/reporting/markdownReportBuilder.ts +0 -138
  127. package/src/runtime/reporting/reportDataCollector.ts +0 -234
  128. package/src/runtime/reporting/summaryGenerator.ts +0 -86
  129. package/src/runtime/reviewPipeline.ts +0 -161
  130. package/src/runtime/runAiCodeReview.ts +0 -153
  131. package/src/runtime/runtimeConfig.ts +0 -5
  132. package/src/runtime/ui/Layout.tsx +0 -57
  133. package/src/runtime/ui/RuntimeApp.tsx +0 -233
  134. package/src/runtime/ui/inkModules.ts +0 -73
  135. package/src/runtime/ui/screens/AuthScreen.tsx +0 -128
  136. package/src/runtime/ui/screens/ModeSelection.tsx +0 -185
  137. package/src/runtime/ui/screens/ProgressScreen.tsx +0 -62
  138. package/src/runtime/ui/screens/ResultsScreen.tsx +0 -83
  139. package/src/strategies/ArchitecturalReviewStrategy.ts +0 -54
  140. package/src/strategies/CodingTestReviewStrategy.ts +0 -920
  141. package/src/strategies/ConsolidatedReviewStrategy.ts +0 -59
  142. package/src/strategies/ExtractPatternsReviewStrategy.ts +0 -64
  143. package/src/strategies/MultiPassReviewStrategy.ts +0 -785
  144. package/src/strategies/ReviewStrategy.ts +0 -64
  145. package/src/strategies/StrategyFactory.ts +0 -79
  146. package/src/strategies/index.ts +0 -14
  147. package/src/tokenizers/baseTokenizer.ts +0 -61
  148. package/src/tokenizers/gptTokenizer.ts +0 -27
  149. package/src/tokenizers/index.ts +0 -8
  150. package/src/types/apiResponses.ts +0 -40
  151. package/src/types/cli.ts +0 -24
  152. package/src/types/common.ts +0 -39
  153. package/src/types/configuration.ts +0 -201
  154. package/src/types/handlebars.d.ts +0 -5
  155. package/src/types/patch.d.ts +0 -25
  156. package/src/types/review.ts +0 -294
  157. package/src/types/reviewContext.d.ts +0 -65
  158. package/src/types/reviewSchema.ts +0 -181
  159. package/src/types/structuredReview.ts +0 -167
  160. package/src/types/tokenAnalysis.ts +0 -56
  161. package/src/utils/FileReader.ts +0 -93
  162. package/src/utils/FileWriter.ts +0 -76
  163. package/src/utils/PathGenerator.ts +0 -97
  164. package/src/utils/api/apiUtils.ts +0 -14
  165. package/src/utils/api/index.ts +0 -1
  166. package/src/utils/apiErrorHandler.ts +0 -287
  167. package/src/utils/ciDataCollector.ts +0 -252
  168. package/src/utils/codingTestConfigLoader.ts +0 -466
  169. package/src/utils/dependencies/aiDependencyAnalyzer.ts +0 -454
  170. package/src/utils/detection/frameworkDetector.ts +0 -879
  171. package/src/utils/detection/index.ts +0 -10
  172. package/src/utils/detection/projectTypeDetector.ts +0 -518
  173. package/src/utils/diagramGenerator.ts +0 -206
  174. package/src/utils/errorLogger.ts +0 -60
  175. package/src/utils/estimationUtils.ts +0 -407
  176. package/src/utils/fileFilters.ts +0 -373
  177. package/src/utils/fileSystem.ts +0 -57
  178. package/src/utils/index.ts +0 -36
  179. package/src/utils/logger.ts +0 -290
  180. package/src/utils/pathValidator.ts +0 -98
  181. package/src/utils/priorityFilter.ts +0 -59
  182. package/src/utils/projectDocs.ts +0 -189
  183. package/src/utils/promptPaths.ts +0 -29
  184. package/src/utils/promptTemplateManager.ts +0 -157
  185. package/src/utils/review/consolidateReview.ts +0 -553
  186. package/src/utils/review/fixDisplay.ts +0 -100
  187. package/src/utils/review/fixImplementation.ts +0 -61
  188. package/src/utils/review/index.ts +0 -36
  189. package/src/utils/review/interactiveProcessing.ts +0 -294
  190. package/src/utils/review/progressTracker.ts +0 -296
  191. package/src/utils/review/reviewExtraction.ts +0 -382
  192. package/src/utils/review/types.ts +0 -46
  193. package/src/utils/reviewActionHandler.ts +0 -18
  194. package/src/utils/reviewParser.ts +0 -253
  195. package/src/utils/sanitizer.ts +0 -238
  196. package/src/utils/smartFileSelector.ts +0 -255
  197. package/src/utils/templateLoader.ts +0 -514
  198. package/src/utils/treeGenerator.ts +0 -153
  199. package/tsconfig.build.json +0 -14
  200. package/tsconfig.json +0 -59
@@ -1,290 +0,0 @@
1
- /**
2
- * @fileoverview Centralized logging system for the cr-aia tool.
3
- *
4
- * This module provides a standardized logging interface with support for
5
- * different log levels, colored output, and log level control via environment
6
- * variables. It's designed to be used throughout the codebase to ensure
7
- * consistent logging behavior.
8
- */
9
-
10
- // Define log levels with numeric values for comparison
11
- export enum LogLevel {
12
- DEBUG = 0,
13
- INFO = 1,
14
- WARN = 2,
15
- ERROR = 3,
16
- NONE = 4,
17
- }
18
-
19
- // Map string log level names to enum values
20
- const LOG_LEVEL_MAP: Record<string, LogLevel> = {
21
- debug: LogLevel.DEBUG,
22
- info: LogLevel.INFO,
23
- warn: LogLevel.WARN,
24
- error: LogLevel.ERROR,
25
- none: LogLevel.NONE,
26
- };
27
-
28
- import { createWriteStream, mkdirSync, type WriteStream } from 'node:fs';
29
- import { dirname } from 'node:path';
30
-
31
- // ANSI color codes for terminal output
32
- const COLORS = {
33
- reset: '\x1b[0m',
34
- dim: '\x1b[2m',
35
- bright: '\x1b[1m',
36
- debug: '\x1b[36m', // Cyan
37
- info: '\x1b[32m', // Green
38
- warn: '\x1b[33m', // Yellow
39
- error: '\x1b[31m', // Red
40
- time: '\x1b[90m', // Gray
41
- };
42
-
43
- // Track if we're initializing to avoid circular dependencies
44
- const isInitializing = false;
45
- let logFileStream: WriteStream | null = null;
46
- let suppressConsoleOutput = false;
47
-
48
- // Get the current log level from environment variables
49
- function getCurrentLogLevel(): LogLevel {
50
- // Avoid debug logs during initialization to prevent overwhelming output
51
- const shouldLog = process.argv.includes('--trace-logger') && !isInitializing;
52
-
53
- if (shouldLog) {
54
- // Only print when explicitly requested with --trace-logger
55
- console.error(
56
- `Debug: getCurrentLogLevel called, AI_CODE_REVIEW_LOG_LEVEL=${process.env.AI_CODE_REVIEW_LOG_LEVEL}`,
57
- );
58
- }
59
-
60
- // Always check CLI flags first - highest priority
61
- if (process.argv.includes('--debug')) {
62
- if (shouldLog) {
63
- console.error('Debug: Debug flag found in process.argv, forcing DEBUG level');
64
- }
65
- return LogLevel.DEBUG;
66
- }
67
-
68
- // Next check environment variable
69
- const envLogLevel = process.env.AI_CODE_REVIEW_LOG_LEVEL?.toLowerCase();
70
-
71
- if (envLogLevel) {
72
- if (shouldLog) {
73
- console.error(`Debug: Found AI_CODE_REVIEW_LOG_LEVEL environment variable: ${envLogLevel}`);
74
- }
75
-
76
- if (envLogLevel in LOG_LEVEL_MAP) {
77
- if (shouldLog) {
78
- console.error(`Debug: Mapped log level ${envLogLevel} -> ${LOG_LEVEL_MAP[envLogLevel]}`);
79
- }
80
- return LOG_LEVEL_MAP[envLogLevel];
81
- }
82
- if (shouldLog) {
83
- console.error(
84
- `Debug: Invalid log level: ${envLogLevel}, valid options are: ${Object.keys(LOG_LEVEL_MAP).join(', ')}`,
85
- );
86
- }
87
- } else if (shouldLog) {
88
- console.error('Debug: AI_CODE_REVIEW_LOG_LEVEL environment variable not found');
89
- }
90
-
91
- // Default to INFO if not specified
92
- if (shouldLog) {
93
- console.error('Debug: No valid log level found, defaulting to INFO');
94
- }
95
- return LogLevel.INFO;
96
- }
97
-
98
- // The current log level
99
- let currentLogLevel = getCurrentLogLevel();
100
-
101
- /**
102
- * Set the current log level
103
- * @param level The log level to set
104
- */
105
- export function setLogLevel(level: LogLevel | string): void {
106
- // Only log when explicitly requested with --trace-logger
107
- const shouldLog = process.argv.includes('--trace-logger');
108
-
109
- if (shouldLog) {
110
- console.error(`Debug: setLogLevel called with ${level}`);
111
- }
112
-
113
- if (typeof level === 'string') {
114
- const levelLower = level.toLowerCase();
115
- if (levelLower in LOG_LEVEL_MAP) {
116
- currentLogLevel = LOG_LEVEL_MAP[levelLower];
117
- if (shouldLog) {
118
- console.error(`Debug: Log level set to ${levelLower} -> ${currentLogLevel}`);
119
- }
120
- } else {
121
- console.warn(`Invalid log level: ${level}. Using default.`);
122
- }
123
- } else {
124
- currentLogLevel = level;
125
- if (shouldLog) {
126
- console.error(`Debug: Log level set to numeric value ${level}`);
127
- }
128
- }
129
- }
130
-
131
- /**
132
- * Get the current log level
133
- * @returns The current log level
134
- */
135
- export function getLogLevel(): LogLevel {
136
- return currentLogLevel;
137
- }
138
-
139
- function formatConsoleMessage(level: string, message: string, timestamp: string): string {
140
- const levelUpper = level.toUpperCase().padEnd(5);
141
- return `${COLORS.time}[${timestamp}]${COLORS.reset} ${COLORS[level as keyof typeof COLORS]}${levelUpper}${COLORS.reset} ${message}`;
142
- }
143
-
144
- function formatFileMessage(level: string, message: string, timestamp: string, args: any[]): string {
145
- const levelUpper = level.toUpperCase().padEnd(5);
146
- const extras = args.length ? ` ${args.map((arg) => serializeLogArg(arg)).join(' ')}` : '';
147
- return `[${timestamp}] ${levelUpper} ${message}${extras}`;
148
- }
149
-
150
- function serializeLogArg(arg: unknown): string {
151
- if (typeof arg === 'string') {
152
- return arg;
153
- }
154
- if (arg instanceof Error) {
155
- return arg.stack || arg.message;
156
- }
157
- try {
158
- return JSON.stringify(arg);
159
- } catch {
160
- return String(arg);
161
- }
162
- }
163
-
164
- export function enableFileLogging(filePath: string, options?: { suppressConsole?: boolean }): void {
165
- try {
166
- mkdirSync(dirname(filePath), { recursive: true });
167
- if (logFileStream) {
168
- logFileStream.end();
169
- }
170
- logFileStream = createWriteStream(filePath, { flags: 'a' });
171
- suppressConsoleOutput = options?.suppressConsole ?? true;
172
- } catch (error) {
173
- console.error('Failed to enable file logging:', error);
174
- logFileStream = null;
175
- suppressConsoleOutput = false;
176
- }
177
- }
178
-
179
- export function disableFileLogging(): void {
180
- if (logFileStream) {
181
- logFileStream.end();
182
- logFileStream = null;
183
- }
184
- suppressConsoleOutput = false;
185
- }
186
-
187
- /**
188
- * Log a message if the current log level allows it
189
- * @param level The log level
190
- * @param message The message to log
191
- * @param args Additional arguments to log
192
- */
193
- function log(level: LogLevel, levelName: string, message: string, ...args: any[]): void {
194
- const timestamp = new Date().toISOString();
195
-
196
- if (logFileStream) {
197
- logFileStream.write(`${formatFileMessage(levelName, message, timestamp, args)}\n`);
198
- }
199
-
200
- const shouldLogToConsole = !suppressConsoleOutput && level >= currentLogLevel;
201
-
202
- if (shouldLogToConsole) {
203
- const formattedMessage = formatConsoleMessage(levelName, message, timestamp);
204
-
205
- switch (level) {
206
- case LogLevel.DEBUG:
207
- console.debug(formattedMessage, ...args);
208
- break;
209
- case LogLevel.INFO:
210
- console.log(formattedMessage, ...args);
211
- break;
212
- case LogLevel.WARN:
213
- console.warn(formattedMessage, ...args);
214
- break;
215
- case LogLevel.ERROR:
216
- console.error(formattedMessage, ...args);
217
- break;
218
- default:
219
- break;
220
- }
221
- } else if (!suppressConsoleOutput && level === LogLevel.DEBUG && process.argv.includes('--trace-logger')) {
222
- console.error(
223
- `Suppressing DEBUG log because currentLogLevel=${currentLogLevel}, message was: ${message}`,
224
- );
225
- }
226
- }
227
-
228
- /**
229
- * Log a debug message
230
- * @param message The message to log
231
- * @param args Additional arguments to log
232
- */
233
- export function debug(message: string, ...args: any[]): void {
234
- log(LogLevel.DEBUG, 'debug', message, ...args);
235
- }
236
-
237
- /**
238
- * Log an info message
239
- * @param message The message to log
240
- * @param args Additional arguments to log
241
- */
242
- export function info(message: string, ...args: any[]): void {
243
- log(LogLevel.INFO, 'info', message, ...args);
244
- }
245
-
246
- /**
247
- * Log a warning message
248
- * @param message The message to log
249
- * @param args Additional arguments to log
250
- */
251
- export function warn(message: string, ...args: any[]): void {
252
- log(LogLevel.WARN, 'warn', message, ...args);
253
- }
254
-
255
- /**
256
- * Log an error message
257
- * @param message The message to log
258
- * @param args Additional arguments to log
259
- */
260
- export function error(message: string, ...args: any[]): void {
261
- log(LogLevel.ERROR, 'error', message, ...args);
262
- }
263
-
264
- /**
265
- * Create a logger instance with a specific prefix
266
- * @param prefix The prefix to add to all log messages
267
- * @returns An object with debug, info, warn, and error methods
268
- */
269
- export function createLogger(prefix: string) {
270
- return {
271
- debug: (message: string, ...args: any[]) => debug(`[${prefix}] ${message}`, ...args),
272
- info: (message: string, ...args: any[]) => info(`[${prefix}] ${message}`, ...args),
273
- warn: (message: string, ...args: any[]) => warn(`[${prefix}] ${message}`, ...args),
274
- error: (message: string, ...args: any[]) => error(`[${prefix}] ${message}`, ...args),
275
- };
276
- }
277
-
278
- // Export a default logger instance
279
- export default {
280
- debug,
281
- info,
282
- warn,
283
- error,
284
- setLogLevel,
285
- getLogLevel,
286
- createLogger,
287
- LogLevel,
288
- enableFileLogging,
289
- disableFileLogging,
290
- };
@@ -1,98 +0,0 @@
1
- /**
2
- * @fileoverview Path validation utilities.
3
- *
4
- * This module provides utilities for validating file and directory paths,
5
- * ensuring they are safe to use and exist on the file system.
6
- */
7
-
8
- import fs from 'node:fs';
9
- import path from 'node:path';
10
-
11
- /**
12
- * Check if a path is within the current directory or its subdirectories
13
- * @param targetPath Path to check
14
- * @returns True if the path is within the current directory, false otherwise
15
- */
16
- export function isPathWithinCwd(targetPath: string): boolean {
17
- const resolvedPath = path.resolve(targetPath);
18
- const resolvedCwd = path.resolve(process.cwd());
19
-
20
- return resolvedPath.startsWith(resolvedCwd);
21
- }
22
-
23
- /**
24
- * Check if a path exists
25
- * @param targetPath Path to check
26
- * @returns True if the path exists, false otherwise
27
- */
28
- export function pathExists(targetPath: string): boolean {
29
- try {
30
- fs.accessSync(targetPath);
31
- return true;
32
- } catch (_error) {
33
- return false;
34
- }
35
- }
36
-
37
- /**
38
- * Check if a path is a directory
39
- * @param targetPath Path to check
40
- * @returns True if the path is a directory, false otherwise
41
- */
42
- export function isDirectory(targetPath: string): boolean {
43
- try {
44
- return fs.statSync(targetPath).isDirectory();
45
- } catch (_error) {
46
- return false;
47
- }
48
- }
49
-
50
- /**
51
- * Check if a path is a file
52
- * @param targetPath Path to check
53
- * @returns True if the path is a file, false otherwise
54
- */
55
- export function isFile(targetPath: string): boolean {
56
- try {
57
- return fs.statSync(targetPath).isFile();
58
- } catch (_error) {
59
- return false;
60
- }
61
- }
62
-
63
- /**
64
- * Validate a target path for security and existence
65
- * @param targetPath Path to validate
66
- * @returns Object with validation results
67
- */
68
- export function validateTargetPath(targetPath: string): {
69
- isValid: boolean;
70
- isDir: boolean;
71
- error?: string;
72
- } {
73
- // Check if the path is within the current directory
74
- if (!isPathWithinCwd(targetPath)) {
75
- return {
76
- isValid: false,
77
- isDir: false,
78
- error: `Path must be within the current directory: ${process.cwd()}`,
79
- };
80
- }
81
-
82
- // Check if the path exists
83
- if (!pathExists(targetPath)) {
84
- return {
85
- isValid: false,
86
- isDir: false,
87
- error: `Path does not exist: ${targetPath}`,
88
- };
89
- }
90
-
91
- // Check if the path is a directory or file
92
- const isDir = isDirectory(targetPath);
93
-
94
- return {
95
- isValid: true,
96
- isDir,
97
- };
98
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * @fileoverview Utility functions for handling priority filters.
3
- *
4
- * This module provides utility functions for working with priority filters
5
- * in interactive mode, including extracting priority filters from command line
6
- * arguments and review options.
7
- */
8
-
9
- import type { ReviewOptions } from '../types/review';
10
- import type { PriorityFilter } from '../types/common';
11
-
12
- /**
13
- * Get the priority filter from command line arguments or options
14
- *
15
- * This function extracts the priority filter from either:
16
- * 1. The options object (if the interactive property is a string)
17
- * 2. The command line arguments (if --interactive or -i is followed by a priority filter)
18
- *
19
- * Priority filters determine which issues to display in interactive mode:
20
- * - 'h': High priority issues only
21
- * - 'm': Medium and high priority issues
22
- * - 'l': Low, medium, and high priority issues
23
- * - 'a': All issues (including informational)
24
- *
25
- * @param options Review options that may contain the priority filter
26
- * @returns The priority filter (h, m, l, or a) or undefined if not specified
27
- * @example
28
- * // With options object
29
- * const filter = getPriorityFilterFromArgs({ interactive: 'h' });
30
- * // filter === 'h'
31
- *
32
- * // With command line arguments (if process.argv includes '--interactive h')
33
- * const filter = getPriorityFilterFromArgs();
34
- * // filter === 'h'
35
- */
36
- export function getPriorityFilterFromArgs(options?: ReviewOptions): PriorityFilter | undefined {
37
- // First check if the interactive option is a string (priority filter)
38
- if (
39
- options &&
40
- typeof options.interactive === 'string' &&
41
- ['h', 'm', 'l', 'a'].includes(options.interactive)
42
- ) {
43
- return options.interactive as PriorityFilter;
44
- }
45
-
46
- // Otherwise check if there's a priority filter argument after --interactive
47
- const args = process.argv;
48
- const interactiveIndex = args.findIndex((arg) => arg === '--interactive' || arg === '-i');
49
-
50
- if (interactiveIndex !== -1 && interactiveIndex < args.length - 1) {
51
- const nextArg = args[interactiveIndex + 1];
52
- // Check if the next argument is a priority filter and not another option
53
- if (['h', 'm', 'l', 'a'].includes(nextArg) && !nextArg.startsWith('-')) {
54
- return nextArg as PriorityFilter;
55
- }
56
- }
57
-
58
- return undefined;
59
- }
@@ -1,189 +0,0 @@
1
- /**
2
- * @fileoverview Utilities for reading and processing project documentation.
3
- *
4
- * This module provides functionality for reading and processing project documentation
5
- * files like README.md, PROJECT.md, and PROGRESS.md. These files provide important
6
- * context for code reviews, helping the AI model understand the project's purpose,
7
- * structure, and current state.
8
- */
9
-
10
- import fs from 'node:fs/promises';
11
- import path from 'node:path';
12
- import { fileExists } from './fileSystem';
13
- import logger from './logger';
14
-
15
- /**
16
- * Project documentation interface
17
- */
18
- export interface ProjectDocs {
19
- readme?: string;
20
- project?: string;
21
- progress?: string;
22
- contributing?: string;
23
- architecture?: string;
24
- custom?: Record<string, string>;
25
- metadata?: Record<string, string>;
26
- }
27
-
28
- /**
29
- * Maximum size for documentation files (in characters)
30
- * This helps prevent token limit issues
31
- */
32
- const MAX_DOC_SIZE = 50000;
33
-
34
- /**
35
- * Read a documentation file if it exists
36
- * @param filePath File path
37
- * @returns File content or undefined if the file doesn't exist
38
- */
39
- async function readDocFile(filePath: string): Promise<string | undefined> {
40
- try {
41
- if (await fileExists(filePath)) {
42
- const content = await fs.readFile(filePath, 'utf-8');
43
-
44
- // Truncate if too large
45
- if (content.length > MAX_DOC_SIZE) {
46
- logger.warn(
47
- `Documentation file ${filePath} is too large, truncating to ${MAX_DOC_SIZE} characters.`,
48
- );
49
- return `${content.substring(0, MAX_DOC_SIZE)}\n\n[Content truncated due to size]`;
50
- }
51
-
52
- return content;
53
- }
54
- } catch (error) {
55
- logger.warn(`Error reading documentation file ${filePath}:`, error);
56
- }
57
-
58
- return undefined;
59
- }
60
-
61
- /**
62
- * Read project documentation files
63
- * @param projectDir Project directory
64
- * @returns Project documentation
65
- */
66
- export async function readProjectDocs(projectDir: string): Promise<ProjectDocs> {
67
- const docs: ProjectDocs = {
68
- custom: {},
69
- };
70
-
71
- // Read standard documentation files
72
- docs.readme = await readDocFile(path.join(projectDir, 'README.md'));
73
- docs.project = await readDocFile(path.join(projectDir, 'PROJECT.md'));
74
- docs.progress = await readDocFile(path.join(projectDir, 'PROGRESS.md'));
75
- docs.contributing = await readDocFile(path.join(projectDir, 'CONTRIBUTING.md'));
76
- docs.architecture = await readDocFile(path.join(projectDir, 'ARCHITECTURE.md'));
77
-
78
- // Read custom documentation files from the docs directory
79
- try {
80
- const docsDir = path.join(projectDir, 'docs');
81
- if (await fileExists(docsDir)) {
82
- const files = await fs.readdir(docsDir);
83
-
84
- for (const file of files) {
85
- if (file.endsWith('.md')) {
86
- const filePath = path.join(docsDir, file);
87
- const content = await readDocFile(filePath);
88
-
89
- if (content) {
90
- docs.custom![file] = content;
91
- }
92
- }
93
- }
94
- }
95
- } catch (error) {
96
- logger.warn('Error reading docs directory:', error);
97
- }
98
-
99
- return docs;
100
- }
101
-
102
- /**
103
- * Add metadata to project documentation
104
- * @param docs Project documentation object
105
- * @param key Metadata key
106
- * @param value Metadata value
107
- * @returns Project documentation with added metadata
108
- */
109
- export function addMetadataToProjectDocs(
110
- docs: ProjectDocs,
111
- key: string,
112
- value: string,
113
- ): ProjectDocs {
114
- if (!docs.metadata) {
115
- docs.metadata = {};
116
- }
117
- docs.metadata[key] = value;
118
- return docs;
119
- }
120
-
121
- /**
122
- * Format project documentation for inclusion in prompts
123
- * @param docs Project documentation
124
- * @returns Formatted documentation string
125
- */
126
- export function formatProjectDocs(docs: ProjectDocs): string {
127
- const sections: string[] = [];
128
-
129
- if (docs.readme) {
130
- sections.push(`# README.md\n\n${docs.readme}`);
131
- }
132
-
133
- if (docs.project) {
134
- sections.push(`# PROJECT.md\n\n${docs.project}`);
135
- }
136
-
137
- if (docs.architecture) {
138
- sections.push(`# ARCHITECTURE.md\n\n${docs.architecture}`);
139
- }
140
-
141
- if (docs.progress) {
142
- sections.push(`# PROGRESS.md\n\n${docs.progress}`);
143
- }
144
-
145
- if (docs.contributing) {
146
- sections.push(`# CONTRIBUTING.md\n\n${docs.contributing}`);
147
- }
148
-
149
- // Add custom documentation files
150
- if (docs.custom) {
151
- for (const [file, content] of Object.entries(docs.custom)) {
152
- sections.push(`# docs/${file}\n\n${content}`);
153
- }
154
- }
155
-
156
- // Add metadata if present
157
- if (docs.metadata) {
158
- for (const [key, content] of Object.entries(docs.metadata)) {
159
- // Format the metadata section
160
- const title = key.charAt(0).toUpperCase() + key.slice(1).replace(/([A-Z])/g, ' $1');
161
- sections.push(`# ${title}\n\n${content}`);
162
- }
163
- }
164
-
165
- if (sections.length === 0) {
166
- return '';
167
- }
168
-
169
- return `## Project Documentation\n\n${sections.join('\n\n---\n\n')}`;
170
- }
171
-
172
- /**
173
- * Add project documentation to a prompt
174
- * @param prompt The prompt to add documentation to
175
- * @param docs Project documentation object
176
- * @returns The prompt with documentation added
177
- */
178
- export function addProjectDocsToPrompt(prompt: string, docs: ProjectDocs): string {
179
- const docsText = formatProjectDocs(docs);
180
- if (docsText) {
181
- // Try to replace a placeholder if it exists
182
- if (prompt.includes('{{PROJECT_DOCS}}')) {
183
- return prompt.replace('{{PROJECT_DOCS}}', docsText);
184
- }
185
- // Otherwise, append to the end
186
- return `${prompt}\n\n${docsText}`;
187
- }
188
- return prompt;
189
- }
@@ -1,29 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- /**
5
- * Resolve the directory that contains the compiled prompt templates.
6
- * The location varies depending on whether we're running from source,
7
- * the compiled dist output, or an older workspace layout.
8
- */
9
- export function resolvePromptTemplatesDir(): string {
10
- const candidates = [
11
- // When running via ts-node from the src tree
12
- path.resolve(__dirname, '..', 'prompts', 'promptText'),
13
- // When running compiled code while keeping src in the package
14
- path.resolve(__dirname, '..', '..', 'src', 'prompts', 'promptText'),
15
- // When executing directly from the repo root
16
- path.resolve(process.cwd(), 'src', 'prompts', 'promptText'),
17
- // Legacy location used before the prompts lived under src/
18
- path.resolve(process.cwd(), 'promptText'),
19
- ];
20
-
21
- for (const candidate of candidates) {
22
- if (fs.existsSync(candidate)) {
23
- return candidate;
24
- }
25
- }
26
-
27
- // Fall back to the first option so callers always receive a deterministic path.
28
- return candidates[0];
29
- }