@driftsys/markspec 0.9.0 → 0.10.2

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 (131) hide show
  1. package/esm/collect/mod.d.ts +34 -0
  2. package/esm/collect/mod.d.ts.map +1 -0
  3. package/esm/collect/mod.js +37 -0
  4. package/esm/compiler/mod.d.ts +7 -0
  5. package/esm/compiler/mod.d.ts.map +1 -1
  6. package/esm/compiler/mod.js +17 -3
  7. package/esm/compiler/schema.d.ts +8 -1
  8. package/esm/compiler/schema.d.ts.map +1 -1
  9. package/esm/compiler/schema.js +8 -1
  10. package/esm/formatter/dprint.d.ts +62 -0
  11. package/esm/formatter/dprint.d.ts.map +1 -0
  12. package/esm/formatter/dprint.js +83 -0
  13. package/esm/formatter/md_equiv.d.ts +24 -0
  14. package/esm/formatter/md_equiv.d.ts.map +1 -0
  15. package/esm/formatter/md_equiv.js +81 -0
  16. package/esm/formatter/mod.d.ts +25 -0
  17. package/esm/formatter/mod.d.ts.map +1 -1
  18. package/esm/formatter/mod.js +135 -7
  19. package/esm/formatter/prose.d.ts +48 -0
  20. package/esm/formatter/prose.d.ts.map +1 -0
  21. package/esm/formatter/prose.js +85 -0
  22. package/esm/gates/mod.d.ts +82 -0
  23. package/esm/gates/mod.d.ts.map +1 -0
  24. package/esm/gates/mod.js +139 -0
  25. package/esm/lint/runner.d.ts +26 -3
  26. package/esm/lint/runner.d.ts.map +1 -1
  27. package/esm/lint/runner.js +39 -9
  28. package/esm/lock/edge_drift.d.ts +31 -0
  29. package/esm/lock/edge_drift.d.ts.map +1 -0
  30. package/esm/lock/edge_drift.js +29 -0
  31. package/esm/lock/mod.d.ts +2 -0
  32. package/esm/lock/mod.d.ts.map +1 -1
  33. package/esm/lock/mod.js +1 -0
  34. package/esm/mod.d.ts +16 -7
  35. package/esm/mod.d.ts.map +1 -1
  36. package/esm/mod.js +13 -4
  37. package/esm/model/mod.d.ts +27 -1
  38. package/esm/model/mod.d.ts.map +1 -1
  39. package/esm/model/mod.js +10 -0
  40. package/esm/model/profile.d.ts +42 -0
  41. package/esm/model/profile.d.ts.map +1 -1
  42. package/esm/parser/markdown.d.ts.map +1 -1
  43. package/esm/parser/markdown.js +38 -11
  44. package/esm/profile/chain.js +1 -0
  45. package/esm/profile/delivered.d.ts +48 -0
  46. package/esm/profile/delivered.d.ts.map +1 -0
  47. package/esm/profile/delivered.js +103 -0
  48. package/esm/profile/manifest.d.ts +1 -0
  49. package/esm/profile/manifest.d.ts.map +1 -1
  50. package/esm/profile/manifest.js +107 -0
  51. package/esm/profile/merge.d.ts.map +1 -1
  52. package/esm/profile/merge.js +22 -0
  53. package/esm/refs/mod.d.ts.map +1 -1
  54. package/esm/refs/mod.js +22 -0
  55. package/esm/reporter/mod.d.ts.map +1 -1
  56. package/esm/reporter/mod.js +16 -4
  57. package/esm/util/fence.d.ts +8 -0
  58. package/esm/util/fence.d.ts.map +1 -1
  59. package/esm/util/fence.js +22 -0
  60. package/esm/validator/corpus.d.ts +25 -0
  61. package/esm/validator/corpus.d.ts.map +1 -0
  62. package/esm/validator/corpus.js +140 -0
  63. package/esm/validator/mod.d.ts +2 -0
  64. package/esm/validator/mod.d.ts.map +1 -1
  65. package/esm/validator/mod.js +1 -0
  66. package/package.json +3 -1
  67. package/script/collect/mod.d.ts +34 -0
  68. package/script/collect/mod.d.ts.map +1 -0
  69. package/script/collect/mod.js +40 -0
  70. package/script/compiler/mod.d.ts +7 -0
  71. package/script/compiler/mod.d.ts.map +1 -1
  72. package/script/compiler/mod.js +16 -2
  73. package/script/compiler/schema.d.ts +8 -1
  74. package/script/compiler/schema.d.ts.map +1 -1
  75. package/script/compiler/schema.js +8 -1
  76. package/script/formatter/dprint.d.ts +62 -0
  77. package/script/formatter/dprint.d.ts.map +1 -0
  78. package/script/formatter/dprint.js +120 -0
  79. package/script/formatter/md_equiv.d.ts +24 -0
  80. package/script/formatter/md_equiv.d.ts.map +1 -0
  81. package/script/formatter/md_equiv.js +87 -0
  82. package/script/formatter/mod.d.ts +25 -0
  83. package/script/formatter/mod.d.ts.map +1 -1
  84. package/script/formatter/mod.js +135 -6
  85. package/script/formatter/prose.d.ts +48 -0
  86. package/script/formatter/prose.d.ts.map +1 -0
  87. package/script/formatter/prose.js +88 -0
  88. package/script/gates/mod.d.ts +82 -0
  89. package/script/gates/mod.d.ts.map +1 -0
  90. package/script/gates/mod.js +144 -0
  91. package/script/lint/runner.d.ts +26 -3
  92. package/script/lint/runner.d.ts.map +1 -1
  93. package/script/lint/runner.js +39 -9
  94. package/script/lock/edge_drift.d.ts +31 -0
  95. package/script/lock/edge_drift.d.ts.map +1 -0
  96. package/script/lock/edge_drift.js +32 -0
  97. package/script/lock/mod.d.ts +2 -0
  98. package/script/lock/mod.d.ts.map +1 -1
  99. package/script/lock/mod.js +3 -1
  100. package/script/mod.d.ts +16 -7
  101. package/script/mod.d.ts.map +1 -1
  102. package/script/mod.js +56 -29
  103. package/script/model/mod.d.ts +27 -1
  104. package/script/model/mod.d.ts.map +1 -1
  105. package/script/model/mod.js +11 -0
  106. package/script/model/profile.d.ts +42 -0
  107. package/script/model/profile.d.ts.map +1 -1
  108. package/script/parser/markdown.d.ts.map +1 -1
  109. package/script/parser/markdown.js +38 -11
  110. package/script/profile/chain.js +1 -0
  111. package/script/profile/delivered.d.ts +48 -0
  112. package/script/profile/delivered.d.ts.map +1 -0
  113. package/script/profile/delivered.js +109 -0
  114. package/script/profile/manifest.d.ts +1 -0
  115. package/script/profile/manifest.d.ts.map +1 -1
  116. package/script/profile/manifest.js +108 -1
  117. package/script/profile/merge.d.ts.map +1 -1
  118. package/script/profile/merge.js +22 -0
  119. package/script/refs/mod.d.ts.map +1 -1
  120. package/script/refs/mod.js +22 -0
  121. package/script/reporter/mod.d.ts.map +1 -1
  122. package/script/reporter/mod.js +16 -4
  123. package/script/util/fence.d.ts +8 -0
  124. package/script/util/fence.d.ts.map +1 -1
  125. package/script/util/fence.js +23 -0
  126. package/script/validator/corpus.d.ts +25 -0
  127. package/script/validator/corpus.d.ts.map +1 -0
  128. package/script/validator/corpus.js +144 -0
  129. package/script/validator/mod.d.ts +2 -0
  130. package/script/validator/mod.d.ts.map +1 -1
  131. package/script/validator/mod.js +4 -1
@@ -31,12 +31,31 @@ const RECOGNIZED_TRAILER_KEYS = new Set([
31
31
  * with an alphanumeric).
32
32
  */
33
33
  const SLUG_RE = /^[A-Za-z]([A-Za-z0-9._/-]*[A-Za-z0-9])?$/;
34
- /** Match `[...]` at the start of a list item paragraph. Captures: [1] = display ID, [2] = title. */
35
- const ENTRY_START_RE = /^\[([^\]]+)\]\s*(.*)$/;
34
+ /**
35
+ * Match `[...]` at the start of a list item paragraph. Captures:
36
+ * [1] = display ID, [2] = title.
37
+ *
38
+ * The title group is `[\s\S]*` (not `.*`) so a title that soft-wraps onto
39
+ * a second physical line is still captured — remark keeps a soft-wrapped
40
+ * paragraph as one text node with an embedded `\n`, which `.` would not
41
+ * cross, leaving the entry silently undetected (#686). {@linkcode collapseTitle}
42
+ * then folds the wrapped title back to a single logical line.
43
+ */
44
+ const ENTRY_START_RE = /^\[([^\]]+)\]\s*([\s\S]*)$/;
36
45
  /** Match `[]` at the start — empty brackets. */
37
46
  const EMPTY_BRACKET_RE = /^\[\]\s*(.*)$/;
38
47
  /** Match `[` at the start without a closing `]` on the same logical content — unterminated. */
39
48
  const UNTERMINATED_BRACKET_RE = /^\[[^\]]*$/;
