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