agentic-loop 3.1.6 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,152 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # review.sh - Code review verification module for ralph
4
-
5
- # Run code review on changes
6
- run_code_review() {
7
- local story="$1"
8
-
9
- # Check if code review is enabled in config
10
- local review_enabled
11
- review_enabled=$(get_config '.verification.codeReviewEnabled' "true")
12
- if [[ "$review_enabled" == "false" ]]; then
13
- echo " (code review disabled in config, skipping)"
14
- return 0
15
- fi
16
-
17
- # Check if git is available
18
- if ! command -v git &>/dev/null || [[ ! -d ".git" ]]; then
19
- echo " (no git repository, skipping)"
20
- return 0
21
- fi
22
-
23
- # Get the diff of uncommitted changes (limit size to prevent memory issues)
24
- local diff
25
- local max_diff_lines=2000
26
- diff=$(git diff HEAD 2>/dev/null | head -n "$max_diff_lines")
27
-
28
- if [[ -z "$diff" ]]; then
29
- # No uncommitted changes, check staged
30
- diff=$(git diff --cached 2>/dev/null | head -n "$max_diff_lines")
31
- fi
32
-
33
- if [[ -z "$diff" ]]; then
34
- echo " (no changes to review)"
35
- return 0
36
- fi
37
-
38
- # Check if diff was truncated
39
- local full_diff_lines
40
- full_diff_lines=$(git diff HEAD 2>/dev/null | wc -l)
41
- if [[ "$full_diff_lines" -gt "$max_diff_lines" ]]; then
42
- echo " (diff truncated from $full_diff_lines to $max_diff_lines lines)"
43
- fi
44
-
45
- # Get story context for the review
46
- local story_json
47
- story_json=$(jq --arg id "$story" '.stories[] | select(.id==$id)' "$RALPH_DIR/prd.json" 2>/dev/null)
48
-
49
- # Build the code review prompt
50
- local prompt
51
- prompt=$(cat <<EOF
52
- You are a senior code reviewer. Review this diff for a story implementation.
53
-
54
- ## Story Context
55
- \`\`\`json
56
- $story_json
57
- \`\`\`
58
-
59
- ## Code Diff
60
- \`\`\`diff
61
- $diff
62
- \`\`\`
63
-
64
- ## Review Checklist
65
-
66
- Check for these issues:
67
-
68
- 1. **Security** - SQL injection, XSS, command injection, hardcoded secrets, OWASP top 10
69
- 2. **Error handling** - Missing try/catch, unhandled promise rejections, silent failures
70
- 3. **Edge cases** - Null/undefined checks, empty arrays, boundary conditions
71
- 4. **Code quality** - Unused variables, dead code, overly complex logic
72
- 5. **Performance** - N+1 queries, unnecessary re-renders, memory leaks
73
- 6. **Scalability** - Unbounded queries? Missing pagination? Missing indexes? No caching strategy?
74
- 7. **Accessibility** - Missing ARIA labels, keyboard navigation, color contrast (if frontend)
75
- 8. **Story compliance** - Does the code actually implement what the story requires?
76
- 9. **Architecture** - Files in correct directories? Reusing existing components? File size < 300 lines?
77
- 10. **No duplication** - Creating something that already exists? Reinventing utilities?
78
-
79
- ## Response Format
80
-
81
- IMPORTANT: Output ONLY raw JSON, no markdown formatting, no code blocks, no explanation.
82
-
83
- {"pass": true/false, "issues": [{"severity": "critical|warning|info", "category": "security|error-handling|edge-case|quality|performance|scalability|a11y|architecture|compliance", "file": "path/to/file", "line": 123, "message": "Description", "suggestion": "Fix"}], "summary": "Brief assessment"}
84
-
85
- Only fail (pass: false) for critical or multiple warning-level issues.
86
- EOF
87
- )
88
-
89
- echo " Reviewing changes..."
90
-
91
- local result
92
- # Timeout for code review (defined in utils.sh)
93
- result=$(echo "$prompt" | run_with_timeout "$CODE_REVIEW_TIMEOUT_SECONDS" claude -p --dangerously-skip-permissions 2>/dev/null) || {
94
- print_warning " Code review skipped (Claude unavailable or timed out)"
95
- return 0
96
- }
97
-
98
- # Save review result
99
- mkdir -p "$RALPH_DIR/reviews"
100
- echo "$result" > "$RALPH_DIR/reviews/${story}-review.json"
101
-
102
- # Extract JSON from markdown code blocks if present
103
- local json_result
104
- if echo "$result" | grep -q '```json'; then
105
- json_result=$(echo "$result" | sed -n '/```json/,/```/p' | sed '1d;$d')
106
- elif echo "$result" | grep -q '```'; then
107
- json_result=$(echo "$result" | sed -n '/```/,/```/p' | sed '1d;$d')
108
- else
109
- json_result="$result"
110
- fi
111
-
112
- # Check if result is valid JSON
113
- if ! echo "$json_result" | jq -e . >/dev/null 2>&1; then
114
- print_warning " Code review returned invalid response, skipping"
115
- return 0
116
- fi
117
-
118
- local passed
119
- passed=$(echo "$json_result" | jq -r '.pass // true' 2>/dev/null)
120
-
121
- # Handle empty/null result
122
- if [[ -z "$passed" || "$passed" == "null" ]]; then
123
- print_warning " Code review inconclusive, continuing"
124
- return 0
125
- fi
126
-
127
- if [[ "$passed" == "true" ]]; then
128
- print_success "passed"
129
-
130
- # Show any warnings/info even on pass
131
- local warnings
132
- warnings=$(echo "$json_result" | jq -r '.issues[] | select(.severity != "critical") | " [\(.severity)] \(.message)"' 2>/dev/null)
133
- if [[ -n "$warnings" ]]; then
134
- echo " Notes:"
135
- echo "$warnings"
136
- fi
137
- return 0
138
- else
139
- print_error "failed"
140
- echo ""
141
-
142
- # Show all issues
143
- echo " Issues found:"
144
- echo "$json_result" | jq -r '.issues[] | " [\(.severity)] \(.category): \(.message)"' 2>/dev/null
145
- echo ""
146
- echo " Summary: $(echo "$json_result" | jq -r '.summary // "Review failed"' 2>/dev/null)"
147
-
148
- # Save for failure context
149
- echo "$json_result" > "$RALPH_DIR/last_review_failure.json"
150
- return 1
151
- fi
152
- }