Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

iPhone approvals: say why a request is gone; clearer Mac logs; no "unknown" error

Claudec7c36c5071fc
diff --git a/NotchBuddy/Sources/App/ApprovalQueue.swift b/NotchBuddy/Sources/App/ApprovalQueue.swift
index e5c02353..66127fcd 100644
--- a/NotchBuddy/Sources/App/ApprovalQueue.swift
+++ b/NotchBuddy/Sources/App/ApprovalQueue.swift
@@ -21,6 +21,8 @@ struct QueuedApproval: Equatable, Sendable {
/// Host app / bundle id of the session, so the card's pill keeps showing where it runs.
var hostApp: String? = nil
var bundleId: String = ""
+ /// When the request arrived (for the log: how long it waited).
+ var received = Date()
}
struct ApprovalQueue: Sendable {
diff --git a/NotchBuddy/Sources/App/HookServer.swift b/NotchBuddy/Sources/App/HookServer.swift
index b27ed921..bd52a4ed 100644
--- a/NotchBuddy/Sources/App/HookServer.swift
+++ b/NotchBuddy/Sources/App/HookServer.swift
@@ -120,6 +120,8 @@ final class HookServer: @unchecked Sendable {
@MainActor
private func removeApproval(id: UUID, answer json: String? = nil, note: String? = nil) {
guard let entry = approvals.remove(id: id) else { return }
+ let age = Int(Date().timeIntervalSince(entry.received))
+ nbLog("Approval \(entry.tool) closed after \(age) s: \(json.map { _ in "answered from Coucou" } ?? note ?? "dropped")")
let source = approvalSources.removeValue(forKey: id)
if let json {
let fd = entry.fd
@@ -3818,8 +3820,14 @@ extension HookServer {
case "max_output_tokens": return String(localized: "The answer was too long and was cut.")
case "model_not_found": return String(localized: "This model is not available.")
default:
- // A readable error is shown as it is; a bare status code ("500") says nothing.
- return kind.count > 3 && Int(kind) == nil ? kind : nil
+ // Claude Code often sends only `error: "unknown"`: its last message then usually
+ // carries the API's own words ("API Error: 529 Overloaded…").
+ if let last = payload["last_assistant_message"] as? String,
+ last.range(of: "error", options: .caseInsensitive) != nil {
+ return DiffEngine.toOneLine(last)
+ }
+ // A readable error is shown as it is; "unknown" or a bare status code says nothing.
+ return kind.count > 3 && Int(kind) == nil && kind != "unknown" ? kind : nil
}
}
}
diff --git a/NotchBuddy/Sources/App/PhoneLink/ApprovalRelay.swift b/NotchBuddy/Sources/App/PhoneLink/ApprovalRelay.swift
index 7c49288e..4bf34591 100644
--- a/NotchBuddy/Sources/App/PhoneLink/ApprovalRelay.swift
+++ b/NotchBuddy/Sources/App/PhoneLink/ApprovalRelay.swift
@@ -123,6 +123,8 @@ final class ApprovalRelay {
changeToken = nil
return false
} catch {
+ // The request was settled on the Mac meanwhile: its poll is cancelled, not failed.
+ if Task.isCancelled || (error as? CKError)?.code == .operationCancelled { return true }
log("decision check failed: \(error.localizedDescription)")
return false
}
diff --git a/NotchBuddy/Sources/Phone/ApprovalCard.swift b/NotchBuddy/Sources/Phone/ApprovalCard.swift
index a7e8a53b..96aa4e59 100644
--- a/NotchBuddy/Sources/Phone/ApprovalCard.swift
+++ b/NotchBuddy/Sources/Phone/ApprovalCard.swift
@@ -84,9 +84,17 @@ struct ReviewSheet: View {
let link: PhoneLink
let fingerprint: String
@Environment(\.dismiss) private var dismiss
+ /// Set once the Mac's sessions were fetched again: until then, "already answered" may be wrong.
+ @State private var checked = false
private var session: SessionItem? { link.sessions.first { $0.approvalFingerprint == fingerprint } }
+ /// The Mac waits 115 s for an answer, then hands the request back to the agent.
+ private var expired: Bool {
+ guard let since = link.reviewSince else { return false }
+ return Date().timeIntervalSince(since) > 115
+ }
+
var body: some View {
NavigationStack {
ScrollView {
@@ -105,11 +113,23 @@ struct ReviewSheet: View {
}
}
ApprovalCard(link: link, session: session)
- } else {
- Text("This request was already answered or has expired.")
- .foregroundStyle(.secondary)
+ } else if !checked {
+ ProgressView("Checking with your Mac…")
.frame(maxWidth: .infinity)
.padding(40)
+ } else {
+ VStack(spacing: 8) {
+ Text(expired ? "This request expired." : "Already answered on your Mac.")
+ .font(.headline)
+ Text(expired
+ ? "Your Mac waits 2 minutes for an answer, then the agent asks again in its own window."
+ : "It was answered there (in the terminal or VS Code), or the command went ahead.")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ .multilineTextAlignment(.center)
+ }
+ .frame(maxWidth: .infinity)
+ .padding(40)
}
}
.padding(16)
@@ -121,6 +141,10 @@ struct ReviewSheet: View {
ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } }
}
.refreshable { await link.refresh() }
+ .task {
+ await link.refresh()
+ checked = true
+ }
}
}
}
diff --git a/NotchBuddy/Sources/Phone/CoucouPhoneApp.swift b/NotchBuddy/Sources/Phone/CoucouPhoneApp.swift
index 815e2379..efa2bda8 100644
--- a/NotchBuddy/Sources/Phone/CoucouPhoneApp.swift
+++ b/NotchBuddy/Sources/Phone/CoucouPhoneApp.swift
@@ -68,9 +68,10 @@ final class PhoneAppDelegate: NSObject, UIApplicationDelegate, UNUserNotificatio
let note = CKNotification(fromRemoteNotificationDictionary: userInfo) as? CKQueryNotification
let pillId = userInfo["pillId"] as? String ?? note?.recordFields?["pillId"] as? String ?? ""
+ let received = response.notification.date
if let fingerprint = PhoneLink.approvalFingerprint(in: request) {
Task { @MainActor in
- await Self.handleApproval(action: action, fingerprint: fingerprint, pillId: pillId)
+ await Self.handleApproval(action: action, fingerprint: fingerprint, pillId: pillId, received: received)
done()
}
return
@@ -98,7 +99,7 @@ final class PhoneAppDelegate: NSObject, UIApplicationDelegate, UNUserNotificatio
}
@MainActor
- private static func handleApproval(action: String, fingerprint: String, pillId: String) async {
+ private static func handleApproval(action: String, fingerprint: String, pillId: String, received: Date) async {
let link = PhoneLink.shared
link.noteICloudAlert(fingerprint)
switch action {
@@ -112,6 +113,7 @@ final class PhoneAppDelegate: NSObject, UIApplicationDelegate, UNUserNotificatio
_ = await link.allowFromOutside(fingerprint: fingerprint, pillId: pillId, from: "a notification")
default:
// Review, or a tap on the notification: open the command, Allow needs Face ID there.
+ link.reviewSince = received
link.reviewFingerprint = fingerprint
Task { await link.refresh() }
}
diff --git a/NotchBuddy/Sources/Phone/PhoneLink.swift b/NotchBuddy/Sources/Phone/PhoneLink.swift
index 2a0d8b34..f39fff42 100644
--- a/NotchBuddy/Sources/Phone/PhoneLink.swift
+++ b/NotchBuddy/Sources/Phone/PhoneLink.swift
@@ -504,6 +504,9 @@ final class PhoneLink {
/// Set when the user taps "Review" on an approval notification.
var reviewFingerprint: String?
+ /// When the notification of the request under review arrived: a request older than the
+ /// Mac's 2-minute wait has expired rather than been answered.
+ var reviewSince: Date?
/// Sends allow / deny for one exact request. The Mac applies it only if the
/// fingerprint still matches the request it is waiting on.