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§
- Window
Stats - Cheap aggregate over the last
nturns oftool_events(P2/T7). Scans events withturn > turn_counter - n.
Constants§
- SHIPPED_
SESSION_ INJECT - Default first-turn session injection. Loaded from
[prompts] session_injectin aphrodite.toml; this constant is the fallback when the key is absent. Rendered once (turn_counter == 0) bybuild_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_injecttemplate. Returns empty string ifstate.session_injectis 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 oferror_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_callAFTERnext_turnadvances 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_calland self-purges afterttl_turns(P3/T9).ttl_turns = 1is a one-shot: rendered on the next turn, purged at the followingpost_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, orNone= permanent). - turn_
window - Compute
WindowStatsover the lastnturns (P2/T7).