From d238f8de815dcdc44d57b02f4228049a312cdb42 Mon Sep 17 00:00:00 2001 From: Anito Anto <49053859+anitoanto@users.noreply.github.com> Date: Sat, 4 Apr 2026 13:07:16 +0100 Subject: [PATCH] enhance session management by refreshing session count for specific paths --- src/gitdirector/commands/tui.py | 37 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/gitdirector/commands/tui.py b/src/gitdirector/commands/tui.py index 1dd1f4a..b5f8deb 100644 --- a/src/gitdirector/commands/tui.py +++ b/src/gitdirector/commands/tui.py @@ -708,11 +708,16 @@ def action_open_tmux(self, agent_cmd: str | None = None) -> None: ["tmux", "send-keys", "-t", session_name, f"clear && {agent_cmd}", "Enter"], check=False, ) - self.push_screen(_AgentLoadingScreen(agent_cmd, session_name)) + self.push_screen( + _AgentLoadingScreen(agent_cmd, session_name), + callback=lambda _: self.set_timer( + 0.2, lambda: self._refresh_sessions_for_path(path) + ), + ) else: - self._suspend_and_attach(session_name) + self._suspend_and_attach(session_name, path) - def _suspend_and_attach(self, session_name: str) -> None: + def _suspend_and_attach(self, session_name: str, path: Path | None = None) -> None: """Suspend the TUI and attach to the tmux session.""" import sys @@ -725,9 +730,28 @@ def _suspend_and_attach(self, session_name: str) -> None: sys.stdout.write("\033[?25h") sys.stdout.flush() - def _attach_to_session(self, session_name: str) -> None: + if path is not None: + self.set_timer(0.2, lambda: self._refresh_sessions_for_path(path)) + + def _refresh_sessions_for_path(self, path: Path) -> None: + """Update only the sessions cell for the given repo path.""" + from ..integrations.tmux import list_repo_sessions + + count = len(list_repo_sessions(path.name)) + self._sessions_cache[str(path)] = count + table = self.query_one("#repo-table", DataTable) + try: + table.update_cell( + str(path), + self._col_keys[5], + str(count) if count > 0 else "—", + ) + except Exception: + pass + + def _attach_to_session(self, session_name: str, path: Path | None = None) -> None: """Attach to an existing tmux session.""" - self._suspend_and_attach(session_name) + self._suspend_and_attach(session_name, path) def action_show_menu(self) -> None: path = self._get_selected_path() @@ -756,7 +780,8 @@ def _handle_menu_action(self, action: str | None) -> None: self.action_open_tmux(agent_cmd=self._AGENT_COMMANDS[action]) elif action.startswith("attach:"): session_name = action[len("attach:") :] - self._attach_to_session(session_name) + path = self._get_selected_path() + self._attach_to_session(session_name, path) elif action == "remove_session": path = self._get_selected_path() if path: