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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ It comes in two styles, chosen in **Settings… → Menu Bar**:

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 shortcuts to
**Waiting for you** in that window and to **Settings**. Both widgets work when the menu bar icon is hidden.
the **Waiting for you** filter in **Recent** 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 to open **Projects & Recent** on **Waiting for you**, then choose a chat.
Click the ring to open **Recent** with the **Waiting for you** filter selected, 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.

Expand Down Expand Up @@ -223,8 +223,9 @@ Open **Projects & Recent…** from the menu bar to find an observed Claude or Co
Opening Agent Watch again from Finder or Spotlight opens the same window, even with the menu bar
icon hidden.
Linked Git working folders appear under the same project. Filter by activity, search by branch or
chat name, and open the matching conversation. Recent shows up to 20 chats. **Usage profiles**
shows the last observed limits and their time for the default Claude profile and configured Codex folders.
chat name, and open the matching conversation. **Waiting for you** lists all chats waiting for a
reply. The other **Recent** filters show up to 20 chats. **Usage profiles** shows the last observed
limits and their time for the default Claude profile and configured Codex folders.

In **Settings… → Git Protection**, check the hook status beside each Claude Code or Codex
profile. Click **Install…** to connect a profile or **Repair…** to fix an outdated hook.
Expand Down
8 changes: 4 additions & 4 deletions Sources/AgentWatchApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,14 @@ extension AppDelegate: StatusMenuHost, SettingsHost {
private func navigate(to destination: WatchDestination, on screen: NSScreen? = nil) {
switch destination {
case .projects: showProjects()
case .waiting: presentProjects(.waiting, on: screen)
case .waiting: presentProjects(filter: .waiting, on: screen)
case .settings: showWidgetSettings()
}
}

func showProjects() { presentProjects(.recent) }
func showProjects() { presentProjects(filter: .all) }

private func presentProjects(_ scope: ProjectBrowserScope, on screen: NSScreen? = nil) {
private func presentProjects(filter: ProjectBrowserFilter, on screen: NSScreen? = nil) {
if projectsWindow == nil {
projectsWindow = ProjectBrowserWindow(
waitingChats: waitingChats,
Expand All @@ -790,7 +790,7 @@ extension AppDelegate: StatusMenuHost, SettingsHost {
updateProjects(supervisor.sessions, refresh: true)
}
}
projectsWindow?.present(scope, on: screen)
projectsWindow?.presentRecent(filter: filter, on: screen)
}

private func updateProjects(_ sessions: [SessionSnapshot], refresh: Bool = false) {
Expand Down
66 changes: 38 additions & 28 deletions Sources/AgentWatchApp/ProjectBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ struct ProjectBrowserEntry: Identifiable, Equatable, Sendable {
var session: SessionSnapshot
let copy: GitWorkingCopy?
var id: String { session.id }

func matchesSearch(_ needle: String) -> Bool {
let fields = [
session.title, session.projectName, session.gitBranch, session.source.rawValue, copy?.root.path,
copy?.projectURL.path,
]
return fields.compactMap { $0 }.contains { $0.localizedCaseInsensitiveContains(needle) }
}
}

enum ProjectBrowserFilter: String, CaseIterable {
Expand All @@ -27,7 +35,7 @@ enum ProjectBrowserFilter: String, CaseIterable {
}

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

enum WatchDestination: String, CaseIterable {
Expand Down Expand Up @@ -56,12 +64,7 @@ enum ProjectBrowserCatalog {
case .unknown where entry.copy != nil: return false
default: break
}
let fields = [
row.title, row.projectName, row.gitBranch, row.source.rawValue, entry.copy?.root.path,
entry.copy?.projectURL.path,
]
return filter.includes(row, now: now)
&& (needle.isEmpty || fields.compactMap { $0 }.contains { $0.localizedCaseInsensitiveContains(needle) })
return filter.includes(row, now: now) && (needle.isEmpty || entry.matchesSearch(needle))
}.sorted { left, right in
let lhs = left.session
let rhs = right.session
Expand All @@ -79,9 +82,11 @@ final class ProjectBrowserModel: ObservableObject {
@Published var filter = ProjectBrowserFilter.all
@Published var search = ""

func navigate(to scope: ProjectBrowserScope) {
self.scope = scope
filter = .all
var showsWaitingChats: Bool { (scope ?? .recent) == .recent && filter == .waiting }

func showRecent(filter: ProjectBrowserFilter) {
scope = .recent
self.filter = filter
search = ""
message = nil
}
Expand Down Expand Up @@ -229,11 +234,11 @@ final class ProjectBrowserWindow: NSWindowController, NSWindowDelegate {
@available(*, unavailable)
required init?(coder: NSCoder) { nil }

func present(_ scope: ProjectBrowserScope, on preferredScreen: NSScreen?) {
func presentRecent(filter: ProjectBrowserFilter, on preferredScreen: NSScreen?) {
guard let window else { return }
model.navigate(to: scope)
model.showRecent(filter: filter)
let wasKey = window.isKeyWindow
let showsWaiting = scope == .waiting
let showsWaiting = filter == .waiting
let targetScreen =
showsWaiting
? preferredScreen ?? NSScreen.screens.first { $0.frame.contains(NSEvent.mouseLocation) }
Expand Down Expand Up @@ -283,8 +288,6 @@ 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 @@ -302,9 +305,7 @@ private struct ProjectBrowserView: View {
}
.navigationSplitViewColumnWidth(min: 150, ideal: 205)
} detail: {
if model.scope == .waiting {
WaitingChatsView(model: waitingChats)
} else if model.scope == .profiles, let folders = model.folders {
if model.scope == .profiles, let folders = model.folders {
UsageProfilesView(
folders: folders, defaultClaudeUsage: model.claudeUsage, sessions: model.profileSessions,
readsTranscripts: model.readsTranscripts)
Expand All @@ -327,21 +328,30 @@ private struct ProjectBrowserView: View {
Picker("Filter", selection: $model.filter) {
ForEach(ProjectBrowserFilter.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}.pickerStyle(.segmented)
if model.entries.contains(where: { $0.session.phase.claimsWork }) {
TimelineView(.periodic(from: .now, by: 15)) { context in
chatList(now: context.date)
}
if model.showsWaitingChats {
WaitingChatsView(model: waitingChats, search: model.search, projectEntries: model.entries)
} else {
chatList(now: .now)
desktopChats
}
if let message = model.message { Text(message).foregroundStyle(.secondary) }
Text(
"Observed desktop chats with a verified link. Recent shows up to \(ProjectBrowserCatalog.recentLimit). Closed chats are excluded."
)
.font(.caption).foregroundStyle(.secondary)
}.padding()
}

@ViewBuilder
private var desktopChats: some View {
if model.entries.contains(where: { $0.session.phase.claimsWork }) {
TimelineView(.periodic(from: .now, by: 15)) { context in
chatList(now: context.date)
}
} else {
chatList(now: .now)
}
if let message = model.message { Text(message).foregroundStyle(.secondary) }
Text(
"Observed desktop chats with a verified link. Recent shows up to \(ProjectBrowserCatalog.recentLimit). Closed chats are excluded."
)
.font(.caption).foregroundStyle(.secondary)
}

@ViewBuilder
private func chatList(now: Date) -> some View {
let rows = ProjectBrowserCatalog.visible(
Expand Down
23 changes: 18 additions & 5 deletions Sources/AgentWatchApp/WaitingChats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ final class WaitingChatsModel: ObservableObject {
id = session.id
title = session.title ?? session.projectName ?? "Chat \(session.id.suffix(8))"
let agent = session.source == .codex ? "Codex" : "Claude"
detail = [agent, session.projectName == title ? nil : session.projectName].compactMap { $0 }.joined(
separator: " · ")
detail = [agent, session.projectName == title ? nil : session.projectName, session.gitBranch]
.compactMap { $0 }.joined(separator: " · ")
canResetBeacon = session.source == .codex && session.pendingCodexQuestions?.isEmpty == false
}
}
Expand All @@ -39,6 +39,16 @@ final class WaitingChatsModel: ObservableObject {
if let unavailableID, !waiting.contains(where: { $0.id == unavailableID }) { self.unavailableID = nil }
}

func visibleRows(search: String, projectEntries: [ProjectBrowserEntry]) -> [Row] {
let needle = search.trimmingCharacters(in: .whitespacesAndNewlines)
guard !needle.isEmpty else { return rows }
let projectMatches = Set(projectEntries.lazy.filter { $0.matchesSearch(needle) }.map(\.id))
return rows.filter { row in
projectMatches.contains(row.id) || row.title.localizedCaseInsensitiveContains(needle)
|| row.detail.localizedCaseInsensitiveContains(needle)
}
}

func open(_ id: String) {
guard rows.contains(where: { $0.id == id }) else { return }
unavailableID = focus(id) == .raised ? nil : id
Expand All @@ -52,14 +62,17 @@ final class WaitingChatsModel: ObservableObject {

struct WaitingChatsView: View {
@ObservedObject var model: WaitingChatsModel
let search: String
let projectEntries: [ProjectBrowserEntry]

var body: some View {
if model.rows.isEmpty {
Text("All caught up. No chats are waiting for a reply.")
let rows = model.visibleRows(search: search, projectEntries: projectEntries)
if rows.isEmpty {
Text(model.rows.isEmpty ? "All caught up. No chats are waiting for a reply." : "No matching chats")
.foregroundStyle(.secondary).padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
} else {
List(model.rows) { row in
List(rows) { row in
Button {
model.open(row.id)
} label: {
Expand Down
16 changes: 11 additions & 5 deletions Tests/AgentWatchAppTests/ProjectBrowserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,27 @@ final class ProjectBrowserTests: XCTestCase {
}

@MainActor
func testNavigatingStartsTheChosenScopeWithoutAnOldSearchOrFilter() {
func testOpeningRecentSelectsTheRequestedFilterAndClearsThePreviousSearch() {
let model = ProjectBrowserModel()
defer { model.stop() }
model.scope = .profiles
model.search = "an old search"
model.filter = .quiet
model.message = "An old opening error"
model.navigate(to: .waiting)
XCTAssertEqual(model.scope, .waiting)
model.showRecent(filter: .waiting)
XCTAssertEqual(model.scope, .recent)
XCTAssertEqual(model.filter, .waiting)
XCTAssertTrue(model.showsWaitingChats)
XCTAssertTrue(model.search.isEmpty)
XCTAssertEqual(model.filter, .all)
XCTAssertNil(model.message)

model.navigate(to: .recent)
model.scope = .unknown
XCTAssertFalse(model.showsWaitingChats)

model.showRecent(filter: .all)
XCTAssertEqual(model.scope, .recent)
XCTAssertEqual(model.filter, .all)
XCTAssertFalse(model.showsWaitingChats)
}

/// A new chat appearing while a click is being resolved rereads the list; the click still
Expand Down
20 changes: 20 additions & 0 deletions Tests/AgentWatchAppTests/WaitingChatsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import XCTest

@testable import AgentWatchApp
@testable import AgentWatchCore
@testable import AgentWatchLookup

@MainActor
final class WaitingChatsTests: XCTestCase {
Expand Down Expand Up @@ -34,6 +35,25 @@ final class WaitingChatsTests: XCTestCase {
XCTAssertTrue(model.rows.isEmpty)
}

func testSearchCanFindTerminalChatsAndKnownProjectFoldersWithoutCappingTheWaitingList() {
let now = Date(timeIntervalSince1970: 100)
var terminalChats = (1...25).map {
testSession(index: $0, phase: .waitingForUser, clientKind: .cli, lastObservedAt: now)
}
terminalChats[24].gitBranch = "Beacon-Fix"
let desktop = testSession(source: .codex, phase: .waitingForUser, clientKind: .desktop, lastObservedAt: now)
let root = URL(fileURLWithPath: "/workspace/shared-project")
let project = GitWorkingCopy(commonDirectory: root.appendingPathComponent(".git"), root: root)
let entries = [ProjectBrowserEntry(session: desktop, copy: project)]
let model = WaitingChatsModel(focus: { _ in .raised }, resetBeacon: { _ in })
model.update(terminalChats + [desktop])

XCTAssertEqual(model.visibleRows(search: "", projectEntries: entries).count, 26)
XCTAssertEqual(
model.visibleRows(search: " beacon-fix ", projectEntries: entries).map(\.id), [terminalChats[24].id])
XCTAssertEqual(model.visibleRows(search: "shared-project", projectEntries: entries).map(\.id), [desktop.id])
}

func testCodexCanKeepWorkingWhileItsQuestionIsInTheList() {
var session = testSession(source: .codex, phase: .executing, lastObservedAt: .now)
session.pendingCodexQuestions = ["question-1": .now]
Expand Down
Loading
Loading