@driftsys/markspec 0.4.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 (319) 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 +49 -4
  34. package/esm/formatter/mod.d.ts.map +1 -1
  35. package/esm/formatter/mod.js +362 -33
  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 +19 -6
  58. package/esm/mod.d.ts.map +1 -1
  59. package/esm/mod.js +14 -3
  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 +98 -3
  66. package/esm/model/mod.d.ts.map +1 -1
  67. package/esm/model/mod.js +57 -2
  68. package/esm/model/profile.d.ts +33 -27
  69. package/esm/model/profile.d.ts.map +1 -1
  70. package/esm/model/source_introspection.d.ts +26 -0
  71. package/esm/model/source_introspection.d.ts.map +1 -0
  72. package/esm/model/source_introspection.js +77 -0
  73. package/esm/model/type_hierarchy.d.ts +51 -0
  74. package/esm/model/type_hierarchy.d.ts.map +1 -0
  75. package/esm/model/type_hierarchy.js +126 -0
  76. package/esm/model/uri_scheme_map.d.ts +21 -0
  77. package/esm/model/uri_scheme_map.d.ts.map +1 -0
  78. package/esm/model/uri_scheme_map.js +66 -0
  79. package/esm/parser/attributes.d.ts.map +1 -1
  80. package/esm/parser/attributes.js +9 -6
  81. package/esm/parser/entity_refs.d.ts +53 -0
  82. package/esm/parser/entity_refs.d.ts.map +1 -0
  83. package/esm/parser/entity_refs.js +151 -0
  84. package/esm/parser/glossary.d.ts +43 -0
  85. package/esm/parser/glossary.d.ts.map +1 -0
  86. package/esm/parser/glossary.js +217 -0
  87. package/esm/parser/markdown.d.ts.map +1 -1
  88. package/esm/parser/markdown.js +223 -7
  89. package/esm/parser/mod.d.ts +1 -0
  90. package/esm/parser/mod.d.ts.map +1 -1
  91. package/esm/parser/mod.js +1 -0
  92. package/esm/parser/source.d.ts +20 -0
  93. package/esm/parser/source.d.ts.map +1 -1
  94. package/esm/parser/source.js +3 -3
  95. package/esm/profile/chain.js +3 -13
  96. package/esm/profile/colors.js +1 -1
  97. package/esm/profile/introspect.d.ts +135 -0
  98. package/esm/profile/introspect.d.ts.map +1 -0
  99. package/esm/profile/introspect.js +378 -0
  100. package/esm/profile/load.d.ts.map +1 -1
  101. package/esm/profile/load.js +67 -0
  102. package/esm/profile/manifest.d.ts.map +1 -1
  103. package/esm/profile/manifest.js +277 -88
  104. package/esm/profile/merge.js +139 -39
  105. package/esm/profile/mod.d.ts +2 -4
  106. package/esm/profile/mod.d.ts.map +1 -1
  107. package/esm/profile/mod.js +5 -2
  108. package/esm/reporter/mod.js +4 -4
  109. package/esm/util/fence.d.ts +30 -0
  110. package/esm/util/fence.d.ts.map +1 -0
  111. package/esm/util/fence.js +40 -0
  112. package/esm/validator/attributes.d.ts +3 -3
  113. package/esm/validator/attributes.d.ts.map +1 -1
  114. package/esm/validator/attributes.js +1 -18
  115. package/esm/validator/body_blocks.d.ts +38 -0
  116. package/esm/validator/body_blocks.d.ts.map +1 -0
  117. package/esm/validator/body_blocks.js +218 -0
  118. package/esm/validator/caption_convention.d.ts +29 -0
  119. package/esm/validator/caption_convention.d.ts.map +1 -0
  120. package/esm/validator/caption_convention.js +58 -0
  121. package/esm/validator/captions.d.ts +22 -0
  122. package/esm/validator/captions.d.ts.map +1 -0
  123. package/esm/validator/captions.js +137 -0
  124. package/esm/validator/component_schemes.d.ts +73 -0
  125. package/esm/validator/component_schemes.d.ts.map +1 -0
  126. package/esm/validator/component_schemes.js +375 -0
  127. package/esm/validator/feature_ac.d.ts +28 -0
  128. package/esm/validator/feature_ac.d.ts.map +1 -0
  129. package/esm/validator/feature_ac.js +102 -0
  130. package/esm/validator/listing.d.ts +42 -0
  131. package/esm/validator/listing.d.ts.map +1 -0
  132. package/esm/validator/listing.js +295 -0
  133. package/esm/validator/mod.d.ts +2 -0
  134. package/esm/validator/mod.d.ts.map +1 -1
  135. package/esm/validator/mod.js +253 -12
  136. package/esm/validator/modal_keywords.d.ts +23 -0
  137. package/esm/validator/modal_keywords.d.ts.map +1 -0
  138. package/esm/validator/modal_keywords.js +137 -0
  139. package/esm/validator/per_type_attrs.d.ts +29 -0
  140. package/esm/validator/per_type_attrs.d.ts.map +1 -0
  141. package/esm/validator/per_type_attrs.js +75 -0
  142. package/esm/validator/pipeline.d.ts +7 -2
  143. package/esm/validator/pipeline.d.ts.map +1 -1
  144. package/esm/validator/pipeline.js +40 -7
  145. package/esm/validator/trace_types.d.ts +26 -0
  146. package/esm/validator/trace_types.d.ts.map +1 -0
  147. package/esm/validator/trace_types.js +232 -0
  148. package/esm/validator/traceability.d.ts +3 -4
  149. package/esm/validator/traceability.d.ts.map +1 -1
  150. package/esm/validator/traceability.js +5 -10
  151. package/esm/validator/type_resolution.d.ts +67 -0
  152. package/esm/validator/type_resolution.d.ts.map +1 -0
  153. package/esm/validator/type_resolution.js +140 -0
  154. package/esm/validator/types.d.ts +45 -0
  155. package/esm/validator/types.d.ts.map +1 -1
  156. package/esm/validator/types.js +128 -16
  157. package/esm/validator/value_types.d.ts +8 -0
  158. package/esm/validator/value_types.d.ts.map +1 -1
  159. package/esm/validator/value_types.js +8 -1
  160. package/package.json +1 -1
  161. package/script/ast/build.d.ts +70 -0
  162. package/script/ast/build.d.ts.map +1 -0
  163. package/script/ast/build.js +610 -0
  164. package/script/ast/equivalence.d.ts +18 -0
  165. package/script/ast/equivalence.d.ts.map +1 -0
  166. package/script/ast/equivalence.js +59 -0
  167. package/script/ast/nodes.d.ts +221 -0
  168. package/script/ast/nodes.d.ts.map +1 -0
  169. package/script/ast/nodes.js +13 -0
  170. package/script/ast/normalize.d.ts +67 -0
  171. package/script/ast/normalize.d.ts.map +1 -0
  172. package/script/ast/normalize.js +258 -0
  173. package/script/ast/render.d.ts +34 -0
  174. package/script/ast/render.d.ts.map +1 -0
  175. package/script/ast/render.js +218 -0
  176. package/script/compiler/inverses.d.ts +2 -8
  177. package/script/compiler/inverses.d.ts.map +1 -1
  178. package/script/compiler/inverses.js +50 -14
  179. package/script/compiler/manifest.d.ts +59 -0
  180. package/script/compiler/manifest.d.ts.map +1 -0
  181. package/script/compiler/manifest.js +51 -0
  182. package/script/compiler/mod.d.ts +9 -1
  183. package/script/compiler/mod.d.ts.map +1 -1
  184. package/script/compiler/mod.js +21 -2
  185. package/script/compiler/ndjson_writer.d.ts +50 -0
  186. package/script/compiler/ndjson_writer.d.ts.map +1 -0
  187. package/script/compiler/ndjson_writer.js +78 -0
  188. package/script/compiler/schema.d.ts +18 -1
  189. package/script/compiler/schema.d.ts.map +1 -1
  190. package/script/compiler/schema.js +18 -8
  191. package/script/config/mod.d.ts.map +1 -1
  192. package/script/config/mod.js +54 -0
  193. package/script/formatter/mod.d.ts +49 -4
  194. package/script/formatter/mod.d.ts.map +1 -1
  195. package/script/formatter/mod.js +365 -33
  196. package/script/formatter/synth_ulid.d.ts +21 -0
  197. package/script/formatter/synth_ulid.d.ts.map +1 -0
  198. package/script/formatter/synth_ulid.js +67 -0
  199. package/script/lint/mod.d.ts +10 -0
  200. package/script/lint/mod.d.ts.map +1 -0
  201. package/script/lint/mod.js +12 -0
  202. package/script/lint/rules/lexicon.d.ts +24 -0
  203. package/script/lint/rules/lexicon.d.ts.map +1 -0
  204. package/script/lint/rules/lexicon.js +240 -0
  205. package/script/lint/rules/struct.d.ts +17 -0
  206. package/script/lint/rules/struct.d.ts.map +1 -0
  207. package/script/lint/rules/struct.js +59 -0
  208. package/script/lint/rules/suppression.d.ts +19 -0
  209. package/script/lint/rules/suppression.d.ts.map +1 -0
  210. package/script/lint/rules/suppression.js +80 -0
  211. package/script/lint/runner.d.ts +39 -0
  212. package/script/lint/runner.d.ts.map +1 -0
  213. package/script/lint/runner.js +116 -0
  214. package/script/lint/types.d.ts +19 -0
  215. package/script/lint/types.d.ts.map +1 -0
  216. package/script/lint/types.js +10 -0
  217. package/script/mod.d.ts +19 -6
  218. package/script/mod.d.ts.map +1 -1
  219. package/script/mod.js +56 -32
  220. package/script/model/attributes.d.ts.map +1 -1
  221. package/script/model/attributes.js +163 -2
  222. package/script/model/discriminating_attr.d.ts +33 -0
  223. package/script/model/discriminating_attr.d.ts.map +1 -0
  224. package/script/model/discriminating_attr.js +77 -0
  225. package/script/model/mod.d.ts +98 -3
  226. package/script/model/mod.d.ts.map +1 -1
  227. package/script/model/mod.js +64 -3
  228. package/script/model/profile.d.ts +33 -27
  229. package/script/model/profile.d.ts.map +1 -1
  230. package/script/model/source_introspection.d.ts +26 -0
  231. package/script/model/source_introspection.d.ts.map +1 -0
  232. package/script/model/source_introspection.js +80 -0
  233. package/script/model/type_hierarchy.d.ts +51 -0
  234. package/script/model/type_hierarchy.d.ts.map +1 -0
  235. package/script/model/type_hierarchy.js +130 -0
  236. package/script/model/uri_scheme_map.d.ts +21 -0
  237. package/script/model/uri_scheme_map.d.ts.map +1 -0
  238. package/script/model/uri_scheme_map.js +69 -0
  239. package/script/parser/attributes.d.ts.map +1 -1
  240. package/script/parser/attributes.js +9 -6
  241. package/script/parser/entity_refs.d.ts +53 -0
  242. package/script/parser/entity_refs.d.ts.map +1 -0
  243. package/script/parser/entity_refs.js +155 -0
  244. package/script/parser/glossary.d.ts +43 -0
  245. package/script/parser/glossary.d.ts.map +1 -0
  246. package/script/parser/glossary.js +221 -0
  247. package/script/parser/markdown.d.ts.map +1 -1
  248. package/script/parser/markdown.js +222 -6
  249. package/script/parser/mod.d.ts +1 -0
  250. package/script/parser/mod.d.ts.map +1 -1
  251. package/script/parser/mod.js +5 -1
  252. package/script/parser/source.d.ts +20 -0
  253. package/script/parser/source.d.ts.map +1 -1
  254. package/script/parser/source.js +3 -0
  255. package/script/profile/chain.js +3 -13
  256. package/script/profile/colors.js +1 -1
  257. package/script/profile/introspect.d.ts +135 -0
  258. package/script/profile/introspect.d.ts.map +1 -0
  259. package/script/profile/introspect.js +381 -0
  260. package/script/profile/load.d.ts.map +1 -1
  261. package/script/profile/load.js +67 -0
  262. package/script/profile/manifest.d.ts.map +1 -1
  263. package/script/profile/manifest.js +276 -87
  264. package/script/profile/merge.js +139 -39
  265. package/script/profile/mod.d.ts +2 -4
  266. package/script/profile/mod.d.ts.map +1 -1
  267. package/script/profile/mod.js +7 -6
  268. package/script/reporter/mod.js +4 -4
  269. package/script/util/fence.d.ts +30 -0
  270. package/script/util/fence.d.ts.map +1 -0
  271. package/script/util/fence.js +44 -0
  272. package/script/validator/attributes.d.ts +3 -3
  273. package/script/validator/attributes.d.ts.map +1 -1
  274. package/script/validator/attributes.js +1 -18
  275. package/script/validator/body_blocks.d.ts +38 -0
  276. package/script/validator/body_blocks.d.ts.map +1 -0
  277. package/script/validator/body_blocks.js +221 -0
  278. package/script/validator/caption_convention.d.ts +29 -0
  279. package/script/validator/caption_convention.d.ts.map +1 -0
  280. package/script/validator/caption_convention.js +61 -0
  281. package/script/validator/captions.d.ts +22 -0
  282. package/script/validator/captions.d.ts.map +1 -0
  283. package/script/validator/captions.js +140 -0
  284. package/script/validator/component_schemes.d.ts +73 -0
  285. package/script/validator/component_schemes.d.ts.map +1 -0
  286. package/script/validator/component_schemes.js +384 -0
  287. package/script/validator/feature_ac.d.ts +28 -0
  288. package/script/validator/feature_ac.d.ts.map +1 -0
  289. package/script/validator/feature_ac.js +105 -0
  290. package/script/validator/listing.d.ts +42 -0
  291. package/script/validator/listing.d.ts.map +1 -0
  292. package/script/validator/listing.js +298 -0
  293. package/script/validator/mod.d.ts +2 -0
  294. package/script/validator/mod.d.ts.map +1 -1
  295. package/script/validator/mod.js +256 -14
  296. package/script/validator/modal_keywords.d.ts +23 -0
  297. package/script/validator/modal_keywords.d.ts.map +1 -0
  298. package/script/validator/modal_keywords.js +140 -0
  299. package/script/validator/per_type_attrs.d.ts +29 -0
  300. package/script/validator/per_type_attrs.d.ts.map +1 -0
  301. package/script/validator/per_type_attrs.js +78 -0
  302. package/script/validator/pipeline.d.ts +7 -2
  303. package/script/validator/pipeline.d.ts.map +1 -1
  304. package/script/validator/pipeline.js +39 -6
  305. package/script/validator/trace_types.d.ts +26 -0
  306. package/script/validator/trace_types.d.ts.map +1 -0
  307. package/script/validator/trace_types.js +235 -0
  308. package/script/validator/traceability.d.ts +3 -4
  309. package/script/validator/traceability.d.ts.map +1 -1
  310. package/script/validator/traceability.js +5 -10
  311. package/script/validator/type_resolution.d.ts +67 -0
  312. package/script/validator/type_resolution.d.ts.map +1 -0
  313. package/script/validator/type_resolution.js +146 -0
  314. package/script/validator/types.d.ts +45 -0
  315. package/script/validator/types.d.ts.map +1 -1
  316. package/script/validator/types.js +131 -16
  317. package/script/validator/value_types.d.ts +8 -0
  318. package/script/validator/value_types.d.ts.map +1 -1
  319. package/script/validator/value_types.js +10 -2
