Repository navigation
Description
Summary
Add an owned terminal application API shared by the core and Async gems. A caller should pass literal argv, interact with a returned program, await exit and a bounded final screen, and close its owned resources explicitly or through a block scope.
Motivation
Server#run dispatches tmux commands, while Session#new_window supplies application creation primitives. Neither gives a program owner combining launch, application completion and cleanup. The MCP enrolled-shell runner has its own borrowed-shell and input-authority rules.
A command that writes final UTF-8 output and exits 7 needs completion evidence after fast exit. An interactive application needs input, resize, independent waiter cancellation and explicit termination through the same owner.
Proposal
- Add
start_program(argv, ...), a block-scoped form andrun_program, returning aProgramwith wait, screen, input and explicit close operations. Reuse literal command encoding, physical references and daemon binding. Support cwd, environment, geometry and retention; preserve singleton executables, empty arguments and shell syntax as data. - Arm retention and observation before launch. Return immutable typed exit/status, signal, uncertain-dispatch, lost-generation and cleanup results. Guard destructive operations against the accepted daemon and program generation in the daemon queue, including respawn. A previous pane-ID read cannot authorize later destruction.
- Share one owner with the Async facade. Preserve fiber-aware I/O and bounded queues. Give each wait its own cancellation while retaining a shared completion; owning-run cancellation and block exit settle their declared cleanup policy. Explicit close failures stay inspectable and retryable. State the owner-process failure/recovery policy rather than relying on garbage collection.
- Extend
Internal::Capabilitiesand reuse Expose the capability map through the public API #112 for public discovery andtmux_capabilitiesdoes not report the optional features a daemon refuses #56 for MCP reporting. Evaluate program support against the bound daemon before pane/helper creation or input.supports_control?alone is insufficient. Record every primitive's actual minimum, including any selected 3.8 event path, without raising older primitive floors. Refuse below requirements unless an evidenced fallback passes the same workload; test patch/prerelease/unknown versions, client/daemon mismatch, replacement and manifest drift. - Wrap the core owner in distinct MCP owned-program operations with opaque handles, bounded output pages, explicit cleanup and the same capability decisions. Keep the existing enrolled-shell
tmux_runprotocol and its process-cursor requirements explicit. Define the initial PR's exact gem/tool scope before implementation.
Acceptance needs private-daemon tests for literal argv, PTY/cwd/environment/geometry, fast exit and final output, status versus signal, input, cancelled setup/wait/owning run, concurrent waiters, retention, failed cleanup, respawn/restart refusal and observer release. Prove critical ownership, subscription and version-gate tests fail under deliberate breaks, and show sibling Async tasks remain responsive. Execute standalone command/interactive examples, installed-gem consumers, RBS/public API and documentation checks, and final-head CI for the affected gems.
Document merged stdout/stderr, screen/history bounds versus terminal bytes, stream gaps/backpressure, process-group/daemonization limits, owner-death recovery and filesystem locality. Terminal ownership does not provide filesystem, network or privilege confinement.
References
- Lifecycle(feat): Add owned tmux resource scopes #27 adds resource scopes; reconcile ownership seams without silently requiring unmerged code.
- Refuse Async::Server.open and make internal constructors private #96 changes Async constructor inheritance; coordinate factories with that work.
- Core library cannot wait for pane text on tmux 3.3a–3.6 #53 tracks core visible-text waits and Fill remaining standalone Core API showcase examples #86 requests standalone examples; readiness and application completion remain separate.
Activity
tony commentedon Nov 30, 2026
Two acceptance cases from the terminal tester would make the completion contract concrete:
fin caféand exited 7. Withremain-on-exit, the pane and exit status remained readable. The default viewport could show tmux’s exit banner while omitting the program line. A capture that included scrollback found it.Expose observed exit and signal separately and define the final screen’s bounds. These cases let a caller tell when the program has finished, what evidence is available, and how far back the returned screen reaches. Release command-result contract · Pane capture range handling
tony commentedon Dec 1, 2026
Core and Async share a program owner in the dedicated-daemon preview. The tests cover literal argv, input, resize, independent waits, exit status or signal, and bounded final terminal text. Draft PR
Final screen retention sets a tmux 3.7 floor for this preview. On 3.3a, six of 30 burst-output runs lost the final line despite an observed exit 0. A pipe-based experiment retained it on all 30 runs, with helper lifecycle and queue ordering still to verify. An independent probe retained the last line in 100 of 100 runs on each of 3.7 and 3.8.
The issue stays open for process-generation guards, borrowed-daemon ownership, descendant cleanup and MCP. The preview closes its dedicated terminal and daemon. A process that ignores SIGHUP or detaches can survive.
Tool use. Codex and Sol 6.2 developed and reviewed the preview and checked the native tmux and package test results.
tony commentedon Dec 5, 2026
Core and Async now own terminal programs on private and caller-owned tmux servers. The caller can send input, resize the terminal, wait for the exit or signal, and read the retained screen. The program requires tmux 3.7. On 3.6 the library refused the operation before starting a program. Merged change
The final checks used Ruby 4.0.7 with tmux 3.3a and 3.8. Both Linux cells passed 364 unit, 341 integration and eight installed-gem tests with zero skips. On 3.7, the installed examples returned the accented diagnostic with exit 7 and read the interactive reply.
The MCP capability report exposes availability and tool policy. The remaining MCP interface stays tracked here.
tony commentedon Dec 5, 2026
Core and Async 0.1.3 are on RubyGems. I ran both tagged Core examples from an isolated install on Linux arm64 with tmux 3.7 and 3.8. The failing migration returned status 7 and its final diagnostic. The interactive program received
café, printed its reply and exited 0. The release suite also exercised the Async facade. Core gem · Async gem · Program testsThe MCP gem reports the bound daemon’s capabilities and enabled tools. The owned-program handle and result-page interface in this proposal remains open. Core and Async callers can use the released API independently of the lifecycle draft in #27. Capability catalog · MCP tool catalog