@driftsys/markspec 0.3.0 → 0.5.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.
Files changed (331) hide show
  1. package/esm/ast/build.d.ts +70 -0
  2. package/esm/ast/build.d.ts.map +1 -0
  3. package/esm/ast/build.js +605 -0
  4. package/esm/ast/equivalence.d.ts +18 -0
  5. package/esm/ast/equivalence.d.ts.map +1 -0
  6. package/esm/ast/equivalence.js +56 -0
  7. package/esm/ast/nodes.d.ts +221 -0
  8. package/esm/ast/nodes.d.ts.map +1 -0
  9. package/esm/ast/nodes.js +12 -0
  10. package/esm/ast/normalize.d.ts +67 -0
  11. package/esm/ast/normalize.d.ts.map +1 -0
  12. package/esm/ast/normalize.js +255 -0
  13. package/esm/ast/render.d.ts +34 -0
  14. package/esm/ast/render.d.ts.map +1 -0
  15. package/esm/ast/render.js +215 -0
  16. package/esm/compiler/inverses.d.ts +2 -8
  17. package/esm/compiler/inverses.d.ts.map +1 -1
  18. package/esm/compiler/inverses.js +50 -14
  19. package/esm/compiler/manifest.d.ts +59 -0
  20. package/esm/compiler/manifest.d.ts.map +1 -0
  21. package/esm/compiler/manifest.js +48 -0
  22. package/esm/compiler/mod.d.ts +9 -1
  23. package/esm/compiler/mod.d.ts.map +1 -1
  24. package/esm/compiler/mod.js +21 -2
  25. package/esm/compiler/ndjson_writer.d.ts +50 -0
  26. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  27. package/esm/compiler/ndjson_writer.js +73 -0
  28. package/esm/compiler/schema.d.ts +18 -1
  29. package/esm/compiler/schema.d.ts.map +1 -1
  30. package/esm/compiler/schema.js +18 -9
  31. package/esm/config/mod.d.ts.map +1 -1
  32. package/esm/config/mod.js +54 -0
  33. package/esm/formatter/mod.d.ts +56 -6
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +372 -41
  36. package/esm/formatter/synth_ulid.d.ts +21 -0
  37. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  38. package/esm/formatter/synth_ulid.js +64 -0
  39. package/esm/lint/mod.d.ts +10 -0
  40. package/esm/lint/mod.d.ts.map +1 -0
  41. package/esm/lint/mod.js +7 -0
  42. package/esm/lint/rules/lexicon.d.ts +24 -0
  43. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  44. package/esm/lint/rules/lexicon.js +236 -0
  45. package/esm/lint/rules/struct.d.ts +17 -0
  46. package/esm/lint/rules/struct.d.ts.map +1 -0
  47. package/esm/lint/rules/struct.js +55 -0
  48. package/esm/lint/rules/suppression.d.ts +19 -0
  49. package/esm/lint/rules/suppression.d.ts.map +1 -0
  50. package/esm/lint/rules/suppression.js +75 -0
  51. package/esm/lint/runner.d.ts +39 -0
  52. package/esm/lint/runner.d.ts.map +1 -0
  53. package/esm/lint/runner.js +112 -0
  54. package/esm/lint/types.d.ts +19 -0
  55. package/esm/lint/types.d.ts.map +1 -0
  56. package/esm/lint/types.js +9 -0
  57. package/esm/mod.d.ts +21 -8
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +16 -5
  60. package/esm/model/attributes.d.ts.map +1 -1
  61. package/esm/model/attributes.js +163 -2
  62. package/esm/model/discriminating_attr.d.ts +33 -0
  63. package/esm/model/discriminating_attr.d.ts.map +1 -0
  64. package/esm/model/discriminating_attr.js +74 -0
  65. package/esm/model/mod.d.ts +100 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +58 -2
  68. package/esm/model/palette.d.ts +18 -0
  69. package/esm/model/palette.d.ts.map +1 -0
  70. package/esm/model/palette.js +23 -0
  71. package/esm/model/profile.d.ts +33 -27
  72. package/esm/model/profile.d.ts.map +1 -1
  73. package/esm/model/source_introspection.d.ts +26 -0
  74. package/esm/model/source_introspection.d.ts.map +1 -0
  75. package/esm/model/source_introspection.js +77 -0
  76. package/esm/model/type_hierarchy.d.ts +51 -0
  77. package/esm/model/type_hierarchy.d.ts.map +1 -0
  78. package/esm/model/type_hierarchy.js +126 -0
  79. package/esm/model/uri_scheme_map.d.ts +21 -0
  80. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  81. package/esm/model/uri_scheme_map.js +66 -0
  82. package/esm/parser/attributes.d.ts.map +1 -1
  83. package/esm/parser/attributes.js +9 -6
  84. package/esm/parser/entity_refs.d.ts +53 -0
  85. package/esm/parser/entity_refs.d.ts.map +1 -0
  86. package/esm/parser/entity_refs.js +151 -0
  87. package/esm/parser/glossary.d.ts +43 -0
  88. package/esm/parser/glossary.d.ts.map +1 -0
  89. package/esm/parser/glossary.js +217 -0
  90. package/esm/parser/markdown.d.ts +10 -3
  91. package/esm/parser/markdown.d.ts.map +1 -1
  92. package/esm/parser/markdown.js +241 -11
  93. package/esm/parser/mod.d.ts +1 -0
  94. package/esm/parser/mod.d.ts.map +1 -1
  95. package/esm/parser/mod.js +4 -3
  96. package/esm/parser/source.d.ts +20 -0
  97. package/esm/parser/source.d.ts.map +1 -1
  98. package/esm/parser/source.js +4 -4
  99. package/esm/profile/chain.js +3 -13
  100. package/esm/profile/colors.d.ts +26 -0
  101. package/esm/profile/colors.d.ts.map +1 -0
  102. package/esm/profile/colors.js +46 -0
  103. package/esm/profile/introspect.d.ts +135 -0
  104. package/esm/profile/introspect.d.ts.map +1 -0
  105. package/esm/profile/introspect.js +378 -0
  106. package/esm/profile/load.d.ts.map +1 -1
  107. package/esm/profile/load.js +67 -0
  108. package/esm/profile/manifest.d.ts.map +1 -1
  109. package/esm/profile/manifest.js +278 -104
  110. package/esm/profile/merge.js +139 -39
  111. package/esm/profile/mod.d.ts +3 -4
  112. package/esm/profile/mod.d.ts.map +1 -1
  113. package/esm/profile/mod.js +6 -2
  114. package/esm/reporter/mod.js +4 -4
  115. package/esm/util/fence.d.ts +30 -0
  116. package/esm/util/fence.d.ts.map +1 -0
  117. package/esm/util/fence.js +40 -0
  118. package/esm/validator/attributes.d.ts +3 -3
  119. package/esm/validator/attributes.d.ts.map +1 -1
  120. package/esm/validator/attributes.js +1 -18
  121. package/esm/validator/body_blocks.d.ts +38 -0
  122. package/esm/validator/body_blocks.d.ts.map +1 -0
  123. package/esm/validator/body_blocks.js +218 -0
  124. package/esm/validator/caption_convention.d.ts +29 -0
  125. package/esm/validator/caption_convention.d.ts.map +1 -0
  126. package/esm/validator/caption_convention.js +58 -0
  127. package/esm/validator/captions.d.ts +22 -0
  128. package/esm/validator/captions.d.ts.map +1 -0
  129. package/esm/validator/captions.js +137 -0
  130. package/esm/validator/component_schemes.d.ts +73 -0
  131. package/esm/validator/component_schemes.d.ts.map +1 -0
  132. package/esm/validator/component_schemes.js +375 -0
  133. package/esm/validator/feature_ac.d.ts +28 -0
  134. package/esm/validator/feature_ac.d.ts.map +1 -0
  135. package/esm/validator/feature_ac.js +102 -0
  136. package/esm/validator/listing.d.ts +42 -0
  137. package/esm/validator/listing.d.ts.map +1 -0
  138. package/esm/validator/listing.js +295 -0
  139. package/esm/validator/mod.d.ts +2 -0
  140. package/esm/validator/mod.d.ts.map +1 -1
  141. package/esm/validator/mod.js +253 -12
  142. package/esm/validator/modal_keywords.d.ts +23 -0
  143. package/esm/validator/modal_keywords.d.ts.map +1 -0
  144. package/esm/validator/modal_keywords.js +137 -0
  145. package/esm/validator/per_type_attrs.d.ts +29 -0
  146. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  147. package/esm/validator/per_type_attrs.js +75 -0
  148. package/esm/validator/pipeline.d.ts +7 -2
  149. package/esm/validator/pipeline.d.ts.map +1 -1
  150. package/esm/validator/pipeline.js +40 -7
  151. package/esm/validator/trace_types.d.ts +26 -0
  152. package/esm/validator/trace_types.d.ts.map +1 -0
  153. package/esm/validator/trace_types.js +232 -0
  154. package/esm/validator/traceability.d.ts +3 -4
  155. package/esm/validator/traceability.d.ts.map +1 -1
  156. package/esm/validator/traceability.js +5 -10
  157. package/esm/validator/type_resolution.d.ts +67 -0
  158. package/esm/validator/type_resolution.d.ts.map +1 -0
  159. package/esm/validator/type_resolution.js +140 -0
  160. package/esm/validator/types.d.ts +45 -0
  161. package/esm/validator/types.d.ts.map +1 -1
  162. package/esm/validator/types.js +128 -16
  163. package/esm/validator/value_types.d.ts +8 -0
  164. package/esm/validator/value_types.d.ts.map +1 -1
  165. package/esm/validator/value_types.js +8 -1
  166. package/package.json +1 -1
  167. package/script/ast/build.d.ts +70 -0
  168. package/script/ast/build.d.ts.map +1 -0
  169. package/script/ast/build.js +610 -0
  170. package/script/ast/equivalence.d.ts +18 -0
  171. package/script/ast/equivalence.d.ts.map +1 -0
  172. package/script/ast/equivalence.js +59 -0
  173. package/script/ast/nodes.d.ts +221 -0
  174. package/script/ast/nodes.d.ts.map +1 -0
  175. package/script/ast/nodes.js +13 -0
  176. package/script/ast/normalize.d.ts +67 -0
  177. package/script/ast/normalize.d.ts.map +1 -0
  178. package/script/ast/normalize.js +258 -0
  179. package/script/ast/render.d.ts +34 -0
  180. package/script/ast/render.d.ts.map +1 -0
  181. package/script/ast/render.js +218 -0
  182. package/script/compiler/inverses.d.ts +2 -8
  183. package/script/compiler/inverses.d.ts.map +1 -1
  184. package/script/compiler/inverses.js +50 -14
  185. package/script/compiler/manifest.d.ts +59 -0
  186. package/script/compiler/manifest.d.ts.map +1 -0
  187. package/script/compiler/manifest.js +51 -0
  188. package/script/compiler/mod.d.ts +9 -1
  189. package/script/compiler/mod.d.ts.map +1 -1
  190. package/script/compiler/mod.js +21 -2
  191. package/script/compiler/ndjson_writer.d.ts +50 -0
  192. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  193. package/script/compiler/ndjson_writer.js +78 -0
  194. package/script/compiler/schema.d.ts +18 -1
  195. package/script/compiler/schema.d.ts.map +1 -1
  196. package/script/compiler/schema.js +18 -8
  197. package/script/config/mod.d.ts.map +1 -1
  198. package/script/config/mod.js +54 -0
  199. package/script/formatter/mod.d.ts +56 -6
  200. package/script/formatter/mod.d.ts.map +1 -1
  201. package/script/formatter/mod.js +375 -41
  202. package/script/formatter/synth_ulid.d.ts +21 -0
  203. package/script/formatter/synth_ulid.d.ts.map +1 -0
  204. package/script/formatter/synth_ulid.js +67 -0
  205. package/script/lint/mod.d.ts +10 -0
  206. package/script/lint/mod.d.ts.map +1 -0
  207. package/script/lint/mod.js +12 -0
  208. package/script/lint/rules/lexicon.d.ts +24 -0
  209. package/script/lint/rules/lexicon.d.ts.map +1 -0
  210. package/script/lint/rules/lexicon.js +240 -0
  211. package/script/lint/rules/struct.d.ts +17 -0
  212. package/script/lint/rules/struct.d.ts.map +1 -0
  213. package/script/lint/rules/struct.js +59 -0
  214. package/script/lint/rules/suppression.d.ts +19 -0
  215. package/script/lint/rules/suppression.d.ts.map +1 -0
  216. package/script/lint/rules/suppression.js +80 -0
  217. package/script/lint/runner.d.ts +39 -0
  218. package/script/lint/runner.d.ts.map +1 -0
  219. package/script/lint/runner.js +116 -0
  220. package/script/lint/types.d.ts +19 -0
  221. package/script/lint/types.d.ts.map +1 -0
  222. package/script/lint/types.js +10 -0
  223. package/script/mod.d.ts +21 -8
  224. package/script/mod.d.ts.map +1 -1
  225. package/script/mod.js +58 -32
  226. package/script/model/attributes.d.ts.map +1 -1
  227. package/script/model/attributes.js +163 -2
  228. package/script/model/discriminating_attr.d.ts +33 -0
  229. package/script/model/discriminating_attr.d.ts.map +1 -0
  230. package/script/model/discriminating_attr.js +77 -0
  231. package/script/model/mod.d.ts +100 -3
  232. package/script/model/mod.d.ts.map +1 -1
  233. package/script/model/mod.js +67 -3
  234. package/script/model/palette.d.ts +18 -0
  235. package/script/model/palette.d.ts.map +1 -0
  236. package/script/model/palette.js +26 -0
  237. package/script/model/profile.d.ts +33 -27
  238. package/script/model/profile.d.ts.map +1 -1
  239. package/script/model/source_introspection.d.ts +26 -0
  240. package/script/model/source_introspection.d.ts.map +1 -0
  241. package/script/model/source_introspection.js +80 -0
  242. package/script/model/type_hierarchy.d.ts +51 -0
  243. package/script/model/type_hierarchy.d.ts.map +1 -0
  244. package/script/model/type_hierarchy.js +130 -0
  245. package/script/model/uri_scheme_map.d.ts +21 -0
  246. package/script/model/uri_scheme_map.d.ts.map +1 -0
  247. package/script/model/uri_scheme_map.js +69 -0
  248. package/script/parser/attributes.d.ts.map +1 -1
  249. package/script/parser/attributes.js +9 -6
  250. package/script/parser/entity_refs.d.ts +53 -0
  251. package/script/parser/entity_refs.d.ts.map +1 -0
  252. package/script/parser/entity_refs.js +155 -0
  253. package/script/parser/glossary.d.ts +43 -0
  254. package/script/parser/glossary.d.ts.map +1 -0
  255. package/script/parser/glossary.js +221 -0
  256. package/script/parser/markdown.d.ts +10 -3
  257. package/script/parser/markdown.d.ts.map +1 -1
  258. package/script/parser/markdown.js +240 -10
  259. package/script/parser/mod.d.ts +1 -0
  260. package/script/parser/mod.d.ts.map +1 -1
  261. package/script/parser/mod.js +8 -4
  262. package/script/parser/source.d.ts +20 -0
  263. package/script/parser/source.d.ts.map +1 -1
  264. package/script/parser/source.js +4 -1
  265. package/script/profile/chain.js +3 -13
  266. package/script/profile/colors.d.ts +26 -0
  267. package/script/profile/colors.d.ts.map +1 -0
  268. package/script/profile/colors.js +49 -0
  269. package/script/profile/introspect.d.ts +135 -0
  270. package/script/profile/introspect.d.ts.map +1 -0
  271. package/script/profile/introspect.js +381 -0
  272. package/script/profile/load.d.ts.map +1 -1
  273. package/script/profile/load.js +67 -0
  274. package/script/profile/manifest.d.ts.map +1 -1
  275. package/script/profile/manifest.js +280 -106
  276. package/script/profile/merge.js +139 -39
  277. package/script/profile/mod.d.ts +3 -4
  278. package/script/profile/mod.d.ts.map +1 -1
  279. package/script/profile/mod.js +9 -6
  280. package/script/reporter/mod.js +4 -4
  281. package/script/util/fence.d.ts +30 -0
  282. package/script/util/fence.d.ts.map +1 -0
  283. package/script/util/fence.js +44 -0
  284. package/script/validator/attributes.d.ts +3 -3
  285. package/script/validator/attributes.d.ts.map +1 -1
  286. package/script/validator/attributes.js +1 -18
  287. package/script/validator/body_blocks.d.ts +38 -0
  288. package/script/validator/body_blocks.d.ts.map +1 -0
  289. package/script/validator/body_blocks.js +221 -0
  290. package/script/validator/caption_convention.d.ts +29 -0
  291. package/script/validator/caption_convention.d.ts.map +1 -0
  292. package/script/validator/caption_convention.js +61 -0
  293. package/script/validator/captions.d.ts +22 -0
  294. package/script/validator/captions.d.ts.map +1 -0
  295. package/script/validator/captions.js +140 -0
  296. package/script/validator/component_schemes.d.ts +73 -0
  297. package/script/validator/component_schemes.d.ts.map +1 -0
  298. package/script/validator/component_schemes.js +384 -0
  299. package/script/validator/feature_ac.d.ts +28 -0
  300. package/script/validator/feature_ac.d.ts.map +1 -0
  301. package/script/validator/feature_ac.js +105 -0
  302. package/script/validator/listing.d.ts +42 -0
  303. package/script/validator/listing.d.ts.map +1 -0
  304. package/script/validator/listing.js +298 -0
  305. package/script/validator/mod.d.ts +2 -0
  306. package/script/validator/mod.d.ts.map +1 -1
  307. package/script/validator/mod.js +256 -14
  308. package/script/validator/modal_keywords.d.ts +23 -0
  309. package/script/validator/modal_keywords.d.ts.map +1 -0
  310. package/script/validator/modal_keywords.js +140 -0
  311. package/script/validator/per_type_attrs.d.ts +29 -0
  312. package/script/validator/per_type_attrs.d.ts.map +1 -0
  313. package/script/validator/per_type_attrs.js +78 -0
  314. package/script/validator/pipeline.d.ts +7 -2
  315. package/script/validator/pipeline.d.ts.map +1 -1
  316. package/script/validator/pipeline.js +39 -6
  317. package/script/validator/trace_types.d.ts +26 -0
  318. package/script/validator/trace_types.d.ts.map +1 -0
  319. package/script/validator/trace_types.js +235 -0
  320. package/script/validator/traceability.d.ts +3 -4
  321. package/script/validator/traceability.d.ts.map +1 -1
  322. package/script/validator/traceability.js +5 -10
  323. package/script/validator/type_resolution.d.ts +67 -0
  324. package/script/validator/type_resolution.d.ts.map +1 -0
  325. package/script/validator/type_resolution.js +146 -0
  326. package/script/validator/types.d.ts +45 -0
  327. package/script/validator/types.d.ts.map +1 -1
  328. package/script/validator/types.js +131 -16
  329. package/script/validator/value_types.d.ts +8 -0
  330. package/script/validator/value_types.d.ts.map +1 -1
  331. package/script/validator/value_types.js +10 -2
