Skip to content

Commit e8d7e81

Browse files
committed
⚙️ organize ralph script and add jq check
1 parent e4cc459 commit e8d7e81

3 files changed

Lines changed: 133 additions & 9 deletions

File tree

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ docs: ## Run docs with bun
122122
@cd docs && bun run dev
123123
@echo "$(GREEN)✅ Docs run completed.$(RESET)"
124124

125+
ralph: check_jq ## Run Ralph agent loop
126+
@echo "$(GREEN)🤖Starting Ralph Agent...$(RESET)"
127+
@chmod +x scripts/ralph.sh
128+
@./scripts/ralph.sh $(ARGS)
129+
@echo "$(GREEN)✅ Ralph Agent finished.$(RESET)"
130+
125131

126132
########################################################
127133
# Run Tests

scripts/ralph.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@ if [[ "$TOOL" != "opencode" && "$TOOL" != "amp" && "$TOOL" != "claude" ]]; then
3333
echo "Error: Invalid tool '$TOOL'. Must be 'opencode', 'amp' or 'claude'."
3434
exit 1
3535
fi
36+
37+
# Check for jq dependency
38+
if ! command -v jq >/dev/null 2>&1; then
39+
echo "Error: 'jq' is not installed but required by this script."
40+
echo "Please install it (e.g., 'brew install jq' or 'sudo apt-get install jq')."
41+
exit 1
42+
fi
43+
3644
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37-
PRD_FILE="$SCRIPT_DIR/prd.json"
38-
PROGRESS_FILE="$SCRIPT_DIR/progress.txt"
39-
ARCHIVE_DIR="$SCRIPT_DIR/archive"
40-
LAST_BRANCH_FILE="$SCRIPT_DIR/.last-branch"
45+
RALPH_DIR="$SCRIPT_DIR/ralph"
46+
PRD_FILE="$RALPH_DIR/prd.json"
47+
PROGRESS_FILE="$RALPH_DIR/progress.txt"
48+
ARCHIVE_DIR="$RALPH_DIR/archive"
49+
LAST_BRANCH_FILE="$RALPH_DIR/.last-branch"
4150

4251
# Archive previous run if branch changed
4352
if [ -f "$PRD_FILE" ] && [ -f "$LAST_BRANCH_FILE" ]; then
@@ -90,17 +99,18 @@ for i in $(seq 1 $MAX_ITERATIONS); do
9099
# Run the selected tool with the ralph prompt
91100
if [[ "$TOOL" == "opencode" ]]; then
92101
# opencode run: use prompt from prompt.md
93-
if [ -f "$SCRIPT_DIR/prompt.md" ]; then
94-
OUTPUT=$(opencode run "$(cat "$SCRIPT_DIR/prompt.md")" 2>&1 | tee /dev/stderr) || true
102+
if [ -f "$RALPH_DIR/prompt.md" ]; then
103+
OUTPUT=$(opencode run "$(cat "$RALPH_DIR/prompt.md")" 2>&1 | tee /dev/stderr) || true
95104
else
96-
echo "Error: $SCRIPT_DIR/prompt.md not found. Ralph needs a prompt to work."
105+
echo "Error: $RALPH_DIR/prompt.md not found. Create this file or use a different tool."
106+
echo "Example: ./ralph.sh --tool claude"
97107
exit 1
98108
fi
99109
elif [[ "$TOOL" == "amp" ]]; then
100-
OUTPUT=$(cat "$SCRIPT_DIR/prompt.md" | amp --dangerously-allow-all 2>&1 | tee /dev/stderr) || true
110+
OUTPUT=$(cat "$RALPH_DIR/prompt.md" | amp --dangerously-allow-all 2>&1 | tee /dev/stderr) || true
101111
else
102112
# Claude Code: use --dangerously-skip-permissions for autonomous operation, --print for output
103-
OUTPUT=$(claude --dangerously-skip-permissions --print < "$SCRIPT_DIR/CLAUDE.md" 2>&1 | tee /dev/stderr) || true
113+
OUTPUT=$(claude --dangerously-skip-permissions --print < "$SCRIPT_DIR/../CLAUDE.md" 2>&1 | tee /dev/stderr) || true
104114
fi
105115

106116
# Check for completion signal

