diff --git a/skills/kugetsu/scripts/kugetsu-session.sh b/skills/kugetsu/scripts/kugetsu-session.sh index dcbb1f3..2ee1e89 100755 --- a/skills/kugetsu/scripts/kugetsu-session.sh +++ b/skills/kugetsu/scripts/kugetsu-session.sh @@ -81,9 +81,20 @@ EOF echo "Press Ctrl+C to cancel or wait for session to be created" sleep 2 + local before_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true) + opencode - local session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' | tail -1) + local after_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true) + local session_ids="" + while IFS= read -r line; do + local sid=$(echo "$line" | awk '{print $1}') + if [ -n "$sid" ] && ! echo "$before_sessions" | grep -q "^${sid}$"; then + session_ids="$sid" + break + fi + done <<< "$after_sessions" + if [ -z "$session_ids" ]; then echo "Error: Could not find newly created session" >&2 exit 1 @@ -95,9 +106,20 @@ EOF echo "Base session created: $session_ids" echo "Starting PM agent..." + before_sessions="$after_sessions" + opencode - local pm_session_ids=$(opencode session list 2>/dev/null | grep -E '^ses_' | grep -v "$session_ids" | tail -1) + after_sessions=$(opencode session list 2>/dev/null | grep -E '^ses_' | awk '{print $1}' || true) + local pm_session_ids="" + while IFS= read -r line; do + local sid=$(echo "$line" | awk '{print $1}') + if [ -n "$sid" ] && ! echo "$before_sessions" | grep -q "^${sid}$"; then + pm_session_ids="$sid" + break + fi + done <<< "$after_sessions" + if [ -z "$pm_session_ids" ]; then echo "Warning: Could not find separate PM agent session" >&2 pm_session_ids="$session_ids"