@@ -11,6 +11,12 @@ import { attributeSpec, IDENTITY_KEY } from "../model/mod.js";
11
11
  import { ATTR_LINE_RE } from "../parser/attributes.js";
12
12
  import { extractFrontMatter } from "../parser/frontmatter.js";
13
13
  import { parseMarkdown } from "../parser/markdown.js";
14
+ import { FENCE_RE, walkProseLines } from "../util/fence.js";
15
+ import { synthesizedUlid } from "./synth_ulid.js";
16
+ import { buildBodyAst } from "../ast/build.js";
17
+ import { render as renderBodyAst } from "../ast/render.js";
18
+ import { normalizeBodyAst } from "../ast/normalize.js";
19
+ import { astEquivalent } from "../ast/equivalence.js";
14
20
  /**
15
21
  * Value types that accept CSV on input but must be emitted as multi-line
16
22
  * per ADR-002 §2.6. `citation` is deliberately excluded because locators
@@ -21,6 +27,71 @@ const CSV_SPLITTABLE_TYPES = new Set([
21
27
  "tag-list",
22
28
  "external-id",
23
29
  ]);
30
+ /**
31
+ * RFC 2119 modal keywords in uppercase form, with optional ` NOT` suffix.
32
+ * Captured for canonical-form normalisation per spec §3.4.1: uppercase
33
+ * input is accepted but emitted lowercase, unconditionally.
34
+ */
35
+ const RFC2119_MODAL_RE = /\b(SHALL|SHOULD|MAY|MUST)(\s+NOT)?\b/g;
36
+ /**
37
+ * EARS keywords subject to the sentence-initial rule of spec §3.4.1:
38
+ * lowercased when mid-sentence, preserved when starting a sentence.
39
+ * `If…then` is deferred to a later slice because its multi-token form
40
+ * needs separate handling.
41
+ */
42
+ const EARS_KEYWORD_RE = /\b(When|While|Where|Unless)\b/g;
43
+ /**
44
+ * Decide whether the EARS keyword at `offset` in `line` is at sentence
45
+ * start (return value true). Walks left over whitespace and reports true
46
+ * when it hits the beginning of the line or a sentence-terminating
47
+ * punctuation character (`.`, `!`, `?`).
48
+ */
49
+ export function isSentenceInitial(line, offset) {
50
+ if (offset === 0)
51
+ return true;
52
+ let i = offset - 1;
53
+ while (i >= 0 && (line[i] === " " || line[i] === "\t"))
54
+ i--;
55
+ if (i < 0)
56
+ return true;
57
+ const prev = line[i];
58
+ return prev === "." || prev === "!" || prev === "?";
59
+ }
60
+ /**
61
+ * Normalise modal keywords to canonical case in body prose (§3.4.1):
62
+ *
63
+ * - RFC 2119 (`SHALL`, `SHOULD`, `MAY`, `MUST`, optionally `… NOT`) —
64
+ * always lowercased.
65
+ * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased mid-sentence,
66
+ * preserved sentence-initial.
67
+ *
68
+ * The pass skips:
69
+ *
70
+ * - Fenced code blocks (between paired ``` or ~~~ markers) — code is
71
+ * verbatim per round-trip invariants (spec §5.1).
72
+ * - Lines indented by four or more spaces (or a tab) — conservatively
73
+ * captures indented code blocks and attribute trailers, both of which
74
+ * are not prose.
75
+ *
76
+ * @remarks Not called by `format()` as of SP3 Task 5 — body modal
77
+ * normalization moved to `normalizeBodyAst` in the AST pass (spec-correct
78
+ * verbatim-boundary handling). Retained as an exported symbol because
79
+ * `mod_test.ts` tests it directly and `core/ast/normalize.ts` documents
80
+ * the intentional duplication until a follow-up collapses the two. Do NOT
81
+ * delete — external callers may depend on this export.
82
+ */
83
+ export function normalizeModalKeywords(markdown) {
84
+ const lines = markdown.split("\n");
85
+ walkProseLines(markdown, (line, i) => {
86
+ // Indented-code / attribute-trailer lines aren't prose either.
87
+ if (/^( {4}|\t)/.test(line))
88
+ return;
89
+ let normalized = line.replace(RFC2119_MODAL_RE, (m) => m.toLowerCase());
90
+ normalized = normalized.replace(EARS_KEYWORD_RE, (m, _g1, offset) => isSentenceInitial(normalized, offset) ? m : m.toLowerCase());
91
+ lines[i] = normalized;
92
+ });
93
+ return lines.join("\n");
94
+ }
24
95
  /**
25
96
  * Canonical front-matter key order per ADR-007. Core keys first, then
26
97
  * `metadata` (reserved free-form map), then `extra` (allowlisted ecosystem
@@ -36,29 +107,194 @@ const FRONT_MATTER_CORE_ORDER = [
36
107
  "references",
37
108
  ];
38
109
  /**
39
- * Canonical attribute ordering per the language spec.
110
+ * Canonical trailer ordering per spec §3.3.2 (six-group rule).
40
111
  *
41
- * Identity (`Id:`) comes first, then profile-declared attributes appear in
42
- * the order the author wrote them (or in the order a profile-aware pass
43
- * may rewrite them), then the universal set
44
- * (References / Labels / External-id / Supersedes / Deprecated). Unknown
45
- * keys are placed just before `Labels:`, preserving their relative order.
112
+ * Groups, top → bottom:
113
+ * 1. Identity & classification — `Id`, `Type`, `Source`, `Origin`.
114
+ * 2. Reference-shape navigation — `Reference-document`, `Reference-url`.
115
+ * 3. Trace upstream relations — authored trace edges (`Part-of`,
116
+ * `Derived-from`, `Satisfies`, …).
117
+ * 4. Type-specific data — payload attributes per concrete type
118
+ * (`Schema-language`, `License`, `Manufacturer`, …).
119
+ * 5. Universal trailing — `References`, `External-id`, `Labels`,
120
+ * `Supersedes`, `Deprecated`.
121
+ * 6. Profile-declared / unknown attributes — preserved in source order
122
+ * at the bottom (§3.3.6: fmt never deletes a key it doesn't own).
46
123
  *
47
- * A profile-aware formatter may extend this with profile-declared canonical
48
- * positions; the core formatter only knows about `Id:` and the universal
49
- * set.
124
+ * Generated-origin attributes (`Superseded-by`, every inverse from ADR-003
125
+ * §Part 3) are stripped from this list; the formatter rejects them with
126
+ * MSL-A030 when found in source (current code keeps `Superseded-by:` to
127
+ * round-trip historical fixtures — that hardening lands in a later slice).
50
128
  */
51
129
  const CANONICAL_ORDER = [
130
+ // Group 1 — identity & classification
52
131
  "Id",
53
- // Profile-declared attributes land here in whatever order the source has
54
- // them; the filler slot keeps them between Id and the universal set.
132
+ "Type",
133
+ "Source",
134
+ "Origin",
135
+ // Group 2 — reference-shape navigation
136
+ "Reference-document",
137
+ "Reference-url",
138
+ // Group 3 — trace upstream (authored relations)
139
+ "Part-of",
140
+ "Derived-from",
141
+ "Satisfies",
142
+ "Verifies",
143
+ "Tests",
144
+ "Realizes",
145
+ "Provides",
146
+ "Requires",
147
+ "Depends-on",
148
+ "Caused-by",
149
+ "Mitigated-by",
150
+ "Allocated-to",
151
+ "Affects",
152
+ // Group 4 — type-specific data
153
+ "Schema-language",
154
+ "License",
155
+ "Build-manifest",
156
+ "Package-manager",
157
+ "Manufacturer",
158
+ "Part-number",
159
+ "Datasheet",
160
+ "Bus-protocol",
161
+ "Connector-type",
162
+ "Voltage-level",
163
+ "Signal-direction",
164
+ "Symbol",
165
+ "Language",
166
+ "Footprint",
167
+ "Value",
168
+ "Aliases",
169
+ "See-also",
170
+ // Group 5 — universal trailing
55
171
  "References",
56
- "Labels",
57
172
  "External-id",
173
+ "Labels",
58
174
  "Supersedes",
59
175
  "Superseded-by",
60
176
  "Deprecated",
177
+ // Group 6 — profile-declared / unknown keys are appended in source order
178
+ // after this list by sortAttributes().
61
179
  ];
