Files
splinter/src/config.h
T
Konrad 04420d9f8d splinter: exit ring, config next to the sessions, drop-ins
The config moved to ~/.splinter/splinter.conf - next to the sessions, where the
state of this thing already lives - and every *.conf in the directory named after
it is read after it, in name order. A later file overrides an earlier one, an
unknown key is still fatal, and the error now names the file it came from.

plugins/ring is the exit ring: several ways to reach a model, walked in order
when one is rate limited.

  exit = go    | OpenCode Go    | endpoint=... | model=...
  exit = groq  | Groq free tier | endpoint=... | model=... | key_env=GROQ_KEY
  exit = local | kontron, lokal | endpoint=... | model=...

Only pressure moves the ring - 429, 5xx, 'rate limit', 'quota'. A dead host or a
bad key stops the turn, because a ring that treats every failure as 'try the
next one' hides real breakage behind a random provider.

Two things had to be fixed underneath: sp_openai_transport kept its context in a
static variable, so building several transports pointed them all at the last one
(now one heap context per transport), and plugins had no way to read the config
or the registry (sp_host_config, sp_host_registry).

Measured against two fake providers: the first answers 429, the ring moves on and
the second answers 'Antwort vom zweiten Ausgang.'; a dead port does not move it
and the error stands.
2026-11-08 12:55:42 +00:00

90 lines
2.7 KiB
C

/*
* splinter -- configuration file.
*
* Copyright (c) 2026 Konrad Lother
* SPDX-License-Identifier: BSD-3-Clause
*
* Format: one `key = value` per line, `#` starts a comment, blank lines are
* ignored. Deliberately not JSON: this file is meant to be edited by hand at
* 2 a.m., and a missing comma must not be the reason the harness will not
* start.
*
* Precedence, highest first: command line, then this file, then the built-in
* default. Every key is documented in `docs/CONFIG.md`; an unknown key is an
* error with the line number, because a typo that is silently ignored is a
* config that lies about what it does.
*/
#ifndef SPLINTER_CONFIG_H
#define SPLINTER_CONFIG_H
#include <stddef.h>
#include "splinter.h"
#define SP_CONFIG_MAX_PLUGINS 8
/*
* A delegate is another model splinter may hand work to: a name, what it is
* good at, and where it lives. No profiles - a profile is a directory with a
* dozen files, and all this needs is a line you can read at 2 a.m.
*/
#define SP_CONFIG_MAX_DELEGATES 8
/*
* An exit is one way to reach a model: an endpoint, a model name and where its
* key lives. The ring tries them in order, so a rate limit costs a step, not the
* turn.
*/
struct sp_exit {
char id[32];
char label[64]; /* what shows up in the sidebar */
char endpoint[512];
char model[256];
char key_env[64];
};
struct sp_delegate {
char id[32];
char about[128]; /* what it is good at, in words */
char tags[128]; /* comma separated, matched against the task */
char endpoint[512];
char model[256];
char key_env[64];
};
struct sp_config {
struct sp_delegate delegate[SP_CONFIG_MAX_DELEGATES];
size_t ndelegates;
struct sp_exit exit[SP_CONFIG_MAX_DELEGATES];
size_t nexits;
char endpoint[512];
char model[256];
char key_env[64];
char transport[32];
char theme[64];
char system_prompt[1024];
char session_dir[512];
char cli_cmd[512];
char locale[32]; /* language code, exported as SPLINTER_LOCALE */
char plugins[SP_CONFIG_MAX_PLUGINS][512];
size_t nplugins;
size_t steps; /* 0: not set */
size_t max_bytes; /* 0: not set */
int autonomous; /* -1 not set, 0 off, 1 on */
};
void sp_config_init(struct sp_config *);
/* Path of the file: $SPLINTER_CONFIG, else $XDG_CONFIG_HOME/splinter/config,
* else ~/.config/splinter/config. Returns 0 or -1 when no home is known. */
int sp_config_path(char *buf, size_t len);
/* Returns 0 when the file was read, -1 with a message otherwise. A missing
* file is reported as such: "not found" is different from "broken". */
int sp_config_load(struct sp_config *, const char *path, struct sp_buf *err);
/* Write a commented starter file. Returns 0 or -1. */
int sp_config_write_example(const char *path, struct sp_buf *err);
#endif /* SPLINTER_CONFIG_H */