Skip to main content
An anchor is a locator plus a selector. The locator names a resource; the selector picks one unit inside it, so that hibi can find that unit again after the file is edited.

Locators

Selectors

The empty selector {} selects the whole resource (its file unit). A selector holds no position: where a quote stood is never used to decide which unit it names.

Compact anchors on the command line

--subject, --evidence and the other anchor options take a compact string: The part after the first :: is the quote, taken verbatim. The part between # and :: is the symbol. For an external scheme, a compact anchor is the locator alone, with the empty selector. Compact syntax is split at the first :: and then at the first #, so an anchor whose path contains # or ::, or whose symbol contains ::, must be written as JSON. So must any selector other than the empty one for an external scheme (such as a key). Give those as an object {"loc": ..., "sel": {...}}. An anchor option whose value starts with { is read as such an object, also after the n= of reanchor --evidence. In a hibi claim --stdin document an anchor is a compact string, an object, or a string that holds the object as JSON, such as an anchor copied from an error or a candidate. This example assumes the scheme ref is declared in .hibi/hibi.toml and its provider is registered in your user config (see external providers):

Which anchor to write

  • Code: a name. Write #name to follow a declaration, or #name::<line> to follow it and say which line of it the claim is about. With a line, editing that line asks you for a new anchor; editing the rest of the declaration only asks you to re-check.
  • Prose, and code outside any declaration: a quote. Quote the words the claim is about. A whole sentence is a good quote; a short phrase works when no other unit of the file holds it.
Quote whole lines or whole tokens when you type a quote. A quote is matched as text, so the line of a #name::<line> anchor that ends inside a number or a word still matches after an edit: A = 1 still occurs in A = 10, and the side is only changed, not gone. A bare quote there goes missing, because the text right after it changed. A bare quote on a line inside a function follows the text, not the function. claim accepts it and prints a note with the anchor that follows the declaration instead:
output
In JSON the same sentence is in the entry’s notes.

Stored anchors are completed

hibi never stores a selector as you typed it. It resolves the anchor and stores the selector the provider returns for the unit it found:
  • #name stores the symbol alone, and count when the name has several declarations.
  • #name::<line> stores the symbol, the quote, and the text right around the quote inside the declaration.
  • A quote stores the quote, the text right around it inside its unit, and the container (within), with count when the container’s path names several containers.
This is what reanchor printed for the walkthrough’s claim:
output
The sentence is in the section “Retries”, in the paragraph whose first sentence is “The client retries a failed download.”. The evidence was given as #MAX_ATTEMPTS and stores only that.

Finding the unit of a new anchor

A quote that differs from the text only in the length of its runs of whitespace, for example after a paragraph was re-wrapped, counts as an exact occurrence. Whitespace where the text has none, or none where it has some, does not. An anchor as you type it must select one unit. Occurrences of the quote inside one unit resolve to that unit. Occurrences in more than one unit are side_ambiguous, whatever the length of the quote. The error lists the units, at most 20 and then how many more, each with an anchor that selects it, so you can pass one of those or make the quote longer; in code you can also add a symbol:
output
Units that are identical where they stand have no anchor that selects one of them alone. The error says so instead of printing an anchor:
output
Identical units are reported this way, as side_ambiguous with each unit marked as not selectable alone. Anchor the unit that contains them instead. The last sentence of the message names it: a declaration only when one declaration holds every unit of the file that cannot be told apart from a listed one, also those not listed, and otherwise the whole file. The code quote_not_distinguishable is a guard behind this: before a new anchor is stored, the file provider resolves the anchor it would store, and refuses the new anchor with this code when that anchor does not select the same unit alone.

How a stored anchor finds its unit

