Skip to content

chore: implement agent-review session improvements#27

Merged
marcusquinn merged 1 commit intomainfrom
chore/agent-review-improvements
Jan 11, 2026
Merged

chore: implement agent-review session improvements#27
marcusquinn merged 1 commit intomainfrom
chore/agent-review-improvements

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Jan 11, 2026

Summary

Improvements identified from @agent-review session analysis:

  • worktree-helper.sh: Detect squash-merged branches by checking for deleted remote branches
  • pr.md: Add "Handling Contradictory AI Feedback" section
  • worktree.md: Document squash merge detection and manual cleanup
  • postflight.md: Add worktree cleanup reminder after PR merge
  • AGENTS.md: Clarify when direct-to-main is acceptable

Changes

File Change
worktree-helper.sh Enhanced cmd_clean() to detect squash merges via git show-ref
pr.md New section for handling contradictory AI reviewer feedback
worktree.md Documented squash merge detection behavior
postflight.md Added worktree cleanup reminder section
AGENTS.md Clarified option 4 (docs-only acceptable)

Problem Solved

The worktree-helper.sh clean command previously only detected traditional merges via git branch --merged. Squash merges (common in GitHub PRs) weren't detected because they create new commits. Now the script also checks if the remote branch was deleted, which reliably indicates the PR was merged.

Summary by CodeRabbit

  • Documentation

    • Updated guidance for branch selection criteria with conditional rules for documentation-only changes.
    • Added sections on worktree cleanup workflows, squash merge detection, and handling contradictory feedback in pull request processes.
  • Improvements

    • Enhanced worktree cleanup logic to detect both traditional and squash merges, with automatic local branch deletion during cleanup.

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

Improvements identified from session review:

- worktree-helper.sh: Detect squash-merged branches by checking for
  deleted remote branches (fixes cleanup not detecting squash merges)
- pr.md: Add 'Handling Contradictory AI Feedback' section with
  verification and resolution process
- worktree.md: Document squash merge detection and manual cleanup
- postflight.md: Add worktree cleanup reminder after PR merge
- AGENTS.md: Clarify when direct-to-main (option 4) is acceptable
  (docs-only changes) vs not acceptable (code changes)
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 11, 2026

Walkthrough

These changes enhance the git worktree management system by adding improved merge detection logic to the helper script and documenting new cleanup workflows. Documentation is updated to clarify conditional acceptance criteria and provide guidance on contradictory feedback handling.

Changes

Cohort / File(s) Summary
Shell Script Enhancement
.agent/scripts/worktree-helper.sh
Adds git fetch origin --prune in cmd_clean to refresh remote state. Enhances merge detection with dual-condition logic: traditional merge detection plus remote branch deletion (refs/remotes/origin/branch). Updates status output to report merge type ("merged" or "remote deleted"). Implements two-step removal decision logic with forced removal fallback and local branch deletion.
Worktree Workflow Documentation
.agent/workflows/postflight.md, .agent/workflows/worktree.md
postflight.md adds "Worktree Cleanup" section detailing cleanup after PR merges and updates Related Workflows list. worktree.md introduces "Squash Merge Detection" subsection documenting both traditional and squash merge detection, auto-prune behavior, and manual cleanup command examples.
Guidance Updates
.agent/AGENTS.md, .agent/workflows/pr.md
AGENTS.md refines option 4 ("Stay on main") wording to "docs-only acceptable, otherwise not recommended" with clarified acceptance criteria. pr.md adds "Handling Contradictory AI Feedback" section outlining detection, resolution process, and example workflows.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Git branches prune, worktrees align, 🌿
Merge detection sharp—remote or inline,
Cleanup flows clean, old refs resign,
DevOps automation reaching design! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'chore: implement agent-review session improvements' is vague and doesn't clearly reflect the specific changes made—worktree cleanup detection, documentation additions, and guidance clarification. Consider a more descriptive title that captures the main change, such as 'chore: add squash merge detection to worktree cleanup and document agent-review workflow' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 streamlines the development workflow by introducing smarter worktree management and clearer guidelines for interacting with automated review systems. The core improvement is the worktree-helper.sh script's ability to automatically identify and remove worktrees for branches that have been squash-merged, addressing a previous gap in cleanup automation. Additionally, it provides essential guidance on navigating conflicting AI feedback and clarifies policies for direct merges to the main branch, enhancing overall efficiency and consistency.

