Repository navigation
feat(privacy_filter): add rewrite action and optional app scope - #175
TimeToBuildBob wants to merge 3 commits into
Conversation
The existing actions are all-or-nothing: drop discards the event and redact replaces the whole field. That cannot express the common title cleanup from ActivityWatch#112, e.g. stripping a browser suffix or an unread counter while keeping the rest of the title readable. Add action = "rewrite" (pattern.sub(replacement, value)) plus an optional app scope so a rule can be limited to one application. A rewrite requires an explicit replacement, including the empty string, because the "excluded" default would otherwise delete the matched text. Carries ActivityWatch#112 without adding a second rule engine or config section. Git-Session-Id: b770e86d-23b9-48f1-9d61-05c99e384e89
[Medium impact] The PR appears safe to merge; both previous findings are addressed and no new blocking issue was found. SummaryAdds opt-in
Reviews (2) · Last reviewed commit: "fix(privacy_filter): make documented rew..." · Reviewed by Greptile |
A dangling group reference or bad escape in a rewrite rule's replacement only raises inside re.sub, i.e. while the heartbeat loop is applying filters, which would stop window tracking. Validate the replacement against the compiled pattern at compile time and skip the rule with an error log instead. Also drop the trailing anchor from the documented counter example so it strips counters in either position, per review. Git-Session-Id: b770e86d-23b9-48f1-9d61-05c99e384e89
|
Both review findings addressed in ee7f74a:
Tests: |
|
Verified the rewrite action end-to-end on a real watcher run, not just the unit tests: The mechanism works. At The The documented example doesn't do what its comment says. At HEAD this rule: pattern = "( - Mozilla Firefox|\\(\\d+\\+?\\)\\s*)"emits This one does, in a single pattern = "(\\s*\\(\\d+\\+?\\)|\\s*- Mozilla Firefox)+$"→ emitted Worth swapping the README/docstring example before merge — no behaviour change, just an example that matches its own comment. |
🤖 AI code reviewAdds the "rewrite" action to compile_privacy_rules() and apply_privacy_filters(), using regex substitution with an explicit replacement string. Adds optional case-insensitive exact app scoping, replacement validation, documentation examples, and tests for rewriting and app matching. Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No findings. The diff looks correct to me on this pass. Files changed (3) — the diff as I read it
Previous review passes
Reviewed Maintainer commands
|
…dges Git-Session-Id: 1b5783aa-3dfd-5643-b844-f6ad512e50b7
|
@greptileai review |
|
Fixed the remaining example bug in 99cb5d2. The README and module example now use two ordered Firefox-scoped rules: strip the browser suffix plus trailing counters, then leading counters. Both The regression test parses the actual TOML from both examples rather than copying their regex into a fixture. It also checks that other applications are untouched and input events are not mutated. The module docstring is now raw so rendered TOML retains its required backslashes. Before the fix: 8 of the 10 example cases failed; after: all 50 privacy-filter tests pass, and the module's mypy check passes. The invalid-replacement crash was already fixed by ee7f74a; no filter-engine behavior changed in this follow-up. Requested a fresh Greptile review through the helper after pushing the fix. |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Carries the useful part of #112 inside the existing
privacy_filterinstead of adding a second rule engine and config section (that PR is 477d old and conflicts with master inconfig.py/main.py).What
action = "rewrite"appliespattern.sub(replacement, value), so a rule can strip a suffix or counter and keep the rest of the title readable.drop(discard event) andredact(replace whole field) are unchanged.appscope limits a rule to one application (case-insensitive exact match), which is what per-app title cleanup needs.rewriterule must give an explicitreplacement(empty string allowed). The"excluded"default would silently delete the matched text, so a missing replacement is rejected with an error log and the rule is skipped.Why not merge #112 as-is
It predates
privacy_filterand would add a parallel regex engine plus a second config section. The requested behaviour is ~20 lines inside the existing mechanism. Rewriting is opt-in: nothing mutates titles unless a user configures arewriterule.Tests
16 new cases cover suffix/counter stripping, app scoping (match, case-insensitive match, non-matching app untouched), missing/invalid replacement rejection, non-matching pass-through, never dropping/redacting, and input-not-mutated.
mypy --follow-imports=skipis clean on the module.Note:
tests/test_startup.pyandtests/test_xauth_integration.pyfail in this sandbox from anaw_coreversion mismatch (ModuleNotFoundError: aw_core.dirs.platformdirs), before any change here — the privacy-filter suite is self-contained.Refs #112