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): *> 全流重定向、Win 上动态重定向目标、cd/pushd 别名、Suspend-Computer
Chrisae6b26eaad63
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 0e231f0725..cb3d269751 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -3118,6 +3118,97 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评}});+ it('PowerShell 的 *> 全流重定向与 > 是同一个写通道', () => {+ // `*>` / `*>>` 把所有流一起写进目标(about_Redirection),重定向提取只认 `>`/`N>`/`&>` → 整条+ // 落灰区(codex 报)。+ const win = ['C:\\repo'];+ const hosts = 'C:\\Windows\\System32\\drivers\\etc\\hosts';+ for (const c of [+ `'owned' *> ${hosts}`,+ `'owned' *>> ${hosts}`,+ `Get-Process *> ${hosts}`,+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 反例:区内落地判档不变。+ expect(classifyShellCommand("'owned' *> C:\\repo\\out.txt", win, { platform: 'win32' }))+ .toBe('prompt');+ // `*` 必须紧跟分隔符才算操作符 —— POSIX 的"通配符后接重定向"判法不变。+ expect(classifyShellCommand('echo a*>/ws/b', ['/ws'], { platform: 'linux' })).toBe('prompt');+ // 同一个操作符解析是共用的:POSIX 上 `*>` 的目标也确实是那个文件,一并必问(修前为 prompt)。+ expect(classifyShellCommand('echo x *> /etc/hosts', ['/ws'], { platform: 'linux' }))+ .toBe('prompt-each-time');+ });++ it('Windows 上重定向目标含运行期求值 → 不可证', () => {+ // 写 cmdlet 的目标早就过了"含 `$` = 不可证"这一步,重定向目标没过 → 被当字面量拼到工作区下,+ // `'owned' > "$env:windir\System32\drivers\etc\hosts"` 落灰区(codex 报)。+ const win = ['C:\\repo'];+ for (const c of [+ "'owned' > \"$env:windir\\System32\\drivers\\etc\\hosts\"",+ "'owned' > $target",+ "'owned' > \"$(Get-Location)\\x\"",+ "'owned' *> \"$env:windir\\x\"",+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 反例一:静态可证的区内目标判档不变。+ for (const c of ["'owned' > C:\\repo\\out.txt", "'owned' *> C:\\repo\\out.txt"]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ // 反例二:**只在 win32 生效** —— POSIX 的 `echo x > $LOGFILE` 是既有行为,这轮不动它。+ expect(classifyShellCommand('echo x > $LOGFILE', ['/ws'], { platform: 'linux' })).toBe('prompt');+ });++ it('整机电源:Suspend-Computer 与 Restart/Stop 同档', () => {+ const win = ['C:\\repo'];+ for (const c of ['Suspend-Computer -Force', 'Stop-Computer -Force', 'Restart-Computer']) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 反例:服务级与非电源的 `*-Computer` 不在本条范围。+ for (const c of [+ 'Suspend-Service -Name spooler',+ 'Restart-Service -Name spooler',+ 'Checkpoint-Computer -Description x',+ 'Get-Process',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ });++ it('cd / pushd 在 PowerShell 里是位置 cmdlet 的别名,但单字母选项仍按 POSIX 开关', () => {+ // `cd`/`pushd` 同时是 POSIX 内建与 Set-Location/Push-Location 的别名。上一提交只给全名开了+ // PowerShell 文法,于是 `pushd -StackName foo -Path <系统目录>` 把 `foo` 当 cwd(codex 报)。+ const win = ['C:\\repo'];+ const s32 = 'C:\\Windows\\System32';+ for (const c of [+ `pushd -StackName foo -Path ${s32}; Set-Content payload.txt owned`,+ `cd -StackName foo -Path ${s32}; Set-Content payload.txt owned`,+ `cd -ErrorAction Stop ${s32}; Set-Content payload.txt owned`,+ `chdir -StackName foo -Path ${s32}; Set-Content payload.txt owned`,+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 反例一:消费带值选项后要选中真正的 `-Path`,区内位置不能变成"未知"而被误升级。+ for (const c of [+ 'pushd -StackName foo -Path C:\\repo\\build; Set-Content a.txt x',+ 'cd -ErrorAction Stop C:\\repo\\build; Set-Content a.txt x',+ 'cd C:\\repo\\build; Set-Content a.txt x',+ 'pushd C:\\repo\\build; Set-Content a.txt x',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ // 反例二:POSIX 的单字母开关照旧当开关 —— cwd 仍被跟踪,区内破坏不被误升级。+ for (const c of [+ 'cd -P /ws/build && rm -rf x',+ 'cd -L /ws/build && rm -rf x',+ 'pushd -n /ws/x && rm -rf y',+ 'cd /ws/build && rm -rf x',+ ]) {+ expect(classifyShellCommand(c, ['/ws'], { platform: 'linux' }), c).toBe('prompt');+ }+ });+it('位置 cmdlet 的带值选项要先消费,不能把选项值当成新 cwd', () => {// 上一提交给位置 cmdlet 加的 parser 只做了"以 `-` 开头就跳过",于是带值选项的**值**被当成位置:// `Push-Location -StackName foo -Path <系统目录>` 把 `foo` 当新 cwd,真正的 `-Path` 反而没被看,diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 172251f70c..3cc638f926 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -199,10 +199,14 @@ const SYSTEM_WRITE_PATH_PATTERNS: readonly RegExp[] = [/*** 抽出 shell 输出重定向(`>`/`>>`/`N>`/`&>`/`>|`)的目标文件。用于把重定向写入复用 file-write 的系统红线* (codex 报:`cat x > /etc/hosts` 只当灰区重定向会绕过系统写同意)。目标可带引号或裸,取到空白/分隔符止。+ *+ * `*>` / `*>>` 是 PowerShell 的**全流**重定向(about_Redirection),与 `>` 同一个写通道,只是把所有+ * 流一起写进去 —— 不认它就等于 `'owned' *> <系统路径>` 整条落灰区(codex 报)。`*` 必须**紧跟**在+ * 分隔符后面才算重定向操作符,所以 POSIX 的 `echo a*>b`(通配符后接重定向)判法不变。*/function redirectionTargets(command: string): string[] {const out: string[] = [];- const re = /(?:^|[\s;&|()])(?:\d*|&)>{1,2}\|?\s*("(?:[^"\\]|\\.)*"|'[^']*'|[^\s;&|<>()]+)/g;+ const re = /(?:^|[\s;&|()])(?:\d*|&|\*)>{1,2}\|?\s*("(?:[^"\\]|\\.)*"|'[^']*'|[^\s;&|<>()]+)/g;for (const m of command.matchAll(re)) {// shell 词拼接:相邻引号/裸片段拼成一个词(`/e'tc'/hosts` → `/etc/hosts`,codex 报)→ 去掉所有引号字符。// **保留反斜杠**(Windows 路径分隔符);POSIX `\` 转义形态由调用点额外查去转义变体覆盖。@@ -1356,7 +1360,8 @@ const ALWAYS_ASK_PATTERNS: readonly RegExp[] = [// 裸语句包装成 `pwsh -Command '…'` 后仍落灰区,可被轻量 reviewer 静默放行(codex 报)。// 放在**整条命令**扫描的这张表里,裸语句、`pwsh -Command` 嵌套、Bash 原样串一次覆盖。// 只收"整机电源"这一类;`Stop-Service` / `Restart-Service` 是服务级、不在本条范围。- /\b(?:Restart|Stop)-Computer\b/i, // 系统电源(PowerShell)+ // `Suspend-Computer` 是同一族的第三个:挂起整台机器。`*-Service` 是服务级,不在本条范围。+ /\b(?:Restart|Stop|Suspend)-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)@@ -3151,9 +3156,14 @@ function powerShellLocationAttachedTarget(token: string): string | undefined {*/type LocationOptionKind = 'target-next' | 'consumes-value' | 'standalone' | 'unprovable';-function powerShellLocationOptionKind(token: string): LocationOptionKind {+function powerShellLocationOptionKind(token: string, posixFlagsWin = false): LocationOptionKind {const name = token.split(/[:=]/)[0].toLowerCase();const attached = token.length > name.length;+ // `cd` / `pushd` 这两个名字在 POSIX 是 shell 内建、在 PowerShell 是 Set-Location/Push-Location 的+ // 别名,同一个 token 两种文法。**单字母**选项按 POSIX 开关处理(`cd -P /ws/build`、`pushd -n`),+ // 多字母的才按 PowerShell 参数解析(`cd -ErrorAction Stop <路径>`)—— POSIX 的 cd/pushd 没有多字母+ // 选项,所以这条分界不会改动 POSIX 侧任何既有判档。+ if (posixFlagsWin && name.length <= 2) return 'standalone'; // `-P` / `-L` / `-n` / `-e`const known = [...POWERSHELL_TARGET_PARAMS, ...POWERSHELL_VALUE_PARAMS, ...POWERSHELL_SWITCH_PARAMS,];@@ -3186,9 +3196,11 @@ function directoryChangeTarget(tokens: string[]): { changesDirectory: boolean; t}// POSIX `pushd -n` 只压栈、不切目录。PowerShell 的 Push-Location 没有这个开关。if (bin === 'pushd' && tokens.slice(1).includes('-n')) return { changesDirectory: false };- // PowerShell 的位置 cmdlet 有带值选项(`-StackName`、common parameters),必须先消费掉再挑位置。- // POSIX 的 `cd`/`pushd` 只有开关,沿用原来的"以 `-` 开头就跳过",不改既有行为。- const powerShellLocation = pushLike ? bin === 'push-location' : POWERSHELL_SET_LOCATION.has(bin);+ // 位置 cmdlet 有带值选项(`-StackName`、common parameters),必须先消费掉再挑位置。+ // `cd` / `pushd` 也是 Set-Location / Push-Location 的**别名**,同样要按 PowerShell 文法解析+ // (`pushd -StackName foo -Path <系统目录>` 修前把 `foo` 当 cwd,codex 报);它们又同时是 POSIX+ // 的 shell 内建,所以单字母选项按 POSIX 开关处理,见 powerShellLocationOptionKind。+ const posixFlagAliases = bin === 'cd' || bin === 'pushd';let optionsEnded = false;for (let i = 1; i < tokens.length; i++) {const token = tokens[i];@@ -3197,10 +3209,9 @@ function directoryChangeTarget(tokens: string[]): { changesDirectory: boolean; tcontinue;}if (!optionsEnded && token.startsWith('-') && token !== '-') {- if (!powerShellLocation) continue;const attached = powerShellLocationAttachedTarget(token);if (attached !== undefined) return { changesDirectory: true, target: attached };- const kind = powerShellLocationOptionKind(token);+ const kind = powerShellLocationOptionKind(token, posixFlagAliases);if (kind === 'unprovable') return { changesDirectory: true };if (kind === 'consumes-value') {const value = tokens[i + 1];@@ -3349,7 +3360,16 @@ function systemWriteTargetsInSegment(workspaceRoots: string[],opts: ShellReviewOptions,): boolean {- const targets = [...redirectionTargets(segment), ...argumentWriteTargets(tokens)];+ // Windows 上重定向目标里的 `$` 是运行期求值(`$env:windir`、`$target`、`$(Get-Location)`),与写+ // cmdlet 的目标同一个判据 —— 早先只有 cmdlet 参数过了这一步,重定向目标被当字面量拼到工作区下,+ // 于是 `'owned' > "$env:windir\System32\drivers\etc\hosts"` 落灰区(codex 报)。+ // **只在 win32 生效**:POSIX 的 `echo x > $LOGFILE` 是另一件事(既有行为,#2622 在跟),这里不动它。+ const dynamicRedirectUnprovable = (opts.platform ?? process.platform) === 'win32';+ const targets = [+ ...redirectionTargets(segment).map((t) =>+ dynamicRedirectUnprovable && POWERSHELL_DYNAMIC_TARGET.test(t) ? UNPROVABLE_WRITE_TARGET : t),+ ...argumentWriteTargets(tokens),+ ];if (targets.length === 0) return false;// 静态不可证的写目标(tar -P 的归档成员等)一律要求同意。if (targets.includes(UNPROVABLE_WRITE_TARGET)) return true;