@codebolt/codeboltjs 2.0.5 → 2.0.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.
Files changed (64) hide show
  1. package/dist/core/websocket.js +2 -1
  2. package/dist/index.d.ts +57 -16
  3. package/dist/index.js +2 -0
  4. package/dist/modules/agent.js +1 -1
  5. package/dist/modules/codeparsers.d.ts +32 -3
  6. package/dist/modules/codeparsers.js +295 -3
  7. package/dist/modules/codeutils.d.ts +24 -7
  8. package/dist/modules/codeutils.js +93 -29
  9. package/dist/modules/docutils.d.ts +1 -4
  10. package/dist/modules/docutils.js +52 -2
  11. package/dist/modules/fs.d.ts +46 -0
  12. package/dist/modules/fs.js +70 -1
  13. package/dist/modules/git.d.ts +7 -14
  14. package/dist/modules/git.js +16 -37
  15. package/dist/modules/outputparsers.d.ts +36 -4
  16. package/dist/modules/outputparsers.js +56 -5
  17. package/dist/modules/project.d.ts +3 -4
  18. package/dist/modules/project.js +7 -5
  19. package/dist/modules/terminal.js +1 -1
  20. package/dist/utils/parse-source-code/index.d.ts +9 -0
  21. package/dist/utils/parse-source-code/index.js +233 -0
  22. package/dist/utils/parse-source-code/languageParser.d.ts +8 -0
  23. package/dist/utils/parse-source-code/languageParser.js +137 -0
  24. package/dist/utils/parse-source-code/queries/c-sharp.d.ts +2 -0
  25. package/dist/utils/parse-source-code/queries/c-sharp.js +25 -0
  26. package/dist/utils/parse-source-code/queries/c.d.ts +2 -0
  27. package/dist/utils/parse-source-code/queries/c.js +17 -0
  28. package/dist/utils/parse-source-code/queries/cpp.d.ts +2 -0
  29. package/dist/utils/parse-source-code/queries/cpp.js +25 -0
  30. package/dist/utils/parse-source-code/queries/go.d.ts +2 -0
  31. package/dist/utils/parse-source-code/queries/go.js +29 -0
  32. package/dist/utils/parse-source-code/queries/index.d.ts +12 -0
  33. package/dist/utils/parse-source-code/queries/index.js +30 -0
  34. package/dist/utils/parse-source-code/queries/java.d.ts +2 -0
  35. package/dist/utils/parse-source-code/queries/java.js +17 -0
  36. package/dist/utils/parse-source-code/queries/javascript.d.ts +2 -0
  37. package/dist/utils/parse-source-code/queries/javascript.js +67 -0
  38. package/dist/utils/parse-source-code/queries/php.d.ts +2 -0
  39. package/dist/utils/parse-source-code/queries/php.js +17 -0
  40. package/dist/utils/parse-source-code/queries/python.d.ts +2 -0
  41. package/dist/utils/parse-source-code/queries/python.js +13 -0
  42. package/dist/utils/parse-source-code/queries/ruby.d.ts +2 -0
  43. package/dist/utils/parse-source-code/queries/ruby.js +54 -0
  44. package/dist/utils/parse-source-code/queries/rust.d.ts +2 -0
  45. package/dist/utils/parse-source-code/queries/rust.js +18 -0
  46. package/dist/utils/parse-source-code/queries/swift.d.ts +2 -0
  47. package/dist/utils/parse-source-code/queries/swift.js +47 -0
  48. package/dist/utils/parse-source-code/queries/typescript.d.ts +2 -0
  49. package/dist/utils/parse-source-code/queries/typescript.js +34 -0
  50. package/dist/utils/parse-source-code/tree-sitter-c.wasm +0 -0
  51. package/dist/utils/parse-source-code/tree-sitter-c_sharp.wasm +0 -0
  52. package/dist/utils/parse-source-code/tree-sitter-cpp.wasm +0 -0
  53. package/dist/utils/parse-source-code/tree-sitter-go.wasm +0 -0
  54. package/dist/utils/parse-source-code/tree-sitter-java.wasm +0 -0
  55. package/dist/utils/parse-source-code/tree-sitter-javascript.wasm +0 -0
  56. package/dist/utils/parse-source-code/tree-sitter-php.wasm +0 -0
  57. package/dist/utils/parse-source-code/tree-sitter-python.wasm +0 -0
  58. package/dist/utils/parse-source-code/tree-sitter-ruby.wasm +0 -0
  59. package/dist/utils/parse-source-code/tree-sitter-rust.wasm +0 -0
  60. package/dist/utils/parse-source-code/tree-sitter-swift.wasm +0 -0
  61. package/dist/utils/parse-source-code/tree-sitter-tsx.wasm +0 -0
  62. package/dist/utils/parse-source-code/tree-sitter-typescript.wasm +0 -0
  63. package/dist/utils/parse-source-code/tree-sitter.wasm +0 -0
  64. package/package.json +6 -2
