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:
lotherkandClaude Opus 5.5 committed 2026-11-13 20:08:16 +00:00
1 parent 05c8d936e7
commit 2c58dcfd2a
8 files changed
+125 -12

No files matched your search

+2 -2
View File
@@ -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;
+38
View File
@@ -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;
}
+13
View File
@@ -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
View File
@@ -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
View File
@@ -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')