Files
lotherk 74df75d438 no approval gate: splinter runs what the operator's registry offers
Konrad, 24.11.: "v1 geht durch ohne irgendwas. ich will auch keine approvals
generell. ich will nur das der user mit ask nach sachen gefragt werden kann."

Removed the whole approval apparatus, not just the prompt:

- agent.c: the decision point (sp_host_gate/approve callbacks), the
  pause/resume path (has_pending, pending_from, sp_agent_resume), ack_approval,
  ask_operator and the ack stdin thread are gone. A tool runs; its exit status
  is the observation. sp_tool_policy (allow/deny per profile) stays - that is
  the operator's own configuration, not a question to the operator.
- engine.c: SP_EV_APPROVAL, sp_engine_approve, the approve_pending condition
  variable and the `approval`/`approve` protocol commands are gone.
- openai_server.c: the v1 endpoint runs gw_* tools without a gate; the
  autonomous flag is no longer part of sp_gateway_opts.
- a2aserver.c: INPUT_REQUIRED and the resume-by-taskId path are gone; CancelTask
  stays. An A2A caller has no operator sitting in front of a prompt.
- mcpserver.c: --autonomous no longer gates mutating tools; the flag and the
  config key are accepted for compatibility and documented as changing
  nothing.
- telegram.c: tg_approve and the approval callback are gone; ask is the only
  dialog, and /cancel inside it still ends the turn.
- front ends: protocol.c, curses.c, ui_local.c, ui_remote.c, client.c lose the
  approval event and the waiting flag.
- ack.c stays: it is a plugin API (plugins/kids asks its parent through it),
  not splinter's own gate. --ack is documented as such.

Tests: test_pause.c guarded the pause and now guards the opposite (a mutate and
a destructive tool run, nothing is asked). test_a2a_input.sh, test_protocol.sh,
test_ui.sh, test_agents_ui.sh, test_gateway.sh, test_gateway_openai.sh,
test_agent.c and test_mcpsession.sh were rewritten the same way;
splinter_approve must now be absent from the MCP tool list. Every rewritten
test was run red against the old behaviour where that was possible.

make check: all tests passed (428 s)
make check-asan: all 47 test binaries clean
make check-tsan: all 47 test binaries free of data races
2026-11-24 11:46:10 +00:00

126 lines
6.6 KiB
Markdown

# 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 `ask` question 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). `/sessions` without an argument is a
two-step picker over the same ops (`sources`, then `source_sessions`): the
foreign stores appear next to this folder's sessions, and picking one of their
rows runs the same `/open <source>:<id>` that imports and continues it. 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.
1. **Link the library.** Include `splinter_engine.h`, call `sp_engine_open()`,
then `sp_engine_input()` / `sp_engine_submit()` / `sp_engine_poll()` as
`src/frontend/curses.c` does. This only works from C or a C-binding
language.
2. **Speak the socket.** Run `splinter --serve` and 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.md` is the contract;
`docs/proto-example.py` is a complete 60-line client, and
`splinter --attach` is the full curses front end running this way. Use
`sessions`/`open` for tabs and retry the connect for a server restart.
3. **Let another harness use splinter as a model.** `splinter --openai-listen`
serves `/v1/chat/completions`: the caller's tools stay with the caller,
splinter's own run locally under `gw_*`. See `docs/GATEWAY.md`.
The recommended shape for a GUI:
* one window per connection; the `state` event fills the sidebar (session,
model, agent, tokens);
* on connect, send `history` once and draw the returned items - a GUI that
joins a session should not look like it invented it;
* append `stream` deltas to the open bubble; close it on `step` or `turn`;
* draw `tool` as a call row and `tool_result` under it (or on the same row
when `join` is true);
* when `ask` arrives, show `text` and `options` and send `answer` with the
text the operator gave; the turn is parked until it arrives, so a client
that ignores the event leaves the model waiting (the engine's timeout ends
it with "nobody answered", but slowly);
* `busy` drives the spinner; `cancel` and `steer` are 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 `ask` question that nobody can answer would park the engine forever.