@probelabs/probe 0.6.0-rc103 → 0.6.0-rc105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc103",
3
+ "version": "0.6.0-rc105",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -68,6 +68,7 @@
68
68
  "author": "probelabs",
69
69
  "license": "ISC",
70
70
  "dependencies": {
71
+ "@ai-sdk/amazon-bedrock": "^1.0.8",
71
72
  "@ai-sdk/anthropic": "^2.0.8",
72
73
  "@ai-sdk/google": "^2.0.14",
73
74
  "@ai-sdk/openai": "^2.0.10",
@@ -2,6 +2,7 @@
2
2
  import { createAnthropic } from '@ai-sdk/anthropic';
3
3
  import { createOpenAI } from '@ai-sdk/openai';
4
4
  import { createGoogleGenerativeAI } from '@ai-sdk/google';
5
+ import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
5
6
  import { streamText } from 'ai';
6
7
  import { randomUUID } from 'crypto';
7
8
  import { EventEmitter } from 'events';
@@ -91,8 +92,14 @@ export class ProbeAgent {
91
92
  this.maxResponseTokens = options.maxResponseTokens || parseInt(process.env.MAX_RESPONSE_TOKENS || '0', 10) || null;
92
93
  this.disableMermaidValidation = !!options.disableMermaidValidation;
93
94
 
94
- // Search configuration
95
- this.allowedFolders = options.path ? [options.path] : [process.cwd()];
95
+ // Search configuration - support both path (single) and allowedFolders (array)
96
+ if (options.allowedFolders && Array.isArray(options.allowedFolders)) {
97
+ this.allowedFolders = options.allowedFolders;
98
+ } else if (options.path) {
99
+ this.allowedFolders = [options.path];
100
+ } else {
101
+ this.allowedFolders = [process.cwd()];
102
+ }
96
103
 
97
104
  // API configuration
98
105
  this.clientApiProvider = options.provider || null;
@@ -186,12 +193,18 @@ export class ProbeAgent {
186
193
  const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
187
194
  const openaiApiKey = process.env.OPENAI_API_KEY;
188
195
  const googleApiKey = process.env.GOOGLE_API_KEY;
196
+ const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
197
+ const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
198
+ const awsRegion = process.env.AWS_REGION;
199
+ const awsSessionToken = process.env.AWS_SESSION_TOKEN;
200
+ const awsApiKey = process.env.AWS_BEDROCK_API_KEY;
189
201
 
190
202
  // Get custom API URLs if provided
191
203
  const llmBaseUrl = process.env.LLM_BASE_URL;
192
204
  const anthropicApiUrl = process.env.ANTHROPIC_API_URL || llmBaseUrl;
193
205
  const openaiApiUrl = process.env.OPENAI_API_URL || llmBaseUrl;
194
206
  const googleApiUrl = process.env.GOOGLE_API_URL || llmBaseUrl;
207
+ const awsBedrockBaseUrl = process.env.AWS_BEDROCK_BASE_URL || llmBaseUrl;
195
208
 
196
209
  // Get model override if provided
197
210
  const modelName = process.env.MODEL_NAME;
@@ -200,7 +213,12 @@ export class ProbeAgent {
200
213
  const forceProvider = this.clientApiProvider || (process.env.FORCE_PROVIDER ? process.env.FORCE_PROVIDER.toLowerCase() : null);
201
214
 
202
215
  if (this.debug) {
203
- console.log(`[DEBUG] Available API keys: Anthropic=${!!anthropicApiKey}, OpenAI=${!!openaiApiKey}, Google=${!!googleApiKey}`);
216
+ const hasAwsCredentials = !!(awsAccessKeyId && awsSecretAccessKey && awsRegion);
217
+ const hasAwsApiKey = !!awsApiKey;
218
+ console.log(`[DEBUG] Available API keys: Anthropic=${!!anthropicApiKey}, OpenAI=${!!openaiApiKey}, Google=${!!googleApiKey}, AWS Bedrock=${hasAwsCredentials || hasAwsApiKey}`);
219
+ if (hasAwsCredentials) console.log(`[DEBUG] AWS credentials: AccessKey=${!!awsAccessKeyId}, SecretKey=${!!awsSecretAccessKey}, Region=${awsRegion}, SessionToken=${!!awsSessionToken}`);
220
+ if (hasAwsApiKey) console.log(`[DEBUG] AWS API Key provided`);
221
+ if (awsBedrockBaseUrl) console.log(`[DEBUG] AWS Bedrock base URL: ${awsBedrockBaseUrl}`);
204
222
  console.log(`[DEBUG] Force provider: ${forceProvider || '(not set)'}`);
205
223
  if (modelName) console.log(`[DEBUG] Model override: ${modelName}`);
206
224
  }
@@ -216,6 +234,9 @@ export class ProbeAgent {
216
234
  } else if (forceProvider === 'google' && googleApiKey) {
217
235
  this.initializeGoogleModel(googleApiKey, googleApiUrl, modelName);
218
236
  return;
237
+ } else if (forceProvider === 'bedrock' && ((awsAccessKeyId && awsSecretAccessKey && awsRegion) || awsApiKey)) {
238
+ this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
239
+ return;
219
240
  }
220
241
  console.warn(`WARNING: Forced provider "${forceProvider}" selected but required API key is missing or invalid! Falling back to auto-detection.`);
221
242
  }
@@ -227,8 +248,10 @@ export class ProbeAgent {
227
248
  this.initializeOpenAIModel(openaiApiKey, openaiApiUrl, modelName);
228
249
  } else if (googleApiKey) {
229
250
  this.initializeGoogleModel(googleApiKey, googleApiUrl, modelName);
251
+ } else if ((awsAccessKeyId && awsSecretAccessKey && awsRegion) || awsApiKey) {
252
+ this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
230
253
  } else {
231
- throw new Error('No API key provided. Please set ANTHROPIC_API_KEY, OPENAI_API_KEY, or GOOGLE_API_KEY environment variable.');
254
+ throw new Error('No API key provided. Please set ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY, AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION), or AWS_BEDROCK_API_KEY environment variables.');
232
255
  }
233
256
  }
234
257
 
@@ -281,6 +304,46 @@ export class ProbeAgent {
281
304
  }
282
305
  }
283
306
 
307
+ /**
308
+ * Initialize AWS Bedrock model
309
+ */
310
+ initializeBedrockModel(accessKeyId, secretAccessKey, region, sessionToken, apiKey, baseURL, modelName) {
311
+ // Build configuration object, only including defined values
312
+ const config = {};
313
+
314
+ // Authentication - prefer API key if provided, otherwise use AWS credentials
315
+ if (apiKey) {
316
+ config.apiKey = apiKey;
317
+ } else if (accessKeyId && secretAccessKey) {
318
+ config.accessKeyId = accessKeyId;
319
+ config.secretAccessKey = secretAccessKey;
320
+ if (sessionToken) {
321
+ config.sessionToken = sessionToken;
322
+ }
323
+ }
324
+
325
+ // Region is required for AWS credentials but optional for API key
326
+ if (region) {
327
+ config.region = region;
328
+ }
329
+
330
+ // Optional base URL
331
+ if (baseURL) {
332
+ config.baseURL = baseURL;
333
+ }
334
+
335
+ this.provider = createAmazonBedrock(config);
336
+ this.model = modelName || 'anthropic.claude-sonnet-4-20250514-v1:0';
337
+ this.apiType = 'bedrock';
338
+
339
+ if (this.debug) {
340
+ const authMethod = apiKey ? 'API Key' : 'AWS Credentials';
341
+ const regionInfo = region ? ` (Region: ${region})` : '';
342
+ const baseUrlInfo = baseURL ? ` (Base URL: ${baseURL})` : '';
343
+ console.log(`Using AWS Bedrock API with model: ${this.model}${regionInfo} [Auth: ${authMethod}]${baseUrlInfo}`);
344
+ }
345
+ }
346
+
284
347
  /**
285
348
  * Process assistant response content and detect/load image references
286
349
  * @param {string} content - The assistant's response content
@@ -1060,8 +1123,12 @@ When troubleshooting:
1060
1123
  } else if (this.toolImplementations[toolName]) {
1061
1124
  // Execute native tool
1062
1125
  try {
1063
- // Add sessionId to params for tool execution
1064
- const toolParams = { ...params, sessionId: this.sessionId };
1126
+ // Add sessionId and workingDirectory to params for tool execution
1127
+ const toolParams = {
1128
+ ...params,
1129
+ sessionId: this.sessionId,
1130
+ workingDirectory: (this.allowedFolders && this.allowedFolders[0]) || process.cwd()
1131
+ };
1065
1132
 
1066
1133
  // Emit tool start event
1067
1134
  this.events.emit('toolCall', {
@@ -1214,8 +1281,10 @@ Remember: Use proper XML format with BOTH opening and closing tags:
1214
1281
  <parameter>value</parameter>
1215
1282
  </tool_name>
1216
1283
 
1217
- Or for quick completion if your previous response was already correct:
1218
- <attempt_complete>`;
1284
+ Or for quick completion if your previous response was already correct and complete:
1285
+ <attempt_complete>
1286
+
1287
+ IMPORTANT: When using <attempt_complete>, this must be the ONLY content in your response. No additional text, explanations, or other content should be included. This tag signals to reuse your previous response as the final answer.`;
1219
1288
  }
1220
1289
 
1221
1290
  currentMessages.push({
@@ -1733,4 +1802,4 @@ Convert your previous response content into actual JSON data that follows this s
1733
1802
  console.log(`[DEBUG] Agent cancelled for session ${this.sessionId}`);
1734
1803
  }
1735
1804
  }
1736
- }
1805
+ }
@@ -112,6 +112,7 @@ function parseArgs() {
112
112
  acp: false,
113
113
  question: null,
114
114
  path: null,
115
+ allowedFolders: null,
115
116
  prompt: null,
116
117
  systemPrompt: null,
117
118
  schema: null,
@@ -145,6 +146,8 @@ function parseArgs() {
145
146
  config.allowEdit = true;
146
147
  } else if (arg === '--path' && i + 1 < args.length) {
147
148
  config.path = args[++i];
149
+ } else if (arg === '--allowed-folders' && i + 1 < args.length) {
150
+ config.allowedFolders = args[++i].split(',').map(dir => dir.trim());
148
151
  } else if (arg === '--prompt' && i + 1 < args.length) {
149
152
  config.prompt = args[++i];
150
153
  } else if (arg === '--system-prompt' && i + 1 < args.length) {
@@ -201,6 +204,7 @@ Usage:
201
204
 
202
205
  Options:
203
206
  --path <dir> Search directory (default: current)
207
+ --allowed-folders <dirs> Comma-separated list of allowed directories for file operations
204
208
  --prompt <type> Persona: code-explorer, engineer, code-review, support, architect
205
209
  --system-prompt <text|file> Custom system prompt (text or file path)
206
210
  --schema <schema|file> Output schema (JSON, XML, any format - text or file path)
@@ -296,17 +300,22 @@ class ProbeAgentMcpServer {
296
300
  tools: [
297
301
  {
298
302
  name: 'search_code',
299
- description: "Search code and answer questions about the codebase using an AI agent. This tool provides intelligent responses based on code analysis.",
303
+ description: "AI agent that answers free-form questions about codebases. Ask detailed questions in natural language.",
300
304
  inputSchema: {
301
305
  type: 'object',
302
306
  properties: {
303
307
  query: {
304
308
  type: 'string',
305
- description: 'The question or request about the codebase.',
309
+ description: 'A detailed, free-form question about the codebase in natural language. Be specific and descriptive. Example: "How does the authentication system work and where is user session management implemented?"',
306
310
  },
307
311
  path: {
308
312
  type: 'string',
309
- description: 'Optional path to the directory to search in. Defaults to current directory.',
313
+ description: 'Absolute path to the directory to search in (e.g., "/Users/username/projects/myproject").',
314
+ },
315
+ allowed_folders: {
316
+ type: 'array',
317
+ items: { type: 'string' },
318
+ description: 'Optional list of allowed directories for file operations. Defaults to current directory if not specified.',
310
319
  },
311
320
  prompt: {
312
321
  type: 'string',
@@ -315,34 +324,6 @@ class ProbeAgentMcpServer {
315
324
  system_prompt: {
316
325
  type: 'string',
317
326
  description: 'Optional custom system prompt (text or file path).',
318
- },
319
- provider: {
320
- type: 'string',
321
- description: 'Optional AI provider to force: anthropic, openai, google.',
322
- },
323
- model: {
324
- type: 'string',
325
- description: 'Optional model name override.',
326
- },
327
- allow_edit: {
328
- type: 'boolean',
329
- description: 'Enable code modification capabilities.',
330
- },
331
- max_iterations: {
332
- type: 'number',
333
- description: 'Maximum number of tool iterations (default: 30).',
334
- },
335
- max_response_tokens: {
336
- type: 'number',
337
- description: 'Maximum tokens for AI response (overrides model defaults).',
338
- },
339
- schema: {
340
- type: 'string',
341
- description: 'Optional output schema (JSON, XML, or any format - text or file path).',
342
- },
343
- no_mermaid_validation: {
344
- type: 'boolean',
345
- description: 'Disable automatic mermaid diagram validation and fixing.',
346
327
  }
347
328
  },
348
329
  required: ['query']
@@ -404,7 +385,7 @@ class ProbeAgentMcpServer {
404
385
 
405
386
  // Create agent with configuration
406
387
  const agentConfig = {
407
- path: args.path || process.cwd(),
388
+ path: args.path || (args.allowed_folders && args.allowed_folders[0]) || process.cwd(),
408
389
  promptType: args.prompt || 'code-explorer',
409
390
  customPrompt: systemPrompt,
410
391
  provider: args.provider,
@@ -643,6 +624,7 @@ async function main() {
643
624
  // Create and configure agent
644
625
  const agentConfig = {
645
626
  path: config.path,
627
+ allowedFolders: config.allowedFolders,
646
628
  promptType: config.prompt,
647
629
  customPrompt: systemPrompt,
648
630
  allowEdit: config.allowEdit,
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { MCPClientManager } from './client.js';
7
7
  import { loadMCPConfiguration } from './config.js';
8
+ import { processXmlWithThinkingAndRecovery } from '../xmlParsingUtils.js';
8
9
 
9
10
  /**
10
11
  * Convert MCP tool to XML definition format
@@ -254,18 +255,18 @@ export class MCPXmlBridge {
254
255
 
255
256
  /**
256
257
  * Enhanced XML parser that handles both native and MCP tools
258
+ * Uses the exact same logic as CLI/SDK mode to ensure consistency
257
259
  * @param {string} xmlString - XML string to parse
258
260
  * @param {Array<string>} nativeTools - List of native tool names
259
261
  * @param {MCPXmlBridge} mcpBridge - MCP bridge instance
260
262
  * @returns {Object|null} Parsed tool call
261
263
  */
262
264
  export function parseHybridXmlToolCall(xmlString, nativeTools = [], mcpBridge = null) {
263
- // First try native tools with standard XML parsing
264
- for (const toolName of nativeTools) {
265
- const nativeResult = parseNativeXmlTool(xmlString, toolName);
266
- if (nativeResult) {
267
- return { ...nativeResult, type: 'native' };
268
- }
265
+ // First try native tools with the same logic as CLI/SDK mode
266
+ // This includes thinking tag removal and attempt_complete recovery logic
267
+ const nativeResult = parseNativeXmlToolWithThinking(xmlString, nativeTools);
268
+ if (nativeResult) {
269
+ return { ...nativeResult, type: 'native' };
269
270
  }
270
271
 
271
272
  // Then try MCP tools if bridge is available
@@ -279,6 +280,33 @@ export function parseHybridXmlToolCall(xmlString, nativeTools = [], mcpBridge =
279
280
  return null;
280
281
  }
281
282
 
283
+ /**
284
+ * Parse native XML tools using the same logic as CLI/SDK mode
285
+ * Now uses shared utilities instead of duplicating code
286
+ * @param {string} xmlString - XML string to parse
287
+ * @param {Array<string>} validTools - List of valid tool names
288
+ * @returns {Object|null} Parsed tool call
289
+ */
290
+ function parseNativeXmlToolWithThinking(xmlString, validTools) {
291
+ // Use the shared processing logic
292
+ const { cleanedXmlString, recoveryResult } = processXmlWithThinkingAndRecovery(xmlString, validTools);
293
+
294
+ // If recovery found an attempt_complete pattern, return it
295
+ if (recoveryResult) {
296
+ return recoveryResult;
297
+ }
298
+
299
+ // Use the original parseNativeXmlTool function to parse the cleaned XML string
300
+ for (const toolName of validTools) {
301
+ const result = parseNativeXmlTool(cleanedXmlString, toolName);
302
+ if (result) {
303
+ return result;
304
+ }
305
+ }
306
+
307
+ return null;
308
+ }
309
+
282
310
  /**
283
311
  * Parse native XML tool (existing format)
284
312
  * @param {string} xmlString - XML string
@@ -207,14 +207,24 @@ export function createWrappedTools(baseTools) {
207
207
  // Simple file listing tool
208
208
  export const listFilesTool = {
209
209
  execute: async (params) => {
210
- const { directory = '.' } = params;
210
+ const { directory = '.', workingDirectory } = params;
211
+
212
+ // Use the provided working directory, or fall back to process.cwd()
213
+ const baseCwd = workingDirectory || process.cwd();
214
+
215
+ // Security: Validate path to prevent traversal attacks
216
+ const secureBaseDir = path.resolve(baseCwd);
217
+ const targetDir = path.resolve(secureBaseDir, directory);
218
+ if (!targetDir.startsWith(secureBaseDir + path.sep) && targetDir !== secureBaseDir) {
219
+ throw new Error('Path traversal attempt detected. Access denied.');
220
+ }
211
221
 
212
222
  try {
213
223
  const files = await listFilesByLevel({
214
- directory,
224
+ directory: targetDir,
215
225
  maxFiles: 100,
216
226
  respectGitignore: !process.env.PROBE_NO_GITIGNORE || process.env.PROBE_NO_GITIGNORE === '',
217
- cwd: process.cwd()
227
+ cwd: secureBaseDir
218
228
  });
219
229
 
220
230
  return files;
@@ -227,15 +237,23 @@ export const listFilesTool = {
227
237
  // Simple file search tool
228
238
  export const searchFilesTool = {
229
239
  execute: async (params) => {
230
- const { pattern, directory = '.', recursive = true } = params;
240
+ const { pattern, directory = '.', recursive = true, workingDirectory } = params;
231
241
 
232
242
  if (!pattern) {
233
243
  throw new Error('Pattern is required for file search');
234
244
  }
235
245
 
246
+ // Security: Validate path to prevent traversal attacks
247
+ const baseCwd = workingDirectory || process.cwd();
248
+ const secureBaseDir = path.resolve(baseCwd);
249
+ const targetDir = path.resolve(secureBaseDir, directory);
250
+ if (!targetDir.startsWith(secureBaseDir + path.sep) && targetDir !== secureBaseDir) {
251
+ throw new Error('Path traversal attempt detected. Access denied.');
252
+ }
253
+
236
254
  try {
237
255
  const options = {
238
- cwd: directory,
256
+ cwd: targetDir,
239
257
  ignore: ['node_modules/**', '.git/**'],
240
258
  absolute: false
241
259
  };
@@ -18,6 +18,7 @@ import {
18
18
  parseXmlToolCall
19
19
  } from '../index.js';
20
20
  import { randomUUID } from 'crypto';
21
+ import { processXmlWithThinkingAndRecovery } from './xmlParsingUtils.js';
21
22
 
22
23
  // Create configured tool instances
23
24
  export function createTools(configOptions) {
@@ -134,30 +135,15 @@ User: Find all markdown files in the docs directory, but only at the top level.
134
135
  * @returns {Object|null} - The parsed tool call or null if no valid tool call found
135
136
  */
136
137
  export function parseXmlToolCallWithThinking(xmlString, validTools) {
137
- // Extract thinking content if present (for potential logging or analysis)
138
- const thinkingMatch = xmlString.match(/<thinking>([\s\S]*?)<\/thinking>/);
139
- const thinkingContent = thinkingMatch ? thinkingMatch[1].trim() : null;
140
-
141
- // Remove thinking tags and their content from the XML string
142
- let cleanedXmlString = xmlString.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
143
-
144
- // Check for attempt_complete shorthand (single tag with no closing tag and no parameters)
145
- const attemptCompleteMatch = cleanedXmlString.match(/^<attempt_complete>\s*$/);
146
- if (attemptCompleteMatch) {
147
- // Convert shorthand to full attempt_completion format with special marker
148
- return {
149
- toolName: 'attempt_completion',
150
- params: { result: '__PREVIOUS_RESPONSE__' }
151
- };
138
+ // Use the shared processing logic
139
+ const { cleanedXmlString, recoveryResult } = processXmlWithThinkingAndRecovery(xmlString, validTools);
140
+
141
+ // If recovery found an attempt_complete pattern, return it
142
+ if (recoveryResult) {
143
+ return recoveryResult;
152
144
  }
153
145
 
154
- // Use the original parseXmlToolCall function to parse the cleaned XML string
155
- const parsedTool = parseXmlToolCall(cleanedXmlString, validTools);
156
-
157
- // If debugging is enabled, log the thinking content
158
- if (process.env.DEBUG === '1' && thinkingContent) {
159
- console.log(`[DEBUG] AI Thinking Process:\n${thinkingContent}`);
160
- }
146
+ // Otherwise, use the original parseXmlToolCall function to parse the cleaned XML string
147
+ return parseXmlToolCall(cleanedXmlString, validTools);
148
+ }
161
149
 
162
- return parsedTool;
163
- }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Shared XML parsing utilities used by both CLI/SDK and MCP modes
3
+ * This module contains the core logic for thinking tag removal and attempt_complete recovery
4
+ */
5
+
6
+ /**
7
+ * Remove thinking tags and their content from XML string
8
+ * @param {string} xmlString - The XML string to clean
9
+ * @returns {string} - Cleaned XML string without thinking tags
10
+ */
11
+ export function removeThinkingTags(xmlString) {
12
+ return xmlString.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
13
+ }
14
+
15
+ /**
16
+ * Extract thinking content for potential logging
17
+ * @param {string} xmlString - The XML string to extract from
18
+ * @returns {string|null} - Thinking content or null if not found
19
+ */
20
+ export function extractThinkingContent(xmlString) {
21
+ const thinkingMatch = xmlString.match(/<thinking>([\s\S]*?)<\/thinking>/);
22
+ return thinkingMatch ? thinkingMatch[1].trim() : null;
23
+ }
24
+
25
+ /**
26
+ * Check for attempt_complete recovery patterns and return standardized result
27
+ * @param {string} cleanedXmlString - XML string with thinking tags already removed
28
+ * @param {Array<string>} validTools - List of valid tool names
29
+ * @returns {Object|null} - Standardized attempt_completion result or null
30
+ */
31
+ export function checkAttemptCompleteRecovery(cleanedXmlString, validTools = []) {
32
+ // Enhanced recovery logic for attempt_complete shorthand
33
+ const attemptCompletePatterns = [
34
+ // Standard shorthand with optional whitespace
35
+ /^<attempt_complete>\s*$/,
36
+ // Empty with proper closing tag (common case from the logs)
37
+ /^<attempt_complete>\s*<\/attempt_complete>\s*$/,
38
+ // Self-closing variant
39
+ /^<attempt_complete\s*\/>\s*$/,
40
+ // Incomplete opening tag (missing closing bracket)
41
+ /^<attempt_complete\s*$/,
42
+ // With trailing content (extract just the tag part) - must come after empty tag pattern
43
+ /^<attempt_complete>(.*)$/s,
44
+ // Self-closing with trailing content
45
+ /^<attempt_complete\s*\/>(.*)$/s
46
+ ];
47
+
48
+ for (const pattern of attemptCompletePatterns) {
49
+ const match = cleanedXmlString.match(pattern);
50
+ if (match) {
51
+ // Convert any form of attempt_complete to the standard format
52
+ return {
53
+ toolName: 'attempt_completion',
54
+ params: { result: '__PREVIOUS_RESPONSE__' }
55
+ };
56
+ }
57
+ }
58
+
59
+ // Additional recovery: check if the string contains attempt_complete anywhere
60
+ // and treat the entire response as a completion signal if no other tool tags are found
61
+ if (cleanedXmlString.includes('<attempt_complete') && !hasOtherToolTags(cleanedXmlString, validTools)) {
62
+ // This handles malformed cases where attempt_complete appears but is broken
63
+ return {
64
+ toolName: 'attempt_completion',
65
+ params: { result: '__PREVIOUS_RESPONSE__' }
66
+ };
67
+ }
68
+
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Helper function to check if the XML string contains other tool tags
74
+ * @param {string} xmlString - The XML string to check
75
+ * @param {string[]} validTools - List of valid tool names
76
+ * @returns {boolean} - True if other tool tags are found
77
+ */
78
+ function hasOtherToolTags(xmlString, validTools = []) {
79
+ const defaultTools = ['search', 'query', 'extract', 'listFiles', 'searchFiles', 'implement', 'attempt_completion'];
80
+ const toolsToCheck = validTools.length > 0 ? validTools : defaultTools;
81
+
82
+ // Check for any tool tags other than attempt_complete variants
83
+ for (const tool of toolsToCheck) {
84
+ if (tool !== 'attempt_completion' && xmlString.includes(`<${tool}`)) {
85
+ return true;
86
+ }
87
+ }
88
+ return false;
89
+ }
90
+
91
+ /**
92
+ * Apply the full thinking tag removal and attempt_complete recovery logic
93
+ * This replicates the core logic from parseXmlToolCallWithThinking
94
+ * @param {string} xmlString - The XML string to process
95
+ * @param {Array<string>} validTools - List of valid tool names
96
+ * @returns {Object} - Processing result with cleanedXml and potentialRecovery
97
+ */
98
+ export function processXmlWithThinkingAndRecovery(xmlString, validTools = []) {
99
+ // Extract thinking content if present (for potential logging or analysis)
100
+ const thinkingContent = extractThinkingContent(xmlString);
101
+
102
+ // Remove thinking tags and their content from the XML string
103
+ const cleanedXmlString = removeThinkingTags(xmlString);
104
+
105
+ // Check for attempt_complete recovery patterns
106
+ const recoveryResult = checkAttemptCompleteRecovery(cleanedXmlString, validTools);
107
+
108
+ // If debugging is enabled, log the thinking content
109
+ if (process.env.DEBUG === '1' && thinkingContent) {
110
+ console.log(`[DEBUG] AI Thinking Process:\n${thinkingContent}`);
111
+ }
112
+
113
+ return {
114
+ cleanedXmlString,
115
+ thinkingContent,
116
+ recoveryResult
117
+ };
118
+ }
package/src/utils.js CHANGED
@@ -43,7 +43,7 @@ export async function getBinaryPath(options = {}) {
43
43
 
44
44
  // Check bin directory
45
45
  const isWindows = process.platform === 'win32';
46
- const binaryName = isWindows ? 'probe.exe' : 'probe';
46
+ const binaryName = isWindows ? 'probe.exe' : 'probe-binary';
47
47
  const binaryPath = path.join(binDir, binaryName);
48
48
 
49
49
  if (fs.existsSync(binaryPath) && !forceDownload) {