pub struct TmuxManager { /* private fields */ }Expand description
Manage tmux sessions for agent tasks.
Implementations§
Source§impl TmuxManager
impl TmuxManager
pub fn new() -> Self
Sourcepub fn session_name(&self, project: &str, task_id: &str) -> String
pub fn session_name(&self, project: &str, task_id: &str) -> String
Session name for a task: orch-{project}-{task_id}.
The project name is derived from the repo slug (e.g. owner/repo → repo).
This prevents collisions between projects with the same issue number.
Sourcepub async fn create_session(
&self,
repo: &str,
task_id: &str,
working_dir: &str,
command: &str,
env_vars: &[(&str, &str)],
) -> Result<String>
pub async fn create_session( &self, repo: &str, task_id: &str, working_dir: &str, command: &str, env_vars: &[(&str, &str)], ) -> Result<String>
Create a new tmux session for a task and run a command in it.
Environment variables in env_vars are injected into the session via
tmux new-session -e KEY=VALUE — they are not written to disk.
The session is detached — the agent runs in the background. Returns the session name.
Note: GH_TOKEN is passed here via -e like all other env vars. Do NOT
use create_session_detached + set_env + create_window to avoid
exposing secrets in process args — that creates a 2-window session which
breaks all tmux monitoring (completion detection, output capture, silence
detection) because they target the default window (the idle shell), not
the agent window. See the revert of PR #2903.
Sourcepub async fn session_exists(&self, session: &str) -> bool
pub async fn session_exists(&self, session: &str) -> bool
Check if a session exists.
Sourcepub async fn kill_session(&self, session: &str) -> Result<()>
pub async fn kill_session(&self, session: &str) -> Result<()>
Kill a session.
Sourcepub async fn capture_pane(&self, session: &str, lines: i32) -> Result<String>
pub async fn capture_pane(&self, session: &str, lines: i32) -> Result<String>
Capture the current pane content (last N lines).
Returns Ok(String::new()) if the session or pane is not found — this is
an expected teardown race when the session was cleaned up between the caller’s
is_session_active() check and this capture.
Sourcepub async fn is_session_active(&self, session: &str) -> bool
pub async fn is_session_active(&self, session: &str) -> bool
Check if the process in a session’s pane is still running. Returns false if the session doesn’t exist or the pane has no active process.
Sourcepub async fn session_blocks_dispatch(&self, session: &str) -> bool
pub async fn session_blocks_dispatch(&self, session: &str) -> bool
Return whether a session should block a new dispatch.
Dead tmux sessions with the same name are cleaned up eagerly so they do
not block reclaim/re-dispatch loops or cause new-session name collisions.
Sourcepub async fn session_blocks_dispatch_from_map(
&self,
session: &str,
session_map: &HashMap<String, bool>,
) -> bool
pub async fn session_blocks_dispatch_from_map( &self, session: &str, session_map: &HashMap<String, bool>, ) -> bool
Batch variant of session_blocks_dispatch that uses a pre-fetched session map.
session_map is the result of batch_session_active(). Sessions absent from the
map do not exist (→ no block). Sessions present with alive=true block dispatch.
Sessions present with alive=false have a dead pane and are cleaned up eagerly.
Sourcepub async fn batch_session_active(&self) -> HashMap<String, bool>
pub async fn batch_session_active(&self) -> HashMap<String, bool>
Get pane_dead status for all sessions in a single tmux call.
Returns a map from session name → alive (true = alive, false = dead/missing).
Uses list-panes -a to avoid one subprocess per session.
Sourcepub async fn list_sessions(&self) -> Result<Vec<Session>>
pub async fn list_sessions(&self) -> Result<Vec<Session>>
List all orch-prefixed sessions with metadata including creation time.
Sourcepub async fn kill_stale_sessions(&self, before_timestamp: u64) -> Result<usize>
pub async fn kill_stale_sessions(&self, before_timestamp: u64) -> Result<usize>
Kill all orch-prefixed sessions created before a given timestamp. Returns the number of sessions killed.
Sourcepub async fn wait_for_sessions_dead(
&self,
sessions: &[String],
poll_interval: Duration,
timeout: Duration,
) -> usize
pub async fn wait_for_sessions_dead( &self, sessions: &[String], poll_interval: Duration, timeout: Duration, ) -> usize
Wait for multiple sessions to be fully dead (no longer exist).
Polls every poll_interval up to timeout.
Returns the number of sessions that were still alive after timeout.
Sourcepub async fn wait_for_completion(
&self,
session: &str,
poll_interval: Duration,
) -> Result<String>
pub async fn wait_for_completion( &self, session: &str, poll_interval: Duration, ) -> Result<String>
Wait for a session to finish (pane process exits). Returns the captured output from the last N lines.
Sourcepub async fn snapshot(&self) -> Vec<(Session, bool)>
pub async fn snapshot(&self) -> Vec<(Session, bool)>
Snapshot all orch-prefixed sessions — for engine tick monitoring.
Returns a vector of (Session, alive) so callers can operate on the actual session name instead of reconstructing one from repo+task_id.
Uses batch_session_active() internally to fetch all pane-dead statuses
in a single subprocess call instead of one call per session (N+1 → 2).
Sourcepub async fn unset_env(&self, session: &str, key: &str) -> Result<()>
pub async fn unset_env(&self, session: &str, key: &str) -> Result<()>
Unset (remove) an environment variable from a tmux session.
Sourcepub async fn unset_global_env(&self, key: &str) -> Result<()>
pub async fn unset_global_env(&self, key: &str) -> Result<()>
Unset (remove) an environment variable from the tmux global environment.
Uses: tmux set-environment -gu <key>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TmuxManager
impl RefUnwindSafe for TmuxManager
impl Send for TmuxManager
impl Sync for TmuxManager
impl Unpin for TmuxManager
impl UnsafeUnpin for TmuxManager
impl UnwindSafe for TmuxManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more