fix(backend): 修正 Shell 语法口径不一致与危险命令误伤 - #160
Merged
Merged
Conversation
统一 shell 检测口径,让提示词与执行层 auto 实际使用的解释器一致:
- 新增 build_shell_prompt_section,按 recommended_family(与 detect_interpreter
"auto" 同序)生成语法口径;消除提示词里"优先 bash"与"Windows 优先 PowerShell"
的矛盾,删除错误的 2>nul(cmd 语法,PowerShell 下会生成名为 nul 的文件)
- AVAILABLE_SHELLS 改走 ShellExecutor 探测,避免把 System32 的 WSL 启动器
误报为可用 bash
- general_host_prompt.md 接入 ${SHELL_GUIDANCE_SECTION}
修复危险命令拦截误伤正规操作:
- hardline 拆档:纯破坏命令(rm -rf / 与 ~、mkfs、dd of=/dev/、fork bomb)
仍全模式硬拦;高危但常用的操作(rm -rf 子目录、curl|bash、sudo/su、
nmap/nc、带 $TOKEN 的 curl)从 hardline 移除,落到 shell_policy 按授权模式
改为需确认(full_auto 放行),修复安装脚本等被无条件 BLOCK
- shell_tool.py 同步删除重复且误伤的拦截条,仅保留纯破坏命令
- 同步调整/新增 authorization、shell_environment、powershell 相关测试
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.
Closes #159
改动概述
本 PR 只含一个 commit(
d40a80c,2026-07-24),修两个独立但同源的问题:提示词与执行层对「用哪个 shell、写哪种语法」的口径不统一。一、统一 Shell 语法口径
build_shell_prompt_section(),按recommended_family生成语法口径段落,与detect_interpreter("auto")同序(Windows:Git Bash → WSL → busybox → PowerShell)2>nul(cmd 语法,PowerShell 下会生成名为nul的文件)AVAILABLE_SHELLS改走ShellExecutor探测,避免把 System32 的 WSL 启动器误报为可用 bashgeneral_host_prompt.md接入${SHELL_GUIDANCE_SECTION}与
build_powershell_prompt_section()的分工:本段负责「默认用哪个解释器、写哪种语法」的主口径,PowerShell 段只补充 5.1 / 7 版本兼容写法。二、危险命令拦截拆档
hardline 原本把「高危但常用」与「纯破坏性」混在一档无条件 BLOCK,导致安装脚本等正规操作无法通过任何授权模式放行。
rm -rf /与~、mkfs、dd of=/dev/、fork bombrm -rf子目录、curl|bash、sudo/su、nmap/nc、带$TOKEN的curl)下沉到shell_policy,按授权模式改为需确认,full_auto放行shell_tool.py同步删除重复且误伤的拦截条验证
在 Windows(win32 / Python 3.12.11)本地跑通,基线为含 back-merge 的最新
dev(3e95b82):ruff format --check app/改动 9 个文件、+286 −50,其中 169 行是测试(
test_shell_environment.py+98、test_capability_authorization.py+50、test_powershell_prompt_section.py+21)。审阅提示
本 commit 与刚合入 dev 的
c1b49bf(PowerShell auto 改用系统最新版本)都涉及 auto 行为,且都改动shell_environment.py与test_powershell_prompt_section.py。cherry-pick 到 back-merge 后的 dev 时 git 自动合并、无冲突,但代码不冲突不等于语义兼容,因此额外单独跑了上述 155 例定向测试确认两者共存无问题:
c1b49bf管「选哪个 PowerShell 版本」,本 PR 管「默认选哪个解释器族、提示词教哪种语法」,作用层次不同。