Alibi fails your build at every place where someone switched off a check of RuboCop, Clippy, TypeScript, Steep, or any other tool, until that place has an alibi: the reason the check is off there, on the record.
Every linter, type checker, and compiler lets you switch a check off at one place, with a comment or an attribute such as # rubocop:disable, #[allow(...)], @ts-ignore, or # steep:ignore. Such a line is easy to miss in the change that adds it, and hard to find among the rest of the code afterward, so a green build can hide places where a check no longer holds. Alibi finds each one with a pattern you choose, and fails until it has an alibi.
An alibi costs something to add and nothing to keep. To write one, someone runs alibi add, which asks four questions before it writes anything: what they tried, to fix the code instead; what shows that the place needs it; why no change to the code can remove it; and the reason, for a reviewer who wasn't there. Each question says how to stop and fix the code instead. Alibi keeps the answers in an alibi file in your repository, sealed, so that an edit by hand fails the build. Whoever answers for the code (a maintainer, a reviewer, an orchestrating agent, or an auditor) then reads, in that one file and in its diffs, every place where a passing build doesn't mean what it says.
Alibi is for a developer, or an AI agent working for one, in a project whose checks someone can switch off at one place. It checks files in any language, on macOS, Linux, and Windows. It has no built-in knowledge of any linter: an alibi file lists the files it covers and a Ruby regular expression, so it bans whatever the pattern finds, a suppression or anything else. Its questions are written for an agent about to switch a check off as well as for a person, and none of them needs a prompt: with no terminal, alibi add shows one question at a time, with the command line that answers it.
A Ruby project in a git repository has a Gemfile and a nine-line lib/invoice.rb, with two comments that switch a RuboCop cop off:
$ cat lib/invoice.rb
class Invoice
def total(lines) # rubocop:disable Metrics/AbcSize
lines.sum { |line| line.quantity * line.unit_price * (1 - line.discount) + line.tax }
end
def due_on(issued_on)
issued_on + 30 # rubocop:disable Style/NumericLiterals
end
endIn the project folder, write an alibi file from the example that bans RuboCop's disable comments, and run Alibi. A line that starts with $ is a command; the lines after it are what it prints.
$ alibi init .config/alibi/rubocop-disable-never.kdl --example rubocop-disable-never
wrote .config/alibi/rubocop-disable-never.kdl; to check it, run alibi .config/alibi/rubocop-disable-never.kdl
$ alibi
.config/alibi/rubocop-disable-never.kdl: failed: 2 matches in 2 files: fix the code, or run alibi add .config/alibi/rubocop-disable-never.kdl PATH:LINE for each match with no alibi
lib/invoice.rb:2: def total(lines) # rubocop:disable Metrics/AbcSize
lib/invoice.rb:7: issued_on + 30 # rubocop:disable Style/NumericLiteralsAlibi exits with status 1, so the build fails. The second comment needs no alibi: 30 breaks no rule of Style/NumericLiterals, so delete the comment, and one match is left. That one keeps the formula in the shape of a tax worksheet, so write an alibi for it. At a terminal, alibi add opens your editor for each of its four questions in turn; here the answers come from four files, as they would for an agent:
$ alibi add .config/alibi/rubocop-disable-never.kdl lib/invoice.rb:2 --tried-file tried.txt --evidence-file evidence.txt --unfixable-file unfixable.txt --reason-file reason.txt
added the alibi 0a916d4 for lib/invoice.rb:2:20 to .config/alibi/rubocop-disable-never.kdl; to check it, run alibi .config/alibi/rubocop-disable-never.kdl
$ alibi
.config/alibi/rubocop-disable-never.kdl: passed: 1 match in 2 files, each with its alibi
$ alibi list
alibi 0a916d4 lib/invoice.rb
def total(lines) # rubocop:disable Metrics/AbcSize
tried:
Split total into a method for each term. Metrics/AbcSize still counted the calls on line.
evidence:
docs/tax/worksheet.pdf, section 4, gives the total as one formula.
unfixable:
The formula is the tax authority's, and auditors compare the code with it term by term.
reason:
total mirrors section 4 of the tax worksheet as one formula, so an auditor can check it.Commit .config/alibi/rubocop-disable-never.kdl with the code. From then on, the build fails on each new disable comment until it has an alibi, and on each alibi whose code changes, so that someone reads its reason again.
- A tool's rule for its suppressions, such as Clippy's
allow_attributes_without_reason, typescript-eslint'sban-ts-commentwithallow-with-description, or RuboCop'sStyle/DisableCopsWithinSourceCodeDirective. Each covers one tool, and either bans its suppressions or asks for a line of text beside each one, in the code. Alibi covers any tool, asks four questions, and keeps every answer in one file for review. Use both: the tool's rule can keep its suppressions in one form, and an alibi file can ban that form. - A search in CI, such as
grepforrubocop:disable. It finds every match and can excuse none, so a project either bans the form outright or lets each new one through. Alibi excuses one match at a time, and fails again when the code it excuses changes. - A baseline that a tool writes to accept every violation it finds today. With it, the tool accepts every violation at once, with nothing written at each place. Alibi writes one alibi for one match, after four answers, and no command writes alibis for many matches at once.
Each release has a build for each of these platforms. A build carries a Ruby, so the computer needs none.
| Platform | Release archive | Runs on |
|---|---|---|
arm64-darwin |
alibi-arm64-darwin.tar.gz |
macOS 14 or newer, on Apple silicon |
x86_64-linux |
alibi-x86_64-linux.tar.gz |
Linux on x86-64, with glibc 2.38 or newer |
aarch64-linux |
alibi-aarch64-linux.tar.gz |
Linux on ARM64, with glibc 2.38 or newer |
x86_64-linux-musl |
alibi-x86_64-linux-musl.tar.gz |
Linux on x86-64, with musl, such as Alpine |
aarch64-linux-musl |
alibi-aarch64-linux-musl.tar.gz |
Linux on ARM64, with musl |
x64-mingw-ucrt |
alibi-x64-mingw-ucrt.zip |
Windows on x64 |
Alibi has no build for Windows on ARM64 or for macOS on Intel.
- git has to be on the
PATHfor each command that reads the project: a check,alibi init,alibi add, andalibi remove --stale, which checks too. Alibi runs git to learn whether a folder is in a git working tree, and to list its files. Without git, such a command is an error with exit status 2, since walking the folder instead would read build output that git leaves out.alibi list,alibi amend, andalibi removewith IDs read only the alibi file, and need no git. - libgcc, for the musl builds, which load
libgcc_s.so.1from the system. On Alpine,apk add libgccinstalls it. - An editor, named by
$VISUALor else$EDITOR, is where a person at a terminal answers Alibi's questions. It has to wait until you close the file, ascode --waitdoes. Without one, give each answer in a file. - A glob or a pattern on a command line is written
--files=GLOBor--pattern=REGEX, with the whole word in double quotes, as the examples here show. On Windows, Ruby expands a wildcard in an argument, whatever the quotes around it, unless the word starts with--.--files GLOB, with a space, is accepted too, but there Ruby may expand the glob, or a pattern with a wildcard in it, before Alibi reads it.
Until Alibi 1.0.0, a minor release (0.X.0) may change what an alibi file may hold, as Semantic Versioning allows for a 0.y.z version. CHANGELOG.md marks each such change as breaking, and says what to do.
Install Alibi with mise, from its releases on GitHub. Put this in a project's mise.toml, or in ~/.config/mise/config.toml for every project, and run mise install:
[tools."github:setdef/Alibi"]
version = "latest"
strip_components = 1
bin_path = "."
[tools."github:setdef/Alibi".platforms]
macos-arm64 = { asset_pattern = "alibi-arm64-darwin.tar.gz" }
linux-x64 = { asset_pattern = "alibi-x86_64-linux.tar.gz" }
linux-arm64 = { asset_pattern = "alibi-aarch64-linux.tar.gz" }
windows-x64 = { asset_pattern = "alibi-x64-mingw-ucrt.zip" }mise exec -- alibi --version then prints the version it installed. With strip_components and bin_path, mise puts the alibi program on your PATH, and leaves the build's Ruby off it, so that Ruby never stands in for one you use.
mise's github backend applies a default minimum_release_age of 24 hours when it resolves latest, so version = "latest" installs the newest release that is at least a day old. To install a newer release, write its number in place of latest, as in version = "X.Y.Z": mise doesn't hold back an exact version.
On Linux with musl, the recipe above installs the glibc build, since the platforms table of mise's github backend has a key for an operating system and a CPU architecture only, and mise ignores its libc option when asset_pattern is set. Use this recipe in its place:
[tools."github:setdef/Alibi"]
version = "latest"
strip_components = 1
bin_path = "."
[tools."github:setdef/Alibi".platforms]
linux-x64 = { asset_pattern = "alibi-x86_64-linux-musl.tar.gz" }
linux-arm64 = { asset_pattern = "alibi-aarch64-linux-musl.tar.gz" }Without mise, download the archive for your platform from the releases and unpack it. It makes one folder, such as alibi-arm64-darwin, with the alibi program at its top: put that folder on your PATH.
An alibi file bans one pattern in some of a project's files, and holds an alibi for each match the project keeps. Keep alibi files in .config/alibi/ at the top of the project, one for each thing you ban. Alibi writes and changes them: alibi init writes a new one, alibi add adds an alibi, alibi amend changes one, and alibi remove takes alibis out. alibi --help, and --help after a command, print how to use each.
The examples in this section come from two projects: the invoice project of the first example, and a ledger project whose lib/ holds ledger.rb, entry.rb, and period.rb, with a RuboCop disable comment on lines 2 and 6 of ledger.rb.
alibi with no arguments checks each *.kdl file directly in .config/alibi/, in order of name. alibi FILE.kdl ... checks the alibi files you name. Run it in CI, in a pre-commit hook, or in your build task: any status but 0 fails it.
$ alibi
.config/alibi/breakpoint-never.kdl: passed: no matches in 3 files
.config/alibi/rubocop-disable-never.kdl: failed: 2 matches in 3 files: fix the code, or run alibi add .config/alibi/rubocop-disable-never.kdl PATH:LINE for each match with no alibi
lib/ledger.rb:2: def post(entry) # rubocop:disable Metrics/MethodLength
lib/ledger.rb:6: def close(period) # rubocop:disable Naming/PredicateMethodAn argument with a . or a / in it is an alibi file, and so is every argument after --. An argument with neither, such as alibi unsafe, is an error that says to write ./unsafe for a file of that name. add, amend, init, list, and remove are commands only as the first argument, so no command added later can change what a command line with a file in it does.
For each alibi file, Alibi prints one line on standard output that says whether it passed and how many files it checked, then a line for each failure. A match with no alibi gets PATH:LINE: TEXT, which editors link to and grep finds. Paths start at the project root: the top of the git working tree that holds the alibi file. Alibi prints no color. It shows a control character from a file, other than a tab, as an escape such as \x1B, and so too each character that would reorder or break the line around it.
An alibi file passes when every match has exactly one alibi and every alibi excuses exactly one match. Besides a match with no alibi, these fail, each on a line that says what to do:
- A stale alibi, which matches nothing: its code changed or went away, so its snippet occurs nowhere in its file, or the glob no longer matches its file.
- An ambiguous alibi, whose snippet occurs more than once in its file. It excuses none of those places.
- A match with several alibis, when their snippets overlap.
Alibi checks the files git lists: the files it tracks, and the untracked ones it doesn't ignore, so a new file counts before you stage it. It skips a symlink and a submodule. Outside a git working tree, the project root is the folder where you run Alibi, and Alibi reads every regular file under it, with no .gitignore read, so write the glob for the folders you mean. Alibi reads each file as UTF-8, with each CRLF as LF, so a Windows checkout gets the same answer as Linux. A matched file that isn't valid UTF-8, such as an image, is an error: write the glob so that it matches only text files.
| Status | Meaning |
|---|---|
| 0 | Every alibi file passed, or a command did what it was asked, or the command line was --version or --help. |
| 1 | An alibi file failed, and none had an error. Only a check exits with 1. |
| 2 | An error, which outweighs a failure: a command line Alibi can't use; an alibi file that is missing, unreadable, written by hand, or isn't valid; a glob that matches no file; a pattern Alibi refuses; a matched file that isn't UTF-8 text; no git on the PATH; or a bare alibi with no *.kdl file in .config/alibi/. A command that writes an alibi file writes nothing when it exits with 2, except that a walk keeps the alibis it wrote before the error. |
| 130 | You pressed Ctrl-C. Alibi writes alibi: interrupted, with no backtrace, and leaves no file half written. On Linux and macOS it ends by SIGINT, so a shell loop or an && chain stops too; on Windows it exits with 130. |
With several alibi files, Alibi checks each one, and the highest status wins: an error in one alibi file doesn't stop it from checking the others.
Errors go to standard error, one line each, starting with alibi:. A command line that Alibi can't use gets a line for each fault, then a line that says which help to read:
$ alibi --bogus
alibi: Invalid flag `--bogus`: no such flag
alibi: run alibi --help to see how to use Alibi--help anywhere on a command line prints how to use the command it starts with, whatever else is on it, so add it to the end of a command line that failed. alibi add, alibi amend, alibi init, and alibi remove with nothing after them print the same help on standard error, and exit with 2. docs/reference/cli.md has every command, flag, and exit status.
alibi init writes a new alibi file with no alibis. Start from one of the examples, or give a glob and a pattern:
$ alibi init .config/alibi/breakpoint-never.kdl "--files=lib/**/*.rb" "--pattern=binding\.(?:irb|pry)\b" --about-file about.txt
wrote .config/alibi/breakpoint-never.kdl; to check it, run alibi .config/alibi/breakpoint-never.kdl--files=GLOBis the glob of the files the alibi file applies to, from the project root.*matches any part of a name, a name that starts with a dot included,**/matches any number of folders, and braces list alternatives, as in{lib,test}/**/*.rb. Write/between folders on every system.--pattern=REGEXis a Ruby regular expression that Alibi runs over the whole text of each file. It can span lines, and a match on several lines is shown at the line where it starts.^and$match at each line. Write flags inline, such as(?i)to ignore case, or(?m)to let.match a line break.- The about says what the alibi file bans, and why the project bans it, for a reader who wasn't there. It comes from the file you give
--about-file, with-for standard input, or, at a terminal, from your editor. With--no-input, or with no terminal,alibi initopens no editor, and an about that no file gives is an error. --example NAMEtakes the glob, the pattern, and the about from an example, and asks nothing. Add--files=GLOBto fit its glob to your folders.
Before it writes, alibi init refuses, with exit status 2, what a check would refuse: a glob that matches no file, since a typo there would leave the ban unenforced; a glob that is absolute or has a .. segment; a pattern that can match empty text, such as a*; and a pattern that Ruby can't match in linear time, which could hang Alibi:
$ alibi init .config/alibi/todo-never.kdl "--files=src/**/*.rb" "--pattern=TODO" --about-file about.txt
alibi: the glob "src/**/*.rb" matches no file in the project: check it for a typo, or delete the alibi file
$ alibi init .config/alibi/todo-never.kdl "--files=lib/**/*.rb" "--pattern=^(?!\s*#).*TODO" --about-file about.txt
alibi: Ruby can't match the pattern /^(?!\s*#).*TODO/ in linear time, so it could hang Alibi. Common causes are back-references, captures inside lookarounds, nested quantifiers, absence operators, conditionals, and a quantifier followed by more of the pattern inside a lookahead, as in `(?!\s*#)`. Rewrite the pattern without them; Regexp.linear_time? says whether Ruby accepts the patternAlibi accepts a pattern when Regexp.linear_time? says yes for it, in the Ruby that Alibi's build carries, so no list of what it refuses is complete. Back-references, the absence operator, and conditionals always fail that test. A lookahead that holds a quantifier followed by more of the pattern can fail, and the natural pattern for a line that isn't a comment does; move the quantifier out of the lookahead and make it possessive (*+):
| Pattern | Alibi |
|---|---|
^(?![ \t]*#).*\buntyped\b |
Refused: Ruby can't match it in linear time. |
^[ \t]*+(?!#).*\buntyped\b |
Accepted. |
As a backstop, a pattern that runs for more than 2 seconds over one file is an error. A flag given twice, such as --files, is an error too, rather than a choice between the two. alibi init writes only a file that doesn't exist, makes the folders above it, and writes it whole or not at all. No command changes an alibi file's glob or pattern: to change either, write a new alibi file and add its alibis again.
Alibi comes with these examples, in examples/alibi/. Each opens with a comment that says what it bans, why, and what it leaves alone, which alibi init --example makes its about.
| Example | Bans |
|---|---|
cargo-lint-allow-never |
A lint set to "allow" in a Cargo.toml. |
rubocop-cop-enabled-false-never |
Enabled: false in a .rubocop*.yml file. |
rubocop-disable-never |
RuboCop's comments that switch a cop off: disable, todo, push, next, and their -next forms. |
rust-allow-never |
Rust's #[allow(...)] and #![allow(...)], in every form Rust reads. |
rust-allow-unsafe-code-never |
Turning off Rust's unsafe_code lint, with allow or expect. |
rust-expect-never |
Rust's #[expect(...)] and #![expect(...)]. |
steep-ignore-never |
Steep's steep:ignore comments. |
ts-expect-error-never |
TypeScript's @ts-expect-error. |
ts-ignore-never |
TypeScript's @ts-ignore. |
ts-nocheck-never |
TypeScript's @ts-nocheck. |
The Rust examples overlap: rust-allow-never and rust-expect-never ban every lint, and rust-allow-unsafe-code-never bans one, for a project that allows others. A Rust attribute can span lines, and a match is shown at the line where it starts.
An example isn't an alibi file: it has no seal, so Alibi refuses a copy of one. Start from it with alibi init FILE.kdl --example NAME instead.
alibi add FILE.kdl PATH:LINE writes an alibi for the match that starts on that line, where PATH:LINE is the start of the line a check printed for it. When several matches start on one line, add the column: PATH:LINE:COLUMN. Fix the code first if you can: the best alibi file is empty.
Before it writes anything, alibi add asks four questions, one at a time:
tried: what you tried, to fix the code so that it no longer matches.evidence: what shows that the match is necessary at its place, which a reviewer can check without you: an issue, a measurement, a failing test, or a document.unfixable: why no change to the code can remove the match.reason: why the match is necessary at its place, for a reviewer who wasn't there.
Each answer comes from the first of these that has it:
-
A file, given to the question's flag:
--tried-file,--evidence-file,--unfixable-file, or--reason-file.-reads standard input, for one answer per run. No flag takes an answer as text. -
Your editor, when standard input is a terminal and you didn't pass
--no-input. It opens a file for each question, with the match and the question as comment lines below an empty first line, where your answer goes:# lib/ledger.rb:2: def post(entry) # rubocop:disable Metrics/MethodLength # # What did you try, to fix the code so that it no longer matches? # Name each change you made, and what went wrong with it. # If you haven't tried one, stop here and try one first. # # Write the answer above these lines. Lines that start with # are dropped. # To stop and write nothing, leave the answer empty. -
Nothing. With no terminal, or with
--no-input,alibi addshows the first question that has no answer, with the command line that answers it, and exits with 2. An agent reads one question, writes its answer in a file, and runs the command line it was given, four times:$ alibi add .config/alibi/rubocop-disable-never.kdl lib/ledger.rb:2 --no-input alibi: alibi add asks 4 questions before it writes an alibi for lib/ledger.rb:2, one at a time. Question 1 of 4, `tried`, has no answer yet, since --no-input was passed: alibi: What did you try, to fix the code so that it no longer matches? alibi: Name each change you made, and what went wrong with it. alibi: If you haven't tried one, stop here and try one first. alibi: to answer it, write the answer in a file and run alibi add .config/alibi/rubocop-disable-never.kdl lib/ledger.rb:2 --tried-file PATH, with - for standard input alibi: to stop instead, and write nothing: fix the code so that lib/ledger.rb:2 no longer matches, and run alibi .config/alibi/rubocop-disable-never.kdl to check it
To stop, leave an answer empty, in the file or in the editor. alibi add then writes nothing and says to fix the code instead. An editor that exits with a status other than 0, as vim does after :cq, stops it too.
$ alibi add .config/alibi/rubocop-disable-never.kdl lib/ledger.rb:2 --tried-file - < /dev/null
alibi: nothing was written, since `tried` has no answer: fix the code so that lib/ledger.rb:2 no longer matches, and run alibi .config/alibi/rubocop-disable-never.kdl to check itBefore the first question, alibi add refuses, with exit status 2: an alibi file that is missing, written by hand, or isn't valid; a line where no match starts; a line where several start, with the address of each; and a match that has an alibi already:
$ alibi add .config/alibi/rubocop-disable-never.kdl lib/invoice.rb:3
alibi: no match starts on lib/invoice.rb:3: run alibi .config/alibi/rubocop-disable-never.kdl to see where each match with no alibi starts
$ alibi add .config/alibi/rubocop-disable-never.kdl lib/invoice.rb:2
alibi: the match at lib/invoice.rb:2 has an alibi already, the alibi 0a916d4 for "def total(lines) # rubocop:disable Metrics/AbcSize" on line 2: run alibi list .config/alibi/rubocop-disable-never.kdl to read itAfter the questions, it writes nothing when the reason is one that another alibi in the alibi file has, since each reason is written for one place, or when the alibi file changed while you answered: run the command again.
alibi add chooses the alibi's snippet: the fewest lines around the match that occur once in its file, keeping their indent, so a reviewer reads the code as it is. When those lines hold other matches, the alibi gets an occurrence that counts to this one. The alibi excuses that one match:
- Alibi compares the snippet with the file a whole line at a time, without each line's indent, so reindenting the code changes nothing. Everything else on a line counts: the snippet
ydoesn't occur in a file whose line isy # TODO. - A change to the snippet's lines makes the alibi stale, so the next check fails and someone reads the reason again. A change elsewhere in the file leaves the alibi as it was.
- Alibi refuses a blank answer, and two alibis in one alibi file with the same reason once whitespace is collapsed. It checks nothing else about an answer: whether a reason holds up, such as "same as above", is for whoever reviews the change.
alibi add FILE.kdl, with no match named, walks through each match that has no alibi, in the order a check prints them, at a terminal. For each one it shows the match and how many are left, asks the four questions in your editor, and writes the alibi as soon as its answers are in, so Ctrl-C keeps the alibis written so far, and the next walk starts where this one stopped. An empty answer leaves that match for a fix of the code, and the walk goes on to the next, as here, where the editor's file for the first question of the second match was left empty:
$ alibi add .config/alibi/rubocop-disable-never.kdl
lib/ledger.rb:2: def post(entry) # rubocop:disable Metrics/MethodLength
2 matches left; this one starts at lib/ledger.rb:2:19
added the alibi 31c3615 for lib/ledger.rb:2:19 to .config/alibi/rubocop-disable-never.kdl
lib/ledger.rb:6: def close(period) # rubocop:disable Naming/PredicateMethod
1 match left; this one starts at lib/ledger.rb:6:21
nothing was written for lib/ledger.rb:6:21: an answer had nothing in it, so the match is left for a fix of the code
wrote 1 alibi and left 1 match for a fix of the code; to check it, run alibi .config/alibi/rubocop-disable-never.kdlAn editor that exits with a status other than 0 ends the walk, with exit status 2, and the alibis written before it stay. When every match has an alibi, the walk says so, and exits with 0:
$ alibi add .config/alibi/rubocop-disable-never.kdl
no match is without an alibi in .config/alibi/rubocop-disable-never.kdl, so nothing was written; to check it, run alibi .config/alibi/rubocop-disable-never.kdlWith no terminal, or with --no-input, the walk asks nothing. It says how many matches have no alibi, and gives the command line that adds the first, one match at a time:
$ alibi add .config/alibi/rubocop-disable-never.kdl --no-input
alibi: alibi add walks each match with no alibi only at a terminal, and --no-input was passed: .config/alibi/rubocop-disable-never.kdl has 2 matches with no alibi, so add them one at a time, starting with the first: alibi add .config/alibi/rubocop-disable-never.kdl lib/ledger.rb:2:19A file of answers is for one match, so --tried-file and the other answer flags are an error with no match named. Nothing writes alibis for many matches at once: each one costs its four answers.
alibi list prints every alibi in .config/alibi/, or in the alibi files you name, for a reader who wants every reason without reading the code around it: a line with the alibi's ID and path, then its snippet and its four answers, each under its name. With --id, it prints only the alibis of one alibi file whose IDs start with what you give; give --id again for more:
$ alibi list .config/alibi/rubocop-disable-never.kdl --id 0a916d4
alibi 0a916d4 lib/invoice.rb
def total(lines) # rubocop:disable Metrics/AbcSize
tried:
Split total into a method for each term. Metrics/AbcSize still counted the calls on line.
evidence:
docs/tax/worksheet.pdf, section 4, gives the total as one formula.
unfixable:
The formula is the tax authority's, and auditors compare the code with it term by term.
reason:
total mirrors section 4 of the tax worksheet as one formula, so an auditor can check it.An alibi's ID is the first seven hexadecimal digits of a SHA-256 digest of its path, its snippet without the indent, and its occurrence, so it changes only when those do. Alibi refers to an alibi by its ID in every line it prints about it, and a failure line ends with the alibi list command line that shows it. When two alibis in one alibi file start with the same seven digits, Alibi shows each with as many digits as tell them apart, as git does with a short commit hash. Each alibi in the file holds a copy of its ID, so grep finds it.
With several alibi files, each one's name comes before its alibis. alibi list reads only the alibi files, so it needs no git and works on a glob that matches nothing. It exits with 2 when an alibi file can't be read, or an ID start picks no alibi or several, and lists the rest.
A change to an alibi file changes what the project excuses, and git shows it. Each alibi is a block that starts at the left edge, which git reads as the start of a function, so git diff -W (--function-context) shows each alibi that a change touched whole, with its other answers. git log -p -W and git show -W do the same for commits. Here alibi amend changed a reason:
$ git diff -W
diff --git a/.config/alibi/rubocop-disable-never.kdl b/.config/alibi/rubocop-disable-never.kdl
index 32aa235..4654e13 100644
--- a/.config/alibi/rubocop-disable-never.kdl
+++ b/.config/alibi/rubocop-disable-never.kdl
@@ -27,20 +27,20 @@ pattern #"(?<!["'])#\s*rubocop\s*:\s*(?:disable|todo|push|next)\b"#
alibi "lib/invoice.rb" {
id "0a916d4"
snippet #"""
def total(lines) # rubocop:disable Metrics/AbcSize
"""#
tried #"""
Split total into a method for each term. Metrics/AbcSize still counted the calls on line.
"""#
evidence #"""
docs/tax/worksheet.pdf, section 4, gives the total as one formula.
"""#
unfixable #"""
The formula is the tax authority's, and auditors compare the code with it term by term.
"""#
reason #"""
- total mirrors section 4 of the tax worksheet as one formula, so an auditor can check it.
+ total keeps section 4 of the tax worksheet as one formula, so an auditor can check it term by term.
"""#
}
-seal "sha256:115a2329cc236a33e7b6a31e7c48d0ad5dc7fd63cdcc300ab86ccf7623c3268d"
+seal "sha256:4323e08c93ea9a3ba54fc93f5166d6dd6ab1b640de09d8e330858babf404b3a7"To see alibis in a diff as alibi list prints them, with the line alibi ID PATH of the changed alibi in each hunk header, make alibi list git's textconv driver for alibi files. Name the driver for the alibi files in .gitattributes, which is committed:
.config/alibi/*.kdl diff=alibiThen set the driver's command once in your clone. Git takes it from your configuration, never from the repository, so a clone where nobody has set it shows the KDL:
git config diff.alibi.textconv "alibi list"git diff, git log -p, and git show then run alibi list on each version of an alibi file, and compare the lists. An alibi whose snippet changed has a new ID, so a reader sees the old alibi go and the new one arrive. A textconv diff is for reading: add --no-textconv for a patch that git apply takes, or to see a version that alibi list can't read, such as one someone edited by hand, at which git otherwise stops.
alibi amend FILE.kdl ID asks the four questions of one alibi again, and writes the new answers in its place. At a terminal, your editor opens for each question that no flag answers, starting from the old answer. With no terminal, or with --no-input, an answer that no flag gives stays as it was, so one flag changes one answer:
$ alibi amend .config/alibi/rubocop-disable-never.kdl 0a916d4 --reason-file new-reason.txt
amended the alibi 0a916d4 in .config/alibi/rubocop-disable-never.kdl, changing reason; to check it, run alibi .config/alibi/rubocop-disable-never.kdl
$ alibi amend .config/alibi/rubocop-disable-never.kdl 0a916d4 --reason-file new-reason.txt
alibi: no answer of the alibi 0a916d4 changed, so nothing was written: give one of --tried-file, --evidence-file, --unfixable-file, or --reason-file a file with an answer that differs from the one it has, or leave the alibi as it isThe alibi keeps its path, snippet, and occurrence, and so its ID. alibi amend reads only the alibi file, and needs no git. Its editor's file starts from the old answer, and shows the alibi as alibi ID PATH above the question. When a line of the old answer starts with #, Alibi marks the file's comment lines with another character, and says which, so that no line of your answer is dropped. An empty answer stops the command, with nothing written. alibi amend refuses a reason that another alibi has, and an ID that several alibis share, since it can't tell which to change: take them out with alibi remove, and add the alibi again. To change an alibi's snippet, remove it and add it again.
alibi remove FILE.kdl ID ... takes the alibis with those IDs out of an alibi file. It asks no question: fixing the code is what leads to removing an alibi, and version control shows the change and undoes it. Every ID has to pick one alibi, or nothing is removed. Alibis that share an ID go together, and Alibi says so.
$ alibi remove .config/alibi/rubocop-disable-never.kdl 31c3615
removed the alibi 31c3615 from .config/alibi/rubocop-disable-never.kdl; to check it, run alibi .config/alibi/rubocop-disable-never.kdlAn alibi goes stale when the code it excuses changes: fixing the code removes the match, and any other change to the snippet's lines leaves a match with no alibi. Either way, the check fails until the alibi is gone. alibi remove FILE.kdl --stale takes out every stale alibi, which it finds by checking the project, so it needs git. Here someone changed def total(lines) to def total(lines, rate), and the match is still necessary, so it gets a new alibi, with a new ID:
$ alibi
.config/alibi/rubocop-disable-never.kdl: failed: 1 match and 1 alibi in 2 files: fix the code, or run alibi add .config/alibi/rubocop-disable-never.kdl PATH:LINE for each match with no alibi
lib/invoice.rb:2: def total(lines, rate) # rubocop:disable Metrics/AbcSize
lib/invoice.rb: the alibi 0a916d4 for "def total(lines) # rubocop:disable Metrics/AbcSize" matches nothing: run alibi remove .config/alibi/rubocop-disable-never.kdl 0a916d4, and, if its match is still there, alibi add .config/alibi/rubocop-disable-never.kdl PATH:LINE for it; to see it, run alibi list .config/alibi/rubocop-disable-never.kdl --id 0a916d4
$ alibi remove .config/alibi/rubocop-disable-never.kdl --stale
removed the stale alibi 0a916d4 from .config/alibi/rubocop-disable-never.kdl; to check it, run alibi .config/alibi/rubocop-disable-never.kdl
$ alibi add .config/alibi/rubocop-disable-never.kdl lib/invoice.rb:2 --tried-file tried.txt --evidence-file evidence.txt --unfixable-file unfixable.txt --reason-file reason.txt
added the alibi a533552 for lib/invoice.rb:2:26 to .config/alibi/rubocop-disable-never.kdl; to check it, run alibi .config/alibi/rubocop-disable-never.kdl--stale leaves an alibi that fails for another reason, such as a snippet that occurs twice, since its line says how to fix it, and it's an error when no alibi is stale.
An alibi file is KDL that Alibi writes in format 1, the same way each time, so that a diff shows only what changed. It opens with a comment and format 1, then the about, the glob, and the pattern, then a block for each alibi, and it ends with a seal:
// Alibi wrote this file. Change it only with alibi init, add, amend, or remove: an edit by hand breaks its seal.
format 1
about #"""
Bans a breakpoint left in the code: binding.irb and binding.pry.
A breakpoint stops the program at a prompt, which hangs a server or a CI job.
"""#
files "lib/**/*.rb"
pattern #"binding\.(?:irb|pry)\b"#
seal "sha256:651f5d71fe7ba2ef07eaba1b18bd840748390aafef2e2fee849806d809d4ca9a"The seal is a SHA-256 digest of everything above it. Alibi refuses, with exit status 2, a file whose seal doesn't match, so every build that runs Alibi catches an edit made by hand:
$ alibi .config/alibi/breakpoint-never.kdl
alibi: .config/alibi/breakpoint-never.kdl: the seal doesn't match the text above it: something other than Alibi changed the alibi file; undo that changeThe seal has no key. With it, Alibi catches an edit made in an editor, but not someone who reads Alibi's source and writes a matching seal on purpose. Nor does a seal show that an answer is true: review of each change to an alibi file still does that.
A file in format 1 is an error too when an id isn't its alibi's ID, when the about or an answer is blank, or when a node is missing or one that format 1 doesn't have. A file in a newer format is an error that says the Alibi that wrote it reads it.
The seal still matches in a checkout where git turns LF into CRLF, as it can on Windows, since Alibi reads each CRLF as LF.
An alibi file with no format node was written by hand, in the form that earlier versions of Alibi read. Alibi reads only an alibi file that it wrote and sealed, so it refuses such a file with exit status 2, and says how to create it anew:
$ alibi .config/alibi/todos.kdl
alibi: .config/alibi/todos.kdl: was written by hand, and Alibi reads only an alibi file that it wrote and sealed: move it aside, run alibi init .config/alibi/todos.kdl --files=GLOB --pattern=REGEX with its glob and pattern, then run alibi add .config/alibi/todos.kdl, which walks each matchMove the old file out of .config/alibi/, since alibi init never replaces a file. Run alibi init with its glob and pattern, and an about, which can be the comment that opens the old file. Then run alibi add, which walks each match and asks the four questions for it: an old reason answers reason, and tried, evidence, and unfixable are the questions that a hand-written alibi never had to answer. A copy of an example is written by hand too, and the line for it says to start from that example:
$ alibi .config/alibi/steep-ignore-never.kdl
alibi: .config/alibi/steep-ignore-never.kdl: was written by hand, and Alibi reads only an alibi file that it wrote and sealed: move it aside, run alibi init .config/alibi/steep-ignore-never.kdl --example steep-ignore-never, then run alibi add .config/alibi/steep-ignore-never.kdl, which walks each matchdocs/reference/cli.md: every command, argument, flag, and exit status, generated from the same file asalibi --help.CHANGELOG.md: what changed in each release, breaking changes marked.docs/glossary.md: the words in Alibi's messages and documentation, such as match, snippet, stale alibi, and seal, each with its meaning.examples/alibi/: the examples, each with a comment on what it bans and why.docs/contributors/design/check.md: how Alibi works and why it's built this way, for people who change it.
Open an issue at github.com/setdef/Alibi/issues. Include what alibi --version prints, your platform, the command line you ran, what it printed, and its exit status. For a wrong verdict, include the alibi file and the lines of the file it read, or the smallest project that shows the problem.
CONTRIBUTING.md has the project's rules for changing it: how to run the tests, commit to the trunk, and write the documentation.
Alibi's code is under the MIT License, and its documentation under CC BY 4.0, copyright setdef. The examples in examples/alibi/ are under MIT-0, which requires nothing of you, not even a notice, so an alibi file you start from one is yours to use as you like.
I use three words for how code and prose comes to exist. Code or prose I wrote, I typed by hand, with nothing generated. Code or prose I wrought, an AI agent generated while I iterated with it, and I reviewed every change before committing it, so I take responsibility for every diff. Code or prose I requested, an agent built with little or no review from me, in the style of a "dark factory."
Alibi's code, tests, and documentation, this README included, were requested. Agents built them from my goals and decisions. In place of review, the project's rules require every change to be test-driven, every line and branch to be covered by tests on every system CI runs, and every change to pass RuboCop, Steep, RubyCritic, RDoc coverage, reuse lint, and Alibi's own check that the project switches none of those checks off before it lands. declare-ai.org.