From 59abf0fa7d9504d54c97030f99145c8183258690 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Thu, 16 Apr 2026 19:35:02 +0200 Subject: [PATCH] scripts/osh: fix session creation and /kill Replace write to defunct /ctl with s/new spec format. Add -name flag so named sessions skip the post-write poll. Fix /kill to write to s/{id}/ctl instead of the removed top-level ctl file. Co-Authored-By: Claude Sonnet 4.6 --- scripts/osh | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/scripts/osh b/scripts/osh index 9715918..d4412ab 100755 --- a/scripts/osh +++ b/scripts/osh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# ollie.sh: a simplified, fully-functional chat interface for ollie AI agents. +# osh: interactive chat interface for ollie AI agents. set -o history MOUNT=${OLLIE_9MOUNT:-$HOME/mnt/ollie} @@ -30,45 +30,52 @@ drain() { } # Parse flags -new=0; resume=0; id_flag= +new=0; resume=0; id_flag=; name= backend=; model=; agent=; cwd= while [ $# -gt 0 ]; do case $1 in -new) new=1 ;; -resume) resume=1 ;; -session) id_flag=$2; shift ;; + -name) name=$2; shift ;; -backend) backend=$2; shift ;; - -model) model=$2; shift ;; - -agent) agent=$2; shift ;; - -cwd) cwd=$2; shift ;; + -model) model=$2; shift ;; + -agent) agent=$2; shift ;; + -cwd) cwd=$2; shift ;; *) die "unknown flag: $1" ;; esac shift done -# Build "new" ctl command with opts -new_cmd() { - local cmd=new - [ -n "$backend" ] && cmd="$cmd backend=$backend" - [ -n "$model" ] && cmd="$cmd model=$model" - [ -n "$agent" ] && cmd="$cmd agent=$agent" - cmd="$cmd cwd=${cwd:-$(pwd)}" - printf '%s\n' "$cmd" +# Write spec to s/new +write_new() { + { + [ -n "$name" ] && printf 'name=%s\n' "$name" + printf 'cwd=%s\n' "${cwd:-$(pwd)}" + [ -n "$backend" ] && printf 'backend=%s\n' "$backend" + [ -n "$model" ] && printf 'model=%s\n' "$model" + [ -n "$agent" ] && printf 'agent=%s\n' "$agent" + } > "$MOUNT/s/new" || die "write s/new" } # Create a fresh session, sets $id create_session() { local before d deadline - before=$(ls "$MOUNT/s" 2>/dev/null) - new_cmd > "$MOUNT/ctl" || die "write ctl" - deadline=$(($(date +%s) + 5)) - while [ "$(date +%s)" -lt "$deadline" ]; do - for d in $(ls "$MOUNT/s" 2>/dev/null); do - printf '%s\n' "$before" | grep -qxF "$d" || { id=$d; return; } + if [ -n "$name" ]; then + write_new + id=$name + else + before=$(ls "$MOUNT/s" 2>/dev/null) + write_new + deadline=$(($(date +%s) + 5)) + while [ "$(date +%s)" -lt "$deadline" ]; do + for d in $(ls "$MOUNT/s" 2>/dev/null); do + printf '%s\n' "$before" | grep -qxF "$d" || { id=$d; return; } + done + sleep 0.05 done - sleep 0.05 - done - die "timeout waiting for new session" + die "timeout waiting for new session" + fi } # Resolve session @@ -109,7 +116,7 @@ while true; do [ -z "$input" ] && continue history -s "$input" case "$input" in - /kill) printf 'kill %s\n' "$id" > "$MOUNT/ctl"; break ;; + /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" ;;