Highlights

  • Worktree Cleanup Enhancement: The worktree-helper.sh script now accurately detects and cleans up worktrees associated with squash-merged branches by checking for deleted remote branches, in addition to traditional merges.
  • AI Feedback Guidance: New documentation in pr.md provides a structured approach for detecting and resolving contradictory feedback from AI code reviewers.
  • Documentation Updates: worktree.md and postflight.md have been updated to reflect the new squash merge detection capabilities and to remind users about worktree cleanup post-PR merge.
  • Direct-to-Main Clarification: AGENTS.md now explicitly defines scenarios where direct merges to the main branch are acceptable (e.g., documentation-only changes).
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, 225 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Jan 11 00:43:43 UTC 2026: Code review monitoring started
Sun Jan 11 00:43:44 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 225
Sun Jan 11 00:43:44 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Sun Jan 11 00:43:46 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 225
  • VULNERABILITIES: 0

Generated on: Sun Jan 11 00:44:20 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@augmentcode
Copy link

augmentcode bot commented Jan 11, 2026

🤖 Augment PR Summary

Summary: This PR improves agent workflow guidance and enhances worktree cleanup to better handle GitHub’s common squash-merge pattern.

Changes:

  • Updated worktree-helper.sh clean to detect merged branches via both git branch --merged and deleted remote refs (after git fetch --prune).
  • Extended cleanup to optionally remove stale worktrees and associated local branches.
  • Added guidance in workflows/pr.md for handling contradictory AI reviewer feedback with verification and documentation.
  • Documented squash-merge detection and manual cleanup steps in workflows/worktree.md and added a post-merge reminder in workflows/postflight.md.
  • Clarified in AGENTS.md when working directly on main is acceptable (docs-only changes).

Technical Notes: Squash-merge detection relies on the remote branch being deleted (post-prune), which is typical for --delete-branch merges on GitHub.

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

Fix All in Augment

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

is_merged=true
merge_type="merged"
# Check 2: Remote branch deleted (indicates squash merge or PR closed)
elif ! git show-ref --verify --quiet "refs/remotes/origin/$worktree_branch" 2>/dev/null; then
Copy link

Choose a reason for hiding this comment

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

The “remote deleted” heuristic (git show-ref ... refs/remotes/origin/$worktree_branch) will also be true for branches that were never pushed (or repos without an origin remote), which could mark active/unmerged worktrees as merged and delete them after confirmation. Consider gating this check on the branch having an origin/<branch> (or upstream) to avoid false positives.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

git worktree remove "$worktree_path" 2>/dev/null || true
git worktree remove "$worktree_path" 2>/dev/null || git worktree remove --force "$worktree_path" 2>/dev/null || true
# Also delete the local branch
git branch -D "$worktree_branch" 2>/dev/null || true
Copy link

Choose a reason for hiding this comment

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

cmd_clean now runs git branch -D (and may worktree remove --force), which can delete the branch and potentially discard uncommitted changes—this is a behavioral shift from the prior “cleanup” semantics. It may be worth explicitly documenting this in the script/help/docs so users don’t lose work unexpectedly.

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

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 several valuable improvements, particularly enhancing the worktree-helper.sh script to detect squash-merged branches, which is a significant enhancement for workflows using that merge strategy. The accompanying documentation updates in pr.md, worktree.md, and postflight.md are clear and helpful.

My review includes a few suggestions for the worktree-helper.sh script to improve maintainability by refactoring duplicated code and simplifying a command. I also noted a small correction for the documentation in postflight.md to ensure the example command for auto-cleaning worktrees is accurate. Overall, these are solid improvements.

Comment on lines +380 to +391
local is_merged=false
local merge_type=""

# Check 1: Traditional merge detection
if git branch --merged "$default_branch" 2>/dev/null | grep -q "^\s*$worktree_branch$"; then
is_merged=true
merge_type="merged"
# Check 2: Remote branch deleted (indicates squash merge or PR closed)
elif ! git show-ref --verify --quiet "refs/remotes/origin/$worktree_branch" 2>/dev/null; then
is_merged=true
merge_type="remote deleted"
fi

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 if a worktree is ready for cleaning is duplicated in the auto-clean section around line 423. To improve maintainability and avoid the two sections diverging in the future, consider extracting this logic into a shared helper function.

For example, you could create a function that checks for both merge conditions and returns a status.

# Determines if a branch is cleanable and returns the reason.
# @param $1 branch_name
# @param $2 default_branch
# @return 0 on success (cleanable), 1 on failure.
# @output The merge type ('merged' or 'remote deleted') if cleanable.
_get_cleanable_merge_type() {
    local branch_name="$1"
    local default_branch="$2"

    if git branch --merged "$default_branch" 2>/dev/null | grep -q "^\s*${branch_name}$"; then
        echo "merged"
        return 0
    elif ! git show-ref --verify --quiet "refs/remotes/origin/${branch_name}" 2>/dev/null; then
        echo "remote deleted"
        return 0
    fi
    
    return 1
}

