Skip to content

fix(loop-state): change state files from .md to .state extension#111

Merged
marcusquinn merged 1 commit intomainfrom
fix/loop-state-extension
Jan 17, 2026
Merged

fix(loop-state): change state files from .md to .state extension#111
marcusquinn merged 1 commit intomainfrom
fix/loop-state-extension

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Jan 17, 2026

Summary

Loop state files (.local.md) were being picked up as OpenCode agents because they're .md files in the .agent/ directory tree (via the .opencode/agent symlink).

Solution

Changed file extensions from .md to .state:

  • ralph-loop.local.md -> ralph-loop.local.state
  • quality-loop.local.md -> quality-loop.local.state
  • full-loop.local.md -> full-loop.local.state

This prevents OpenCode from discovering them as agents while keeping them in the logical .agent/loop-state/ location.

Files Updated

  • quality-loop-helper.sh - STATE_FILE constant
  • ralph-loop-helper.sh - RALPH_STATE_FILE and legacy paths
  • full-loop-helper.sh - STATE_FILE and cleanup paths
  • worktree-sessions.sh - state file paths
  • session-review-helper.sh - ralph file paths
  • generate-opencode-commands.sh - documentation
  • setup.sh - migration paths

Testing

After merging, run ./setup.sh to deploy. The loop state files will use .state extension and won't appear in OpenCode's Tab cycle.

Fixes "Loop-State/Quality-Loop.Local" appearing in OpenCode tab cycle.

Summary by CodeRabbit

  • Refactor

    • Updated internal state file tracking format and associated helper scripts for improved system organization and consistency.
  • Chores

    • Adjusted default iteration limits for loop optimization.

✏️ Tip: You can customize this high-level summary in your review settings.

Loop state files (.local.md) were being picked up as OpenCode agents
because they're .md files in the .agent/ directory tree.

Changed extensions:
- ralph-loop.local.md -> ralph-loop.local.state
- quality-loop.local.md -> quality-loop.local.state
- full-loop.local.md -> full-loop.local.state

This prevents OpenCode from discovering them as agents while keeping
them in the logical .agent/loop-state/ location.

Fixes 'Loop-State/Quality-Loop.Local' appearing in OpenCode tab cycle.
@marcusquinn marcusquinn merged commit c80342d into main Jan 17, 2026
4 of 6 checks passed
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 17, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

State file naming convention updated from .md to .state across loop helper scripts for consistency. Two new iteration limit constants added to full-loop-helper.sh. Migration logic and all related state file references updated to reflect the new file extension throughout the shell script infrastructure.

Changes

Cohort / File(s) Summary
Loop Helper Scripts
.agent/scripts/full-loop-helper.sh, .agent/scripts/ralph-loop-helper.sh, .agent/scripts/quality-loop-helper.sh
State file naming migrated from .md to .state extension (both active and legacy paths). Updated state file path references in resume checks and cancellation logic. Added DEFAULT_MAX_PREFLIGHT_ITERATIONS (50) and DEFAULT_MAX_PR_ITERATIONS (20) constants to full-loop-helper.sh.
State File Reference Scripts
.agent/scripts/session-review-helper.sh, .agent/scripts/worktree-sessions.sh
Updated get_ralph_status functions to read loop state from new .state file paths with legacy fallback support. File path changes only; extraction and output logic unchanged.
Setup & Migration
setup.sh
Updated migrate_loop_state_directories to search for and migrate .state files instead of .md files in legacy state directory transfers.
Command Documentation
.agent/scripts/generate-opencode-commands.sh
Help text updated to reference new .agent/loop-state/ralph-loop.local.state path in CANCEL-RALPH command documentation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


🔄 From .md loops to .state of mind,
Constants hold defaults, neat and aligned,
Legacy paths gracefully fall back in place,
Refactoring loops—no control flow to retrace!

✨ Finishing touches
  • 📝 Generate docstrings

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 an issue where certain loop state files, previously using the .md extension, were mistakenly recognized as OpenCode agents. To rectify this, the file extension for these state files has been changed to .state. This ensures that the system correctly distinguishes between actual OpenCode agents and internal state files, preventing unintended behavior and improving the clarity of file purpose.

Highlights

  • File Extension Change: Modified the file extension for loop state files from .md to .state to prevent them from being incorrectly identified as OpenCode agents.
  • OpenCode Agent Misidentification Fix: Resolved an issue where .md state files in the .agent/ directory were being picked up by OpenCode as agents, leading to unwanted entries in the Tab cycle.
  • Backward Compatibility & Migration: Updated various helper scripts and the setup script to recognize and migrate state files with the new .state extension, while also maintaining checks for legacy .md files during a transition period.
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, 262 code smells

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

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 262
  • VULNERABILITIES: 0

Generated on: Sat Jan 17 03:20:49 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

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 correctly changes the file extension for loop state files from .md to .state across multiple scripts, which is a good change to prevent them from being incorrectly identified as agents. My review focuses on improving maintainability by reducing hardcoded file paths and addresses a critical issue in the migration script (setup.sh) that could lead to loss of user state. I've suggested using constants for file paths where possible and provided a more robust migration logic for setup.sh.


# 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

Comment on lines +646 to +649
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

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.

# $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

Comment on lines +602 to +603
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"

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"

Comment on lines +674 to +675
local legacy_state="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local legacy_state_old="$worktree_path/.claude/ralph-loop.local.state"

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"

Comment on lines +93 to +94
local ralph_file="$project_root/.agent/loop-state/ralph-loop.local.state"
local ralph_file_legacy="$project_root/.claude/ralph-loop.local.state"

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.

Comment on lines +106 to +107
local state_file="$worktree_path/.agent/loop-state/ralph-loop.local.state"
local state_file_legacy="$worktree_path/.claude/ralph-loop.local.state"

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.

@augmentcode
Copy link

augmentcode bot commented Jan 17, 2026

🤖 Augment PR Summary

Summary: This PR prevents loop state files from being discovered as OpenCode agents by changing their extension from .local.md to .local.state.

Changes:

  • Updated Ralph/Quality/Full loop helper scripts to read/write and clean up *.local.state files instead of *.local.md
  • Adjusted cross-loop checks (resume/cancel/status/session tools) to look for the new .state filenames in both .agent/loop-state and legacy .claude locations
  • Updated documentation output in generate-opencode-commands.sh to reference the new state filename
  • Updated setup.sh migration logic to move renamed loop state files during deployment

Technical Notes: The key behavior change is the file extension swap to avoid Markdown-based agent discovery while keeping the loop-state files colocated under .agent/loop-state/.

🤖 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. 1 suggestions posted.

Fix All in Augment

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

# 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 👎

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