-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add support for symbolic links in .roo/commands directory #7284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified scanCommandDirectory to check for both regular files and symbolic links - Added comprehensive test coverage for symbolic link functionality - Ensures symbolic links to markdown files are properly loaded as commands Fixes #7282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
src/services/command/commands.ts
Outdated
| for (const entry of entries) { | ||
| if (entry.isFile() && isMarkdownFile(entry.name)) { | ||
| // Check for both regular files and symbolic links | ||
| if ((entry.isFile() || entry.isSymbolicLink()) && isMarkdownFile(entry.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this approach intentional? I notice we're explicitly checking for symbolic links here in scanCommandDirectory, but the tryLoadCommand function (lines 54-112) doesn't have this explicit check. While fs.readFile follows symlinks automatically, this creates an inconsistency in how we handle symlinks across the codebase. Should we add a similar check in tryLoadCommand for consistency?
src/services/command/commands.ts
Outdated
| for (const entry of entries) { | ||
| if (entry.isFile() && isMarkdownFile(entry.name)) { | ||
| // Check for both regular files and symbolic links | ||
| if ((entry.isFile() || entry.isSymbolicLink()) && isMarkdownFile(entry.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security consideration: Symbolic links can point to files outside the commands directory. While this flexibility might be useful, could it potentially allow access to sensitive files if a malicious symlink is placed in the commands directory? Should we consider validating that symlinks resolve to paths within expected boundaries?
src/services/command/commands.ts
Outdated
| for (const entry of entries) { | ||
| if (entry.isFile() && isMarkdownFile(entry.name)) { | ||
| // Check for both regular files and symbolic links | ||
| if ((entry.isFile() || entry.isSymbolicLink()) && isMarkdownFile(entry.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment here explaining that symbolic links are now supported. Something like:
| if ((entry.isFile() || entry.isSymbolicLink()) && isMarkdownFile(entry.name)) { | |
| // Check for both regular files and symbolic links to support command aliasing | |
| if ((entry.isFile() || entry.isSymbolicLink()) && isMarkdownFile(entry.name)) { |
This would help future maintainers understand the design decision.
|
|
||
| // Mock fs and path modules | ||
| vi.mock("fs/promises") | ||
| vi.mock("../../roo-config", () => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mock path here uses ../../roo-config while the existing test file frontmatter-commands.spec.ts uses ../roo-config. Should we make this consistent?
| vi.mock("../../roo-config", () => ({ | |
| vi.mock("../roo-config", () => ({ |
| }) | ||
| }) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! This test suite thoroughly covers the symbolic link functionality including edge cases like broken links. Consider also adding a test that explicitly verifies tryLoadCommand works with symbolic links (even though it should work via fs.readFile).
- Check if symbolic links point to files before processing - Prevent attempting to read directories as files - Add test coverage for symlinks pointing to directories
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Closing due to security concerns - symbolic links could potentially allow reading files outside the workspace without proper permission grants. This needs security review before implementation. |
This PR attempts to address Issue #7282 by adding support for symbolic links in the
.roo/commandsdirectory.Problem
Users were unable to use symbolic links to markdown files in the
.roo/commandsdirectory. When a slash command markdown file was copied as a symbolic link, Roo Code would not recognize it as a valid command.Solution
Modified the
scanCommandDirectoryfunction insrc/services/command/commands.tsto check for both regular files and symbolic links usingentry.isSymbolicLink()in addition toentry.isFile().Changes
Testing
symlink-commands.spec.tswith 5 test casesFixes #7282
Feedback and guidance are welcome!
Important
Adds support for symbolic links in
.roo/commandsby updatingscanCommandDirectoryto recognize them as valid command files, with comprehensive test coverage.scanCommandDirectoryincommands.tsnow checks for symbolic links usingentry.isSymbolicLink()in addition toentry.isFile().symlink-commands.spec.tswith 5 test cases covering various scenarios of symbolic link handling.This description was created by
for 90e983e. You can customize this summary. It will automatically update as commits are pushed.