@ai-matrx/content-ir 0.20.1 → 0.21.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
@@ -7,5 +7,5 @@ export { DualGateDefinition, DualGateInput, DualGateResolvedComponent, DualGateR
7
7
  export { ArrayItemKindBinding, BlockSchemaDraft, CONTROL_KEYS, CONTROL_KEY_FIELDS, ControlKey, ControlKeysMode, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonOptions, KindSchemaFromJsonResult, RECORD_DISPOSITION, SavePlanEntry, SavePlanValidation, SchemaConversionResult, WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys } 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 { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, 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, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes } from './source.cjs';
10
+ export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DIRECTIVE_CONTAINER_OPEN, DirectiveContainerTracker, DisturbedIsland, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceInfo, FenceLineKind, FenceLines, FenceMeta, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TITLED_IMAGE_LINE, TokenizeOptions, XmlBalanceOptions, XmlBalanceState, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, removeCodeSpans, replaceFences, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes } 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, CONTROL_KEYS, CONTROL_KEY_FIELDS, ControlKey, ControlKeysMode, ConversionProblem, DroppedMetadata, FieldComparison, ItemKindRefCheck, JsonSchemaNode, KindJsonSchemaExport, KindJsonSchemaOptions, KindSchemaFromJsonOptions, KindSchemaFromJsonResult, RECORD_DISPOSITION, SavePlanEntry, SavePlanValidation, SchemaConversionResult, WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys } 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 { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceLineKind, FenceLines, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, 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, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, unescapeCellPipes } from './source.js';
10
+ export { AFTER_WINDOW, BacktickRuns, BlockIslandType, CALLOUT_NAMES, CodePointIndex, CodeRange, DIRECTIVE_CONTAINER_OPEN, DirectiveContainerTracker, DisturbedIsland, FENCE_META_KEY, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, FenceEnd, FenceInfo, FenceLineKind, FenceLines, FenceMeta, FenceOpener, FenceReader, InlineIslandType, InnerFenceLine, IslandMeta, IslandType, LinkDefinition, MapOptions, MappedPosition, MappedRange, NESTING_FENCE_LANGUAGES, ReadXmlTag, SourceBlock, SourceBlockKind, SourceChange, SourceEdit, SourceIsland, SourceSpan, SourceSpliceError, SourceSpliceErrorCode, SpliceIntegrity, SpliceOptions, SpliceResult, TITLED_IMAGE_LINE, TokenizeOptions, XmlBalanceOptions, XmlBalanceState, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, continuesTable, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isMathPlaceholder, isPipeLedRow, isSingleDollarMath, islandEdit, joinSource, lineIndent, listIslands, looksLikeDisplayMath, looksLikeOpenInlineMath, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, normalizeLinkLabel, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readXmlTag, removeCodeSpans, replaceFences, resolveReferenceLinks, rowCells, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, tableContainerIndent, tableStartsAt, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes } from './source.js';
11
11
  import 'react';
package/dist/index.js CHANGED
@@ -8081,6 +8081,424 @@ function resolveReferenceLinks(fragment, defs) {
8081
8081
  return resolved.replace(new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g"), (_m, i) => spans[Number(i)] ?? "");
8082
8082
  }
8083
8083
 
8084
- export { ACTION_BY_CLASS, AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, CAPABILITY_BY_CLASS, CLASSES, CONTROL_KEYS, CONTROL_KEY_FIELDS, 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, RECORD_DISPOSITION, 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, collectLinkDefinitions, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, continuesTable, controlKeysApplyTo, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, createKindValidator, decodeDirective, describeDualGateFailure, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, executesAtOutputRoot, fenceDiscriminator, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, fieldsToDbPayload, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, fingerprintText, formatBlockLabel, getParseSession, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDirectiveClass, isDuplicateBlockSlug, isEmptyResidue, isEscapedBracketMath, isGfmDelimiterRow, isHtmlBlockTagName, isIrEnvelopeCache, isJsonAnyField, isKindDirective, isLegacyShell, isMathPlaceholder, isPipeLedRow, isProvisionalKind, isReservedDirectiveSlug, isScalarArrayType, isSingleDollarMath, isTerminalKindEvent, islandEdit, itemFacts, itemSubtitle, itemTitle, joinSource, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, legacyShellUses, lineIndent, listIslands, looksLikeDirectiveHead, looksLikeDisplayMath, looksLikeOpenInlineMath, makePartialKindStalenessGate, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, normalizeLinkLabel, nounFamily, nounLabel, nounTitleColumn, openParseSession, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseDirectiveSlug, parseFenceOpener, pendingCodeSpanStart, pendingDisplayMathOpener, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, readXmlTag, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, resetLegacyShellUses, resolveReferenceLinks, resolvesInContent, reuseEnvelopeIfCurrent, rowCells, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, singleDollarAfter, singleDollarMathEnd, spliceSave, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsPipelessTable, storageToKindSchema, stripControlKeys, stripKindDeep, tableContainerIndent, tableStartsAt, titleCaseToken, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine, tryDecodeDirective, tryDecodeDirectiveContent, unescapeCellPipes, validateBlockSchemaSavePlan, validateStructuralLeg, withControlKeyFields, withControlKeys, withRootKind, xmlDiscriminator };
8084
+ // source/code-range-edits.ts
8085
+ function unwrapCodeSpans(text) {
8086
+ if (!text.includes("`")) return text;
8087
+ return mapCodeRanges(text, (range, raw) => range.kind === "span" ? codeSpanText(raw) : raw);
8088
+ }
8089
+ function removeCodeSpans(text) {
8090
+ if (!text.includes("`")) return text;
8091
+ return mapCodeRanges(text, (range, raw) => range.kind === "span" ? "" : raw);
8092
+ }
8093
+ function replaceFences(text, fn) {
8094
+ if (!text.includes("```") && !text.includes("~~~")) return text;
8095
+ return mapCodeRanges(text, (range, raw) => {
8096
+ if (range.kind !== "fence") return raw;
8097
+ const parts = fenceParts(raw);
8098
+ return fn({ lang: parts?.opener.lang ?? "", body: parts?.body ?? raw, closed: parts?.closed ?? false, raw });
8099
+ });
8100
+ }
8101
+ function soleFence(text, options = {}) {
8102
+ const trimmed = text.trim();
8103
+ if (!trimmed.startsWith("`") && !trimmed.startsWith("~")) return null;
8104
+ const ranges = findCodeRanges(trimmed);
8105
+ const only = ranges.length === 1 ? ranges[0] : void 0;
8106
+ if (!only || only.kind !== "fence" || only.start !== 0 || only.end !== trimmed.length) return null;
8107
+ const parts = fenceParts(trimmed);
8108
+ if (!parts || !parts.closed && !options.allowUnclosed) return null;
8109
+ return { lang: parts.opener.lang, body: parts.body, closed: parts.closed };
8110
+ }
8111
+
8112
+ // source/plain-text.ts
8113
+ var INLINE_PATTERNS = [
8114
+ // [label](href) → label. Runs first so emphasis inside a label still unwraps.
8115
+ [/\[([^\]]+)\]\([^)]*\)/g, "$1"],
8116
+ [/\*\*\*(?=\S)([\s\S]*?\S)\*\*\*/g, "$1"],
8117
+ [/___(?=\S)([\s\S]*?\S)___/g, "$1"],
8118
+ [/\*\*(?=\S)([\s\S]*?\S)\*\*/g, "$1"],
8119
+ [/__(?=\S)([\s\S]*?\S)__/g, "$1"],
8120
+ [/~~(?=\S)([\s\S]*?\S)~~/g, "$1"],
8121
+ [/\*(?=\S)([^*\n]*?\S)\*/g, "$1"],
8122
+ // Underscore italics only between word boundaries: snake_case_names are not
8123
+ // emphasis, and mangling an identifier is a worse defect than a stray marker.
8124
+ [/(^|[\s(])_(?=\S)([^_\n]*?\S)_(?=[\s).,;:!?]|$)/g, "$1$2"]
8125
+ ];
8126
+ var MATH_STRUCTURAL = [
8127
+ [/\\(?:d|t)?frac\s*\{([^{}]*)\}\s*\{([^{}]*)\}/g, "$1/$2"],
8128
+ [/\\sqrt\s*\{([^{}]*)\}/g, "\u221A($1)"]
8129
+ ];
8130
+ var MATH_PATTERNS = [
8131
+ // Environments (\begin{aligned} … \end{aligned}) carry no meaning in a
8132
+ // one-line preview; drop the wrapper, keep the contents. Without this the
8133
+ // catch-all below turned them into the word "aligned" twice.
8134
+ [/\\(?:begin|end)\s*\{[^{}]*\}/g, " "],
8135
+ // A TeX line break inside a preview is just a space.
8136
+ [/\\\\/g, " "],
8137
+ // TeX spacing commands (\, \; \: thin/medium space, \! negative space).
8138
+ [/\\[,;:]/g, " "],
8139
+ [/\\!/g, ""],
8140
+ // \left\{ … \right\} — the escaped-brace forms, which the character-class
8141
+ // rule below cannot reach because the brace is preceded by a backslash.
8142
+ [/\\(?:left|right)\s*\\?([([\]|){}])/g, "$1"],
8143
+ // NOTE: every command below ends with (?![a-zA-Z]) and NOT \b. `_` is a WORD
8144
+ // character, so \b fails after `\sum_` — which silently left every
8145
+ // summation, integral and limit card reading as "sum_" / "int_".
8146
+ [/\\times(?![a-zA-Z])/g, "\xD7"],
8147
+ [/\\div(?![a-zA-Z])/g, "\xF7"],
8148
+ [/\\pm(?![a-zA-Z])/g, "\xB1"],
8149
+ [/\\cdot(?![a-zA-Z])/g, "\xB7"],
8150
+ [/\\leq(?![a-zA-Z])/g, "\u2264"],
8151
+ [/\\geq(?![a-zA-Z])/g, "\u2265"],
8152
+ [/\\neq(?![a-zA-Z])/g, "\u2260"],
8153
+ [/\\approx(?![a-zA-Z])/g, "\u2248"],
8154
+ [/\\infty(?![a-zA-Z])/g, "\u221E"],
8155
+ [/\\pi(?![a-zA-Z])/g, "\u03C0"],
8156
+ [/\\theta(?![a-zA-Z])/g, "\u03B8"],
8157
+ [/\\alpha(?![a-zA-Z])/g, "\u03B1"],
8158
+ [/\\beta(?![a-zA-Z])/g, "\u03B2"],
8159
+ [/\\Delta(?![a-zA-Z])/g, "\u0394"],
8160
+ [/\\delta(?![a-zA-Z])/g, "\u03B4"],
8161
+ [/\\sum(?![a-zA-Z])/g, "\u03A3"],
8162
+ [/\\prod(?![a-zA-Z])/g, "\u220F"],
8163
+ [/\\int(?![a-zA-Z])/g, "\u222B"],
8164
+ [/\\lim(?![a-zA-Z])/g, "lim"],
8165
+ [/\\(?:rightarrow|to)(?![a-zA-Z])/g, "\u2192"],
8166
+ // Braces that only ever grouped a script or argument: ^{2} → ^2, _{i} → _i.
8167
+ [/([_^])\s*\{([^{}]*)\}/g, "$1$2"],
8168
+ // Any remaining single-argument command: \text{x} / \mathrm{x} → x.
8169
+ [/\\[a-zA-Z]+\s*\{([^{}]*)\}/g, "$1"],
8170
+ // Bare commands we did not translate: drop the backslash, keep the word.
8171
+ [/\\([a-zA-Z]+)/g, "$1"]
8172
+ ];
8173
+ var MATH_REGIONS = [
8174
+ /\\\[([\s\S]*?)\\\]/g,
8175
+ /\\\(([\s\S]*?)\\\)/g,
8176
+ /\$\$([\s\S]*?)\$\$/g
8177
+ ];
8178
+ function mathToReadable(expression) {
8179
+ let text = expression;
8180
+ for (let pass = 0; pass < 8; pass += 1) {
8181
+ const before = text;
8182
+ for (const [pattern, replacement] of MATH_STRUCTURAL) {
8183
+ text = text.replace(pattern, replacement);
8184
+ }
8185
+ if (text === before) break;
8186
+ }
8187
+ for (const [pattern, replacement] of MATH_PATTERNS) {
8188
+ text = text.replace(pattern, replacement);
8189
+ }
8190
+ return text.trim();
8191
+ }
8192
+ function markdownToPlainText(value) {
8193
+ if (!value) return "";
8194
+ const mathChunks = [];
8195
+ let text = value;
8196
+ for (const region of MATH_REGIONS) {
8197
+ text = text.replace(region, (_match, inner) => {
8198
+ mathChunks.push(mathToReadable(inner));
8199
+ return `\uE000MATH${mathChunks.length - 1}\uE001`;
8200
+ });
8201
+ }
8202
+ for (const [pattern, replacement] of INLINE_PATTERNS) {
8203
+ text = text.replace(pattern, replacement);
8204
+ }
8205
+ text = unwrapCodeSpans(text);
8206
+ text = text.replace(
8207
+ /\uE000MATH(\d+)\uE001/g,
8208
+ (_m, index) => mathChunks[Number(index)] ?? ""
8209
+ );
8210
+ return text.replace(/[ \t]{2,}/g, " ").trim();
8211
+ }
8212
+ function unwrapKindEnvelopes(value) {
8213
+ if (!value) return "";
8214
+ if (!value.includes("<artifact")) return value;
8215
+ return tokenizeSource(value).map((block) => {
8216
+ if (block.kind !== "island" || block.islandType !== "xml_attr" && block.islandType !== "xml_container") {
8217
+ return block.raw;
8218
+ }
8219
+ const match = /^\s*<artifact\b[^>]*>([\s\S]*?)<\/artifact>\s*$/.exec(block.raw);
8220
+ return match ? (match[1] ?? "").replace(/^\n/, "").replace(/\n$/, "") : block.raw;
8221
+ }).join("");
8222
+ }
8223
+
8224
+ // source/clean-markdown.ts
8225
+ var cleanMarkdown = (text) => {
8226
+ if (!text || typeof text !== "string") return "";
8227
+ let cleanedText = text;
8228
+ const lines = cleanedText.split("\n");
8229
+ const processedLines = [];
8230
+ for (let line of lines) {
8231
+ let processedLine = line;
8232
+ if (processedLine.trim() === "") {
8233
+ processedLines.push(processedLine);
8234
+ continue;
8235
+ }
8236
+ processedLine = processedLine.replace(/^#{1,6}\s+(.+)$/, "$1");
8237
+ processedLine = processedLine.replace(/(\*\*|__)(.*?)\1/, "$2");
8238
+ processedLine = processedLine.replace(/(\*|_)(.*?)\1/, "$2");
8239
+ processedLine = unwrapCodeSpans(processedLine);
8240
+ processedLine = processedLine.replace(/\[([^\]]+)\]\(([^)]+)\)/, "$1");
8241
+ processedLine = processedLine.replace(/!\[([^\]]*)\]\(([^)]+)\)/, "$1");
8242
+ processedLine = processedLine.replace(/^>\s*(.+)$/, "$1");
8243
+ processedLine = processedLine.replace(/^(\*{3,}|-{3,}|_{3,})$/, "");
8244
+ processedLine = processedLine.replace(/^(\s*[-+*]\s+|\s*\d+\.\s+)(.+)$/, "$2");
8245
+ processedLine = processedLine.replace(/<\/?[^>]+(>|$)/g, "");
8246
+ processedLines.push(processedLine);
8247
+ }
8248
+ cleanedText = processedLines.join("\n");
8249
+ cleanedText = replaceFences(cleanedText, ({ body }) => body);
8250
+ return cleanedText;
8251
+ };
8252
+
8253
+ // source/fence-meta.ts
8254
+ var FENCE_META_KEY = "fenceMeta";
8255
+ function splitFenceInfo(info) {
8256
+ const trimmed = info.trim();
8257
+ if (!trimmed) return {};
8258
+ const firstSpace = trimmed.search(/\s/);
8259
+ let token = firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
8260
+ let rest = firstSpace === -1 ? "" : trimmed.slice(firstSpace).trim();
8261
+ const braceAt = token.indexOf("{");
8262
+ if (braceAt > 0) {
8263
+ rest = `${token.slice(braceAt)} ${rest}`.trim();
8264
+ token = token.slice(0, braceAt);
8265
+ }
8266
+ const colonAt = token.indexOf(":");
8267
+ if (colonAt > 0 && colonAt < token.length - 1) {
8268
+ const filename = token.slice(colonAt + 1);
8269
+ rest = `title="${filename}" ${rest}`.trim();
8270
+ token = token.slice(0, colonAt);
8271
+ }
8272
+ if (token.startsWith("{")) {
8273
+ rest = `${token} ${rest}`.trim();
8274
+ token = "";
8275
+ }
8276
+ const out = {};
8277
+ if (token) out.language = token;
8278
+ if (rest) out.meta = rest;
8279
+ return out;
8280
+ }
8281
+ var TITLE_RE = /(?:^|\s)(?:title|filename|file)=(?:"([^"]*)"|'([^']*)'|(\S+))/i;
8282
+ var RANGES_RE = /(?:^|\s)\{([\d\s,-]+)\}/;
8283
+ var LINE_NUMBERS_RE = /(?:^|\s)showLineNumbers(?:\{(\d+)\})?(?=\s|$)/;
8284
+ var MAX_HIGHLIGHT_LINES = 1e4;
8285
+ function parseFenceMeta(meta) {
8286
+ const result = { highlightLines: [] };
8287
+ if (!meta) return result;
8288
+ const title = TITLE_RE.exec(meta);
8289
+ if (title) {
8290
+ const value = (title[1] ?? title[2] ?? title[3] ?? "").trim();
8291
+ if (value) result.title = value;
8292
+ }
8293
+ const ranges = RANGES_RE.exec(meta);
8294
+ if (ranges) result.highlightLines = parseLineRanges(ranges[1] ?? "");
8295
+ const lineNumbers = LINE_NUMBERS_RE.exec(meta);
8296
+ if (lineNumbers) {
8297
+ result.showLineNumbers = true;
8298
+ if (lineNumbers[1]) {
8299
+ const start = Number.parseInt(lineNumbers[1], 10);
8300
+ if (Number.isFinite(start) && start > 0) result.startLine = start;
8301
+ }
8302
+ }
8303
+ return result;
8304
+ }
8305
+ function parseLineRanges(spec) {
8306
+ const lines = /* @__PURE__ */ new Set();
8307
+ for (const part of spec.split(",")) {
8308
+ const piece = part.trim();
8309
+ if (!piece) continue;
8310
+ const range = /^(\d+)\s*-\s*(\d+)$/.exec(piece);
8311
+ if (range) {
8312
+ const from = Number.parseInt(range[1] ?? "", 10);
8313
+ const to = Number.parseInt(range[2] ?? "", 10);
8314
+ if (from < 1 || to < from) continue;
8315
+ for (let n = from; n <= to && lines.size < MAX_HIGHLIGHT_LINES; n += 1) {
8316
+ lines.add(n);
8317
+ }
8318
+ continue;
8319
+ }
8320
+ if (/^\d+$/.test(piece)) {
8321
+ const n = Number.parseInt(piece, 10);
8322
+ if (n >= 1) lines.add(n);
8323
+ }
8324
+ }
8325
+ return [...lines].sort((a, b) => a - b);
8326
+ }
8327
+
8328
+ // source/directive-container.ts
8329
+ var DIRECTIVE_CONTAINER_OPEN = /^[ \t]{0,3}(:{3,})[A-Za-z][\w-]*/;
8330
+ var CLOSE = /^[ \t]{0,3}(:{3,})[ \t]*$/;
8331
+ var DirectiveContainerTracker = class {
8332
+ stack;
8333
+ fence = null;
8334
+ constructor(openingLine) {
8335
+ const m = DIRECTIVE_CONTAINER_OPEN.exec(openingLine);
8336
+ this.stack = [m ? m[1].length : 3];
8337
+ }
8338
+ /** Feed the next line (after the opener). True once the outermost container has closed on this line. */
8339
+ consume(line) {
8340
+ if (this.fence) {
8341
+ if (this.fence.feed(line)) this.fence = null;
8342
+ return false;
8343
+ }
8344
+ const opener = fenceOpenerOf(line);
8345
+ if (opener) {
8346
+ this.fence = new FenceReader(opener);
8347
+ return false;
8348
+ }
8349
+ const open = DIRECTIVE_CONTAINER_OPEN.exec(line);
8350
+ if (open) {
8351
+ this.stack.push(open[1].length);
8352
+ return false;
8353
+ }
8354
+ const close = CLOSE.exec(line);
8355
+ if (close && close[1].length >= (this.stack[this.stack.length - 1] ?? 3)) {
8356
+ this.stack.pop();
8357
+ return this.stack.length === 0;
8358
+ }
8359
+ return false;
8360
+ }
8361
+ };
8362
+
8363
+ // source/image-figure.ts
8364
+ var TITLED_IMAGE_LINE = /^[ \t]{0,3}!\[[^\]\n]*\]\(\s*<?[^\s)>]+>?\s+(?:"[^"\n]+"|'[^'\n]+')\s*\)[ \t]*$/;
8365
+
8366
+ // source/inline-code-span.ts
8367
+ function isInsideInlineCode(line, at) {
8368
+ let i = 0;
8369
+ while (i <= at && i < line.length) {
8370
+ if (line[i] === "\\") {
8371
+ i += 2;
8372
+ continue;
8373
+ }
8374
+ if (line[i] !== "`") {
8375
+ i += 1;
8376
+ continue;
8377
+ }
8378
+ let run = 0;
8379
+ while (line[i + run] === "`") run += 1;
8380
+ let close = -1;
8381
+ for (let j = i + run; j < line.length; ) {
8382
+ if (line[j] !== "`") {
8383
+ j += 1;
8384
+ continue;
8385
+ }
8386
+ let r = 0;
8387
+ while (line[j + r] === "`") r += 1;
8388
+ if (r === run) {
8389
+ close = j;
8390
+ break;
8391
+ }
8392
+ j += r;
8393
+ }
8394
+ if (close === -1) {
8395
+ i += run;
8396
+ continue;
8397
+ }
8398
+ if (at > i && at < close + run) return true;
8399
+ i = close + run;
8400
+ }
8401
+ return false;
8402
+ }
8403
+ function indexOutsideInlineCode(line, needle, from = 0) {
8404
+ for (let idx = line.indexOf(needle, from); idx !== -1; idx = line.indexOf(needle, idx + 1)) {
8405
+ if (!isInsideInlineCode(line, idx)) return idx;
8406
+ }
8407
+ return -1;
8408
+ }
8409
+ function hasUnclosedBacktickRun(text) {
8410
+ let i = 0;
8411
+ while (i < text.length) {
8412
+ if (text[i] === "\\") {
8413
+ i += 2;
8414
+ continue;
8415
+ }
8416
+ if (text[i] !== "`") {
8417
+ i += 1;
8418
+ continue;
8419
+ }
8420
+ let run = 0;
8421
+ while (text[i + run] === "`") run += 1;
8422
+ let close = -1;
8423
+ for (let j = i + run; j < text.length; ) {
8424
+ if (text[j] !== "`") {
8425
+ j += 1;
8426
+ continue;
8427
+ }
8428
+ let r = 0;
8429
+ while (text[j + r] === "`") r += 1;
8430
+ if (r === run) {
8431
+ close = j;
8432
+ break;
8433
+ }
8434
+ j += r;
8435
+ }
8436
+ if (close === -1) return true;
8437
+ i = close + run;
8438
+ }
8439
+ return false;
8440
+ }
8441
+
8442
+ // source/xml-tag-balance.ts
8443
+ function initialXmlBalance() {
8444
+ return { depth: 1, fence: null };
8445
+ }
8446
+ function escapeRegExp(value) {
8447
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
8448
+ }
8449
+ function findBalancedXmlClose(line, tagName, state, { trackFences = true, nest = true } = {}) {
8450
+ if (state.fence) {
8451
+ if (state.fence.feed(line)) state.fence = null;
8452
+ return -1;
8453
+ }
8454
+ const opener = trackFences ? fenceOpenerOf(line) : null;
8455
+ if (opener) {
8456
+ state.fence = new FenceReader(opener);
8457
+ return -1;
8458
+ }
8459
+ const tag = new RegExp(
8460
+ `<(\\/?)${escapeRegExp(tagName)}(?=[\\s>/])[^<>]*?(\\/?)>`,
8461
+ "g"
8462
+ );
8463
+ for (const match of line.matchAll(tag)) {
8464
+ const closing = match[1] === "/";
8465
+ const selfClosing = match[2] === "/";
8466
+ if (closing) {
8467
+ state.depth -= 1;
8468
+ if (state.depth === 0) return match.index ?? -1;
8469
+ } else if (nest && !selfClosing && line.slice(0, match.index).trim() === "") {
8470
+ state.depth += 1;
8471
+ }
8472
+ }
8473
+ return -1;
8474
+ }
8475
+
8476
+ // source/gfm-table-lines.ts
8477
+ function findWholeTableStart(lines, from = 0) {
8478
+ for (let i = Math.max(0, from); i + 1 < lines.length; i += 1) if (tableStartsAt(lines, i)) return i;
8479
+ return -1;
8480
+ }
8481
+ function startsLikeTableRow(line) {
8482
+ return /^\s*\|/.test(line);
8483
+ }
8484
+ function isGrowingDelimiterRow(line) {
8485
+ return /^[\s|:-]*-[\s|:-]*$/.test(line);
8486
+ }
8487
+ function trailingTableStart(lines, end = lines.length) {
8488
+ const isTableLine = (line) => startsLikeTableRow(line) || continuesTable(line.trimStart());
8489
+ let start = end;
8490
+ while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
8491
+ if (start === end && end > 1 && isGrowingDelimiterRow(lines[end - 1] ?? "") && continuesTable((lines[end - 2] ?? "").trimStart())) {
8492
+ start = end - 1;
8493
+ while (start > 0 && isTableLine(lines[start - 1] ?? "")) start -= 1;
8494
+ }
8495
+ for (let head = start; head < end; head += 1) {
8496
+ if (startsLikeTableRow(lines[head] ?? "")) return head;
8497
+ if (end - head > 1 && isGrowingDelimiterRow(lines[head + 1] ?? "")) return head;
8498
+ }
8499
+ return end;
8500
+ }
8501
+
8502
+ export { ACTION_BY_CLASS, AFTER_WINDOW, BacktickRuns, CALLOUT_NAMES, CAPABILITY_BY_CLASS, CLASSES, CONTROL_KEYS, CONTROL_KEY_FIELDS, DIRECTIVE_CONTAINER_OPEN, DIRECTIVE_VERSION, DirectiveContainerTracker, DirectiveDecodeError, FENCE_META_KEY, 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, RECORD_DISPOSITION, RESERVED_PREFIX, ROOT_STORAGE_NAME, RUN_RESULT_KIND, SIDE_EFFECT_CLASSES, SLUG_PREFIX, SourceSpliceError, TITLED_IMAGE_LINE, XmlContainerTracker, advancePartialKind, asKindInstance, blockAt, blockEdit, blockRangeEdit, buildAgentSchemaWithRenderBlockSupport, buildCodePointIndex, buildCompliantKindSnapshot, buildDirectiveSlug, buildKindDirective, capabilityOf, classifyInboundEnvelopeMetadata, classifyInnerFenceLine, cleanMarkdown, closeFence, codeSpanText, collectLinkDefinitions, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, continuesTable, controlKeysApplyTo, convertAiSchemaToBlockFields, createFingerprinter, createKindStreamParser, createKindValidator, decodeDirective, describeDualGateFailure, directiveDisplay, directiveItemKindFromEdges, directiveSlugOf, disposeParseSession, emitPayloadFence, emitPayloadJson, emptyValueForFieldSchema, envelopeCacheFromEnvelopes, envelopeFromCompleteValue, executesAtOutputRoot, fenceDiscriminator, fenceLineKinds, fenceNestsInnerFences, fenceOpenerOf, fenceParts, fieldsToDbPayload, findBalancedXmlClose, findCodeRanges, findInlineCodeSpans, findLinkDefinitionLines, findTableEnd, findTableStart, findWholeTableStart, fingerprintText, formatBlockLabel, getParseSession, hasUnclosedBacktickRun, indexOutsideInlineCode, initialXmlBalance, injectKindIntoObjectSchema, irPathIsUnderOrEqual, irPathKey, irPathLabel, irPathsEqual, isCanonicalBlockIR, isDirectiveClass, isDuplicateBlockSlug, isEmptyResidue, isEscapedBracketMath, isGfmDelimiterRow, isGrowingDelimiterRow, isHtmlBlockTagName, isInsideInlineCode, isIrEnvelopeCache, isJsonAnyField, isKindDirective, isLegacyShell, isMathPlaceholder, isPipeLedRow, isProvisionalKind, isReservedDirectiveSlug, isScalarArrayType, isSingleDollarMath, isTerminalKindEvent, islandEdit, itemFacts, itemSubtitle, itemTitle, joinSource, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, kindSchemaToStorage, kindVerdictOf, legacyShellUses, lineIndent, listIslands, looksLikeDirectiveHead, looksLikeDisplayMath, looksLikeOpenInlineMath, makePartialKindStalenessGate, mapCodeRanges, mapInlineCodeSpans, mapPosition, mapRange, markdownToPlainText, mathToReadable, mergeResidueIntoValue, normalizeAiSchemaInput, normalizeJsonRegion, normalizeLinkLabel, nounFamily, nounLabel, nounTitleColumn, openParseSession, opensStrippedHtmlBlock, opensTable, pairDisplayMath, parseDirectiveSlug, parseFenceMeta, parseFenceOpener, parseLineRanges, pendingCodeSpanStart, pendingDisplayMathOpener, readEnvelope, readNodeOutcomeValue, readObjectKind, readOutputRef, readPartialKindEvent, readRunResultValue, readXmlTag, reconstructRegionValue, rehydrateNodeOutcome, rehydrateRunResult, removeCodeSpans, replaceFences, resetLegacyShellUses, resolveReferenceLinks, resolvesInContent, reuseEnvelopeIfCurrent, rowCells, runKindDualGate, runSchemaConversion, sanitizeInboundEnvelopeMetadata, sanitizeInboundPartialKindMetadata, scalarArrayItemType, schemaLayoutMode, schemaStructureDepth, setJsonRootKeyLookup, singleDollarAfter, singleDollarMathEnd, soleFence, spliceSave, splitFenceInfo, splitRowSegments, splitsSurrogatePair, startsHtmlBlock, startsLikeTableRow, startsPipelessTable, storageToKindSchema, stripControlKeys, stripKindDeep, tableContainerIndent, tableStartsAt, titleCaseToken, toCodePointOffset, toUtf16Offset, tokenizeSource, trailingTableStart, trimFenceLine, tryDecodeDirective, tryDecodeDirectiveContent, unescapeCellPipes, unwrapCodeSpans, unwrapKindEnvelopes, validateBlockSchemaSavePlan, validateStructuralLeg, withControlKeyFields, withControlKeys, withRootKind, xmlDiscriminator };
8085
8503
  //# sourceMappingURL=index.js.map
8086
8504
  //# sourceMappingURL=index.js.map