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
voice-jarvis: review fixes (stale re-listen, action before "c'est fait", live caption)
Clauded6b478d6ac35
diff --git a/NotchBuddy/Resources/Localizable.xcstrings b/NotchBuddy/Resources/Localizable.xcstringsindex c69d9c57..c16542b2 100644--- a/NotchBuddy/Resources/Localizable.xcstrings+++ b/NotchBuddy/Resources/Localizable.xcstrings@@ -24386,6 +24386,71 @@}}}+ },+ "voice.setting-captions": {+ "extractionState": "manual",+ "localizations": {+ "ar": {+ "stringUnit": {+ "state": "translated",+ "value": "ترجمة نصية أسفل النوتش"+ }+ },+ "bn": {+ "stringUnit": {+ "state": "translated",+ "value": "নচের নিচে সাবটাইটেল"+ }+ },+ "en": {+ "stringUnit": {+ "state": "translated",+ "value": "Subtitles under the notch"+ }+ },+ "es": {+ "stringUnit": {+ "state": "translated",+ "value": "Subtítulos bajo el notch"+ }+ },+ "fr": {+ "stringUnit": {+ "state": "translated",+ "value": "Sous-titres sous le notch"+ }+ },+ "hi": {+ "stringUnit": {+ "state": "translated",+ "value": "नॉच के नीचे सबटाइटल"+ }+ },+ "id": {+ "stringUnit": {+ "state": "translated",+ "value": "Subtitel di bawah notch"+ }+ },+ "pt-BR": {+ "stringUnit": {+ "state": "translated",+ "value": "Legendas abaixo do notch"+ }+ },+ "ru": {+ "stringUnit": {+ "state": "translated",+ "value": "Субтитры под вырезом"+ }+ },+ "zh-Hans": {+ "stringUnit": {+ "state": "translated",+ "value": "刘海下方显示字幕"+ }+ }+ }}},"version": "1.0"diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swiftindex 2f83f7e9..3e623ede 100644--- a/NotchBuddy/Sources/App/IslandWindowController.swift+++ b/NotchBuddy/Sources/App/IslandWindowController.swift@@ -1468,10 +1468,17 @@ extension IslandWindowController {let brainWarm = VoiceBrain.shared.isSessionReadyvar brainUsed = false+ // A stale "finished speaking" handler from the previous turn would re-open+ // the mic between two streamed sentences: drop it before streaming.+ VoiceSpeaker.shared.onDidFinish = nil+let brain = await VoiceBrain.shared.resolveWithStreaming(transcript, pills: pills- ) { sentence in- VoiceSpeaker.shared.enqueue(sentence, locale: locale)+ ) { sentence, hasActions in+ // When the model is acting (tool call), its text is not spoken: the real+ // outcome comes from VoiceActionRunner below ("C'est fait" must not be+ // said before the action ran, or when it failed / needs a question).+ if !hasActions { VoiceSpeaker.shared.enqueue(sentence, locale: locale) }VoiceCaptionManager.shared.appendResponse(sentence)}@@ -1481,22 +1488,36 @@ extension IslandWindowController {if let brain {if !brain.intents.isEmpty {- // Run brain intents; model already voiced confirmation via streaming TTS.+ // Run the actions the model asked for: removals before additions.var sorted = brain.intentssorted.sort { a, b inlet ra: Bool = { switch a { case .pillRemove, .pillRemoveMultiple: return true; default: return false } }()let rb: Bool = { switch b { case .pillRemove, .pillRemoveMultiple: return true; default: return false } }()return ra && !rb}+ effectiveIntent = sorted[0]+ var parts: [String] = []+ var anyFailure = false+ var questionResult: VoiceActionResult? = nilfor bi in sorted {let r = await runner.run(bi, availablePills: pills, rawTranscript: transcript)- if case .success = r.outcome {+ parts.append(r.message)+ switch r.outcome {+ case .success:effectiveIntent = biVoiceTranscriptHistory.shared.record(transcript: transcript, intent: bi, origin: .brain)+ case .failure:+ anyFailure = true+ case .question:+ questionResult = r}}- result = VoiceActionResult(outcome: .success, message: brain.text)- brainUsed = true+ // Same path as a parser command below: short spoken confirmation,+ // or the question ("laquelle j'enlève ?") with its re-listen.+ VoiceCaptionManager.shared.clearResponse()+ result = questionResult ?? VoiceActionResult(+ outcome: anyFailure ? .failure : .success,+ message: parts.joined(separator: " · "))} else if !brain.text.isEmpty {result = VoiceActionResult(outcome: .success, message: brain.text)brainUsed = truediff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swiftindex 90a03838..fa9c794a 100644--- a/NotchBuddy/Sources/App/SettingsView.swift+++ b/NotchBuddy/Sources/App/SettingsView.swift@@ -1269,7 +1269,7 @@ struct SettingsView: View {Toggle(String(localized: "voice.setting-speak"), isOn: $speakEnabled)- Toggle(String(localized: "Sous-titres"), isOn: $captionEnabled)+ Toggle(String(localized: "voice.setting-captions"), isOn: $captionEnabled)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))diff --git a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift b/NotchBuddy/Sources/App/Voice/VoiceBrain.swiftindex 4d910827..2a47833c 100644--- a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift@@ -42,8 +42,10 @@ final class VoiceBrain {// MARK: - Conversation lifecycle+ /// Keeps the session created (and prewarmed) at wake time, so the first turn's+ /// context and the warm model carry into the conversation.func beginConversation() {- sessionBox = VoiceBrain._makeSession()+ if sessionBox == nil { sessionBox = VoiceBrain._makeSession() }}func endConversation() {@@ -75,7 +77,7 @@ final class VoiceBrain {func resolveWithStreaming(_ transcript: String,pills: [PillDefinition],- onSentence: @escaping @MainActor (String) -> Void+ onSentence: @escaping @MainActor (_ sentence: String, _ hasActions: Bool) -> Void) async -> BrainResult? {if sessionBox == nil { sessionBox = VoiceBrain._makeSession() }return await VoiceBrain._resolveWithStreaming(@@ -172,7 +174,7 @@ final class VoiceBrain {_ transcript: String,pills: [PillDefinition],sessionBox: AnyObject?,- onSentence: @escaping @MainActor (String) -> Void+ onSentence: @escaping @MainActor (_ sentence: String, _ hasActions: Bool) -> Void) async -> BrainResult? {#if canImport(FoundationModels)if #available(macOS 26, *) {@@ -207,7 +209,8 @@ final class VoiceBrain {let sentence = String(accumulated[startIdx..<afterBoundary]).trimmingCharacters(in: .whitespaces)if !sentence.isEmpty {- await MainActor.run { onSentence(sentence) }+ let acts = !collector.intents.isEmpty+ await MainActor.run { onSentence(sentence, acts) }}sentUpTo = accumulated.distance(from: accumulated.startIndex, to: afterBoundary)}@@ -218,7 +221,8 @@ final class VoiceBrain {let startIdx = accumulated.index(accumulated.startIndex, offsetBy: sentUpTo)let remaining = String(accumulated[startIdx...]).trimmingCharacters(in: .whitespaces)if !remaining.isEmpty {- await MainActor.run { onSentence(remaining) }+ let acts = !collector.intents.isEmpty+ await MainActor.run { onSentence(remaining, acts) }}}diff --git a/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift b/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swiftindex 65ec7a24..8b44c4e3 100644--- a/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift@@ -1,5 +1,6 @@#if !APPSTOREimport AppKit+import Combineimport SwiftUI// MARK: - VoiceCaptionState@@ -10,6 +11,9 @@ final class VoiceCaptionState: ObservableObject {@Published var userLine: String = ""@Published var responseLine: String = ""@Published var isVisible: Bool = false+ /// Live words while the mic is open for a command (mirrors VoiceEngine).+ @Published var liveLine: String = ""+ @Published var isListening: Bool = false}// MARK: - VoiceCaptionManager@@ -34,12 +38,35 @@ final class VoiceCaptionManager {private var panel: NSPanel?private var hideTask: Task<Void, Never>?+ private var subs: Set<AnyCancellable> = []private let captionWidth: CGFloat = 360- private let captionHeight: CGFloat = 52+ private let captionHeight: CGFloat = 76 // 1 line heard + 2 lines of answerprivate let notchGap: CGFloat = 6- private init() {}+ private init() {+ // Only these two engine properties: observing the whole engine would redraw+ // the caption on every mic level change.+ let engine = VoiceEngine.shared+ engine.$commandTranscript+ .removeDuplicates()+ .receive(on: RunLoop.main)+ .sink { [weak self] t in+ MainActor.assumeIsolated { self?.state.liveLine = t }+ }+ .store(in: &subs)+ engine.$isListeningForCommand+ .removeDuplicates()+ .receive(on: RunLoop.main)+ .sink { [weak self] on in+ MainActor.assumeIsolated {+ guard let self else { return }+ self.state.isListening = on+ if on { self.state.liveLine = "" }+ }+ }+ .store(in: &subs)+ }// MARK: - Show / hide@@ -111,7 +138,9 @@ final class VoiceCaptionManager {)p.isOpaque = falsep.backgroundColor = .clear- p.level = .statusBar+ // Same level as the island, so the caption is never hidden behind it.+ p.level = NSWindow.Level(rawValue: Int(CGWindowLevelForKey(.mainMenuWindow)) + 3)+ p.ignoresMouseEvents = truep.collectionBehavior = [.canJoinAllSpaces, .stationary, .ignoresCycle]p.contentView = viewp.alphaValue = 0@@ -144,31 +173,44 @@ final class VoiceCaptionManager {struct VoiceCaptionView: View {@ObservedObject var state: VoiceCaptionState+ /// While the mic is open: what I am saying, live. Afterwards: what I said + the answer.+ private var heard: String { state.isListening ? state.liveLine : state.userLine }+ private var answer: String { state.isListening ? "" : state.responseLine }+var body: some View {- VStack(alignment: .leading, spacing: 2) {- if !state.userLine.isEmpty {- Text(state.userLine)- .font(.system(size: 12))- .foregroundStyle(.secondary)- .lineLimit(1)- .truncationMode(.tail)- }- if !state.responseLine.isEmpty {- Text(state.responseLine)- .font(.system(size: 12))- .foregroundStyle(.white)- .lineLimit(2)- .truncationMode(.tail)+ VStack(spacing: 0) {+ if !heard.isEmpty || !answer.isEmpty {+ VStack(alignment: .leading, spacing: 2) {+ if !heard.isEmpty {+ Text(verbatim: heard)+ .font(.system(size: 12))+ .foregroundColor(.white.opacity(0.55))+ .lineLimit(1)+ .truncationMode(.head)+ }+ if !answer.isEmpty {+ Text(verbatim: answer)+ .font(.system(size: 12, weight: .medium))+ .foregroundColor(.white)+ .lineLimit(2)+ .truncationMode(.tail)+ }+ }+ .padding(.horizontal, 14)+ .padding(.vertical, 8)+ .frame(maxWidth: 360, alignment: .leading)+ .fixedSize(horizontal: false, vertical: true)+ .background(+ RoundedRectangle(cornerRadius: 12, style: .continuous)+ .fill(Color.black.opacity(0.92))+ )+ .transition(.opacity)}+ Spacer(minLength: 0)}- .padding(.horizontal, 14)- .padding(.vertical, 8)- .frame(maxWidth: .infinity, alignment: .leading)- .background(- RoundedRectangle(cornerRadius: 12, style: .continuous)- .fill(Color.black.opacity(0.88))- )- .frame(width: 360)+ .animation(.easeOut(duration: 0.2), value: heard.isEmpty && answer.isEmpty)+ .frame(width: 360, height: 76, alignment: .top)+ .environment(\.colorScheme, .dark)}}#endifdiff --git a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swiftindex 1bcb7c49..b7a3c718 100644--- a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift+++ b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift@@ -65,21 +65,27 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Sendsynth.speak(utt)}- /// Picks the highest quality installed voice for the given locale.- /// Falls back to .premium → .enhanced → default language voice.+ /// Picks the best installed voice for the spoken locale: same region first+ /// (fr-FR before fr-CA), then quality (.premium > .enhanced > default).+ /// Novelty voices and the user's Personal Voice are never used.private func _bestVoice(for locale: Locale?) -> AVSpeechSynthesisVoice? {guard let loc = locale else { return nil }let lang = loc.language.languageCode?.identifier ?? ""guard !lang.isEmpty else { return nil }+ let region = loc.region?.identifier+ let exact = region.map { "\(lang)-\($0)" }- let voices = AVSpeechSynthesisVoice.speechVoices().filter {- $0.language.hasPrefix(lang)+ let voices = AVSpeechSynthesisVoice.speechVoices().filter { v in+ (v.language == lang || v.language.hasPrefix(lang + "-"))+ && !v.voiceTraits.contains(.isNoveltyVoice)+ && !v.voiceTraits.contains(.isPersonalVoice)}- if voices.isEmpty { return AVSpeechSynthesisVoice(language: lang) }+ guard !voices.isEmpty else { return AVSpeechSynthesisVoice(language: exact ?? lang) }- // Sort by quality descending (.premium > .enhanced > default)- let sorted = voices.sorted { $0.quality.rawValue > $1.quality.rawValue }- return sorted.first ?? AVSpeechSynthesisVoice(language: lang)+ func rank(_ v: AVSpeechSynthesisVoice) -> (Int, Int) {+ (v.language == exact ? 1 : 0, v.quality.rawValue)+ }+ return voices.max { rank($0) < rank($1) }}// MARK: - AVSpeechSynthesizerDelegate