49
+ /**
50
+ * Fold a title that may span multiple soft-wrapped physical lines (one
51
+ * Markdown paragraph) into a single logical line: every run of whitespace
52
+ * — including the embedded newlines remark preserves inside the paragraph
53
+ * text node — collapses to a single space, matching how a soft-wrapped
54
+ * line renders (#686).
55
+ */
56
+ function collapseTitle(raw) {
57
+ return raw.replace(/\s+/g, " ").trim();
58
+ }
40
59
  /**
41
60
  * Find the `Id:` attribute on an entry. Returns undefined when absent. If
42
61
  * more than one `Id:` is present, returns the first — the validator flags
@@ -133,7 +152,7 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
133
152
  const match = ENTRY_START_RE.exec(textValue);
134
153
  if (match) {
135
154
  displayId = match[1];
136
- title = match[2].trim();
155
+ title = collapseTitle(match[2]);
137
156
  }
138
157
  else if (EMPTY_BRACKET_RE.test(textValue)) {
139
158
  // MSL-P001: bracketed content is empty — `- [] Title`
@@ -176,11 +195,10 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
176
195
  // Title comes from subsequent text nodes in the paragraph
177
196
  if (displayId && paragraph.children.length > 1) {
178
197
  const rest = paragraph.children.slice(1);
179
- title = rest
198
+ title = collapseTitle(rest
180
199
  .filter((n) => n.type === "text")
181
200
  .map((n) => n.value)
182
- .join("")
183
- .trim();
201
+ .join(""));
184
202
  }
185
203
  }
186
204
  if (!displayId)
@@ -321,12 +339,21 @@ function extractEntry(item, markdownLines, file, definitions, isReferencesDoc, d
321
339
  if (!colonMatch)
322
340
  break; // stop at non-colon line
323
341
  const key = colonMatch[1].trim();
324
- // A genuine trailer key is a single token; it never contains internal
325
- // whitespace or a pipe. A colon inside prose ("modes are: fast") or a
326
- // Markdown table row ("| Fast | latency: 200ms |") is body content, not
327
- // a malformed trailer — stop scanning at it (#648).
328
- if (/[\s|]/.test(key))
342
+ // A colon inside prose ("modes are: fast") or a Markdown table row
343
+ // ("| Fast | latency: 200ms |") is body content, not a malformed
344
+ // trailer — stop scanning at it (#648). A pipe always means a table
345
+ // cell. Internal whitespace usually means prose, EXCEPT a space-for-
346
+ // hyphen typo of a real trailer key (`Verified by` for `Verified-by`):
347
+ // that is a malformed trailer the author intended and must still fire
348
+ // MSL-P022 rather than silently dropping the trace link (#697). Detect
349
+ // it by normalising spaces to hyphens and checking the recognised
350
+ // trailer-key vocabulary.
351
+ if (key.includes("|"))
329
352
  break;
353
+ if (/\s/.test(key) &&
354
+ !RECOGNIZED_TRAILER_KEYS.has(key.replace(/\s+/g, "-"))) {
355
+ break;
356
+ }
330
357
  if (ATTR_LINE_RE.test(trimmed)) {
331
358
  // Valid attr line in body → already caught by P020
332
359
  continue;
@@ -199,6 +199,7 @@ function buildPlaceholderEffective(tiers) {
199
199
  colors: new Map(),
200
200
  types: new Map(),
201
201
  documents: { types: new Map(), frontMatter: new Map() },
202
+ delivers: [],
202
203
  kinds: new Map(),
203
204
  prose: {
204
205
  lexicons: {
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module core/profile/delivered
3
+ *
4
+ * Loader for profile-delivered documents (ADR-030). Checks every delivered
5
+ * file's existence (PROFILE-DELIVERS-001/002), parses the `corpus: true`
6
+ * files, and stamps each parsed entry with its profile origin. Pure — all
7
+ * I/O via the injected {@linkcode ReadFile}.
8
+ */
9
+ import type { ReadFile } from "../config/mod.js";
10
+ import type { DeliveredDocument, Diagnostic, Entry } from "../model/mod.js";
11
+ /** Result of {@linkcode loadDeliveredCorpus}. */
12
+ export interface LoadDeliveredCorpusResult {
13
+ readonly entries: readonly Entry[];
14
+ readonly diagnostics: readonly Diagnostic[];
15
+ }
16
+ /**
17
+ * Canonicalises a path, resolving symlinks (e.g. `Deno.realPath`). Injected so
18
+ * core stays runtime-agnostic. Supplied by callers to the delivered-path
19
+ * containment guard (#699); omitting it disables the guard.
20
+ */
21
+ export type RealPath = (path: string) => Promise<string>;
22
+ /** Human-facing label of a delivered document's providing tier. */
23
+ export declare function corpusOriginLabel(doc: DeliveredDocument): string;
24
+ /** Index delivered documents by absolute path — used by CLI/LSP callers to
25
+ * recognise corpus locations when rendering diagnostics. */
26
+ export declare function buildCorpusIndex(delivers: readonly DeliveredDocument[]): ReadonlyMap<string, DeliveredDocument>;
27
+ /**
28
+ * Load the delivered corpus of an effective profile chain. Iterates
29
+ * `delivers` in order (parent-first + manifest order — the deterministic
30
+ * injection order), so the returned entry order is stable across runs.
31
+ */
32
+ export declare function loadDeliveredCorpus(delivers: readonly DeliveredDocument[], readFile: ReadFile, realPath?: RealPath): Promise<LoadDeliveredCorpusResult>;
33
+ /**
34
+ * True when `doc`'s real (symlink-resolved) path stays within its profile's
35
+ * `baseDir` — the delivered-path containment guard (#699). A malicious profile
36
+ * (pulled via `extends: git+…`, which preserves symlinks) can deliver a `.md`
37
+ * that is actually a symlink to an arbitrary local file (`~/.ssh/id_rsa`); the
38
+ * string-level path checks (PROFILE-DELIVERS-003/004) validate the declared
39
+ * path, not the symlink target, so a real-path containment check is the only
40
+ * thing that stops the read.
41
+ *
42
+ * Degrades to `true` (allow) when the doc carries no `baseDir` or when the
43
+ * paths cannot be canonicalised (e.g. the file is missing) — a missing file is
44
+ * left to the existing PROFILE-DELIVERS-001/002 checks. Shared by the MCP
45
+ * `readDeliveredDocument` read path, which faces the same vector.
46
+ */
47
+ export declare function deliveredPathIsContained(doc: DeliveredDocument, realPath: RealPath): Promise<boolean>;
48
+ //# sourceMappingURL=delivered.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivered.d.ts","sourceRoot":"","sources":["../../src/profile/delivered.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAGzB,iDAAiD;AACjD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAEzD,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,iBAAiB,GAAG,MAAM,CAEhE;AAED;4DAC4D;AAC5D,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,SAAS,iBAAiB,EAAE,GACrC,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAIxC;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,EACtC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,yBAAyB,CAAC,CA2CpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,iBAAiB,EACtB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,OAAO,CAAC,CAalB"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @module core/profile/delivered
3
+ *
4
+ * Loader for profile-delivered documents (ADR-030). Checks every delivered
5
+ * file's existence (PROFILE-DELIVERS-001/002), parses the `corpus: true`
6
+ * files, and stamps each parsed entry with its profile origin. Pure — all
7
+ * I/O via the injected {@linkcode ReadFile}.
8
+ */
9
+ import { SEPARATOR } from "@std/path";
10
+ import { parseFile } from "../parser/mod.js";
11
+ /** Human-facing label of a delivered document's providing tier. */
12
+ export function corpusOriginLabel(doc) {
13
+ return `${doc.profileId}@${doc.profileVersion}`;
14
+ }
15
+ /** Index delivered documents by absolute path — used by CLI/LSP callers to
16
+ * recognise corpus locations when rendering diagnostics. */
17
+ export function buildCorpusIndex(delivers) {
18
+ const out = new Map();
19
+ for (const d of delivers)
20
+ out.set(d.absPath, d);
21
+ return out;
22
+ }
23
+ /**
24
+ * Load the delivered corpus of an effective profile chain. Iterates
25
+ * `delivers` in order (parent-first + manifest order — the deterministic
26
+ * injection order), so the returned entry order is stable across runs.
27
+ */
28
+ export async function loadDeliveredCorpus(delivers, readFile, realPath) {
29
+ const entries = [];
30
+ const diagnostics = [];
31
+ for (const doc of delivers) {
32
+ if (realPath && !(await deliveredPathIsContained(doc, realPath))) {
33
+ diagnostics.push({
34
+ code: "PROFILE-DELIVERS-005",
35
+ severity: "error",
36
+ message: `delivered ${doc.corpus ? "corpus" : "document"} file ` +
37
+ `'${doc.path}' declared by ${corpusOriginLabel(doc)} resolves ` +
38
+ `outside the profile package (symlink escape) and was not read`,
39
+ location: { file: doc.absPath, line: 1, column: 1 },
40
+ });
41
+ continue;
42
+ }
43
+ const content = await readFile(doc.absPath);
44
+ if (content === undefined) {
45
+ diagnostics.push({
46
+ code: doc.corpus ? "PROFILE-DELIVERS-001" : "PROFILE-DELIVERS-002",
47
+ severity: doc.corpus ? "error" : "warning",
48
+ message: `delivered ${doc.corpus ? "corpus" : "document"} file ` +
49
+ `'${doc.path}' declared by ${corpusOriginLabel(doc)} is missing ` +
50
+ `from the profile package`,
51
+ location: { file: doc.absPath, line: 1, column: 1 },
52
+ });
53
+ continue;
54
+ }
55
+ if (!doc.corpus)
56
+ continue; // docs-only: existence check only, never parsed
57
+ const parsed = await parseFile(content, { file: doc.absPath });
58
+ for (const d of parsed.diagnostics) {
59
+ diagnostics.push({
60
+ ...d,
61
+ message: `delivered by ${corpusOriginLabel(doc)}: ${d.message}`,
62
+ });
63
+ }
64
+ const origin = {
65
+ kind: "profile",
66
+ profileId: doc.profileId,
67
+ profileVersion: doc.profileVersion,
68
+ };
69
+ entries.push(...parsed.entries.map((e) => ({ ...e, origin })));
70
+ }
71
+ return { entries, diagnostics };
72
+ }
73
+ /**
74
+ * True when `doc`'s real (symlink-resolved) path stays within its profile's
75
+ * `baseDir` — the delivered-path containment guard (#699). A malicious profile
76
+ * (pulled via `extends: git+…`, which preserves symlinks) can deliver a `.md`
77
+ * that is actually a symlink to an arbitrary local file (`~/.ssh/id_rsa`); the
78
+ * string-level path checks (PROFILE-DELIVERS-003/004) validate the declared
79
+ * path, not the symlink target, so a real-path containment check is the only
80
+ * thing that stops the read.
81
+ *
82
+ * Degrades to `true` (allow) when the doc carries no `baseDir` or when the
83
+ * paths cannot be canonicalised (e.g. the file is missing) — a missing file is
84
+ * left to the existing PROFILE-DELIVERS-001/002 checks. Shared by the MCP
85
+ * `readDeliveredDocument` read path, which faces the same vector.
86
+ */
87
+ export async function deliveredPathIsContained(doc, realPath) {
88
+ if (doc.baseDir === undefined)
89
+ return true;
90
+ let realBase;
91
+ let realTarget;
92
+ try {
93
+ realBase = await realPath(doc.baseDir);
94
+ realTarget = await realPath(doc.absPath);
95
+ }
96
+ catch {
97
+ return true; // unresolvable (e.g. missing) — handled by 001/002 downstream
98
+ }
99
+ if (realTarget === realBase)
100
+ return true;
101
+ const prefix = realBase.endsWith(SEPARATOR) ? realBase : realBase + SEPARATOR;
102
+ return realTarget.startsWith(prefix);
103
+ }
@@ -11,6 +11,7 @@ export declare const ALLOWED_PROFILE_KEYS: Set<string>;
11
11
  export declare const ALLOWED_TYPE_KEYS: Set<string>;
