@probelabs/probe 0.6.0-rc116 → 0.6.0-rc117

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.
@@ -29807,6 +29807,268 @@ var init_simpleTelemetry = __esm({
29807
29807
  }
29808
29808
  });
29809
29809
 
29810
+ // src/agent/probeTool.js
29811
+ function isSessionCancelled(sessionId) {
29812
+ return activeToolExecutions.get(sessionId)?.cancelled || false;
29813
+ }
29814
+ function registerToolExecution(sessionId) {
29815
+ if (!sessionId) return;
29816
+ if (!activeToolExecutions.has(sessionId)) {
29817
+ activeToolExecutions.set(sessionId, { cancelled: false });
29818
+ } else {
29819
+ activeToolExecutions.get(sessionId).cancelled = false;
29820
+ }
29821
+ }
29822
+ function clearToolExecutionData(sessionId) {
29823
+ if (!sessionId) return;
29824
+ if (activeToolExecutions.has(sessionId)) {
29825
+ activeToolExecutions.delete(sessionId);
29826
+ if (process.env.DEBUG === "1") {
29827
+ console.log(`Cleared tool execution data for session: ${sessionId}`);
29828
+ }
29829
+ }
29830
+ }
29831
+ function createWrappedTools(baseTools) {
29832
+ const wrappedTools = {};
29833
+ if (baseTools.searchTool) {
29834
+ wrappedTools.searchToolInstance = wrapToolWithEmitter(
29835
+ baseTools.searchTool,
29836
+ "search",
29837
+ baseTools.searchTool.execute
29838
+ );
29839
+ }
29840
+ if (baseTools.queryTool) {
29841
+ wrappedTools.queryToolInstance = wrapToolWithEmitter(
29842
+ baseTools.queryTool,
29843
+ "query",
29844
+ baseTools.queryTool.execute
29845
+ );
29846
+ }
29847
+ if (baseTools.extractTool) {
29848
+ wrappedTools.extractToolInstance = wrapToolWithEmitter(
29849
+ baseTools.extractTool,
29850
+ "extract",
29851
+ baseTools.extractTool.execute
29852
+ );
29853
+ }
29854
+ if (baseTools.delegateTool) {
29855
+ wrappedTools.delegateToolInstance = wrapToolWithEmitter(
29856
+ baseTools.delegateTool,
29857
+ "delegate",
29858
+ baseTools.delegateTool.execute
29859
+ );
29860
+ }
29861
+ if (baseTools.bashTool) {
29862
+ wrappedTools.bashToolInstance = wrapToolWithEmitter(
29863
+ baseTools.bashTool,
29864
+ "bash",
29865
+ baseTools.bashTool.execute
29866
+ );
29867
+ }
29868
+ return wrappedTools;
29869
+ }
29870
+ var import_child_process8, import_util6, import_crypto3, import_events, import_fs4, import_fs5, import_path8, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
29871
+ var init_probeTool = __esm({
29872
+ "src/agent/probeTool.js"() {
29873
+ "use strict";
29874
+ init_index();
29875
+ import_child_process8 = require("child_process");
29876
+ import_util6 = require("util");
29877
+ import_crypto3 = require("crypto");
29878
+ import_events = require("events");
29879
+ import_fs4 = __toESM(require("fs"), 1);
29880
+ import_fs5 = require("fs");
29881
+ import_path8 = __toESM(require("path"), 1);
29882
+ import_glob = require("glob");
29883
+ toolCallEmitter = new import_events.EventEmitter();
29884
+ activeToolExecutions = /* @__PURE__ */ new Map();
29885
+ wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
29886
+ return {
29887
+ ...tool3,
29888
+ // Spread schema, description etc.
29889
+ execute: async (params) => {
29890
+ const debug = process.env.DEBUG === "1";
29891
+ const toolSessionId = params.sessionId || (0, import_crypto3.randomUUID)();
29892
+ if (debug) {
29893
+ console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
29894
+ }
29895
+ registerToolExecution(toolSessionId);
29896
+ let executionError = null;
29897
+ let result = null;
29898
+ try {
29899
+ const toolCallStartData = {
29900
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
29901
+ name: toolName,
29902
+ args: params,
29903
+ status: "started"
29904
+ };
29905
+ if (debug) {
29906
+ console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
29907
+ }
29908
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
29909
+ if (isSessionCancelled(toolSessionId)) {
29910
+ if (debug) {
29911
+ console.log(`Tool execution cancelled before start for ${toolSessionId}`);
29912
+ }
29913
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
29914
+ }
29915
+ result = await baseExecute(params);
29916
+ if (isSessionCancelled(toolSessionId)) {
29917
+ if (debug) {
29918
+ console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
29919
+ }
29920
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
29921
+ }
29922
+ } catch (error2) {
29923
+ executionError = error2;
29924
+ if (debug) {
29925
+ console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
29926
+ }
29927
+ }
29928
+ if (executionError) {
29929
+ const toolCallErrorData = {
29930
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
29931
+ name: toolName,
29932
+ args: params,
29933
+ error: executionError.message || "Unknown error",
29934
+ status: "error"
29935
+ };
29936
+ if (debug) {
29937
+ console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
29938
+ }
29939
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
29940
+ throw executionError;
29941
+ } else {
29942
+ if (isSessionCancelled(toolSessionId)) {
29943
+ if (process.env.DEBUG === "1") {
29944
+ console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
29945
+ }
29946
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
29947
+ }
29948
+ const toolCallData = {
29949
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
29950
+ name: toolName,
29951
+ args: params,
29952
+ // Safely preview result
29953
+ resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
29954
+ status: "completed"
29955
+ };
29956
+ if (debug) {
29957
+ console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
29958
+ }
29959
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
29960
+ return result;
29961
+ }
29962
+ }
29963
+ };
29964
+ };
29965
+ listFilesTool = {
29966
+ execute: async (params) => {
29967
+ const { directory = ".", workingDirectory } = params;
29968
+ const baseCwd = workingDirectory || process.cwd();
29969
+ const secureBaseDir = import_path8.default.resolve(baseCwd);
29970
+ const targetDir = import_path8.default.resolve(secureBaseDir, directory);
29971
+ if (!targetDir.startsWith(secureBaseDir + import_path8.default.sep) && targetDir !== secureBaseDir) {
29972
+ throw new Error("Path traversal attempt detected. Access denied.");
29973
+ }
29974
+ const debug = process.env.DEBUG === "1";
29975
+ if (debug) {
29976
+ console.log(`[DEBUG] Listing files in directory: ${targetDir}`);
29977
+ }
29978
+ try {
29979
+ const files = await import_fs5.promises.readdir(targetDir, { withFileTypes: true });
29980
+ const formatSize = (size) => {
29981
+ if (size < 1024) return `${size}B`;
29982
+ if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}K`;
29983
+ if (size < 1024 * 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}M`;
29984
+ return `${(size / (1024 * 1024 * 1024)).toFixed(1)}G`;
29985
+ };
29986
+ const entries = await Promise.all(files.map(async (file) => {
29987
+ const isDirectory = file.isDirectory();
29988
+ const fullPath = import_path8.default.join(targetDir, file.name);
29989
+ let size = 0;
29990
+ try {
29991
+ const stats = await import_fs5.promises.stat(fullPath);
29992
+ size = stats.size;
29993
+ } catch (statError) {
29994
+ if (debug) {
29995
+ console.log(`[DEBUG] Could not stat file ${file.name}:`, statError.message);
29996
+ }
29997
+ }
29998
+ return {
29999
+ name: file.name,
30000
+ isDirectory,
30001
+ size
30002
+ };
30003
+ }));
30004
+ entries.sort((a3, b3) => {
30005
+ if (a3.isDirectory && !b3.isDirectory) return -1;
30006
+ if (!a3.isDirectory && b3.isDirectory) return 1;
30007
+ return a3.name.localeCompare(b3.name);
30008
+ });
30009
+ const formatted = entries.map((entry) => {
30010
+ const type = entry.isDirectory ? "dir " : "file";
30011
+ const sizeStr = formatSize(entry.size).padStart(8);
30012
+ return `${type} ${sizeStr} ${entry.name}`;
30013
+ });
30014
+ if (debug) {
30015
+ console.log(`[DEBUG] Found ${entries.length} files/directories in ${targetDir}`);
30016
+ }
30017
+ const header = `${targetDir}:
30018
+ `;
30019
+ const output = header + formatted.join("\n");
30020
+ return output;
30021
+ } catch (error2) {
30022
+ throw new Error(`Failed to list files: ${error2.message}`);
30023
+ }
30024
+ }
30025
+ };
30026
+ searchFilesTool = {
30027
+ execute: async (params) => {
30028
+ const { pattern, directory = ".", recursive = true, workingDirectory } = params;
30029
+ if (!pattern) {
30030
+ throw new Error("Pattern is required for file search");
30031
+ }
30032
+ const baseCwd = workingDirectory || process.cwd();
30033
+ const secureBaseDir = import_path8.default.resolve(baseCwd);
30034
+ const targetDir = import_path8.default.resolve(secureBaseDir, directory);
30035
+ if (!targetDir.startsWith(secureBaseDir + import_path8.default.sep) && targetDir !== secureBaseDir) {
30036
+ throw new Error("Path traversal attempt detected. Access denied.");
30037
+ }
30038
+ if (pattern.includes("**/**") || pattern.split("*").length > 10) {
30039
+ throw new Error("Pattern too complex. Please use a simpler glob pattern.");
30040
+ }
30041
+ try {
30042
+ const options = {
30043
+ cwd: targetDir,
30044
+ ignore: ["node_modules/**", ".git/**"],
30045
+ absolute: false
30046
+ };
30047
+ if (!recursive) {
30048
+ options.deep = 1;
30049
+ }
30050
+ const timeoutPromise = new Promise((_2, reject2) => {
30051
+ setTimeout(() => reject2(new Error("Search operation timed out after 10 seconds")), 1e4);
30052
+ });
30053
+ const files = await Promise.race([
30054
+ (0, import_glob.glob)(pattern, options),
30055
+ timeoutPromise
30056
+ ]);
30057
+ const maxResults = 1e3;
30058
+ if (files.length > maxResults) {
30059
+ return files.slice(0, maxResults);
30060
+ }
30061
+ return files;
30062
+ } catch (error2) {
30063
+ throw new Error(`Failed to search files: ${error2.message}`);
30064
+ }
30065
+ }
30066
+ };
30067
+ listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
30068
+ searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
30069
+ }
30070
+ });
30071
+
29810
30072
  // src/index.js
