From 8aad48b9289348368b7f52b5f39b15e70f047e23 Mon Sep 17 00:00:00 2001 From: lotherk Date: Tue, 17 Nov 2026 20:00:38 +0000 Subject: [PATCH] remove the mem0 memory system The memory tools talked to a mem0 server (memory_url/memory_key_env), one bucket per unix user. It is gone: no memory_add, no memory_search, no mem0 client, no config keys, no test_memory. - delete src/backend/memory.c and memory.h; the engine no longer registers the tools; config loses memory_url/memory_key_env; SPLINTER_MEM_KEY leaves the secret list; docs/CONFIG, ROADMAP and GATEWAY stop mentioning it. - the unix identity helper stays, under its real name: sp_user_name() in src/backend/user.c (profiles, interview and the Telegram gateway used it). - tool list is now read/search/list/write/edit/run/skill_*/... plus the MCP session tools; nothing about memory remains. - test_mcpsession.sh: the client socket gets a 120 s read timeout, not the 5 s connect timeout (a turn under load answered too late and looked hung). make check: all tests passed. --- Makefile | 7 +- TODO.md | 2 +- docs/CONFIG.md | 2 - docs/GATEWAY.md | 2 +- docs/ROADMAP.md | 4 +- include/splinter.h | 2 +- src/backend/builtin.c | 2 +- src/backend/config.c | 4 - src/backend/config.h | 2 - src/backend/engine.c | 2 - src/backend/interview.c | 6 +- src/backend/memory.c | 281 --------------------------------------- src/backend/memory.h | 16 --- src/backend/telegram.c | 4 +- src/backend/user.c | 40 ++++++ src/main.c | 3 +- tests/test_mcpsession.sh | 2 + tests/test_memory.c | 111 ---------------- 18 files changed, 55 insertions(+), 437 deletions(-) delete mode 100644 src/backend/memory.c delete mode 100644 src/backend/memory.h create mode 100644 src/backend/user.c delete mode 100644 tests/test_memory.c diff --git a/Makefile b/Makefile index f80c104..3ad7d87 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ LIB = libsplinter.so LIBOBJ = src/backend/buf.o src/backend/tool.o src/backend/session.o src/backend/conv.o src/backend/transport.o \ src/backend/json.o src/backend/sse.o src/backend/openai.o src/backend/transport_openai.o \ src/backend/anthropic.o src/backend/transport_anthropic.o src/backend/builtin.o \ - src/backend/agent.o src/backend/theme.o src/backend/palettes.o src/backend/decomp.o src/backend/i18n.o src/backend/delegate.o src/backend/telegram.o src/backend/log.o src/backend/cmdscript.o src/backend/folder.o src/backend/interview.o src/backend/ack.o src/backend/mcpserver.o src/backend/mcpsession.o src/backend/skills.o src/backend/memory.o src/backend/prompt.o src/backend/config.o src/backend/plugin.o src/backend/curl.o src/backend/swarm.o src/backend/provstate.o src/backend/md.o src/backend/tgmd.o src/backend/b64.o src/backend/a2aserver.o src/backend/providers.o src/backend/usage.o src/backend/confblock.o src/backend/agents.o src/backend/engine.o src/backend/http.o src/backend/openai_server.o src/backend/catalogs.o + src/backend/agent.o src/backend/theme.o src/backend/palettes.o src/backend/decomp.o src/backend/i18n.o src/backend/delegate.o src/backend/telegram.o src/backend/log.o src/backend/cmdscript.o src/backend/folder.o src/backend/interview.o src/backend/ack.o src/backend/mcpserver.o src/backend/mcpsession.o src/backend/skills.o src/backend/user.o src/backend/prompt.o src/backend/config.o src/backend/plugin.o src/backend/curl.o src/backend/swarm.o src/backend/provstate.o src/backend/md.o src/backend/tgmd.o src/backend/b64.o src/backend/a2aserver.o src/backend/providers.o src/backend/usage.o src/backend/confblock.o src/backend/agents.o src/backend/engine.o src/backend/http.o src/backend/openai_server.o src/backend/catalogs.o # buildinfo.o is separate: buildinfo.c is generated from the objects below. LIBOBJ_ALL = $(LIBOBJ) src/backend/buildinfo.o BIN = splinter @@ -49,7 +49,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \ plugins/self/self.so TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \ tests/test_transport tests/test_agent tests/test_openai \ - tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_anthropic tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_tgmd tests/test_providers tests/test_b64 tests/test_pause tests/test_swarm tests/test_provstate tests/test_planner tests/test_tmux tests/test_usage tests/test_agents tests/test_confblock tests/test_jobs tests/test_engine tests/test_self + tests/test_theme tests/test_plugin tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_anthropic tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_tgmd tests/test_providers tests/test_b64 tests/test_pause tests/test_swarm tests/test_provstate tests/test_planner tests/test_tmux tests/test_usage tests/test_agents tests/test_confblock tests/test_jobs tests/test_engine tests/test_self RPATH = -Wl,-rpath,'$$ORIGIN' PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..' @@ -181,7 +181,6 @@ src/backend/interview.o: src/backend/interview.h include/splinter.h src/backend/mcpserver.o: src/backend/mcpserver.h include/splinter.h src/backend/skills.o: src/backend/skills.h src/backend/config.h include/splinter.h src/backend/prompt.o: src/backend/prompt.h include/splinter.h -src/backend/memory.o: src/backend/memory.h src/backend/config.h include/splinter.h src/backend/config.o: src/backend/config.h include/splinter.h src/backend/plugin.o: include/splinter.h include/splinter_plugin.h src/frontend/curses.o: src/frontend/ui.h src/frontend/ui_backend.h \ @@ -218,8 +217,6 @@ tests/test_theme: tests/test_theme.c $(LIB) $(CC) $(CFLAGS) -o $@ tests/test_theme.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_focus: tests/test_focus.c $(LIB) $(PLUGIN) $(CC) $(CFLAGS) -o $@ tests/test_focus.c -L. -lsplinter $(TEST_RPATH) $(LIBS) -tests/test_memory: tests/test_memory.c $(LIB) - $(CC) $(CFLAGS) -o $@ tests/test_memory.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_skills: tests/test_skills.c $(LIB) $(CC) $(CFLAGS) -o $@ tests/test_skills.c -L. -lsplinter $(TEST_RPATH) $(LIBS) tests/test_telegram: tests/test_telegram.c $(LIB) diff --git a/TODO.md b/TODO.md index 7491b35..d3223e8 100644 --- a/TODO.md +++ b/TODO.md @@ -88,7 +88,7 @@ beobachten). in denselben Puffer; `json_str` haengt an, also wurde aus `job-1` mit `force=1` die Id `job-11` (`src/delegate.c`, `tool_delegate_retry`). - **Skills und Memory**: `src/skills.c`, `src/memory.c`, registriert in - `src/main.c:908-909`, `test_skills` und `test_memory` laufen gruen. + `src/main.c:908-909` und `test_skills` laufen gruen. - **Kompression verdrahtet**: `ag->host` wird gesetzt (`src/main.c:635`). - **Turn-Loop-Schrittlimit**: `8` war der alte Default, kein Zaehlfehler; `75d8bee` setzt 150 (`src/main.c:873`, `src/config.c:573`). diff --git a/docs/CONFIG.md b/docs/CONFIG.md index 9d4c2e9..4b6af26 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -246,8 +246,6 @@ lies about what it does. | `session_dir` | where session logs go (default `~/.splinter`) | | `system_prompt` | sent once at the start of a conversation | | `telegram_allow` | user ids the gateway answers, comma-separated; empty means nobody | -| `memory_url` | base URL of a mem0 server (`memory_search`, `memory_add`) | -| `memory_key_env` | env var with the mem0 key, sent as `Authorization: Token ` | | `skills_dir` | a directory of skills, one line each | | `env_delegates` | `1` turns `CLAUDE_CODE_OAUTH_TOKEN(_N)` into delegates (default off) | | `on_limit` | `wait` (default) or `fail`: what a usage limit does | diff --git a/docs/GATEWAY.md b/docs/GATEWAY.md index 5d90f7a..fb80e09 100644 --- a/docs/GATEWAY.md +++ b/docs/GATEWAY.md @@ -115,6 +115,6 @@ A caller tool comes back instead: `gw_*` is the engine's registry: the builtins (`read`, `write`, `edit`, `search`, `list`, `run`, `websearch`, `webfetch`), `folder_history`, -`delegate`, and the memory/skills tools. Plugins loaded with `--plugin` add +`delegate`, and the skills tools. Plugins loaded with `--plugin` add theirs. The caller's tools are passed through to the provider untouched, except for the `gw_` reservation. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index e3c61c3..1921bf3 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -63,7 +63,7 @@ Stream. `tests/test_protocol.sh` (Socket, Freigabe, Kommandos, quit). - Werkzeuge: read, write, edit, search, list, run, websearch, webfetch, folder_history, delegate (plus parallel/list/submit/jobs/result/due/retry), - skill_search/skill_load, memory_search/memory_add, echo, clock + skill_search/skill_load, echo, clock - Freigabe im TUI (Condition Variable), Diff-Anzeige, Ctrl-C killt curl - Session-Resume, MCP-Client und -Server, Exit-Ring, Delegation mit Modellwahl - Gateway (Telegram) mit Typing-Indicator und Slash-Commands @@ -71,8 +71,6 @@ Stream. - Slash-Programme: `~/.splinter/commands/`, Ausgabe geht ans Modell - **Skills**: `~/.splinter/skills/` + `skills_dir`, `skill_search`/`skill_load`, kein Vorladen (`test_skills`) -- **Memory**: mem0-REST, `user_id` aus dem laufenden Prozess, pro User getrennt - (`test_memory`) - **Streaming im Gateway**: eigener Callback, damit auch SSE-only-Provider gehen - **Remote/Jumphost**: `host=` schickt den ganzen Aufruf über ssh; belegt in `README.md` (olivia, Provider nur über WireGuard erreichbar) diff --git a/include/splinter.h b/include/splinter.h index 3010f1e..f852f0c 100644 --- a/include/splinter.h +++ b/include/splinter.h @@ -434,7 +434,7 @@ int sp_telegram_run(struct sp_agent *, struct sp_host *host, const char *token, const char *allow, struct sp_config *conf, struct sp_buf *err); int sp_telegram_token(char *buf, size_t len, const char *path); -const char *sp_memory_user(void); +const char *sp_user_name(void); /* * Slash commands that are programs: /commands/. The program * gets the rest of the line, and its output becomes context for the model. diff --git a/src/backend/builtin.c b/src/backend/builtin.c index ac7ca11..5369738 100644 --- a/src/backend/builtin.c +++ b/src/backend/builtin.c @@ -84,7 +84,7 @@ tool_echo(const char *args, struct sp_buf *out, void *ctx) #define SECRET_MAX 32 static char secret_env[SECRET_MAX][96] = { - "SPLINTER_API_KEY", "SPLINTER_TELEGRAM_TOKEN", "SPLINTER_MEM_KEY", + "SPLINTER_API_KEY", "SPLINTER_TELEGRAM_TOKEN", "SPLINTER_DELEGATE_KEY_*", "CLAUDE_CODE_OAUTH_TOKEN", "OLLAMA_KEY", "SPLINTER_OLLAMA_KEY_*", "SPLINTER_MCP_TOKEN" }; diff --git a/src/backend/config.c b/src/backend/config.c index a1b9d71..ce149d4 100644 --- a/src/backend/config.c +++ b/src/backend/config.c @@ -672,10 +672,6 @@ load_stream(struct sp_config *c, FILE *f, const char *path, } else if (!strcmp(key, "transport")) set_str(c->transport, sizeof(c->transport), val); - else if (!strcmp(key, "memory_url")) - set_str(c->memory_url, sizeof(c->memory_url), val); - else if (!strcmp(key, "memory_key_env")) - set_str(c->memory_key_env, sizeof(c->memory_key_env), val); else if (!strcmp(key, "telegram_allow")) set_str(c->telegram_allow, sizeof(c->telegram_allow), val); else if (!strcmp(key, "locale")) diff --git a/src/backend/config.h b/src/backend/config.h index c8c2edd..b6699d1 100644 --- a/src/backend/config.h +++ b/src/backend/config.h @@ -144,8 +144,6 @@ struct sp_config { char cli_env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */ size_t ncli_env; char cli_fallback[256]; /* cli delegate ids, comma separated */ - char memory_url[512]; - char memory_key_env[64]; char telegram_allow[256]; /* comma separated user ids */ char locale[32]; /* language code, exported as SPLINTER_LOCALE */ char plugins[SP_CONFIG_MAX_PLUGINS][512]; diff --git a/src/backend/engine.c b/src/backend/engine.c index c9cb84c..9ab43f9 100644 --- a/src/backend/engine.c +++ b/src/backend/engine.c @@ -35,7 +35,6 @@ #include "i18n.h" #include "log.h" #include "mcp.h" -#include "memory.h" #include "prompt.h" #include "providers.h" #include "skills.h" @@ -2376,7 +2375,6 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o, o->conf->model); if (sp_builtin_register(&e->reg) != 0 || - sp_memory_register(&e->reg, e->conf) != 0 || sp_skills_register(&e->reg, e->conf) != 0) { sp_buf_puts(err, "cannot register the builtin tools"); goto fail; diff --git a/src/backend/interview.c b/src/backend/interview.c index 356c2d2..7b31f56 100644 --- a/src/backend/interview.c +++ b/src/backend/interview.c @@ -82,7 +82,7 @@ sp_interview_save(const char *session_dir, const char *const *answers, size_t n, struct sp_buf *err) { char dir[600], path[700]; - const char *user = sp_memory_user(); + const char *user = sp_user_name(); FILE *f; size_t i, max = sp_interview_count(); @@ -126,7 +126,7 @@ int sp_profile_exists(const char *session_dir) { char dir[600], path[700]; - const char *user = sp_memory_user(); + const char *user = sp_user_name(); if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL) return 0; @@ -140,7 +140,7 @@ sp_interview_run(const char *session_dir, struct sp_buf *err) static char answers[INTERVIEW_MAX][ANSWER_MAX]; const char *ptrs[INTERVIEW_MAX]; char dir[600], path[700]; - const char *user = sp_memory_user(); + const char *user = sp_user_name(); size_t i, n = sp_interview_count(); if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL) { diff --git a/src/backend/memory.c b/src/backend/memory.c deleted file mode 100644 index 3a35dcc..0000000 --- a/src/backend/memory.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * splinter -- memory, one bucket per user. - * - * Copyright (c) 2026 Konrad Lother - * SPDX-License-Identifier: BSD-3-Clause - * - * The model may remember things. It may not remember them across users. - * - * user_id := the account this process runs as ($USER, else the passwd entry) - * - * Every request carries that id, so a memory written by /root is invisible to - * lotherk and the other way round. The id is not configurable on purpose: a - * config key is a thing to forget, and the process already knows who it is. - * - * Talks mem0's REST API with curl: - * POST /v1/memories/ {messages, user_id} - * POST /v1/memories/search/ {query, user_id} - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "splinter.h" -#include "mcp.h" -#include "config.h" -#include "memory.h" -#include "curl.h" - -static const struct sp_config *mem_cfg; - -/* Who is asking. Not a setting: a fact about the process. */ -const char * -sp_memory_user(void) -{ - static char name[64]; - const char *env = getenv("USER"); - struct passwd *pw; - - if (name[0] != '\0') - return name; - if (env != NULL && *env != '\0') { - snprintf(name, sizeof(name), "%s", env); - return name; - } - pw = getpwuid(getuid()); - if (pw != NULL && pw->pw_name != NULL) { - snprintf(name, sizeof(name), "%s", pw->pw_name); - return name; - } - snprintf(name, sizeof(name), "uid-%ld", (long)getuid()); - return name; -} - -/* - * One POST, body from a buffer, answer captured. - * - * memory_key_env used to be put into the child's environment as - * SPLINTER_MEM_KEY, which curl never reads: no request carried a key, and a - * mem0 that wanted one refused every call. It is now a header, on curl's stdin - * (sp_curl_start), in mem0's "Authorization: Token " form. - */ -static int -mem_post(const char *url, const char *body, struct sp_buf *out, - struct sp_buf *err) -{ - const char *args[] = { "-sS", "-m", "30", "-X", "POST", "-H", - "Content-Type: application/json", "--data-binary", - body, NULL }; - const char *hdrs[2] = { NULL, NULL }; - char auth[600]; - pid_t child; - int fd; - - if (mem_cfg != NULL && mem_cfg->memory_key_env[0] != '\0') { - const char *key = getenv(mem_cfg->memory_key_env); - - if (key != NULL && *key != '\0') { - snprintf(auth, sizeof(auth), "Authorization: Token %s", key); - hdrs[0] = auth; - } - } - fd = sp_curl_start(args, url, hdrs, 1, &child, err); - memset(auth, 0, sizeof(auth)); - if (fd < 0) - return -1; - { - struct pollfd pfd; - char chunk[4096]; - - for (;;) { - ssize_t got; - - pfd.fd = fd; - pfd.events = POLLIN; - if (poll(&pfd, 1, 35000) <= 0) { - (void)kill(child, SIGKILL); - break; - } - got = read(fd, chunk, sizeof(chunk)); - if (got <= 0) - break; - if (sp_buf_add(out, chunk, (size_t)got) != 0) - break; - } - } - close(fd); - { - int st = 0; - - (void)waitpid(child, &st, 0); - if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) { - sp_buf_printf(err, "memory: curl failed"); - return -1; - } - } - return 0; -} - -static int -have_url(struct sp_buf *out) -{ - if (mem_cfg == NULL || mem_cfg->memory_url[0] == '\0') { - sp_buf_puts(out, "error: no memory configured (memory_url in the " - "config)\n"); - return 0; - } - return 1; -} - -static int -tool_memory_add(const char *args, struct sp_buf *out, void *ctx) -{ - struct sp_buf body, reply, err; - const char *text = NULL; - mcp_json *v; - - (void)ctx; - if (!have_url(out)) - return 0; - if (sp_buf_init(&body) != 0 || sp_buf_init(&reply) != 0 || - sp_buf_init(&err) != 0) - return -1; - if (args != NULL && args[0] == '{') { - v = mcp_parse(args); - if (v != NULL) { - text = mcp_arg_string(v, "text"); - if (text != NULL) - (void)sp_buf_puts(&body, text); - mcp_json_free(v); - } - } - text = body.p; - if (text == NULL || *text == '\0') { - sp_buf_puts(out, "error: 'text' is required\n"); - sp_buf_free(&body); - sp_buf_free(&reply); - sp_buf_free(&err); - return 0; - } - { - struct sp_buf req; - - if (sp_buf_init(&req) != 0) - return -1; - sp_buf_printf(&req, "{\"messages\":[{\"role\":\"user\",\"content\":\""); - (void)sp_json_escape(&req, text); - sp_buf_printf(&req, "\"}],\"user_id\":\""); - (void)sp_json_escape(&req, sp_memory_user()); - sp_buf_puts(&req, "\"}"); - { - struct sp_buf url; - - if (sp_buf_init(&url) != 0) { - sp_buf_free(&req); - return -1; - } - sp_buf_printf(&url, "%s/v1/memories/", mem_cfg->memory_url); - if (mem_post(url.p, req.p, &reply, &err) != 0) - sp_buf_printf(out, "error: %s\n", - err.p != NULL ? err.p : "memory add failed"); - else - sp_buf_printf(out, "remembered for '%s'\n", - sp_memory_user()); - sp_buf_free(&url); - } - sp_buf_free(&req); - } - sp_buf_free(&body); - sp_buf_free(&reply); - sp_buf_free(&err); - return 0; -} - -static int -tool_memory_search(const char *args, struct sp_buf *out, void *ctx) -{ - struct sp_buf body, reply, err, req, url; - const char *query = NULL; - mcp_json *v; - - (void)ctx; - if (!have_url(out)) - return 0; - if (sp_buf_init(&body) != 0 || sp_buf_init(&reply) != 0 || - sp_buf_init(&err) != 0 || sp_buf_init(&req) != 0 || - sp_buf_init(&url) != 0) - return -1; - if (args != NULL && args[0] == '{') { - v = mcp_parse(args); - if (v != NULL) { - const char *q = mcp_arg_string(v, "query"); - - if (q != NULL) - (void)sp_buf_puts(&body, q); - mcp_json_free(v); - } - } - query = body.p; - if (query == NULL || *query == '\0') { - sp_buf_puts(out, "error: 'query' is required\n"); - goto done; - } - sp_buf_puts(&req, "{\"query\":\""); - (void)sp_json_escape(&req, query); - sp_buf_puts(&req, "\",\"user_id\":\""); - (void)sp_json_escape(&req, sp_memory_user()); - sp_buf_puts(&req, "\"}"); - sp_buf_printf(&url, "%s/v1/memories/search/", mem_cfg->memory_url); - if (mem_post(url.p, req.p, &reply, &err) != 0) { - sp_buf_printf(out, "error: %s\n", - err.p != NULL ? err.p : "memory search failed"); - goto done; - } - if (reply.p == NULL || strstr(reply.p, "memory") == NULL) { - sp_buf_puts(out, "(nothing remembered)\n"); - goto done; - } - sp_buf_printf(out, "%s\n", reply.p); -done: - sp_buf_free(&body); - sp_buf_free(&reply); - sp_buf_free(&err); - sp_buf_free(&req); - sp_buf_free(&url); - return 0; -} - -int -sp_memory_register(struct sp_registry *r, const struct sp_config *cfg) -{ - struct sp_tool t; - - mem_cfg = cfg; - - memset(&t, 0, sizeof(t)); - t.name = "memory_search"; - t.description = "Search your own memories (scoped to the user this " - "process runs as)."; - t.params = "{\"type\":\"object\",\"properties\":{\"query\":" - "{\"type\":\"string\"}},\"required\":[\"query\"]}"; - t.auth = SP_AUTH_READ; - t.run = tool_memory_search; - if (sp_registry_add(r, &t) != 0) - return -1; - - memset(&t, 0, sizeof(t)); - t.name = "memory_add"; - t.description = "Remember one fact for this user."; - t.params = "{\"type\":\"object\",\"properties\":{\"text\":" - "{\"type\":\"string\"}},\"required\":[\"text\"]}"; - t.auth = SP_AUTH_MUTATE; - t.run = tool_memory_add; - return sp_registry_add(r, &t); -} diff --git a/src/backend/memory.h b/src/backend/memory.h deleted file mode 100644 index a550d3a..0000000 --- a/src/backend/memory.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * splinter -- memory, one bucket per user. - * - * Copyright (c) 2026 Konrad Lother - * SPDX-License-Identifier: BSD-3-Clause - */ -#ifndef SPLINTER_MEMORY_H -#define SPLINTER_MEMORY_H - -#include "splinter.h" - -struct sp_config; -int sp_memory_register(struct sp_registry *, const struct sp_config *); -const char *sp_memory_user(void); - -#endif /* SPLINTER_MEMORY_H */ diff --git a/src/backend/telegram.c b/src/backend/telegram.c index 5b43412..1c8681e 100644 --- a/src/backend/telegram.c +++ b/src/backend/telegram.c @@ -1045,7 +1045,7 @@ tg_interview_begin(const char *token, long chat_id, struct sp_buf *err) tg_iv.step = 0; if (sp_buf_init(&msg) != 0) return; - sp_buf_printf(&msg, sp_t("tg.interview.start"), sp_memory_user(), + sp_buf_printf(&msg, sp_t("tg.interview.start"), sp_user_name(), sp_interview_count()); (void)send_message(token, chat_id, msg.p, err); sp_buf_free(&msg); @@ -1069,7 +1069,7 @@ tg_interview_end(const char *token, long chat_id, const char *session_dir, path[0] = '\0'; if (sp_profile_path(session_dir, dir, sizeof(dir)) != NULL) snprintf(path, sizeof(path), "%s/%s.md", dir, - sp_memory_user()); + sp_user_name()); if (sp_buf_init(&msg) == 0) { sp_buf_printf(&msg, sp_t("tg.interview.saved"), path); (void)send_message(token, chat_id, msg.p, err); diff --git a/src/backend/user.c b/src/backend/user.c new file mode 100644 index 0000000..5f0a4ea --- /dev/null +++ b/src/backend/user.c @@ -0,0 +1,40 @@ +/* + * splinter -- who this process runs as. + * + * Copyright (c) 2026 Konrad Lother + * SPDX-License-Identifier: BSD-3-Clause + * + * The account is a fact about the process, not a setting: profiles, the + * interview and the memory were all keyed by it. The memory (mem0) is gone, + * the identity is not. + */ +#include +#include +#include +#include +#include +#include + +#include "splinter.h" + +const char * +sp_user_name(void) +{ + static char name[64]; + const char *env = getenv("USER"); + struct passwd *pw; + + if (name[0] != '\0') + return name; + if (env != NULL && *env != '\0') { + snprintf(name, sizeof(name), "%s", env); + return name; + } + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_name != NULL) { + snprintf(name, sizeof(name), "%s", pw->pw_name); + return name; + } + snprintf(name, sizeof(name), "uid-%ld", (long)getuid()); + return name; +} diff --git a/src/main.c b/src/main.c index 68c80f9..6d67994 100644 --- a/src/main.c +++ b/src/main.c @@ -614,7 +614,6 @@ hide_secrets(const struct opts *o, const struct sp_config *conf) (void)sp_secret_env_add(o->key_env); (void)sp_secret_env_add(conf->key_env); - (void)sp_secret_env_add(conf->memory_key_env); (void)sp_secret_env_add("OLLAMA_KEY_*"); (void)sp_secret_env_add("CLAUDE_CODE_OAUTH_TOKEN_*"); for (k = 0; k < conf->ndelegates; k++) @@ -1546,7 +1545,7 @@ main(int argc, char **argv) if (!sp_profile_exists(sp_engine_state_dir(eng))) fprintf(stderr, "splinter: kein Profil fuer '%s' - " "`splinter --interview` legt eins an\n", - sp_memory_user()); + sp_user_name()); rc = sp_ui_run(sp_ui_backend_engine(&eng, &eo), o.theme); } else if (o.prompt != NULL && (o.prompt[0] == '/' || o.prompt[0] == '!')) diff --git a/tests/test_mcpsession.sh b/tests/test_mcpsession.sh index 01a47de..33b6745 100755 --- a/tests/test_mcpsession.sh +++ b/tests/test_mcpsession.sh @@ -42,6 +42,8 @@ python3 - "$port" <<'PY' import json, socket, sys s = socket.create_connection(("127.0.0.1", int(sys.argv[1])), 5) +# a turn is a turn: the script transport is fast, but the machine may be busy +s.settimeout(120) f = s.makefile("rw", encoding="utf-8") def req(i, method, params=None): diff --git a/tests/test_memory.c b/tests/test_memory.c deleted file mode 100644 index dc26329..0000000 --- a/tests/test_memory.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * splinter -- memory scoping. - * - * The one thing that must never break: the user id. Every request carries it, - * and it comes from who is running - not from a setting someone can forget. - */ -#include -#include -#include - -#include -#include - -#include "splinter.h" -#include "config.h" -#include "memory.h" - -static int failures; - -#define CHECK(c) do { if (!(c)) { fprintf(stderr, "FAIL %s:%d: %s\n", \ - __FILE__, __LINE__, #c); failures++; } } while (0) - -int -main(void) -{ - const char *user; - - /* from the environment */ - CHECK(setenv("USER", "lotherk", 1) == 0); - user = sp_memory_user(); - CHECK(user != NULL); - CHECK(strcmp(user, "lotherk") == 0); - - /* without USER it falls back to the passwd entry, never to empty */ - CHECK(unsetenv("USER") == 0); - user = sp_memory_user(); - CHECK(user != NULL); - CHECK(strlen(user) > 0); - - /* - * ---- memory_key_env reaches the server, and only through stdin ---- - * It used to become SPLINTER_MEM_KEY in curl's environment, which curl - * never reads: no request carried a key. A fake curl records its argv - * and the config it is handed. - */ - { - char dir[] = "/var/tmp/splinter-mem-XXXXXX"; - char path[600], line[1400], cfgf[620], argf[620]; - char buf[4096]; - const char *oldpath = getenv("PATH"); - static struct sp_config c; - struct sp_registry r; - struct sp_buf out; - const struct sp_tool *t; - FILE *f; - size_t n; - - CHECK(mkdtemp(dir) != NULL); - snprintf(cfgf, sizeof(cfgf), "%s/cfg", dir); - snprintf(argf, sizeof(argf), "%s/args", dir); - snprintf(path, sizeof(path), "%s/curl", dir); - f = fopen(path, "w"); - CHECK(f != NULL); - if (f != NULL) { - fprintf(f, "#!/bin/sh\nprintf '%%s\\n' \"$@\" > %s\n" - "cat > %s\necho '{\"results\":[]}'\n", argf, cfgf); - fclose(f); - } - (void)chmod(path, 0755); - snprintf(line, sizeof(line), "%s:%s", dir, - oldpath != NULL ? oldpath : "/usr/bin:/bin"); - (void)setenv("PATH", line, 1); - (void)setenv("MY_MEM0_KEY", "m0-geheim", 1); - - sp_config_init(&c); - snprintf(c.memory_url, sizeof(c.memory_url), "http://mem0.example"); - snprintf(c.memory_key_env, sizeof(c.memory_key_env), "MY_MEM0_KEY"); - memset(&r, 0, sizeof(r)); - CHECK(sp_memory_register(&r, &c) == 0); - CHECK(sp_buf_init(&out) == 0); - t = sp_registry_find(&r, "memory_search"); - CHECK(t != NULL); - if (t != NULL) - (void)t->run("{\"query\":\"x\"}", &out, t->ctx); - - buf[0] = '\0'; - if ((f = fopen(cfgf, "r")) != NULL) { - n = fread(buf, 1, sizeof(buf) - 1, f); - buf[n] = '\0'; - fclose(f); - } - CHECK(strstr(buf, "Authorization: Token m0-geheim") != NULL); - buf[0] = '\0'; - if ((f = fopen(argf, "r")) != NULL) { - n = fread(buf, 1, sizeof(buf) - 1, f); - buf[n] = '\0'; - fclose(f); - } - CHECK(buf[0] != '\0' && strstr(buf, "m0-geheim") == NULL); - - sp_buf_free(&out); - sp_registry_free(&r); - (void)setenv("PATH", oldpath != NULL ? oldpath : "/usr/bin:/bin", 1); - snprintf(line, sizeof(line), "rm -rf '%s'", dir); - (void)system(line); - } - - if (failures == 0) - printf("test_memory: ok\n"); - return failures == 0 ? 0 : 1; -}