@gitsense/gsc-utils 0.2.24 → 0.2.27

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 (40) hide show
  1. package/README.md +380 -62
  2. package/dist/gsc-utils.cjs.js +14270 -523
  3. package/dist/gsc-utils.esm.js +14270 -523
  4. package/package.json +1 -1
  5. package/src/AnalyzerUtils/cloner.js +149 -0
  6. package/src/AnalyzerUtils/constants.js +1 -1
  7. package/src/AnalyzerUtils/defaultPromptLoader.js +10 -10
  8. package/src/AnalyzerUtils/discovery.js +48 -39
  9. package/src/AnalyzerUtils/index.js +13 -7
  10. package/src/AnalyzerUtils/instructionLoader.js +6 -6
  11. package/src/AnalyzerUtils/jsonParser.js +35 -0
  12. package/src/AnalyzerUtils/management.js +6 -6
  13. package/src/AnalyzerUtils/saver.js +5 -5
  14. package/src/AnalyzerUtils/schemaLoader.js +194 -26
  15. package/src/AnalyzerUtils/updater.js +187 -0
  16. package/src/CodeBlockUtils/blockProcessor.js +14 -32
  17. package/src/CodeBlockUtils/constants.js +8 -4
  18. package/src/CodeBlockUtils/headerUtils.js +19 -3
  19. package/src/CodeBlockUtils/index.js +7 -6
  20. package/src/CodeBlockUtils/lineageTracer.js +95 -0
  21. package/src/CompactChatUtils/CompactedMessageUtils.js +224 -0
  22. package/src/CompactChatUtils/README.md +321 -0
  23. package/src/CompactChatUtils/ReferenceMessageUtils.js +143 -0
  24. package/src/CompactChatUtils/index.js +40 -0
  25. package/src/ContextUtils.js +41 -5
  26. package/src/DomUtils.js +559 -0
  27. package/src/GSToolBlockUtils.js +66 -1
  28. package/src/GitSenseChatUtils.js +108 -16
  29. package/src/LanguageNameUtils.js +171 -0
  30. package/src/MarkdownUtils.js +127 -0
  31. package/src/MessageUtils.js +1 -1
  32. package/src/MetaRawResultUtils.js +244 -0
  33. package/src/ObjectUtils.js +54 -0
  34. package/src/PatchUtils/constants.js +9 -3
  35. package/src/PatchUtils/patchParser.js +60 -37
  36. package/src/PatchUtils/patchProcessor.js +8 -5
  37. package/src/PatchUtils/patchVerifier/detectAndFixOverlappingHunks.js +1 -1
  38. package/src/SVGUtils.js +1467 -0
  39. package/src/SharedUtils/stringUtils.js +303 -0
  40. package/src/CodeBlockUtils/blockProcessor.js.rej +0 -8
@@ -0,0 +1,321 @@
1
+ # CompactChatUtils
2
+
3
+ A utility module for working with compacted messages in GitSense Chat. This module provides functionality for parsing reference messages, formatting compacted messages, and validating message formats.
4
+
5
+ ## Overview
6
+
7
+ CompactChatUtils is designed to handle the compact message workflow in GitSense Chat, which allows for efficient storage and retrieval of chat messages by compacting older messages while preserving context. The module consists of two main utility classes:
8
+
9
+ - **ReferenceMessageUtils**: Parses reference messages that contain information about which messages to compact and which to keep as context
10
+ - **CompactedMessageUtils**: Formats, parses, and validates compacted messages with standardized metadata headers
11
+
12
+ ## Installation
13
+
14
+ ```javascript
15
+ const { CompactChatUtils } = require('@gitsense/gsc-utils');
16
+ ```
17
+
18
+ Or import individual utilities:
19
+
20
+ ```javascript
21
+ const { ReferenceMessageUtils } = require('@gitsense/gsc-utils');
22
+ const { CompactedMessageUtils } = require('@gitsense/gsc-utils');
23
+ ```
24
+
25
+ ## API Reference
26
+
27
+ ### ReferenceMessageUtils
28
+
29
+ #### `extractReferenceMessageData(referenceMessage)`
30
+
31
+ Extracts all data from a reference message including session data, metadata, and message sections.
32
+
33
+ **Parameters:**
34
+ - `referenceMessage` (string): The reference message content to parse
35
+
36
+ **Returns:**
37
+ - Object: Parsed data with messages to compact and keep, metadata, and session information
38
+
39
+ **Example:**
40
+ ```javascript
41
+ const data = ReferenceMessageUtils.extractReferenceMessageData(referenceMessage);
42
+ console.log(data.messagesToCompact);
43
+ console.log(data.originalChatUuid);
44
+ ```
45
+
46
+ #### `parseMessageSection(section)`
47
+
48
+ Parses a message section to extract individual messages.
49
+
50
+ **Parameters:**
51
+ - `section` (string): The section content to parse
52
+
53
+ **Returns:**
54
+ - Array: Array of parsed message objects
55
+
56
+ **Example:**
57
+ ```javascript
58
+ const messages = ReferenceMessageUtils.parseMessageSection(section);
59
+ ```
60
+
61
+ #### `extractReferenceMessageMetadata(referenceMessage)`
62
+
63
+ Extracts just the metadata from a reference message without the message sections.
64
+
65
+ **Parameters:**
66
+ - `referenceMessage` (string): The reference message content to parse
67
+
68
+ **Returns:**
69
+ - Object: Metadata object with original chat UUID, validation hash, session ID, and range information
70
+
71
+ **Example:**
72
+ ```javascript
73
+ const metadata = ReferenceMessageUtils.extractReferenceMessageMetadata(referenceMessage);
74
+ console.log(metadata.originalChatUuid);
75
+ ```
76
+
77
+ #### `isReferenceMessage(message)`
78
+
79
+ Checks if a message is a reference message.
80
+
81
+ **Parameters:**
82
+ - `message` (string): The message content to check
83
+
84
+ **Returns:**
85
+ - boolean: True if the message is a reference message
86
+
87
+ **Example:**
88
+ ```javascript
89
+ if (ReferenceMessageUtils.isReferenceMessage(message)) {
90
+ // Handle reference message
91
+ }
92
+ ```
93
+
94
+ ### CompactedMessageUtils
95
+
96
+ #### `formatCompactedMessage(content, originalChatUuid, messageRange, options)`
97
+
98
+ Formats a compacted message with standardized metadata headers.
99
+
100
+ **Parameters:**
101
+ - `content` (string): The compacted message content
102
+ - `originalChatUuid` (string): UUID of the original chat
103
+ - `messageRange` (string): Message range that was compacted (e.g., "3-6")
104
+ - `options` (Object, optional): Additional options
105
+ - `compactedAt` (Date): Custom timestamp for when the message was compacted
106
+
107
+ **Returns:**
108
+ - string: Formatted compacted message with metadata
109
+
110
+ **Example:**
111
+ ```javascript
112
+ const compactedMessage = CompactedMessageUtils.formatCompactedMessage(
113
+ content,
114
+ '123e4567-e89b-12d3-a456-426614174000',
115
+ '3-6'
116
+ );
117
+ ```
118
+
119
+ #### `extractCompactedMessageMetadata(compactedMessage)`
120
+
121
+ Extracts metadata from a compacted message.
122
+
123
+ **Parameters:**
124
+ - `compactedMessage` (string): The compacted message to parse
125
+
126
+ **Returns:**
127
+ - Object|null: Metadata object or null if format is invalid
128
+
129
+ **Example:**
130
+ ```javascript
131
+ const metadata = CompactedMessageUtils.extractCompactedMessageMetadata(compactedMessage);
132
+ console.log(metadata.originalChatUuid);
133
+ ```
134
+
135
+ #### `extractCompactedMessageContent(compactedMessage)`
136
+
137
+ Extracts just the content portion from a compacted message (without metadata).
138
+
139
+ **Parameters:**
140
+ - `compactedMessage` (string): The compacted message to parse
141
+
142
+ **Returns:**
143
+ - string|null: Content portion or null if format is invalid
144
+
145
+ **Example:**
146
+ ```javascript
147
+ const content = CompactedMessageUtils.extractCompactedMessageContent(compactedMessage);
148
+ ```
149
+
150
+ #### `validateCompactedMessageFormat(compactedMessage)`
151
+
152
+ Validates that a compacted message follows the expected format.
153
+
154
+ **Parameters:**
155
+ - `compactedMessage` (string): The compacted message to validate
156
+
157
+ **Returns:**
158
+ - Object: Validation result with isValid flag and any errors/warnings
159
+
160
+ **Example:**
161
+ ```javascript
162
+ const validation = CompactedMessageUtils.validateCompactedMessageFormat(compactedMessage);
163
+ if (validation.isValid) {
164
+ // Process valid compacted message
165
+ } else {
166
+ console.error(validation.errors);
167
+ }
168
+ ```
169
+
170
+ #### `isCompactedMessage(message)`
171
+
172
+ Checks if a message is a compacted message.
173
+
174
+ **Parameters:**
175
+ - `message` (string): The message content to check
176
+
177
+ **Returns:**
178
+ - boolean: True if the message is a compacted message
179
+
180
+ **Example:**
181
+ ```javascript
182
+ if (CompactedMessageUtils.isCompactedMessage(message)) {
183
+ // Handle compacted message
184
+ }
185
+ ```
186
+
187
+ #### `isValidUUID(uuid)`
188
+
189
+ Validates if a string is a valid UUID v4.
190
+
191
+ **Parameters:**
192
+ - `uuid` (string): The UUID string to validate
193
+
194
+ **Returns:**
195
+ - boolean: True if valid UUID v4
196
+
197
+ **Example:**
198
+ ```javascript
199
+ if (CompactedMessageUtils.isValidUUID(uuid)) {
200
+ // Process valid UUID
201
+ }
202
+ ```
203
+
204
+ #### `isValidMessageRange(range)`
205
+
206
+ Validates if a string is a valid message range (e.g., "3-6").
207
+
208
+ **Parameters:**
209
+ - `range` (string): The range string to validate
210
+
211
+ **Returns:**
212
+ - boolean: True if valid range format
213
+
214
+ **Example:**
215
+ ```javascript
216
+ if (CompactedMessageUtils.isValidMessageRange(range)) {
217
+ // Process valid range
218
+ }
219
+ ```
220
+
221
+ #### `isValidISOTimestamp(timestamp)`
222
+
223
+ Validates if a string is a valid ISO 8601 timestamp.
224
+
225
+ **Parameters:**
226
+ - `timestamp` (string): The timestamp string to validate
227
+
228
+ **Returns:**
229
+ - boolean: True if valid ISO 8601 timestamp
230
+
231
+ **Example:**
232
+ ```javascript
233
+ if (CompactedMessageUtils.isValidISOTimestamp(timestamp)) {
234
+ // Process valid timestamp
235
+ }
236
+ ```
237
+
238
+ ## Usage Examples
239
+
240
+ ### Parsing a Reference Message
241
+
242
+ ```javascript
243
+ const { ReferenceMessageUtils } = require('@gitsense/gsc-utils');
244
+
245
+ // Parse a reference message to extract data
246
+ const referenceData = ReferenceMessageUtils.extractReferenceMessageData(referenceMessage);
247
+
248
+ // Access the extracted data
249
+ const { messagesToCompact, messagesToKeep, originalChatUuid, range } = referenceData;
250
+
251
+ console.log(`Original Chat UUID: ${originalChatUuid}`);
252
+ console.log(`Messages to compact: ${messagesToCompact.length}`);
253
+ console.log(`Messages to keep: ${messagesToKeep.length}`);
254
+ ```
255
+
256
+ ### Formatting a Compacted Message
257
+
258
+ ```javascript
259
+ const { CompactedMessageUtils } = require('@gitsense/gsc-utils');
260
+
261
+ // Format a compacted message with metadata
262
+ const compactedMessage = CompactedMessageUtils.formatCompactedMessage(
263
+ "This is the compacted content...",
264
+ "123e4567-e89b-12d3-a456-426614174000",
265
+ "3-6",
266
+ { compactedAt: new Date() }
267
+ );
268
+
269
+ console.log(compactedMessage);
270
+ ```
271
+
272
+ ### Validating a Compacted Message
273
+
274
+ ```javascript
275
+ const { CompactedMessageUtils } = require('@gitsense/gsc-utils');
276
+
277
+ // Validate a compacted message
278
+ const validation = CompactedMessageUtils.validateCompactedMessageFormat(compactedMessage);
279
+
280
+ if (!validation.isValid) {
281
+ console.error("Validation errors:");
282
+ validation.errors.forEach(error => console.error(`- ${error}`));
283
+
284
+ if (validation.warnings.length > 0) {
285
+ console.warn("Validation warnings:");
286
+ validation.warnings.forEach(warning => console.warn(`- ${warning}`));
287
+ }
288
+ }
289
+ ```
290
+
291
+ ### Using the Combined Interface
292
+
293
+ ```javascript
294
+ const { CompactChatUtils } = require('@gitsense/gsc-utils');
295
+
296
+ // Check if a message is a reference message
297
+ if (CompactChatUtils.isReferenceMessage(message)) {
298
+ const data = CompactChatUtils.extractReferenceMessageData(message);
299
+ // Process reference message data
300
+ }
301
+
302
+ // Check if a message is a compacted message
303
+ if (CompactChatUtils.isCompactedMessage(message)) {
304
+ const metadata = CompactChatUtils.extractCompactedMessageMetadata(message);
305
+ // Process compacted message metadata
306
+ }
307
+ ```
308
+
309
+ ## File Structure
310
+
311
+ ```
312
+ src/CompactChatUtils/
313
+ ├── index.js # Main entry point that exports all utilities
314
+ ├── ReferenceMessageUtils.js # Utilities for parsing reference messages
315
+ ├── CompactedMessageUtils.js # Utilities for compacted messages
316
+ └── README.md # This documentation
317
+ ```
318
+
319
+ ## Dependencies
320
+
321
+ The CompactChatUtils module has no external dependencies and is part of the larger `@gitsense/gsc-utils` package.
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Component: ReferenceMessageUtils
3
+ * Block-UUID: 2870551a-4311-4d64-9491-c9cc62f276e8
4
+ * Parent-UUID: N/A
5
+ * Description: Utility for parsing reference messages in the compact message workflow, extracting session data, metadata, and message sections.
6
+ * Language: JavaScript
7
+ * Created-at: 2025-12-07T00:08:42.573Z
8
+ * Authors: GLM-4.6 (v1.0.0)
9
+ */
10
+
11
+
12
+ class ReferenceMessageUtils {
13
+ /**
14
+ * Extracts all data from a reference message including session data, metadata, and message sections
15
+ * @param {string} referenceMessage - The reference message content to parse
16
+ * @returns {Object} Parsed data with messages to compact and keep, metadata, and session information
17
+ */
18
+ static extractReferenceMessageData(referenceMessage) {
19
+ if (!referenceMessage) {
20
+ return {
21
+ messagesToCompact: [],
22
+ messagesToKeep: [],
23
+ originalChatUuid: null,
24
+ validationHash: null,
25
+ sessionId: null,
26
+ range: null,
27
+ from: null,
28
+ to: null
29
+ };
30
+ }
31
+
32
+ // Extract Original Chat UUID
33
+ const originalChatUuidMatch = referenceMessage.match(/Original Chat UUID:\s*([a-f0-9-]+)/i);
34
+ const originalChatUuid = originalChatUuidMatch ? originalChatUuidMatch[1] : null;
35
+
36
+ // Extract Validation Hash
37
+ const validationHashMatch = referenceMessage.match(/Validation Hash:\s*([a-f0-9]+)/i);
38
+ const validationHash = validationHashMatch ? validationHashMatch[1] : null;
39
+
40
+ // Extract Session ID
41
+ const sessionIdMatch = referenceMessage.match(/Session ID:\s*(\d+)/i);
42
+ const sessionId = sessionIdMatch ? sessionIdMatch[1] : null;
43
+
44
+ // Extract Range
45
+ const rangeMatch = referenceMessage.match(/Range:\s*(\d+-\d+)/i);
46
+ const range = rangeMatch ? rangeMatch[1] : null;
47
+
48
+ // Extract From and To values
49
+ const fromMatch = referenceMessage.match(/From:\s*(\d+)/i);
50
+ const from = fromMatch ? parseInt(fromMatch[1], 10) : null;
51
+
52
+ const toMatch = referenceMessage.match(/To:\s*(\d+)/i);
53
+ const to = toMatch ? parseInt(toMatch[1], 10) : null;
54
+
55
+ // If range is not found but from and to are available, construct the range
56
+ if (!range && from !== null && to !== null) {
57
+ range = `${from}-${to}`;
58
+ }
59
+
60
+ // Extract Messages to Compact section
61
+ const compactSectionMatch = referenceMessage.match(/# Messages to Compact\n([\s\S]*?)(?=\n# |\n$|$)/);
62
+ const compactSection = compactSectionMatch ? compactSectionMatch[1] : '';
63
+
64
+ // Extract Messages to Keep section
65
+ const keepSectionMatch = referenceMessage.match(/# Messages to Keep \(Context\)\n([\s\S]*?)(?=\n# |\n$|$)/);
66
+ const keepSection = keepSectionMatch ? keepSectionMatch[1] : '';
67
+
68
+ // Parse messages from each section
69
+ const messagesToCompact = this.parseMessageSection(compactSection);
70
+ const messagesToKeep = this.parseMessageSection(keepSection);
71
+
72
+ return {
73
+ messagesToCompact,
74
+ messagesToKeep,
75
+ originalChatUuid,
76
+ validationHash,
77
+ sessionId,
78
+ range,
79
+ from,
80
+ to
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Parses a message section to extract individual messages
86
+ * @param {string} section - The section content to parse
87
+ * @returns {Array} Array of parsed message objects
88
+ */
89
+ static parseMessageSection(section) {
90
+ if (!section) return [];
91
+
92
+ const messages = [];
93
+ const messageRegex = /<(\w+) message number (\d+)>\n([\s\S]*?)\n<\/\1 message number \2>/g;
94
+ let match;
95
+
96
+ while ((match = messageRegex.exec(section)) !== null) {
97
+ const [, role, positionStr, content] = match;
98
+ const position = parseInt(positionStr, 10);
99
+
100
+ messages.push({
101
+ role,
102
+ position,
103
+ content: content.trim()
104
+ });
105
+ }
106
+
107
+ return messages;
108
+ }
109
+
110
+ /**
111
+ * Extracts just the metadata from a reference message without the message sections
112
+ * @param {string} referenceMessage - The reference message content to parse
113
+ * @returns {Object} Metadata object with original chat UUID, validation hash, session ID, and range information
114
+ */
115
+ static extractReferenceMessageMetadata(referenceMessage) {
116
+ const data = this.extractReferenceMessageData(referenceMessage);
117
+
118
+ return {
119
+ originalChatUuid: data.originalChatUuid,
120
+ validationHash: data.validationHash,
121
+ sessionId: data.sessionId,
122
+ range: data.range,
123
+ from: data.from,
124
+ to: data.to
125
+ };
126
+ }
127
+
128
+ /**
129
+ * Checks if a message is a reference message
130
+ * @param {string} message - The message content to check
131
+ * @returns {boolean} True if the message is a reference message
132
+ */
133
+ static isReferenceMessage(message) {
134
+ if (!message) return false;
135
+
136
+ // Check for key indicators of a reference message
137
+ return message.includes('# Compact Messages Reference') &&
138
+ message.includes('Original Chat UUID:') &&
139
+ message.includes('Session ID:');
140
+ }
141
+ }
142
+
143
+ module.exports = { ReferenceMessageUtils };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Component: CompactChatUtils Index
3
+ * Block-UUID: cd0a6091-edb6-4e92-9439-63dd8f6a6796
4
+ * Parent-UUID: 5ffa0338-b4fb-4968-908c-f23a26d4923b
5
+ * Version: 2.0.0
6
+ * Description: Entry point for CompactChatUtils that exports both ReferenceMessageUtils and CompactedMessageUtils methods directly for easier access.
7
+ * Language: JavaScript
8
+ * Created-at: 2025-12-07T00:10:05.123Z
9
+ * Authors: GLM-4.6 (v1.0.0), GLM-4.6 (v2.0.0)
10
+ */
11
+
12
+
13
+ const { ReferenceMessageUtils } = require('./ReferenceMessageUtils');
14
+ const { CompactedMessageUtils } = require('./CompactedMessageUtils');
15
+
16
+ /**
17
+ * CompactChatUtils provides utilities for working with compacted messages in GitSense Chat.
18
+ * It includes functionality for parsing reference messages and formatting/parsing compacted messages.
19
+ */
20
+ module.exports = {
21
+ // Export the classes for those who want to access them directly
22
+ ReferenceMessageUtils,
23
+ CompactedMessageUtils,
24
+
25
+ // Export all methods from ReferenceMessageUtils directly
26
+ extractReferenceMessageData: ReferenceMessageUtils.extractReferenceMessageData,
27
+ parseMessageSection: ReferenceMessageUtils.parseMessageSection,
28
+ extractReferenceMessageMetadata: ReferenceMessageUtils.extractReferenceMessageMetadata,
29
+ isReferenceMessage: ReferenceMessageUtils.isReferenceMessage,
30
+
31
+ // Export all methods from CompactedMessageUtils directly
32
+ formatCompactedMessage: CompactedMessageUtils.formatCompactedMessage,
33
+ extractCompactedMessageMetadata: CompactedMessageUtils.extractCompactedMessageMetadata,
34
+ extractCompactedMessageContent: CompactedMessageUtils.extractCompactedMessageContent,
35
+ validateCompactedMessageFormat: CompactedMessageUtils.validateCompactedMessageFormat,
36
+ isCompactedMessage: CompactedMessageUtils.isCompactedMessage,
37
+ isValidUUID: CompactedMessageUtils.isValidUUID,
38
+ isValidMessageRange: CompactedMessageUtils.isValidMessageRange,
39
+ isValidISOTimestamp: CompactedMessageUtils.isValidISOTimestamp
40
+ };
@@ -1,12 +1,12 @@
1
1
  /*
2
2
  * Component: ContextUtils
3
- * Block-UUID: a0b71292-b1cc-401a-8ce2-544a047b0fef
4
- * Parent-UUID: c018b1f9-2291-4bc9-9c4b-ab53a5db745e
5
- * Version: 1.3.0
3
+ * Block-UUID: 534c348d-a11f-4de6-ad15-f33068d51fb8
4
+ * Parent-UUID: a0b71292-b1cc-401a-8ce2-544a047b0fef
5
+ * Version: 1.4.0
6
6
  * Description: Provides utility functions for parsing context message sections to extract file details and code blocks, and for formatting content for LLM context.
7
7
  * Language: JavaScript
8
8
  * Created-at: 2025-05-09T01:36:20.107Z
9
- * Authors: Gemini 2.5 Flash Thinking (v1.0.0), Gemini 2.5 Flash (v1.1.0), Qwen 3 Coder 480B - Cerebras (v1.2.0), Qwen 3 Coder 480B - Cerebras (v1.3.0)
9
+ * Authors: Gemini 2.5 Flash Thinking (v1.0.0), Gemini 2.5 Flash (v1.1.0), Qwen 3 Coder 480B - Cerebras (v1.2.0), Qwen 3 Coder 480B - Cerebras (v1.3.0), Qwen 3 Coder 480B - Cerebras (v1.4.0)
10
10
  */
11
11
 
12
12
 
@@ -77,6 +77,41 @@ function _createContextSummary(items, contentType) {
77
77
  return summary + "\n";
78
78
  }
79
79
 
80
+ /**
81
+ * Extracts all context files from a given chat object.
82
+ * Iterates through chat messages, identifies context loader outputs,
83
+ * and parses them into individual file objects.
84
+ *
85
+ * @param {object} chat - The GitSense chat object.
86
+ * @returns {Array<object>} An array of parsed context file objects.
87
+ * Returns an empty array if no context files are found or on error.
88
+ */
89
+ function getContextFiles(chat) {
90
+ const ChatUtils = require('./ChatUtils');
91
+ const contextFiles = [];
92
+ const messages = ChatUtils.getChatMessages(chat);
93
+
94
+ if (!Array.isArray(messages)) {
95
+ console.warn("getContextFiles: Provided chat object does not contain a valid messages array.");
96
+ return contextFiles;
97
+ }
98
+
99
+ messages.forEach(message => {
100
+ // Check if the message content is a context message
101
+ if (MessageUtils.isContextMessage(message.message)) {
102
+ try {
103
+ // Extract all context sections from the message content
104
+ const extractedFiles = extractContextSections(message.message);
105
+ contextFiles.push(...extractedFiles);
106
+ } catch (error) {
107
+ console.warn(`getContextFiles: Failed to extract context sections from message ID ${message.id}:`, error);
108
+ }
109
+ }
110
+ });
111
+
112
+ return contextFiles;
113
+ }
114
+
80
115
  /**
81
116
  * Escapes backticks in code blocks to prevent premature termination of LLM-generated code blocks.
82
117
  * @param {string} content - The content string to escape.
@@ -141,7 +176,7 @@ function parseContextSection(sectionText) {
141
176
  if (properties.includes(property)) {
142
177
  let value = trimmedLine.split(':').slice(1).join(':').trim();
143
178
 
144
- if (property.match(/id/))
179
+ if (property.match(/id/) || property.match(/tokens/))
145
180
  value = parseInt(value);
146
181
 
147
182
  contextSection[property] = value;
@@ -351,6 +386,7 @@ function formatContextContent(items, contentType, contentOption) {
351
386
  module.exports = {
352
387
  parseContextSection,
353
388
  extractContextSections,
389
+ getContextFiles,
354
390
  extractContextItemsOverviewTableRows,
355
391
  formatContextContent,
356
392
  };