Skip to content

feat(classify): per-field patterns on the existing regex rule - #206

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/regex-rule-fields-map
Open

TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/regex-rule-fields-map

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Python side of the "extend the existing regex type" direction for ActivityWatch/aw-webui#939, replacing the separate regex_fields type proposed in #155 (closed pending judgement).

{"type": "regex", "fields": {"app": "mstsc\\.exe", "title": "office\\.example"}}
  • Every field in fields must match (AND). Each pattern uses the same unanchored search as regex, and ignore_case applies. Use ^…$ for an exact match, as today.
  • regex alone and regex + select_keys behave exactly as before.
  • Rollout safety: a fields rule has no regex, so an older server matches nothing for it instead of misclassifying events.
  • fields combined with regex or select_keys, an empty or non-mapping value, or an invalid pattern is logged and the rule matches nothing. This mirrors the existing invalid-regex handling.
  • Both Rule.match and the planned fast path (_plan/_matching, used by categorize/tag) support it.

Not in this PR: the aw-server-rust twin, capability advertising, and the webui editor. The editor should only offer fields once both servers support it.

Tests: tests/test_classify_fields.py covers the mstsc/winbox split, AND semantics, missing and non-string fields, search and ignore_case, the rejected combinations, tags, and legacy rules. Local run: 188 passed across the classify, query-cache, transform and query2 suites. mypy and ruff are clean.

A regex rule may now carry 'fields' (e.g. {"app": "mstsc\\.exe", "title": "office"})
instead of 'regex'. Every listed field must match, each with the same
unanchored search as 'regex'. This lets users split two apps that show the
same window title (ActivityWatch/aw-webui#939) without a new rule type.

A fields rule carries no 'regex', so servers that predate it match nothing
for it rather than misclassifying. Combining 'fields' with 'regex' or
'select_keys', or an empty/invalid mapping, is logged and matches nothing.

Git-Session-Id: bd564fff-a9f8-42c7-a783-31ca4204a2c6
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Review guide (auto-posted)

Structured warm-up for reviewers — what changed, what to run, where to look.

Key files

  • tests/test_classify_fields.py (+96/-0, Δ96)
  • aw_transform/classify.py (+61/-5, Δ66)

Suggested verification

  • uv run pytest tests/test_classify_fields.py -q
  • make typecheck

Known risks / watch points

  • No automatic high-risk tags; use file list + diff for judgment.

Suggested review focus

  • Confirm behavior matches the PR description acceptance criteria.
  • Skim the largest diffs first (listed above).
  • If CI is green, spot-check the highest-risk paths called out here.

Generated by scripts/github/pr-warmup-review-guide.py for #206.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches Python category and tag queries that classify events.

The PR appears safe to merge, with a non-blocking gap in rejecting mixed rules with empty values.

Findings

  1. P2 Mixed rules still match ▶

Summary

Adds per-field patterns to existing regex rules for categories and tags.

  • Regex rules can match patterns across several named event fields.

One non-blocking gap remains: mixed rules with empty legacy values are accepted instead of disabled.

Reviews (1) · Last reviewed commit: "feat(classify): per-field patterns on th..." · Reviewed by Greptile

Comment thread aw_transform/classify.py Resolved
Git-Session-Id: bd564fff-a9f8-42c7-a783-31ca4204a2c6
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.

1 participant