From c0ec7bacd47a4efb6f2fe08fed3644d1b1cce1bd Mon Sep 17 00:00:00 2001 From: Konrad Date: Sun, 8 Nov 2026 16:02:21 +0000 Subject: [PATCH] splinter: kid mode enforces the day, and the site speaks Portuguese The daily budget was advisory: the gate refused tools and a system message asked the model to close the day, but a chatty model answered anyway. So the core grew a turn gate - a plugin can now refuse the whole turn before the model is called: Fuer heute ist Schluss: 60 von 30 Minuten sind verbraucht. Morgen geht es weiter. That sentence comes from the plugin, not from a model that was asked to obey. No model call, no tokens, no way around it by talking. Also fixed: one-shot mode printed only a newline when the transport streamed nothing (a turn blocked before the stream), so the answer vanished. It is printed when no bytes were streamed. Website: third language, index.pt.html, generated from the same source; the language bar on all three pages links all three. check_i18n now sees 51 keys in three catalogues. --- include/splinter_plugin.h | 7 ++ plugins/kids/kids.c | 18 ++++- src/agent.c | 16 +++- src/main.c | 6 +- src/plugin.c | 14 ++++ src/www/index.html | 2 +- src/www/index.pt.html | 156 ++++++++++++++++++++++++++++++++++++++ tools/gen_www.py | 101 +++++++++++++++++++++++- 8 files changed, 313 insertions(+), 7 deletions(-) create mode 100644 src/www/index.pt.html diff --git a/include/splinter_plugin.h b/include/splinter_plugin.h index fc99fe3..5519093 100644 --- a/include/splinter_plugin.h +++ b/include/splinter_plugin.h @@ -77,6 +77,12 @@ struct sp_gate { int (*check)(struct sp_host *, const char *tool, int auth, const char *args, char *reason, size_t reason_len); + /* + * Optional: refuse the whole turn before the model is called. Used by kid + * mode when the day's minutes are gone - a message the child reads, not a + * hang, and not a model that has to be trusted to obey. + */ + int (*block_turn)(struct sp_host *, char *msg, size_t len); }; struct sp_plugin { @@ -105,6 +111,7 @@ int sp_host_add_gate(struct sp_host *, const struct sp_gate *); /* 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); +int sp_host_turn_blocked(struct sp_host *, char *msg, size_t len); int sp_host_add_command(struct sp_host *, const char *name, sp_cmd_fn, void *ctx); int sp_host_command(struct sp_host *, const char *name, const char *args, diff --git a/plugins/kids/kids.c b/plugins/kids/kids.c index b0d83f2..0ad5504 100644 --- a/plugins/kids/kids.c +++ b/plugins/kids/kids.c @@ -248,7 +248,23 @@ kids_gate(struct sp_host *h, const char *tool, int auth, const char *args, return ask_parent(tool, args, reason, reason_len) ? 1 : 0; } -static const struct sp_gate gate = { "kids", kids_gate }; +/* + * The day ends here. Not "the model is asked to stop" - the model is not called + * at all, so a chatty model cannot talk past the budget. + */ +static int +kids_block_turn(struct sp_host *h, char *msg, size_t len) +{ + (void)h; + if (quota_left() != 0) + return 0; + snprintf(msg, len, "Fuer heute ist Schluss: %ld von %u Minuten sind " + "verbraucht. Morgen geht es weiter.", used_seconds / 60, + daily_minutes); + return 1; +} + +static const struct sp_gate gate = { "kids", kids_gate, kids_block_turn }; /* * Kid-safe conversation: a system message in front of every request, because a diff --git a/src/agent.c b/src/agent.c index 3c68a2a..4915b6b 100644 --- a/src/agent.c +++ b/src/agent.c @@ -118,7 +118,21 @@ sp_agent_run(struct sp_agent *a, const char *user_text, struct sp_buf *answer, sp_buf_clear(answer); /* the turn counter is what a plugin like 'focus' schedules against */ if (a->host != NULL) - sp_host_turn(a->host); + /* + * A turn gate runs before the model does. Kid mode ends the day here: the + * child gets a sentence, the model gets nothing to answer. + */ + if (a->host != NULL) { + char msg[256]; + + msg[0] = '\0'; + if (sp_host_turn_blocked(a->host, msg, sizeof(msg))) { + sp_buf_puts(answer, msg[0] != '\0' ? msg : + "today is over"); + return 0; + } + } + sp_host_turn(a->host); if (sp_buf_init(&obs) != 0) { sp_buf_puts(err, "agent: out of memory"); if (conv == &local) diff --git a/src/main.c b/src/main.c index 1a70f28..84ddf2b 100644 --- a/src/main.c +++ b/src/main.c @@ -112,12 +112,16 @@ load_script(struct sp_mock *m, const char *path, struct sp_buf *err) } /* one-shot mode: print the answer as it arrives, no buffering */ +/* bytes the transport streamed: if none, the answer still has to be printed */ +static size_t streamed_bytes; + static void stdout_stream(void *ctx, int kind, const char *text) { (void)ctx; if (kind != SP_STREAM_TEXT || text == NULL) return; + streamed_bytes += strlen(text); fputs(text, stdout); fflush(stdout); } @@ -797,7 +801,7 @@ main(int argc, char **argv) cfg.stream_ctx = NULL; rc = sp_agent_run(&ag, prompt, &answer, &err); if (rc == 0) { - if (cfg.stream == NULL) + if (cfg.stream == NULL || streamed_bytes == 0) printf("%s\n", answer.p != NULL ? answer.p : ""); else printf("\n"); /* the stream already printed it */ diff --git a/src/plugin.c b/src/plugin.c index 5fbfb92..4a63a72 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -189,6 +189,20 @@ sp_host_add_gate(struct sp_host *h, const struct sp_gate *g) * The first gate with an opinion wins. A denial carries its reason; allowing * skips the operator prompt, which is what a whitelist is for. */ +int +sp_host_turn_blocked(struct sp_host *h, char *msg, size_t len) +{ + size_t i; + + if (h == NULL) + return 0; + for (i = 0; i < h->ngate; i++) + if (h->gate[i]->block_turn != NULL && + h->gate[i]->block_turn(h, msg, len)) + return 1; + return 0; +} + int sp_host_gate(struct sp_host *h, const char *tool, int auth, const char *args, char *reason, size_t reason_len) diff --git a/src/www/index.html b/src/www/index.html index cc1c53a..6881746 100644 --- a/src/www/index.html +++ b/src/www/index.html @@ -48,7 +48,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
-

Deutsch · English

+

Deutsch · English · Portugues (BR)

splinter_

Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.

diff --git a/src/www/index.pt.html b/src/www/index.pt.html new file mode 100644 index 0000000..753e8c7 --- /dev/null +++ b/src/www/index.pt.html @@ -0,0 +1,156 @@ + + + + +splinter - um harness de agente que e seu + + + + +
+ +

Deutsch · English · Portugues (BR)

+ +

splinter_

+

Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.

+ +

9.125 linhas C99/POSIX · +248.568 bytes do binario · 21 programas de teste · +8 plugins · 42 paletas · BSD-3-Clause

+ +

O que e

+

splinter e um harness de agente em C99/POSIX: um programa que segura a +conversa, decide quais ferramentas existem, quem pode usa-las e o que ficou +registrado. O modelo e um detalhe trocavel; o harness e a parte que sabe o que +acontece.

+ +

Como se parece

+
voce: por que o build falha?
+pensando: preciso ler o erro antes de opinar.
+ferramenta: search {"pattern":"error","path":"build/logs"}
+ferramenta: read {"path":"build/logs/last.log"}
+alteracao: -CFLAGS = -O2
+           +CFLAGS = -O2 -Wall -Werror
+modelo: faltava -Werror; o erro era um aviso promovido.
+

Pensamento, ferramenta com argumentos, alteracao e resposta entram no +transcript na ordem em que acontecem.

+ +

Tres verificacoes antes de cada ferramenta

+

Orcamento, registro e classe de autorizacao. A ferramenta declara a classe +(read, mutate, destructive) - nunca o modelo, nunca o prompt. Um plugin pode +entrar na frente com um gate: permitir, negar com motivo, ou nao opinar.

+ +

Ferramentas

+

14 ferramentas: read, write, edit, +search, list, run, +folder_history, delegate, +delegate_parallel e as de leitura do sistema.

+ +

Transportes e plugins

+

Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), mock para +teste. Plugins sao .so carregados com dlopen: lcm, focus, reminder, +ring, mcp, cli, clock, cps e agora kids.

+ +

Delegacao: outros modelos, splinter escolhe

+
[parallel: 2 task(s), 12018 ms wall]
+
+## task 1 | model slow | score 5 | 12018 ms | exit 0 | 75 B | requested tag 'slow'
+

Modelo, duracao e status por tarefa - um delegado lento aparece no cabecalho +antes de alguem ler o texto.

+ +

Configuracao

+
endpoint = http://kontron.local:8080/v1/chat/completions
+model = ...
+autonomous = 1
+

~/.splinter/splinter.conf mais splinter.conf.d/*.conf +em ordem de nome. Chave desconhecida e erro com numero de linha.

+ +

Gateway: Telegram

+

splinter --daemon fala Telegram com indicador de digitacao e os +mesmos slash commands do terminal.

+ +

O que fica registrado

+

Cada sessao escreve session.log (eventos legiveis) e +wire.jsonl (o que foi de fato enviado ao modelo).

+ +

Compilar

+
make
+make check   # 21 binarios de teste, i18n, site
+

Sem dependencias alem de libc e pthread; ncurses vem do vendor.

+ +

O que nao e

+
  • nao e um modelo;
  • nao e um servico - e um programa;
  • +
  • nao guarda nada em sqlite: sessoes sao arquivos;
  • +
  • nao adivinha: mede.
+ +

A frota

+
delegate = olivia | em olivia | tags=remote | host=172.25.206.16 |
+           endpoint=http://172.25.206.2:18082/v1/chat/completions | model=...
+

O delegate nomeia um host e a chamada inteira vai por ssh; a maquina remota +poe suas proprias chaves.

+ +

As duas direcoes: MCP

+
$ splinter --mcp-server-listen 0.0.0.0 --mcp-listen-port 8098
+splinter: MCP server on 0.0.0.0:8098 (14 tools, read only)
+

Como cliente busca ferramentas; como servidor oferece as suas. Mutar so com +--autonomous.

+ +

Pipe, pasta, primeira conversa

+
$ cat /etc/passwd | splinter "explique o arquivo"
+$ cd ~/src/splinter && splinter -c
+$ splinter --interview
+

stdin vira contexto; -c pega a ultima sessao daquele diretorio; +--interview escreve o perfil em +~/.splinter/profile/<usuario>.md.

+ +

Modo crianca

+

Com o plugin kids, toda acao que muda algo precisa da aprovacao de +um adulto (Telegram), uma lista branca libera o inofensivo, o modelo e lembrado a +cada pedido de manter a conversa adequada a idade, e um limite diario de minutos +fecha o dia quando acaba.

+ +
+ + +
+ + diff --git a/tools/gen_www.py b/tools/gen_www.py index 6228df0..8fb2676 100644 --- a/tools/gen_www.py +++ b/tools/gen_www.py @@ -14,8 +14,9 @@ import sys ROOT = pathlib.Path(__file__).resolve().parent.parent OUT = ROOT / "src" / "www" -LANGS = ["de", "en"] -FILES = {"de": "index.html", "en": "index.en.html"} +LANGS = ["de", "en", "pt_BR"] +FILES = {"de": "index.html", "en": "index.en.html", + "pt_BR": "index.pt.html"} HEAD = """ @@ -171,7 +172,7 @@ T = { "de": { "title": "splinter — ein Agent-Harness, das dir gehoert", "desc": "splinter ist ein Agent-Harness in C99/POSIX: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jeder OpenAI-kompatible Endpunkt, Telegram-Gateway.", - "langbar": "Deutsch · English", + "langbar": "Deutsch · English · Portugues (BR)", "lead": "Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit " "Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns " "gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines " @@ -199,6 +200,20 @@ T = { }, } +T["pt_BR"] = { + "title": "splinter - um harness de agente que e seu", + "desc": "splinter e um harness de agente em C99/POSIX: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer endpoint compativel com OpenAI, gateway Telegram.", + "langbar": "Deutsch · English · Portugues (BR)", + "lead": "Um harness de agente que e seu: chat no terminal, ferramentas com " + "classes de autorizacao, plugins, qualquer modelo que fale OpenAI - " + "escrito por nos para poder mudar-lo, em vez de nos acostumar com o " + "comportamento de um cliente alheio.", + "m_lines": "linhas C99/POSIX", "m_binary": "bytes do binario", + "m_tests": "programas de teste", "m_plugins": "plugins", "m_themes": "paletas", + "foot": "splinter - C99/POSIX, BSD-3-Clause. Manual: man ./docs/splinter.1" + " · ABI de plugins: docs/PLUGINS.md", +} + SECTIONS = { "de": [ ("

Was es ist

\n

Dasselbe, was Claude Code oder opencode fuer dich sind: ein " @@ -440,6 +455,86 @@ of letting it guess; the profile from the interview lives in ~/.splinter/profile/<user>.md.

""", ] + +SECTIONS["pt_BR"] = [ +"""

O que e

+

splinter e um harness de agente em C99/POSIX: um programa que segura a +conversa, decide quais ferramentas existem, quem pode usa-las e o que ficou +registrado. O modelo e um detalhe trocavel; o harness e a parte que sabe o que +acontece.

""", +"""

Como se parece

+
voce: por que o build falha?
+pensando: preciso ler o erro antes de opinar.
+ferramenta: search {"pattern":"error","path":"build/logs"}
+ferramenta: read {"path":"build/logs/last.log"}
+alteracao: -CFLAGS = -O2
+           +CFLAGS = -O2 -Wall -Werror
+modelo: faltava -Werror; o erro era um aviso promovido.
+

Pensamento, ferramenta com argumentos, alteracao e resposta entram no +transcript na ordem em que acontecem.

""", +"""

Tres verificacoes antes de cada ferramenta

+

Orcamento, registro e classe de autorizacao. A ferramenta declara a classe +(read, mutate, destructive) - nunca o modelo, nunca o prompt. Um plugin pode +entrar na frente com um gate: permitir, negar com motivo, ou nao opinar.

""", +"""

Ferramentas

+

14 ferramentas: read, write, edit, +search, list, run, +folder_history, delegate, +delegate_parallel e as de leitura do sistema.

""", +"""

Transportes e plugins

+

Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), mock para +teste. Plugins sao .so carregados com dlopen: lcm, focus, reminder, +ring, mcp, cli, clock, cps e agora kids.

""", +"""

Delegacao: outros modelos, splinter escolhe

+
[parallel: 2 task(s), 12018 ms wall]
+
+## task 1 | model slow | score 5 | 12018 ms | exit 0 | 75 B | requested tag 'slow'
+

Modelo, duracao e status por tarefa - um delegado lento aparece no cabecalho +antes de alguem ler o texto.

""", +"""

Configuracao

+
endpoint = http://kontron.local:8080/v1/chat/completions
+model = ...
+autonomous = 1
+

~/.splinter/splinter.conf mais splinter.conf.d/*.conf +em ordem de nome. Chave desconhecida e erro com numero de linha.

""", +"""

Gateway: Telegram

+

splinter --daemon fala Telegram com indicador de digitacao e os +mesmos slash commands do terminal.

""", +"""

O que fica registrado

+

Cada sessao escreve session.log (eventos legiveis) e +wire.jsonl (o que foi de fato enviado ao modelo).

""", +"""

Compilar

+
make
+make check   # 21 binarios de teste, i18n, site
+

Sem dependencias alem de libc e pthread; ncurses vem do vendor.

""", +"""

O que nao e

+""", +"""

A frota

+
delegate = olivia | em olivia | tags=remote | host=172.25.206.16 |
+           endpoint=http://172.25.206.2:18082/v1/chat/completions | model=...
+

O delegate nomeia um host e a chamada inteira vai por ssh; a maquina remota +poe suas proprias chaves.

""", +"""

As duas direcoes: MCP

+
$ splinter --mcp-server-listen 0.0.0.0 --mcp-listen-port 8098
+splinter: MCP server on 0.0.0.0:8098 (14 tools, read only)
+

Como cliente busca ferramentas; como servidor oferece as suas. Mutar so com +--autonomous.

""", +"""

Pipe, pasta, primeira conversa

+
$ cat /etc/passwd | splinter "explique o arquivo"
+$ cd ~/src/splinter && splinter -c
+$ splinter --interview
+

stdin vira contexto; -c pega a ultima sessao daquele diretorio; +--interview escreve o perfil em +~/.splinter/profile/<usuario>.md.

""", +"""

Modo crianca

+

Com o plugin kids, toda acao que muda algo precisa da aprovacao de +um adulto (Telegram), uma lista branca libera o inofensivo, o modelo e lembrado a +cada pedido de manter a conversa adequada a idade, e um limite diario de minutos +fecha o dia quando acaba.

""", +] + def render(lang): strings = dict(T[lang]) strings["lang"] = lang