Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

restatement

A sentence a diff removed that is still asserted, word for word, somewhere else in the tree. The check reads the removed lines of the diff, subtracts anything the same file’s diff also added, and searches every tracked file it reads for the words that remain. A surviving copy is an advisory finding: the diff retracted something in one place, and the same thing is still said in another, and someone should look. It is advisory because the same sentence can legitimately live in two places on purpose, a summary and the page it summarises, and the check cannot tell a retraction from an edit to one copy of two.

What it checks

The diff is read file by file, and only the removed lines of a file whose extension is in scope count. The built-in scope is .md, .swift, .py, .sh and .yml, and extensions adds to it. Before a removed line is searched for, the words the same file’s diff added are subtracted: a reflowed paragraph removes and re-adds most of itself, and a thing still said in the same file is not a thing retracted. The subtraction is per file, so an unrelated addition elsewhere in the diff cannot cancel a genuine retraction.

In a source file only the comment text is read, on every side: the removed lines, the added lines subtracted from them, and the lines searched for survivors. Code contributes no words, so a line of code deleted from one file and still present in another is not a finding. Four extensions are read this way:

  • .py: # comments and docstrings. A docstring is a triple-quoted string, """ or ''' with an optional r, u or b prefix in either case, whose opening quotes begin a line after indentation; a string assigned or passed on the same line, x = """..., is code.
  • .sh: # comments.
  • .rs and .swift: every comment, //, ///, //! and /* */, not only doc comments. A block comment nested inside another is read to the outer one’s close.

A comment that trails code on the same line counts, its comment part only. A #, // or /* opens a comment only at the start of a line or after whitespace, so ${x#y}, $# and http:// are code, and a shebang on the first line is not a comment. In a .py file a string on one line is code, so "a # b" holds no comment and '"""' opens no docstring; a docstring is not ended by an escaped \""". In the other three, strings are not recognised, so a comment marker inside one, "a // b", is read as the start of a comment. Each line is classified in the context of its whole file, the old version for a removed line and the new one for an added or surviving line, so a line deep inside a docstring or a block comment is comment text even when its opening is lines away. Every other extension in scope, .md and .yml included, is read whole, line by line.

Comment text and prose are compared with each other in both directions: a sentence retracted from a Markdown page and still present in a docstring is found, and so is the reverse.

Each line is reduced to its words before anything is compared: link syntax is replaced by its text, inline markup characters become spaces, letters are lowercased, and every other character becomes a space too. A sentence that survives with different emphasis or a re-pointed link is the same sentence.

Two modes search for what remains, and each finding names the one that fired:

  • restatement-ngram takes every run of six consecutive words the diff removed and did not add back, and reports a line anywhere in scope that still contains one. A line with several matching runs is reported once, quoting the one with the most characters.
  • restatement-whole-line takes every removed line of at least ten words whose whole word sequence does not reappear in the file’s added words, in order, across line breaks, and reports a line anywhere in scope that reduces to exactly the same words. In a source file the line is its comment part alone, still of at least ten words.

Six is the run length because eight missed a real restatement that differed from the retracted sentence by one word. Neither length is configurable.

The check is verbatim only. A file that restates the removed fact in different words shares too few consecutive words for the first mode and does not match line for line for the second, and is not found. That is by design and not a gap to close: telling a paraphrase from a different claim is a judgment, and the mechanical half of this tool does not make judgments.

A survivor is reported only while the removed text exists in at most duplication_threshold other files, one by default. A sentence in two places, the edited file and one survivor, is exactly the case the check exists for and is reported; a banner or licence line in three or more is text duplicated on purpose, where removing one copy says nothing about the others, and every copy of it is suppressed. The count is taken over the files that still hold the text, so a line present in two survivors is over the default threshold whichever of them is read first.

A line the diff itself added is never a survivor, in any file. Because the subtraction is per file, a sentence moved from one file to another counts as removed from the first, and its new copy would otherwise be reported as the survivor of its own removal; whoever wrote that line in this change meant it. A run of six words is set aside only when every word of it is on an added line: a run that starts on an untouched line can be a real survivor wrapping onto a line the diff edited, so moved text rewrapped to start at the end of an untouched line is reported there. An old last line with no newline that the diff only gave one, by appending after it, is not an added line. Added lines are set aside before the threshold counts files, so a moved copy neither pushes an untouched survivor over the threshold nor is reported in its place: a sentence moved from one page to another, with an untouched copy in a third, is reported at the third. A line the diff did not add is still a survivor, even in a file the diff otherwise changed.

The check is diff-scoped: with nothing removed there is nothing to search for, and a survivor left behind by an earlier commit is not reported on a later one. The survivor sweep itself is whole-tree over every tracked file in scope, so a copy in a file the diff never touched is found. It reads each file as it is on disk, so a --diff-range that does not end at the checked-out files can misplace or miss a survivor. The check runs no command.

