github / github/copilot-cli

Ctrl+H (delete previous character) is misinterpreted as Ctrl+Backspace (delete word) under WSL2 due to WT_SESSION leaking from Windows Terminal

オープン 初心者向け
#4,328 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

area:input-keyboard area:platform-windows
主要言語
Shell
スター
11.2k
フォーク
1.9k
平均マージ
14時間 16分
マージ済み PR(30日)
6

説明

Description

/help documents ctrl+h as "delete previous character", but under WSL2 it instead deletes the whole previous word (i.e. behaves like ctrl+w/Ctrl+Backspace).

Environment
  • Copilot CLI version: 1.0.78-2
  • Platform: WSL2 (Linux ... 6.18.33.2-microsoft-standard-WSL2), Windows Terminal as host, plain xterm-256color inside (issue reproduces both inside and outside tmux)
  • WSLENV=WT_SESSION:WT_PROFILE_ID: (default WSL/Windows Terminal integration), so WT_SESSION is present in the WSL shell environment even though the CLI is not running as a native Windows process
Root cause

In the bundled app.js, the raw-byte key decoder special-cases byte 0x08 (\b) — which is exactly what Ctrl+H sends — as Ctrl+Backspace when a ctrlHIsCtrlBackspace flag is set:

function ZDe(t, e=!1) {
  return t.length!==1 ? null
    : t==="\r" ? {code:"return"}
    : ...
    : t==="\b" && e ? {code:"backspace", ctrl:!0}   // <-- Ctrl+H reinterpreted as Ctrl+Backspace
    : t==="\b" || t==="\x7F" ? {code:"backspace"}
    : ...
}

The flag is computed once at startup:

reader = new ope({ ctrlHIsCtrlBackspace: fSt() })

function Nk() { return !RA() && !process.env.TMUX && !process.env.STY }
function fSt() { return process.platform==="win32" && Nk() || !!process.env.WT_SESSION }

The intent is reasonable on native Windows (Windows Console/Windows Terminal apps can't distinguish a literal Ctrl+H keypress from Ctrl+Backspace, since both produce byte 0x08), so trading away the Ctrl+H binding there makes sense. However, the || !!process.env.WT_SESSION clause has no accompanying process.platform==="win32" check, so it also fires under WSL2, where WT_SESSION is forwarded into the Linux environment by WSLENV for terminal-integration purposes, but the CLI is actually running in a normal Linux pty where Ctrl+H and Ctrl+Backspace are distinguishable. This causes a false positive: the workaround for a Windows-only ambiguity ends up breaking a real, distinguishable keybinding on WSL.

This also affects users in the reverse scenario, if WT_SESSION is otherwise present in the environment (e.g. propagated through SSH or subshells) on non-Windows platforms.

Steps to reproduce
  1. Launch Copilot CLI inside WSL2 under Windows Terminal (default WSLENV integration).
  2. Type some text, then press Ctrl+H.
  3. Expected: deletes one character before the cursor (per /help).
  4. Actual: deletes the entire previous word.
Suggested fix

Gate the WT_SESSION check on process.platform === "win32" as well, e.g.:

function fSt() {
  return process.platform === "win32" && (Nk() || !!process.env.WT_SESSION);
}

or otherwise detect WSL (e.g. via /proc/version containing "microsoft" or process.platform !== "win32") and skip the ctrlHIsCtrlBackspace heuristic in that case.

Workaround

unset WT_SESSION before launching copilot restores the documented Ctrl+H behavior.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

バンドルされた app.js の fSt() とその reader の初期化から始め、ZDe() を確認する前に、WT_SESSION と process.platform が ctrlHIsCtrlBackspace にどのように影響するかを検証します。WT_SESSION を設定した場合と設定しない場合の WSL2 で再現します。Ctrl+H で 1 文字が削除され、ネイティブな Windows の動作が変わらない状態になれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, linux, node.js
領域
cli, operating-systems
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
78/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。