# The front-end protocol `splinter --serve` runs the engine on a Unix socket. Everything a front end needs — the transcript, the reasoning as it streams, tool calls, approval questions, slash commands, model and profile switches — arrives as one JSON object per line. The curses interface uses the same engine in-process through `include/splinter_engine.h`; this socket is the same boundary for programs that are not C. ``` splinter --serve [--socket PATH] ``` The default socket is `$SPLINTER_SOCKET`, else `~/.splinter/splinter.sock`. The file is created mode `0600` and the server refuses a peer whose uid is not the owner's: this conversation may run `run` with the owner's rights. The reference client is `splinterctl`; `docs/proto-example.py` is a 60-line Python client that shows the whole loop. `splinter --attach` is the complete curses front end speaking this protocol, so anything the screen can do is reachable over the socket by design. If its connection drops, `--attach` reconnects and asks for the session it was on with `open`; a GUI can do the same. ## Framing * One JSON object per line, UTF-8, `\n` terminated. No arrays, no envelope. * Server → client objects have `"ev"`; client → server objects have `"cmd"`. * Unknown fields are ignored. Unknown `cmd` answers with an `error` event. * `"protocol": 2` in the greeting is the format version. It changes only when a field changes meaning; new fields are added without a bump. One client at a time. The server holds one active engine, so one conversation runs; `open` switches it, it does not run two. A second writer on the same engine would be a second history. When a client disconnects in the middle of a turn, the server cancels the turn (an approval nobody can answer would otherwise park the engine forever) and accepts the next client. ## Sequence ``` client server | connect | |<-- {"ev":"ready","protocol":2,...} | | {"cmd":"commands"} / {"cmd":"history"} | |<-- {"ev":"state",...} | |<-- {"ev":"commands","names":[...]} | |<-- {"ev":"history","items":[...]} | | {"cmd":"input","line":"hallo"} | |<-- {"ev":"submitted","text":"hallo"}| |<-- {"ev":"busy","on":true} | |<-- {"ev":"stream","kind":"think",..}| (only with a reasoning model) |<-- {"ev":"stream","kind":"text",..} | |<-- {"ev":"step","think":..,"text":..} |<-- {"ev":"tool","name":"run",...} | |<-- {"ev":"approval","name":"run",..}| (a mutating tool) | {"cmd":"approve","allow":true} | |<-- {"ev":"tool_result",...} | |<-- {"ev":"stream","kind":"text",..} | |<-- {"ev":"turn","ok":true,...} | |<-- {"ev":"state",...} | |<-- {"ev":"busy","on":false} | ``` `stream` chunks are deltas: append them. `step` marks the end of one model step at a tool call; it carries the step's whole reasoning and answer, so a client that lost a chunk can repair from it. The final answer of the turn is in `turn.answer` (the last step's text, which is also the last `stream` text). A `turn` event does not by itself mean the engine is idle. A steer that was typed too late for a step boundary becomes a second turn in the same busy period: another `entry` (`you`), more `stream`/`turn` events, and only then `busy:false`. A client finishes its work when `busy.on` is `false`, not at the first `turn`; each `turn` is one answer to show. ## Client → server ### `{"cmd":"input","line":"..."}` The universal entry point: exactly what the operator typed. * A slash command (`/model`, `/status`, `/agent plan`, …) answers with a `reply` event and does not start a turn. * A prompt starts a turn: `submitted`, then the turn events. * `!command` runs a shell; its output arrives as an `entry` with `"role":"shell"`. * A program in `~/.splinter/commands/` replaces the line with its output and starts a turn with it (`submitted` carries the text). The server refuses this command with an `error` while a turn is running; the transcript is the engine's, not a client's scratchpad. ### `{"cmd":"say","text":"..."}` Start a turn directly, without command interpretation. The client has already decided this is a prompt (for example from its own input field). ### `{"cmd":"command","line":"/..."}` Alias of `input`; kept because a client that has a command palette knows what it is sending. ### `{"cmd":"approve","allow":true}` Answer the open approval question. `false` denies; the denial becomes the observation the model sees (it is not silent). ### `{"cmd":"cancel"}` Cancel the running turn. The engine sets its flag; every transport kills the child process or the `curl` it started. The turn then ends with `"ev":"turn","ok":false`. ### `{"cmd":"steer","text":"..."}` Text typed while the turn runs. The loop picks it up at the next step boundary and puts it into the conversation; a step that has already ended cannot be interrupted. If no turn runs, the answer is an `error`. ### `{"cmd":"state"}` Ask for a `state` event. Useful after a reconnect. ### `{"cmd":"history"}` Ask for the transcript so far: `"ev":"history"`, `"truncated":bool`, `"items":[{"role":"user","text":"..."}, {"role":"assistant",...}]`. The last 100 messages and 256 KiB are sent; a client that attaches shows the session it joins instead of an empty pane. The system prompt and tool observations stay out — this is what the person and the model said. ### `{"cmd":"sessions"}` List the sessions in the server's session directory, newest first: `"ev":"sessions"`, `"items":[{"id","title","mtime","bytes","current"}]`. `title` is the first user line or what `/rename` set (empty when there is no message yet), `current` marks the session the connection is on. ### `{"cmd":"open","session":"ID"}` Switch this connection to another session. `"new"` starts a fresh one, `"last"` the newest, an id continues that file. The server sends `ready`, `state`, `commands`, `history` and finally `"ev":"opened"` with the new `session` and `dir`; the old engine is closed first, so plugins are not doubled. While a turn runs the command is refused. An unknown id is an error and the connection stays on its session. `{"cmd":"input","line":"/rename [ID] TITLE"}` names the current session (or the one named by ID), and `{"cmd":"input","line":"/rm ID"}` removes a session that is not the open one: its JSONL, sidecars and `