Skip to content

Design question: intended input boundary for embedded PTY clients #155

Description

@schickling-assistant

@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:

  1. The embedding client owns decoding of its outer terminal input and keeps both exact raw bytes and a normalized semantic event.
  2. 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.
  3. PTY remains a byte-oriented session transport. Detach is an explicit control message, never inferred by scanning terminal data.
  4. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions