Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(pty): make tmux set-option target parse so mouse scroll works (CHOO-1403) (#18)

Louis Amaudruz3ce4e8e1605a
diff --git a/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.test.ts b/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.test.ts
index 1888fa708..bfbe6e4e6 100644
--- a/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.test.ts
@@ -16,9 +16,12 @@ describe('buildTmuxShellLine', () => {
expect(result).toContain(
'tmux -u new-session -d -s \\"agent-session\\" \\"exec /bin/zsh -il\\"'
);
- expect(result).toContain('tmux set-option -t \\"=agent-session\\" mouse on');
- expect(result).toContain('tmux set-option -t \\"=agent-session\\" history-limit 100000');
- expect(result).toContain('tmux set-option -t \\"=agent-session\\" window-size latest');
+ // set-option needs the trailing colon: it rejects a bare `=name` target
+ // ("no such session"), silently disabling mouse scroll on tmux terminals
+ // (CHOO-1403). `=name:` keeps the exact match and is accepted.
+ expect(result).toContain('tmux set-option -t \\"=agent-session:\\" mouse on');
+ expect(result).toContain('tmux set-option -t \\"=agent-session:\\" history-limit 100000');
+ expect(result).toContain('tmux set-option -t \\"=agent-session:\\" window-size latest');
expect(result).toContain('tmux -u attach-session -t \\"=agent-session\\"');
expect(result.indexOf('mouse on')).toBeLessThan(result.indexOf('attach-session'));
expect(result.indexOf('history-limit')).toBeLessThan(result.indexOf('attach-session'));
diff --git a/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.ts b/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.ts
index 6f7e04c06..fa63796c2 100644
--- a/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/pty/tmux-session-name.ts
@@ -22,6 +22,10 @@ export function buildTmuxShellLine(
): string {
const quotedName = JSON.stringify(sessionName);
const quotedTarget = JSON.stringify(exactTmuxTarget(sessionName));
+ // set-option/show-options reject a bare `=name` target ("no such session"),
+ // unlike has-session/attach-session. A trailing colon makes them parse it as
+ // a session target while keeping the `=` exact-match guarantee.
+ const quotedOptionTarget = JSON.stringify(`${exactTmuxTarget(sessionName)}:`);
const quotedCmd = JSON.stringify(commandLine);
// Set the agent's env on the tmux session itself with `-e`. A new pane inherits
// the tmux SERVER's environment, NOT that of the shell invoking `new-session`,
@@ -40,14 +44,14 @@ export function buildTmuxShellLine(
// non-UTF-8 locale and mangles multibyte glyphs like Nerd-font/box-drawing characters.
const checkExists = `tmux has-session -t ${quotedTarget} 2>/dev/null`;
const newSession = `tmux -u new-session ${newSessionFlags} -s ${quotedName} ${quotedCmd}`;
- const enableMouse = `tmux set-option -t ${quotedTarget} mouse on 2>/dev/null || true`;
- const setHistoryLimit = `tmux set-option -t ${quotedTarget} history-limit ${TMUX_HISTORY_LIMIT} 2>/dev/null || true`;
+ const enableMouse = `tmux set-option -t ${quotedOptionTarget} mouse on 2>/dev/null || true`;
+ const setHistoryLimit = `tmux set-option -t ${quotedOptionTarget} history-limit ${TMUX_HISTORY_LIMIT} 2>/dev/null || true`;
// With multiple clients (different laptops) attached to the same session, tmux
// otherwise clamps the shared window to the SMALLEST client, cramping the active
// user whenever an idle viewer with a smaller terminal is attached. `latest`
// sizes the window to the most-recently-active client instead, so a passive
// viewer no longer constrains whoever is actually driving the session.
- const setWindowSize = `tmux set-option -t ${quotedTarget} window-size latest 2>/dev/null || true`;
+ const setWindowSize = `tmux set-option -t ${quotedOptionTarget} window-size latest 2>/dev/null || true`;
const configure = `(${enableMouse}) && (${setHistoryLimit}) && (${setWindowSize})`;
const attach = `tmux -u attach-session -t ${quotedTarget}`;
const script = `(${checkExists} || ${newSession}) && ${configure} && ${attach}`;