Skip to content

Fix AGENTS.md patch replacing CLAUDE.md content instead of falling back#579

Merged
bl-ue merged 3 commits intoPiebald-AI:mainfrom
TyceHerrman:fix/agents-md-with-claude-md-present
Mar 4, 2026
Merged

Fix AGENTS.md patch replacing CLAUDE.md content instead of falling back#579
bl-ue merged 3 commits intoPiebald-AI:mainfrom
TyceHerrman:fix/agents-md-with-claude-md-present

Conversation

@TyceHerrman
Copy link
Copy Markdown
Contributor

@TyceHerrman TyceHerrman commented Mar 4, 2026

Summary

  • The agentsMd patch injected fallback logic at the wrong location — before return { content }, which runs after CLAUDE.md is successfully read, unconditionally replacing its content with AGENTS.md
  • Moved injection to the early return null (after existsSync/statSync check) so alternatives are only tried when CLAUDE.md doesn't exist
  • Added 7 unit tests covering fallback behavior, CLAUDE.md preservation, recursion guard, and error cases

Test plan

  • pnpm build passes (no type errors)
  • pnpm test passes (169 tests, including 7 new ones)
  • Manual: apply tweakcc to a Claude Code installation, verify that in a project with both CLAUDE.md and AGENTS.md, the CLAUDE.md content is used (not replaced)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing configuration files with automatic fallback to alternative file names.
  • Tests

    • Added comprehensive test coverage for file routing and fallback logic.

TyceHerrman and others added 3 commits February 11, 2026 10:37
actual minified code in CC is ensureServerStarted:$,sendRequest:H
The injection was at the wrong location — before `return { content }`,
which runs after CLAUDE.md is successfully read, unconditionally replacing
its content with AGENTS.md. Moved injection to the early `return null`
(after existsSync/statSync check) so alternatives are only tried when
CLAUDE.md doesn't exist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

This PR adds a comprehensive test suite for the agentsMd module and refactors its routing logic. The implementation introduces a didReroute parameter to handle fallback paths when CLAUDE.md is unavailable, checking alternative filenames (AGENTS.md, GEMINI.md, QWEN.md) and rerouting accordingly before returning null.

Changes

Cohort / File(s) Summary
Test Suite
src/patches/agentsMd.test.ts
New test suite verifying writeAgentsMd behavior including early fallback handling, CLAUDE.md preservation, didReroute propagation, null returns, function signature changes, and filesystem checks.
Core Implementation
src/patches/agentsMd.ts
Refactored routing logic to move alternative-name fallback to early-exit path; added didReroute parameter to function signature; updated injection point from final return to early return null; adjusted matching patterns and error messages; reworked fallback construction logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • bl-ue

Poem

🐰 A rabbit hops through fallback paths so true,
When CLAUDE's gone, we know just what to do—
Check AGENTS, GEMINI, QWEN in the fray,
didReroute guides us on our way!

🚥 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 clearly and specifically describes the main fix: correcting the AGENTS.md patch behavior to fall back rather than replace CLAUDE.md content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (3)
src/patches/agentsMd.ts (2)

107-107: Use the intermediate buffer as showDiff’s old content in step 2.

Passing file again in the second showDiff mixes step 1 + step 2 changes and
can offset context around the replacement site.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/agentsMd.ts` at line 107, The second call to showDiff currently
reuses `file` as the "old" content which mixes step-1 and step-2 changes;
replace the first-steps result with the intermediate buffer (the variable
holding the file content after step 1 — e.g., `newFile` or the actual
intermediate buffer name used in this scope) as the oldContent argument when
calling showDiff(file, newFile, newStr, earlyReturnStart, earlyReturnStart) so
the second diff shows only step-2 changes; update the second invocation of
showDiff to pass that intermediate buffer instead of `file` (refer to the
showDiff call and the intermediate buffer/newFile variable in this file).

78-84: Remove the inline “Step” comments to match repository TS rules.

The function body is clear without these comments, and the added comments violate
the repo convention for TS/JS files.

As per coding guidelines, “Do not add comments unless explicitly requested.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/agentsMd.ts` around lines 78 - 84, Remove the inline "Step"
comments added in this patch: delete the comment lines starting with "// Step 1:
Add didReroute parameter to function signature" and "// Step 2: Inject fallback
at the early return null (when file doesn't exist)" so only the actual code
mutations remain (the insertion of ',didReroute' via sigIndex/newFile and the
showDiff call); ensure no other inline "Step" comments remain in the same block
around the symbols sigIndex, newFile, file.slice, or showDiff so the file
conforms to the repository TS/JS comment policy.
src/patches/agentsMd.test.ts (1)

44-47: Test title is misleading for what this assertion actually validates.

This test currently checks that generated code contains a return null branch,
not runtime behavior when no alternatives are found.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/agentsMd.test.ts` around lines 44 - 47, The test title is
misleading: the spec for writeAgentsMd(mockFunction, altNames) is asserting
generated source contains a "return null" branch, not actual runtime behavior.
Update the test either by renaming it to something like "should generate code
with a return null branch when no alternatives are found" to reflect the
string/assertion, or change the assertion to execute the generated function and
assert it returns null at runtime (invoke the code produced by writeAgentsMd and
call the resulting function); reference writeAgentsMd and the existing
mockFunction/altNames symbols when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/patches/agentsMd.test.ts`:
- Around line 44-47: The test title is misleading: the spec for
writeAgentsMd(mockFunction, altNames) is asserting generated source contains a
"return null" branch, not actual runtime behavior. Update the test either by
renaming it to something like "should generate code with a return null branch
when no alternatives are found" to reflect the string/assertion, or change the
assertion to execute the generated function and assert it returns null at
runtime (invoke the code produced by writeAgentsMd and call the resulting
function); reference writeAgentsMd and the existing mockFunction/altNames
symbols when making the change.

In `@src/patches/agentsMd.ts`:
- Line 107: The second call to showDiff currently reuses `file` as the "old"
content which mixes step-1 and step-2 changes; replace the first-steps result
with the intermediate buffer (the variable holding the file content after step 1
— e.g., `newFile` or the actual intermediate buffer name used in this scope) as
the oldContent argument when calling showDiff(file, newFile, newStr,
earlyReturnStart, earlyReturnStart) so the second diff shows only step-2
changes; update the second invocation of showDiff to pass that intermediate
buffer instead of `file` (refer to the showDiff call and the intermediate
buffer/newFile variable in this file).
- Around line 78-84: Remove the inline "Step" comments added in this patch:
delete the comment lines starting with "// Step 1: Add didReroute parameter to
function signature" and "// Step 2: Inject fallback at the early return null
(when file doesn't exist)" so only the actual code mutations remain (the
insertion of ',didReroute' via sigIndex/newFile and the showDiff call); ensure
no other inline "Step" comments remain in the same block around the symbols
sigIndex, newFile, file.slice, or showDiff so the file conforms to the
repository TS/JS comment policy.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3cea938 and dd71619.

📒 Files selected for processing (2)
  • src/patches/agentsMd.test.ts
  • src/patches/agentsMd.ts

Copy link
Copy Markdown
Member

@bl-ue bl-ue left a comment

Choose a reason for hiding this comment

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

Thank you!

@bl-ue bl-ue merged commit 2b145aa into Piebald-AI:main Mar 4, 2026
2 checks passed
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.

2 participants