@probelabs/visor 0.1.78 → 0.1.80

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- process.env.VISOR_VERSION = '0.1.78';
3
- process.env.PROBE_VERSION = '0.6.0-rc120';
2
+ process.env.VISOR_VERSION = '0.1.80';
3
+ process.env.PROBE_VERSION = '0.6.0-rc122';
4
4
  /******/ (() => { // webpackBootstrap
5
5
  /******/ var __webpack_modules__ = ({
6
6
 
@@ -102520,21 +102520,30 @@ class CheckExecutionEngine {
102520
102520
  dependencyResults.set(depId, depResult);
102521
102521
  }
102522
102522
  }
102523
- // If any direct dependency failed (errors/critical or */error ruleIds), skip this check
102523
+ // If any direct dependency failed or was skipped, skip this check
102524
102524
  const directDeps = checkConfig.depends_on || [];
102525
102525
  const failedDeps = [];
102526
102526
  for (const depId of directDeps) {
102527
102527
  const depRes = results.get(depId);
102528
102528
  if (!depRes)
102529
102529
  continue;
102530
- // Only treat command provider execution/transform failures as dependency-fatal
102531
- const hasFatalCommandFailure = (depRes.issues || []).some(issue => {
102530
+ // Check if dependency was skipped
102531
+ const wasSkipped = (depRes.issues || []).some(issue => {
102532
102532
  const id = issue.ruleId || '';
102533
- return (id.endsWith('/command/execution_error') ||
102533
+ return id.endsWith('/__skipped');
102534
+ });
102535
+ // Check for fatal failures: command provider execution/transform failures and forEach iteration errors
102536
+ const hasFatalFailure = (depRes.issues || []).some(issue => {
102537
+ const id = issue.ruleId || '';
102538
+ return (id === 'command/execution_error' ||
102539
+ id.endsWith('/command/execution_error') ||
102540
+ id === 'command/transform_js_error' ||
102534
102541
  id.endsWith('/command/transform_js_error') ||
102535
- id.endsWith('/command/transform_error'));
102542
+ id === 'command/transform_error' ||
102543
+ id.endsWith('/command/transform_error') ||
102544
+ id.endsWith('/forEach/iteration_error'));
102536
102545
  });
102537
- if (hasFatalCommandFailure)
102546
+ if (wasSkipped || hasFatalFailure)
102538
102547
  failedDeps.push(depId);
102539
102548
  }
102540
102549
  if (failedDeps.length > 0) {
@@ -102606,8 +102615,8 @@ class CheckExecutionEngine {
102606
102615
  if (debug) {
102607
102616
  log(`🔄 Debug: Check "${checkName}" depends on forEach check "${forEachParentName}", executing ${forEachItems.length} times`);
102608
102617
  }
102609
- // Log forEach processing start
102610
- logger_1.logger.info(` Processing ${forEachItems.length} items...`);
102618
+ // Log forEach processing start (non-debug)
102619
+ logger_1.logger.info(` forEach: processing ${forEachItems.length} items from "${forEachParentName}"...`);
102611
102620
  const allIssues = [];
102612
102621
  const allOutputs = [];
102613
102622
  const aggregatedContents = [];
@@ -102678,8 +102687,19 @@ class CheckExecutionEngine {
102678
102687
  parent: forEachParentName,
102679
102688
  });
102680
102689
  // Record iteration completion
102690
+ // Check if this iteration had fatal errors
102691
+ const hadFatalError = (itemResult.issues || []).some(issue => {
102692
+ const id = issue.ruleId || '';
102693
+ return (id === 'command/execution_error' ||
102694
+ id.endsWith('/command/execution_error') ||
102695
+ id === 'command/transform_js_error' ||
102696
+ id.endsWith('/command/transform_js_error') ||
102697
+ id === 'command/transform_error' ||
102698
+ id.endsWith('/command/transform_error'));
102699
+ });
102681
102700
  const iterationDuration = (Date.now() - iterationStart) / 1000;
102682
- this.recordIterationComplete(checkName, iterationStart, true, itemResult.issues || [], itemResult.output);
102701
+ this.recordIterationComplete(checkName, iterationStart, !hadFatalError, // Success if no fatal errors
102702
+ itemResult.issues || [], itemResult.output);
102683
102703
  // Log iteration progress
102684
102704
  logger_1.logger.info(` ✔ ${itemIndex + 1}/${forEachItems.length} (${iterationDuration.toFixed(1)}s)`);
102685
102705
  return { index: itemIndex, itemResult };
@@ -102691,7 +102711,22 @@ class CheckExecutionEngine {
102691
102711
  const forEachResults = await this.executeWithLimitedParallelism(itemTasks, forEachConcurrency, false);
102692
102712
  for (const result of forEachResults) {
102693
102713
  if (result.status === 'rejected') {
102694
- throw result.reason;
102714
+ // Instead of throwing, record the failure and continue with other iterations
102715
+ const error = result.reason;
102716
+ const errorMessage = error instanceof Error ? error.message : String(error);
102717
+ // Create an error issue for this failed iteration
102718
+ allIssues.push({
102719
+ ruleId: `${checkName}/forEach/iteration_error`,
102720
+ severity: 'error',
102721
+ category: 'logic',
102722
+ message: `forEach iteration failed: ${errorMessage}`,
102723
+ file: '',
102724
+ line: 0,
102725
+ });
102726
+ if (debug) {
102727
+ log(`🔄 Debug: forEach iteration for check "${checkName}" failed: ${errorMessage}`);
102728
+ }
102729
+ continue;
102695
102730
  }
102696
102731
  // Skip results from skipped items (those that failed if condition)
102697
102732
  if (result.value.skipped) {
@@ -102749,7 +102784,18 @@ class CheckExecutionEngine {
102749
102784
  // Execute with retry/routing semantics
102750
102785
  finalResult = await this.executeWithRouting(checkName, checkConfig, provider, providerConfig, prInfo, dependencyResults, sessionInfo, config, dependencyGraph, debug, results);
102751
102786
  // Record normal (non-forEach) execution
102752
- this.recordIterationComplete(checkName, checkStartTime, true, finalResult.issues || [], finalResult.output);
102787
+ // Check if this check had fatal errors
102788
+ const hadFatalError = (finalResult.issues || []).some(issue => {
102789
+ const id = issue.ruleId || '';
102790
+ return (id === 'command/execution_error' ||
102791
+ id.endsWith('/command/execution_error') ||
102792
+ id === 'command/transform_js_error' ||
102793
+ id.endsWith('/command/transform_js_error') ||
102794
+ id === 'command/transform_error' ||
102795
+ id.endsWith('/command/transform_error'));
102796
+ });
102797
+ this.recordIterationComplete(checkName, checkStartTime, !hadFatalError, // Success if no fatal errors
102798
+ finalResult.issues || [], finalResult.output);
102753
102799
  if (checkConfig.forEach) {
102754
102800
  try {
102755
102801
  const finalResultWithOutput = finalResult;
@@ -102830,11 +102876,24 @@ class CheckExecutionEngine {
102830
102876
  const result = levelResults[i];
102831
102877
  const checkConfig = config.checks[checkName];
102832
102878
  if (result.status === 'fulfilled' && result.value.result && !result.value.error) {
102833
- // Skip storing results for skipped checks (they should not appear in outputs)
102879
+ // For skipped checks, store a marker so dependent checks can detect the skip
102834
102880
  if (result.value.skipped) {
102835
102881
  if (debug) {
102836
- log(`🔧 Debug: Not storing result for skipped check "${checkName}"`);
102882
+ log(`🔧 Debug: Storing skip marker for skipped check "${checkName}"`);
102837
102883
  }
102884
+ // Store a special marker result with a skip issue so dependencies can detect it
102885
+ results.set(checkName, {
102886
+ issues: [
102887
+ {
102888
+ ruleId: `${checkName}/__skipped`,
102889
+ severity: 'info',
102890
+ category: 'logic',
102891
+ message: 'Check was skipped',
102892
+ file: '',
102893
+ line: 0,
102894
+ },
102895
+ ],
102896
+ });
102838
102897
  continue;
102839
102898
  }
102840
102899
  const reviewResult = result.value.result;
@@ -102864,6 +102923,8 @@ class CheckExecutionEngine {
102864
102923
  else {
102865
102924
  normalizedOutput = [rawOutput];
102866
102925
  }
102926
+ // Log forEach items found (non-debug)
102927
+ logger_1.logger.info(` Found ${normalizedOutput.length} items for forEach iteration`);
102867
102928
  try {
102868
102929
  const preview = JSON.stringify(normalizedOutput);
102869
102930
  logger_1.logger.debug(`🔧 Debug: Check "${checkName}" forEach output: ${preview?.slice(0, 200) || '(empty)'}`);
@@ -103166,7 +103227,9 @@ class CheckExecutionEngine {
103166
103227
  debugInfo.push(`✅ Check "${checkName}" completed: ${(result.issues || []).length} issues found (level ${executionGroup.level})`);
103167
103228
  }
103168
103229
  // Issues are already prefixed and enriched with group/schema info
103169
- aggregatedIssues.push(...(result.issues || []));
103230
+ // Filter out internal __skipped markers
103231
+ const nonInternalIssues = (result.issues || []).filter(issue => !issue.ruleId?.endsWith('/__skipped'));
103232
+ aggregatedIssues.push(...nonInternalIssues);
103170
103233
  const resultSummary = result;
103171
103234
  const resultContent = resultSummary.content;
103172
103235
  if (typeof resultContent === 'string' && resultContent.trim()) {
@@ -112708,8 +112771,22 @@ class CommandCheckProvider extends check_provider_interface_1.CheckProvider {
112708
112771
  output = parsed;
112709
112772
  }
112710
112773
  catch {
112711
- // If not JSON, keep as string
112712
- output = rawOutput;
112774
+ // Try to extract JSON from the end of output (for commands with debug logs)
112775
+ const extracted = this.extractJsonFromEnd(rawOutput);
112776
+ if (extracted) {
112777
+ try {
112778
+ output = JSON.parse(extracted);
112779
+ logger_1.logger.debug(`🔧 Debug: Extracted and parsed JSON from end of output (${extracted.length} chars from ${rawOutput.length} total)`);
112780
+ }
112781
+ catch {
112782
+ // Extraction found something but it's not valid JSON
112783
+ output = rawOutput;
112784
+ }
112785
+ }
112786
+ else {
112787
+ // Not JSON, keep as string
112788
+ output = rawOutput;
112789
+ }
112713
112790
  }
112714
112791
  // Apply transform if specified (Liquid or JavaScript)
112715
112792
  let finalOutput = output;
@@ -112945,6 +113022,7 @@ class CommandCheckProvider extends check_provider_interface_1.CheckProvider {
112945
113022
  * - If it's a JSON string, expose parsed properties via Proxy (e.g., value.key)
112946
113023
  * - When coerced to string (toString/valueOf/Symbol.toPrimitive), return the original raw string
112947
113024
  * - If parsing fails or value is not a string, return the value unchanged
113025
+ * - Attempts to extract JSON from the end of the output if full parse fails
112948
113026
  */
112949
113027
  makeJsonSmart(value) {
112950
113028
  if (typeof value !== 'string') {
@@ -112952,12 +113030,28 @@ class CommandCheckProvider extends check_provider_interface_1.CheckProvider {
112952
113030
  }
112953
113031
  const raw = value;
112954
113032
  let parsed;
113033
+ // First try: parse the entire string as JSON
112955
113034
  try {
112956
113035
  parsed = JSON.parse(raw);
112957
113036
  }
112958
113037
  catch {
112959
- // Not JSON, return original string
112960
- return raw;
113038
+ // Second try: extract JSON from the end of the output
113039
+ // Look for { or [ at the start of a line and take everything after it
113040
+ const jsonMatch = this.extractJsonFromEnd(raw);
113041
+ if (jsonMatch) {
113042
+ try {
113043
+ parsed = JSON.parse(jsonMatch);
113044
+ logger_1.logger.debug(`🔧 Debug: Extracted JSON from end of output (${jsonMatch.length} chars from ${raw.length} total)`);
113045
+ }
113046
+ catch {
113047
+ // Not valid JSON even after extraction, return original string
113048
+ return raw;
113049
+ }
113050
+ }
113051
+ else {
113052
+ // Not JSON, return original string
113053
+ return raw;
113054
+ }
112961
113055
  }
112962
113056
  // Use a boxed string so string methods still work via Proxy fallback
112963
113057
  const boxed = new String(raw);
@@ -113010,6 +113104,30 @@ class CommandCheckProvider extends check_provider_interface_1.CheckProvider {
113010
113104
  };
113011
113105
  return new Proxy(boxed, handler);
113012
113106
  }
113107
+ /**
113108
+ * Extract JSON from the end of a string that may contain logs/debug output
113109
+ * Looks for the last occurrence of { or [ and tries to parse from there
113110
+ */
113111
+ extractJsonFromEnd(text) {
113112
+ // Strategy: Find the last line that starts with { or [
113113
+ // Then try to parse from that point to the end
113114
+ const lines = text.split('\n');
113115
+ // Search backwards for a line starting with { or [
113116
+ for (let i = lines.length - 1; i >= 0; i--) {
113117
+ const trimmed = lines[i].trim();
113118
+ if (trimmed.startsWith('{') || trimmed.startsWith('[')) {
113119
+ // Found potential JSON start - take everything from here to the end
113120
+ const candidate = lines.slice(i).join('\n');
113121
+ // Quick validation: does it look like valid JSON structure?
113122
+ const trimmedCandidate = candidate.trim();
113123
+ if ((trimmedCandidate.startsWith('{') && trimmedCandidate.endsWith('}')) ||
113124
+ (trimmedCandidate.startsWith('[') && trimmedCandidate.endsWith(']'))) {
113125
+ return trimmedCandidate;
113126
+ }
113127
+ }
113128
+ }
113129
+ return null;
113130
+ }
113013
113131
  /**
113014
113132
  * Recursively apply JSON-smart wrapper to outputs object values
113015
113133
  */
@@ -136162,6 +136280,74 @@ var init_extract = __esm({
136162
136280
  }
136163
136281
  });
136164
136282
 
136283
+ // src/grep.js
136284
+ async function grep(options) {
136285
+ if (!options || !options.pattern) {
136286
+ throw new Error("Pattern is required");
136287
+ }
136288
+ if (!options.paths) {
136289
+ throw new Error("Path(s) are required");
136290
+ }
136291
+ const binaryPath = await getBinaryPath(options.binaryOptions || {});
136292
+ const cliArgs = ["grep"];
136293
+ for (const [key, flag] of Object.entries(GREP_FLAG_MAP)) {
136294
+ const value = options[key];
136295
+ if (value === void 0 || value === null) continue;
136296
+ if (typeof value === "boolean" && value) {
136297
+ cliArgs.push(flag);
136298
+ } else if (typeof value === "number") {
136299
+ cliArgs.push(flag, String(value));
136300
+ } else if (typeof value === "string") {
136301
+ cliArgs.push(flag, value);
136302
+ }
136303
+ }
136304
+ cliArgs.push(options.pattern);
136305
+ const paths = Array.isArray(options.paths) ? options.paths : [options.paths];
136306
+ cliArgs.push(...paths);
136307
+ try {
136308
+ const { stdout, stderr } = await execFileAsync(binaryPath, cliArgs, {
136309
+ maxBuffer: 10 * 1024 * 1024,
136310
+ // 10MB buffer
136311
+ env: {
136312
+ ...process.env,
136313
+ // Disable colors in stderr for cleaner output
136314
+ NO_COLOR: "1"
136315
+ }
136316
+ });
136317
+ return stdout;
136318
+ } catch (error2) {
136319
+ if (error2.code === 1 && !error2.stderr) {
136320
+ return error2.stdout || "";
136321
+ }
136322
+ const errorMessage = error2.stderr || error2.message || "Unknown error";
136323
+ throw new Error(`Grep failed: ${errorMessage}`);
136324
+ }
136325
+ }
136326
+ var import_child_process5, import_util5, execFileAsync, GREP_FLAG_MAP;
136327
+ var init_grep = __esm({
136328
+ "src/grep.js"() {
136329
+ "use strict";
136330
+ import_child_process5 = __nccwpck_require__(35317);
136331
+ import_util5 = __nccwpck_require__(39023);
136332
+ init_utils();
136333
+ execFileAsync = (0, import_util5.promisify)(import_child_process5.execFile);
136334
+ GREP_FLAG_MAP = {
136335
+ ignoreCase: "-i",
136336
+ lineNumbers: "-n",
136337
+ count: "-c",
136338
+ filesWithMatches: "-l",
136339
+ filesWithoutMatches: "-L",
136340
+ invertMatch: "-v",
136341
+ beforeContext: "-B",
136342
+ afterContext: "-A",
136343
+ context: "-C",
136344
+ noGitignore: "--no-gitignore",
136345
+ color: "--color",
136346
+ maxCount: "-m"
136347
+ };
136348
+ }
136349
+ });
136350
+
136165
136351
  // src/tools/common.js
136166
136352
  function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
136167
136353
  for (const toolName of validTools) {
@@ -136645,7 +136831,7 @@ async function delegate({ task, timeout = 300, debug = false, currentIteration =
136645
136831
  }
136646
136832
  return new Promise((resolve4, reject2) => {
136647
136833
  const delegationSpan = tracer ? tracer.createDelegationSpan(sessionId, task) : null;
136648
- const process2 = (0, import_child_process5.spawn)(binaryPath, args, {
136834
+ const process2 = (0, import_child_process6.spawn)(binaryPath, args, {
136649
136835
  stdio: ["pipe", "pipe", "pipe"],
136650
136836
  timeout: timeout * 1e3
136651
136837
  });
@@ -136780,11 +136966,11 @@ async function delegate({ task, timeout = 300, debug = false, currentIteration =
136780
136966
  throw new Error(`Delegation setup failed: ${error2.message}`);
136781
136967
  }
136782
136968
  }
136783
- var import_child_process5, import_crypto2;
136969
+ var import_child_process6, import_crypto2;
136784
136970
  var init_delegate = __esm({
136785
136971
  "src/delegate.js"() {
136786
136972
  "use strict";
136787
- import_child_process5 = __nccwpck_require__(35317);
136973
+ import_child_process6 = __nccwpck_require__(35317);
136788
136974
  import_crypto2 = __nccwpck_require__(76982);
136789
136975
  init_utils();
136790
136976
  init_common();
@@ -137860,7 +138046,7 @@ async function executeBashCommand(command, options = {}) {
137860
138046
  return;
137861
138047
  }
137862
138048
  const [cmd, ...cmdArgs] = args;
137863
- const child = (0, import_child_process6.spawn)(cmd, cmdArgs, {
138049
+ const child = (0, import_child_process7.spawn)(cmd, cmdArgs, {
137864
138050
  cwd,
137865
138051
  env: processEnv,
137866
138052
  stdio: ["ignore", "pipe", "pipe"],
@@ -138044,11 +138230,11 @@ function validateExecutionOptions(options = {}) {
138044
138230
  warnings
138045
138231
  };
138046
138232
  }
138047
- var import_child_process6, import_path4, import_fs;
138233
+ var import_child_process7, import_path4, import_fs;
138048
138234
  var init_bashExecutor = __esm({
138049
138235
  "src/agent/bashExecutor.js"() {
138050
138236
  "use strict";
138051
- import_child_process6 = __nccwpck_require__(35317);
138237
+ import_child_process7 = __nccwpck_require__(35317);
138052
138238
  import_path4 = __nccwpck_require__(16928);
138053
138239
  import_fs = __nccwpck_require__(79896);
138054
138240
  init_bashCommandUtils();
@@ -138573,15 +138759,15 @@ function shouldIgnore(filePath, ignorePatterns) {
138573
138759
  }
138574
138760
  return false;
138575
138761
  }
138576
- var import_fs2, import_path6, import_util5, import_child_process7, execAsync4;
138762
+ var import_fs2, import_path6, import_util6, import_child_process8, execAsync4;
138577
138763
  var init_file_lister = __esm({
138578
138764
  "src/utils/file-lister.js"() {
138579
138765
  "use strict";
138580
138766
  import_fs2 = __toESM(__nccwpck_require__(79896), 1);
138581
138767
  import_path6 = __toESM(__nccwpck_require__(16928), 1);
138582
- import_util5 = __nccwpck_require__(39023);
138583
- import_child_process7 = __nccwpck_require__(35317);
138584
- execAsync4 = (0, import_util5.promisify)(import_child_process7.exec);
138768
+ import_util6 = __nccwpck_require__(39023);
138769
+ import_child_process8 = __nccwpck_require__(35317);
138770
+ execAsync4 = (0, import_util6.promisify)(import_child_process8.exec);
138585
138771
  }
138586
138772
  });
138587
138773
 
@@ -159891,8 +160077,8 @@ var require_dist_cjs59 = __commonJS({
159891
160077
  module2.exports = __toCommonJS2(index_exports2);
159892
160078
  var import_property_provider2 = require_dist_cjs24();
159893
160079
  var import_shared_ini_file_loader = require_dist_cjs42();
159894
- var import_child_process9 = __nccwpck_require__(35317);
159895
- var import_util9 = __nccwpck_require__(39023);
160080
+ var import_child_process10 = __nccwpck_require__(35317);
160081
+ var import_util10 = __nccwpck_require__(39023);
159896
160082
  var import_client7 = (init_client(), __toCommonJS(client_exports));
159897
160083
  var getValidatedProcessCredentials = /* @__PURE__ */ __name((profileName, data2, profiles) => {
159898
160084
  if (data2.Version !== 1) {
@@ -159928,7 +160114,7 @@ var require_dist_cjs59 = __commonJS({
159928
160114
  if (profiles[profileName]) {
159929
160115
  const credentialProcess = profile["credential_process"];
159930
160116
  if (credentialProcess !== void 0) {
159931
- const execPromise = (0, import_util9.promisify)(import_shared_ini_file_loader.externalDataInterceptor?.getTokenRecord?.().exec ?? import_child_process9.exec);
160117
+ const execPromise = (0, import_util10.promisify)(import_shared_ini_file_loader.externalDataInterceptor?.getTokenRecord?.().exec ?? import_child_process10.exec);
159932
160118
  try {
159933
160119
  const { stdout } = await execPromise(credentialProcess);
159934
160120
  let data2;
@@ -166366,13 +166552,13 @@ function createWrappedTools(baseTools) {
166366
166552
  }
166367
166553
  return wrappedTools;
166368
166554
  }
166369
- var import_child_process8, import_util8, import_crypto4, import_events, import_fs3, import_fs4, import_path7, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
166555
+ var import_child_process9, import_util9, import_crypto4, import_events, import_fs3, import_fs4, import_path7, import_glob, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
166370
166556
  var init_probeTool = __esm({
166371
166557
  "src/agent/probeTool.js"() {
166372
166558
  "use strict";
166373
166559
  init_index();
166374
- import_child_process8 = __nccwpck_require__(35317);
166375
- import_util8 = __nccwpck_require__(39023);
166560
+ import_child_process9 = __nccwpck_require__(35317);
166561
+ import_util9 = __nccwpck_require__(39023);
166376
166562
  import_crypto4 = __nccwpck_require__(76982);
166377
166563
  import_events = __nccwpck_require__(24434);
166378
166564
  import_fs3 = __toESM(__nccwpck_require__(79896), 1);
@@ -195519,6 +195705,14 @@ function cleanSchemaResponse(response) {
195519
195705
  return response;
195520
195706
  }
195521
195707
  const trimmed = response.trim();
195708
+ const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
195709
+ if (jsonBlockMatch) {
195710
+ return jsonBlockMatch[1].trim();
195711
+ }
195712
+ const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
195713
+ if (anyBlockMatch) {
195714
+ return anyBlockMatch[1].trim();
195715
+ }
195522
195716
  const codeBlockPatterns = [
195523
195717
  /```json\s*\n?([{\[][\s\S]*?[}\]])\s*\n?```/,
195524
195718
  /```\s*\n?([{\[][\s\S]*?[}\]])\s*\n?```/,
@@ -196331,8 +196525,8 @@ function loadMCPConfigurationFromPath(configPath) {
196331
196525
  try {
196332
196526
  const content = (0, import_fs5.readFileSync)(configPath, "utf8");
196333
196527
  const config = JSON.parse(content);
196334
- if (process.env.DEBUG === "1") {
196335
- console.error(`[MCP] Loaded configuration from: ${configPath}`);
196528
+ if (process.env.DEBUG === "1" || process.env.DEBUG_MCP === "1") {
196529
+ console.error(`[MCP DEBUG] Loaded configuration from: ${configPath}`);
196336
196530
  }
196337
196531
  return mergeWithEnvironment(config);
196338
196532
  } catch (error2) {
@@ -196358,12 +196552,12 @@ function loadMCPConfiguration() {
196358
196552
  try {
196359
196553
  const content = (0, import_fs5.readFileSync)(configPath, "utf8");
196360
196554
  config = JSON.parse(content);
196361
- if (process.env.DEBUG === "1") {
196362
- console.error(`[MCP] Loaded configuration from: ${configPath}`);
196555
+ if (process.env.DEBUG === "1" || process.env.DEBUG_MCP === "1") {
196556
+ console.error(`[MCP DEBUG] Loaded configuration from: ${configPath}`);
196363
196557
  }
196364
196558
  break;
196365
196559
  } catch (error2) {
196366
- console.error(`[MCP] Failed to parse config from ${configPath}:`, error2.message);
196560
+ console.error(`[MCP ERROR] Failed to parse config from ${configPath}:`, error2.message);
196367
196561
  }
196368
196562
  }
196369
196563
  }
@@ -196439,12 +196633,12 @@ function parseEnabledServers(config) {
196439
196633
  }
196440
196634
  if (server.transport === "stdio") {
196441
196635
  if (!server.command) {
196442
- console.error(`[MCP] Server ${name14} missing required 'command' for stdio transport`);
196636
+ console.error(`[MCP ERROR] Server ${name14} missing required 'command' for stdio transport`);
196443
196637
  continue;
196444
196638
  }
196445
196639
  } else if (["websocket", "sse", "http"].includes(server.transport)) {
196446
196640
  if (!server.url) {
196447
- console.error(`[MCP] Server ${name14} missing required 'url' for ${server.transport} transport`);
196641
+ console.error(`[MCP ERROR] Server ${name14} missing required 'url' for ${server.transport} transport`);
196448
196642
  continue;
196449
196643
  }
196450
196644
  }
@@ -196575,20 +196769,45 @@ var init_client2 = __esm({
196575
196769
  async initialize(config = null) {
196576
196770
  this.config = config || loadMCPConfiguration();
196577
196771
  const servers = parseEnabledServers(this.config);
196772
+ console.error(`[MCP INFO] Found ${servers.length} enabled MCP server${servers.length !== 1 ? "s" : ""}`);
196773
+ if (servers.length === 0) {
196774
+ console.error("[MCP INFO] No MCP servers configured or enabled");
196775
+ console.error("[MCP INFO] 0 MCP tools available");
196776
+ return {
196777
+ connected: 0,
196778
+ total: 0,
196779
+ tools: []
196780
+ };
196781
+ }
196578
196782
  if (this.debug) {
196579
- console.error(`[MCP] Found ${servers.length} enabled servers`);
196783
+ console.error("[MCP DEBUG] Server details:");
196784
+ servers.forEach((server) => {
196785
+ console.error(`[MCP DEBUG] - ${server.name} (${server.transport})`);
196786
+ });
196580
196787
  }
196581
196788
  const connectionPromises = servers.map(
196582
196789
  (server) => this.connectToServer(server).catch((error2) => {
196583
- console.error(`[MCP] Failed to connect to ${server.name}:`, error2.message);
196790
+ console.error(`[MCP ERROR] Failed to connect to ${server.name}:`, error2.message);
196584
196791
  return null;
196585
196792
  })
196586
196793
  );
196587
196794
  const results = await Promise.all(connectionPromises);
196588
196795
  const connectedCount = results.filter(Boolean).length;
196589
- if (this.debug) {
196590
- console.error(`[MCP] Successfully connected to ${connectedCount}/${servers.length} servers`);
196591
- console.error(`[MCP] Total tools available: ${this.tools.size}`);
196796
+ if (connectedCount === 0) {
196797
+ console.error(`[MCP ERROR] Failed to connect to all ${servers.length} server${servers.length !== 1 ? "s" : ""}`);
196798
+ console.error("[MCP INFO] 0 MCP tools available");
196799
+ } else if (connectedCount < servers.length) {
196800
+ console.error(`[MCP INFO] Successfully connected to ${connectedCount}/${servers.length} servers`);
196801
+ console.error(`[MCP INFO] ${this.tools.size} MCP tool${this.tools.size !== 1 ? "s" : ""} available`);
196802
+ } else {
196803
+ console.error(`[MCP INFO] Successfully connected to all ${connectedCount} server${connectedCount !== 1 ? "s" : ""}`);
196804
+ console.error(`[MCP INFO] ${this.tools.size} MCP tool${this.tools.size !== 1 ? "s" : ""} available`);
196805
+ }
196806
+ if (this.debug && this.tools.size > 0) {
196807
+ console.error("[MCP DEBUG] Available tools:");
196808
+ Array.from(this.tools.keys()).forEach((toolName) => {
196809
+ console.error(`[MCP DEBUG] - ${toolName}`);
196810
+ });
196592
196811
  }
196593
196812
  return {
196594
196813
  connected: connectedCount,
@@ -196604,7 +196823,7 @@ var init_client2 = __esm({
196604
196823
  const { name: name14 } = serverConfig;
196605
196824
  try {
196606
196825
  if (this.debug) {
196607
- console.error(`[MCP] Connecting to ${name14} via ${serverConfig.transport}...`);
196826
+ console.error(`[MCP DEBUG] Connecting to ${name14} via ${serverConfig.transport}...`);
196608
196827
  }
196609
196828
  const transport = createTransport(serverConfig);
196610
196829
  const client = new import_client3.Client(
@@ -196623,6 +196842,7 @@ var init_client2 = __esm({
196623
196842
  config: serverConfig
196624
196843
  });
196625
196844
  const toolsResponse = await client.listTools();
196845
+ const toolCount = toolsResponse?.tools?.length || 0;
196626
196846
  if (toolsResponse && toolsResponse.tools) {
196627
196847
  for (const tool3 of toolsResponse.tools) {
196628
196848
  const qualifiedName = `${name14}_${tool3.name}`;
@@ -196632,16 +196852,17 @@ var init_client2 = __esm({
196632
196852
  originalName: tool3.name
196633
196853
  });
196634
196854
  if (this.debug) {
196635
- console.error(`[MCP] Registered tool: ${qualifiedName}`);
196855
+ console.error(`[MCP DEBUG] Registered tool: ${qualifiedName}`);
196636
196856
  }
196637
196857
  }
196638
196858
  }
196639
- if (this.debug) {
196640
- console.error(`[MCP] Connected to ${name14} with ${toolsResponse?.tools?.length || 0} tools`);
196641
- }
196859
+ console.error(`[MCP INFO] Connected to ${name14}: ${toolCount} tool${toolCount !== 1 ? "s" : ""} loaded`);
196642
196860
  return true;
196643
196861
  } catch (error2) {
196644
- console.error(`[MCP] Error connecting to ${name14}:`, error2.message);
196862
+ console.error(`[MCP ERROR] Error connecting to ${name14}:`, error2.message);
196863
+ if (this.debug) {
196864
+ console.error(`[MCP DEBUG] Full error details:`, error2);
196865
+ }
196645
196866
  return false;
196646
196867
  }
196647
196868
  }
@@ -196661,7 +196882,7 @@ var init_client2 = __esm({
196661
196882
  }
196662
196883
  try {
196663
196884
  if (this.debug) {
196664
- console.error(`[MCP] Calling ${toolName} with args:`, args);
196885
+ console.error(`[MCP DEBUG] Calling ${toolName} with args:`, JSON.stringify(args, null, 2));
196665
196886
  }
196666
196887
  const timeout = this.config?.settings?.timeout || 3e4;
196667
196888
  const timeoutPromise = new Promise((_2, reject2) => {
@@ -196676,9 +196897,15 @@ var init_client2 = __esm({
196676
196897
  }),
196677
196898
  timeoutPromise
196678
196899
  ]);
196900
+ if (this.debug) {
196901
+ console.error(`[MCP DEBUG] Tool ${toolName} executed successfully`);
196902
+ }
196679
196903
  return result;
196680
196904
  } catch (error2) {
196681
- console.error(`[MCP] Error calling tool ${toolName}:`, error2);
196905
+ console.error(`[MCP ERROR] Error calling tool ${toolName}:`, error2.message);
196906
+ if (this.debug) {
196907
+ console.error(`[MCP DEBUG] Full error details:`, error2);
196908
+ }
196682
196909
  throw error2;
196683
196910
  }
196684
196911
  }
@@ -196723,20 +196950,32 @@ var init_client2 = __esm({
196723
196950
  */
196724
196951
  async disconnect() {
196725
196952
  const disconnectPromises = [];
196953
+ if (this.clients.size === 0) {
196954
+ if (this.debug) {
196955
+ console.error("[MCP DEBUG] No MCP clients to disconnect");
196956
+ }
196957
+ return;
196958
+ }
196959
+ if (this.debug) {
196960
+ console.error(`[MCP DEBUG] Disconnecting from ${this.clients.size} MCP server${this.clients.size !== 1 ? "s" : ""}...`);
196961
+ }
196726
196962
  for (const [name14, clientInfo] of this.clients.entries()) {
196727
196963
  disconnectPromises.push(
196728
196964
  clientInfo.client.close().then(() => {
196729
196965
  if (this.debug) {
196730
- console.error(`[MCP] Disconnected from ${name14}`);
196966
+ console.error(`[MCP DEBUG] Disconnected from ${name14}`);
196731
196967
  }
196732
196968
  }).catch((error2) => {
196733
- console.error(`[MCP] Error disconnecting from ${name14}:`, error2);
196969
+ console.error(`[MCP ERROR] Error disconnecting from ${name14}:`, error2.message);
196734
196970
  })
196735
196971
  );
196736
196972
  }
196737
196973
  await Promise.all(disconnectPromises);
196738
196974
  this.clients.clear();
196739
196975
  this.tools.clear();
196976
+ if (this.debug) {
196977
+ console.error("[MCP DEBUG] All MCP connections closed");
196978
+ }
196740
196979
  }
196741
196980
  };
196742
196981
  }
@@ -196888,31 +197127,58 @@ var init_xmlBridge = __esm({
196888
197127
  async initialize(config = null) {
196889
197128
  let mcpConfigs = null;
196890
197129
  if (!config) {
197130
+ if (this.debug) {
197131
+ console.error("[MCP DEBUG] No config provided, attempting auto-discovery...");
197132
+ }
196891
197133
  mcpConfigs = loadMCPConfiguration();
197134
+ if (!mcpConfigs || !mcpConfigs.mcpServers || Object.keys(mcpConfigs.mcpServers).length === 0) {
197135
+ console.error("[MCP WARNING] MCP enabled but no configuration found");
197136
+ console.error("[MCP INFO] To use MCP, provide configuration via:");
197137
+ console.error("[MCP INFO] - mcpConfig option when creating ProbeAgent");
197138
+ console.error("[MCP INFO] - mcpConfigPath option pointing to a config file");
197139
+ console.error("[MCP INFO] - Config file in standard locations (~/.mcp/config.json, etc.)");
197140
+ console.error("[MCP INFO] - Environment variable MCP_CONFIG_PATH");
197141
+ }
196892
197142
  } else if (Array.isArray(config)) {
197143
+ if (this.debug) {
197144
+ console.error("[MCP DEBUG] Using deprecated array config format (consider using mcpConfig object)");
197145
+ }
196893
197146
  mcpConfigs = { mcpServers: config };
196894
197147
  } else {
197148
+ if (this.debug) {
197149
+ console.error("[MCP DEBUG] Using provided MCP config object");
197150
+ }
196895
197151
  mcpConfigs = config;
196896
197152
  }
196897
197153
  if (!mcpConfigs || !mcpConfigs.mcpServers || Object.keys(mcpConfigs.mcpServers).length === 0) {
196898
- if (this.debug) {
196899
- console.error("[MCP] No MCP servers configured");
196900
- }
197154
+ console.error("[MCP INFO] 0 MCP tools available");
196901
197155
  return;
196902
197156
  }
196903
197157
  try {
197158
+ if (this.debug) {
197159
+ console.error("[MCP DEBUG] Initializing MCP client manager...");
197160
+ }
196904
197161
  this.mcpManager = new MCPClientManager({ debug: this.debug });
196905
197162
  const result = await this.mcpManager.initialize(mcpConfigs);
196906
197163
  const vercelTools = this.mcpManager.getVercelTools();
196907
197164
  this.mcpTools = vercelTools;
197165
+ const toolCount = Object.keys(vercelTools).length;
196908
197166
  for (const [name14, tool3] of Object.entries(vercelTools)) {
196909
197167
  this.xmlDefinitions[name14] = mcpToolToXmlDefinition(name14, tool3);
196910
197168
  }
196911
- if (this.debug) {
196912
- console.error(`[MCP] Loaded ${Object.keys(vercelTools).length} MCP tools from ${result.connected} server(s)`);
197169
+ if (toolCount === 0) {
197170
+ console.error("[MCP INFO] MCP initialization complete: 0 tools loaded");
197171
+ } else {
197172
+ console.error(`[MCP INFO] MCP initialization complete: ${toolCount} tool${toolCount !== 1 ? "s" : ""} loaded from ${result.connected} server${result.connected !== 1 ? "s" : ""}`);
197173
+ if (this.debug) {
197174
+ console.error("[MCP DEBUG] Tool definitions generated for XML bridge");
197175
+ }
196913
197176
  }
196914
197177
  } catch (error2) {
196915
- console.error("[MCP] Failed to initialize MCP connections:", error2);
197178
+ console.error("[MCP ERROR] Failed to initialize MCP connections:", error2.message);
197179
+ if (this.debug) {
197180
+ console.error("[MCP DEBUG] Full error details:", error2);
197181
+ }
196916
197182
  }
196917
197183
  }
196918
197184
  /**
@@ -196937,24 +197203,35 @@ var init_xmlBridge = __esm({
196937
197203
  async executeFromXml(xmlString) {
196938
197204
  const parsed = parseXmlMcpToolCall(xmlString, this.getToolNames());
196939
197205
  if (!parsed) {
197206
+ console.error("[MCP ERROR] No valid MCP tool call found in XML");
196940
197207
  throw new Error("No valid MCP tool call found in XML");
196941
197208
  }
196942
197209
  const { toolName, params } = parsed;
196943
197210
  if (this.debug) {
196944
- console.error(`[MCP] Executing MCP tool: ${toolName} with params:`, params);
197211
+ console.error(`[MCP DEBUG] Executing MCP tool: ${toolName}`);
197212
+ console.error(`[MCP DEBUG] Parameters:`, JSON.stringify(params, null, 2));
196945
197213
  }
196946
197214
  const tool3 = this.mcpTools[toolName];
196947
197215
  if (!tool3) {
197216
+ console.error(`[MCP ERROR] Unknown MCP tool: ${toolName}`);
197217
+ console.error(`[MCP ERROR] Available tools: ${this.getToolNames().join(", ")}`);
196948
197218
  throw new Error(`Unknown MCP tool: ${toolName}`);
196949
197219
  }
196950
197220
  try {
196951
197221
  const result = await tool3.execute(params);
197222
+ if (this.debug) {
197223
+ console.error(`[MCP DEBUG] Tool ${toolName} executed successfully`);
197224
+ }
196952
197225
  return {
196953
197226
  success: true,
196954
197227
  toolName,
196955
197228
  result
196956
197229
  };
196957
197230
  } catch (error2) {
197231
+ console.error(`[MCP ERROR] Tool ${toolName} execution failed:`, error2.message);
197232
+ if (this.debug) {
197233
+ console.error(`[MCP DEBUG] Full error details:`, error2);
197234
+ }
196958
197235
  return {
196959
197236
  success: false,
196960
197237
  toolName,
@@ -197088,6 +197365,7 @@ var init_ProbeAgent = __esm({
197088
197365
  this.mcpConfig = options.mcpConfig || null;
197089
197366
  this.mcpServers = options.mcpServers || null;
197090
197367
  this.mcpBridge = null;
197368
+ this._mcpInitialized = false;
197091
197369
  this.initializeModel();
197092
197370
  }
197093
197371
  /**
@@ -197095,7 +197373,8 @@ var init_ProbeAgent = __esm({
197095
197373
  * This method initializes MCP and merges MCP tools into the tool list
197096
197374
  */
197097
197375
  async initialize() {
197098
- if (this.enableMcp) {
197376
+ if (this.enableMcp && !this._mcpInitialized) {
197377
+ this._mcpInitialized = true;
197099
197378
  try {
197100
197379
  await this.initializeMCP();
197101
197380
  if (this.mcpBridge) {
@@ -197119,7 +197398,10 @@ var init_ProbeAgent = __esm({
197119
197398
  console.error("[DEBUG] ========================================\n");
197120
197399
  }
197121
197400
  } catch (error2) {
197122
- console.error("[MCP] Failed to initialize MCP:", error2);
197401
+ console.error("[MCP ERROR] Failed to initialize MCP:", error2.message);
197402
+ if (this.debug) {
197403
+ console.error("[MCP DEBUG] Full error details:", error2);
197404
+ }
197123
197405
  this.mcpBridge = null;
197124
197406
  }
197125
197407
  }
@@ -197543,13 +197825,13 @@ var init_ProbeAgent = __esm({
197543
197825
  if (this.mcpConfig) {
197544
197826
  mcpConfig = this.mcpConfig;
197545
197827
  if (this.debug) {
197546
- console.log("[DEBUG] Using provided MCP config object");
197828
+ console.error("[MCP DEBUG] Using provided MCP config object");
197547
197829
  }
197548
197830
  } else if (this.mcpConfigPath) {
197549
197831
  try {
197550
197832
  mcpConfig = loadMCPConfigurationFromPath(this.mcpConfigPath);
197551
197833
  if (this.debug) {
197552
- console.log(`[DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
197834
+ console.error(`[MCP DEBUG] Loaded MCP config from: ${this.mcpConfigPath}`);
197553
197835
  }
197554
197836
  } catch (error2) {
197555
197837
  throw new Error(`Failed to load MCP config from ${this.mcpConfigPath}: ${error2.message}`);
@@ -197557,8 +197839,13 @@ var init_ProbeAgent = __esm({
197557
197839
  } else if (this.mcpServers) {
197558
197840
  mcpConfig = { mcpServers: this.mcpServers };
197559
197841
  if (this.debug) {
197560
- console.warn("[DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.");
197842
+ console.error("[MCP DEBUG] Using deprecated mcpServers option. Consider using mcpConfig instead.");
197561
197843
  }
197844
+ } else {
197845
+ if (this.debug) {
197846
+ console.error("[MCP DEBUG] No explicit MCP config provided, will attempt auto-discovery");
197847
+ }
197848
+ mcpConfig = null;
197562
197849
  }
197563
197850
  this.mcpBridge = new MCPXmlBridge({ debug: this.debug });
197564
197851
  await this.mcpBridge.initialize(mcpConfig);
@@ -197566,22 +197853,25 @@ var init_ProbeAgent = __esm({
197566
197853
  const mcpToolCount = mcpToolNames.length;
197567
197854
  if (mcpToolCount > 0) {
197568
197855
  if (this.debug) {
197569
- console.error("\n[DEBUG] ========================================");
197570
- console.error(`[DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
197571
- console.error("[DEBUG] Available MCP tools:");
197856
+ console.error("\n[MCP DEBUG] ========================================");
197857
+ console.error(`[MCP DEBUG] MCP Tools Initialized (${mcpToolCount} tools)`);
197858
+ console.error("[MCP DEBUG] Available MCP tools:");
197572
197859
  for (const toolName of mcpToolNames) {
197573
- console.error(`[DEBUG] - ${toolName}`);
197860
+ console.error(`[MCP DEBUG] - ${toolName}`);
197574
197861
  }
197575
- console.error("[DEBUG] ========================================\n");
197862
+ console.error("[MCP DEBUG] ========================================\n");
197576
197863
  }
197577
197864
  } else {
197578
197865
  if (this.debug) {
197579
- console.error("[DEBUG] No MCP tools loaded, setting bridge to null");
197866
+ console.error("[MCP DEBUG] No MCP tools loaded, setting bridge to null");
197580
197867
  }
197581
197868
  this.mcpBridge = null;
197582
197869
  }
197583
197870
  } catch (error2) {
197584
- console.error("[MCP] Error initializing MCP:", error2);
197871
+ console.error("[MCP ERROR] Error initializing MCP:", error2.message);
197872
+ if (this.debug) {
197873
+ console.error("[MCP DEBUG] Full error details:", error2);
197874
+ }
197585
197875
  this.mcpBridge = null;
197586
197876
  }
197587
197877
  }
@@ -197589,6 +197879,23 @@ var init_ProbeAgent = __esm({
197589
197879
  * Get the system message with instructions for the AI (XML Tool Format)
197590
197880
  */
197591
197881
  async getSystemMessage() {
197882
+ if (this.enableMcp && !this.mcpBridge && !this._mcpInitialized) {
197883
+ this._mcpInitialized = true;
197884
+ try {
197885
+ await this.initializeMCP();
197886
+ if (this.mcpBridge) {
197887
+ const mcpTools = this.mcpBridge.mcpTools || {};
197888
+ for (const [toolName, toolImpl] of Object.entries(mcpTools)) {
197889
+ this.toolImplementations[toolName] = toolImpl;
197890
+ }
197891
+ }
197892
+ } catch (error2) {
197893
+ console.error("[MCP ERROR] Failed to lazy-initialize MCP:", error2.message);
197894
+ if (this.debug) {
197895
+ console.error("[MCP DEBUG] Full error details:", error2);
197896
+ }
197897
+ }
197898
+ }
197592
197899
  let toolDefinitions = `
197593
197900
  ${searchToolDefinition}
197594
197901
  ${queryToolDefinition}
@@ -198889,6 +199196,7 @@ __export(index_exports, {
198889
199196
  extractTool: () => extractTool,
198890
199197
  extractToolDefinition: () => extractToolDefinition,
198891
199198
  getBinaryPath: () => getBinaryPath,
199199
+ grep: () => grep,
198892
199200
  initializeSimpleTelemetryFromOptions: () => initializeSimpleTelemetryFromOptions,
198893
199201
  listFilesByLevel: () => listFilesByLevel,
198894
199202
  listFilesToolInstance: () => listFilesToolInstance,
@@ -198911,6 +199219,7 @@ var init_index = __esm({
198911
199219
  init_search();
198912
199220
  init_query();
198913
199221
  init_extract();
199222
+ init_grep();
198914
199223
  init_delegate();
198915
199224
  init_utils();
198916
199225
  init_tools();
@@ -228501,7 +228810,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
228501
228810
  /***/ ((module) => {
228502
228811
 
228503
228812
  "use strict";
228504
- module.exports = {"rE":"0.1.78"};
228813
+ module.exports = {"rE":"0.1.80"};
228505
228814
 
228506
228815
  /***/ })
228507
228816