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): PowerShell 的位置 cmdlet 进 cwd 跟踪
Chris9ab3a1e1be77
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex de93d08026..cecd9fcbdc 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -3075,6 +3075,49 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评}});+ it('PowerShell 的位置 cmdlet 也要进 cwd 跟踪', () => {+ // cwd 跟踪早先只认 POSIX 名字(`cd`/`pushd`/`popd`),于是同一条命令换成 `Set-Location` 判档就+ // 不同:`Set-Location C:\Windows\System32; Set-Content payload.txt owned` 的相对目标仍按工作区+ // 解析、整条落灰区,而 `cd` 写法修前就已必问(codex 报)。+ const win = ['C:\\repo'];+ const s32 = 'C:\\Windows\\System32';+ for (const c of [+ `Set-Location ${s32}; Set-Content payload.txt owned`,+ `sl ${s32}; Set-Content payload.txt owned`, // 别名+ `chdir ${s32}; Set-Content payload.txt owned`,+ `Set-Location -Path ${s32}; Set-Content payload.txt owned`, // 具名+ `Set-Location -Path:${s32}; Set-Content payload.txt owned`, // 贴值+ `Set-Location -LiteralPath ${s32}; Set-Content payload.txt owned`,+ `Push-Location ${s32}; Set-Content payload.txt owned`,+ // 连续切换:第二段是相对路径,按上一段跟踪到的 cwd 解析。+ 'Set-Location C:\\Windows; Set-Location System32; Set-Content payload.txt owned',+ `Set-Location ${s32}; Remove-Item payload.txt`, // 删除同族+ // 回到栈上一层 = 运行期状态 → cwd 未知 → fail closed(与 POSIX `popd` 同口径)。+ 'Pop-Location; Set-Content payload.txt owned',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }+ // 对照:POSIX 写法修前就已必问,补齐后两边一致(钉住"换个名字判档不同"不再发生)。+ for (const c of [+ `cd ${s32}; Set-Content payload.txt owned`,+ 'popd; Set-Content payload.txt owned',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例:切到区内、或目标是绝对路径 → 判档不变,补齐没有把日常操作打成硬弹窗。+ for (const c of [+ 'Set-Location C:\\repo\\build; Set-Content a.txt x',+ 'sl C:\\repo; Remove-Item build\\x',+ `Set-Location ${s32}; Set-Content C:\\repo\\a.txt x`, // 绝对目标不受 cwd 影响+ `Set-Location ${s32}`, // 只切目录,没有写+ 'Get-Location', // 只读,不算切换+ 'Set-Location C:\\repo; Push-Location C:\\repo\\build; Set-Content a.txt x',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ });+it('前缀撞到别的 cmdlet 的参数时,按处理方式归并;贴值归不出来也不许丢', () => {// 真 PowerShell 把缩写解析到**被调 cmdlet 自己的参数集**,而这里的候选集是三张全局表拼的,// 于是 `Copy-Item -Dest` 撞上别的 cmdlet 的 `-DestinationPath` → 判成歧义。歧义分支对**贴值**diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex fad25302ab..eee4cee41a 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -3108,12 +3108,45 @@ function windowsDestructiveRmTargets(tokens: string[]): string[] | null {return targets.length > 0 ? targets : null;}+/**+ * PowerShell 改当前位置的 cmdlet 与别名。`cd` / `chdir` 在 cmd.exe 与 PowerShell 里语义一致,+ * 早先只认 `cd`/`pushd`(POSIX 名字),于是+ * `Set-Location C:\Windows\System32; Set-Content payload.txt owned` 的相对目标仍按工作区解析、+ * 整条落灰区(codex 报)。**同一条命令换个 cmdlet 名字判档就不同**,这里把三个入口补齐:+ * · `Set-Location` / `sl` / `chdir` → 同 `cd`;+ * · `Push-Location` → 同 `pushd`;+ * · `Pop-Location` → 同 `popd`(回到栈上一层 = 运行期状态 → cwd 未知,fail closed)。+ * `Get-Location` 只读,不在此列。+ */+const POWERSHELL_SET_LOCATION: ReadonlySet<string> = new Set(['set-location', 'sl', 'chdir']);++/**+ * PowerShell 的 `-Path:<路径>` / `-LiteralPath:<路径>` 把值**贴在**参数上,不占一个 token。按+ * "以 `-` 开头就跳过"处理等于"没给目标"→ cwd 变未知 → 后续**区内**相对写会被误升级成硬弹窗。+ * 前缀歧义(`-p:` 同时命中 `-Path`/`-PSPath`)时返回 undefined,走原来的"没给目标"分支 = fail closed。+ */+function powerShellLocationAttachedTarget(token: string): string | undefined {+ const name = token.split(/[:=]/)[0].toLowerCase();+ if (token.length === name.length) return undefined; // 没有贴值+ const known = POWERSHELL_PATH_PARAMS;+ const matched = known.includes(name)+ ? [name]+ : name.length >= 2 ? known.filter((p) => p.startsWith(name)) : [];+ return matched.length === 1 ? token.slice(name.length + 1) : undefined;+}+function directoryChangeTarget(tokens: string[]): { changesDirectory: boolean; target?: string } {// executableName 归一大小写/.exe:Windows cmd/PowerShell 大小写不敏感,`CD /` 的 cwd 变更不能漏识别// (copilot 报:漏了会把后续相对破坏目标误当仍在工作区内)。const bin = executableName(tokens[0] ?? '');- if (bin === 'source' || bin === '.' || bin === 'popd') return { changesDirectory: true };- if (bin !== 'cd' && bin !== 'pushd') return { changesDirectory: false };+ if (bin === 'source' || bin === '.' || bin === 'popd' || bin === 'pop-location') {+ return { changesDirectory: true };+ }+ const pushLike = bin === 'pushd' || bin === 'push-location';+ if (bin !== 'cd' && !pushLike && !POWERSHELL_SET_LOCATION.has(bin)) {+ return { changesDirectory: false };+ }+ // POSIX `pushd -n` 只压栈、不切目录。PowerShell 的 Push-Location 没有这个开关。if (bin === 'pushd' && tokens.slice(1).includes('-n')) return { changesDirectory: false };let optionsEnded = false;for (const token of tokens.slice(1)) {@@ -3121,7 +3154,11 @@ function directoryChangeTarget(tokens: string[]): { changesDirectory: boolean; toptionsEnded = true;continue;}- if (!optionsEnded && token.startsWith('-') && token !== '-') continue;+ if (!optionsEnded && token.startsWith('-') && token !== '-') {+ const attached = powerShellLocationAttachedTarget(token);+ if (attached !== undefined) return { changesDirectory: true, target: attached };+ continue;+ }// pushd +/-N rotates the directory stack; the resulting cwd is runtime state.if (bin === 'pushd' && /^[+-]\d+$/.test(token)) {return { changesDirectory: true };