Skip to content

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

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

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

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Companion to ActivityWatch/aw-server-rust#663, requested by @ErikBjare.

Optional integer priority (alias weight) on categorize rules.

  • Explicit integer on the rule dict: higher wins
  • Omitted: rank is depth * 10 (depth 1 → 10, depth 2 → 20), so values can slot between nesting levels
  • Unprioritized configs keep the current deepest-match-wins order
  • aw-server (Python) uses this aw_transform.classify path — no separate copy

Query example:

events = categorize(events, [
    [["Work"], {"regex": "vim", "priority": 25}],
    [["Media", "Video"], {"regex": "vim"}]
]);

Does not close ActivityWatch/aw-server-rust#597 — WebUI editor field is still a follow-up.

Match ActivityWatch/aw-server-rust#663: integer `priority`/`weight` on
rules, default rank is depth * 10 so values can slot between nesting
levels. Existing configs keep their current ordering.
@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds optional integer priority and weight fields to categorization rules while retaining depth-based ranking for rules without an explicit priority.

  • Validates priority values during rule construction and exposes validation errors as query exceptions.
  • Selects the highest-ranked matching category, preserving later-match tie-breaking.
  • Adds transform and Query 2 coverage for explicit, default, negative, aliased, and invalid priorities.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
aw_transform/classify.py Adds validated optional rule priorities and rank-based category selection with an unbounded-safe no-match sentinel.
aw_query/functions.py Converts invalid categorize and tag rule priorities into QueryFunctionException errors.
tests/test_transforms.py Covers ranking precedence, aliases, ties, negative priorities, empty categories, and invalid values.
tests/test_query2.py Verifies priority behavior and validation through the Query 2 interface.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Matching category rules] --> B{Explicit priority?}
    B -->|Yes| C[Use integer priority]
    B -->|No| D[Use category depth times 10]
    C --> E{Rank at least current rank?}
    D --> E
    E -->|Yes| F[Select category]
    E -->|No| G[Keep current category]
    F --> H[Return highest-ranked match]
    G --> H
Loading

Reviews (2): Last reviewed commit: "fix(classify): pick category without i64..." | Re-trigger Greptile

Comment thread aw_transform/classify.py
Replace the signed-64-bit Uncategorized rank with Optional[int] so a
valid unbounded Python priority below -(2**63) still beats Uncategorized.

Git-Session-Id: bob-monitor-aw-core-153
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@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.

Category picking issues?

1 participant