Skip to content

feat(classify): optional priority field for category rules - #663

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/classify-priority-597
Open

feat(classify): optional priority field for category rules#663
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/classify-priority-597

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Optional priority (alias weight) on categorize rules, as discussed in #597.

  • Explicit integer on the rule dict: higher wins
  • Omitted: existing depth ranking, unchanged
  • Query example: { "type": "regex", "regex": "vim", "priority": 10 }

In the reported tree (A matches at depth 1, B→B1 matches at depth 2) A wins if its priority is higher than B1's depth.

Does not change default configs. WebUI editor field and aw-core/Python ranking are separate follow-ups — not closing #597 here.

When multiple rules match, ranking uses an optional `priority` (alias
`weight`) on the rule dict. If omitted, depth-based ranking is unchanged.

This lets a shallow rule beat a deeper organizational match without
changing default behavior for existing configs.
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

Adds optional priority and weight ranking fields to category rules while preserving depth-based ranking when omitted.

  • Introduces the CategoryRule structure for category, rule, and optional priority.
  • Parses and validates query-provided priority values.
  • Preserves Uncategorized when a matching rule has an empty category path.
  • Adds transform-level and query-level regression coverage for ranking and validation behavior.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported empty-category regression is fixed by skipping empty category paths before ranking, and no blocking failure remains.

Important Files Changed

Filename Overview
aw-query/src/datatype.rs Converts query category-rule tuples into CategoryRule values and validates optional integer priorities.
aw-query/src/functions.rs Updates the categorize built-in to pass structured category rules into the transform.
aw-query/tests/query.rs Adds end-to-end coverage for priority overrides, the weight alias, and invalid priority values.
aw-transform/src/classify.rs Implements priority-aware category ranking and safely preserves the fallback for empty category paths.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Query category rule] --> B[Parse optional priority or weight]
    B --> C{Category path empty?}
    C -- Yes --> D[Skip rule]
    C -- No --> E{Rule matches event?}
    E -- No --> F[Check next rule]
    E -- Yes --> G[Rank by explicit priority or category depth]
    G --> H[Keep highest-ranked category]
    H --> I[Write category to event]
Loading

Reviews (2): Last reviewed commit: "fix(classify): skip empty category paths..." | Re-trigger Greptile

Comment thread aw-transform/src/classify.rs
An empty match must not replace Uncategorized. The old depth comparison
rejected len 0 against the fallback's len 1; keep that when ranking
starts from i64::MIN so negative priorities can still categorize.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Empty-category fallback fixed in 676c090 (Greptile P1).

macOS test_push_does_not_reexport_synced_buckets failure is the known aw-sync tmp_db collision (duplicate column name: data) — same flake #655 targets. Unrelated to this change; ubuntu/windows/android/clippy/format are green.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.97590% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.79%. Comparing base (656f3c9) to head (676c090).
⚠️ Report is 93 commits behind head on master.

Files with missing lines Patch % Lines
aw-query/src/datatype.rs 88.88% 3 Missing ⚠️
aw-transform/src/classify.rs 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #663      +/-   ##
==========================================
+ Coverage   70.81%   78.79%   +7.98%     
==========================================
  Files          51       66      +15     
  Lines        2916     5523    +2607     
==========================================
+ Hits         2065     4352    +2287     
- Misses        851     1171     +320     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

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.

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