#!/usr/bin/env bash
# ── Hermes Ops Dashboard v2 ────────────────────────────────────────────
# Clean 3-pane layout:
#   ┌───────────────────────────────────┬────────────────────────────────┐
#   │                                   │                                │
#   │  STATUS + GITEA + QUEUE           │  KIMI LIVE FEED               │
#   │  (auto-refresh 20s)               │  (tail log, colored)          │
#   │                                   │                                │
#   │                                   │                                │
#   ├───────────────────────────────────┴────────────────────────────────┤
#   │  CONTROLS (bash prompt with helpers loaded)                        │
#   └────────────────────────────────────────────────────────────────────┘
# ───────────────────────────────────────────────────────────────────────
SESSION="ops"

tmux kill-session -t "$SESSION" 2>/dev/null

tmux new-session -d -s "$SESSION"

# Split: left status (60%) | right kimi log (40%)
tmux split-window -h -p 40 -t "$SESSION"

# Split left pane: top status (80%) | bottom controls (20%)
tmux split-window -v -p 20 -t "$SESSION:1.1"

# Pane 1 (top-left): consolidated status, auto-refresh
tmux send-keys -t "$SESSION:1.1" "watch -n 20 -t -c 'bash ~/.hermes/bin/ops-panel.sh'" Enter

# Pane 2 (right): kimi live feed with color
tmux send-keys -t "$SESSION:1.2" "tail -f ~/.hermes/logs/kimi-loop.log | GREP_COLOR='1;32' grep --color=always -E 'SUCCESS|$' | GREP_COLOR='1;31' grep --color=always -E 'FAILED|BACKOFF|$' | GREP_COLOR='1;36' grep --color=always -E 'ISSUE #[0-9]+|$'" Enter

# Pane 3 (bottom-left): controls with helpers sourced
tmux send-keys -t "$SESSION:1.3" "source ~/.hermes/bin/ops-helpers.sh && ops-help" Enter

# Focus on status pane
tmux select-pane -t "$SESSION:1.1"

tmux attach -t "$SESSION"
