-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach.sh
More file actions
executable file
·69 lines (61 loc) · 2.25 KB
/
Copy pathattach.sh
File metadata and controls
executable file
·69 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# Usage: ./attach.sh <session-or-target> <agent>
# Example: ./attach.sh claude_myproject_alice claude
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <session-or-target> <agent>"
echo " session-or-target tmux session or pane target (e.g. claude_myproject_alice or claude_myproject_alice:0.0)"
echo " agent claude, codex, copilot, gemini, vibe, qwen, antigravity"
exit 1
fi
TARGET=$1
if [[ "$TARGET" != *:*.* ]]; then
if [[ "$TARGET" != *:* ]]; then
TARGET="${TARGET}:0.0"
elif [[ "$TARGET" != *.* ]]; then
TARGET="${TARGET}.0"
fi
fi
SESSION=${TARGET%%:*}
AGENT=$2
# Socket name derived from full pane target for uniqueness
# Examples:
# mysession → /tmp/mysession_0-0.sock
# mysession:0 → /tmp/mysession_0-0.sock
# mysession:0.0 → /tmp/mysession_0-0.sock
# mysession:1.2 → /tmp/mysession_1-2.sock
# agents:0.0 → /tmp/agents_0-0.sock (pane grid friendly)
WINDOW_PANE="${TARGET#*:}" # Strip session, keep window.pane
SOCK="/tmp/${SESSION}_${WINDOW_PANE}.sock"
DIR="$(cd "$(dirname "$0")" && pwd)"
tmux list-panes -t "$TARGET" >/dev/null 2>&1 || {
echo "Target pane not found: $TARGET"
exit 1
}
[ -x "$DIR/monitor-bin" ] || { echo "monitor-bin not found — run: make build"; exit 1; }
CMD="$DIR/monitor-bin"
DEBUG_FLAG=""
if [ -n "${MONITOR_DEBUG:-}" ]; then
DEBUG_PATH="${MONITOR_DEBUG}"
if [ "$DEBUG_PATH" = "1" ]; then
# Use session_window-pane.raw for debug files
DEBUG_PATH="/tmp/${SESSION}_${WINDOW_PANE}.raw"
fi
DEBUG_FLAG="--debug $DEBUG_PATH"
echo "Debug log: $DEBUG_PATH"
fi
STATE_LOG_FLAG=""
if [ -n "${MONITOR_STATE_LOG:-}" ]; then
STATE_LOG_PATH="${MONITOR_STATE_LOG}"
if [ "$STATE_LOG_PATH" = "1" ]; then
# Use session_window-pane.state.log for state logs
STATE_LOG_PATH="/tmp/${SESSION}_${WINDOW_PANE}.state.log"
fi
STATE_LOG_FLAG="--state-log $STATE_LOG_PATH"
echo "State log: $STATE_LOG_PATH"
fi
IDLE_SECS="${MONITOR_IDLE_SECS:-10}"
tmux pipe-pane -t "$TARGET" "$CMD --agent $AGENT --socket $SOCK --idle-secs $IDLE_SECS $DEBUG_FLAG $STATE_LOG_FLAG"
echo "Monitoring $TARGET → $SOCK"
echo "Idle after ${IDLE_SECS}s without pane output"
echo "Query: echo status | nc -U $SOCK"