Skip to content

chore: add loop state migration from .claude/ to .agent/loop-state/#67

Merged
marcusquinn merged 1 commit intomainfrom
chore/loop-state-migration
Jan 12, 2026
Merged

chore: add loop state migration from .claude/ to .agent/loop-state/#67
marcusquinn merged 1 commit intomainfrom
chore/loop-state-migration

Conversation

@marcusquinn
Copy link
Owner

Summary

Handles the breaking change from v2.51.0 where loop state directory moved from .claude/ to .agent/loop-state/.

What This Does

When users run setup.sh, it now:

  1. Scans ~/Git/ for repositories with .claude/ loop state files
  2. Moves loop-related files to .agent/loop-state/:
    • ralph-loop.local.md
    • loop-state.json
    • re-anchor.md
    • guardrails.md
    • receipts/ directory
  3. Updates .gitignore if needed
  4. Removes empty .claude/ directories
  5. Preserves other files in .claude/ (non-destructive)

Why This Is Needed

PR #65 moved loop state from .claude/ to .agent/loop-state/ with backward compatibility in the scripts (they check both locations). However, without migration:

  • Old state files would be orphaned
  • Users might have confusing duplicate state
  • .claude/ directories would accumulate cruft

Testing

  • ShellCheck passes
  • Bash syntax validation passes
  • Manual test with existing .claude/ directory

Handles the breaking change from v2.51.0 where loop state directory moved.
The migration:
- Scans ~/Git/ for repositories with .claude/ loop state
- Moves ralph-loop.local.md, loop-state.json, receipts/, etc.
- Updates .gitignore if needed
- Removes empty .claude/ directories
- Non-destructive: preserves other files in .claude/
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 12, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between cf40b84 and 1224021.

📒 Files selected for processing (1)
  • setup.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a breaking change introduced in v2.51.0 by providing an automated migration path for user loop state directories. It ensures that legacy loop state files are correctly moved from the old .claude/ location to the new .agent/loop-state/ structure, preventing orphaned files, duplicate state issues, and accumulation of unnecessary directories, thereby maintaining data integrity and a clean project structure for users.

Highlights

  • Loop State Migration: Implemented a new migrate_loop_state_directories function in setup.sh to automatically move loop state files from the deprecated .claude/ directory to the new .agent/loop-state/ location.
  • File Relocation Logic: The migration process identifies Git repositories in common user directories, moves specific loop-related files (ralph-loop.local.md, loop-state.json, re-anchor.md, guardrails.md, and receipts/ directory) to the new location, and updates .gitignore accordingly.
  • Directory Cleanup: Empty .claude/ directories are removed after migration, while any .claude/ directories containing other files are preserved to prevent data loss.
  • Integration into Setup Script: The new migration function is integrated into the setup.sh script's main execution flow, ensuring users are prompted to perform the migration during setup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link

@github-actions
Copy link

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 256 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Mon Jan 12 17:10:09 UTC 2026: Code review monitoring started
Mon Jan 12 17:10:10 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 256
Mon Jan 12 17:10:10 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Mon Jan 12 17:10:12 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 256
  • VULNERABILITIES: 0

Generated on: Mon Jan 12 17:10:52 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@augmentcode
Copy link

augmentcode bot commented Jan 12, 2026

🤖 Augment PR Summary

Summary: Adds an automated migration step in setup.sh to handle the v2.51.0 loop-state directory move from .claude/ to .agent/loop-state/.

Changes:

  • Introduces migrate_loop_state_directories to discover Git repos (e.g., under ~/Git) containing legacy loop state.
  • Moves known loop-related files/directories into .agent/loop-state/ and cleans up empty .claude/ folders.
  • Appends .agent/loop-state/ to each repo’s .gitignore when missing.
  • Wires the migration into the interactive main() setup flow via confirm_step.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.


# Migrate loop state from .claude/ to .agent/loop-state/ in user projects
# This handles the breaking change from v2.51.0 where loop state directory moved
# The migration is non-destructive: moves files, doesn't delete originals until confirmed
Copy link

Choose a reason for hiding this comment

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

This comment says the migration "doesn't delete originals until confirmed", but the implementation uses mv and no confirmation, so the originals are removed immediately. Consider aligning the comment with the actual behavior so users don’t assume a reversible/verified migration.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎


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

Choose a reason for hiding this comment

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

has_loop_state only checks for ralph-loop.local.md, loop-state.json, and receipts/, but the migration also moves re-anchor.md and guardrails.md. Repos that only have those files would currently be skipped.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

# Move loop-related files
for file in ralph-loop.local.md loop-state.json re-anchor.md guardrails.md; do
if [[ -f "$old_state_dir/$file" ]]; then
mv "$old_state_dir/$file" "$new_state_dir/"
Copy link

Choose a reason for hiding this comment

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

These mv operations can overwrite existing files in $new_state_dir if users already have new-format state (or rerun migration), which risks losing the newer state. Also, if $new_state_dir/receipts already exists, mv can result in a nested receipts/receipts directory.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

@marcusquinn marcusquinn merged commit d1e8887 into main Jan 12, 2026
9 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a migration script to move loop state files from the legacy .claude/ directory to the new .agent/loop-state/ location. The implementation is well-structured, but I've identified a significant correctness issue where the script fails to detect all files intended for migration, potentially leaving some repositories in an inconsistent state. Additionally, there's an opportunity to improve the robustness of a directory check. My review includes specific code suggestions to address these points.

Comment on lines +233 to +240
local has_loop_state=false
if [[ -f "$old_state_dir/ralph-loop.local.md" ]] || \
[[ -f "$old_state_dir/loop-state.json" ]] || \
[[ -d "$old_state_dir/receipts" ]]; then
has_loop_state=true
fi

[[ "$has_loop_state" != "true" ]] && continue

Choose a reason for hiding this comment

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

high

The check for legacy loop state files is incomplete. It's missing re-anchor.md and guardrails.md, which are moved later in the script (line 248). This means if a .claude directory only contains one of these files, the migration for that repository will be skipped. This is a correctness issue.

Additionally, the logic using a has_loop_state flag is verbose and can be simplified into a more direct check. The suggested change below fixes the bug and improves readability by combining the check and the conditional continuation.

Suggested change
local has_loop_state=false
if [[ -f "$old_state_dir/ralph-loop.local.md" ]] || \
[[ -f "$old_state_dir/loop-state.json" ]] || \
[[ -d "$old_state_dir/receipts" ]]; then
has_loop_state=true
fi
[[ "$has_loop_state" != "true" ]] && continue
if ! [[ -f "$old_state_dir/ralph-loop.local.md" || \
-f "$old_state_dir/loop-state.json" || \
-d "$old_state_dir/receipts" || \
-f "$old_state_dir/re-anchor.md" || \
-f "$old_state_dir/guardrails.md" ]]; then
continue
fi

Comment on lines +263 to +269
remaining=$(find "$old_state_dir" -mindepth 1 -maxdepth 1 2>/dev/null | wc -l | tr -d ' ')

if [[ "$remaining" -eq 0 ]]; then
rmdir "$old_state_dir" 2>/dev/null && print_info " Removed empty .claude/"
else
print_warning " .claude/ has other files, not removing"
fi

Choose a reason for hiding this comment

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

medium

The use of find ... | wc -l to check if a directory is empty is not fully robust, as it can miscount if filenames contain newline characters. A more standard and safer approach is to check if the output of ls -A is empty. This avoids parsing find's output and is a common idiom for this purpose.

Suggested change
remaining=$(find "$old_state_dir" -mindepth 1 -maxdepth 1 2>/dev/null | wc -l | tr -d ' ')
if [[ "$remaining" -eq 0 ]]; then
rmdir "$old_state_dir" 2>/dev/null && print_info " Removed empty .claude/"
else
print_warning " .claude/ has other files, not removing"
fi
remaining=$(ls -A -- "$old_state_dir" 2>/dev/null)
if [[ -z "$remaining" ]]; then
rmdir "$old_state_dir" 2>/dev/null && print_info " Removed empty .claude/"
else
print_warning " .claude/ has other files, not removing"
fi

@marcusquinn marcusquinn deleted the chore/loop-state-migration branch February 21, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant