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