@@ -0,0 +1,295 @@
1
+ /**
2
+ * @module validator/listing
3
+ *
4
+ * Listing-directive validator — MSL-L010 through MSL-L050.
5
+ *
6
+ * Validates four concern areas:
7
+ *
8
+ * 1. Directive placement / conflict (§2.3): L010, L011, L012
9
+ * 2. Glossary heading-shape grammar (§4.2): L020–L024 (delegated to
10
+ * `validateGlossaryStructure`)
11
+ * 3. Component Id-scheme parsers (§5): L030–L037 (via `parseComponentScheme`)
12
+ * 4. Per-directive content (§6): L040, L041, L042, L043, L050
13
+ *
14
+ * Called from the validate CLI command once per invocation, receiving one
15
+ * {@linkcode ListingFileContext} per validated file. The listing validator
16
+ * is separate from `runPipeline` because it requires per-file context
17
+ * (file name, raw content, directives) that the flat Entry-list pipeline
18
+ * does not carry.
19
+ */
20
+ import { basename } from "@std/path";
21
+ import { validateGlossaryStructure } from "../parser/glossary.js";
22
+ import { isSchemeQualifiedUri, parseComponentScheme, } from "./component_schemes.js";
23
+ // ---------------------------------------------------------------------------
24
+ // Component-family and Unit-family sets
25
+ // ---------------------------------------------------------------------------
26
+ /** Core Component-family type names per ADR-003 §Part 2 / spec §6.3. */
27
+ const COMPONENT_FAMILY = new Set([
28
+ "Component",
29
+ "SoftwareComponent",
30
+ "HardwareComponent",
31
+ "SoftwareInterface",
32
+ "HardwareInterface",
33
+ ]);
34
+ /** Core Unit-family type names per ADR-003 §Part 2. */
35
+ const UNIT_FAMILY = new Set([
36
+ "Unit",
37
+ "SoftwareUnit",
38
+ "HardwareUnit",
39
+ ]);
40
+ // ---------------------------------------------------------------------------
41
+ // Filename-trigger detection
42
+ // ---------------------------------------------------------------------------
43
+ /** Listing kind implied by a file's basename, or null if not a listing file. */
44
+ function filenameKind(file) {
45
+ const base = basename(file).toLowerCase().replace(/\.[^.]+$/, "");
46
+ if (base === "references")
47
+ return "references";
48
+ if (base === "glossary")
49
+ return "glossary";
50
+ if (base === "components")
51
+ return "components";
52
+ return null;
53
+ }
54
+ /** Listing kind named by a directive, or null for non-listing directives. */
55
+ function directiveKind(name) {
56
+ if (name === "references")
57
+ return "references";
58
+ if (name === "glossary")
59
+ return "glossary";
60
+ if (name === "components")
61
+ return "components";
62
+ return null;
63
+ }
64
+ // ---------------------------------------------------------------------------
65
+ // Type-attribute helper
66
+ // ---------------------------------------------------------------------------
67
+ /** Extract the raw `Type:` attribute value from an entry, or null. */
68
+ function rawType(entry) {
69
+ for (const attr of entry.rawAttributes) {
70
+ if (attr.key === "Type")
71
+ return attr.value.trim();
72
+ }
73
+ return null;
74
+ }
75
+ // ---------------------------------------------------------------------------
76
+ // Per-file validation
77
+ // ---------------------------------------------------------------------------
78
+ function validateFile(ctx) {
79
+ const { file, content, entries, directives } = ctx;
80
+ const diagnostics = [];
81
+ // -------------------------------------------------------------------------
82
+ // Phase 1: directive placement / conflict detection (§2.3)
83
+ // -------------------------------------------------------------------------
84
+ const fileKind = filenameKind(file);
85
+ const listingDirectives = directives.filter((d) => directiveKind(d.name) !== null);
86
+ let resolvedKind = fileKind;
87
+ if (listingDirectives.length >= 2) {
88
+ // MSL-L012: multiple explicit listing directives in one file.
89
+ diagnostics.push({
90
+ code: "MSL-L012",
91
+ severity: "error",
92
+ message: `${file}:${listingDirectives[1].location.line}: ` +
93
+ `multiple listing directives in one file ` +
94
+ `('${listingDirectives[0].name}' and '${listingDirectives[1].name}') — ` +
95
+ `a listing file carries exactly one directive (spec §2.3)`,
96
+ location: listingDirectives[1].location,
97
+ });
98
+ // Use the first directive as the resolved kind so downstream checks run.
99
+ resolvedKind = directiveKind(listingDirectives[0].name);
100
+ }
101
+ else if (listingDirectives.length === 1) {
102
+ const explicitKind = directiveKind(listingDirectives[0].name);
103
+ if (fileKind !== null) {
104
+ if (fileKind === explicitKind) {
105
+ // MSL-L010: redundant explicit directive (matches filename trigger).
106
+ diagnostics.push({
107
+ code: "MSL-L010",
108
+ severity: "info",
109
+ message: `${file}:${listingDirectives[0].location.line}: ` +
110
+ `redundant directive '<!-- markspec:${explicitKind} -->' — ` +
111
+ `the filename '${basename(file)}' already triggers this listing ` +
112
+ `(spec §2.1)`,
113
+ location: listingDirectives[0].location,
114
+ });
115
+ resolvedKind = explicitKind;
116
+ }
117
+ else {
118
+ // MSL-L011: explicit directive conflicts with filename trigger.
119
+ diagnostics.push({
120
+ code: "MSL-L011",
121
+ severity: "error",
122
+ message: `${file}:${listingDirectives[0].location.line}: ` +
123
+ `directive 'markspec:${explicitKind}' conflicts with filename ` +
124
+ `trigger '${fileKind}' — remove the directive or rename the file ` +
125
+ `(spec §2.3)`,
126
+ location: listingDirectives[0].location,
127
+ });
128
+ // Conflict is unresolved; use the filename trigger.
129
+ resolvedKind = fileKind;
130
+ }
131
+ }
132
+ else {
133
+ resolvedKind = explicitKind;
134
+ }
135
+ }
136
+ // No listing kind → not a listing file, nothing more to validate.
137
+ if (resolvedKind === null)
138
+ return diagnostics;
139
+ // -------------------------------------------------------------------------
140
+ // Phase 2: Glossary heading-shape validation (§4.2)
141
+ // -------------------------------------------------------------------------
142
+ let glossaryTermCount = 0;
143
+ if (resolvedKind === "glossary") {
144
+ const glossaryResult = validateGlossaryStructure(content, { file });
145
+ diagnostics.push(...glossaryResult.diagnostics);
146
+ glossaryTermCount = glossaryResult.termCount;
147
+ // MSL-L042: entry blocks must not appear in a glossary file.
148
+ for (const entry of entries) {
149
+ diagnostics.push({
150
+ code: "MSL-L042",
151
+ severity: "error",
152
+ message: `${file}:${entry.location.line}: entry block ` +
153
+ `'[${entry.displayId}]' in a glossary listing — ` +
154
+ `the glossary shape uses headings, not entry blocks (spec §6.2)`,
155
+ location: entry.location,
156
+ });
157
+ }
158
+ }
159
+ // -------------------------------------------------------------------------
160
+ // Phase 3 & 4: per-entry validation for references and components
161
+ // -------------------------------------------------------------------------
162
+ for (const entry of entries) {
163
+ if (resolvedKind === "references") {
164
+ validateReferencesEntry(entry, file, diagnostics);
165
+ }
166
+ else if (resolvedKind === "components") {
167
+ validateComponentsEntry(entry, file, diagnostics);
168
+ }
169
+ }
170
+ // -------------------------------------------------------------------------
171
+ // Phase 4: MSL-L050 — empty listing
172
+ // -------------------------------------------------------------------------
173
+ const isEmpty = resolvedKind === "glossary"
174
+ ? glossaryTermCount === 0
175
+ : entries.length === 0;
176
+ if (isEmpty) {
177
+ diagnostics.push({
178
+ code: "MSL-L050",
179
+ severity: "info",
180
+ message: `${file}: empty ${resolvedKind} listing — ` +
181
+ `no items found (valid placeholder; spec §6.4)`,
182
+ location: { file, line: 1, column: 1 },
183
+ });
184
+ }
185
+ return diagnostics;
186
+ }
187
+ // ---------------------------------------------------------------------------
188
+ // References listing — per-entry checks (§6.1)
189
+ // ---------------------------------------------------------------------------
190
+ function validateReferencesEntry(entry, file, diagnostics) {
191
+ // MSL-L040: Authored-shape entry in a references listing (warning).
192
+ if (entry.shape === "Authored") {
193
+ diagnostics.push({
194
+ code: "MSL-L040",
195
+ severity: "warning",
196
+ message: `${file}:${entry.location.line}: Authored entry ` +
197
+ `'[${entry.displayId}]' in a references listing — ` +
198
+ `references should be Reference-shape (URI Id:); ` +
199
+ `Authored entries are project-owned, not bibliographic (spec §6.1)`,
200
+ location: entry.location,
201
+ });
202
+ return;
203
+ }
204
+ // MSL-L041: resolved Type is in the Unit family (warning).
205
+ const typeVal = rawType(entry);
206
+ if (typeVal !== null && UNIT_FAMILY.has(typeVal)) {
207
+ diagnostics.push({
208
+ code: "MSL-L041",
209
+ severity: "warning",
210
+ message: `${file}:${entry.location.line}: entry '[${entry.displayId}]' ` +
211
+ `has Type: ${typeVal} (Unit family) in a references listing — ` +
212
+ `references should resolve to Specification or Component (spec §6.1)`,
213
+ location: entry.location,
214
+ });
215
+ }
216
+ }
217
+ // ---------------------------------------------------------------------------
218
+ // Components listing — per-entry checks (§6.3)
219
+ // ---------------------------------------------------------------------------
220
+ function validateComponentsEntry(entry, file, diagnostics) {
221
+ // MSL-L043: explicit Type: is not in the Component family.
222
+ const typeVal = rawType(entry);
223
+ if (typeVal !== null && !COMPONENT_FAMILY.has(typeVal)) {
224
+ diagnostics.push({
225
+ code: "MSL-L043",
226
+ severity: "error",
227
+ message: `${file}:${entry.location.line}: entry '[${entry.displayId}]' ` +
228
+ `has Type: ${typeVal} which is not in the Component family ` +
229
+ `(Component/SoftwareComponent/HardwareComponent/` +
230
+ `SoftwareInterface/HardwareInterface) — ` +
231
+ `only Component-family types are permitted in a components listing ` +
232
+ `(spec §6.3)`,
233
+ location: entry.location,
234
+ });
235
+ return;
236
+ }
237
+ // For Reference-shape entries, validate the Id: scheme (§5).
238
+ if (entry.shape === "Reference" && entry.id) {
239
+ validateComponentScheme(entry.id, entry, file, diagnostics);
240
+ }
241
+ // Authored-shape components (ULID Id:) are valid per spec §6.3 — no scheme check.
242
+ }
243
+ // ---------------------------------------------------------------------------
244
+ // Component Id-scheme validation (§5 / §6.3)
245
+ // ---------------------------------------------------------------------------
246
+ function validateComponentScheme(idValue, entry, file, diagnostics) {
247
+ const result = parseComponentScheme(idValue);
248
+ if (result === null) {
249
+ // No known component scheme matched. If it's a valid RFC 3986 URI →
250
+ // MSL-L030 info (unrecognized scheme, generic fallback).
251
+ // `isSchemeQualifiedUri` checks the RFC 3986 scheme prefix.
252
+ if (isSchemeQualifiedUri(idValue)) {
253
+ diagnostics.push({
254
+ code: "MSL-L030",
255
+ severity: "info",
256
+ message: `${file}:${entry.location.line}: ` +
257
+ `entry '[${entry.displayId}]' Id: '${idValue}' — ` +
258
+ `unrecognized component Id scheme; classified by fallback ` +
259
+ `(spec §5, MSL-L030)`,
260
+ location: entry.location,
261
+ });
262
+ }
263
+ // Not a scheme-qualified URI at all → the core validator (MSL-R004) handles it.
264
+ return;
265
+ }
266
+ if (!result.ok) {
267
+ diagnostics.push({
268
+ code: result.code,
269
+ severity: "error",
270
+ message: `${file}:${entry.location.line}: ` +
271
+ `entry '[${entry.displayId}]' Id: '${idValue}' — ${result.message}`,
272
+ location: entry.location,
273
+ });
274
+ }
275
+ // result.ok === true → valid scheme, no diagnostic needed here.
276
+ // (MSL-L030 for unknown purl types is handled inside parsePurl returning
277
+ // { ok: true, type: "Component" } — the caller gets no diagnostic.)
278
+ }
279
+ // ---------------------------------------------------------------------------
280
+ // Public API
281
+ // ---------------------------------------------------------------------------
282
+ /**
283
+ * Validate a set of files for listing-directive conformance.
284
+ *
285
+ * Returns diagnostics in document order (one file at a time in the order
286
+ * `contexts` was supplied). Call this alongside `runPipeline` — both
287
+ * operate independently.
288
+ */
289
+ export function validateListingDocuments(contexts) {
290
+ const diagnostics = [];
291
+ for (const ctx of contexts) {
292
+ diagnostics.push(...validateFile(ctx));
293
+ }
294
+ return diagnostics;
295
+ }
@@ -32,6 +32,8 @@ export declare function indexByDisplayId(entries: readonly Entry[]): ReadonlyMap
32
32
  export declare function findAttr(attrs: readonly Attribute[], key: string): Attribute | undefined;
