flake-update-20260201
 1#!/usr/bin/env bash
 2# Review a GitHub PR/issue with Claude on a remote machine via shpool
 3# Usage: gh-news-review [-d|--detach] [-y|--yolo] <url>
 4#   -d, --detach  Start session in background and return immediately
 5#   -y, --yolo    Skip permission prompts (auto-accept all tool calls)
 6
 7set -euo pipefail
 8
 9DETACH=false
10YOLO=false
11
12while [[ $# -gt 0 ]]; do
13    case "$1" in
14        -d|--detach)
15            DETACH=true
16            shift
17            ;;
18        -y|--yolo)
19            YOLO=true
20            shift
21            ;;
22        -*)
23            echo "Unknown option: $1" >&2
24            echo "Usage: gh-news-review [-d|--detach] [-y|--yolo] <url>" >&2
25            exit 1
26            ;;
27        *)
28            break
29            ;;
30    esac
31done
32
33URL="${1:-}"
34if [[ -z "$URL" ]]; then
35    echo "Usage: gh-news-review [-d|--detach] [-y|--yolo] <url>" >&2
36    exit 1
37fi
38
39# Extract session name from URL (e.g., pull-123 or issues-456)
40SESSION_NAME="review-$(echo "$URL" | grep -oE '(pull|issues)/[0-9]+' | tr '/' '-')"
41
42if [[ -z "$SESSION_NAME" || "$SESSION_NAME" == "review-" ]]; then
43    echo "Error: Could not extract PR/issue number from URL: $URL" >&2
44    exit 1
45fi
46
47# Detect if this is a nixpkgs PR for more specific instructions
48IS_NIXPKGS=false
49if [[ "$URL" == *"NixOS/nixpkgs"* ]]; then
50    IS_NIXPKGS=true
51fi
52
53# Build the prompt based on the type of review
54if [[ "$IS_NIXPKGS" == "true" ]]; then
55    PROMPT="Review $URL using the Nixpkgs skill.
56
57For nixpkgs PRs:
581. Load and follow the Nixpkgs skill workflow
592. Use nixpkgs-review to build and test the changes when appropriate
603. When approving, use a concise message (e.g., 'LGTM, tested with nixpkgs-review')
614. If I'm a maintainer of the touched packages, use the auto-merge-pr script to build, approve, and trigger merge-bot"
62else
63    PROMPT="Review $URL, and load the proper skill as needed (e.g. nixpkgs skills and workflows if it is a pr from NixOS/nixpkgs)"
64fi
65
66# Build cr command with optional yolo mode
67CR_CMD="cr"
68if [[ "$YOLO" == "true" ]]; then
69    CR_CMD="cr --dangerously-skip-permissions"
70fi
71
72# Encode prompt in base64 to avoid all quoting issues
73PROMPT_B64=$(printf '%s' "$PROMPT" | base64 -w0)
74
75if [[ "$DETACH" == "true" ]]; then
76    # Write a temp script on remote and execute it in shpool
77    # Using heredoc avoids all nested quoting issues
78    # shellcheck disable=SC2029,SC2087  # Intentional client-side expansion
79    ssh aomi.sbr.pm "cat > /tmp/review-cmd-$SESSION_NAME.sh && chmod +x /tmp/review-cmd-$SESSION_NAME.sh && nohup shpool attach -f -c '/run/current-system/sw/bin/bash -l /tmp/review-cmd-$SESSION_NAME.sh' $SESSION_NAME > /dev/null 2>&1 &" <<EOF
80cd ~/src/nixpkgs
81$CR_CMD "\$(echo '$PROMPT_B64' | base64 -d)"
82EOF
83    echo "Started review session: $SESSION_NAME"
84    echo "Attach with: ssh -t aomi.sbr.pm 'shpool attach $SESSION_NAME'"
85else
86    # Interactive: write temp script and run
87    # shellcheck disable=SC2029,SC2087  # Intentional client-side expansion
88    ssh aomi.sbr.pm "cat > /tmp/review-cmd-$SESSION_NAME.sh && chmod +x /tmp/review-cmd-$SESSION_NAME.sh" <<EOF
89cd ~/src/nixpkgs
90$CR_CMD "\$(echo '$PROMPT_B64' | base64 -d)"
91EOF
92    exec ssh -t aomi.sbr.pm "shpool attach -f -c '/run/current-system/sw/bin/bash -l /tmp/review-cmd-$SESSION_NAME.sh' $SESSION_NAME"
93fi