One survivor comes from a mark rather than the diff. When a change rewords a line that held a marked restatement-ngram survivor and keeps the quoted run, the change both removes and re-adds the run in that file, so the diff alone retracts nothing. The mark committed at HEAD still records the earlier retraction, so a run whose range reaches the working tree, the commit hook’s included, searches for that run again and reports it on the reworded line, with the line and message a range over both commits reports. Marking it in the commit that rewords the line quiets both. The old mark is reported as an orphan too, and pruning it does not lose the finding, since the mark is read as committed. A rewording that drops one of the quoted run’s words raises nothing here, even where a shorter run the earlier commit also retracted survives: a range over both commits reports that run, and only there.

Why it exists

A fact that lives in two files is corrected in one. The edit that retracts a sentence is the one moment when the author knows it was wrong, and the check uses that moment: the removed line is the search term, and the search finds the copy the author did not remember. A whole-tree duplicate finder would report every deliberate pair on every commit; starting from what the diff retracted is what makes the finding worth reading.

Example

The example is a committed step and a pending edit. The step holds three pages that share a banner line, two of which also share a sentence about eviction, and a third that says the same thing in other words:

examples/restatement/history/01-states/docs/overview.md:

# Overview

This page is part of the AI Radio operator handbook and is maintained by hand.

The cache keeps one entry per path and never evicts an entry on its own.

examples/restatement/history/01-states/docs/setup.md:

# Setup

This page is part of the AI Radio operator handbook and is maintained by hand.

There is nothing to configure.

The cache keeps one entry per path and never evicts an entry on its own.

examples/restatement/history/01-states/docs/faq.md:

# FAQ

This page is part of the AI Radio operator handbook and is maintained by hand.

Nothing is ever evicted from the cache; an entry stays until restart.

The pending edit rewrites the overview, removing the banner and the sentence and saying the opposite of the sentence:

examples/restatement/docs/overview.md:

# Overview

Entries are evicted once the cache passes its size limit, oldest first.

Run with that edit staged, the check reports:

# python3 scripts/capture.py: restatement, run against a throwaway git repository seeded from examples/restatement
[advisory] docs/setup.md:7 (restatement-ngram) still says: ...entry per path and never evicts...
[advisory] docs/setup.md:7 (restatement-whole-line) still says: the cache keeps one entry per path and never evicts an entry on its own

Both findings are the one surviving copy of the retracted sentence, in the setup page, once from each mode: the first quotes one six-word run the two lines share, the second quotes the whole line as words. The FAQ says the same thing and is not reported, because it says it in different words; that is the verbatim limit, and a reader who wants the FAQ found has to search for it. The banner was removed too, and survives in both the setup page and the FAQ, which is one file more than the default threshold allows, so neither copy is reported.

Without the edit, the same three pages report nothing: the check starts from what a diff removed, and a duplicate that no diff has touched is not a retraction.

The fix for a finding is to retract the surviving copy too, or to leave it if the two really are meant to differ; and where a line is shared on purpose across many files, to raise duplication_threshold rather than dismiss the finding each time.

Configuration

[restatement]
exclude = ["examples/*"]
historical = ["CHANGELOG.md", "RELEASES.md"]
extensions = [".rs"]
duplication_threshold = 3
KeyShapeDefaultReach for this when
excludelist of glob strings; a bare string is a one-element list[]: nothing excludedA file is expected to keep retracted prose on purpose, such as a directory of inputs written to be broken, like this site’s own examples. An excluded file contributes no removed lines from its own diff, and is dropped from the survivor sweep entirely, so it neither counts toward another file’s duplication nor is reported for it.
historicallist of glob strings; a bare string is a one-element list[]: every file is swept for survivorsA file is an append-only record, a changelog or release notes, whose shipped entries your own rules forbid editing, so a survivor in one is never something to fix. A line in it that the diff did not add is never a survivor and never counts toward duplication_threshold, and nor is a run of six words starting on one. A line the diff did add is read as in any file: a run that starts on it and wraps onto a shipped line is still reported there. Its own diff is still read: a line removed from it, such as an edit to an [Unreleased] section, is searched for elsewhere like any other retraction, which exclude would stop.
extensionslist of dotted suffixes; a bare string is a one-element listthe built-in set alone: .md, .swift, .py, .sh, .ymlThe project has prose or source in a language the built-in set does not cover, .rs for a Rust project, and wants its retractions and its survivors read too. Entries are added to the built-in set, never substituted for it. .py, .sh, .rs and .swift are read as comment text only, as described above; any other extension, built-in or added, is read whole, code included.
duplication_thresholdinteger; a boolean or a non-integer is a configuration error1Text is duplicated on purpose across more files than the default tolerates, a shared licence header or a generated banner, and each copy is reported every time one of the others changes. 0 reports nothing at all, since every survivor is in at least one file; the lowest useful value is the default.

enabled, which takes this check out of the commit gate while leaving it in the on-demand skill and the CLI, is shared by every check and covered on Configuring claims.

Retirement markers

None. A surviving copy inside a blockquote, an italicised sentence or a paragraph opening “Previously said:” is reported like any other line, because the words are compared after markup is stripped and a blockquote marker is markup. The retired-quote exemption skips a sentence quoted in order to retire it; here a retired quotation of the removed sentence is a survivor in the plain sense, and a file that keeps such quotations on purpose belongs under exclude.

Next

spliced-docs, which reads Swift and Rust doc comments for one that an insertion has pushed onto the wrong declaration.