From 675f7880fe09c1b13b92ae61b9a6184c12c001cc Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 6 May 2026 17:16:59 +0900 Subject: [PATCH] fix(team-mode): resolve caller tmux window target Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../resolve-caller-tmux-session.test.ts | 15 +++++++------ .../resolve-caller-tmux-session.ts | 21 +++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.test.ts b/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.test.ts index 492b6847c..9a3b6b9c3 100644 --- a/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.test.ts +++ b/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.test.ts @@ -18,7 +18,7 @@ function shellSingleQuote(value: string): string { return `'${value.split("'").join(`'"'"'`)}'` } -async function createTmuxStub(options: { stdout: string; exitCode: number }): Promise { +async function createTmuxStub(options: { stdout: string; windowStdout?: string; exitCode: number }): Promise { const directory = await mkdtemp(path.join(tmpdir(), "resolve-caller-tmux-session-")) temporaryDirectories.push(directory) @@ -27,7 +27,7 @@ async function createTmuxStub(options: { stdout: string; exitCode: number }): Pr const script = [ "#!/bin/sh", `printf '%s\\n' \"$@\" >> ${shellSingleQuote(logPath)}`, - `printf '%s' ${shellSingleQuote(options.stdout)}`, + `case "$*" in *'#{session_name}:#{window_index}'*) printf '%s' ${shellSingleQuote(options.windowStdout ?? options.stdout)} ;; *) printf '%s' ${shellSingleQuote(options.stdout)} ;; esac`, `exit ${options.exitCode}`, ].join("\n") @@ -67,17 +67,20 @@ describe("resolveCallerTmuxSession", () => { expect(await readLogLines(stub.logPath)).toHaveLength(0) }) - test("#given TMUX_PANE=%42 and display returns '$7' #when resolve runs #then returns { sessionId: '$7' }", async () => { + test("#given TMUX_PANE=%42 and display returns session and window #when resolve runs #then returns caller tmux target", async () => { // given process.env.TMUX_PANE = "%42" - const stub = await createTmuxStub({ stdout: "$7", exitCode: 0 }) + const stub = await createTmuxStub({ stdout: "$7", windowStdout: "test-session:0", exitCode: 0 }) // when const result = await resolveCallerTmuxSession(stub.tmuxPath) // then - expect(result).toEqual({ sessionId: "$7" }) - expect(await readLogLines(stub.logPath)).toEqual(["display", "-p", "-F", "#{session_id}", "-t", "%42"]) + expect(result).toEqual({ sessionId: "$7", paneId: "%42", windowTarget: "test-session:0" }) + expect(await readLogLines(stub.logPath)).toEqual([ + "display", "-p", "-F", "#{session_id}", "-t", "%42", + "display", "-p", "-F", "#{session_name}:#{window_index}", "-t", "%42", + ]) }) test("#given TMUX_PANE=%42 and display returns 'garbage' #when resolve runs #then returns null", async () => { diff --git a/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.ts b/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.ts index 3766a5d99..3d7cb7e6f 100644 --- a/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.ts +++ b/src/features/team-mode/team-layout-tmux/resolve-caller-tmux-session.ts @@ -2,9 +2,12 @@ import { runTmuxCommand } from "../../../shared/tmux" type ResolvedCallerTmuxSession = { sessionId: string + paneId: string + windowTarget: string } const TMUX_SESSION_ID_PATTERN = /^\$[0-9]+$/ +const TMUX_WINDOW_TARGET_PATTERN = /^[^:]+:[0-9]+$/ export async function resolveCallerTmuxSession(tmuxPath: string): Promise { const callerPaneId = process.env.TMUX_PANE @@ -12,15 +15,25 @@ export async function resolveCallerTmuxSession(tmuxPath: string): Promise