@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
@@ -2,9 +2,9 @@
2
2
  /**
3
3
  * @module parser/source
4
4
  *
5
- * Source-code doc-comment parser. Extracts MarkSpec requirement blocks from
6
- * doc comments in Rust, Kotlin, C, C++, and Java source files. Delegates
7
- * parsed content to the markdown parser for entry extraction.
5
+ * Source-code doc-comment parser. Extracts MarkSpec entry blocks from doc
6
+ * comments in Rust, Kotlin, C, C++, and Java source files. Delegates parsed
7
+ * content to the markdown parser for entry extraction.
8
8
  */
9
9
  var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -14,15 +14,14 @@ exports.parseSource = parseSource;
14
14
  const web_tree_sitter_1 = __importDefault(require("web-tree-sitter"));
15
15
  const markdown_js_1 = require("./markdown.js");
16
16
  /**
17
- * Parse a source file and return all MarkSpec entries found in doc comments.
17
+ * Parse a source file and return entries extracted from doc comments.
18
18
  *
19
19
  * Uses tree-sitter to parse the source, walks the AST to find doc comment
20
- * nodes, strips comment prefixes, and delegates to the markdown parser
21
- * for entry extraction.
20
+ * nodes, strips comment prefixes, and delegates to the markdown parser for
21
+ * entry extraction. Doc comments that don't contain entry blocks are ignored.
22
22
  *
23
23
  * @param content - Source file text
24
24
  * @param options - Parse options (language grammar, file path)
25
- * @returns Array of parsed entries with `source: "doc-comment"`
26
25
  */
