@descent-vtt/spec-graph 0.4.0 → 0.5.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,258 @@
3
3
  Notable changes, newest first. Versions follow [semver](https://semver.org):
4
4
  a patch fixes behaviour without asking anything of a repository that upgrades.
5
5
 
6
+ ## 0.5.0
7
+
8
+ One shipped feature turned out to have shipped a false positive, and the
9
+ predicate that was documented as dangerous is now an automaton that cannot
10
+ backtrack. Four of the ADR suite's open questions answered by building the
11
+ thing, seven directions declined with a reason, one deferred with its design
12
+ settled so it is not re-litigated.
13
+
14
+ ### Fixed
15
+
16
+ **A register's decisions answer for the front matter above them.** This was a
17
+ false positive in the feature 0.4.0 led with, and the worst kind: confident and
18
+ unanswerable. A region answered *nothing* for `fm.owner`, `!=` against an absent
19
+ value is a mismatch, so a repository writing
20
+
21
+ ```json
22
+ "rules": { "owned": { "query": "document[fm.owner!=platform]" } }
23
+ ```
24
+
25
+ was told twice that a register saying `owner: platform` is not owned by
26
+ platform — with the message rendering `{0.fm.owner}` as the literal placeholder,
27
+ because there was nothing to put there.
28
+
29
+ A region now carries its file's front matter minus two kinds of key. A
30
+ **relation** key stays behind: `supersedes:` at the top of a register supersedes
31
+ on behalf of the register, not of each decision in it. So does a key the region
32
+ **answers for itself** — its identifier, status, title and aliases, which are
33
+ precisely the things a register exists to vary row by row.
34
+ [ADR-0009](docs/adr/0009-a-specification-is-a-region.md) carried this as a
35
+ narrowed open question and called it a gap. It was a defect, and it was found by
36
+ pointing the binary at a register rather than by reading the code.
37
+
38
+ Read from the other side, this can *add* findings: a rule phrased positively,
39
+ `document[fm.deprecated]`, now matches a register's decisions as well as the
40
+ register. That is the same correction - the decisions really are described by
41
+ the front matter above them - and worth knowing before upgrading a repository
42
+ that keeps registers and writes rules about front matter.
43
+
44
+ ### Added
45
+
46
+ **`~=` is matched by an automaton that cannot backtrack.**
47
+ [ADR-0016](docs/adr/0016-a-query-needs-a-sentence.md) documented this hazard
48
+ with `(a+)+$`, which nobody writes, and priced the fix at "worth it only if a
49
+ real repository hangs". Both were wrong. `^([A-Za-z0-9_]+[ ]?)+$` is what
50
+ somebody writes to check that a title is words separated by single spaces:
51
+
52
+ | subject | `RegExp` | now |
53
+ | --- | ---: | ---: |
54
+ | `the quick brown fox jumps over the lazy dog!` | 0.9s | 11us |
55
+ | `... over the lazy dog and!` | 5.4s | 12us |
56
+ | `... over the lazy dog and keeps!` | 103s | 13us |
57
+
58
+ A word of k letters can be cut into pieces 2^(k-1) ways and a backtracking
59
+ engine tries the product, so a sixty-character title does not finish this year —
60
+ unattended, on every build, against a corpus whose titles the author of the rule
61
+ has not read. The work is now exactly O(pattern x subject), and **no stage of
62
+ this pipeline can take longer than its input.**
63
+
64
+ It costs a dialect. Backreferences and lookaround are not regular, so they are
65
+ refused while the selector is read, with the character pointed at — as are three
66
+ things `RegExp` accepts and should not: an unknown letter escape, which `RegExp`
67
+ reads as the letter, so a pattern meant as an anchor silently matches a capital
68
+ A; a Unicode property escape, which needs a table this package will not carry;
69
+ and octal escapes. Everything else works, and a pattern that does not parse is
70
+ now a usage error rather than a pattern that silently matches nothing.
71
+
72
+ Verified against the engine it replaces: **1.33 million pattern-subject pairs,
73
+ zero disagreements**, 19,000 of them committed as a gate. It earned that twice
74
+ over, on one clause of the language specification read backwards in two
75
+ different places - the word characters `` recognises, and whether a character
76
+ whose upper case is ASCII may match `[A-Z]`. The second was found by the
77
+ mutation score pointing at a corpus with a blind spot in it rather than at a
78
+ test. See [ADR-0017](docs/adr/0017-a-predicate-must-finish.md) and
79
+ [ADR-0007](docs/adr/0007-mutation-testing.md).
80
+
81
+ **Configuration is discovered upward, and the file holding it is the root.**
82
+
83
+ ```bash
84
+ cd packages/auth && spec-graph check # the repository's rules, the
85
+ # repository's patterns, the
86
+ # repository's paths
87
+ ```
88
+
89
+ [ADR-0010](docs/adr/0010-configuration-belongs-to-the-repository.md) worried
90
+ that discovery would make a run depend on where it started. Reading the working
91
+ directory already did, and silently: a check from a package directory found no
92
+ configuration, ran no project rules, used the default include patterns, and
93
+ printed a verdict in the same shape as the real one. Because the directory
94
+ holding the file becomes the root, and every path here is relative to the root,
95
+ a run from anywhere inside the repository now produces **byte-identical** output
96
+ to a run from the top. The walk stops at the repository — a directory holding
97
+ `.git` — so a stray file in a home directory cannot reach it. `--root` names the
98
+ root yourself and turns discovery off, and a path typed on the command line
99
+ stays relative to where you typed it. See
100
+ [ADR-0018](docs/adr/0018-the-configuration-file-is-the-root.md).
101
+
102
+ **`spec-graph query project:<rule>` runs a registered rule by name.** The rule
103
+ is already compiled by the time the command runs, and the alternative was
104
+ copying its selector back out of the configuration file by hand. Several
105
+ selectors are deduped the way the check dedupes them, so this prints the set the
106
+ check reports on; `--verbose` names them, which is the question a team
107
+ calibrating a convention is actually asking. Built-in rules are deliberately not
108
+ addressable this way: a project rule *is* its selector, while a built-in is a
109
+ selector plus judgement, and printing a set that differs from the findings would
110
+ invite the wrong conclusion.
111
+
112
+ **`spec-graph rules <rule-id> --explain` names the ADR that decided it.** A rule
113
+ that fires is a claim about somebody's repository, and the reasoning behind the
114
+ claim was in a document nobody could find from the message. The table holds a
115
+ pointer rather than a paraphrase, because a second copy of the reasoning would
116
+ drift from the first — and a test holds every pointer to a file this corpus
117
+ checks, so a renamed ADR breaks the link in the same run that breaks the
118
+ reference.
119
+
120
+ **`--format markdown`** writes the same facts as a GitHub-flavoured table, for
121
+ `$GITHUB_STEP_SUMMARY` or a pull-request comment:
122
+
123
+ ```yaml
124
+ - run: npx spec-graph --format markdown >> "$GITHUB_STEP_SUMMARY"
125
+ ```
126
+
127
+ SARIF puts a finding on the line that caused it, which is where somebody fixing
128
+ one wants it, and says nothing at all to the person deciding whether to merge.
129
+ This leads with the verdict, counts the corpus, gives every finding its hint,
130
+ and *names* the stale baseline entries rather than counting them — on a pull
131
+ request a count is the one thing a reader cannot act on. No environment
132
+ detection: a format that changed because a variable was set would be a format
133
+ nobody controls.
134
+
135
+ ### Changed
136
+
137
+ Four behaviours move, none of them a rule. Three can turn a run that passed
138
+ into a usage error, which is the point in each case; the fourth changes what a
139
+ run from a subdirectory reports.
140
+
141
+ - **A `~=` pattern that does not parse is a usage error**, with the character
142
+ pointed at, rather than a pattern that matches nothing. The old silence was
143
+ indistinguishable from a rule that ran and found none.
144
+ - **A `~=` pattern using a backreference, lookaround, `\p{...}`, an octal
145
+ escape or an unknown letter escape is refused**, for the reasons above. If
146
+ you have one, the message says which construct and why; `^=`, `$=` and `*=`
147
+ cover the fixed-prefix, suffix and substring cases without a pattern at all.
148
+ - **A run from a subdirectory now finds the repository's configuration**, and
149
+ reports repository-relative paths because the configuration's directory is
150
+ the root. A script that read paths out of a nested run will see them change.
151
+ `--root` keeps the old behaviour exactly.
152
+ - **`spec-graph rules <word>` reads the word as a rule id** and reports one
153
+ that names nothing. It used to be collected as an include pattern, which the
154
+ command has no use for.
155
+
156
+ ### Declined
157
+
158
+ Each with its reasoning in the ADR that owns the question, rather than in a
159
+ roadmap nobody reads:
160
+
161
+ - **An MCP server.** The capability is already here — `analyseSources()` takes
162
+ text, `--format json` is the answer — so what is left is a protocol
163
+ implementation, hand-written to keep the dependency count at zero, tracking a
164
+ specification that is still moving, to expose three tools that are three shell
165
+ commands an agent can already run.
166
+ - **A language server.** The right shape for editor feedback and a second
167
+ package's worth of work, and SARIF already reaches the problems pane. Two of
168
+ the three hard parts are done — `analyseSources()` needs no file on disk, and
169
+ every finding carries a span — so it should start when somebody wants hover
170
+ and go-to-definition, not as a way of delivering diagnostics that already
171
+ arrive.
172
+ - **A `--watch` daemon.** Declined again, with a better reason than last time:
173
+ the incremental half of it cannot work. Whether a bare `ADR-0099` in prose is
174
+ a citation depends on which families exist elsewhere, and a near-miss
175
+ suggestion is computed against every sibling — touch one file and the honest
176
+ set to recompute is all of them. Which is fine, because the pipeline is a pure
177
+ function and 60 ms long. And then the resident index buys nothing, and the
178
+ feature is a loop.
179
+ - **Code frames in the terminal.** The report already prints
180
+ `file:line:column`, which every terminal in use turns into a click, and
181
+ `renderMatch` already prints the shape of a multi-hop path.
182
+ - **Provenance and attestation metadata.** A timestamp in the output means no
183
+ two reports of one corpus are ever byte-identical, which is the property every
184
+ format here is built to have. The commit is something CI already knows.
185
+ - **An interactive SVG.** A layout engine or a vendored library is a runtime
186
+ dependency wherever it sits in the tarball, and its bytes depend on a layout
187
+ pass. `dot` and `mermaid` hand layout to tools built for it, and both are
188
+ text. The other half of that ask - phase styling and typed edges in the
189
+ Mermaid export - has been there since the first release. What is left is a
190
+ `subgraph` per directory, which changes the shape of an export somebody's
191
+ documentation build is parsing, to group a corpus that is one directory in
192
+ most repositories.
193
+ - **Definition lists as a register form.** Two unrelated syntaxes behind one
194
+ name: raw `<dl>`, which the scanner leaves as prose deliberately because
195
+ ADR-0001's masking guarantee is what keeps a code fence quiet, and the
196
+ PHP-Markdown-Extra form, which is not CommonMark and which no corpus here
197
+ contains. Either would need a new parser for a convention nobody has written
198
+ down.
199
+
200
+ One is deferred rather than declined, with half its design recorded so it is not
201
+ re-litigated: a **relational diff** between two states of the graph, taken
202
+ between two `--graph-format json` exports rather than between two git revisions,
203
+ because revisions mean spawning a binary underneath a pipeline that is a pure
204
+ function of text. See
205
+ [ADR-0015](docs/adr/0015-feedback-goes-where-the-tools-already-look.md).
206
+
207
+ ### Verified
208
+
209
+ | | |
210
+ |---|---|
211
+ | `npm run lint` | pass |
212
+ | `npm test` | 833 passing, 21 files |
213
+ | `npm run selfcheck` | pass, over 21 documents and 159 relations |
214
+ | `npm run test:mutation` | 80.54% over 9,697 mutants, 74m27s |
215
+ | hosted full run, which governs | **76.83%**, 168m06s |
216
+ | hosted incremental run, same commit | 76.43%, 64m27s |
217
+ | `break` | unchanged at 70 |
218
+
219
+ 79.41% over 8,585 mutants at 0.4.0 against 80.54% over 9,697 here, on the same
220
+ machine: 1,112 more mutants and a point higher. The new code carries itself -
221
+ `regex.ts` at **90.61%**, `config.ts` at 92.37%, `project-rules.ts` still at
222
+ 99.50% - and lose all 343 timeouts and the figure reads 77.00%.
223
+
224
+ The first full run of this release read 80.35%, and its survivor list is where
225
+ the last defect came from. A mutant on the line stepping past `^` in a negated
226
+ class survived 1.33 million differential comparisons, because the corpus only
227
+ ever tested classes against two-character subjects; one-character subjects
228
+ killed it and then caught `[A-Z]` matching U+017F. `report.ts` went from 66.30%
229
+ to 70.84% on the same pass, once the Markdown tests asserted the table's
230
+ structure - rectangular rows, a blank line before every block, every summary
231
+ number present - rather than fragments of its text. What remains there is
232
+ mostly the older formatters.
233
+
234
+ Between those two runs `rules.ts` moved from 79.42% to 76.02% and
235
+ `directives.ts` from 77.92% to 74.03%, with neither file touched: the tests added
236
+ in between changed which tests `perTest` believes cover which mutants.
237
+ [ADR-0007](docs/adr/0007-mutation-testing.md) has recorded that shape for two
238
+ releases, and it is why a per-file drop is a question and not an answer.
239
+
240
+ The hosted number is the one that governs, because it is where the build fails:
241
+ **76.83%**, up from 75.40% at 0.4.0. Lose every timeout and it reads 73.31%, the
242
+ first time the pessimistic figure has cleared the guard by more than three
243
+ points.
244
+
245
+ The incremental run on the same commit read 0.40 points low - the third
246
+ observation after 3.18 high at 0.3.0 and 1.29 low at 0.4.0, and the reason
247
+ [ADR-0007](docs/adr/0007-mutation-testing.md) calls it a signal rather than a
248
+ figure. The tag's run also saved its own report to the cache, which is the first
249
+ time the cache-key fix from 0.4.0 has been seen doing its job.
250
+
251
+ **The rebuild took 168 of its 180 minutes.** 13% more mutants than 0.4.0, and 63%
252
+ longer on the hosted runner against 15% longer locally. At 0.4.0's old cap of
253
+ 120 it would have been cancelled with nothing reported. The cause is not yet
254
+ attributed - runner variance and the new differential test are both candidates -
255
+ and the choice between raising the cap again and cutting per-mutant cost is left
256
+ open in ADR-0007 until it is.
257
+
6
258
  ## 0.4.0
7
259
 
8
260
  Ten open questions across the ADR suite, answered. Five shipped, three declined
package/README.md CHANGED
@@ -386,6 +386,19 @@ Items inherit their document's lifecycle, so `item[phase=retired]` means what yo
386
386
  expect. A query evaluates to **paths**, not endpoints, which is why a finding can
387
387
  name both ends and the line that connects them.
388
388
 
389
+ `~=` is a regular expression matched by an automaton that cannot backtrack, so a
390
+ predicate is linear in the subject whatever the pattern — `^([A-Za-z0-9_]+[ ]?)+$`
391
+ against a fifty-four-character title takes `RegExp` 103 seconds and this 13
392
+ microseconds. It reads the usual syntax minus backreferences and lookaround,
393
+ which are not regular; both are refused when the selector is read, with the
394
+ character pointed at. See [ADR-0017](docs/adr/0017-a-predicate-must-finish.md).
395
+
396
+ On a register, a region answers its file's front matter for every descriptive
397
+ key — `fm.owner` on a decision inside a register is the register's owner — while
398
+ the keys a region owns itself, its identifier and status and title, and any key
399
+ that declares a relation, stay on the file. See
400
+ [ADR-0009](docs/adr/0009-a-specification-is-a-region.md).
401
+
389
402
  ## Your own rules
390
403
 
391
404
  A convention spec-graph never anticipated is a selector plus a sentence. Write
@@ -432,6 +445,12 @@ escalated by `--strict`, listed by `spec-graph rules`, exempted on journals like
432
445
  every other rule about obligations, and emitted as a first-class `ruleId` in
433
446
  SARIF, where a project rule describes itself by the selector it is.
434
447
 
448
+ To see what a rule matches without copying its selector back out of the file:
449
+
450
+ ```bash
451
+ spec-graph query project:no-draft-dependency --verbose
452
+ ```
453
+
435
454
  Mistakes are reported when the file is read, not discovered as a rule that
436
455
  quietly finds nothing:
437
456
 
@@ -594,6 +613,14 @@ command. spec-graph reads the first of `.spec-graph.json`,
594
613
  }
