Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(auto-review): 补整机电源 cmdlet 与 Set-Acl 的 PowerShell 名字
Chrisf54ff0ab2615
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex f35b0a89c7..be1ff69285 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -2634,6 +2634,60 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评expect(classifyShellCommand('echo x | tee a b c', ['/repo'])).toBe('prompt');});+ it('整机电源与 ACL:PowerShell 形态要与 POSIX/cmd 同口径,不能只有 shutdown 那几个名字', () => {+ // 这两条都不是新判据,是既有判据**缺 PowerShell 的名字**:+ // · 电源:HIGH_RISK 里只有 `shutdown|reboot|halt|poweroff`(`shutdown /r` 已必问),+ // `Restart-Computer` / `Stop-Computer` 一条都不匹配 → 裸语句包装后仍落灰区(codex 报);+ // · ACL:`chmod`/`chown`/`setfacl` 分支早就把 FILE 操作数当写目标(改访问控制与改内容同险),+ // 但 `Set-Acl` 没登记 → 取不到目标(codex 报)。+ const win = ['C:\\repo'];+ const hosts = 'C:\\Windows\\System32\\drivers\\etc\\hosts';++ // 整机电源。放在**整条命令**扫描的表里,所以裸语句 / `pwsh -Command` 嵌套 / 多段混合一次覆盖。+ for (const c of [+ 'Restart-Computer',+ 'Stop-Computer',+ 'Restart-Computer -Force',+ 'Stop-Computer -ComputerName localhost',+ 'restart-computer', // 大小写不敏感+ 'pwsh -Command Restart-Computer',+ "pwsh -Command 'Stop-Computer -Force'",+ 'Get-Process; Restart-Computer', // 与只读段混合+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 回归:POSIX / cmd 形态判档不变。+ expect(classifyShellCommand('shutdown /r', win, { platform: 'win32' })).toBe('prompt-each-time');+ expect(classifyShellCommand('reboot', win, { platform: 'win32' })).toBe('prompt-each-time');+ // 只收「整机电源」这一类 —— 服务级的 Stop-Service/Restart-Service 不在本条范围,仍交审阅器。+ expect(classifyShellCommand('Restart-Service MyService', win, { platform: 'win32' })).toBe('prompt');+ expect(classifyShellCommand('Stop-Service MyService', win, { platform: 'win32' })).toBe('prompt');++ // Set-Acl:受保护目标的访问控制变更 = 确定性同意。+ for (const c of [+ `Set-Acl ${hosts} $acl`,+ `Set-Acl -Path ${hosts} -AclObject $acl`,+ `Set-Acl -LiteralPath ${hosts} -AclObject $acl`,+ 'Set-Acl C:\\Windows\\System32 $acl',+ `Set-Acl -AclObject $acl -Path ${hosts}`, // 参数顺序反过来+ `pwsh -Command Set-Acl -Path ${hosts} -AclObject $acl`, // 载荷下探+ `Set-Acl -Path HKLM:\\SYSTEM\\Foo -AclObject $acl`, // provider 路径同族+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 反例:区内目标仍是灰区;只读 Get-Acl 不在写目标表里。+ expect(classifyShellCommand('Set-Acl C:\\repo\\a.txt $acl', win, { platform: 'win32' })).toBe('prompt');+ expect(classifyShellCommand('Set-Acl -Path C:\\repo\\a.txt -AclObject $acl', win, { platform: 'win32' }))+ .toBe('prompt');+ expect(classifyShellCommand(`Get-Acl ${hosts}`, win, { platform: 'win32' })).toBe('prompt');+ // 反例:`-AclObject` 是**带值**参数,值不能被当成位置操作数顶掉真目标 ——+ // 这条钉住的是"值被吃掉"那个错法(会让 `$acl` 变成写目标、系统路径反而漏掉)。+ expect(classifyShellCommand('Set-Acl -AclObject $acl C:\\repo\\a.txt', win, { platform: 'win32' }))+ .toBe('prompt');+ expect(classifyShellCommand(`Set-Acl -AclObject $acl ${hosts}`, win, { platform: 'win32' }))+ .toBe('prompt-each-time');+ });+it('iex 是把 stdin 当程序的执行器:`| iex` 落在外层 shell 也命中下载即执行', () => {// `pwsh -Command 'iwr https://…/a.ps1' | iex`:`| iex` 在**外层**,顶层分段把它切成独立一段。// 于是两段各自都不红 —— payload 那段只有 `iwr`(单纯下载不是红线),`iex` 那段 tokens[0] 不是diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 38ccf4debf..101283a07c 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -337,6 +337,11 @@ const POWERSHELL_WRITE_CMDLETS: ReadonlyMap<['clear-content', { targets: 'first' }],['set-itemproperty', { targets: 'first' }],['set-item', { targets: 'first' }],+ // `Set-Acl` 改的是**访问控制**,与改内容同等危险 —— 与本文件既有的+ // `chmod`/`chown`/`setfacl` 分支同口径(那条已经把 FILE 操作数当写目标)。+ // 之前只有 POSIX 名字,`Set-Acl C:\Windows\…\hosts $acl` 取不到目标、落灰区(codex 报)。+ // 位置 0 是 `-Path`,ACL 对象由 `-AclObject` 给出(已在带值参数表里)。+ ['set-acl', { targets: 'first' }],// 文档别名(Microsoft.PowerShell.Management)—— PowerShell 里 alias 的解析**优先于**外部// 命令,所以 `sc <系统路径> owned` 等价于 `Set-Content`,不列就整条绕过本判据(codex 报)。// `sc` 在 PowerShell 7 里已因与 `sc.exe` 冲突而移除,Windows PowerShell 5.1 仍有;两边都@@ -469,6 +474,8 @@ const POWERSHELL_VALUE_PARAMS: readonly string[] = ['-encoding', '-value', '-itemtype', '-name', '-filter', '-include', '-exclude','-width', '-delimiter', '-stream', '-credential', '-type', '-propertytype','-fromsession', '-tosession', '-totalcount', '-tail',+ // Set-Acl 的 ACL 对象:不是写目标,但**带值** —— 不消费的话值会被当位置操作数、顶掉真目标。+ '-aclobject', '-securitydescriptor', '-centralaccesspolicy',];/**@@ -1169,6 +1176,12 @@ const ALWAYS_ASK_PATTERNS: readonly RegExp[] = [/\b(?:mkfs|fdisk|dd)\b/, // 磁盘/文件系统操作/(?:^|\s)>\s*\/dev\/[sh]d/, // 写块设备/\b(?:shutdown|reboot|halt|poweroff)\b/, // 系统电源+ // PowerShell 的同一件事:`Restart-Computer` / `Stop-Computer` 关掉或重启整台机器。+ // 这条红线本来只有 POSIX / cmd 的名字(`shutdown /r` 已必问),PowerShell 形态一条都不匹配 →+ // 裸语句包装成 `pwsh -Command '…'` 后仍落灰区,可被轻量 reviewer 静默放行(codex 报)。+ // 放在**整条命令**扫描的这张表里,裸语句、`pwsh -Command` 嵌套、Bash 原样串一次覆盖。+ // 只收"整机电源"这一类;`Stop-Service` / `Restart-Service` 是服务级、不在本条范围。+ /\b(?:Restart|Stop)-Computer\b/i, // 系统电源(PowerShell)/:\s*\(\s*\)\s*\{.*\|.*&.*\}/, // fork bomb :(){ :|:& };:/\bchmod\b[^|;&]*\s(?:-R\s+)?[0-7]*7{2,3}\b/, // chmod 777 之类数字放宽权限/\bchmod\b[^|;&]*\s[ugoa]*[oa][ugoa]*[-+=][^\s]*w/, // chmod 符号型对 other/all 开放写(a+w / o+w / a+rwx)