Current section

Files

Jump to
libtmux docs capabilities.md
Raw

docs/capabilities.md

# Check the connected daemon's tmux features

Call `Server.capabilities/2` for a server descriptor or `Control.capabilities/2`
for an established control connection. The release comes from the daemon;
a different client executable does not change the decision.

## Observe the server and connection

With tmux on `PATH`, run this program from the checkout:

```console
$ mix run examples/capabilities.exs
```

<!-- example: examples/capabilities.exs -->

```elixir
alias LibTmux.{Capabilities, Command, Control, Server}

tmux = System.find_executable("tmux") || raise "tmux is not on PATH"

Server.with_owned([executable: tmux], fn server ->
  {:ok, report} = Server.capabilities(server, native_commands: true)
  {:ok, %{name: "split-window"}} = Capabilities.command(report, "split-window")

  event_wait =
    case Capabilities.require(report, "event-wait") do
      {:ok, %{scope: :tmux_primitive}} ->
        command = Command.new("wait-for", ["-E", "-l", "pane-created"])
        {:ok, %{stdout: ""}} = Server.run(server, command)

        "available"

      {:error, %{kind: :unsupported_feature, certainty: :no_write}} ->
        "refused"
    end

  {:ok, %{value: %{id: id}}} =
    Server.new_session(server, "capabilities", command: {:argv, ["/bin/cat"]})

  {:ok, same_instance} =
    Control.with_connection(
      [server: server, session: {:existing, id}, lane: :host_qualified],
      fn control ->
        {:ok, connected} = Control.capabilities(control)
        same_daemon = connected.server_instance == report.server_instance
        same_daemon and is_reference(connected.epoch)
      end
    )

  IO.puts(
    JSON.encode!(%{
      daemon: report.daemon_version,
      event_wait: event_wait,
      same_instance: same_instance
    })
  )
end)
```

<!-- /example -->

On tmux 3.8 it prints:

```text
{"daemon":"3.8","event_wait":"available","same_instance":true}
```

On tmux 3.3, `event_wait` is `"refused"`. That branch sends no event-wait
command. The server is private, so its empty configuration establishes the
bootstrap and control prerequisites below. `Server.with_owned/2` stops its
server and panes; `Control.with_connection/2` retires its client.

## Check a named primitive

`Capabilities.status/2` returns a decision; `supports?/2` returns a boolean;
`require/2` returns the supported decision or an error before dispatch. All
three are pure. For unknown IDs, `status/2` and `require/2` return
`unknown_feature`, and `supports?/2` returns `false`. An unsupported decision
returns `unsupported_feature` with its required and observed versions.

The `since` value is the first qualified tmux release within this project's
supported range. An older tmux can already provide the primitive.

| Feature ID | Native prerequisite | Supported floor |
| --- | --- | --- |
| `event-wait` | Event subscriptions with `wait-for -E` | 3.8 |
| `event-wait-claim` | Consume a specific pending event waiter with `wait-for -E -w` | 3.8 |
| `format-argument-quote` | Quote an argument token with the `q/a` format modifier | 3.7 |
| `capture-trim-blank-cells` | Trim blank cells with `capture-pane -T` | 3.4 |
| `pane-split-with-id` | Split a pane with literal argv and report its ID | 3.3 |
| `pane-retain-on-exit` | Set retention and exit banner options on a pane | 3.3 |
| `pane-identity-formats` | Read pane PID and dead-state formats | 3.3 |
| `pane-screen-capture` | Capture a pane's rendered screen | 3.3 |
| `pane-literal-keys` | Send literal text or named keys to a pane | 3.3 |
| `pane-kill` | Remove an exact pane | 3.3 |
| `pane-generation-fence` | Invalidate a per-pane marker on respawn and guard a same-queue action | 3.8 |
| `pane-rendered-history` | Observe retained and discarded rows around rendered capture | 3.8 |

Each decision links to the pinned tmux source for that primitive. The registry
covers known releases from 3.3 through 3.8, including listed letter releases.
Unknown patches, prereleases and future releases return `unsupported_version`
with the observed release and minimum. See the [tested runtime combinations](implementation.md#packages-and-support).

## Read a daemon's advertised commands

Pass `native_commands: true` to `Server.capabilities/2`. Then use
`Capabilities.command/2` with an exact canonical name. The returned map
gives the canonical name, alias and native usage. The usage exposes tmux's
advertised flags. It does not establish flag introduction, backport history
or behavior for a particular build.

The additional listing shares the observation deadline. Each row must
match the daemon's release, PID and start time before the second identity
check. Reports from a default or Control observation have no inventory.
All command observations require the same native bootstrap described below.

## Preserve the observation boundary

- A `Server` remains an unbound descriptor. Discovery takes two bounded native
  observations and checks the daemon's OS identity around them. Its report
  does not reserve the socket or remove a later one-shot check/use race.
- Discovery reserves the native, unaliased `list-commands` bootstrap. On an
  existing server, keep that command unaliased throughout the call and exclude
  concurrent administrative configuration changes. Discovery does not inspect
  or repair configuration before trusting its bootstrap.
- A `Control` report stays on its already established epoch. Its field read
  inherits the connection's [host qualification](managed-control.md#before-you-start)
  for hooks, aliases and other writers. It does not reconnect or change
  transport. Mixed client/daemon connection limits remain in
  [implementation status](implementation.md).
- Both calls use one monotonic timeout, default 1000ms, with the existing
  bounded transport and cleanup errors. A timeout is not authority to replay.
- A report describes the daemon at the time of discovery. `Program.run/4`
  checks the current daemon and pane before starting an application.
  See [owned programs](owned-program-concept.md).

Use `LibTmux.ReleaseMap.lookup/2` to look up a command, flag, setting, hook or
format in a tagged tmux release without connecting to a daemon. See the
[release lookup example](api-examples.md#choose-a-native-release).
The [MCP package guide](../packages/mcp/README.md) exposes its own tools for observing
panes and applying authorized workspaces.