First run against a real model (Qwen3.6-35B-A3B on kontron, strata-poly)
exposed two things a stub never would:
- our tool schema sent "properties":{}, which tells the model that no
arguments exist. Tools now carry a real JSON schema (echo/command/clock), and
the loop completes a tool round against the 35B: request 1 -> tool_call,
request 2 -> "Das Ergebnis ist: ping".
- an answer longer than the screen was not drawn at all: the entry did not
'fit', so the viewport skipped it and the chat looked empty. draw_history is
now a real viewport (total height, bottom-anchored, entries taller than the
screen start at the offset that puts their end on screen).
Steering: a turn runs on its own thread while the UI keeps reading keys. Enter
queues text the loop picks up at the next step boundary; Ctrl-C cancels; in a
single-step turn the text becomes the next message instead of disappearing.
Curses remains UI-thread-only. A dangling ag->cfg after the turn made a steer
run twice - the caller's config is now restored, and the session log confirms
one user line per steer.
Transports are plugins now (sp_host_add_transport / --transport). plugins/cli
makes any program the model: SPLINTER_CLI_CMD, run through /bin/sh, prompt on
stdin, stdout as the answer, 4 MiB cap, non-zero exit with the program's stderr,
empty output is an error. Verified with sed, with claude -p (2.9 s, answer OK)
and with cat.
Eleven test binaries green, test_cli included.
85 lines
1.8 KiB
C
85 lines
1.8 KiB
C
/*
|
|
* splinter -- example plugin: a clock widget in the sidebar.
|
|
*
|
|
* Copyright (c) 2026 Konrad Lother
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*
|
|
* Shows the three parts of the ABI that matter:
|
|
* - init() registers a widget,
|
|
* - tick() runs on the host's worker thread and only publishes text,
|
|
* - run() adds a turn-level tool the harness can call.
|
|
*
|
|
* Build: cc -std=c99 -shared -fPIC -o clock.so clock.c -lsplinter
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_plugin.h"
|
|
|
|
static int
|
|
clock_tick(struct sp_host *h, const char *name, void *ctx)
|
|
{
|
|
char out[128];
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
|
|
(void)ctx;
|
|
localtime_r(&now, &tm);
|
|
snprintf(out, sizeof(out), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min,
|
|
tm.tm_sec);
|
|
return sp_host_widget_text(h, name, out);
|
|
}
|
|
|
|
static int
|
|
clock_tool(const char *args, struct sp_buf *out, void *ctx)
|
|
{
|
|
char line[64];
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
|
|
(void)args;
|
|
(void)ctx;
|
|
localtime_r(&now, &tm);
|
|
snprintf(line, sizeof(line), "%04d-%02d-%02d %02d:%02d:%02d",
|
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
|
|
tm.tm_sec);
|
|
return sp_buf_puts(out, line);
|
|
}
|
|
|
|
static int
|
|
clock_init(struct sp_host *h)
|
|
{
|
|
static const struct sp_widget w = {
|
|
"clock", clock_tick, NULL, NULL, 1000
|
|
};
|
|
struct sp_tool t;
|
|
|
|
if (sp_host_add_widget(h, &w) != 0)
|
|
return -1;
|
|
|
|
memset(&t, 0, sizeof(t));
|
|
t.name = "clock";
|
|
t.description = "Report the local date and time.";
|
|
t.params = "{\"type\":\"object\",\"properties\":{}}";
|
|
t.auth = SP_AUTH_READ;
|
|
t.run = clock_tool;
|
|
return sp_host_add_tool(h, &t);
|
|
}
|
|
|
|
static const struct sp_plugin clock_plugin = {
|
|
SP_PLUGIN_ABI,
|
|
"clock",
|
|
"1.0.0",
|
|
clock_init,
|
|
NULL,
|
|
NULL
|
|
};
|
|
|
|
const struct sp_plugin *
|
|
sp_plugin_describe(void)
|
|
{
|
|
return &clock_plugin;
|
|
}
|