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): 登记 Set-AuthenticodeSignature;计算属性算换来源;修 TS7022
Chrise010d01b01e3
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 8025e34120..a7bcb4bd35 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,70 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评}});+ it('Select-Object 的计算属性造出新路径,不是透传', () => {+ // `Select-Object @{Name='Path';Expression={…}}` 造出一个新的 `Path` 值,而 `Remove-Item -Path`+ // 按属性名接受 pipeline 输入 → 删除段吃的是表达式算出来的路径,不是上游那个项(codex 报)。+ //+ // 实测:codex 给的那条原样命令**修前已经是 prompt-each-time**,但那是**偶然** —— `@{…}` 里的+ // `;` 被当成语句分隔符把 hashtable 撕开了。去掉 `;` 的 `@{Name='Path'}` 修前就是 prompt,+ // 所以这里按语义显式判 `@` 开头的 token,不再依赖分隔符。+ const win = ['C:\\repo'];+ const hosts = 'C:\\Windows\\System32\\drivers\\etc\\hosts';+ for (const c of [+ `Get-Item C:\\repo | Select-Object @{Name='Path';Expression={'${hosts}'}} | Remove-Item`,+ "Get-Item C:\\repo | Select-Object @{Name='Path'} | Remove-Item", // 无 `;`,修前漏+ "Get-Item C:\\repo | Select-Object -Property @{Name='Path'} | Remove-Item", // 具名,修前漏+ "Get-Item C:\\repo | Select-Object @{n='Path';e={$x}} | Remove-Item", // 缩写键名+ 'Get-Item C:\\repo | Select-Object @props | Remove-Item', // splatting+ 'Get-Item C:\\repo | Where-Object @cond | Remove-Item', // 同族其它阶段+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例:真正的透传形态判档不变(属性名、挑选开关、过滤条件都不含 `@`)。+ for (const c of [+ 'Get-ChildItem C:\\repo\\build | Select-Object Name | Remove-Item',+ 'Get-ChildItem C:\\repo\\build | Select-Object -Property Name | Remove-Item',+ 'Get-ChildItem C:\\repo\\build | Select-Object -First 1 | Remove-Item',+ 'Get-ChildItem C:\\repo\\build | Where-Object Name -eq x | Remove-Item',+ 'Get-ChildItem C:\\repo\\build | Where-Object { $_ } | Remove-Item',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ });++ it('Set-AuthenticodeSignature 写的是被签名文件本身', () => {+ // 签名把签名块写进文件尾 → 是对该文件的写入。之前没登记,`-FilePath <系统路径>` 取不到目标、+ // 落灰区(codex 报)。位置 0 是 `-FilePath`(与 Get-AuthenticodeSignature 同签名)。+ const win = ['C:\\repo'];+ const prof = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\profile.ps1';+ for (const c of [+ `Set-AuthenticodeSignature -FilePath ${prof} -Certificate $cert`,+ `Set-AuthenticodeSignature ${prof} -Certificate $cert`, // 位置 0+ `Set-AuthenticodeSignature ${prof} $cert`, // 证书也按位置绑+ `Set-AuthenticodeSignature -File ${prof} -Certificate $cert`, // 唯一前缀+ `Set-AuthenticodeSignature -FilePath:${prof} -Certificate $cert`, // 贴值+ // 自己的带值参数已登记 → 不会顶掉真目标,也不会触发操作数错位的 fail closed。+ `Set-AuthenticodeSignature -FilePath ${prof} -HashAlgorithm SHA256 `+ + '-TimestampServer http://t.test -IncludeChain All -Certificate $cert',+ // 运行期求值的目标 → 不可证。+ 'Set-AuthenticodeSignature -FilePath $target -Certificate $cert',+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例:区内文件签名仍是灰区 —— 用 `first` 而不是 `all` 就是为了这条(`all` 会把按位置绑的+ // `$cert` 当写目标,把区内签名误升级成硬弹窗)。+ for (const c of [+ 'Set-AuthenticodeSignature -FilePath C:\\repo\\a.ps1 -Certificate $cert',+ 'Set-AuthenticodeSignature C:\\repo\\a.ps1 $cert',+ 'Set-AuthenticodeSignature -Certificate $cert', // 缺目标参数 → 没有写入+ `Get-AuthenticodeSignature ${prof}`, // 只读,不在此列+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ });+it('Select-Object -ExpandProperty 取的是属性值,来源变了', () => {// `Select-Object` 只有**透传对象**的形态算"只挑选、没换来源";`-ExpandProperty` 输出属性值,// 来源随之改变:`Get-Item Env:ComSpec | Select-Object -ExpandProperty Value | Remove-Item`diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 484d138b6d..ac1397d6fb 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -375,6 +375,14 @@ const POWERSHELL_WRITE_CMDLETS: ReadonlyMap<// 之前只有 POSIX 名字,`Set-Acl C:\Windows\…\hosts $acl` 取不到目标、落灰区(codex 报)。// 位置 0 是 `-Path`,ACL 对象由 `-AclObject` 给出(已在带值参数表里)。['set-acl', { targets: 'first' }],+ // `Set-AuthenticodeSignature` 改的是**被签名文件本身**(它把签名块写进文件尾),与改内容同等+ // 危险:`Set-AuthenticodeSignature -FilePath C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1+ // -Certificate $cert` 之前取不到目标、落灰区(codex 报)。位置 0 是 `-FilePath`(与+ // `Get-AuthenticodeSignature` 同签名),证书由 `-Certificate` 给出(已在带值参数表里)。+ // 用 `first` 而不是 `all`:`-Certificate` 也能按位置绑到位置 1,取全部操作数会把 `$cert`+ // 当成写目标 → 区内文件签名被误升级成硬弹窗。+ // `Get-AuthenticodeSignature` 是只读的,不在此列。+ ['set-authenticodesignature', { targets: 'first' }],// 文档别名(Microsoft.PowerShell.Management)—— PowerShell 里 alias 的解析**优先于**外部// 命令,所以 `sc <系统路径> owned` 等价于 `Set-Content`,不列就整条绕过本判据(codex 报)。// `sc` 在 PowerShell 7 里已因与 `sc.exe` 冲突而移除,Windows PowerShell 5.1 仍有;两边都@@ -516,6 +524,8 @@ const POWERSHELL_VALUE_PARAMS: readonly string[] = [// Export-* / 归档族自己的带值参数。同一个道理:`Export-Csv -InputObject $x -Path <系统路径>`// 若不消费 `$x`,它会被当成位置操作数顶掉 `-Path`(这是本表第三次踩同一个坑,前两次是// `-Encoding` 与 `-AclObject`,所以登记新 cmdlet 时一并登记它的带值参数已是固定动作)。+ // Set-AuthenticodeSignature 自己的带值参数(登记新 cmdlet 时一并登记带值参数,同上)。+ '-includechain', '-hashalgorithm', '-timestampserver', '-sourcepathorextension', '-content','-inputobject', '-cert', '-certificate', '-module', '-compressionlevel', '-password','-usequotes', '-quotefields', '-usiculture', '-fullyqualifiedmodule',// Invoke-WebRequest / Invoke-RestMethod 的带值参数。这一组必须齐,否则未知参数会触发下面@@ -3325,10 +3335,16 @@ function matchesPowerShellParam(token: string, full: string): boolean {* · `-ExpandProperty <name>`:输出的是**那个属性的值**、不再是原对象。* `Get-Item Env:ComSpec | Select-Object -ExpandProperty Value | Remove-Item` 喂给删除段的是* 系统 `cmd.exe` 的路径(codex 报)。+ * · `@` 开头的 token:**计算属性** `@{Name='Path';Expression={…}}` 造出一个新的 `Path` 值,而+ * `Remove-Item -Path` 按属性名接受 pipeline 输入 → 删除段吃的是表达式算出来的那个路径,不是+ * 上游那个项(codex 报)。同形状的 splatting `@args`(可能把 `-InputObject` /+ * `-ExpandProperty` 塞进来)与数组 `@(…)` 一并算,判据只看"来源还证不证得出来"。*/function pipelineStageReplacesSource(tokens: string[]): boolean {return tokens.slice(1).some((token) =>- matchesPowerShellParam(token, 'inputobject') || matchesPowerShellParam(token, 'expandproperty'));+ token.startsWith('@')+ || matchesPowerShellParam(token, 'inputobject')+ || matchesPowerShellParam(token, 'expandproperty'));}/**@@ -3578,7 +3594,10 @@ function scopedDestructionNeedsConsent(} else {const operands = positionalOperands(tokens.slice(1));// 没给实参:首段 = 枚举当前目录;有上游 = 项由上游喂进来,provenance 原样保留(含 `null`)。- const emitted = operands.length > 0 ? operands : (fromPipe ? upstreamOperands : ['.']);+ // 类型标注是必须的:初始化式里读了 `upstreamOperands`,而它下一行又由本变量赋值,+ // 少了标注 tsc 会判成循环推断(TS7022,desktop 的 typecheck 实测报错)。+ const emitted: string[] | null =+ operands.length > 0 ? operands : (fromPipe ? upstreamOperands : ['.']);// `-Name` 输出相对名称 → 下游按它自己的 cwd 解析,并集加一个 `.` 候选(`null` 不得被降级)。upstreamOperands = enumeratorEmitsRelativeNames(tokens) && emitted !== null? [...emitted, '.']