ui: show what the tools returned; the log keeps the order they happened

Three things were missing or doubled.

The reasoning is no longer cut to ten lines: it is shown as it comes.

A tool's observation was only ever shown when it carried a diff, and then as a
separate "diff" entry - so the output of a `run` was invisible in the chat
while the session log had it. Now every observation is an entry of its own
(role "observation"), capped at 4 KiB with the number of lines left out: a
300 KB JSON dump must not bury the conversation, and the log keeps all of it.
The separate diff queue is gone, which is also what printed a diff twice.

The session log had holes: the user's words were not logged at all, and the
reasoning only for the last step of a turn. Both are written now, and a step
that only called tools no longer leaves an empty "reply" record. The chat and
session.log carry the same records; the log has the full observation where
the screen keeps its head.

The call line keeps one readable line of arguments (200 chars, "..." after
that); the log has the whole argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-13 23:18:41 +00:00
1 parent cb73c4a0bb
commit 41f42cbf95
9 files changed
+86 -45

No files matched your search

+16
View File
@@ -242,6 +242,22 @@ The vendored NetBSD curses emits Latin-1 bytes for wide characters (`ü` becomes
That is a defect in the ported library, recorded here instead of being papered
over with a claim that it works.
## What you see, and what is on disk
The chat draws a transcript: `[time] <you>`, `[time] ~ denkt:` for the model's
reasoning, `[time] <werkzeug> run command: ...` for a tool call, `[time]
<ausgabe>` for what the tool returned, `[time] <model>` for the answer. A turn
that calls tools therefore reads in order: reasoning, text before the call,
the call, the output, text after it.
The same records go to `<session_dir>/logs/<session-id>/session.log`, in the
order they happened: the user's words, the model's answer, its reasoning, every
call with its arguments, every observation, failures and token counts.
`wire.jsonl` next to it keeps the request bodies and replies, raw. The log is
the complete record - the screen keeps the head of a long observation (4 KiB,
with the number of lines left out) so a 300 KB JSON dump does not bury the
conversation; the log has all of it.
## Input history
Up and Down walk through what was typed before, like a shell. The list is kept
+1
View File
@@ -32,6 +32,7 @@ err.session = Sitzung
err.plugin_failed = Plugin fehlgeschlagen
role.tool = werkzeug
role.observation = ausgabe
err.thread = Turn-Thread laesst sich nicht starten
err.turn_failed = Turn fehlgeschlagen
focus.reminder = Pruefe vor der Antwort, ob der letzte Schritt naeher am Ziel war; wenn nicht, sage das und nenne den naechsten Schritt. Ziel: %s
+1
View File
@@ -31,6 +31,7 @@ err.session = session
err.plugin_failed = plugin failed
role.tool = tool
role.observation = output
err.thread = cannot start the turn thread
err.turn_failed = turn failed
focus.reminder = Before answering, check whether the last step moved closer to the goal. If not, say so and name the next step. Goal: %s
+1
View File
@@ -23,6 +23,7 @@ role.you = voce
role.agent = modelo
role.thinking = pensando
role.tool = ferramenta
role.observation = saida
role.shell = shell
role.splinter = splinter
role.error = erro
+2
View File
@@ -469,6 +469,7 @@ agent_loop(struct sp_agent *a, struct sp_conv *conv, int resume, int decision,
sp_buf_free(&steer);
goto oom;
}
sp_logf("user", "%s", steer.p);
if (a->sess != NULL)
(void)sp_session_append(a->sess, "user",
steer.p, err);
@@ -709,6 +710,7 @@ sp_agent_run(struct sp_agent *a, const char *user_text, struct sp_buf *answer,
}
}
sp_host_turn(a->host);
sp_logf("user", "%s", user_text != NULL ? user_text : "");
if (sp_conv_push(conv, "user", NULL, user_text) != 0) {
sp_buf_puts(err, "agent: out of memory");
if (conv == &local)
+3 -1
View File
@@ -513,7 +513,9 @@ as_stream(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
}
if (sp_as_sse_finish(sse, out, err) != 0)
goto out;
sp_logf("reply", "%s", out->content != NULL ? out->content : "");
/* a step that only called tools said nothing: no empty record */
if (out->content != NULL && out->content[0] != '\0')
sp_logf("reply", "%s", out->content);
if (out->content != NULL && out->content[0] == '\0' && out->ncalls == 0) {
sp_buf_printf(err, "anthropic: stream ended with no answer: %.300s",
tail.p != NULL ? tail.p : "(empty)");
+3 -1
View File
@@ -576,7 +576,9 @@ openai_stream(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
}
if (sp_sse_finish(sse, out, err) != 0)
goto out;
sp_logf("reply", "%s", out->content != NULL ? out->content : "");
/* a step that only called tools said nothing: no empty record */
if (out->content != NULL && out->content[0] != '\0')
sp_logf("reply", "%s", out->content);
if (out->content != NULL && out->content[0] == '\0' && out->ncalls == 0) {
sp_buf_printf(err, sp_td("openai.stream_no_answer", "openai: stream ended with no answer: %.300s"),
tail.p != NULL ? tail.p : "(empty)");
+55 -39
View File
@@ -191,8 +191,6 @@ struct turn {
int nev, capev;
char tool[64]; /* last tool the model called */
char tool_line[512]; /* name + args, for the live area */
char diffs[8][4096]; /* observations that carry a diff */
int ndiffs;
int tool_tick;
int compacted; /* compaction events to show in chat */
size_t c_bytes_before;
@@ -209,6 +207,8 @@ struct turn {
pthread_mutex_t lock;
};
static int ev_push(struct turn *, int, const char *);
/*
* Called from the turn thread right before a tool runs. The UI drains the list
* on its next tick and writes the calls into the transcript in order - so the
@@ -246,19 +246,55 @@ approve_cb(void *ctx, const char *name, int auth, const char *args)
return answer;
}
/* Keep the observations that carry a diff; the rest is noise in the transcript. */
/*
* What the tool returned, into the transcript. A full `run` can carry a
* 300 KB JSON dump, and printing that would bury the conversation, so the
* entry keeps the head of it and says how much is left. The whole text is in
* the session log either way - the log gets what the harness saw, not what
* fits on screen.
*/
#define OBS_SHOW 4096 /* bytes of an observation the transcript keeps */
static void
tool_end_cb(void *ctx, const char *name, const char *obs)
{
struct turn *t = ctx;
char *shown;
size_t len, keep, i, rest = 0;
(void)name;
if (obs == NULL || strstr(obs, "--- a/") == NULL)
if (obs == NULL || *obs == '\0')
return;
len = strlen(obs);
if (len <= OBS_SHOW) {
shown = strdup(obs);
if (shown == NULL)
return;
} else {
keep = OBS_SHOW;
while (keep > 0 && obs[keep - 1] != '\n')
keep--;
if (keep == 0)
keep = OBS_SHOW;
for (i = keep; i < len; i++)
if (obs[i] == '\n')
rest++;
shown = malloc(keep + 128);
if (shown == NULL)
return;
memcpy(shown, obs, keep);
shown[keep] = '\0';
if (rest > 0) {
char mark[80];
snprintf(mark, sizeof(mark), sp_t("ui.more_lines"), rest);
snprintf(shown + keep, 128, "\n%s", mark);
}
}
pthread_mutex_lock(&t->lock);
if (t->ndiffs < 8)
snprintf(t->diffs[t->ndiffs++], sizeof(t->diffs[0]), "%s", obs);
(void)ev_push(t, 'o', shown);
pthread_mutex_unlock(&t->lock);
free(shown);
}
/*
@@ -416,8 +452,12 @@ tool_begin_cb(void *ctx, const char *name, const char *args)
sp_buf_clear(&t->live);
{
char call[640];
size_t n = strlen(shown);
snprintf(call, sizeof(call), "%s %.480s", name, shown);
if (n > 200)
snprintf(call, sizeof(call), "%s %.200s...", name, shown);
else
snprintf(call, sizeof(call), "%s %s", name, shown);
(void)ev_push(t, 'x', call);
}
pthread_mutex_unlock(&t->lock);
@@ -999,7 +1039,6 @@ sp_ui_ascii_char(const char *s, char *out, size_t cap)
struct vline {
size_t beg, end; /* bytes of the plain text */
int indent; /* columns left of the text */
size_t skipped; /* > 0: a "... N more lines" marker, no text */
};
struct elayout {
@@ -1010,10 +1049,8 @@ struct elayout {
int blank; /* a gap before this entry */
};
#define THINK_LINES 10 /* a reasoning stream shows its last lines */
static int
vl_add(struct elayout *l, size_t beg, size_t end, int indent, size_t skipped)
vl_add(struct elayout *l, size_t beg, size_t end, int indent)
{
if (l->n == l->cap) {
size_t nc = l->cap != 0 ? l->cap * 2 : 16;
@@ -1027,7 +1064,6 @@ vl_add(struct elayout *l, size_t beg, size_t end, int indent, size_t skipped)
l->v[l->n].beg = beg;
l->v[l->n].end = end;
l->v[l->n].indent = indent;
l->v[l->n].skipped = skipped;
l->n++;
return 0;
}
@@ -1073,7 +1109,7 @@ wrap_text(struct elayout *l, const char *p, int cols, int ind)
w += cw;
i += n;
}
if (vl_add(l, beg, end, indent, 0) != 0)
if (vl_add(l, beg, end, indent) != 0)
return;
first = 0;
if (wrapped) {
@@ -1141,7 +1177,7 @@ entry_layout(struct entry *e, int cols)
* 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, "diff") == 0)
strcmp(e->role, "tool") == 0 || strcmp(e->role, "observation") == 0)
ind = 0;
else {
ind = (int)strlen(prefix);
@@ -1152,19 +1188,8 @@ entry_layout(struct entry *e, int cols)
}
wrap_text(l, l->plain, cols, ind);
/* blank lines at the end are not content */
while (l->n > 1 && l->v[l->n - 1].beg == l->v[l->n - 1].end &&
l->v[l->n - 1].skipped == 0)
while (l->n > 1 && l->v[l->n - 1].beg == l->v[l->n - 1].end)
l->n--;
if (strcmp(e->role, "thinking") == 0 && l->n > THINK_LINES) {
size_t keep = THINK_LINES - 2, drop = l->n - 1 - keep, k;
l->v[1].skipped = drop;
l->v[1].beg = l->v[1].end = 0;
l->v[1].indent = ind;
for (k = 0; k < keep; k++)
l->v[2 + k] = l->v[l->n - keep + k];
l->n = 2 + keep;
}
return l;
}
@@ -1178,15 +1203,6 @@ draw_vline(int y, const struct elayout *l, const struct vline *vl)
(void)wattr_get(ui_hist, &base, &pair, NULL);
base &= ~A_COLOR;
if (vl->skipped > 0) {
char m[64];
snprintf(m, sizeof(m), sp_t("ui.more_lines"), vl->skipped);
(void)wattr_set(ui_hist, base, PAIR_DIM, NULL);
mvwaddstr(ui_hist, y, x, m);
(void)wattr_set(ui_hist, base, pair, NULL);
return;
}
for (i = vl->beg; i < vl->end;) {
char o[8];
unsigned a = l->attr != NULL ? l->attr[i] : 0;
@@ -2732,7 +2748,6 @@ ui_slash(struct ui_state *s, struct sp_agent *ag, struct sp_host *host,
struct turn_view {
struct timespec t0;
int drained; /* events already in the transcript */
int drained_d; /* diffs already in the transcript */
struct seg {
size_t id; /* entry showing the open part, 0 = none */
size_t off; /* bytes before the open entry */
@@ -2822,9 +2837,6 @@ turn_drain(struct ui_state *s, struct turn *tu, struct turn_view *v)
nev++;
v->drained++;
}
for (k = v->drained_d; k < tu->ndiffs; k++)
add_entry(s, "diff", tu->diffs[k]);
v->drained_d = tu->ndiffs;
compacted = tu->compacted;
cb = tu->c_bytes_before; ca = tu->c_bytes_after;
cm = tu->c_msgs_before; cn = tu->c_msgs_after;
@@ -2834,9 +2846,13 @@ turn_drain(struct ui_state *s, struct turn *tu, struct turn_view *v)
pthread_mutex_unlock(&tu->lock);
for (k = 0; k < nev; k++) {
const char *role = ev[k].kind == 'x' ? "tool" :
ev[k].kind == 'o' ? "observation" :
ev[k].kind == 'n' ? "splinter" :
ev[k].kind == 't' ? "thinking" : "agent";
/* the log gets what the screen gets, in the same order */
if (ev[k].kind == 't')
sp_logf("thinking", "%s", ev[k].text);
add_entry(s, role, ev[k].text);
free(ev[k].text);
}
+4 -4
View File
@@ -51,8 +51,8 @@ def hardcoded():
# Roles are keys too: add_entry() takes an identifier, the label comes from the
# catalogue. An unknown identifier would ship as untranslated text.
ROLE_CALL = re.compile(r'add_entry\(\s*&?[A-Za-z_>.-]*\s*,\s*"([a-z_]+)"')
ALLOWED_ROLES = {"you", "agent", "thinking", "tool", "error", "shell",
"splinter", "diff"}
ALLOWED_ROLES = {"you", "agent", "thinking", "tool", "observation", "error",
"shell", "splinter", "diff"}
def unknown_roles():
@@ -70,8 +70,8 @@ def main():
used = used_keys()
# role.<x> is built by role_label(), never written literally
used.add("role.you"); used.add("role.agent"); used.add("role.thinking")
used.add("role.tool"); used.add("role.error"); used.add("role.shell")
used.add("role.splinter"); used.add("role.diff")
used.add("role.tool"); used.add("role.observation"); used.add("role.error")
used.add("role.shell"); used.add("role.splinter"); used.add("role.diff")
bad = 0
cats = sorted(ROOT.glob("share/locale/*.msg"))
if not cats: