agentic-loop 3.1.5 → 3.2.0

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,324 +0,0 @@
1
- #!/usr/bin/env bash
2
- # shellcheck shell=bash
3
- # browser.sh - Browser validation module for ralph
4
-
5
- # Browser validation for frontend stories using Playwright
6
- run_browser_validation() {
7
- local story="$1"
8
-
9
- # Check if browser validation is enabled in config
10
- local browser_enabled
11
- browser_enabled=$(get_config '.verification.browserEnabled' "true")
12
- if [[ "$browser_enabled" == "false" ]]; then
13
- echo " (browser validation disabled in config, skipping)"
14
- return 0
15
- fi
16
-
17
- # Get base URL from config (required for relative URLs)
18
- local base_url
19
- base_url=$(get_config '.testUrlBase' "")
20
-
21
- # Check if Docker mode - Playwright needs special handling
22
- local docker_enabled
23
- docker_enabled=$(get_config '.docker.enabled' "false")
24
- if [[ "$docker_enabled" == "true" ]]; then
25
- echo " (Docker mode: using curl check - set verification.browserEnabled=false to hide this)"
26
- # In Docker, fall back to curl unless they've set up remote browser
27
- local url
28
- url=$(jq -r --arg id "$story" '.stories[] | select(.id==$id) | .testUrl // empty' "$RALPH_DIR/prd.json" 2>/dev/null)
29
- if [[ -n "$url" ]]; then
30
- # Check for unsubstituted template variables
31
- if [[ "$url" =~ \{[a-zA-Z_][a-zA-Z0-9_]*\} ]]; then
32
- print_warning " testUrl has unsubstituted variable: $url"
33
- return 0
34
- fi
35
- # Handle relative URLs
36
- if [[ "$url" =~ ^/ ]]; then
37
- if [[ -z "$base_url" ]]; then
38
- print_error "testUrlBase not set in config.json (needed for relative URL: $url)"
39
- return 1
40
- fi
41
- url="${base_url}${url}"
42
- fi
43
- return run_curl_check "$url"
44
- fi
45
- return 0
46
- fi
47
-
48
- local url
49
- url=$(jq -r --arg id "$story" '.stories[] | select(.id==$id) | .testUrl // empty' "$RALPH_DIR/prd.json" 2>/dev/null)
50
-
51
- if [[ -z "$url" ]]; then
52
- echo " skipped (no testUrl - infrastructure or backend story)"
53
- return 0
54
- fi
55
-
56
- # Check for unsubstituted template variables like {collectionId}
57
- if [[ "$url" =~ \{[a-zA-Z_][a-zA-Z0-9_]*\} ]]; then
58
- print_warning " testUrl has unsubstituted variable: $url"
59
- echo " Add concrete ID to testUrl in PRD, or set in .ralph/config.json testUrlVars"
60
- echo " skipped"
61
- return 0
62
- fi
63
-
64
- # Handle relative URLs by prepending base URL from config
65
- if [[ "$url" =~ ^/ ]]; then
66
- if [[ -z "$base_url" ]]; then
67
- print_error "testUrlBase not set in config.json (needed for relative URL: $url)"
68
- return 1
69
- fi
70
- url="${base_url}${url}"
71
- fi
72
-
73
- if ! validate_url "$url"; then
74
- print_error "Invalid URL: $url"
75
- return 1
76
- fi
77
-
78
- echo " URL: $url"
79
-
80
- # Check if npx is available
81
- if ! command -v npx &>/dev/null; then
82
- print_warning " npx not found, skipping browser validation"
83
- return 0
84
- fi
85
-
86
- # Check if Playwright package is installed
87
- local playwright_installed=false
88
- if npm list playwright &>/dev/null || npm list -g playwright &>/dev/null; then
89
- playwright_installed=true
90
- fi
91
-
92
- # Check if browser binaries are installed (look for chromium in cache)
93
- # macOS uses ~/Library/Caches, Linux uses ~/.cache
94
- local browser_installed=false
95
- local playwright_cache=""
96
- if [[ -d "$HOME/Library/Caches/ms-playwright" ]]; then
97
- playwright_cache="$HOME/Library/Caches/ms-playwright"
98
- elif [[ -d "$HOME/.cache/ms-playwright" ]]; then
99
- playwright_cache="$HOME/.cache/ms-playwright"
100
- fi
101
- if [[ -n "$playwright_cache" ]] && ls "$playwright_cache"/chromium-* &>/dev/null; then
102
- browser_installed=true
103
- fi
104
-
105
- # If either is missing, auto-install (Ralph runs autonomously)
106
- if [[ "$playwright_installed" == "false" ]] || [[ "$browser_installed" == "false" ]]; then
107
- echo ""
108
- print_info " Installing Playwright for browser verification (~150MB)..."
109
- if npm install playwright &>/dev/null && npx playwright install chromium &>/dev/null; then
110
- print_success " Playwright installed!"
111
- else
112
- print_warning " Installation failed, falling back to curl check"
113
- return run_curl_check "$url"
114
- fi
115
- fi
116
-
117
- # Get selectors to check from story (if defined)
118
- local selectors
119
- selectors=$(jq -r --arg id "$story" '.stories[] | select(.id==$id) | .selectors // [] | @json' "$RALPH_DIR/prd.json" 2>/dev/null)
120
- if [[ "$selectors" == "null" || -z "$selectors" ]]; then
121
- selectors="[]"
122
- fi
123
-
124
- # Screenshot path
125
- mkdir -p "$RALPH_DIR/screenshots"
126
- local screenshot_path="$RALPH_DIR/screenshots/${story}.png"
127
-
128
- # Check mobile too?
129
- local check_mobile
130
- check_mobile=$(jq -r --arg id "$story" '.stories[] | select(.id==$id) | .mobile // empty' "$RALPH_DIR/prd.json" 2>/dev/null)
131
-
132
- # Build command - use the browser-verify skill
133
- local verify_script="$RALPH_LIB/browser-verify/verify.ts"
134
-
135
- if [[ ! -f "$verify_script" ]]; then
136
- print_warning " browser-verify.ts not found, falling back to curl check"
137
- return run_curl_check "$url"
138
- fi
139
-
140
- # Check for auth config (env vars take precedence over config file)
141
- local auth_login=""
142
- local login_url
143
- local test_user
144
- local test_password
145
- login_url=$(get_config '.auth.loginUrl' "")
146
- test_user="${RALPH_TEST_USER:-$(get_config '.auth.testUser' "")}"
147
- test_password="${RALPH_TEST_PASSWORD:-$(get_config '.auth.testPassword' "")}"
148
-
149
- if [[ -n "$login_url" && -n "$test_user" && -n "$test_password" ]]; then
150
- # Build auth login JSON
151
- local username_selector
152
- local password_selector
153
- local submit_selector
154
- local success_indicator
155
- username_selector=$(get_config '.auth.usernameSelector' "input[name='email'], input[name='username'], input[type='email']")
156
- password_selector=$(get_config '.auth.passwordSelector' "input[name='password'], input[type='password']")
157
- submit_selector=$(get_config '.auth.submitSelector' "button[type='submit'], input[type='submit']")
158
- success_indicator=$(get_config '.auth.successIndicator' "")
159
-
160
- auth_login=$(jq -n \
161
- --arg loginUrl "$login_url" \
162
- --arg usernameSelector "$username_selector" \
163
- --arg passwordSelector "$password_selector" \
164
- --arg submitSelector "$submit_selector" \
165
- --arg username "$test_user" \
166
- --arg password "$test_password" \
167
- --arg successIndicator "$success_indicator" \
168
- '{
169
- loginUrl: $loginUrl,
170
- usernameSelector: $usernameSelector,
171
- passwordSelector: $passwordSelector,
172
- submitSelector: $submitSelector,
173
- username: $username,
174
- password: $password,
175
- successIndicator: (if $successIndicator == "" then null else $successIndicator end)
176
- }')
177
- fi
178
-
179
- echo " Running Playwright verification..."
180
-
181
- local result
182
- local exit_code=0
183
-
184
- # Build the command with optional auth
185
- local cmd_args=(
186
- npx tsx "$verify_script" "$url"
187
- --selectors "$selectors"
188
- --screenshot "$screenshot_path"
189
- --timeout "$BROWSER_PAGE_TIMEOUT_MS"
190
- )
191
-
192
- if [[ -n "$auth_login" ]]; then
193
- cmd_args+=(--auth-login "$auth_login")
194
- fi
195
-
196
- # Run browser verification with wrapper timeout (in case Playwright hangs)
197
- result=$(run_with_timeout "$BROWSER_TIMEOUT_SECONDS" "${cmd_args[@]}" 2>&1) || exit_code=$?
198
-
199
- # Check for timeout
200
- if [[ $exit_code -eq 124 ]]; then
201
- print_error "failed (timed out after ${BROWSER_TIMEOUT_SECONDS}s)"
202
- echo " The page may be stuck loading or the dev server isn't responding."
203
- echo " Check: curl -I $url"
204
- return run_curl_check "$url"
205
- fi
206
-
207
- # Check if we got any output
208
- if [[ -z "$result" ]]; then
209
- print_error "failed (no output from Playwright)"
210
- echo " Exit code: $exit_code"
211
- echo " This usually means Playwright crashed or isn't installed correctly."
212
- echo " Try: npm install playwright && npx playwright install chromium"
213
- return run_curl_check "$url"
214
- fi
215
-
216
- # Check if result is valid JSON
217
- if ! echo "$result" | jq -e . >/dev/null 2>&1; then
218
- print_error "failed (invalid response)"
219
- echo " Raw output:"
220
- echo "$result" | head -20 | sed 's/^/ /'
221
- return run_curl_check "$url"
222
- fi
223
-
224
- # Parse result
225
- local passed
226
- passed=$(echo "$result" | jq -r '.pass // false' 2>/dev/null)
227
-
228
- if [[ "$passed" == "true" ]]; then
229
- local load_time
230
- load_time=$(echo "$result" | jq -r '.loadTime // 0' 2>/dev/null)
231
- print_success "passed (${load_time}ms)"
232
-
233
- # Show any warnings
234
- local warnings
235
- warnings=$(echo "$result" | jq -r '.warnings[]?' 2>/dev/null)
236
- if [[ -n "$warnings" ]]; then
237
- echo "$warnings" | sed 's/^/ Warning: /'
238
- fi
239
-
240
- # Run mobile check if required
241
- if [[ -n "$check_mobile" ]]; then
242
- echo -n " Mobile viewport... "
243
- local mobile_result
244
- mobile_result=$(run_with_timeout "$BROWSER_TIMEOUT_SECONDS" npx tsx "$verify_script" "$url" \
245
- --selectors "$selectors" \
246
- --screenshot "$RALPH_DIR/screenshots/${story}-mobile.png" \
247
- --mobile \
248
- 2>&1) || true
249
-
250
- local mobile_passed
251
- mobile_passed=$(echo "$mobile_result" | jq -r '.pass // false' 2>/dev/null)
252
-
253
- if [[ "$mobile_passed" == "true" ]]; then
254
- print_success "passed"
255
- else
256
- print_warning "issues found"
257
- echo "$mobile_result" | jq -r '.errors[]?' 2>/dev/null | head -3 | sed 's/^/ /'
258
- fi
259
- fi
260
-
261
- return 0
262
- else
263
- print_error "failed"
264
- echo ""
265
-
266
- # Show errors
267
- echo " Errors:"
268
- echo "$result" | jq -r '.errors[]?' 2>/dev/null | sed 's/^/ /'
269
-
270
- # Show console errors if any
271
- local console_errors
272
- console_errors=$(echo "$result" | jq -r '.consoleErrors[]?' 2>/dev/null)
273
- if [[ -n "$console_errors" ]]; then
274
- echo ""
275
- echo " Console errors:"
276
- echo "$console_errors" | head -5 | sed 's/^/ /'
277
- fi
278
-
279
- # Show missing elements if any
280
- local missing
281
- missing=$(echo "$result" | jq -r '.elementsMissing[]?' 2>/dev/null)
282
- if [[ -n "$missing" ]]; then
283
- echo ""
284
- echo " Missing elements:"
285
- echo "$missing" | sed 's/^/ /'
286
- fi
287
-
288
- # Save for failure context
289
- echo "$result" > "$RALPH_DIR/last_browser_failure.json"
290
-
291
- return 1
292
- fi
293
- }
294
-
295
- # Fallback curl check when Playwright isn't available
296
- run_curl_check() {
297
- local url="$1"
298
-
299
- local http_response
300
- http_response=$(curl -s -o /dev/null -w "%{http_code}" --max-time "$CURL_TIMEOUT_SECONDS" "$url" 2>/dev/null) || http_response="000"
301
-
302
- if [[ "$http_response" == "000" ]]; then
303
- print_error "Cannot reach $url - server not responding"
304
- return 1
305
- elif [[ "$http_response" -ge 500 ]]; then
306
- print_error "Server error $http_response at $url"
307
- return 1
308
- elif [[ "$http_response" -ge 400 ]]; then
309
- print_warning "HTTP $http_response (may be expected for auth pages)"
310
- return 0
311
- fi
312
-
313
- # Check for error messages in response
314
- local page_content
315
- page_content=$(curl -s --max-time "$CURL_TIMEOUT_SECONDS" "$url" 2>/dev/null)
316
-
317
- if echo "$page_content" | grep -qi "something went wrong\|error.*occurred\|500 internal\|503 service\|oops\!" 2>/dev/null; then
318
- print_error "Page contains error message"
319
- return 1
320
- fi
321
-
322
- print_success "HTTP $http_response"
323
- return 0
324
- }
@@ -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
- }