@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,378 @@
1
+ /**
2
+ * @module core/profile/introspect
3
+ *
4
+ * Unified introspection API for profile chains. All discovery surfaces
5
+ * (CLI, MCP, LSP) consume this module instead of re-walking EffectiveProfile.
6
+ *
7
+ * Node-safe: no Deno.* APIs.
8
+ */
9
+ // ---------------------------------------------------------------------------
10
+ // Factory
11
+ // ---------------------------------------------------------------------------
12
+ /**
13
+ * Build a `ProfileIntrospection` from a profile chain (or `null` when
14
+ * no profile is configured for the project).
15
+ *
16
+ * The returned object is lazy — `overview()` caches after the first call.
17
+ */
18
+ export function buildProfileIntrospection(chain) {
19
+ if (!chain) {
20
+ return {
21
+ overview: () => ({
22
+ tiers: [
23
+ { id: "(none)", version: "", summary: "No profile configured" },
24
+ ],
25
+ elements: [],
26
+ }),
27
+ describe: () => undefined,
28
+ resolve: () => [],
29
+ };
30
+ }
31
+ // Capture non-null references so inner closures type-check.
32
+ const nonNullChain = chain;
33
+ const effective = nonNullChain.effective;
34
+ let cachedOverview;
35
+ function getOverview() {
36
+ if (cachedOverview)
37
+ return cachedOverview;
38
+ const tiers = nonNullChain.tiers.map((tier) => ({
39
+ id: tier.id,
40
+ version: tier.version,
41
+ summary: tier.manifest.description ?? tier.id,
42
+ }));
43
+ const elements = [];
44
+ // Types
45
+ for (const [name, entry] of effective.types) {
46
+ const tdef = entry.value;
47
+ const summary = tdef.description.value ?? tdef.extends;
48
+ elements.push({
49
+ kind: "type",
50
+ name,
51
+ summary,
52
+ ref: `type/${name}`,
53
+ });
54
+ }
55
+ // Universal attributes
56
+ for (const [name, entry] of effective.attributes) {
57
+ const decl = entry.value;
58
+ const summary = decl.description ??
59
+ `${decl.type}, ${formatCardinality(decl.cardinality)}`;
60
+ elements.push({
61
+ kind: "attribute",
62
+ name,
63
+ summary,
64
+ ref: `attribute/${name}`,
65
+ });
66
+ }
67
+ // Relations (deduplicated across types)
68
+ const seenRelations = new Map();
69
+ for (const [, typeEntry] of effective.types) {
70
+ const tdef = typeEntry.value;
71
+ for (const [relName, ruleEntry] of tdef.traceability) {
72
+ const existing = seenRelations.get(relName);
73
+ const desc = tdef.relationDescriptions.get(relName);
74
+ if (!existing) {
75
+ seenRelations.set(relName, {
76
+ targets: new Set(ruleEntry.value.target.map(targetToString)),
77
+ description: desc?.value,
78
+ });
79
+ }
80
+ else {
81
+ for (const t of ruleEntry.value.target.map(targetToString)) {
82
+ existing.targets.add(t);
83
+ }
84
+ if (desc?.value !== undefined && existing.description === undefined) {
85
+ existing.description = desc.value;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ for (const [name, info] of seenRelations) {
91
+ const summary = info.description ??
92
+ `targets: ${[...info.targets].join(", ")}`;
93
+ elements.push({
94
+ kind: "relation",
95
+ name,
96
+ summary,
97
+ ref: `relation/${name}`,
98
+ });
99
+ }
100
+ // Label concerns
101
+ for (const [name, entry] of effective.labels) {
102
+ const concern = entry.value;
103
+ const summary = concern.description ??
104
+ `${concern.kind}, ${concern.values.length} values`;
105
+ elements.push({
106
+ kind: "label-concern",
107
+ name,
108
+ summary,
109
+ ref: `label/${name}`,
110
+ });
111
+ }
112
+ // Conventions
113
+ for (const [name, entry] of effective.conventions) {
114
+ const conv = entry.value;
115
+ const summary = conv.description ??
116
+ Object.entries(conv.settings).map(([k, v]) => `${k}=${v}`).join(" ");
117
+ elements.push({
118
+ kind: "convention",
119
+ name,
120
+ summary,
121
+ ref: `convention/${name}`,
122
+ });
123
+ }
124
+ // Sort by kind order, then name within kind.
125
+ const KIND_ORDER = {
126
+ "type": 0,
127
+ "attribute": 1,
128
+ "relation": 2,
129
+ "label-concern": 3,
130
+ "convention": 4,
131
+ };
132
+ elements.sort((a, b) => {
133
+ const kDiff = KIND_ORDER[a.kind] - KIND_ORDER[b.kind];
134
+ return kDiff !== 0 ? kDiff : a.name.localeCompare(b.name);
135
+ });
136
+ cachedOverview = { tiers, elements };
137
+ return cachedOverview;
138
+ }
139
+ function describe(kind, name) {
140
+ switch (kind) {
141
+ case "type":
142
+ return describeType(name, effective);
143
+ case "attribute":
144
+ return describeAttribute(name, effective);
145
+ case "relation":
146
+ return describeRelation(name, effective);
147
+ case "label-concern":
148
+ return describeLabelConcern(name, effective);
149
+ case "convention":
150
+ return describeConvention(name, effective);
151
+ }
152
+ }
153
+ function resolve(query) {
154
+ const tokens = query.toLowerCase().split(/\s+/).filter(Boolean);
155
+ if (tokens.length === 0)
156
+ return [];
157
+ const overview = getOverview();
158
+ return overview.elements.filter((ref) => {
159
+ const haystack = `${ref.kind} ${ref.name} ${ref.summary}`.toLowerCase();
160
+ return tokens.every((t) => haystack.includes(t));
161
+ });
162
+ }
163
+ return { overview: getOverview, describe, resolve };
164
+ }
165
+ // ---------------------------------------------------------------------------
166
+ // Per-element describe helpers
167
+ // ---------------------------------------------------------------------------
168
+ function describeType(name, effective) {
169
+ const entry = effective.types.get(name);
170
+ if (!entry)
171
+ return undefined;
172
+ const tdef = entry.value;
173
+ const description = provenancedFromValue(tdef.description);
174
+ // Required attributes: those listed in tdef.required
175
+ const requiredAttributes = tdef.required.value
176
+ .map((attrName) => attrRef(attrName, effective, tdef));
177
+ // Allowed attributes: all declared attrs minus required
178
+ const requiredSet = new Set(tdef.required.value);
179
+ const allAttrNames = [
180
+ ...tdef.attributes.keys(),
181
+ ...effective.attributes.keys(),
182
+ ].filter((attrName, i, arr) => arr.indexOf(attrName) === i); // dedupe
183
+ const allowedAttributes = allAttrNames
184
+ .filter((attrName) => !requiredSet.has(attrName))
185
+ .map((attrName) => attrRef(attrName, effective, tdef));
186
+ // Outgoing relations
187
+ const outgoingRelations = [
188
+ ...tdef.traceability.keys(),
189
+ ].map((relName) => {
190
+ const descEntry = tdef.relationDescriptions.get(relName);
191
+ const rule = tdef.traceability.get(relName);
192
+ const summary = descEntry?.value ??
193
+ `targets: ${rule.value.target.map(targetToString).join(", ")}`;
194
+ return {
195
+ kind: "relation",
196
+ name: relName,
197
+ summary,
198
+ ref: `relation/${relName}`,
199
+ };
200
+ });
201
+ // Incoming relations: types whose traceability targets this type by name
202
+ const incomingRelations = [];
203
+ const seenIn = new Set();
204
+ for (const [otherTypeName, otherEntry] of effective.types) {
205
+ if (otherTypeName === name)
206
+ continue;
207
+ for (const [relName, ruleEntry] of otherEntry.value.traceability) {
208
+ if (seenIn.has(relName))
209
+ continue;
210
+ const targets = ruleEntry.value.target;
211
+ const matches = targets.some((t) => typeof t === "string" ? t === name : false);
212
+ if (matches) {
213
+ seenIn.add(relName);
214
+ const relDesc = otherEntry.value.relationDescriptions.get(relName);
215
+ const summary = relDesc?.value ?? `from ${otherTypeName}`;
216
+ incomingRelations.push({
217
+ kind: "relation",
218
+ name: relName,
219
+ summary,
220
+ ref: `relation/${relName}`,
221
+ });
222
+ }
223
+ }
224
+ }
225
+ return {
226
+ kind: "type",
227
+ name,
228
+ description,
229
+ extendsTarget: tdef.extends,
230
+ shape: tdef.extends,
231
+ displayIdPattern: tdef.displayIdPattern.value,
232
+ color: tdef.color.value,
233
+ requiredAttributes,
234
+ allowedAttributes,
235
+ outgoingRelations,
236
+ incomingRelations,
237
+ };
238
+ }
239
+ function attrRef(attrName, effective, tdef) {
240
+ // Look in type-specific scope first, then universal.
241
+ const typeAttr = tdef.attributes.get(attrName)?.value;
242
+ const universalAttr = effective.attributes.get(attrName)?.value;
243
+ const attrDecl = typeAttr ?? universalAttr;
244
+ const attrDesc = tdef.attrDescriptions.get(attrName);
245
+ const summary = attrDesc?.value ??
246
+ attrDecl?.description ??
247
+ (attrDecl
248
+ ? `${attrDecl.type}, ${formatCardinality(attrDecl.cardinality)}`
249
+ : attrName);
250
+ return {
251
+ kind: "attribute",
252
+ name: attrName,
253
+ summary,
254
+ ref: `attribute/${attrName}`,
255
+ };
256
+ }
257
+ function describeAttribute(name, effective) {
258
+ const entry = effective.attributes.get(name);
259
+ if (!entry)
260
+ return undefined;
261
+ const decl = entry.value;
262
+ // Find which types also declare this attribute.
263
+ const declaredBy = ["universal"];
264
+ for (const [typeName, typeEntry] of effective.types) {
265
+ if (typeEntry.value.attributes.has(name)) {
266
+ declaredBy.push(typeName);
267
+ }
268
+ }
269
+ const description = {
270
+ text: decl.description,
271
+ origin: decl.description !== undefined ? entry.origin : undefined,
272
+ };
273
+ return {
274
+ kind: "attribute",
275
+ name,
276
+ description,
277
+ valueType: decl.type,
278
+ cardinality: formatCardinality(decl.cardinality),
279
+ required: decl.required,
280
+ enumValues: decl.values,
281
+ inverse: decl.inverse,
282
+ declaredBy,
283
+ };
284
+ }
285
+ function describeRelation(name, effective) {
286
+ const declaredBy = [];
287
+ let bestDesc = {};
288
+ const targets = [];
289
+ let required = false;
290
+ let cardinality;
291
+ for (const [typeName, typeEntry] of effective.types) {
292
+ const tdef = typeEntry.value;
293
+ const ruleEntry = tdef.traceability.get(name);
294
+ if (!ruleEntry)
295
+ continue;
296
+ declaredBy.push(typeName);
297
+ const rule = ruleEntry.value;
298
+ for (const t of rule.target.map(targetToString)) {
299
+ if (!targets.includes(t))
300
+ targets.push(t);
301
+ }
302
+ if (rule.required)
303
+ required = true;
304
+ if (rule.cardinality) {
305
+ cardinality = formatCardinality(rule.cardinality);
306
+ }
307
+ const descEntry = tdef.relationDescriptions.get(name);
308
+ if (descEntry?.value !== undefined && bestDesc.text === undefined) {
309
+ bestDesc = {
310
+ text: descEntry.value,
311
+ origin: descEntry.origin,
312
+ overrides: descEntry.overrides ? [...descEntry.overrides] : undefined,
313
+ };
314
+ }
315
+ }
316
+ if (declaredBy.length === 0)
317
+ return undefined;
318
+ return {
319
+ kind: "relation",
320
+ name,
321
+ description: bestDesc,
322
+ targets,
323
+ cardinality,
324
+ required,
325
+ declaredBy,
326
+ };
327
+ }
328
+ function describeLabelConcern(name, effective) {
329
+ const entry = effective.labels.get(name);
330
+ if (!entry)
331
+ return undefined;
332
+ const concern = entry.value;
333
+ const description = {
334
+ text: concern.description,
335
+ origin: concern.description !== undefined ? entry.origin : undefined,
336
+ overrides: entry.overrides ? [...entry.overrides] : undefined,
337
+ };
338
+ return {
339
+ kind: "label-concern",
340
+ name,
341
+ description,
342
+ concernKind: concern.kind,
343
+ values: concern.values,
344
+ };
345
+ }
346
+ function describeConvention(name, effective) {
347
+ const entry = effective.conventions.get(name);
348
+ if (!entry)
349
+ return undefined;
350
+ const conv = entry.value;
351
+ const description = {
352
+ text: conv.description,
353
+ origin: conv.description !== undefined ? entry.origin : undefined,
354
+ overrides: entry.overrides ? [...entry.overrides] : undefined,
355
+ };
356
+ return {
357
+ kind: "convention",
358
+ name,
359
+ description,
360
+ settings: conv.settings,
361
+ };
362
+ }
363
+ // ---------------------------------------------------------------------------
364
+ // Helpers
365
+ // ---------------------------------------------------------------------------
366
+ function provenancedFromValue(pv) {
367
+ return {
368
+ text: pv.value,
369
+ origin: pv.value !== undefined ? pv.origin : undefined,
370
+ };
371
+ }
372
+ function formatCardinality(card) {
373
+ const upper = card.upper === Infinity ? "N" : String(card.upper);
374
+ return `${card.lower}..${upper}`;
375
+ }
376
+ function targetToString(t) {
377
+ return typeof t === "string" ? t : `{shape:${t.shape}}`;
378
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/profile/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGhE,yCAAyC;AACzC,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,2BAA2B,CAAC,CAuCtC"}
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/profile/load.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAIhE,yCAAyC;AACzC,MAAM,WAAW,2BAA2B;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,2BAA2B,CAAC,CA4CtC"}
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { join } from "@std/path";
10
10
  import { MARKSPEC_YAML_FILENAME, parseMarkspecYaml, readMarkspecYaml, } from "../config/markspec.js";
11
+ import { CORE_TYPES } from "../model/mod.js";
11
12
  import { loadChain } from "./chain.js";
12
13
  /**
13
14
  * Load the active profile chain for the project at `projectRoot`.
@@ -46,5 +47,71 @@ export async function loadProfileForCommand(projectRoot, readFile) {
46
47
  }
47
48
  const chainResult = await loadChain(profiles[0], projectRoot, projectRoot, readFile);
48
49
  diagnostics.push(...chainResult.diagnostics);
50
+ // MSL-A040 — profile must not redefine reserved core keys / types.
51
+ if (chainResult.chain) {
52
+ diagnostics.push(...checkReservedRedefinitions(chainResult.chain));
53
+ }
49
54
  return { chain: chainResult.chain, diagnostics };
50
55
  }
56
+ /**
57
+ * Reserved attribute names a profile must never declare. Per spec
58
+ * §4.4 MSL-A040 and ADR-009 §6: the identity slot (`Id`) and the
59
+ * type attribute (`Type`) are the absolutely reserved keys; their
60
+ * meaning is fixed by the core and any profile redefinition would
61
+ * silently break shape discrimination or type resolution.
62
+ */
63
+ const RESERVED_ATTRIBUTE_KEYS = new Set([
64
+ "Id",
65
+ "Type",
66
+ ]);
67
+ /**
68
+ * Scan the loaded profile chain for declarations that shadow core
69
+ * reserved names and emit MSL-A040 diagnostics. The check inspects:
70
+ *
71
+ * - universal `attributes:` scope,
72
+ * - per-shape `identified.attributes:` and `referenced.attributes:`,
73
+ * - every per-type `attributes:` map under `types:`,
74
+ * - each declared type name itself (must not match a core type).
75
+ */
76
+ function checkReservedRedefinitions(chain) {
77
+ const diagnostics = [];
78
+ const effective = chain.effective;
79
+ // Build origin → sourcePath index from the chain's tiers so diagnostics
80
+ // can point at the manifest file that introduced each declaration.
81
+ const originToPath = new Map();
82
+ for (const tier of chain.tiers) {
83
+ originToPath.set(tier.id, tier.sourcePath);
84
+ }
85
+ // Fallback file when an origin somehow isn't in the tier list.
86
+ const fallbackPath = chain.tiers[0]?.sourcePath ?? "<profile>";
87
+ function pathFor(origin) {
88
+ return originToPath.get(origin) ?? fallbackPath;
89
+ }
90
+ function checkAttrMap(map, scope) {
91
+ for (const [key, entry] of map) {
92
+ if (RESERVED_ATTRIBUTE_KEYS.has(key)) {
93
+ diagnostics.push({
94
+ code: "MSL-A040",
95
+ severity: "error",
96
+ message: `profile ${scope} attribute '${key}' shadows a core ` +
97
+ `reserved key (spec §4.4, ADR-009 §6); choose a different name`,
98
+ location: { file: pathFor(entry.origin), line: 1, column: 1 },
99
+ });
100
+ }
101
+ }
102
+ }
103
+ checkAttrMap(effective.attributes, "universal");
104
+ for (const [typeName, typeEntry] of effective.types) {
105
+ checkAttrMap(typeEntry.value.attributes, `type '${typeName}'`);
106
+ if (CORE_TYPES.has(typeName)) {
107
+ diagnostics.push({
108
+ code: "MSL-A040",
109
+ severity: "error",
110
+ message: `profile type '${typeName}' shadows a core type name ` +
111
+ `(spec §4.4); the 15-type core vocabulary is reserved`,
112
+ location: { file: pathFor(typeEntry.origin), line: 1, column: 1 },
113
+ });
114
+ }
115
+ }
116
+ return diagnostics;
117
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAyGnE,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AA4tBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CAkNrB"}
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/profile/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AA4EnE,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAo9BD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,UAAU,SAAoB,GAC7B,mBAAmB,CA6KrB"}