Background (root cause)
pi's fullscreen (alt-screen) TUI enables mouse capture (SGR mouse ?1000h ?1002h ?1006h).
When mouse capture is enabled, Windows Terminal forwards right-click events to the application and no longer pastes itself. Therefore right-click paste
in fullscreen is implemented by pi itself—but pi-tui's TuiAltScreen.handleRightClickPaste() has a
process.platform !== "win32" hard gate:
- Native Windows (pwsh7): platform=win32 → gate passes → paste works normally.
- WSL: platform=linux → gate blocks → right-click event is swallowed by pi but handled by no one → dead click.
- regular mode: no mouse capture → WT pastes itself → both environments work normally.
Upstream (earendil-works/pi, issue #10345 same root cause)not yet fixed, npm 1.1.0 still has the gate.
This skill is a temporary workaround; it is overwritten as soon as pi is updated, so it must be re-run.
Fix method
Remove the process.platform !== "win32" gate, keep the TERM_PROGRAM === "vscode" exception:
// 旧
if (!this.onRightClickPaste ||
process.platform !== "win32" || ...
// 新(删门禁版)
if (!this.onRightClickPaste ||
process.env.TERM_PROGRAM?.toLowerCase() === "vscode" || ...
Why removing the gate is safe and complete (this fix was confirmed by research):
handleRightClickPasteispassively triggered—pi only receives it when the terminal forwards the right-click event to the application.- Terminals fall into three categories:forward right-click but do not paste themselves(Windows Terminal, WezTerm, VTE/GNOME Terminal,
kitty by default) → pi pastes (correct);do not forward right-click(macOS Terminal.app) → the event never reaches
pi, no side effect;forward + paste themselves→ the only double-paste risk, currently empirically only the VS Code integrated terminal
(issue #8186), already covered by the
TERM_PROGRAM=vscodeexception. - The whitelist approach (identifying by
WT_SESSION/TERM_PROGRAM=wezterm) cannot cover SSH remote scenarios and has been abandoned; early WT_SESSION-based patches are automatically converged by this script to the gate-removal version.
Execution
bash <skill 目录>/patch.sh
patch.sh uses BASH_SOURCE[0] to locate its own directory (= the skill directory), independent of cwd; on this machine the distributed skill directory is usually ~/.agents/skills/pi-rightclick-paste-patch/, in the repository it is skills/self/pi-rightclick-paste-patch/。
The script only handles the latest version installed by mise(three-part version directories, excluding latest/1.x aliases),
and patches two locations:
dist/bundle/chunks/chunk-*.js(the entry the user actually runs, bundle inlines pi-tui code)@earendil-works/pi-tui/dist/tui-alt-screen.js(non-bundle run path, skipped if missing)
Idempotent: if the target file already contains the patch marker (handleRightClickPaste followed directly by a process.env.TERM_PROGRAM check, i.e. the gate-removal form) then skip; if it contains the old win32 gate or an earlier WT_SESSION version patch thenconvergeto the gate-removal version; if the fragment does not match, warn and continue processing the remaining targets (failure is determined by the verification section).
Completion criteria
- Script outputs the latest version number and
already patched (skip)orpatched; - Verification section outputs
ok: bundle chunks clean of the old gate, no FAIL; - After restarting pi, right-click in WT's WSL fullscreen mode and the clipboard content can be pasted (manual confirmation).
- Regression driver:
/tmp/pi-clip-probe/rightclick-loop.mjs(fake terminal + SGR right-click event, assert that non-vscode terminals trigger on right-click).
Restore and notes
- Pre-patchoriginalfile backup is in
backups/directory, named<basename>.orig(e.g.chunk-OTL6MGLJ.js.orig、tui-alt-screen.js.orig); keep only the first pristine copy, do not overwrite. Can be restored when needed, but after restoring you need to rerun this script to reapply the patch. mise upgrade, losing the patch afterwards is expected; just rerun this skill; the script will relocate based on the latest version (chunk filenames are content hashes and may change after updates; the script locates by content matching, not hardcoded filenames).- Once upstream is fixed (issue #10345 or a new PR merged, npm release published), this skill should be discontinued.