Skip to content

Commit 7dfedbe

Browse files
committed
mcp(fix[window_tools]): Split from specified pane, not active pane
why: When `pane_id` was provided to `split_window`, the code resolved the pane but then called `window.split()`, which delegates to `self.active_pane.split()`. If the specified pane was not the active pane, the wrong pane got split. what: - Call `pane.split()` directly when `pane_id` is provided - Move direction validation before the pane/window branch - Keep `window.split()` path for window-level targeting
1 parent 215c8b4 commit 7dfedbe

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/libtmux/mcp/tools/window_tools.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ def split_window(
125125
"""
126126
server = _get_server(socket_name=socket_name)
127127

128-
if pane_id is not None:
129-
pane = _resolve_pane(server, pane_id=pane_id)
130-
window = pane.window
131-
else:
132-
window = _resolve_window(
133-
server,
134-
window_id=window_id,
135-
window_index=window_index,
136-
session_name=session_name,
137-
)
138-
139128
pane_dir: PaneDirection | None = None
140129
if direction is not None:
141130
pane_dir = _DIRECTION_MAP.get(direction.lower())
@@ -146,12 +135,27 @@ def split_window(
146135
msg = f"Invalid direction: {direction!r}. Valid: {valid}"
147136
raise ToolError(msg)
148137

149-
new_pane = window.split(
150-
direction=pane_dir,
151-
size=size,
152-
start_directory=start_directory,
153-
shell=shell,
154-
)
138+
if pane_id is not None:
139+
pane = _resolve_pane(server, pane_id=pane_id)
140+
new_pane = pane.split(
141+
direction=pane_dir,
142+
size=size,
143+
start_directory=start_directory,
144+
shell=shell,
145+
)
146+
else:
147+
window = _resolve_window(
148+
server,
149+
window_id=window_id,
150+
window_index=window_index,
151+
session_name=session_name,
152+
)
153+
new_pane = window.split(
154+
direction=pane_dir,
155+
size=size,
156+
start_directory=start_directory,
157+
shell=shell,
158+
)
155159
return json.dumps(_serialize_pane(new_pane))
156160

157161

0 commit comments

Comments
 (0)