@probelabs/probe 0.6.0-rc132 → 0.6.0-rc134

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.
@@ -1928,7 +1928,7 @@ Convert your previous response content into actual JSON data that follows this s
1928
1928
  }
1929
1929
  } else if (reachedMaxIterations && options.schema && this.debug) {
1930
1930
  console.log('[DEBUG] Skipping schema formatting due to max iterations reached without completion');
1931
- } else if (completionAttempted && options.schema) {
1931
+ } else if (completionAttempted && options.schema && !options._schemaFormatted) {
1932
1932
  // For attempt_completion results with schema, still clean markdown if needed
1933
1933
  try {
1934
1934
  finalResult = cleanSchemaResponse(finalResult);
@@ -2083,7 +2083,7 @@ Convert your previous response content into actual JSON data that follows this s
2083
2083
  }
2084
2084
 
2085
2085
  // Final mermaid validation for all responses (regardless of schema or attempt_completion)
2086
- if (!this.disableMermaidValidation) {
2086
+ if (!this.disableMermaidValidation && !options._schemaFormatted) {
2087
2087
  try {
2088
2088
  if (this.debug) {
2089
2089
  console.log(`[DEBUG] Mermaid validation: Performing final mermaid validation on result...`);
@@ -2119,9 +2119,11 @@ Convert your previous response content into actual JSON data that follows this s
2119
2119
  }
2120
2120
 
2121
2121
  // Remove thinking tags from final result before returning to user
2122
- finalResult = removeThinkingTags(finalResult);
2123
- if (this.debug) {
2124
- console.log(`[DEBUG] Removed thinking tags from final result`);
2122
+ if (!options._schemaFormatted) {
2123
+ finalResult = removeThinkingTags(finalResult);
2124
+ if (this.debug) {
2125
+ console.log(`[DEBUG] Removed thinking tags from final result`);
2126
+ }
2125
2127
  }
2126
2128
 
2127
2129
  return finalResult;
@@ -46498,19 +46498,16 @@ function cleanSchemaResponse(response) {
46498
46498
  return trimmed.substring(startIndex, endIndex);
46499
46499
  }
46500
46500
  }
46501
- const firstBracket = Math.min(
46502
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
46503
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
46504
- );
46505
- const lastBracket = Math.max(
46506
- trimmed.lastIndexOf("}"),
46507
- trimmed.lastIndexOf("]")
46508
- );
46509
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
46510
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
46511
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
46512
- return trimmed.substring(firstBracket, lastBracket + 1);
46513
- }
46501
+ let cleaned = trimmed;
46502
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
46503
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
46504
+ cleaned = cleaned.trim();
46505
+ const firstChar = cleaned[0];
46506
+ const lastChar = cleaned[cleaned.length - 1];
46507
+ const isJsonObject = firstChar === "{" && lastChar === "}";
46508
+ const isJsonArray = firstChar === "[" && lastChar === "]";
46509
+ if (isJsonObject || isJsonArray) {
46510
+ return cleaned;
46514
46511
  }
46515
46512
  return response;
46516
46513
  }
@@ -49898,7 +49895,7 @@ Convert your previous response content into actual JSON data that follows this s
49898
49895
  }
49899
49896
  } else if (reachedMaxIterations && options.schema && this.debug) {
49900
49897
  console.log("[DEBUG] Skipping schema formatting due to max iterations reached without completion");
49901
- } else if (completionAttempted && options.schema) {
49898
+ } else if (completionAttempted && options.schema && !options._schemaFormatted) {
49902
49899
  try {
49903
49900
  finalResult = cleanSchemaResponse(finalResult);
49904
49901
  if (!this.disableMermaidValidation) {
@@ -50025,7 +50022,7 @@ Convert your previous response content into actual JSON data that follows this s
50025
50022
  }
50026
50023
  }
50027
50024
  }
