tmux
tmux
¶
TmuxControl — async wrapper over the tmux binary.
All interactive sessions live on an isolated tmux server (socket name
marianne) so Marianne never touches the user's default tmux server.
Sessions are created detached with a fixed virtual terminal size; the agent
command is passed as an explicit argv tail (never a joined shell string) so
the pane process is the agent itself — pid == pgid == session leader, which
is what the baton's PID registration and group-kill plumbing expect.
Every tmux invocation runs with a short per-command timeout: a wedged tmux
server must surface as a structured :class:TmuxError (which the driver
treats as session-lost), never as a driver hang the sheet timeout cannot
reach.
kill_server exists for tests only. Production teardown is always
per-session (kill_session) — a server kill would take down every
concurrent interactive sheet.
Classes¶
PaneExit
dataclass
¶
How a pane's process ended: an exit status, or the signal that killed it.
TmuxError
¶
Bases: RuntimeError
A tmux control command failed or timed out.
The driver treats any TmuxError during DRIVE as session-lost; during
LAUNCH it is a startup failure. stderr carries tmux's own message
for diagnostics.
Source code in src/marianne/execution/instruments/interactive/tmux.py
TmuxControl
¶
Async control surface over an isolated tmux server.
One instance per socket name; safe to share across sessions (tmux
serializes commands server-side). All methods raise :class:TmuxError
on failure or per-command timeout.
Source code in src/marianne/execution/instruments/interactive/tmux.py
Attributes¶
Methods:¶
version
async
¶
Parse the tmux version, or None when unparseable.
Returns (major, minor); suffixes like 3.4a parse as (3, 4).
Source code in src/marianne/execution/instruments/interactive/tmux.py
new_session
async
¶
Create a detached session running command as the pane process.
The command is passed as an explicit argv tail — tmux execs it
directly (no shell), so the pane process is the agent itself in its
own process group (spike-verified; integration tests pin this).
When supplied, env replaces the server environment via env -i.
The wrapper execs the target, preserving the pane PID/process group.
None retains tmux inheritance for callers without an environment policy.
Source code in src/marianne/execution/instruments/interactive/tmux.py
has_session
async
¶
Whether the session exists on this server.
kill_session
async
¶
Kill the session. Idempotent — a missing session is not an error.
list_sessions
async
¶
List session names on this server, optionally prefix-filtered.
Returns an empty list when the server is not running.
Source code in src/marianne/execution/instruments/interactive/tmux.py
capture_screen
async
¶
Capture the session's rendered screen as plain text.
capture-pane -p without -e renders to plain text — no ANSI
escape sequences (spike-verified), so the result is directly
pattern-matchable.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pane_exit
async
¶
How the pane's process ended, or None while it is still running.
Reads tmux's pane_dead / pane_dead_status / pane_dead_signal
(tmux 3.0+). A vanished session or a tmux failure also reads as None —
the caller already knows the session is unusable and only wants the
cause when tmux still holds the dead pane.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pane_pid
async
¶
The pane process PID, or None when unavailable.
Source code in src/marianne/execution/instruments/interactive/tmux.py
send_keys
async
¶
Send key names (tmux key syntax, e.g. 'Enter', 'Escape').
paste_text
async
¶
Deliver text to the session via a named buffer paste.
Uses load-buffer from a private temp file + bracketed paste
(paste-buffer -p), which delivers arbitrary multiline UTF-8
without key-escaping issues or ARG_MAX limits. The buffer name is
per-session so concurrent sheets never clobber each other; -d
deletes the buffer after pasting. Does NOT submit — callers send
Enter separately.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pipe_pane_to_file
async
¶
Stream the pane's raw output to log_path.
The raw stream is a debug artifact (cursor-addressing soup from
TUIs) — it is never machine-parsed. State detection uses
:meth:capture_screen exclusively.
The file is truncated first (GH #398): transcript names are keyed by job/sheet/attempt, and a later run that reuses that identity must not inherit — and misattribute — a previous run's session content.
Source code in src/marianne/execution/instruments/interactive/tmux.py
pipe_pane_off
async
¶
Stop streaming the pane's output (idempotent).
kill_server
async
¶
Kill the entire tmux server. TESTS ONLY.
Never call from production paths — it destroys every concurrent interactive session on the socket.
Source code in src/marianne/execution/instruments/interactive/tmux.py
Functions:¶
sanitize_session_name
¶
Sanitize a string into a valid tmux session name.
Replaces unsafe characters with - and caps the length. Deterministic:
the same input always produces the same name (cleanup relies on this).
Source code in src/marianne/execution/instruments/interactive/tmux.py
job_session_prefix
¶
Prefix shared by ordinary per-attempt sessions for one job.
Session names are generated as mzt-{job_id}-s{sheet}-a{attempt} after
sanitization. The -s suffix keeps job from matching job2 while
still matching every sheet/attempt for the job.
Source code in src/marianne/execution/instruments/interactive/tmux.py
kill_sessions_with_prefix_sync
¶
Best-effort synchronous tmux sweep for sessions with prefix.
BatonAdapter.deregister_job is deliberately synchronous, but cancelled
interactive attempts live outside the daemon process tree in tmux. This
helper gives the sync cancellation path a tmux-session teardown backstop.
Missing tmux or missing server is a no-op; individual kill failures are
logged and do not abort the sweep.
Source code in src/marianne/execution/instruments/interactive/tmux.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |