v0.8.4: WebUI sessions, diff, settings, slash commands and extensions
Sessions: rename, delete and search; /api/retry regenerates the last answer, editing a prompt resends from there; /api/export downloads the transcript as Markdown (cst_session_export_md). Session messages carry note/tool_result markers, so a reload rebuilds the tool steps with their arguments, output and exit status; subagent progress is shown. Diff and settings: /api/diff shows the real diff; /api/settings covers protocol, max_steps, tool switches and confirm; /api/permissions edits the rules; sandbox status is reported. Session rename no longer reads past a short title. Commands: slash commands with completion in the composer (/model, /provider, /new, /retry, /undo, /compact, /export, /diff, /init, /skill and more), a Ctrl+P palette, Shift+Tab cycles the approval mode, F1 or ? shows the keys. "Thinking expanded" is saved in the settings (show_thinking), "expand all tool output" in the browser. Extensions: GET /api/extensions lists MCP servers, plugins, skills, agent roles and subagent runs; POST /api/extensions/reload and /api/extensions/trust; a workspace switch reloads them. /api/init and /api/skill run on the server (cst_init_prompt shared with the TUI). Errors, statuses and [cst] notes are shown in Chinese with a readable reason instead of rc=; a failed turn's error survives the reload. Tests: scripts/e2e_webui_sessions.py, e2e_webui_workspace.py and e2e_webui_ext.py, run from e2e_webui.sh.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "cJSON.h"
|
||||
#include "cst_agent.h"
|
||||
#include "cst_attach.h"
|
||||
#include "cst_util.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
@@ -409,3 +410,62 @@ int cst_session_rewrite(cst_session_t *s, const cst_message_t *msgs, int n) {
|
||||
free(copy);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int cst_message_is_tool_result(const cst_message_t *m) {
|
||||
return m && (m->role == CST_ROLE_TOOL ||
|
||||
(m->role == CST_ROLE_USER && m->tool_call_id[0]));
|
||||
}
|
||||
|
||||
static void md_fence(cst_buf_t *b, const char *s, size_t max) {
|
||||
size_t n = strlen(s);
|
||||
if (n > max)
|
||||
n = cst_utf8_floor(s, max);
|
||||
cst_buf_puts(b, "````\n");
|
||||
cst_buf_append(b, s, n);
|
||||
cst_buf_puts(b, n < strlen(s) ? "\n…(truncated)\n````\n\n" : "\n````\n\n");
|
||||
}
|
||||
|
||||
char *cst_session_export_md(cst_session_t *s, const char *title,
|
||||
const char *sid, const char *model) {
|
||||
if (!s)
|
||||
return NULL;
|
||||
cst_buf_t b = {0};
|
||||
cst_buf_printf(&b, "# %s\n\nsession `%s` · model `%s`\n\n",
|
||||
title ? title : "", sid ? sid : "", model ? model : "");
|
||||
cst_session_lock(s);
|
||||
for (int i = 0; i < cst_session_count(s); i++) {
|
||||
const cst_message_t *m = cst_session_get(s, i);
|
||||
const char *c = m->content ? m->content : "";
|
||||
if (m->role == CST_ROLE_SYSTEM)
|
||||
continue;
|
||||
if (cst_message_is_tool_result(m)) {
|
||||
cst_buf_printf(&b, "**Tool result** `%s`\n\n", m->tool_name);
|
||||
md_fence(&b, c, 4000);
|
||||
} else if (cst_message_is_note(m)) {
|
||||
cst_buf_puts(&b, "> ");
|
||||
cst_buf_append(&b, c, strcspn(c, "\n"));
|
||||
cst_buf_puts(&b, "\n\n");
|
||||
} else if (m->role == CST_ROLE_USER) {
|
||||
cst_buf_puts(&b, "## User\n\n");
|
||||
cst_buf_puts(&b, c);
|
||||
cst_buf_puts(&b, "\n\n");
|
||||
for (int k = 0; k < m->nattach; k++) {
|
||||
char d[128];
|
||||
cst_attach_describe(&m->attach[k], d, sizeof(d));
|
||||
cst_buf_printf(&b, "- image `%s` (%s)\n", m->attach[k].name, d);
|
||||
}
|
||||
if (m->nattach)
|
||||
cst_buf_puts(&b, "\n");
|
||||
} else {
|
||||
cst_buf_puts(&b, "## Assistant\n\n");
|
||||
cst_buf_puts(&b, c);
|
||||
cst_buf_puts(&b, "\n\n");
|
||||
if (m->tool_calls_json && m->tool_calls_json[0]) {
|
||||
cst_buf_puts(&b, "**Tool calls**\n\n");
|
||||
md_fence(&b, m->tool_calls_json, 4000);
|
||||
}
|
||||
}
|
||||
}
|
||||
cst_session_unlock(s);
|
||||
return cst_buf_steal(&b);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user