@driftsys/markspec 0.1.0 → 0.3.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 (242) hide show
  1. package/README.md +32 -8
  2. package/esm/_dnt.polyfills.d.ts +101 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +127 -0
  5. package/esm/compiler/inverses.d.ts +22 -0
  6. package/esm/compiler/inverses.d.ts.map +1 -0
  7. package/esm/compiler/inverses.js +147 -0
  8. package/esm/compiler/link_target.d.ts +19 -0
  9. package/esm/compiler/link_target.d.ts.map +1 -0
  10. package/esm/compiler/link_target.js +66 -0
  11. package/esm/compiler/mod.d.ts +43 -0
  12. package/esm/compiler/mod.d.ts.map +1 -0
  13. package/esm/compiler/mod.js +163 -0
  14. package/esm/compiler/schema.d.ts +38 -0
  15. package/esm/compiler/schema.d.ts.map +1 -0
  16. package/esm/compiler/schema.js +44 -0
  17. package/esm/config/markspec.d.ts +51 -0
  18. package/esm/config/markspec.d.ts.map +1 -0
  19. package/esm/config/markspec.js +216 -0
  20. package/esm/config/mod.d.ts +48 -0
  21. package/esm/config/mod.d.ts.map +1 -0
  22. package/esm/config/mod.js +243 -0
  23. package/esm/formatter/mod.d.ts +65 -0
  24. package/esm/formatter/mod.d.ts.map +1 -0
  25. package/esm/formatter/mod.js +306 -0
  26. package/esm/mod.d.ts +19 -0
  27. package/esm/mod.d.ts.map +1 -1
  28. package/esm/mod.js +18 -0
  29. package/esm/model/attributes.d.ts +47 -0
  30. package/esm/model/attributes.d.ts.map +1 -0
  31. package/esm/model/attributes.js +97 -0
  32. package/esm/model/mod.d.ts +381 -0
  33. package/esm/model/mod.d.ts.map +1 -0
  34. package/esm/model/mod.js +73 -0
  35. package/esm/model/profile.d.ts +189 -0
  36. package/esm/model/profile.d.ts.map +1 -0
  37. package/esm/model/profile.js +31 -0
  38. package/esm/parser/attributes.d.ts +48 -0
  39. package/esm/parser/attributes.d.ts.map +1 -0
  40. package/esm/parser/attributes.js +131 -0
  41. package/esm/parser/captions.d.ts +25 -0
  42. package/esm/parser/captions.d.ts.map +1 -0
  43. package/esm/parser/captions.js +148 -0
  44. package/esm/parser/directives.d.ts +29 -0
  45. package/esm/parser/directives.d.ts.map +1 -0
  46. package/esm/parser/directives.js +88 -0
  47. package/esm/parser/frontmatter.d.ts +53 -0
  48. package/esm/parser/frontmatter.d.ts.map +1 -0
  49. package/esm/parser/frontmatter.js +185 -0
  50. package/esm/parser/grammars.d.ts +22 -0
  51. package/esm/parser/grammars.d.ts.map +1 -0
  52. package/esm/parser/grammars.js +70 -0
  53. package/esm/parser/markdown.d.ts +32 -0
  54. package/esm/parser/markdown.d.ts.map +1 -0
  55. package/esm/parser/markdown.js +225 -0
  56. package/esm/parser/mod.d.ts +73 -0
  57. package/esm/parser/mod.d.ts.map +1 -0
  58. package/esm/parser/mod.js +89 -0
  59. package/esm/parser/references.d.ts +24 -0
  60. package/esm/parser/references.d.ts.map +1 -0
  61. package/esm/parser/references.js +71 -0
  62. package/esm/parser/remark.d.ts +9 -0
  63. package/esm/parser/remark.d.ts.map +1 -0
  64. package/esm/parser/remark.js +11 -0
  65. package/esm/parser/source.d.ts +33 -0
  66. package/esm/parser/source.d.ts.map +1 -0
  67. package/esm/parser/source.js +192 -0
  68. package/esm/profile/cache.d.ts +29 -0
  69. package/esm/profile/cache.d.ts.map +1 -0
  70. package/esm/profile/cache.js +45 -0
  71. package/esm/profile/chain.d.ts +42 -0
  72. package/esm/profile/chain.d.ts.map +1 -0
  73. package/esm/profile/chain.js +193 -0
  74. package/esm/profile/git-cache.d.ts +73 -0
  75. package/esm/profile/git-cache.d.ts.map +1 -0
  76. package/esm/profile/git-cache.js +96 -0
  77. package/esm/profile/load.d.ts +28 -0
  78. package/esm/profile/load.d.ts.map +1 -0
  79. package/esm/profile/load.js +50 -0
  80. package/esm/profile/manifest.d.ts +21 -0
  81. package/esm/profile/manifest.d.ts.map +1 -0
  82. package/esm/profile/manifest.js +830 -0
  83. package/esm/profile/merge.d.ts +26 -0
  84. package/esm/profile/merge.d.ts.map +1 -0
  85. package/esm/profile/merge.js +518 -0
  86. package/esm/profile/mod.d.ts +23 -0
  87. package/esm/profile/mod.d.ts.map +1 -0
  88. package/esm/profile/mod.js +14 -0
  89. package/esm/profile/npm.d.ts +51 -0
  90. package/esm/profile/npm.d.ts.map +1 -0
  91. package/esm/profile/npm.js +186 -0
  92. package/esm/profile/resolver.d.ts +60 -0
  93. package/esm/profile/resolver.d.ts.map +1 -0
  94. package/esm/profile/resolver.js +132 -0
  95. package/esm/reporter/mod.d.ts +31 -0
  96. package/esm/reporter/mod.d.ts.map +1 -0
  97. package/esm/reporter/mod.js +173 -0
  98. package/esm/validator/attributes.d.ts +43 -0
  99. package/esm/validator/attributes.d.ts.map +1 -0
  100. package/esm/validator/attributes.js +169 -0
  101. package/esm/validator/mod.d.ts +44 -0
  102. package/esm/validator/mod.d.ts.map +1 -0
  103. package/esm/validator/mod.js +214 -0
  104. package/esm/validator/normalize.d.ts +21 -0
  105. package/esm/validator/normalize.d.ts.map +1 -0
  106. package/esm/validator/normalize.js +58 -0
  107. package/esm/validator/pattern.d.ts +23 -0
  108. package/esm/validator/pattern.d.ts.map +1 -0
  109. package/esm/validator/pattern.js +44 -0
  110. package/esm/validator/pipeline.d.ts +30 -0
  111. package/esm/validator/pipeline.d.ts.map +1 -0
  112. package/esm/validator/pipeline.js +115 -0
  113. package/esm/validator/traceability.d.ts +48 -0
  114. package/esm/validator/traceability.d.ts.map +1 -0
  115. package/esm/validator/traceability.js +141 -0
  116. package/esm/validator/types.d.ts +48 -0
  117. package/esm/validator/types.d.ts.map +1 -0
  118. package/esm/validator/types.js +140 -0
  119. package/esm/validator/value_types.d.ts +20 -0
  120. package/esm/validator/value_types.d.ts.map +1 -0
  121. package/esm/validator/value_types.js +126 -0
  122. package/package.json +8 -1
  123. package/script/_dnt.polyfills.d.ts +101 -0
  124. package/script/_dnt.polyfills.d.ts.map +1 -0
  125. package/script/_dnt.polyfills.js +130 -0
  126. package/script/compiler/inverses.d.ts +22 -0
  127. package/script/compiler/inverses.d.ts.map +1 -0
  128. package/script/compiler/inverses.js +150 -0
  129. package/script/compiler/link_target.d.ts +19 -0
  130. package/script/compiler/link_target.d.ts.map +1 -0
  131. package/script/compiler/link_target.js +69 -0
  132. package/script/compiler/mod.d.ts +43 -0
  133. package/script/compiler/mod.d.ts.map +1 -0
  134. package/script/compiler/mod.js +169 -0
  135. package/script/compiler/schema.d.ts +38 -0
  136. package/script/compiler/schema.d.ts.map +1 -0
  137. package/script/compiler/schema.js +47 -0
  138. package/script/config/markspec.d.ts +51 -0
  139. package/script/config/markspec.d.ts.map +1 -0
  140. package/script/config/markspec.js +222 -0
  141. package/script/config/mod.d.ts +48 -0
  142. package/script/config/mod.d.ts.map +1 -0
  143. package/script/config/mod.js +250 -0
  144. package/script/formatter/mod.d.ts +65 -0
  145. package/script/formatter/mod.d.ts.map +1 -0
  146. package/script/formatter/mod.js +313 -0
  147. package/script/mod.d.ts +19 -0
  148. package/script/mod.d.ts.map +1 -1
  149. package/script/mod.js +65 -2
  150. package/script/model/attributes.d.ts +47 -0
  151. package/script/model/attributes.d.ts.map +1 -0
  152. package/script/model/attributes.js +101 -0
  153. package/script/model/mod.d.ts +381 -0
  154. package/script/model/mod.d.ts.map +1 -0
  155. package/script/model/mod.js +83 -0
  156. package/script/model/profile.d.ts +189 -0
  157. package/script/model/profile.d.ts.map +1 -0
  158. package/script/model/profile.js +34 -0
  159. package/script/parser/attributes.d.ts +48 -0
  160. package/script/parser/attributes.d.ts.map +1 -0
  161. package/script/parser/attributes.js +137 -0
  162. package/script/parser/captions.d.ts +25 -0
  163. package/script/parser/captions.d.ts.map +1 -0
  164. package/script/parser/captions.js +151 -0
  165. package/script/parser/directives.d.ts +29 -0
  166. package/script/parser/directives.d.ts.map +1 -0
  167. package/script/parser/directives.js +91 -0
  168. package/script/parser/frontmatter.d.ts +53 -0
  169. package/script/parser/frontmatter.d.ts.map +1 -0
  170. package/script/parser/frontmatter.js +188 -0
  171. package/script/parser/grammars.d.ts +22 -0
  172. package/script/parser/grammars.d.ts.map +1 -0
  173. package/script/parser/grammars.js +77 -0
  174. package/script/parser/markdown.d.ts +32 -0
  175. package/script/parser/markdown.d.ts.map +1 -0
  176. package/script/parser/markdown.js +228 -0
  177. package/script/parser/mod.d.ts +73 -0
  178. package/script/parser/mod.d.ts.map +1 -0
  179. package/script/parser/mod.js +101 -0
  180. package/script/parser/references.d.ts +24 -0
  181. package/script/parser/references.d.ts.map +1 -0
  182. package/script/parser/references.js +74 -0
  183. package/script/parser/remark.d.ts +9 -0
  184. package/script/parser/remark.d.ts.map +1 -0
  185. package/script/parser/remark.js +17 -0
  186. package/script/parser/source.d.ts +33 -0
  187. package/script/parser/source.d.ts.map +1 -0
  188. package/script/parser/source.js +198 -0
  189. package/script/profile/cache.d.ts +29 -0
  190. package/script/profile/cache.d.ts.map +1 -0
  191. package/script/profile/cache.js +48 -0
  192. package/script/profile/chain.d.ts +42 -0
  193. package/script/profile/chain.d.ts.map +1 -0
  194. package/script/profile/chain.js +229 -0
  195. package/script/profile/git-cache.d.ts +73 -0
  196. package/script/profile/git-cache.d.ts.map +1 -0
  197. package/script/profile/git-cache.js +104 -0
  198. package/script/profile/load.d.ts +28 -0
  199. package/script/profile/load.d.ts.map +1 -0
  200. package/script/profile/load.js +53 -0
  201. package/script/profile/manifest.d.ts +21 -0
  202. package/script/profile/manifest.d.ts.map +1 -0
  203. package/script/profile/manifest.js +833 -0
  204. package/script/profile/merge.d.ts +26 -0
  205. package/script/profile/merge.d.ts.map +1 -0
  206. package/script/profile/merge.js +521 -0
  207. package/script/profile/mod.d.ts +23 -0
  208. package/script/profile/mod.d.ts.map +1 -0
  209. package/script/profile/mod.js +31 -0
  210. package/script/profile/npm.d.ts +51 -0
  211. package/script/profile/npm.d.ts.map +1 -0
  212. package/script/profile/npm.js +191 -0
  213. package/script/profile/resolver.d.ts +60 -0
  214. package/script/profile/resolver.d.ts.map +1 -0
  215. package/script/profile/resolver.js +136 -0
  216. package/script/reporter/mod.d.ts +31 -0
  217. package/script/reporter/mod.d.ts.map +1 -0
  218. package/script/reporter/mod.js +176 -0
  219. package/script/validator/attributes.d.ts +43 -0
  220. package/script/validator/attributes.d.ts.map +1 -0
  221. package/script/validator/attributes.js +173 -0
  222. package/script/validator/mod.d.ts +44 -0
  223. package/script/validator/mod.d.ts.map +1 -0
  224. package/script/validator/mod.js +231 -0
  225. package/script/validator/normalize.d.ts +21 -0
  226. package/script/validator/normalize.d.ts.map +1 -0
  227. package/script/validator/normalize.js +61 -0
  228. package/script/validator/pattern.d.ts +23 -0
  229. package/script/validator/pattern.d.ts.map +1 -0
  230. package/script/validator/pattern.js +47 -0
  231. package/script/validator/pipeline.d.ts +30 -0
  232. package/script/validator/pipeline.d.ts.map +1 -0
  233. package/script/validator/pipeline.js +118 -0
  234. package/script/validator/traceability.d.ts +48 -0
  235. package/script/validator/traceability.d.ts.map +1 -0
  236. package/script/validator/traceability.js +146 -0
  237. package/script/validator/types.d.ts +48 -0
  238. package/script/validator/types.d.ts.map +1 -0
  239. package/script/validator/types.js +144 -0
  240. package/script/validator/value_types.d.ts +20 -0
  241. package/script/validator/value_types.d.ts.map +1 -0
  242. package/script/validator/value_types.js +129 -0
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ /**
3
+ * @module compiler
4
+ *
5
+ * Compiler pipeline. Takes file paths, parses all entries, validates them,
6
+ * builds a bidirectional traceability graph, and returns the compiled model.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.generateInverses = exports.serializeCompileResult = void 0;
10
+ exports.compile = compile;
11
+ const mod_js_1 = require("../parser/mod.js");
12
+ const mod_js_2 = require("../validator/mod.js");
13
+ const inverses_js_1 = require("./inverses.js");
14
+ const link_target_js_1 = require("./link_target.js");
15
+ /**
16
+ * Compile MarkSpec files from the given paths into a resolved
17
+ * traceability graph.
18
+ *
19
+ * @param paths - File paths to compile
20
+ * @param options - Compile options
21
+ * @returns Compiled entries, links, and diagnostics
22
+ */
23
+ async function compile(paths, options) {
24
+ const read = options.readFile;
25
+ const allEntries = [];
26
+ const parseDiagnostics = [];
27
+ const documents = new Map();
28
+ // Phase 1: Read and parse all files.
29
+ for (const filePath of paths) {
30
+ let content;
31
+ try {
32
+ content = await read(filePath);
33
+ }
34
+ catch {
35
+ parseDiagnostics.push({
36
+ code: "MSL-E000",
37
+ severity: "error",
38
+ message: `failed to read file: ${filePath}`,
39
+ location: undefined,
40
+ });
41
+ continue;
42
+ }
43
+ const result = await (0, mod_js_1.parseFile)(content, { file: filePath });
44
+ allEntries.push(...result.entries);
45
+ parseDiagnostics.push(...result.diagnostics);
46
+ if (result.document)
47
+ documents.set(filePath, result.document);
48
+ }
49
+ // Phase 2: Validate all entries.
50
+ const validationResult = (0, mod_js_2.validate)(allEntries);
51
+ // Phase 2.5: Classify entries when a profile is loaded.
52
+ let classifiedEntries = allEntries;
53
+ if (options.profile) {
54
+ const stage2 = (0, mod_js_2.classifyEntriesStage)(allEntries, options.profile);
55
+ classifiedEntries = stage2.entries;
56
+ parseDiagnostics.push(...stage2.diagnostics);
57
+ }
58
+ // Phase 3: Build traceability graph.
59
+ // Keep first occurrence of each display ID (validator catches duplicates).
60
+ const entries = new Map();
61
+ for (const entry of classifiedEntries) {
62
+ if (!entries.has(entry.displayId)) {
63
+ entries.set(entry.displayId, entry);
64
+ }
65
+ }
66
+ // Phase 3.5: Generate inverse attributes from profile declarations.
67
+ if (options.profile) {
68
+ const inverseResult = (0, inverses_js_1.generateInverses)([...entries.values()], options.profile);
69
+ parseDiagnostics.push(...inverseResult.diagnostics);
70
+ entries.clear();
71
+ for (const entry of inverseResult.entries) {
72
+ if (!entries.has(entry.displayId)) {
73
+ entries.set(entry.displayId, entry);
74
+ }
75
+ }
76
+ }
77
+ const links = extractLinks([...entries.values()]);
78
+ // MSL-T013: check link targets for draft/retired state.
79
+ const linkTargetDiags = (0, link_target_js_1.checkLinkTargets)(entries, links);
80
+ const forward = buildAdjacency(links, (l) => l.from);
81
+ const reverse = buildAdjacency(links, (l) => l.to);
82
+ const diagnostics = [
83
+ ...parseDiagnostics,
84
+ ...validationResult.diagnostics,
85
+ ...linkTargetDiags,
86
+ ];
87
+ return { entries, links, forward, reverse, documents, diagnostics };
88
+ }
89
+ /** Extract traceability links from entry attributes. */
90
+ function extractLinks(entries) {
91
+ const links = [];
92
+ for (const entry of entries) {
93
+ for (const attr of entry.rawAttributes) {
94
+ const extracted = extractLinksFromAttribute(entry.displayId, attr.key, attr.value, entry.location);
95
+ links.push(...extracted);
96
+ }
97
+ }
98
+ return links;
99
+ }
100
+ /**
101
+ * Attributes whose value is `slug + optional free-text locator` per
102
+ * ADR-002 §2.6 (citation type + legacy Derived-from tolerance). The link
103
+ * target is the leading non-whitespace token only.
104
+ */
105
+ const LOCATOR_BEARING_ATTRS = new Set([
106
+ "Derived-from",
107
+ "References",
108
+ ]);
109
+ /** Map an attribute key+value to zero or more links. */
110
+ function extractLinksFromAttribute(from, key, value, location) {
111
+ const kind = ATTR_TO_LINK_KIND[key];
112
+ if (!kind)
113
+ return [];
114
+ if (LOCATOR_BEARING_ATTRS.has(key)) {
115
+ // Format: "ID §section" — extract ID part only.
116
+ const idPart = value.split(/\s/)[0];
117
+ if (idPart) {
118
+ return [{ from, to: idPart, kind, location }];
119
+ }
120
+ return [];
121
+ }
122
+ // Comma-separated targets for id-list attributes.
123
+ return value
124
+ .split(",")
125
+ .map((s) => s.trim())
126
+ .filter((s) => s.length > 0)
127
+ .map((to) => ({ from, to, kind, location }));
128
+ }
129
+ /**
130
+ * Attribute keys that produce traceability links per ADR-002.
131
+ *
132
+ * Spec attributes: Satisfies, Derived-from, References, Allocated-to.
133
+ * Test attributes: Verifies, Tests.
134
+ * Element attributes: Realizes, Depends-on, Part-of, Generated-from.
135
+ * Universal: Supersedes (same-family).
136
+ */
137
+ const ATTR_TO_LINK_KIND = {
138
+ "Satisfies": "satisfies",
139
+ "Derived-from": "derived-from",
140
+ "References": "references",
141
+ "Allocated-to": "allocated-to",
142
+ "Realizes": "realizes",
143
+ "Verifies": "verifies",
144
+ "Tests": "tests",
145
+ "Depends-on": "depends-on",
146
+ "Part-of": "part-of",
147
+ "Generated-from": "generated-from",
148
+ "Supersedes": "supersedes",
149
+ };
150
+ /** Build an adjacency map from links using a key selector. */
151
+ function buildAdjacency(links, keyFn) {
152
+ const map = new Map();
153
+ for (const link of links) {
154
+ const key = keyFn(link);
155
+ let list = map.get(key);
156
+ if (!list) {
157
+ list = [];
158
+ map.set(key, list);
159
+ }
160
+ list.push(link);
161
+ }
162
+ return map;
163
+ }
164
+ // Re-export serialization helper.
165
+ var schema_js_1 = require("./schema.js");
166
+ Object.defineProperty(exports, "serializeCompileResult", { enumerable: true, get: function () { return schema_js_1.serializeCompileResult; } });
167
+ // Re-export inverse generation.
168
+ var inverses_js_2 = require("./inverses.js");
169
+ Object.defineProperty(exports, "generateInverses", { enumerable: true, get: function () { return inverses_js_2.generateInverses; } });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @module schema
3
+ *
4
+ * Serialization helper that converts {@linkcode CompileResult} (which uses
5
+ * Maps) to a plain JSON-serializable object suitable for export and
6
+ * interchange.
7
+ */
8
+ import type { CompileResult } from "./mod.js";
9
+ import type { Diagnostic, Entry, Link } from "../model/mod.js";
10
+ /**
11
+ * Serialized form of {@linkcode CompileResult}.
12
+ *
13
+ * All `ReadonlyMap` fields are converted to plain objects keyed by display ID.
14
+ * Arrays and scalar fields are passed through unchanged.
15
+ */
16
+ export interface SerializedCompileResult {
17
+ /** Entries keyed by display ID. */
18
+ readonly entries: Record<string, Entry>;
19
+ /** All traceability links. */
20
+ readonly links: readonly Link[];
21
+ /** Outgoing links per entry (entry -> targets). */
22
+ readonly forward: Record<string, readonly Link[]>;
23
+ /** Incoming links per entry (entry -> sources pointing to it). */
24
+ readonly reverse: Record<string, readonly Link[]>;
25
+ /** Diagnostics from parsing and validation. */
26
+ readonly diagnostics: readonly Diagnostic[];
27
+ }
28
+ /**
29
+ * Convert a {@linkcode CompileResult} to a plain JSON-serializable object.
30
+ *
31
+ * Maps are converted to `Record` objects keyed by display ID; arrays and
32
+ * scalars pass through unchanged.
33
+ *
34
+ * @param result - The compiled project output
35
+ * @returns A plain object safe for `JSON.stringify`
36
+ */
37
+ export declare function serializeCompileResult(result: CompileResult): SerializedCompileResult;
38
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/compiler/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,mCAAmC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,mDAAmD;IACnD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,aAAa,GACpB,uBAAuB,CAazB"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * @module schema
4
+ *
5
+ * Serialization helper that converts {@linkcode CompileResult} (which uses
6
+ * Maps) to a plain JSON-serializable object suitable for export and
7
+ * interchange.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.serializeCompileResult = serializeCompileResult;
11
+ /**
12
+ * Convert a {@linkcode CompileResult} to a plain JSON-serializable object.
13
+ *
14
+ * Maps are converted to `Record` objects keyed by display ID; arrays and
15
+ * scalars pass through unchanged.
16
+ *
17
+ * @param result - The compiled project output
18
+ * @returns A plain object safe for `JSON.stringify`
19
+ */
20
+ function serializeCompileResult(result) {
21
+ const rawEntries = Object.fromEntries(result.entries);
22
+ const entries = {};
23
+ for (const [key, entry] of Object.entries(rawEntries)) {
24
+ entries[key] = serializeEntry(entry);
25
+ }
26
+ return {
27
+ entries,
28
+ links: result.links,
29
+ forward: Object.fromEntries(result.forward),
30
+ reverse: Object.fromEntries(result.reverse),
31
+ diagnostics: result.diagnostics,
32
+ };
33
+ }
34
+ /**
35
+ * Convert an {@linkcode Entry} to a JSON-safe form by replacing
36
+ * `typedAttributes` (a `ReadonlyMap`) with a plain object.
37
+ */
38
+ function serializeEntry(entry) {
39
+ if (!entry.typedAttributes || entry.typedAttributes.size === 0) {
40
+ return entry;
41
+ }
42
+ const typedObj = Object.fromEntries(entry.typedAttributes);
43
+ return {
44
+ ...entry,
45
+ typedAttributes: typedObj,
46
+ };
47
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @module core/config/markspec
3
+ *
4
+ * Load and validate `.markspec.yaml` — the consumer-project binding that
5
+ * declares which profiles the project uses.
6
+ *
7
+ * Emits diagnostics (MARKSPEC-YAML-*) on parse or schema errors. See
8
+ * [spec §7.6](../../../../docs/superpowers/specs/2026-04-21-adr-008-profile-system-v1-design.md).
9
+ */
10
+ import type { Diagnostic, ProfileSpecifier } from "../model/mod.js";
11
+ import type { ReadFile } from "./mod.js";
12
+ /** The consumer-binding config filename, placed next to `project.yaml`. */
13
+ export declare const MARKSPEC_YAML_FILENAME = ".markspec.yaml";
14
+ /**
15
+ * Read a `.markspec.yaml` file at the given project root.
16
+ *
17
+ * @param projectRoot - Absolute path to the directory containing `project.yaml`
18
+ * @param readFile - File reader (returns `undefined` when missing)
19
+ * @returns Raw file contents, or `null` when the file is absent
20
+ */
21
+ export declare function readMarkspecYaml(projectRoot: string, readFile: ReadFile): Promise<string | null>;
22
+ /** The parsed content of a `.markspec.yaml`. */
23
+ export interface MarkspecYaml {
24
+ readonly profiles: readonly ProfileSpecifier[];
25
+ }
26
+ /** Result of parsing a `.markspec.yaml` string. */
27
+ export interface ParseMarkspecYamlResult {
28
+ readonly config: MarkspecYaml | null;
29
+ readonly diagnostics: readonly Diagnostic[];
30
+ }
31
+ /**
32
+ * Parse and validate a `.markspec.yaml` string.
33
+ *
34
+ * - `MARKSPEC-YAML-002` — YAML parse error.
35
+ * - `MARKSPEC-YAML-003` — schema error (wrong type, bad specifier).
36
+ * - `MARKSPEC-YAML-001` — unknown top-level key (warning; config still produced).
37
+ */
38
+ export declare function parseMarkspecYaml(rawYaml: string, sourcePath: string): ParseMarkspecYamlResult;
39
+ /** Injectable file writer for addProfileSpecifier. */
40
+ export type WriteFile = (path: string, content: string) => Promise<void>;
41
+ /**
42
+ * Append a profile specifier to `.markspec.yaml`.
43
+ *
44
+ * - File absent: creates with `profiles:\n - <specifier>\n`.
45
+ * - File exists with `profiles:` key: appends after the last list entry.
46
+ * - File exists without `profiles:` key: appends the block at end of file.
47
+ *
48
+ * Uses raw string manipulation to preserve user comments and formatting.
49
+ */
50
+ export declare function addProfileSpecifier(specifier: string, readFileFn: ReadFile, writeFileFn: WriteFile, projectRoot: string): Promise<void>;
51
+ //# sourceMappingURL=markspec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markspec.d.ts","sourceRoot":"","sources":["../../src/config/markspec.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,mBAAmB,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAIxB;AAMD,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAChD;AAED,mDAAmD;AACnD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAID;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,uBAAuB,CA8EzB;AAgFD,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,QAAQ,EACpB,WAAW,EAAE,SAAS,EACtB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAiDf"}
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/config/markspec
4
+ *
5
+ * Load and validate `.markspec.yaml` — the consumer-project binding that
6
+ * declares which profiles the project uses.
7
+ *
8
+ * Emits diagnostics (MARKSPEC-YAML-*) on parse or schema errors. See
9
+ * [spec §7.6](../../../../docs/superpowers/specs/2026-04-21-adr-008-profile-system-v1-design.md).
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MARKSPEC_YAML_FILENAME = void 0;
13
+ exports.readMarkspecYaml = readMarkspecYaml;
14
+ exports.parseMarkspecYaml = parseMarkspecYaml;
15
+ exports.addProfileSpecifier = addProfileSpecifier;
16
+ const yaml_1 = require("@std/yaml");
17
+ const path_1 = require("@std/path");
18
+ /** The consumer-binding config filename, placed next to `project.yaml`. */
19
+ exports.MARKSPEC_YAML_FILENAME = ".markspec.yaml";
20
+ /**
21
+ * Read a `.markspec.yaml` file at the given project root.
22
+ *
23
+ * @param projectRoot - Absolute path to the directory containing `project.yaml`
24
+ * @param readFile - File reader (returns `undefined` when missing)
25
+ * @returns Raw file contents, or `null` when the file is absent
26
+ */
27
+ async function readMarkspecYaml(projectRoot, readFile) {
28
+ const path = (0, path_1.join)(projectRoot, exports.MARKSPEC_YAML_FILENAME);
29
+ const content = await readFile(path);
30
+ return content ?? null;
31
+ }
32
+ const ALLOWED_MARKSPEC_YAML_KEYS = new Set(["profiles"]);
33
+ /**
34
+ * Parse and validate a `.markspec.yaml` string.
35
+ *
36
+ * - `MARKSPEC-YAML-002` — YAML parse error.
37
+ * - `MARKSPEC-YAML-003` — schema error (wrong type, bad specifier).
38
+ * - `MARKSPEC-YAML-001` — unknown top-level key (warning; config still produced).
39
+ */
40
+ function parseMarkspecYaml(rawYaml, sourcePath) {
41
+ const diagnostics = [];
42
+ // Empty file is equivalent to `profiles: []`
43
+ const trimmed = rawYaml.trim();
44
+ if (trimmed.length === 0) {
45
+ return { config: { profiles: [] }, diagnostics };
46
+ }
47
+ let parsed;
48
+ try {
49
+ parsed = (0, yaml_1.parse)(rawYaml);
50
+ }
51
+ catch (err) {
52
+ const message = err instanceof Error ? err.message : String(err);
53
+ diagnostics.push({
54
+ code: "MARKSPEC-YAML-002",
55
+ severity: "error",
56
+ message: `.markspec.yaml: YAML parse error: ${message}`,
57
+ location: { file: sourcePath, line: 1, column: 1 },
58
+ });
59
+ return { config: null, diagnostics };
60
+ }
61
+ if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
62
+ diagnostics.push({
63
+ code: "MARKSPEC-YAML-003",
64
+ severity: "error",
65
+ message: ".markspec.yaml must be a YAML mapping",
66
+ location: { file: sourcePath, line: 1, column: 1 },
67
+ });
68
+ return { config: null, diagnostics };
69
+ }
70
+ const root = parsed;
71
+ // Unknown keys — warn, but continue parsing.
72
+ for (const key of Object.keys(root)) {
73
+ if (!ALLOWED_MARKSPEC_YAML_KEYS.has(key)) {
74
+ diagnostics.push({
75
+ code: "MARKSPEC-YAML-001",
76
+ severity: "warning",
77
+ message: `.markspec.yaml: unknown top-level key '${key}'`,
78
+ location: { file: sourcePath, line: 1, column: 1 },
79
+ });
80
+ }
81
+ }
82
+ const rawProfiles = root.profiles;
83
+ if (rawProfiles !== undefined && !Array.isArray(rawProfiles)) {
84
+ diagnostics.push({
85
+ code: "MARKSPEC-YAML-003",
86
+ severity: "error",
87
+ message: ".markspec.yaml: 'profiles' must be a list",
88
+ location: { file: sourcePath, line: 1, column: 1 },
89
+ });
90
+ return { config: null, diagnostics };
91
+ }
92
+ const profiles = [];
93
+ if (Array.isArray(rawProfiles)) {
94
+ for (let i = 0; i < rawProfiles.length; i++) {
95
+ const spec = parseProfileSpecifier(rawProfiles[i], `.markspec.yaml: profiles[${i}]`, sourcePath, diagnostics);
96
+ if (spec)
97
+ profiles.push(spec);
98
+ }
99
+ }
100
+ // If any specifier failed to parse, treat the whole file as invalid.
101
+ const hasErrors = diagnostics.some((d) => d.severity === "error");
102
+ if (hasErrors) {
103
+ return { config: null, diagnostics };
104
+ }
105
+ return { config: { profiles }, diagnostics };
106
+ }
107
+ /**
108
+ * Parse a single specifier string into a {@linkcode ProfileSpecifier}.
109
+ * Emits `MARKSPEC-YAML-003` on malformed input.
110
+ */
111
+ function parseProfileSpecifier(raw, context, sourcePath, diagnostics) {
112
+ if (typeof raw !== "string" || raw.length === 0) {
113
+ diagnostics.push({
114
+ code: "MARKSPEC-YAML-003",
115
+ severity: "error",
116
+ message: `${context}: specifier must be a non-empty string`,
117
+ location: { file: sourcePath, line: 1, column: 1 },
118
+ });
119
+ return undefined;
120
+ }
121
+ if (raw.startsWith("./") || raw.startsWith("../")) {
122
+ return { kind: "local", path: raw };
123
+ }
124
+ if (raw.startsWith("git+")) {
125
+ const m = /^git\+((?:https?|file):\/\/[^#]+?\.git)(\/[^#]+)?#(.+)$/.exec(raw);
126
+ if (!m) {
127
+ diagnostics.push({
128
+ code: "MARKSPEC-YAML-003",
129
+ severity: "error",
130
+ message: `${context}: git specifier malformed; expected git+<https|file>://host/.git[/subpath]#<tag>`,
131
+ location: { file: sourcePath, line: 1, column: 1 },
132
+ });
133
+ return undefined;
134
+ }
135
+ const [, repo, rawSubpath, tag] = m;
136
+ const subpath = rawSubpath ? rawSubpath.slice(1) : undefined;
137
+ return { kind: "git", repo, subpath, tag };
138
+ }
139
+ if (raw.startsWith("npm:")) {
140
+ // npm:@scope/name@range or npm:name@range
141
+ const body = raw.slice(4); // strip "npm:"
142
+ const scopedMatch = /^(@[a-z0-9-]+\/[a-z0-9-]+)@(.+)$/.exec(body);
143
+ if (scopedMatch) {
144
+ const [, fullName, range] = scopedMatch;
145
+ const slashIdx = fullName.indexOf("/");
146
+ return {
147
+ kind: "npm",
148
+ scope: fullName.slice(0, slashIdx),
149
+ name: fullName.slice(slashIdx + 1),
150
+ range,
151
+ };
152
+ }
153
+ const unscopedMatch = /^([a-z0-9-]+)@(.+)$/.exec(body);
154
+ if (unscopedMatch) {
155
+ const [, name, range] = unscopedMatch;
156
+ return { kind: "npm", name, range };
157
+ }
158
+ diagnostics.push({
159
+ code: "MARKSPEC-YAML-003",
160
+ severity: "error",
161
+ message: `${context}: npm specifier malformed; expected npm:[@scope/]name@<version-range>`,
162
+ location: { file: sourcePath, line: 1, column: 1 },
163
+ });
164
+ return undefined;
165
+ }
166
+ diagnostics.push({
167
+ code: "MARKSPEC-YAML-003",
168
+ severity: "error",
169
+ message: `${context}: unsupported specifier scheme (use './path', 'git+<https|file>://…#<tag>', or 'npm:[@scope/]name@<range>')`,
170
+ location: { file: sourcePath, line: 1, column: 1 },
171
+ });
172
+ return undefined;
173
+ }
174
+ /**
175
+ * Append a profile specifier to `.markspec.yaml`.
176
+ *
177
+ * - File absent: creates with `profiles:\n - <specifier>\n`.
178
+ * - File exists with `profiles:` key: appends after the last list entry.
179
+ * - File exists without `profiles:` key: appends the block at end of file.
180
+ *
181
+ * Uses raw string manipulation to preserve user comments and formatting.
182
+ */
183
+ async function addProfileSpecifier(specifier, readFileFn, writeFileFn, projectRoot) {
184
+ const filePath = (0, path_1.join)(projectRoot, exports.MARKSPEC_YAML_FILENAME);
185
+ const existing = await readFileFn(filePath);
186
+ if (existing === undefined) {
187
+ await writeFileFn(filePath, `profiles:\n - "${specifier}"\n`);
188
+ return;
189
+ }
190
+ const profilesIdx = existing.indexOf("profiles:");
191
+ if (profilesIdx === -1) {
192
+ const trailing = existing.endsWith("\n") ? "" : "\n";
193
+ await writeFileFn(filePath, existing + trailing + `\nprofiles:\n - "${specifier}"\n`);
194
+ return;
195
+ }
196
+ const lines = existing.split("\n");
197
+ let lastEntryLine = -1;
198
+ let inProfiles = false;
199
+ for (let i = 0; i < lines.length; i++) {
200
+ if (lines[i].trimStart().startsWith("profiles:")) {
201
+ inProfiles = true;
202
+ continue;
203
+ }
204
+ if (inProfiles) {
205
+ if (/^\s+-\s/.test(lines[i])) {
206
+ lastEntryLine = i;
207
+ }
208
+ else if (lines[i].trim().length > 0 && !lines[i].startsWith(" ") &&
209
+ !lines[i].startsWith("#")) {
210
+ break;
211
+ }
212
+ }
213
+ }
214
+ if (lastEntryLine >= 0) {
215
+ lines.splice(lastEntryLine + 1, 0, ` - "${specifier}"`);
216
+ }
217
+ else {
218
+ const profilesLine = lines.findIndex((l) => l.trimStart().startsWith("profiles:"));
219
+ lines.splice(profilesLine + 1, 0, ` - "${specifier}"`);
220
+ }
221
+ await writeFileFn(filePath, lines.join("\n"));
222
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module config
3
+ *
4
+ * Project discovery and configuration loading. Walks up from CWD to
5
+ * find `project.yaml`, parses the YAML, and validates the schema.
6
+ */
7
+ import { type ProjectConfig } from "../model/mod.js";
8
+ /** The config file name used as the project root marker. */
9
+ export declare const CONFIG_FILE_NAME = "project.yaml";
10
+ /** Result of loading a project configuration. */
11
+ export interface LoadConfigResult {
12
+ /** The parsed and validated configuration. */
13
+ readonly config: ProjectConfig;
14
+ /** Absolute path to the project root directory. */
15
+ readonly projectRoot: string;
16
+ /** Absolute path to the `project.yaml` file. */
17
+ readonly configPath: string;
18
+ }
19
+ /** A function that reads a file and returns its content, or `undefined` if not found. */
20
+ export type ReadFile = (path: string) => Promise<string | undefined>;
21
+ /**
22
+ * Walk up from `startDir` to the filesystem root looking for `project.yaml`.
23
+ *
24
+ * @returns Absolute path to the directory containing `project.yaml`,
25
+ * or `undefined` if not found.
26
+ */
27
+ export declare function discoverProjectRoot(startDir: string, readFile: ReadFile): Promise<string | undefined>;
28
+ /**
29
+ * Parse a YAML string and validate it as a MarkSpec project configuration.
30
+ *
31
+ * @param yaml - Raw YAML content
32
+ * @param filePath - Path to the file (for error messages)
33
+ * @returns Validated `ProjectConfig`
34
+ * @throws {ConfigError} on invalid content
35
+ */
36
+ export declare function parseProjectConfig(yaml: string, filePath: string): ProjectConfig;
37
+ /**
38
+ * Derive a 3-6 letter project domain abbreviation from the project name.
39
+ */
40
+ export declare function deriveDomain(projectName: string): string;
41
+ /**
42
+ * Discover `project.yaml` by walking up from `startDir`, load, and validate.
43
+ *
44
+ * @returns `LoadConfigResult` if found and valid, `undefined` if not found.
45
+ * @throws {ConfigError} if `project.yaml` exists but is invalid.
46
+ */
47
+ export declare function loadConfig(startDir: string, readFile: ReadFile): Promise<LoadConfigResult | undefined>;
48
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/config/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,yFAAyF;AACzF,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAMrE;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU7B;AAsBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,aAAa,CAwIf;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAMD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC"}