fix(core): handle nested plan files by resolving paths correctly#24854
fix(core): handle nested plan files by resolving paths correctly#24854mahimashanware merged 1 commit intoworktree-con-plan-bugfrom
Conversation
|
Hi @mahimashanware, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
🧠 Model Steering GuidanceThis PR modifies files that affect the model's behavior (prompts, tools, or instructions).
This is an automated guidance message triggered by steering logic signatures. |
f403b78 to
fd8cfad
Compare
229d2ca to
81ac743
Compare
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug that prevented the correct handling of nested plan files by misinterpreting their paths. By transitioning from Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request enhances security for the EditTool and WriteFileTool by implementing stricter path validation in 'plan mode.' It replaces path.basename with path.resolve and uses isSubpath to verify that all file operations occur within the designated plans directory. Review feedback suggests refactoring the duplicated path resolution logic into a shared utility and trimming tool parameters to ensure robust validation.
This fixes a bug where path.basename was incorrectly stripping directory structures from plan files (e.g., trying to write to plans/nested/file.md would incorrectly write to plans/file.md). By using path.resolve and verifying with isSubpath, nested files are now handled securely and correctly.
81ac743 to
7bcddc6
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a robust path resolution and validation mechanism for plan files by adding resolveAndValidatePlanPath to planUtils.ts and integrating it into the EditTool and WriteFileTool classes. It also includes a new test case to ensure nested plan directories are handled correctly. Regarding the review feedback, the catch block in validatePlanPath has been identified as overly broad; it should be updated to log the specific error for better diagnostics while maintaining the existing error handling strategy.
| } catch { | ||
| return PlanErrorMessages.PATH_ACCESS_DENIED( | ||
| planPath, | ||
| resolveToRealPath(plansDir), | ||
| ); | ||
| } |
There was a problem hiding this comment.
The catch block is overly broad, masking specific validation errors. Following repository guidelines, detailed errors should be logged for debugging instead of providing only a generic error message. Propagating the specific error message will improve diagnostics and user experience. Note that we assume configuration files are valid and avoid adding defensive code specifically for empty or whitespace-only strings.
} catch (err) {
console.error(err);
if (err instanceof Error) {
return err.message;
}
return PlanErrorMessages.PATH_ACCESS_DENIED(
planPath,
resolveToRealPath(plansDir),
);
}References
- When catching exceptions, log the detailed error for debugging instead of providing only a generic error message.
- For internally managed configuration files, such as plan.toml, assume the configuration is valid and avoid adding defensive code to handle unlikely misconfigurations like empty or whitespace-only strings.
Summary
This fixes a bug where
path.basenamewas incorrectly stripping directory structures from plan files (e.g., trying to write toplans/nested/file.mdwould incorrectly write toplans/file.md). By usingpath.resolveand verifying withisSubpath, nested files are now handled securely and correctly.Details
path.basenamelogic inedit.ts,write-file.ts, andplanUtils.tswith proper path resolution.Fixes #24975