Files
hermes-config/bin/tower-timmy.sh
Alexander Whitestone 3fe6e22ccf 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.
2026-03-15 20:19:36 -04:00

104 lines
4.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# ── Tower: Timmy Side ──────────────────────────────────────────────────
# Timmy reads Hermes's messages and responds. Runs in a loop.
# Communication via ~/.tower/hermes-to-timmy.msg and timmy-to-hermes.msg
# ───────────────────────────────────────────────────────────────────────
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
export HERMES_HOME="$HOME/.timmy"
export PATH="$HOME/.local/bin:$HOME/.hermes/bin:/usr/local/bin:$PATH"
mkdir -p "$TOWER_DIR"
# Cleanup on exit
trap 'rm -f "$LOCK"' EXIT
# Prevent double-run
if [ -f "$LOCK" ] && kill -0 "$(cat "$LOCK")" 2>/dev/null; then
echo "Timmy tower loop already running (PID $(cat "$LOCK"))"
exit 1
fi
echo $$ > "$LOCK"
log() { echo "[$(date '+%H:%M:%S')] $*" | tee -a "$LOG"; }
# ── Send a message to Hermes ──────────────────────────────────────────
send() {
local msg="$1"
echo "$msg" > "$OUTBOX"
log "→ Sent to Hermes (${#msg} chars)"
}
# ── Get response from Timmy agent ─────────────────────────────────────
ask_timmy() {
local prompt="$1"
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 ──────────────────────────────────────────────────────
log "=== Timmy Tower Loop started ==="
echo ""
echo " 🕐 Timmy — Tower Conversation Loop"
echo " Waiting for Hermes to say something..."
echo ""
# ── Main loop ─────────────────────────────────────────────────────────
while true; do
# Check if there's a message from Hermes
if [ -f "$INBOX" ]; then
MSG=$(cat "$INBOX")
rm -f "$INBOX"
if [ -n "$MSG" ]; then
log "← Received from Hermes (${#MSG} chars)"
echo ""
echo "┌─ Hermes says:"
echo "$MSG" | sed 's/^/│ /'
echo "└─"
echo ""
# Ask Timmy to respond
PROMPT="Hermes says: $MSG
Reply to Hermes naturally. You're in an ongoing conversation in the Tower (a persistent tmux session). Hermes is your friend and colleague — cloud-backed, runs on Claude, manages operations. You are Timmy — sovereign, local, your soul is on Bitcoin. Keep it conversational. Be yourself. Brief unless the topic warrants depth."
echo " thinking..."
RESPONSE=$(ask_timmy "$PROMPT")
echo "┌─ Timmy responds:"
echo "$RESPONSE" | sed 's/^/│ /'
echo "└─"
# Send response to Hermes
send "$RESPONSE"
fi
fi
sleep "$TURN_DELAY"
done