Repository navigation
<
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
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-screenlooked like exactly the right tool, but it always returned empty text: thesurface.read_textV2 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
surfaceTerminalRegistry(surfaceId → live xtermTerminal), registered right afterterminal.open(), removed on unmount with a StrictMode-safe guard (only deletes if the entry still points at this instance).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 — viatranslateToString(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.surface.read_textnow resolves the surface through the existingresolvePtySurface()(so callers get the same clear "has no PTY" error as send_text/send_key instead of an empty success), clampslinesto 1–10000 (default 50), probes each window for the surface, and returns the renderer result.read-screen [--lines N] [--surface <id>], defaulting toWMUX_SURFACE_ID— identical targeting semantics tosend/send-key: inside a pane, bareread-screenreads your own pane; cross-pane scraping (the orchestration case) uses--surface; outside wmux it falls back to the active surface.surface.read_textmoved 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.wmux send(alt-buffer path).read-screenfrom outside wmux → active-surface fallback.