Files
splinter/plugins/reminder/reminder.c
Konrad 878c8588e0 splinter: default system prompt with placeholders, reminder plugin
The default prompt says what the code cannot: read the documentation before you
build - README, AGENTS, man pages, the source itself - because a hack that works
against the documented way is a bug with good timing. Also: check what exists,
change the approach instead of repeating a failure, evidence over claims, never
invent output, answer briefly.

Placeholders {{os}}, {{home}}, {{cwd}}, {{model}} are filled at startup, so the
model is told which machine it is on instead of asking.

plugins/reminder puts five short rules back into the conversation every tenth
turn (SPLINTER_REMINDER_EVERY), in front of the newest user message. A rule read
once and buried under forty thousand tokens has stopped existing; one that comes
back is still a rule.

The bug that made both pointless: ag.host was never set, so sp_host_compact was
never called by the real binary. Every compactor - lcm, focus, reminder - was
registered, tested in isolation, and dead in production. 'Compaction happens
before the budget is judged' was true only in the tests.

Verified: with SPLINTER_REMINDER_EVERY=1 the request body contains [reminder]
(checked in wire.jsonl), and the system prompt arrives with the OS and no
leftover {{...}}.
2026-11-08 13:51:48 +00:00

122 lines
3.1 KiB
C

/*
* splinter -- the reminder.
*
* Copyright (c) 2026 Konrad Lother
* SPDX-License-Identifier: BSD-3-Clause
*
* Every tenth turn the rules go back into the conversation, as a system message
* right before the newest user message:
*
* SPLINTER_REMINDER_EVERY turns between reminders, default 10
*
* Why not in the system prompt? Because it is read once and then buried under
* forty thousand tokens of conversation. A rule that matters every turn has to
* come back, or it stops existing.
*
* The rules are short and factual. A reminder that lectures is a reminder the
* model learns to skip.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "splinter.h"
#include "splinter_plugin.h"
#include "i18n.h"
#define REMINDER_MAX 1024
static unsigned every = 10;
static unsigned last_reminder = (unsigned)-1;
static unsigned sent;
static const char *const rules[] = {
"Read the documentation before you build: README, AGENTS, man pages, "
"the source itself. A hack that works against the documented way is a "
"bug with good timing.",
"Check what already exists before writing something new.",
"Evidence over claims: run it, read the output, say what is verified.",
"Never invent output, paths or results.",
"Stop and ask before anything destructive or irreversible.",
NULL
};
static int
reminder_compact(struct sp_host *h, struct sp_conv *conv, size_t budget,
unsigned turn)
{
char text[REMINDER_MAX];
struct sp_msg m;
size_t at, i, used = 0;
(void)budget;
if (conv == NULL || conv->n == 0 || every == 0)
return 0;
if (turn % every != 0 || turn == last_reminder)
return 0;
last_reminder = turn;
used += (size_t)snprintf(text, sizeof(text) - used, "[reminder]\n");
for (i = 0; rules[i] != NULL && used + 4 < sizeof(text); i++)
used += (size_t)snprintf(text + used, sizeof(text) - used,
"- %s\n", rules[i]);
/* before the newest user message, never after it */
at = conv->n;
for (i = conv->n; i > 0; i--) {
if (conv->v[i - 1].role != NULL &&
strcmp(conv->v[i - 1].role, "user") == 0) {
at = i - 1;
break;
}
}
memset(&m, 0, sizeof(m));
m.role = "system";
m.content = text;
if (sp_conv_add(conv, &m) != 0) {
(void)sp_host_note(h, "reminder: cannot add the message");
return -1;
}
/* sp_conv_add appends; move it in front of the user message */
if (at < conv->n - 1) {
struct sp_msg moved = conv->v[conv->n - 1];
memmove(&conv->v[at + 1], &conv->v[at],
sizeof(conv->v[0]) * (conv->n - 1 - at));
conv->v[at] = moved;
}
sent++;
return 1;
}
static const struct sp_compactor compactor = { "reminder", reminder_compact };
static int
reminder_init(struct sp_host *h)
{
const char *env = getenv("SPLINTER_REMINDER_EVERY");
if (env != NULL && *env != '\0')
every = (unsigned)strtoul(env, NULL, 10);
if (sp_host_add_compactor(h, &compactor) != 0) {
(void)sp_host_note(h, "reminder: cannot register (add_compactor)");
return -1;
}
return 0;
}
static const struct sp_plugin plugin = {
SP_PLUGIN_ABI,
"reminder",
"1.0",
reminder_init,
NULL,
NULL
};
const struct sp_plugin *
sp_plugin_describe(void)
{
return &plugin;
}