PasteService-Hardening: Terminal-Paste, Clipboard-Restore, CopyQ-Cleanup - #38
Merged
Conversation
xdotool-based active-window detection lets PasteService send Ctrl+Shift+V in known terminal emulators instead of Ctrl+V, which is usually a no-op or copy there. X11-only, falls back cleanly on Wayland/missing xdotool. First step of the PasteService-Hardening roadmap item (clipboard-restore and CopyQ-cleanup follow separately).
Reads the previous clipboard content before writing the transcribed text, then restores it once ydotool has delivered the paste keystrokes. Wayland (wl-paste) and X11 (xclip -o) are supported; restore is best-effort and never blocks the main paste path on failure. Only applies to the autopaste flow — clipboard_only() leaves the transcribed text in the clipboard for manual paste, as intended. Second step of the PasteService-Hardening roadmap item (CopyQ cleanup follows separately).
Popen() without check=True never raises CalledProcessError, so that branch in _read_clipboard() was dead. Also documents why paste() and _ydotool_paste() each sleep _PASTE_DELAY for a different reason, so a future reader doesn't mistake it for an accidental double wait.
After a successful autopaste-and-restore cycle, remove the transient pasted text from CopyQ's clipboard history if CopyQ is installed and its top entry matches exactly (trailing newline tolerant). No hard CopyQ dependency: missing binary, timeouts, and other errors are swallowed and never affect the main paste path. Third and final step of the PasteService-Hardening roadmap item.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f95e72eeb6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
test_force_autopaste_override_enables_ydotool asserted call_count==3 but only mocked subprocess.run, not the subprocess.Popen used by _read_clipboard(). On a desktop with wl-copy/xclip actually installed this reads the real clipboard and the assertion holds; in CI, where those binaries are absent, _read_clipboard() returns None and the restore step never fires a subprocess.run call, dropping the count to 2 and failing the build. Mock _read_clipboard() directly so the test no longer depends on whichever clipboard tooling happens to be present on the runner.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the roadmap item "PasteService-Hardening — Clipboard-Restore + Terminal-Paste" (Project #10), in three independently reviewed commits.
Test plan
pytest tests/test_paste_service.py tests/test_state_machine.py -v— all greenpytest -q(full suite) — 356 passed, 70 skipped, 0 failed