Skip to content

#72: dashboard — content-filter recent-hits ring#89

Merged
BrettKinny merged 1 commit into
mainfrom
fix/72-content-filter-ring
May 22, 2026
Merged

#72: dashboard — content-filter recent-hits ring#89
BrettKinny merged 1 commit into
mainfrom
fix/72-content-filter-ring

Conversation

@BrettKinny
Copy link
Copy Markdown
Owner

#72 — content-filter recent-hits ring

content_filter() (bridge/text.py) already evaluates the severity tier
and the matched term at every hit. This keeps the last 20 hits in an
in-memory ring and surfaces them at /ui/safety/recent.

  • bridge/text.py_cf_recent deque (maxlen 20) +
    recent_content_filter_hits() getter; content_filter() appends
    (ts, tier, rule, 8-char prefix) per hit. In-memory only — never
    written to disk, and the matched term recorded is no more exposed than
    the content-filter-hit log line content_filter() already emits.
  • dashboard.pyGET /ui/safety/recent.
  • safety_recent.html + a card in dashboard.html.

Completes the dashboard quick-wins batch — #69 / #64 / #74 landed via #87.

The earlier "spec mismatch" re-triage comment on the issue was wrong: it
assumed content_filter lived in an opaque textUtils module. It is a
repo file (bridge/text.py) and already had the tier + matched term in
scope — so #72 was a clean quick win after all.

Verified with py_compile and Jinja tag-balance; the bridge test suite
needs the RPi.

Closes #72.

🤖 Generated with Claude Code

content_filter() (bridge/text.py) already has the tier and the matched
term in scope at every hit. Keep the last 20 hits in an in-memory ring
and expose them at /ui/safety/recent.

- bridge/text.py: _cf_recent deque (maxlen 20) + recent_content_filter_hits
  getter; content_filter appends (ts, tier, rule, 8-char prefix) per hit.
  In-memory only — never written to disk; no more exposed than the
  content-filter-hit log line content_filter() already emits.
- dashboard.py: GET /ui/safety/recent.
- safety_recent.html + a card in dashboard.html.

Closes #72.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 22, 2026 10:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements issue #72 by keeping an in-memory ring buffer of the most recent content-filter hits and surfacing them in the dashboard at /ui/safety/recent, allowing operators to quickly inspect recent tier/rule/prefix details without persisting any filtered text to disk.

Changes:

  • Add a 20-entry in-memory deque in bridge/text.py that records timestamp, tier, matched term, and an 8-character prefix on each content_filter() hit.
  • Add GET /ui/safety/recent in bridge/dashboard.py to render the recent-hit ring into a dashboard partial.
  • Add a new safety_recent.html partial template and a new Safety card section to dashboard.html that polls the endpoint every 30s.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
bridge/text.py Adds recent-hit ring buffer and accessor; appends hit metadata during content_filter() matches.
bridge/dashboard.py Adds /ui/safety/recent route to format and render ring-buffer entries.
bridge/templates/safety_recent.html New partial to display recent content-filter hits in the dashboard card body.
bridge/templates/dashboard.html Adds a new Safety card that polls /ui/safety/recent via htmx.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bridge/dashboard.py
Comment on lines +895 to +899
ts = hit.get("ts") or 0
try:
time_str = datetime.fromtimestamp(ts).astimezone().strftime("%H:%M:%S")
except Exception:
time_str = "?"
@BrettKinny BrettKinny merged commit de9690c into main May 22, 2026
10 checks passed
@BrettKinny BrettKinny deleted the fix/72-content-filter-ring branch May 22, 2026 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard: Content-filter rule detail ring buffer

2 participants