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; }
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.
-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; }
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.
-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; }
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.
-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.
$ 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.