@gitsense/gsc-utils 0.2.25 → 0.2.28
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 +380 -62
- package/dist/gsc-utils.cjs.js +2290 -326
- package/dist/gsc-utils.esm.js +2290 -326
- package/package.json +1 -1
- package/src/AnalyzerUtils/cloner.js +149 -0
- package/src/AnalyzerUtils/constants.js +1 -1
- package/src/AnalyzerUtils/defaultPromptLoader.js +10 -10
- package/src/AnalyzerUtils/discovery.js +48 -39
- package/src/AnalyzerUtils/index.js +13 -7
- package/src/AnalyzerUtils/instructionLoader.js +6 -6
- package/src/AnalyzerUtils/jsonParser.js +35 -0
- package/src/AnalyzerUtils/management.js +6 -6
- package/src/AnalyzerUtils/saver.js +5 -5
- package/src/AnalyzerUtils/schemaLoader.js +194 -26
- package/src/AnalyzerUtils/updater.js +187 -0
- package/src/CodeBlockUtils/blockProcessor.js +14 -32
- package/src/CodeBlockUtils/index.js +7 -6
- package/src/CodeBlockUtils/lineageTracer.js +95 -0
- package/src/CompactChatUtils/CompactedMessageUtils.js +224 -0
- package/src/CompactChatUtils/README.md +321 -0
- package/src/CompactChatUtils/ReferenceMessageUtils.js +143 -0
- package/src/CompactChatUtils/index.js +40 -0
- package/src/ContextUtils.js +40 -4
- package/src/DomUtils.js +102 -14
- package/src/FormatterUtils.js +1 -1
- package/src/GSToolBlockUtils.js +66 -1
- package/src/GitSenseChatUtils.js +58 -5
- package/src/LLMUtils.js +1 -1
- package/src/MarkdownUtils.js +4 -1
- package/src/MessageUtils.js +1 -1
- package/src/MetaRawResultUtils.js +244 -0
- package/src/PatchUtils/constants.js +9 -3
- package/src/PatchUtils/patchParser.js +60 -36
- package/src/PatchUtils/patchVerifier/detectAndFixOverlappingHunks.js +1 -1
- package/src/PatchUtils/patchVerifier/detectAndFixRedundantChanges.js +1 -1
- package/src/PatchUtils/patchVerifier/verifyAndCorrectHunkHeaders.js +1 -1
- package/src/SVGUtils.js +137 -2
- package/src/SharedUtils/stringUtils.js +303 -0
- package/src/CodeBlockUtils/blockProcessor.js.rej +0 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# GitSense Chat Utils (gsc-utils)
|
|
2
2
|
|
|
3
|
-
A comprehensive JavaScript library providing utilities for processing, manipulating, and managing various elements within GitSense Chat messages, including code blocks, patches, analyzers, and
|
|
3
|
+
A comprehensive JavaScript library providing utilities for processing, manipulating, and managing various elements within GitSense Chat messages, including code blocks, patches, analyzers, context data, and compacted messages.
|
|
4
4
|
|
|
5
5
|
## Code Structure
|
|
6
6
|
|
|
@@ -12,72 +12,193 @@ A comprehensive JavaScript library providing utilities for processing, manipulat
|
|
|
12
12
|
├── package.json
|
|
13
13
|
├── rollup.config.js
|
|
14
14
|
├── src
|
|
15
|
-
│
|
|
16
|
-
│
|
|
17
|
-
│
|
|
18
|
-
│
|
|
19
|
-
│
|
|
20
|
-
│
|
|
21
|
-
│
|
|
22
|
-
│
|
|
23
|
-
│
|
|
24
|
-
│
|
|
25
|
-
│
|
|
26
|
-
│
|
|
27
|
-
│
|
|
28
|
-
│
|
|
29
|
-
│
|
|
30
|
-
│
|
|
31
|
-
│
|
|
32
|
-
│
|
|
33
|
-
│
|
|
34
|
-
│
|
|
35
|
-
│
|
|
36
|
-
│
|
|
37
|
-
│
|
|
38
|
-
│
|
|
39
|
-
│
|
|
40
|
-
│
|
|
41
|
-
│
|
|
42
|
-
│
|
|
43
|
-
│
|
|
44
|
-
│
|
|
45
|
-
│
|
|
46
|
-
│
|
|
47
|
-
│
|
|
48
|
-
│
|
|
49
|
-
│
|
|
50
|
-
│
|
|
51
|
-
│
|
|
52
|
-
│
|
|
53
|
-
│
|
|
54
|
-
│
|
|
55
|
-
│
|
|
56
|
-
│
|
|
57
|
-
│
|
|
58
|
-
│
|
|
59
|
-
│
|
|
60
|
-
│
|
|
61
|
-
│
|
|
62
|
-
│
|
|
63
|
-
│
|
|
64
|
-
│
|
|
65
|
-
│
|
|
66
|
-
│
|
|
67
|
-
│
|
|
68
|
-
│
|
|
69
|
-
│
|
|
70
|
-
│
|
|
71
|
-
│
|
|
72
|
-
│
|
|
73
|
-
│
|
|
15
|
+
│ ├── AnalysisBlockUtils.js
|
|
16
|
+
│ ├── AnalyzerUtils
|
|
17
|
+
│ │ ├── constants.js
|
|
18
|
+
│ │ ├── contextMapper.js
|
|
19
|
+
│ │ ├── dataValidator.js
|
|
20
|
+
│ │ ├── defaultPromptLoader.js
|
|
21
|
+
│ │ ├── discovery.js
|
|
22
|
+
│ │ ├── index.js
|
|
23
|
+
│ │ ├── instructionLoader.js
|
|
24
|
+
│ │ ├── management.js
|
|
25
|
+
│ │ ├── responseProcessor.js
|
|
26
|
+
│ │ ├── saver.js
|
|
27
|
+
│ │ └── schemaLoader.js
|
|
28
|
+
│ ├── ChatUtils.js
|
|
29
|
+
│ ├── CodeBlockUtils
|
|
30
|
+
│ │ ├── blockExtractor.js
|
|
31
|
+
│ │ ├── blockProcessor.js
|
|
32
|
+
│ │ ├── constants.js
|
|
33
|
+
│ │ ├── continuationUtils.js
|
|
34
|
+
│ │ ├── headerParser.js
|
|
35
|
+
│ │ ├── headerUtils.js
|
|
36
|
+
│ │ ├── index.js
|
|
37
|
+
│ │ ├── lineNumberFormatter.js
|
|
38
|
+
│ │ ├── markerRemover.js
|
|
39
|
+
│ │ ├── patchIntegration.js
|
|
40
|
+
│ │ ├── relationshipUtils.js
|
|
41
|
+
│ │ ├── updateCodeBlock.js
|
|
42
|
+
│ │ └── uuidUtils.js
|
|
43
|
+
│ ├── CompactChatUtils
|
|
44
|
+
│ │ ├── index.js
|
|
45
|
+
│ │ ├── ReferenceMessageUtils.js
|
|
46
|
+
│ │ ├── CompactedMessageUtils.js
|
|
47
|
+
│ │ └── README.md
|
|
48
|
+
│ ├── ConfigUtils.js
|
|
49
|
+
│ ├── ContextUtils.js
|
|
50
|
+
│ ├── DateUtils.js
|
|
51
|
+
│ ├── DomUtils.js
|
|
52
|
+
│ ├── EnvUtils.js
|
|
53
|
+
│ ├── FormatterUtils.js
|
|
54
|
+
│ ├── GSToolBlockUtils.js
|
|
55
|
+
│ ├── GitSenseChatUtils.js
|
|
56
|
+
│ ├── JsonUtils.js
|
|
57
|
+
│ ├── LanguageNameUtils.js
|
|
58
|
+
│ ├── LLMUtils.js
|
|
59
|
+
│ ├── MarkdownUtils.js
|
|
60
|
+
│ ├── MetaRawResultUtils.js
|
|
61
|
+
│ ├── MessageUtils.js
|
|
62
|
+
│ ├── ObjectUtils.js
|
|
63
|
+
│ ├── PatchUtils
|
|
64
|
+
│ │ ├── constants.js
|
|
65
|
+
│ │ ├── diagnosticReporter.js
|
|
66
|
+
│ │ ├── enhancedPatchProcessor.js
|
|
67
|
+
│ │ ├── fuzzyMatcher.js
|
|
68
|
+
│ │ ├── hunkCorrector.js
|
|
69
|
+
│ │ ├── hunkValidator.js
|
|
70
|
+
│ │ ├── index.js
|
|
71
|
+
│ │ ├── patchExtractor.js
|
|
72
|
+
│ │ ├── patchHeaderFormatter.js
|
|
73
|
+
│ │ ├── patchParser.js
|
|
74
|
+
│ │ ├── patchProcessor.js
|
|
75
|
+
│ │ └── patchVerifier
|
|
76
|
+
│ │ ├── constants.js
|
|
77
|
+
│ │ ├── detectAndFixOverlappingHunks.js
|
|
78
|
+
│ │ ├── detectAndFixRedundantChanges.js
|
|
79
|
+
│ │ ├── formatAndAddLineNumbers.js
|
|
80
|
+
│ │ ├── index.js
|
|
81
|
+
│ │ ├── verifyAndCorrectHunkHeaders.js
|
|
82
|
+
│ │ └── verifyAndCorrectLineNumbers.js
|
|
83
|
+
│ └── SharedUtils
|
|
84
|
+
│ ├── stringUtils.js
|
|
85
|
+
│ ├── timestampUtils.js
|
|
86
|
+
│ └── versionUtils.js
|
|
74
87
|
```
|
|
75
88
|
|
|
76
89
|
## Core Modules
|
|
77
90
|
|
|
78
91
|
### GitSenseChatUtils (Main Interface)
|
|
79
92
|
|
|
80
|
-
This is the primary class exported by the library, offering a unified API for interacting with the various utility modules. It aggregates functionalities from `CodeBlockUtils`, `PatchUtils`, `AnalyzerUtils`, `MessageUtils`, `LLMUtils`, `ConfigUtils`, and `
|
|
93
|
+
This is the primary class exported by the library, offering a unified API for interacting with the various utility modules. It aggregates functionalities from `CodeBlockUtils`, `PatchUtils`, `AnalyzerUtils`, `MessageUtils`, `LLMUtils`, `ConfigUtils`, `EnvUtils`, `MetaRawResultUtils`, and `CompactChatUtils`.
|
|
94
|
+
|
|
95
|
+
### CompactChatUtils
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
#### Overview
|
|
100
|
+
|
|
101
|
+
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:
|
|
102
|
+
|
|
103
|
+
- **ReferenceMessageUtils**: Parses reference messages that contain information about which messages to compact and which to keep as context
|
|
104
|
+
- **CompactedMessageUtils**: Formats, parses, and validates compacted messages with standardized metadata headers
|
|
105
|
+
|
|
106
|
+
#### Core Functions
|
|
107
|
+
|
|
108
|
+
* **`extractReferenceMessageData(referenceMessage)`**: Extracts all data from a reference message including session data, metadata, and message sections.
|
|
109
|
+
* **`parseMessageSection(section)`**: Parses a message section to extract individual messages.
|
|
110
|
+
* **`extractReferenceMessageMetadata(referenceMessage)`**: Extracts just the metadata from a reference message without the message sections.
|
|
111
|
+
* **`isReferenceMessage(message)`**: Checks if a message is a reference message.
|
|
112
|
+
* **`formatCompactedMessage(content, originalChatUuid, messageRange, options)`**: Formats a compacted message with standardized metadata headers.
|
|
113
|
+
* **`extractCompactedMessageMetadata(compactedMessage)`**: Extracts metadata from a compacted message.
|
|
114
|
+
* **`extractCompactedMessageContent(compactedMessage)`**: Extracts just the content portion from a compacted message (without metadata).
|
|
115
|
+
* **`validateCompactedMessageFormat(compactedMessage)`**: Validates that a compacted message follows the expected format.
|
|
116
|
+
* **`isCompactedMessage(message)`**: Checks if a message is a compacted message.
|
|
117
|
+
* **`isValidUUID(uuid)`**: Validates if a string is a valid UUID v4.
|
|
118
|
+
* **`isValidMessageRange(range)`**: Validates if a string is a valid message range (e.g., "3-6").
|
|
119
|
+
* **`isValidISOTimestamp(timestamp)`**: Validates if a string is a valid ISO 8601 timestamp.
|
|
120
|
+
|
|
121
|
+
#### Usage Example
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
const { CompactChatUtils } = require('@gitsense/gsc-utils');
|
|
125
|
+
|
|
126
|
+
// Parse a reference message
|
|
127
|
+
if (CompactChatUtils.isReferenceMessage(message)) {
|
|
128
|
+
const data = CompactChatUtils.extractReferenceMessageData(message);
|
|
129
|
+
console.log(`Original Chat UUID: ${data.originalChatUuid}`);
|
|
130
|
+
console.log(`Messages to compact: ${data.messagesToCompact.length}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Format a compacted message
|
|
134
|
+
const compactedMessage = CompactChatUtils.formatCompactedMessage(
|
|
135
|
+
"This is the compacted content...",
|
|
136
|
+
"123e4567-e89b-12d3-a456-426614174000",
|
|
137
|
+
"3-6"
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Validate a compacted message
|
|
141
|
+
const validation = CompactChatUtils.validateCompactedMessageFormat(compactedMessage);
|
|
142
|
+
if (!validation.isValid) {
|
|
143
|
+
console.error("Validation errors:", validation.errors);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### MetaRawResultUtils
|
|
148
|
+
|
|
149
|
+
Provides utilities for parsing and extracting file metadata mappings from `meta-raw-result` messages in GitSense Chat. These utilities are essential for validating chat ID references in AI-generated context bundles and providing file information for metadata-driven workflows.
|
|
150
|
+
|
|
151
|
+
#### Core Functions
|
|
152
|
+
|
|
153
|
+
* **`extractMetaRawResultMappings(chat, model)`**: The primary function for processing all messages in a chat and extracting mappings from `meta-raw-result` messages. It returns a Map of chatId to file metadata objects, enabling validation of chat ID references and providing comprehensive file information.
|
|
154
|
+
* **`isMetaRawResultMessage(message)`**: Validates whether a given message object represents a `meta-raw-result` message by checking the message type and content indicators like `profile:meta-raw` and the presence of data sections.
|
|
155
|
+
* **`parseMetaRawResultContent(messageContent)`**: Parses the content of a single `meta-raw-result` message to extract chat ID to file metadata mappings. Handles the markdown table format used in these messages.
|
|
156
|
+
* **`parseTableRow(rowLine)`**: Parses a single table row from `meta-raw-result` content, extracting file information like chat ID, path, repository, branch, language, size, and tokens.
|
|
157
|
+
* **`parseSize(sizeStr)`**: Converts size strings (e.g., "1.2 KB", "500 B") to bytes for consistent numerical processing.
|
|
158
|
+
* **`parseTokens(tokensStr)`**: Converts token strings (e.g., "1.2k", "500") to numerical token counts for analysis and validation.
|
|
159
|
+
|
|
160
|
+
#### Mapping Structure
|
|
161
|
+
|
|
162
|
+
The utility returns mappings with the following structure:
|
|
163
|
+
```javascript
|
|
164
|
+
{
|
|
165
|
+
chatId: {
|
|
166
|
+
id: number, // The chat ID
|
|
167
|
+
name: string, // File name
|
|
168
|
+
path: string, // File path (repo/path)
|
|
169
|
+
repo: string, // Repository name
|
|
170
|
+
branch: string, // Branch name
|
|
171
|
+
language: string, // File language
|
|
172
|
+
size: number, // File size in bytes
|
|
173
|
+
tokens: number, // Token count
|
|
174
|
+
commitHash: string, // Last commit hash
|
|
175
|
+
commitTimestamp: number, // Unix timestamp
|
|
176
|
+
analyzedTimestamp: string, // ISO timestamp of last analysis
|
|
177
|
+
fullPath: string // Full path including repo
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Usage Example
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
const { MetaRawResultUtils } = require('@gitsense/gsc-utils');
|
|
186
|
+
|
|
187
|
+
// Extract all meta-raw-result mappings from a chat
|
|
188
|
+
const mappings = MetaRawResultUtils.extractMetaRawResultMappings(chat, message.model);
|
|
189
|
+
|
|
190
|
+
// Validate a chat ID reference
|
|
191
|
+
if (mappings.has(chatId)) {
|
|
192
|
+
const fileInfo = mappings.get(chatId);
|
|
193
|
+
console.log(`Valid file: ${fileInfo.fullPath} (${fileInfo.size} bytes)`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Check if a message is a meta-raw-result message
|
|
197
|
+
if (MetaRawResultUtils.isMetaRawResultMessage(message)) {
|
|
198
|
+
const contentMappings = MetaRawResultUtils.parseMetaRawResultContent(message.message);
|
|
199
|
+
// Process individual message mappings
|
|
200
|
+
}
|
|
201
|
+
```
|
|
81
202
|
|
|
82
203
|
### CodeBlockUtils
|
|
83
204
|
|
|
@@ -243,6 +364,7 @@ Provides a suite of utilities for managing and interacting with GitSense Chat an
|
|
|
243
364
|
|
|
244
365
|
* **`getAnalyzers(basePath, options)`**: Discovers and lists all available analyzers by traversing the directory structure under `basePath`. An analyzer is considered valid if its corresponding `1.md` instruction file exists. The `options` parameter can include `includeDescription` to optionally load the analyzer's description from its JSON metadata.
|
|
245
366
|
* **`getAnalyzerSchema(basePath, analyzerId)`**: Retrieves the JSON schema for a specific analyzer identified by `analyzerId`. It reads the corresponding `1.md` file, extracts the JSON block, and deduces schema types from the metadata fields.
|
|
367
|
+
* **`getAnalyzerConfigMetadata(basePath, analyzerId)`**: Retrieves the configuration metadata (description, version, tags) for a specific analyzer identified by `analyzerId`. It reads the corresponding `1.md` file and extracts the top-level properties from the JSON block.
|
|
246
368
|
* **`getAnalyzerInstructionsContent(basePath, analyzerId)`**: Loads the raw Markdown content of a specific analyzer's `1.md` instruction file based on its `analyzerId`.
|
|
247
369
|
* **`saveConfiguration(basePath, analyzerId, instructionsContent, options)`**: Saves or updates an analyzer configuration. It parses the `analyzerId` to determine the directory structure, creates directories if necessary, and saves the `instructionsContent` to `1.md`. It can optionally ensure `config.json` files exist in the analyzer, content, and instructions directories.
|
|
248
370
|
* **`deleteAnalyzer(basePath, analyzerId)`**: Deletes a specific analyzer configuration and intelligently cleans up empty directories. It checks for protection at all levels (analyzer, content type, instructions type) before deletion.
|
|
@@ -341,6 +463,7 @@ Provides utility functions for parsing and formatting context message sections.
|
|
|
341
463
|
* **`parseContextSection(sectionText)`**: Parses the details (name, path, chat ID, etc.) and code content from a single context message section.
|
|
342
464
|
* **`extractContextSections(messageContent)`**: Extracts and parses all context sections from a full context message string.
|
|
343
465
|
* **`extractContextItemsOverviewTableRows(messageContent)`**: Parses the table rows from a Context Items Overview message.
|
|
466
|
+
* **`getContextFiles(chat)`**: Extracts all context files from a given chat object.
|
|
344
467
|
* **`formatContextContent(items, contentType, contentOption)`**: Formats an array of loaded items into a structured context message string suitable for LLM consumption.
|
|
345
468
|
|
|
346
469
|
### AnalysisBlockUtils
|
|
@@ -354,6 +477,121 @@ Provides utilities for identifying, parsing, and validating structured analysis
|
|
|
354
477
|
* **`parseOverviewMetadata(content)`**: Parses the metadata fields from an analysis block's content, assuming a Markdown list format.
|
|
355
478
|
* **`validateAnalysisMetadata(metadata)`**: Validates the parsed analysis metadata object, checking for required fields like 'Chat ID'.
|
|
356
479
|
|
|
480
|
+
### ChatUtils
|
|
481
|
+
|
|
482
|
+
Provides utility functions for analyzing and classifying chat sessions based on message content and structure.
|
|
483
|
+
|
|
484
|
+
#### Core Functions
|
|
485
|
+
|
|
486
|
+
* **`isAskChat(chat, model)`**: Determines if the current chat session appears to be an "Ask" session.
|
|
487
|
+
* **`isNewAnalyzerChat(chat, model)`**: Determines if the current chat session appears to be a "New Analyzer" session.
|
|
488
|
+
* **`isAnalyzeChat(chat)`**: Determines if the current chat session appears to be an "Analyze" session.
|
|
489
|
+
* **`isAnalyzeBuilderChat(chat)`**: Determines if the current chat session appears to be an "Analyze Builder" session.
|
|
490
|
+
* **`isPlanChat(chat, model)`**: Determines if the current chat session appears to be a "Plan Chat" session.
|
|
491
|
+
* **`isCodeChat(chat, model)`**: Determines if the current chat session appears to be a "Code Chat" session.
|
|
492
|
+
* **`getChatMessages(chat, model)`**: Retrieves all messages from a chat session.
|
|
493
|
+
|
|
494
|
+
### DateUtils
|
|
495
|
+
|
|
496
|
+
Provides date formatting and manipulation utilities for GitSense Chat.
|
|
497
|
+
|
|
498
|
+
#### Core Functions
|
|
499
|
+
|
|
500
|
+
* **`formatAge(dateString)`**: Formats a date string into a relative time string (e.g., "5m ago").
|
|
501
|
+
* **`isValidDateString(dateString)`**: Validates a date string format.
|
|
502
|
+
* **`compareDates(dateA, dateB)`**: Compares two date strings.
|
|
503
|
+
* **`normalizeDateTime(dateString)`**: Ensures a date string has a timezone indicator.
|
|
504
|
+
* **`getTimeDifference(dateString)`**: Calculates the time difference between now and a given date.
|
|
505
|
+
* **`formatTimeDifference(diff)`**: Formats a time difference in seconds to a human-readable string.
|
|
506
|
+
|
|
507
|
+
### DomUtils
|
|
508
|
+
|
|
509
|
+
Provides helper functions for creating and manipulating DOM elements.
|
|
510
|
+
|
|
511
|
+
#### Core Functions
|
|
512
|
+
|
|
513
|
+
* **`h.createElement(type, params)`**: Creates a new DOM element with specified attributes and properties.
|
|
514
|
+
* **`h.createDiv(params)`**, **`h.createSpan(params)`**, **`h.createP(params)`**, etc.: Factory methods for creating common HTML elements.
|
|
515
|
+
* **`h.updateDOM(sourceNode, targetNode)`**: Efficiently updates a target DOM node to match a source node.
|
|
516
|
+
* **`h.safeEscape(html)`**: Escapes HTML in a string, preserving content within specified tags.
|
|
517
|
+
* **`h.injectStyles(cssString, id)`**: Injects CSS styles into the document head.
|
|
518
|
+
* **`h.getDistanceFromViewportEdge(elem, edge)`**: Calculates the distance from an element to the viewport edge.
|
|
519
|
+
|
|
520
|
+
### LanguageNameUtils
|
|
521
|
+
|
|
522
|
+
Utility for converting common lowercase language names and aliases to their proper capitalization.
|
|
523
|
+
|
|
524
|
+
#### Core Functions
|
|
525
|
+
|
|
526
|
+
* **`normalizeLanguageName(language)`**: Normalizes a language name or alias to its proper capitalization.
|
|
527
|
+
* **`isKnownLanguage(language)`**: Checks if a language name or alias is known to the normalizer.
|
|
528
|
+
* **`getKnownLanguageAliases()`**: Gets all known language aliases.
|
|
529
|
+
* **`getLanguageNameMap()`**: Gets the mapping of language aliases to their normalized names.
|
|
530
|
+
|
|
531
|
+
### ObjectUtils
|
|
532
|
+
|
|
533
|
+
Utility functions for processing and manipulating JavaScript objects.
|
|
534
|
+
|
|
535
|
+
#### Core Functions
|
|
536
|
+
|
|
537
|
+
* **`trimObjectStrings(obj, maxLength, suffix)`**: Recursively trims string properties in an object to a maximum length.
|
|
538
|
+
|
|
539
|
+
### SVGUtils
|
|
540
|
+
|
|
541
|
+
Utility module for creating and managing SVG elements. Provides factory methods for generating common SVG icons and elements with customizable parameters.
|
|
542
|
+
|
|
543
|
+
#### Core Functions
|
|
544
|
+
|
|
545
|
+
* **`SVGUtils.create(xml, params, xmlOnly)`**: Creates an SVG element from an XML string.
|
|
546
|
+
* **`SVGUtils.aiModel(params)`**, **`SVGUtils.alert(params)`**, **`SVGUtils.apps(params)`**, etc.: Factory methods for generating a wide variety of SVG icons.
|
|
547
|
+
|
|
548
|
+
### MarkdownUtils
|
|
549
|
+
|
|
550
|
+
Provides utilities for configuring and using markdown-it with highlight.js for rendering Markdown content with syntax highlighting.
|
|
551
|
+
|
|
552
|
+
#### Core Functions
|
|
553
|
+
|
|
554
|
+
* **`createMarkdownRenderer(hljs, hstyle, nhstyle)`**: Creates a configured markdown renderer instance.
|
|
555
|
+
* **`removeSignature(body)`**: Removes any existing LLM author signature from rendered markdown HTML.
|
|
556
|
+
|
|
557
|
+
### FormatterUtils
|
|
558
|
+
|
|
559
|
+
Utility functions for formatting content in GitSense Chat.
|
|
560
|
+
|
|
561
|
+
#### Core Functions
|
|
562
|
+
|
|
563
|
+
* **`formatBytes(bytes)`**: Formats bytes into human-readable string (KB, MB, GB).
|
|
564
|
+
* **`formatTokens(count)`**: Formats token count into human-readable string (k, m, b).
|
|
565
|
+
|
|
566
|
+
### SharedUtils
|
|
567
|
+
|
|
568
|
+
Provides a collection of utility functions for common tasks shared across different parts of the GitSense Chat system.
|
|
569
|
+
|
|
570
|
+
#### String Utilities
|
|
571
|
+
|
|
572
|
+
* **`splitWithLimit(text, delimiter, limit)`**: Splits a string into an array of substrings based on a delimiter, up to a specified limit.
|
|
573
|
+
* **`capitalize(text)`**: Capitalizes the first character of a string.
|
|
574
|
+
* **`titleCase(text)`**: Converts a string to title case (capitalizing the first letter of each word).
|
|
575
|
+
* **`camelCase(text)`**: Converts a string to camelCase.
|
|
576
|
+
* **`pascalCase(text)`**: Converts a string to PascalCase.
|
|
577
|
+
* **`kebabCase(text)`**: Converts a string to kebab-case.
|
|
578
|
+
* **`snakeCase(text)`**: Converts a string to snake_case.
|
|
579
|
+
* **`constantCase(text)`**: Converts a string to CONSTANT_CASE.
|
|
580
|
+
* **`trimWhitespace(text)`**: Trims leading and trailing whitespace and normalizes internal whitespace.
|
|
581
|
+
* **`truncate(text, maxLength, suffix)`**: Truncates a string to a specified maximum length and appends a suffix if truncated.
|
|
582
|
+
* **`escapeHtml(text)`**: Escapes HTML characters in a string to prevent them from being interpreted as HTML.
|
|
583
|
+
* **`stripHtml(text)`**: Removes HTML tags from a string.
|
|
584
|
+
* **`isValidEmail(email)`**: Performs a basic check to see if a string looks like a valid email address.
|
|
585
|
+
|
|
586
|
+
#### Timestamp Utilities
|
|
587
|
+
|
|
588
|
+
* **`formatTimestamp(timestamp)`**: Formats a timestamp in a human-readable format.
|
|
589
|
+
|
|
590
|
+
#### Version Utilities
|
|
591
|
+
|
|
592
|
+
* **`isValidVersion(version)`**: Validates version string format (X.Y.Z).
|
|
593
|
+
* **`incrementVersion(version, type)`**: Increments a semantic version string.
|
|
594
|
+
|
|
357
595
|
## Usage
|
|
358
596
|
|
|
359
597
|
To use the GitSense Chat Utils library in your project, you can import the main interface class or individual modules/functions as needed.
|
|
@@ -376,6 +614,15 @@ const { text: fixedText, modified } = utils.fixTextCodeBlocks(markdownText);
|
|
|
376
614
|
|
|
377
615
|
// Example: Check if a code block is a patch
|
|
378
616
|
const isPatch = utils.isPatchBlock(codeBlockContentString);
|
|
617
|
+
|
|
618
|
+
// Example: Extract meta-raw-result mappings
|
|
619
|
+
const mappings = utils.extractMetaRawResultMappings(chat, message.model);
|
|
620
|
+
|
|
621
|
+
// Example: Parse a reference message
|
|
622
|
+
if (utils.isReferenceMessage(message)) {
|
|
623
|
+
const data = utils.extractReferenceMessageData(message);
|
|
624
|
+
console.log(`Original Chat UUID: ${data.originalChatUuid}`);
|
|
625
|
+
}
|
|
379
626
|
```
|
|
380
627
|
|
|
381
628
|
### Individual Modules
|
|
@@ -394,7 +641,17 @@ const { JsonUtils } = require('@gitsense/gsc-utils');
|
|
|
394
641
|
const { GSToolBlockUtils } = require('@gitsense/gsc-utils');
|
|
395
642
|
const { ContextUtils } = require('@gitsense/gsc-utils');
|
|
396
643
|
const { AnalysisBlockUtils } = require('@gitsense/gsc-utils');
|
|
644
|
+
const { SharedUtils } = require('@gitsense/gsc-utils');
|
|
645
|
+
const { SVGUtils } = require('@gitsense/gsc-utils');
|
|
646
|
+
const { ObjectUtils } = require('@gitsense/gsc-utils');
|
|
647
|
+
const { LanguageNameUtils } = require('@gitsense/gsc-utils');
|
|
648
|
+
const { DomUtils } = require('@gitsense/gsc-utils');
|
|
649
|
+
const { DateUtils } = require('@gitsense/gsc-utils');
|
|
397
650
|
const { ChatUtils } = require('@gitsense/gsc-utils');
|
|
651
|
+
const { MarkdownUtils } = require('@gitsense/gsc-utils');
|
|
652
|
+
const { FormatterUtils } = require('@gitsense/gsc-utils');
|
|
653
|
+
const { MetaRawResultUtils } = require('@gitsense/gsc-utils');
|
|
654
|
+
const { CompactChatUtils } = require('@gitsense/gsc-utils');
|
|
398
655
|
|
|
399
656
|
// Example: Using CodeBlockUtils directly
|
|
400
657
|
const { blocks, warnings } = CodeBlockUtils.extractCodeBlocks(markdownText);
|
|
@@ -407,6 +664,31 @@ const analyzers = AnalyzerUtils.getAnalyzers('/path/to/analyzers');
|
|
|
407
664
|
|
|
408
665
|
// Example: Using MessageUtils directly
|
|
409
666
|
const messages = MessageUtils.getChatTemplateMessages('/path/to/messages', 'draft');
|
|
667
|
+
|
|
668
|
+
// Example: Using SharedUtils directly
|
|
669
|
+
const camelCaseText = SharedUtils.camelCase('hello world text');
|
|
670
|
+
|
|
671
|
+
// Example: Using SVGUtils directly
|
|
672
|
+
const svgIcon = SVGUtils.aiModel({ width: 24, height: 24 });
|
|
673
|
+
|
|
674
|
+
// Example: Using DateUtils directly
|
|
675
|
+
const ageString = DateUtils.formatAge('2025-10-31T12:00:00.000Z');
|
|
676
|
+
|
|
677
|
+
// Example: Using MetaRawResultUtils directly
|
|
678
|
+
const mappings = MetaRawResultUtils.extractMetaRawResultMappings(chat, message.model);
|
|
679
|
+
if (mappings.has(chatId)) {
|
|
680
|
+
const fileInfo = mappings.get(chatId);
|
|
681
|
+
console.log(`Valid file: ${fileInfo.fullPath}`);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Example: Using CompactChatUtils directly
|
|
685
|
+
const { ReferenceMessageUtils, CompactedMessageUtils } = CompactChatUtils;
|
|
686
|
+
const referenceData = ReferenceMessageUtils.extractReferenceMessageData(referenceMessage);
|
|
687
|
+
const compactedMessage = CompactedMessageUtils.formatCompactedMessage(
|
|
688
|
+
content,
|
|
689
|
+
originalChatUuid,
|
|
690
|
+
messageRange
|
|
691
|
+
);
|
|
410
692
|
```
|
|
411
693
|
|
|
412
694
|
### Individual Functions
|
|
@@ -421,7 +703,18 @@ const {
|
|
|
421
703
|
getAnalyzers,
|
|
422
704
|
getChatTemplateMessages,
|
|
423
705
|
applyPatchWithDiagnostics,
|
|
424
|
-
estimateTokens
|
|
706
|
+
estimateTokens,
|
|
707
|
+
capitalize,
|
|
708
|
+
isValidVersion,
|
|
709
|
+
formatAge,
|
|
710
|
+
normalizeLanguageName,
|
|
711
|
+
trimObjectStrings,
|
|
712
|
+
extractMetaRawResultMappings,
|
|
713
|
+
isMetaRawResultMessage,
|
|
714
|
+
parseMetaRawResultContent,
|
|
715
|
+
extractReferenceMessageData,
|
|
716
|
+
formatCompactedMessage,
|
|
717
|
+
validateCompactedMessageFormat
|
|
425
718
|
} = require('@gitsense/gsc-utils');
|
|
426
719
|
|
|
427
720
|
// Example: Extract code blocks
|
|
@@ -429,4 +722,29 @@ const { blocks, warnings } = extractCodeBlocks(markdownText);
|
|
|
429
722
|
|
|
430
723
|
// Example: Estimate tokens
|
|
431
724
|
const tokenCount = estimateTokens("Sample text for token estimation.");
|
|
725
|
+
|
|
726
|
+
// Example: Capitalize a string
|
|
727
|
+
const capitalizedText = capitalize("hello world");
|
|
728
|
+
|
|
729
|
+
// Example: Validate a version string
|
|
730
|
+
const isValid = isValidVersion("1.2.3");
|
|
731
|
+
|
|
732
|
+
// Example: Format a date
|
|
733
|
+
const age = formatAge('2025-10-31T12:00:00.000Z');
|
|
734
|
+
|
|
735
|
+
// Example: Normalize a language name
|
|
736
|
+
const langName = normalizeLanguageName('javascript'); // Returns 'JavaScript'
|
|
737
|
+
|
|
738
|
+
// Example: Extract meta-raw-result mappings
|
|
739
|
+
const mappings = extractMetaRawResultMappings(chat, message.model);
|
|
740
|
+
|
|
741
|
+
// Example: Parse a reference message
|
|
742
|
+
const referenceData = extractReferenceMessageData(referenceMessage);
|
|
743
|
+
|
|
744
|
+
// Example: Format a compacted message
|
|
745
|
+
const compactedMessage = formatCompactedMessage(
|
|
746
|
+
content,
|
|
747
|
+
originalChatUuid,
|
|
748
|
+
messageRange
|
|
749
|
+
);
|
|
432
750
|
```
|