interview: the model talks to the user, USER.txt rides in the prompt
The six-question form is gone. `splinter --interview` now opens the chat with an interview system prompt: get to know the person, one question at a time, then write a compact summary and end with INTERVIEW_COMPLETE. - the marker is captured in the engine's turn thread and in the synchronous -p path: the summary before it is written to ~/.splinter/USER.txt (0600), the marker is stripped from the answer and the conversation, and a "interview saved to USER.txt" note goes into the transcript. An installation from before USER.txt keeps working: profile/<user>.md is the fallback until the first new interview. - the USER.txt text is appended to the system prompt of every later session (plain "What you know about the user" block), including after /new and an agent switch (it rides in base_prompt). - --interview is a chat mode with the interview prompt and no agent profiles; it needs a provider like any chat. - Telegram: /interview swaps the system prompt, starts the conversation and restores the normal prompt once the summary is captured. The initial turn and every later reply are checked, so a model that summarizes immediately also works. - test_interview.sh now proves capture, marker-free USER.txt and the summary in the next request; test_gateway drives /interview and the fake model answers with the marker when the interview prompt is in the request. - docs (README, PLUGINS) describe the new flow. make check: all tests passed.
This commit is contained in:
1 parent
8aad48b928
commit
1e15c91e4e
14 files changed
+424
-367
No files matched your search
@@ -464,12 +464,20 @@ processes that share a working directory — not A2A, and not a network protocol
|
||||
|
||||
splinter --interview
|
||||
|
||||
Six questions - language, who you are, stack, answering style, what never to
|
||||
do, which paths are sacred - written to `~/.splinter/profile/<user>.md`. The
|
||||
questions come from the catalogue: the default is English, `locale = de` (or
|
||||
`SPLINTER_LOCALE`) makes them German. 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.
|
||||
No questionnaire: the model talks to you. Its system prompt says to get to know
|
||||
you - what you work on, the tools you reach for, how you want to be spoken to,
|
||||
what you never want - one question at a time, and to end with a compact summary
|
||||
followed by the single line `INTERVIEW_COMPLETE`.
|
||||
|
||||
That summary is written to `~/.splinter/USER.txt` (0600) and put into the system
|
||||
prompt of every later session, so the harness starts out knowing who it is
|
||||
working with. The marker itself never reaches the file or the transcript. The
|
||||
interview needs a provider like any chat; Telegram has the same `/interview`,
|
||||
with the conversation in the chat.
|
||||
|
||||
An installation from before `USER.txt` still has `~/.splinter/profile/<user>.md`;
|
||||
it is read as the fallback until the first new interview. Starting the chat
|
||||
without either prints a hint, once.
|
||||
|
||||
## Piped input
|
||||
|
||||
@@ -549,8 +557,8 @@ endpoint. It writes the line to `<config>.d/20-connect.conf`, so the next start
|
||||
has the provider too, runs one tiny turn against it to prove endpoint, model
|
||||
and key work, and offers to use it right away.
|
||||
|
||||
`/interview` asks the same six questions as `splinter --interview`, one
|
||||
message per answer; `/skip` skips one and `/cancel` stops. A program in
|
||||
`/interview` starts the same model-driven interview as `splinter --interview`
|
||||
in the chat; `/new` leaves it. A program in
|
||||
`commands/` answers in the chat: its output is the reply. In the
|
||||
TUI the same program's output becomes context for the model instead. A typo
|
||||
such as `/nosuch` is answered with the command list, not sent to the model.
|
||||
|
||||
+2
-2
@@ -378,8 +378,8 @@ Ein Timeout ist ein Nein. Stille ist keine Zustimmung.
|
||||
Das Telegram-Gateway registriert seine Befehle beim Start: die der geladenen
|
||||
Plugins, die Programme in `~/.splinter/commands/` mit gueltigem Telegram-Namen
|
||||
und `/start`, `/help`, `/interview`; `/help` listet sie im Chat. `/interview`
|
||||
stellt dieselben sechs Fragen wie `splinter --interview` im Chat, `/skip`
|
||||
ueberspringt eine, `/cancel` bricht ab. Die Anfrage selbst legt es als
|
||||
startet dasselbe modellgetriebene Interview wie `splinter --interview` im Chat;
|
||||
die Zusammenfassung landet in `~/.splinter/USER.txt`, `/new` beendet es. Die Anfrage selbst legt es als
|
||||
Nachricht mit **Ja/Nein-Knoepfen** vor.
|
||||
Der Knopf ist ein `callback_query`, kein Text: das Gateway prueft denselben
|
||||
Allow-List-Eintrag, antwortet dem Knopf, entfernt die Knoepfe und legt die
|
||||
|
||||
@@ -68,6 +68,7 @@ struct sp_engine_opts {
|
||||
int resume; /* load the session's history */
|
||||
int continue_last; /* -c: newest session in this cwd */
|
||||
int no_transport; /* tools only (MCP server, delegate) */
|
||||
int interview; /* the model interviews the user */
|
||||
int swarm; /* join the local fleet */
|
||||
};
|
||||
|
||||
|
||||
@@ -252,3 +252,7 @@ status.meter_value = ctx %zu/%zu, Cache %zu, Tok %zu/%zu
|
||||
status.bar = Leiste
|
||||
status.swarm = Schwarm
|
||||
status.swarm_value = %s (Id %d)
|
||||
|
||||
interview.system = Du bist splinter und arbeitest zum ersten Mal mit dieser Person. Interview sie, um sie kennenzulernen: woran sie arbeitet, welche Werkzeuge und Sprachen sie nutzt, wie sie angesprochen werden will, was sie nie will und welche Projekte zaehlen. Stelle eine Frage auf einmal, hoere zu und gehe nach, wo es wichtig ist. Frage nicht nach Codedetails, die du im Repository lesen kannst. Wenn du genug hast, schreibe eine kompakte Zusammenfassung der Person und ihrer Arbeitsweise (ein paar Absaetze oder Punkte) und beende deine Antwort mit der einen Zeile INTERVIEW_COMPLETE. Diese Zusammenfassung wird in ~/.splinter/USER.txt gespeichert und am Anfang jeder spaeteren Sitzung gelesen.
|
||||
interview.saved = Interview in USER.txt gespeichert
|
||||
tg.interview.begin = Interview gestartet. Beantworte die Fragen des Modells; /new beendet das Interview.
|
||||
@@ -251,3 +251,7 @@ status.meter_value = ctx %zu/%zu, cache %zu, tok %zu/%zu
|
||||
status.bar = bar
|
||||
status.swarm = swarm
|
||||
status.swarm_value = %s (id %d)
|
||||
|
||||
interview.system = You are splinter, about to work with this person for the first time. Interview them to get to know them: what they work on, the tools and languages they reach for, how they want to be spoken to, what they never want, and which projects matter. Ask one question at a time, listen, and go deeper where it matters. Do not ask about code details you can read from the repository. When you have enough, write a compact summary of the person and how they want to work (a few paragraphs or bullets), then end your answer with the single line INTERVIEW_COMPLETE. That summary is saved to ~/.splinter/USER.txt and read at the start of every later session.
|
||||
interview.saved = interview saved to USER.txt
|
||||
tg.interview.begin = Interview started. Answer the model's questions; /new leaves the interview.
|
||||
@@ -255,3 +255,7 @@ status.meter_value = ctx %zu/%zu, cache %zu, tok %zu/%zu
|
||||
status.bar = barra
|
||||
status.swarm = enxame
|
||||
status.swarm_value = %s (id %d)
|
||||
|
||||
interview.system = Voce e o splinter e vai trabalhar com esta pessoa pela primeira vez. Entreviste-a para conhece-la: no que trabalha, quais ferramentas e linguagens usa, como quer ser tratada, o que nunca quer e quais projetos importam. Faca uma pergunta por vez, escute e aprofunde onde importa. Nao pergunte detalhes de codigo que voce pode ler no repositorio. Quando tiver o suficiente, escreva um resumo compacto da pessoa e de como ela quer trabalhar (alguns paragrafos ou pontos) e termine sua resposta com a linha unica INTERVIEW_COMPLETE. Esse resumo e salvo em ~/.splinter/USER.txt e lido no inicio de cada sessao posterior.
|
||||
interview.saved = entrevista salva em USER.txt
|
||||
tg.interview.begin = Entrevista iniciada. Responda as perguntas do modelo; /new encerra a entrevista.
|
||||
+79
-1
@@ -29,6 +29,7 @@
|
||||
#include "splinter_engine.h"
|
||||
#include "splinter_plugin.h"
|
||||
#include "agents.h"
|
||||
#include "interview.h"
|
||||
#include "cmdscript.h"
|
||||
#include "config.h"
|
||||
#include "folder.h"
|
||||
@@ -201,6 +202,7 @@ sp_engine_event_free(struct sp_event *ev)
|
||||
}
|
||||
|
||||
static void snapshot_stats(struct sp_engine *);
|
||||
static int capture_interview(struct sp_engine *, struct sp_buf *);
|
||||
|
||||
/* ------------------------------------------------------------- snapshot */
|
||||
|
||||
@@ -959,6 +961,13 @@ turn_thread(void *arg)
|
||||
sp_buf_clear(&e->steer);
|
||||
}
|
||||
pthread_mutex_unlock(&e->lock);
|
||||
if (rc == 0 && capture_interview(e, &e->answer)) {
|
||||
char note[700];
|
||||
|
||||
snprintf(note, sizeof(note), sp_td("interview.saved",
|
||||
"interview saved to USER.txt"));
|
||||
ev_push(e, SP_EV_ENTRY, 0, "splinter", note);
|
||||
}
|
||||
ev_push(e, SP_EV_TURN_END, rc,
|
||||
e->answer.p != NULL ? e->answer.p : "",
|
||||
e->err.p != NULL ? e->err.p : "");
|
||||
@@ -1192,6 +1201,38 @@ engine_join(struct sp_engine *e)
|
||||
* One synchronous request: what -p, the slash prompt and a test want. No
|
||||
* queue, no thread; the caller's stream callback sees the text as it arrives.
|
||||
*/
|
||||
/*
|
||||
* The answer that ends with INTERVIEW_COMPLETE: save the summary to USER.txt
|
||||
* (once), keep the marker out of the answer and the conversation, and say so.
|
||||
* Both paths - the turn thread and the synchronous -p path - end here.
|
||||
*/
|
||||
static int
|
||||
capture_interview(struct sp_engine *e, struct sp_buf *answer)
|
||||
{
|
||||
char clean[16384];
|
||||
size_t k;
|
||||
|
||||
if (answer == NULL || answer->p == NULL)
|
||||
return 0;
|
||||
if (!sp_interview_capture(e->sess.dir, answer->p, clean,
|
||||
sizeof(clean)))
|
||||
return 0;
|
||||
sp_buf_clear(answer);
|
||||
(void)sp_buf_puts(answer, clean);
|
||||
for (k = e->conv.n; k > 0; k--)
|
||||
if (e->conv.v[k - 1].role != NULL &&
|
||||
strcmp(e->conv.v[k - 1].role, "assistant") == 0) {
|
||||
char *c2 = strdup(clean);
|
||||
|
||||
if (c2 != NULL) {
|
||||
free(e->conv.v[k - 1].content);
|
||||
e->conv.v[k - 1].content = c2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
sp_engine_prompt(struct sp_engine *e, const char *text, sp_stream_cb stream,
|
||||
void *stream_ctx, struct sp_buf *answer, struct sp_buf *err)
|
||||
@@ -1216,6 +1257,8 @@ sp_engine_prompt(struct sp_engine *e, const char *text, sp_stream_cb stream,
|
||||
e->ag.cfg = &cfg;
|
||||
rc = sp_agent_run(&e->ag, text, answer, err);
|
||||
e->ag.cfg = &e->base;
|
||||
if (rc == 0)
|
||||
(void)capture_interview(e, answer);
|
||||
snapshot_stats(e);
|
||||
return rc;
|
||||
}
|
||||
@@ -2309,6 +2352,8 @@ setup_conversation(struct sp_engine *e, const struct sp_engine_opts *o,
|
||||
size_t loaded = 0;
|
||||
|
||||
sp_conv_init(&e->conv);
|
||||
if (o->interview)
|
||||
e->base.system_prompt = sp_interview_system();
|
||||
sp_prompt_expand(e->base.system_prompt, e->prompt_expanded,
|
||||
sizeof(e->prompt_expanded), o->model);
|
||||
e->base.system_prompt = e->prompt_expanded;
|
||||
@@ -2414,11 +2459,44 @@ sp_engine_open(struct sp_engine **out, const struct sp_engine_opts *o,
|
||||
e->ag.cfg = &e->base;
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
cwd[0] = '\0';
|
||||
if (sp_agents_load(&e->agents, cwd, getenv("HOME")) != 0) {
|
||||
if (!o->interview &&
|
||||
sp_agents_load(&e->agents, cwd, getenv("HOME")) != 0) {
|
||||
sp_buf_puts(err, "cannot load the agent profiles");
|
||||
goto fail;
|
||||
}
|
||||
e->base_prompt = sp_agents_base(&e->conv);
|
||||
{
|
||||
/*
|
||||
* What the interview learned about the user rides in the system
|
||||
* prompt of every session, not in a tool the model has to call.
|
||||
*/
|
||||
char *ub = sp_interview_user_block(e->sess.dir);
|
||||
|
||||
if (ub != NULL) {
|
||||
size_t bl = e->base_prompt != NULL ?
|
||||
strlen(e->base_prompt) : 0;
|
||||
char *nb = malloc(bl + strlen(ub) + 1);
|
||||
|
||||
if (nb != NULL) {
|
||||
snprintf(nb, bl + strlen(ub) + 1, "%s%s",
|
||||
e->base_prompt != NULL ? e->base_prompt : "",
|
||||
ub);
|
||||
free(e->base_prompt);
|
||||
e->base_prompt = nb;
|
||||
}
|
||||
free(ub);
|
||||
}
|
||||
}
|
||||
if (e->agents.n == 0 && e->base_prompt != NULL && e->conv.n > 0 &&
|
||||
e->conv.v[0].role != NULL &&
|
||||
strcmp(e->conv.v[0].role, "system") == 0) {
|
||||
char *copy = strdup(e->base_prompt);
|
||||
|
||||
if (copy != NULL) {
|
||||
free(e->conv.v[0].content);
|
||||
e->conv.v[0].content = copy;
|
||||
}
|
||||
}
|
||||
if (e->agents.n > 0) {
|
||||
char saved[48];
|
||||
|
||||
|
||||
+135
-140
@@ -1,20 +1,18 @@
|
||||
/*
|
||||
* splinter -- the first conversation.
|
||||
* splinter -- the first conversation, and what it leaves behind.
|
||||
*
|
||||
* 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.
|
||||
* No questionnaire: the model talks to the user, one question at a time, about
|
||||
* whatever it needs to know to work well with them. When it has enough it
|
||||
* writes a summary and ends the answer with INTERVIEW_COMPLETE; that summary
|
||||
* goes to ~/.splinter/USER.txt and is put into the system prompt of every later
|
||||
* session. Facts about the operator should be the operator's, in one readable
|
||||
* file, not six fields a plugin guessed.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -25,146 +23,143 @@
|
||||
#include "i18n.h"
|
||||
#include "interview.h"
|
||||
|
||||
#define ANSWER_MAX 4096
|
||||
#define USER_FILE "USER.txt"
|
||||
#define USER_MAX (16 * 1024)
|
||||
#define DONE_LINE "INTERVIEW_COMPLETE"
|
||||
|
||||
/*
|
||||
* The keys are the profile schema and stay in English; the prompt and hint are
|
||||
* catalogue keys, so the same questions come out in the process language for
|
||||
* the terminal and the Telegram chat alike.
|
||||
*/
|
||||
struct question {
|
||||
const char *key;
|
||||
const char *prompt_key;
|
||||
const char *hint_key;
|
||||
};
|
||||
|
||||
static const struct question questions[] = {
|
||||
{ "language", "interview.q.language", "interview.h.language" },
|
||||
{ "about", "interview.q.about", "interview.h.about" },
|
||||
{ "stack", "interview.q.stack", "interview.h.stack" },
|
||||
{ "style", "interview.q.style", "interview.h.style" },
|
||||
{ "never", "interview.q.never", "interview.h.never" },
|
||||
{ "paths", "interview.q.paths", "interview.h.paths" },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
#define INTERVIEW_MAX 16
|
||||
|
||||
size_t
|
||||
sp_interview_count(void)
|
||||
static const char *
|
||||
user_path(const char *dir, char *buf, size_t cap)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; questions[i].key != NULL; i++)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_interview_prompt(size_t i)
|
||||
{
|
||||
return i < sp_interview_count() ? sp_t(questions[i].prompt_key) : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_interview_hint(size_t i)
|
||||
{
|
||||
return i < sp_interview_count() ? sp_t(questions[i].hint_key) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the profile from answers collected by a front end. A short answer list
|
||||
* (Ctrl-D, /cancel after a few questions) still writes what was answered; a
|
||||
* missing answer is recorded as "not answered", not as an empty line.
|
||||
*/
|
||||
int
|
||||
sp_interview_save(const char *session_dir, const char *const *answers, size_t n,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
char dir[600], path[700];
|
||||
const char *user = sp_user_name();
|
||||
FILE *f;
|
||||
size_t i, max = sp_interview_count();
|
||||
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL) {
|
||||
sp_buf_puts(err, sp_t("interview.error.nodir"));
|
||||
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, sp_t("interview.error.write"), path);
|
||||
return -1;
|
||||
}
|
||||
fprintf(f, "# Profile: %s\n\n", user);
|
||||
fprintf(f, "%s\n\n", sp_t("interview.header"));
|
||||
if (n > max)
|
||||
n = max;
|
||||
for (i = 0; i < n; i++) {
|
||||
fprintf(f, "## %s\n", questions[i].key);
|
||||
if (answers == NULL || answers[i] == NULL ||
|
||||
answers[i][0] == '\0')
|
||||
fprintf(f, "%s\n\n", sp_t("interview.skipped"));
|
||||
else
|
||||
fprintf(f, "%s\n\n", answers[i]);
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_profile_path(const char *session_dir, char *buf, size_t len)
|
||||
{
|
||||
if (session_dir == NULL || *session_dir == '\0')
|
||||
if (dir == NULL || *dir == '\0')
|
||||
return NULL;
|
||||
snprintf(buf, len, "%s/profile", session_dir);
|
||||
snprintf(buf, cap, "%s/%s", dir, USER_FILE);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *
|
||||
sp_interview_system(void)
|
||||
{
|
||||
return sp_td("interview.system",
|
||||
"You are splinter, about to work with this person for the first "
|
||||
"time. Interview them to get to know them: what they work on, the "
|
||||
"tools and languages they reach for, how they want to be spoken "
|
||||
"to, what they never want, and which projects matter. Ask one "
|
||||
"question at a time, listen, and go deeper where it matters. Do "
|
||||
"not ask about code details you can read from the repository. "
|
||||
"When you have enough, write a compact summary of the person and "
|
||||
"how they want to work (a few paragraphs or bullets), then end "
|
||||
"your answer with the single line INTERVIEW_COMPLETE. That "
|
||||
"summary is saved to ~/.splinter/USER.txt and read at the start "
|
||||
"of every later session.");
|
||||
}
|
||||
|
||||
char *
|
||||
sp_interview_user_block(const char *session_dir)
|
||||
{
|
||||
char path[700];
|
||||
FILE *f;
|
||||
struct sp_buf b;
|
||||
char chunk[4096];
|
||||
size_t n;
|
||||
|
||||
if (user_path(session_dir, path, sizeof(path)) == NULL)
|
||||
return NULL;
|
||||
f = fopen(path, "r");
|
||||
if (f == NULL) {
|
||||
/* an installation from before USER.txt still has the profile */
|
||||
snprintf(path, sizeof(path), "%s/profile/%s.md", session_dir,
|
||||
sp_user_name());
|
||||
f = fopen(path, "r");
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
}
|
||||
if (sp_buf_init(&b) != 0) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
while ((n = fread(chunk, 1, sizeof(chunk), f)) > 0 &&
|
||||
b.len < USER_MAX)
|
||||
if (sp_buf_add(&b, chunk, n) != 0)
|
||||
break;
|
||||
fclose(f);
|
||||
if (b.len == 0) {
|
||||
sp_buf_free(&b);
|
||||
return NULL;
|
||||
}
|
||||
{
|
||||
struct sp_buf out;
|
||||
|
||||
if (sp_buf_init(&out) != 0) {
|
||||
sp_buf_free(&b);
|
||||
return NULL;
|
||||
}
|
||||
if (sp_buf_puts(&out, "\n\nWhat you know about the user "
|
||||
"(from the interview):\n") != 0 ||
|
||||
sp_buf_add(&out, b.p, b.len) != 0) {
|
||||
sp_buf_free(&b);
|
||||
sp_buf_free(&out);
|
||||
return NULL;
|
||||
}
|
||||
sp_buf_free(&b);
|
||||
return out.p;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
sp_interview_capture(const char *session_dir, const char *answer, char *clean,
|
||||
size_t cap)
|
||||
{
|
||||
char path[700], tmp[800];
|
||||
const char *mark;
|
||||
FILE *f;
|
||||
size_t n;
|
||||
|
||||
if (session_dir == NULL || *session_dir == '\0' || answer == NULL ||
|
||||
clean == NULL || cap == 0)
|
||||
return 0;
|
||||
mark = strstr(answer, DONE_LINE);
|
||||
if (mark == NULL)
|
||||
return 0;
|
||||
n = (size_t)(mark - answer);
|
||||
while (n > 0 && (answer[n - 1] == '\n' || answer[n - 1] == '\r' ||
|
||||
answer[n - 1] == ' ' || answer[n - 1] == '\t'))
|
||||
n--;
|
||||
if (n == 0)
|
||||
return 0;
|
||||
snprintf(clean, cap, "%.*s", (int)(n < cap ? n : cap - 1), answer);
|
||||
if (user_path(session_dir, path, sizeof(path)) == NULL)
|
||||
return 0;
|
||||
snprintf(tmp, sizeof(tmp), "%s.tmp", path);
|
||||
f = fopen(tmp, "w");
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
if (fprintf(f, "%s\n", clean) < 0 || fclose(f) != 0) {
|
||||
(void)unlink(tmp);
|
||||
return 0;
|
||||
}
|
||||
(void)chmod(tmp, 0600);
|
||||
if (rename(tmp, path) != 0) {
|
||||
(void)unlink(tmp);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
sp_profile_exists(const char *session_dir)
|
||||
{
|
||||
char dir[600], path[700];
|
||||
const char *user = sp_user_name();
|
||||
char path[700];
|
||||
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL)
|
||||
if (user_path(session_dir, path, sizeof(path)) == NULL)
|
||||
return 0;
|
||||
snprintf(path, sizeof(path), "%s/%s.md", dir, user);
|
||||
return access(path, R_OK) == 0;
|
||||
}
|
||||
if (access(path, F_OK) == 0)
|
||||
return 1;
|
||||
/* an installation from before USER.txt: profile/<user>.md */
|
||||
{
|
||||
char dir[700];
|
||||
const char *user = sp_user_name();
|
||||
|
||||
int
|
||||
sp_interview_run(const char *session_dir, struct sp_buf *err)
|
||||
{
|
||||
static char answers[INTERVIEW_MAX][ANSWER_MAX];
|
||||
const char *ptrs[INTERVIEW_MAX];
|
||||
char dir[600], path[700];
|
||||
const char *user = sp_user_name();
|
||||
size_t i, n = sp_interview_count();
|
||||
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) == NULL) {
|
||||
sp_buf_puts(err, sp_t("interview.error.nodir"));
|
||||
return -1;
|
||||
snprintf(dir, sizeof(dir), "%s/profile/%s.md", session_dir, user);
|
||||
return access(dir, F_OK) == 0;
|
||||
}
|
||||
snprintf(path, sizeof(path), "%s/%s.md", dir, user);
|
||||
if (n > INTERVIEW_MAX)
|
||||
n = INTERVIEW_MAX;
|
||||
printf(sp_t("interview.intro"), user);
|
||||
printf("\n\n");
|
||||
for (i = 0; i < n; i++) {
|
||||
printf("%s\n (%s)\n> ", sp_interview_prompt(i),
|
||||
sp_interview_hint(i));
|
||||
fflush(stdout);
|
||||
if (fgets(answers[i], sizeof(answers[i]), stdin) == NULL)
|
||||
break;
|
||||
answers[i][strcspn(answers[i], "\r\n")] = '\0';
|
||||
ptrs[i] = answers[i];
|
||||
}
|
||||
if (sp_interview_save(session_dir, ptrs, i, err) != 0)
|
||||
return -1;
|
||||
printf("\n");
|
||||
printf(sp_t("interview.written"), path);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
+22
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* splinter -- the first conversation.
|
||||
* splinter -- the first conversation, and what it leaves behind.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
@@ -7,17 +7,29 @@
|
||||
#ifndef SPLINTER_INTERVIEW_H
|
||||
#define SPLINTER_INTERVIEW_H
|
||||
|
||||
#include <stddef.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);
|
||||
/*
|
||||
* The interview is a model-driven conversation: the system prompt tells the
|
||||
* model to get to know the user and end with INTERVIEW_COMPLETE. The summary
|
||||
* before that line is written to <session dir>/USER.txt and read at the start
|
||||
* of every later session.
|
||||
*/
|
||||
const char *sp_interview_system(void);
|
||||
|
||||
/* The same questions for a front end that is not a terminal (Telegram). */
|
||||
size_t sp_interview_count(void);
|
||||
const char *sp_interview_prompt(size_t i);
|
||||
const char *sp_interview_hint(size_t i);
|
||||
int sp_interview_save(const char *session_dir,
|
||||
const char *const *answers, size_t n, struct sp_buf *err);
|
||||
/* "\n\nWhat you know about the user:\n...", malloc'd; NULL when there is none. */
|
||||
char *sp_interview_user_block(const char *session_dir);
|
||||
|
||||
/*
|
||||
* If answer carries INTERVIEW_COMPLETE, write the summary to USER.txt and copy
|
||||
* the answer without the marker to clean. 1 when it captured something.
|
||||
*/
|
||||
int sp_interview_capture(const char *session_dir, const char *answer,
|
||||
char *clean, size_t cap);
|
||||
|
||||
/* 1 when USER.txt exists (the old profile/<user>.md still counts). */
|
||||
int sp_profile_exists(const char *session_dir);
|
||||
|
||||
#endif /* SPLINTER_INTERVIEW_H */
|
||||
+77
-114
@@ -999,121 +999,69 @@ static struct {
|
||||
} tg_cur;
|
||||
|
||||
/*
|
||||
* /interview in the chat: the same questions as `splinter --interview`, one
|
||||
* message per answer. The state is per gateway process; a restart abandons a
|
||||
* half-finished interview, as a closed terminal does.
|
||||
* /interview: the model talks to the user, not a questionnaire. The system
|
||||
* prompt is swapped for the interview prompt and the conversation restarted;
|
||||
* an answer that ends with INTERVIEW_COMPLETE is captured in the turn loop and
|
||||
* written to USER.txt, then the normal prompt comes back.
|
||||
*/
|
||||
struct tg_interview {
|
||||
int active;
|
||||
long chat_id;
|
||||
size_t step;
|
||||
char answers[16][4096];
|
||||
};
|
||||
|
||||
static struct tg_interview tg_iv;
|
||||
|
||||
static int
|
||||
tg_interview_ask(const char *token, long chat_id, struct sp_buf *err)
|
||||
{
|
||||
const char *q = sp_interview_prompt(tg_iv.step);
|
||||
const char *h = sp_interview_hint(tg_iv.step);
|
||||
struct sp_buf msg;
|
||||
|
||||
if (q == NULL)
|
||||
return -1;
|
||||
if (sp_buf_init(&msg) != 0)
|
||||
return -1;
|
||||
sp_buf_printf(&msg, sp_t("tg.interview.question"), tg_iv.step + 1,
|
||||
sp_interview_count(), q);
|
||||
if (h != NULL && *h != '\0')
|
||||
sp_buf_printf(&msg, "\n (%s)", h);
|
||||
sp_buf_puts(&msg, "\n");
|
||||
sp_buf_puts(&msg, sp_t("tg.interview.how"));
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
return 0;
|
||||
}
|
||||
static struct sp_agent_config tg_iv_cfg;
|
||||
static const struct sp_agent_config *tg_iv_orig;
|
||||
static const char *tg_iv_normal;
|
||||
static int tg_iv_active;
|
||||
|
||||
static void
|
||||
tg_interview_begin(const char *token, long chat_id, struct sp_buf *err)
|
||||
{
|
||||
struct sp_buf msg;
|
||||
|
||||
memset(&tg_iv, 0, sizeof(tg_iv));
|
||||
tg_iv.active = 1;
|
||||
tg_iv.chat_id = chat_id;
|
||||
tg_iv.step = 0;
|
||||
if (sp_buf_init(&msg) != 0)
|
||||
return;
|
||||
sp_buf_printf(&msg, sp_t("tg.interview.start"), sp_user_name(),
|
||||
sp_interview_count());
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
(void)tg_interview_ask(token, chat_id, err);
|
||||
}
|
||||
|
||||
static void
|
||||
tg_interview_end(const char *token, long chat_id, const char *session_dir,
|
||||
tg_interview_begin(const char *token, long chat_id, struct sp_agent *ag,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
const char *ptrs[16];
|
||||
char dir[600], path[700];
|
||||
struct sp_buf msg;
|
||||
size_t i, n = tg_iv.step;
|
||||
struct sp_buf msg, answer;
|
||||
|
||||
if (n > 16)
|
||||
n = 16;
|
||||
for (i = 0; i < n; i++)
|
||||
ptrs[i] = tg_iv.answers[i];
|
||||
if (sp_interview_save(session_dir, ptrs, n, err) == 0) {
|
||||
path[0] = '\0';
|
||||
if (sp_profile_path(session_dir, dir, sizeof(dir)) != NULL)
|
||||
snprintf(path, sizeof(path), "%s/%s.md", dir,
|
||||
sp_user_name());
|
||||
if (sp_buf_init(&msg) == 0) {
|
||||
sp_buf_printf(&msg, sp_t("tg.interview.saved"), path);
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
}
|
||||
} else {
|
||||
if (tg_iv_active) {
|
||||
(void)send_message(token, chat_id,
|
||||
"the interview is already running", err);
|
||||
return;
|
||||
}
|
||||
tg_iv_orig = ag->cfg;
|
||||
tg_iv_normal = ag->cfg->system_prompt;
|
||||
tg_iv_cfg = *ag->cfg;
|
||||
tg_iv_cfg.system_prompt = sp_interview_system();
|
||||
tg_iv_active = 1;
|
||||
ag->cfg = &tg_iv_cfg;
|
||||
if (ag->conv != NULL)
|
||||
(void)sp_conv_reset(ag->conv, tg_iv_cfg.system_prompt);
|
||||
if (sp_buf_init(&msg) == 0) {
|
||||
sp_buf_puts(&msg, sp_td("tg.interview.begin",
|
||||
"Interview started. Answer the model's questions; /new "
|
||||
"leaves the interview."));
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
}
|
||||
if (sp_buf_init(&answer) != 0)
|
||||
return;
|
||||
if (sp_agent_run(ag, "Begin the interview with your first question.",
|
||||
&answer, err) == 0) {
|
||||
char clean[16384], note[700];
|
||||
|
||||
if (answer.p != NULL && sp_interview_capture(
|
||||
ag->sess != NULL ? ag->sess->dir : NULL, answer.p, clean,
|
||||
sizeof(clean))) {
|
||||
snprintf(note, sizeof(note), sp_td("interview.saved",
|
||||
"interview saved to USER.txt"));
|
||||
(void)send_markdown(token, chat_id, clean, NULL, err);
|
||||
(void)send_message(token, chat_id, note, err);
|
||||
ag->cfg = tg_iv_orig;
|
||||
if (ag->conv != NULL && tg_iv_normal != NULL)
|
||||
(void)sp_conv_reset(ag->conv, tg_iv_normal);
|
||||
tg_iv_active = 0;
|
||||
} else
|
||||
(void)send_markdown(token, chat_id,
|
||||
answer.p != NULL ? answer.p : sp_t("reply.empty"),
|
||||
NULL, err);
|
||||
} else
|
||||
(void)send_message(token, chat_id,
|
||||
err->p != NULL ? err->p : sp_t("err.turn_failed"), err);
|
||||
}
|
||||
memset(&tg_iv, 0, sizeof(tg_iv));
|
||||
sp_buf_free(&answer);
|
||||
}
|
||||
|
||||
static void
|
||||
tg_interview_answer(const char *token, long chat_id, const char *text,
|
||||
const char *session_dir, struct sp_buf *err)
|
||||
{
|
||||
struct sp_buf msg;
|
||||
|
||||
if (strcmp(text, "/cancel") == 0) {
|
||||
memset(&tg_iv, 0, sizeof(tg_iv));
|
||||
if (sp_buf_init(&msg) == 0) {
|
||||
sp_buf_puts(&msg, sp_t("tg.interview.cancel"));
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (text[0] == '/' && strcmp(text, "/skip") != 0) {
|
||||
if (sp_buf_init(&msg) == 0) {
|
||||
sp_buf_puts(&msg, sp_t("tg.interview.busy"));
|
||||
(void)send_message(token, chat_id, msg.p, err);
|
||||
sp_buf_free(&msg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (tg_iv.step < 16)
|
||||
snprintf(tg_iv.answers[tg_iv.step], sizeof(tg_iv.answers[0]),
|
||||
"%s", strcmp(text, "/skip") == 0 ? "" : text);
|
||||
tg_iv.step++;
|
||||
if (tg_iv.step < sp_interview_count())
|
||||
(void)tg_interview_ask(token, chat_id, err);
|
||||
else
|
||||
tg_interview_end(token, chat_id, session_dir, err);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -1729,7 +1677,6 @@ tg_new_conversation(const char *token, long chat_id, struct sp_agent *ag,
|
||||
return;
|
||||
}
|
||||
ag->sess = &fresh;
|
||||
memset(&tg_iv, 0, sizeof(tg_iv));
|
||||
memset(&tg_cc, 0, sizeof(tg_cc));
|
||||
if (sp_buf_init(&msg) == 0) {
|
||||
sp_buf_printf(&msg, sp_t("session.new"), fresh.id);
|
||||
@@ -2095,13 +2042,6 @@ sp_telegram_run(struct sp_agent *ag, struct sp_host *host, const char *token,
|
||||
* reader of this chat, so it resolves here instead of letting a
|
||||
* second poller fight it for updates.
|
||||
*/
|
||||
if (tg_iv.active && tg_iv.chat_id == chat_id) {
|
||||
tg_interview_answer(token, chat_id, text,
|
||||
ag->sess != NULL ? ag->sess->dir : NULL,
|
||||
err);
|
||||
sp_buf_clear(err);
|
||||
continue;
|
||||
}
|
||||
if (tg_cc.active && tg_cc.chat_id == chat_id) {
|
||||
tg_connect_answer(token, chat_id, text, ag,
|
||||
conf, err);
|
||||
@@ -2111,7 +2051,7 @@ sp_telegram_run(struct sp_agent *ag, struct sp_host *host, const char *token,
|
||||
if (tg_ack_reply(token, chat_id, text))
|
||||
continue;
|
||||
if (strcmp(text, "/interview") == 0) {
|
||||
tg_interview_begin(token, chat_id, err);
|
||||
tg_interview_begin(token, chat_id, ag, err);
|
||||
sp_buf_clear(err);
|
||||
continue;
|
||||
}
|
||||
@@ -2274,6 +2214,29 @@ sp_telegram_run(struct sp_agent *ag, struct sp_host *host, const char *token,
|
||||
tstop = 1;
|
||||
(void)pthread_join(tty, NULL);
|
||||
}
|
||||
if (answer.p != NULL && tg_iv_active) {
|
||||
char clean[16384], note[700];
|
||||
|
||||
if (sp_interview_capture(
|
||||
ag->sess != NULL ? ag->sess->dir : NULL,
|
||||
answer.p, clean, sizeof(clean))) {
|
||||
snprintf(note, sizeof(note), sp_td(
|
||||
"interview.saved",
|
||||
"interview saved to USER.txt"));
|
||||
(void)send_markdown(token, chat_id,
|
||||
clean, NULL, err);
|
||||
(void)send_message(token, chat_id,
|
||||
note, err);
|
||||
ag->cfg = tg_iv_orig;
|
||||
if (ag->conv != NULL &&
|
||||
tg_iv_normal != NULL)
|
||||
(void)sp_conv_reset(ag->conv,
|
||||
tg_iv_normal);
|
||||
tg_iv_active = 0;
|
||||
sp_buf_clear(err);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
(void)send_markdown(token, chat_id,
|
||||
answer.p != NULL ? answer.p : sp_t("reply.empty"),
|
||||
NULL, err);
|
||||
|
||||
+3
-61
@@ -88,8 +88,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"
|
||||
" --interview let the model interview you; writes "
|
||||
"USER.txt\n"
|
||||
" --mcp-server-listen IP serve MCP on IP (tools of this "
|
||||
"registry);\n"
|
||||
" beyond 127.x it needs "
|
||||
@@ -714,52 +714,6 @@ check_usage(const struct opts *o)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the session directory and id, opened; 0 or the exit status */
|
||||
/*
|
||||
* For the one-shot modes that need a session directory but no agent
|
||||
* (--interview, --ack*): the same rules as the engine's, without building it.
|
||||
*/
|
||||
static int
|
||||
open_session_only(struct opts *o, struct sp_session_info *sess,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
static char sessbuf[512], idbuf[64];
|
||||
char cwd[512];
|
||||
|
||||
if (o->sessdir == NULL) {
|
||||
const char *home = getenv("HOME");
|
||||
|
||||
snprintf(sessbuf, sizeof(sessbuf), "%s/.splinter",
|
||||
home != NULL ? home : ".");
|
||||
o->sessdir = sessbuf;
|
||||
}
|
||||
if (o->continue_here && o->sessid == NULL) {
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL ||
|
||||
sp_session_last_for(o->sessdir, cwd, idbuf,
|
||||
sizeof(idbuf)) != 0) {
|
||||
fprintf(stderr, "splinter: no session in %s yet\n",
|
||||
getcwd(cwd, sizeof(cwd)) != NULL ? cwd : ".");
|
||||
return 2;
|
||||
}
|
||||
o->sessid = idbuf;
|
||||
o->resume = 1;
|
||||
}
|
||||
if (o->resume && o->sessid == NULL &&
|
||||
sp_session_latest(o->sessdir, idbuf, sizeof(idbuf)) == 0)
|
||||
o->sessid = idbuf;
|
||||
if (o->sessid == NULL) {
|
||||
snprintf(idbuf, sizeof(idbuf), "sess-%ld-%d", (long)time(NULL),
|
||||
(int)getpid());
|
||||
o->sessid = idbuf;
|
||||
}
|
||||
if (sp_session_open(sess, o->sessdir, o->sessid, err) != 0) {
|
||||
fprintf(stderr, "splinter: %s\n",
|
||||
err->len > 0 ? err->p : sp_t("err.session"));
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
program_found(const char *cmd)
|
||||
{
|
||||
@@ -1390,19 +1344,6 @@ main(int argc, char **argv)
|
||||
printf("%s %d\n", o.ack_yes ? "yes" : "no", o.ack_id);
|
||||
return 0;
|
||||
}
|
||||
if (o.interview) {
|
||||
struct sp_session_info sess;
|
||||
|
||||
memset(&sess, 0, sizeof(sess));
|
||||
if ((rc = open_session_only(&o, &sess, &err)) != 0)
|
||||
return rc;
|
||||
rc = sp_interview_run(sess.dir, &err);
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "splinter: %s\n",
|
||||
err.len > 0 ? err.p : "interview failed");
|
||||
return rc == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
memset(&eo, 0, sizeof(eo));
|
||||
eo.conf = &conf;
|
||||
eo.base = &cfg;
|
||||
@@ -1421,6 +1362,7 @@ main(int argc, char **argv)
|
||||
* The MCP server is tools-only unless a model is given (or the daemon
|
||||
* owns the engine): the session tools need a transport to run a turn.
|
||||
*/
|
||||
eo.interview = o.interview;
|
||||
eo.no_transport = (o.mcp_ip != NULL && !o.daemon &&
|
||||
o.endpoint == NULL && o.model == NULL) || o.delegate != NULL;
|
||||
/* the fleet belongs to the curses chat, not to a served engine */
|
||||
|
||||
@@ -145,13 +145,21 @@ class H(http.server.BaseHTTPRequestHandler):
|
||||
return self.reply({"ok": True, "result": {"message_id": 100}})
|
||||
req = json.loads(raw)
|
||||
has_tool = any(m.get("role") == "tool" for m in req.get("messages", []))
|
||||
system = " ".join((m.get("content") or "") for m in
|
||||
req.get("messages", []) if m.get("role") == "system")
|
||||
last_user = ""
|
||||
for m in reversed(req.get("messages", [])):
|
||||
if m.get("role") == "user":
|
||||
last_user = m.get("content") or ""
|
||||
break
|
||||
answer = "ok"
|
||||
if "single word ok" in last_user:
|
||||
if "INTERVIEW_COMPLETE" in system:
|
||||
# the model-driven interview: a summary and the marker; the
|
||||
# gateway strips it and writes USER.txt
|
||||
answer = "Testprofil: mag C99.\nINTERVIEW_COMPLETE"
|
||||
chunks = [{"choices": [{"delta": {"content": answer}}]},
|
||||
{"choices": [{"delta": {}, "finish_reason": "stop"}]}]
|
||||
elif "single word ok" in last_user:
|
||||
# /connect's test turn
|
||||
answer = "ok"
|
||||
chunks = [{"choices": [{"delta": {"content": answer}}]},
|
||||
|
||||
@@ -204,13 +204,14 @@ check "connect offers to use it now" \
|
||||
grep -q '"callback_data":"model:testprov"' "$D/sent.log"
|
||||
check "connect tested the provider" grep -q 'Test bestanden: ok' "$D/sent.log"
|
||||
|
||||
# /interview asks the six questions and writes the profile
|
||||
run_text "/interview" '^Profil geschrieben' 30
|
||||
prof=$(ls "$D/home/.splinter/profile/"*.md 2>/dev/null | head -1)
|
||||
check "the interview wrote a profile" test -n "$prof"
|
||||
check "the first answer is in the profile" grep -q 'antwort-1' "$prof"
|
||||
check "the last answer is in the profile" grep -q 'antwort-6' "$prof"
|
||||
check "the profile has the language section" grep -q '## language' "$prof"
|
||||
# /interview: the model interviews; the summary before INTERVIEW_COMPLETE
|
||||
# becomes USER.txt (the fake answers with the marker once the interview
|
||||
# prompt is in the request)
|
||||
run_text "/interview" 'Interview gestartet' 30 'Interview in USER.txt gespeichert'
|
||||
check "the interview saved USER.txt" test -s "$D/home/.splinter/USER.txt"
|
||||
check "the summary is in USER.txt" grep -q 'mag C99' "$D/home/.splinter/USER.txt"
|
||||
check "the marker is not in USER.txt" \
|
||||
sh -c "! grep -q INTERVIEW_COMPLETE '$D/home/.splinter/USER.txt'"
|
||||
|
||||
if [ "$fails" -eq 0 ]; then echo "test_gateway: ok"; exit 0; fi
|
||||
cat "$D/gw.out"
|
||||
|
||||
+60
-23
@@ -1,34 +1,71 @@
|
||||
#!/bin/sh
|
||||
# splinter -- the first-run interview from the terminal.
|
||||
# splinter -- the model-driven interview and what it leaves behind.
|
||||
#
|
||||
# No transport is needed; the questions come from the catalogue (English here),
|
||||
# and the answers are written to profile/<user>.md. The six answers also prove
|
||||
# that a skipped question (the empty line) is recorded as such.
|
||||
# The script transport stands in for the model: its answer carries a summary
|
||||
# and INTERVIEW_COMPLETE. The summary must land in USER.txt, the marker must
|
||||
# not, and the next run's system prompt must carry the summary.
|
||||
set -u
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-iv-XXXXXX") || exit 1
|
||||
cleanup() { rm -rf "$D"; }
|
||||
trap cleanup EXIT
|
||||
port=18992
|
||||
srv=
|
||||
cleanup() { [ -n "$srv" ] && kill "$srv" 2>/dev/null; rm -rf "$D"; }
|
||||
trap cleanup EXIT INT TERM
|
||||
fails=0
|
||||
check() { # $1 = description, $2.. = command
|
||||
d=$1; shift
|
||||
if "$@"; then :; else echo "FAIL $d"; fails=$((fails + 1)); fi
|
||||
}
|
||||
check() { d=$1; shift; if "$@"; then :; else echo "FAIL $d"; fails=$((fails+1)); fi; }
|
||||
|
||||
out=$(printf 'english\nabout me\nC99\n\nno commits\n/home/carol\n' | \
|
||||
HOME="$D" SPLINTER_LOCALE=en ./splinter --no-config \
|
||||
--session "$D/sess" --interview 2>&1)
|
||||
check "the interview needs no transport" test $? -eq 0
|
||||
echo "$out" | grep -q 'First conversation'
|
||||
check "the questions are in the process language" test $? -eq 0
|
||||
echo "$out" | grep -q 'Which language should I speak'
|
||||
check "the language question is English" test $? -eq 0
|
||||
mkdir -p "$D/home"
|
||||
echo 'answer Summary: the user likes C99 and short answers. INTERVIEW_COMPLETE' > "$D/r1"
|
||||
HOME="$D/home" ./splinter --no-config --model m --script "$D/r1" \
|
||||
-p "interview me" > "$D/out1" 2>&1
|
||||
check "the turn ran" test $? -eq 0
|
||||
check "USER.txt was written" test -f "$D/home/.splinter/USER.txt"
|
||||
check "the summary is in USER.txt" grep -q 'likes C99' "$D/home/.splinter/USER.txt"
|
||||
check "the marker is not in USER.txt" sh -c "! grep -q INTERVIEW_COMPLETE '$D/home/.splinter/USER.txt'"
|
||||
|
||||
prof=$(ls "$D/sess/profile/"*.md 2>/dev/null | head -1)
|
||||
check "the profile was written" test -n "$prof"
|
||||
check "the first answer is in the profile" grep -q 'english' "$prof"
|
||||
check "the skipped question is not a lie" grep -q '(not answered)' "$prof"
|
||||
check "the last section is in the profile" grep -q '## paths' "$prof"
|
||||
# the next run's request must carry USER.txt in the system prompt
|
||||
python3 - "$D/req.json" <<'PY' &
|
||||
import http.server, sys
|
||||
out = sys.argv[1]
|
||||
class H(http.server.BaseHTTPRequestHandler):
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
def do_POST(self):
|
||||
n = int(self.headers.get("Content-Length", 0))
|
||||
open(out, "wb").write(self.rfile.read(n))
|
||||
b = b'data: {"choices":[{"delta":{"content":"ok"}}]}\n\ndata: [DONE]\n\n'
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/event-stream")
|
||||
self.send_header("Content-Length", str(len(b)))
|
||||
self.end_headers()
|
||||
self.wfile.write(b)
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", 18992), H).serve_forever()
|
||||
PY
|
||||
srv=$!
|
||||
i=0
|
||||
while [ $i -lt 50 ]; do
|
||||
if python3 - "$port" <<'PY'
|
||||
import socket, sys
|
||||
s = socket.socket(); s.settimeout(0.2)
|
||||
try:
|
||||
s.connect(("127.0.0.1", int(sys.argv[1])))
|
||||
except OSError:
|
||||
sys.exit(1)
|
||||
finally:
|
||||
s.close()
|
||||
PY
|
||||
then
|
||||
break
|
||||
fi
|
||||
i=$((i + 1)); sleep 0.1
|
||||
done
|
||||
|
||||
HOME="$D/home" ./splinter --no-config --model m \
|
||||
--endpoint "http://127.0.0.1:$port/v1/chat/completions" \
|
||||
-p "hallo" > "$D/out2" 2>&1
|
||||
check "the second turn ran" test $? -eq 0
|
||||
check "the request carries USER.txt" grep -q 'What you know about the user' "$D/req.json"
|
||||
check "the request carries the summary" grep -q 'likes C99' "$D/req.json"
|
||||
|
||||
if [ "$fails" -eq 0 ]; then echo "test_interview: ok"; exit 0; fi
|
||||
exit 1
|
||||
Reference in new issue
Block a user