The goal lived only in the focus plugin's memory: a resume lost it and
there was no way to start the next turn from it. It is now stored in the
session's .meta (one line, 1000 bytes) and read back when the plugin sees a
new session id, so /open and a resumed process find their own goal again.
/continue reads the same sidecar and starts a turn with "Continue working
toward this goal: ...". /goal still sets it and starts the recap turn.
The sidebar was a patchwork of pairs and widgets could inherit the wrong
background. It now uses one PAIR_SIDE (white on a darkened theme
background) for every heading, label, usage row and widget; the window
gets that pair as its background, so no line paints its own surface.
New plugins/sysinfo: a widget thread samples /proc/meminfo, /proc/stat and
statvfs("/"), and publishes RAM, CPU, swap and disk with five-cell
[|||| ] gauges every two seconds. It is added to the shipped plugin list
and to the user's config.
agent.c keeps the last prompt/cache counters when a tool-call step reports
no usage. A zero there used to reset the ctx gauge in the status bar after
every tool call.
Tests: session goal survives reopen, /continue returns the prompt,
make check: all tests passed.
177 lines
4.5 KiB
C
177 lines
4.5 KiB
C
/* splinter -- append-only session tests. */
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
#include "splinter.h"
|
|
|
|
static int failures;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct sp_session_info s;
|
|
struct sp_buf err, line;
|
|
char tmpl[] = "/tmp/splinter-sess-XXXXXX";
|
|
char *dir;
|
|
char path[640];
|
|
size_t n;
|
|
FILE *f;
|
|
|
|
dir = mkdtemp(tmpl);
|
|
if (dir == NULL) {
|
|
perror("mkdtemp");
|
|
return 1;
|
|
}
|
|
if (sp_buf_init(&err) != 0)
|
|
return 1;
|
|
|
|
CHECK(sp_session_open(&s, dir, "s1", &err) == 0);
|
|
CHECK(strcmp(s.id, "s1") == 0);
|
|
|
|
CHECK(sp_session_count(&s, &n, &err) == 0);
|
|
CHECK(n == 0);
|
|
|
|
CHECK(sp_session_append(&s, "user", "hi \"there\"", &err) == 0);
|
|
CHECK(sp_session_append(&s, "assistant", "hello", &err) == 0);
|
|
CHECK(sp_session_count(&s, &n, &err) == 0);
|
|
CHECK(n == 2);
|
|
|
|
/* the record is valid JSONL with the text escaped */
|
|
snprintf(path, sizeof(path), "%s/s1.jsonl", dir);
|
|
f = fopen(path, "r");
|
|
CHECK(f != NULL);
|
|
if (f != NULL) {
|
|
if (sp_buf_init(&line) == 0) {
|
|
char buf[512];
|
|
size_t got = fread(buf, 1, sizeof(buf) - 1, f);
|
|
|
|
buf[got] = '\0';
|
|
CHECK(strstr(buf, "\"role\":\"user\"") != NULL);
|
|
CHECK(strstr(buf, "hi \\\"there\\\"") != NULL);
|
|
CHECK(buf[got - 1] == '\n');
|
|
sp_buf_free(&line);
|
|
}
|
|
fclose(f);
|
|
}
|
|
|
|
/* a torn tail must not be counted as a record and must not be an error */
|
|
f = fopen(path, "a");
|
|
CHECK(f != NULL);
|
|
if (f != NULL) {
|
|
fputs("{\"role\":\"user\",\"text\":\"torn", f);
|
|
fclose(f);
|
|
}
|
|
CHECK(sp_session_count(&s, &n, &err) == 0);
|
|
CHECK(n == 2);
|
|
|
|
/* the first user line is the title, and it survives reopening */
|
|
{
|
|
struct sp_session_brief v[4];
|
|
char mpath[700];
|
|
FILE *m;
|
|
char buf[512];
|
|
size_t got;
|
|
|
|
snprintf(mpath, sizeof(mpath), "%s/s1.meta", dir);
|
|
m = fopen(mpath, "r");
|
|
CHECK(m != NULL);
|
|
if (m != NULL) {
|
|
got = fread(buf, 1, sizeof(buf) - 1, m);
|
|
buf[got] = '\0';
|
|
CHECK(strstr(buf, "title=hi \"there\"") != NULL);
|
|
fclose(m);
|
|
}
|
|
CHECK(sp_session_list(dir, v, 4) == 1);
|
|
CHECK(strcmp(v[0].title, "hi \"there\"") == 0);
|
|
}
|
|
|
|
/* an explicit title wins and is not lost when the session is opened */
|
|
CHECK(sp_session_set_title(dir, "s1", "Ein Titel", &err) == 0);
|
|
CHECK(sp_session_open(&s, dir, "s1", &err) == 0);
|
|
/* the goal lives in the same sidecar and survives a reopen */
|
|
CHECK(sp_session_set_goal(dir, "s1", "Ship the config file", &err) == 0);
|
|
{
|
|
char goal[1001];
|
|
|
|
CHECK(sp_session_get_goal(dir, "s1", goal, sizeof(goal)) == 0);
|
|
CHECK(strcmp(goal, "Ship the config file") == 0);
|
|
CHECK(sp_session_open(&s, dir, "s1", &err) == 0);
|
|
CHECK(sp_session_get_goal(dir, "s1", goal, sizeof(goal)) == 0);
|
|
CHECK(strcmp(goal, "Ship the config file") == 0);
|
|
}
|
|
{
|
|
struct sp_session_brief v[4];
|
|
|
|
CHECK(sp_session_list(dir, v, 4) == 1);
|
|
CHECK(strcmp(v[0].title, "Ein Titel") == 0);
|
|
}
|
|
|
|
/* reopening an existing session appends, it never truncates */
|
|
CHECK(sp_session_open(&s, dir, "s1", &err) == 0);
|
|
CHECK(sp_session_append(&s, "user", "again", &err) == 0);
|
|
|
|
/* removal takes the log, sidecars and the per-session log directory */
|
|
{
|
|
char lpath[700], lfile[760];
|
|
FILE *lf;
|
|
|
|
snprintf(lpath, sizeof(lpath), "%s/logs", dir);
|
|
CHECK(mkdir(lpath, 0700) == 0 || errno == EEXIST);
|
|
snprintf(lpath, sizeof(lpath), "%s/logs/s1", dir);
|
|
CHECK(mkdir(lpath, 0700) == 0);
|
|
snprintf(lfile, sizeof(lfile), "%s/session.log", lpath);
|
|
lf = fopen(lfile, "w");
|
|
CHECK(lf != NULL);
|
|
if (lf != NULL) {
|
|
fputs("x\n", lf);
|
|
fclose(lf);
|
|
}
|
|
snprintf(path, sizeof(path), "%s/s1.jsonl", dir);
|
|
CHECK(sp_session_delete(dir, "s1", &err) == 0);
|
|
CHECK(access(path, F_OK) != 0);
|
|
CHECK(access(lpath, F_OK) != 0);
|
|
{
|
|
struct sp_session_brief v[4];
|
|
|
|
CHECK(sp_session_list(dir, v, 4) == 0);
|
|
}
|
|
CHECK(sp_session_delete(dir, "s1", &err) == -1);
|
|
}
|
|
|
|
/*
|
|
* A session from before titles existed has no title in its meta (or no
|
|
* meta at all): the listing reads the first user line itself.
|
|
*/
|
|
{
|
|
struct sp_session_brief v[4];
|
|
FILE *of;
|
|
|
|
snprintf(path, sizeof(path), "%s/old.jsonl", dir);
|
|
of = fopen(path, "w");
|
|
CHECK(of != NULL);
|
|
if (of != NULL) {
|
|
fputs("{\"role\":\"user\",\"text\":\"alte frage\"}\n",
|
|
of);
|
|
fclose(of);
|
|
}
|
|
CHECK(sp_session_list(dir, v, 4) == 1);
|
|
CHECK(strcmp(v[0].title, "alte frage") == 0);
|
|
CHECK(sp_session_delete(dir, "old", &err) == 0);
|
|
}
|
|
|
|
sp_buf_free(&err);
|
|
printf("test_session: ok (%s)\n", dir);
|
|
return failures == 0 ? 0 : 1;
|
|
}
|