29811
30073
  var init_index = __esm({
29812
30074
  "src/index.js"() {
@@ -29824,6 +30086,7 @@ var init_index = __esm({
29824
30086
  init_bash();
29825
30087
  init_ProbeAgent();
29826
30088
  init_simpleTelemetry();
30089
+ init_probeTool();
29827
30090
  }
29828
30091
  });
29829
30092
 
@@ -29946,12 +30209,12 @@ function parseXmlToolCallWithThinking(xmlString, validTools) {
29946
30209
  }
29947
30210
  return parseXmlToolCall(cleanedXmlString, validTools);
29948
30211
  }
29949
- var import_crypto3, implementToolDefinition, listFilesToolDefinition, searchFilesToolDefinition;
30212
+ var import_crypto4, implementToolDefinition, listFilesToolDefinition, searchFilesToolDefinition;
29950
30213
  var init_tools2 = __esm({
29951
30214
  "src/agent/tools.js"() {
29952
30215
  "use strict";
29953
30216
  init_index();
29954
- import_crypto3 = require("crypto");
30217
+ import_crypto4 = require("crypto");
29955
30218
  init_xmlParsingUtils();
29956
30219
  implementToolDefinition = `
29957
30220
  ## implement
@@ -30030,216 +30293,6 @@ User: Find all markdown files in the docs directory, but only at the top level.
30030
30293
  }
30031
30294
  });
30032
30295
 
30033
- // src/agent/probeTool.js
30034
- function isSessionCancelled(sessionId) {
30035
- return activeToolExecutions.get(sessionId)?.cancelled || false;
30036
- }
30037
- function registerToolExecution(sessionId) {
30038
- if (!sessionId) return;
30039
- if (!activeToolExecutions.has(sessionId)) {
30040
- activeToolExecutions.set(sessionId, { cancelled: false });
30041
- } else {
30042
- activeToolExecutions.get(sessionId).cancelled = false;
30043
- }
30044
- }
30045
- function clearToolExecutionData(sessionId) {
30046
- if (!sessionId) return;
30047
- if (activeToolExecutions.has(sessionId)) {
30048
- activeToolExecutions.delete(sessionId);
30049
- if (process.env.DEBUG === "1") {
30050
- console.log(`Cleared tool execution data for session: ${sessionId}`);
30051
- }
30052
- }
30053
- }
30054
- function createWrappedTools(baseTools) {
30055
- const wrappedTools = {};
30056
- if (baseTools.searchTool) {
30057
- wrappedTools.searchToolInstance = wrapToolWithEmitter(
30058
- baseTools.searchTool,
30059
- "search",
30060
- baseTools.searchTool.execute
30061
- );
30062
- }
30063
- if (baseTools.queryTool) {
30064
- wrappedTools.queryToolInstance = wrapToolWithEmitter(
30065
- baseTools.queryTool,
30066
- "query",
30067
- baseTools.queryTool.execute
30068
- );
30069
- }
30070
- if (baseTools.extractTool) {
30071
- wrappedTools.extractToolInstance = wrapToolWithEmitter(
30072
- baseTools.extractTool,
30073
- "extract",
30074
- baseTools.extractTool.execute
30075
- );
30076
- }
30077
- if (baseTools.delegateTool) {
30078
- wrappedTools.delegateToolInstance = wrapToolWithEmitter(
30079
- baseTools.delegateTool,
30080
- "delegate",
30081
- baseTools.delegateTool.execute
30082
- );
30083
- }
30084
- if (baseTools.bashTool) {
30085
- wrappedTools.bashToolInstance = wrapToolWithEmitter(
30086
- baseTools.bashTool,
30087
- "bash",
30088
- baseTools.bashTool.execute
30089
- );
30090
- }
30091
- return wrappedTools;
30092
- }
30093
- var import_child_process8, import_util6, import_crypto4, import_events, import_fs4, import_fs5, import_path8, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
30094
- var init_probeTool = __esm({
30095
- "src/agent/probeTool.js"() {
30096
- "use strict";
30097
- init_index();
30098
- import_child_process8 = require("child_process");
30099
- import_util6 = require("util");
30100
- import_crypto4 = require("crypto");
30101
- import_events = require("events");
30102
- import_fs4 = __toESM(require("fs"), 1);
30103
- import_fs5 = require("fs");
30104
- import_path8 = __toESM(require("path"), 1);
30105
- import_glob = require("glob");
30106
- toolCallEmitter = new import_events.EventEmitter();
30107
- activeToolExecutions = /* @__PURE__ */ new Map();
30108
- wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
30109
- return {
30110
- ...tool3,
30111
- // Spread schema, description etc.
30112
- execute: async (params) => {
30113
- const debug = process.env.DEBUG === "1";
30114
- const toolSessionId = params.sessionId || (0, import_crypto4.randomUUID)();
30115
- if (debug) {
30116
- console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
30117
- }
30118
- registerToolExecution(toolSessionId);
30119
- let executionError = null;
30120
- let result = null;
30121
- try {
30122
- const toolCallStartData = {
30123
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30124
- name: toolName,
30125
- args: params,
30126
- status: "started"
30127
- };
30128
- if (debug) {
30129
- console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
30130
- }
30131
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
30132
- if (isSessionCancelled(toolSessionId)) {
30133
- if (debug) {
30134
- console.log(`Tool execution cancelled before start for ${toolSessionId}`);
30135
- }
30136
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30137
- }
30138
- result = await baseExecute(params);
30139
- if (isSessionCancelled(toolSessionId)) {
30140
- if (debug) {
30141
- console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
30142
- }
30143
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30144
- }
30145
- } catch (error2) {
30146
- executionError = error2;
30147
- if (debug) {
30148
- console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
30149
- }
30150
- }
30151
- if (executionError) {
30152
- const toolCallErrorData = {
30153
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30154
- name: toolName,
30155
- args: params,
30156
- error: executionError.message || "Unknown error",
30157
- status: "error"
30158
- };
30159
- if (debug) {
30160
- console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
30161
- }
30162
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
30163
- throw executionError;
30164
- } else {
30165
- if (isSessionCancelled(toolSessionId)) {
30166
- if (process.env.DEBUG === "1") {
30167
- console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
30168
- }
30169
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30170
- }
30171
- const toolCallData = {
30172
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30173
- name: toolName,
30174
- args: params,
30175
- // Safely preview result
30176
- resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
30177
- status: "completed"
30178
- };
30179
- if (debug) {
30180
- console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
30181
- }
30182
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
30183
- return result;
30184
- }
30185
- }
30186
- };
30187
- };
30188
- listFilesTool = {
30189
- execute: async (params) => {
30190
- const { directory = ".", workingDirectory } = params;
30191
- const baseCwd = workingDirectory || process.cwd();
30192
- const secureBaseDir = import_path8.default.resolve(baseCwd);
30193
- const targetDir = import_path8.default.resolve(secureBaseDir, directory);
30194
- if (!targetDir.startsWith(secureBaseDir + import_path8.default.sep) && targetDir !== secureBaseDir) {
30195
- throw new Error("Path traversal attempt detected. Access denied.");
30196
- }
30197
- try {
30198
- const files = await listFilesByLevel({
30199
- directory: targetDir,
30200
- maxFiles: 100,
30201
- respectGitignore: !process.env.PROBE_NO_GITIGNORE || process.env.PROBE_NO_GITIGNORE === "",
30202
- cwd: secureBaseDir
30203
- });
30204
- return files;
30205
- } catch (error2) {
30206
- throw new Error(`Failed to list files: ${error2.message}`);
30207
- }
30208
- }
30209
- };
30210
- searchFilesTool = {
30211
- execute: async (params) => {
30212
- const { pattern, directory = ".", recursive = true, workingDirectory } = params;
30213
- if (!pattern) {
30214
- throw new Error("Pattern is required for file search");
30215
- }
30216
- const baseCwd = workingDirectory || process.cwd();
30217
- const secureBaseDir = import_path8.default.resolve(baseCwd);
30218
- const targetDir = import_path8.default.resolve(secureBaseDir, directory);
30219
- if (!targetDir.startsWith(secureBaseDir + import_path8.default.sep) && targetDir !== secureBaseDir) {
30220
- throw new Error("Path traversal attempt detected. Access denied.");
30221
- }
30222
- try {
30223
- const options = {
30224
- cwd: targetDir,
30225
- ignore: ["node_modules/**", ".git/**"],
30226
- absolute: false
30227
- };
30228
- if (!recursive) {
30229
- options.deep = 1;
30230
- }
30231
- const files = await (0, import_glob.glob)(pattern, options);
30232
- return files;
30233
- } catch (error2) {
30234
- throw new Error(`Failed to search files: ${error2.message}`);
30235
- }
30236
- }
30237
- };
30238
- listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
30239
- searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
30240
- }
30241
- });
30242
-
30243
30296
  // src/agent/mockProvider.js
30244
30297
  function createMockProvider() {
30245
30298
  return {
@@ -57632,8 +57685,8 @@ When presented with a broken Mermaid diagram, analyze it thoroughly and provide
57632
57685
  debug: this.options.debug,
57633
57686
  tracer: this.options.tracer,
57634
57687
  allowEdit: this.options.allowEdit,
57635
- maxIterations: 2,
57636
- // Limit mermaid fixing to 2 iterations to prevent long loops
57688
+ maxIterations: 10,
57689
+ // Allow more iterations for mermaid fixing to handle complex diagrams
57637
57690
  disableMermaidValidation: true
57638
57691
  // CRITICAL: Disable mermaid validation in nested agent to prevent infinite recursion
57639
57692
  });
@@ -58533,6 +58586,18 @@ var init_ProbeAgent = __esm({
58533
58586
  this.toolImplementations.bash = wrappedTools.bashToolInstance;
58534
58587
  }
58535
58588
  this.wrappedTools = wrappedTools;
58589
+ if (this.debug) {
58590
+ console.error("\n[DEBUG] ========================================");
58591
+ console.error("[DEBUG] ProbeAgent Tools Initialized");
58592
+ console.error("[DEBUG] Session ID:", this.sessionId);
58593
+ console.error("[DEBUG] Available tools:");
58594
+ for (const toolName of Object.keys(this.toolImplementations)) {
58595
+ console.error(`[DEBUG] - ${toolName}`);
58596
+ }
58597
+ console.error("[DEBUG] Allowed folders:", this.allowedFolders);
58598
+ console.error("[DEBUG] Outline mode:", this.outline);
58599
+ console.error("[DEBUG] ========================================\n");
58600
+ }
58536
58601
  }
58537
58602
  /**
58538
58603
  * Initialize the AI model based on available API keys and forced provider setting
@@ -59303,12 +59368,28 @@ You are working with a repository located at: ${searchDirectory}
59303
59368
  const { type } = parsedTool;
59304
59369
  if (type === "mcp" && this.mcpBridge && this.mcpBridge.isMcpTool(toolName)) {
59305
59370
  try {
59306
- if (this.debug) console.log(`[DEBUG] Executing MCP tool '${toolName}' with params:`, params);
59371
+ if (this.debug) {
59372
+ console.error(`
59373
+ [DEBUG] ========================================`);
59374
+ console.error(`[DEBUG] Executing MCP tool: ${toolName}`);
59375
+ console.error(`[DEBUG] Arguments:`);
59376
+ for (const [key, value] of Object.entries(params)) {
59377
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59378
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59379
+ }
59380
+ console.error(`[DEBUG] ========================================
59381
+ `);
59382
+ }
59307
59383
  const executionResult = await this.mcpBridge.mcpTools[toolName].execute(params);
59308
59384
  const toolResultContent = typeof executionResult === "string" ? executionResult : JSON.stringify(executionResult, null, 2);
59309
- const preview = createMessagePreview(toolResultContent);
59310
59385
  if (this.debug) {
59311
- console.log(`[DEBUG] MCP tool '${toolName}' executed successfully. Result preview: ${preview}`);
59386
+ const preview = toolResultContent.length > 500 ? toolResultContent.substring(0, 500) + "..." : toolResultContent;
59387
+ console.error(`[DEBUG] ========================================`);
59388
+ console.error(`[DEBUG] MCP tool '${toolName}' completed successfully`);
59389
+ console.error(`[DEBUG] Result preview:`);
59390
+ console.error(preview);
59391
+ console.error(`[DEBUG] ========================================
59392
+ `);
59312
59393
  }
59313
59394
  currentMessages.push({ role: "user", content: `<tool_result>
59314
59395
  ${toolResultContent}
@@ -59316,7 +59397,13 @@ ${toolResultContent}
59316
59397
  } catch (error2) {
59317
59398
  console.error(`Error executing MCP tool ${toolName}:`, error2);
59318
59399
  const toolResultContent = `Error executing MCP tool ${toolName}: ${error2.message}`;
59319
- if (this.debug) console.log(`[DEBUG] MCP tool '${toolName}' execution FAILED.`);
59400
+ if (this.debug) {
59401
+ console.error(`[DEBUG] ========================================`);
59402
+ console.error(`[DEBUG] MCP tool '${toolName}' failed with error:`);
59403
+ console.error(`[DEBUG] ${error2.message}`);
59404
+ console.error(`[DEBUG] ========================================
59405
+ `);
59406
+ }
59320
59407
  currentMessages.push({ role: "user", content: `<tool_result>
59321
59408
  ${toolResultContent}
59322
59409
  </tool_result>` });
@@ -59328,6 +59415,18 @@ ${toolResultContent}
59328
59415
  sessionId: this.sessionId,
59329
59416
  workingDirectory: this.allowedFolders && this.allowedFolders[0] || process.cwd()
59330
59417
  };
59418
+ if (this.debug) {
59419
+ console.error(`
59420
+ [DEBUG] ========================================`);
59421
+ console.error(`[DEBUG] Executing tool: ${toolName}`);
59422
+ console.error(`[DEBUG] Arguments:`);
59423
+ for (const [key, value] of Object.entries(params)) {
59424
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59425
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59426
+ }
59427
+ console.error(`[DEBUG] ========================================
59428
+ `);
59429
+ }
59331
59430
  this.events.emit("toolCall", {
59332
59431
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59333
59432
  name: toolName,
@@ -59369,6 +59468,15 @@ ${toolResultContent}
59369
59468
  } else {
59370
59469
  toolResult = await executeToolCall();
59371
59470
  }
59471
+ if (this.debug) {
59472
+ const resultPreview = typeof toolResult === "string" ? toolResult.length > 500 ? toolResult.substring(0, 500) + "..." : toolResult : toolResult ? JSON.stringify(toolResult, null, 2).substring(0, 500) + "..." : "No Result";
59473
+ console.error(`[DEBUG] ========================================`);
59474
+ console.error(`[DEBUG] Tool '${toolName}' completed successfully`);
59475
+ console.error(`[DEBUG] Result preview:`);
59476
+ console.error(resultPreview);
59477
+ console.error(`[DEBUG] ========================================
59478
+ `);
59479
+ }
59372
59480
  this.events.emit("toolCall", {
59373
59481
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59374
59482
  name: toolName,
@@ -59377,6 +59485,13 @@ ${toolResultContent}
59377
59485
  status: "completed"
59378
59486
  });
59379
59487
  } catch (toolError) {
59488
+ if (this.debug) {
59489
+ console.error(`[DEBUG] ========================================`);
59490
+ console.error(`[DEBUG] Tool '${toolName}' failed with error:`);
59491
+ console.error(`[DEBUG] ${toolError.message}`);
59492
+ console.error(`[DEBUG] ========================================
59493
+ `);
59494
+ }
59380
59495
  this.events.emit("toolCall", {
59381
59496
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59382
59497
  name: toolName,
@@ -59426,6 +59541,16 @@ Error: Unknown tool '${toolName}'. Available tools: ${allAvailableTools.join(",
59426
59541
  }
59427
59542
  }
59428
59543
  } else {
59544
+ const hasMermaidCodeBlock = /```mermaid\s*\n[\s\S]*?\n```/.test(assistantResponseContent);
59545
+ const hasNoSchemaOrTools = !options.schema && validTools.length === 0;
59546
+ if (hasMermaidCodeBlock && hasNoSchemaOrTools) {
59547
+ finalResult = assistantResponseContent;
59548
+ completionAttempted = true;
59549
+ if (this.debug) {
59550
+ console.error(`[DEBUG] Accepting mermaid code block as valid completion (no schema, no tools)`);
59551
+ }
59552
+ break;
59553
+ }
59429
59554
  currentMessages.push({ role: "assistant", content: assistantResponseContent });
59430
59555
  let reminderContent;
59431
59556
  if (options.schema) {