splinter: approvals answered over telegram, widgets hold still, room to breathe
The gateway is the one reader of the chat, so it resolves approvals: 'ok 4711',
'no 4711', 'ja 4711', 'nein 4711' drop the answer file and confirm in the chat. A
second poller would have fought it for the same updates and lost replies.
Widgets freeze while a turn is processed. A clock that jumps every 500 ms next to
a streaming answer is noise, and the numbers beside it disagree with themselves.
The cache is refreshed again the moment the turn ends.
Tool calls were cut at 120 characters in the live line and 200 in the transcript;
the arguments are what makes a call readable, so they are no longer truncated and
the buffers grew to hold them. Measured: 'run {"command":"echo
dies-ist-ein-sehr-langer-befehl-...-abcdefghij"}' shows whole.
Layout: one column between chat and sidebar, one on both sides inside the chat.
Text at the very edge of a window reads like a terminal dump.
Also: the config line 'locale = de' forced German on a machine whose LANG is
en_US - removed, and the UI now says 'you:' and 'tool:' as it should.
This commit is contained in:
1 parent
8682f97759
commit
c12cb78a94
3 files changed
+59
-12
No files matched your search
@@ -31,6 +31,7 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ack.h"
|
||||
#include "splinter.h"
|
||||
#include "mcp.h"
|
||||
#include "log.h"
|
||||
@@ -337,6 +338,29 @@ sp_telegram_run(struct sp_agent *ag, struct sp_host *host, const char *token,
|
||||
* model: /goal and /recap come from plugins and
|
||||
* answer without a request.
|
||||
*/
|
||||
/*
|
||||
* An answer to a pending approval. The gateway is the one
|
||||
* reader of this chat, so it resolves here instead of letting a
|
||||
* second poller fight it for updates.
|
||||
*/
|
||||
if (strncmp(text, "ok ", 3) == 0 || strncmp(text, "no ", 3) == 0 ||
|
||||
strncmp(text, "ja ", 3) == 0 || strncmp(text, "nein ", 5) == 0) {
|
||||
const char *num = strchr(text, ' ');
|
||||
int id = num != NULL ? atoi(num + 1) : 0;
|
||||
|
||||
if (id > 0) {
|
||||
int yes = text[0] == 'o' || text[0] == 'j';
|
||||
|
||||
if (sp_ack_answer(id, yes, "telegram") == 0)
|
||||
(void)send_message(token, chat_id,
|
||||
yes ? "Zustimmung erteilt." :
|
||||
"Abgelehnt.", NULL);
|
||||
else
|
||||
(void)send_message(token, chat_id,
|
||||
"Diese Anfrage gibt es nicht (mehr).", NULL);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (text[0] == '/' && text[1] != '\0') {
|
||||
char name[32], *rest;
|
||||
size_t n = strcspn(text + 1, " ");
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
#include "theme.h"
|
||||
#include "ui.h"
|
||||
|
||||
/* set while a turn runs: widgets hold still instead of ticking under the answer */
|
||||
static volatile int g_turn_busy;
|
||||
|
||||
#define MAX_ENTRIES 512
|
||||
|
||||
struct entry {
|
||||
@@ -101,7 +104,7 @@ struct turn {
|
||||
struct sp_buf live; /* streamed text so far */
|
||||
struct sp_buf think; /* the model's reasoning so far */
|
||||
char tool[64]; /* last tool the model called */
|
||||
char tool_line[256]; /* name + args, for the live area */
|
||||
char tool_line[512]; /* name + args, for the live area */
|
||||
char tools_done[16][256]; /* finished calls, in order */
|
||||
char diffs[8][4096]; /* observations that carry a diff */
|
||||
int ndiffs;
|
||||
@@ -177,11 +180,11 @@ tool_begin_cb(void *ctx, const char *name, const char *args)
|
||||
if (name == NULL)
|
||||
return;
|
||||
pthread_mutex_lock(&t->lock);
|
||||
snprintf(t->tool_line, sizeof(t->tool_line), "%s %.120s", name,
|
||||
snprintf(t->tool_line, sizeof(t->tool_line), "%s %s", name,
|
||||
args != NULL ? args : "");
|
||||
if (t->ntools_done < 16)
|
||||
snprintf(t->tools_done[t->ntools_done++],
|
||||
sizeof(t->tools_done[0]), "%s %.200s", name,
|
||||
sizeof(t->tools_done[0]), "%s %s", name,
|
||||
args != NULL ? args : "");
|
||||
pthread_mutex_unlock(&t->lock);
|
||||
}
|
||||
@@ -226,8 +229,10 @@ turn_thread(void *arg)
|
||||
{
|
||||
struct turn *t = arg;
|
||||
|
||||
g_turn_busy = 1;
|
||||
t->rc = sp_agent_run(t->ag, t->text, &t->answer, &t->err);
|
||||
t->done = 1;
|
||||
g_turn_busy = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -550,6 +555,7 @@ draw_history(struct ui_state *s, int reserve)
|
||||
long skip = 0;
|
||||
|
||||
getmaxyx(ui_hist, rows, cols);
|
||||
cols -= 2; /* padding left and right */
|
||||
werase(ui_hist);
|
||||
wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
/* while a turn runs the bottom lines belong to it */
|
||||
@@ -588,7 +594,7 @@ draw_history(struct ui_state *s, int reserve)
|
||||
off = (long)strlen(render);
|
||||
skip = 0;
|
||||
|
||||
wmove(ui_hist, y, 0);
|
||||
wmove(ui_hist, y, 1);
|
||||
if (strcmp(e->role, "you") == 0)
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_ACCENT) | A_BOLD);
|
||||
else if (strcmp(e->role, "agent") == 0)
|
||||
@@ -674,10 +680,22 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
mvwaddnstr(ui_side, y++, 0, sp_t("sidebar.no_widgets"), cols - 1);
|
||||
} else {
|
||||
char snap[1024];
|
||||
char *line, *save = NULL;
|
||||
static char cache[1024];
|
||||
char snap[1024];
|
||||
char *line, *save = NULL;
|
||||
|
||||
sp_host_widget_snapshot(host, snap, sizeof(snap));
|
||||
/*
|
||||
* While a turn is being processed the widgets freeze: a clock that
|
||||
* jumps every 500 ms next to a streaming answer is noise, and the
|
||||
* numbers beside it (steps, tools) would disagree with themselves.
|
||||
*/
|
||||
if (g_turn_busy && cache[0] != '\0')
|
||||
snprintf(snap, sizeof(snap), "%s", cache);
|
||||
else {
|
||||
sp_host_widget_snapshot(host, snap, sizeof(snap));
|
||||
if (!g_turn_busy)
|
||||
snprintf(cache, sizeof(cache), "%s", snap);
|
||||
}
|
||||
for (line = strtok_r(snap, "\n", &save); line != NULL;
|
||||
line = strtok_r(NULL, "\n", &save)) {
|
||||
if (y >= getmaxy(ui_side))
|
||||
@@ -801,10 +819,15 @@ layout(void)
|
||||
int rows, cols, chat_w, side_w;
|
||||
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
chat_w = cols * 3 / 4;
|
||||
if (cols - chat_w < 12)
|
||||
chat_w = cols > 24 ? cols - 16 : cols;
|
||||
side_w = cols - chat_w;
|
||||
/*
|
||||
* One column of air between the chat and the sidebar, and one inside the
|
||||
* chat on both sides: text that starts at the very edge of a window reads
|
||||
* like a terminal dump, not like a conversation.
|
||||
*/
|
||||
chat_w = cols * 3 / 4 - 1;
|
||||
if (chat_w < 20)
|
||||
chat_w = cols > 40 ? cols * 3 / 4 : cols - 1;
|
||||
side_w = cols - chat_w - 1;
|
||||
/*
|
||||
* Order, top to bottom: chat and sidebar, then the status line, then the
|
||||
* input. Status above the prompt, the way Hermes shows it - the line you
|
||||
@@ -812,7 +835,7 @@ layout(void)
|
||||
*/
|
||||
ui_hist = newwin(rows - 2, chat_w, 0, 0);
|
||||
wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
ui_side = newwin(rows - 2, side_w, 0, chat_w);
|
||||
ui_side = newwin(rows - 2, side_w, 0, chat_w + 1);
|
||||
ui_status = newwin(1, cols, rows - 2, 0);
|
||||
ui_input = newwin(1, cols, rows - 1, 0);
|
||||
keypad(ui_input, TRUE);
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user