Expand description
Output-echo detection (#501).
lean-ctx aggressively optimizes the input side, but never looked at the
agent’s output — although output tokens cost 4-5x more. The most common
waste pattern is the code echo: the agent re-quotes file content that is
already in context. The afterAgentResponse hook delivers the reply text;
this module measures which share of its code lines were echoed from
recently read files (context radar tail) and feeds three consumers:
- rolling stats (
~/.lean-ctx/output_echo.json) forctx_metrics,ctx_session output_statsand the dashboard, - an automatic
LlmFeedbackEventso the adaptive mode policy finally receives continuous data instead of voluntaryctx_feedbackcalls, - a stable, cache-friendly CEP nudge the MCP server appends to a tool result when echo stays high (cooldown-limited).
Structs§
Functions§
- analyze
- Pure analysis: which share of the response’s code lines appear verbatim in any source document (recently read file contents)?
- analyze_
and_ record - Hook entry point: analyze an agent response against the radar tail, persist rolling stats and emit the automatic feedback event.
- current_
avg_ ratio - Average echo ratio over the rolling window — CEP score input.
- load_
stats - take_
pending_ nudge - CEP nudge for the MCP server to append to a tool result. Stable text in 10%-steps (prompt-cache friendly, #498), cooldown-limited. Consuming the nudge advances the cooldown marker.