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.
- package/dist/analysis/static/wpPhpcsRunner.d.ts +11 -0
- package/dist/analysis/static/wpPhpcsRunner.js +219 -0
- package/dist/analysis/static/wpPhpcsRunner.js.map +1 -0
- package/dist/clients/implementations/openRouterClient.js +2 -2
- package/dist/clients/implementations/openRouterClient.js.map +1 -1
- package/dist/clients/openRouterClient.js +2 -2
- package/dist/clients/openRouterClient.js.map +1 -1
- package/dist/clients/utils/promptFormatter.d.ts +3 -2
- package/dist/clients/utils/promptFormatter.js +82 -24
- package/dist/clients/utils/promptFormatter.js.map +1 -1
- package/dist/core/ConfigurationService.d.ts +21 -0
- package/dist/core/ConfigurationService.js +39 -0
- package/dist/core/ConfigurationService.js.map +1 -1
- package/dist/core/handlers/FileProcessingHandler.js +5 -0
- package/dist/core/handlers/FileProcessingHandler.js.map +1 -1
- package/dist/core/reviewOrchestrator.js +61 -1
- package/dist/core/reviewOrchestrator.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/cliEntry.js +57 -4
- package/dist/runtime/cliEntry.js.map +1 -1
- package/dist/runtime/fileCollector.d.ts +10 -1
- package/dist/runtime/fileCollector.js +217 -2
- package/dist/runtime/fileCollector.js.map +1 -1
- package/dist/runtime/reporting/markdownReportBuilder.d.ts +2 -0
- package/dist/runtime/reporting/markdownReportBuilder.js +57 -0
- package/dist/runtime/reporting/markdownReportBuilder.js.map +1 -1
- package/dist/runtime/reviewPipeline.d.ts +22 -3
- package/dist/runtime/reviewPipeline.js +46 -7
- package/dist/runtime/reviewPipeline.js.map +1 -1
- package/dist/runtime/runAiCodeReview.d.ts +19 -1
- package/dist/runtime/runAiCodeReview.js +243 -8
- package/dist/runtime/runAiCodeReview.js.map +1 -1
- package/dist/runtime/ui/RuntimeApp.js +15 -4
- package/dist/runtime/ui/RuntimeApp.js.map +1 -1
- package/dist/runtime/ui/screens/ProgressScreen.d.ts +6 -1
- package/dist/runtime/ui/screens/ProgressScreen.js +28 -2
- package/dist/runtime/ui/screens/ProgressScreen.js.map +1 -1
- package/dist/runtime/ui/screens/ResultsScreen.js +8 -1
- package/dist/runtime/ui/screens/ResultsScreen.js.map +1 -1
- package/dist/types/review.d.ts +60 -0
- package/dist/utils/detection/frameworkDetector.js +55 -0
- package/dist/utils/detection/frameworkDetector.js.map +1 -1
- package/dist/utils/promptTemplateManager.js +1 -0
- package/dist/utils/promptTemplateManager.js.map +1 -1
- package/package.json +13 -10
- package/.cr-aia.yml +0 -23
- package/.crignore +0 -0
- package/src/analysis/FindingsExtractor.ts +0 -431
- package/src/analysis/ai-detection/analyzers/BaseAnalyzer.ts +0 -267
- package/src/analysis/ai-detection/analyzers/DocumentationAnalyzer.ts +0 -622
- package/src/analysis/ai-detection/analyzers/GitHistoryAnalyzer.ts +0 -430
- package/src/analysis/ai-detection/core/AIDetectionEngine.ts +0 -467
- package/src/analysis/ai-detection/types/DetectionTypes.ts +0 -406
- package/src/analysis/ai-detection/utils/SubmissionConverter.ts +0 -390
- package/src/analysis/context/ReviewContext.ts +0 -378
- package/src/analysis/context/index.ts +0 -7
- package/src/analysis/index.ts +0 -8
- package/src/analysis/tokens/TokenAnalysisFormatter.ts +0 -154
- package/src/analysis/tokens/TokenAnalyzer.ts +0 -747
- package/src/analysis/tokens/index.ts +0 -8
- package/src/clients/base/abstractClient.ts +0 -190
- package/src/clients/base/httpClient.ts +0 -160
- package/src/clients/base/index.ts +0 -12
- package/src/clients/base/modelDetection.ts +0 -107
- package/src/clients/base/responseProcessor.ts +0 -586
- package/src/clients/factory/clientFactory.ts +0 -55
- package/src/clients/factory/index.ts +0 -8
- package/src/clients/implementations/index.ts +0 -8
- package/src/clients/implementations/openRouterClient.ts +0 -411
- package/src/clients/openRouterClient.ts +0 -863
- package/src/clients/openRouterClientWrapper.ts +0 -44
- package/src/clients/utils/directoryStructure.ts +0 -52
- package/src/clients/utils/index.ts +0 -11
- package/src/clients/utils/languageDetection.ts +0 -44
- package/src/clients/utils/promptFormatter.ts +0 -105
- package/src/clients/utils/promptLoader.ts +0 -53
- package/src/clients/utils/tokenCounter.ts +0 -297
- package/src/core/ApiClientSelector.ts +0 -37
- package/src/core/ConfigurationService.ts +0 -591
- package/src/core/ConsolidationService.ts +0 -423
- package/src/core/InteractiveDisplayManager.ts +0 -81
- package/src/core/OutputManager.ts +0 -275
- package/src/core/ReviewGenerator.ts +0 -140
- package/src/core/fileDiscovery.ts +0 -237
- package/src/core/handlers/EstimationHandler.ts +0 -104
- package/src/core/handlers/FileProcessingHandler.ts +0 -204
- package/src/core/handlers/OutputHandler.ts +0 -125
- package/src/core/handlers/ReviewExecutor.ts +0 -104
- package/src/core/reviewOrchestrator.ts +0 -333
- package/src/core/utils/ModelInfoUtils.ts +0 -56
- package/src/formatters/outputFormatter.ts +0 -62
- package/src/formatters/utils/IssueFormatters.ts +0 -83
- package/src/formatters/utils/JsonFormatter.ts +0 -77
- package/src/formatters/utils/MarkdownFormatters.ts +0 -609
- package/src/formatters/utils/MetadataFormatter.ts +0 -269
- package/src/formatters/utils/ModelInfoExtractor.ts +0 -115
- package/src/index.ts +0 -28
- package/src/plugins/PluginInterface.ts +0 -50
- package/src/plugins/PluginManager.ts +0 -126
- package/src/prompts/PromptManager.ts +0 -69
- package/src/prompts/cache/PromptCache.ts +0 -50
- package/src/prompts/promptText/common/variables/css-frameworks.json +0 -33
- package/src/prompts/promptText/common/variables/framework-versions.json +0 -45
- package/src/prompts/promptText/frameworks/react/comprehensive.hbs +0 -19
- package/src/prompts/promptText/languages/css/comprehensive.hbs +0 -18
- package/src/prompts/promptText/languages/generic/comprehensive.hbs +0 -20
- package/src/prompts/promptText/languages/html/comprehensive.hbs +0 -18
- package/src/prompts/promptText/languages/javascript/comprehensive.hbs +0 -18
- package/src/prompts/promptText/languages/python/comprehensive.hbs +0 -18
- package/src/prompts/promptText/languages/typescript/comprehensive.hbs +0 -18
- package/src/runtime/auth/service.ts +0 -58
- package/src/runtime/auth/session.ts +0 -103
- package/src/runtime/auth/types.ts +0 -11
- package/src/runtime/cliEntry.ts +0 -196
- package/src/runtime/debug/logManager.ts +0 -37
- package/src/runtime/errors.ts +0 -13
- package/src/runtime/fileCollector.ts +0 -222
- package/src/runtime/manifest.ts +0 -64
- package/src/runtime/openrouterProxy.ts +0 -45
- package/src/runtime/preprod/webCheck.ts +0 -104
- package/src/runtime/proxyConfig.ts +0 -94
- package/src/runtime/proxyEnvironment.ts +0 -71
- package/src/runtime/reportMerge.ts +0 -102
- package/src/runtime/reporting/markdownReportBuilder.ts +0 -138
- package/src/runtime/reporting/reportDataCollector.ts +0 -234
- package/src/runtime/reporting/summaryGenerator.ts +0 -86
- package/src/runtime/reviewPipeline.ts +0 -161
- package/src/runtime/runAiCodeReview.ts +0 -153
- package/src/runtime/runtimeConfig.ts +0 -5
- package/src/runtime/ui/Layout.tsx +0 -57
- package/src/runtime/ui/RuntimeApp.tsx +0 -233
- package/src/runtime/ui/inkModules.ts +0 -73
- package/src/runtime/ui/screens/AuthScreen.tsx +0 -128
- package/src/runtime/ui/screens/ModeSelection.tsx +0 -185
- package/src/runtime/ui/screens/ProgressScreen.tsx +0 -62
- package/src/runtime/ui/screens/ResultsScreen.tsx +0 -83
- package/src/strategies/ArchitecturalReviewStrategy.ts +0 -54
- package/src/strategies/CodingTestReviewStrategy.ts +0 -920
- package/src/strategies/ConsolidatedReviewStrategy.ts +0 -59
- package/src/strategies/ExtractPatternsReviewStrategy.ts +0 -64
- package/src/strategies/MultiPassReviewStrategy.ts +0 -785
- package/src/strategies/ReviewStrategy.ts +0 -64
- package/src/strategies/StrategyFactory.ts +0 -79
- package/src/strategies/index.ts +0 -14
- package/src/tokenizers/baseTokenizer.ts +0 -61
- package/src/tokenizers/gptTokenizer.ts +0 -27
- package/src/tokenizers/index.ts +0 -8
- package/src/types/apiResponses.ts +0 -40
- package/src/types/cli.ts +0 -24
- package/src/types/common.ts +0 -39
- package/src/types/configuration.ts +0 -201
- package/src/types/handlebars.d.ts +0 -5
- package/src/types/patch.d.ts +0 -25
- package/src/types/review.ts +0 -294
- package/src/types/reviewContext.d.ts +0 -65
- package/src/types/reviewSchema.ts +0 -181
- package/src/types/structuredReview.ts +0 -167
- package/src/types/tokenAnalysis.ts +0 -56
- package/src/utils/FileReader.ts +0 -93
- package/src/utils/FileWriter.ts +0 -76
- package/src/utils/PathGenerator.ts +0 -97
- package/src/utils/api/apiUtils.ts +0 -14
- package/src/utils/api/index.ts +0 -1
- package/src/utils/apiErrorHandler.ts +0 -287
- package/src/utils/ciDataCollector.ts +0 -252
- package/src/utils/codingTestConfigLoader.ts +0 -466
- package/src/utils/dependencies/aiDependencyAnalyzer.ts +0 -454
- package/src/utils/detection/frameworkDetector.ts +0 -879
- package/src/utils/detection/index.ts +0 -10
- package/src/utils/detection/projectTypeDetector.ts +0 -518
- package/src/utils/diagramGenerator.ts +0 -206
- package/src/utils/errorLogger.ts +0 -60
- package/src/utils/estimationUtils.ts +0 -407
- package/src/utils/fileFilters.ts +0 -373
- package/src/utils/fileSystem.ts +0 -57
- package/src/utils/index.ts +0 -36
- package/src/utils/logger.ts +0 -290
- package/src/utils/pathValidator.ts +0 -98
- package/src/utils/priorityFilter.ts +0 -59
- package/src/utils/projectDocs.ts +0 -189
- package/src/utils/promptPaths.ts +0 -29
- package/src/utils/promptTemplateManager.ts +0 -157
- package/src/utils/review/consolidateReview.ts +0 -553
- package/src/utils/review/fixDisplay.ts +0 -100
- package/src/utils/review/fixImplementation.ts +0 -61
- package/src/utils/review/index.ts +0 -36
- package/src/utils/review/interactiveProcessing.ts +0 -294
- package/src/utils/review/progressTracker.ts +0 -296
- package/src/utils/review/reviewExtraction.ts +0 -382
- package/src/utils/review/types.ts +0 -46
- package/src/utils/reviewActionHandler.ts +0 -18
- package/src/utils/reviewParser.ts +0 -253
- package/src/utils/sanitizer.ts +0 -238
- package/src/utils/smartFileSelector.ts +0 -255
- package/src/utils/templateLoader.ts +0 -514
- package/src/utils/treeGenerator.ts +0 -153
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -59
package/src/utils/fileFilters.ts
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Utilities for filtering and selecting files for code review.
|
|
3
|
-
*
|
|
4
|
-
* This module provides functions for identifying, filtering, and selecting files
|
|
5
|
-
* for code review based on various criteria. It handles file discovery, gitignore
|
|
6
|
-
* pattern matching, file extension filtering, and test file identification.
|
|
7
|
-
* Supported file types include TypeScript, JavaScript, JSON, and Markdown.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import fs from 'node:fs/promises';
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
import type { FileInfo } from '../types/review';
|
|
13
|
-
import logger from './logger';
|
|
14
|
-
|
|
15
|
-
// import { promises as fsPromises } from 'fs'; // TODO: Remove if not needed
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Supported file extensions for code review - focus on executable code only
|
|
19
|
-
* Exclude non-executable files like .md, .txt, .log, .tgz, .json, and .svg
|
|
20
|
-
*/
|
|
21
|
-
const SUPPORTED_EXTENSIONS = [
|
|
22
|
-
'.ts',
|
|
23
|
-
'.tsx',
|
|
24
|
-
'.js',
|
|
25
|
-
'.jsx',
|
|
26
|
-
'.py',
|
|
27
|
-
'.pyc',
|
|
28
|
-
'.pyi',
|
|
29
|
-
'.pyx',
|
|
30
|
-
'.pyd',
|
|
31
|
-
'.php',
|
|
32
|
-
'.java',
|
|
33
|
-
'.rb',
|
|
34
|
-
'.rake',
|
|
35
|
-
'.gemspec',
|
|
36
|
-
'.ru',
|
|
37
|
-
'.erb',
|
|
38
|
-
'.go',
|
|
39
|
-
'.rs',
|
|
40
|
-
'.c',
|
|
41
|
-
'.cpp',
|
|
42
|
-
'.h',
|
|
43
|
-
'.hpp',
|
|
44
|
-
'.cs',
|
|
45
|
-
'.swift',
|
|
46
|
-
'.kt',
|
|
47
|
-
'.dart',
|
|
48
|
-
];
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Check if a file is a test file
|
|
52
|
-
* @param filePath File path
|
|
53
|
-
* @returns True if the file is a test file
|
|
54
|
-
*/
|
|
55
|
-
export function isTestFile(filePath: string): boolean {
|
|
56
|
-
const fileName = path.basename(filePath);
|
|
57
|
-
return (
|
|
58
|
-
fileName.includes('.test.') ||
|
|
59
|
-
fileName.includes('.spec.') ||
|
|
60
|
-
fileName.startsWith('test-') ||
|
|
61
|
-
fileName.endsWith('.test.ts') ||
|
|
62
|
-
fileName.endsWith('.test.js') ||
|
|
63
|
-
fileName.endsWith('.spec.ts') ||
|
|
64
|
-
fileName.endsWith('.spec.js') ||
|
|
65
|
-
filePath.includes('/__tests__/') ||
|
|
66
|
-
filePath.includes('/test/') ||
|
|
67
|
-
filePath.includes('/tests/')
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Load gitignore patterns from a project directory
|
|
73
|
-
* @param projectDir Project directory path
|
|
74
|
-
* @returns Array of gitignore patterns
|
|
75
|
-
*/
|
|
76
|
-
export async function loadGitignorePatterns(projectDir: string): Promise<string[]> {
|
|
77
|
-
try {
|
|
78
|
-
const gitignorePath = path.join(projectDir, '.gitignore');
|
|
79
|
-
|
|
80
|
-
// Check if .gitignore exists
|
|
81
|
-
try {
|
|
82
|
-
await fs.access(gitignorePath);
|
|
83
|
-
} catch (_error) {
|
|
84
|
-
// File doesn't exist
|
|
85
|
-
logger.debug(`No .gitignore file found at ${gitignorePath}`);
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Read and parse .gitignore
|
|
90
|
-
const content = await fs.readFile(gitignorePath, 'utf-8');
|
|
91
|
-
return content
|
|
92
|
-
.split('\n')
|
|
93
|
-
.map((line) => line.trim())
|
|
94
|
-
.filter((line) => line && !line.startsWith('#'));
|
|
95
|
-
} catch (error) {
|
|
96
|
-
logger.error(`Error reading .gitignore: ${error}`);
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Check if a file should be excluded based on gitignore patterns
|
|
103
|
-
* @param filePath File path
|
|
104
|
-
* @param gitignorePatterns Array of gitignore patterns
|
|
105
|
-
* @returns True if the file should be excluded
|
|
106
|
-
*/
|
|
107
|
-
export function shouldExcludeFile(filePath: string, gitignorePatterns: string[]): boolean {
|
|
108
|
-
// Convert Windows paths to Unix-style for consistent pattern matching
|
|
109
|
-
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
110
|
-
|
|
111
|
-
for (const pattern of gitignorePatterns) {
|
|
112
|
-
// Skip empty lines and comments
|
|
113
|
-
if (!pattern || pattern.startsWith('#')) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Handle negation patterns (those starting with !)
|
|
118
|
-
const isNegation = pattern.startsWith('!');
|
|
119
|
-
const actualPattern = isNegation ? pattern.slice(1) : pattern;
|
|
120
|
-
|
|
121
|
-
// Convert glob pattern to regex
|
|
122
|
-
let regexPattern = actualPattern
|
|
123
|
-
// Escape special regex characters
|
|
124
|
-
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
125
|
-
// Convert glob ** to regex
|
|
126
|
-
.replace(/\*\*/g, '.*')
|
|
127
|
-
// Convert glob * to regex
|
|
128
|
-
.replace(/\*/g, '[^/]*')
|
|
129
|
-
// Convert glob ? to regex
|
|
130
|
-
.replace(/\?/g, '[^/]');
|
|
131
|
-
|
|
132
|
-
// Handle directory-specific patterns (those ending with /)
|
|
133
|
-
if (regexPattern.endsWith('/')) {
|
|
134
|
-
regexPattern = `${regexPattern}.*`;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Create the regex
|
|
138
|
-
const regex = new RegExp(
|
|
139
|
-
`^${regexPattern}$|^${regexPattern}/|/${regexPattern}$|/${regexPattern}/`,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
// Check if the path matches the pattern
|
|
143
|
-
const matches = regex.test(normalizedPath);
|
|
144
|
-
|
|
145
|
-
if (matches) {
|
|
146
|
-
// If it's a negation pattern and matches, don't exclude
|
|
147
|
-
if (isNegation) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
// If it's a regular pattern and matches, exclude
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// If no patterns matched, don't exclude
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Get the language for a file based on its extension
|
|
161
|
-
* @param filePath File path
|
|
162
|
-
* @returns Language identifier
|
|
163
|
-
*/
|
|
164
|
-
export function getLanguageForFile(filePath: string): string {
|
|
165
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
166
|
-
|
|
167
|
-
switch (ext) {
|
|
168
|
-
case '.ts':
|
|
169
|
-
case '.tsx':
|
|
170
|
-
return 'typescript';
|
|
171
|
-
case '.js':
|
|
172
|
-
case '.jsx':
|
|
173
|
-
return 'javascript';
|
|
174
|
-
case '.py':
|
|
175
|
-
case '.pyi':
|
|
176
|
-
case '.pyx':
|
|
177
|
-
return 'python';
|
|
178
|
-
case '.php':
|
|
179
|
-
return 'php';
|
|
180
|
-
case '.rb':
|
|
181
|
-
case '.rake':
|
|
182
|
-
case '.gemspec':
|
|
183
|
-
case '.ru':
|
|
184
|
-
case '.erb':
|
|
185
|
-
return 'ruby';
|
|
186
|
-
case '.go':
|
|
187
|
-
return 'go';
|
|
188
|
-
case '.java':
|
|
189
|
-
return 'java';
|
|
190
|
-
case '.rs':
|
|
191
|
-
return 'rust';
|
|
192
|
-
case '.c':
|
|
193
|
-
case '.h':
|
|
194
|
-
return 'c';
|
|
195
|
-
case '.cpp':
|
|
196
|
-
case '.hpp':
|
|
197
|
-
return 'cpp';
|
|
198
|
-
case '.cs':
|
|
199
|
-
return 'csharp';
|
|
200
|
-
case '.swift':
|
|
201
|
-
return 'swift';
|
|
202
|
-
case '.kt':
|
|
203
|
-
return 'kotlin';
|
|
204
|
-
case '.dart':
|
|
205
|
-
return 'dart';
|
|
206
|
-
case '.json':
|
|
207
|
-
return 'json';
|
|
208
|
-
case '.md':
|
|
209
|
-
return 'markdown';
|
|
210
|
-
default:
|
|
211
|
-
return 'unknown';
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Check if a file is supported for code review
|
|
217
|
-
* @param filePath File path
|
|
218
|
-
* @returns True if the file is supported
|
|
219
|
-
*/
|
|
220
|
-
export function isSupportedFile(filePath: string): boolean {
|
|
221
|
-
// Skip files that start with a dot (hidden files)
|
|
222
|
-
const fileName = path.basename(filePath);
|
|
223
|
-
if (fileName.startsWith('.')) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const ext = path.extname(filePath).toLowerCase();
|
|
228
|
-
return SUPPORTED_EXTENSIONS.includes(ext);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Discover files in a directory recursively
|
|
233
|
-
* @param dirPath Directory path
|
|
234
|
-
* @param options Options for file discovery
|
|
235
|
-
* @returns Array of file paths
|
|
236
|
-
*/
|
|
237
|
-
export async function discoverFiles(
|
|
238
|
-
dirPath: string,
|
|
239
|
-
options: {
|
|
240
|
-
excludePatterns?: string[];
|
|
241
|
-
includeTests?: boolean;
|
|
242
|
-
maxDepth?: number;
|
|
243
|
-
currentDepth?: number;
|
|
244
|
-
} = {},
|
|
245
|
-
): Promise<string[]> {
|
|
246
|
-
const { excludePatterns = [], includeTests = false, maxDepth = 10, currentDepth = 0 } = options;
|
|
247
|
-
|
|
248
|
-
// Check max depth
|
|
249
|
-
if (currentDepth > maxDepth) {
|
|
250
|
-
return [];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
try {
|
|
254
|
-
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
255
|
-
const files: string[] = [];
|
|
256
|
-
|
|
257
|
-
for (const entry of entries) {
|
|
258
|
-
const entryPath = path.join(dirPath, entry.name);
|
|
259
|
-
|
|
260
|
-
// Skip excluded files (from .gitignore)
|
|
261
|
-
if (shouldExcludeFile(entryPath, excludePatterns)) {
|
|
262
|
-
logger.debug(`Skipping path: ${entryPath} (matched by .gitignore pattern)`);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (entry.isDirectory()) {
|
|
267
|
-
// Skip node_modules, .git directories, and directories starting with '.'
|
|
268
|
-
if (entry.name === 'node_modules' || entry.name === '.git' || entry.name.startsWith('.')) {
|
|
269
|
-
logger.debug(`Skipping directory: ${entry.name} (hidden or excluded)`);
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// Recursively discover files in subdirectories
|
|
274
|
-
const subFiles = await discoverFiles(entryPath, {
|
|
275
|
-
excludePatterns,
|
|
276
|
-
includeTests,
|
|
277
|
-
maxDepth,
|
|
278
|
-
currentDepth: currentDepth + 1,
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
files.push(...subFiles);
|
|
282
|
-
} else if (entry.isFile()) {
|
|
283
|
-
// Skip dot files
|
|
284
|
-
if (entry.name.startsWith('.')) {
|
|
285
|
-
logger.debug(`Skipping file: ${entry.name} (hidden file)`);
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Skip test files if not including tests
|
|
290
|
-
if (!includeTests && isTestFile(entryPath)) {
|
|
291
|
-
logger.debug(`Skipping file: ${entryPath} (test file)`);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Skip unsupported files
|
|
296
|
-
if (!isSupportedFile(entryPath)) {
|
|
297
|
-
logger.debug(`Skipping file: ${entryPath} (unsupported file type)`);
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
files.push(entryPath);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return files;
|
|
306
|
-
} catch (error) {
|
|
307
|
-
logger.error(`Error discovering files in ${dirPath}:`, error);
|
|
308
|
-
return [];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Read file content and create a FileInfo object
|
|
314
|
-
* @param filePath File path
|
|
315
|
-
* @returns FileInfo object
|
|
316
|
-
*/
|
|
317
|
-
export async function readFileInfo(filePath: string): Promise<FileInfo> {
|
|
318
|
-
try {
|
|
319
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
320
|
-
// const language = getLanguageForFile(filePath); // TODO: Remove if not needed
|
|
321
|
-
|
|
322
|
-
return {
|
|
323
|
-
path: filePath,
|
|
324
|
-
relativePath: filePath,
|
|
325
|
-
content,
|
|
326
|
-
};
|
|
327
|
-
} catch (error) {
|
|
328
|
-
logger.error(`Error reading file ${filePath}:`, error);
|
|
329
|
-
throw error;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Read multiple files and create FileInfo objects
|
|
335
|
-
* @param filePaths Array of file paths
|
|
336
|
-
* @returns Array of FileInfo objects
|
|
337
|
-
*/
|
|
338
|
-
export async function readMultipleFiles(filePaths: string[]): Promise<FileInfo[]> {
|
|
339
|
-
const filePromises = filePaths.map((filePath) => readFileInfo(filePath));
|
|
340
|
-
return Promise.all(filePromises);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Get files to review based on the target path
|
|
345
|
-
* @param targetPath The target file or directory path
|
|
346
|
-
* @param isFile Whether the target is a file
|
|
347
|
-
* @param includeTests Whether to include test files
|
|
348
|
-
* @returns Array of file paths to review
|
|
349
|
-
*/
|
|
350
|
-
export async function getFilesToReview(
|
|
351
|
-
targetPath: string,
|
|
352
|
-
isFile: boolean,
|
|
353
|
-
includeTests = false,
|
|
354
|
-
excludePatterns: string[] = [],
|
|
355
|
-
): Promise<string[]> {
|
|
356
|
-
if (isFile) {
|
|
357
|
-
// If the target is a file, just return it
|
|
358
|
-
return [targetPath];
|
|
359
|
-
}
|
|
360
|
-
// If it's a directory, load .gitignore patterns if not already provided
|
|
361
|
-
let patterns = excludePatterns;
|
|
362
|
-
if (patterns.length === 0) {
|
|
363
|
-
patterns = await loadGitignorePatterns(targetPath);
|
|
364
|
-
logger.debug(`Loaded ${patterns.length} patterns from .gitignore`);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// If the target is a directory, discover files
|
|
368
|
-
return discoverFiles(targetPath, {
|
|
369
|
-
excludePatterns: patterns,
|
|
370
|
-
includeTests,
|
|
371
|
-
maxDepth: 10,
|
|
372
|
-
});
|
|
373
|
-
}
|
package/src/utils/fileSystem.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview File system utilities for the code review tool.
|
|
3
|
-
*
|
|
4
|
-
* This module re-exports utilities from more specialized modules to maintain
|
|
5
|
-
* backward compatibility while adhering to the Single Responsibility Principle.
|
|
6
|
-
*
|
|
7
|
-
* The original functionality has been split into:
|
|
8
|
-
* - pathValidator: For path validation and security checks
|
|
9
|
-
* - fileReader: For reading file operations
|
|
10
|
-
* - fileWriter: For writing file operations
|
|
11
|
-
* - pathGenerator: For generating output paths
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
// Import from pathValidator for aliases
|
|
15
|
-
import {
|
|
16
|
-
isDirectory,
|
|
17
|
-
isFile,
|
|
18
|
-
isPathWithinCwd,
|
|
19
|
-
pathExists,
|
|
20
|
-
validateTargetPath,
|
|
21
|
-
} from './pathValidator';
|
|
22
|
-
|
|
23
|
-
// Re-export from pathValidator
|
|
24
|
-
export { validateTargetPath, pathExists, isDirectory, isFile, isPathWithinCwd };
|
|
25
|
-
|
|
26
|
-
// Aliases for backward compatibility
|
|
27
|
-
export const fileExists = pathExists;
|
|
28
|
-
export const directoryExists = isDirectory;
|
|
29
|
-
export const validatePath = validateTargetPath;
|
|
30
|
-
|
|
31
|
-
// Re-export from fileReader
|
|
32
|
-
export {
|
|
33
|
-
readFile,
|
|
34
|
-
readFilesInDirectory as findFilesInDirectory,
|
|
35
|
-
readFilesWithInfo,
|
|
36
|
-
readFileWithInfo,
|
|
37
|
-
} from './FileReader';
|
|
38
|
-
|
|
39
|
-
// Import from fileWriter for aliases
|
|
40
|
-
import {
|
|
41
|
-
appendFile as appendFileImpl,
|
|
42
|
-
ensureDirectoryExists,
|
|
43
|
-
writeFile as writeFileImpl,
|
|
44
|
-
} from './FileWriter';
|
|
45
|
-
|
|
46
|
-
// Re-export from fileWriter
|
|
47
|
-
export { ensureDirectoryExists, writeFileImpl as writeFile, appendFileImpl as appendFile };
|
|
48
|
-
|
|
49
|
-
// Alias for backward compatibility
|
|
50
|
-
export const createDirectory = ensureDirectoryExists;
|
|
51
|
-
|
|
52
|
-
// Re-export from pathGenerator
|
|
53
|
-
export {
|
|
54
|
-
generateTempFilePath,
|
|
55
|
-
generateUniqueOutputPath,
|
|
56
|
-
generateVersionedOutputPath,
|
|
57
|
-
} from './PathGenerator';
|
package/src/utils/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Index file for utility modules.
|
|
3
|
-
*
|
|
4
|
-
* This module re-exports utilities from subdirectories for easy importing.
|
|
5
|
-
* It provides a centralized entry point for all utility functions used
|
|
6
|
-
* throughout the application.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// API utilities
|
|
10
|
-
export * from './api';
|
|
11
|
-
// Config utilities moved to core/ConfigurationService
|
|
12
|
-
export { getConfig, configurationService } from '../core/ConfigurationService';
|
|
13
|
-
export * from './fileFilters';
|
|
14
|
-
export * from './fileSystem';
|
|
15
|
-
// Core utilities
|
|
16
|
-
export * from './logger';
|
|
17
|
-
export * from './pathValidator';
|
|
18
|
-
export * from './priorityFilter';
|
|
19
|
-
// export * from './fileSystemUtils'; // Commented out due to conflicts with fileSystem.ts
|
|
20
|
-
export * from './projectDocs';
|
|
21
|
-
export * from './smartFileSelector';
|
|
22
|
-
|
|
23
|
-
// File utilities (moved to main utils directory)
|
|
24
|
-
// export * from './files'; // Deprecated - files moved to main utils
|
|
25
|
-
|
|
26
|
-
// Re-export types
|
|
27
|
-
export * from '../types/review';
|
|
28
|
-
// Detection utilities
|
|
29
|
-
export * from './detection';
|
|
30
|
-
|
|
31
|
-
// Template utilities (moved from templates directory)
|
|
32
|
-
export * from './promptTemplateManager';
|
|
33
|
-
// Parsing utilities (moved to main utils directory)
|
|
34
|
-
export * from './reviewParser';
|
|
35
|
-
export * from './sanitizer';
|
|
36
|
-
export * from './templateLoader';
|