diff --git a/src/swarm.c b/src/swarm.c index 08e1865..37362aa 100644 --- a/src/swarm.c +++ b/src/swarm.c @@ -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; } diff --git a/src/ui.c b/src/ui.c index 61c53c6..11e0c48 100644 --- a/src/ui.c +++ b/src/ui.c @@ -29,6 +29,7 @@ * * Keys: Enter sends, Ctrl-L redraws, Ctrl-C drops the input line, Ctrl-D quits. */ +#include #include #include #include @@ -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);