@descent-vtt/spec-brief 0.2.7 → 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 (51) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/README.md +162 -29
  3. package/dist/cli.d.ts +1 -1
  4. package/dist/cli.js +61 -43
  5. package/dist/cli.js.map +1 -1
  6. package/dist/collisions.js +13 -8
  7. package/dist/collisions.js.map +1 -1
  8. package/dist/config.js +2 -1
  9. package/dist/config.js.map +1 -1
  10. package/dist/corpus.d.ts +5 -0
  11. package/dist/corpus.js +7 -0
  12. package/dist/corpus.js.map +1 -1
  13. package/dist/glob.d.ts +6 -5
  14. package/dist/glob.js +22 -103
  15. package/dist/glob.js.map +1 -1
  16. package/dist/lint.js +1 -0
  17. package/dist/lint.js.map +1 -1
  18. package/dist/report.d.ts +18 -4
  19. package/dist/report.js +98 -28
  20. package/dist/report.js.map +1 -1
  21. package/dist/rules.d.ts +2 -0
  22. package/dist/rules.js +21 -8
  23. package/dist/rules.js.map +1 -1
  24. package/dist/schedule.js +12 -10
  25. package/dist/schedule.js.map +1 -1
  26. package/dist/schema.d.ts +5 -1
  27. package/dist/schema.js +6 -2
  28. package/dist/schema.js.map +1 -1
  29. package/dist/scope.d.ts +26 -4
  30. package/dist/scope.js +64 -8
  31. package/dist/scope.js.map +1 -1
  32. package/dist/trigger.js +59 -3
  33. package/dist/trigger.js.map +1 -1
  34. package/dist/types.d.ts +9 -0
  35. package/dist/types.js.map +1 -1
  36. package/dist/vendor/spec-core/markdown/frontmatter.d.ts +11 -1
  37. package/dist/vendor/spec-core/markdown/frontmatter.js +20 -3
  38. package/dist/vendor/spec-core/markdown/frontmatter.js.map +1 -1
  39. package/dist/vendor/spec-core/pattern/glob.d.ts +85 -0
  40. package/dist/vendor/spec-core/pattern/glob.js +207 -17
  41. package/dist/vendor/spec-core/pattern/glob.js.map +1 -1
  42. package/dist/vendor/spec-core/pattern/index.d.ts +2 -2
  43. package/dist/vendor/spec-core/pattern/index.js +1 -1
  44. package/dist/vendor/spec-core/pattern/index.js.map +1 -1
  45. package/dist/vendor/spec-core/text/index.d.ts +1 -0
  46. package/dist/vendor/spec-core/text/index.js +1 -0
  47. package/dist/vendor/spec-core/text/index.js.map +1 -1
  48. package/dist/vendor/spec-core/text/width.d.ts +30 -0
  49. package/dist/vendor/spec-core/text/width.js +113 -0
  50. package/dist/vendor/spec-core/text/width.js.map +1 -0
  51. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"corpus.js","sourceRoot":"","sources":["../src/corpus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiB3C,MAAM,UAAU,WAAW,CAAC,KAA4B,EAAE,MAAc;IACtE,6CAA6C;IAC7C,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO;QACL,MAAM;QACN,MAAM;QACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC;QAC9C,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,UAAU,CAAC;KACvD,CAAC;AACJ,CAAC;AAED;;;;GA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tH,OAAO,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IACD,kFAAkF;IAClF,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/**\n * Every brief of a repository at once, and the dependency graph between them.\n */\n\nimport { parseBrief, type Brief } from './brief.js';\nimport type { Config } from './config.js';\nimport { normalisePath } from './links.js';\nimport type { Phase } from './types.js';\n\nexport interface SourceFile {\n readonly path: string;\n readonly text: string;\n readonly phase: Phase;\n}\n\nexport interface Corpus {\n readonly config: Config;\n /** Sorted by path. */\n readonly briefs: readonly Brief[];\n readonly live: readonly Brief[];\n readonly archived: readonly Brief[];\n}\n\nexport function buildCorpus(files: readonly SourceFile[], config: Config): Corpus {\n // Paths are unique, so no two compare equal.\n const briefs = [...files]\n .sort((a, b) => (a.path < b.path ? -1 : 1))\n .map((file) => parseBrief(file.path, file.text, config, file.phase));\n return {\n config,\n briefs,\n live: briefs.filter((b) => b.phase === 'live'),\n archived: briefs.filter((b) => b.phase === 'archived'),\n };\n}\n\n/**\n * The form in which ids are compared. Numeric ids compare by value, so a\n * dependency written `34` - which YAML would read as a number anyway - names\n * brief `034`.\n */\nexport function idKey(id: string): string {\n return /^\\d+$/.test(id) ? String(Number(id)) : id;\n}\n\n/** Briefs an id, a file name or a path names. More than one is an ambiguity the caller reports. */\nexport function findBriefs(corpus: Corpus, reference: string): Brief[] {\n const key = idKey(reference.trim());\n const byId = corpus.briefs.filter((b) => b.id !== null && idKey(b.id) === key);\n if (byId.length > 0) return byId;\n let path: string;\n try {\n path = normalisePath(reference);\n } catch {\n return [];\n }\n return corpus.briefs.filter((b) => b.file === path || b.name === path);\n}\n\n/** The brief a dependency names, preferring a live one when an id is ambiguous. */\nexport function resolveDependency(corpus: Corpus, id: string): Brief | undefined {\n const found = findBriefs(corpus, id);\n return found.find((b) => b.phase === 'live') ?? found[0];\n}\n\n/** Briefs grouped by id, for the ids more than one file claims. */\nexport function duplicateIds(corpus: Corpus): Map<string, Brief[]> {\n const groups = new Map<string, Brief[]>();\n for (const brief of corpus.briefs) {\n if (brief.id === null) continue;\n const key = idKey(brief.id);\n groups.set(key, [...(groups.get(key) ?? []), brief]);\n }\n return new Map([...groups].filter(([, members]) => members.length > 1));\n}\n\n/** The live dependencies of a brief that are not archived yet. */\nexport function pendingDependencies(corpus: Corpus, brief: Brief): string[] {\n return brief.dependsOn.filter((dependency) => {\n const target = resolveDependency(corpus, dependency);\n return target !== undefined && target.phase === 'live';\n });\n}\n\n/**\n * A live brief whose every dependency is archived can be executed now, unless\n * it is still being written or is deferred until its trigger.\n */\nexport function isReady(corpus: Corpus, brief: Brief): boolean {\n if (brief.phase !== 'live' || brief.status === 'draft' || brief.status === 'deferred') return false;\n return brief.dependsOn.every((dependency) => resolveDependency(corpus, dependency)?.phase === 'archived');\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\n/** Briefs by id, numbers by value; by path where two ids agree. */\nexport function byId(a: Brief, b: Brief): number {\n const x = label(a);\n const y = label(b);\n const numeric = /^\\d+$/.test(x) && /^\\d+$/.test(y);\n if (numeric && Number(x) !== Number(y)) return Number(x) - Number(y);\n if (x < y) return -1;\n if (x > y) return 1;\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;\n}\n\n/** The live briefs a brief depends on, by id. Archived ones are done, and unknown ones are the dependency rule's. */\nexport function liveDependencies(corpus: Corpus, brief: Brief): Brief[] {\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n return [...new Set(targets)].sort(byId);\n}\n\n/** A live brief that cannot start before deferred work, and the dependency it waits through. */\nexport interface Waiting {\n readonly brief: Brief;\n /** The deferred brief it depends on, or the brief through which it waits on one; the first by id. */\n readonly waitsOn: Brief;\n}\n\n/**\n * Live briefs that wait on deferred work: each depends on a deferred brief,\n * or on a brief that waits on one. Neither can start before an event nobody\n * has scheduled, so neither runs in a wave (ADR-0011): `schedule` places them\n * nowhere and `matrix` compares them with nothing. By id.\n */\nexport function waitingOnDeferred(corpus: Corpus): Waiting[] {\n const candidates = corpus.live.filter((b) => b.status !== 'deferred');\n const dependencies = new Map(candidates.map((b) => [b, liveDependencies(corpus, b)]));\n const held = new Set<Brief>();\n const holds = (d: Brief): boolean => d.status === 'deferred' || held.has(d);\n // Each pass holds another brief or is the last, so there is at most one pass more than there are briefs.\n for (let grew = true; grew; ) {\n grew = false;\n for (const brief of candidates) {\n if (held.has(brief) || !(dependencies.get(brief) as Brief[]).some(holds)) continue;\n held.add(brief);\n grew = true;\n }\n }\n return [...held].sort(byId).map((brief) => ({ brief, waitsOn: (dependencies.get(brief) as Brief[]).find(holds) as Brief }));\n}\n\n/**\n * Dependency cycles among live briefs, each as the ids along it with the first\n * repeated at the end. Found with Tarjan's algorithm; each strongly connected\n * component is reported once, starting from its first brief by path.\n */\nexport function dependencyCycles(corpus: Corpus): Brief[][] {\n const nodes = corpus.live;\n const edges = new Map<Brief, Brief[]>();\n for (const brief of nodes) {\n // A brief that depends on itself is the dependency rule's finding; left\n // in, the edge would be the shortest way round any cycle it is part of.\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n edges.set(brief, targets);\n }\n\n const index = new Map<Brief, number>();\n const low = new Map<Brief, number>();\n const stack: Brief[] = [];\n const onStack = new Set<Brief>();\n const components: Brief[][] = [];\n let counter = 0;\n\n // Recursion depth is bounded by the number of live briefs.\n const connect = (v: Brief): void => {\n index.set(v, counter);\n low.set(v, counter);\n counter += 1;\n stack.push(v);\n onStack.add(v);\n for (const w of edges.get(v) ?? []) {\n if (!index.has(w)) {\n connect(w);\n low.set(v, Math.min(low.get(v) as number, low.get(w) as number));\n } else if (onStack.has(w)) {\n low.set(v, Math.min(low.get(v) as number, index.get(w) as number));\n }\n }\n if (low.get(v) === index.get(v)) {\n const component: Brief[] = [];\n for (;;) {\n const w = stack.pop() as Brief;\n onStack.delete(w);\n component.push(w);\n if (w === v) break;\n }\n if (component.length > 1) components.push(component);\n }\n };\n for (const brief of nodes) if (!index.has(brief)) connect(brief);\n\n return components.map((component) => {\n const members = new Set(component);\n const start = [...component].sort((a, b) => (a.file < b.file ? -1 : 1))[0] as Brief;\n return cyclePath(start, members, edges);\n });\n}\n\n/** A path from `start` back to itself inside one component, found breadth-first. */\nfunction cyclePath(start: Brief, members: ReadonlySet<Brief>, edges: ReadonlyMap<Brief, Brief[]>): Brief[] {\n const previous = new Map<Brief, Brief>();\n const queue: Brief[] = [start];\n for (let head = 0; head < queue.length; head += 1) {\n const node = queue[head] as Brief;\n for (const next of edges.get(node) ?? []) {\n if (!members.has(next)) continue;\n if (next === start) {\n const path: Brief[] = [start];\n for (let at: Brief | undefined = node; at !== undefined && at !== start; at = previous.get(at)) path.splice(1, 0, at);\n return [...path, start];\n }\n if (!previous.has(next)) {\n previous.set(next, node);\n queue.push(next);\n }\n }\n }\n /* v8 ignore next -- a component of two or more always leads back to its start. */\n return [start, start];\n}\n"]}
1
+ {"version":3,"file":"corpus.js","sourceRoot":"","sources":["../src/corpus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAiB3C,MAAM,UAAU,WAAW,CAAC,KAA4B,EAAE,MAAc;IACtE,6CAA6C;IAC7C,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAA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nimport { parseBrief, type Brief } from './brief.js';\nimport type { Config } from './config.js';\nimport { normalisePath } from './links.js';\nimport type { Phase } from './types.js';\n\nexport interface SourceFile {\n readonly path: string;\n readonly text: string;\n readonly phase: Phase;\n}\n\nexport interface Corpus {\n readonly config: Config;\n /** Sorted by path. */\n readonly briefs: readonly Brief[];\n readonly live: readonly Brief[];\n readonly archived: readonly Brief[];\n}\n\nexport function buildCorpus(files: readonly SourceFile[], config: Config): Corpus {\n // Paths are unique, so no two compare equal.\n const briefs = [...files]\n .sort((a, b) => (a.path < b.path ? -1 : 1))\n .map((file) => parseBrief(file.path, file.text, config, file.phase));\n return {\n config,\n briefs,\n live: briefs.filter((b) => b.phase === 'live'),\n archived: briefs.filter((b) => b.phase === 'archived'),\n };\n}\n\n/**\n * The form in which ids are compared. Numeric ids compare by value, so a\n * dependency written `34` - which YAML would read as a number anyway - names\n * brief `034`.\n */\nexport function idKey(id: string): string {\n return /^\\d+$/.test(id) ? String(Number(id)) : id;\n}\n\n/** Briefs an id, a file name or a path names. More than one is an ambiguity the caller reports. */\nexport function findBriefs(corpus: Corpus, reference: string): Brief[] {\n const key = idKey(reference.trim());\n const byId = corpus.briefs.filter((b) => b.id !== null && idKey(b.id) === key);\n if (byId.length > 0) return byId;\n let path: string;\n try {\n path = normalisePath(reference);\n } catch {\n return [];\n }\n return corpus.briefs.filter((b) => b.file === path || b.name === path);\n}\n\n/** The brief a dependency names, preferring a live one when an id is ambiguous. */\nexport function resolveDependency(corpus: Corpus, id: string): Brief | undefined {\n const found = findBriefs(corpus, id);\n return found.find((b) => b.phase === 'live') ?? found[0];\n}\n\n/** Briefs grouped by id, for the ids more than one file claims. */\nexport function duplicateIds(corpus: Corpus): Map<string, Brief[]> {\n const groups = new Map<string, Brief[]>();\n for (const brief of corpus.briefs) {\n if (brief.id === null) continue;\n const key = idKey(brief.id);\n groups.set(key, [...(groups.get(key) ?? []), brief]);\n }\n return new Map([...groups].filter(([, members]) => members.length > 1));\n}\n\n/** The live dependencies of a brief that are not archived yet. */\nexport function pendingDependencies(corpus: Corpus, brief: Brief): string[] {\n return brief.dependsOn.filter((dependency) => {\n const target = resolveDependency(corpus, dependency);\n return target !== undefined && target.phase === 'live';\n });\n}\n\n/**\n * A live brief whose every dependency is archived can be executed now, unless\n * it is still being written or is deferred until its trigger.\n */\nexport function isReady(corpus: Corpus, brief: Brief): boolean {\n if (brief.phase !== 'live' || brief.status === 'draft' || brief.status === 'deferred') return false;\n return brief.dependsOn.every((dependency) => resolveDependency(corpus, dependency)?.phase === 'archived');\n}\n\nfunction label(brief: Brief): string {\n return brief.id ?? brief.name;\n}\n\n/** Briefs by id, numbers by value; by path where two ids agree. */\nexport function byId(a: Brief, b: Brief): number {\n const x = label(a);\n const y = label(b);\n const numeric = /^\\d+$/.test(x) && /^\\d+$/.test(y);\n if (numeric && Number(x) !== Number(y)) return Number(x) - Number(y);\n if (x < y) return -1;\n if (x > y) return 1;\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;\n}\n\n/** The live briefs a brief depends on, by id. Archived ones are done, and unknown ones are the dependency rule's. */\nexport function liveDependencies(corpus: Corpus, brief: Brief): Brief[] {\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n return [...new Set(targets)].sort(byId);\n}\n\n/** A live brief that cannot start before deferred work, and the dependency it waits through. */\nexport interface Waiting {\n readonly brief: Brief;\n /** The deferred brief it depends on, or the brief through which it waits on one; the first by id. */\n readonly waitsOn: Brief;\n}\n\n/**\n * Live briefs that wait on deferred work: each depends on a deferred brief,\n * or on a brief that waits on one. Neither can start before an event nobody\n * has scheduled, so neither runs in a wave (ADR-0011): `schedule` places them\n * nowhere and `matrix` compares them with nothing. By id.\n */\nexport function waitingOnDeferred(corpus: Corpus): Waiting[] {\n const candidates = corpus.live.filter((b) => b.status !== 'deferred');\n const dependencies = new Map(candidates.map((b) => [b, liveDependencies(corpus, b)]));\n const held = new Set<Brief>();\n const holds = (d: Brief): boolean => d.status === 'deferred' || held.has(d);\n // Each pass holds another brief or is the last, so there is at most one pass more than there are briefs.\n for (let grew = true; grew; ) {\n grew = false;\n for (const brief of candidates) {\n if (held.has(brief) || !(dependencies.get(brief) as Brief[]).some(holds)) continue;\n held.add(brief);\n grew = true;\n }\n }\n return [...held].sort(byId).map((brief) => ({ brief, waitsOn: (dependencies.get(brief) as Brief[]).find(holds) as Brief }));\n}\n\n/**\n * Dependency cycles among live briefs, each as the ids along it with the first\n * repeated at the end. Found with Tarjan's algorithm; each strongly connected\n * component is reported once, starting from its first brief by path.\n */\nexport function dependencyCycles(corpus: Corpus): Brief[][] {\n const nodes = corpus.live;\n const edges = new Map<Brief, Brief[]>();\n for (const brief of nodes) {\n // A brief that depends on itself is the dependency rule's finding; left\n // in, the edge would be the shortest way round any cycle it is part of.\n const targets = brief.dependsOn\n .map((d) => resolveDependency(corpus, d))\n .filter((t): t is Brief => t !== undefined && t !== brief && t.phase === 'live');\n edges.set(brief, targets);\n }\n\n const index = new Map<Brief, number>();\n const low = new Map<Brief, number>();\n const stack: Brief[] = [];\n const onStack = new Set<Brief>();\n const components: Brief[][] = [];\n let counter = 0;\n\n // Recursion depth is bounded by the number of live briefs.\n const connect = (v: Brief): void => {\n index.set(v, counter);\n low.set(v, counter);\n counter += 1;\n stack.push(v);\n onStack.add(v);\n for (const w of edges.get(v) ?? []) {\n if (!index.has(w)) {\n connect(w);\n low.set(v, Math.min(low.get(v) as number, low.get(w) as number));\n } else if (onStack.has(w)) {\n low.set(v, Math.min(low.get(v) as number, index.get(w) as number));\n }\n }\n if (low.get(v) === index.get(v)) {\n const component: Brief[] = [];\n for (;;) {\n const w = stack.pop() as Brief;\n onStack.delete(w);\n component.push(w);\n if (w === v) break;\n }\n if (component.length > 1) components.push(component);\n }\n };\n for (const brief of nodes) if (!index.has(brief)) connect(brief);\n\n return components.map((component) => {\n const members = new Set(component);\n const start = [...component].sort((a, b) => (a.file < b.file ? -1 : 1))[0] as Brief;\n return cyclePath(start, members, edges);\n });\n}\n\n/**\n * A cycle as a finding's subject: the briefs on it, each once, in order. `lint`\n * and `schedule` word a cycle differently and report it as one problem.\n */\nexport function cycleSubject(cycle: readonly Brief[]): string {\n return [...new Set(cycle.map((b) => b.id ?? b.name))].sort().join(', ');\n}\n\n/** A path from `start` back to itself inside one component, found breadth-first. */\nfunction cyclePath(start: Brief, members: ReadonlySet<Brief>, edges: ReadonlyMap<Brief, Brief[]>): Brief[] {\n const previous = new Map<Brief, Brief>();\n const queue: Brief[] = [start];\n for (let head = 0; head < queue.length; head += 1) {\n const node = queue[head] as Brief;\n for (const next of edges.get(node) ?? []) {\n if (!members.has(next)) continue;\n if (next === start) {\n const path: Brief[] = [start];\n for (let at: Brief | undefined = node; at !== undefined && at !== start; at = previous.get(at)) path.splice(1, 0, at);\n return [...path, start];\n }\n if (!previous.has(next)) {\n previous.set(next, node);\n queue.push(next);\n }\n }\n }\n /* v8 ignore next -- a component of two or more always leads back to its start. */\n return [start, start];\n}\n"]}
package/dist/glob.d.ts CHANGED
@@ -8,11 +8,12 @@
8
8
  * spec-brief adds around it:
9
9
  *
10
10
  * - A pattern is relative to the repository root, so a leading `/` is refused
11
- * rather than rooted at the filesystem: on the pattern, one after a leading
12
- * `./` too, as in `.//docs`, and on a text its braces give, since spec-core
13
- * reads `{/docs,x}` as `/docs` or `x`, and `docs` would fall out of the
14
- * scope unsaid. A list entry's `!` has no list to belong to in a scope, so
15
- * it is refused rather than read.
11
+ * rather than rooted at the filesystem: on the pattern, and on a text its
12
+ * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and
13
+ * `docs` would fall out of the scope unsaid. A leading `./` goes with the
14
+ * slashes after it, as POSIX reads them: `.//docs` is `docs`, and
15
+ * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong
16
+ * to in a scope, so it is refused rather than read.
16
17
  * - Paths compare case-sensitively on every host, as git's do.
17
18
  * - A path with no glob syntax is read as the tree reads it: a file the tree
18
19
  * holds is that file, a directory it holds is everything beneath it, and a
package/dist/glob.js CHANGED
@@ -8,11 +8,12 @@
8
8
  * spec-brief adds around it:
9
9
  *
10
10
  * - A pattern is relative to the repository root, so a leading `/` is refused
11
- * rather than rooted at the filesystem: on the pattern, one after a leading
12
- * `./` too, as in `.//docs`, and on a text its braces give, since spec-core
13
- * reads `{/docs,x}` as `/docs` or `x`, and `docs` would fall out of the
14
- * scope unsaid. A list entry's `!` has no list to belong to in a scope, so
15
- * it is refused rather than read.
11
+ * rather than rooted at the filesystem: on the pattern, and on a text its
12
+ * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and
13
+ * `docs` would fall out of the scope unsaid. A leading `./` goes with the
14
+ * slashes after it, as POSIX reads them: `.//docs` is `docs`, and
15
+ * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong
16
+ * to in a scope, so it is refused rather than read.
16
17
  * - Paths compare case-sensitively on every host, as git's do.
17
18
  * - A path with no glob syntax is read as the tree reads it: a file the tree
18
19
  * holds is that file, a directory it holds is everything beneath it, and a
@@ -28,7 +29,7 @@
28
29
  * size times the path's length, and a question about two scopes that cannot be
29
30
  * answered within the search's budget answers `undecided`, never a guess.
30
31
  */
31
- import { globCovers as coreCovers, globWitness as coreWitness, isGlobSyntax, parseGlob as coreParse, WITNESS_BUDGET, } from './vendor/spec-core/pattern/index.js';
32
+ import { globAlternatives, globCovers as coreCovers, globWitness as coreWitness, isGlobSyntax, parseGlob as coreParse, WITNESS_BUDGET, } from './vendor/spec-core/pattern/index.js';
32
33
  import { segments } from './vendor/spec-core/path/index.js';
33
34
  export { isGlobSyntax, WITNESS_BUDGET };
34
35
  /** Parses a scope pattern, or says why it cannot. */
@@ -36,7 +37,15 @@ export function parseGlob(source, options = {}) {
36
37
  const pattern = source.trim();
37
38
  if (pattern.startsWith('!'))
38
39
  return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };
39
- if (undotted(pattern).startsWith('/'))
40
+ // spec-core's own reading of where each alternative starts, a leading `./`
41
+ // and `/` included (spec-core ADR-0003). A pattern it refuses, the core's
42
+ // parse refuses in the same words, so either may say so. It comes first so
43
+ // that a pattern led by `/`, which the core roots at the filesystem's root,
44
+ // is refused in spec-brief's words.
45
+ const read = globAlternatives(pattern);
46
+ if (!read.ok)
47
+ return { ok: false, error: read.error };
48
+ if (read.rooted)
40
49
  return { ok: false, error: 'a pattern is relative to the repository root and cannot start with "/"' };
