@driftsys/markspec 0.7.4 → 0.9.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 (57) hide show
  1. package/esm/config/mod.d.ts.map +1 -1
  2. package/esm/config/mod.js +25 -0
  3. package/esm/discovery/gitignore.d.ts +40 -0
  4. package/esm/discovery/gitignore.d.ts.map +1 -0
  5. package/esm/discovery/gitignore.js +145 -0
  6. package/esm/discovery/mod.d.ts +54 -0
  7. package/esm/discovery/mod.d.ts.map +1 -0
  8. package/esm/discovery/mod.js +122 -0
  9. package/esm/mod.d.ts +3 -1
  10. package/esm/mod.d.ts.map +1 -1
  11. package/esm/mod.js +3 -1
  12. package/esm/model/mod.d.ts +6 -0
  13. package/esm/model/mod.d.ts.map +1 -1
  14. package/esm/model/mod.js +1 -0
  15. package/esm/parser/markdown.d.ts.map +1 -1
  16. package/esm/parser/markdown.js +28 -15
  17. package/esm/refs/mod.d.ts.map +1 -1
  18. package/esm/refs/mod.js +48 -6
  19. package/esm/self_upgrade/pm_detect.d.ts +4 -4
  20. package/esm/self_upgrade/pm_detect.d.ts.map +1 -1
  21. package/esm/self_upgrade/pm_detect.js +12 -6
  22. package/esm/self_upgrade/target.d.ts +3 -3
  23. package/esm/self_upgrade/target.d.ts.map +1 -1
  24. package/esm/self_upgrade/target.js +4 -2
  25. package/esm/validator/listing.d.ts.map +1 -1
  26. package/esm/validator/listing.js +4 -1
  27. package/esm/validator/value_types.d.ts.map +1 -1
  28. package/esm/validator/value_types.js +6 -1
  29. package/package.json +1 -1
  30. package/script/config/mod.d.ts.map +1 -1
  31. package/script/config/mod.js +25 -0
  32. package/script/discovery/gitignore.d.ts +40 -0
  33. package/script/discovery/gitignore.d.ts.map +1 -0
  34. package/script/discovery/gitignore.js +149 -0
  35. package/script/discovery/mod.d.ts +54 -0
  36. package/script/discovery/mod.d.ts.map +1 -0
  37. package/script/discovery/mod.js +128 -0
  38. package/script/mod.d.ts +3 -1
  39. package/script/mod.d.ts.map +1 -1
  40. package/script/mod.js +10 -2
  41. package/script/model/mod.d.ts +6 -0
  42. package/script/model/mod.d.ts.map +1 -1
  43. package/script/model/mod.js +1 -0
  44. package/script/parser/markdown.d.ts.map +1 -1
  45. package/script/parser/markdown.js +27 -14
  46. package/script/refs/mod.d.ts.map +1 -1
  47. package/script/refs/mod.js +48 -6
  48. package/script/self_upgrade/pm_detect.d.ts +4 -4
  49. package/script/self_upgrade/pm_detect.d.ts.map +1 -1
  50. package/script/self_upgrade/pm_detect.js +12 -6
  51. package/script/self_upgrade/target.d.ts +3 -3
  52. package/script/self_upgrade/target.d.ts.map +1 -1
  53. package/script/self_upgrade/target.js +4 -2
  54. package/script/validator/listing.d.ts.map +1 -1
  55. package/script/validator/listing.js +4 -1
  56. package/script/validator/value_types.d.ts.map +1 -1
  57. package/script/validator/value_types.js +6 -1
package/esm/refs/mod.js CHANGED
@@ -43,6 +43,11 @@ export function buildRefIndex(entries) {
43
43
  }
44
44
  /** Trailer trace line: indent, key, `:` + spaces, value-rest. */
45
45
  const TRACE_TRAILER_RE = /^(\s{4,})([A-Z][A-Za-z-]*)(\s*:\s*)(.*)$/;
