Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Add app aware custom prompt configuration

grohith327cdd8802bfd51
diff --git a/Fluid.xcodeproj/project.pbxproj b/Fluid.xcodeproj/project.pbxproj
index 8a85af7f..1a20b3f0 100644
--- a/Fluid.xcodeproj/project.pbxproj
+++ b/Fluid.xcodeproj/project.pbxproj
@@ -408,7 +408,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = V4J43B279J;
+ DEVELOPMENT_TEAM = J67LH9U7BN;
ENABLE_APP_SANDBOX = NO;
ENABLE_CODE_COVERAGE = NO;
ENABLE_FILE_ACCESS_DOWNLOADS_FOLDER = readwrite;
@@ -462,7 +462,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
- DEVELOPMENT_TEAM = V4J43B279J;
+ DEVELOPMENT_TEAM = J67LH9U7BN;
ENABLE_APP_SANDBOX = NO;
ENABLE_CODE_COVERAGE = NO;
ENABLE_FILE_ACCESS_DOWNLOADS_FOLDER = readwrite;
@@ -623,8 +623,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ejbills/mediaremote-adapter";
requirement = {
- kind = branch;
branch = master;
+ kind = branch;
};
};
7CE006BB2E80EBE600DDCCD6 /* XCRemoteSwiftPackageReference "AppUpdater" */ = {
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index a72d6758..d39683df 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -1217,6 +1217,22 @@ struct ContentView: View {
return nil
}
+ private func captureRecordingContext() {
+ // Capture the focused target PID BEFORE any overlay/UI changes.
+ // Used to restore focus when the user interacts with overlay dropdowns.
+ let focusedPID = TypingService.captureSystemFocusedPID()
+ ?? NSWorkspace.shared.frontmostApplication?.processIdentifier
+ NotchContentState.shared.recordingTargetPID = focusedPID
+
+ let info = self.getCurrentAppInfo()
+ self.recordingAppInfo = info
+ self.rewriteModeService.setPromptAppBundleID(info.bundleId)
+ DebugLogger.shared.debug(
+ "Captured recording app context: app=\(info.name), bundleId=\(info.bundleId), title=\(info.windowTitle)",
+ source: "ContentView"
+ )
+ }
+
// MARK: - Commented out app-specific prompts - using general processing only
/*
@@ -1330,8 +1346,10 @@ struct ContentView: View {
/// Build a general system prompt with voice editing commands support
private func buildSystemPrompt(appInfo: (name: String, bundleId: String, windowTitle: String)) -> String {
- _ = appInfo
- return SettingsStore.shared.effectiveSystemPrompt(for: .dictate)
+ return SettingsStore.shared.effectiveSystemPrompt(
+ for: .dictate,
+ appBundleID: appInfo.bundleId
+ )
}
private var shouldTracePromptProcessing: Bool {
@@ -1424,7 +1442,10 @@ struct ContentView: View {
let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
let systemPrompt = self.buildSystemPrompt(appInfo: appInfo)
if self.shouldTracePromptProcessing {
- let selectedProfile = SettingsStore.shared.selectedPromptProfile(for: .dictate)
+ let selectedProfile = SettingsStore.shared.resolvedPromptProfile(
+ for: .dictate,
+ appBundleID: appInfo.bundleId
+ )
let selectedPromptName: String = {
if let profile = selectedProfile {
return profile.name.isEmpty ? "Untitled Prompt" : profile.name
@@ -1432,7 +1453,10 @@ struct ContentView: View {
return "Default Dictate"
}()
self.logDictationPromptTrace("Selected prompt profile", value: selectedPromptName)
- self.logDictationPromptTrace("Prompt body (custom/default body)", value: SettingsStore.shared.effectivePromptBody(for: .dictate))
+ self.logDictationPromptTrace(
+ "Prompt body (custom/default body)",
+ value: SettingsStore.shared.effectivePromptBody(for: .dictate, appBundleID: appInfo.bundleId)
+ )
self.logDictationPromptTrace("Built-in default system prompt (baseline)", value: SettingsStore.defaultSystemPromptText(for: .dictate))
self.logDictationPromptTrace("Final system prompt sent to model", value: systemPrompt)
self.logDictationPromptTrace("Input transcription (Q)", value: inputText)
@@ -1468,7 +1492,10 @@ struct ContentView: View {
}()
DebugLogger.shared.debug("Using app context for AI: app=\(appInfo.name), bundleId=\(appInfo.bundleId), title=\(appInfo.windowTitle)", source: "ContentView")
if self.shouldTracePromptProcessing {
- let selectedProfile = SettingsStore.shared.selectedPromptProfile(for: .dictate)
+ let selectedProfile = SettingsStore.shared.resolvedPromptProfile(
+ for: .dictate,
+ appBundleID: appInfo.bundleId
+ )
let selectedPromptName: String = {
if let profile = selectedProfile {
return profile.name.isEmpty ? "Untitled Prompt" : profile.name
@@ -1476,7 +1503,10 @@ struct ContentView: View {
return "Default Dictate"
}()
self.logDictationPromptTrace("Selected prompt profile", value: selectedPromptName)
- self.logDictationPromptTrace("Prompt body (custom/default body)", value: SettingsStore.shared.effectivePromptBody(for: .dictate))
+ self.logDictationPromptTrace(
+ "Prompt body (custom/default body)",
+ value: SettingsStore.shared.effectivePromptBody(for: .dictate, appBundleID: appInfo.bundleId)
+ )
self.logDictationPromptTrace("Built-in default system prompt (baseline)", value: SettingsStore.defaultSystemPromptText(for: .dictate))
self.logDictationPromptTrace("Prompt override in use", value: (overrideSystemPrompt?.isEmpty == false) ? "yes" : "no")
if let overrideSystemPrompt, !overrideSystemPrompt.isEmpty {
@@ -1636,7 +1666,8 @@ struct ContentView: View {
// If this was a rewrite recording, process the rewrite instead of typing
if wasRewriteMode {
DebugLogger.shared.info("Processing rewrite with instruction: \(transcribedText)", source: "ContentView")
- await self.processRewriteWithVoiceInstruction(transcribedText)
+ let appInfo = self.recordingAppInfo ?? self.getCurrentAppInfo()
+ await self.processRewriteWithVoiceInstruction(transcribedText, appInfo: appInfo)
AnalyticsService.shared.capture(
.transcriptionCompleted,
properties: [
@@ -1968,7 +1999,11 @@ struct ContentView: View {
// MARK: - Rewrite Mode Voice Processing
- private func processRewriteWithVoiceInstruction(_ instruction: String) async {
+ private func processRewriteWithVoiceInstruction(
+ _ instruction: String,
+ appInfo: (name: String, bundleId: String, windowTitle: String)
+ ) async {
+ self.rewriteModeService.setPromptAppBundleID(appInfo.bundleId)
let hasOriginalText = !self.rewriteModeService.originalText.isEmpty
DebugLogger.shared.info("Processing \(hasOriginalText ? "rewrite" : "write/improve") - instruction: '\(instruction)', originalText length: \(self.rewriteModeService.originalText.count)", source: "ContentView")
@@ -2127,6 +2162,8 @@ struct ContentView: View {
"ContentView: startRecording() for model=\(model.displayName), supportsStreaming=\(model.supportsStreaming)",
source: "ContentView"
)
+
+ self.captureRecordingContext()
self.setActiveRecordingMode(.dictate)
// Ensure normal dictation mode is set (command/rewrite modes set their own)
@@ -2138,15 +2175,6 @@ struct ContentView: View {
TranscriptionSoundPlayer.shared.playStartSound()
}
- // Capture the focused target PID BEFORE any overlay/UI changes.
- // Used to restore focus when the user interacts with overlay dropdowns (e.g. prompt selection).
- let focusedPID = TypingService.captureSystemFocusedPID()
- ?? NSWorkspace.shared.frontmostApplication?.processIdentifier
- NotchContentState.shared.recordingTargetPID = focusedPID
-
- let info = self.getCurrentAppInfo()
- self.recordingAppInfo = info
- DebugLogger.shared.debug("Captured recording app context: app=\(info.name), bundleId=\(info.bundleId), title=\(info.windowTitle)", source: "ContentView")
Task {
await self.asr.start()
}
@@ -2441,6 +2469,7 @@ struct ContentView: View {
"ContentView: selected model for dictate hotkey=\(SettingsStore.shared.selectedSpeechModel.displayName)",
source: "ContentView"
)
+ self.captureRecordingContext()
self.setActiveRecordingMode(.dictate)
self.rewriteModeService.clearState()
self.menuBarManager.setOverlayMode(.dictation)
@@ -2460,6 +2489,7 @@ struct ContentView: View {
},
commandModeCallback: {
DebugLogger.shared.info("Command mode triggered", source: "ContentView")
+ self.captureRecordingContext()
// Set flag so stopAndProcessTranscription knows to process as command
self.setActiveRecordingMode(.command)
@@ -2480,6 +2510,8 @@ struct ContentView: View {
}
},
rewriteModeCallback: {
+ self.captureRecordingContext()
+
// Try to capture text first while still in the other app
let captured = self.rewriteModeService.captureSelectedText()
DebugLogger.shared.info("Rewrite mode triggered, text captured: \(captured)", source: "ContentView")
diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swift
index 60294295..60a6b40e 100644
--- a/Sources/Fluid/Persistence/SettingsStore.swift
+++ b/Sources/Fluid/Persistence/SettingsStore.swift
@@ -126,6 +126,82 @@ final class SettingsStore: ObservableObject {
}
}
+ struct AppPromptBinding: Codable, Identifiable, Hashable {
+ let id: String
+ var mode: PromptMode
+ var appBundleID: String
+ var appName: String
+ var promptID: String?
+ var createdAt: Date
+ var updatedAt: Date
+
+ private enum CodingKeys: String, CodingKey {
+ case id
+ case mode
+ case appBundleID
+ case appName
+ case promptID
+ case createdAt
+ case updatedAt
+ }
+
+ init(
+ id: String = UUID().uuidString,
+ mode: PromptMode,
+ appBundleID: String,
+ appName: String,
+ promptID: String?,
+ createdAt: Date = Date(),
+ updatedAt: Date = Date()
+ ) {
+ self.id = id
+ self.mode = mode.normalized
+ self.appBundleID = Self.normalizeBundleID(appBundleID)
+ let trimmedName = appName.trimmingCharacters(in: .whitespacesAndNewlines)
+ self.appName = trimmedName.isEmpty ? self.appBundleID : trimmedName
+ let trimmedPromptID = promptID?.trimmingCharacters(in: .whitespacesAndNewlines)
+ self.promptID = (trimmedPromptID?.isEmpty == true) ? nil : trimmedPromptID
+ self.createdAt = createdAt
+ self.updatedAt = updatedAt
+ }
+
+ init(from decoder: Decoder) throws {
+ let container = try decoder.container(keyedBy: CodingKeys.self)
+ self.id = try container.decode(String.self, forKey: .id)
+ self.mode = try (container.decodeIfPresent(PromptMode.self, forKey: .mode) ?? .dictate).normalized
+ let rawBundleID = try container.decodeIfPresent(String.self, forKey: .appBundleID) ?? ""
+ self.appBundleID = Self.normalizeBundleID(rawBundleID)
+ let rawName = try container.decodeIfPresent(String.self, forKey: .appName) ?? ""
+ let trimmedName = rawName.trimmingCharacters(in: .whitespacesAndNewlines)
+ self.appName = trimmedName.isEmpty ? self.appBundleID : trimmedName
+ let rawPromptID = try container.decodeIfPresent(String.self, forKey: .promptID)
+ let trimmedPromptID = rawPromptID?.trimmingCharacters(in: .whitespacesAndNewlines)
+ self.promptID = (trimmedPromptID?.isEmpty == true) ? nil : trimmedPromptID
+ self.createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) ?? Date()
+ self.updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt) ?? Date()
+ }
+
+ private static func normalizeBundleID(_ value: String) -> String {
+ value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ }
+ }
+
+ enum PromptResolutionSource: String {
+ case appBindingProfile
+ case appBindingDefault
+ case selectedProfile
+ case defaultOverride
+ case builtInDefault
+ }
+
+ struct PromptResolution {
+ let source: PromptResolutionSource
+ let profile: DictationPromptProfile?
+ let appBinding: AppPromptBinding?
+ let promptBody: String
+ let systemPrompt: String
+ }
+
/// User-defined dictation prompt profiles (named system prompts for dictation cleanup).
/// The built-in default prompt is not stored here.
var dictationPromptProfiles: [DictationPromptProfile] {
@@ -148,6 +224,27 @@ final class SettingsStore: ObservableObject {
}
}
+ /// Per-app prompt routing rules keyed by mode + app bundle identifier.
+ /// `promptID == nil` means force Default prompt for that mode in the matched app.
+ var appPromptBindings: [AppPromptBinding] {
+ get {
+ guard let data = self.defaults.data(forKey: Keys.appPromptBindings),
+ let decoded = try? JSONDecoder().decode([AppPromptBinding].self, from: data)
+ else {
+ return []
+ }
+ return decoded
+ }
+ set {
+ objectWillChange.send()
+ if let encoded = try? JSONEncoder().encode(newValue) {
+ self.defaults.set(encoded, forKey: Keys.appPromptBindings)
+ } else {
+ self.defaults.removeObject(forKey: Keys.appPromptBindings)
+ }
+ }
+ }
+
/// Selected dictation prompt profile ID. `nil` means "Default".
var selectedDictationPromptID: String? {
get {
@@ -247,6 +344,92 @@ final class SettingsStore: ObservableObject {
return self.dictationPromptProfiles.first(where: { $0.id == id && $0.mode.normalized == target })
}
+ func appPromptBindings(for mode: PromptMode) -> [AppPromptBinding] {
+ let target = mode.normalized
+ return self.appPromptBindings.filter { $0.mode.normalized == target }
+ }
+
+ func appPromptBinding(for mode: PromptMode, appBundleID: String?) -> AppPromptBinding? {
+ guard let normalizedBundleID = Self.normalizeAppBundleID(appBundleID) else { return nil }
+ let target = mode.normalized
+ return self.appPromptBindings.first {
+ $0.mode.normalized == target &&
+ $0.appBundleID == normalizedBundleID
+ }
+ }
+
+ func hasAppPromptBinding(for mode: PromptMode, appBundleID: String?) -> Bool {
+ self.appPromptBinding(for: mode, appBundleID: appBundleID) != nil
+ }
+
+ func upsertAppPromptBinding(
+ for mode: PromptMode,
+ appBundleID: String,
+ appName: String,
+ promptID: String?
+ ) {
+ guard let normalizedBundleID = Self.normalizeAppBundleID(appBundleID) else { return }
+
+ let normalizedMode = mode.normalized
+ let trimmedName = appName.trimmingCharacters(in: .whitespacesAndNewlines)
+ let resolvedName = trimmedName.isEmpty ? normalizedBundleID : trimmedName
+ let cleanedPromptID = promptID?.trimmingCharacters(in: .whitespacesAndNewlines)
+ let resolvedPromptID = (cleanedPromptID?.isEmpty == true) ? nil : cleanedPromptID
+ let now = Date()
+
+ var bindings = self.appPromptBindings
+ if let idx = bindings.firstIndex(where: {
+ $0.mode.normalized == normalizedMode &&
+ $0.appBundleID == normalizedBundleID
+ }) {
+ bindings[idx].mode = normalizedMode
+ bindings[idx].appName = resolvedName
+ bindings[idx].promptID = resolvedPromptID
+ bindings[idx].updatedAt = now
+ } else {
+ bindings.append(
+ AppPromptBinding(
+ mode: normalizedMode,
+ appBundleID: normalizedBundleID,
+ appName: resolvedName,
+ promptID: resolvedPromptID,
+ createdAt: now,
+ updatedAt: now
+ )
+ )
+ }
+
+ self.appPromptBindings = bindings
+ }
+
+ func removeAppPromptBinding(id: String) {
+ var bindings = self.appPromptBindings
+ bindings.removeAll { $0.id == id }
+ self.appPromptBindings = bindings
+ }
+
+ func removeAppPromptBinding(for mode: PromptMode, appBundleID: String?) {
+ guard let normalizedBundleID = Self.normalizeAppBundleID(appBundleID) else { return }
+ let normalizedMode = mode.normalized
+ var bindings = self.appPromptBindings
+ bindings.removeAll {
+ $0.mode.normalized == normalizedMode &&
+ $0.appBundleID == normalizedBundleID
+ }
+ self.appPromptBindings = bindings
+ }
+
+ /// Re-run prompt/profile normalization after profile mutations.
+ func reconcilePromptStateAfterProfileChanges() {
+ self.normalizePromptSelectionsIfNeeded()
+ }
+
+ private static func normalizeAppBundleID(_ value: String?) -> String? {
+ guard let value else { return nil }
+ let normalized = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ return normalized.isEmpty ? nil : normalized
+ }
+
/// Optional override for the built-in default dictation system prompt.
/// - nil: use the built-in default prompt
/// - empty string: use an empty system prompt
@@ -517,37 +700,104 @@ final class SettingsStore: ObservableObject {
return "\(template)\n\(trimmedContext)"
}
- func effectivePromptBody(for mode: PromptMode) -> String {
- if let profile = self.selectedPromptProfile(for: mode) {
- let body = Self.stripBasePrompt(for: mode, from: profile.prompt)
- if !body.isEmpty {
- return body
+ func promptResolution(for mode: PromptMode, appBundleID: String? = nil) -> PromptResolution {
+ let normalizedMode = mode.normalized
+
+ if let binding = self.appPromptBinding(for: normalizedMode, appBundleID: appBundleID) {
+ if let promptID = binding.promptID,
+ let profile = self.dictationPromptProfiles.first(where: {
+ $0.id == promptID &&
+ $0.mode.normalized == normalizedMode
+ })
+ {
+ let body = Self.stripBasePrompt(for: normalizedMode, from: profile.prompt)
+ if !body.isEmpty {
+ return PromptResolution(
+ source: .appBindingProfile,
+ profile: profile,
+ appBinding: binding,
+ promptBody: body,
+ systemPrompt: Self.combineBasePrompt(for: normalizedMode, with: body)
+ )
+ }
}
- }
- if let override = self.defaultPromptOverride(for: mode) {
- return Self.stripBasePrompt(for: mode, from: override)
+ let fallback = self.defaultPromptResolution(
+ for: normalizedMode,
+ source: .appBindingDefault,
+ appBinding: binding
+ )
+ return fallback
}
- return Self.defaultPromptBodyText(for: mode)
- }
-
- func effectiveSystemPrompt(for mode: PromptMode) -> String {
- if let profile = self.selectedPromptProfile(for: mode) {
- let body = Self.stripBasePrompt(for: mode, from: profile.prompt)
+ if let profile = self.selectedPromptProfile(for: normalizedMode) {
+ let body = Self.stripBasePrompt(for: normalizedMode, from: profile.prompt)
if !body.isEmpty {
- return Self.combineBasePrompt(for: mode, with: body)
+ return PromptResolution(
+ source: .selectedProfile,
+ profile: profile,
+ appBinding: nil,
+ promptBody: body,
+ systemPrompt: Self.combineBasePrompt(for: normalizedMode, with: body)
+ )
}
}
+ return self.defaultPromptResolution(for: normalizedMode, source: .defaultOverride, appBinding: nil)
+ }
+
+ func resolvedPromptProfile(for mode: PromptMode, appBundleID: String? = nil) -> DictationPromptProfile? {
+ self.promptResolution(for: mode, appBundleID: appBundleID).profile
+ }
+
+ func effectivePromptBody(for mode: PromptMode, appBundleID: String? = nil) -> String {
+ self.promptResolution(for: mode, appBundleID: appBundleID).promptBody
+ }
+
+ func effectiveSystemPrompt(for mode: PromptMode, appBundleID: String? = nil) -> String {
+ self.promptResolution(for: mode, appBundleID: appBundleID).systemPrompt
+ }
+
+ func effectivePromptSource(for mode: PromptMode, appBundleID: String? = nil) -> PromptResolutionSource {
+ self.promptResolution(for: mode, appBundleID: appBundleID).source
+ }
+
+ private func defaultPromptResolution(
+ for mode: PromptMode,
+ source: PromptResolutionSource,
+ appBinding: AppPromptBinding?
+ ) -> PromptResolution {
if let override = self.defaultPromptOverride(for: mode) {
let trimmedOverride = override.trimmingCharacters(in: .whitespacesAndNewlines)
- guard !trimmedOverride.isEmpty else { return override }
+ if trimmedOverride.isEmpty {
+ return PromptResolution(
+ source: source,
+ profile: nil,
+ appBinding: appBinding,
+ promptBody: "",
+ systemPrompt: override
+ )
+ }
+
let body = Self.stripBasePrompt(for: mode, from: trimmedOverride)
- return Self.combineBasePrompt(for: mode, with: body)
+ return PromptResolution(
+ source: source,
+ profile: nil,
+ appBinding: appBinding,
+ promptBody: body,
+ systemPrompt: Self.combineBasePrompt(for: mode, with: body)
+ )
}
- return Self.defaultSystemPromptText(for: mode)
+ let defaultBody = Self.defaultPromptBodyText(for: mode)
+ let fallbackSource: PromptResolutionSource = source == .defaultOverride ? .builtInDefault : source
+ return PromptResolution(
+ source: fallbackSource,
+ profile: nil,
+ appBinding: appBinding,
+ promptBody: defaultBody,
+ systemPrompt: Self.combineBasePrompt(for: mode, with: defaultBody)
+ )
}
// MARK: - Model Reasoning Configuration
@@ -1711,6 +1961,72 @@ final class SettingsStore: ObservableObject {
{
self.selectedEditPromptID = nil
}
+
+ let validPromptIDsByMode: [PromptMode: Set<String>] = [
+ .dictate: Set(self.dictationPromptProfiles.filter { $0.mode.normalized == .dictate }.map(\.id)),
+ .edit: Set(self.dictationPromptProfiles.filter { $0.mode.normalized == .edit }.map(\.id)),
+ ]
+
+ var normalizedBindings: [AppPromptBinding] = []
+ var dedupe: [String: AppPromptBinding] = [:]
+ var didMutateBindings = false
+
+ for binding in self.appPromptBindings {
+ let normalizedMode = binding.mode.normalized
+ guard let normalizedBundleID = Self.normalizeAppBundleID(binding.appBundleID) else {
+ didMutateBindings = true
+ continue
+ }
+
+ var cleaned = binding
+ if cleaned.mode != normalizedMode {
+ cleaned.mode = normalizedMode
+ didMutateBindings = true
+ }
+ if cleaned.appBundleID != normalizedBundleID {
+ cleaned.appBundleID = normalizedBundleID
+ didMutateBindings = true
+ }
+
+ let trimmedName = cleaned.appName.trimmingCharacters(in: .whitespacesAndNewlines)
+ let resolvedName = trimmedName.isEmpty ? normalizedBundleID : trimmedName
+ if cleaned.appName != resolvedName {
+ cleaned.appName = resolvedName
+ didMutateBindings = true
+ }
+
+ if let promptID = cleaned.promptID,
+ validPromptIDsByMode[normalizedMode]?.contains(promptID) != true
+ {
+ cleaned.promptID = nil
+ didMutateBindings = true
+ }
+
+ let dedupeKey = "\(normalizedMode.rawValue)|\(normalizedBundleID)"
+ if let existing = dedupe[dedupeKey] {
+ // Keep the most recently updated binding when duplicates exist.
+ if cleaned.updatedAt >= existing.updatedAt {
+ dedupe[dedupeKey] = cleaned
+ }
+ didMutateBindings = true
+ } else {
+ dedupe[dedupeKey] = cleaned
+ }
+ }
+
+ normalizedBindings = Array(dedupe.values).sorted { lhs, rhs in
+ if lhs.mode.normalized != rhs.mode.normalized {
+ return lhs.mode.normalized.rawValue < rhs.mode.normalized.rawValue
+ }
+ if lhs.appName.localizedCaseInsensitiveCompare(rhs.appName) != .orderedSame {
+ return lhs.appName.localizedCaseInsensitiveCompare(rhs.appName) == .orderedAscending
+ }
+ return lhs.appBundleID < rhs.appBundleID
+ }
+
+ if didMutateBindings || normalizedBindings.count != self.appPromptBindings.count {
+ self.appPromptBindings = normalizedBindings
+ }
}
private func migrateOverlayBottomOffsetTo50IfNeeded() {
@@ -2598,6 +2914,7 @@ private extension SettingsStore {
// Dictation Prompt Profiles (multi-prompt system)
static let dictationPromptProfiles = "DictationPromptProfiles"
+ static let appPromptBindings = "AppPromptBindings"
static let selectedDictationPromptID = "SelectedDictationPromptID"
static let selectedEditPromptID = "SelectedEditPromptID"
static let selectedWritePromptID = "SelectedWritePromptID" // legacy fallback key
diff --git a/Sources/Fluid/Services/RewriteModeService.swift b/Sources/Fluid/Services/RewriteModeService.swift
index 3005e075..903619e8 100644
--- a/Sources/Fluid/Services/RewriteModeService.swift
+++ b/Sources/Fluid/Services/RewriteModeService.swift
@@ -12,6 +12,7 @@ final class RewriteModeService: ObservableObject {
@Published var isProcessing = false
@Published var conversationHistory: [Message] = []
@Published var isWriteMode: Bool = false // true = no text selected (write/improve), false = text selected (rewrite)
+ private var promptAppBundleID: String?
private let textSelectionService = TextSelectionService.shared
private let typingService = TypingService()
@@ -180,6 +181,12 @@ final class RewriteModeService: ObservableObject {
self.conversationHistory = []
self.isWriteMode = false
self.thinkingBuffer = []
+ self.promptAppBundleID = nil
+ }
+
+ func setPromptAppBundleID(_ bundleID: String?) {
+ let trimmed = bundleID?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ self.promptAppBundleID = (trimmed?.isEmpty == true) ? nil : trimmed
}
// MARK: - LLM Integration
@@ -187,16 +194,17 @@ final class RewriteModeService: ObservableObject {
private func callLLM(messages: [Message], isWriteMode: Bool) async throws -> String {
let settings = SettingsStore.shared
let promptMode: SettingsStore.PromptMode = .edit
- let selectedProfile = settings.selectedPromptProfile(for: promptMode)
+ let appBundleID = self.promptAppBundleID
+ let selectedProfile = settings.resolvedPromptProfile(for: promptMode, appBundleID: appBundleID)
let selectedPromptName: String = {
if let profile = selectedProfile {
return profile.name.isEmpty ? "Untitled Prompt" : profile.name
}
return "Default Edit"
}()
- let promptBody = settings.effectivePromptBody(for: promptMode)
+ let promptBody = settings.effectivePromptBody(for: promptMode, appBundleID: appBundleID)
let builtInDefaultPrompt = SettingsStore.defaultSystemPromptText(for: promptMode)
- let systemPromptBeforeContext = settings.effectiveSystemPrompt(for: promptMode)
+ let systemPromptBeforeContext = settings.effectiveSystemPrompt(for: promptMode, appBundleID: appBundleID)
// Use global provider/model when linked, otherwise use Edit Mode's independent settings.
let providerID: String = {
if settings.rewriteModeLinkedToGlobal {
@@ -278,7 +286,7 @@ final class RewriteModeService: ObservableObject {
self.appendDiagnosticLog(
"LLM config | writeMode=\(isWriteMode) | linkedToGlobal=\(settings.rewriteModeLinkedToGlobal) | " +
"provider=\(providerID) | model=\(model) | profile=\(selectedPromptName) | " +
- "contextChars=\(contextText.count) | contextInjected=\(!contextBlock.isEmpty)"
+ "contextChars=\(contextText.count) | contextInjected=\(!contextBlock.isEmpty) | appBundle=\(appBundleID ?? "none")"
)
let apiKey = settings.getAPIKey(for: providerID) ?? ""
diff --git a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift
index 20a49e8e..16c62435 100644
--- a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift
+++ b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsView.swift
@@ -41,5 +41,22 @@ struct AIEnhancementSettingsView: View {
Text("Delete “\(self.viewModel.pendingDeletePromptName)”? This cannot be undone.")
}
}
+ .alert(
+ "Couldn't Add App Override",
+ isPresented: Binding(
+ get: { !self.viewModel.appPromptBindingErrorMessage.isEmpty },
+ set: { isPresented in
+ if !isPresented {
+ self.viewModel.appPromptBindingErrorMessage = ""
+ }
+ }
+ )
+ ) {
+ Button("OK", role: .cancel) {
+ self.viewModel.appPromptBindingErrorMessage = ""
+ }
+ } message: {
+ Text(self.viewModel.appPromptBindingErrorMessage)
+ }
}
}
diff --git a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
index f76d6147..6b84d60e 100644
--- a/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
+++ b/Sources/Fluid/UI/AISettings/AIEnhancementSettingsViewModel.swift
@@ -3,6 +3,7 @@ import Combine
import CryptoKit
import Security
import SwiftUI
+import UniformTypeIdentifiers
@MainActor
final class AIEnhancementSettingsViewModel: ObservableObject {
@@ -94,12 +95,21 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
let isBuiltIn: Bool
}
+ struct AppBindingTarget: Identifiable, Hashable {
+ let bundleID: String
+ let name: String
+
+ var id: String { self.bundleID }
+ }
+
@Published var cachedProviderItems: [ProviderItemData] = []
@Published var cachedVerifiedProviderItems: [ProviderItemData] = []
@Published var cachedUnverifiedProviderItems: [ProviderItemData] = []
// Dictation Prompt Profiles UI
@Published var dictationPromptProfiles: [SettingsStore.DictationPromptProfile] = []
+ @Published var appPromptBindings: [SettingsStore.AppPromptBinding] = []
+ @Published var appPromptBindingErrorMessage: String = ""
@Published var selectedDictationPromptID: String? = nil
@Published var selectedEditPromptID: String? = nil
@Published var promptEditorMode: PromptEditorMode? = nil
@@ -140,6 +150,7 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
self.providerAPIKeys = self.settings.providerAPIKeys
self.savedProviders = self.settings.savedProviders
self.dictationPromptProfiles = self.settings.dictationPromptProfiles
+ self.appPromptBindings = self.settings.appPromptBindings
self.selectedDictationPromptID = self.settings.selectedDictationPromptID
self.selectedEditPromptID = self.settings.selectedEditPromptID
@@ -1247,6 +1258,7 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
var profiles = self.settings.dictationPromptProfiles
profiles.removeAll { $0.id == id }
self.settings.dictationPromptProfiles = profiles
+ self.settings.reconcilePromptStateAfterProfileChanges()
// If the deleted profile was active, reset to Default
if let deleted = self.dictationPromptProfiles.first(where: { $0.id == id }),
@@ -1255,7 +1267,8 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
self.settings.setSelectedPromptID(nil, for: deleted.mode)
}
- self.dictationPromptProfiles = profiles
+ self.dictationPromptProfiles = self.settings.dictationPromptProfiles
+ self.appPromptBindings = self.settings.appPromptBindings
self.selectedDictationPromptID = self.settings.selectedDictationPromptID
self.selectedEditPromptID = self.settings.selectedEditPromptID
@@ -1353,12 +1366,210 @@ final class AIEnhancementSettingsViewModel: ObservableObject {
}
self.settings.dictationPromptProfiles = profiles
- self.dictationPromptProfiles = profiles
+ self.settings.reconcilePromptStateAfterProfileChanges()
+ self.dictationPromptProfiles = self.settings.dictationPromptProfiles
+ self.appPromptBindings = self.settings.appPromptBindings
self.selectedDictationPromptID = self.settings.selectedDictationPromptID
self.selectedEditPromptID = self.settings.selectedEditPromptID
self.closePromptEditor()
}
+ func appBindings(for mode: SettingsStore.PromptMode) -> [SettingsStore.AppPromptBinding] {
+ self.appPromptBindings
+ .filter { $0.mode.normalized == mode.normalized }
+ .sorted { lhs, rhs in
+ if lhs.appName.localizedCaseInsensitiveCompare(rhs.appName) != .orderedSame {
+ return lhs.appName.localizedCaseInsensitiveCompare(rhs.appName) == .orderedAscending
+ }
+ return lhs.appBundleID < rhs.appBundleID
+ }
+ }
+
+ func appBindingTargets(for mode: SettingsStore.PromptMode) -> [AppBindingTarget] {
+ let boundBundleIDs = Set(
+ self.appBindings(for: mode)
+ .map { self.normalizedBundleID($0.appBundleID) }
+ )
+
+ var candidatesByBundleID: [String: AppBindingTarget] = [:]
+
+ if let focusedTarget = self.resolveBindingTargetApp() {
+ let normalized = self.normalizedBundleID(focusedTarget.bundleID)
+ if !boundBundleIDs.contains(normalized) {
+ candidatesByBundleID[normalized] = AppBindingTarget(bundleID: normalized, name: focusedTarget.name)
+ }
+ }
+
+ for application in NSWorkspace.shared.runningApplications {
+ guard let target = self.bindingTarget(from: application) else { continue }
+ let normalized = self.normalizedBundleID(target.bundleID)
+ guard !boundBundleIDs.contains(normalized) else { continue }
+ if candidatesByBundleID[normalized] == nil {
+ candidatesByBundleID[normalized] = AppBindingTarget(bundleID: normalized, name: target.name)
+ }
+ }
+
+ return candidatesByBundleID.values.sorted { lhs, rhs in
+ if lhs.name.localizedCaseInsensitiveCompare(rhs.name) != .orderedSame {
+ return lhs.name.localizedCaseInsensitiveCompare(rhs.name) == .orderedAscending
+ }
+ return lhs.bundleID < rhs.bundleID
+ }
+ }
+
+ func addAppPromptBinding(for mode: SettingsStore.PromptMode, appBundleID: String, appName: String) {
+ let normalizedBundleID = self.normalizedBundleID(appBundleID)
+ guard !normalizedBundleID.isEmpty else {
+ self.appPromptBindingErrorMessage = "The selected app is missing a valid bundle identifier."
+ return
+ }
+
+ let trimmedName = appName.trimmingCharacters(in: .whitespacesAndNewlines)
+ let resolvedName = trimmedName.isEmpty ? normalizedBundleID : trimmedName
+ let existingPromptID = self.settings.appPromptBinding(for: mode, appBundleID: normalizedBundleID)?.promptID
+ let resolvedPromptID = existingPromptID ?? self.selectedPromptID(for: mode)
+
+ self.appPromptBindingErrorMessage = ""
+ self.settings.upsertAppPromptBinding(
+ for: mode.normalized,
+ appBundleID: normalizedBundleID,
+ appName: resolvedName,
+ promptID: resolvedPromptID
+ )
+ self.appPromptBindings = self.settings.appPromptBindings
+ }
+
+ func addCurrentAppPromptBinding(for mode: SettingsStore.PromptMode) {
+ guard let target = self.resolveBindingTargetApp() else {
+ self.appPromptBindingErrorMessage = "Could not detect a target app. Focus another app window (outside FluidVoice) and try again."
+ DebugLogger.shared.info(
+ "App prompt binding skipped: unable to resolve non-Fluid target app",
+ source: "AISettingsView"
+ )
+ return
+ }
+ self.addAppPromptBinding(for: mode, appBundleID: target.bundleID, appName: target.name)
+ }
+
+ func addAppPromptBindingFromFilePicker(for mode: SettingsStore.PromptMode) {
+ let panel = NSOpenPanel()
+ panel.title = "Choose Application"
+ panel.message = "Pick an app to add an app-specific prompt override."
+ panel.prompt = "Add App"
+ panel.canChooseFiles = true
+ panel.canChooseDirectories = false
+ panel.allowsMultipleSelection = false
+ panel.treatsFilePackagesAsDirectories = false
+ panel.allowedContentTypes = [.application]
+ panel.directoryURL = URL(fileURLWithPath: "/Applications", isDirectory: true)
+
+ guard panel.runModal() == .OK, let appURL = panel.url else { return }
+
+ guard let target = self.bindingTarget(fromApplicationURL: appURL) else {
+ self.appPromptBindingErrorMessage = "Could not read that app. Please choose a valid .app bundle."
+ return
+ }
+
+ self.addAppPromptBinding(for: mode, appBundleID: target.bundleID, appName: target.name)
+ }
+
+ func removeAppPromptBinding(_ binding: SettingsStore.AppPromptBinding) {
+ self.settings.removeAppPromptBinding(id: binding.id)
+ self.appPromptBindings = self.settings.appPromptBindings
+ }
+
+ func setPromptID(_ promptID: String?, for binding: SettingsStore.AppPromptBinding) {
+ self.settings.upsertAppPromptBinding(
+ for: binding.mode,
+ appBundleID: binding.appBundleID,
+ appName: binding.appName,
+ promptID: promptID
+ )
+ self.appPromptBindings = self.settings.appPromptBindings
+ }
+
+ func promptName(for mode: SettingsStore.PromptMode, promptID: String?) -> String {
+ guard let promptID = promptID,
+ let profile = self.dictationPromptProfiles.first(where: {
+ $0.id == promptID &&
+ $0.mode.normalized == mode.normalized
+ })
+ else {
+ return "Default"
+ }
+
+ let trimmed = profile.name.trimmingCharacters(in: .whitespacesAndNewlines)
+ return trimmed.isEmpty ? "Untitled Prompt" : trimmed
+ }
+
+ private func resolveBindingTargetApp() -> (name: String, bundleID: String)? {
+ if let pid = NotchContentState.shared.recordingTargetPID,
+ let app = NSRunningApplication(processIdentifier: pid),
+ let target = self.bindingTarget(from: app)
+ {
+ return target
+ }
+
+ if let app = ActiveAppMonitor.shared.activeApp,
+ let target = self.bindingTarget(from: app)
+ {
+ return target
+ }
+
+ if let app = NSWorkspace.shared.frontmostApplication,
+ let target = self.bindingTarget(from: app)
+ {
+ return target
+ }
+
+ return nil
+ }
+
+ private func bindingTarget(from application: NSRunningApplication) -> (name: String, bundleID: String)? {
+ guard application.activationPolicy == .regular,
+ let bundleID = application.bundleIdentifier,
+ bundleID != Bundle.main.bundleIdentifier
+ else {
+ return nil
+ }
+
+ let normalizedBundleID = self.normalizedBundleID(bundleID)
+ guard !normalizedBundleID.isEmpty else { return nil }
+
+ let trimmedName = application.localizedName?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
+ let resolvedName = trimmedName.isEmpty ? normalizedBundleID : trimmedName
+ return (name: resolvedName, bundleID: normalizedBundleID)
+ }
+
+ private func bindingTarget(fromApplicationURL appURL: URL) -> (name: String, bundleID: String)? {
+ guard appURL.pathExtension.lowercased() == "app",
+ let appBundle = Bundle(url: appURL),
+ let bundleID = appBundle.bundleIdentifier,
+ bundleID != Bundle.main.bundleIdentifier
+ else {
+ return nil
+ }
+
+ let normalizedBundleID = self.normalizedBundleID(bundleID)
+ guard !normalizedBundleID.isEmpty else { return nil }
+
+ let displayName = (appBundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String)?
+ .trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
+ let bundleName = (appBundle.object(forInfoDictionaryKey: "CFBundleName") as? String)?
+ .trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
+ let fallbackName = appURL.deletingPathExtension().lastPathComponent
+ .trimmingCharacters(in: .whitespacesAndNewlines)
+
+ let resolvedName = [displayName, bundleName, fallbackName]
+ .first(where: { !$0.isEmpty }) ?? normalizedBundleID
+
+ return (name: resolvedName, bundleID: normalizedBundleID)
+ }
+
+ private func normalizedBundleID(_ value: String) -> String {
+ value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ }
+
func selectedPromptID(for mode: SettingsStore.PromptMode) -> String? {
switch mode.normalized {
case .dictate:
diff --git a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift
index a692c6ea..433f4e17 100644
--- a/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift
+++ b/Sources/Fluid/UI/AISettingsView+AdvancedSettings.swift
@@ -231,6 +231,8 @@ extension AIEnhancementSettingsView {
)
}
}
+
+ self.appPromptBindingsSection(mode: mode)
}
.padding(12)
.background(
@@ -354,6 +356,151 @@ extension AIEnhancementSettingsView {
}
}
+ @ViewBuilder
+ private func appPromptBindingsSection(mode: SettingsStore.PromptMode) -> some View {
+ let bindings = self.viewModel.appBindings(for: mode)
+ let appTargets = self.viewModel.appBindingTargets(for: mode)
+ let modeProfiles = self.viewModel.dictationPromptProfiles
+ .filter { $0.mode.normalized == mode.normalized }
+
+ VStack(alignment: .leading, spacing: 8) {
+ HStack(spacing: 8) {
+ Text("App-Based Prompts")
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(self.theme.palette.secondaryText)
+ Spacer()
+
+ Menu {
+ if appTargets.isEmpty {
+ Text("No unassigned running apps")
+ } else {
+ ForEach(appTargets) { target in
+ Button(self.appBindingTargetMenuTitle(target)) {
+ self.viewModel.addAppPromptBinding(
+ for: mode,
+ appBundleID: target.bundleID,
+ appName: target.name
+ )
+ }
+ }
+ }
+
+ Divider()
+
+ Button("Choose App…") {
+ self.viewModel.addAppPromptBindingFromFilePicker(for: mode)
+ }
+ } label: {
+ Text("+ Add App")
+ }
+ .buttonStyle(CompactButtonStyle())
+ .frame(minHeight: 26)
+ }
+
+ Text("Pick from running apps, or choose any .app to add an app not shown in the list.")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ .padding(.horizontal, 4)
+
+ if bindings.isEmpty {
+ Text("No app-specific overrides yet. Add one to route this mode to a different prompt in a specific app.")
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ .padding(.horizontal, 4)
+ } else {
+ ForEach(bindings) { binding in
+ self.appPromptBindingRow(
+ binding: binding,
+ mode: mode,
+ modeProfiles: modeProfiles
+ )
+ }
+ }
+ }
+ .padding(.top, 6)
+ }
+
+ @ViewBuilder
+ private func appPromptBindingRow(
+ binding: SettingsStore.AppPromptBinding,
+ mode: SettingsStore.PromptMode,
+ modeProfiles: [SettingsStore.DictationPromptProfile]
+ ) -> some View {
+ HStack(spacing: 10) {
+ VStack(alignment: .leading, spacing: 2) {
+ Text(binding.appName)
+ .font(.system(size: 12, weight: .semibold))
+ .foregroundStyle(self.theme.palette.primaryText)
+ .lineLimit(1)
+ Text(binding.appBundleID)
+ .font(.caption2)
+ .foregroundStyle(.secondary)
+ .lineLimit(1)
+ }
+
+ Spacer(minLength: 8)
+
+ Menu {
+ Button("Default") {
+ self.viewModel.setPromptID(nil, for: binding)
+ }
+
+ Divider()
+
+ Button("Create New Prompt…") {
+ self.viewModel.openNewPromptEditor(prefillMode: mode)
+ }
+
+ if !modeProfiles.isEmpty {
+ Divider()
+ ForEach(modeProfiles) { profile in
+ Button(profile.name.isEmpty ? "Untitled Prompt" : profile.name) {
+ self.viewModel.setPromptID(profile.id, for: binding)
+ }
+ }
+ }
+ } label: {
+ HStack(spacing: 6) {
+ Text(self.viewModel.promptName(for: mode, promptID: binding.promptID))
+ .font(.caption)
+ .foregroundStyle(self.theme.palette.primaryText)
+ .lineLimit(1)
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 6)
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(self.theme.palette.cardBackground.opacity(0.5))
+ .overlay(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .stroke(self.theme.palette.cardBorder.opacity(0.35), lineWidth: 1)
+ )
+ )
+ }
+ .menuStyle(.borderlessButton)
+ .fixedSize(horizontal: true, vertical: false)
+
+ Button {
+ self.viewModel.removeAppPromptBinding(binding)
+ } label: {
+ Image(systemName: "trash")
+ .font(.system(size: 11, weight: .semibold))
+ .foregroundStyle(.red.opacity(0.9))
+ }
+ .buttonStyle(.plain)
+ .help("Remove app-specific override")
+ }
+ .padding(8)
+ .background(
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .fill(self.theme.palette.cardBackground.opacity(0.35))
+ .overlay(
+ RoundedRectangle(cornerRadius: 10, style: .continuous)
+ .stroke(self.theme.palette.cardBorder.opacity(0.2), lineWidth: 1)
+ )
+ )
+ }
+
private var editModeVerifiedProviders: [AIEnhancementSettingsViewModel.ProviderItemData] {
self.viewModel.cachedVerifiedProviderItems.sorted { lhs, rhs in
lhs.name.localizedCaseInsensitiveCompare(rhs.name) == .orderedAscending
@@ -493,6 +640,13 @@ extension AIEnhancementSettingsView {
return Color.fluidGreen
}
+ private func appBindingTargetMenuTitle(_ target: AIEnhancementSettingsViewModel.AppBindingTarget) -> String {
+ if target.name.caseInsensitiveCompare(target.bundleID) == .orderedSame {
+ return target.bundleID
+ }
+ return "\(target.name) (\(target.bundleID))"
+ }
+
private func modeSymbol(_ mode: SettingsStore.PromptMode) -> String {
switch mode.normalized {
case .dictate:
diff --git a/Sources/Fluid/Views/BottomOverlayView.swift b/Sources/Fluid/Views/BottomOverlayView.swift
index 0bdd8e21..1af3a32c 100644
--- a/Sources/Fluid/Views/BottomOverlayView.swift
+++ b/Sources/Fluid/Views/BottomOverlayView.swift
@@ -1749,9 +1749,24 @@ struct BottomOverlayView: View {
self.activePromptMode != nil
}
+ private var promptResolutionBundleID: String? {
+ self.activeAppMonitor.activeAppBundleID
+ }
+
+ private var isAppPromptOverrideActive: Bool {
+ guard let activePromptMode else { return false }
+ return self.settings.hasAppPromptBinding(
+ for: activePromptMode,
+ appBundleID: self.promptResolutionBundleID
+ )
+ }
+
private var selectedPromptLabel: String {
guard let activePromptMode else { return "N/A" }
- if let profile = self.settings.selectedPromptProfile(for: activePromptMode) {
+ if let profile = self.settings.resolvedPromptProfile(
+ for: activePromptMode,
+ appBundleID: self.promptResolutionBundleID
+ ) {
let name = profile.name.trimmingCharacters(in: .whitespacesAndNewlines)
return name.isEmpty ? "Untitled" : name
}
@@ -1994,6 +2009,17 @@ struct BottomOverlayView: View {
.font(.system(size: self.promptSelectorFontSize, weight: .semibold))
.foregroundStyle(.white.opacity(0.75))
.lineLimit(1)
+ if self.isAppPromptOverrideActive {
+ Text("App")
+ .font(.system(size: max(self.promptSelectorFontSize - 2, 8), weight: .semibold))
+ .foregroundStyle(.white.opacity(0.9))
+ .padding(.horizontal, 5)
+ .padding(.vertical, 1)
+ .background(
+ Capsule()
+ .fill(Color.white.opacity(0.15))
+ )
+ }
Image(systemName: "chevron.up")
.font(.system(size: max(self.promptSelectorFontSize - 1, 8), weight: .semibold))
.foregroundStyle(.white.opacity(0.45))
diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swift
index eb174e2d..34b04ff2 100644
--- a/Sources/Fluid/Views/NotchContentViews.swift
+++ b/Sources/Fluid/Views/NotchContentViews.swift
@@ -270,6 +270,7 @@ struct NotchExpandedView: View {
let audioPublisher: AnyPublisher<CGFloat, Never>
@ObservedObject private var contentState = NotchContentState.shared
@ObservedObject private var settings = SettingsStore.shared
+ @ObservedObject private var activeAppMonitor = ActiveAppMonitor.shared
@Environment(\.theme) private var theme
@State private var showPromptHoverMenu = false
@State private var promptHoverWorkItem: DispatchWorkItem?
@@ -336,9 +337,24 @@ struct NotchExpandedView: View {
self.activePromptMode != nil
}
+ private var promptResolutionBundleID: String? {
+ self.activeAppMonitor.activeAppBundleID
+ }
+
+ private var isAppPromptOverrideActive: Bool {
+ guard let activePromptMode else { return false }
+ return self.settings.hasAppPromptBinding(
+ for: activePromptMode,
+ appBundleID: self.promptResolutionBundleID
+ )
+ }
+
private var selectedPromptLabel: String {
guard let activePromptMode else { return "N/A" }
- if let profile = self.settings.selectedPromptProfile(for: activePromptMode) {
+ if let profile = self.settings.resolvedPromptProfile(
+ for: activePromptMode,
+ appBundleID: self.promptResolutionBundleID
+ ) {
let name = profile.name.trimmingCharacters(in: .whitespacesAndNewlines)
return name.isEmpty ? "Untitled" : name
}
@@ -474,6 +490,17 @@ struct NotchExpandedView: View {
.font(.system(size: 9, weight: .medium))
.foregroundStyle(.white.opacity(0.75))
.lineLimit(1)
+ if self.isAppPromptOverrideActive {
+ Text("App")
+ .font(.system(size: 8, weight: .semibold))
+ .foregroundStyle(.white.opacity(0.9))
+ .padding(.horizontal, 4)
+ .padding(.vertical, 1)
+ .background(
+ Capsule()
+ .fill(Color.white.opacity(0.15))
+ )
+ }
Image(systemName: "chevron.down")
.font(.system(size: 8, weight: .semibold))
.foregroundStyle(.white.opacity(0.45))
diff --git a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
index c9e93417..c0c52c9f 100644
--- a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
+++ b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift
@@ -6,6 +6,12 @@ import XCTest
final class DictationE2ETests: XCTestCase {
private let enableTranscriptionSoundsKey = "EnableTranscriptionSounds"
private let transcriptionStartSoundKey = "TranscriptionStartSound"
+ private let dictationPromptProfilesKey = "DictationPromptProfiles"
+ private let appPromptBindingsKey = "AppPromptBindings"
+ private let selectedDictationPromptIDKey = "SelectedDictationPromptID"
+ private let selectedEditPromptIDKey = "SelectedEditPromptID"
+ private let defaultDictationPromptOverrideKey = "DefaultDictationPromptOverride"
+ private let defaultEditPromptOverrideKey = "DefaultEditPromptOverride"
func testTranscriptionStartSound_noneOptionHasNoFile() {
XCTAssertEqual(SettingsStore.TranscriptionStartSound.none.displayName, "None")
@@ -68,6 +74,109 @@ final class DictationE2ETests: XCTestCase {
)
}
+ func testAppPromptBinding_profileOverridesModeSelection() {
+ self.withPromptSettingsRestored {
+ let settings = SettingsStore.shared
+
+ let global = SettingsStore.DictationPromptProfile(
+ name: "Global Dictate",
+ prompt: "Global dictate prompt",
+ mode: .dictate
+ )
+ let mail = SettingsStore.DictationPromptProfile(
+ name: "Mail Dictate",
+ prompt: "Mail dictate prompt",
+ mode: .dictate
+ )
+
+ settings.dictationPromptProfiles = [global, mail]
+ settings.selectedDictationPromptID = global.id
+ settings.appPromptBindings = [
+ SettingsStore.AppPromptBinding(
+ mode: .dictate,
+ appBundleID: "com.apple.mail",
+ appName: "Mail",
+ promptID: mail.id
+ ),
+ ]
+
+ let mailResolution = settings.promptResolution(for: .dictate, appBundleID: "com.apple.mail")
+ XCTAssertEqual(mailResolution.source, .appBindingProfile)
+ XCTAssertEqual(mailResolution.profile?.id, mail.id)
+
+ let notesResolution = settings.promptResolution(for: .dictate, appBundleID: "com.apple.notes")
+ XCTAssertEqual(notesResolution.source, .selectedProfile)
+ XCTAssertEqual(notesResolution.profile?.id, global.id)
+ }
+ }
+
+ func testAppPromptBinding_defaultFallbackIgnoresGlobalSelection() {
+ self.withPromptSettingsRestored {
+ let settings = SettingsStore.shared
+
+ let global = SettingsStore.DictationPromptProfile(
+ name: "Global Dictate",
+ prompt: "Global dictate prompt",
+ mode: .dictate
+ )
+
+ settings.dictationPromptProfiles = [global]
+ settings.selectedDictationPromptID = global.id
+ settings.appPromptBindings = [
+ SettingsStore.AppPromptBinding(
+ mode: .dictate,
+ appBundleID: "com.apple.mail",
+ appName: "Mail",
+ promptID: nil
+ ),
+ ]
+
+ let mailResolution = settings.promptResolution(for: .dictate, appBundleID: "com.apple.mail")
+ XCTAssertEqual(mailResolution.source, .appBindingDefault)
+ XCTAssertNil(mailResolution.profile)
+ XCTAssertEqual(
+ mailResolution.systemPrompt,
+ SettingsStore.defaultSystemPromptText(for: .dictate)
+ )
+
+ let otherResolution = settings.promptResolution(for: .dictate, appBundleID: "com.apple.notes")
+ XCTAssertEqual(otherResolution.source, .selectedProfile)
+ XCTAssertEqual(otherResolution.profile?.id, global.id)
+ }
+ }
+
+ func testAppPromptBindings_reconcileInvalidPromptAndLegacyMode() {
+ self.withPromptSettingsRestored {
+ let settings = SettingsStore.shared
+
+ let editProfile = SettingsStore.DictationPromptProfile(
+ name: "Edit",
+ prompt: "Edit prompt",
+ mode: .edit
+ )
+ settings.dictationPromptProfiles = [editProfile]
+ settings.appPromptBindings = [
+ SettingsStore.AppPromptBinding(
+ mode: .rewrite,
+ appBundleID: " COM.APPLE.SAFARI ",
+ appName: "Safari",
+ promptID: "missing-profile"
+ ),
+ ]
+
+ settings.reconcilePromptStateAfterProfileChanges()
+
+ guard let binding = settings.appPromptBindings.first else {
+ XCTFail("Expected normalized app prompt binding")
+ return
+ }
+
+ XCTAssertEqual(binding.mode, .edit)
+ XCTAssertEqual(binding.appBundleID, "com.apple.safari")
+ XCTAssertNil(binding.promptID)
+ }
+ }
+
private static func modelDirectoryForRun() -> URL {
// Use a stable path on CI so GitHub Actions cache can speed up runs.
if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" ||
@@ -121,4 +230,18 @@ final class DictationE2ETests: XCTestCase {
run()
}
+
+ private func withPromptSettingsRestored(run: () -> Void) {
+ self.withRestoredDefaults(
+ keys: [
+ self.dictationPromptProfilesKey,
+ self.appPromptBindingsKey,
+ self.selectedDictationPromptIDKey,
+ self.selectedEditPromptIDKey,
+ self.defaultDictationPromptOverrideKey,
+ self.defaultEditPromptOverrideKey,
+ ],
+ run: run
+ )
+ }
}