50028
- if (!this.disableMermaidValidation) {
50025
+ if (!this.disableMermaidValidation && !options._schemaFormatted) {
50029
50026
  try {
50030
50027
  if (this.debug) {
50031
50028
  console.log(`[DEBUG] Mermaid validation: Performing final mermaid validation on result...`);
@@ -50056,9 +50053,11 @@ Convert your previous response content into actual JSON data that follows this s
50056
50053
  } else if (this.debug) {
50057
50054
  console.log(`[DEBUG] Mermaid validation: Skipped final validation due to disableMermaidValidation option`);
50058
50055
  }
50059
- finalResult = removeThinkingTags(finalResult);
50060
- if (this.debug) {
50061
- console.log(`[DEBUG] Removed thinking tags from final result`);
50056
+ if (!options._schemaFormatted) {
50057
+ finalResult = removeThinkingTags(finalResult);
50058
+ if (this.debug) {
50059
+ console.log(`[DEBUG] Removed thinking tags from final result`);
50060
+ }
50062
50061
  }
50063
50062
  return finalResult;
50064
50063
  } catch (error) {
@@ -51370,7 +51369,7 @@ Please reformat your previous response to match this schema exactly. Only return
51370
51369
  if (!validation.isValid) {
51371
51370
  const correctionPrompt = createJsonCorrectionPrompt(result, schema, validation.error);
51372
51371
  try {
51373
- result = await agent.answer(correctionPrompt, [], { schema });
51372
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true });
51374
51373
  result = cleanSchemaResponse(result);
51375
51374
  const finalValidation = validateJsonResponse(result);
51376
51375
  if (!finalValidation.isValid && args.debug) {
@@ -51652,11 +51651,11 @@ Please reformat your previous response to match this schema exactly. Only return
51652
51651
  if (appTracer) {
51653
51652
  result = await appTracer.withSpan(
51654
51653
  "agent.json_correction",
51655
- () => agent.answer(correctionPrompt, [], { schema }),
51654
+ () => agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true }),
51656
51655
  { "original_error": validation.error }
51657
51656
  );
51658
51657
  } else {
51659
- result = await agent.answer(correctionPrompt, [], { schema });
51658
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true });
51660
51659
  }
51661
51660
  result = cleanSchemaResponse(result);
51662
51661
  const finalValidation = validateJsonResponse(result);
@@ -106,28 +106,28 @@ export function cleanSchemaResponse(response) {
106
106
  }
107
107
  }
108
108
 
109
- // Fallback: Find JSON boundaries anywhere in the text
110
- const firstBracket = Math.min(
111
- trimmed.indexOf('{') >= 0 ? trimmed.indexOf('{') : Infinity,
112
- trimmed.indexOf('[') >= 0 ? trimmed.indexOf('[') : Infinity
113
- );
114
-
115
- const lastBracket = Math.max(
116
- trimmed.lastIndexOf('}'),
117
- trimmed.lastIndexOf(']')
118
- );
119
-
120
- // Only extract if we found valid JSON boundaries
121
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
122
- // Check if the response likely starts with JSON (directly or after minimal content)
123
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
124
-
125
- // If there's minimal content before the first bracket, extract the JSON
126
- if (beforeFirstBracket === '' ||
127
- beforeFirstBracket.match(/^```\w*$/) ||
128
- beforeFirstBracket.split('\n').length <= 2) {
129
- return trimmed.substring(firstBracket, lastBracket + 1);
130
- }
109
+ // Fallback: Check if response is JSON after removing code block markers and whitespace
110
+ // First, remove common code block markers from top and bottom
111
+ let cleaned = trimmed;
112
+
113
+ // Remove opening code block markers (```json, ```, etc.)
114
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, '');
115
+
116
+ // Remove closing code block markers
117
+ cleaned = cleaned.replace(/\n?```\s*$/, '');
118
+
119
+ // Trim whitespace and newlines
120
+ cleaned = cleaned.trim();
121
+
122
+ // Now check if first and last characters are valid JSON boundaries
123
+ const firstChar = cleaned[0];
124
+ const lastChar = cleaned[cleaned.length - 1];
125
+
126
+ const isJsonObject = firstChar === '{' && lastChar === '}';
127
+ const isJsonArray = firstChar === '[' && lastChar === ']';
128
+
129
+ if (isJsonObject || isJsonArray) {
130
+ return cleaned;
131
131
  }
132
132
 
133
133
  return response; // Return original if no extractable JSON found
@@ -71893,19 +71893,16 @@ function cleanSchemaResponse(response) {
71893
71893
  return trimmed.substring(startIndex, endIndex);
71894
71894
  }
71895
71895
  }
