@driftsys/markspec 0.2.0 → 0.4.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 (214) hide show
  1. package/README.md +32 -8
  2. package/esm/compiler/inverses.d.ts +22 -0
  3. package/esm/compiler/inverses.d.ts.map +1 -0
  4. package/esm/compiler/inverses.js +147 -0
  5. package/esm/compiler/link_target.d.ts +19 -0
  6. package/esm/compiler/link_target.d.ts.map +1 -0
  7. package/esm/compiler/link_target.js +66 -0
  8. package/esm/compiler/mod.d.ts +7 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +61 -14
  11. package/esm/compiler/schema.d.ts.map +1 -1
  12. package/esm/compiler/schema.js +20 -1
  13. package/esm/config/markspec.d.ts +51 -0
  14. package/esm/config/markspec.d.ts.map +1 -0
  15. package/esm/config/markspec.js +216 -0
  16. package/esm/config/mod.d.ts +4 -0
  17. package/esm/config/mod.d.ts.map +1 -1
  18. package/esm/config/mod.js +27 -16
  19. package/esm/formatter/mod.d.ts +19 -4
  20. package/esm/formatter/mod.d.ts.map +1 -1
  21. package/esm/formatter/mod.js +139 -29
  22. package/esm/mod.d.ts +11 -7
  23. package/esm/mod.d.ts.map +1 -1
  24. package/esm/mod.js +6 -3
  25. package/esm/model/attributes.d.ts +47 -0
  26. package/esm/model/attributes.d.ts.map +1 -0
  27. package/esm/model/attributes.js +97 -0
  28. package/esm/model/mod.d.ts +257 -26
  29. package/esm/model/mod.d.ts.map +1 -1
  30. package/esm/model/mod.js +28 -1
  31. package/esm/model/palette.d.ts +18 -0
  32. package/esm/model/palette.d.ts.map +1 -0
  33. package/esm/model/palette.js +23 -0
  34. package/esm/model/profile.d.ts +189 -0
  35. package/esm/model/profile.d.ts.map +1 -0
  36. package/esm/model/profile.js +31 -0
  37. package/esm/parser/attributes.d.ts +13 -1
  38. package/esm/parser/attributes.d.ts.map +1 -1
  39. package/esm/parser/attributes.js +47 -0
  40. package/esm/parser/frontmatter.d.ts +53 -0
  41. package/esm/parser/frontmatter.d.ts.map +1 -0
  42. package/esm/parser/frontmatter.js +185 -0
  43. package/esm/parser/grammars.js +11 -2
  44. package/esm/parser/markdown.d.ts +21 -7
  45. package/esm/parser/markdown.d.ts.map +1 -1
  46. package/esm/parser/markdown.js +101 -40
  47. package/esm/parser/mod.d.ts +26 -10
  48. package/esm/parser/mod.d.ts.map +1 -1
  49. package/esm/parser/mod.js +40 -10
  50. package/esm/parser/source.d.ts +12 -8
  51. package/esm/parser/source.d.ts.map +1 -1
  52. package/esm/parser/source.js +21 -14
  53. package/esm/profile/cache.d.ts +29 -0
  54. package/esm/profile/cache.d.ts.map +1 -0
  55. package/esm/profile/cache.js +45 -0
  56. package/esm/profile/chain.d.ts +42 -0
  57. package/esm/profile/chain.d.ts.map +1 -0
  58. package/esm/profile/chain.js +193 -0
  59. package/esm/profile/colors.d.ts +26 -0
  60. package/esm/profile/colors.d.ts.map +1 -0
  61. package/esm/profile/colors.js +46 -0
  62. package/esm/profile/git-cache.d.ts +73 -0
  63. package/esm/profile/git-cache.d.ts.map +1 -0
  64. package/esm/profile/git-cache.js +96 -0
  65. package/esm/profile/load.d.ts +28 -0
  66. package/esm/profile/load.d.ts.map +1 -0
  67. package/esm/profile/load.js +50 -0
  68. package/esm/profile/manifest.d.ts +21 -0
  69. package/esm/profile/manifest.d.ts.map +1 -0
  70. package/esm/profile/manifest.js +815 -0
  71. package/esm/profile/merge.d.ts +26 -0
  72. package/esm/profile/merge.d.ts.map +1 -0
  73. package/esm/profile/merge.js +518 -0
  74. package/esm/profile/mod.d.ts +24 -0
  75. package/esm/profile/mod.d.ts.map +1 -0
  76. package/esm/profile/mod.js +15 -0
  77. package/esm/profile/npm.d.ts +51 -0
  78. package/esm/profile/npm.d.ts.map +1 -0
  79. package/esm/profile/npm.js +186 -0
  80. package/esm/profile/resolver.d.ts +60 -0
  81. package/esm/profile/resolver.d.ts.map +1 -0
  82. package/esm/profile/resolver.js +132 -0
  83. package/esm/reporter/mod.js +14 -27
  84. package/esm/validator/attributes.d.ts +43 -0
  85. package/esm/validator/attributes.d.ts.map +1 -0
  86. package/esm/validator/attributes.js +169 -0
  87. package/esm/validator/mod.d.ts +27 -6
  88. package/esm/validator/mod.d.ts.map +1 -1
  89. package/esm/validator/mod.js +132 -124
  90. package/esm/validator/normalize.d.ts +21 -0
  91. package/esm/validator/normalize.d.ts.map +1 -0
  92. package/esm/validator/normalize.js +58 -0
  93. package/esm/validator/pattern.d.ts +23 -0
  94. package/esm/validator/pattern.d.ts.map +1 -0
  95. package/esm/validator/pattern.js +44 -0
  96. package/esm/validator/pipeline.d.ts +30 -0
  97. package/esm/validator/pipeline.d.ts.map +1 -0
  98. package/esm/validator/pipeline.js +115 -0
  99. package/esm/validator/traceability.d.ts +48 -0
  100. package/esm/validator/traceability.d.ts.map +1 -0
  101. package/esm/validator/traceability.js +141 -0
  102. package/esm/validator/types.d.ts +48 -0
  103. package/esm/validator/types.d.ts.map +1 -0
  104. package/esm/validator/types.js +140 -0
  105. package/esm/validator/value_types.d.ts +20 -0
  106. package/esm/validator/value_types.d.ts.map +1 -0
  107. package/esm/validator/value_types.js +126 -0
  108. package/package.json +1 -1
  109. package/script/compiler/inverses.d.ts +22 -0
  110. package/script/compiler/inverses.d.ts.map +1 -0
  111. package/script/compiler/inverses.js +150 -0
  112. package/script/compiler/link_target.d.ts +19 -0
  113. package/script/compiler/link_target.d.ts.map +1 -0
  114. package/script/compiler/link_target.js +69 -0
  115. package/script/compiler/mod.d.ts +7 -1
  116. package/script/compiler/mod.d.ts.map +1 -1
  117. package/script/compiler/mod.js +62 -14
  118. package/script/compiler/schema.d.ts.map +1 -1
  119. package/script/compiler/schema.js +20 -1
  120. package/script/config/markspec.d.ts +51 -0
  121. package/script/config/markspec.d.ts.map +1 -0
  122. package/script/config/markspec.js +222 -0
  123. package/script/config/mod.d.ts +4 -0
  124. package/script/config/mod.d.ts.map +1 -1
  125. package/script/config/mod.js +28 -16
  126. package/script/formatter/mod.d.ts +19 -4
  127. package/script/formatter/mod.d.ts.map +1 -1
  128. package/script/formatter/mod.js +140 -29
  129. package/script/mod.d.ts +11 -7
  130. package/script/mod.d.ts.map +1 -1
  131. package/script/mod.js +50 -19
  132. package/script/model/attributes.d.ts +47 -0
  133. package/script/model/attributes.d.ts.map +1 -0
  134. package/script/model/attributes.js +101 -0
  135. package/script/model/mod.d.ts +257 -26
  136. package/script/model/mod.d.ts.map +1 -1
  137. package/script/model/mod.js +37 -2
  138. package/script/model/palette.d.ts +18 -0
  139. package/script/model/palette.d.ts.map +1 -0
  140. package/script/model/palette.js +26 -0
  141. package/script/model/profile.d.ts +189 -0
  142. package/script/model/profile.d.ts.map +1 -0
  143. package/script/model/profile.js +34 -0
  144. package/script/parser/attributes.d.ts +13 -1
  145. package/script/parser/attributes.d.ts.map +1 -1
  146. package/script/parser/attributes.js +48 -0
  147. package/script/parser/frontmatter.d.ts +53 -0
  148. package/script/parser/frontmatter.d.ts.map +1 -0
  149. package/script/parser/frontmatter.js +188 -0
  150. package/script/parser/grammars.js +11 -2
  151. package/script/parser/markdown.d.ts +21 -7
  152. package/script/parser/markdown.d.ts.map +1 -1
  153. package/script/parser/markdown.js +100 -39
  154. package/script/parser/mod.d.ts +26 -10
  155. package/script/parser/mod.d.ts.map +1 -1
  156. package/script/parser/mod.js +42 -11
  157. package/script/parser/source.d.ts +12 -8
  158. package/script/parser/source.d.ts.map +1 -1
  159. package/script/parser/source.js +21 -14
  160. package/script/profile/cache.d.ts +29 -0
  161. package/script/profile/cache.d.ts.map +1 -0
  162. package/script/profile/cache.js +48 -0
  163. package/script/profile/chain.d.ts +42 -0
  164. package/script/profile/chain.d.ts.map +1 -0
  165. package/script/profile/chain.js +229 -0
  166. package/script/profile/colors.d.ts +26 -0
  167. package/script/profile/colors.d.ts.map +1 -0
  168. package/script/profile/colors.js +49 -0
  169. package/script/profile/git-cache.d.ts +73 -0
  170. package/script/profile/git-cache.d.ts.map +1 -0
  171. package/script/profile/git-cache.js +104 -0
  172. package/script/profile/load.d.ts +28 -0
  173. package/script/profile/load.d.ts.map +1 -0
  174. package/script/profile/load.js +53 -0
  175. package/script/profile/manifest.d.ts +21 -0
  176. package/script/profile/manifest.d.ts.map +1 -0
  177. package/script/profile/manifest.js +818 -0
  178. package/script/profile/merge.d.ts +26 -0
  179. package/script/profile/merge.d.ts.map +1 -0
  180. package/script/profile/merge.js +521 -0
  181. package/script/profile/mod.d.ts +24 -0
  182. package/script/profile/mod.d.ts.map +1 -0
  183. package/script/profile/mod.js +33 -0
  184. package/script/profile/npm.d.ts +51 -0
  185. package/script/profile/npm.d.ts.map +1 -0
  186. package/script/profile/npm.js +191 -0
  187. package/script/profile/resolver.d.ts +60 -0
  188. package/script/profile/resolver.d.ts.map +1 -0
  189. package/script/profile/resolver.js +136 -0
  190. package/script/reporter/mod.js +14 -27
  191. package/script/validator/attributes.d.ts +43 -0
  192. package/script/validator/attributes.d.ts.map +1 -0
  193. package/script/validator/attributes.js +173 -0
  194. package/script/validator/mod.d.ts +27 -6
  195. package/script/validator/mod.d.ts.map +1 -1
  196. package/script/validator/mod.js +145 -123
  197. package/script/validator/normalize.d.ts +21 -0
  198. package/script/validator/normalize.d.ts.map +1 -0
  199. package/script/validator/normalize.js +61 -0
  200. package/script/validator/pattern.d.ts +23 -0
  201. package/script/validator/pattern.d.ts.map +1 -0
  202. package/script/validator/pattern.js +47 -0
  203. package/script/validator/pipeline.d.ts +30 -0
  204. package/script/validator/pipeline.d.ts.map +1 -0
  205. package/script/validator/pipeline.js +118 -0
  206. package/script/validator/traceability.d.ts +48 -0
  207. package/script/validator/traceability.d.ts.map +1 -0
  208. package/script/validator/traceability.js +146 -0
  209. package/script/validator/types.d.ts +48 -0
  210. package/script/validator/types.d.ts.map +1 -0
  211. package/script/validator/types.js +144 -0
  212. package/script/validator/value_types.d.ts +20 -0
  213. package/script/validator/value_types.d.ts.map +1 -0
  214. package/script/validator/value_types.js +129 -0
