@ai-matrx/content-ir 0.18.5 → 0.19.0

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
@@ -3,7 +3,7 @@ export { I as IrTree, a as IrTreeNode, J as JsonPath, K as KindStreamEvent, b as
3
3
  export { CompleteValueEnvelopeOptions, CompliantKindSnapshot, ContentRegionInit, Fingerprinter, IR_ENVELOPE_CACHE_VERSION, InboundEnvelopeHooks, InboundEnvelopeVerdict, IrEnvelopeCache, JSON_DISCRIMINATOR, JsonStreamTokenizer, JsonToken, KindResolution, NormalizeJsonRegionOptions, Punct, RegionEndReason, RegionFormat, RegionSourceKind, SchemaLayoutMode, buildCompliantKindSnapshot, classifyInboundEnvelopeMetadata, createFingerprinter, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, fenceDiscriminator, fingerprintText, formatBlockLabel, isCanonicalBlockIR, isIrEnvelopeCache, mergeResidueIntoValue, normalizeJsonRegion, readEnvelope, reconstructRegionValue, reuseEnvelopeIfCurrent, sanitizeInboundEnvelopeMetadata, schemaLayoutMode, schemaStructureDepth, stripKindDeep, xmlDiscriminator } from './core.cjs';
4
4
  export { A as ArrayItemScalarType, F as FieldSchema, K as KIND_KEY, a as KindSchema, R as RecordValueType, S as ScalarFieldType, i as isJsonAnyField, b as isScalarArrayType, r as readObjectKind, s as scalarArrayItemType } from './kind-schema.types-CwncWj9U.cjs';
5
5
  export { ParseSession, ParseSessionOptions, disposeParseSession, getParseSession, openParseSession } from './session.cjs';
6
- export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateResult, KindBlockProps, KindDefinition, KindEdgeSpec, KindStorageError, KindStorageShape, KindTier, LegResult, ROOT_STORAGE_NAME, StoredFieldElement, describeDualGateFailure, kindSchemaToStorage, runKindDualGate, storageToKindSchema, validateStructuralLeg } from './registry.cjs';
6
+ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateResult, Json, KindBlockProps, KindDefinition, KindEdgeSpec, KindStorageError, KindStorageShape, KindTier, KindValidationResult, KindValidator, KindValidatorOptions, LegResult, ROOT_STORAGE_NAME, SchemaSourcePort, SchemaUnavailableReason, StoredFieldElement, createKindValidator, describeDualGateFailure, kindSchemaToStorage, runKindDualGate, storageToKindSchema, validateStructuralLeg } from './registry.cjs';
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';
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { I as IrTree, a as IrTreeNode, J as JsonPath, K as KindStreamEvent, b as
3
3
  export { CompleteValueEnvelopeOptions, CompliantKindSnapshot, ContentRegionInit, Fingerprinter, IR_ENVELOPE_CACHE_VERSION, InboundEnvelopeHooks, InboundEnvelopeVerdict, IrEnvelopeCache, JSON_DISCRIMINATOR, JsonStreamTokenizer, JsonToken, KindResolution, NormalizeJsonRegionOptions, Punct, RegionEndReason, RegionFormat, RegionSourceKind, SchemaLayoutMode, buildCompliantKindSnapshot, classifyInboundEnvelopeMetadata, createFingerprinter, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, fenceDiscriminator, fingerprintText, formatBlockLabel, isCanonicalBlockIR, isIrEnvelopeCache, mergeResidueIntoValue, normalizeJsonRegion, readEnvelope, reconstructRegionValue, reuseEnvelopeIfCurrent, sanitizeInboundEnvelopeMetadata, schemaLayoutMode, schemaStructureDepth, stripKindDeep, xmlDiscriminator } from './core.js';
4
4
  export { A as ArrayItemScalarType, F as FieldSchema, K as KIND_KEY, a as KindSchema, R as RecordValueType, S as ScalarFieldType, i as isJsonAnyField, b as isScalarArrayType, r as readObjectKind, s as scalarArrayItemType } from './kind-schema.types-CwncWj9U.js';
5
5
  export { ParseSession, ParseSessionOptions, disposeParseSession, getParseSession, openParseSession } from './session.js';
6
- export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateResult, KindBlockProps, KindDefinition, KindEdgeSpec, KindStorageError, KindStorageShape, KindTier, LegResult, ROOT_STORAGE_NAME, StoredFieldElement, describeDualGateFailure, kindSchemaToStorage, runKindDualGate, storageToKindSchema, validateStructuralLeg } from './registry.js';
6
+ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateResult, Json, KindBlockProps, KindDefinition, KindEdgeSpec, KindStorageError, KindStorageShape, KindTier, KindValidationResult, KindValidator, KindValidatorOptions, LegResult, ROOT_STORAGE_NAME, SchemaSourcePort, SchemaUnavailableReason, StoredFieldElement, createKindValidator, describeDualGateFailure, kindSchemaToStorage, runKindDualGate, storageToKindSchema, validateStructuralLeg } from './registry.js';
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';
package/dist/index.js CHANGED
@@ -2962,6 +2962,93 @@ function describeDualGateFailure(kind, result) {
2962
2962
  return `kind "${kind}" failed the dual gate \u2014 ${parts.join(" | ")}`;
2963
2963
  }