595
614
  ```
596
615
 
616
+ The file is looked for in the working directory and then upward, as far as the
617
+ repository — a directory holding `.git` — and **the directory holding it becomes
618
+ the root**. So a run from `packages/auth` reports what a run from the top
619
+ reports, byte for byte, because every path here is relative to the root. The
620
+ nearest file wins, `--root` names the root yourself and turns discovery off, and
621
+ a path typed on the command line stays relative to where you typed it. See
622
+ [ADR-0018](docs/adr/0018-the-configuration-file-is-the-root.md).
623
+
597
624
  A flag always wins over the file, and list flags **add** to it rather than
598
625
  replacing it — a `--ignore-ref` on the command line is one more exclusion, not a
599
626
  decision to discard what the repository already declared. `--verbose` prints
@@ -644,10 +671,14 @@ already exists in the corpus.
644
671
  ```text
645
672
  spec-graph [check] [patterns...] Validate the graph. The default.
646
673
  spec-graph query <selector> Run a selector, print matching paths.
674
+ spec-graph query project:<rule> Run a registered rule by its id.
647
675
  spec-graph graph [patterns...] Export for Graphviz, Mermaid or JSON.
648
- spec-graph rules [--explain] List the diagnostics.
676
+ spec-graph rules [rule-id] List the diagnostics; --explain adds
677
+ each selector and the ADR behind it.
649
678
 
650
- --root <dir> Directory patterns resolve against
679
+ --root <dir> Directory patterns resolve against, and the root of the
680
+ run. Without it the config file is discovered upward and
681
+ its directory is the root
651
682
  --ignore <glob> Skip paths (repeatable)
652
683
  --ignore-ref <glob> Do not report these reference targets (repeatable)
653
684
  --family <name> Families a bare identifier may name (repeatable)
@@ -657,7 +688,7 @@ spec-graph rules [--explain] List the diagnostics.
657
688
  --record-baseline <f> Write today's findings as accepted debt, exit 0
658
689
  --ratchet Also fail when a baseline entry no longer occurs
659
690
  --no-config Ignore .spec-graph.json and the package.json key
660
- --format <fmt> human | json | sarif
691
+ --format <fmt> human | json | sarif | markdown
661
692
  --graph-format <fmt> dot | mermaid | json
662
693
  --documents-only Hide items; their relations lift onto their documents
663
694
  --rule <id>=<severity> error | warn | info | off (repeatable)
@@ -680,6 +711,19 @@ rather than a silent success.
680
711
  run: npx spec-graph "docs/**/*.md" --format json > spec-graph.json
681
712
  ```
682
713
 
714
+ `--format markdown` writes the same facts as a table, for the place reviewers
715
+ actually look:
716
+
717
+ ```yaml
718
+ - name: Summarise the specification graph
719
+ if: always()
720
+ run: npx spec-graph --format markdown >> "$GITHUB_STEP_SUMMARY"
721
+ ```
722
+
723
+ It leads with the verdict, counts the corpus, gives every finding its hint, and
724
+ *names* the baseline entries that no longer occur rather than counting them —
725
+ on a pull request a count is the one thing a reader cannot act on.
726
+
683
727
  The JSON report is versioned, flat, and carries start and end positions for
684
728
  every finding, so a bot can annotate a diff:
685
729
 
@@ -739,7 +783,7 @@ exported. Reporters, editor extensions and custom rules are all first-class.
739
783
 
740
784
  ## Design
741
785
 
742
- Twelve ADRs, which `spec-graph` validates on every CI run:
786
+ Eighteen ADRs, which `spec-graph` validates on every CI run:
743
787
 
744
788
  - [ADR-0001 — A hand-written Markdown scanner](docs/adr/0001-hand-written-markdown-scanner.md)
745
789
  - [ADR-0002 — A four-phase lifecycle lattice](docs/adr/0002-lifecycle-lattice.md)
@@ -756,11 +800,16 @@ Twelve ADRs, which `spec-graph` validates on every CI run:
756
800
  - [ADR-0013 — When the scanner is unsure, it hands back prose](docs/adr/0013-the-scanner-hands-back-prose.md)
757
801
  - [ADR-0014 — A relation is spelled in both directions](docs/adr/0014-a-relation-is-spelled-both-ways.md)
758
802
  - [ADR-0015 — Feedback goes where the tools already look](docs/adr/0015-feedback-goes-where-the-tools-already-look.md)
803
+ - [ADR-0016 — A query needs a sentence before it is a rule](docs/adr/0016-a-query-needs-a-sentence.md)
804
+ - [ADR-0017 — A predicate must finish](docs/adr/0017-a-predicate-must-finish.md)
805
+ - [ADR-0018 — The configuration file is the root](docs/adr/0018-the-configuration-file-is-the-root.md)
759
806
 
760
807
  **Zero runtime dependencies.** Node 22+, native ESM, TypeScript strict with
761
808
  `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes`. The Markdown
762
- scanner, the front-matter reader, the glob matcher and the query parser are all
763
- written here, so the whole package is auditable in an afternoon.
809
+ scanner, the front-matter reader, the glob matcher, the query parser and the
810
+ regular-expression matcher behind `~=` are all written here, so the whole
811
+ package is auditable in an afternoon — and nothing in the pipeline can take
812
+ longer than its input.
764
813
 
765
814
  **Verified, not just covered.** 411 tests; 94.2% statement and 96.9% line
766
815
  coverage. Coverage says a line ran, so the suite is also held to a mutation
package/dist/cli.d.ts CHANGED
@@ -21,6 +21,14 @@ export interface CliOptions {
21
21
  readonly command: Command;
22
22
  readonly patterns: readonly string[];
23
23
  readonly root: string;
24
+ /**
25
+ * Whether `--root` was given.
26
+ *
27
+ * When it was, the caller has named the root and configuration is read from
28
+ * exactly there. When it was not, the root is discovered - which is a
29
+ * different question from what the root currently is. See ADR-0018.
30
+ */
31
+ readonly rootExplicit: boolean;
24
32
  readonly ignore: readonly string[];
25
33
  /** Reference targets to leave unreported when they do not resolve. */
26
34
  readonly ignoreReferences: readonly string[];
@@ -45,7 +53,7 @@ export interface CliOptions {
45
53
  readonly ratchet: boolean;
46
54
  /** Skip the repository configuration file entirely. */
47
55
  readonly noConfig: boolean;
48
- readonly format: 'human' | 'json' | 'sarif';
56
+ readonly format: 'human' | 'json' | 'sarif' | 'markdown';
49
57
  readonly graphFormat: GraphFormat;
50
58
  readonly severities: Partial<Record<AnyRuleId, Severity>>;
51
59
  readonly color: boolean | null;
@@ -68,7 +76,7 @@ export interface CliIO {
68
76
  readonly env?: Readonly<Record<string, string | undefined>> | undefined;
69
77
  readonly isTTY?: boolean | undefined;
70
78
  }
71
- export declare const HELP = "spec-graph - turn Markdown specifications into a verifiable graph\n\nUSAGE\n spec-graph [check] [patterns...] [options]\n spec-graph query <selector> [patterns...] [options]\n spec-graph graph [patterns...] [--graph-format dot|mermaid|json]\n spec-graph rules [--explain]\n\nCOMMANDS\n check Validate the specification graph. The default.\n query Run a selector and print the matching paths.\n graph Export the graph for Graphviz, Mermaid, or another tool.\n rules List the diagnostics that will run, built in and project.\n\nOPTIONS\n --root <dir> Directory the patterns resolve against (default: cwd)\n --ignore <glob> Skip paths. Repeatable.\n --ignore-ref <glob> Do not report these reference targets when they fail\n to resolve, for repositories where [[...]] tags a\n concept rather than naming a file. Repeatable.\n Suppresses findings only, never edges.\n --family <name> Families a bare identifier in prose may name. When\n given, everything else stays prose. Repeatable.\n --ignore-family <name> Families that are never citations - RFC when the repo\n cites RFC 2119 and keeps its own RFCs. Repeatable.\n --history <glob> Files that log what was decided rather than deciding\n it - journals, changelogs, minutes. Their links are\n still checked; their obligations are not. Repeatable.\n --baseline <file> Accept the findings recorded in this file and report\n only what is new since. Missing file = accept nothing.\n --record-baseline <f> Write today's findings to this file as accepted debt,\n and exit 0 without judging them.\n --ratchet Also fail when a baseline entry no longer occurs, so\n a paid-off exemption cannot outlive the defect.\n --no-config Ignore .spec-graph.json and the package.json key.\n --format <fmt> human, json, or sarif - the interchange format\n GitHub code scanning and editors already read\n (default: human)\n --graph-format <fmt> dot, mermaid or json (default: dot)\n --documents-only Leave items out of the exported graph\n --rule <id>=<severity> Override one rule: error, warn, info or off. A project\n rule is named in full: project:no-draft-dependency.\n Repeatable.\n --max <n> Show at most n findings (0 = no limit)\n --max-warnings <n> Fail when warnings exceed n (default: no limit)\n --strict Raise every warning to an error. An explicit --rule\n still wins, so --strict --rule x=warn exempts x.\n --color / --no-color Force colour on or off\n --ascii Use ASCII glyphs only\n --verbose Include parse problems, per-file detail, and every\n reference --ignore-ref or --ignore-family silenced\n -h, --help Show this help\n -v, --version Show the version\n\nSELECTORS\n A selector is a path through the graph.\n\n item[openness=open] -delegates-to-> document[phase=retired]\n document[phase=active] -assumes-> document[phase=retired]\n document =supersedes=> document\n *[path^=docs/adr] -contains-> item[state=accepted-debt]\n\n Node types: document, item, * (any)\n Attributes: id, kind, title, path, file, line, phase, status, receptivity,\n alias, document, state (or disposition), openness, section,\n text, body, evidence, conflicted, fm.<front-matter-key>\n Operators: = != ^= $= *= ~= and [attr] for \"is present\"\n ~= is a JavaScript regular expression, run once per node; ^= $=\n and *= cover most cases and cannot backtrack\n Relations: -kind-> <-kind- =kind=> <=kind= (= forms are transitive)\n\nEXIT CODES\n 0 clean\n 1 findings at error severity (or over --max-warnings)\n 2 the tool could not run\n\nCONFIGURATION\n Anything repeated on every run belongs in the repository rather than in the\n command. spec-graph reads the first of these that exists:\n\n .spec-graph.json, spec-graph.config.json, or a \"spec-graph\" key in\n package.json\n\n { \"patterns\": [\"docs/**/*.md\"],\n \"ignoreReferences\": [\"trap *\"],\n \"ignoreFamilies\": [\"RFC\"],\n \"historyPatterns\": [\"**/JOURNAL_*.md\", \"archive/**\"],\n \"baseline\": \".spec-graph-baseline.json\",\n \"severities\": { \"self-reference\": \"off\" },\n \"strict\": true }\n\n A flag always wins over the file, and list flags add to it rather than\n replacing it.\n\nPROJECT RULES\n A convention spec-graph never anticipated is a selector plus a sentence, and\n belongs in the same file. Every rule declared here runs beside the built-ins\n and is reported, baselined, escalated by --strict and silenced by --rule in\n exactly the same way.\n\n { \"rules\": {\n \"no-draft-dependency\": {\n \"query\": \"document[phase=active] -depends-on-> document[phase=draft]\",\n \"message\": \"{0} depends on {1}, which is still a draft\",\n \"hint\": \"wait for {1} to be accepted, or drop it from {0.path}\",\n \"severity\": \"error\" } } }\n\n query One selector, or a list of them read as a union.\n message The headline. {0} is the first node on the path, {1} the next;\n {1.phase} and {0.fm.owner} read any selector attribute.\n hint The next action. Optional, and templated the same way.\n severity error, warn, info or off. Defaults to warn - a rule a team has\n just written has not yet earned the right to fail their build.\n\n The id is the name with project: in front, which is why it can never collide\n with a built-in. A selector that does not parse, or a {2} the query can never\n reach, is reported when the file is read rather than found missing later.\n\nADOPTING THIS ON AN OLD REPOSITORY\n Record what is already wrong, then report only what happens next:\n\n spec-graph check --record-baseline .spec-graph-baseline.json\n git add .spec-graph-baseline.json\n\n The file is keyed by specification and citation, not by line number, so it\n survives edits, moves and renames. Findings that stop occurring are reported\n so the file can be tightened; nothing new gets in.\n\nEXAMPLES\n spec-graph \"docs/**/*.md\"\n spec-graph check --rule self-reference=off --format json\n spec-graph query 'item[openness=open] -delegates-to-> document[phase=retired]'\n spec-graph check --ignore-ref \"trap *\" # [[trap 55]] tags a concept, not a file\n spec-graph graph --documents-only --graph-format mermaid > graph.mmd\n spec-graph check --history \"**/JOURNAL_*.md\" # a log is not a specification\n spec-graph check --baseline .spec-graph-baseline.json\n spec-graph rules --explain # including this repository's own\n spec-graph check --rule project:no-draft-dependency=off\n";
79
+ export declare const HELP = "spec-graph - turn Markdown specifications into a verifiable graph\n\nUSAGE\n spec-graph [check] [patterns...] [options]\n spec-graph query <selector|project:rule> [patterns...] [options]\n spec-graph graph [patterns...] [--graph-format dot|mermaid|json]\n spec-graph rules [rule-id] [--explain]\n\nCOMMANDS\n check Validate the specification graph. The default.\n query Run a selector - or a registered project rule, by its id - and\n print the matching paths.\n graph Export the graph for Graphviz, Mermaid, or another tool.\n rules List the diagnostics that will run, built in and project. Name one\n to see only that one; --explain adds its selector and the ADR that\n decided it.\n\nOPTIONS\n --root <dir> Directory the patterns resolve against. Without it,\n .spec-graph.json is looked for in the working\n directory and then upward as far as the repository,\n and the directory holding it becomes the root - so a\n run from a subdirectory reports what a run from the\n top reports. Paths typed on the command line stay\n relative to where they were typed.\n --ignore <glob> Skip paths. Repeatable.\n --ignore-ref <glob> Do not report these reference targets when they fail\n to resolve, for repositories where [[...]] tags a\n concept rather than naming a file. Repeatable.\n Suppresses findings only, never edges.\n --family <name> Families a bare identifier in prose may name. When\n given, everything else stays prose. Repeatable.\n --ignore-family <name> Families that are never citations - RFC when the repo\n cites RFC 2119 and keeps its own RFCs. Repeatable.\n --history <glob> Files that log what was decided rather than deciding\n it - journals, changelogs, minutes. Their links are\n still checked; their obligations are not. Repeatable.\n --baseline <file> Accept the findings recorded in this file and report\n only what is new since. Missing file = accept nothing.\n --record-baseline <f> Write today's findings to this file as accepted debt,\n and exit 0 without judging them.\n --ratchet Also fail when a baseline entry no longer occurs, so\n a paid-off exemption cannot outlive the defect.\n --no-config Ignore .spec-graph.json and the package.json key.\n --format <fmt> human, json, sarif or markdown. sarif is the\n interchange format GitHub code scanning and editors\n already read; markdown is a table for a pull-request\n comment or $GITHUB_STEP_SUMMARY (default: human)\n --graph-format <fmt> dot, mermaid or json (default: dot)\n --documents-only Leave items out of the exported graph\n --rule <id>=<severity> Override one rule: error, warn, info or off. A project\n rule is named in full: project:no-draft-dependency.\n Repeatable.\n --max <n> Show at most n findings (0 = no limit)\n --max-warnings <n> Fail when warnings exceed n (default: no limit)\n --strict Raise every warning to an error. An explicit --rule\n still wins, so --strict --rule x=warn exempts x.\n --color / --no-color Force colour on or off\n --ascii Use ASCII glyphs only\n --verbose Include parse problems, per-file detail, and every\n reference --ignore-ref or --ignore-family silenced\n -h, --help Show this help\n -v, --version Show the version\n\nSELECTORS\n A selector is a path through the graph.\n\n item[openness=open] -delegates-to-> document[phase=retired]\n document[phase=active] -assumes-> document[phase=retired]\n document =supersedes=> document\n *[path^=docs/adr] -contains-> item[state=accepted-debt]\n\n Node types: document, item, * (any)\n Attributes: id, kind, title, path, file, line, phase, status, receptivity,\n alias, document, state (or disposition), openness, section,\n text, body, evidence, conflicted, fm.<front-matter-key>\n Operators: = != ^= $= *= ~= and [attr] for \"is present\"\n ~= is a regular expression, matched by an automaton that cannot\n backtrack: linear in the subject, whatever the pattern. It reads\n the usual syntax minus backreferences and lookaround, which are\n not regular - both are refused when the selector is read, with\n the character pointed at\n Relations: -kind-> <-kind- =kind=> <=kind= (= forms are transitive)\n\nEXIT CODES\n 0 clean\n 1 findings at error severity (or over --max-warnings)\n 2 the tool could not run\n\nCONFIGURATION\n Anything repeated on every run belongs in the repository rather than in the\n command. spec-graph reads the first of these that exists:\n\n .spec-graph.json, spec-graph.config.json, or a \"spec-graph\" key in\n package.json\n\n { \"patterns\": [\"docs/**/*.md\"],\n \"ignoreReferences\": [\"trap *\"],\n \"ignoreFamilies\": [\"RFC\"],\n \"historyPatterns\": [\"**/JOURNAL_*.md\", \"archive/**\"],\n \"baseline\": \".spec-graph-baseline.json\",\n \"severities\": { \"self-reference\": \"off\" },\n \"strict\": true }\n\n A flag always wins over the file, and list flags add to it rather than\n replacing it.\n\nPROJECT RULES\n A convention spec-graph never anticipated is a selector plus a sentence, and\n belongs in the same file. Every rule declared here runs beside the built-ins\n and is reported, baselined, escalated by --strict and silenced by --rule in\n exactly the same way.\n\n { \"rules\": {\n \"no-draft-dependency\": {\n \"query\": \"document[phase=active] -depends-on-> document[phase=draft]\",\n \"message\": \"{0} depends on {1}, which is still a draft\",\n \"hint\": \"wait for {1} to be accepted, or drop it from {0.path}\",\n \"severity\": \"error\" } } }\n\n query One selector, or a list of them read as a union.\n message The headline. {0} is the first node on the path, {1} the next;\n {1.phase} and {0.fm.owner} read any selector attribute.\n hint The next action. Optional, and templated the same way.\n severity error, warn, info or off. Defaults to warn - a rule a team has\n just written has not yet earned the right to fail their build.\n\n The id is the name with project: in front, which is why it can never collide\n with a built-in. A selector that does not parse, or a {2} the query can never\n reach, is reported when the file is read rather than found missing later.\n\n To see what one matches without copying its selector out of the file:\n\n spec-graph query project:no-draft-dependency --verbose\n\nADOPTING THIS ON AN OLD REPOSITORY\n Record what is already wrong, then report only what happens next:\n\n spec-graph check --record-baseline .spec-graph-baseline.json\n git add .spec-graph-baseline.json\n\n The file is keyed by specification and citation, not by line number, so it\n survives edits, moves and renames. Findings that stop occurring are reported\n so the file can be tightened; nothing new gets in.\n\nEXAMPLES\n spec-graph \"docs/**/*.md\"\n spec-graph check --rule self-reference=off --format json\n spec-graph query 'item[openness=open] -delegates-to-> document[phase=retired]'\n spec-graph check --ignore-ref \"trap *\" # [[trap 55]] tags a concept, not a file\n spec-graph graph --documents-only --graph-format mermaid > graph.mmd\n spec-graph check --history \"**/JOURNAL_*.md\" # a log is not a specification\n spec-graph check --baseline .spec-graph-baseline.json\n spec-graph rules --explain # including this repository's own\n spec-graph rules ghost-handover --explain # and why it exists\n spec-graph check --rule project:no-draft-dependency=off\n spec-graph query project:no-draft-dependency # what does that rule match?\n spec-graph check --format markdown >> \"$GITHUB_STEP_SUMMARY\"\n";
72
80
  /** Parses argv into options. Throws {@link UsageError} on anything malformed. */
73
81
  export declare function parseArgs(argv: readonly string[], cwd: string): CliOptions;
74
82
  /** Runs the CLI and returns the process exit code. Never throws. */