scripts/s/sh: implement all supported slash commands

Add explicit handlers for all session ctl commands (/stop, /kill,
/compact, /clear, /rn, /cwd) and session file r/w commands (/agent,
/model, /backend) and read-only queries (/models, /backends, /usage,
/ctxsz). Ctl commands now continue past the drain loop. /rn updates
local $id/$S after rename. Unknown slash commands print an error
instead of writing garbage to ctl.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-04-18 14:53:42 +02:00
parent c5d87567ce
commit 179a157c8b
1 changed files with 38 additions and 7 deletions

View File

@ -47,9 +47,20 @@ Flags:
Input at the prompt:
<text> submit prompt, stream response
/q <text> enqueue prompt for later
/<cmd> send to session ctl (e.g. /compact, /clear)
/stop interrupt the current agent turn
/kill kill the session and exit
/compact compact conversation history
/clear clear conversation history
/rn <name> rename the session
/cwd [path] get or set working directory
/agent [name] get or set agent
/model [name] get or set model
/backend [name] get or set backend
/models list available models
/backends list available backends
/usage show token usage
/ctxsz show context size
/q <text> enqueue prompt for later
Ctrl-C interrupt running turn (or exit if idle)
EOF
exit 0
@ -144,11 +155,31 @@ while true; do
[ -z "$input" ] && continue
history -s "$input"
case "$input" in
/kill) printf 'kill\n' > "$S/ctl"; break ;;
"/q "*) printf '%s\n' "${input#/q }" > "$S/enqueue"
printf 'queued\n' >&2; continue ;;
/*) printf '%s\n' "$input" > "$S/ctl" ;;
*) printf '%s' "$input" > "$S/prompt" || { printf 'submit failed\n' >&2; continue; } ;;
/stop) printf 'stop\n' > "$S/ctl"; continue ;;
/kill) printf 'kill\n' > "$S/ctl"; break ;;
/compact) printf 'compact\n' > "$S/ctl"; continue ;;
/clear) printf 'clear\n' > "$S/ctl"; continue ;;
"/rn "*) newid=${input#/rn }
printf 'rn %s\n' "$newid" > "$S/ctl"
id=$newid; S=$MOUNT/s/$id
save_session "$_dir" "$id"; continue ;;
/cwd) cat "$S/cwd" 2>/dev/null; printf '\n'; continue ;;
"/cwd "*) newcwd=${input#/cwd }
printf 'cwd %s\n' "$newcwd" > "$S/ctl"; continue ;;
/agent) cat "$S/agent" 2>/dev/null; printf '\n'; continue ;;
"/agent "*) printf '%s\n' "${input#/agent }" > "$S/agent"; continue ;;
/model) cat "$S/model" 2>/dev/null; printf '\n'; continue ;;
"/model "*) printf '%s\n' "${input#/model }" > "$S/model"; continue ;;
/backend) cat "$S/backend" 2>/dev/null; printf '\n'; continue ;;
"/backend "*) printf '%s\n' "${input#/backend }" > "$S/backend"; continue ;;
/models) cat "$S/models" 2>/dev/null; continue ;;
/backends) cat "$MOUNT/backends" 2>/dev/null; continue ;;
/usage) cat "$S/usage" 2>/dev/null; continue ;;
/ctxsz) cat "$S/ctxsz" 2>/dev/null; continue ;;
"/q "*) printf '%s\n' "${input#/q }" > "$S/enqueue"
printf 'queued\n' >&2; continue ;;
/*) printf 'unknown command: %s\n' "${input%% *}" >&2; continue ;;
*) printf '%s' "$input" > "$S/prompt" || { printf 'submit failed\n' >&2; continue; } ;;
esac
sleep 0.15
while true; do