You could then call it in both places like this:

if merge_type=$(_get_cleanable_merge_type "$worktree_branch" "$default_branch"); then
    # ... logic for listing or removing ...
fi

This would make the code DRY (Don't Repeat Yourself).

if [[ "$should_remove" == "true" ]]; then
echo -e "${BLUE}Removing $worktree_branch...${NC}"
git worktree remove "$worktree_path" 2>/dev/null || true
git worktree remove "$worktree_path" 2>/dev/null || git worktree remove --force "$worktree_path" 2>/dev/null || true

Choose a reason for hiding this comment

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

medium

The command to remove the worktree can be simplified. git worktree remove --force will remove the worktree regardless of whether it has uncommitted changes or not, making the current chain of commands redundant. You can simplify this line to just use --force.

Suggested change
git worktree remove "$worktree_path" 2>/dev/null || git worktree remove --force "$worktree_path" 2>/dev/null || true
git worktree remove --force "$worktree_path" 2>/dev/null || true

~/.aidevops/agents/scripts/worktree-helper.sh list

# Auto-clean merged worktrees (detects squash merges too)
~/.aidevops/agents/scripts/worktree-helper.sh clean

Choose a reason for hiding this comment

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

medium

The comment # Auto-clean merged worktrees suggests a non-interactive operation, but worktree-helper.sh clean runs interactively by default. To match the comment's intent and provide a true auto-clean command, you should add the --auto-yes flag.

Suggested change
~/.aidevops/agents/scripts/worktree-helper.sh clean
~/.aidevops/agents/scripts/worktree-helper.sh clean --auto-yes

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: 2

🤖 Fix all issues with AI agents
In @.agent/workflows/pr.md:
- Around line 515-519: The markdown fenced code block after the list item "4.
**Proceed with merge**" is missing a blank line before the opening ``` and thus
violates MD031; add a blank line between the paragraph and the code fence and
ensure the fence uses the language tag (bash) and has a matching closing ``` so
the snippet `gh pr merge 123 --squash --delete-branch` is properly rendered as a
code block.
🧹 Nitpick comments (2)
.agent/scripts/worktree-helper.sh (1)

369-370: Consider adding feedback for fetch operation.

The git fetch --prune silently continues on failure, which could lead to stale remote state being used for merge detection. While the || true prevents script failure (good for robustness), users have no visibility into whether the fetch succeeded.

🔍 Optional improvement for visibility
-    # Fetch to get current remote branch state (detects deleted branches)
-    git fetch --prune origin 2>/dev/null || true
+    # Fetch to get current remote branch state (detects deleted branches)
+    echo "Fetching remote branch state..."
+    if git fetch --prune origin 2>/dev/null; then
+        echo "Remote state updated"
+    else
+        echo -e "${YELLOW}Warning: Could not fetch remote state (using local cache)${NC}"
+    fi

Based on coding guidelines emphasizing clear logging and feedback.

.agent/workflows/worktree.md (1)

325-342: Clear documentation of squash merge detection.

The new subsection accurately documents the enhanced merge detection behavior and provides practical manual cleanup commands for edge cases. The two-method approach (traditional + remote deletion) is clearly explained.

The manual cleanup examples appropriately use --force and -D flags, though you might consider adding a brief note that -D is destructive and should only be used for truly abandoned branches.

📋 Optional safety note

Consider adding a brief warning before the manual commands:

**Manual cleanup** if needed (use with caution):

```bash
# Force remove worktree (only if normal removal fails)
git worktree remove --force ~/Git/myrepo-feature-old

# Delete local branch (WARNING: -D force-deletes without checking for unmerged work)
git branch -D feature/old
</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: Path: .coderabbit.yaml

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 61ed0572da9059d2484555455b67b130c465fe51 and 39ff3833b35301c38c1c81a45128e21a6ad19642.

</details>

<details>
<summary>📒 Files selected for processing (5)</summary>

* `.agent/AGENTS.md`
* `.agent/scripts/worktree-helper.sh`
* `.agent/workflows/postflight.md`
* `.agent/workflows/pr.md`
* `.agent/workflows/worktree.md`

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>📓 Path-based instructions (1)</summary>

<details>
<summary>.agent/scripts/*.sh</summary>


**⚙️ 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/worktree-helper.sh`

</details>

</details><details>
<summary>🧠 Learnings (9)</summary>

<details>
<summary>📚 Learning: 2025-12-22T01:24:53.937Z</summary>

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/workflows/postflight.md`
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-11-29T04:34:42.033Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Reference AGENTS.md (authoritative) instead of AGENT.md for AI assistant guidance


**Applied to files:**
- `.agent/workflows/pr.md`
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-11-29T04:34:42.033Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENT.md:0-0
Timestamp: 2025-11-29T04:34:42.033Z
Learning: Maintain all AI assistant instructions, documentation, and operational guidance in AGENTS.md as the single source of truth


**Applied to files:**
- `.agent/workflows/pr.md`
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-11-29T04:34:27.158Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-29T04:34:27.158Z
Learning: All instructions, documentation, and operational guidance should be maintained in AGENTS.md as the single source of truth


**Applied to files:**
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-11-29T04:34:30.742Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-11-29T04:34:30.742Z
Learning: Maintain all instructions, documentation, and operational guidance in AGENTS.md as the single source of truth


**Applied to files:**
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2026-01-06T15:57:56.008Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.008Z
Learning: Applies to **/AGENTS.md : Limit root AGENTS.md to ~50-100 max instructions with universal applicability to >80% of tasks


**Applied to files:**
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2026-01-06T15:57:56.008Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-06T15:57:56.008Z
Learning: Applies to **/AGENTS.md : Use progressive disclosure in AGENTS.md with pointers to subagents rather than inline content


**Applied to files:**
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-11-29T04:34:30.742Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-11-29T04:34:30.742Z
Learning: Reference AGENTS.md for authoritative AI assistant guidance instead of GEMINI.md


**Applied to files:**
- `.agent/AGENTS.md`

</details>
<details>
<summary>📚 Learning: 2025-12-22T01:24:53.937Z</summary>

Learnt from: CR
Repo: marcusquinn/aidevops PR: 0
File: templates/home/AGENTS.md:0-0
Timestamp: 2025-12-22T01:24:53.937Z
Learning: Reference the authoritative repository at ~/Git/aidevops/ for all detailed AI assistant instructions and configurations


**Applied to files:**
- `.agent/AGENTS.md`

</details>

</details><details>
<summary>🪛 GitHub Check: Codacy Static Code Analysis</summary>

<details>
<summary>.agent/workflows/pr.md</summary>

[notice] 516-516: .agent/workflows/pr.md#L516
Fenced code blocks should be surrounded by blank lines

</details>

</details>
<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

<details>
<summary>.agent/workflows/pr.md</summary>

516-516: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

</details>

</details>

</details>

<details>
<summary>⏰ 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)</summary>

