Telegram gateway - A tool call of the gateway's own turn that needed consent was either denied (a daemon has no approval stream) or, with ack channels set, waited for an "ok <id>" that only the blocked gateway could have read. It now asks in the chat the turn came from, keeps reading while it waits, resolves answers (also other processes' and 'splinter --ack'), ignores strangers and tells everything else to wait. The update offset is shared, so nothing is handled twice. New cfg flag approve_is_channel: such an approve is asked directly. - send_message wrote its error through err, and half the callers pass NULL: the first refused message (too long, bad UTF-8) crashed the gateway. It also missed '"ok": true' by substring; the reply is parsed now. - tests/test_gateway.sh drives the real daemon against a fake Bot API and a fake model (tests/fake_telegram.py), with "ok" and with "no". In make check; .gitignore no longer hides tests/test_*.sh. Approvals - A channel was told "Zustimmung <id>" and nothing else: a phone said yes to a number. The message now names the tool and its arguments (cut at 300 bytes) and how to answer, and goes to the channel as "$1", never parsed by sh. Smaller - ring: an exit that already streamed text is not retried on the next one (the operator saw a second answer after half of the first); the header now says what moves the ring - limits and providers that are down. - cli: the program's stderr went over the curses screen and the error quoted stdout. stderr goes to a file and into the error; temp paths are quoted; the BODY_CAP no-op is gone. (That is the "kaputt" make check used to print.) - memory: memory_key_env became an env var curl never reads, so no request had a key. It is "Authorization: Token <key>" now, on curl's stdin. Tested. - docs/CONFIG.md: the real default path, and the seven keys it did not know (telegram_allow, memory_url, memory_key_env, skills_dir, env_delegates, exit, delegate) with the line formats, checked against the parser. - The no-token message named a config key that does not exist. Left as it is, on purpose: 'read' stays unrestricted (decision); the fsync per session line stays (durability over latency). make check: 26 test binaries and the gateway script, green, also under ASan/UBSan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
3.0 KiB
C
112 lines
3.0 KiB
C
/*
|
|
* 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 <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
#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;
|
|
}
|