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: revue 3 — politeness, infinitives, question display, default target

Louis Raille1cf2e0cf360d
diff --git a/NotchBuddy/Resources/Localizable.xcstrings b/NotchBuddy/Resources/Localizable.xcstrings
index acaede98..ff3e5242 100644
--- a/NotchBuddy/Resources/Localizable.xcstrings
+++ b/NotchBuddy/Resources/Localizable.xcstrings
@@ -23615,6 +23615,70 @@
}
}
},
+ "voice.question-cancelled": {
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "OK, leaving it as is"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "D'accord, je laisse comme ça"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "De acuerdo, lo dejo como está"
+ }
+ },
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "حسنًا، أتركه كما هو"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ঠিক আছে, এটা যেমন আছে রেখে দিচ্ছি"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ठीक है, जैसा है वैसा छोड़ता हूँ"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Baik, biarkan seperti itu"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Ok, vou deixar como está"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Хорошо, оставляю как есть"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "好的,保持原样"
+ }
+ }
+ }
+ },
"voice.unknown": {
"localizations": {
"en": {
diff --git a/NotchBuddy/Sources/App/IslandWindowController.swift b/NotchBuddy/Sources/App/IslandWindowController.swift
index a12f6109..5cc25158 100644
--- a/NotchBuddy/Sources/App/IslandWindowController.swift
+++ b/NotchBuddy/Sources/App/IslandWindowController.swift
@@ -297,7 +297,10 @@ final class IslandWindowController: NSWindowController {
#if !APPSTORE
NotificationCenter.default.addObserver(
forName: .voiceWoke, object: nil, queue: .main
- ) { [weak self] _ in
+ ) { [weak self] note in
+ // Genuine wake phrase (not programmatic re-listen) → clear any pending question
+ let isDirect = (note.object as? String) == "direct"
+ if !isDirect { VoiceActionRunner.shared.pendingQuestion = nil }
self?.fsm.voiceWoke()
}
// Voice: command session ended — run intent, show result for 2 s, then collapse.
@@ -307,7 +310,18 @@ final class IslandWindowController: NSWindowController {
guard let self else { return }
let transcript = note.object as? String ?? ""
if transcript.isEmpty {
- self.fsm.voiceFinished()
+ if VoiceActionRunner.shared.pendingQuestion != nil {
+ // Re-listen timed out with no answer → show cancellation message
+ Task { @MainActor in
+ let result = await VoiceActionRunner.shared.handleAnswer(
+ "", availablePills: PillCatalog.available)
+ AppState.shared.voiceResult = result
+ self.expand(to: .voiceResult)
+ self.scheduleVoiceDismiss(delay: 1.5)
+ }
+ } else {
+ self.fsm.voiceFinished()
+ }
} else {
Task { @MainActor in await self.handleVoiceCommand(transcript) }
}
diff --git a/NotchBuddy/Sources/App/Voice/IntentParser.swift b/NotchBuddy/Sources/App/Voice/IntentParser.swift
index c64122aa..6445f962 100644
--- a/NotchBuddy/Sources/App/Voice/IntentParser.swift
+++ b/NotchBuddy/Sources/App/Voice/IntentParser.swift
@@ -18,9 +18,24 @@ enum IntentParser {
// rawWords: same splits as normalise but no diacritics strip, no letter filter, original case
let rawWords0 = buildRawWords(raw)
// defilter both arrays in parallel: ma→la, mon→le, strip filler words
- let (fwords, frawWords) = defilter(words, rawWords: rawWords0)
+ var (fwords, frawWords) = defilter(words, rawWords: rawWords0)
guard !fwords.isEmpty else { return .unknown }
+ // ── 0a. Strip politeness prefixes from the start ─────────────────────
+ // "tu peux", "est-ce que tu peux", "peux-tu", "can you", etc.
+ for prefix in politenessPrefixes {
+ if fwords.starts(with: prefix) {
+ fwords = Array(fwords[prefix.count...])
+ frawWords = Array(frawWords[min(prefix.count, frawWords.count)...])
+ break
+ }
+ }
+ guard !fwords.isEmpty else { return .unknown }
+
+ // ── 0b. Map infinitives → imperative forms ────────────────────────────
+ // "mettre" → "mets", "lancer" → "lance", "ajouter" → "ajoute", …
+ fwords = fwords.map { infinitiveMap[$0] ?? $0 }
+
// ── 1. Explicit music-only patterns ──────────────────────────────────
if matchesAny(fwords, in: pausePrefixes) { return .musicPause }
if matchesAny(fwords, in: nextPrefixes) { return .musicNext }
@@ -133,7 +148,10 @@ enum IntentParser {
}
if ids.count >= 2 { return .pillAddMultiple(ids: ids) }
}
- // Music service pills → musicPlay with target
+ // Generic music word → musicPlay(nil) FIRST (before service-pill check so
+ // "musique" alias → integration_music doesn't force an appleMusic target)
+ if musicGenericWords.contains(clean) { return .musicPlay(target: nil) }
+ // Music service pills → musicPlay with explicit target
if let id = EntityResolver.resolve(clean, from: pills),
musicServicePillIds.contains(id) {
let target: MusicTarget = id == "integration_spotify" ? .spotify : .appleMusic
@@ -154,8 +172,6 @@ enum IntentParser {
if let id = EntityResolver.resolve(clean, from: pills) {
return .pillAdd(id: id)
}
- // Generic music word → musicPlay(nil)
- if musicGenericWords.contains(clean) { return .musicPlay(target: nil) }
// Not a pill, not generic → search (title or artist) with original text
let name = cleanRaw.isEmpty ? clean : cleanRaw
return .musicPlaySearch(name: name)
@@ -410,6 +426,38 @@ enum IntentParser {
// MARK: - Keyword tables
+ /// Polite prefix sequences stripped from the START of the word array (longest first).
+ private static let politenessPrefixes: [[String]] = [
+ ["est", "ce", "que", "tu", "peux"],
+ ["est", "ce", "que", "tu", "pourrais"],
+ ["tu", "peux"],
+ ["tu", "pourrais"],
+ ["peux", "tu"],
+ ["could", "you"],
+ ["can", "you"],
+ ["please"],
+ ]
+
+ /// Maps normalised infinitive forms → imperative/trigger forms.
+ private static let infinitiveMap: [String: String] = [
+ "mettre": "mets",
+ "lancer": "lance",
+ "jouer": "joue",
+ "ajouter": "ajoute",
+ "enlever": "enleve",
+ "retirer": "retire",
+ "supprimer": "supprime",
+ "activer": "active",
+ "desactiver": "desactive",
+ "remplacer": "remplace",
+ "garder": "garde",
+ "passer": "passe",
+ "monter": "monte",
+ "baisser": "baisse",
+ "couper": "coupe",
+ "arreter": "arrete",
+ ]
+
private static let pausePrefixes: [[String]] = [
["pause"], ["stop"], ["stoppe"], ["coupe"],
["mets", "en", "pause"], ["met", "en", "pause"],
diff --git a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
index cb3d16cf..2ec6bdf3 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceActionRunner.swift
@@ -253,6 +253,10 @@ final class VoiceActionRunner {
guard let pending = pendingQuestion else { return fail("voice.unknown") }
pendingQuestion = nil
+ guard !transcript.trimmingCharacters(in: .whitespaces).isEmpty else {
+ return ok("voice.question-cancelled")
+ }
+
let norm = IntentParser.normalise(transcript)
guard let entity = EntityResolver.resolve(norm, from: availablePills) else {
return fail("voice.unknown")
diff --git a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
index 8457201a..a44e3473 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
@@ -99,7 +99,7 @@ final class VoiceEngine: ObservableObject {
lastWordCount = 0
audio.bypassVAD = true
appendAppLog("nb.log", "[Voice] direct listen start")
- NotificationCenter.default.post(name: .voiceWoke, object: nil)
+ NotificationCenter.default.post(name: .voiceWoke, object: "direct" as NSString)
let preroll = audio.drainPreroll()
spotter.beginWindow(locale: loc, preroll: preroll)
resetSilenceTimer()
diff --git a/NotchBuddy/Sources/App/Voice/VoiceIslandView.swift b/NotchBuddy/Sources/App/Voice/VoiceIslandView.swift
index 3e1fc450..c22c532e 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceIslandView.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceIslandView.swift
@@ -12,6 +12,13 @@ import SwiftUI
struct VoiceListeningView: View {
let isActive: Bool
@ObservedObject private var voice = VoiceEngine.shared
+ @ObservedObject private var state = AppState.shared
+
+ /// Question text to show above transcript when re-listening after a .question outcome.
+ private var pendingQuestionText: String? {
+ if case .question(let text) = state.voiceResult?.outcome { return text }
+ return nil
+ }
var body: some View {
ZStack {
@@ -28,11 +35,18 @@ struct VoiceListeningView: View {
.foregroundColor(Color(hex: "#F5F6F8"))
}
- if voice.commandTranscript.isEmpty {
+ if let question = pendingQuestionText {
+ Text(question)
+ .font(.system(size: 12))
+ .foregroundColor(Color(hex: "#F97316"))
+ .lineLimit(2)
+ } else if voice.commandTranscript.isEmpty {
Text("Say your command", tableName: "Localizable")
.font(.system(size: 12))
.foregroundColor(Color(hex: "#8E939C"))
- } else {
+ }
+
+ if !voice.commandTranscript.isEmpty {
Text(voice.commandTranscript)
.font(.system(size: 12))
.foregroundColor(Color(hex: "#C8CBD0"))
diff --git a/tests/IntentParserTests.swift b/tests/IntentParserTests.swift
index a43fa0ab..7f21df17 100644
--- a/tests/IntentParserTests.swift
+++ b/tests/IntentParserTests.swift
@@ -171,6 +171,23 @@ enum IntentParserTests {
check("mònte lê sôn diacritics", parse("mònte lê sôn"), .musicVolumeUp)
check("next trailing punct", parse("next!"), .musicNext)
+ // ── Politeness prefixes + infinitives ────────────────────────────────
+ check("tu peux mettre de la musique",
+ parse("tu peux mettre de la musique"),
+ .musicPlay(target: nil))
+ check("est-ce que tu peux enlever Vercel",
+ parse("est-ce que tu peux enlever Vercel", pills: pills),
+ .pillRemove(id: "integration_vercel"))
+ check("peux-tu ajouter GitHub",
+ parse("peux-tu ajouter GitHub", pills: pills),
+ .pillAdd(id: "integration_github"))
+ check("could you play some music",
+ parse("could you play some music"),
+ .musicPlay(target: nil))
+ check("tu pourrais baisser le son",
+ parse("tu pourrais baisser le son"),
+ .musicVolumeDown)
+
// Summary
let total = pass + fail
if fail == 0 { print("\n\(total)/\(total) passed.") }
diff --git a/tests/VoiceActionRunnerTests.swift b/tests/VoiceActionRunnerTests.swift
index ea023ee9..a111365d 100644
--- a/tests/VoiceActionRunnerTests.swift
+++ b/tests/VoiceActionRunnerTests.swift
@@ -223,6 +223,14 @@ enum VoiceActionRunnerTests {
check("pillOnly → removed notion", pills_.calls.contains("toggle:integration_notion"), true)
check("pillOnly → added vercel", pills_.calls.contains("toggle:integration_vercel"), true)
+ // ── Follow-up: empty transcript cancels question ─────────────────────
+ pills_.active = Set(["integration_github","integration_vercel","integration_notion","integration_resend"])
+ _ = await runner.run(.pillAdd(id: "agent_cursor"), availablePills: pills)
+ check("pending set before empty answer", runner.pendingQuestion != nil, true)
+ let emptyAnswer = await runner.handleAnswer("", availablePills: pills)
+ check("empty answer → success (cancelled)", emptyAnswer.outcome, .success)
+ check("empty answer clears pendingQuestion", runner.pendingQuestion == nil, true)
+
// ── Unknown ───────────────────────────────────────────────────────────
let unk = await runner.run(.unknown, availablePills: pills)
check("unknown → failure", unk.outcome, .failure)