"""Replay engine contracts for vm.These protocols keep :class:`~tangl.vm.runtime.ledger.Ledger` algorithm-agnostic.Diff-based replay is one implementation; future event-sourced variants shouldimplement the same contracts."""from__future__importannotationsfromtypingimportProtocol,runtime_checkablefromtangl.coreimportGraphfrom.recordsimportCheckpointRecord@runtime_checkableclassReplayDelta(Protocol):"""A replayable state delta."""defapply_to(self,graph:Graph)->Graph:"""Apply this delta to ``graph`` and return the resulting graph."""
[docs]@runtime_checkableclassReplayEngine(Protocol):"""Algorithm interface for replay and rollback."""defalgorithm_id(self)->str:"""Stable algorithm identifier used on replay records."""defbuild_delta(self,*,before_graph:Graph,after_graph:Graph)->ReplayDelta|None:"""Build a delta between two graph states, or ``None`` when unchanged."""defapply_delta(self,*,graph:Graph,delta:ReplayDelta)->Graph:"""Apply a delta to ``graph``."""defmake_checkpoint(self,*,graph:Graph,step:int,cursor_id,call_stack_ids,)->CheckpointRecord:"""Create a checkpoint record for the current graph state."""defrestore_checkpoint(self,checkpoint:CheckpointRecord)->Graph:"""Restore and verify graph state from a checkpoint."""