@probelabs/probe 0.6.0-rc247 → 0.6.0-rc248

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.
@@ -85,7 +85,7 @@ import {
85
85
  validateAndFixMermaidResponse,
86
86
  tryAutoWrapForSimpleSchema
87
87
  } from './schemaUtils.js';
88
- import { removeThinkingTags } from './xmlParsingUtils.js';
88
+ import { removeThinkingTags, extractThinkingContent } from './xmlParsingUtils.js';
89
89
  import { predefinedPrompts } from './shared/prompts.js';
90
90
  import {
91
91
  MCPXmlBridge,
@@ -2904,10 +2904,11 @@ Follow these instructions carefully:
2904
2904
  // Track initial history length for storage
2905
2905
  const oldHistoryLength = this.history.length;
2906
2906
 
2907
- // Reset output buffer for this answer() call — but NOT during schema correction recursion
2908
- // When _schemaFormatted is true, this is a recursive call to fix JSON formatting,
2909
- // and we must preserve the output buffer so the parent call can append it
2910
- if (this._outputBuffer && !options?._schemaFormatted) {
2907
+ // Reset output buffer for this answer() call — but NOT during recursive calls.
2908
+ // _schemaFormatted: recursive call to fix JSON formatting
2909
+ // _completionPromptProcessed: recursive call for completionPrompt follow-up
2910
+ // Both must preserve the output buffer so the parent call can append it.
2911
+ if (this._outputBuffer && !options?._schemaFormatted && !options?._completionPromptProcessed) {
2911
2912
  this._outputBuffer.items = [];
2912
2913
  }
2913
2914
 
@@ -3554,8 +3555,25 @@ Follow these instructions carefully:
3554
3555
  continue; // Don't use broken response, continue the loop
3555
3556
  }
3556
3557
 
3557
- finalResult = prevContent;
3558
- if (this.debug) console.log(`[DEBUG] Using previous response as completion: ${finalResult.substring(0, 100)}...`);
3558
+ // Pre-strip thinking tags to avoid losing content at final cleanup stage
3559
+ const strippedContent = removeThinkingTags(prevContent);
3560
+ if (strippedContent.length > 50) {
3561
+ // Enough content outside thinking tags — use stripped version directly
3562
+ finalResult = strippedContent;
3563
+ if (this.debug) console.log(`[DEBUG] Using previous response (thinking-stripped) as completion: ${finalResult.substring(0, 100)}...`);
3564
+ } else {
3565
+ // Content was mostly/entirely inside thinking tags.
3566
+ // Extract thinking content and use it as the actual answer.
3567
+ const thinkingContent = extractThinkingContent(prevContent);
3568
+ if (thinkingContent && thinkingContent.length > 50) {
3569
+ finalResult = thinkingContent;
3570
+ if (this.debug) console.log(`[DEBUG] Previous response was mostly in thinking tags — using thinking content as completion: ${finalResult.substring(0, 100)}...`);
3571
+ } else {
3572
+ // Neither stripped nor thinking content is substantive — use raw as fallback
3573
+ finalResult = prevContent;
3574
+ if (this.debug) console.log(`[DEBUG] Using previous response as completion (raw): ${finalResult.substring(0, 100)}...`);
3575
+ }
3576
+ }
3559
3577
  } else {
3560
3578
  finalResult = 'Error: No previous response found to use as completion.';
3561
3579
  if (this.debug) console.log(`[DEBUG] No suitable previous response found for attempt_complete shorthand`);
@@ -4296,10 +4314,16 @@ After reviewing, provide your final answer using attempt_completion.`;
4296
4314
 
4297
4315
  // Make a follow-up call with the completion prompt
4298
4316
  // Pass _completionPromptProcessed to prevent infinite loops
4317
+ // Save output buffer — the recursive answer() must not destroy DSL output() content
4318
+ const savedOutputItems = this._outputBuffer ? [...this._outputBuffer.items] : [];
4299
4319
  const completionResult = await this.answer(completionPromptMessage, [], {
4300
4320
  ...options,
4301
4321
  _completionPromptProcessed: true
4302
4322
  });
4323
+ // Restore output buffer so the parent call can append it to the final result
4324
+ if (this._outputBuffer) {
4325
+ this._outputBuffer.items = savedOutputItems;
4326
+ }
4303
4327
 
4304
4328
  // Update finalResult with the result from the completion prompt
4305
4329
  finalResult = completionResult;
@@ -83497,7 +83497,7 @@ You are working with a workspace. Available paths: ${workspaceDesc}
83497
83497
  }
83498
83498
  try {
83499
83499
  const oldHistoryLength = this.history.length;
83500
- if (this._outputBuffer && !options?._schemaFormatted) {
83500
+ if (this._outputBuffer && !options?._schemaFormatted && !options?._completionPromptProcessed) {
83501
83501
  this._outputBuffer.items = [];
83502
83502
  }
83503
83503
  if (this.enableTasks) {
@@ -83942,8 +83942,20 @@ You are working with a workspace. Available paths: ${workspaceDesc}
83942
83942
  completionAttempted = false;
83943
83943
  continue;
83944
83944
  }
83945
- finalResult = prevContent;
83946
- if (this.debug) console.log(`[DEBUG] Using previous response as completion: ${finalResult.substring(0, 100)}...`);
83945
+ const strippedContent = removeThinkingTags(prevContent);
83946
+ if (strippedContent.length > 50) {
83947
+ finalResult = strippedContent;
83948
+ if (this.debug) console.log(`[DEBUG] Using previous response (thinking-stripped) as completion: ${finalResult.substring(0, 100)}...`);
83949
+ } else {
83950
+ const thinkingContent = extractThinkingContent(prevContent);
83951
+ if (thinkingContent && thinkingContent.length > 50) {
83952
+ finalResult = thinkingContent;
83953
+ if (this.debug) console.log(`[DEBUG] Previous response was mostly in thinking tags \u2014 using thinking content as completion: ${finalResult.substring(0, 100)}...`);
83954
+ } else {
83955
+ finalResult = prevContent;
83956
+ if (this.debug) console.log(`[DEBUG] Using previous response as completion (raw): ${finalResult.substring(0, 100)}...`);
83957
+ }
83958
+ }
83947
83959
  } else {
83948
83960
  finalResult = "Error: No previous response found to use as completion.";
83949
83961
  if (this.debug) console.log(`[DEBUG] No suitable previous response found for attempt_complete shorthand`);
@@ -84515,10 +84527,14 @@ ${finalResult}
84515
84527
  </result>
84516
84528
 
84517
84529
  After reviewing, provide your final answer using attempt_completion.`;
84530
+ const savedOutputItems = this._outputBuffer ? [...this._outputBuffer.items] : [];
84518
84531
  const completionResult = await this.answer(completionPromptMessage, [], {
84519
84532
  ...options,
84520
84533
  _completionPromptProcessed: true
84521
84534
  });
84535
+ if (this._outputBuffer) {
84536
+ this._outputBuffer.items = savedOutputItems;
84537
+ }
84522
84538
  finalResult = completionResult;
84523
84539
  if (this.debug) {
84524
84540
  console.log(`[DEBUG] Completion prompt finished. New result length: ${finalResult?.length || 0}`);