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.

voice: review fixes — real VoiceBrain Tools, speaker race, single phrase list

Louis Raillec2e39bcd9246
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 90f9fa29..ef47d5ce 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -54,6 +54,9 @@ jobs:
- name: Voice ActionRunner tests
run: bash scripts/test-voice-runner.sh
+ - name: Voice conversation end-phrase tests
+ run: bash scripts/test-voice-conversation.sh
+
- name: Test terminal target
run: bash scripts/test-terminal-target.sh
diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift
index bd129843..81c5cb17 100644
--- a/NotchBuddy/Sources/App/IslandWindowController.swift
+++ b/NotchBuddy/Sources/App/IslandWindowController.swift
@@ -27,10 +27,6 @@ final class IslandWindowController: NSWindowController {
private var voiceResultWork: DispatchWorkItem?
private var isInConversation = false
private var conversationContext = ConversationContext()
- private let conversationEndPhrases: Set<String> = [
- "merci", "c est bon", "c'est bon", "that s all", "that's all",
- "laisse tomber", "annule", "annuler", "cancel", "never mind", "bye", "au revoir",
- ]
#endif
// Suppress peek sound on next reveal (e.g. musicReveal)
@@ -335,6 +331,7 @@ final class IslandWindowController: NSWindowController {
self.voiceResultWork?.cancel()
self.voiceResultWork = nil
VoiceEngine.shared.endConversation()
+ VoiceBrain.shared.endConversation()
self.scheduleVoiceDismiss(delay: 0.3)
} else {
self.fsm.voiceFinished()
@@ -537,6 +534,7 @@ final class IslandWindowController: NSWindowController {
voiceResultWork?.cancel()
voiceResultWork = nil
VoiceEngine.shared.endConversation()
+ VoiceBrain.shared.endConversation()
}
#endif
// Keep the FSM in step with what is on screen (home/coucou → petit now).
@@ -1341,7 +1339,7 @@ extension IslandWindowController {
// ── Conversation end phrase ────────────────────────────────────────────────
let normTranscript = WakePhrase.normalise(transcript)
- if isInConversation && conversationEndPhrases.contains(normTranscript) {
+ if isInConversation && TurnEndPolicy.conversationEndPhrases.contains(normTranscript) {
endConversation(speaking: true)
return
}
@@ -1349,8 +1347,14 @@ extension IslandWindowController {
// ── Follow-up answer to a pending question ─────────────────────────────────
if runner.pendingQuestion != nil {
let result = await runner.handleAnswer(transcript, availablePills: pills)
- showVoiceResult(result, emote: result.outcome == .success ? BotEmote.happy : nil)
- // Questions don't continue conversation (already re-listening if needed)
+ if result.outcome == .success {
+ NotificationCenter.default.post(name: .triggerEmote, object: BotEmote.happy)
+ } else {
+ NotificationCenter.default.post(name: .botDizzy, object: nil)
+ }
+ AppState.shared.voiceResult = result
+ expand(to: .voiceResult)
+ speakAndContinueConversation(result)
return
}
@@ -1407,13 +1411,25 @@ extension IslandWindowController {
}
// ── Single command ─────────────────────────────────────────────────────────
- let result = await runner.run(intent, availablePills: pills, rawTranscript: transcript)
+ var result = await runner.run(intent, availablePills: pills, rawTranscript: transcript)
+ var effectiveIntent = intent
+
+ // If unknown, try VoiceBrain (macOS 26 + Apple Intelligence).
+ if case .unknown = intent,
+ let brain = await VoiceBrain.shared.resolve(transcript, pills: pills) {
+ if let firstIntent = brain.intents.first {
+ result = await runner.run(firstIntent, availablePills: pills, rawTranscript: transcript)
+ effectiveIntent = firstIntent
+ } else if !brain.text.isEmpty {
+ result = VoiceActionResult(outcome: .success, message: brain.text)
+ }
+ }
// Mochi reaction
switch result.outcome {
case .success:
NotificationCenter.default.post(name: .triggerEmote, object: BotEmote.happy)
- conversationContext.update(intent)
+ conversationContext.update(effectiveIntent)
case .failure:
NotificationCenter.default.post(name: .botDizzy, object: nil)
case .question:
@@ -1425,13 +1441,24 @@ extension IslandWindowController {
expand(to: .voiceResult)
if case .question = result.outcome {
- // Re-open listening in command phase (skip wake gate) so the answer goes straight
- // to the command pipeline. Give 5 s initial silence — user needs to read the question.
- voiceResultWork?.cancel()
- voiceResultWork = nil
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { [weak self] in
- guard self != nil else { return }
- VoiceEngine.shared.startListeningDirectly(firstWordTimeout: 5.0)
+ // Speak the question aloud, then re-listen once speech finishes.
+ // Give 5 s initial silence so the user has time to read/hear the question.
+ let speaker = VoiceSpeaker.shared
+ if VoiceSettings.speakEnabled {
+ speaker.speak(result.message, locale: VoiceEngine.shared.speechLocale)
+ speaker.onDidFinish = { [weak self] in
+ Task { @MainActor in
+ guard self != nil else { return }
+ VoiceEngine.shared.startListeningDirectly(firstWordTimeout: 5.0)
+ }
+ }
+ } else {
+ voiceResultWork?.cancel()
+ voiceResultWork = nil
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { [weak self] in
+ guard self != nil else { return }
+ VoiceEngine.shared.startListeningDirectly(firstWordTimeout: 5.0)
+ }
}
} else {
speakAndContinueConversation(result)
@@ -1453,6 +1480,7 @@ extension IslandWindowController {
/// Speak the result message (if enabled) then start next conversation turn.
@MainActor
private func speakAndContinueConversation(_ result: VoiceActionResult) {
+ if !isInConversation { VoiceBrain.shared.beginConversation() }
isInConversation = true
let speaker = VoiceSpeaker.shared
@@ -1492,6 +1520,7 @@ extension IslandWindowController {
voiceResultWork?.cancel()
voiceResultWork = nil
VoiceEngine.shared.endConversation()
+ VoiceBrain.shared.endConversation()
if speaking {
// Brief farewell emote
NotificationCenter.default.post(name: .triggerEmote, object: BotEmote.happy)
diff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swift
index 318bafa4..0b923833 100644
--- a/NotchBuddy/Sources/App/SettingsView.swift
+++ b/NotchBuddy/Sources/App/SettingsView.swift
@@ -1258,6 +1258,7 @@ struct SettingsView: View {
#if !APPSTORE
@State private var voicePermissionsGranted: Bool = false
@ObservedObject private var voiceEngine = VoiceEngine.shared
+ @AppStorage("voiceSpeakEnabled") private var speakEnabled: Bool = true
@ViewBuilder private var voiceSection: some View {
GroupBox(String(localized: "«\u{202F}OK Coucou\u{202F}» — voice wake word")) {
@@ -1265,10 +1266,7 @@ struct SettingsView: View {
Toggle(String(localized: "Enable voice command"), isOn: $voiceEngine.isEnabled)
.disabled(!voicePermissionsGranted && !voiceEngine.isEnabled)
- Toggle(String(localized: "voice.setting-speak"), isOn: Binding(
- get: { VoiceSettings.speakEnabled },
- set: { VoiceSettings.speakEnabled = $0 }
- ))
+ Toggle(String(localized: "voice.setting-speak"), isOn: $speakEnabled)
Text("When enabled, Coucou listens for the wake word «\u{202F}OK Coucou\u{202F}». Speech recognition runs entirely on-device — no audio or transcript leaves your Mac.")
.font(.system(size: 11))
@@ -1364,7 +1362,6 @@ struct SettingsView: View {
case .available: return String(localized: "voice.model-available")
case .notMacOS26: return String(localized: "voice.model-not-macos26")
case .appleIntelligenceOff: return String(localized: "voice.model-ai-off")
- case .languageUnsupported: return String(localized: "voice.model-lang")
}
}
#endif
diff --git a/NotchBuddy/Sources/App/Voice/ConversationContext.swift b/NotchBuddy/Sources/App/Voice/ConversationContext.swift
index 251e5801..2edfde0a 100644
--- a/NotchBuddy/Sources/App/Voice/ConversationContext.swift
+++ b/NotchBuddy/Sources/App/Voice/ConversationContext.swift
@@ -79,10 +79,11 @@ struct ConversationContext {
// MARK: - Reverse / undo
- // Triggers: "remets la", "remets le", "annule ca", "annule", "undo", "defait",
+ // Triggers: "remets la", "remets le", "annule ca", "undo", "defait",
// "cancel that", "undo this"
+ // Note: bare "annule" removed — it is a conversation-end phrase (TurnEndPolicy).
private func resolveReverse(norm: String) -> VoiceIntent? {
- let triggers = ["remets la", "remets le", "annule ca", "annule", "undo", "defait",
+ let triggers = ["remets la", "remets le", "annule ca", "undo", "defait",
"cancel that", "undo this"]
let isReverse = triggers.contains { norm == $0 || norm.hasPrefix($0 + " ") }
guard isReverse, let last = lastIntent else { return nil }
diff --git a/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift b/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift
index a5f3e433..1b6a927b 100644
--- a/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift
+++ b/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift
@@ -20,6 +20,13 @@ enum TurnEndPolicy {
return extendingWords.contains(lastWord) ? extendedSilence : baseSilence
}
+ /// Phrases that end the conversation window.
+ /// Single source of truth — used by VoiceEngine and IslandWindowController.
+ static let conversationEndPhrases: Set<String> = [
+ "merci", "c est bon", "c'est bon", "that s all", "that's all", "stop",
+ "laisse tomber", "annule", "annuler", "cancel", "never mind", "bye", "au revoir",
+ ]
+
// Words that suggest the utterance is mid-thought and should get extra silence.
static let extendingWords: Set<String> = [
// FR conjunctions / linkers
diff --git a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
index 84b69e61..34aae75a 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
@@ -162,7 +162,7 @@ final class VoiceActionRunner {
// Not in library — open Apple Music search
music.openSearch(name)
let fmt = Self.localizedString("voice.music-search-opened", locale: commandLocale)
- return .init(outcome: .failure,
+ return .init(outcome: .success,
message: fmt.contains("%@") ? String(format: fmt, name) : name)
case .musicPlayPlaylist(let name):
diff --git a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
index 0af7a06d..d5ba7a22 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
@@ -10,7 +10,13 @@ enum LocalModelStatus {
case available
case notMacOS26 // running on macOS < 26 or device not eligible
case appleIntelligenceOff
- case languageUnsupported
+}
+
+// MARK: - BrainResult
+
+struct BrainResult {
+ let intents: [VoiceIntent] // tool-derived intents (may be empty)
+ let text: String // natural-language reply to speak / display
}
// MARK: - VoiceBrain
@@ -27,7 +33,7 @@ final class VoiceBrain {
/// Current model availability status, updated lazily.
private(set) var modelStatus: LocalModelStatus
- /// Opaque session holder — avoids @available on stored property.
+ /// Opaque session container — avoids @available on stored property.
private var sessionBox: AnyObject? = nil
private init() {
@@ -47,8 +53,8 @@ final class VoiceBrain {
// MARK: - Intent resolution
/// Try to resolve `transcript` using the language model.
- /// Returns nil if the model is unavailable, or if the model cannot map to a VoiceIntent.
- func resolve(_ transcript: String, pills: [PillDefinition]) async -> VoiceIntent? {
+ /// Returns nil if the model is unavailable or if the model cannot map to any intent.
+ func resolve(_ transcript: String, pills: [PillDefinition]) async -> BrainResult? {
await VoiceBrain._resolve(transcript, pills: pills, sessionBox: sessionBox)
}
@@ -64,8 +70,6 @@ final class VoiceBrain {
switch reason {
case .appleIntelligenceNotEnabled:
return .appleIntelligenceOff
- case .deviceNotEligible:
- return .notMacOS26
default:
return .notMacOS26
}
@@ -81,13 +85,19 @@ final class VoiceBrain {
#if canImport(FoundationModels)
if #available(macOS 26, *) {
guard SystemLanguageModel.default.availability == .available else { return nil }
- return LanguageModelSession(
+ let collector = IntentCollector()
+ let session = LanguageModelSession(
+ tools: [PillTool(collector: collector),
+ MusicTool(collector: collector),
+ StatusTool(collector: collector)],
instructions: """
Tu es Coucou, un assistant dans le notch du MacBook.
Réponds toujours dans la langue de l'utilisateur.
- Réponds avec une phrase courte.
+ Réponds avec une phrase courte et directe.
+ Utilise les outils disponibles pour exécuter des commandes sur les pills et la musique.
"""
)
+ return SessionContainer(session: session, collector: collector)
}
#endif
return nil
@@ -95,17 +105,28 @@ final class VoiceBrain {
static func _resolve(_ transcript: String,
pills: [PillDefinition],
- sessionBox: AnyObject?) async -> VoiceIntent? {
+ sessionBox: AnyObject?) async -> BrainResult? {
#if canImport(FoundationModels)
if #available(macOS 26, *) {
guard SystemLanguageModel.default.availability == .available else { return nil }
- guard let session = sessionBox as? LanguageModelSession else { return nil }
+ guard let container = sessionBox as? SessionContainer else { return nil }
+ let collector = container.collector
+ collector.reset()
+
+ let pillList = pills.prefix(20)
+ .map { "\($0.id) (\($0.name))" }
+ .joined(separator: ", ")
+ let prompt = """
+ User said: "\(transcript)"
+ Available pills: \(pillList)
+ Use a tool if this is a command. Otherwise answer naturally in the user's language.
+ """
+
do {
- let prompt = "User said: \"\(transcript)\". Available pill names: \(pills.map(\.name).joined(separator: ", ")). Is this a command or a question? Respond in one sentence."
- _ = try await session.respond(to: prompt)
- // For now: VoiceBrain provides the fallback text answer (to be spoken),
- // but returns nil to VoiceIntent so execution falls through to .unknown.
- return nil
+ let response = try await withBrainTimeout(seconds: 4) {
+ try await container.session.respond(to: prompt)
+ }
+ return BrainResult(intents: collector.intents, text: response.content)
} catch {
return nil
}
@@ -115,4 +136,133 @@ final class VoiceBrain {
}
}
+// MARK: - Timeout helper (file-private)
+
+private func withBrainTimeout<T: Sendable>(
+ seconds: Double,
+ operation: @escaping @Sendable () async throws -> T
+) async throws -> T {
+ try await withThrowingTaskGroup(of: T.self) { group in
+ group.addTask { try await operation() }
+ group.addTask {
+ try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
+ throw CancellationError()
+ }
+ defer { group.cancelAll() }
+ guard let result = try await group.next() else { throw CancellationError() }
+ return result
+ }
+}
+
+// MARK: - FoundationModels types (macOS 26 only)
+
+#if canImport(FoundationModels)
+
+// MARK: IntentCollector
+
+@available(macOS 26, *)
+final class IntentCollector: @unchecked Sendable {
+ private(set) var intents: [VoiceIntent] = []
+
+ func append(_ intent: VoiceIntent) { intents.append(intent) }
+ func reset() { intents = [] }
+}
+
+// MARK: SessionContainer
+
+@available(macOS 26, *)
+final class SessionContainer: @unchecked Sendable {
+ let session: LanguageModelSession
+ let collector: IntentCollector
+ init(session: LanguageModelSession, collector: IntentCollector) {
+ self.session = session
+ self.collector = collector
+ }
+}
+
+// MARK: PillTool
+
+@available(macOS 26, *)
+struct PillTool: Tool, @unchecked Sendable {
+ let name = "pill"
+ let description = "Add, remove, set as main, or list pills in the notch"
+
+ @Generable
+ struct Arguments {
+ @Guide(description: "Action to perform: add | remove | setMain | list")
+ var action: String
+ @Guide(description: "Pill identifier, e.g. integration_github or agent_cursor. Empty for list.")
+ var pillId: String
+ }
+
+ let collector: IntentCollector
+
+ func call(arguments: Arguments) async throws -> String {
+ let intent: VoiceIntent? = switch arguments.action {
+ case "add": .pillAdd(id: arguments.pillId)
+ case "remove": .pillRemove(id: arguments.pillId)
+ case "setMain": .pillSetMain(id: arguments.pillId)
+ default: nil
+ }
+ if let i = intent { collector.append(i) }
+ return arguments.action == "list" ? "Listing active pills" : "\(arguments.action) \(arguments.pillId)"
+ }
+}
+
+// MARK: MusicTool
+
+@available(macOS 26, *)
+struct MusicTool: Tool, @unchecked Sendable {
+ let name = "music"
+ let description = "Control music playback: play, pause, next, previous, volumeUp, volumeDown, search, playlist"
+
+ @Generable
+ struct Arguments {
+ @Guide(description: "Action: play | pause | next | prev | volumeUp | volumeDown | search | playlist")
+ var action: String
+ @Guide(description: "Track or playlist name for search/playlist. Empty for other actions.")
+ var query: String
+ }
+
+ let collector: IntentCollector
+
+ func call(arguments: Arguments) async throws -> String {
+ let intent: VoiceIntent? = switch arguments.action {
+ case "play": .musicPlay(target: nil)
+ case "pause": .musicPause
+ case "next": .musicNext
+ case "prev": .musicPrevious
+ case "volumeUp": .musicVolumeUp
+ case "volumeDown": .musicVolumeDown
+ case "search": arguments.query.isEmpty ? nil : .musicPlaySearch(name: arguments.query)
+ case "playlist": arguments.query.isEmpty ? nil : .musicPlayPlaylist(name: arguments.query)
+ default: nil
+ }
+ if let i = intent { collector.append(i) }
+ return "music \(arguments.action)"
+ }
+}
+
+// MARK: StatusTool
+
+@available(macOS 26, *)
+struct StatusTool: Tool, @unchecked Sendable {
+ let name = "status"
+ let description = "Report Coucou status: list active pills, current agent session, or overall app state"
+
+ @Generable
+ struct Arguments {
+ @Guide(description: "What to report: pills | session | all")
+ var query: String
+ }
+
+ let collector: IntentCollector
+
+ func call(arguments: Arguments) async throws -> String {
+ // Status is answered in natural language by the model; no VoiceIntent needed.
+ return "status:\(arguments.query)"
+ }
+}
+
+#endif // canImport(FoundationModels)
#endif // !APPSTORE
diff --git a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
index bf2ce1a7..ff7bddc1 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
@@ -100,10 +100,6 @@ final class VoiceEngine: ObservableObject {
private static let maxRebuildsPerMinute = 5
private static let cancelPhrases = ["annule", "annuler", "cancel", "laisse tomber", "never mind"]
- private static let conversationEndPhrases: Set<String> = [
- "merci", "c est bon", "c'est bon", "that s all", "that's all", "stop",
- "laisse tomber", "annule", "annuler", "cancel", "never mind", "bye", "au revoir",
- ]
// MARK: - Init
@@ -112,13 +108,6 @@ final class VoiceEngine: ObservableObject {
let buildHash = Bundle.main.object(forInfoDictionaryKey: "CoucouGitHash") as? String ?? "unknown"
appendAppLog("nb.log", "[Voice] build \(buildHash)")
observeSystemEvents()
- VoiceSpeaker.shared.onDidFinish = { [weak self] in
- Task { @MainActor in
- guard let self, self.isListeningForCommand else { return }
- self.audio?.resetVAD()
- appendAppLog("nb.log", "[Voice] speaker finished, VAD recalibrated")
- }
- }
if isEnabled && !isPaused { startAudioPipeline() }
}
@@ -140,6 +129,7 @@ final class VoiceEngine: ObservableObject {
/// Called by IslandWindowController after showing a command result.
func startConversationTurn() {
isInConversation = true
+ audio?.resetVAD()
startListeningDirectly(firstWordTimeout: 8.0)
}
@@ -527,7 +517,7 @@ final class VoiceEngine: ObservableObject {
let normTrimmed = WakePhrase.normalise(trimmed)
if Self.cancelPhrases.contains(normTrimmed) {
endCommand(postFinished: true)
- } else if isInConversation && Self.conversationEndPhrases.contains(normTrimmed) {
+ } else if isInConversation && TurnEndPolicy.conversationEndPhrases.contains(normTrimmed) {
// Post voiceFinished with the end phrase so IslandWindowController can handle cleanup
endCommand(postFinished: true)
}
diff --git a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
index b0a46cee..eee1c031 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
@@ -14,6 +14,7 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
private let synth = AVSpeechSynthesizer()
private(set) var isSpeaking = false
+ private var currentUtterance: AVSpeechUtterance? = nil
/// Called ~300 ms after the utterance finishes. VoiceEngine uses this to resume listening.
var onDidFinish: (() -> Void)?
@@ -34,6 +35,7 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
let lang = loc.language.languageCode?.identifier ?? ""
if !lang.isEmpty { utt.voice = AVSpeechSynthesisVoice(language: lang) }
}
+ currentUtterance = utt
isSpeaking = true
synth.speak(utt)
}
@@ -48,8 +50,11 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
nonisolated func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer,
didFinish utterance: AVSpeechUtterance) {
+ let id = ObjectIdentifier(utterance)
Task { @MainActor in
+ guard let curr = self.currentUtterance, ObjectIdentifier(curr) == id else { return }
self.isSpeaking = false
+ self.currentUtterance = nil
try? await Task.sleep(nanoseconds: 300_000_000) // 300 ms gap
self.onDidFinish?()
}
@@ -57,7 +62,12 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
nonisolated func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer,
didCancel utterance: AVSpeechUtterance) {
- Task { @MainActor in self.isSpeaking = false }
+ let id = ObjectIdentifier(utterance)
+ Task { @MainActor in
+ guard let curr = self.currentUtterance, ObjectIdentifier(curr) == id else { return }
+ self.isSpeaking = false
+ self.currentUtterance = nil
+ }
}
}
#endif
diff --git a/scripts/test-voice-conversation.sh b/scripts/test-voice-conversation.sh
new file mode 100755
index 00000000..7a350f43
--- /dev/null
+++ b/scripts/test-voice-conversation.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+set -euo pipefail
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+OUT=/tmp/voice-conversation-tests
+echo "=== Voice conversation end-phrase tests ==="
+swiftc -swift-version 6 -strict-concurrency=complete \
+ "$ROOT/NotchBuddy/Sources/App/Voice/TurnEndPolicy.swift" \
+ "$ROOT/tests/VoiceConversationTests.swift" \
+ -o "$OUT"
+"$OUT"
diff --git a/tests/ConversationContextTests.swift b/tests/ConversationContextTests.swift
index f7a1e6ce..7a80c343 100644
--- a/tests/ConversationContextTests.swift
+++ b/tests/ConversationContextTests.swift
@@ -48,9 +48,9 @@ enum ConversationContextTests {
static func testReverse_pillAdd() {
var ctx = ConversationContext()
ctx.update(.pillAdd(id: "integration_github"))
- let r = ctx.resolveRelative("annule", pills: pills)
+ let r = ctx.resolveRelative("annule ca", pills: pills)
precondition(r == .pillRemove(id: "integration_github"),
- "annule after pillAdd → pillRemove")
+ "annule ca after pillAdd → pillRemove")
}
static func testReverse_musicPause() {
diff --git a/tests/VoiceActionRunnerTests.swift b/tests/VoiceActionRunnerTests.swift
index 6eaaa5a3..d193a568 100644
--- a/tests/VoiceActionRunnerTests.swift
+++ b/tests/VoiceActionRunnerTests.swift
@@ -125,10 +125,10 @@ enum VoiceActionRunnerTests {
check("search → search:Daft Punk", music.calls.last, "search:Daft Punk")
music.calls = []
- // Search not found → failure
+ // Search not found → Apple Music search opened → success
music.searchResult = false
let searchFail = await runner.run(.musicPlaySearch(name: "XYZ"), availablePills: pills)
- check("search not found → failure", searchFail.outcome, .failure)
+ check("search not found → failure", searchFail.outcome, .success)
music.searchResult = true
music.calls = []
diff --git a/tests/VoiceConversationTests.swift b/tests/VoiceConversationTests.swift
new file mode 100644
index 00000000..a11f98aa
--- /dev/null
+++ b/tests/VoiceConversationTests.swift
@@ -0,0 +1,34 @@
+import Foundation
+
+@main
+enum VoiceConversationTests {
+
+ static func main() {
+ let phrases = TurnEndPolicy.conversationEndPhrases
+
+ // ── Members ───────────────────────────────────────────────────────────
+ precondition(phrases.contains("stop"), "stop must end conversation")
+ precondition(phrases.contains("merci"), "merci must end conversation")
+ precondition(phrases.contains("annule"), "annule must end conversation")
+ precondition(phrases.contains("annuler"), "annuler must end conversation")
+ precondition(phrases.contains("cancel"), "cancel must end conversation")
+ precondition(phrases.contains("never mind"), "never mind must end conversation")
+ precondition(phrases.contains("bye"), "bye must end conversation")
+ precondition(phrases.contains("au revoir"), "au revoir must end conversation")
+ precondition(phrases.contains("c est bon"), "c est bon must end conversation")
+ precondition(phrases.contains("c'est bon"), "c'est bon must end conversation")
+ precondition(phrases.contains("that s all"), "that s all must end conversation")
+ precondition(phrases.contains("that's all"), "that's all must end conversation")
+ precondition(phrases.contains("laisse tomber"), "laisse tomber must end conversation")
+
+ // ── Non-members ───────────────────────────────────────────────────────
+ precondition(!phrases.contains("xyz"), "xyz must NOT end conversation")
+ precondition(!phrases.contains("ajoute"), "ajoute must NOT end conversation")
+ precondition(!phrases.contains("merci beaucoup"), "merci beaucoup must NOT end conversation")
+
+ // ── Non-empty ─────────────────────────────────────────────────────────
+ precondition(!phrases.isEmpty, "conversationEndPhrases must not be empty")
+
+ print("All voice conversation end-phrase tests passed.")
+ }
+}