Files
splinter/src/config.h
T
lotherkandClaude Opus 5.5 808039cd58 cli: the main transport falls back at the limit, too
cli_fallback = claude1, claude0 names cli delegates whose cmd and env=
take over when cli_cmd answers with its limit. The main command is
benched as "cli", a fallback under its own id, on the same bench the
delegation uses (sp_limit_parse, sp_cooldown_until, sp_cooldown_set are
now exported from libsplinter). The session key stays, so claude
resumes the same conversation under the next account. With everyone
benched the turn fails with the first reset, as WAIT_QUOTA ready_at=.

A fallback's env= goes through a 0600 file the shell sources, not a
command line. A delegate's child is benched under the delegate's id
(SPLINTER_CLI_ID), never as "cli".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:51:23 +00:00

138 lines
4.8 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
/*
* Extra environment for a program splinter starts: NAME=VALUE, set in the
* child right before exec. Lets two delegates run the same cli with two
* different accounts.
*/
#define SP_CONFIG_MAX_ENV 8
#define SP_CONFIG_ENV_LEN 512
/*
* 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 kind[16]; /* "openai" (default) or "cli" */
char cmd[256]; /* for kind=cli: the program, e.g. "claude -p" */
char key[256]; /* a literal key from the environment, if any */
char host[128]; /* ssh target; empty means this machine */
int prio; /* tie-break: higher wins */
int max_parallel; /* how many of these may run at once */
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];
char env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */
size_t nenv;
};
struct sp_config {
struct sp_delegate delegate[SP_CONFIG_MAX_DELEGATES];
size_t ndelegates;
char skills_dir[SP_CONFIG_MAX_DELEGATES][512];
size_t nskills_dir;
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 cli_env[SP_CONFIG_MAX_ENV][SP_CONFIG_ENV_LEN]; /* NAME=VALUE */
size_t ncli_env;
char cli_fallback[256]; /* cli delegate ids, comma separated */
char memory_url[512];
char memory_key_env[64];
char telegram_allow[256]; /* comma separated user ids */
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 */
long http_timeout; /* seconds for HTTP/SSE requests, 0: default */
long cli_timeout; /* seconds for cli transport, 0: default */
long delegate_timeout; /* seconds for delegate children, 0: default */
long run_timeout; /* seconds for the run tool, 0: default */
int autonomous; /* -1 not set, 0 off, 1 on */
/*
* Delegates built from environment tokens (CLAUDE_CODE_OAUTH_TOKEN and the
* numbered variants) are off unless asked for. An entry that appears because
* a variable happens to be exported competes for work nobody assigned it,
* and there is already an explicit cli delegate for the same program.
*/
int env_delegates;
};
void sp_config_init(struct sp_config *);
/*
* Providers from the environment: OLLAMA_KEY, OLLAMA_KEY_0..N and
* CLAUDE_CODE_OAUTH_TOKEN, _0..N. Each one becomes a delegate, so several keys
* mean several models to hand work to - and the Ollama ones also become exits,
* so a rate limit moves the ring instead of ending the turn.
*
* Returns how many entries were added.
*/
size_t sp_config_scan_env(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);
/* Set every NAME=VALUE of 'env' in this process, overwriting. */
void sp_config_apply_env(const char (*env)[SP_CONFIG_ENV_LEN], size_t n);
#endif /* SPLINTER_CONFIG_H */