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.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
iPhone step 6: widgets (Solo, Team, List, Lock Screen) (#213)
Louis769c4f241f22
diff --git a/NotchBuddy/Resources/CoucouPhone.entitlements b/NotchBuddy/Resources/CoucouPhone.entitlementsindex e8455bbb..6c705131 100644--- a/NotchBuddy/Resources/CoucouPhone.entitlements+++ b/NotchBuddy/Resources/CoucouPhone.entitlements@@ -12,5 +12,9 @@<array><string>CloudKit</string></array>+ <key>com.apple.security.application-groups</key>+ <array>+ <string>group.fr.louisraille.Coucou</string>+ </array></dict></plist>diff --git a/NotchBuddy/Resources/CoucouPhoneProduction.entitlements b/NotchBuddy/Resources/CoucouPhoneProduction.entitlementsindex 85dee5e5..b40e7907 100644--- a/NotchBuddy/Resources/CoucouPhoneProduction.entitlements+++ b/NotchBuddy/Resources/CoucouPhoneProduction.entitlements@@ -14,5 +14,9 @@</array><key>com.apple.developer.icloud-container-environment</key><string>Production</string>+ <key>com.apple.security.application-groups</key>+ <array>+ <string>group.fr.louisraille.Coucou</string>+ </array></dict></plist>diff --git a/NotchBuddy/Resources/CoucouWidgets.entitlements b/NotchBuddy/Resources/CoucouWidgets.entitlementsnew file mode 100644index 00000000..e6893e80--- /dev/null+++ b/NotchBuddy/Resources/CoucouWidgets.entitlements@@ -0,0 +1,10 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>com.apple.security.application-groups</key>+ <array>+ <string>group.fr.louisraille.Coucou</string>+ </array>+</dict>+</plist>diff --git a/NotchBuddy/Resources/InfoWidgets.plist b/NotchBuddy/Resources/InfoWidgets.plistnew file mode 100644index 00000000..a3ae7e9e--- /dev/null+++ b/NotchBuddy/Resources/InfoWidgets.plist@@ -0,0 +1,29 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>CFBundleDevelopmentRegion</key>+ <string>$(DEVELOPMENT_LANGUAGE)</string>+ <key>CFBundleDisplayName</key>+ <string>Coucou</string>+ <key>CFBundleExecutable</key>+ <string>$(EXECUTABLE_NAME)</string>+ <key>CFBundleIdentifier</key>+ <string>fr.louisraille.Coucou.Widgets</string>+ <key>CFBundleInfoDictionaryVersion</key>+ <string>6.0</string>+ <key>CFBundleName</key>+ <string>CoucouWidgets</string>+ <key>CFBundlePackageType</key>+ <string>XPC!</string>+ <key>CFBundleShortVersionString</key>+ <string>0.1</string>+ <key>CFBundleVersion</key>+ <string>1</string>+ <key>NSExtension</key>+ <dict>+ <key>NSExtensionPointIdentifier</key>+ <string>com.apple.widgetkit-extension</string>+ </dict>+</dict>+</plist>diff --git a/NotchBuddy/Sources/CoucouKit/MochiStill.swift b/NotchBuddy/Sources/CoucouKit/MochiStill.swiftindex b31c6563..c6c53926 100644--- a/NotchBuddy/Sources/CoucouKit/MochiStill.swift+++ b/NotchBuddy/Sources/CoucouKit/MochiStill.swift@@ -33,3 +33,15 @@ struct MochiStill: View {.aspectRatio(1, contentMode: .fit)}}++extension Color {+ /// Background for a white Mochi on an agent's color. Very light colors+ /// (VS Code's is near-white) would hide him, so they get a dark gray tile.+ static func mochiTile(hex: String) -> Color {+ guard let c = cgColorFromHex(hex), let comps = c.components, comps.count >= 3 else {+ return Color(hex: hex)+ }+ let luminance = 0.2126 * comps[0] + 0.7152 * comps[1] + 0.0722 * comps[2]+ return luminance > 0.7 ? Color(white: 0.32) : Color(hex: hex)+ }+}diff --git a/NotchBuddy/Sources/Phone/HomeView.swift b/NotchBuddy/Sources/Phone/HomeView.swiftindex b0d24978..7bbed7c6 100644--- a/NotchBuddy/Sources/Phone/HomeView.swift+++ b/NotchBuddy/Sources/Phone/HomeView.swift@@ -106,7 +106,7 @@ struct SessionRow: View {MochiStill(state: session.state).padding(4).frame(width: 40, height: 40)- .background(Color(hex: session.color), in: RoundedRectangle(cornerRadius: 11))+ .background(Color.mochiTile(hex: session.color), in: RoundedRectangle(cornerRadius: 11))VStack(alignment: .leading, spacing: 2) {Text(session.title).font(.body.weight(.semibold))diff --git a/NotchBuddy/Sources/Phone/KitPreviewView.swift b/NotchBuddy/Sources/Phone/KitPreviewView.swiftindex dada31de..5dbc42be 100644--- a/NotchBuddy/Sources/Phone/KitPreviewView.swift+++ b/NotchBuddy/Sources/Phone/KitPreviewView.swift@@ -43,7 +43,7 @@ struct KitPreviewView: View {MochiStill().padding(3).frame(width: 30, height: 30)- .background(Color(hex: pill.color), in: RoundedRectangle(cornerRadius: 8))+ .background(Color.mochiTile(hex: pill.color), in: RoundedRectangle(cornerRadius: 8))VStack(alignment: .leading) {Text(pill.name)Text(pill.id).font(.caption2.monospaced()).foregroundStyle(.secondary)diff --git a/NotchBuddy/Sources/Phone/LinkTestView.swift b/NotchBuddy/Sources/Phone/LinkTestView.swiftindex 3ff0a208..79ad9742 100644--- a/NotchBuddy/Sources/Phone/LinkTestView.swift+++ b/NotchBuddy/Sources/Phone/LinkTestView.swift@@ -29,7 +29,7 @@ struct LinkTestView: View {MochiStill(state: session.state).padding(4).frame(width: 40, height: 40)- .background(Color(hex: session.color), in: RoundedRectangle(cornerRadius: 10))+ .background(Color.mochiTile(hex: session.color), in: RoundedRectangle(cornerRadius: 10))VStack(alignment: .leading, spacing: 2) {Text(session.name.isEmpty ? session.pillName : session.name)Text("\(session.pillName) · \(session.state.rawValue)" +diff --git a/NotchBuddy/Sources/Phone/PhoneLink.swift b/NotchBuddy/Sources/Phone/PhoneLink.swiftindex 2b8fa002..93bbe09e 100644--- a/NotchBuddy/Sources/Phone/PhoneLink.swift+++ b/NotchBuddy/Sources/Phone/PhoneLink.swift@@ -2,6 +2,7 @@ import CloudKitimport Observationimport UIKitimport UserNotifications+import WidgetKit/// A Ping written by the Mac, as seen by the iPhone.struct PingItem: Identifiable {@@ -149,6 +150,7 @@ final class PhoneLink {}firstFetchDone = truestatus = .ready+ if gotNew { updateWidgets() }} catch let error as CKError where error.code == .zoneNotFound || error.code == .userDeletedZone {status = .zoneMissing} catch let error as CKError where error.code == .changeTokenExpired {@@ -183,6 +185,12 @@ final class PhoneLink {return true}+ /// Hands the sessions to the widgets and asks them to redraw.+ private func updateWidgets() {+ SharedSessions.save(sessions.map(\.shared))+ WidgetCenter.shared.reloadAllTimelines()+ }+/// Writes a Pong linked to the latest Ping.func sendPong() async {guard let ping = pings.first else { return }diff --git a/NotchBuddy/Sources/Phone/SessionDetailView.swift b/NotchBuddy/Sources/Phone/SessionDetailView.swiftindex 3eeaf076..bd740d57 100644--- a/NotchBuddy/Sources/Phone/SessionDetailView.swift+++ b/NotchBuddy/Sources/Phone/SessionDetailView.swift@@ -56,7 +56,7 @@ struct SessionDetailView: View {MochiStill(state: session.state).padding(10).frame(width: 84, height: 84)- .background(Color(hex: session.color), in: RoundedRectangle(cornerRadius: 22))+ .background(Color.mochiTile(hex: session.color), in: RoundedRectangle(cornerRadius: 22))VStack(alignment: .leading, spacing: 4) {Text("\(session.pillName) · \(session.title)").font(.headline)diff --git a/NotchBuddy/Sources/Phone/SessionStatus.swift b/NotchBuddy/Sources/Phone/SessionStatus.swiftindex 479d360b..4abeb9c2 100644--- a/NotchBuddy/Sources/Phone/SessionStatus.swift+++ b/NotchBuddy/Sources/Phone/SessionStatus.swift@@ -45,6 +45,25 @@ extension SessionItem {}var title: String { name.isEmpty ? pillName : name }++ var tone: SharedSession.Tone {+ switch urgency {+ case 0: .waiting+ case 1: .question+ case 2: .error+ case 3: .working+ case 4: .done+ default: .idle+ }+ }++ /// What the widgets get (SharedSessions).+ var shared: SharedSession {+ SharedSession(id: id, title: title, agent: pillName, color: color, state: state.rawValue,+ statusText: statusText, tone: tone, urgency: urgency,+ stepIndex: stepIndex, stepCount: steps.count,+ currentStep: currentStep ?? "", updatedAt: updatedAt)+ }}extension Array where Element == SessionItem {diff --git a/NotchBuddy/Sources/Phone/SharedSessions.swift b/NotchBuddy/Sources/Phone/SharedSessions.swiftnew file mode 100644index 00000000..00c84bbd--- /dev/null+++ b/NotchBuddy/Sources/Phone/SharedSessions.swift@@ -0,0 +1,60 @@+import Foundation++// The sessions the iPhone app hands to its widgets, through the App Group+// container. Compiled into both the app and the CoucouWidgets extension.++struct SharedSession: Codable, Identifiable, Hashable, Sendable {+ let id: String // pill ID+ let title: String // project name, or the agent's name+ let agent: String // "VS Code", "Codex"…+ let color: String // agent color, hex+ let state: String // BotState raw value+ let statusText: String // "working · 3/7", "waiting for your OK"…+ let tone: Tone+ let urgency: Int // lower = more urgent+ let stepIndex: Int+ let stepCount: Int+ let currentStep: String+ let updatedAt: Date++ enum Tone: String, Codable, Sendable {+ case waiting, question, error, working, done, idle+ }++ var isWaitingForYou: Bool { tone == .waiting || tone == .question }+ var isWorking: Bool { tone == .working }+}++enum SharedSessions {+ static let appGroup = "group.fr.louisraille.Coucou"++ private static var fileURL: URL? {+ FileManager.default+ .containerURL(forSecurityApplicationGroupIdentifier: appGroup)?+ .appendingPathComponent("sessions.json")+ }++ static func save(_ sessions: [SharedSession]) {+ guard let url = fileURL, let data = try? JSONEncoder().encode(sessions) else { return }+ try? data.write(to: url, options: .atomic)+ }++ /// Most urgent first.+ static func load() -> [SharedSession] {+ guard let url = fileURL, let data = try? Data(contentsOf: url),+ let sessions = try? JSONDecoder().decode([SharedSession].self, from: data) else { return [] }+ return sessions.sorted { ($0.urgency, $1.updatedAt) < ($1.urgency, $0.updatedAt) }+ }+}++extension Array where Element == SharedSession {+ /// "2 working · 1 waiting", or nil when nothing is going on.+ var summary: String? {+ let waiting = filter(\.isWaitingForYou).count+ let working = filter(\.isWorking).count+ var parts: [String] = []+ if working > 0 { parts.append("\(working) working") }+ if waiting > 0 { parts.append("\(waiting) waiting") }+ return parts.isEmpty ? nil : parts.joined(separator: " · ")+ }+}diff --git a/NotchBuddy/Sources/Widgets/CoucouWidgets.swift b/NotchBuddy/Sources/Widgets/CoucouWidgets.swiftnew file mode 100644index 00000000..7280abfa--- /dev/null+++ b/NotchBuddy/Sources/Widgets/CoucouWidgets.swift@@ -0,0 +1,268 @@+import SwiftUI+import WidgetKit++// Coucou widgets: Solo, Team and List on the Home Screen, plus the Lock+// Screen accessories. They show the sessions the iPhone app last saved to the+// App Group; the app reloads them whenever a session changes.++@main+struct CoucouWidgetBundle: WidgetBundle {+ var body: some Widget {+ SoloWidget()+ TeamWidget()+ ListWidget()+ LockScreenWidget()+ }+}++// MARK: - Timeline++struct SessionsEntry: TimelineEntry {+ let date: Date+ let sessions: [SharedSession] // most urgent first+}++struct SessionsProvider: TimelineProvider {+ func placeholder(in context: Context) -> SessionsEntry {+ SessionsEntry(date: .now, sessions: SharedSession.samples)+ }++ func getSnapshot(in context: Context, completion: @escaping (SessionsEntry) -> Void) {+ let saved = SharedSessions.load()+ completion(SessionsEntry(date: .now, sessions: context.isPreview && saved.isEmpty ? SharedSession.samples : saved))+ }++ func getTimeline(in context: Context, completion: @escaping (Timeline<SessionsEntry>) -> Void) {+ // No polling: the app calls WidgetCenter.reloadAllTimelines() on every change.+ completion(Timeline(entries: [SessionsEntry(date: .now, sessions: SharedSessions.load())], policy: .never))+ }+}++// MARK: - Widgets++struct SoloWidget: Widget {+ var body: some WidgetConfiguration {+ StaticConfiguration(kind: "CoucouSolo", provider: SessionsProvider()) { entry in+ SoloView(session: entry.sessions.first)+ }+ .configurationDisplayName("Solo")+ .description("Your most urgent agent session.")+ .supportedFamilies([.systemSmall])+ }+}++struct TeamWidget: Widget {+ var body: some WidgetConfiguration {+ StaticConfiguration(kind: "CoucouTeam", provider: SessionsProvider()) { entry in+ TeamView(sessions: Array(entry.sessions.prefix(4)))+ }+ .configurationDisplayName("Team")+ .description("Up to four agents at a glance.")+ .supportedFamilies([.systemSmall])+ }+}++struct ListWidget: Widget {+ var body: some WidgetConfiguration {+ StaticConfiguration(kind: "CoucouList", provider: SessionsProvider()) { entry in+ ListView(sessions: Array(entry.sessions.prefix(4)))+ }+ .configurationDisplayName("List")+ .description("Your agent sessions and what they are doing.")+ .supportedFamilies([.systemMedium])+ }+}++struct LockScreenWidget: Widget {+ var body: some WidgetConfiguration {+ StaticConfiguration(kind: "CoucouLock", provider: SessionsProvider()) { entry in+ LockScreenView(sessions: entry.sessions)+ }+ .configurationDisplayName("Coucou")+ .description("Mochi on your Lock Screen.")+ .supportedFamilies([.accessoryCircular, .accessoryRectangular, .accessoryInline])+ }+}++// MARK: - Views++extension SharedSession {+ var botState: BotState { BotState(rawValue: state) ?? .idle }++ var toneColor: Color {+ switch tone {+ case .waiting: .orange+ case .question: .cyan+ case .error: .red+ case .done: .green+ case .working, .idle: .white.opacity(0.7)+ }+ }+}++extension Array where Element == SharedSession {+ var leadState: BotState {+ guard let lead = first else { return .sleeping }+ switch lead.tone {+ case .waiting: return .approval+ case .question: return .question+ default: return lead.botState+ }+ }+}++struct SoloView: View {+ let session: SharedSession?++ var body: some View {+ VStack(alignment: .leading, spacing: 4) {+ MochiStill(state: session?.botState ?? .sleeping)+ .frame(width: 56, height: 56)+ Spacer(minLength: 0)+ if let session {+ Text(session.title)+ .font(.headline)+ .lineLimit(1)+ Text(session.currentStep.isEmpty ? session.agent : session.currentStep)+ .font(.caption)+ .lineLimit(2)+ .opacity(0.85)+ HStack(spacing: 4) {+ Text(session.statusText).foregroundStyle(session.toneColor)+ Text("·")+ Text(session.updatedAt, style: .relative)+ }+ .font(.caption2)+ .lineLimit(1)+ .opacity(0.8)+ } else {+ Text("All quiet").font(.headline)+ Text("No agent session").font(.caption).opacity(0.7)+ }+ }+ .foregroundStyle(.white)+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)+ .containerBackground(for: .widget) {+ LinearGradient(colors: [Color(hex: session?.color ?? "#3B4A6B").opacity(0.55), Color(white: 0.08)],+ startPoint: .topLeading, endPoint: .bottomTrailing)+ }+ }+}++struct TeamView: View {+ let sessions: [SharedSession]++ var body: some View {+ Grid(horizontalSpacing: 8, verticalSpacing: 8) {+ GridRow { tile(0); tile(1) }+ GridRow { tile(2); tile(3) }+ }+ .containerBackground(for: .widget) { Color(white: 0.08) }+ }++ @ViewBuilder private func tile(_ index: Int) -> some View {+ if sessions.indices.contains(index) {+ let session = sessions[index]+ MochiStill(state: session.botState)+ .padding(8)+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .background(Color.mochiTile(hex: session.color), in: RoundedRectangle(cornerRadius: 16))+ } else {+ RoundedRectangle(cornerRadius: 16)+ .fill(Color.white.opacity(0.06))+ }+ }+}++struct ListView: View {+ let sessions: [SharedSession]++ var body: some View {+ VStack(alignment: .leading, spacing: 6) {+ if sessions.isEmpty {+ HStack(spacing: 10) {+ MochiStill(state: .sleeping).frame(width: 34, height: 34)+ Text("All quiet: no agent session").font(.subheadline).opacity(0.7)+ }+ .frame(maxHeight: .infinity)+ }+ ForEach(sessions) { session in+ HStack(spacing: 8) {+ MochiStill(state: session.botState)+ .padding(2)+ .frame(width: 24, height: 24)+ .background(Color.mochiTile(hex: session.color), in: RoundedRectangle(cornerRadius: 7))+ Text(session.title)+ .font(.subheadline.weight(.semibold))+ .lineLimit(1)+ Text(session.agent)+ .font(.caption)+ .opacity(0.6)+ .lineLimit(1)+ Spacer(minLength: 4)+ Text(session.statusText)+ .font(.caption.weight(session.isWaitingForYou ? .semibold : .regular))+ .foregroundStyle(session.toneColor)+ .lineLimit(1)+ }+ }+ Spacer(minLength: 0)+ }+ .foregroundStyle(.white)+ .containerBackground(for: .widget) { Color(white: 0.08) }+ }+}++struct LockScreenView: View {+ @Environment(\.widgetFamily) private var family+ let sessions: [SharedSession]++ var body: some View {+ switch family {+ case .accessoryCircular:+ ZStack {+ AccessoryWidgetBackground()+ MochiStill(state: sessions.leadState).padding(6)+ }+ .containerBackground(for: .widget) { Color.clear }+ case .accessoryRectangular:+ HStack(spacing: 6) {+ MochiStill(state: sessions.leadState).frame(width: 30, height: 30)+ VStack(alignment: .leading, spacing: 0) {+ Text(sessions.summary ?? "All quiet")+ .font(.headline)+ .lineLimit(1)+ if let lead = sessions.first {+ Text("\(lead.title) · \(lead.statusText)")+ .font(.caption)+ .lineLimit(2)+ }+ }+ Spacer(minLength: 0)+ }+ .containerBackground(for: .widget) { Color.clear }+ default:+ Text(sessions.summary.map { "Coucou · \($0)" } ?? "Coucou · all quiet")+ .containerBackground(for: .widget) { Color.clear }+ }+ }+}++// MARK: - Samples (widget gallery)++extension SharedSession {+ static let samples: [SharedSession] = [+ SharedSession(id: "integration_claude", title: "coucou", agent: "VS Code", color: "#4A86E8",+ state: "approval", statusText: "waiting for your OK", tone: .waiting, urgency: 0,+ stepIndex: 2, stepCount: 7, currentStep: "npm run test", updatedAt: .now),+ SharedSession(id: "agent_codex", title: "site-perso", agent: "Codex", color: "#D9663A",+ state: "working", statusText: "working · 3/7", tone: .working, urgency: 3,+ stepIndex: 2, stepCount: 7, currentStep: "Edit index.html", updatedAt: .now),+ SharedSession(id: "agent_gemini", title: "api-factures", agent: "Gemini CLI", color: "#4CA63A",+ state: "finished", statusText: "✓ done", tone: .done, urgency: 4,+ stepIndex: 4, stepCount: 4, currentStep: "", updatedAt: .now),+ SharedSession(id: "agent_cursor", title: "notes", agent: "Cursor", color: "#4FA37E",+ state: "sleeping", statusText: "asleep", tone: .idle, urgency: 5,+ stepIndex: 0, stepCount: 0, currentStep: "", updatedAt: .now),+ ]+}diff --git a/NotchBuddy/project.yml b/NotchBuddy/project.ymlindex d8b7fc8a..84bd8555 100644--- a/NotchBuddy/project.yml+++ b/NotchBuddy/project.yml@@ -112,6 +112,7 @@ targets:type: groupexcludes:- "Phone/**"+ - "Widgets/**"- path: Assets.xcassetsbuildPhase: resources- path: Resources/sounds@@ -164,6 +165,7 @@ targets:type: groupexcludes:- "Phone/**"+ - "Widgets/**"- path: Assets.xcassetsbuildPhase: resources- path: Resources/sounds@@ -213,6 +215,8 @@ targets:type: applicationplatform: iOSdeploymentTarget: "18.0"+ dependencies:+ - target: CoucouWidgetssources:- path: Sources/Phonetype: group@@ -255,3 +259,46 @@ targets:configs:DebugCloud:CODE_SIGN_ENTITLEMENTS: Resources/CoucouPhoneProduction.entitlements++ # Home Screen and Lock Screen widgets (Solo, Team, List, accessories). They+ # read the sessions the iPhone app saves to the shared App Group.+ CoucouWidgets:+ type: app-extension+ platform: iOS+ deploymentTarget: "18.0"+ sources:+ - path: Sources/Widgets+ type: group+ - path: Sources/CoucouKit+ type: group+ - path: Sources/Phone/SharedSessions.swift+ - path: Sources/Phone/MacStubs.swift+ info:+ path: Resources/InfoWidgets.plist+ properties:+ CFBundleName: CoucouWidgets+ CFBundleDisplayName: Coucou+ CFBundleIdentifier: fr.louisraille.Coucou.Widgets+ CFBundleVersion: "1"+ CFBundleShortVersionString: "0.1"+ CFBundlePackageType: XPC!+ NSExtension:+ NSExtensionPointIdentifier: com.apple.widgetkit-extension+ settings:+ base:+ PRODUCT_BUNDLE_IDENTIFIER: fr.louisraille.Coucou.Widgets+ PRODUCT_NAME: CoucouWidgets+ INFOPLIST_FILE: Resources/InfoWidgets.plist+ IPHONEOS_DEPLOYMENT_TARGET: "18.0"+ TARGETED_DEVICE_FAMILY: "1"+ SUPPORTS_MACCATALYST: NO+ CODE_SIGN_STYLE: Automatic+ CODE_SIGN_IDENTITY: "Apple Development"+ CODE_SIGN_ENTITLEMENTS: Resources/CoucouWidgets.entitlements+ DEVELOPMENT_TEAM: 256AUJ9555+ CODE_SIGNING_REQUIRED: YES+ CODE_SIGNING_ALLOWED: YES+ ENABLE_HARDENED_RUNTIME: NO+ OTHER_CODE_SIGN_FLAGS: ""+ SKIP_INSTALL: YES+ APPLICATION_EXTENSION_API_ONLY: YES