@driftsys/markspec 0.11.0 → 0.12.1

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.
Files changed (176) hide show
  1. package/README.md +9 -0
  2. package/esm/ast/normalize.d.ts +4 -5
  3. package/esm/ast/normalize.d.ts.map +1 -1
  4. package/esm/ast/normalize.js +6 -37
  5. package/esm/collect/mod.d.ts +29 -9
  6. package/esm/collect/mod.d.ts.map +1 -1
  7. package/esm/collect/mod.js +36 -10
  8. package/esm/compiler/mod.d.ts.map +1 -1
  9. package/esm/compiler/mod.js +2 -6
  10. package/esm/config/markspec.d.ts +5 -3
  11. package/esm/config/markspec.d.ts.map +1 -1
  12. package/esm/config/mod.d.ts.map +1 -1
  13. package/esm/config/mod.js +47 -5
  14. package/esm/discovery/mod.d.ts +24 -8
  15. package/esm/discovery/mod.d.ts.map +1 -1
  16. package/esm/discovery/mod.js +57 -21
  17. package/esm/discovery/projects.d.ts +111 -0
  18. package/esm/discovery/projects.d.ts.map +1 -0
  19. package/esm/discovery/projects.js +242 -0
  20. package/esm/formatter/entry_body.d.ts +84 -0
  21. package/esm/formatter/entry_body.d.ts.map +1 -0
  22. package/esm/formatter/entry_body.js +291 -0
  23. package/esm/formatter/md_equiv.d.ts +6 -5
  24. package/esm/formatter/md_equiv.d.ts.map +1 -1
  25. package/esm/formatter/md_equiv.js +6 -5
  26. package/esm/formatter/mod.d.ts +16 -9
  27. package/esm/formatter/mod.d.ts.map +1 -1
  28. package/esm/formatter/mod.js +327 -53
  29. package/esm/formatter/tab_markers.d.ts +15 -0
  30. package/esm/formatter/tab_markers.d.ts.map +1 -0
  31. package/esm/formatter/tab_markers.js +133 -0
  32. package/esm/gates/mod.d.ts.map +1 -1
  33. package/esm/gates/mod.js +6 -5
  34. package/esm/lint/runner.d.ts.map +1 -1
  35. package/esm/lint/runner.js +4 -4
  36. package/esm/lock/check.d.ts.map +1 -1
  37. package/esm/lock/check.js +2 -1
  38. package/esm/lock/edge_drift.d.ts +2 -0
  39. package/esm/lock/edge_drift.d.ts.map +1 -1
  40. package/esm/lock/edge_drift.js +4 -0
  41. package/esm/lock/mod.d.ts +1 -1
  42. package/esm/lock/mod.d.ts.map +1 -1
  43. package/esm/lock/mod.js +1 -1
  44. package/esm/lock/upstream_deps.js +1 -1
  45. package/esm/mod.d.ts +11 -6
  46. package/esm/mod.d.ts.map +1 -1
  47. package/esm/mod.js +9 -6
  48. package/esm/model/mod.d.ts +22 -1
  49. package/esm/model/mod.d.ts.map +1 -1
  50. package/esm/model/mod.js +10 -0
  51. package/esm/parser/code_regions.d.ts +29 -0
  52. package/esm/parser/code_regions.d.ts.map +1 -0
  53. package/esm/parser/code_regions.js +38 -0
  54. package/esm/parser/markdown.d.ts.map +1 -1
  55. package/esm/parser/markdown.js +103 -40
  56. package/esm/parser/mod.d.ts.map +1 -1
  57. package/esm/parser/mod.js +7 -1
  58. package/esm/parser/translate.d.ts.map +1 -1
  59. package/esm/parser/translate.js +5 -0
  60. package/esm/refs/mod.d.ts +6 -2
  61. package/esm/refs/mod.d.ts.map +1 -1
  62. package/esm/refs/mod.js +15 -21
  63. package/esm/reporter/mod.d.ts.map +1 -1
  64. package/esm/reporter/mod.js +2 -2
  65. package/esm/sync/mapping.d.ts +4 -3
  66. package/esm/sync/mapping.d.ts.map +1 -1
  67. package/esm/sync/mapping.js +52 -9
  68. package/esm/util/display_id.d.ts +20 -0
  69. package/esm/util/display_id.d.ts.map +1 -0
  70. package/esm/util/display_id.js +19 -0
  71. package/esm/util/fence.d.ts +20 -29
  72. package/esm/util/fence.d.ts.map +1 -1
  73. package/esm/util/fence.js +42 -50
  74. package/esm/util/modals.d.ts +6 -0
  75. package/esm/util/modals.d.ts.map +1 -1
  76. package/esm/util/modals.js +37 -0
  77. package/esm/validator/body_blocks.d.ts +2 -1
  78. package/esm/validator/body_blocks.d.ts.map +1 -1
  79. package/esm/validator/body_blocks.js +80 -2
  80. package/esm/validator/corpus.d.ts +6 -0
  81. package/esm/validator/corpus.d.ts.map +1 -1
  82. package/esm/validator/corpus.js +16 -4
  83. package/esm/validator/mod.d.ts +1 -1
  84. package/esm/validator/mod.d.ts.map +1 -1
  85. package/esm/validator/mod.js +1 -1
  86. package/esm/validator/pipeline.d.ts +6 -4
  87. package/esm/validator/pipeline.d.ts.map +1 -1
  88. package/esm/validator/pipeline.js +24 -19
  89. package/package.json +1 -1
  90. package/script/ast/normalize.d.ts +4 -5
  91. package/script/ast/normalize.d.ts.map +1 -1
  92. package/script/ast/normalize.js +5 -36
  93. package/script/collect/mod.d.ts +29 -9
  94. package/script/collect/mod.d.ts.map +1 -1
  95. package/script/collect/mod.js +38 -10
  96. package/script/compiler/mod.d.ts.map +1 -1
  97. package/script/compiler/mod.js +1 -5
  98. package/script/config/markspec.d.ts +5 -3
  99. package/script/config/markspec.d.ts.map +1 -1
  100. package/script/config/mod.d.ts.map +1 -1
  101. package/script/config/mod.js +47 -5
  102. package/script/discovery/mod.d.ts +24 -8
  103. package/script/discovery/mod.d.ts.map +1 -1
  104. package/script/discovery/mod.js +56 -20
  105. package/script/discovery/projects.d.ts +111 -0
  106. package/script/discovery/projects.d.ts.map +1 -0
  107. package/script/discovery/projects.js +250 -0
  108. package/script/formatter/entry_body.d.ts +84 -0
  109. package/script/formatter/entry_body.d.ts.map +1 -0
  110. package/script/formatter/entry_body.js +296 -0
  111. package/script/formatter/md_equiv.d.ts +6 -5
  112. package/script/formatter/md_equiv.d.ts.map +1 -1
  113. package/script/formatter/md_equiv.js +6 -5
  114. package/script/formatter/mod.d.ts +16 -9
  115. package/script/formatter/mod.d.ts.map +1 -1
  116. package/script/formatter/mod.js +324 -50
  117. package/script/formatter/tab_markers.d.ts +15 -0
  118. package/script/formatter/tab_markers.d.ts.map +1 -0
  119. package/script/formatter/tab_markers.js +141 -0
  120. package/script/gates/mod.d.ts.map +1 -1
  121. package/script/gates/mod.js +15 -14
  122. package/script/lint/runner.d.ts.map +1 -1
  123. package/script/lint/runner.js +3 -3
  124. package/script/lock/check.d.ts.map +1 -1
  125. package/script/lock/check.js +2 -1
  126. package/script/lock/edge_drift.d.ts +2 -0
  127. package/script/lock/edge_drift.d.ts.map +1 -1
  128. package/script/lock/edge_drift.js +5 -0
  129. package/script/lock/mod.d.ts +1 -1
  130. package/script/lock/mod.d.ts.map +1 -1
  131. package/script/lock/mod.js +2 -1
  132. package/script/lock/upstream_deps.js +1 -1
  133. package/script/mod.d.ts +11 -6
  134. package/script/mod.d.ts.map +1 -1
  135. package/script/mod.js +23 -5
  136. package/script/model/mod.d.ts +22 -1
  137. package/script/model/mod.d.ts.map +1 -1
  138. package/script/model/mod.js +11 -0
  139. package/script/parser/code_regions.d.ts +29 -0
  140. package/script/parser/code_regions.d.ts.map +1 -0
  141. package/script/parser/code_regions.js +41 -0
  142. package/script/parser/markdown.d.ts.map +1 -1
  143. package/script/parser/markdown.js +102 -39
  144. package/script/parser/mod.d.ts.map +1 -1
  145. package/script/parser/mod.js +7 -1
  146. package/script/parser/translate.d.ts.map +1 -1
  147. package/script/parser/translate.js +5 -0
  148. package/script/refs/mod.d.ts +6 -2
  149. package/script/refs/mod.d.ts.map +1 -1
  150. package/script/refs/mod.js +14 -20
  151. package/script/reporter/mod.d.ts.map +1 -1
  152. package/script/reporter/mod.js +1 -1
  153. package/script/sync/mapping.d.ts +4 -3
  154. package/script/sync/mapping.d.ts.map +1 -1
  155. package/script/sync/mapping.js +52 -9
  156. package/script/util/display_id.d.ts +20 -0
  157. package/script/util/display_id.d.ts.map +1 -0
  158. package/script/util/display_id.js +22 -0
  159. package/script/util/fence.d.ts +20 -29
  160. package/script/util/fence.d.ts.map +1 -1
  161. package/script/util/fence.js +47 -54
  162. package/script/util/modals.d.ts +6 -0
  163. package/script/util/modals.d.ts.map +1 -1
  164. package/script/util/modals.js +38 -0
  165. package/script/validator/body_blocks.d.ts +2 -1
  166. package/script/validator/body_blocks.d.ts.map +1 -1
  167. package/script/validator/body_blocks.js +80 -2
  168. package/script/validator/corpus.d.ts +6 -0
  169. package/script/validator/corpus.d.ts.map +1 -1
  170. package/script/validator/corpus.js +16 -3
  171. package/script/validator/mod.d.ts +1 -1
  172. package/script/validator/mod.d.ts.map +1 -1
  173. package/script/validator/mod.js +2 -1
  174. package/script/validator/pipeline.d.ts +6 -4
  175. package/script/validator/pipeline.d.ts.map +1 -1
  176. package/script/validator/pipeline.js +24 -19
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module core/parser/code_regions
3
+ *
4
+ * Source regions of CommonMark code nodes, using the shared remark parser.
5
+ * This module depends only on remark and mdast types so prose passes can use
6
+ * it without importing the entry parser or creating an AST dependency cycle.
7
+ */
8
+ import type { Root } from "@types/mdast";
9
+ /** Code boundaries in the original document, with zero-based indices. */
10
+ export interface CodeRegions {
11
+ readonly fencedLines: ReadonlySet<number>;
12
+ /** Half-open source offsets, including the inline-code delimiters. */
13
+ readonly inlineCode: readonly {
14
+ start: number;
15
+ end: number;
16
+ }[];
17
+ }
18
+ /**
19
+ * Collect fenced-code lines and inline-code source ranges. Reuse the supplied
20
+ * tree for this exact source when available; otherwise parse the document once.
21
+ * A fenced node starts at its marker, after any list or quote prefix. An
22
+ * indented code node starts at its indentation, so it cannot match here.
23
+ * Indented code is deliberately excluded: MarkSpec trailers use that syntax.
24
+ * Node ends at column one are exclusive of that line (for example when an
25
+ * unclosed fence ends at a sibling list item). All other end lines include
26
+ * content or a closing delimiter and belong to the fenced region.
27
+ */
28
+ export declare function parseCodeRegions(markdown: string, tree?: Root): CodeRegions;
29
+ //# sourceMappingURL=code_regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code_regions.d.ts","sourceRoot":"","sources":["../../src/parser/code_regions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,IAAI,EAAe,MAAM,cAAc,CAAC;AAGtD,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,sEAAsE;IACtE,QAAQ,CAAC,UAAU,EAAE,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAChE;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,IAAgC,GACrC,WAAW,CA4Bb"}
@@ -0,0 +1,38 @@
1
+ import { processor } from "./remark.js";
2
+ /**
3
+ * Collect fenced-code lines and inline-code source ranges. Reuse the supplied
4
+ * tree for this exact source when available; otherwise parse the document once.
5
+ * A fenced node starts at its marker, after any list or quote prefix. An
6
+ * indented code node starts at its indentation, so it cannot match here.
7
+ * Indented code is deliberately excluded: MarkSpec trailers use that syntax.
8
+ * Node ends at column one are exclusive of that line (for example when an
9
+ * unclosed fence ends at a sibling list item). All other end lines include
10
+ * content or a closing delimiter and belong to the fenced region.
11
+ */
12
+ export function parseCodeRegions(markdown, tree = processor.parse(markdown)) {
13
+ const fencedLines = new Set();
14
+ const inlineCode = [];
15
+ const visit = (node) => {
16
+ const position = node.position;
17
+ if (position) {
18
+ const { start, end } = position;
19
+ if (node.type === "code" && start.offset !== undefined &&
20
+ /^(?:`{3,}|~{3,})/.test(markdown.slice(start.offset, start.offset + 3))) {
21
+ const lastLine = end.line - (end.column === 1 ? 1 : 0);
22
+ for (let line = start.line; line <= lastLine; line++) {
23
+ fencedLines.add(line - 1);
24
+ }
25
+ }
26
+ else if (node.type === "inlineCode" && start.offset !== undefined &&
27
+ end.offset !== undefined) {
28
+ inlineCode.push({ start: start.offset, end: end.offset });
29
+ }
30
+ }
31
+ if ("children" in node) {
32
+ for (const child of node.children)
33
+ visit(child);
34
+ }
35
+ };
36
+ visit(tree);
37
+ return { fencedLines, inlineCode };
38
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/parser/markdown.ts"],"names":[],"mappings":"AAAA;;;;;GAKG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AK,EAAE,CAAC;IAC1B,4DAA4D;IAC5D,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,mBAAmB,CAgDrB"}
@@ -4,23 +4,28 @@
4
4
  * CommonMark + MarkSpec extension parser. Walks the mdast AST to detect
5
5
  * `- [DISPLAY_ID] Title` entry blocks and extract structured attributes.
6
6
  */
7
- import { CORE_RELATIONS, IDENTITY_KEY, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, shapeFromIdValue, UNIVERSAL_ATTRIBUTE_KEYS, } from "../model/mod.js";
7
+ import { attributeSpec, CORE_RELATIONS, IDENTITY_KEY, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, shapeFromIdValue, UNIVERSAL_ATTRIBUTE_KEYS, } from "../model/mod.js";
8
8
  import { ATTR_LINE_RE, collateAttributes, parseAttributes, splitBodyAndAttributes, } from "./attributes.js";
9
9
  import { extractBodyTokens } from "./body_tokens.js";
10
10
  import { isMarkspecDirectiveComment } from "./directives.js";
11
11
  import { processor } from "./remark.js";
12
12
  import { buildBodyAstWithTree } from "../ast/build.js";
13
+ import { parseCodeRegions } from "./code_regions.js";
14
+ import { normalizeLineEndings } from "../util/line_endings.js";
13
15
  import { translateEntryLocations } from "./translate.js";
14
16
  import { assembleTyplTypes } from "../typl/mod.js";
15
17
  /**
16
18
  * Canonical set of trailer attribute keys the core recognizes: the union of
17
- * every universal attribute, every core trace relation, and the extra inverse
18
- * lock key (`Verified-by`). MSL-P020 (misplaced trailer) fires only when a
19
- * body line's key is in this set; any other capitalized `Word:` lead-in
20
- * (`Note:`, `Example:`, `Assumption:`) is prose, not a misplaced trailer (#654).
19
+ * every authored universal attribute, every core trace relation, and the
20
+ * extra inverse lock key (`Verified-by`). Universal keys with
21
+ * `origin: "generated"` (`Contains`, `Caused`, ...) are left out: the compiler
22
+ * computes them and authors never write them (#706). MSL-P020 (misplaced
23
+ * trailer) fires only when a body line's key is in this set; any other
24
+ * capitalized `Word:` lead-in (`Note:`, `Example:`, `Assumption:`) is prose,
25
+ * not a misplaced trailer (#654).
21
26
  */
22
27
  const RECOGNIZED_TRAILER_KEYS = new Set([
23
- ...UNIVERSAL_ATTRIBUTE_KEYS,
28
+ ...UNIVERSAL_ATTRIBUTE_KEYS.filter((key) => attributeSpec(key)?.origin !== "generated"),
24
29
  ...CORE_RELATIONS.map((r) => r.attr),
25
30
  ...LOCK_EXTRA_INVERSE_KEYS,
26
31
  ]);
@@ -107,10 +112,26 @@ export function parseMarkdown(markdown, options) {
107
112
  entries.push(entry);
108
113
  }
109
114
  }
110
- const finalEntries = options?.lineMap
111
- ? translateEntryLocations(entries, options.lineMap)
112
- : entries;
113
- return { entries: finalEntries, diagnostics };
115
+ const lineMap = options?.lineMap;
116
+ if (!lineMap)
117
+ return { entries, diagnostics };
118
+ return {
119
+ entries: translateEntryLocations(entries, lineMap),
120
+ diagnostics: translateDiagnosticLocations(diagnostics, lineMap),
121
+ };
122
+ }
123
+ /**
124
+ * Translate parse-diagnostic locations from wrapped-buffer coordinates to
125
+ * source-file coordinates (doc-comment parsing). A location the map cannot
126
+ * translate is kept as-is.
127
+ */
128
+ function translateDiagnosticLocations(diagnostics, lineMap) {
129
+ return diagnostics.map((d) => {
130
+ if (!d.location)
131
+ return d;
132
+ const mapped = lineMap.translate(d.location.line, d.location.column);
133
+ return mapped ? { ...d, location: { ...d.location, ...mapped } } : d;
134
+ });
114
135
  }
115
136
  /**
116
137
  * Resolve whether this is a references document.
@@ -247,16 +268,12 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
247
268
  // caption lead-ins (`Figure:`, `Table:`) are left as legitimate body content.
248
269
  if (body.length > 0) {
249
270
  const bodyLines = body.split("\n");
250
- let inFencedBlock = false;
271
+ const fencedLines = parseCodeRegions(normalizeLineEndings(body), mdastTree).fencedLines;
251
272
  for (let i = 0; i < bodyLines.length; i++) {
252
- const trimmed = bodyLines[i].trim();
253
- // Track fenced code blocks (``` or ~~~) to skip their contents
254
- if (/^(`{3,}|~{3,})/.test(trimmed)) {
255
- inFencedBlock = !inFencedBlock;
256
- continue;
257
- }
258
- if (inFencedBlock)
273
+ // Reuse the LF-normalized body tree: examples cannot be misplaced trailers.
274
+ if (fencedLines.has(i))
259
275
  continue;
276
+ const trimmed = bodyLines[i].trim();
260
277
  if (!ATTR_LINE_RE.test(trimmed))
261
278
  continue;
262
279
  // Only a RECOGNIZED trailer key signals a genuinely misplaced trailer.
@@ -284,8 +301,23 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
284
301
  // but failed ATTR_LINE_RE (thus stayed in the body).
285
302
  const TRAILER_KEY_RE = /^[A-Za-z][A-Za-z0-9-]*$/;
286
303
  const COLON_SPLIT_RE = /^([^:]+):\s*(.*)$/;
304
+ // P021/P022 point at the offending trailer line itself, not the title, so
305
+ // editors underline the bad line and quick fixes can target it directly.
306
+ // `bodyContent` starts at the second list-item child's line and has only
307
+ // trailing blank lines trimmed, so content index `i` sits on file line
308
+ // `contentStartLine + i`. The column is the line's first non-blank char.
309
+ const contentStartLine = item.children[1]?.position?.start.line ??
310
+ entryLine + 1;
311
+ const trailerLineLocation = (contentIndex) => {
312
+ const line = contentStartLine + contentIndex;
313
+ const firstNonBlank = (markdownLines[line - 1] ?? "").search(/\S/);
314
+ return { file, line, column: firstNonBlank >= 0 ? firstNonBlank + 1 : 1 };
315
+ };
316
+ // `attrLines` is the contiguous, blank-free tail of `bodyContent`.
317
+ const attrContentStart = bodyContent.split("\n").length - attrLines.length;
287
318
  // Check lines that DID end up in attrLines but might have key issues
288
- for (const rawLine of attrLines) {
319
+ for (const [attrIndex, rawLine] of attrLines.entries()) {
320
+ const trailerLocation = trailerLineLocation(attrContentStart + attrIndex);
289
321
  const trimmed = rawLine.trim();
290
322
  if (!trimmed)
291
323
  continue;
@@ -299,7 +331,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
299
331
  severity: "error",
300
332
  message: `${displayId}: trailer key '${key}' contains characters ` +
301
333
  `outside [A-Za-z][A-Za-z0-9-]* (spec section 4.1)`,
302
- location: { file, line: entryLine, column: 1 },
334
+ location: trailerLocation,
303
335
  });
304
336
  }
305
337
  else {
@@ -308,7 +340,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
308
340
  severity: "error",
309
341
  message: `${displayId}: trailer line does not match 'Key: Value' ` +
310
342
  `syntax (spec section 4.1): "${trimmed}"`,
311
- location: { file, line: entryLine, column: 1 },
343
+ location: trailerLocation,
312
344
  });
313
345
  }
314
346
  }
@@ -318,7 +350,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
318
350
  severity: "error",
319
351
  message: `${displayId}: trailer line does not match 'Key: Value' ` +
320
352
  `syntax (spec section 4.1): "${trimmed}"`,
321
- location: { file, line: entryLine, column: 1 },
353
+ location: trailerLocation,
322
354
  });
323
355
  }
324
356
  }
@@ -336,6 +368,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
336
368
  const trimmed = bodyLines[i].trim();
337
369
  if (!trimmed)
338
370
  continue; // skip trailing blanks
371
+ const trailerLocation = trailerLineLocation(i);
339
372
  // A `<!-- markspec:* -->` directive comment is legitimate body
340
373
  // content (spec §2.4.1), not a trailer line — skip it so its
341
374
  // `<!--markspec` colon-prefix is never mistaken for a malformed
@@ -351,18 +384,33 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
351
384
  // A colon inside prose ("modes are: fast") or a Markdown table row
352
385
  // ("| Fast | latency: 200ms |") is body content, not a malformed
353
386
  // trailer — stop scanning at it (#648). A pipe always means a table
354
- // cell. Internal whitespace usually means prose, EXCEPT a space-for-
355
- // hyphen typo of a real trailer key (`Verified by` for `Verified-by`):
356
- // that is a malformed trailer the author intended and must still fire
357
- // MSL-P022 rather than silently dropping the trace link (#697). Detect
358
- // it by normalising spaces to hyphens and checking the recognised
359
- // trailer-key vocabulary.
387
+ // cell; the checks below handle Markdown punctuation, internal
388
+ // whitespace, and the other punctuation.
360
389
  if (key.includes("|"))
361
390
  break;
362
- if (/\s/.test(key) &&
363
- !RECOGNIZED_TRAILER_KEYS.has(key.replace(/\s+/g, "-"))) {
391
+ // Markdown punctuation before the colon (`**Rationale:**`,
392
+ // `[link](http://…)`, `` `mode:fast` ``, `<mailto:…>`) means inline
393
+ // Markdown in prose. A trailer key never holds it, so stop here too.
394
+ if (/[*[\]()<>`]/.test(key))
395
+ break;
396
+ // A typo of a recognized trailer key (`Verified by`, `Verified.by`,
397
+ // `Verified,by`, `Satisfies"`) must still fire MSL-P022 below, so the
398
+ // trace link is not silently dropped (#697). Detect it by turning
399
+ // whitespace and the punctuation `.`, `/`, `,`, `'`, `"` into
400
+ // hyphens, trimming hyphens at both ends, and checking the recognized
401
+ // key vocabulary.
402
+ const typoOfKnownKey = RECOGNIZED_TRAILER_KEYS.has(key.replace(/[\s./,'"]+/g, "-").replace(/^-+|-+$/g, ""));
403
+ // A time (`10:30`), an abbreviation (`e.g.:`), a version (`v2.0:`)
404
+ // or a word pair (`and/or:`) is prose. The 80-column wrap of the
405
+ // formatter can put one at the start of the last body line. A
406
+ // trailer key starts with a letter and never holds `.`, `/`, `,`,
407
+ // `'` or `"`, so stop here unless the key is a typo of a known key.
408
+ // Lowercase and underscored keys still reach the checks below.
409
+ if ((!/^[A-Za-z]/.test(key) || /[./,'"]/.test(key)) && !typoOfKnownKey) {
364
410
  break;
365
411
  }
412
+ if (/\s/.test(key) && !typoOfKnownKey)
413
+ break;
366
414
  if (ATTR_LINE_RE.test(trimmed)) {
367
415
  // Valid attr line in body → already caught by P020
368
416
  continue;
@@ -373,7 +421,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
373
421
  severity: "error",
374
422
  message: `${displayId}: trailer key '${key}' contains characters ` +
375
423
  `outside [A-Za-z][A-Za-z0-9-]* (spec section 4.1)`,
376
- location: { file, line: entryLine, column: 1 },
424
+ location: trailerLocation,
377
425
  });
378
426
  }
379
427
  else if (colonMatch[2].trim().length === 0) {
@@ -382,7 +430,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
382
430
  severity: "error",
383
431
  message: `${displayId}: trailer line does not match 'Key: Value' ` +
384
432
  `syntax (spec section 4.1): "${trimmed}"`,
385
- location: { file, line: entryLine, column: 1 },
433
+ location: trailerLocation,
386
434
  });
387
435
  }
388
436
  break; // one diagnostic per trailing suspect line is sufficient
@@ -460,12 +508,14 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
460
508
  // loose lists have a blank line between title and body, so the body is at
461
509
  // (entry_line + 2), not (entry_line + 1).
462
510
  //
463
- // columnOffset: body text has been stripped of the list-item indent (e.g.,
464
- // " " for column-1 items), so each token column must be bumped by that
465
- // indent width. The + 2 accounts for the " " continuation indent
466
- // prepended by wrapAsListItem to every non-title line.
467
- const bodyIndent = (item.position?.start.column ?? 1) - 1 + 2;
511
+ // columnOffset: body text has been stripped of the list-item content
512
+ // indent (itemContentIndent: 2 for `- [ID]`, 4 for `- [ID]`), so each
513
+ // token column is bumped by that width. For a source
514
+ // doc comment, wrapAsListItem writes `- ` and a 2-space indent on every
515
+ // non-title line, so the width is 2 there.
516
+ const bodyIndent = itemContentIndent(item);
468
517
  const bodyStartLine = item.children[1]?.position?.start.line ?? (line + 1);
518
+ const endLine = item.position?.end.line;
469
519
  const bodyTokens = extractBodyTokens(body, bodyAst, {
470
520
  file,
471
521
  line: bodyStartLine,
@@ -489,12 +539,27 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
489
539
  shape,
490
540
  location: entryLocation,
491
541
  bodyStartLine,
542
+ ...(endLine !== undefined ? { endLine } : {}),
492
543
  source: { kind: "markdown" },
493
544
  properties: { file: { path: file, line, column } },
494
545
  bodyTokens,
495
546
  ...(types ? { types } : {}),
496
547
  };
497
548
  }
549
+ /**
550
+ * Width of the continuation indent of a list item: the 0-based column where
551
+ * its title paragraph starts. That is the marker column plus the marker
552
+ * width plus the spaces after the marker, so `- [ID]` gives 2 and
553
+ * `- [ID]` gives 4 (ordered lists never hold entries; see
554
+ * `parseMarkdown`). Falls back to the marker column plus 2 when the title
555
+ * has no position.
556
+ */
557
+ function itemContentIndent(item) {
558
+ const title = item.children[0]?.position?.start.column;
559
+ if (title !== undefined)
560
+ return title - 1;
561
+ return (item.position?.start.column ?? 1) - 1 + 2;
562
+ }
498
563
  /**
499
564
  * Extract body content from a list item's children (excluding the first paragraph
500
565
  * which contains the display ID and title).
@@ -511,9 +576,7 @@ function extractBodyContent(item, lines) {
511
576
  const endLine = children[children.length - 1].position?.end.line;
512
577
  if (!startLine || !endLine)
513
578
  return "";
514
- // Compute indent width from the list item's column position.
515
- // column is 1-based, plus 2 for the `- ` marker.
516
- const indent = (item.position?.start.column ?? 1) - 1 + 2;
579
+ const indent = itemContentIndent(item);
517
580
  const indentStr = " ".repeat(indent);
518
581
  // Extract the raw lines and strip the list item continuation indent
519
582
  const rawLines = lines.slice(startLine - 1, endLine);
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/parser/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAU5E,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACV,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE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E,MAAM,oBAAoB,CAAC;AAE5E,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,YAAY,GACrB,KAAK,EAAE,CAOT;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,sBAAsB;IACtB,QAAQ,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAeD;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACjC,OAAO,CAAC,eAAe,CAAC,CAqD1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,EAAE,CAEX"}
package/esm/parser/mod.js CHANGED
@@ -81,7 +81,13 @@ export async function parseFile(content, options) {
81
81
  return { entries: result.entries, diagnostics: [] };
82
82
  }
83
83
  const fm = extractFrontMatter(normalised, { file: options.file });
84
- const body = fm.hadFrontMatter ? fm.markdown : normalised;
84
+ // Replace the stripped front matter with blank lines so every location
85
+ // the Markdown parser reports stays file-relative (CommonMark ignores
86
+ // leading blank lines).
87
+ const body = fm.hadFrontMatter
88
+ ? "\n".repeat(normalised.slice(0, normalised.length - fm.markdown.length)
89
+ .split("\n").length - 1) + fm.markdown
90
+ : normalised;
85
91
  const isReferencesDoc = isReferencesDocument(options.file);
86
92
  const { entries, diagnostics: parseDiagnostics } = parseMarkdown(body, {
87
93
  file: options.file,
@@ -1 +1 @@
1
- {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/parser/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,OAAO,GACf,KAAK,EAAE,CAoDT"}
1
+ {"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/parser/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,OAAO,GACf,KAAK,EAAE,CAyDT"}
@@ -37,6 +37,11 @@ export function translateEntryLocations(entries, lineMap) {
37
37
  return {
38
38
  ...entry,
39
39
  location: translatedEntryLoc,
40
+ ...(entry.endLine !== undefined
41
+ ? {
42
+ endLine: lineMap.translate(entry.endLine, 1)?.line ?? entry.endLine,
43
+ }
44
+ : {}),
40
45
  bodyAst: entry.bodyAst
41
46
  ? entry.bodyAst.map((block) => translateBlock(block, lineMap, fallbackPoint, warn))
42
47
  : entry.bodyAst,
package/esm/refs/mod.d.ts CHANGED
@@ -34,9 +34,13 @@ export declare function buildRefIndex(entries: readonly Entry[]): RefIndex;
34
34
  * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
35
35
  * `entries` MUST be the parse of `content` (used to map each trailer line to its
36
36
  * source entry's stable ULID). Returns the rewritten text and whether anything
37
- * changed. Lossless: only resolvable value tokens are replaced.
37
+ * changed. Lossless: only resolvable value tokens are replaced. Optional
38
+ * `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
38
39
  */
39
- export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[]): {
40
+ export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[], preservedRanges?: readonly {
41
+ readonly start: number;
42
+ readonly end: number;
43
+ }[]): {
40
44
  output: string;
41
45
  changed: boolean;
42
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,GAC1B;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAgHtC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,eAAe,GAAE,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACtE,GACH;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAwGtC"}
package/esm/refs/mod.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * it (WASM-migration purity guard, AGENTS.md).
13
13
  */
14
14
  import { CORE_RELATIONS, DISPLAY_ID_RE, LOCK_EXTRA_INVERSE_KEYS, ULID_RE, } from "../model/mod.js";
15
- import { FENCE_RE } from "../util/fence.js";
15
+ import { fencedCodeLines } from "../util/fence.js";
16
16
  /**
17
17
  * Trace-attribute keys whose values are canonicalised/healed: the core
18
18
  * relations plus `Verified-by`. Derived from {@linkcode CORE_RELATIONS} so new
@@ -55,9 +55,10 @@ const VALUE_TOKEN_RE = /[^\s,]+/g;
55
55
  * Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
56
56
  * `entries` MUST be the parse of `content` (used to map each trailer line to its
57
57
  * source entry's stable ULID). Returns the rewritten text and whether anything
58
- * changed. Lossless: only resolvable value tokens are replaced.
58
+ * changed. Lossless: only resolvable value tokens are replaced. Optional
59
+ * `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
59
60
  */
60
- export function canonicalizeRefs(content, entries, index, ledger) {
61
+ export function canonicalizeRefs(content, entries, index, ledger, preservedRanges = []) {
61
62
  const ledgerByKey = new Map();
62
63
  for (const e of ledger) {
63
64
  if (e.targetUlid === undefined)
@@ -85,25 +86,21 @@ export function canonicalizeRefs(content, entries, index, ledger) {
85
86
  };
86
87
  const lines = content.split("\n");
87
88
  let changed = false;
88
- // Track fenced-code regions so illustrative trailers inside ``` / ~~~
89
- // blocks (e.g. `Realizes: 01HGW...` in a ```markdown example) are never
90
- // "healed" against the real ref index — the same verbatim-region rule
91
- // every other fmt pass honors (§5.1; cf. `collapseBlankLines`). Without
92
- // this, `markspec fmt` rewrites example IDs in spec/ADR docs on every run
93
- // (#668). The parser/validator already treat fenced content as inert.
94
- let inFence = false;
89
+ // Share CommonMark fence boundaries with other prose passes. Compute them
90
+ // once so both the main loop and continuation loop remain linear (#705).
91
+ const fencedLines = new Set(fencedCodeLines(content));
92
+ for (const range of preservedRanges) {
93
+ for (let i = range.start; i < range.end; i++)
94
+ fencedLines.add(i);
95
+ }
95
96
  for (let i = 0; i < lines.length; i++) {
97
+ if (fencedLines.has(i))
98
+ continue;
96
99
  // Strip a trailing CR before matching so CRLF files are handled (the
97
100
  // trailer regex ends in `$`, which `\r` would block) and re-append it on
98
101
  // rewrite so line endings stay byte-for-byte lossless.
99
102
  const cr = lines[i].endsWith("\r");
100
103
  const bare = cr ? lines[i].slice(0, -1) : lines[i];
101
- if (FENCE_RE.test(bare)) {
102
- inFence = !inFence;
103
- continue;
104
- }
105
- if (inFence)
106
- continue;
107
104
  const m = TRACE_TRAILER_RE.exec(bare);
108
105
  if (!m)
109
106
  continue;
@@ -130,11 +127,8 @@ export function canonicalizeRefs(content, entries, index, ledger) {
130
127
  j++;
131
128
  const crj = lines[j].endsWith("\r");
132
129
  const barej = crj ? lines[j].slice(0, -1) : lines[j];
133
- // A fence marker is never continuation text. An indented one (e.g.
134
- // ` ```md`) would otherwise match CONTINUATION_LINE_RE and be
135
- // swallowed here without toggling `inFence`, desyncing fence tracking
136
- // for the rest of the file. Back out and let the outer loop toggle it.
137
- if (FENCE_RE.test(barej)) {
130
+ // Fence delimiters and fenced content cannot continue a trace value.
131
+ if (fencedLines.has(j)) {
138
132
  j--;
139
133
  break;
140
134
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/reporter/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAIxD,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;AAErD,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;OASG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAY5E"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/reporter/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQxD,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;AAErD,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;;;OASG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CACtD;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAY5E"}
@@ -4,7 +4,7 @@
4
4
  * Output reporters. Transforms compiled traceability graph into
5
5
  * traceability matrices and coverage reports in md, json, or csv format.
6
6
  */
7
- import { formatEntryOrigin, isUpstreamEntry } from "../model/mod.js";
7
+ import { formatEntryOrigin, isCorpusEntry, isUpstreamEntry, } from "../model/mod.js";
8
8
  /**
9
9
  * Generate a report from compiled traceability graph.
10
10
  *
@@ -50,7 +50,7 @@ function filterEntries(result, scope, label) {
50
50
  * Markdown, and JSON rows all agree on the same value.
51
51
  */
52
52
  function originCell(entry) {
53
- return entry.origin ? formatEntryOrigin(entry.origin) : "project";
53
+ return isCorpusEntry(entry) ? formatEntryOrigin(entry.origin) : "project";
54
54
  }
55
55
  function buildTraceRows(result, entries) {
56
56
  return entries.map((entry) => {
@@ -7,7 +7,7 @@
7
7
  * cache TTL.
8
8
  *
9
9
  * Diagnostic family is `MSL-S###`:
10
- * - MSL-S001 — malformed YAML / unsupported schema
10
+ * - MSL-S001 — malformed YAML / invalid structure / unsupported schema
11
11
  * - MSL-S002 — locked + outbound contradiction
12
12
  * - MSL-S003 — unknown conflict policy (newest-wins removed pre-1.0)
13
13
  * - MSL-S004 — system ≠ identity.external-id-scheme
@@ -52,8 +52,9 @@ export interface ParseMappingResult {
52
52
  }
53
53
  /**
54
54
  * Parse and validate one mapping.yaml. Returns the model when valid, or
55
- * an MSL-S### diagnostic when not. Single-shot — stops at the first
56
- * integrity failure to keep the repair signal clear.
55
+ * an MSL-S### diagnostic when not. Never throws on invalid YAML or invalid
56
+ * field shapes. Single-shot — stops at the first integrity failure to keep
57
+ * the repair signal clear.
57
58
  */
58
59
  export declare function parseMapping(yaml: string, sourcePath: string): ParseMappingResult;
59
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../src/sync/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,2BAA2B;AAC3B,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,eAAe,CAAC;AAEjE,yEAAyE;AACzE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,aAAa,CAAC;AAErE,gEAAgE;AAChE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,sCAAsC;AACtC,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MA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