Skip to content

fix(ralph-loop): fix hooks matcher and stdin handling - #388

Merged
baleen37 merged 1 commit into
mainfrom
fix/ralph-loop
Feb 4, 2026
Merged

fix(ralph-loop): fix hooks matcher and stdin handling#388
baleen37 merged 1 commit into
mainfrom
fix/ralph-loop

Conversation

@baleen37

@baleen37 baleen37 commented Feb 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixed critical bugs that prevented /ralph-loop command from working
  • Changed hooks.json matcher from invalid "ralph-loop-active" to "*"
  • Fixed session-start-hook.sh to read SESSION_ID from stdin
  • Fixed session-start-hook.sh to write RALPH_SESSION_ID to ENV_FILE
  • Added 12 new tests for bug validation and E2E integration

Bug Fixes

1. hooks.json matcher (Critical)

  • Problem: "ralph-loop-active" is not a valid matcher pattern
  • Impact: SessionStart and Stop hooks never executed
  • Fix: Changed to "*" wildcard, hooks check state file existence internally

2. session-start-hook.sh stdin reading

  • Problem: jq -r '.session_id' reads nothing without stdin redirect
  • Impact: SESSION_ID was empty, causing early exit at validation
  • Fix: Added </dev/stdin to read JSON input

3. session-start-hook.sh ENV_FILE writing

  • Problem: Only wrote to existing files, but file was just created
  • Impact: RALPH_SESSION_ID never written to session-env.sh
  • Fix: Added elif branch to handle newly-created files

Test Coverage

  • Before: 42 tests
  • After: 54 tests (+12)
  • All tests passing

Test Plan

  • All existing tests pass
  • New bug fix tests validate the fixes
  • E2E integration tests verify core scenarios

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Changes

    • Broadened hook triggering scope to apply to all sessions instead of limited active states.
    • Improved session ID extraction and environment variable file handling.
  • Tests

    • Added comprehensive test coverage for hook matchers, session initialization, state management, and edge cases.
  • Documentation

    • Removed internal documentation files.

Critical bugs that prevented /ralph-loop from working:

1. hooks.json: Change matcher from "ralph-loop-active" to "*"
   - The invalid matcher prevented hooks from ever executing
   - Wildcard matcher allows hooks to run, with state file check inside

2. session-start-hook.sh: Read SESSION_ID from stdin
   - Add </dev/stdin to jq command to read JSON input
   - Without this, SESSION_ID was empty causing early exit

3. session-start-hook.sh: Fix RALPH_SESSION_ID file writing
   - Handle both existing files and newly-created files
   - Previous logic only wrote to existing files, missing the just-created case

Tests: Added 12 new tests (54 total, all passing)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@baleen37
baleen37 enabled auto-merge February 4, 2026 23:27
@coderabbitai

coderabbitai Bot commented Feb 4, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This change removes ralph-loop plugin documentation files, updates hook configuration matchers from "ralph-loop-active" to wildcard matching, enhances session-start-hook.sh to persist session IDs to an environment file, and adds comprehensive test coverage for these modifications and related behavior.

Changes

Cohort / File(s) Summary
Documentation Removal
plugins/ralph-loop/CLAUDE.md, plugins/ralph-loop/hooks/CLAUDE.md
Deleted markdown documentation files describing ralph-loop plugin functionality and hooks behavior (115 lines removed).
Hook Configuration
plugins/ralph-loop/hooks/hooks.json
Updated SessionStart and Stop hook matchers from "ralph-loop-active" to "*" to trigger on all sessions instead of a specific active state.
Session Management
plugins/ralph-loop/hooks/session-start-hook.sh
Modified session ID extraction to read from stdin via jq, added logic to write RALPH_SESSION_ID to ENV_FILE with handling for both existing and new files.
Test Suite Expansion
plugins/ralph-loop/tests/ralph-loop-specific.bats
Added 125 lines of new tests covering hooks.json wildcard matchers, session-start-hook.sh behavior, ENV_FILE creation/writing, state management, completion promise handling, and edge cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 The rabbit hops through session states,
With wildcard hooks that catch all gates,
ENV files now persist the way,
Tests ensure the loops will play! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/ralph-loop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant