@gitsense/gsc-utils 0.2.16 → 0.2.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitsense/gsc-utils",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "Utilities for GitSense Chat (GSC)",
5
5
  "main": "dist/gsc-utils.cjs.js",
6
6
  "module": "dist/gsc-utils.esm.js",
@@ -13,6 +13,7 @@
13
13
  const fs = require('fs').promises;
14
14
  const path = require('path');
15
15
  const { getAnalyzerInstructionsContent } = require('./instructionLoader');
16
+ const CodeBlockUtils = require('../CodeBlockUtils');
16
17
 
17
18
  /**
18
19
  * Reads and parses the config.json file in a directory.
@@ -110,10 +111,21 @@ async function getAnalyzers(analyzeMessagesBasePath, options = {}) {
110
111
  const analyzerId = `${analyzerName}::${contentType}::${instructionsType}`;
111
112
  const analyzerFullLabel = `${analyzerLabel} (${contentLabel} - ${instructionsLabel})`;
112
113
 
113
- let descriptionContent = null;
114
+ let description = null;
114
115
  if (includeDescription) {
115
116
  try {
116
- descriptionContent = await getAnalyzerInstructionsContent(analyzeMessagesBasePath, analyzerId);
117
+ const content = await getAnalyzerInstructionsContent(analyzeMessagesBasePath, analyzerId);
118
+ const { blocks, warnings } = CodeBlockUtils.extractCodeBlocks(content, { silent: true });
119
+ const jsonBlock = blocks.find(block => block.language === 'json');
120
+
121
+ if (jsonBlock && jsonBlock.content) {
122
+ try {
123
+ const json = JSON.parse(jsonBlock.content);
124
+ description = json.description;
125
+ } catch(error) {
126
+ console.warn(`${analyzerId} contains an invalid JSON`);
127
+ }
128
+ }
117
129
  } catch (descError) {
118
130
  console.warn(`Warning: Could not load description for ${analyzerId}: ${descError.message}`);
119
131
  descriptionContent = null;
@@ -125,7 +137,7 @@ async function getAnalyzers(analyzeMessagesBasePath, options = {}) {
125
137
  label: analyzerFullLabel,
126
138
  name: analyzerName,
127
139
  protected: analyzerConfig?.protected || false,
128
- ...(descriptionContent && { description: descriptionContent })
140
+ description
129
141
  });
130
142
  } catch (error) {
131
143
  // If 1.md doesn't exist, this is not a complete analyzer configuration, skip.
@@ -10,9 +10,6 @@
10
10
  */
11
11
 
12
12
 
13
- const { updateCodeBlockByIndex } = require('./CodeBlockUtils/updateCodeBlock');
14
- const { processCodeBlocks } = require('./CodeBlockUtils/blockProcessor');
15
-
16
13
  /**
17
14
  * Checks if a given code block content represents a GitSense Chat Tool Block.
18
15
  * It verifies if the first non-empty line starts with "# GitSense Chat Tool".
@@ -120,11 +117,16 @@ function formatToolBlock(toolData) {
120
117
  * @returns {string} The markdown content with the specified tool block updated.
121
118
  * @throws {Error} If the target tool block is not found or if CodeBlockUtils encounters an error.
122
119
  */
123
- function replaceToolBlock(markdownContent, toolName, newToolData) {
120
+ function replaceToolBlock(markdownContent, toolName, newToolData, processCodeBlocks, updateCodeBlockByIndex) {
124
121
  if (typeof markdownContent !== 'string' || !toolName || !newToolData) {
125
122
  throw new Error("Missing required parameters for replaceToolBlock.");
126
123
  }
127
124
 
125
+ // We can't require them as this will create a circular dependency
126
+ if (!processCodeBlocks || !updateCodeBlockByIndex) {
127
+ throw new Error("Missing required dependencies processCodeBlocks and/or updateCodeBlockByIndex.");
128
+ }
129
+
128
130
  // 1. Process the markdown content to find all code blocks
129
131
  const { blocks, warnings } = processCodeBlocks(markdownContent, { silent: true });
130
132