diff --git a/src/builtin.c b/src/builtin.c index 6ce074c..1e6d0dd 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -87,7 +87,21 @@ tool_run(const char *args, struct sp_buf *out, void *ctx) sp_buf_free(&keep); return sp_buf_puts(out, "error: empty command"); } - p = popen(cmd, "r"); + /* + * stderr of the child belongs in the answer, not on the terminal: a curses + * screen that suddenly contains a shell error is broken, and the error is + * exactly what the model needs to see. + */ + { + struct sp_buf wrapped = { 0 }; + + if (sp_buf_init(&wrapped) == 0 && + sp_buf_printf(&wrapped, "{ %s\n} 2>&1", cmd) == 0) { + p = popen(wrapped.p, "r"); + sp_buf_free(&wrapped); + } else + p = popen(cmd, "r"); + } if (p == NULL) { rc = sp_buf_printf(out, "error: popen: %s", strerror(errno)); sp_buf_free(&keep); diff --git a/src/config.c b/src/config.c index 6e9fd20..9e0558e 100644 --- a/src/config.c +++ b/src/config.c @@ -212,7 +212,13 @@ parse_delegate(struct sp_delegate *d, const char *val, struct sp_buf *err, path, lineno); return -1; } - if (d->endpoint[0] == '\0' || d->model[0] == '\0') { + /* + * A cli delegate runs a program, not an endpoint: claude and opencode bring + * their own model choice. Requiring endpoint and model there would force a + * fake value into the file, which is worse than no value. + */ + if (strcmp(d->kind, "cli") != 0 && + (d->endpoint[0] == '\0' || d->model[0] == '\0')) { sp_buf_printf(err, "config: %s:%u: delegate '%s' needs endpoint " "and model", path, lineno, d->id); return -1; diff --git a/src/main.c b/src/main.c index a6ec6b3..85d6a4e 100644 --- a/src/main.c +++ b/src/main.c @@ -775,7 +775,7 @@ main(int argc, char **argv) fprintf(stderr, "splinter: kein Profil fuer '%s' - " "`splinter --interview` legt eins an\n", sp_memory_user()); - rc = sp_ui_run(&ag, endpoint, theme, host); + rc = sp_ui_run(&ag, endpoint, model, theme, host); if (have_mock) sp_mock_free(&mock); sp_host_free(host); diff --git a/src/ui.c b/src/ui.c index dadd602..72b2bdb 100644 --- a/src/ui.c +++ b/src/ui.c @@ -44,6 +44,13 @@ /* set while a turn runs: widgets hold still instead of ticking under the answer */ static volatile int g_turn_busy; +/* + * Who is speaking. Not the role - the name: the person from $USER, the model from + * the configuration. 'thinking is thinking' was a label talking about itself. + */ +static char g_who[128] = "you"; +static char g_model[128] = "model"; + #define MAX_ENTRIES 512 struct entry { @@ -521,15 +528,37 @@ static void entry_prefix(const struct entry *e, char *buf, size_t len) { struct tm tm; - char clock[16]; + char clock[16], who[64]; (void)localtime_r(&e->ts, &tm); strftime(clock, sizeof(clock), "%H:%M:%S", &tm); - if (strcmp(e->role, "thinking") == 0) - snprintf(buf, len, "[%s] * %s is thinking ", clock, - role_label(e->role)); - else - snprintf(buf, len, "[%s] <%s> ", clock, role_label(e->role)); + if (strcmp(e->role, "thinking") == 0) { + snprintf(who, sizeof(who), "%.40s", g_model); + { + char *dot = strstr(who, ".gguf"); + + if (dot != NULL) + *dot = '\0'; + } + snprintf(buf, len, "[%s] * %s is thinking: ", clock, who); + } else if (strcmp(e->role, "you") == 0) { + snprintf(who, sizeof(who), "%.40s", g_who); + snprintf(buf, len, "[%s] <%s> ", clock, who); + } else if (strcmp(e->role, "agent") == 0) { + snprintf(who, sizeof(who), "%.40s", g_model); + { + char *dot = strstr(who, ".gguf"); + + if (dot != NULL) + *dot = '\0'; + } + snprintf(buf, len, "[%s] <%s> ", clock, who); + } else if (strcmp(e->role, "splinter") == 0) { + snprintf(buf, len, "[%s] --- ", clock); + } else { + snprintf(who, sizeof(who), "%.40s", role_label(e->role)); + snprintf(buf, len, "[%s] <%s> ", clock, who); + } } static int @@ -541,7 +570,7 @@ entry_lines(int cols, const struct entry *e) if (cols < 2) return 1; { - char prefix[128]; + char prefix[256]; entry_prefix(e, prefix, sizeof(prefix)); len = strlen(prefix) + strlen(e->text) + 1; @@ -956,8 +985,8 @@ layout(void) } int -sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, - struct sp_host *host) +sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model, + const char *theme_name, struct sp_host *host) { struct ui_state s; struct sp_buf answer = { 0 }, err = { 0 }; @@ -968,6 +997,23 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, memset(&s, 0, sizeof(s)); sp_buf_init(&s.last_think); s.endpoint = endpoint; + { + const char *user = getenv("USER"); + const char *slash; + size_t n; + + if (user != NULL && *user != '\0') + snprintf(g_who, sizeof(g_who), "%s", user); + if (model != NULL && *model != '\0') { + /* a path like /models/x/y.gguf: the name is the last part */ + slash = strrchr(model, '/'); + snprintf(g_model, sizeof(g_model), "%s", + slash != NULL ? slash + 1 : model); + n = strlen(g_model); + if (n > 4 && strcmp(g_model + n - 4, ".gguf") == 0) + g_model[n - 4] = '\0'; + } + } g_status_host = host; /* the status line is drawn per tick */ if (sp_buf_init(&answer) != 0 || sp_buf_init(&err) != 0) return 1; @@ -1463,8 +1509,14 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, wrefresh(ui_input); continue; } - if (c == KEY_PPAGE) { - s.scroll += 3; + /* + * PgUp/PgDn and Shift+Up/Down scroll the + * conversation. The earlier PgDn moved a counter + * and never repainted, so the screen agreed with + * nothing. + */ + if (c == KEY_PPAGE || c == KEY_SR) { + s.scroll += (c == KEY_SR ? 1 : 10); draw_history(&s, 0); draw_sidebar(&s, ag->sess != NULL ? ag->sess->id : NULL, @@ -1474,11 +1526,18 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, doupdate(); continue; } - if (c == KEY_NPAGE) { - if (s.scroll > 3) - s.scroll = s.scroll >= 3 ? s.scroll - 3 : 0; - else - s.scroll = 0; + if (c == KEY_NPAGE || c == KEY_SF) { + int step = (c == KEY_SF ? 1 : 10); + + s.scroll = s.scroll > (size_t)step ? + s.scroll - (size_t)step : 0; + draw_history(&s, 0); + draw_sidebar(&s, ag->sess != NULL ? + ag->sess->id : NULL, + ag->sess != NULL ? ag->sess->dir : + NULL, host); + draw_status(&s); + doupdate(); continue; } if (c == 3) { diff --git a/src/ui.h b/src/ui.h index 709ab94..46cea9d 100644 --- a/src/ui.h +++ b/src/ui.h @@ -10,7 +10,7 @@ * palette name; NULL selects the default. `host` may be NULL (no plugins). * Returns 0 on a clean quit. */ -int sp_ui_run(struct sp_agent *ag, const char *endpoint, +int sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *model, const char *theme_name, struct sp_host *host); /* diff --git a/tests/test_ascii b/tests/test_ascii index d85eaf1..b622df3 100755 Binary files a/tests/test_ascii and b/tests/test_ascii differ