Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3b832ae64 | ||
|
|
bddba6423b |
No files matched your search
+60
-21
@@ -29,9 +29,11 @@ core {
|
||||
steps = 60
|
||||
on_limit = wait # a usage limit is waited out (or: fail)
|
||||
max_wait = 2d
|
||||
plugins = [plugins/lcm/lcm.so, plugins/cli/cli.so]
|
||||
}
|
||||
|
||||
plugin lcm { } # one block per plugin, see "Plugins"
|
||||
plugin cli { }
|
||||
|
||||
telegram { allow = [123456789] }
|
||||
|
||||
provider ocgo {
|
||||
@@ -228,7 +230,7 @@ lies about what it does.
|
||||
| `api_key_env` | name of the env var holding the key (default `SPLINTER_API_KEY`) |
|
||||
| `transport` | a transport a plugin provides, e.g. `cli` |
|
||||
| `cli_cmd` | command for the `cli` transport, e.g. `claude -p` |
|
||||
| `plugin` | a plugin to load, one line each; absolute paths survive a `cd` |
|
||||
| `plugin` | a plugin to load, one line each: a shipped plugin's name (`lcm`) or a path; in the block form `plugin NAME { }`, see "Plugins" |
|
||||
| `theme` | CDE palette name (`splinter --list-themes`) |
|
||||
| `locale` | language code (`de`, `en`); catalogues live in `share/locale` |
|
||||
| `autonomous` | `1` runs mutating/destructive tools without asking |
|
||||
@@ -320,29 +322,66 @@ task moves to the next delegate in its own slot while the others keep running,
|
||||
unless that one is already at its `max_parallel`. Only when nothing else fits
|
||||
does the job wait (`waiting_quota`) for the reset.
|
||||
|
||||
## Plugins
|
||||
|
||||
Every plugin has its own block. The block loads it, and everything in it
|
||||
apart from `path` and `enabled` is that plugin's own configuration:
|
||||
|
||||
```
|
||||
plugin lcm {
|
||||
keep = 40
|
||||
}
|
||||
plugin tmux { }
|
||||
plugin mine {
|
||||
path = ~/my/plugin.so # not shipped: say where it is
|
||||
foo = bar
|
||||
}
|
||||
plugin status { enabled = false } # kept in the file, not loaded
|
||||
```
|
||||
|
||||
| field | meaning |
|
||||
|-------|---------|
|
||||
| `path` | the `.so` to load; without it the shipped plugin of that name |
|
||||
| `enabled` | `false` keeps the block but does not load the plugin (default on) |
|
||||
| anything else | the plugin's own setting, read with `sp_host_plugin_config()` |
|
||||
|
||||
Without `path`, `plugin NAME { }` finds the shipped plugin next to the
|
||||
binary: `plugins/NAME/NAME.so` in the build tree, then the installed
|
||||
`$(PREFIX)/lib/splinter/plugins/NAME.so`, then the build directory the binary
|
||||
was compiled in. A nested block gives dotted names: `server a { url = x }`
|
||||
inside `plugin foo` is `server.a.url`; a list `[a, b]` arrives as `a,b`.
|
||||
`docs/PLUGINS.md` has the API.
|
||||
|
||||
The old forms still load, so an existing file keeps working:
|
||||
`plugins = [plugins/lcm/lcm.so, ...]` in `core` (one path each) and the flat
|
||||
`plugin = /path/to/x.so`. They carry no plugin settings.
|
||||
|
||||
## MCP servers
|
||||
|
||||
An MCP server contributes tools. One line each, or a block, and it needs the
|
||||
`plugins/mcp/mcp.so` plugin:
|
||||
An MCP server contributes tools. The servers are the configuration of the
|
||||
`mcp` plugin, one `server` block each:
|
||||
|
||||
```
|
||||
plugin = /home/lotherk/src/splinter/plugins/mcp/mcp.so
|
||||
plugin mcp {
|
||||
# streamable HTTP: one POST per message
|
||||
server junction {
|
||||
url = http://172.25.206.16:8090/mcp
|
||||
header = "Authorization: Bearer ${JUNCTION_TOKEN}"
|
||||
}
|
||||
|
||||
# streamable HTTP: one POST per message
|
||||
mcp junction {
|
||||
url = http://172.25.206.16:8090/mcp
|
||||
header = "Authorization: Bearer ${JUNCTION_TOKEN}"
|
||||
# or a program that speaks MCP on its stdin/stdout
|
||||
server files {
|
||||
cmd = "npx -y @modelcontextprotocol/server-filesystem /home"
|
||||
}
|
||||
|
||||
# a server that exists but should not be asked
|
||||
server old { url = http://127.0.0.1:9000/mcp enabled = false }
|
||||
}
|
||||
|
||||
# or a program that speaks MCP on its stdin/stdout
|
||||
mcp files {
|
||||
cmd = "npx -y @modelcontextprotocol/server-filesystem /home"
|
||||
}
|
||||
|
||||
# a server that exists but should not be asked
|
||||
mcp old { url = http://127.0.0.1:9000/mcp enabled = false }
|
||||
```
|
||||
|
||||
The top-level `mcp NAME { ... }` block and the flat `mcp = ...` line from
|
||||
before still work (they need the plugin loaded as well).
|
||||
|
||||
| field | meaning |
|
||||
|-------|---------|
|
||||
| `url` | the endpoint, streamable-HTTP transport (`.../mcp`) |
|
||||
@@ -373,9 +412,9 @@ endpoint = http://127.0.0.1:8080/v1
|
||||
model = /models/unsloth/Qwen3.6-35B-A3B-MTP-GGUF/Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf
|
||||
theme = Delphinium
|
||||
autonomous = 1
|
||||
plugin = /home/lotherk/src/splinter/plugins/lcm/lcm.so
|
||||
plugin = /home/lotherk/src/splinter/plugins/cps/cps.so
|
||||
plugin = /home/lotherk/src/splinter/plugins/clock/clock.so
|
||||
plugin = lcm
|
||||
plugin = cps
|
||||
plugin = clock
|
||||
session_dir = /home/lotherk/.splinter
|
||||
```
|
||||
|
||||
@@ -385,7 +424,7 @@ session_dir = /home/lotherk/.splinter
|
||||
transport = cli
|
||||
cli_cmd = claude -p
|
||||
cli_timeout = 1800
|
||||
plugin = /home/lotherk/src/splinter/plugins/cli/cli.so
|
||||
plugin = cli
|
||||
theme = Delphinium
|
||||
```
|
||||
|
||||
|
||||
@@ -24,6 +24,46 @@ cc -std=c99 -shared -fPIC -o myplugin.so myplugin.c -L. -lsplinter \
|
||||
plugin that fails to load is reported on stderr and skipped; the harness keeps
|
||||
working.
|
||||
|
||||
## Configuration
|
||||
|
||||
In the config file every plugin has its own block (`docs/CONFIG.md`,
|
||||
"Plugins"):
|
||||
|
||||
```
|
||||
plugin mine {
|
||||
path = ~/my/myplugin.so # omitted: the shipped plugin "mine"
|
||||
depth = 3
|
||||
hosts = [a, b]
|
||||
server a { url = http://a/mcp }
|
||||
}
|
||||
```
|
||||
|
||||
Everything but `path` and `enabled` is the plugin's own, and it reads it
|
||||
through the host by the block's name:
|
||||
|
||||
```c
|
||||
const char *d = sp_host_plugin_config(host, "mine", "depth"); /* "3" */
|
||||
const char *h = sp_host_plugin_config(host, "mine", "hosts"); /* "a,b" */
|
||||
const char *u = sp_host_plugin_config(host, "mine", "server.a.url");
|
||||
```
|
||||
|
||||
A missing key is NULL; the value is a string, parsing is the plugin's job.
|
||||
To see every setting (the servers it was given, say), walk them in file order:
|
||||
|
||||
```c
|
||||
const char *key, *val;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; (val = sp_host_plugin_config_at(host, "mine", i, &key)) != NULL; i++)
|
||||
/* key = "depth", "hosts", "server.a.url", ... */;
|
||||
```
|
||||
|
||||
Both work from `init()` on. The config is read once at start; a value does
|
||||
not change while the plugin runs. The `mcp` plugin is the one exception to
|
||||
the dotted names: its `server NAME { }` blocks become the MCP server list it
|
||||
always read (`sp_host_config()`), so `plugin mcp { server ... }` and the old
|
||||
`mcp NAME { }` block mean the same.
|
||||
|
||||
## What a plugin may do
|
||||
|
||||
| hook | thread | may block | may touch curses |
|
||||
|
||||
@@ -355,6 +355,14 @@ int sp_delegate_prio(const struct sp_config *, const char *id);
|
||||
*/
|
||||
void sp_delegate_cli_plugin(const char *self, char *out, size_t len);
|
||||
|
||||
/*
|
||||
* A shipped plugin by name ("lcm", "mcp"): the build tree next to the binary
|
||||
* at 'self', the installed layout ($(PREFIX)/lib/splinter/plugins), then the
|
||||
* build directory compiled in. None found: the first candidate.
|
||||
*/
|
||||
void sp_plugin_path(const char *self, const char *name, char *out,
|
||||
size_t len);
|
||||
|
||||
/*
|
||||
* Limits. sp_limit_parse: is this error text a rate/usage limit (429, "weekly
|
||||
* limit", "quota", ...) and until when - the reset it names, else an hour.
|
||||
|
||||
@@ -224,6 +224,26 @@ void sp_host_turn(struct sp_host *);
|
||||
/* The loaded configuration, so plugins (the exit ring) can read it. */
|
||||
const void *sp_host_config(struct sp_host *);
|
||||
void sp_host_set_config(struct sp_host *, const void *);
|
||||
|
||||
/*
|
||||
* A plugin's own configuration, from its block in the config file:
|
||||
*
|
||||
* plugin lcm {
|
||||
* keep = 40
|
||||
* server junction { url = http://... }
|
||||
* }
|
||||
*
|
||||
* sp_host_plugin_config(h, "lcm", "keep") is "40", a nested block gives
|
||||
* dotted keys ("server.junction.url"), a list "a,b,c". NULL when the key is
|
||||
* not set (or no config is loaded). 'plugin' is the block's name.
|
||||
*
|
||||
* sp_host_plugin_config_at() walks every setting of 'plugin' in file order:
|
||||
* index 0, 1, ... until it returns NULL; *key gets the setting's name.
|
||||
*/
|
||||
const char *sp_host_plugin_config(struct sp_host *, const char *plugin,
|
||||
const char *key);
|
||||
const char *sp_host_plugin_config_at(struct sp_host *, const char *plugin,
|
||||
size_t i, const char **key);
|
||||
struct sp_registry *sp_host_registry(struct sp_host *);
|
||||
|
||||
/* ---- host side, implemented by splinter, called by the harness ---- */
|
||||
|
||||
+23
-1
@@ -63,6 +63,7 @@ struct server {
|
||||
char cmd[SP_CONFIG_MCP_CMD];
|
||||
char session[160]; /* Mcp-Session-Id, echoed back */
|
||||
pid_t pid;
|
||||
volatile pid_t http_pid; /* the curl of a round trip in flight */
|
||||
FILE *to; /* stdio: our writes become the server's stdin */
|
||||
int from; /* stdio: its stdout, read without stdio */
|
||||
struct sp_buf in; /* bytes read but not yet a whole line */
|
||||
@@ -349,6 +350,8 @@ http_rpc(struct server *s, const char *method, const char *params,
|
||||
|
||||
snprintf(data, sizeof(data), "@%s", body);
|
||||
args[n++] = "-sS";
|
||||
args[n++] = "--connect-timeout";
|
||||
args[n++] = "5";
|
||||
args[n++] = "-m";
|
||||
args[n++] = tmo;
|
||||
args[n++] = "-X";
|
||||
@@ -375,6 +378,14 @@ http_rpc(struct server *s, const char *method, const char *params,
|
||||
}
|
||||
hdrs[n] = NULL;
|
||||
|
||||
if (stopping) {
|
||||
sp_buf_puts(err, "mcp: shutting down");
|
||||
(void)unlink(body);
|
||||
(void)unlink(hdr);
|
||||
sp_buf_free(&req);
|
||||
sp_buf_free(&out);
|
||||
return NULL;
|
||||
}
|
||||
fd = sp_curl_start(args, s->url, hdrs, 1, &pid, err);
|
||||
if (fd < 0) {
|
||||
(void)unlink(body);
|
||||
@@ -383,6 +394,8 @@ http_rpc(struct server *s, const char *method, const char *params,
|
||||
sp_buf_free(&out);
|
||||
return NULL;
|
||||
}
|
||||
/* shutdown kills it: a server that is down must not hold the exit */
|
||||
s->http_pid = pid;
|
||||
{
|
||||
char chunk[8192];
|
||||
ssize_t got;
|
||||
@@ -394,6 +407,7 @@ http_rpc(struct server *s, const char *method, const char *params,
|
||||
}
|
||||
close(fd);
|
||||
(void)waitpid(pid, &rc, 0);
|
||||
s->http_pid = 0;
|
||||
take_session(s, hdrp);
|
||||
(void)unlink(body);
|
||||
(void)unlink(hdr);
|
||||
@@ -566,6 +580,8 @@ notify(struct server *s, const char *method)
|
||||
close(fd);
|
||||
snprintf(data, sizeof(data), "@%s", body);
|
||||
args[n++] = "-sS";
|
||||
args[n++] = "--connect-timeout";
|
||||
args[n++] = "5";
|
||||
args[n++] = "-m";
|
||||
args[n++] = HTTP_TIMEOUT_S;
|
||||
args[n++] = "-X";
|
||||
@@ -579,10 +595,13 @@ notify(struct server *s, const char *method)
|
||||
if (s->header[0] != '\0')
|
||||
hdrs[n++] = s->header;
|
||||
hdrs[n] = NULL;
|
||||
fd = sp_curl_start(args, s->url, hdrs,
|
||||
fd = stopping ? -1 :
|
||||
sp_curl_start(args, s->url, hdrs,
|
||||
1, &pid, &err);
|
||||
if (fd >= 0) {
|
||||
s->http_pid = pid;
|
||||
(void)waitpid(pid, NULL, 0);
|
||||
s->http_pid = 0;
|
||||
close(fd);
|
||||
take_session(s, hdr);
|
||||
}
|
||||
@@ -1072,6 +1091,9 @@ mcp_shutdown(struct sp_host *h)
|
||||
(void)waitpid(sv[i].pid, NULL, 0);
|
||||
sv[i].pid = 0;
|
||||
}
|
||||
/* an HTTP round trip in flight: its curl goes, the thread sees EOF */
|
||||
if (sv[i].http && sv[i].http_pid > 0)
|
||||
(void)kill(sv[i].http_pid, SIGKILL);
|
||||
sv[i].dead = 1;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-7
@@ -373,23 +373,30 @@ sp_anthropic_request(const struct sp_conv *conv, const char *model,
|
||||
}
|
||||
if (!any)
|
||||
continue; /* nothing to say: no empty message */
|
||||
if (prev_assistant == assistant) {
|
||||
/*
|
||||
* Same role as the message before (observations of a parallel
|
||||
* round, or a user turn that failed and was asked again): its
|
||||
* blocks join the open message. The message stays open until
|
||||
* the role changes -- closing it first put the blocks outside
|
||||
* any message, and the API answered 400 "messages.N.role".
|
||||
*/
|
||||
if (nmsg > 0 && prev_assistant == assistant) {
|
||||
if (sp_buf_puts(out, ",") != 0 ||
|
||||
(blocks.len > 0 && sp_buf_add(out, blocks.p,
|
||||
blocks.len) != 0))
|
||||
sp_buf_add(out, blocks.p, blocks.len) != 0)
|
||||
goto out;
|
||||
continue;
|
||||
}
|
||||
if (nmsg++ > 0 && sp_buf_puts(out, ",") != 0)
|
||||
if (nmsg > 0 && sp_buf_puts(out, "]},") != 0)
|
||||
goto out;
|
||||
nmsg++;
|
||||
if (sp_buf_printf(out, "{\"role\":\"%s\",\"content\":[",
|
||||
assistant ? "assistant" : "user") != 0 ||
|
||||
(blocks.len > 0 && sp_buf_add(out, blocks.p,
|
||||
blocks.len) != 0) ||
|
||||
sp_buf_puts(out, "]}") != 0)
|
||||
sp_buf_add(out, blocks.p, blocks.len) != 0)
|
||||
goto out;
|
||||
prev_assistant = assistant;
|
||||
}
|
||||
if (nmsg > 0 && sp_buf_puts(out, "]}") != 0)
|
||||
goto out;
|
||||
if (sp_buf_puts(out, "]") != 0)
|
||||
goto out;
|
||||
|
||||
|
||||
+164
-4
@@ -18,8 +18,10 @@ struct val {
|
||||
|
||||
struct ent {
|
||||
char key[48];
|
||||
char sub[96]; /* key NAME { ... }: the NAME */
|
||||
struct val v;
|
||||
unsigned line;
|
||||
int block; /* a nested { } block: items are A=b */
|
||||
};
|
||||
|
||||
struct cb {
|
||||
@@ -459,6 +461,140 @@ done:
|
||||
sp_buf_free(&l);
|
||||
}
|
||||
|
||||
/* one setting of a plugin: plugin_conf = NAME | key=value */
|
||||
static void
|
||||
plugin_kv(struct cb *c, const struct ent *e, const char *plugin,
|
||||
const char *key, const char *val)
|
||||
{
|
||||
if (strchr(key, '=') != NULL || strchr(key, '|') != NULL) {
|
||||
fail(c, e->line, "bad plugin setting name '%s'", key);
|
||||
return;
|
||||
}
|
||||
if (!clean(c, e, val))
|
||||
return;
|
||||
emit(c, e->line, "plugin_conf = %s | %s=%s", plugin, key, val);
|
||||
}
|
||||
|
||||
/* plugin mcp { server ID { url = ... } }: the servers the mcp plugin runs */
|
||||
static void
|
||||
mcp_server(struct cb *c, const struct ent *e)
|
||||
{
|
||||
struct sp_buf l;
|
||||
size_t j;
|
||||
|
||||
if (e->sub[0] == '\0') {
|
||||
fail(c, e->line, "server needs a name: server NAME { url = ... }");
|
||||
return;
|
||||
}
|
||||
if (sp_buf_init(&l) != 0)
|
||||
return;
|
||||
sp_buf_printf(&l, "mcp = %s", e->sub);
|
||||
for (j = 0; j < e->v.n; j++) {
|
||||
const char *kv = e->v.items[j], *eq = strchr(kv, '=');
|
||||
size_t kl = eq != NULL ? (size_t)(eq - kv) : 0;
|
||||
|
||||
if (eq == NULL || !clean(c, e, kv))
|
||||
goto done;
|
||||
if ((kl == 3 && !strncmp(kv, "url", 3)) ||
|
||||
(kl == 3 && !strncmp(kv, "cmd", 3)) ||
|
||||
(kl == 6 && !strncmp(kv, "header", 6)))
|
||||
sp_buf_printf(&l, " | %s", kv);
|
||||
else if (kl == 7 && !strncmp(kv, "enabled", 7))
|
||||
sp_buf_printf(&l, " | enabled=%d", boolean(eq + 1));
|
||||
else {
|
||||
fail(c, e->line, "unknown mcp server field '%.*s'",
|
||||
(int)kl, kv);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
emit(c, e->line, "%s", l.p);
|
||||
done:
|
||||
sp_buf_free(&l);
|
||||
}
|
||||
|
||||
/*
|
||||
* plugin NAME { path = ... enabled = false anything = else }
|
||||
*
|
||||
* The block loads the plugin -- the shipped one for NAME unless 'path' names
|
||||
* another -- and everything else in it is the plugin's own configuration,
|
||||
* which it reads with sp_host_plugin_config(host, NAME, key).
|
||||
*/
|
||||
static void
|
||||
do_plugin(struct cb *c, const char *name, unsigned line, struct ent *e,
|
||||
size_t n)
|
||||
{
|
||||
const char *path = NULL;
|
||||
char full[1024], list[2048], key[200];
|
||||
size_t i, j;
|
||||
int on = 1;
|
||||
|
||||
for (i = 0; name[i] != '\0'; i++)
|
||||
if (!isalnum((unsigned char)name[i]) && name[i] != '_' &&
|
||||
name[i] != '-') {
|
||||
fail(c, line, "plugin name '%s': letters, digits, _ and - "
|
||||
"only", name);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < n && !c->failed; i++) {
|
||||
if (!strcmp(e[i].key, "path") && !e[i].block) {
|
||||
path = one(c, &e[i]);
|
||||
if (path != NULL && !clean(c, &e[i], path))
|
||||
return;
|
||||
} else if (!strcmp(e[i].key, "enabled") && !e[i].block) {
|
||||
const char *s = one(c, &e[i]);
|
||||
|
||||
if (s == NULL)
|
||||
return;
|
||||
on = boolean(s);
|
||||
}
|
||||
}
|
||||
if (c->failed || !on)
|
||||
return;
|
||||
if (path != NULL && path[0] == '~' && path[1] == '/' &&
|
||||
getenv("HOME") != NULL) {
|
||||
snprintf(full, sizeof(full), "%s%s", getenv("HOME"), path + 1);
|
||||
path = full;
|
||||
}
|
||||
/* a bare name is the shipped plugin: main.c looks it up */
|
||||
emit(c, line, "plugin = %s", path != NULL ? path : name);
|
||||
for (i = 0; i < n && !c->failed; i++) {
|
||||
const struct ent *x = &e[i];
|
||||
|
||||
if ((!strcmp(x->key, "path") || !strcmp(x->key, "enabled")) &&
|
||||
!x->block)
|
||||
continue;
|
||||
if (x->block) {
|
||||
if (!strcmp(name, "mcp") && !strcmp(x->key, "server")) {
|
||||
mcp_server(c, x);
|
||||
continue;
|
||||
}
|
||||
for (j = 0; j < x->v.n && !c->failed; j++) {
|
||||
const char *kv = x->v.items[j];
|
||||
const char *eq = strchr(kv, '=');
|
||||
|
||||
if (eq == NULL)
|
||||
continue;
|
||||
if (x->sub[0] != '\0')
|
||||
snprintf(key, sizeof(key), "%s.%s.%.*s",
|
||||
x->key, x->sub, (int)(eq - kv), kv);
|
||||
else
|
||||
snprintf(key, sizeof(key), "%s.%.*s",
|
||||
x->key, (int)(eq - kv), kv);
|
||||
plugin_kv(c, x, name, key, eq + 1);
|
||||
}
|
||||
} else if (x->v.list) {
|
||||
joined(&x->v, list, sizeof(list));
|
||||
plugin_kv(c, x, name, x->key, list);
|
||||
} else {
|
||||
const char *s = one(c, x);
|
||||
|
||||
if (s == NULL)
|
||||
return;
|
||||
plugin_kv(c, x, name, x->key, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_exit(struct cb *c, const char *name, unsigned line, struct ent *e, size_t n)
|
||||
{
|
||||
@@ -533,10 +669,30 @@ body(struct cb *c, struct ent *e, int *closed)
|
||||
snprintf(e[n].key, sizeof(e[n].key), "%s", key);
|
||||
e[n].line = line;
|
||||
skip(c, 0);
|
||||
if (*c->p != '{' && *c->p != '=' && *c->p != '\0' &&
|
||||
*c->p != '\n') {
|
||||
/* key NAME { ... }: a named nested block (server junction) */
|
||||
size_t m = 0;
|
||||
|
||||
while (isalnum((unsigned char)*c->p) || *c->p == '_' ||
|
||||
*c->p == '-' || *c->p == '.') {
|
||||
if (m + 1 < sizeof(e[n].sub))
|
||||
e[n].sub[m++] = *c->p;
|
||||
c->p++;
|
||||
}
|
||||
e[n].sub[m] = '\0';
|
||||
skip(c, 0);
|
||||
if (m == 0 || *c->p != '{') {
|
||||
fail(c, line, "expected '{' after %s %s", key,
|
||||
e[n].sub);
|
||||
return n;
|
||||
}
|
||||
}
|
||||
if (*c->p == '{') {
|
||||
/* env { A = b } */
|
||||
/* env { A = b }, server junction { url = ... } */
|
||||
c->p++;
|
||||
e[n].v.list = 1;
|
||||
e[n].block = 1;
|
||||
for (;;) {
|
||||
char nm[96];
|
||||
size_t m = 0;
|
||||
@@ -554,7 +710,8 @@ body(struct cb *c, struct ent *e, int *closed)
|
||||
return n;
|
||||
}
|
||||
vl = c->line;
|
||||
while (isalnum((unsigned char)*c->p) || *c->p == '_') {
|
||||
while (isalnum((unsigned char)*c->p) || *c->p == '_' ||
|
||||
*c->p == '-' || *c->p == '.') {
|
||||
if (m + 1 < sizeof(nm))
|
||||
nm[m++] = *c->p;
|
||||
c->p++;
|
||||
@@ -699,7 +856,7 @@ sp_confblock_translate(const char *text, const char *path, struct sp_buf *out,
|
||||
if (!c.failed && closed) {
|
||||
int needs_name = !strcmp(kind, "provider") ||
|
||||
!strcmp(kind, "pool") || !strcmp(kind, "exit") ||
|
||||
!strcmp(kind, "mcp");
|
||||
!strcmp(kind, "mcp") || !strcmp(kind, "plugin");
|
||||
|
||||
if (needs_name && name[0] == '\0')
|
||||
fail(&c, line, "%s needs a name: %s NAME { ... }",
|
||||
@@ -727,11 +884,14 @@ sp_confblock_translate(const char *text, const char *path, struct sp_buf *out,
|
||||
do_pool(&c, name, line, e, n);
|
||||
else if (!strcmp(kind, "exit"))
|
||||
do_exit(&c, name, line, e, n);
|
||||
else if (!strcmp(kind, "plugin"))
|
||||
do_plugin(&c, name, line, e, n);
|
||||
else if (!strcmp(kind, "mcp"))
|
||||
/* deprecated: plugin mcp { server ID { ... } } */
|
||||
do_mcp(&c, name, line, e, n);
|
||||
else
|
||||
fail(&c, line, "unknown block '%s' (core, telegram, "
|
||||
"provider, pool, exit, mcp)", kind);
|
||||
"provider, pool, exit, plugin)", kind);
|
||||
}
|
||||
ents_free(e, n);
|
||||
if (c.failed)
|
||||
|
||||
+47
-2
@@ -776,6 +776,29 @@ load_stream(struct sp_config *c, FILE *f, const char *path,
|
||||
}
|
||||
else if (!strcmp(key, "default"))
|
||||
set_str(c->default_id, sizeof(c->default_id), val);
|
||||
else if (!strcmp(key, "plugin_conf")) {
|
||||
/* plugin_conf = NAME | key=value (from a plugin { } block) */
|
||||
struct sp_plugin_kv *kv;
|
||||
char *bar = strstr(val, " | "), *eq2;
|
||||
|
||||
if (bar == NULL || (eq2 = strchr(bar + 3, '=')) == NULL) {
|
||||
sp_buf_printf(err, "config: %s:%u: plugin_conf "
|
||||
"wants NAME | key=value", path, lineno);
|
||||
return -1;
|
||||
}
|
||||
if (c->nplugin_conf == SP_CONFIG_MAX_PLUGIN_KV) {
|
||||
sp_buf_printf(err, "config: %s:%u: more than %d "
|
||||
"plugin settings", path, lineno,
|
||||
SP_CONFIG_MAX_PLUGIN_KV);
|
||||
return -1;
|
||||
}
|
||||
kv = &c->plugin_conf[c->nplugin_conf++];
|
||||
*bar = '\0';
|
||||
*eq2 = '\0';
|
||||
set_str(kv->plugin, sizeof(kv->plugin), trim(val));
|
||||
set_str(kv->key, sizeof(kv->key), trim(bar + 3));
|
||||
set_str(kv->val, sizeof(kv->val), eq2 + 1);
|
||||
}
|
||||
else if (!strcmp(key, "plugin")) {
|
||||
if (c->nplugins == SP_CONFIG_MAX_PLUGINS) {
|
||||
sp_buf_printf(err, "config: %s:%u: more than %d "
|
||||
@@ -848,10 +871,14 @@ sp_config_write_example(const char *path, struct sp_buf *err)
|
||||
" # A usage limit is waited out: splinter finds the reset and goes on.\n"
|
||||
" #on_limit = wait # or fail\n"
|
||||
" #max_wait = 12h\n"
|
||||
"\n"
|
||||
" #plugins = [plugins/lcm/lcm.so, plugins/cps/cps.so]\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"# One block per plugin; what is in it is that plugin's own setting.\n"
|
||||
"#plugin lcm { }\n"
|
||||
"#plugin mcp {\n"
|
||||
"# server junction { url = http://127.0.0.1:8090/mcp }\n"
|
||||
"#}\n"
|
||||
"\n"
|
||||
"#telegram { allow = [123456789] }\n"
|
||||
"\n"
|
||||
"provider local {\n"
|
||||
@@ -1086,3 +1113,21 @@ sp_cli_command(const struct sp_delegate *d, const char *model, char *out,
|
||||
snprintf(out, cap, "%s --model %s", cmd, full);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_config_plugin_value(const struct sp_config *c, const char *plugin,
|
||||
const char *key)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (c == NULL || plugin == NULL || key == NULL)
|
||||
return NULL;
|
||||
/* the last one wins, like every other setting */
|
||||
for (i = c->nplugin_conf; i > 0; i--) {
|
||||
const struct sp_plugin_kv *kv = &c->plugin_conf[i - 1];
|
||||
|
||||
if (strcmp(kv->plugin, plugin) == 0 && strcmp(kv->key, key) == 0)
|
||||
return kv->val;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -22,6 +22,18 @@
|
||||
#include "splinter.h"
|
||||
|
||||
#define SP_CONFIG_MAX_PLUGINS 32
|
||||
#define SP_CONFIG_MAX_PLUGIN_KV 96
|
||||
|
||||
/*
|
||||
* One setting of a plugin's own configuration: plugin NAME { key = value }.
|
||||
* A nested block (server junction { url = ... }) gives dotted keys,
|
||||
* "server.junction.url"; a list becomes "a,b,c".
|
||||
*/
|
||||
struct sp_plugin_kv {
|
||||
char plugin[48];
|
||||
char key[96];
|
||||
char val[512];
|
||||
};
|
||||
|
||||
/*
|
||||
* A delegate is another model splinter may hand work to: a name, what it is
|
||||
@@ -136,6 +148,8 @@ struct sp_config {
|
||||
char locale[32]; /* language code, exported as SPLINTER_LOCALE */
|
||||
char plugins[SP_CONFIG_MAX_PLUGINS][512];
|
||||
size_t nplugins;
|
||||
struct sp_plugin_kv plugin_conf[SP_CONFIG_MAX_PLUGIN_KV];
|
||||
size_t nplugin_conf;
|
||||
struct sp_mcpserver mcp[SP_CONFIG_MAX_MCP];
|
||||
size_t nmcp;
|
||||
size_t steps; /* 0: not set */
|
||||
@@ -182,6 +196,13 @@ const char *sp_config_loaded_path(void);
|
||||
/* Write a commented starter file. Returns 0 or -1. */
|
||||
int sp_config_write_example(const char *path, struct sp_buf *err);
|
||||
|
||||
/*
|
||||
* A plugin's own setting (plugin NAME { key = value }), or NULL. 'key' may be
|
||||
* dotted for a nested block: "server.junction.url".
|
||||
*/
|
||||
const char *sp_config_plugin_value(const struct sp_config *,
|
||||
const char *plugin, const char *key);
|
||||
|
||||
/* Set every NAME=VALUE of 'env' in this process, overwriting. */
|
||||
void sp_config_apply_env(const char (*env)[SP_CONFIG_ENV_LEN], size_t n);
|
||||
|
||||
|
||||
+26
-8
@@ -569,15 +569,30 @@ shell_quote(struct sp_buf *b, const char *s)
|
||||
void
|
||||
sp_delegate_cli_plugin(const char *self, char *out, size_t len)
|
||||
{
|
||||
char dir[512], cand[3][600];
|
||||
const char *env = getenv("SPLINTER_CLI_PLUGIN");
|
||||
const char *slash;
|
||||
size_t n = 0, i;
|
||||
const char *env = getenv("SPLINTER_CLI_PLUGIN");
|
||||
|
||||
if (env != NULL && *env != '\0') {
|
||||
snprintf(out, len, "%s", env);
|
||||
return;
|
||||
}
|
||||
sp_plugin_path(self, "cli", out, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* A shipped plugin by name, for a binary at 'self'. Order:
|
||||
* <dir of self>/plugins/NAME/NAME.so the build tree
|
||||
* <dir of self>/../lib/splinter/plugins/NAME/NAME.so
|
||||
* <dir of self>/../lib/splinter/plugins/NAME.so what 'make install' writes
|
||||
* SPLINTER_PLUGIN_DIR/plugins/NAME/NAME.so the build tree compiled in
|
||||
* The first readable one wins; none: the first, so the error names a place.
|
||||
*/
|
||||
void
|
||||
sp_plugin_path(const char *self, const char *name, char *out, size_t len)
|
||||
{
|
||||
char dir[512], cand[4][700];
|
||||
const char *slash;
|
||||
size_t n = 0, i;
|
||||
|
||||
snprintf(dir, sizeof(dir), "%s",
|
||||
self != NULL && *self != '\0' ? self : "splinter");
|
||||
slash = strrchr(dir, '/');
|
||||
@@ -585,12 +600,15 @@ sp_delegate_cli_plugin(const char *self, char *out, size_t len)
|
||||
dir[slash - dir] = '\0';
|
||||
else
|
||||
snprintf(dir, sizeof(dir), ".");
|
||||
snprintf(cand[n++], sizeof(cand[0]), "%s/plugins/cli/cli.so", dir);
|
||||
snprintf(cand[n++], sizeof(cand[0]), "%s/plugins/%s/%s.so", dir, name,
|
||||
name);
|
||||
snprintf(cand[n++], sizeof(cand[0]),
|
||||
"%s/../lib/splinter/plugins/cli/cli.so", dir);
|
||||
"%s/../lib/splinter/plugins/%s/%s.so", dir, name, name);
|
||||
snprintf(cand[n++], sizeof(cand[0]),
|
||||
"%s/../lib/splinter/plugins/%s.so", dir, name);
|
||||
#ifdef SPLINTER_PLUGIN_DIR
|
||||
snprintf(cand[n++], sizeof(cand[0]), "%s/plugins/cli/cli.so",
|
||||
SPLINTER_PLUGIN_DIR);
|
||||
snprintf(cand[n++], sizeof(cand[0]), "%s/plugins/%s/%s.so",
|
||||
SPLINTER_PLUGIN_DIR, name, name);
|
||||
#endif
|
||||
for (i = 0; i < n; i++)
|
||||
if (access(cand[i], R_OK) == 0)
|
||||
|
||||
+22
-9
@@ -794,8 +794,23 @@ load_plugins(const struct opts *o, struct sp_registry *reg, struct sp_agent *ag,
|
||||
ag->host = host;
|
||||
sp_host_set_config(host, conf);
|
||||
for (k = 0; k < o->nplugins; k++) {
|
||||
const char *p = o->plugins[k];
|
||||
char self[512], found[800];
|
||||
ssize_t sn;
|
||||
|
||||
/*
|
||||
* A bare name ("lcm", from plugin lcm { }) is a shipped plugin:
|
||||
* the tree next to the binary, then the installed layout.
|
||||
*/
|
||||
if (strchr(p, '/') == NULL &&
|
||||
(strlen(p) < 3 || strcmp(p + strlen(p) - 3, ".so") != 0)) {
|
||||
sn = readlink("/proc/self/exe", self, sizeof(self) - 1);
|
||||
self[sn > 0 ? sn : 0] = '\0';
|
||||
sp_plugin_path(self, p, found, sizeof(found));
|
||||
p = found;
|
||||
}
|
||||
sp_buf_clear(err);
|
||||
if (sp_plugin_load(host, o->plugins[k], err) != 0)
|
||||
if (sp_plugin_load(host, p, err) != 0)
|
||||
fprintf(stderr, "splinter: %s\n", err->len > 0 ? err->p :
|
||||
sp_t("err.plugin_failed"));
|
||||
}
|
||||
@@ -973,16 +988,14 @@ apply_selection(struct opts *o, struct sp_config *conf)
|
||||
slash = strrchr(self, '/');
|
||||
if (slash != NULL)
|
||||
*slash = '\0';
|
||||
snprintf(plug, sizeof(plug), "%s/plugins/cli/cli.so", self);
|
||||
(void)plug;
|
||||
for (i = 0; i < o->nplugins; i++)
|
||||
if (strstr(o->plugins[i], "cli.so") != NULL)
|
||||
if (strstr(o->plugins[i], "cli.so") != NULL ||
|
||||
strcmp(o->plugins[i], "cli") == 0)
|
||||
have = 1;
|
||||
if (!have && o->nplugins < 32) {
|
||||
static char keep[600];
|
||||
|
||||
snprintf(keep, sizeof(keep), "%s", plug);
|
||||
o->plugins[o->nplugins++] = keep;
|
||||
}
|
||||
/* by name: load_plugins finds the tree or the installed one */
|
||||
if (!have && o->nplugins < 32)
|
||||
o->plugins[o->nplugins++] = "cli";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
+49
-3
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "splinter.h"
|
||||
#include "splinter_plugin.h"
|
||||
#include "config.h"
|
||||
|
||||
#define MAX_WIDGETS 32
|
||||
#define MAX_COMPACTORS 8
|
||||
@@ -108,9 +109,27 @@ widget_thread(void *arg)
|
||||
|
||||
if (w->interval_ms == 0)
|
||||
break;
|
||||
ts.tv_sec = w->interval_ms / 1000;
|
||||
ts.tv_nsec = (long)(w->interval_ms % 1000) * 1000000L;
|
||||
nanosleep(&ts, NULL);
|
||||
/*
|
||||
* Sleep in short steps and look at the stop flag between them:
|
||||
* one long sleep made the exit wait for a whole interval, since
|
||||
* sp_host_free() joins this thread.
|
||||
*/
|
||||
{
|
||||
unsigned long left = w->interval_ms;
|
||||
int stop = 0;
|
||||
|
||||
while (left > 0 && !stop) {
|
||||
unsigned long step = left > 100 ? 100 : left;
|
||||
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = (long)step * 1000000L;
|
||||
nanosleep(&ts, NULL);
|
||||
left -= step;
|
||||
pthread_mutex_lock(&w->lock);
|
||||
stop = w->stop;
|
||||
pthread_mutex_unlock(&w->lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -489,6 +508,33 @@ sp_host_set_config(struct sp_host *h, const void *conf)
|
||||
h->conf = conf;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_host_plugin_config(struct sp_host *h, const char *plugin, const char *key)
|
||||
{
|
||||
return sp_config_plugin_value(h != NULL ? h->conf : NULL, plugin, key);
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_host_plugin_config_at(struct sp_host *h, const char *plugin, size_t i,
|
||||
const char **key)
|
||||
{
|
||||
const struct sp_config *c = h != NULL ? h->conf : NULL;
|
||||
size_t k, seen = 0;
|
||||
|
||||
if (c == NULL || plugin == NULL)
|
||||
return NULL;
|
||||
for (k = 0; k < c->nplugin_conf; k++) {
|
||||
if (strcmp(c->plugin_conf[k].plugin, plugin) != 0)
|
||||
continue;
|
||||
if (seen++ == i) {
|
||||
if (key != NULL)
|
||||
*key = c->plugin_conf[k].key;
|
||||
return c->plugin_conf[k].val;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
sp_host_turn(struct sp_host *h)
|
||||
{
|
||||
|
||||
@@ -1814,11 +1814,27 @@ redraw(struct ui_state *s, struct sp_agent *ag, struct sp_host *host)
|
||||
doupdate();
|
||||
}
|
||||
|
||||
/*
|
||||
* The prompt mark, always followed by one space: the catalogue reader trims
|
||||
* trailing blanks, so "> " in the .msg file arrives as ">".
|
||||
*/
|
||||
static const char *
|
||||
prompt_mark(void)
|
||||
{
|
||||
static char buf[32];
|
||||
const char *m = sp_t("ui.prompt_mark");
|
||||
size_t n = strlen(m);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s%s", m, n > 0 && m[n - 1] == ' ' ?
|
||||
"" : " ");
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* the prompt line with what has been typed so far */
|
||||
static void
|
||||
draw_prompt(const char *input)
|
||||
{
|
||||
const char *mark = sp_t("ui.prompt_mark");
|
||||
const char *mark = prompt_mark();
|
||||
char *ascii;
|
||||
size_t n, avail, cap;
|
||||
int w = getmaxx(ui_input);
|
||||
@@ -2356,6 +2372,12 @@ ui_slash(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
|
||||
add_entry(s, "splinter", outbuf);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(name, "quit") == 0 || strcmp(name, "exit") == 0 ||
|
||||
strcmp(name, "q") == 0) {
|
||||
s->quit = 1;
|
||||
sp_buf_free(&out);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(name, "usage") == 0) {
|
||||
sp_usage_report(s->conf, &out);
|
||||
snprintf(outbuf, sizeof(outbuf), "%s", out.p ? out.p : "");
|
||||
@@ -3289,7 +3311,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model,
|
||||
draw_sidebar(&s, SESS_ID(ag), SESS_DIR(ag), host);
|
||||
draw_status(&s, NULL);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark"));
|
||||
mvwaddstr(ui_input, 0, 0, prompt_mark());
|
||||
wnoutrefresh(ui_input);
|
||||
doupdate();
|
||||
|
||||
@@ -3308,8 +3330,11 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model,
|
||||
"you were working on. Do not repeat work that is "
|
||||
"already done.");
|
||||
if (input[0] == '/' && input[1] != '\0' &&
|
||||
ui_slash(&s, ag, host, input, sizeof(input)))
|
||||
ui_slash(&s, ag, host, input, sizeof(input))) {
|
||||
if (s.quit)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (s.cc.active) {
|
||||
struct sp_buf o;
|
||||
|
||||
|
||||
@@ -236,6 +236,25 @@ main(void)
|
||||
sp_reply_free(&rep);
|
||||
sp_as_sse_free(sse);
|
||||
|
||||
/* two user turns in a row (the first one failed): one message, both blocks */
|
||||
{
|
||||
struct sp_conv c2;
|
||||
struct sp_buf r2;
|
||||
|
||||
sp_conv_init(&c2);
|
||||
CHECK(sp_buf_init(&r2) == 0);
|
||||
CHECK(sp_conv_push(&c2, "user", NULL, "first") == 0);
|
||||
CHECK(sp_conv_push(&c2, "user", NULL, "again") == 0);
|
||||
CHECK(sp_conv_push(&c2, "assistant", NULL, "ok") == 0);
|
||||
CHECK(sp_anthropic_request(&c2, "claude-x", ®, 0, 0, &r2) == 0);
|
||||
CHECK(strstr(r2.p, "\"messages\":[{\"role\":\"user\",\"content\":["
|
||||
"{\"type\":\"text\",\"text\":\"first\"},{\"type\":\"text\","
|
||||
"\"text\":\"again\"}]},{\"role\":\"assistant\"") != NULL);
|
||||
/* no block may stand outside a message */
|
||||
CHECK(strstr(r2.p, "]},{\"type\"") == NULL);
|
||||
sp_buf_free(&r2);
|
||||
sp_conv_free(&c2);
|
||||
}
|
||||
sp_buf_free(&req);
|
||||
sp_buf_free(&err);
|
||||
sp_buf_free(&delta);
|
||||
|
||||
@@ -136,6 +136,79 @@ main(void)
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("model = m\nsteps = 7\n", c, &err) == 0 && c->steps == 7);
|
||||
|
||||
/* plugin blocks: one per plugin, its own settings beside it */
|
||||
sp_buf_clear(&err);
|
||||
setenv("HOME", "/home/cb", 1);
|
||||
CHECK(load(
|
||||
"plugin lcm {\n"
|
||||
" keep = 40\n"
|
||||
" tags = [a, b]\n"
|
||||
" opts { depth = 3 }\n"
|
||||
"}\n"
|
||||
"plugin tmux { }\n"
|
||||
"plugin off { enabled = false\n x = 1 }\n"
|
||||
"plugin mine {\n"
|
||||
" path = ~/my/plugin.so\n"
|
||||
" foo = bar\n"
|
||||
" server s1 { url = http://h/mcp }\n"
|
||||
"}\n"
|
||||
"plugin mcp {\n"
|
||||
" server junction { url = http://172.25.206.16:8090/mcp }\n"
|
||||
" server local {\n"
|
||||
" cmd = \"tasksd --stdio\"\n"
|
||||
" header = \"Authorization: Bearer ${CB_TOKEN}\"\n"
|
||||
" enabled = no\n"
|
||||
" }\n"
|
||||
"}\n", c, &err) == 0);
|
||||
CHECK(c->nplugins == 4);
|
||||
CHECK(c->nplugins == 4 && strcmp(c->plugins[0], "lcm") == 0 &&
|
||||
strcmp(c->plugins[1], "tmux") == 0 &&
|
||||
strcmp(c->plugins[2], "/home/cb/my/plugin.so") == 0 &&
|
||||
strcmp(c->plugins[3], "mcp") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "lcm", "keep") != NULL &&
|
||||
strcmp(sp_config_plugin_value(c, "lcm", "keep"), "40") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "lcm", "tags") != NULL &&
|
||||
strcmp(sp_config_plugin_value(c, "lcm", "tags"), "a,b") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "lcm", "opts.depth") != NULL &&
|
||||
strcmp(sp_config_plugin_value(c, "lcm", "opts.depth"), "3") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "mine", "foo") != NULL &&
|
||||
strcmp(sp_config_plugin_value(c, "mine", "foo"), "bar") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "mine", "server.s1.url") != NULL &&
|
||||
strcmp(sp_config_plugin_value(c, "mine", "server.s1.url"),
|
||||
"http://h/mcp") == 0);
|
||||
CHECK(sp_config_plugin_value(c, "mine", "path") == NULL);
|
||||
CHECK(sp_config_plugin_value(c, "off", "x") == NULL);
|
||||
CHECK(sp_config_plugin_value(c, "lcm", "nope") == NULL);
|
||||
/* plugin mcp { server ... } is what mcp ID { } was */
|
||||
CHECK(c->nmcp == 2);
|
||||
CHECK(c->nmcp == 2 && strcmp(c->mcp[0].id, "junction") == 0 &&
|
||||
strcmp(c->mcp[0].url, "http://172.25.206.16:8090/mcp") == 0 &&
|
||||
c->mcp[0].enabled == 1);
|
||||
CHECK(c->nmcp == 2 && strcmp(c->mcp[1].id, "local") == 0 &&
|
||||
strcmp(c->mcp[1].cmd, "tasksd --stdio") == 0 &&
|
||||
strcmp(c->mcp[1].header, "Authorization: Bearer sekrit") == 0 &&
|
||||
c->mcp[1].enabled == 0);
|
||||
|
||||
/* the old forms still load: plugins = [...] and mcp ID { } */
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("core { plugins = [x/a.so] }\n"
|
||||
"mcp old { url = http://o/mcp }\n", c, &err) == 0);
|
||||
CHECK(c->nplugins == 1 && strcmp(c->plugins[0], "x/a.so") == 0);
|
||||
CHECK(c->nmcp == 1 && strcmp(c->mcp[0].id, "old") == 0);
|
||||
|
||||
/* errors */
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("plugin { x = 1 }\n", c, &err) != 0);
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("plugin a/b { }\n", c, &err) != 0);
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("plugin mcp {\n server { url = x }\n}\n", c, &err) != 0);
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("plugin mcp {\n server s { nope = x }\n}\n", c, &err) != 0);
|
||||
CHECK(strstr(err.p, ":2:") != NULL && strstr(err.p, "nope") != NULL);
|
||||
sp_buf_clear(&err);
|
||||
CHECK(load("plugin p { v = \"a|b\" }\n", c, &err) != 0);
|
||||
|
||||
free(c);
|
||||
if (failures == 0)
|
||||
puts("test_confblock: ok");
|
||||
|
||||
@@ -93,6 +93,21 @@ test_cli_plugin_path(void)
|
||||
CHECK(strcmp(got, "/explicit/cli.so") == 0);
|
||||
(void)unsetenv("SPLINTER_CLI_PLUGIN");
|
||||
|
||||
/* any shipped plugin by name; 'make install' writes a flat layout */
|
||||
(void)unlink(tree);
|
||||
(void)unlink(inst);
|
||||
snprintf(expect, sizeof(expect), "%s/lib/splinter/plugins/lcm.so", root);
|
||||
f = fopen(expect, "w");
|
||||
CHECK(f != NULL);
|
||||
if (f != NULL)
|
||||
fclose(f);
|
||||
sp_plugin_path(dir, "lcm", got, sizeof(got));
|
||||
snprintf(expect, sizeof(expect), "%s/bin/../lib/splinter/plugins/lcm.so",
|
||||
root);
|
||||
CHECK(strcmp(got, expect) == 0);
|
||||
sp_plugin_path(dir, "nothere", got, sizeof(got));
|
||||
CHECK(strstr(got, "/plugins/nothere/nothere.so") != NULL);
|
||||
|
||||
/* nothing found: the answer still names a cli plugin, so the child's
|
||||
* own error points at a place one can put it in (or at the build tree
|
||||
* this binary was compiled in) */
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "splinter.h"
|
||||
#include "splinter_plugin.h"
|
||||
#include "config.h"
|
||||
|
||||
static int failures;
|
||||
|
||||
@@ -115,6 +116,35 @@ main(void)
|
||||
CHECK(sp_registry_find(®, "broken") == NULL);
|
||||
}
|
||||
|
||||
/* a plugin reads its own block: plugin lcm { keep = 40 ... } */
|
||||
{
|
||||
static struct sp_config conf;
|
||||
const char *k = NULL;
|
||||
|
||||
CHECK(sp_host_plugin_config(host, "lcm", "keep") == NULL);
|
||||
sp_config_init(&conf);
|
||||
snprintf(conf.plugin_conf[0].plugin, 48, "lcm");
|
||||
snprintf(conf.plugin_conf[0].key, 96, "keep");
|
||||
snprintf(conf.plugin_conf[0].val, 512, "40");
|
||||
snprintf(conf.plugin_conf[1].plugin, 48, "mcp");
|
||||
snprintf(conf.plugin_conf[1].key, 96, "x");
|
||||
snprintf(conf.plugin_conf[1].val, 512, "y");
|
||||
snprintf(conf.plugin_conf[2].plugin, 48, "lcm");
|
||||
snprintf(conf.plugin_conf[2].key, 96, "server.a.url");
|
||||
snprintf(conf.plugin_conf[2].val, 512, "http://a");
|
||||
conf.nplugin_conf = 3;
|
||||
sp_host_set_config(host, &conf);
|
||||
CHECK(sp_host_plugin_config(host, "lcm", "keep") != NULL &&
|
||||
strcmp(sp_host_plugin_config(host, "lcm", "keep"), "40") == 0);
|
||||
CHECK(sp_host_plugin_config(host, "lcm", "x") == NULL);
|
||||
CHECK(sp_host_plugin_config_at(host, "lcm", 0, &k) != NULL &&
|
||||
k != NULL && strcmp(k, "keep") == 0);
|
||||
CHECK(sp_host_plugin_config_at(host, "lcm", 1, &k) != NULL &&
|
||||
k != NULL && strcmp(k, "server.a.url") == 0);
|
||||
CHECK(sp_host_plugin_config_at(host, "lcm", 2, &k) == NULL);
|
||||
sp_host_set_config(host, NULL);
|
||||
}
|
||||
|
||||
/* freeing the host stops the threads: no hang, no crash */
|
||||
sp_host_free(host);
|
||||
|
||||
|
||||
+3
-3
@@ -108,11 +108,11 @@ check grep -q 'vom gateway' "$D/out.txt"
|
||||
typed 'halb'
|
||||
check shows 'halb' # let the UI consume the keys
|
||||
key C-l; sleep 1
|
||||
check shows '^>halb'
|
||||
check shows '^> halb'
|
||||
key BSpace BSpace
|
||||
check shows '^>ha *$' # the backspaces arrived
|
||||
check shows '^> ha *$' # the backspaces arrived
|
||||
key C-l; sleep 1
|
||||
check shows '^>ha *$'
|
||||
check shows '^> ha *$'
|
||||
typed 'zeig eine tabelle'; key Enter
|
||||
check shows '| a | b |'
|
||||
check shows '|---|----|'
|
||||
|
||||
Reference in new issue
Block a user