@driftsys/markspec 0.4.0 → 0.6.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 (632) hide show
  1. package/README.md +74 -20
  2. package/esm/ast/build.d.ts +60 -0
  3. package/esm/ast/build.d.ts.map +1 -0
  4. package/esm/ast/build.js +516 -0
  5. package/esm/ast/equivalence.d.ts +18 -0
  6. package/esm/ast/equivalence.d.ts.map +1 -0
  7. package/esm/ast/equivalence.js +56 -0
  8. package/esm/ast/nodes.d.ts +189 -0
  9. package/esm/ast/nodes.d.ts.map +1 -0
  10. package/esm/ast/nodes.js +17 -0
  11. package/esm/ast/normalize.d.ts +58 -0
  12. package/esm/ast/normalize.d.ts.map +1 -0
  13. package/esm/ast/normalize.js +197 -0
  14. package/esm/ast/render.d.ts +34 -0
  15. package/esm/ast/render.d.ts.map +1 -0
  16. package/esm/ast/render.js +215 -0
  17. package/esm/compiler/constants.d.ts +16 -0
  18. package/esm/compiler/constants.d.ts.map +1 -0
  19. package/esm/compiler/constants.js +26 -0
  20. package/esm/compiler/discipline_classifier.d.ts +55 -0
  21. package/esm/compiler/discipline_classifier.d.ts.map +1 -0
  22. package/esm/compiler/discipline_classifier.js +191 -0
  23. package/esm/compiler/inverses.d.ts +2 -1
  24. package/esm/compiler/inverses.d.ts.map +1 -1
  25. package/esm/compiler/inverses.js +33 -14
  26. package/esm/compiler/manifest.d.ts +59 -0
  27. package/esm/compiler/manifest.d.ts.map +1 -0
  28. package/esm/compiler/manifest.js +48 -0
  29. package/esm/compiler/mod.d.ts +38 -1
  30. package/esm/compiler/mod.d.ts.map +1 -1
  31. package/esm/compiler/mod.js +202 -50
  32. package/esm/compiler/ndjson_writer.d.ts +50 -0
  33. package/esm/compiler/ndjson_writer.d.ts.map +1 -0
  34. package/esm/compiler/ndjson_writer.js +73 -0
  35. package/esm/compiler/schema.d.ts +33 -1
  36. package/esm/compiler/schema.d.ts.map +1 -1
  37. package/esm/compiler/schema.js +30 -9
  38. package/esm/config/markspec.d.ts +5 -0
  39. package/esm/config/markspec.d.ts.map +1 -1
  40. package/esm/config/markspec.js +17 -2
  41. package/esm/config/mod.d.ts.map +1 -1
  42. package/esm/config/mod.js +54 -0
  43. package/esm/formatter/mod.d.ts +55 -4
  44. package/esm/formatter/mod.d.ts.map +1 -1
  45. package/esm/formatter/mod.js +423 -46
  46. package/esm/formatter/synth_ulid.d.ts +21 -0
  47. package/esm/formatter/synth_ulid.d.ts.map +1 -0
  48. package/esm/formatter/synth_ulid.js +64 -0
  49. package/esm/lexicons/loader.d.ts +35 -0
  50. package/esm/lexicons/loader.d.ts.map +1 -0
  51. package/esm/lexicons/loader.js +51 -0
  52. package/esm/lexicons/mod.d.ts +13 -0
  53. package/esm/lexicons/mod.d.ts.map +1 -0
  54. package/esm/lexicons/mod.js +12 -0
  55. package/esm/lint/glossary.d.ts +45 -0
  56. package/esm/lint/glossary.d.ts.map +1 -0
  57. package/esm/lint/glossary.js +85 -0
  58. package/esm/lint/mod.d.ts +14 -0
  59. package/esm/lint/mod.d.ts.map +1 -0
  60. package/esm/lint/mod.js +9 -0
  61. package/esm/lint/range_util.d.ts +25 -0
  62. package/esm/lint/range_util.d.ts.map +1 -0
  63. package/esm/lint/range_util.js +50 -0
  64. package/esm/lint/rules/ears.d.ts +39 -0
  65. package/esm/lint/rules/ears.d.ts.map +1 -0
  66. package/esm/lint/rules/ears.js +316 -0
  67. package/esm/lint/rules/incose_sentence.d.ts +46 -0
  68. package/esm/lint/rules/incose_sentence.d.ts.map +1 -0
  69. package/esm/lint/rules/incose_sentence.js +417 -0
  70. package/esm/lint/rules/lexicon.d.ts +24 -0
  71. package/esm/lint/rules/lexicon.d.ts.map +1 -0
  72. package/esm/lint/rules/lexicon.js +236 -0
  73. package/esm/lint/rules/modal_sentence.d.ts +46 -0
  74. package/esm/lint/rules/modal_sentence.d.ts.map +1 -0
  75. package/esm/lint/rules/modal_sentence.js +146 -0
  76. package/esm/lint/rules/passive.d.ts +64 -0
  77. package/esm/lint/rules/passive.d.ts.map +1 -0
  78. package/esm/lint/rules/passive.js +282 -0
  79. package/esm/lint/rules/struct.d.ts +17 -0
  80. package/esm/lint/rules/struct.d.ts.map +1 -0
  81. package/esm/lint/rules/struct.js +55 -0
  82. package/esm/lint/rules/suppression.d.ts +54 -0
  83. package/esm/lint/rules/suppression.d.ts.map +1 -0
  84. package/esm/lint/rules/suppression.js +129 -0
  85. package/esm/lint/rules/xref.d.ts +19 -0
  86. package/esm/lint/rules/xref.d.ts.map +1 -0
  87. package/esm/lint/rules/xref.js +248 -0
  88. package/esm/lint/runner.d.ts +59 -0
  89. package/esm/lint/runner.d.ts.map +1 -0
  90. package/esm/lint/runner.js +153 -0
  91. package/esm/lint/score.d.ts +64 -0
  92. package/esm/lint/score.d.ts.map +1 -0
  93. package/esm/lint/score.js +163 -0
  94. package/esm/lint/segmenter.d.ts +32 -0
  95. package/esm/lint/segmenter.d.ts.map +1 -0
  96. package/esm/lint/segmenter.js +79 -0
  97. package/esm/lint/types.d.ts +31 -0
  98. package/esm/lint/types.d.ts.map +1 -0
  99. package/esm/lint/types.js +9 -0
  100. package/esm/lock/canonical_edges.d.ts +31 -0
  101. package/esm/lock/canonical_edges.d.ts.map +1 -0
  102. package/esm/lock/canonical_edges.js +57 -0
  103. package/esm/lock/check.d.ts +24 -0
  104. package/esm/lock/check.d.ts.map +1 -0
  105. package/esm/lock/check.js +127 -0
  106. package/esm/lock/hash.d.ts +12 -0
  107. package/esm/lock/hash.d.ts.map +1 -0
  108. package/esm/lock/hash.js +32 -0
  109. package/esm/lock/mod.d.ts +19 -0
  110. package/esm/lock/mod.d.ts.map +1 -0
  111. package/esm/lock/mod.js +14 -0
  112. package/esm/lock/model.d.ts +81 -0
  113. package/esm/lock/model.d.ts.map +1 -0
  114. package/esm/lock/model.js +7 -0
  115. package/esm/lock/parser.d.ts +26 -0
  116. package/esm/lock/parser.d.ts.map +1 -0
  117. package/esm/lock/parser.js +195 -0
  118. package/esm/lock/resolve.d.ts +142 -0
  119. package/esm/lock/resolve.d.ts.map +1 -0
  120. package/esm/lock/resolve.js +389 -0
  121. package/esm/lock/serializer.d.ts +14 -0
  122. package/esm/lock/serializer.d.ts.map +1 -0
  123. package/esm/lock/serializer.js +104 -0
  124. package/esm/mod.d.ts +28 -8
  125. package/esm/mod.d.ts.map +1 -1
  126. package/esm/mod.js +23 -4
  127. package/esm/model/attributes.d.ts +6 -0
  128. package/esm/model/attributes.d.ts.map +1 -1
  129. package/esm/model/attributes.js +200 -2
  130. package/esm/model/discipline.d.ts +53 -0
  131. package/esm/model/discipline.d.ts.map +1 -0
  132. package/esm/model/discipline.js +50 -0
  133. package/esm/model/discriminating_attr.d.ts +33 -0
  134. package/esm/model/discriminating_attr.d.ts.map +1 -0
  135. package/esm/model/discriminating_attr.js +74 -0
  136. package/esm/model/mod.d.ts +267 -14
  137. package/esm/model/mod.d.ts.map +1 -1
  138. package/esm/model/mod.js +99 -3
  139. package/esm/model/profile.d.ts +102 -27
  140. package/esm/model/profile.d.ts.map +1 -1
  141. package/esm/model/source_introspection.d.ts +26 -0
  142. package/esm/model/source_introspection.d.ts.map +1 -0
  143. package/esm/model/source_introspection.js +77 -0
  144. package/esm/model/type_hierarchy.d.ts +51 -0
  145. package/esm/model/type_hierarchy.d.ts.map +1 -0
  146. package/esm/model/type_hierarchy.js +126 -0
  147. package/esm/model/uri_scheme_map.d.ts +21 -0
  148. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  149. package/esm/model/uri_scheme_map.js +66 -0
  150. package/esm/parser/attributes.d.ts.map +1 -1
  151. package/esm/parser/attributes.js +10 -16
  152. package/esm/parser/body_tokens.d.ts +35 -0
  153. package/esm/parser/body_tokens.d.ts.map +1 -0
  154. package/esm/parser/body_tokens.js +232 -0
  155. package/esm/parser/glossary.d.ts +51 -0
  156. package/esm/parser/glossary.d.ts.map +1 -0
  157. package/esm/parser/glossary.js +219 -0
  158. package/esm/parser/grammars.d.ts +5 -3
  159. package/esm/parser/grammars.d.ts.map +1 -1
  160. package/esm/parser/grammars.js +12 -4
  161. package/esm/parser/language_spec.d.ts +55 -0
  162. package/esm/parser/language_spec.d.ts.map +1 -0
  163. package/esm/parser/language_spec.js +419 -0
  164. package/esm/parser/line_map.d.ts +60 -0
  165. package/esm/parser/line_map.d.ts.map +1 -0
  166. package/esm/parser/line_map.js +41 -0
  167. package/esm/parser/markdown.d.ts +9 -0
  168. package/esm/parser/markdown.d.ts.map +1 -1
  169. package/esm/parser/markdown.js +317 -25
  170. package/esm/parser/mod.d.ts +5 -0
  171. package/esm/parser/mod.d.ts.map +1 -1
  172. package/esm/parser/mod.js +31 -8
  173. package/esm/parser/source.d.ts +53 -2
  174. package/esm/parser/source.d.ts.map +1 -1
  175. package/esm/parser/source.js +158 -68
  176. package/esm/parser/translate.d.ts +24 -0
  177. package/esm/parser/translate.d.ts.map +1 -0
  178. package/esm/parser/translate.js +99 -0
  179. package/esm/profile/chain.d.ts +8 -0
  180. package/esm/profile/chain.d.ts.map +1 -1
  181. package/esm/profile/chain.js +32 -14
  182. package/esm/profile/colors.js +1 -1
  183. package/esm/profile/default_profile.d.ts +25 -0
  184. package/esm/profile/default_profile.d.ts.map +1 -0
  185. package/esm/profile/default_profile.js +43 -0
  186. package/esm/profile/discipline_mode.d.ts +64 -0
  187. package/esm/profile/discipline_mode.d.ts.map +1 -0
  188. package/esm/profile/discipline_mode.js +133 -0
  189. package/esm/profile/discipline_registry.d.ts +41 -0
  190. package/esm/profile/discipline_registry.d.ts.map +1 -0
  191. package/esm/profile/discipline_registry.js +67 -0
  192. package/esm/profile/introspect.d.ts +135 -0
  193. package/esm/profile/introspect.d.ts.map +1 -0
  194. package/esm/profile/introspect.js +378 -0
  195. package/esm/profile/load.d.ts +3 -1
  196. package/esm/profile/load.d.ts.map +1 -1
  197. package/esm/profile/load.js +91 -5
  198. package/esm/profile/manifest.d.ts.map +1 -1
  199. package/esm/profile/manifest.js +512 -90
  200. package/esm/profile/merge.d.ts.map +1 -1
  201. package/esm/profile/merge.js +251 -39
  202. package/esm/profile/mod.d.ts +4 -4
  203. package/esm/profile/mod.d.ts.map +1 -1
  204. package/esm/profile/mod.js +7 -2
  205. package/esm/reporter/mod.js +4 -4
  206. package/esm/sync/locked_attributes.d.ts +19 -0
  207. package/esm/sync/locked_attributes.d.ts.map +1 -0
  208. package/esm/sync/locked_attributes.js +27 -0
  209. package/esm/sync/log.d.ts +34 -0
  210. package/esm/sync/log.d.ts.map +1 -0
  211. package/esm/sync/log.js +48 -0
  212. package/esm/sync/mapping.d.ts +66 -0
  213. package/esm/sync/mapping.d.ts.map +1 -0
  214. package/esm/sync/mapping.js +165 -0
  215. package/esm/sync/mod.d.ts +16 -0
  216. package/esm/sync/mod.d.ts.map +1 -0
  217. package/esm/sync/mod.js +12 -0
  218. package/esm/sync/status.d.ts +23 -0
  219. package/esm/sync/status.d.ts.map +1 -0
  220. package/esm/sync/status.js +21 -0
  221. package/esm/typl/ast.d.ts +87 -0
  222. package/esm/typl/ast.d.ts.map +1 -0
  223. package/esm/typl/ast.js +21 -0
  224. package/esm/typl/bridge.d.ts +32 -0
  225. package/esm/typl/bridge.d.ts.map +1 -0
  226. package/esm/typl/bridge.js +27 -0
  227. package/esm/typl/bullet.d.ts +34 -0
  228. package/esm/typl/bullet.d.ts.map +1 -0
  229. package/esm/typl/bullet.js +44 -0
  230. package/esm/typl/diagnostics.d.ts +43 -0
  231. package/esm/typl/diagnostics.d.ts.map +1 -0
  232. package/esm/typl/diagnostics.js +61 -0
  233. package/esm/typl/fence.d.ts +31 -0
  234. package/esm/typl/fence.d.ts.map +1 -0
  235. package/esm/typl/fence.js +24 -0
  236. package/esm/typl/grammar.d.ts +20 -0
  237. package/esm/typl/grammar.d.ts.map +1 -0
  238. package/esm/typl/grammar.js +471 -0
  239. package/esm/typl/inline.d.ts +34 -0
  240. package/esm/typl/inline.d.ts.map +1 -0
  241. package/esm/typl/inline.js +48 -0
  242. package/esm/typl/lexer.d.ts +37 -0
  243. package/esm/typl/lexer.d.ts.map +1 -0
  244. package/esm/typl/lexer.js +234 -0
  245. package/esm/typl/mod.d.ts +23 -0
  246. package/esm/typl/mod.d.ts.map +1 -0
  247. package/esm/typl/mod.js +16 -0
  248. package/esm/typl/registry.d.ts +42 -0
  249. package/esm/typl/registry.d.ts.map +1 -0
  250. package/esm/typl/registry.js +26 -0
  251. package/esm/typl/validator.d.ts +29 -0
  252. package/esm/typl/validator.d.ts.map +1 -0
  253. package/esm/typl/validator.js +141 -0
  254. package/esm/util/fence.d.ts +30 -0
  255. package/esm/util/fence.d.ts.map +1 -0
  256. package/esm/util/fence.js +40 -0
  257. package/esm/util/line_endings.d.ts +33 -0
  258. package/esm/util/line_endings.d.ts.map +1 -0
  259. package/esm/util/line_endings.js +53 -0
  260. package/esm/util/modals.d.ts +29 -0
  261. package/esm/util/modals.d.ts.map +1 -0
  262. package/esm/util/modals.js +38 -0
  263. package/esm/validator/attributes.d.ts +3 -3
  264. package/esm/validator/attributes.d.ts.map +1 -1
  265. package/esm/validator/attributes.js +1 -18
  266. package/esm/validator/body_blocks.d.ts +38 -0
  267. package/esm/validator/body_blocks.d.ts.map +1 -0
  268. package/esm/validator/body_blocks.js +218 -0
  269. package/esm/validator/caption_convention.d.ts +29 -0
  270. package/esm/validator/caption_convention.d.ts.map +1 -0
  271. package/esm/validator/caption_convention.js +58 -0
  272. package/esm/validator/captions.d.ts +22 -0
  273. package/esm/validator/captions.d.ts.map +1 -0
  274. package/esm/validator/captions.js +137 -0
  275. package/esm/validator/component_schemes.d.ts +73 -0
  276. package/esm/validator/component_schemes.d.ts.map +1 -0
  277. package/esm/validator/component_schemes.js +375 -0
  278. package/esm/validator/discipline.d.ts +35 -0
  279. package/esm/validator/discipline.d.ts.map +1 -0
  280. package/esm/validator/discipline.js +204 -0
  281. package/esm/validator/feature_ac.d.ts +28 -0
  282. package/esm/validator/feature_ac.d.ts.map +1 -0
  283. package/esm/validator/feature_ac.js +102 -0
  284. package/esm/validator/listing.d.ts +42 -0
  285. package/esm/validator/listing.d.ts.map +1 -0
  286. package/esm/validator/listing.js +295 -0
  287. package/esm/validator/mod.d.ts +3 -1
  288. package/esm/validator/mod.d.ts.map +1 -1
  289. package/esm/validator/mod.js +275 -13
  290. package/esm/validator/modal_keywords.d.ts +25 -0
  291. package/esm/validator/modal_keywords.d.ts.map +1 -0
  292. package/esm/validator/modal_keywords.js +54 -0
  293. package/esm/validator/pattern.d.ts +15 -8
  294. package/esm/validator/pattern.d.ts.map +1 -1
  295. package/esm/validator/pattern.js +42 -19
  296. package/esm/validator/per_type_attrs.d.ts +29 -0
  297. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  298. package/esm/validator/per_type_attrs.js +75 -0
  299. package/esm/validator/pipeline.d.ts +18 -2
  300. package/esm/validator/pipeline.d.ts.map +1 -1
  301. package/esm/validator/pipeline.js +76 -21
  302. package/esm/validator/trace_types.d.ts +26 -0
  303. package/esm/validator/trace_types.d.ts.map +1 -0
  304. package/esm/validator/trace_types.js +232 -0
  305. package/esm/validator/traceability.d.ts +3 -4
  306. package/esm/validator/traceability.d.ts.map +1 -1
  307. package/esm/validator/traceability.js +5 -10
  308. package/esm/validator/type_resolution.d.ts +67 -0
  309. package/esm/validator/type_resolution.d.ts.map +1 -0
  310. package/esm/validator/type_resolution.js +162 -0
  311. package/esm/validator/types.d.ts +45 -0
  312. package/esm/validator/types.d.ts.map +1 -1
  313. package/esm/validator/types.js +128 -16
  314. package/esm/validator/value_types.d.ts +8 -0
  315. package/esm/validator/value_types.d.ts.map +1 -1
  316. package/esm/validator/value_types.js +8 -1
  317. package/package.json +2 -2
  318. package/script/ast/build.d.ts +60 -0
  319. package/script/ast/build.d.ts.map +1 -0
  320. package/script/ast/build.js +521 -0
  321. package/script/ast/equivalence.d.ts +18 -0
  322. package/script/ast/equivalence.d.ts.map +1 -0
  323. package/script/ast/equivalence.js +59 -0
  324. package/script/ast/nodes.d.ts +189 -0
  325. package/script/ast/nodes.d.ts.map +1 -0
  326. package/script/ast/nodes.js +18 -0
  327. package/script/ast/normalize.d.ts +58 -0
  328. package/script/ast/normalize.d.ts.map +1 -0
  329. package/script/ast/normalize.js +200 -0
  330. package/script/ast/render.d.ts +34 -0
  331. package/script/ast/render.d.ts.map +1 -0
  332. package/script/ast/render.js +218 -0
  333. package/script/compiler/constants.d.ts +16 -0
  334. package/script/compiler/constants.d.ts.map +1 -0
  335. package/script/compiler/constants.js +29 -0
  336. package/script/compiler/discipline_classifier.d.ts +55 -0
  337. package/script/compiler/discipline_classifier.d.ts.map +1 -0
  338. package/script/compiler/discipline_classifier.js +196 -0
  339. package/script/compiler/inverses.d.ts +2 -1
  340. package/script/compiler/inverses.d.ts.map +1 -1
  341. package/script/compiler/inverses.js +33 -14
  342. package/script/compiler/manifest.d.ts +59 -0
  343. package/script/compiler/manifest.d.ts.map +1 -0
  344. package/script/compiler/manifest.js +51 -0
  345. package/script/compiler/mod.d.ts +38 -1
  346. package/script/compiler/mod.d.ts.map +1 -1
  347. package/script/compiler/mod.js +206 -54
  348. package/script/compiler/ndjson_writer.d.ts +50 -0
  349. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  350. package/script/compiler/ndjson_writer.js +78 -0
  351. package/script/compiler/schema.d.ts +33 -1
  352. package/script/compiler/schema.d.ts.map +1 -1
  353. package/script/compiler/schema.js +30 -8
  354. package/script/config/markspec.d.ts +5 -0
  355. package/script/config/markspec.d.ts.map +1 -1
  356. package/script/config/markspec.js +17 -2
  357. package/script/config/mod.d.ts.map +1 -1
  358. package/script/config/mod.js +54 -0
  359. package/script/formatter/mod.d.ts +55 -4
  360. package/script/formatter/mod.d.ts.map +1 -1
  361. package/script/formatter/mod.js +426 -46
  362. package/script/formatter/synth_ulid.d.ts +21 -0
  363. package/script/formatter/synth_ulid.d.ts.map +1 -0
  364. package/script/formatter/synth_ulid.js +67 -0
  365. package/script/lexicons/loader.d.ts +35 -0
  366. package/script/lexicons/loader.d.ts.map +1 -0
  367. package/script/lexicons/loader.js +55 -0
  368. package/script/lexicons/mod.d.ts +13 -0
  369. package/script/lexicons/mod.d.ts.map +1 -0
  370. package/script/lexicons/mod.js +17 -0
  371. package/script/lint/glossary.d.ts +45 -0
  372. package/script/lint/glossary.d.ts.map +1 -0
  373. package/script/lint/glossary.js +88 -0
  374. package/script/lint/mod.d.ts +14 -0
  375. package/script/lint/mod.d.ts.map +1 -0
  376. package/script/lint/mod.js +17 -0
  377. package/script/lint/range_util.d.ts +25 -0
  378. package/script/lint/range_util.d.ts.map +1 -0
  379. package/script/lint/range_util.js +53 -0
  380. package/script/lint/rules/ears.d.ts +39 -0
  381. package/script/lint/rules/ears.d.ts.map +1 -0
  382. package/script/lint/rules/ears.js +320 -0
  383. package/script/lint/rules/incose_sentence.d.ts +46 -0
  384. package/script/lint/rules/incose_sentence.d.ts.map +1 -0
  385. package/script/lint/rules/incose_sentence.js +421 -0
  386. package/script/lint/rules/lexicon.d.ts +24 -0
  387. package/script/lint/rules/lexicon.d.ts.map +1 -0
  388. package/script/lint/rules/lexicon.js +240 -0
  389. package/script/lint/rules/modal_sentence.d.ts +46 -0
  390. package/script/lint/rules/modal_sentence.d.ts.map +1 -0
  391. package/script/lint/rules/modal_sentence.js +150 -0
  392. package/script/lint/rules/passive.d.ts +64 -0
  393. package/script/lint/rules/passive.d.ts.map +1 -0
  394. package/script/lint/rules/passive.js +286 -0
  395. package/script/lint/rules/struct.d.ts +17 -0
  396. package/script/lint/rules/struct.d.ts.map +1 -0
  397. package/script/lint/rules/struct.js +59 -0
  398. package/script/lint/rules/suppression.d.ts +54 -0
  399. package/script/lint/rules/suppression.d.ts.map +1 -0
  400. package/script/lint/rules/suppression.js +136 -0
  401. package/script/lint/rules/xref.d.ts +19 -0
  402. package/script/lint/rules/xref.d.ts.map +1 -0
  403. package/script/lint/rules/xref.js +251 -0
  404. package/script/lint/runner.d.ts +59 -0
  405. package/script/lint/runner.d.ts.map +1 -0
  406. package/script/lint/runner.js +157 -0
  407. package/script/lint/score.d.ts +64 -0
  408. package/script/lint/score.d.ts.map +1 -0
  409. package/script/lint/score.js +167 -0
  410. package/script/lint/segmenter.d.ts +32 -0
  411. package/script/lint/segmenter.d.ts.map +1 -0
  412. package/script/lint/segmenter.js +82 -0
  413. package/script/lint/types.d.ts +31 -0
  414. package/script/lint/types.d.ts.map +1 -0
  415. package/script/lint/types.js +10 -0
  416. package/script/lock/canonical_edges.d.ts +31 -0
  417. package/script/lock/canonical_edges.d.ts.map +1 -0
  418. package/script/lock/canonical_edges.js +61 -0
  419. package/script/lock/check.d.ts +24 -0
  420. package/script/lock/check.d.ts.map +1 -0
  421. package/script/lock/check.js +130 -0
  422. package/script/lock/hash.d.ts +12 -0
  423. package/script/lock/hash.d.ts.map +1 -0
  424. package/script/lock/hash.js +36 -0
  425. package/script/lock/mod.d.ts +19 -0
  426. package/script/lock/mod.d.ts.map +1 -0
  427. package/script/lock/mod.js +31 -0
  428. package/script/lock/model.d.ts +81 -0
  429. package/script/lock/model.d.ts.map +1 -0
  430. package/script/lock/model.js +10 -0
  431. package/script/lock/parser.d.ts +26 -0
  432. package/script/lock/parser.d.ts.map +1 -0
  433. package/script/lock/parser.js +198 -0
  434. package/script/lock/resolve.d.ts +142 -0
  435. package/script/lock/resolve.d.ts.map +1 -0
  436. package/script/lock/resolve.js +397 -0
  437. package/script/lock/serializer.d.ts +14 -0
  438. package/script/lock/serializer.d.ts.map +1 -0
  439. package/script/lock/serializer.js +107 -0
  440. package/script/mod.d.ts +28 -8
  441. package/script/mod.d.ts.map +1 -1
  442. package/script/mod.js +129 -32
  443. package/script/model/attributes.d.ts +6 -0
  444. package/script/model/attributes.d.ts.map +1 -1
  445. package/script/model/attributes.js +201 -3
  446. package/script/model/discipline.d.ts +53 -0
  447. package/script/model/discipline.d.ts.map +1 -0
  448. package/script/model/discipline.js +53 -0
  449. package/script/model/discriminating_attr.d.ts +33 -0
  450. package/script/model/discriminating_attr.d.ts.map +1 -0
  451. package/script/model/discriminating_attr.js +77 -0
  452. package/script/model/mod.d.ts +267 -14
  453. package/script/model/mod.d.ts.map +1 -1
  454. package/script/model/mod.js +111 -3
  455. package/script/model/profile.d.ts +102 -27
  456. package/script/model/profile.d.ts.map +1 -1
  457. package/script/model/source_introspection.d.ts +26 -0
  458. package/script/model/source_introspection.d.ts.map +1 -0
  459. package/script/model/source_introspection.js +80 -0
  460. package/script/model/type_hierarchy.d.ts +51 -0
  461. package/script/model/type_hierarchy.d.ts.map +1 -0
  462. package/script/model/type_hierarchy.js +130 -0
  463. package/script/model/uri_scheme_map.d.ts +21 -0
  464. package/script/model/uri_scheme_map.d.ts.map +1 -0
  465. package/script/model/uri_scheme_map.js +69 -0
  466. package/script/parser/attributes.d.ts.map +1 -1
  467. package/script/parser/attributes.js +10 -16
  468. package/script/parser/body_tokens.d.ts +35 -0
  469. package/script/parser/body_tokens.d.ts.map +1 -0
  470. package/script/parser/body_tokens.js +235 -0
  471. package/script/parser/glossary.d.ts +51 -0
  472. package/script/parser/glossary.d.ts.map +1 -0
  473. package/script/parser/glossary.js +224 -0
  474. package/script/parser/grammars.d.ts +5 -3
  475. package/script/parser/grammars.d.ts.map +1 -1
  476. package/script/parser/grammars.js +15 -8
  477. package/script/parser/language_spec.d.ts +55 -0
  478. package/script/parser/language_spec.d.ts.map +1 -0
  479. package/script/parser/language_spec.js +423 -0
  480. package/script/parser/line_map.d.ts +60 -0
  481. package/script/parser/line_map.d.ts.map +1 -0
  482. package/script/parser/line_map.js +44 -0
  483. package/script/parser/markdown.d.ts +9 -0
  484. package/script/parser/markdown.d.ts.map +1 -1
  485. package/script/parser/markdown.js +315 -23
  486. package/script/parser/mod.d.ts +5 -0
  487. package/script/parser/mod.d.ts.map +1 -1
  488. package/script/parser/mod.js +36 -7
  489. package/script/parser/source.d.ts +53 -2
  490. package/script/parser/source.d.ts.map +1 -1
  491. package/script/parser/source.js +159 -69
  492. package/script/parser/translate.d.ts +24 -0
  493. package/script/parser/translate.d.ts.map +1 -0
  494. package/script/parser/translate.js +102 -0
  495. package/script/profile/chain.d.ts +8 -0
  496. package/script/profile/chain.d.ts.map +1 -1
  497. package/script/profile/chain.js +32 -14
  498. package/script/profile/colors.js +1 -1
  499. package/script/profile/default_profile.d.ts +25 -0
  500. package/script/profile/default_profile.d.ts.map +1 -0
  501. package/script/profile/default_profile.js +46 -0
  502. package/script/profile/discipline_mode.d.ts +64 -0
  503. package/script/profile/discipline_mode.d.ts.map +1 -0
  504. package/script/profile/discipline_mode.js +138 -0
  505. package/script/profile/discipline_registry.d.ts +41 -0
  506. package/script/profile/discipline_registry.d.ts.map +1 -0
  507. package/script/profile/discipline_registry.js +70 -0
  508. package/script/profile/introspect.d.ts +135 -0
  509. package/script/profile/introspect.d.ts.map +1 -0
  510. package/script/profile/introspect.js +381 -0
  511. package/script/profile/load.d.ts +3 -1
  512. package/script/profile/load.d.ts.map +1 -1
  513. package/script/profile/load.js +91 -5
  514. package/script/profile/manifest.d.ts.map +1 -1
  515. package/script/profile/manifest.js +511 -89
  516. package/script/profile/merge.d.ts.map +1 -1
  517. package/script/profile/merge.js +251 -39
  518. package/script/profile/mod.d.ts +4 -4
  519. package/script/profile/mod.d.ts.map +1 -1
  520. package/script/profile/mod.js +12 -6
  521. package/script/reporter/mod.js +4 -4
  522. package/script/sync/locked_attributes.d.ts +19 -0
  523. package/script/sync/locked_attributes.d.ts.map +1 -0
  524. package/script/sync/locked_attributes.js +30 -0
  525. package/script/sync/log.d.ts +34 -0
  526. package/script/sync/log.d.ts.map +1 -0
  527. package/script/sync/log.js +52 -0
  528. package/script/sync/mapping.d.ts +66 -0
  529. package/script/sync/mapping.d.ts.map +1 -0
  530. package/script/sync/mapping.js +169 -0
  531. package/script/sync/mod.d.ts +16 -0
  532. package/script/sync/mod.d.ts.map +1 -0
  533. package/script/sync/mod.js +21 -0
  534. package/script/sync/status.d.ts +23 -0
  535. package/script/sync/status.d.ts.map +1 -0
  536. package/script/sync/status.js +24 -0
  537. package/script/typl/ast.d.ts +87 -0
  538. package/script/typl/ast.d.ts.map +1 -0
  539. package/script/typl/ast.js +24 -0
  540. package/script/typl/bridge.d.ts +32 -0
  541. package/script/typl/bridge.d.ts.map +1 -0
  542. package/script/typl/bridge.js +30 -0
  543. package/script/typl/bullet.d.ts +34 -0
  544. package/script/typl/bullet.d.ts.map +1 -0
  545. package/script/typl/bullet.js +47 -0
  546. package/script/typl/diagnostics.d.ts +43 -0
  547. package/script/typl/diagnostics.d.ts.map +1 -0
  548. package/script/typl/diagnostics.js +65 -0
  549. package/script/typl/fence.d.ts +31 -0
  550. package/script/typl/fence.d.ts.map +1 -0
  551. package/script/typl/fence.js +27 -0
  552. package/script/typl/grammar.d.ts +20 -0
  553. package/script/typl/grammar.d.ts.map +1 -0
  554. package/script/typl/grammar.js +474 -0
  555. package/script/typl/inline.d.ts +34 -0
  556. package/script/typl/inline.d.ts.map +1 -0
  557. package/script/typl/inline.js +51 -0
  558. package/script/typl/lexer.d.ts +37 -0
  559. package/script/typl/lexer.d.ts.map +1 -0
  560. package/script/typl/lexer.js +237 -0
  561. package/script/typl/mod.d.ts +23 -0
  562. package/script/typl/mod.d.ts.map +1 -0
  563. package/script/typl/mod.js +29 -0
  564. package/script/typl/registry.d.ts +42 -0
  565. package/script/typl/registry.d.ts.map +1 -0
  566. package/script/typl/registry.js +29 -0
  567. package/script/typl/validator.d.ts +29 -0
  568. package/script/typl/validator.d.ts.map +1 -0
  569. package/script/typl/validator.js +144 -0
  570. package/script/util/fence.d.ts +30 -0
  571. package/script/util/fence.d.ts.map +1 -0
  572. package/script/util/fence.js +44 -0
  573. package/script/util/line_endings.d.ts +33 -0
  574. package/script/util/line_endings.d.ts.map +1 -0
  575. package/script/util/line_endings.js +58 -0
  576. package/script/util/modals.d.ts +29 -0
  577. package/script/util/modals.d.ts.map +1 -0
  578. package/script/util/modals.js +42 -0
  579. package/script/validator/attributes.d.ts +3 -3
  580. package/script/validator/attributes.d.ts.map +1 -1
  581. package/script/validator/attributes.js +1 -18
  582. package/script/validator/body_blocks.d.ts +38 -0
  583. package/script/validator/body_blocks.d.ts.map +1 -0
  584. package/script/validator/body_blocks.js +221 -0
  585. package/script/validator/caption_convention.d.ts +29 -0
  586. package/script/validator/caption_convention.d.ts.map +1 -0
  587. package/script/validator/caption_convention.js +61 -0
  588. package/script/validator/captions.d.ts +22 -0
  589. package/script/validator/captions.d.ts.map +1 -0
  590. package/script/validator/captions.js +140 -0
  591. package/script/validator/component_schemes.d.ts +73 -0
  592. package/script/validator/component_schemes.d.ts.map +1 -0
  593. package/script/validator/component_schemes.js +384 -0
  594. package/script/validator/discipline.d.ts +35 -0
  595. package/script/validator/discipline.d.ts.map +1 -0
  596. package/script/validator/discipline.js +207 -0
  597. package/script/validator/feature_ac.d.ts +28 -0
  598. package/script/validator/feature_ac.d.ts.map +1 -0
  599. package/script/validator/feature_ac.js +105 -0
  600. package/script/validator/listing.d.ts +42 -0
  601. package/script/validator/listing.d.ts.map +1 -0
  602. package/script/validator/listing.js +298 -0
  603. package/script/validator/mod.d.ts +3 -1
  604. package/script/validator/mod.d.ts.map +1 -1
  605. package/script/validator/mod.js +278 -14
  606. package/script/validator/modal_keywords.d.ts +25 -0
  607. package/script/validator/modal_keywords.d.ts.map +1 -0
  608. package/script/validator/modal_keywords.js +57 -0
  609. package/script/validator/pattern.d.ts +15 -8
  610. package/script/validator/pattern.d.ts.map +1 -1
  611. package/script/validator/pattern.js +42 -19
  612. package/script/validator/per_type_attrs.d.ts +29 -0
  613. package/script/validator/per_type_attrs.d.ts.map +1 -0
  614. package/script/validator/per_type_attrs.js +78 -0
  615. package/script/validator/pipeline.d.ts +18 -2
  616. package/script/validator/pipeline.d.ts.map +1 -1
  617. package/script/validator/pipeline.js +78 -22
  618. package/script/validator/trace_types.d.ts +26 -0
  619. package/script/validator/trace_types.d.ts.map +1 -0
  620. package/script/validator/trace_types.js +235 -0
  621. package/script/validator/traceability.d.ts +3 -4
  622. package/script/validator/traceability.d.ts.map +1 -1
  623. package/script/validator/traceability.js +5 -10
  624. package/script/validator/type_resolution.d.ts +67 -0
  625. package/script/validator/type_resolution.d.ts.map +1 -0
  626. package/script/validator/type_resolution.js +168 -0
  627. package/script/validator/types.d.ts +45 -0
  628. package/script/validator/types.d.ts.map +1 -1
  629. package/script/validator/types.js +131 -16
  630. package/script/validator/value_types.d.ts +8 -0
  631. package/script/validator/value_types.d.ts.map +1 -1
  632. 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,16 +21,58 @@ 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 line_endings_js_1 = require("../util/line_endings.js");
