mirror of
https://github.com/Louis-CFM/coucou.git
synced 2026-12-06 23:24:20 +09:00
- Live Activity: Mochi colored by state (working, thinking, waiting for your OK, done) as on Botan's screen, plain words instead of step counts, a see-through Lock Screen background. The iPhone keeps it up to date, shows "Done" a few seconds then ends it, ends it when nothing runs, and starts it itself when the app is open; one activity at a time. - Mac: starts it with the tokens it already has (no full iCloud read first), after 8 s instead of 20 when the Mac is unlocked. - Notifications: a notification service fills in the iCloud alert for an approval (agent, project, command), so one banner instead of two; the app's own banner only comes if the iCloud alert never does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B9uCpBfczfSCvLARne8hCd
39 lines
2.0 KiB
Swift
39 lines
2.0 KiB
Swift
import CloudKit
|
|
import Foundation
|
|
import UserNotifications
|
|
|
|
/// Fills in Botan's iCloud alert for an approval, so one banner says it all ("VS Code · portfo ·
|
|
/// Waiting for your OK: npm run build") instead of a plain alert followed by a second, detailed one.
|
|
/// The alert itself carries the agent (pill ID) and the fingerprint; the command and the project
|
|
/// come from the app, which the same push wakes (PendingApprovals). Waits a few seconds for them,
|
|
/// then shows what it has.
|
|
final class NotificationService: UNNotificationServiceExtension {
|
|
override func didReceive(_ request: UNNotificationRequest,
|
|
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
|
|
guard let content = request.content.mutableCopy() as? UNMutableNotificationContent else {
|
|
contentHandler(request.content)
|
|
return
|
|
}
|
|
let note = CKNotification(fromRemoteNotificationDictionary: request.content.userInfo) as? CKQueryNotification
|
|
guard let fingerprint = note?.recordFields?["fingerprint"] as? String, !fingerprint.isEmpty else {
|
|
contentHandler(content)
|
|
return
|
|
}
|
|
let pillId = note?.recordFields?["pillId"] as? String ?? ""
|
|
content.title = PillCatalog.definition(for: pillId)?.name ?? "An agent"
|
|
content.body = "Waiting for your OK"
|
|
content.userInfo["fingerprint"] = fingerprint
|
|
content.userInfo["pillId"] = pillId
|
|
// This runs on its own thread, with about 30 s to spare: waiting here is fine.
|
|
for _ in 0..<16 {
|
|
if let item = PendingApprovals.load()[fingerprint] {
|
|
content.title = item.project.isEmpty ? item.agent : "\(item.agent) · \(item.project)"
|
|
if !item.command.isEmpty { content.body = "Waiting for your OK: \(item.command.prefix(140))" }
|
|
break
|
|
}
|
|
Thread.sleep(forTimeInterval: 0.5)
|
|
}
|
|
contentHandler(content)
|
|
}
|
|
}
|