Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(selection): Fix Wayland capture blockers and model-side edit failures
Chadpihaec4716fe2a94
diff --git a/resources/linux-fast-paste.c b/resources/linux-fast-paste.cindex 8bed41d28..d2d9ebfdd 100644--- a/resources/linux-fast-paste.c+++ b/resources/linux-fast-paste.c@@ -494,6 +494,22 @@ static int print_atspi_selection(void) {AtspiAccessible *app = NULL;AtspiAccessible *win = find_active_atspi_window(&app);int pid = app ? atspi_active_pid(app) : 0;++ /* Replacement text typed back into a shell executes on its embedded+ * newlines, so a terminal's selection is reported as no selection and the+ * command falls back to standalone dictation. */+ if (pid && app) {+ char *app_name = atspi_accessible_get_name(app, NULL);+ int terminal = app_name ? is_terminal(app_name) : 0;+ g_free(app_name);+ if (terminal) {+ if (win) g_object_unref(win);+ g_object_unref(app);+ printf("ATSPI_NONE %d\n", pid);+ return 0;+ }+ }+AtspiAccessible *focused = win ? find_focused_text(win, 0) : NULL;if (win) g_object_unref(win);if (app) g_object_unref(app);diff --git a/src/helpers/selectionManager.js b/src/helpers/selectionManager.jsindex be83d7124..69906b19c 100644--- a/src/helpers/selectionManager.js+++ b/src/helpers/selectionManager.js@@ -9,6 +9,11 @@ const MAX_SELECTION_EDIT_CODE_POINTS = 6000;// re-verifying — the accepted cost of failing closed rather than pasting blind.const COPY_TIMEOUT_MS = 1200;const CLIPBOARD_POLL_MS = 20;+// The AT-SPI desktop scan takes ~600ms idle on KDE Wayland and over 1s under+// recording-start load or through Flatpak's xdg-dbus-proxy; a tighter timeout+// kills the probe with the target already on stdout and the capture falls+// back to standalone dictation, pasting over the selection.+const ATSPI_TARGET_TIMEOUT_MS = 2000;// Editors that copy the whole current line when Ctrl+C lands with an empty// selection (VS Code's editor.emptySelectionClipboard, Scintilla, JetBrains,@@ -95,37 +100,54 @@ class SelectionManager {this.now = now;this.sessions = new Map();this.lastTarget = null;+ this._captureTargetPromise = null;}async captureTarget() {if (this.platform === "darwin") return;this.lastTarget = null;+ const probe = this._probeTarget();+ this._captureTargetPromise = probe;+ const target = await probe;+ // A newer toggle press may have started its own probe while this one ran;+ // only the latest probe's result may land in lastTarget.+ if (this._captureTargetPromise === probe) {+ this.lastTarget = target;+ this._captureTargetPromise = null;+ }+ }++ async _probeTarget() {if (this.platform === "win32") {const binary = this.clipboardManager.resolveWindowsFastPasteBinary();- if (!binary) {- this.lastTarget = null;- return;- }+ if (!binary) return null;const result = await runSpawn(binary, ["--detect-only"], { timeout: 700 });const match = result.stdout.match(/TARGET\s+(\S+)/);- this.lastTarget =- result.success && match- ? {- kind: "win-hwnd",- id: match[1],- windowClass: result.stdout.match(/^WINDOW_CLASS (.+)$/m)?.[1]?.trim() || null,- exeName: result.stdout.match(/^EXE_NAME (.+)$/m)?.[1]?.trim() || null,- }- : null;- return;+ return result.success && match+ ? {+ kind: "win-hwnd",+ id: match[1],+ windowClass: result.stdout.match(/^WINDOW_CLASS (.+)$/m)?.[1]?.trim() || null,+ exeName: result.stdout.match(/^EXE_NAME (.+)$/m)?.[1]?.trim() || null,+ }+ : null;}if (this.platform === "linux") {- this.lastTarget = await this._getLinuxTarget();+ return this._getLinuxTarget();}+ return null;}async captureSelectedText() {return this.clipboardManager.runClipboardOperation(async () => {+ // captureTarget() fires on every toggle press, including stop. Fast+ // cloud transcription can get here before the stop-press probe lands+ // (~1s on Wayland AT-SPI), when lastTarget is still nulled from the+ // probe's start — so wait for the latest probe instead of failing with+ // target_unavailable while the answer is in flight.+ while (this._captureTargetPromise) {+ await this._captureTargetPromise;+ }this._pruneSessions();const expectedTarget =this.platform === "darwin" && this.textEditMonitor?.lastTargetPid@@ -262,6 +284,13 @@ class SelectionManager {if (expectedTarget && !this._sameTarget(target, expectedTarget)) {return { status: "target_changed" };}+ // Replacement text typed into a shell executes on its embedded newlines,+ // so a terminal selection reads as no selection and the command keeps the+ // pre-selection-editing behavior of typing at the cursor. AT-SPI targets+ // carry no window class here; the helper binary applies the same rule.+ if (this.clipboardManager.isLinuxTerminalWindowClass?.(target.windowClass)) {+ return { status: "none", target };+ }const binary = this.clipboardManager.resolveLinuxFastPasteBinary();if (target.kind === "atspi-pid") {@@ -404,7 +433,9 @@ class SelectionManager {async _getLinuxAtspiTarget() {const binary = this.clipboardManager.resolveLinuxFastPasteBinary();if (!binary) return null;- const result = await runSpawn(binary, ["--atspi-target"], { timeout: 700 });+ const result = await runSpawn(binary, ["--atspi-target"], {+ timeout: ATSPI_TARGET_TIMEOUT_MS,+ });const match = result.stdout.match(/^TARGET\s+ATSPI\s+(\d+)$/m);return result.success && match ? { kind: "atspi-pid", id: match[1] } : null;}diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.tsindex fbcfd1638..7ab83c198 100644--- a/src/services/ReasoningService.ts+++ b/src/services/ReasoningService.ts@@ -213,9 +213,11 @@ class ReasoningService extends BaseReasoningService {// gpt-oss defaults to medium reasoning effort; low cuts hidden reasoning// tokens (latency) and the tendency to answer the transcript instead of- // cleaning it. applyThinkingSuppression still wins when thinking is- // disabled by the user.- if (isCleanup && model.includes("gpt-oss")) {+ // cleaning it. Selection edits need it too: at higher efforts Groq's+ // gpt-oss can leave the whole reply in the reasoning channel and return+ // whitespace content, failing the edit. applyThinkingSuppression still+ // wins when thinking is disabled by the user.+ if ((isCleanup || config.requireCompleteOutput) && model.includes("gpt-oss")) {requestBody.reasoning_effort = "low";}diff --git a/test/helpers/selectionManager.test.js b/test/helpers/selectionManager.test.jsindex 647556e70..0fa7e5c05 100644--- a/test/helpers/selectionManager.test.js+++ b/test/helpers/selectionManager.test.js@@ -247,6 +247,77 @@ test("does not overwrite a clipboard value copied while capture is in flight", aassert.equal(writes.at(-1), "new user clipboard");});+// captureTarget() fires on every toggle press, including stop, and the AT-SPI+// probe can outlive fast cloud transcription. Reading lastTarget before the+// stop-press probe lands must wait for it instead of failing closed.+test("captureSelectedText awaits an in-flight target probe before reading lastTarget", async () => {+ const clipboardManager = { runClipboardOperation: (operation) => operation() };+ const manager = new SelectionManager({+ clipboardManager,+ textEditMonitor: {},+ platform: "linux",+ now: () => 1000,+ });+ let resolveProbe;+ manager._getLinuxTarget = () => new Promise((resolve) => (resolveProbe = resolve));+ manager._readCurrentSelection = async (expectedTarget) =>+ expectedTarget+ ? { status: "selected", text: "picked", target: expectedTarget }+ : { status: "unavailable", code: "target_unavailable" };++ const probe = manager.captureTarget();+ const read = manager.captureSelectedText();+ resolveProbe({ kind: "atspi-pid", id: "2524568" });+ await probe;++ const result = await read;+ assert.equal(result.status, "selected");+ assert.equal(result.text, "picked");+});++test("a superseded probe never overwrites the newer probe's target", async () => {+ const clipboardManager = { runClipboardOperation: (operation) => operation() };+ const manager = new SelectionManager({+ clipboardManager,+ textEditMonitor: {},+ platform: "linux",+ now: () => 1000,+ });+ const resolvers = [];+ manager._getLinuxTarget = () => new Promise((resolve) => resolvers.push(resolve));++ const first = manager.captureTarget();+ const second = manager.captureTarget();+ resolvers[1]({ kind: "atspi-pid", id: "2" });+ await second;+ resolvers[0]({ kind: "atspi-pid", id: "1" });+ await first;++ assert.deepEqual(manager.lastTarget, { kind: "atspi-pid", id: "2" });+});++// Replacement text typed into a shell executes on its embedded newlines, so a+// terminal target must read as no selection (standalone dictation), not as an+// editable selection.+test("a terminal target reads as no selection", async () => {+ const clipboardManager = {+ runClipboardOperation: (operation) => operation(),+ isLinuxTerminalWindowClass: (windowClass) => windowClass === "konsole",+ };+ const manager = new SelectionManager({+ clipboardManager,+ textEditMonitor: {},+ platform: "linux",+ now: () => 1000,+ });+ const terminalTarget = { kind: "kde-window", id: "9", windowClass: "konsole" };+ manager._getLinuxTarget = async () => terminalTarget;++ const result = await manager._readLinuxSelection(null);+ assert.equal(result.status, "none");+ assert.deepEqual(result.target, terminalTarget);+});+test("empty replacement output is rejected without consuming a paste", async () => {const { manager, pastes } = makeHarness({ selections: ["original"] });const capture = await manager.captureSelectedText();