refactor(tool): eliminate code duplication & standardize exception handling (#54, #58) 重构工具类:消除代码重复并统一异常处理 (#54, #58)#76
Merged
SunYanbox merged 2 commits intoMay 1, 2026
Conversation
- 将 _validate_mtime 和 _generate_diff 方法从 EditTool 和 WriteTool 移至基类 BaseTool,消除重复代码 - 在 BaseTool 中添加 handle_tool_exceptions 装饰器,统一处理工具方法的异常 - 使用装饰器替换所有工具类中的四段式异常处理代码: - edit_tool.py, write_tool.py, read_tool.py, read_lines_tool.py - ls_tool.py, glob_tool.py, stat_tool.py, regex_search_tool.py - exact_search_tool.py, symbol_ref_tool.py - 移除工具类中无用的导入和重复代码
- 重构优化: 清理冗余导入,将路径校验逻辑移至基类或调用方 * `symbol_ref_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `ls_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `read_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `stat_tool.py` 移除 `ToolErrorResponse`, `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `glob_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `read_lines_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `regex_search_tool.py` 移除 `PathNotFoundError`, `WorkspaceBoundaryError` 导入 * `exact_search_tool.py` 移除 `ToolErrorResponse`, `PathNotFoundError`, `WorkspaceBoundaryError` 导入 - 文档更新: 修正 docstring 标点符号规范 * `_validate_mtime` 方法注释由中文句号改为英文句点 * `handle_tool_exceptions` 装饰器注释由中文句号改为英文句点
This was
linked to
issues
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix #54
fix #58