-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: enforce file restrictions for all edit tools in architect mode (#5445) #5447
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,13 +266,39 @@ export function isToolAllowedForMode( | |
| // For the edit group, check file regex if specified | ||
| if (groupName === "edit" && options.fileRegex) { | ||
| const filePath = toolParams?.path | ||
| if ( | ||
| filePath && | ||
| (toolParams.diff || toolParams.content || toolParams.operations) && | ||
| !doesFileMatchRegex(filePath, options.fileRegex) | ||
| ) { | ||
| // Check if this is an actual edit operation (not just path-only for streaming) | ||
| const isEditOperation = !!( | ||
| toolParams?.diff || | ||
| toolParams?.content || | ||
| toolParams?.operations || | ||
| toolParams?.search || | ||
| toolParams?.replace || | ||
| toolParams?.args | ||
| ) | ||
|
|
||
| // Handle single file path validation | ||
| if (filePath && isEditOperation && !doesFileMatchRegex(filePath, options.fileRegex)) { | ||
| throw new FileRestrictionError(mode.name, options.fileRegex, options.description, filePath) | ||
|
||
| } | ||
|
|
||
| // Handle XML args parameter (used by MULTI_FILE_APPLY_DIFF experiment) | ||
| if (toolParams?.args && typeof toolParams.args === "string") { | ||
| // Extract file paths from XML args | ||
| const filePathMatches = toolParams.args.match(/<path>([^<]+)<\/path>/g) | ||
| if (filePathMatches) { | ||
| for (const match of filePathMatches) { | ||
| const extractedPath = match.replace(/<\/?path>/g, "") | ||
|
||
| if (!doesFileMatchRegex(extractedPath, options.fileRegex)) { | ||
| throw new FileRestrictionError( | ||
| mode.name, | ||
| options.fileRegex, | ||
| options.description, | ||
| extractedPath, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true | ||
|
|
||
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.
For better maintainability, would it be helpful to extract these edit operation indicators into a constant? Something like:
This would make it easier to add new edit-related parameters in the future and keep the logic centralized.