@@ -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
+ }
@@ -34,6 +34,10 @@ export declare function discoverProjectRoot(startDir: string, readFile: ReadFile
34
34
  * @throws {ConfigError} on invalid content
35
35
  */
36
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;
37
41
  /**
38
42
  * Discover `project.yaml` by walking up from `startDir`, load, and validate.
39
43
  *
@@ -1 +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,CAuJf;AAMD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC"}
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"}
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.CONFIG_FILE_NAME = void 0;
10
10
  exports.discoverProjectRoot = discoverProjectRoot;
11
11
  exports.parseProjectConfig = parseProjectConfig;
12
+ exports.deriveDomain = deriveDomain;
12
13
  exports.loadConfig = loadConfig;
13
14
  const yaml_1 = require("@std/yaml");
14
15
  const path_1 = require("@std/path");
@@ -103,21 +104,7 @@ function parseProjectConfig(yaml, filePath) {
103
104
  line: findLineNumber(yaml, "name"),
104
105
  });
105
106
  }
106
- // domain: optional, must match ^[A-Z]{2,6}$
107
- let domain = mod_js_1.DEFAULT_PROJECT_CONFIG.domain;
108
- if (obj.domain !== undefined && obj.domain !== null) {
109
- if (typeof obj.domain !== "string" || !/^[A-Z]{2,6}$/.test(obj.domain)) {
110
- errors.push({
111
- field: "domain",
112
- message: "must be 2-6 uppercase letters (e.g., BRK), got " +
113
- JSON.stringify(obj.domain),
114
- line: findLineNumber(yaml, "domain"),
115
- });
116
- }
117
- else {
118
- domain = obj.domain;
119
- }
120
- }
107
+ // version: optional string
121
108
  // version: optional string
122
109
  let version = mod_js_1.DEFAULT_PROJECT_CONFIG.version;
123
110
  if (obj.version !== undefined && obj.version !== null) {
@@ -197,7 +184,6 @@ function parseProjectConfig(yaml, filePath) {
197
184
  }
198
185
  return {
199
186
  name: obj.name,
200
- domain,
201
187
  version,
202
188
  labels,
203
189
  parents,
@@ -205,6 +191,32 @@ function parseProjectConfig(yaml, filePath) {
205
191
  };
206
192
  }
207
193
  // ---------------------------------------------------------------------------
194
+ // Domain derivation
195
+ // ---------------------------------------------------------------------------
196
+ /**
197
+ * Derive a 3-6 letter project domain abbreviation from the project name.
198
+ */
199
+ function deriveDomain(projectName) {
200
+ const lastSegment = projectName.split(".").pop() ?? projectName;
201
+ const words = lastSegment.split(/[-_]+/).filter((w) => w.length > 0);
202
+ if (words.length === 0) {
203
+ return "XXXXX";
204
+ }
205
+ const charsPerWord = Math.ceil(6 / words.length);
206
+ const abbrev = words
207
+ .map((word) => word.slice(0, charsPerWord).toUpperCase())
208
+ .join("");
209
+ if (abbrev.length >= 3 && abbrev.length <= 6) {
210
+ return abbrev;
211
+ }
212
+ else if (abbrev.length > 6) {
213
+ return abbrev.slice(0, 6);
214
+ }
215
+ else {
216
+ return (abbrev + "XXXXXX").slice(0, 6);
217
+ }
218
+ }
219
+ // ---------------------------------------------------------------------------
208
220
  // Combined load
209
221
  // ---------------------------------------------------------------------------
210
222
  /**
@@ -32,13 +32,28 @@ export interface FormatResult {
32
32
  */
33
33
  export declare function format(markdown: string, options?: FormatOptions): FormatResult;
34
34
  /**
35
- * Sort attributes to canonical order.
36
- * Unknown keys are placed before Labels, preserving their relative order.
35
+ * Expand CSV values on repeatable-type attributes into one entry per value
36
+ * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
37
+ * but must round-trip as multi-line output; `citation` is left alone
38
+ * because locators may contain commas.
39
+ */
40
+ export declare function expandCsvValues(attrs: Attribute[]): Attribute[];
41
+ /**
42
+ * Sort attributes to canonical order per the language spec.
43
+ *
44
+ * `Id:` first, then profile-declared/unknown keys in source order, then
45
+ * universal attributes (References / Labels / External-id / Supersedes /
46
+ * Superseded-by / Deprecated).
37
47
  */
38
48
  export declare function sortAttributes(attributes: Attribute[]): Attribute[];
39
49
  /**
40
- * Render attributes as indented `Key: Value\` lines.
41
- * Trailing backslash on all lines except the last.
50
+ * Render attributes as an indented code block.
51
+ * Each line is `Key: Value` at (indent + 4) absolute columns;
52
+ * no trailing line-continuation characters.
53
+ *
54
+ * @param attributes - The attributes to render, in canonical order.
55
+ * @param indent - Body indent for the entry (2 for list-wrapped entries,
56
+ * 0 for entries inside source-file doc comments).
42
57
  */
43
58
  export declare function renderAttributeBlock(attributes: Attribute[], indent: number): string;
44
59
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAS,MAAM,iBAAiB,CAAC;AAiBpE,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CACtC;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CA6Dd;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAmCnE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAQR;AA2BD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B5C"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AAyDzB,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;CACtC;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CA8Ed;AA8BD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAmB/D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,SAAS,EAAE,CAmCb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAKR;AA2BD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B5C"}
@@ -8,23 +8,63 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.format = format;
11
+ exports.expandCsvValues = expandCsvValues;
11
12
  exports.sortAttributes = sortAttributes;