33
33
  export { runPipeline } from "./pipeline.js";
34
34
  export type { PipelineResult } from "./pipeline.js";
35
+ export { validateListingDocuments } from "./listing.js";
36
+ export type { ListingFileContext, ListingKind } from "./listing.js";
35
37
  export { classifyEntriesStage, classifyEntry } from "./types.js";
36
38
  export type { ClassifyResult, ClassifyStageResult } from "./types.js";
37
39
  export { compileDisplayIdPattern } from "./pattern.js";
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAWpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,cAAc,CAQlE;AAyLD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAM5B;AAGD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAEvB;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAmCpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,cAAc,CAQlE;AAwZD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAM5B;AAGD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAEvB;AAED,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC"}
@@ -13,9 +13,29 @@
13
13
  * constraints, enum vocabularies) are profile-declared and evaluated by
14
14
  * a profile-aware validator layer (not in the core).
15
15
  */
16
- import { IDENTITY_KEY, ULID_RE, UNIVERSAL_ATTRIBUTE_KEYS, URI_SCHEME_RE, } from "../model/mod.js";
16
+ import { attributeSpec, CORE_TYPE_SCOPED_ATTRS, IDENTITY_KEY, ULID_RE, UNIVERSAL_ATTRIBUTE_KEYS, URI_SCHEME_RE, } from "../model/mod.js";
17
+ import { HTTP_URL_RE } from "./value_types.js";
17
18
  /** Universal attribute keys the core recognizes. */
