Skip to content

Fix duplicate guidelines when using symlinked paths#634

Merged
pushpak1300 merged 3 commits intolaravel:mainfrom
damianlewis:fix/resolve-symlinked-guideline-paths
Mar 6, 2026
Merged

Fix duplicate guidelines when using symlinked paths#634
pushpak1300 merged 3 commits intolaravel:mainfrom
damianlewis:fix/resolve-symlinked-guideline-paths

Conversation

@damianlewis
Copy link
Contributor

Summary

When .ai/guidelines is a symlink (or contains symlinked files), GuidelineComposer produces duplicate guidelines in the generated output. This happens because realpath() is applied inconsistently — Symfony Finder resolves symlinks via getRealPath(), but customGuidelinePath() returns unresolved paths. The deduplication logic then fails because it compares these mismatched path strings.

This PR applies realpath() to all paths derived from customGuidelinePath() so that path comparisons and deduplication work correctly regardless of whether the guidelines directory or individual files are symlinked.

Benefit to end users: Users who symlink their .ai/guidelines directory (e.g. to an external repo shared across projects) no longer see duplicate guideline sections in their generated agent files.

Does not break existing features: realpath() is a no-op on non-symlinked paths, so behaviour is unchanged for users with regular directories. All existing tests continue to pass.

Changes

  • Resolve customGuidelinePath() before str_contains comparisons in guidelinePath() and guideline()
  • Resolve paths returned from user override detection in guidelinePath()

Test plan

  • New test: symlinked custom guidelines directory does not produce duplicates
  • New test: symlinked custom guideline file does not produce duplicates
  • Both tests fail without the fix (asserting 2 is not 1) and pass with it
  • All existing tests pass
  • Pint, PHPStan, and Rector checks pass
  • Verified fix in a real project with a symlinked .ai/guidelines directory

@pushpak1300 pushpak1300 merged commit 11686ce into laravel:main Mar 6, 2026
15 checks passed
@damianlewis damianlewis deleted the fix/resolve-symlinked-guideline-paths branch March 6, 2026 14:48
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