A stored anchor identifies its unit in one of two ways, and nothing else resolves it. By name. You wrote #name, or #name::<line>. The claim follows the declaration with that name for as long as the name refers to the same number of declarations as when the claim was made. Its body can change: the side is then changed, and you re-check and mark. With a line, the line must still be in the declaration. When it was edited or removed, the side is changed with the detail “the stored quote is no longer in this unit”, next is a reanchor, and mark refuses the claim, because a mark would keep a line that is no longer in the code. By place. You quoted text. The claim follows those words inside the same scope, with the text right around them, inside the same unit, unchanged. The container of a unit is its section (one heading and the text below it), plus the paragraph, list item or table row when that holds several sentences; in code it is the enclosing declaration. hibi stores the container’s path, and the scope is every container that path names: sections with the same heading path, paragraphs whose first sentences start with the same 120 characters, and declarations that share a symbol. The claim resolves while the path names as many containers as when the claim was made. Everything else is a candidate that you choose. hibi lists the units that have the content that was marked first, then its guesses, and it never puts a candidate into a command. Content alone never identifies a unit, so a copy of the text in another scope is only offered as a candidate. A copy in the same scope can take the claim over; the limits say when. A unit that has no container is found in its whole file. That is plain text, a one-sentence paragraph, list item or table row above the first heading, and code outside every declaration.

What an edit does

Editing quoted text

Here the claim quoted 30 s in “Each attempt times out after 30 s.”. That sentence now says 45 s, and 30 s appears in the next sentence instead. The candidate is that other sentence, not the one that was checked: a candidate is a guess, so read the file.
output
mark refuses the claim until you re-anchor it or retire it. An edit far from the quote, in a long sentence, leaves the quote and the text right around it in place. The side is changed, and status prints the sentence as it is now:
output

Editing the container

The first 120 characters of a paragraph’s first sentence name the paragraph. In the example above it changed from “Each attempt times out after 30 s.” to ”… 45 s.”, so a claim on the unchanged third sentence of that paragraph is missing as well, with that sentence as a candidate. The sentence has the content that was marked, so it is listed first:
output
A renamed heading does the same to every claim under it. Here ”# Limits” became ”# Queue limits”:
output

Sections with the same heading

A section is one heading and the text below it, so two sections can have the same heading path, for example after a template section is pasted. Here docs/guide.md had one section “Example” under “Retries”, with a claim on its sentence, and a second “Example” section was pasted below it. The path now names two sections, so the claim no longer resolves:
output
The printed anchor carries count. Re-anchored, the claim stores the path and the count, and resolves in both sections together while the path names two:
output

Copied text

A copy in another scope is a candidate, never the claim’s unit. Here the sentence “Downloads time out after 30 s.” was copied from the section “Timeouts” into the section “Limits”, and the original was then changed to 45 s:
output
Inside one scope it is different. A one-sentence paragraph, list item or table row copied in its own section, with the original then edited, is followed: nothing tells the copy apart from the original. The claim stays fresh, now on the copy:
output
status cannot show this. hibi cover does: the edited original is listed as uncovered. hibi cover --since <range> lists units whose key and content are new since the base, so it does not list a copy whose original was edited; run hibi cover without --since after copying text.

Renamed functions

In code, renaming the function around a bare quote makes the claim a candidate in the same way. The claim made with the note above, after delay was renamed to delay_ms:
output

Editing the line of a name anchor

A claim on src/wait.py#wait::time.sleep(BACKOFF_SECONDS * 2 ** n), after the quoted line was edited from 2 to 3. The side prints the declaration as it is now, and next asks for a new anchor:
output
output
After re-checking the statement, give the edited line:
When the line moves into another declaration, the name and the quoted text point to different units. Both are candidates, the declaration with the name first. Each candidate’s anchor is the name alone, and the note after it says to add ::<line> again:
output

Duplicated declarations

A claim on src/queue.py#limit, made while the file had one def limit(), stops resolving when a second def limit() is added above it. The name now refers to two declarations, and both are listed in file order. The one with the content that was marked is labelled, and has sameFingerprint: true in JSON:
output
The printed anchors name the symbol, how many declarations it has, and a line that only that declaration holds. Such an anchor resolves while the name has that many declarations, and its scope is all of them: when its line is copied into another declaration of the name and the original line is then edited, the claim follows the copy (see limits). In src/parse.py a claim was made on the int stub of three @overload declarations of parse, with the anchor printed for it. Its signature was then changed to x: float, so the stored line is gone and every declaration is a candidate:
output

Why a side is not_exact

The line under a not_exact side, its detail in JSON, and the side_missing error of mark, claim and reanchor, after “resolves to no unit (not_exact):”, say why nothing resolved: A new anchor that only similar text was found for fails with selector_not_exact, and its message says “the anchor matches no unit exactly” after the side and its locator.

Candidates

The candidates of a side come first from the units of the side’s file whose content equals what the claim’s reference mark recorded (sameFingerprint: true, printed as “same content as at the reference mark”). Then come the provider’s guesses: units that hold the stored quote exactly, then units the quote runs across, then a unit with similar text. A unit is listed once. The same list appears in the side_missing errors of mark, claim and reanchor. A candidate is never used as the side’s unit: the claim is stale, mark refuses it, and next asks you for an anchor. Freshness is always exact fingerprint equality. Candidates are guesses, and the right unit may not be among them. A unit that moved to another file is never a candidate, because only the side’s own file is searched. A declaration that was renamed is not a candidate for a claim that names it with #name alone; with #name::<line>, or a quote inside it, the units that still hold the quoted text are candidates. Look for it yourself and give its anchor. Each candidate carries an anchor that selects it alone. The anchor is <loc>#<symbol> when that symbol occurs once in the whole file, and the unit’s full anchor as JSON otherwise. A printed anchor quotes the unit’s first line, its whole text, a run of its lines when neither of those selects it alone, or for a duplicated declaration the first line only it holds. That can be wider than the words the claim was about, or another line of the declaration. A first-line quote is cut at 120 characters and any other quote at 2,048, so it can end inside a word; it still selects its unit. The advice to quote whole lines or tokens is for quotes you type. When the claim is about particular words, such as a number or one line of code, anchor the candidate with a quote of your own instead (<loc>::<words> or <loc>#<name>::<line>). Units that are identical where they stand have no such anchor: they are listed without one, and a line under the side says what to do instead. Here the sentence was copied, unchanged, inside its own paragraph:
output
In JSON such a candidate has "anchor": null. At most 20 candidates are listed, with the count of all of them. In the text output, each candidate’s | line shows its text on one line, cut to 100 characters. When two candidates would show the same line, each shows a line that no other candidate shows, or its place in the file. --detail prints a candidate’s whole text, in the text output and in JSON. Without it, a candidate’s JSON text is cut to 240 characters, and text that is cut ends with … (<n> characters), the length of the whole text. A new anchor whose symbol names several declarations is ambiguous and lists them, at most 20 and then how many more. Two Python functions with the same name give JSON anchors:
output

Limits

