From a00ffef699021f409eaee4813a086de408478204 Mon Sep 17 00:00:00 2001
From: lotherk
Date: Tue, 10 Nov 2026 08:56:23 +0000
Subject: [PATCH] a2a: INPUT_REQUIRED -- a turn that pauses and resumes
sp_agent_run can stop before a mutating tool when an approval callback
returns 2; the assistant call is in the conversation, no observation is.
sp_agent_resume(decision) runs the pending calls, adds the observations
and continues the model loop. Normal callers are unchanged: the ack, UI
and gateway paths still return 0/1.
The A2A server pauses as TASK_STATE_INPUT_REQUIRED, keeps the task and
its context, and resumes on SendMessage with the same taskId and
yes/no. CancelTask cancels a paused task. SendStreamingMessage has no
resume point and denies mutating tools instead.
test_pause covers allow/deny in the agent; test_a2a_input covers the
whole HTTP flow (yes, no, cancel). Full make check green (33 C tests).
---
Makefile | 5 +-
README.md | 2 +-
TODO.md | 40 +-----
docs/PLUGINS.md | 11 +-
docs/ROADMAP.md | 18 +--
include/splinter.h | 13 ++
src/a2aserver.c | 270 +++++++++++++++++++++++++++++++++++++---
src/agent.c | 261 ++++++++++++++++++++++++++------------
src/www/index.en.html | 10 +-
src/www/index.html | 10 +-
src/www/index.pt.html | 10 +-
tests/test_a2a_input.sh | 109 ++++++++++++++++
tests/test_pause.c | 130 +++++++++++++++++++
tools/gen_www.py | 12 +-
14 files changed, 740 insertions(+), 161 deletions(-)
create mode 100755 tests/test_a2a_input.sh
create mode 100644 tests/test_pause.c
diff --git a/Makefile b/Makefile
index 628d569..889d0fe 100644
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
plugins/tmux/tmux.so
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_conv \
tests/test_transport tests/test_agent tests/test_openai \
- tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_b64 tests/test_swarm tests/test_provstate tests/test_planner tests/test_jobs
+ tests/test_theme tests/test_plugin tests/test_memory tests/test_skills tests/test_telegram tests/test_delegate tests/test_builtin tests/test_ascii tests/test_ack tests/test_i18n tests/test_config tests/test_focus tests/test_sse tests/test_cli tests/test_compactor tests/test_secrets tests/test_mcpclient tests/test_kids tests/test_lifecycle tests/test_md tests/test_b64 tests/test_pause tests/test_swarm tests/test_provstate tests/test_planner tests/test_jobs
RPATH = -Wl,-rpath,'$$ORIGIN'
PLUGIN_RPATH = -Wl,-rpath,'$$ORIGIN/../..'
@@ -185,6 +185,8 @@ tests/test_md: tests/test_md.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_md.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_b64: tests/test_b64.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_b64.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
+tests/test_pause: tests/test_pause.c $(LIB)
+ $(CC) $(CFLAGS) -o $@ tests/test_pause.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_swarm: tests/test_swarm.c $(LIB)
$(CC) $(CFLAGS) -o $@ tests/test_swarm.c -L. -lsplinter $(TEST_RPATH) $(LIBS)
tests/test_provstate: tests/test_provstate.c $(LIB)
@@ -227,6 +229,7 @@ check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
echo "== tests/test_a2a_ui.sh"; sh tests/test_a2a_ui.sh; \
echo "== tests/test_a2a_server.sh"; sh tests/test_a2a_server.sh; \
echo "== tests/test_a2a_context.sh"; sh tests/test_a2a_context.sh; \
+ echo "== tests/test_a2a_input.sh"; sh tests/test_a2a_input.sh; \
echo "== tests/test_ui.sh"; sh tests/test_ui.sh; \
echo "all tests passed"
diff --git a/README.md b/README.md
index 4a4a50b..f482d86 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ the screen, a sidebar on one quarter, plugins that can put tools and widgets
into both.
make # libsplinter.so, the binary, the plugins
- make check # every test binary (32), no network, no model
+ make check # every test binary (33), no network, no model
splinter # starts the chat from ~/.config/splinter/config
diff --git a/TODO.md b/TODO.md
index 66e9c37..54323e3 100644
--- a/TODO.md
+++ b/TODO.md
@@ -5,41 +5,9 @@ Erledigtes steht unten, damit die Liste nicht wieder behauptet, etwas sei offen.
## Offen
-### 1. A2A: Client und Server stehen, der Rest fehlt
-Der Client ist gebaut: `plugins/a2a/a2a.c` sendet `SendMessage` als JSON-RPC 2.0
-mit einem Text-Teil, blockierend, und liest eine direkte `Message` oder eine
-`Task` in `TASK_STATE_COMPLETED` (Status-Nachricht plus Artefakte). In der UI
-laeuft der Turn ueber `SendStreamingMessage`; Artefakt- und Message-Text
-erscheint waehrend des Laufs, Zwischenstatus wird nicht angehaengt. Task- und
-Context-Id bleiben fuer die Sitzung; ein terminaler Task verliert seine Id, der
-Context bleibt. `SPLINTER_A2A_CARD` findet den Endpunkt ueber die Agent Card.
-
-Der Server ist gebaut: `src/a2aserver.c`, `POST /a2a` mit `SendMessage` (ein
-Turn in der Konversation des `contextId`), `SendStreamingMessage` (SSE,
-`artifactUpdate`-Chunks, dann completed `statusUpdate`), `GetTask`,
-`ListTasks`, Multiturn ueber `contextId` und
-`GET /.well-known/agent-card.json`, Bearer-Token ueber
-`SPLINTER_A2A_SERVER_TOKEN` jenseits von Loopback. `CancelTask` antwortet
-`TaskNotCancelable` (-32002), `SubscribeToTask` und die Push-Config-CRUD-Methoden
-`UnsupportedOperation` (-32004). Eine `taskPushNotificationConfig` in der
-Anfrage schickt den fertigen Task an einen Webhook; Loopback ist erlaubt, andere
-Hosts nur ueber `SPLINTER_A2A_PUSH_ALLOW` (SSRF-Schutz).
-
-Text, text/plain `raw` (base64) und String-`data`-Teile werden gelesen; ein
-`url`- oder binaerer Teil wird mit `ContentTypeNotSupported` (-32005) abgelehnt,
-nicht abgerufen. Push an Webhooks und Multiturn ueber `contextId` stehen.
-
-Der Client registriert `a2a_get_task` und `a2a_cancel_task` (read/destructive)
-fuer ein lokales Modell, das ihn als Werkzeugquelle nutzt; der Server liefert
-`GetTask` als Task-Objekt (nicht als `{"task":...}`). Push-Configs lassen sich
-per CRUD verwalten; text/plain-URL-Teile werden von Loopback oder
-`SPLINTER_A2A_URL_ALLOW` geholt (1 MiB, keine Redirects).
-
-Offen: die Fortsetzung eines unterbrochenen Tasks (`INPUT_REQUIRED`). Binaere
-Teile bleiben bewusst abgelehnt.
-
-Naechster Schritt: ein pausierbarer Turn fuer INPUT_REQUIRED.
+Nichts aus der alten Liste. Binaere A2A-Teile bleiben bewusst abgelehnt
+(`ContentTypeNotSupported`); URL-Teile werden nur von erlaubten Hosts geholt.
## Erledigt
@@ -84,7 +52,9 @@ Naechster Schritt: ein pausierbarer Turn fuer INPUT_REQUIRED.
`a2a_get_task`/`a2a_cancel_task` als Client-Werkzeuge und die Agent Card mit
Bearer-Token; die Karte meldet `streaming:true` und
`pushNotifications:true`. `GetTask` liefert das Task-Objekt, nicht
- `{"task":...}`. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
+ `{"task":...}`. Ein mutierendes Werkzeug pausiert als
+ `INPUT_REQUIRED`; `SendMessage` mit `taskId` und `yes`/`no` setzt fort,
+ `CancelTask` bricht ab (`test_pause`, `test_a2a_input.sh`). `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
Streaming und Discovery, `tests/test_a2a_ui.sh` den Streaming-Pfad,
`tests/test_a2a_server.sh` den Server und den Client gegen den Server
(Discovery, blockierend und streamend), `tests/test_a2a_context.sh` die
diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md
index bfc56b1..5dc58bb 100644
--- a/docs/PLUGINS.md
+++ b/docs/PLUGINS.md
@@ -352,7 +352,14 @@ A text/plain `url` part is fetched from loopback or a host in
`SPLINTER_A2A_URL_ALLOW` (same syntax, 1 MiB cap, no redirects); a binary or
other media type is refused.
-Refused with a JSON-RPC error, not half-answered: `CancelTask`,
-`SubscribeToTask`, binary parts and continuation of an interrupted task. Beyond loopback
+A mutating tool that needs approval pauses the task in
+`TASK_STATE_INPUT_REQUIRED`; the assistant call is already in the context, the
+tool has not run. Another `SendMessage` with the same `taskId` and a
+`yes`/`no` answer resumes it (`sp_agent_resume`); `CancelTask` cancels it.
+`SendStreamingMessage` has nowhere to resume, so it denies mutating tools
+instead of pausing.
+
+Refused with a JSON-RPC error, not half-answered: `SubscribeToTask` and binary
+parts. Beyond loopback
`SPLINTER_A2A_SERVER_TOKEN` is required and checked as
`Authorization: Bearer ...`; there is no TLS.
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index e549341..9aeb83d 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -1,16 +1,12 @@
# Offene Punkte
-Stand: 2026-11-09. Die geprüfte, ausführliche Liste mit Belegen steht in
-`TODO.md`; hier bleibt die Reihenfolge, was als Nächstes gebaut wird.
+Stand: 2026-11-10. Die geprüfte, ausführliche Liste mit Belegen steht in
+`TODO.md`.
-1. **A2A: was noch fehlt** — Client (`SendMessage`, `SendStreamingMessage` in
- der UI, Agent-Card-Discovery) und Server (`SendMessage`, SSE-Streaming,
- `GetTask`, `ListTasks`, Multiturn ueber `contextId`, Agent Card) stehen, alles
- mit Text. Offen sind Datei- und strukturierte Teile, Push-Notifications,
- `CancelTask`/`SubscribeToTask` und die Fortsetzung eines unterbrochenen
- Tasks. `swarm` ist nur lokale IPC im
- selben Verzeichnis, kein A2A.
+## Offen
+Nichts aus der alten A2A-Liste. Binaere A2A-Teile bleiben bewusst abgelehnt;
+URL-Teile werden nur von erlaubten Hosts geholt.
## Erledigt
@@ -37,3 +33,7 @@ Stand: 2026-11-09. Die geprüfte, ausführliche Liste mit Belegen steht in
Generieren aus dem Baum (`tools/gen_www.py`)
- **Letzter Delegate-Fehler**: die letzten 400 Bytes des Kindes stehen im Fehler,
ein Limit bencht den Delegate und der nächste übernimmt (`test_delegate`)
+- **A2A INPUT_REQUIRED**: ein mutierendes Werkzeug pausiert (`sp_agent_run`
+ liefert 2), `SendMessage` mit `taskId` und `yes`/`no` setzt per
+ `sp_agent_resume` fort; `CancelTask` bricht ab (`test_pause`,
+ `test_a2a_input.sh`)
diff --git a/include/splinter.h b/include/splinter.h
index 0ece151..d9753c5 100644
--- a/include/splinter.h
+++ b/include/splinter.h
@@ -265,10 +265,23 @@ struct sp_agent {
struct sp_session_info *sess;
struct sp_conv *conv; /* optional: history lives here */
struct sp_agent_stats stats;
+ /*
+ * A turn that stopped before a tool ran because a person has to decide.
+ * The assistant message with the calls is already in the conversation;
+ * the calls from pending_from on are still unobserved.
+ */
+ struct sp_reply pending;
+ size_t pending_from;
+ int has_pending;
};
+#define SP_AGENT_INPUT_REQUIRED 2
+
int sp_agent_run(struct sp_agent *, const char *user_text,
struct sp_buf *answer, struct sp_buf *err);
+/* Resume a paused turn: decision 1 allows the pending calls, 0 denies. */
+int sp_agent_resume(struct sp_agent *, int decision, struct sp_buf *answer,
+ struct sp_buf *err);
/* builtin.c */
int sp_builtin_register(struct sp_registry *);
diff --git a/src/a2aserver.c b/src/a2aserver.c
index 481d9ea..e25c2fb 100644
--- a/src/a2aserver.c
+++ b/src/a2aserver.c
@@ -58,6 +58,7 @@ struct a2a_task {
int used;
char id[64];
char context[128];
+ char state[32];
struct sp_buf answer;
};
@@ -87,6 +88,9 @@ static struct a2a_ctx g_ctx[A2A_CONTEXTS];
static unsigned g_seq;
static unsigned g_ctx_seq;
static unsigned long g_clock;
+static char g_ir_task[64]; /* task waiting for a decision */
+static char g_ir_context[128];
+static char g_ir_msg[512];
static volatile int g_stop;
static void
@@ -398,6 +402,7 @@ task_store_id(const char *id, const char *context, const struct sp_buf *answer)
snprintf(t->id, sizeof(t->id), "task-%d-%u", (int)getpid(),
g_seq);
snprintf(t->context, sizeof(t->context), "%s", context);
+ snprintf(t->state, sizeof(t->state), "TASK_STATE_COMPLETED");
if (sp_buf_add(&t->answer, answer->p, answer->len) != 0) {
sp_buf_free(&t->answer);
return NULL;
@@ -412,6 +417,35 @@ task_store(const char *context, const struct sp_buf *answer)
return task_store_id(NULL, context, answer);
}
+static void
+task_update(struct a2a_task *t, const char *state, const struct sp_buf *answer)
+{
+ snprintf(t->state, sizeof(t->state), "%s", state);
+ sp_buf_clear(&t->answer);
+ if (answer != NULL && answer->p != NULL)
+ (void)sp_buf_add(&t->answer, answer->p, answer->len);
+}
+
+static struct a2a_task *
+task_store_state(const char *id, const char *context, const char *state,
+ const char *message)
+{
+ struct sp_buf empty;
+ struct a2a_task *t;
+
+ if (sp_buf_init(&empty) != 0)
+ return NULL;
+ t = task_store_id(id, context, &empty);
+ sp_buf_free(&empty);
+ if (t != NULL) {
+ snprintf(t->state, sizeof(t->state), "%s", state);
+ sp_buf_clear(&t->answer);
+ if (message != NULL)
+ (void)sp_buf_puts(&t->answer, message);
+ }
+ return t;
+}
+
static struct a2a_ctx *
ctx_get(struct sp_agent *ag, const char *id, int create)
{
@@ -458,14 +492,21 @@ ctx_get(struct sp_agent *ag, const char *id, int create)
static void
task_obj(struct sp_buf *b, const struct a2a_task *t)
{
+ int completed = strcmp(t->state, "TASK_STATE_COMPLETED") == 0;
+
sp_buf_puts(b, "{\"id\":\"");
sp_buf_puts(b, t->id);
- sp_buf_printf(b, "\",\"contextId\":\"%s\",\"status\":{\"state\":"
- "\"TASK_STATE_COMPLETED\",\"message\":{\"messageId\":\"msg-%s\","
+ sp_buf_printf(b, "\",\"contextId\":\"%s\",\"status\":{\"state\":\"%s\","
+ "\"message\":{\"messageId\":\"msg-%s\","
"\"role\":\"ROLE_AGENT\",\"parts\":[{\"text\":\"", t->context,
- t->id);
+ t->state[0] != '\0' ? t->state : "TASK_STATE_COMPLETED", t->id);
sp_json_escape(b, t->answer.p);
- sp_buf_puts(b, "\"}]}},\"artifacts\":[{\"artifactId\":\"a-");
+ sp_buf_puts(b, "\"}]}}");
+ if (!completed) {
+ sp_buf_puts(b, "}"); /* status, task */
+ return;
+ }
+ sp_buf_puts(b, ",\"artifacts\":[{\"artifactId\":\"a-");
sp_buf_puts(b, t->id);
sp_buf_puts(b, "\",\"parts\":[{\"text\":\"");
sp_json_escape(b, t->answer.p);
@@ -857,8 +898,56 @@ rpc_result(int fd, const char *id, const char *result)
* The shared conversation from --chat would let one remote agent read another's
* history.
*/
+static int
+a2a_approve(void *ctx, const char *name, int auth, const char *args)
+{
+ (void)ctx;
+ (void)auth;
+ snprintf(g_ir_msg, sizeof(g_ir_msg), "approval required: %s %s",
+ name, args != NULL ? args : "");
+ return 2; /* pause; the task becomes INPUT_REQUIRED */
+}
+
+static int
+a2a_deny(void *ctx, const char *name, int auth, const char *args)
+{
+ (void)ctx;
+ (void)name;
+ (void)auth;
+ (void)args;
+ return 0; /* streaming has nowhere to resume from */
+}
+
static int
run_turn(struct sp_agent *ag, struct sp_conv *conv, const char *text,
+ int (*approve)(void *, const char *, int, const char *),
+ struct sp_buf *answer, struct sp_buf *err)
+{
+ struct sp_agent_config cfg;
+ const struct sp_agent_config *savedcfg;
+ struct sp_conv *savedconv;
+ int rc;
+
+ if (ag->cfg == NULL) {
+ sp_buf_puts(err, "no agent configuration");
+ return -1;
+ }
+ cfg = *ag->cfg;
+ cfg.approve = approve;
+ cfg.approve_ctx = NULL;
+ cfg.approve_is_channel = 1;
+ savedcfg = ag->cfg;
+ savedconv = ag->conv;
+ ag->cfg = &cfg;
+ ag->conv = conv;
+ rc = sp_agent_run(ag, text, answer, err);
+ ag->conv = savedconv;
+ ag->cfg = savedcfg;
+ return rc;
+}
+
+static int
+resume_turn(struct sp_agent *ag, struct sp_conv *conv, int decision,
struct sp_buf *answer, struct sp_buf *err)
{
struct sp_conv *saved;
@@ -866,11 +955,33 @@ run_turn(struct sp_agent *ag, struct sp_conv *conv, const char *text,
saved = ag->conv;
ag->conv = conv;
- rc = sp_agent_run(ag, text, answer, err);
+ rc = sp_agent_resume(ag, decision, answer, err);
ag->conv = saved;
return rc;
}
+/* yes/ok/ja/sim -> 1, no/nein/nao -> 0, anything else -> -1 */
+static int
+decision_of(const char *text)
+{
+ if (text == NULL)
+ return -1;
+ while (*text == ' ' || *text == '\t')
+ text++;
+ if (strncasecmp(text, "yes", 3) == 0 ||
+ strncasecmp(text, "ja", 2) == 0 ||
+ strncasecmp(text, "ok", 2) == 0 ||
+ strncasecmp(text, "sim", 3) == 0 ||
+ (text[0] == 'y' && (text[1] == '\0' || text[1] == ' ')))
+ return 1;
+ if (strncasecmp(text, "nein", 4) == 0 ||
+ strncasecmp(text, "no", 2) == 0 ||
+ strncasecmp(text, "nao", 3) == 0 ||
+ (text[0] == 'n' && (text[1] == '\0' || text[1] == ' ')))
+ return 0;
+ return -1;
+}
+
/*
* Server-side streaming: the turn runs with a callback that writes one A2A
* artifactUpdate per chunk. A transport that cannot stream (cli, script) runs
@@ -1013,6 +1124,11 @@ handle_stream(int fd, struct sp_agent *ag, const char *id,
return;
}
sse_start(fd);
+ if (g_ir_task[0] != '\0') {
+ sse_error(&o, -32004, "a task is waiting for input; use "
+ "SendMessage with its taskId");
+ goto out;
+ }
message = mcp_arg(params, "message");
parts = message != NULL ? mcp_arg(message, "parts") : NULL;
rc = collect_text(parts, &text);
@@ -1048,8 +1164,8 @@ handle_stream(int fd, struct sp_agent *ag, const char *id,
cfg.stream = sse_text;
cfg.stream_ctx = &o;
ag->cfg = &cfg;
- rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "", &answer,
- &err);
+ rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "",
+ a2a_deny, &answer, &err);
ag->cfg = saved;
if (rc != 0) {
sse_error(&o, -32603, err.p != NULL && err.len > 0 ?
@@ -1084,7 +1200,7 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
{
mcp_json *v;
const mcp_json *params, *message, *parts;
- const char *method, *ctx;
+ const char *method, *ctx, *task_id;
char id[128], ctxbuf[128];
struct sp_buf text, answer, err, out, perr;
struct a2a_ctx *cx;
@@ -1117,6 +1233,7 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
goto send_out;
}
message = mcp_arg(params, "message");
+ task_id = message != NULL ? mcp_arg_string(message, "taskId") : NULL;
parts = message != NULL ? mcp_arg(message, "parts") : NULL;
rc = collect_text(parts, &text);
if (rc != 0) {
@@ -1125,6 +1242,67 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
"out of memory");
goto send_out;
}
+ rc = push_parse(params, &push, &perr);
+ if (rc < 0) {
+ rpc_error(fd, id, rc == -2 ? -32003 : -32602, perr.p);
+ goto send_out;
+ }
+ if (g_ir_task[0] != '\0') {
+ struct a2a_task *t;
+ int decision;
+
+ if (task_id == NULL ||
+ strcmp(task_id, g_ir_task) != 0) {
+ rpc_error(fd, id, -32004, "a task is waiting "
+ "for input; send its taskId");
+ goto send_out;
+ }
+ t = task_find(task_id);
+ if (t == NULL) {
+ rpc_error(fd, id, -32001, "task not found");
+ goto send_out;
+ }
+ decision = decision_of(text.p);
+ if (decision < 0) {
+ rpc_error(fd, id, -32602, "expected yes or no");
+ goto send_out;
+ }
+ cx = ctx_get(ag, t->context, 1);
+ if (cx == NULL) {
+ rpc_error(fd, id, -32603, "out of memory "
+ "for a context");
+ goto send_out;
+ }
+ rc = resume_turn(ag, &cx->conv, decision, &answer,
+ &err);
+ if (rc == SP_AGENT_INPUT_REQUIRED) {
+ sp_buf_clear(&t->answer);
+ (void)sp_buf_puts(&t->answer, g_ir_msg);
+ task_json(&out, t);
+ rpc_result(fd, id, out.p != NULL ? out.p : "{}");
+ goto send_out;
+ }
+ if (rc != 0) {
+ sp_reply_free(&ag->pending);
+ ag->has_pending = 0;
+ ag->pending_from = 0;
+ g_ir_task[0] = '\0';
+ g_ir_context[0] = '\0';
+ task_update(t, "TASK_STATE_FAILED", &err);
+ rpc_error(fd, id, -32603,
+ err.p != NULL && err.len > 0 ? err.p :
+ "the turn failed");
+ goto send_out;
+ }
+ task_update(t, "TASK_STATE_COMPLETED", &answer);
+ g_ir_task[0] = '\0';
+ g_ir_context[0] = '\0';
+ g_ir_msg[0] = '\0';
+ task_json(&out, t);
+ rpc_result(fd, id, out.p != NULL ? out.p : "{}");
+ push_task(&push, t);
+ goto send_out;
+ }
ctx = mcp_arg_string(message, "contextId");
if (ctx == NULL || *ctx == '\0') {
snprintf(ctxbuf, sizeof(ctxbuf), "ctx-%d-%u",
@@ -1136,13 +1314,29 @@ handle_rpc(int fd, struct sp_agent *ag, const char *payload)
rpc_error(fd, id, -32603, "out of memory for a context");
goto send_out;
}
- rc = push_parse(params, &push, &perr);
- if (rc < 0) {
- rpc_error(fd, id, rc == -2 ? -32003 : -32602, perr.p);
+ g_ir_task[0] = '\0';
+ g_ir_context[0] = '\0';
+ g_ir_msg[0] = '\0';
+ rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "",
+ a2a_approve, &answer, &err);
+ if (rc == SP_AGENT_INPUT_REQUIRED) {
+ char tid[64];
+ struct a2a_task *t;
+
+ gen_task_id(tid, sizeof(tid));
+ t = task_store_state(tid, ctx,
+ "TASK_STATE_INPUT_REQUIRED", g_ir_msg);
+ if (t == NULL) {
+ rpc_error(fd, id, -32603, "out of memory");
+ goto send_out;
+ }
+ snprintf(g_ir_task, sizeof(g_ir_task), "%s", t->id);
+ snprintf(g_ir_context, sizeof(g_ir_context), "%s",
+ t->context);
+ task_json(&out, t);
+ rpc_result(fd, id, out.p != NULL ? out.p : "{}");
goto send_out;
}
- rc = run_turn(ag, &cx->conv, text.p != NULL ? text.p : "",
- &answer, &err);
if (rc != 0) {
rpc_error(fd, id, -32603,
err.p != NULL && err.len > 0 ? err.p :
@@ -1222,14 +1416,48 @@ send_out:
} else if (strcmp(method, "SendStreamingMessage") == 0) {
handle_stream(fd, ag, id, params);
} else if (strcmp(method, "CancelTask") == 0) {
- const char *tid = mcp_arg_string(params, "id");
+ const char *tid = mcp_arg_string(params, "id");
+ struct a2a_task *t;
- if (tid == NULL || *tid == '\0')
+ if (tid == NULL || *tid == '\0') {
rpc_error(fd, id, -32602, "id is required");
- else if (task_find(tid) == NULL)
+ mcp_json_free(v);
+ return;
+ }
+ t = task_find(tid);
+ if (t == NULL) {
rpc_error(fd, id, -32001, "task not found");
- else
+ mcp_json_free(v);
+ return;
+ }
+ if (strcmp(t->state, "TASK_STATE_INPUT_REQUIRED") == 0) {
+ struct sp_buf out, msg;
+
+ if (ag->has_pending) {
+ sp_reply_free(&ag->pending);
+ ag->has_pending = 0;
+ ag->pending_from = 0;
+ }
+ if (strcmp(g_ir_task, t->id) == 0)
+ g_ir_task[0] = '\0';
+ g_ir_context[0] = '\0';
+ g_ir_msg[0] = '\0';
+ memset(&msg, 0, sizeof(msg));
+ sp_buf_init(&msg);
+ sp_buf_puts(&msg, "task canceled");
+ task_update(t, "TASK_STATE_CANCELED", &msg);
+ sp_buf_free(&msg);
+ memset(&out, 0, sizeof(out));
+ if (sp_buf_init(&out) != 0) {
+ rpc_error(fd, id, -32603, "out of memory");
+ } else {
+ task_json(&out, t);
+ rpc_result(fd, id, out.p != NULL ? out.p : "{}");
+ sp_buf_free(&out);
+ }
+ } else {
rpc_error(fd, id, -32002, "task is already completed");
+ }
} else if (strcmp(method, "SubscribeToTask") == 0) {
rpc_error(fd, id, -32004, "subscription is not served; use "
"SendStreamingMessage");
@@ -1525,6 +1753,14 @@ sp_a2a_serve(struct sp_agent *ag, const char *ip, int port, struct sp_buf *err)
}
for (i = 0; i < 32; i++)
g_pcfg[i].used = 0;
+ if (ag->has_pending) {
+ sp_reply_free(&ag->pending);
+ ag->has_pending = 0;
+ ag->pending_from = 0;
+ }
+ g_ir_task[0] = '\0';
+ g_ir_context[0] = '\0';
+ g_ir_msg[0] = '\0';
}
fprintf(stderr, "splinter: A2A server stopped\n");
return 0;
diff --git a/src/agent.c b/src/agent.c
index 8247bad..5da74ea 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -194,17 +194,23 @@ ask_operator(struct sp_agent *a, const struct sp_tool *t, const char *args)
}
/* The observation is always written: an error is an observation too. */
-static void
+/*
+ * 0 = ran (obs is the observation), 1 = a person has to decide first (nothing
+ * ran). have_decision/decision are used by a resume: the decision applies to
+ * the pending calls instead of asking again.
+ */
+static int
run_one_call(struct sp_agent *a, const struct sp_toolcall *call,
- struct sp_buf *obs)
+ struct sp_buf *obs, int have_decision, int decision)
{
const struct sp_tool *t;
+ int verdict;
a->stats.tool_calls++;
t = sp_registry_find(a->reg, call->name);
if (t == NULL) {
sp_buf_printf(obs, "error: unknown tool '%s'", call->name);
- return;
+ return 0;
}
/*
* A gate may decide before anybody else: a plugin's policy (kid mode, a
@@ -213,87 +219,114 @@ run_one_call(struct sp_agent *a, const struct sp_toolcall *call,
*/
if (a->host != NULL) {
char reason[256];
- int verdict = sp_host_gate(a->host, t->name, (int)t->auth,
- call->args, reason, sizeof(reason));
+ verdict = sp_host_gate(a->host, t->name, (int)t->auth,
+ call->args, reason, sizeof(reason));
if (verdict == 0) {
a->stats.denied++;
sp_buf_printf(obs, "denied: %s", reason[0] != '\0' ?
reason : "by policy");
sp_logf("gate", "%s denied: %s", t->name, reason);
- return;
+ return 0;
}
if (verdict == 1) {
if (t->run(call->args, obs, t->ctx) != 0)
sp_buf_printf(obs, "error: tool '%s' failed",
call->name);
- return;
+ return 0;
}
}
- if (t->auth != SP_AUTH_READ && !a->cfg->autonomous &&
- !ask_operator(a, t, call->args)) {
- a->stats.denied++;
- sp_buf_puts(obs, "error: denied by operator");
- return;
+ if (t->auth != SP_AUTH_READ && !a->cfg->autonomous) {
+ if (have_decision)
+ verdict = decision ? 1 : 0;
+ else {
+ verdict = ask_operator(a, t, call->args);
+ if (verdict == 2)
+ return 1; /* pause; nothing has run */
+ }
+ if (!verdict) {
+ a->stats.denied++;
+ sp_buf_puts(obs, "error: denied by operator");
+ return 0;
+ }
}
if (t->run(call->args, obs, t->ctx) != 0)
sp_buf_printf(obs, "error: tool '%s' failed", call->name);
+ return 0;
}
-int
-sp_agent_run(struct sp_agent *a, const char *user_text, struct sp_buf *answer,
- struct sp_buf *err)
+/* run one call and add its observation; 1 means approval is still required */
+static int
+run_one(struct sp_agent *a, struct sp_conv *conv,
+ const struct sp_toolcall *call, int have_decision, int decision,
+ struct sp_buf *obs, struct sp_buf *err)
+{
+ struct sp_msg tm;
+ int rc;
+
+ sp_buf_clear(obs);
+ sp_logf("tool", "%s %s", call->name,
+ call->args != NULL ? call->args : "");
+ if (a->cfg->tool_begin != NULL)
+ a->cfg->tool_begin(a->cfg->tool_begin_ctx, call->name,
+ call->args);
+ rc = run_one_call(a, call, obs, have_decision, decision);
+ if (rc != 0)
+ return rc;
+ if (a->cfg->tool_end != NULL)
+ a->cfg->tool_end(a->cfg->tool_end_ctx, call->name,
+ obs->p != NULL ? obs->p : "");
+ sp_logf("observation", "%s", obs->p != NULL ? obs->p : "");
+ if (obs->p != NULL && strncmp(obs->p, "error", 5) == 0)
+ sp_logf("tool failed", "%s: %s", call->name, obs->p);
+ memset(&tm, 0, sizeof(tm));
+ tm.role = "tool";
+ tm.name = call->name;
+ tm.call_id = call->id;
+ tm.content = obs->p;
+ if (sp_conv_add(conv, &tm) != 0) {
+ sp_buf_puts(err, "agent: out of memory");
+ return -1;
+ }
+ if (a->sess != NULL &&
+ sp_session_append(a->sess, "observation", obs->p, err) != 0)
+ return -1;
+ return 0;
+}
+
+static int
+agent_loop(struct sp_agent *a, struct sp_conv *conv, int resume, int decision,
+ struct sp_buf *answer, struct sp_buf *err)
{
- struct sp_conv local;
- struct sp_conv *conv;
struct sp_buf obs;
size_t step, i;
int rc = -1;
- if (a == NULL || a->reg == NULL || a->cfg == NULL)
- return -1;
- if (a->cfg->max_steps == 0)
- return -1;
-
- if (a->conv != NULL) {
- conv = a->conv;
- } else {
- sp_conv_init(&local);
- conv = &local;
- }
-
- sp_buf_clear(answer);
- /* the turn counter is what a plugin like 'focus' schedules against */
- /*
- * A turn gate runs before the model does. Kid mode ends the day here: the
- * child gets a sentence, the model gets nothing to answer.
- */
- if (a->host != NULL) {
- char msg[256];
-
- msg[0] = '\0';
- if (sp_host_turn_blocked(a->host, msg, sizeof(msg))) {
- sp_buf_puts(answer, msg[0] != '\0' ? msg :
- "today is over");
- return 0;
- }
- }
- sp_host_turn(a->host);
if (sp_buf_init(&obs) != 0) {
sp_buf_puts(err, "agent: out of memory");
- if (conv == &local)
- sp_conv_free(&local);
return -1;
}
- if (sp_conv_push(conv, "user", NULL, user_text) != 0) {
- sp_buf_puts(err, "agent: out of memory");
- goto out;
- }
- if (a->sess != NULL &&
- sp_session_append(a->sess, "user", user_text, err) != 0)
- goto out;
+ if (resume) {
+ if (!a->has_pending || a->pending_from > a->pending.ncalls) {
+ sp_buf_puts(err, "agent: no turn is waiting for input");
+ goto out;
+ }
+ for (i = a->pending_from; i < a->pending.ncalls; i++) {
+ int r = run_one(a, conv, &a->pending.calls[i], 1,
+ decision, &obs, err);
+ if (r != 0) {
+ if (r > 0)
+ sp_buf_puts(err, "agent: approval "
+ "needed again");
+ goto out;
+ }
+ }
+ sp_reply_free(&a->pending);
+ a->has_pending = 0;
+ a->pending_from = 0;
+ }
for (step = 0; step < a->cfg->max_steps; step++) {
struct sp_reply reply;
size_t sent;
@@ -438,34 +471,23 @@ sp_agent_run(struct sp_agent *a, const char *user_text, struct sp_buf *answer,
}
}
for (i = 0; i < reply.ncalls; i++) {
- struct sp_msg tm;
+ int r = run_one(a, conv, &reply.calls[i], 0, 0, &obs,
+ err);
- sp_buf_clear(&obs);
- sp_logf("tool", "%s %s", reply.calls[i].name,
- reply.calls[i].args != NULL ? reply.calls[i].args : "");
- if (a->cfg->tool_begin != NULL)
- a->cfg->tool_begin(a->cfg->tool_begin_ctx,
- reply.calls[i].name, reply.calls[i].args);
- run_one_call(a, &reply.calls[i], &obs);
- sp_logf("observation", "%s", obs.p != NULL ? obs.p : "");
- if (obs.p != NULL && strncmp(obs.p, "error", 5) == 0)
- sp_logf("tool failed", "%s: %s",
- reply.calls[i].name, obs.p);
- if (a->cfg->tool_end != NULL)
- a->cfg->tool_end(a->cfg->tool_end_ctx,
- reply.calls[i].name, obs.p != NULL ? obs.p : "");
- memset(&tm, 0, sizeof(tm));
- tm.role = "tool";
- tm.name = reply.calls[i].name;
- tm.call_id = reply.calls[i].id;
- tm.content = obs.p;
- if (sp_conv_add(conv, &tm) != 0) {
- sp_reply_free(&reply);
- goto oom;
+ if (r == 1) {
+ /*
+ * Pause with the assistant message already in the
+ * conversation; the calls from here on have no
+ * observation yet. The next run resumes them.
+ */
+ a->pending = reply;
+ memset(&reply, 0, sizeof(reply));
+ a->pending_from = i;
+ a->has_pending = 1;
+ rc = SP_AGENT_INPUT_REQUIRED;
+ goto out;
}
- if (a->sess != NULL &&
- sp_session_append(a->sess, "observation", obs.p,
- err) != 0) {
+ if (r != 0) {
sp_reply_free(&reply);
goto out;
}
@@ -481,7 +503,84 @@ oom:
sp_buf_puts(err, "agent: out of memory");
out:
sp_buf_free(&obs);
+ return rc;
+}
+
+int
+sp_agent_run(struct sp_agent *a, const char *user_text, struct sp_buf *answer,
+ struct sp_buf *err)
+{
+ struct sp_conv local;
+ struct sp_conv *conv;
+ int rc;
+
+ if (a == NULL || a->reg == NULL || a->cfg == NULL)
+ return -1;
+ if (a->cfg->max_steps == 0)
+ return -1;
+ if (a->has_pending) {
+ sp_buf_puts(err, "agent: a turn is waiting for input");
+ return -1;
+ }
+ if (a->conv != NULL) {
+ conv = a->conv;
+ } else {
+ sp_conv_init(&local);
+ conv = &local;
+ }
+ sp_buf_clear(answer);
+ /*
+ * A turn gate runs before the model does. Kid mode ends the day here: the
+ * child gets a sentence, the model gets nothing to answer.
+ */
+ if (a->host != NULL) {
+ char msg[256];
+
+ msg[0] = '\0';
+ if (sp_host_turn_blocked(a->host, msg, sizeof(msg))) {
+ sp_buf_puts(answer, msg[0] != '\0' ? msg :
+ "today is over");
+ if (conv == &local)
+ sp_conv_free(&local);
+ return 0;
+ }
+ }
+ sp_host_turn(a->host);
+ if (sp_conv_push(conv, "user", NULL, user_text) != 0) {
+ sp_buf_puts(err, "agent: out of memory");
+ if (conv == &local)
+ sp_conv_free(&local);
+ return -1;
+ }
+ if (a->sess != NULL &&
+ sp_session_append(a->sess, "user", user_text, err) != 0) {
+ if (conv == &local)
+ sp_conv_free(&local);
+ return -1;
+ }
+ rc = agent_loop(a, conv, 0, 0, answer, err);
+ if (rc == SP_AGENT_INPUT_REQUIRED && conv == &local) {
+ /* nowhere to resume from: do not leave a dangling pending turn */
+ sp_reply_free(&a->pending);
+ a->has_pending = 0;
+ a->pending_from = 0;
+ sp_buf_puts(err, "agent: input required without a persistent "
+ "conversation");
+ rc = -1;
+ }
if (conv == &local)
sp_conv_free(&local);
return rc;
}
+
+int
+sp_agent_resume(struct sp_agent *a, int decision, struct sp_buf *answer,
+ struct sp_buf *err)
+{
+ if (a == NULL || a->cfg == NULL || a->conv == NULL || !a->has_pending) {
+ sp_buf_puts(err, "agent: no turn is waiting for input");
+ return -1;
+ }
+ sp_buf_clear(answer);
+ return agent_loop(a, a->conv, 1, decision ? 1 : 0, answer, err);
+}
diff --git a/src/www/index.en.html b/src/www/index.en.html
index e041870..f889564 100644
--- a/src/www/index.en.html
+++ b/src/www/index.en.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
An agent harness you own: chat in the terminal, tools with authorization classes, plugins, any model that speaks OpenAI — built by us so we can change it, instead of getting used to how somebody else's client behaves.
-25291 lines of C99/POSIX ·
-25 tools · 32 test programs ·
+
25639 lines of C99/POSIX ·
+25 tools · 33 test programs ·
16 plugins · 42 palettes · BSD-3-Clause
What it is
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so
Building
$ git clone ssh://host/home/git/splinter.git
$ cd splinter && make small, nothing but libc and curses
-$ make check 32 test programs, plus the i18n checker
+$ make check 33 test programs, plus the i18n checker
$ ./splinter chat, the config is read
$ ./splinter --daemon Telegram gateway
POSIX make, C99, -Wall -Wextra -Werror. NetBSD curses is vendored, so the binary does not depend on a distribution's mood.
@@ -213,7 +213,9 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
conversation; without one the server makes one and returns it. A
taskPushNotificationConfig posts the completed task to a webhook
(loopback or SPLINTER_A2A_PUSH_ALLOW); push configs can be managed
-with CRUD and text/plain URLs are fetched from allowed hosts. Beyond loopback the bearer
+with CRUD and text/plain URLs are fetched from allowed hosts. A mutating tool pauses as
+INPUT_REQUIRED; a follow-up with taskId and
+yes/no resumes. Beyond loopback the bearer
token is required.
Kid mode
diff --git a/src/www/index.html b/src/www/index.html
index 2ab484a..0e7304b 100644
--- a/src/www/index.html
+++ b/src/www/index.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
Ein Agent-Harness, das dir gehoert: Chat im Terminal, Werkzeuge mit Autorisierungsklassen, Plugins, jedes Modell das OpenAI spricht — von uns gebaut, damit wir es umbauen koennen, statt uns an das Verhalten eines fremden Clients zu gewoehnen.
-25291 Zeilen C99/POSIX ·
-25 Werkzeuge · 32 Test-Programme ·
+
25639 Zeilen C99/POSIX ·
+25 Werkzeuge · 33 Test-Programme ·
16 Plugins · 42 Farbschemata · BSD-3-Clause
Was es ist
@@ -152,7 +152,7 @@ plugin = plugins/reminder/reminder.so
Bauen
$ git clone ssh://host/home/git/splinter.git
$ cd splinter && make klein, nichts ausser libc und curses
-$ make check 32 Test-Programme, plus i18n-Pruefer
+$ make check 33 Test-Programme, plus i18n-Pruefer
$ ./splinter Chat, Konfiguration wird gelesen
$ ./splinter --daemon Telegram-Gateway
POSIX make, C99, -Wall -Wextra -Werror. Die NetBSD-curses liegt im Baum, damit das Binary nicht von der Laune einer Distribution abhaengt.
@@ -215,7 +215,9 @@ Konversation; ohne eines legt der Server eins an und gibt es zurueck. Eine
taskPushNotificationConfig schickt den fertigen Task an einen
Webhook (Loopback oder SPLINTER_A2A_PUSH_ALLOW); Push-Configs
lassen sich per CRUD verwalten, text/plain-URLs werden von erlaubten Hosts
-geholt. Jenseits von
+geholt. Ein mutierendes Werkzeug pausiert als
+INPUT_REQUIRED; ein Folgeaufruf mit taskId und
+yes/no setzt fort. Jenseits von
Loopback ist der Bearer-Token Pflicht.
Kindermodus
diff --git a/src/www/index.pt.html b/src/www/index.pt.html
index b9fe239..19e779b 100644
--- a/src/www/index.pt.html
+++ b/src/www/index.pt.html
@@ -53,8 +53,8 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
splinter_
Um harness de agente que e seu: chat no terminal, ferramentas com classes de autorizacao, plugins, qualquer modelo que fale OpenAI - escrito por nos para poder mudar-lo, em vez de nos acostumar com o comportamento de um cliente alheio.
-25291 linhas C99/POSIX ·
-25 ferramentas · 32 programas de teste ·
+
25639 linhas C99/POSIX ·
+25 ferramentas · 33 programas de teste ·
16 plugins · 42 paletas · BSD-3-Clause
O que e
@@ -117,7 +117,7 @@ botoes Sim/Nao.
Compilar
make
-make check # 32 binarios de teste, i18n, site
+make check # 33 binarios de teste, i18n, site
Sem dependencias alem de libc e pthread; ncurses vem do vendor.
O que nao e
@@ -162,7 +162,9 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
sem ele o servidor cria um e devolve. Uma taskPushNotificationConfig
envia a tarefa concluida para um webhook (loopback ou
SPLINTER_A2A_PUSH_ALLOW); configs de push podem ser gerenciadas por
-CRUD e URLs text/plain sao buscadas de hosts permitidos. Fora do loopback o token Bearer e obrigatorio.
+CRUD e URLs text/plain sao buscadas de hosts permitidos. Uma ferramenta mutante pausa como
+INPUT_REQUIRED; um acompanhamento com taskId e
+yes/no continua. Fora do loopback o token Bearer e obrigatorio.
diff --git a/tests/test_a2a_input.sh b/tests/test_a2a_input.sh
new file mode 100755
index 0000000..b29ba0e
--- /dev/null
+++ b/tests/test_a2a_input.sh
@@ -0,0 +1,109 @@
+#!/bin/sh
+# splinter -- A2A INPUT_REQUIRED: a turn pauses before a mutating tool and
+# resumes with a task id and a yes/no answer.
+#
+# The script transport is the model: first a write call, then the answer. The
+# first SendMessage must return TASK_STATE_INPUT_REQUIRED without running the
+# tool; the follow-up with taskId "yes" runs it and completes; "no" completes
+# without writing.
+set -u
+cd "$(dirname "$0")/.." || exit 1
+D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-ir-XXXXXX") || exit 1
+P=$((20000 + ($$ % 20000)))
+P2=$((P + 1))
+P3=$((P + 2))
+S1=
+S2=
+S3=
+cleanup() {
+ [ -n "$S1" ] && kill "$S1" 2>/dev/null
+ [ -n "$S2" ] && kill "$S2" 2>/dev/null
+ [ -n "$S3" ] && kill "$S3" 2>/dev/null
+ rm -rf "$D"
+}
+trap cleanup EXIT
+mkdir -p "$D/home"
+
+fails=0
+check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
+wait_port() {
+ for i in $(seq 1 100); do
+ curl -s -o /dev/null "http://127.0.0.1:$1/" && return 0
+ sleep 0.2
+ done
+ return 1
+}
+post() { # post
+ curl -s -H 'Content-Type: application/json' --data "$2" \
+ "http://127.0.0.1:$1/a2a"
+}
+first() { # first
+ post "$1" '{"jsonrpc":"2.0","id":"1","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"text":"please write"}]}}}'
+}
+follow() { # follow
+ post "$1" "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m2\",\"role\":\"ROLE_USER\",\"taskId\":\"$2\",\"parts\":[{\"text\":\"$3\"}]}}}"
+}
+state_of() {
+ printf '%s' "$1" | python3 -c \
+ 'import json,sys; print(json.load(sys.stdin)["result"]["task"]["status"]["state"])'
+}
+task_of() {
+ printf '%s' "$1" | python3 -c \
+ 'import json,sys; print(json.load(sys.stdin)["result"]["task"]["id"])'
+}
+
+# ---- yes: pause, then run the write ----
+printf 'tool write {"path":"%s/written.txt","content":"yes"}\nanswer done\n' \
+ "$D" > "$D/model.txt"
+HOME="$D/home" ./splinter --no-config --script "$D/model.txt" \
+ --a2a-server-listen 127.0.0.1 --a2a-listen-port "$P" \
+ > "$D/gw1.out" 2>&1 &
+S1=$!
+check wait_port "$P"
+
+r=$(first "$P")
+check test "$(state_of "$r")" = "TASK_STATE_INPUT_REQUIRED"
+tid=$(task_of "$r")
+check test -n "$tid"
+check test ! -e "$D/written.txt"
+
+r=$(follow "$P" "$tid" "yes")
+check test "$(state_of "$r")" = "TASK_STATE_COMPLETED"
+check test -e "$D/written.txt"
+check grep -q 'yes' "$D/written.txt"
+
+# ---- no: pause, then complete without the write ----
+printf 'tool write {"path":"%s/notwritten.txt","content":"no"}\nanswer done\n' \
+ "$D" > "$D/model2.txt"
+HOME="$D/home2" ./splinter --no-config --script "$D/model2.txt" \
+ --a2a-server-listen 127.0.0.1 --a2a-listen-port "$P2" \
+ > "$D/gw2.out" 2>&1 &
+S2=$!
+check wait_port "$P2"
+
+r=$(first "$P2")
+check test "$(state_of "$r")" = "TASK_STATE_INPUT_REQUIRED"
+tid=$(task_of "$r")
+r=$(follow "$P2" "$tid" "no")
+check test "$(state_of "$r")" = "TASK_STATE_COMPLETED"
+check test ! -e "$D/notwritten.txt"
+
+# ---- cancel a task that is waiting for input ----
+printf 'tool write {"path":"%s/canceled.txt","content":"x"}\nanswer done\n' \
+ "$D" > "$D/model3.txt"
+HOME="$D/home3" ./splinter --no-config --script "$D/model3.txt" \
+ --a2a-server-listen 127.0.0.1 --a2a-listen-port "$P3" \
+ > "$D/gw3.out" 2>&1 &
+S3=$!
+check wait_port "$P3"
+r=$(first "$P3")
+check test "$(state_of "$r")" = "TASK_STATE_INPUT_REQUIRED"
+tid=$(task_of "$r")
+r=$(post "$P3" "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\":\"CancelTask\",\"params\":{\"id\":\"$tid\"}}")
+check test "$(state_of "$r")" = "TASK_STATE_CANCELED"
+check test ! -e "$D/canceled.txt"
+
+if [ "$fails" -eq 0 ]; then echo "test_a2a_input: ok"; exit 0; fi
+echo "--- gw1 ---"; tail -5 "$D/gw1.out" 2>/dev/null
+echo "--- gw2 ---"; tail -5 "$D/gw2.out" 2>/dev/null
+exit 1
diff --git a/tests/test_pause.c b/tests/test_pause.c
new file mode 100644
index 0000000..60baad6
--- /dev/null
+++ b/tests/test_pause.c
@@ -0,0 +1,130 @@
+/*
+ * splinter -- a turn that pauses for approval and resumes.
+ *
+ * The tool has not run when the turn returns SP_AGENT_INPUT_REQUIRED: the
+ * assistant call is in the conversation, no observation is. Resuming with a
+ * decision runs the pending call, adds its observation and continues the
+ * model loop. A denial is an observation too, and the turn still ends.
+ */
+#include
+#include
+
+#include "splinter.h"
+
+static int failures;
+static int ran;
+
+#define CHECK(cond) do { \
+ if (!(cond)) { \
+ fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
+ failures++; \
+ } \
+} while (0)
+
+static int
+write_tool(const char *args, struct sp_buf *out, void *ctx)
+{
+ (void)args;
+ (void)ctx;
+ ran++;
+ return sp_buf_puts(out, "written");
+}
+
+static int
+approve(void *ctx, const char *name, int auth, const char *args)
+{
+ (void)name;
+ (void)auth;
+ (void)args;
+ return *(int *)ctx;
+}
+
+int
+main(void)
+{
+ struct sp_registry r;
+ struct sp_tool t;
+ struct sp_agent a;
+ struct sp_agent_config cfg;
+ struct sp_conv conv;
+ struct sp_mock m;
+ struct sp_buf answer, err;
+ int verdict;
+
+ memset(&r, 0, sizeof(r));
+ memset(&t, 0, sizeof(t));
+ t.name = "write";
+ t.description = "mutate";
+ t.auth = SP_AUTH_MUTATE;
+ t.run = write_tool;
+ CHECK(sp_registry_add(&r, &t) == 0);
+
+ memset(&a, 0, sizeof(a));
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.max_steps = 5;
+ cfg.autonomous = 0;
+ cfg.approve = approve;
+ cfg.approve_ctx = &verdict;
+ cfg.approve_is_channel = 1;
+ sp_conv_init(&conv);
+ a.reg = &r;
+ a.cfg = &cfg;
+ a.conv = &conv;
+ CHECK(sp_buf_init(&answer) == 0);
+ CHECK(sp_buf_init(&err) == 0);
+
+ /* a call that needs a person: the turn stops before it runs */
+ CHECK(sp_mock_init(&m) == 0);
+ CHECK(sp_mock_push(&m, 200, "tool write x") == 0);
+ CHECK(sp_mock_push(&m, 200, "answer done") == 0);
+ a.tr = sp_mock_transport(&m);
+ verdict = 2;
+ CHECK(sp_agent_run(&a, "go", &answer, &err) == SP_AGENT_INPUT_REQUIRED);
+ CHECK(ran == 0);
+ CHECK(a.has_pending == 1);
+ CHECK(conv.n >= 2);
+ CHECK(strcmp(conv.v[conv.n - 1].role, "assistant") == 0);
+
+ /* yes: the pending call runs, its observation goes back, the turn ends */
+ CHECK(sp_agent_resume(&a, 1, &answer, &err) == 0);
+ CHECK(ran == 1);
+ CHECK(a.has_pending == 0);
+ CHECK(strcmp(answer.p, "done") == 0);
+ CHECK(strstr(m.last_request.p, "observe write written") != NULL);
+ sp_mock_free(&m);
+ sp_conv_free(&conv);
+
+ /* no: the call does not run, but it is an observation and the turn ends */
+ ran = 0;
+ memset(&a, 0, sizeof(a));
+ memset(&cfg, 0, sizeof(cfg));
+ cfg.max_steps = 5;
+ cfg.approve = approve;
+ cfg.approve_ctx = &verdict;
+ cfg.approve_is_channel = 1;
+ sp_conv_init(&conv);
+ a.reg = &r;
+ a.cfg = &cfg;
+ a.conv = &conv;
+ CHECK(sp_mock_init(&m) == 0);
+ CHECK(sp_mock_push(&m, 200, "tool write x") == 0);
+ CHECK(sp_mock_push(&m, 200, "answer done") == 0);
+ a.tr = sp_mock_transport(&m);
+ verdict = 2;
+ CHECK(sp_agent_run(&a, "go", &answer, &err) == SP_AGENT_INPUT_REQUIRED);
+ CHECK(sp_agent_resume(&a, 0, &answer, &err) == 0);
+ CHECK(ran == 0);
+ CHECK(a.has_pending == 0);
+ CHECK(strstr(m.last_request.p, "observe write") != NULL);
+ CHECK(strstr(m.last_request.p, "denied by operator") != NULL);
+ sp_mock_free(&m);
+ sp_conv_free(&conv);
+
+ sp_buf_free(&answer);
+ sp_buf_free(&err);
+ sp_registry_free(&r);
+
+ if (failures == 0)
+ printf("test_pause: ok\n");
+ return failures == 0 ? 0 : 1;
+}
diff --git a/tools/gen_www.py b/tools/gen_www.py
index 760d72d..a37feef 100644
--- a/tools/gen_www.py
+++ b/tools/gen_www.py
@@ -461,7 +461,9 @@ Konversation; ohne eines legt der Server eins an und gibt es zurueck. Eine
taskPushNotificationConfig schickt den fertigen Task an einen
Webhook (Loopback oder SPLINTER_A2A_PUSH_ALLOW); Push-Configs
lassen sich per CRUD verwalten, text/plain-URLs werden von erlaubten Hosts
-geholt. Jenseits von
+geholt. Ein mutierendes Werkzeug pausiert als
+INPUT_REQUIRED; ein Folgeaufruf mit taskId und
+yes/no setzt fort. Jenseits von
Loopback ist der Bearer-Token Pflicht.""",
]
@@ -511,7 +513,9 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
conversation; without one the server makes one and returns it. A
taskPushNotificationConfig posts the completed task to a webhook
(loopback or SPLINTER_A2A_PUSH_ALLOW); push configs can be managed
-with CRUD and text/plain URLs are fetched from allowed hosts. Beyond loopback the bearer
+with CRUD and text/plain URLs are fetched from allowed hosts. A mutating tool pauses as
+INPUT_REQUIRED; a follow-up with taskId and
+yes/no resumes. Beyond loopback the bearer
token is required.""",
]
@@ -607,7 +611,9 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
sem ele o servidor cria um e devolve. Uma taskPushNotificationConfig
envia a tarefa concluida para um webhook (loopback ou
SPLINTER_A2A_PUSH_ALLOW); configs de push podem ser gerenciadas por
-CRUD e URLs text/plain sao buscadas de hosts permitidos. Fora do loopback o token Bearer e obrigatorio.""",
+CRUD e URLs text/plain sao buscadas de hosts permitidos. Uma ferramenta mutante pausa como
+INPUT_REQUIRED; um acompanhamento com taskId e
+yes/no continua. Fora do loopback o token Bearer e obrigatorio.""",
]