From bc178f0ad5d9c5642b21d70703a53b5aaeed9224 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 12:09:45 -0600 Subject: [PATCH 1/3] Server(feat): Report bound tmux capabilities why: Callers need the daemon's feature requirements before sending a command that depends on them. what: - Resolve public capability reports from the checked connection. - Recheck pinned socket identity without sending a tmux command. - Copy registry entries and exercise both runtime adapters. --- lua/libtmux/_internal/endpoint.lua | 9 +++ lua/libtmux/_internal/server.lua | 33 +++++++++++ .../_internal/support/capabilities.lua | 59 +++++++++++++++++++ tests/integration/endpoint.lua | 16 +++++ tests/integration/features.lua | 30 +++++++++- tests/integration/test_endpoint.lua | 21 ++++--- tests/integration/test_features.lua | 25 ++++++++ tests/integration/test_version_check.lua | 5 +- tests/integration/version_check.lua | 2 + tests/unit/capabilities.lua | 44 ++++++++++++++ tests/unit/endpoint.lua | 36 +++++++++++ tests/unit/server.lua | 22 +++++++ 12 files changed, 290 insertions(+), 12 deletions(-) diff --git a/lua/libtmux/_internal/endpoint.lua b/lua/libtmux/_internal/endpoint.lua index 65174bc7..b9682684 100644 --- a/lua/libtmux/_internal/endpoint.lua +++ b/lua/libtmux/_internal/endpoint.lua @@ -449,6 +449,15 @@ function Bound:generation() return bindings[self].generation end +function Bound:_checked_evidence() + local state = assert(bindings[self], "invalid endpoint") + local valid, err = verify(state) + if not valid then + return nil, err + end + return self:evidence() +end + function Bound:close() local state = assert(bindings[self], "invalid endpoint") invalidate(state, "endpoint closed", "endpoint_closed") diff --git a/lua/libtmux/_internal/server.lua b/lua/libtmux/_internal/server.lua index 62fb761e..628bc8d2 100644 --- a/lua/libtmux/_internal/server.lua +++ b/lua/libtmux/_internal/server.lua @@ -15,6 +15,7 @@ local domain = require("libtmux._internal.domain") local live_query = require("libtmux._internal.live_query") local observation = require("libtmux._internal.observation") local program = require("libtmux._internal.program") +local capability_registry = require("libtmux._internal.support.capabilities") local M, Server = {}, {} -- Live objects own state; the registry must not root returned-request cycles on Lua 5.1. local servers = setmetatable({}, { __mode = "kv" }) @@ -383,6 +384,29 @@ local function capture(state, options) end, { operation = "snapshot", effect = "not_sent" }) end +--- Report feature support for the daemon release checked when connecting. +--- Rechecks a pinned socket's identity. Named and default sockets use the +--- original binding until the runtime detects a change. The returned report +--- owns its metadata, and editing it leaves command guards intact. +---@return libtmux.Request +function Server:capabilities() + local state = servers[self] + return state.runtime:_operation(function() + if state.closed then + return nil, + errors.new("closed", "server handle is closed", { + operation = "capabilities", + effect = "not_sent", + }) + end + local evidence, err = state.bound:_checked_evidence() + if not evidence then + return nil, err + end + return capability_registry.report(evidence.version) + end, { operation = "capabilities", effect = "not_sent" }) +end + function Server:get_option(name, options) return settings.run(servers[self], nil, "option", "get", name, nil, options) end @@ -1380,6 +1404,14 @@ end --- --- `libtmux.Runtime:connect`, `Server:close` and `Server:observe` --- +--- **Checking feature support.** `Server:capabilities` resolves to a +--- detached `libtmux.CapabilityReport` for the release checked at connection. +--- It reports named feature requirements and decisions, plus release-specific +--- workarounds. Editing the report leaves command guards intact. +--- +--- `Server:capabilities`, `libtmux.CapabilityReport.features` and +--- `libtmux.CapabilityReport.workarounds` +--- --- **Finding one thing.** Take one record from a `libtmux.Snapshot`, or from --- the rows of a query, with `libtmux.Selection:one`, which reports no match or --- several as errors, or `libtmux.Selection:one_or_nil`, which also accepts no @@ -1477,6 +1509,7 @@ end --- --- `Server:command`, `Server:group` and `Server:batch` ---@class libtmux.Server +---@field capabilities fun(self:libtmux.Server):libtmux.Request ---@field get_option fun(self:libtmux.Server,name:libtmux.OptionName|string, --- options?:libtmux.SettingGetOptions): --- libtmux.Request diff --git a/lua/libtmux/_internal/support/capabilities.lua b/lua/libtmux/_internal/support/capabilities.lua index 8fbe0376..f4ea186d 100644 --- a/lua/libtmux/_internal/support/capabilities.lua +++ b/lua/libtmux/_internal/support/capabilities.lua @@ -3,6 +3,7 @@ -- features.lua refuses with these thresholds, and scripts/emit_capabilities.lua -- serializes this same table to capabilities.json, so the two cannot disagree. -- Release names are inferred from the daemon's version; tmux advertises none. +local fields = require("libtmux._internal.fields") local M = {} local RAW = { "libtmux.Server:command", "libtmux.Server:batch", "libtmux.Server:group" } @@ -232,4 +233,62 @@ function M.workaround(id) return find(M.workarounds, id) end +---@class libtmux.CapabilityStatus: libtmux.Capability +---@field supported boolean Whether the observed release provides this feature. + +---@class libtmux.WorkaroundStatus +---@field id string +---@field name string +---@field summary string +---@field releases string[] Exact releases affected by this workaround. +---@field required string? First release that fixes this defect, when known. +---@field handling "refuse"|"repair" +---@field apis string[] +---@field commands libtmux.CapabilityCommand[] +---@field active boolean Whether the observed release needs this workaround. + +---@class libtmux.CapabilityReport +---@field version string Daemon release checked at connection. +---@field features table Named feature decisions and requirements. +---@field workarounds table Release-specific defects and handling. + +local function copy(value) + if type(value) ~= "table" then + return value + end + local result = {} + for key, item in pairs(value) do + result[key] = copy(item) + end + return result +end + +local function contains(values, version) + for _, value in ipairs(values) do + if value == version then + return true + end + end + return false +end + +-- Each report owns its nested metadata; caller edits cannot change admission. +---@param version string +---@return libtmux.CapabilityReport +function M.report(version) + local report = { version = version, features = {}, workarounds = {} } + for _, entry in ipairs(M.capabilities) do + local status = copy(entry) + status.supported = fields.at_least(version, entry.since) == true + and not contains(entry.except, version) + report.features[entry.id] = status + end + for _, entry in ipairs(M.workarounds) do + local status = copy(entry) + status.active = contains(entry.releases, version) + report.workarounds[entry.id] = status + end + return report +end + return M diff --git a/tests/integration/endpoint.lua b/tests/integration/endpoint.lua index 39bf405e..c78a608a 100644 --- a/tests/integration/endpoint.lua +++ b/tests/integration/endpoint.lua @@ -66,6 +66,22 @@ local function work(runtime) assert(server:close():await()) return mode .. " passed" end + if mode == "capabilities_replacement" then + local server = assert( + runtime:connect({ binary = options.binary, socket_path = options.socket }):await() + ) + local report = assert(server:capabilities():await()) + ready(runtime, { + pid = assert(os.getenv("TMUX_DAEMON_PID")), + started = assert(os.getenv("TMUX_DAEMON_START")), + }) + local replaced, err = server:capabilities():await() + assert(replaced == nil, "capability discovery accepted the replacement daemon") + assert(err.code == "stale_generation" and err.effect == "not_sent", tostring(err)) + assert(report.version == os.getenv("TMUX_DAEMON_VERSION")) + assert(server:close():await()) + return mode .. " passed" + end if mode == "cancel_bind" then local uv = runtime._driver.uv local original = uv.fs_mkdtemp diff --git a/tests/integration/features.lua b/tests/integration/features.lua index a5b580b0..aee4ed5e 100644 --- a/tests/integration/features.lua +++ b/tests/integration/features.lua @@ -5,12 +5,38 @@ local mode = assert(os.getenv("LIBTMUX_FEATURE_CASE")) local function work(runtime) local server = assert(runtime :connect({ - binary = assert(os.getenv("TMUX_BIN")), + binary = os.getenv("TMUX_CLIENT_BIN") or assert(os.getenv("TMUX_BIN")), socket_path = assert(os.getenv("TMUX_SOCKET")), }) :await()) local report - if mode == "observe" then + if mode == "capabilities" then + local discovered = assert(server:capabilities():await()) + assert(discovered.version == os.getenv("TMUX_DAEMON_VERSION"), discovered.version) + local deletion = assert(discovered.features["buffer-delete-named"]) + assert(deletion.since == "3.4" and deletion.handling == "refuse") + assert(discovered.features["unknown-feature"] == nil) + local expected = assert(os.getenv("LIBTMUX_EXPECT_DELETE")) == "yes" + assert(deletion.supported == expected, "feature decision disagrees with daemon") + deletion.since, deletion.supported = "1.0", true + deletion.commands[1].flags[1] = "-not-a-flag" + assert(server:set_buffer("capability-check", "owned"):await()) + local deleted, err = server:delete_buffer("capability-check"):await() + if expected then + assert(deleted, tostring(err)) + else + assert(deleted == nil and err.code == "unsupported" and err.effect == "not_sent") + end + local again = assert(server:capabilities():await()) + assert(again.features["buffer-delete-named"].since == "3.4") + assert(again.features["buffer-delete-named"].supported == expected) + assert(again.features["buffer-delete-named"].commands[1].flags[1] == "-b") + assert(server:close():await()) + local closed, closed_error = server:capabilities():await() + assert(closed == nil and closed_error.code == "closed") + assert(discovered.version == os.getenv("TMUX_DAEMON_VERSION")) + return "DISCOVERED " .. discovered.version + elseif mode == "observe" then local snapshot = assert(server:snapshot({ fields = { sessions = { "id", "name" } } }):await()) local session = assert(server:handle(snapshot, assert(snapshot.sessions:first()))) diff --git a/tests/integration/test_endpoint.lua b/tests/integration/test_endpoint.lua index fcb242c8..b2290f6c 100644 --- a/tests/integration/test_endpoint.lua +++ b/tests/integration/test_endpoint.lua @@ -9,15 +9,15 @@ local M = {} local function run_case(mode, host) fixture.with(function(f) local version = f:version() - local program = f:start_program( - host, - "endpoint", - { TMUX_DAEMON_VERSION = version, LIBTMUX_ENDPOINT_CASE = mode }, - "pipe" - ) + local program = f:start_program(host, "endpoint", { + TMUX_DAEMON_VERSION = version, + TMUX_DAEMON_PID = tostring(f.server_pid), + TMUX_DAEMON_START = f:out("display-message", "-p", "#{start_time}"):gsub("%s+$", ""), + LIBTMUX_ENDPOINT_CASE = mode, + }, "pipe") local old_socket = f.path .. "/old.sock" local ok, failure = pcall(function() - if mode == "replacement" or mode == "dead" then + if mode == "replacement" or mode == "capabilities_replacement" or mode == "dead" then test.assertTrue( program:expect(function(fresh) return fresh:find("\n", 1, true) ~= nil @@ -27,7 +27,7 @@ local function run_case(mode, host) local ready = program:output():match("^[^\n]*") local old_pid, old_started = ready:match("^READY (%d+) (%d+)$") test.assertNotNil(old_pid, ready .. program:errors()) - if mode == "replacement" then + if mode == "replacement" or mode == "capabilities_replacement" then assert(uv.fs_rename(f.socket, old_socket)) local result = f:run( "new-session", @@ -56,7 +56,7 @@ local function run_case(mode, host) test.assertEquals(result.code, 0, result.stderr) test.assertStrContains(result.stdout, mode .. " passed") test.assertEquals(f:pins(), {}) - if mode == "replacement" then + if mode == "replacement" or mode == "capabilities_replacement" then test.assertEquals(f:out("list-sessions", "-F", "#{session_name}"), "fixture\n") elseif mode == "dead" then test.assertNotEquals(f:try("list-sessions").code, 0) @@ -78,6 +78,9 @@ end) fixture.each_host(M, "path_replacement_rejects_reused_entity_ids", function(host) run_case("replacement", host) end) +fixture.each_host(M, "public_capabilities_refuse_a_replacement_daemon", function(host) + run_case("capabilities_replacement", host) +end) fixture.each_host(M, "dead_alias_cannot_autostart_new_daemon", function(host) run_case("dead", host) end) diff --git a/tests/integration/test_features.lua b/tests/integration/test_features.lua index 178e3ae7..14c3a8a4 100644 --- a/tests/integration/test_features.lua +++ b/tests/integration/test_features.lua @@ -50,6 +50,31 @@ fixture.each_host(M, "control_observation_needs_tmux_3_7_and_attaches_nothing_be end) end) +fixture.each_host(M, "public_capabilities_follow_the_daemon_and_keep_guards_private", function(host) + fixture.with(function(f) + local version = f:version() + local before = state(f) + local result = f:program(host, "features", { + TMUX_DAEMON_VERSION = version, + TMUX_CLIENT_BIN = os.getenv("TMUX_CLIENT_BIN") or f.binary, + LIBTMUX_FEATURE_CASE = "capabilities", + LIBTMUX_EXPECT_DELETE = fixture.at_least(version, 3, 4) and "yes" or "no", + }, { timeout = DEADLINE }) + test.assertStrContains(result.stdout, "FEATURE DISCOVERED " .. version) + test.assertEquals(f:pins(), {}) + local after = state(f) + test.assertEquals(after[2], before[2]) + test.assertEquals(after[3], before[3]) + test.assertEquals(after[4], before[4]) + if fixture.at_least(version, 3, 4) then + test.assertEquals(after[1], before[1]) + else + test.assertStrContains(after[1], "capability-check") + end + alive(f) + end) +end) + fixture.each_host(M, "raw_commands_are_refused_per_release_without_effects", function(host) fixture.with(function(f) local version = f:version() diff --git a/tests/integration/test_version_check.lua b/tests/integration/test_version_check.lua index d03a1639..27ab619d 100644 --- a/tests/integration/test_version_check.lua +++ b/tests/integration/test_version_check.lua @@ -105,7 +105,10 @@ local function exercise(f, armed) end local function run_lua(f, mode, host, version, extra) - local env = { LIBTMUX_EXPECT_REFUSAL = refusal_wording(version) } + local env = { + LIBTMUX_EXPECT_REFUSAL = refusal_wording(version), + TMUX_DAEMON_VERSION = version, + } -- A newer client in front of an older daemon: the lane builds both. for _, name in ipairs({ "TMUX_CLIENT_BIN", "LIBTMUX_REFUSAL_MAX_MS" }) do env[name] = os.getenv(name) diff --git a/tests/integration/version_check.lua b/tests/integration/version_check.lua index 0a3494fb..d8aefc87 100644 --- a/tests/integration/version_check.lua +++ b/tests/integration/version_check.lua @@ -135,6 +135,8 @@ local function work(runtime) end assert(mode == "supported", "unknown version check case") assert(server, tostring(err)) + local capabilities = assert(server:capabilities():await()) + assert(capabilities.version == os.getenv("TMUX_DAEMON_VERSION")) local created created, err = server:command({ "new-session", "-d", "-s", "supported", "/bin/cat" }):await() assert(created, tostring(err)) diff --git a/tests/unit/capabilities.lua b/tests/unit/capabilities.lua index b294025d..6b09135e 100644 --- a/tests/unit/capabilities.lua +++ b/tests/unit/capabilities.lua @@ -73,4 +73,48 @@ function M.test_lookup_rejects_an_unknown_id() t.assertError(registry.workaround, "control-mode") end +function M.test_reports_feature_boundaries_and_exact_release_workarounds() + t.assertEquals(type(registry.report), "function", "capability reports are missing") + for _, case in ipairs({ + { "3.3a", false, false }, + { "3.7", true, false }, + { "3.7z", true, false }, + { "next-3.8", true, false }, + { "3.8-rc2", true, false }, + { "3.8", true, true }, + { "3.8a", true, true }, + }) do + local report = registry.report(case[1]) + t.assertEquals(report.version, case[1]) + t.assertEquals(report.features["control-mode"].supported, case[2], case[1]) + t.assertEquals(report.features["layout-json"].supported, case[3], case[1]) + t.assertEquals(report.features["layout-json"].since, "3.8") + t.assertNil(report.features["no-such-capability"]) + end + t.assertTrue(registry.report("3.7").workarounds["name-separators-rejected"].active) + t.assertFalse(registry.report("3.7a").workarounds["name-separators-rejected"].active) + t.assertNil(registry.report("3.7").workarounds["control-mode"]) +end + +function M.test_report_mutation_cannot_change_admission_or_another_report() + t.assertEquals(type(registry.report), "function", "capability reports are missing") + local report = registry.report("3.7") + report.features["layout-json"].since = "1.0" + report.features["layout-json"].supported = true + report.features["control-mode"].commands[1].flags[1] = "broken" + report.features["control-mode"].apis[1] = "broken" + report.workarounds["name-separators-rejected"].releases[1] = "3.7a" + local next_report = registry.report("3.7") + t.assertEquals(next_report.features["layout-json"].since, "3.8") + t.assertFalse(next_report.features["layout-json"].supported) + t.assertEquals(next_report.features["control-mode"].commands[1].flags[1], "-E") + t.assertEquals(next_report.features["control-mode"].apis[1], "libtmux.Server:observe") + t.assertTrue(next_report.workarounds["name-separators-rejected"].active) + local refusal = assert(require("libtmux._internal.features").commands("3.7", { + { "select-layout", '{"type":"pane"}' }, + })) + t.assertEquals(refusal.code, "unsupported") + t.assertEquals(refusal.required, "3.8") +end + return M diff --git a/tests/unit/endpoint.lua b/tests/unit/endpoint.lua index 42d2b024..a854a21b 100644 --- a/tests/unit/endpoint.lua +++ b/tests/unit/endpoint.lua @@ -256,6 +256,42 @@ function M.test_libtmux_socket_is_a_name_passed_as_L_and_pins_nothing() t.assertEquals(f.uv.calls, {}) end +function M.test_capability_evidence_checks_the_pinned_socket_without_a_tmux_client() + local f = fixture() + f:start(function(rt) + local bound = assert(endpoints + .bind(rt, { + binary = "/tmux", + socket = "/owned/tmux.sock", + }, environment({})) + :await()) + f.uv.calls = {} + t.assertEquals(assert(bound:_checked_evidence()).version, "3.7c") + t.assertEquals(f.uv.calls, { "lstat", "lstat" }) + t.assertEquals(#f.uv.spawned, 1) + + f.uv.files["/owned/tmux.sock"] = { type = "socket", dev = 1, ino = 11 } + local evidence, err = bound:_checked_evidence() + t.assertNil(evidence) + t.assertEquals(assert(err).code, "stale_generation") + t.assertEquals(#f.uv.spawned, 1) + assert(bound:close():await()) + end) +end + +function M.test_capability_evidence_for_a_named_socket_comes_from_binding() + local f = fixture() + f:start(function(rt) + local getenv = environment({ LIBTMUX_SOCKET = "work" }) + local bound = assert(endpoints.bind(rt, { binary = "/tmux" }, getenv):await()) + f.uv.daemon_version = "3.8" + t.assertEquals(assert(bound:_checked_evidence()).version, "3.7c") + t.assertEquals(#f.uv.spawned, 1) + t.assertEquals(f.uv.calls, {}) + assert(bound:close():await()) + end) +end + function M.test_the_path_wins_when_both_variables_are_set() local f = fixture() f:start(function(rt) diff --git a/tests/unit/server.lua b/tests/unit/server.lua index ced29cfa..d9df896d 100644 --- a/tests/unit/server.lua +++ b/tests/unit/server.lua @@ -35,6 +35,9 @@ local function fixture(body, limits, expected_root_error) function bound.evidence() return identity.evidence(generation) end + function bound._checked_evidence() + return identity.evidence(generation) + end function bound.close() state.closed = true identity.invalidate(generation) @@ -216,6 +219,25 @@ function M.test_public_batch_can_register_its_only_completion_slot() t.assertEquals(calls, 1) end +function M.test_public_capabilities_return_a_detached_report_and_refuse_closed_handles() + fixture(function(rt) + local server = connect(rt) + t.assertEquals(type(server.capabilities), "function", "public discovery is missing") + local report = assert(server:capabilities():await()) + t.assertEquals(report.version, "3.7c") + t.assertFalse(report.features["layout-json"].supported) + t.assertTrue(report.features["control-mode"].supported) + report.features["layout-json"].since = "1.0" + local next_report = assert(server:capabilities():await()) + t.assertEquals(next_report.features["layout-json"].since, "3.8") + server:close():await() + local value, err = server:capabilities():await() + t.assertNil(value) + t.assertEquals(assert(err).code, "closed") + t.assertEquals(report.version, "3.7c") + end) +end + function M.test_connection_copies_options_and_invalid_snapshot_dispatches_nothing() fixture(function(rt, state) t.assertEquals(type(rt.connect), "function", "public connection is missing") From 79a5ab6451c42271b4219496de62b9f0051d9f8f Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 12:09:45 -0600 Subject: [PATCH 2/3] Docs(feat): Show tmux capability reports why: Callers need a concrete feature check and the lifetime of its result. what: - Document what the report says about the bound tmux release. - Add the runnable example, API export and editor completion. --- docs/compatibility.md | 20 ++++++++++++++++++ examples/api/README.md | 1 + examples/api/capabilities.lua | 27 ++++++++++++++++++++++++ examples/api/manifest.json | 11 ++++++++++ lua/libtmux/README.md | 6 ++++++ scripts/check_editor/script.lua | 9 ++++++++ scripts/docs/tests/test_api_examples.lua | 6 ++++-- 7 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 examples/api/capabilities.lua diff --git a/docs/compatibility.md b/docs/compatibility.md index 12b98bc8..02410fd7 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -91,6 +91,26 @@ also run the check with a 3.3a client against the old daemon, which covers the ## Optional features +Use `Server:capabilities():await()` to check a feature before attempting it. +The [complete program](../examples/api/capabilities.lua) starts and stops its +own daemon and checks named buffer deletion against it. + +The request uses the daemon release checked when the handle connected. +It sends no tmux command. A pinned path is rechecked and a stale path +returns `stale_generation`. With a named or default socket, the report +describes the bound release until the runtime detects a change. Use a new +connection for a fresh measurement. + +- `version` records the daemon's release at connection. +- `features[id]` gives the requirement, affected APIs and commands, and + boolean `supported` decision. +- `workarounds[id]` gives release-specific defect details and the boolean + `active` decision. + +Unknown IDs are absent. The report is an observation; later daemon changes do +not update it. Editing it cannot change the library's command guards or a +later report. Those guards still check every operation before dispatch. + The 3.3a minimum covers subprocess commands, typed operations, snapshots and polling captures. Each feature below names its own release requirement. A refusal has a test that fails when the guard is removed. diff --git a/examples/api/README.md b/examples/api/README.md index 5520fd51..9bef4cd8 100644 --- a/examples/api/README.md +++ b/examples/api/README.md @@ -30,6 +30,7 @@ to select a different build. | [start_server.lua](start_server.lua) | Start a private server, use it and stop it | `sessions: 0, then 1` | | [with_server.lua](with_server.lua) | Run a body on a server that stops when the body ends | `sessions: 1` | | [connect.lua](connect.lua) | Find the `work` session on a tmux server | `work` | +| [capabilities.lua](capabilities.lua) | Check a feature on the connected daemon | `named deletion requires: 3.4`, then `daemon decision checked` | | [snapshot.lua](snapshot.lua) | List sessions, windows, and panes | Two of each | | [new_session.lua](new_session.lua) | Create a session | `session: demo` | | [new_window.lua](new_window.lua) | Create a window in that session | `window: logs` | diff --git a/examples/api/capabilities.lua b/examples/api/capabilities.lua new file mode 100644 index 00000000..cec7d6e6 --- /dev/null +++ b/examples/api/capabilities.lua @@ -0,0 +1,27 @@ +local adapter = require("libtmux.runtime.luv") + +local function must(value, err) + if err ~= nil then + error(tostring(err), 0) + end + return value +end + +must(adapter.run(function(runtime) + local owned = must(runtime:start_server():await()) + local report = must(owned.server:capabilities():await()) + local deletion = assert(report.features["buffer-delete-named"]) + print("named deletion requires: " .. deletion.since) + + must(owned.server:set_buffer("demo", "kept until deletion is safe"):await()) + if deletion.supported then + must(owned.server:delete_buffer("demo"):await()) + else + local deleted, err = owned.server:delete_buffer("demo"):await() + assert(deleted == nil and err.code == "unsupported" and err.effect == "not_sent") + end + print("daemon decision checked") + + must(owned:stop():await()) + return true +end)) diff --git a/examples/api/manifest.json b/examples/api/manifest.json index 2f2a30ae..4bbc8960 100644 --- a/examples/api/manifest.json +++ b/examples/api/manifest.json @@ -35,6 +35,17 @@ "description": "Find the session named work on a supplied tmux socket or try it on a private server.", "stdout": "work\n" }, + { + "id": "capabilities", + "symbols": [ + "libtmux.Server:capabilities", + "libtmux.CapabilityReport.features", + "libtmux.CapabilityStatus.supported" + ], + "file": "examples/api/capabilities.lua", + "description": "Check named feature requirements against the connected daemon and use its decision.", + "stdout": "named deletion requires: 3.4\ndaemon decision checked\n" + }, { "id": "snapshot", "symbols": [ diff --git a/lua/libtmux/README.md b/lua/libtmux/README.md index bc1b6e2a..7e0804b3 100644 --- a/lua/libtmux/README.md +++ b/lua/libtmux/README.md @@ -194,6 +194,10 @@ $ nvim --clean \ -c 'luafile examples/nvim_snapshot.lua' ``` +`Server:capabilities` reports feature support for the daemon release checked +when connecting. See the [compatibility guide][guide-capabilities] and the +[complete example][example-capabilities]. + ### [`libtmux.query`][ref-query]: tables without tmux [`select`][ref-query-select] wraps Lua tables in a [`Selection`][ref-selection], @@ -251,3 +255,5 @@ of a table. The [query guide][guide-query] lists the criteria both accept. [src-luv]: https://github.com/libtmux/libtmux-lua/blob/master/lua/libtmux/runtime/luv.lua [src-nvim]: https://github.com/libtmux/libtmux-lua/blob/master/lua/libtmux/runtime/nvim.lua [src-query]: https://github.com/libtmux/libtmux-lua/blob/master/lua/libtmux/query.lua +[guide-capabilities]: https://github.com/libtmux/libtmux-lua/blob/master/docs/compatibility.md#optional-features +[example-capabilities]: https://github.com/libtmux/libtmux-lua/blob/master/examples/api/capabilities.lua diff --git a/scripts/check_editor/script.lua b/scripts/check_editor/script.lua index 2f165784..5b0ec5ca 100644 --- a/scripts/check_editor/script.lua +++ b/scripts/check_editor/script.lua @@ -104,6 +104,7 @@ local function connect(doc, adapter, entry) doc:complete(" pending:", { "await", "cancel", "result", "on_complete" }) doc:add(" local server = assert(pending:await())") doc:complete(" server:", { + "capabilities", "snapshot", "close", "handle", @@ -124,6 +125,14 @@ local function connect(doc, adapter, entry) "show_buffer", "delete_buffer", }) + doc:add(" local discovery = server:capabilities()") + doc:complete(" discovery:", { "await", "cancel", "result", "on_complete" }) + doc:add(" local capabilities = assert(discovery:await())") + doc:complete(" capabilities.", { "version", "features", "workarounds" }) + doc:add(' local feature = capabilities.features["layout-json"]') + doc:complete(" feature.", { "id", "since", "except", "supported", "apis", "commands" }) + doc:add(' local workaround = capabilities.workarounds["name-separators-rejected"]') + doc:complete(" workaround.", { "id", "releases", "required", "active", "handling" }) end --- A buffer, a created session and the objects it holds: session, window and window link. diff --git a/scripts/docs/tests/test_api_examples.lua b/scripts/docs/tests/test_api_examples.lua index 678d3b5d..db763774 100644 --- a/scripts/docs/tests/test_api_examples.lua +++ b/scripts/docs/tests/test_api_examples.lua @@ -24,7 +24,9 @@ for symbol in libtmux.WindowLink:move libtmux.Window:layout libtmux.Server:start_program libtmux.Server:run_program libtmux.Program:send_text libtmux.Program:send_keys libtmux.Program:wait - libtmux.Program:reference libtmux.Program:stop libtmux.Program:screen]]):gmatch("%S+") + libtmux.Program:reference libtmux.Program:stop libtmux.Program:screen + libtmux.Server:capabilities libtmux.CapabilityReport.features + libtmux.CapabilityStatus.supported]]):gmatch("%S+") do TARGETS[symbol] = true end @@ -73,7 +75,7 @@ end function M.test_complete_programs_cover_their_existing_targets() local loaded = api.load_examples(repo.root, TARGETS) - test.assertEquals(#loaded.examples, 22) + test.assertEquals(#loaded.examples, 23) local seen = {} for _, example in ipairs(loaded.examples) do for _, symbol in ipairs(example.symbols) do From fac07174c242ac716b8333298069c596471433d4 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 5 Dec 2026 12:09:57 -0600 Subject: [PATCH 3/3] Changes(docs): Record capability reports why: Callers can test feature support before invoking an operation. what: - Add the new Server request under Unreleased. --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9a0d7f0d..522ced37 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -84,6 +84,8 @@ Notable changes to `libtmux`. and return types. - Docs: the Lua API export uses original source lines and records SHA-256 digests for its Lua inputs. (#113) +- Runtime: `Server:capabilities()` reports feature support and workarounds + for the daemon release checked when connecting. (#104) ## 0.1.1-1 (2026-11-01)