@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.
- 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 +19 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +139 -29
- package/esm/mod.d.ts +11 -7
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +6 -3
- 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 +257 -26
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +28 -1
- package/esm/model/palette.d.ts +18 -0
- package/esm/model/palette.d.ts.map +1 -0
- package/esm/model/palette.js +23 -0
- 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 +21 -7
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +101 -40
- package/esm/parser/mod.d.ts +26 -10
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +40 -10
- package/esm/parser/source.d.ts +12 -8
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +21 -14
- 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/colors.d.ts +26 -0
- package/esm/profile/colors.d.ts.map +1 -0
- package/esm/profile/colors.js +46 -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 +815 -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 +24 -0
- package/esm/profile/mod.d.ts.map +1 -0
- package/esm/profile/mod.js +15 -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 +19 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +140 -29
- package/script/mod.d.ts +11 -7
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +50 -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 +257 -26
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +37 -2
- package/script/model/palette.d.ts +18 -0
- package/script/model/palette.d.ts.map +1 -0
- package/script/model/palette.js +26 -0
- 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 +21 -7
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +100 -39
- package/script/parser/mod.d.ts +26 -10
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +42 -11
- package/script/parser/source.d.ts +12 -8
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +21 -14
- 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/colors.d.ts +26 -0
- package/script/profile/colors.d.ts.map +1 -0
- package/script/profile/colors.js +49 -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 +818 -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 +24 -0
- package/script/profile/mod.d.ts.map +1 -0
- package/script/profile/mod.js +33 -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
package/README.md
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
A Markdown flavor for traceable industrial documentation, and a CLI toolchain
|
|
10
10
|
that processes it.
|
|
11
11
|
|
|
12
|
-
> Early development. The
|
|
13
|
-
>
|
|
12
|
+
> Early development. The
|
|
13
|
+
> [language specification](docs/spec/language/language.md) is under active
|
|
14
|
+
> revision to match ADR-009 (core/profile boundary). Tooling is not yet
|
|
15
|
+
> functional.
|
|
14
16
|
|
|
15
17
|
## Tools
|
|
16
18
|
|
|
@@ -18,8 +20,10 @@ that processes it.
|
|
|
18
20
|
markspec format # stamp ULIDs, normalize attributes
|
|
19
21
|
markspec validate # check broken refs, missing Ids
|
|
20
22
|
markspec compile <paths> # build traceability graph → JSON
|
|
23
|
+
# (ingests deps via SBOM tooling if configured)
|
|
21
24
|
markspec export # JSON → csv, reqif, yaml
|
|
22
|
-
markspec insert # scaffold
|
|
25
|
+
markspec insert # scaffold entry block
|
|
26
|
+
markspec profile # add / publish / manage profiles
|
|
23
27
|
|
|
24
28
|
markspec doc build # document PDF
|
|
25
29
|
markspec book build # PDF + HTML book
|
|
@@ -35,7 +39,7 @@ markspec mcp # MCP server
|
|
|
35
39
|
|
|
36
40
|
```text
|
|
37
41
|
core/ ← parser, validator, compiler, reporter, formatter
|
|
38
|
-
render/ ← Typst WASM, Mustache substitution, captions
|
|
42
|
+
render/ ← Typst WASM, entry block rendering, Mustache substitution, captions
|
|
39
43
|
book/ ← multi-file PDF + HTML book builder
|
|
40
44
|
deck/ ← Touying-based slide deck builder
|
|
41
45
|
cli/ ← subcommand handlers
|
|
@@ -50,7 +54,7 @@ One binary. One install. Three rendering targets (document, book, deck).
|
|
|
50
54
|
MarkSpec extends CommonMark with constructs that render as plain Markdown on
|
|
51
55
|
GitHub and GitLab — no tooling required to read.
|
|
52
56
|
|
|
53
|
-
**Entry blocks** — a list item with a
|
|
57
|
+
**Entry blocks** — a list item with a display ID and an indented body:
|
|
54
58
|
|
|
55
59
|
```markdown
|
|
56
60
|
- [SRS_BRK_0001] Sensor input debouncing
|
|
@@ -58,11 +62,25 @@ GitHub and GitLab — no tooling required to read.
|
|
|
58
62
|
The sensor driver shall debounce raw inputs to eliminate electrical noise
|
|
59
63
|
before processing.
|
|
60
64
|
|
|
61
|
-
Id:
|
|
65
|
+
Id: 01HGW2Q8MNP3RSTVWXYZABCDEF\
|
|
62
66
|
Satisfies: SYS_BRK_0042\
|
|
63
67
|
Labels: ASIL-B
|
|
64
68
|
```
|
|
65
69
|
|
|
70
|
+
Every entry carries a single `Id:` attribute. A ULID value identifies an
|
|
71
|
+
**identified** entry (content the project authors); a URI value (`urn:`, `doi:`,
|
|
72
|
+
`pkg:`, `https:`, …) identifies a **referenced** entry (citation of an external
|
|
73
|
+
artifact). The entry's type (requirement, test, unit, standard, dependency, …)
|
|
74
|
+
is inferred by the active profile from the display-ID prefix (`SRS_` →
|
|
75
|
+
`type: software-requirement`); compliance vocabulary comes from the active
|
|
76
|
+
profile.
|
|
77
|
+
|
|
78
|
+
In PDF output, entry blocks render as admonition-style blocks with
|
|
79
|
+
profile-driven color-coding by type, label pills on the title line, and italic
|
|
80
|
+
metadata with dashed-underline cross-references. See
|
|
81
|
+
[`docs/examples/entry-rendering.md`](docs/examples/entry-rendering.md) for a
|
|
82
|
+
full showcase.
|
|
83
|
+
|
|
66
84
|
**Table captions** — emphasized paragraph above a pipe table:
|
|
67
85
|
|
|
68
86
|
```markdown
|
|
@@ -81,7 +99,7 @@ _Table: Sensor thresholds_
|
|
|
81
99
|
_Figure: High-level architecture of the braking system_
|
|
82
100
|
```
|
|
83
101
|
|
|
84
|
-
**In-code entries** —
|
|
102
|
+
**In-code entries** — entries in doc comments, same format:
|
|
85
103
|
|
|
86
104
|
```rust
|
|
87
105
|
/// [SRS_BRK_0001] Sensor input debouncing
|
|
@@ -89,7 +107,7 @@ _Figure: High-level architecture of the braking system_
|
|
|
89
107
|
/// The sensor driver shall reject transient noise shorter
|
|
90
108
|
/// than the configured debounce window.
|
|
91
109
|
///
|
|
92
|
-
/// Id:
|
|
110
|
+
/// Id: 01HGW2Q8MNP3RSTVWXYZABCDEF \
|
|
93
111
|
/// Satisfies: SYS_BRK_0042 \
|
|
94
112
|
/// Labels: ASIL-B
|
|
95
113
|
#[test]
|
|
@@ -108,3 +126,9 @@ resolved at build time.
|
|
|
108
126
|
---
|
|
109
127
|
|
|
110
128
|
Part of the [DriftSys](https://github.com/driftsys) ecosystem.
|
|
129
|
+
|
|
130
|
+
<!-- git-std:bootstrap -->
|
|
131
|
+
|
|
132
|
+
## Post-clone setup
|
|
133
|
+
|
|
134
|
+
Run `./bootstrap` after `git clone` or `git worktree add`.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module compiler/inverses
|
|
3
|
+
*
|
|
4
|
+
* Inverse attribute generation — walks forward link attributes that carry
|
|
5
|
+
* an `inverse:` declaration and emits synthetic back-link values on target
|
|
6
|
+
* entries.
|
|
7
|
+
*/
|
|
8
|
+
import type { Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
|
|
9
|
+
/** Result of inverse generation. */
|
|
10
|
+
export interface GenerateInversesResult {
|
|
11
|
+
readonly entries: readonly Entry[];
|
|
12
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate inverse (back-link) attributes from forward link declarations.
|
|
16
|
+
*
|
|
17
|
+
* Walks every identified entry's `typedAttributes` for attributes that match
|
|
18
|
+
* an `inverse:` declaration in the effective profile, then accumulates
|
|
19
|
+
* back-links on target entries.
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateInverses(entries: readonly Entry[], profile: EffectiveProfile): GenerateInversesResult;
|
|
22
|
+
//# sourceMappingURL=inverses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inverses.d.ts","sourceRoot":"","sources":["../../src/compiler/inverses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,KAAK,EAEN,MAAM,iBAAiB,CAAC;AAEzB,oCAAoC;AACpC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAcD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GACxB,sBAAsB,CA4GxB"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module compiler/inverses
|
|
3
|
+
*
|
|
4
|
+
* Inverse attribute generation — walks forward link attributes that carry
|
|
5
|
+
* an `inverse:` declaration and emits synthetic back-link values on target
|
|
6
|
+
* entries.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Generate inverse (back-link) attributes from forward link declarations.
|
|
10
|
+
*
|
|
11
|
+
* Walks every identified entry's `typedAttributes` for attributes that match
|
|
12
|
+
* an `inverse:` declaration in the effective profile, then accumulates
|
|
13
|
+
* back-links on target entries.
|
|
14
|
+
*/
|
|
15
|
+
export function generateInverses(entries, profile) {
|
|
16
|
+
if (entries.length === 0) {
|
|
17
|
+
return { entries: [], diagnostics: [] };
|
|
18
|
+
}
|
|
19
|
+
// Step 1: Collect all inverse declarations from the profile
|
|
20
|
+
const inverseSpecs = collectInverseSpecs(profile);
|
|
21
|
+
if (inverseSpecs.length === 0) {
|
|
22
|
+
return { entries: [...entries], diagnostics: [] };
|
|
23
|
+
}
|
|
24
|
+
// Step 2: Index entries by id
|
|
25
|
+
const byId = new Map();
|
|
26
|
+
for (const e of entries) {
|
|
27
|
+
if (e.id !== undefined) {
|
|
28
|
+
byId.set(e.id, e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Step 3–5: Walk entries, accumulate back-links
|
|
32
|
+
// Map: targetId → Map<inverseAttrName, Set<sourceId>>
|
|
33
|
+
const generated = new Map();
|
|
34
|
+
for (const source of entries) {
|
|
35
|
+
if (source.shape !== "identified" || source.id === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
const applicableSpecs = resolveApplicableSpecs(inverseSpecs, source.type);
|
|
38
|
+
for (const spec of applicableSpecs) {
|
|
39
|
+
const forwardValues = source.typedAttributes.get(spec.attrName);
|
|
40
|
+
if (!forwardValues)
|
|
41
|
+
continue;
|
|
42
|
+
for (const targetId of forwardValues) {
|
|
43
|
+
const target = byId.get(targetId);
|
|
44
|
+
if (!target || target.type !== spec.inverse.category)
|
|
45
|
+
continue;
|
|
46
|
+
let targetMap = generated.get(targetId);
|
|
47
|
+
if (!targetMap) {
|
|
48
|
+
targetMap = new Map();
|
|
49
|
+
generated.set(targetId, targetMap);
|
|
50
|
+
}
|
|
51
|
+
let idSet = targetMap.get(spec.inverse.name);
|
|
52
|
+
if (!idSet) {
|
|
53
|
+
idSet = new Set();
|
|
54
|
+
targetMap.set(spec.inverse.name, idSet);
|
|
55
|
+
}
|
|
56
|
+
idSet.add(source.id);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Step 6–7: Merge generated values into entries, emit diagnostics
|
|
61
|
+
const diagnostics = [];
|
|
62
|
+
const result = [];
|
|
63
|
+
for (const e of entries) {
|
|
64
|
+
const targetInverses = e.id ? generated.get(e.id) : undefined;
|
|
65
|
+
if (!targetInverses) {
|
|
66
|
+
result.push(e);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const newAttrs = new Map(e.typedAttributes);
|
|
70
|
+
let changed = false;
|
|
71
|
+
for (const [inverseName, generatedIds] of targetInverses) {
|
|
72
|
+
const generatedArr = [...generatedIds];
|
|
73
|
+
const authored = e.typedAttributes.get(inverseName);
|
|
74
|
+
if (authored && authored.length > 0) {
|
|
75
|
+
const authoredSet = new Set(authored);
|
|
76
|
+
const genSet = generatedIds;
|
|
77
|
+
const match = authoredSet.size === genSet.size &&
|
|
78
|
+
[...authoredSet].every((v) => genSet.has(v));
|
|
79
|
+
if (!match) {
|
|
80
|
+
diagnostics.push({
|
|
81
|
+
code: "MSL-L005",
|
|
82
|
+
severity: "warning",
|
|
83
|
+
message: `authored "${inverseName}" on ${e.displayId} differs from generated inverse values`,
|
|
84
|
+
location: e.location,
|
|
85
|
+
});
|
|
86
|
+
// Union authored + generated
|
|
87
|
+
const union = new Set([...authored, ...generatedArr]);
|
|
88
|
+
newAttrs.set(inverseName, [...union]);
|
|
89
|
+
changed = true;
|
|
90
|
+
}
|
|
91
|
+
// If match, keep as-is
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
newAttrs.set(inverseName, generatedArr);
|
|
95
|
+
changed = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (changed) {
|
|
99
|
+
result.push({ ...e, typedAttributes: newAttrs });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
result.push(e);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { entries: result, diagnostics };
|
|
106
|
+
}
|
|
107
|
+
/** Collect all inverse-bearing attribute declarations from the profile. */
|
|
108
|
+
function collectInverseSpecs(profile) {
|
|
109
|
+
const specs = [];
|
|
110
|
+
// Universal scope
|
|
111
|
+
for (const [, entry] of profile.attributes) {
|
|
112
|
+
if (entry.value.inverse) {
|
|
113
|
+
specs.push({
|
|
114
|
+
attrName: entry.value.name,
|
|
115
|
+
inverse: entry.value.inverse,
|
|
116
|
+
sourceType: null,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Identified shape scope
|
|
121
|
+
for (const [, entry] of profile.identified.attributes) {
|
|
122
|
+
if (entry.value.inverse) {
|
|
123
|
+
specs.push({
|
|
124
|
+
attrName: entry.value.name,
|
|
125
|
+
inverse: entry.value.inverse,
|
|
126
|
+
sourceType: null,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Type scopes
|
|
131
|
+
for (const [typeName, typeEntry] of profile.types) {
|
|
132
|
+
for (const [, attrEntry] of typeEntry.value.attributes) {
|
|
133
|
+
if (attrEntry.value.inverse) {
|
|
134
|
+
specs.push({
|
|
135
|
+
attrName: attrEntry.value.name,
|
|
136
|
+
inverse: attrEntry.value.inverse,
|
|
137
|
+
sourceType: typeName,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return specs;
|
|
143
|
+
}
|
|
144
|
+
/** Filter specs applicable to a source entry's type. */
|
|
145
|
+
function resolveApplicableSpecs(specs, sourceType) {
|
|
146
|
+
return specs.filter((s) => s.sourceType === null || s.sourceType === sourceType);
|
|
147
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/compiler/link_target
|
|
3
|
+
*
|
|
4
|
+
* MSL-T013: Tiered link-target severity. After links are extracted and
|
|
5
|
+
* inverses generated, check the state of each link target:
|
|
6
|
+
*
|
|
7
|
+
* | Target state | Severity |
|
|
8
|
+
* |---|---|
|
|
9
|
+
* | Active | OK (no diagnostic) |
|
|
10
|
+
* | Draft (Labels: DRAFT) | info |
|
|
11
|
+
* | Retired (Superseded-by: set OR Deprecated: set) | warning |
|
|
12
|
+
*/
|
|
13
|
+
import type { Diagnostic, DisplayId, Entry, Link } from "../model/mod.js";
|
|
14
|
+
/**
|
|
15
|
+
* Check all link targets for retirement/draft state.
|
|
16
|
+
* Run after inverse generation so `Superseded-by:` is available.
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkLinkTargets(entries: ReadonlyMap<DisplayId, Entry>, links: readonly Link[]): Diagnostic[];
|
|
19
|
+
//# sourceMappingURL=link_target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"link_target.d.ts","sourceRoot":"","sources":["../../src/compiler/link_target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,EACtC,KAAK,EAAE,SAAS,IAAI,EAAE,GACrB,UAAU,EAAE,CA4Bd"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/compiler/link_target
|
|
3
|
+
*
|
|
4
|
+
* MSL-T013: Tiered link-target severity. After links are extracted and
|
|
5
|
+
* inverses generated, check the state of each link target:
|
|
6
|
+
*
|
|
7
|
+
* | Target state | Severity |
|
|
8
|
+
* |---|---|
|
|
9
|
+
* | Active | OK (no diagnostic) |
|
|
10
|
+
* | Draft (Labels: DRAFT) | info |
|
|
11
|
+
* | Retired (Superseded-by: set OR Deprecated: set) | warning |
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Check all link targets for retirement/draft state.
|
|
15
|
+
* Run after inverse generation so `Superseded-by:` is available.
|
|
16
|
+
*/
|
|
17
|
+
export function checkLinkTargets(entries, links) {
|
|
18
|
+
const diagnostics = [];
|
|
19
|
+
for (const link of links) {
|
|
20
|
+
const target = entries.get(link.to);
|
|
21
|
+
if (!target)
|
|
22
|
+
continue; // Unresolved — handled by MSL-T005/MSL-T012
|
|
23
|
+
const state = classifyTargetState(target);
|
|
24
|
+
if (state === "active")
|
|
25
|
+
continue;
|
|
26
|
+
if (state === "draft") {
|
|
27
|
+
diagnostics.push({
|
|
28
|
+
code: "MSL-T013",
|
|
29
|
+
severity: "info",
|
|
30
|
+
message: `${link.from}: link target '${link.to}' is marked DRAFT`,
|
|
31
|
+
location: link.location,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
diagnostics.push({
|
|
36
|
+
code: "MSL-T013",
|
|
37
|
+
severity: "warning",
|
|
38
|
+
message: `${link.from}: link target '${link.to}' is retired`,
|
|
39
|
+
location: link.location,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return diagnostics;
|
|
44
|
+
}
|
|
45
|
+
function classifyTargetState(entry) {
|
|
46
|
+
// Check for retirement markers
|
|
47
|
+
const hasDeprecated = entry.rawAttributes.some((a) => a.key === "Deprecated");
|
|
48
|
+
if (hasDeprecated)
|
|
49
|
+
return "retired";
|
|
50
|
+
const supersededBy = entry.typedAttributes.get("Superseded-by");
|
|
51
|
+
if (supersededBy && supersededBy.length > 0)
|
|
52
|
+
return "retired";
|
|
53
|
+
// Check for DRAFT label via typedAttributes
|
|
54
|
+
const labels = entry.typedAttributes.get("Labels");
|
|
55
|
+
if (labels && labels.includes("DRAFT"))
|
|
56
|
+
return "draft";
|
|
57
|
+
// Also check raw attributes for Labels containing DRAFT
|
|
58
|
+
for (const attr of entry.rawAttributes) {
|
|
59
|
+
if (attr.key === "Labels") {
|
|
60
|
+
const values = attr.value.split(",").map((s) => s.trim());
|
|
61
|
+
if (values.includes("DRAFT"))
|
|
62
|
+
return "draft";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return "active";
|
|
66
|
+
}
|
package/esm/compiler/mod.d.ts
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
* Compiler pipeline. Takes file paths, parses all entries, validates them,
|
|
5
5
|
* builds a bidirectional traceability graph, and returns the compiled model.
|
|
6
6
|
*/
|
|
7
|
-
import type { Diagnostic, DisplayId, Entry, Link } from "../model/mod.js";
|
|
7
|
+
import type { Diagnostic, DisplayId, Document, EffectiveProfile, Entry, Link } from "../model/mod.js";
|
|
8
8
|
/** Options for {@linkcode compile}. */
|
|
9
9
|
export interface CompileOptions {
|
|
10
10
|
/** File reader function. Required — no default to avoid Deno dependency in library code. */
|
|
11
11
|
readonly readFile: (path: string) => Promise<string>;
|
|
12
|
+
/** Active profile for inverse attribute generation. Optional — when absent, inverses are skipped. */
|
|
13
|
+
readonly profile?: EffectiveProfile;
|
|
12
14
|
}
|
|
13
15
|
/** Compiled project output with resolved traceability graph. */
|
|
14
16
|
export interface CompileResult {
|
|
@@ -20,6 +22,8 @@ export interface CompileResult {
|
|
|
20
22
|
readonly forward: ReadonlyMap<DisplayId, readonly Link[]>;
|
|
21
23
|
/** Incoming links per entry (entry → sources pointing to it). */
|
|
22
24
|
readonly reverse: ReadonlyMap<DisplayId, readonly Link[]>;
|
|
25
|
+
/** Documents keyed by file path. A file appears here only when it carried YAML front matter per ADR-007. */
|
|
26
|
+
readonly documents: ReadonlyMap<string, Document>;
|
|
23
27
|
/** Diagnostics from parsing and validation. */
|
|
24
28
|
readonly diagnostics: readonly Diagnostic[];
|
|
25
29
|
}
|
|
@@ -34,4 +38,6 @@ export interface CompileResult {
|
|
|
34
38
|
export declare function compile(paths: readonly string[], options: CompileOptions): Promise<CompileResult>;
|
|
35
39
|
export { serializeCompileResult } from "./schema.js";
|
|
36
40
|
export type { SerializedCompileResult } from "./schema.js";
|
|
41
|
+
export { generateInverses } from "./inverses.js";
|
|
42
|
+
export type { GenerateInversesResult } from "./inverses.js";
|
|
37
43
|
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,KAAK,EACL,IAAI,EAGL,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/compiler/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,KAAK,EACL,IAAI,EAGL,MAAM,iBAAiB,CAAC;AAMzB,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAChD,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAC1D,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;IAC1D,4GAA4G;IAC5G,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CA4ExB;AAmGD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,YAAY,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
|
package/esm/compiler/mod.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* builds a bidirectional traceability graph, and returns the compiled model.
|
|
6
6
|
*/
|
|
7
7
|
import { parseFile } from "../parser/mod.js";
|
|
8
|
-
import { validate } from "../validator/mod.js";
|
|
8
|
+
import { classifyEntriesStage, validate } from "../validator/mod.js";
|
|
9
|
+
import { generateInverses } from "./inverses.js";
|
|
10
|
+
import { checkLinkTargets } from "./link_target.js";
|
|
9
11
|
/**
|
|
10
12
|
* Compile MarkSpec files from the given paths into a resolved
|
|
11
13
|
* traceability graph.
|
|
@@ -18,6 +20,7 @@ export async function compile(paths, options) {
|
|
|
18
20
|
const read = options.readFile;
|
|
19
21
|
const allEntries = [];
|
|
20
22
|
const parseDiagnostics = [];
|
|
23
|
+
const documents = new Map();
|
|
21
24
|
// Phase 1: Read and parse all files.
|
|
22
25
|
for (const filePath of paths) {
|
|
23
26
|
let content;
|
|
@@ -33,45 +36,78 @@ export async function compile(paths, options) {
|
|
|
33
36
|
});
|
|
34
37
|
continue;
|
|
35
38
|
}
|
|
36
|
-
const
|
|
37
|
-
allEntries.push(...entries);
|
|
39
|
+
const result = await parseFile(content, { file: filePath });
|
|
40
|
+
allEntries.push(...result.entries);
|
|
41
|
+
parseDiagnostics.push(...result.diagnostics);
|
|
42
|
+
if (result.document)
|
|
43
|
+
documents.set(filePath, result.document);
|
|
38
44
|
}
|
|
39
45
|
// Phase 2: Validate all entries.
|
|
40
46
|
const validationResult = validate(allEntries);
|
|
47
|
+
// Phase 2.5: Classify entries when a profile is loaded.
|
|
48
|
+
let classifiedEntries = allEntries;
|
|
49
|
+
if (options.profile) {
|
|
50
|
+
const stage2 = classifyEntriesStage(allEntries, options.profile);
|
|
51
|
+
classifiedEntries = stage2.entries;
|
|
52
|
+
parseDiagnostics.push(...stage2.diagnostics);
|
|
53
|
+
}
|
|
41
54
|
// Phase 3: Build traceability graph.
|
|
42
55
|
// Keep first occurrence of each display ID (validator catches duplicates).
|
|
43
56
|
const entries = new Map();
|
|
44
|
-
for (const entry of
|
|
57
|
+
for (const entry of classifiedEntries) {
|
|
45
58
|
if (!entries.has(entry.displayId)) {
|
|
46
59
|
entries.set(entry.displayId, entry);
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
|
-
|
|
62
|
+
// Phase 3.5: Generate inverse attributes from profile declarations.
|
|
63
|
+
if (options.profile) {
|
|
64
|
+
const inverseResult = generateInverses([...entries.values()], options.profile);
|
|
65
|
+
parseDiagnostics.push(...inverseResult.diagnostics);
|
|
66
|
+
entries.clear();
|
|
67
|
+
for (const entry of inverseResult.entries) {
|
|
68
|
+
if (!entries.has(entry.displayId)) {
|
|
69
|
+
entries.set(entry.displayId, entry);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const links = extractLinks([...entries.values()]);
|
|
74
|
+
// MSL-T013: check link targets for draft/retired state.
|
|
75
|
+
const linkTargetDiags = checkLinkTargets(entries, links);
|
|
50
76
|
const forward = buildAdjacency(links, (l) => l.from);
|
|
51
77
|
const reverse = buildAdjacency(links, (l) => l.to);
|
|
52
78
|
const diagnostics = [
|
|
53
79
|
...parseDiagnostics,
|
|
54
80
|
...validationResult.diagnostics,
|
|
81
|
+
...linkTargetDiags,
|
|
55
82
|
];
|
|
56
|
-
return { entries, links, forward, reverse, diagnostics };
|
|
83
|
+
return { entries, links, forward, reverse, documents, diagnostics };
|
|
57
84
|
}
|
|
58
85
|
/** Extract traceability links from entry attributes. */
|
|
59
86
|
function extractLinks(entries) {
|
|
60
87
|
const links = [];
|
|
61
88
|
for (const entry of entries) {
|
|
62
|
-
for (const attr of entry.
|
|
89
|
+
for (const attr of entry.rawAttributes) {
|
|
63
90
|
const extracted = extractLinksFromAttribute(entry.displayId, attr.key, attr.value, entry.location);
|
|
64
91
|
links.push(...extracted);
|
|
65
92
|
}
|
|
66
93
|
}
|
|
67
94
|
return links;
|
|
68
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Attributes whose value is `slug + optional free-text locator` per
|
|
98
|
+
* ADR-002 §2.6 (citation type + legacy Derived-from tolerance). The link
|
|
99
|
+
* target is the leading non-whitespace token only.
|
|
100
|
+
*/
|
|
101
|
+
const LOCATOR_BEARING_ATTRS = new Set([
|
|
102
|
+
"Derived-from",
|
|
103
|
+
"References",
|
|
104
|
+
]);
|
|
69
105
|
/** Map an attribute key+value to zero or more links. */
|
|
70
106
|
function extractLinksFromAttribute(from, key, value, location) {
|
|
71
107
|
const kind = ATTR_TO_LINK_KIND[key];
|
|
72
108
|
if (!kind)
|
|
73
109
|
return [];
|
|
74
|
-
if (key
|
|
110
|
+
if (LOCATOR_BEARING_ATTRS.has(key)) {
|
|
75
111
|
// Format: "ID §section" — extract ID part only.
|
|
76
112
|
const idPart = value.split(/\s/)[0];
|
|
77
113
|
if (idPart) {
|
|
@@ -79,7 +115,7 @@ function extractLinksFromAttribute(from, key, value, location) {
|
|
|
79
115
|
}
|
|
80
116
|
return [];
|
|
81
117
|
}
|
|
82
|
-
// Comma-separated targets
|
|
118
|
+
// Comma-separated targets for id-list attributes.
|
|
83
119
|
return value
|
|
84
120
|
.split(",")
|
|
85
121
|
.map((s) => s.trim())
|
|
@@ -87,16 +123,25 @@ function extractLinksFromAttribute(from, key, value, location) {
|
|
|
87
123
|
.map((to) => ({ from, to, kind, location }));
|
|
88
124
|
}
|
|
89
125
|
/**
|
|
90
|
-
* Attribute keys that produce traceability links.
|
|
91
|
-
*
|
|
92
|
-
*
|
|
126
|
+
* Attribute keys that produce traceability links per ADR-002.
|
|
127
|
+
*
|
|
128
|
+
* Spec attributes: Satisfies, Derived-from, References, Allocated-to.
|
|
129
|
+
* Test attributes: Verifies, Tests.
|
|
130
|
+
* Element attributes: Realizes, Depends-on, Part-of, Generated-from.
|
|
131
|
+
* Universal: Supersedes (same-family).
|
|
93
132
|
*/
|
|
94
133
|
const ATTR_TO_LINK_KIND = {
|
|
95
134
|
"Satisfies": "satisfies",
|
|
96
135
|
"Derived-from": "derived-from",
|
|
97
|
-
"
|
|
136
|
+
"References": "references",
|
|
137
|
+
"Allocated-to": "allocated-to",
|
|
138
|
+
"Realizes": "realizes",
|
|
98
139
|
"Verifies": "verifies",
|
|
99
|
-
"
|
|
140
|
+
"Tests": "tests",
|
|
141
|
+
"Depends-on": "depends-on",
|
|
142
|
+
"Part-of": "part-of",
|
|
143
|
+
"Generated-from": "generated-from",
|
|
144
|
+
"Supersedes": "supersedes",
|
|
100
145
|
};
|
|
101
146
|
/** Build an adjacency map from links using a key selector. */
|
|
102
147
|
function buildAdjacency(links, keyFn) {
|
|
@@ -114,3 +159,5 @@ function buildAdjacency(links, keyFn) {
|
|
|
114
159
|
}
|
|
115
160
|
// Re-export serialization helper.
|
|
116
161
|
export { serializeCompileResult } from "./schema.js";
|
|
162
|
+
// Re-export inverse generation.
|
|
163
|
+
export { generateInverses } from "./inverses.js";
|
|
@@ -1 +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,
|
|
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"}
|
package/esm/compiler/schema.js
CHANGED
|
@@ -15,11 +15,30 @@
|
|
|
15
15
|
* @returns A plain object safe for `JSON.stringify`
|
|
16
16
|
*/
|
|
17
17
|
export function serializeCompileResult(result) {
|
|
18
|
+
const rawEntries = Object.fromEntries(result.entries);
|
|
19
|
+
const entries = {};
|
|
20
|
+
for (const [key, entry] of Object.entries(rawEntries)) {
|
|
21
|
+
entries[key] = serializeEntry(entry);
|
|
22
|
+
}
|
|
18
23
|
return {
|
|
19
|
-
entries
|
|
24
|
+
entries,
|
|
20
25
|
links: result.links,
|
|
21
26
|
forward: Object.fromEntries(result.forward),
|
|
22
27
|
reverse: Object.fromEntries(result.reverse),
|
|
23
28
|
diagnostics: result.diagnostics,
|
|
24
29
|
};
|
|
25
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert an {@linkcode Entry} to a JSON-safe form by replacing
|
|
33
|
+
* `typedAttributes` (a `ReadonlyMap`) with a plain object.
|
|
34
|
+
*/
|
|
35
|
+
function serializeEntry(entry) {
|
|
36
|
+
if (!entry.typedAttributes || entry.typedAttributes.size === 0) {
|
|
37
|
+
return entry;
|
|
38
|
+
}
|
|
39
|
+
const typedObj = Object.fromEntries(entry.typedAttributes);
|
|
40
|
+
return {
|
|
41
|
+
...entry,
|
|
42
|
+
typedAttributes: typedObj,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -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"}
|