* GitHub Check: Codacy Static Code Analysis

</details>

<details>
<summary>🔇 Additional comments (5)</summary><blockquote>

<details>
<summary>.agent/AGENTS.md (1)</summary><blockquote>

`34-39`: **Clear documentation improvement for branch workflow.**

The explicit guidance on when direct-to-main commits are acceptable (docs-only) vs. not acceptable (code changes) helps AI assistants and developers make better decisions. This reduces the risk of accidental code commits bypassing PR review.

</blockquote></details>
<details>
<summary>.agent/scripts/worktree-helper.sh (2)</summary><blockquote>

`380-391`: **Well-structured squash merge detection logic.**

The two-condition approach correctly addresses the PR objective of detecting squash merges via remote branch deletion. The logic is clear and defensive:

1. Traditional merge detection first (authoritative)
2. Remote deletion fallback (squash merge indicator)
3. Distinct labeling for user clarity

The remote deletion check could theoretically flag force-deleted or never-merged branches, but the subsequent user confirmation prompt (`[y/N]`) provides a safety gate.

---

`395-395`: **Excellent feedback improvement.**

Displaying the specific merge detection reason (`"merged"` vs `"remote deleted"`) helps users understand why a worktree is being flagged for cleanup. This transparency aids troubleshooting and builds trust in the automation.

</blockquote></details>
<details>
<summary>.agent/workflows/postflight.md (1)</summary><blockquote>

`584-604`: **Helpful postflight workflow addition.**

The new "Worktree Cleanup" section logically extends the postflight checklist with practical cleanup guidance. The placement after success criteria is appropriate, and the cross-reference to `worktree.md` helps users find detailed documentation.

The documentation accurately reflects the enhanced detection behavior implemented in `worktree-helper.sh`.

</blockquote></details>
<details>
<summary>.agent/workflows/pr.md (1)</summary><blockquote>

`488-528`: **Pragmatic guidance for handling AI reviewer limitations.**

This section provides a balanced approach to contradictory AI feedback:
- Emphasizes verification and documentation (steps 1-3)
- Requires checking authoritative sources
- Mandates explaining decisions in PR comments
- Only suggests proceeding with merge after demonstrating correctness

