Skip to content

guardrails: surface advisory findings to the TUI (client-visible, model-invisible) #170

Description

@JAORMX

The problem

Advisory-mode guardrail findings are invisible to the TUI. An operator who enables guardrails in advisory mode cannot see that the checker fired — the finding goes only to the operator log (stderr/journald/file), never to the client event stream, so the TUI renders nothing.

This defeats the stated purpose of advisory mode. ADR 0021 (docs/adr/0021-guardrails.md) says advisory exists "so the operator measures the false-positive rate before promoting a rule to block/sanitize." You cannot measure what you cannot see. If the operator has to leave the TUI mid-session and grep guardrail-finding a log file to discover the checker flagged three mcp__* calls, they won't do it — advisory mode becomes a black hole that never gets promoted because the signal never surfaces.

What happens today

  • internal/adapter/modelhook/modelhook.go:305 (enforce, ModeAdvisory arm): calls r.diag.Log(...) (operator log) and returns governance.HookOutcome{} — an empty outcome.
  • engine/agent/dispatch.go only emits an EvHook event when a hook outcome actually does something — HookBlocked (dispatch.go:637/1048) or HookModified (dispatch.go:646/1057). An empty HookOutcome = "hook did nothing" → no event emitted.
  • So: advisory finding → operator log only → TUI sees nothing, model sees nothing. The EvHook + HookPayload channel (which the TUI already renders as notices on tool cards via HookPayload.CallID) never fires for an advisory finding.

Proposed change

Emit an EvHook for advisory findings, client-visible, model-invisible.

  1. Add a new HookDecision value HookAdvisory (engine/session/event.go, alongside HookInfo/HookBlocked/HookModified). It's a string passthrough on the wire (proto type/stop are strings, no task generate).
  2. In the ModeAdvisory arm of enforce (modelhook.go:305), return a non-empty HookOutcome carrying the advisory reason (or add a dedicated advisory-outcome path), so dispatch emits an EvHook with Decision: HookAdvisory.
    • The runner already has the governance.HookEvent (Phase/Tool/CallID/SessionID), so the EvHook can carry the full HookPayload and pin the notice to the exact tool card.
  3. The TUI renders an advisory notice in a warning colour (distinct from the error colour used for HookBlocked), addressed to the originating tool card via CallID.
  4. Keep the diag log — headless deployments (mecated --headless, mecatequi) have no TUI, and the guardrail-finding grep marker is the right correlation channel for post-hoc log analysis. The change is "ALSO emit an EvHook," not "replace the log with an event."

The visibility split

The current contract bundles two claims: "the client sees nothing" and "the model sees nothing." This issue splits them:

  • Client (TUI): yes, show it. This is the fix.
  • Model: no, keep it invisible. Advisory means the tool result is unaltered — the model sees the byte-identical result, no annotation. Making the model aware that a guardrail flagged something risks injection: a malicious tool result that trips a spurious advisory finding could steer the model's behaviour ("the guardrail said this was unsafe, so treat it as suspicious"). Client-visible, model-invisible is the safe split.

Considerations

  • Noise: an MCP-heavy session under the default rule set could fire a finding per mcp__* call. If each becomes a TUI notice, scrollback gets loud. This is a rendering problem (a count badge on the tool card, a collapsible guardrails notice, a status-line summary), not a reason to stay invisible.
  • ADR 0021 wording: the "client and model see nothing on an advisory finding" line needs amending, but the ADR's intent (don't disrupt the agent, measure before promoting) is better served by TUI visibility. The amendment strengthens the stated goal rather than contradicting it.
  • EvHook is already client-relayed — it is NOT in the log-only set (EvApproval/EvCompactionArchive/EvUserPrompt), so no relay change is needed.

Scope

  • New HookAdvisory decision in engine/session/event.go.
  • Advisory arm in modelhook.enforce returns a non-empty outcome (or a dedicated advisory-emission path) so dispatch emits the EvHook.
  • TUI rendering of the advisory notice (warning colour, pinned to tool card via CallID).
  • ADR 0021 + docs/architecture.md amendment.
  • Tests: advisory finding emits an EvHook with HookAdvisory; model sees unaltered result; TUI golden update.

Out of scope

  • Making advisory findings model-visible (separate, injection-implications decision).
  • The default-mode flip (advisory → block) — that's #NNN.

Ref: #168 (remove maxChecks), #169 (checker-down posture toggle).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions