@driftsys/markspec 0.2.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.
- package/README.md +32 -8
- package/esm/compiler/inverses.d.ts +22 -0
- package/esm/compiler/inverses.d.ts.map +1 -0
- package/esm/compiler/inverses.js +147 -0
- package/esm/compiler/link_target.d.ts +19 -0
- package/esm/compiler/link_target.d.ts.map +1 -0
- package/esm/compiler/link_target.js +66 -0
- package/esm/compiler/mod.d.ts +7 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +61 -14
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +20 -1
- package/esm/config/markspec.d.ts +51 -0
- package/esm/config/markspec.d.ts.map +1 -0
- package/esm/config/markspec.js +216 -0
- package/esm/config/mod.d.ts +4 -0
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +27 -16
- package/esm/formatter/mod.d.ts +12 -2
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +130 -22
- package/esm/mod.d.ts +10 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +5 -2
- package/esm/model/attributes.d.ts +47 -0
- package/esm/model/attributes.d.ts.map +1 -0
- package/esm/model/attributes.js +97 -0
- package/esm/model/mod.d.ts +255 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +27 -1
- package/esm/model/profile.d.ts +189 -0
- package/esm/model/profile.d.ts.map +1 -0
- package/esm/model/profile.js +31 -0
- package/esm/parser/attributes.d.ts +13 -1
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +47 -0
- package/esm/parser/frontmatter.d.ts +53 -0
- package/esm/parser/frontmatter.d.ts.map +1 -0
- package/esm/parser/frontmatter.js +185 -0
- package/esm/parser/grammars.js +11 -2
- package/esm/parser/markdown.d.ts +11 -4
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +85 -38
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +39 -9
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +20 -13
- package/esm/profile/cache.d.ts +29 -0
- package/esm/profile/cache.d.ts.map +1 -0
- package/esm/profile/cache.js +45 -0
- package/esm/profile/chain.d.ts +42 -0
- package/esm/profile/chain.d.ts.map +1 -0
- package/esm/profile/chain.js +193 -0
- package/esm/profile/git-cache.d.ts +73 -0
- package/esm/profile/git-cache.d.ts.map +1 -0
- package/esm/profile/git-cache.js +96 -0
- package/esm/profile/load.d.ts +28 -0
- package/esm/profile/load.d.ts.map +1 -0
- package/esm/profile/load.js +50 -0
- package/esm/profile/manifest.d.ts +21 -0
- package/esm/profile/manifest.d.ts.map +1 -0
- package/esm/profile/manifest.js +830 -0
- package/esm/profile/merge.d.ts +26 -0
- package/esm/profile/merge.d.ts.map +1 -0
- package/esm/profile/merge.js +518 -0
- package/esm/profile/mod.d.ts +23 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +14 -0
- package/esm/profile/npm.d.ts +51 -0
- package/esm/profile/npm.d.ts.map +1 -0
- package/esm/profile/npm.js +186 -0
- package/esm/profile/resolver.d.ts +60 -0
- package/esm/profile/resolver.d.ts.map +1 -0
- package/esm/profile/resolver.js +132 -0
- package/esm/reporter/mod.js +14 -27
- package/esm/validator/attributes.d.ts +43 -0
- package/esm/validator/attributes.d.ts.map +1 -0
- package/esm/validator/attributes.js +169 -0
- package/esm/validator/mod.d.ts +27 -6
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +132 -124
- package/esm/validator/normalize.d.ts +21 -0
- package/esm/validator/normalize.d.ts.map +1 -0
- package/esm/validator/normalize.js +58 -0
- package/esm/validator/pattern.d.ts +23 -0
- package/esm/validator/pattern.d.ts.map +1 -0
- package/esm/validator/pattern.js +44 -0
- package/esm/validator/pipeline.d.ts +30 -0
- package/esm/validator/pipeline.d.ts.map +1 -0
- package/esm/validator/pipeline.js +115 -0
- package/esm/validator/traceability.d.ts +48 -0
- package/esm/validator/traceability.d.ts.map +1 -0
- package/esm/validator/traceability.js +141 -0
- package/esm/validator/types.d.ts +48 -0
- package/esm/validator/types.d.ts.map +1 -0
- package/esm/validator/types.js +140 -0
- package/esm/validator/value_types.d.ts +20 -0
- package/esm/validator/value_types.d.ts.map +1 -0
- package/esm/validator/value_types.js +126 -0
- package/package.json +1 -1
- package/script/compiler/inverses.d.ts +22 -0
- package/script/compiler/inverses.d.ts.map +1 -0
- package/script/compiler/inverses.js +150 -0
- package/script/compiler/link_target.d.ts +19 -0
- package/script/compiler/link_target.d.ts.map +1 -0
- package/script/compiler/link_target.js +69 -0
- package/script/compiler/mod.d.ts +7 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +62 -14
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +20 -1
- package/script/config/markspec.d.ts +51 -0
- package/script/config/markspec.d.ts.map +1 -0
- package/script/config/markspec.js +222 -0
- package/script/config/mod.d.ts +4 -0
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +28 -16
- package/script/formatter/mod.d.ts +12 -2
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +131 -22
- package/script/mod.d.ts +10 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +48 -19
- package/script/model/attributes.d.ts +47 -0
- package/script/model/attributes.d.ts.map +1 -0
- package/script/model/attributes.js +101 -0
- package/script/model/mod.d.ts +255 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +34 -2
- package/script/model/profile.d.ts +189 -0
- package/script/model/profile.d.ts.map +1 -0
- package/script/model/profile.js +34 -0
- package/script/parser/attributes.d.ts +13 -1
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +48 -0
- package/script/parser/frontmatter.d.ts +53 -0
- package/script/parser/frontmatter.d.ts.map +1 -0
- package/script/parser/frontmatter.js +188 -0
- package/script/parser/grammars.js +11 -2
- package/script/parser/markdown.d.ts +11 -4
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +84 -37
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +41 -10
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +20 -13
- package/script/profile/cache.d.ts +29 -0
- package/script/profile/cache.d.ts.map +1 -0
- package/script/profile/cache.js +48 -0
- package/script/profile/chain.d.ts +42 -0
- package/script/profile/chain.d.ts.map +1 -0
- package/script/profile/chain.js +229 -0
- package/script/profile/git-cache.d.ts +73 -0
- package/script/profile/git-cache.d.ts.map +1 -0
- package/script/profile/git-cache.js +104 -0
- package/script/profile/load.d.ts +28 -0
- package/script/profile/load.d.ts.map +1 -0
- package/script/profile/load.js +53 -0
- package/script/profile/manifest.d.ts +21 -0
- package/script/profile/manifest.d.ts.map +1 -0
- package/script/profile/manifest.js +833 -0
- package/script/profile/merge.d.ts +26 -0
- package/script/profile/merge.d.ts.map +1 -0
- package/script/profile/merge.js +521 -0
- package/script/profile/mod.d.ts +23 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +31 -0
- package/script/profile/npm.d.ts +51 -0
- package/script/profile/npm.d.ts.map +1 -0
- package/script/profile/npm.js +191 -0
- package/script/profile/resolver.d.ts +60 -0
- package/script/profile/resolver.d.ts.map +1 -0
- package/script/profile/resolver.js +136 -0
- package/script/reporter/mod.js +14 -27
- package/script/validator/attributes.d.ts +43 -0
- package/script/validator/attributes.d.ts.map +1 -0
- package/script/validator/attributes.js +173 -0
- package/script/validator/mod.d.ts +27 -6
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +145 -123
- package/script/validator/normalize.d.ts +21 -0
- package/script/validator/normalize.d.ts.map +1 -0
- package/script/validator/normalize.js +61 -0
- package/script/validator/pattern.d.ts +23 -0
- package/script/validator/pattern.d.ts.map +1 -0
- package/script/validator/pattern.js +47 -0
- package/script/validator/pipeline.d.ts +30 -0
- package/script/validator/pipeline.d.ts.map +1 -0
- package/script/validator/pipeline.js +118 -0
- package/script/validator/traceability.d.ts +48 -0
- package/script/validator/traceability.d.ts.map +1 -0
- package/script/validator/traceability.js +146 -0
- package/script/validator/types.d.ts +48 -0
- package/script/validator/types.d.ts.map +1 -0
- package/script/validator/types.js +144 -0
- package/script/validator/value_types.d.ts +20 -0
- package/script/validator/value_types.d.ts.map +1 -0
- 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
|
+
}
|
package/script/config/mod.d.ts
CHANGED
|
@@ -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,
|
|
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"}
|
package/script/config/mod.js
CHANGED
|
@@ -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
|
-
//
|
|
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,8 +32,18 @@ export interface FormatResult {
|
|
|
32
32
|
*/
|
|
33
33
|
export declare function format(markdown: string, options?: FormatOptions): FormatResult;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
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
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
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;;;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"}
|
package/script/formatter/mod.js
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 =
|
|
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.
|
|
52
|
-
// Assign ULID to
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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 };
|
|
85
140
|
}
|
|
86
141
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
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`;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
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);
|
package/script/mod.d.ts
CHANGED
|
@@ -10,17 +10,21 @@
|
|
|
10
10
|
import "./_dnt.polyfills.js";
|
|
11
11
|
export declare const VERSION = "0.0.1";
|
|
12
12
|
export { ConfigError, DEFAULT_PROJECT_CONFIG, REFHUB_URL, } from "./model/mod.js";
|
|
13
|
-
export type { Attribute,
|
|
13
|
+
export type { Attribute, Caption, ConfigFieldError, Diagnostic, Directive, DisplayId, EffectiveProfile, Entry, EntryShape, EntrySource, InlineRef, Link, LinkKind, 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, 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
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,qBAAqB,CAAC;AAG7B,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,qBAAqB,CAAC;AAG7B,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EACL,WAAW,EACX,sBAAsB,EACtB,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,WAAW,EACX,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,cAAc,EACd,IAAI,GACL,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAElE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,YAAY,EACZ,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,SAAS,EACT,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,2BAA2B,EAC3B,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,MAAM,EACN,YAAY,GACb,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,WAAW,EACX,KAAK,EACL,SAAS,EACT,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGtE,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,YAAY,EACV,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAAM,mBAAmB,CAAC"}
|