12
12
  export declare const ALLOWED_DOC_TYPE_KEYS: Set<string>;
13
13
  export declare const ALLOWED_DOCUMENTS_KEYS: Set<string>;
14
+ export declare const ALLOWED_DELIVERS_KEYS: Set<string>;
14
15
  export declare const ALLOWED_ATTR_KEYS: Set<string>;
15
16
  export declare const ALLOWED_INVERSE_KEYS: Set<string>;
16
17
  export declare const ALLOWED_TRACE_RULE_KEYS: Set<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA6BnE,eAAO,MAAM,iBAAiB,aAS5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAU/B,CAAC;AAEH,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAEH,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAChF,eAAO,MAAM,sBAAsB,aAAoC,CAAC;AAExE,eAAO,MAAM,iBAAiB,aAQ5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAAgC,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAKlC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AA2tCD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CA+LrB"}
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA8BnE,eAAO,MAAM,iBAAiB,aAS5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAW/B,CAAC;AAEH,eAAO,MAAM,iBAAiB,aAU5B,CAAC;AAEH,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAChF,eAAO,MAAM,sBAAsB,aAAoC,CAAC;AACxE,eAAO,MAAM,qBAAqB,aAA6C,CAAC;AAEhF,eAAO,MAAM,iBAAiB,aAQ5B,CAAC;AAEH,eAAO,MAAM,oBAAoB,aAAgC,CAAC;AAElE,eAAO,MAAM,uBAAuB,aAKlC,CAAC;AAEH,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAq0CD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CAyMrB"}
@@ -26,6 +26,7 @@ export const ALLOWED_PROFILE_KEYS = new Set([
26
26
  "conventions",
27
27
  "types",
28
28
  "documents",
29
+ "delivers",
29
30
  "kinds",
30
31
  "prose",
31
32
  "discipline-mode",
@@ -43,6 +44,7 @@ export const ALLOWED_TYPE_KEYS = new Set([
43
44
  ]);
44
45
  export const ALLOWED_DOC_TYPE_KEYS = new Set(["id", "contains", "description"]);
45
46
  export const ALLOWED_DOCUMENTS_KEYS = new Set(["types", "frontMatter"]);
47
+ export const ALLOWED_DELIVERS_KEYS = new Set(["path", "corpus", "description"]);
46
48
  export const ALLOWED_ATTR_KEYS = new Set([
47
49
  "name",
48
50
  "type",
@@ -1094,6 +1096,106 @@ function parseDocumentsSection(raw, sourcePath, diagnostics) {
1094
1096
  const frontMatter = parseAttrList(r.frontMatter, "profile.documents.frontMatter", sourcePath, diagnostics);
1095
1097
  return { types, frontMatter };
1096
1098
  }
1099
+ function parseDeliversSection(raw, sourcePath, diagnostics) {
1100
+ if (raw === undefined)
1101
+ return [];
1102
+ const loc = { file: sourcePath, line: 1, column: 1 };
1103
+ if (!Array.isArray(raw)) {
1104
+ diagnostics.push({
1105
+ code: "PROFILE-LOAD-003",
1106
+ severity: "error",
1107
+ message: `profile.delivers: must be a list`,
1108
+ location: loc,
1109
+ });
1110
+ return [];
1111
+ }
1112
+ const out = [];
1113
+ const seenPaths = new Set();
1114
+ for (const item of raw) {
1115
+ if (item == null || typeof item !== "object" || Array.isArray(item)) {
1116
+ diagnostics.push({
1117
+ code: "PROFILE-LOAD-003",
1118
+ severity: "error",
1119
+ message: `profile.delivers: each item must be a mapping`,
1120
+ location: loc,
1121
+ });
1122
+ continue;
1123
+ }
1124
+ const r = item;
1125
+ for (const key of Object.keys(r)) {
1126
+ if (!ALLOWED_DELIVERS_KEYS.has(key)) {
1127
+ diagnostics.push({
1128
+ code: "PROFILE-LOAD-003",
1129
+ severity: "error",
1130
+ message: `profile.delivers: unknown key '${key}'`,
1131
+ location: loc,
1132
+ });
1133
+ }
1134
+ }
1135
+ const path = r.path;
1136
+ if (typeof path !== "string" || path.trim().length === 0) {
1137
+ diagnostics.push({
1138
+ code: "PROFILE-LOAD-003",
1139
+ severity: "error",
1140
+ message: `profile.delivers: item missing required 'path' (string)`,
1141
+ location: loc,
1142
+ });
1143
+ continue;
1144
+ }
1145
+ // PROFILE-DELIVERS-003 — the path must stay inside the profile
1146
+ // directory: no absolute paths (POSIX or drive-letter), no `..`.
1147
+ const normalized = path.replaceAll("\\", "/");
1148
+ if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) ||
1149
+ normalized.split("/").includes("..")) {
1150
+ diagnostics.push({
1151
+ code: "PROFILE-DELIVERS-003",
1152
+ severity: "error",
1153
+ message: `profile.delivers: path '${path}' escapes the profile ` +
1154
+ `directory (absolute paths and '..' segments are not allowed)`,
1155
+ location: loc,
1156
+ });
1157
+ continue;
1158
+ }
1159
+ if (r.corpus !== undefined && typeof r.corpus !== "boolean") {
1160
+ diagnostics.push({
1161
+ code: "PROFILE-LOAD-003",
1162
+ severity: "error",
1163
+ message: `profile.delivers: 'corpus' must be a boolean`,
1164
+ location: loc,
1165
+ });
1166
+ continue;
1167
+ }
1168
+ const corpus = r.corpus === true;
1169
+ if (corpus && !normalized.toLowerCase().endsWith(".md")) {
1170
+ diagnostics.push({
1171
+ code: "PROFILE-DELIVERS-004",
1172
+ severity: "error",
1173
+ message: `profile.delivers: 'corpus: true' requires a Markdown ` +
1174
+ `(.md) file, got '${path}'`,
1175
+ location: loc,
1176
+ });
1177
+ continue;
1178
+ }
1179
+ if (seenPaths.has(normalized)) {
1180
+ diagnostics.push({
1181
+ code: "PROFILE-LOAD-003",
1182
+ severity: "error",
1183
+ message: `profile.delivers: duplicate path '${path}'`,
1184
+ location: loc,
1185
+ });
1186
+ continue;
1187
+ }
1188
+ seenPaths.add(normalized);
1189
+ out.push({
1190
+ path: normalized,
1191
+ corpus,
1192
+ description: typeof r.description === "string"
1193
+ ? r.description
1194
+ : undefined,
1195
+ });
1196
+ }
1197
+ return out;
1198
+ }
1097
1199
  /**
1098
1200
  * Parse and validate a raw markspec.yaml string.
1099
1201
  *
@@ -1207,6 +1309,10 @@ export function parseManifest(rawYaml, sourcePath = "<markspec.yaml>") {
1207
1309
  if (diagnostics.some((d) => d.severity === "error")) {
1208
1310
  return { manifest: null, diagnostics };
1209
1311
  }
1312
+ const delivers = parseDeliversSection(profileSection.delivers, sourcePath, diagnostics);
1313
+ if (diagnostics.some((d) => d.severity === "error")) {
1314
+ return { manifest: null, diagnostics };
1315
+ }
1210
1316
  const prose = parseProse(profileSection.prose, sourcePath, diagnostics);
1211
1317
  if (diagnostics.some((d) => d.severity === "error")) {
1212
1318
  return { manifest: null, diagnostics };
@@ -1236,6 +1342,7 @@ export function parseManifest(rawYaml, sourcePath = "<markspec.yaml>") {
1236
1342
  colors,
1237
1343
  types: types,
1238
1344
  documents: documents,
1345
+ delivers,
1239
1346
  kinds,
1240
1347
  prose,
1241
1348
  disciplineMode,
@@ -1 +1 @@
1
- {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/profile/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAEV,UAAU,EAGV,gBAAgB,EAKhB,YAAY,EASb,MAAM,iBAAiB,CAAC;AAGzB,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAiF3D"}
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/profile/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAGV,UAAU,EAGV,gBAAgB,EAKhB,YAAY,EASb,MAAM,iBAAiB,CAAC;AAGzB,oDAAoD;AACpD,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAiF3D"}
@@ -7,6 +7,7 @@
7
7
  *
8
8
  * Merge happens once at load. Callers should not call `mergeChain` lazily.
9
9
  */
10
+ import { join } from "@std/path";
10
11
  import { CORE_KINDS } from "../model/mod.js";
11
12
  import { resolveDisciplineMode } from "./discipline_mode.js";
12
13
  /**
@@ -140,6 +141,13 @@ function foldTier(base, tier, diagnostics) {
140
141
  // Overlap handling deferred.
141
142
  }
142
143
  const frontMatter = unionAttrMap(base.documents.frontMatter, m.documents.frontMatter, origin, diagnostics);
144
+ // Delivered documents — additive union keyed by (profileId, path).
145
+ const delivers = [...base.delivers];
146
+ for (const d of deliveredFromTier(tier)) {
147
+ if (!delivers.some((e) => e.profileId === d.profileId && e.path === d.path)) {
148
+ delivers.push(d);
149
+ }
150
+ }
143
151
  // Prose lexicons: list-additive across tiers (profile-schema §5.1).
144
152
  const capAllow = unionList(base.prose.lexicons["capitalized-allow"], m.prose.lexicons["capitalized-allow"], origin);
145
153
  const sentAbbrev = unionList(base.prose.lexicons["sentence-abbrev"], m.prose.lexicons["sentence-abbrev"], origin);
@@ -153,6 +161,7 @@ function foldTier(base, tier, diagnostics) {
153
161
  types: docTypes,
154
162
  frontMatter,
155
163
  },
164
+ delivers,
156
165
  kinds,
157
166
  prose: {
158
167
  lexicons: {
@@ -516,6 +525,18 @@ function stringifyMatcher(m) {
516
525
  // ---------------------------------------------------------------------------
517
526
  // Helpers: construct an EffectiveProfile from a single tier's manifest.
518
527
  // ---------------------------------------------------------------------------
528
+ /** Resolve a tier's `delivers:` declarations against its baseDir (ADR-030). */
529
+ function deliveredFromTier(tier) {
530
+ return tier.manifest.delivers.map((d) => ({
531
+ profileId: tier.id,
532
+ profileVersion: tier.version,
533
+ path: d.path,
534
+ absPath: join(tier.baseDir, d.path),
535
+ baseDir: tier.baseDir,
536
+ corpus: d.corpus,
537
+ description: d.description,
538
+ }));
539
+ }
519
540
  function seedFromTier(tier) {
520
541
  const origin = tier.id;
521
542
  const m = tier.manifest;
@@ -529,6 +550,7 @@ function seedFromTier(tier) {
529
550
  types: mapFromDocTypes(m.documents.types, origin),
530
551
  frontMatter: mapFromAttrList(m.documents.frontMatter, origin),
531
552
  },
553
+ delivers: deliveredFromTier(tier),
532
554
  kinds: mapFromKinds(m.kinds, origin),
533
555
  prose: {
534
556
  lexicons: {
@@ -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;AAE/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,CA4FtC"}
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"}
package/esm/refs/mod.js CHANGED
@@ -12,6 +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
16
  /**
16
17
  * Trace-attribute keys whose values are canonicalised/healed: the core
17
18
  * relations plus `Verified-by`. Derived from {@linkcode CORE_RELATIONS} so new
@@ -84,12 +85,25 @@ export function canonicalizeRefs(content, entries, index, ledger) {
84
85
  };
85
86
  const lines = content.split("\n");
86
87
  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;
87
95
  for (let i = 0; i < lines.length; i++) {
88
96
  // Strip a trailing CR before matching so CRLF files are handled (the
89
97
  // trailer regex ends in `$`, which `\r` would block) and re-append it on
90
98
  // rewrite so line endings stay byte-for-byte lossless.
91
99
  const cr = lines[i].endsWith("\r");
92
100
  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;
93
107
  const m = TRACE_TRAILER_RE.exec(bare);
94
108
  if (!m)
95
109
  continue;
@@ -116,6 +130,14 @@ export function canonicalizeRefs(content, entries, index, ledger) {
116
130
  j++;
117
131
  const crj = lines[j].endsWith("\r");
118
132
  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)) {
138
+ j--;
139
+ break;
140
+ }
119
141
  const cm = CONTINUATION_LINE_RE.exec(barej);
120
142
  if (!cm) {
121
143
  j--; // not a continuation line — leave it for the outer loop
@@ -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;AAGxD,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;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO5E"}
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;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO5E"}
@@ -4,6 +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 } from "../model/mod.js";
7
8
  /**
8
9
  * Generate a report from compiled traceability graph.
9
10
  *
@@ -42,6 +43,15 @@ function filterEntries(result, scope, label) {
42
43
  }
43
44
  return entries;
44
45
  }
46
+ /**
47
+ * Render an entry's provenance cell (ADR-030): `<profileId>@<profileVersion>`
48
+ * for an entry injected from a profile-delivered corpus, `"project"` for a
49
+ * project-authored entry. Shared by the traceability matrix builder so CSV,
50
+ * Markdown, and JSON rows all agree on the same value.
51
+ */
52
+ function originCell(entry) {
53
+ return entry.origin ? formatEntryOrigin(entry.origin) : "project";
54
+ }
45
55
  function buildTraceRows(result, entries) {
46
56
  return entries.map((entry) => {
47
57
  const fwd = result.forward.get(entry.displayId) ?? [];
@@ -50,6 +60,7 @@ function buildTraceRows(result, entries) {
50
60
  id: entry.displayId,
51
61
  title: entry.title,
52
62
  entryType: entry.type ?? "",
63
+ origin: originCell(entry),
53
64
  satisfies: fwd
54
65
  .filter((l) => l.kind === "satisfies")
55
66
  .map((l) => l.to)
@@ -67,20 +78,21 @@ function formatTraceability(result, entries, format) {
67
78
  return JSON.stringify(rows, null, 2);
68
79
  }
69
80
  if (format === "csv") {
70
- const header = "ID,Title,Type,Satisfies,Satisfied-by";
81
+ const header = "ID,Title,Type,Origin,Satisfies,Satisfied-by";
71
82
  const lines = rows.map((r) => [
72
83
  r.id,
73
84
  csvEscape(r.title),
74
85
  r.entryType,
86
+ csvEscape(r.origin),
75
87
  csvEscape(r.satisfies),
76
88
  csvEscape(r.satisfiedBy),
77
89
  ].join(","));
78
90
  return [header, ...lines].join("\n");
79
91
  }
80
92
  // Markdown table
81
- const header = "| ID | Title | Type | Satisfies | Satisfied-by |";
82
- const sep = "| -- | ----- | ---- | --------- | ------------ |";
83
- const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
93
+ const header = "| ID | Title | Type | Origin | Satisfies | Satisfied-by |";
94
+ const sep = "| -- | ----- | ---- | ------ | --------- | ------------ |";
95
+ const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.origin} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
84
96
  return [header, sep, ...lines].join("\n");
85
97
  }
86
98
  function computeCoverage(result, entries) {
@@ -27,4 +27,12 @@ export type ProseLineCallback = (line: string, index: number) => void;
27
27
  * skipped (they're structural, not prose).
28
28
  */
29
29
  export declare function walkProseLines(body: string, cb: ProseLineCallback): void;
30
+ /**
31
+ * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
32
+ * would skip — either a fence-marker line itself, or content inside a
33
+ * fenced block. Single-line-membership counterpart to `walkProseLines`'s
34
+ * full-body callback walk, for callers that only need a yes/no answer for
35
+ * one position (e.g. an LSP request gating a cursor position, #680).
36
+ */
37
+ export declare function isLineFenced(body: string, lineIndex: number): boolean;
30
38
  //# sourceMappingURL=fence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAExC,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAYxE"}
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAExC,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAYxE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAYrE"}
package/esm/util/fence.js CHANGED
@@ -38,3 +38,25 @@ export function walkProseLines(body, cb) {
38
38
  cb(line, i);
39
39
  }
40
40
  }
41
+ /**
42
+ * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
43
+ * would skip — either a fence-marker line itself, or content inside a
44
+ * fenced block. Single-line-membership counterpart to `walkProseLines`'s
45
+ * full-body callback walk, for callers that only need a yes/no answer for
46
+ * one position (e.g. an LSP request gating a cursor position, #680).
47
+ */
48
+ export function isLineFenced(body, lineIndex) {
49
+ const lines = body.split("\n");
50
+ let inFence = false;
51
+ for (let i = 0; i <= lineIndex && i < lines.length; i++) {
52
+ if (FENCE_RE.test(lines[i])) {
53
+ inFence = !inFence;
54
+ if (i === lineIndex)
55
+ return true;
56
+ continue;
57
+ }
58
+ if (i === lineIndex)
59
+ return inFence;
60
+ }
61
+ return false;
62
+ }