From 544399a3bfa15098ebde954a6fa289c5cf6fe6cd Mon Sep 17 00:00:00 2001
From: lotherk
Date: Tue, 10 Nov 2026 08:28:08 +0000
Subject: [PATCH] a2a: GetTask/CancelTask as client tools, and a spec-shaped
GetTask
The plugin registers a2a_get_task (read) and a2a_cancel_task
(destructive) for a local model that uses A2A as a tool source; both
share the endpoint or card and return the raw task/error JSON.
The server's GetTask result was wrapped as {"task": ...}; the spec's
result is the Task itself. Fixed, and the test checks the shape.
The website's tool-count regex missed digits, so a2a_get_task and
a2a_cancel_task were not counted; [a-z0-9_]+ now reports 25.
test_a2a drives both tools through the mock transport and checks the
session observations. Full make check green.
---
.gitignore | 3 +
TODO.md | 16 +++--
docs/PLUGINS.md | 10 +--
plugins/a2a/a2a.c | 139 +++++++++++++++++++++++++++++++++++++++
src/a2aserver.c | 3 +-
src/www/index.en.html | 6 +-
src/www/index.html | 6 +-
src/www/index.pt.html | 8 +--
tests/fake_a2a.py | 38 ++++++++---
tests/test_a2a.sh | 24 +++++++
tests/test_a2a_server.sh | 2 +
tools/gen_www.py | 2 +-
12 files changed, 226 insertions(+), 31 deletions(-)
diff --git a/.gitignore b/.gitignore
index 2cd757a..88a9ba3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,6 @@ plugins/*/*.so
tests/test_*
!tests/test_*.c
!tests/test_*.sh
+
+# python bytecode from the test helpers
+__pycache__/
diff --git a/TODO.md b/TODO.md
index 5e88650..8ef4c7f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -30,11 +30,14 @@ 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.
-Offen: die Fortsetzung eines unterbrochenen Tasks (`INPUT_REQUIRED`), die
-Push-Config-CRUD-Methoden und `GetTask`/`CancelTask` auf der Client-Seite.
+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":...}`).
-Naechster Schritt: Client-Polling (GetTask) oder ein pausierbarer Turn fuer
-INPUT_REQUIRED.
+Offen: die Fortsetzung eines unterbrochenen Tasks (`INPUT_REQUIRED`) und die
+Push-Config-CRUD-Methoden. URL- und binaere Teile bleiben bewusst abgelehnt.
+
+Naechster Schritt: ein pausierbarer Turn fuer INPUT_REQUIRED.
### 2. `~/.local/lib` enthaelt Fremdlast
@@ -79,8 +82,9 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code.
Artefakt-Text live) und findet den Endpunkt ueber `SPLINTER_A2A_CARD`;
`src/a2aserver.c` serviert `SendMessage`, `SendStreamingMessage` (SSE),
`GetTask`, `ListTasks`, Multiturn ueber `contextId`, text/plain-`raw`- und
- String-`data`-Teile, Webhook-Push und die Agent Card mit Bearer-Token; die
- Karte meldet `streaming:true` und `pushNotifications:true`. `tests/test_a2a.sh` prueft Task, Message, Token, Fehler,
+ String-`data`-Teile, Webhook-Push, `a2a_get_task`/`a2a_cancel_task` als
+ Client-Werkzeuge und die Agent Card mit Bearer-Token; die Karte meldet
+ `streaming:true` und `pushNotifications:true`. `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 493f258..50fff37 100644
--- a/docs/PLUGINS.md
+++ b/docs/PLUGINS.md
@@ -314,8 +314,10 @@ The endpoint can be configured directly (`SPLINTER_A2A_URL`) or discovered:
The discovered URL is kept for the session.
Not implemented yet on the client side, and named so nobody assumes otherwise:
-file/structured-data parts, push notifications, and `GetTask`/`CancelTask`
-(the client sends and streams; it does not poll or cancel).
+file/structured-data parts and push notifications (the client sends and streams). With a local
+transport, the plugin also registers `a2a_get_task` and `a2a_cancel_task`
+(read/destructive); both use the same endpoint or card and return the raw
+task/error JSON.
`tests/fake_a2a.py` and `tests/test_a2a.sh` pin the blocking wire shape, both
result forms, the bearer token, a JSON-RPC error, streaming and discovery;
`tests/test_a2a_ui.sh` drives the streaming path through tmux.
@@ -333,8 +335,8 @@ named by `contextId` (or a fresh one, whose id comes back in the task), stores
the completed Task and returns it;
`SendStreamingMessage` runs the same turn and writes SSE `artifactUpdate` events
as the transport produces text (a non-streaming transport sends its whole answer
-as one artifact), followed by a completed `statusUpdate`; `GetTask` returns a
-stored task and `ListTasks` lists them (optionally by `contextId`); `GET /.well-known/agent-card.json` serves a card with the `JSONRPC`
+as one artifact), followed by a completed `statusUpdate`; `GetTask` returns the
+stored Task itself and `ListTasks` lists them (optionally by `contextId`); `GET /.well-known/agent-card.json` serves a card with the `JSONRPC`
interface. One request at a time, one connection at a time.
A `taskPushNotificationConfig` in the `SendMessage`/`SendStreamingMessage`
diff --git a/plugins/a2a/a2a.c b/plugins/a2a/a2a.c
index acbb3e5..5cdbb85 100644
--- a/plugins/a2a/a2a.c
+++ b/plugins/a2a/a2a.c
@@ -932,6 +932,121 @@ out:
return rc;
}
+static const char *
+arg_id(const char *args, struct sp_buf *keep)
+{
+ mcp_json *v;
+ const char *sv;
+ const char *id = NULL;
+
+ if (args == NULL || args[0] != '{' || (v = mcp_parse(args)) == NULL)
+ return NULL;
+ sv = mcp_arg_string(v, "id");
+ if (sv != NULL && *sv != '\0' && sp_buf_puts(keep, sv) == 0)
+ id = keep->p;
+ mcp_json_free(v);
+ return id;
+}
+
+/* one JSON-RPC call whose result is a Task or an error; the raw answer is text */
+static int
+rpc(struct a2a_cfg *c, const char *method, const char *id, struct sp_buf *out,
+ struct sp_buf *err)
+{
+ struct sp_buf body, raw;
+ char rid[96], *nl;
+ long http;
+
+ if (discover(c, err) != 0)
+ return -1;
+ if (c->url[0] == '\0') {
+ sp_buf_puts(err, "a2a: neither SPLINTER_A2A_URL nor "
+ "SPLINTER_A2A_CARD is set");
+ return -1;
+ }
+ make_id(rid, sizeof(rid), "rpc");
+ if (sp_buf_init(&body) != 0 || sp_buf_init(&raw) != 0)
+ return -1;
+ if (sp_buf_printf(&body, "{\"jsonrpc\":\"2.0\",\"id\":\"%s\","
+ "\"method\":\"%s\",\"params\":{\"id\":\"", rid, method) != 0 ||
+ sp_json_escape(&body, id) != 0 ||
+ sp_buf_puts(&body, "\"}}") != 0 ||
+ post(c, body.p, &raw, err) != 0)
+ goto fail;
+ if (raw.len < 2 || (nl = strrchr(raw.p, '\n')) == NULL) {
+ sp_buf_puts(err, "a2a: unparseable response (no HTTP status)");
+ goto fail;
+ }
+ http = strtol(nl + 1, NULL, 10);
+ *nl = '\0';
+ if (http < 200 || http > 299) {
+ sp_buf_printf(err, "a2a: HTTP %ld: %.200s", http,
+ raw.p != NULL ? raw.p : "");
+ goto fail;
+ }
+ sp_buf_puts(out, raw.p);
+ sp_buf_free(&body);
+ sp_buf_free(&raw);
+ return 0;
+
+fail:
+ sp_buf_free(&body);
+ sp_buf_free(&raw);
+ return -1;
+}
+
+static int
+tool_get_task(const char *args, struct sp_buf *out, void *ctx)
+{
+ struct a2a_cfg *c = ctx;
+ struct sp_buf keep, err;
+ const char *id;
+ int rc;
+
+ if (sp_buf_init(&keep) != 0 || sp_buf_init(&err) != 0)
+ return -1;
+ id = arg_id(args, &keep);
+ if (id == NULL || *id == '\0') {
+ sp_buf_free(&keep);
+ sp_buf_free(&err);
+ return sp_buf_puts(out, "error: 'id' is required");
+ }
+ rc = rpc(c, "GetTask", id, out, &err);
+ if (rc != 0) {
+ sp_buf_puts(out, "error: ");
+ sp_buf_puts(out, err.p != NULL ? err.p : "request failed");
+ }
+ sp_buf_free(&keep);
+ sp_buf_free(&err);
+ return 0;
+}
+
+static int
+tool_cancel_task(const char *args, struct sp_buf *out, void *ctx)
+{
+ struct a2a_cfg *c = ctx;
+ struct sp_buf keep, err;
+ const char *id;
+ int rc;
+
+ if (sp_buf_init(&keep) != 0 || sp_buf_init(&err) != 0)
+ return -1;
+ id = arg_id(args, &keep);
+ if (id == NULL || *id == '\0') {
+ sp_buf_free(&keep);
+ sp_buf_free(&err);
+ return sp_buf_puts(out, "error: 'id' is required");
+ }
+ rc = rpc(c, "CancelTask", id, out, &err);
+ if (rc != 0) {
+ sp_buf_puts(out, "error: ");
+ sp_buf_puts(out, err.p != NULL ? err.p : "request failed");
+ }
+ sp_buf_free(&keep);
+ sp_buf_free(&err);
+ return 0;
+}
+
static int
a2a_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
struct sp_buf *err)
@@ -1024,6 +1139,30 @@ a2a_init(struct sp_host *h)
cfg.timeout = strtol(to, NULL, 10);
cfg.full = full != NULL && strcmp(full, "0") != 0;
+ {
+ static struct sp_tool t_get, t_cancel;
+
+ memset(&t_get, 0, sizeof(t_get));
+ t_get.name = "a2a_get_task";
+ t_get.description = "Poll an A2A task by id; returns the task JSON.";
+ t_get.params = "{\"type\":\"object\",\"properties\":{"
+ "\"id\":{\"type\":\"string\"}},\"required\":[\"id\"]}";
+ t_get.auth = SP_AUTH_READ;
+ t_get.run = tool_get_task;
+ t_get.ctx = &cfg;
+ (void)sp_host_add_tool(h, &t_get);
+
+ memset(&t_cancel, 0, sizeof(t_cancel));
+ t_cancel.name = "a2a_cancel_task";
+ t_cancel.description = "Cancel an A2A task by id; a completed task "
+ "answers TaskNotCancelable.";
+ t_cancel.params = t_get.params;
+ t_cancel.auth = SP_AUTH_DESTRUCTIVE;
+ t_cancel.run = tool_cancel_task;
+ t_cancel.ctx = &cfg;
+ (void)sp_host_add_tool(h, &t_cancel);
+ }
+
memset(&tr, 0, sizeof(tr));
tr.send = a2a_send;
tr.send_stream = a2a_stream;
diff --git a/src/a2aserver.c b/src/a2aserver.c
index ab07105..5f294ef 100644
--- a/src/a2aserver.c
+++ b/src/a2aserver.c
@@ -1016,7 +1016,8 @@ send_out:
mcp_json_free(v);
return;
}
- task_json(&out, t);
+ /* GetTask's result is the Task itself, not {"task": ...} */
+ task_obj(&out, t);
rpc_result(fd, id, out.p != NULL ? out.p : "{}");
sp_buf_free(&out);
} else if (strcmp(method, "ListTasks") == 0) {
diff --git a/src/www/index.en.html b/src/www/index.en.html
index d9b6e0d..ff98997 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.
-24853 lines of C99/POSIX ·
-23 tools · 32 test programs ·
+
24993 lines of C99/POSIX ·
+25 tools · 32 test programs ·
16 plugins · 42 palettes · BSD-3-Clause
What it is
@@ -187,7 +187,7 @@ in the header before anybody reads its prose.
As a client splinter fetches an MCP server's tools. As a server it offers its
own:
$ splinter --mcp-server-listen 0.0.0.0 --mcp-listen-port 8098
-splinter: MCP server on 0.0.0.0:8098 (23 tools, read only)
+splinter: MCP server on 0.0.0.0:8098 (25 tools, read only)
Another agent gets initialize, tools/list and
tools/call. Read tools are served; mutating and destructive ones only
with --autonomous — a foreign agent does not run shell commands
diff --git a/src/www/index.html b/src/www/index.html
index 8c0bb2d..c66ec06 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.
-24853 Zeilen C99/POSIX ·
-23 Werkzeuge · 32 Test-Programme ·
+
24993 Zeilen C99/POSIX ·
+25 Werkzeuge · 32 Test-Programme ·
16 Plugins · 42 Farbschemata · BSD-3-Clause
Was es ist
@@ -188,7 +188,7 @@ ist in der Kopfzeile sichtbar, bevor jemand seinen Text liest.
Als Client holt splinter die Werkzeuge eines MCP-Servers. Als Server stellt es
seine eigenen hin:
$ splinter --mcp-server-listen 0.0.0.0 --mcp-listen-port 8098
-splinter: MCP server on 0.0.0.0:8098 (23 tools, read only)
+splinter: MCP server on 0.0.0.0:8098 (25 tools, read only)
Ein anderer Agent bekommt initialize, tools/list und
tools/call. Lesende Werkzeuge werden bedient, mutierende und
destruktive nur mit --autonomous — ein fremder Agent fuehrt hier
diff --git a/src/www/index.pt.html b/src/www/index.pt.html
index 64560e8..500f4a5 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.
-24853 linhas C99/POSIX ·
-23 ferramentas · 32 programas de teste ·
+
24993 linhas C99/POSIX ·
+25 ferramentas · 32 programas de teste ·
16 plugins · 42 paletas · BSD-3-Clause
O que e
@@ -80,7 +80,7 @@ transcript na ordem em que acontecem.
entrar na frente com um gate: permitir, negar com motivo, ou nao opinar.
Ferramentas
-23 ferramentas: read, write, edit,
+
25 ferramentas: read, write, edit,
search, list, run, folder_history,
delegate, delegate_parallel, as de leitura do sistema e as de
skills, memoria e pesquisa na web.
@@ -133,7 +133,7 @@ poe suas proprias chaves.
As duas direcoes: MCP
$ splinter --mcp-server-listen 0.0.0.0 --mcp-listen-port 8098
-splinter: MCP server on 0.0.0.0:8098 (23 tools, read only)
+splinter: MCP server on 0.0.0.0:8098 (25 tools, read only)
Como cliente busca ferramentas; como servidor oferece as suas. Mutar so com
--autonomous.
diff --git a/tests/fake_a2a.py b/tests/fake_a2a.py
index dbf81b0..2f64a6d 100644
--- a/tests/fake_a2a.py
+++ b/tests/fake_a2a.py
@@ -32,6 +32,14 @@ class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass
+ def reply(self, obj, ctype="application/json"):
+ b = json.dumps(obj).encode()
+ self.send_response(200)
+ self.send_header("Content-Type", ctype)
+ self.send_header("Content-Length", str(len(b)))
+ self.end_headers()
+ self.wfile.write(b)
+
def do_GET(self):
port = self.server.server_address[1]
if self.path.endswith("old-card.json"):
@@ -51,6 +59,7 @@ class H(http.server.BaseHTTPRequestHandler):
self.wfile.write(b)
def do_POST(self):
+ global last_task
n = int(self.headers.get("Content-Length", 0))
raw = self.rfile.read(n)
with open(LOG, "a") as f:
@@ -65,6 +74,15 @@ class H(http.server.BaseHTTPRequestHandler):
pass
rid = req.get("id")
ctype = "text/event-stream" if stream else "application/json"
+ method = req.get("method", "")
+ if method == "GetTask":
+ task = last_task if last_task is not None else task_obj(
+ "TASK_STATE_COMPLETED", "a2a sagt hallo", "und tschuess")
+ return self.reply({"jsonrpc": "2.0", "id": rid, "result": task})
+ if method == "CancelTask":
+ return self.reply({"jsonrpc": "2.0", "id": rid,
+ "error": {"code": -32002,
+ "message": "TaskNotCancelable"}})
want_auth = "auth" in text
if want_auth and self.headers.get("Authorization") != "Bearer tok":
if stream:
@@ -90,15 +108,16 @@ class H(http.server.BaseHTTPRequestHandler):
b = json.dumps({"jsonrpc": "2.0", "id": rid,
"result": {"message": msg}}).encode()
elif "raw" in text:
- body = {"jsonrpc": "2.0", "id": rid, "result": {"task": {
- "id": "task-1", "contextId": "ctx-1",
- "status": {"state": "TASK_STATE_COMPLETED",
- "message": {"messageId": "m5",
- "role": "ROLE_AGENT",
- "parts": [{"text": "text teil"}]}},
- "artifacts": [{"artifactId": "a3", "parts": [
- {"raw": "aGFsbG8=", "mediaType": "text/plain"},
- {"data": "struktur"}]}]}}}
+ task = {"id": "task-1", "contextId": "ctx-1",
+ "status": {"state": "TASK_STATE_COMPLETED",
+ "message": {"messageId": "m5",
+ "role": "ROLE_AGENT",
+ "parts": [{"text": "text teil"}]}},
+ "artifacts": [{"artifactId": "a3", "parts": [
+ {"raw": "aGFsbG8=", "mediaType": "text/plain"},
+ {"data": "struktur"}]}]}
+ last_task = task
+ body = {"jsonrpc": "2.0", "id": rid, "result": {"task": task}}
b = json.dumps(body).encode()
elif stream and "streamstatus" in text:
b = (event(rid, {"task": task_obj("TASK_STATE_WORKING")}) +
@@ -135,6 +154,7 @@ class H(http.server.BaseHTTPRequestHandler):
else:
task = task_obj("TASK_STATE_COMPLETED", "a2a sagt hallo",
"und tschuess")
+ last_task = task
if stream:
b = event(rid, {"task": task}).encode()
else:
diff --git a/tests/test_a2a.sh b/tests/test_a2a.sh
index 73d5436..bc04c73 100755
--- a/tests/test_a2a.sh
+++ b/tests/test_a2a.sh
@@ -109,5 +109,29 @@ out=$(discovered "old-card.json" "hallo" 2>&1)
echo "$out" | grep -q 'a2a sagt hallo'
check test $? -eq 0
+# ---- the plugin's GetTask/CancelTask tools against the same agent ----
+mkdir -p "$D/home"
+printf 'tool a2a_get_task {"id":"task-1"}\nanswer done\n' > "$D/tool-get.txt"
+out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
+ SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
+ --plugin plugins/a2a/a2a.so --script "$D/tool-get.txt" \
+ -p "tool" --autonomous 2>&1)
+echo "$out" | grep -q '^done'
+check test $? -eq 0
+sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
+check test -n "$sess"
+check grep -q 'TASK_STATE_COMPLETED' "$sess"
+
+printf 'tool a2a_cancel_task {"id":"task-1"}\nanswer done\n' \
+ > "$D/tool-cancel.txt"
+out=$(HOME="$D/home" SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" \
+ SPLINTER_A2A_TIMEOUT=20 ./splinter --no-config \
+ --plugin plugins/a2a/a2a.so --script "$D/tool-cancel.txt" \
+ -p "tool" --autonomous 2>&1)
+echo "$out" | grep -q '^done'
+check test $? -eq 0
+sess=$(ls -t "$D/home/.splinter"/sess-*.jsonl 2>/dev/null | head -1)
+check grep -q -- '-32002' "$sess"
+
if [ "$fails" -eq 0 ]; then echo "test_a2a: ok"; exit 0; fi
exit 1
diff --git a/tests/test_a2a_server.sh b/tests/test_a2a_server.sh
index ce33a08..a56c148 100755
--- a/tests/test_a2a_server.sh
+++ b/tests/test_a2a_server.sh
@@ -77,6 +77,8 @@ id=$(printf '%s' "$resp" | python3 -c \
resp2=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"method\":\"GetTask\",\"params\":{\"id\":\"$id\"}}")
echo "$resp2" | grep -q 'hallo von splinter'
check test $? -eq 0
+echo "$resp2" | grep -q '"result":{"id":"task-'
+check test $? -eq 0
# streaming: SSE with an artifact and a completed status
resp3=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"3\",\"method\":\"SendStreamingMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",\"parts\":[{\"text\":\"hallo\"}]}}}")
diff --git a/tools/gen_www.py b/tools/gen_www.py
index ea35b80..f0ba59f 100644
--- a/tools/gen_www.py
+++ b/tools/gen_www.py
@@ -36,7 +36,7 @@ def counts():
tools = set()
for p in (list((ROOT / "src").glob("*.c")) +
list((ROOT / "plugins").glob("*/*.c"))):
- tools.update(re.findall(r'\.name = "([a-z_]+)"',
+ tools.update(re.findall(r'\.name = "([a-z0-9_]+)"',
p.read_text(encoding="utf-8")))
return {
"N_LINES": (_c_lines(ROOT / "src") + _c_lines(ROOT / "include") +