Improve auto-send reliability with AX-based paste detection - #616
gulliversgames wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="VoiceInk/CursorPaster.swift">
<violation number="1" location="VoiceInk/CursorPaster.swift:116">
P1: Auto-send polling runs in an uncancelled detached task and can fire Enter into a different app/field after focus changes.</violation>
<violation number="2" location="VoiceInk/CursorPaster.swift:126">
P2: Paste completion detection is too weak (`contains(prefix)`), allowing false positives (including empty-text immediate match) and premature auto-send before paste is actually applied.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| guard autoSendKey.isEnabled else { return } | ||
|
|
||
| // Poll the focused element's AXValue to detect when paste has landed. | ||
| Task.detached { |
There was a problem hiding this comment.
P1: Auto-send polling runs in an uncancelled detached task and can fire Enter into a different app/field after focus changes.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At VoiceInk/CursorPaster.swift, line 116:
<comment>Auto-send polling runs in an uncancelled detached task and can fire Enter into a different app/field after focus changes.</comment>
<file context>
@@ -100,6 +100,66 @@ class CursorPaster {
+ guard autoSendKey.isEnabled else { return }
+
+ // Poll the focused element's AXValue to detect when paste has landed.
+ Task.detached {
+ let maxWait: TimeInterval = 3.0
+ let pollInterval: UInt64 = 50_000_000 // 50ms
</file context>
Three fixes for paste and auto-send reliability: 1. Dismiss recorder before pasting so macOS refocuses the target window first (was: paste fired while recorder was still visible, causing keystrokes to miss the target window) 2. Capture auto-send key before dismissing, since dismissMiniRecorder clears the Power Mode configuration (was: autoSendKey was always nil by the time it was read) 3. Replace fixed auto-send delay with AX-based paste detection: polls the focused text field's AXValue every 50ms (up to 3s) to confirm the paste has landed before sending the auto-send keystroke. This works reliably for any text length — short messages send immediately, long pastes wait until the app has finished processing. Falls back to a timeout for apps where AXValue isn't readable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a4f417e to
6dc3f12
Compare
Code reviewFound 3 issues:
VoiceInk/VoiceInk/Whisper/TranscriptionPipeline.swift Lines 184 to 193 in 6dc3f12
VoiceInk/VoiceInk/CursorPaster.swift Lines 134 to 142 in 6dc3f12
VoiceInk/VoiceInk/CursorPaster.swift Lines 148 to 153 in 6dc3f12 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Summary
dismissMiniRecorderclears the Power Mode config, so the auto-send key was always nil by the time it was readAXValueevery 50ms (up to 3s) to confirm the paste has landed before sending the auto-send keystroke. Works for any text length. Falls back to a timeout for apps whereAXValueisn't readable (e.g. some web apps)Problem
The auto-send feature (sending Enter/Shift+Enter/Cmd+Enter after paste) was unreliable:
Test plan
🤖 Generated with Claude Code
Summary by cubic
Improves auto-send reliability by dismissing the recorder before paste, capturing the auto-send key earlier, and using AX-based detection to wait for the paste to land. Prevents misdirected keystrokes and sends Enter only after text appears.
Written for commit 6dc3f12. Summary will update on new commits.