The harness was two halves that could not see each other: main.c built the
agent, ui.c ran it -- with the curses thread model, the approval condition
variable, the slash commands and the provider switching inside the drawing
code. A second front end had to copy all of it.
Now:
src/backend/ engine.c owns the session, the turn thread, the event queue
and every command; agent, transports, tools, session, config,
providers, plugins and the protocol servers move here.
src/frontend/ curses.c draws and reads keys through ui_backend.h;
ui_local.c is the engine in this process, ui_remote.c is a
served engine behind a socket. protocol.c serves the engine
as JSON lines (protocol 2: history, approvals, steering);
client.c is splinterctl, the reference client.
splinter --serve / --attach: the same screen runs as a client of a served
engine, so the socket carries everything the front end needs. docs/PROTOCOL.md
and docs/FRONTENDS.md describe the contract; docs/proto-example.py is a
60-line client. tests/test_engine, test_protocol and test_attach cover the
event order, the socket and the attach mode.
Review fixes in the same tree: dynamic line buffers (9 KB prompts and 8 KB
events were truncated), a turn event no longer ends the busy window (steer
leftovers), the screen finalises every turn, /new keeps the profile, reopens
the log and gets unique ids, the profile is remembered in <session>.agent so
--resume comes back in it, agent statistics are a locked snapshot (no data
race), !shell keeps 64 KiB with a marker, the socket probes for a live server,
compares its inode and sets CLOEXEC/SNDTIMEO, exit 2 means configuration,
BSD peer checks use getpeereid, and the i18n checker scans the new
subdirectories again.
Includes the parallel session's SSE fix: the parser reports what a line
produced, so a tool name no longer lands in the answer ("readread").
133 lines
3.9 KiB
Bash
Executable File
133 lines
3.9 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# splinter -- the curses front end attached to a served engine.
|
|
#
|
|
# What it guards: --attach is a protocol client, not a second engine. The
|
|
# screen shows the server's session (not one of its own), a prompt runs on the
|
|
# server, /status answers with the server's numbers, Tab switches the server's
|
|
# agent profile, and Ctrl-D ends the client while the server keeps serving.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
if ! command -v tmux >/dev/null 2>&1; then
|
|
echo "test_attach: skipped (no tmux)"
|
|
exit 0
|
|
fi
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-attach-XXXXXX") || exit 1
|
|
unset TMUX TMUX_PANE
|
|
export TMUX_TMPDIR="$D"
|
|
own_server() {
|
|
if [ -n "${TMUX:-}" ] || [ "${TMUX_TMPDIR:-}" != "$D" ]; then
|
|
echo "test_attach: refusing to touch a tmux server this test does not own" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
killserver() { own_server; tmux kill-server 2>/dev/null; }
|
|
S=splinter-attach-$$
|
|
P=$((20000 + ($$ + 7) % 30000))
|
|
F=
|
|
G=
|
|
fails=0
|
|
cleanup() {
|
|
killserver
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
[ -n "$G" ] && kill "$G" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
check() { if "$@"; then :; else echo "FAIL $*"; fails=$((fails + 1)); fi; }
|
|
shows() {
|
|
for i in $(seq 1 60); do
|
|
tmux capture-pane -t $S -p | grep -q -- "$1" && return 0
|
|
sleep 0.5
|
|
done
|
|
return 1
|
|
}
|
|
idle_prompt() { # the turn is over when the prompt says build>
|
|
for i in $(seq 1 60); do
|
|
tmux capture-pane -t $S -p | grep -q '^build>' && return 0
|
|
sleep 0.5
|
|
done
|
|
return 1
|
|
}
|
|
typed() { tmux send-keys -t $S -l "$1"; }
|
|
key() { tmux send-keys -t $S "$@"; }
|
|
|
|
mkdir -p "$D/server" "$D/client"
|
|
python3 -I tests/fake_telegram.py "$P" "$D/out.txt" "$D/sent.log" ok \
|
|
> "$D/fake.log" 2>&1 &
|
|
F=$!
|
|
for i in $(seq 1 60); do
|
|
curl -s -o /dev/null "http://127.0.0.1:$P/x" && break
|
|
sleep 0.2
|
|
done
|
|
HOME=$D/server SPLINTER_LOCALE=en ./splinter --no-config --autonomous \
|
|
--endpoint "http://127.0.0.1:$P/v1/chat/completions" --model m \
|
|
--serve --socket "$D/sock" > "$D/serve.log" 2>&1 &
|
|
G=$!
|
|
for i in $(seq 1 60); do
|
|
[ -S "$D/sock" ] && break
|
|
sleep 0.2
|
|
done
|
|
if [ ! -S "$D/sock" ]; then
|
|
echo "FAIL the server has no socket"
|
|
cat "$D/serve.log"
|
|
exit 1
|
|
fi
|
|
|
|
# a turn before the attach: the client must see it in the transcript
|
|
HOME=$D/server SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--say "fruehere frage" > "$D/say-before.txt" 2>/dev/null
|
|
check grep -q 'fertig' "$D/say-before.txt"
|
|
|
|
# the server chooses the session; the client must show it, not one of its own
|
|
HOME=$D/server SPLINTER_LOCALE=en ./splinterctl --socket "$D/sock" \
|
|
--cmd /status > "$D/status.txt" 2>/dev/null
|
|
sess=$(sed -n 's/^ session //p' "$D/status.txt" | head -1)
|
|
check test -n "$sess"
|
|
|
|
tmux new-session -d -s $S -x 110 -y 30 \
|
|
"HOME=$D/client SPLINTER_LOCALE=en ./splinter --no-config \
|
|
--attach --socket $D/sock 2>/dev/null; echo \$? > $D/rc"
|
|
check shows 'Enter sends'
|
|
check shows "$sess"
|
|
check shows 'fruehere frage'
|
|
check shows 'fertig'
|
|
|
|
typed 'single word ok'; key Enter
|
|
check idle_prompt
|
|
check shows '<m> ok'
|
|
check shows "$sess"
|
|
|
|
typed '/status'; key Enter
|
|
check shows 'status ('
|
|
check shows "$sess"
|
|
|
|
# Tab switches the profile in the engine, not in this process
|
|
key Tab
|
|
check shows 'agent: plan'
|
|
|
|
# Ctrl-D ends the client; the server must still be there
|
|
key C-u C-d
|
|
for i in $(seq 1 40); do [ -s "$D/rc" ] && break; sleep 0.5; done
|
|
check test "$(cat "$D/rc" 2>/dev/null)" = 0
|
|
check test -S "$D/sock"
|
|
check kill -0 "$G" 2>/dev/null
|
|
|
|
# no server: attach refuses with an error instead of pretending
|
|
HOME=$D/client SPLINTER_LOCALE=en ./splinter --no-config --attach \
|
|
--socket "$D/nosock" > /dev/null 2> "$D/err.txt"
|
|
check test $? -eq 3
|
|
check grep -q 'nosock' "$D/err.txt"
|
|
|
|
# --attach is the screen alone: a prompt or a server mode is a contradiction
|
|
HOME=$D/client SPLINTER_LOCALE=en ./splinter --no-config --attach \
|
|
--socket "$D/sock" -p hallo > /dev/null 2> "$D/conflict.txt"
|
|
check test $? -eq 2
|
|
check grep -q 'screen alone' "$D/conflict.txt"
|
|
|
|
if [ "$fails" -eq 0 ]; then
|
|
echo "test_attach: ok"
|
|
exit 0
|
|
fi
|
|
exit 1
|