2964
2964
 
2965
+ // registry/kind-validator.ts
2966
+ var SCHEMA_COMPILE_FAILURE_PREFIX = "emitted_json_schema failed to compile:";
2967
+ var DEFAULT_CACHE_TTL_MS = 3e4;
2968
+ function unavailableMessage(kind, reason, detail) {
2969
+ switch (reason) {
2970
+ case "kind_not_registered":
2971
+ return `kind "${kind}" is not registered in content_ir.kind_definition`;
2972
+ case "schema_unavailable":
2973
+ return `kind "${kind}" has no emitted_json_schema \u2014 nothing to validate against`;
2974
+ case "schema_invalid":
2975
+ return `kind "${kind}" has an uncompilable emitted_json_schema${detail ? `: ${detail}` : ""}`;
2976
+ case "catalog_unreachable":
2977
+ return `could not read the contract for kind "${kind}"${detail ? `: ${detail}` : ""}`;
2978
+ }
2979
+ }
2980
+ function degraded(kind, reason, detail) {
2981
+ return {
2982
+ kind,
2983
+ checked: false,
2984
+ ok: false,
2985
+ errors: [unavailableMessage(kind, reason, detail)],
2986
+ degradedReason: reason
2987
+ };
2988
+ }
2989
+ function createKindValidator(source, options = {}) {
2990
+ const ttl = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
2991
+ const now = options.now ?? Date.now;
2992
+ const cache = /* @__PURE__ */ new Map();
2993
+ async function fetchSchema(kind, signal) {
2994
+ const cached = cache.get(kind);
2995
+ if (cached && now() - cached.fetchedAt <= ttl) {
2996
+ return { schema: cached.schema, version: cached.version };
2997
+ }
2998
+ let answer;
2999
+ try {
3000
+ answer = await source.kindSchema(kind, signal);
3001
+ } catch (err) {
3002
+ return {
3003
+ unavailable: "catalog_unreachable",
3004
+ detail: err instanceof Error ? err.message : String(err)
3005
+ };
3006
+ }
3007
+ if ("unavailable" in answer) return { unavailable: answer.unavailable };
3008
+ if (answer.schema == null) {
3009
+ return { unavailable: "schema_unavailable" };
3010
+ }
3011
+ cache.set(kind, {
3012
+ schema: answer.schema,
3013
+ version: answer.version,
3014
+ fetchedAt: now()
3015
+ });
3016
+ return answer;
3017
+ }
3018
+ return {
3019
+ async validate(value, kind, signal = new AbortController().signal) {
3020
+ if (!kind || typeof kind !== "string") {
3021
+ throw new TypeError(
3022
+ `validateAgainstKind: "kind" must be a non-empty slug (received ${typeof kind})`
3023
+ );
3024
+ }
3025
+ const fetched = await fetchSchema(kind, signal);
3026
+ if ("unavailable" in fetched) {
3027
+ return degraded(kind, fetched.unavailable, fetched.detail);
3028
+ }
3029
+ const leg = validateStructuralLeg(value, fetched.schema);
3030
+ if (!leg.ok && leg.detail?.startsWith(SCHEMA_COMPILE_FAILURE_PREFIX)) {
3031
+ return degraded(kind, "schema_invalid", leg.detail);
3032
+ }
3033
+ return {
3034
+ kind,
3035
+ checked: true,
3036
+ ok: leg.ok,
3037
+ errors: leg.ok ? [] : [leg.detail ?? "validation failed"],
3038
+ degradedReason: null
3039
+ };
3040
+ },
3041
+ async cachedSchema(kind, signal = new AbortController().signal) {
3042
+ const fetched = await fetchSchema(kind, signal);
3043
+ return "unavailable" in fetched ? null : fetched.schema;
3044
+ },
3045
+ invalidate(kind) {
3046
+ if (kind) cache.delete(kind);
3047
+ else cache.clear();
3048
+ }
3049
+ };
3050
+ }
3051
+
2965
3052
  // convert/openai-schema-converter.ts
