Skip to content

vt(feat[libvt]): Add optional VT integration - #934

Open
tony wants to merge 4 commits into
masterfrom
feat-933-vt
Open

tony wants to merge 4 commits into
masterfrom
feat-933-vt

Conversation

@tony

@tony tony commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add the optional libtmux[vt] extra on Python 3.12+ without changing core runtime dependencies.
  • Add Pane.capture_vt() for single-batch reconstruction of pane cells, SGR styles, modes, and scrollback.
  • Add Session.observe_vt() and Pane.observe_vt() for multiplexed raw-byte tmux -C pane synchronization with tear-free ?2026 wait_until() Snapshot predicates and FlightRecorder timeout diagnostics.
  • Add Pane.send_vt_input() and VtPaneHandle.send_input() for mode-aware keyboard, mouse (?1006 and ?1016), focus, and paste encoding, gated by tmux release capabilities for one-shot paste (3.7+) and focus (3.8+).
  • Add the vt_observer pytest fixture plus assert_pane_screen() and assert_pane_screen_box() test helpers.

Closes #933 (parent: #932; companion: #937, tmux-python/tmuxp#1118). Plain-string pane capture drops cell geometry, SGR attributes, cursor visibility, active DEC private modes, and primary scrollback saved behind alternate-screen TUIs, while text-decoded control-mode pipes cannot safely carry split multi-byte UTF-8 %output streams.

Changes

Packaging and lazy boundary

  • pyproject.toml and uv.lock: declare the optional vt extra (libvt>=0.0.1a6,<0.1; python_version >= '3.12'), allowlist unresolved libvt imports under [tool.ty.analysis] for Python 3.11 and core environments, exclude libvt from the uv release-age cooldown, and scope BLE001 to src/libtmux/vt.py's background reader task.
  • src/libtmux/vt.py: defer importing libvt inside _require_libvt() until call time, keeping import libtmux, import libtmux.pytest_plugin, and import libtmux.vt free of libvt on Python 3.11+ installations.

Atomic capture, live control-mode sync, and mode-aware input

  • src/libtmux/vt.py: implement capture_pane_vt(), send_pane_vt_input() (preserving Terminal ?1016 pixel dimensions and refusing one-shot PasteEvent below tmux 3.7 and FocusEvent below tmux 3.8 with VersionTooLow when no live observer is supplied), VtPaneHandle (including a per-pane FlightRecorder ring buffer), VtSessionObserver (draining stderr, routing control events across TmuxPaneSync state machines, framing direct commands with reply markers, and isolating OUT_OF_SCOPE and per-pane ProtocolError failures), observe_pane_vt(), assert_pane_screen(), and assert_pane_screen_box().
  • src/libtmux/_internal/support/capabilities.py and capabilities.json: add bracket-paste-format (3.7) and pane-private-modes-format (3.8) one-shot refusal capabilities for Pane.send_vt_input() and send_pane_vt_input().
  • src/libtmux/pane.py: expose Pane.capture_vt(), Pane.observe_vt(), and Pane.send_vt_input().
  • src/libtmux/session.py: expose Session.observe_vt().

Testing, pytest plugin, and documentation

  • src/libtmux/pytest_plugin.py: add VtObserverFactory and the vt_observer fixture.
  • tests/test_vt.py, tests/test_capabilities.py, and tests/test_docs_capabilities.py: exercise lazy import guards, Pane.capture_vt(), multiplexed VtSessionObserver resizes, in-place resync(), per-operation %error attribution, ?2026 tear-free wait_until() Snapshot predicates and stalled-hold expiry, FlightRecorder recent_bytes timeout diagnostics, mode-aware send-keys -H input, capability release gates and Sphinx cross-references, and boxed screen assertions against live tmux servers.
  • docs/api/libtmux.vt.md, docs/api/index.md, docs/api/testing/pytest-plugin/fixtures.md, and CHANGES: document libtmux.vt (including its provisional pre-0.1 libvt status, synchronous capture examples, and an executable recipe for testing interactive tmux applications), vt_observer, and the libtmux[vt] extra.

Design decisions

  • Read raw bytes in VtSessionObserver via asyncio.create_subprocess_exec and feed TmuxControlParser directly, because ControlMode opens stdout with text=True whereas tmux -C %output splits multi-byte UTF-8 codepoints across lines and escapes control bytes as octal \ooo.
  • Route control events through marker-framed TmuxPaneSync batches and queue VtPaneHandle.send_input() commands FIFO on VtSessionObserver so concurrent watch_pane(), resync(), and send_input() calls share one tmux -C subprocess with per-operation %begin/%end/%error attribution, stderr diagnostics, and isolated per-pane recovery.
  • Evaluate VtPaneHandle.wait_until() predicates against Terminal.committed (Snapshot) and return that exact Snapshot (with automatic stalled-?2026 hold expiry and per-pane FlightRecorder byte disassembly on timeout) so predicates never observe or return torn mid-frame screens.
  • Raise VersionTooLow from send_pane_vt_input() when terminal=None below tmux 3.7 (PasteEvent) or 3.8 (FocusEvent), because #{bracket_paste_flag} and #{pane_private_modes} are absent there.
  • Defer importing libvt behind PEP 508 markers and _require_libvt() at call time to preserve Python 3.11 compatibility and zero mandatory dependencies for core libtmux.

