diff --git a/CHANGELOG.md b/CHANGELOG.md index edac459d..28fcab1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.64.2] - 2026-10-31 + +### Fixed + +- **Ctrl-C works at the shell again after a session that ends without cleaning up.** + Claude Code switches on xterm `modifyOtherKeys` and focus reports in the container. + When the session ended without its own reset reaching the terminal, both stayed on: + Ctrl-C reached bash as `ESC[27;5;99~`, so it typed `;5;99~` into the line instead of + cancelling it, and focus changes printed `^[[I` and `^[[O`. The restore `dl` writes + after every session now also turns off both modes + ([#718](https://github.com/blooop/devlaunch/pull/718)). + ## [0.64.1] - 2026-10-30 ### Added diff --git a/README.md b/README.md index 9af628eb..e73eeddf 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ one argument instead of a clone, a config file and a build command. [![GitHub pull-requests merged](https://badgen.net/github/merged-prs/blooop/devlaunch)](https://github.com/blooop/devlaunch/pulls?q=is%3Amerged) [![GitHub release](https://img.shields.io/github/release/blooop/devlaunch.svg)](https://GitHub.com/blooop/devlaunch/releases/) [![PyPI](https://img.shields.io/pypi/v/devlaunch)](https://pypi.org/project/devlaunch/) -[![Conda](https://img.shields.io/badge/conda-v0.64.1-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch) +[![Conda](https://img.shields.io/badge/conda-v0.64.2-brightgreen?logo=anaconda)](https://prefix.dev/channels/blooop/packages/devlaunch) [![License](https://img.shields.io/github/license/blooop/devlaunch)](https://opensource.org/license/mit/) [![Platform](https://img.shields.io/badge/platform-linux--64-blue)](https://github.com/blooop/devlaunch/releases) [![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh) @@ -350,7 +350,7 @@ clone, and [docs/cleanup.md](docs/cleanup.md) says what it carries one past and ```bash $ dl --version -dl 0.64.1 +dl 0.64.2 ``` `--devcontainer ` picks a non-default `devcontainer.json`. A bare name means diff --git a/docs/cli.md b/docs/cli.md index 96de7d7f..19f8acca 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -272,8 +272,8 @@ one of devpod's ssh-config context options names a different one. Set ### Getting the terminal back when a session dies badly A terminal is not only a stream. A full screen program switches modes on in the -emulator for its own use, the kitty keyboard protocol, bracketed paste, mouse -reporting, the alternate screen, and is expected to switch them off again on the +emulator for its own use, the kitty keyboard protocol, xterm `modifyOtherKeys`, +focus reports, bracketed paste, mouse reporting, the alternate screen, and is expected to switch them off again on the way out. One that is killed never gets the chance, and those modes live in your terminal rather than in the connection, so nothing between the program and the glass undoes them. @@ -285,22 +285,28 @@ broken: ssh restores the tty settings on its way out, so the shell still echoes and still edits lines, and yet Ctrl-C does nothing and ordinary keys print things like `9;133u` at the prompt. Those are kitty keyboard protocol key reports, still switched on. Ctrl-C is one of them, arriving as an escape sequence instead of as -the byte that raises SIGINT. +the byte that raises SIGINT. Claude Code also switches on xterm `modifyOtherKeys` +and focus reports. With those left on, Ctrl-C at the prompt types `;5;99~` into +the line instead of cancelling it, so the next Enter runs that line, and each +focus change prints `^[[I` or `^[[O`. `dl` is the last process holding that terminal, so `dl` repairs it. Every session ends with a short restore written to the terminal, over either transport, and the interrupt handler writes the same thing before it exits. It goes out after a clean session too, because ssh's exit status does not say whether the far end cleaned up after itself. That costs nothing: every sequence in it is chosen for -doing nothing when the mode it names is already off. The one obvious candidate +doing nothing when the mode it names is already off. `ESC [ > 4 m` is a reset, +not an off: it puts `modifyOtherKeys` back to your terminal's configured value. +The one obvious candidate that is not, `ESC [ ? 1049 l`, is left out on purpose, because it restores the cursor as well as the screen and would scramble the display on every ordinary exit. Nothing is written when `dl`'s own output is not a terminal, so `dl -- ls > files.txt` keeps its output free of escape sequences. If you are ever left with a -wrecked terminal some other way, `printf '\033[4m\033[?1004l'` undoes `modifyOtherKeys` and focus +reports, and `reset` undoes everything. ### `--rm`: the throwaway workspace diff --git a/rust/Cargo.lock b/rust/Cargo.lock index b12c09d0..95594668 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -438,7 +438,7 @@ dependencies = [ [[package]] name = "devlaunch-core" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-runner", "devlaunch-test-support", @@ -458,7 +458,7 @@ dependencies = [ [[package]] name = "devlaunch-runner" -version = "0.64.1" +version = "0.64.2" dependencies = [ "libc", "portable-pty", @@ -467,7 +467,7 @@ dependencies = [ [[package]] name = "devlaunch-test-support" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-runner", "serde", @@ -509,7 +509,7 @@ dependencies = [ [[package]] name = "dl" -version = "0.64.1" +version = "0.64.2" dependencies = [ "clap", "devlaunch-core", @@ -527,7 +527,7 @@ dependencies = [ [[package]] name = "dla" -version = "0.64.1" +version = "0.64.2" dependencies = [ "devlaunch-test-support", "dl", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index ec058417..6d4e13a9 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -11,7 +11,7 @@ members = [ # The single source of the version (docs/rust-rewrite-plan.md: cutover ships # 0.1.0, version read from Cargo.toml). [workspace.package] -version = "0.64.1" +version = "0.64.2" edition = "2024" license = "MIT" repository = "https://github.com/blooop/devlaunch" diff --git a/rust/devlaunch-runner/src/terminal.rs b/rust/devlaunch-runner/src/terminal.rs index 1bc6d01f..2c7bca61 100644 --- a/rust/devlaunch-runner/src/terminal.rs +++ b/rust/devlaunch-runner/src/terminal.rs @@ -3,8 +3,8 @@ //! A child that inherits this process's stdout inherits the *terminal*, and a //! terminal is not only a stream: it holds modes an application switches on for //! its own use and is expected to switch off again on the way out. The kitty -//! keyboard protocol, bracketed paste, mouse reporting and the alternate screen -//! all live in the emulator, not in the connection and not in the tty driver, so +//! keyboard protocol, xterm `modifyOtherKeys`, focus reports, bracketed paste, +//! mouse reporting and the alternate screen all live in the emulator, not in the connection and not in the tty driver, so //! nothing between the application and the glass undoes them. //! //! An application that exits normally undoes its own. One that is *killed* never @@ -28,7 +28,12 @@ //! badly, because "did the remote die without cleaning up" is not a question //! ssh's exit status answers. That is only safe if a restore costs nothing when //! there was nothing to restore, so each sequence below was chosen for being -//! idempotent, and the one obvious candidate that is *not* was left out: +//! idempotent, and the one obvious candidate that is *not* was left out. One +//! sequence is a reset rather than an off: `ESC [ > 4 m` puts `modifyOtherKeys` +//! back to the terminal's configured value, so it also undoes a value the user's +//! own shell set before `dl` ran. +//! +//! The candidate left out: //! //! `ESC [ ? 1049 l` is the usual way to leave the alternate screen, and it is //! also a DECRC — xterm's ctlseqs defines it as "Use Normal Screen Buffer and @@ -71,6 +76,15 @@ /// child of `dl`'s is reaped is that child's, and nobody else's to lose. A /// caller that violates the contract is damaged by the first pop and no further /// by the rest, which is why counting them buys nothing. +/// - `ESC [ > 4 m` — xterm `modifyOtherKeys` back to its initial value, which is +/// off unless the user's resources say otherwise. Claude Code switches it on, +/// and while it is on Ctrl-C arrives as `ESC [ 27;5;99 ~`, not as the byte that +/// raises SIGINT. Readline takes the `ESC [ 27` and types `;5;99~` into the +/// line, so Ctrl-C at the prompt no longer cancels it, and the next Enter runs +/// it: reported on 2026-10-31 as `dla ;5;99~;5;99~;5;99~;5;99~exit`. `ESC [ > 4 ; 0 m` +/// would force it to 0 and lose a user's `modifyOtherKeys: 1`. +/// - `ESC [ ? 1004 l` — focus reports off, or each focus change prints `^[[I` or +/// `^[[O` at the prompt. Claude Code switches this on as well. /// - `ESC [ ? 2004 l` — bracketed paste off, or a paste arrives wrapped in /// `ESC [ 200 ~` markers that the shell prints instead of obeying. /// - `ESC [ ? 1000 l` … `ESC [ ? 1015 l` — the mouse tracking modes and the three @@ -81,6 +95,8 @@ pub(crate) const RESTORE: &str = concat!( "\x1b[?1047l", // alternate screen off "\x1b[4m", // xterm modifyOtherKeys reset + "\x1b[?1004l", // focus reports off "\x1b[?2004l", // bracketed paste off "\x1b[?1000l", // mouse: normal tracking off "\x1b[?1002l", // mouse: button-event tracking off @@ -182,6 +198,18 @@ mod tests { ); } + /// The 2026-10-31 report: Claude Code died holding `modifyOtherKeys` and focus + /// reports, and Ctrl-C at the shell typed `;5;99~` into the line instead of + /// cancelling it. + #[test] + fn the_restore_turns_off_the_modes_claude_code_switches_on() { + assert!(RESTORE.contains("\x1b[>4m"), "modifyOtherKeys: {RESTORE:?}"); + assert!( + RESTORE.contains("\x1b[?1004l"), + "focus reports: {RESTORE:?}" + ); + } + /// Every sequence is a complete CSI: introducer, parameters, final byte. A /// truncated one would be printed as text by the terminal, which is the /// failure this module exists to prevent. diff --git a/rust/dl/tests/terminal.rs b/rust/dl/tests/terminal.rs index 3508f9aa..aed4346b 100644 --- a/rust/dl/tests/terminal.rs +++ b/rust/dl/tests/terminal.rs @@ -38,6 +38,14 @@ const MAIN: &str = "devlaunch-main-3j1t"; const KEYBOARD_PUSH: &str = "\x1b[>1u"; const KEYBOARD_POP: &str = "\x1b[