27
26
  function parseSource(content, options) {
28
27
  const file = options.file ?? "<unknown>";
@@ -34,22 +33,30 @@ function parseSource(content, options) {
34
33
  const entries = [];
35
34
  for (const block of blocks) {
36
35
  const markdown = wrapAsListItem(block.lines);
37
- const parsed = (0, markdown_js_1.parseMarkdown)(markdown, { file });
36
+ const { entries: parsed } = (0, markdown_js_1.parseMarkdown)(markdown, { file });
38
37
  for (const entry of parsed) {
38
+ const location = {
39
+ file,
40
+ line: block.startLine,
41
+ column: block.startColumn,
42
+ };
39
43
  entries.push({
40
44
  ...entry,
41
45
  source: "doc-comment",
42
- location: {
43
- file,
44
- line: block.startLine,
45
- column: block.startColumn,
46
+ location,
47
+ properties: {
48
+ file: {
49
+ path: file,
50
+ line: block.startLine,
51
+ column: block.startColumn,
52
+ },
46
53
  },
47
54
  });
48
55
  }
49
56
  }
50
57
  tree.delete();
51
58
  parser.delete();
52
- return entries;
59
+ return { entries };
53
60
  }
54
61
  /**
55
62
  * Recursively walk the tree-sitter AST and collect doc comment blocks.
@@ -101,7 +108,7 @@ function walkForDocComments(node, blocks) {
101
108
  });
102
109
  continue;
103
110
  }
104
- // Non-comment node — flush pending line comments, then recurse
111
+ // Non-comment node — flush pending line comments, then recurse.
105
112
  flushLineBlock();
106
113
  if (child.childCount > 0) {
107
114
  walkForDocComments(child, blocks);
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module core/profile/cache
3
+ *
4
+ * XDG-compliant cache directory resolution for profile storage.
5
+ * Profiles fetched from git or npm are cached globally so they can
6
+ * be shared across projects.
7
+ */
8
+ /**
9
+ * Environment variables consulted for cache directory resolution.
10
+ * Injectable for testing — production code passes `Deno.env.toObject()`.
11
+ */
12
+ export interface CacheEnv {
13
+ readonly XDG_CACHE_HOME?: string;
14
+ readonly HOME?: string;
15
+ readonly LOCALAPPDATA?: string;
16
+ }
17
+ /**
18
+ * Resolve the global markspec cache directory (XDG-compliant).
19
+ *
20
+ * - `$XDG_CACHE_HOME/markspec` if set (any platform)
21
+ * - macOS: `~/Library/Caches/markspec`
22
+ * - Windows: `%LOCALAPPDATA%/markspec/cache`
23
+ * - Linux/other: `~/.cache/markspec`
24
+ *
25
+ * @param env - Environment variables (injectable for tests)
26
+ * @param platform - OS platform string (injectable for tests; defaults to `Deno.build.os`)
27
+ */
28
+ export declare function cacheDir(env?: CacheEnv, platform?: string): string;
29
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/profile/cache.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACtB,GAAG,CAAC,EAAE,QAAQ,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,CAsBR"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/cache
4
+ *
5
+ * XDG-compliant cache directory resolution for profile storage.
6
+ * Profiles fetched from git or npm are cached globally so they can
7
+ * be shared across projects.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.cacheDir = cacheDir;
11
+ const path_1 = require("@std/path");
12
+ /**
13
+ * Resolve the global markspec cache directory (XDG-compliant).
14
+ *
15
+ * - `$XDG_CACHE_HOME/markspec` if set (any platform)
16
+ * - macOS: `~/Library/Caches/markspec`
17
+ * - Windows: `%LOCALAPPDATA%/markspec/cache`
18
+ * - Linux/other: `~/.cache/markspec`
19
+ *
20
+ * @param env - Environment variables (injectable for tests)
21
+ * @param platform - OS platform string (injectable for tests; defaults to `Deno.build.os`)
22
+ */
23
+ function cacheDir(env, platform) {
24
+ const e = env ?? envFromDeno();
25
+ const os = platform ?? Deno.build.os;
26
+ if (e.XDG_CACHE_HOME) {
27
+ return (0, path_1.join)(e.XDG_CACHE_HOME, "markspec");
28
+ }
29
+ if (os === "darwin") {
30
+ const home = e.HOME ?? "/tmp";
31
+ return (0, path_1.join)(home, "Library", "Caches", "markspec");
32
+ }
33
+ if (os === "windows") {
34
+ const localAppData = e.LOCALAPPDATA ??
35
+ (0, path_1.join)(e.HOME ?? "C:\\Users\\default", "AppData", "Local");
36
+ return (0, path_1.join)(localAppData, "markspec", "cache");
37
+ }
38
+ // Linux and others — XDG default
39
+ const home = e.HOME ?? "/tmp";
40
+ return (0, path_1.join)(home, ".cache", "markspec");
41
+ }
42
+ function envFromDeno() {
43
+ return {
44
+ XDG_CACHE_HOME: Deno.env.get("XDG_CACHE_HOME"),
45
+ HOME: Deno.env.get("HOME"),
46
+ LOCALAPPDATA: Deno.env.get("LOCALAPPDATA"),
47
+ };
48
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module core/profile/chain
3
+ *
4
+ * Profile chain loader. Walks the `extends:` pointer from a leaf specifier
5
+ * up to the root, producing a multi-tier {@linkcode ProfileChain} ordered
6
+ * root → leaf.
7
+ *
8
+ * Supports both local and git specifiers, with cycle + depth detection. Git
9
+ * specifiers route through {@linkcode resolveGitSpecifier} (per-project
10
+ * shallow+sparse clone cache); local specifiers route through
11
+ * {@linkcode resolveLocalSpecifier}. The chain's {@linkcode EffectiveProfile}
12
+ * is produced by {@linkcode mergeChain}.
13
+ */
14
+ import type { ReadFile } from "../config/mod.js";
15
+ import type { Diagnostic, ProfileChain, ProfileSpecifier } from "../model/mod.js";
16
+ import type { AppendFile, RunGit } from "./git-cache.js";
17
+ /** Result of loading a profile chain. */
18
+ export interface LoadChainResult {
19
+ readonly chain: ProfileChain | null;
20
+ readonly diagnostics: readonly Diagnostic[];
21
+ }
22
+ /** Options accepted by {@linkcode loadChain}. */
23
+ export interface LoadChainOptions {
24
+ readonly runGit?: RunGit;
25
+ readonly appendFile?: AppendFile;
26
+ }
27
+ /**
28
+ * Load a profile chain from a specifier, walking the `extends:` pointer up
29
+ * to the root. The returned chain's tiers are ordered root → leaf, so
30
+ * `tiers[0]` is the ultimate ancestor and `tiers[last]` is the leaf
31
+ * specified by the caller.
32
+ *
33
+ * @param specifier - The leaf specifier (from `.markspec.yaml`)
34
+ * @param contextDir - Directory the specifier was declared in (for local
35
+ * path resolution)
36
+ * @param projectRoot - Absolute path of the project root (used to locate
37
+ * the `.markspec/cache/` directory for git specifiers)
38
+ * @param readFile - File reader abstraction
39
+ * @param opts - Injectable runners for git-cache operations (optional)
40
+ */
41
+ export declare function loadChain(specifier: ProfileSpecifier, contextDir: string, projectRoot: string, readFile: ReadFile, opts?: LoadChainOptions): Promise<LoadChainResult>;
42
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/profile/chain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,UAAU,EAGV,YAAY,EACZ,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAYzD,yCAAyC;AACzC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;CAC7C;AAED,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CAClC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAC7B,SAAS,EAAE,gBAAgB,EAC3B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,GAAE,gBAAqB,GAC1B,OAAO,CAAC,eAAe,CAAC,CA+G1B"}
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/chain
4
+ *
5
+ * Profile chain loader. Walks the `extends:` pointer from a leaf specifier
6
+ * up to the root, producing a multi-tier {@linkcode ProfileChain} ordered
7
+ * root → leaf.
8
+ *
9
+ * Supports both local and git specifiers, with cycle + depth detection. Git
10
+ * specifiers route through {@linkcode resolveGitSpecifier} (per-project
11
+ * shallow+sparse clone cache); local specifiers route through
12
+ * {@linkcode resolveLocalSpecifier}. The chain's {@linkcode EffectiveProfile}
13
+ * is produced by {@linkcode mergeChain}.
14
+ */
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ var desc = Object.getOwnPropertyDescriptor(m, k);
18
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
19
+ desc = { enumerable: true, get: function() { return m[k]; } };
20
+ }
21
+ Object.defineProperty(o, k2, desc);
22
+ }) : (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ o[k2] = m[k];
25
+ }));
26
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
28
+ }) : function(o, v) {
29
+ o["default"] = v;
30
+ });
31
+ var __importStar = (this && this.__importStar) || (function () {
32
+ var ownKeys = function(o) {
33
+ ownKeys = Object.getOwnPropertyNames || function (o) {
34
+ var ar = [];
35
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
36
+ return ar;
37
+ };
38
+ return ownKeys(o);
39
+ };
40
+ return function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
47
+ })();
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.loadChain = loadChain;
50
+ const path_1 = require("@std/path");
51
+ const manifest_js_1 = require("./manifest.js");
52
+ const merge_js_1 = require("./merge.js");
53
+ const resolver_js_1 = require("./resolver.js");
54
+ /** Maximum number of tiers allowed in an `extends:` chain. */
55
+ const MAX_CHAIN_DEPTH = 20;
56
+ /**
57
+ * Load a profile chain from a specifier, walking the `extends:` pointer up
58
+ * to the root. The returned chain's tiers are ordered root → leaf, so
59
+ * `tiers[0]` is the ultimate ancestor and `tiers[last]` is the leaf
60
+ * specified by the caller.
61
+ *
62
+ * @param specifier - The leaf specifier (from `.markspec.yaml`)
63
+ * @param contextDir - Directory the specifier was declared in (for local
64
+ * path resolution)
65
+ * @param projectRoot - Absolute path of the project root (used to locate
66
+ * the `.markspec/cache/` directory for git specifiers)
67
+ * @param readFile - File reader abstraction
68
+ * @param opts - Injectable runners for git-cache operations (optional)
69
+ */
70
+ async function loadChain(specifier, contextDir, projectRoot, readFile, opts = {}) {
71
+ const diagnostics = [];
72
+ // Walk extends: chain. Accumulate tiers leaf-first, reverse at the end.
73
+ const tiersLeafFirst = [];
74
+ const visited = new Set(); // canonical specifier key
75
+ let cursorSpec = specifier;
76
+ let cursorDir = contextDir;
77
+ while (cursorSpec !== undefined) {
78
+ const key = specifierKey(cursorSpec, cursorDir);
79
+ if (visited.has(key)) {
80
+ diagnostics.push({
81
+ code: "PROFILE-LOAD-004",
82
+ severity: "error",
83
+ message: `profile extends: cycle detected at ${stringifySpec(cursorSpec)} ` +
84
+ `(already visited in this chain)`,
85
+ location: { file: "<specifier>", line: 1, column: 1 },
86
+ });
87
+ return { chain: null, diagnostics };
88
+ }
89
+ visited.add(key);
90
+ if (tiersLeafFirst.length >= MAX_CHAIN_DEPTH) {
91
+ diagnostics.push({
92
+ code: "PROFILE-LOAD-005",
93
+ severity: "error",
94
+ message: `profile extends: chain exceeds maximum depth (${MAX_CHAIN_DEPTH})`,
95
+ location: { file: "<specifier>", line: 1, column: 1 },
96
+ });
97
+ return { chain: null, diagnostics };
98
+ }
99
+ let resolved;
100
+ if (cursorSpec.kind === "git") {
101
+ resolved = await (0, resolver_js_1.resolveGitSpecifier)(cursorSpec, projectRoot, readFile, diagnostics, { runGit: opts.runGit, appendFile: opts.appendFile });
102
+ }
103
+ else if (cursorSpec.kind === "npm") {
104
+ const { resolveNpmSpecifier } = await Promise.resolve().then(() => __importStar(require("./npm.js")));
105
+ const { cacheDir: cacheDirFn } = await Promise.resolve().then(() => __importStar(require("./cache.js")));
106
+ resolved = await resolveNpmSpecifier(cursorSpec, diagnostics, {
107
+ cacheRoot: cacheDirFn(),
108
+ readFile,
109
+ });
110
+ }
111
+ else {
112
+ resolved = await (0, resolver_js_1.resolveLocalSpecifier)(cursorSpec, cursorDir, readFile, diagnostics);
113
+ }
114
+ if (!resolved) {
115
+ return { chain: null, diagnostics };
116
+ }
117
+ const parsed = (0, manifest_js_1.parseManifest)(resolved.rawYaml, resolved.sourcePath);
118
+ diagnostics.push(...parsed.diagnostics);
119
+ if (!parsed.manifest) {
120
+ return { chain: null, diagnostics };
121
+ }
122
+ const tier = {
123
+ id: parsed.manifest.id,
124
+ version: parsed.manifest.version,
125
+ specifier: cursorSpec,
126
+ manifest: parsed.manifest,
127
+ sourcePath: resolved.sourcePath,
128
+ baseDir: resolved.baseDir,
129
+ };
130
+ tiersLeafFirst.push(tier);
131
+ // Advance cursor to the parent, if any.
132
+ if (parsed.manifest.extends !== undefined) {
133
+ cursorSpec = parsed.manifest.extends;
134
+ cursorDir = resolved.baseDir;
135
+ }
136
+ else {
137
+ cursorSpec = undefined;
138
+ }
139
+ }
140
+ // Reverse so tiers[0] = root parent, tiers[last] = leaf child.
141
+ const tiers = tiersLeafFirst.reverse();
142
+ // Build a temporary chain shape to feed into mergeChain. It reads only
143
+ // .tiers; the placeholder effective is ignored by merge.
144
+ const stubChain = {
145
+ tiers,
146
+ effective: buildPlaceholderEffective(tiers),
147
+ };
148
+ const mergeResult = (0, merge_js_1.mergeChain)(stubChain);
149
+ diagnostics.push(...mergeResult.diagnostics);
150
+ if (!mergeResult.effective) {
151
+ return { chain: null, diagnostics };
152
+ }
153
+ return {
154
+ chain: { tiers, effective: mergeResult.effective },
155
+ diagnostics,
156
+ };
157
+ }
158
+ /**
159
+ * Canonical cycle-detection key for a resolved specifier. Two specifiers that
160
+ * resolve to the same tier are canonicalized to the same key:
161
+ *
162
+ * - Local specifiers key on the absolute resolved directory (after
163
+ * normalization of `.` / `..`).
164
+ * - Git specifiers key on `(repo, tag, subpath)`, which is what the git cache
165
+ * itself uses — two specifiers that hit the same cache entry are the same
166
+ * tier.
167
+ *
168
+ * Note: this does NOT canonicalize symlinks for local specifiers. Two
169
+ * different symlinked paths pointing at the same profile will only be caught
170
+ * by MAX_CHAIN_DEPTH, which emits PROFILE-LOAD-005 instead of
171
+ * PROFILE-LOAD-004. Acceptable for v1 since `Deno.realPath` would require an
172
+ * additional I/O round-trip and a filesystem shim for the test mock reader.
173
+ */
174
+ function specifierKey(spec, contextDir) {
175
+ if (spec.kind === "local") {
176
+ return `local:${(0, path_1.resolve)(contextDir, spec.path)}`;
177
+ }
178
+ if (spec.kind === "git") {
179
+ return `git:${spec.repo}#${spec.tag}|${spec.subpath ?? ""}`;
180
+ }
181
+ if (spec.kind === "npm") {
182
+ const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
183
+ return `npm:${pkg}@${spec.range}`;
184
+ }
185
+ const _exhaustive = spec;
186
+ throw new Error(`Unknown specifier kind`);
187
+ }
188
+ /** Human-readable one-liner for a specifier (used in diagnostic messages). */
189
+ function stringifySpec(spec) {
190
+ if (spec.kind === "local") {
191
+ return spec.path;
192
+ }
193
+ if (spec.kind === "git") {
194
+ return `git+${spec.repo}#${spec.tag}`;
195
+ }
196
+ if (spec.kind === "npm") {
197
+ const pkg = spec.scope ? `${spec.scope}/${spec.name}` : spec.name;
198
+ return `npm:${pkg}@${spec.range}`;
199
+ }
200
+ const _exhaustive = spec;
201
+ throw new Error(`Unknown specifier kind`);
202
+ }
203
+ /**
204
+ * Build a placeholder EffectiveProfile used only as a stub input when
205
+ * constructing the {@linkcode ProfileChain} shape we hand to
206
+ * {@linkcode mergeChain}. `mergeChain` reads only `.tiers`, so the stub
207
+ * contents are irrelevant.
208
+ */
209
+ function buildPlaceholderEffective(tiers) {
210
+ const leafOrigin = tiers[tiers.length - 1]?.id ?? "<unknown>";
211
+ return {
212
+ required: { value: [], origin: leafOrigin },
213
+ attributes: new Map(),
214
+ labels: { value: [], origin: leafOrigin },
215
+ colors: new Map(),
216
+ identified: {
217
+ required: { value: [], origin: leafOrigin },
218
+ attributes: new Map(),
219
+ traceability: new Map(),
220
+ },
221
+ referenced: {
222
+ required: { value: [], origin: leafOrigin },
223
+ attributes: new Map(),
224
+ traceability: new Map(),
225
+ },
226
+ types: new Map(),
227
+ documents: { types: new Map(), frontMatter: new Map() },
228
+ };
229
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module core/profile/colors
3
+ *
4
+ * Profile-driven entry color resolution. Pure function that maps an entry
5
+ * and the active profile to a palette hue name (or `null` for uncolored).
6
+ *
7
+ * Lives in core/profile so both rendering layers (Typst PDF and HTML book)
8
+ * can call it without crossing the peer-module boundary defined in AGENTS.md.
9
+ *
10
+ * See docs/superpowers/specs/2026-05-06-profile-driven-entry-colors-design.md
11
+ * for the resolution table.
12
+ */
13
+ import type { EffectiveProfile, Entry } from "../model/mod.js";
14
+ import { type PaletteHue } from "../model/palette.js";
15
+ /**
16
+ * Resolve the palette hue for an entry under the active profile.
17
+ *
18
+ * Returns `null` for referenced-shape entries (uncolored block).
19
+ * Returns a palette hue name for identified entries — using the type's
20
+ * declared color when available, falling back to `"blue"` otherwise.
21
+ *
22
+ * The fallback is the palette hue directly (not the `primary` semantic
23
+ * name) so the renderer works for files compiled without a profile.
24
+ */
25
+ export declare function resolveEntryColor(entry: Entry, profile: EffectiveProfile | undefined): PaletteHue | null;
26
+ //# sourceMappingURL=colors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/profile/colors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKpE;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,UAAU,GAAG,IAAI,CAmBnB"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/profile/colors
4
+ *
5
+ * Profile-driven entry color resolution. Pure function that maps an entry
6
+ * and the active profile to a palette hue name (or `null` for uncolored).
7
+ *
8
+ * Lives in core/profile so both rendering layers (Typst PDF and HTML book)
9
+ * can call it without crossing the peer-module boundary defined in AGENTS.md.
10
+ *
11
+ * See docs/superpowers/specs/2026-05-06-profile-driven-entry-colors-design.md
12
+ * for the resolution table.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.resolveEntryColor = resolveEntryColor;
16
+ const palette_js_1 = require("../model/palette.js");
17
+ /** Default identified-entry hue when no profile / no type color resolves. */
18
+ const DEFAULT_HUE = "blue";
19
+ /**
20
+ * Resolve the palette hue for an entry under the active profile.
21
+ *
22
+ * Returns `null` for referenced-shape entries (uncolored block).
23
+ * Returns a palette hue name for identified entries — using the type's
24
+ * declared color when available, falling back to `"blue"` otherwise.
25
+ *
26
+ * The fallback is the palette hue directly (not the `primary` semantic
27
+ * name) so the renderer works for files compiled without a profile.
28
+ */
29
+ function resolveEntryColor(entry, profile) {
30
+ if (entry.shape === "referenced")
31
+ return null;
32
+ if (!profile || !entry.type)
33
+ return DEFAULT_HUE;
34
+ const typeDef = profile.types.get(entry.type);
35
+ const colorName = typeDef?.value.color.value;
36
+ if (!colorName)
37
+ return DEFAULT_HUE;
38
+ const hueEntry = profile.colors.get(colorName);
39
+ if (!hueEntry)
40
+ return DEFAULT_HUE;
41
+ // Defense in depth: the manifest parser already enforces PALETTE_HUES, but
42
+ // EffectiveProfile can in principle be constructed programmatically (tests,
43
+ // future APIs) without going through parseManifest. Guard the cast so an
44
+ // invalid hue can never reach downstream interpolation.
45
+ const hue = hueEntry.value;
46
+ if (!palette_js_1.PALETTE_HUES.includes(hue))
47
+ return DEFAULT_HUE;
48
+ return hue;
49
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @module core/profile/git-cache
3
+ *
4
+ * Cache + `git` CLI infrastructure for git-specifier resolution.
5
+ *
6
+ * The cache lives under `<project-root>/.markspec/cache/<sha>/` where `<sha>`
7
+ * is the sha256 of a canonical `(host, repo, subpath, tag)` tuple. Because
8
+ * the spec requires tag-only specifiers and tags are (by convention)
9
+ * immutable, cached content never needs refresh: either the cache directory
10
+ * exists and contains `markspec.yaml`, or we clone afresh.
11
+ */
12
+ /** Components of a git specifier that contribute to the cache key. */
13
+ export interface GitCacheKeyInput {
14
+ readonly repo: string;
15
+ readonly subpath: string | undefined;
16
+ readonly tag: string;
17
+ }
18
+ /**
19
+ * Stable sha256 hex digest of the canonical `(repo, subpath, tag)` tuple.
20
+ * Same inputs → same digest, always.
21
+ */
22
+ export declare function computeCacheKey(input: GitCacheKeyInput): Promise<string>;
23
+ /** Resolved paths for a cache-backed specifier. */
24
+ export interface CacheLocation {
25
+ /** sha256 hex key for the specifier. */
26
+ readonly key: string;
27
+ /** Absolute cache directory — where the clone lives (top-level repo). */
28
+ readonly dir: string;
29
+ /** Absolute path of the `markspec.yaml` the resolver needs to read. */
30
+ readonly manifestPath: string;
31
+ }
32
+ /**
33
+ * Compute the cache location for a git specifier relative to a project root.
34
+ */
35
+ export declare function computeCacheLocation(projectRoot: string, input: GitCacheKeyInput): Promise<CacheLocation>;
36
+ /** Result of running a git subcommand — captures exit code + output streams. */
37
+ export interface RunGitResult {
38
+ readonly code: number;
39
+ readonly stdout: string;
40
+ readonly stderr: string;
41
+ }
42
+ /**
43
+ * Inject this into the resolver to stub git invocations in unit tests.
44
+ * Production code uses {@linkcode defaultRunGit}.
45
+ */
46
+ export type RunGit = (args: readonly string[], cwd?: string) => Promise<RunGitResult>;
47
+ /**
48
+ * Default implementation backed by `Deno.Command("git", …)`. Captures stdout
49
+ * and stderr; never throws for nonzero exit — callers inspect `result.code`.
50
+ *
51
+ * Requires `--allow-run=git` at the Deno CLI level.
52
+ */
53
+ export declare const defaultRunGit: RunGit;
54
+ /** Injectable appender for {@linkcode ensureCacheGitignored}. */
55
+ export type AppendFile = (path: string, content: string) => Promise<void>;
56
+ /**
57
+ * Idempotently add `.markspec/cache/` to the project's `.gitignore` if that
58
+ * file exists. No-op when `.gitignore` is absent.
59
+ *
60
+ * Treats `.markspec/`, `.markspec/cache`, and `.markspec/cache/` as already
61
+ * ignored (broadest pattern wins).
62
+ *
63
+ * @param projectRoot - Absolute path containing the `.gitignore`
64
+ * @param readFile - Abstraction matching `core/config/mod.ts` `ReadFile`
65
+ * @param appendFile - Abstraction that appends a string to a file
66
+ */
67
+ export declare function ensureCacheGitignored(projectRoot: string, readFile: (path: string) => Promise<string | undefined>, appendFile: AppendFile): Promise<void>;
68
+ /**
69
+ * Default `AppendFile` backed by `Deno.writeTextFile` with `{ append: true }`.
70
+ * Requires `--allow-write`.
71
+ */
72
+ export declare const defaultAppendFile: AppendFile;
73
+ //# sourceMappingURL=git-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-cache.d.ts","sourceRoot":"","sources":["../../src/profile/git-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,CACnB,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,CAAC,EAAE,MAAM,KACT,OAAO,CAAC,YAAY,CAAC,CAAC;AAI3B;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,MAa3B,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,EACvD,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,UAE/B,CAAC"}