Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2akouwu Reverify Ledger

From Leeroopedia
Knowledge Sources
Domains State_Management, Verification, Persistence
Last Updated 2026-10-24 12:00 GMT

Overview

Concrete tool for durable per-binary fact persistence that survives context resets, recording verified facts, observed values, and refuted claims with a bounded, pinned view, provided by the Reverify library.

Description

The Ledger class is the durable state store for Reverify. Each binary gets its own ledger (keyed by SHA-256 of its bytes). It records three categories: facts (VERIFIED with weight + OBSERVED values, with proof-grade facts pinned), refuted (REFUTED claims kept as known-false), and runs (metadata per reconstruction attempt).

The record method folds a verification report into the ledger: VERIFIED claims with non-zero weight become facts, OBSERVED values update the observed dict, REFUTED claims are kept as known-false. The established(max_facts) method returns a bounded view: the most recent N fact lines, with proof-grade facts pinned so they never page out. The known_false method returns recent refutations. The save method writes atomically (temp file + rename). The for_bytes classmethod creates or loads a ledger for a binary.

Usage

Import this class when you need to:

  • Persist verified facts across rounds in the reconstruction loop (the agent does this automatically).
  • Recover grounded state after a context reset (MCP re_ledger tool, CLI ledger subcommand).
  • Record results after each verification round.
  • Query the bounded established view for the prompt.

Code Reference

Source Location

  • Repository: Reverify
  • File: reverify/ledger.py
  • Lines: Ledger class throughout; record at L408-488; established at L492-506; known_false at L508-512; save at L358-376; LEDGER_INSTRUCTIONS at L70-76

Signature

class Ledger:
    @classmethod
    def for_bytes(cls, data: bytes, directory=None, persist=True, file_path=None) -> "Ledger":
        """Create or load the ledger for this binary (keyed by SHA-256)."""

    @classmethod
    def for_file(cls, file_path: str, directory=None) -> "Ledger":
        """Create or load the ledger for a file path."""

    def record(
        self,
        results: Union[Dict[str, Any], Iterable[Dict[str, Any]]],
        rnd: Optional[int] = None,
        goal: Optional[str] = None,
        session: Optional[str] = None,
    ) -> Dict[str, int]:
        """Fold a verification report into the ledger.

        Returns {"facts": N, "observed": N, "refuted": N} added counts."""

    def established(self, max_facts: int = 40) -> List[str]:
        """Bounded context view: most recent N fact lines, proof-grade pinned."""

    def known_false(self, limit: int = 12) -> List[str]:
        """Most recent refutations so a fresh context does not re-propose them."""

    def save(self) -> Optional[Path]:
        """Atomic checkpoint (temp file + rename). No-op for in-memory."""

    def clear(self) -> None:
        """Discard all facts, refutations, and the on-disk file."""

Import

from reverify.ledger import Ledger

I/O Contract

Inputs

Name Type Required Description
results Dict or Iterable[Dict] Yes Verification report (or its results list)
rnd int No Round number
goal str No Reconstruction goal
session str No Session label
max_facts int No Bounded view size (default 40)

Outputs

Name Type Description
record return Dict[str, int] {"facts": N, "observed": N, "refuted": N} added counts
established return List[str] Bounded fact lines for the prompt
known_false return List[str] Recent refutation lines
save return Optional[Path] Path to atomically-written JSON file (None if in-memory)

Usage Examples

Record and Query

from reverify.ledger import Ledger

led = Ledger.for_bytes(data, directory="./ledgers")
added = led.record(report["results"], rnd=1, goal="Reconstruct entry", session="s1")
print(f"Added: {added}")
led.save()

# Bounded view for the next prompt
established = led.established(max_facts=40)
known_false = led.known_false()

Recover After Context Reset

# After a /clear or new session, load the ledger for the same binary
led = Ledger.for_bytes(data, directory="./ledgers")
established = led.established(40)  # verified facts are back
known_false = led.known_false()     # refuted claims are back
print(f"Restored {len(established)} facts, {len(known_false)} known-false")

CLI / MCP Usage

# CLI: show the ledger for a binary
reverify ledger target.dll --context

# MCP: re_ledger tool restores state after compaction
# (called by the AI agent automatically)

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment