splinter: delegates on other hosts, and the first-run interview
A delegate may name a host; the whole invocation then goes through ssh, so claude, opencode or another splinter run on that machine. delegate and delegate_parallel both honour it, and the report names the host like any other model. The environment does not cross the jump: a cli delegate carries its command explicitly (quoted, because ssh rejoins its arguments into one remote shell command), and the remote host supplies its own keys. Proven: a delegate with host=172.25.206.16 ran on olivia and answered through a provider only reachable over the wireguard link. --interview asks seven questions once - language, who you are, stack, style, what never to do, sacred paths - and writes ~/.splinter/profile/<user>.md. Enter skips a question and the skip is recorded as a skip. Starting the chat without a profile prints a hint. Two bugs found while testing: the stdin intake ate the interview's answers before it could ask, and the question texts carried literal \n because of how the file was written - both fixed and verified by running the interview with piped answers and reading the resulting profile.
This commit is contained in:
1 parent
e4f25b481f
commit
41662a7293
14 files changed
+207
-10
No files matched your search
@@ -23,7 +23,7 @@ CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
|
||||
LIB = libsplinter.so
|
||||
LIBOBJ = src/buf.o src/tool.o src/session.o src/conv.o src/transport.o \
|
||||
src/json.o src/sse.o src/openai.o src/transport_openai.o src/builtin.o \
|
||||
src/agent.o src/theme.o src/palettes.o src/decomp.o src/i18n.o src/delegate.o src/telegram.o src/log.o src/cmdscript.o src/folder.o src/mcpserver.o src/skills.o src/memory.o src/prompt.o src/config.o src/plugin.o
|
||||
src/agent.o src/theme.o src/palettes.o src/decomp.o src/i18n.o src/delegate.o src/telegram.o src/log.o src/cmdscript.o src/folder.o src/interview.o src/mcpserver.o src/skills.o src/memory.o src/prompt.o src/config.o src/plugin.o
|
||||
BIN = splinter
|
||||
BINOBJ = src/main.o src/ui.o
|
||||
PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
|
||||
@@ -108,6 +108,7 @@ src/telegram.o: include/splinter.h
|
||||
src/log.o: src/log.h
|
||||
src/cmdscript.o: src/cmdscript.h include/splinter.h
|
||||
src/folder.o: src/folder.h include/splinter.h
|
||||
src/interview.o: src/interview.h include/splinter.h
|
||||
src/mcpserver.o: src/mcpserver.h include/splinter.h
|
||||
src/skills.o: src/skills.h src/config.h include/splinter.h
|
||||
src/prompt.o: src/prompt.h include/splinter.h
|
||||
|
||||
@@ -184,6 +184,30 @@ key that `en.msg` has.
|
||||
|
||||
Ships with `en` and `de`. Plugins translate their own strings with `sp_t()`.
|
||||
|
||||
## Hosts: one fleet
|
||||
|
||||
A delegate may name a host. The whole invocation then goes through ssh, so
|
||||
claude, opencode or another splinter run where the model or the network is:
|
||||
|
||||
delegate = olivia | auf olivia | tags=remote | host=172.25.206.16 |
|
||||
endpoint=http://172.25.206.2:18082/v1/chat/completions | model=...
|
||||
|
||||
delegate and delegate_parallel both honour it, and the report names the host like
|
||||
any other model. The remote needs splinter at the same path and its own keys -
|
||||
nothing crosses the jump except the task.
|
||||
|
||||
Proven: a delegate with host=172.25.206.16 ran on olivia and answered from a
|
||||
provider reachable only over the wireguard link.
|
||||
|
||||
## First run: the interview
|
||||
|
||||
splinter --interview
|
||||
|
||||
Seven questions - language, who you are, stack, answering style, what never to
|
||||
do, which paths are sacred - written to `~/.splinter/profile/<user>.md`. Enter
|
||||
skips a question and the skip is recorded as such: an empty line would be a lie.
|
||||
Starting the chat without a profile prints a hint, once.
|
||||
|
||||
## Piped input
|
||||
|
||||
cat /etc/passwd | splinter "explain the file"
|
||||
|
||||
@@ -263,6 +263,7 @@ struct sp_host;
|
||||
int sp_telegram_run(struct sp_agent *, struct sp_host *host,
|
||||
const char *token, const char *allow, struct sp_buf *err);
|
||||
int sp_telegram_token(char *buf, size_t len, const char *path);
|
||||
const char *sp_memory_user(void);
|
||||
/*
|
||||
* Slash commands that are programs: <session dir>/commands/<name>. The program
|
||||
* gets the rest of the line, and its output becomes context for the model.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
+3
-1
@@ -175,7 +175,9 @@ parse_delegate(struct sp_delegate *d, const char *val, struct sp_buf *err,
|
||||
first = 0;
|
||||
continue;
|
||||
}
|
||||
if (!strncmp(s, "prio=", 5))
|
||||
if (!strncmp(s, "host=", 5))
|
||||
snprintf(d->host, sizeof(d->host), "%s", s + 5);
|
||||
else if (!strncmp(s, "prio=", 5))
|
||||
d->prio = (int)strtol(s + 5, NULL, 10);
|
||||
else if (!strncmp(s, "max_parallel=", 13)) {
|
||||
d->max_parallel = (int)strtol(s + 13, NULL, 10);
|
||||
|
||||
@@ -48,6 +48,7 @@ struct sp_delegate {
|
||||
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 */
|
||||
|
||||
+22
-7
@@ -127,6 +127,8 @@ choose(const struct sp_config *cfg, const char *task, const char *wanted,
|
||||
}
|
||||
|
||||
/* Run the child and collect its answer. */
|
||||
static void copy_answer(struct sp_buf *dst, const struct sp_buf *src);
|
||||
|
||||
static int
|
||||
run_child(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
const char *task, struct sp_buf *out, struct sp_buf *err)
|
||||
@@ -148,8 +150,8 @@ run_child(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
return -1;
|
||||
}
|
||||
if (child == 0) {
|
||||
char *argv[20];
|
||||
int n = 0;
|
||||
char *argv[24];
|
||||
int n = 0, remote = 0;
|
||||
int cli = strcmp(d->kind, "cli") == 0;
|
||||
char envname[96];
|
||||
|
||||
@@ -196,7 +198,9 @@ run_child(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
argv[n++] = "--max-bytes";
|
||||
argv[n++] = maxbuf;
|
||||
argv[n++] = "--autonomous";
|
||||
if (key_env != NULL) {
|
||||
if (remote)
|
||||
; /* the remote host has its own keys */
|
||||
else if (key_env != NULL) {
|
||||
argv[n++] = "--api-key-env";
|
||||
argv[n++] = (char *)key_env;
|
||||
} else if (d->key[0] != '\0') {
|
||||
@@ -357,7 +361,10 @@ tool_delegate(const char *args, struct sp_buf *out, void *ctx)
|
||||
if (slot < SP_CONFIG_MAX_DELEGATES && running[slot] > 0)
|
||||
running[slot]--;
|
||||
}
|
||||
sp_buf_printf(out, "%s", reply.p != NULL ? reply.p : "(no answer)");
|
||||
if (reply.p != NULL)
|
||||
copy_answer(out, &reply);
|
||||
else
|
||||
sp_buf_puts(out, "(no answer)\n");
|
||||
sp_buf_free(&reply);
|
||||
sp_buf_free(&err);
|
||||
sp_buf_free(&keep);
|
||||
@@ -440,8 +447,8 @@ spawn_job(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
return -1;
|
||||
}
|
||||
if (child == 0) {
|
||||
char *argv[20];
|
||||
int n = 0;
|
||||
char *argv[24];
|
||||
int n = 0, remote = 0;
|
||||
int cli = strcmp(d->kind, "cli") == 0;
|
||||
char maxbuf[32];
|
||||
|
||||
@@ -450,6 +457,14 @@ spawn_job(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
close(fds[0]);
|
||||
close(fds[1]);
|
||||
snprintf(maxbuf, sizeof(maxbuf), "%d", DELEGATE_MAX_BYTES);
|
||||
if (d->host[0] != '\0') {
|
||||
argv[n++] = "ssh";
|
||||
argv[n++] = "-o";
|
||||
argv[n++] = "BatchMode=yes";
|
||||
argv[n++] = (char *)d->host;
|
||||
argv[n++] = "--";
|
||||
remote = 1;
|
||||
}
|
||||
argv[n++] = (char *)c->self;
|
||||
argv[n++] = "--no-config";
|
||||
argv[n++] = "-p";
|
||||
@@ -482,7 +497,7 @@ spawn_job(const struct del_ctx *c, const struct sp_delegate *d,
|
||||
argv[n++] = "--max-bytes";
|
||||
argv[n++] = maxbuf;
|
||||
argv[n++] = "--autonomous";
|
||||
if (d->key[0] != '\0' && !cli) {
|
||||
if (d->key[0] != '\0' && !cli && !remote) {
|
||||
char envname[96];
|
||||
|
||||
snprintf(envname, sizeof(envname),
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* splinter -- the first conversation.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* A harness that knows nothing about the person in front of it guesses on every
|
||||
* turn. So the first time splinter runs for a user, it asks - once - and writes
|
||||
* the answers where they are read at start:
|
||||
*
|
||||
* ~/.splinter/profile/<user>.md
|
||||
*
|
||||
* Plain questions on the terminal, no curses, no model in the loop: the answers
|
||||
* are facts about the operator and should not depend on a model's mood. Enter
|
||||
* skips a question, and a skipped question is recorded as skipped - an empty
|
||||
* line in a profile is a lie, "not answered" is information.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "splinter.h"
|
||||
#include "interview.h"
|
||||
|
||||
#define ANSWER_MAX 4096
|
||||
|
||||
struct question {
|
||||
const char *key;
|
||||
const char *prompt;
|
||||
const char *hint;
|
||||
};
|
||||
|
||||
static const struct question questions[] = {
|
||||
{ "language", "In welcher Sprache soll ich mit dir reden?",
|
||||
"z.B. deutsch, english, portugues" },
|
||||
{ "about", "Wer bist du und woran arbeitest du gerade?",
|
||||
"zwei Saetze reichen" },
|
||||
{ "stack", "Welche Sprachen und Werkzeuge benutzt du am liebsten?",
|
||||
"z.B. C99/POSIX, kein Python, Make statt CMake" },
|
||||
{ "style", "Wie soll ich antworten?",
|
||||
"kurz/lang, mit oder ohne Begruendung, Code zuerst?" },
|
||||
{ "never", "Was soll ich NIE tun?",
|
||||
"z.B. keine Commits ohne Auftrag, nichts in /tmp" },
|
||||
{ "paths", "Welche Pfade sind heilig oder gefaehrlich?",
|
||||
"z.B. /home/carol nie anfassen" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
const char *
|
||||
sp_profile_path(const char *session_dir, char *buf, size_t len)
|
||||
{
|
||||
if (session_dir == NULL || *session_dir == '\0')
|
||||
return NULL;
|
||||
snprintf(buf, len, "%s/profile", session_dir);
|
||||
return buf;
|
||||
}
|
||||
|
||||
int
|
||||
sp_profile_exists(const char *session_dir)
|
||||
{
|
||||
char dir[600], path[700];
|
||||
const char *user = sp_memory_user();
|
||||
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL)
|
||||
return 0;
|
||||
snprintf(path, sizeof(path), "%s/%s.md", dir, user);
|
||||
return access(path, R_OK) == 0;
|
||||
}
|
||||
|
||||
int
|
||||
sp_interview_run(const char *session_dir, struct sp_buf *err)
|
||||
{
|
||||
char dir[600], path[700];
|
||||
const char *user = sp_memory_user();
|
||||
FILE *f;
|
||||
size_t i;
|
||||
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL) {
|
||||
sp_buf_puts(err, "interview: no session directory");
|
||||
return -1;
|
||||
}
|
||||
(void)mkdir(dir, 0700);
|
||||
snprintf(path, sizeof(path), "%s/%s.md", dir, user);
|
||||
f = fopen(path, "w");
|
||||
if (f == NULL) {
|
||||
sp_buf_printf(err, "interview: cannot write %s", path);
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "# Profile: %s\n\n", user);
|
||||
fprintf(f, "_Written by `splinter --interview`. Edit it by hand whenever you "
|
||||
"like; splinter reads it at start._\n\n");
|
||||
|
||||
printf("Erstes Gespraech fuer '%s'. Enter ueberspringt eine Frage, "
|
||||
"Ctrl-D bricht ab.\n\n", user);
|
||||
for (i = 0; questions[i].key != NULL; i++) {
|
||||
char answer[ANSWER_MAX];
|
||||
size_t len;
|
||||
|
||||
printf("%s\n (%s)\n> ", questions[i].prompt, questions[i].hint);
|
||||
fflush(stdout);
|
||||
if (fgets(answer, sizeof(answer), stdin) == NULL)
|
||||
break;
|
||||
len = strcspn(answer, "\r\n");
|
||||
answer[len] = '\0';
|
||||
fprintf(f, "## %s\n", questions[i].key);
|
||||
if (len == 0)
|
||||
fprintf(f, "(nicht beantwortet)\n\n");
|
||||
else
|
||||
fprintf(f, "%s\n\n", answer);
|
||||
}
|
||||
fclose(f);
|
||||
printf("\nGeschrieben: %s\n", path);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* splinter -- the first conversation.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef SPLINTER_INTERVIEW_H
|
||||
#define SPLINTER_INTERVIEW_H
|
||||
|
||||
#include "splinter.h"
|
||||
|
||||
const char *sp_profile_path(const char *session_dir, char *buf, size_t len);
|
||||
int sp_profile_exists(const char *session_dir);
|
||||
int sp_interview_run(const char *session_dir, struct sp_buf *err);
|
||||
|
||||
#endif /* SPLINTER_INTERVIEW_H */
|
||||
+22
-1
@@ -24,6 +24,7 @@
|
||||
#include "prompt.h"
|
||||
#include "folder.h"
|
||||
#include "mcpserver.h"
|
||||
#include "interview.h"
|
||||
#include "splinter_plugin.h"
|
||||
#include "theme.h"
|
||||
#include "ui.h"
|
||||
@@ -54,6 +55,8 @@ usage(FILE *f)
|
||||
" --no-stdin ignore data on standard input\n"
|
||||
" -c, --continue continue the last session started in this "
|
||||
"directory\n"
|
||||
" --interview ask the first-run questions and write the "
|
||||
"profile\n"
|
||||
" --mcp-server-listen IP serve MCP on IP (tools of this "
|
||||
"registry)\n"
|
||||
" --mcp-listen-port N MCP port, default 8098\n"
|
||||
@@ -199,6 +202,7 @@ main(int argc, char **argv)
|
||||
int have_mock = 0;
|
||||
int i, rc, chatmode = 0, resume = 0;
|
||||
int daemon_mode = 0, no_stdin = 0, continue_here = 0;
|
||||
int interview = 0;
|
||||
const char *mcp_ip = NULL;
|
||||
int mcp_port = 8098;
|
||||
struct sp_config conf;
|
||||
@@ -273,6 +277,8 @@ main(int argc, char **argv)
|
||||
choose_text = argv[++i];
|
||||
} else if (!strcmp(argv[i], "--daemon")) {
|
||||
daemon_mode = 1;
|
||||
} else if (!strcmp(argv[i], "--interview")) {
|
||||
interview = 1;
|
||||
} else if (!strcmp(argv[i], "--mcp-server-listen")) {
|
||||
if (i + 1 >= argc) {
|
||||
fprintf(stderr, "splinter: --mcp-server-listen "
|
||||
@@ -350,7 +356,9 @@ main(int argc, char **argv)
|
||||
int is_binary = 0, have_stdin = 0;
|
||||
size_t raw = 0;
|
||||
|
||||
if (!no_stdin && !chatmode && !daemon_mode && !isatty(STDIN_FILENO) &&
|
||||
/* the interview asks its questions on stdin: leave it alone */
|
||||
if (!no_stdin && !chatmode && !daemon_mode && !interview &&
|
||||
!isatty(STDIN_FILENO) &&
|
||||
sp_buf_init(&intake) == 0) {
|
||||
if (read_stdin_block(&intake, &is_binary, &raw) == 0 &&
|
||||
raw > 0)
|
||||
@@ -568,6 +576,15 @@ main(int argc, char **argv)
|
||||
}
|
||||
ag.sess = &sess;
|
||||
(void)sp_log_open(sess.dir, sess.id);
|
||||
if (interview) {
|
||||
rc = sp_interview_run(sess.dir, &err);
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "splinter: %s\n", err.p != NULL ? err.p :
|
||||
"interview failed");
|
||||
return rc == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
sp_logf("session", "started: %s", sess.id);
|
||||
|
||||
|
||||
@@ -721,6 +738,10 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (chatmode) {
|
||||
if (!sp_profile_exists(sess.dir))
|
||||
fprintf(stderr, "splinter: kein Profil fuer '%s' - "
|
||||
"`splinter --interview` legt eins an\n",
|
||||
sp_memory_user());
|
||||
rc = sp_ui_run(&ag, endpoint, theme, host);
|
||||
if (have_mock)
|
||||
sp_mock_free(&mock);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user