@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.
Files changed (202) 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 +12 -2
  20. package/esm/formatter/mod.d.ts.map +1 -1
  21. package/esm/formatter/mod.js +130 -22
  22. package/esm/mod.d.ts +10 -6
  23. package/esm/mod.d.ts.map +1 -1
  24. package/esm/mod.js +5 -2
  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 +255 -26
  29. package/esm/model/mod.d.ts.map +1 -1
  30. package/esm/model/mod.js +27 -1
  31. package/esm/model/profile.d.ts +189 -0
  32. package/esm/model/profile.d.ts.map +1 -0
  33. package/esm/model/profile.js +31 -0
  34. package/esm/parser/attributes.d.ts +13 -1
  35. package/esm/parser/attributes.d.ts.map +1 -1
  36. package/esm/parser/attributes.js +47 -0
  37. package/esm/parser/frontmatter.d.ts +53 -0
  38. package/esm/parser/frontmatter.d.ts.map +1 -0
  39. package/esm/parser/frontmatter.js +185 -0
  40. package/esm/parser/grammars.js +11 -2
  41. package/esm/parser/markdown.d.ts +11 -4
  42. package/esm/parser/markdown.d.ts.map +1 -1
  43. package/esm/parser/markdown.js +85 -38
  44. package/esm/parser/mod.d.ts +26 -10
  45. package/esm/parser/mod.d.ts.map +1 -1
  46. package/esm/parser/mod.js +39 -9
  47. package/esm/parser/source.d.ts +12 -8
  48. package/esm/parser/source.d.ts.map +1 -1
  49. package/esm/parser/source.js +20 -13
  50. package/esm/profile/cache.d.ts +29 -0
  51. package/esm/profile/cache.d.ts.map +1 -0
  52. package/esm/profile/cache.js +45 -0
  53. package/esm/profile/chain.d.ts +42 -0
  54. package/esm/profile/chain.d.ts.map +1 -0
  55. package/esm/profile/chain.js +193 -0
  56. package/esm/profile/git-cache.d.ts +73 -0
  57. package/esm/profile/git-cache.d.ts.map +1 -0
  58. package/esm/profile/git-cache.js +96 -0
  59. package/esm/profile/load.d.ts +28 -0
  60. package/esm/profile/load.d.ts.map +1 -0
  61. package/esm/profile/load.js +50 -0
  62. package/esm/profile/manifest.d.ts +21 -0
  63. package/esm/profile/manifest.d.ts.map +1 -0
  64. package/esm/profile/manifest.js +830 -0
  65. package/esm/profile/merge.d.ts +26 -0
  66. package/esm/profile/merge.d.ts.map +1 -0
  67. package/esm/profile/merge.js +518 -0
  68. package/esm/profile/mod.d.ts +23 -0
  69. package/esm/profile/mod.d.ts.map +1 -0
  70. package/esm/profile/mod.js +14 -0
  71. package/esm/profile/npm.d.ts +51 -0
  72. package/esm/profile/npm.d.ts.map +1 -0
  73. package/esm/profile/npm.js +186 -0
  74. package/esm/profile/resolver.d.ts +60 -0
  75. package/esm/profile/resolver.d.ts.map +1 -0
  76. package/esm/profile/resolver.js +132 -0
  77. package/esm/reporter/mod.js +14 -27
  78. package/esm/validator/attributes.d.ts +43 -0
  79. package/esm/validator/attributes.d.ts.map +1 -0
  80. package/esm/validator/attributes.js +169 -0
  81. package/esm/validator/mod.d.ts +27 -6
  82. package/esm/validator/mod.d.ts.map +1 -1
  83. package/esm/validator/mod.js +132 -124
  84. package/esm/validator/normalize.d.ts +21 -0
  85. package/esm/validator/normalize.d.ts.map +1 -0
  86. package/esm/validator/normalize.js +58 -0
  87. package/esm/validator/pattern.d.ts +23 -0
  88. package/esm/validator/pattern.d.ts.map +1 -0
  89. package/esm/validator/pattern.js +44 -0
  90. package/esm/validator/pipeline.d.ts +30 -0
  91. package/esm/validator/pipeline.d.ts.map +1 -0
  92. package/esm/validator/pipeline.js +115 -0
  93. package/esm/validator/traceability.d.ts +48 -0
  94. package/esm/validator/traceability.d.ts.map +1 -0
  95. package/esm/validator/traceability.js +141 -0
  96. package/esm/validator/types.d.ts +48 -0
  97. package/esm/validator/types.d.ts.map +1 -0
  98. package/esm/validator/types.js +140 -0
  99. package/esm/validator/value_types.d.ts +20 -0
  100. package/esm/validator/value_types.d.ts.map +1 -0
  101. package/esm/validator/value_types.js +126 -0
  102. package/package.json +1 -1
  103. package/script/compiler/inverses.d.ts +22 -0
  104. package/script/compiler/inverses.d.ts.map +1 -0
  105. package/script/compiler/inverses.js +150 -0
  106. package/script/compiler/link_target.d.ts +19 -0
  107. package/script/compiler/link_target.d.ts.map +1 -0
  108. package/script/compiler/link_target.js +69 -0
  109. package/script/compiler/mod.d.ts +7 -1
  110. package/script/compiler/mod.d.ts.map +1 -1
  111. package/script/compiler/mod.js +62 -14
  112. package/script/compiler/schema.d.ts.map +1 -1
  113. package/script/compiler/schema.js +20 -1
  114. package/script/config/markspec.d.ts +51 -0
  115. package/script/config/markspec.d.ts.map +1 -0
  116. package/script/config/markspec.js +222 -0
  117. package/script/config/mod.d.ts +4 -0
  118. package/script/config/mod.d.ts.map +1 -1
  119. package/script/config/mod.js +28 -16
  120. package/script/formatter/mod.d.ts +12 -2
  121. package/script/formatter/mod.d.ts.map +1 -1
  122. package/script/formatter/mod.js +131 -22
  123. package/script/mod.d.ts +10 -6
  124. package/script/mod.d.ts.map +1 -1
  125. package/script/mod.js +48 -19
  126. package/script/model/attributes.d.ts +47 -0
  127. package/script/model/attributes.d.ts.map +1 -0
  128. package/script/model/attributes.js +101 -0
  129. package/script/model/mod.d.ts +255 -26
  130. package/script/model/mod.d.ts.map +1 -1
  131. package/script/model/mod.js +34 -2
  132. package/script/model/profile.d.ts +189 -0
  133. package/script/model/profile.d.ts.map +1 -0
  134. package/script/model/profile.js +34 -0
  135. package/script/parser/attributes.d.ts +13 -1
  136. package/script/parser/attributes.d.ts.map +1 -1
  137. package/script/parser/attributes.js +48 -0
  138. package/script/parser/frontmatter.d.ts +53 -0
  139. package/script/parser/frontmatter.d.ts.map +1 -0
  140. package/script/parser/frontmatter.js +188 -0
  141. package/script/parser/grammars.js +11 -2
  142. package/script/parser/markdown.d.ts +11 -4
  143. package/script/parser/markdown.d.ts.map +1 -1
  144. package/script/parser/markdown.js +84 -37
  145. package/script/parser/mod.d.ts +26 -10
  146. package/script/parser/mod.d.ts.map +1 -1
  147. package/script/parser/mod.js +41 -10
  148. package/script/parser/source.d.ts +12 -8
  149. package/script/parser/source.d.ts.map +1 -1
  150. package/script/parser/source.js +20 -13
  151. package/script/profile/cache.d.ts +29 -0
  152. package/script/profile/cache.d.ts.map +1 -0
  153. package/script/profile/cache.js +48 -0
  154. package/script/profile/chain.d.ts +42 -0
  155. package/script/profile/chain.d.ts.map +1 -0
  156. package/script/profile/chain.js +229 -0
  157. package/script/profile/git-cache.d.ts +73 -0
  158. package/script/profile/git-cache.d.ts.map +1 -0
  159. package/script/profile/git-cache.js +104 -0
  160. package/script/profile/load.d.ts +28 -0
  161. package/script/profile/load.d.ts.map +1 -0
  162. package/script/profile/load.js +53 -0
  163. package/script/profile/manifest.d.ts +21 -0
  164. package/script/profile/manifest.d.ts.map +1 -0
  165. package/script/profile/manifest.js +833 -0
  166. package/script/profile/merge.d.ts +26 -0
  167. package/script/profile/merge.d.ts.map +1 -0
  168. package/script/profile/merge.js +521 -0
  169. package/script/profile/mod.d.ts +23 -0
  170. package/script/profile/mod.d.ts.map +1 -0
  171. package/script/profile/mod.js +31 -0
  172. package/script/profile/npm.d.ts +51 -0
  173. package/script/profile/npm.d.ts.map +1 -0
  174. package/script/profile/npm.js +191 -0
  175. package/script/profile/resolver.d.ts +60 -0
  176. package/script/profile/resolver.d.ts.map +1 -0
  177. package/script/profile/resolver.js +136 -0
  178. package/script/reporter/mod.js +14 -27
  179. package/script/validator/attributes.d.ts +43 -0
  180. package/script/validator/attributes.d.ts.map +1 -0
  181. package/script/validator/attributes.js +173 -0
  182. package/script/validator/mod.d.ts +27 -6
  183. package/script/validator/mod.d.ts.map +1 -1
  184. package/script/validator/mod.js +145 -123
  185. package/script/validator/normalize.d.ts +21 -0
  186. package/script/validator/normalize.d.ts.map +1 -0
  187. package/script/validator/normalize.js +61 -0
  188. package/script/validator/pattern.d.ts +23 -0
  189. package/script/validator/pattern.d.ts.map +1 -0
  190. package/script/validator/pattern.js +47 -0
  191. package/script/validator/pipeline.d.ts +30 -0
  192. package/script/validator/pipeline.d.ts.map +1 -0
  193. package/script/validator/pipeline.js +118 -0
  194. package/script/validator/traceability.d.ts +48 -0
  195. package/script/validator/traceability.d.ts.map +1 -0
  196. package/script/validator/traceability.js +146 -0
  197. package/script/validator/types.d.ts +48 -0
  198. package/script/validator/types.d.ts.map +1 -0
  199. package/script/validator/types.js +144 -0
  200. package/script/validator/value_types.d.ts +20 -0
  201. package/script/validator/value_types.d.ts.map +1 -0
  202. package/script/validator/value_types.js +129 -0
