- plugins/self: what the session costs the machine - RSS, CPU, threads, fds and io of the process itself from /proc/self/*, and the same (count, RSS, CPU) for every process whose parent chain reaches it: run calls, MCP children, delegates. Widget, /self and the session_usage tool; interval in the plugin block (default 2 s). - MCP server: the session tools. splinter_sessions, splinter_state, splinter_models, splinter_agents, splinter_history, splinter_say, splinter_open, splinter_model, splinter_agent, splinter_steer, splinter_cancel, splinter_approve. Say starts a real turn and returns the answer; a turn parked on an approval returns the question instead of failing. Mutating tools obey --autonomous. `--daemon --mcp-server-listen` runs the MCP server on a thread beside the Telegram daemon. - the MCP server asks the engine for its registry on every call (a session switch replaces it) and copies the tool name out of the parsed JSON before freeing it (the first version compared a dangling pointer and answered every session call with empty text). - junction: "serving <endpoint>" - streaming answers carry no X-Junction-Endpoint, so the plugin compares the route targets' ok counters from /status between samples and names the one that grew, with its last_ms. The header is still used when present (non-streaming). The X-Junction-Endpoint of the plugin's own /v1/models probe remains a probe fact in /junction only. - transport: X-Junction-Endpoint is parsed from the response headers in both the streaming and the non-streaming path and published through sp_host_served_by(); sp_reply carries served_by. - the curl rate guard (--speed-limit/--speed-time) is gone: it cut slow router streams with "Less than 1 bytes/sec" even while keepalives arrived. The overall -m timeout stays. - focus: the sidebar shows "recap N, every M turns", and an applied recap writes "recap applied (turn N, every M turns)" into the transcript (host status messages are now drained during a turn; protocol clients get them as entry events too). The initial goal announcement says so as well. - tests: test_self, test_mcpsession.sh (real socket), test_focus status messages, test_junction serving placeholder. make check: all tests passed.
78 lines
1.9 KiB
C
78 lines
1.9 KiB
C
/*
|
|
* splinter -- the self plugin: the session's own resource use.
|
|
*
|
|
* The numbers come from /proc, so the test proves the shape and that both the
|
|
* widget and /self answer; the exact values belong to the machine.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_plugin.h"
|
|
|
|
static int failures;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static void
|
|
nap_ms(long ms)
|
|
{
|
|
struct timespec ts;
|
|
|
|
ts.tv_sec = ms / 1000;
|
|
ts.tv_nsec = (ms % 1000) * 1000000L;
|
|
nanosleep(&ts, NULL);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
struct sp_registry reg;
|
|
struct sp_agent ag;
|
|
struct sp_host *host;
|
|
struct sp_buf err, out;
|
|
char snap[2048];
|
|
|
|
memset(®, 0, sizeof(reg));
|
|
memset(&ag, 0, sizeof(ag));
|
|
if (sp_buf_init(&err) != 0 || sp_buf_init(&out) != 0)
|
|
return 1;
|
|
host = sp_host_new(®, &ag, NULL);
|
|
CHECK(host != NULL);
|
|
CHECK(sp_plugin_load(host, "plugins/self/self.so", &err) == 0);
|
|
CHECK(sp_registry_find(®, "session_usage") != NULL);
|
|
|
|
/* the widget samples on its first tick and every two seconds */
|
|
nap_ms(2400);
|
|
snap[0] = '\0';
|
|
CHECK(sp_host_widget_snapshot(host, snap, sizeof(snap)) > 0);
|
|
CHECK(strstr(snap, "self: ") != NULL);
|
|
CHECK(strstr(snap, "rss") != NULL);
|
|
CHECK(strstr(snap, "thr") != NULL);
|
|
CHECK(strstr(snap, "fd") != NULL);
|
|
CHECK(strstr(snap, "kids") != NULL);
|
|
|
|
/* /self and the tool carry the same numbers, with the child count */
|
|
sp_buf_clear(&out);
|
|
CHECK(sp_host_command(host, "self", "", &out) == 0);
|
|
CHECK(strstr(out.p, "rss:") != NULL);
|
|
CHECK(strstr(out.p, "threads:") != NULL);
|
|
CHECK(strstr(out.p, "children:") != NULL);
|
|
CHECK(strstr(out.p, "cpu:") != NULL);
|
|
|
|
sp_host_free(host);
|
|
sp_buf_free(&err);
|
|
sp_buf_free(&out);
|
|
sp_registry_free(®);
|
|
|
|
if (failures == 0)
|
|
printf("test_self: ok\n");
|
|
return failures == 0 ? 0 : 1;
|
|
}
|