Architecture: Daemon → Headless → PTY
PTY-for-AI is built on three layers. Each layer does one thing and is independently replaceable.The Three Layers
Layer 1: PTY Daemon
The foundation. A persistent process that spawns and manages PTY sessions. Responsibility: Create terminal sessions, resize, close, list. Nothing more. Protocol (JSON over Unix socket):- Runs as OS service (launchd on macOS, systemd on Linux)
- Survives terminal closures, reboots, SSH disconnects
- Each session has its own Unix socket for I/O
- Supports
cwdandshellper session — this is how plugins work - Binary is never modified. All extension happens externally.
Layer 2: Headless Server
Bridges PTY sessions to the network without a GUI window. Responsibility: Connect to gateway, relay terminal I/O, manage grid state. What it does:- Creates a PTY session via daemon (Layer 1)
- Renders terminal grid (VTE parsing)
- Connects to gateway via WebSocket
- Relays input/output between gateway and PTY
- Accepts
--default-cwdand--default-shellfrom plugins
- No window. No UI. No display.
- Does not modify terminal content.
- Does not interpret commands.
Layer 3: Gateway / P2P
Remote access to headless sessions across machines and networks. Two paths:How Sessions Are Controlled
Persistence Model
- Terminal window closures
- SSH disconnects
- Network interruptions
- Application restarts
Plugin Injection Points
Plugins transform session parameters before they reach the daemon. The daemon never knows plugins exist.- Daemon binary never changes (stable, signed, tested)
- New plugins are added to the CLI layer only
- Plugin development doesn’t require daemon access
- Third-party plugins are possible (same interface)
What Each Layer Knows
| PTY Daemon | Headless | Gateway | |
|---|---|---|---|
| What CLI is running | ❌ | ❌ | ❌ |
| Session cwd | ✅ (at spawn) | ✅ (passes to daemon) | ❌ |
| Terminal content | ❌ (raw bytes) | ✅ (VTE parsed) | ✅ (relayed) |
| Network access | ❌ | ✅ | ✅ |
| Which LLM | ❌ | ❌ | ❌ |