Resolve symlinked AGENTS context files#65
Conversation
📝 WalkthroughWalkthroughUpdates workspace agent-file loading to resolve symlinks before reading content, avoid duplicate discovery by resolved path, and extend tests for symlinked and unsafe AGENTS.md setups. ChangesSymlink-aware AGENTS.md loading
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/workspaces.ts`:
- Around line 249-264: The symlink handling in loadInitialAgentsFiles() can load
files outside the workspace because it resolves the path and reads it without
verifying the target stays under root or agentDir. Add a containment check after
resolve() and before readResolvedContextFile() using the existing
isInitialAgentsFilePath() flow, and skip or safely ignore any AGENTS.md target
that resolves outside the allowed roots.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3f0c2ec3-6447-4da6-a3ed-cd62c1f3cb39
📒 Files selected for processing (2)
src/workspaces.test.tssrc/workspaces.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/workspaces.test.ts (1)
83-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider also asserting on
availableAgentsFilesfor the unsafe symlink case.The test confirms the rejected symlink's content isn't loaded into
agentsFiles, but doesn't verify whetherunsafeWorkspace.availableAgentsFilesstill surfacesunsafeAgentDir/AGENTS.mdas a discoverable entry. Since the symlink is rejected rather than loaded, it's never added toloadedRealPathsinfindAvailableAgentsFiles, so it may still appear in the discovered list. Asserting on this would close the loop on the "don't list an already-resolved symlink twice / expose stale/escaped paths" behavior described in the PR objective.assert.deepEqual( unsafeWorkspace.agentsFiles.map((file) => file.content), ["root instructions\n"], ); +assert.deepEqual( + unsafeWorkspace.availableAgentsFiles.map((file) => file.path), + [/* expected discovered paths */], +);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/workspaces.test.ts` around lines 83 - 102, The unsafe symlink test only verifies agentsFiles content, so extend it to also assert unsafeWorkspace.availableAgentsFiles for the rejected symlink case. Use WorkspaceRegistry.openWorkspace and findAvailableAgentsFiles behavior to confirm whether the symlinked AGENTS.md is still discovered or intentionally excluded, and update the expected discovered paths accordingly to cover the stale/escaped path handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/workspaces.test.ts`:
- Around line 83-102: The unsafe symlink test only verifies agentsFiles content,
so extend it to also assert unsafeWorkspace.availableAgentsFiles for the
rejected symlink case. Use WorkspaceRegistry.openWorkspace and
findAvailableAgentsFiles behavior to confirm whether the symlinked AGENTS.md is
still discovered or intentionally excluded, and update the expected discovered
paths accordingly to cover the stale/escaped path handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a2650fb7-936c-409a-8581-5039d2619042
📒 Files selected for processing (2)
src/workspaces.test.tssrc/workspaces.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/workspaces.ts
Summary
Fixes #58.
Tests
Summary by CodeRabbit
Bug Fixes
Tests