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