@driftsys/markspec 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +32 -8
  2. package/esm/compiler/inverses.d.ts +22 -0
  3. package/esm/compiler/inverses.d.ts.map +1 -0
  4. package/esm/compiler/inverses.js +147 -0
  5. package/esm/compiler/link_target.d.ts +19 -0
  6. package/esm/compiler/link_target.d.ts.map +1 -0
  7. package/esm/compiler/link_target.js +66 -0
  8. package/esm/compiler/mod.d.ts +7 -1
  9. package/esm/compiler/mod.d.ts.map +1 -1
  10. package/esm/compiler/mod.js +61 -14
  11. package/esm/compiler/schema.d.ts.map +1 -1
  12. package/esm/compiler/schema.js +20 -1
  13. package/esm/config/markspec.d.ts +51 -0
  14. package/esm/config/markspec.d.ts.map +1 -0
  15. package/esm/config/markspec.js +216 -0
  16. package/esm/config/mod.d.ts +4 -0
  17. package/esm/config/mod.d.ts.map +1 -1
  18. package/esm/config/mod.js +27 -16
  19. package/esm/formatter/mod.d.ts +19 -4
  20. package/esm/formatter/mod.d.ts.map +1 -1
  21. package/esm/formatter/mod.js +139 -29
  22. package/esm/mod.d.ts +11 -7
  23. package/esm/mod.d.ts.map +1 -1
  24. package/esm/mod.js +6 -3
  25. package/esm/model/attributes.d.ts +47 -0
  26. package/esm/model/attributes.d.ts.map +1 -0
  27. package/esm/model/attributes.js +97 -0
  28. package/esm/model/mod.d.ts +257 -26
  29. package/esm/model/mod.d.ts.map +1 -1
  30. package/esm/model/mod.js +28 -1
  31. package/esm/model/palette.d.ts +18 -0
  32. package/esm/model/palette.d.ts.map +1 -0
  33. package/esm/model/palette.js +23 -0
  34. package/esm/model/profile.d.ts +189 -0
  35. package/esm/model/profile.d.ts.map +1 -0
  36. package/esm/model/profile.js +31 -0
  37. package/esm/parser/attributes.d.ts +13 -1
  38. package/esm/parser/attributes.d.ts.map +1 -1
  39. package/esm/parser/attributes.js +47 -0
  40. package/esm/parser/frontmatter.d.ts +53 -0
  41. package/esm/parser/frontmatter.d.ts.map +1 -0
  42. package/esm/parser/frontmatter.js +185 -0
  43. package/esm/parser/grammars.js +11 -2
  44. package/esm/parser/markdown.d.ts +21 -7
  45. package/esm/parser/markdown.d.ts.map +1 -1
  46. package/esm/parser/markdown.js +101 -40
  47. package/esm/parser/mod.d.ts +26 -10
  48. package/esm/parser/mod.d.ts.map +1 -1
  49. package/esm/parser/mod.js +40 -10
  50. package/esm/parser/source.d.ts +12 -8
  51. package/esm/parser/source.d.ts.map +1 -1
  52. package/esm/parser/source.js +21 -14
  53. package/esm/profile/cache.d.ts +29 -0
  54. package/esm/profile/cache.d.ts.map +1 -0
  55. package/esm/profile/cache.js +45 -0
  56. package/esm/profile/chain.d.ts +42 -0
  57. package/esm/profile/chain.d.ts.map +1 -0
  58. package/esm/profile/chain.js +193 -0
  59. package/esm/profile/colors.d.ts +26 -0
  60. package/esm/profile/colors.d.ts.map +1 -0
  61. package/esm/profile/colors.js +46 -0
  62. package/esm/profile/git-cache.d.ts +73 -0
  63. package/esm/profile/git-cache.d.ts.map +1 -0
  64. package/esm/profile/git-cache.js +96 -0
  65. package/esm/profile/load.d.ts +28 -0
  66. package/esm/profile/load.d.ts.map +1 -0
  67. package/esm/profile/load.js +50 -0
  68. package/esm/profile/manifest.d.ts +21 -0
  69. package/esm/profile/manifest.d.ts.map +1 -0
  70. package/esm/profile/manifest.js +815 -0
  71. package/esm/profile/merge.d.ts +26 -0
  72. package/esm/profile/merge.d.ts.map +1 -0
  73. package/esm/profile/merge.js +518 -0
  74. package/esm/profile/mod.d.ts +24 -0
  75. package/esm/profile/mod.d.ts.map +1 -0
  76. package/esm/profile/mod.js +15 -0
  77. package/esm/profile/npm.d.ts +51 -0
  78. package/esm/profile/npm.d.ts.map +1 -0
  79. package/esm/profile/npm.js +186 -0
  80. package/esm/profile/resolver.d.ts +60 -0
  81. package/esm/profile/resolver.d.ts.map +1 -0
  82. package/esm/profile/resolver.js +132 -0
  83. package/esm/reporter/mod.js +14 -27
  84. package/esm/validator/attributes.d.ts +43 -0
  85. package/esm/validator/attributes.d.ts.map +1 -0
  86. package/esm/validator/attributes.js +169 -0
  87. package/esm/validator/mod.d.ts +27 -6
  88. package/esm/validator/mod.d.ts.map +1 -1
  89. package/esm/validator/mod.js +132 -124
  90. package/esm/validator/normalize.d.ts +21 -0
  91. package/esm/validator/normalize.d.ts.map +1 -0
  92. package/esm/validator/normalize.js +58 -0
  93. package/esm/validator/pattern.d.ts +23 -0
  94. package/esm/validator/pattern.d.ts.map +1 -0
  95. package/esm/validator/pattern.js +44 -0
  96. package/esm/validator/pipeline.d.ts +30 -0
  97. package/esm/validator/pipeline.d.ts.map +1 -0
  98. package/esm/validator/pipeline.js +115 -0
  99. package/esm/validator/traceability.d.ts +48 -0
  100. package/esm/validator/traceability.d.ts.map +1 -0
  101. package/esm/validator/traceability.js +141 -0
  102. package/esm/validator/types.d.ts +48 -0
  103. package/esm/validator/types.d.ts.map +1 -0
  104. package/esm/validator/types.js +140 -0
  105. package/esm/validator/value_types.d.ts +20 -0
  106. package/esm/validator/value_types.d.ts.map +1 -0
  107. package/esm/validator/value_types.js +126 -0
  108. package/package.json +1 -1
  109. package/script/compiler/inverses.d.ts +22 -0
  110. package/script/compiler/inverses.d.ts.map +1 -0
  111. package/script/compiler/inverses.js +150 -0
  112. package/script/compiler/link_target.d.ts +19 -0
  113. package/script/compiler/link_target.d.ts.map +1 -0
  114. package/script/compiler/link_target.js +69 -0
  115. package/script/compiler/mod.d.ts +7 -1
  116. package/script/compiler/mod.d.ts.map +1 -1
  117. package/script/compiler/mod.js +62 -14
  118. package/script/compiler/schema.d.ts.map +1 -1
  119. package/script/compiler/schema.js +20 -1
  120. package/script/config/markspec.d.ts +51 -0
  121. package/script/config/markspec.d.ts.map +1 -0
  122. package/script/config/markspec.js +222 -0
  123. package/script/config/mod.d.ts +4 -0
  124. package/script/config/mod.d.ts.map +1 -1
  125. package/script/config/mod.js +28 -16
  126. package/script/formatter/mod.d.ts +19 -4
  127. package/script/formatter/mod.d.ts.map +1 -1
  128. package/script/formatter/mod.js +140 -29
  129. package/script/mod.d.ts +11 -7
  130. package/script/mod.d.ts.map +1 -1
  131. package/script/mod.js +50 -19
  132. package/script/model/attributes.d.ts +47 -0
  133. package/script/model/attributes.d.ts.map +1 -0
  134. package/script/model/attributes.js +101 -0
  135. package/script/model/mod.d.ts +257 -26
  136. package/script/model/mod.d.ts.map +1 -1
  137. package/script/model/mod.js +37 -2
  138. package/script/model/palette.d.ts +18 -0
  139. package/script/model/palette.d.ts.map +1 -0
  140. package/script/model/palette.js +26 -0
  141. package/script/model/profile.d.ts +189 -0
  142. package/script/model/profile.d.ts.map +1 -0
  143. package/script/model/profile.js +34 -0
  144. package/script/parser/attributes.d.ts +13 -1
  145. package/script/parser/attributes.d.ts.map +1 -1
  146. package/script/parser/attributes.js +48 -0
  147. package/script/parser/frontmatter.d.ts +53 -0
  148. package/script/parser/frontmatter.d.ts.map +1 -0
  149. package/script/parser/frontmatter.js +188 -0
  150. package/script/parser/grammars.js +11 -2
  151. package/script/parser/markdown.d.ts +21 -7
  152. package/script/parser/markdown.d.ts.map +1 -1
  153. package/script/parser/markdown.js +100 -39
  154. package/script/parser/mod.d.ts +26 -10
  155. package/script/parser/mod.d.ts.map +1 -1
  156. package/script/parser/mod.js +42 -11
  157. package/script/parser/source.d.ts +12 -8
  158. package/script/parser/source.d.ts.map +1 -1
  159. package/script/parser/source.js +21 -14
  160. package/script/profile/cache.d.ts +29 -0
  161. package/script/profile/cache.d.ts.map +1 -0
  162. package/script/profile/cache.js +48 -0
  163. package/script/profile/chain.d.ts +42 -0
  164. package/script/profile/chain.d.ts.map +1 -0
  165. package/script/profile/chain.js +229 -0
  166. package/script/profile/colors.d.ts +26 -0
  167. package/script/profile/colors.d.ts.map +1 -0
  168. package/script/profile/colors.js +49 -0
  169. package/script/profile/git-cache.d.ts +73 -0
  170. package/script/profile/git-cache.d.ts.map +1 -0
  171. package/script/profile/git-cache.js +104 -0
  172. package/script/profile/load.d.ts +28 -0
  173. package/script/profile/load.d.ts.map +1 -0
  174. package/script/profile/load.js +53 -0
  175. package/script/profile/manifest.d.ts +21 -0
  176. package/script/profile/manifest.d.ts.map +1 -0
  177. package/script/profile/manifest.js +818 -0
  178. package/script/profile/merge.d.ts +26 -0
  179. package/script/profile/merge.d.ts.map +1 -0
  180. package/script/profile/merge.js +521 -0
  181. package/script/profile/mod.d.ts +24 -0
  182. package/script/profile/mod.d.ts.map +1 -0
  183. package/script/profile/mod.js +33 -0
  184. package/script/profile/npm.d.ts +51 -0
  185. package/script/profile/npm.d.ts.map +1 -0
  186. package/script/profile/npm.js +191 -0
  187. package/script/profile/resolver.d.ts +60 -0
  188. package/script/profile/resolver.d.ts.map +1 -0
  189. package/script/profile/resolver.js +136 -0
  190. package/script/reporter/mod.js +14 -27
  191. package/script/validator/attributes.d.ts +43 -0
  192. package/script/validator/attributes.d.ts.map +1 -0
  193. package/script/validator/attributes.js +173 -0
  194. package/script/validator/mod.d.ts +27 -6
  195. package/script/validator/mod.d.ts.map +1 -1
  196. package/script/validator/mod.js +145 -123
  197. package/script/validator/normalize.d.ts +21 -0
  198. package/script/validator/normalize.d.ts.map +1 -0
  199. package/script/validator/normalize.js +61 -0
  200. package/script/validator/pattern.d.ts +23 -0
  201. package/script/validator/pattern.d.ts.map +1 -0
  202. package/script/validator/pattern.js +47 -0
  203. package/script/validator/pipeline.d.ts +30 -0
  204. package/script/validator/pipeline.d.ts.map +1 -0
  205. package/script/validator/pipeline.js +118 -0
  206. package/script/validator/traceability.d.ts +48 -0
  207. package/script/validator/traceability.d.ts.map +1 -0
  208. package/script/validator/traceability.js +146 -0
  209. package/script/validator/types.d.ts +48 -0
  210. package/script/validator/types.d.ts.map +1 -0
  211. package/script/validator/types.js +144 -0
  212. package/script/validator/value_types.d.ts +20 -0
  213. package/script/validator/value_types.d.ts.map +1 -0
  214. package/script/validator/value_types.js +129 -0
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/npm
4
+ *
5
+ * Resolve an npm profile specifier by downloading the package tarball
6
+ * via `npm pack` and extracting `markspec.yaml` from it. Results are
7
+ * cached under the global XDG cache directory.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.defaultRunNpm = defaultRunNpm;
11
+ exports.extractVersionFromTarball = extractVersionFromTarball;
12
+ exports.resolveNpmSpecifier = resolveNpmSpecifier;
13
+ const path_1 = require("@std/path");
14
+ /** Default npm runner using `Deno.Command`. */
15
+ async function defaultRunNpm(args, cwd) {
16
+ const cmd = new Deno.Command("npm", {
17
+ args: [...args],
18
+ cwd,
19
+ stdout: "piped",
20
+ stderr: "piped",
21
+ });
22
+ const result = await cmd.output();
23
+ return {
24
+ code: result.code,
25
+ stdout: new TextDecoder().decode(result.stdout),
26
+ stderr: new TextDecoder().decode(result.stderr),
27
+ };
28
+ }
29
+ /**
30
+ * Build the cache directory path for an npm package.
31
+ * Layout: `<cacheRoot>/npm/@scope/name/<version>/` or `<cacheRoot>/npm/name/<version>/`
32
+ */
33
+ function npmCacheDir(cacheRoot, spec, version) {
34
+ return spec.scope
35
+ ? (0, path_1.join)(cacheRoot, "npm", spec.scope, spec.name, version)
36
+ : (0, path_1.join)(cacheRoot, "npm", spec.name, version);
37
+ }
38
+ /** Extract semver from a tarball filename like `profile-default-1.0.0.tgz`. */
39
+ function extractVersionFromTarball(filename) {
40
+ const match = filename.match(/(\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?)\.tgz$/);
41
+ return match ? match[1] : null;
42
+ }
43
+ /**
44
+ * Resolve an npm specifier into a {@linkcode ResolvedProfileSource}.
45
+ *
46
+ * 1. Check the cache for an existing resolution
47
+ * 2. On miss, run `npm pack <pkg>@<range> --pack-destination <tmpdir>`
48
+ * 3. Extract `markspec.yaml` from the tarball
49
+ * 4. Cache to `<cacheRoot>/npm/<pkg>/<version>/`
50
+ * 5. Return the resolved source
51
+ */
52
+ async function resolveNpmSpecifier(specifier, diagnostics, opts) {
53
+ const runNpm = opts.runNpm ?? defaultRunNpm;
54
+ const pkgName = specifier.scope
55
+ ? `${specifier.scope}/${specifier.name}`
56
+ : specifier.name;
57
+ const pkgWithRange = `${pkgName}@${specifier.range}`;
58
+ // Cache hit — if we know the version, check for cached manifest.
59
+ if (opts.resolvedVersion) {
60
+ const cachedDir = npmCacheDir(opts.cacheRoot, specifier, opts.resolvedVersion);
61
+ const cachedManifest = (0, path_1.join)(cachedDir, "markspec.yaml");
62
+ const cached = await opts.readFile(cachedManifest);
63
+ if (cached !== undefined) {
64
+ return {
65
+ rawYaml: cached,
66
+ sourcePath: cachedManifest,
67
+ baseDir: cachedDir,
68
+ };
69
+ }
70
+ }
71
+ // Run npm pack to download the tarball.
72
+ let tmpDir;
73
+ const mkTmp = opts.makeTempDir ??
74
+ (() => Deno.makeTempDir({ prefix: "markspec-npm-" }));
75
+ const rmTmp = opts.removeTempDir ??
76
+ ((p) => Deno.remove(p, { recursive: true }));
77
+ try {
78
+ tmpDir = await mkTmp();
79
+ const packResult = await runNpm([
80
+ "pack",
81
+ pkgWithRange,
82
+ "--pack-destination",
83
+ tmpDir,
84
+ ]);
85
+ if (packResult.code !== 0) {
86
+ // Distinguish npm-not-found from package-not-found.
87
+ const stderr = packResult.stderr.toLowerCase();
88
+ if (packResult.code === 127 ||
89
+ stderr.includes("command not found") ||
90
+ stderr.includes("not recognized")) {
91
+ diagnostics.push({
92
+ code: "PROFILE-ADD-004",
93
+ severity: "error",
94
+ message: `npm is not installed or not in PATH; cannot resolve '${pkgWithRange}'`,
95
+ location: { file: "<specifier>", line: 1, column: 1 },
96
+ });
97
+ }
98
+ else {
99
+ diagnostics.push({
100
+ code: "PROFILE-LOAD-001",
101
+ severity: "error",
102
+ message: `npm pack failed for '${pkgWithRange}': ${packResult.stderr.trim()}`,
103
+ location: { file: "<specifier>", line: 1, column: 1 },
104
+ });
105
+ }
106
+ return null;
107
+ }
108
+ // Find the tarball in tmpDir.
109
+ const stdout = packResult.stdout.trim();
110
+ const tarballName = stdout.split("\n").pop()?.trim();
111
+ if (!tarballName) {
112
+ diagnostics.push({
113
+ code: "PROFILE-LOAD-001",
114
+ severity: "error",
115
+ message: `npm pack for '${pkgWithRange}' produced no output`,
116
+ location: { file: "<specifier>", line: 1, column: 1 },
117
+ });
118
+ return null;
119
+ }
120
+ const version = extractVersionFromTarball(tarballName);
121
+ if (!version) {
122
+ diagnostics.push({
123
+ code: "PROFILE-LOAD-001",
124
+ severity: "error",
125
+ message: `cannot extract version from tarball '${tarballName}'`,
126
+ location: { file: "<specifier>", line: 1, column: 1 },
127
+ });
128
+ return null;
129
+ }
130
+ // Check cache again with the resolved version.
131
+ const cacheTargetDir = npmCacheDir(opts.cacheRoot, specifier, version);
132
+ const cacheManifestPath = (0, path_1.join)(cacheTargetDir, "markspec.yaml");
133
+ const existingCached = await opts.readFile(cacheManifestPath);
134
+ if (existingCached !== undefined) {
135
+ return {
136
+ rawYaml: existingCached,
137
+ sourcePath: cacheManifestPath,
138
+ baseDir: cacheTargetDir,
139
+ };
140
+ }
141
+ // Extract tarball into cache directory.
142
+ await Deno.mkdir(cacheTargetDir, { recursive: true });
143
+ const tgzPath = (0, path_1.join)(tmpDir, tarballName);
144
+ const tarResult = await runTar(tgzPath, cacheTargetDir);
145
+ if (tarResult.code !== 0) {
146
+ diagnostics.push({
147
+ code: "PROFILE-LOAD-001",
148
+ severity: "error",
149
+ message: `tar extraction failed for '${tarballName}': ${tarResult.stderr.trim()}`,
150
+ location: { file: tgzPath, line: 1, column: 1 },
151
+ });
152
+ return null;
153
+ }
154
+ // Read the manifest from extracted contents.
155
+ const rawYaml = await opts.readFile(cacheManifestPath);
156
+ if (rawYaml === undefined) {
157
+ diagnostics.push({
158
+ code: "PROFILE-LOAD-001",
159
+ severity: "error",
160
+ message: `npm package '${pkgWithRange}' does not contain markspec.yaml`,
161
+ location: { file: cacheManifestPath, line: 1, column: 1 },
162
+ });
163
+ return null;
164
+ }
165
+ return { rawYaml, sourcePath: cacheManifestPath, baseDir: cacheTargetDir };
166
+ }
167
+ finally {
168
+ if (tmpDir) {
169
+ try {
170
+ await rmTmp(tmpDir);
171
+ }
172
+ catch {
173
+ // Best-effort cleanup.
174
+ }
175
+ }
176
+ }
177
+ }
178
+ /** Extract a .tgz tarball, stripping the top-level `package/` directory. */
179
+ async function runTar(tgzPath, targetDir) {
180
+ const cmd = new Deno.Command("tar", {
181
+ args: ["xzf", tgzPath, "--strip-components=1", "-C", targetDir],
182
+ stdout: "piped",
183
+ stderr: "piped",
184
+ });
185
+ const result = await cmd.output();
186
+ return {
187
+ code: result.code,
188
+ stdout: new TextDecoder().decode(result.stdout),
189
+ stderr: new TextDecoder().decode(result.stderr),
190
+ };
191
+ }
@@ -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,136 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/resolver
4
+ *
5
+ * Resolve a {@linkcode ProfileSpecifier} into the raw `markspec.yaml`
6
+ * contents + resolved paths, ready for the chain loader to parse.
7
+ *
8
+ * Phase 2 supports local specifiers only. Git specifiers land in Phase 4.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.resolveLocalSpecifier = resolveLocalSpecifier;
12
+ exports.resolveGitSpecifier = resolveGitSpecifier;
13
+ const path_1 = require("@std/path");
14
+ const git_cache_js_1 = require("./git-cache.js");
15
+ /**
16
+ * Resolve a local specifier. The specifier's `path` is joined to `contextDir`
17
+ * and the `markspec.yaml` inside that directory is read.
18
+ *
19
+ * @param specifier - The local-kind specifier
20
+ * @param contextDir - Absolute path of the directory that declared the specifier
21
+ * (the `.markspec.yaml` parent dir for top-level specifiers)
22
+ * @param readFile - File reader abstraction
23
+ * @param diagnostics - Accumulator for emit errors (PROFILE-LOAD-001)
24
+ */
25
+ async function resolveLocalSpecifier(specifier, contextDir, readFile, diagnostics) {
26
+ const baseDir = (0, path_1.resolve)(contextDir, specifier.path);
27
+ const sourcePath = (0, path_1.join)(baseDir, "markspec.yaml");
28
+ const rawYaml = await readFile(sourcePath);
29
+ if (rawYaml === undefined) {
30
+ diagnostics.push({
31
+ code: "PROFILE-LOAD-001",
32
+ severity: "error",
33
+ message: `profile specifier '${specifier.path}' cannot be resolved: ` +
34
+ `no markspec.yaml at ${sourcePath}`,
35
+ location: { file: sourcePath, line: 1, column: 1 },
36
+ });
37
+ return null;
38
+ }
39
+ return { rawYaml, sourcePath, baseDir };
40
+ }
41
+ /**
42
+ * Resolve a git specifier via a per-project shallow+sparse clone cache.
43
+ *
44
+ * On cache hit: reads `markspec.yaml` from the cached location.
45
+ * On cache miss: Task 4.4 implements the clone; for now emits
46
+ * `PROFILE-LOAD-001`.
47
+ *
48
+ * @param specifier - The git-kind specifier
49
+ * @param projectRoot - Absolute path of the project root (holds `.markspec/cache/`)
50
+ * @param readFile - File reader abstraction
51
+ * @param diagnostics - Accumulator for errors
52
+ * @param opts - Injectable runner (optional, defaults to real `git`)
53
+ */
54
+ async function resolveGitSpecifier(specifier, projectRoot, readFile, diagnostics, opts = {}) {
55
+ const runGit = opts.runGit ?? git_cache_js_1.defaultRunGit;
56
+ const location = await (0, git_cache_js_1.computeCacheLocation)(projectRoot, {
57
+ repo: specifier.repo,
58
+ subpath: specifier.subpath,
59
+ tag: specifier.tag,
60
+ });
61
+ // Cache hit?
62
+ const cached = await readFile(location.manifestPath);
63
+ if (cached !== undefined) {
64
+ return buildResolvedSource(cached, location, specifier);
65
+ }
66
+ // Cache miss — clone shallow + sparse, then checkout the tag.
67
+ const cloneResult = await runGit([
68
+ "clone",
69
+ "--depth=1",
70
+ `--branch=${specifier.tag}`,
71
+ "--filter=blob:none",
72
+ "--sparse",
73
+ "--no-checkout",
74
+ specifier.repo,
75
+ location.dir,
76
+ ]);
77
+ if (cloneResult.code !== 0) {
78
+ diagnostics.push({
79
+ code: "PROFILE-LOAD-001",
80
+ severity: "error",
81
+ message: `git clone failed for ${specifier.repo}#${specifier.tag}: ` +
82
+ cloneResult.stderr.trim(),
83
+ location: { file: location.dir, line: 1, column: 1 },
84
+ });
85
+ return null;
86
+ }
87
+ // First fetch populated the cache — make sure it's ignored by git.
88
+ await (0, git_cache_js_1.ensureCacheGitignored)(projectRoot, readFile, opts.appendFile ?? git_cache_js_1.defaultAppendFile);
89
+ if (specifier.subpath !== undefined) {
90
+ const sparseResult = await runGit(["sparse-checkout", "set", specifier.subpath], location.dir);
91
+ if (sparseResult.code !== 0) {
92
+ diagnostics.push({
93
+ code: "PROFILE-LOAD-001",
94
+ severity: "error",
95
+ message: `git sparse-checkout failed for ${specifier.repo}#${specifier.tag} ` +
96
+ `subpath '${specifier.subpath}': ${sparseResult.stderr.trim()}`,
97
+ location: { file: location.dir, line: 1, column: 1 },
98
+ });
99
+ return null;
100
+ }
101
+ }
102
+ const checkoutResult = await runGit(["checkout", specifier.tag], location.dir);
103
+ if (checkoutResult.code !== 0) {
104
+ diagnostics.push({
105
+ code: "PROFILE-LOAD-001",
106
+ severity: "error",
107
+ message: `git checkout failed for ${specifier.repo}#${specifier.tag}: ` +
108
+ checkoutResult.stderr.trim(),
109
+ location: { file: location.dir, line: 1, column: 1 },
110
+ });
111
+ return null;
112
+ }
113
+ // After clone+checkout, expect the manifest at the computed path.
114
+ const postCloneYaml = await readFile(location.manifestPath);
115
+ if (postCloneYaml === undefined) {
116
+ diagnostics.push({
117
+ code: "PROFILE-LOAD-001",
118
+ severity: "error",
119
+ message: `git clone of ${specifier.repo}#${specifier.tag} succeeded but ` +
120
+ `no markspec.yaml at ${location.manifestPath}`,
121
+ location: { file: location.manifestPath, line: 1, column: 1 },
122
+ });
123
+ return null;
124
+ }
125
+ return buildResolvedSource(postCloneYaml, location, specifier);
126
+ }
127
+ function buildResolvedSource(rawYaml, location, specifier) {
128
+ const baseDir = specifier.subpath !== undefined
129
+ ? location.manifestPath.slice(0, -"/markspec.yaml".length)
130
+ : location.dir;
131
+ return {
132
+ rawYaml,
133
+ sourcePath: location.manifestPath,
134
+ baseDir,
135
+ };
136
+ }
@@ -36,7 +36,7 @@ function filterEntries(result, scope, label) {
36
36
  }
37
37
  if (label) {
38
38
  entries = entries.filter((e) => {
39
- const labelsAttr = e.attributes.find((a) => a.key === "Labels");
39
+ const labelsAttr = e.rawAttributes.find((a) => a.key === "Labels");
40
40
  if (!labelsAttr)
41
41
  return false;
42
42
  const labels = labelsAttr.value.split(",").map((s) => s.trim());
@@ -52,7 +52,7 @@ function buildTraceRows(result, entries) {
52
52
  return {
53
53
  id: entry.displayId,
54
54
  title: entry.title,
55
- entryType: entry.entryType ?? "",
55
+ entryType: entry.type ?? "",
56
56
  satisfies: fwd
57
57
  .filter((l) => l.kind === "satisfies")
58
58
  .map((l) => l.to)
@@ -61,10 +61,6 @@ function buildTraceRows(result, entries) {
61
61
  .filter((l) => l.kind === "satisfies")
62
62
  .map((l) => l.from)
63
63
  .join(", "),
64
- verifiedBy: rev
65
- .filter((l) => l.kind === "verifies")
66
- .map((l) => l.from)
67
- .join(", "),
68
64
  };
69
65
  });
70
66
  }
@@ -74,32 +70,31 @@ function formatTraceability(result, entries, format) {
74
70
  return JSON.stringify(rows, null, 2);
75
71
  }
76
72
  if (format === "csv") {
77
- const header = "ID,Title,Type,Satisfies,Satisfied-by,Verified-by";
73
+ const header = "ID,Title,Type,Satisfies,Satisfied-by";
78
74
  const lines = rows.map((r) => [
79
75
  r.id,
80
76
  csvEscape(r.title),
81
77
  r.entryType,
82
78
  csvEscape(r.satisfies),
83
79
  csvEscape(r.satisfiedBy),
84
- csvEscape(r.verifiedBy),
85
80
  ].join(","));
86
81
  return [header, ...lines].join("\n");
87
82
  }
88
83
  // Markdown table
89
- const header = "| ID | Title | Type | Satisfies | Satisfied-by | Verified-by |";
90
- const sep = "| -- | ----- | ---- | --------- | ------------ | ----------- |";
91
- const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} | ${r.verifiedBy || "\u2014"} |`);
84
+ const header = "| ID | Title | Type | Satisfies | Satisfied-by |";
85
+ const sep = "| -- | ----- | ---- | --------- | ------------ |";
86
+ const lines = rows.map((r) => `| ${r.id} | ${r.title} | ${r.entryType} | ${r.satisfies || "\u2014"} | ${r.satisfiedBy || "\u2014"} |`);
92
87
  return [header, sep, ...lines].join("\n");
93
88
  }
94
89
  function computeCoverage(result, entries) {
95
90
  const byType = {};
96
91
  const orphans = [];
97
92
  const unsatisfied = [];
98
- const unverified = [];
99
93
  let withSatisfies = 0;
100
94
  let withoutSatisfies = 0;
101
95
  for (const entry of entries) {
102
- const t = entry.entryType ?? "ref";
96
+ // Bucket by profile-declared type when available, fall back to shape.
97
+ const t = entry.type ?? (entry.shape === "referenced" ? "ref" : "untyped");
103
98
  byType[t] = (byType[t] ?? 0) + 1;
104
99
  const fwd = result.forward.get(entry.displayId) ?? [];
105
100
  const rev = result.reverse.get(entry.displayId) ?? [];
@@ -107,29 +102,25 @@ function computeCoverage(result, entries) {
107
102
  if (hasSatisfies) {
108
103
  withSatisfies++;
109
104
  }
110
- else if (entry.entryType) {
105
+ else if (entry.shape === "identified") {
111
106
  withoutSatisfies++;
112
107
  orphans.push(entry.displayId);
113
108
  }
114
- // STK/SYS without children = unsatisfied parent
109
+ // Identified entries without downstream satisfiers are tentatively
110
+ // orphaned. Which types count as "top-level unsatisfied" is
111
+ // profile-specific; a profile-aware reporter layer refines this.
115
112
  const hasSatisfiedBy = rev.some((l) => l.kind === "satisfies");
116
- if (entry.entryType &&
117
- ["STK", "SYS"].includes(entry.entryType) &&
113
+ if (entry.type &&
118
114
  !hasSatisfiedBy) {
119
115
  unsatisfied.push(entry.displayId);
120
116
  }
121
- // Typed entries without verification
122
- const hasVerification = rev.some((l) => l.kind === "verifies");
123
- if (entry.entryType && !hasVerification) {
124
- unverified.push(entry.displayId);
125
- }
126
117
  }
127
118
  return {
128
119
  total: entries.length,
129
120
  byType,
130
121
  withSatisfies,
131
122
  withoutSatisfies,
132
- gaps: { orphans, unsatisfied, unverified },
123
+ gaps: { orphans, unsatisfied },
133
124
  };
134
125
  }
135
126
  function formatCoverage(result, entries, format) {
@@ -146,7 +137,6 @@ function formatCoverage(result, entries, format) {
146
137
  `Without Satisfies,${stats.withoutSatisfies}`,
147
138
  `Orphans,${stats.gaps.orphans.length}`,
148
139
  `Unsatisfied parents,${stats.gaps.unsatisfied.length}`,
149
- `Unverified,${stats.gaps.unverified.length}`,
150
140
  ];
151
141
  return lines.join("\n");
152
142
  }
@@ -172,9 +162,6 @@ function formatCoverage(result, entries, format) {
172
162
  if (stats.gaps.unsatisfied.length > 0) {
173
163
  lines.push("## Unsatisfied parents (STK/SYS with no children)", "", ...stats.gaps.unsatisfied.map((id) => `- ${id}`), "");
174
164
  }
175
- if (stats.gaps.unverified.length > 0) {
176
- lines.push("## Unverified requirements", "", ...stats.gaps.unverified.map((id) => `- ${id}`), "");
177
- }
178
165
  return lines.join("\n");
179
166
  }
180
167
  // ---------------------------------------------------------------------------
@@ -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"}