Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .agent/scripts/full-loop-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
readonly SCRIPT_DIR
readonly STATE_DIR=".agent/loop-state"
readonly STATE_FILE="${STATE_DIR}/full-loop.local.md"
readonly STATE_FILE="${STATE_DIR}/full-loop.local.state"

# Legacy state directory (for backward compatibility during migration)
# shellcheck disable=SC2034 # Defined for documentation, used in cancel checks
readonly LEGACY_STATE_DIR=".claude"
# shellcheck disable=SC2034 # Defined for backward compatibility path reference
readonly LEGACY_STATE_FILE="${LEGACY_STATE_DIR}/full-loop.local.md"
readonly LEGACY_STATE_FILE="${LEGACY_STATE_DIR}/full-loop.local.state"

# Default settings
readonly DEFAULT_MAX_TASK_ITERATIONS=50
Expand Down Expand Up @@ -562,7 +562,7 @@ cmd_resume() {
case "$CURRENT_PHASE" in
"$PHASE_TASK")
# Check if task is complete (check both new and legacy locations)
if [[ -f ".agent/loop-state/ralph-loop.local.md" ]] || [[ -f ".claude/ralph-loop.local.md" ]]; then
if [[ -f ".agent/loop-state/ralph-loop.local.state" ]] || [[ -f ".claude/ralph-loop.local.state" ]]; then
print_info "Task loop still active. Complete it first."
return 0
fi
Expand Down Expand Up @@ -643,10 +643,10 @@ cmd_cancel() {
clear_state

# Also cancel any sub-loops (both new and legacy locations)
rm -f ".agent/loop-state/ralph-loop.local.md" 2>/dev/null
rm -f ".agent/loop-state/quality-loop.local.md" 2>/dev/null
rm -f ".claude/ralph-loop.local.md" 2>/dev/null
rm -f ".claude/quality-loop.local.md" 2>/dev/null
rm -f ".agent/loop-state/ralph-loop.local.state" 2>/dev/null
rm -f ".agent/loop-state/quality-loop.local.state" 2>/dev/null
rm -f ".claude/ralph-loop.local.state" 2>/dev/null
rm -f ".claude/quality-loop.local.state" 2>/dev/null
Comment on lines +646 to +649

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These file paths for sub-loops are hardcoded, and a similar issue exists in cmd_resume. To improve maintainability and avoid magic strings, it would be best to define them as readonly constants at the top of the script. This would centralize the paths and make future changes easier.

For example, at the top of the script:

readonly RALPH_STATE_FILE_PATH=".agent/loop-state/ralph-loop.local.state"
readonly RALPH_LEGACY_STATE_FILE_PATH=".claude/ralph-loop.local.state"
# ... and so on for quality loop

Then these constants could be used here and in cmd_resume.


print_success "Full loop cancelled"
return 0
Expand Down
2 changes: 1 addition & 1 deletion .agent/scripts/generate-opencode-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ Cancel the active Ralph loop.
~/.aidevops/agents/scripts/ralph-loop-helper.sh cancel
```

This removes the state file at `.agent/loop-state/ralph-loop.local.md` and stops the loop.
This removes the state file at `.agent/loop-state/ralph-loop.local.state` and stops the loop.

If no loop is active, it will report "No active Ralph loop found."
EOF
Expand Down
4 changes: 2 additions & 2 deletions .agent/scripts/quality-loop-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
readonly SCRIPT_DIR
readonly STATE_DIR=".agent/loop-state"
readonly STATE_FILE="${STATE_DIR}/quality-loop.local.md"
readonly STATE_FILE="${STATE_DIR}/quality-loop.local.state"

# Legacy state directory (for backward compatibility during migration)
# shellcheck disable=SC2034 # Defined for documentation
Expand Down Expand Up @@ -228,7 +228,7 @@ get_pending_checks() {
# $2 - Max iterations
# $3 - Options string (key=value pairs separated by commas)
# Returns: 0
# Side effects: Creates .agent/loop-state/quality-loop.local.md
# Side effects: Creates .agent/loop-state/quality-loop.local.state

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of hardcoding the filename in this comment, it's better to refer to the STATE_FILE constant defined at the top of the script. This ensures the comment stays in sync if the variable ever changes.

Suggested change
# Side effects: Creates .agent/loop-state/quality-loop.local.state
# Side effects: Creates the state file defined in STATE_FILE

create_state() {
local loop_type="$1"
local max_iterations="$2"
Expand Down
12 changes: 6 additions & 6 deletions .agent/scripts/ralph-loop-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ fi

# State directories
readonly RALPH_STATE_DIR=".agent/loop-state"
readonly RALPH_STATE_FILE="${RALPH_STATE_DIR}/ralph-loop.local.md"
readonly RALPH_STATE_FILE="${RALPH_STATE_DIR}/ralph-loop.local.state"

# Legacy state directory (for backward compatibility during migration)
readonly RALPH_LEGACY_STATE_DIR=".claude"
# shellcheck disable=SC2034 # Defined for documentation, used in status checks
readonly RALPH_LEGACY_STATE_FILE="${RALPH_LEGACY_STATE_DIR}/ralph-loop.local.md"
readonly RALPH_LEGACY_STATE_FILE="${RALPH_LEGACY_STATE_DIR}/ralph-loop.local.state"

# Adaptive timing constants (evidence-based from PR #19 analysis)
readonly RALPH_DELAY_BASE="${RALPH_DELAY_BASE:-2}"
Expand Down Expand Up @@ -599,8 +599,8 @@ show_status_all() {
# Check for v2 state (new location first, then legacy)
local v2_state="$worktree_path/.agent/loop-state/loop-state.json"
local v2_state_legacy="$worktree_path/.claude/loop-state.json"
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.md"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.md"
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"
Comment on lines +602 to +603

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file paths are being reconstructed here, but you have RALPH_STATE_FILE and RALPH_LEGACY_STATE_FILE constants defined at the top of the file. Reusing them would make the code more maintainable and less prone to errors if the paths change.

Suggested change
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"
local legacy_state="$worktree_path/$RALPH_STATE_FILE"
local legacy_state_old="$worktree_path/$RALPH_LEGACY_STATE_FILE"


# Check any of the state file locations
if [[ -f "$v2_state" ]] || [[ -f "$v2_state_legacy" ]] || [[ -f "$legacy_state" ]] || [[ -f "$legacy_state_old" ]]; then
Expand Down Expand Up @@ -671,8 +671,8 @@ check_other_loops() {
# Check all possible state file locations (new and legacy)
local v2_state="$worktree_path/.agent/loop-state/loop-state.json"
local v2_state_legacy="$worktree_path/.claude/loop-state.json"
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.md"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.md"
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"
Comment on lines +674 to +675

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the show_status_all function, the file paths are being reconstructed here. Please use the RALPH_STATE_FILE and RALPH_LEGACY_STATE_FILE constants to improve maintainability.

Suggested change
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"
local legacy_state="$worktree_path/$RALPH_STATE_FILE"
local legacy_state_old="$worktree_path/$RALPH_LEGACY_STATE_FILE"


if [[ -f "$v2_state" ]] || [[ -f "$v2_state_legacy" ]] || [[ -f "$legacy_state" ]] || [[ -f "$legacy_state_old" ]]; then
local branch
Expand Down
4 changes: 2 additions & 2 deletions .agent/scripts/session-review-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ get_todo_status() {
get_ralph_status() {
local project_root="$1"
# Check new location first, then legacy
local ralph_file="$project_root/.agent/loop-state/ralph-loop.local.md"
local ralph_file_legacy="$project_root/.claude/ralph-loop.local.md"
local ralph_file="$project_root/.agent/loop-state/ralph-loop.local.state"
local ralph_file_legacy="$project_root/.claude/ralph-loop.local.state"
Comment on lines +93 to +94

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These file paths are hardcoded. To improve maintainability and avoid magic strings, consider defining them as readonly constants at the top of the script and using those constants here. This centralizes the path definitions, making them easier to update in the future.


local active_file=""
[[ -f "$ralph_file" ]] && active_file="$ralph_file"
Expand Down
4 changes: 2 additions & 2 deletions .agent/scripts/worktree-sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ epoch_to_date() {
get_ralph_loop_status() {
local worktree_path="$1"
# Check new location first, then legacy
local state_file="$worktree_path/.agent/loop-state/ralph-loop.local.md"
local state_file_legacy="$worktree_path/.claude/ralph-loop.local.md"
local state_file="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local state_file_legacy="$worktree_path/.claude/ralph-loop.local.state"
Comment on lines +106 to +107

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These file paths are hardcoded. To improve maintainability and avoid magic strings, consider defining them as readonly constants at the top of the script and using those constants here. This centralizes the path definitions, making them easier to update in the future.


local active_file=""
[[ -f "$state_file" ]] && active_file="$state_file"
Expand Down
4 changes: 2 additions & 2 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ migrate_loop_state_directories() {

# Check for loop state files in old location
local has_loop_state=false
if [[ -f "$old_state_dir/ralph-loop.local.md" ]] || \
if [[ -f "$old_state_dir/ralph-loop.local.state" ]] || \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

migrate_loop_state_directories() now checks for ralph-loop.local.state inside .claude/, but existing installs are likely to still have the legacy .md state file; in that case has_loop_state will stay false and the state won’t be migrated.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

[[ -f "$old_state_dir/loop-state.json" ]] || \
[[ -d "$old_state_dir/receipts" ]]; then
has_loop_state=true
Expand All @@ -245,7 +245,7 @@ migrate_loop_state_directories() {
mkdir -p "$new_state_dir"

# Move loop-related files
for file in ralph-loop.local.md loop-state.json re-anchor.md guardrails.md; do
for file in ralph-loop.local.state loop-state.json re-anchor.md guardrails.md; do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This migration logic appears incomplete and could lead to loss of user loop state.

  1. File Rename: It moves ralph-loop.local.state but doesn't handle renaming existing .md state files (e.g., ralph-loop.local.md) to the new .state extension. Old .md files will be ignored by the updated scripts.
  2. Missing Files: The migration only considers ralph-loop. It should also handle quality-loop.local.md and full-loop.local.md.

A more robust migration would be to explicitly check for old .md files, move and rename them. For example:

# Files to move and rename from .md to .state
local files_to_rename=("ralph-loop.local" "quality-loop.local" "full-loop.local")
for base_name in "${files_to_rename[@]}"; do
    if [[ -f "$old_state_dir/${base_name}.md" ]]; then
        mv "$old_state_dir/${base_name}.md" "$new_state_dir/${base_name}.state"
        print_info "  Moved and renamed ${base_name}.md"
    fi
done

# Move other files that don't need renaming
for file in loop-state.json re-anchor.md guardrails.md; do
    if [[ -f "$old_state_dir/$file" ]]; then
        mv "$old_state_dir/$file" "$new_state_dir/"
        print_info "  Moved $file"
    fi
done

if [[ -f "$old_state_dir/$file" ]]; then
mv "$old_state_dir/$file" "$new_state_dir/"
print_info " Moved $file"
Expand Down
Loading