@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.
@@ -30026,6 +30026,268 @@ var init_simpleTelemetry = __esm({
30026
30026
  }
30027
30027
  });
30028
30028
 
30029
+ // src/agent/probeTool.js
30030
+ import { exec as exec6 } from "child_process";
30031
+ import { promisify as promisify6 } from "util";
30032
+ import { randomUUID as randomUUID2 } from "crypto";
30033
+ import { EventEmitter } from "events";
30034
+ import fs5 from "fs";
30035
+ import { promises as fsPromises } from "fs";
30036
+ import path5 from "path";
30037
+ import { glob } from "glob";
30038
+ function isSessionCancelled(sessionId) {
30039
+ return activeToolExecutions.get(sessionId)?.cancelled || false;
30040
+ }
30041
+ function registerToolExecution(sessionId) {
30042
+ if (!sessionId) return;
30043
+ if (!activeToolExecutions.has(sessionId)) {
30044
+ activeToolExecutions.set(sessionId, { cancelled: false });
30045
+ } else {
30046
+ activeToolExecutions.get(sessionId).cancelled = false;
30047
+ }
30048
+ }
30049
+ function clearToolExecutionData(sessionId) {
30050
+ if (!sessionId) return;
30051
+ if (activeToolExecutions.has(sessionId)) {
30052
+ activeToolExecutions.delete(sessionId);
30053
+ if (process.env.DEBUG === "1") {
30054
+ console.log(`Cleared tool execution data for session: ${sessionId}`);
30055
+ }
30056
+ }
30057
+ }
30058
+ function createWrappedTools(baseTools) {
30059
+ const wrappedTools = {};
30060
+ if (baseTools.searchTool) {
30061
+ wrappedTools.searchToolInstance = wrapToolWithEmitter(
30062
+ baseTools.searchTool,
30063
+ "search",
30064
+ baseTools.searchTool.execute
30065
+ );
30066
+ }
30067
+ if (baseTools.queryTool) {
30068
+ wrappedTools.queryToolInstance = wrapToolWithEmitter(
30069
+ baseTools.queryTool,
30070
+ "query",
30071
+ baseTools.queryTool.execute
30072
+ );
30073
+ }
30074
+ if (baseTools.extractTool) {
30075
+ wrappedTools.extractToolInstance = wrapToolWithEmitter(
30076
+ baseTools.extractTool,
30077
+ "extract",
30078
+ baseTools.extractTool.execute
30079
+ );
30080
+ }
30081
+ if (baseTools.delegateTool) {
30082
+ wrappedTools.delegateToolInstance = wrapToolWithEmitter(
30083
+ baseTools.delegateTool,
30084
+ "delegate",
30085
+ baseTools.delegateTool.execute
30086
+ );
30087
+ }
30088
+ if (baseTools.bashTool) {
30089
+ wrappedTools.bashToolInstance = wrapToolWithEmitter(
30090
+ baseTools.bashTool,
30091
+ "bash",
30092
+ baseTools.bashTool.execute
30093
+ );
30094
+ }
30095
+ return wrappedTools;
30096
+ }
30097
+ var toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
30098
+ var init_probeTool = __esm({
30099
+ "src/agent/probeTool.js"() {
30100
+ "use strict";
30101
+ init_index();
30102
+ toolCallEmitter = new EventEmitter();
30103
+ activeToolExecutions = /* @__PURE__ */ new Map();
30104
+ wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
30105
+ return {
30106
+ ...tool3,
30107
+ // Spread schema, description etc.
30108
+ execute: async (params) => {
30109
+ const debug = process.env.DEBUG === "1";
30110
+ const toolSessionId = params.sessionId || randomUUID2();
30111
+ if (debug) {
30112
+ console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
30113
+ }
30114
+ registerToolExecution(toolSessionId);
30115
+ let executionError = null;
30116
+ let result = null;
30117
+ try {
30118
+ const toolCallStartData = {
30119
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30120
+ name: toolName,
30121
+ args: params,
30122
+ status: "started"
30123
+ };
30124
+ if (debug) {
30125
+ console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
30126
+ }
30127
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
30128
+ if (isSessionCancelled(toolSessionId)) {
30129
+ if (debug) {
30130
+ console.log(`Tool execution cancelled before start for ${toolSessionId}`);
30131
+ }
30132
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30133
+ }
30134
+ result = await baseExecute(params);
30135
+ if (isSessionCancelled(toolSessionId)) {
30136
+ if (debug) {
30137
+ console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
30138
+ }
30139
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30140
+ }
30141
+ } catch (error2) {
30142
+ executionError = error2;
30143
+ if (debug) {
30144
+ console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
30145
+ }
30146
+ }
30147
+ if (executionError) {
30148
+ const toolCallErrorData = {
30149
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30150
+ name: toolName,
30151
+ args: params,
30152
+ error: executionError.message || "Unknown error",
30153
+ status: "error"
30154
+ };
30155
+ if (debug) {
30156
+ console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
30157
+ }
30158
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
30159
+ throw executionError;
30160
+ } else {
30161
+ if (isSessionCancelled(toolSessionId)) {
30162
+ if (process.env.DEBUG === "1") {
30163
+ console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
30164
+ }
30165
+ throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30166
+ }
30167
+ const toolCallData = {
30168
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30169
+ name: toolName,
30170
+ args: params,
30171
+ // Safely preview result
30172
+ resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
30173
+ status: "completed"
30174
+ };
30175
+ if (debug) {
30176
+ console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
30177
+ }
30178
+ toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
30179
+ return result;
30180
+ }
30181
+ }
30182
+ };
30183
+ };
30184
+ listFilesTool = {
30185
+ execute: async (params) => {
30186
+ const { directory = ".", workingDirectory } = params;
30187
+ const baseCwd = workingDirectory || process.cwd();
30188
+ const secureBaseDir = path5.resolve(baseCwd);
30189
+ const targetDir = path5.resolve(secureBaseDir, directory);
30190
+ if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
30191
+ throw new Error("Path traversal attempt detected. Access denied.");
30192
+ }
30193
+ const debug = process.env.DEBUG === "1";
30194
+ if (debug) {
30195
+ console.log(`[DEBUG] Listing files in directory: ${targetDir}`);
30196
+ }
30197
+ try {
30198
+ const files = await fsPromises.readdir(targetDir, { withFileTypes: true });
30199
+ const formatSize = (size) => {
30200
+ if (size < 1024) return `${size}B`;
30201
+ if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)}K`;
30202
+ if (size < 1024 * 1024 * 1024) return `${(size / (1024 * 1024)).toFixed(1)}M`;
30203
+ return `${(size / (1024 * 1024 * 1024)).toFixed(1)}G`;
30204
+ };
30205
+ const entries = await Promise.all(files.map(async (file) => {
30206
+ const isDirectory = file.isDirectory();
30207
+ const fullPath = path5.join(targetDir, file.name);
30208
+ let size = 0;
30209
+ try {
30210
+ const stats = await fsPromises.stat(fullPath);
30211
+ size = stats.size;
30212
+ } catch (statError) {
30213
+ if (debug) {
30214
+ console.log(`[DEBUG] Could not stat file ${file.name}:`, statError.message);
30215
+ }
30216
+ }
30217
+ return {
30218
+ name: file.name,
30219
+ isDirectory,
30220
+ size
30221
+ };
30222
+ }));
30223
+ entries.sort((a3, b3) => {
30224
+ if (a3.isDirectory && !b3.isDirectory) return -1;
30225
+ if (!a3.isDirectory && b3.isDirectory) return 1;
30226
+ return a3.name.localeCompare(b3.name);
30227
+ });
30228
+ const formatted = entries.map((entry) => {
30229
+ const type = entry.isDirectory ? "dir " : "file";
30230
+ const sizeStr = formatSize(entry.size).padStart(8);
30231
+ return `${type} ${sizeStr} ${entry.name}`;
30232
+ });
30233
+ if (debug) {
30234
+ console.log(`[DEBUG] Found ${entries.length} files/directories in ${targetDir}`);
30235
+ }
30236
+ const header = `${targetDir}:
30237
+ `;
30238
+ const output = header + formatted.join("\n");
30239
+ return output;
30240
+ } catch (error2) {
30241
+ throw new Error(`Failed to list files: ${error2.message}`);
30242
+ }
30243
+ }
30244
+ };
30245
+ searchFilesTool = {
30246
+ execute: async (params) => {
30247
+ const { pattern, directory = ".", recursive = true, workingDirectory } = params;
30248
+ if (!pattern) {
30249
+ throw new Error("Pattern is required for file search");
30250
+ }
30251
+ const baseCwd = workingDirectory || process.cwd();
30252
+ const secureBaseDir = path5.resolve(baseCwd);
30253
+ const targetDir = path5.resolve(secureBaseDir, directory);
30254
+ if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
30255
+ throw new Error("Path traversal attempt detected. Access denied.");
30256
+ }
30257
+ if (pattern.includes("**/**") || pattern.split("*").length > 10) {
30258
+ throw new Error("Pattern too complex. Please use a simpler glob pattern.");
30259
+ }
30260
+ try {
30261
+ const options = {
30262
+ cwd: targetDir,
30263
+ ignore: ["node_modules/**", ".git/**"],
30264
+ absolute: false
30265
+ };
30266
+ if (!recursive) {
30267
+ options.deep = 1;
30268
+ }
30269
+ const timeoutPromise = new Promise((_2, reject2) => {
30270
+ setTimeout(() => reject2(new Error("Search operation timed out after 10 seconds")), 1e4);
30271
+ });
30272
+ const files = await Promise.race([
30273
+ glob(pattern, options),
30274
+ timeoutPromise
30275
+ ]);
30276
+ const maxResults = 1e3;
30277
+ if (files.length > maxResults) {
30278
+ return files.slice(0, maxResults);
30279
+ }
30280
+ return files;
30281
+ } catch (error2) {
30282
+ throw new Error(`Failed to search files: ${error2.message}`);
30283
+ }
30284
+ }
30285
+ };
30286
+ listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
30287
+ searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
30288
+ }
30289
+ });
30290
+
30029
30291
  // src/index.js
30030
30292
  var init_index = __esm({
30031
30293
  "src/index.js"() {
@@ -30043,6 +30305,7 @@ var init_index = __esm({
30043
30305
  init_bash();
30044
30306
  init_ProbeAgent();
30045
30307
  init_simpleTelemetry();
30308
+ init_probeTool();
30046
30309
  }
30047
30310
  });
30048
30311
 
@@ -30146,7 +30409,7 @@ var init_xmlParsingUtils = __esm({
30146
30409
  });
30147
30410
 
30148
30411
  // src/agent/tools.js
30149
- import { randomUUID as randomUUID2 } from "crypto";
30412
+ import { randomUUID as randomUUID3 } from "crypto";
30150
30413
  function createTools(configOptions) {
30151
30414
  const tools2 = {
30152
30415
  searchTool: searchTool(configOptions),
@@ -30249,216 +30512,6 @@ User: Find all markdown files in the docs directory, but only at the top level.
30249
30512
  }
30250
30513
  });
30251
30514
 
30252
- // src/agent/probeTool.js
30253
- import { exec as exec6 } from "child_process";
30254
- import { promisify as promisify6 } from "util";
30255
- import { randomUUID as randomUUID3 } from "crypto";
30256
- import { EventEmitter } from "events";
30257
- import fs5 from "fs";
30258
- import { promises as fsPromises } from "fs";
30259
- import path5 from "path";
30260
- import { glob } from "glob";
30261
- function isSessionCancelled(sessionId) {
30262
- return activeToolExecutions.get(sessionId)?.cancelled || false;
30263
- }
30264
- function registerToolExecution(sessionId) {
30265
- if (!sessionId) return;
30266
- if (!activeToolExecutions.has(sessionId)) {
30267
- activeToolExecutions.set(sessionId, { cancelled: false });
30268
- } else {
30269
- activeToolExecutions.get(sessionId).cancelled = false;
30270
- }
30271
- }
30272
- function clearToolExecutionData(sessionId) {
30273
- if (!sessionId) return;
30274
- if (activeToolExecutions.has(sessionId)) {
30275
- activeToolExecutions.delete(sessionId);
30276
- if (process.env.DEBUG === "1") {
30277
- console.log(`Cleared tool execution data for session: ${sessionId}`);
30278
- }
30279
- }
30280
- }
30281
- function createWrappedTools(baseTools) {
30282
- const wrappedTools = {};
30283
- if (baseTools.searchTool) {
30284
- wrappedTools.searchToolInstance = wrapToolWithEmitter(
30285
- baseTools.searchTool,
30286
- "search",
30287
- baseTools.searchTool.execute
30288
- );
30289
- }
30290
- if (baseTools.queryTool) {
30291
- wrappedTools.queryToolInstance = wrapToolWithEmitter(
30292
- baseTools.queryTool,
30293
- "query",
30294
- baseTools.queryTool.execute
30295
- );
30296
- }
30297
- if (baseTools.extractTool) {
30298
- wrappedTools.extractToolInstance = wrapToolWithEmitter(
30299
- baseTools.extractTool,
30300
- "extract",
30301
- baseTools.extractTool.execute
30302
- );
30303
- }
30304
- if (baseTools.delegateTool) {
30305
- wrappedTools.delegateToolInstance = wrapToolWithEmitter(
30306
- baseTools.delegateTool,
30307
- "delegate",
30308
- baseTools.delegateTool.execute
30309
- );
30310
- }
30311
- if (baseTools.bashTool) {
30312
- wrappedTools.bashToolInstance = wrapToolWithEmitter(
30313
- baseTools.bashTool,
30314
- "bash",
30315
- baseTools.bashTool.execute
30316
- );
30317
- }
30318
- return wrappedTools;
30319
- }
30320
- var toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
30321
- var init_probeTool = __esm({
30322
- "src/agent/probeTool.js"() {
30323
- "use strict";
30324
- init_index();
30325
- toolCallEmitter = new EventEmitter();
30326
- activeToolExecutions = /* @__PURE__ */ new Map();
30327
- wrapToolWithEmitter = (tool3, toolName, baseExecute) => {
30328
- return {
30329
- ...tool3,
30330
- // Spread schema, description etc.
30331
- execute: async (params) => {
30332
- const debug = process.env.DEBUG === "1";
30333
- const toolSessionId = params.sessionId || randomUUID3();
30334
- if (debug) {
30335
- console.log(`[DEBUG] probeTool: Executing ${toolName} for session ${toolSessionId}`);
30336
- }
30337
- registerToolExecution(toolSessionId);
30338
- let executionError = null;
30339
- let result = null;
30340
- try {
30341
- const toolCallStartData = {
30342
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30343
- name: toolName,
30344
- args: params,
30345
- status: "started"
30346
- };
30347
- if (debug) {
30348
- console.log(`[DEBUG] probeTool: Emitting toolCallStart:${toolSessionId}`);
30349
- }
30350
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallStartData);
30351
- if (isSessionCancelled(toolSessionId)) {
30352
- if (debug) {
30353
- console.log(`Tool execution cancelled before start for ${toolSessionId}`);
30354
- }
30355
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30356
- }
30357
- result = await baseExecute(params);
30358
- if (isSessionCancelled(toolSessionId)) {
30359
- if (debug) {
30360
- console.log(`Tool execution cancelled after completion for ${toolSessionId}`);
30361
- }
30362
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30363
- }
30364
- } catch (error2) {
30365
- executionError = error2;
30366
- if (debug) {
30367
- console.error(`[DEBUG] probeTool: Error in ${toolName}:`, error2);
30368
- }
30369
- }
30370
- if (executionError) {
30371
- const toolCallErrorData = {
30372
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30373
- name: toolName,
30374
- args: params,
30375
- error: executionError.message || "Unknown error",
30376
- status: "error"
30377
- };
30378
- if (debug) {
30379
- console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (error)`);
30380
- }
30381
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallErrorData);
30382
- throw executionError;
30383
- } else {
30384
- if (isSessionCancelled(toolSessionId)) {
30385
- if (process.env.DEBUG === "1") {
30386
- console.log(`Tool execution finished but session was cancelled for ${toolSessionId}`);
30387
- }
30388
- throw new Error(`Tool execution cancelled for session ${toolSessionId}`);
30389
- }
30390
- const toolCallData = {
30391
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
30392
- name: toolName,
30393
- args: params,
30394
- // Safely preview result
30395
- resultPreview: typeof result === "string" ? result.length > 200 ? result.substring(0, 200) + "..." : result : result ? JSON.stringify(result).substring(0, 200) + "..." : "No Result",
30396
- status: "completed"
30397
- };
30398
- if (debug) {
30399
- console.log(`[DEBUG] probeTool: Emitting toolCall:${toolSessionId} (completed)`);
30400
- }
30401
- toolCallEmitter.emit(`toolCall:${toolSessionId}`, toolCallData);
30402
- return result;
30403
- }
30404
- }
30405
- };
30406
- };
30407
- listFilesTool = {
30408
- execute: async (params) => {
30409
- const { directory = ".", workingDirectory } = params;
30410
- const baseCwd = workingDirectory || process.cwd();
30411
- const secureBaseDir = path5.resolve(baseCwd);
30412
- const targetDir = path5.resolve(secureBaseDir, directory);
30413
- if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
30414
- throw new Error("Path traversal attempt detected. Access denied.");
30415
- }
30416
- try {
30417
- const files = await listFilesByLevel({
30418
- directory: targetDir,
30419
- maxFiles: 100,
30420
- respectGitignore: !process.env.PROBE_NO_GITIGNORE || process.env.PROBE_NO_GITIGNORE === "",
30421
- cwd: secureBaseDir
30422
- });
30423
- return files;
30424
- } catch (error2) {
30425
- throw new Error(`Failed to list files: ${error2.message}`);
30426
- }
30427
- }
30428
- };
30429
- searchFilesTool = {
30430
- execute: async (params) => {
30431
- const { pattern, directory = ".", recursive = true, workingDirectory } = params;
30432
- if (!pattern) {
30433
- throw new Error("Pattern is required for file search");
30434
- }
30435
- const baseCwd = workingDirectory || process.cwd();
30436
- const secureBaseDir = path5.resolve(baseCwd);
30437
- const targetDir = path5.resolve(secureBaseDir, directory);
30438
- if (!targetDir.startsWith(secureBaseDir + path5.sep) && targetDir !== secureBaseDir) {
30439
- throw new Error("Path traversal attempt detected. Access denied.");
30440
- }
30441
- try {
30442
- const options = {
30443
- cwd: targetDir,
30444
- ignore: ["node_modules/**", ".git/**"],
30445
- absolute: false
30446
- };
30447
- if (!recursive) {
30448
- options.deep = 1;
30449
- }
30450
- const files = await glob(pattern, options);
30451
- return files;
30452
- } catch (error2) {
30453
- throw new Error(`Failed to search files: ${error2.message}`);
30454
- }
30455
- }
30456
- };
30457
- listFilesToolInstance = wrapToolWithEmitter(listFilesTool, "listFiles", listFilesTool.execute);
30458
- searchFilesToolInstance = wrapToolWithEmitter(searchFilesTool, "searchFiles", searchFilesTool.execute);
30459
- }
30460
- });
30461
-
30462
30515
  // src/agent/mockProvider.js
