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
#nameto 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.
#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
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:#namestores the symbol alone, andcountwhen 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), withcountwhen the container’s path names several containers.
reanchor printed for the walkthrough’s claim:
output
#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 areside_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
output
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 quoted30 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 ismissing as
well, with that sentence as a candidate. The sentence has the content that was marked, so it is listed first:
output
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. Heredocs/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
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
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, afterdelay was renamed to delay_ms:
output
Editing the line of a name anchor
A claim onsrc/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
::<line> again:
output
Duplicated declarations
A claim onsrc/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
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
"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 Idandimpl Debug for Id, which both defineId.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**andRetriesread the same, butmax_retriesandmaxretriesare 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 thenchangedwithnext: 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 (twofmtmethods in twoimplblocks of one type, a Python function defined twice, two Goinitfunctions), the side is firstmissingorambiguous, 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 item3. Ship.in the second list, fresh. One removal alone makes the claimmissingorambiguous. countcannot 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
missinguntil 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.
coverreads 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 (inclaim, or a replaced or added side in
reanchor), it must resolve to exactly one unit, exactly:
output
output
#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
, 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
#symbol needs a file with declarations. On a markdown, prose or plain
text file it is refused:
output
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
output
Renames
hibi keeps no alias for a renamed or moved unit. When a stored symbol names no declaration, the side ismissing 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
git diff. If it is the same function
and the statement still holds, anchor to it:
output
sameFingerprint: true in JSON).
Renaming the struct Config to Settings gives, for a claim on its field
Config.timeout_secs:
output
hibi reanchor c1-796b --evidence 1=file:src/config.rs#Settings.timeout_secs
stores the new symbol.
