Harness adapter contract
On this page
Harness adapter contract#
Wakterm runs coding agents such as Claude Code, Codex, agy, Gemini CLI, OpenCode, ZCode, Devin, Muse and endchat as terminal programs in panes it owns. This page describes the end state for how Wakterm observes and drives them: one adapter per harness, fed by the channels each harness offers in a fixed order of authority, with the pane's screen read only for facts no other channel records. consolidation-roadmap.md items 1, 2 and 7 are the steps toward it.
What an adapter provides#
Each harness has one adapter in mux/src/harness/<name>/, which both observes its pane and drives it. From one read of its channels it produces one snapshot, replaced whole, and the durable events, with presentation state such as seen_at kept apart:
- Turn boundaries: the turn's ID, its phase (idle, working, waiting for background work, or blocked on the user), what started it, how it ended (completed, interrupted, ended by an API error, stopped by a hook, or ended with its process) and its final reply.
- Input membership: whether each input started a turn, was taken into a running one, is queued for the next, or was dropped, and why.
- Dialog state: an open permission, question, authentication or survey dialog, with its prompt and the choices Wakterm may answer. Choices that change the harness's permissions beyond the request, such as "always allow", are left to the pane.
- Input box state: ready, holding text someone is typing, blocked by a dialog, or blocked by a mode such as a shell mode.
- Driving: delivering a prompt, steering a running turn, and answering a dialog.
- Channel health: each channel the adapter relies on is healthy or reports drift.
Every fact carries the channel it came from and the process incarnation it belongs to.
Channels in order of authority#
Each fact has exactly one authoritative channel. A lower channel only fills a gap a higher one declares, and never overrides it.
| Priority | Channel | Authoritative for |
|---|---|---|
| 1 | The provider's own protocol for the same session, such as Codex's app-server | everything it reports, while the harness's terminal UI and Wakterm share the session |
| 2 | Escape sequences the harness writes to its terminal, such as agy's OSC 7501 | live state: working, blocked and on what, idle |
| 3 | Hooks the harness runs, such as Claude Code's hook journal | edges the records below miss or lag behind: a turn's end and its reply, a dialog opening, a session's file changing |
| 4 | Transcripts, databases and logs | durable history, turn boundaries, which turn each input joined, recovery after a restart |
| 5 | The pane's screen | never turns, input membership or whether a dialog is open |
The screen is read for two facts only: text in the input box that has not been sent, and a dialog's choices when a higher channel reports the dialog without listing them. A dialog's choices are read only while a channel of priority 1 to 3 reports it open; if they cannot be read then, the pane stays blocked with unknown choices, and consumers are told to answer in the pane. A screen parser returns input box or dialog state, never turn events.
Before a channel is relied on#
- Fixtures captured from the live harness, with its version: raw escape sequences, hook payloads, transcript rows, log lines and screens. Synthetic tests cover edge cases, never a channel's main format, and a format described from reading a harness's code is checked against a capture before a parser depends on it.
- Proof for each process that the channel works, such as the harness answering a query or a hook reporting its session's start; until then the adapter uses the channels below it.
- A period running beside the current readers with their disagreements explained, and, for anything in the harness's live path such as a hook recorder, tests showing that its failure changes nothing the harness does.
- Drift reported visibly: unknown values on a channel in use, or a reported dialog whose choices cannot be read, mark the agent degraded rather than being ignored.
Driving and its results#
Delivering a prompt, steering and answering a dialog are one operation on the server, serialized per pane, with a policy saying whether the agent must be idle or may be working, and the incarnation, turn or dialog it is meant for. It uses the harness's most reliable channel: the provider's protocol where there is one, otherwise keys typed into the pane after the checks above, confirmed through an authoritative channel. Every caller receives one of:
- Refused before writing, with the reason: nothing was sent, so the caller may retry.
- Submitted, with the turn it started or joined.
- Queued, into the running turn or for the next.
- Written but unconfirmed: keys were sent and no channel confirmed them, so the caller must not resend blindly.
- Indeterminate, with the reason.
Harnesses#
- Codex: its app-server for the session is the authority for turns, input, approvals and driving.
- Claude Code: the transcript for turns and input membership; the hook journal Wakterm passes with
--settingsfor live ends, replies, background tasks, waits on the user and file changes; the screen for question choices and the input box. claude-turn-records.md lists the records. - agy: OSC 7501 for live state, enabled by answering agy's query and by
AGY_CLI_OSC7501=onat launch; its CLI log for which prompt is open and for confirming input; its transcript for turns; the screen for a prompt's choices and the input box. Its local API may later replace keys for agy that Wakterm launches, once a live test shows agy's terminal UI stays in step with it. - Gemini CLI, OpenCode, ZCode, Devin, Muse and endchat move to the contract one at a time, each after its channels are inventoried and captured.