ui: a tool call reads like a call; a joined swarm session stays usable

The transcript said

  [23:12:05] <werkzeug> run  command: touch /tmp/.../made

which is the harness talking about itself. Hermes prints one row per call -
emoji, a capitalized verb, a one-line preview of the primary argument
(agent/display.py builds it per tool, 80 chars) and a duration; its long
outputs end in "... (N more lines)". opencode's TUI does the same shape: a
header line for the call, the output indented underneath.

So the row is ">> Run  touch /tmp/.../made" (verb capitalized, no
"command:" and no JSON for a shell call), and the observation hangs under it
as "| output", cut at 4 KiB with "... N lines". The log keeps the rest.

Also: the swarm master never sent "unlock", so a second splinter in the same
directory sat on "[swarm locked]" and swallowed every key - one of the
intermittent failures in the suite. Joining unlocks; the master locks a slave
only while it routes work to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-14 06:42:10 +00:00
1 parent 41f42cbf95
commit b05bb34cc7
2 files changed
+43 -7

No files matched your search

+16 -1
View File
@@ -189,6 +189,13 @@ master_accept(struct swarm *s)
p->fd = fd; p->id = id; p->alive = 1; p->busy = 0;
snprintf(msg, sizeof(msg), "{\"t\":\"welcome\",\"id\":%d,\"master\":%d}", id, (int)getpid());
send_line(fd, msg);
/*
* And immediately let it go. A joined session used to stay locked for
* good - nothing ever sent "unlock" - so a second splinter in the same
* directory sat on "[swarm locked]" and swallowed every key. A session is
* only locked while the fleet actually runs work on it.
*/
send_line(fd, "{\"t\":\"unlock\"}");
}
static void
@@ -338,10 +345,18 @@ swarm_route(struct swarm *s, int id, const char *text)
if (!p || p->fd < 0) return -1;
{
char esc[3500];
json_escape(esc, sizeof(esc), text);
if (text[0] == '\0') {
snprintf(msg, sizeof(msg), "{\"t\":\"unlock\"}");
send_line(p->fd, msg);
return id;
}
/* the slave is busy with fleet work: no local input until it is done */
send_line(p->fd, "{\"t\":\"lock\"}");
snprintf(msg, sizeof(msg), "{\"t\":\"exec\",\"text\":\"%s\"}", esc);
send_line(p->fd, msg);
}
send_line(p->fd, msg);
return id;
}
+27 -6
View File
@@ -29,6 +29,7 @@
*
* Keys: Enter sends, Ctrl-L redraws, Ctrl-C drops the input line, Ctrl-D quits.
*/
#include <ctype.h>
#include <curses.h>
#include <errno.h>
#include <iconv.h>
@@ -265,7 +266,13 @@ tool_end_cb(void *ctx, const char *name, const char *obs)
(void)name;
if (obs == NULL || *obs == '\0')
return;
while (*obs == '\n' || *obs == '\r')
obs++;
len = strlen(obs);
if (len == 0)
return;
while (len > 0 && (obs[len - 1] == '\n' || obs[len - 1] == '\r'))
len--;
if (len <= OBS_SHOW) {
shown = strdup(obs);
if (shown == NULL)
@@ -451,13 +458,24 @@ tool_begin_cb(void *ctx, const char *name, const char *args)
sp_buf_clear(&t->think);
sp_buf_clear(&t->live);
{
char call[640];
size_t n = strlen(shown);
/*
* ">> Run du -sh ../xsrc" reads like the thing that happened. The
* argument of a shell call is the command; saying "command:" before
* it, or pasting the JSON, is the harness talking about itself.
*/
char call[640], verb[64];
const char *detail = shown;
size_t n;
snprintf(verb, sizeof(verb), "%s", name);
verb[0] = (char)toupper((unsigned char)verb[0]);
if (strcmp(name, "run") == 0 && strncmp(detail, "command: ", 9) == 0)
detail += 9;
n = strlen(detail);
if (n > 200)
snprintf(call, sizeof(call), "%s %.200s...", name, shown);
snprintf(call, sizeof(call), "%s %.200s...", verb, detail);
else
snprintf(call, sizeof(call), "%s %s", name, shown);
snprintf(call, sizeof(call), "%s %s", verb, detail);
(void)ev_push(t, 'x', call);
}
pthread_mutex_unlock(&t->lock);
@@ -810,6 +828,10 @@ entry_prefix(const struct entry *e, char *buf, size_t len)
*dot = '\0';
}
snprintf(buf, len, "[%s] <%s> ", clock, who);
} else if (strcmp(e->role, "tool") == 0) {
snprintf(buf, len, "[%s] >> ", clock);
} else if (strcmp(e->role, "observation") == 0) {
snprintf(buf, len, "[%s] | ", clock);
} else if (strcmp(e->role, "splinter") == 0) {
snprintf(buf, len, "[%s] --- ", clock);
} else {
@@ -1176,8 +1198,7 @@ entry_layout(struct entry *e, int cols)
* Chat lines hang under their text. Command output, shell output and
* diffs are columns the author laid out: shifting them would break them.
*/
if (strcmp(e->role, "splinter") == 0 || strcmp(e->role, "shell") == 0 ||
strcmp(e->role, "tool") == 0 || strcmp(e->role, "observation") == 0)
if (strcmp(e->role, "splinter") == 0 || strcmp(e->role, "shell") == 0)
ind = 0;
else {
ind = (int)strlen(prefix);