@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,436 @@
1
+ /**
2
+ * Logger - Centralized logging system for the Loxia AI Agents System
3
+ *
4
+ * Purpose:
5
+ * - Structured logging with different levels
6
+ * - Agent activity logging
7
+ * - Tool execution logging
8
+ * - System event logging
9
+ * - Log output management (console, file)
10
+ */
11
+
12
+ import { promises as fs } from 'fs';
13
+ import path from 'path';
14
+
15
+ import {
16
+ SYSTEM_VERSION
17
+ } from './constants.js';
18
+
19
+ class Logger {
20
+ constructor(config = {}) {
21
+ this.config = config;
22
+
23
+ // Log levels in order of severity
24
+ this.levels = {
25
+ error: 0,
26
+ warn: 1,
27
+ info: 2,
28
+ debug: 3
29
+ };
30
+
31
+ this.currentLevel = this.levels[config.level || 'info'];
32
+ this.outputs = config.outputs || ['console'];
33
+ this.logFile = config.logFile || null;
34
+ this.maxFileSize = config.maxFileSize || 10 * 1024 * 1024; // 10MB
35
+ this.maxFiles = config.maxFiles || 5;
36
+
37
+ // Log formatting
38
+ this.enableColors = config.colors !== false;
39
+ this.includeTimestamp = config.timestamp !== false;
40
+ this.includeLevel = config.includeLevel !== false;
41
+
42
+ // Color codes for console output
43
+ this.colors = {
44
+ error: '\x1b[31m', // Red
45
+ warn: '\x1b[33m', // Yellow
46
+ info: '\x1b[36m', // Cyan
47
+ debug: '\x1b[90m', // Gray
48
+ reset: '\x1b[0m'
49
+ };
50
+
51
+ this.initialized = false;
52
+ }
53
+
54
+ /**
55
+ * Initialize logger
56
+ * @returns {Promise<void>}
57
+ */
58
+ async initialize() {
59
+ if (this.initialized) return;
60
+
61
+ try {
62
+ // Create log directory if file output is enabled
63
+ if (this.outputs.includes('file') && this.logFile) {
64
+ const logDir = path.dirname(this.logFile);
65
+ await fs.mkdir(logDir, { recursive: true });
66
+ }
67
+
68
+ this.initialized = true;
69
+ this.info('Logger initialized', {
70
+ level: Object.keys(this.levels)[this.currentLevel],
71
+ outputs: this.outputs,
72
+ logFile: this.logFile
73
+ });
74
+
75
+ } catch (error) {
76
+ console.error('Logger initialization failed:', error.message);
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Log error message
82
+ * @param {string} message - Log message
83
+ * @param {Object} meta - Additional metadata
84
+ */
85
+ error(message, meta = {}) {
86
+ this.log('error', message, meta);
87
+ }
88
+
89
+ /**
90
+ * Log warning message
91
+ * @param {string} message - Log message
92
+ * @param {Object} meta - Additional metadata
93
+ */
94
+ warn(message, meta = {}) {
95
+ this.log('warn', message, meta);
96
+ }
97
+
98
+ /**
99
+ * Log info message
100
+ * @param {string} message - Log message
101
+ * @param {Object} meta - Additional metadata
102
+ */
103
+ info(message, meta = {}) {
104
+ this.log('info', message, meta);
105
+ }
106
+
107
+ /**
108
+ * Log debug message
109
+ * @param {string} message - Log message
110
+ * @param {Object} meta - Additional metadata
111
+ */
112
+ debug(message, meta = {}) {
113
+ this.log('debug', message, meta);
114
+ }
115
+
116
+ /**
117
+ * Log agent activity
118
+ * @param {string} agentId - Agent identifier
119
+ * @param {string} action - Action performed
120
+ * @param {Object} details - Action details
121
+ */
122
+ logAgentActivity(agentId, action, details = {}) {
123
+ this.info(`[AGENT:${agentId}] ${action}`, {
124
+ category: 'agent-activity',
125
+ agentId,
126
+ action,
127
+ ...details
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Log tool execution
133
+ * @param {string} toolId - Tool identifier
134
+ * @param {string} operationId - Operation identifier
135
+ * @param {string} status - Execution status
136
+ * @param {number} duration - Execution duration in ms
137
+ * @param {Object} details - Additional details
138
+ */
139
+ logToolExecution(toolId, operationId, status, duration, details = {}) {
140
+ const level = status === 'failed' ? 'error' : 'info';
141
+ this[level](`[TOOL:${toolId}] Operation ${operationId} ${status} (${duration}ms)`, {
142
+ category: 'tool-execution',
143
+ toolId,
144
+ operationId,
145
+ status,
146
+ duration,
147
+ ...details
148
+ });
149
+ }
150
+
151
+ /**
152
+ * Log system event
153
+ * @param {string} event - Event name
154
+ * @param {Object} context - Event context
155
+ */
156
+ logSystemEvent(event, context = {}) {
157
+ this.info(`[SYSTEM] ${event}`, {
158
+ category: 'system-event',
159
+ event,
160
+ ...context
161
+ });
162
+ }
163
+
164
+ /**
165
+ * Log API request/response
166
+ * @param {string} method - HTTP method
167
+ * @param {string} url - Request URL
168
+ * @param {number} status - Response status
169
+ * @param {number} duration - Request duration in ms
170
+ * @param {Object} details - Additional details
171
+ */
172
+ logApiRequest(method, url, status, duration, details = {}) {
173
+ const level = status >= 400 ? 'error' : 'info';
174
+ this[level](`[API] ${method} ${url} ${status} (${duration}ms)`, {
175
+ category: 'api-request',
176
+ method,
177
+ url,
178
+ status,
179
+ duration,
180
+ ...details
181
+ });
182
+ }
183
+
184
+ /**
185
+ * Log with specified level
186
+ * @param {string} level - Log level
187
+ * @param {string} message - Log message
188
+ * @param {Object} meta - Additional metadata
189
+ */
190
+ log(level, message, meta = {}) {
191
+ // Check if level is enabled
192
+ if (this.levels[level] > this.currentLevel) {
193
+ return;
194
+ }
195
+
196
+ const logEntry = this.createLogEntry(level, message, meta);
197
+
198
+ // Output to configured destinations
199
+ for (const output of this.outputs) {
200
+ switch (output) {
201
+ case 'console':
202
+ this.outputToConsole(logEntry);
203
+ break;
204
+ case 'file':
205
+ this.outputToFile(logEntry);
206
+ break;
207
+ }
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Create structured log entry
213
+ * @private
214
+ */
215
+ createLogEntry(level, message, meta) {
216
+ const entry = {
217
+ timestamp: new Date().toISOString(),
218
+ level: level.toUpperCase(),
219
+ message,
220
+ version: SYSTEM_VERSION,
221
+ ...meta
222
+ };
223
+
224
+ // Add process information
225
+ entry.pid = process.pid;
226
+
227
+ // Add memory usage for debug level
228
+ if (level === 'debug') {
229
+ const memUsage = process.memoryUsage();
230
+ entry.memory = {
231
+ rss: Math.round(memUsage.rss / 1024 / 1024),
232
+ heapUsed: Math.round(memUsage.heapUsed / 1024 / 1024),
233
+ heapTotal: Math.round(memUsage.heapTotal / 1024 / 1024)
234
+ };
235
+ }
236
+
237
+ return entry;
238
+ }
239
+
240
+ /**
241
+ * Output log entry to console
242
+ * @private
243
+ */
244
+ outputToConsole(entry) {
245
+ let output = '';
246
+
247
+ // Add timestamp
248
+ if (this.includeTimestamp) {
249
+ const timestamp = new Date(entry.timestamp).toLocaleTimeString();
250
+ output += `[${timestamp}] `;
251
+ }
252
+
253
+ // Add level with color
254
+ if (this.includeLevel) {
255
+ const levelStr = entry.level.padEnd(5);
256
+ if (this.enableColors && process.stdout.isTTY) {
257
+ const color = this.colors[entry.level.toLowerCase()] || '';
258
+ output += `${color}${levelStr}${this.colors.reset} `;
259
+ } else {
260
+ output += `${levelStr} `;
261
+ }
262
+ }
263
+
264
+ // Add message
265
+ output += entry.message;
266
+
267
+ // Add metadata if present
268
+ const { timestamp, level, message, version, pid, ...metadata } = entry;
269
+ if (Object.keys(metadata).length > 0) {
270
+ output += ` ${JSON.stringify(metadata)}`;
271
+ }
272
+
273
+ // Output based on level
274
+ if (entry.level === 'ERROR') {
275
+ console.error(output);
276
+ } else {
277
+ console.log(output);
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Output log entry to file
283
+ * @private
284
+ */
285
+ async outputToFile(entry) {
286
+ if (!this.logFile) return;
287
+
288
+ try {
289
+ // Check file size and rotate if needed
290
+ await this.rotateLogFileIfNeeded();
291
+
292
+ const logLine = JSON.stringify(entry) + '\n';
293
+ await fs.appendFile(this.logFile, logLine, 'utf8');
294
+
295
+ } catch (error) {
296
+ console.error('Failed to write to log file:', error.message);
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Rotate log file if it exceeds max size
302
+ * @private
303
+ */
304
+ async rotateLogFileIfNeeded() {
305
+ try {
306
+ const stats = await fs.stat(this.logFile);
307
+
308
+ if (stats.size >= this.maxFileSize) {
309
+ await this.rotateLogFiles();
310
+ }
311
+
312
+ } catch (error) {
313
+ // File doesn't exist yet, that's ok
314
+ if (error.code !== 'ENOENT') {
315
+ throw error;
316
+ }
317
+ }
318
+ }
319
+
320
+ /**
321
+ * Rotate log files
322
+ * @private
323
+ */
324
+ async rotateLogFiles() {
325
+ const dir = path.dirname(this.logFile);
326
+ const basename = path.basename(this.logFile, path.extname(this.logFile));
327
+ const ext = path.extname(this.logFile);
328
+
329
+ // Rotate existing files
330
+ for (let i = this.maxFiles - 1; i >= 1; i--) {
331
+ const oldFile = path.join(dir, `${basename}.${i}${ext}`);
332
+ const newFile = path.join(dir, `${basename}.${i + 1}${ext}`);
333
+
334
+ try {
335
+ await fs.rename(oldFile, newFile);
336
+ } catch (error) {
337
+ // File doesn't exist, continue
338
+ if (error.code !== 'ENOENT') {
339
+ console.error(`Failed to rotate log file ${oldFile}:`, error.message);
340
+ }
341
+ }
342
+ }
343
+
344
+ // Move current file to .1
345
+ const rotatedFile = path.join(dir, `${basename}.1${ext}`);
346
+ try {
347
+ await fs.rename(this.logFile, rotatedFile);
348
+ } catch (error) {
349
+ console.error(`Failed to rotate current log file:`, error.message);
350
+ }
351
+ }
352
+
353
+ /**
354
+ * Set log level
355
+ * @param {string} level - New log level
356
+ */
357
+ setLevel(level) {
358
+ if (level in this.levels) {
359
+ this.currentLevel = this.levels[level];
360
+ this.info(`Log level changed to: ${level}`);
361
+ } else {
362
+ this.warn(`Invalid log level: ${level}. Valid levels: ${Object.keys(this.levels).join(', ')}`);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Add output destination
368
+ * @param {string} output - Output destination ('console' or 'file')
369
+ */
370
+ addOutput(output) {
371
+ if (!this.outputs.includes(output)) {
372
+ this.outputs.push(output);
373
+ this.info(`Added log output: ${output}`);
374
+ }
375
+ }
376
+
377
+ /**
378
+ * Remove output destination
379
+ * @param {string} output - Output destination to remove
380
+ */
381
+ removeOutput(output) {
382
+ const index = this.outputs.indexOf(output);
383
+ if (index > -1) {
384
+ this.outputs.splice(index, 1);
385
+ this.info(`Removed log output: ${output}`);
386
+ }
387
+ }
388
+
389
+ /**
390
+ * Create child logger with additional context
391
+ * @param {Object} context - Additional context to include in all logs
392
+ * @returns {Logger} Child logger instance
393
+ */
394
+ child(context) {
395
+ const childLogger = Object.create(this);
396
+ childLogger.childContext = { ...this.childContext, ...context };
397
+ return childLogger;
398
+ }
399
+
400
+ /**
401
+ * Flush any pending log entries
402
+ * @returns {Promise<void>}
403
+ */
404
+ async flush() {
405
+ // File system writes are typically immediate, but this provides
406
+ // a hook for more complex logging backends
407
+ return Promise.resolve();
408
+ }
409
+
410
+ /**
411
+ * Close logger and cleanup resources
412
+ * @returns {Promise<void>}
413
+ */
414
+ async close() {
415
+ await this.flush();
416
+ this.info('Logger closed');
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Create a logger instance with specified configuration
422
+ * @param {Object} config - Logger configuration
423
+ * @returns {Logger} Logger instance
424
+ */
425
+ function createLogger(config = {}) {
426
+ const logger = new Logger(config);
427
+
428
+ // Auto-initialize if not explicitly disabled
429
+ if (config.autoInit !== false) {
430
+ setImmediate(() => logger.initialize());
431
+ }
432
+
433
+ return logger;
434
+ }
435
+
436
+ export { Logger, createLogger };