Skip to content

Let shell.json rewrite the urgency a notification sender declared - #9660

Closed
wjax wants to merge 1 commit into
omacom:quattrofrom
wjax:feat/notification-urgency-rules
Closed

wjax wants to merge 1 commit into
omacom:quattrofrom
wjax:feat/notification-urgency-rules

Conversation

@wjax

@wjax wjax commented Sep 1, 2026

Copy link
Copy Markdown

Senders pick their own urgency and some misdeclare it. A chat app that marks every message critical gets a toast that never expires, because durationFor() returns 0 for NotificationUrgency.Critical. The message then sits on screen until it is dismissed by hand.

Urgency is not read in one place — popup lifetime, the do-not-disturb bypass, card styling and what lands in history all consult it. So rather than special-casing duration, this corrects urgency once at ingest and lets every downstream decision stay honest.

What it adds

A top-level notifications.rules[] block in shell.json:

{
  "notifications": {
    "rules": [
      { "app": "Brave Origin", "urgency": "critical", "set": { "urgency": "normal" } },
      { "app": "Brave Origin", "summary~": "Alex|Sam", "set": { "urgency": "critical" } }
    ]
  }
}

A rule filters on the fields it names — app, appIcon, summary, body, and the incoming urgency — and every field it names has to match. A ~ suffix makes the value a regular expression instead of exact text, following mako’s summary~ / body~ convention. What changes goes in set. Rules apply in order and the last match wins, so the pair above reads as “everything that browser marks critical is really only normal, except messages from these two people”.

Read straight off shellConfig, so the rules hot-reload with the rest of shell.json.

Prior art

dunst has carried this for years: its rules match appname / desktop_entry / msg_urgency and urgency is among the attributes they can set. mako matches on a comparable field set with POSIX regex on summary / body. Both converged on declarative multi-field criteria rather than an expression language, which is what this follows.

Implementation notes

  • The mapping lands in snapshotOf(). Every snapshot funnels through it, replacementSnapshot() included, so notifications updated in place via replaces_id are mapped on the same path.
  • shouldBypassDnd() now takes the snapshot instead of the live notification, so it reads the mapped urgency. Without this a sender mapped below critical would keep bypassing do-not-disturb and the mapping would only half apply. Its four existing assertions were updated to pass app rather than appName.
  • isEphemeral() deliberately still reads the live object: it looks at the transient hint and the app name, neither of which the mapping touches.
  • A rule whose regular expression does not compile is skipped rather than propagated, so a typo in shell.json cannot take a notification down with it.

Testing

test/shell.d/notifications-test.sh covers the pure logic: matching by app and by regex, AND across matchers, later-rule-wins, an unknown urgency name, absent rules, and a malformed pattern. Three further assertions check the Service.qml wiring the way that file already checks the rest of the service.

./test/all passes except config-test.sh, snapper-test.sh and unowned-system-paths-test.sh, which fail identically on a clean checkout here (they want a sibling omarchy-pkgs checkout and a real system layout).

Also verified end to end on a running Omarchy 4.0.2 desktop, with the rules above in shell.json: a critical from the browser expired on the normal 8s timer, a matching summary stayed pinned, an unmapped CLI critical stayed pinned, and a notify-send critical mapped down to normal correctly stopped bypassing do-not-disturb.

Relationship to existing work

Related to #9361, which reports that critical notifications never auto-expire. This does not close it: that report is about Omarchy’s own crash toasts, which are genuinely critical, and remapping those would be the wrong fix. A bounded default for critical, as the issue suggests, remains a separate change.

Orthogonal to #9010 and #8980, which both add a visible dismiss control. This touches neither the card nor durationFor().

🤖 Generated with Claude Code

https://claude.ai/code/session_01DLxWtBaFee73f3cnkcA4iu

Senders pick their own urgency and some misdeclare it. Chat apps mark
routine messages critical to force their way in front of you, and a
critical toast never expires, so those messages sit on screen until they
are dismissed by hand.

Urgency is read by every downstream decision — popup lifetime, the
do-not-disturb bypass, card styling, what lands in history — so correcting
it once, at ingest, keeps all of them honest instead of special-casing each
in turn. A `notifications.rules[]` block in shell.json now does that:

    "notifications": {
      "rules": [
        { "app": "Brave Origin", "urgency": "critical", "set": { "urgency": "normal" } },
        { "app": "Brave Origin", "summary~": "Alex|Sam", "set": { "urgency": "critical" } }
      ]
    }

A rule filters on the fields it names (app, appIcon, summary, body and the
incoming urgency) and every one of them has to match; a `~` suffix makes the
value a regular expression, following mako's `summary~` convention. Rules
apply in order and the last match wins, so a broad rule can be narrowed by a
later one. dunst has carried the same capability for years, where rules match
appname/desktop_entry and can set urgency directly.

The mapping lands in snapshotOf(), which every snapshot funnels through,
including the replaces_id update path. shouldBypassDnd() now reads the
snapshot rather than the live notification, so a sender mapped below critical
stops bypassing do-not-disturb too — otherwise the mapping would only half
apply.

A rule whose regular expression does not compile is skipped rather than
propagated, so a typo in shell.json cannot take a notification down with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLxWtBaFee73f3cnkcA4iu
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @wjax. Since #16430 notifications have no settings in shell.json at all, so per-app urgency rules would bring back exactly the configuration surface that change removed. Checked by Claude Opus 5.5 against current quattro; no second-opinion review ran. Closing on the maintainer's decision.

@omarchybot omarchybot closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants