@driftsys/markspec 0.1.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 (242) hide show
  1. package/README.md +32 -8
  2. package/esm/_dnt.polyfills.d.ts +101 -0
  3. package/esm/_dnt.polyfills.d.ts.map +1 -0
  4. package/esm/_dnt.polyfills.js +127 -0
  5. package/esm/compiler/inverses.d.ts +22 -0
  6. package/esm/compiler/inverses.d.ts.map +1 -0
  7. package/esm/compiler/inverses.js +147 -0
  8. package/esm/compiler/link_target.d.ts +19 -0
  9. package/esm/compiler/link_target.d.ts.map +1 -0
  10. package/esm/compiler/link_target.js +66 -0
  11. package/esm/compiler/mod.d.ts +43 -0
  12. package/esm/compiler/mod.d.ts.map +1 -0
  13. package/esm/compiler/mod.js +163 -0
  14. package/esm/compiler/schema.d.ts +38 -0
  15. package/esm/compiler/schema.d.ts.map +1 -0
  16. package/esm/compiler/schema.js +44 -0
  17. package/esm/config/markspec.d.ts +51 -0
  18. package/esm/config/markspec.d.ts.map +1 -0
  19. package/esm/config/markspec.js +216 -0
  20. package/esm/config/mod.d.ts +48 -0
  21. package/esm/config/mod.d.ts.map +1 -0
  22. package/esm/config/mod.js +243 -0
  23. package/esm/formatter/mod.d.ts +65 -0
  24. package/esm/formatter/mod.d.ts.map +1 -0
  25. package/esm/formatter/mod.js +306 -0
  26. package/esm/mod.d.ts +19 -0
  27. package/esm/mod.d.ts.map +1 -1
  28. package/esm/mod.js +18 -0
  29. package/esm/model/attributes.d.ts +47 -0
  30. package/esm/model/attributes.d.ts.map +1 -0
  31. package/esm/model/attributes.js +97 -0
  32. package/esm/model/mod.d.ts +381 -0
  33. package/esm/model/mod.d.ts.map +1 -0
  34. package/esm/model/mod.js +73 -0
  35. package/esm/model/profile.d.ts +189 -0
  36. package/esm/model/profile.d.ts.map +1 -0
  37. package/esm/model/profile.js +31 -0
  38. package/esm/parser/attributes.d.ts +48 -0
  39. package/esm/parser/attributes.d.ts.map +1 -0
  40. package/esm/parser/attributes.js +131 -0
  41. package/esm/parser/captions.d.ts +25 -0
  42. package/esm/parser/captions.d.ts.map +1 -0
  43. package/esm/parser/captions.js +148 -0
  44. package/esm/parser/directives.d.ts +29 -0
  45. package/esm/parser/directives.d.ts.map +1 -0
  46. package/esm/parser/directives.js +88 -0
  47. package/esm/parser/frontmatter.d.ts +53 -0
  48. package/esm/parser/frontmatter.d.ts.map +1 -0
  49. package/esm/parser/frontmatter.js +185 -0
  50. package/esm/parser/grammars.d.ts +22 -0
  51. package/esm/parser/grammars.d.ts.map +1 -0
  52. package/esm/parser/grammars.js +70 -0
  53. package/esm/parser/markdown.d.ts +32 -0
  54. package/esm/parser/markdown.d.ts.map +1 -0
  55. package/esm/parser/markdown.js +225 -0
  56. package/esm/parser/mod.d.ts +73 -0
  57. package/esm/parser/mod.d.ts.map +1 -0
  58. package/esm/parser/mod.js +89 -0
  59. package/esm/parser/references.d.ts +24 -0
  60. package/esm/parser/references.d.ts.map +1 -0
  61. package/esm/parser/references.js +71 -0
  62. package/esm/parser/remark.d.ts +9 -0
  63. package/esm/parser/remark.d.ts.map +1 -0
  64. package/esm/parser/remark.js +11 -0
  65. package/esm/parser/source.d.ts +33 -0
  66. package/esm/parser/source.d.ts.map +1 -0
  67. package/esm/parser/source.js +192 -0
  68. package/esm/profile/cache.d.ts +29 -0
  69. package/esm/profile/cache.d.ts.map +1 -0
  70. package/esm/profile/cache.js +45 -0
  71. package/esm/profile/chain.d.ts +42 -0
  72. package/esm/profile/chain.d.ts.map +1 -0
  73. package/esm/profile/chain.js +193 -0
  74. package/esm/profile/git-cache.d.ts +73 -0
  75. package/esm/profile/git-cache.d.ts.map +1 -0
  76. package/esm/profile/git-cache.js +96 -0
  77. package/esm/profile/load.d.ts +28 -0
  78. package/esm/profile/load.d.ts.map +1 -0
  79. package/esm/profile/load.js +50 -0
  80. package/esm/profile/manifest.d.ts +21 -0
  81. package/esm/profile/manifest.d.ts.map +1 -0
  82. package/esm/profile/manifest.js +830 -0
  83. package/esm/profile/merge.d.ts +26 -0
  84. package/esm/profile/merge.d.ts.map +1 -0
  85. package/esm/profile/merge.js +518 -0
  86. package/esm/profile/mod.d.ts +23 -0
  87. package/esm/profile/mod.d.ts.map +1 -0
  88. package/esm/profile/mod.js +14 -0
  89. package/esm/profile/npm.d.ts +51 -0
  90. package/esm/profile/npm.d.ts.map +1 -0
  91. package/esm/profile/npm.js +186 -0
  92. package/esm/profile/resolver.d.ts +60 -0
  93. package/esm/profile/resolver.d.ts.map +1 -0
  94. package/esm/profile/resolver.js +132 -0
  95. package/esm/reporter/mod.d.ts +31 -0
  96. package/esm/reporter/mod.d.ts.map +1 -0
  97. package/esm/reporter/mod.js +173 -0
  98. package/esm/validator/attributes.d.ts +43 -0
  99. package/esm/validator/attributes.d.ts.map +1 -0
  100. package/esm/validator/attributes.js +169 -0
  101. package/esm/validator/mod.d.ts +44 -0
  102. package/esm/validator/mod.d.ts.map +1 -0
  103. package/esm/validator/mod.js +214 -0
  104. package/esm/validator/normalize.d.ts +21 -0
  105. package/esm/validator/normalize.d.ts.map +1 -0
  106. package/esm/validator/normalize.js +58 -0
  107. package/esm/validator/pattern.d.ts +23 -0
  108. package/esm/validator/pattern.d.ts.map +1 -0
  109. package/esm/validator/pattern.js +44 -0
  110. package/esm/validator/pipeline.d.ts +30 -0
  111. package/esm/validator/pipeline.d.ts.map +1 -0
  112. package/esm/validator/pipeline.js +115 -0
  113. package/esm/validator/traceability.d.ts +48 -0
  114. package/esm/validator/traceability.d.ts.map +1 -0
  115. package/esm/validator/traceability.js +141 -0
  116. package/esm/validator/types.d.ts +48 -0
  117. package/esm/validator/types.d.ts.map +1 -0
  118. package/esm/validator/types.js +140 -0
  119. package/esm/validator/value_types.d.ts +20 -0
  120. package/esm/validator/value_types.d.ts.map +1 -0
  121. package/esm/validator/value_types.js +126 -0
  122. package/package.json +8 -1
  123. package/script/_dnt.polyfills.d.ts +101 -0
  124. package/script/_dnt.polyfills.d.ts.map +1 -0
  125. package/script/_dnt.polyfills.js +130 -0
  126. package/script/compiler/inverses.d.ts +22 -0
  127. package/script/compiler/inverses.d.ts.map +1 -0
  128. package/script/compiler/inverses.js +150 -0
  129. package/script/compiler/link_target.d.ts +19 -0
  130. package/script/compiler/link_target.d.ts.map +1 -0
  131. package/script/compiler/link_target.js +69 -0
  132. package/script/compiler/mod.d.ts +43 -0
  133. package/script/compiler/mod.d.ts.map +1 -0
  134. package/script/compiler/mod.js +169 -0
  135. package/script/compiler/schema.d.ts +38 -0
  136. package/script/compiler/schema.d.ts.map +1 -0
  137. package/script/compiler/schema.js +47 -0
  138. package/script/config/markspec.d.ts +51 -0
  139. package/script/config/markspec.d.ts.map +1 -0
  140. package/script/config/markspec.js +222 -0
  141. package/script/config/mod.d.ts +48 -0
  142. package/script/config/mod.d.ts.map +1 -0
  143. package/script/config/mod.js +250 -0
  144. package/script/formatter/mod.d.ts +65 -0
  145. package/script/formatter/mod.d.ts.map +1 -0
  146. package/script/formatter/mod.js +313 -0
  147. package/script/mod.d.ts +19 -0
  148. package/script/mod.d.ts.map +1 -1
  149. package/script/mod.js +65 -2
  150. package/script/model/attributes.d.ts +47 -0
  151. package/script/model/attributes.d.ts.map +1 -0
  152. package/script/model/attributes.js +101 -0
  153. package/script/model/mod.d.ts +381 -0
  154. package/script/model/mod.d.ts.map +1 -0
  155. package/script/model/mod.js +83 -0
  156. package/script/model/profile.d.ts +189 -0
  157. package/script/model/profile.d.ts.map +1 -0
  158. package/script/model/profile.js +34 -0
  159. package/script/parser/attributes.d.ts +48 -0
  160. package/script/parser/attributes.d.ts.map +1 -0
  161. package/script/parser/attributes.js +137 -0
  162. package/script/parser/captions.d.ts +25 -0
  163. package/script/parser/captions.d.ts.map +1 -0
  164. package/script/parser/captions.js +151 -0
  165. package/script/parser/directives.d.ts +29 -0
  166. package/script/parser/directives.d.ts.map +1 -0
  167. package/script/parser/directives.js +91 -0
  168. package/script/parser/frontmatter.d.ts +53 -0
  169. package/script/parser/frontmatter.d.ts.map +1 -0
  170. package/script/parser/frontmatter.js +188 -0
  171. package/script/parser/grammars.d.ts +22 -0
  172. package/script/parser/grammars.d.ts.map +1 -0
  173. package/script/parser/grammars.js +77 -0
  174. package/script/parser/markdown.d.ts +32 -0
  175. package/script/parser/markdown.d.ts.map +1 -0
  176. package/script/parser/markdown.js +228 -0
  177. package/script/parser/mod.d.ts +73 -0
  178. package/script/parser/mod.d.ts.map +1 -0
  179. package/script/parser/mod.js +101 -0
  180. package/script/parser/references.d.ts +24 -0
  181. package/script/parser/references.d.ts.map +1 -0
  182. package/script/parser/references.js +74 -0
  183. package/script/parser/remark.d.ts +9 -0
  184. package/script/parser/remark.d.ts.map +1 -0
  185. package/script/parser/remark.js +17 -0
  186. package/script/parser/source.d.ts +33 -0
  187. package/script/parser/source.d.ts.map +1 -0
  188. package/script/parser/source.js +198 -0
  189. package/script/profile/cache.d.ts +29 -0
  190. package/script/profile/cache.d.ts.map +1 -0
  191. package/script/profile/cache.js +48 -0
  192. package/script/profile/chain.d.ts +42 -0
  193. package/script/profile/chain.d.ts.map +1 -0
  194. package/script/profile/chain.js +229 -0
  195. package/script/profile/git-cache.d.ts +73 -0
  196. package/script/profile/git-cache.d.ts.map +1 -0
  197. package/script/profile/git-cache.js +104 -0
  198. package/script/profile/load.d.ts +28 -0
  199. package/script/profile/load.d.ts.map +1 -0
  200. package/script/profile/load.js +53 -0
  201. package/script/profile/manifest.d.ts +21 -0
  202. package/script/profile/manifest.d.ts.map +1 -0
  203. package/script/profile/manifest.js +833 -0
  204. package/script/profile/merge.d.ts +26 -0
  205. package/script/profile/merge.d.ts.map +1 -0
  206. package/script/profile/merge.js +521 -0
  207. package/script/profile/mod.d.ts +23 -0
  208. package/script/profile/mod.d.ts.map +1 -0
  209. package/script/profile/mod.js +31 -0
  210. package/script/profile/npm.d.ts +51 -0
  211. package/script/profile/npm.d.ts.map +1 -0
  212. package/script/profile/npm.js +191 -0
  213. package/script/profile/resolver.d.ts +60 -0
  214. package/script/profile/resolver.d.ts.map +1 -0
  215. package/script/profile/resolver.js +136 -0
  216. package/script/reporter/mod.d.ts +31 -0
  217. package/script/reporter/mod.d.ts.map +1 -0
  218. package/script/reporter/mod.js +176 -0
  219. package/script/validator/attributes.d.ts +43 -0
  220. package/script/validator/attributes.d.ts.map +1 -0
  221. package/script/validator/attributes.js +173 -0
  222. package/script/validator/mod.d.ts +44 -0
  223. package/script/validator/mod.d.ts.map +1 -0
  224. package/script/validator/mod.js +231 -0
  225. package/script/validator/normalize.d.ts +21 -0
  226. package/script/validator/normalize.d.ts.map +1 -0
  227. package/script/validator/normalize.js +61 -0
  228. package/script/validator/pattern.d.ts +23 -0
  229. package/script/validator/pattern.d.ts.map +1 -0
  230. package/script/validator/pattern.js +47 -0
  231. package/script/validator/pipeline.d.ts +30 -0
  232. package/script/validator/pipeline.d.ts.map +1 -0
  233. package/script/validator/pipeline.js +118 -0
  234. package/script/validator/traceability.d.ts +48 -0
  235. package/script/validator/traceability.d.ts.map +1 -0
  236. package/script/validator/traceability.js +146 -0
  237. package/script/validator/types.d.ts +48 -0
  238. package/script/validator/types.d.ts.map +1 -0
  239. package/script/validator/types.js +144 -0
  240. package/script/validator/value_types.d.ts +20 -0
  241. package/script/validator/value_types.d.ts.map +1 -0
  242. 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
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @module reporter
3
+ *
4
+ * Output reporters. Transforms compiled traceability graph into
5
+ * traceability matrices and coverage reports in md, json, or csv format.
6
+ */
7
+ import type { CompileResult } from "../compiler/mod.js";
8
+ /** Supported report kinds. */
9
+ export type ReportKind = "traceability" | "coverage";
10
+ /** Supported output formats. */
11
+ export type ReportFormat = "md" | "json" | "csv";
12
+ /** Options for {@linkcode report}. */
13
+ export interface ReportOptions {
14
+ /** Report kind. */
15
+ readonly kind: ReportKind;
16
+ /** Output format. */
17
+ readonly format: ReportFormat;
18
+ /** Filter entries by domain abbreviation in display ID. */
19
+ readonly scope?: string;
20
+ /** Filter entries by label value. */
21
+ readonly label?: string;
22
+ }
23
+ /**
24
+ * Generate a report from compiled traceability graph.
25
+ *
26
+ * @param result - Compiled project
27
+ * @param options - Report options
28
+ * @returns Formatted report string
29
+ */
30
+ export declare function report(result: CompileResult, options: ReportOptions): string;
31
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/reporter/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,8BAA8B;AAC9B,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,UAAU,CAAC;AAErD,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,qCAAqC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,CAO5E"}
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ /**
3
+ * @module reporter
4
+ *
5
+ * Output reporters. Transforms compiled traceability graph into
6
+ * traceability matrices and coverage reports in md, json, or csv format.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.report = report;
10
+ /**
11
+ * Generate a report from compiled traceability graph.
12
+ *
13
+ * @param result - Compiled project
14
+ * @param options - Report options
15
+ * @returns Formatted report string
16
+ */
17
+ function report(result, options) {
18
+ const entries = filterEntries(result, options.scope, options.label);
19
+ if (options.kind === "traceability") {
20
+ return formatTraceability(result, entries, options.format);
21
+ }
22
+ return formatCoverage(result, entries, options.format);
23
+ }
24
+ // ---------------------------------------------------------------------------
25
+ // Filtering
26
+ // ---------------------------------------------------------------------------
27
+ /** Filter entries by scope (domain) and/or label. */
28
+ function filterEntries(result, scope, label) {
29
+ let entries = [...result.entries.values()];
30
+ if (scope) {
31
+ const scopeUpper = scope.toUpperCase();
32
+ entries = entries.filter((e) => {
33
+ const parts = e.displayId.split("_");
34
+ return parts.length >= 2 && parts[1] === scopeUpper;
35
+ });
36
+ }
37
+ if (label) {
38
+ entries = entries.filter((e) => {
39
+ const labelsAttr = e.rawAttributes.find((a) => a.key === "Labels");
40
+ if (!labelsAttr)
41
+ return false;
42
+ const labels = labelsAttr.value.split(",").map((s) => s.trim());
43
+ return labels.includes(label);
44
+ });
45
+ }
46
+ return entries;
47
+ }
48
+ function buildTraceRows(result, entries) {
49
+ return entries.map((entry) => {
50
+ const fwd = result.forward.get(entry.displayId) ?? [];
51
+ const rev = result.reverse.get(entry.displayId) ?? [];
52
+ return {
53
+ id: entry.displayId,
54
+ title: entry.title,
55
+ entryType: entry.type ?? "",
56
+ satisfies: fwd
57
+ .filter((l) => l.kind === "satisfies")
58
+ .map((l) => l.to)
59
+ .join(", "),
60
+ satisfiedBy: rev
61
+ .filter((l) => l.kind === "satisfies")
62
+ .map((l) => l.from)
63
+ .join(", "),
64
+ };
65
+ });
66
+ }
67
+ function formatTraceability(result, entries, format) {
68
+ const rows = buildTraceRows(result, entries);
69
+ if (format === "json") {
70
+ return JSON.stringify(rows, null, 2);
71
+ }
72
+ if (format === "csv") {
73
+ const header = "ID,Title,Type,Satisfies,Satisfied-by";
74
+ const lines = rows.map((r) => [
75
+ r.id,
76
+ csvEscape(r.title),
77
+ r.entryType,
78
+ csvEscape(r.satisfies),
79
+ csvEscape(r.satisfiedBy),
80
+ ].join(","));
81
+ return [header, ...lines].join("\n");
82
+ }
83
+ // Markdown table
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"} |`);
87
+ return [header, sep, ...lines].join("\n");
88
+ }
89
+ function computeCoverage(result, entries) {
90
+ const byType = {};
91
+ const orphans = [];
92
+ const unsatisfied = [];
93
+ let withSatisfies = 0;
94
+ let withoutSatisfies = 0;
95
+ for (const entry of entries) {
96
+ // Bucket by profile-declared type when available, fall back to shape.
97
+ const t = entry.type ?? (entry.shape === "referenced" ? "ref" : "untyped");
98
+ byType[t] = (byType[t] ?? 0) + 1;
99
+ const fwd = result.forward.get(entry.displayId) ?? [];
100
+ const rev = result.reverse.get(entry.displayId) ?? [];
101
+ const hasSatisfies = fwd.some((l) => l.kind === "satisfies");
102
+ if (hasSatisfies) {
103
+ withSatisfies++;
104
+ }
105
+ else if (entry.shape === "identified") {
106
+ withoutSatisfies++;
107
+ orphans.push(entry.displayId);
108
+ }
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.
112
+ const hasSatisfiedBy = rev.some((l) => l.kind === "satisfies");
113
+ if (entry.type &&
114
+ !hasSatisfiedBy) {
115
+ unsatisfied.push(entry.displayId);
116
+ }
117
+ }
118
+ return {
119
+ total: entries.length,
120
+ byType,
121
+ withSatisfies,
122
+ withoutSatisfies,
123
+ gaps: { orphans, unsatisfied },
124
+ };
125
+ }
126
+ function formatCoverage(result, entries, format) {
127
+ const stats = computeCoverage(result, entries);
128
+ if (format === "json") {
129
+ return JSON.stringify(stats, null, 2);
130
+ }
131
+ if (format === "csv") {
132
+ const lines = [
133
+ "Metric,Value",
134
+ `Total entries,${stats.total}`,
135
+ ...Object.entries(stats.byType).map(([t, n]) => `Type ${t},${n}`),
136
+ `With Satisfies,${stats.withSatisfies}`,
137
+ `Without Satisfies,${stats.withoutSatisfies}`,
138
+ `Orphans,${stats.gaps.orphans.length}`,
139
+ `Unsatisfied parents,${stats.gaps.unsatisfied.length}`,
140
+ ];
141
+ return lines.join("\n");
142
+ }
143
+ // Markdown
144
+ const lines = [
145
+ "# Coverage Report",
146
+ "",
147
+ `**Total entries:** ${stats.total}`,
148
+ "",
149
+ "## By Type",
150
+ "",
151
+ ...Object.entries(stats.byType).map(([t, n]) => `- **${t}:** ${n}`),
152
+ "",
153
+ "## Coverage",
154
+ "",
155
+ `- With Satisfies: ${stats.withSatisfies}`,
156
+ `- Without Satisfies (orphans): ${stats.withoutSatisfies}`,
157
+ "",
158
+ ];
159
+ if (stats.gaps.orphans.length > 0) {
160
+ lines.push("## Orphan entries (no Satisfies)", "", ...stats.gaps.orphans.map((id) => `- ${id}`), "");
161
+ }
162
+ if (stats.gaps.unsatisfied.length > 0) {
163
+ lines.push("## Unsatisfied parents (STK/SYS with no children)", "", ...stats.gaps.unsatisfied.map((id) => `- ${id}`), "");
164
+ }
165
+ return lines.join("\n");
166
+ }
167
+ // ---------------------------------------------------------------------------
168
+ // Helpers
169
+ // ---------------------------------------------------------------------------
170
+ /** Escape a value for CSV. */
171
+ function csvEscape(value) {
172
+ if (value.includes(",") || value.includes('"') || value.includes("\n")) {
173
+ return `"${value.replace(/"/g, '""')}"`;
174
+ }
175
+ return value;
176
+ }
@@ -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"}