agentic-loop 3.1.4 → 3.1.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-loop",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Autonomous AI coding loop - PRD-driven development with Claude Code",
5
5
  "author": "Allie Jones <allie@allthrive.ai>",
6
6
  "license": "MIT",
@@ -3,6 +3,7 @@
3
3
  # Hook: PreToolUse matcher: "Edit|Write"
4
4
  #
5
5
  # Allows: /prd, /idea commands (they create .prd-edit-allowed marker)
6
+ # Allows: Ralph loop fixing test steps (detected by last_failure.txt)
6
7
  # Blocks: Accidental edits during normal coding
7
8
 
8
9
  set -euo pipefail
@@ -19,6 +20,16 @@ if [[ "$FILE_PATH" == *"prd.json"* ]]; then
19
20
  exit 0
20
21
  fi
21
22
 
23
+ # Allow if Ralph is in a retry loop with a RECENT failure (within 10 min)
24
+ # This lets Ralph fix broken test steps, but not stale failures from old sessions
25
+ if [[ -f ".ralph/last_failure.txt" ]]; then
26
+ file_age=$(( $(date +%s) - $(stat -f %m ".ralph/last_failure.txt" 2>/dev/null || echo 0) ))
27
+ if [[ $file_age -lt 600 ]]; then # 10 minutes
28
+ echo '{"continue": true}'
29
+ exit 0
30
+ fi
31
+ fi
32
+
22
33
  echo "BLOCKED: prd.json is managed by Ralph. Use /prd or /idea to add stories." >&2
23
34
  exit 2 # Exit code 2 = blocking error
24
35
  fi
package/ralph/loop.sh CHANGED
@@ -355,6 +355,7 @@ run_loop() {
355
355
  rm -f "$RALPH_DIR/last_playwright_failure.log"
356
356
  rm -f "$RALPH_DIR/last_browser_failure.json"
357
357
  rm -f "$RALPH_DIR/last_precommit_failure.log"
358
+ rm -f "$RALPH_DIR/last_prd_failure.log"
358
359
 
359
360
  # Auto-commit if git is available
360
361
  if command -v git &>/dev/null && [[ -d ".git" ]]; then
@@ -608,9 +609,16 @@ _inject_failure_context() {
608
609
  echo ""
609
610
  echo "### What to do:"
610
611
  echo "1. Read the error messages carefully"
611
- echo "2. Identify the root cause"
612
+ echo "2. Identify the root cause - is it your implementation OR a flawed test step?"
612
613
  echo "3. Fix the issue (do not just retry the same approach)"
613
614
  echo "4. Run verification again"
615
+ echo ""
616
+ echo "### If the test step itself is broken:"
617
+ echo "If the error is in the PRD test step (not your implementation), you CAN fix it:"
618
+ echo "1. Read .ralph/prd.json to find the story index and broken testStep"
619
+ echo "2. Use jq to update: \`jq '.stories[IDX].testSteps[N] = \"fixed\"' .ralph/prd.json > tmp && mv tmp .ralph/prd.json\`"
620
+ echo "3. Common test step bugs: missing imports, str() triggering lazy loading, wrong paths"
621
+ echo "4. ONLY fix the test command - do NOT change acceptance criteria or story scope"
614
622
  }
615
623
 
616
624
  # Helper: Inject signs (learned patterns)
@@ -58,8 +58,13 @@ verify_prd_criteria() {
58
58
 
59
59
  local failed=0
60
60
  local log_file
61
+ local prd_failure_log="$RALPH_DIR/last_prd_failure.log"
61
62
  log_file=$(create_temp_file ".log") || return 1
62
63
 
64
+ # Clear previous PRD failure log
65
+ rm -f "$prd_failure_log"
66
+
67
+ local step_index=0
63
68
  while IFS= read -r step; do
64
69
  [[ -z "$step" ]] && continue
65
70
 
@@ -72,8 +77,19 @@ verify_prd_criteria() {
72
77
  echo ""
73
78
  echo " Output:"
74
79
  tail -"$MAX_OUTPUT_PREVIEW_LINES" "$log_file" | sed 's/^/ /'
80
+
81
+ # Save failure details for retry context
82
+ {
83
+ echo "PRD test step $step_index failed for $story:"
84
+ echo " Command: $step"
85
+ echo " Error output:"
86
+ tail -30 "$log_file" | sed 's/^/ /'
87
+ echo ""
88
+ } >> "$prd_failure_log"
89
+
75
90
  failed=1
76
91
  fi
92
+ ((step_index++)) || true
77
93
  done <<< "$test_steps"
78
94
 
79
95
  rm -f "$log_file"
package/ralph/verify.sh CHANGED
@@ -330,5 +330,18 @@ save_failure_context() {
330
330
  echo " async def get_items() -> list[ItemSchema]:"
331
331
  echo ""
332
332
  fi
333
+
334
+ if [[ -f "$RALPH_DIR/last_prd_failure.log" ]]; then
335
+ echo "--- PRD Test Step Failure ---"
336
+ echo "A test step in the PRD failed. Either fix your implementation OR fix the test step:"
337
+ echo ""
338
+ cat "$RALPH_DIR/last_prd_failure.log"
339
+ echo ""
340
+ echo "If the test step itself is broken (not your code), you can fix it:"
341
+ echo " 1. Read .ralph/prd.json to find the story and testSteps array"
342
+ echo " 2. Fix the command (e.g., add missing imports for SQLAlchemy models)"
343
+ echo " 3. Update with: jq '.stories[IDX].testSteps[N] = \"fixed command\"' .ralph/prd.json > tmp && mv tmp .ralph/prd.json"
344
+ echo ""
345
+ fi
333
346
  } > "$context_file"
334
347
  }