splinter: a status line that plugins can write
New host API for it: sp_host_add_status() takes a named renderer, and sp_host_status_text() joins the segments with ' | '. The numbers a plugin shows come from the harness through struct sp_meter - context used and window, session tokens, cache hits, tokens per second, running tasks. A plugin that counted for itself would drift from the harness within one turn. plugins/status renders clock, ctx with a 24 column bar, cache, tok/s, tokens in and out, cost and task count. Prices are configuration, not knowledge: SPLINTER_CTX_MAX=32768 SPLINTER_PRICE_IN=0.3 SPLINTER_PRICE_OUT=1.2 Without prices the cost segment says nothing instead of inventing a number. Also fixed: the status.so recipe compiled kids.c, so the plugin that loaded was the kid mode with a different name - the reason seven status registrations produced an empty line. Known open: the segments compose (probe: 'clock: 17:28:14 | ctx 0/32.8k [........................] 0% | 0 in / 0 out | $0.0000') but the bar still draws only the title - not yet isolated.
This commit is contained in:
1 parent
a8667a8ccc
commit
3f65dfdc4c
6 files changed
+320
-1
No files matched your search
@@ -85,6 +85,28 @@ struct sp_gate {
|
||||
int (*block_turn)(struct sp_host *, char *msg, size_t len);
|
||||
};
|
||||
|
||||
/*
|
||||
* What the status line is allowed to know. The harness owns the numbers - a
|
||||
* plugin must not count tokens twice or guess a price.
|
||||
*/
|
||||
struct sp_meter {
|
||||
size_t ctx_used; /* tokens the last request carried */
|
||||
size_t ctx_max; /* the window, 0 = unknown */
|
||||
size_t tok_in; /* this session */
|
||||
size_t tok_out;
|
||||
size_t cached; /* tokens the provider served from cache */
|
||||
long tps; /* output tokens per second, last turn */
|
||||
double cost; /* session cost, filled from the price config */
|
||||
unsigned tasks_running;
|
||||
unsigned tasks_max;
|
||||
};
|
||||
|
||||
/* A status segment: a name and a renderer, drawn in the order registered. */
|
||||
struct sp_status {
|
||||
const char *name;
|
||||
void (*render)(struct sp_host *, char *buf, size_t len);
|
||||
};
|
||||
|
||||
struct sp_plugin {
|
||||
uint32_t abi; /* must equal SP_PLUGIN_ABI */
|
||||
const char *name;
|
||||
@@ -108,6 +130,10 @@ int sp_host_widget_text(struct sp_host *, const char *widget,
|
||||
int sp_host_note(struct sp_host *, const char *text);
|
||||
int sp_host_add_compactor(struct sp_host *, const struct sp_compactor *);
|
||||
int sp_host_add_gate(struct sp_host *, const struct sp_gate *);
|
||||
int sp_host_add_status(struct sp_host *, const struct sp_status *);
|
||||
const struct sp_meter *sp_host_meter(struct sp_host *);
|
||||
void sp_host_set_meter(struct sp_host *, const struct sp_meter *);
|
||||
size_t sp_host_status_text(struct sp_host *, char *buf, size_t len);
|
||||
/* Ask every gate. Returns 1 allowed, 0 denied (reason filled), -1 no opinion. */
|
||||
int sp_host_gate(struct sp_host *, const char *tool, int auth,
|
||||
const char *args, char *reason, size_t reason_len);
|
||||
|
||||
Reference in new issue
Block a user