18
19
  const UNIVERSAL_KEYS = new Set(UNIVERSAL_ATTRIBUTE_KEYS);
20
+ /**
21
+ * Value-type set that's repeatable per spec §1.8 — these attributes
22
+ * accept multiple lines for distinct values, so multiple trailers with
23
+ * the same key are legal. Single-cardinality attributes are anything
24
+ * not in this set.
25
+ */
26
+ const REPEATABLE_VALUE_TYPES = new Set([
27
+ "id-list",
28
+ "tag-list",
29
+ "citation",
30
+ "external-id",
31
+ ]);
32
+ /**
33
+ * Slug pattern for Reference-shape display IDs (spec §1.7, ADR-002 §Part 3).
34
+ * Pandoc/BibTeX cite-key convention, restricted to a portable character
35
+ * set: starts with a letter, body alphanumeric + `.` / `/` / `-` / `_`,
36
+ * ends with an alphanumeric.
37
+ */
38
+ const REFERENCE_SLUG_RE = /^[A-Za-z]([A-Za-z0-9._/-]*[A-Za-z0-9])?$/;
19
39
  /**
20
40
  * Validate a set of parsed entries for structural correctness and
21
41
  * cross-reference integrity.
@@ -35,6 +55,8 @@ function checkStructural(entries, diagnostics) {
35
55
  const ids = new Map();
36
56
  for (const entry of entries) {
37
57
  // MSL-R003: exactly one `Id:` attribute per entry.
58
+ // Dual-emit: MSL-I002 (Reference missing Id), MSL-I003 (Authored missing
59
+ // Id), MSL-I004 (multiple Id) — nextgen §4.2 codes alongside legacy.
38
60
  const idAttrs = entry.rawAttributes.filter((a) => a.key === IDENTITY_KEY);
39
61
  if (idAttrs.length === 0) {
40
62
  diagnostics.push({
@@ -43,6 +65,25 @@ function checkStructural(entries, diagnostics) {
43
65
  message: `${entry.displayId}: missing Id: attribute`,
44
66
  location: entry.location,
45
67
  });
68
+ // Dual-emit: shape-specific nextgen code
69
+ if (entry.shape === "Reference") {
70
+ diagnostics.push({
71
+ code: "MSL-I002",
72
+ severity: "error",
73
+ message: `${entry.displayId}: Reference-shape entry without Id: ` +
74
+ `fmt cannot mint URIs (spec section 4.2)`,
75
+ location: entry.location,
76
+ });
77
+ }
78
+ else {
79
+ diagnostics.push({
80
+ code: "MSL-I003",
81
+ severity: "error",
82
+ message: `${entry.displayId}: Authored-shape entry without Id: ` +
83
+ `run fmt to mint a ULID (spec section 4.2)`,
84
+ location: entry.location,
85
+ });
86
+ }
46
87
  }
47
88
  else if (idAttrs.length > 1) {
48
89
  diagnostics.push({
@@ -51,8 +92,17 @@ function checkStructural(entries, diagnostics) {
51
92
  message: `${entry.displayId}: multiple Id: attributes (${idAttrs.length}) — exactly one is required`,
52
93
  location: entry.location,
53
94
  });
95
+ // Dual-emit: MSL-I004
96
+ diagnostics.push({
97
+ code: "MSL-I004",
98
+ severity: "error",
99
+ message: `${entry.displayId}: multiple Id: trailers ` +
100
+ `(${idAttrs.length}) on the same entry (spec section 4.2)`,
101
+ location: entry.location,
102
+ });
54
103
  }
55
104
  // MSL-R004: `Id:` value must be a ULID or a scheme-qualified URI.
105
+ // Dual-emit: MSL-I001 — nextgen §4.2 code alongside legacy.
56
106
  if (idAttrs.length > 0) {
57
107
  const value = idAttrs[0].value;
58
108
  const isUlid = ULID_RE.test(value);
@@ -64,9 +114,16 @@ function checkStructural(entries, diagnostics) {
64
114
  message: `${entry.displayId}: Id: value '${value}' is neither a bare ULID nor a scheme-qualified URI`,
65
115
  location: entry.location,
66
116
  });
117
+ diagnostics.push({
118
+ code: "MSL-I001",
119
+ severity: "error",
120
+ message: `${entry.displayId}: Id: value '${value}' is neither a ULID ` +
121
+ `(^[0-9A-HJKMNP-TV-Z]{26}$) nor an RFC 3986 URI (spec section 4.2)`,
122
+ location: entry.location,
123
+ });
67
124
  }
68
125
  // Shape consistency: ULID ↔ identified, URI ↔ referenced.
69
- if (isUlid && entry.shape !== "identified") {
126
+ if (isUlid && entry.shape !== "Authored") {
70
127
  diagnostics.push({
71
128
  code: "MSL-R004",
72
129
  severity: "error",
@@ -74,7 +131,7 @@ function checkStructural(entries, diagnostics) {
74
131
  location: entry.location,
75
132
  });
76
133
  }
77
- else if (isUri && entry.shape !== "referenced") {
134
+ else if (isUri && entry.shape !== "Reference") {
78
135
  diagnostics.push({
79
136
  code: "MSL-R004",
80
137
  severity: "error",
@@ -83,7 +140,21 @@ function checkStructural(entries, diagnostics) {
83
140
  });
84
141
  }
85
142
  }
143
+ // MSL-I006: Reference-shape display ID must match the slug pattern
144
+ // (spec §1.7, ADR-002 §Part 3). Authored entries have a free-form
145
+ // display ID at core level (tightened by profile patterns).
146
+ if (entry.shape === "Reference" && !REFERENCE_SLUG_RE.test(entry.displayId)) {
147
+ diagnostics.push({
148
+ code: "MSL-I006",
149
+ severity: "error",
150
+ message: `${entry.displayId}: Reference-shape display ID does not ` +
151
+ `match the slug pattern (spec §1.7); expected ` +
152
+ `^[A-Za-z]([A-Za-z0-9._/-]*[A-Za-z0-9])?$`,
153
+ location: entry.location,
154
+ });
155
+ }
86
156
  // MSL-R006: Display ID unique across all entries.
157
+ // Dual-emit: MSL-I008 (warning) — nextgen §4.2.
87
158
  const existingDisplay = displayIds.get(entry.displayId);
88
159
  if (existingDisplay) {
89
160
  diagnostics.push({
@@ -92,11 +163,21 @@ function checkStructural(entries, diagnostics) {
92
163
  message: `duplicate display ID '${entry.displayId}' (also at ${existingDisplay.location.file}:${existingDisplay.location.line})`,
93
164
  location: entry.location,
94
165
  });
166
+ diagnostics.push({
167
+ code: "MSL-I008",
168
+ severity: "warning",
169
+ message: `duplicate display ID '${entry.displayId}' within the same ` +
170
+ `shape (also at ${existingDisplay.location.file}:` +
171
+ `${existingDisplay.location.line}) -- cross-references resolve ` +
172
+ `by Id:, so this is style-only (spec section 4.2)`,
173
+ location: entry.location,
174
+ });
95
175
  }
96
176
  else {
97
177
  displayIds.set(entry.displayId, entry);
98
178
  }
99
179
  // MSL-R005: identity value unique across all entries.
180
+ // Dual-emit: MSL-I007 — nextgen §4.2.
100
181
  if (entry.id) {
101
182
  const existingId = ids.get(entry.id);
102
183
  if (existingId) {
@@ -106,17 +187,174 @@ function checkStructural(entries, diagnostics) {
106
187
  message: `duplicate Id '${entry.id}' (also at ${existingId.location.file}:${existingId.location.line})`,
107
188
  location: entry.location,
108
189
  });
190
+ diagnostics.push({
191
+ code: "MSL-I007",
192
+ severity: "error",
193
+ message: `duplicate Id: value '${entry.id}' across the project (also ` +
194
+ `at ${existingId.location.file}:${existingId.location.line}) ` +
195
+ `(spec section 4.2)`,
196
+ location: entry.location,
197
+ });
109
198
  }
110
199
  else {
111
200
  ids.set(entry.id, entry);
112
201
  }
113
202
  }
114
- // MSL-R010: Unknown attributes are warnings in the core. A
115
- // profile-aware validator widens this check to include profile-declared
116
- // attributes; until then, anything outside the universal set is
117
- // unrecognized.
203
+ // MSL-P010 — entry title is empty after trimming. The parser
204
+ // accepts an empty title for shape stability (`[REQ-001]` with
205
+ // nothing after) but the canonical form per spec §4.2 requires a
206
+ // non-empty human-readable title. Fires regardless of shape.
207
+ if (entry.title.trim().length === 0) {
208
+ diagnostics.push({
209
+ code: "MSL-P010",
210
+ severity: "error",
211
+ message: `${entry.displayId}: title is empty after trimming ` +
212
+ `(spec §4.2); add a non-empty human-readable title after ']'`,
213
+ location: entry.location,
214
+ });
215
+ }
216
+ // MSL-A011 — `citation`-typed attribute (References:) used CSV
217
+ // form. The canonical form is multi-line per spec §2.3.2: locators
218
+ // may contain commas (e.g. `[@iso26262, p. 42]`), so the parser
219
+ // never CSV-splits citation values. Detection scans for a `,` at
220
+ // bracket-depth zero — commas inside `[…]` are locators and OK.
221
+ for (const attr of entry.rawAttributes) {
222
+ const spec = attributeSpec(attr.key);
223
+ if (spec?.type !== "citation")
224
+ continue;
225
+ let depth = 0;
226
+ let sawTopLevelComma = false;
227
+ for (const ch of attr.value) {
228
+ if (ch === "[")
229
+ depth++;
230
+ else if (ch === "]" && depth > 0)
231
+ depth--;
232
+ else if (ch === "," && depth === 0) {
233
+ sawTopLevelComma = true;
234
+ break;
235
+ }
236
+ }
237
+ if (sawTopLevelComma) {
238
+ diagnostics.push({
239
+ code: "MSL-A011",
240
+ severity: "error",
241
+ message: `${entry.displayId}: '${attr.key}' is citation-typed and ` +
242
+ `must use multi-line form (spec §2.3.2); CSV is rejected because ` +
243
+ `Pandoc locators may contain commas`,
244
+ location: entry.location,
245
+ });
246
+ }
247
+ }
248
+ // MSL-A012 — repeatable attribute value list is empty (spec §1.8).
249
+ // Fires when an authored repeatable attribute (id-list, tag-list,
250
+ // citation, external-id) carries no non-empty values after trimming
251
+ // and CSV splitting. `citation` is not CSV-splittable, so its check
252
+ // is a plain trim-and-empty test.
253
+ for (const attr of entry.rawAttributes) {
254
+ const spec = attributeSpec(attr.key);
255
+ if (!spec)
256
+ continue;
257
+ if (!REPEATABLE_VALUE_TYPES.has(spec.type))
258
+ continue;
259
+ const raw = attr.value;
260
+ const isCitation = spec.type === "citation";
261
+ const values = isCitation
262
+ ? [raw.trim()].filter((s) => s.length > 0)
263
+ : raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
264
+ if (values.length === 0) {
265
+ diagnostics.push({
266
+ code: "MSL-A012",
267
+ severity: "error",
268
+ message: `${entry.displayId}: '${attr.key}' is a repeatable ` +
269
+ `attribute but the value list is empty (spec §1.8)`,
270
+ location: entry.location,
271
+ });
272
+ }
273
+ }
274
+ // MSL-A013 — single-cardinality core attribute used more than once.
275
+ // `Id:` is excluded because MSL-R003 (above) reports its duplicates
276
+ // with a more specific message. Profile-declared attribute
277
+ // cardinality is enforced by the profile-aware Stage 3 (MSL-A002).
278
+ const seenSingleKeys = new Set();
279
+ const reportedA013 = new Set();
118
280
  for (const attr of entry.rawAttributes) {
119
- if (!UNIVERSAL_KEYS.has(attr.key) && attr.key !== "Type") {
281
+ if (attr.key === IDENTITY_KEY)
282
+ continue;
283
+ const spec = attributeSpec(attr.key);
284
+ if (!spec)
285
+ continue;
286
+ if (REPEATABLE_VALUE_TYPES.has(spec.type))
287
+ continue;
288
+ if (seenSingleKeys.has(attr.key)) {
289
+ if (!reportedA013.has(attr.key)) {
290
+ diagnostics.push({
291
+ code: "MSL-A013",
292
+ severity: "error",
293
+ message: `${entry.displayId}: '${attr.key}' is single-cardinality ` +
294
+ `but appears more than once (spec §1.8)`,
295
+ location: entry.location,
296
+ });
297
+ reportedA013.add(attr.key);
298
+ }
299
+ }
300
+ else {
301
+ seenSingleKeys.add(attr.key);
302
+ }
303
+ }
304
+ // MSL-A030 / MSL-A050 / MSL-R010 checks per attribute
305
+ // (§4.4 / §4.8 / spec §1.5).
306
+ for (const attr of entry.rawAttributes) {
307
+ // MSL-A030: generated-origin attributes must not appear in source.
308
+ const spec = attributeSpec(attr.key);
309
+ if (spec?.origin === "generated") {
310
+ diagnostics.push({
311
+ code: "MSL-A030",
312
+ severity: "error",
313
+ message: `${entry.displayId}: '${attr.key}' has generated origin and must not appear in source (computed at build time per ADR-003 §Part 3)`,
314
+ location: entry.location,
315
+ });
316
+ continue;
317
+ }
318
+ // MSL-A050: value does not parse against the declared value type
319
+ // (§4.4). The core knows the value type for the promoted Reference
320
+ // attributes (spec §1.5) and the universal enum attributes;
321
+ // profile-declared attribute types are validated by the
322
+ // profile-aware Stage 3 instead.
323
+ if (attr.key === "Reference-url") {
324
+ if (!HTTP_URL_RE.test(attr.value.trim())) {
325
+ diagnostics.push({
326
+ code: "MSL-A050",
327
+ severity: "error",
328
+ message: `${entry.displayId}: Reference-url value ` +
329
+ `'${attr.value.trim()}' is not an http(s) URL (spec §1.5)`,
330
+ location: entry.location,
331
+ });
332
+ continue;
333
+ }
334
+ }
335
+ if (spec?.type === "enum" && spec.enumValues) {
336
+ const trimmed = attr.value.trim();
337
+ if (trimmed.length > 0 && !spec.enumValues.includes(trimmed)) {
338
+ diagnostics.push({
339
+ code: "MSL-A050",
340
+ severity: "error",
341
+ message: `${entry.displayId}: ${attr.key} value '${trimmed}' ` +
342
+ `is not in the allowed set ` +
343
+ `{${spec.enumValues.join(", ")}} (spec §1.8 enum)`,
344
+ location: entry.location,
345
+ });
346
+ continue;
347
+ }
348
+ }
349
+ // MSL-R010: Unknown attributes are warnings in the core. A
350
+ // profile-aware validator widens this check to include profile-declared
351
+ // attributes; until then, anything outside the universal set is
352
+ // unrecognized. Core-typed attributes (per ADR-003 §Part 2) are
353
+ // suppressed here — the per-type validator emits a more specific
354
+ // MSL-T022 when they appear on the "wrong" type.
355
+ if (!UNIVERSAL_KEYS.has(attr.key) &&
356
+ attr.key !== "Type" &&
357
+ !CORE_TYPE_SCOPED_ATTRS.has(attr.key)) {
120
358
  diagnostics.push({
121
359
  code: "MSL-R010",
122
360
  severity: "warning",
@@ -180,11 +418,13 @@ function checkReferences(entries, diagnostics) {
180
418
  });
181
419
  continue;
182
420
  }
183
- if (resolved.shape !== "referenced") {
421
+ if (resolved.shape !== "Reference") {
184
422
  diagnostics.push({
185
- code: "MSL-T005",
186
- severity: "error",
187
- message: `${entry.displayId}: References: target '${slug}' is shape '${resolved.shape}', expected 'referenced'`,
423
+ code: "MSL-R085",
424
+ severity: "warning",
425
+ message: `${entry.displayId}: References: target '${slug}' resolves to a ` +
426
+ `'${resolved.shape}' entry but References must cite a ` +
427
+ `Reference-shape entry (spec §4.8)`,
188
428
  location: entry.location,
189
429
  });
190
430
  }
@@ -206,6 +446,7 @@ export function findAttr(attrs, key) {
206
446
  return attrs.find((a) => a.key === key);
207
447
  }
208
448
  export { runPipeline } from "./pipeline.js";
449
+ export { validateListingDocuments } from "./listing.js";
209
450
  export { classifyEntriesStage, classifyEntry } from "./types.js";
210
451
  export { compileDisplayIdPattern } from "./pattern.js";
211
452
  export { effectiveScope, validateAttributesForEntry } from "./attributes.js";