- --openai-listen: an OpenAI-compatible /v1/chat/completions and /v1/models. The model gets splinter's local tools as gw_* (executed here) and the caller's tools under their own names (returned as tool_calls to run there). Local calls loop inside one request; a mixed reply runs the local calls and asks again. --autonomous gates mutation; beyond loopback a bearer token is required; stream:true answers with SSE. - --serve keeps several sessions: sessions/open over the protocol and /sessions, /open in the attach screen. The server owns the engines, closes the old one before opening the next (plugins keep globals) and sends state/history after every switch. Session ids are unique per process, so two engines in the same second no longer share a file. - --attach reconnects: when the server goes away the screen keeps running, retries every second, asks for its session by id and restores the transcript; a missing session falls back to the server's current one. - transports own their context now: provider switches and close dispose it (a switch used to leak one per change). The idle screen repaints entries it drains, so a reconnect note is not invisible. - docs/GATEWAY.md; PROTOCOL, FRONTENDS, README and the manual page describe the three; tests cover the gateway tools, sessions/open and a server restart under --attach.
5.8 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. 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. 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.