71896
- const firstBracket = Math.min(
71897
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
71898
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
71899
- );
71900
- const lastBracket = Math.max(
71901
- trimmed.lastIndexOf("}"),
71902
- trimmed.lastIndexOf("]")
71903
- );
71904
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
71905
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
71906
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
71907
- return trimmed.substring(firstBracket, lastBracket + 1);
71908
- }
71896
+ let cleaned = trimmed;
71897
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
71898
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
71899
+ cleaned = cleaned.trim();
71900
+ const firstChar = cleaned[0];
71901
+ const lastChar = cleaned[cleaned.length - 1];
71902
+ const isJsonObject = firstChar === "{" && lastChar === "}";
71903
+ const isJsonArray = firstChar === "[" && lastChar === "]";
71904
+ if (isJsonObject || isJsonArray) {
71905
+ return cleaned;
71909
71906
  }
71910
71907
  return response;
71911
71908
  }
@@ -75293,7 +75290,7 @@ Convert your previous response content into actual JSON data that follows this s
75293
75290
  }
75294
75291
  } else if (reachedMaxIterations && options.schema && this.debug) {
75295
75292
  console.log("[DEBUG] Skipping schema formatting due to max iterations reached without completion");
75296
- } else if (completionAttempted && options.schema) {
75293
+ } else if (completionAttempted && options.schema && !options._schemaFormatted) {
75297
75294
  try {
75298
75295
  finalResult = cleanSchemaResponse(finalResult);
75299
75296
  if (!this.disableMermaidValidation) {
@@ -75420,7 +75417,7 @@ Convert your previous response content into actual JSON data that follows this s
75420
75417
  }
75421
75418
  }
75422
75419
  }
