diff --git a/TODO.md b/TODO.md index 8ef4c7f..66e9c37 100644 --- a/TODO.md +++ b/TODO.md @@ -32,25 +32,23 @@ 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":...}`). +`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`) und die -Push-Config-CRUD-Methoden. URL- und binaere Teile bleiben bewusst abgelehnt. +Offen: die Fortsetzung eines unterbrochenen Tasks (`INPUT_REQUIRED`). Binaere +Teile bleiben bewusst abgelehnt. Naechster Schritt: ein pausierbarer Turn fuer INPUT_REQUIRED. -### 2. `~/.local/lib` enthaelt Fremdlast - -`~/.local/lib` ist ein Symlink auf `~/.local/npm`. Dort liegen `node_modules`, -`package.json` und `package-lock.json` aus einem frueheren Projekt (Maerz 2026) — -und seit `make install PREFIX=$HOME/.local` auch `libsplinter.so`. Nur die -npm-Dateien sind Fremdlast; das Verzeichnis ist inzwischen auch das -Installationsziel. - -Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code. - ## Erledigt +- **`~/.local/lib` entwirrt**: `~/.local/lib` ist jetzt ein echtes Verzeichnis + mit `libsplinter.so` und einem `node_modules`-Symlink auf + `../npm/node_modules`. Der npm-Baum ist keine Fremdlast: er enthaelt + `mcp-local-memory` (der MCP, auf den `~/.local/bin/mcp-local-memory` zeigt) + und die Python-User-Verzeichnisse. `npm root -g`, das Modul und + `~/.local/bin/splinter --version` sind geprueft; nichts geloescht. - **Kids-Zustimmung ueber echtes Telegram**: Am 2026-11-10 wurde Anfrage `548769685` an `@hbx_splinter_bot` geschickt; die Antwort `ok 548769685` kam im Chat, das Gateway loeste sie auf, der `write` lief und schrieb @@ -81,10 +79,12 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code. (JSON-RPC 2.0, Text, blockierend), in der UI `SendStreamingMessage` (SSE, 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, `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, + `GetTask`, `ListTasks`, Multiturn ueber `contextId`, text/plain-`raw`-, + URL- und String-`data`-Teile, Webhook-Push samt Push-Config-CRUD, + `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, 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 50fff37..bfc56b1 100644 --- a/docs/PLUGINS.md +++ b/docs/PLUGINS.md @@ -344,11 +344,15 @@ configuration posts the completed task to that webhook (payload: one `StreamResponse` with `task`). Loopback is allowed by default; any other host needs `SPLINTER_A2A_PUSH_ALLOW` (comma separated, `*` for all), which keeps a client from turning the server into an SSRF probe. The config token travels as -`X-A2A-Notification-Token`, the authentication as `Authorization`. The -standalone push-config CRUD methods are not served. +`X-A2A-Notification-Token`, the authentication as `Authorization`. The four +push-config methods (`CreateTaskPushNotificationConfig`, `Get...`, `List...`, +`Delete...`) manage the same configs in memory. + +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`, URL/binary parts, push-config CRUD, plus continuation of an -interrupted task. Beyond loopback +`SubscribeToTask`, binary parts and continuation of an interrupted task. Beyond loopback `SPLINTER_A2A_SERVER_TOKEN` is required and checked as `Authorization: Bearer ...`; there is no TLS. diff --git a/src/a2aserver.c b/src/a2aserver.c index 5f294ef..481d9ea 100644 --- a/src/a2aserver.c +++ b/src/a2aserver.c @@ -264,12 +264,15 @@ json_id(const char *payload, char *out, size_t cap) } } +static int url_host_allowed(const char *url); +static int fetch_url_text(const char *url, struct sp_buf *out); + /* - * A part can be text, a string in data, or a text/plain raw part (base64). A - * url is not fetched (that would be an SSRF hole in an agent server), and a - * structured object is not guessed at; both are refused with - * ContentTypeNotSupported. Returns 0 when text was collected, 1 when the - * content cannot be used, -1 on allocation failure. + * A part can be text, a string in data, a text/plain raw part (base64), or a + * text/plain url from an allowlisted host. A structured object is not guessed + * at; a URL to anywhere else is refused with ContentTypeNotSupported. Returns + * 0 when text was collected, 1 when the content cannot be used, -1 on + * allocation failure. */ static int append_text(struct sp_buf *out, const char *s) @@ -328,6 +331,34 @@ collect_text(const mcp_json *parts, struct sp_buf *out) got = 1; continue; } + { + const char *url = mcp_arg_string(p, "url"); + + if (url != NULL && *url != '\0') { + struct sp_buf fetched; + + mt = mcp_arg_string(p, "mediaType"); + if (mt != NULL && *mt != '\0' && + strncmp(mt, "text/", 5) != 0) + return 1; + if (!url_host_allowed(url)) + return 1; + if (sp_buf_init(&fetched) != 0) + return -1; + if (fetch_url_text(url, &fetched) != 0 || + fetched.len == 0) { + sp_buf_free(&fetched); + return 1; + } + if (append_text(out, fetched.p) != 0) { + sp_buf_free(&fetched); + return -1; + } + sp_buf_free(&fetched); + got = 1; + continue; + } + } return 1; } return got ? 0 : 1; @@ -456,10 +487,10 @@ task_json(struct sp_buf *b, const struct a2a_task *t) * and the token/credentials may not smuggle a header line. */ static int -push_host_allowed(const char *url) +host_allowed(const char *url, const char *envname) { const char *p, *host, *end; - const char *allow = getenv("SPLINTER_A2A_PUSH_ALLOW"); + const char *allow = getenv(envname); char h[256], copy[512], *tok, *save; size_t n; @@ -500,6 +531,76 @@ push_host_allowed(const char *url) return 0; } +static int +push_host_allowed(const char *url) +{ + return host_allowed(url, "SPLINTER_A2A_PUSH_ALLOW"); +} + +static int +url_host_allowed(const char *url) +{ + return host_allowed(url, "SPLINTER_A2A_URL_ALLOW"); +} + +/* text/plain from an allowlisted URL, capped at 1 MiB; no redirects */ +static int +fetch_url_text(const char *url, struct sp_buf *out) +{ + const char *args[8]; + struct sp_buf raw, err; + pid_t pid = -1; + char chunk[4096], *nl; + size_t got; + int fd, status = 0; + long http; + + args[0] = "-sS"; + args[1] = "-m"; + args[2] = "15"; + args[3] = "-w"; + args[4] = "\n%{http_code}"; + args[5] = NULL; + if (sp_buf_init(&raw) != 0 || sp_buf_init(&err) != 0) + return -1; + fd = sp_curl_start(args, url, NULL, 1, &pid, &err); + if (fd < 0) + goto fail; + while ((got = read(fd, chunk, sizeof(chunk))) > 0) { + if (raw.len + got > (1u << 20)) { + close(fd); + (void)kill(pid, SIGKILL); + (void)waitpid(pid, NULL, 0); + goto fail; + } + if (sp_buf_add(&raw, chunk, got) != 0) { + close(fd); + (void)kill(pid, SIGKILL); + (void)waitpid(pid, NULL, 0); + goto fail; + } + } + close(fd); + if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || + WEXITSTATUS(status) != 0) + goto fail; + if (raw.len < 2 || (nl = strrchr(raw.p, '\n')) == NULL) + goto fail; + http = strtol(nl + 1, NULL, 10); + *nl = '\0'; + if (http < 200 || http > 299) + goto fail; + sp_buf_puts(out, raw.p); + sp_buf_free(&raw); + sp_buf_free(&err); + return 0; + +fail: + sp_buf_free(&raw); + sp_buf_free(&err); + return -1; +} + static int has_crlf(const char *s) { @@ -508,16 +609,12 @@ has_crlf(const char *s) /* 0 no push requested, 1 configured, -1 invalid, -2 host not allowed */ static int -push_parse(const mcp_json *params, struct a2a_push *p, struct sp_buf *err) +push_from_config(const mcp_json *pn, struct a2a_push *p, struct sp_buf *err) { - const mcp_json *conf, *pn, *auth; + const mcp_json *auth; const char *url, *token, *scheme, *cred; memset(p, 0, sizeof(*p)); - conf = mcp_arg(params, "configuration"); - pn = conf != NULL ? mcp_arg(conf, "taskPushNotificationConfig") : NULL; - if (pn == NULL) - return 0; url = mcp_arg_string(pn, "url"); if (url == NULL || *url == '\0') { sp_buf_puts(err, "push config has no url"); @@ -551,6 +648,81 @@ push_parse(const mcp_json *params, struct a2a_push *p, struct sp_buf *err) return 1; } +static int +push_parse(const mcp_json *params, struct a2a_push *p, struct sp_buf *err) +{ + const mcp_json *conf, *pn; + + memset(p, 0, sizeof(*p)); + conf = mcp_arg(params, "configuration"); + pn = conf != NULL ? mcp_arg(conf, "taskPushNotificationConfig") : NULL; + if (pn == NULL) + return 0; + return push_from_config(pn, p, err); +} + +struct a2a_pcfg { + int used; + char id[64]; + char task_id[64]; + struct a2a_push p; +}; + +static struct a2a_pcfg g_pcfg[32]; +static unsigned g_pcfg_seq; + +static struct a2a_pcfg * +pcfg_store(const char *task_id, const struct a2a_push *p) +{ + struct a2a_pcfg *c = &g_pcfg[g_pcfg_seq % 32]; + + g_pcfg_seq++; + memset(c, 0, sizeof(*c)); + c->p = *p; + c->p.set = 1; + snprintf(c->id, sizeof(c->id), "cfg-%d-%u", (int)getpid(), g_pcfg_seq); + snprintf(c->task_id, sizeof(c->task_id), "%s", task_id); + c->used = 1; + return c; +} + +static struct a2a_pcfg * +pcfg_find(const char *task_id, const char *id) +{ + size_t i; + + for (i = 0; i < 32; i++) + if (g_pcfg[i].used && strcmp(g_pcfg[i].task_id, task_id) == 0 && + (id == NULL || strcmp(g_pcfg[i].id, id) == 0)) + return &g_pcfg[i]; + return NULL; +} + +static void +pcfg_json(struct sp_buf *b, const struct a2a_pcfg *c) +{ + sp_buf_puts(b, "{\"id\":\""); + sp_json_escape(b, c->id); + sp_buf_puts(b, "\",\"taskId\":\""); + sp_json_escape(b, c->task_id); + sp_buf_puts(b, "\",\"url\":\""); + sp_json_escape(b, c->p.url); + sp_buf_puts(b, "\""); + if (c->p.token[0] != '\0') { + sp_buf_puts(b, ",\"token\":\""); + sp_json_escape(b, c->p.token); + sp_buf_puts(b, "\""); + } + if (c->p.scheme[0] != '\0') { + sp_buf_puts(b, ",\"authentication\":{\"scheme\":\""); + sp_json_escape(b, c->p.scheme); + sp_buf_puts(b, "\",\"credentials\":\""); + sp_json_escape(b, c->p.cred); + sp_buf_puts(b, "\"}"); + } + sp_buf_puts(b, "}"); +} + /* best effort after the response: a push must not make the client's turn fail */ static void push_task(const struct a2a_push *p, const struct a2a_task *t) @@ -1061,12 +1233,136 @@ send_out: } else if (strcmp(method, "SubscribeToTask") == 0) { rpc_error(fd, id, -32004, "subscription is not served; use " "SendStreamingMessage"); - } else if (strcmp(method, "CreateTaskPushNotificationConfig") == 0 || - strcmp(method, "GetTaskPushNotificationConfig") == 0 || - strcmp(method, "ListTaskPushNotificationConfigs") == 0 || - strcmp(method, "DeleteTaskPushNotificationConfig") == 0) { - rpc_error(fd, id, -32004, "push config CRUD is not served; " - "send taskPushNotificationConfig in SendMessage"); + } else if (strcmp(method, "CreateTaskPushNotificationConfig") == 0) { + const char *tid = mcp_arg_string(params, "taskId"); + struct a2a_push p; + struct sp_buf perr, out; + struct a2a_pcfg *c; + + if (tid == NULL || *tid == '\0') { + rpc_error(fd, id, -32602, "taskId is required"); + mcp_json_free(v); + return; + } + if (task_find(tid) == NULL) { + rpc_error(fd, id, -32001, "task not found"); + mcp_json_free(v); + return; + } + memset(&perr, 0, sizeof(perr)); + if (sp_buf_init(&perr) != 0) { + rpc_error(fd, id, -32603, "out of memory"); + mcp_json_free(v); + return; + } + rc = push_from_config(params, &p, &perr); + if (rc < 0) { + rpc_error(fd, id, rc == -2 ? -32003 : -32602, perr.p); + sp_buf_free(&perr); + mcp_json_free(v); + return; + } + c = pcfg_store(tid, &p); + if (c == NULL) { + rpc_error(fd, id, -32603, "out of memory"); + sp_buf_free(&perr); + mcp_json_free(v); + return; + } + memset(&out, 0, sizeof(out)); + if (sp_buf_init(&out) != 0) { + rpc_error(fd, id, -32603, "out of memory"); + } else { + pcfg_json(&out, c); + rpc_result(fd, id, out.p != NULL ? out.p : "{}"); + sp_buf_free(&out); + } + sp_buf_free(&perr); + } else if (strcmp(method, "GetTaskPushNotificationConfig") == 0) { + const char *tid = mcp_arg_string(params, "taskId"); + const char *cid = mcp_arg_string(params, + "pushNotificationConfigId"); + struct a2a_pcfg *c; + struct sp_buf out; + + if (cid == NULL) + cid = mcp_arg_string(params, "configId"); + if (cid == NULL) + cid = mcp_arg_string(params, "id"); + if (tid == NULL || *tid == '\0' || cid == NULL || *cid == '\0') { + rpc_error(fd, id, -32602, "taskId and config id are " + "required"); + mcp_json_free(v); + return; + } + c = pcfg_find(tid, cid); + if (c == NULL) { + rpc_error(fd, id, -32001, "push config not found"); + mcp_json_free(v); + return; + } + memset(&out, 0, sizeof(out)); + if (sp_buf_init(&out) != 0) { + rpc_error(fd, id, -32603, "out of memory"); + } else { + pcfg_json(&out, c); + rpc_result(fd, id, out.p != NULL ? out.p : "{}"); + sp_buf_free(&out); + } + } else if (strcmp(method, "ListTaskPushNotificationConfigs") == 0) { + const char *tid = mcp_arg_string(params, "taskId"); + struct sp_buf out; + size_t i; + int n = 0; + + if (tid == NULL || *tid == '\0') { + rpc_error(fd, id, -32602, "taskId is required"); + mcp_json_free(v); + return; + } + memset(&out, 0, sizeof(out)); + if (sp_buf_init(&out) != 0) { + rpc_error(fd, id, -32603, "out of memory"); + mcp_json_free(v); + return; + } + sp_buf_puts(&out, "{\"configs\":["); + for (i = 0; i < 32; i++) { + if (!g_pcfg[i].used || + strcmp(g_pcfg[i].task_id, tid) != 0) + continue; + if (n++ > 0) + sp_buf_puts(&out, ","); + pcfg_json(&out, &g_pcfg[i]); + } + sp_buf_printf(&out, "],\"nextPageToken\":\"\"," + "\"pageSize\":%d,\"totalSize\":%d}", n, n); + rpc_result(fd, id, out.p != NULL ? out.p : "{}"); + sp_buf_free(&out); + } else if (strcmp(method, "DeleteTaskPushNotificationConfig") == 0) { + const char *tid = mcp_arg_string(params, "taskId"); + const char *cid = mcp_arg_string(params, + "pushNotificationConfigId"); + struct a2a_pcfg *c; + + if (cid == NULL) + cid = mcp_arg_string(params, "configId"); + if (cid == NULL) + cid = mcp_arg_string(params, "id"); + if (tid == NULL || *tid == '\0' || cid == NULL || *cid == '\0') { + rpc_error(fd, id, -32602, "taskId and config id are " + "required"); + mcp_json_free(v); + return; + } + c = pcfg_find(tid, cid); + if (c == NULL) { + rpc_error(fd, id, -32001, "push config not found"); + mcp_json_free(v); + return; + } + c->used = 0; + rpc_result(fd, id, "{}"); } else { rpc_error(fd, id, -32601, "method not found"); } @@ -1227,6 +1523,8 @@ sp_a2a_serve(struct sp_agent *ag, const char *ip, int port, struct sp_buf *err) sp_conv_free(&g_ctx[i].conv); g_ctx[i].used = 0; } + for (i = 0; i < 32; i++) + g_pcfg[i].used = 0; } fprintf(stderr, "splinter: A2A server stopped\n"); return 0; diff --git a/src/www/index.en.html b/src/www/index.en.html index ff98997..e041870 100644 --- a/src/www/index.en.html +++ b/src/www/index.en.html @@ -53,7 +53,7 @@ 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.
- @@ -212,7 +212,8 @@ splinter: A2A server on 127.0.0.1:8099 (token required)/.well-known/agent-card.json. A contextId is a
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). Beyond loopback the bearer
+(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
token is required.
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.
- @@ -213,7 +213,9 @@ splinter: A2A server on 127.0.0.1:8099 (token required)/.well-known/agent-card.json. Ein contextId ist eine
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). Jenseits von
+Webhook (Loopback oder SPLINTER_A2A_PUSH_ALLOW); Push-Configs
+lassen sich per CRUD verwalten, text/plain-URLs werden von erlaubten Hosts
+geholt. Jenseits von
Loopback ist der Bearer-Token Pflicht.
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.
- @@ -161,7 +161,8 @@ splinter: A2A server on 127.0.0.1:8099 (token required)/.well-known/agent-card.json. Um contextId e uma conversa;
sem ele o servidor cria um e devolve. Uma taskPushNotificationConfig
envia a tarefa concluida para um webhook (loopback ou
-SPLINTER_A2A_PUSH_ALLOW). Fora do loopback o token Bearer e obrigatorio.
+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.
splinter - C99/POSIX, BSD-3-Clause. Manual: man ./docs/splinter.1 · ABI de plugins: docs/PLUGINS.md
/.well-known/agent-card.json. Ein contextId ist eine
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). Jenseits von
+Webhook (Loopback oder SPLINTER_A2A_PUSH_ALLOW); Push-Configs
+lassen sich per CRUD verwalten, text/plain-URLs werden von erlaubten Hosts
+geholt. Jenseits von
Loopback ist der Bearer-Token Pflicht.""",
]
@@ -508,7 +510,8 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
/.well-known/agent-card.json. A contextId is a
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). Beyond loopback the bearer
+(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
token is required.""",
]
@@ -603,7 +606,8 @@ splinter: A2A server on 127.0.0.1:8099 (token required)
/.well-known/agent-card.json. Um contextId e uma conversa;
sem ele o servidor cria um e devolve. Uma taskPushNotificationConfig
envia a tarefa concluida para um webhook (loopback ou
-SPLINTER_A2A_PUSH_ALLOW). Fora do loopback o token Bearer e obrigatorio.""",
+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.""",
]