- sp_engine_switch(): close the old engine and open the chosen session from the same options; if the new one fails, reopen the session the engine was on. The protocol's open and the in-process /open both use it. The curses screen clears the pane and replays the new history, so /open no longer says it needs --attach. - gateway: temperature, top_p and max_tokens (max_completion_tokens) are forwarded to the provider instead of dropped; request bodies may be Transfer-Encoding: chunked; a mixed reply runs the gw_ calls, returns the caller's calls in tool_calls and puts the local observations in content (also in the SSE delta), so the caller can echo them back. - reconnect: when the remembered session is gone, the screen says which one and stays on the session the server has instead of silently swapping the transcript. - ring: the exits' transports are disposed on plugin shutdown. - /status goes through the catalogues like the rest of the UI (the English labels and their alignment are unchanged, so existing parsers still work). - the man page passes mandoc -Tlint and covers the gateway and /open. Tests: test_ui.sh covers local /sessions and /open (new, back, history), test_protocol.sh the shared switch, test_reconnect.sh a vanished session, test_gateway_openai.sh forwarded parameters, a chunked body and the mixed reply in JSON and SSE. make check green.
6.1 KiB
Backend and front ends
splinter is split in two so that the screen is not the harness.
+-----------------------+
a keyboard ---> | front end (curses) | ---\
+-----------------------+ \
\ +----------------+
a socket ---> | front end (protocol) | --------> | the engine |
+-----------------------+ / +----------------+
/ agent, tools,
-p / --daemon --> | direct library use | ---/ transports,
+-----------------------+ session, config,
plugins
The backend
libsplinter.so is the whole harness minus the screen:
| file | what it owns |
|---|---|
src/backend/engine.c |
struct sp_engine: session, conversation, registry, plugins, transport, agent, turn thread, event queue, slash commands |
src/backend/agent.c |
the loop: request, tool calls, observations, answer |
src/backend/transport*.c, openai.c, anthropic.c, sse.c |
a conversation in, a reply out |
src/backend/builtin.c, tool.c |
the tools and the registry |
src/backend/session.c, conv.c |
append-only JSONL, owned messages |
src/backend/config.c, providers.c, usage.c |
configuration and providers |
src/backend/plugin.c |
dlopen, widgets, commands, gates, compactors |
src/backend/telegram.c, a2aserver.c, mcpserver.c |
outbound protocol adapters |
The engine never calls into a front end. A turn runs on a thread of the
engine's making and appends struct sp_event records to a queue; the front end
drains it whenever it draws. That is the whole threading rule, and it is why a
slow terminal cannot stall a model, and why a GUI cannot corrupt a turn.
include/splinter_engine.h is the C boundary. Its event kinds map one to one
onto the JSON ev names in docs/PROTOCOL.md.
The front ends
| file | kind |
|---|---|
src/frontend/curses.c |
the screen: transcript, sidebar, prompt, keys |
src/frontend/ui_backend.h |
what the screen needs from a backend |
src/frontend/ui_local.c |
that backend as the engine in this process |
src/frontend/ui_remote.c |
that backend as a protocol client (--attach) |
src/frontend/protocol.c |
splinter --serve: JSON lines, sessions, open |
src/frontend/client.c |
splinterctl, the reference protocol client |
src/main.c |
the launcher: parse, config, engine, pick a front end |
curses.c owns the screen, the themes, the markdown-to-ASCII pass, the input
history and the key bindings. It does not know how a provider is switched, how
a session is created or how an approval is waited for — those are
/model, /new and the engine's condition variable. It talks to one of two
backends through ui_backend.h: the engine linked into the process
(--chat), or a served engine over the socket (--attach). The screen cannot
tell them apart, which is the test the protocol has to pass.
splinter --serve --socket /tmp/s.sock # one process: engine + protocol
splinter --attach --socket /tmp/s.sock # another: the screen as a client
The server owns the engine: sessions lists the session directory and open
switches to another id (or new/last), sending the state and history of that
session. The curses screen exposes that as /sessions and /open ID, in both
modes: --serve switches its engine, and the in-process --chat closes its
engine and opens the next one from the same options (plugins keep process
globals, so the old one goes first). One session is active at a time; two
clients still take turns.
--attach keeps running when the backend disappears: it says so, retries every
second, and on the next server asks for the session it was on by id. The history
it already had is shown again, and turns continue; if that session is gone, the
screen says which one and stays on the session the server has. A GUI gets the
same with sessions, open and its own retry loop.
Writing a GUI client
Two ways, and the second one is the interesting one.
-
Link the library. Include
splinter_engine.h, callsp_engine_open(), thensp_engine_input()/sp_engine_submit()/sp_engine_poll()assrc/frontend/curses.cdoes. This only works from C or a C-binding language. -
Speak the socket. Run
splinter --serveand connect to the Unix socket from anything that can open one and write JSON: Python/Tk, Qt, GTK, a web front end through a small bridge.docs/PROTOCOL.mdis the contract;docs/proto-example.pyis a complete 60-line client, andsplinter --attachis the full curses front end running this way. Usesessions/openfor tabs and retry the connect for a server restart. -
Let another harness use splinter as a model.
splinter --openai-listenserves/v1/chat/completions: the caller's tools stay with the caller, splinter's own run locally undergw_*. Seedocs/GATEWAY.md.
The recommended shape for a GUI:
- one window per connection; the
stateevent fills the sidebar (session, model, agent, tokens); - on connect, send
historyonce and draw the returned items - a GUI that joins a session should not look like it invented it; - append
streamdeltas to the open bubble; close it onsteporturn; - draw
toolas a call row andtool_resultunder it (or on the same row whenjoinis true); - when
approvalarrives, show the question and sendapprove; busydrives the spinner;cancelandsteerare the two buttons that must remain live during a turn;- nothing in the client has to know a provider, a session file or a tool's authorization class — the engine already decided.
There is one conversation and one client at a time; a second connection waits
until the first is gone. An attaching client asks for history (the last 100
messages, up to 256 KiB) and shows the session it joins; live events continue
from that point. If a client disconnects, the server cancels a running turn,
because an approval that nobody can answer would park the engine forever.