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
SessionStartdispatch, so total wall time is budgeted to 50ms p99. Any DB read that crosses that budget bails out viatokio::time::timeoutand the caller seesNone— 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 withprev_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.dbis locked, missing, or rejects the query, the helper returnsNone.
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§
- Banner
Context - What the banner helper needs to do its job. The integration site in
hook_runtime::dispatchbuilds this from theHookEvent::SessionStartpayload it already has — no new plumbing through the rest of the pipeline.client_nameis 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
Nonewhen there is nothing new to show OR when any step in the pipeline failed — callers should treat both as “emit nothing”.