@gitsense/gsc-utils 0.2.5 → 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.
@@ -11051,6 +11051,23 @@ var discovery = {
11051
11051
  getAnalyzers: getAnalyzers$2,
11052
11052
  readConfig: readConfig$1};
11053
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
+
11054
11071
  /*
11055
11072
  * Component: AnalyzerUtils Schema Loader
11056
11073
  * Block-UUID: 0c1d2e3f-4a5b-6c7d-8e9f-0a1b2c3d4e5f
@@ -11414,6 +11431,7 @@ const { buildChatIdToPathMap: buildChatIdToPathMap$1 } = contextMapper;
11414
11431
  const { processLLMAnalysisResponse: processLLMAnalysisResponse$1 } = responseProcessor;
11415
11432
  const { validateLLMAnalysisData: validateLLMAnalysisData$1 } = dataValidator;
11416
11433
  const { getAnalyzers: getAnalyzers$1 } = discovery;
11434
+ const { saveConfiguration } = saver;
11417
11435
  const { getAnalyzerSchema: getAnalyzerSchema$1 } = schemaLoader;
11418
11436
  const { deleteAnalyzer: deleteAnalyzer$1 } = management;
11419
11437
  const { getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1 } = instructionLoader;
@@ -11426,6 +11444,7 @@ var AnalyzerUtils$1 = {
11426
11444
  getAnalyzerSchema: getAnalyzerSchema$1,
11427
11445
  deleteAnalyzer: deleteAnalyzer$1,
11428
11446
  getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1,
11447
+ saveConfiguration,
11429
11448
  };
11430
11449
 
11431
11450
  /**
@@ -11648,7 +11667,7 @@ const CodeBlockUtils = CodeBlockUtils$4;
11648
11667
  const ContextUtils = ContextUtils$2;
11649
11668
  const MessageUtils = MessageUtils$3;
11650
11669
  const AnalysisBlockUtils = AnalysisBlockUtils$3;
11651
- const AnalyzerUtils = AnalyzerUtils$1; // Updated import
11670
+ const AnalyzerUtils = AnalyzerUtils$1;
11652
11671
  const PatchUtils = PatchUtils$2;
11653
11672
  const GSToolBlockUtils = GSToolBlockUtils$3;
11654
11673
  const LLMUtils = LLMUtils$1;
@@ -11688,7 +11707,7 @@ const {
11688
11707
  validateOverviewMetadata,
11689
11708
  } = AnalysisBlockUtils;
11690
11709
 
11691
- const { // Updated AnalyzerUtils destructuring
11710
+ const {
11692
11711
  buildChatIdToPathMap,
11693
11712
  processLLMAnalysisResponse,
11694
11713
  validateLLMAnalysisData,
@@ -11696,6 +11715,7 @@ const { // Updated AnalyzerUtils destructuring
11696
11715
  getAnalyzerSchema,
11697
11716
  deleteAnalyzer,
11698
11717
  getAnalyzerInstructionsContent,
11718
+ saveAnalyzerConfiguration,
11699
11719
  } = AnalyzerUtils;
11700
11720
 
11701
11721
  const {
@@ -11049,6 +11049,23 @@ var discovery = {
11049
11049
  getAnalyzers: getAnalyzers$2,
11050
11050
  readConfig: readConfig$1};
11051
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
+
11052
11069
  /*
11053
11070
  * Component: AnalyzerUtils Schema Loader
11054
11071
  * Block-UUID: 0c1d2e3f-4a5b-6c7d-8e9f-0a1b2c3d4e5f
@@ -11412,6 +11429,7 @@ const { buildChatIdToPathMap: buildChatIdToPathMap$1 } = contextMapper;
11412
11429
  const { processLLMAnalysisResponse: processLLMAnalysisResponse$1 } = responseProcessor;
11413
11430
  const { validateLLMAnalysisData: validateLLMAnalysisData$1 } = dataValidator;
11414
11431
  const { getAnalyzers: getAnalyzers$1 } = discovery;
11432
+ const { saveConfiguration } = saver;
11415
11433
  const { getAnalyzerSchema: getAnalyzerSchema$1 } = schemaLoader;
11416
11434
  const { deleteAnalyzer: deleteAnalyzer$1 } = management;
11417
11435
  const { getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1 } = instructionLoader;
@@ -11424,6 +11442,7 @@ var AnalyzerUtils$1 = {
11424
11442
  getAnalyzerSchema: getAnalyzerSchema$1,
11425
11443
  deleteAnalyzer: deleteAnalyzer$1,
11426
11444
  getAnalyzerInstructionsContent: getAnalyzerInstructionsContent$1,
11445
+ saveConfiguration,
11427
11446
  };
11428
11447
 
11429
11448
  /**
@@ -11646,7 +11665,7 @@ const CodeBlockUtils = CodeBlockUtils$4;
11646
11665
  const ContextUtils = ContextUtils$2;
11647
11666
  const MessageUtils = MessageUtils$3;
11648
11667
  const AnalysisBlockUtils = AnalysisBlockUtils$3;
11649
- const AnalyzerUtils = AnalyzerUtils$1; // Updated import
11668
+ const AnalyzerUtils = AnalyzerUtils$1;
11650
11669
  const PatchUtils = PatchUtils$2;
11651
11670
  const GSToolBlockUtils = GSToolBlockUtils$3;
11652
11671
  const LLMUtils = LLMUtils$1;
@@ -11686,7 +11705,7 @@ const {
11686
11705
  validateOverviewMetadata,
11687
11706
  } = AnalysisBlockUtils;
11688
11707
 
11689
- const { // Updated AnalyzerUtils destructuring
11708
+ const {
11690
11709
  buildChatIdToPathMap,
11691
11710
  processLLMAnalysisResponse,
11692
11711
  validateLLMAnalysisData,
@@ -11694,6 +11713,7 @@ const { // Updated AnalyzerUtils destructuring
11694
11713
  getAnalyzerSchema,
11695
11714
  deleteAnalyzer,
11696
11715
  getAnalyzerInstructionsContent,
11716
+ saveAnalyzerConfiguration,
11697
11717
  } = AnalyzerUtils;
11698
11718
 
11699
11719
  const {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitsense/gsc-utils",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Utilities for GitSense Chat (GSC)",
5
5
  "main": "dist/gsc-utils.cjs.js",
6
6
  "module": "dist/gsc-utils.esm.js",
@@ -14,6 +14,7 @@ const { buildChatIdToPathMap } = require('./contextMapper');
14
14
  const { processLLMAnalysisResponse } = require('./responseProcessor');
15
15
  const { validateLLMAnalysisData } = require('./dataValidator');
16
16
  const { getAnalyzers } = require('./discovery');
17
+ const { saveConfiguration } = require('./saver');
17
18
  const { getAnalyzerSchema } = require('./schemaLoader');
18
19
  const { deleteAnalyzer } = require('./management');
19
20
  const { getAnalyzerInstructionsContent } = require('./instructionLoader');
@@ -26,4 +27,5 @@ module.exports = {
26
27
  getAnalyzerSchema,
27
28
  deleteAnalyzer,
28
29
  getAnalyzerInstructionsContent,
30
+ saveConfiguration,
29
31
  };
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Component: Analyzer Saver Utility
3
+ * Block-UUID: a373f4ba-89ce-465f-8624-24258c923e61
4
+ * Parent-UUID: N/A
5
+ * Version: 1.1.0
6
+ * Description: Utility function to save or update an analyzer configuration based on its ID and content.
7
+ * Language: JavaScript
8
+ * Created-at: 2025-07-12T04:12:33.454Z
9
+ * Authors: Gemini 2.5 Flash Thinking (v1.0.0), Gemini 2.5 Flash Thinking (v1.1.0)
10
+ */
11
+
12
+
13
+ const fs = require('fs').promises;
14
+ const path = require('path');
15
+
16
+ /**
17
+ * Saves or updates an analyzer configuration.
18
+ *
19
+ * This function takes the analyzer ID and its full instructions content,
20
+ * parses the ID to determine the directory structure, creates directories
21
+ * if necessary, saves the instructions to '1.md'. Optionally, it can
22
+ * ensure config.json files exist with labels derived from directory names.
23
+ *
24
+ * @param {string} analyzeMessagesBasePath - The absolute or relative path to the 'messages/analyze' directory.
25
+ * @param {string} analyzerId - The unique ID of the analyzer (format: 'analyzer_name::content_type::instructions_type').
26
+ * @param {string} instructionsContent - The full content of the analyzer instructions message to be saved in '1.md'.
27
+ * @param {object} [options={}] - Optional configuration options.
28
+ * @param {boolean} [options.ensureConfigs=false] - If true, ensures config.json files exist in the analyzer, content, and instructions directories. Defaults to false.
29
+ * @returns {Promise<{success: boolean, message?: string}>} A promise that resolves with a result object.
30
+ */
31
+ async function saveAnalyzerConfiguration(analyzeMessagesBasePath, analyzerId, instructionsContent, options = {}) {
32
+ const { ensureConfigs = false } = options;
33
+
34
+ // 1. Validate inputs
35
+ if (typeof analyzeMessagesBasePath !== 'string' || analyzeMessagesBasePath.trim() === '') {
36
+ return { success: false, message: 'analyzeMessagesBasePath is required.' };
37
+ }
38
+ if (typeof analyzerId !== 'string' || analyzerId.trim() === '') {
39
+ return { success: false, message: 'analyzerId is required.' };
40
+ }
41
+ if (typeof instructionsContent !== 'string' || instructionsContent.trim() === '') {
42
+ return { success: false, message: 'instructionsContent is required.' };
43
+ }
44
+
45
+ // 2. Parse analyzerId
46
+ const parts = analyzerId.split('::');
47
+ if (parts.length !== 3) {
48
+ return { success: false, message: `Invalid analyzerId format. Expected 'analyzer_name::content_type::instructions_type', but got '${analyzerId}'.` };
49
+ }
50
+ const [analyzerName, contentType, instructionsType] = parts;
51
+
52
+ // Helper to validate directory names based on README.md rules
53
+ const isValidDirName = (name) => {
54
+ // Cannot start with underscore, cannot contain dots, must be alphanumeric, dash, or underscore
55
+ return /^[a-zA-Z0-9_-]+$/.test(name) && !name.startsWith('_') && !name.includes('.');
56
+ };
57
+
58
+ if (!isValidDirName(analyzerName)) {
59
+ return { success: false, message: `Invalid analyzer name '${analyzerName}'. Names must be alphanumeric, dash, or underscore, cannot start with underscore, and cannot contain dots.` };
60
+ }
61
+ if (!isValidDirName(contentType)) {
62
+ return { success: false, message: `Invalid content type name '${contentType}'. Names must be alphanumeric, dash, or underscore, cannot start with underscore, and cannot contain dots.` };
63
+ }
64
+ if (!isValidDirName(instructionsType)) {
65
+ return { success: false, message: `Invalid instructions type name '${instructionsType}'. Names must be alphanumeric, dash, or underscore, cannot start with underscore, and cannot contain dots.` };
66
+ }
67
+
68
+ // 3. Construct directory paths
69
+ const analyzerDir = path.join(analyzeMessagesBasePath, analyzerName);
70
+ const contentDir = path.join(analyzerDir, contentType);
71
+ const instructionsDir = path.join(contentDir, instructionsType);
72
+ const instructionsFilePath = path.join(instructionsDir, '1.md');
73
+
74
+ try {
75
+ // 4. Create directories recursively
76
+ await fs.mkdir(instructionsDir, { recursive: true });
77
+
78
+ // 5. Save instructions content to 1.md
79
+ const finalContent = `; role: assistant\n\n\n${instructionsContent}`;
80
+ await fs.writeFile(instructionsFilePath, finalContent, 'utf8');
81
+
82
+ // 6. Optionally create/Update config.json files
83
+ if (ensureConfigs) {
84
+ await ensureConfigJson(analyzerDir, analyzerName);
85
+ await ensureConfigJson(contentDir, contentType);
86
+ await ensureConfigJson(instructionsDir, instructionsType);
87
+ }
88
+
89
+ return { success: true, message: `Analyzer configuration '${analyzerId}' saved successfully.` };
90
+
91
+ } catch (error) {
92
+ console.error(`Error saving analyzer configuration '${analyzerId}':`, error);
93
+ return { success: false, message: `Failed to save analyzer configuration: ${error.message}` };
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Ensures a config.json file exists in the given directory with a label.
99
+ * If the file exists, it reads it and adds the label if missing.
100
+ * If the file doesn't exist, it creates it with the label.
101
+ *
102
+ * @param {string} dirPath - The path to the directory.
103
+ * @param {string} label - The label to ensure is in the config.json.
104
+ */
105
+ async function ensureConfigJson(dirPath, label) {
106
+ const configPath = path.join(dirPath, 'config.json');
107
+ let config = {};
108
+
109
+ try {
110
+ const fileContent = await fs.readFile(configPath, 'utf8');
111
+ config = JSON.parse(fileContent);
112
+ } catch (error) {
113
+ // If file doesn't exist or parsing fails, start with an empty config
114
+ if (error.code !== 'ENOENT') {
115
+ console.warn(`Failed to read or parse existing config.json in ${dirPath}: ${error.message}`);
116
+ }
117
+ config = {}; // Ensure config is an object even on error
118
+ }
119
+
120
+ // Add or update the label if it's missing or empty
121
+ if (!config.label || typeof config.label !== 'string' || config.label.trim() === '') {
122
+ // Capitalize the first letter for the label
123
+ config.label = label.charAt(0).toUpperCase() + label.slice(1);
124
+ }
125
+
126
+ // Write the updated config back to the file
127
+ await fs.writeFile(configPath, JSON.stringify(config, null, 4), 'utf8');
128
+ }
129
+
130
+
131
+ module.exports = {
132
+ saveAnalyzerConfiguration,
133
+ };
@@ -15,7 +15,7 @@ const CodeBlockUtils = require('./CodeBlockUtils');
15
15
  const ContextUtils = require('./ContextUtils');
16
16
  const MessageUtils = require('./MessageUtils');
17
17
  const AnalysisBlockUtils = require('./AnalysisBlockUtils');
18
- const AnalyzerUtils = require('./AnalyzerUtils'); // Updated import
18
+ const AnalyzerUtils = require('./AnalyzerUtils');
19
19
  const PatchUtils = require('./PatchUtils');
20
20
  const GSToolBlockUtils = require('./GSToolBlockUtils');
21
21
  const LLMUtils = require('./LLMUtils');
@@ -55,7 +55,7 @@ const {
55
55
  validateOverviewMetadata,
56
56
  } = AnalysisBlockUtils;
57
57
 
58
- const { // Updated AnalyzerUtils destructuring
58
+ const {
59
59
  buildChatIdToPathMap,
60
60
  processLLMAnalysisResponse,
61
61
  validateLLMAnalysisData,
@@ -63,6 +63,7 @@ const { // Updated AnalyzerUtils destructuring
63
63
  getAnalyzerSchema,
64
64
  deleteAnalyzer,
65
65
  getAnalyzerInstructionsContent,
66
+ saveAnalyzerConfiguration,
66
67
  } = AnalyzerUtils;
67
68
 
68
69
  const {