xa.panes

Pane providers: where a session’s terminal lives (tmux on a server, iTerm on a Mac).

Everything xa does with a session’s terminal is four verbs: create a pane running a command, capture its text, address it later, tear it down. A PaneProvider is that, and a PaneAddress (provider + ref) is the provider-neutral way to name a pane, so Session need not carry tmux-shaped fields.

  • TmuxPanes: the default; a thin layer over xa.tmux. Its ref is the tmux session name or a full pane ref (session:@window.%pane). Panes survive disconnection.

  • ITermPanes: an iTerm2 tab on a Mac, driven through an injected osascript runner. Its ref is the iTerm session id, valid while iTerm runs. Every value reaches AppleScript through on run argv, never spliced into the script text, so a directory or name containing a quote cannot break out.

>>> TmuxPanes().address("work").ref, TmuxPanes().address("work").provider
('work', 'tmux')
>>> str(PaneAddress("iterm", "ABC-1"))
'iterm:ABC-1'

Module Attributes

Runner

runs AppleScript with args as argv.

NO_GUI_SESSION

What osascript says when the caller is outside the GUI's launchd namespace (an SSH login): only then is the launchctl asuser retry made, so a failure that already did something (a tab opened, then an error) is never repeated.

PROVIDERS

Provider name -> factory (keyword arguments are the provider's own options).

Functions

osascript_runner(*[, run, uid, osascript, ...])

A Runner for osascript: directly first, and through launchctl asuser <uid> (which needs root) only when the direct call says the caller has no GUI session (NO_GUI_SESSION).

pane_provider([name])

The provider called name (tmux or iterm), built with options.

Classes

ITermPanes(*[, profile, run, known_profiles, ps])

iTerm2 tabs on a Mac.

PaneAddress(provider, ref)

Provider-neutral name of one pane: which provider, and its own reference.

PaneProvider(*args, **kwargs)

Where panes live.

TmuxPanes(*[, binary])

tmux panes, through xa.tmux (binary is the tmux executable).

Exceptions

PaneUnsupported

The provider cannot do this (e.g. stream a pane to a file).

class xa.panes.ITermPanes(*, profile='Default', run=None, known_profiles=None, ps=None)[source]

Bases: object

iTerm2 tabs on a Mac. run is the AppleScript runner (default: osascript_runner()); known_profiles optionally lists the profile names iTerm has, so a typo is an error before the GUI is touched (a typo otherwise opens a Default tab and looks like it worked).

pane_pids(ref)[source]

The pids on the tab’s tty (its login shell and what it runs), found through iTerm’s tty and ps -t; [] when iTerm no longer has the tab.

Return type:

list[int]

xa.panes.NO_GUI_SESSION = ('-609', '-600', 'Connection is invalid')

What osascript says when the caller is outside the GUI’s launchd namespace (an SSH login): only then is the launchctl asuser retry made, so a failure that already did something (a tab opened, then an error) is never repeated.

xa.panes.PROVIDERS: Mapping[str, Callable[..., PaneProvider]] = {'iterm': <class 'xa.panes.ITermPanes'>, 'tmux': <class 'xa.panes.TmuxPanes'>}

Provider name -> factory (keyword arguments are the provider’s own options).

class xa.panes.PaneAddress(provider, ref)[source]

Bases: object

Provider-neutral name of one pane: which provider, and its own reference.

class xa.panes.PaneProvider(*args, **kwargs)[source]

Bases: Protocol

Where panes live. Implementations: TmuxPanes, ITermPanes.

address(ref)[source]

The PaneAddress of a pane of this provider.

Return type:

PaneAddress

capture(ref, *, lines=200)[source]

The last lines of the pane’s text, or “” when it cannot be read.

Return type:

str

create(name, *, command, cwd=None)[source]

Start a pane named name running the shell command; return its address.

Return type:

PaneAddress

kill(ref)[source]

Tear the pane down.

Return type:

None

pane_pids(ref)[source]

The pids of the programs running in the pane (a root of each process tree; the claude process is one of them or below one). [] when the pane is gone.

Return type:

list[int]

stream_to_file(ref, path)[source]

Append the pane’s output to path as it appears (may raise PaneUnsupported).

Return type:

None

exception xa.panes.PaneUnsupported[source]

Bases: RuntimeError

The provider cannot do this (e.g. stream a pane to a file).

xa.panes.Runner

runs AppleScript with args as argv.

Type:

Runner(script, args) -> stdout

alias of Callable[[str, Sequence[str]], str]

class xa.panes.TmuxPanes(*, binary='tmux')[source]

Bases: object

tmux panes, through xa.tmux (binary is the tmux executable).

kill(ref)[source]

A bare session name closes that session; a pane ref (session:@window.%pane) closes only that pane, never the workspace.

Return type:

None

xa.panes.osascript_runner(*, run=<function run>, uid=None, osascript='osascript', timeout=30.0)[source]

A Runner for osascript: directly first, and through launchctl asuser <uid> (which needs root) only when the direct call says the caller has no GUI session (NO_GUI_SESSION). run is the subprocess seam.

Return type:

Callable[[str, Sequence[str]], str]

xa.panes.pane_provider(name='tmux', **options)[source]

The provider called name (tmux or iterm), built with options.

>>> pane_provider("tmux", binary="tmux").name
'tmux'
Return type:

PaneProvider