fix(tool): built-in file tools support relative tools#747
Conversation
Summary of ChangesHello @fang-tech, 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 refines the built-in file tools to better support relative paths, particularly when operating within a restricted base directory. The changes ensure that file operations correctly interpret relative paths and maintain security by preventing unauthorized access outside the designated directory. Additionally, the documentation for skill prompts has been streamlined to provide clearer guidance on skill usage and resource access. Highlights
Changelog
Activity
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a fix to allow built-in file tools to correctly handle relative paths when a baseDir is specified. The core logic change in FileToolUtils.validatePath is sound and correctly resolves relative paths against the base directory, which is a good improvement for security and usability. The accompanying tests are comprehensive and cover various scenarios, ensuring the new logic is robust. The update to the agent skill prompt also improves clarity. Overall, this is a solid contribution. I've left one minor comment regarding a test's display name for better maintainability.
agentscope-core/src/test/java/io/agentscope/core/tool/file/WriteFileToolTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This pull request fixes the file tool utilities to properly support relative paths when a base directory is specified. Previously, relative paths were always resolved against the current working directory; now they are correctly resolved relative to the specified baseDir.
Changes:
- Modified
FileToolUtils.validatePath()to resolve relative paths relative to the baseDir when specified - Added comprehensive unit tests for the validatePath method covering relative paths, absolute paths, path traversal attacks, and various edge cases
- Added integration tests for WriteFileTool demonstrating relative path usage with baseDir
- Simplified and improved the AgentSkillPromptProvider documentation to be more concise and remove hardcoded path assumptions
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| agentscope-core/src/main/java/io/agentscope/core/tool/file/FileToolUtils.java | Core logic change: resolve relative paths relative to baseDir instead of current working directory |
| agentscope-core/src/test/java/io/agentscope/core/tool/file/FileToolUtilsTest.java | Comprehensive unit tests for validatePath method with relative and absolute paths |
| agentscope-core/src/test/java/io/agentscope/core/tool/file/WriteFileToolTest.java | Integration tests demonstrating relative path usage in writeTextFile and insertTextFile |
| agentscope-core/src/main/java/io/agentscope/core/skill/AgentSkillPromptProvider.java | Simplified skill usage documentation to remove hardcoded path assumptions |
agentscope-core/src/test/java/io/agentscope/core/tool/file/WriteFileToolTest.java
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScope-Java Version
[The version of AgentScope-Java you are working on, e.g. 1.0.8, check your pom.xml dependency version or run
mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]Description
[Please describe the background, purpose, changes made, and how to test this PR]
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)