Repository navigation
Add interactive terminal support (pty.attach, persistent_pty.attach) - #11
Merged
Merged
Conversation
Implements the two WebSocket endpoints the generator omits (pty.connect and persistentPty.connect) as hand-written mixins on the generated resources, with sync and asyncio connections built on the optional websockets extra.
shrijayan
force-pushed
the
feat/pty-attach
branch
from
October 22, 2026 09:58
30442b0 to
2f62c9f
Compare
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.
Implements the two WebSocket endpoints the generator omits:
pty.connectandpersistentPty.connect(OpenCode v2.1.2).client.pty.attach(pty_id, cursor=...)andclient.experimental.persistent_pty.attach(pty_id, cursor=, role=, attachment_id=, takeover=, on_event=)returnPtyConnection/AsyncPtyConnectionwithsend,resize,recv, iteration,closeand context-manager support. Async is asyncio-only.pip install "opencode-python-sdk[pty]"(websockets>=14,<17), imported lazily; missing →PtyConnectionErrorwith install hint.codegen/render.pygains aMIXINStable so generated resources inherit the hand-writtenopencode/_pty.pymixins.examples/terminal.pybridges a local TTY to a remote PTY; README section.echo hitest. Lowest-deps CI job now installs.[pty].Protocol implemented
POST …/connect-tokenwithx-opencode-ticket: 1→ single-use 60 s ticket passed as?ticket=. Basic auth is also sent on the handshake.pty.connect: querylocation[directory],cursor(-1skips replay),ticket. Server sends replay (text, 64 KiB chunks), then a binary control frame0x00+{"cursor":n}, then live text output. Input: UTF-8 text/binary. Resize viaPUT /api/pty/:id.persistentPty.connect: queryticket,cursor(byte offset),role(controller|observer),attachment_id,takeover,input_protocol=1. Text frames are JSON events (attachedfirst,replay_complete,resized,controller_changed, …); binary frames are output. Input frames:u8 type(0 control/resize, 1 input) + big-endianu16 cols,u16 rows+ payload.cursortracks endOffset + output bytes for resume.PtyConnectionError).Verified live against opencode 2.1.2 for both endpoints. Do not merge without review (merges release to PyPI).