orca icon indicating copy to clipboard operation
orca copied to clipboard

feat(ssh): discover pre-existing tmux agent sessions on remote hosts

Open huhuhulululu opened this issue 5 months ago • 1 comments

What

Adds a relay-side probe that enumerates tmux sessions already running on an SSH host — sessions Orca does not own — and, for each pane, reports:

  • which coding agent it's running (claude / codex / none), classified by walking the pane's process subtree (tmux only reports the immediate foreground command, so the real agent is usually a descendant of a shell);
  • the pane's cwd and the git branch at that path;
  • whether the session is attached.

New API: orca.ssh.discoverHostSessions({ targetId }) → { sessions, tmuxAvailable }.

Why

When you run agents on a remote host, anything started outside Orca (a bare tmux + claude/codex on the box) is invisible to Orca today. This gives Orca a way to observe an environment it doesn't own, without taking it over.

How

  • src/relay/host-sessions-handler.ts — registers host.discoverSessions. Because the relay already executes on the target host, the probe runs tmux list-panes / ps / git locally with no per-probe SSH round-trip, and is cancellable via the request signal. Parsing/classification is factored into pure functions (parseTmuxPaneLine, parseProcTable, classifyAgentFromProcTable) with unit tests.
  • src/main/ipc/ssh.ts — ssh:discoverHostSessions resolves the target's active multiplexer and forwards the RPC; a disconnected host returns { sessions: [], tmuxAvailable: false } rather than erroring.
  • src/shared/host-session-types.ts — canonical HostSession / HostSessionsResult.
  • preload — exposes ssh.discoverHostSessions.

Cross-platform / degradation

Missing tmux → tmuxAvailable: false; missing ps/git → agent: null / no branch. No hard failures. Windows hosts (no tmux) return an empty result. Matches the SSH use case and Cross-Platform requirements in AGENTS.md.

Scope

Backend pipeline only. The SSH-host UI surface (panel + status-bar segment + polling) is intentionally a follow-up so this diff stays reviewable.

Test plan

  • [x] vitest — 15 unit tests (agent classification incl. subtree isolation and cyclic-ppid safety, tmux/ps parsing)
  • [x] typecheck (node + cli + web) clean
  • [x] oxlint clean on changed files
  • [ ] Manual: connect an SSH host running a detached tmux + claude, call discoverHostSessions, confirm the session/agent/branch are reported

huhuhulululu avatar Jul 04 '26 01:07 huhuhulululu

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds host tmux session discovery. A new shared types module defines HostSessionAgent, HostSession, and HostSessionsResult. A relay-side HostSessionsHandler registers a host.discoverSessions request handler that probes tmux list-panes, ps -axo, and git branch to build session lists with agent classification, alongside unit tests for its parsing/classification helpers. The relay boot sequence instantiates this handler. A new main-process IPC handler ssh:discoverHostSessions forwards requests to the active SSH multiplexer, and preload exposes a corresponding ssh.discoverHostSessions API to the renderer.

Changes

Cohort / File(s) Summary
Shared types (src/shared/host-session-types.ts) Adds HostSessionAgent, HostSession, HostSessionsResult type definitions.
Relay handler (src/relay/host-sessions-handler.ts, .test.ts) Implements HostSessionsHandler with tmux/ps/git probing, parseTmuxPaneLine, parseProcTable, classifyAgentFromProcTable, plus unit tests.
Relay wiring (src/relay/relay.ts) Instantiates HostSessionsHandler with RelayDispatcher.
Main IPC (src/main/ipc/ssh.ts) Adds ssh:discoverHostSessions handler querying the active multiplexer.
Preload (src/preload/api-types.ts, src/preload/index.ts) Adds ssh.discoverHostSessions API method and type declaration.

Sequence Diagram(s)

sequenceDiagram
  participant Renderer
  participant Preload
  participant MainIPC
  participant Multiplexer
  participant HostSessionsHandler
  participant tmux
  participant ps
  participant git
  Renderer->>Preload: ssh.discoverHostSessions({targetId})
  Preload->>MainIPC: invoke ssh:discoverHostSessions
  MainIPC->>Multiplexer: request host.discoverSessions
  Multiplexer->>HostSessionsHandler: host.discoverSessions
  HostSessionsHandler->>tmux: list-panes
  HostSessionsHandler->>ps: -axo pid,ppid,comm
  HostSessionsHandler->>git: branch --show-current
  HostSessionsHandler-->>Multiplexer: HostSessionsResult
  Multiplexer-->>MainIPC: HostSessionsResult
  MainIPC-->>Preload: HostSessionsResult
  Preload-->>Renderer: HostSessionsResult

Related PRs: None identified.

Suggested labels: enhancement, relay, ipc

Suggested reviewers: None identified.

🐰 A hop through panes both dark and lit, I sniff for claude, for codex bit, tmux whispers who's alive, git branches help sessions thrive, a rabbit's map of hosts, legit.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning It explains the feature well, but it doesn't follow the required template and omits Screenshots, AI Review Report, and Security Audit sections. Rewrite the description using the repo template and add the missing Screenshots, AI Review Report, Security Audit, and Notes sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: discovering pre-existing tmux agent sessions over SSH.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jul 04 '26 01:07 coderabbitai[bot]

Thank you for this, @huhuhulululu! The legacy SSH relay this probe ran on has been removed (SSH hosts now run Orca's managed remote server), so the handler can't land as-is. The idea of seeing tmux/agent sessions started outside Orca is still tracked in #25344 and #18185, and I've linked your design there.

OrcaWin avatar Oct 11 '26 06:10 OrcaWin