@ai-matrx/content-ir 0.18.4 → 0.18.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -7,5 +7,5 @@ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateR
7
7
  export { ArrayItemKindBinding, BlockSchemaDraft, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonResult, SavePlanEntry, SavePlanValidation, SchemaConversionResult, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, validateBlockSchemaSavePlan } from './convert.cjs';
8
8
  export { AnyPartialKindEvent, IR_PARTIAL_KEY, KindVerdict, NODE_OUTCOME_KIND, NodeOutcomeWrapper, PartialKindEvent, PartialKindNode, PartialKindState, RUN_RESULT_KIND, RetractedKindEvent, RunResultWrapper, SupersededKindEvent, advancePartialKind, emitPayloadFence, emitPayloadJson, isProvisionalKind, isTerminalKindEvent, kindVerdictOf, makePartialKindStalenessGate, readNodeOutcomeValue, readOutputRef, readPartialKindEvent, readRunResultValue, rehydrateNodeOutcome, rehydrateRunResult, sanitizeInboundPartialKindMetadata, withRootKind } from './wire.cjs';
9
9
  export { ACTION_BY_CLASS, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DecodedDirective, DirectiveCapability, DirectiveClass, DirectiveDecodeError, DirectiveDisplay, DirectiveItemKindLookup, DirectiveItemsEdge, DirectiveNounCatalog, DirectiveNounEntry, DirectiveSlug, IN_CONTENT_CLASSES, ItemFact, KindDirectiveShell, RESERVED_PREFIX, SIDE_EFFECT_CLASSES, SLUG_PREFIX, asKindInstance, buildDirectiveSlug, buildKindDirective, capabilityOf, decodeDirective, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, executesAtOutputRoot, isDirectiveClass, isKindDirective, isLegacyShell, isReservedDirectiveSlug, itemFacts, itemSubtitle, itemTitle, legacyShellUses, looksLikeDirectiveHead, nounFamily, nounLabel, nounTitleColumn, parseDirectiveSlug, resetLegacyShellUses, resolvesInContent, titleCaseToken, tryDecodeDirective, tryDecodeDirectiveContent } from './directives.cjs';
10
- export { BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine } from './source.cjs';
10
+ export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarAfter, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine } from './source.cjs';
11
11
  import 'react';
package/dist/index.d.ts CHANGED
@@ -7,5 +7,5 @@ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateR
7
7
  export { ArrayItemKindBinding, BlockSchemaDraft, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonResult, SavePlanEntry, SavePlanValidation, SchemaConversionResult, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, validateBlockSchemaSavePlan } from './convert.js';
8
8
  export { AnyPartialKindEvent, IR_PARTIAL_KEY, KindVerdict, NODE_OUTCOME_KIND, NodeOutcomeWrapper, PartialKindEvent, PartialKindNode, PartialKindState, RUN_RESULT_KIND, RetractedKindEvent, RunResultWrapper, SupersededKindEvent, advancePartialKind, emitPayloadFence, emitPayloadJson, isProvisionalKind, isTerminalKindEvent, kindVerdictOf, makePartialKindStalenessGate, readNodeOutcomeValue, readOutputRef, readPartialKindEvent, readRunResultValue, rehydrateNodeOutcome, rehydrateRunResult, sanitizeInboundPartialKindMetadata, withRootKind } from './wire.js';
9
9
  export { ACTION_BY_CLASS, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DecodedDirective, DirectiveCapability, DirectiveClass, DirectiveDecodeError, DirectiveDisplay, DirectiveItemKindLookup, DirectiveItemsEdge, DirectiveNounCatalog, DirectiveNounEntry, DirectiveSlug, IN_CONTENT_CLASSES, ItemFact, KindDirectiveShell, RESERVED_PREFIX, SIDE_EFFECT_CLASSES, SLUG_PREFIX, asKindInstance, buildDirectiveSlug, buildKindDirective, capabilityOf, decodeDirective, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, executesAtOutputRoot, isDirectiveClass, isKindDirective, isLegacyShell, isReservedDirectiveSlug, itemFacts, itemSubtitle, itemTitle, legacyShellUses, looksLikeDirectiveHead, nounFamily, nounLabel, nounTitleColumn, parseDirectiveSlug, resetLegacyShellUses, resolvesInContent, titleCaseToken, tryDecodeDirective, tryDecodeDirectiveContent } from './directives.js';
10
- export { BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine } from './source.js';
10
+ export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, closeFence, codeSpanText, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, isEscapedBracketMath, isMathPlaceholder, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, pendingDisplayMathOpener, readXmlTag, singleDollarAfter, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine } from './source.js';
11
11
  import 'react';
package/dist/index.js CHANGED
@@ -5290,6 +5290,7 @@ var FenceReader = class {
5290
5290
  function closeFence(src, open, opener) {
5291
5291
  const first = readFence(src, open, new FenceReader(opener));
5292
5292
  if (first.closed || !first.reader.sawNested || first.reader.nestedDepth <= 0) return { line: first.line, closed: first.closed };
5293
+ if (src.streaming) return { line: first.line, closed: false };
5293
5294
  const strict = readFence(src, open, new FenceReader(opener, { nesting: false }));
5294
5295
  return { line: strict.line, closed: strict.closed };
5295
5296
  }
@@ -5553,6 +5554,8 @@ function fenceLineKinds(text) {
5553
5554
  function pendingCodeSpanStart(text) {
5554
5555
  const n = text.length;
5555
5556
  if (n === 0 || /\n[ \t]*\n[ \t]*$/.test(text)) return -1;
5557
+ const lastLine = text.slice(text.lastIndexOf("\n") + 1);
5558
+ if (lastLine && /^(?: {0,3}>[ \t]?)*[ \t]*$/.test(lastLine)) return pendingCodeSpanStart(`${text}x`);
5556
5559
  const s = scan(text);
5557
5560
  const para = s.pendingPara;
5558
5561
  if (s.endsInFence || para === -1) return -1;
@@ -5699,13 +5702,26 @@ var MATH_SHAPE_CHARS = /^[A-Za-z0-9'\s(),.*\/-]+$/;
5699
5702
  function isSingleDollarMath(content, after) {
5700
5703
  if (!content || content.length > 400) return false;
5701
5704
  if (/^\s/.test(content) || /\s$/.test(content)) return false;
5702
- if (after !== void 0 && /[0-9]/.test(after)) return false;
5705
+ if (after !== void 0 && /^[0-9]/.test(after)) return false;
5706
+ if (isVariableChain(content, after)) return false;
5703
5707
  if (/(?:^|[^\\])%/.test(content)) return false;
5704
5708
  if (/^[)\]}"/]/.test(content) || /[(\[{":;,/]$/.test(content)) return false;
5705
- if (/^[0-9]/.test(content) && after !== void 0 && /[A-Za-z]/.test(after)) return false;
5709
+ if (/^[0-9]/.test(content) && after !== void 0 && /^[A-Za-z]/.test(after)) return false;
5706
5710
  if (isMathPlaceholder(content)) return false;
5707
5711
  return TEX_SIGNAL.test(content) || !readsAsProse(content);
5708
5712
  }
5713
+ var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
5714
+ var MATH_SUFFIX = /^(?:s|es|th|st|nd|rd)$/i;
5715
+ function isVariableChain(content, after) {
5716
+ if (/^\{[A-Za-z_][\w.]*\}$/.test(content)) return true;
5717
+ if (!after) return false;
5718
+ if (after[0] === "{") return IDENTIFIER.test(content);
5719
+ const run = /^[A-Za-z0-9_]+/.exec(after)?.[0];
5720
+ if (!run) return false;
5721
+ if (after.length === 1) return false;
5722
+ if (/^[A-Za-z_][A-Za-z0-9_]*[.@-]$/.test(content)) return true;
5723
+ return IDENTIFIER.test(content) && !MATH_SUFFIX.test(run);
5724
+ }
5709
5725
  var FUNCTION_NAMES = /* @__PURE__ */ new Set([
5710
5726
  "sin",
5711
5727
  "cos",
@@ -5749,6 +5765,12 @@ function isMathShape(content) {
5749
5765
  if (/[A-Za-z]'+[A-Za-z]/.test(content) || /(?:^|[\s(,])[A-Za-z]\.(?:[A-Za-z]\.|\s|$)/.test(content)) return false;
5750
5766
  return /[A-Za-z]'*\(|[A-Za-z]'|\b[A-Za-z]\s+[A-Za-z]\b|\([^)]*[A-Za-z][^)]*\)/.test(content);
5751
5767
  }
5768
+ var AFTER_WINDOW = 32;
5769
+ function singleDollarAfter(text, close) {
5770
+ const rest = text.slice(close + 1, close + 1 + AFTER_WINDOW);
5771
+ return rest.length < AFTER_WINDOW ? `${rest}
5772
+ ` : rest;
5773
+ }
5752
5774
  function singleDollarMathEnd(text, open, limit = text.length) {
5753
5775
  const bound = Math.min(limit, open + 403);
5754
5776
  let close = -1;
@@ -5766,7 +5788,7 @@ function singleDollarMathEnd(text, open, limit = text.length) {
5766
5788
  }
5767
5789
  if (close === -1 || text[close + 1] === "$") return -1;
5768
5790
  const content = text.slice(open + 1, close);
5769
- return isSingleDollarMath(content, text[close + 1]) ? close + 1 : -1;
5791
+ return isSingleDollarMath(content, singleDollarAfter(text, close)) ? close + 1 : -1;
5770
5792
  }
5771
5793
  var BRACKET_TEX_SIGNAL = /\\[A-Za-z]+|[\^{}=<>+]|_\{|(?:^|[^A-Za-z0-9])[A-Za-z]_[A-Za-z0-9](?![A-Za-z0-9])/;
5772
5794
  function isEscapedBracketMath(content, before) {
@@ -6137,18 +6159,14 @@ var Tokenizer = class {
6137
6159
  /**
6138
6160
  * Streaming: an open last line that begins with `{` is undecided — each new
6139
6161
  * byte can balance or unbalance its braces and flip the whole line between
6140
- * prose and a JSON island — and so is a line that is exactly one allowed
6141
- * HTML tag so far; both are provisional until they end (G5).
6162
+ * prose and a JSON island — so it is provisional until it ends (G5).
6163
+ * (A lone HTML tag on that line is held by {@link holdUndecidedTail}.)
6142
6164
  */
6143
6165
  markOpenJsonTail() {
6144
6166
  const last = this.lineStarts.length - 1;
6145
6167
  if (!this.isOpenTail(last)) return;
6146
- const start = this.lineStarts[last];
6147
- const t = this.lineText(last).trim();
6148
- const oneTag = t.startsWith("<") ? readXmlTag(t, 0) : null;
6149
- const loneTag = !!oneTag && oneTag.raw === t && ALLOWED_RAW_HTML_TAGS.has(oneTag.tagName.toLowerCase());
6150
- if (t.startsWith("{") || loneTag) {
6151
- this.provisionalFrom = Math.min(this.provisionalFrom, start);
6168
+ if (this.lineText(last).trim().startsWith("{")) {
6169
+ this.provisionalFrom = Math.min(this.provisionalFrom, this.lineStarts[last]);
6152
6170
  }
6153
6171
  }
6154
6172
  /**
@@ -6181,11 +6199,25 @@ var Tokenizer = class {
6181
6199
  /** Streaming only: a paragraph ending at `pe` may still be continued by a line not yet arrived. */
6182
6200
  paragraphMayGrow(pe) {
6183
6201
  if (!this.streaming) return false;
6202
+ if (this.undecidedBreaks.has(pe)) return true;
6184
6203
  const rest = this.n - pe;
6185
6204
  if (rest === 0) return true;
6186
6205
  const tail = this.text.slice(pe);
6187
- return tail === "\n" || tail === "\r\n" || tail === "\r";
6206
+ return /^(?:\r\n|\r|\n)[ \t]*$/.test(tail);
6188
6207
  }
6208
+ /**
6209
+ * Streaming: an open block that may still turn back into prose — a `$$`
6210
+ * pair whose closer is on the open last line (prose after it makes it
6211
+ * inline), a JSON head whose braces have not balanced (it may never parse),
6212
+ * or any opener that is itself still arriving on the open last line.
6213
+ */
6214
+ mayDissolve(block) {
6215
+ if (!this.streaming || block.complete) return false;
6216
+ if (block.type === "math_block" || block.type === "json") return true;
6217
+ return this.isOpenTail(this.lineOf(block.start));
6218
+ }
6219
+ /** Streaming: paragraph ends where an undecided, dissolvable block cut them short. */
6220
+ undecidedBreaks = /* @__PURE__ */ new Set();
6189
6221
  /** Streaming only: the final line, still waiting for its terminator. */
6190
6222
  isOpenTail(k) {
6191
6223
  return this.streaming && k === this.lineStarts.length - 1 && (this.lineEnds[k] === this.contentEnds[k] || this.pendingCR);
@@ -6203,6 +6235,12 @@ var Tokenizer = class {
6203
6235
  }
6204
6236
  return lo;
6205
6237
  }
6238
+ /** How many whitespace characters open the text at `from` (up to `to`). */
6239
+ leadingSpace(from, to) {
6240
+ let k = from;
6241
+ while (k < to && /\s/.test(this.text[k])) k++;
6242
+ return k - from;
6243
+ }
6206
6244
  isBlank(from, to) {
6207
6245
  return !NOT_WHITESPACE.test(this.text.slice(from, to));
6208
6246
  }
@@ -6227,6 +6265,10 @@ var Tokenizer = class {
6227
6265
  break;
6228
6266
  }
6229
6267
  const island = this.detectBlock(pos, li, true);
6268
+ if (island && pos + this.leadingSpace(pos, this.contentEnds[li]) >= this.provisionalFrom) {
6269
+ this.push({ kind: "prose", start: pos, end: this.n, island: null, inlines: [] });
6270
+ break;
6271
+ }
6230
6272
  if (island) {
6231
6273
  this.push({ kind: "island", start: island.start, end: island.end, island, inlines: [] });
6232
6274
  pos = island.end;
@@ -6234,8 +6276,122 @@ var Tokenizer = class {
6234
6276
  }
6235
6277
  pos = this.paragraph(pos, li);
6236
6278
  }
6279
+ if (this.streaming) this.holdUndecidedTail();
6237
6280
  return this.blocks;
6238
6281
  }
6282
+ /**
6283
+ * Streaming: settle nothing the next bytes can still change (verify-RC-B3 F3).
6284
+ *
6285
+ * 1. A block island that ends on the open last line is undecided — the next
6286
+ * bytes on that line can re-read it or dissolve it (`<!--@a:k1-->` +
6287
+ * ` more` is an inline anchor, `<br>` + `x` is prose). It runs open to
6288
+ * the end of the text.
6289
+ * 2. A box-drawing tree still forming at the end of the text claims, as its
6290
+ * root label, the lines directly above its first connector (the
6291
+ * renderer's `findTreeBlockStart`), and the open last line itself may
6292
+ * become one of its connector lines — so inlines on those lines are held
6293
+ * back as prose until a blank line, a heading or a tree line decides.
6294
+ * This also holds everything a closer still able to arrive on the open
6295
+ * last line could change (`$x$` + `5` is currency, G4; `{{v}}` + `}`).
6296
+ */
6297
+ holdUndecidedTail() {
6298
+ const last = this.lineStarts.length - 1;
6299
+ if (last < 0) return;
6300
+ if (this.isOpenTail(last)) {
6301
+ const lineStart = this.lineStarts[last];
6302
+ for (const block2 of this.blocks) {
6303
+ if (block2.kind === "prose" && block2.end > lineStart) {
6304
+ block2.inlines = block2.inlines.filter((inline) => inline.end <= lineStart);
6305
+ }
6306
+ }
6307
+ let b = this.blocks.length - 1;
6308
+ while (b >= 0 && this.blocks[b].kind === "gap") b--;
6309
+ const block = this.blocks[b];
6310
+ if (block?.island?.complete && block.island.end > this.lineStarts[last]) {
6311
+ block.island.complete = false;
6312
+ block.island.end = this.n;
6313
+ block.end = this.n;
6314
+ this.blocks.length = b + 1;
6315
+ }
6316
+ }
6317
+ const from = this.treeRootHoldFrom();
6318
+ for (let b = this.blocks.length - 1; b >= 0; b--) {
6319
+ const block = this.blocks[b];
6320
+ if (block.end <= from) break;
6321
+ if (block.kind === "prose") block.inlines = block.inlines.filter((inline) => inline.end <= from);
6322
+ if (block.island) this.blocks[b] = { kind: "prose", start: block.start, end: block.end, island: null, inlines: [] };
6323
+ }
6324
+ }
6325
+ /**
6326
+ * Streaming: where a tree that may still form at the end of the text would
6327
+ * start claiming lines (`n` when none can). Only paragraph lines can be
6328
+ * claimed — a line that starts inside an island (a fence body, an XML
6329
+ * region…) is never a tree line nor a root label, so it stops the walk.
6330
+ */
6331
+ treeRootHoldFrom() {
6332
+ const claimFrom = (k2) => {
6333
+ const lineStart = this.lineStarts[k2];
6334
+ const lineEnd = this.contentEnds[k2];
6335
+ let pos = lineStart;
6336
+ for (; ; ) {
6337
+ const block = this.blockAt(pos);
6338
+ if (!block || block.kind !== "island" || !block.island) return pos;
6339
+ if (block.island.fromParagraph === true || this.mayDissolve(block.island)) return pos;
6340
+ if (block.start < lineStart) {
6341
+ const opened = this.lineOf(block.start);
6342
+ if (this.lineStarts[opened] !== block.start && claimFrom(opened) !== -1) return pos;
6343
+ if (block.end >= lineEnd) return -1;
6344
+ pos = block.end;
6345
+ continue;
6346
+ }
6347
+ if (block.end >= lineEnd) return -1;
6348
+ pos = block.end;
6349
+ }
6350
+ };
6351
+ let k = this.lineCount - 1;
6352
+ let start = this.lineCount;
6353
+ let startPos = this.n;
6354
+ if (k >= 0 && this.isOpenTail(k)) {
6355
+ const at = claimFrom(k);
6356
+ if (at === -1) return this.n;
6357
+ start = k;
6358
+ startPos = at;
6359
+ k--;
6360
+ }
6361
+ for (; k >= 0; k--) {
6362
+ this.tick(1);
6363
+ const at = claimFrom(k);
6364
+ if (at === -1) break;
6365
+ if (this.lineIsBlank(k)) continue;
6366
+ if (!TREE_GLYPHS.test(this.lineText(k))) break;
6367
+ start = k;
6368
+ startPos = at;
6369
+ }
6370
+ let rootPos = startPos;
6371
+ for (let j = start - 1; j >= 0; j--) {
6372
+ const at = claimFrom(j);
6373
+ if (at === -1) break;
6374
+ const trimmed = this.lineText(j).trim();
6375
+ this.tick(trimmed.length + 1);
6376
+ if (!trimmed || isSplitterTreeLine(trimmed) || /^#{1,6}\s/.test(trimmed)) break;
6377
+ rootPos = at;
6378
+ if (at > this.lineStarts[j]) break;
6379
+ }
6380
+ return rootPos;
6381
+ }
6382
+ /** The block (so far) containing offset `pos`, or null. */
6383
+ blockAt(pos) {
6384
+ let lo = 0;
6385
+ let hi = this.blocks.length - 1;
6386
+ while (lo <= hi) {
6387
+ const mid = lo + hi >>> 1;
6388
+ const block = this.blocks[mid];
6389
+ if (pos < block.start) hi = mid - 1;
6390
+ else if (pos >= block.end) lo = mid + 1;
6391
+ else return block;
6392
+ }
6393
+ return null;
6394
+ }
6239
6395
  push(block) {
6240
6396
  if (block.end <= block.start) return;
6241
6397
  if (block.kind === "prose" && this.isBlank(block.start, block.end)) {
@@ -6439,7 +6595,10 @@ var Tokenizer = class {
6439
6595
  continue;
6440
6596
  }
6441
6597
  if (this.isOpenTail(k)) return this.heldFootnote(p, open[1]);
6442
- if (FOOTNOTE_DEF.test(line.trimStart()) || this.detectBlock(this.lineStarts[k], k, false)) break;
6598
+ if (FOOTNOTE_DEF.test(line.trimStart())) break;
6599
+ const block = this.detectBlock(this.lineStarts[k], k, false);
6600
+ if (block && this.mayDissolve(block)) return this.heldFootnote(p, open[1]);
6601
+ if (block) break;
6443
6602
  last = k;
6444
6603
  }
6445
6604
  const end = this.contentEnds[last];
@@ -6455,7 +6614,8 @@ var Tokenizer = class {
6455
6614
  return {
6456
6615
  count: this.lineCount,
6457
6616
  line: (k) => this.lineText(k),
6458
- openTail: (k) => this.isOpenTail(k)
6617
+ openTail: (k) => this.isOpenTail(k),
6618
+ streaming: this.streaming
6459
6619
  };
6460
6620
  }
6461
6621
  /**
@@ -6515,6 +6675,10 @@ var Tokenizer = class {
6515
6675
  if (fenceOpenerOf(this.lineText(j))?.char === "~") continue;
6516
6676
  const inner = this.detectBlockUncached(start, j, false);
6517
6677
  if (!inner) continue;
6678
+ if (this.streaming && inner.end >= tildeEnd && this.paragraphMayGrow(inner.end)) {
6679
+ this.overflowComplete = false;
6680
+ return this.n;
6681
+ }
6518
6682
  if (inner.end > end) {
6519
6683
  end = inner.end;
6520
6684
  this.overflowComplete = inner.complete;
@@ -6643,12 +6807,7 @@ var Tokenizer = class {
6643
6807
  return this.island("html_block", p, close.index + close[0].length, true, { tag: name });
6644
6808
  }
6645
6809
  const typeSix = HTML_BLOCK_LEVEL_TAGS.has(name);
6646
- const loneTag = atParaStart && t.trimEnd() === tag.raw;
6647
- if (loneTag && this.isOpenTail(li)) {
6648
- this.provisionalFrom = Math.min(this.provisionalFrom, p);
6649
- return null;
6650
- }
6651
- const typeSeven = loneTag;
6810
+ const typeSeven = atParaStart && t.trimEnd() === tag.raw;
6652
6811
  if (!typeSix && !typeSeven) return null;
6653
6812
  let end = this.contentEnds[li];
6654
6813
  for (let k = li + 1; k < this.lineCount && !this.lineIsBlank(k); k++) {
@@ -6706,6 +6865,13 @@ var Tokenizer = class {
6706
6865
  }
6707
6866
  return null;
6708
6867
  }
6868
+ if (this.isOpenTail(lastLine)) {
6869
+ if (isRecognizedJsonHead(this.text.slice(tp, tp + 512))) {
6870
+ return this.island("json", p, this.n, false, jsonMeta(this.text.slice(tp)));
6871
+ }
6872
+ this.provisionalFrom = Math.min(this.provisionalFrom, p);
6873
+ return null;
6874
+ }
6709
6875
  if (net !== 0) return null;
6710
6876
  const end = this.contentEnds[lastLine];
6711
6877
  const content = this.text.slice(tp, end).trim();
@@ -6740,8 +6906,10 @@ var Tokenizer = class {
6740
6906
  let breakLine = -1;
6741
6907
  for (let k = li + 1; k < this.lineCount; k++) {
6742
6908
  if (this.lineIsBlank(k)) break;
6743
- if (this.detectBlock(this.lineStarts[k], k, false)) {
6909
+ const block = this.detectBlock(this.lineStarts[k], k, false);
6910
+ if (block) {
6744
6911
  breakLine = k;
6912
+ if (this.mayDissolve(block)) this.undecidedBreaks.add(end);
6745
6913
  break;
6746
6914
  }
6747
6915
  end = this.contentEnds[k];
@@ -6779,7 +6947,7 @@ var Tokenizer = class {
6779
6947
  this.push({ kind: "prose", start: pos, end, island: null, inlines: scan2.inlines });
6780
6948
  return end;
6781
6949
  }
6782
- const br = scan2.breakIsland;
6950
+ const br = { ...scan2.breakIsland, fromParagraph: true };
6783
6951
  if (scan2.orphan) {
6784
6952
  let start = pos;
6785
6953
  while (this.blocks.length) {
@@ -6802,6 +6970,15 @@ var Tokenizer = class {
6802
6970
  this.push({ kind: "island", start: br.start, end: br.end, island: br, inlines: [] });
6803
6971
  return br.end;
6804
6972
  }
6973
+ /**
6974
+ * An island that opens inside a paragraph and closes past its end becomes a
6975
+ * block. Streaming: while the paragraph may still grow over its closer, the
6976
+ * island may yet be inline — undecided, so it runs open to the end (F3).
6977
+ */
6978
+ spill(type, start, end, pe, meta) {
6979
+ if (this.paragraphMayGrow(pe)) return this.island(type, start, this.n, false, meta);
6980
+ return this.island(type, start, end, true, meta);
6981
+ }
6805
6982
  scanInline(ps, pe) {
6806
6983
  const text = this.text;
6807
6984
  const inlines = [];
@@ -6836,6 +7013,9 @@ var Tokenizer = class {
6836
7013
  i = close + 2;
6837
7014
  continue;
6838
7015
  }
7016
+ if (close === -1 && this.streaming && this.paragraphMayGrow(pe)) {
7017
+ return { inlines, breakIsland: null, orphan: false };
7018
+ }
6839
7019
  }
6840
7020
  i += 2;
6841
7021
  continue;
@@ -6856,17 +7036,13 @@ var Tokenizer = class {
6856
7036
  i += 2;
6857
7037
  continue;
6858
7038
  }
6859
- if (close + 2 > pe) return stop(this.island("math_block", i, close + 2, true, { delimiter: "$$" }));
7039
+ if (close + 2 > pe) return stop(this.spill("math_block", i, close + 2, pe, { delimiter: "$$" }));
6860
7040
  inlines.push(this.island("math_inline", i, close + 2, true, { delimiter: "$$" }));
6861
7041
  i = close + 2;
6862
7042
  continue;
6863
7043
  }
6864
7044
  const end = singleDollarMathEnd(text, i, pe);
6865
7045
  this.tick(end > 0 ? end - i : Math.min(403, pe - i));
6866
- if (end > 0 && this.streaming && end === this.n) {
6867
- this.provisionalFrom = Math.min(this.provisionalFrom, i);
6868
- return { inlines, breakIsland: null, orphan: false };
6869
- }
6870
7046
  if (end > 0) {
6871
7047
  inlines.push(this.island("math_inline", i, end, true, { delimiter: "$" }));
6872
7048
  i = end;
@@ -6944,7 +7120,7 @@ var Tokenizer = class {
6944
7120
  const anchor = end - i <= 64 ? PINNED_ANCHOR_RE.exec(text.slice(i, end)) : null;
6945
7121
  const type = anchor ? "anchor" : "html_comment";
6946
7122
  const meta = anchor ? { id: anchor[1] } : {};
6947
- if (end > pe) return stop(this.island(type, i, end, true, meta));
7123
+ if (end > pe) return stop(this.spill(type, i, end, pe, meta));
6948
7124
  inlines.push(this.island(type, i, end, true, meta));
6949
7125
  i = end;
6950
7126
  continue;
@@ -6971,9 +7147,13 @@ var Tokenizer = class {
6971
7147
  const closer = `</${name}>`;
6972
7148
  const close = this.next(closer, tagEnd);
6973
7149
  const blockType = isAttr ? "xml_attr" : "xml_region";
7150
+ if (close === -1 && isThinking && !this.streaming) {
7151
+ i = tagEnd;
7152
+ continue;
7153
+ }
6974
7154
  if (close === -1) return stop(this.island(blockType, i, this.n, false, { tag: name }));
6975
7155
  const end = close + closer.length;
6976
- if (end > pe) return stop(this.island(blockType, i, end, true, { tag: name }));
7156
+ if (end > pe) return stop(this.spill(blockType, i, end, pe, { tag: name }));
6977
7157
  inlines.push(this.island("xml_inline", i, end, true, { tag: name }));
6978
7158
  i = end;
6979
7159
  continue;
@@ -7358,6 +7538,6 @@ function mapRange(changes, start, end, unit = "utf16") {
7358
7538
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
7359
7539
  }
7360
7540
 
7361
- export { ACTION_BY_CLASS, BacktickRuns, CALLOUT_NAMES, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DirectiveDecodeError, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, IN_CONTENT_CLASSES, IR_ENVELOPE_CACHE_VERSION, IR_ENVELOPE_KEY, IR_PARTIAL_KEY, IR_VERSION, IrTree, JSON_DISCRIMINATOR, JsonStreamTokenizer, KIND_KEY, KindStorageError, KindStreamParser, NESTING_FENCE_LANGUAGES, NODE_OUTCOME_KIND, ParseSession, RESERVED_PREFIX, ROOT_STORAGE_NAME, RUN_RESULT_KIND, SIDE_EFFECT_CLASSES, SLUG_PREFIX, SourceSpliceError, XmlContainerTracker, advancePartialKind, asKindInstance, blockAt, blockEdit, blockRangeEdit, buildAgentSchemaWithRenderBlockSupport, buildCodePointIndex, buildCompliantKindSnapshot, buildDirectiveSlug, buildKindDirective, capabilityOf, classifyInboundEnvelopeMetadata, classifyInnerFenceLine, closeFence, codeSpanText, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, decodeDirective, describeDualGateFailure, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, executesAtOutputRoot, fenceDiscriminator, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, fieldsToDbPayload, findCodeRanges, fingerprintText, formatBlockLabel, getParseSession, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDirectiveClass, isDuplicateBlockSlug, isEmptyResidue, isEscapedBracketMath, isIrEnvelopeCache, isJsonAnyField, isKindDirective, isLegacyShell, isMathPlaceholder, isProvisionalKind, isReservedDirectiveSlug, isScalarArrayType, isSingleDollarMath, isTerminalKindEvent, islandEdit, itemFacts, itemSubtitle, itemTitle, joinSource, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, legacyShellUses, listIslands, looksLikeDirectiveHead, looksLikeDisplayMath, looksLikeOpenInlineMath, makePartialKindStalenessGate, mapCodeRanges, mapPosition, mapRange, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, nounFamily, nounLabel, nounTitleColumn, openParseSession, pairDisplayMath, parseDirectiveSlug, parseFenceOpener, pendingDisplayMathOpener, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, readXmlTag, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, resetLegacyShellUses, resolvesInContent, reuseEnvelopeIfCurrent, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, singleDollarMathEnd, spliceSave, splitsSurrogatePair, storageToKindSchema, stripKindDeep, titleCaseToken, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, tryDecodeDirective, tryDecodeDirectiveContent, validateBlockSchemaSavePlan, validateStructuralLeg, withRootKind, xmlDiscriminator };
7541
+ export { ACTION_BY_CLASS, AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, CAPABILITY_BY_CLASS, CLASSES, DIRECTIVE_VERSION, DirectiveDecodeError, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceReader, IN_CONTENT_CLASSES, IR_ENVELOPE_CACHE_VERSION, IR_ENVELOPE_KEY, IR_PARTIAL_KEY, IR_VERSION, IrTree, JSON_DISCRIMINATOR, JsonStreamTokenizer, KIND_KEY, KindStorageError, KindStreamParser, NESTING_FENCE_LANGUAGES, NODE_OUTCOME_KIND, ParseSession, RESERVED_PREFIX, ROOT_STORAGE_NAME, RUN_RESULT_KIND, SIDE_EFFECT_CLASSES, SLUG_PREFIX, SourceSpliceError, XmlContainerTracker, advancePartialKind, asKindInstance, blockAt, blockEdit, blockRangeEdit, buildAgentSchemaWithRenderBlockSupport, buildCodePointIndex, buildCompliantKindSnapshot, buildDirectiveSlug, buildKindDirective, capabilityOf, classifyInboundEnvelopeMetadata, classifyInnerFenceLine, closeFence, codeSpanText, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, decodeDirective, describeDualGateFailure, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, executesAtOutputRoot, fenceDiscriminator, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, fieldsToDbPayload, findCodeRanges, fingerprintText, formatBlockLabel, getParseSession, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDirectiveClass, isDuplicateBlockSlug, isEmptyResidue, isEscapedBracketMath, isIrEnvelopeCache, isJsonAnyField, isKindDirective, isLegacyShell, isMathPlaceholder, isProvisionalKind, isReservedDirectiveSlug, isScalarArrayType, isSingleDollarMath, isTerminalKindEvent, islandEdit, itemFacts, itemSubtitle, itemTitle, joinSource, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, legacyShellUses, listIslands, looksLikeDirectiveHead, looksLikeDisplayMath, looksLikeOpenInlineMath, makePartialKindStalenessGate, mapCodeRanges, mapPosition, mapRange, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, nounFamily, nounLabel, nounTitleColumn, openParseSession, pairDisplayMath, parseDirectiveSlug, parseFenceOpener, pendingDisplayMathOpener, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, readXmlTag, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, resetLegacyShellUses, resolvesInContent, reuseEnvelopeIfCurrent, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, singleDollarAfter, singleDollarMathEnd, spliceSave, splitsSurrogatePair, storageToKindSchema, stripKindDeep, titleCaseToken, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, tryDecodeDirective, tryDecodeDirectiveContent, validateBlockSchemaSavePlan, validateStructuralLeg, withRootKind, xmlDiscriminator };
7362
7542
  //# sourceMappingURL=index.js.map
7363
7543
  //# sourceMappingURL=index.js.map