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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ It comes in two styles, chosen in **Settings… → Menu Bar**:
<img src="docs/images/clip-counts.avif" alt="The same scene with the Counts icon: the one session moves from done to working, to needs you, and back to done" width="640">

Click the date and time to open Notification Center, choose **Edit Widgets**, and add **Agent Watch**.
The small widget opens **Projects & Recent**. The medium widget also has **Waiting for you**, which
opens the same list of waiting chats as the beacon, and **Settings**. Both work when the menu bar icon is hidden.
The small widget opens **Projects & Recent**. The medium widget also has shortcuts to
**Waiting for you** in that window and to **Settings**. Both widgets work when the menu bar icon is hidden.

An optional orange beacon appears when a chat is waiting for your reply. Choose **Full screen only** or **All modes** to show it on windowed desktops too.
Click the ring and choose a chat to open it. Right-click it to open **Waiting Beacon Settings…**.
Click the ring to open **Projects & Recent** on **Waiting for you**, then choose a chat.
Right-click the ring to open **Waiting Beacon Settings…**.
You can also open **Settings → Waiting Beacon** to turn it on, resize it, or choose its position.

<img src="docs/images/full-screen-beacon.png" alt="An orange light on the rim of the waiting-chat beacon" width="56">
Expand Down
18 changes: 6 additions & 12 deletions Sources/AgentWatchApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
self?.supervisor.focusSession(id: id, requireDesktopLink: true) ?? .nothingRaised
},
resetBeacon: { [weak self] id in self?.supervisor.resetCodexQuestionBeacon(forSessionWithID: id) })
private lazy var waitingWindow = WaitingChatsWindow(model: waitingChats)
private lazy var fullScreenDot = FullScreenDot(
openWaiting: { [weak self] in self?.waitingWindow.present() },
openWaiting: { [weak self] screen in self?.navigate(to: .waiting, on: screen) },
openSettings: { [weak self] in
self?.settingsWindow.model.go(.waitingBeacon)
self?.showWidgetSettings()
Expand Down Expand Up @@ -771,32 +770,27 @@ extension AppDelegate: StatusMenuHost, SettingsHost {
return false
}

private func navigate(to destination: WatchDestination) {
private func navigate(to destination: WatchDestination, on screen: NSScreen? = nil) {
switch destination {
case .projects: showProjects()
// The widget's link opens the same list as the beacon: one list of waiting chats.
case .waiting: waitingWindow.present()
case .waiting: presentProjects(.waiting, on: screen)
case .settings: showWidgetSettings()
}
}

func showProjects() { presentProjects(.recent) }

private func presentProjects(_ scope: ProjectBrowserScope) {
private func presentProjects(_ scope: ProjectBrowserScope, on screen: NSScreen? = nil) {
if projectsWindow == nil {
projectsWindow = ProjectBrowserWindow(
openSession: { [weak self] id in self?.focusSession(id: id) ?? .nothingRaised },
waitingChats: waitingChats,
settings: { [weak self] in self?.showWidgetSettings() }
) { [weak self] in
guard let self else { return }
updateProjects(supervisor.sessions, refresh: true)
}
}
projectsWindow?.model.navigate(to: scope)
let wasKey = projectsWindow?.window?.isKeyWindow == true
projectsWindow?.showWindow(nil)
NSApplication.shared.activate(ignoringOtherApps: true)
if wasKey { updateProjects(supervisor.sessions, refresh: true) }
projectsWindow?.present(scope, on: screen)
}

private func updateProjects(_ sessions: [SessionSnapshot], refresh: Bool = false) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/AgentWatchApp/FullScreenDot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import AppKit
@MainActor
final class FullScreenDot: NSObject {
private var panels: [WaitingBeaconPanel] = []
private let openWaiting: () -> Void
private let openWaiting: (NSScreen?) -> Void
private let openSettings: () -> Void
private var waitingCount = 0
private var isEnabled = false
private var scope = WaitingBeaconScope.fullScreenOnly

init(openWaiting: @escaping () -> Void, openSettings: @escaping () -> Void) {
init(openWaiting: @escaping (NSScreen?) -> Void, openSettings: @escaping () -> Void) {
self.openWaiting = openWaiting
self.openSettings = openSettings
super.init()
Expand Down Expand Up @@ -134,7 +134,7 @@ final class FullScreenDot: NSObject {
private final class WaitingBeaconPanel: NSPanel {
let button: WaitingBeaconButton

init(openWaiting: @escaping () -> Void, openSettings: @escaping () -> Void) {
init(openWaiting: @escaping (NSScreen?) -> Void, openSettings: @escaping () -> Void) {
button = WaitingBeaconButton(openSettings: openSettings, openWaiting: openWaiting)
super.init(
contentRect: button.bounds, styleMask: [.borderless, .nonactivatingPanel],
Expand Down Expand Up @@ -171,9 +171,9 @@ final class WaitingBeaconButton: NSButton {
private let light = CALayer()
private(set) var diameter: CGFloat = WidgetTheme.Timing.Dot().ringDiameter
private let openSettings: () -> Void
private let openWaiting: () -> Void
private let openWaiting: (NSScreen?) -> Void

init(openSettings: @escaping () -> Void = {}, openWaiting: @escaping () -> Void) {
init(openSettings: @escaping () -> Void = {}, openWaiting: @escaping (NSScreen?) -> Void) {
self.openSettings = openSettings
self.openWaiting = openWaiting
super.init(frame: NSRect(x: 0, y: 0, width: Self.side, height: Self.side))
Expand Down Expand Up @@ -213,7 +213,7 @@ final class WaitingBeaconButton: NSButton {

@objc private func configure() { openSettings() }

@objc private func openList() { openWaiting() }
@objc private func openList() { openWaiting(window?.screen) }

func showCount(_ count: Int) {
title = count > 99 ? "99+" : String(count)
Expand Down
51 changes: 44 additions & 7 deletions Sources/AgentWatchApp/ProjectBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum ProjectBrowserFilter: String, CaseIterable {
}

enum ProjectBrowserScope: Hashable {
case recent, project(URL), unknown, profiles
case recent, waiting, project(URL), unknown, profiles
}

enum WatchDestination: String, CaseIterable {
Expand Down Expand Up @@ -208,10 +208,9 @@ final class ProjectBrowserModel: ObservableObject {
@MainActor
final class ProjectBrowserWindow: NSWindowController, NSWindowDelegate {
let model = ProjectBrowserModel()
let refresh: () -> Void
private let refresh: () -> Void

init(openSession: @escaping (String) -> SessionClick, settings: @escaping () -> Void, refresh: @escaping () -> Void)
{
init(waitingChats: WaitingChatsModel, settings: @escaping () -> Void, refresh: @escaping () -> Void) {
self.refresh = refresh
let window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 840, height: 540),
Expand All @@ -222,22 +221,56 @@ final class ProjectBrowserWindow: NSWindowController, NSWindowDelegate {
window.center()
super.init(window: window)
window.contentView = NSHostingView(
rootView: ProjectBrowserView(model: model, refresh: refresh, openSession: openSession, settings: settings))
rootView: ProjectBrowserView(model: model, waitingChats: waitingChats, refresh: refresh, settings: settings)
)
window.delegate = self
}

@available(*, unavailable)
required init?(coder: NSCoder) { nil }

func present(_ scope: ProjectBrowserScope, on preferredScreen: NSScreen?) {
guard let window else { return }
model.navigate(to: scope)
let wasKey = window.isKeyWindow
let showsWaiting = scope == .waiting
let targetScreen =
showsWaiting
? preferredScreen ?? NSScreen.screens.first { $0.frame.contains(NSEvent.mouseLocation) }
: nil

// Waiting can open from another app's full-screen Space, including Split View.
window.collectionBehavior =
showsWaiting
? [.moveToActiveSpace, .canJoinAllApplications, .fullScreenAuxiliary]
: [.moveToActiveSpace]
window.level = showsWaiting ? .floating : .normal
if let screen = targetScreen, !window.isVisible || !window.isOnActiveSpace || window.screen != screen {
let area = screen.visibleFrame
window.setFrameOrigin(
NSPoint(x: area.midX - window.frame.width / 2, y: area.midY - window.frame.height / 2))
}
if window.isMiniaturized { window.deminiaturize(nil) }
showWindow(nil)
NSApp.activate(ignoringOtherApps: true)
if wasKey { refresh() }
}

func windowDidBecomeKey(_ notification: Notification) { refresh() }

func windowDidResignKey(_ notification: Notification) {
guard let window, window.level == .floating else { return }
window.level = .normal
window.collectionBehavior = [.moveToActiveSpace]
}

func windowWillClose(_ notification: Notification) { model.stop() }
}

private struct ProjectBrowserView: View {
@ObservedObject var model: ProjectBrowserModel
let waitingChats: WaitingChatsModel
let refresh: () -> Void
let openSession: (String) -> SessionClick
let settings: () -> Void

private var projects: [GitWorkingCopy] {
Expand All @@ -250,6 +283,8 @@ private struct ProjectBrowserView: View {
NavigationSplitView {
List(selection: $model.scope) {
Label("Recent", systemImage: "clock").tag(ProjectBrowserScope.recent)
Label("Waiting for you", systemImage: "bubble.left.and.exclamationmark.bubble.right")
.tag(ProjectBrowserScope.waiting)
Label("Usage profiles", systemImage: "chart.bar").tag(ProjectBrowserScope.profiles)
Section("Projects") {
ForEach(projects, id: \.commonDirectory) { copy in
Expand All @@ -267,7 +302,9 @@ private struct ProjectBrowserView: View {
}
.navigationSplitViewColumnWidth(min: 150, ideal: 205)
} detail: {
if model.scope == .profiles, let folders = model.folders {
if model.scope == .waiting {
WaitingChatsView(model: waitingChats)
} else if model.scope == .profiles, let folders = model.folders {
UsageProfilesView(
folders: folders, defaultClaudeUsage: model.claudeUsage, sessions: model.profileSessions,
readsTranscripts: model.readsTranscripts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AgentWatchCore
import AppKit
import SwiftUI

@MainActor
Expand Down Expand Up @@ -40,11 +39,9 @@ final class WaitingChatsModel: ObservableObject {
if let unavailableID, !waiting.contains(where: { $0.id == unavailableID }) { self.unavailableID = nil }
}

func open(_ id: String) -> Bool {
guard rows.contains(where: { $0.id == id }) else { return false }
let opened = focus(id) == .raised
unavailableID = opened ? nil : id
return opened
func open(_ id: String) {
guard rows.contains(where: { $0.id == id }) else { return }
unavailableID = focus(id) == .raised ? nil : id
}

func resetBeacon(for id: String) {
Expand All @@ -53,44 +50,8 @@ final class WaitingChatsModel: ObservableObject {
}
}

@MainActor
final class WaitingChatsWindow: NSWindowController {
init(model: WaitingChatsModel) {
let panel = NSPanel(
contentRect: NSRect(x: 0, y: 0, width: 380, height: 280),
styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false)
panel.title = "Chats waiting for your reply"
panel.isReleasedWhenClosed = false
panel.contentMinSize = NSSize(width: 280, height: 120)
panel.collectionBehavior = [.moveToActiveSpace, .canJoinAllApplications, .fullScreenAuxiliary]
panel.level = .floating
super.init(window: panel)
panel.contentView = NSHostingView(
rootView: WaitingChatsView(model: model) { [weak panel] id in
if model.open(id) { panel?.orderOut(nil) }
})
}

@available(*, unavailable)
required init?(coder: NSCoder) { fatalError() }

func present() {
guard let window else { return }
if let screen = NSScreen.screens.first(where: { $0.frame.contains(NSEvent.mouseLocation) }),
!window.isVisible || window.screen != screen
{
let area = screen.visibleFrame
window.setFrameOrigin(
NSPoint(x: area.midX - window.frame.width / 2, y: area.midY - window.frame.height / 2))
}
NSApp.activate(ignoringOtherApps: true)
window.makeKeyAndOrderFront(nil)
}
}

private struct WaitingChatsView: View {
struct WaitingChatsView: View {
@ObservedObject var model: WaitingChatsModel
let open: (String) -> Void

var body: some View {
if model.rows.isEmpty {
Expand All @@ -100,7 +61,7 @@ private struct WaitingChatsView: View {
} else {
List(model.rows) { row in
Button {
open(row.id)
model.open(row.id)
} label: {
HStack {
VStack(alignment: .leading, spacing: 3) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/AgentWatchAppTests/DocumentationRenderProbe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class DocumentationRenderProbe: XCTestCase {

func testDrawTheWaitingBeacon() throws {
let root = try outputDirectory()
let beacon = WaitingBeaconButton {}
let beacon = WaitingBeaconButton { _ in }
beacon.showCount(2)
try write(framed(beacon, padding: 6, color: .clear), "full-screen-beacon", in: root)
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/AgentWatchAppTests/FullScreenDotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class FullScreenDotTests: XCTestCase {

func testBeaconIsAnActionWithAnAccessibleExactCountEvenWhenTheNumberIsAbbreviated() {
var opened = 0
let beacon = WaitingBeaconButton { opened += 1 }
let beacon = WaitingBeaconButton { _ in opened += 1 }
beacon.showCount(126)
XCTAssertEqual(beacon.title, "99+")
XCTAssertEqual(beacon.accessibilityLabel(), "126 chats waiting for a reply")
Expand All @@ -52,7 +52,7 @@ final class FullScreenDotTests: XCTestCase {
func testBeaconSizeKeepsTheClickTargetAndItsContextMenuOpensSettings() throws {
var settingsOpened = false
var chatsOpened = false
let beacon = WaitingBeaconButton(openSettings: { settingsOpened = true }) { chatsOpened = true }
let beacon = WaitingBeaconButton(openSettings: { settingsOpened = true }) { _ in chatsOpened = true }
XCTAssertEqual(beacon.diameter, 24)
beacon.setDiameter(30)
XCTAssertEqual(beacon.diameter, 30)
Expand All @@ -65,7 +65,7 @@ final class FullScreenDotTests: XCTestCase {
}

func testReduceMotionStopsTheOrbitAndKeepsTheCount() {
let beacon = WaitingBeaconButton {}
let beacon = WaitingBeaconButton { _ in }
beacon.showCount(3)
beacon.setRotating(true)
XCTAssertTrue(beacon.isRotating)
Expand Down
9 changes: 7 additions & 2 deletions Tests/AgentWatchAppTests/ProjectBrowserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ final class ProjectBrowserTests: XCTestCase {
model.scope = .profiles
model.search = "an old search"
model.filter = .quiet
model.navigate(to: .recent)
XCTAssertEqual(model.scope, .recent)
model.message = "An old opening error"
model.navigate(to: .waiting)
XCTAssertEqual(model.scope, .waiting)
XCTAssertTrue(model.search.isEmpty)
XCTAssertEqual(model.filter, .all)
XCTAssertNil(model.message)

model.navigate(to: .recent)
XCTAssertEqual(model.scope, .recent)
}

/// A new chat appearing while a click is being resolved rereads the list; the click still
Expand Down
10 changes: 5 additions & 5 deletions Tests/AgentWatchAppTests/WaitingChatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ final class WaitingChatsTests: XCTestCase {

model.update([first, headless, second])
XCTAssertEqual(model.rows.map(\.id), [second.id, first.id])
XCTAssertTrue(model.open(first.id))
model.open(first.id)
model.update([third, second])
XCTAssertEqual(model.rows.map(\.id), [third.id, second.id])
XCTAssertFalse(model.open(first.id))
XCTAssertTrue(model.open(second.id))
model.open(first.id)
model.open(second.id)
XCTAssertEqual(focused, [first.id, second.id])
model.update([])
XCTAssertTrue(model.rows.isEmpty)
Expand Down Expand Up @@ -90,10 +90,10 @@ final class WaitingChatsTests: XCTestCase {
var result = SessionClick.nothingRaised
let model = WaitingChatsModel(focus: { _ in result }, resetBeacon: { _ in })
model.update([session])
XCTAssertFalse(model.open(session.id))
model.open(session.id)
XCTAssertEqual(model.unavailableID, session.id)
result = .raised
XCTAssertTrue(model.open(session.id))
model.open(session.id)
XCTAssertNil(model.unavailableID)
}
}
9 changes: 6 additions & 3 deletions docs/menu-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@
В `Settings → Waiting Beacon` включите `Show waiting beacon`. В поле `Show in` выберите
`Full screen only` для полноэкранных рабочих столов или `All modes` для всех подключённых экранов,
включая рабочие столы с обычными окнами. Под строкой меню
появляется оранжевое кольцо с числом чатов, которые ждут ответа. Щелчок открывает их список. Выберите чат в списке, чтобы вернуться к вопросу. Для настольных
Claude и Codex список закрывается после передачи ссылки на выбранный чат. Если ссылку получить
или открыть не удалось, строка предлагает открыть чат в приложении или повторить попытку.
появляется оранжевое кольцо с числом чатов, которые ждут ответа. Щелчок выводит окно
`Projects & Recent` на передний план и выбирает раздел `Waiting for you`. Выберите чат, чтобы
вернуться к вопросу. Если открыть чат не удалось, строка предлагает открыть его в приложении
или повторить попытку.

Чтобы убрать сигнал об уже показанных асинхронных вопросах Codex, нажмите правой кнопкой на чат
в списке и выберите `Reset Beacon`. Обычное текстовое сообщение в том же чате тоже сбрасывает
Expand Down Expand Up @@ -121,6 +122,8 @@ Claude и Codex список закрывается после передачи
### Проекты и недавние чаты

Пункт `Projects & Recent…` открывает окно с наблюдаемыми чатами настольных Claude и Codex.
Раздел `Waiting for you` показывает те же ожидающие чаты, которые считает маячок, включая
сессии в терминале.
То же окно открывается, когда уже запущенный Agent Watch открывают снова из Finder или Spotlight:
так до него можно добраться и со скрытым значком в строке меню.
В разделе `Recent` видно до 20 чатов. Сначала идут текущие, затем чаты с завершённым ходом,
Expand Down
Loading
Loading