Another harness's conversation is not a session until splinter can resume
it. plugins/foreign reads the three stores that already exist on the
machine - ~/.claude/projects/<slug>/<id>.jsonl, <root>/state.db (and
profiles/*/state.db) and opencode.db's session_v2/session_message - and
offers four tools plus /foreign:
list, search TEXT, read SOURCE ID, import SOURCE ID
The stores are read with sqlite3 -readonly: an import copies, it never
moves. Reasoning blocks are dropped on the way in, because a provider does
not accept another model's thinking as evidence. Tool calls arrive with
their results in place, which is what makes the imported session worth
resuming instead of retyping.
import writes a real splinter session: the conversation as a replayable
jsonl, and a .meta with the source's title, its start time and *its*
working directory. So /open continues it in the chat,
--session-id <id> --resume in a shell, and -c finds it in the directory the
conversation actually ran in. The marker foreign=<source>:<id> survives
every later reopen, which needed the core's .meta sidecar to carry keys it
does not own.
Building this found nine bugs, each one seen red before it was green:
- four use-after-frees: mcp_arg_string returns a pointer *into* the parse
tree, read after mcp_json_free. That garbage in `only`/`src` was why a
list of three stores answered "no sessions" and named AÃ_Â¥U.
- sql_json took "no rows" for a failure (NULL), so every empty answer
looked like a broken database.
- args_split never terminated its buffers: /foreign list became
"unknown subcommand 'list('".
- path_join(dir, id, ".meta") built dir/id/.meta, so the sidecar landed
in a subdirectory.
- claude_slug_dir had the sign inverted and returned -1 for every
non-empty cwd, so the project directory was never found.
- sp_session_open overwrote cwd with getcwd() on *every* open, though the
comment beside it promised the opposite: imports claimed the directory
they were imported from and -c then picked the wrong session.
- hermes_text ran strncmp(p, "\x00json:", 6) on an empty content, a
one-byte allocation - heap-buffer-overflow, found by ASAN. The marker is
stripped in SQL anyway.
- hermes_calls never freed the root node on the object path (5456 bytes
over 42 allocations).
- list_any reported strerror(errno) with errno never set: a real file with
the wrong schema read as "No such file or directory". The SQL reason is
passed through now.
Checked end to end against the stores on this machine: claude 64 sessions,
opencode 25, hermes 0 (both hermes databases here are empty, count(*) = 0).
A real opencode session of 150 messages reads back with its tool output; one
of 75 imports with the right cwd and title, --resume sends its history, and
-c from the source directory opens it.
tests/sh/port.sh comes along: the shell tests guessed a port with
20000 + $$ % 30000 and on 2026-11-21 landed on one dtsession held. The fake
died, curl got an answer from dtsession, and twenty checks blamed the
gateway. They ask the kernel for a free port now.
249 lines
12 KiB
Bash
Executable File
249 lines
12 KiB
Bash
Executable File
#!/bin/sh
|
|
# splinter -- the A2A server, driven by curl.
|
|
#
|
|
# What it guards: the agent card, SendMessage -> completed Task with the
|
|
# answer, GetTask from the in-memory store, a refusal for streaming, and the
|
|
# bearer token that is required beyond loopback (or when configured).
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-a2a-srv-XXXXXX") || exit 1
|
|
SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR
|
|
P=$(free_port)
|
|
P2=$((P + 1))
|
|
P3=$((P + 2))
|
|
S1=
|
|
S2=
|
|
W=
|
|
cleanup() {
|
|
[ -n "$S1" ] && kill "$S1" 2>/dev/null
|
|
[ -n "$S2" ] && kill "$S2" 2>/dev/null
|
|
[ -n "$W" ] && kill "$W" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
mkdir -p "$D/home"
|
|
printf 'answer hallo von splinter\n%.0s' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > "$D/model.txt"
|
|
|
|
fails=0
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
check_that() { # $1 = description, $2.. = command
|
|
d=$1; shift
|
|
if "$@"; then :; else echo "FAIL $d"; fails=$((fails + 1)); fi
|
|
}
|
|
wait_port() {
|
|
for i in $(seq 1 50); do
|
|
curl -s -o /dev/null "http://127.0.0.1:$1/" && return 0
|
|
sleep 0.2
|
|
done
|
|
return 1
|
|
}
|
|
post() { # post <port> <json> [extra curl args...]
|
|
port=$1; body=$2; shift 2
|
|
curl -s -H 'Content-Type: application/json' "$@" \
|
|
--data "$body" "http://127.0.0.1:$port/a2a"
|
|
}
|
|
send_json() {
|
|
printf '%s' '{"jsonrpc":"2.0","id":"1","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"text":"hallo"}]}}}'
|
|
}
|
|
|
|
HOME="$D/home" ./splinter --no-config --script "$D/model.txt" \
|
|
--a2a-server-listen 127.0.0.1 --a2a-listen-port "$P" \
|
|
>"$D/out1" 2>"$D/err1" &
|
|
S1=$!
|
|
check wait_port "$P"
|
|
|
|
python3 -I tests/fake_webhook.py "$P3" "$D/hook.log" &
|
|
W=$!
|
|
check wait_port "$P3"
|
|
|
|
# the agent card names the JSON-RPC interface
|
|
card=$(curl -s "http://127.0.0.1:$P/.well-known/agent-card.json")
|
|
echo "$card" | grep -q '"protocolBinding":"JSONRPC"'
|
|
check test $? -eq 0
|
|
echo "$card" | grep -q '"streaming":true'
|
|
check test $? -eq 0
|
|
echo "$card" | grep -q "/a2a"
|
|
check test $? -eq 0
|
|
|
|
# SendMessage -> a completed task with the answer in message and artifact
|
|
resp=$(post "$P" "$(send_json)")
|
|
echo "$resp" | grep -q '"state":"TASK_STATE_COMPLETED"'
|
|
check test $? -eq 0
|
|
echo "$resp" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
|
|
# GetTask returns the same task
|
|
id=$(printf '%s' "$resp" | python3 -c \
|
|
'import json,sys; print(json.load(sys.stdin)["result"]["task"]["id"])')
|
|
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\"}]}}}")
|
|
echo "$resp3" | grep -q 'artifactUpdate'
|
|
check test $? -eq 0
|
|
echo "$resp3" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
echo "$resp3" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
|
|
# a completed task cannot be canceled: the spec's TaskNotCancelable (-32002)
|
|
resp6=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"6\",\"method\":\"CancelTask\",\"params\":{\"id\":\"$id\"}}")
|
|
echo "$resp6" | grep -q '"code":-32002'
|
|
check test $? -eq 0
|
|
# push-config CRUD: create, get, list, delete, then get again
|
|
resp9=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"9\",\"method\":\"CreateTaskPushNotificationConfig\",\"params\":{\"taskId\":\"$id\",\"url\":\"http://127.0.0.1:$P3/hook2\",\"token\":\"t2\",\"authentication\":{\"scheme\":\"Bearer\",\"credentials\":\"c2\"}}}")
|
|
echo "$resp9" | grep -q '"id":"cfg-'
|
|
check test $? -eq 0
|
|
cid=$(printf '%s' "$resp9" | python3 -c 'import json,sys; print(json.load(sys.stdin)["result"]["id"])')
|
|
check test -n "$cid"
|
|
resp9=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"9\",\"method\":\"GetTaskPushNotificationConfig\",\"params\":{\"taskId\":\"$id\",\"pushNotificationConfigId\":\"$cid\"}}")
|
|
echo "$resp9" | grep -q 'hook2'
|
|
check test $? -eq 0
|
|
resp9=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"9\",\"method\":\"ListTaskPushNotificationConfigs\",\"params\":{\"taskId\":\"$id\"}}")
|
|
echo "$resp9" | grep -q '"totalSize":1'
|
|
check test $? -eq 0
|
|
resp9=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"9\",\"method\":\"DeleteTaskPushNotificationConfig\",\"params\":{\"taskId\":\"$id\",\"pushNotificationConfigId\":\"$cid\"}}")
|
|
echo "$resp9" | grep -q '"result":{}'
|
|
check test $? -eq 0
|
|
resp9=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"9\",\"method\":\"GetTaskPushNotificationConfig\",\"params\":{\"taskId\":\"$id\",\"pushNotificationConfigId\":\"$cid\"}}")
|
|
echo "$resp9" | grep -q '"code":-32001'
|
|
check test $? -eq 0
|
|
|
|
# a binary part is accepted: the bytes land in the session's inbox and the
|
|
# model is told the path (a text model cannot read a PNG, the agent can)
|
|
b64=$(printf 'PNGDATA' | python3 -c 'import base64,sys; print(base64.b64encode(sys.stdin.buffer.read()).decode())')
|
|
resp13=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"13\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m13\",\"role\":\"ROLE_USER\",\"parts\":[{\"file\":{\"name\":\"pic.png\",\"mimeType\":\"image/png\",\"bytes\":\"$b64\"}},{\"text\":\"sieh dir das an\"}]}}}")
|
|
echo "$resp13" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
found=$(ls "$D"/home/.splinter/inbox/*pic.png 2>/dev/null | head -1)
|
|
check_that "the binary part lands in the inbox" test -n "$found"
|
|
check_that "the bytes are the bytes" sh -c "printf PNGDATA | cmp - '$found'"
|
|
check_that "the model is told the path" grep -rq 'file pic.png at' "$D/home/.splinter"
|
|
|
|
# the raw shape (base64 in "raw") is the same thing
|
|
resp14=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"14\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m14\",\"role\":\"ROLE_USER\",\"parts\":[{\"raw\":\"$b64\",\"mediaType\":\"image/png\",\"metadata\":{\"filename\":\"raw.png\"}},{\"text\":\"und das\"}]}}}")
|
|
echo "$resp14" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
found=$(ls "$D"/home/.splinter/inbox/*raw.png 2>/dev/null | head -1)
|
|
check_that "a raw part lands in the inbox" test -n "$found"
|
|
|
|
# a binary part without a session and without an inbox still must not be lost
|
|
# silently: a text/plain raw part is still text
|
|
resp15=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"15\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m15\",\"role\":\"ROLE_USER\",\"parts\":[{\"raw\":\"$b64\",\"mediaType\":\"text/plain\"}]}}}")
|
|
echo "$resp15" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
|
|
# SubscribeToTask: the stored state, once, as an SSE status update
|
|
resp16=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"16\",\"method\":\"SubscribeToTask\",\"params\":{\"id\":\"$id\"}}")
|
|
echo "$resp16" | grep -q 'statusUpdate'
|
|
check test $? -eq 0
|
|
echo "$resp16" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
echo "$resp16" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
resp16=$(post "$P" '{"jsonrpc":"2.0","id":"16","method":"SubscribeToTask","params":{"id":"nope"}}')
|
|
echo "$resp16" | grep -q '"code":-32001'
|
|
check test $? -eq 0
|
|
|
|
# ListTasks: the stored task, and an empty list for another context
|
|
resp7=$(post "$P" '{"jsonrpc":"2.0","id":"7","method":"ListTasks","params":{}}')
|
|
echo "$resp7" | grep -q "$id"
|
|
check test $? -eq 0
|
|
resp8=$(post "$P" '{"jsonrpc":"2.0","id":"8","method":"ListTasks","params":{"contextId":"other"}}')
|
|
echo "$resp8" | grep -q '"tasks":\[\]'
|
|
check test $? -eq 0
|
|
|
|
# a task that does not exist is a JSON-RPC error, not an empty answer
|
|
resp4=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"4\",\"method\":\"GetTask\",\"params\":{\"id\":\"nope\"}}")
|
|
echo "$resp4" | grep -q '"code":-32001'
|
|
check test $? -eq 0
|
|
|
|
# a text/plain raw part is accepted; a url part is refused, not fetched
|
|
resp10=$(post "$P" '{"jsonrpc":"2.0","id":"10","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"raw":"aGFsbG8=","mediaType":"text/plain"}]}}}')
|
|
echo "$resp10" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
resp11=$(post "$P" '{"jsonrpc":"2.0","id":"11","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"url":"http://example/x"}]}}}')
|
|
echo "$resp11" | grep -q '"code":-32005'
|
|
check test $? -eq 0
|
|
|
|
# a text/plain URL on loopback is fetched; the file server sees the GET
|
|
resp14=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"14\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",\"parts\":[{\"url\":\"http://127.0.0.1:$P3/file.txt\",\"mediaType\":\"text/plain\"}]}}}")
|
|
echo "$resp14" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
grep -q 'get /file.txt' "$D/hook.log"
|
|
check test $? -eq 0
|
|
|
|
# a push config posts the completed task to the loopback webhook
|
|
resp12=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"12\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",\"parts\":[{\"text\":\"push\"}]},\"configuration\":{\"taskPushNotificationConfig\":{\"url\":\"http://127.0.0.1:$P3/hook\",\"token\":\"t1\",\"authentication\":{\"scheme\":\"Bearer\",\"credentials\":\"secret\"}}}}}")
|
|
echo "$resp12" | grep -q 'TASK_STATE_COMPLETED'
|
|
check test $? -eq 0
|
|
for i in $(seq 1 50); do
|
|
grep -q 'hallo von splinter' "$D/hook.log" 2>/dev/null && break
|
|
sleep 0.2
|
|
done
|
|
check_that "the push carries the answer" grep -q 'hallo von splinter' "$D/hook.log"
|
|
check_that "the push carries the bearer credential" \
|
|
grep -q 'auth=Bearer secret' "$D/hook.log"
|
|
check_that "the push carries its token" grep -q 'token=t1' "$D/hook.log"
|
|
|
|
# a push to a host that is not allowlisted is refused before the turn
|
|
resp13=$(post "$P" '{"jsonrpc":"2.0","id":"13","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"text":"push"}]},"configuration":{"taskPushNotificationConfig":{"url":"http://example.com/hook"}}}}')
|
|
echo "$resp13" | grep -q '"code":-32003'
|
|
check test $? -eq 0
|
|
|
|
# userinfo in front of an allowed host is not that host (SSRF)
|
|
resp15=$(post "$P" '{"jsonrpc":"2.0","id":"15","method":"SendMessage","params":{"message":{"messageId":"m","role":"ROLE_USER","parts":[{"text":"push"}]},"configuration":{"taskPushNotificationConfig":{"url":"http://localhost:x@169.254.169.254/hook"}}}}')
|
|
printf '%s' "$resp15" | grep -q '"code":-32003'
|
|
check_that "userinfo push url refused" test $? -eq 0
|
|
|
|
# the reply carries the top-level id, not the first "id" in the body
|
|
resp16=$(post "$P" '{"jsonrpc":"2.0","params":{"id":"inner"},"method":"GetTask","id":77}')
|
|
printf '%s' "$resp16" | grep -q '"id":77,'
|
|
check_that "top-level id answered" test $? -eq 0
|
|
resp17=$(post "$P" '{"jsonrpc":"2.0","method":"GetTask","params":{"id":"x"},"id":"a\"b"}')
|
|
printf '%s' "$resp17" | grep -qF '"id":"a\"b"'
|
|
check_that "string id escaped" test $? -eq 0
|
|
|
|
# a contextId that would be stored cut short is refused
|
|
longctx=$(printf 'c%.0s' $(seq 1 200))
|
|
resp18=$(post "$P" "{\"jsonrpc\":\"2.0\",\"id\":\"18\",\"method\":\"SendMessage\",\"params\":{\"message\":{\"messageId\":\"m\",\"role\":\"ROLE_USER\",\"contextId\":\"$longctx\",\"parts\":[{\"text\":\"x\"}]}}}")
|
|
printf '%s' "$resp18" | grep -q 'contextId too long'
|
|
check_that "long contextId refused" test $? -eq 0
|
|
|
|
# ---- the client half against the server half ----
|
|
# discovery (the agent card names /a2a) plus a blocking turn, then the
|
|
# streaming path: both sides of the protocol in one process pair
|
|
cardurl="http://127.0.0.1:$P/.well-known/agent-card.json"
|
|
out=$(HOME="$D/home" SPLINTER_A2A_CARD="$cardurl" SPLINTER_A2A_TIMEOUT=20 \
|
|
./splinter --no-config --plugin plugins/a2a/a2a.so --transport a2a \
|
|
--no-stream -p "hallo" 2>&1)
|
|
echo "$out" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
out=$(HOME="$D/home" SPLINTER_A2A_CARD="$cardurl" SPLINTER_A2A_TIMEOUT=20 \
|
|
./splinter --no-config --plugin plugins/a2a/a2a.so --transport a2a \
|
|
-p "hallo" 2>&1)
|
|
echo "$out" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
|
|
# ---- token: without it a request is 401, with it the turn runs ----
|
|
HOME="$D/home" SPLINTER_A2A_SERVER_TOKEN=tok ./splinter --no-config \
|
|
--script "$D/model.txt" --a2a-server-listen 127.0.0.1 \
|
|
--a2a-listen-port "$P2" >"$D/out2" 2>"$D/err2" &
|
|
S2=$!
|
|
check wait_port "$P2"
|
|
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Content-Type: application/json' \
|
|
--data "$(send_json)" "http://127.0.0.1:$P2/a2a")
|
|
check test "$code" = 401
|
|
resp5=$(post "$P2" "$(send_json)" -H 'Authorization: Bearer tok')
|
|
echo "$resp5" | grep -q 'hallo von splinter'
|
|
check test $? -eq 0
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_a2a_server: ok"; exit 0; fi
|
|
exit 1
|