Add Codex target commands and session routing

This commit is contained in:
2026-02-17 04:24:07 +09:00
parent 6a29c5f3dd
commit 537839ba1a
9 changed files with 203 additions and 28 deletions

View File

@@ -25,6 +25,7 @@ class Bridge:
self._output_thread: threading.Thread | None = None
self._running = False
self._channel: str = self.config.allowed_channel_id
self._active_target: str | None = None
self._last_sent_output: str = ""
self._last_input_at = time.monotonic()
self._last_output_at = time.monotonic()
@@ -65,15 +66,30 @@ class Bridge:
)
return any(pattern in normalized for pattern in blocked_patterns)
def _handle_command(self, command: str, channel: str) -> None:
@staticmethod
def _display_name(target: str) -> str:
if target == "codex":
return "Codex"
return "Claude"
def _session_name_for_target(self, target: str) -> str:
if target == "codex":
return self.config.codex_tmux_session_name
return self.config.tmux_session_name
def _handle_command(self, action: str, target: str, channel: str) -> None:
"""슬래시 커맨드를 처리한다."""
if command == "start":
self._start_session(channel)
elif command == "stop":
if target not in {"claude", "codex"}:
self.slack.send_message(channel, ":warning: 지원하지 않는 대상입니다.")
return
if action == "start":
self._start_session(channel, target)
elif action == "stop":
self._stop_session(channel)
def _start_session(self, channel: str) -> None:
"""기존 Claude tmux 세션에 연결한다."""
def _start_session(self, channel: str, target: str) -> None:
"""지정한 대상의 tmux 세션에 연결한다."""
if self.pty and self.pty.is_alive:
self.slack.send_message(
channel, ":information_source: 이미 세션에 연결되어 있습니다."
@@ -81,8 +97,12 @@ class Bridge:
return
self._channel = channel
self._active_target = target
self._last_sent_output = ""
self.pty = PtyManager(self.config.tmux_session_name)
self.pty = PtyManager(
self._session_name_for_target(target),
cli_name=target,
)
try:
self.pty.start()
except RuntimeError as exc:
@@ -98,7 +118,10 @@ class Bridge:
self._output_thread = threading.Thread(target=self._poll_output, daemon=True)
self._output_thread.start()
self.slack.send_message(channel, ":link: Claude 세션에 연결되었습니다.")
display_name = self._display_name(target)
self.slack.send_message(
channel, f":link: {display_name} 세션에 연결되었습니다."
)
def _stop_session(self, channel: str) -> None:
"""브릿지 연결만 해제한다."""
@@ -106,6 +129,7 @@ class Bridge:
if self.pty:
self.pty.stop()
self.pty = None
self._active_target = None
self._last_sent_output = ""
self.slack.send_message(channel, ":electric_plug: 세션 연결이 해제되었습니다.")