goal in the session, /continue, a white sidebar, sysinfo
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.
This commit is contained in:
1 parent
006198425c
commit
67b4d5d070
21 files changed
+433
-28
No files matched your search
@@ -43,6 +43,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
|
||||
plugins/scheduler/scheduler.so \
|
||||
plugins/planner/planner.so \
|
||||
plugins/a2a/a2a.so \
|
||||
plugins/sysinfo/sysinfo.so \
|
||||
plugins/tmux/tmux.so
|
||||
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
|
||||
tests/test_transport tests/test_agent tests/test_openai \
|
||||
@@ -364,3 +365,7 @@ plugins/tmux/tmux.so: plugins/tmux/tmux.c $(LIB)
|
||||
plugins/a2a/a2a.so: plugins/a2a/a2a.c $(LIB)
|
||||
$(CC) $(CFLAGS) -shared -o $@ plugins/a2a/a2a.c -L. -lsplinter \
|
||||
$(PLUGIN_RPATH) $(LIBS)
|
||||
|
||||
plugins/sysinfo/sysinfo.so: plugins/sysinfo/sysinfo.c $(LIB)
|
||||
$(CC) $(CFLAGS) -shared -o $@ plugins/sysinfo/sysinfo.c -L. -lsplinter \
|
||||
$(PLUGIN_RPATH) $(LIBS)
|
||||
@@ -384,9 +384,10 @@ comes from the parser (`sp_sse_kind`).
|
||||
`focus` keeps a short recap of the session's goal in front of the model every
|
||||
seven turns — one inserted system message, never twice in a turn, nothing until
|
||||
a goal is set. `/goal <text>` sets the goal and starts that recap turn; the
|
||||
model's answer is remembered and injected later. `/goal` alone shows it. There
|
||||
is no separate `/recap`: recapping is what a goal does. Both work in the TUI and
|
||||
with `-p`.
|
||||
model's answer is remembered and injected later. The goal is stored in the
|
||||
session's `.meta`, so a resumed session finds it; `/continue` starts the next
|
||||
turn from it. `/goal` alone shows it. There is no separate `/recap`: recapping
|
||||
is what a goal does. Both work in the TUI and with `-p`.
|
||||
|
||||
## Languages
|
||||
|
||||
|
||||
+2
-2
@@ -218,8 +218,8 @@ repeats the request: `on_limit = wait`, the default. `max_wait` bounds it
|
||||
The session goal is set at runtime with `/goal <text>` — in the TUI, or in a
|
||||
one-shot run (`splinter -p "/goal ship the config"`). It sets the goal and
|
||||
starts a turn that writes a short recap; the recap is injected every seventh
|
||||
turn. It belongs to the conversation in front of you, not to a file that
|
||||
outlives it.
|
||||
turn. The goal itself is stored in the session's `.meta`, so `/continue` and a
|
||||
resumed session find it. It belongs to the conversation in front of you.
|
||||
|
||||
## Precedence
|
||||
|
||||
|
||||
+21
-4
@@ -219,10 +219,12 @@ the table.
|
||||
recap (3-5 bullets, what must be true at the end, the first steps, open
|
||||
questions). The plugin remembers that answer and injects it every seventh turn
|
||||
— never twice in one turn, nothing at all when no goal is set. `/goal` alone
|
||||
shows the goal. There is no `/recap`: recapping is what a goal does. That works
|
||||
in the TUI and in a one-shot run (`splinter -p "/goal ..."`); it is deliberately
|
||||
not a config key, because a goal belongs to the conversation in front of you and
|
||||
not to a file that outlives it. `SPLINTER_FOCUS_EVERY` sets the interval
|
||||
shows the goal. There is no `/recap`: recapping is what a goal does. The goal is
|
||||
stored in the session's `.meta`, so a resume, `/open` or `/continue` finds it
|
||||
again. `/continue` starts a turn that picks the goal up where the session
|
||||
stopped. That works in the TUI and in a one-shot run
|
||||
(`splinter -p "/goal ..."`); it is not a config key, because a goal belongs to
|
||||
the conversation in front of you. `SPLINTER_FOCUS_EVERY` sets the interval
|
||||
(default 7 turns).
|
||||
|
||||
It registers as a compactor and inserts one system message — *before* the newest
|
||||
@@ -233,6 +235,21 @@ widget line shows the goal and how many recaps went out.
|
||||
It is a reminder, not an instruction: the user can change direction at any
|
||||
time, and the message says so on its face.
|
||||
|
||||
## sysinfo
|
||||
|
||||
RAM, CPU, swap and disk in one sidebar line:
|
||||
|
||||
```
|
||||
RAM 46% [|| ] CPU 13% [| ] SWAP 12% [ ] DISK 71% [|||| ]
|
||||
```
|
||||
|
||||
A widget thread samples `/proc/meminfo`, `/proc/stat` and `statvfs("/")` every
|
||||
two seconds. CPU is the busy share between two samples; RAM is
|
||||
`MemTotal - MemAvailable` (with Free+Buffers+Cached as the fallback); swap is
|
||||
`SwapTotal - SwapFree`; disk is `f_blocks - f_bfree` on `/`. Everything is a
|
||||
percentage with a five-cell `[|||| ]` gauge. A missing `/proc` entry leaves the
|
||||
number at 0 and the plugin still loads. It has no commands and no config.
|
||||
|
||||
## Zustimmung (ack)
|
||||
|
||||
Ein Werkzeug, das etwas aendert, braucht ein Ja von einem Menschen. Der Mensch
|
||||
|
||||
@@ -250,6 +250,11 @@ int sp_session_list(const char *dir, struct sp_session_brief *v,
|
||||
/* give a session a title (one line, at most 95 bytes) */
|
||||
int sp_session_set_title(const char *dir, const char *id,
|
||||
const char *title, struct sp_buf *err);
|
||||
/* the session's /goal, stored in its meta sidecar so a resume finds it */
|
||||
int sp_session_set_goal(const char *dir, const char *id,
|
||||
const char *goal, struct sp_buf *err);
|
||||
int sp_session_get_goal(const char *dir, const char *id,
|
||||
char *buf, size_t cap);
|
||||
/*
|
||||
* Remove a session: its log, meta, saved profile and the logs/<id> directory.
|
||||
* The caller must not delete the session its engine has open.
|
||||
|
||||
@@ -252,6 +252,7 @@ struct sp_host *sp_host_new(struct sp_registry *, struct sp_agent *,
|
||||
struct sp_session_info *);
|
||||
void sp_host_free(struct sp_host *);
|
||||
const char *sp_host_session_dir(struct sp_host *);
|
||||
const char *sp_host_session_id(struct sp_host *);
|
||||
/* Retry a durable delegation job (scheduler/worker). 0 on handled (see out). */
|
||||
int sp_delegate_retry_job(const char *id, int force, struct sp_buf *out);
|
||||
/* Scheduler tick: retry one due waiting_quota/waiting_poll job if any. */
|
||||
|
||||
+60
-4
@@ -50,6 +50,8 @@ static unsigned every = 7;
|
||||
static unsigned last_reminder;
|
||||
static unsigned reminders;
|
||||
static char widget_text[128];
|
||||
static char session_id[64]; /* whose goal the statics belong to */
|
||||
static char env_goal[GOAL_MAX + 1]; /* SPLINTER_FOCUS_GOAL fallback */
|
||||
|
||||
/* One line, bounded: the recap travels in a system message, not a transcript. */
|
||||
static void
|
||||
@@ -101,6 +103,34 @@ recap_capture(struct sp_conv *conv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A plugin is not unloaded between sessions: the same focus statics serve the
|
||||
* next /open. Read the goal from the session meta whenever the session id
|
||||
* changes, so a resumed session and a switched session see their own goal.
|
||||
* The caller holds focus_lock.
|
||||
*/
|
||||
static void
|
||||
focus_session_sync(struct sp_host *h)
|
||||
{
|
||||
const char *dir = sp_host_session_dir(h);
|
||||
const char *id = sp_host_session_id(h);
|
||||
char g[GOAL_MAX + 1];
|
||||
|
||||
if (id == NULL || *id == '\0' || strcmp(session_id, id) == 0)
|
||||
return;
|
||||
snprintf(session_id, sizeof(session_id), "%s", id);
|
||||
goal[0] = '\0';
|
||||
recap[0] = '\0';
|
||||
recap_pending = 0;
|
||||
reminders = 0;
|
||||
last_reminder = 0;
|
||||
if (dir != NULL && *dir != '\0' &&
|
||||
sp_session_get_goal(dir, id, g, sizeof(g)) == 0)
|
||||
snprintf(goal, sizeof(goal), "%s", g);
|
||||
else if (env_goal[0] != '\0')
|
||||
snprintf(goal, sizeof(goal), "%s", env_goal);
|
||||
}
|
||||
|
||||
static int
|
||||
focus_compact(struct sp_host *h, struct sp_conv *conv, size_t budget,
|
||||
unsigned turn)
|
||||
@@ -116,6 +146,7 @@ focus_compact(struct sp_host *h, struct sp_conv *conv, size_t budget,
|
||||
if (conv == NULL || conv->n == 0)
|
||||
return 0;
|
||||
pthread_mutex_lock(&focus_lock);
|
||||
focus_session_sync(h);
|
||||
recap_capture(conv);
|
||||
if (goal[0] == '\0' || turn == 0 || (turn % every) != 0 ||
|
||||
turn == last_reminder) { /* one recap per turn, always */
|
||||
@@ -164,11 +195,12 @@ static int
|
||||
focus_command(struct sp_host *h, const char *args, struct sp_buf *out,
|
||||
void *ctx)
|
||||
{
|
||||
char g[GOAL_MAX + 1];
|
||||
char g[GOAL_MAX + 1], saveerr[256] = "";
|
||||
unsigned n;
|
||||
|
||||
(void)ctx;
|
||||
pthread_mutex_lock(&focus_lock);
|
||||
focus_session_sync(h);
|
||||
if (args == NULL || *args == '\0') {
|
||||
snprintf(g, sizeof(g), "%s", goal);
|
||||
n = reminders;
|
||||
@@ -186,6 +218,22 @@ focus_command(struct sp_host *h, const char *args, struct sp_buf *out,
|
||||
reminders = 0;
|
||||
last_reminder = 0;
|
||||
snprintf(g, sizeof(g), "%s", goal);
|
||||
{
|
||||
const char *dir = sp_host_session_dir(h);
|
||||
const char *id = sp_host_session_id(h);
|
||||
|
||||
if (dir != NULL && *dir != '\0' && id != NULL && *id != '\0') {
|
||||
struct sp_buf serr;
|
||||
|
||||
if (sp_buf_init(&serr) == 0) {
|
||||
if (sp_session_set_goal(dir, id, goal, &serr) != 0)
|
||||
snprintf(saveerr, sizeof(saveerr), "%s",
|
||||
serr.p != NULL ? serr.p :
|
||||
"not saved");
|
||||
sp_buf_free(&serr);
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&focus_lock);
|
||||
/* publish now, so the sidebar does not wait for the next tick */
|
||||
{
|
||||
@@ -195,7 +243,10 @@ focus_command(struct sp_host *h, const char *args, struct sp_buf *out,
|
||||
strlen(g) > 160 ? "..." : "");
|
||||
(void)sp_host_widget_text(h, "focus", line);
|
||||
}
|
||||
return sp_buf_printf(out, sp_td("focus.set", "goal set: %s"), g);
|
||||
(void)sp_buf_printf(out, sp_td("focus.set", "goal set: %s"), g);
|
||||
if (saveerr[0] != '\0')
|
||||
sp_buf_printf(out, " (%s)", saveerr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -205,6 +256,7 @@ focus_tick(struct sp_host *h, const char *name, void *ctx)
|
||||
|
||||
(void)ctx;
|
||||
pthread_mutex_lock(&focus_lock);
|
||||
focus_session_sync(h);
|
||||
if (goal[0] == '\0')
|
||||
line[0] = '\0'; /* no goal: the sidebar says nothing */
|
||||
else
|
||||
@@ -225,11 +277,15 @@ focus_init(struct sp_host *h)
|
||||
|
||||
memset(goal, 0, sizeof(goal));
|
||||
memset(recap, 0, sizeof(recap));
|
||||
memset(env_goal, 0, sizeof(env_goal));
|
||||
session_id[0] = '\0';
|
||||
recap_pending = 0;
|
||||
if (g != NULL) {
|
||||
snprintf(goal, sizeof(goal), "%.*s", GOAL_MAX, g);
|
||||
snprintf(env_goal, sizeof(env_goal), "%.*s", GOAL_MAX, g);
|
||||
if (strlen(g) > GOAL_MAX)
|
||||
snprintf(goal + GOAL_MAX - 24, 25, "...[gekuerzt]");
|
||||
snprintf(env_goal + GOAL_MAX - 24, 25,
|
||||
"...[gekuerzt]");
|
||||
snprintf(goal, sizeof(goal), "%s", env_goal);
|
||||
}
|
||||
if (e != NULL && atoi(e) > 0 && atoi(e) < 1000)
|
||||
every = (unsigned)atoi(e);
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* splinter -- sysinfo: RAM, CPU, swap and disk in the sidebar.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Four numbers the operator checks before starting a long turn: is the box
|
||||
* swapping, is the CPU already busy, is the disk full. Linux exposes all of
|
||||
* them in /proc and statvfs(2); the widget thread samples them every two
|
||||
* seconds and publishes one compact line:
|
||||
*
|
||||
* RAM 62% [||| ] CPU 13% [| ] SWAP 0% [ ] DISK 71% [|||| ]
|
||||
*
|
||||
* The sidebar wraps it at spaces. A missing /proc entry is not an error:
|
||||
* the plugin still loads and says n/a for what it cannot read.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "splinter.h"
|
||||
#include "splinter_plugin.h"
|
||||
|
||||
#define BAR_WIDTH 5
|
||||
|
||||
static int have_cpu;
|
||||
static unsigned long long prev_total, prev_idle;
|
||||
|
||||
/* one [||| ] gauge, width 5 */
|
||||
static void
|
||||
gauge(char *b, size_t cap, double pct)
|
||||
{
|
||||
int i, filled;
|
||||
|
||||
if (cap < BAR_WIDTH + 3)
|
||||
return;
|
||||
if (pct < 0)
|
||||
pct = 0;
|
||||
if (pct > 100)
|
||||
pct = 100;
|
||||
filled = (int)((pct * BAR_WIDTH + 50) / 100);
|
||||
b[0] = '[';
|
||||
for (i = 0; i < BAR_WIDTH; i++)
|
||||
b[i + 1] = i < filled ? '|' : ' ';
|
||||
b[BAR_WIDTH + 1] = ']';
|
||||
b[BAR_WIDTH + 2] = '\0';
|
||||
}
|
||||
|
||||
/* /proc/stat's first line: total and idle ticks */
|
||||
static int
|
||||
cpu_read(unsigned long long *total, unsigned long long *idle)
|
||||
{
|
||||
FILE *f = fopen("/proc/stat", "r");
|
||||
char line[512];
|
||||
unsigned long long v[10];
|
||||
int n;
|
||||
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
if (fgets(line, sizeof(line), f) == NULL) {
|
||||
fclose(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
memset(v, 0, sizeof(v));
|
||||
n = sscanf(line, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu",
|
||||
&v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8]);
|
||||
if (n < 4)
|
||||
return -1;
|
||||
*total = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6] + v[7] +
|
||||
v[8];
|
||||
*idle = v[3] + v[4]; /* idle + iowait */
|
||||
return *total > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
/* /proc/meminfo: MemTotal, MemAvailable or Free+Buffers+Cached, Swap */
|
||||
static int
|
||||
mem_read(unsigned long long *mt, unsigned long long *ma,
|
||||
unsigned long long *st, unsigned long long *sf)
|
||||
{
|
||||
FILE *f = fopen("/proc/meminfo", "r");
|
||||
char line[256];
|
||||
unsigned long long v;
|
||||
unsigned long long free_kb = 0, buffers = 0, cached = 0;
|
||||
|
||||
*mt = *ma = *st = *sf = 0;
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
while (fgets(line, sizeof(line), f) != NULL) {
|
||||
if (sscanf(line, "MemTotal: %llu", &v) == 1)
|
||||
*mt = v;
|
||||
else if (sscanf(line, "MemAvailable: %llu", &v) == 1)
|
||||
*ma = v;
|
||||
else if (sscanf(line, "MemFree: %llu", &v) == 1)
|
||||
free_kb = v;
|
||||
else if (sscanf(line, "Buffers: %llu", &v) == 1)
|
||||
buffers = v;
|
||||
else if (sscanf(line, "Cached: %llu", &v) == 1)
|
||||
cached = v;
|
||||
else if (sscanf(line, "SwapTotal: %llu", &v) == 1)
|
||||
*st = v;
|
||||
else if (sscanf(line, "SwapFree: %llu", &v) == 1)
|
||||
*sf = v;
|
||||
}
|
||||
fclose(f);
|
||||
if (*ma == 0)
|
||||
*ma = free_kb + buffers + cached;
|
||||
return *mt > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
static double
|
||||
pct(unsigned long long used, unsigned long long total)
|
||||
{
|
||||
if (total == 0)
|
||||
return 0;
|
||||
if (used > total)
|
||||
used = total;
|
||||
return (double)used * 100.0 / (double)total;
|
||||
}
|
||||
|
||||
static int
|
||||
tick(struct sp_host *h, const char *name, void *ctx)
|
||||
{
|
||||
unsigned long long mt, ma, st, sf, total, idle;
|
||||
double ram = 0, swap = 0, disk = 0, cpu = 0;
|
||||
char rb[16], cb[16], sb[16], db[16], line[512];
|
||||
|
||||
(void)ctx;
|
||||
if (mem_read(&mt, &ma, &st, &sf) == 0) {
|
||||
ram = pct(mt - ma, mt);
|
||||
if (st > 0)
|
||||
swap = pct(st - sf, st);
|
||||
}
|
||||
if (cpu_read(&total, &idle) == 0) {
|
||||
if (have_cpu && total > prev_total &&
|
||||
idle >= prev_idle && total - prev_total > 0) {
|
||||
unsigned long long dt = total - prev_total;
|
||||
unsigned long long di = idle - prev_idle;
|
||||
|
||||
cpu = pct(dt > di ? dt - di : 0, dt);
|
||||
}
|
||||
prev_total = total;
|
||||
prev_idle = idle;
|
||||
have_cpu = 1;
|
||||
}
|
||||
{
|
||||
struct statvfs vfs;
|
||||
|
||||
if (statvfs("/", &vfs) == 0 && vfs.f_blocks > 0) {
|
||||
unsigned long long used = (unsigned long long)
|
||||
(vfs.f_blocks - vfs.f_bfree);
|
||||
|
||||
disk = pct(used, (unsigned long long)vfs.f_blocks);
|
||||
}
|
||||
}
|
||||
gauge(rb, sizeof(rb), ram);
|
||||
gauge(cb, sizeof(cb), cpu);
|
||||
gauge(sb, sizeof(sb), swap);
|
||||
gauge(db, sizeof(db), disk);
|
||||
snprintf(line, sizeof(line),
|
||||
"RAM %.0f%% %s CPU %.0f%% %s SWAP %.0f%% %s DISK %.0f%% %s",
|
||||
ram, rb, cpu, cb, swap, sb, disk, db);
|
||||
return sp_host_widget_text(h, name, line);
|
||||
}
|
||||
|
||||
static int
|
||||
init(struct sp_host *h)
|
||||
{
|
||||
static const struct sp_widget w = { "sysinfo", tick, NULL, NULL, 2000 };
|
||||
unsigned long long total, idle;
|
||||
|
||||
(void)cpu_read(&total, &idle);
|
||||
if (total > 0) {
|
||||
prev_total = total;
|
||||
prev_idle = idle;
|
||||
have_cpu = 1;
|
||||
}
|
||||
return sp_host_add_widget(h, &w);
|
||||
}
|
||||
|
||||
static const struct sp_plugin plugin = {
|
||||
SP_PLUGIN_ABI, "sysinfo", "0.1.0", init, NULL, NULL
|
||||
};
|
||||
|
||||
const struct sp_plugin *
|
||||
sp_plugin_describe(void)
|
||||
{
|
||||
return &plugin;
|
||||
}
|
||||
@@ -44,6 +44,7 @@ err.thread = Turn-Thread laesst sich nicht starten
|
||||
err.turn_failed = Turn fehlgeschlagen
|
||||
focus.reminder = Recap zum Merken: %s. Pruefe vor der Antwort, ob der letzte Schritt naeher am Ziel war; wenn nicht, sage das und nenne den naechsten Schritt.
|
||||
focus.recap_prompt = Ziel: %s. Schreibe einen kurzen Recap zum Merken: 3-5 Punkte, was am Ende stimmen muss, die ersten konkreten Schritte und offene Fragen.
|
||||
focus.continue_prompt = Arbeite an diesem Ziel weiter: %s. Mach dort weiter, wo die Sitzung aufgehoert hat: pruefe den Stand, tue den naechsten konkreten Schritt und berichte, was sich geaendert hat.
|
||||
focus.set = Ziel gesetzt: %s
|
||||
focus.none = kein Ziel gesetzt (/goal <text>)
|
||||
focus.status = Ziel: %s (%u Recaps, alle %u Turns)
|
||||
@@ -196,6 +197,7 @@ sidebar.usage = Kontingent
|
||||
sidebar.turn_line = %.1f s, %zu Schritte, %zu Tools
|
||||
widget.focus = Ziel
|
||||
widget.plan = Plan
|
||||
widget.sysinfo = System
|
||||
widget.tasks = Aufgaben
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = Nutzungslimit: weiter um %s (Strg-C stoppt, /resume macht weiter)
|
||||
|
||||
@@ -43,6 +43,7 @@ err.thread = cannot start the turn thread
|
||||
err.turn_failed = turn failed
|
||||
focus.reminder = Recap to remember: %s. Before answering, check whether the last step moved closer to the goal; if not, say so and name the next step.
|
||||
focus.recap_prompt = Goal: %s. Write a short recap to remember: 3-5 bullets, what must be true at the end, the first concrete steps, and open questions.
|
||||
focus.continue_prompt = Continue working toward this goal: %s. Pick up where the session stopped: check the current state, do the next concrete step, and report what changed.
|
||||
focus.set = goal set: %s
|
||||
focus.none = no goal set (/goal <text>)
|
||||
focus.status = goal: %s (%u recaps, every %u turns)
|
||||
@@ -195,6 +196,7 @@ sidebar.usage = usage
|
||||
sidebar.turn_line = %.1f s, %zu steps, %zu tools
|
||||
widget.focus = goal
|
||||
widget.plan = plan
|
||||
widget.sysinfo = system
|
||||
widget.tasks = tasks
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = usage limit: continuing at %s (Ctrl-C stops, /resume goes on)
|
||||
|
||||
@@ -58,6 +58,7 @@ auth.destructive = destrutivo
|
||||
|
||||
focus.reminder = Recap para lembrar: %s. Antes de responder, verifique se o ultimo passo aproximou do objetivo; se nao, diga isso e proponha o proximo passo.
|
||||
focus.recap_prompt = Objetivo: %s. Escreva um recap curto para lembrar: 3-5 pontos, o que precisa estar certo no final, os primeiros passos concretos e as perguntas abertas.
|
||||
focus.continue_prompt = Continue trabalhando neste objetivo: %s. Retome de onde a sessao parou: verifique o estado, faca o proximo passo concreto e relate o que mudou.
|
||||
focus.set = objetivo definido: %s
|
||||
focus.none = nenhum objetivo definido (/goal <texto>)
|
||||
focus.status = objetivo: %s (%u recaps, a cada %u turnos)
|
||||
@@ -199,6 +200,7 @@ sidebar.usage = uso
|
||||
sidebar.turn_line = %.1f s, %zu passos, %zu ferramentas
|
||||
widget.focus = meta
|
||||
widget.plan = plano
|
||||
widget.sysinfo = sistema
|
||||
widget.tasks = tarefas
|
||||
widget.tmux = tmux
|
||||
ui.limit_wait = limite de uso: continua as %s (Ctrl-C para, /resume continua)
|
||||
|
||||
+11
-4
@@ -585,10 +585,17 @@ agent_loop(struct sp_agent *a, struct sp_conv *conv, int resume, int decision,
|
||||
reply.tokens_in : 0);
|
||||
a->stats.tokens_out += (size_t)(reply.tokens_out > 0 ?
|
||||
reply.tokens_out : 0);
|
||||
a->stats.last_in = (size_t)(reply.tokens_in > 0 ?
|
||||
reply.tokens_in : 0);
|
||||
a->stats.last_cached = (size_t)(reply.tokens_cached > 0 ?
|
||||
reply.tokens_cached : 0);
|
||||
/*
|
||||
* Some providers do not report usage on a tool-call step. A zero
|
||||
* there is "unknown", not "the context became empty": keep the
|
||||
* last known prompt size, or the status bar drops to 0 after
|
||||
* every tool call.
|
||||
*/
|
||||
if (reply.tokens_in > 0) {
|
||||
a->stats.last_in = (size_t)reply.tokens_in;
|
||||
a->stats.last_cached = (size_t)(reply.tokens_cached > 0 ?
|
||||
reply.tokens_cached : 0);
|
||||
}
|
||||
sp_host_provider_account(a->host, a->tr.provider, a->tr.key_id,
|
||||
reply.status,
|
||||
(size_t)(reply.tokens_in > 0 ? reply.tokens_in : 0),
|
||||
|
||||
+17
-3
@@ -1461,9 +1461,9 @@ int
|
||||
sp_engine_command_names(struct sp_engine *e, char (*names)[64], int max)
|
||||
{
|
||||
static const char *builtin[] = {
|
||||
"agent", "agents", "connect", "exit", "model", "new", "q",
|
||||
"quit", "rename", "reset", "resume", "rm", "status", "swarm",
|
||||
"usage", "widgets"
|
||||
"agent", "agents", "connect", "continue", "exit", "model",
|
||||
"new", "q", "quit", "rename", "reset", "resume", "rm", "status",
|
||||
"swarm", "usage", "widgets"
|
||||
};
|
||||
struct sp_buf b;
|
||||
char cdir[700], *p, *tok, *save;
|
||||
@@ -1992,6 +1992,20 @@ sp_engine_input(struct sp_engine *e, const char *line, struct sp_buf *out)
|
||||
cmd_rm(e, args, out);
|
||||
return SP_INPUT_HANDLED;
|
||||
}
|
||||
if (strcmp(name, "continue") == 0) {
|
||||
char goal[1001];
|
||||
|
||||
if (sp_session_get_goal(e->sess.dir, e->sess.id, goal,
|
||||
sizeof(goal)) != 0) {
|
||||
sp_buf_puts(out, sp_t("focus.none"));
|
||||
return SP_INPUT_HANDLED;
|
||||
}
|
||||
sp_buf_printf(out, sp_td("focus.continue_prompt",
|
||||
"Continue working toward this goal: %s. Pick up where the "
|
||||
"session stopped: check the current state, do the next "
|
||||
"concrete step, and report what changed."), goal);
|
||||
return SP_INPUT_PROMPT;
|
||||
}
|
||||
if (strcmp(name, "connect") == 0) {
|
||||
if (sp_config_loaded_path() == NULL) {
|
||||
sp_buf_puts(out, sp_t("connect.nodir"));
|
||||
|
||||
@@ -787,6 +787,12 @@ sp_host_session_dir(struct sp_host *h)
|
||||
return (h != NULL) ? h->session_dir : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_host_session_id(struct sp_host *h)
|
||||
{
|
||||
return (h != NULL && h->sess != NULL) ? h->sess->id : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
sp_host_set_provider(struct sp_host *h, const struct sp_provider_ops *ops)
|
||||
{
|
||||
|
||||
+56
-1
@@ -55,6 +55,7 @@ struct session_meta {
|
||||
long created;
|
||||
long opened;
|
||||
char title[96];
|
||||
char goal[1001]; /* the session's /goal, one line */
|
||||
};
|
||||
|
||||
/* a title is one line, no control bytes, at most 95 bytes of UTF-8 */
|
||||
@@ -115,7 +116,7 @@ title_from_text(const char *text, char *out, size_t cap)
|
||||
static int
|
||||
meta_read(const char *dir, const char *id, struct session_meta *m)
|
||||
{
|
||||
char path[700], line[700];
|
||||
char path[700], line[1600];
|
||||
FILE *f;
|
||||
|
||||
memset(m, 0, sizeof(*m));
|
||||
@@ -138,6 +139,8 @@ meta_read(const char *dir, const char *id, struct session_meta *m)
|
||||
m->opened = strtol(v, NULL, 10);
|
||||
else if (strcmp(line, "title") == 0)
|
||||
snprintf(m->title, sizeof(m->title), "%s", v);
|
||||
else if (strcmp(line, "goal") == 0)
|
||||
snprintf(m->goal, sizeof(m->goal), "%s", v);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
@@ -158,6 +161,8 @@ meta_write(const char *dir, const char *id, const struct session_meta *m)
|
||||
m->opened);
|
||||
if (m->title[0] != '\0')
|
||||
fprintf(f, "title=%s\n", m->title);
|
||||
if (m->goal[0] != '\0')
|
||||
fprintf(f, "goal=%s\n", m->goal);
|
||||
if (fclose(f) != 0) {
|
||||
(void)unlink(tmp);
|
||||
return -1;
|
||||
@@ -786,6 +791,56 @@ sp_session_set_title(const char *dir, const char *id, const char *title,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The goal belongs to the session, not to the process: a resume must find it
|
||||
* again, and /continue must not depend on a plugin that may have restarted.
|
||||
*/
|
||||
int
|
||||
sp_session_set_goal(const char *dir, const char *id, const char *goal,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
struct session_meta m;
|
||||
char path[700], clean[1001];
|
||||
|
||||
if (dir == NULL || id == NULL || goal == NULL || !valid_id(id)) {
|
||||
sp_buf_puts(err, "session: invalid id");
|
||||
return -1;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%s/%s.jsonl", dir, id);
|
||||
if (access(path, F_OK) != 0) {
|
||||
sp_buf_puts(err, "session: no such session");
|
||||
return -1;
|
||||
}
|
||||
title_from_text(goal, clean, sizeof(clean));
|
||||
if (clean[0] == '\0') {
|
||||
sp_buf_puts(err, "session: empty goal");
|
||||
return -1;
|
||||
}
|
||||
if (meta_read(dir, id, &m) != 0)
|
||||
memset(&m, 0, sizeof(m));
|
||||
snprintf(m.goal, sizeof(m.goal), "%s", clean);
|
||||
if (meta_write(dir, id, &m) != 0) {
|
||||
sp_buf_printf(err, "session: cannot write the meta file: %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sp_session_get_goal(const char *dir, const char *id, char *buf, size_t cap)
|
||||
{
|
||||
struct session_meta m;
|
||||
|
||||
if (dir == NULL || id == NULL || buf == NULL || cap == 0 ||
|
||||
!valid_id(id))
|
||||
return -1;
|
||||
if (meta_read(dir, id, &m) != 0 || m.goal[0] == '\0')
|
||||
return -1;
|
||||
snprintf(buf, cap, "%s", m.goal);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
sp_session_delete(const char *dir, const char *id, struct sp_buf *err)
|
||||
{
|
||||
|
||||
+26
-7
@@ -148,7 +148,8 @@ enum {
|
||||
PAIR_AGENT, /* the model's answer */
|
||||
PAIR_THINK, /* the model's reasoning */
|
||||
PAIR_TOOL, /* a tool call */
|
||||
PAIR_NOTICE /* status and session notes */
|
||||
PAIR_NOTICE, /* status and session notes */
|
||||
PAIR_SIDE /* sidebar: white on one dark surface */
|
||||
};
|
||||
|
||||
/* the session id and directory the sidebar shows */
|
||||
@@ -267,6 +268,7 @@ init_colors(const struct sp_theme *t)
|
||||
init_pair(PAIR_THINK, think, t->idx_bg);
|
||||
init_pair(PAIR_TOOL, tool, t->idx_bg);
|
||||
init_pair(PAIR_NOTICE, notice, t->idx_bg);
|
||||
init_pair(PAIR_SIDE, COLOR_WHITE, t->idx_bg);
|
||||
return;
|
||||
}
|
||||
init_pair(PAIR_MAIN, rgb(t->fg, n), rgb(t->bg, n));
|
||||
@@ -279,6 +281,20 @@ init_colors(const struct sp_theme *t)
|
||||
init_pair(PAIR_THINK, rgb(t->think, n), rgb(t->bg, n));
|
||||
init_pair(PAIR_TOOL, rgb(t->tool, n), rgb(t->bg, n));
|
||||
init_pair(PAIR_NOTICE, rgb(t->notice, n), rgb(t->bg, n));
|
||||
{
|
||||
/*
|
||||
* The sidebar is one surface, not a patchwork: a darkened theme
|
||||
* background with white text, so every heading, label and widget
|
||||
* sits on the same colour. On a dark theme it is simply the
|
||||
* background.
|
||||
*/
|
||||
unsigned char side_bg[3];
|
||||
|
||||
memcpy(side_bg, t->bg, 3);
|
||||
sp_color_darken(side_bg, 45000);
|
||||
init_pair(PAIR_SIDE, rgb((const unsigned char[]){255, 255, 255}, n),
|
||||
rgb(side_bg, n));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1021,11 +1037,11 @@ draw_history(struct ui_state *s)
|
||||
static void
|
||||
sidebar_heading(int *y, int cols, const char *text)
|
||||
{
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM) | A_BOLD);
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_SIDE) | A_BOLD);
|
||||
mvwaddnstr(ui_side, *y, 0, text, cols - 1);
|
||||
wattroff(ui_side, A_BOLD);
|
||||
(*y)++;
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
}
|
||||
|
||||
/* wrap 'text' into the sidebar from row *y, at most 'maxrows' rows */
|
||||
@@ -1099,6 +1115,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
(void)dir;
|
||||
cols = getmaxx(ui_side);
|
||||
werase(ui_side);
|
||||
wattrset(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
|
||||
/* who is answering: the profile, the provider, the model */
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.model"));
|
||||
@@ -1155,10 +1172,10 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
sp_usage_brief(&u, brief, sizeof(brief));
|
||||
snprintf(line, sizeof(line), "%-9.9s %s", pid, brief);
|
||||
if (u.frac >= 0.9 || u.benched_until > 0)
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_ACCENT) | A_BOLD);
|
||||
wattron(ui_side, A_BOLD);
|
||||
if (y < getmaxy(ui_side))
|
||||
mvwaddnstr(ui_side, y++, 0, line, cols - 1);
|
||||
wattrset(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
wattrset(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
}
|
||||
if (printed)
|
||||
y++;
|
||||
@@ -1218,7 +1235,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
|
||||
if (id != NULL && y < getmaxy(ui_side) - 2) {
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.session"));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
side_text(&y, cols, id, 1);
|
||||
}
|
||||
/*
|
||||
@@ -1238,7 +1255,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir,
|
||||
else
|
||||
snprintf(shown, sizeof(shown), "%s", cwd);
|
||||
sidebar_heading(&y, cols, sp_t("sidebar.cwd"));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
side_path(&y, cols, shown, 4);
|
||||
}
|
||||
}
|
||||
@@ -1530,6 +1547,8 @@ layout(void)
|
||||
newwin(rows - 2, side_w, 0, chat_w + 1) : NULL;
|
||||
}
|
||||
wbkgd(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
if (ui_side != NULL)
|
||||
wbkgd(ui_side, COLOR_PAIR(PAIR_SIDE));
|
||||
/* the meter line sits above the input, like a status bar */
|
||||
ui_status = newwin(1, cols, rows - 2, 0);
|
||||
wbkgd(ui_status, COLOR_PAIR(PAIR_STATUS));
|
||||
|
||||
@@ -141,6 +141,7 @@ coder 7 task mentions 'code'</pre>
|
||||
<div class="cols"><ul>
|
||||
<li><b>lcm</b>, <b>cps</b>: compact the conversation</li>
|
||||
<li><b>focus</b>: keeps a <code>/goal</code> recap in front every 7 turns</li>
|
||||
<li><b>sysinfo</b>: RAM, CPU, swap and disk gauges in the sidebar</li>
|
||||
<li><b>reminder</b>: puts the ground rules back every 10 turns</li>
|
||||
<li><b>ring</b>: next exit on 429 or limit</li>
|
||||
<li><b>mcp</b>, <b>a2a</b>, <b>cli</b>: reach other tools and agents</li>
|
||||
|
||||
@@ -141,6 +141,7 @@ coder 7 task mentions 'code'</pre>
|
||||
<div class="cols"><ul>
|
||||
<li><b>lcm</b>, <b>cps</b>: Konversation komprimieren</li>
|
||||
<li><b>focus</b>: legt <code>/goal</code> als Recap alle 7 Turns vor</li>
|
||||
<li><b>sysinfo</b>: RAM, CPU, Swap und Disk als Balken in der Sidebar</li>
|
||||
<li><b>reminder</b>: legt alle 10 Turns die Grundregeln zurück</li>
|
||||
<li><b>ring</b>: nächster Ausgang bei 429 oder Limit</li>
|
||||
<li><b>mcp</b>, <b>a2a</b>, <b>cli</b>: andere Werkzeuge und Agenten erreichen</li>
|
||||
|
||||
@@ -141,6 +141,7 @@ coder 7 task mentions 'code'</pre>
|
||||
<div class="cols"><ul>
|
||||
<li><b>lcm</b>, <b>cps</b>: comprimem a conversa</li>
|
||||
<li><b>focus</b>: mantem o recap do <code>/goal</code> a cada 7 turnos</li>
|
||||
<li><b>sysinfo</b>: RAM, CPU, swap e disco como barras na sidebar</li>
|
||||
<li><b>reminder</b>: repõe as regras básicas a cada 10 turnos</li>
|
||||
<li><b>ring</b>: próxima saída em 429 ou limite</li>
|
||||
<li><b>mcp</b>, <b>a2a</b>, <b>cli</b>: alcançam outras ferramentas e agentes</li>
|
||||
|
||||
@@ -177,6 +177,14 @@ main(void)
|
||||
CHECK(contains(out.p, "/no-such-command"));
|
||||
sp_buf_clear(&out);
|
||||
|
||||
/* the goal is in the session sidecar; /continue turns it into a prompt */
|
||||
CHECK(sp_session_set_goal(path, "sess-engine",
|
||||
"Ship the config file", &err) == 0);
|
||||
kind = sp_engine_input(eng, "/continue", &out);
|
||||
CHECK(kind == SP_INPUT_PROMPT);
|
||||
CHECK(contains(out.p, "Ship the config file"));
|
||||
sp_buf_clear(&out);
|
||||
|
||||
/*
|
||||
* /new drops the conversation, not the way of working: the active
|
||||
* profile's prompt goes back on top, and the new session gets an id of
|
||||
|
||||
@@ -99,6 +99,17 @@ main(void)
|
||||
/* 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];
|
||||
|
||||
|
||||
Reference in new issue
Block a user