Expand description
Local Approval Use Journal – v0.9.9 PR 2.
Per-workspace append-only memory of consumed Approval Grants. The journal turns the v0.9.6 “package-local only” replay finding into a local-journal replay finding: with this module wired through, verify can say “use 1/1 – local Approval Use Journal passed” instead of “no global ledger consulted.”
Scope of THIS PR:
- journal storage (records/, heads/, indexes/, locks/)
- append-only writes with file lock + atomic temp+rename
- hash chain via
previous_record_digest - read-only
check_replaylookup verify_integritychain walkrebuild_indexesfrom records (records are truth)
Out of scope (later PRs):
- consume-before-action wiring inside
treeship attest action(PR 3) - package export of journal records (PR 4)
- Hub checkpoint signing (PR 6 scaffold)
Privacy rules baked into the layout:
nonce_digest, never raw nonce- no commands, prompts, file contents, bearer tokens, or API keys are stored. The journal answers the single question “has this (grant_id, nonce_digest) been consumed before, and if so how many times?” – everything else stays in the signed grant + receipt where it already is.
Structs§
Enums§
Functions§
- append_
checkpoint - Append a JournalCheckpoint over a contiguous range of prior records.
- append_
revocation - Append an ApprovalRevocation. Sibling of
append_use. - append_
use - Append an ApprovalUse to the journal. The caller MUST set
previous_record_digestto the current head’s digest on the incoming record; we re-validate before write.record_digestis computed from the canonical form and stamped on the stored record. - check_
replay - Check whether (
grant_id,nonce_digest) has already been consumed, and how many times. Returns aReplayCheckcarrying the strongest level the journal can speak to: - find_
use_ for_ action - Find the recorded ApprovalUse for an already-signed action.
Returns the matching use record plus a
ReplayCheckthat answers the verify-time question – “is the recorded use within max_uses?” – as opposed tocheck_replay’s consume-time question – “would the next use exceed?”. The two questions look the same but have different boundary semantics: - list_
uses_ for_ grant - Every ApprovalUse for
grant_id. Reads the by-grant index, then loads each record. Quiet on missing journal. - rebuild_
indexes - Delete and rebuild every index from the records directory. Records are truth; indexes are cache. Useful as a recovery tool when an index file is corrupt or out of sync.
- reserve_
use - Atomic check-and-append for the consume path. Combines
check_replay+ append under a single journal lock so concurrent consume paths cannot bypassmax_usesvia TOCTOU race. - verify_
integrity - Walk every record in order, recompute each
record_digest, and check that each record’sprevious_record_digestmatches the prior record’s storedrecord_digest. Returns the number of records walked or an error pinpointing the first integrity failure.