libtmux_mcp.tools.pane_tools.wait_for_text
- libtmux_mcp.tools.pane_tools.wait_for_textWait
( 12 parameters )
For Text Result -
Wait for NEW output in a tmux pane, then return.
Description#
Polls until one of
patternsappears on a line written after this call starts, one ofstopappears (immediate failure exit), or the timeout expires. Passpatterns=nullto wait for any new output at all. Use this instead of pollingcapture_panein a loop.Pre-existing scrollback is never matched, and neither is paint left below the cursor at entry — only rows written after the call began count. If a pattern was already on screen the result says so via
matched_at_entry.Last resort: reserve for output you did not author. Commands you send are AUTHORED — use
run_command(returns exit status) or compose; tmux wait-for -S <channel>withwait_for_channelinstead, both cheaper and exact. For unattributable recurring prompts or background log lines, bracket your own command with a unique sentinel (cmd; echo __WAIT_$RANDOM__) and wait for that.stopis the cheap way to avoid burning the whole budget: pass the failure markers you already know ("error:","FAILED","Traceback") and a failed run returns in milliseconds instead of at the ceiling.The server caps
timeout. An over-large value is not an error — the wait returns at the ceiling and reportseffective_timeout.Notes
Matching happens in Python, never in tmux. Patterns are never interpolated into a tmux format string: tmux's format parser treats
#and}structurally, so an ordinary regex quantifier corrupts field parsing and a pattern ending in#swallows the rest of the format. Only fixed literal formats reach tmux.Every tmux call is timeout-bounded. Reads are spawned with
asyncio.create_subprocess_execand bounded against the wait's own deadline, rather than going through libtmux's untimedPopen.communicate(). Nothing in this path runs on a worker thread, so a wedged tmux server can neither pin the event loop nor hang interpreter shutdown.Alternate screen / pagers suppress matching. Inside
lessor any full-screen program,capture-panereturns the program's painted rows, so matching them would report text the program had already drawn. Matching is skipped for as long as the alternate screen lasts and the result comes back asalternate_screenrather thantimeout— read the screen, don't retry the wait.Scrollback rollover detection is partial. The tool raises when
hsizeshrinks below the entry value (clear-history, and any rollover whose dip is observable between polls). It does not reliably detectgrid_collect_historytrim during continuous output; a runtimectx.warningfires when sampled state enters the trim-risk band. Usewait_for_channelwhen correctness matters more than convenience.- Parameters
-
-
patterns(list[str] | None) # – Success patterns; the first one to match ends the wait. Literal text unlessregex=True. Omit or passnullto wait for any new output. -
stop(list[str] | None) # – Failure patterns. A hit ends the wait immediately withoutcome="stopped"andfound=false;matched_indexsays which entry fired. -
regex(bool) # – Interpretpatternsandstopas regular expressions. Default False (literal text). -
session_name(str | None) # – Session name for pane resolution. -
session_id(str | None) # – Session ID (e.g. '$1') for pane resolution. -
timeout(float) # – Requested seconds to wait. Default 8.0. Clamped by server policy; seeeffective_timeoutin the result. -
interval(float) # – Seconds between polls. Default 0.05 (50ms). Minimum 0.01. -
match_case(bool) # – Whether to match case. Default False (case-insensitive). -
socket_name(str | None) # – tmux socket name. -
ctx(Context | None) # – FastMCP context; when injected the tool reports progress to the client. Omitted in tests.
-
- Returns
-
WaitForTextResult Match outcome, a bounded tail of what the pane printed, and the timeout actually enforced.
Discussed in Python MCP examples , Python MCP topics