Skip to content

Run owned terminal programs through core and Async #122

Open

Description

@tony

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 and run_program, returning a Program with 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::Capabilities and reuse Expose the capability map through the public API #112 for public discovery and tmux_capabilities does 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_run protocol 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

Activity

  1. tony commented on Nov 30, 2026

    @tony
    ContributorAuthor

    Two acceptance cases from the terminal tester would make the completion contract concrete:

    • On tmux 3.3a and 3.6a, a child that closed its terminal before exiting was visible as dead while the numeric exit status was still absent. The corrected consumer kept its existing deadline active until it observed exit 7. The same check on 3.8 saw 7 at the first dead observation. The verifier also rejected an expected-0 mismatch and separately observed signal 15.
    • A short program printed fin café and exited 7. With remain-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

  2. added
    potential high value
    on Dec 1, 2026
  3. tony commented on Dec 1, 2026

    @tony
    ContributorAuthor

    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.

  4. tony commented on Dec 5, 2026

    @tony
    ContributorAuthor

    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.

  5. tony commented on Dec 5, 2026

    @tony
    ContributorAuthor

    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 tests

    The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    potential high value

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions