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.

review/voice-phase1 round 3: home-collapse timer + original-text command

Louis Raille498f18f39f2b
diff --git a/NotchBuddy/Sources/App/IslandStateMachine.swift b/NotchBuddy/Sources/App/IslandStateMachine.swift
index 1cd32777..c54e87a8 100644
--- a/NotchBuddy/Sources/App/IslandStateMachine.swift
+++ b/NotchBuddy/Sources/App/IslandStateMachine.swift
@@ -160,7 +160,9 @@ final class IslandStateMachine {
/// Command session ended (silence timeout, cancel phrase, or user dismiss).
func voiceFinished() {
guard state == .listening else { return }
- transition(to: stateBeforeListening == .home ? .home : .petit)
+ let target: State = stateBeforeListening == .home ? .home : .petit
+ transition(to: target)
+ if target == .home, isHeldOpen?() != true { scheduleHomeCollapse() }
}
/// Greeting animation finished (called at T.end ≈ 4.60 s).
diff --git a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
index 07d9c15b..231cf02f 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
@@ -220,7 +220,7 @@ final class VoiceEngine: ObservableObject {
resetSilenceTimer()
// Cancel only when the ENTIRE command is a cancel phrase (not a substring).
let trimmed = command.trimmingCharacters(in: .whitespaces)
- if Self.cancelPhrases.contains(trimmed) {
+ if Self.cancelPhrases.contains(WakePhrase.normalise(trimmed)) {
endCommand(postFinished: true)
}
}
diff --git a/NotchBuddy/Sources/App/Voice/WakePhrase.swift b/NotchBuddy/Sources/App/Voice/WakePhrase.swift
index fb1c50f5..1108c323 100644
--- a/NotchBuddy/Sources/App/Voice/WakePhrase.swift
+++ b/NotchBuddy/Sources/App/Voice/WakePhrase.swift
@@ -10,11 +10,15 @@ enum WakePhrase {
struct SplitResult {
let matched: Bool
- let command: String // words after the LAST wake phrase occurrence (lowercased, normalised)
+ /// Words after the LAST wake phrase occurrence, extracted from the **original** transcript
+ /// (original casing, apostrophes, hyphens, accents preserved).
+ /// Leading punctuation on the first word is stripped.
+ let command: String
}
/// Scans `raw` for a wake phrase at a word boundary (anywhere in the transcript,
- /// not just the start). Returns the text following the **last** occurrence as the command.
+ /// not just the start). Returns the text following the **last** occurrence as the command,
+ /// preserving the original casing and punctuation of the command portion.
///
/// Accepted patterns (case-insensitive, after phonetic normalisation):
/// - "ok coucou" and variants: "okay coucou", "ok cuckoo", "ok kuku", "ok cou cou" …
@@ -23,23 +27,30 @@ enum WakePhrase {
/// Word-boundary search means "euh ok coucou add" matches and returns "add".
/// Standalone "coucou" never matches (no preceding "ok"/"hey").
static func split(_ raw: String) -> SplitResult {
- // 1. Strip punctuation, lowercase, normalise phonetic variants
- let normalised = normalise(raw)
+ // Split original into whitespace-separated tokens (punctuation stays attached to words)
+ let originalWords = raw.components(separatedBy: .whitespaces).filter { !$0.isEmpty }
+ guard !originalWords.isEmpty else { return SplitResult(matched: false, command: "") }
- // 2. Split into words
- let words = normalised.split(separator: " ", omittingEmptySubsequences: true).map(String.init)
- guard !words.isEmpty else { return SplitResult(matched: false, command: "") }
+ // Normalise each word independently for wake-phrase matching only
+ let normWords = originalWords.map(normWord)
- // 3. Wake phrase word-arrays
- let patterns: [[String]] = [["ok", "coucou"], ["hey", "coucou"]]
+ // Wake phrase patterns (normalised).
+ // "ok cou cou" handled as a 3-token pattern in case the STT splits it.
+ let patterns: [[String]] = [
+ ["ok", "coucou"],
+ ["ok", "cou", "cou"],
+ ["hey", "coucou"],
+ ["hey", "cou", "cou"],
+ ]
- // 4. Find LAST occurrence of any pattern
+ // Find LAST occurrence of any pattern
var lastMatchEnd: Int? = nil // word index immediately after the matched pattern
for pattern in patterns {
+ guard normWords.count >= pattern.count else { continue }
var i = 0
- while i <= words.count - pattern.count {
- if Array(words[i ..< i + pattern.count]) == pattern {
+ while i <= normWords.count - pattern.count {
+ if Array(normWords[i ..< i + pattern.count]) == pattern {
let end = i + pattern.count
if lastMatchEnd == nil || end > lastMatchEnd! { lastMatchEnd = end }
i = end // resume search after this match
@@ -51,26 +62,35 @@ enum WakePhrase {
guard let end = lastMatchEnd else { return SplitResult(matched: false, command: "") }
- let commandWords = Array(words[end...])
- return SplitResult(matched: true, command: commandWords.joined(separator: " "))
+ let tail = Array(originalWords[end...])
+ guard !tail.isEmpty else { return SplitResult(matched: true, command: "") }
+
+ // Strip leading punctuation from the first command word
+ var first = tail[0]
+ while let c = first.first, !c.isLetter && !c.isNumber { first = String(first.dropFirst()) }
+
+ let parts = ([first] + Array(tail.dropFirst())).filter { !$0.isEmpty }
+ return SplitResult(matched: true, command: parts.joined(separator: " "))
+ }
+
+ /// Normalise a string for cancel-phrase comparison: lowercase + strip punctuation.
+ static func normalise(_ s: String) -> String {
+ s.lowercased()
+ .components(separatedBy: .punctuationCharacters)
+ .joined()
+ .trimmingCharacters(in: .whitespaces)
}
- // MARK: - Internal
+ // MARK: - Private
- /// Lowercase, strip punctuation, normalise phonetic / spelling variants.
- static func normalise(_ raw: String) -> String {
- var t = raw.lowercased()
- .components(separatedBy: .punctuationCharacters)
- .joined()
- .trimmingCharacters(in: .whitespaces)
+ /// Normalise a single word token for wake-phrase matching.
+ private static func normWord(_ w: String) -> String {
+ var t = normalise(w)
t = t
- .replacingOccurrences(of: "cuckoo", with: "coucou")
- .replacingOccurrences(of: "kuku", with: "coucou")
- .replacingOccurrences(of: "kucou", with: "coucou")
- .replacingOccurrences(of: "cou cou", with: "coucou")
- .replacingOccurrences(of: "okay", with: "ok")
- .replacingOccurrences(of: "o k ", with: "ok ")
- while t.contains(" ") { t = t.replacingOccurrences(of: " ", with: " ") }
+ .replacingOccurrences(of: "cuckoo", with: "coucou")
+ .replacingOccurrences(of: "kuku", with: "coucou")
+ .replacingOccurrences(of: "kucou", with: "coucou")
+ .replacingOccurrences(of: "okay", with: "ok")
return t
}
}
diff --git a/NotchBuddy/Sources/App/Voice/WakeSpotter.swift b/NotchBuddy/Sources/App/Voice/WakeSpotter.swift
index 53bc9554..591ed37f 100644
--- a/NotchBuddy/Sources/App/Voice/WakeSpotter.swift
+++ b/NotchBuddy/Sources/App/Voice/WakeSpotter.swift
@@ -125,7 +125,7 @@ final class WakeSpotter: @unchecked Sendable {
case .command:
let r = WakePhrase.split(transcript)
// In command phase, split always finds the wake prefix; fall back to full transcript.
- return .commandUpdate(r.matched ? r.command : transcript.lowercased())
+ return .commandUpdate(r.matched ? r.command : transcript)
}
}
diff --git a/tests/VoiceIslandTests.swift b/tests/VoiceIslandTests.swift
index 3063aa4f..d6e4cb70 100644
--- a/tests/VoiceIslandTests.swift
+++ b/tests/VoiceIslandTests.swift
@@ -98,6 +98,16 @@ enum VoiceIslandTests {
precondition(extra == 0, "double voiceWoke → no extra transition")
}
+ // voiceFinished from home-prev schedules the home-collapse timer
+ do {
+ let m = home()
+ m.homeToPetitDelay = 0.05 // 50 ms for a fast test
+ m.voiceWoke(); m.voiceFinished()
+ precondition(m.state == .home, "voiceFinished home-prev → home immediately")
+ try await Task.sleep(for: .milliseconds(200))
+ precondition(m.state == .petit, "home auto-collapsed after homeToPetitDelay")
+ }
+
print("\nAll VoiceIslandTests passed.")
}
}
diff --git a/tests/WakePhraseTests.swift b/tests/WakePhraseTests.swift
index 8d5765a7..25322d42 100644
--- a/tests/WakePhraseTests.swift
+++ b/tests/WakePhraseTests.swift
@@ -9,26 +9,39 @@ enum WakePhraseTests {
static func main() {
// MARK: split — should match
+
+ // Basic wake phrases (no command)
checkMatch("ok coucou", WakePhrase.split("ok coucou"), cmd: "")
checkMatch("OK COUCOU", WakePhrase.split("OK COUCOU"), cmd: "")
checkMatch("okay coucou", WakePhrase.split("okay coucou"), cmd: "")
- checkMatch("Okay, Coucou, ajoute GitHub",
- WakePhrase.split("Okay, Coucou, ajoute GitHub"), cmd: "ajoute github")
- checkMatch("ok cuckoo add github", WakePhrase.split("ok cuckoo add github"), cmd: "add github")
checkMatch("ok kuku", WakePhrase.split("ok kuku"), cmd: "")
checkMatch("ok cou cou", WakePhrase.split("ok cou cou"), cmd: "")
checkMatch("hey coucou", WakePhrase.split("hey coucou"), cmd: "")
checkMatch("Hey Coucou", WakePhrase.split("Hey Coucou"), cmd: "")
- checkMatch("ok coucou ouvre figma", WakePhrase.split("ok coucou ouvre figma"), cmd: "ouvre figma")
+
+ // Command extracted from original text (casing/punctuation preserved)
+ checkMatch("Okay, Coucou, ajoute GitHub",
+ WakePhrase.split("Okay, Coucou, ajoute GitHub"), cmd: "ajoute GitHub")
+ checkMatch("ok cuckoo add github",
+ WakePhrase.split("ok cuckoo add github"), cmd: "add github")
+ checkMatch("ok coucou ouvre figma",
+ WakePhrase.split("ok coucou ouvre figma"), cmd: "ouvre figma")
+
+ // Apostrophes, hyphens and accents preserved in command
+ checkMatch("OK Coucou, mets l'album de Daft Punk",
+ WakePhrase.split("OK Coucou, mets l'album de Daft Punk"), cmd: "mets l'album de Daft Punk")
+ checkMatch("ok coucou qu'est-ce que fait Claude ?",
+ WakePhrase.split("ok coucou qu'est-ce que fait Claude ?"), cmd: "qu'est-ce que fait Claude ?")
// Wake anywhere in transcript (word-boundary search)
checkMatch("euh ok coucou mets de la musique",
- WakePhrase.split("euh ok coucou mets de la musique"), cmd: "mets de la musique")
- checkMatch("la chanson dit ok coucou",WakePhrase.split("la chanson dit ok coucou"), cmd: "") // accepted false positive
+ WakePhrase.split("euh ok coucou mets de la musique"), cmd: "mets de la musique")
+ checkMatch("la chanson dit ok coucou",
+ WakePhrase.split("la chanson dit ok coucou"), cmd: "") // accepted false positive
// LAST occurrence wins
checkMatch("ok coucou search ok coucou play music",
- WakePhrase.split("ok coucou search ok coucou play music"), cmd: "play music")
+ WakePhrase.split("ok coucou search ok coucou play music"), cmd: "play music")
// Partial word-by-word delivery
checkNoMatch("ok alone", WakePhrase.split("ok"))