Skip to content

feat: migrate loop state to .agent/loop-state and enhance re-anchor#65

Merged
marcusquinn merged 2 commits intomainfrom
feature/loop-improvements
Jan 12, 2026
Merged

feat: migrate loop state to .agent/loop-state and enhance re-anchor#65
marcusquinn merged 2 commits intomainfrom
feature/loop-improvements

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Jan 12, 2026

Summary

  • Migrate loop state directory from .claude/ to .agent/loop-state/ (BREAKING CHANGE)
  • Add backward compatibility to check both old and new locations during transition
  • Enhance loop_generate_reanchor() with single-task extraction (Loom's "pin" concept)
  • Add Linkage section to plans-template.md for spec-as-lookup-table pattern

Changes

State Directory Migration

  • .claude/.agent/loop-state/ aligns with our framework conventions
  • All loop scripts updated: loop-common.sh, ralph-loop-helper.sh, full-loop-helper.sh, quality-loop-helper.sh
  • Session review and worktree scripts check both locations for backward compatibility
  • .gitignore updated to include new path

Re-anchor Enhancement

  • loop_generate_reanchor() now extracts single next task from TODO.md
  • Follows Loom's "pin" concept - focus each iteration on ONE task
  • Reduces context drift in long-running loops

Plans Template

  • Added Linkage (The Pin) section for spec-as-lookup-table pattern
  • Maps concepts to files, line numbers, and synonyms

Breaking Change

Loop state files moved from .claude/ to .agent/loop-state/. Existing loops will continue to work due to backward compatibility checks, but new loops will use the new location.

Testing

  • ShellCheck passes on all modified scripts
  • Preflight checks pass (only pre-existing issues flagged)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added guardrails system to prevent repeated mistakes during task iterations.
    • Enhanced iteration tracking with single-task focus emphasis.
  • Improvements

    • Added warnings when approaching attempt limits to help identify challenging tasks early.
    • Improved loop documentation with clearer emphasis on context management and iteration philosophy.
  • Documentation

    • Added "Linkage" reference section to planning templates for better concept and file organization.

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

BREAKING CHANGE: Loop state files moved from .claude/ to .agent/loop-state/

- Migrate state directory from .claude/ to .agent/loop-state/
- Add backward compatibility to check both old and new locations
- Enhance loop_generate_reanchor() with single-task extraction (Loom's pin concept)
- Add Linkage section to plans-template.md for spec-as-lookup-table pattern
- Update all documentation to reflect new paths
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 12, 2026

Walkthrough

Migration of loop state storage from .claude/ to .agent/loop-state/ with backward compatibility support across all loop helpers. Introduces new guardrails generation and gutter detection features. Updates documentation and templates to reflect new state paths and enhanced loop philosophy.

Changes

Cohort / File(s) Summary
State Directory Migration
.agent/scripts/full-loop-helper.sh, .agent/scripts/quality-loop-helper.sh, .agent/scripts/ralph-loop-helper.sh, .agent/scripts/loop-common.sh
Migrates state storage from .claude/ to .agent/loop-state/. Adds LEGACY_STATE_DIR and fallback variables for backward compatibility. Enhanced resume/cancel logic to check both new and legacy paths.
State Path Documentation Updates
.agent/scripts/commands/full-loop.md, .agent/scripts/commands/postflight-loop.md, .agent/scripts/generate-opencode-commands.sh
Updates state-tracking path references from .claude/ to .agent/loop-state/ in step descriptions and cancellation messages.
Session & Worktree State Lookup
.agent/scripts/session-review-helper.sh, .agent/scripts/worktree-sessions.sh
Implements dual-location lookup logic: prioritizes new .agent/loop-state/ path with fallback to legacy .claude/ path for ralph loop status detection.
New Loop Features
.agent/scripts/loop-common.sh
Introduces loop_generate_guardrails() function to derive actionable signs from recent failures. Enhances loop_generate_reanchor() with single-task focus and guardrails integration. Adds gutter detection in loop_should_block() with 80% attempt threshold warnings.
Workflow & Template Documentation
.agent/workflows/ralph-loop.md, .agent/workflows/session-review.md, .agent/templates/plans-template.md
Restructures ralph-loop philosophy sections with emphasis on context pollution prevention and guardrails. Adds "Linkage (The Pin)" documentation feature to plans template. Updates all state file references to new path.
Version Control
.gitignore
Adds .agent/loop-state/ directory to ignore rules with clarifying comment for per-worktree loop state files.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🏗️ State files find their new home, organized and neat,
From .claude to .agent/loop-state—a migration complete,
Guardrails born from failures, gutter warnings stand tall,
Legacy paths remembered, backward compatible through it all! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the two main objectives: migrating loop state to .agent/loop-state and enhancing the re-anchor function with single-task focus and guardrails.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 refactors the internal state management for agent loops by moving state files to a new, more conventional directory structure. It also introduces a significant enhancement to the re-anchoring mechanism, guiding the agent to focus on a single, specific task per iteration, thereby improving efficiency and reducing context loss. Additionally, it integrates a new pattern for linking documentation to code, which is designed to enhance AI's ability to accurately reference relevant information.

Highlights

  • Loop State Directory Migration: The loop state directory has been migrated from .claude/ to .agent/loop-state/ to align with framework conventions. This is a breaking change, but backward compatibility has been added to check both old and new locations during the transition.
  • Re-anchor Enhancement for Single-Task Focus: The loop_generate_reanchor() function has been enhanced to extract a single next task from TODO.md, following Loom's 'pin' concept. This aims to focus each iteration on one task, reducing context drift in long-running loops.
  • Plans Template Update: A new 'Linkage (The Pin)' section has been added to plans-template.md. This section promotes a 'spec-as-lookup-table' pattern, mapping concepts to files, line numbers, and synonyms to improve AI search hit-rate and reduce hallucinations.
  • Backward Compatibility and Cleanup: All relevant loop scripts and documentation have been updated to reflect the new state directory. Backward compatibility checks are implemented in scripts like full-loop-helper.sh, ralph-loop-helper.sh, session-review-helper.sh, and worktree-sessions.sh to ensure a smooth transition. The .gitignore file has also been updated to include the new state directory.
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.

@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 15:55:02 UTC 2026: Code review monitoring started
Mon Jan 12 15:55:02 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 256
Mon Jan 12 15:55:02 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Mon Jan 12 15:55:04 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

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

Generated on: Mon Jan 12 15:55:44 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 successfully migrates the loop state directory from .claude/ to the more conventional .agent/loop-state/, a good move for framework alignment. The inclusion of backward compatibility checks is thoughtful and ensures a smooth transition for existing loops. The enhancement to loop_generate_reanchor() to focus on a single task is a great improvement for reducing context drift in long-running operations.

My review focuses on improving code clarity and reducing duplication. I've noticed that the logic for finding the correct state file (checking new and legacy paths) is repeated across several shell scripts. While the implementation is correct, it can be hard to read and maintain. I've suggested refactoring these blocks to use more standard control structures for better readability and recommended centralizing this logic into a common helper function to reduce code duplication.

Comment on lines +612 to +615
[[ -f "$v2_state" ]] && active_v2_state="$v2_state"
[[ -z "$active_v2_state" && -f "$v2_state_legacy" ]] && active_v2_state="$v2_state_legacy"
[[ -f "$legacy_state" ]] && active_legacy_state="$legacy_state"
[[ -z "$active_legacy_state" && -f "$legacy_state_old" ]] && active_legacy_state="$legacy_state_old"

Choose a reason for hiding this comment

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

medium

This logic to determine the active state file is a bit difficult to read due to the chained logical operators. Using a standard if/elif structure would improve readability and maintainability.

Additionally, this pattern of finding the correct state file by checking multiple locations is repeated in check_other_loops within this file, and also in session-review-helper.sh and worktree-sessions.sh. To avoid code duplication, consider creating a shared helper function in loop-common.sh that can be used across all these scripts.

Suggested change
[[ -f "$v2_state" ]] && active_v2_state="$v2_state"
[[ -z "$active_v2_state" && -f "$v2_state_legacy" ]] && active_v2_state="$v2_state_legacy"
[[ -f "$legacy_state" ]] && active_legacy_state="$legacy_state"
[[ -z "$active_legacy_state" && -f "$legacy_state_old" ]] && active_legacy_state="$legacy_state_old"
if [[ -f "$v2_state" ]]; then
active_v2_state="$v2_state"
elif [[ -f "$v2_state_legacy" ]]; then
active_v2_state="$v2_state_legacy"
fi
if [[ -f "$legacy_state" ]]; then
active_legacy_state="$legacy_state"
elif [[ -f "$legacy_state_old" ]]; then
active_legacy_state="$legacy_state_old"
fi

Comment on lines 671 to 679
if [[ -f "$v2_state" ]]; then
iteration=$(jq -r '.iteration // 0' "$v2_state" 2>/dev/null || echo "?")
elif [[ -f "$v2_state_legacy" ]]; then
iteration=$(jq -r '.iteration // 0' "$v2_state_legacy" 2>/dev/null || echo "?")
elif [[ -f "$legacy_state" ]]; then
iteration=$(grep '^iteration:' "$legacy_state" | sed 's/iteration: *//')
elif [[ -f "$legacy_state_old" ]]; then
iteration=$(grep '^iteration:' "$legacy_state_old" | sed 's/iteration: *//')
fi

Choose a reason for hiding this comment

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

medium

This long if/elif chain for finding the iteration number can be made more structured and readable by using loops to iterate through the possible state file locations. This approach is also more scalable if more legacy paths need to be checked in the future.

Suggested change
if [[ -f "$v2_state" ]]; then
iteration=$(jq -r '.iteration // 0' "$v2_state" 2>/dev/null || echo "?")
elif [[ -f "$v2_state_legacy" ]]; then
iteration=$(jq -r '.iteration // 0' "$v2_state_legacy" 2>/dev/null || echo "?")
elif [[ -f "$legacy_state" ]]; then
iteration=$(grep '^iteration:' "$legacy_state" | sed 's/iteration: *//')
elif [[ -f "$legacy_state_old" ]]; then
iteration=$(grep '^iteration:' "$legacy_state_old" | sed 's/iteration: *//')
fi
for f in "$v2_state" "$v2_state_legacy"; do
if [[ -f "$f" ]]; then
iteration=$(jq -r '.iteration // 0' "$f" 2>/dev/null || echo "?")
break
fi
done
if [[ "$iteration" == "?" ]]; then
for f in "$legacy_state" "$legacy_state_old"; do
if [[ -f "$f" ]]; then
iteration=$(grep '^iteration:' "$f" | sed 's/iteration: *//')
break
fi
done
fi

Comment on lines +97 to +98
[[ -f "$ralph_file" ]] && active_file="$ralph_file"
[[ -z "$active_file" && -f "$ralph_file_legacy" ]] && active_file="$ralph_file_legacy"

Choose a reason for hiding this comment

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

medium

This logic to determine the active state file uses chained logical operators which can be hard to read. A standard if/elif structure would be more explicit and improve readability. This logic is also duplicated in other scripts; consider creating a common helper function to centralize it.

Suggested change
[[ -f "$ralph_file" ]] && active_file="$ralph_file"
[[ -z "$active_file" && -f "$ralph_file_legacy" ]] && active_file="$ralph_file_legacy"
if [[ -f "$ralph_file" ]]; then
active_file="$ralph_file"
elif [[ -f "$ralph_file_legacy" ]]; then
active_file="$ralph_file_legacy"
fi

Comment on lines +110 to +111
[[ -f "$state_file" ]] && active_file="$state_file"
[[ -z "$active_file" && -f "$state_file_legacy" ]] && active_file="$state_file_legacy"

Choose a reason for hiding this comment

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

medium

This logic to determine the active state file uses chained logical operators which can be hard to read. A standard if/elif structure would be more explicit and improve readability. This logic is also duplicated in other scripts; consider creating a common helper function to centralize it.

Suggested change
[[ -f "$state_file" ]] && active_file="$state_file"
[[ -z "$active_file" && -f "$state_file_legacy" ]] && active_file="$state_file_legacy"
if [[ -f "$state_file" ]]; then
active_file="$state_file"
elif [[ -f "$state_file_legacy" ]]; then
active_file="$state_file_legacy"
fi

@augmentcode
Copy link

augmentcode bot commented Jan 12, 2026

🤖 Augment PR Summary

Summary: Migrates loop state storage from .claude/ to .agent/loop-state/ and updates loop tooling/docs to match.

Changes:

  • Switched default state paths in loop helpers and docs; .gitignore now excludes .agent/loop-state/.
  • Added backward-compatible checks so session/worktree tooling can detect state in both new and legacy locations.
  • Enhanced loop_generate_reanchor() to extract a single “pin” task from TODO.md to reduce iteration drift.
  • Extended full loop cancellation/resume logic to account for the new state directory (during the migration window).
  • Updated plans-template.md with a “Linkage (The Pin)” section to map concepts to files/lines/synonyms for better AI lookup.

Technical Notes: This is a breaking path change, but the scripts attempt a transition period by checking both directories when reading existing 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. 3 suggestions posted.

Fix All in Augment

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

if [[ -f "TODO.md" ]]; then
# Get first unchecked task from In Progress section, or first from Backlog
next_task=$(awk '
/^## In Progress/,/^##/ { if (/^- \[ \]/) { print; exit } }
Copy link

Choose a reason for hiding this comment

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

The awk range /^## In Progress/,/^##/ (and Backlog) will terminate on the same header line because ^## matches ## In Progress, so it likely never scans the section body and next_task stays empty.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

# Check if task is complete
if [[ -f ".claude/ralph-loop.local.md" ]]; then
# 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
Copy link

Choose a reason for hiding this comment

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

cmd_resume checks only for the legacy Ralph state files (ralph-loop.local.md), but run_task_phase can run Ralph in v2 mode which writes loop-state.json; this can allow the full loop to advance to preflight while a v2 task loop is still active.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎


# Also cancel any sub-loops
# Also cancel any sub-loops (both new and legacy locations)
rm -f ".agent/loop-state/ralph-loop.local.md" 2>/dev/null
Copy link

Choose a reason for hiding this comment

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

Related: cmd_cancel only deletes legacy .local.md sub-loop state files; if the task phase ran in v2, the v2 state (e.g., loop-state.json / re-anchor.md) may remain and still look “active”.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

- Add loop_generate_guardrails() to transform failures into actionable signs
- Include guardrails section in re-anchor prompt (limited to 5 most recent)
- Enhance loop_should_block() with gutter warning at 80% threshold
- Update ralph-loop.md with Agrim Singh's philosophical framing:
  - Context pollution prevention (why fresh sessions matter)
  - Progress persists, failures don't (externalize state)
  - Guardrails: same mistake never happens twice

Based on analysis from @agrimsingh's 'ralph for idiots' explanation.
@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 16:52:59 UTC 2026: Code review monitoring started
Mon Jan 12 16:53:00 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 256
Mon Jan 12 16:53:00 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Mon Jan 12 16:53:02 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

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

Generated on: Mon Jan 12 16:53:40 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
.agent/scripts/full-loop-helper.sh (1)

43-49: Consider removing or using LEGACY_STATE_FILE.

The static analysis correctly identifies that LEGACY_STATE_FILE is defined but never used. The rm commands on lines 647-648 use hardcoded paths instead. Either use the constant or remove it to eliminate dead code.

♻️ Option 1: Use the constant
-    rm -f ".claude/ralph-loop.local.md" 2>/dev/null
-    rm -f ".claude/quality-loop.local.md" 2>/dev/null
+    rm -f "$LEGACY_STATE_FILE" 2>/dev/null
+    rm -f "${LEGACY_STATE_DIR}/ralph-loop.local.md" 2>/dev/null
+    rm -f "${LEGACY_STATE_DIR}/quality-loop.local.md" 2>/dev/null
♻️ Option 2: Remove unused constant
 # Legacy state directory (for backward compatibility during migration)
-# shellcheck disable=SC2034  # Defined for documentation, used in cancel checks
 readonly LEGACY_STATE_DIR=".claude"
-readonly LEGACY_STATE_FILE="${LEGACY_STATE_DIR}/full-loop.local.md"
.agent/scripts/worktree-sessions.sh (1)

118-120: Consider removing unused started_at extraction.

The started_at variable is extracted on line 120 but never used in the function's output (lines 122-126). This appears to be dead code.

♻️ Suggested cleanup
         iteration=$(grep '^iteration:' "$active_file" 2>/dev/null | sed 's/iteration: *//')
         max_iterations=$(grep '^max_iterations:' "$active_file" 2>/dev/null | sed 's/max_iterations: *//')
-        started_at=$(grep '^started_at:' "$active_file" 2>/dev/null | sed 's/started_at: *//' | sed 's/^"\(.*\)"$/\1/')
.agent/scripts/quality-loop-helper.sh (2)

267-271: Temp file not cleaned up on sed failure.

If sed fails (e.g., invalid regex or disk full), the script exits due to set -e but leaves the temp file orphaned. Consider adding error handling or using a trap for cleanup.

🛠️ Suggested improvement
 update_state() {
     local field="$1"
     local value="$2"
     
     if [[ ! -f "$STATE_FILE" ]]; then
         return 1
     fi
     
     local temp_file="${STATE_FILE}.tmp.$$"
-    sed "s/^${field}: .*/${field}: ${value}/" "$STATE_FILE" > "$temp_file"
-    mv "$temp_file" "$STATE_FILE"
+    if sed "s/^${field}: .*/${field}: ${value}/" "$STATE_FILE" > "$temp_file"; then
+        mv "$temp_file" "$STATE_FILE"
+    else
+        rm -f "$temp_file"
+        print_error "Failed to update state field: $field"
+        return 1
+    fi
     return 0
 }

231-231: Outdated comment references old state path.

The side-effect documentation still mentions .claude/quality-loop.local.md but the actual path is now ${STATE_DIR}/quality-loop.local.md (.agent/loop-state/quality-loop.local.md).

📝 Suggested fix
-# Side effects: Creates .claude/quality-loop.local.md
+# Side effects: Creates ${STATE_DIR}/quality-loop.local.md
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87df987 and e819d7e.

📒 Files selected for processing (13)
  • .agent/scripts/commands/full-loop.md
  • .agent/scripts/commands/postflight-loop.md
  • .agent/scripts/full-loop-helper.sh
  • .agent/scripts/generate-opencode-commands.sh
  • .agent/scripts/loop-common.sh
  • .agent/scripts/quality-loop-helper.sh
  • .agent/scripts/ralph-loop-helper.sh
  • .agent/scripts/session-review-helper.sh
  • .agent/scripts/worktree-sessions.sh
  • .agent/templates/plans-template.md
  • .agent/workflows/ralph-loop.md
  • .agent/workflows/session-review.md
  • .gitignore
🧰 Additional context used
📓 Path-based instructions (1)
.agent/scripts/*.sh

⚙️ CodeRabbit configuration file

.agent/scripts/*.sh: Automation scripts - focus on:

  • Reliability and robustness
  • Clear logging and feedback
  • Proper exit codes
  • Error recovery mechanisms

Files:

  • .agent/scripts/quality-loop-helper.sh
  • .agent/scripts/worktree-sessions.sh
  • .agent/scripts/generate-opencode-commands.sh
  • .agent/scripts/session-review-helper.sh
  • .agent/scripts/full-loop-helper.sh
  • .agent/scripts/ralph-loop-helper.sh
  • .agent/scripts/loop-common.sh
🧠 Learnings (3)
📚 Learning: 2026-01-06T15:57:56.007Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.007Z
Learning: Applies to **/.agent/scripts/linters-local.sh : Run quality checks before committing using .agent/scripts/linters-local.sh

Applied to files:

  • .agent/scripts/quality-loop-helper.sh
  • .agent/workflows/session-review.md
📚 Learning: 2025-12-22T01:24:53.937Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Follow all security protocols and working directory specifications defined in ~/Git/aidevops/AGENTS.md

Applied to files:

  • .agent/scripts/quality-loop-helper.sh
  • .agent/scripts/full-loop-helper.sh
  • .agent/workflows/ralph-loop.md
📚 Learning: 2025-12-22T01:24:53.937Z
Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Use only the specified working directories: ~/.aidevops/.agent-workspace/work/[project]/ for work files, ~/.aidevops/.agent-workspace/tmp/ for temporary files, and ~/.aidevops/.agent-workspace/memory/ for persistent memory

Applied to files:

  • .agent/scripts/quality-loop-helper.sh
  • .gitignore
  • .agent/scripts/full-loop-helper.sh
🪛 GitHub Check: Codacy Static Code Analysis
.agent/scripts/full-loop-helper.sh

[warning] 49-49: .agent/scripts/full-loop-helper.sh#L49
LEGACY_STATE_FILE appears unused. Verify use (or export if used externally).

🪛 LanguageTool
.agent/templates/plans-template.md

[grammar] ~39-~39: Ensure spelling is correct
Context: ...te with synonyms - Points to exact file hunks for context - Prevents AI from inventin...

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (30)
.agent/templates/plans-template.md (3)

22-22: LGTM! Clear and concise format addition.

The Linkage item is well-integrated into the format list and appropriately cross-references the detailed section below.


28-41: Excellent addition for reducing AI hallucination and improving search accuracy.

The Linkage section provides a clear, actionable pattern for maintaining explicit file:line anchors. The table format is intuitive, and the benefits are well-articulated. This aligns perfectly with the goal of reducing context drift in iterative loops.

Note: The static analysis tool flagged "inventin" on line 39, but this is a false positive—the actual word "inventing" is correctly spelled.


83-88: LGTM! Template section is well-structured.

The Linkage section in the template provides clear example placeholders that guide users on how to populate the lookup table. The consistency between the documentation and template ensures the pattern will be properly adopted.

.gitignore (1)

187-189: LGTM! Clean migration of loop state ignore rule.

The new .agent/loop-state/ ignore rule is correctly formatted and properly documented. The old .claude/ path (line 182) remains ignored for backward compatibility during the transition, which aligns with the PR's migration strategy.

.agent/scripts/commands/full-loop.md (1)

66-66: LGTM!

Documentation correctly updated to reflect the new state-tracking path .agent/loop-state/full-loop.local.md, consistent with the migration objective.

.agent/scripts/commands/postflight-loop.md (1)

74-74: LGTM!

Documentation properly updated to the new state-tracking path .agent/loop-state/quality-loop.local.md.

.agent/scripts/generate-opencode-commands.sh (1)

1138-1138: LGTM!

Generated command documentation correctly references the new state file location .agent/loop-state/ralph-loop.local.md.

.agent/workflows/session-review.md (1)

73-75: LGTM!

Dual-location compatibility is well-implemented with the location-first approach: new path .agent/loop-state/ralph-loop.local.md is checked before falling back to legacy .claude/ralph-loop.local.md. Comment clearly documents the intent.

.agent/scripts/ralph-loop-helper.sh (3)

45-52: LGTM!

State directory constants are well-defined with proper readonly declarations. The shellcheck disable=SC2034 is appropriate since RALPH_LEGACY_STATE_FILE is documented for use by sourcing scripts during the transition period.


588-629: Thorough dual-location compatibility in status display.

The four-way state file detection covers all migration scenarios well. The preference order (new v2 → legacy v2 → new legacy → old legacy) ensures smooth transition while preserving backward compatibility.


660-679: LGTM!

Dual-location detection in check_other_loops is consistent with show_status_all. The cascading fallback logic correctly handles all four state file variants.

.agent/scripts/loop-common.sh (4)

26-33: LGTM!

State directory constants properly migrated with the legacy path preserved for backward compatibility. The SC2034 disable is appropriate for the exported constant.


257-302: Well-designed guardrails system with robust error handling.

The function gracefully handles missing memory helper, empty results, and parse errors. The jq transformation with // fallbacks ensures resilience. Good defensive coding pattern for an automation script.


338-352: Good implementation of the "pin" concept.

The single-task extraction from TODO.md using awk is clean and correctly prioritizes In Progress over Backlog. The 2>/dev/null ensures graceful handling of malformed files.


624-631: Helpful gutter detection with actionable guidance.

The 80% warning threshold provides early indication before blocking. The suggestions (different approach, smaller scope, human review) give users clear options when iteration isn't converging.

.agent/scripts/full-loop-helper.sh (2)

563-567: LGTM!

Dual-location check in cmd_resume correctly handles the transition period by checking both new and legacy Ralph loop state files before proceeding.


644-648: LGTM!

Comprehensive cleanup removes state files from both new and legacy locations. The 2>/dev/null appropriately suppresses errors for non-existent files.

.agent/scripts/session-review-helper.sh (1)

92-108: LGTM! Clean dual-location fallback implementation.

The backward compatibility logic correctly prioritizes the new .agent/loop-state/ path while gracefully falling back to the legacy .claude/ location. The pattern of using an active_file intermediate variable makes the intent clear and keeps the subsequent reads DRY.

Minor observation: The || echo "0" and || echo "unlimited" fallbacks on lines 102-103 provide sensible defaults if the grep fails, maintaining robustness.

.agent/scripts/worktree-sessions.sh (1)

105-130: LGTM! Consistent dual-location pattern with session-review-helper.sh.

The implementation mirrors the approach in session-review-helper.sh, maintaining consistency across the codebase. The logic correctly checks the new location first, then falls back to legacy.

.agent/workflows/ralph-loop.md (4)

162-174: LGTM! State file documentation updated correctly.

The documentation now correctly references the new .agent/loop-state/ralph-loop.local.md path, aligning with the script changes across the PR.


315-362: Excellent documentation of the guardrails philosophy.

The new sections on Context Pollution Prevention (lines 315-331), Progress Persistence (lines 333-343), and Guardrails (lines 345-362) provide valuable insight into why Ralph works the way it does. The table comparing context vs files/git is particularly effective at conveying the core insight.

The guardrail example clearly demonstrates the append-only lesson pattern, which should help users understand and extend the system.


404-413: LGTM! Monitoring commands updated consistently.

All three monitoring examples now reference the new .agent/loop-state/ path. This is the correct approach for documentation - guide users toward the canonical new location while scripts handle backward compatibility internally.


694-706: LGTM! Full loop state management paths updated.

The state management documentation for the full development loop correctly references .agent/loop-state/full-loop.local.md, maintaining consistency with the Ralph loop state path migration.

.agent/scripts/quality-loop-helper.sh (7)

676-689: LGTM — Cross-platform date parsing with sensible fallbacks.

The dual-path approach (macOS date -j -f with Linux date -d fallback) and the final || echo "0" fallback ensures robust handling across platforms without breaking the loop on parse failures. Well implemented.


44-44: LGTM — Stale threshold constant well-integrated.

The DEFAULT_REVIEW_STALE_THRESHOLD is properly defined and used as the default parameter in check_and_trigger_review(). The 5-minute threshold is reasonable for detecting stale CodeRabbit reviews after a push.


412-424: LGTM — Secretlint integration looks correct.

The quoted glob pattern "**/*" is passed directly to secretlint which handles glob expansion internally. The error suppression with 2>/dev/null and graceful skip when not installed follows good defensive patterns.


34-35: LGTM — State directory migration implemented cleanly.

The migration from .claude to .agent/loop-state is straightforward and STATE_FILE correctly derives from the new STATE_DIR. This aligns with the PR's stated breaking change.


933-944: LGTM — Duration parsing is user-friendly with clear fallback behavior.

The regex-based parsing of Nm, Nh, Ns, and raw seconds with a helpful warning for unrecognized formats demonstrates good UX. Continuing with the default rather than failing is appropriate for a monitoring utility.


296-308: LGTM — Iteration increment handles edge cases correctly.

The numeric validation with regex ^[0-9]+$ and fallback to 0 ensures robustness when state is corrupted or missing. Clean implementation.


37-40: Remove unused LEGACY_STATE_DIR constant — it's defined but never referenced in this script.

The LEGACY_STATE_DIR constant is marked with a shellcheck disable for documentation purposes, but unlike full-loop-helper.sh and ralph-loop-helper.sh, this script doesn't implement backward compatibility checks. Functions like create_state(), get_state_field(), and show_status() don't attempt to read from the legacy .claude/quality-loop.local.md location. Either implement the fallback checks to use this constant, or remove it to reduce confusion.

Likely an incorrect or invalid review comment.

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