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
feat(debug): trace clipboard writes and restoration metadata
altic-devdaa0f2d347d9
diff --git a/Sources/Fluid/Services/ClipboardService.swift b/Sources/Fluid/Services/ClipboardService.swiftindex e26cfc2c..5ab8185c 100644--- a/Sources/Fluid/Services/ClipboardService.swift+++ b/Sources/Fluid/Services/ClipboardService.swift@@ -7,15 +7,17 @@ enum ClipboardService {/// - Parameter text: The text to copy to clipboard/// - Returns: Boolean indicating success or failure@discardableResult- static func copyToClipboard(_ text: String) -> Bool {+ static func copyToClipboard(_ text: String, file: String = #fileID, line: Int = #line) -> Bool {guard !text.isEmpty else {DebugLogger.shared.debug("Attempted to copy empty text to clipboard, skipping", source: "ClipboardService")return false}let pasteboard = NSPasteboard.general+ ClipboardAudit.record("copy_begin", pasteboard: pasteboard, file: file, line: line)pasteboard.clearContents()let success = pasteboard.setString(text, forType: .string)+ ClipboardAudit.record("copy_end", pasteboard: pasteboard, detail: "success=\(success) chars=\(text.count)", file: file, line: line)if success {DebugLogger.shared.info("Copied \(text.count) characters to clipboard", source: "ClipboardService")@@ -33,3 +35,36 @@ enum ClipboardService {return pasteboard.string(forType: .string)}}++/// Event-bound metadata only: no clipboard text, URLs, data payloads, or polling.+enum ClipboardAudit {+ static func metadata(for pasteboard: NSPasteboard) -> String {+ let before = pasteboard.changeCount+ let items = pasteboard.pasteboardItems ?? []+ let types = items.first?.types ?? []+ let after = pasteboard.changeCount+ let transient = types.contains(NSPasteboard.PasteboardType("org.nspasteboard.TransientType"))+ let concealed = types.contains(NSPasteboard.PasteboardType("org.nspasteboard.ConcealedType"))+ let generated = types.contains(NSPasteboard.PasteboardType("org.nspasteboard.AutoGeneratedType"))+ let chromium = types.contains(NSPasteboard.PasteboardType("org.chromium.source-url"))+ return "changeCount=\(after) stable=\(before == after) items=\(items.count) firstTypes=\(types.count) " ++ "text=\(types.contains(.string)) transient=\(transient) concealed=\(concealed) generated=\(generated) html=\(types.contains(.html)) chromium=\(chromium)"+ }++ static func record(+ _ event: String,+ pasteboard: NSPasteboard = .general,+ detail: String = "",+ file: String = #fileID,+ line: Int = #line+ ) {+ let startedAt = ProcessInfo.processInfo.systemUptime+ let metadata = self.metadata(for: pasteboard)+ let auditMs = (ProcessInfo.processInfo.systemUptime - startedAt) * 1000+ DebugLogger.shared.benchmark(+ "CLIPBOARD_AUDIT",+ message: "schema=1 pid=\(ProcessInfo.processInfo.processIdentifier) event=\(event) caller=\(file):\(line) \(detail) \(metadata) auditMs=\(auditMs)",+ source: "ClipboardAudit"+ )+ }+}diff --git a/Sources/Fluid/Services/PasteDeliveryCoordinator.swift b/Sources/Fluid/Services/PasteDeliveryCoordinator.swiftindex 3d71276c..f02ecc6a 100644--- a/Sources/Fluid/Services/PasteDeliveryCoordinator.swift+++ b/Sources/Fluid/Services/PasteDeliveryCoordinator.swift@@ -61,6 +61,11 @@ protocol PasteboardManaging: AnyObject {func isOwned(sessionID: String, expectedText: String) -> Boolfunc restore(_ snapshot: PasteboardSnapshot) -> Boolfunc restoreTemporarySnapshot(_ snapshot: PasteboardSnapshot, sessionID: String, expectedText: String) -> Bool+ func recordAudit(_ event: String, detail: String)+}++extension PasteboardManaging {+ func recordAudit(_: String, detail _: String) {}}@MainActor@@ -92,6 +97,10 @@ final class SystemPasteboardManager: PasteboardManaging {self.pasteboard = pasteboard}+ func recordAudit(_ event: String, detail: String) {+ ClipboardAudit.record(event, pasteboard: self.pasteboard, detail: detail)+ }+func captureSnapshot() -> PasteboardSnapshot? {let startedAt = ProcessInfo.processInfo.systemUptimefor attempt in 1...2 {@@ -194,9 +203,11 @@ final class SystemPasteboardManager: PasteboardManaging {return false}+ ClipboardAudit.record("temporary_begin", pasteboard: self.pasteboard, detail: "session=\(sessionID)")let clearedChangeCount = self.pasteboard.clearContents()self.temporaryWrite = (sessionID, clearedChangeCount)let didWrite = self.pasteboard.writeObjects([item])+ ClipboardAudit.record("temporary_end", pasteboard: self.pasteboard, detail: "session=\(sessionID) success=\(didWrite)")if self.hasTemporaryText(sessionID: sessionID, expectedText: text) {self.temporaryWrite = (sessionID, self.pasteboard.changeCount)return didWrite@@ -208,11 +219,15 @@ final class SystemPasteboardManager: PasteboardManaging {let item = NSPasteboardItem()guard item.setString(text, forType: .string) else { return false }+ ClipboardAudit.record("intentional_begin", pasteboard: self.pasteboard)self.pasteboard.clearContents()- return self.pasteboard.writeObjects([item]) && self.pasteboard.string(forType: .string) == text+ let success = self.pasteboard.writeObjects([item]) && self.pasteboard.string(forType: .string) == text+ ClipboardAudit.record("intentional_end", pasteboard: self.pasteboard, detail: "success=\(success)")+ return success}func isOwned(sessionID: String, expectedText: String) -> Bool {+ ClipboardAudit.record("ownership_check", pasteboard: self.pasteboard, detail: "session=\(sessionID) expectedChangeCount=\(self.temporaryWrite?.changeCount ?? -1)")guard let temporaryWrite,temporaryWrite.sessionID == sessionID,temporaryWrite.changeCount == self.pasteboard.changeCount@@ -268,6 +283,8 @@ final class SystemPasteboardManager: PasteboardManaging {items.append(item)}+ ClipboardAudit.record("restore_begin", pasteboard: self.pasteboard, detail: "expectedChangeCount=\(changeCount ?? -1)")+ defer { ClipboardAudit.record("restore_end", pasteboard: self.pasteboard) }// Recheck after preparing representations; a newer external copy wins.if let changeCount, self.pasteboard.changeCount != changeCount { return false }self.pasteboard.clearContents()@@ -557,6 +574,7 @@ final class PasteDeliveryCoordinator {preserveTranscriptOnClipboard: Bool,onCommandPosted: ((TimeInterval) -> Void)? = nil) async -> TextDeliveryResult {+ self.log("delivery_policy keepTranscript=\(preserveTranscriptOnClipboard) auditSchema=1")let slotRequestedAt = ProcessInfo.processInfo.systemUptimeawait self.acquireDeliverySlot()let slotAcquiredAt = ProcessInfo.processInfo.systemUptime@@ -587,12 +605,15 @@ final class PasteDeliveryCoordinator {"clipboard_write generation=\(generation) elapsedMs=\(Self.elapsedMs(since: writeStartedAt))")- guard await self.commandPoster.postGlobalPasteCommand() else {+ self.pasteboard.recordAudit("command_before", detail: "session=\(sessionID)")+ let commandPosted = await self.commandPoster.postGlobalPasteCommand()+ let commandPostedAt = ProcessInfo.processInfo.systemUptime+ self.pasteboard.recordAudit("command_after", detail: "session=\(sessionID) success=\(commandPosted)")+ guard commandPosted else {self.restoreAfterFailure(originalSnapshot, sessionID: sessionID, expectedText: text, generation: generation, reason: "paste_command_failed")self.log("delivery_failed generation=\(generation) reason=paste_command_failed")return .recoverableFailure(.pasteCommandFailed)}- let commandPostedAt = ProcessInfo.processInfo.systemUptimeonCommandPosted?(commandPostedAt)self.log(diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swiftindex 1113023c..b46bf5eb 100644--- a/Sources/Fluid/Services/TypingService.swift+++ b/Sources/Fluid/Services/TypingService.swift@@ -469,6 +469,7 @@ final class TypingService {self.bench("request chars=\(text.count) mode=\(mode.rawValue) autocompleteSteps=\(plan.steps.count) preferredPID=\(preferredTargetPID.map { String($0) } ?? "nil") textReadyAgeMs=\(textReadyAge.map { String($0) } ?? "nil")")+ self.bench("clipboard_policy keepTranscript=\(preserveTranscriptOnClipboard)")self.log("[TypingService] ENTRY: typeTextInstantly called with text length: \(text.count)")self.log("[TypingService] Text preview: \"\(String(text.prefix(100)))\"")diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swiftindex 29596ccc..65dadf6c 100644--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift@@ -678,8 +678,10 @@ struct MeetingTranscriptionView: View {}private func copyToClipboard(_ text: String) {+ ClipboardAudit.record("ui_copy_begin")NSPasteboard.general.clearContents()NSPasteboard.general.setString(text, forType: .string)+ ClipboardAudit.record("ui_copy_end")withAnimation {self.showingCopyConfirmation = truediff --git a/Sources/Fluid/UI/TranscriptionHistoryView.swift b/Sources/Fluid/UI/TranscriptionHistoryView.swiftindex b8fc3e85..c3a4a488 100644--- a/Sources/Fluid/UI/TranscriptionHistoryView.swift+++ b/Sources/Fluid/UI/TranscriptionHistoryView.swift@@ -568,8 +568,10 @@ struct TranscriptionHistoryView: View {}private func copyToClipboard(_ text: String) {+ ClipboardAudit.record("ui_copy_begin")NSPasteboard.general.clearContents()NSPasteboard.general.setString(text, forType: .string)+ ClipboardAudit.record("ui_copy_end")}private func openFeedbackReport(for entry: TranscriptionHistoryEntry) {diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swiftindex fceede03..7b77abcb 100644--- a/Sources/Fluid/UI/WelcomeView.swift+++ b/Sources/Fluid/UI/WelcomeView.swift@@ -278,8 +278,10 @@ struct WelcomeView: View {if !self.asr.finalText.isEmpty {HStack(spacing: 8) {Button {+ ClipboardAudit.record("ui_copy_begin")NSPasteboard.general.clearContents()NSPasteboard.general.setString(self.asr.finalText, forType: .string)+ ClipboardAudit.record("ui_copy_end")} label: {Label("Copy Text", systemImage: "doc.on.doc")}diff --git a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swiftindex 088df1e1..9d9cd2bc 100644--- a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift+++ b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift@@ -82,6 +82,23 @@ final class TypingServiceTransientPasteboardTests: XCTestCase {XCTAssertEqual(item.string(forType: .string), "hello world")}+ func testClipboardAuditReportsMarkersWithoutReadingOrChangingPayloads() throws {+ let pasteboard = self.makePasteboard()+ defer { pasteboard.releaseGlobally() }+ let secret = "private-dictation-example-https://private.invalid"+ XCTAssertTrue(SystemPasteboardManager(pasteboard: pasteboard).writeTemporaryText(secret, sessionID: "audit-test"))+ let changeCount = pasteboard.changeCount+ let metadata = ClipboardAudit.metadata(for: pasteboard)+ XCTAssertTrue(metadata.contains("concealed=true"))+ XCTAssertTrue(metadata.contains("transient=true"))+ XCTAssertTrue(metadata.contains("generated=true"))+ XCTAssertTrue(metadata.contains("stable=true"))+ XCTAssertFalse(metadata.contains(secret))+ XCTAssertFalse(metadata.contains("audit-test"))+ XCTAssertEqual(pasteboard.changeCount, changeCount)+ XCTAssertEqual(pasteboard.string(forType: .string), secret)+ }+func testRecoveryActivationDoesNotRaiseAllWindowsOfTargetApp() {// Issue #748: recovery must NOT raise every window of the target app.let options = TypingService.recoveryActivationOptionsdiff --git a/scripts/trace_clipboard.swift b/scripts/trace_clipboard.swiftnew file mode 100644index 00000000..d6b6eecc--- /dev/null+++ b/scripts/trace_clipboard.swift@@ -0,0 +1,47 @@+// Read-only, bounded diagnostic. Run with: xcrun swift scripts/trace_clipboard.swift 120+// Logs changes only. Foreground app is context, not proof of which process wrote.+import AppKit+import Foundation++let duration = min(600, max(1, Double(CommandLine.arguments.dropFirst().first ?? "120") ?? 120))+let deadline = ProcessInfo.processInfo.systemUptime + duration+let board = NSPasteboard.general+var previousCount = -1+let formatter = ISO8601DateFormatter()+formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]+while ProcessInfo.processInfo.systemUptime < deadline {+ autoreleasepool {+ let changeCount = board.changeCount+ guard changeCount != previousCount else { return }+ previousCount = changeCount+ let items = board.pasteboardItems ?? []+ let types = items.first?.types ?? []+ func has(_ name: String) -> Bool { types.contains(NSPasteboard.PasteboardType(name)) }+ // Classify known public origins without writing full source URLs to the log.+ let sourceURL = board.string(forType: NSPasteboard.PasteboardType("org.chromium.source-url"))+ let host = sourceURL.flatMap { URL(string: $0)?.host }+ let knownHost = host ?? ""+ let origin = ["claude.ai", "chatgpt.com", "chat.openai.com"].contains(knownHost) ? knownHost : "other-or-unavailable"+ let event: [String: Any] = [+ "wallTime": formatter.string(from: Date()),+ "uptime": ProcessInfo.processInfo.systemUptime,+ "changeCount": changeCount,+ "stable": changeCount == board.changeCount,+ "items": items.count,+ "text": types.contains(.string),+ "html": types.contains(.html),+ "transient": has("org.nspasteboard.TransientType"),+ "concealed": has("org.nspasteboard.ConcealedType"),+ "generated": has("org.nspasteboard.AutoGeneratedType"),+ "chromium": has("org.chromium.internal.source-rfh-token") || has("org.chromium.source-url"),+ "knownOrigin": origin,+ "frontmostAppNotWriter": NSWorkspace.shared.frontmostApplication?.bundleIdentifier ?? "unknown",+ ]+ if let data = try? JSONSerialization.data(withJSONObject: event, options: [.sortedKeys]),+ let line = String(data: data, encoding: .utf8) {+ print(line)+ fflush(stdout)+ }+ }+ Thread.sleep(forTimeInterval: 0.05)+}