@@ -0,0 +1,186 @@
1
+ /**
2
+ * @module core/profile/npm
3
+ *
4
+ * Resolve an npm profile specifier by downloading the package tarball
5
+ * via `npm pack` and extracting `markspec.yaml` from it. Results are
6
+ * cached under the global XDG cache directory.
7
+ */
8
+ import { join } from "@std/path";
9
+ /** Default npm runner using `Deno.Command`. */
10
+ export async function defaultRunNpm(args, cwd) {
11
+ const cmd = new Deno.Command("npm", {
12
+ args: [...args],
13
+ cwd,
14
+ stdout: "piped",
15
+ stderr: "piped",
16
+ });
17
+ const result = await cmd.output();
18
+ return {
19
+ code: result.code,
20
+ stdout: new TextDecoder().decode(result.stdout),
21
+ stderr: new TextDecoder().decode(result.stderr),
22
+ };
23
+ }
24
+ /**
25
+ * Build the cache directory path for an npm package.
26
+ * Layout: `<cacheRoot>/npm/@scope/name/<version>/` or `<cacheRoot>/npm/name/<version>/`
27
+ */
28
+ function npmCacheDir(cacheRoot, spec, version) {
29
+ return spec.scope
30
+ ? join(cacheRoot, "npm", spec.scope, spec.name, version)
31
+ : join(cacheRoot, "npm", spec.name, version);
32
+ }
33
+ /** Extract semver from a tarball filename like `profile-default-1.0.0.tgz`. */
34
+ export function extractVersionFromTarball(filename) {
35
+ const match = filename.match(/(\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?)\.tgz$/);
36
+ return match ? match[1] : null;
37
+ }
38
+ /**
39
+ * Resolve an npm specifier into a {@linkcode ResolvedProfileSource}.
40
+ *
41
+ * 1. Check the cache for an existing resolution
42
+ * 2. On miss, run `npm pack <pkg>@<range> --pack-destination <tmpdir>`
43
+ * 3. Extract `markspec.yaml` from the tarball
44
+ * 4. Cache to `<cacheRoot>/npm/<pkg>/<version>/`
45
+ * 5. Return the resolved source
46
+ */
47
+ export async function resolveNpmSpecifier(specifier, diagnostics, opts) {
48
+ const runNpm = opts.runNpm ?? defaultRunNpm;
49
+ const pkgName = specifier.scope
50
+ ? `${specifier.scope}/${specifier.name}`
51
+ : specifier.name;
52
+ const pkgWithRange = `${pkgName}@${specifier.range}`;
53
+ // Cache hit — if we know the version, check for cached manifest.
54
+ if (opts.resolvedVersion) {
55
+ const cachedDir = npmCacheDir(opts.cacheRoot, specifier, opts.resolvedVersion);
56
+ const cachedManifest = join(cachedDir, "markspec.yaml");
57
+ const cached = await opts.readFile(cachedManifest);
58
+ if (cached !== undefined) {
59
+ return {
60
+ rawYaml: cached,
61
+ sourcePath: cachedManifest,
62
+ baseDir: cachedDir,
63
+ };
64
+ }
65
+ }
66
+ // Run npm pack to download the tarball.
67
+ let tmpDir;
68
+ const mkTmp = opts.makeTempDir ??
69
+ (() => Deno.makeTempDir({ prefix: "markspec-npm-" }));
70
+ const rmTmp = opts.removeTempDir ??
71
+ ((p) => Deno.remove(p, { recursive: true }));
72
+ try {
73
+ tmpDir = await mkTmp();
74
+ const packResult = await runNpm([
75
+ "pack",
76
+ pkgWithRange,
77
+ "--pack-destination",
78
+ tmpDir,
79
+ ]);
80
+ if (packResult.code !== 0) {
81
+ // Distinguish npm-not-found from package-not-found.
82
+ const stderr = packResult.stderr.toLowerCase();
83
+ if (packResult.code === 127 ||
84
+ stderr.includes("command not found") ||
85
+ stderr.includes("not recognized")) {
86
+ diagnostics.push({
87
+ code: "PROFILE-ADD-004",
88
+ severity: "error",
89
+ message: `npm is not installed or not in PATH; cannot resolve '${pkgWithRange}'`,
90
+ location: { file: "<specifier>", line: 1, column: 1 },
91
+ });
92
+ }
93
+ else {
94
+ diagnostics.push({
95
+ code: "PROFILE-LOAD-001",
96
+ severity: "error",
97
+ message: `npm pack failed for '${pkgWithRange}': ${packResult.stderr.trim()}`,
98
+ location: { file: "<specifier>", line: 1, column: 1 },
99
+ });
100
+ }
101
+ return null;
102
+ }
103
+ // Find the tarball in tmpDir.
104
+ const stdout = packResult.stdout.trim();
105
+ const tarballName = stdout.split("\n").pop()?.trim();
106
+ if (!tarballName) {
107
+ diagnostics.push({
108
+ code: "PROFILE-LOAD-001",
109
+ severity: "error",
110
+ message: `npm pack for '${pkgWithRange}' produced no output`,
111
+ location: { file: "<specifier>", line: 1, column: 1 },
112
+ });
113
+ return null;
114
+ }
115
+ const version = extractVersionFromTarball(tarballName);
116
+ if (!version) {
117
+ diagnostics.push({
118
+ code: "PROFILE-LOAD-001",
119
+ severity: "error",
120
+ message: `cannot extract version from tarball '${tarballName}'`,
121
+ location: { file: "<specifier>", line: 1, column: 1 },
122
+ });
123
+ return null;
124
+ }
125
+ // Check cache again with the resolved version.
126
+ const cacheTargetDir = npmCacheDir(opts.cacheRoot, specifier, version);
127
+ const cacheManifestPath = join(cacheTargetDir, "markspec.yaml");
128
+ const existingCached = await opts.readFile(cacheManifestPath);
129
+ if (existingCached !== undefined) {
130
+ return {
131
+ rawYaml: existingCached,
132
+ sourcePath: cacheManifestPath,
133
+ baseDir: cacheTargetDir,
134
+ };
135
+ }
136
+ // Extract tarball into cache directory.
137
+ await Deno.mkdir(cacheTargetDir, { recursive: true });
138
+ const tgzPath = join(tmpDir, tarballName);
139
+ const tarResult = await runTar(tgzPath, cacheTargetDir);
140
+ if (tarResult.code !== 0) {
141
+ diagnostics.push({
142
+ code: "PROFILE-LOAD-001",
143
+ severity: "error",
144
+ message: `tar extraction failed for '${tarballName}': ${tarResult.stderr.trim()}`,
145
+ location: { file: tgzPath, line: 1, column: 1 },
146
+ });
147
+ return null;
148
+ }
149
+ // Read the manifest from extracted contents.
150
+ const rawYaml = await opts.readFile(cacheManifestPath);
151
+ if (rawYaml === undefined) {
152
+ diagnostics.push({
153
+ code: "PROFILE-LOAD-001",
154
+ severity: "error",
155
+ message: `npm package '${pkgWithRange}' does not contain markspec.yaml`,
156
+ location: { file: cacheManifestPath, line: 1, column: 1 },
157
+ });
158
+ return null;
159
+ }
160
+ return { rawYaml, sourcePath: cacheManifestPath, baseDir: cacheTargetDir };
161
+ }
162
+ finally {
163
+ if (tmpDir) {
164
+ try {
165
+ await rmTmp(tmpDir);
166
+ }
167
+ catch {
168
+ // Best-effort cleanup.
169
+ }
170
+ }
171
+ }
172
+ }
173
+ /** Extract a .tgz tarball, stripping the top-level `package/` directory. */
174
+ async function runTar(tgzPath, targetDir) {
175
+ const cmd = new Deno.Command("tar", {
176
+ args: ["xzf", tgzPath, "--strip-components=1", "-C", targetDir],
177
+ stdout: "piped",
178
+ stderr: "piped",
179
+ });
180
+ const result = await cmd.output();
181
+ return {
182
+ code: result.code,
183
+ stdout: new TextDecoder().decode(result.stdout),
184
+ stderr: new TextDecoder().decode(result.stderr),
185
+ };
186
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @module core/profile/resolver
3
+ *
4
+ * Resolve a {@linkcode ProfileSpecifier} into the raw `markspec.yaml`
5
+ * contents + resolved paths, ready for the chain loader to parse.
6
+ *
7
+ * Phase 2 supports local specifiers only. Git specifiers land in Phase 4.
8
+ */
9
+ import type { ReadFile } from "../config/mod.js";
10
+ import type { Diagnostic, ProfileSpecifier } from "../model/mod.js";
11
+ import type { AppendFile, RunGit } from "./git-cache.js";
12
+ /**
13
+ * A profile that has been located on disk (or in a cache) and read.
14
+ * Ready for the chain loader to hand to `parseManifest`.
15
+ */
16
+ export interface ResolvedProfileSource {
17
+ /** Raw `markspec.yaml` contents. */
18
+ readonly rawYaml: string;
19
+ /** Absolute path of `<baseDir>/markspec.yaml`. */
20
+ readonly sourcePath: string;
21
+ /** Absolute directory the profile lives in (used for future extends resolution). */
22
+ readonly baseDir: string;
23
+ }
24
+ /**
25
+ * Resolve a local specifier. The specifier's `path` is joined to `contextDir`
26
+ * and the `markspec.yaml` inside that directory is read.
27
+ *
28
+ * @param specifier - The local-kind specifier
29
+ * @param contextDir - Absolute path of the directory that declared the specifier
30
+ * (the `.markspec.yaml` parent dir for top-level specifiers)
31
+ * @param readFile - File reader abstraction
32
+ * @param diagnostics - Accumulator for emit errors (PROFILE-LOAD-001)
33
+ */
34
+ export declare function resolveLocalSpecifier(specifier: Extract<ProfileSpecifier, {
35
+ kind: "local";
36
+ }>, contextDir: string, readFile: ReadFile, diagnostics: Diagnostic[]): Promise<ResolvedProfileSource | null>;
37
+ /** Options accepted by {@linkcode resolveGitSpecifier}. */
38
+ export interface ResolveGitOptions {
39
+ /** Injectable git runner — defaults to {@linkcode defaultRunGit}. */
40
+ readonly runGit?: RunGit;
41
+ /** Injectable file appender — defaults to {@linkcode defaultAppendFile}. */
42
+ readonly appendFile?: AppendFile;
43
+ }
44
+ /**
45
+ * Resolve a git specifier via a per-project shallow+sparse clone cache.
46
+ *
47
+ * On cache hit: reads `markspec.yaml` from the cached location.
48
+ * On cache miss: Task 4.4 implements the clone; for now emits
49
+ * `PROFILE-LOAD-001`.
50
+ *
51
+ * @param specifier - The git-kind specifier
52
+ * @param projectRoot - Absolute path of the project root (holds `.markspec/cache/`)
53
+ * @param readFile - File reader abstraction
54
+ * @param diagnostics - Accumulator for errors
55
+ * @param opts - Injectable runner (optional, defaults to real `git`)
56
+ */
57
+ export declare function resolveGitSpecifier(specifier: Extract<ProfileSpecifier, {
58
+ kind: "git";
59
+ }>, projectRoot: string, readFile: ReadFile, diagnostics: Diagnostic[], opts?: ResolveGitOptions): Promise<ResolvedProfileSource | null>;
60
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/profile/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAOpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,EACvD,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAevC;AAED,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,OAAO,CAAC,gBAAgB,EAAE;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC,EACrD,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,UAAU,EAAE,EACzB,IAAI,GAAE,iBAAsB,GAC3B,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CA4FvC"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @module core/profile/resolver
3
+ *
4
+ * Resolve a {@linkcode ProfileSpecifier} into the raw `markspec.yaml`
5
+ * contents + resolved paths, ready for the chain loader to parse.
6
+ *
7
+ * Phase 2 supports local specifiers only. Git specifiers land in Phase 4.
8
+ */
9
+ import { join, resolve } from "@std/path";
10
+ import { computeCacheLocation, defaultAppendFile, defaultRunGit, ensureCacheGitignored, } from "./git-cache.js";
11
+ /**
12
+ * Resolve a local specifier. The specifier's `path` is joined to `contextDir`
13
+ * and the `markspec.yaml` inside that directory is read.
14
+ *
15
+ * @param specifier - The local-kind specifier
16
+ * @param contextDir - Absolute path of the directory that declared the specifier
17
+ * (the `.markspec.yaml` parent dir for top-level specifiers)
18
+ * @param readFile - File reader abstraction
19
+ * @param diagnostics - Accumulator for emit errors (PROFILE-LOAD-001)
20
+ */
21
+ export async function resolveLocalSpecifier(specifier, contextDir, readFile, diagnostics) {
22
+ const baseDir = resolve(contextDir, specifier.path);
23
+ const sourcePath = join(baseDir, "markspec.yaml");
24
+ const rawYaml = await readFile(sourcePath);
25
+ if (rawYaml === undefined) {
26
+ diagnostics.push({
27
+ code: "PROFILE-LOAD-001",
28
+ severity: "error",
29
+ message: `profile specifier '${specifier.path}' cannot be resolved: ` +
30
+ `no markspec.yaml at ${sourcePath}`,
31
+ location: { file: sourcePath, line: 1, column: 1 },
32
+ });
33
+ return null;
34
+ }
35
+ return { rawYaml, sourcePath, baseDir };
36
+ }
37
+ /**
38
+ * Resolve a git specifier via a per-project shallow+sparse clone cache.
39
+ *
40
+ * On cache hit: reads `markspec.yaml` from the cached location.
41
+ * On cache miss: Task 4.4 implements the clone; for now emits
42
+ * `PROFILE-LOAD-001`.
43
+ *
44
+ * @param specifier - The git-kind specifier
45
+ * @param projectRoot - Absolute path of the project root (holds `.markspec/cache/`)
46
+ * @param readFile - File reader abstraction
47
+ * @param diagnostics - Accumulator for errors
48
+ * @param opts - Injectable runner (optional, defaults to real `git`)
49
+ */
50
+ export async function resolveGitSpecifier(specifier, projectRoot, readFile, diagnostics, opts = {}) {
51
+ const runGit = opts.runGit ?? defaultRunGit;
52
+ const location = await computeCacheLocation(projectRoot, {
53
+ repo: specifier.repo,
54
+ subpath: specifier.subpath,
55
+ tag: specifier.tag,
56
+ });
57
+ // Cache hit?
58
+ const cached = await readFile(location.manifestPath);
59
+ if (cached !== undefined) {
60
+ return buildResolvedSource(cached, location, specifier);
61
+ }
62
+ // Cache miss — clone shallow + sparse, then checkout the tag.
63
+ const cloneResult = await runGit([
64
+ "clone",
65
+ "--depth=1",
66
+ `--branch=${specifier.tag}`,
67
+ "--filter=blob:none",
68
+ "--sparse",
69
+ "--no-checkout",
70
+ specifier.repo,
71
+ location.dir,
72
+ ]);
73
+ if (cloneResult.code !== 0) {
74
+ diagnostics.push({
75
+ code: "PROFILE-LOAD-001",
76
+ severity: "error",
77
+ message: `git clone failed for ${specifier.repo}#${specifier.tag}: ` +
78
+ cloneResult.stderr.trim(),
79
+ location: { file: location.dir, line: 1, column: 1 },
80
+ });
81
+ return null;
82
+ }
83
+ // First fetch populated the cache — make sure it's ignored by git.
84
+ await ensureCacheGitignored(projectRoot, readFile, opts.appendFile ?? defaultAppendFile);
85
+ if (specifier.subpath !== undefined) {
86
+ const sparseResult = await runGit(["sparse-checkout", "set", specifier.subpath], location.dir);
87
+ if (sparseResult.code !== 0) {
88
+ diagnostics.push({
89
+ code: "PROFILE-LOAD-001",
90
+ severity: "error",
91
+ message: `git sparse-checkout failed for ${specifier.repo}#${specifier.tag} ` +
92
+ `subpath '${specifier.subpath}': ${sparseResult.stderr.trim()}`,
93
+ location: { file: location.dir, line: 1, column: 1 },
94
+ });
95
+ return null;
96
+ }
97
+ }
98
+ const checkoutResult = await runGit(["checkout", specifier.tag], location.dir);
99
+ if (checkoutResult.code !== 0) {
100
+ diagnostics.push({
101
+ code: "PROFILE-LOAD-001",
102
+ severity: "error",
103
+ message: `git checkout failed for ${specifier.repo}#${specifier.tag}: ` +
104
+ checkoutResult.stderr.trim(),
105
+ location: { file: location.dir, line: 1, column: 1 },
106
+ });
107
+ return null;
108
+ }
109
+ // After clone+checkout, expect the manifest at the computed path.
110
+ const postCloneYaml = await readFile(location.manifestPath);
111
+ if (postCloneYaml === undefined) {
112
+ diagnostics.push({
113
+ code: "PROFILE-LOAD-001",
114
+ severity: "error",
115
+ message: `git clone of ${specifier.repo}#${specifier.tag} succeeded but ` +
116
+ `no markspec.yaml at ${location.manifestPath}`,
117
+ location: { file: location.manifestPath, line: 1, column: 1 },
118
+ });
119
+ return null;
120
+ }
121
+ return buildResolvedSource(postCloneYaml, location, specifier);
122
+ }
123
+ function buildResolvedSource(rawYaml, location, specifier) {
124
+ const baseDir = specifier.subpath !== undefined
125
+ ? location.manifestPath.slice(0, -"/markspec.yaml".length)
126
+ : location.dir;
127
+ return {
128
+ rawYaml,
129
+ sourcePath: location.manifestPath,
130
+ baseDir,
131
+ };
132
+ }
@@ -33,7 +33,7 @@ function filterEntries(result, scope, label) {
33
33
  }
34
34
  if (label) {
35
35
  entries = entries.filter((e) => {
36
- const labelsAttr = e.attributes.find((a) => a.key === "Labels");
36
+ const labelsAttr = e.rawAttributes.find((a) => a.key === "Labels");
37
37
  if (!labelsAttr)
38
38
  return false;
39
39
  const labels = labelsAttr.value.split(",").map((s) => s.trim());
@@ -49,7 +49,7 @@ function buildTraceRows(result, entries) {
49
49
  return {
50
50
  id: entry.displayId,
51
51
  title: entry.title,
52
- entryType: entry.entryType ?? "",
52
+ entryType: entry.type ?? "",
53
53
  satisfies: fwd
54
54
  .filter((l) => l.kind === "satisfies")
55
55
  .map((l) => l.to)
@@ -58,10 +58,6 @@ function buildTraceRows(result, entries) {
58
58
  .filter((l) => l.kind === "satisfies")
59
59
  .map((l) => l.from)
60
60
  .join(", "),
61
- verifiedBy: rev
62
- .filter((l) => l.kind === "verifies")
63
- .map((l) => l.from)
64
- .join(", "),
65
61
  };
66
62
  });
67
63
  }
@@ -71,32 +67,31 @@ function formatTraceability(result, entries, format) {
71
67
  return JSON.stringify(rows, null, 2);
72
68
  }
73
69
  if (format === "csv") {
74
- const header = "ID,Title,Type,Satisfies,Satisfied-by,Verified-by";
70
+ const header = "ID,Title,Type,Satisfies,Satisfied-by";
75
71
  const lines = rows.map((r) => [
76
72
  r.id,
77
73
  csvEscape(r.title),
78
74
  r.entryType,
79
75
  csvEscape(r.satisfies),
80
76
  csvEscape(r.satisfiedBy),
81
- csvEscape(r.verifiedBy),
82
77
  ].join(","));
83
78
  return [header, ...lines].join("\n");
84
79
  }
85
80
  // Markdown table
86
- const header = "| ID | Title | Type | Satisfies | Satisfied-by | Verified-by |";
87
- const sep = "| -- | ----- | ---- | --------- | ------------ | ----------- |";
88
- const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} | ${r.verifiedBy || "\u2014"} |`);
81
+ const header = "| ID | Title | Type | Satisfies | Satisfied-by |";
82
+ const sep = "| -- | ----- | ---- | --------- | ------------ |";
83
+ const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
89
84
  return [header, sep, ...lines].join("\n");
90
85
  }
91
86
  function computeCoverage(result, entries) {
92
87
  const byType = {};
93
88
  const orphans = [];
94
89
  const unsatisfied = [];
95
- const unverified = [];
96
90
  let withSatisfies = 0;
97
91
  let withoutSatisfies = 0;
98
92
  for (const entry of entries) {
99
- const t = entry.entryType ?? "ref";
93
+ // Bucket by profile-declared type when available, fall back to shape.
94
+ const t = entry.type ?? (entry.shape === "referenced" ? "ref" : "untyped");
100
95
  byType[t] = (byType[t] ?? 0) + 1;
101
96
  const fwd = result.forward.get(entry.displayId) ?? [];
102
97
  const rev = result.reverse.get(entry.displayId) ?? [];
@@ -104,29 +99,25 @@ function computeCoverage(result, entries) {
104
99
  if (hasSatisfies) {
105
100
  withSatisfies++;
106
101
  }
107
- else if (entry.entryType) {
102
+ else if (entry.shape === "identified") {
108
103
  withoutSatisfies++;
109
104
  orphans.push(entry.displayId);
110
105
  }
111
- // STK/SYS without children = unsatisfied parent
106
+ // Identified entries without downstream satisfiers are tentatively
107
+ // orphaned. Which types count as "top-level unsatisfied" is
108
+ // profile-specific; a profile-aware reporter layer refines this.
112
109
  const hasSatisfiedBy = rev.some((l) => l.kind === "satisfies");
113
- if (entry.entryType &&
114
- ["STK", "SYS"].includes(entry.entryType) &&
110
+ if (entry.type &&
115
111
  !hasSatisfiedBy) {
116
112
  unsatisfied.push(entry.displayId);
117
113
  }
118
- // Typed entries without verification
119
- const hasVerification = rev.some((l) => l.kind === "verifies");
120
- if (entry.entryType && !hasVerification) {
121
- unverified.push(entry.displayId);
122
- }
123
114
  }
124
115
  return {
125
116
  total: entries.length,
126
117
  byType,
127
118
  withSatisfies,
128
119
  withoutSatisfies,
129
- gaps: { orphans, unsatisfied, unverified },
120
+ gaps: { orphans, unsatisfied },
130
121
  };
131
122
  }
132
123
  function formatCoverage(result, entries, format) {
@@ -143,7 +134,6 @@ function formatCoverage(result, entries, format) {
143
134
  `Without Satisfies,${stats.withoutSatisfies}`,
144
135
  `Orphans,${stats.gaps.orphans.length}`,
145
136
  `Unsatisfied parents,${stats.gaps.unsatisfied.length}`,
146
- `Unverified,${stats.gaps.unverified.length}`,
147
137
  ];
148
138
  return lines.join("\n");
149
139
  }
@@ -169,9 +159,6 @@ function formatCoverage(result, entries, format) {
169
159
  if (stats.gaps.unsatisfied.length > 0) {
170
160
  lines.push("## Unsatisfied parents (STK/SYS with no children)", "", ...stats.gaps.unsatisfied.map((id) => `- ${id}`), "");
171
161
  }
172
- if (stats.gaps.unverified.length > 0) {
173
- lines.push("## Unverified requirements", "", ...stats.gaps.unverified.map((id) => `- ${id}`), "");
174
- }
175
162
  return lines.join("\n");
176
163
  }
177
164
  // ---------------------------------------------------------------------------
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @module core/validator/attributes
3
+ *
4
+ * Validator Stage 3 — typed attribute validation.
5
+ *
6
+ * Runs after Stage 2 classification. For each entry, computes the effective
7
+ * attribute scope (universal ∪ shape ∪ type) and checks:
8
+ * - Required presence (MSL-A001)
9
+ * - Cardinality (MSL-A002 upper / MSL-A003 lower)
10
+ * - Value-type conformance (MSL-A004, delegated to value_types.ts)
11
+ * - Unknown attributes (MSL-A005 warning)
12
+ */
13
+ import type { AttrDecl, Diagnostic, EffectiveProfile, Entry } from "../model/mod.js";
14
+ /**
15
+ * Effective attribute declarations and required list for an entry, derived
16
+ * from the profile's universal, shape, and (when classified) type scopes.
17
+ *
18
+ * Scope layering (outer → inner):
19
+ * universal → shape.identified/referenced → types.<T>
20
+ *
21
+ * Name collisions: inner scope wins. Required lists are concatenated in
22
+ * scope order (universal first, type last) preserving duplicates across
23
+ * tiers — consumers should treat them as a set.
24
+ */
25
+ export interface EffectiveAttrScope {
26
+ readonly required: readonly string[];
27
+ readonly attributes: ReadonlyMap<string, AttrDecl>;
28
+ }
29
+ /**
30
+ * Compute the effective attribute scope for a given entry against the
31
+ * profile. Uses universal + shape scope always; adds type scope only when
32
+ * `entry.type` is set and the type is declared in the profile.
33
+ */
34
+ export declare function effectiveScope(entry: Entry, profile: EffectiveProfile): EffectiveAttrScope;
35
+ /**
36
+ * Run Stage 3 structural + value-type checks for one entry. Returns all
37
+ * diagnostics the entry produced.
38
+ *
39
+ * Task 6.2 ships required / cardinality / unknown checks. Task 6.6 wires in
40
+ * value-type conformance (MSL-A004) through the value-types registry.
41
+ */
42
+ export declare function validateAttributesForEntry(entry: Entry, profile: EffectiveProfile): Diagnostic[];
43
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/validator/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,KAAK,EACN,MAAM,iBAAiB,CAAC;AAWzB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACpD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,kBAAkB,CAsDpB;AAqBD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GACxB,UAAU,EAAE,CA4Ed"}