Normative 10-Rule Context Derivation Engine (packages/durable/docs/spec.md §2.1).
Responsibilities:
- Walk conversation fork ancestry (
libgraphDAG) to collect visible entries in order. - Replay positional
pi.systementries (fullbaseline +deltaprompt sections and tools) and append minimaldeltaentries when configuration changes so provider prompt caches stay warm. - Slice the active window from the newest visible
head_entry_idmarker (pi.compactionorpi.reset). - Apply non-destructive
ContextEditoperations (omitandreplace) in entry order.
Summary
Functions
Derives the active LLM context for conversation_id according to the 10-rule specification.
visible is the result of visible_entries_with_graph/1 when the caller already has it.
Compares desired_sections and desired_tools against the conversation's replayed pi.system
state. Appends a "full" baseline on first request, a "delta" entry only when a section or tool
changed, or nothing when unchanged (preserving LLM prompt cache prefixes).
Builds the fork ancestry DAG (Graph) and returns all visible entries for conversation_id
in chronological order, respecting parent_entry_id fork cutoffs.
Types
Functions
@spec derive(integer(), {[SuperPi.Durable.Schemas.Entry.t()], Graph.t()} | nil) :: derived_context()
Derives the active LLM context for conversation_id according to the 10-rule specification.
visible is the result of visible_entries_with_graph/1 when the caller already has it.
@spec ensure_system_state!( integer(), [map()], [map()], [SuperPi.Durable.Schemas.Entry.t()] | nil ) :: {:unchanged | :full | :delta, SuperPi.Durable.Schemas.Entry.t() | nil}
Compares desired_sections and desired_tools against the conversation's replayed pi.system
state. Appends a "full" baseline on first request, a "delta" entry only when a section or tool
changed, or nothing when unchanged (preserving LLM prompt cache prefixes).
@spec visible_entries_with_graph(integer()) :: {[SuperPi.Durable.Schemas.Entry.t()], Graph.t()}
Builds the fork ancestry DAG (Graph) and returns all visible entries for conversation_id
in chronological order, respecting parent_entry_id fork cutoffs.