steer mode runs commands; provider names; mcp servers in the sidebar
/model and the other slash commands are not messages to the model. In steer mode a line starting with '/' or '!' now goes to the engine instead of steer(): - /model opens the picker at once. A selector chosen while a turn runs is remembered and applied between requests (tool_end) or at the end of the turn, because replacing the transport under a live curl frees the context the request is reading. The note says the switch follows the request. - /status, /cost, /usage, /sessions and ! answer immediately. - /new, /reset, /compact, /agent, /connect say "not while a turn runs" and are not sent to the model; /open says the same. - only a command that produces a prompt (e.g. /continue) is handed to steer(). The protocol input command allows slash commands while busy (plain text still gets "a turn is running"), so --attach behaves the same. The picker showed a phantom "main" provider with -m provider/model: the selected endpoint was copied into the config as main. It is only main when no configured provider owns it, so the row is now "junction qwen3.6-35b-judged". The stale ~/.splinter/splinter.conf.d/90-model.conf from the old global /model was moved aside; it was the other source of that "main" row. The mcp widget names every server and its state - "junction connected", "files disconnected" - instead of counting tools. make check: all tests passed.
This commit is contained in:
1 parent
00aba079c5
commit
056b8c4277
8 files changed
+232
-24
No files matched your search
@@ -413,7 +413,13 @@ input line or the status bar; an error is a transcript row below the row that
|
||||
caused it, and a backend request that failed before any answer is retried (the
|
||||
status row says so). A steer is picked up at the
|
||||
next step boundary; in a single-step turn it becomes the next message instead of
|
||||
being dropped. Curses is only ever touched by the UI thread.
|
||||
being dropped. A line that starts with `/` or `!` is a command, not a steer:
|
||||
`/model` opens the picker at once (the switch is applied between requests, so
|
||||
the transport under the running request is never freed), `/status`, `/cost`,
|
||||
`/usage`, `/sessions` and `!` answer immediately, and a command that rebuilds
|
||||
the conversation (`/new`, `/compact`, `/agent`, `/connect`) says "not while a
|
||||
turn runs" instead of being sent to the model. Curses is only ever touched by
|
||||
the UI thread.
|
||||
|
||||
A name is not text: `SP_STREAM_TOOL` carries the name of a call that has begun,
|
||||
and the answer text is built from `SP_STREAM_TEXT` alone. The stream used to be
|
||||
@@ -587,7 +593,9 @@ starts on. `/model <name>` keeps the endpoint and takes another model from it.
|
||||
really serve.
|
||||
|
||||
In the curses chat, `/model` alone opens a picker: Up/Down move, typing filters
|
||||
by provider or model, Enter takes the highlighted selector, Esc cancels. After
|
||||
by provider or model, Enter takes the highlighted selector, Esc cancels. The
|
||||
rows are named after the configured provider (`junction qwen3.6-35b-judged`);
|
||||
`-m provider/model` does not invent a second "main" row for the same endpoint. After
|
||||
the configured list appears, the picker asks the endpoint this session is on
|
||||
what it serves and adds those models, so a router's whole menu is selectable
|
||||
and not only the one alias in the config. It is the same list the clients get
|
||||
@@ -743,6 +751,10 @@ harness does not pretend to know better. With one server the tools are
|
||||
test server (the model called `mcp_add(17, 25)` and answered 42) and a socket
|
||||
server that speaks HTTP and SSE.
|
||||
|
||||
The sidebar names every server and says whether it is connected
|
||||
(`junction connected`, `files disconnected`), rather than only counting the
|
||||
tools they offered.
|
||||
|
||||
The one-server form from before still works:
|
||||
|
||||
SPLINTER_MCP_CMD="npx -y @modelcontextprotocol/server-filesystem /home" \
|
||||
|
||||
+22
-13
@@ -70,7 +70,7 @@ struct server {
|
||||
int next_id;
|
||||
int dead;
|
||||
int ntools;
|
||||
int up; /* handshake done and answering */
|
||||
volatile int up; /* handshake done and answering */
|
||||
int registered; /* its tools are in the registry (once) */
|
||||
pthread_mutex_t lock; /* one round trip at a time */
|
||||
};
|
||||
@@ -821,24 +821,33 @@ register_tools(struct server *s, size_t which, int prefix, struct sp_buf *err)
|
||||
|
||||
/* ---- plugin entry points ---- */
|
||||
|
||||
/* The sidebar says how many tools the servers offered and whether they are gone. */
|
||||
/*
|
||||
* The sidebar names every MCP server and whether it is connected, the way the
|
||||
* editor does: "junction connected", "local disconnected". The old line
|
||||
* counted tools, which said nothing about which server was gone.
|
||||
*/
|
||||
static int
|
||||
mcp_widget_tick(struct sp_host *h, const char *name, void *ctx)
|
||||
{
|
||||
char line[96];
|
||||
size_t i;
|
||||
int alive = 0, total = 0;
|
||||
char line[1024];
|
||||
size_t i, off = 0;
|
||||
|
||||
(void)ctx;
|
||||
for (i = 0; i < nsv; i++) {
|
||||
total += sv[i].up ? sv[i].ntools : 0;
|
||||
if (sv[i].up)
|
||||
alive++;
|
||||
if (nsv == 0) {
|
||||
(void)sp_host_widget_text(h, name,
|
||||
"no server configured");
|
||||
return 0;
|
||||
}
|
||||
for (i = 0; i < nsv && off < sizeof(line); i++) {
|
||||
int n;
|
||||
|
||||
n = snprintf(line + off, sizeof(line) - off, "%s%s %s",
|
||||
i > 0 ? "\n" : "", sv[i].id,
|
||||
sv[i].up ? "connected" : "disconnected");
|
||||
if (n < 0)
|
||||
break;
|
||||
off += (size_t)n;
|
||||
}
|
||||
if (nsv > 0 && alive == 0)
|
||||
snprintf(line, sizeof(line), "%d tools, offline", total);
|
||||
else
|
||||
snprintf(line, sizeof(line), "%d tools", total);
|
||||
(void)sp_host_widget_text(h, name, line);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ ui.steering_queued = Steuerung eingereiht
|
||||
ui.steer_queued_line = Steuerung eingereiht: %s
|
||||
ui.steer_failed = Steuerung nicht angenommen (kein Turn laeuft)
|
||||
ui.model_title = Modell
|
||||
ui.open_busy = Sitzungswechsel geht nicht waehrend ein Turn laeuft; /open danach
|
||||
ui.command_busy = nicht waehrend ein Turn laeuft; danach noch einmal
|
||||
ui.model_filter = filter:
|
||||
ui.model_hint = tippen filtert Pfeile bewegen Enter waehlt Esc bricht ab
|
||||
ui.status_turn = %lds
|
||||
@@ -171,6 +173,7 @@ model.none = Kein Modell konfiguriert. Mit /connect kommt eins dazu.
|
||||
model.unknown = Kein solches Modell: %s
|
||||
model.pool = Pool %s: %s (Anbieter %s, diese Sitzung).
|
||||
model.pools = Pools:
|
||||
model.pending = Modellwechsel auf %s nach der laufenden Anfrage
|
||||
ui.cancelling = breche ab ... (Ctrl-C nochmal beendet)
|
||||
model.failed = Umschalten fehlgeschlagen: %s
|
||||
model.switched = Modell: %s (Provider %s, diese Sitzung).
|
||||
|
||||
@@ -18,6 +18,8 @@ ui.steering_queued = steering queued
|
||||
ui.steer_queued_line = steering queued: %s
|
||||
ui.steer_failed = steering not accepted (no turn is running)
|
||||
ui.model_title = model
|
||||
ui.open_busy = cannot switch sessions while a turn runs; /open after the turn
|
||||
ui.command_busy = not while a turn runs; run it again after the turn
|
||||
ui.model_filter = filter:
|
||||
ui.model_hint = type to filter Up/Down move Enter selects Esc cancels
|
||||
ui.status_turn = %lds
|
||||
@@ -170,6 +172,7 @@ model.none = No model is configured. Add one with /connect.
|
||||
model.unknown = No such model: %s
|
||||
model.pool = Pool %s: using %s (provider %s, this session).
|
||||
model.pools = pools:
|
||||
model.pending = model switch to %s after the current request
|
||||
ui.cancelling = cancelling ... (Ctrl-C again quits)
|
||||
model.failed = Could not switch: %s
|
||||
model.switched = Model: %s (provider %s, this session).
|
||||
|
||||
@@ -19,6 +19,8 @@ ui.steering_queued = direcionamento na fila
|
||||
ui.steer_queued_line = direcionamento na fila: %s
|
||||
ui.steer_failed = direcionamento nao aceito (nenhum turno em andamento)
|
||||
ui.model_title = modelo
|
||||
ui.open_busy = nao da para trocar de sessao durante um turno; /open depois
|
||||
ui.command_busy = nao durante um turno; rode de novo depois
|
||||
ui.model_filter = filtro:
|
||||
ui.model_hint = digite para filtrar setas movem Enter escolhe Esc cancela
|
||||
ui.status_turn = %lds
|
||||
@@ -174,6 +176,7 @@ model.none = Nenhum modelo configurado. Adicione um com /connect.
|
||||
model.unknown = Modelo inexistente: %s
|
||||
model.pool = Pool %s: usando %s (provedor %s, esta sessao).
|
||||
model.pools = Pools:
|
||||
model.pending = troca de modelo para %s depois da requisicao atual
|
||||
ui.cancelling = cancelando ... (Ctrl-C de novo encerra)
|
||||
model.failed = Nao consegui trocar: %s
|
||||
model.switched = Modelo: %s (provedor %s, esta sessao).
|
||||
|
||||
+99
-7
@@ -77,6 +77,10 @@ struct sp_engine {
|
||||
char prompt_expanded[8192];
|
||||
char cur_model[256];
|
||||
char cur_endpoint[512];
|
||||
/* a /model chosen while a turn runs: applied between requests */
|
||||
char pend_model[320];
|
||||
int has_pend_model;
|
||||
pthread_mutex_t model_lock;
|
||||
char theme[48];
|
||||
char agent_name[48];
|
||||
char home_id[64]; /* provider before a profile moved it */
|
||||
@@ -143,6 +147,10 @@ struct sp_engine {
|
||||
size_t nq, capq;
|
||||
};
|
||||
|
||||
static void cmd_model_apply(struct sp_engine *, const char *,
|
||||
struct sp_buf *, int);
|
||||
static void engine_apply_pending_model(struct sp_engine *);
|
||||
|
||||
/* --------------------------------------------------------------- events */
|
||||
|
||||
/* the caller holds e->lock */
|
||||
@@ -861,6 +869,8 @@ engine_tool_end(void *ctx, const char *name, const char *obs)
|
||||
ev_push(e, SP_EV_TOOL_RESULT, kind == SP_OBS_JOIN ? 1 : 0,
|
||||
name, short_obs.p != NULL ? short_obs.p : "");
|
||||
sp_buf_free(&short_obs);
|
||||
/* a /model typed during the turn takes effect before the next request */
|
||||
engine_apply_pending_model(e);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1137,6 +1147,7 @@ turn_thread(void *arg)
|
||||
"interview saved to USER.txt"));
|
||||
ev_push(e, SP_EV_ENTRY, 0, "splinter", note);
|
||||
}
|
||||
engine_apply_pending_model(e);
|
||||
ev_push(e, SP_EV_TURN_END, rc,
|
||||
e->answer.p != NULL ? e->answer.p : "",
|
||||
e->err.p != NULL ? e->err.p : "");
|
||||
@@ -1764,7 +1775,8 @@ sp_engine_command_names(struct sp_engine *e, char (*names)[64], int max)
|
||||
* endpoints which models they really serve.
|
||||
*/
|
||||
static void
|
||||
cmd_model(struct sp_engine *e, const char *args, struct sp_buf *out)
|
||||
cmd_model_apply(struct sp_engine *e, const char *args, struct sp_buf *out,
|
||||
int defer)
|
||||
{
|
||||
struct sp_provider p;
|
||||
struct sp_buf perr;
|
||||
@@ -1772,6 +1784,22 @@ cmd_model(struct sp_engine *e, const char *args, struct sp_buf *out)
|
||||
char poolname[40];
|
||||
int is_pool = 0;
|
||||
|
||||
/*
|
||||
* Replacing the transport under a request in flight frees the curl
|
||||
* context the turn is still reading. While a turn runs, the selector is
|
||||
* remembered and applied by engine_apply_pending_model() between
|
||||
* requests (tool_end) or at the end of the turn.
|
||||
*/
|
||||
if (defer && args[0] != '\0' && strcmp(args, "probe") != 0 &&
|
||||
sp_engine_busy(e)) {
|
||||
pthread_mutex_lock(&e->model_lock);
|
||||
snprintf(e->pend_model, sizeof(e->pend_model), "%s", args);
|
||||
e->has_pend_model = 1;
|
||||
pthread_mutex_unlock(&e->model_lock);
|
||||
sp_buf_printf(out, sp_t("model.pending"), args);
|
||||
ev_push(e, SP_EV_STATE, 0, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
snprintf(poolname, sizeof(poolname), "%s", args);
|
||||
is_pool = sp_pool_find(e->conf, args) != NULL;
|
||||
if (!is_pool) {
|
||||
@@ -1957,6 +1985,36 @@ cmd_model(struct sp_engine *e, const char *args, struct sp_buf *out)
|
||||
ev_push(e, SP_EV_STATE, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
/* the ordinary /model: a running turn defers the switch */
|
||||
static void
|
||||
cmd_model(struct sp_engine *e, const char *args, struct sp_buf *out)
|
||||
{
|
||||
cmd_model_apply(e, args, out, 1);
|
||||
}
|
||||
|
||||
/* apply the selector a /model left while the turn was running */
|
||||
static void
|
||||
engine_apply_pending_model(struct sp_engine *e)
|
||||
{
|
||||
char sel[320];
|
||||
struct sp_buf out;
|
||||
|
||||
pthread_mutex_lock(&e->model_lock);
|
||||
if (!e->has_pend_model) {
|
||||
pthread_mutex_unlock(&e->model_lock);
|
||||
return;
|
||||
}
|
||||
snprintf(sel, sizeof(sel), "%s", e->pend_model);
|
||||
e->has_pend_model = 0;
|
||||
pthread_mutex_unlock(&e->model_lock);
|
||||
if (sp_buf_init(&out) != 0)
|
||||
return;
|
||||
cmd_model_apply(e, sel, &out, 0);
|
||||
if (out.p != NULL && out.len > 0)
|
||||
ev_push(e, SP_EV_ENTRY, 0, "splinter", out.p);
|
||||
sp_buf_free(&out);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_new(struct sp_engine *e, struct sp_buf *out)
|
||||
{
|
||||
@@ -2340,6 +2398,18 @@ sp_engine_input(struct sp_engine *e, const char *line, struct sp_buf *out)
|
||||
name[nlen] = '\0';
|
||||
snprintf(args, sizeof(args), "%s", sp + 1);
|
||||
}
|
||||
/*
|
||||
* Commands that rebuild the conversation or the prompt cannot run in
|
||||
* the middle of a turn. They are not steered into the model either: the
|
||||
* operator gets an honest "after this turn" and can repeat it then.
|
||||
*/
|
||||
if (sp_engine_busy(e) &&
|
||||
(strcmp(name, "new") == 0 || strcmp(name, "reset") == 0 ||
|
||||
strcmp(name, "compact") == 0 || strcmp(name, "agent") == 0 ||
|
||||
strcmp(name, "agents") == 0 || strcmp(name, "connect") == 0)) {
|
||||
sp_buf_puts(out, sp_t("ui.command_busy"));
|
||||
return SP_INPUT_HANDLED;
|
||||
}
|
||||
if (strcmp(name, "agent") == 0 || strcmp(name, "agents") == 0) {
|
||||
if (args[0] != '\0') {
|
||||
int idx = sp_agents_find(&e->agents, args);
|
||||
@@ -2771,6 +2841,7 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o,
|
||||
return -1;
|
||||
}
|
||||
pthread_mutex_init(&e->lock, NULL);
|
||||
pthread_mutex_init(&e->model_lock, NULL);
|
||||
pthread_cond_init(&e->cond, NULL);
|
||||
sp_buf_init(&e->answer);
|
||||
sp_buf_init(&e->err);
|
||||
@@ -2862,12 +2933,32 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o,
|
||||
* /model shows the run's providers, and a command line is part of the
|
||||
* run: --endpoint/--model without a config file still has a provider.
|
||||
*/
|
||||
if (e->conf->endpoint[0] == '\0' && o->endpoint != NULL)
|
||||
snprintf(e->conf->endpoint, sizeof(e->conf->endpoint), "%s",
|
||||
o->endpoint);
|
||||
if (e->conf->model[0] == '\0' && o->model != NULL)
|
||||
snprintf(e->conf->model, sizeof(e->conf->model), "%.255s",
|
||||
o->model);
|
||||
{
|
||||
/*
|
||||
* -m junction/model sets o->endpoint/model, but that is not a
|
||||
* main provider: junction is. Copying it into the config made
|
||||
* the picker show a phantom "main" beside the real provider.
|
||||
* Only an endpoint that came from the command line without a
|
||||
* matching configured provider becomes main.
|
||||
*/
|
||||
const char *act = sp_usage_active();
|
||||
int from_provider = 0;
|
||||
|
||||
if (act != NULL && *act != '\0' &&
|
||||
strcmp(act, "main") != 0 &&
|
||||
sp_provider_find(e->conf, act, NULL))
|
||||
from_provider = 1;
|
||||
if (!from_provider) {
|
||||
if (e->conf->endpoint[0] == '\0' && o->endpoint != NULL)
|
||||
snprintf(e->conf->endpoint,
|
||||
sizeof(e->conf->endpoint), "%s",
|
||||
o->endpoint);
|
||||
if (e->conf->model[0] == '\0' && o->model != NULL)
|
||||
snprintf(e->conf->model,
|
||||
sizeof(e->conf->model), "%.255s",
|
||||
o->model);
|
||||
}
|
||||
}
|
||||
if (setup_conversation(e, o, err) != 0)
|
||||
goto fail;
|
||||
e->ag.reg = &e->reg;
|
||||
@@ -2977,6 +3068,7 @@ sp_engine_close(struct sp_engine *e)
|
||||
}
|
||||
free(e->q);
|
||||
pthread_cond_destroy(&e->cond);
|
||||
pthread_mutex_destroy(&e->model_lock);
|
||||
pthread_mutex_destroy(&e->lock);
|
||||
free(e);
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ static void draw_sidebar(struct ui_state *, const char *, const char *,
|
||||
struct sp_host *);
|
||||
static void draw_statusbar(struct ui_state *);
|
||||
static void tmux_title_reset(void);
|
||||
static void session_line(void *, const char *, const char *, int, long);
|
||||
static size_t add_entry(struct ui_state *, const char *, const char *);
|
||||
static void drain_idle(struct ui_state *);
|
||||
|
||||
@@ -2772,6 +2773,76 @@ turn_approval(struct ui_state *s, int c)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* A slash command typed while a turn runs. It is not a message to the model:
|
||||
* /model opens the picker at once (the switch is applied between requests),
|
||||
* read-only commands answer now, and a command that rebuilds the conversation
|
||||
* says so instead of being steered. Only a command that itself produces a
|
||||
* prompt is sent as a steer, because that is what it asked for.
|
||||
*/
|
||||
static void
|
||||
turn_run_command(struct ui_state *s, const char *line)
|
||||
{
|
||||
struct sp_buf out;
|
||||
char cmd[1024];
|
||||
int kind;
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "%s", line);
|
||||
if (strcmp(cmd, "/model") == 0) {
|
||||
char sel[320];
|
||||
|
||||
if (model_picker(s->be, sel, sizeof(sel)) != 0) {
|
||||
clearok(curscr, TRUE);
|
||||
redraw(s, s->be);
|
||||
return;
|
||||
}
|
||||
snprintf(cmd, sizeof(cmd), "/model %s", sel);
|
||||
clearok(curscr, TRUE);
|
||||
redraw(s, s->be);
|
||||
}
|
||||
if (strncmp(cmd, "/open", 5) == 0 &&
|
||||
(cmd[5] == '\0' || cmd[5] == ' ')) {
|
||||
add_entry(s, "splinter", sp_t("ui.open_busy"));
|
||||
return;
|
||||
}
|
||||
if (strcmp(cmd, "/sessions") == 0) {
|
||||
struct sp_buf list;
|
||||
|
||||
if (sp_buf_init(&list) != 0)
|
||||
return;
|
||||
if (s->be->sessions(s->be->ctx, session_line, &list) == 0)
|
||||
sp_buf_puts(&list, sp_t("ui.no_sessions"));
|
||||
add_entry(s, "splinter", list.p != NULL ? list.p : "");
|
||||
sp_buf_free(&list);
|
||||
return;
|
||||
}
|
||||
if (sp_buf_init(&out) != 0)
|
||||
return;
|
||||
kind = s->be->input(s->be->ctx, cmd, &out);
|
||||
if (kind == SP_INPUT_HANDLED) {
|
||||
if (out.p != NULL && out.len > 0)
|
||||
add_entry(s, "splinter", out.p);
|
||||
if (strcmp(cmd, "/quit") == 0 || strcmp(cmd, "/exit") == 0 ||
|
||||
strcmp(cmd, "/q") == 0) {
|
||||
(void)s->be->cancel(s->be->ctx);
|
||||
s->quit = 1;
|
||||
}
|
||||
} else {
|
||||
const char *p = out.p != NULL && out.len > 0 ? out.p : cmd;
|
||||
char note[600];
|
||||
|
||||
if (s->be->steer(s->be->ctx, p) == 0) {
|
||||
snprintf(note, sizeof(note),
|
||||
sp_t("ui.steer_queued_line"), p);
|
||||
cut_line(note, 240);
|
||||
add_entry(s, "splinter", note);
|
||||
} else {
|
||||
add_entry(s, "error", sp_t("ui.steer_failed"));
|
||||
}
|
||||
}
|
||||
sp_buf_free(&out);
|
||||
}
|
||||
|
||||
/*
|
||||
* The keys of a running turn: type to steer (Enter queues the text for the
|
||||
* next step), PgUp/PgDn scroll, Ctrl-C cancels, Ctrl-D cancels and quits.
|
||||
@@ -2811,6 +2882,14 @@ turn_key(struct ui_state *s, struct turn_view *v, int c)
|
||||
if (v->llen > 0) {
|
||||
char line[600];
|
||||
|
||||
if (v->line[0] == '/' || v->line[0] == '!') {
|
||||
snprintf(line, sizeof(line), "%s", v->line);
|
||||
v->llen = 0;
|
||||
v->line[0] = '\0';
|
||||
turn_run_command(s, line);
|
||||
turn_draw_input(s, v);
|
||||
return 0;
|
||||
}
|
||||
if (s->be->steer(s->be->ctx, v->line) == 0) {
|
||||
/* the transcript is where a steer is a
|
||||
* message to the model, and where it stays
|
||||
|
||||
@@ -641,11 +641,18 @@ handle_line(struct client *c, struct proto *p, const char *line)
|
||||
text = mcp_arg_string(v, "line");
|
||||
if (text == NULL) {
|
||||
(void)send_error(c, "no line");
|
||||
} else if (sp_engine_busy(eng)) {
|
||||
} else if (sp_engine_busy(eng) &&
|
||||
text[0] != '/' && text[0] != '!') {
|
||||
/* steering is the 'steer' command; plain text is a turn */
|
||||
(void)send_error(c, "a turn is running");
|
||||
} else {
|
||||
handled = sp_engine_input(eng, text, &out);
|
||||
if (handled == SP_INPUT_PROMPT) {
|
||||
if (handled == SP_INPUT_PROMPT &&
|
||||
sp_engine_busy(eng)) {
|
||||
/* a prompt-producing command: hand it back,
|
||||
* do not start a second turn */
|
||||
(void)send_reply(c, out.p != NULL ? out.p : text);
|
||||
} else if (handled == SP_INPUT_PROMPT) {
|
||||
struct sp_buf prompt, b;
|
||||
|
||||
if (sp_buf_init(&prompt) != 0)
|
||||
|
||||
Reference in new issue
Block a user