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.
98 lines
3.5 KiB
C
98 lines
3.5 KiB
C
/*
|
|
* splinter -- plugin ABI.
|
|
*
|
|
* Copyright (c) 2026 Konrad Lother
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*
|
|
* A plugin is a shared object loaded with dlopen(). It links against
|
|
* libsplinter.so, never against the binary, so there is exactly one copy of
|
|
* every symbol in the process.
|
|
*
|
|
* What a plugin may do, and where:
|
|
*
|
|
* init() called once, on the main thread, before any turn. Register
|
|
* tools and widgets here. May fail; a failed plugin is unloaded
|
|
* from the set and reported, never half-used.
|
|
* run() called on the main thread while a turn is being handled.
|
|
* tick() called on the widget's own thread, so it may block, read
|
|
* files, wait on sockets. It must NOT touch curses and must NOT
|
|
* assume it is the only thread.
|
|
* draw() called on the UI thread only, must be fast and non-blocking.
|
|
* A widget without draw() is rendered from its published text.
|
|
*
|
|
* Text that should appear in the sidebar is published with
|
|
* sp_host_widget_text(); the host copies it under a mutex, so the string does
|
|
* not have to outlive the call.
|
|
*/
|
|
#ifndef SPLINTER_PLUGIN_H
|
|
#define SPLINTER_PLUGIN_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "splinter.h"
|
|
|
|
#define SP_PLUGIN_ABI 1u
|
|
|
|
struct sp_host;
|
|
|
|
struct sp_widget {
|
|
const char *name; /* unique in the sidebar */
|
|
int (*tick)(struct sp_host *, const char *name, void *ctx);
|
|
void (*draw)(struct sp_host *, const char *name, void *ctx);
|
|
void *ctx;
|
|
unsigned interval_ms; /* 0: tick once, then stop */
|
|
};
|
|
|
|
/*
|
|
* A compactor runs on the main thread before every request, with the whole
|
|
* conversation in hand. It may rewrite it. Returning 1 means "changed", 0
|
|
* "nothing to do", -1 "failed" - and a failure is reported, never ignored.
|
|
*/
|
|
struct sp_compactor {
|
|
const char *name;
|
|
int (*compact)(struct sp_host *, struct sp_conv *,
|
|
size_t budget_bytes, unsigned turn);
|
|
};
|
|
|
|
struct sp_plugin {
|
|
uint32_t abi; /* must equal SP_PLUGIN_ABI */
|
|
const char *name;
|
|
const char *version;
|
|
int (*init)(struct sp_host *);
|
|
int (*run)(struct sp_host *, const char *input,
|
|
struct sp_buf *out);
|
|
void (*shutdown)(struct sp_host *);
|
|
};
|
|
|
|
/* Every plugin exports exactly this. */
|
|
const struct sp_plugin *sp_plugin_describe(void);
|
|
|
|
/* ---- host API, implemented by splinter, called by plugins ---- */
|
|
|
|
uint32_t sp_host_abi(struct sp_host *);
|
|
int sp_host_add_tool(struct sp_host *, const struct sp_tool *);
|
|
int sp_host_add_widget(struct sp_host *, const struct sp_widget *);
|
|
int sp_host_widget_text(struct sp_host *, const char *widget,
|
|
const char *text);
|
|
int sp_host_note(struct sp_host *, const char *text);
|
|
int sp_host_add_compactor(struct sp_host *, const struct sp_compactor *);
|
|
int sp_host_add_transport(struct sp_host *, const char *name,
|
|
struct sp_transport);
|
|
struct sp_transport *sp_host_transport(struct sp_host *, const char *name);
|
|
int sp_host_compact(struct sp_host *, struct sp_conv *, size_t budget);
|
|
size_t sp_host_compaction_stats(struct sp_host *, size_t *compactions,
|
|
size_t *failed, unsigned *turns);
|
|
void sp_host_turn(struct sp_host *);
|
|
|
|
/* ---- host side, implemented by splinter, called by the harness ---- */
|
|
|
|
struct sp_host *sp_host_new(struct sp_registry *, struct sp_agent *,
|
|
struct sp_session_info *);
|
|
void sp_host_free(struct sp_host *);
|
|
int sp_plugin_load(struct sp_host *, const char *path,
|
|
struct sp_buf *err);
|
|
size_t sp_host_widget_snapshot(struct sp_host *, char *buf, size_t len);
|
|
size_t sp_host_widget_count(struct sp_host *);
|
|
|
|
#endif /* SPLINTER_PLUGIN_H */
|