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

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions