diff --git a/Tests/StackNudgePanelCoreTests/EventsListTests.swift b/Tests/StackNudgePanelCoreTests/EventsListTests.swift index e080111d..50b634c8 100644 --- a/Tests/StackNudgePanelCoreTests/EventsListTests.swift +++ b/Tests/StackNudgePanelCoreTests/EventsListTests.swift @@ -233,6 +233,27 @@ 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. 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")) + 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) + 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() { 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..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, 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/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..d50e0b7e 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: the Events tab count minus snoozed events. + 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