12
13
  exports.renderAttributeBlock = renderAttributeBlock;
13
14
  exports.findAttributeBlockRange = findAttributeBlockRange;
14
15
  const ulid_1 = require("@std/ulid");
16
+ const yaml_1 = require("@std/yaml");
17
+ const mod_js_1 = require("../model/mod.js");
15
18
  const attributes_js_1 = require("../parser/attributes.js");
19
+ const frontmatter_js_1 = require("../parser/frontmatter.js");
16
20
  const markdown_js_1 = require("../parser/markdown.js");
17
- /** Canonical attribute ordering. Unknown keys go before Labels. */
21
+ /**
22
+ * Value types that accept CSV on input but must be emitted as multi-line
23
+ * per ADR-002 §2.6. `citation` is deliberately excluded because locators
24
+ * may contain commas.
25
+ */
26
+ const CSV_SPLITTABLE_TYPES = new Set([
27
+ "id-list",
28
+ "tag-list",
29
+ "external-id",
30
+ ]);
31
+ /**
32
+ * Canonical front-matter key order per ADR-007. Core keys first, then
33
+ * `metadata` (reserved free-form map), then `extra` (allowlisted ecosystem
34
+ * keys / profile keys) are emitted verbatim at the end.
35
+ */
36
+ const FRONT_MATTER_CORE_ORDER = [
37
+ "document-id",
38
+ "document-type",
39
+ "labels",
40
+ "deprecated",
41
+ "external-id",
42
+ "supersedes",
43
+ "references",
44
+ ];
45
+ /**
46
+ * Canonical attribute ordering per the language spec.
47
+ *
48
+ * Identity (`Id:`) comes first, then profile-declared attributes appear in
49
+ * the order the author wrote them (or in the order a profile-aware pass
50
+ * may rewrite them), then the universal set
51
+ * (References / Labels / External-id / Supersedes / Deprecated). Unknown
52
+ * keys are placed just before `Labels:`, preserving their relative order.
53
+ *
54
+ * A profile-aware formatter may extend this with profile-declared canonical
55
+ * positions; the core formatter only knows about `Id:` and the universal
56
+ * set.
57
+ */
18
58
  const CANONICAL_ORDER = [
19
59
  "Id",
20
- "Satisfies",
21
- "Derived-from",
22
- "Allocates",
23
- "Component",
24
- "Constrains",
25
- "Between",
26
- "Interface",
60
+ // Profile-declared attributes land here in whatever order the source has
61
+ // them; the filler slot keeps them between Id and the universal set.
62
+ "References",
27
63
  "Labels",
64
+ "External-id",
65
+ "Supersedes",
66
+ "Superseded-by",
67
+ "Deprecated",
28
68
  ];
29
69
  /**
30
70
  * Format a Markdown string — normalize attribute blocks,
@@ -36,23 +76,30 @@ const CANONICAL_ORDER = [
36
76
  */
37
77
  function format(markdown, options) {
38
78
  const file = options?.file ?? "<unknown>";
39
- const entries = (0, markdown_js_1.parseMarkdown)(markdown, { file });
40
- if (entries.length === 0) {
41
- return { output: markdown, diagnostics: [], changed: false };
79
+ // Extract any YAML front matter first so entries are parsed against the
80
+ // body only (front-matter `---` could be confused with horizontal rules).
81
+ const fm = (0, frontmatter_js_1.extractFrontMatter)(markdown, { file });
82
+ const body = fm.hadFrontMatter ? fm.markdown : markdown;
83
+ const { entries } = (0, markdown_js_1.parseMarkdown)(body, { file });
84
+ const diagnostics = [...fm.diagnostics];
85
+ if (entries.length === 0 && !fm.hadFrontMatter) {
86
+ return { output: markdown, diagnostics, changed: false };
42
87
  }
43
- const lines = markdown.split("\n");
44
- const diagnostics = [];
88
+ const lines = body.split("\n");
45
89
  let changed = false;
46
90
  // Process bottom-to-top so line splicing doesn't shift earlier entries.
47
91
  const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
48
92
  const genUlid = options?.generateUlid ?? ulid_1.ulid;
49
93
  for (const entry of sorted) {
50
94
  const indent = (entry.location.column - 1) + 2;
51
- let attrs = [...entry.attributes];
52
- // Assign ULID to typed entries missing Id.
53
- if (entry.entryType && !attrs.some((a) => a.key === "Id")) {
54
- const newId = `${entry.entryType}_${genUlid()}`;
55
- attrs = [{ key: "Id", value: newId }, ...attrs];
95
+ let attrs = [...entry.rawAttributes];
96
+ // Assign a bare ULID `Id:` to identified entries that carry no
97
+ // identity yet. Referenced entries are left alone — their `Id:` is a
98
+ // URI that must be author-provided.
99
+ const hasIdentity = attrs.some((a) => a.key === mod_js_1.IDENTITY_KEY);
100
+ if (!hasIdentity && entry.shape === "identified") {
101
+ const newId = genUlid();
102
+ attrs = [{ key: mod_js_1.IDENTITY_KEY, value: newId }, ...attrs];
56
103
  diagnostics.push({
57
104
  code: "MSL-F001",
58
105
  severity: "info",
@@ -62,7 +109,7 @@ function format(markdown, options) {
62
109
  }
63
110
  if (attrs.length === 0)
64
111
  continue;
65
- const normalized = sortAttributes(attrs);
112
+ const normalized = sortAttributes(expandCsvValues(attrs));
66
113
  const range = findAttributeBlockRange(lines, entry.location.line, indent);
67
114
  if (range) {
68
115
  // Replace existing attribute block.
@@ -81,11 +128,73 @@ function format(markdown, options) {
81
128
  changed = true;
82
129
  }
83
130
  }
84
- return { output: lines.join("\n"), diagnostics, changed };
131
+ const formattedBody = lines.join("\n");
132
+ if (fm.hadFrontMatter) {
133
+ const canonicalFm = renderFrontMatter(fm.attributes);
134
+ const output = canonicalFm + formattedBody;
135
+ if (output !== markdown)
136
+ changed = true;
137
+ return { output, diagnostics, changed };
138
+ }
139
+ return { output: formattedBody, diagnostics, changed };
140
+ }
141
+ /**
142
+ * Render {@linkcode DocumentAttributes} as a canonical YAML front matter
143
+ * block. Keys are emitted in canonical order (core → metadata → extra);
144
+ * an `extra` subtree is flattened to top-level keys per ADR-007
145
+ * allowlist conventions.
146
+ */
147
+ function renderFrontMatter(attrs) {
148
+ const ordered = {};
149
+ const a = attrs;
150
+ for (const key of FRONT_MATTER_CORE_ORDER) {
151
+ if (a[key] !== undefined)
152
+ ordered[key] = a[key];
153
+ }
154
+ if (a.metadata !== undefined)
155
+ ordered.metadata = a.metadata;
156
+ if (a.extra && typeof a.extra === "object") {
157
+ for (const [key, value] of Object.entries(a.extra)) {
158
+ ordered[key] = value;
159
+ }
160
+ }
161
+ if (Object.keys(ordered).length === 0) {
162
+ return "---\n---\n\n";
163
+ }
164
+ const yaml = (0, yaml_1.stringify)(ordered).trimEnd();
165
+ return `---\n${yaml}\n---\n\n`;
85
166
  }
86
167
  /**
87
- * Sort attributes to canonical order.
88
- * Unknown keys are placed before Labels, preserving their relative order.
168
+ * Expand CSV values on repeatable-type attributes into one entry per value
169
+ * per ADR-002 §2.6. `id-list` / `tag-list` / `external-id` accept CSV input
170
+ * but must round-trip as multi-line output; `citation` is left alone
171
+ * because locators may contain commas.
172
+ */
173
+ function expandCsvValues(attrs) {
174
+ const result = [];
175
+ for (const attr of attrs) {
176
+ const spec = (0, mod_js_1.attributeSpec)(attr.key);
177
+ if (spec && CSV_SPLITTABLE_TYPES.has(spec.type) && attr.value.includes(",")) {
178
+ const values = attr.value
179
+ .split(",")
180
+ .map((s) => s.trim())
181
+ .filter((s) => s.length > 0);
182
+ for (const value of values) {
183
+ result.push({ key: attr.key, value });
184
+ }
185
+ }
186
+ else {
187
+ result.push(attr);
188
+ }
189
+ }
190
+ return result;
191
+ }
192
+ /**
193
+ * Sort attributes to canonical order per the language spec.
194
+ *
195
+ * `Id:` first, then profile-declared/unknown keys in source order, then
196
+ * universal attributes (References / Labels / External-id / Supersedes /
197
+ * Superseded-by / Deprecated).
89
198
  */
90
199
  function sortAttributes(attributes) {
91
200
  const known = new Array(CANONICAL_ORDER.length);
@@ -121,16 +230,18 @@ function sortAttributes(attributes) {
121
230
  return result;
122
231
  }
123
232
  /**
124
- * Render attributes as indented `Key: Value\` lines.
125
- * Trailing backslash on all lines except the last.
233
+ * Render attributes as an indented code block.
234
+ * Each line is `Key: Value` at (indent + 4) absolute columns;
235
+ * no trailing line-continuation characters.
236
+ *
237
+ * @param attributes - The attributes to render, in canonical order.
238
+ * @param indent - Body indent for the entry (2 for list-wrapped entries,
239
+ * 0 for entries inside source-file doc comments).
126
240
  */
127
241
  function renderAttributeBlock(attributes, indent) {
128
- const prefix = " ".repeat(indent);
242
+ const prefix = " ".repeat(indent + 4);
129
243
  return attributes
130
- .map((attr, i) => {
131
- const sep = i < attributes.length - 1 ? "\\" : "";
132
- return `${prefix}${attr.key}: ${attr.value}${sep}`;
133
- })
244
+ .map((attr) => `${prefix}${attr.key}: ${attr.value}`)
134
245
  .join("\n");
135
246
  }
136
247
  /**
package/script/mod.d.ts CHANGED
@@ -9,18 +9,22 @@
9
9
  */
10
10
  import "./_dnt.polyfills.js";
11
11
  export declare const VERSION = "0.0.1";
12
- export { ConfigError, DEFAULT_PROJECT_CONFIG, REFHUB_URL, } from "./model/mod.js";
13
- export type { Attribute, BuiltinType, Caption, ConfigFieldError, Diagnostic, Directive, DisplayId, Entry, EntrySource, EntryType, InlineRef, Link, LinkKind, ProjectConfig, Severity, SourceLocation, Ulid, } from "./model/mod.js";
12
+ export { ConfigError, DEFAULT_PROJECT_CONFIG, PALETTE_HUES, REFHUB_URL, } from "./model/mod.js";
13
+ export type { Attribute, Caption, ConfigFieldError, Diagnostic, Directive, DisplayId, EffectiveProfile, EffectiveTypeDef, Entry, EntryShape, EntrySource, InlineRef, Link, LinkKind, PaletteHue, ProfileChain, ProjectConfig, Severity, SourceLocation, Ulid, } from "./model/mod.js";
14
14
  export { discoverProjectRoot, loadConfig, parseProjectConfig, } from "./config/mod.js";
15
15
  export type { LoadConfigResult, ReadFile } from "./config/mod.js";
16
+ export { MARKSPEC_YAML_FILENAME, parseMarkspecYaml, readMarkspecYaml, } from "./config/markspec.js";
17
+ export type { MarkspecYaml, ParseMarkspecYamlResult, } from "./config/markspec.js";
18
+ export { computeCacheKey, computeCacheLocation, defaultAppendFile, defaultRunGit, ensureCacheGitignored, loadChain, loadProfileForCommand, mergeChain, parseManifest, resolveEntryColor, resolveGitSpecifier, resolveLocalSpecifier, } from "./profile/mod.js";
19
+ export type { AppendFile, CacheLocation, GitCacheKeyInput, LoadChainOptions, LoadChainResult, LoadProfileForCommandResult, MergeResult, ParseManifestResult, ResolvedProfileSource, ResolveGitOptions, RunGit, RunGitResult, } from "./profile/mod.js";
16
20
  export { detectCaptions, detectDirectives, detectInlineRefs, isSupportedExtension, loadGrammar, parse, parseFile, parseSource, } from "./parser/mod.js";
17
- export type { DetectCaptionsOptions, DetectDirectivesOptions, DetectInlineRefsOptions, ParseOptions, ParseSourceOptions, } from "./parser/mod.js";
21
+ export type { DetectCaptionsOptions, DetectDirectivesOptions, DetectInlineRefsOptions, ParseFileResult, ParseOptions, ParseSourceOptions, ParseSourceResult, } from "./parser/mod.js";
18
22
  export { format } from "./formatter/mod.js";
19
23
  export type { FormatOptions, FormatResult } from "./formatter/mod.js";
20
- export { validate } from "./validator/mod.js";
21
- export type { ValidateResult } from "./validator/mod.js";
22
- export { compile, serializeCompileResult } from "./compiler/mod.js";
23
- export type { CompileOptions, CompileResult, SerializedCompileResult, } from "./compiler/mod.js";
24
+ export { classifyEntriesStage, classifyEntry, compileDisplayIdPattern, effectiveScope, effectiveTraceRules, matchesAnyTarget, normalizeListValues, runPipeline, validate, validateAttributesForEntry, validateTraceabilityForEntry, validateValue, } from "./validator/mod.js";
25
+ export type { ClassifyResult, ClassifyStageResult, EffectiveAttrScope, PipelineResult, ValidateResult, ValueValidator, } from "./validator/mod.js";
26
+ export { compile, generateInverses, serializeCompileResult, } from "./compiler/mod.js";
27
+ export type { CompileOptions, CompileResult, GenerateInversesResult, SerializedCompileResult, } from "./compiler/mod.js";
24
28
  export { report } from "./reporter/mod.js";
25
29
  export type { ReportFormat, ReportKind, ReportOptions, } from "./reporter/mod.js";
26
30
  //# sourceMappingURL=mod.d.ts.map