30463
30516
  function createMockProvider() {
30464
30517
  return {
@@ -57910,8 +57963,8 @@ When presented with a broken Mermaid diagram, analyze it thoroughly and provide
57910
57963
  debug: this.options.debug,
57911
57964
  tracer: this.options.tracer,
57912
57965
  allowEdit: this.options.allowEdit,
57913
- maxIterations: 2,
57914
- // Limit mermaid fixing to 2 iterations to prevent long loops
57966
+ maxIterations: 10,
57967
+ // Allow more iterations for mermaid fixing to handle complex diagrams
57915
57968
  disableMermaidValidation: true
57916
57969
  // CRITICAL: Disable mermaid validation in nested agent to prevent infinite recursion
57917
57970
  });
@@ -58811,6 +58864,18 @@ var init_ProbeAgent = __esm({
58811
58864
  this.toolImplementations.bash = wrappedTools.bashToolInstance;
58812
58865
  }
58813
58866
  this.wrappedTools = wrappedTools;
58867
+ if (this.debug) {
58868
+ console.error("\n[DEBUG] ========================================");
58869
+ console.error("[DEBUG] ProbeAgent Tools Initialized");
58870
+ console.error("[DEBUG] Session ID:", this.sessionId);
58871
+ console.error("[DEBUG] Available tools:");
58872
+ for (const toolName of Object.keys(this.toolImplementations)) {
58873
+ console.error(`[DEBUG] - ${toolName}`);
58874
+ }
58875
+ console.error("[DEBUG] Allowed folders:", this.allowedFolders);
58876
+ console.error("[DEBUG] Outline mode:", this.outline);
58877
+ console.error("[DEBUG] ========================================\n");
58878
+ }
58814
58879
  }
