Skip to main content

Module flow

Module flow 

Source
Expand description

Flow-context assembler (report 05, P1) - the single choke point for ALL per-turn injected context.

Before this module, three separate call sites composed the model-visible context independently: the Hermes bridge pre_llm_call arm, the context_engine_pre_llm tool, and core hooks::pre_llm_call. The bridge sites never called build_directive_context, so the directives system was invisible on the only path real sessions use (bug class 01-F3 / 04-F1).

build_turn_context assembles every section in a fixed order under one hard byte cap (state.flow_budget_chars), dropping low-priority sections from the BOTTOM when over budget. Every injection site now routes through it, so the “bridge reimplements the hook body and forks” failure mode is unrepresentable.

Structs§

WindowStats
Cheap aggregate over the last n turns of tool_events (P2/T7). Scans events with turn > turn_counter - n.

Constants§

SHIPPED_SESSION_INJECT
Default first-turn session injection. Loaded from [prompts] session_inject in aphrodite.toml; this constant is the fallback when the key is absent. Rendered once (turn_counter == 0) by build_first_turn_injection, then dropped. Empty string disables it entirely.

Functions§

build_first_turn_injection
Build the one-shot first-turn injection from the configured session_inject template. Returns empty string if state.session_inject is empty or the turn has advanced past 0 (first-turn only).
build_turn_context
Assemble the complete per-turn injected context, in fixed order, hard-capped at state.flow_budget_chars.
error_sig
FNV-1a signature of an error: error_type + first line of error_message (P2/P7). Distinct compiler errors differ on line 1, so this stays discriminating without over-matching.
normalize_args_sig
FNV-1a signature of tool + normalized args (P2/P8 similarity key).
purge_expired_nudges
Purge expired ephemeral directives (P3/T9). Called from post_llm_call AFTER next_turn advances the counter, so a nudge pushed during turn N (expiring at N + ttl) renders in turn N+1’s context exactly once for ttl=1.
push_nudge
Push an inline nudge that renders on the next pre_llm_call and self-purges after ttl_turns (P3/T9). ttl_turns = 1 is a one-shot: rendered on the next turn, purged at the following post_llm_call. At most 4 ephemeral entries are stored; pushing a 5th drops the oldest.
render_nudges
Render at most 2 active inline nudges as [nudge: <text>] lines, newest wins (P3/T9). An entry renders while it has not expired (expires_after_turn >= turn_counter, or None = permanent).
turn_window
Compute WindowStats over the last n turns (P2/T7).