41
50
  const given = options.literal ?? 'file';
42
51
  const literals = [];
@@ -50,106 +59,16 @@ export function parseGlob(source, options = {}) {
50
59
  const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });
51
60
  if (!parsed.ok)
52
61
  return parsed;
53
- // Read once the core has parsed the pattern, so that its braces close and
54
- // give no more texts than the core allows.
55
- const rooted = rootedAlternative(pattern);
62
+ // Once the core has parsed the pattern, so that an alternative naming no
63
+ // path, `{/,x}`, is refused in the core's words. The text is named behind
64
+ // the `/` that roots it, as spec-core gives it: it reads the same written
65
+ // alone, so a `}` or `,` no group took is written as a class, `[}]`.
66
+ const rooted = read.alternatives.find((alternative) => alternative.rooted);
56
67
  if (rooted !== undefined) {
57
- return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to "${rooted}", which starts with "/"` };
68
+ return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to "/${rooted.text}", which starts with "/"` };
58
69
  }
59
70
  return { ok: true, glob: { source, compiled: parsed.glob, literals } };
60
71
  }
61
- /**
62
- * A pattern less the `./` it starts with. spec-core drops it before it reads
63
- * a leading `/`, since `.` names nothing: `.//docs` is `/docs`, rooted at the
64
- * filesystem's root.
65
- */
66
- function undotted(pattern) {
67
- let rest = pattern;
68
- while (rest.startsWith('./'))
69
- rest = rest.slice(2);
70
- return rest;
71
- }
72
- /**
73
- * The first text a pattern's braces give that starts with `/` once its `./`
74
- * is dropped, less that `./`: an alternative spec-core roots at the
75
- * filesystem's root, since braces expand before a leading `/` is read, so
76
- * that `{/docs,x}` is `/docs` or `x` (spec-core ADR-0003, amended
77
- * 2026-09-29). `undefined` when there is none. A `/` after anything else
78
- * starts no text: `a/{/b,c}` gives `a//b`, which is `a/b`.
79
- *
80
- * spec-core keeps nothing of the texts its braces give, and the refusal names
81
- * the text, as the core's own refusals do. So this expands braces as the core
82
- * does, for a pattern the core parsed, whose braces close and give at most
83
- * `MAX_ALTERNATIVES` texts: a `\` escapes the next character, a class holds
84
- * no brace syntax, a `}` with no `{` open is a literal, and the first braces
85
- * to close are expanded first, each option in turn, so the text named is the
86
- * first such text the core gives.
87
- *
88
- * Its loop, read one step past the end, reads `''`, which no branch acts on,
89
- * so a bound one further reads the same.
90
- */
91
- function rootedAlternative(pattern) {
92
- let depth = 0;
93
- let open = 0;
94
- const stops = [];
95
- for (let i = 0; i < pattern.length; i += 1) {
96
- const ch = pattern.charAt(i);
97
- if (ch === '\\') {
98
- i += 1;
99
- }
100
- else if (ch === '[') {
101
- const close = classEnd(pattern, i);
102
- if (close !== -1)
103
- i = close;
104
- }
105
- else if (ch === '{') {
106
- if (depth === 0)
107
- open = i;
108
- depth += 1;
109
- }
110
- else if (ch === ',' && depth === 1) {
111
- stops.push(i);
112
- }
113
- else if (ch === '}' && depth > 0) {
114
- depth -= 1;
115
- if (depth === 0) {
116
- let start = open + 1;
117
- for (const stop of [...stops, i]) {
118
- const rooted = rootedAlternative(`${pattern.slice(0, open)}${pattern.slice(start, stop)}${pattern.slice(i + 1)}`);
119
- if (rooted !== undefined)
120
- return rooted;
121
- start = stop + 1;
122
- }
123
- return undefined;
124
- }
125
- }
126
- }
127
- const text = undotted(pattern);
128
- return text.startsWith('/') ? text : undefined;
129
- }
130
- /**
131
- * The index of the `]` closing a class opened at `open`, or -1 when none does
132
- * within its segment, as spec-core finds it while it expands braces: after a
133
- * `!` or `^`, the first member is a member even when it is `]`.
134
- */
135
- function classEnd(pattern, open) {
136
- let i = open + 1;
137
- if (pattern.charAt(i) === '!' || pattern.charAt(i) === '^')
138
- i += 1;
139
- if (pattern.charAt(i) === ']')
140
- i += 1;
141
- for (; i < pattern.length; i += 1) {
142
- const ch = pattern.charAt(i);
143
- if (ch === '\\')
144
- i += 1;
145
- else if (ch === '/')
146
- return -1;
147
- else if (ch === ']')
148
- return i;
149
- }
150
- /* v8 ignore next -- in a pattern the core parsed, a "[" is closed, or met by a "/", before the pattern ends. */
151
- return -1;
152
- }
153
72
  /**
154
73
  * Whether a path matches. The path is read as a repository path: empty and
155
74
  * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.
package/dist/glob.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACL,UAAU,IAAI,UAAU,EACxB,WAAW,IAAI,WAAW,EAC1B,YAAY,EACZ,SAAS,IAAI,SAAS,EAGtB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAuB,cAAc,EAAgB,CAAC;AA+B3E,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAO,GAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iEAAiE,EAAE,CAAC;IAC5H,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,wEAAwE,EAAE,CAAC;IAC7I,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC;IACxC,MAAM,QAAQ,GAAc,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAG,CAAC,IA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AAC;IACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;YAAE,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAChI,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACpD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,IAAI,CAAC,IAAU,EAAE,IAAY;IAC3C,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAA+B;IACvD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem: on the pattern, one after a leading\n * `./` too, as in `.//docs`, and on a text its braces give, since spec-core\n * reads `{/docs,x}` as `/docs` or `x`, and `docs` would fall out of the\n * scope unsaid. A list entry's `!` has no list to belong to in a scope, so\n * it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file. A trailing `/` means\n * the same on a brace alternative as on the whole pattern: `{src/,lib}` is\n * `src/` or `lib`, and the tree is asked about `lib` alone.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /**\n * Each path the pattern names with no glob syntax and no trailing `/`, one\n * per brace alternative; empty when it has none.\n */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n if (undotted(pattern).startsWith('/')) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n // A pattern too large to compile is refused by the core, with its reason,\n // as a malformed one is; what the reading throws is a defect, and passes on.\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n if (!parsed.ok) return parsed;\n // Read once the core has parsed the pattern, so that its braces close and\n // give no more texts than the core allows.\n const rooted = rootedAlternative(pattern);\n if (rooted !== undefined) {\n return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to \"${rooted}\", which starts with \"/\"` };\n }\n return { ok: true, glob: { source, compiled: parsed.glob, literals } };\n}\n\n/**\n * A pattern less the `./` it starts with. spec-core drops it before it reads\n * a leading `/`, since `.` names nothing: `.//docs` is `/docs`, rooted at the\n * filesystem's root.\n */\nfunction undotted(pattern: string): string {\n let rest = pattern;\n while (rest.startsWith('./')) rest = rest.slice(2);\n return rest;\n}\n\n/**\n * The first text a pattern's braces give that starts with `/` once its `./`\n * is dropped, less that `./`: an alternative spec-core roots at the\n * filesystem's root, since braces expand before a leading `/` is read, so\n * that `{/docs,x}` is `/docs` or `x` (spec-core ADR-0003, amended\n * 2026-09-29). `undefined` when there is none. A `/` after anything else\n * starts no text: `a/{/b,c}` gives `a//b`, which is `a/b`.\n *\n * spec-core keeps nothing of the texts its braces give, and the refusal names\n * the text, as the core's own refusals do. So this expands braces as the core\n * does, for a pattern the core parsed, whose braces close and give at most\n * `MAX_ALTERNATIVES` texts: a `\\` escapes the next character, a class holds\n * no brace syntax, a `}` with no `{` open is a literal, and the first braces\n * to close are expanded first, each option in turn, so the text named is the\n * first such text the core gives.\n *\n * Its loop, read one step past the end, reads `''`, which no branch acts on,\n * so a bound one further reads the same.\n */\nfunction rootedAlternative(pattern: string): string | undefined {\n let depth = 0;\n let open = 0;\n const stops: number[] = [];\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '[') {\n const close = classEnd(pattern, i);\n if (close !== -1) i = close;\n } else if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n } else if (ch === ',' && depth === 1) {\n stops.push(i);\n } else if (ch === '}' && depth > 0) {\n depth -= 1;\n if (depth === 0) {\n let start = open + 1;\n for (const stop of [...stops, i]) {\n const rooted = rootedAlternative(`${pattern.slice(0, open)}${pattern.slice(start, stop)}${pattern.slice(i + 1)}`);\n if (rooted !== undefined) return rooted;\n start = stop + 1;\n }\n return undefined;\n }\n }\n }\n const text = undotted(pattern);\n return text.startsWith('/') ? text : undefined;\n}\n\n/**\n * The index of the `]` closing a class opened at `open`, or -1 when none does\n * within its segment, as spec-core finds it while it expands braces: after a\n * `!` or `^`, the first member is a member even when it is `]`.\n */\nfunction classEnd(pattern: string, open: number): number {\n let i = open + 1;\n if (pattern.charAt(i) === '!' || pattern.charAt(i) === '^') i += 1;\n if (pattern.charAt(i) === ']') i += 1;\n for (; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') i += 1;\n else if (ch === '/') return -1;\n else if (ch === ']') return i;\n }\n /* v8 ignore next -- in a pattern the core parsed, a \"[\" is closed, or met by a \"/\", before the pattern ends. */\n return -1;\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A brace alternative as its pattern writes it, and the index in the pattern where it ends. */\nexport interface WrittenAlternative {\n readonly written: string;\n readonly end: number;\n}\n\n/**\n * Each alternative of a pattern as written, in the order the core expands\n * them, and where each ends, when a `/` written there ends that alternative\n * and no other: the pattern itself when it has no braces, or the alternatives\n * of braces that end the pattern and whose own braces end theirs -\n * `lib/{util,new}`, `{a,b/{c,d}}`. `null` when more of the pattern follows\n * braces, `{a,b}/new`, since every alternative they give ends where the\n * pattern does; and for a pattern with a class, which may hold a brace or a\n * comma of its own and which this does not read.\n *\n * spec-core expands braces and keeps nothing of where an alternative was\n * written, and a note's advice is built from what was written, as the core\n * builds its own. So this reads braces as the expansion does, for a pattern\n * that parses: a `\\` escapes the next character, and a `}` with no `{` open\n * is a literal.\n */\nexport function writtenAlternatives(pattern: string): WrittenAlternative[] | null {\n let depth = 0;\n let open = 0;\n const stops: number[] = [];\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '[') {\n return null;\n } else if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n } else if (ch === ',' && depth === 1) {\n stops.push(i);\n } else if (ch === '}' && depth > 0) {\n depth -= 1;\n if (depth === 0) return i === pattern.length - 1 ? optionsOf(pattern, open, [...stops, i]) : null;\n }\n }\n return [{ written: pattern, end: pattern.length }];\n}\n\n/** The alternatives of the braces opened at `open`, each option ending at one of `stops`. */\nfunction optionsOf(pattern: string, open: number, stops: readonly number[]): WrittenAlternative[] | null {\n const prefix = pattern.slice(0, open);\n const alternatives: WrittenAlternative[] = [];\n let start = open + 1;\n for (const stop of stops) {\n const inner = writtenAlternatives(pattern.slice(start, stop));\n if (inner === null) return null;\n for (const { written, end } of inner) alternatives.push({ written: prefix + written, end: start + end });\n start = stop + 1;\n }\n return alternatives;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EACL,gBAAgB,EAChB,UAAU,IAAI,UAAU,EACxB,WAAW,IAAI,WAAW,EAC1B,YAAY,EACZ,SAAS,IAAI,SAAS,EAGtB,cAAc,GAEf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAuB,cAAc,EAAgB,CAAC;AA+B3E,qDAAqD;AACrD,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,OAAO,GAAiB,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC9B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,iEAAiE,EAAE,CAAC;IAC5H,2EAA2E;IAC3E,0EAA0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QAAE,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["/**\n * Scopes as globs: spec-core's `path` dialect, read the way spec-brief reads a\n * brief.\n *\n * The syntax, the automaton and the witness search are spec-core's, copied\n * into `src/vendor/` and verified by hash, so the family's tools read one\n * pattern the same way (spec-core ADR-0003). What is decided here is what\n * spec-brief adds around it:\n *\n * - A pattern is relative to the repository root, so a leading `/` is refused\n * rather than rooted at the filesystem: on the pattern, and on a text its\n * braces give, since spec-core reads `{/docs,x}` as `/docs` or `x`, and\n * `docs` would fall out of the scope unsaid. A leading `./` goes with the\n * slashes after it, as POSIX reads them: `.//docs` is `docs`, and\n * `./{/docs,x}` is `docs` or `x`. A list entry's `!` has no list to belong\n * to in a scope, so it is refused rather than read.\n * - Paths compare case-sensitively on every host, as git's do.\n * - A path with no glob syntax is read as the tree reads it: a file the tree\n * holds is that file, a directory it holds is everything beneath it, and a\n * path it does not hold is a file, unless it is written with a trailing `/`.\n * The tree, not the spelling, knows that `Dockerfile` is a file and\n * `docs/v1.2` a directory (ADR-0005, amended 2026-09-26).\n * - A trailing `/**` is at least one segment, so `docs/**` is the directory's\n * contents and a collision witness is always a file. A trailing `/` means\n * the same on a brace alternative as on the whole pattern: `{src/,lib}` is\n * `src/` or `lib`, and the tree is asked about `lib` alone.\n *\n * Nothing here compiles to a `RegExp`. Matching costs at most the pattern's\n * size times the path's length, and a question about two scopes that cannot be\n * answered within the search's budget answers `undecided`, never a guess.\n */\n\nimport {\n globAlternatives,\n globCovers as coreCovers,\n globWitness as coreWitness,\n isGlobSyntax,\n parseGlob as coreParse,\n type Glob as CoreGlob,\n type LiteralReading,\n WITNESS_BUDGET,\n type Witness,\n} from './vendor/spec-core/pattern/index.js';\nimport { segments } from './vendor/spec-core/path/index.js';\n\nexport { isGlobSyntax, type LiteralReading, WITNESS_BUDGET, type Witness };\n\n/** A literal path a pattern names, and how it was read. */\nexport interface Literal {\n readonly path: string;\n readonly reading: LiteralReading;\n}\n\nexport interface Glob {\n readonly source: string;\n /** The compiled pattern: spec-core's `path` dialect, case-sensitive. */\n readonly compiled: CoreGlob;\n /**\n * Each path the pattern names with no glob syntax and no trailing `/`, one\n * per brace alternative; empty when it has none.\n */\n readonly literals: readonly Literal[];\n}\n\nexport type GlobParse = { readonly ok: true; readonly glob: Glob } | { readonly ok: false; readonly error: string };\n\nexport interface ParseOptions {\n /**\n * How a path with no glob syntax is read: `file`, that path alone;\n * `directory`, everything beneath it; `either`, both. A function is asked\n * per literal path, as {@link readingIn} answers for a tree. `file` when\n * unset: a path nothing says is a directory is not read as one.\n */\n readonly literal?: LiteralReading | ((path: string) => LiteralReading) | undefined;\n}\n\n/** Parses a scope pattern, or says why it cannot. */\nexport function parseGlob(source: string, options: ParseOptions = {}): GlobParse {\n const pattern = source.trim();\n if (pattern.startsWith('!')) return { ok: false, error: 'negated patterns are not supported; narrow the positive pattern' };\n // spec-core's own reading of where each alternative starts, a leading `./`\n // and `/` included (spec-core ADR-0003). A pattern it refuses, the core's\n // parse refuses in the same words, so either may say so. It comes first so\n // that a pattern led by `/`, which the core roots at the filesystem's root,\n // is refused in spec-brief's words.\n const read = globAlternatives(pattern);\n if (!read.ok) return { ok: false, error: read.error };\n if (read.rooted) return { ok: false, error: 'a pattern is relative to the repository root and cannot start with \"/\"' };\n const given = options.literal ?? 'file';\n const literals: Literal[] = [];\n const literal = (path: string): LiteralReading => {\n const reading = typeof given === 'function' ? given(path) : given;\n literals.push({ path, reading });\n return reading;\n };\n // A pattern too large to compile is refused by the core, with its reason,\n // as a malformed one is; what the reading throws is a defect, and passes on.\n const parsed = coreParse(pattern, { dialect: 'path', caseSensitive: true, literal });\n if (!parsed.ok) return parsed;\n // Once the core has parsed the pattern, so that an alternative naming no\n // path, `{/,x}`, is refused in the core's words. The text is named behind\n // the `/` that roots it, as spec-core gives it: it reads the same written\n // alone, so a `}` or `,` no group took is written as a class, `[}]`.\n const rooted = read.alternatives.find((alternative) => alternative.rooted);\n if (rooted !== undefined) {\n return { ok: false, error: `a pattern is relative to the repository root, and the braces expand to \"/${rooted.text}\", which starts with \"/\"` };\n }\n return { ok: true, glob: { source, compiled: parsed.glob, literals } };\n}\n\n/**\n * Whether a path matches. The path is read as a repository path: empty and\n * `.` segments are dropped, so `./src//a.ts` is `src/a.ts`.\n */\nexport function matchGlob(glob: Glob, path: string): boolean {\n const canonical = segments(path).join('/');\n return canonical !== '' && glob.compiled.match(canonical);\n}\n\n/**\n * A shortest path every glob in `include` matches and none in `exclude` does,\n * `none` as a proof that there is no such path, or `undecided` when the search\n * met its budget first.\n */\nexport function globWitness(include: readonly Glob[], exclude: readonly Glob[] = [], budget: number = WITNESS_BUDGET): Witness {\n return coreWitness(\n include.map((g) => g.compiled),\n exclude.map((g) => g.compiled),\n budget,\n );\n}\n\n/** Whether every path `inner` matches is matched by one of `outer`, or `undecided`. */\nexport function globCovers(outer: readonly Glob[], inner: Glob, budget: number = WITNESS_BUDGET): boolean | 'undecided' {\n return coreCovers(\n outer.map((g) => g.compiled),\n inner.compiled,\n budget,\n );\n}\n\n/**\n * A path both globs match, or `null` when there is none: the 0.1 interface,\n * kept for the library's callers. It cannot say `undecided`, so a search that\n * meets its budget throws; {@link globWitness} answers in three ways.\n */\nexport function intersectGlobs(a: Glob, b: Glob, budget: number = WITNESS_BUDGET): string | null {\n const witness = globWitness([a, b], [], budget);\n if (witness.kind === 'undecided') {\n throw new Error(`whether \"${a.source}\" and \"${b.source}\" meet is undecided within the search's budget`);\n }\n return witness.kind === 'found' ? witness.path : null;\n}\n\n/**\n * The directories a walk must enter to find every match, one per brace\n * alternative: the leading literal segments, or a literal file's directory.\n * `''` for an alternative that can match at the root.\n */\nexport function globBases(glob: Glob): readonly string[] {\n return glob.compiled.bases;\n}\n\n/** The first of {@link globBases}: the 0.1 interface, kept for the library's callers. */\nexport function globBase(glob: Glob): string {\n // One base per alternative, and a pattern has at least one.\n return glob.compiled.bases[0] as string;\n}\n\n/** A brace alternative as its pattern writes it, and the index in the pattern where it ends. */\nexport interface WrittenAlternative {\n readonly written: string;\n readonly end: number;\n}\n\n/**\n * Each alternative of a pattern as written, in the order the core expands\n * them, and where each ends, when a `/` written there ends that alternative\n * and no other: the pattern itself when it has no braces, or the alternatives\n * of braces that end the pattern and whose own braces end theirs -\n * `lib/{util,new}`, `{a,b/{c,d}}`. `null` when more of the pattern follows\n * braces, `{a,b}/new`, since every alternative they give ends where the\n * pattern does; and for a pattern with a class, which may hold a brace or a\n * comma of its own and which this does not read.\n *\n * spec-core expands braces and keeps nothing of where an alternative was\n * written, and a note's advice is built from what was written, as the core\n * builds its own. So this reads braces as the expansion does, for a pattern\n * that parses: a `\\` escapes the next character, and a `}` with no `{` open\n * is a literal.\n */\nexport function writtenAlternatives(pattern: string): WrittenAlternative[] | null {\n let depth = 0;\n let open = 0;\n const stops: number[] = [];\n for (let i = 0; i < pattern.length; i += 1) {\n const ch = pattern.charAt(i);\n if (ch === '\\\\') {\n i += 1;\n } else if (ch === '[') {\n return null;\n } else if (ch === '{') {\n if (depth === 0) open = i;\n depth += 1;\n } else if (ch === ',' && depth === 1) {\n stops.push(i);\n } else if (ch === '}' && depth > 0) {\n depth -= 1;\n if (depth === 0) return i === pattern.length - 1 ? optionsOf(pattern, open, [...stops, i]) : null;\n }\n }\n return [{ written: pattern, end: pattern.length }];\n}\n\n/** The alternatives of the braces opened at `open`, each option ending at one of `stops`. */\nfunction optionsOf(pattern: string, open: number, stops: readonly number[]): WrittenAlternative[] | null {\n const prefix = pattern.slice(0, open);\n const alternatives: WrittenAlternative[] = [];\n let start = open + 1;\n for (const stop of stops) {\n const inner = writtenAlternatives(pattern.slice(start, stop));\n if (inner === null) return null;\n for (const { written, end } of inner) alternatives.push({ written: prefix + written, end: start + end });\n start = stop + 1;\n }\n return alternatives;\n}\n\n/** A name with an extension, `login.ts` or `.eslintrc.json`, and not a dot-name such as `.github`. */\nexport function hasExtension(name: string): boolean {\n return /.\\.[^.]+$/.test(name);\n}\n\n/** The files a tree holds, and every directory above one. */\nexport interface Tree {\n readonly files: ReadonlySet<string>;\n readonly directories: ReadonlySet<string>;\n}\n\nconst trees = new WeakMap<readonly string[], Tree>();\n\n/** The tree a list of files describes. Built once per list, which every brief of a run shares. */\nexport function treeOf(files: readonly string[]): Tree {\n const known = trees.get(files);\n if (known !== undefined) return known;\n const directories = new Set<string>();\n for (const file of files) {\n for (let slash = file.indexOf('/'); slash !== -1; slash = file.indexOf('/', slash + 1)) directories.add(file.slice(0, slash));\n }\n const tree = { files: new Set(files), directories };\n trees.set(files, tree);\n return tree;\n}\n\n/** What the tree holds at a path: a file, a directory, or nothing. */\nexport function held(tree: Tree, path: string): 'file' | 'directory' | null {\n if (tree.files.has(path)) return 'file';\n return tree.directories.has(path) ? 'directory' : null;\n}\n\n/**\n * How a tree reads a literal path: a directory it holds is a directory, and\n * anything else is a file. Without a tree nothing is known to be a directory,\n * so every literal is a file; a trailing `/` says otherwise, and never reaches\n * this question.\n */\nexport function readingIn(files: readonly string[] | null): (path: string) => LiteralReading {\n if (files === null) return () => 'file';\n const tree = treeOf(files);\n return (path) => (held(tree, path) === 'directory' ? 'directory' : 'file');\n}\n"]}
package/dist/lint.js CHANGED
@@ -68,6 +68,7 @@ export async function lint(corpus, options = {}) {
68
68
  line: Math.max(1, Math.trunc(result.line)),
69
69
  brief: brief.id ?? undefined,
70
70
  hint: result.hint,
71
+ subject: result.subject,
71
72
  });
72
73
  }
73
74
  }
package/dist/lint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAA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U,SAAS,CAAC,QAA4B;IACpD,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM;QAC7D,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,MAAM;QACjE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,MAAM;KAC5D,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,QAA4B,EAAE,MAAe;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["/**\n * Running rules: severities from the configuration, plugins beside the\n * built-in rules, findings in a stable order.\n */\n\nimport type { Waiver } from './archive.js';\nimport type { Brief } from './brief.js';\nimport { ConfigError } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { analyse, ARCHIVE_RULES, COLLISION_RULES, type Rule, type RuleInfo, RULES } from './rules.js';\nimport type { Finding, Severity, SeveritySetting } from './types.js';\n\n/** What a plugin's `waive` hook is asked about: one archival, refused. */\nexport interface WaiveContext {\n /** The absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n /**\n * Every finding that refuses the archival, as a frozen copy: writing to it\n * throws, and the waivers are matched against the plan's own. A\n * `protected-file` finding names its `path`; an `out-of-scope` one lists its\n * `paths`. Only those two can be waived.\n */\n readonly findings: readonly Finding[];\n /** The base the round is measured from, as it was given; `null` when none was. */\n readonly base: string | null;\n /** The commit the round landed as; `null` when none was read. */\n readonly commit: string | null;\n}\n\nexport interface Plugin {\n /** Prefixes the plugin's rule ids: `<name>/<rule>`. */\n readonly name: string;\n readonly rules: readonly Rule[];\n /** The plugin's entry in the configuration, handed to each rule. */\n readonly options?: unknown;\n /**\n * Lifts refusals of an archival that the plugin's own check allows - a\n * protected file a verified ruling covers - by rule and path. Asked only\n * when the plan has a refusal it could lift. Returning nothing waives\n * nothing.\n */\n readonly waive?: ((context: WaiveContext) => readonly Waiver[] | void | Promise<readonly Waiver[] | void>) | undefined;\n}\n\nexport interface LintOptions {\n readonly plugins?: readonly Plugin[];\n /** Tracked files, for the rules that read the tree. */\n readonly repoFiles?: readonly string[] | null;\n /** Limit the findings to these briefs. The whole corpus is still read. */\n readonly only?: readonly Brief[];\n}\n\nconst RANK: Readonly<Record<Severity, number>> = { note: 0, warning: 1, error: 2 };\n\nfunction lower(a: Severity, b: Severity): Severity {\n return RANK[a] <= RANK[b] ? a : b;\n}\n\ninterface ActiveRule {\n readonly id: string;\n readonly rule: Rule;\n readonly severity: SeveritySetting;\n readonly options: unknown;\n}\n\n/** Every rule id a run knows: built-in, collision, archive and plugin. */\nexport function ruleIds(plugins: readonly Plugin[] = []): string[] {\n return [\n ...RULES.map((r) => r.id),\n ...COLLISION_RULES.map((r) => r.id),\n ...ARCHIVE_RULES.map((r) => r.id),\n ...plugins.flatMap((p) => p.rules.map((r) => `${p.name}/${r.id}`)),\n ];\n}\n\n/** The severity configuration assigns a rule, or its own. */\nexport function severityOf(corpus: Corpus, id: string, fallback: SeveritySetting): SeveritySetting {\n return corpus.config.rules[id] ?? fallback;\n}\n\n/** The severity of a built-in rule as configured, or `null` when it is off. */\nexport function configuredSeverity(corpus: Corpus, id: string): Severity | null {\n const rule = [...RULES, ...COLLISION_RULES, ...ARCHIVE_RULES].find((r) => r.id === id) as RuleInfo;\n const setting = severityOf(corpus, id, rule.severity);\n return setting === 'off' ? null : setting;\n}\n\n/** Refuses a configuration that names a rule nobody defines: a typo there silences nothing. */\nexport function checkRuleIds(corpus: Corpus, plugins: readonly Plugin[] = []): void {\n const known = new Set(ruleIds(plugins));\n const unknown = Object.keys(corpus.config.rules).filter((id) => !known.has(id));\n if (unknown.length > 0) {\n throw new ConfigError('configuration', unknown.map((id) => `\"rules.${id}\" names no rule`));\n }\n}\n\nexport async function lint(corpus: Corpus, options: LintOptions = {}): Promise<Finding[]> {\n const plugins = options.plugins ?? [];\n checkRuleIds(corpus, plugins);\n const active: ActiveRule[] = [\n ...RULES.map((rule) => ({ id: rule.id, rule, severity: severityOf(corpus, rule.id, rule.severity), options: undefined })),\n ...plugins.flatMap((plugin) =>\n plugin.rules.map((rule) => {\n const id = `${plugin.name}/${rule.id}`;\n return { id, rule, severity: severityOf(corpus, id, rule.severity), options: plugin.options };\n }),\n ),\n ].filter((r) => r.severity !== 'off');\n\n const shared = analyse(corpus);\n const targets = options.only ?? corpus.briefs;\n const findings: Finding[] = [];\n for (const brief of targets) {\n for (const { id, rule, severity, options: ruleOptions } of active) {\n const results = await rule.check({\n brief,\n corpus,\n config: corpus.config,\n repoFiles: options.repoFiles ?? null,\n shared,\n options: ruleOptions,\n });\n for (const result of results) {\n const configured = severity as Severity;\n findings.push({\n rule: id,\n severity: result.severity === undefined ? configured : lower(result.severity, configured),\n message: result.message,\n file: brief.file,\n line: Math.max(1, Math.trunc(result.line)),\n brief: brief.id ?? undefined,\n hint: result.hint,\n });\n }\n }\n }\n return sortFindings(findings);\n}\n\n/** Strings by code unit, which is the same order on every host and in every locale. */\nfunction order(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function sortFindings(findings: readonly Finding[]): Finding[] {\n return [...findings].sort(\n (a, b) => order(a.file, b.file) || a.line - b.line || order(a.rule, b.rule) || order(a.message, b.message),\n );\n}\n\nexport interface Summary {\n readonly errors: number;\n readonly warnings: number;\n readonly notes: number;\n}\n\nexport function summarise(findings: readonly Finding[]): Summary {\n return {\n errors: findings.filter((f) => f.severity === 'error').length,\n warnings: findings.filter((f) => f.severity === 'warning').length,\n notes: findings.filter((f) => f.severity === 'note').length,\n };\n}\n\n/** Whether findings fail a run: any error, or any warning under `--strict`. */\nexport function failing(findings: readonly Finding[], strict: boolean): boolean {\n return findings.some((f) => f.severity === 'error' || (strict && f.severity === 'warning'));\n}\n"]}
1
+ {"version":3,"file":"lint.js","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAA4B,KAAK,EAAE,MAAM,YAAY,CAAC;AA4CtG,MAAM,IAAI,GAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEnF,SAAS,KAAK,CAAC,CAAW,EAAE,CAAW;IACrC,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,CAAC;AASD,0EAA0E;AAC1E,MAAM,UAAU,OAAO,CAAC,OAAO,GAAsB,EAAE;IACrD,OAAO;QACL,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzB,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI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,QAAQ,CAAC,CAAC,IAAI,CACvB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAC3G,CAAC;AACJ,CAAC;AAQD,MAAM,UAAU,SAAS,CAAC,QAA4B;IACpD,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,MAAM;QAC7D,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,MAAM;QACjE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,MAAM;KAC5D,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,QAA4B,EAAE,MAAe;IACnE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["/**\n * Running rules: severities from the configuration, plugins beside the\n * built-in rules, findings in a stable order.\n */\n\nimport type { Waiver } from './archive.js';\nimport type { Brief } from './brief.js';\nimport { ConfigError } from './config.js';\nimport type { Corpus } from './corpus.js';\nimport { analyse, ARCHIVE_RULES, COLLISION_RULES, type Rule, type RuleInfo, RULES } from './rules.js';\nimport type { Finding, Severity, SeveritySetting } from './types.js';\n\n/** What a plugin's `waive` hook is asked about: one archival, refused. */\nexport interface WaiveContext {\n /** The absolute root: the directory holding the configuration. */\n readonly root: string;\n readonly brief: { readonly id: string | null; readonly file: string; readonly text: string };\n /**\n * Every finding that refuses the archival, as a frozen copy: writing to it\n * throws, and the waivers are matched against the plan's own. A\n * `protected-file` finding names its `path`; an `out-of-scope` one lists its\n * `paths`. Only those two can be waived.\n */\n readonly findings: readonly Finding[];\n /** The base the round is measured from, as it was given; `null` when none was. */\n readonly base: string | null;\n /** The commit the round landed as; `null` when none was read. */\n readonly commit: string | null;\n}\n\nexport interface Plugin {\n /** Prefixes the plugin's rule ids: `<name>/<rule>`. */\n readonly name: string;\n readonly rules: readonly Rule[];\n /** The plugin's entry in the configuration, handed to each rule. */\n readonly options?: unknown;\n /**\n * Lifts refusals of an archival that the plugin's own check allows - a\n * protected file a verified ruling covers - by rule and path. Asked only\n * when the plan has a refusal it could lift. Returning nothing waives\n * nothing.\n */\n readonly waive?: ((context: WaiveContext) => readonly Waiver[] | void | Promise<readonly Waiver[] | void>) | undefined;\n}\n\nexport interface LintOptions {\n readonly plugins?: readonly Plugin[];\n /** Tracked files, for the rules that read the tree. */\n readonly repoFiles?: readonly string[] | null;\n /** Limit the findings to these briefs. The whole corpus is still read. */\n readonly only?: readonly Brief[];\n}\n\nconst RANK: Readonly<Record<Severity, number>> = { note: 0, warning: 1, error: 2 };\n\nfunction lower(a: Severity, b: Severity): Severity {\n return RANK[a] <= RANK[b] ? a : b;\n}\n\ninterface ActiveRule {\n readonly id: string;\n readonly rule: Rule;\n readonly severity: SeveritySetting;\n readonly options: unknown;\n}\n\n/** Every rule id a run knows: built-in, collision, archive and plugin. */\nexport function ruleIds(plugins: readonly Plugin[] = []): string[] {\n return [\n ...RULES.map((r) => r.id),\n ...COLLISION_RULES.map((r) => r.id),\n ...ARCHIVE_RULES.map((r) => r.id),\n ...plugins.flatMap((p) => p.rules.map((r) => `${p.name}/${r.id}`)),\n ];\n}\n\n/** The severity configuration assigns a rule, or its own. */\nexport function severityOf(corpus: Corpus, id: string, fallback: SeveritySetting): SeveritySetting {\n return corpus.config.rules[id] ?? fallback;\n}\n\n/** The severity of a built-in rule as configured, or `null` when it is off. */\nexport function configuredSeverity(corpus: Corpus, id: string): Severity | null {\n const rule = [...RULES, ...COLLISION_RULES, ...ARCHIVE_RULES].find((r) => r.id === id) as RuleInfo;\n const setting = severityOf(corpus, id, rule.severity);\n return setting === 'off' ? null : setting;\n}\n\n/** Refuses a configuration that names a rule nobody defines: a typo there silences nothing. */\nexport function checkRuleIds(corpus: Corpus, plugins: readonly Plugin[] = []): void {\n const known = new Set(ruleIds(plugins));\n const unknown = Object.keys(corpus.config.rules).filter((id) => !known.has(id));\n if (unknown.length > 0) {\n throw new ConfigError('configuration', unknown.map((id) => `\"rules.${id}\" names no rule`));\n }\n}\n\nexport async function lint(corpus: Corpus, options: LintOptions = {}): Promise<Finding[]> {\n const plugins = options.plugins ?? [];\n checkRuleIds(corpus, plugins);\n const active: ActiveRule[] = [\n ...RULES.map((rule) => ({ id: rule.id, rule, severity: severityOf(corpus, rule.id, rule.severity), options: undefined })),\n ...plugins.flatMap((plugin) =>\n plugin.rules.map((rule) => {\n const id = `${plugin.name}/${rule.id}`;\n return { id, rule, severity: severityOf(corpus, id, rule.severity), options: plugin.options };\n }),\n ),\n ].filter((r) => r.severity !== 'off');\n\n const shared = analyse(corpus);\n const targets = options.only ?? corpus.briefs;\n const findings: Finding[] = [];\n for (const brief of targets) {\n for (const { id, rule, severity, options: ruleOptions } of active) {\n const results = await rule.check({\n brief,\n corpus,\n config: corpus.config,\n repoFiles: options.repoFiles ?? null,\n shared,\n options: ruleOptions,\n });\n for (const result of results) {\n const configured = severity as Severity;\n findings.push({\n rule: id,\n severity: result.severity === undefined ? configured : lower(result.severity, configured),\n message: result.message,\n file: brief.file,\n line: Math.max(1, Math.trunc(result.line)),\n brief: brief.id ?? undefined,\n hint: result.hint,\n subject: result.subject,\n });\n }\n }\n }\n return sortFindings(findings);\n}\n\n/** Strings by code unit, which is the same order on every host and in every locale. */\nfunction order(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function sortFindings(findings: readonly Finding[]): Finding[] {\n return [...findings].sort(\n (a, b) => order(a.file, b.file) || a.line - b.line || order(a.rule, b.rule) || order(a.message, b.message),\n );\n}\n\nexport interface Summary {\n readonly errors: number;\n readonly warnings: number;\n readonly notes: number;\n}\n\nexport function summarise(findings: readonly Finding[]): Summary {\n return {\n errors: findings.filter((f) => f.severity === 'error').length,\n warnings: findings.filter((f) => f.severity === 'warning').length,\n notes: findings.filter((f) => f.severity === 'note').length,\n };\n}\n\n/** Whether findings fail a run: any error, or any warning under `--strict`. */\nexport function failing(findings: readonly Finding[], strict: boolean): boolean {\n return findings.some((f) => f.severity === 'error' || (strict && f.severity === 'warning'));\n}\n"]}
package/dist/report.d.ts CHANGED
@@ -38,10 +38,14 @@ export declare function sarif(findings: readonly Finding[], version: string): st
38
38
  /**
39
39
  * GitLab Code Quality: a JSON array of issues, which a merge request shows
40
40
  * beside the lines they are on. The fingerprint is how GitLab tells a new
41
- * issue from one it has seen, so it hashes the rule, the file and the message
42
- * and not the line: a finding that moves down a page is the same finding. Two
43
- * findings with the same three - a section duplicated twice - are told apart
44
- * by their order.
41
+ * issue from one it has seen, so it hashes the finding's identity and nothing
42
+ * that changes while the problem stays: not the line, so a finding that moves
43
+ * down a page is the same finding, and not the message, so rewording one, or
44
+ * naming another file two colliding briefs both write, does not show as one
45
+ * problem fixed and another found. Findings that share an identity - a front
46
+ * matter with two problems - are told apart by their order, the second hashed
47
+ * with a `2`, as spec-graph hashes them. The description carries the next
48
+ * action as well as the message.
45
49
  */
46
50
  export declare function gitlabCodeQuality(findings: readonly Finding[]): string;
47
51
  export declare function githubCommands(findings: readonly Finding[]): string;
@@ -53,6 +57,16 @@ export declare function briefJson(brief: Brief, extra?: Record<string, unknown>)
53
57
  * knows in advance.
54
58
  */
55
59
  export declare function sectionsJson(config: Config): Record<string, unknown>[];
60
+ /**
61
+ * A title as a table shows it, without the id it repeats: `new` writes
62
+ * `# 012 — Rotate tokens`, and the table has an id column already. Only the
63
+ * brief's own id comes off, compared as ids are, so that `12 - x` in brief
64
+ * `012` loses it and `0010 — x` in brief `001` keeps it, and only before a
65
+ * separator: `Fix - the login bug` and `2026:roadmap` are titles. For
66
+ * display alone: `Brief.title`, and every JSON document, keep the title as
67
+ * written.
68
+ */
69
+ export declare function titleWithoutId(title: string, id: string | null): string;
56
70
  export interface ListRow {
57
71
  readonly brief: Brief;
58
72
  readonly ready: boolean;