agentic-loop 3.2.11 → 3.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/ralph/loop.sh +70 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-loop",
3
- "version": "3.2.11",
3
+ "version": "3.3.0",
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
@@ -182,6 +182,7 @@ run_loop() {
182
182
  local total_attempts=0
183
183
  local skipped_stories=()
184
184
  local start_time
185
+ local session_started=false # Track if we've started a Claude session
185
186
  start_time=$(date +%s)
186
187
 
187
188
  while [[ $iteration -lt $max_iterations ]]; do
@@ -278,7 +279,7 @@ run_loop() {
278
279
 
279
280
  # Temporarily disable errexit to capture build_prompt errors
280
281
  set +e
281
- build_prompt "$story" "$failure_context" > "$prompt_file" 2>&1
282
+ build_prompt "$story" "$failure_context" "$session_started" > "$prompt_file" 2>&1
282
283
  local build_status=$?
283
284
  set -e
284
285
 
@@ -323,18 +324,27 @@ run_loop() {
323
324
  local timeout_seconds
324
325
  timeout_seconds=$(get_config '.maxSessionSeconds' "$DEFAULT_TIMEOUT_SECONDS")
325
326
 
326
- # Run Claude with output visible on terminal
327
- if ! cat "$prompt_file" | run_with_timeout "$timeout_seconds" claude -p --dangerously-skip-permissions --verbose; then
327
+ # Run Claude - first story gets fresh session, subsequent continue the session
328
+ local claude_cmd="claude -p --dangerously-skip-permissions --verbose"
329
+ if [[ "$session_started" == "true" ]]; then
330
+ claude_cmd="claude --continue -p --dangerously-skip-permissions --verbose"
331
+ fi
332
+
333
+ if ! cat "$prompt_file" | run_with_timeout "$timeout_seconds" $claude_cmd; then
328
334
  print_warning "Claude session ended (timeout or error)"
329
335
  log_progress "$story" "TIMEOUT" "Claude session ended after ${timeout_seconds}s"
330
336
  rm -f "$prompt_file"
331
337
 
338
+ # Session may be broken - reset for next attempt
339
+ session_started=false
340
+
332
341
  # If running specific story, exit on failure
333
342
  [[ -n "$specific_story" ]] && return 1
334
343
  continue
335
344
  fi
336
345
 
337
346
  rm -f "$prompt_file"
347
+ session_started=true # Mark session as active for subsequent stories
338
348
 
339
349
  # 5. Run migrations BEFORE verification (tests need DB schema)
340
350
  if ! run_migrations_if_needed "$pre_story_sha"; then
@@ -611,6 +621,52 @@ _inject_architecture() {
611
621
  echo "- Scripts go in scripts/, docs go in docs/"
612
622
  }
613
623
 
624
+ # Helper: Build delta prompt for continuing session
625
+ # Minimal context - just new story + any failure info
626
+ _build_delta_prompt() {
627
+ local story="$1"
628
+ local story_json="$2"
629
+ local failure_context="${3:-}"
630
+
631
+ echo ""
632
+ echo "---"
633
+ echo ""
634
+
635
+ # If this is a retry (failure context exists), note it
636
+ if [[ -n "$failure_context" ]]; then
637
+ echo "## Retry: Fix the errors below"
638
+ echo ""
639
+ echo '```'
640
+ echo "$failure_context"
641
+ echo '```'
642
+ echo ""
643
+ else
644
+ # New story - note previous completion
645
+ local completed_count
646
+ completed_count=$(jq '[.stories[] | select(.passes==true)] | length' "$RALPH_DIR/prd.json" 2>/dev/null || echo "0")
647
+ if [[ "$completed_count" -gt 0 ]]; then
648
+ echo "## Previous stories complete. Moving to next story."
649
+ echo ""
650
+ # Suggest compact if we've done several stories
651
+ if [[ "$completed_count" -ge 3 ]]; then
652
+ echo "*Consider running /compact if context feels heavy.*"
653
+ echo ""
654
+ fi
655
+ fi
656
+ fi
657
+
658
+ echo "## Current Story"
659
+ echo ""
660
+ echo '```json'
661
+ echo "$story_json"
662
+ echo '```'
663
+
664
+ # Include file guidance for the new story
665
+ _inject_file_guidance "$story_json"
666
+ _inject_story_scale "$story_json"
667
+ _inject_styleguide "$story_json"
668
+ }
669
+
614
670
  # Helper: Inject failure context from previous iteration
615
671
  _inject_failure_context() {
616
672
  local failure_context="$1"
@@ -653,17 +709,25 @@ _inject_developer_dna() {
653
709
  }
654
710
 
655
711
  # Build the prompt with story context injected
712
+ # Usage: build_prompt <story_id> [failure_context] [is_continuation]
656
713
  build_prompt() {
657
714
  local story="$1"
658
715
  local failure_context="${2:-}"
659
-
660
- # Read base PROMPT.md
661
- cat "$PROMPT_FILE"
716
+ local is_continuation="${3:-false}"
662
717
 
663
718
  # Get story JSON once
664
719
  local story_json
665
720
  story_json=$(jq --arg id "$story" '.stories[] | select(.id==$id)' "$RALPH_DIR/prd.json")
666
721
 
722
+ if [[ "$is_continuation" == "true" ]]; then
723
+ # Delta prompt for continuing session - just new story context
724
+ _build_delta_prompt "$story" "$story_json" "$failure_context"
725
+ return
726
+ fi
727
+
728
+ # Full prompt for fresh session
729
+ cat "$PROMPT_FILE"
730
+
667
731
  # Inject all sections
668
732
  _inject_story_context "$story_json"
669
733
  _inject_file_guidance "$story_json"