delegates and cli_env: hardcoded environment per cli program; swarm, provider, planner, scheduler, tmux

env=NAME=VALUE on a delegate line (repeatable) is set in the child right
before exec and beats what the parent exported, so two delegates can run
the same cli with two accounts. Remotely it goes in front as
`env 'NAME=VALUE'`, quoted like the rest. cli_env = NAME=VALUE does the
same for the main cli transport. A bad name is an error with the line.

Also in this commit, the work in progress from the tree: swarm and
provider state, the provider/scheduler/planner/tmux plugins, the ui test,
whose tmux session name is now per run so parallel runs do not collide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Opus 5.5 committed 2026-11-09 19:15:48 +00:00
1 parent 25a616a87f
commit 75d8beeaa4
44 files changed
+5721 -1674

No files matched your search

+46 -23
View File
@@ -12,15 +12,19 @@
*
* Configuration is by environment, deliberately: no config file to drift.
*
* SPLINTER_CLI_CMD the program, default "claude -p"
* SPLINTER_CLI_CMD the program, default "claude -p". If it contains
* {file}, the prompt file path is substituted there;
* {prompt} substitutes a shell-quoted prompt. Without
* a placeholder the prompt is fed on stdin.
* SPLINTER_CLI_FULL=1 send the whole transcript instead of the last user
* message (the program keeps no history of its own)
* SPLINTER_CLI_TIMEOUT seconds, default 600
* SPLINTER_CLI_TIMEOUT seconds, default 1800
*
* Trust note, because it matters: the command runs through /bin/sh -c, so the
* string comes from the operator's environment, never from the model. Output is
* capped at 4 MiB and a non-zero exit is an error with the program's own
* stderr attached -- a silent empty answer is the one thing this must not do.
* string comes from the operator's environment, never from the model. Output
* grows dynamically (capped at 64 MiB) and a non-zero exit is an error with the
* program's own stderr attached -- a silent empty answer is the one thing this
* must not do.
*/
#include <errno.h>
#include <stdio.h>
@@ -33,7 +37,7 @@
#include "splinter_plugin.h"
#include "i18n.h"
#define OUT_CAP (4u << 20)
#define OUT_CAP (64u << 20)
struct cli_cfg {
char cmd[512];
@@ -123,18 +127,41 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
}
/*
* 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.
* The program reads the prompt on stdin unless the command names where it
* goes: {file} becomes the prompt file path, {prompt} becomes the prompt
* as a shell word. timeout guards a hang. stderr goes to a file next to
* the prompt so it never lands in the middle of a curses screen.
*/
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;
sp_buf_printf(&cmd, "timeout %s ", c->timeout);
if (strstr(c->cmd, "{file}") != NULL || strstr(c->cmd, "{prompt}") != NULL) {
const char *p = c->cmd;
while (*p != '\0') {
if (strncmp(p, "{file}", 6) == 0) {
if (sh_word(&cmd, path) != 0)
goto fail_build;
p += 6;
} else if (strncmp(p, "{prompt}", 8) == 0) {
if (sh_word(&cmd, body.p != NULL ? body.p : "") != 0)
goto fail_build;
p += 8;
} else if (sp_buf_add(&cmd, p, 1) != 0) {
goto fail_build;
} else
p++;
}
if (sp_buf_puts(&cmd, " 2> ") != 0 || sh_word(&cmd, errpath) != 0)
goto fail_build;
} else {
sp_buf_printf(&cmd, "%s < ", c->cmd);
if (sh_word(&cmd, path) != 0 || sp_buf_puts(&cmd, " 2> ") != 0 ||
sh_word(&cmd, errpath) != 0) {
fail_build:
unlink(path);
unlink(errpath);
goto fail;
}
}
p = popen(cmd.p, "r");
if (p == NULL) {
@@ -147,12 +174,8 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
size_t got;
while ((got = fread(chunk, 1, sizeof(chunk), p)) > 0) {
if (raw.len + got > OUT_CAP) {
sp_buf_puts(err, "cli: output over 4 MiB, aborted");
pclose(p);
unlink(path);
goto fail;
}
if (raw.len + got > OUT_CAP)
break;
if (sp_buf_add(&raw, chunk, got) != 0) {
pclose(p);
unlink(path);
@@ -225,7 +248,7 @@ cli_init(struct sp_host *h)
snprintf(cfg.cmd, sizeof(cfg.cmd), "%s",
cmd != NULL && *cmd != '\0' ? cmd : "claude -p");
snprintf(cfg.timeout, sizeof(cfg.timeout), "%s",
to != NULL && *to != '\0' ? to : "600");
to != NULL && *to != '\0' ? to : "1800");
cfg.full = full != NULL && strcmp(full, "0") != 0;
tr.send = cli_send;