@gitsense/gsc-utils 0.2.4 → 0.2.6
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/dist/gsc-utils.cjs.js +559 -32
- package/dist/gsc-utils.esm.js +559 -32
- package/package.json +1 -1
- package/src/AnalyzerUtils/discovery.js +139 -0
- package/src/AnalyzerUtils/index.js +13 -3
- package/src/AnalyzerUtils/instructionLoader.js +58 -0
- package/src/AnalyzerUtils/management.js +131 -0
- package/src/AnalyzerUtils/saver.js +133 -0
- package/src/AnalyzerUtils/schemaLoader.js +163 -0
- package/src/GitSenseChatUtils.js +20 -5
package/dist/gsc-utils.esm.js
CHANGED
|
@@ -16,8 +16,8 @@ function getDefaultExportFromCjs (x) {
|
|
|
16
16
|
* Authors: Claude 3.7 Sonnet (v1.0.0), Gemini 2.5 Pro (v1.1.0), Gemini 2.5 Flash Thinking (v1.2.0)
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
const fs$
|
|
20
|
-
const path = require$$1;
|
|
19
|
+
const fs$6 = require$$0;
|
|
20
|
+
const path$4 = require$$1;
|
|
21
21
|
const ANALYZE_MESSAGE_REGEXP = /^# Analyze - `([^`]+)`\n/;
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -51,12 +51,12 @@ function unescapeCodeBlocks(content) {
|
|
|
51
51
|
* @returns {Array} An array of message objects with role and content properties
|
|
52
52
|
*/
|
|
53
53
|
function getChatTemplateMessages$1(dirname, messageType) {
|
|
54
|
-
const messagesDir = path.join(dirname, messageType);
|
|
54
|
+
const messagesDir = path$4.join(dirname, messageType);
|
|
55
55
|
const messages = [];
|
|
56
56
|
|
|
57
57
|
try {
|
|
58
58
|
// Read all files in the directory
|
|
59
|
-
const files = fs$
|
|
59
|
+
const files = fs$6.readdirSync(messagesDir);
|
|
60
60
|
|
|
61
61
|
// Sort files numerically (1.md, 2.md, etc.)
|
|
62
62
|
const sortedFiles = files.sort((a, b) => {
|
|
@@ -67,9 +67,9 @@ function getChatTemplateMessages$1(dirname, messageType) {
|
|
|
67
67
|
|
|
68
68
|
// Process each file
|
|
69
69
|
for (const file of sortedFiles) {
|
|
70
|
-
if (path.extname(file) === '.md') {
|
|
71
|
-
const filePath = path.join(messagesDir, file);
|
|
72
|
-
const fileContent = fs$
|
|
70
|
+
if (path$4.extname(file) === '.md') {
|
|
71
|
+
const filePath = path$4.join(messagesDir, file);
|
|
72
|
+
const fileContent = fs$6.readFileSync(filePath, 'utf8');
|
|
73
73
|
|
|
74
74
|
// Split by triple newline to separate metadata from content
|
|
75
75
|
const parts = fileContent.split('\n\n\n');
|
|
@@ -10397,7 +10397,7 @@ const { updateCodeBlockByIndex: updateCodeBlockByIndex$1, updateCodeBlockByUUID,
|
|
|
10397
10397
|
const { formatWithLineNumbers: formatWithLineNumbers$1, formatBlockWithLineNumbers: formatBlockWithLineNumbers$1, formatBlocksWithLineNumbers: formatBlocksWithLineNumbers$1, removeLineNumbers: removeLineNumbers$1 } = lineNumberFormatter;
|
|
10398
10398
|
|
|
10399
10399
|
// Export all imported items
|
|
10400
|
-
var CodeBlockUtils$
|
|
10400
|
+
var CodeBlockUtils$4 = {
|
|
10401
10401
|
// Constants
|
|
10402
10402
|
COMMENT_STYLES: COMMENT_STYLES$1,
|
|
10403
10403
|
|
|
@@ -10464,7 +10464,7 @@ var CodeBlockUtils$3 = {
|
|
|
10464
10464
|
* Authors: Gemini 2.5 Flash Thinking (v1.0.0)
|
|
10465
10465
|
*/
|
|
10466
10466
|
|
|
10467
|
-
const CodeBlockUtils$
|
|
10467
|
+
const CodeBlockUtils$3 = CodeBlockUtils$4;
|
|
10468
10468
|
const MessageUtils$2 = MessageUtils$3;
|
|
10469
10469
|
|
|
10470
10470
|
/**
|
|
@@ -10521,7 +10521,7 @@ function parseContextSection(sectionText) {
|
|
|
10521
10521
|
}
|
|
10522
10522
|
});
|
|
10523
10523
|
|
|
10524
|
-
const { blocks, warnings } = CodeBlockUtils$
|
|
10524
|
+
const { blocks, warnings } = CodeBlockUtils$3.extractCodeBlocks(sectionText, { silent: true });
|
|
10525
10525
|
const codeBlocks = blocks.filter(block => block.type === 'code');
|
|
10526
10526
|
|
|
10527
10527
|
if (codeBlocks.length === 0) {
|
|
@@ -10654,7 +10654,7 @@ const ContextUtils$1 = ContextUtils$2;
|
|
|
10654
10654
|
* @param {Array<Object>} allMessages - An array of all message objects in the chat.
|
|
10655
10655
|
* @returns {Map<number, string>} A Map where keys are chat IDs (numbers) and values are file paths (strings).
|
|
10656
10656
|
*/
|
|
10657
|
-
function buildChatIdToPathMap$
|
|
10657
|
+
function buildChatIdToPathMap$2(allMessages) {
|
|
10658
10658
|
const chatIdToPathMap = new Map();
|
|
10659
10659
|
|
|
10660
10660
|
for (const msg of allMessages) {
|
|
@@ -10681,7 +10681,7 @@ function buildChatIdToPathMap$1(allMessages) {
|
|
|
10681
10681
|
}
|
|
10682
10682
|
|
|
10683
10683
|
var contextMapper = {
|
|
10684
|
-
buildChatIdToPathMap: buildChatIdToPathMap$
|
|
10684
|
+
buildChatIdToPathMap: buildChatIdToPathMap$2
|
|
10685
10685
|
};
|
|
10686
10686
|
|
|
10687
10687
|
/*
|
|
@@ -10712,7 +10712,7 @@ var constants = {
|
|
|
10712
10712
|
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
10713
10713
|
*/
|
|
10714
10714
|
|
|
10715
|
-
const CodeBlockUtils$
|
|
10715
|
+
const CodeBlockUtils$2 = CodeBlockUtils$4;
|
|
10716
10716
|
const GSToolBlockUtils$1 = GSToolBlockUtils$3;
|
|
10717
10717
|
const JsonUtils$1 = JsonUtils$2;
|
|
10718
10718
|
const { ANALYZE_HEADER_PREFIX } = constants;
|
|
@@ -10727,9 +10727,9 @@ const { ANALYZE_HEADER_PREFIX } = constants;
|
|
|
10727
10727
|
* @returns {{analysisBlocks: Array<Object>, analysisMetadataBlocks: Array<Object|null>, error: string|null}}
|
|
10728
10728
|
* An object containing the extracted blocks and any processing error.
|
|
10729
10729
|
*/
|
|
10730
|
-
function processLLMAnalysisResponse$
|
|
10730
|
+
function processLLMAnalysisResponse$2(messageContent, stoppedStreaming) {
|
|
10731
10731
|
const silent = { silent: true };
|
|
10732
|
-
const { blocks, warnings } = CodeBlockUtils$
|
|
10732
|
+
const { blocks, warnings } = CodeBlockUtils$2.extractCodeBlocks(messageContent, silent);
|
|
10733
10733
|
|
|
10734
10734
|
const analysisBlocks = [];
|
|
10735
10735
|
const analysisMetadataBlocks = [];
|
|
@@ -10828,7 +10828,7 @@ function processLLMAnalysisResponse$1(messageContent, stoppedStreaming) {
|
|
|
10828
10828
|
}
|
|
10829
10829
|
|
|
10830
10830
|
var responseProcessor = {
|
|
10831
|
-
processLLMAnalysisResponse: processLLMAnalysisResponse$
|
|
10831
|
+
processLLMAnalysisResponse: processLLMAnalysisResponse$2
|
|
10832
10832
|
};
|
|
10833
10833
|
|
|
10834
10834
|
/*
|
|
@@ -10855,7 +10855,7 @@ const AnalysisBlockUtils$1 = AnalysisBlockUtils$3;
|
|
|
10855
10855
|
* @returns {{validAnalysisData: Array<Object>, invalidAnalysisBlocks: Array<string|Object>}}
|
|
10856
10856
|
* An object containing arrays of valid analysis data and invalid analysis blocks.
|
|
10857
10857
|
*/
|
|
10858
|
-
function validateLLMAnalysisData$
|
|
10858
|
+
function validateLLMAnalysisData$2(analysisBlocks, analysisMetadataBlocks, chatIdToPathMap) {
|
|
10859
10859
|
const validAnalysisData = []; // Store data for the "Save All" button
|
|
10860
10860
|
const invalidAnalysisBlocks = []; // Store invalid analysis blocks
|
|
10861
10861
|
|
|
@@ -10909,28 +10909,540 @@ function validateLLMAnalysisData$1(analysisBlocks, analysisMetadataBlocks, chatI
|
|
|
10909
10909
|
}
|
|
10910
10910
|
|
|
10911
10911
|
var dataValidator = {
|
|
10912
|
-
validateLLMAnalysisData: validateLLMAnalysisData$
|
|
10912
|
+
validateLLMAnalysisData: validateLLMAnalysisData$2
|
|
10913
|
+
};
|
|
10914
|
+
|
|
10915
|
+
/*
|
|
10916
|
+
* Component: AnalyzerUtils Discovery
|
|
10917
|
+
* Block-UUID: 0b1c2d3e-4f5a-6b7c-8d9e-0f1a2b3c4d5f
|
|
10918
|
+
* Parent-UUID: N/A
|
|
10919
|
+
* Version: 1.0.0
|
|
10920
|
+
* Description: Provides utility functions for discovering available analyzers.
|
|
10921
|
+
* Language: JavaScript
|
|
10922
|
+
* Created-at: 2025-08-28T23:48:00.000Z
|
|
10923
|
+
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
10924
|
+
*/
|
|
10925
|
+
|
|
10926
|
+
const fs$5 = require$$0.promises;
|
|
10927
|
+
const path$3 = require$$1;
|
|
10928
|
+
|
|
10929
|
+
/**
|
|
10930
|
+
* Reads and parses the config.json file in a directory.
|
|
10931
|
+
* @param {string} dirPath - The path to the directory.
|
|
10932
|
+
* @returns {Promise<object|null>} A promise that resolves to the parsed config object
|
|
10933
|
+
* or null if the file doesn't exist or is invalid.
|
|
10934
|
+
*/
|
|
10935
|
+
async function readConfig$1(dirPath) {
|
|
10936
|
+
const configPath = path$3.join(dirPath, 'config.json');
|
|
10937
|
+
try {
|
|
10938
|
+
const fileContent = await fs$5.readFile(configPath, 'utf8');
|
|
10939
|
+
return JSON.parse(fileContent);
|
|
10940
|
+
} catch (error) {
|
|
10941
|
+
if (error.code !== 'ENOENT') {
|
|
10942
|
+
// Log a warning if config.json exists but is malformed
|
|
10943
|
+
console.warn(`Warning: Failed to parse config.json in ${dirPath}: ${error.message}`);
|
|
10944
|
+
}
|
|
10945
|
+
return null; // Return null if file not found or parsing failed
|
|
10946
|
+
}
|
|
10947
|
+
}
|
|
10948
|
+
|
|
10949
|
+
/**
|
|
10950
|
+
* Checks if a directory name is valid based on the rules in messages/analyze/README.md.
|
|
10951
|
+
* Allowed: a-z, A-Z, 0-9, dash (-), underscore (_). Cannot start with underscore or contain dots.
|
|
10952
|
+
* @param {string} name - The directory name to check.
|
|
10953
|
+
* @returns {boolean} True if the name is valid, false otherwise.
|
|
10954
|
+
*/
|
|
10955
|
+
function isValidDirName(name) {
|
|
10956
|
+
// Exclude names starting with underscore or containing dots
|
|
10957
|
+
if (name.startsWith('_') || name.includes('.')) {
|
|
10958
|
+
return false;
|
|
10959
|
+
}
|
|
10960
|
+
// Check for allowed characters
|
|
10961
|
+
return /^[a-zA-Z0-9_-]+$/.test(name);
|
|
10962
|
+
}
|
|
10963
|
+
|
|
10964
|
+
/**
|
|
10965
|
+
* Discovers and lists all available analyzers by traversing the directory structure.
|
|
10966
|
+
* An analyzer is considered valid if a '1.md' file exists in the instructions directory.
|
|
10967
|
+
*
|
|
10968
|
+
* @param {string} analyzeMessagesBasePath - The absolute or relative path to the base directory containing the analyzer message files (e.g., 'messages/analyze').
|
|
10969
|
+
* @returns {Promise<Array<{id: string, label: string}>>} A promise that resolves to an array of analyzer objects.
|
|
10970
|
+
*/
|
|
10971
|
+
async function getAnalyzers$2(analyzeMessagesBasePath) {
|
|
10972
|
+
const analyzers = [];
|
|
10973
|
+
|
|
10974
|
+
try {
|
|
10975
|
+
const analyzerEntries = await fs$5.readdir(analyzeMessagesBasePath, { withFileTypes: true });
|
|
10976
|
+
|
|
10977
|
+
for (const analyzerEntry of analyzerEntries) {
|
|
10978
|
+
if (analyzerEntry.isDirectory() && isValidDirName(analyzerEntry.name)) {
|
|
10979
|
+
const analyzerName = analyzerEntry.name;
|
|
10980
|
+
const analyzerPath = path$3.join(analyzeMessagesBasePath, analyzerName);
|
|
10981
|
+
const analyzerConfig = await readConfig$1(analyzerPath);
|
|
10982
|
+
const analyzerLabel = analyzerConfig?.label || analyzerName;
|
|
10983
|
+
|
|
10984
|
+
const contentEntries = await fs$5.readdir(analyzerPath, { withFileTypes: true });
|
|
10985
|
+
|
|
10986
|
+
for (const contentEntry of contentEntries) {
|
|
10987
|
+
if (contentEntry.isDirectory() && isValidDirName(contentEntry.name)) {
|
|
10988
|
+
const contentType = contentEntry.name;
|
|
10989
|
+
const contentPath = path$3.join(analyzerPath, contentType);
|
|
10990
|
+
const contentConfig = await readConfig$1(contentPath);
|
|
10991
|
+
const contentLabel = contentConfig?.label || contentType;
|
|
10992
|
+
|
|
10993
|
+
const instructionsEntries = await fs$5.readdir(contentPath, { withFileTypes: true });
|
|
10994
|
+
|
|
10995
|
+
for (const instructionsEntry of instructionsEntries) {
|
|
10996
|
+
if (instructionsEntry.isDirectory() && isValidDirName(instructionsEntry.name)) {
|
|
10997
|
+
const instructionsType = instructionsEntry.name;
|
|
10998
|
+
const instructionsPath = path$3.join(contentPath, instructionsType);
|
|
10999
|
+
const instructionsConfig = await readConfig$1(instructionsPath);
|
|
11000
|
+
const instructionsLabel = instructionsConfig?.label || instructionsType;
|
|
11001
|
+
|
|
11002
|
+
// Check for the existence of 1.md to confirm a valid analyzer configuration
|
|
11003
|
+
const instructionsFilePath = path$3.join(instructionsPath, '1.md');
|
|
11004
|
+
try {
|
|
11005
|
+
await fs$5.access(instructionsFilePath); // Check if file exists and is accessible
|
|
11006
|
+
|
|
11007
|
+
// If analyzerName starts with 'tutorial-', check its last modified time.
|
|
11008
|
+
if (analyzerName.startsWith('tutorial-')) {
|
|
11009
|
+
const stats = await fs$5.stat(instructionsFilePath);
|
|
11010
|
+
const lastModified = stats.mtime.getTime(); // Get timestamp in milliseconds
|
|
11011
|
+
const sixtyMinutesAgo = Date.now() - (60 * 60 * 1000); // Current time - 60 minutes in ms
|
|
11012
|
+
|
|
11013
|
+
if (lastModified < sixtyMinutesAgo) {
|
|
11014
|
+
// This tutorial analyzer has expired, skip it.
|
|
11015
|
+
continue;
|
|
11016
|
+
}
|
|
11017
|
+
}
|
|
11018
|
+
// Construct the analyzer ID and label
|
|
11019
|
+
const analyzerId = `${analyzerName}::${contentType}::${instructionsType}`;
|
|
11020
|
+
const analyzerFullLabel = `${analyzerLabel} (${contentLabel} - ${instructionsLabel})`;
|
|
11021
|
+
|
|
11022
|
+
analyzers.push({
|
|
11023
|
+
id: analyzerId,
|
|
11024
|
+
label: analyzerFullLabel,
|
|
11025
|
+
protected: analyzerConfig?.protected || false
|
|
11026
|
+
});
|
|
11027
|
+
} catch (error) {
|
|
11028
|
+
// If 1.md doesn't exist, this is not a complete analyzer configuration, skip.
|
|
11029
|
+
if (error.code !== 'ENOENT') {
|
|
11030
|
+
console.warn(`Warning: Error accessing 1.md for ${analyzerId}: ${error.message}`);
|
|
11031
|
+
}
|
|
11032
|
+
}
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
}
|
|
11036
|
+
}
|
|
11037
|
+
}
|
|
11038
|
+
}
|
|
11039
|
+
} catch (error) {
|
|
11040
|
+
console.error(`Error traversing analyze messages directory ${analyzeMessagesBasePath}: ${error.message}`);
|
|
11041
|
+
// Depending on requirements, you might want to throw the error or return an empty array
|
|
11042
|
+
throw error; // Re-throw to indicate failure
|
|
11043
|
+
}
|
|
11044
|
+
|
|
11045
|
+
return analyzers;
|
|
11046
|
+
}
|
|
11047
|
+
|
|
11048
|
+
var discovery = {
|
|
11049
|
+
getAnalyzers: getAnalyzers$2,
|
|
11050
|
+
readConfig: readConfig$1};
|
|
11051
|
+
|
|
11052
|
+
/**
|
|
11053
|
+
* Component: Analyzer Saver Utility
|
|
11054
|
+
* Block-UUID: a373f4ba-89ce-465f-8624-24258c923e61
|
|
11055
|
+
* Parent-UUID: N/A
|
|
11056
|
+
* Version: 1.1.0
|
|
11057
|
+
* Description: Utility function to save or update an analyzer configuration based on its ID and content.
|
|
11058
|
+
* Language: JavaScript
|
|
11059
|
+
* Created-at: 2025-07-12T04:12:33.454Z
|
|
11060
|
+
* Authors: Gemini 2.5 Flash Thinking (v1.0.0), Gemini 2.5 Flash Thinking (v1.1.0)
|
|
11061
|
+
*/
|
|
11062
|
+
|
|
11063
|
+
require$$0.promises;
|
|
11064
|
+
|
|
11065
|
+
|
|
11066
|
+
var saver = {
|
|
11067
|
+
};
|
|
11068
|
+
|
|
11069
|
+
/*
|
|
11070
|
+
* Component: AnalyzerUtils Schema Loader
|
|
11071
|
+
* Block-UUID: 0c1d2e3f-4a5b-6c7d-8e9f-0a1b2c3d4e5f
|
|
11072
|
+
* Parent-UUID: N/A
|
|
11073
|
+
* Version: 1.0.0
|
|
11074
|
+
* Description: Provides utility functions for retrieving and deducing JSON schemas for analyzers.
|
|
11075
|
+
* Language: JavaScript
|
|
11076
|
+
* Created-at: 2025-08-28T23:48:00.000Z
|
|
11077
|
+
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
11078
|
+
*/
|
|
11079
|
+
|
|
11080
|
+
const fs$4 = require$$0.promises;
|
|
11081
|
+
const path$2 = require$$1;
|
|
11082
|
+
const CodeBlockUtils$1 = CodeBlockUtils$4;
|
|
11083
|
+
|
|
11084
|
+
/**
|
|
11085
|
+
* Deduces the JSON schema type and format/items from a string value pattern.
|
|
11086
|
+
* Handles patterns like "[string: ...]", "[number: ...]", "[datetime: ...]", "[<string>: ...]",
|
|
11087
|
+
* and boolean instructions. Defaults to 'string' for unknown patterns.
|
|
11088
|
+
*
|
|
11089
|
+
* @param {any} value - The value from the raw JSON (expected to be a string pattern).
|
|
11090
|
+
* @param {string} fieldName - The name of the field (for logging warnings).
|
|
11091
|
+
* @returns {{type: string, format?: string, items?: object}} An object describing the schema type and format/items.
|
|
11092
|
+
*/
|
|
11093
|
+
function deduceSchemaType(value, fieldName) {
|
|
11094
|
+
const defaultSchema = { type: 'string' }; // Default fallback
|
|
11095
|
+
|
|
11096
|
+
if (typeof value !== 'string') {
|
|
11097
|
+
const jsType = typeof value;
|
|
11098
|
+
if (jsType === 'object' && value !== null) {
|
|
11099
|
+
console.warn(`Warning: Unexpected non-string, non-null object/array value for field "${fieldName}". Defaulting to type 'string'. Value:`, value);
|
|
11100
|
+
return defaultSchema;
|
|
11101
|
+
}
|
|
11102
|
+
return { type: jsType };
|
|
11103
|
+
}
|
|
11104
|
+
|
|
11105
|
+
const trimmedValue = value.trim();
|
|
11106
|
+
|
|
11107
|
+
if (/^\[string:.*\]$/.test(trimmedValue) || (/^\[[^:]+\]$/.test(trimmedValue) && !/^\[(number|datetime|date|<string>):.*\]$/.test(trimmedValue))) {
|
|
11108
|
+
return { type: 'string' };
|
|
11109
|
+
}
|
|
11110
|
+
|
|
11111
|
+
if (/^\[number:.*\]$/.test(trimmedValue)) {
|
|
11112
|
+
return { type: 'number' };
|
|
11113
|
+
}
|
|
11114
|
+
|
|
11115
|
+
if (/^\[boolean:.*\]$/.test(trimmedValue)) {
|
|
11116
|
+
return { type: 'boolean' };
|
|
11117
|
+
}
|
|
11118
|
+
|
|
11119
|
+
if (/^\[date-*time:.*\]$/.test(trimmedValue)) {
|
|
11120
|
+
return { type: 'string', format: 'date-time' };
|
|
11121
|
+
}
|
|
11122
|
+
|
|
11123
|
+
if (/^\[date:.*\]$/.test(trimmedValue)) {
|
|
11124
|
+
return { type: 'string', format: 'date' };
|
|
11125
|
+
}
|
|
11126
|
+
|
|
11127
|
+
if (/^\[<string>:.*\]$/.test(trimmedValue) || trimmedValue.toLowerCase().includes('array of strings')) {
|
|
11128
|
+
return { type: 'array', items: { type: 'string' } };
|
|
11129
|
+
}
|
|
11130
|
+
|
|
11131
|
+
if (trimmedValue.toLowerCase().includes("output 'true' or 'false'") || trimmedValue.toLowerCase().includes("determine if") && (trimmedValue.toLowerCase().includes("true") || trimmedValue.toLowerCase().includes("false"))) {
|
|
11132
|
+
return { type: 'boolean' };
|
|
11133
|
+
}
|
|
11134
|
+
|
|
11135
|
+
console.warn(`Warning: Unknown metadata value pattern for field "${fieldName}". Defaulting to type 'string'. Value: "${value}"`);
|
|
11136
|
+
return defaultSchema;
|
|
11137
|
+
}
|
|
11138
|
+
|
|
11139
|
+
|
|
11140
|
+
/**
|
|
11141
|
+
* Retrieves the JSON schema for a specific analyzer.
|
|
11142
|
+
* Reads the corresponding '1.md' file, extracts the JSON block,
|
|
11143
|
+
* and deduces schema types from the string values.
|
|
11144
|
+
*
|
|
11145
|
+
* @param {string} analyzeMessagesBasePath - The absolute or relative path to the base directory containing the analyzer message files (e.g., 'messages/analyze').
|
|
11146
|
+
* @param {string} analyzerId - The unique ID of the analyzer (format: 'analyzer_name::content_type::instructions_type').
|
|
11147
|
+
* @returns {Promise<object|null>} A promise that resolves with the JSON schema object or null if the analyzer ID is invalid or the schema cannot be retrieved/parsed.
|
|
11148
|
+
* @throws {Error} If the 1.md file is found but does not contain exactly one JSON code block.
|
|
11149
|
+
*/
|
|
11150
|
+
async function getAnalyzerSchema$2(analyzeMessagesBasePath, analyzerId) {
|
|
11151
|
+
if (typeof analyzeMessagesBasePath !== 'string' || analyzeMessagesBasePath.trim() === '') {
|
|
11152
|
+
console.error('Error: analyzeMessagesBasePath is required.');
|
|
11153
|
+
return null;
|
|
11154
|
+
}
|
|
11155
|
+
if (typeof analyzerId !== 'string' || analyzerId.trim() === '') {
|
|
11156
|
+
console.error('Error: analyzerId is required.');
|
|
11157
|
+
return null;
|
|
11158
|
+
}
|
|
11159
|
+
|
|
11160
|
+
const parts = analyzerId.split('::');
|
|
11161
|
+
if (parts.length !== 3) {
|
|
11162
|
+
console.error(`Error: Invalid analyzerId format. Expected 'analyzer_name::content_type::instructions_type', but got '${analyzerId}'.`);
|
|
11163
|
+
return null;
|
|
11164
|
+
}
|
|
11165
|
+
const [analyzerName, contentType, instructionsType] = parts;
|
|
11166
|
+
|
|
11167
|
+
const instructionsFilePath = path$2.join(analyzeMessagesBasePath, analyzerName, contentType, instructionsType, '1.md');
|
|
11168
|
+
|
|
11169
|
+
try {
|
|
11170
|
+
const fileContent = await fs$4.readFile(instructionsFilePath, 'utf8');
|
|
11171
|
+
const { blocks } = CodeBlockUtils$1.extractCodeBlocks(fileContent, { silent: true });
|
|
11172
|
+
const jsonBlocks = blocks.filter(block => block.type === 'code' && block.language === 'json');
|
|
11173
|
+
|
|
11174
|
+
if (jsonBlocks.length !== 1) {
|
|
11175
|
+
throw new Error(`Expected exactly one JSON code block in ${instructionsFilePath}, but found ${jsonBlocks.length}.`);
|
|
11176
|
+
}
|
|
11177
|
+
|
|
11178
|
+
const jsonBlockContent = jsonBlocks[0].content;
|
|
11179
|
+
let rawJson = null;
|
|
11180
|
+
try {
|
|
11181
|
+
rawJson = JSON.parse(jsonBlockContent);
|
|
11182
|
+
} catch (parseError) {
|
|
11183
|
+
console.error(`Error parsing JSON content from ${instructionsFilePath}: ${parseError.message}`);
|
|
11184
|
+
return null;
|
|
11185
|
+
}
|
|
11186
|
+
|
|
11187
|
+
const schema = {
|
|
11188
|
+
type: 'object',
|
|
11189
|
+
description: rawJson.description,
|
|
11190
|
+
properties: {},
|
|
11191
|
+
required: []
|
|
11192
|
+
};
|
|
11193
|
+
|
|
11194
|
+
const metadataProperties = rawJson?.extracted_metadata;
|
|
11195
|
+
|
|
11196
|
+
if (metadataProperties && typeof metadataProperties === 'object') {
|
|
11197
|
+
for (const fieldName in metadataProperties) {
|
|
11198
|
+
if (Object.hasOwnProperty.call(metadataProperties, fieldName)) {
|
|
11199
|
+
const rawValue = metadataProperties[fieldName];
|
|
11200
|
+
const fieldSchema = deduceSchemaType(rawValue, fieldName);
|
|
11201
|
+
const description = rawValue.match(/^\[\w+: ([^\]]+)\]/)?.[1] || '';
|
|
11202
|
+
|
|
11203
|
+
schema.properties[fieldName] = {
|
|
11204
|
+
...fieldSchema,
|
|
11205
|
+
description,
|
|
11206
|
+
title: fieldName.replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase())
|
|
11207
|
+
};
|
|
11208
|
+
}
|
|
11209
|
+
}
|
|
11210
|
+
} else {
|
|
11211
|
+
console.warn(`Warning: Could not find 'extracted_metadata' object in JSON block from ${instructionsFilePath}. Schema will be empty.`);
|
|
11212
|
+
}
|
|
11213
|
+
|
|
11214
|
+
return schema;
|
|
11215
|
+
|
|
11216
|
+
} catch (error) {
|
|
11217
|
+
if (error.code === 'ENOENT') {
|
|
11218
|
+
console.warn(`Analyzer instructions file not found: ${instructionsFilePath}`);
|
|
11219
|
+
return null;
|
|
11220
|
+
} else {
|
|
11221
|
+
console.error(`Error retrieving or processing schema for analyzer ${analyzerId}: ${error.message}`);
|
|
11222
|
+
throw error;
|
|
11223
|
+
}
|
|
11224
|
+
}
|
|
11225
|
+
}
|
|
11226
|
+
|
|
11227
|
+
var schemaLoader = {
|
|
11228
|
+
getAnalyzerSchema: getAnalyzerSchema$2};
|
|
11229
|
+
|
|
11230
|
+
/*
|
|
11231
|
+
* Component: AnalyzerUtils Management
|
|
11232
|
+
* Block-UUID: 0d1e2f3a-4b5c-6d7e-8f9a-0b1c2d3e4f5a
|
|
11233
|
+
* Parent-UUID: N/A
|
|
11234
|
+
* Version: 1.0.0
|
|
11235
|
+
* Description: Provides utility functions for managing (deleting) analyzer configurations.
|
|
11236
|
+
* Language: JavaScript
|
|
11237
|
+
* Created-at: 2025-08-28T23:48:00.000Z
|
|
11238
|
+
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
11239
|
+
*/
|
|
11240
|
+
|
|
11241
|
+
const fs$3 = require$$0.promises;
|
|
11242
|
+
const path$1 = require$$1;
|
|
11243
|
+
const { readConfig } = discovery; // Import helper from discovery
|
|
11244
|
+
|
|
11245
|
+
/**
|
|
11246
|
+
* Checks if a directory is empty or only contains a config.json.
|
|
11247
|
+
* @param {string} dirPath - The path to the directory.
|
|
11248
|
+
* @returns {Promise<boolean>} True if the directory is empty or only contains config.json, false otherwise.
|
|
11249
|
+
*/
|
|
11250
|
+
async function isDirectoryEmpty(dirPath) {
|
|
11251
|
+
try {
|
|
11252
|
+
const files = await fs$3.readdir(dirPath);
|
|
11253
|
+
return files.length === 0 || (files.length === 1 && files[0] === 'config.json');
|
|
11254
|
+
} catch (error) {
|
|
11255
|
+
if (error.code === 'ENOENT') {
|
|
11256
|
+
return true; // Directory doesn't exist, so it's "empty" for our purpose
|
|
11257
|
+
}
|
|
11258
|
+
throw error; // Re-throw other errors
|
|
11259
|
+
}
|
|
11260
|
+
}
|
|
11261
|
+
|
|
11262
|
+
/**
|
|
11263
|
+
* Deletes a specific analyzer configuration and intelligently cleans up empty directories.
|
|
11264
|
+
*
|
|
11265
|
+
* @param {string} analyzeMessagesBasePath - The absolute or relative path to the base directory containing the analyzer message files (e.g., 'messages/analyze').
|
|
11266
|
+
* @param {string} analyzerId - The unique ID of the analyzer to delete (format: 'analyzer_name::content_type::instructions_type').
|
|
11267
|
+
* @returns {Promise<{success: boolean, message: string}>} A promise that resolves with a result object indicating success or failure.
|
|
11268
|
+
*/
|
|
11269
|
+
async function deleteAnalyzer$2(analyzeMessagesBasePath, analyzerId) {
|
|
11270
|
+
if (typeof analyzeMessagesBasePath !== 'string' || analyzeMessagesBasePath.trim() === '') {
|
|
11271
|
+
return { success: false, message: 'analyzeMessagesBasePath is required.' };
|
|
11272
|
+
}
|
|
11273
|
+
if (typeof analyzerId !== 'string' || analyzerId.trim() === '') {
|
|
11274
|
+
return { success: false, message: 'analyzerId is required.' };
|
|
11275
|
+
}
|
|
11276
|
+
|
|
11277
|
+
const parts = analyzerId.split('::');
|
|
11278
|
+
if (parts.length !== 3) {
|
|
11279
|
+
return { success: false, message: `Invalid analyzerId format. Expected 'analyzer_name::content_type::instructions_type', but got '${analyzerId}'.` };
|
|
11280
|
+
}
|
|
11281
|
+
const [analyzerName, contentType, instructionsType] = parts;
|
|
11282
|
+
|
|
11283
|
+
const analyzerDir = path$1.join(analyzeMessagesBasePath, analyzerName);
|
|
11284
|
+
const contentDir = path$1.join(analyzerDir, contentType);
|
|
11285
|
+
const instructionsDir = path$1.join(contentDir, instructionsType);
|
|
11286
|
+
const instructionsFilePath = path$1.join(instructionsDir, '1.md');
|
|
11287
|
+
|
|
11288
|
+
try {
|
|
11289
|
+
// 1. Check for protection at all levels
|
|
11290
|
+
const analyzerConfig = await readConfig(analyzerDir);
|
|
11291
|
+
if (analyzerConfig?.protected) {
|
|
11292
|
+
return { success: false, message: `Analyzer '${analyzerName}' is protected and cannot be deleted.` };
|
|
11293
|
+
}
|
|
11294
|
+
|
|
11295
|
+
const contentConfig = await readConfig(contentDir);
|
|
11296
|
+
if (contentConfig?.protected) {
|
|
11297
|
+
return { success: false, message: `Content type '${contentType}' for analyzer '${analyzerName}' is protected and cannot be deleted.` };
|
|
11298
|
+
}
|
|
11299
|
+
|
|
11300
|
+
const instructionsConfig = await readConfig(instructionsDir);
|
|
11301
|
+
if (instructionsConfig?.protected) {
|
|
11302
|
+
return { success: false, message: `Instructions type '${instructionsType}' for content type '${contentType}' is protected and cannot be deleted.` };
|
|
11303
|
+
}
|
|
11304
|
+
|
|
11305
|
+
// 2. Delete the 1.md file
|
|
11306
|
+
try {
|
|
11307
|
+
await fs$3.unlink(instructionsFilePath);
|
|
11308
|
+
} catch (error) {
|
|
11309
|
+
if (error.code === 'ENOENT') {
|
|
11310
|
+
return { success: false, message: `Analyzer instructions file not found: ${instructionsFilePath}. It may have already been deleted.` };
|
|
11311
|
+
}
|
|
11312
|
+
throw error; // Re-throw other errors
|
|
11313
|
+
}
|
|
11314
|
+
|
|
11315
|
+
// 3. Intelligently delete empty directories, cascading upwards
|
|
11316
|
+
let deletedDirs = [];
|
|
11317
|
+
|
|
11318
|
+
// Check and delete instructions directory
|
|
11319
|
+
if (await isDirectoryEmpty(instructionsDir)) {
|
|
11320
|
+
try {
|
|
11321
|
+
await fs$3.rmdir(instructionsDir);
|
|
11322
|
+
deletedDirs.push(instructionsDir);
|
|
11323
|
+
} catch (error) {
|
|
11324
|
+
console.warn(`Warning: Could not remove empty instructions directory ${instructionsDir}: ${error.message}`);
|
|
11325
|
+
}
|
|
11326
|
+
}
|
|
11327
|
+
|
|
11328
|
+
// Check and delete content directory
|
|
11329
|
+
if (await isDirectoryEmpty(contentDir)) {
|
|
11330
|
+
try {
|
|
11331
|
+
await fs$3.rmdir(contentDir);
|
|
11332
|
+
deletedDirs.push(contentDir);
|
|
11333
|
+
} catch (error) {
|
|
11334
|
+
console.warn(`Warning: Could not remove empty content directory ${contentDir}: ${error.message}`);
|
|
11335
|
+
}
|
|
11336
|
+
}
|
|
11337
|
+
|
|
11338
|
+
// Check and delete analyzer directory
|
|
11339
|
+
if (await isDirectoryEmpty(analyzerDir)) {
|
|
11340
|
+
try {
|
|
11341
|
+
await fs$3.rmdir(analyzerDir);
|
|
11342
|
+
deletedDirs.push(analyzerDir);
|
|
11343
|
+
} catch (error) {
|
|
11344
|
+
console.warn(`Warning: Could not remove empty analyzer directory ${analyzerDir}: ${error.message}`);
|
|
11345
|
+
}
|
|
11346
|
+
}
|
|
11347
|
+
|
|
11348
|
+
return { success: true, message: `Analyzer '${analyzerId}' deleted successfully. Cleaned up directories: ${deletedDirs.join(', ') || 'None'}.` };
|
|
11349
|
+
|
|
11350
|
+
} catch (error) {
|
|
11351
|
+
console.error(`Error deleting analyzer '${analyzerId}': ${error.message}`);
|
|
11352
|
+
return { success: false, message: `Failed to delete analyzer: ${error.message}` };
|
|
11353
|
+
}
|
|
11354
|
+
}
|
|
11355
|
+
|
|
11356
|
+
var management = {
|
|
11357
|
+
deleteAnalyzer: deleteAnalyzer$2};
|
|
11358
|
+
|
|
11359
|
+
/*
|
|
11360
|
+
* Component: AnalyzerUtils Instruction Loader
|
|
11361
|
+
* Block-UUID: 0a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5e
|
|
11362
|
+
* Parent-UUID: N/A
|
|
11363
|
+
* Version: 1.0.0
|
|
11364
|
+
* Description: Provides utility functions for loading raw analyzer instruction content.
|
|
11365
|
+
* Language: JavaScript
|
|
11366
|
+
* Created-at: 2025-08-28T23:48:00.000Z
|
|
11367
|
+
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
11368
|
+
*/
|
|
11369
|
+
|
|
11370
|
+
const fs$2 = require$$0.promises;
|
|
11371
|
+
const path = require$$1;
|
|
11372
|
+
|
|
11373
|
+
/**
|
|
11374
|
+
* Retrieves the raw Markdown content of the analyzer's '1.md' instruction file.
|
|
11375
|
+
*
|
|
11376
|
+
* @param {string} analyzeMessagesBasePath - The absolute path to the base directory containing the analyzer message files (e.g., 'messages/analyze').
|
|
11377
|
+
* @param {string} analyzerId - The unique ID of the analyzer (format: 'analyzer_name::content_type::instructions_type').
|
|
11378
|
+
* @returns {Promise<string|null>} A promise that resolves with the full Markdown content of the '1.md' file, or null if not found/invalid.
|
|
11379
|
+
*/
|
|
11380
|
+
async function getAnalyzerInstructionsContent$2(analyzeMessagesBasePath, analyzerId) {
|
|
11381
|
+
if (typeof analyzeMessagesBasePath !== 'string' || analyzeMessagesBasePath.trim() === '') {
|
|
11382
|
+
console.error('Error: analyzeMessagesBasePath is required.');
|
|
11383
|
+
return null;
|
|
11384
|
+
}
|
|
11385
|
+
if (typeof analyzerId !== 'string' || analyzerId.trim() === '') {
|
|
11386
|
+
console.error('Error: analyzerId is required.');
|
|
11387
|
+
return null;
|
|
11388
|
+
}
|
|
11389
|
+
|
|
11390
|
+
const parts = analyzerId.split('::');
|
|
11391
|
+
if (parts.length !== 3) {
|
|
11392
|
+
console.error(`Error: Invalid analyzerId format. Expected 'analyzer_name::content_type::instructions_type', but got '${analyzerId}'.`);
|
|
11393
|
+
return null;
|
|
11394
|
+
}
|
|
11395
|
+
const [analyzerName, contentType, instructionsType] = parts;
|
|
11396
|
+
|
|
11397
|
+
const instructionsFilePath = path.join(analyzeMessagesBasePath, analyzerName, contentType, instructionsType, '1.md');
|
|
11398
|
+
|
|
11399
|
+
try {
|
|
11400
|
+
const fileContent = await fs$2.readFile(instructionsFilePath, 'utf8');
|
|
11401
|
+
return fileContent;
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
if (error.code === 'ENOENT') {
|
|
11404
|
+
console.warn(`Analyzer instructions file not found: ${instructionsFilePath}`);
|
|
11405
|
+
return null;
|
|
11406
|
+
} else {
|
|
11407
|
+
console.error(`Error reading analyzer instructions file ${instructionsFilePath}: ${error.message}`);
|
|
11408
|
+
throw error;
|
|
11409
|
+
}
|
|
11410
|
+
}
|
|
11411
|
+
}
|
|
11412
|
+
|
|
11413
|
+
var instructionLoader = {
|
|
11414
|
+
getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$2
|
|
10913
11415
|
};
|
|
10914
11416
|
|
|
10915
11417
|
/*
|
|
10916
11418
|
* Component: AnalyzerUtils Index
|
|
10917
11419
|
* Block-UUID: b403b6a1-230b-4247-8cd6-2a3d068f4bbf
|
|
10918
11420
|
* Parent-UUID: N/A
|
|
10919
|
-
* Version: 1.
|
|
11421
|
+
* Version: 1.1.0
|
|
10920
11422
|
* Description: Aggregates and exports all utility functions from the AnalyzerUtils module.
|
|
10921
11423
|
* Language: JavaScript
|
|
10922
11424
|
* Created-at: 2025-08-28T15:56:40.319Z
|
|
10923
|
-
* Authors: Gemini 2.5 Flash (v1.0.0)
|
|
11425
|
+
* Authors: Gemini 2.5 Flash (v1.0.0), Gemini 2.5 Flash (v1.1.0)
|
|
10924
11426
|
*/
|
|
10925
11427
|
|
|
10926
|
-
const { buildChatIdToPathMap } = contextMapper;
|
|
10927
|
-
const { processLLMAnalysisResponse } = responseProcessor;
|
|
10928
|
-
const { validateLLMAnalysisData } = dataValidator;
|
|
11428
|
+
const { buildChatIdToPathMap: buildChatIdToPathMap$1 } = contextMapper;
|
|
11429
|
+
const { processLLMAnalysisResponse: processLLMAnalysisResponse$1 } = responseProcessor;
|
|
11430
|
+
const { validateLLMAnalysisData: validateLLMAnalysisData$1 } = dataValidator;
|
|
11431
|
+
const { getAnalyzers: getAnalyzers$1 } = discovery;
|
|
11432
|
+
const { saveConfiguration } = saver;
|
|
11433
|
+
const { getAnalyzerSchema: getAnalyzerSchema$1 } = schemaLoader;
|
|
11434
|
+
const { deleteAnalyzer: deleteAnalyzer$1 } = management;
|
|
11435
|
+
const { getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1 } = instructionLoader;
|
|
10929
11436
|
|
|
10930
11437
|
var AnalyzerUtils$1 = {
|
|
10931
|
-
buildChatIdToPathMap,
|
|
10932
|
-
processLLMAnalysisResponse,
|
|
10933
|
-
validateLLMAnalysisData
|
|
11438
|
+
buildChatIdToPathMap: buildChatIdToPathMap$1,
|
|
11439
|
+
processLLMAnalysisResponse: processLLMAnalysisResponse$1,
|
|
11440
|
+
validateLLMAnalysisData: validateLLMAnalysisData$1,
|
|
11441
|
+
getAnalyzers: getAnalyzers$1,
|
|
11442
|
+
getAnalyzerSchema: getAnalyzerSchema$1,
|
|
11443
|
+
deleteAnalyzer: deleteAnalyzer$1,
|
|
11444
|
+
getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1,
|
|
11445
|
+
saveConfiguration,
|
|
10934
11446
|
};
|
|
10935
11447
|
|
|
10936
11448
|
/**
|
|
@@ -11141,15 +11653,15 @@ var EnvUtils$1 = {
|
|
|
11141
11653
|
* Component: GitSenseChatUtils
|
|
11142
11654
|
* Block-UUID: 5e8d1a9c-0b3f-4e1a-8c7d-9f0b2e1d3a4b
|
|
11143
11655
|
* Parent-UUID: 7a9b1c8e-f1a4-4b2d-9e8f-6f7a0b1c2d3f
|
|
11144
|
-
* Version: 2.1.
|
|
11656
|
+
* Version: 2.1.3
|
|
11145
11657
|
* Description: Interface class for GitSense Chat utilities providing a unified API for code block parsing (markdown), extraction, and patch operations. Integrates functionalities from CodeBlockUtils and PatchUtils modules, and now includes ConfigUtils and EnvUtils.
|
|
11146
11658
|
* Language: JavaScript
|
|
11147
11659
|
* Created-at: 2025-04-15T16:04:26.780Z
|
|
11148
|
-
* Authors: Claude 3.7 Sonnet (v1.0.0), Gemini 2.5 Pro (v2.0.0), Gemini 2.5 Pro (v2.1.0), Gemini 2.5 Pro (v2.1.1), Gemini 2.5 Flash (v2.1.2)
|
|
11660
|
+
* Authors: Claude 3.7 Sonnet (v1.0.0), Gemini 2.5 Pro (v2.0.0), Gemini 2.5 Pro (v2.1.0), Gemini 2.5 Pro (v2.1.1), Gemini 2.5 Flash (v2.1.2), Gemini 2.5 Flash (v2.1.3)
|
|
11149
11661
|
*/
|
|
11150
11662
|
|
|
11151
11663
|
const ChatUtils = ChatUtils$1;
|
|
11152
|
-
const CodeBlockUtils = CodeBlockUtils$
|
|
11664
|
+
const CodeBlockUtils = CodeBlockUtils$4;
|
|
11153
11665
|
const ContextUtils = ContextUtils$2;
|
|
11154
11666
|
const MessageUtils = MessageUtils$3;
|
|
11155
11667
|
const AnalysisBlockUtils = AnalysisBlockUtils$3;
|
|
@@ -11193,6 +11705,17 @@ const {
|
|
|
11193
11705
|
validateOverviewMetadata,
|
|
11194
11706
|
} = AnalysisBlockUtils;
|
|
11195
11707
|
|
|
11708
|
+
const {
|
|
11709
|
+
buildChatIdToPathMap,
|
|
11710
|
+
processLLMAnalysisResponse,
|
|
11711
|
+
validateLLMAnalysisData,
|
|
11712
|
+
getAnalyzers,
|
|
11713
|
+
getAnalyzerSchema,
|
|
11714
|
+
deleteAnalyzer,
|
|
11715
|
+
getAnalyzerInstructionsContent,
|
|
11716
|
+
saveAnalyzerConfiguration,
|
|
11717
|
+
} = AnalyzerUtils;
|
|
11718
|
+
|
|
11196
11719
|
const {
|
|
11197
11720
|
COMMENT_STYLES,
|
|
11198
11721
|
generateUUID,
|
|
@@ -11518,9 +12041,13 @@ var GitSenseChatUtils_1 = {
|
|
|
11518
12041
|
validateOverviewMetadata,
|
|
11519
12042
|
|
|
11520
12043
|
// Analyzer Utilities
|
|
11521
|
-
buildChatIdToPathMap
|
|
11522
|
-
processLLMAnalysisResponse
|
|
11523
|
-
validateLLMAnalysisData
|
|
12044
|
+
buildChatIdToPathMap,
|
|
12045
|
+
processLLMAnalysisResponse,
|
|
12046
|
+
validateLLMAnalysisData,
|
|
12047
|
+
getAnalyzers,
|
|
12048
|
+
getAnalyzerSchema,
|
|
12049
|
+
deleteAnalyzer,
|
|
12050
|
+
getAnalyzerInstructionsContent,
|
|
11524
12051
|
|
|
11525
12052
|
// ChatUtils
|
|
11526
12053
|
getChatMessages,
|