These follow from the rule and are accepted. This list is the one place that states them; other pages link here.
  • A sentence split far from its quote stays with the half that holds the quote. That half is changed. A split in the first 120 characters of a paragraph’s first sentence is the exception: it renames the paragraph.
  • A name anchor follows the name. If the declaration is replaced by different code with the same name, the side is changed, and the re-check is yours.
  • An edit to another sentence has no effect, except an edit that renames or restructures the container: editing the first 120 characters of a paragraph’s or list item’s first sentence, deleting or inserting that sentence, editing the first cell of a table row, splitting a paragraph, joining two (for the second paragraph’s claims), removing the other sentences of a paragraph or list item, renumbering an ordered list or changing its marker, reflowing a blockquote, and an edit in the first 120 characters of a claimed first sentence. These turn the claims on that paragraph, item or row into candidates, usually with the right sentence listed first.
  • A scope is every container the stored path names, and it can be wider than one section, paragraph or declaration. It holds the sections with the same heading path, the paragraphs or list items whose first unit starts with the same 120 characters, a subsection and a paragraph of its parent section whose first 120 characters read the same as the subsection’s heading, and the declarations that share a symbol: Java and TypeScript overloads, a Python function defined twice, and Rust impl Display for Id and impl Debug for Id, which both define Id.fmt. Headings are compared without inline markup: a link or image counts as its text, and backticks, *, ~ and every run of _ except one between two letters or digits are dropped, also inside a link’s text. So **Retries** and Retries read the same, but max_retries and maxretries are two sections.
  • Inside one scope a copy is followed. A sentence, list item, table row or line of code copied in the scope, with the same text around it inside its unit (the same 48 characters on each side, or the same start or end of the unit), takes the claim when the original is then edited, also for #name::<line>. In code that text is read with every comment as one space, so editing a comment next to a quote changes nothing. With overloads or a function defined twice, the copy can be in another declaration of the same name. For a copied line the side is then changed with next: hibi mark, shows the same name and only other line numbers, and the mark is accepted, so read the line. When a declaration’s whole body is copied into another declaration of the same name (two fmt methods in two impl blocks of one type, a Python function defined twice, two Go init functions), the side is first missing or ambiguous, and once the original is edited the claim follows the copy and stays fresh. A Python claim can end up on the earlier definition, which the module does not use.
  • A copy in another scope is a candidate, never the claim’s unit.
  • A pasted copy can become the claim’s place. When a paragraph or section is pasted again under the same heading, its claims become candidates. When the original’s first sentence or heading is then edited, the stored name names only the copy, and the claims resolve on the copy, fresh.
  • Two numbered lists in one section are one scope. It takes two edits for a claim to move between them: a step removed from the first list, which renumbers its items, and an item of the second list edited to read as the claimed item did. A claim on the item 3. Ship. in the first list then follows the item 3. Ship. in the second list, fresh. One removal alone makes the claim missing or ambiguous.
  • count cannot see a swap. When one of several sections with the same path is removed and another with that path is added, or one is emptied with its heading kept and its text is pasted into another, empty section of that name, the count is unchanged, and the copy can take the claim.
  • Identical units in one scope cannot be anchored one by one. When you claim, anchor the unit that contains them, as the message names it. In cover, exclude each such unit by its key: a claim on the containing unit does not cover them.
  • Plain text, a one-sentence paragraph above the first heading and code outside every declaration have no container. Identical units there cannot be claimed: a quote of one is side_ambiguous, and no anchor is offered for either. When a unit there is copied and the original is then edited, the copy takes the claim.
  • A renamed or deleted heading, paragraph or declaration makes the claims in it missing until they are re-anchored, with the units that still hold the quoted text as candidates, unless another container then has the old name: a section or function renamed to it, or a pasted copy (above). Then the claims follow that name.
  • A function renamed while its claim names it alone shows no candidate. Find it yourself, as in renames.
  • cover reads a file once for each item it lists, so a single file with many thousands of units is slow.
  • An external provider decides by itself which unit an anchor identifies. See external providers.

Write checks: every side resolves exactly

When an anchor is new (in claim, or a replaced or added side in reanchor), it must resolve to exactly one unit, exactly:
output
output
With #symbol::quote, the quote must occur inside that declaration. A quote that is not found there, such as text from a doc comment written above the declaration, makes the anchor selector_not_exact (or quote_in_comment when the quote lies in a comment inside it):
output
A quote copied from a member line keeps its leading indentation and a trailing , or ; and still resolves to that member: file:src/pair.rs:: pub left: u32, selects the field Pair.left. A quote must lie inside one unit, also when a symbol names several declarations:
output
A #symbol needs a file with declarations. On a markdown, prose or plain text file it is refused:
output
Two evidence anchors that resolve to the same unit are refused, however they are written:
output
mark and a reanchor that keeps a side make the same check on the stored anchor: every side must resolve to exactly one unit. A side that is missing or ambiguous makes them fail with side_missing or side_ambiguous, and the error lists the candidates.

Quotes inside code comments cannot be anchored

The code fingerprint ignores comments, so a claim anchored to a comment could never go stale. A quote that lies wholly or partly inside a comment is refused, and that includes documentation comments: JSDoc, rustdoc and Javadoc.
output
A Python docstring is a string, not a comment. It is part of the fingerprint and can be anchored:
output

Renames

hibi keeps no alias for a renamed or moved unit. When a stored symbol names no declaration, the side is missing with reason selector_not_found, and the claim is stale until someone re-anchors it. A renamed declaration is not listed, because its first line changed with its name. Renaming the Python function limit to queue_limit gives:
output
Find the function, for example with git diff. If it is the same function and the statement still holds, anchor to it:
output
Here the statement named the function, so it changed too. A rename of an enclosing container (a struct, class or module) changes a member’s path but not the member’s content. The member is a candidate with “same content as at the reference mark” (sameFingerprint: true in JSON). Renaming the struct Config to Settings gives, for a claim on its field Config.timeout_secs:
output
The field has the content that was checked, so after reading it, hibi reanchor c1-796b --evidence 1=file:src/config.rs#Settings.timeout_secs stores the new symbol.