Skip to main content

Module session_banner

Module session_banner 

Source
Expand description

Since-last-session banner.

Emits a short, agent-visible note when the current repo has gained rules since the last SessionStart fired for it. Plugs into every platform adapter (Claude Code, Cursor, Gemini CLI, Windsurf) via the additional_context field on HookResult — adapters just append the banner string to whatever context they already produce.

Design notes ────────────

  • Hot path discipline. The helper runs inside SessionStart dispatch, so total wall time is budgeted to 50ms p99. Any DB read that crosses that budget bails out via tokio::time::timeout and the caller sees None — never a panic, never an error bubble.
  • Zero-noise on quiet sessions. When no new rules exist for this repo since the last fire, the helper returns None. The adapter then appends nothing, preserving the exact existing transcript.
  • Per-repo watermark. Each repo gets its own JSON watermark at ~/.difflore/projects/{hash}/last-session-start.json. New repos start with prev_ts = None, so the first session shows everything learned to date (capped at 5). The watermark is then advanced to “now” so subsequent fires only show genuinely-new rules.
  • DB read failures are swallowed. Hooks must never block the agent. If data.db is locked, missing, or rejects the query, the helper returns None.

Modules§

query
SQL for “new rules since prev_ts, scoped to this repo”.
render
Banner text formatter.
watermark
Per-project “last session start” watermark.

Structs§

BannerContext
What the banner helper needs to do its job. The integration site in hook_runtime::dispatch builds this from the HookEvent::SessionStart payload it already has — no new plumbing through the rest of the pipeline. client_name is recorded into the watermark so a future follow-up can per-client-scope the “since last session” wording (e.g. “since last Claude Code session”); the current banner just uses it for the watermark file’s debug trail.

Functions§

render_since_last_session_banner
Build the “since-last-session” banner for the given context. Returns None when there is nothing new to show OR when any step in the pipeline failed — callers should treat both as “emit nothing”.