180
+ /**
181
+ * Post-pass: route each entry's body through the canonical body-AST
182
+ * (the load-bearing §5.2 emission path — SP3 Task 5 cutover).
183
+ *
184
+ * Called on the post-collapse `lines` array (after attribute-block
185
+ * splicing and `collapseBlankLines`). The body modal-keyword §3.4.1
186
+ * pass is NO LONGER applied as a pre-parse whole-body string pass; it
187
+ * is now AST-native via `normalizeBodyAst` here (more spec-correct:
188
+ * the AST pass respects §2.5 verbatim boundaries and per-node
189
+ * sentence-initial context that the whole-body string pass could get
190
+ * wrong inside Code/Math blocks). Re-parses the lines to get entries
191
+ * with correct post-collapse line numbers, then for each entry:
192
+ *
193
+ * 1. Takes `entry.body` — the body string from the parser
194
+ * (indent-stripped, trimmed, attrs split off).
195
+ * 2. Builds the body AST, applies `normalizeBodyAst` (the §3.4.1 /
196
+ * §5.2 canonicalization pass), and emits via `render`.
197
+ * 3. Guards the emit with the formal §5 `astEquivalent` relation:
198
+ * `render`-ing the emitted body and re-building must be AST-equal
199
+ * to the canonical AST. If not, this is an SP3 residual — keep
200
+ * the original body lines untouched and raise a LOUD diagnostic
201
+ * (MSL-F900). This branch is RETAINED for safety; over the
202
+ * idempotence corpus and real project docs it never fires.
203
+ * 4. Reconstructs the body segment in `lines` from the emitted
204
+ * string, preserving the leading/trailing blank-line delimiters
205
+ * that separate the body from the title and attr block.
206
+ *
207
+ * Returns `true` when any entry body was rewritten (so `format()` can
208
+ * keep `changed` accurate for `--check` mode); `false` when every body
209
+ * was already §5.2-canonical.
210
+ *
211
+ * `Entry.body` stays `string`; no other module is affected.
212
+ * `normalizeBodyAst` is FORMATTER-ONLY — the validate/parse path must
213
+ * never call it.
214
+ */
215
+ function emitBodyViaAst(lines, file, diagnostics) {
216
+ // Diagnostics from this re-parse are intentionally discarded: the
217
+ // input is already canonical (post-collapse) output.
218
+ const { entries } = parseMarkdown(lines.join("\n"), { file });
219
+ if (entries.length === 0)
220
+ return false;
221
+ let bodyChanged = false;
222
+ // Process bottom-to-top so splices don't shift earlier entry positions.
223
+ const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
224
+ for (const entry of sorted) {
225
+ if (!entry.body.trim())
226
+ continue; // empty or whitespace-only body
227
+ const indent = (entry.location.column - 1) + 2; // marker column (0-based) + 2 spaces = list-item continuation indent
228
+ const indentStr = " ".repeat(indent);
229
+ const titleLineIdx = entry.location.line - 1; // 0-based
230
+ // Locate the body segment in `lines` — between the title line and
231
+ // the attr block start (or item end when there is no attr block).
232
+ const range = findAttributeBlockRange(lines, entry.location.line, indent);
233
+ const bodyStart = titleLineIdx + 1;
234
+ const bodyEnd = range
235
+ ? range.start
236
+ : findItemEnd(lines, titleLineIdx, indent);
237
+ if (bodyEnd <= bodyStart)
238
+ continue; // no body lines to replace
239
+ // Route the body through the canonical AST: build → normalize
240
+ // (§3.4.1 / §5.2) → render. The §5 equivalence relation guards the
241
+ // emit; `render`+`build` is the inverse on canonical input for
242
+ // every body shape under the equivalence gate.
243
+ const ast0 = buildBodyAst(entry.body);
244
+ const canonical = normalizeBodyAst(ast0);
245
+ const emittedBody = renderBodyAst(canonical);
246
+ if (!astEquivalent(buildBodyAst(emittedBody), canonical)) {
247
+ // SP3 residual. The build/render inverse is not yet total over
248
+ // every valid Markdown body construct; for a body where the
249
+ // emitted form does not re-build AST-equivalent to the canonical
250
+ // AST we cannot guarantee a lossless §5.2 re-emission. Keep the
251
+ // original body lines EXACTLY as-is — zero corruption, zero
252
+ // spurious rewrites — and raise a LOUD diagnostic so the residual
253
+ // is visible (it never fires over the idempotence corpus or real
254
+ // project docs). This safe-fallback branch is RETAINED by design;
255
+ // only its criterion changed (byte-identity → astEquivalent) and
256
+ // it now diagnoses instead of silently degrading.
257
+ diagnostics.push({
258
+ code: "MSL-F900",
259
+ severity: "error",
260
+ message: `${entry.displayId}: body not AST-equivalent after ` +
261
+ `canonicalization (SP3 residual — formatter kept the ` +
262
+ `original body)`,
263
+ location: entry.location,
264
+ });
265
+ continue;
266
+ }
267
+ // The emitted body is the §5.2-canonical body and re-builds
268
+ // AST-equivalent to the canonical AST. Splice it back into the
269
+ // document — the AST is the load-bearing emission path.
270
+ // Reconstruct the body segment: re-add the continuation indent to
271
+ // each non-blank line, preserving the blank-line delimiters that
272
+ // separate the body from the title and attr block.
273
+ const rawSegment = lines.slice(bodyStart, bodyEnd);
274
+ // Preserve the blank delimiter lines at the start/end of the segment.
275
+ const leadBlanks = [];
276
+ const trailBlanks = [];
277
+ let si = 0;
278
+ while (si < rawSegment.length && rawSegment[si].trim() === "") {
279
+ leadBlanks.push(rawSegment[si++]);
280
+ }
281
+ let ei = rawSegment.length - 1;
282
+ while (ei >= si && rawSegment[ei].trim() === "") {
283
+ trailBlanks.unshift(rawSegment[ei--]);
284
+ }
285
+ const emittedLines = emittedBody.split("\n").map((l) => l ? `${indentStr}${l}` : l);
286
+ const newSegment = [...leadBlanks, ...emittedLines, ...trailBlanks];
287
+ // `changed` accuracy: only flag a body rewrite when the spliced
288
+ // segment actually differs from the original lines (a §5.2-canonical
289
+ // body splices back byte-identically — a pure no-op).
290
+ if (newSegment.length !== rawSegment.length ||
291
+ newSegment.some((l, i) => l !== rawSegment[i])) {
292
+ bodyChanged = true;
293
+ }
294
+ lines.splice(bodyStart, bodyEnd - bodyStart, ...newSegment);
295
+ }
296
+ return bodyChanged;
297
+ }
62
298
  /**
63
299
  * Format a Markdown string — normalize attribute blocks,
64
300
  * fix indentation, enforce canonical ordering.
@@ -72,8 +308,14 @@ export function format(markdown, options) {
72
308
  // Extract any YAML front matter first so entries are parsed against the
73
309
  // body only (front-matter `---` could be confused with horizontal rules).
74
310
  const fm = extractFrontMatter(markdown, { file });
75
- const body = fm.hadFrontMatter ? fm.markdown : markdown;
76
- const entries = parseMarkdown(body, { file });
311
+ const rawBody = fm.hadFrontMatter ? fm.markdown : markdown;
312
+ // The §3.4.1 modal-keyword pass is NO LONGER a pre-parse whole-body
313
+ // string pass. It is AST-native in `emitBodyViaAst` via
314
+ // `normalizeBodyAst` (more spec-correct: respects §2.5 verbatim
315
+ // boundaries and per-node sentence-initial context). `normalizeModalKeywords`
316
+ // stays exported/defined for other callers/tests but is not invoked here.
317
+ const body = rawBody;
318
+ const { entries } = parseMarkdown(body, { file });
77
319
  const diagnostics = [...fm.diagnostics];
78
320
  if (entries.length === 0 && !fm.hadFrontMatter) {
79
321
  return { output: markdown, diagnostics, changed: false };
@@ -86,12 +328,37 @@ export function format(markdown, options) {
86
328
  for (const entry of sorted) {
87
329
  const indent = (entry.location.column - 1) + 2;
88
330
  let attrs = [...entry.rawAttributes];
331
+ // Title-line bullet canonicalisation per spec §3.2: rewrite `*`
332
+ // or `+` to `-`. The list-item position from the parser is the
333
+ // line carrying the bullet marker; we only touch the marker
334
+ // character itself, leaving the rest of the title alone.
335
+ const titleLineIdx = entry.location.line - 1;
336
+ if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
337
+ const titleLine = lines[titleLineIdx];
338
+ const markerCol = entry.location.column - 1;
339
+ const markerChar = titleLine.charAt(markerCol);
340
+ if (markerChar === "*" || markerChar === "+") {
341
+ lines[titleLineIdx] = titleLine.slice(0, markerCol) +
342
+ "-" + titleLine.slice(markerCol + 1);
343
+ changed = true;
344
+ }
345
+ }
89
346
  // Assign a bare ULID `Id:` to identified entries that carry no
90
347
  // identity yet. Referenced entries are left alone — their `Id:` is a
91
348
  // URI that must be author-provided.
349
+ //
350
+ // For `Origin: synthesized` entries (spec §3.5), derive the ULID
351
+ // deterministically from `Source:` so re-running `fmt` on the same
352
+ // input reproduces the same identity. Falls back to fresh random
353
+ // when `Source:` is missing — synthesizing without a source pointer
354
+ // makes no sense, but the formatter never fails a stamp.
92
355
  const hasIdentity = attrs.some((a) => a.key === IDENTITY_KEY);
93
- if (!hasIdentity && entry.shape === "identified") {
94
- const newId = genUlid();
356
+ if (!hasIdentity && entry.shape === "Authored") {
357
+ const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
358
+ const source = attrs.find((a) => a.key === "Source")?.value.trim();
359
+ const newId = origin === "synthesized" && source && source.length > 0
360
+ ? synthesizedUlid(source)
361
+ : genUlid();
95
362
  attrs = [{ key: IDENTITY_KEY, value: newId }, ...attrs];
96
363
  diagnostics.push({
97
364
  code: "MSL-F001",
@@ -121,7 +388,26 @@ export function format(markdown, options) {
121
388
  changed = true;
122
389
  }
123
390
  }
124
- const formattedBody = lines.join("\n");
391
+ // Spec §3.4.3 / §5.2 — collapse consecutive blank lines to one.
392
+ // Runs after entry-block splicing so the in-progress line indices
393
+ // stay aligned with parser-reported positions. Operates inside
394
+ // fenced code regions only outside-code; verbatim regions keep
395
+ // their blank-line counts.
396
+ const collapsedLines = collapseBlankLines(lines);
397
+ if (collapsedLines.length !== lines.length)
398
+ changed = true;
399
+ // SP3 §5.2-via-AST cutover: route each entry's body through the
400
+ // canonical AST — build → normalizeBodyAst (§3.4.1 / §5.2) → render,
401
+ // guarded by the formal §5 `astEquivalent` relation. This is the
402
+ // load-bearing body-emission path AND the body modal-keyword pass
403
+ // (the pre-parse whole-body string pass was removed above). It
404
+ // returns whether any body was rewritten so `changed` stays accurate
405
+ // for `--check`. emitBodyViaAst re-parses collapsedLines to get
406
+ // post-collapse entry positions, scoped only to the body segment
407
+ // (title/trailer/front-matter are untouched).
408
+ if (emitBodyViaAst(collapsedLines, file, diagnostics))
409
+ changed = true;
410
+ const formattedBody = collapsedLines.join("\n");
125
411
  if (fm.hadFrontMatter) {
126
412
  const canonicalFm = renderFrontMatter(fm.attributes);
127
413
  const output = canonicalFm + formattedBody;
@@ -157,6 +443,36 @@ function renderFrontMatter(attrs) {
157
443
  const yaml = stringifyYaml(ordered).trimEnd();
158
444
  return `---\n${yaml}\n---\n\n`;
159
445
  }
446
+ /**
447
+ * Collapse consecutive blank lines to a single blank line per spec
448
+ * §3.4.3 (caption boundary) / §5.2 (general body rule). Fenced code
449
+ * regions are preserved verbatim — blank-line counts inside fenced
450
+ * blocks are author intent, not noise.
451
+ */
452
+ function collapseBlankLines(lines) {
453
+ const out = [];
454
+ let inFence = false;
455
+ let prevBlank = false;
456
+ for (const line of lines) {
457
+ if (FENCE_RE.test(line)) {
458
+ out.push(line);
459
+ inFence = !inFence;
460
+ prevBlank = false;
461
+ continue;
462
+ }
463
+ if (inFence) {
464
+ out.push(line);
465
+ prevBlank = false;
466
+ continue;
467
+ }
468
+ const isBlank = line.trim() === "";
469
+ if (isBlank && prevBlank)
470
+ continue;
471
+ out.push(line);
472
+ prevBlank = isBlank;
473
+ }
474
+ return out;
475
+ }
160
476
  /**
161
477
  * Expand CSV values on repeatable-type attributes into one entry per value
162
478
  * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
@@ -183,56 +499,71 @@ export function expandCsvValues(attrs) {
183
499
  return result;
184
500
  }
185
501
  /**
186
- * Sort attributes to canonical order per the language spec.
502
+ * Canonicalise a trailer key to TitleCase-Hyphenated per spec §3.3.4.
503
+ * First character of the key uppercase, every other character
504
+ * lowercase; hyphens preserved. Examples (from the spec):
505
+ *
506
+ * `Id`, `Derived-from`, `Reference-url`, `Bus-protocol`.
187
507
  *
188
- * `Id:` first, then profile-declared/unknown keys in source order, then
189
- * universal attributes (References / Labels / External-id / Supersedes /
190
- * Superseded-by / Deprecated).
508
+ * Inputs like `ID`, `BUS-PROTOCOL`, `reference-URL`, `Derived-From`
509
+ * all canonicalise to the spec form regardless of casing in source.
510
+ */
511
+ export function canonicalizeKey(key) {
512
+ if (key.length === 0)
513
+ return key;
514
+ return key[0].toUpperCase() + key.slice(1).toLowerCase();
515
+ }
516
+ /**
517
+ * Sort attributes to canonical trailer order per spec §3.3.2 and
518
+ * re-case each key per spec §3.3.4.
519
+ *
520
+ * Known core keys appear in their {@linkcode CANONICAL_ORDER} slot
521
+ * (lookup is case-insensitive via {@linkcode canonicalizeKey}).
522
+ * Unknown / profile-declared keys (group 6) are appended at the end
523
+ * in source order — `fmt` never deletes a key it doesn't own
524
+ * (§3.3.6). Every emitted attribute carries the canonical key form.
191
525
  */
192
526
  export function sortAttributes(attributes) {
193
527
  const known = new Array(CANONICAL_ORDER.length);
194
528
  const unknown = [];
195
529
  for (const attr of attributes) {
196
- const idx = CANONICAL_ORDER.indexOf(attr.key);
530
+ const canonical = canonicalizeKey(attr.key);
531
+ const recased = canonical === attr.key
532
+ ? attr
533
+ : { ...attr, key: canonical };
534
+ const idx = CANONICAL_ORDER.indexOf(canonical);
197
535
  if (idx >= 0) {
198
536
  // Preserve duplicates — keep all occurrences of the same key.
199
537
  if (!known[idx])
200
538
  known[idx] = [];
201
- known[idx].push(attr);
539
+ known[idx].push(recased);
202
540
  }
203
541
  else {
204
- unknown.push(attr);
542
+ unknown.push(recased);
205
543
  }
206
544
  }
207
545
  const result = [];
208
- const labelsIdx = CANONICAL_ORDER.indexOf("Labels");
209
- const hasLabels = known[labelsIdx] != null;
210
546
  for (let i = 0; i < known.length; i++) {
211
- // Insert unknown attributes just before Labels (or at end if no Labels).
212
- if (i === labelsIdx && hasLabels) {
213
- result.push(...unknown);
214
- }
215
547
  if (known[i] != null) {
216
548
  result.push(...known[i]);
217
549
  }
218
550
  }
219
- // If Labels was not present, unknown attrs go at the end.
220
- if (!hasLabels) {
221
- result.push(...unknown);
222
- }
551
+ result.push(...unknown);
223
552
  return result;
224
553
  }
