Feat/enhance path validation exclusion / 增强路径验证排除#151
Merged
Conversation
- 新增功能: 引入统一的文件排除与权限决策引擎 * 新增 `ExclusionManager` 类,聚合默认性能排除、.gitignore 规则及用户自定义忽略项 * 新增 `PermissionManager` 类,提供基于操作类型 (READ/WRITE/SEARCH) 的统一权限决策接口 * 新增 `SensitiveFileError` 异常类,用于在路径校验阶段拦截敏感文件访问 * 工具层集成:`ls_tool`, `glob_tool`, `regex_search_tool`, `exact_search_tool` 均接入 `exclusion_manager` 进行路径过滤 - 修复问题: 增强敏感文件保护机制 * 在 `PathValidator` 中增加 `_raise_if_sensitive` 逻辑,直接禁止访问 `.env`, `*.pem`, `id_rsa` 等敏感文件 * 在 `BaseTool` 的异常处理装饰器中捕获 `SensitiveFileError`,返回明确的拒绝访问提示 * 将原本硬编码的 `DEFAULT_EXCLUDED_DIRS` 替换为动态加载的 `ExclusionManager` 实例 - 重构优化: 简化搜索与遍历逻辑 * 移除 `workspace.py` 和各类 Search Tool 中重复的正则编译与排除逻辑 * 使用 `merge_ignore_regexes` 方法统一合并默认规则与用户传入的 ignore 模式 * 利用 `is_ignored_by_gitignore` 函数统一处理 .gitignore 规则的匹配与否定逻辑 - 文档更新: 补充模块设计说明 * 添加 `ExclusionManager` 和 `PermissionManager` 的类级文档字符串,明确区分性能排除与安全排除场景
- 破坏性变更: 移除 `PermissionManager` 及其相关 API * 删除 `src/workspace/permissions.py` 文件 * 移除 `Workspace` 类中的 `self.permission_manager` 属性及初始化逻辑 * 调用方需直接依赖 `PathValidator` 进行敏感文件拦截,不再通过 `workspace.permission_manager.is_allowed()` 查询 - 重构优化: 整合敏感文件规则至 `ExclusionManager` * 将 `SENSITIVE_FILE_PATTERNS` 从硬编码移至 `ExclusionManager.SENSITIVE_FILE_PATTERNS` * `PathValidator` 引入 `ExclusionManager` 作为唯一敏感文件模式来源 (`re.compile(p) for p in ExclusionManager.SENSITIVE_FILE_PATTERNS`) * 更新正则表达式前缀以支持路径边界匹配 (添加 `(^|/)`) - 代码清理: 移除冗余的排除检查逻辑 * 在 `Workspace._search_content` 中移除基于 `should_exclude_dir` 的父目录遍历检查 * 移除 `ExclusionManager` 中已废弃的 `_sensitive_file_res` 预编译缓存逻辑 * 移除 `ExclusionManager` 中不再使用的 `is_sensitive_file` 和 `should_exclude_dir` 方法 - 文档更新: 补充 `gitignore_loader` 已知局限性说明 * 明确标注不支持嵌套 `.gitignore`、行尾续行及字符类扩展语法 * 记录否定模式优先级处理与真实 Git 的差异及设计理由
Owner
Author
|
Need fix / 需要修复 #154 |
- 新增功能: 在文件扩展名白名单中添加Godot相关后缀 * 添加 `.godot` 和 `.gd` 支持 * 添加 `.gd.uid` 和 `.tscn` 支持
- 新增功能: 在 binary_detector.py 的 FILE_EXTENSIONS 集合中增加对特定编译产物和数据库文件的识别 * 添加 .pdb (程序数据库) 后缀 * 添加 .pyd (Python 动态链接库) 后缀 * 添加 .o (目标文件) 后缀
- 新增功能: 集成二进制文件检测机制 * 在 `regex_search_tool.py` 和 `exact_search_tool.py` 中导入 `src.utils.binary_detector.is_binary_file` * 在遍历文件列表时增加 `is_binary_file(file_path)` 判断,自动跳过二进制文件 - 重构优化: 增强文件路径筛选与排除逻辑 * 修改 `files_to_search` 生成逻辑,将简单的 `rglob` 转换为包含条件过滤的列表推导式 * 引入 `self._exclusion_manager.should_exclude_path(p)` 方法,支持自定义路径排除规则 * 确保仅处理 `p.is_file()` 且未被排除的有效文件
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.