Conversation
…e injection length and mitigate LLM hallucinations / 合并相似工具的参数与功能,缩短工具注入长度,降低模型幻觉 (#128) * refactor(read): 合并 read_lines 至 read 工具并支持范围读取 (#119) - 重构优化: 统一文件读取逻辑,移除冗余工具类 * 删除 `src/workspace/tools/read_lines_tool.py` 中的 `ReadLinesTool` 类及其 `read_lines` 方法 * 增强 `src/workspace/tools/read_tool.py` 中的 `ReadTool` 类,将 `read` 方法参数从 `max_lines` 变更为 `start`, `end`, `context` * 在 `ReadTool` 中新增私有函数 `_resolve_index` 用于处理负数索引和边界校验 * 更新 `ReadTool.read` 方法的返回格式,动态显示实际读取的行号范围 `[行 start-end / 共 total_lines 行]` - 破坏性变更: 废弃 `read_lines` 工具接口 * 移除 `read_lines` 工具名称注册,相关调用需迁移至 `read` 工具 * 修改 `read` 工具的 API 签名:原 `max_lines` 参数已移除,现使用 `start` (起始行), `end` (结束行, 支持负数), `context` (上下文行数) 替代 * 影响模块:`src/core/tool_registry.py` 中移除了对 `ReadLinesTool` 的导入和注册 - 文档更新: 同步工具列表与测试用例 * 更新 `README.md` 和 `README_ZH.md`,将 `read_lines` 条目合并入 `read` 的描述 * 重构 `tests/core/test_tool_registry.py` 中的分类断言,移除 `read_lines` * 重命名测试类及方法:`TestReadLinesToolMtimeRecording` -> `TestReadToolRangeRecording`, `test_read_lines_records_mtime` -> `test_read_range_records_mtime` * 更新 `tests/workspace/tools/test_binary_protection.py`,将针对 `read_lines` 的二进制保护测试迁移至 `read` 工具 * refactor(tools): 重构参数描述逻辑并精简文档 (#127) - 重构优化: 将工具参数文档生成格式从 XML 转换为 Markdown 列表 * 新增 `build_param_list_item` 函数替代原有的 `build_param_doc`,支持生成 `- **name** (type, required/optional)` 格式的列表项 * 在 `BaseTool` 类中引入 `self.param_descriptions` 字典,允许子类为每个参数提供自定义中文描述 * 更新 `to_doc` 方法逻辑,调用新函数并拼接自定义描述后缀 - 新增功能: 为所有核心工具添加详细的参数中文说明 * `symbol_ref_tool.py`: 定义 `symbol_name`, `path`, `language`, `include_definitions` 等 10 个参数的描述 * `ls_tool.py`, `git_tool.py`, `read_tool.py`, `write_tool.py`, `stat_tool.py`, `glob_tool.py`, `regex_search_tool.py`, `exact_search_tool.py`, `edit_tool.py`: 分别为各工具的输入参数添加了清晰的中文解释 - 文档更新: 移除冗余的 Docstring 注释块 * 删除了多个工具函数(如 `symbol_ref`, `ls`, `git`, `read`, `write`, `stat`, `glob`, `regex_search`, `exact_search`, `edit`)中重复的 `Args` 或 `Parameters` 段落 * 清理了不再使用的 `Returns` 部分,依赖动态生成的文档结构 - 测试维护: 同步更新单元测试以适配新的实现 * 移除对已废弃函数 `build_param_doc` 的导入和测试用例 `test_build_param_doc` * 删除针对旧 XML 输出格式的 `test_to_doc_new_format` 测试,保留参数提取逻辑验证 * docs(contributing): 更新工具开发指南以适配新的参数描述机制 - 文档更新: 同步 `CONTRIBUTING_ZH.md` 和 `CONTRIBUTING.md` 中的代码示例 * 移除函数 Docstring 中冗余的 `Parameters` 或 `Args` 段落,避免与动态生成的文档重复 * 在工具类初始化部分添加 `self.param_descriptions` 字典赋值逻辑,展示如何为每个参数提供中文或英文说明 * 更新示例代码结构,明确区分静态描述(通过 `param_descriptions`)与动态生成逻辑 * refactor(tools): 精简工具参数描述与文档摘要 - 重构优化: 移除参数说明中的默认值细节,统一为通用描述 * `symbol_ref_tool.py`: 更新 `path`, `language`, `include_definitions` 等参数的描述,移除“默认为...”后缀 * `ls_tool.py`, `stat_tool.py`: 简化 `folder_path` 和 `path` 的描述,去除默认路径提示 * `regex_search_tool.py`, `exact_search_tool.py`: 清理 `path`, `context`, `file_pattern`, `limit` 等参数的冗余信息 * `edit_tool.py`: 调整 `old_string`, `max_replacements`, `context_before`, `context_after` 的描述,使其更简洁明确 - 文档更新: 压缩函数 Docstring 内容,去除冗余的换行和解释性文字 * `symbol_ref_tool.py`: 合并多行功能描述为一行,保留核心场景说明 * `git_tool.py`, `read_tool.py`, `write_tool.py`: 缩短简介,移除不必要的标点或补充说明 * `exact_search_tool.py`: 将复杂的括号说明简化为纯文本 * `edit_tool.py`: 删除关于 dry-run、diff 生成及审计流程的详细解释,仅保留核心功能定义 * refactor(tools): 统一文件路径参数名为 `path` (#127) - 重构优化: 将多个工具中的文件/目录路径参数从特定名称统一重命名为 `path` * `ls_tool.py`: 将参数 `folder_path` 重命名为 `path`,更新内部变量引用及错误提示逻辑 * `read_tool.py`: 将参数 `file_path` 重命名为 `path`,同步更新所有涉及路径验证、二进制检查、文件读取及元数据记录的局部变量名 * `write_tool.py`: 将参数 `file_path` 重命名为 `path`,调整路径解析、存在性检查、mtime 验证及 diff 生成过程中的变量使用 * `glob_tool.py`: 将参数 `folder_path` 重命名为 `path`,简化根路径验证逻辑 * `edit_tool.py`: 将参数 `file_path` 重命名为 `path`,更新源路径解析、文件存在性校验及错误返回信息中的变量引用 - 破坏性变更: 修改了工具函数的 API 签名 * 受影响的函数包括 `ls`, `read`, `write`, `glob`, `edit` * 调用方需将对应的路径参数名更新为 `path`,例如 `tool.ls(folder_path=...)` 需改为 `tool.ls(path=...)` * refactor(tools): 调整错误处理语句格式以符合代码规范 - 重构优化: 统一 `ToolErrorResponse` 的调用格式,移除不必要的换行或缩进 * `read_tool.py`: 将 `is_file()` 检查失败时的错误返回语句合并为单行,移除跨行括号导致的冗余缩进 * `write_tool.py`: 将 `exists() and is_dir()` 检查失败时的错误返回语句拆分为多行,增强可读性并匹配其他错误处理逻辑
- 修复问题: 消除多模式搜索导致的文件系统重复遍历与 I/O 瓶颈 * 移除 `_search_single_pattern` 和 `_search_patterns_concurrent`,引入 `_search_all_patterns` 实现单次文件遍历匹配所有正则 * 调用 `Workspace.search_content_multi_pattern` API 替代旧版 `search_content`,避免 N 次 (N=模式数量) 重复打开文件 * 优化 `_build_results_with_context` 逻辑,按需读取文件行缓存而非全量加载,解决大文件内存溢出风险 - 重构优化: 修正上下文行获取逻辑与数据格式处理 * 将匹配结果从非结构化文本字符串解析重构为原生 `list[dict]` 数据结构,消除“格式化→正则解析”的反模式 * 修复上下文行计算逻辑,支持精确获取匹配行前后指定行数 (`context_lines`) 的原始内容 * 增加正则预编译与无效模式过滤机制,提升搜索执行效率 - 破坏性变更: 底层搜索接口返回结构变更 * `symbol_ref_tool` 不再依赖 `Workspace.search_content` 的格式化字符串输出,转而使用 `search_content_multi_pattern` 的结构化字典列表 * 移除了对 `[文件] path\n----\n` 文本格式的解析代码,下游需适配新的 `file`, `line_num`, `content`, `pattern_type` 字段
- 修复问题: 清理已解决的重复警告逻辑 * 删除 `src/core/input_parser.py` 中针对 `<func_call>` 标签的 `warnings.warn` 调用 * 移除不再需要的 `import warnings` 依赖
…write_permission attribute (#139)
…pattern parameter and fix limit semantics (#140) - 为 exact_search 添加 file_pattern 参数,默认 "*" 保持向后兼容 - 将 limit 语义从"扫描文件数"改为"返回匹配项数",同步修复 regex_search - Replace hardcoded rglob("*") with rglob(file_pattern) - Change limit to count individual matches instead of files scanned
* feat(tools): 重构工具异常处理机制并统一返回结构 (#133) - 新增功能: 引入 `ToolResult` 结构化结果类 * 定义 `ToolResult` 类,包含 `success`, `data`, `error` 属性及 `__slots__` 优化 * 实现 `handle_tool_exceptions` 装饰器,将各类异常(如 `PathNotFoundError`, `PermissionError`)统一封装为 `ToolResult(success=False, error=...)` * 确保工具方法无论同步或异步执行均返回标准 `ToolResult` 对象 - 修复问题: 统一会话 ID 访问方式 * 移除对私有属性 `workspace._current_session_id` 的直接访问 * 在 `Workspace` 类中公开 `session_id` 的 getter/setter 属性供外部调用 * 更新 `FileTracker`, `WriteTool`, `EditTool`, `QuitCmd` 等模块使用 `self.workspace.session_id` - 重构优化: 升级 `ToolRegistry` 执行逻辑 * 修改 `call_tool` 方法,增加对 `ToolResult` 的解包与状态判断逻辑 * 更新 `set_session_id` 方法,使其自动同步 `session_id` 到关联的 `Workspace` 实例 * 修正 `_log_tool_call` 和 `_record_tool_summary` 中的会话 ID 获取方式,直接使用内部变量而非 `getattr` * refactor(tools): 统一工具返回结果为 ToolResult 对象并重构测试断言 - 重构优化: 标准化 `ToolResult` 的使用逻辑与内部结构 * 调整 `src/workspace/tools/base_tool.py` 中 `__slots__` 属性顺序为 `(data, error, success)` 以符合初始化参数顺序 * 简化 `src/core/tool_registry.py` 中的结果处理逻辑,移除冗余的 `if-else` 分支,统一使用三元表达式解包 `raw_result` * 确保所有工具方法(ReadTool, WriteTool, EditTool)返回值均严格遵循 `ToolResult` 规范,通过 `result.data` 或 `result.error` 访问内容 - 修复问题: 更新测试用例以适配新的返回结构 * 修正 `tests/workspace/tools/test_read_tool.py` 中针对文件读取结果的断言,从检查字符串变为访问 `result.data` * 更新 `tests/workspace/tools/test_write_tool.py` 和 `test_edit_tool.py`,将直接检查返回字符串改为验证 `result.data` 字段 * 调整 `tests/workspace/tools/test_binary_protection.py` 中的二进制文件保护逻辑断言,确保正确访问 `result.data` 或 `result.error` * refactor(tool): 重构工具结果模型与执行流程 - 新增功能: 引入 `ToolResult` 模型类替代原有内联实现 * 新增 `src/models/tools/tool_result.py` 文件,定义 `ToolResult` 类 * 在 `ToolResult` 中集成 `_compress_result` 方法,支持字符串、列表和字典的自动截断逻辑 * 新增 `to_xml_string` 辅助函数,用于生成标准化的 XML 格式响应 * 添加 `make_tool_result_response`, `make_success_response`, `make_failed_response` 静态工厂方法至 `BaseTool` - 修复问题: 统一异常处理与返回值类型 * 修改 `BaseTool.handle_tool_exceptions` 装饰器,确保捕获的异常 (`PathNotFoundError`, `WorkspaceBoundaryError` 等) 均返回包含 `func_name` 和 `func_kwargs` 的 `ToolResult` 对象 * 移除 `ToolErrorResponse` 依赖,直接格式化错误信息为 `ClassName: Message` 格式 * 更新 `ToolRegistry.execute` 方法签名,强制返回 `ToolResult` 类型而非原始数据 * 增强 `ToolRegistry.execute` 中的类型检查,对非 `ToolResult` 类型的返回值抛出明确的错误提示 - 重构优化: 移动配置管理与压缩逻辑 * 将 `MAX_RESULT_LENGTH`, `LIST_TRUNCATE_THRESHOLD`, `DICT_TRUNCATE_THRESHOLD` 等常量从 `ToolRegistry` 移至 `ToolResult` 类属性 * 删除 `ToolRegistry` 中的 `_validate_config` 和 `_compress_result` 方法 * 将 `ToolRegistry._log_tool_call` 和 `_record_tool_call_summary` 调用参数由 `output` 改为 `result.response` - 文档更新: 补充单元测试覆盖 * 新增 `tests/models/tools/test_tool_result.py`,覆盖 `_compress_result` 在不同数据结构下的行为 * 删除 `tests/core/test_tool_registry.py` 中原有的重复压缩测试用例 * feat(core): 重构工具执行流程与异常处理机制 - 新增功能: 统一工具调用异常捕获逻辑 * `ToolRegistry.execute` 方法增加全局 try-except 块,将未找到的工具或运行时错误统一封装为 `ToolResult` 对象返回 * 移除 `tool_handler.py` 中冗余的 `json.dumps` 序列化及手动 traceback 打印逻辑 * 修改 `tool_handler.py` 中的结果获取方式,直接通过 `response.response` 访问标准化后的响应数据 - 修复问题: 修正导入路径与测试用例迁移 * 修复 `src/models/tools/tool_result.py` 中 `truncate_params_string` 的相对导入路径错误,改为绝对导入 `from src.utils.string_snapshot import ...` * 修复 `src/core/tool_registry.py` 中 `ToolResult` 的导入路径,从 `models.tools.tool_result` 调整为 `src.models.tools.tool_result` * 将配置验证测试 `test_validate_config` 从 `tests/core/test_tool_registry.py` 迁移至 `tests/models/tools/test_tool_result.py` * 删除 `tests/core/test_tool_registry.py` 中已不再适用的 `test_execute_nonexistent_tool` 测试用例 - 重构优化: 简化代码结构与提升健壮性 * 在 `tool_registry.py` 中移除 `execute` 方法内部对 `ValueError` 的显式 `else` 分支,利用外层异常处理统一覆盖所有错误场景 * 移除 `tool_handler.py` 中对 `json` 模块的依赖,减少不必要的字符串序列化操作 * refactor(workspace/tools): 统一工具响应格式至 ToolResult 标准 (#133) - 重构优化: 将各工具模块的返回类型从字符串或列表统一改为 `ToolResult` 对象 * 移除对 `src.models.tool_error_response.ToolErrorResponse` 的依赖,全面引入 `src.models.tools.tool_result.ToolResult` * 修改 `BaseTool` 中 `extract_params` 和 `handle_tool_exceptions` 的类型注解以适配新的返回结构 * 替换所有错误处理逻辑为调用 `self.make_failed_response(kwargs=locals().copy(), error=...)` * 替换所有成功返回逻辑为调用 `self.make_success_response(kwargs=locals().copy(), data=...)` - 新增功能: 增强搜索工具的异常处理与警告机制 * `regex_search_tool.py` 和 `exact_search_tool.py` 增加 `warnings` 列表收集文件读取错误,并通过 `error` 参数返回执行警告 * 修复正则表达式捕获语法错误 `(OSError, UnicodeDecodeError, PermissionError)` 为正确的元组形式 - 破坏性变更: 工具函数返回值类型变更 * 所有工具方法(如 `ls`, `read`, `write`, `git`, `stat`, `glob`, `edit`, `symbol_ref`, `regex_search`, `exact_search`)的返回类型由 `str` 或 `list[str]` 变更为 `ToolResult` * 调用方需更新解析逻辑以提取 `ToolResult` 中的 `data` 或 `error` 字段,不再直接解析字符串内容 * fix(tools): 优化异常处理逻辑与数据判空策略 - 修复问题: 改进 Git 命令超时异常的捕获与错误信息展示 * `src/workspace/tools/git_tool.py` 中修改 `subprocess.TimeoutExpired` 异常处理,将原始异常对象 `time_out_exception` 注入错误消息,替代固定文本"Git 命令执行超时 (30 秒)" - 重构优化: 统一工具结果模型中的空值判断逻辑 * `src/models/tools/tool_result.py` 中将 `if data:` 和 `if not data` 改为显式的 `if data is not None:` 和 `if data is None:`,避免布尔类型 falsy 值导致的误判 - 文档更新: 调整编辑工具的返回消息格式为多行字符串 * `src/workspace/tools/edit_tool.py` 中移除响应元组内的逗号分隔符,将原本的单行元组转换为包含换行符的多行字符串结构 * docs(tools): 规范工具开发流程与 ToolResult 返回标准 - 新增功能: 统一工具执行结果模型与文档示例 * 引入 `ToolResult` 类 (位于 `src/models/tools/tool_result.py`) 作为统一包装器 * 定义 `ToolResult` 字段:`success`, `func_name`, `func_kwargs`, `data`, `error`, `response` * 更新工具方法签名,要求返回类型为 `ToolResult` 而非原始数据 * 新增 `make_success_response` 和 `make_failed_response` 辅助方法使用示例 - 重构优化: 完善写入操作与注册逻辑说明 * 明确写入操作需通过 `self._validate_mtime(path)` 检查并记录 `PENDING_AUDIT` 快照 * 更新 `src/core/tool_registry.py` 中 `register()` 方法的实现细节与异常处理 * 增加对工具回调和参数缺失的警告机制 (`tool.func is None or tool.params is None`) - 文档更新: 强化测试覆盖要求 * 在 `tests/workspace/tools/` 下增加正常路径与失败场景的断言示例 * 明确要求验证 `result.success` 状态及 `result.data` / `result.error` 内容 * 提供基于 `WorkspaceBoundaryError` 的边界安全测试代码片段 * test(workspace): 统一工具执行结果断言为结构化属性 - 修复问题: 将测试断言从字符串匹配升级为基于 `result.success`、`result.data` 和 `result.error` 的结构化属性检查 * `TestGitAllowedCommands`: 更新 `git` 方法调用后的断言,使用 `result.response` 替代直接字符串操作 * `TestGitBlockedCommands`: 修改阻塞命令测试,通过 `result.success is False` 和 `result.error` 验证错误信息 * `TestBinaryProtection`: 修正 `ReadTool`、`WriteTool` 和 `EditTool` 对二进制文件的处理逻辑断言 * `TestEditTool`: 调整上下文匹配失败及文件不存在等场景的断言逻辑 * `TestWriteTool`: 更新外部修改检测场景的断言,验证 `FILE_MODIFIED_EXTERNALLY` 错误码
* chore(project): 更新项目版本号至 0.5.0 - 文档更新: 同步 README 文件中的版本信息 * 更新 `README_ZH.md` 中显示的版本号为 0.5.0 * 更新 `README.md` 中显示的版本号为 0.5.0 - 配置更新: 修改项目元数据与常量定义 * 在 `pyproject.toml` 中将 `[project]` 的 `version` 字段从 "0.4.1" 更新为 "0.5.0" * 在 `src/constants/__init__.py` 中将 `__version__` 变量从 "0.4.1" 更新为 "0.5.0" * docs(changelog): 记录 v0.5.0 版本工具重构与搜索优化变更 - 新增功能: 扩展工具能力与参数机制 * 引入 `ToolResult` 数据类统一所有工具的返回类型,包含 `success`、`data`、`error`、`response` 属性 * `exact_search` 新增 `file_pattern` 参数支持文件模式过滤 * 基于 `write_permission` 实现工具自动分类,无需手动注册 * `read` 工具支持通过 `start`、`end`、`context` 参数进行精确行范围读取 * `BaseTool` 引入 `param_descriptions` 字典,参数文档格式转为 Markdown 列表 * `read` 工具增加 `MAX_READ_FILE_SIZE` 配置项防止大文件内存溢出 - 修复问题: 修正搜索逻辑与清理冗余代码 * 修正 `exact_search` 和 `regex_search` 中 `limit` 参数语义,改为统计匹配结果数 * 移除输入解析器中过时的 `warnings.warn` 调用及未使用的依赖 - 重构优化: 提升性能并简化系统提示注入 * 使用 `search_content_multi_pattern` API 替代逐模式遍历,消除 I/O 开销并返回结构化 `list[dict]` * 统一所有工具路径参数名为 `path`,替换原有的 `file_path` 和 `folder_path` * 精简工具 Docstring 描述并移除冗余段落,降低 LLM 幻觉风险 * `handle_tool_exceptions` 装饰器统一封装异常为 `ToolResult` 对象,移除 `ToolErrorResponse` 依赖 - 破坏性变更: 移除旧版工具并更改参数命名 * 删除 `read_lines` 工具,其功能已合并至 `read` 工具,需迁移至使用 `read` 的 `start`/`end`/`context` 参数 * 所有工具的 `file_path` 和 `folder_path` 参数重命名为 `path`,上游调用方需同步更新参数名称
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.
No description provided.