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 3: CoucouKit (shared Mochi, pills, diff, models) (#210)
Louisf4bfb499d852
diff --git a/CLAUDE.md b/CLAUDE.mdindex ea0bd65e..272aae75 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -3,8 +3,8 @@Coucou is a native macOS app (`NotchBuddy/`); `windows/` is the Tauri version for Windows and Linux. Mochi, a small animated character living in the MacBook notch, shows AI coding agent sessions (Claude Code, Gemini CLI, Antigravity and more) and a few integrations, and lets the user approve, answer, chat and drop files from the notch.## Where things are-- `NotchBuddy/Sources/App/` — all Swift code. `NotchBuddy/Resources/sounds/` — the 28 WAV sounds. `NotchBuddy/project.yml` — XcodeGen project (never edit the `.xcodeproj` by hand).-- `NotchBuddy/Sources/App/PillCatalog.swift` — single source of truth for all declared pills (workspace tools, agents, AI providers, services). Every pill ID, color, category and subtitle lives here.+- `NotchBuddy/Sources/App/` — Mac-only Swift code. `NotchBuddy/Sources/CoucouKit/` — code shared with the iPhone app (Mochi's BotEngine and outfits, pills, diff, models). `NotchBuddy/Sources/Phone/` — iPhone app (`CoucouPhone` target). `NotchBuddy/Resources/sounds/` — the 28 WAV sounds. `NotchBuddy/project.yml` — XcodeGen project (never edit the `.xcodeproj` by hand).+- `NotchBuddy/Sources/CoucouKit/PillCatalog.swift` — single source of truth for all declared pills (workspace tools, agents, AI providers, services). Every pill ID, color, category and subtitle lives here.- `docs/SPEC.md`, `docs/INTEGRATIONS.md` — behaviour, views, states, integrations (in French).- `design/prototype/notch-buddy.html` — original prototype, the visual source of truth. `design/captures/` — target screenshots.- `windows/` — the Tauri app for Windows and Linux: Rust in `src-tauri/`, TypeScript in `src/`, the `coucou-hook` relay in `hook/`. `windows/README.md` lists what differs from the Mac.diff --git a/NotchBuddy/Sources/App/BotCanvasView.swift b/NotchBuddy/Sources/App/BotCanvasView.swiftindex e80be390..38f5598e 100644--- a/NotchBuddy/Sources/App/BotCanvasView.swift+++ b/NotchBuddy/Sources/App/BotCanvasView.swift@@ -229,20 +229,3 @@ struct MiniBotCanvasView: View {}}}--// MARK: - CGColor from hex string--func cgColorFromHex(_ hex: String) -> CGColor? {- let h = hex.trimmingCharacters(in: CharacterSet(charactersIn: "#"))- guard let val = UInt64(h, radix: 16) else { return nil }- let r = CGFloat((val >> 16) & 0xFF) / 255- let g = CGFloat((val >> 8) & 0xFF) / 255- let b = CGFloat( val & 0xFF) / 255- return CGColor(red: r, green: g, blue: b, alpha: 1)-}--extension CGColor {- static func from(_ hex: String) -> CGColor {- cgColorFromHex(hex) ?? CGColor(gray: 0.5, alpha: 1)- }-}diff --git a/NotchBuddy/Sources/App/IslandRootView.swift b/NotchBuddy/Sources/App/IslandRootView.swiftindex 2d30e1ce..eb91f230 100644--- a/NotchBuddy/Sources/App/IslandRootView.swift+++ b/NotchBuddy/Sources/App/IslandRootView.swift@@ -629,16 +629,3 @@ struct CompactMiniGrid: View {.frame(width: 28, height: 28)}}--// MARK: - Color helper--extension Color {- init(hex: String) {- let h = hex.trimmingCharacters(in: CharacterSet(charactersIn: "#"))- let val = UInt64(h, radix: 16) ?? 0- let r = Double((val >> 16) & 0xFF) / 255- let g = Double((val >> 8) & 0xFF) / 255- let b = Double( val & 0xFF) / 255- self.init(red: r, green: g, blue: b)- }-}diff --git a/NotchBuddy/Sources/App/BotEngine.swift b/NotchBuddy/Sources/CoucouKit/BotEngine.swiftsimilarity index 99%rename from NotchBuddy/Sources/App/BotEngine.swiftrename to NotchBuddy/Sources/CoucouKit/BotEngine.swiftindex 81d16bde..0443ef9c 100644--- a/NotchBuddy/Sources/App/BotEngine.swift+++ b/NotchBuddy/Sources/CoucouKit/BotEngine.swift@@ -1,5 +1,6 @@import Foundationimport CoreGraphics+import QuartzCoreimport SwiftUI// MARK: - Easing functions (same as prototype: E.out, E.inOut, E.back, E.lin)diff --git a/NotchBuddy/Sources/CoucouKit/ColorHex.swift b/NotchBuddy/Sources/CoucouKit/ColorHex.swiftnew file mode 100644index 00000000..161a5aae--- /dev/null+++ b/NotchBuddy/Sources/CoucouKit/ColorHex.swift@@ -0,0 +1,43 @@+import SwiftUI+import CoreGraphics++// Hex color helpers shared by the Mac app and the iPhone app.++// MARK: - Color from hex string++extension Color {+ init(hex: String) {+ let h = hex.trimmingCharacters(in: CharacterSet(charactersIn: "#"))+ let val = UInt64(h, radix: 16) ?? 0+ let r = Double((val >> 16) & 0xFF) / 255+ let g = Double((val >> 8) & 0xFF) / 255+ let b = Double( val & 0xFF) / 255+ self.init(red: r, green: g, blue: b)+ }+}++// MARK: - CGColor from hex string++func cgColorFromHex(_ hex: String) -> CGColor? {+ let h = hex.trimmingCharacters(in: CharacterSet(charactersIn: "#"))+ guard let val = UInt64(h, radix: 16) else { return nil }+ let r = CGFloat((val >> 16) & 0xFF) / 255+ let g = CGFloat((val >> 8) & 0xFF) / 255+ let b = CGFloat( val & 0xFF) / 255+ return CGColor(red: r, green: g, blue: b, alpha: 1)+}++extension CGColor {+ static func from(_ hex: String) -> CGColor {+ cgColorFromHex(hex) ?? CGColor(gray: 0.5, alpha: 1)+ }+}++#if !os(macOS)+// CGColor.white / .black / .clear only exist on macOS; BotEngine uses them.+extension CGColor {+ static var white: CGColor { CGColor(gray: 1, alpha: 1) }+ static var black: CGColor { CGColor(gray: 0, alpha: 1) }+ static var clear: CGColor { CGColor(gray: 0, alpha: 0) }+}+#endifdiff --git a/NotchBuddy/Sources/App/DiffEngine.swift b/NotchBuddy/Sources/CoucouKit/DiffEngine.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/DiffEngine.swiftrename to NotchBuddy/Sources/CoucouKit/DiffEngine.swiftdiff --git a/NotchBuddy/Sources/App/IslandScreenGeometry.swift b/NotchBuddy/Sources/CoucouKit/IslandScreenGeometry.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/IslandScreenGeometry.swiftrename to NotchBuddy/Sources/CoucouKit/IslandScreenGeometry.swiftdiff --git a/NotchBuddy/Sources/App/IslandTypes.swift b/NotchBuddy/Sources/CoucouKit/IslandTypes.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/IslandTypes.swiftrename to NotchBuddy/Sources/CoucouKit/IslandTypes.swiftdiff --git a/NotchBuddy/Sources/App/MochiOutfitDrawing.swift b/NotchBuddy/Sources/CoucouKit/MochiOutfitDrawing.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/MochiOutfitDrawing.swiftrename to NotchBuddy/Sources/CoucouKit/MochiOutfitDrawing.swiftdiff --git a/NotchBuddy/Sources/CoucouKit/MochiStill.swift b/NotchBuddy/Sources/CoucouKit/MochiStill.swiftnew file mode 100644index 00000000..b31c6563--- /dev/null+++ b/NotchBuddy/Sources/CoucouKit/MochiStill.swift@@ -0,0 +1,35 @@+import SwiftUI++/// Mochi in a fixed pose: one frame of BotEngine, no animation, no timer.+/// For surfaces that can't animate (widgets, lists on the iPhone). The Mac+/// island keeps its animated BotCanvasView / MiniBotCanvasView.+struct MochiStill: View {+ var state: BotState = .idle+ /// Overrides the state's eyes (e.g. .closed for a sleeping agent).+ var eye: EyeShape? = nil+ /// Body color; white by default, like the mockups.+ var bodyHex: String = "#FFFFFF"+ var showBadge: Bool = true++ var body: some View {+ Canvas { context, size in+ let engine = BotEngine()+ engine.isMini = true+ engine.bodyColor = cgColorFromHex(bodyHex)+ engine.state = state+ engine.cfg = BotStates[state]!+ if let eye {+ engine.permanentEye = eye+ engine.eyeOverride = eye+ engine.eyeOverrideUntil = .greatestFiniteMagnitude+ }+ engine.draw(context: context, size: size)+ if showBadge, let badge = engine.cfg.badge {+ engine.badge = badge+ engine.badgeS = 1+ engine.drawHandsAndExtras(context: context, size: size)+ }+ }+ .aspectRatio(1, contentMode: .fit)+ }+}diff --git a/NotchBuddy/Sources/App/MochiWardrobe.swift b/NotchBuddy/Sources/CoucouKit/MochiWardrobe.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/MochiWardrobe.swiftrename to NotchBuddy/Sources/CoucouKit/MochiWardrobe.swiftdiff --git a/NotchBuddy/Sources/App/PillCatalog.swift b/NotchBuddy/Sources/CoucouKit/PillCatalog.swiftsimilarity index 100%rename from NotchBuddy/Sources/App/PillCatalog.swiftrename to NotchBuddy/Sources/CoucouKit/PillCatalog.swiftdiff --git a/NotchBuddy/Sources/Phone/KitPreviewView.swift b/NotchBuddy/Sources/Phone/KitPreviewView.swiftnew file mode 100644index 00000000..dada31de--- /dev/null+++ b/NotchBuddy/Sources/Phone/KitPreviewView.swift@@ -0,0 +1,93 @@+import SwiftUI++/// Step 3 check: CoucouKit (Mochi, pills, diff, models) drawn on the iPhone+/// with the Mac's own code.+struct KitPreviewView: View {+ private let poses: [(BotState, EyeShape?, String)] = [+ (.idle, nil, "idle"),+ (.working, nil, "working"),+ (.approval, nil, "approval"),+ (.question, nil, "question"),+ (.finished, .happy, "finished"),+ (.error, nil, "error"),+ (.sleeping, .closed, "sleeping"),+ (.thinking, nil, "thinking"),+ ]++ private let sampleDiff = DiffEngine.fromEdit(+ old: "func greet() {\n print(\"Hello\")\n}\n",+ new: "func greet(name: String) {\n print(\"Coucou \\(name)\")\n}\n",+ path: "/coucou/Greeting.swift")++ var body: some View {+ List {+ Section("Mochi — fixed poses") {+ LazyVGrid(columns: [GridItem(.adaptive(minimum: 72))], spacing: 12) {+ ForEach(Array(poses.enumerated()), id: \.offset) { index, pose in+ VStack(spacing: 4) {+ MochiStill(state: pose.0, eye: pose.1)+ .padding(6)+ .frame(width: 64, height: 64)+ .background(tileColor(index), in: RoundedRectangle(cornerRadius: 14))+ Text(pose.2).font(.caption2).foregroundStyle(.secondary)+ }+ }+ }+ .padding(.vertical, 6)+ }++ ForEach(PillCategory.allCases, id: \.self) { category in+ Section(category.title) {+ ForEach(PillCatalog.all.filter { $0.category == category }, id: \.id) { pill in+ HStack(spacing: 12) {+ MochiStill()+ .padding(3)+ .frame(width: 30, height: 30)+ .background(Color(hex: pill.color), in: RoundedRectangle(cornerRadius: 8))+ VStack(alignment: .leading) {+ Text(pill.name)+ Text(pill.id).font(.caption2.monospaced()).foregroundStyle(.secondary)+ }+ Spacer()+ Text(pill.subtitle).font(.caption).foregroundStyle(.secondary)+ }+ }+ }+ }++ Section("Diff — \(sampleDiff.name) +\(sampleDiff.added) −\(sampleDiff.removed)") {+ VStack(alignment: .leading, spacing: 0) {+ ForEach(Array(sampleDiff.hunks.flatMap(\.lines).enumerated()), id: \.offset) { _, line in+ Text(prefix(line.kind) + line.text)+ .font(.caption.monospaced())+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding(.horizontal, 6)+ .background(lineColor(line.kind))+ }+ }+ }+ }+ .navigationTitle("CoucouKit")+ }++ private func tileColor(_ index: Int) -> Color {+ let pills = PillCatalog.all+ return Color(hex: pills[index % pills.count].color)+ }++ private func prefix(_ kind: DiffLine.Kind) -> String {+ switch kind {+ case .added: "+ "+ case .removed: "− "+ case .context: " "+ }+ }++ private func lineColor(_ kind: DiffLine.Kind) -> Color {+ switch kind {+ case .added: .green.opacity(0.18)+ case .removed: .red.opacity(0.18)+ case .context: .clear+ }+ }+}diff --git a/NotchBuddy/Sources/Phone/LinkTestView.swift b/NotchBuddy/Sources/Phone/LinkTestView.swiftindex 5cfab38e..795d0601 100644--- a/NotchBuddy/Sources/Phone/LinkTestView.swift+++ b/NotchBuddy/Sources/Phone/LinkTestView.swift@@ -62,6 +62,9 @@ struct LinkTestView: View {}.navigationTitle("Coucou link test").refreshable { await link.refresh() }+ .toolbar {+ NavigationLink("Kit") { KitPreviewView() }+ }}}diff --git a/NotchBuddy/Sources/Phone/MacStubs.swift b/NotchBuddy/Sources/Phone/MacStubs.swiftnew file mode 100644index 00000000..94e01e43--- /dev/null+++ b/NotchBuddy/Sources/Phone/MacStubs.swift@@ -0,0 +1,15 @@+import Foundation++// Stand-ins for Mac-only pieces that CoucouKit's BotEngine calls.+// The Mac app has the real ones (SoundEngine.swift, IslandWindowController.swift).++/// Mochi is silent on the iPhone.+@MainActor+final class SoundEngine {+ static let shared = SoundEngine()+ func play(_ name: String) {}+}++extension Notification.Name {+ static let botDizzy = Notification.Name("notchBuddy.botDizzy")+}diff --git a/NotchBuddy/project.yml b/NotchBuddy/project.ymlindex 4f7eb58e..87f9b026 100644--- a/NotchBuddy/project.yml+++ b/NotchBuddy/project.yml@@ -204,6 +204,9 @@ targets:sources:- path: Sources/Phonetype: group+ # Shared with the Mac targets (they get it through Sources/).+ - path: Sources/CoucouKit+ type: groupinfo:path: Resources/InfoPhone.plistproperties:diff --git a/scripts/render-outfits.sh b/scripts/render-outfits.shindex 73d38496..88b704f7 100644--- a/scripts/render-outfits.sh+++ b/scripts/render-outfits.sh@@ -13,11 +13,11 @@ swiftc \-parse-as-library \-sdk "$SDK" \-target arm64-apple-macosx15.0 \- NotchBuddy/Sources/App/IslandScreenGeometry.swift \- NotchBuddy/Sources/App/IslandTypes.swift \- NotchBuddy/Sources/App/MochiWardrobe.swift \- NotchBuddy/Sources/App/BotEngine.swift \- NotchBuddy/Sources/App/MochiOutfitDrawing.swift \+ NotchBuddy/Sources/CoucouKit/IslandScreenGeometry.swift \+ NotchBuddy/Sources/CoucouKit/IslandTypes.swift \+ NotchBuddy/Sources/CoucouKit/MochiWardrobe.swift \+ NotchBuddy/Sources/CoucouKit/BotEngine.swift \+ NotchBuddy/Sources/CoucouKit/MochiOutfitDrawing.swift \scripts/RenderOutfits.swift \-framework AppKit \-framework SwiftUI \diff --git a/scripts/test-diff-engine.sh b/scripts/test-diff-engine.shindex e2493478..115a7dfa 100755--- a/scripts/test-diff-engine.sh+++ b/scripts/test-diff-engine.sh@@ -3,6 +3,6 @@ set -euo pipefailcd "$(dirname "$0")/.."TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/coucou-diff-engine.XXXXXX")"trap 'rm -rf "$TEST_DIR"' EXIT-swiftc NotchBuddy/Sources/App/DiffEngine.swift \+swiftc NotchBuddy/Sources/CoucouKit/DiffEngine.swift \tests/DiffEngineTests.swift -o "$TEST_DIR/diff-engine-tests""$TEST_DIR/diff-engine-tests"diff --git a/scripts/test-screen-geometry.sh b/scripts/test-screen-geometry.shindex 4b2b011c..71e0026d 100644--- a/scripts/test-screen-geometry.sh+++ b/scripts/test-screen-geometry.sh@@ -3,6 +3,6 @@ set -euo pipefailcd "$(dirname "$0")/.."TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/coucou-geometry.XXXXXX")"trap 'rm -rf "$TEST_DIR"' EXIT-swiftc NotchBuddy/Sources/App/IslandScreenGeometry.swift \+swiftc NotchBuddy/Sources/CoucouKit/IslandScreenGeometry.swift \tests/IslandScreenGeometryTests.swift -o "$TEST_DIR/geometry-tests""$TEST_DIR/geometry-tests"diff --git a/scripts/test-wardrobe.sh b/scripts/test-wardrobe.shindex d416186a..14b18546 100755--- a/scripts/test-wardrobe.sh+++ b/scripts/test-wardrobe.sh@@ -3,6 +3,6 @@ set -euo pipefailcd "$(dirname "$0")/.."TEST_DIR="$(mktemp -d "${TMPDIR:-/tmp}/coucou-wardrobe.XXXXXX")"trap 'rm -rf "$TEST_DIR"' EXIT-swiftc NotchBuddy/Sources/App/MochiWardrobe.swift \+swiftc NotchBuddy/Sources/CoucouKit/MochiWardrobe.swift \tests/MochiWardrobeTests.swift -o "$TEST_DIR/wardrobe-tests""$TEST_DIR/wardrobe-tests"