feat: add pty_snapshot and pty_snapshot_wait tools with seq-based diffing#31
Open
JosXa wants to merge 4 commits intoshekohex:mainfrom
Open
feat: add pty_snapshot and pty_snapshot_wait tools with seq-based diffing#31JosXa wants to merge 4 commits intoshekohex:mainfrom
JosXa wants to merge 4 commits intoshekohex:mainfrom
Conversation
added 2 commits
April 2, 2026 01:13
Add a headless terminal emulator (@xterm/headless) to each PTY session that processes raw output in parallel with the existing ring buffer. This enables clean, ANSI-free screen capture via a new pty_snapshot tool. The snapshot returns the visible terminal screen text, cursor position, terminal size, and a content hash for efficient change detection - useful for monitoring TUI applications during development. Also improves the web UI plain-text buffer endpoint to use the parsed screen instead of naive ANSI regex stripping.
- pty_snapshot_wait: blocks until search regex matches or screen stabilizes (hashStableMs) - seq-based history: each content change gets a monotonic sequence number - since parameter on both tools: returns line-level diff against historical frame - Ring buffer of 200 deduped snapshots per session for diffing - LineDiff format: changed/added/removed lines with content and line numbers
- Document snapshot and snapshot_wait tools in tools table - Add usage examples for screen capture, seq-based diffs, and conditional waiting - Add 'Debugging OpenCode itself' walkthrough as a real-world use case - Update 'How It Works' section with snapshot/diff/wait pipeline - Add xterm.js to credits
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.
Summary
Adds
pty_snapshotandpty_snapshot_waittools that capture the parsed visible terminal screen of any PTY session, with seq-based history and line-level diffing. Complements the existingpty_readtool which returns the raw output buffer (ANSI codes and all).Motivation
When using
pty_readon TUI applications like OpenCode itself, the output is an unreadable flood of ANSI escape sequences, cursor movements, and control characters. This makes it impossible for AI agents to understand what is actually displayed on screen.pty_snapshotsolves this by maintaining a headless terminal emulator (@xterm/headless) alongside each PTY session, producing clean screen captures that look exactly like what a human would see.What is included
pty_snapshottoolsinceparameter: pass a previous seq to get only changed lines (line-level diff) instead of the full screenpty_snapshot_waittoolsearch: regex pattern against screen text, resolves on first matchhashStableMs: resolves when screen content is unchanged for N millisecondstimeout: max wait (default 30s)sincefor diff outputSeq-based history
historyTruncatedflagOther improvements
Example: full snapshot
Example: diff since seq 3
Implementation details
@xterm/headless(same terminal emulation as VS Code terminal)waitForConditionpolls at 100ms intervals, checks search regex and/or hash stability