Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a39089f
test: cover Claude needs input acknowledgement
austinywang May 26, 2026
63be611
fix: demote Claude needs input after acknowledgement
austinywang May 26, 2026
21d1d73
Merge remote-tracking branch 'origin/main' into issue-2576-native-cla…
austinywang May 26, 2026
5e8cc39
fix: scope agent input acknowledgement to matching notifications
austinywang May 26, 2026
eee40ab
fix: share structured agent notification registry
austinywang May 26, 2026
b3f1b94
Merge origin/main into issue-2576-native-claude-detection-should
austinywang Jun 6, 2026
2491b42
fix: acknowledge removed agent notifications
austinywang Jun 6, 2026
5481f40
test: cover sibling agent notification acknowledgement
austinywang Jun 6, 2026
0c22400
fix: keep agent status while unread alerts remain
austinywang Jun 6, 2026
ea845d0
test: cover agent notification panel id precedence
austinywang Jun 6, 2026
9f1671d
fix: prefer panel id for agent notification acknowledgement
austinywang Jun 6, 2026
8e71084
test: cover localized agent notification acknowledgement
austinywang Jun 6, 2026
bf2d2a9
fix: tag structured agent notifications by status key
austinywang Jun 6, 2026
f39ceec
fix: address agent status premerge feedback
austinywang Jun 6, 2026
673d58f
test: cover queued agent notification acknowledgement
austinywang Jun 6, 2026
d2a714a
fix: include queued agent notifications in acknowledgement guard
austinywang Jun 6, 2026
00a29f9
test: cover pending policy hook agent notifications
austinywang Jun 6, 2026
46a65d9
fix: track pending policy hook agent notifications
austinywang Jun 6, 2026
7d5d01b
Merge remote-tracking branch 'origin/main' into issue-2576-native-cla…
austinywang Jun 10, 2026
bfda23d
test: cover focus clearing feed-routed Claude needs-input
austinywang Jun 10, 2026
afca982
fix: clear feed-routed Claude needs-input on workspace focus
austinywang Jun 10, 2026
3bc1dfe
chore: refresh Swift file-length budget for needs-input fix
austinywang Jun 10, 2026
835f949
fix: keep ghostty submodule at main's pointer after merge
austinywang Jun 10, 2026
11c64b8
test: assert needs-input acknowledgement clears agent lifecycle
austinywang Jun 10, 2026
d8aa8b5
fix: demote agent lifecycle when needs-input is acknowledged
austinywang Jun 10, 2026
b523007
chore: refresh Swift file-length budget for lifecycle demotion fix
austinywang Jun 10, 2026
3f16c38
test: panel-scoped needs-input acknowledgement keeps sibling badge
austinywang Jun 11, 2026
29f0030
fix: scope needs-input acknowledgement by panel, not just status key
austinywang Jun 11, 2026
7f783d2
chore: refresh Swift file-length budget for panel-scoped acknowledgement
austinywang Jun 11, 2026
3c97954
Merge remote-tracking branch 'origin/main' into issue-2576-native-cla…
austinywang Jun 11, 2026
912d604
test: feed prompt on a panel blocks its lifecycle demotion
austinywang Jun 11, 2026
04bf222
fix: count pending feed/queue/policy inputs in panel lifecycle gate
austinywang Jun 11, 2026
d90e083
chore: refresh Swift file-length budget for panel lifecycle gate
austinywang Jun 11, 2026
e2d5726
fix: initialize feedTarget before defer in regression test
austinywang Jun 11, 2026
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
86 changes: 86 additions & 0 deletions Sources/TerminalNotificationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1555,20 +1555,91 @@ final class TerminalNotificationStore: ObservableObject {
}
}

