8000 feat(cli): implement wmux read-screen (surface.read_text was a stub) by tawman · Pull Request #76 · amirlehmam/wmux · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div id="diff-comparison-viewer-container" class="Container__qkpM1i tmp-mt-4 container-xl tmp-px-3 tmp-px-md-4 tmp-px-lg-5 pullRequestLayoutVariables__fZp87z ContainerSidePanel__47M93r" data-side-panel-open="false" data-hovercard-subject-tag="pull_request:4005234374">

feat(cli): implement wmux read-screen (surface.read_text was a stub) - #76

Merged
amirlehmam merged 1 commit into
amirlehmam:masterfrom
tawman:feature/wmux-read-screen
Jul 7, 2026
Merged

amirlehmam merged 1 commit into
amirlehmam:masterfrom
tawman:feature/wmux-read-screen

Conversation

@tawman
@tawman tawman commented Jul 7, 2026
Copy link
Copy Markdown
Contributor

Motivation

We use wmux heavily for multi-agent Claude Code orchestration, and coordinators regularly need to scrape sibling panes to verify an agent's actual state — did the prompt submit, is a TUI stuck, what error is on screen. wmux read-screen looked like exactly the right tool, but it always returned empty text: the surface.read_text V2 handler turned out to be a hardcoded stub that replied { text: "", note: "Screen reading requires renderer-side xterm serializer" } without ever calling into the renderer. This PR wires it up for real.

Implementation

  • useTerminal: module-level surfaceTerminalRegistry (surfaceId → live xterm Terminal), registered right after terminal.open(), removed on unmount with a StrictMode-safe guard (only deletes if the entry still points at this instance).
  • pipe-bridge: new window.__wmux_readScreen(surfaceId?, lines?) global. It reads the active buffer — alt buffer included, so a pane running a full-screen TUI (Claude Code, vim, tmux) returns what is actually visible — via translateToString(true): plain text, no ANSI escapes, which is what agents want. Returns the last N lines including scrollback with trailing blank lines trimmed, as { text, lines, surfaceId }, or { error } for markdown/browser/closed surfaces.
  • main: surface.read_text now resolves the surface through the existing resolvePtySurface() (so callers get the same clear "has no PTY" error as send_text/send_key instead of an empty success), clamps lines to 1–10000 (default 50), probes each window for the surface, and returns the renderer result.
  • CLI: read-screen [--lines N] [--surface <id>], defaulting to WMUX_SURFACE_ID — identical targeting semantics to send/send-key: inside a pane, bare read-screen reads your own pane; cross-pane scraping (the orchestration case) uses --surface; outside wmux it falls back to the active surface.
  • CLAUDE.md: surface.read_text moved out of "Partially implemented"; CLI reference updated.

Testing

  • npm run build:main, npx vite build, npm test (162/162) all green; no new lint errors.
  • Verified live against a dev instance:
    • Read a pane running the full-screen Claude Code TUI → clean plain text of the visible screen, including a marker string we injected via wmux send (alt-buffer path).
    • Bare read-screen from outside wmux → active-surface fallback.
    • Markdown surface and a bogus surface id → clear "has no PTY" errors, not silent empty output.

surface.read_text always returned empty text with a note asking for a
renderer-side serializer, so `wmux read-screen` never worked. Wire it up
for real:

- useTerminal: register live xterm instances in a module-level
  surfaceTerminalRegistry keyed by surfaceId (StrictMode-safe cleanup).
- pipe-bridge: new __wmux_readScreen global reading the ACTIVE buffer as
  plain text via translateToString (alt buffer included, so full-screen
  TUIs return what is actually visible; no ANSI escapes). Last N lines
  including scrollback, trailing blanks trimmed.
- main: surface.read_text resolves the surface via resolvePtySurface
  (clear errors for markdown/browser/closed surfaces), clamps lines to
  1..10000 (default 50), and delegates to the bridge global.
- CLI: read-screen gains --surface <id> and defaults to WMUX_SURFACE_ID,
  matching send/send-key targeting semantics.
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.

2 participants

0