Books of documents whose kinds a project declares, linked to the files they stand on, and whether each decision about them still holds.
A project keeps its reasons as Markdown documents with front matter: what was found, what is required, what was decided, and how it is checked. Each kind is a book the project declares, and documents link to each other and to the files, Rust items and tests they stand on. A person approves a document; the approval pins what it stood on. On every read, whyshelf tells whether each approval still holds:
- fresh;
- stale, when something it stood on changed;
- expired, past its
--until; - broken, when something it stood on is gone or no longer stands.
Nothing about freshness is stored; it is derived again each time.
cargo install --path crates/whyshelf-cli # from a checkout: installs the `whyshelf` commandIn the root of a project:
whyshelf init --template sample # a declaration of four books, and one pending document of each
whyshelf check # nothing wrong: exit 0
whyshelf map | jq -r .diagram # the books and their links, drawn
whyshelf trace V-1 # the chain, from the verification up to the finding
whyshelf judge approve --pending F-1 V-1 --reason "read, and it holds"
# F-1, REQ-1, DEC-1 and V-1, upstream first
whyshelf status # each document, approved and freshEvery command answers in JSON; map also carries a text drawing in diagram. whyshelf --help lists the commands in the order of the work, and whyshelf guide | jq -r .text says each step with the commands to type.
--pending F-1 V-1 takes V-1 and the pending documents it depends on, DEC-1 and REQ-1. F-1 is named as well, because REQ-1 only grounds on it, an informs link, which an approval does not stand on.
Edit books/requirement/REQ-1.md and run whyshelf stale. REQ-1 no longer holds, nor do the decision and the verification that depend on it, and stale says it starts at REQ-1. F-1 still holds: a change makes stale what depends on it, never what it stands on.
How a verification names its tests, and how a shelf that names test files whole moves to test functions: whyshelf guide tests | jq -r .text.
init --template <name> chooses one of four templates, listed by init --help:
| template | what it writes |
|---|---|
minimal |
the default: one book of notes, with comments on how to add a field, a link and a link to files; no document |
sample |
four books, finding → requirement → decision → verification, and one document of each in one chain |
qa-first |
the same four books, with two rules loosened so checks can be written before the decisions they check; a finding, a requirement and a verification, no decision yet. The manual says how to tighten the rules at release |
experiment |
the same four books, for checks that are measurements planned before they are run: a decision names its code, and a plan and its result are two verifications; one chain ending in a plan, with its table of what is expected |
init writes over nothing and approves nothing. It makes the directory of every book the declaration names: a book that gets no document gets an empty .gitkeep in its directory, because check fails for a book whose directory is not there and Git keeps no empty directory, so a directory without a file is missing in a clone. A mistyped dir fails check and names the book and the directory; a link to a key no document has, of any meaning, fails it too, unless the document that holds it is denied, deprecated or retired.
-
Books and links.
.whyshelf/books.tomldeclares each book: its directory, its key grammar, its fields and its links.- A link that depends makes a document stale when its target changes; one that informs does not.
- A link may declare a cover: every pending or approved document of its target book is expected to be reached by it.
trueor"error"failscheck;"warn"lists the gap and warns on stderr. - A book may declare which files of its directory are documents:
include,excludeandwithout_front_matter.
-
Approvals. An approval is a record in
.whyshelf/ledger/, with who, when and why, pinning the hashes of what it stood on.judge approve --pendingapproves pending documents: never approved, or with every decision withdrawn. Bare, it takes all of them; with references, it takes those and the pending documents they depend on.judge approve --staleapproves again what an edit made stale or what expired.- Both run upstream first, in one run. An approval that would only repeat the one that stands is left out, unless
--again.
-
Artifacts and spaces. What a document stands on outside the books is an artifact named in a space:
file, a path of the project;rust-item, a public Rust path, read from the docscargo docbuilds. Build them afresh before you check or approve: before they are built a name cannot be told, and docs left from an earlier build are read as they are;rust-test, a test function,<file>.rs::[<module>::…]<fn>, read by a shallow scan of the file that runs no program; it lists the tests of the files a selection takes, so a link to tests may declare a cover;js-test, a JavaScript or TypeScript test,<file>::<title>::…, by the file it is in and its titles, read from the source without running any program;py-test, a Python test,<file>.py::[<Class>::…]<function>, by the file it is in, the classes around it and its function, read from the source without running any program; it lists the tests of the files a selection takes, so a link to tests may declare a cover.
Each link says how to compare (
bytes,linesorpresence). Presets (code,file,js-test,py-test,rustdoc,rustdoc-promise,test) are short names for the usual settings. -
Declarations. A person may declare:
- that an edit keeps the meaning (
judge same); - that an artifact moved (
judge moved;whyshelf movessuggests where), or that every name under a prefix did, as when a directory or a module is renamed (judge moved --prefix <old> <new>); - that a document is not expected to be reached by a cover (
judge exempt).
Each is a ledger record with a reason, and
judge withdrawtakes it back. - that an edit keeps the meaning (
-
Who may decide.
.whyshelf/books.tomlmay name groups of actors ([[group]]) and, per book ([book.decide]) and for the records of no book ([decide]), which groups may write each kind of judgement (an exemption is ruled by the book that declares the link it exempts from).judgerefuses a name the rule does not admit;checkfails on a record in the ledger it does not admit, which is not used. A rule may ask forapprovals = 2(up to 10): an approval then settles only once that many different names approved the same content, and until then the document isawaiting, notfresh; it is fresh again once another name approves it, and awaits again when a reading lapses. An edit declared to keep the meaning (judge same) needs as many names. There is no authentication: the rule is about the name written, as declared, so one person who writes two names is two names. A rule declared over an earlier ledger is best given asince. Known limitation: what stands on an awaiting document is stale until the last name approves it, as on a pending one, so a CI that runsstale --exit-codefails between the first approval and the last.
| reading | |
|---|---|
check |
the declaration, the documents and the ledger; exit 1 if anything is wrong, a book whose directory is not there and a link to a key no document has included |
status, get <ref> |
where each document stands, or one with why |
stale [--exit-code] |
the approvals that no longer hold, with where that starts, and the commands that can settle each origin with what each does |
units [--pending] |
the approvals that no longer hold (with --pending, the pending documents too), divided into units of work that share nothing |
trace <ref>, map |
the chain through a document, and the books and their links |
reach <ref>... |
what depends on documents, what all of it stands on, and the files that hold it |
impact (--since <rev> [--until <rev> | --index] | --before <dir> [--after <dir>]) |
whether a change makes approvals not hold: yes with where it starts, no, or cannot_tell with what cannot be told |
impact ... --within <ref>... [--exit-code] |
and whether the change stays inside the documents it was meant for |
contrast (--since <rev> [--until <rev> | --index] | --before <dir> [--after <dir>]) [--all] |
two revisions side by side, each read by its own declaration and ledger: every document on the sides it is on, with its standing and whether its content differs, and each book and covering link with the gaps at one side only |
unlinked |
the documents no link reaches, or that hold none |
doctor [--all] |
the signs of what the shelf costs to keep, the costliest first and the first of each kind unless --all: files named whole where test functions could be named, what changed under approvals made again with no declaration naming it, artifacts many documents stand on, and pinned names that are gone |
stats, moves |
how the work went, from the ledger; and where pinned files may have moved |
get <ref> --approved, diff <ref> |
what an approval saw; and that against now |
schema |
the JSON Schema of every answer |
guide [<topic>] |
the guide, in the order of the work, as text in the JSON (jq -r .text) |
| writing | |
|---|---|
init, new <book> |
start a project; make one document |
judge approve, deny, deprecate, retire, revoke |
decide about documents |
judge same, moved (--prefix for a renamed directory or module), exempt, withdraw |
declare, and take back |
fmt [--check] |
put every document in the one form |
rekey <ref> |
give a document a new key (two branches took one), and rewrite the links that mean it |
Every command prints one JSON document on stdout (--help and --version aside); warnings and errors also go to stderr.
impact reads the project before and after a change one way, the same at both ends, and answers for every registered document whether the change adds a cause that makes its approval not hold, by the rule stale uses: yes (where it starts), no, or cannot_tell (what cannot be told). A new edit of what already did not hold is a cause added too, so yes does not mean the approval held before (before says that). The flags choose the way, and the answer's way says which was used:
- Git:
--since <rev>before, and--until <rev>or--indexafter (defaultHEAD). It reads the tracked content as a checkout of the repository writes it (no filter driver is run), each commit converted by its own.gitattributes; the attributes of your own Git settings (core.attributesFileand its default file) and of the system are not read, so nothing outside the repository decides a conversion.--indexcan be read only while the index's.gitattributesareHEAD's (otherwise exit 2: ask with the file way), and a path added withgit add -Nreads there as an empty file. It needs a Git that knows--attr-source; each converted file costs one process of Git. Nothing is built in a commit, so an approval that stands on arust-itemcannot be told this way. - Files:
--before <dir>before, and--after <dir>after (default the project root). Prepare the directory before yourself (for examplegit worktree add --detach <dir> <rev>, and build the docs there to ask aboutrust-item); whyshelf makes nothing.
contrast reads two revisions the way impact does (the same flags), each side by its own declaration and ledger, and answers what each side holds: every document on the side or sides it is on, with its file, standing and holding there and whether its content is the same at both (a document the same in every way at both is counted in hidden and listed with --all); each book with its documents by standing; and each covering link with its gaps at each side and those at one side only. A side with no declaration (a commit before init), or one that cannot be used, is that side's answer, and the exit is 0 whenever it answers. It compares the two ends as given: for what a branch changed since it left main, give --since $(git merge-base main <branch>) --until <branch>.
impact --within <ref>... answers too, for every document, whether the change reaches it (a cause added or taken away, what was decided, on the shelf or off it, its content or links, a record about it), each by the rule impact, the ledger or the shelf already answers it with, and its verdict against the reach of the documents named as the project stood before the change (the named and those that depend on them). --exit-code (which requires --within) exits 1 unless the gate passes; --within alone exits 0. The verdicts, what keeps the gate from passing (a file of the books or of the ledger that cannot be read, at either end, among it) and the known limits are on the page of the library's domain::shelf::within, the one place they are stated. Read through Git, the built docs cannot be read, so an approval on a rust-item outside the reach cannot be told: to tell it, build the docs in both directories and ask with the file way.
whyshelf check && whyshelf fmt --check && whyshelf stale --exit-codeThis fails in any of these cases:
- the declaration cannot be used, or a document or the ledger is not sound;
- a covering link leaves an error gap;
- the directory of a book is not there or is no directory (a mistyped
dir, or an empty directory Git did not keep: make it with a file in it, or correctdir); - a link of a pending or approved document cannot be followed (it writes a key no document has, whatever the link means);
- a file is not in the one form;
- an approval no longer holds;
- an approval stands on a name that cannot be told now. For
rust-item, build the docs first (cargo doc --no-deps).
Run it on pull requests as well as on the main branch, on the result of merging the pull request into the main branch (what a GitHub workflow on pull_request checks out), so that a key two branches took in files of different names is reported before the merge rather than after it. Two runs of new that took one key write one file, and that merge conflicts: there is no result to check until the conflict is resolved. The result is made from the main branch of the time: once the main branch moves, run the check again, or require a branch to be up to date before it is merged, or merge through a merge queue (on GitHub, give the workflow the merge_group trigger), so that what lands was checked against what it lands on.
The findings, requirements, decisions and verifications of whyshelf itself are books under books/, approved in .whyshelf/ledger/. just check builds the docs and runs the gate above on them. whyshelf status lists them.
Everything else is the RustDoc: the model, the file formats, the command line, its output and exit status. Build and read it with:
just rust-docCargo prints the path of each page it generates. Start at the whyshelf crate page, which is the manual. The page of the whyshelf binary (the whyshelf-cli crate) is built as the second step.
How several people or branches add documents to one shelf at once is the manual's section "Working from several branches".
| crate | role | depends on |
|---|---|---|
whyshelf |
Umbrella: the name users depend on. Re-exports the core; the adapters behind the infra feature. |
-core, -infra (optional) |
whyshelf-core |
Core (SDK): domain (pure rules and types), app (use cases and their ports). No I/O crate. |
— |
whyshelf-infra |
Adapters of the ports: file system, Git, clock, TOML / YAML front matter / JSON, and the spaces. | -core |
whyshelf-cli |
The whyshelf command. |
-core, -infra |
The layer rules inside the core are in arch-lint.toml and run with cargo test.
The rule between crates is the [dependencies] table: the core never depends on an I/O crate.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.