# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-self-editing-context-windows-have-entered-a-lossy-prune-boundary.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-self-editing-context-windows-have-entered-a-lossy-prune-boundary.warrant.json
# Markdown SHA-256:   78a7e055db206acd4bc4ecd83108f9bc56aa6a2bc6a743e434527472bb1083fa
# Code AST SHA-256:   cd6eb3a62b258586d2f0aa169c15b08bcf268f07cffbb6f7db6c9d2b128e7bf1
# Verified Classes:   LossyPruneBoundaryError, Claim
# Defensive Guards:   1 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from typing import Optional


class LossyPruneBoundaryError(RuntimeError):
    """Raised when an irreversible action is attempted on a claim whose only
    support was evicted as paraphrase, with no recoverable verbatim anchor."""


@dataclass
class Claim:
    text: str
    verbatim_anchor: Optional[str]   # exact span present in live window
    ledger_key: Optional[str]        # key into eviction side-store
    evicted_as_paraphrase: bool


def assert_actionable(claim: Claim, irreversible: bool) -> None:
    has_live_anchor = claim.verbatim_anchor is not None
    has_ledger_anchor = claim.ledger_key is not None

    if has_live_anchor or has_ledger_anchor:
        return  # provenance satisfied; safe to proceed

    if claim.evicted_as_paraphrase and irreversible:
        raise LossyPruneBoundaryError(
            f"Claim {claim.text!r} has no verbatim anchor and no ledger key; "
            "only a paraphrase survived pruning. Irreversible action blocked. "
            "Re-acquire the source span before proceeding."
        )
    # Reversible actions may proceed but must be flagged as unverified.
    claim.text = f"[UNVERIFIED] {claim.text}"


def guard_irreversible(claim: Claim) -> None:
    assert_actionable(claim, irreversible=True)
