Skip to content

Feat: add regex-based title cleaning rules configuration and implementation - #112

Open
AminZibayi wants to merge 1 commit into
ActivityWatch:masterfrom
AminZibayi:master
Open

AminZibayi wants to merge 1 commit into
ActivityWatch:masterfrom
AminZibayi:master

Conversation

@AminZibayi

@AminZibayi AminZibayi commented Jun 28, 2025 •

Copy link
Copy Markdown

You can configure regex-based title cleaning rules to modify window titles before they are sent to the server. This is useful for removing application-specific suffixes, temporary states (like unread message counts), or other noisy data from window titles, leading to cleaner and more accurate data aggregation.


Important

Add regex-based title cleaning rules to modify window titles before sending to server, with configuration and documentation updates.

  • Feature:
    • Add regex-based title cleaning rules to modify window titles before sending to server.
    • Implemented in clean_window_title() in main.py and get_title_cleaning_rules() in config.py.
    • Configuration examples added to example-config.toml.
  • Configuration:
    • Users can define rules in ~/.config/activitywatch/aw-watcher-window.toml.
    • Each rule includes app, pattern, and replacement fields.
  • Documentation:
    • Updated README.md with instructions for configuring title cleaning rules.

This description was created by Ellipsis for 18e1877. You can customize this summary. It will automatically update as commits are pushed.

@ellipsis-dev ellipsis-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 18e1877 in 51 seconds. Click for details.
  • Reviewed 180 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. aw_watcher_window/config.py:20
  • Draft comment:
    Inconsistent config access: load_config now returns the full config (without indexing by 'aw-watcher-window') while parse_args still accesses config['aw-watcher-window']. Consider harmonizing how configuration is retrieved.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. aw_watcher_window/config.py:26
  • Draft comment:
    get_title_cleaning_rules() calls load_config_toml() directly, reloading the config. Consider reusing the result from load_config() or caching the cleaning rules to avoid redundant config parsing.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. aw_watcher_window/main.py:43
  • Draft comment:
    In clean_window_title(), regex patterns are recompiled on every call. Consider precompiling the regex patterns (possibly during config loading) to improve performance.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_i0pKdKX8Sb5oBQe5

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

@AminZibayi thanks, and sorry this sat so long. I re-checked it against current master (10638b2, 31 commits ahead of your base). The rebase conflicts in config.py and main.py, and master now has a related mechanism: the watcher-side privacy_filter (#135, merged 2026-10-14), which applies regex rules to window events before they're sent.

It doesn't cover your case. privacy_filter's redact action replaces the whole field. This PR does a per-app re.sub, e.g. strip - Mozilla Firefox or (3) unread counts, so titles stay readable and heartbeats stop splitting on counter changes. Rebased as-is, though, it would add a second regex rule engine and config section next to privacy_filter.

@ErikBjare: do you want watcher-side title rewriting at all? It permanently changes the raw data, whereas categories work at query time. If yes, I'd carry it as a rewrite action in privacy_filter, applying pattern.sub(replacement, value) with an optional app scope. That's about 20 lines plus tests and keeps one engine. If not, I'd close this with thanks.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

@AminZibayi following up on the question above. Two weeks on with no design answer, I'm carrying the useful part of this internally instead of letting it sit: per-app title rewriting becomes an action: "rewrite" (pattern.sub) with an optional app scope inside the existing privacy_filter, about 20 lines plus tests, rather than a second rule engine and config section. It stays opt-in, so nothing rewrites raw titles unless a user configures it.

That means this branch won't be merged as-is (it conflicts with master in config.py and main.py), but the feature it implements is not being dropped — I'll reference this PR in the implementation PR so the idea stays credited here. Thanks for the work; sorry it took this long to get you an answer.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

The carry is up: #175 adds action = "rewrite" to the existing privacy_filter plus an optional app scope, so per-app title cleanup no longer needs a second rule engine. @AminZibayi your per-app re.sub use case is exactly what this covers — the regex from your branch works as a rewrite rule.

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.

2 participants