2966
3053
  function requiredNullableFlags(required, nullable) {
2967
3054
  return {
@@ -5237,12 +5324,6 @@ function fenceOpenerOf(content) {
5237
5324
  return null;
5238
5325
  }
5239
5326
  var FenceReader = class {
5240
- constructor(opener, options = {}) {
5241
- this.opener = opener;
5242
- this.isJson = opener.char === "`" && opener.lang === "json";
5243
- this.nesting = opener.char === "`" && (options.nesting ?? fenceNestsInnerFences(opener.lang));
5244
- this.tildeCloser = opener.char === "~" ? new RegExp(`^ {0,3}~{${opener.ticks},}[ \\t]*$`) : null;
5245
- }
5246
5327
  opener;
5247
5328
  state = { inString: false, escaped: false };
5248
5329
  depth = 0;
@@ -5251,6 +5332,12 @@ var FenceReader = class {
5251
5332
  isJson;
5252
5333
  nesting;
5253
5334
  tildeCloser;
5335
+ constructor(opener, options = {}) {
5336
+ this.opener = opener;
5337
+ this.isJson = opener.char === "`" && opener.lang === "json";
5338
+ this.nesting = opener.char === "`" && (options.nesting ?? fenceNestsInnerFences(opener.lang));
5339
+ this.tildeCloser = opener.char === "~" ? new RegExp(`^ {0,3}~{${opener.ticks},}[ \\t]*$`) : null;
5340
+ }
5254
5341
  /** How many nested fences are open right now. */
5255
5342
  get nestedDepth() {
5256
5343
  return this.depth;
@@ -5868,9 +5955,6 @@ function isEscapedBacktick(line, offset) {
5868
5955
  return slashes % 2 === 1;
5869
5956
  }
5870
5957
  var XmlContainerTracker = class {
5871
- constructor(rootTag) {
5872
- this.rootTag = rootTag;
5873
- }
5874
5958
  rootTag;
5875
5959
  depth = 0;
5876
5960
  inComment = false;
@@ -5878,6 +5962,9 @@ var XmlContainerTracker = class {
5878
5962
  inlineTicks = 0;
5879
5963
  /** The open fence, read by THE one closer (source/code-ranges.ts). */
5880
5964
  fence = null;
5965
+ constructor(rootTag) {
5966
+ this.rootTag = rootTag;
5967
+ }
5881
5968
  consumeLine(line, startOffset = 0) {
5882
5969
  if (this.fence) {
5883
5970
  if (this.fence.feed(line)) this.fence = null;
@@ -6089,6 +6176,23 @@ function isSplitterTreeLine(line) {
6089
6176
  }
6090
6177
  var MEDIA_REF_PREFIXES = ["[Image URL:", "[Video URL:", "[Audio URL:"];
6091
6178
  var Tokenizer = class {
6179
+ text;
6180
+ streaming;
6181
+ meter;
6182
+ n;
6183
+ lineStarts = [];
6184
+ contentEnds = [];
6185
+ lineEnds = [];
6186
+ blocks = [];
6187
+ blockCache = /* @__PURE__ */ new Map();
6188
+ /** Lazily built: for line i, first line j >= i where brace net from i drops to <= 0. */
6189
+ braceStop = null;
6190
+ braceNet = null;
6191
+ /** Every occurrence offset of each needle searched so far (overlapping, like indexOf). */
6192
+ occurrences = /* @__PURE__ */ new Map();
6193
+ /** `$$` opener → closer for the pairs the core renders as math. */
6194
+ mathPairs;
6195
+ finder = (needle, from) => this.next(needle, from);
6092
6196
  constructor(text, streaming = false, meter = void 0) {
6093
6197
  this.text = text;
6094
6198
  this.streaming = streaming;
@@ -6135,23 +6239,6 @@ var Tokenizer = class {
6135
6239
  this.lineEnds.push(text.length);
6136
6240
  }
6137
6241
  }
6138
- text;
6139
- streaming;
6140
- meter;
6141
- n;
6142
- lineStarts = [];
6143
- contentEnds = [];
6144
- lineEnds = [];
6145
- blocks = [];
6146
- blockCache = /* @__PURE__ */ new Map();
6147
- /** Lazily built: for line i, first line j >= i where brace net from i drops to <= 0. */
6148
- braceStop = null;
6149
- braceNet = null;
6150
- /** Every occurrence offset of each needle searched so far (overlapping, like indexOf). */
6151
- occurrences = /* @__PURE__ */ new Map();
6152
- /** `$$` opener → closer for the pairs the core renders as math. */
6153
- mathPairs;
6154
- finder = (needle, from) => this.next(needle, from);
6155
6242
  /** Streaming: where provisional text starts (a pending `$$`), or +∞. */
6156
6243
  provisionalFrom = Number.POSITIVE_INFINITY;
6157
6244
  /** Streaming: the text ends in a lone CR whose LF has not arrived yet. */
@@ -6208,10 +6295,13 @@ var Tokenizer = class {
6208
6295
  /**
6209
6296
  * Streaming: an open block that may still turn back into prose — a `$$`
6210
6297
  * pair whose closer is on the open last line (prose after it makes it
6211
- * inline), or a JSON head whose braces have not balanced (it may never parse).
6298
+ * inline), a JSON head whose braces have not balanced (it may never parse),
6299
+ * or any opener that is itself still arriving on the open last line.
6212
6300
  */
6213
6301
  mayDissolve(block) {
6214
- return this.streaming && !block.complete && (block.type === "math_block" || block.type === "json");
6302
+ if (!this.streaming || block.complete) return false;
6303
+ if (block.type === "math_block" || block.type === "json") return true;
6304
+ return this.isOpenTail(this.lineOf(block.start));
6215
6305
  }
6216
6306
  /** Streaming: paragraph ends where an undecided, dissolvable block cut them short. */
6217
6307
  undecidedBreaks = /* @__PURE__ */ new Set();
@@ -6232,6 +6322,12 @@ var Tokenizer = class {
6232
6322
  }
6233
6323
  return lo;
6234
6324
  }
6325
+ /** How many whitespace characters open the text at `from` (up to `to`). */
6326
+ leadingSpace(from, to) {
6327
+ let k = from;
6328
+ while (k < to && /\s/.test(this.text[k])) k++;
6329
+ return k - from;
6330
+ }
6235
6331
  isBlank(from, to) {
6236
6332
  return !NOT_WHITESPACE.test(this.text.slice(from, to));
6237
6333
  }
@@ -6256,6 +6352,10 @@ var Tokenizer = class {
6256
6352
  break;
6257
6353
  }
6258
6354
  const island = this.detectBlock(pos, li, true);
6355
+ if (island && pos + this.leadingSpace(pos, this.contentEnds[li]) >= this.provisionalFrom) {
6356
+ this.push({ kind: "prose", start: pos, end: this.n, island: null, inlines: [] });
6357
+ break;
6358
+ }
6259
6359
  if (island) {
6260
6360
  this.push({ kind: "island", start: island.start, end: island.end, island, inlines: [] });
6261
6361
  pos = island.end;
@@ -6285,12 +6385,6 @@ var Tokenizer = class {
6285
6385
  const last = this.lineStarts.length - 1;
6286
6386
  if (last < 0) return;
6287
6387
  if (this.isOpenTail(last)) {
6288
- const lineStart = this.lineStarts[last];
6289
- for (const block2 of this.blocks) {
6290
- if (block2.kind === "prose" && block2.end > lineStart) {
6291
- block2.inlines = block2.inlines.filter((inline) => inline.end <= lineStart);
6292
- }
6293
- }
6294
6388
  let b = this.blocks.length - 1;
6295
6389
  while (b >= 0 && this.blocks[b].kind === "gap") b--;
6296
6390
  const block = this.blocks[b];
@@ -6316,36 +6410,55 @@ var Tokenizer = class {
6316
6410
  * region…) is never a tree line nor a root label, so it stops the walk.
6317
6411
  */
6318
6412
  treeRootHoldFrom() {
6319
- const claimable = (k2) => {
6413
+ const claimFrom = (k2) => {
6414
+ const lineStart = this.lineStarts[k2];
6415
+ const lineEnd = this.contentEnds[k2];
6416
+ let pos = lineStart;
6320
6417
  for (; ; ) {
6321
- const block = this.blockAt(this.lineStarts[k2]);
6322
- if (!block || block.kind !== "island" || block.island?.fromParagraph === true) return true;
6323
- const opened = this.lineOf(block.start);
6324
- if (this.lineStarts[opened] === block.start || opened === k2) return false;
6325
- k2 = opened;
6418
+ const block = this.blockAt(pos);
6419
+ if (!block || block.kind !== "island" || !block.island) return pos;
6420
+ if (block.island.fromParagraph === true || this.mayDissolve(block.island)) return pos;
6421
+ if (block.start < lineStart) {
6422
+ const opened = this.lineOf(block.start);
6423
+ if (this.lineStarts[opened] !== block.start && claimFrom(opened) !== -1) return pos;
6424
+ if (block.end >= lineEnd) return -1;
6425
+ pos = block.end;
6426
+ continue;
6427
+ }
6428
+ if (block.end >= lineEnd) return -1;
6429
+ pos = block.end;
6326
6430
  }
6327
6431
  };
6328
6432
  let k = this.lineCount - 1;
6329
6433
  let start = this.lineCount;
6434
+ let startPos = this.n;
6330
6435
  if (k >= 0 && this.isOpenTail(k)) {
6331
- if (!claimable(k)) return this.n;
6436
+ const at = claimFrom(k);
6437
+ if (at === -1) return this.n;
6332
6438
  start = k;
6439
+ startPos = at;
6333
6440
  k--;
6334
6441
  }
6335
- for (; k >= 0 && claimable(k); k--) {
6442
+ for (; k >= 0; k--) {
6336
6443
  this.tick(1);
6444
+ const at = claimFrom(k);
6445
+ if (at === -1) break;
6337
6446
  if (this.lineIsBlank(k)) continue;
6338
6447
  if (!TREE_GLYPHS.test(this.lineText(k))) break;
6339
6448
  start = k;
6449
+ startPos = at;
6340
6450
  }
6341
- let root = start;
6342
- for (let j = start - 1; j >= 0 && claimable(j); j--) {
6451
+ let rootPos = startPos;
6452
+ for (let j = start - 1; j >= 0; j--) {
6453
+ const at = claimFrom(j);
6454
+ if (at === -1) break;
6343
6455
  const trimmed = this.lineText(j).trim();
6344
6456
  this.tick(trimmed.length + 1);
6345
6457
  if (!trimmed || isSplitterTreeLine(trimmed) || /^#{1,6}\s/.test(trimmed)) break;
6346
- root = j;
6458
+ rootPos = at;
6459
+ if (at > this.lineStarts[j]) break;
6347
6460
  }
6348
- return root < this.lineCount ? this.lineStarts[root] : this.n;
6461
+ return rootPos;
6349
6462
  }
6350
6463
  /** The block (so far) containing offset `pos`, or null. */
6351
6464
  blockAt(pos) {
@@ -6877,7 +6990,9 @@ var Tokenizer = class {
6877
6990
  const block = this.detectBlock(this.lineStarts[k], k, false);
6878
6991
  if (block) {
6879
6992
  breakLine = k;
6880
- if (this.mayDissolve(block)) this.undecidedBreaks.add(end);
6993
+ if (this.mayDissolve(block) || this.streaming && block.start >= this.provisionalFrom) {
6994
+ this.undecidedBreaks.add(end);
6995
+ }
6881
6996
  break;
6882
6997
  }
6883
6998
  end = this.contentEnds[k];
@@ -7115,6 +7230,10 @@ var Tokenizer = class {
7115
7230
  const closer = `</${name}>`;
7116
7231
  const close = this.next(closer, tagEnd);
7117
7232
  const blockType = isAttr ? "xml_attr" : "xml_region";
7233
+ if (close === -1 && isThinking && !this.streaming) {
7234
+ i = tagEnd;
7235
+ continue;
7236
+ }
7118
7237
  if (close === -1) return stop(this.island(blockType, i, this.n, false, { tag: name }));
7119
7238
  const end = close + closer.length;
7120
7239
  if (end > pe) return stop(this.spill(blockType, i, end, pe, { tag: name }));
@@ -7218,12 +7337,12 @@ function blockAt(blocks, offset) {
7218
7337
 
7219
7338
  // source/splice.ts
7220
7339
  var SourceSpliceError = class extends Error {
7340
+ code;
7221
7341
  constructor(code, message) {
7222
7342
  super(message);
7223
7343
  this.code = code;
7224
7344
  this.name = "SourceSpliceError";
7225
7345
  }
7226
- code;
7227
7346
  };
7228
7347
  function blockEdit(block, text) {
7229
7348
  return { start: block.start, end: block.end, text };
@@ -7502,6 +7621,6 @@ function mapRange(changes, start, end, unit = "utf16") {
7502
7621
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
7503
7622
  }
7504
7623
 
7505
- 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 };
7624
+ 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, createKindValidator, 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 };
7506
7625
  //# sourceMappingURL=index.js.map
7507
7626
  //# sourceMappingURL=index.js.map