agentic-loop 3.18.1 → 3.18.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/ralph/loop.sh +57 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-loop",
3
- "version": "3.18.1",
3
+ "version": "3.18.2",
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",
package/ralph/loop.sh CHANGED
@@ -391,6 +391,10 @@ PATTERN: <pattern>"
391
391
  }
392
392
 
393
393
  run_loop() {
394
+ # Trap Ctrl+C so it stops the entire loop, not just the current child process.
395
+ # Without this, SIGINT only kills the pipeline (claude|tee) and the while loop continues.
396
+ trap 'echo ""; print_warning "Ctrl+C received — stopping loop..."; trap - INT; kill -INT $$' INT
397
+
394
398
  local max_iterations="$DEFAULT_MAX_ITERATIONS"
395
399
  local specific_story=""
396
400
  local fast_mode=false
@@ -950,6 +954,36 @@ startup_checklist() {
950
954
  fi
951
955
  }
952
956
 
957
+ # Helper: Check if files listed in a story's files.create/files.modify already exist on disk
958
+ # Returns newline-separated list of existing files (empty string if none)
959
+ _check_story_files_exist() {
960
+ local story_id="$1"
961
+ local prd_file="$RALPH_DIR/prd.json"
962
+ [[ ! -f "$prd_file" ]] && return
963
+
964
+ local file_list
965
+ file_list=$(jq -r --arg id "$story_id" '
966
+ .stories[] | select(.id == $id) |
967
+ ((.files.create // []) + (.files.modify // [])) | .[]
968
+ ' "$prd_file" 2>/dev/null) || return
969
+
970
+ [[ -z "$file_list" ]] && return
971
+
972
+ local existing=""
973
+ while IFS= read -r f; do
974
+ [[ -z "$f" ]] && continue
975
+ if [[ -f "$f" ]]; then
976
+ if [[ -z "$existing" ]]; then
977
+ existing="$f"
978
+ else
979
+ existing="$existing"$'\n'"$f"
980
+ fi
981
+ fi
982
+ done <<< "$file_list"
983
+
984
+ [[ -n "$existing" ]] && echo "$existing"
985
+ }
986
+
953
987
  # Helper: Build delta prompt for continuing session
954
988
  # Minimal context - just story ID + any failure info
955
989
  _build_delta_prompt() {
@@ -964,6 +998,15 @@ _build_delta_prompt() {
964
998
  if [[ -n "$failure_context" ]]; then
965
999
  echo "## Retry: Fix the errors below"
966
1000
  echo ""
1001
+
1002
+ # Check if story files already exist — if so, skip re-implementation
1003
+ local existing_files
1004
+ existing_files=$(_check_story_files_exist "$story")
1005
+ if [[ -n "$existing_files" ]]; then
1006
+ echo "**The code is ALREADY WRITTEN.** Do NOT rewrite. Fix ONLY the errors below, then verify."
1007
+ echo ""
1008
+ fi
1009
+
967
1010
  echo "Read \`.ralph/last_failure.txt\` for full error details."
968
1011
  echo ""
969
1012
  echo '```'
@@ -1039,6 +1082,20 @@ build_prompt() {
1039
1082
  echo ""
1040
1083
  echo "## Previous Iteration Failed"
1041
1084
  echo ""
1085
+
1086
+ # Check if story files already exist — if so, skip re-implementation
1087
+ local existing_files
1088
+ existing_files=$(_check_story_files_exist "$story")
1089
+ if [[ -n "$existing_files" ]]; then
1090
+ echo "**IMPORTANT: The code for this story is ALREADY WRITTEN.** These files exist:"
1091
+ echo '```'
1092
+ echo "$existing_files"
1093
+ echo '```'
1094
+ echo "Do NOT rewrite or re-implement. Read the existing code, then fix ONLY the"
1095
+ echo "specific errors below. Go straight to verification after fixing."
1096
+ echo ""
1097
+ fi
1098
+
1042
1099
  echo "Read \`.ralph/last_failure.txt\` for details. Key error:"
1043
1100
  echo ""
1044
1101
  echo '```'