From 3fe6e22ccf307b8a57960af0718fadae608e0c8b Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Sun, 15 Mar 2026 20:19:36 -0400 Subject: [PATCH] fix: strip hermes metadata from tower message passing Session resume lines, tool traces, and session rename output were leaking into the messages passed between agents. Added grep filters to strip them from ask_hermes/ask_timmy output. Also switched from set -e to avoid exits on non-zero from first-run --continue calls. --- bin/tower-hermes.sh | 24 ++++++++++++++++++------ bin/tower-timmy.sh | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) 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 ──────────────────────────────────────────────────────