75423
- if (!this.disableMermaidValidation) {
75420
+ if (!this.disableMermaidValidation && !options._schemaFormatted) {
75424
75421
  try {
75425
75422
  if (this.debug) {
75426
75423
  console.log(`[DEBUG] Mermaid validation: Performing final mermaid validation on result...`);
@@ -75451,9 +75448,11 @@ Convert your previous response content into actual JSON data that follows this s
75451
75448
  } else if (this.debug) {
75452
75449
  console.log(`[DEBUG] Mermaid validation: Skipped final validation due to disableMermaidValidation option`);
75453
75450
  }
75454
- finalResult = removeThinkingTags(finalResult);
75455
- if (this.debug) {
75456
- console.log(`[DEBUG] Removed thinking tags from final result`);
75451
+ if (!options._schemaFormatted) {
75452
+ finalResult = removeThinkingTags(finalResult);
75453
+ if (this.debug) {
75454
+ console.log(`[DEBUG] Removed thinking tags from final result`);
75455
+ }
75457
75456
  }
75458
75457
  return finalResult;
75459
75458
  } catch (error2) {
package/cjs/index.cjs CHANGED
@@ -72073,19 +72073,16 @@ function cleanSchemaResponse(response) {
72073
72073
  return trimmed.substring(startIndex, endIndex);
72074
72074
  }
72075
72075
  }
72076
- const firstBracket = Math.min(
72077
- trimmed.indexOf("{") >= 0 ? trimmed.indexOf("{") : Infinity,
72078
- trimmed.indexOf("[") >= 0 ? trimmed.indexOf("[") : Infinity
72079
- );
72080
- const lastBracket = Math.max(
72081
- trimmed.lastIndexOf("}"),
72082
- trimmed.lastIndexOf("]")
72083
- );
72084
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
72085
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
72086
- if (beforeFirstBracket === "" || beforeFirstBracket.match(/^```\w*$/) || beforeFirstBracket.split("\n").length <= 2) {
72087
- return trimmed.substring(firstBracket, lastBracket + 1);
72088
- }
72076
+ let cleaned = trimmed;
72077
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, "");
72078
+ cleaned = cleaned.replace(/\n?```\s*$/, "");
72079
+ cleaned = cleaned.trim();
72080
+ const firstChar = cleaned[0];
72081
+ const lastChar = cleaned[cleaned.length - 1];
72082
+ const isJsonObject = firstChar === "{" && lastChar === "}";
72083
+ const isJsonArray = firstChar === "[" && lastChar === "]";
72084
+ if (isJsonObject || isJsonArray) {
72085
+ return cleaned;
72089
72086
  }
72090
72087
  return response;
72091
72088
  }
@@ -75473,7 +75470,7 @@ Convert your previous response content into actual JSON data that follows this s
75473
75470
  }
75474
75471
  } else if (reachedMaxIterations && options.schema && this.debug) {
75475
75472
  console.log("[DEBUG] Skipping schema formatting due to max iterations reached without completion");
75476
- } else if (completionAttempted && options.schema) {
75473
+ } else if (completionAttempted && options.schema && !options._schemaFormatted) {
75477
75474
  try {
75478
75475
  finalResult = cleanSchemaResponse(finalResult);
75479
75476
  if (!this.disableMermaidValidation) {
@@ -75600,7 +75597,7 @@ Convert your previous response content into actual JSON data that follows this s
75600
75597
  }
75601
75598
  }
75602
75599
  }
75603
- if (!this.disableMermaidValidation) {
75600
+ if (!this.disableMermaidValidation && !options._schemaFormatted) {
75604
75601
  try {
75605
75602
  if (this.debug) {
75606
75603
  console.log(`[DEBUG] Mermaid validation: Performing final mermaid validation on result...`);
@@ -75631,9 +75628,11 @@ Convert your previous response content into actual JSON data that follows this s
75631
75628
  } else if (this.debug) {
75632
75629
  console.log(`[DEBUG] Mermaid validation: Skipped final validation due to disableMermaidValidation option`);
75633
75630
  }
75634
- finalResult = removeThinkingTags(finalResult);
75635
- if (this.debug) {
75636
- console.log(`[DEBUG] Removed thinking tags from final result`);
75631
+ if (!options._schemaFormatted) {
75632
+ finalResult = removeThinkingTags(finalResult);
75633
+ if (this.debug) {
75634
+ console.log(`[DEBUG] Removed thinking tags from final result`);
75635
+ }
75637
75636
  }
75638
75637
  return finalResult;
75639
75638
  } catch (error2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc132",
3
+ "version": "0.6.0-rc134",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -1928,7 +1928,7 @@ Convert your previous response content into actual JSON data that follows this s
1928
1928
  }
1929
1929
  } else if (reachedMaxIterations && options.schema && this.debug) {
1930
1930
  console.log('[DEBUG] Skipping schema formatting due to max iterations reached without completion');
1931
- } else if (completionAttempted && options.schema) {
1931
+ } else if (completionAttempted && options.schema && !options._schemaFormatted) {
1932
1932
  // For attempt_completion results with schema, still clean markdown if needed
1933
1933
  try {
1934
1934
  finalResult = cleanSchemaResponse(finalResult);
@@ -2083,7 +2083,7 @@ Convert your previous response content into actual JSON data that follows this s
2083
2083
  }
2084
2084
 
2085
2085
  // Final mermaid validation for all responses (regardless of schema or attempt_completion)
2086
- if (!this.disableMermaidValidation) {
2086
+ if (!this.disableMermaidValidation && !options._schemaFormatted) {
2087
2087
  try {
2088
2088
  if (this.debug) {
2089
2089
  console.log(`[DEBUG] Mermaid validation: Performing final mermaid validation on result...`);
@@ -2119,9 +2119,11 @@ Convert your previous response content into actual JSON data that follows this s
2119
2119
  }
2120
2120
 
2121
2121
  // Remove thinking tags from final result before returning to user
2122
- finalResult = removeThinkingTags(finalResult);
2123
- if (this.debug) {
2124
- console.log(`[DEBUG] Removed thinking tags from final result`);
2122
+ if (!options._schemaFormatted) {
2123
+ finalResult = removeThinkingTags(finalResult);
2124
+ if (this.debug) {
2125
+ console.log(`[DEBUG] Removed thinking tags from final result`);
2126
+ }
2125
2127
  }
2126
2128
 
2127
2129
  return finalResult;
@@ -483,7 +483,7 @@ class ProbeAgentMcpServer {
483
483
  // Retry once with correction prompt
484
484
  const correctionPrompt = createJsonCorrectionPrompt(result, schema, validation.error);
485
485
  try {
486
- result = await agent.answer(correctionPrompt, [], { schema });
486
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true });
487
487
  result = cleanSchemaResponse(result);
488
488
 
489
489
  // Validate again after correction
@@ -822,11 +822,11 @@ async function main() {
822
822
  try {
823
823
  if (appTracer) {
824
824
  result = await appTracer.withSpan('agent.json_correction',
825
- () => agent.answer(correctionPrompt, [], { schema }),
825
+ () => agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true }),
826
826
  { 'original_error': validation.error }
827
827
  );
828
828
  } else {
829
- result = await agent.answer(correctionPrompt, [], { schema });
829
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true });
830
830
  }
831
831
  result = cleanSchemaResponse(result);
832
832
 
@@ -106,28 +106,28 @@ export function cleanSchemaResponse(response) {
106
106
  }
107
107
  }
108
108
 
109
- // Fallback: Find JSON boundaries anywhere in the text
110
- const firstBracket = Math.min(
111
- trimmed.indexOf('{') >= 0 ? trimmed.indexOf('{') : Infinity,
112
- trimmed.indexOf('[') >= 0 ? trimmed.indexOf('[') : Infinity
113
- );
114
-
115
- const lastBracket = Math.max(
116
- trimmed.lastIndexOf('}'),
117
- trimmed.lastIndexOf(']')
118
- );
119
-
120
- // Only extract if we found valid JSON boundaries
121
- if (firstBracket < Infinity && lastBracket >= 0 && firstBracket < lastBracket) {
122
- // Check if the response likely starts with JSON (directly or after minimal content)
123
- const beforeFirstBracket = trimmed.substring(0, firstBracket).trim();
124
-
125
- // If there's minimal content before the first bracket, extract the JSON
126
- if (beforeFirstBracket === '' ||
127
- beforeFirstBracket.match(/^```\w*$/) ||
128
- beforeFirstBracket.split('\n').length <= 2) {
129
- return trimmed.substring(firstBracket, lastBracket + 1);
130
- }
109
+ // Fallback: Check if response is JSON after removing code block markers and whitespace
110
+ // First, remove common code block markers from top and bottom
111
+ let cleaned = trimmed;
112
+
113
+ // Remove opening code block markers (```json, ```, etc.)
114
+ cleaned = cleaned.replace(/^```(?:json)?\s*\n?/i, '');
115
+
116
+ // Remove closing code block markers
117
+ cleaned = cleaned.replace(/\n?```\s*$/, '');
118
+
119
+ // Trim whitespace and newlines
120
+ cleaned = cleaned.trim();
121
+
122
+ // Now check if first and last characters are valid JSON boundaries
123
+ const firstChar = cleaned[0];
124
+ const lastChar = cleaned[cleaned.length - 1];
125
+
126
+ const isJsonObject = firstChar === '{' && lastChar === '}';
127
+ const isJsonArray = firstChar === '[' && lastChar === ']';
128
+
129
+ if (isJsonObject || isJsonArray) {
130
+ return cleaned;
131
131
  }
132
132
 
133
133
  return response; // Return original if no extractable JSON found