Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions create_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,15 @@ should_exit_gracefully() {
# Fix #144: Only match valid markdown checkboxes, not date entries like [2026-01-29]
# Valid patterns: "- [ ]" (uncompleted) and "- [x]" or "- [X]" (completed)
if [[ -f "$RALPH_DIR/fix_plan.md" ]]; then
local uncompleted_items=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null || echo "0")
local completed_items=$(grep -cE "^[[:space:]]*- \[[xX]\]" "$RALPH_DIR/fix_plan.md" 2>/dev/null || echo "0")
# `grep -c ... || echo "0"` duplicates output on no-match (grep -c prints
# "0" AND exits 1, triggering the fallback). Pipe to head -1 and validate
# as a number to avoid breaking the arithmetic below.
local uncompleted_items
uncompleted_items=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null | head -1)
[[ "$uncompleted_items" =~ ^[0-9]+$ ]] || uncompleted_items=0
local completed_items
completed_items=$(grep -cE "^[[:space:]]*- \[[xX]\]" "$RALPH_DIR/fix_plan.md" 2>/dev/null | head -1)
[[ "$completed_items" =~ ^[0-9]+$ ]] || completed_items=0
local total_items=$((uncompleted_items + completed_items))

if [[ $total_items -gt 0 ]] && [[ $completed_items -eq $total_items ]]; then
Expand Down
8 changes: 5 additions & 3 deletions lib/response_analyzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ detect_questions() {
# Count lines matching question patterns (case-insensitive)
for pattern in "${QUESTION_PATTERNS[@]}"; do
local matches
matches=$(echo "$content" | grep -ciw "$pattern" 2>/dev/null || echo "0")
matches=$(echo "$matches" | tr -d '[:space:]')
matches=${matches:-0}
# `grep -c || echo "0"` duplicates output on no-match (grep -c prints
# "0" AND exits 1, triggering the fallback). Pipe to head -1 and
# validate as an integer instead.
matches=$(echo "$content" | grep -ciw "$pattern" 2>/dev/null | head -1)
[[ "$matches" =~ ^[0-9]+$ ]] || matches=0
question_count=$((question_count + matches))
done

Expand Down
11 changes: 8 additions & 3 deletions ralph_enable_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,27 @@ main() {
beads)
if beads_tasks=$(fetch_beads_tasks 2>/dev/null); then
imported_tasks="$beads_tasks"
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' || echo "0")
# `grep -c || echo "0"` duplicates output on no-match. Use head -1
# + regex validation so TASKS_IMPORTED is always a single integer.
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' | head -1)
[[ "$TASKS_IMPORTED" =~ ^[0-9]+$ ]] || TASKS_IMPORTED=0
output_message "Imported $TASKS_IMPORTED tasks from beads"
fi
;;
github)
if github_tasks=$(fetch_github_tasks "$GITHUB_LABEL" 2>/dev/null); then
imported_tasks="$github_tasks"
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' || echo "0")
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' | head -1)
[[ "$TASKS_IMPORTED" =~ ^[0-9]+$ ]] || TASKS_IMPORTED=0
output_message "Imported $TASKS_IMPORTED tasks from GitHub"
fi
;;
prd)
if [[ -n "$PRD_FILE" && -f "$PRD_FILE" ]]; then
if prd_tasks=$(extract_prd_tasks "$PRD_FILE" 2>/dev/null); then
imported_tasks="$prd_tasks"
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' || echo "0")
TASKS_IMPORTED=$(echo "$imported_tasks" | grep -c '^\- \[' | head -1)
[[ "$TASKS_IMPORTED" =~ ^[0-9]+$ ]] || TASKS_IMPORTED=0
output_message "Extracted $TASKS_IMPORTED tasks from PRD"
fi
else
Expand Down
18 changes: 15 additions & 3 deletions ralph_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,16 @@ should_exit_gracefully() {
# Fix #144: Only match valid markdown checkboxes, not date entries like [2026-01-29]
# Valid patterns: "- [ ]" (uncompleted) and "- [x]" or "- [X]" (completed)
if [[ -f "$RALPH_DIR/fix_plan.md" ]]; then
local uncompleted_items=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null || echo "0")
local completed_items=$(grep -cE "^[[:space:]]*- \[[xX]\]" "$RALPH_DIR/fix_plan.md" 2>/dev/null || echo "0")
# Note: `grep -c ... || echo "0"` duplicates output. `grep -c` prints "0"
# AND exits 1 when there are no matches, so the `||` fallback appends
# ANOTHER "0", producing a two-line value that breaks arithmetic. Pipe
# through `head -1` and validate with a regex instead.
local uncompleted_items
uncompleted_items=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null | head -1)
[[ "$uncompleted_items" =~ ^[0-9]+$ ]] || uncompleted_items=0
local completed_items
completed_items=$(grep -cE "^[[:space:]]*- \[[xX]\]" "$RALPH_DIR/fix_plan.md" 2>/dev/null | head -1)
[[ "$completed_items" =~ ^[0-9]+$ ]] || completed_items=0
local total_items=$((uncompleted_items + completed_items))

if [[ $total_items -gt 0 ]] && [[ $completed_items -eq $total_items ]]; then
Expand Down Expand Up @@ -877,7 +885,11 @@ build_loop_context() {
# Extract incomplete tasks from fix_plan.md
# Bug #3 Fix: Support indented markdown checkboxes with [[:space:]]* pattern
if [[ -f "$RALPH_DIR/fix_plan.md" ]]; then
local incomplete_tasks=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null || echo "0")
# See comment in should_exit_gracefully(): `grep -c || echo "0"` produces
# a two-line value on no-match. Sanitize via `head -1` + regex check.
local incomplete_tasks
incomplete_tasks=$(grep -cE "^[[:space:]]*- \[ \]" "$RALPH_DIR/fix_plan.md" 2>/dev/null | head -1)
[[ "$incomplete_tasks" =~ ^[0-9]+$ ]] || incomplete_tasks=0
context+="Remaining tasks: ${incomplete_tasks}. "
fi

Expand Down
Loading