Documentation
¶
Overview ¶
Package tmux is a thin wrapper over the tmux CLI used to host agent sessions: it creates and kills sessions, captures pane contents and scrollback, resizes windows, and reads/writes the @amux_* activity tags that coordinate detection and reattach across amux instances. tmux exit code 1 ("not found") is treated as an empty/absent result, not an error.
Index ¶
- Constants
- func AllSessionStates(opts Options) (map[string]SessionState, error)
- func CapturePane(sessionName string, opts Options) ([]byte, error)
- func CapturePaneTail(sessionName string, lines int, opts Options) (string, bool)
- func ContentHash(content string) [16]byte
- func EnsureAvailable() error
- func GlobalOptionValue(key string, opts Options) (string, error)
- func GlobalOptionValues(keys []string, opts Options) (map[string]string, error)
- func InstallHint() string
- func IsNoServerError(err error) bool
- func KillSession(sessionName string, opts Options) error
- func KillSessionsMatchingTags(tags map[string]string, opts Options) (bool, error)
- func KillSessionsWithPrefix(prefix string, opts Options) error
- func KillSessionsWithPrefixMissingTag(prefix, tag string, opts Options) error
- func KillWorkspaceSessions(wsID string, opts Options) error
- func ListSessions(opts Options) ([]string, error)
- func ListSessionsMatchingTags(tags map[string]string, opts Options) ([]string, error)
- func NewClientCommand(sessionName string, p ClientCommandParams) string
- func ResizePaneToSize(sessionName string, cols, rows int, opts Options) error
- func SessionActiveWithin(sessionName string, window time.Duration, opts Options) (bool, error)
- func SessionClientCount(sessionName string, opts Options) (int, error)
- func SessionCreatedAt(sessionName string, opts Options) (int64, error)
- func SessionHasClients(sessionName string, opts Options) (bool, error)
- func SessionLatestActivity(sessionName string, opts Options) (time.Time, bool, error)
- func SessionName(parts ...string) string
- func SessionNamesWithClients(opts Options) (map[string]bool, error)
- func SessionPaneID(sessionName string, opts Options) (string, error)
- func SessionPaneSize(sessionName string, opts Options) (int, int, bool, error)
- func SessionPaneSnapshotInfo(sessionName string, opts Options) (int, int, bool, error)
- func SessionTagValue(sessionName, key string, opts Options) (string, error)
- func SetGlobalOptionValue(key, value string, opts Options) error
- func SetGlobalOptionValues(values []OptionValue, opts Options) error
- func SetMonitorActivityOn(opts Options) error
- func SetSessionTagValue(sessionName, key, value string, opts Options) error
- func SetSessionTagValues(sessionName string, tags []OptionValue, opts Options) error
- func SetStatusOff(opts Options) error
- type ClientCommandParams
- type OptionValue
- type Options
- type PaneModeState
- type PaneSnapshot
- type SessionActivity
- type SessionState
- type SessionTagValues
- type SessionTags
Constants ¶
const ( TagLastOutputAt = "@amux_last_output_at" TagLastInputAt = "@amux_last_input_at" TagSessionOwner = "@amux_session_owner" TagSessionLeaseAt = "@amux_session_lease_ms" // TagAgentState publishes the semantic per-session agent state // ("idle"/"working"/"done", see activity.AgentState.String()) computed by // the activity scan's hysteresis. Written best-effort on state transitions // only (see app_tmux_activity_result.go); read-only telemetry for external // orchestrators. TagAgentState = "@amux_agent_state" )
Variables ¶
This section is empty.
Functions ¶
func AllSessionStates ¶ added in v0.0.15
func AllSessionStates(opts Options) (map[string]SessionState, error)
AllSessionStates returns the SessionState for every tmux session on the server in a single subprocess call. It runs:
tmux list-panes -a -F "#{session_name}\t#{pane_dead}"
Sessions that appear in output have Exists=true. Any session with at least one pane where pane_dead is "0" gets HasLivePane=true. If there are no sessions at all (exit code 1), an empty map is returned.
func CapturePane ¶
CapturePane captures the scrollback history of a tmux pane (excluding the visible screen area) with ANSI escape codes preserved. Returns nil if the session has no scrollback or does not exist.
func CapturePaneTail ¶
CapturePaneTail captures the last N lines of a session's active pane. Returns the content and a success flag. Returns ("", false) on error (e.g., session doesn't exist or capture times out).
func ContentHash ¶
ContentHash returns a fast hash of the content for change detection.
func EnsureAvailable ¶
func EnsureAvailable() error
func GlobalOptionValue ¶ added in v0.0.15
GlobalOptionValue returns a tmux global option value for the given key. Missing options return an empty value with nil error, while connection failures (for example, no running server) are returned as errors. Unlike SetGlobalOptionValue, read paths do not suppress generic command errors because callers rely on these failures for ownership/coordination fallback decisions.
func GlobalOptionValues ¶ added in v0.0.15
GlobalOptionValues returns tmux global option values for the given keys in a single tmux command invocation.
func InstallHint ¶
func InstallHint() string
func IsNoServerError ¶ added in v0.0.15
IsNoServerError reports whether err indicates that no tmux server is currently running for the selected socket/server name.
func KillSession ¶
func KillSessionsMatchingTags ¶
KillSessionsMatchingTags kills sessions that match all provided tags.
func KillSessionsWithPrefix ¶
KillSessionsWithPrefix kills all sessions with a matching name prefix.
func KillSessionsWithPrefixMissingTag ¶ added in v0.0.20
KillSessionsWithPrefixMissingTag kills sessions with a matching name prefix only when the given session option is empty. This is used for legacy amux sessions created before @amux_instance existed; modern sessions owned by other app instances are left alone.
func KillWorkspaceSessions ¶
KillWorkspaceSessions kills all sessions for a workspace ID.
func ListSessions ¶
ListSessions returns all tmux session names for the configured server.
func ListSessionsMatchingTags ¶
ListSessionsMatchingTags returns sessions matching all provided tags.
func NewClientCommand ¶ added in v0.0.14
func NewClientCommand(sessionName string, p ClientCommandParams) string
NewClientCommand builds the shell command string that creates (or reattaches to) a tmux session with the given name and parameters.
func ResizePaneToSize ¶ added in v0.0.19
ResizePaneToSize updates a managed session's window size to the given cell dimensions before any new client attaches. This is used to capture an authoritative snapshot at the size a reattached client will render.
func SessionActiveWithin ¶ added in v0.0.19
SessionActiveWithin reports whether any window in the session had tmux activity within the provided time window.
func SessionClientCount ¶ added in v0.0.19
SessionClientCount reports how many tmux clients are currently attached to a session.
func SessionCreatedAt ¶
SessionCreatedAt returns the tmux session creation timestamp (unix seconds).
func SessionHasClients ¶
SessionHasClients reports whether the tmux session has any attached clients.
func SessionLatestActivity ¶ added in v0.0.19
SessionLatestActivity reports the most recent tmux window_activity timestamp for a session without applying any second-resolution slack.
func SessionName ¶
func SessionNamesWithClients ¶ added in v0.0.15
SessionNamesWithClients returns the set of session names that currently have at least one attached client.
func SessionPaneID ¶ added in v0.0.19
SessionPaneID reports the active pane ID for a session using only tmux metadata. Returns an empty string if the session does not exist.
func SessionPaneSize ¶ added in v0.0.19
SessionPaneSize reports the current size of a session's active pane using only tmux metadata. The returned size is independent of whether the pane is eligible for authoritative full-pane snapshots.
func SessionPaneSnapshotInfo ¶ added in v0.0.19
SessionPaneSnapshotInfo reports whether a session's active pane is eligible for an authoritative full-pane snapshot, along with its current size. This uses only pane metadata and does not capture pane history.
func SessionTagValue ¶
SessionTagValue returns a session option value for the given tag key.
func SetGlobalOptionValue ¶ added in v0.0.15
SetGlobalOptionValue sets a tmux global option value.
func SetGlobalOptionValues ¶ added in v0.0.15
func SetGlobalOptionValues(values []OptionValue, opts Options) error
SetGlobalOptionValues sets multiple tmux global options in a single tmux command.
func SetMonitorActivityOn ¶
SetMonitorActivityOn enables tmux monitor-activity globally. Called once at startup and when the tmux server name changes, rather than on every activity scan.
func SetSessionTagValue ¶ added in v0.0.12
SetSessionTagValue sets a tmux session option for the given session. Returns nil if the session no longer exists (killed between create and tag).
func SetSessionTagValues ¶ added in v0.0.15
func SetSessionTagValues(sessionName string, tags []OptionValue, opts Options) error
SetSessionTagValues sets multiple tmux session options for the given session in a single tmux command invocation. Returns nil if the session no longer exists (killed between create and tag).
func SetStatusOff ¶
SetStatusOff disables the tmux status line globally for the server.
Types ¶
type ClientCommandParams ¶ added in v0.0.14
type ClientCommandParams struct {
WorkDir string
Command string
Options Options
Tags SessionTags
DetachExisting bool // Detach other clients attached to this session.
}
ClientCommandParams holds the parameters for building a tmux client command.
type OptionValue ¶ added in v0.0.15
OptionValue represents a tmux option key/value pair.
type Options ¶
type Options struct {
ServerName string
ConfigPath string
HideStatus bool
DisableMouse bool
DefaultTerminal string
CommandTimeout time.Duration
}
func DefaultOptions ¶
func DefaultOptions() Options
type PaneModeState ¶ added in v0.0.19
type PaneModeState struct {
HasState bool
AltScreen bool
OriginMode bool
CursorHidden bool
ScrollTop int
ScrollBottom int
HasAltSavedCursor bool
AltSavedCursorX int
AltSavedCursorY int
}
PaneModeState describes the VT mode state tmux reports for a captured pane.
type PaneSnapshot ¶ added in v0.0.19
type PaneSnapshot struct {
Data []byte
Cols int
Rows int
CursorX int
CursorY int
HasCursor bool
ModeState PaneModeState
}
PaneSnapshot contains a full-pane capture plus optional cursor metadata from tmux.
func CapturePaneSnapshot ¶ added in v0.0.19
func CapturePaneSnapshot(sessionName string, opts Options) (PaneSnapshot, error)
CapturePaneSnapshot captures the full tmux pane state (scrollback plus the current visible screen) with ANSI escape codes preserved, along with the pane cursor position when tmux reports it.
type SessionActivity ¶
func ActiveAgentSessionsByActivity ¶
func ActiveAgentSessionsByActivity(window time.Duration, opts Options) ([]SessionActivity, error)
ActiveAgentSessionsByActivity returns tagged agent sessions with recent tmux activity. Activity is derived from tmux's window_activity timestamp. Note: monitor-activity is set once at startup and per-session at creation via SetMonitorActivityOn, not on every scan.
type SessionState ¶
func SessionStateFor ¶
func SessionStateFor(sessionName string, opts Options) (SessionState, error)
type SessionTagValues ¶
SessionTagValues stores tag values for a tmux session.
func SessionsWithTags ¶
func SessionsWithTags(match map[string]string, keys []string, opts Options) ([]SessionTagValues, error)
SessionsWithTags returns sessions matching the provided tags, plus values for requested tag keys.