@loxia-labs/loxia-autopilot-one 1.0.1 → 1.0.3
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/README.md +44 -54
- package/bin/cli.js +1 -115
- package/bin/loxia-terminal-v2.js +3 -0
- package/bin/loxia-terminal.js +3 -0
- package/bin/start-with-terminal.js +3 -0
- package/package.json +14 -15
- package/scripts/install-scanners.js +1 -235
- package/src/analyzers/CSSAnalyzer.js +1 -297
- package/src/analyzers/ConfigValidator.js +1 -690
- package/src/analyzers/ESLintAnalyzer.js +1 -320
- package/src/analyzers/JavaScriptAnalyzer.js +1 -261
- package/src/analyzers/PrettierFormatter.js +1 -247
- package/src/analyzers/PythonAnalyzer.js +1 -266
- package/src/analyzers/SecurityAnalyzer.js +1 -729
- package/src/analyzers/TypeScriptAnalyzer.js +1 -247
- package/src/analyzers/codeCloneDetector/analyzer.js +1 -344
- package/src/analyzers/codeCloneDetector/detector.js +1 -203
- package/src/analyzers/codeCloneDetector/index.js +1 -160
- package/src/analyzers/codeCloneDetector/parser.js +1 -199
- package/src/analyzers/codeCloneDetector/reporter.js +1 -148
- package/src/analyzers/codeCloneDetector/scanner.js +1 -59
- package/src/core/agentPool.js +1 -1474
- package/src/core/agentScheduler.js +1 -2147
- package/src/core/contextManager.js +1 -709
- package/src/core/messageProcessor.js +1 -732
- package/src/core/orchestrator.js +1 -548
- package/src/core/stateManager.js +1 -877
- package/src/index.js +1 -631
- package/src/interfaces/cli.js +1 -549
- package/src/interfaces/terminal/__tests__/smoke/advancedFeatures.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/agentControl.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/agents.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/components.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/connection.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/imports.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/messages.test.js +1 -0
- package/src/interfaces/terminal/__tests__/smoke/tools.test.js +1 -0
- package/src/interfaces/terminal/api/apiClient.js +1 -0
- package/src/interfaces/terminal/api/messageRouter.js +1 -0
- package/src/interfaces/terminal/api/session.js +1 -0
- package/src/interfaces/terminal/api/websocket.js +1 -0
- package/src/interfaces/terminal/components/AgentCreator.js +1 -0
- package/src/interfaces/terminal/components/AgentEditor.js +1 -0
- package/src/interfaces/terminal/components/AgentSwitcher.js +1 -0
- package/src/interfaces/terminal/components/ErrorBoundary.js +1 -0
- package/src/interfaces/terminal/components/ErrorPanel.js +1 -0
- package/src/interfaces/terminal/components/Header.js +1 -0
- package/src/interfaces/terminal/components/HelpPanel.js +1 -0
- package/src/interfaces/terminal/components/InputBox.js +1 -0
- package/src/interfaces/terminal/components/Layout.js +1 -0
- package/src/interfaces/terminal/components/LoadingSpinner.js +1 -0
- package/src/interfaces/terminal/components/MessageList.js +1 -0
- package/src/interfaces/terminal/components/MultilineTextInput.js +1 -0
- package/src/interfaces/terminal/components/SearchPanel.js +1 -0
- package/src/interfaces/terminal/components/SettingsPanel.js +1 -0
- package/src/interfaces/terminal/components/StatusBar.js +1 -0
- package/src/interfaces/terminal/components/TextInput.js +1 -0
- package/src/interfaces/terminal/config/agentEditorConstants.js +1 -0
- package/src/interfaces/terminal/config/constants.js +1 -0
- package/src/interfaces/terminal/index.js +1 -0
- package/src/interfaces/terminal/state/useAgentControl.js +1 -0
- package/src/interfaces/terminal/state/useAgents.js +1 -0
- package/src/interfaces/terminal/state/useConnection.js +1 -0
- package/src/interfaces/terminal/state/useMessages.js +1 -0
- package/src/interfaces/terminal/state/useTools.js +1 -0
- package/src/interfaces/terminal/utils/debugLogger.js +1 -0
- package/src/interfaces/terminal/utils/settingsStorage.js +1 -0
- package/src/interfaces/terminal/utils/theme.js +1 -0
- package/src/interfaces/webServer.js +1 -2162
- package/src/modules/fileExplorer/controller.js +1 -280
- package/src/modules/fileExplorer/index.js +1 -37
- package/src/modules/fileExplorer/middleware.js +1 -92
- package/src/modules/fileExplorer/routes.js +1 -125
- package/src/modules/fileExplorer/types.js +1 -44
- package/src/services/aiService.js +1 -1232
- package/src/services/apiKeyManager.js +1 -164
- package/src/services/benchmarkService.js +1 -366
- package/src/services/budgetService.js +1 -539
- package/src/services/contextInjectionService.js +1 -247
- package/src/services/conversationCompactionService.js +1 -637
- package/src/services/errorHandler.js +1 -810
- package/src/services/fileAttachmentService.js +1 -544
- package/src/services/modelRouterService.js +1 -366
- package/src/services/modelsService.js +1 -322
- package/src/services/qualityInspector.js +1 -796
- package/src/services/tokenCountingService.js +1 -536
- package/src/tools/agentCommunicationTool.js +1 -1344
- package/src/tools/agentDelayTool.js +1 -485
- package/src/tools/asyncToolManager.js +1 -604
- package/src/tools/baseTool.js +1 -800
- package/src/tools/browserTool.js +1 -920
- package/src/tools/cloneDetectionTool.js +1 -621
- package/src/tools/dependencyResolverTool.js +1 -1215
- package/src/tools/fileContentReplaceTool.js +1 -875
- package/src/tools/fileSystemTool.js +1 -1107
- package/src/tools/fileTreeTool.js +1 -853
- package/src/tools/imageTool.js +1 -901
- package/src/tools/importAnalyzerTool.js +1 -1060
- package/src/tools/jobDoneTool.js +1 -248
- package/src/tools/seekTool.js +1 -956
- package/src/tools/staticAnalysisTool.js +1 -1778
- package/src/tools/taskManagerTool.js +1 -2873
- package/src/tools/terminalTool.js +1 -2304
- package/src/tools/webTool.js +1 -1430
- package/src/types/agent.js +1 -519
- package/src/types/contextReference.js +1 -972
- package/src/types/conversation.js +1 -730
- package/src/types/toolCommand.js +1 -747
- package/src/utilities/attachmentValidator.js +1 -292
- package/src/utilities/configManager.js +1 -582
- package/src/utilities/constants.js +1 -722
- package/src/utilities/directoryAccessManager.js +1 -535
- package/src/utilities/fileProcessor.js +1 -307
- package/src/utilities/logger.js +1 -436
- package/src/utilities/tagParser.js +1 -1246
- package/src/utilities/toolConstants.js +1 -317
- package/web-ui/build/index.html +2 -2
- package/web-ui/build/static/{index-Dy2bYbOa.css → index-CClD1090.css} +1 -1
- package/web-ui/build/static/{index-CjkkcnFA.js → index-lCBai6dX.js} +66 -67
|
@@ -1,972 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Reference Data Model - Type definitions and validation for context references
|
|
3
|
-
*
|
|
4
|
-
* Purpose:
|
|
5
|
-
* - Define the structure and properties of context references
|
|
6
|
-
* - Provide validation functions for context reference data
|
|
7
|
-
* - Handle context reference resolution and management
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { CONTEXT_REFERENCE_TYPES, FILE_EXTENSIONS, CONTEXT_ICONS } from '../utilities/constants.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Context Reference data model
|
|
14
|
-
* @typedef {Object} ContextReference
|
|
15
|
-
* @property {string} id - Unique reference identifier
|
|
16
|
-
* @property {string} type - Reference type (file, component, selection, directory)
|
|
17
|
-
* @property {string} path - Path or identifier of referenced item
|
|
18
|
-
* @property {string} name - Human-readable name
|
|
19
|
-
* @property {string} [content] - Referenced content (if loaded)
|
|
20
|
-
* @property {ReferenceMetadata} metadata - Reference metadata
|
|
21
|
-
* @property {ReferenceScope} scope - Reference scope and boundaries
|
|
22
|
-
* @property {string} createdAt - ISO timestamp of creation
|
|
23
|
-
* @property {string} [lastAccessed] - ISO timestamp of last access
|
|
24
|
-
* @property {string} [lastModified] - ISO timestamp of last modification
|
|
25
|
-
* @property {boolean} isValid - Whether reference is still valid
|
|
26
|
-
* @property {string} [invalidReason] - Reason for invalidity
|
|
27
|
-
* @property {number} accessCount - Number of times accessed
|
|
28
|
-
* @property {Object} tags - Reference tags and labels
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Reference metadata
|
|
33
|
-
* @typedef {Object} ReferenceMetadata
|
|
34
|
-
* @property {string} [language] - Programming language (for code files)
|
|
35
|
-
* @property {string} [encoding] - File encoding
|
|
36
|
-
* @property {number} [size] - Content size in bytes
|
|
37
|
-
* @property {string} [mimeType] - MIME type
|
|
38
|
-
* @property {string} [checksum] - Content checksum for integrity
|
|
39
|
-
* @property {string[]} [keywords] - Extracted keywords
|
|
40
|
-
* @property {string} [description] - Reference description
|
|
41
|
-
* @property {Object} [customFields] - Custom metadata fields
|
|
42
|
-
* @property {string} [icon] - Display icon identifier
|
|
43
|
-
* @property {Object} [permissions] - Access permissions
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Reference scope and boundaries
|
|
48
|
-
* @typedef {Object} ReferenceScope
|
|
49
|
-
* @property {number} [startLine] - Start line number (for selections)
|
|
50
|
-
* @property {number} [endLine] - End line number (for selections)
|
|
51
|
-
* @property {number} [startColumn] - Start column number
|
|
52
|
-
* @property {number} [endColumn] - End column number
|
|
53
|
-
* @property {string} [functionName] - Function/method name (for code)
|
|
54
|
-
* @property {string} [className] - Class name (for code)
|
|
55
|
-
* @property {string} [namespace] - Namespace or module (for code)
|
|
56
|
-
* @property {string[]} [includePaths] - Included sub-paths (for directories)
|
|
57
|
-
* @property {string[]} [excludePaths] - Excluded sub-paths (for directories)
|
|
58
|
-
* @property {number} [maxDepth] - Maximum directory depth
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* File Reference (extends ContextReference)
|
|
63
|
-
* @typedef {Object} FileReference
|
|
64
|
-
* @property {string} absolutePath - Absolute file path
|
|
65
|
-
* @property {string} relativePath - Relative file path from workspace
|
|
66
|
-
* @property {string} extension - File extension
|
|
67
|
-
* @property {boolean} exists - Whether file exists on filesystem
|
|
68
|
-
* @property {FileStats} [stats] - File system statistics
|
|
69
|
-
* @property {string} [gitStatus] - Git status of file
|
|
70
|
-
* @property {DependencyInfo} [dependencies] - File dependencies
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Directory Reference (extends ContextReference)
|
|
75
|
-
* @typedef {Object} DirectoryReference
|
|
76
|
-
* @property {string} absolutePath - Absolute directory path
|
|
77
|
-
* @property {string} relativePath - Relative directory path from workspace
|
|
78
|
-
* @property {FileSystemTree} [tree] - Directory tree structure
|
|
79
|
-
* @property {number} [fileCount] - Number of files in directory
|
|
80
|
-
* @property {number} [totalSize] - Total size of directory contents
|
|
81
|
-
* @property {string[]} [fileTypes] - File types present in directory
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Selection Reference (extends ContextReference)
|
|
86
|
-
* @typedef {Object} SelectionReference
|
|
87
|
-
* @property {string} sourceFile - Source file path
|
|
88
|
-
* @property {string} selectedText - Selected text content
|
|
89
|
-
* @property {SyntaxInfo} [syntax] - Syntax information
|
|
90
|
-
* @property {ContextInfo} [context] - Surrounding context
|
|
91
|
-
* @property {string} [purpose] - Purpose of selection
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Component Reference (extends ContextReference)
|
|
96
|
-
* @typedef {Object} ComponentReference
|
|
97
|
-
* @property {string} componentType - Type of component
|
|
98
|
-
* @property {string} [sourceFile] - Source file containing component
|
|
99
|
-
* @property {Object} [properties] - Component properties
|
|
100
|
-
* @property {string[]} [dependencies] - Component dependencies
|
|
101
|
-
* @property {string} [documentation] - Component documentation
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* File system statistics
|
|
106
|
-
* @typedef {Object} FileStats
|
|
107
|
-
* @property {number} size - File size in bytes
|
|
108
|
-
* @property {string} created - Creation timestamp
|
|
109
|
-
* @property {string} modified - Last modification timestamp
|
|
110
|
-
* @property {string} accessed - Last access timestamp
|
|
111
|
-
* @property {boolean} isDirectory - Whether item is directory
|
|
112
|
-
* @property {boolean} isFile - Whether item is file
|
|
113
|
-
* @property {number} mode - File permissions mode
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* File system tree structure
|
|
118
|
-
* @typedef {Object} FileSystemTree
|
|
119
|
-
* @property {string} name - Item name
|
|
120
|
-
* @property {string} path - Item path
|
|
121
|
-
* @property {string} type - Item type (file, directory)
|
|
122
|
-
* @property {FileSystemTree[]} [children] - Child items (for directories)
|
|
123
|
-
* @property {number} [size] - Item size
|
|
124
|
-
* @property {string} [extension] - File extension
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Syntax information
|
|
129
|
-
* @typedef {Object} SyntaxInfo
|
|
130
|
-
* @property {string} language - Programming language
|
|
131
|
-
* @property {string[]} [symbols] - Identified symbols
|
|
132
|
-
* @property {string[]} [imports] - Import statements
|
|
133
|
-
* @property {string[]} [functions] - Function definitions
|
|
134
|
-
* @property {string[]} [classes] - Class definitions
|
|
135
|
-
* @property {string[]} [variables] - Variable definitions
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Context information
|
|
140
|
-
* @typedef {Object} ContextInfo
|
|
141
|
-
* @property {string} [beforeText] - Text before selection
|
|
142
|
-
* @property {string} [afterText] - Text after selection
|
|
143
|
-
* @property {number} [indentLevel] - Indentation level
|
|
144
|
-
* @property {string[]} [surroundingFunctions] - Surrounding function names
|
|
145
|
-
* @property {string[]} [surroundingClasses] - Surrounding class names
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Dependency information
|
|
150
|
-
* @typedef {Object} DependencyInfo
|
|
151
|
-
* @property {string[]} imports - Imported modules/files
|
|
152
|
-
* @property {string[]} exports - Exported items
|
|
153
|
-
* @property {string[]} dependencies - External dependencies
|
|
154
|
-
* @property {string[]} dependents - Files that depend on this file
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Context Reference validation functions
|
|
159
|
-
*/
|
|
160
|
-
export class ContextReferenceValidator {
|
|
161
|
-
/**
|
|
162
|
-
* Validate context reference data structure
|
|
163
|
-
* @param {Object} reference - Context reference to validate
|
|
164
|
-
* @returns {Object} Validation result
|
|
165
|
-
*/
|
|
166
|
-
static validate(reference) {
|
|
167
|
-
const errors = [];
|
|
168
|
-
const warnings = [];
|
|
169
|
-
|
|
170
|
-
// Required fields
|
|
171
|
-
if (!reference.id || typeof reference.id !== 'string') {
|
|
172
|
-
errors.push('Reference ID is required and must be a string');
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!reference.type || typeof reference.type !== 'string') {
|
|
176
|
-
errors.push('Reference type is required and must be a string');
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (!reference.path || typeof reference.path !== 'string') {
|
|
180
|
-
errors.push('Reference path is required and must be a string');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!reference.name || typeof reference.name !== 'string') {
|
|
184
|
-
errors.push('Reference name is required and must be a string');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Type validation
|
|
188
|
-
if (reference.type && !Object.values(CONTEXT_REFERENCE_TYPES).includes(reference.type)) {
|
|
189
|
-
errors.push(`Invalid reference type: ${reference.type}`);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// Content validation
|
|
193
|
-
if (reference.content && typeof reference.content !== 'string') {
|
|
194
|
-
errors.push('Reference content must be a string');
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (reference.content && reference.content.length > 1000000) { // 1MB
|
|
198
|
-
warnings.push('Reference content is very large (>1MB)');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// Metadata validation
|
|
202
|
-
if (reference.metadata) {
|
|
203
|
-
const metadataValidation = this.validateMetadata(reference.metadata);
|
|
204
|
-
errors.push(...metadataValidation.errors);
|
|
205
|
-
warnings.push(...metadataValidation.warnings);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Scope validation
|
|
209
|
-
if (reference.scope) {
|
|
210
|
-
const scopeValidation = this.validateScope(reference.scope);
|
|
211
|
-
errors.push(...scopeValidation.errors);
|
|
212
|
-
warnings.push(...scopeValidation.warnings);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Access count validation
|
|
216
|
-
if (reference.accessCount !== undefined && typeof reference.accessCount !== 'number') {
|
|
217
|
-
errors.push('Access count must be a number');
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Timestamp validation
|
|
221
|
-
const timestampFields = ['createdAt', 'lastAccessed', 'lastModified'];
|
|
222
|
-
timestampFields.forEach(field => {
|
|
223
|
-
if (reference[field] && !this.isValidTimestamp(reference[field])) {
|
|
224
|
-
errors.push(`Invalid timestamp for ${field}: ${reference[field]}`);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
// Type-specific validation
|
|
229
|
-
switch (reference.type) {
|
|
230
|
-
case CONTEXT_REFERENCE_TYPES.FILE:
|
|
231
|
-
const fileValidation = this.validateFileReference(reference);
|
|
232
|
-
errors.push(...fileValidation.errors);
|
|
233
|
-
warnings.push(...fileValidation.warnings);
|
|
234
|
-
break;
|
|
235
|
-
case CONTEXT_REFERENCE_TYPES.SELECTION:
|
|
236
|
-
const selectionValidation = this.validateSelectionReference(reference);
|
|
237
|
-
errors.push(...selectionValidation.errors);
|
|
238
|
-
warnings.push(...selectionValidation.warnings);
|
|
239
|
-
break;
|
|
240
|
-
case CONTEXT_REFERENCE_TYPES.DIRECTORY:
|
|
241
|
-
const directoryValidation = this.validateDirectoryReference(reference);
|
|
242
|
-
errors.push(...directoryValidation.errors);
|
|
243
|
-
warnings.push(...directoryValidation.warnings);
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
isValid: errors.length === 0,
|
|
249
|
-
errors,
|
|
250
|
-
warnings
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Validate reference metadata
|
|
256
|
-
* @param {Object} metadata - Metadata to validate
|
|
257
|
-
* @returns {Object} Validation result
|
|
258
|
-
*/
|
|
259
|
-
static validateMetadata(metadata) {
|
|
260
|
-
const errors = [];
|
|
261
|
-
const warnings = [];
|
|
262
|
-
|
|
263
|
-
if (metadata.size !== undefined && (typeof metadata.size !== 'number' || metadata.size < 0)) {
|
|
264
|
-
errors.push('Metadata size must be a non-negative number');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (metadata.language && typeof metadata.language !== 'string') {
|
|
268
|
-
errors.push('Metadata language must be a string');
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (metadata.encoding && typeof metadata.encoding !== 'string') {
|
|
272
|
-
errors.push('Metadata encoding must be a string');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (metadata.keywords && !Array.isArray(metadata.keywords)) {
|
|
276
|
-
errors.push('Metadata keywords must be an array');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (metadata.mimeType && typeof metadata.mimeType !== 'string') {
|
|
280
|
-
errors.push('Metadata MIME type must be a string');
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return { errors, warnings };
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Validate reference scope
|
|
288
|
-
* @param {Object} scope - Scope to validate
|
|
289
|
-
* @returns {Object} Validation result
|
|
290
|
-
*/
|
|
291
|
-
static validateScope(scope) {
|
|
292
|
-
const errors = [];
|
|
293
|
-
const warnings = [];
|
|
294
|
-
|
|
295
|
-
const numericFields = ['startLine', 'endLine', 'startColumn', 'endColumn', 'maxDepth'];
|
|
296
|
-
numericFields.forEach(field => {
|
|
297
|
-
if (scope[field] !== undefined && (typeof scope[field] !== 'number' || scope[field] < 0)) {
|
|
298
|
-
errors.push(`Scope ${field} must be a non-negative number`);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// Line range validation
|
|
303
|
-
if (scope.startLine !== undefined && scope.endLine !== undefined) {
|
|
304
|
-
if (scope.startLine > scope.endLine) {
|
|
305
|
-
errors.push('Start line must be <= end line');
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Column range validation
|
|
310
|
-
if (scope.startColumn !== undefined && scope.endColumn !== undefined) {
|
|
311
|
-
if (scope.startColumn > scope.endColumn) {
|
|
312
|
-
errors.push('Start column must be <= end column');
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const arrayFields = ['includePaths', 'excludePaths'];
|
|
317
|
-
arrayFields.forEach(field => {
|
|
318
|
-
if (scope[field] && !Array.isArray(scope[field])) {
|
|
319
|
-
errors.push(`Scope ${field} must be an array`);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
return { errors, warnings };
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Validate file reference specific fields
|
|
328
|
-
* @param {Object} reference - File reference to validate
|
|
329
|
-
* @returns {Object} Validation result
|
|
330
|
-
*/
|
|
331
|
-
static validateFileReference(reference) {
|
|
332
|
-
const errors = [];
|
|
333
|
-
const warnings = [];
|
|
334
|
-
|
|
335
|
-
if (reference.absolutePath && typeof reference.absolutePath !== 'string') {
|
|
336
|
-
errors.push('Absolute path must be a string');
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (reference.relativePath && typeof reference.relativePath !== 'string') {
|
|
340
|
-
errors.push('Relative path must be a string');
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (reference.extension && typeof reference.extension !== 'string') {
|
|
344
|
-
errors.push('File extension must be a string');
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (reference.exists !== undefined && typeof reference.exists !== 'boolean') {
|
|
348
|
-
errors.push('File exists flag must be a boolean');
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
return { errors, warnings };
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Validate selection reference specific fields
|
|
356
|
-
* @param {Object} reference - Selection reference to validate
|
|
357
|
-
* @returns {Object} Validation result
|
|
358
|
-
*/
|
|
359
|
-
static validateSelectionReference(reference) {
|
|
360
|
-
const errors = [];
|
|
361
|
-
const warnings = [];
|
|
362
|
-
|
|
363
|
-
if (!reference.scope || (!reference.scope.startLine && !reference.scope.endLine)) {
|
|
364
|
-
warnings.push('Selection reference should have line scope defined');
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (reference.selectedText && typeof reference.selectedText !== 'string') {
|
|
368
|
-
errors.push('Selected text must be a string');
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (reference.sourceFile && typeof reference.sourceFile !== 'string') {
|
|
372
|
-
errors.push('Source file must be a string');
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return { errors, warnings };
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Validate directory reference specific fields
|
|
380
|
-
* @param {Object} reference - Directory reference to validate
|
|
381
|
-
* @returns {Object} Validation result
|
|
382
|
-
*/
|
|
383
|
-
static validateDirectoryReference(reference) {
|
|
384
|
-
const errors = [];
|
|
385
|
-
const warnings = [];
|
|
386
|
-
|
|
387
|
-
if (reference.fileCount !== undefined && (typeof reference.fileCount !== 'number' || reference.fileCount < 0)) {
|
|
388
|
-
errors.push('File count must be a non-negative number');
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (reference.totalSize !== undefined && (typeof reference.totalSize !== 'number' || reference.totalSize < 0)) {
|
|
392
|
-
errors.push('Total size must be a non-negative number');
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (reference.fileTypes && !Array.isArray(reference.fileTypes)) {
|
|
396
|
-
errors.push('File types must be an array');
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
return { errors, warnings };
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Check if a timestamp is valid ISO string
|
|
404
|
-
* @param {string} timestamp - Timestamp to validate
|
|
405
|
-
* @returns {boolean} True if valid
|
|
406
|
-
*/
|
|
407
|
-
static isValidTimestamp(timestamp) {
|
|
408
|
-
if (typeof timestamp !== 'string') return false;
|
|
409
|
-
const date = new Date(timestamp);
|
|
410
|
-
return date instanceof Date && !isNaN(date.getTime());
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Context Reference factory functions
|
|
416
|
-
*/
|
|
417
|
-
export class ContextReferenceFactory {
|
|
418
|
-
/**
|
|
419
|
-
* Create a new context reference
|
|
420
|
-
* @param {string} type - Reference type
|
|
421
|
-
* @param {string} path - Reference path
|
|
422
|
-
* @param {string} name - Reference name
|
|
423
|
-
* @param {Object} options - Additional options
|
|
424
|
-
* @returns {ContextReference} New context reference
|
|
425
|
-
*/
|
|
426
|
-
static create(type, path, name, options = {}) {
|
|
427
|
-
const now = new Date().toISOString();
|
|
428
|
-
const referenceId = this.generateReferenceId();
|
|
429
|
-
|
|
430
|
-
return {
|
|
431
|
-
id: referenceId,
|
|
432
|
-
type,
|
|
433
|
-
path,
|
|
434
|
-
name,
|
|
435
|
-
content: options.content || null,
|
|
436
|
-
metadata: this.createDefaultMetadata(type, path, options.metadata),
|
|
437
|
-
scope: options.scope || {},
|
|
438
|
-
createdAt: now,
|
|
439
|
-
lastAccessed: null,
|
|
440
|
-
lastModified: options.lastModified || null,
|
|
441
|
-
isValid: true,
|
|
442
|
-
invalidReason: null,
|
|
443
|
-
accessCount: 0,
|
|
444
|
-
tags: options.tags || {}
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Create a file reference
|
|
450
|
-
* @param {string} absolutePath - Absolute file path
|
|
451
|
-
* @param {string} relativePath - Relative file path
|
|
452
|
-
* @param {Object} options - Additional options
|
|
453
|
-
* @returns {FileReference} File reference
|
|
454
|
-
*/
|
|
455
|
-
static createFileReference(absolutePath, relativePath, options = {}) {
|
|
456
|
-
const name = options.name || this.extractFileName(absolutePath);
|
|
457
|
-
const extension = this.extractFileExtension(absolutePath);
|
|
458
|
-
|
|
459
|
-
const reference = this.create(CONTEXT_REFERENCE_TYPES.FILE, relativePath, name, options);
|
|
460
|
-
|
|
461
|
-
return {
|
|
462
|
-
...reference,
|
|
463
|
-
absolutePath,
|
|
464
|
-
relativePath,
|
|
465
|
-
extension,
|
|
466
|
-
exists: options.exists !== undefined ? options.exists : true,
|
|
467
|
-
stats: options.stats || null,
|
|
468
|
-
gitStatus: options.gitStatus || null,
|
|
469
|
-
dependencies: options.dependencies || null
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Create a selection reference
|
|
475
|
-
* @param {string} sourceFile - Source file path
|
|
476
|
-
* @param {string} selectedText - Selected text
|
|
477
|
-
* @param {Object} scope - Selection scope
|
|
478
|
-
* @param {Object} options - Additional options
|
|
479
|
-
* @returns {SelectionReference} Selection reference
|
|
480
|
-
*/
|
|
481
|
-
static createSelectionReference(sourceFile, selectedText, scope, options = {}) {
|
|
482
|
-
const name = options.name || this.generateSelectionName(sourceFile, scope);
|
|
483
|
-
|
|
484
|
-
const reference = this.create(CONTEXT_REFERENCE_TYPES.SELECTION, sourceFile, name, {
|
|
485
|
-
...options,
|
|
486
|
-
scope,
|
|
487
|
-
content: selectedText
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
return {
|
|
491
|
-
...reference,
|
|
492
|
-
sourceFile,
|
|
493
|
-
selectedText,
|
|
494
|
-
syntax: options.syntax || null,
|
|
495
|
-
context: options.context || null,
|
|
496
|
-
purpose: options.purpose || null
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Create a directory reference
|
|
502
|
-
* @param {string} absolutePath - Absolute directory path
|
|
503
|
-
* @param {string} relativePath - Relative directory path
|
|
504
|
-
* @param {Object} options - Additional options
|
|
505
|
-
* @returns {DirectoryReference} Directory reference
|
|
506
|
-
*/
|
|
507
|
-
static createDirectoryReference(absolutePath, relativePath, options = {}) {
|
|
508
|
-
const name = options.name || this.extractDirectoryName(absolutePath);
|
|
509
|
-
|
|
510
|
-
const reference = this.create(CONTEXT_REFERENCE_TYPES.DIRECTORY, relativePath, name, options);
|
|
511
|
-
|
|
512
|
-
return {
|
|
513
|
-
...reference,
|
|
514
|
-
absolutePath,
|
|
515
|
-
relativePath,
|
|
516
|
-
tree: options.tree || null,
|
|
517
|
-
fileCount: options.fileCount || null,
|
|
518
|
-
totalSize: options.totalSize || null,
|
|
519
|
-
fileTypes: options.fileTypes || null
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Create a component reference
|
|
525
|
-
* @param {string} componentType - Component type
|
|
526
|
-
* @param {string} path - Component path/identifier
|
|
527
|
-
* @param {string} name - Component name
|
|
528
|
-
* @param {Object} options - Additional options
|
|
529
|
-
* @returns {ComponentReference} Component reference
|
|
530
|
-
*/
|
|
531
|
-
static createComponentReference(componentType, path, name, options = {}) {
|
|
532
|
-
const reference = this.create(CONTEXT_REFERENCE_TYPES.COMPONENT, path, name, options);
|
|
533
|
-
|
|
534
|
-
return {
|
|
535
|
-
...reference,
|
|
536
|
-
componentType,
|
|
537
|
-
sourceFile: options.sourceFile || null,
|
|
538
|
-
properties: options.properties || null,
|
|
539
|
-
dependencies: options.dependencies || null,
|
|
540
|
-
documentation: options.documentation || null
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Create default metadata for reference type
|
|
546
|
-
* @param {string} type - Reference type
|
|
547
|
-
* @param {string} path - Reference path
|
|
548
|
-
* @param {Object} overrides - Metadata overrides
|
|
549
|
-
* @returns {ReferenceMetadata} Default metadata
|
|
550
|
-
*/
|
|
551
|
-
static createDefaultMetadata(type, path, overrides = {}) {
|
|
552
|
-
const metadata = {
|
|
553
|
-
language: null,
|
|
554
|
-
encoding: 'utf-8',
|
|
555
|
-
size: null,
|
|
556
|
-
mimeType: null,
|
|
557
|
-
checksum: null,
|
|
558
|
-
keywords: [],
|
|
559
|
-
description: '',
|
|
560
|
-
customFields: {},
|
|
561
|
-
icon: this.getDefaultIcon(type, path),
|
|
562
|
-
permissions: {},
|
|
563
|
-
...overrides
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
// Set language for file references
|
|
567
|
-
if (type === CONTEXT_REFERENCE_TYPES.FILE) {
|
|
568
|
-
const extension = this.extractFileExtension(path);
|
|
569
|
-
metadata.language = this.getLanguageFromExtension(extension);
|
|
570
|
-
metadata.mimeType = this.getMimeTypeFromExtension(extension);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
return metadata;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* Generate unique reference ID
|
|
578
|
-
* @returns {string} Unique reference ID
|
|
579
|
-
*/
|
|
580
|
-
static generateReferenceId() {
|
|
581
|
-
const timestamp = Date.now().toString(36);
|
|
582
|
-
const random = Math.random().toString(36).substr(2, 9);
|
|
583
|
-
return `ref_${timestamp}_${random}`;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
/**
|
|
587
|
-
* Extract file name from path
|
|
588
|
-
* @param {string} path - File path
|
|
589
|
-
* @returns {string} File name
|
|
590
|
-
*/
|
|
591
|
-
static extractFileName(path) {
|
|
592
|
-
return path.split(/[/\\]/).pop() || path;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Extract directory name from path
|
|
597
|
-
* @param {string} path - Directory path
|
|
598
|
-
* @returns {string} Directory name
|
|
599
|
-
*/
|
|
600
|
-
static extractDirectoryName(path) {
|
|
601
|
-
const parts = path.split(/[/\\]/).filter(Boolean);
|
|
602
|
-
return parts[parts.length - 1] || 'Root';
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* Extract file extension from path
|
|
607
|
-
* @param {string} path - File path
|
|
608
|
-
* @returns {string} File extension
|
|
609
|
-
*/
|
|
610
|
-
static extractFileExtension(path) {
|
|
611
|
-
const fileName = this.extractFileName(path);
|
|
612
|
-
const lastDot = fileName.lastIndexOf('.');
|
|
613
|
-
return lastDot !== -1 ? fileName.substring(lastDot) : '';
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Generate selection name from file and scope
|
|
618
|
-
* @param {string} sourceFile - Source file path
|
|
619
|
-
* @param {Object} scope - Selection scope
|
|
620
|
-
* @returns {string} Selection name
|
|
621
|
-
*/
|
|
622
|
-
static generateSelectionName(sourceFile, scope) {
|
|
623
|
-
const fileName = this.extractFileName(sourceFile);
|
|
624
|
-
|
|
625
|
-
if (scope.startLine && scope.endLine) {
|
|
626
|
-
if (scope.startLine === scope.endLine) {
|
|
627
|
-
return `${fileName}:${scope.startLine}`;
|
|
628
|
-
} else {
|
|
629
|
-
return `${fileName}:${scope.startLine}-${scope.endLine}`;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
if (scope.functionName) {
|
|
634
|
-
return `${fileName}:${scope.functionName}()`;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (scope.className) {
|
|
638
|
-
return `${fileName}:${scope.className}`;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return `${fileName} (selection)`;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Get default icon for reference type and path
|
|
646
|
-
* @param {string} type - Reference type
|
|
647
|
-
* @param {string} path - Reference path
|
|
648
|
-
* @returns {string} Icon identifier
|
|
649
|
-
*/
|
|
650
|
-
static getDefaultIcon(type, path) {
|
|
651
|
-
if (type === CONTEXT_REFERENCE_TYPES.FILE) {
|
|
652
|
-
const extension = this.extractFileExtension(path);
|
|
653
|
-
return FILE_ICONS[extension] || CONTEXT_ICONS.DEFAULT;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return CONTEXT_ICONS[type] || CONTEXT_ICONS.DEFAULT;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Get programming language from file extension
|
|
661
|
-
* @param {string} extension - File extension
|
|
662
|
-
* @returns {string|null} Programming language
|
|
663
|
-
*/
|
|
664
|
-
static getLanguageFromExtension(extension) {
|
|
665
|
-
const languageMap = {
|
|
666
|
-
'.js': 'javascript',
|
|
667
|
-
'.jsx': 'javascript',
|
|
668
|
-
'.ts': 'typescript',
|
|
669
|
-
'.tsx': 'typescript',
|
|
670
|
-
'.py': 'python',
|
|
671
|
-
'.java': 'java',
|
|
672
|
-
'.cpp': 'cpp',
|
|
673
|
-
'.c': 'c',
|
|
674
|
-
'.cs': 'csharp',
|
|
675
|
-
'.php': 'php',
|
|
676
|
-
'.rb': 'ruby',
|
|
677
|
-
'.go': 'go',
|
|
678
|
-
'.rs': 'rust',
|
|
679
|
-
'.html': 'html',
|
|
680
|
-
'.css': 'css',
|
|
681
|
-
'.scss': 'scss',
|
|
682
|
-
'.json': 'json',
|
|
683
|
-
'.yml': 'yaml',
|
|
684
|
-
'.yaml': 'yaml',
|
|
685
|
-
'.xml': 'xml',
|
|
686
|
-
'.sql': 'sql',
|
|
687
|
-
'.md': 'markdown'
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
return languageMap[extension.toLowerCase()] || null;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
/**
|
|
694
|
-
* Get MIME type from file extension
|
|
695
|
-
* @param {string} extension - File extension
|
|
696
|
-
* @returns {string|null} MIME type
|
|
697
|
-
*/
|
|
698
|
-
static getMimeTypeFromExtension(extension) {
|
|
699
|
-
const mimeMap = {
|
|
700
|
-
'.js': 'application/javascript',
|
|
701
|
-
'.jsx': 'application/javascript',
|
|
702
|
-
'.ts': 'application/typescript',
|
|
703
|
-
'.tsx': 'application/typescript',
|
|
704
|
-
'.py': 'text/x-python',
|
|
705
|
-
'.java': 'text/x-java-source',
|
|
706
|
-
'.cpp': 'text/x-c++src',
|
|
707
|
-
'.c': 'text/x-csrc',
|
|
708
|
-
'.cs': 'text/x-csharp',
|
|
709
|
-
'.php': 'application/x-php',
|
|
710
|
-
'.rb': 'application/x-ruby',
|
|
711
|
-
'.go': 'text/x-go',
|
|
712
|
-
'.rs': 'text/x-rust',
|
|
713
|
-
'.html': 'text/html',
|
|
714
|
-
'.css': 'text/css',
|
|
715
|
-
'.scss': 'text/x-scss',
|
|
716
|
-
'.json': 'application/json',
|
|
717
|
-
'.yml': 'application/x-yaml',
|
|
718
|
-
'.yaml': 'application/x-yaml',
|
|
719
|
-
'.xml': 'application/xml',
|
|
720
|
-
'.sql': 'application/sql',
|
|
721
|
-
'.md': 'text/markdown',
|
|
722
|
-
'.txt': 'text/plain'
|
|
723
|
-
};
|
|
724
|
-
|
|
725
|
-
return mimeMap[extension.toLowerCase()] || 'text/plain';
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Context Reference utility functions
|
|
731
|
-
*/
|
|
732
|
-
export class ContextReferenceUtils {
|
|
733
|
-
/**
|
|
734
|
-
* Check if reference is still valid
|
|
735
|
-
* @param {ContextReference} reference - Reference to check
|
|
736
|
-
* @returns {boolean} True if valid
|
|
737
|
-
*/
|
|
738
|
-
static isValid(reference) {
|
|
739
|
-
return reference.isValid && !reference.invalidReason;
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
/**
|
|
743
|
-
* Mark reference as accessed
|
|
744
|
-
* @param {ContextReference} reference - Reference to mark
|
|
745
|
-
* @returns {ContextReference} Updated reference
|
|
746
|
-
*/
|
|
747
|
-
static markAccessed(reference) {
|
|
748
|
-
return {
|
|
749
|
-
...reference,
|
|
750
|
-
lastAccessed: new Date().toISOString(),
|
|
751
|
-
accessCount: reference.accessCount + 1
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
/**
|
|
756
|
-
* Mark reference as invalid
|
|
757
|
-
* @param {ContextReference} reference - Reference to invalidate
|
|
758
|
-
* @param {string} reason - Reason for invalidation
|
|
759
|
-
* @returns {ContextReference} Updated reference
|
|
760
|
-
*/
|
|
761
|
-
static markInvalid(reference, reason) {
|
|
762
|
-
return {
|
|
763
|
-
...reference,
|
|
764
|
-
isValid: false,
|
|
765
|
-
invalidReason: reason
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
/**
|
|
770
|
-
* Get reference display name with context
|
|
771
|
-
* @param {ContextReference} reference - Reference to format
|
|
772
|
-
* @returns {string} Display name
|
|
773
|
-
*/
|
|
774
|
-
static getDisplayName(reference) {
|
|
775
|
-
if (reference.type === CONTEXT_REFERENCE_TYPES.SELECTION && reference.scope) {
|
|
776
|
-
return ContextReferenceFactory.generateSelectionName(reference.path, reference.scope);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
return reference.name;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* Get reference description
|
|
784
|
-
* @param {ContextReference} reference - Reference to describe
|
|
785
|
-
* @returns {string} Description
|
|
786
|
-
*/
|
|
787
|
-
static getDescription(reference) {
|
|
788
|
-
if (reference.metadata?.description) {
|
|
789
|
-
return reference.metadata.description;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
switch (reference.type) {
|
|
793
|
-
case CONTEXT_REFERENCE_TYPES.FILE:
|
|
794
|
-
return `File: ${reference.path}`;
|
|
795
|
-
case CONTEXT_REFERENCE_TYPES.DIRECTORY:
|
|
796
|
-
return `Directory: ${reference.path}`;
|
|
797
|
-
case CONTEXT_REFERENCE_TYPES.SELECTION:
|
|
798
|
-
return `Selection from ${reference.path}`;
|
|
799
|
-
case CONTEXT_REFERENCE_TYPES.COMPONENT:
|
|
800
|
-
return `Component: ${reference.name}`;
|
|
801
|
-
default:
|
|
802
|
-
return reference.path;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* Calculate reference relevance score
|
|
808
|
-
* @param {ContextReference} reference - Reference to score
|
|
809
|
-
* @param {Object} context - Scoring context
|
|
810
|
-
* @returns {number} Relevance score (0-1)
|
|
811
|
-
*/
|
|
812
|
-
static calculateRelevance(reference, context = {}) {
|
|
813
|
-
let score = 0.5; // Base score
|
|
814
|
-
|
|
815
|
-
// Recent access bonus
|
|
816
|
-
if (reference.lastAccessed) {
|
|
817
|
-
const daysSinceAccess = (Date.now() - new Date(reference.lastAccessed)) / (1000 * 60 * 60 * 24);
|
|
818
|
-
score += Math.max(0, 0.2 * (1 - daysSinceAccess / 30)); // Decay over 30 days
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
// Access frequency bonus
|
|
822
|
-
if (reference.accessCount > 0) {
|
|
823
|
-
score += Math.min(0.2, reference.accessCount * 0.01);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
// Type-specific scoring
|
|
827
|
-
switch (reference.type) {
|
|
828
|
-
case CONTEXT_REFERENCE_TYPES.FILE:
|
|
829
|
-
if (context.fileTypes && reference.metadata?.language) {
|
|
830
|
-
if (context.fileTypes.includes(reference.metadata.language)) {
|
|
831
|
-
score += 0.2;
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
break;
|
|
835
|
-
case CONTEXT_REFERENCE_TYPES.SELECTION:
|
|
836
|
-
score += 0.1; // Selections are often more relevant
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
// Keyword matching
|
|
841
|
-
if (context.keywords && reference.metadata?.keywords) {
|
|
842
|
-
const matches = context.keywords.filter(k =>
|
|
843
|
-
reference.metadata.keywords.includes(k)
|
|
844
|
-
).length;
|
|
845
|
-
score += Math.min(0.3, matches * 0.1);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// Invalid references get heavy penalty
|
|
849
|
-
if (!reference.isValid) {
|
|
850
|
-
score *= 0.1;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
return Math.min(1, Math.max(0, score));
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
* Group references by type
|
|
858
|
-
* @param {ContextReference[]} references - References to group
|
|
859
|
-
* @returns {Object} Grouped references
|
|
860
|
-
*/
|
|
861
|
-
static groupByType(references) {
|
|
862
|
-
return references.reduce((groups, reference) => {
|
|
863
|
-
const type = reference.type;
|
|
864
|
-
if (!groups[type]) {
|
|
865
|
-
groups[type] = [];
|
|
866
|
-
}
|
|
867
|
-
groups[type].push(reference);
|
|
868
|
-
return groups;
|
|
869
|
-
}, {});
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
/**
|
|
873
|
-
* Sort references by relevance
|
|
874
|
-
* @param {ContextReference[]} references - References to sort
|
|
875
|
-
* @param {Object} context - Sorting context
|
|
876
|
-
* @returns {ContextReference[]} Sorted references
|
|
877
|
-
*/
|
|
878
|
-
static sortByRelevance(references, context = {}) {
|
|
879
|
-
return [...references].sort((a, b) => {
|
|
880
|
-
const scoreA = this.calculateRelevance(a, context);
|
|
881
|
-
const scoreB = this.calculateRelevance(b, context);
|
|
882
|
-
return scoreB - scoreA;
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
/**
|
|
887
|
-
* Filter references by criteria
|
|
888
|
-
* @param {ContextReference[]} references - References to filter
|
|
889
|
-
* @param {Object} criteria - Filter criteria
|
|
890
|
-
* @returns {ContextReference[]} Filtered references
|
|
891
|
-
*/
|
|
892
|
-
static filter(references, criteria = {}) {
|
|
893
|
-
return references.filter(reference => {
|
|
894
|
-
// Type filter
|
|
895
|
-
if (criteria.types && !criteria.types.includes(reference.type)) {
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// Valid filter
|
|
900
|
-
if (criteria.validOnly && !reference.isValid) {
|
|
901
|
-
return false;
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
// Language filter
|
|
905
|
-
if (criteria.languages && reference.metadata?.language) {
|
|
906
|
-
if (!criteria.languages.includes(reference.metadata.language)) {
|
|
907
|
-
return false;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
// Path filter
|
|
912
|
-
if (criteria.pathPattern) {
|
|
913
|
-
const regex = new RegExp(criteria.pathPattern, 'i');
|
|
914
|
-
if (!regex.test(reference.path)) {
|
|
915
|
-
return false;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
// Keyword filter
|
|
920
|
-
if (criteria.keywords && reference.metadata?.keywords) {
|
|
921
|
-
const hasKeyword = criteria.keywords.some(keyword =>
|
|
922
|
-
reference.metadata.keywords.includes(keyword)
|
|
923
|
-
);
|
|
924
|
-
if (!hasKeyword) {
|
|
925
|
-
return false;
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
// Date range filter
|
|
930
|
-
if (criteria.createdAfter) {
|
|
931
|
-
if (new Date(reference.createdAt) < new Date(criteria.createdAfter)) {
|
|
932
|
-
return false;
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
if (criteria.createdBefore) {
|
|
937
|
-
if (new Date(reference.createdAt) > new Date(criteria.createdBefore)) {
|
|
938
|
-
return false;
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
return true;
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Format reference for display
|
|
948
|
-
* @param {ContextReference} reference - Reference to format
|
|
949
|
-
* @returns {Object} Formatted reference
|
|
950
|
-
*/
|
|
951
|
-
static formatForDisplay(reference) {
|
|
952
|
-
return {
|
|
953
|
-
id: reference.id,
|
|
954
|
-
type: reference.type,
|
|
955
|
-
name: this.getDisplayName(reference),
|
|
956
|
-
description: this.getDescription(reference),
|
|
957
|
-
path: reference.path,
|
|
958
|
-
icon: reference.metadata?.icon || CONTEXT_ICONS[reference.type] || CONTEXT_ICONS.DEFAULT,
|
|
959
|
-
isValid: reference.isValid,
|
|
960
|
-
lastAccessed: reference.lastAccessed,
|
|
961
|
-
accessCount: reference.accessCount,
|
|
962
|
-
size: reference.metadata?.size || null,
|
|
963
|
-
language: reference.metadata?.language || null
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
export default {
|
|
969
|
-
ContextReferenceValidator,
|
|
970
|
-
ContextReferenceFactory,
|
|
971
|
-
ContextReferenceUtils
|
|
972
|
-
};
|
|
1
|
+
const a0_0x4dff8e=a0_0x465e;(function(_0x105b3e,_0x5cabbc){const _0x3c2eda=a0_0x465e,_0x5c7c94=_0x105b3e();while(!![]){try{const _0x113b25=-parseInt(_0x3c2eda(0x11e))/0x1*(parseInt(_0x3c2eda(0x107))/0x2)+-parseInt(_0x3c2eda(0x183))/0x3*(-parseInt(_0x3c2eda(0x159))/0x4)+-parseInt(_0x3c2eda(0x127))/0x5*(-parseInt(_0x3c2eda(0x10c))/0x6)+-parseInt(_0x3c2eda(0x141))/0x7+parseInt(_0x3c2eda(0x184))/0x8*(parseInt(_0x3c2eda(0x146))/0x9)+parseInt(_0x3c2eda(0x11b))/0xa*(-parseInt(_0x3c2eda(0x147))/0xb)+-parseInt(_0x3c2eda(0x156))/0xc*(-parseInt(_0x3c2eda(0x153))/0xd);if(_0x113b25===_0x5cabbc)break;else _0x5c7c94['push'](_0x5c7c94['shift']());}catch(_0x31c300){_0x5c7c94['push'](_0x5c7c94['shift']());}}}(a0_0x56f3,0xb9a7b));import{CONTEXT_REFERENCE_TYPES,FILE_EXTENSIONS,CONTEXT_ICONS}from'../utilities/constants.js';function a0_0x465e(_0x3886e0,_0x274be9){_0x3886e0=_0x3886e0-0xf4;const _0x56f3e6=a0_0x56f3();let _0x465e80=_0x56f3e6[_0x3886e0];if(a0_0x465e['oCAacS']===undefined){var _0x59a2d7=function(_0x335230){const _0x3517c8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x562c3d='',_0x2c9c93='';for(let _0x413afa=0x0,_0x52cd27,_0x8a89cd,_0x2cd667=0x0;_0x8a89cd=_0x335230['charAt'](_0x2cd667++);~_0x8a89cd&&(_0x52cd27=_0x413afa%0x4?_0x52cd27*0x40+_0x8a89cd:_0x8a89cd,_0x413afa++%0x4)?_0x562c3d+=String['fromCharCode'](0xff&_0x52cd27>>(-0x2*_0x413afa&0x6)):0x0){_0x8a89cd=_0x3517c8['indexOf'](_0x8a89cd);}for(let _0x504dfe=0x0,_0x135e4c=_0x562c3d['length'];_0x504dfe<_0x135e4c;_0x504dfe++){_0x2c9c93+='%'+('00'+_0x562c3d['charCodeAt'](_0x504dfe)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x2c9c93);};a0_0x465e['GcdKJb']=_0x59a2d7,a0_0x465e['OZWvBO']={},a0_0x465e['oCAacS']=!![];}const _0x1136bf=_0x56f3e6[0x0],_0x2b2f55=_0x3886e0+_0x1136bf,_0xe29659=a0_0x465e['OZWvBO'][_0x2b2f55];return!_0xe29659?(_0x465e80=a0_0x465e['GcdKJb'](_0x465e80),a0_0x465e['OZWvBO'][_0x2b2f55]=_0x465e80):_0x465e80=_0xe29659,_0x465e80;}function a0_0x56f3(){const _0x3cc464=['CNvIEq','revgqvvmva','ChvZAa','C2nZCW','DhLWzxm','C29Tzq','twv0ywrHDgeGC2L6zsbTDxn0igjLigeGBM9Ulw5Lz2f0AxzLig51BwjLCG','zxHJBhvKzvbHDgHZ','yxbWBgLJyxrPB24VC3fS','q09nue9oru5u','ig11C3qGyMuGysbUB24TBMvNyxrPDMuGBNvTyMvY','mJyZndKZEhnMse1l','nJG4rw9fyNzU','rKLmrq','AMf2yq','ChjVCgvYDgLLCW','Cgf0Aa','zg9JDw1LBNrHDgLVBG','Cgf0AfbHDhrLCM4','yxbWBgLJyxrPB24VEg1S','Dgv4Dc9JC3m','DxrMltG','zNvUy3rPB25oyw1L','DhLWzxnJCMLWDa','D2fYBMLUz3m','u2nVCguG','BwLU','u2vSzwn0zwqGDgv4DcbTDxn0igjLigeGC3rYAw5N','ywnJzxnZq291BNq','z2v0rgLZCgXHEu5HBwu','Dg9mB3DLCKnHC2u','AxnbCNjHEq','BgvUz3rO','mtu0mtm4ofHsufj1zW','zMLSDgvY','u291CMnLigzPBguGBxvZDcbIzsbHihn0CMLUzW','C3rHDhm','y29UDgvUDa','mJeWAvPUrKPT','CMfUzg9T','u0vmrunusu9o','C2nVCgu','CMvMxW','zw5Kq29SDw1U','z2v0twLTzvr5CgvgCM9TrxH0zw5ZAw9U','Dgv4Dc9TyxjRzg93BG','DgvZDa','BwfYA0fJy2vZC2vK','CgHW','C2L6zq','z2v0tgfUz3vHz2vgCM9TrxH0zw5ZAw9U','icHZzwXLy3rPB24P','y3jLyxrLzefMDgvY','mtK4otq2mfr0sNLNBa','Dgv4Dc94lwnZAgfYCa','zxH0CMfJDezPBgvoyw1L','mujmzwT4CG','y3jLyxrL','BMfTzq','DMfSAwrHDgvtzwXLy3rPB25szwzLCMvUy2u','zw5KtgLUzq','zMLSzunVDw50','yxbWBgLJyxrPB24VAMf2yxnJCMLWDa','C29YDa','twv0ywrHDgeGtuLnrsb0ExbLig11C3qGyMuGysbZDhjPBMC','mtuWnta1A3fxEvjL','DMfSAwrHDgvty29Wzq','z2vUzxjHDgvszwzLCMvUy2vjza','C3rHCNrdB2X1Bw4','BwfYA0LUDMfSAwq','zw5JB2rPBMC','zgvWzw5Kzw5JAwvZ','yxbWBgLJyxrPB24VANnVBG','zMLSzvr5CgvZ','BgfZDefJy2vZC2vK','ChvYCg9Zzq','reLsrunut1jz','BgfZDeLUzgv4t2y','zxH0CMfJDezPBgvfEhrLBNnPB24','Cg9W','Aw52ywXPzfjLyxnVBG','Dg90ywXtAxPL','A2v5D29Yzhm','Dgv4Dc94lwPHDMeTC291CMnL','C3rHCNrmAw5L','yxbWBgLJyxrPB24VDhLWzxnJCMLWDa','yxbWBgLJyxrPB24VEc15yw1S','Bwf4','z2v0rgvMyxvSDeLJB24','AxnwywXPza','sw52ywXPzcbYzwzLCMvUy2uGDhLWztOG','nZe0mdi0nvHIENnsra','y3jLyxrLrgvMyxvSDe1LDgfKyxrH','y3bW','C3rYAw5N','y3jLyxrLrMLSzvjLzMvYzw5Jzq','odaZnJfnDhPXs1i','mtfvvM51C2O','y2fSy3vSyxrLuMvSzxzHBMnL','rMLSzsbLEgLZDhmGzMXHzYbTDxn0igjLigeGyM9VBgvHBG','y3nOyxjW','C3LUDgf4','DMfSAwrHDgvnzxrHzgf0yq','DMfSAwrHDgu','CMvKDwnL','uMvMzxjLBMnLihbHDgGGAxmGCMvXDwLYzwqGyw5Kig11C3qGyMuGysbZDhjPBMC','z2vUzxjHDgvtzwXLy3rPB25oyw1L','z2v0rgvZy3jPChrPB24','ig11C3qGyMuGyw4GyxjYyxK','mtnbseftze0','Dgv4Dc9WBgfPBG','zxHPC3rZ','ndGYmdqZnK9kA2TNwa','C3vIC3rY','zM9YrwfJAa','mJrJwvvkv0S','zM9YBwf0rM9YrgLZCgXHEq','Dg9ju09tDhjPBMC','DMfSAwrpBMX5','qwjZB2X1DguGCgf0AcbTDxn0igjLigeGC3rYAw5N','z2v0vgLTzq','zxH0CMfJDerPCMvJDg9YEu5HBwu','BNvTyMvY','zxjYB3jZ','u2vSzwn0Aw9UigzYB20G','qwnJzxnZignVDw50ig11C3qGyMuGysbUDw1Izxi','BwLTzvr5Cgu','CNvZDa','AMf2yxnJCMLWDa','Aw5JBhvKzxm','y3jLyxrLzef0','Bwv0ywrHDge','yM9VBgvHBG','ywjZB2X1DgvqyxrO','DMfSAwrHDgveAxjLy3rVCNLszwzLCMvUy2u','Dgv4Dc9ODg1S','BgfUz3vHz2u','y3jLyxrLu2vSzwn0Aw9UuMvMzxjLBMnL','C2vSzwn0zwruzxH0','C291CMnLrMLSzq','C29YDej5uMvSzxzHBMnL','Dg9tDhjPBMC','y2XHC3noyw1L','BgfZDe1VzgLMAwvK','twv0ywrHDgeGBgfUz3vHz2uGBxvZDcbIzsbHihn0CMLUzW','DhLWzq'];a0_0x56f3=function(){return _0x3cc464;};return a0_0x56f3();}export class ContextReferenceValidator{static[a0_0x4dff8e(0x14d)](_0x562c3d){const _0x1c789f=a0_0x4dff8e,_0x2c9c93=[],_0x413afa=[];(!_0x562c3d['id']||typeof _0x562c3d['id']!==_0x1c789f(0x144))&&_0x2c9c93[_0x1c789f(0x17a)]('Reference\x20ID\x20is\x20required\x20and\x20must\x20be\x20a\x20string');(!_0x562c3d[_0x1c789f(0x177)]||typeof _0x562c3d[_0x1c789f(0x177)]!==_0x1c789f(0x144))&&_0x2c9c93[_0x1c789f(0x17a)]('Reference\x20type\x20is\x20required\x20and\x20must\x20be\x20a\x20string');(!_0x562c3d[_0x1c789f(0xf6)]||typeof _0x562c3d[_0x1c789f(0xf6)]!==_0x1c789f(0x144))&&_0x2c9c93[_0x1c789f(0x17a)](_0x1c789f(0x14f));(!_0x562c3d['name']||typeof _0x562c3d[_0x1c789f(0x120)]!==_0x1c789f(0x144))&&_0x2c9c93[_0x1c789f(0x17a)]('Reference\x20name\x20is\x20required\x20and\x20must\x20be\x20a\x20string');_0x562c3d['type']&&!Object['values'](CONTEXT_REFERENCE_TYPES)['includes'](_0x562c3d[_0x1c789f(0x177)])&&_0x2c9c93['push'](_0x1c789f(0x140)+_0x562c3d['type']);_0x562c3d[_0x1c789f(0x10b)]&&typeof _0x562c3d['content']!=='string'&&_0x2c9c93['push']('Reference\x20content\x20must\x20be\x20a\x20string');_0x562c3d['content']&&_0x562c3d[_0x1c789f(0x10b)]['length']>0xf4240&&_0x413afa['push']('Reference\x20content\x20is\x20very\x20large\x20(>1MB)');if(_0x562c3d['metadata']){const _0x8a89cd=this[_0x1c789f(0x14c)](_0x562c3d[_0x1c789f(0x169)]);_0x2c9c93[_0x1c789f(0x17a)](..._0x8a89cd['errors']),_0x413afa['push'](..._0x8a89cd[_0x1c789f(0xfe)]);}if(_0x562c3d[_0x1c789f(0x10f)]){const _0x2cd667=this[_0x1c789f(0x128)](_0x562c3d[_0x1c789f(0x10f)]);_0x2c9c93[_0x1c789f(0x17a)](..._0x2cd667[_0x1c789f(0x161)]),_0x413afa[_0x1c789f(0x17a)](..._0x2cd667[_0x1c789f(0xfe)]);}_0x562c3d[_0x1c789f(0x102)]!==undefined&&typeof _0x562c3d['accessCount']!=='number'&&_0x2c9c93[_0x1c789f(0x17a)](_0x1c789f(0x163));const _0x52cd27=[_0x1c789f(0x168),_0x1c789f(0x130),'lastModified'];_0x52cd27['forEach'](_0x504dfe=>{const _0x53ef98=_0x1c789f;_0x562c3d[_0x504dfe]&&!this['isValidTimestamp'](_0x562c3d[_0x504dfe])&&_0x2c9c93[_0x53ef98(0x17a)]('Invalid\x20timestamp\x20for\x20'+_0x504dfe+':\x20'+_0x562c3d[_0x504dfe]);});switch(_0x562c3d['type']){case CONTEXT_REFERENCE_TYPES[_0x1c789f(0x185)]:const _0x135e4c=this['validateFileReference'](_0x562c3d);_0x2c9c93[_0x1c789f(0x17a)](..._0x135e4c['errors']),_0x413afa[_0x1c789f(0x17a)](..._0x135e4c['warnings']);break;case CONTEXT_REFERENCE_TYPES['SELECTION']:const _0x1cf67d=this[_0x1c789f(0x121)](_0x562c3d);_0x2c9c93[_0x1c789f(0x17a)](..._0x1cf67d[_0x1c789f(0x161)]),_0x413afa['push'](..._0x1cf67d['warnings']);break;case CONTEXT_REFERENCE_TYPES[_0x1c789f(0x132)]:const _0x836edc=this['validateDirectoryReference'](_0x562c3d);_0x2c9c93['push'](..._0x836edc['errors']),_0x413afa['push'](..._0x836edc['warnings']);break;}return{'isValid':_0x2c9c93['length']===0x0,'errors':_0x2c9c93,'warnings':_0x413afa};}static[a0_0x4dff8e(0x14c)](_0xeca215){const _0xd7ca20=a0_0x4dff8e,_0x515bed=[],_0x437229=[];return _0xeca215[_0xd7ca20(0x117)]!==undefined&&(typeof _0xeca215['size']!=='number'||_0xeca215['size']<0x0)&&_0x515bed['push'](_0xd7ca20(0x17e)),_0xeca215['language']&&typeof _0xeca215['language']!==_0xd7ca20(0x144)&&_0x515bed['push'](_0xd7ca20(0x176)),_0xeca215['encoding']&&typeof _0xeca215[_0xd7ca20(0x12c)]!=='string'&&_0x515bed['push']('Metadata\x20encoding\x20must\x20be\x20a\x20string'),_0xeca215['keywords']&&!Array['isArray'](_0xeca215[_0xd7ca20(0x138)])&&_0x515bed[_0xd7ca20(0x17a)]('Metadata\x20keywords\x20must\x20be\x20an\x20array'),_0xeca215['mimeType']&&typeof _0xeca215[_0xd7ca20(0x164)]!==_0xd7ca20(0x144)&&_0x515bed[_0xd7ca20(0x17a)](_0xd7ca20(0x126)),{'errors':_0x515bed,'warnings':_0x437229};}static[a0_0x4dff8e(0x128)](_0x3b773f){const _0x41ed5d=a0_0x4dff8e,_0x166721=[],_0x491c09=[],_0x37e974=['startLine','endLine',_0x41ed5d(0x12a),'endColumn','maxDepth'];_0x37e974['forEach'](_0x4b83cb=>{const _0x874881=_0x41ed5d;_0x3b773f[_0x4b83cb]!==undefined&&(typeof _0x3b773f[_0x4b83cb]!==_0x874881(0x160)||_0x3b773f[_0x4b83cb]<0x0)&&_0x166721['push'](_0x874881(0xff)+_0x4b83cb+_0x874881(0x182));});_0x3b773f[_0x41ed5d(0x13a)]!==undefined&&_0x3b773f['endLine']!==undefined&&(_0x3b773f['startLine']>_0x3b773f['endLine']&&_0x166721['push']('Start\x20line\x20must\x20be\x20<=\x20end\x20line'));_0x3b773f['startColumn']!==undefined&&_0x3b773f['endColumn']!==undefined&&(_0x3b773f['startColumn']>_0x3b773f[_0x41ed5d(0x111)]&&_0x166721['push']('Start\x20column\x20must\x20be\x20<=\x20end\x20column'));const _0x2967db=['includePaths',_0x41ed5d(0x17f)];return _0x2967db[_0x41ed5d(0x158)](_0x2eda12=>{const _0x257b9d=_0x41ed5d;_0x3b773f[_0x2eda12]&&!Array[_0x257b9d(0x105)](_0x3b773f[_0x2eda12])&&_0x166721['push'](_0x257b9d(0xff)+_0x2eda12+_0x257b9d(0x152));}),{'errors':_0x166721,'warnings':_0x491c09};}static['validateFileReference'](_0xc76d99){const _0x47b3b6=a0_0x4dff8e,_0x372c8c=[],_0x3f5b82=[];return _0xc76d99[_0x47b3b6(0x16b)]&&typeof _0xc76d99[_0x47b3b6(0x16b)]!=='string'&&_0x372c8c['push'](_0x47b3b6(0x15d)),_0xc76d99['relativePath']&&typeof _0xc76d99['relativePath']!==_0x47b3b6(0x144)&&_0x372c8c[_0x47b3b6(0x17a)]('Relative\x20path\x20must\x20be\x20a\x20string'),_0xc76d99['extension']&&typeof _0xc76d99['extension']!=='string'&&_0x372c8c['push']('File\x20extension\x20must\x20be\x20a\x20string'),_0xc76d99[_0x47b3b6(0x155)]!==undefined&&typeof _0xc76d99['exists']!==_0x47b3b6(0x16a)&&_0x372c8c[_0x47b3b6(0x17a)](_0x47b3b6(0x149)),{'errors':_0x372c8c,'warnings':_0x3f5b82};}static[a0_0x4dff8e(0x121)](_0xd91fbb){const _0x432771=a0_0x4dff8e,_0x10c296=[],_0x26552f=[];return(!_0xd91fbb['scope']||!_0xd91fbb[_0x432771(0x10f)]['startLine']&&!_0xd91fbb[_0x432771(0x10f)][_0x432771(0x122)])&&_0x26552f[_0x432771(0x17a)]('Selection\x20reference\x20should\x20have\x20line\x20scope\x20defined'),_0xd91fbb[_0x432771(0x170)]&&typeof _0xd91fbb[_0x432771(0x170)]!=='string'&&_0x10c296[_0x432771(0x17a)](_0x432771(0x101)),_0xd91fbb[_0x432771(0x171)]&&typeof _0xd91fbb[_0x432771(0x171)]!=='string'&&_0x10c296['push'](_0x432771(0x109)),{'errors':_0x10c296,'warnings':_0x26552f};}static[a0_0x4dff8e(0x16c)](_0x3bf879){const _0x3ae068=a0_0x4dff8e,_0xae6ad9=[],_0x2ca55e=[];return _0x3bf879['fileCount']!==undefined&&(typeof _0x3bf879[_0x3ae068(0x123)]!==_0x3ae068(0x160)||_0x3bf879['fileCount']<0x0)&&_0xae6ad9['push']('File\x20count\x20must\x20be\x20a\x20non-negative\x20number'),_0x3bf879['totalSize']!==undefined&&(typeof _0x3bf879[_0x3ae068(0x137)]!==_0x3ae068(0x160)||_0x3bf879[_0x3ae068(0x137)]<0x0)&&_0xae6ad9['push']('Total\x20size\x20must\x20be\x20a\x20non-negative\x20number'),_0x3bf879['fileTypes']&&!Array[_0x3ae068(0x105)](_0x3bf879[_0x3ae068(0x12f)])&&_0xae6ad9['push']('File\x20types\x20must\x20be\x20an\x20array'),{'errors':_0xae6ad9,'warnings':_0x2ca55e};}static['isValidTimestamp'](_0x2fdb68){const _0x4762ce=a0_0x4dff8e;if(typeof _0x2fdb68!=='string')return![];const _0x56096a=new Date(_0x2fdb68);return _0x56096a instanceof Date&&!isNaN(_0x56096a[_0x4762ce(0x15e)]());}}export class ContextReferenceFactory{static['create'](_0x4e4987,_0x48edb4,_0x215017,_0x428331={}){const _0x440151=a0_0x4dff8e,_0x4c9784=new Date()[_0x440151(0x15b)](),_0xde4c0a=this['generateReferenceId']();return{'id':_0xde4c0a,'type':_0x4e4987,'path':_0x48edb4,'name':_0x215017,'content':_0x428331[_0x440151(0x10b)]||null,'metadata':this['createDefaultMetadata'](_0x4e4987,_0x48edb4,_0x428331[_0x440151(0x169)]),'scope':_0x428331[_0x440151(0x10f)]||{},'createdAt':_0x4c9784,'lastAccessed':null,'lastModified':_0x428331[_0x440151(0x175)]||null,'isValid':!![],'invalidReason':null,'accessCount':0x0,'tags':_0x428331['tags']||{}};}static[a0_0x4dff8e(0x145)](_0x2918f0,_0x36a5f2,_0x96c330={}){const _0x4e8cb7=a0_0x4dff8e,_0x6a838c=_0x96c330[_0x4e8cb7(0x120)]||this['extractFileName'](_0x2918f0),_0x517f14=this['extractFileExtension'](_0x2918f0),_0x5c4e3a=this[_0x4e8cb7(0x11f)](CONTEXT_REFERENCE_TYPES['FILE'],_0x36a5f2,_0x6a838c,_0x96c330);return{..._0x5c4e3a,'absolutePath':_0x2918f0,'relativePath':_0x36a5f2,'extension':_0x517f14,'exists':_0x96c330['exists']!==undefined?_0x96c330[_0x4e8cb7(0x155)]:!![],'stats':_0x96c330[_0x4e8cb7(0x10a)]||null,'gitStatus':_0x96c330['gitStatus']||null,'dependencies':_0x96c330[_0x4e8cb7(0x12d)]||null};}static[a0_0x4dff8e(0x16f)](_0x9ee6e3,_0x44f30d,_0x554445,_0x1adeeb={}){const _0x3aeace=a0_0x4dff8e,_0x4fb3b8=_0x1adeeb['name']||this['generateSelectionName'](_0x9ee6e3,_0x554445),_0x42e706=this['create'](CONTEXT_REFERENCE_TYPES[_0x3aeace(0x10e)],_0x9ee6e3,_0x4fb3b8,{..._0x1adeeb,'scope':_0x554445,'content':_0x44f30d});return{..._0x42e706,'sourceFile':_0x9ee6e3,'selectedText':_0x44f30d,'syntax':_0x1adeeb[_0x3aeace(0x14b)]||null,'context':_0x1adeeb['context']||null,'purpose':_0x1adeeb[_0x3aeace(0x131)]||null};}static['createDirectoryReference'](_0x3676b6,_0x164e6c,_0x54c409={}){const _0x2d2140=a0_0x4dff8e,_0x17ee6f=_0x54c409[_0x2d2140(0x120)]||this[_0x2d2140(0x15f)](_0x3676b6),_0x58f3b5=this[_0x2d2140(0x11f)](CONTEXT_REFERENCE_TYPES['DIRECTORY'],_0x164e6c,_0x17ee6f,_0x54c409);return{..._0x58f3b5,'absolutePath':_0x3676b6,'relativePath':_0x164e6c,'tree':_0x54c409['tree']||null,'fileCount':_0x54c409['fileCount']||null,'totalSize':_0x54c409[_0x2d2140(0x137)]||null,'fileTypes':_0x54c409[_0x2d2140(0x12f)]||null};}static['createComponentReference'](_0x4294ea,_0x17efbc,_0x16d36f,_0x3f1fa3={}){const _0x1c115c=a0_0x4dff8e,_0x1653f0=this['create'](CONTEXT_REFERENCE_TYPES[_0x1c115c(0x181)],_0x17efbc,_0x16d36f,_0x3f1fa3);return{..._0x1653f0,'componentType':_0x4294ea,'sourceFile':_0x3f1fa3[_0x1c115c(0x171)]||null,'properties':_0x3f1fa3[_0x1c115c(0xf5)]||null,'dependencies':_0x3f1fa3[_0x1c115c(0x12d)]||null,'documentation':_0x3f1fa3[_0x1c115c(0xf7)]||null};}static[a0_0x4dff8e(0x142)](_0xad236d,_0x5e8068,_0x2f3b2c={}){const _0x2643e2=a0_0x4dff8e,_0x49f17a={'language':null,'encoding':_0x2643e2(0xfb),'size':null,'mimeType':null,'checksum':null,'keywords':[],'description':'','customFields':{},'icon':this[_0x2643e2(0x13e)](_0xad236d,_0x5e8068),'permissions':{},..._0x2f3b2c};if(_0xad236d===CONTEXT_REFERENCE_TYPES[_0x2643e2(0x185)]){const _0x47d3d0=this['extractFileExtension'](_0x5e8068);_0x49f17a[_0x2643e2(0x16e)]=this[_0x2643e2(0x118)](_0x47d3d0),_0x49f17a['mimeType']=this[_0x2643e2(0x112)](_0x47d3d0);}return _0x49f17a;}static[a0_0x4dff8e(0x129)](){const _0x4ad66f=a0_0x4dff8e,_0x497a3d=Date['now']()['toString'](0x24),_0x17d81f=Math[_0x4ad66f(0x10d)]()[_0x4ad66f(0x173)](0x24)[_0x4ad66f(0x157)](0x2,0x9);return _0x4ad66f(0x110)+_0x497a3d+'_'+_0x17d81f;}static['extractFileName'](_0x165bde){const _0x1b053f=a0_0x4dff8e;return _0x165bde['split'](/[/\\]/)[_0x1b053f(0x135)]()||_0x165bde;}static[a0_0x4dff8e(0x15f)](_0x12d1a4){const _0x1c8690=a0_0x4dff8e,_0x26d7d0=_0x12d1a4['split'](/[/\\]/)['filter'](Boolean);return _0x26d7d0[_0x26d7d0[_0x1c8690(0x106)]-0x1]||'Root';}static[a0_0x4dff8e(0x134)](_0x43144c){const _0x593add=a0_0x4dff8e,_0x20135e=this['extractFileName'](_0x43144c),_0x1c5d21=_0x20135e[_0x593add(0x133)]('.');return _0x1c5d21!==-0x1?_0x20135e['substring'](_0x1c5d21):'';}static[a0_0x4dff8e(0x150)](_0x16a1ca,_0x454cf1){const _0x7651ef=a0_0x4dff8e,_0x3a8539=this[_0x7651ef(0x11d)](_0x16a1ca);if(_0x454cf1[_0x7651ef(0x13a)]&&_0x454cf1[_0x7651ef(0x122)])return _0x454cf1[_0x7651ef(0x13a)]===_0x454cf1['endLine']?_0x3a8539+':'+_0x454cf1['startLine']:_0x3a8539+':'+_0x454cf1['startLine']+'-'+_0x454cf1['endLine'];if(_0x454cf1[_0x7651ef(0xfc)])return _0x3a8539+':'+_0x454cf1[_0x7651ef(0xfc)]+'()';if(_0x454cf1[_0x7651ef(0x174)])return _0x3a8539+':'+_0x454cf1[_0x7651ef(0x174)];return _0x3a8539+_0x7651ef(0x119);}static[a0_0x4dff8e(0x13e)](_0x4d0bbf,_0x28540b){const _0x94223=a0_0x4dff8e;if(_0x4d0bbf===CONTEXT_REFERENCE_TYPES['FILE']){const _0x3cb83a=this[_0x94223(0x134)](_0x28540b);return FILE_ICONS[_0x3cb83a]||CONTEXT_ICONS['DEFAULT'];}return CONTEXT_ICONS[_0x4d0bbf]||CONTEXT_ICONS['DEFAULT'];}static[a0_0x4dff8e(0x118)](_0x556c39){const _0x2e927a=a0_0x4dff8e,_0x490509={'.js':'javascript','.jsx':_0x2e927a(0x166),'.ts':_0x2e927a(0xfd),'.tsx':'typescript','.py':'python','.java':_0x2e927a(0xf4),'.cpp':_0x2e927a(0x143),'.c':'c','.cs':_0x2e927a(0x14a),'.php':_0x2e927a(0x116),'.rb':_0x2e927a(0x178),'.go':'go','.rs':_0x2e927a(0x165),'.html':'html','.css':'css','.scss':_0x2e927a(0x17b),'.json':'json','.yml':'yaml','.yaml':'yaml','.xml':'xml','.sql':'sql','.md':'markdown'};return _0x490509[_0x556c39[_0x2e927a(0x104)]()]||null;}static['getMimeTypeFromExtension'](_0x41bcc7){const _0x1d676c=a0_0x4dff8e,_0x42e469={'.js':_0x1d676c(0x124),'.jsx':'application/javascript','.ts':'application/typescript','.tsx':_0x1d676c(0x13b),'.py':'text/x-python','.java':_0x1d676c(0x139),'.cpp':'text/x-c++src','.c':'text/x-csrc','.cs':_0x1d676c(0x11c),'.php':'application/x-php','.rb':'application/x-ruby','.go':'text/x-go','.rs':'text/x-rust','.html':_0x1d676c(0x16d),'.css':_0x1d676c(0xfa),'.scss':'text/x-scss','.json':_0x1d676c(0x12e),'.yml':_0x1d676c(0x13c),'.yaml':'application/x-yaml','.xml':_0x1d676c(0xf9),'.sql':_0x1d676c(0x180),'.md':_0x1d676c(0x113),'.txt':'text/plain'};return _0x42e469[_0x41bcc7[_0x1d676c(0x104)]()]||_0x1d676c(0x154);}}export class ContextReferenceUtils{static[a0_0x4dff8e(0x13f)](_0x18d431){const _0x49d4d9=a0_0x4dff8e;return _0x18d431[_0x49d4d9(0x13f)]&&!_0x18d431[_0x49d4d9(0x136)];}static[a0_0x4dff8e(0x115)](_0x426657){const _0x5549d4=a0_0x4dff8e;return{..._0x426657,'lastAccessed':new Date()[_0x5549d4(0x15b)](),'accessCount':_0x426657['accessCount']+0x1};}static[a0_0x4dff8e(0x12b)](_0x119a7a,_0x51e28e){return{..._0x119a7a,'isValid':![],'invalidReason':_0x51e28e};}static[a0_0x4dff8e(0x103)](_0x24d550){const _0x4bc27d=a0_0x4dff8e;if(_0x24d550['type']===CONTEXT_REFERENCE_TYPES['SELECTION']&&_0x24d550['scope'])return ContextReferenceFactory['generateSelectionName'](_0x24d550[_0x4bc27d(0xf6)],_0x24d550['scope']);return _0x24d550[_0x4bc27d(0x120)];}static[a0_0x4dff8e(0x151)](_0x422db0){const _0x41ca83=a0_0x4dff8e;if(_0x422db0[_0x41ca83(0x169)]?.['description'])return _0x422db0[_0x41ca83(0x169)]['description'];switch(_0x422db0[_0x41ca83(0x177)]){case CONTEXT_REFERENCE_TYPES[_0x41ca83(0x185)]:return'File:\x20'+_0x422db0[_0x41ca83(0xf6)];case CONTEXT_REFERENCE_TYPES['DIRECTORY']:return'Directory:\x20'+_0x422db0['path'];case CONTEXT_REFERENCE_TYPES['SELECTION']:return _0x41ca83(0x162)+_0x422db0[_0x41ca83(0xf6)];case CONTEXT_REFERENCE_TYPES[_0x41ca83(0x181)]:return'Component:\x20'+_0x422db0[_0x41ca83(0x120)];default:return _0x422db0[_0x41ca83(0xf6)];}}static[a0_0x4dff8e(0x148)](_0x57ed5f,_0x45cd4c={}){const _0x61e903=a0_0x4dff8e;let _0xd0a2cf=0.5;if(_0x57ed5f['lastAccessed']){const _0x39c1e6=(Date['now']()-new Date(_0x57ed5f['lastAccessed']))/(0x3e8*0x3c*0x3c*0x18);_0xd0a2cf+=Math[_0x61e903(0x13d)](0x0,0.2*(0x1-_0x39c1e6/0x1e));}_0x57ed5f['accessCount']>0x0&&(_0xd0a2cf+=Math[_0x61e903(0x100)](0.2,_0x57ed5f['accessCount']*0.01));switch(_0x57ed5f['type']){case CONTEXT_REFERENCE_TYPES['FILE']:_0x45cd4c['fileTypes']&&_0x57ed5f['metadata']?.['language']&&(_0x45cd4c[_0x61e903(0x12f)]['includes'](_0x57ed5f['metadata'][_0x61e903(0x16e)])&&(_0xd0a2cf+=0.2));break;case CONTEXT_REFERENCE_TYPES[_0x61e903(0x10e)]:_0xd0a2cf+=0.1;break;}if(_0x45cd4c[_0x61e903(0x138)]&&_0x57ed5f[_0x61e903(0x169)]?.['keywords']){const _0x239b81=_0x45cd4c['keywords'][_0x61e903(0x108)](_0x459f3e=>_0x57ed5f[_0x61e903(0x169)]['keywords']['includes'](_0x459f3e))[_0x61e903(0x106)];_0xd0a2cf+=Math['min'](0.3,_0x239b81*0.1);}return!_0x57ed5f['isValid']&&(_0xd0a2cf*=0.1),Math[_0x61e903(0x100)](0x1,Math['max'](0x0,_0xd0a2cf));}static['groupByType'](_0x1e67d2){const _0x2b9153=a0_0x4dff8e;return _0x1e67d2[_0x2b9153(0x14e)]((_0x426c67,_0x324f21)=>{const _0x4947dc=_0x2b9153,_0x382014=_0x324f21['type'];return!_0x426c67[_0x382014]&&(_0x426c67[_0x382014]=[]),_0x426c67[_0x382014][_0x4947dc(0x17a)](_0x324f21),_0x426c67;},{});}static[a0_0x4dff8e(0x172)](_0x23d909,_0x53e631={}){const _0x1ba231=a0_0x4dff8e;return[..._0x23d909][_0x1ba231(0x125)]((_0x34e2b5,_0x29e9c9)=>{const _0x61bd84=_0x1ba231,_0x5b89ff=this[_0x61bd84(0x148)](_0x34e2b5,_0x53e631),_0x496ed6=this['calculateRelevance'](_0x29e9c9,_0x53e631);return _0x496ed6-_0x5b89ff;});}static['filter'](_0x22fb4f,_0x1ff44b={}){return _0x22fb4f['filter'](_0x20725a=>{const _0x1883f3=a0_0x465e;if(_0x1ff44b['types']&&!_0x1ff44b[_0x1883f3(0x17c)][_0x1883f3(0x167)](_0x20725a['type']))return![];if(_0x1ff44b[_0x1883f3(0x15c)]&&!_0x20725a['isValid'])return![];if(_0x1ff44b['languages']&&_0x20725a['metadata']?.['language']){if(!_0x1ff44b['languages'][_0x1883f3(0x167)](_0x20725a['metadata']['language']))return![];}if(_0x1ff44b[_0x1883f3(0xf8)]){const _0x2fad33=new RegExp(_0x1ff44b[_0x1883f3(0xf8)],'i');if(!_0x2fad33[_0x1883f3(0x114)](_0x20725a[_0x1883f3(0xf6)]))return![];}if(_0x1ff44b[_0x1883f3(0x138)]&&_0x20725a[_0x1883f3(0x169)]?.[_0x1883f3(0x138)]){const _0x53b4f1=_0x1ff44b['keywords'][_0x1883f3(0x17d)](_0x39a4f4=>_0x20725a['metadata'][_0x1883f3(0x138)][_0x1883f3(0x167)](_0x39a4f4));if(!_0x53b4f1)return![];}if(_0x1ff44b[_0x1883f3(0x11a)]){if(new Date(_0x20725a['createdAt'])<new Date(_0x1ff44b[_0x1883f3(0x11a)]))return![];}if(_0x1ff44b['createdBefore']){if(new Date(_0x20725a['createdAt'])>new Date(_0x1ff44b['createdBefore']))return![];}return!![];});}static[a0_0x4dff8e(0x15a)](_0x277ab9){const _0x802c0b=a0_0x4dff8e;return{'id':_0x277ab9['id'],'type':_0x277ab9[_0x802c0b(0x177)],'name':this[_0x802c0b(0x103)](_0x277ab9),'description':this[_0x802c0b(0x151)](_0x277ab9),'path':_0x277ab9['path'],'icon':_0x277ab9[_0x802c0b(0x169)]?.['icon']||CONTEXT_ICONS[_0x277ab9['type']]||CONTEXT_ICONS[_0x802c0b(0x179)],'isValid':_0x277ab9['isValid'],'lastAccessed':_0x277ab9[_0x802c0b(0x130)],'accessCount':_0x277ab9[_0x802c0b(0x102)],'size':_0x277ab9['metadata']?.['size']||null,'language':_0x277ab9['metadata']?.[_0x802c0b(0x16e)]||null};}}export default{'ContextReferenceValidator':ContextReferenceValidator,'ContextReferenceFactory':ContextReferenceFactory,'ContextReferenceUtils':ContextReferenceUtils};
|