225
554
  /**
226
- * Render attributes as indented `Key: Value\` lines.
227
- * Trailing backslash on all lines except the last.
555
+ * Render attributes as an indented code block.
556
+ * Each line is `Key: Value` at (indent + 4) absolute columns;
557
+ * no trailing line-continuation characters.
558
+ *
559
+ * @param attributes - The attributes to render, in canonical order.
560
+ * @param indent - Body indent for the entry (2 for list-wrapped entries,
561
+ * 0 for entries inside source-file doc comments).
228
562
  */
229
563
  export function renderAttributeBlock(attributes, indent) {
230
- const prefix = " ".repeat(indent);
564
+ const prefix = " ".repeat(indent + 4);
231
565
  return attributes
232
- .map((attr, i) => {
233
- const sep = i < attributes.length - 1 ? "\\" : "";
234
- return `${prefix}${attr.key}: ${attr.value}${sep}`;
235
- })
566
+ .map((attr) => `${prefix}${attr.key}: ${attr.value}`)
236
567
  .join("\n");
237
568
  }
238
569
  /**
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module core/formatter/synth_ulid
3
+ *
4
+ * Deterministic synthesized-ULID derivation per spec §3.5:
5
+ *
6
+ * ULID(timestamp=0, randomness=truncate(SHA-256(canonical(Source)), 80))
7
+ *
8
+ * Used by the formatter when an Authored entry carries `Origin:
9
+ * synthesized` — the ULID becomes a content-addressed fingerprint of the
10
+ * source pointer, so re-running `fmt` against an already-synthesized
11
+ * entry reproduces the same `Id:`. Authored (default) origin keeps using
12
+ * a fresh random ULID.
13
+ *
14
+ * Uses `node:crypto` rather than Web Crypto so the function stays
15
+ * synchronous; the formatter's public API is sync and threading async
16
+ * through every call site would be a much larger change for no benefit
17
+ * (the hash is bounded by a single short string).
18
+ */
19
+ /** Derive a deterministic ULID from a `Source:` value. */
20
+ export declare function synthesizedUlid(source: string): string;
21
+ //# sourceMappingURL=synth_ulid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"synth_ulid.d.ts","sourceRoot":"","sources":["../../src/formatter/synth_ulid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgDH,0DAA0D;AAC1D,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKtD"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @module core/formatter/synth_ulid
3
+ *
4
+ * Deterministic synthesized-ULID derivation per spec §3.5:
5
+ *
6
+ * ULID(timestamp=0, randomness=truncate(SHA-256(canonical(Source)), 80))
7
+ *
8
+ * Used by the formatter when an Authored entry carries `Origin:
9
+ * synthesized` — the ULID becomes a content-addressed fingerprint of the
10
+ * source pointer, so re-running `fmt` against an already-synthesized
11
+ * entry reproduces the same `Id:`. Authored (default) origin keeps using
12
+ * a fresh random ULID.
13
+ *
14
+ * Uses `node:crypto` rather than Web Crypto so the function stays
15
+ * synchronous; the formatter's public API is sync and threading async
16
+ * through every call site would be a much larger change for no benefit
17
+ * (the hash is bounded by a single short string).
18
+ */
19
+ import { createHash } from "node:crypto";
20
+ /** Crockford base32 alphabet (no I, L, O, U). */
21
+ const CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
22
+ /** Timestamp half of a `ULID(timestamp=0)` — 10 zero chars. */
23
+ const ZERO_TIMESTAMP = "0000000000";
24
+ /**
25
+ * Canonicalize a `Source:` value before hashing.
26
+ *
27
+ * Currently: trim leading/trailing whitespace. The canonical form is
28
+ * intentionally minimal — `Source:` is already author-typed and not
29
+ * subject to encoding ambiguity beyond stray surrounding whitespace
30
+ * that the parser may not have stripped (e.g. trailing `\n` from
31
+ * line-joined trailers).
32
+ */
33
+ function canonical(source) {
34
+ return source.trim();
35
+ }
36
+ /**
37
+ * Encode an 80-bit (10-byte) buffer as a 16-char Crockford base32
38
+ * string. Bit order matches the ULID spec (most-significant bit first
39
+ * in the output). Each Crockford symbol carries 5 bits; 80 / 5 = 16.
40
+ */
41
+ function encodeBase32_80(bytes) {
42
+ if (bytes.length !== 10) {
43
+ throw new Error(`expected 10 bytes for 80-bit encoding, got ${bytes.length}`);
44
+ }
45
+ // Accumulate bits into a buffer and pull 5 at a time, MSB-first.
46
+ let bits = 0n;
47
+ for (const b of bytes) {
48
+ bits = (bits << 8n) | BigInt(b);
49
+ }
50
+ let out = "";
51
+ for (let i = 15; i >= 0; i--) {
52
+ const shift = BigInt(i * 5);
53
+ const idx = Number((bits >> shift) & 0x1fn);
54
+ out += CROCKFORD[idx];
55
+ }
56
+ return out;
57
+ }
58
+ /** Derive a deterministic ULID from a `Source:` value. */
59
+ export function synthesizedUlid(source) {
60
+ const canonicalSource = canonical(source);
61
+ const hash = createHash("sha256").update(canonicalSource, "utf8").digest();
62
+ const truncated = new Uint8Array(hash.buffer, hash.byteOffset, 10);
63
+ return ZERO_TIMESTAMP + encodeBase32_80(truncated);
64
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module core/lint
3
+ *
4
+ * Prose-analysis lint pipeline barrel. Exports the public API for the
5
+ * markspec lint subcommand and LSP integration.
6
+ */
7
+ export type { LintDiagnostic } from "./types.js";
8
+ export { isProseScope, runLint } from "./runner.js";
9
+ export type { LintOptions, LintResult } from "./runner.js";
10
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/lint/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACpD,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @module core/lint
3
+ *
4
+ * Prose-analysis lint pipeline barrel. Exports the public API for the
5
+ * markspec lint subcommand and LSP integration.
6
+ */
7
+ export { isProseScope, runLint } from "./runner.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module core/lint/rules/lexicon
3
+ *
4
+ * Six INCOSE GtWR lexicon rules for PA-1. All operate by scanning
5
+ * InlineContent.text in prose-bearing AST blocks for canonical
6
+ * word/phrase matches. No sentence segmentation needed.
7
+ *
8
+ * Rules:
9
+ * MSL-Q302 incose-r7-vague-term (warn, score 3)
10
+ * MSL-Q303 incose-r8-escape-clause (warn, score 3)
11
+ * MSL-Q304 incose-r9-open-ended (info, score 1)
12
+ * MSL-Q305 incose-r10-superfluous-inf (info, score 1)
13
+ * MSL-Q310 incose-r26-absolute (info, score 1)
14
+ * MSL-Q313 incose-r16-not (info, score 1)
15
+ */
16
+ import type { Entry } from "../../model/mod.js";
17
+ import type { LintDiagnostic } from "../types.js";
18
+ /** Run all six lexicon rules on an entry's prose AST blocks.
19
+ * Returns one LintDiagnostic per matching term per rule (one per rule
20
+ * per entry — first match only, to avoid flooding). */
21
+ export declare function runLexiconRules(entry: Entry): LintDiagnostic[];
22
+ /** Exported for test/diagnostic use: the set of rule codes this module emits. */
23
+ export declare const LEXICON_RULE_CODES: ReadonlySet<string>;
24
+ //# sourceMappingURL=lexicon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexicon.d.ts","sourceRoot":"","sources":["../../../src/lint/rules/lexicon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,KAAK,EAA4B,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA4LlD;;uDAEuD;AACvD,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,EAAE,CAiD9D;AAED,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAOjD,CAAC"}