Skip to content
46 changes: 46 additions & 0 deletions scripts/eternity-loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,36 @@ $RALPH_SKILL_GUIDELINES" 2>&1 | tee /dev/stderr || true
return 0
}

# Post progress.txt as a PR comment
# Usage: post_progress_comment <work_dir> <pr_number>
post_progress_comment() {
local work_dir="$1"
local pr_number="$2"
local progress_file="$work_dir/scripts/ralph/progress.txt"

if [ ! -f "$progress_file" ]; then
log_err "[progress] No progress.txt found at $progress_file. Skipping comment."
return 0
fi

local progress_content
progress_content=$(cat "$progress_file")
if [ -z "$progress_content" ]; then
log_err "[progress] progress.txt is empty. Skipping comment."
return 0
fi

log_err "[progress] Posting progress.txt as comment on PR #$pr_number..."
local comment_body
comment_body=$(printf '馃 **eternity-loop bot:** Progress log\n\n<details>\n<summary>Click to expand progress log</summary>\n\n```\n%s\n```\n\n</details>' "$progress_content")

cd "$work_dir"
gh pr comment "$pr_number" --body "$comment_body" 2>/dev/null || {
log_err "[progress] WARNING: Failed to post progress comment on PR #$pr_number"
}
log_err "[progress] Progress comment posted on PR #$pr_number."
Comment on lines +1332 to +1335

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gh pr comment ... || { ... } logs a warning on failure, but the function still unconditionally logs "Progress comment posted" afterwards. This will report success even when the comment wasn't created. Consider logging success only when gh pr comment exits 0 (and keep the warning log for failures).

Suggested change
gh pr comment "$pr_number" --body "$comment_body" 2>/dev/null || {
log_err "[progress] WARNING: Failed to post progress comment on PR #$pr_number"
}
log_err "[progress] Progress comment posted on PR #$pr_number."
if gh pr comment "$pr_number" --body "$comment_body" 2>/dev/null; then
log_err "[progress] Progress comment posted on PR #$pr_number."
else
log_err "[progress] WARNING: Failed to post progress comment on PR #$pr_number"
fi

Copilot uses AI. Check for mistakes.
}

# --- Main Loop ---

# Suppress notifications in child processes
Expand Down Expand Up @@ -1418,12 +1448,18 @@ $review_comments
## Recent commits addressing this feedback
$(cd "$WORK_DIR" && git log --oneline -20)" 2>&1 | tee /dev/stderr || true
log "[loop] Finished replying to PR comments."

# Post progress log as PR comment
post_progress_comment "$WORK_DIR" "$PR_NUMBER"
elif [ "$TASK_TYPE" = "ci-fix" ]; then
# For CI fix tasks: push updates to the existing PR (no comment replies needed)
cd "$WORK_DIR"
log "[loop] Pushing CI fixes to origin..."
git push origin "$(git branch --show-current)" 2>/dev/null || true
log "[loop] Pushed CI fixes to PR #$PR_NUMBER."

# Post progress log as PR comment
post_progress_comment "$WORK_DIR" "$PR_NUMBER"
else
# For new tasks: create PR based on exit status
if [ "$RALPH_EXIT" -eq 0 ]; then
Expand All @@ -1433,6 +1469,16 @@ $(cd "$WORK_DIR" && git log --oneline -20)" 2>&1 | tee /dev/stderr || true
log "[loop] Ralph exited with status $RALPH_EXIT. Creating draft PR..."
finalize_task "$WORK_DIR" "$ISSUE_JSON" "true"
fi

# Post progress log as PR comment (look up PR number by branch)
cd "$WORK_DIR"
local new_pr_number
new_pr_number=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number' 2>/dev/null) || true

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local new_pr_number is used in the main script body (not inside a function). In bash this prints "local: can only be used in a function" and returns non-zero; with set -e enabled near the top of the script, this will terminate the loop. Use a normal variable assignment (or move this logic into a function) instead of local here.

Copilot uses AI. Check for mistakes.

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When gh pr list --json number --jq '.[0].number' returns an empty list, --jq will output null (a non-empty string). The -n check will pass and post_progress_comment will be invoked with pr_number="null", which will fail. Consider changing the jq to '.[0].number // empty' (or explicitly checking for null) before posting the comment.

Suggested change
new_pr_number=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number' 2>/dev/null) || true
new_pr_number=$(gh pr list --head "$BRANCH_NAME" --json number --jq '.[0].number // empty' 2>/dev/null) || true

Copilot uses AI. Check for mistakes.
if [ -n "$new_pr_number" ]; then
post_progress_comment "$WORK_DIR" "$new_pr_number"
else
log "[loop] Could not find PR for branch $BRANCH_NAME. Skipping progress comment."
fi
fi

LOOP_END=$(date +%s)
Expand Down