58815
58880
  /**
58816
58881
  * Initialize the AI model based on available API keys and forced provider setting
@@ -59581,12 +59646,28 @@ You are working with a repository located at: ${searchDirectory}
59581
59646
  const { type } = parsedTool;
59582
59647
  if (type === "mcp" && this.mcpBridge && this.mcpBridge.isMcpTool(toolName)) {
59583
59648
  try {
59584
- if (this.debug) console.log(`[DEBUG] Executing MCP tool '${toolName}' with params:`, params);
59649
+ if (this.debug) {
59650
+ console.error(`
59651
+ [DEBUG] ========================================`);
59652
+ console.error(`[DEBUG] Executing MCP tool: ${toolName}`);
59653
+ console.error(`[DEBUG] Arguments:`);
59654
+ for (const [key, value] of Object.entries(params)) {
59655
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59656
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59657
+ }
59658
+ console.error(`[DEBUG] ========================================
59659
+ `);
59660
+ }
59585
59661
  const executionResult = await this.mcpBridge.mcpTools[toolName].execute(params);
59586
59662
  const toolResultContent = typeof executionResult === "string" ? executionResult : JSON.stringify(executionResult, null, 2);
59587
- const preview = createMessagePreview(toolResultContent);
59588
59663
  if (this.debug) {
59589
- console.log(`[DEBUG] MCP tool '${toolName}' executed successfully. Result preview: ${preview}`);
59664
+ const preview = toolResultContent.length > 500 ? toolResultContent.substring(0, 500) + "..." : toolResultContent;
59665
+ console.error(`[DEBUG] ========================================`);
59666
+ console.error(`[DEBUG] MCP tool '${toolName}' completed successfully`);
59667
+ console.error(`[DEBUG] Result preview:`);
59668
+ console.error(preview);
59669
+ console.error(`[DEBUG] ========================================
59670
+ `);
59590
59671
  }
59591
59672
  currentMessages.push({ role: "user", content: `<tool_result>
59592
59673
  ${toolResultContent}
@@ -59594,7 +59675,13 @@ ${toolResultContent}
59594
59675
  } catch (error2) {
59595
59676
  console.error(`Error executing MCP tool ${toolName}:`, error2);
59596
59677
  const toolResultContent = `Error executing MCP tool ${toolName}: ${error2.message}`;
59597
- if (this.debug) console.log(`[DEBUG] MCP tool '${toolName}' execution FAILED.`);
59678
+ if (this.debug) {
59679
+ console.error(`[DEBUG] ========================================`);
59680
+ console.error(`[DEBUG] MCP tool '${toolName}' failed with error:`);
59681
+ console.error(`[DEBUG] ${error2.message}`);
59682
+ console.error(`[DEBUG] ========================================
59683
+ `);
59684
+ }
59598
59685
  currentMessages.push({ role: "user", content: `<tool_result>
59599
59686
  ${toolResultContent}
59600
59687
  </tool_result>` });
@@ -59606,6 +59693,18 @@ ${toolResultContent}
59606
59693
  sessionId: this.sessionId,
59607
59694
  workingDirectory: this.allowedFolders && this.allowedFolders[0] || process.cwd()
59608
59695
  };
59696
+ if (this.debug) {
59697
+ console.error(`
59698
+ [DEBUG] ========================================`);
59699
+ console.error(`[DEBUG] Executing tool: ${toolName}`);
59700
+ console.error(`[DEBUG] Arguments:`);
59701
+ for (const [key, value] of Object.entries(params)) {
59702
+ const displayValue = typeof value === "string" && value.length > 100 ? value.substring(0, 100) + "..." : value;
59703
+ console.error(`[DEBUG] ${key}: ${JSON.stringify(displayValue)}`);
59704
+ }
59705
+ console.error(`[DEBUG] ========================================
59706
+ `);
59707
+ }
59609
59708
  this.events.emit("toolCall", {
59610
59709
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59611
59710
  name: toolName,
@@ -59647,6 +59746,15 @@ ${toolResultContent}
59647
59746
  } else {
59648
59747
  toolResult = await executeToolCall();
59649
59748
  }
59749
+ if (this.debug) {
59750
+ const resultPreview = typeof toolResult === "string" ? toolResult.length > 500 ? toolResult.substring(0, 500) + "..." : toolResult : toolResult ? JSON.stringify(toolResult, null, 2).substring(0, 500) + "..." : "No Result";
59751
+ console.error(`[DEBUG] ========================================`);
59752
+ console.error(`[DEBUG] Tool '${toolName}' completed successfully`);
59753
+ console.error(`[DEBUG] Result preview:`);
59754
+ console.error(resultPreview);
59755
+ console.error(`[DEBUG] ========================================
59756
+ `);
59757
+ }
59650
59758
  this.events.emit("toolCall", {
59651
59759
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59652
59760
  name: toolName,
@@ -59655,6 +59763,13 @@ ${toolResultContent}
59655
59763
  status: "completed"
59656
59764
  });
59657
59765
  } catch (toolError) {
59766
+ if (this.debug) {
59767
+ console.error(`[DEBUG] ========================================`);
59768
+ console.error(`[DEBUG] Tool '${toolName}' failed with error:`);
59769
+ console.error(`[DEBUG] ${toolError.message}`);
59770
+ console.error(`[DEBUG] ========================================
59771
+ `);
59772
+ }
59658
59773
  this.events.emit("toolCall", {
59659
59774
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
59660
59775
  name: toolName,
@@ -59704,6 +59819,16 @@ Error: Unknown tool '${toolName}'. Available tools: ${allAvailableTools.join(",
59704
59819
  }
59705
59820
  }
59706
59821
  } else {
59822
+ const hasMermaidCodeBlock = /```mermaid\s*\n[\s\S]*?\n```/.test(assistantResponseContent);
59823
+ const hasNoSchemaOrTools = !options.schema && validTools.length === 0;
59824
+ if (hasMermaidCodeBlock && hasNoSchemaOrTools) {
59825
+ finalResult = assistantResponseContent;
59826
+ completionAttempted = true;
59827
+ if (this.debug) {
59828
+ console.error(`[DEBUG] Accepting mermaid code block as valid completion (no schema, no tools)`);
59829
+ }
59830
+ break;
59831
+ }
59707
59832
  currentMessages.push({ role: "assistant", content: assistantResponseContent });
59708
59833
  let reminderContent;
59709
59834
  if (options.schema) {