scripts/ralph/prompt.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Ralph Agent Instructions
2+
3+
You are an autonomous coding agent working on a software project.
4+
5+
## Your Task
6+
7+
1. Read the PRD at `prd.json` (in the same directory as this file)
8+
2. Read the progress log at `progress.txt` (check Codebase Patterns section first)
9+
3. Check you're on the correct branch from PRD `branchName`. If not, check it out or create from main.
10+
4. Pick the **highest priority** user story where `passes: false`
11+
5. Implement that single user story
12+
6. Run quality checks (e.g., typecheck, lint, test - use whatever your project requires)
13+
7. Update AGENTS.md files if you discover reusable patterns (see below)
14+
8. If checks pass, commit ALL changes with message: `feat: [Story ID] - [Story Title]`
15+
9. Update the PRD to set `passes: true` for the completed story
16+
10. Append your progress to `progress.txt`
17+
18+
## Progress Report Format
19+
20+
APPEND to progress.txt (never replace, always append):
21+
```
22+
## [Date/Time] - [Story ID]
23+
Thread: https://ampcode.com/threads/$AMP_CURRENT_THREAD_ID
24+
- What was implemented
25+
- Files changed
26+
- **Learnings for future iterations:**
27+
- Patterns discovered (e.g., "this codebase uses X for Y")
28+
- Gotchas encountered (e.g., "don't forget to update Z when changing W")
29+
- Useful context (e.g., "the evaluation panel is in component X")
30+
---
31+
```
32+
33+
Include the thread URL so future iterations can use the `read_thread` tool to reference previous work if needed.
34+
35+
The learnings section is critical - it helps future iterations avoid repeating mistakes and understand the codebase better.
36+
37+
## Consolidate Patterns
38+
39+
If you discover a **reusable pattern** that future iterations should know, add it to the `## Codebase Patterns` section at the TOP of progress.txt (create it if it doesn't exist). This section should consolidate the most important learnings:
40+
41+
```
42+
## Codebase Patterns
43+
- Example: Use `sql<number>` template for aggregations
44+
- Example: Always use `IF NOT EXISTS` for migrations
45+
- Example: Export types from actions.ts for UI components
46+
```
47+
48+
Only add patterns that are **general and reusable**, not story-specific details.
49+
50+
## Update AGENTS.md Files
51+
52+
Before committing, check if any edited files have learnings worth preserving in nearby AGENTS.md files:
53+
54+
1. **Identify directories with edited files** - Look at which directories you modified
55+
2. **Check for existing AGENTS.md** - Look for AGENTS.md in those directories or parent directories
56+
3. **Add valuable learnings** - If you discovered something future developers/agents should know:
57+
- API patterns or conventions specific to that module
58+
- Gotchas or non-obvious requirements
59+
- Dependencies between files
60+
- Testing approaches for that area
61+
- Configuration or environment requirements
62+
63+
**Examples of good AGENTS.md additions:**
64+
- "When modifying X, also update Y to keep them in sync"
65+
- "This module uses pattern Z for all API calls"
66+
- "Tests require the dev server running on PORT 3000"
67+
- "Field names must match the template exactly"
68+
69+
**Do NOT add:**
70+
- Story-specific implementation details
71+
- Temporary debugging notes
72+
- Information already in progress.txt
73+
74+
Only update AGENTS.md if you have **genuinely reusable knowledge** that would help future work in that directory.
75+
76+
## Quality Requirements
77+
78+
- ALL commits must pass your project's quality checks (typecheck, lint, test)
79+
- Do NOT commit broken code
80+
- Keep changes focused and minimal
81+
- Follow existing code patterns
82+
83+
## Browser Testing (Required for Frontend Stories)
84+
85+
For any story that changes UI, you MUST verify it works in the browser:
86+
87+
1. Load the `dev-browser` skill
88+
2. Navigate to the relevant page
89+
3. Verify the UI changes work as expected
90+
4. Take a screenshot if helpful for the progress log
91+
92+
A frontend story is NOT complete until browser verification passes.
93+
94+
## Stop Condition
95+
96+
After completing a user story, check if ALL stories have `passes: true`.
97+
98+
If ALL stories are complete and passing, reply with:
99+
<promise>COMPLETE</promise>
100+
101+
If there are still stories with `passes: false`, end your response normally (another iteration will pick up the next story).
102+
103+
## Important
104+
105+
- Work on ONE story per iteration
106+
- Commit frequently
107+
- Keep CI green
108+
- Read the Codebase Patterns section in progress.txt before starting

0 commit comments

Comments
 (0)