Files
splinter/docs/splinter.1
T
lotherk fa16bfd0a9 foreign: adopt a claude, hermes or opencode session as a splinter session
Another harness's conversation is not a session until splinter can resume
it. plugins/foreign reads the three stores that already exist on the
machine - ~/.claude/projects/<slug>/<id>.jsonl, <root>/state.db (and
profiles/*/state.db) and opencode.db's session_v2/session_message - and
offers four tools plus /foreign:

  list, search TEXT, read SOURCE ID, import SOURCE ID

The stores are read with sqlite3 -readonly: an import copies, it never
moves. Reasoning blocks are dropped on the way in, because a provider does
not accept another model's thinking as evidence. Tool calls arrive with
their results in place, which is what makes the imported session worth
resuming instead of retyping.

import writes a real splinter session: the conversation as a replayable
jsonl, and a .meta with the source's title, its start time and *its*
working directory. So /open continues it in the chat,
--session-id <id> --resume in a shell, and -c finds it in the directory the
conversation actually ran in. The marker foreign=<source>:<id> survives
every later reopen, which needed the core's .meta sidecar to carry keys it
does not own.

Building this found nine bugs, each one seen red before it was green:

  - four use-after-frees: mcp_arg_string returns a pointer *into* the parse
    tree, read after mcp_json_free. That garbage in `only`/`src` was why a
    list of three stores answered "no sessions" and named AÃ_Â¥U.
  - sql_json took "no rows" for a failure (NULL), so every empty answer
    looked like a broken database.
  - args_split never terminated its buffers: /foreign list became
    "unknown subcommand 'list('".
  - path_join(dir, id, ".meta") built dir/id/.meta, so the sidecar landed
    in a subdirectory.
  - claude_slug_dir had the sign inverted and returned -1 for every
    non-empty cwd, so the project directory was never found.
  - sp_session_open overwrote cwd with getcwd() on *every* open, though the
    comment beside it promised the opposite: imports claimed the directory
    they were imported from and -c then picked the wrong session.
  - hermes_text ran strncmp(p, "\x00json:", 6) on an empty content, a
    one-byte allocation - heap-buffer-overflow, found by ASAN. The marker is
    stripped in SQL anyway.
  - hermes_calls never freed the root node on the object path (5456 bytes
    over 42 allocations).
  - list_any reported strerror(errno) with errno never set: a real file with
    the wrong schema read as "No such file or directory". The SQL reason is
    passed through now.

Checked end to end against the stores on this machine: claude 64 sessions,
opencode 25, hermes 0 (both hermes databases here are empty, count(*) = 0).
A real opencode session of 150 messages reads back with its tool output; one
of 75 imports with the right cwd and title, --resume sends its history, and
-c from the source directory opens it.

tests/sh/port.sh comes along: the shell tests guessed a port with
20000 + $$ % 30000 and on 2026-11-21 landed on one dtsession held. The fake
died, curl got an answer from dtsession, and twenty checks blamed the
gateway. They ask the kernel for a free port now.
2026-11-21 21:26:43 +00:00

247 lines
6.8 KiB
Groff

.Dd November 7, 2026
.Dt SPLINTER 1
.Os
.Sh NAME
.Nm splinter
.Nd a small C99/POSIX agent harness
.Sh SYNOPSIS
.Nm
.Fl p Ar prompt
.Fl -endpoint Ar url
.Op Fl -autonomous
.Op Fl -steps Ar n
.Op Fl -session Ar dir
.Op Fl -session-id Ar id
.Nm
.Fl p Ar prompt
.Fl -script Ar file
.Op Ar options
.Nm
.Fl V
.Sh DESCRIPTION
.Nm
runs one turn of an agent loop against a transport.
It sends a prompt, executes the tools the transport asks for, and prints the
final answer.
Every turn is appended to a session log as JSON Lines.
.Pp
The loop enforces, in this order, before any tool runs:
.Bl -enum -compact
.It
the request fits the configured byte budget; otherwise nothing is sent;
.It
the tool exists in the registry; otherwise the model is told it does not;
.It
the tool's authorization class allows the call; a mutating or destructive
tool asks the operator unless
.Fl -autonomous
was given.
.El
.Pp
A denied tool is not skipped silently: the denial is the observation the model
receives.
.Sh OPTIONS
.Bl -tag -width Ds
.It Fl p , -prompt Ar TEXT
The user message for this turn.
Required.
.It Fl -endpoint Ar URL
Transport: POST the line protocol to
.Ar URL
using
.Xr curl 1 .
.It Fl -kind Ar NAME
The vendor shape of
.Fl -endpoint :
.Ar openai
(the default,
.Pa /v1/chat/completions )
or
.Ar anthropic
(the Messages API, which takes an
.Pa sk-ant-oat...
Claude Code token or an
.Pa sk-ant-api...
key).
.It Fl -select Ar SEL , m Ar SEL
Use a provider or a pool from the configuration:
.Ar ID ,
.Ar POOL ,
.Ar ID/model
or
.Ar POOL/model .
.It Fl -delegate Ar ID
Run that configured delegate with
.Fl p Ar TEXT ,
print its observation and exit.
No model and no transport are involved; this is the diagnostic path for a
delegate that fails.
.It Fl -script Ar FILE
Transport: replay one reply per line from
.Ar FILE .
This needs no network and is how the test suite drives the loop.
.It Fl -no-stream
One-shot mode: wait for the whole reply instead of printing it as it arrives.
A transport that can stream uses its streaming method by default; this asks for
its plain send method.
.It Fl -autonomous
Run mutating tools without asking.
Read-only tools never ask.
.It Fl -steps Ar N
Maximum tool rounds per turn (default 150).
.It Fl -max-bytes Ar N
Request budget in bytes; 0 means no limit.
.It Fl -a2a-server-listen Ar IP
Serve the A2A agent (JSON-RPC, agent card) on
.Ar IP .
Beyond 127.x it needs
.Ev SPLINTER_A2A_SERVER_TOKEN .
.It Fl -a2a-listen-port Ar N
A2A port (default 8099).
.It Fl -openai-listen Ar IP
Serve an OpenAI-compatible endpoint
.Pq Pa /v1/chat/completions , /v1/models
for another harness.
The model sees splinter's local tools as
.Pa gw_ Ns Ar name
and runs them here; tools the caller sends are returned to the caller as
ordinary tool calls and run there.
Beyond loopback it needs
.Ev SPLINTER_GATEWAY_TOKEN . See
.Pa docs/GATEWAY.md .
.It Fl -openai-listen-port Ar N
Gateway port (default 8097).
.It Fl -serve
Serve the engine on a Unix socket instead of drawing a screen.
Each request and event is one JSON object per line; see
.Pa docs/PROTOCOL.md .
Any program that can open a Unix socket can be a front end, which is what a
GUI client connects to.
.It Fl -attach
Run the curses interface as a client of a served engine
.Pq Fl -serve .
The screen shows the server's session and its transcript so far (asked for
with the protocol's history command) and runs every turn there; the socket
protocol is the same one a GUI client uses.
The commands
.Pa /sessions
and
.Pa /open Ar ID
switch the session.
.Pa /sessions
shows each session with its title: the first user line, or what
.Pa /rename
.Pq Op Ar ID
.Ar TITLE
set.
.Pa /rm Ar ID
removes a session that is not open.
If the server goes away, the screen keeps running, reconnects and asks for the
session it was on.
.It Fl -socket Ar PATH
Socket for
.Fl -serve
and
.Fl -attach ,
default
.Ev SPLINTER_SOCKET
or
.Pa ~/.splinter/splinter.sock .
The file is mode 0600 and the server refuses a peer of another uid.
.It Fl -session Ar DIR
Session directory (default
.Pa ~/.splinter ) .
.It Fl -session-id Ar ID
Session id (default
.Pa sess-<time>-<pid> ) .
.It Fl V , -version
Print the version, the build time and the git revision, then exit.
The release number stays
.Ql 0.1.0 ;
the build stamp is what tells two builds apart.
.El
.Sh PROTOCOL
.Nm
is a backend with front ends.
The curses interface links the engine in process;
.Fl -serve
exposes the same engine as JSON lines on a Unix socket, where
.Pa splinterctl
is the reference client and the place to start a GUI from.
The engine reports a turn as events \(em streamed text, a step, a tool call, its
observation, an approval question, the answer \(em and never calls into a front
end.
.Pp
Between the harness and its transport the protocol is simpler, and not a
vendor API:
.Bd -literal -offset indent
request user <text>
request observe <tool> <output>
reply answer <text>
reply tool <name> <arguments>
.Ed
.Pp
A provider adapter translates an OpenAI-compatible endpoint, the Anthropic
Messages API (a provider with `kind = anthropic`) or a program's stdout
(`--transport cli`) into this shape and back.
The harness itself never parses vendor JSON, which is why the loop is testable
with no network at all.
.Sh FILES
.Bl -tag -width Ds
.It Pa ~/.splinter/<id>.jsonl
Append-only session log, one JSON object per line.
A crash can only truncate the tail.
.It Pa ~/.splinter/emb/<id>.emb
The session's search index, one record per line.
It is written by a background thread, so it lags the session log by a moment
and is rebuilt by reading the log again if it is missing.
.It Pa ~/.splinter/<id>.meta
The session's sidecar, one
.Sq key=value
per line: cwd, created, opened, title, goal, goal_state.
A key the core does not own is carried through unchanged, so a plugin can mark
a session in the same file
.Pq Pa plugins/foreign No writes Sy foreign Ns = Ns Ar source : Ns Ar id .
.It Pa ~/.splinter/splinter.conf
The configuration.
.Fl -init-config
writes it as
.Pa splinter.conf.example
when one is already there, so it never overwrites a file in use.
See
.Pa docs/CONFIG.md .
.El
.Sh EXIT STATUS
.Bl -tag -width Ds -compact
.It 0
The turn produced an answer.
.It 1
The turn failed.
The reason is printed on standard error.
.It 2
Usage or configuration error.
.It 3
The environment could not be set up, for example the session directory.
.El
.Sh EXAMPLES
Run a scripted turn with no network:
.Bd -literal -offset indent
$ printf 'answer hello\\n' > /tmp/r.txt
$ splinter -p "say hello" --script /tmp/r.txt
hello
.Ed
.Pp
Talk to an adapter:
.Bd -literal -offset indent
$ splinter -p "list the C files" --endpoint http://127.0.0.1:8080/turn
.Ed
.Sh SEE ALSO
.Xr curl 1
.Sh AUTHORS
.An Konrad Lother
.Sh CAVEATS
The transport is responsible for anything the model says; the harness trusts
only the registry and the authorization classes.
Tool arguments are passed as a single string and are not validated beyond the
tool's own checks.