cli providers take a model: provider prefix, {model}, -m occli/MODEL
A kind = cli provider now has a default model and a prefix
(provider = opencode), so -m occli/deepseek-v4.1-flash-free runs
"opencode run --model opencode/deepseek-v4.1-flash-free". {model} in cmd
marks where the model goes, otherwise --model is appended; a model that
already has a '/' is used as it is. sp_cli_command() builds the command for
-m, delegates and the cli plugin's pool fallback. Model names are limited to
letters, digits and ._:/@+- since the command goes through /bin/sh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
05c8d936e7
commit
2c58dcfd2a
8 files changed
+125
-12
No files matched your search
@@ -71,6 +71,25 @@ pool claude { members = [claude-a, claude-b, anthropic-a] strategy = balance }
|
||||
| `anthropic` | `https://api.anthropic.com/v1` (POSTs to `/messages`) | `sk-ant-oat...` as a Bearer token with the oauth beta (a Claude Code token); `sk-ant-api...` as `x-api-key` |
|
||||
| `cli` | none; a program (`cmd`) | its own, from `env { }` |
|
||||
|
||||
A `cli` provider can take its model from `-m` like any other:
|
||||
|
||||
```
|
||||
provider occli {
|
||||
kind = cli
|
||||
cmd = "opencode run" # {model} marks where the model goes
|
||||
provider = opencode # prefix for a bare model name
|
||||
model = big-pickle # the default
|
||||
}
|
||||
```
|
||||
|
||||
`-m occli` runs `opencode run --model opencode/big-pickle`,
|
||||
`-m occli/deepseek-v4.1-flash-free` runs `... --model
|
||||
opencode/deepseek-v4.1-flash-free`, and a model that already has a `/`
|
||||
(`-m occli/opencode-go/kimi-k2`) is passed as it is. Without `{model}` in
|
||||
`cmd` the model is appended as `--model`; without any model the command runs
|
||||
unchanged. A model name may hold only letters, digits and `._:/@+-`, since the
|
||||
command goes through `/bin/sh`.
|
||||
|
||||
A `kind = anthropic` provider is called directly, without the `claude` CLI:
|
||||
tools become `tool_use` blocks, their observations `tool_result` blocks, and
|
||||
the system prompt is sent as the top-level `system` field. One provider per
|
||||
|
||||
+4
-2
@@ -647,8 +647,10 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
|
||||
"cli_fallback names no cli delegate");
|
||||
continue;
|
||||
}
|
||||
snprintf(alt.cmd, sizeof(alt.cmd), "%s",
|
||||
d->cmd[0] != '\0' ? d->cmd : "claude -p");
|
||||
if (sp_cli_command(d, NULL, alt.cmd,
|
||||
sizeof(alt.cmd)) != 0)
|
||||
snprintf(alt.cmd, sizeof(alt.cmd), "%s",
|
||||
d->cmd[0] != '\0' ? d->cmd : "claude -p");
|
||||
alt.env = (const char (*)[SP_CONFIG_ENV_LEN])d->env;
|
||||
alt.nenv = d->nenv;
|
||||
}
|
||||
|
||||
+2
-2
@@ -321,8 +321,8 @@ static void
|
||||
do_provider(struct cb *c, const char *name, unsigned line, struct ent *e,
|
||||
size_t n)
|
||||
{
|
||||
static const char *const plain[] = { "kind", "cmd", "host", "endpoint",
|
||||
"model", "key_env", "prio", "max_parallel", "limit", "tokens", NULL };
|
||||
static const char *const plain[] = { "kind", "cmd", "provider", "host",
|
||||
"endpoint", "model", "key_env", "prio", "max_parallel", "limit", "tokens", NULL };
|
||||
struct sp_buf l;
|
||||
const char *about = "";
|
||||
size_t i, j;
|
||||
|
||||
@@ -280,6 +280,9 @@ parse_delegate(struct sp_delegate *d, const char *val, struct sp_buf *err,
|
||||
}
|
||||
else if (!strncmp(s, "cmd=", 4))
|
||||
snprintf(d->cmd, sizeof(d->cmd), "%s", s + 4);
|
||||
else if (!strncmp(s, "provider=", 9))
|
||||
snprintf(d->cli_provider, sizeof(d->cli_provider), "%s",
|
||||
s + 9);
|
||||
else if (!strncmp(s, "tags=", 5))
|
||||
snprintf(d->tags, sizeof(d->tags), "%s", s + 5);
|
||||
else if (!strncmp(s, "endpoint=", 9))
|
||||
@@ -1048,3 +1051,38 @@ sp_config_scan_env(struct sp_config *c)
|
||||
n += scan_family(c, "CLAUDE_CODE_OAUTH_TOKEN", 0, 0);
|
||||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
sp_cli_command(const struct sp_delegate *d, const char *model, char *out,
|
||||
size_t cap)
|
||||
{
|
||||
const char *cmd, *ph, *m;
|
||||
char full[320];
|
||||
size_t k;
|
||||
|
||||
if (d == NULL || out == NULL || cap == 0)
|
||||
return -1;
|
||||
cmd = d->cmd[0] != '\0' ? d->cmd : "claude -p";
|
||||
m = model != NULL && *model != '\0' ? model : d->model;
|
||||
if (m == NULL || *m == '\0') {
|
||||
snprintf(out, cap, "%s", cmd);
|
||||
return 0;
|
||||
}
|
||||
for (k = 0; m[k] != '\0'; k++) {
|
||||
unsigned char ch = (unsigned char)m[k];
|
||||
|
||||
if (!(isalnum(ch) || strchr("._:/@+-", ch) != NULL))
|
||||
return -1;
|
||||
}
|
||||
if (strchr(m, '/') == NULL && d->cli_provider[0] != '\0')
|
||||
snprintf(full, sizeof(full), "%s/%s", d->cli_provider, m);
|
||||
else
|
||||
snprintf(full, sizeof(full), "%s", m);
|
||||
ph = strstr(cmd, "{model}");
|
||||
if (ph != NULL)
|
||||
snprintf(out, cap, "%.*s%s%s", (int)(ph - cmd), cmd, full,
|
||||
ph + 7);
|
||||
else
|
||||
snprintf(out, cap, "%s --model %s", cmd, full);
|
||||
return 0;
|
||||
}
|
||||
@@ -55,6 +55,8 @@ struct sp_delegate {
|
||||
char id[32];
|
||||
char kind[16]; /* "openai" (default) or "cli" */
|
||||
char cmd[256]; /* for kind=cli: the program, e.g. "claude -p" */
|
||||
char cli_provider[64]; /* kind=cli: prefix for a bare model,
|
||||
* "opencode" -> opencode/<model> */
|
||||
char key[256]; /* a literal key from the environment, if any */
|
||||
char host[128]; /* ssh target; empty means this machine */
|
||||
int prio; /* tie-break: higher wins */
|
||||
@@ -183,4 +185,15 @@ int sp_config_write_example(const char *path, struct sp_buf *err);
|
||||
/* 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);
|
||||
|
||||
/*
|
||||
* The command a cli provider runs with 'model' (NULL or "": its configured
|
||||
* model). A bare model gets the provider prefix ("provider = opencode" turns
|
||||
* big-pickle into opencode/big-pickle); one with a '/' is taken as it is.
|
||||
* {model} in cmd is replaced; without it the model is appended as
|
||||
* --model. No model at all: cmd unchanged. -1 for a model with characters a
|
||||
* shell would read (the command goes through /bin/sh).
|
||||
*/
|
||||
int sp_cli_command(const struct sp_delegate *d, const char *model,
|
||||
char *out, size_t cap);
|
||||
|
||||
#endif /* SPLINTER_CONFIG_H */
|
||||
+6
-2
@@ -630,8 +630,12 @@ exec_delegate(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
*/
|
||||
if (cli) {
|
||||
sp_delegate_cli_plugin(c->self, plug, sizeof(plug));
|
||||
if (d->cmd[0] != '\0')
|
||||
(void)setenv("SPLINTER_CLI_CMD", d->cmd, 1);
|
||||
{
|
||||
char cmd[600];
|
||||
|
||||
if (sp_cli_command(d, NULL, cmd, sizeof(cmd)) == 0)
|
||||
(void)setenv("SPLINTER_CLI_CMD", cmd, 1);
|
||||
}
|
||||
if (d->key[0] != '\0' && !remote) {
|
||||
const char *kenv = d->key_env[0] != '\0' ?
|
||||
d->key_env : "CLAUDE_CODE_OAUTH_TOKEN";
|
||||
|
||||
+16
-6
@@ -942,9 +942,15 @@ apply_selection(struct opts *o, struct sp_config *conf)
|
||||
ssize_t n;
|
||||
size_t k;
|
||||
|
||||
char cmd[600];
|
||||
|
||||
o->transport = "cli";
|
||||
setenv("SPLINTER_CLI_CMD", d->cmd[0] != '\0' ? d->cmd :
|
||||
"claude -p", 1);
|
||||
if (sp_cli_command(d, ch.model, cmd, sizeof(cmd)) != 0) {
|
||||
fprintf(stderr, "splinter: '%s' is not a model name\n",
|
||||
ch.model);
|
||||
return 2;
|
||||
}
|
||||
setenv("SPLINTER_CLI_CMD", cmd, 1);
|
||||
setenv("SPLINTER_CLI_ID", d->id, 1);
|
||||
sp_config_apply_env((const char (*)[SP_CONFIG_ENV_LEN])d->env,
|
||||
d->nenv);
|
||||
@@ -1037,10 +1043,14 @@ run_model_list(const struct sp_config *conf, const struct opts *o)
|
||||
|
||||
sp_usage_for(conf, d->id, &u);
|
||||
sp_usage_brief(&u, use, sizeof(use));
|
||||
snprintf(line, sizeof(line), "%s%s%s", d->kind[0] != '\0' &&
|
||||
strcmp(d->kind, "cli") == 0 ? "cli: " : "",
|
||||
d->kind[0] != '\0' && strcmp(d->kind, "cli") == 0 ? d->cmd :
|
||||
d->model, d->about[0] != '\0' ? "" : "");
|
||||
if (strcmp(d->kind, "cli") == 0) {
|
||||
char cmd[300];
|
||||
|
||||
if (sp_cli_command(d, NULL, cmd, sizeof(cmd)) != 0)
|
||||
snprintf(cmd, sizeof(cmd), "%s", d->cmd);
|
||||
snprintf(line, sizeof(line), "cli: %s", cmd);
|
||||
} else
|
||||
snprintf(line, sizeof(line), "%s", d->model);
|
||||
printf("%-34s %s [%s]\n", d->id, line, use);
|
||||
if (o->no_probe || strcmp(d->kind, "cli") == 0 ||
|
||||
d->endpoint[0] == '\0')
|
||||
|
||||
@@ -275,6 +275,33 @@ main(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* a cli provider takes its model from -m, its prefix from provider = */
|
||||
{
|
||||
struct sp_delegate d;
|
||||
char out[400];
|
||||
|
||||
memset(&d, 0, sizeof(d));
|
||||
snprintf(d.cmd, sizeof(d.cmd), "opencode run");
|
||||
CHECK(sp_cli_command(&d, NULL, out, sizeof(out)) == 0 &&
|
||||
strcmp(out, "opencode run") == 0);
|
||||
snprintf(d.cli_provider, sizeof(d.cli_provider), "opencode");
|
||||
snprintf(d.model, sizeof(d.model), "big-pickle");
|
||||
CHECK(sp_cli_command(&d, NULL, out, sizeof(out)) == 0 &&
|
||||
strcmp(out, "opencode run --model opencode/big-pickle") == 0);
|
||||
CHECK(sp_cli_command(&d, "deepseek-v4.1-flash-free", out,
|
||||
sizeof(out)) == 0 && strcmp(out, "opencode run --model "
|
||||
"opencode/deepseek-v4.1-flash-free") == 0);
|
||||
CHECK(sp_cli_command(&d, "opencode-go/kimi-k2", out,
|
||||
sizeof(out)) == 0 && strcmp(out,
|
||||
"opencode run --model opencode-go/kimi-k2") == 0);
|
||||
snprintf(d.cmd, sizeof(d.cmd), "claude -p --model {model} --x");
|
||||
d.cli_provider[0] = '\0';
|
||||
CHECK(sp_cli_command(&d, "opus", out, sizeof(out)) == 0 &&
|
||||
strcmp(out, "claude -p --model opus --x") == 0);
|
||||
CHECK(sp_cli_command(&d, "a;rm -rf ~", out, sizeof(out)) == -1);
|
||||
CHECK(sp_cli_command(&d, "a'b", out, sizeof(out)) == -1);
|
||||
}
|
||||
|
||||
if (failures == 0)
|
||||
printf("test_config: ok\n");
|
||||
return failures == 0 ? 0 : 1;
|
||||
|
||||
Reference in new issue
Block a user