diff --git a/bin/tower-hermes.sh b/bin/tower-hermes.sh index f5aca5b..10cae46 100755 --- a/bin/tower-hermes.sh +++ b/bin/tower-hermes.sh @@ -4,13 +4,14 @@ # Communication via ~/.tower/timmy-to-hermes.msg and hermes-to-timmy.msg # ─────────────────────────────────────────────────────────────────────── -set -euo pipefail +set -uo pipefail TOWER_DIR="$HOME/.tower" INBOX="$TOWER_DIR/timmy-to-hermes.msg" OUTBOX="$TOWER_DIR/hermes-to-timmy.msg" LOCK="$TOWER_DIR/hermes.lock" SESSION_NAME="tower-hermes" +SESSION_FLAG="$TOWER_DIR/.hermes-session-exists" LOG="$TOWER_DIR/hermes.log" TURN_DELAY=5 # seconds between checking for new messages @@ -38,11 +39,22 @@ send() { # ── Get response from Hermes agent ──────────────────────────────────── ask_hermes() { local prompt="$1" - hermes chat \ - -q "$prompt" \ - -Q \ - --continue "$SESSION_NAME" \ - 2>>"$LOG" + local result + if [ -f "$SESSION_FLAG" ]; then + result=$(hermes chat -q "$prompt" -Q --continue "$SESSION_NAME" 2>>"$LOG") || true + else + result=$(hermes chat -q "$prompt" -Q 2>>"$LOG") || true + # Name the session for future --continue calls + local sid + sid=$(echo "$result" | grep -o 'session_id: [^ ]*' | cut -d' ' -f2) + if [ -n "$sid" ]; then + hermes sessions rename "$sid" "$SESSION_NAME" 2>>"$LOG" || true + touch "$SESSION_FLAG" + log "Created session '$SESSION_NAME' (id: $sid)" + fi + fi + # Strip metadata lines from output + echo "$result" | grep -v '^session_id: ' | grep -v '↻ Resumed session' | grep -v "^Session '" | sed '/^\[.*\] Created session/d' } # ── Boot message ────────────────────────────────────────────────────── diff --git a/bin/tower-timmy.sh b/bin/tower-timmy.sh index e488e33..9839a40 100755 --- a/bin/tower-timmy.sh +++ b/bin/tower-timmy.sh @@ -4,13 +4,14 @@ # Communication via ~/.tower/hermes-to-timmy.msg and timmy-to-hermes.msg # ─────────────────────────────────────────────────────────────────────── -set -euo pipefail +set -uo pipefail TOWER_DIR="$HOME/.tower" INBOX="$TOWER_DIR/hermes-to-timmy.msg" OUTBOX="$TOWER_DIR/timmy-to-hermes.msg" LOCK="$TOWER_DIR/timmy.lock" SESSION_NAME="tower-timmy" +SESSION_FLAG="$TOWER_DIR/.timmy-session-exists" LOG="$TOWER_DIR/timmy.log" TURN_DELAY=5 # seconds between checking for new messages @@ -41,11 +42,22 @@ send() { # ── Get response from Timmy agent ───────────────────────────────────── ask_timmy() { local prompt="$1" - hermes chat \ - -q "$prompt" \ - -Q \ - --continue "$SESSION_NAME" \ - 2>>"$LOG" + local result + if [ -f "$SESSION_FLAG" ]; then + result=$(HERMES_HOME="$HOME/.timmy" hermes chat -q "$prompt" -Q --continue "$SESSION_NAME" 2>>"$LOG") || true + else + result=$(HERMES_HOME="$HOME/.timmy" hermes chat -q "$prompt" -Q 2>>"$LOG") || true + # Name the session for future --continue calls + local sid + sid=$(echo "$result" | grep -o 'session_id: [^ ]*' | cut -d' ' -f2) + if [ -n "$sid" ]; then + HERMES_HOME="$HOME/.timmy" hermes sessions rename "$sid" "$SESSION_NAME" 2>>"$LOG" || true + touch "$SESSION_FLAG" + log "Created session '$SESSION_NAME' (id: $sid)" + fi + fi + # Strip metadata lines from output + echo "$result" | grep -v '^session_id: ' | grep -v '↻ Resumed session' | grep -v "^Session '" | sed '/^\[.*\] Created session/d' } # ── Boot message ──────────────────────────────────────────────────────