From 2c662ced202eb9175cbe4108a7f2ea49770e6284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?= <6485562+adefreitas@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:00:01 +0000 Subject: [PATCH 1/2] fix(companion): the badge counts what the Events tab counts The badge and the waiting pose counted every listed event, so read notifications, which stay listed, kept counting: 29 on the badge against 10 on the tab. Both now use the tab's rule: prompts and stops, and notifications until read, less any snoozed. Co-Authored-By: Claude Opus 5.5 --- .../EventsListTests.swift | 17 +++++++++++++++++ docs/panel.md | 2 +- panel/Companion/CompanionController.swift | 2 +- panel/EventStore.swift | 10 +++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Tests/StackNudgePanelCoreTests/EventsListTests.swift b/Tests/StackNudgePanelCoreTests/EventsListTests.swift index e080111d..691fb13d 100644 --- a/Tests/StackNudgePanelCoreTests/EventsListTests.swift +++ b/Tests/StackNudgePanelCoreTests/EventsListTests.swift @@ -233,6 +233,23 @@ final class EventsListTests: XCTestCase { XCTAssertEqual(store.events[0].url?.host, "example.com") } + // The companion's badge read 29 while the Events tab said 10: it counted + // notifications already read, which stay listed. + func testTheCompanionWaitsOnWhatTheEventsTabCounts() { + let store = EventStore() + let now = Date() + store.append(feed("unread")) + store.append(feed("read")) + store.append(feed("snoozed")) + store.append(stop(asks: false)) + let read = store.events.first { $0.message == "read" }! + store.setRead(id: read.id, true) + let snoozed = store.events.first { $0.message == "snoozed" }! + store.setSnoozedUntil(id: snoozed.id, now.addingTimeInterval(600)) + XCTAssertEqual(store.pendingCount, 3) + XCTAssertEqual(Set(EventStore.waiting(store.events, now: now).map(\.message)), ["unread", "Done"]) + } + func testRestoreSkipsOldRecords() { let stale = feed("stale", at: Date().addingTimeInterval(-EventStore.restoreWindow - 60)) let store = EventStore() diff --git a/docs/panel.md b/docs/panel.md index b4db3d6d..11a77ef2 100644 --- a/docs/panel.md +++ b/docs/panel.md @@ -273,7 +273,7 @@ The companion is a small animated character that floats on your desktop and take - **Drag** it anywhere; it stays where you drop it, and comes back on screen if a display it was on goes away. - **Right-click** for the menu, including a **Companion** submenu with its size and **Reset position**, which puts it back where a fresh install starts it. -Its pose follows what stack-nudge knows: thinking while an agent is busy, watching while agent sessions are live, waiting when an event or a permission prompt is queued, alert when a quota is past your alert threshold, muted while notifications are muted, and asleep after five quiet minutes. The waiting pose is a wave: it means something wants you to act, and a finished agent turn is one of those, so it still waves. A new finished turn also gets a single small nod on arrival, when the character is otherwise calm (idle or asleep), not muted, and Reduce Motion is off. A count badge at its corner shows how many events are waiting, grey while muted. It animates on the render server and pauses while it is covered, the display sleeps or the screen is locked, so it stays near 0% CPU. With Reduce Motion on, it holds still. +Its pose follows what stack-nudge knows: thinking while an agent is busy, watching while agent sessions are live, waiting when an event or a permission prompt is queued, alert when a quota is past your alert threshold, muted while notifications are muted, and asleep after five quiet minutes. The waiting pose is a wave: it means something wants you to act, and a finished agent turn is one of those, so it still waves. A new finished turn also gets a single small nod on arrival, when the character is otherwise calm (idle or asleep), not muted, and Reduce Motion is off. A count badge at its corner shows how many events are waiting, the same count as the Events tab (a notification stops counting once read), grey while muted. It animates on the render server and pauses while it is covered, the display sleeps or the screen is locked, so it stays near 0% CPU. With Reduce Motion on, it holds still. | Setting | Key | Values | |---------|-----|--------| diff --git a/panel/Companion/CompanionController.swift b/panel/Companion/CompanionController.swift index 02991047..b0f13367 100644 --- a/panel/Companion/CompanionController.swift +++ b/panel/Companion/CompanionController.swift @@ -91,7 +91,7 @@ final class CompanionController { private func refreshModel(now: Date = Date()) { guard nav.companionEnabled else { return } - let waiting = store.events.filter { ($0.snoozedUntil ?? .distantPast) <= now } + let waiting = EventStore.waiting(store.events, now: now) let live = sessions.liveSessions // Anything to show resets the nap clock; only a quiet spell lets it doze. if !waiting.isEmpty || !live.isEmpty { quietSince = now } diff --git a/panel/EventStore.swift b/panel/EventStore.swift index 72371e10..963c83f8 100644 --- a/panel/EventStore.swift +++ b/panel/EventStore.swift @@ -543,7 +543,15 @@ final class EventStore: ObservableObject { // What the Events tab label counts: prompts and stops are always pending, // a feed event only while unread. - var pendingCount: Int { events.filter { !$0.isFeed || !$0.isRead }.count } + var pendingCount: Int { events.filter(Self.isPending).count } + + static func isPending(_ event: NudgeEvent) -> Bool { !event.isFeed || !event.isRead } + + // What the companion waits on and its badge counts: the pending events, + // less any snoozed, so it agrees with the Events tab. + static func waiting(_ events: [NudgeEvent], now: Date) -> [NudgeEvent] { + events.filter { isPending($0) && ($0.snoozedUntil ?? .distantPast) <= now } + } func unreadCount(forTag tag: String) -> Int { events.filter { $0.isUnread && EventTagFilter.key(for: $0) == tag }.count From 521d7bd8c7ad7ed1173a9d83e12f4cc6c38a0236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?= <6485562+adefreitas@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:17:22 +0000 Subject: [PATCH 2/2] fix: address review feedback - badge doc and code comment now say the badge is the Events tab count less snoozed events - the companion test states the snooze difference: pendingCount 3 vs waiting 2, with the snoozed event named Co-Authored-By: Claude Opus 5.5 --- Tests/StackNudgePanelCoreTests/EventsListTests.swift | 10 +++++++--- docs/panel.md | 2 +- panel/EventStore.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Tests/StackNudgePanelCoreTests/EventsListTests.swift b/Tests/StackNudgePanelCoreTests/EventsListTests.swift index 691fb13d..50b634c8 100644 --- a/Tests/StackNudgePanelCoreTests/EventsListTests.swift +++ b/Tests/StackNudgePanelCoreTests/EventsListTests.swift @@ -234,8 +234,9 @@ final class EventsListTests: XCTestCase { } // The companion's badge read 29 while the Events tab said 10: it counted - // notifications already read, which stay listed. - func testTheCompanionWaitsOnWhatTheEventsTabCounts() { + // notifications already read, which stay listed. It still differs from the + // tab by the snoozed events, which the tab counts and the badge leaves out. + func testTheCompanionWaitsOnTheEventsTabCountLessSnoozed() { let store = EventStore() let now = Date() store.append(feed("unread")) @@ -247,7 +248,10 @@ final class EventsListTests: XCTestCase { let snoozed = store.events.first { $0.message == "snoozed" }! store.setSnoozedUntil(id: snoozed.id, now.addingTimeInterval(600)) XCTAssertEqual(store.pendingCount, 3) - XCTAssertEqual(Set(EventStore.waiting(store.events, now: now).map(\.message)), ["unread", "Done"]) + let waiting = EventStore.waiting(store.events, now: now) + XCTAssertEqual(waiting.count, 2) + XCTAssertEqual(Set(waiting.map(\.message)), ["unread", "Done"]) + XCTAssertFalse(waiting.contains { $0.message == "snoozed" }) } func testRestoreSkipsOldRecords() { diff --git a/docs/panel.md b/docs/panel.md index 11a77ef2..2a14ca50 100644 --- a/docs/panel.md +++ b/docs/panel.md @@ -273,7 +273,7 @@ The companion is a small animated character that floats on your desktop and take - **Drag** it anywhere; it stays where you drop it, and comes back on screen if a display it was on goes away. - **Right-click** for the menu, including a **Companion** submenu with its size and **Reset position**, which puts it back where a fresh install starts it. -Its pose follows what stack-nudge knows: thinking while an agent is busy, watching while agent sessions are live, waiting when an event or a permission prompt is queued, alert when a quota is past your alert threshold, muted while notifications are muted, and asleep after five quiet minutes. The waiting pose is a wave: it means something wants you to act, and a finished agent turn is one of those, so it still waves. A new finished turn also gets a single small nod on arrival, when the character is otherwise calm (idle or asleep), not muted, and Reduce Motion is off. A count badge at its corner shows how many events are waiting, the same count as the Events tab (a notification stops counting once read), grey while muted. It animates on the render server and pauses while it is covered, the display sleeps or the screen is locked, so it stays near 0% CPU. With Reduce Motion on, it holds still. +Its pose follows what stack-nudge knows: thinking while an agent is busy, watching while agent sessions are live, waiting when an event or a permission prompt is queued, alert when a quota is past your alert threshold, muted while notifications are muted, and asleep after five quiet minutes. The waiting pose is a wave: it means something wants you to act, and a finished agent turn is one of those, so it still waves. A new finished turn also gets a single small nod on arrival, when the character is otherwise calm (idle or asleep), not muted, and Reduce Motion is off. A count badge at its corner shows how many events are waiting, the Events tab count less snoozed events (a notification stops counting once read), grey while muted. It animates on the render server and pauses while it is covered, the display sleeps or the screen is locked, so it stays near 0% CPU. With Reduce Motion on, it holds still. | Setting | Key | Values | |---------|-----|--------| diff --git a/panel/EventStore.swift b/panel/EventStore.swift index 963c83f8..d50e0b7e 100644 --- a/panel/EventStore.swift +++ b/panel/EventStore.swift @@ -548,7 +548,7 @@ final class EventStore: ObservableObject { static func isPending(_ event: NudgeEvent) -> Bool { !event.isFeed || !event.isRead } // What the companion waits on and its badge counts: the pending events, - // less any snoozed, so it agrees with the Events tab. + // less any snoozed: the Events tab count minus snoozed events. static func waiting(_ events: [NudgeEvent], now: Date) -> [NudgeEvent] { events.filter { isPending($0) && ($0.snoozedUntil ?? .distantPast) <= now } }