@loxia-labs/loxia-autopilot-one 1.0.1

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 (80) hide show
  1. package/LICENSE +267 -0
  2. package/README.md +509 -0
  3. package/bin/cli.js +117 -0
  4. package/package.json +94 -0
  5. package/scripts/install-scanners.js +236 -0
  6. package/src/analyzers/CSSAnalyzer.js +297 -0
  7. package/src/analyzers/ConfigValidator.js +690 -0
  8. package/src/analyzers/ESLintAnalyzer.js +320 -0
  9. package/src/analyzers/JavaScriptAnalyzer.js +261 -0
  10. package/src/analyzers/PrettierFormatter.js +247 -0
  11. package/src/analyzers/PythonAnalyzer.js +266 -0
  12. package/src/analyzers/SecurityAnalyzer.js +729 -0
  13. package/src/analyzers/TypeScriptAnalyzer.js +247 -0
  14. package/src/analyzers/codeCloneDetector/analyzer.js +344 -0
  15. package/src/analyzers/codeCloneDetector/detector.js +203 -0
  16. package/src/analyzers/codeCloneDetector/index.js +160 -0
  17. package/src/analyzers/codeCloneDetector/parser.js +199 -0
  18. package/src/analyzers/codeCloneDetector/reporter.js +148 -0
  19. package/src/analyzers/codeCloneDetector/scanner.js +59 -0
  20. package/src/core/agentPool.js +1474 -0
  21. package/src/core/agentScheduler.js +2147 -0
  22. package/src/core/contextManager.js +709 -0
  23. package/src/core/messageProcessor.js +732 -0
  24. package/src/core/orchestrator.js +548 -0
  25. package/src/core/stateManager.js +877 -0
  26. package/src/index.js +631 -0
  27. package/src/interfaces/cli.js +549 -0
  28. package/src/interfaces/webServer.js +2162 -0
  29. package/src/modules/fileExplorer/controller.js +280 -0
  30. package/src/modules/fileExplorer/index.js +37 -0
  31. package/src/modules/fileExplorer/middleware.js +92 -0
  32. package/src/modules/fileExplorer/routes.js +125 -0
  33. package/src/modules/fileExplorer/types.js +44 -0
  34. package/src/services/aiService.js +1232 -0
  35. package/src/services/apiKeyManager.js +164 -0
  36. package/src/services/benchmarkService.js +366 -0
  37. package/src/services/budgetService.js +539 -0
  38. package/src/services/contextInjectionService.js +247 -0
  39. package/src/services/conversationCompactionService.js +637 -0
  40. package/src/services/errorHandler.js +810 -0
  41. package/src/services/fileAttachmentService.js +544 -0
  42. package/src/services/modelRouterService.js +366 -0
  43. package/src/services/modelsService.js +322 -0
  44. package/src/services/qualityInspector.js +796 -0
  45. package/src/services/tokenCountingService.js +536 -0
  46. package/src/tools/agentCommunicationTool.js +1344 -0
  47. package/src/tools/agentDelayTool.js +485 -0
  48. package/src/tools/asyncToolManager.js +604 -0
  49. package/src/tools/baseTool.js +800 -0
  50. package/src/tools/browserTool.js +920 -0
  51. package/src/tools/cloneDetectionTool.js +621 -0
  52. package/src/tools/dependencyResolverTool.js +1215 -0
  53. package/src/tools/fileContentReplaceTool.js +875 -0
  54. package/src/tools/fileSystemTool.js +1107 -0
  55. package/src/tools/fileTreeTool.js +853 -0
  56. package/src/tools/imageTool.js +901 -0
  57. package/src/tools/importAnalyzerTool.js +1060 -0
  58. package/src/tools/jobDoneTool.js +248 -0
  59. package/src/tools/seekTool.js +956 -0
  60. package/src/tools/staticAnalysisTool.js +1778 -0
  61. package/src/tools/taskManagerTool.js +2873 -0
  62. package/src/tools/terminalTool.js +2304 -0
  63. package/src/tools/webTool.js +1430 -0
  64. package/src/types/agent.js +519 -0
  65. package/src/types/contextReference.js +972 -0
  66. package/src/types/conversation.js +730 -0
  67. package/src/types/toolCommand.js +747 -0
  68. package/src/utilities/attachmentValidator.js +292 -0
  69. package/src/utilities/configManager.js +582 -0
  70. package/src/utilities/constants.js +722 -0
  71. package/src/utilities/directoryAccessManager.js +535 -0
  72. package/src/utilities/fileProcessor.js +307 -0
  73. package/src/utilities/logger.js +436 -0
  74. package/src/utilities/tagParser.js +1246 -0
  75. package/src/utilities/toolConstants.js +317 -0
  76. package/web-ui/build/index.html +15 -0
  77. package/web-ui/build/logo.png +0 -0
  78. package/web-ui/build/logo2.png +0 -0
  79. package/web-ui/build/static/index-CjkkcnFA.js +344 -0
  80. package/web-ui/build/static/index-Dy2bYbOa.css +1 -0
@@ -0,0 +1,307 @@
1
+ /**
2
+ * File Processor
3
+ * Handles file reading, conversion, and processing operations
4
+ */
5
+
6
+ import fs from 'fs/promises';
7
+ import path from 'path';
8
+ import crypto from 'crypto';
9
+
10
+ // PDF support disabled due to DOM API requirements in Node.js environment
11
+ // The pdf-parse library requires browser DOM APIs (DOMMatrix, ImageData, Path2D)
12
+ // which are not available in Node.js. PDF text extraction can be re-enabled
13
+ // by installing canvas-based polyfills or using an alternative PDF library.
14
+
15
+ class FileProcessor {
16
+ constructor(config = {}, logger = null) {
17
+ this.config = config;
18
+ this.logger = logger;
19
+ this.pdfSupported = false; // Disabled - requires DOM APIs
20
+ }
21
+
22
+ /**
23
+ * Read file content
24
+ * @param {string} filePath - Path to file
25
+ * @param {string} encoding - File encoding (default: 'utf8')
26
+ * @returns {Promise<string|Buffer>}
27
+ */
28
+ async readFile(filePath, encoding = 'utf8') {
29
+ try {
30
+ const content = await fs.readFile(filePath, encoding);
31
+ return content;
32
+ } catch (error) {
33
+ this.logger?.error('Error reading file', { filePath, error: error.message });
34
+ throw new Error(`Failed to read file: ${error.message}`);
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Convert image to base64
40
+ * @param {string} filePath - Path to image file
41
+ * @returns {Promise<string>} Base64 encoded string with data URI
42
+ */
43
+ async imageToBase64(filePath) {
44
+ try {
45
+ const buffer = await fs.readFile(filePath);
46
+ const ext = path.extname(filePath).toLowerCase();
47
+
48
+ // Determine MIME type
49
+ const mimeTypes = {
50
+ '.jpg': 'image/jpeg',
51
+ '.jpeg': 'image/jpeg',
52
+ '.png': 'image/png',
53
+ '.gif': 'image/gif',
54
+ '.webp': 'image/webp',
55
+ '.bmp': 'image/bmp',
56
+ '.svg': 'image/svg+xml'
57
+ };
58
+
59
+ const mimeType = mimeTypes[ext] || 'image/jpeg';
60
+ const base64 = buffer.toString('base64');
61
+
62
+ return `data:${mimeType};base64,${base64}`;
63
+ } catch (error) {
64
+ this.logger?.error('Error converting image to base64', { filePath, error: error.message });
65
+ throw new Error(`Failed to convert image: ${error.message}`);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Extract text from PDF
71
+ * @param {string} filePath - Path to PDF file
72
+ * @returns {Promise<Object>} { text: string, numPages: number }
73
+ */
74
+ async extractPdfText(filePath) {
75
+ if (!this.pdfSupported) {
76
+ throw new Error('PDF text extraction is not supported - pdf-parse library not available');
77
+ }
78
+
79
+ try {
80
+ const dataBuffer = await fs.readFile(filePath);
81
+ const data = await pdfParse(dataBuffer);
82
+
83
+ return {
84
+ text: data.text,
85
+ numPages: data.numpages,
86
+ info: data.info || {},
87
+ metadata: data.metadata || {}
88
+ };
89
+ } catch (error) {
90
+ this.logger?.error('Error extracting PDF text', { filePath, error: error.message });
91
+ throw new Error(`Failed to extract PDF text: ${error.message}`);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Calculate file hash (SHA-256)
97
+ * @param {string} filePath - Path to file
98
+ * @returns {Promise<string>} Hash as hex string
99
+ */
100
+ async calculateHash(filePath) {
101
+ try {
102
+ const buffer = await fs.readFile(filePath);
103
+ const hash = crypto.createHash('sha256');
104
+ hash.update(buffer);
105
+ return hash.digest('hex');
106
+ } catch (error) {
107
+ this.logger?.error('Error calculating file hash', { filePath, error: error.message });
108
+ throw new Error(`Failed to calculate hash: ${error.message}`);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Get file stats
114
+ * @param {string} filePath - Path to file
115
+ * @returns {Promise<Object>} File stats
116
+ */
117
+ async getFileStats(filePath) {
118
+ try {
119
+ const stats = await fs.stat(filePath);
120
+ return {
121
+ size: stats.size,
122
+ created: stats.birthtime,
123
+ modified: stats.mtime,
124
+ isFile: stats.isFile(),
125
+ isDirectory: stats.isDirectory()
126
+ };
127
+ } catch (error) {
128
+ this.logger?.error('Error getting file stats', { filePath, error: error.message });
129
+ throw new Error(`Failed to get file stats: ${error.message}`);
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Check if file exists
135
+ * @param {string} filePath - Path to file
136
+ * @returns {Promise<boolean>}
137
+ */
138
+ async fileExists(filePath) {
139
+ try {
140
+ await fs.access(filePath);
141
+ return true;
142
+ } catch {
143
+ return false;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Process file based on content type
149
+ * @param {string} filePath - Path to file
150
+ * @param {string} contentType - 'text' | 'image' | 'pdf'
151
+ * @returns {Promise<Object>} { content: string, metadata: Object }
152
+ */
153
+ async processFile(filePath, contentType) {
154
+ const metadata = {};
155
+
156
+ try {
157
+ switch (contentType) {
158
+ case 'text': {
159
+ const content = await this.readFile(filePath, 'utf8');
160
+ metadata.lines = content.split('\n').length;
161
+ metadata.characters = content.length;
162
+ return { content, metadata };
163
+ }
164
+
165
+ case 'image': {
166
+ const content = await this.imageToBase64(filePath);
167
+ const stats = await this.getFileStats(filePath);
168
+ metadata.size = stats.size;
169
+ return { content, metadata };
170
+ }
171
+
172
+ case 'pdf': {
173
+ const pdfData = await this.extractPdfText(filePath);
174
+ metadata.numPages = pdfData.numPages;
175
+ metadata.info = pdfData.info;
176
+ return { content: pdfData.text, metadata };
177
+ }
178
+
179
+ default:
180
+ throw new Error(`Unsupported content type: ${contentType}`);
181
+ }
182
+ } catch (error) {
183
+ this.logger?.error('Error processing file', { filePath, contentType, error: error.message });
184
+ throw error;
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Estimate token count for text
190
+ * @param {string} text - Text content
191
+ * @returns {number} Estimated token count
192
+ */
193
+ estimateTokens(text) {
194
+ // Rough estimate: 1 token ≈ 4 characters for text
195
+ // For base64 images: 1 token ≈ 1.5 characters (overhead)
196
+
197
+ if (!text) return 0;
198
+
199
+ // Check if it's a base64 data URI
200
+ if (text.startsWith('data:image')) {
201
+ // Extract base64 part and estimate
202
+ const base64Part = text.split(',')[1] || '';
203
+ return Math.ceil(base64Part.length / 1.5);
204
+ }
205
+
206
+ // Regular text
207
+ return Math.ceil(text.length / 4);
208
+ }
209
+
210
+ /**
211
+ * Write content to file
212
+ * @param {string} filePath - Path to file
213
+ * @param {string|Buffer} content - Content to write
214
+ * @param {string} encoding - Encoding (default: 'utf8')
215
+ * @returns {Promise<void>}
216
+ */
217
+ async writeFile(filePath, content, encoding = 'utf8') {
218
+ try {
219
+ // Ensure directory exists
220
+ const dir = path.dirname(filePath);
221
+ await fs.mkdir(dir, { recursive: true });
222
+
223
+ await fs.writeFile(filePath, content, encoding);
224
+ } catch (error) {
225
+ this.logger?.error('Error writing file', { filePath, error: error.message });
226
+ throw new Error(`Failed to write file: ${error.message}`);
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Delete file
232
+ * @param {string} filePath - Path to file
233
+ * @returns {Promise<void>}
234
+ */
235
+ async deleteFile(filePath) {
236
+ try {
237
+ await fs.unlink(filePath);
238
+ } catch (error) {
239
+ this.logger?.error('Error deleting file', { filePath, error: error.message });
240
+ throw new Error(`Failed to delete file: ${error.message}`);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Copy file
246
+ * @param {string} sourcePath - Source file path
247
+ * @param {string} destPath - Destination file path
248
+ * @returns {Promise<void>}
249
+ */
250
+ async copyFile(sourcePath, destPath) {
251
+ try {
252
+ // Ensure destination directory exists
253
+ const dir = path.dirname(destPath);
254
+ await fs.mkdir(dir, { recursive: true });
255
+
256
+ await fs.copyFile(sourcePath, destPath);
257
+ } catch (error) {
258
+ this.logger?.error('Error copying file', { sourcePath, destPath, error: error.message });
259
+ throw new Error(`Failed to copy file: ${error.message}`);
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Create directory
265
+ * @param {string} dirPath - Directory path
266
+ * @returns {Promise<void>}
267
+ */
268
+ async createDirectory(dirPath) {
269
+ try {
270
+ await fs.mkdir(dirPath, { recursive: true });
271
+ } catch (error) {
272
+ this.logger?.error('Error creating directory', { dirPath, error: error.message });
273
+ throw new Error(`Failed to create directory: ${error.message}`);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Delete directory recursively
279
+ * @param {string} dirPath - Directory path
280
+ * @returns {Promise<void>}
281
+ */
282
+ async deleteDirectory(dirPath) {
283
+ try {
284
+ await fs.rm(dirPath, { recursive: true, force: true });
285
+ } catch (error) {
286
+ this.logger?.error('Error deleting directory', { dirPath, error: error.message });
287
+ throw new Error(`Failed to delete directory: ${error.message}`);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * List files in directory
293
+ * @param {string} dirPath - Directory path
294
+ * @returns {Promise<string[]>} Array of file names
295
+ */
296
+ async listFiles(dirPath) {
297
+ try {
298
+ const files = await fs.readdir(dirPath);
299
+ return files;
300
+ } catch (error) {
301
+ this.logger?.error('Error listing files', { dirPath, error: error.message });
302
+ throw new Error(`Failed to list files: ${error.message}`);
303
+ }
304
+ }
305
+ }
306
+
307
+ export default FileProcessor;