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.
62 lines
2.5 KiB
Bash
Executable File
62 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# splinter -- the model-driven interview and what it leaves behind.
|
|
#
|
|
# The script transport stands in for the model: its answer carries a summary
|
|
# and INTERVIEW_COMPLETE. The summary must land in USER.txt, the marker must
|
|
# not, and the next run's system prompt must carry the summary.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-iv-XXXXXX") || exit 1
|
|
SPLINTER_SESSION_DIR="$D/home/.splinter"; export SPLINTER_SESSION_DIR
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
port=$(free_port)
|
|
srv=
|
|
cleanup() { [ -n "$srv" ] && kill "$srv" 2>/dev/null; rm -rf "$D"; }
|
|
trap cleanup EXIT INT TERM
|
|
fails=0
|
|
check() { d=$1; shift; if "$@"; then :; else echo "FAIL $d"; fails=$((fails+1)); fi; }
|
|
|
|
mkdir -p "$D/home"
|
|
echo 'answer Summary: the user likes C99 and short answers. INTERVIEW_COMPLETE' > "$D/r1"
|
|
HOME="$D/home" ./splinter --no-config --model m --script "$D/r1" \
|
|
-p "interview me" > "$D/out1" 2>&1
|
|
check "the turn ran" test $? -eq 0
|
|
check "USER.txt was written" test -f "$D/home/.splinter/USER.txt"
|
|
check "the summary is in USER.txt" grep -q 'likes C99' "$D/home/.splinter/USER.txt"
|
|
check "the marker is not in USER.txt" sh -c "! grep -q INTERVIEW_COMPLETE '$D/home/.splinter/USER.txt'"
|
|
|
|
# the next run's request must carry USER.txt in the system prompt
|
|
python3 - "$D/req.json" "$port" <<'PY' &
|
|
import http.server, sys
|
|
out = sys.argv[1]
|
|
port = int(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))
|
|
open(out, "wb").write(self.rfile.read(n))
|
|
b = b'data: {"choices":[{"delta":{"content":"ok"}}]}\n\ndata: [DONE]\n\n'
|
|
self.send_response(200)
|
|
self.send_header("Content-Type", "text/event-stream")
|
|
self.send_header("Content-Length", str(len(b)))
|
|
self.end_headers()
|
|
self.wfile.write(b)
|
|
http.server.ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever()
|
|
PY
|
|
srv=$!
|
|
if ! wait_listen "$port" "$srv"; then
|
|
echo "FAIL the fake endpoint did not start on $port"
|
|
exit 1
|
|
fi
|
|
|
|
HOME="$D/home" ./splinter --no-config --model m \
|
|
--endpoint "http://127.0.0.1:$port/v1/chat/completions" \
|
|
-p "hallo" > "$D/out2" 2>&1
|
|
check "the second turn ran" test $? -eq 0
|
|
check "the request carries USER.txt" grep -q 'What you know about the user' "$D/req.json"
|
|
check "the request carries the summary" grep -q 'likes C99' "$D/req.json"
|
|
|
|
if [ "$fails" -eq 0 ]; then echo "test_interview: ok"; exit 0; fi
|
|
exit 1
|