Skip to content

contrib(feat): Drive terminal subprocesses - #142

Merged
tony merged 2 commits into
masterfrom
concept/terminal-subprocess
Dec 5, 2026
Merged

tony merged 2 commits into
masterfrom
concept/terminal-subprocess

Conversation

@tony

@tony tony commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Add libvt.contrib.subprocess (open_terminal, run_terminal, TerminalProcess, VT, Capture, CompletedTerminal, CalledTerminalError, TerminalTimeoutExpired) for driving terminal child processes from synchronous Python on POSIX PTYs (Linux, macOS via anonymous socketpair trampoline) and Windows ConPTY (ReleasePseudoConsole, Windows 11 24H2 / Server 2025 build 26100+).

  • Shares POSIX PTY setup helpers (_make_pty_terminal, _prepare_posix_env, _apply_pty_termios, _set_pty_winsize) from libvt.aio._pty.
  • Uses a decoupled daemon _TerminalOwner thread with weakref.finalize and atexit reaping so unclosed handles never hang interpreter exit.
  • Implements SupportsVtTarget, full outbound drain() parity (write_high_water=0), send_event(), Buffer inputs, chunked run_terminal(input=...), and LibVtError inheritance on CalledTerminalError and TerminalTimeoutExpired.
  • Documents both timeout families (TerminalTimeoutError vs TerminalTimeoutExpired), TerminalProcess attributes, and cross-platform doctests in docs/api/contrib/subprocess.md, docs/topics/architecture.md, docs/project/public-api.md, README.md, AGENTS.md, and CHANGES.

Fixes #106

@tony
tony force-pushed the concept/terminal-subprocess branch from e56a9c8 to d933bf1 Compare December 1, 2026 03:33
tony added a commit that referenced this pull request Dec 3, 2026
why: Record the branch's user-visible change in the unreleased notes.

what:
- Add the #142 entry under What's new in CHANGES
@tony
tony force-pushed the concept/terminal-subprocess branch from d933bf1 to 19200f7 Compare December 3, 2026 02:55
@tony
tony force-pushed the concept/terminal-subprocess branch from 19200f7 to 4e848c1 Compare December 3, 2026 23:58
tony added a commit that referenced this pull request Dec 5, 2026
why: Synchronous callers need to exchange input and frames with a child.

what:
- Expose the terminal subprocess context manager and its PTY adapters.
- Honor the caller's temporary directory for terminal socket setup.
- Exercise teardown and frame reads through the public API.

Adapted from #142 at 4e848c1.
@tony
tony force-pushed the concept/terminal-subprocess branch from a90f825 to 23b7f2c Compare December 5, 2026 14:56
@tony
tony force-pushed the concept/terminal-subprocess branch from 23b7f2c to dcf6243 Compare December 5, 2026 15:06
@tony
tony force-pushed the concept/terminal-subprocess branch from dcf6243 to 6776ee2 Compare December 5, 2026 15:27
why: Reuse terminal initialization, slave PTY configuration, and
reader attachment between open_pty and the Darwin session-leader
launcher without duplicating termios or OSC 7 setup.

what:
- Extract _resolve_python_executable, _make_pty_terminal,
  _prepare_pty_fds, and _child_pty_env in libvt.aio._pty.
- Add PtySession._start_reading and call it from open_pty.
@tony
tony marked this pull request as ready for review December 5, 2026 18:05
@tony
tony force-pushed the concept/terminal-subprocess branch from 6776ee2 to 7ff8a33 Compare December 5, 2026 18:05
@tony tony changed the title Concept: Drive terminal subprocesses from synchronous Python contrib(feat): Drive terminal subprocesses Dec 5, 2026
@tony
tony force-pushed the concept/terminal-subprocess branch from 7ff8a33 to 4fb89d2 Compare December 5, 2026 18:08
why: Synchronous callers and test suites need a direct way to spawn
interactive programs inside a POSIX PTY or Windows ConPTY, wait for
committed frames, send keys or mouse events, drain backpressure, and
reap children without managing an asyncio event loop.

what:
- Add libvt.contrib.subprocess with open_terminal(), run_terminal(),
  VT, Capture, CompletedTerminal, TerminalProcess (with send_event(),
  drain(), Buffer inputs, SupportsVtTarget, and LibVtError-derived
  exceptions), backed by a decoupled daemon _TerminalOwner with
  weakref.finalize and atexit shutdown so unclosed handles never hang.
- Add single-trampoline macOS socketpair helper (_darwin_pty.py) with
  race-safe child.kill() handling and pure-Python ctypes ConPTY helper
  (_conpty.py) sharing _make_pty_terminal, reply flushing, and sync
  timer updates.
- Add unit, PTY, Darwin helper, and import-isolation tests in
  tests/test_subprocess.py, API docs in docs/api/contrib/subprocess.md,
  README/architecture/AGENTS/public-api updates, and a CHANGES entry.

Fixes #106
@tony
tony force-pushed the concept/terminal-subprocess branch from 4fb89d2 to 84b0285 Compare December 5, 2026 18:11
@tony
tony merged commit d577976 into master Dec 5, 2026
9 checks passed
@tony
tony deleted the concept/terminal-subprocess branch December 5, 2026 18:16
@tony tony mentioned this pull request Dec 5, 2026
35 of 38 tasks

This branch was successfully deployed

1 active deployment
docs — 84b02851 Deployed Dec 5, 2026 by tony via build (3.14) #530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offer typed terminal control alongside ordinary subprocess calls

1 participant