@probelabs/probe 0.6.0-rc259 → 0.6.0-rc260

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.
@@ -127,6 +127,8 @@ export function parseSimpleCommand(command) {
127
127
  /&&/, // Logical AND
128
128
  /\|\|/, // Logical OR
129
129
  /(?<!\\);/, // Command separator (but not escaped \;)
130
+ /\n/, // Newline command separator (multi-line commands)
131
+ /\r/, // Carriage return (CRLF line endings)
130
132
  /&$/, // Background execution
131
133
  /\$\(/, // Command substitution $()
132
134
  /`/, // Command substitution ``
@@ -260,6 +262,7 @@ export function isComplexPattern(pattern) {
260
262
  /&&/, // Logical AND
261
263
  /\|\|/, // Logical OR
262
264
  /;/, // Command separator
265
+ /\n/, // Newline command separator
263
266
  /&$/, // Background execution
264
267
  /\$\(/, // Command substitution $()
265
268
  /`/, // Command substitution ``
@@ -402,6 +402,29 @@ export class BashPermissionChecker {
402
402
  i++;
403
403
  continue;
404
404
  }
405
+ // Check for newline (command separator in multi-line scripts)
406
+ // Also handle \r\n (CRLF) line endings
407
+ if (char === '\n' || (char === '\r' && nextChar === '\n')) {
408
+ if (current.trim()) {
409
+ components.push(current.trim());
410
+ }
411
+ current = '';
412
+ if (char === '\r') {
413
+ i += 2; // Skip \r\n
414
+ } else {
415
+ i++;
416
+ }
417
+ continue;
418
+ }
419
+ if (char === '\r') {
420
+ // Bare \r without \n
421
+ if (current.trim()) {
422
+ components.push(current.trim());
423
+ }
424
+ current = '';
425
+ i++;
426
+ continue;
427
+ }
405
428
  }
406
429
 
407
430
  current += char;
@@ -12238,6 +12238,10 @@ function parseSimpleCommand(command) {
12238
12238
  // Logical OR
12239
12239
  /(?<!\\);/,
12240
12240
  // Command separator (but not escaped \;)
12241
+ /\n/,
12242
+ // Newline command separator (multi-line commands)
12243
+ /\r/,
12244
+ // Carriage return (CRLF line endings)
12241
12245
  /&$/,
12242
12246
  // Background execution
12243
12247
  /\$\(/,
@@ -12344,6 +12348,8 @@ function isComplexPattern(pattern) {
12344
12348
  // Logical OR
12345
12349
  /;/,
12346
12350
  // Command separator
12351
+ /\n/,
12352
+ // Newline command separator
12347
12353
  /&$/,
12348
12354
  // Background execution
12349
12355
  /\$\(/,
@@ -12716,6 +12722,26 @@ var init_bashPermissions = __esm({
12716
12722
  i++;
12717
12723
  continue;
12718
12724
  }
12725
+ if (char === "\n" || char === "\r" && nextChar === "\n") {
12726
+ if (current2.trim()) {
12727
+ components.push(current2.trim());
12728
+ }
12729
+ current2 = "";
12730
+ if (char === "\r") {
12731
+ i += 2;
12732
+ } else {
12733
+ i++;
12734
+ }
12735
+ continue;
12736
+ }
12737
+ if (char === "\r") {
12738
+ if (current2.trim()) {
12739
+ components.push(current2.trim());
12740
+ }
12741
+ current2 = "";
12742
+ i++;
12743
+ continue;
12744
+ }
12719
12745
  }
12720
12746
  current2 += char;
12721
12747
  i++;
@@ -24794,7 +24820,11 @@ var init_esm3 = __esm({
24794
24820
  #matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
24795
24821
  const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
24796
24822
  const lastgs = pattern.lastIndexOf(GLOBSTAR);
24797
- const [head2, body, tail] = [
24823
+ const [head2, body, tail] = partial ? [
24824
+ pattern.slice(patternIndex, firstgs),
24825
+ pattern.slice(firstgs + 1),
24826
+ []
24827
+ ] : [
24798
24828
  pattern.slice(patternIndex, firstgs),
24799
24829
  pattern.slice(firstgs + 1, lastgs),
24800
24830
  pattern.slice(lastgs + 1)
@@ -24831,7 +24861,7 @@ var init_esm3 = __esm({
24831
24861
  return false;
24832
24862
  }
24833
24863
  }
24834
- return sawSome;
24864
+ return partial || sawSome;
24835
24865
  }
24836
24866
  const bodySegments = [[[], 0]];
24837
24867
  let currentBody = bodySegments[0];
@@ -24880,7 +24910,7 @@ var init_esm3 = __esm({
24880
24910
  }
24881
24911
  fileIndex++;
24882
24912
  }
24883
- return null;
24913
+ return partial || null;
24884
24914
  }
24885
24915
  #matchOne(file, pattern, partial, fileIndex, patternIndex) {
24886
24916
  let fi;
@@ -70110,6 +70140,15 @@ function normalizeJsonQuotes(str) {
70110
70140
  }
70111
70141
  return result;
70112
70142
  }
70143
+ function isCodeBlockEmbeddedInDocument(text, match2) {
70144
+ const beforeBlock = text.substring(0, match2.index).trim();
70145
+ const afterBlock = text.substring(match2.index + match2[0].length).trim();
70146
+ const hasMarkdownHeadings = /^#{1,6}\s/m.test(beforeBlock) || /^#{1,6}\s/m.test(afterBlock);
70147
+ if (hasMarkdownHeadings) {
70148
+ return true;
70149
+ }
70150
+ return false;
70151
+ }
70113
70152
  function cleanSchemaResponse(response) {
70114
70153
  if (!response || typeof response !== "string") {
70115
70154
  return response;
@@ -70129,11 +70168,11 @@ function cleanSchemaResponse(response) {
70129
70168
  return cleanSchemaResponse(innerContent);
70130
70169
  }
70131
70170
  const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
70132
- if (jsonBlockMatch) {
70171
+ if (jsonBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, jsonBlockMatch)) {
70133
70172
  return normalizeJsonQuotes(jsonBlockMatch[1].trim());
70134
70173
  }
70135
70174
  const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
70136
- if (anyBlockMatch) {
70175
+ if (anyBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, anyBlockMatch)) {
70137
70176
  return normalizeJsonQuotes(anyBlockMatch[1].trim());
70138
70177
  }
70139
70178
  const codeBlockPatterns = [
@@ -70142,7 +70181,7 @@ function cleanSchemaResponse(response) {
70142
70181
  ];
70143
70182
  for (const pattern of codeBlockPatterns) {
70144
70183
  const match2 = trimmed.match(pattern);
70145
- if (match2) {
70184
+ if (match2 && !isCodeBlockEmbeddedInDocument(trimmed, match2)) {
70146
70185
  return normalizeJsonQuotes(match2[1].trim());
70147
70186
  }
70148
70187
  }
@@ -70153,7 +70192,7 @@ function cleanSchemaResponse(response) {
70153
70192
  }
70154
70193
  const codeBlockStartPattern = /```(?:json)?\s*\n?\s*([{\[])/;
70155
70194
  const codeBlockMatch = trimmed.match(codeBlockStartPattern);
70156
- if (codeBlockMatch) {
70195
+ if (codeBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, codeBlockMatch)) {
70157
70196
  const startIndex = codeBlockMatch.index + codeBlockMatch[0].length - 1;
70158
70197
  const openChar = codeBlockMatch[1];
70159
70198
  const closeChar = openChar === "{" ? "}" : "]";
@@ -266,6 +266,36 @@ function normalizeJsonQuotes(str) {
266
266
  return result;
267
267
  }
268
268
 
269
+ /**
270
+ * Check if a code block is embedded within a structured markdown document.
271
+ * Used to avoid extracting embedded JSON examples from markdown text.
272
+ * Issue #456: attempt_completion results containing markdown with JSON code block
273
+ * documentation examples were having the examples extracted as structured output.
274
+ *
275
+ * Normal AI behavior: AI wraps JSON answer in a code block with brief explanation text.
276
+ * Issue #456: AI returns a markdown document that contains JSON code blocks as examples.
277
+ *
278
+ * We distinguish these by checking if the surrounding text contains markdown structural
279
+ * elements (headings) which indicate a document rather than a brief explanation.
280
+ *
281
+ * @param {string} text - The full trimmed text
282
+ * @param {RegExpMatchArray} match - The regex match for the code block
283
+ * @returns {boolean} - true if the code block is embedded in a markdown document
284
+ */
285
+ function isCodeBlockEmbeddedInDocument(text, match) {
286
+ const beforeBlock = text.substring(0, match.index).trim();
287
+ const afterBlock = text.substring(match.index + match[0].length).trim();
288
+
289
+ // Check if surrounding text contains markdown headings (lines starting with #)
290
+ // This is a strong signal that the content is a structured document, not just explanation text
291
+ const hasMarkdownHeadings = /^#{1,6}\s/m.test(beforeBlock) || /^#{1,6}\s/m.test(afterBlock);
292
+ if (hasMarkdownHeadings) {
293
+ return true;
294
+ }
295
+
296
+ return false;
297
+ }
298
+
269
299
  /**
270
300
  * Clean AI response by extracting JSON content when response contains JSON
271
301
  * Only processes responses that contain JSON structures { or [
@@ -311,15 +341,20 @@ export function cleanSchemaResponse(response) {
311
341
  }
312
342
 
313
343
  // First, look for JSON after code block markers - similar to mermaid extraction
344
+ // Only extract from code blocks when they are the primary content (not embedded examples in markdown).
345
+ // Issue #456: When attempt_completion result contains markdown with embedded JSON code blocks
346
+ // as documentation examples, extracting those blocks produces wrong structured output.
347
+ // We check that there's no significant text content outside the code block.
348
+
314
349
  // Try with json language specifier
315
350
  const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
316
- if (jsonBlockMatch) {
351
+ if (jsonBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, jsonBlockMatch)) {
317
352
  return normalizeJsonQuotes(jsonBlockMatch[1].trim());
318
353
  }
319
354
 
320
355
  // Try any code block with JSON content
321
356
  const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
322
- if (anyBlockMatch) {
357
+ if (anyBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, anyBlockMatch)) {
323
358
  return normalizeJsonQuotes(anyBlockMatch[1].trim());
324
359
  }
325
360
 
@@ -331,7 +366,7 @@ export function cleanSchemaResponse(response) {
331
366
 
332
367
  for (const pattern of codeBlockPatterns) {
333
368
  const match = trimmed.match(pattern);
334
- if (match) {
369
+ if (match && !isCodeBlockEmbeddedInDocument(trimmed, match)) {
335
370
  return normalizeJsonQuotes(match[1].trim());
336
371
  }
337
372
  }
@@ -345,10 +380,11 @@ export function cleanSchemaResponse(response) {
345
380
  }
346
381
 
347
382
  // Look for code block start followed immediately by JSON
383
+ // Only extract if the code block is not embedded in a structured markdown document
348
384
  const codeBlockStartPattern = /```(?:json)?\s*\n?\s*([{\[])/;
349
385
  const codeBlockMatch = trimmed.match(codeBlockStartPattern);
350
386
 
351
- if (codeBlockMatch) {
387
+ if (codeBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, codeBlockMatch)) {
352
388
  const startIndex = codeBlockMatch.index + codeBlockMatch[0].length - 1; // Position of the bracket
353
389
 
354
390
  // Find the matching closing bracket
@@ -17506,7 +17506,7 @@ var require_package2 = __commonJS({
17506
17506
  module2.exports = {
17507
17507
  name: "@aws-sdk/client-bedrock-runtime",
17508
17508
  description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
17509
- version: "3.997.0",
17509
+ version: "3.998.0",
17510
17510
  scripts: {
17511
17511
  build: "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
17512
17512
  "build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
@@ -17526,49 +17526,49 @@ var require_package2 = __commonJS({
17526
17526
  dependencies: {
17527
17527
  "@aws-crypto/sha256-browser": "5.2.0",
17528
17528
  "@aws-crypto/sha256-js": "5.2.0",
17529
- "@aws-sdk/core": "^3.973.13",
17530
- "@aws-sdk/credential-provider-node": "^3.972.12",
17531
- "@aws-sdk/eventstream-handler-node": "^3.972.7",
17532
- "@aws-sdk/middleware-eventstream": "^3.972.4",
17533
- "@aws-sdk/middleware-host-header": "^3.972.4",
17534
- "@aws-sdk/middleware-logger": "^3.972.4",
17535
- "@aws-sdk/middleware-recursion-detection": "^3.972.4",
17536
- "@aws-sdk/middleware-user-agent": "^3.972.13",
17537
- "@aws-sdk/middleware-websocket": "^3.972.8",
17538
- "@aws-sdk/region-config-resolver": "^3.972.4",
17539
- "@aws-sdk/token-providers": "3.997.0",
17540
- "@aws-sdk/types": "^3.973.2",
17541
- "@aws-sdk/util-endpoints": "^3.996.1",
17542
- "@aws-sdk/util-user-agent-browser": "^3.972.4",
17543
- "@aws-sdk/util-user-agent-node": "^3.972.12",
17544
- "@smithy/config-resolver": "^4.4.7",
17545
- "@smithy/core": "^3.23.4",
17546
- "@smithy/eventstream-serde-browser": "^4.2.9",
17547
- "@smithy/eventstream-serde-config-resolver": "^4.3.9",
17548
- "@smithy/eventstream-serde-node": "^4.2.9",
17549
- "@smithy/fetch-http-handler": "^5.3.10",
17550
- "@smithy/hash-node": "^4.2.9",
17551
- "@smithy/invalid-dependency": "^4.2.9",
17552
- "@smithy/middleware-content-length": "^4.2.9",
17553
- "@smithy/middleware-endpoint": "^4.4.18",
17554
- "@smithy/middleware-retry": "^4.4.35",
17555
- "@smithy/middleware-serde": "^4.2.10",
17556
- "@smithy/middleware-stack": "^4.2.9",
17557
- "@smithy/node-config-provider": "^4.3.9",
17558
- "@smithy/node-http-handler": "^4.4.11",
17559
- "@smithy/protocol-http": "^5.3.9",
17560
- "@smithy/smithy-client": "^4.11.7",
17561
- "@smithy/types": "^4.12.1",
17562
- "@smithy/url-parser": "^4.2.9",
17529
+ "@aws-sdk/core": "^3.973.14",
17530
+ "@aws-sdk/credential-provider-node": "^3.972.13",
17531
+ "@aws-sdk/eventstream-handler-node": "^3.972.8",
17532
+ "@aws-sdk/middleware-eventstream": "^3.972.5",
17533
+ "@aws-sdk/middleware-host-header": "^3.972.5",
17534
+ "@aws-sdk/middleware-logger": "^3.972.5",
17535
+ "@aws-sdk/middleware-recursion-detection": "^3.972.5",
17536
+ "@aws-sdk/middleware-user-agent": "^3.972.14",
17537
+ "@aws-sdk/middleware-websocket": "^3.972.9",
17538
+ "@aws-sdk/region-config-resolver": "^3.972.5",
17539
+ "@aws-sdk/token-providers": "3.998.0",
17540
+ "@aws-sdk/types": "^3.973.3",
17541
+ "@aws-sdk/util-endpoints": "^3.996.2",
17542
+ "@aws-sdk/util-user-agent-browser": "^3.972.5",
17543
+ "@aws-sdk/util-user-agent-node": "^3.972.13",
17544
+ "@smithy/config-resolver": "^4.4.9",
17545
+ "@smithy/core": "^3.23.6",
17546
+ "@smithy/eventstream-serde-browser": "^4.2.10",
17547
+ "@smithy/eventstream-serde-config-resolver": "^4.3.10",
17548
+ "@smithy/eventstream-serde-node": "^4.2.10",
17549
+ "@smithy/fetch-http-handler": "^5.3.11",
17550
+ "@smithy/hash-node": "^4.2.10",
17551
+ "@smithy/invalid-dependency": "^4.2.10",
17552
+ "@smithy/middleware-content-length": "^4.2.10",
17553
+ "@smithy/middleware-endpoint": "^4.4.20",
17554
+ "@smithy/middleware-retry": "^4.4.37",
17555
+ "@smithy/middleware-serde": "^4.2.11",
17556
+ "@smithy/middleware-stack": "^4.2.10",
17557
+ "@smithy/node-config-provider": "^4.3.10",
17558
+ "@smithy/node-http-handler": "^4.4.12",
17559
+ "@smithy/protocol-http": "^5.3.10",
17560
+ "@smithy/smithy-client": "^4.12.0",
17561
+ "@smithy/types": "^4.13.0",
17562
+ "@smithy/url-parser": "^4.2.10",
17563
17563
  "@smithy/util-base64": "^4.3.1",
17564
17564
  "@smithy/util-body-length-browser": "^4.2.1",
17565
17565
  "@smithy/util-body-length-node": "^4.2.2",
17566
- "@smithy/util-defaults-mode-browser": "^4.3.34",
17567
- "@smithy/util-defaults-mode-node": "^4.2.37",
17568
- "@smithy/util-endpoints": "^3.2.9",
17569
- "@smithy/util-middleware": "^4.2.9",
17570
- "@smithy/util-retry": "^4.2.9",
17571
- "@smithy/util-stream": "^4.5.14",
17566
+ "@smithy/util-defaults-mode-browser": "^4.3.36",
17567
+ "@smithy/util-defaults-mode-node": "^4.2.39",
17568
+ "@smithy/util-endpoints": "^3.3.1",
17569
+ "@smithy/util-middleware": "^4.2.10",
17570
+ "@smithy/util-retry": "^4.2.10",
17571
+ "@smithy/util-stream": "^4.5.15",
17572
17572
  "@smithy/util-utf8": "^4.2.1",
17573
17573
  tslib: "^2.6.2"
17574
17574
  },
@@ -18287,7 +18287,7 @@ var init_package = __esm({
18287
18287
  "node_modules/@aws-sdk/nested-clients/package.json"() {
18288
18288
  package_default = {
18289
18289
  name: "@aws-sdk/nested-clients",
18290
- version: "3.996.1",
18290
+ version: "3.996.2",
18291
18291
  description: "Nested clients for AWS SDK packages.",
18292
18292
  main: "./dist-cjs/index.js",
18293
18293
  module: "./dist-es/index.js",
@@ -18316,40 +18316,40 @@ var init_package = __esm({
18316
18316
  dependencies: {
18317
18317
  "@aws-crypto/sha256-browser": "5.2.0",
18318
18318
  "@aws-crypto/sha256-js": "5.2.0",
18319
- "@aws-sdk/core": "^3.973.13",
18320
- "@aws-sdk/middleware-host-header": "^3.972.4",
18321
- "@aws-sdk/middleware-logger": "^3.972.4",
18322
- "@aws-sdk/middleware-recursion-detection": "^3.972.4",
18323
- "@aws-sdk/middleware-user-agent": "^3.972.13",
18324
- "@aws-sdk/region-config-resolver": "^3.972.4",
18325
- "@aws-sdk/types": "^3.973.2",
18326
- "@aws-sdk/util-endpoints": "^3.996.1",
18327
- "@aws-sdk/util-user-agent-browser": "^3.972.4",
18328
- "@aws-sdk/util-user-agent-node": "^3.972.12",
18329
- "@smithy/config-resolver": "^4.4.7",
18330
- "@smithy/core": "^3.23.4",
18331
- "@smithy/fetch-http-handler": "^5.3.10",
18332
- "@smithy/hash-node": "^4.2.9",
18333
- "@smithy/invalid-dependency": "^4.2.9",
18334
- "@smithy/middleware-content-length": "^4.2.9",
18335
- "@smithy/middleware-endpoint": "^4.4.18",
18336
- "@smithy/middleware-retry": "^4.4.35",
18337
- "@smithy/middleware-serde": "^4.2.10",
18338
- "@smithy/middleware-stack": "^4.2.9",
18339
- "@smithy/node-config-provider": "^4.3.9",
18340
- "@smithy/node-http-handler": "^4.4.11",
18341
- "@smithy/protocol-http": "^5.3.9",
18342
- "@smithy/smithy-client": "^4.11.7",
18343
- "@smithy/types": "^4.12.1",
18344
- "@smithy/url-parser": "^4.2.9",
18319
+ "@aws-sdk/core": "^3.973.14",
18320
+ "@aws-sdk/middleware-host-header": "^3.972.5",
18321
+ "@aws-sdk/middleware-logger": "^3.972.5",
18322
+ "@aws-sdk/middleware-recursion-detection": "^3.972.5",
18323
+ "@aws-sdk/middleware-user-agent": "^3.972.14",
18324
+ "@aws-sdk/region-config-resolver": "^3.972.5",
18325
+ "@aws-sdk/types": "^3.973.3",
18326
+ "@aws-sdk/util-endpoints": "^3.996.2",
18327
+ "@aws-sdk/util-user-agent-browser": "^3.972.5",
18328
+ "@aws-sdk/util-user-agent-node": "^3.972.13",
18329
+ "@smithy/config-resolver": "^4.4.9",
18330
+ "@smithy/core": "^3.23.6",
18331
+ "@smithy/fetch-http-handler": "^5.3.11",
18332
+ "@smithy/hash-node": "^4.2.10",
18333
+ "@smithy/invalid-dependency": "^4.2.10",
18334
+ "@smithy/middleware-content-length": "^4.2.10",
18335
+ "@smithy/middleware-endpoint": "^4.4.20",
18336
+ "@smithy/middleware-retry": "^4.4.37",
18337
+ "@smithy/middleware-serde": "^4.2.11",
18338
+ "@smithy/middleware-stack": "^4.2.10",
18339
+ "@smithy/node-config-provider": "^4.3.10",
18340
+ "@smithy/node-http-handler": "^4.4.12",
18341
+ "@smithy/protocol-http": "^5.3.10",
18342
+ "@smithy/smithy-client": "^4.12.0",
18343
+ "@smithy/types": "^4.13.0",
18344
+ "@smithy/url-parser": "^4.2.10",
18345
18345
  "@smithy/util-base64": "^4.3.1",
18346
18346
  "@smithy/util-body-length-browser": "^4.2.1",
18347
18347
  "@smithy/util-body-length-node": "^4.2.2",
18348
- "@smithy/util-defaults-mode-browser": "^4.3.34",
18349
- "@smithy/util-defaults-mode-node": "^4.2.37",
18350
- "@smithy/util-endpoints": "^3.2.9",
18351
- "@smithy/util-middleware": "^4.2.9",
18352
- "@smithy/util-retry": "^4.2.9",
18348
+ "@smithy/util-defaults-mode-browser": "^4.3.36",
18349
+ "@smithy/util-defaults-mode-node": "^4.2.39",
18350
+ "@smithy/util-endpoints": "^3.3.1",
18351
+ "@smithy/util-middleware": "^4.2.10",
18352
+ "@smithy/util-retry": "^4.2.10",
18353
18353
  "@smithy/util-utf8": "^4.2.1",
18354
18354
  tslib: "^2.6.2"
18355
18355
  },
@@ -39519,6 +39519,10 @@ function parseSimpleCommand(command) {
39519
39519
  // Logical OR
39520
39520
  /(?<!\\);/,
39521
39521
  // Command separator (but not escaped \;)
39522
+ /\n/,
39523
+ // Newline command separator (multi-line commands)
39524
+ /\r/,
39525
+ // Carriage return (CRLF line endings)
39522
39526
  /&$/,
39523
39527
  // Background execution
39524
39528
  /\$\(/,
@@ -39625,6 +39629,8 @@ function isComplexPattern(pattern) {
39625
39629
  // Logical OR
39626
39630
  /;/,
39627
39631
  // Command separator
39632
+ /\n/,
39633
+ // Newline command separator
39628
39634
  /&$/,
39629
39635
  // Background execution
39630
39636
  /\$\(/,
@@ -39997,6 +40003,26 @@ var init_bashPermissions = __esm({
39997
40003
  i5++;
39998
40004
  continue;
39999
40005
  }
40006
+ if (char === "\n" || char === "\r" && nextChar === "\n") {
40007
+ if (current2.trim()) {
40008
+ components.push(current2.trim());
40009
+ }
40010
+ current2 = "";
40011
+ if (char === "\r") {
40012
+ i5 += 2;
40013
+ } else {
40014
+ i5++;
40015
+ }
40016
+ continue;
40017
+ }
40018
+ if (char === "\r") {
40019
+ if (current2.trim()) {
40020
+ components.push(current2.trim());
40021
+ }
40022
+ current2 = "";
40023
+ i5++;
40024
+ continue;
40025
+ }
40000
40026
  }
40001
40027
  current2 += char;
40002
40028
  i5++;
@@ -52076,7 +52102,11 @@ var init_esm3 = __esm({
52076
52102
  #matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
52077
52103
  const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
52078
52104
  const lastgs = pattern.lastIndexOf(GLOBSTAR);
52079
- const [head2, body, tail] = [
52105
+ const [head2, body, tail] = partial ? [
52106
+ pattern.slice(patternIndex, firstgs),
52107
+ pattern.slice(firstgs + 1),
52108
+ []
52109
+ ] : [
52080
52110
  pattern.slice(patternIndex, firstgs),
52081
52111
  pattern.slice(firstgs + 1, lastgs),
52082
52112
  pattern.slice(lastgs + 1)
@@ -52113,7 +52143,7 @@ var init_esm3 = __esm({
52113
52143
  return false;
52114
52144
  }
52115
52145
  }
52116
- return sawSome;
52146
+ return partial || sawSome;
52117
52147
  }
52118
52148
  const bodySegments = [[[], 0]];
52119
52149
  let currentBody = bodySegments[0];
@@ -52162,7 +52192,7 @@ var init_esm3 = __esm({
52162
52192
  }
52163
52193
  fileIndex++;
52164
52194
  }
52165
- return null;
52195
+ return partial || null;
52166
52196
  }
52167
52197
  #matchOne(file, pattern, partial, fileIndex, patternIndex) {
52168
52198
  let fi;
@@ -96958,6 +96988,15 @@ function normalizeJsonQuotes(str) {
96958
96988
  }
96959
96989
  return result;
96960
96990
  }
96991
+ function isCodeBlockEmbeddedInDocument(text, match2) {
96992
+ const beforeBlock = text.substring(0, match2.index).trim();
96993
+ const afterBlock = text.substring(match2.index + match2[0].length).trim();
96994
+ const hasMarkdownHeadings = /^#{1,6}\s/m.test(beforeBlock) || /^#{1,6}\s/m.test(afterBlock);
96995
+ if (hasMarkdownHeadings) {
96996
+ return true;
96997
+ }
96998
+ return false;
96999
+ }
96961
97000
  function cleanSchemaResponse(response) {
96962
97001
  if (!response || typeof response !== "string") {
96963
97002
  return response;
@@ -96977,11 +97016,11 @@ function cleanSchemaResponse(response) {
96977
97016
  return cleanSchemaResponse(innerContent);
96978
97017
  }
96979
97018
  const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
96980
- if (jsonBlockMatch) {
97019
+ if (jsonBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, jsonBlockMatch)) {
96981
97020
  return normalizeJsonQuotes(jsonBlockMatch[1].trim());
96982
97021
  }
96983
97022
  const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
96984
- if (anyBlockMatch) {
97023
+ if (anyBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, anyBlockMatch)) {
96985
97024
  return normalizeJsonQuotes(anyBlockMatch[1].trim());
96986
97025
  }
96987
97026
  const codeBlockPatterns = [
@@ -96990,7 +97029,7 @@ function cleanSchemaResponse(response) {
96990
97029
  ];
96991
97030
  for (const pattern of codeBlockPatterns) {
96992
97031
  const match2 = trimmed.match(pattern);
96993
- if (match2) {
97032
+ if (match2 && !isCodeBlockEmbeddedInDocument(trimmed, match2)) {
96994
97033
  return normalizeJsonQuotes(match2[1].trim());
96995
97034
  }
96996
97035
  }
@@ -97001,7 +97040,7 @@ function cleanSchemaResponse(response) {
97001
97040
  }
97002
97041
  const codeBlockStartPattern = /```(?:json)?\s*\n?\s*([{\[])/;
97003
97042
  const codeBlockMatch = trimmed.match(codeBlockStartPattern);
97004
- if (codeBlockMatch) {
97043
+ if (codeBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, codeBlockMatch)) {
97005
97044
  const startIndex = codeBlockMatch.index + codeBlockMatch[0].length - 1;
97006
97045
  const openChar = codeBlockMatch[1];
97007
97046
  const closeChar = openChar === "{" ? "}" : "]";
package/cjs/index.cjs CHANGED
@@ -19363,7 +19363,7 @@ var require_package2 = __commonJS({
19363
19363
  module2.exports = {
19364
19364
  name: "@aws-sdk/client-bedrock-runtime",
19365
19365
  description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
19366
- version: "3.997.0",
19366
+ version: "3.998.0",
19367
19367
  scripts: {
19368
19368
  build: "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
19369
19369
  "build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
@@ -19383,49 +19383,49 @@ var require_package2 = __commonJS({
19383
19383
  dependencies: {
19384
19384
  "@aws-crypto/sha256-browser": "5.2.0",
19385
19385
  "@aws-crypto/sha256-js": "5.2.0",
19386
- "@aws-sdk/core": "^3.973.13",
19387
- "@aws-sdk/credential-provider-node": "^3.972.12",
19388
- "@aws-sdk/eventstream-handler-node": "^3.972.7",
19389
- "@aws-sdk/middleware-eventstream": "^3.972.4",
19390
- "@aws-sdk/middleware-host-header": "^3.972.4",
19391
- "@aws-sdk/middleware-logger": "^3.972.4",
19392
- "@aws-sdk/middleware-recursion-detection": "^3.972.4",
19393
- "@aws-sdk/middleware-user-agent": "^3.972.13",
19394
- "@aws-sdk/middleware-websocket": "^3.972.8",
19395
- "@aws-sdk/region-config-resolver": "^3.972.4",
19396
- "@aws-sdk/token-providers": "3.997.0",
19397
- "@aws-sdk/types": "^3.973.2",
19398
- "@aws-sdk/util-endpoints": "^3.996.1",
19399
- "@aws-sdk/util-user-agent-browser": "^3.972.4",
19400
- "@aws-sdk/util-user-agent-node": "^3.972.12",
19401
- "@smithy/config-resolver": "^4.4.7",
19402
- "@smithy/core": "^3.23.4",
19403
- "@smithy/eventstream-serde-browser": "^4.2.9",
19404
- "@smithy/eventstream-serde-config-resolver": "^4.3.9",
19405
- "@smithy/eventstream-serde-node": "^4.2.9",
19406
- "@smithy/fetch-http-handler": "^5.3.10",
19407
- "@smithy/hash-node": "^4.2.9",
19408
- "@smithy/invalid-dependency": "^4.2.9",
19409
- "@smithy/middleware-content-length": "^4.2.9",
19410
- "@smithy/middleware-endpoint": "^4.4.18",
19411
- "@smithy/middleware-retry": "^4.4.35",
19412
- "@smithy/middleware-serde": "^4.2.10",
19413
- "@smithy/middleware-stack": "^4.2.9",
19414
- "@smithy/node-config-provider": "^4.3.9",
19415
- "@smithy/node-http-handler": "^4.4.11",
19416
- "@smithy/protocol-http": "^5.3.9",
19417
- "@smithy/smithy-client": "^4.11.7",
19418
- "@smithy/types": "^4.12.1",
19419
- "@smithy/url-parser": "^4.2.9",
19386
+ "@aws-sdk/core": "^3.973.14",
19387
+ "@aws-sdk/credential-provider-node": "^3.972.13",
19388
+ "@aws-sdk/eventstream-handler-node": "^3.972.8",
19389
+ "@aws-sdk/middleware-eventstream": "^3.972.5",
19390
+ "@aws-sdk/middleware-host-header": "^3.972.5",
19391
+ "@aws-sdk/middleware-logger": "^3.972.5",
19392
+ "@aws-sdk/middleware-recursion-detection": "^3.972.5",
19393
+ "@aws-sdk/middleware-user-agent": "^3.972.14",
19394
+ "@aws-sdk/middleware-websocket": "^3.972.9",
19395
+ "@aws-sdk/region-config-resolver": "^3.972.5",
19396
+ "@aws-sdk/token-providers": "3.998.0",
19397
+ "@aws-sdk/types": "^3.973.3",
19398
+ "@aws-sdk/util-endpoints": "^3.996.2",
19399
+ "@aws-sdk/util-user-agent-browser": "^3.972.5",
19400
+ "@aws-sdk/util-user-agent-node": "^3.972.13",
19401
+ "@smithy/config-resolver": "^4.4.9",
19402
+ "@smithy/core": "^3.23.6",
19403
+ "@smithy/eventstream-serde-browser": "^4.2.10",
19404
+ "@smithy/eventstream-serde-config-resolver": "^4.3.10",
19405
+ "@smithy/eventstream-serde-node": "^4.2.10",
19406
+ "@smithy/fetch-http-handler": "^5.3.11",
19407
+ "@smithy/hash-node": "^4.2.10",
19408
+ "@smithy/invalid-dependency": "^4.2.10",
19409
+ "@smithy/middleware-content-length": "^4.2.10",
19410
+ "@smithy/middleware-endpoint": "^4.4.20",
19411
+ "@smithy/middleware-retry": "^4.4.37",
19412
+ "@smithy/middleware-serde": "^4.2.11",
19413
+ "@smithy/middleware-stack": "^4.2.10",
19414
+ "@smithy/node-config-provider": "^4.3.10",
19415
+ "@smithy/node-http-handler": "^4.4.12",
19416
+ "@smithy/protocol-http": "^5.3.10",
19417
+ "@smithy/smithy-client": "^4.12.0",
19418
+ "@smithy/types": "^4.13.0",
19419
+ "@smithy/url-parser": "^4.2.10",
19420
19420
  "@smithy/util-base64": "^4.3.1",
19421
19421
  "@smithy/util-body-length-browser": "^4.2.1",
19422
19422
  "@smithy/util-body-length-node": "^4.2.2",
19423
- "@smithy/util-defaults-mode-browser": "^4.3.34",
19424
- "@smithy/util-defaults-mode-node": "^4.2.37",
19425
- "@smithy/util-endpoints": "^3.2.9",
19426
- "@smithy/util-middleware": "^4.2.9",
19427
- "@smithy/util-retry": "^4.2.9",
19428
- "@smithy/util-stream": "^4.5.14",
19423
+ "@smithy/util-defaults-mode-browser": "^4.3.36",
19424
+ "@smithy/util-defaults-mode-node": "^4.2.39",
19425
+ "@smithy/util-endpoints": "^3.3.1",
19426
+ "@smithy/util-middleware": "^4.2.10",
19427
+ "@smithy/util-retry": "^4.2.10",
19428
+ "@smithy/util-stream": "^4.5.15",
19429
19429
  "@smithy/util-utf8": "^4.2.1",
19430
19430
  tslib: "^2.6.2"
19431
19431
  },
@@ -20144,7 +20144,7 @@ var init_package = __esm({
20144
20144
  "node_modules/@aws-sdk/nested-clients/package.json"() {
20145
20145
  package_default = {
20146
20146
  name: "@aws-sdk/nested-clients",
20147
- version: "3.996.1",
20147
+ version: "3.996.2",
20148
20148
  description: "Nested clients for AWS SDK packages.",
20149
20149
  main: "./dist-cjs/index.js",
20150
20150
  module: "./dist-es/index.js",
@@ -20173,40 +20173,40 @@ var init_package = __esm({
20173
20173
  dependencies: {
20174
20174
  "@aws-crypto/sha256-browser": "5.2.0",
20175
20175
  "@aws-crypto/sha256-js": "5.2.0",
20176
- "@aws-sdk/core": "^3.973.13",
20177
- "@aws-sdk/middleware-host-header": "^3.972.4",
20178
- "@aws-sdk/middleware-logger": "^3.972.4",
20179
- "@aws-sdk/middleware-recursion-detection": "^3.972.4",
20180
- "@aws-sdk/middleware-user-agent": "^3.972.13",
20181
- "@aws-sdk/region-config-resolver": "^3.972.4",
20182
- "@aws-sdk/types": "^3.973.2",
20183
- "@aws-sdk/util-endpoints": "^3.996.1",
20184
- "@aws-sdk/util-user-agent-browser": "^3.972.4",
20185
- "@aws-sdk/util-user-agent-node": "^3.972.12",
20186
- "@smithy/config-resolver": "^4.4.7",
20187
- "@smithy/core": "^3.23.4",
20188
- "@smithy/fetch-http-handler": "^5.3.10",
20189
- "@smithy/hash-node": "^4.2.9",
20190
- "@smithy/invalid-dependency": "^4.2.9",
20191
- "@smithy/middleware-content-length": "^4.2.9",
20192
- "@smithy/middleware-endpoint": "^4.4.18",
20193
- "@smithy/middleware-retry": "^4.4.35",
20194
- "@smithy/middleware-serde": "^4.2.10",
20195
- "@smithy/middleware-stack": "^4.2.9",
20196
- "@smithy/node-config-provider": "^4.3.9",
20197
- "@smithy/node-http-handler": "^4.4.11",
20198
- "@smithy/protocol-http": "^5.3.9",
20199
- "@smithy/smithy-client": "^4.11.7",
20200
- "@smithy/types": "^4.12.1",
20201
- "@smithy/url-parser": "^4.2.9",
20176
+ "@aws-sdk/core": "^3.973.14",
20177
+ "@aws-sdk/middleware-host-header": "^3.972.5",
20178
+ "@aws-sdk/middleware-logger": "^3.972.5",
20179
+ "@aws-sdk/middleware-recursion-detection": "^3.972.5",
20180
+ "@aws-sdk/middleware-user-agent": "^3.972.14",
20181
+ "@aws-sdk/region-config-resolver": "^3.972.5",
20182
+ "@aws-sdk/types": "^3.973.3",
20183
+ "@aws-sdk/util-endpoints": "^3.996.2",
20184
+ "@aws-sdk/util-user-agent-browser": "^3.972.5",
20185
+ "@aws-sdk/util-user-agent-node": "^3.972.13",
20186
+ "@smithy/config-resolver": "^4.4.9",
20187
+ "@smithy/core": "^3.23.6",
20188
+ "@smithy/fetch-http-handler": "^5.3.11",
20189
+ "@smithy/hash-node": "^4.2.10",
20190
+ "@smithy/invalid-dependency": "^4.2.10",
20191
+ "@smithy/middleware-content-length": "^4.2.10",
20192
+ "@smithy/middleware-endpoint": "^4.4.20",
20193
+ "@smithy/middleware-retry": "^4.4.37",
20194
+ "@smithy/middleware-serde": "^4.2.11",
20195
+ "@smithy/middleware-stack": "^4.2.10",
20196
+ "@smithy/node-config-provider": "^4.3.10",
20197
+ "@smithy/node-http-handler": "^4.4.12",
20198
+ "@smithy/protocol-http": "^5.3.10",
20199
+ "@smithy/smithy-client": "^4.12.0",
20200
+ "@smithy/types": "^4.13.0",
20201
+ "@smithy/url-parser": "^4.2.10",
20202
20202
  "@smithy/util-base64": "^4.3.1",
20203
20203
  "@smithy/util-body-length-browser": "^4.2.1",
20204
20204
  "@smithy/util-body-length-node": "^4.2.2",
20205
- "@smithy/util-defaults-mode-browser": "^4.3.34",
20206
- "@smithy/util-defaults-mode-node": "^4.2.37",
20207
- "@smithy/util-endpoints": "^3.2.9",
20208
- "@smithy/util-middleware": "^4.2.9",
20209
- "@smithy/util-retry": "^4.2.9",
20205
+ "@smithy/util-defaults-mode-browser": "^4.3.36",
20206
+ "@smithy/util-defaults-mode-node": "^4.2.39",
20207
+ "@smithy/util-endpoints": "^3.3.1",
20208
+ "@smithy/util-middleware": "^4.2.10",
20209
+ "@smithy/util-retry": "^4.2.10",
20210
20210
  "@smithy/util-utf8": "^4.2.1",
20211
20211
  tslib: "^2.6.2"
20212
20212
  },
@@ -40197,7 +40197,11 @@ var init_esm3 = __esm({
40197
40197
  #matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
40198
40198
  const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
40199
40199
  const lastgs = pattern.lastIndexOf(GLOBSTAR);
40200
- const [head2, body, tail] = [
40200
+ const [head2, body, tail] = partial ? [
40201
+ pattern.slice(patternIndex, firstgs),
40202
+ pattern.slice(firstgs + 1),
40203
+ []
40204
+ ] : [
40201
40205
  pattern.slice(patternIndex, firstgs),
40202
40206
  pattern.slice(firstgs + 1, lastgs),
40203
40207
  pattern.slice(lastgs + 1)
@@ -40234,7 +40238,7 @@ var init_esm3 = __esm({
40234
40238
  return false;
40235
40239
  }
40236
40240
  }
40237
- return sawSome;
40241
+ return partial || sawSome;
40238
40242
  }
40239
40243
  const bodySegments = [[[], 0]];
40240
40244
  let currentBody = bodySegments[0];
@@ -40283,7 +40287,7 @@ var init_esm3 = __esm({
40283
40287
  }
40284
40288
  fileIndex++;
40285
40289
  }
40286
- return null;
40290
+ return partial || null;
40287
40291
  }
40288
40292
  #matchOne(file, pattern, partial, fileIndex, patternIndex) {
40289
40293
  let fi;
@@ -82767,6 +82771,15 @@ function normalizeJsonQuotes(str) {
82767
82771
  }
82768
82772
  return result;
82769
82773
  }
82774
+ function isCodeBlockEmbeddedInDocument(text, match2) {
82775
+ const beforeBlock = text.substring(0, match2.index).trim();
82776
+ const afterBlock = text.substring(match2.index + match2[0].length).trim();
82777
+ const hasMarkdownHeadings = /^#{1,6}\s/m.test(beforeBlock) || /^#{1,6}\s/m.test(afterBlock);
82778
+ if (hasMarkdownHeadings) {
82779
+ return true;
82780
+ }
82781
+ return false;
82782
+ }
82770
82783
  function cleanSchemaResponse(response) {
82771
82784
  if (!response || typeof response !== "string") {
82772
82785
  return response;
@@ -82786,11 +82799,11 @@ function cleanSchemaResponse(response) {
82786
82799
  return cleanSchemaResponse(innerContent);
82787
82800
  }
82788
82801
  const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
82789
- if (jsonBlockMatch) {
82802
+ if (jsonBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, jsonBlockMatch)) {
82790
82803
  return normalizeJsonQuotes(jsonBlockMatch[1].trim());
82791
82804
  }
82792
82805
  const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
82793
- if (anyBlockMatch) {
82806
+ if (anyBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, anyBlockMatch)) {
82794
82807
  return normalizeJsonQuotes(anyBlockMatch[1].trim());
82795
82808
  }
82796
82809
  const codeBlockPatterns = [
@@ -82799,7 +82812,7 @@ function cleanSchemaResponse(response) {
82799
82812
  ];
82800
82813
  for (const pattern of codeBlockPatterns) {
82801
82814
  const match2 = trimmed.match(pattern);
82802
- if (match2) {
82815
+ if (match2 && !isCodeBlockEmbeddedInDocument(trimmed, match2)) {
82803
82816
  return normalizeJsonQuotes(match2[1].trim());
82804
82817
  }
82805
82818
  }
@@ -82810,7 +82823,7 @@ function cleanSchemaResponse(response) {
82810
82823
  }
82811
82824
  const codeBlockStartPattern = /```(?:json)?\s*\n?\s*([{\[])/;
82812
82825
  const codeBlockMatch = trimmed.match(codeBlockStartPattern);
82813
- if (codeBlockMatch) {
82826
+ if (codeBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, codeBlockMatch)) {
82814
82827
  const startIndex = codeBlockMatch.index + codeBlockMatch[0].length - 1;
82815
82828
  const openChar = codeBlockMatch[1];
82816
82829
  const closeChar = openChar === "{" ? "}" : "]";
@@ -104508,6 +104521,10 @@ function parseSimpleCommand(command) {
104508
104521
  // Logical OR
104509
104522
  /(?<!\\);/,
104510
104523
  // Command separator (but not escaped \;)
104524
+ /\n/,
104525
+ // Newline command separator (multi-line commands)
104526
+ /\r/,
104527
+ // Carriage return (CRLF line endings)
104511
104528
  /&$/,
104512
104529
  // Background execution
104513
104530
  /\$\(/,
@@ -104614,6 +104631,8 @@ function isComplexPattern(pattern) {
104614
104631
  // Logical OR
104615
104632
  /;/,
104616
104633
  // Command separator
104634
+ /\n/,
104635
+ // Newline command separator
104617
104636
  /&$/,
104618
104637
  // Background execution
104619
104638
  /\$\(/,
@@ -104986,6 +105005,26 @@ var init_bashPermissions = __esm({
104986
105005
  i5++;
104987
105006
  continue;
104988
105007
  }
105008
+ if (char === "\n" || char === "\r" && nextChar === "\n") {
105009
+ if (current2.trim()) {
105010
+ components.push(current2.trim());
105011
+ }
105012
+ current2 = "";
105013
+ if (char === "\r") {
105014
+ i5 += 2;
105015
+ } else {
105016
+ i5++;
105017
+ }
105018
+ continue;
105019
+ }
105020
+ if (char === "\r") {
105021
+ if (current2.trim()) {
105022
+ components.push(current2.trim());
105023
+ }
105024
+ current2 = "";
105025
+ i5++;
105026
+ continue;
105027
+ }
104989
105028
  }
104990
105029
  current2 += char;
104991
105030
  i5++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc259",
3
+ "version": "0.6.0-rc260",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -127,6 +127,8 @@ export function parseSimpleCommand(command) {
127
127
  /&&/, // Logical AND
128
128
  /\|\|/, // Logical OR
129
129
  /(?<!\\);/, // Command separator (but not escaped \;)
130
+ /\n/, // Newline command separator (multi-line commands)
131
+ /\r/, // Carriage return (CRLF line endings)
130
132
  /&$/, // Background execution
131
133
  /\$\(/, // Command substitution $()
132
134
  /`/, // Command substitution ``
@@ -260,6 +262,7 @@ export function isComplexPattern(pattern) {
260
262
  /&&/, // Logical AND
261
263
  /\|\|/, // Logical OR
262
264
  /;/, // Command separator
265
+ /\n/, // Newline command separator
263
266
  /&$/, // Background execution
264
267
  /\$\(/, // Command substitution $()
265
268
  /`/, // Command substitution ``
@@ -402,6 +402,29 @@ export class BashPermissionChecker {
402
402
  i++;
403
403
  continue;
404
404
  }
405
+ // Check for newline (command separator in multi-line scripts)
406
+ // Also handle \r\n (CRLF) line endings
407
+ if (char === '\n' || (char === '\r' && nextChar === '\n')) {
408
+ if (current.trim()) {
409
+ components.push(current.trim());
410
+ }
411
+ current = '';
412
+ if (char === '\r') {
413
+ i += 2; // Skip \r\n
414
+ } else {
415
+ i++;
416
+ }
417
+ continue;
418
+ }
419
+ if (char === '\r') {
420
+ // Bare \r without \n
421
+ if (current.trim()) {
422
+ components.push(current.trim());
423
+ }
424
+ current = '';
425
+ i++;
426
+ continue;
427
+ }
405
428
  }
406
429
 
407
430
  current += char;
@@ -266,6 +266,36 @@ function normalizeJsonQuotes(str) {
266
266
  return result;
267
267
  }
268
268
 
269
+ /**
270
+ * Check if a code block is embedded within a structured markdown document.
271
+ * Used to avoid extracting embedded JSON examples from markdown text.
272
+ * Issue #456: attempt_completion results containing markdown with JSON code block
273
+ * documentation examples were having the examples extracted as structured output.
274
+ *
275
+ * Normal AI behavior: AI wraps JSON answer in a code block with brief explanation text.
276
+ * Issue #456: AI returns a markdown document that contains JSON code blocks as examples.
277
+ *
278
+ * We distinguish these by checking if the surrounding text contains markdown structural
279
+ * elements (headings) which indicate a document rather than a brief explanation.
280
+ *
281
+ * @param {string} text - The full trimmed text
282
+ * @param {RegExpMatchArray} match - The regex match for the code block
283
+ * @returns {boolean} - true if the code block is embedded in a markdown document
284
+ */
285
+ function isCodeBlockEmbeddedInDocument(text, match) {
286
+ const beforeBlock = text.substring(0, match.index).trim();
287
+ const afterBlock = text.substring(match.index + match[0].length).trim();
288
+
289
+ // Check if surrounding text contains markdown headings (lines starting with #)
290
+ // This is a strong signal that the content is a structured document, not just explanation text
291
+ const hasMarkdownHeadings = /^#{1,6}\s/m.test(beforeBlock) || /^#{1,6}\s/m.test(afterBlock);
292
+ if (hasMarkdownHeadings) {
293
+ return true;
294
+ }
295
+
296
+ return false;
297
+ }
298
+
269
299
  /**
270
300
  * Clean AI response by extracting JSON content when response contains JSON
271
301
  * Only processes responses that contain JSON structures { or [
@@ -311,15 +341,20 @@ export function cleanSchemaResponse(response) {
311
341
  }
312
342
 
313
343
  // First, look for JSON after code block markers - similar to mermaid extraction
344
+ // Only extract from code blocks when they are the primary content (not embedded examples in markdown).
345
+ // Issue #456: When attempt_completion result contains markdown with embedded JSON code blocks
346
+ // as documentation examples, extracting those blocks produces wrong structured output.
347
+ // We check that there's no significant text content outside the code block.
348
+
314
349
  // Try with json language specifier
315
350
  const jsonBlockMatch = trimmed.match(/```json\s*\n([\s\S]*?)\n```/);
316
- if (jsonBlockMatch) {
351
+ if (jsonBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, jsonBlockMatch)) {
317
352
  return normalizeJsonQuotes(jsonBlockMatch[1].trim());
318
353
  }
319
354
 
320
355
  // Try any code block with JSON content
321
356
  const anyBlockMatch = trimmed.match(/```\s*\n([{\[][\s\S]*?[}\]])\s*```/);
322
- if (anyBlockMatch) {
357
+ if (anyBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, anyBlockMatch)) {
323
358
  return normalizeJsonQuotes(anyBlockMatch[1].trim());
324
359
  }
325
360
 
@@ -331,7 +366,7 @@ export function cleanSchemaResponse(response) {
331
366
 
332
367
  for (const pattern of codeBlockPatterns) {
333
368
  const match = trimmed.match(pattern);
334
- if (match) {
369
+ if (match && !isCodeBlockEmbeddedInDocument(trimmed, match)) {
335
370
  return normalizeJsonQuotes(match[1].trim());
336
371
  }
337
372
  }
@@ -345,10 +380,11 @@ export function cleanSchemaResponse(response) {
345
380
  }
346
381
 
347
382
  // Look for code block start followed immediately by JSON
383
+ // Only extract if the code block is not embedded in a structured markdown document
348
384
  const codeBlockStartPattern = /```(?:json)?\s*\n?\s*([{\[])/;
349
385
  const codeBlockMatch = trimmed.match(codeBlockStartPattern);
350
386
 
351
- if (codeBlockMatch) {
387
+ if (codeBlockMatch && !isCodeBlockEmbeddedInDocument(trimmed, codeBlockMatch)) {
352
388
  const startIndex = codeBlockMatch.index + codeBlockMatch[0].length - 1; // Position of the bracket
353
389
 
354
390
  // Find the matching closing bracket