feat(af): each fleet node casts its own local session of techne
This commit is contained in:
@@ -1,51 +1,53 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# ~/bin/af - Antigravity Fleet Unified Session Connector
|
# ~/bin/af - Antigravity Fleet Session Connector
|
||||||
# Attaches to the central persistent Antigravity CLI session (default: bazina).
|
# Each node in the fleet casts its own local session of Techné.
|
||||||
|
# If a specific node is requested (e.g. af bazina), connects to that node.
|
||||||
|
|
||||||
SESSION_NAME="agy"
|
set -euo pipefail
|
||||||
DEFAULT_HOST="bazina"
|
|
||||||
DEFAULT_IP="192.168.1.104"
|
SESSION_NAME="techne"
|
||||||
FALLBACK_HOST="boxC"
|
|
||||||
FALLBACK_IP="192.168.1.101"
|
|
||||||
REMOTE_PORT="2222"
|
|
||||||
EXTERNAL_HOST="home"
|
|
||||||
DEFAULT_CONV="9860fe31-3526-48d1-9063-3e58e630faf9"
|
DEFAULT_CONV="9860fe31-3526-48d1-9063-3e58e630faf9"
|
||||||
|
|
||||||
# Determine current node
|
|
||||||
CURRENT_HOST="$(hostname -s 2>/dev/null || uname -n)"
|
CURRENT_HOST="$(hostname -s 2>/dev/null || uname -n)"
|
||||||
if [ -n "$TERMUX_VERSION" ] || [ -d "/data/data/com.termux" ]; then
|
if [ -n "${TERMUX_VERSION:-}" ] || [ -d "/data/data/com.termux" ]; then
|
||||||
CURRENT_HOST="phone"
|
CURRENT_HOST="phone"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build agy conversation parameter if not already supplied
|
TARGET_NODE=""
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
case "$1" in
|
||||||
|
t520|bazina|boxC|penguin|android|phone)
|
||||||
|
TARGET_NODE="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build agy invocation
|
||||||
AGY_INVOCATION="agy"
|
AGY_INVOCATION="agy"
|
||||||
if [[ "$*" != *"--conversation"* ]] && [[ -n "$DEFAULT_CONV" ]]; then
|
if [[ "$*" != *"--conversation"* ]] && [[ -n "$DEFAULT_CONV" ]]; then
|
||||||
AGY_INVOCATION="agy --conversation=$DEFAULT_CONV"
|
AGY_INVOCATION="agy --conversation=$DEFAULT_CONV"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$CURRENT_HOST" == "bazina" ]]; then
|
log_cast() {
|
||||||
# Already on default node (bazina): attach or create local tmux session
|
local node="${1:-$CURRENT_HOST}"
|
||||||
exec tmux new-session -A -s "$SESSION_NAME" $AGY_INVOCATION "$@"
|
if command -v now >/dev/null 2>&1; then
|
||||||
elif [[ "$CURRENT_HOST" == "boxC" || "$CURRENT_HOST" == "B" ]]; then
|
now "[AF:$node] Techné session cast/attached" || true
|
||||||
# On boxC: connect to bazina if reachable, otherwise fall back to local boxC session
|
|
||||||
if ping -c 1 -W 1 "$DEFAULT_IP" &>/dev/null || ssh -o BatchMode=yes -o ConnectTimeout=2 "$DEFAULT_HOST" "true" &>/dev/null; then
|
|
||||||
exec ssh -t "$DEFAULT_HOST" "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
|
||||||
else
|
|
||||||
echo "[af] bazina is unreachable from boxC; falling back to local boxC session..."
|
|
||||||
exec tmux new-session -A -s "$SESSION_NAME" $AGY_INVOCATION "$@"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Remote node (t520, penguin, android/phone, etc.)
|
|
||||||
# 1. Try default node (bazina) on LAN
|
|
||||||
if ping -c 1 -W 1 "$DEFAULT_IP" &>/dev/null || ssh -o BatchMode=yes -o ConnectTimeout=2 "$DEFAULT_HOST" "true" &>/dev/null; then
|
|
||||||
exec ssh -t "$DEFAULT_HOST" "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
|
||||||
# 2. Fallback to boxC on LAN
|
|
||||||
elif ping -c 1 -W 1 "$FALLBACK_IP" &>/dev/null || ssh -o BatchMode=yes -o ConnectTimeout=2 "$FALLBACK_HOST" "true" &>/dev/null; then
|
|
||||||
echo "[af] bazina unreachable; falling back to boxC on LAN..."
|
|
||||||
exec ssh -t "$FALLBACK_HOST" "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
|
||||||
# 3. Fallback to external SSH via home gateway
|
|
||||||
else
|
|
||||||
echo "[af] LAN unreachable; attempting external gateway fallback..."
|
|
||||||
exec ssh -p "$REMOTE_PORT" -t "$EXTERNAL_HOST" "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$TARGET_NODE" ] && [ "$TARGET_NODE" != "$CURRENT_HOST" ]; then
|
||||||
|
log_cast "$TARGET_NODE"
|
||||||
|
echo "[af] Connecting to Techné session on $TARGET_NODE..."
|
||||||
|
exec ssh -t "$TARGET_NODE" "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Cast local session of Techné
|
||||||
|
log_cast "$CURRENT_HOST"
|
||||||
|
if command -v tmux >/dev/null 2>&1; then
|
||||||
|
exec tmux new-session -A -s "$SESSION_NAME" $AGY_INVOCATION "$@"
|
||||||
|
elif command -v agy >/dev/null 2>&1; then
|
||||||
|
exec agy --conversation="$DEFAULT_CONV" "$@"
|
||||||
|
else
|
||||||
|
echo "[af] Local agy/tmux not found on $CURRENT_HOST; falling back to boxC..."
|
||||||
|
exec ssh -t boxC "tmux new-session -A -s '$SESSION_NAME' $AGY_INVOCATION $*"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user