Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Tests/StackNudgePanelCoreTests/EventsListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion docs/panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|---------|-----|--------|
Expand Down
2 changes: 1 addition & 1 deletion panel/Companion/CompanionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
10 changes: 9 additions & 1 deletion panel/EventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Comment thread
adefreitas marked this conversation as resolved.
Resolved
}

func unreadCount(forTag tag: String) -> Int {
events.filter { $0.isUnread && EventTagFilter.key(for: $0) == tag }.count
Expand Down
Loading