Compaction is not a flag in the loop; it is a compactor registered by a plugin and run on the main thread before every request, with the whole conversation in hand. Returning 1 means changed, 0 nothing to do, -1 failed - and a failure is counted, not fatal. lcm: deterministic lossy compression. Over budget, it keeps the leading system prompt and the last six messages and inserts one system message that says how many messages went, of which roles, and quotes the head of the oldest dropped turn. No second model, so a run stays reproducible and costs nothing extra. cps: continuous parallel compression. The worker thread decides what would go from an index it got under a mutex (role, size, 64 bytes of head per message) and never touches the conversation; the main thread splices the prepared plan in one pass when the budget is hit. The sidebar line shows applied/prepared counts or a ready plan, so the claim is visible. The limit is in both files: they can decide which messages go, not summarise their text, because the text is not the worker's to read. Ten test binaries green; test_compactor drives both against their real .so files, including that lcm leaves the system prompt first, inserts the [lcm] record at index 1, keeps the tail verbatim, and that cps needs two calls (prepare, then apply) to change anything.
4.6 KiB
Plugins
A splinter plugin is a shared object that links against libsplinter.so and
exports one symbol:
const struct sp_plugin *sp_plugin_describe(void);
The struct, the ABI number and the host functions are in
include/splinter_plugin.h. Nothing else is stable. SP_PLUGIN_ABI changes
whenever that header changes in a way that breaks an old plugin, and a plugin
with the wrong number is refused at load time with the two numbers in the
message.
Build
cc -std=c99 -shared -fPIC -o myplugin.so myplugin.c -L. -lsplinter \
-Wl,-rpath,'$ORIGIN'
splinter --plugin ./myplugin.so --chat loads it before the first turn. A
plugin that fails to load is reported on stderr and skipped; the harness keeps
working.
What a plugin may do
| hook | thread | may block | may touch curses |
|---|---|---|---|
init() |
main | no | no |
run() |
main | yes | no |
tick() |
its own | yes | no |
draw() |
main (UI) | no | no |
tick() runs on a thread the host creates and can stop. It may read files,
wait on sockets, sleep. It must not assume it is the only thread.
Anything that should appear in the sidebar is published:
sp_host_widget_text(host, "mywidget", "42 items");
The host copies the string under a mutex, so a stack buffer is fine and the worker never hands the UI a pointer it could free.
Widgets
static const struct sp_widget w = {
.name = "clock",
.tick = clock_tick, /* worker thread, publishes text */
.draw = NULL, /* NULL: render the published text */
.ctx = NULL,
.interval_ms = 1000, /* 0: tick once */
};
sp_host_add_widget(host, &w);
The sidebar lists one line per widget, name: text. draw() exists for
widgets that need more than one line; it runs on the UI thread and must be
fast, because it holds up every other pane while it runs.
Threads, honestly
- One thread per widget with a
tick. A widget withouttickgets no thread. - The host joins every thread in
sp_host_free(), setting a stop flag first. Atickthat never returns therefore hangs the exit; that is a bug in the plugin, not something the host can fix from outside. - No plugin is
dlclose()d. Unmapping code that a thread might still be inside is how a harness dies in a way nobody can debug. - The host pointer is thread-safe only for
sp_host_widget_text()andsp_host_note(). Everything else belongs to the main thread. That is a rule, not an accident.
Tools
A plugin registers tools with the same authorization classes the builtins use:
struct sp_tool t = { 0 };
t.name = "clock";
t.description = "Report the local date and time.";
t.auth = SP_AUTH_READ;
t.run = clock_tool;
sp_host_add_tool(host, &t);
SP_AUTH_READ runs. SP_AUTH_MUTATE and SP_AUTH_DESTRUCTIVE ask the
operator unless the harness was started with --autonomous. The loop decides
this, not the plugin.
Compaction
A compactor runs on the main thread before every request, with the whole conversation in hand, and may rewrite it:
struct sp_compactor {
.const char *name;
int (*compact)(struct sp_host *, struct sp_conv *, size_t budget_bytes,
unsigned turn);
};
Return 1 when it changed something, 0 when there was nothing to do, -1 on failure. A failure is counted and the turn continues: a broken compactor must not take the conversation with it.
Two come with the tree.
lcm — deterministic, lossy, honest. If the conversation does not fit the budget, it keeps the leading system message and the last six messages, and puts one system message in between that says how many messages went, of which roles, and quotes the head of the oldest dropped turn. No second model is called, so a run stays reproducible and costs nothing extra.
cps — continuous parallel compression. The expensive part (deciding what
would go) is computed on the widget's worker thread from an index of the
conversation — role, size, and 64 bytes of head per message, copied under a
mutex. The worker never touches the conversation itself. When the budget is
hit, the main thread splices an already-prepared plan in one pass. Its sidebar
line shows idle (applied N, prepared M) or plan ready: cut X/Y, A -> B B,
so "continuous" is visible rather than claimed.
The limit is stated in both files: they can decide which messages go, not summarise their text, because summarising needs the text and the text is not the worker's to read.