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.

Mochi at 30/60 fps with the same motion, calmer resting poll, no "too many hits" in voice, mails always written by Coucou

Claudebc2c733527ee
diff --git a/NotchBuddy/Sources/App/BotCanvasView.swift b/NotchBuddy/Sources/App/BotCanvasView.swift
index cbdc81ef..627ab8a8 100644
--- a/NotchBuddy/Sources/App/BotCanvasView.swift
+++ b/NotchBuddy/Sources/App/BotCanvasView.swift
@@ -16,11 +16,12 @@ struct BotCanvasView: View {
@StateObject private var engine = BotEngine()
var body: some View {
- TimelineView(.animation(paused: state.mode == .hidden || paused)) { timeline in
+ // 60 fps open, 30 fps in the small resting island: the engine still moves one
+ // 0.05 step per display frame (MochiFrameClock), so the motion is the same as at
+ // the display rate, with half to a quarter of the drawing.
+ TimelineView(.animation(minimumInterval: state.mode == .expanded ? 1.0 / 60.0 : 1.0 / 30.0,
+ paused: state.mode == .hidden || paused)) { _ in
Canvas { context, size in
- let now = timeline.date.timeIntervalSinceReferenceDate
- let dtRaw = min(0.05, now - engine.lastTime)
- let dt = dtRaw
let look = lookXY(state: state)
engine.lookX = look.x
engine.lookY = look.y
@@ -86,7 +87,7 @@ struct BotCanvasView: View {
}
#endif
- engine.update(dt: dt)
+ MochiFrameClock.advance(engine)
var ctx = context
engine.applyDance(&ctx, size: size)
// Rigid-roll: when Mochi wears an outfit (presence > 0.05) and is rolling,
@@ -193,6 +194,8 @@ struct BotCanvasView: View {
nw: state.notchWidth, nh: state.notchHeight)
let screen = IslandWindowController.islandScreen().frame
let desktopTop = IslandWindowController.desktopTop
+ // The pointer read now, not from the island poll (which slows down far from it).
+ let mouse = DesktopSpace.topDown(NSEvent.mouseLocation, desktopTop: desktopTop)
func botPoint(islandH: CGFloat) -> CGPoint {
let (botCx, botCy, _, _) = botPosition(mode: state.mode, view: state.view,
islandW: islandW, islandH: islandH,
@@ -207,8 +210,8 @@ struct BotCanvasView: View {
? min(300, 240 + CGFloat(state.chatHistory.count) * 40)
: islandH
let botY = actualH == islandH ? botX : botPoint(islandH: actualH)
- return (tanh((state.mousePosition.x - botX.x) / 260),
- -tanh((state.mousePosition.y - botY.y) / 200))
+ return (tanh((mouse.x - botX.x) / 260),
+ -tanh((mouse.y - botY.y) / 200))
}
}
@@ -231,17 +234,6 @@ struct MiniBotCanvasView: View {
@Environment(\.islandViewActive) private var viewActive
- /// The rate the mini Mochis used to be drawn at: the island screen's refresh rate,
- /// looked up at most every 2 s (the island can move to another display).
- @MainActor private static var fpsCache: (value: Double, at: CFTimeInterval) = (60, -10)
- @MainActor private static var displayFPS: Double {
- let now = CACurrentMediaTime()
- if now - fpsCache.at > 2 {
- let fps = IslandWindowController.islandScreen().maximumFramesPerSecond
- fpsCache = (Double(min(120, max(30, fps))), now)
- }
- return fpsCache.value
- }
var body: some View {
// A 12–20 pt Mochi: 30 fps looks the same as the display rate and costs a quarter
@@ -249,14 +241,7 @@ struct MiniBotCanvasView: View {
TimelineView(.animation(minimumInterval: 1.0 / 30.0, paused: !viewActive)) { _ in
Canvas { context, size in
engine.setDancing(isDancing)
- // The engine moves 0.05 per step, one step per display frame as before:
- // same motion, only fewer drawings.
- let elapsed = min(1.0 / 15.0, max(0, CACurrentMediaTime() - engine.lastTime))
- engine.stepDebt += elapsed * Self.displayFPS
- let steps = min(8, Int(engine.stepDebt))
- engine.stepDebt -= Double(steps)
- if steps == 0 { engine.lastTime = CACurrentMediaTime() }
- for _ in 0..<steps { engine.update(dt: 0.05) }
+ MochiFrameClock.advance(engine)
var ctx = context
engine.applyDance(&ctx, size: size)
engine.draw(context: ctx, size: size)
@@ -284,3 +269,32 @@ struct MiniBotCanvasView: View {
}
}
}
+
+// MARK: - Frame clock
+
+/// Mochi's engine has always moved one `update(dt: 0.05)` per display frame (its look,
+/// colour, springs and particles are tuned to that). Drawing slower than the display must
+/// not slow Mochi down: each drawn frame runs the steps of the display frames it skipped.
+@MainActor
+enum MochiFrameClock {
+ /// The island screen's refresh rate, looked up at most every 2 s.
+ private static var fpsCache: (value: Double, at: CFTimeInterval) = (60, -10)
+ static var displayFPS: Double {
+ let now = CACurrentMediaTime()
+ if now - fpsCache.at > 2 {
+ let fps = IslandWindowController.islandScreen().maximumFramesPerSecond
+ fpsCache = (Double(min(120, max(30, fps))), now)
+ }
+ return fpsCache.value
+ }
+
+ static func advance(_ engine: BotEngine) {
+ let now = CACurrentMediaTime()
+ let elapsed = min(1.0 / 15.0, max(0, now - engine.lastTime))
+ engine.stepDebt += elapsed * displayFPS
+ let steps = min(8, Int(engine.stepDebt))
+ engine.stepDebt -= Double(steps)
+ if steps == 0 { engine.lastTime = now }
+ for _ in 0..<steps { engine.update(dt: 0.05) }
+ }
+}
diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift
index 5a0e288b..19d2f4ed 100644
--- a/NotchBuddy/Sources/App/IslandWindowController.swift
+++ b/NotchBuddy/Sources/App/IslandWindowController.swift
@@ -401,7 +401,7 @@ final class IslandWindowController: NSWindowController {
}
/// Picks the polling rate for the next ticks (see startPolling).
- /// Three rates for a hidden island: 60 Hz close to the island itself, 20 Hz in the
+ /// Three rates for a hidden or resting island: 60 Hz close to the island itself, 20 Hz in the
/// wide band around the panel (a pointer flicked up still reaches the close zone
/// within one tick), 8 Hz elsewhere. Before, the whole band ran at 60 Hz, so a hidden
/// island polled at 60 Hz most of the time. Desktop Mochi has its own poll.
@@ -409,8 +409,11 @@ final class IslandWindowController: NSWindowController {
let island = islandRect.offsetBy(dx: panelFrame.minX, dy: panelFrame.minY)
let nearIsland = island.insetBy(dx: -200, dy: -160).contains(mouse)
let inBand = panelFrame.insetBy(dx: -120, dy: -120).contains(mouse)
- let busy = state.mode != .hidden || inAttachDrag || attachDragStart != nil
- || fsm.state != .hidden || nearIsland
+ // The resting (compact) island is treated like the hidden one: Mochi reads the
+ // pointer itself every frame, so only hover and clicks need this poll, and those
+ // only near the island. 60 Hz while open, dragging or close to it.
+ let busy = state.mode == .expanded || inAttachDrag || attachDragStart != nil
+ || fsm.state == .home || fsm.state == .coucou || fsm.state == .listening || nearIsland
let wanted = busy ? Self.fastPoll : inBand ? Self.nearPoll : Self.idlePoll
if wanted != pollInterval { startPolling(interval: wanted) }
}
@@ -1462,9 +1465,8 @@ extension IslandWindowController {
if runner.pendingQuestion != nil {
let result = await runner.handleAnswer(transcript, availablePills: pills)
VoiceTranscriptHistory.shared.record(transcript: transcript, note: result.message, origin: .answer)
- if result.outcome != .success {
- NotificationCenter.default.post(name: .botDizzy, object: nil)
- }
+ // A question back ("What's the subject?") is not a miss: no reaction.
+ if result.outcome == .failure { voiceMissReaction() }
VoiceCaptionManager.shared.setUserLine(transcript)
VoiceCaptionManager.shared.appendResponse(result.message)
AppState.shared.voiceResult = result
@@ -1508,9 +1510,7 @@ extension IslandWindowController {
outcome: anyFailure ? .failure : .success,
message: parts.joined(separator: " · ")
)
- if anyFailure {
- NotificationCenter.default.post(name: .botDizzy, object: nil)
- }
+ if anyFailure { voiceMissReaction() }
VoiceCaptionManager.shared.setUserLine(transcript)
VoiceCaptionManager.shared.appendResponse(combined.message)
AppState.shared.voiceResult = combined
@@ -1671,7 +1671,7 @@ extension IslandWindowController {
conversationContext.update(effectiveIntent)
consecutiveFailures = 0
case .failure:
- NotificationCenter.default.post(name: .botDizzy, object: nil)
+ voiceMissReaction()
if isInConversation { consecutiveFailures += 1 }
case .question:
break // Mochi will show listening after re-open
@@ -1718,7 +1718,7 @@ extension IslandWindowController {
if let emote = emote {
NotificationCenter.default.post(name: .triggerEmote, object: emote)
} else if result.outcome == .failure {
- NotificationCenter.default.post(name: .botDizzy, object: nil)
+ voiceMissReaction()
}
AppState.shared.voiceResult = result
expand(to: .voiceResult)
@@ -1805,6 +1805,13 @@ extension IslandWindowController {
}
}
+ /// A voice command that failed: a small "huh?" from Mochi. Not .botDizzy, which is the
+ /// slap reaction and opened the "Too many hits at once" card in the middle of a mail.
+ @MainActor
+ func voiceMissReaction() {
+ NotificationCenter.default.post(name: .triggerEmote, object: BotEmote.surprised)
+ }
+
/// Seconds to wait for the first word of a reply: longer while Coucou waits for a
/// file, since finding it in Finder and dragging it takes a moment.
@MainActor
diff --git a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
index c88a273a..0d6b9c89 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
@@ -524,11 +524,11 @@ final class VoiceActionRunner {
}
if m.body == nil {
if let what = m.instruction {
- m.body = await info.draftBody(to: m.recipient, about: what) ?? what
+ m.body = await info.draftBody(to: m.recipient, about: what) ?? VoiceQuery.simpleMail(from: what)
mail = m
} else {
- return askMail(.body, t("Qu'est-ce que je mets dans le message ? Je peux aussi l'écrire pour toi, dis-moi juste de quoi il parle.",
- "What should the message say? I can also write it for you, just tell me what it's about."))
+ return askMail(.body, t("Qu'est-ce que je lui dis ? Je l'écris pour toi.",
+ "What should the email say? I'll write it for you."))
}
}
if !mailAttachmentAsked {
diff --git a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
index 246d1d75..1aee9453 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
@@ -138,12 +138,16 @@ final class VoiceBrain {
#if canImport(FoundationModels)
if #available(macOS 26, *) {
guard SystemLanguageModel.default.availability == .available else { return nil }
- let fr = VoiceSettings.language == "fr"
+ // The mail is written in the language I used for it, whatever Coucou speaks.
+ let fr = VoiceQuery.looksFrench(instruction)
+ // An address is not a name to greet: a plain greeting then.
+ let name = recipient.contains("@") ? "" : recipient
let session = LanguageModelSession(instructions: fr
- ? "Tu écris des mails courts et naturels, sans objet ni signature, 2 à 4 phrases."
- : "You write short, natural emails without a subject line or signature, 2 to 4 sentences.")
- let prompt = fr ? "Écris le mail à \(recipient) : \(instruction)"
- : "Write the email to \(recipient): \(instruction)"
+ ? "Tu écris des mails courts et naturels à la place de l'utilisateur : une salutation, 1 à 3 phrases qui disent ce qu'il veut dire, sans rien inventer, sans objet ni signature. Réponds uniquement avec le texte du mail."
+ : "You write short, natural emails for the user: a greeting, 1 to 3 sentences saying what they want to say, inventing nothing, no subject line or signature. Reply with the email text only.")
+ let to = name.isEmpty ? "" : (fr ? " à \(name)" : " to \(name)")
+ let prompt = fr ? "Mail\(to). Ce que je veux dire : \(instruction)"
+ : "Email\(to). What I want to say: \(instruction)"
// Boxed like the conversation session: the timeout closure must be Sendable.
let box = SessionContainer(session: session, collector: IntentCollector())
do {
diff --git a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift b/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
index 4420e646..be3d2639 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
@@ -128,6 +128,11 @@ enum VoiceQuery {
"pour lui dire que", "pour lui dire", "pour dire que", "en disant que",
"en disant", "qui dit", "with the text", "body", "saying that", "saying",
"that says", "to say that", "to say", "telling"]
+ /// Markers after which the text is what the mail is about, for Coucou to write it
+ /// ("pour lui dire que l'image est prête"); the others dictate the exact text.
+ private static let instructionMarkers: Set<String> = ["pour lui dire que", "pour lui dire", "pour dire que",
+ "en disant que", "en disant", "saying that", "saying",
+ "to say that", "to say", "telling"]
static func mail(of raw: String) -> MailRequest? {
// 1. Subject and body are free text: cut them out of the raw string first.
@@ -142,7 +147,9 @@ enum VoiceQuery {
return cleanFreeText(String(raw[m.range.upperBound..<end]))
}
let subject = segment(subj, other: body)
- let bodyText = segment(body, other: subj)
+ let bodySegment = segment(body, other: subj)
+ let bodyIsInstruction = body.map { instructionMarkers.contains($0.marker) } ?? false
+ let bodyText = bodyIsInstruction ? nil : bodySegment
// 2. Verb, recipient, file and folder from the head.
let n = IntentParser.normalise(head).split(separator: " ").map(String.init)
@@ -155,7 +162,8 @@ enum VoiceQuery {
// No "à / to": a guided mail — Coucou asks who, the subject, the text, an attachment.
guard let to = n.lastIndex(where: { $0 == "a" || $0 == "to" }), to > v, to + 1 < n.count else {
guard isMail else { return nil }
- return MailRequest(recipient: "", file: nil, folder: nil, subject: subject, body: bodyText)
+ return MailRequest(recipient: "", file: nil, folder: nil, subject: subject, body: bodyText,
+ instruction: bodyIsInstruction ? bodySegment : nil)
}
let after = Array(r[(to + 1)...])
var recipientWords: [String] = []
@@ -204,8 +212,8 @@ enum VoiceQuery {
if !name.isEmpty { file = name } else if n[f] == "pdf" { file = "pdf" }
}
- var instruction: String? = nil
- if bodyText == nil {
+ var instruction: String? = bodyIsInstruction ? bodySegment : nil
+ if bodyText == nil && instruction == nil {
let extra = rest.joined(separator: " ").trimmingCharacters(in: .punctuationCharacters.union(.whitespaces))
if !extra.isEmpty { instruction = extra }
}
@@ -232,20 +240,57 @@ enum VoiceQuery {
.trimmingCharacters(in: CharacterSet(charactersIn: " .,;:!?\"«»“”"))
}
- /// The message text, or nil when it is a request to write it ("écris-lui que…", "write something nice").
+ /// One rule, always the same: Coucou writes the mail from what I say ("faut dire que
+ /// l'image est prête" → a short mail saying it). Only "mot pour mot / exactement /
+ /// word for word …" dictates the exact text.
static func bodyAnswer(_ raw: String) -> (body: String?, instruction: String?) {
- let n = IntentParser.normalise(raw)
- let draftLeads = ["ecris lui", "ecris", "redige", "redige lui", "dis lui", "write", "tell her", "tell him",
- "tell them", "say that", "fais un message", "fais lui", "make it", "draft"]
- if draftLeads.contains(where: { n.hasPrefix($0 + " ") || n == $0 }) || n.contains("pour lui dire") {
- let what = stripLead(raw, ["écris-lui un message pour lui dire", "écris-lui pour lui dire", "écris-lui que", "écris-lui",
- "écris un message pour lui dire", "écris que", "écris", "ecris", "rédige-lui", "rédige",
- "dis-lui que", "dis-lui", "write her that", "write him that", "write that", "write",
- "tell her that", "tell him that", "tell her", "tell him", "say that", "draft"])
- return (nil, what.isEmpty ? raw : what)
+ let literalLeads = ["mot pour mot", "texte exact", "le texte exact c'est", "écris exactement", "ecris exactement",
+ "exactement", "word for word", "verbatim", "exactly", "write exactly", "the exact text is"]
+ let literal = stripLead(raw, literalLeads)
+ if literal.count < raw.trimmingCharacters(in: .whitespacesAndNewlines).count {
+ return (literal.trimmingCharacters(in: CharacterSet(charactersIn: " :;\"«»“”")), nil)
}
- return (stripLead(raw, ["le message c'est", "le message", "message", "c'est", "the message is", "it says", "body"])
- .trimmingCharacters(in: CharacterSet(charactersIn: " :;\"«»“”")), nil)
+ let what = instructionText(raw)
+ return (nil, what.isEmpty ? raw : what)
+ }
+
+ /// What the mail should say, without the way I asked: "faut dire que l'image est prête",
+ /// "écris-lui que…", "tell her that…" → "l'image est prête" / "…".
+ static func instructionText(_ raw: String) -> String {
+ stripLead(raw, ["il faut lui dire que", "il faut dire que", "faut lui dire que", "faut dire que", "faut lui dire",
+ "faut dire", "il faut dire", "écris-lui un message pour lui dire que", "écris-lui un message pour lui dire",
+ "écris-lui pour lui dire que", "écris-lui pour lui dire", "écris-lui que", "écris-lui", "écris lui",
+ "écris un message pour lui dire que", "écris un message pour lui dire", "écris que", "écris", "ecris",
+ "rédige-lui", "rédige", "dis-lui que", "dis-lui", "dis lui que", "dis lui", "dites-lui que",
+ "pour lui dire que", "pour lui dire", "pour dire que", "dire que", "que", "préviens-la que",
+ "préviens-le que", "préviens-la", "préviens-le", "le message c'est", "le message", "c'est",
+ "write her that", "write him that", "write them that", "write that", "write", "tell her that",
+ "tell him that", "tell them that", "tell her", "tell him", "tell them", "say that", "say",
+ "let her know that", "let him know that", "let them know that", "draft", "the message is", "that"])
+ .trimmingCharacters(in: CharacterSet(charactersIn: " :;\"«»“”"))
+ }
+
+ /// The instruction reads as French (to write the mail in the same language).
+ static func looksFrench(_ s: String) -> Bool {
+ let words = IntentParser.normalise(s).split(separator: " ").map(String.init)
+ let fr: Set<String> = ["le", "la", "les", "l", "que", "qu", "est", "sont", "de", "des", "du", "pour", "je", "tu",
+ "il", "elle", "nous", "vous", "un", "une", "et", "a", "au", "avec", "pas", "prete", "pret",
+ "merci", "demain", "hier", "bien", "c", "ce", "sa", "son", "ton", "ta", "mon", "ma"]
+ let en: Set<String> = ["the", "is", "are", "that", "to", "of", "for", "i", "you", "he", "she", "we", "and",
+ "with", "not", "ready", "thanks", "thank", "tomorrow", "yesterday", "it", "my", "your"]
+ let f = words.filter { fr.contains($0) }.count
+ let e = words.filter { en.contains($0) }.count
+ return f > e
+ }
+
+ /// A plain mail from the instruction when no model can write it: "l'image est prête"
+ /// → "Bonjour,\n\nL'image est prête.\n\nBonne journée !"
+ static func simpleMail(from instruction: String) -> String {
+ var t = instructionText(instruction).trimmingCharacters(in: .whitespacesAndNewlines)
+ guard let first = t.first else { return instruction }
+ t = first.uppercased() + t.dropFirst()
+ if let last = t.last, !".!?".contains(last) { t += "." }
+ return looksFrench(instruction) ? "Bonjour,\n\n\(t)\n\nBonne journée !" : "Hi,\n\n\(t)\n\nBest,"
}
/// "oui, Goku.png" / "yes the file called invoice" → "Goku.png" / "invoice"; nil for "no".
diff --git a/tests/VoiceActionRunnerTests.swift b/tests/VoiceActionRunnerTests.swift
index 46c97312..b10d428e 100644
--- a/tests/VoiceActionRunnerTests.swift
+++ b/tests/VoiceActionRunnerTests.swift
@@ -244,7 +244,7 @@ enum VoiceActionRunnerTests {
r = await runner.handleAnswer("it's Tana", availablePills: pills)
check("mail asks subject", r.message.contains("subject"), true)
r = await runner.handleAnswer("the subject is Here is your image", availablePills: pills)
- check("mail asks text", r.message.contains("What should the message say"), true)
+ check("mail asks text", r.message.contains("What should the email say"), true)
r = await runner.handleAnswer("write her that the image is in 1980 by 1080", availablePills: pills)
check("mail asks attachment", r.message.contains("Any attachment"), true)
check("waiting for a drop", runner.isWaitingForAttachment, true)
diff --git a/tests/VoiceQueryTests.swift b/tests/VoiceQueryTests.swift
index daae978c..391a1f11 100644
--- a/tests/VoiceQueryTests.swift
+++ b/tests/VoiceQueryTests.swift
@@ -67,7 +67,17 @@ struct VoiceQueryTests {
check("recipient spoken email", VoiceQuery.recipientAnswer("tana arobase gmail point com"), "[email protected]")
check("subject answer", VoiceQuery.subjectAnswer("l'objet c'est Voilà votre image"), "Voilà votre image")
check("no subject", VoiceQuery.subjectAnswer("pas d'objet"), "")
- check("body verbatim", VoiceQuery.bodyAnswer("Image en 1980 par 1080").body, "Image en 1980 par 1080")
+ check("body verbatim only on request", VoiceQuery.bodyAnswer("mot pour mot : Image en 1980 par 1080").body, "Image en 1980 par 1080")
+ check("body plain answer is drafted", VoiceQuery.bodyAnswer("Image en 1980 par 1080").instruction, "Image en 1980 par 1080")
+ check("body faut dire que", VoiceQuery.bodyAnswer("Faut dire que l'image est prête").instruction, "l'image est prête")
+ check("body faut dire → no literal", VoiceQuery.bodyAnswer("Faut dire que l'image est prête").body, nil)
+ check("body tell her", VoiceQuery.bodyAnswer("tell her that the file is ready").instruction, "the file is ready")
+ check("simple mail fr", VoiceQuery.simpleMail(from: "faut dire que l'image est prête"), "Bonjour,\n\nL'image est prête.\n\nBonne journée !")
+ check("simple mail en", VoiceQuery.simpleMail(from: "the file is ready"), "Hi,\n\nThe file is ready.\n\nBest,")
+ check("looks French", VoiceQuery.looksFrench("l'image est prête"), true)
+ check("looks English", VoiceQuery.looksFrench("the image is ready"), false)
+ check("mail pour lui dire → drafted", VoiceQuery.mail(of: "envoie un mail à Tana pour lui dire que l'image est prête")?.instruction, "l'image est prête")
+ check("mail description → literal", VoiceQuery.mail(of: "envoie un mail à Tana avec le texte rendez-vous demain")?.body, "rendez-vous demain")
check("body draft", VoiceQuery.bodyAnswer("écris-lui que je serai en retard").instruction, "je serai en retard")
check("attachment name", VoiceQuery.attachmentAnswer("oui, Goku point png"), "Goku.png")
// Louis's example, as dictated