private static let structuredAgentStatusKeyByNotificationTitle: [String: String] = {
let pairs = [
("Amp", "amp"),
("Antigravity", "antigravity"),
("Claude Code", "claude_code"),
("CodeBuddy", "codebuddy"),
("Codex", "codex"),
("Copilot", "copilot"),
("Cursor", "cursor"),
("Factory", "factory"),
("Gemini", "gemini"),
("Grok", "grok"),
("Hermes Agent", "hermes-agent"),
("OpenCode", "opencode"),
("Pi", "pi"),
("Qoder", "qoder"),
("Rovo Dev", "rovodev"),
]
return Dictionary(uniqueKeysWithValues: pairs.map { title, statusKey in
(title.trimmingCharacters(in: .whitespacesAndNewlines).lowercased(), statusKey)
})
}()

private static func normalizedStructuredAgentNotificationTitle(_ title: String) -> String {
title.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
}

private static func structuredAgentStatusKey(for notification: TerminalNotification) -> String? {
structuredAgentStatusKeyByNotificationTitle[
normalizedStructuredAgentNotificationTitle(notification.title)
]
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

private func acknowledgeStructuredAgentInputStatuses(for notificationsToAcknowledge: [TerminalNotification]) {
for notification in notificationsToAcknowledge {
Comment on lines +1711 to +1716

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep pending policy-hook input panel-scoped when the request already has a panelId.

workspaceHasTransientInput now blocks lifecycle demotion for every panel in the workspace, but the policy-hook path already knows the owning panel through NotificationPolicyContext.request.panelId. If panel A is waiting on a slow hook and the user acknowledges panel B, this keeps panel B in .needsInput until A’s hook returns, which breaks the panel-scoped acknowledgement contract and can keep sibling panels non-hibernatable longer than necessary.

💡 Narrow the transient guard to the owning panel when possible
-        let transientWorkspaceInputs = transientWorkspaceStructuredAgentInputKeys()
+        let transientWorkspaceInputs = transientWorkspaceStructuredAgentInputKeys()
+        let transientPanelInputs = transientPanelStructuredAgentInputKeys()
...
-                let workspaceHasTransientInput = transientWorkspaceInputs.contains(
-                    StructuredAgentInputNotificationKey(tabId: notification.tabId, statusKey: statusKey)
-                )
-                demotePanelLifecycle = !panelHasRemainingInput && !workspaceHasTransientInput
+                let panelHasTransientInput = transientPanelInputs.contains(
+                    StructuredAgentInputPanelKey(
+                        tabId: notification.tabId,
+                        panelId: acknowledgementPanelId,
+                        statusKey: statusKey
+                    )
+                )
+                demotePanelLifecycle = !panelHasRemainingInput && !panelHasTransientInput

You can still keep a workspace-wide fallback for truly unscoped queued inputs, but the policy-hook path already has enough information to avoid cross-panel bleed-through.

Also applies to: 1743-1746, 1776-1784

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Sources/TerminalNotificationStore.swift` around lines 1711 - 1716, Narrow the
transient demotion guard so policy-hook deliveries that already carry a panel id
only block lifecycle demotion for that specific panel instead of the whole
workspace: inside the loop over notificationsToAcknowledge (and the analogous
sites at 1743–1746 and 1776–1784), check
NotificationPolicyContext.request.panelId (or equivalent on the notification)
and, when present, mark only that panel as having transient input rather than
using transientWorkspaceStructuredAgentInputKeys()/workspace-wide blocking; fall
back to the existing workspace-wide transientWorkspaceInputs behavior only when
no panelId is available.

guard let statusKey = Self.structuredAgentStatusKey(for: notification),
let workspace = workspaceForStructuredAgentInputAcknowledgement(
tabId: notification.tabId,
surfaceId: notification.surfaceId ?? notification.panelId
) else {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
continue
}
workspace.acknowledgeStructuredAgentInputStatus(
statusKeys: [statusKey],
panelId: notification.surfaceId ?? notification.panelId,
notificationCreatedAt: notification.createdAt
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

private func workspaceForStructuredAgentInputAcknowledgement(
tabId: UUID,
surfaceId: UUID?
) -> Workspace? {
guard let appDelegate = AppDelegate.shared else { return nil }
if let surfaceId,
let located = appDelegate.workspaceContainingPanel(
panelId: surfaceId,
preferredWorkspaceId: tabId
) {
return located.workspace
}

let tabManager = appDelegate.tabManagerFor(tabId: tabId) ?? appDelegate.tabManager
return tabManager?.tabs.first(where: { $0.id == tabId })
}

func markRead(id: UUID) {
var updated = notifications
guard let index = updated.firstIndex(where: { $0.id == id }) else { return }
guard !updated[index].isRead else { return }
let notification = updated[index]
updated[index].isRead = true
notifications = updated
acknowledgeStructuredAgentInputStatuses(for: [notification])
center.removeDeliveredNotificationsOffMain(withIdentifiers: [id.uuidString])
}

func markRead(forTabId tabId: UUID) {
var updated = notifications
var idsToClear: [String] = []
var notificationsToAcknowledge: [TerminalNotification] = []
for index in updated.indices {
if updated[index].tabId == tabId && !updated[index].isRead {
notificationsToAcknowledge.append(updated[index])
updated[index].isRead = true
idsToClear.append(updated[index].id.uuidString)
}
Expand All @@ -1580,6 +1651,7 @@ final class TerminalNotificationStore: ObservableObject {
clearWorkspacePanelUnread(forTabId: tabId)
setPanelDerivedWorkspaceUnread(false, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
if !idsToClear.isEmpty {
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
}
Expand All @@ -1588,9 +1660,11 @@ final class TerminalNotificationStore: ObservableObject {
func markRead(forTabId tabId: UUID, surfaceId: UUID?) {
var updated = notifications
var idsToClear: [String] = []
var notificationsToAcknowledge: [TerminalNotification] = []
for index in updated.indices {
if updated[index].matches(tabId: tabId, surfaceId: surfaceId),
!updated[index].isRead {
notificationsToAcknowledge.append(updated[index])
updated[index].isRead = true
idsToClear.append(updated[index].id.uuidString)
}
Expand All @@ -1603,6 +1677,7 @@ final class TerminalNotificationStore: ObservableObject {
setPanelDerivedWorkspaceUnread(false, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
}
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
if !idsToClear.isEmpty {
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
center.removePendingNotificationRequestsOffMain(withIdentifiers: idsToClear)
Expand Down Expand Up @@ -1666,8 +1741,10 @@ final class TerminalNotificationStore: ObservableObject {
var updated = notifications
var idsToClear: [String] = []
var tabIdsToClearPanelUnread = panelDerivedUnreadWorkspaceIds
var notificationsToAcknowledge: [TerminalNotification] = []
for index in updated.indices {
if !updated[index].isRead {
notificationsToAcknowledge.append(updated[index])
tabIdsToClearPanelUnread.insert(updated[index].tabId)
updated[index].isRead = true
idsToClear.append(updated[index].id.uuidString)
Expand All @@ -1680,6 +1757,7 @@ final class TerminalNotificationStore: ObservableObject {
clearAllWorkspacePanelUnread(forTabIds: tabIdsToClearPanelUnread)
clearPanelDerivedWorkspaceUnread()
clearWorkspaceRestoredUnread()
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
if !idsToClear.isEmpty {
center.removeDeliveredNotificationsOffMain(withIdentifiers: idsToClear)
center.removePendingNotificationRequestsOffMain(withIdentifiers: idsToClear)
Expand Down Expand Up @@ -1727,6 +1805,7 @@ final class TerminalNotificationStore: ObservableObject {

func clearAll(discardQueuedNotifications: Bool = true) {
if discardQueuedNotifications { TerminalMutationBus.shared.discardPendingNotifications() }
let notificationsToAcknowledge = notifications
guard !notifications.isEmpty ||
!focusedReadIndicatorByTabId.isEmpty ||
!manualUnreadWorkspaceIds.isEmpty ||
Expand All @@ -1740,6 +1819,7 @@ final class TerminalNotificationStore: ObservableObject {
clearPanelDerivedWorkspaceUnread()
clearWorkspaceRestoredUnread()
focusedReadIndicatorByTabId.removeAll()
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
CmuxEventBus.shared.publishNotificationCleared(ids: ids, workspaceId: nil, surfaceId: nil)
center.removeDeliveredNotificationsOffMain(withIdentifiers: ids)
center.removePendingNotificationRequestsOffMain(withIdentifiers: ids)
Expand All @@ -1756,8 +1836,10 @@ final class TerminalNotificationStore: ObservableObject {
var updated: [TerminalNotification] = []
updated.reserveCapacity(notifications.count)
var idsToClear: [String] = []
var notificationsToAcknowledge: [TerminalNotification] = []
for notification in notifications {
if notification.matches(tabId: tabId, surfaceId: surfaceId) {
notificationsToAcknowledge.append(notification)
idsToClear.append(notification.id.uuidString)
} else {
updated.append(notification)
Expand All @@ -1770,6 +1852,7 @@ final class TerminalNotificationStore: ObservableObject {
if surfaceId == nil {
setWorkspaceRestoredUnread(false, forTabId: tabId)
}
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
clearFocusedReadIndicator(forTabId: tabId, surfaceId: surfaceId)
if !idsToClear.isEmpty {
CmuxEventBus.shared.publishNotificationCleared(ids: idsToClear, workspaceId: tabId, surfaceId: surfaceId)
Expand Down Expand Up @@ -1820,8 +1903,10 @@ final class TerminalNotificationStore: ObservableObject {
var updated: [TerminalNotification] = []
updated.reserveCapacity(notifications.count)
var idsToClear: [String] = []
var notificationsToAcknowledge: [TerminalNotification] = []
for notification in notifications {
if notification.tabId == tabId {
notificationsToAcknowledge.append(notification)
idsToClear.append(notification.id.uuidString)
} else {
updated.append(notification)
Expand All @@ -1831,6 +1916,7 @@ final class TerminalNotificationStore: ObservableObject {
clearWorkspacePanelUnread(forTabId: tabId)
setPanelDerivedWorkspaceUnread(false, forTabId: tabId)
setWorkspaceRestoredUnread(false, forTabId: tabId)
acknowledgeStructuredAgentInputStatuses(for: notificationsToAcknowledge)
guard !idsToClear.isEmpty || hadFocusedReadIndicator else { return }
if !idsToClear.isEmpty {
replaceNotificationsForClear(updated)
Expand Down
42 changes: 42 additions & 0 deletions Sources/Workspace+PanelLifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,48 @@ extension Workspace {
return Self.truthyStartupEnvironmentValues.contains(rawValue)
}

@discardableResult
func acknowledgeStructuredAgentInputStatus(
statusKeys acknowledgedStatusKeys: Set<String>,
panelId: UUID? = nil,
notificationCreatedAt: Date
) -> Bool {
let candidateStatusKeys: Set<String>
if let panelId {
let panelStatusKeys = Set((agentPIDKeysByPanelId[panelId] ?? []).map {
agentStatusKey(forAgentPIDKey: $0)
})
candidateStatusKeys = panelStatusKeys.intersection(acknowledgedStatusKeys)
} else {
candidateStatusKeys = acknowledgedStatusKeys
}

let idleValue = String(localized: "agent.generic.notification.status.idle", defaultValue: "Idle")
var didChange = false
for key in candidateStatusKeys where Self.structuredAgentHookStatusKeys.contains(key) {
guard let entry = statusEntries[key],
isStructuredAgentInputStatus(entry),
entry.timestamp <= notificationCreatedAt else {
continue
}
statusEntries[key] = SidebarStatusEntry(
key: key,
value: idleValue,
icon: "pause.circle.fill",
color: "#8E8E93"
)
didChange = true
}
return didChange
}
Comment thread
austinywang marked this conversation as resolved.
Resolved

private func isStructuredAgentInputStatus(_ entry: SidebarStatusEntry) -> Bool {
guard Self.structuredAgentHookStatusKeys.contains(entry.key) else {
return false
}
return entry.icon == "bell.fill"
}

func sidebarStatusEntriesVisibleForDisplay() -> [SidebarStatusEntry] {
Comment thread
austinywang marked this conversation as resolved.
Resolved
let visibleStructuredStatusKeys = visibleStructuredAgentStatusKeysByPanel()
return statusEntries.values.filter { entry in
Expand Down
Loading
Loading