Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions .agents/scripts/issue-sync-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ log_verbose() {
return 0
}

# Strip lines inside markdown code-fenced blocks (``` ... ```) from stdin.
# Prevents task-like lines in format examples from being parsed as real tasks.
# Usage: strip_code_fences < file OR grep ... | strip_code_fences
strip_code_fences() {
awk '/^[[:space:]]*```/{in_fence=!in_fence; next} !in_fence{print}'
return 0

Choose a reason for hiding this comment

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

medium

This function currently masks the exit code of the awk command by always returning 0. If awk fails for any reason (e.g., resource limits), the script will continue with potentially incomplete data because set -e won't be triggered.

According to the general repository rules, functions that wrap a command should propagate its exit code. Please change this to return awk's exit code to make the function more robust.

Suggested change
return 0
return $?
References
  1. In shell scripts, functions that wrap a command should propagate its exit code to the caller. Avoid masking potential errors with a hardcoded return 0. Instead, use return $? or capture the exit code and return it (e.g., local rc=$?; return $rc).

}

# Find project root (contains TODO.md)
find_project_root() {
local dir="$PWD"
Expand Down Expand Up @@ -782,7 +790,7 @@ cmd_push() {
if [[ -n "$tid" ]] && ! echo "$line" | grep -qE 'ref:GH#[0-9]+'; then
tasks+=("$tid")
fi
done < <(grep -E '^\s*- \[ \] t[0-9]+' "$todo_file" || true)
done < <(strip_code_fences <"$todo_file" | grep -E '^\s*- \[ \] t[0-9]+' || true)
fi

if [[ ${#tasks[@]} -eq 0 ]]; then
Expand Down Expand Up @@ -923,7 +931,7 @@ cmd_enrich() {
if [[ -n "$tid" ]]; then
tasks+=("$tid")
fi
done < <(grep -E '^\s*- \[ \] t[0-9]+.*ref:GH#[0-9]+' "$todo_file" || true)
done < <(strip_code_fences <"$todo_file" | grep -E '^\s*- \[ \] t[0-9]+.*ref:GH#[0-9]+' || true)
fi

if [[ ${#tasks[@]} -eq 0 ]]; then
Expand Down Expand Up @@ -1536,7 +1544,7 @@ cmd_close() {
else
print_error "Failed to close #$issue_number ($task_id)"
fi
done < <(grep -E '^\s*- \[x\] t[0-9]+' "$todo_file" || true)
done < <(strip_code_fences <"$todo_file" | grep -E '^\s*- \[x\] t[0-9]+' || true)

print_info "Close complete: $closed closed, $skipped skipped (no evidence), $ref_fixed refs fixed"
return 0
Expand Down Expand Up @@ -1646,12 +1654,13 @@ cmd_status() {
print_info "Checking sync status for $repo_slug..."

# Count tasks in TODO.md (include both top-level and indented subtasks)
# strip_code_fences prevents format-example lines from inflating counts
local total_open
total_open=$(grep -cE '^\s*- \[ \] t[0-9]+' "$todo_file" || echo "0")
total_open=$(strip_code_fences <"$todo_file" | grep -cE '^\s*- \[ \] t[0-9]+' || echo "0")
local total_completed
total_completed=$(grep -cE '^\s*- \[x\] t[0-9]+' "$todo_file" || echo "0")
total_completed=$(strip_code_fences <"$todo_file" | grep -cE '^\s*- \[x\] t[0-9]+' || echo "0")
local with_ref
with_ref=$(grep -cE '^\s*- \[ \] t[0-9]+.*ref:GH#' "$todo_file" || echo "0")
with_ref=$(strip_code_fences <"$todo_file" | grep -cE '^\s*- \[ \] t[0-9]+.*ref:GH#' || echo "0")
local without_ref
without_ref=$((total_open - with_ref))

Expand All @@ -1674,7 +1683,7 @@ cmd_status() {
print_warning "DRIFT: $line"
fi
fi
done < <(grep -E '^\s*- \[x\] t[0-9]+.*ref:GH#' "$todo_file" || true)
done < <(strip_code_fences <"$todo_file" | grep -E '^\s*- \[x\] t[0-9]+.*ref:GH#' || true)

echo ""
echo "=== Sync Status ==="
Expand Down Expand Up @@ -1757,7 +1766,7 @@ cmd_reconcile() {
elif [[ -z "$correct_number" || "$correct_number" == "null" ]]; then
print_warning "$tid: no matching issue found on GitHub (ref:GH#$gh_ref is stale)"
fi
done < <(grep -E '^\s*- \[.\] t[0-9]+.*ref:GH#[0-9]+' "$todo_file" || true)
done < <(strip_code_fences <"$todo_file" | grep -E '^\s*- \[.\] t[0-9]+.*ref:GH#[0-9]+' || true)

# Phase 2: Find open issues for completed tasks (including those without ref:GH#)
local open_issues_json
Expand Down
Loading