@loxia-labs/loxia-autopilot-one 1.0.1 → 1.0.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 (120) hide show
  1. package/README.md +44 -54
  2. package/bin/cli.js +1 -115
  3. package/bin/loxia-terminal-v2.js +3 -0
  4. package/bin/loxia-terminal.js +3 -0
  5. package/bin/start-with-terminal.js +3 -0
  6. package/package.json +15 -15
  7. package/scripts/install-scanners.js +1 -235
  8. package/src/analyzers/CSSAnalyzer.js +1 -297
  9. package/src/analyzers/ConfigValidator.js +1 -690
  10. package/src/analyzers/ESLintAnalyzer.js +1 -320
  11. package/src/analyzers/JavaScriptAnalyzer.js +1 -261
  12. package/src/analyzers/PrettierFormatter.js +1 -247
  13. package/src/analyzers/PythonAnalyzer.js +1 -266
  14. package/src/analyzers/SecurityAnalyzer.js +1 -729
  15. package/src/analyzers/TypeScriptAnalyzer.js +1 -247
  16. package/src/analyzers/codeCloneDetector/analyzer.js +1 -344
  17. package/src/analyzers/codeCloneDetector/detector.js +1 -203
  18. package/src/analyzers/codeCloneDetector/index.js +1 -160
  19. package/src/analyzers/codeCloneDetector/parser.js +1 -199
  20. package/src/analyzers/codeCloneDetector/reporter.js +1 -148
  21. package/src/analyzers/codeCloneDetector/scanner.js +1 -59
  22. package/src/core/agentPool.js +1 -1474
  23. package/src/core/agentScheduler.js +1 -2147
  24. package/src/core/contextManager.js +1 -709
  25. package/src/core/messageProcessor.js +1 -732
  26. package/src/core/orchestrator.js +1 -548
  27. package/src/core/stateManager.js +1 -877
  28. package/src/index.js +1 -631
  29. package/src/interfaces/cli.js +1 -549
  30. package/src/interfaces/terminal/__tests__/smoke/advancedFeatures.test.js +1 -0
  31. package/src/interfaces/terminal/__tests__/smoke/agentControl.test.js +1 -0
  32. package/src/interfaces/terminal/__tests__/smoke/agents.test.js +1 -0
  33. package/src/interfaces/terminal/__tests__/smoke/components.test.js +1 -0
  34. package/src/interfaces/terminal/__tests__/smoke/connection.test.js +1 -0
  35. package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +1 -0
  36. package/src/interfaces/terminal/__tests__/smoke/imports.test.js +1 -0
  37. package/src/interfaces/terminal/__tests__/smoke/messages.test.js +1 -0
  38. package/src/interfaces/terminal/__tests__/smoke/tools.test.js +1 -0
  39. package/src/interfaces/terminal/api/apiClient.js +1 -0
  40. package/src/interfaces/terminal/api/messageRouter.js +1 -0
  41. package/src/interfaces/terminal/api/session.js +1 -0
  42. package/src/interfaces/terminal/api/websocket.js +1 -0
  43. package/src/interfaces/terminal/components/AgentCreator.js +1 -0
  44. package/src/interfaces/terminal/components/AgentEditor.js +1 -0
  45. package/src/interfaces/terminal/components/AgentSwitcher.js +1 -0
  46. package/src/interfaces/terminal/components/ErrorBoundary.js +1 -0
  47. package/src/interfaces/terminal/components/ErrorPanel.js +1 -0
  48. package/src/interfaces/terminal/components/Header.js +1 -0
  49. package/src/interfaces/terminal/components/HelpPanel.js +1 -0
  50. package/src/interfaces/terminal/components/InputBox.js +1 -0
  51. package/src/interfaces/terminal/components/Layout.js +1 -0
  52. package/src/interfaces/terminal/components/LoadingSpinner.js +1 -0
  53. package/src/interfaces/terminal/components/MessageList.js +1 -0
  54. package/src/interfaces/terminal/components/MultilineTextInput.js +1 -0
  55. package/src/interfaces/terminal/components/SearchPanel.js +1 -0
  56. package/src/interfaces/terminal/components/SettingsPanel.js +1 -0
  57. package/src/interfaces/terminal/components/StatusBar.js +1 -0
  58. package/src/interfaces/terminal/components/TextInput.js +1 -0
  59. package/src/interfaces/terminal/config/agentEditorConstants.js +1 -0
  60. package/src/interfaces/terminal/config/constants.js +1 -0
  61. package/src/interfaces/terminal/index.js +1 -0
  62. package/src/interfaces/terminal/state/useAgentControl.js +1 -0
  63. package/src/interfaces/terminal/state/useAgents.js +1 -0
  64. package/src/interfaces/terminal/state/useConnection.js +1 -0
  65. package/src/interfaces/terminal/state/useMessages.js +1 -0
  66. package/src/interfaces/terminal/state/useTools.js +1 -0
  67. package/src/interfaces/terminal/utils/debugLogger.js +1 -0
  68. package/src/interfaces/terminal/utils/settingsStorage.js +1 -0
  69. package/src/interfaces/terminal/utils/theme.js +1 -0
  70. package/src/interfaces/webServer.js +1 -2162
  71. package/src/modules/fileExplorer/controller.js +1 -280
  72. package/src/modules/fileExplorer/index.js +1 -37
  73. package/src/modules/fileExplorer/middleware.js +1 -92
  74. package/src/modules/fileExplorer/routes.js +1 -125
  75. package/src/modules/fileExplorer/types.js +1 -44
  76. package/src/services/aiService.js +1 -1232
  77. package/src/services/apiKeyManager.js +1 -164
  78. package/src/services/benchmarkService.js +1 -366
  79. package/src/services/budgetService.js +1 -539
  80. package/src/services/contextInjectionService.js +1 -247
  81. package/src/services/conversationCompactionService.js +1 -637
  82. package/src/services/errorHandler.js +1 -810
  83. package/src/services/fileAttachmentService.js +1 -544
  84. package/src/services/modelRouterService.js +1 -366
  85. package/src/services/modelsService.js +1 -322
  86. package/src/services/qualityInspector.js +1 -796
  87. package/src/services/tokenCountingService.js +1 -536
  88. package/src/tools/agentCommunicationTool.js +1 -1344
  89. package/src/tools/agentDelayTool.js +1 -485
  90. package/src/tools/asyncToolManager.js +1 -604
  91. package/src/tools/baseTool.js +1 -800
  92. package/src/tools/browserTool.js +1 -920
  93. package/src/tools/cloneDetectionTool.js +1 -621
  94. package/src/tools/dependencyResolverTool.js +1 -1215
  95. package/src/tools/fileContentReplaceTool.js +1 -875
  96. package/src/tools/fileSystemTool.js +1 -1107
  97. package/src/tools/fileTreeTool.js +1 -853
  98. package/src/tools/imageTool.js +1 -901
  99. package/src/tools/importAnalyzerTool.js +1 -1060
  100. package/src/tools/jobDoneTool.js +1 -248
  101. package/src/tools/seekTool.js +1 -956
  102. package/src/tools/staticAnalysisTool.js +1 -1778
  103. package/src/tools/taskManagerTool.js +1 -2873
  104. package/src/tools/terminalTool.js +1 -2304
  105. package/src/tools/webTool.js +1 -1430
  106. package/src/types/agent.js +1 -519
  107. package/src/types/contextReference.js +1 -972
  108. package/src/types/conversation.js +1 -730
  109. package/src/types/toolCommand.js +1 -747
  110. package/src/utilities/attachmentValidator.js +1 -292
  111. package/src/utilities/configManager.js +1 -582
  112. package/src/utilities/constants.js +1 -722
  113. package/src/utilities/directoryAccessManager.js +1 -535
  114. package/src/utilities/fileProcessor.js +1 -307
  115. package/src/utilities/logger.js +1 -436
  116. package/src/utilities/tagParser.js +1 -1246
  117. package/src/utilities/toolConstants.js +1 -317
  118. package/web-ui/build/index.html +2 -2
  119. package/web-ui/build/static/{index-Dy2bYbOa.css → index-CClD1090.css} +1 -1
  120. package/web-ui/build/static/{index-CjkkcnFA.js → index-lCBai6dX.js} +66 -67
