review fixes, third round: the gateway asks in its chat, approvals say what

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>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-09 06:13:09 +00:00
1 parent 489c5da26a
commit 25a616a87f
15 files changed
+641 -88

No files matched your search

+43 -7
View File
@@ -34,7 +34,6 @@
#include "i18n.h"
#define OUT_CAP (4u << 20)
#define BODY_CAP (1u << 20)
struct cli_cfg {
char cmd[512];
@@ -71,13 +70,26 @@ render(const struct sp_conv *conv, int full, struct sp_buf *out)
}
}
/* 's' as one single-quoted shell word */
static int
sh_word(struct sp_buf *b, const char *s)
{
if (sp_buf_puts(b, "'") != 0)
return -1;
for (; *s != '\0'; s++)
if (*s == '\'' ? sp_buf_puts(b, "'\\''") != 0 :
sp_buf_add(b, s, 1) != 0)
return -1;
return sp_buf_puts(b, "'");
}
static int
cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
struct sp_buf *err)
{
struct cli_cfg *c = ctx;
struct sp_buf body, cmd, raw;
char path[512];
char path[512], errpath[540] = "", errtext[512];
const char *tmpdir = getenv("TMPDIR");
int fd, status;
ssize_t w;
@@ -110,8 +122,20 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
goto fail;
}
/* the program reads the prompt on stdin; timeout guards a hang */
sp_buf_printf(&cmd, "timeout %s %s < %s", c->timeout, c->cmd, path);
/*
* The program reads the prompt on stdin; timeout guards a hang. Its
* stderr goes to a file next to the prompt: on the terminal it landed in
* the middle of the curses screen, and the error message below promised
* "the program's own stderr" while it quoted stdout. The paths are quoted;
* TMPDIR is the operator's, but a space in it still broke the command.
*/
snprintf(errpath, sizeof(errpath), "%s.err", path);
sp_buf_printf(&cmd, "timeout %s %s < ", c->timeout, c->cmd);
if (sh_word(&cmd, path) != 0 || sp_buf_puts(&cmd, " 2> ") != 0 ||
sh_word(&cmd, errpath) != 0) {
unlink(path);
goto fail;
}
p = popen(cmd.p, "r");
if (p == NULL) {
sp_buf_printf(err, "cli: popen: %s", strerror(errno));
@@ -138,6 +162,18 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
}
status = pclose(p);
unlink(path);
errtext[0] = '\0';
{
FILE *ef = fopen(errpath, "r");
size_t en = 0;
if (ef != NULL) {
en = fread(errtext, 1, sizeof(errtext) - 1, ef);
fclose(ef);
}
errtext[en] = '\0';
(void)unlink(errpath);
}
if (status < 0) {
sp_buf_printf(err, "cli: %s", strerror(errno));
@@ -151,7 +187,7 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
sp_buf_printf(err, sp_td("cli.failed", "cli: '%s' failed (exit %d): %.400s"), c->cmd,
WIFEXITED(status) ? WEXITSTATUS(status) : -1,
raw.p != NULL ? raw.p : "");
errtext[0] != '\0' ? errtext : raw.p != NULL ? raw.p : "");
goto fail;
}
if (raw.len == 0) {
@@ -162,14 +198,14 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
out->content = strdup(raw.p);
if (out->content == NULL)
goto fail;
if (body.len > BODY_CAP)
(void)0; /* capped above; kept explicit */
sp_buf_free(&body);
sp_buf_free(&cmd);
sp_buf_free(&raw);
return 0;
fail:
if (errpath[0] != '\0')
(void)unlink(errpath);
sp_buf_free(&body);
sp_buf_free(&cmd);
sp_buf_free(&raw);