Artifact 315f37fc2b2eac2d167dc5892f4a1ffbe69e082f38090ca391dd5aabc7c3ef53:
- Executable file
test/tui/lastmodel.sh
— part of check-in
[a49aa20f3e]
at
2026-11-23 15:38:55
on branch last-model
— Start new conversations on the model last chosen
A model picked in the terminal interface (picker, /model NAME, Ctrl+P) is saved as the default, so the next conversation, pic ask and pic -p start on it and the first line says "your last choice". --model, RPC set_model without persist and a phone save nothing; rememberModel false restores a fixed default. Ctrl+S in the picker says it is already saved. (user: dmestas, size: 4780) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # The model last chosen in the terminal interface is the one the next conversation starts on: # a picker pick, /model NAME and Ctrl+P save it (and the first screen says "your last choice"); # --model and the setting rememberModel=false save nothing; ask and -p start on it too. set -eu PIC=${PIC:?set PIC to the pic binary} SERVER=${SERVER:?set SERVER to the fake_server binary} DRIVE=${DRIVE:?set DRIVE to the pty_drive binary} S=$(cd "$(dirname "$0")/../pic/streams" && pwd) T=$(mktemp -d "${TMPDIR:-/tmp}/pic-tui-lastmodel.XXXXXX") T=$(cd "$T" && pwd -P) spid= cleanup() { [ -n "$spid" ] && kill "$spid" 2>/dev/null || :; rm -rf -- "$T"; } trap cleanup EXIT HUP INT TERM fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } for v in $(env | sed -nE 's/^([A-Za-z0-9_]*_(API_KEY|TOKEN))=.*/\1/p'); do unset "$v"; done unset PIC_TEST_PASSPHRASE mkdir "$T/ws" "$T/log" "$T/home" export HOME="$T/home" PIC_MODELS_FILE="$T/models.json" PIC_MODEL_CATALOG=offline PIC_PI_EXPORT=0 T export PIC_NO_NATIVE_CLIPBOARD=1 "$SERVER" "$T/port" "$T/log" 120 "at:/v1/models=status:404:-" "sse:$S/text.sse" & spid=$! i=0 while [ ! -s "$T/port" ]; do i=$((i + 1)); [ "$i" -lt 600 ] || fail "server"; sleep 0.05; done port=$(cat "$T/port") cat > "$T/models.json" <<EOM {"providers":{ "good":{"baseUrl":"http://127.0.0.1:$port","api":"anthropic-messages","apiKey":"\$GOOD_API_KEY","models":[ {"id":"m","contextWindow":200000},{"id":"n","contextWindow":200000}]}, "fake":{"baseUrl":"http://127.0.0.1:$port","api":"anthropic-messages","apiKey":"\$FAKE_API_KEY","models":[ {"id":"m","contextWindow":200000}]}}} EOM export GOOD_API_KEY=pic-lm-good FAKE_API_KEY=pic-lm-fake screen() { perl -pe 's/\e\[[0-9;?]*[A-Za-z]//g; s/\r//g' "$1" | grep -v '^\s*$' | tail -12; } drive() { # NAME ARGS...: pic on a pseudo-terminal, the script on stdin name=$1 shift "$DRIVE" "$T/$name.tx" 120 30 "$PIC" --tui-mode regular --db "$T/j" --workspace "$T/ws" "$@" || fail "$name: $(screen "$T/$name.tx")" } pic() { "$PIC" --db "$T/j" --workspace "$T/ws" "$@"; } saved() { pic settings defaultModel || :; } # A pick in the picker is the next conversation's model, and the first screen says so. drive pick --model good/m <<'EOF2' expect pic good/m send \ep expect Select a model send fake send \r expect model fake/m; new conversations start on it send \x04\x04 EOF2 [ "$(saved)" = fake/m ] || fail "pick: not saved: $(saved)" drive next <<'EOF2' expect pic fake/m expect model fake/m (your last choice; send \x04\x04 EOF2 printf 'PASS: a model picked in the picker is where the next conversation starts\n' # -p and ask pick it up too. pic -p x < /dev/null > /dev/null 2> "$T/p.err" || : grep -qF 'pic: model fake/m (your last choice' "$T/p.err" || fail "-p: $(cat "$T/p.err")" printf 'PASS: -p starts on the last choice\n' # --model is for one run: it saves nothing, and a run with it is not a choice. drive flag --model good/n <<'EOF2' expect pic good/n send \x04\x04 EOF2 [ "$(saved)" = fake/m ] || fail "--model saved: $(saved)" printf 'PASS: --model saves nothing\n' # /model NAME and Ctrl+P save too; the confirmation is said once, not on every step. drive slash <<'EOF2' expect pic fake/m send /model good/n\r wait 200 send \r expect model good/n; new conversations start on it send \x10 expect model send \x10 expect model send \x04\x04 EOF2 n=$(grep -c 'new conversations start on it' "$T/slash.tx" || :) [ "$n" -le 2 ] || fail "confirmation repeated ($n)" now=$(saved) [ "$now" != fake/m ] || fail "slash/Ctrl+P: not saved" drive cycled <<'EOF2' expect (your last choice; send \x04\x04 EOF2 grep -q "pic $now" "$T/cycled.tx" || fail "cycled: did not start on $now: $(screen "$T/cycled.tx")" printf 'PASS: /model NAME and Ctrl+P save the model\n' # Ctrl+S in the picker is the same as Enter, and says it is already saved. drive ctrls --model good/m <<'EOF2' expect pic good/m send \ep expect Select a model send fake send \x13 expect already saved send \x04\x04 EOF2 [ "$(saved)" = fake/m ] || fail "ctrl+s: $(saved)" printf 'PASS: Ctrl+S in the picker says it is already saved\n' # rememberModel=false is the old behaviour: a pick lasts for the conversation, Ctrl+S saves. pic settings rememberModel false > /dev/null drive off --model good/m <<'EOF2' expect pic good/m send \ep expect Select a model send good/n send \r expect model good/n send \x04\x04 EOF2 [ "$(saved)" = fake/m ] || fail "off: saved $(saved)" drive offsave --model good/m <<'EOF2' expect pic good/m send \ep expect Select a model send good/n send \x13 expect saved as the default send \x04\x04 EOF2 [ "$(saved)" = good/n ] || fail "off+ctrl+s: $(saved)" drive offnext <<'EOF2' expect model good/n (your saved default; send \x04\x04 EOF2 printf 'PASS: rememberModel false keeps a fixed default; Ctrl+S saves it\n'