46
+ /**
47
+ * A `\`-continuation line of a multi-line trace value: leading indent then a
48
+ * non-empty value-rest (no `Key:` — that sat on the first physical line).
49
+ */
50
+ const CONTINUATION_LINE_RE = /^(\s+)(\S.*)$/;
46
51
  /** Token splitter that preserves separators between value tokens. */
47
52
  const VALUE_TOKEN_RE = /[^\s,]+/g;
48
53
  /**
@@ -91,18 +96,55 @@ export function canonicalizeRefs(content, entries, index, ledger) {
91
96
  const [, indent, key, sep, rest] = m;
92
97
  if (!TRACE_ATTRIBUTE_KEYS.has(key))
93
98
  continue;
94
- // Multi-line continuation — leave untouched (debt: full multi-line support).
95
- if (rest.endsWith("\\"))
96
- continue;
97
99
  const sourceUlid = sourceUlidForLine(i + 1);
98
- const rewritten = rest.replace(VALUE_TOKEN_RE, (token) => rewriteToken(token, sourceUlid, key, index, ledgerByKey));
99
- if (rewritten !== rest) {
100
- lines[i] = `${indent}${key}${sep}${rewritten}${cr ? "\r" : ""}`;
100
+ // Rewrite the key line's value, preserving any trailing `\` continuation
101
+ // marker (only resolvable tokens change — indentation, separators and the
102
+ // backslash stay byte-for-byte).
103
+ const newRest = rewriteValuePreservingContinuation(rest, sourceUlid, key, index, ledgerByKey);
104
+ if (newRest !== rest) {
105
+ lines[i] = `${indent}${key}${sep}${newRest}${cr ? "\r" : ""}`;
101
106
  changed = true;
102
107
  }
108
+ // Multi-line value: a `\`-continued value splits across physical lines,
109
+ // each non-final line ending in `\`. Walk the continuation lines (indent +
110
+ // value, no key) and rewrite each the same way, stopping at the first line
111
+ // that does not end in `\`. `i` is advanced past the consumed lines so the
112
+ // outer loop does not re-scan them (#606).
113
+ let continues = rest.endsWith("\\");
114
+ let j = i;
115
+ while (continues && j + 1 < lines.length) {
116
+ j++;
117
+ const crj = lines[j].endsWith("\r");
118
+ const barej = crj ? lines[j].slice(0, -1) : lines[j];
119
+ const cm = CONTINUATION_LINE_RE.exec(barej);
120
+ if (!cm) {
121
+ j--; // not a continuation line — leave it for the outer loop
122
+ break;
123
+ }
124
+ const [, cIndent, cVal] = cm;
125
+ const newVal = rewriteValuePreservingContinuation(cVal, sourceUlid, key, index, ledgerByKey);
126
+ if (newVal !== cVal) {
127
+ lines[j] = `${cIndent}${newVal}${crj ? "\r" : ""}`;
128
+ changed = true;
129
+ }
130
+ continues = cVal.endsWith("\\");
131
+ }
132
+ i = j;
103
133
  }
104
134
  return { output: lines.join("\n"), changed };
105
135
  }
136
+ /**
137
+ * Rewrite the value tokens of one trace-value line, preserving a trailing `\`
138
+ * continuation marker verbatim. The backslash is split off before token
139
+ * rewriting (so it is never mistaken for a value token) and re-appended after,
140
+ * keeping the multi-line continuation lossless.
141
+ */
142
+ function rewriteValuePreservingContinuation(value, sourceUlid, relation, index, ledgerByKey) {
143
+ const hasBackslash = value.endsWith("\\");
144
+ const core = hasBackslash ? value.slice(0, -1) : value;
145
+ const rewritten = core.replace(VALUE_TOKEN_RE, (token) => rewriteToken(token, sourceUlid, relation, index, ledgerByKey));
146
+ return hasBackslash ? `${rewritten}\\` : rewritten;
147
+ }
106
148
  function rewriteToken(token, sourceUlid, relation, index, ledgerByKey) {
107
149
  if (ULID_RE.test(token)) {
108
150
  // Rule 1: ULID → current display ID (canonicalise).
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @module core/self_upgrade/pm_detect
3
3
  *
4
- * Classify the realpath of the running binary into one of four
4
+ * Classify the realpath of the running binary into one of five
5
5
  * install-source buckets so the self-upgrade orchestrator can refuse
6
6
  * with a per-manager hint instead of fighting the package manager.
7
7
  *
8
8
  * The check is heuristic and order-sensitive — Homebrew first (because
9
9
  * brew's bin paths live under /opt/homebrew or /usr/local), npm second,
10
- * system third, user-local fourth. Anything that falls through is
11
- * "unknown" and the orchestrator proceeds with a warning.
10
+ * cargo third, user-local fourth, system fifth. Anything that falls
11
+ * through is "unknown" and the orchestrator proceeds with a warning.
12
12
  *
13
13
  * Path matching is whole-segment (path separator on both sides) to
14
14
  * avoid matching e.g. `/foo/.localfish/markspec` against the user-local
@@ -18,7 +18,7 @@
18
18
  * brew's `/opt/homebrew/bin/markspec` -> `/opt/homebrew/Cellar/.../bin/markspec`
19
19
  * is classified correctly.
20
20
  */
21
- export type InstallSource = "user-local" | "homebrew" | "npm" | "system" | "unknown";
21
+ export type InstallSource = "user-local" | "homebrew" | "npm" | "cargo" | "system" | "unknown";
22
22
  export interface ClassifyResult {
23
23
  readonly source: InstallSource;
24
24
  readonly hintCommand?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"pm_detect.d.ts","sourceRoot":"","sources":["../../src/self_upgrade/pm_detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,UAAU,GACV,KAAK,GACL,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,cAAc,CA+ChB"}
1
+ {"version":3,"file":"pm_detect.d.ts","sourceRoot":"","sources":["../../src/self_upgrade/pm_detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,UAAU,GACV,KAAK,GACL,OAAO,GACP,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,cAAc,CAsDhB"}
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @module core/self_upgrade/pm_detect
3
3
  *
4
- * Classify the realpath of the running binary into one of four
4
+ * Classify the realpath of the running binary into one of five
5
5
  * install-source buckets so the self-upgrade orchestrator can refuse
6
6
  * with a per-manager hint instead of fighting the package manager.
7
7
  *
8
8
  * The check is heuristic and order-sensitive — Homebrew first (because
9
9
  * brew's bin paths live under /opt/homebrew or /usr/local), npm second,
10
- * system third, user-local fourth. Anything that falls through is
11
- * "unknown" and the orchestrator proceeds with a warning.
10
+ * cargo third, user-local fourth, system fifth. Anything that falls
11
+ * through is "unknown" and the orchestrator proceeds with a warning.
12
12
  *
13
13
  * Path matching is whole-segment (path separator on both sides) to
14
14
  * avoid matching e.g. `/foo/.localfish/markspec` against the user-local
@@ -35,17 +35,23 @@ export function classifyInstallPath(realPath, home) {
35
35
  p.includes("/.npm/")) {
36
36
  return { source: "npm", hintCommand: "npm update -g markspec" };
37
37
  }
38
- // 3. user-local paths under $HOME.
38
+ // 3. Cargo (`~/.cargo/bin`). A package-manager location like Homebrew/npm,
39
+ // so it is refused rather than overwritten — self-upgrade's rename-swap
40
+ // would leave cargo's own metadata stale (#575). Checked before the
41
+ // user-local rule, which would otherwise claim `.cargo/bin/`.
42
+ if (h && p.startsWith(`${h}/.cargo/bin/`)) {
43
+ return { source: "cargo", hintCommand: "cargo install markspec --force" };
44
+ }
45
+ // 4. user-local paths under $HOME.
39
46
  if (h && p.startsWith(`${h}/`)) {
40
47
  const tail = p.slice(h.length + 1);
41
48
  if (tail.startsWith(".local/") ||
42
- tail.startsWith(".cargo/bin/") ||
43
49
  tail.startsWith("bin/") ||
44
50
  tail.startsWith("Library/")) {
45
51
  return { source: "user-local" };
46
52
  }
47
53
  }
48
- // 4. system bins.
54
+ // 5. system bins.
49
55
  if (p.startsWith("/usr/") ||
50
56
  p.startsWith("/opt/") ||
51
57
  p.startsWith("/snap/")) {
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Map (os, arch) → the GitHub release target string used in tarball
5
5
  * names. Targets match those produced by the Release workflow:
6
- * x86_64-unknown-linux-gnu, x86_64-apple-darwin,
7
- * aarch64-apple-darwin, x86_64-pc-windows-msvc.
6
+ * x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu,
7
+ * x86_64-apple-darwin, aarch64-apple-darwin, x86_64-pc-windows-msvc.
8
8
  *
9
9
  * Pure functions — no I/O, no Deno.* APIs. The CLI passes
10
10
  * `Deno.build.os` / `Deno.build.arch` strings to platformFromBuild;
@@ -17,7 +17,7 @@ export interface Platform {
17
17
  readonly os: Os;
18
18
  readonly arch: Arch;
19
19
  }
20
- export type Target = "x86_64-unknown-linux-gnu" | "x86_64-apple-darwin" | "aarch64-apple-darwin" | "x86_64-pc-windows-msvc";
20
+ export type Target = "x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" | "x86_64-apple-darwin" | "aarch64-apple-darwin" | "x86_64-pc-windows-msvc";
21
21
  /** Return the release target for a platform, or undefined if not shipped. */
22
22
  export declare function detectTarget(platform: Platform): Target | undefined;
23
23
  /** Parse Deno.build.{os,arch} strings into a typed Platform, or undefined. */
@@ -1 +1 @@
1
- {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/self_upgrade/target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,EAAE,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAChD,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED,MAAM,MAAM,MAAM,GACd,0BAA0B,GAC1B,qBAAqB,GACrB,sBAAsB,GACtB,wBAAwB,CAAC;AAE7B,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAOnE;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,QAAQ,GAAG,SAAS,CAKtB"}
1
+ {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/self_upgrade/target.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,MAAM,EAAE,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAChD,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExC,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED,MAAM,MAAM,MAAM,GACd,0BAA0B,GAC1B,2BAA2B,GAC3B,qBAAqB,GACrB,sBAAsB,GACtB,wBAAwB,CAAC;AAE7B,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAQnE;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GACX,QAAQ,GAAG,SAAS,CAKtB"}
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * Map (os, arch) → the GitHub release target string used in tarball
5
5
  * names. Targets match those produced by the Release workflow:
6
- * x86_64-unknown-linux-gnu, x86_64-apple-darwin,
7
- * aarch64-apple-darwin, x86_64-pc-windows-msvc.
6
+ * x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu,
7
+ * x86_64-apple-darwin, aarch64-apple-darwin, x86_64-pc-windows-msvc.
8
8
  *
9
9
  * Pure functions — no I/O, no Deno.* APIs. The CLI passes
10
10
  * `Deno.build.os` / `Deno.build.arch` strings to platformFromBuild;
@@ -16,6 +16,8 @@ export function detectTarget(platform) {
16
16
  const { os, arch } = platform;
17
17
  if (os === "linux" && arch === "x86_64")
18
18
  return "x86_64-unknown-linux-gnu";
19
+ if (os === "linux" && arch === "aarch64")
20
+ return "aarch64-unknown-linux-gnu";
19
21
  if (os === "darwin" && arch === "x86_64")
20
22
  return "x86_64-apple-darwin";
21
23
  if (os === "darwin" && arch === "aarch64")
@@ -1 +1 @@
1
- {"version":3,"file":"listing.d.ts","sourceRoot":"","sources":["../../src/validator/listing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYpE,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,CAAC;AAEnE,uEAAuE;AACvE,MAAM,WAAW,kBAAkB;IACjC,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAC3C;AA4SD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,SAAS,UAAU,EAAE,CAMvB"}
1
+ {"version":3,"file":"listing.d.ts","sourceRoot":"","sources":["../../src/validator/listing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYpE,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,CAAC;AAEnE,uEAAuE;AACvE,MAAM,WAAW,kBAAkB;IACjC,mEAAmE;IACnE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;CAC3C;AA8SD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,SAAS,UAAU,EAAE,CAMvB"}
@@ -42,7 +42,10 @@ const UNIT_FAMILY = new Set([
42
42
  // ---------------------------------------------------------------------------
43
43
  /** Listing kind implied by a file's basename, or null if not a listing file. */
44
44
  function filenameKind(file) {
45
- const base = basename(file).toLowerCase().replace(/\.[^.]+$/, "");
45
+ const name = basename(file).toLowerCase();
46
+ if (!name.endsWith(".md"))
47
+ return null;
48
+ const base = name.replace(/\.md$/, "");
46
49
  if (base === "references")
47
50
  return "references";
48
51
  if (base === "glossary")
@@ -1 +1 @@
1
- {"version":3,"file":"value_types.d.ts","sourceRoot":"","sources":["../../src/validator/value_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAG3D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAG1E;AAED,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,MAAM,GAAG,IAAI,CAAC;AA+C9E;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAiB,CAAC"}
1
+ {"version":3,"file":"value_types.d.ts","sourceRoot":"","sources":["../../src/validator/value_types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AAG3D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAG1E;AAED,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,MAAM,GAAG,IAAI,CAAC;AAsD9E;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAiB,CAAC"}
@@ -45,7 +45,12 @@ const validateEnum = (value, decl) => {
45
45
  const values = decl.values ?? [];
46
46
  if (values.includes(value))
47
47
  return null;
48
- return `value '${value}' is not in declared enum [${values.join(", ")}]`;
48
+ const base = `value '${value}' is not in declared enum [${values.join(", ")}]`;
49
+ // Case-only mismatch: the author most likely title/upper-cased a valid
50
+ // member (e.g. `Approved` → `approved`). Suggest the declared spelling
51
+ // (#215). A genuine unknown value falls through with no hint.
52
+ const match = values.find((v) => v.toLowerCase() === value.toLowerCase());
53
+ return match !== undefined ? `${base}; did you mean '${match}'?` : base;
49
54
  };
50
55
  // ---------------------------------------------------------------------------
51
56
  // Individual validators (Task 6.4 ID/URI types)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.7.4",
3
+ "version": "0.9.0",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/config/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,yFAAyF;AACzF,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAMrE;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU7B;AAsBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,aAAa,CAqMf;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAMD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/config/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AAEzB,4DAA4D;AAC5D,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,iDAAiD;AACjD,MAAM,WAAW,gBAAgB;IAC/B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,mDAAmD;IACnD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,yFAAyF;AACzF,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAMrE;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU7B;AAsBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,aAAa,CA+Nf;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAMD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAUvC"}
@@ -232,6 +232,30 @@ function parseProjectConfig(yaml, filePath) {
232
232
  }
233
233
  }
234
234
  }
235
+ // exclude: optional string[] of gitignore-syntax patterns
236
+ let exclude = mod_js_1.DEFAULT_PROJECT_CONFIG.exclude;
237
+ if (obj.exclude !== undefined && obj.exclude !== null) {
238
+ if (!Array.isArray(obj.exclude)) {
239
+ errors.push({
240
+ field: "exclude",
241
+ message: `expected array, got ${typeof obj.exclude}`,
242
+ line: findLineNumber(yaml, "exclude"),
243
+ });
244
+ }
245
+ else {
246
+ const bad = obj.exclude.findIndex((v) => typeof v !== "string" || v === "");
247
+ if (bad !== -1) {
248
+ errors.push({
249
+ field: `exclude[${bad}]`,
250
+ message: "each exclude pattern must be a non-empty string",
251
+ line: findLineNumber(yaml, "exclude"),
252
+ });
253
+ }
254
+ else {
255
+ exclude = obj.exclude;
256
+ }
257
+ }
258
+ }
235
259
  if (errors.length > 0) {
236
260
  throw new mod_js_1.ConfigError(filePath, errors);
237
261
  }
@@ -242,6 +266,7 @@ function parseProjectConfig(yaml, filePath) {
242
266
  parents,
243
267
  parentFallback,
244
268
  captionConventions,
269
+ exclude,
245
270
  };
246
271
  }
247
272
  // ---------------------------------------------------------------------------
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @module core/discovery/gitignore
3
+ *
4
+ * Pure-TypeScript `.gitignore` pattern matcher. Implements the standard
5
+ * semantics the discovery walker needs: `#` comments, `!` negation,
6
+ * trailing-`/` directory-only patterns, leading-`/` and contains-`/`
7
+ * anchoring, `*` / `?` / `[...]` globs, and `**` cross-directory globs.
8
+ * Last matching rule wins.
9
+ *
10
+ * Per git semantics, a file inside an ignored directory cannot be
11
+ * re-included by a negation — the walker enforces this by pruning
12
+ * ignored directories without descending.
13
+ *
14
+ * No I/O, no platform APIs — Node-compatible by construction.
15
+ */
16
+ /** One compiled gitignore rule. */
17
+ export interface GitignoreRule {
18
+ /** Matches a root-relative POSIX path (no leading slash). */
19
+ readonly regex: RegExp;
20
+ /** `!pattern` — a match un-ignores the path. */
21
+ readonly negated: boolean;
22
+ /** `pattern/` — matches directories only. */
23
+ readonly dirOnly: boolean;
24
+ }
25
+ /**
26
+ * Parse `.gitignore` content into compiled rules.
27
+ *
28
+ * @param content - Raw file content (LF or CRLF).
29
+ * @param baseDir - Root-relative POSIX dir the `.gitignore` lives in
30
+ * (`""` for the root one). Patterns only match paths under it.
31
+ */
32
+ export declare function parseGitignore(content: string, baseDir: string): GitignoreRule[];
33
+ /**
34
+ * Test a root-relative POSIX path against compiled rules.
35
+ * Last matching rule wins; no match → not ignored.
36
+ *
37
+ * @param isDir - Directory-only rules (`build/`) match only when true.
38
+ */
39
+ export declare function isIgnored(relPath: string, isDir: boolean, rules: readonly GitignoreRule[]): boolean;
40
+ //# sourceMappingURL=gitignore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitignore.d.ts","sourceRoot":"","sources":["../../src/discovery/gitignore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,mCAAmC;AACnC,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA0DD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,aAAa,EAAE,CAyCjB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,SAAS,aAAa,EAAE,GAC9B,OAAO,CAOT"}
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * @module core/discovery/gitignore
4
+ *
5
+ * Pure-TypeScript `.gitignore` pattern matcher. Implements the standard
6
+ * semantics the discovery walker needs: `#` comments, `!` negation,
7
+ * trailing-`/` directory-only patterns, leading-`/` and contains-`/`
8
+ * anchoring, `*` / `?` / `[...]` globs, and `**` cross-directory globs.
9
+ * Last matching rule wins.
10
+ *
11
+ * Per git semantics, a file inside an ignored directory cannot be
12
+ * re-included by a negation — the walker enforces this by pruning
13
+ * ignored directories without descending.
14
+ *
15
+ * No I/O, no platform APIs — Node-compatible by construction.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.parseGitignore = parseGitignore;
19
+ exports.isIgnored = isIgnored;
20
+ const REGEX_SPECIALS = /[.+^${}()|\\]/;
21
+ function escapeRegexChar(c) {
22
+ return REGEX_SPECIALS.test(c) ? `\\${c}` : c;
23
+ }
24
+ /** Translate one gitignore glob (already stripped of `!`, `/` affixes)
25
+ * into a regex source string. */
26
+ function globToRegexSource(pattern) {
27
+ let re = "";
28
+ let i = 0;
29
+ while (i < pattern.length) {
30
+ const c = pattern[i];
31
+ if (c === "*") {
32
+ // Consume the whole run of consecutive `*` so we never emit adjacent
33
+ // unbounded quantifiers (which backtrack catastrophically against a
34
+ // non-matching input). Git likewise treats consecutive `*` that are
35
+ // not a slash-delimited `**` as regular asterisks.
36
+ let stars = 0;
37
+ while (pattern[i] === "*") {
38
+ stars++;
39
+ i++;
40
+ }
41
+ if (stars >= 2 && pattern[i] === "/") {
42
+ re += "(?:[^/]+/)*"; // `**/` — zero or more whole segments
43
+ i++; // consume the `/`
44
+ }
45
+ else if (stars >= 2) {
46
+ re += ".*"; // leading/trailing/bare `**` — crosses directories
47
+ }
48
+ else {
49
+ re += "[^/]*"; // single `*` — within one path segment
50
+ }
51
+ }
52
+ else if (c === "?") {
53
+ re += "[^/]";
54
+ i++;
55
+ }
56
+ else if (c === "[") {
57
+ const end = pattern.indexOf("]", i + 1);
58
+ if (end < 0) {
59
+ re += "\\[";
60
+ i++;
61
+ }
62
+ else {
63
+ let cls = pattern.slice(i + 1, end);
64
+ if (cls.startsWith("!"))
65
+ cls = `^${cls.slice(1)}`;
66
+ re += `[${cls}]`;
67
+ i = end + 1;
68
+ }
69
+ }
70
+ else if (c === "\\" && i + 1 < pattern.length) {
71
+ re += escapeRegexChar(pattern[i + 1]);
72
+ i += 2;
73
+ }
74
+ else {
75
+ re += escapeRegexChar(c);
76
+ i++;
77
+ }
78
+ }
79
+ return re;
80
+ }
81
+ /**
82
+ * Parse `.gitignore` content into compiled rules.
83
+ *
84
+ * @param content - Raw file content (LF or CRLF).
85
+ * @param baseDir - Root-relative POSIX dir the `.gitignore` lives in
86
+ * (`""` for the root one). Patterns only match paths under it.
87
+ */
88
+ function parseGitignore(content, baseDir) {
89
+ const rules = [];
90
+ for (const rawLine of content.split("\n")) {
91
+ // Strip CR and unescaped trailing spaces (git semantics).
92
+ const line = rawLine.replace(/\r$/, "").replace(/(?<!\\) +$/, "");
93
+ if (line === "" || line.startsWith("#"))
94
+ continue;
95
+ let pattern = line;
96
+ let negated = false;
97
+ if (pattern.startsWith("!")) {
98
+ negated = true;
99
+ pattern = pattern.slice(1);
100
+ }
101
+ let dirOnly = false;
102
+ if (pattern.endsWith("/")) {
103
+ dirOnly = true;
104
+ pattern = pattern.slice(0, -1);
105
+ }
106
+ // A separator anywhere in the pattern anchors it to baseDir;
107
+ // otherwise it matches at any depth below baseDir.
108
+ const anchored = pattern.includes("/");
109
+ if (pattern.startsWith("/"))
110
+ pattern = pattern.slice(1);
111
+ if (pattern === "")
112
+ continue;
113
+ // baseDir is a literal directory prefix, so every regex metacharacter
114
+ // in it must be escaped — including `* ? [ ]`, which the pattern-body
115
+ // helpers (escapeRegexChar / globToRegexSource) deliberately leave
116
+ // unescaped so they can act as globs. A dir literally named `pkg[v2]`
117
+ // would otherwise inject a stray character class.
118
+ const prefix = baseDir === ""
119
+ ? ""
120
+ : `${baseDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/`;
121
+ const depth = anchored ? "" : "(?:.*/)?";
122
+ let regex;
123
+ try {
124
+ regex = new RegExp(`^${prefix}${depth}${globToRegexSource(pattern)}$`);
125
+ }
126
+ catch {
127
+ continue; // skip a line that compiles to an invalid regex (e.g. a
128
+ // malformed character class) rather than crashing discovery
129
+ }
130
+ rules.push({ regex, negated, dirOnly });
131
+ }
132
+ return rules;
133
+ }
134
+ /**
135
+ * Test a root-relative POSIX path against compiled rules.
136
+ * Last matching rule wins; no match → not ignored.
137
+ *
138
+ * @param isDir - Directory-only rules (`build/`) match only when true.
139
+ */
140
+ function isIgnored(relPath, isDir, rules) {
141
+ let ignored = false;
142
+ for (const rule of rules) {
143
+ if (rule.dirOnly && !isDir)
144
+ continue;
145
+ if (rule.regex.test(relPath))
146
+ ignored = !rule.negated;
147
+ }
148
+ return ignored;
149
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @module core/discovery
3
+ *
4
+ * Gitignore-aware project file discovery — the single walker every
5
+ * MarkSpec surface uses (CLI verbs, LSP indexing, lockfile entry
6
+ * collection). Yields absolute paths of MarkSpec-relevant files under a
7
+ * root, honoring (in precedence order):
8
+ *
9
+ * 1. built-in skips — hidden directories (name starts with `.`)
10
+ * 2. `.gitignore` files (root + nested, standard semantics)
11
+ * 3. caller-supplied `exclude` patterns (gitignore syntax, root-anchored)
12
+ *
13
+ * I/O is injected via {@linkcode DiscoveryIO} so the module stays
14
+ * Node-compatible; entry points supply the Deno implementation.
15
+ */
16
+ export { type GitignoreRule, isIgnored, parseGitignore } from "./gitignore.js";
17
+ /**
18
+ * Source-file extensions the parser can extract doc-comment entries
19
+ * from (tree-sitter grammars available). Single SSOT — `lsp/context.ts`
20
+ * imports this set.
21
+ */
22
+ export declare const SOURCE_EXTENSIONS: ReadonlySet<string>;
23
+ /** Markdown only — the `fmt` scope (the formatter never rewrites source). */
24
+ export declare const MARKDOWN_EXTENSIONS: ReadonlySet<string>;
25
+ /** Everything MarkSpec-relevant: markdown + source families. */
26
+ export declare const RELEVANT_EXTENSIONS: ReadonlySet<string>;
27
+ /** One directory entry from {@linkcode DiscoveryIO.readDir}.
28
+ * Structurally compatible with `Deno.DirEntry`. */
29
+ export interface DiscoveryDirEntry {
30
+ readonly name: string;
31
+ readonly isDirectory: boolean;
32
+ readonly isFile: boolean;
33
+ }
34
+ /** Injected filesystem surface for the walker. */
35
+ export interface DiscoveryIO {
36
+ readDir(path: string): AsyncIterable<DiscoveryDirEntry>;
37
+ /** Resolves `undefined` when the file does not exist or is unreadable. */
38
+ readFile(path: string): Promise<string | undefined>;
39
+ }
40
+ /** Options for {@linkcode discoverFiles}. */
41
+ export interface DiscoverOptions {
42
+ /** Extension filter; defaults to {@linkcode RELEVANT_EXTENSIONS}. */
43
+ readonly extensions?: ReadonlySet<string>;
44
+ /** Extra gitignore-syntax patterns, anchored at `root` (e.g. from
45
+ * project.yaml `exclude:`). Applied after `.gitignore` rules. */
46
+ readonly exclude?: readonly string[];
47
+ }
48
+ /**
49
+ * Walk `root` recursively, yielding absolute paths of relevant files.
50
+ * Entries are yielded in sorted order per directory — deterministic
51
+ * output across filesystems. Unreadable directories are skipped.
52
+ */
53
+ export declare function discoverFiles(root: string, io: DiscoveryIO, options?: DiscoverOptions): AsyncGenerator<string>;
54
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/discovery/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE/E;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAmBhD,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAAoB,CAAC;AAEzE,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,EAAE,WAAW,CAAC,MAAM,CAGlD,CAAC;AAEH;mDACmD;AACnD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,kDAAkD;AAClD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACxD,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACrD;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C;qEACiE;IACjE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AA8BD;;;;GAIG;AACH,wBAAuB,aAAa,CAClC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,OAAO,GAAE,eAAoB,GAC5B,cAAc,CAAC,MAAM,CAAC,CAgBxB"}