fix(tmux): stop nested prefix keys and TUI Alt+digits from moving other clients

Docker and owned-remote tmux servers kept the stock prefix table, so Ctrl+Q
then )/(/s/w/L switch-client'd the inner client onto a sibling. Those create
chains now leave only C-q send-prefix.

codeman tui bound M-1..M-9 in the server-wide root table. The keys stay, but
switch-client runs only for the attaching client (tty plus a one-shot pid).
A browser tab's Esc-then-digit no longer jumps sessions, and a killed TUI
leaves a binding that matches no live client.

Co-authored-by: DDT <1786035110@qq.com>
This commit is contained in:
DDTandDDT committed 2026-10-23 07:41:46 +00:00
1 parent 002de32a08
commit daeea54495
14 files changed
+728 -62

No files matched your search

+32 -5
View File
@@ -27,11 +27,18 @@
* per tmux server in practice.
*
* That tolerance is server-wide like every key table: while such an alias is
* bound, a browser tab's client can detach itself with it too. The same goes
* for the `root` keys an attach claims, including Alt+1..9, which run
* `switch-client`: a tab that receives Esc then a digit within tmux's
* `escape-time` is moved onto another session for as long as those bindings
* exist. Leaving `root` alone keeps the attach working; it does not close that.
* bound, a browser tab's client can detach itself with it too. F1 in `root`
* is the same kind of way out. Alt+1..9 are not: `codeman tui` binds those
* through `if-shell -F` so `switch-client` runs only for the TUI's own client
* (see `bindSwitchKey` in src/tui/tui-client.ts). This file still does not
* touch `root`.
*
* Docker cases and owned remote sessions run a second tmux (`-L codeman-docker`,
* `-L codeman-remote`) with `prefix C-q`. That server is not this socket, so
* the reset above never sees it, and its stock prefix table still switches
* the inner client. `nestedPrefixTableResetCommands` is the same reduction,
* appended to those create chains. A non-owned remote attach joins another
* Codeman's `-L codeman` and must not run it.
*
* @module tmux-prefix-table
*/
@@ -43,6 +50,26 @@ import { shellescape } from './remote-hosts.js';
/** tmux's stock prefix, used when `show-options` cannot be read. */
const DEFAULT_PREFIX = 'C-b';
/**
* Prefix on the dedicated tmux inside a Docker case and an owned remote
* session. Codeman's own socket keeps the user's prefix; these nested servers
* always use C-q so it does not collide with the outer prefix.
*/
export const NESTED_TMUX_PREFIX = 'C-q';
/**
* Commands that reduce a nested tmux's prefix table to `C-q send-prefix`.
*
* Joined with `\;` onto the `new-session` that creates the server
* (`buildRemoteLaunchCommand`, `buildDockerLaunchCommand`). No `tmux` binary
* and no `-g`: the table is server-global, which is what we want on these
* dedicated sockets and nowhere else. Put them BEFORE `remain-on-exit failed`
* so a remote tmux that rejects `failed` does not drop the reduction.
*/
export function nestedPrefixTableResetCommands(): readonly [string, string] {
return ['unbind-key -a -T prefix', `bind-key -T prefix ${NESTED_TMUX_PREFIX} send-prefix`];
}
/** One `list-keys -T prefix` line: key and command. */
const PREFIX_LINE = /^bind-key\s+(?:-\S+\s+)*?-T\s+prefix\s+(\S+)\s+(.+)$/;