a2a: a client transport for another agent
plugins/a2a sends one SendMessage over JSON-RPC 2.0 with a text part and reads either a direct Message or a Task in TASK_STATE_COMPLETED (status message plus artifact text). Task and context ids are kept for the session; a terminal task loses its id but keeps the context. Bearer token, timeout and SPLINTER_A2A_FULL are supported. Text only. Streaming, file/structured parts, push notifications, GetTask/CancelTask and agent-card discovery are named as not built, so nobody assumes otherwise. tests/fake_a2a.py and tests/test_a2a.sh pin the wire shape, both result forms, the bearer token and a JSON-RPC error. The site now counts the new plugin (16) and names the transport; README, PLUGINS.md and ROADMAP follow. TODO also records the live claude check: both configured accounts are at their limit, exit 1 with the child's text, claude0 benched and claude1 queued; exit 2 remains unreproduced.
This commit is contained in:
1 parent
9b249a0eb6
commit
999787f3bf
12 files changed
+704
-22
No files matched your search
@@ -33,6 +33,7 @@ PLUGIN = plugins/clock/clock.so plugins/lcm/lcm.so plugins/cps/cps.so \
|
||||
plugins/provider/provider.so \
|
||||
plugins/scheduler/scheduler.so \
|
||||
plugins/planner/planner.so \
|
||||
plugins/a2a/a2a.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 \
|
||||
@@ -216,6 +217,7 @@ check: $(LIB) $(BIN) $(PLUGIN) $(TESTS)
|
||||
export LD_LIBRARY_PATH=.; \
|
||||
for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
||||
echo "== tests/test_gateway.sh"; sh tests/test_gateway.sh; \
|
||||
echo "== tests/test_a2a.sh"; sh tests/test_a2a.sh; \
|
||||
echo "== tests/test_ui.sh"; sh tests/test_ui.sh; \
|
||||
echo "all tests passed"
|
||||
|
||||
@@ -254,3 +256,7 @@ plugins/planner/planner.so: plugins/planner/planner.c $(LIB)
|
||||
plugins/tmux/tmux.so: plugins/tmux/tmux.c $(LIB)
|
||||
$(CC) $(CFLAGS) -shared -o $@ plugins/tmux/tmux.c -L. -lsplinter \
|
||||
$(PLUGIN_RPATH) $(LIBS)
|
||||
|
||||
plugins/a2a/a2a.so: plugins/a2a/a2a.c $(LIB)
|
||||
$(CC) $(CFLAGS) -shared -o $@ plugins/a2a/a2a.c -L. -lsplinter \
|
||||
$(PLUGIN_RPATH) $(LIBS)
|
||||
@@ -107,6 +107,20 @@ The `cli` transport runs a program and takes its stdout as the answer, so
|
||||
`claude -p`, `opencode run`, `ollama run` or a script can be the brains. The
|
||||
OpenAI adapter stays the default for local endpoints.
|
||||
|
||||
## Another agent: A2A
|
||||
|
||||
```sh
|
||||
SPLINTER_A2A_URL=https://agent.example/rpc \
|
||||
SPLINTER_A2A_TOKEN=... \
|
||||
./splinter -p "hi" --plugin plugins/a2a/a2a.so --transport a2a
|
||||
```
|
||||
|
||||
The client half of Agent2Agent: one `SendMessage` over JSON-RPC 2.0 with a text
|
||||
part, blocking, and a direct `Message` or a completed `Task` as the answer. The
|
||||
task and context ids are kept for the session, so the next turn continues the
|
||||
same A2A context. Text only; streaming, files, push notifications and agent-card
|
||||
discovery are not built yet.
|
||||
|
||||
## Configuration
|
||||
|
||||
`splinter` alone starts the chat: endpoint, model, plugins, theme and session
|
||||
|
||||
@@ -19,6 +19,13 @@ Naechster Schritt: Kind mit `SPLINTER_DUMP_REQUEST` und ungefiltertem stderr
|
||||
laufen lassen, Exit-Code der CLI von dem von splinter trennen. Braucht die echte
|
||||
CLI und ein Konto.
|
||||
|
||||
Stand 2026-11-09 23:20: beide konfigurierten `claude`-Delegates sind am Limit.
|
||||
`claude0` ist bis 2026-11-10 03:00 gebenched (Cooldown-Datei), `claude1`
|
||||
antwortet mit "5-hour limit, resets 11:30pm". Der Pfad verhaelt sich richtig:
|
||||
Exit 1 mit dem Text des Kindes, `claude0` in die Cooldown-Datei, `claude1` als
|
||||
`waiting_poll`-Job mit Retry. Exit 2 liess sich damit nicht reproduzieren; die
|
||||
Ursache bleibt offen, bis wieder Kontingent da ist.
|
||||
|
||||
### 2. Kids-Zustimmung ist gegen einen Stub geprueft, nicht gegen Telegram
|
||||
|
||||
`sp_ack_*` (19 Checks in `tests/test_ack.c`), `tg-ask` und der Resolver im
|
||||
@@ -29,15 +36,20 @@ Naechster Schritt: `SPLINTER_ACK_CHANNELS=$HOME/.splinter/bin/tg-ask`,
|
||||
`SPLINTER_ACK_CHAT=8300935`, eine Aenderung anstossen, `ok <id>` im Chat
|
||||
schicken. Braucht Token und Chat.
|
||||
|
||||
### 3. A2A nicht gebaut
|
||||
### 3. A2A: Client steht, Server und der Rest fehlen
|
||||
|
||||
splinter ist MCP-Client und -Server, aber kein A2A-Teilnehmer. `src/swarm.c` ist
|
||||
eine lokale Flotte ueber einen Unix-Socket im Arbeitsverzeichnis
|
||||
(`.splinter-swarm.sock`), kein Agent-zu-Agent-Protokoll; `tests/test_swarm.c`
|
||||
deckt nur diesen lokalen Weg ab.
|
||||
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). Task- und
|
||||
Context-Id bleiben fuer die Sitzung; ein terminaler Task verliert seine Id, der
|
||||
Context bleibt. `tests/fake_a2a.py` und `tests/test_a2a.sh` pruefen beide
|
||||
Ergebnisformen, den Bearer-Token und einen JSON-RPC-Fehler.
|
||||
|
||||
Naechster Schritt: A2A-Client (anderen Agenten als Backend) entwerfen; danach
|
||||
Server.
|
||||
Offen: `SendStreamingMessage`, Datei- und strukturierte Teile, Push-
|
||||
Notifications, `GetTask`/`CancelTask`, Agent-Card-Discovery und die
|
||||
Server-Richtung (andere Agents rufen splinter).
|
||||
|
||||
Naechster Schritt: Streaming (SSE) und Discovery, danach der Server.
|
||||
|
||||
### 4. `~/.local/lib` enthaelt Fremdlast
|
||||
|
||||
@@ -74,6 +86,9 @@ Naechster Schritt: entscheiden, ob die npm-Reste weg duerfen. Kein Code.
|
||||
`test_planner` (add/list/update, `/tasks`, Datei, Widget) und `test_jobs`
|
||||
(submit/jobs/result, force-Retry, faelliger Job im Scheduler-Tick,
|
||||
Scheduler-Widget).
|
||||
- **A2A-Client**: `plugins/a2a/a2a.c` sendet `SendMessage` (JSON-RPC 2.0, Text,
|
||||
blockierend) und liest Message oder Task; `tests/test_a2a.sh` prueft Task,
|
||||
direkte Message, Token und JSON-RPC-Fehler.
|
||||
- **Fehler dabei gefunden und behoben**: `delegate_retry` las `id` und `force`
|
||||
in denselben Puffer; `json_str` haengt an, also wurde aus `job-1` mit
|
||||
`force=1` die Id `job-11` (`src/delegate.c`, `tool_delegate_retry`).
|
||||
|
||||
@@ -267,3 +267,26 @@ and `status` are the commands; `tmux_start`, `tmux_send`, `tmux_capture`,
|
||||
process appends new pane output to `<session>/tmux_watch.log`, so `ask` waits on
|
||||
the feed instead of sleeping for a fixed time. It refuses to load when `tmux`
|
||||
is not installed.
|
||||
|
||||
## a2a
|
||||
|
||||
Another agent as the backend, over the Agent2Agent protocol. The transport is
|
||||
selected like any other:
|
||||
|
||||
SPLINTER_A2A_URL=https://agent.example/rpc \
|
||||
SPLINTER_A2A_TOKEN=... \
|
||||
splinter --plugin plugins/a2a/a2a.so --transport a2a -p "..."
|
||||
|
||||
It sends `SendMessage` as JSON-RPC 2.0 with one text part, blocking, and reads
|
||||
either a direct `Message` or a `Task` in `TASK_STATE_COMPLETED`; text parts from
|
||||
the status message and the artifacts are joined. `SPLINTER_A2A_FULL=1` sends the
|
||||
whole transcript instead of the last user turn, and `SPLINTER_A2A_TIMEOUT` sets
|
||||
the curl timeout (default 300 seconds). The task id and context id are remembered
|
||||
for the session, so the next turn stays in the same A2A context; a terminal task
|
||||
loses its id, a context keeps it.
|
||||
|
||||
Not implemented yet, and named so nobody assumes otherwise: streaming
|
||||
(`SendStreamingMessage`), file/structured-data parts, push notifications,
|
||||
`GetTask`/`CancelTask`, and agent-card discovery. The endpoint is configured
|
||||
directly. The fake agent in `tests/fake_a2a.py` and `tests/test_a2a.sh` pin the
|
||||
wire shape, both result forms, the bearer token and a JSON-RPC error.
|
||||
+5
-3
@@ -3,9 +3,11 @@
|
||||
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.
|
||||
|
||||
1. **A2A** — splinter als A2A-Client (anderen Agenten als Backend) und später
|
||||
als Server, damit die Flotte splinter rufen kann. `swarm` ist nur lokale IPC
|
||||
im selben Verzeichnis, kein A2A.
|
||||
1. **A2A: Streaming und Server** — der Client (`plugins/a2a/a2a.c`) kann
|
||||
`SendMessage` mit Text. Offen sind `SendStreamingMessage`, Datei- und
|
||||
strukturierte Teile, Discovery, `GetTask`/`CancelTask` und die Server-Seite,
|
||||
damit die Flotte splinter rufen kann. `swarm` ist nur lokale IPC im selben
|
||||
Verzeichnis, kein A2A.
|
||||
|
||||
2. **Echte Gegenstellen** — die Kids-Zustimmung gegen einen echten Telegram-Bot
|
||||
(nicht `fake_telegram.py`), und die Ursache von `claude` Exit 2.
|
||||
|
||||
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* splinter -- a2a: another agent as the backend, over the A2A protocol.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* A2A (Agent2Agent) is how one agent hands a message to another without
|
||||
* sharing its tools or its memory. This is the client half, and only the part
|
||||
* a chat turn needs:
|
||||
*
|
||||
* SendMessage JSON-RPC 2.0, one text part, blocking
|
||||
*
|
||||
* The answer may come back as a direct Message or as a Task in a terminal
|
||||
* state; both are read, and text parts from the status message and the
|
||||
* artifacts are joined. A Task id and context id are remembered for the rest
|
||||
* of the session, so the next turn continues the same conversation.
|
||||
*
|
||||
* Not implemented, and said out loud: streaming (SendStreamingMessage), file
|
||||
* and structured-data parts, push notifications, task cancel/get, and the
|
||||
* agent-card discovery step. The endpoint is configured directly:
|
||||
*
|
||||
* SPLINTER_A2A_URL the JSON-RPC endpoint (required)
|
||||
* SPLINTER_A2A_TOKEN optional bearer token
|
||||
* SPLINTER_A2A_TIMEOUT seconds, default 300
|
||||
* SPLINTER_A2A_FULL=1 send the whole transcript, not just the last user turn
|
||||
*
|
||||
* The transport is selected like any other: --plugin plugins/a2a/a2a.so
|
||||
* --transport a2a.
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "splinter.h"
|
||||
#include "splinter_plugin.h"
|
||||
#include "curl.h"
|
||||
#include "mcp.h"
|
||||
|
||||
struct a2a_cfg {
|
||||
char url[512];
|
||||
char token[512];
|
||||
char task_id[128];
|
||||
char context_id[128];
|
||||
long timeout;
|
||||
int full;
|
||||
};
|
||||
|
||||
static int
|
||||
render(const struct sp_conv *conv, int full, struct sp_buf *out)
|
||||
{
|
||||
size_t i, from = 0;
|
||||
|
||||
sp_buf_clear(out);
|
||||
if (!full) {
|
||||
for (i = conv->n; i > 0; i--) {
|
||||
if (conv->v[i - 1].role != NULL &&
|
||||
strcmp(conv->v[i - 1].role, "user") == 0) {
|
||||
from = i - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = from; i < conv->n; i++) {
|
||||
const struct sp_msg *m = &conv->v[i];
|
||||
|
||||
if (m->content == NULL || m->content[0] == '\0')
|
||||
continue;
|
||||
if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
|
||||
return -1;
|
||||
if (full &&
|
||||
sp_buf_printf(out, "%s: ", m->role != NULL ? m->role :
|
||||
"?") != 0)
|
||||
return -1;
|
||||
if (sp_buf_puts(out, m->content) != 0)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
make_id(char *out, size_t cap, const char *prefix)
|
||||
{
|
||||
static unsigned seq;
|
||||
struct timespec ts;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
snprintf(out, cap, "%s-%ld-%d-%u", prefix, (long)ts.tv_sec,
|
||||
(int)getpid(), ++seq);
|
||||
}
|
||||
|
||||
static int
|
||||
build_request(struct a2a_cfg *c, const char *text, struct sp_buf *out)
|
||||
{
|
||||
char rid[96], mid[96];
|
||||
|
||||
make_id(rid, sizeof(rid), "rpc");
|
||||
make_id(mid, sizeof(mid), "msg");
|
||||
if (sp_buf_printf(out,
|
||||
"{\"jsonrpc\":\"2.0\",\"id\":\"%s\",\"method\":\"SendMessage\","
|
||||
"\"params\":{\"message\":{\"messageId\":\"%s\","
|
||||
"\"role\":\"ROLE_USER\",", rid, mid) != 0)
|
||||
return -1;
|
||||
if (c->task_id[0] != '\0' &&
|
||||
sp_buf_printf(out, "\"taskId\":\"%s\",", c->task_id) != 0)
|
||||
return -1;
|
||||
if (c->context_id[0] != '\0' &&
|
||||
sp_buf_printf(out, "\"contextId\":\"%s\",", c->context_id) != 0)
|
||||
return -1;
|
||||
if (sp_buf_puts(out, "\"parts\":[{\"text\":\"") != 0 ||
|
||||
sp_json_escape(out, text) != 0 ||
|
||||
sp_buf_puts(out, "\"}]},\"configuration\":{"
|
||||
"\"acceptedOutputModes\":[\"text/plain\"],"
|
||||
"\"returnImmediately\":false}}}") != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* text parts -> out, joined by newlines; 0 when at least one was found */
|
||||
static int
|
||||
collect_parts(const mcp_json *parts, struct sp_buf *out)
|
||||
{
|
||||
size_t i, n;
|
||||
int found = 0;
|
||||
|
||||
if (parts == NULL || parts->t != MCP_ARR)
|
||||
return 0;
|
||||
n = mcp_array_len(parts);
|
||||
for (i = 0; i < n; i++) {
|
||||
const mcp_json *p = mcp_array_at(parts, i);
|
||||
const char *t = mcp_arg_string(p, "text");
|
||||
|
||||
if (t == NULL || *t == '\0')
|
||||
continue;
|
||||
if (out->len > 0 && sp_buf_puts(out, "\n") != 0)
|
||||
return 0;
|
||||
if (sp_buf_puts(out, t) != 0)
|
||||
return 0;
|
||||
found = 1;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
static int
|
||||
collect_task(struct a2a_cfg *c, const mcp_json *task, struct sp_buf *text,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
const mcp_json *status, *msg, *artifacts;
|
||||
const char *id, *ctx, *state;
|
||||
size_t i, n;
|
||||
int got = 0;
|
||||
|
||||
ctx = mcp_arg_string(task, "contextId");
|
||||
if (ctx != NULL && *ctx != '\0')
|
||||
snprintf(c->context_id, sizeof(c->context_id), "%s", ctx);
|
||||
|
||||
status = mcp_arg(task, "status");
|
||||
state = status != NULL ? mcp_arg_string(status, "state") : NULL;
|
||||
/*
|
||||
* A terminal task cannot take another message. Keep the context (the
|
||||
* conversation), drop the task id, so the next turn starts a new task
|
||||
* in the same context instead of asking a closed one to continue.
|
||||
*/
|
||||
id = mcp_arg_string(task, "id");
|
||||
if (id != NULL && *id != '\0') {
|
||||
if (state != NULL &&
|
||||
(strcmp(state, "TASK_STATE_COMPLETED") == 0 ||
|
||||
strcmp(state, "TASK_STATE_FAILED") == 0 ||
|
||||
strcmp(state, "TASK_STATE_CANCELED") == 0 ||
|
||||
strcmp(state, "TASK_STATE_REJECTED") == 0))
|
||||
c->task_id[0] = '\0';
|
||||
else
|
||||
snprintf(c->task_id, sizeof(c->task_id), "%s", id);
|
||||
}
|
||||
if (state != NULL && strcmp(state, "TASK_STATE_FAILED") == 0) {
|
||||
struct sp_buf why;
|
||||
|
||||
sp_buf_init(&why);
|
||||
msg = mcp_arg(status, "message");
|
||||
if (msg != NULL)
|
||||
(void)collect_parts(mcp_arg(msg, "parts"), &why);
|
||||
sp_buf_printf(err, "a2a: task failed%s%s", why.len > 0 ? ": " : "",
|
||||
why.p != NULL ? why.p : "");
|
||||
sp_buf_free(&why);
|
||||
return -1;
|
||||
}
|
||||
if (state != NULL && (strcmp(state, "TASK_STATE_INPUT_REQUIRED") == 0 ||
|
||||
strcmp(state, "TASK_STATE_AUTH_REQUIRED") == 0)) {
|
||||
sp_buf_printf(err, "a2a: task needs %s (state %s)",
|
||||
strcmp(state, "TASK_STATE_AUTH_REQUIRED") == 0 ?
|
||||
"authentication" : "input", state);
|
||||
return -1;
|
||||
}
|
||||
msg = status != NULL ? mcp_arg(status, "message") : NULL;
|
||||
if (msg != NULL && collect_parts(mcp_arg(msg, "parts"), text))
|
||||
got = 1;
|
||||
artifacts = mcp_arg(task, "artifacts");
|
||||
if (artifacts != NULL && artifacts->t == MCP_ARR) {
|
||||
n = mcp_array_len(artifacts);
|
||||
for (i = 0; i < n; i++) {
|
||||
const mcp_json *a = mcp_array_at(artifacts, i);
|
||||
|
||||
if (collect_parts(mcp_arg(a, "parts"), text))
|
||||
got = 1;
|
||||
}
|
||||
}
|
||||
if (state != NULL && strcmp(state, "TASK_STATE_COMPLETED") != 0) {
|
||||
sp_buf_printf(err, "a2a: task not complete (state %s)", state);
|
||||
return -1;
|
||||
}
|
||||
if (!got) {
|
||||
sp_buf_puts(err, "a2a: task has no text parts");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_answer(struct a2a_cfg *c, const char *raw, struct sp_reply *out,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
mcp_json *v = NULL;
|
||||
const mcp_json *error, *result, *task, *message;
|
||||
struct sp_buf text;
|
||||
int rc = -1;
|
||||
|
||||
if (sp_buf_init(&text) != 0)
|
||||
return -1;
|
||||
v = mcp_parse(raw);
|
||||
if (v == NULL) {
|
||||
sp_buf_puts(err, "a2a: response is not JSON");
|
||||
goto out;
|
||||
}
|
||||
error = mcp_arg(v, "error");
|
||||
if (error != NULL) {
|
||||
const char *m = mcp_arg_string(error, "message");
|
||||
|
||||
sp_buf_printf(err, "a2a: %s", m != NULL ? m : "JSON-RPC error");
|
||||
goto out;
|
||||
}
|
||||
result = mcp_arg(v, "result");
|
||||
if (result == NULL) {
|
||||
sp_buf_puts(err, "a2a: no result in the response");
|
||||
goto out;
|
||||
}
|
||||
task = mcp_arg(result, "task");
|
||||
message = mcp_arg(result, "message");
|
||||
if (task == NULL && message == NULL) {
|
||||
/* some servers put the object itself in result */
|
||||
if (mcp_arg(result, "status") != NULL)
|
||||
task = result;
|
||||
else if (mcp_arg(result, "parts") != NULL)
|
||||
message = result;
|
||||
}
|
||||
if (task != NULL && collect_task(c, task, &text, err) != 0)
|
||||
goto out;
|
||||
if (message != NULL) {
|
||||
const char *ctx = mcp_arg_string(message, "contextId");
|
||||
|
||||
if (ctx != NULL && *ctx != '\0')
|
||||
snprintf(c->context_id, sizeof(c->context_id), "%s",
|
||||
ctx);
|
||||
(void)collect_parts(mcp_arg(message, "parts"), &text);
|
||||
}
|
||||
if (text.len == 0) {
|
||||
sp_buf_puts(err, "a2a: empty answer");
|
||||
goto out;
|
||||
}
|
||||
out->content = strdup(text.p);
|
||||
if (out->content == NULL) {
|
||||
sp_buf_puts(err, "a2a: out of memory");
|
||||
goto out;
|
||||
}
|
||||
out->status = 200;
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
if (v != NULL)
|
||||
mcp_json_free(v);
|
||||
sp_buf_free(&text);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
dump_request(const char *body, size_t len)
|
||||
{
|
||||
const char *path = getenv("SPLINTER_DUMP_REQUEST");
|
||||
FILE *f;
|
||||
|
||||
if (path == NULL || *path == '\0')
|
||||
return;
|
||||
f = fopen(path, "w");
|
||||
if (f == NULL)
|
||||
return;
|
||||
if (len > 0)
|
||||
(void)fwrite(body, 1, len, f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static int
|
||||
post(struct a2a_cfg *c, const char *body, struct sp_buf *raw,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
char tmo[32], data[700], auth[sizeof(c->token) + 32];
|
||||
char templ[600];
|
||||
const char *args[16];
|
||||
const char *hdrs[2] = { NULL, NULL };
|
||||
const char *dir;
|
||||
int fd, n = 0;
|
||||
FILE *f;
|
||||
pid_t pid = -1;
|
||||
char chunk[4096];
|
||||
size_t got;
|
||||
|
||||
dir = getenv("TMPDIR");
|
||||
if (dir == NULL || *dir == '\0')
|
||||
dir = "/var/tmp";
|
||||
snprintf(templ, sizeof(templ), "%s/splinter-a2a-XXXXXX", dir);
|
||||
fd = mkstemp(templ);
|
||||
if (fd < 0) {
|
||||
sp_buf_printf(err, "a2a: mkstemp: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (write(fd, body, strlen(body)) != (ssize_t)strlen(body)) {
|
||||
sp_buf_printf(err, "a2a: short write: %s", strerror(errno));
|
||||
close(fd);
|
||||
unlink(templ);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
snprintf(tmo, sizeof(tmo), "%ld", c->timeout);
|
||||
snprintf(data, sizeof(data), "@%s", templ);
|
||||
args[n++] = "-sS";
|
||||
args[n++] = "-m";
|
||||
args[n++] = tmo;
|
||||
args[n++] = "-X";
|
||||
args[n++] = "POST";
|
||||
args[n++] = "-H";
|
||||
args[n++] = "Content-Type: application/json";
|
||||
args[n++] = "-H";
|
||||
args[n++] = "Accept: application/json";
|
||||
args[n++] = "--data-binary";
|
||||
args[n++] = data;
|
||||
args[n++] = "-w";
|
||||
args[n++] = "\n%{http_code}";
|
||||
args[n] = NULL;
|
||||
if (c->token[0] != '\0') {
|
||||
snprintf(auth, sizeof(auth), "Authorization: Bearer %s",
|
||||
c->token);
|
||||
hdrs[0] = auth;
|
||||
}
|
||||
fd = sp_curl_start(args, c->url, hdrs, 0, &pid, err);
|
||||
memset(auth, 0, sizeof(auth));
|
||||
if (fd < 0) {
|
||||
unlink(templ);
|
||||
return -1;
|
||||
}
|
||||
f = fdopen(fd, "r");
|
||||
if (f == NULL) {
|
||||
close(fd);
|
||||
(void)kill(pid, SIGKILL);
|
||||
(void)waitpid(pid, NULL, 0);
|
||||
sp_buf_printf(err, "a2a: fdopen: %s", strerror(errno));
|
||||
unlink(templ);
|
||||
return -1;
|
||||
}
|
||||
while ((got = fread(chunk, 1, sizeof(chunk), f)) > 0)
|
||||
if (sp_buf_add(raw, chunk, got) != 0) {
|
||||
fclose(f);
|
||||
(void)kill(pid, SIGKILL);
|
||||
(void)waitpid(pid, NULL, 0);
|
||||
unlink(templ);
|
||||
sp_buf_puts(err, "a2a: out of memory");
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) ||
|
||||
WEXITSTATUS(status) != 0) {
|
||||
sp_buf_printf(err, "a2a: transfer failed for %s", c->url);
|
||||
unlink(templ);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
unlink(templ);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
a2a_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out,
|
||||
struct sp_buf *err)
|
||||
{
|
||||
struct a2a_cfg *c = ctx;
|
||||
struct sp_buf body, raw, text;
|
||||
char *nl;
|
||||
long http;
|
||||
int rc = -1;
|
||||
|
||||
if (c == NULL || conv == NULL || out == NULL)
|
||||
return -1;
|
||||
if (c->url[0] == '\0') {
|
||||
sp_buf_puts(err, "a2a: SPLINTER_A2A_URL is not set");
|
||||
return -1;
|
||||
}
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->status = 200;
|
||||
if (sp_buf_init(&body) != 0)
|
||||
return -1;
|
||||
if (sp_buf_init(&raw) != 0) {
|
||||
sp_buf_free(&body);
|
||||
return -1;
|
||||
}
|
||||
if (sp_buf_init(&text) != 0) {
|
||||
sp_buf_free(&body);
|
||||
sp_buf_free(&raw);
|
||||
return -1;
|
||||
}
|
||||
if (render(conv, c->full, &text) != 0) {
|
||||
sp_buf_puts(err, "a2a: out of memory");
|
||||
goto out;
|
||||
}
|
||||
if (text.len == 0) {
|
||||
sp_buf_puts(err, "a2a: nothing to send");
|
||||
goto out;
|
||||
}
|
||||
if (build_request(c, text.p, &body) != 0) {
|
||||
sp_buf_puts(err, "a2a: out of memory");
|
||||
goto out;
|
||||
}
|
||||
dump_request(body.p, body.len);
|
||||
if (post(c, body.p, &raw, err) != 0)
|
||||
goto out;
|
||||
if (raw.len < 2 || (nl = strrchr(raw.p, '\n')) == NULL) {
|
||||
sp_buf_puts(err, "a2a: unparseable response (no HTTP status)");
|
||||
goto out;
|
||||
}
|
||||
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 out;
|
||||
}
|
||||
if (parse_answer(c, raw.p, out, err) != 0)
|
||||
goto out;
|
||||
rc = 0;
|
||||
|
||||
out:
|
||||
sp_buf_free(&body);
|
||||
sp_buf_free(&raw);
|
||||
sp_buf_free(&text);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
a2a_init(struct sp_host *h)
|
||||
{
|
||||
static struct a2a_cfg cfg;
|
||||
static struct sp_transport tr;
|
||||
const char *url = getenv("SPLINTER_A2A_URL");
|
||||
const char *tok = getenv("SPLINTER_A2A_TOKEN");
|
||||
const char *to = getenv("SPLINTER_A2A_TIMEOUT");
|
||||
const char *full = getenv("SPLINTER_A2A_FULL");
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
if (url != NULL)
|
||||
snprintf(cfg.url, sizeof(cfg.url), "%s", url);
|
||||
if (tok != NULL)
|
||||
snprintf(cfg.token, sizeof(cfg.token), "%s", tok);
|
||||
cfg.timeout = 300;
|
||||
if (to != NULL && *to != '\0')
|
||||
cfg.timeout = strtol(to, NULL, 10);
|
||||
cfg.full = full != NULL && strcmp(full, "0") != 0;
|
||||
|
||||
memset(&tr, 0, sizeof(tr));
|
||||
tr.send = a2a_send;
|
||||
tr.ctx = &cfg;
|
||||
tr.provider = "a2a";
|
||||
return sp_host_add_transport(h, "a2a", tr);
|
||||
}
|
||||
|
||||
static const struct sp_plugin a2a_plugin = {
|
||||
SP_PLUGIN_ABI, "a2a", "0.1.0", a2a_init, NULL, NULL
|
||||
};
|
||||
|
||||
const struct sp_plugin *
|
||||
sp_plugin_describe(void)
|
||||
{
|
||||
return &a2a_plugin;
|
||||
}
|
||||
@@ -53,9 +53,9 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>21776</b> lines of C99/POSIX ·
|
||||
<p class="meta"><b>22274</b> lines of C99/POSIX ·
|
||||
<b>23</b> tools · <b>31</b> test programs ·
|
||||
<b>15</b> plugins · <b>42</b> palettes · BSD-3-Clause</p>
|
||||
<b>16</b> plugins · <b>42</b> palettes · BSD-3-Clause</p>
|
||||
|
||||
<h2>What it is</h2>
|
||||
<p>The same thing Claude Code or opencode is for you: a program you sit in front of, talking to a model, running the tools it asks for. The difference is the source. If something bothers you — the layout, the keys, the confirmation prompts, the transport — you change it here instead of waiting for someone else to.</p>
|
||||
@@ -106,6 +106,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<tr><th>Name</th><th>What it does</th></tr>
|
||||
<tr><td class="c">openai</td><td>any OpenAI-compatible endpoint, streaming over SSE</td></tr>
|
||||
<tr><td class="c">cli</td><td>any program as the model, e.g. <code>claude -p</code></td></tr>
|
||||
<tr><td class="c">a2a</td><td>another agent over A2A (SendMessage, text)</td></tr>
|
||||
<tr><td class="c">ring</td><td>exit ring: 429 or limit → next exit</td></tr>
|
||||
<tr><td class="c">mcp</td><td>an MCP server as a tool source, with its own schemas</td></tr>
|
||||
<tr><td class="c">lcm</td><td>compaction of the conversation</td></tr>
|
||||
|
||||
+3
-2
@@ -53,9 +53,9 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>21776</b> Zeilen C99/POSIX ·
|
||||
<p class="meta"><b>22274</b> Zeilen C99/POSIX ·
|
||||
<b>23</b> Werkzeuge · <b>31</b> Test-Programme ·
|
||||
<b>15</b> Plugins · <b>42</b> Farbschemata · BSD-3-Clause</p>
|
||||
<b>16</b> Plugins · <b>42</b> Farbschemata · BSD-3-Clause</p>
|
||||
|
||||
<h2>Was es ist</h2>
|
||||
<p>Dasselbe, was Claude Code oder opencode fuer dich sind: ein Programm, in dem du mit einem Modell redest und das die Werkzeuge ausfuehrt, um die es bittet. Der Unterschied ist der Quelltext. Wenn dich etwas stoert — das Layout, die Tasten, die Frage nach Bestaetigung, der Transport — aenderst du es hier, statt darauf zu warten.</p>
|
||||
@@ -106,6 +106,7 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<tr><th>Name</th><th>Was es tut</th></tr>
|
||||
<tr><td class="c">openai</td><td>jeder OpenAI-kompatible Endpunkt, Streaming ueber SSE</td></tr>
|
||||
<tr><td class="c">cli</td><td>jedes Programm als Modell, etwa <code>claude -p</code></td></tr>
|
||||
<tr><td class="c">a2a</td><td>ein anderer Agent ueber A2A (SendMessage, Text)</td></tr>
|
||||
<tr><td class="c">ring</td><td>Exit-Ring: 429 oder Limit → naechster Ausgang</td></tr>
|
||||
<tr><td class="c">mcp</td><td>MCP-Server als Werkzeugquelle, mit den Schemata des Servers</td></tr>
|
||||
<tr><td class="c">lcm</td><td>Komprimierung der Konversation</td></tr>
|
||||
|
||||
@@ -53,9 +53,9 @@ hr { border: 0; border-top: 1px solid #1d2126; margin: 3em 0 1.5em 0; }
|
||||
<h1>splinter<span>_</span></h1>
|
||||
<p class="lead">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.</p>
|
||||
|
||||
<p class="meta"><b>21776</b> linhas C99/POSIX ·
|
||||
<p class="meta"><b>22274</b> linhas C99/POSIX ·
|
||||
<b>23</b> ferramentas · <b>31</b> programas de teste ·
|
||||
<b>15</b> plugins · <b>42</b> paletas · BSD-3-Clause</p>
|
||||
<b>16</b> plugins · <b>42</b> paletas · BSD-3-Clause</p>
|
||||
|
||||
<h2>O que e</h2>
|
||||
<p>splinter e um harness de agente em C99/POSIX: um programa que segura a
|
||||
@@ -86,9 +86,10 @@ entrar na frente com um gate: permitir, negar com motivo, ou nao opinar.</p>
|
||||
skills, memoria e pesquisa na web.</p>
|
||||
|
||||
<h2>Transportes e plugins</h2>
|
||||
<p>Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), mock para
|
||||
teste. Plugins sao <code>.so</code> carregados com dlopen: lcm, focus, reminder,
|
||||
ring, mcp, cli, clock, cps e agora kids.</p>
|
||||
<p>Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), a2a
|
||||
(outro agente via JSON-RPC), mock para teste. Plugins sao <code>.so</code>
|
||||
carregados com dlopen: lcm, focus, reminder, ring, mcp, cli, a2a, clock, cps,
|
||||
kids, tasks, planner, provider, scheduler, status e tmux.</p>
|
||||
|
||||
<h2>Delegacao: outros modelos, splinter escolhe</h2>
|
||||
<pre>[parallel: 2 task(s), 12018 ms wall]
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# fake A2A agent for tests/test_a2a.sh.
|
||||
# argv: port, request log. One SendMessage handler, no streaming.
|
||||
import http.server, json, sys
|
||||
|
||||
LOG = sys.argv[2]
|
||||
|
||||
|
||||
class H(http.server.BaseHTTPRequestHandler):
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
def do_POST(self):
|
||||
n = int(self.headers.get("Content-Length", 0))
|
||||
raw = self.rfile.read(n)
|
||||
with open(LOG, "a") as f:
|
||||
f.write(raw.decode("utf-8") + "\n")
|
||||
req = json.loads(raw)
|
||||
text = ""
|
||||
try:
|
||||
for p in req["params"]["message"]["parts"]:
|
||||
text += p.get("text", "")
|
||||
except Exception:
|
||||
pass
|
||||
rid = req.get("id")
|
||||
if "fehler" in text:
|
||||
body = {"jsonrpc": "2.0", "id": rid,
|
||||
"error": {"code": -32603, "message": "boom from a2a"}}
|
||||
elif "direkt" in text:
|
||||
body = {"jsonrpc": "2.0", "id": rid, "result": {"message": {
|
||||
"messageId": "m1", "contextId": "ctx-1",
|
||||
"role": "ROLE_AGENT",
|
||||
"parts": [{"text": "direkt vom agenten"}]}}}
|
||||
elif "auth" in text and self.headers.get("Authorization") != "Bearer tok":
|
||||
body = {"jsonrpc": "2.0", "id": rid,
|
||||
"error": {"code": -32000, "message": "unauthorized"}}
|
||||
else:
|
||||
body = {"jsonrpc": "2.0", "id": rid, "result": {"task": {
|
||||
"id": "task-1", "contextId": "ctx-1",
|
||||
"status": {"state": "TASK_STATE_COMPLETED", "message": {
|
||||
"messageId": "m2", "role": "ROLE_AGENT",
|
||||
"parts": [{"text": "a2a sagt hallo"}]}},
|
||||
"artifacts": [{"artifactId": "a1",
|
||||
"parts": [{"text": "und tschuess"}]}]}}}
|
||||
b = json.dumps(body).encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(b)))
|
||||
self.end_headers()
|
||||
self.wfile.write(b)
|
||||
|
||||
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
||||
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/bin/sh
|
||||
# splinter -- the A2A client transport, against a fake A2A agent.
|
||||
#
|
||||
# What it guards: SendMessage as JSON-RPC, the message shape, a Task result
|
||||
# (status message plus artifact text), a direct Message result, the bearer
|
||||
# token, and a JSON-RPC error that must fail the turn instead of becoming an
|
||||
# empty answer.
|
||||
set -u
|
||||
cd "$(dirname "$0")/.." || exit 1
|
||||
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-XXXXXX") || exit 1
|
||||
P=$((20000 + ($$ % 20000)))
|
||||
F=
|
||||
cleanup() { [ -n "$F" ] && kill "$F" 2>/dev/null; rm -rf "$D"; }
|
||||
trap cleanup EXIT
|
||||
python3 -I tests/fake_a2a.py "$P" "$D/req.log" &
|
||||
F=$!
|
||||
for i in $(seq 1 50); do
|
||||
curl -s -o /dev/null "http://127.0.0.1:$P/x" && break
|
||||
sleep 0.2
|
||||
done
|
||||
|
||||
fails=0
|
||||
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
||||
run() { # run <text>, env from the caller
|
||||
SPLINTER_A2A_URL="http://127.0.0.1:$P/rpc" SPLINTER_A2A_TIMEOUT=20 \
|
||||
./splinter --no-config --plugin plugins/a2a/a2a.so \
|
||||
--transport a2a -p "$1"
|
||||
}
|
||||
|
||||
# a Task: status message and artifact text are both the answer
|
||||
out=$(run "hallo" 2>&1)
|
||||
echo "$out" | grep -q 'a2a sagt hallo'
|
||||
check test $? -eq 0
|
||||
echo "$out" | grep -q 'und tschuess'
|
||||
check test $? -eq 0
|
||||
|
||||
# the wire shape
|
||||
grep -q '"method":"SendMessage"' "$D/req.log"
|
||||
check test $? -eq 0
|
||||
grep -q '"role":"ROLE_USER"' "$D/req.log"
|
||||
check test $? -eq 0
|
||||
grep -q '"parts":\[{"text":"hallo"}\]' "$D/req.log"
|
||||
check test $? -eq 0
|
||||
|
||||
# a direct Message is an answer, not a task
|
||||
out=$(run "direkt" 2>&1)
|
||||
echo "$out" | grep -q 'direkt vom agenten'
|
||||
check test $? -eq 0
|
||||
|
||||
# the token goes out as a bearer header, and is required when the agent asks
|
||||
out=$(SPLINTER_A2A_TOKEN=tok run "auth bitte" 2>&1)
|
||||
echo "$out" | grep -q 'a2a sagt hallo'
|
||||
check test $? -eq 0
|
||||
out=$(run "auth ohne token" 2>&1)
|
||||
echo "$out" | grep -q 'unauthorized'
|
||||
check test $? -eq 0
|
||||
|
||||
# a JSON-RPC error fails the turn with the agent's message
|
||||
run "fehler" >/dev/null 2>"$D/err"
|
||||
check test $? -ne 0
|
||||
grep -q 'boom from a2a' "$D/err"
|
||||
check test $? -eq 0
|
||||
|
||||
if [ "$fails" -eq 0 ]; then echo "test_a2a: ok"; exit 0; fi
|
||||
exit 1
|
||||
+7
-3
@@ -157,6 +157,7 @@ TRANSPORTS = """<h2>{h}</h2>
|
||||
<tr><th>{t_name}</th><th>{t_does}</th></tr>
|
||||
<tr><td class="c">openai</td><td>{d_openai}</td></tr>
|
||||
<tr><td class="c">cli</td><td>{d_cli}</td></tr>
|
||||
<tr><td class="c">a2a</td><td>{d_a2a}</td></tr>
|
||||
<tr><td class="c">ring</td><td>{d_ring}</td></tr>
|
||||
<tr><td class="c">mcp</td><td>{d_mcp}</td></tr>
|
||||
<tr><td class="c">lcm</td><td>{d_lcm}</td></tr>
|
||||
@@ -283,6 +284,7 @@ SECTIONS = {
|
||||
(TRANSPORTS.format(h="Transporte und Plugins", t_name="Name", t_does="Was es tut",
|
||||
d_openai="jeder OpenAI-kompatible Endpunkt, Streaming ueber SSE",
|
||||
d_cli="jedes Programm als Modell, etwa <code>claude -p</code>",
|
||||
d_a2a="ein anderer Agent ueber A2A (SendMessage, Text)",
|
||||
d_ring="Exit-Ring: 429 oder Limit → naechster Ausgang",
|
||||
d_mcp="MCP-Server als Werkzeugquelle, mit den Schemata des Servers",
|
||||
d_lcm="Komprimierung der Konversation",
|
||||
@@ -363,6 +365,7 @@ SECTIONS = {
|
||||
(TRANSPORTS.format(h="Transports and plugins", t_name="Name", t_does="What it does",
|
||||
d_openai="any OpenAI-compatible endpoint, streaming over SSE",
|
||||
d_cli="any program as the model, e.g. <code>claude -p</code>",
|
||||
d_a2a="another agent over A2A (SendMessage, text)",
|
||||
d_ring="exit ring: 429 or limit → next exit",
|
||||
d_mcp="an MCP server as a tool source, with its own schemas",
|
||||
d_lcm="compaction of the conversation",
|
||||
@@ -512,9 +515,10 @@ entrar na frente com um gate: permitir, negar com motivo, ou nao opinar.</p>""",
|
||||
<code>delegate</code>, <code>delegate_parallel</code>, as de leitura do sistema e as de
|
||||
skills, memoria e pesquisa na web.</p>""",
|
||||
"""<h2>Transportes e plugins</h2>
|
||||
<p>Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), mock para
|
||||
teste. Plugins sao <code>.so</code> carregados com dlopen: lcm, focus, reminder,
|
||||
ring, mcp, cli, clock, cps e agora kids.</p>""",
|
||||
<p>Transporte e um vtable: openai (HTTP/SSE), cli (claude, opencode), a2a
|
||||
(outro agente via JSON-RPC), mock para teste. Plugins sao <code>.so</code>
|
||||
carregados com dlopen: lcm, focus, reminder, ring, mcp, cli, a2a, clock, cps,
|
||||
kids, tasks, planner, provider, scheduler, status e tmux.</p>""",
|
||||
"""<h2>Delegacao: outros modelos, splinter escolhe</h2>
|
||||
<pre>[parallel: 2 task(s), 12018 ms wall]
|
||||
|
||||
|
||||
Reference in new issue
Block a user