Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion agent_cli/dev/terminals/tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,21 @@ def _create_session(
session_name: str,
) -> TerminalHandle | None:
"""Create a detached tmux session and return its initial pane handle."""
return self._spawn_target(
handle = self._spawn_target(
["tmux", "new-session", "-d", "-s", session_name],
path=path,
command=command,
tab_name=tab_name,
session_name=session_name,
)
if handle is None:
return None
subprocess.run(
["tmux", "set-option", "-t", session_name, "renumber-windows", "off"], # noqa: S607
capture_output=True,
check=False,
)
return handle

def _spawn_target(
self,
Expand Down
29 changes: 29 additions & 0 deletions tests/dev/test_terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ def test_open_in_session_creates_detached_session_when_missing(self) -> None:
session_name="repo-session",
)

def test_create_session_disables_renumber_windows(self) -> None:
"""New tmux sessions disable window renumbering."""
terminal = Tmux()
mock_handle = MagicMock(handle="%42", session_name="repo-session")
with (
patch.object(terminal, "_spawn_target", return_value=mock_handle) as mock_spawn,
patch("subprocess.run") as mock_run,
):
handle = terminal._create_session(
Path("/some/path"),
"echo hello",
"test",
session_name="repo-session",
)

assert handle is mock_handle
mock_spawn.assert_called_once_with(
["tmux", "new-session", "-d", "-s", "repo-session"],
path=Path("/some/path"),
command="echo hello",
tab_name="test",
session_name="repo-session",
)
mock_run.assert_called_once_with(
["tmux", "set-option", "-t", "repo-session", "renumber-windows", "off"],
capture_output=True,
check=False,
)

def test_open_in_session_reuses_existing_session(self) -> None:
"""Outside tmux, a named session gets a new window when it already exists."""
terminal = Tmux()
Expand Down
Loading