status reports when they change, and cover lists the ones without
a claim.
Two halves of the setup
A provider is set up in two places, on purpose:-
The repository declares the scheme in
.hibi/hibi.toml. This never names a command: -
Each user registers the command in their own user config (see
configuration):
hibi status on someone else’s
code into running their code. A command key in hibi.toml is refused:
output
unavailable
with reason provider_not_registered, no command is run, and next is
hibi providers:
output
hibi providers shows what is set up and prints the lines to add for what is
not. It starts no provider. In this run HIBI_CONFIG pointed at a user config
that does not exist yet:
output
remediation field holding those lines, or null when nothing is missing.
Using provider units in claims
A compact anchor on an external scheme is the locator alone, with the empty selector. What the empty selector matches is up to the provider; the reference provider answers it with every unit of the resource:output
output
hello is refused before
anything is sent, and the remediation names the keys it accepts:
output
n1, the claim goes stale
like any other:
output
output
The protocol
Protocol version 1. The full specification is section 13 ofdesign/SPEC.md;
hibi schema provider-request, hibi schema provider-response and
hibi schema unit print the JSON Schemas.
Transport
- hibi starts
command[0]with the other elements as arguments, without a shell, in the root directory. A program name without/is looked up onPATH; give any other program as an absolute path. Relative arguments are read by your program, which runs in the root directory. The environment is inherited, plusHIBI_ROOT(the absolute root) andHIBI_PROTOCOL=1. - One process per scheme per hibi run, started only when a locator of that scheme is needed.
- Every message is one JSON object on one line. hibi writes requests to the provider’s standard input and reads responses from its standard output. Standard output carries protocol lines only; write diagnostics to standard error, of which hibi keeps the last 4096 bytes for its error messages.
- Requests are sequential. The first is always
hello. - Each response must arrive within
timeout_ms(default 10000, from 100 to 600000). A provider that stops reading its input fails when that limit expires, like one that does not answer. A response line longer than 16 MiB is a violation. - When it is done, hibi closes standard input. The provider must then exit
with status 0 within 2 seconds; hibi kills it after that. In a normal run
hibi does not read output written after the last response;
hibi providers --check <scheme>reads at most 65,536 bytes of it and fails the case when there is more, and it also checks the exit status. - A provider that writes a line when no request is waiting, or exits while a child process still holds its output pipes, is treated as failed at once.
- On a timeout, an oversized line, a line that is not a JSON object, a
response with the wrong
id, or an unexpected exit, hibi kills the provider for the rest of the run, and every side it had not answered isunavailablewith reasonprovider_failed. The claim’snextis thenhibi providers --check <scheme>, which runs the provider and reports each conformance case. Here the registered command isfalse:
output
Requests
Each request is{"id": <n>, "method": <name>, "params": {...}} and each
response is {"id": <n>, "result": ...} or
{"id": <n>, "error": {"code", "message"}}. This is a real session with the
reference provider and the fixture shown below; requests first, then the
responses in order:
output
output
Inside a batch, an inner
hello or batch is answered with the error
invalid_request; the other inner requests are answered as usual, errors
included, and the batch itself still succeeds.
Lines that are not requests
A provider answers every line it reads, and keeps running:Selectors
A selector sent inresolve is an object with at most these keys, and only
the keys the provider listed in selectors in its hello:
Listing
quote in selectors also allows prefix, suffix, within
and, together with within, count; listing symbol also allows
count. hibi sends these keys when they
are in a stored sel your provider returned, or in an anchor given as JSON,
which hibi sends as typed. The empty selector {} is
always allowed. A selector is closed: hibi never sends
a key the provider did not list, and rejects a returned sel with an unknown
key or an unlisted one. A stored selector with a key your provider no
longer lists is not sent: the side is unavailable with reason
selector_refused, and next asks for a new anchor.
Units
A fingerprint is
b3:<profile>:<hex>: b3 says the digest is BLAKE3,
<profile> names how the provider normalized the content and matches
[a-z][a-z0-9-]*, and <hex> is 32 to 64 lower-case hex digits, the start
of the digest. hibi checks only this format and never recomputes a digest:
two fingerprints are equal only when the strings are equal. What goes into
the digest is the provider’s choice. It must be the same for the same
content and change whenever a change should make claims stale. Use your own
profile name, such as memo-v1. The built-in prose-v1 is BLAKE3 over the
bytes hibi:prose-v1 and a newline, followed by the text after Unicode NFC
and whitespace collapsing (every run of whitespace becomes one space, then
the result is trimmed); the reference provider uses it. Name a new profile
when you change what the fingerprint covers; sides marked under the old name
then report profile_mismatch instead of silently changing state.
hibi checks every unit it receives: fp must match that format, sel must
be a valid selector that uses only listed keys, and keys must be unique in
one units answer. A unit that fails is not used, and the side becomes
unavailable with reason provider_error.
Both sides ignore object keys they do not know, except inside a selector.
Identity
Which unit a stored anchor names is decided by your provider alone. A unit returned withoutapprox is your provider’s statement that it is the unit
the stored selector was made for. hibi checks nothing else: it compares that
unit’s fingerprint with the marks. A wrong answer makes a claim follow
another unit, which can then be reported fresh while the text the claim
was made for changed, or stale because of an unrelated change.
When your provider cannot tell, return the units it could mean with
approx: true. hibi never resolves a side to such a unit: when any unit of
an answer has approx: true, the side is missing with reason not_exact,
and the units of the answer are listed as candidates for the agent to
choose, at most 20, with the count of all of them. One unit without approx resolves the side. Several units without
approx make it ambiguous.
The reference provider resolves by key, by quote (every unit containing
it) or by both, and never returns approx. A quote that moved to another
unit, together with a key, gives no unit: the key still names its unit,
the quote is no longer in it, so the side is missing, never the unit the
quote moved to.
Errors
An error is{"code": <string>, "message": <string>}.
invalid_locator and invalid_selector say that the anchor is wrong for the
resource, not that the provider failed. On a stored anchor the side’s
detail holds your message and its next is the hibi reanchor template.
With unavailable or unparsable, your message is the side’s detail,
and its remediation is your message followed by “Run the command again
once that is fixed.”, so say in the message what the user can do. With
unparsable hibi also adds the commands to move on without the resource,
because no anchor on it can work until it parses: for evidence, anchor the
side to another resource or drop it; for the subject, re-point it or retire
the claim.
An unknown code is treated as internal. After answering hello with
unsupported_protocol, a provider may keep running or exit; hibi never sends
a second hello in a run, and sends no other request to that provider.
How resolve matches a selector, what render puts in context, and which
unit kinds exist are the provider’s own design. The reference provider below
is one complete, small answer to those questions.
The reference provider
hibi-provider-reference is a complete provider in the repository
(crates/hibi-provider-reference), written to be read. It serves scheme
ref from a fixture file:
notes.json
key and quote selectors, fingerprints each unit’s text with
prose-v1, and answers {} with every unit of the resource. Build it from a
clone of the repository:
Checking a provider
hibi providers --check <scheme> starts the registered command and runs the
protocol conformance cases that are compiled into hibi. They check the
handshake, the envelope of every response, malformed lines, unknown methods,
batch ordering, an error for a resource the provider cannot have, and exit
within 2 seconds of the end of input. After an unsupported_protocol answer
the provider may keep running or exit.
They do not check how resolve matches, the content of units or
render, or fingerprints; test those with claims of your own. A failing case is
reported and does not make the command fail. The built-in schemes file
and repo have no provider command, so there is nothing to check:
output
.hibi/hibi.toml first:
output
output
cases/provider/protocol/ of the repository; cases/provider/reference/ holds further cases for the reference
provider itself.