@@ -55,7 +55,8 @@ class cbws {
55
55
  const parentIdParam = process.env.parentId ? `&parentId=${process.env.parentId}` : '';
56
56
  const parentAgentInstanceIdParam = process.env.parentAgentInstanceId ? `&parentAgentInstanceId=${process.env.parentAgentInstanceId}` : '';
57
57
  const agentTask = process.env.agentTask ? `&agentTask=${process.env.agentTask}` : '';
58
- this.websocket = new ws_1.default(`ws://localhost:${process.env.SOCKET_PORT}/codebolt?id=${uniqueConnectionId}${agentIdParam}${parentIdParam}${parentAgentInstanceIdParam}${agentTask}${process.env.Is_Dev ? '&dev=true' : ''}`);
58
+ const socketPort = process.env.SOCKET_PORT || '12345';
59
+ this.websocket = new ws_1.default(`ws://localhost:${socketPort}/codebolt?id=${uniqueConnectionId}${agentIdParam}${parentIdParam}${parentAgentInstanceIdParam}${agentTask}${process.env.Is_Dev ? '&dev=true' : ''}`);
59
60
  return new Promise((resolve, reject) => {
60
61
  this.websocket.on('error', (error) => {
61
62
  reject(error);
package/dist/index.d.ts CHANGED
@@ -35,19 +35,30 @@ declare class Codebolt {
35
35
  result: any;
36
36
  }>;
37
37
  writeToFile: (relPath: string, newContent: string) => Promise<any>;
38
+ grepSearch: (path: string, query: string, includePattern?: string | undefined, excludePattern?: string | undefined, caseSensitive?: boolean) => Promise<{
39
+ success: boolean;
40
+ result: any;
41
+ }>;
42
+ fileSearch: (query: string) => Promise<{
43
+ success: boolean;
44
+ result: any;
45
+ }>;
46
+ editFileWithDiff: (targetFile: string, codeEdit: string, diffIdentifier: string, prompt: string, applyModel?: string | undefined) => Promise<{
47
+ success: boolean;
48
+ result: any;
49
+ }>;
38
50
  };
39
51
  git: {
40
52
  init: (path: string) => Promise<any>;
41
- clone: (url: string, path: string) => Promise<any>;
42
- pull: (path: string) => Promise<any>;
43
- push: (path: string) => Promise<any>;
44
- status: (path: string) => Promise<any>;
45
- add: (path: string) => Promise<any>;
53
+ pull: () => Promise<any>;
54
+ push: () => Promise<any>;
55
+ status: () => Promise<any>;
56
+ addAll: () => Promise<any>;
46
57
  commit: (message: string) => Promise<any>;
47
- checkout: (path: string, branch: string) => Promise<any>;
48
- branch: (path: string, branch: string) => Promise<any>;
58
+ checkout: (branch: string) => Promise<any>;
59
+ branch: (branch: string) => Promise<any>;
49
60
  logs: (path: string) => Promise<any>;
50
- diff: (commitHash: string, path: string) => Promise<any>;
61
+ diff: (commitHash: string) => Promise<any>;
51
62
  };
52
63
  llm: {
53
64
  inference: (message: string, llmrole: string) => Promise<import("@codebolt/types").LLMResponse>;
@@ -134,14 +145,14 @@ declare class Codebolt {
134
145
  };
135
146
  };
136
147
  codeutils: {
137
- getJsTree: (filePath?: string | undefined) => Promise<any>;
148
+ getJsTree: (filePath?: string | undefined) => Promise<import("./modules/codeutils").JSTreeResponse>;
138
149
  getAllFilesAsMarkDown: () => Promise<string>;
139
- performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
150
+ performMatch: (matcherDefinition: object, problemPatterns: any[], problems?: any[]) => Promise<import("@codebolt/types").MatchProblemResponse>;
140
151
  getMatcherList: () => Promise<import("@codebolt/types").GetMatcherListTreeResponse>;
141
152
  matchDetail: (matcher: string) => Promise<import("@codebolt/types").getMatchDetail>;
142
153
  };
143
154
  docutils: {
144
- pdf_to_text: (pdf_path: any) => Promise<string>;
155
+ pdf_to_text: (pdf_path: string) => Promise<string>;
145
156
  };
146
157
  crawler: {
147
158
  start: () => void;
@@ -162,17 +173,47 @@ declare class Codebolt {
162
173
  retrieve_related_knowledge: (query: string, filename: string) => void;
163
174
  };
164
175
  codeparsers: {
165
- getClassesInFile: (file: any) => void;
166
- getFunctionsinClass: (file: any, className: any) => void;
167
- getAstTreeInFile: (file: any, className: any) => void;
176
+ getClassesInFile: (file: string) => Promise<{
177
+ error: string;
178
+ } | {
179
+ name: any;
180
+ location: string;
181
+ }[]>;
182
+ getFunctionsinClass: (file: string, className: string) => Promise<{
183
+ error: string;
184
+ } | {
185
+ name: string;
186
+ class: string;
187
+ location: string;
188
+ }[]>;
189
+ getAstTreeInFile: (file: string, className?: string | undefined) => Promise<import("./modules/codeparsers").ASTNode | {
190
+ error: string;
191
+ }>;
168
192
  };
169
193
  outputparsers: {
170
- init: (output: any) => void;
194
+ parseJSON: (jsonString: string) => {
195
+ success: boolean;
196
+ parsed?: any;
197
+ error?: Error | undefined;
198
+ };
199
+ parseXML: (xmlString: string) => {
200
+ success: boolean;
201
+ parsed?: any;
202
+ };
203
+ parseCSV: (csvString: string) => {
204
+ success: boolean;
205
+ parsed?: any[] | undefined;
206
+ error?: Error | undefined;
207
+ };
208
+ parseText: (text: string) => {
209
+ success: boolean;
210
+ parsed: string[];
211
+ };
171
212
  parseErrors: (output: any) => string[];
172
213
  parseWarnings: (output: any) => string[];
173
214
  };
174
215
  project: {
175
- getProjectSettings: (output: any) => void;
216
+ getProjectSettings: () => Promise<any>;
176
217
  getProjectPath: () => Promise<import("@codebolt/types").GetProjectPathResponse>;
177
218
  getRepoMap: (message: any) => Promise<import("@codebolt/types").GetProjectPathResponse>;
178
219
  runProject: () => void;
package/dist/index.js CHANGED
@@ -66,6 +66,7 @@ class Codebolt {
66
66
  this.tools = tools_1.default;
67
67
  this.agent = agent_1.default;
68
68
  this.utils = utils_1.default;
69
+ console.log("Codebolt Agent initialized");
69
70
  websocket_1.default.initializeWebSocket();
70
71
  this.websocket = websocket_1.default.getWebsocket;
71
72
  }
@@ -101,6 +102,7 @@ class Codebolt {
101
102
  const waitForConnection = () => {
102
103
  if (websocket_1.default.messageManager) {
103
104
  const handleUserMessage = async (response) => {
105
+ console.log("Message received By Agent Library Starting Custom Agent Handler Logic", response);
104
106
  if (response.type === "messageResponse") {
105
107
  try {
106
108
  const result = await handler(response);
@@ -73,7 +73,7 @@ const codeboltAgent = {
73
73
  "type": "agentEvent",
74
74
  "action": "agentsDetail",
75
75
  "agentList": agentList
76
- }, "listAgentsResponse");
76
+ }, "agentsDetailResponse");
77
77
  }
78
78
  };
79
79
  exports.default = codeboltAgent;
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Type definition for an AST node.
3
+ */
4
+ export interface ASTNode {
5
+ type: string;
6
+ text: string;
7
+ startPosition: {
8
+ row: number;
9
+ column: number;
10
+ };
11
+ endPosition: {
12
+ row: number;
13
+ column: number;
14
+ };
15
+ children: ASTNode[];
16
+ }
1
17
  /**
2
18
  * A collection of code parser functions.
3
19
  */
@@ -6,18 +22,31 @@ declare const cbcodeparsers: {
6
22
  * Retrieves the classes in a given file.
7
23
  * @param file The file to parse for classes.
8
24
  */
9
- getClassesInFile: (file: any) => void;
25
+ getClassesInFile: (file: string) => Promise<{
26
+ error: string;
27
+ } | {
28
+ name: any;
29
+ location: string;
30
+ }[]>;
10
31
  /**
11
32
  * Retrieves the functions in a given class within a file.
12
33
  * @param file The file containing the class.
13
34
  * @param className The name of the class to parse for functions.
14
35
  */
15
- getFunctionsinClass: (file: any, className: any) => void;
36
+ getFunctionsinClass: (file: string, className: string) => Promise<{
37
+ error: string;
38
+ } | {
39
+ name: string;
40
+ class: string;
41
+ location: string;
42
+ }[]>;
16
43
  /**
17
44
  * Generates an Abstract Syntax Tree (AST) for a given file.
18
45
  * @param file The file to generate an AST for.
19
46
  * @param className The name of the class to focus the AST generation on.
20
47
  */
21
- getAstTreeInFile: (file: any, className: any) => void;
48
+ getAstTreeInFile: (file: string, className?: string) => Promise<ASTNode | {
49
+ error: string;
50
+ }>;
22
51
  };
23
52
  export default cbcodeparsers;
@@ -1,5 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const parse_source_code_1 = require("../utils/parse-source-code");
27
+ const languageParser_1 = require("../utils/parse-source-code/languageParser");
28
+ const fs = __importStar(require("fs/promises"));
29
+ const path = __importStar(require("path"));
3
30
  /**
4
31
  * A collection of code parser functions.
5
32
  */
@@ -8,21 +35,286 @@ const cbcodeparsers = {
8
35
  * Retrieves the classes in a given file.
9
36
  * @param file The file to parse for classes.
10
37
  */
11
- getClassesInFile: (file) => {
38
+ getClassesInFile: async (file) => {
39
+ // Check if file exists
40
+ try {
41
+ await fs.access(file);
42
+ }
43
+ catch (error) {
44
+ return { error: `File does not exist or is not accessible: ${file}` };
45
+ }
46
+ // Get file extension and determine if we support it
47
+ const ext = path.extname(file).toLowerCase().slice(1);
48
+ const supportedExtensions = ['js', 'jsx', 'ts', 'tsx', 'py', 'rs', 'go', 'c', 'h', 'cpp', 'hpp', 'cs', 'rb', 'java', 'php', 'swift'];
49
+ if (!supportedExtensions.includes(ext)) {
50
+ return { error: `Unsupported file type: ${ext}` };
51
+ }
52
+ // Load language parser for this file
53
+ const languageParsers = await (0, languageParser_1.loadRequiredLanguageParsers)([file]);
54
+ // Parse the file
55
+ const result = await (0, parse_source_code_1.parseFile)(file, languageParsers);
56
+ // Filter for class definitions only
57
+ const lines = (result === null || result === void 0 ? void 0 : result.split('\n')) || [];
58
+ const classes = [];
59
+ let currentClass = null;
60
+ for (const line of lines) {
61
+ // Match line patterns from the parseFile result format
62
+ if (line.includes('@definition.class')) {
63
+ // Extract the class name from the line
64
+ const className = line.split('@')[0].trim();
65
+ currentClass = { name: className, location: file };
66
+ classes.push(currentClass);
67
+ }
68
+ }
69
+ // If no classes found, try to use AST approach
70
+ if (classes.length === 0) {
71
+ try {
72
+ // Get the file extension
73
+ const ext = path.extname(file).toLowerCase().slice(1);
74
+ // Load language parser
75
+ const languageParsers = await (0, languageParser_1.loadRequiredLanguageParsers)([file]);
76
+ // Get the parser for this file type
77
+ const { parser } = languageParsers[ext] || {};
78
+ if (parser) {
79
+ // Read the file content
80
+ const fileContent = await fs.readFile(file, 'utf8');
81
+ // Parse the file to get AST
82
+ const tree = parser.parse(fileContent);
83
+ // Function to find class nodes in the AST
84
+ const findClassNodes = (node) => {
85
+ const classNodes = [];
86
+ if (node.type === 'class_declaration' ||
87
+ node.type === 'class' ||
88
+ node.type === 'class_definition') {
89
+ classNodes.push(node);
90
+ }
91
+ // Recursively search children
92
+ for (let i = 0; i < node.childCount; i++) {
93
+ const childResults = findClassNodes(node.child(i));
94
+ classNodes.push(...childResults);
95
+ }
96
+ return classNodes;
97
+ };
98
+ const classNodes = findClassNodes(tree.rootNode);
99
+ // Extract class names from the nodes
100
+ for (const node of classNodes) {
101
+ // For most languages, the class name is in a child node
102
+ // Let's attempt to extract it from the text
103
+ const text = node.text;
104
+ const classMatch = text.match(/class\s+([a-zA-Z_$][0-9a-zA-Z_$]*)/);
105
+ if (classMatch && classMatch[1]) {
106
+ classes.push({
107
+ name: classMatch[1],
108
+ location: file
109
+ });
110
+ }
111
+ }
112
+ }
113
+ }
114
+ catch (error) {
115
+ console.error('Error trying AST approach:', error);
116
+ }
117
+ }
118
+ return classes;
12
119
  },
13
120
  /**
14
121
  * Retrieves the functions in a given class within a file.
15
122
  * @param file The file containing the class.
16
123
  * @param className The name of the class to parse for functions.
17
124
  */
18
- getFunctionsinClass: (file, className) => {
125
+ getFunctionsinClass: async (file, className) => {
126
+ // Check if file exists
127
+ try {
128
+ await fs.access(file);
129
+ }
130
+ catch (error) {
131
+ return { error: `File does not exist or is not accessible: ${file}` };
132
+ }
133
+ // Load language parser for this file
134
+ const languageParsers = await (0, languageParser_1.loadRequiredLanguageParsers)([file]);
135
+ // Parse the file
136
+ const result = await (0, parse_source_code_1.parseFile)(file, languageParsers);
137
+ // Extract content
138
+ const fileContent = await fs.readFile(file, 'utf8');
139
+ // Parse the file content to find the class and its methods
140
+ const lines = (result === null || result === void 0 ? void 0 : result.split('\n')) || [];
141
+ const functions = [];
142
+ // Use AST approach to find methods within the class
143
+ try {
144
+ // Get the file extension
145
+ const ext = path.extname(file).toLowerCase().slice(1);
146
+ // Get the parser for this file type
147
+ const { parser } = languageParsers[ext] || {};
148
+ if (parser) {
149
+ // Parse the file to get AST
150
+ const tree = parser.parse(fileContent);
151
+ // Find the class node
152
+ const findClassNode = (node) => {
153
+ if ((node.type === 'class_declaration' ||
154
+ node.type === 'class' ||
155
+ node.type === 'class_definition') &&
156
+ node.text.includes(className)) {
157
+ return node;
158
+ }
159
+ // Recursively search children
160
+ for (let i = 0; i < node.childCount; i++) {
161
+ const child = node.child(i);
162
+ const result = findClassNode(child);
163
+ if (result)
164
+ return result;
165
+ }
166
+ return null;
167
+ };
168
+ const classNode = findClassNode(tree.rootNode);
169
+ if (classNode) {
170
+ // Function to find method nodes within the class
171
+ const findMethodNodes = (node) => {
172
+ const methodNodes = [];
173
+ // Different languages use different node types for methods
174
+ if (node.type === 'method_definition' ||
175
+ node.type === 'method' ||
176
+ node.type === 'method_declaration' ||
177
+ node.type === 'function' ||
178
+ node.type === 'function_definition') {
179
+ methodNodes.push(node);
180
+ }
181
+ // Recursively search children
182
+ for (let i = 0; i < node.childCount; i++) {
183
+ const childResults = findMethodNodes(node.child(i));
184
+ methodNodes.push(...childResults);
185
+ }
186
+ return methodNodes;
187
+ };
188
+ const methodNodes = findMethodNodes(classNode);
189
+ // Extract method names from the nodes
190
+ for (const node of methodNodes) {
191
+ // Try to find method name from node text
192
+ let methodName = '';
193
+ // Different pattern matching based on language type
194
+ if (ext === 'py') {
195
+ // Python methods: def method_name(
196
+ const methodMatch = node.text.match(/def\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/);
197
+ if (methodMatch && methodMatch[1]) {
198
+ methodName = methodMatch[1];
199
+ }
200
+ }
201
+ else if (['js', 'jsx', 'ts', 'tsx'].includes(ext)) {
202
+ // JavaScript/TypeScript methods: methodName( or methodName =
203
+ const methodMatch = node.text.match(/([a-zA-Z_$][a-zA-Z0-9_$]*)\s*[\(=]/);
204
+ if (methodMatch && methodMatch[1]) {
205
+ methodName = methodMatch[1];
206
+ }
207
+ }
208
+ else {
209
+ // Generic approach for other languages
210
+ // Look for identifiers followed by parentheses
211
+ const methodMatch = node.text.match(/([a-zA-Z_][a-zA-Z0-9_]*)\s*\(/);
212
+ if (methodMatch && methodMatch[1]) {
213
+ methodName = methodMatch[1];
214
+ }
215
+ }
216
+ if (methodName && !['constructor', '__init__'].includes(methodName)) {
217
+ functions.push({
218
+ name: methodName,
219
+ class: className,
220
+ location: file
221
+ });
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }
227
+ catch (error) {
228
+ console.error('Error parsing methods:', error);
229
+ }
230
+ return functions;
19
231
  },
20
232
  /**
21
233
  * Generates an Abstract Syntax Tree (AST) for a given file.
22
234
  * @param file The file to generate an AST for.
23
235
  * @param className The name of the class to focus the AST generation on.
24
236
  */
25
- getAstTreeInFile: (file, className) => {
237
+ getAstTreeInFile: async (file, className) => {
238
+ try {
239
+ await fs.access(file);
240
+ }
241
+ catch (error) {
242
+ return { error: `File does not exist or is not accessible: ${file}` };
243
+ }
244
+ // Get file extension and determine if we support it
245
+ const ext = path.extname(file).toLowerCase().slice(1);
246
+ const supportedExtensions = ['js', 'jsx', 'ts', 'tsx', 'py', 'rs', 'go', 'c', 'h', 'cpp', 'hpp', 'cs', 'rb', 'java', 'php', 'swift'];
247
+ if (!supportedExtensions.includes(ext)) {
248
+ return { error: `Unsupported file type: ${ext}` };
249
+ }
250
+ // Load language parser for this file
251
+ const languageParsers = await (0, languageParser_1.loadRequiredLanguageParsers)([file]);
252
+ // Get the parser for this file type
253
+ const { parser } = languageParsers[ext] || {};
254
+ if (!parser) {
255
+ return { error: `No parser available for file type: ${ext}` };
256
+ }
257
+ // Read the file content
258
+ const fileContent = await fs.readFile(file, 'utf8');
259
+ // Parse the file to get AST
260
+ const tree = parser.parse(fileContent);
261
+ // If className is provided, find and return only that class's AST
262
+ if (className) {
263
+ // Function to recursively search for the class node
264
+ const findClassNode = (node) => {
265
+ if ((node.type === 'class_declaration' ||
266
+ node.type === 'abstract_class_declaration' ||
267
+ node.type === 'class_definition') &&
268
+ node.text.includes(className)) {
269
+ return node;
270
+ }
271
+ // Recursively search children
272
+ for (let i = 0; i < node.childCount; i++) {
273
+ const child = node.child(i);
274
+ const result = findClassNode(child);
275
+ if (result)
276
+ return result;
277
+ }
278
+ return null;
279
+ };
280
+ const classNode = findClassNode(tree.rootNode);
281
+ if (classNode) {
282
+ // Convert the class node to a JSON-serializable object
283
+ const serializeNode = (node) => {
284
+ const result = {
285
+ type: node.type,
286
+ text: node.text,
287
+ startPosition: { row: node.startPosition.row, column: node.startPosition.column },
288
+ endPosition: { row: node.endPosition.row, column: node.endPosition.column },
289
+ children: []
290
+ };
291
+ for (let i = 0; i < node.childCount; i++) {
292
+ result.children.push(serializeNode(node.child(i)));
293
+ }
294
+ return result;
295
+ };
296
+ return serializeNode(classNode);
297
+ }
298
+ else {
299
+ return { error: `Class '${className}' not found in file: ${file}` };
300
+ }
301
+ }
302
+ // Otherwise return the full AST
303
+ // Convert the full tree to a JSON-serializable object
304
+ const serializeNode = (node) => {
305
+ const result = {
306
+ type: node.type,
307
+ text: node.text,
308
+ startPosition: { row: node.startPosition.row, column: node.startPosition.column },
309
+ endPosition: { row: node.endPosition.row, column: node.endPosition.column },
310
+ children: []
311
+ };
312
+ for (let i = 0; i < node.childCount; i++) {
313
+ result.children.push(serializeNode(node.child(i)));
314
+ }
315
+ return result;
316
+ };
317
+ return serializeNode(tree.rootNode);
26
318
  }
27
319
  };
28
320
  exports.default = cbcodeparsers;
@@ -1,4 +1,21 @@
1
1
  import { MatchProblemResponse, GetMatcherListTreeResponse, getMatchDetail } from '@codebolt/types';
2
+ export interface JSTreeStructureItem {
3
+ type: string;
4
+ name: string;
5
+ startLine: number;
6
+ endLine: number;
7
+ startColumn: number;
8
+ endColumn: number;
9
+ nodeType: string;
10
+ }
11
+ export interface JSTreeResponse {
12
+ event: string;
13
+ payload?: {
14
+ filePath: string;
15
+ structure: JSTreeStructureItem[];
16
+ };
17
+ error?: string;
18
+ }
2
19
  /**
3
20
  * A utility module for working with code.
4
21
  */
@@ -6,9 +23,9 @@ declare const cbcodeutils: {
6
23
  /**
7
24
  * Retrieves a JavaScript tree structure for a given file path.
8
25
  * @param {string} filePath - The path of the file to retrieve the JS tree for.
9
- * @returns {Promise<GetJsTreeResponse>} A promise that resolves with the JS tree response.
26
+ * @returns {Promise<JSTreeResponse>} A promise that resolves with the JS tree response.
10
27
  */
11
- getJsTree: (filePath?: string) => Promise<any>;
28
+ getJsTree: (filePath?: string) => Promise<JSTreeResponse>;
12
29
  /**
13
30
  * Retrieves all files as Markdown.
14
31
  * @returns {Promise<string>} A promise that resolves with the Markdown content of all files.
@@ -16,12 +33,12 @@ declare const cbcodeutils: {
16
33
  getAllFilesAsMarkDown: () => Promise<string>;
17
34
  /**
18
35
  * Performs a matching operation based on the provided matcher definition and problem patterns.
19
- * @param {object} matcherDefinition - The definition of the matcher.
20
- * @param {Array} problemPatterns - The patterns to match against.
21
- * @param {Array} problems - The list of problems.
36
+ * @param {object} matcherDefinition - The definition of the matcher (name, pattern, language, etc.).
37
+ * @param {Array} problemPatterns - The patterns to match against (regex patterns with severity levels).
38
+ * @param {Array} problems - Optional list of pre-existing problems to include.
22
39
  * @returns {Promise<MatchProblemResponse>} A promise that resolves with the matching problem response.
23
40
  */
24
- performMatch: (matcherDefinition: object, problemPatterns: any[], problems: any[]) => Promise<MatchProblemResponse>;
41
+ performMatch: (matcherDefinition: object, problemPatterns: any[], problems?: any[]) => Promise<MatchProblemResponse>;
25
42
  /**
26
43
  * Retrieves the list of matchers.
27
44
  * @returns {Promise<GetMatcherListTreeResponse>} A promise that resolves with the list of matchers response.
@@ -29,7 +46,7 @@ declare const cbcodeutils: {
29
46
  getMatcherList: () => Promise<GetMatcherListTreeResponse>;
30
47
  /**
31
48
  * Retrieves details of a match.
32
- * @param {string} matcher - The matcher to retrieve details for.
49
+ * @param {string} matcher - The matcher to retrieve details for (by name or identifier).
33
50
  * @returns {Promise<getMatchDetail>} A promise that resolves with the match detail response.
34
51
  */
35
52
  matchDetail: (matcher: string) => Promise<getMatchDetail>;