Test plan

  • Verify lazy import isolation, Python 3.11 guard, and missing-extra error message in tests/test_vt.py::test_vt_packaging_lazy_import_and_runtime_guards
  • Verify SGR cell styles, wide CJK graphemes, bounded scrollback, saved primary history behind ?1049h, structured libtmux.common logging, and dead-pane error propagation in tests/test_vt.py::test_pane_capture_vt_cells_styles_history_alt_screen_and_logging
  • Verify multiplexed pane streaming, split UTF-8 output, passive query suppression, %layout-change window resize handling, and in-place resync() epoch tracking in tests/test_vt.py::test_vt_session_observer_multiplex_resize_resync_and_logging
  • Verify per-operation %error attribution, unattached-handle cleanup, ?2026 tear-free wait_until() Snapshot predicates, stalled-hold expiry, and FlightRecorder recent_bytes timeout diagnostics in tests/test_vt.py::test_vt_observer_error_attribution_and_cleanup
  • Verify DECCKM application cursor keys, ?2004 bracketed paste sanitization and framing, one-shot VersionTooLow capability gates, and ?1006 / ?1016 mouse events in tests/test_vt.py::test_send_vt_input_mode_aware_keys_paste_and_mouse
  • Verify capability manifest sync, release-table gates, and Sphinx cross-references in tests/test_capabilities.py and tests/test_docs_capabilities.py
  • Verify assert_pane_screen() and assert_pane_screen_box() pass and mismatch diagnostics in tests/test_vt.py::test_assert_pane_screen_and_box_helpers
  • Check formatting, ANN lint rules, strict types (3.11 and 3.15), doctests, and Sphinx links with uv run ruff format . .github/scripts --check, uv run ruff check . .github/scripts, uv run ty check, uv run ty check --python-version 3.15, uv run pytest, and just build-docs

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.19400% with 169 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.84%. Comparing base (71bdbe2) to head (a342546).

Files with missing lines Patch % Lines
src/libtmux/vt.py 70.36% 115 Missing and 48 partials ⚠️
src/libtmux/pane.py 66.66% 3 Missing ⚠️
src/libtmux/pytest_plugin.py 60.00% 2 Missing ⚠️
src/libtmux/session.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #934      +/-   ##
==========================================
+ Coverage   62.05%   62.84%   +0.79%     
==========================================
  Files          29       30       +1     
  Lines        5091     5658     +567     
  Branches     1082     1181      +99     
==========================================
+ Hits         3159     3556     +397     
- Misses       1592     1715     +123     
- Partials      340      387      +47     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
tony added this pull request to stack #938 November 29, 2026 16:23
tony added a commit that referenced this pull request Nov 29, 2026
why: WRITING.md places pull-request references in deliverable headings
rather than repeating them at paragraph ends.

what:
- Remove duplicate trailing (#934) references in CHANGES
@tony tony changed the title vt(feat[libvt]): Add optional libtmux[vt] capture, sync, and input vt(feat[libvt]): Add optional VT integration Nov 30, 2026
@tony
tony force-pushed the feat-933-vt branch 3 times, most recently from 153747b to f619e06 Compare November 30, 2026 01:57
@tony tony added the area: observation Waits, capture, snapshots, subscriptions label Dec 5, 2026
@tony tony added this to the 0.73.0 milestone Dec 5, 2026
@tony
tony force-pushed the feat-933-vt branch 2 times, most recently from 1a6c4be to 13958b6 Compare December 5, 2026 18:41
tony added 3 commits December 5, 2026 16:53
why: Plain-string capture-pane output drops cell geometry, SGR styles,
cursor visibility, DEC private modes, and saved primary scrollback
behind alternate-screen TUIs, while text-decoded control-mode pipes
cannot safely carry split multi-byte UTF-8 %output streams.

what:
- Add the optional libtmux[vt] extra (libvt>=0.0.1a4,<0.1 on Python
  3.12+) with lazy _require_libvt() loading and ty unresolved-import
  allowlisting so core libtmux and Python 3.11 stay dependency-free.
- Add Pane.capture_vt() and capture_pane_vt() for single-batch pane
  reconstruction, plus assert_pane_screen() and
  assert_pane_screen_box().
- Add Session.observe_vt(), Pane.observe_vt(), VtSessionObserver,
  VtPaneHandle, and the vt_observer pytest fixture with FIFO command
  and handshake queueing, stderr draining, ?2026 tear-free wait_until()
  Snapshot predicates, stalled-hold expiry, and FlightRecorder timeout
  reports.
- Add Pane.send_vt_input() and VtPaneHandle.send_input() with
  mode-aware key, mouse (?1006/?1016), focus, and bracketed-paste
  encoding and tmux 3.7/3.8 one-shot capability refusal gates.
- Document libtmux.vt with synchronous capture and interactive TUI
  lifecycle doctest recipes.
why:
libvt 0.0.1a6 is published on PyPI with marker-framed TmuxPaneSync
batches, native layout-change recapture, OUT_OF_SCOPE detection, and
updated boxed step diff formatting.

what:
- Bump libvt extra requirement to >=0.0.1a6,<0.1 and refresh uv.lock
  against PyPI libvt 0.0.1a6.
- Update VtSessionObserver to route control events to every TmuxPaneSync,
  frame direct commands with reply markers, and handle OUT_OF_SCOPE and
  per-pane ProtocolError isolation without closing sibling panes.
- Update the boxed step diff styles line in docs/api/libtmux.vt.md.
why: Record optional libtmux[vt] terminal capture and observation.

what:
- Add unreleased 0.73.0 feature notes for #932 and #934.
why: libvt 0.0.1a7 is published on PyPI.

what:
- Bump libvt extra requirement from >=0.0.1a6,<0.1 to >=0.0.1a7,<0.1
- Refresh uv.lock against PyPI libvt 0.0.1a7

This branch has not been deployed

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

Labels

area: observation Waits, capture, snapshots, subscriptions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prototype libtmux[vt] capture, -C sync, input, and test helpers

1 participant