The guidance correctly acknowledges that AI reviewers can be wrong while maintaining accountability through documentation requirements.

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +423 to +437
local should_remove=false

# Check 1: Traditional merge
if git branch --merged "$default_branch" 2>/dev/null | grep -q "^\s*$worktree_branch$"; then
should_remove=true
# Check 2: Remote branch deleted
elif ! git show-ref --verify --quiet "refs/remotes/origin/$worktree_branch" 2>/dev/null; then
should_remove=true
fi

if [[ "$should_remove" == "true" ]]; then
echo -e "${BLUE}Removing $worktree_branch...${NC}"
git worktree remove "$worktree_path" 2>/dev/null || true
git worktree remove "$worktree_path" 2>/dev/null || git worktree remove --force "$worktree_path" 2>/dev/null || true
# Also delete the local branch
git branch -D "$worktree_branch" 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Improve error handling and user feedback in removal logic.

The removal logic has several reliability concerns:

  1. Silent multi-level fallback (line 435): The triple-chained command with full error suppression provides no feedback about which removal method succeeded or if all failed
  2. Unconditional force delete (line 437): git branch -D destroys the local branch without checking for unmerged commits, potentially losing work
  3. Inconsistent state risk: If worktree removal fails but branch deletion succeeds, the worktree directory remains but the branch reference is lost
🛡️ Proposed fix with logging and safety checks
                 if [[ "$should_remove" == "true" ]]; then
                     echo -e "${BLUE}Removing $worktree_branch...${NC}"
-                    git worktree remove "$worktree_path" 2>/dev/null || git worktree remove --force "$worktree_path" 2>/dev/null || true
-                    # Also delete the local branch
-                    git branch -D "$worktree_branch" 2>/dev/null || true
+                    
+                    # Try normal removal first
+                    if git worktree remove "$worktree_path" 2>/dev/null; then
+                        echo "  Worktree removed"
+                    elif git worktree remove --force "$worktree_path" 2>/dev/null; then
+                        echo -e "  ${YELLOW}Worktree force-removed${NC}"
+                    else
+                        echo -e "  ${RED}Failed to remove worktree${NC}"
+                        # Skip branch deletion if worktree removal failed
+                        worktree_path=""
+                        worktree_branch=""
+                        continue
+                    fi
+                    
+                    # Delete local branch only after successful worktree removal
+                    if git branch -d "$worktree_branch" 2>/dev/null; then
+                        echo "  Local branch deleted"
+                    elif git branch -D "$worktree_branch" 2>/dev/null; then
+                        echo -e "  ${YELLOW}Local branch force-deleted${NC}"
+                    else
+                        echo -e "  ${YELLOW}Could not delete local branch${NC}"
+                    fi
                 fi

Key improvements:

  • Clear feedback at each removal step
  • Try soft delete (-d) before force delete (-D) for branches
  • Skip branch deletion if worktree removal fails (maintains consistency)
  • User can see if force removal was necessary

Based on coding guidelines emphasizing "Clear logging and feedback" and "Error recovery mechanisms".

Comment on lines +515 to +519
4. **Proceed with merge**: If feedback is demonstrably incorrect, merge despite CHANGES_REQUESTED
```bash
gh pr merge 123 --squash --delete-branch
```

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix markdown formatting for code block.

Missing blank line before the fenced code block on line 516 violates markdown formatting standards (MD031).

📝 Proposed fix
 4. **Proceed with merge**: If feedback is demonstrably incorrect, merge despite CHANGES_REQUESTED
+
    ```bash
    gh pr merge 123 --squash --delete-branch
    ```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
4. **Proceed with merge**: If feedback is demonstrably incorrect, merge despite CHANGES_REQUESTED
```bash
gh pr merge 123 --squash --delete-branch
```
4. **Proceed with merge**: If feedback is demonstrably incorrect, merge despite CHANGES_REQUESTED
🧰 Tools
🪛 GitHub Check: Codacy Static Code Analysis

[notice] 516-516: .agent/workflows/pr.md#L516
Fenced code blocks should be surrounded by blank lines

🪛 markdownlint-cli2 (0.18.1)

516-516: Fenced code blocks should be surrounded by blank lines

(MD031, blanks-around-fences)

🤖 Prompt for AI Agents
In @.agent/workflows/pr.md around lines 515 - 519, The markdown fenced code
block after the list item "4. **Proceed with merge**" is missing a blank line
before the opening ``` and thus violates MD031; add a blank line between the
paragraph and the code fence and ensure the fence uses the language tag (bash)
and has a matching closing ``` so the snippet `gh pr merge 123 --squash
--delete-branch` is properly rendered as a code block.

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