@@ -1,709 +1 @@
1
- /**
2
- * ContextManager - Handles context reference processing and file context integration
3
- *
4
- * Purpose:
5
- * - Process context references (files, components, selections)
6
- * - Load and validate file content
7
- * - Generate context prompts for AI models
8
- * - Manage context size limits
9
- * - Handle context reference caching
10
- */
11
-
12
- import { promises as fs } from 'fs';
13
- import path from 'path';
14
- import crypto from 'crypto';
15
-
16
- class ContextManager {
17
- constructor(config, logger) {
18
- this.config = config;
19
- this.logger = logger;
20
-
21
- this.maxContextSize = config.context?.maxSize || 50000; // characters
22
- this.maxReferences = config.context?.maxReferences || 10;
23
- this.autoValidation = config.context?.autoValidation || true;
24
- this.cacheExpiry = config.context?.cacheExpiry || 3600; // seconds
25
-
26
- // Context cache
27
- this.contextCache = new Map();
28
-
29
- // File watchers for context validation
30
- this.fileWatchers = new Map();
31
- }
32
-
33
- /**
34
- * Process message with context references
35
- * @param {Object} message - Message object with contextReferences
36
- * @param {string} projectDir - Project directory path
37
- * @returns {Promise<Object>} Enhanced message with context
38
- */
39
- async processMessageWithContext(message, projectDir) {
40
- if (!message.contextReferences || message.contextReferences.length === 0) {
41
- return message;
42
- }
43
-
44
- try {
45
- // Load and process context references
46
- const processedReferences = await this.loadContextReferences(
47
- message.contextReferences,
48
- projectDir
49
- );
50
-
51
- // Generate context prompt
52
- const contextPrompt = this.generateContextPrompt(processedReferences);
53
-
54
- // Combine context with original message
55
- const enhancedMessage = {
56
- ...message,
57
- content: contextPrompt + '\n\n' + message.content,
58
- originalContent: message.content,
59
- processedContextReferences: processedReferences,
60
- contextSize: contextPrompt.length
61
- };
62
-
63
- this.logger.info('Message enhanced with context', {
64
- originalLength: message.content.length,
65
- contextSize: contextPrompt.length,
66
- referencesCount: processedReferences.length,
67
- totalSize: enhancedMessage.content.length
68
- });
69
-
70
- return enhancedMessage;
71
-
72
- } catch (error) {
73
- this.logger.error(`Context processing failed: ${error.message}`, {
74
- referencesCount: message.contextReferences.length,
75
- error: error.stack
76
- });
77
-
78
- // Return original message with error info
79
- return {
80
- ...message,
81
- contextProcessingError: error.message,
82
- processedContextReferences: []
83
- };
84
- }
85
- }
86
-
87
- /**
88
- * Load and validate context references
89
- * @param {Array} references - Array of context reference objects
90
- * @param {string} projectDir - Project directory path
91
- * @returns {Promise<Array>} Array of processed context references
92
- */
93
- async loadContextReferences(references, projectDir) {
94
- const loaded = [];
95
- let totalSize = 0;
96
-
97
- // Sort references by priority (file > component > selection)
98
- const sortedReferences = this.sortReferencesByPriority(references);
99
-
100
- for (const ref of sortedReferences.slice(0, this.maxReferences)) {
101
- try {
102
- const cacheKey = this.generateCacheKey(ref, projectDir);
103
-
104
- // Check cache first
105
- let loadedRef = this.getFromCache(cacheKey);
106
-
107
- if (!loadedRef || this.shouldRefreshCache(loadedRef)) {
108
- loadedRef = await this.loadSingleReference(ref, projectDir);
109
- this.addToCache(cacheKey, loadedRef);
110
- }
111
-
112
- // Check size limits
113
- if (totalSize + loadedRef.content.length > this.maxContextSize) {
114
- loadedRef.content = loadedRef.content.substring(
115
- 0,
116
- this.maxContextSize - totalSize
117
- ) + '\n... [context truncated due to size limit]';
118
- loadedRef.truncated = true;
119
- }
120
-
121
- loaded.push(loadedRef);
122
- totalSize += loadedRef.content.length;
123
-
124
- if (totalSize >= this.maxContextSize) {
125
- this.logger.warn('Context size limit reached, stopping reference loading');
126
- break;
127
- }
128
-
129
- } catch (error) {
130
- this.logger.warn(`Failed to load context reference: ${error.message}`, {
131
- referenceType: ref.type,
132
- referencePath: ref.path || ref.name
133
- });
134
-
135
- loaded.push({
136
- ...ref,
137
- error: error.message,
138
- content: `[Error loading reference: ${error.message}]`,
139
- exists: false
140
- });
141
- }
142
- }
143
-
144
- return loaded;
145
- }
146
-
147
- /**
148
- * Load a single context reference
149
- * @param {Object} ref - Context reference object
150
- * @param {string} projectDir - Project directory path
151
- * @returns {Promise<Object>} Processed reference object
152
- */
153
- async loadSingleReference(ref, projectDir) {
154
- const startTime = Date.now();
155
-
156
- try {
157
- switch (ref.type) {
158
- case 'file':
159
- return await this.loadFileReference(ref, projectDir);
160
-
161
- case 'component':
162
- return await this.loadComponentReference(ref, projectDir);
163
-
164
- case 'selection':
165
- return await this.loadSelectionReference(ref, projectDir);
166
-
167
- case 'directory':
168
- return await this.loadDirectoryReference(ref, projectDir);
169
-
170
- default:
171
- throw new Error(`Unknown reference type: ${ref.type}`);
172
- }
173
-
174
- } finally {
175
- const loadTime = Date.now() - startTime;
176
- this.logger.debug(`Reference loaded in ${loadTime}ms`, {
177
- type: ref.type,
178
- path: ref.path || ref.name
179
- });
180
- }
181
- }
182
-
183
- /**
184
- * Load file reference
185
- * @private
186
- */
187
- async loadFileReference(ref, projectDir) {
188
- const fullPath = path.resolve(projectDir, ref.path);
189
-
190
- // Check file exists and get stats
191
- let stats;
192
- try {
193
- stats = await fs.stat(fullPath);
194
- if (!stats.isFile()) {
195
- throw new Error('Path is not a file');
196
- }
197
- } catch {
198
- throw new Error('File not found');
199
- }
200
-
201
- // Read file content
202
- let content = await fs.readFile(fullPath, 'utf8');
203
-
204
- // Apply line range if specified
205
- if (ref.lines && ref.lines.length > 0) {
206
- const lines = content.split('\n');
207
- const startLine = Math.max(0, (ref.lines[0] || 1) - 1);
208
- const endLine = Math.min(lines.length, ref.lines[1] || ref.lines[0] || lines.length);
209
-
210
- content = lines.slice(startLine, endLine).join('\n');
211
- }
212
-
213
- // Calculate checksum for change detection
214
- const checksum = this.calculateChecksum(content);
215
-
216
- return {
217
- ...ref,
218
- content,
219
- exists: true,
220
- lastModified: stats.mtime.toISOString(),
221
- fileSize: stats.size,
222
- checksum,
223
- hasChanged: ref.checksum && ref.checksum !== checksum,
224
- loadedAt: new Date().toISOString()
225
- };
226
- }
227
-
228
- /**
229
- * Load component reference
230
- * @private
231
- */
232
- async loadComponentReference(ref, projectDir) {
233
- const fullPath = path.resolve(projectDir, ref.file);
234
-
235
- try {
236
- const fileContent = await fs.readFile(fullPath, 'utf8');
237
- const componentInfo = await this.extractComponent(fileContent, ref.name, ref.startLine, ref.endLine);
238
-
239
- return {
240
- ...ref,
241
- content: componentInfo.content,
242
- exists: true,
243
- signature: componentInfo.signature,
244
- dependencies: componentInfo.dependencies,
245
- actualStartLine: componentInfo.startLine,
246
- actualEndLine: componentInfo.endLine,
247
- loadedAt: new Date().toISOString()
248
- };
249
-
250
- } catch (error) {
251
- throw new Error(`Component extraction failed: ${error.message}`);
252
- }
253
- }
254
-
255
- /**
256
- * Load selection reference
257
- * @private
258
- */
259
- async loadSelectionReference(ref, projectDir) {
260
- // Selection content is provided by user, validate against file if possible
261
- if (ref.file) {
262
- const fullPath = path.resolve(projectDir, ref.file);
263
-
264
- try {
265
- const fileContent = await fs.readFile(fullPath, 'utf8');
266
- const lines = fileContent.split('\n');
267
-
268
- if (ref.lines && ref.lines.length >= 2) {
269
- const startLine = Math.max(0, ref.lines[0] - 1);
270
- const endLine = Math.min(lines.length, ref.lines[1]);
271
- const fileSelection = lines.slice(startLine, endLine).join('\n');
272
-
273
- const selectionValid = this.compareSelections(ref.content, fileSelection);
274
-
275
- return {
276
- ...ref,
277
- exists: true,
278
- validated: selectionValid,
279
- currentFileContent: selectionValid ? null : fileSelection,
280
- loadedAt: new Date().toISOString()
281
- };
282
- }
283
- } catch {
284
- // File validation failed, use provided content
285
- }
286
- }
287
-
288
- return {
289
- ...ref,
290
- exists: true,
291
- validated: false,
292
- loadedAt: new Date().toISOString()
293
- };
294
- }
295
-
296
- /**
297
- * Load directory reference
298
- * @private
299
- */
300
- async loadDirectoryReference(ref, projectDir) {
301
- const fullPath = path.resolve(projectDir, ref.path);
302
-
303
- try {
304
- const stats = await fs.stat(fullPath);
305
- if (!stats.isDirectory()) {
306
- throw new Error('Path is not a directory');
307
- }
308
-
309
- const files = await fs.readdir(fullPath, { withFileTypes: true });
310
- const structure = files.map(file => ({
311
- name: file.name,
312
- type: file.isDirectory() ? 'directory' : 'file',
313
- isSymbolicLink: file.isSymbolicLink()
314
- }));
315
-
316
- // Generate directory listing content
317
- const content = this.generateDirectoryListing(ref.path, structure);
318
-
319
- return {
320
- ...ref,
321
- content,
322
- exists: true,
323
- structure,
324
- fileCount: files.filter(f => f.isFile()).length,
325
- directoryCount: files.filter(f => f.isDirectory()).length,
326
- loadedAt: new Date().toISOString()
327
- };
328
-
329
- } catch (error) {
330
- throw new Error(`Directory reading failed: ${error.message}`);
331
- }
332
- }
333
-
334
- /**
335
- * Generate context prompt from processed references
336
- * @param {Array} references - Array of processed context references
337
- * @returns {string} Generated context prompt
338
- */
339
- generateContextPrompt(references) {
340
- if (!references.length) return '';
341
-
342
- let prompt = '\n=== PROJECT CONTEXT REFERENCES ===\n';
343
-
344
- for (const ref of references) {
345
- if (ref.error) {
346
- prompt += `❌ ${ref.type.toUpperCase()}: ${ref.path || ref.name}\n`;
347
- prompt += ` Error: ${ref.error}\n\n`;
348
- continue;
349
- }
350
-
351
- const icon = this.getContextIcon(ref.type);
352
- prompt += `${icon} ${ref.type.toUpperCase()}: ${ref.path || ref.name}\n`;
353
-
354
- // Add metadata
355
- if (ref.lines && ref.lines.length > 0) {
356
- const lineRange = ref.lines.length === 1
357
- ? `Line ${ref.lines[0]}`
358
- : `Lines ${ref.lines[0]}-${ref.lines[1]}`;
359
- prompt += ` ${lineRange}\n`;
360
- }
361
-
362
- if (ref.description) {
363
- prompt += ` Description: ${ref.description}\n`;
364
- }
365
-
366
- if (ref.hasChanged) {
367
- prompt += ` ⚠️ File has changed since reference was created\n`;
368
- }
369
-
370
- if (ref.truncated) {
371
- prompt += ` ⚠️ Content truncated due to size limits\n`;
372
- }
373
-
374
- // Add content with appropriate syntax highlighting
375
- const language = this.getLanguageFromPath(ref.path || ref.file);
376
- prompt += `\n\`\`\`${language}\n`;
377
- prompt += ref.content;
378
- prompt += '\n```\n\n';
379
- }
380
-
381
- prompt += '=== END CONTEXT REFERENCES ===\n';
382
- return prompt;
383
- }
384
-
385
- /**
386
- * Extract component from file content
387
- * @private
388
- */
389
- async extractComponent(fileContent, componentName, startLine, endLine) {
390
- const lines = fileContent.split('\n');
391
-
392
- if (startLine && endLine) {
393
- // Use provided line range
394
- const content = lines.slice(startLine - 1, endLine).join('\n');
395
- return {
396
- content,
397
- startLine,
398
- endLine,
399
- signature: this.extractSignature(content, componentName),
400
- dependencies: this.extractDependencies(content)
401
- };
402
- }
403
-
404
- // Search for component by name
405
- const componentRegex = new RegExp(
406
- `(class\\s+${componentName}|function\\s+${componentName}|const\\s+${componentName}|export.*${componentName})`,
407
- 'i'
408
- );
409
-
410
- let foundStartLine = -1;
411
- let foundEndLine = -1;
412
- let braceCount = 0;
413
- let inComponent = false;
414
-
415
- for (let i = 0; i < lines.length; i++) {
416
- const line = lines[i];
417
-
418
- if (!inComponent && componentRegex.test(line)) {
419
- foundStartLine = i + 1;
420
- inComponent = true;
421
-
422
- // Count opening braces in this line
423
- braceCount += (line.match(/\{/g) || []).length;
424
- braceCount -= (line.match(/\}/g) || []).length;
425
-
426
- if (braceCount === 0 && line.includes(';')) {
427
- // Single line declaration
428
- foundEndLine = i + 1;
429
- break;
430
- }
431
-
432
- continue;
433
- }
434
-
435
- if (inComponent) {
436
- braceCount += (line.match(/\{/g) || []).length;
437
- braceCount -= (line.match(/\}/g) || []).length;
438
-
439
- if (braceCount <= 0) {
440
- foundEndLine = i + 1;
441
- break;
442
- }
443
- }
444
- }
445
-
446
- if (foundStartLine === -1) {
447
- throw new Error(`Component '${componentName}' not found in file`);
448
- }
449
-
450
- const content = lines.slice(foundStartLine - 1, foundEndLine).join('\n');
451
-
452
- return {
453
- content,
454
- startLine: foundStartLine,
455
- endLine: foundEndLine,
456
- signature: this.extractSignature(content, componentName),
457
- dependencies: this.extractDependencies(content)
458
- };
459
- }
460
-
461
- /**
462
- * Extract function/class signature
463
- * @private
464
- */
465
- extractSignature(content, name) {
466
- const lines = content.split('\n');
467
- const firstLine = lines[0].trim();
468
-
469
- // Try to extract a meaningful signature
470
- const signatureRegex = new RegExp(`(.*${name}[^{;]*)[{;]?`);
471
- const match = firstLine.match(signatureRegex);
472
-
473
- return match ? match[1].trim() : firstLine;
474
- }
475
-
476
- /**
477
- * Extract dependencies from content
478
- * @private
479
- */
480
- extractDependencies(content) {
481
- const dependencies = [];
482
-
483
- // Extract import statements
484
- const importRegex = /import\s+.*?\s+from\s+['"]([^'"]+)['"]/g;
485
- let match;
486
- while ((match = importRegex.exec(content)) !== null) {
487
- dependencies.push(match[1]);
488
- }
489
-
490
- // Extract require statements
491
- const requireRegex = /require\(['"]([^'"]+)['"]\)/g;
492
- while ((match = requireRegex.exec(content)) !== null) {
493
- dependencies.push(match[1]);
494
- }
495
-
496
- return [...new Set(dependencies)]; // Remove duplicates
497
- }
498
-
499
- /**
500
- * Generate directory listing content
501
- * @private
502
- */
503
- generateDirectoryListing(dirPath, structure) {
504
- let content = `Directory: ${dirPath}\n\n`;
505
-
506
- const directories = structure.filter(item => item.type === 'directory');
507
- const files = structure.filter(item => item.type === 'file');
508
-
509
- if (directories.length > 0) {
510
- content += 'Directories:\n';
511
- for (const dir of directories) {
512
- content += ` 📁 ${dir.name}${dir.isSymbolicLink ? ' (symlink)' : ''}\n`;
513
- }
514
- content += '\n';
515
- }
516
-
517
- if (files.length > 0) {
518
- content += 'Files:\n';
519
- for (const file of files) {
520
- const icon = this.getFileIcon(file.name);
521
- content += ` ${icon} ${file.name}${file.isSymbolicLink ? ' (symlink)' : ''}\n`;
522
- }
523
- }
524
-
525
- if (structure.length === 0) {
526
- content += '(empty directory)\n';
527
- }
528
-
529
- return content;
530
- }
531
-
532
- /**
533
- * Sort references by priority
534
- * @private
535
- */
536
- sortReferencesByPriority(references) {
537
- const priorityOrder = { file: 1, component: 2, selection: 3, directory: 4 };
538
-
539
- return [...references].sort((a, b) => {
540
- const aPriority = priorityOrder[a.type] || 999;
541
- const bPriority = priorityOrder[b.type] || 999;
542
- return aPriority - bPriority;
543
- });
544
- }
545
-
546
- /**
547
- * Get context icon for reference type
548
- * @private
549
- */
550
- getContextIcon(type) {
551
- const icons = {
552
- file: '📄',
553
- component: '🔧',
554
- selection: '✂️',
555
- directory: '📁'
556
- };
557
- return icons[type] || '📎';
558
- }
559
-
560
- /**
561
- * Get file icon based on extension
562
- * @private
563
- */
564
- getFileIcon(filename) {
565
- const ext = path.extname(filename).toLowerCase();
566
- const icons = {
567
- '.js': '📜',
568
- '.jsx': '⚛️',
569
- '.ts': '📘',
570
- '.tsx': '⚛️',
571
- '.py': '🐍',
572
- '.java': '☕',
573
- '.html': '🌐',
574
- '.css': '🎨',
575
- '.json': '📋',
576
- '.md': '📝',
577
- '.yml': '⚙️',
578
- '.yaml': '⚙️'
579
- };
580
- return icons[ext] || '📄';
581
- }
582
-
583
- /**
584
- * Get language identifier from file path
585
- * @private
586
- */
587
- getLanguageFromPath(filePath) {
588
- if (!filePath) return '';
589
-
590
- const ext = path.extname(filePath).toLowerCase();
591
- const langMap = {
592
- '.js': 'javascript',
593
- '.jsx': 'jsx',
594
- '.ts': 'typescript',
595
- '.tsx': 'tsx',
596
- '.py': 'python',
597
- '.java': 'java',
598
- '.cpp': 'cpp',
599
- '.c': 'c',
600
- '.cs': 'csharp',
601
- '.php': 'php',
602
- '.rb': 'ruby',
603
- '.go': 'go',
604
- '.rs': 'rust',
605
- '.html': 'html',
606
- '.css': 'css',
607
- '.scss': 'scss',
608
- '.json': 'json',
609
- '.yml': 'yaml',
610
- '.yaml': 'yaml',
611
- '.md': 'markdown',
612
- '.xml': 'xml',
613
- '.sql': 'sql'
614
- };
615
-
616
- return langMap[ext] || '';
617
- }
618
-
619
- /**
620
- * Calculate content checksum
621
- * @private
622
- */
623
- calculateChecksum(content) {
624
- return crypto.createHash('sha256').update(content).digest('hex').substring(0, 16);
625
- }
626
-
627
- /**
628
- * Compare two code selections
629
- * @private
630
- */
631
- compareSelections(selection1, selection2) {
632
- // Normalize whitespace and compare
633
- const normalize = str => str.replace(/\s+/g, ' ').trim();
634
- return normalize(selection1) === normalize(selection2);
635
- }
636
-
637
- /**
638
- * Generate cache key for reference
639
- * @private
640
- */
641
- generateCacheKey(ref, projectDir) {
642
- const keyData = {
643
- type: ref.type,
644
- path: ref.path || ref.file,
645
- lines: ref.lines,
646
- name: ref.name,
647
- projectDir
648
- };
649
-
650
- return crypto.createHash('md5').update(JSON.stringify(keyData)).digest('hex');
651
- }
652
-
653
- /**
654
- * Get reference from cache
655
- * @private
656
- */
657
- getFromCache(cacheKey) {
658
- const cached = this.contextCache.get(cacheKey);
659
- if (!cached) return null;
660
-
661
- return cached.data;
662
- }
663
-
664
- /**
665
- * Add reference to cache
666
- * @private
667
- */
668
- addToCache(cacheKey, data) {
669
- this.contextCache.set(cacheKey, {
670
- data,
671
- timestamp: Date.now()
672
- });
673
-
674
- // Clean up old cache entries
675
- this.cleanupCache();
676
- }
677
-
678
- /**
679
- * Check if cached reference should be refreshed
680
- * @private
681
- */
682
- shouldRefreshCache(cachedRef) {
683
- if (!this.autoValidation) return false;
684
-
685
- const age = (Date.now() - new Date(cachedRef.loadedAt).getTime()) / 1000;
686
- return age > this.cacheExpiry;
687
- }
688
-
689
- /**
690
- * Clean up expired cache entries
691
- * @private
692
- */
693
- cleanupCache() {
694
- const now = Date.now();
695
- const expiredKeys = [];
696
-
697
- for (const [key, cached] of this.contextCache.entries()) {
698
- if (now - cached.timestamp > this.cacheExpiry * 1000) {
699
- expiredKeys.push(key);
700
- }
701
- }
702
-
703
- for (const key of expiredKeys) {
704
- this.contextCache.delete(key);
705
- }
706
- }
707
- }
708
-
709
- export default ContextManager;
1
+ const a0_0x543338=a0_0x5e4e;(function(_0x10fc6f,_0x18791a){const _0x261752=a0_0x5e4e,_0x208a3e=_0x10fc6f();while(!![]){try{const _0x17c1d4=-parseInt(_0x261752(0x17f))/0x1+-parseInt(_0x261752(0x121))/0x2+parseInt(_0x261752(0x150))/0x3+parseInt(_0x261752(0x175))/0x4+parseInt(_0x261752(0x11c))/0x5+-parseInt(_0x261752(0x171))/0x6*(-parseInt(_0x261752(0x15d))/0x7)+-parseInt(_0x261752(0x142))/0x8*(parseInt(_0x261752(0x182))/0x9);if(_0x17c1d4===_0x18791a)break;else _0x208a3e['push'](_0x208a3e['shift']());}catch(_0xb3b890){_0x208a3e['push'](_0x208a3e['shift']());}}}(a0_0x445c,0x9995f));function a0_0x5e4e(_0x3329e1,_0xff54f4){_0x3329e1=_0x3329e1-0x10d;const _0x445c73=a0_0x445c();let _0x5e4e42=_0x445c73[_0x3329e1];if(a0_0x5e4e['uoOggU']===undefined){var _0x2f6f58=function(_0x570f10){const _0x18ae67='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x54daf2='',_0x1a83c0='';for(let _0x29b37e=0x0,_0x38f469,_0x473ebe,_0x38157c=0x0;_0x473ebe=_0x570f10['charAt'](_0x38157c++);~_0x473ebe&&(_0x38f469=_0x29b37e%0x4?_0x38f469*0x40+_0x473ebe:_0x473ebe,_0x29b37e++%0x4)?_0x54daf2+=String['fromCharCode'](0xff&_0x38f469>>(-0x2*_0x29b37e&0x6)):0x0){_0x473ebe=_0x18ae67['indexOf'](_0x473ebe);}for(let _0x341cb6=0x0,_0x351962=_0x54daf2['length'];_0x341cb6<_0x351962;_0x341cb6++){_0x1a83c0+='%'+('00'+_0x54daf2['charCodeAt'](_0x341cb6)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x1a83c0);};a0_0x5e4e['uGEFPj']=_0x2f6f58,a0_0x5e4e['LnaWuK']={},a0_0x5e4e['uoOggU']=!![];}const _0x3d2eae=_0x445c73[0x0],_0x597b7c=_0x3329e1+_0x3d2eae,_0x378897=a0_0x5e4e['LnaWuK'][_0x597b7c];return!_0x378897?(_0x5e4e42=a0_0x5e4e['uGEFPj'](_0x5e4e42),a0_0x5e4e['LnaWuK'][_0x597b7c]=_0x5e4e42):_0x5e4e42=_0x378897,_0x5e4e42;}function a0_0x445c(){const _0x2dd01f=['icHZEw1SAw5Rkq','CMvZB2X2zq','Bg9Nz2vY','AxntEw1IB2XPy0XPBMS','zw5KtgLUzq','BM93','Bwf4q29UDgv4DfnPEMu','zgvZy3jPChrPB24','z2v0tgfUz3vHz2vgCM9Tugf0Aa','z2vUzxjHDgveAxjLy3rVCNLmAxn0Aw5N','Dg9ju09tDhjPBMC','CNvZDa','BgvUz3rO','BgLUzxm','zxH0CMfJDfnPz25HDhvYzq','tgLUzxmG','icaG','Bwf4uMvMzxjLBMnLCW','uMvMzxjLBMnLigXVywrLzcbPBIa','odCXogDVzg92va','ChvZAa','Dhn4','Bg9HzenVBNrLEhrszwzLCMvUy2vZ','mtK5nJK1nKjbzvDcyG','Bg9HzezPBgvszwzLCMvUy2u','Eg1S','D2fYBG','Agv4','twvZC2fNzsbLBMHHBMnLzcb3AxrOignVBNrLEhq','rgLYzwn0B3jPzxm6cG','EwfTBa','CgHW','ugf0AcbPCYbUB3qGysbMAwXL','mtaYnZeYoxjksxHmBG','C3bSAxq','FgnVBNn0xhmR','mJqZodfds3jqtMi','zgvSzxrL','zgf0yq','y29UDgvUDa','kc4Q','y29UDgv4Da','zMLSzq','q29UDgv4DcbZAxPLigXPBwL0ihjLywnOzwqSihn0B3bWAw5NihjLzMvYzw5JzsbSB2fKAw5N','AMf2yxnJCMLWDa','zxH0BMfTzq','DhjPBq','zxjYB3i','Bg9HzfnLBgvJDgLVBLjLzMvYzw5Jzq','y3bW','C2HVDwXKuMvMCMvZAenHy2HL','AMf2yq','z2vUzxjHDgvdywnOzuTLEq','AgfZq2HHBMDLza','Cgf0Aa','Bg9HzgvKqxq','zxHLyW','zgLNzxn0','ntu1mZK1nuDfqwLyAa','AxneAxjLy3rVCNK','icaGrgvZy3jPChrPB246ia','Bwf4u2L6zq','rMfPBgvKihrVigXVywqGy29UDgv4DcbYzwzLCMvUy2u6ia','mJq1odC4DNjStM1Y','DxbKyxrL','DhLWzxnJCMLWDa','BxrPBwu','zw50CMLLCW','icaG4PQG77IpicbgAwXLigHHCYbJAgfUz2vKihnPBMnLihjLzMvYzw5Jzsb3yxmGy3jLyxrLzaO','CMvHzezPBgu','y3nZ','rgLYzwn0B3j5ihjLywrPBMCGzMfPBgvKoIa','BwLU','BwvZC2fNzq','AM9PBG','Dg9mB3DLCKnHC2u','y29UDgv4DfjLzMvYzw5Jzxm','AxngAwXL','C3fS','q29TCg9Uzw50icC','zxH0CMfJDerLCgvUzgvUy2LLCW','z2vUzxjHDgvdB250zxH0uhjVBxb0','icaGrxjYB3i6ia','zgLYzwn0B3j5','y29UDgv4DenHy2HL','ANnVBG','Fgv4Cg9YDc4Q','C2vSzwn0Aw9U','z2v0q29UDgv4DeLJB24','BMfTzq','C2HHmJu2','DhLWzq','y2fSy3vSyxrLq2HLy2TZDw0','C29YDfjLzMvYzw5JzxncEvbYAw9YAxr5','ugf0AcbPCYbUB3qGysbKAxjLy3rVCNK','Bwf0y2G','mZiZmMzVDeP1za','C3rHy2S','C3rHCNrmAw5L','ChjVy2vZC01LC3nHz2vxAxrOq29UDgv4Da','cI4UlIbBy29UDgv4Dcb0CNvUy2f0zwqGzhvLihrVihnPEMuGBgLTAxrD','q29TCg9Uzw50igv4DhjHy3rPB24GzMfPBgvKoIa','z2v0rNjVBunHy2HL','y2XLyw51CenHy2HL','kgnSyxnZxhmR','yxv0B1zHBgLKyxrPB24','Bwq1','z2v0rMLSzuLJB24','Bg9HzfnPBMDSzvjLzMvYzw5Jzq','y2HLy2TZDw0','mZC1ntGXmwvRDwfTua','zMLSDgvY','jYbUB3qGzM91BMqGAw4GzMLSzq','Fgz1BMn0Aw9UxhmR','C2nZCW','C3vIC3rYAw5N','rMLSzsbUB3qGzM91BMq','zxH0CMfJDenVBxbVBMvUDa','C3rHDa','DgvZDa','CNvIEq','C2XPy2u','q29UDgv4DcbWCM9JzxnZAw5NigzHAwXLzdOG','ntzTs2ntCgm'];a0_0x445c=function(){return _0x2dd01f;};return a0_0x445c();}import{promises as a0_0x54daf2}from'fs';import a0_0x1a83c0 from'path';import a0_0x29b37e from'crypto';class ContextManager{constructor(_0x38f469,_0x473ebe){const _0x40e9fb=a0_0x5e4e;this['config']=_0x38f469,this['logger']=_0x473ebe,this['maxContextSize']=_0x38f469[_0x40e9fb(0x187)]?.[_0x40e9fb(0x11f)]||0xc350,this[_0x40e9fb(0x16f)]=_0x38f469['context']?.['maxReferences']||0xa,this['autoValidation']=_0x38f469[_0x40e9fb(0x187)]?.[_0x40e9fb(0x14b)]||!![],this['cacheExpiry']=_0x38f469[_0x40e9fb(0x187)]?.['cacheExpiry']||0xe10,this[_0x40e9fb(0x136)]=new Map(),this['fileWatchers']=new Map();}async[a0_0x543338(0x145)](_0x38157c,_0x341cb6){const _0x2d99af=a0_0x543338;if(!_0x38157c[_0x2d99af(0x12e)]||_0x38157c[_0x2d99af(0x12e)]['length']===0x0)return _0x38157c;try{const processedReferences=await this[_0x2d99af(0x174)](_0x38157c['contextReferences'],_0x341cb6),_0x351962=this['generateContextPrompt'](processedReferences),_0x3ac0db={..._0x38157c,'content':_0x351962+'\x0a\x0a'+_0x38157c['content'],'originalContent':_0x38157c['content'],'processedContextReferences':processedReferences,'contextSize':_0x351962['length']};return this[_0x2d99af(0x160)]['info'](_0x2d99af(0x17a),{'originalLength':_0x38157c['content'][_0x2d99af(0x16a)],'contextSize':_0x351962[_0x2d99af(0x16a)],'referencesCount':processedReferences['length'],'totalSize':_0x3ac0db['content']['length']}),_0x3ac0db;}catch(_0x1cad8b){return this['logger']['error'](_0x2d99af(0x15c)+_0x1cad8b['message'],{'referencesCount':_0x38157c['contextReferences']['length'],'error':_0x1cad8b[_0x2d99af(0x143)]}),{..._0x38157c,'contextProcessingError':_0x1cad8b[_0x2d99af(0x12b)],'processedContextReferences':[]};}}async[a0_0x543338(0x174)](_0x1ca0bc,_0x3ae00b){const _0x50c100=a0_0x543338,_0x1ad3f2=[];let _0x5c9320=0x0;const _0x16ffa0=this['sortReferencesByPriority'](_0x1ca0bc);for(const _0x56caaf of _0x16ffa0[_0x50c100(0x15b)](0x0,this['maxReferences'])){try{const _0x4af905=this['generateCacheKey'](_0x56caaf,_0x3ae00b);let _0x4732df=this[_0x50c100(0x148)](_0x4af905);(!_0x4732df||this[_0x50c100(0x114)](_0x4732df))&&(_0x4732df=await this['loadSingleReference'](_0x56caaf,_0x3ae00b),this['addToCache'](_0x4af905,_0x4732df));_0x5c9320+_0x4732df[_0x50c100(0x185)][_0x50c100(0x16a)]>this[_0x50c100(0x164)]&&(_0x4732df[_0x50c100(0x185)]=_0x4732df['content']['substring'](0x0,this[_0x50c100(0x164)]-_0x5c9320)+_0x50c100(0x146),_0x4732df['truncated']=!![]);_0x1ad3f2['push'](_0x4732df),_0x5c9320+=_0x4732df['content'][_0x50c100(0x16a)];if(_0x5c9320>=this['maxContextSize']){this['logger'][_0x50c100(0x178)](_0x50c100(0x10d));break;}}catch(_0x10e5ad){this[_0x50c100(0x160)][_0x50c100(0x178)](_0x50c100(0x120)+_0x10e5ad[_0x50c100(0x12b)],{'referenceType':_0x56caaf[_0x50c100(0x13d)],'referencePath':_0x56caaf[_0x50c100(0x118)]||_0x56caaf[_0x50c100(0x13b)]}),_0x1ad3f2['push']({..._0x56caaf,'error':_0x10e5ad['message'],'content':'[Error\x20loading\x20reference:\x20'+_0x10e5ad[_0x50c100(0x12b)]+']','exists':![]});}}return _0x1ad3f2;}async[a0_0x543338(0x14e)](_0xdeb9f2,_0x5412ba){const _0x527fe1=a0_0x543338,_0x429537=Date['now']();try{switch(_0xdeb9f2['type']){case _0x527fe1(0x188):return await this['loadFileReference'](_0xdeb9f2,_0x5412ba);case'component':return await this['loadComponentReference'](_0xdeb9f2,_0x5412ba);case _0x527fe1(0x139):return await this['loadSelectionReference'](_0xdeb9f2,_0x5412ba);case _0x527fe1(0x135):return await this['loadDirectoryReference'](_0xdeb9f2,_0x5412ba);default:throw new Error('Unknown\x20reference\x20type:\x20'+_0xdeb9f2[_0x527fe1(0x13d)]);}}finally{const _0x53ee93=Date['now']()-_0x429537;this[_0x527fe1(0x160)]['debug'](_0x527fe1(0x170)+_0x53ee93+'ms',{'type':_0xdeb9f2[_0x527fe1(0x13d)],'path':_0xdeb9f2[_0x527fe1(0x118)]||_0xdeb9f2['name']});}}async[a0_0x543338(0x176)](_0x5afaa4,_0x4478d6){const _0x174d5a=a0_0x543338,_0x2a43f7=a0_0x1a83c0['resolve'](_0x4478d6,_0x5afaa4[_0x174d5a(0x118)]);let _0xc034ec;try{_0xc034ec=await a0_0x54daf2[_0x174d5a(0x158)](_0x2a43f7);if(!_0xc034ec[_0x174d5a(0x12f)]())throw new Error(_0x174d5a(0x17e));}catch{throw new Error(_0x174d5a(0x156));}let _0x2e9b24=await a0_0x54daf2['readFile'](_0x2a43f7,'utf8');if(_0x5afaa4[_0x174d5a(0x16b)]&&_0x5afaa4['lines'][_0x174d5a(0x16a)]>0x0){const _0x1a9eec=_0x2e9b24[_0x174d5a(0x180)]('\x0a'),_0x22305a=Math['max'](0x0,(_0x5afaa4[_0x174d5a(0x16b)][0x0]||0x1)-0x1),_0x5c8f33=Math[_0x174d5a(0x12a)](_0x1a9eec[_0x174d5a(0x16a)],_0x5afaa4[_0x174d5a(0x16b)][0x1]||_0x5afaa4['lines'][0x0]||_0x1a9eec['length']);_0x2e9b24=_0x1a9eec[_0x174d5a(0x15b)](_0x22305a,_0x5c8f33)[_0x174d5a(0x12c)]('\x0a');}const _0xd8e940=this[_0x174d5a(0x13e)](_0x2e9b24);return{..._0x5afaa4,'content':_0x2e9b24,'exists':!![],'lastModified':_0xc034ec[_0x174d5a(0x124)]['toISOString'](),'fileSize':_0xc034ec['size'],'checksum':_0xd8e940,'hasChanged':_0x5afaa4[_0x174d5a(0x14f)]&&_0x5afaa4['checksum']!==_0xd8e940,'loadedAt':new Date()['toISOString']()};}async['loadComponentReference'](_0x4082d4,_0x3d6d32){const _0x552b0b=a0_0x543338,_0x1ab5d7=a0_0x1a83c0['resolve'](_0x3d6d32,_0x4082d4['file']);try{const _0x1db2c1=await a0_0x54daf2['readFile'](_0x1ab5d7,'utf8'),_0x1cb624=await this[_0x552b0b(0x157)](_0x1db2c1,_0x4082d4['name'],_0x4082d4[_0x552b0b(0x144)],_0x4082d4[_0x552b0b(0x162)]);return{..._0x4082d4,'content':_0x1cb624['content'],'exists':!![],'signature':_0x1cb624['signature'],'dependencies':_0x1cb624['dependencies'],'actualStartLine':_0x1cb624[_0x552b0b(0x144)],'actualEndLine':_0x1cb624['endLine'],'loadedAt':new Date()[_0x552b0b(0x168)]()};}catch(_0x2b97ef){throw new Error(_0x552b0b(0x147)+_0x2b97ef[_0x552b0b(0x12b)]);}}async[a0_0x543338(0x112)](_0x3a9a4a,_0x19b7d6){const _0x42cefb=a0_0x543338;if(_0x3a9a4a['file']){const _0x427464=a0_0x1a83c0[_0x42cefb(0x15f)](_0x19b7d6,_0x3a9a4a[_0x42cefb(0x188)]);try{const _0x13767c=await a0_0x54daf2[_0x42cefb(0x127)](_0x427464,'utf8'),_0x297e14=_0x13767c[_0x42cefb(0x180)]('\x0a');if(_0x3a9a4a['lines']&&_0x3a9a4a['lines']['length']>=0x2){const _0x3bfb54=Math['max'](0x0,_0x3a9a4a['lines'][0x0]-0x1),_0x53de20=Math[_0x42cefb(0x12a)](_0x297e14[_0x42cefb(0x16a)],_0x3a9a4a['lines'][0x1]),_0x79b60f=_0x297e14[_0x42cefb(0x15b)](_0x3bfb54,_0x53de20)['join']('\x0a'),_0x505a7e=this['compareSelections'](_0x3a9a4a['content'],_0x79b60f);return{..._0x3a9a4a,'exists':!![],'validated':_0x505a7e,'currentFileContent':_0x505a7e?null:_0x79b60f,'loadedAt':new Date()[_0x42cefb(0x168)]()};}}catch{}}return{..._0x3a9a4a,'exists':!![],'validated':![],'loadedAt':new Date()[_0x42cefb(0x168)]()};}async['loadDirectoryReference'](_0x1770ae,_0x465d09){const _0x3190ae=a0_0x543338,_0x21cbe1=a0_0x1a83c0['resolve'](_0x465d09,_0x1770ae['path']);try{const _0x1975f5=await a0_0x54daf2['stat'](_0x21cbe1);if(!_0x1975f5['isDirectory']())throw new Error(_0x3190ae(0x140));const _0x2e28f8=await a0_0x54daf2['readdir'](_0x21cbe1,{'withFileTypes':!![]}),_0x5d8b35=_0x2e28f8['map'](_0x2cf0f4=>({'name':_0x2cf0f4['name'],'type':_0x2cf0f4[_0x3190ae(0x11d)]()?'directory':_0x3190ae(0x188),'isSymbolicLink':_0x2cf0f4[_0x3190ae(0x161)]()})),_0xaf9d9a=this[_0x3190ae(0x167)](_0x1770ae['path'],_0x5d8b35);return{..._0x1770ae,'content':_0xaf9d9a,'exists':!![],'structure':_0x5d8b35,'fileCount':_0x2e28f8[_0x3190ae(0x151)](_0x40fc9a=>_0x40fc9a['isFile']())[_0x3190ae(0x16a)],'directoryCount':_0x2e28f8[_0x3190ae(0x151)](_0x15027b=>_0x15027b['isDirectory']())['length'],'loadedAt':new Date()['toISOString']()};}catch(_0x42918a){throw new Error(_0x3190ae(0x129)+_0x42918a[_0x3190ae(0x12b)]);}}[a0_0x543338(0x133)](_0x1ddd90){const _0x7d0e09=a0_0x543338;if(!_0x1ddd90['length'])return'';let _0x216950='\x0a===\x20PROJECT\x20CONTEXT\x20REFERENCES\x20===\x0a';for(const _0x5742a9 of _0x1ddd90){if(_0x5742a9[_0x7d0e09(0x111)]){_0x216950+='❌\x20'+_0x5742a9[_0x7d0e09(0x13d)]['toUpperCase']()+':\x20'+(_0x5742a9[_0x7d0e09(0x118)]||_0x5742a9[_0x7d0e09(0x13b)])+'\x0a',_0x216950+=_0x7d0e09(0x134)+_0x5742a9['error']+'\x0a\x0a';continue;}const _0x38ef2c=this['getContextIcon'](_0x5742a9[_0x7d0e09(0x13d)]);_0x216950+=_0x38ef2c+'\x20'+_0x5742a9['type']['toUpperCase']()+':\x20'+(_0x5742a9[_0x7d0e09(0x118)]||_0x5742a9[_0x7d0e09(0x13b)])+'\x0a';if(_0x5742a9[_0x7d0e09(0x16b)]&&_0x5742a9[_0x7d0e09(0x16b)][_0x7d0e09(0x16a)]>0x0){const _0x370152=_0x5742a9[_0x7d0e09(0x16b)][_0x7d0e09(0x16a)]===0x1?'Line\x20'+_0x5742a9['lines'][0x0]:_0x7d0e09(0x16d)+_0x5742a9['lines'][0x0]+'-'+_0x5742a9['lines'][0x1];_0x216950+=_0x7d0e09(0x16e)+_0x370152+'\x0a';}_0x5742a9[_0x7d0e09(0x165)]&&(_0x216950+=_0x7d0e09(0x11e)+_0x5742a9['description']+'\x0a');_0x5742a9[_0x7d0e09(0x117)]&&(_0x216950+=_0x7d0e09(0x126));_0x5742a9['truncated']&&(_0x216950+='\x20\x20\x20⚠️\x20\x20Content\x20truncated\x20due\x20to\x20size\x20limits\x0a');const _0x37d6a0=this[_0x7d0e09(0x166)](_0x5742a9[_0x7d0e09(0x118)]||_0x5742a9[_0x7d0e09(0x188)]);_0x216950+='\x0a```'+_0x37d6a0+'\x0a',_0x216950+=_0x5742a9[_0x7d0e09(0x185)],_0x216950+='\x0a```\x0a\x0a';}return _0x216950+='===\x20END\x20CONTEXT\x20REFERENCES\x20===\x0a',_0x216950;}async[a0_0x543338(0x157)](_0x311ffa,_0x3a68db,_0x318da,_0x4ff1f6){const _0x12c6dd=a0_0x543338,_0x170ee1=_0x311ffa[_0x12c6dd(0x180)]('\x0a');if(_0x318da&&_0x4ff1f6){const _0x35ab70=_0x170ee1['slice'](_0x318da-0x1,_0x4ff1f6)['join']('\x0a');return{'content':_0x35ab70,'startLine':_0x318da,'endLine':_0x4ff1f6,'signature':this['extractSignature'](_0x35ab70,_0x3a68db),'dependencies':this['extractDependencies'](_0x35ab70)};}const _0x6857dc=new RegExp(_0x12c6dd(0x14a)+_0x3a68db+_0x12c6dd(0x153)+_0x3a68db+_0x12c6dd(0x181)+_0x3a68db+_0x12c6dd(0x138)+_0x3a68db+')','i');let _0xbe0af=-0x1,_0x5ed71b=-0x1,_0x9145fd=0x0,_0x56ebce=![];for(let _0x5e13a3=0x0;_0x5e13a3<_0x170ee1['length'];_0x5e13a3++){const _0x23e4f0=_0x170ee1[_0x5e13a3];if(!_0x56ebce&&_0x6857dc[_0x12c6dd(0x159)](_0x23e4f0)){_0xbe0af=_0x5e13a3+0x1,_0x56ebce=!![],_0x9145fd+=(_0x23e4f0[_0x12c6dd(0x141)](/\{/g)||[])['length'],_0x9145fd-=(_0x23e4f0['match'](/\}/g)||[])[_0x12c6dd(0x16a)];if(_0x9145fd===0x0&&_0x23e4f0['includes'](';')){_0x5ed71b=_0x5e13a3+0x1;break;}continue;}if(_0x56ebce){_0x9145fd+=(_0x23e4f0['match'](/\{/g)||[])['length'],_0x9145fd-=(_0x23e4f0['match'](/\}/g)||[])[_0x12c6dd(0x16a)];if(_0x9145fd<=0x0){_0x5ed71b=_0x5e13a3+0x1;break;}}}if(_0xbe0af===-0x1)throw new Error(_0x12c6dd(0x131)+_0x3a68db+_0x12c6dd(0x152));const _0x4ff31e=_0x170ee1['slice'](_0xbe0af-0x1,_0x5ed71b)['join']('\x0a');return{'content':_0x4ff31e,'startLine':_0xbe0af,'endLine':_0x5ed71b,'signature':this[_0x12c6dd(0x16c)](_0x4ff31e,_0x3a68db),'dependencies':this['extractDependencies'](_0x4ff31e)};}[a0_0x543338(0x16c)](_0x3fe4a4,_0x4fee94){const _0x3aeb7c=a0_0x543338,_0x5185e3=_0x3fe4a4[_0x3aeb7c(0x180)]('\x0a'),_0x463f7f=_0x5185e3[0x0]['trim'](),_0xc96c79=new RegExp(_0x3aeb7c(0x186)+_0x4fee94+'[^{;]*)[{;]?'),_0x3a6296=_0x463f7f[_0x3aeb7c(0x141)](_0xc96c79);return _0x3a6296?_0x3a6296[0x1][_0x3aeb7c(0x110)]():_0x463f7f;}[a0_0x543338(0x132)](_0x24580b){const _0x487306=a0_0x543338,_0x5e3497=[],importRegex=/import\s+.*?\s+from\s+['"]([^'"]+)['"]/g;let _0x3a638f;while((_0x3a638f=importRegex['exec'](_0x24580b))!==null){_0x5e3497['push'](_0x3a638f[0x1]);}const requireRegex=/require\(['"]([^'"]+)['"]\)/g;while((_0x3a638f=requireRegex[_0x487306(0x11a)](_0x24580b))!==null){_0x5e3497[_0x487306(0x172)](_0x3a638f[0x1]);}return[...new Set(_0x5e3497)];}[a0_0x543338(0x167)](_0x1d8124,_0x1b84cd){const _0xb2a741=a0_0x543338;let _0x5ad195='Directory:\x20'+_0x1d8124+'\x0a\x0a';const _0x2a31b8=_0x1b84cd[_0xb2a741(0x151)](_0x2bf5d4=>_0x2bf5d4['type']===_0xb2a741(0x135)),_0x5024fe=_0x1b84cd['filter'](_0x2d826a=>_0x2d826a[_0xb2a741(0x13d)]==='file');if(_0x2a31b8[_0xb2a741(0x16a)]>0x0){_0x5ad195+=_0xb2a741(0x17b);for(const _0x1c317f of _0x2a31b8){_0x5ad195+='\x20\x20📁\x20'+_0x1c317f[_0xb2a741(0x13b)]+(_0x1c317f['isSymbolicLink']?'\x20(symlink)':'')+'\x0a';}_0x5ad195+='\x0a';}if(_0x5024fe[_0xb2a741(0x16a)]>0x0){_0x5ad195+='Files:\x0a';for(const _0x27d5c9 of _0x5024fe){const _0x309ef4=this['getFileIcon'](_0x27d5c9['name']);_0x5ad195+='\x20\x20'+_0x309ef4+'\x20'+_0x27d5c9['name']+(_0x27d5c9[_0xb2a741(0x161)]?_0xb2a741(0x15e):'')+'\x0a';}}return _0x1b84cd[_0xb2a741(0x16a)]===0x0&&(_0x5ad195+='(empty\x20directory)\x0a'),_0x5ad195;}[a0_0x543338(0x13f)](_0x40f1ce){const _0x787aaa={'file':0x1,'component':0x2,'selection':0x3,'directory':0x4};return[..._0x40f1ce]['sort']((_0x1ae974,_0x3e8844)=>{const _0x12cbaf=a0_0x5e4e,_0x32db25=_0x787aaa[_0x1ae974[_0x12cbaf(0x13d)]]||0x3e7,_0x562245=_0x787aaa[_0x3e8844[_0x12cbaf(0x13d)]]||0x3e7;return _0x32db25-_0x562245;});}[a0_0x543338(0x13a)](_0x22dc10){const _0x5e6eee={'file':'📄','component':'🔧','selection':'✂️','directory':'📁'};return _0x5e6eee[_0x22dc10]||'📎';}[a0_0x543338(0x14d)](_0x20ad08){const _0x35b54e=a0_0x543338,_0x46c4e9=a0_0x1a83c0[_0x35b54e(0x10f)](_0x20ad08)[_0x35b54e(0x12d)](),_0x44a34f={'.js':'📜','.jsx':'⚛️','.ts':'📘','.tsx':'⚛️','.py':'🐍','.java':'☕','.html':'🌐','.css':'🎨','.json':'📋','.md':'📝','.yml':'⚙️','.yaml':'⚙️'};return _0x44a34f[_0x46c4e9]||'📄';}['getLanguageFromPath'](_0x3c4484){const _0x720832=a0_0x543338;if(!_0x3c4484)return'';const _0x12770e=a0_0x1a83c0['extname'](_0x3c4484)[_0x720832(0x12d)](),_0x5d0b70={'.js':_0x720832(0x10e),'.jsx':'jsx','.ts':_0x720832(0x123),'.tsx':_0x720832(0x173),'.py':'python','.java':_0x720832(0x115),'.cpp':_0x720832(0x113),'.c':'c','.cs':'csharp','.php':_0x720832(0x17d),'.rb':_0x720832(0x15a),'.go':'go','.rs':_0x720832(0x169),'.html':'html','.css':_0x720832(0x128),'.scss':_0x720832(0x154),'.json':_0x720832(0x137),'.yml':_0x720832(0x17c),'.yaml':'yaml','.md':'markdown','.xml':_0x720832(0x177),'.sql':_0x720832(0x130)};return _0x5d0b70[_0x12770e]||'';}[a0_0x543338(0x13e)](_0x33b2b7){const _0x1ca961=a0_0x543338;return a0_0x29b37e['createHash'](_0x1ca961(0x13c))[_0x1ca961(0x122)](_0x33b2b7)['digest'](_0x1ca961(0x179))[_0x1ca961(0x155)](0x0,0x10);}['compareSelections'](_0x2c77a3,_0xaecfa7){const _0x3d6f7b=a0_0x543338,_0x9470fd=_0x4332ae=>_0x4332ae['replace'](/\s+/g,'\x20')[_0x3d6f7b(0x110)]();return _0x9470fd(_0x2c77a3)===_0x9470fd(_0xaecfa7);}[a0_0x543338(0x116)](_0xa38b8f,_0xeaa22e){const _0x13d0a7=a0_0x543338,_0x5640a9={'type':_0xa38b8f[_0x13d0a7(0x13d)],'path':_0xa38b8f['path']||_0xa38b8f[_0x13d0a7(0x188)],'lines':_0xa38b8f[_0x13d0a7(0x16b)],'name':_0xa38b8f[_0x13d0a7(0x13b)],'projectDir':_0xeaa22e};return a0_0x29b37e['createHash'](_0x13d0a7(0x14c))['update'](JSON['stringify'](_0x5640a9))[_0x13d0a7(0x11b)]('hex');}['getFromCache'](_0x2ddb5c){const _0xea15ef=a0_0x543338,_0x648af5=this['contextCache']['get'](_0x2ddb5c);if(!_0x648af5)return null;return _0x648af5[_0xea15ef(0x184)];}['addToCache'](_0x5c2091,_0xed4d9c){const _0x2563e8=a0_0x543338;this['contextCache']['set'](_0x5c2091,{'data':_0xed4d9c,'timestamp':Date[_0x2563e8(0x163)]()}),this[_0x2563e8(0x149)]();}[a0_0x543338(0x114)](_0x43bbf5){const _0x3d336f=a0_0x543338;if(!this[_0x3d336f(0x14b)])return![];const _0x588e6b=(Date['now']()-new Date(_0x43bbf5[_0x3d336f(0x119)])['getTime']())/0x3e8;return _0x588e6b>this['cacheExpiry'];}[a0_0x543338(0x149)](){const _0x3c88b3=a0_0x543338,_0x17c0de=Date['now'](),_0x4572d5=[];for(const [_0xce5933,_0x14ab28]of this[_0x3c88b3(0x136)][_0x3c88b3(0x125)]()){_0x17c0de-_0x14ab28['timestamp']>this['cacheExpiry']*0x3e8&&_0x4572d5[_0x3c88b3(0x172)](_0xce5933);}for(const _0x29842e of _0x4572d5){this[_0x3c88b3(0x136)][_0x3c88b3(0x183)](_0x29842e);}}}export default ContextManager;