26
+ const modals_js_1 = require("../util/modals.js");
27
+ const synth_ulid_js_1 = require("./synth_ulid.js");
28
+ const build_js_1 = require("../ast/build.js");
29
+ const render_js_1 = require("../ast/render.js");
30
+ const normalize_js_1 = require("../ast/normalize.js");
31
+ const equivalence_js_1 = require("../ast/equivalence.js");
21
32
  /**
22
- * Value types that accept CSV on input but must be emitted as multi-line
23
- * per ADR-002 §2.6. `citation` is deliberately excluded because locators
24
- * may contain commas.
33
+ * Decide whether the EARS keyword at `offset` in `line` is at sentence
34
+ * start (return value true). Delegates to the shared implementation in
35
+ * `core/util/modals.ts`; re-exported here for backward compatibility with
36
+ * existing callers and tests that import from `formatter/mod.ts`.
25
37
  */
26
- const CSV_SPLITTABLE_TYPES = new Set([
27
- "id-list",
28
- "tag-list",
29
- "external-id",
30
- ]);
38
+ function isSentenceInitial(line, offset) {
39
+ return (0, modals_js_1.isSentenceInitial)(line, offset);
40
+ }
41
+ /**
42
+ * Normalise modal keywords to canonical case in body prose (§3.4.1):
43
+ *
44
+ * - RFC 2119 (`SHALL`, `SHOULD`, `MAY`, `MUST`, optionally `… NOT`) —
45
+ * always lowercased.
46
+ * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased mid-sentence,
47
+ * preserved sentence-initial.
48
+ *
49
+ * The pass skips:
50
+ *
51
+ * - Fenced code blocks (between paired ``` or ~~~ markers) — code is
52
+ * verbatim per round-trip invariants (spec §5.1).
53
+ * - Lines indented by four or more spaces (or a tab) — conservatively
54
+ * captures indented code blocks and attribute trailers, both of which
55
+ * are not prose.
56
+ *
57
+ * @remarks Not called by `format()` as of SP3 Task 5 — body modal
58
+ * normalization moved to `normalizeBodyAst` in the AST pass (spec-correct
59
+ * verbatim-boundary handling). Retained as an exported symbol because
60
+ * `mod_test.ts` tests it directly and `core/ast/normalize.ts` documents
61
+ * the intentional duplication until a follow-up collapses the two. Do NOT
62
+ * delete — external callers may depend on this export.
63
+ */
64
+ function normalizeModalKeywords(markdown) {
65
+ const lines = markdown.split("\n");
66
+ (0, fence_js_1.walkProseLines)(markdown, (line, i) => {
67
+ // Indented-code / attribute-trailer lines aren't prose either.
68
+ if (/^( {4}|\t)/.test(line))
69
+ return;
70
+ let normalized = line.replace(modals_js_1.RFC2119_MODAL_RE, (m) => m.toLowerCase());
71
+ normalized = normalized.replace(modals_js_1.EARS_KEYWORD_RE, (m, _g1, offset) => isSentenceInitial(normalized, offset) ? m : m.toLowerCase());
72
+ lines[i] = normalized;
73
+ });
74
+ return lines.join("\n");
75
+ }
31
76
  /**
32
77
  * Canonical front-matter key order per ADR-007. Core keys first, then
33
78
  * `metadata` (reserved free-form map), then `extra` (allowlisted ecosystem
@@ -43,29 +88,228 @@ const FRONT_MATTER_CORE_ORDER = [
43
88
  "references",
44
89
  ];
45
90
  /**
46
- * Canonical attribute ordering per the language spec.
91
+ * Canonical trailer ordering per spec §3.3.2 (six-group rule).
47
92
  *
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.
93
+ * Groups, top → bottom:
94
+ * 1. Identity & classification — `Id`, `Type`, `Source`, `Origin`.
95
+ * 2. Reference-shape navigation — `Reference-document`, `Reference-url`.
96
+ * 3. Trace upstream relations — authored trace edges (`Part-of`,
97
+ * `Derived-from`, `Satisfies`, …).
98
+ * 4. Type-specific data — payload attributes per concrete type
99
+ * (`Schema-language`, `License`, `Manufacturer`, …).
100
+ * 5. Universal trailing — `References`, `External-id`, `Labels`,
101
+ * `Supersedes`, `Deprecated`.
102
+ * 6. Profile-declared / unknown attributes — preserved in source order
103
+ * at the bottom (§3.3.6: fmt never deletes a key it doesn't own).
53
104
  *
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.
105
+ * Generated-origin attributes (`Superseded-by`, every inverse from ADR-003
106
+ * §Part 3) are stripped from this list; the formatter rejects them with
107
+ * MSL-A030 when found in source (current code keeps `Superseded-by:` to
108
+ * round-trip historical fixtures — that hardening lands in a later slice).
57
109
  */
58
110
  const CANONICAL_ORDER = [
111
+ // Group 1 — identity & classification
59
112
  "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.
113
+ "Type",
114
+ "Source",
115
+ "Origin",
116
+ // Group 2 — reference-shape navigation
117
+ "Reference-document",
118
+ "Reference-url",
119
+ // Group 3 — trace upstream (authored relations)
120
+ "Part-of",
121
+ "Derived-from",
122
+ "Satisfies",
123
+ "Verifies",
124
+ "Tests",
125
+ "Realizes",
126
+ "Provides",
127
+ "Requires",
128
+ "Depends-on",
129
+ "Caused-by",
130
+ "Mitigated-by",
131
+ "Allocated-to",
132
+ "Affects",
133
+ // Group 4 — type-specific data
134
+ "Schema-language",
135
+ "License",
136
+ "Build-manifest",
137
+ "Package-manager",
138
+ "Manufacturer",
139
+ "Part-number",
140
+ "Datasheet",
141
+ "Bus-protocol",
142
+ "Connector-type",
143
+ "Voltage-level",
144
+ "Signal-direction",
145
+ "Symbol",
146
+ "Language",
147
+ "Footprint",
148
+ "Value",
149
+ "Aliases",
150
+ "See-also",
151
+ // Group 5 — universal trailing
62
152
  "References",
63
- "Labels",
64
153
  "External-id",
154
+ "Labels",
65
155
  "Supersedes",
66
156
  "Superseded-by",
67
157
  "Deprecated",
158
+ // Group 6 — profile-declared / unknown keys are appended in source order
159
+ // after this list by sortAttributes().
68
160
  ];
161
+ /**
162
+ * Post-pass: route each entry's body through the canonical body-AST
163
+ * (the load-bearing §5.2 emission path — SP3 Task 5 cutover).
164
+ *
165
+ * Called on the post-collapse `lines` array (after attribute-block
166
+ * splicing and `collapseBlankLines`). The body modal-keyword §3.4.1
167
+ * pass is NO LONGER applied as a pre-parse whole-body string pass; it
168
+ * is now AST-native via `normalizeBodyAst` here (more spec-correct:
169
+ * the AST pass respects §2.5 verbatim boundaries and per-node
170
+ * sentence-initial context that the whole-body string pass could get
171
+ * wrong inside Code/Math blocks). Re-parses the lines to get entries
172
+ * with correct post-collapse line numbers, then for each entry:
173
+ *
174
+ * 1. Takes `entry.body` — the body string from the parser
175
+ * (indent-stripped, trimmed, attrs split off).
176
+ * 2. Builds the body AST, applies `normalizeBodyAst` (the §3.4.1 /
177
+ * §5.2 canonicalization pass), and emits via `render`.
178
+ * 3. Guards the emit with the formal §5 `astEquivalent` relation:
179
+ * `render`-ing the emitted body and re-building must be AST-equal
180
+ * to the canonical AST. If not, this is an SP3 residual — keep
181
+ * the original body lines untouched and raise a LOUD diagnostic
182
+ * (MSL-F900). This branch is RETAINED for safety; over the
183
+ * idempotence corpus and real project docs it never fires.
184
+ * 4. Reconstructs the body segment in `lines` from the emitted
185
+ * string, preserving the leading/trailing blank-line delimiters
186
+ * that separate the body from the title and attr block.
187
+ *
188
+ * Returns `true` when any entry body was rewritten (so `format()` can
189
+ * keep `changed` accurate for `--check` mode); `false` when every body
190
+ * was already §5.2-canonical.
191
+ *
192
+ * `Entry.body` stays `string`; no other module is affected.
193
+ * `normalizeBodyAst` is FORMATTER-ONLY — the validate/parse path must
194
+ * never call it.
195
+ */
196
+ function emitBodyViaAst(lines, file, diagnostics, cachedEntries) {
197
+ // When the caller supplies pre-parsed entries whose line numbers are still
198
+ // valid in `lines` (i.e., no line-count-changing operations occurred before
199
+ // this call), skip the re-parse entirely — the common hot path for files
200
+ // that are already in canonical form. When the caller passes undefined the
201
+ // re-parse is performed as before.
202
+ let entries;
203
+ if (cachedEntries !== undefined) {
204
+ entries = cachedEntries;
205
+ }
206
+ else {
207
+ // Diagnostics from this re-parse are intentionally discarded: the
208
+ // input is already canonical (post-collapse) output.
209
+ ({ entries } = (0, markdown_js_1.parseMarkdown)(lines.join("\n"), { file }));
210
+ }
211
+ if (entries.length === 0)
212
+ return false;
213
+ let bodyChanged = false;
214
+ // Process bottom-to-top so splices don't shift earlier entry positions.
215
+ const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
216
+ for (const entry of sorted) {
217
+ if (!entry.body.trim())
218
+ continue; // empty or whitespace-only body
219
+ const indent = (entry.location.column - 1) + 2; // marker column (0-based) + 2 spaces = list-item continuation indent
220
+ const indentStr = " ".repeat(indent);
221
+ const titleLineIdx = entry.location.line - 1; // 0-based
222
+ // Locate the body segment in `lines` — between the title line and
223
+ // the attr block start (or item end when there is no attr block).
224
+ const range = findAttributeBlockRange(lines, entry.location.line, indent);
225
+ const bodyStart = titleLineIdx + 1;
226
+ const bodyEnd = range
227
+ ? range.start
228
+ : findItemEnd(lines, titleLineIdx, indent);
229
+ if (bodyEnd <= bodyStart)
230
+ continue; // no body lines to replace
231
+ // Route the body through the canonical AST: build → normalize
232
+ // (§3.4.1 / §5.2) → render. The §5 equivalence relation guards the
233
+ // emit; `render`+`build` is the inverse on canonical input for
234
+ // every body shape under the equivalence gate.
235
+ const ast0 = (0, build_js_1.buildBodyAst)(entry.body);
236
+ const canonical = (0, normalize_js_1.normalizeBodyAst)(ast0);
237
+ const emittedBody = (0, render_js_1.render)(canonical);
238
+ if (!(0, equivalence_js_1.astEquivalent)((0, build_js_1.buildBodyAst)(emittedBody), canonical)) {
239
+ // SP3 residual. The build/render inverse is not yet total over
240
+ // every valid Markdown body construct; for a body where the
241
+ // emitted form does not re-build AST-equivalent to the canonical
242
+ // AST we cannot guarantee a lossless §5.2 re-emission. Keep the
243
+ // original body lines EXACTLY as-is — zero corruption, zero
244
+ // spurious rewrites — and raise a LOUD diagnostic so the residual
245
+ // is visible (it never fires over the idempotence corpus or real
246
+ // project docs). This safe-fallback branch is RETAINED by design;
247
+ // only its criterion changed (byte-identity → astEquivalent) and
248
+ // it now diagnoses instead of silently degrading.
249
+ diagnostics.push({
250
+ code: "MSL-F900",
251
+ severity: "error",
252
+ message: `${entry.displayId}: body not AST-equivalent after ` +
253
+ `canonicalization (SP3 residual — formatter kept the ` +
254
+ `original body)`,
255
+ location: entry.location,
256
+ });
257
+ continue;
258
+ }
259
+ // The emitted body is the §5.2-canonical body and re-builds
260
+ // AST-equivalent to the canonical AST. Splice it back into the
261
+ // document — the AST is the load-bearing emission path.
262
+ // Reconstruct the body segment: re-add the continuation indent to
263
+ // each non-blank line, preserving the blank-line delimiters that
264
+ // separate the body from the title and attr block.
265
+ const rawSegment = lines.slice(bodyStart, bodyEnd);
266
+ // Preserve the blank delimiter lines at the start/end of the segment.
267
+ const leadBlanks = [];
268
+ const trailBlanks = [];
269
+ let si = 0;
270
+ while (si < rawSegment.length && rawSegment[si].trim() === "") {
271
+ leadBlanks.push(rawSegment[si++]);
272
+ }
273
+ let ei = rawSegment.length - 1;
274
+ while (ei >= si && rawSegment[ei].trim() === "") {
275
+ trailBlanks.unshift(rawSegment[ei--]);
276
+ }
277
+ const emittedLines = emittedBody.split("\n").map((l) => l ? `${indentStr}${l}` : l);
278
+ const newSegment = [...leadBlanks, ...emittedLines, ...trailBlanks];
279
+ // `changed` accuracy: only flag a body rewrite when the spliced
280
+ // segment actually differs from the original lines (a §5.2-canonical
281
+ // body splices back byte-identically — a pure no-op).
282
+ if (newSegment.length !== rawSegment.length ||
283
+ newSegment.some((l, i) => l !== rawSegment[i])) {
284
+ bodyChanged = true;
285
+ }
286
+ lines.splice(bodyStart, bodyEnd - bodyStart, ...newSegment);
287
+ }
288
+ return bodyChanged;
289
+ }
290
+ /**
291
+ * UTC `YYYY-MM-DD` for today. Used as the default for the
292
+ * Discipline-frozen: stamper.
293
+ */
294
+ function todayUtc() {
295
+ return new Date().toISOString().slice(0, 10);
296
+ }
297
+ /**
298
+ * If `value` is a bare discipline kind (no `@`), return
299
+ * `<kind> @ <today>`. Otherwise return the value unchanged. Used by
300
+ * `format()` to auto-stamp `Discipline-frozen:` lines per ADR-017 Slice 3.
301
+ *
302
+ * The bare-kind regex deliberately matches the same shape the validator
303
+ * accepts in {@linkcode parseFrozenValue}; anything that doesn't match
304
+ * (e.g. uppercase kinds, already-dated forms) is left alone — the
305
+ * validator handles malformed values via MSL-T026.
306
+ */
307
+ function stampDisciplineFrozen(value, today) {
308
+ if (/^[a-z][a-z0-9-]*\s*$/.test(value)) {
309
+ return `${value.trim()} @ ${today}`;
310
+ }
311
+ return value;
312
+ }
69
313
  /**
70
314
  * Format a Markdown string — normalize attribute blocks,
71
315
  * fix indentation, enforce canonical ordering.
@@ -76,13 +320,30 @@ const CANONICAL_ORDER = [
76
320
  */
77
321
  function format(markdown, options) {
78
322
  const file = options?.file ?? "<unknown>";
323
+ // Detect the source file's line-ending convention up front so we can
324
+ // restore it on write-back. The rest of the formatter operates on a
325
+ // pure-LF buffer; any `\r` characters from a CRLF (or legacy Mac CR)
326
+ // source would otherwise leak into trailers and AST nodes.
327
+ const sourceLineEnding = (0, line_endings_js_1.detectLineEnding)(markdown);
328
+ const normalisedMarkdown = sourceLineEnding === "lf"
329
+ ? markdown
330
+ : (0, line_endings_js_1.normalizeLineEndings)(markdown);
79
331
  // Extract any YAML front matter first so entries are parsed against the
80
332
  // body only (front-matter `---` could be confused with horizontal rules).
81
- const fm = (0, frontmatter_js_1.extractFrontMatter)(markdown, { file });
82
- const body = fm.hadFrontMatter ? fm.markdown : markdown;
333
+ const fm = (0, frontmatter_js_1.extractFrontMatter)(normalisedMarkdown, { file });
334
+ const rawBody = fm.hadFrontMatter ? fm.markdown : normalisedMarkdown;
335
+ // The §3.4.1 modal-keyword pass is NO LONGER a pre-parse whole-body
336
+ // string pass. It is AST-native in `emitBodyViaAst` via
337
+ // `normalizeBodyAst` (more spec-correct: respects §2.5 verbatim
338
+ // boundaries and per-node sentence-initial context). `normalizeModalKeywords`
339
+ // stays exported/defined for other callers/tests but is not invoked here.
340
+ const body = rawBody;
83
341
  const { entries } = (0, markdown_js_1.parseMarkdown)(body, { file });
84
342
  const diagnostics = [...fm.diagnostics];
85
343
  if (entries.length === 0 && !fm.hadFrontMatter) {
344
+ // No entries and no front matter — nothing to format. Returning the
345
+ // original `markdown` preserves the source's exact byte sequence,
346
+ // including its line-ending convention.
86
347
  return { output: markdown, diagnostics, changed: false };
87
348
  }
88
349
  const lines = body.split("\n");
@@ -93,12 +354,37 @@ function format(markdown, options) {
93
354
  for (const entry of sorted) {
94
355
  const indent = (entry.location.column - 1) + 2;
95
356
  let attrs = [...entry.rawAttributes];
357
+ // Title-line bullet canonicalisation per spec §3.2: rewrite `*`
358
+ // or `+` to `-`. The list-item position from the parser is the
359
+ // line carrying the bullet marker; we only touch the marker
360
+ // character itself, leaving the rest of the title alone.
361
+ const titleLineIdx = entry.location.line - 1;
362
+ if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
363
+ const titleLine = lines[titleLineIdx];
364
+ const markerCol = entry.location.column - 1;
365
+ const markerChar = titleLine.charAt(markerCol);
366
+ if (markerChar === "*" || markerChar === "+") {
367
+ lines[titleLineIdx] = titleLine.slice(0, markerCol) +
368
+ "-" + titleLine.slice(markerCol + 1);
369
+ changed = true;
370
+ }
371
+ }
96
372
  // Assign a bare ULID `Id:` to identified entries that carry no
97
373
  // identity yet. Referenced entries are left alone — their `Id:` is a
98
374
  // URI that must be author-provided.
375
+ //
376
+ // For `Origin: synthesized` entries (spec §3.5), derive the ULID
377
+ // deterministically from `Source:` so re-running `fmt` on the same
378
+ // input reproduces the same identity. Falls back to fresh random
379
+ // when `Source:` is missing — synthesizing without a source pointer
380
+ // makes no sense, but the formatter never fails a stamp.
99
381
  const hasIdentity = attrs.some((a) => a.key === mod_js_1.IDENTITY_KEY);
100
- if (!hasIdentity && entry.shape === "identified") {
101
- const newId = genUlid();
382
+ if (!hasIdentity && entry.shape === "Authored") {
383
+ const origin = attrs.find((a) => a.key === "Origin")?.value.trim();
384
+ const source = attrs.find((a) => a.key === "Source")?.value.trim();
385
+ const newId = origin === "synthesized" && source && source.length > 0
386
+ ? (0, synth_ulid_js_1.synthesizedUlid)(source)
387
+ : genUlid();
102
388
  attrs = [{ key: mod_js_1.IDENTITY_KEY, value: newId }, ...attrs];
103
389
  diagnostics.push({
104
390
  code: "MSL-F001",
@@ -107,6 +393,31 @@ function format(markdown, options) {
107
393
  location: entry.location,
108
394
  });
109
395
  }
396
+ // Discipline-frozen: date stamping (ADR-017 Slice 3). Walk attrs;
397
+ // if any Discipline-frozen: value is a bare kind, rewrite it with
398
+ // today's UTC date. Idempotent on already-dated values.
399
+ const todayFn = options?.today ?? todayUtc;
400
+ const todayStr = todayFn();
401
+ let stampedCount = 0;
402
+ attrs = attrs.map((a) => {
403
+ if (a.key !== "Discipline-frozen")
404
+ return a;
405
+ const newValue = stampDisciplineFrozen(a.value, todayStr);
406
+ if (newValue !== a.value) {
407
+ stampedCount++;
408
+ return { key: a.key, value: newValue };
409
+ }
410
+ return a;
411
+ });
412
+ if (stampedCount > 0) {
413
+ diagnostics.push({
414
+ code: "MSL-F001",
415
+ severity: "info",
416
+ message: `stamped Discipline-frozen: with ${todayStr} on ${entry.displayId}`,
417
+ location: entry.location,
418
+ });
419
+ changed = true;
420
+ }
110
421
  if (attrs.length === 0)
111
422
  continue;
112
423
  const normalized = sortAttributes(expandCsvValues(attrs));
@@ -128,15 +439,41 @@ function format(markdown, options) {
128
439
  changed = true;
129
440
  }
130
441
  }
131
- const formattedBody = lines.join("\n");
442
+ // Spec §3.4.3 / §5.2 — collapse consecutive blank lines to one.
443
+ // Runs after entry-block splicing so the in-progress line indices
444
+ // stay aligned with parser-reported positions. Operates inside
445
+ // fenced code regions only outside-code; verbatim regions keep
446
+ // their blank-line counts.
447
+ const collapsedLines = collapseBlankLines(lines);
448
+ if (collapsedLines.length !== lines.length)
449
+ changed = true;
450
+ // SP3 §5.2-via-AST cutover: route each entry's body through the
451
+ // canonical AST — build → normalizeBodyAst (§3.4.1 / §5.2) → render,
452
+ // guarded by the formal §5 `astEquivalent` relation. This is the
453
+ // load-bearing body-emission path AND the body modal-keyword pass
454
+ // (the pre-parse whole-body string pass was removed above). It
455
+ // returns whether any body was rewritten so `changed` stays accurate
456
+ // for `--check`.
457
+ //
458
+ // D6 optimization: when neither attribute-block splicing nor blank-line
459
+ // collapse altered any line positions, the first-parse entry line numbers
460
+ // are still valid in `collapsedLines` — pass the cached entries so
461
+ // emitBodyViaAst skips its re-parse (the hot path for already-formatted
462
+ // files). When `changed` is true, any splicing or collapse may have
463
+ // shifted positions, so pass undefined to trigger the normal re-parse.
464
+ if (emitBodyViaAst(collapsedLines, file, diagnostics, changed ? undefined : entries))
465
+ changed = true;
466
+ const formattedBody = collapsedLines.join("\n");
132
467
  if (fm.hadFrontMatter) {
133
468
  const canonicalFm = renderFrontMatter(fm.attributes);
134
- const output = canonicalFm + formattedBody;
135
- if (output !== markdown)
469
+ const outputLf = canonicalFm + formattedBody;
470
+ if (outputLf !== normalisedMarkdown)
136
471
  changed = true;
472
+ const output = (0, line_endings_js_1.applyLineEnding)(outputLf, sourceLineEnding);
137
473
  return { output, diagnostics, changed };
138
474
  }
139
- return { output: formattedBody, diagnostics, changed };
475
+ const output = (0, line_endings_js_1.applyLineEnding)(formattedBody, sourceLineEnding);
476
+ return { output, diagnostics, changed };
140
477
  }
141
478
  /**
142
479
  * Render {@linkcode DocumentAttributes} as a canonical YAML front matter
@@ -164,6 +501,36 @@ function renderFrontMatter(attrs) {
164
501
  const yaml = (0, yaml_1.stringify)(ordered).trimEnd();
165
502
  return `---\n${yaml}\n---\n\n`;
166
503
  }
504
+ /**
505
+ * Collapse consecutive blank lines to a single blank line per spec
506
+ * §3.4.3 (caption boundary) / §5.2 (general body rule). Fenced code
507
+ * regions are preserved verbatim — blank-line counts inside fenced
508
+ * blocks are author intent, not noise.
509
+ */
510
+ function collapseBlankLines(lines) {
511
+ const out = [];
512
+ let inFence = false;
513
+ let prevBlank = false;
514
+ for (const line of lines) {
515
+ if (fence_js_1.FENCE_RE.test(line)) {
516
+ out.push(line);
517
+ inFence = !inFence;
518
+ prevBlank = false;
519
+ continue;
520
+ }
521
+ if (inFence) {
522
+ out.push(line);
523
+ prevBlank = false;
524
+ continue;
525
+ }
526
+ const isBlank = line.trim() === "";
527
+ if (isBlank && prevBlank)
528
+ continue;
529
+ out.push(line);
530
+ prevBlank = isBlank;
531
+ }
532
+ return out;
533
+ }
167
534
  /**
168
535
  * Expand CSV values on repeatable-type attributes into one entry per value
169
536
  * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
@@ -174,7 +541,7 @@ function expandCsvValues(attrs) {
174
541
  const result = [];
175
542
  for (const attr of attrs) {
176
543
  const spec = (0, mod_js_1.attributeSpec)(attr.key);
177
- if (spec && CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
544
+ if (spec && mod_js_1.CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
178
545
  const values = attr.value
179
546
  .split(",")
180
547
  .map((s) => s.trim())
@@ -190,43 +557,56 @@ function expandCsvValues(attrs) {
190
557
  return result;
191
558
  }
192
559
  /**
193
- * Sort attributes to canonical order per the language spec.
560
+ * Canonicalise a trailer key to TitleCase-Hyphenated per spec §3.3.4.
561
+ * First character of the key uppercase, every other character
562
+ * lowercase; hyphens preserved. Examples (from the spec):
563
+ *
564
+ * `Id`, `Derived-from`, `Reference-url`, `Bus-protocol`.
565
+ *
566
+ * Inputs like `ID`, `BUS-PROTOCOL`, `reference-URL`, `Derived-From`
567
+ * all canonicalise to the spec form regardless of casing in source.
568
+ */
569
+ function canonicalizeKey(key) {
570
+ if (key.length === 0)
571
+ return key;
572
+ return key[0].toUpperCase() + key.slice(1).toLowerCase();
573
+ }
574
+ /**
575
+ * Sort attributes to canonical trailer order per spec §3.3.2 and
576
+ * re-case each key per spec §3.3.4.
194
577
  *
195
- * `Id:` first, then profile-declared/unknown keys in source order, then
196
- * universal attributes (References / Labels / External-id / Supersedes /
197
- * Superseded-by / Deprecated).
578
+ * Known core keys appear in their {@linkcode CANONICAL_ORDER} slot
579
+ * (lookup is case-insensitive via {@linkcode canonicalizeKey}).
580
+ * Unknown / profile-declared keys (group 6) are appended at the end
581
+ * in source order — `fmt` never deletes a key it doesn't own
582
+ * (§3.3.6). Every emitted attribute carries the canonical key form.
198
583
  */
199
584
  function sortAttributes(attributes) {
200
585
  const known = new Array(CANONICAL_ORDER.length);
201
586
  const unknown = [];
202
587
  for (const attr of attributes) {
203
- const idx = CANONICAL_ORDER.indexOf(attr.key);
588
+ const canonical = canonicalizeKey(attr.key);
589
+ const recased = canonical === attr.key
590
+ ? attr
591
+ : { ...attr, key: canonical };
592
+ const idx = CANONICAL_ORDER.indexOf(canonical);
204
593
  if (idx >= 0) {
205
594
  // Preserve duplicates — keep all occurrences of the same key.
206
595
  if (!known[idx])
207
596
  known[idx] = [];
208
- known[idx].push(attr);
597
+ known[idx].push(recased);
209
598
  }
210
599
  else {
211
- unknown.push(attr);
600
+ unknown.push(recased);
212
601
  }
213
602
  }
214
603
  const result = [];
215
- const labelsIdx = CANONICAL_ORDER.indexOf("Labels");
216
- const hasLabels = known[labelsIdx] != null;
217
604
  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
605
  if (known[i] != null) {
223
606
  result.push(...known[i]);
224
607
  }
225
608
  }
226
- // If Labels was not present, unknown attrs go at the end.
227
- if (!hasLabels) {
228
- result.push(...unknown);
229
- }
609
+ result.push(...unknown);
230
610
  return result;
231
611
  }
232
612
  /**
@@ -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"}