The `ask` tool asks and the answer -- or "nobody answered" -- becomes the observation. Read class: it changes nothing on the machine, and the authority is the operator, not a gate. Front ends: the chat draws a dialog (options to pick, typed words still count), the protocol carries it as an `ask` event and an `answer` command, MCP returns it from splinter_say and resumes with splinter_answer, the Telegram gateway sends it as a message and takes the next message from an allowed user. What the review of the WIP found, and what this fixes: - -p hung for the full 900 s ask wait: sp_engine_prompt installed engine_ask, but nobody polls events on the synchronous path. cfg.ask now stays NULL there, so the tool answers at once with "nobody can be asked here". Measured: 3 s instead of 900 s (was rc=124 after 20 s). - splinter_say over MCP hung the same way, because tool_say only looked at st.waiting. It now looks at st.asking and returns the question; the client timed out at 15 s before, and the turn was lost. - protocol.c read the question buffer uninitialized when sp_engine_ask returned 0. - turn_ask answered nothing when the window could not be opened, which parked the turn for the full wait. - pick_run computed the list height without the question's rows, so the highlighted row scrolled out of the window (reproduced: after nine Downs no ">" row was on the screen). pick_draw and pick_run now share pick_listtop(). - the Telegram gateway was dead for this tool: it runs its turns on a copy of e->base, where ask was never set, so the model was told "nobody can be asked" while the operator sat in the chat. New tg_ask, verified against a running daemon and covered in test_gateway.sh. - tests/test_ask_ui.sh was untracked and not in make check, so it never ran. A2A keeps no ask channel on purpose: there an approval pauses the task into INPUT_REQUIRED, and the ask signature cannot express a pause -- saying "nobody can be asked" is the honest answer there. Tests: make check green (327 s), including the new test_ask_mcp.sh and test_ask_ui.sh, both wired into make check. test_ask_mcp.sh was verified to fail against the unfixed code (client times out, no result written). make check-asan: 46 binaries clean. make check-tsan: 46 binaries, no races.
82 lines
2.7 KiB
Bash
Executable File
82 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# The MCP server's session tools, over a real socket.
|
|
#
|
|
# A script transport stands in for the model ("answer hello"), so no network is
|
|
# touched: tools/list must offer the session tools, and say/history/sessions/
|
|
# models must round-trip through the engine.
|
|
set -e
|
|
cd "$(dirname "$0")/.."
|
|
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-mcps-XXXXXX") || exit 1
|
|
port=$(free_port)
|
|
pid=
|
|
cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; rm -rf "$D"; }
|
|
trap cleanup EXIT INT TERM
|
|
|
|
mkdir -p "$D/home"
|
|
echo "answer hello" > "$D/replies"
|
|
HOME=$D/home ./splinter --no-config --autonomous --model m \
|
|
--script "$D/replies" --mcp-server-listen 127.0.0.1 \
|
|
--mcp-listen-port "$port" > "$D/srv.out" 2>&1 &
|
|
pid=$!
|
|
|
|
# the helper proves our own server owns the socket, so a port another program
|
|
# holds cannot make the checks below talk to a stranger
|
|
if ! wait_tcp "$port" "$pid"; then
|
|
echo "test_mcpsession: the MCP server did not start on $port"
|
|
cat "$D/srv.out"
|
|
exit 1
|
|
fi
|
|
|
|
python3 - "$port" <<'PY'
|
|
import json, socket, sys
|
|
|
|
s = socket.create_connection(("127.0.0.1", int(sys.argv[1])), 5)
|
|
# a turn is a turn: the script transport is fast, but the machine may be busy
|
|
s.settimeout(120)
|
|
f = s.makefile("rw", encoding="utf-8")
|
|
|
|
def req(i, method, params=None):
|
|
o = {"jsonrpc": "2.0", "id": i, "method": method}
|
|
if params is not None:
|
|
o["params"] = params
|
|
f.write(json.dumps(o) + "\n"); f.flush()
|
|
return json.loads(f.readline())
|
|
|
|
def call(i, name, args):
|
|
r = req(i, "tools/call", {"name": name, "arguments": args})
|
|
if "error" in r:
|
|
print("error:", r["error"], file=sys.stderr); sys.exit(1)
|
|
return r["result"]["content"][0]["text"]
|
|
|
|
init = req(1, "initialize", {})
|
|
assert init["result"]["serverInfo"]["name"] == "splinter", init
|
|
tools = [t["name"] for t in req(2, "tools/list")["result"]["tools"]]
|
|
for want in ("splinter_sessions", "splinter_state", "splinter_models",
|
|
"splinter_history", "splinter_say", "splinter_steer",
|
|
"splinter_cancel", "splinter_approve", "splinter_answer"):
|
|
assert want in tools, (want, tools)
|
|
|
|
state = call(3, "splinter_state", {})
|
|
assert "model: m" in state, state
|
|
assert "session: sess-" in state, state
|
|
|
|
say = call(4, "splinter_say", {"text": "hi"})
|
|
assert "hello" in say, say
|
|
|
|
hist = call(5, "splinter_history", {"limit": 10})
|
|
assert "[user] hi" in hist and "[assistant] hello" in hist, hist
|
|
|
|
sessions = call(6, "splinter_sessions", {})
|
|
assert "sess-" in sessions and "*" in sessions, sessions
|
|
|
|
models = call(7, "splinter_models", {})
|
|
assert "local/m" in models, models
|
|
|
|
cancel = call(8, "splinter_cancel", {})
|
|
assert "no turn is running" in cancel, cancel
|
|
print("test_mcpsession: ok")
|
|
PY
|