Read values, execute explicitly

Copy Markdown View Source
  • Capture once when several decisions need the same graph, and keep that snapshot while you select and filter.
  • Run a new command explicitly for another observation or an effect.
  • Capture covers an interval, so fields can change during it. The value you get stays fixed while tmux keeps changing.

The values you hold

ValueWhat it representsI/O boundary
LibTmux.ServerExecutable, socket choice and environment for an existing serverPure descriptor construction
LibTmux.SnapshotAn indexed graph captured over one intervalLibTmux.Server.snapshot/2 captures a new value
LibTmux.SelectionOrdered items and their originating snapshotFiltering and enumeration use captured values
LibTmux.RefAn observed exact ID and server instancePure identity data; it reserves nothing
LibTmux.ControlA handle pinned to one connection epochStatus reads are local; startup explicitly attaches a client
LibTmux.OperationAccess to one retained operation recordResult/status reads are local; awaiting registers a separate waiter
  • Windows are physical objects. LibTmux.WindowLink gives a window's session membership, index and active state.
  • A linked window can appear more than once, while its panes stay the same physical panes.
  • Choose window links when membership matters. Choose panes when an action should address each physical pane once.

See captured state.

Coverage tells you which questions the graph can answer

  • A loaded field holds a value, an empty string or a documented nil.
  • :unloaded means this snapshot lacks the observation. :unavailable means the capability is absent. Neither means known absence.
  • Relationship predicates need complete captured join domains. A missing pane relation cannot satisfy "no pane matches."
  • Validation raises a structured coverage error before filtering, even for an empty selection.
  • Capture again explicitly for more coverage. Existing selections keep their graph.

See filtering.

Server identity and connection epochs have different lifetimes

  • A server instance identifies one tmux process incarnation. Native object IDs can be reused after that process exits.
  • References keep the observed instance, so qualified control requests can reject known stale targets. One-shot commands keep a check/use race; an observed ID reserves nothing.
  • An epoch identifies one control connection and its owned transport actors. The server instance can stay the same while the epoch changes.
  • LibTmux.Control.reconnect/2 returns the ready epoch, unchanged if it is already ready. Close first to require a replacement.
  • A replacement waits for retirement and returns a new pinned handle. Old handles cannot submit into it, and reconnect never replays work.

Waiting, command outcomes and retirement are separate

ResultWhat the caller can conclude
LibTmux.Control.submit/3 returns {:ok, operation}Admission succeeded; inspect or await the retained operation
LibTmux.Operation.await/2 returns an API timeoutThis waiter ended; the operation may still advance
A canonical outcome is :completed or :failed with :acknowledged certaintytmux supplied a command reply; arbitrary programs started by that command have their own lifetimes
A canonical outcome is :skipped with :no_write certaintyThe operation was classified before dispatch
A canonical outcome is :unknownAvailable evidence cannot determine its effects
Operation status reports wire: :retiredReply attribution has retired; the retained record may still occupy capacity
LibTmux.Control.close/2 returns :okThe pinned connection epoch retired; its enclosing supervisor remains running
  • Each await call has its own budget. A timeout or the caller's death ends that waiter without cancelling the operation.
  • For wire-active work, LibTmux.Operation.stop/1 asks to close the whole pinned epoch and can affect siblings. An already retired operation returns :ok without closing its connection.
  • LibTmux.Control.close/2 waits for connection retirement.
  • Inspect retained results instead of replaying an uncertain mutation.
  • A canonical outcome never changes once it exists. Bang operation APIs raise API and context errors, and still return failed, skipped and unknown outcomes as values.
  • Wire retirement, record expiry and native process cleanup each have their own evidence. Ownership covers deadlines, bounds and remaining limits.

Return conventions

These APIs answer different questions. Command completion does not mean that a program started by tmux has finished.

APINormal returnFailure handling
Domain actions such as LibTmux.Window.rename/4{:ok, result} only for completion, retaining value and evidenceUnsuccessful outcomes use LibTmux.Action.CompletionError; API and admitted execution errors retain their own types
Domain bangs such as LibTmux.Window.rename!/4Completed valueRaise the same errors with their evidence
LibTmux.Control.execute/3 and LibTmux.Operation.await/2{:ok, canonical_result}, including failed, skipped and unknown outcomesOuter errors describe execution context or waiting; their bangs raise those errors and return canonical outcomes unchanged
LibTmux.Selection.one/2 and LibTmux.Selection.one_or_nil/2{:ok, item}, or allowed {:ok, nil}Cardinality errors are tuples; bangs raise them. Predicate and coverage validation can raise in either form
Relationship helpers such as LibTmux.Session.panes/2Ordered selection, or observation/nil for to-one relationships; no I/OIdentity, coverage and ambiguity errors raise
LibTmux.Control.with_connection/2{:ok, callback_value} after cleanup, even when that value is {:error, reason}Startup errors return errors; callback raise/throw/exit propagates after cleanup. Unproved cleanup returns LibTmux.Control.ScopeFailure preserving the primary outcome
  • The recovery example handles lower-level execution and cleanup separately.
  • Option validation may raise. A name without a bang does not promise that every malformed call returns an error tuple.