@myobie, I would appreciate a design check before we extend the embedding protocol further: where is key interpretation intended to live for a terminal UI embedding a PTY session?
The concrete consumer is Fractal, which embeds a live session inside another terminal application. We have two independent findings:
- Alt+Left arrives from the outer terminal as
ESC b, and direct pty attach delivers those bytes unchanged. Fractal currently reads a semantic Crossterm event and reconstructs only b, so that loss is in the embedding client rather than PTY.
- PTY's interactive attach path is not byte-transparent today. It converts input
Buffer -> string -> Buffer and scans 0x1c for detach. At current main (025a9034), bytes 1b 62 ff 00 become 1b 62 ef bf bd 00.
Our current candidate design is:
- The embedding client owns decoding of its outer terminal input and keeps both exact raw bytes and a normalized semantic event.
- A mode-aware codec reuses raw bytes only when the outer and child input modes are compatible; otherwise it re-encodes the semantic event for the child.
- PTY remains a byte-oriented session transport. Detach is an explicit control message, never inferred by scanning terminal data.
- Attach admission, initial geometry/mode/screen state, updates, and the terminal outcome are ordered on one generation-bound connection.
Before implementing that, is this the intended responsibility split, or is there a simpler supported pattern we should use?
In particular:
- Should a non-TypeScript embedder speak the existing daemon packet protocol directly (the conceptual equivalent of
SessionConnection) and add only the missing byte-safe/generation-bound pieces?
- Or should machine attach grow one bidirectional framed channel so embedders never need to own the daemon protocol?
- Should PTY expose only ordered child-mode state while the embedder owns key decoding/re-encoding, or is PTY intended to own more of that translation?
- Is an explicit detach frame the intended replacement for the interactive CLI's
Ctrl-\\ byte interception in an embedded path?
- Should older daemons reject the new embedded contract explicitly, without automatic restart or a legacy fallback?
This is a design question, not yet a request for a particular v2 protocol. Related work already covers incarnation binding (#121), mode visibility (#130), ordered effective geometry (#134), terminal detach outcomes (#151), and PTY's named-key encoder (#13). I would like to avoid introducing a parallel abstraction if those are meant to compose into a simpler embedding API.
Current direction (2026-08-03)
The investigation changed the priority, but not the responsibility split above. pty-layout is strong evidence that the current PTY protocol already supports a useful compositor locally and through pty-relay over SSH and WebSocket. The first step is therefore to improve and test clients against the current protocol. Machine attach v2 is not a prerequisite for making Fractal useful.
The original v2 questions remain useful as possible answers to proven ordering or lifecycle gaps. They are no longer assumptions that block current-protocol client work.
@myobie, I would appreciate a design check before we extend the embedding protocol further: where is key interpretation intended to live for a terminal UI embedding a PTY session?
The concrete consumer is Fractal, which embeds a live session inside another terminal application. We have two independent findings:
ESC b, and directpty attachdelivers those bytes unchanged. Fractal currently reads a semantic Crossterm event and reconstructs onlyb, so that loss is in the embedding client rather than PTY.Buffer -> string -> Bufferand scans0x1cfor detach. At currentmain(025a9034), bytes1b 62 ff 00become1b 62 ef bf bd 00.Our current candidate design is:
Before implementing that, is this the intended responsibility split, or is there a simpler supported pattern we should use?
In particular:
SessionConnection) and add only the missing byte-safe/generation-bound pieces?Ctrl-\\byte interception in an embedded path?This is a design question, not yet a request for a particular v2 protocol. Related work already covers incarnation binding (#121), mode visibility (#130), ordered effective geometry (#134), terminal detach outcomes (#151), and PTY's named-key encoder (#13). I would like to avoid introducing a parallel abstraction if those are meant to compose into a simpler embedding API.
Current direction (2026-08-03)
The investigation changed the priority, but not the responsibility split above. pty-layout is strong evidence that the current PTY protocol already supports a useful compositor locally and through pty-relay over SSH and WebSocket. The first step is therefore to improve and test clients against the current protocol. Machine attach v2 is not a prerequisite for making Fractal useful.
pty attachand embedded clients share the same tested input behavior where possible, as Nathan suggested.The original v2 questions remain useful as possible answers to proven ordering or lifecycle gaps. They are no longer assumptions that block current-protocol client work.