Repository navigation
feat(ralph): Simplified loop with Claude Code hooks - #11
Merged
Merged
Conversation
Implements a minimal Ralph loop (~200 lines) with hook-based enforcement: - simplified-loop.sh: Core iteration loop with signal handling, timeout - lib/minimal.sh: Essential utilities (logging, atomic write, story mgmt) - hooks/pre-tool.sh: PreToolUse validation (Edit requires Read, blocks git push) - hooks/post-tool.sh: PostToolUse test failure detection (Jest/pytest/Go/etc) - hooks/on-stop.sh: Stop hook for completion state and cleanup - hooks/pre-prompt.sh: UserPromptSubmit hook for session management Key improvements: - 5x smaller than original loop.sh (805 vs 4,244 lines) - All enforcement via hooks (not inline validation) - Comprehensive test failure patterns for 7+ frameworks - All hooks exit 0 (never break Claude Code) - Atomic file operations for race-condition safety Test coverage: 20 tests, all passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Validate PRD_NUMBER to prevent path traversal attacks - Escape sed special characters (& and \) in template substitution - Sanitize session log entries to prevent log injection - Add tests for git --force blocking and Edit/Write validation Security improvements identified during code review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant SimplifiedLoop
participant PrePromptHook
participant PreToolHook
participant ClaudeAgent
participant PostToolHook
participant StopHook
participant GitRepo
User->>SimplifiedLoop: Start build
SimplifiedLoop->>SimplifiedLoop: Validate PRD
SimplifiedLoop->>SimplifiedLoop: Select story
SimplifiedLoop->>GitRepo: Save checkpoint
SimplifiedLoop->>PrePromptHook: UserPromptSubmit
PrePromptHook->>PrePromptHook: Clear session log
PrePromptHook-->>SimplifiedLoop: Success
SimplifiedLoop->>ClaudeAgent: Execute agent
ClaudeAgent->>PreToolHook: Read file
PreToolHook-->>ClaudeAgent: Allow
ClaudeAgent->>PreToolHook: Edit file
PreToolHook->>PreToolHook: Check session log
PreToolHook-->>ClaudeAgent: Allow or Block
ClaudeAgent->>PreToolHook: Git push
PreToolHook-->>ClaudeAgent: Block
ClaudeAgent->>PostToolHook: After tool use
PostToolHook->>PostToolHook: Check test failures
PostToolHook->>GitRepo: Rollback if failed
PostToolHook-->>ClaudeAgent: Success
ClaudeAgent->>StopHook: Session ends
StopHook->>StopHook: Cleanup files
StopHook-->>SimplifiedLoop: Complete
SimplifiedLoop->>GitRepo: Commit changes
SimplifiedLoop->>SimplifiedLoop: Mark story done
SimplifiedLoop-->>User: Build complete
|
- Update README.md with simplified loop section and hooks configuration - Update CLAUDE.md with simplified loop usage and file structure - Update .agents/ralph/README.md with hooks reference table - Fix post-tool.sh test failure detection patterns - Add comprehensive test fixtures for multi-framework test detection - All 23 tests passing Co-Authored-By: Claude <noreply@anthropic.com>
- High-level system architecture (mermaid) - Hook execution flow sequence diagram - Data flow diagram - Story lifecycle state machine - Security considerations (10 attack vectors) - Performance benchmarks - Migration guide from legacy loop Co-Authored-By: Claude <noreply@anthropic.com>
- Fix command injection via sed regex in mark_story_complete - Enhance git command blocking to prevent bypass attempts - Complete log injection sanitization (remove ANSI escapes) - Add lock-based checkpoint protection against TOCTOU race - Fix regex injection in on-stop.sh hook - Add MAX_ITERATIONS upper bound validation Security improvements: - Story IDs now validated against strict US-NNN pattern - Git push/merge detection catches subshells, scripts, base64 - All control characters stripped from log entries - Exclusive lock prevents concurrent agent execution Tests: All 33 tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The flock command is not available on macOS by default. Added fallback support for: - flock (Linux, GNU coreutils) - shlock (macOS, some BSD systems) - PID-based fallback (universal) This ensures the TOCTOU race condition protection works across all platforms. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
Code Review & Testing Complete ✅Test ResultsAll 33 tests passing: Security Improvements AppliedFollowing comprehensive code review, these security enhancements were implemented:
Cross-Platform Support
Demo (dry-run)$ .agents/ralph/simplified-loop.sh --dry-run --prd=1
[23:47:34] Starting simplified loop (PRD-1, max 25 iterations)
[23:47:34] Acquired exclusive lock for agent execution
[23:47:34] === Iteration 1/25 ===
[23:47:34] ✓ All stories complete!🤖 Reviewed and tested with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a minimal Ralph loop (~200 lines) with hook-based enforcement, achieving a 5x reduction from the original 4,244-line loop.sh.
Key changes:
simplified-loop.sh: Core iteration loop with signal handling, timeout, atomic checkpointslib/minimal.sh: Essential utilities (logging, atomic write, story management)hooks/pre-tool.sh: PreToolUse validation (Edit requires Read, blocks git push/merge/force)hooks/post-tool.sh: PostToolUse test failure detection (Jest/pytest/Go/Mocha/RSpec/Bats)hooks/on-stop.sh: Stop hook for completion state and cleanuphooks/pre-prompt.sh: UserPromptSubmit hook for session managementDesign principles:
Test plan
Line count comparison