@descent-vtt/spec-graph 0.18.0 → 0.19.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 +58 -0
- package/README.md +18 -5
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +33 -15
- package/dist/cli.js.map +1 -1
- package/dist/extract.js +22 -11
- package/dist/extract.js.map +1 -1
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +6 -1
- package/dist/glob.js.map +1 -1
- package/dist/paths.d.ts +12 -0
- package/dist/paths.js +17 -0
- package/dist/paths.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,64 @@ the family's
|
|
|
11
11
|
[versioning policy](https://github.com/DescentVTT/spec-core/blob/main/docs/adr/0009-versions-before-1-0.md)
|
|
12
12
|
records.
|
|
13
13
|
|
|
14
|
+
## 0.19.0
|
|
15
|
+
|
|
16
|
+
A comma ends the clause a negation before a phrase is in, so
|
|
17
|
+
`if not, blocked by [ADR-0002](0002.md)` is the relation it states. A
|
|
18
|
+
library caller's own directory is where a relative `--root` is read
|
|
19
|
+
from, a drive letter names its volume in either case on Windows, and a
|
|
20
|
+
`\` in a root or a baseline is a separator wherever the run starts.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **A comma ends the clause a negation before a phrase is in.**
|
|
25
|
+
`if not, blocked by [ADR-0002](0002.md)` and
|
|
26
|
+
`both or neither, because [ADR-0002](0002.md) says so` were citations:
|
|
27
|
+
the comma was blanked, and the negation then stood against the phrase.
|
|
28
|
+
Each is the relation it states now, `blocked-by` and `assumes`, and so
|
|
29
|
+
are `No, blocked by`, `Not yet, deferred to` and
|
|
30
|
+
`Like it or not, superseded by`. A comma still counts toward no phrase's
|
|
31
|
+
40 characters, and a negation between the phrase and the reference
|
|
32
|
+
cancels it as before, whatever commas stand there. A `ghost-handover`,
|
|
33
|
+
`stale-premise` or supersession such a sentence states is reported, and
|
|
34
|
+
an open question it hands to a live document is no longer an
|
|
35
|
+
`orphaned-obligation`, so a check that passed can fail
|
|
36
|
+
([ADR-0006](https://github.com/DescentVTT/spec-graph/blob/main/docs/adr/0006-false-positives-cost-more.md)).
|
|
37
|
+
Upgrading: run `check`; a finding it now reports from such a sentence is
|
|
38
|
+
one the sentence states. A negation set off by commas from the phrase it
|
|
39
|
+
denies, `Never, ever, blocked by`, is read as the relation too: write it
|
|
40
|
+
without the commas.
|
|
41
|
+
- **A relative `--root` is read from the directory `main` is given.** The
|
|
42
|
+
library's `main({ argv, cwd })` compared two values of `--root` from
|
|
43
|
+
`cwd`, and read the one it kept from the process's own directory: `check
|
|
44
|
+
--root docs` checked another tree's `docs`, a `--record-baseline` beside
|
|
45
|
+
it was written there, and where that directory had no `docs` the root was
|
|
46
|
+
not there. The root, its configuration and its baselines are read from
|
|
47
|
+
`cwd` now, and a relative `cwd` is read from the process's directory, so
|
|
48
|
+
the walk for a configuration from it goes up to the repository as it does
|
|
49
|
+
from that directory, where it stopped at the top of the relative path.
|
|
50
|
+
The `spec-graph` command is as it was
|
|
51
|
+
([ADR-0010](https://github.com/DescentVTT/spec-graph/blob/main/docs/adr/0010-configuration-belongs-to-the-repository.md)).
|
|
52
|
+
Upgrading: a caller that passed a `cwd` other than the directory it meant
|
|
53
|
+
`--root` from passes that directory, or an absolute `--root`.
|
|
54
|
+
- **On Windows a drive letter names its volume in either case.** `--root
|
|
55
|
+
C:\x` beside `--root c:\x` was refused, exit `2`, as two directories, and
|
|
56
|
+
so were two baselines written so, and `C:docs` beside `c:docs`. Each is
|
|
57
|
+
one value now, taken once; past the letter two names are compared as
|
|
58
|
+
before, so `C:\x` beside `C:\X` is still refused (spec-core's ADR-0005,
|
|
59
|
+
2026-10-19). Upgrading: nothing to do; a line refused for this runs now.
|
|
60
|
+
- **A `\` in a baseline or a root is a separator wherever the run starts.**
|
|
61
|
+
On Linux `--baseline 'sub\held.json'` typed at the root read a file of
|
|
62
|
+
that name, and `'..\sub\held.json'` typed one directory down read
|
|
63
|
+
`sub/held.json`; a `"baseline"` in the configuration was read as the
|
|
64
|
+
first, and two baselines that differed only so were refused as two. Each
|
|
65
|
+
reads `sub/held.json` now, as an absolute path and a pattern did already,
|
|
66
|
+
and a `--root` with a `\` is asked of the disk as it is walked. Windows
|
|
67
|
+
reads every one as before
|
|
68
|
+
([ADR-0018](https://github.com/DescentVTT/spec-graph/blob/main/docs/adr/0018-the-configuration-file-is-the-root.md)).
|
|
69
|
+
Upgrading: on Linux, rename a baseline whose file name holds a `\`; a
|
|
70
|
+
check that read it reads the path the `\` spells now.
|
|
71
|
+
|
|
14
72
|
## 0.18.0
|
|
15
73
|
|
|
16
74
|
Two values for an option that takes one are compared as each is read, a
|
package/README.md
CHANGED
|
@@ -473,7 +473,9 @@ it, in the same statement: a sentence, a paragraph, a list item or a table cell.
|
|
|
473
473
|
`yet`, `longer`, `necessarily` and a few more) stand between: `not only
|
|
474
474
|
blocked by`, `nothing but blocked by`, the option `"never" blocked by` and
|
|
475
475
|
`Not in this release: deferred to` each state the relation, and are read as
|
|
476
|
-
they state it.
|
|
476
|
+
they state it. So do `if not, blocked by` and `both or neither, because`: a
|
|
477
|
+
comma ends the clause the negation is in, and counts toward no phrase's 40
|
|
478
|
+
characters.
|
|
477
479
|
- A sentence written in Chinese ends at `。`, `?`, `!` or `;`, with a space
|
|
478
480
|
after it or none, so `Deferred to later。另見 ADR-0002` hands nothing to
|
|
479
481
|
ADR-0002. A stop only ends a statement sooner: it reads less, never more.
|
|
@@ -892,6 +894,9 @@ reports, byte for byte, because every path here is relative to the root.
|
|
|
892
894
|
- A path typed on the command line stays relative to where you typed it, brace
|
|
893
895
|
alternative by brace alternative: `{/docs,x}` typed in `sub` is `/docs` or
|
|
894
896
|
`sub/x`.
|
|
897
|
+
- A `\` in a root or a baseline is a separator on every host, as in a pattern,
|
|
898
|
+
so `--baseline sub\held.json` typed at the root and `..\sub\held.json`
|
|
899
|
+
typed in `docs` are one file, `sub/held.json`, on Linux as on Windows.
|
|
895
900
|
|
|
896
901
|
See [ADR-0018](https://github.com/DescentVTT/spec-graph/blob/main/docs/adr/0018-the-configuration-file-is-the-root.md).
|
|
897
902
|
|
|
@@ -1187,8 +1192,10 @@ variable in `--family "$FAMILIES"` is the usual way to write one:
|
|
|
1187
1192
|
two`. Two values are compared as each is read, so one value twice is that
|
|
1188
1193
|
value once however it is spelled: `--root .` beside `--root ./` names one
|
|
1189
1194
|
directory, a baseline is a path resolved as the root is, and `--max 1`
|
|
1190
|
-
beside `--max " 1"` is one number.
|
|
1191
|
-
|
|
1195
|
+
beside `--max " 1"` is one number. On Windows a drive letter names its
|
|
1196
|
+
volume in either case, so `--root C:\x` beside `--root c:\x` is one
|
|
1197
|
+
directory; past the letter two names are two, `C:\x` beside `C:\X`. An
|
|
1198
|
+
option that is repeatable above takes each of its values;
|
|
1192
1199
|
- `--baseline` beside `--record-baseline`: a recording writes every finding
|
|
1193
1200
|
of the run and opens no baseline, so the one to read would go unread. A
|
|
1194
1201
|
`"baseline"` in the configuration is no option, and is recorded over as
|
|
@@ -1513,6 +1520,12 @@ const ghosts = query(graph, 'item[openness=open] -delegates-to-> document[phase=
|
|
|
1513
1520
|
The graph, the scanner, the selector engine and every vocabulary table are
|
|
1514
1521
|
exported. Reporters, editor extensions and custom rules are all first-class.
|
|
1515
1522
|
|
|
1523
|
+
The command line is `main`, which takes the line and the directory it was
|
|
1524
|
+
typed in: `await main({ argv: ['check', '--root', 'docs'], cwd })` reads
|
|
1525
|
+
`docs`, its configuration and any baseline beside it from `cwd`, and walks
|
|
1526
|
+
up from `cwd` for a configuration where no `--root` is given. Left out,
|
|
1527
|
+
`cwd` is the process's working directory, as for the `spec-graph` command.
|
|
1528
|
+
|
|
1516
1529
|
## Design
|
|
1517
1530
|
|
|
1518
1531
|
Twenty-three ADRs, which `spec-graph` validates on every CI run:
|
|
@@ -1550,9 +1563,9 @@ tools share, whose code is copied into `src/vendor/` and checked by hash rather
|
|
|
1550
1563
|
than installed. So the whole package is auditable in an afternoon — and nothing
|
|
1551
1564
|
in the pipeline can take longer than its input.
|
|
1552
1565
|
|
|
1553
|
-
**Verified, not just covered.** 2,
|
|
1566
|
+
**Verified, not just covered.** 2,354 tests; 99.4% statement and 99.8% line
|
|
1554
1567
|
coverage. Coverage says a line ran, so the suite is also held to a mutation
|
|
1555
|
-
score - 96.
|
|
1568
|
+
score - 96.58% over 9,126 mutants, measured by CI's full sweep, and a build
|
|
1556
1569
|
fails under 93 - because a vocabulary entry or a boundary
|
|
1557
1570
|
condition can be weakened by an ordinary-looking refactor without a single test
|
|
1558
1571
|
going red. [ADR-0007](https://github.com/DescentVTT/spec-graph/blob/main/docs/adr/0007-mutation-testing.md) is straight about what
|
package/dist/cli.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export interface CliIO {
|
|
|
78
78
|
readonly env?: Readonly<Record<string, string | undefined>> | undefined;
|
|
79
79
|
readonly isTTY?: boolean | undefined;
|
|
80
80
|
}
|
|
81
|
-
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 spec-graph diff <before.json> <after.json> [--format human|json|markdown]\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 diff Compare two graph exports: documents added, removed, moved or\n accepted; relations added or removed; and obligations resolved or\n reopened where they can be told apart. Make both exports with the\n same spec-graph. Exits 0 whether anything changed or not.\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. It has to be a\n directory that is there.\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: one\n name each time, the prefix its identifiers are\n written with, ADR for ADR-0007. A document here has\n to belong to one of them, or the check stops: a list\n that names none allows nothing. It stops too where\n a name has no document and the list leaves out a\n family the documents do belong to, as RFCS for RFC\n does: one is most likely meant for the other.\n --ignore-family <name> Families that are never citations - RFC when the repo\n cites RFC 2119 and keeps its own RFCs. Repeatable,\n one name each time.\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 A pattern whose files an ignore leaves out is\n refused: no journal it names would be read.\n --baseline <file> Accept the findings recorded in this file and report\n only what is new since. The file has to be there: a\n path that reads nothing accepts nothing and says so\n nowhere. A \"baseline\" in the configuration may name a\n file not recorded yet; a path typed here may not.\n --record-baseline <f> Write today's findings to this file as accepted debt,\n and exit 0 without judging them. With --format json\n the recording is a JSON document.\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, github, gitlab or markdown. json\n is for check, query or diff. sarif is the interchange\n format GitHub code scanning and editors already read,\n github the workflow commands a GitHub Actions log\n turns into annotations, and gitlab the Code Quality\n report a GitLab merge request reads, all three for\n check; markdown is a table for a pull-request comment\n or $GITHUB_STEP_SUMMARY, for check or diff (default:\n 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, whatever NO_COLOR, FORCE_COLOR\n and the terminal say. The two together are refused\n --ascii / --no-ascii ASCII glyphs or Unicode ones. SPEC_GRAPH_ASCII asks\n for ASCII, unless it is empty, 0 or false. Either\n option wins over it, and over what the terminal is\n taken for. The two together are refused\n --verbose Include parse problems, per-file detail, and every\n reference --ignore-ref or --ignore-family silenced\n --explain With rules: add each rule's selector and the ADR\n that decided it\n -h, --help Show this help\n -v, --version Show the version\n\n An option belongs to the commands that read it, and any other command\n refuses it by name:\n\n --root, --verbose check, query, graph, rules\n --ignore, --history check, query, graph\n --format check, query, diff\n --graph-format, --documents-only graph\n --explain rules\n every other option check\n\n --no-config, --no-color and --ascii are taken by every command: each is\n true already of a command with nothing to read it for. --color and\n --no-ascii are not: each would say that a command drew what only a check\n draws.\n\n An option beside its own opposite is refused, whichever comes first:\n --color beside --no-color, and --ascii beside --no-ascii. The later would\n decide and the earlier go unread. Either alone wins over the environment,\n and the same option twice is that option once.\n\n An option that takes one value is refused given two, as in --root a\n --root b: the later would be read and the earlier go unread. That is each\n option above with a value that is not marked Repeatable, and one rule\n given two severities by --rule. Two values are compared as each is read,\n so one value twice is that value once however it is spelled: --root .\n beside --root ./ names one directory.\n\n A baseline to read is refused beside one to record, --baseline beside\n --record-baseline: a recording writes every finding and opens no\n baseline. So is each option a recording does not read, since it judges,\n shows and colours no finding: --ratchet, --strict, --max, --max-warnings,\n --color, --no-ascii, and --format sarif, github or gitlab. So is one\n family given to both --family and --ignore-family, whose citations are\n passed over whatever asked for them. One family asked for beside another\n ignored is taken.\n\n A value that begins with -- reads as an option, so the option before it is\n refused as missing its value. A name that does begin so is written ./--name\n for a file, [-]-name in a pattern and \\--name for a reference target.\n\n A line that is wrong is refused with --help or --version on it too, an\n option a recording does not read among them, and --help beside --version\n is refused: one of the two answers would go unread. What a command still\n needs, a selector or two exports, is what --help is for: query --help and\n diff --help print it. The help reads no disk, so what only the run finds,\n a --root that is not there or a --history an ignore leaves out, is\n answered by it.\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\n An input that is set and names nothing is a 2, named on stderr, and never\n read as if it had not been given: an empty value, a family name no family\n has, a list of families no document here belongs to, a --root that is no\n directory, a second word after rules, an option of another command. So\n are two things of which one would go unread: an option beside its own\n opposite, an option that takes one value given two, --baseline beside\n --record-baseline, an option a recording does not read, a family both\n asked for and ignored, a --history whose files an ignore leaves out,\n --help beside --version.\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 \"maxRelated\": 3 }\n\n A flag always wins over the file, and list flags add to it rather than\n replacing it: --family RFC reads the citations \"ignoreFamilies\" passes\n over. maxRelated has no flag: it caps how many related locations one\n finding lists, 8 unless set, and 0 lists none.\n\n A problem in that file stops the run with exit 2, named on stderr: invalid\n JSON, an unknown key, a rule that does not compile, one family in both\n \"families\" and \"ignoreFamilies\", a file that is there and cannot be read. A configuration that did not load checks a different\n repository than the one configured, and would report that one as consistent.\n --no-config runs on defaults instead.\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 spec-graph check --format github # annotations from an Actions log\n spec-graph check --format gitlab > gl-code-quality-report.json\n spec-graph diff base.json head.json --format markdown >> \"$GITHUB_STEP_SUMMARY\"\n";
|
|
81
|
+
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 spec-graph diff <before.json> <after.json> [--format human|json|markdown]\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 diff Compare two graph exports: documents added, removed, moved or\n accepted; relations added or removed; and obligations resolved or\n reopened where they can be told apart. Make both exports with the\n same spec-graph. Exits 0 whether anything changed or not.\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. It has to be a\n directory that is there.\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: one\n name each time, the prefix its identifiers are\n written with, ADR for ADR-0007. A document here has\n to belong to one of them, or the check stops: a list\n that names none allows nothing. It stops too where\n a name has no document and the list leaves out a\n family the documents do belong to, as RFCS for RFC\n does: one is most likely meant for the other.\n --ignore-family <name> Families that are never citations - RFC when the repo\n cites RFC 2119 and keeps its own RFCs. Repeatable,\n one name each time.\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 A pattern whose files an ignore leaves out is\n refused: no journal it names would be read.\n --baseline <file> Accept the findings recorded in this file and report\n only what is new since. The file has to be there: a\n path that reads nothing accepts nothing and says so\n nowhere. A \"baseline\" in the configuration may name a\n file not recorded yet; a path typed here may not.\n --record-baseline <f> Write today's findings to this file as accepted debt,\n and exit 0 without judging them. With --format json\n the recording is a JSON document.\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, github, gitlab or markdown. json\n is for check, query or diff. sarif is the interchange\n format GitHub code scanning and editors already read,\n github the workflow commands a GitHub Actions log\n turns into annotations, and gitlab the Code Quality\n report a GitLab merge request reads, all three for\n check; markdown is a table for a pull-request comment\n or $GITHUB_STEP_SUMMARY, for check or diff (default:\n 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, whatever NO_COLOR, FORCE_COLOR\n and the terminal say. The two together are refused\n --ascii / --no-ascii ASCII glyphs or Unicode ones. SPEC_GRAPH_ASCII asks\n for ASCII, unless it is empty, 0 or false. Either\n option wins over it, and over what the terminal is\n taken for. The two together are refused\n --verbose Include parse problems, per-file detail, and every\n reference --ignore-ref or --ignore-family silenced\n --explain With rules: add each rule's selector and the ADR\n that decided it\n -h, --help Show this help\n -v, --version Show the version\n\n An option belongs to the commands that read it, and any other command\n refuses it by name:\n\n --root, --verbose check, query, graph, rules\n --ignore, --history check, query, graph\n --format check, query, diff\n --graph-format, --documents-only graph\n --explain rules\n every other option check\n\n --no-config, --no-color and --ascii are taken by every command: each is\n true already of a command with nothing to read it for. --color and\n --no-ascii are not: each would say that a command drew what only a check\n draws.\n\n An option beside its own opposite is refused, whichever comes first:\n --color beside --no-color, and --ascii beside --no-ascii. The later would\n decide and the earlier go unread. Either alone wins over the environment,\n and the same option twice is that option once.\n\n An option that takes one value is refused given two, as in --root a\n --root b: the later would be read and the earlier go unread. That is each\n option above with a value that is not marked Repeatable, and one rule\n given two severities by --rule. Two values are compared as each is read,\n so one value twice is that value once however it is spelled: --root .\n beside --root ./ names one directory, and so on Windows does C:\\x beside\n c:\\x, a drive letter naming its volume in either case.\n\n A baseline to read is refused beside one to record, --baseline beside\n --record-baseline: a recording writes every finding and opens no\n baseline. So is each option a recording does not read, since it judges,\n shows and colours no finding: --ratchet, --strict, --max, --max-warnings,\n --color, --no-ascii, and --format sarif, github or gitlab. So is one\n family given to both --family and --ignore-family, whose citations are\n passed over whatever asked for them. One family asked for beside another\n ignored is taken.\n\n A value that begins with -- reads as an option, so the option before it is\n refused as missing its value. A name that does begin so is written ./--name\n for a file, [-]-name in a pattern and \\--name for a reference target.\n\n A line that is wrong is refused with --help or --version on it too, an\n option a recording does not read among them, and --help beside --version\n is refused: one of the two answers would go unread. What a command still\n needs, a selector or two exports, is what --help is for: query --help and\n diff --help print it. The help reads no disk, so what only the run finds,\n a --root that is not there or a --history an ignore leaves out, is\n answered by it.\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\n An input that is set and names nothing is a 2, named on stderr, and never\n read as if it had not been given: an empty value, a family name no family\n has, a list of families no document here belongs to, a --root that is no\n directory, a second word after rules, an option of another command. So\n are two things of which one would go unread: an option beside its own\n opposite, an option that takes one value given two, --baseline beside\n --record-baseline, an option a recording does not read, a family both\n asked for and ignored, a --history whose files an ignore leaves out,\n --help beside --version.\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 \"maxRelated\": 3 }\n\n A flag always wins over the file, and list flags add to it rather than\n replacing it: --family RFC reads the citations \"ignoreFamilies\" passes\n over. maxRelated has no flag: it caps how many related locations one\n finding lists, 8 unless set, and 0 lists none.\n\n A problem in that file stops the run with exit 2, named on stderr: invalid\n JSON, an unknown key, a rule that does not compile, one family in both\n \"families\" and \"ignoreFamilies\", a file that is there and cannot be read. A configuration that did not load checks a different\n repository than the one configured, and would report that one as consistent.\n --no-config runs on defaults instead.\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 spec-graph check --format github # annotations from an Actions log\n spec-graph check --format gitlab > gl-code-quality-report.json\n spec-graph diff base.json head.json --format markdown >> \"$GITHUB_STEP_SUMMARY\"\n";
|
|
82
82
|
/** Parses argv into options. Throws {@link UsageError} on anything malformed. */
|
|
83
83
|
export declare function parseArgs(argv: readonly string[], cwd: string): CliOptions;
|
|
84
84
|
/**
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import { isFamilyName } from './identity.js';
|
|
|
19
19
|
import { analyse, DEFAULT_PATTERNS, withDiagnostics } from './runner.js';
|
|
20
20
|
import { formatGithub, formatGitlab, formatGraph, formatJson, formatMarkdown, formatReport, formatSarif, shouldUseAscii, shouldUseColor, } from './report.js';
|
|
21
21
|
import { DEFAULT_SEVERITIES, resolveStrict, RULE_DECISIONS, decisionUrl, RULE_DESCRIPTIONS, RULE_IDS, RULE_QUERIES, } from './rules.js';
|
|
22
|
-
import { isAbsolutePath, joinPosix, toPosix } from './paths.js';
|
|
22
|
+
import { foldDriveLetter, isAbsolutePath, joinPosix, toPosix } from './paths.js';
|
|
23
23
|
import { formatRef } from './source.js';
|
|
24
24
|
import { execute, parseQuery, QueryError, renderMatch } from './select.js';
|
|
25
25
|
import { isProjectRule } from './types.js';
|
|
@@ -153,7 +153,8 @@ OPTIONS
|
|
|
153
153
|
option above with a value that is not marked Repeatable, and one rule
|
|
154
154
|
given two severities by --rule. Two values are compared as each is read,
|
|
155
155
|
so one value twice is that value once however it is spelled: --root .
|
|
156
|
-
beside --root ./ names one directory
|
|
156
|
+
beside --root ./ names one directory, and so on Windows does C:\\x beside
|
|
157
|
+
c:\\x, a drive letter naming its volume in either case.
|
|
157
158
|
|
|
158
159
|
A baseline to read is refused beside one to record, --baseline beside
|
|
159
160
|
--record-baseline: a recording writes every finding and opens no
|
|
@@ -489,7 +490,9 @@ export function parseArgs(argv, cwd) {
|
|
|
489
490
|
// JSON where the two the other way round are refused. Two values are
|
|
490
491
|
// compared as each is read, not as it is written, so `--root .` beside
|
|
491
492
|
// `--root ./` names one directory and is taken once (spec-core's ADR-0005,
|
|
492
|
-
// 2026-10-18)
|
|
493
|
+
// 2026-10-18), and so do `C:\x` and `c:\x` on Windows, where a drive letter
|
|
494
|
+
// names its volume in either case (the same, 2026-10-19). Each is read
|
|
495
|
+
// once the whole line has been, since a
|
|
493
496
|
// baseline typed beside `--root` is read from the root, wherever on the
|
|
494
497
|
// line the root stands. A mutant that seeds this list with a string holds
|
|
495
498
|
// it under no option's key, where no value is compared with it: equivalent.
|
|
@@ -548,11 +551,12 @@ export function parseArgs(argv, cwd) {
|
|
|
548
551
|
verbose = true;
|
|
549
552
|
break;
|
|
550
553
|
case '--root': {
|
|
551
|
-
// Resolved from where the line was typed
|
|
552
|
-
//
|
|
553
|
-
//
|
|
554
|
+
// Resolved from where the line was typed, with a `\` read as the run
|
|
555
|
+
// reads it, and compared as text past the drive letter: the disk is
|
|
556
|
+
// not asked, so a link and its target are two values, and no other
|
|
557
|
+
// case is folded.
|
|
554
558
|
const value = filled(arg, i, 'a directory');
|
|
555
|
-
once(arg, value, () => resolve(cwd, value));
|
|
559
|
+
once(arg, value, () => foldDriveLetter(resolve(cwd, toPosix(value))));
|
|
556
560
|
root = value;
|
|
557
561
|
rootExplicit = true;
|
|
558
562
|
i += 1;
|
|
@@ -582,14 +586,14 @@ export function parseArgs(argv, cwd) {
|
|
|
582
586
|
// and from where it was typed otherwise, which is the root's default.
|
|
583
587
|
case '--baseline': {
|
|
584
588
|
const value = filled(arg, i, 'a file');
|
|
585
|
-
once(arg, value, () => resolve(cwd, root, value));
|
|
589
|
+
once(arg, value, () => foldDriveLetter(resolve(cwd, toPosix(root), toPosix(value))));
|
|
586
590
|
baseline = value;
|
|
587
591
|
i += 1;
|
|
588
592
|
break;
|
|
589
593
|
}
|
|
590
594
|
case '--record-baseline': {
|
|
591
595
|
const value = filled(arg, i, 'a file');
|
|
592
|
-
once(arg, value, () => resolve(cwd, root, value));
|
|
596
|
+
once(arg, value, () => foldDriveLetter(resolve(cwd, toPosix(root), toPosix(value))));
|
|
593
597
|
recordBaseline = value;
|
|
594
598
|
i += 1;
|
|
595
599
|
break;
|
|
@@ -897,6 +901,13 @@ async function run(io, err) {
|
|
|
897
901
|
// it can compare exports from a checkout it is not running in.
|
|
898
902
|
if (options.command === 'diff')
|
|
899
903
|
return runDiff(options.patterns, cwd, options.format, out, err);
|
|
904
|
+
// Where the run starts: the root a `--root` names, or the directory the
|
|
905
|
+
// line was typed in. Either is read from that directory, which a caller of
|
|
906
|
+
// the library names with `io.cwd`, and where two values of `--root` were
|
|
907
|
+
// compared: left relative, the disk read it from Node's own directory, so
|
|
908
|
+
// `--root docs` checked, and recorded a baseline into, another tree than
|
|
909
|
+
// the caller's. A `\` is a separator, as the walk has always read it.
|
|
910
|
+
const start = resolve(cwd, toPosix(options.root));
|
|
900
911
|
// A root that was named is a directory, for every command that reads one.
|
|
901
912
|
// `rules --root` with a path that is not there listed the built-in rules and
|
|
902
913
|
// exited 0, as if the repository declared none, and the others said only
|
|
@@ -905,7 +916,7 @@ async function run(io, err) {
|
|
|
905
916
|
const { stat } = await import('node:fs/promises');
|
|
906
917
|
// A path that cannot be reached reads as one that is not there: either
|
|
907
918
|
// way there is nothing under it to read.
|
|
908
|
-
const found = await stat(
|
|
919
|
+
const found = await stat(start).catch(() => null);
|
|
909
920
|
if (found === null || !found.isDirectory()) {
|
|
910
921
|
err(`spec-graph: --root "${options.root}" is not ${found === null ? 'there' : 'a directory'}\n`);
|
|
911
922
|
return EXIT_ERROR;
|
|
@@ -921,10 +932,10 @@ async function run(io, err) {
|
|
|
921
932
|
// Read before `rules` prints anything, so that command lists the conventions
|
|
922
933
|
// this repository will actually check rather than the ones spec-graph ships.
|
|
923
934
|
const loaded = options.noConfig
|
|
924
|
-
? { config: {}, source: null, problems: [], root:
|
|
935
|
+
? { config: {}, source: null, problems: [], root: start }
|
|
925
936
|
: options.rootExplicit
|
|
926
|
-
? { ...loadConfig(
|
|
927
|
-
: discoverConfig(
|
|
937
|
+
? { ...loadConfig(start), root: start }
|
|
938
|
+
: discoverConfig(start);
|
|
928
939
|
for (const problem of loaded.problems)
|
|
929
940
|
err(`spec-graph: ${problem}\n`);
|
|
930
941
|
// A configuration that did not load means a run against a different
|
|
@@ -944,7 +955,7 @@ async function run(io, err) {
|
|
|
944
955
|
// How far the root moved up. Everything a repository declares about itself is
|
|
945
956
|
// relative to the root; everything typed on the command line is relative to
|
|
946
957
|
// where it was typed, and this is what keeps those two readings apart.
|
|
947
|
-
const here = below(root,
|
|
958
|
+
const here = below(root, start);
|
|
948
959
|
// A `--rule` naming a project rule that does not exist is a flag that
|
|
949
960
|
// silently does nothing, and nothing in the output would distinguish that
|
|
950
961
|
// from a rule that ran and found none.
|
|
@@ -1037,8 +1048,10 @@ async function run(io, err) {
|
|
|
1037
1048
|
err(`spec-graph: ${error.message}\n`);
|
|
1038
1049
|
return EXIT_ERROR;
|
|
1039
1050
|
}
|
|
1051
|
+
// A root that was named is named as it was typed, as every other refusal
|
|
1052
|
+
// of it is; the one discovery found is named as it was found.
|
|
1040
1053
|
if (result.files.length === 0) {
|
|
1041
|
-
err(`spec-graph: no specifications matched ${patterns.map((p) => `"${p}"`).join(', ')}\n looked under ${root}\n`);
|
|
1054
|
+
err(`spec-graph: no specifications matched ${patterns.map((p) => `"${p}"`).join(', ')}\n looked under ${options.rootExplicit ? options.root : root}\n`);
|
|
1042
1055
|
return EXIT_ERROR;
|
|
1043
1056
|
}
|
|
1044
1057
|
// A journal named on the line and never read. A `--history` pattern marks
|
|
@@ -1262,6 +1275,11 @@ async function run(io, err) {
|
|
|
1262
1275
|
* arithmetic.
|
|
1263
1276
|
*/
|
|
1264
1277
|
function below(root, from) {
|
|
1278
|
+
// `from` is where the run starts as `path.resolve` gives it, which ends in
|
|
1279
|
+
// no separator but at a filesystem root, `/` or `C:\`, and there `below` is
|
|
1280
|
+
// `''` whether the strip takes every slash, takes one, or writes a word in
|
|
1281
|
+
// their place: the mutants of this line are equivalent since the run
|
|
1282
|
+
// resolves where it starts. The strip stays for a path passed as typed.
|
|
1265
1283
|
const start = toPosix(from).replace(/[/]+$/, '');
|
|
1266
1284
|
// The prefix test only guards a root that is neither `start` nor above it,
|
|
1267
1285
|
// which nothing returns; for `start` itself, slicing past its end is `''`
|