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): 通配符目标整条按占位符归一;补 Tee-Object 写通道
Chris87fee41bf7db
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex c1e599d661..f35b0a89c7 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -2570,6 +2570,70 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评)).toBe('prompt-each-time');});+ it('通配符之后的 .. 跳转:整条按占位符归一,不能只看共同前缀', () => {+ // 早先这里取"第一个通配符之前的共同前缀"判在不在区内。那漏了**通配符之后的 `..`**:+ // `C:\repo\safe\*\..\..\..\Windows\…\hosts` 的共同前缀是 `C:\repo\safe\`,判成区内 → 灰区,+ // 而它实际写的是 hosts(codex 报)。我当时的注释还写着"模式里没有 `..`,normalizeTarget 会+ // 先折叠掉"—— 那句话只对前缀成立,对通配符**后面**那段不成立。+ //+ // 改法不是"再识别一下 `..`",而是把每个含通配符的**路径分量**换成一个不可折叠的占位符,+ // 然后走与普通目标完全相同的归一 + 判定链:`..` 由 normalizeSlashes 正常折叠,通配符分量也+ // 参与折叠。通配符不匹配 `.` / `..` 目录项,所以拿一个普通分量代表它是可靠的最坏边界。+ const win = ['C:\\repo'];+ for (const c of [+ 'Remove-Item C:\\repo\\safe\\*\\..\\..\\..\\Windows\\System32\\drivers\\etc\\hosts',+ 'Set-Content C:\\repo\\safe\\*\\..\\..\\..\\Windows\\System32\\drivers\\etc\\hosts owned',+ 'Remove-Item C:\\repo\\*\\..\\..\\Windows\\x',+ 'Copy-Item C:\\repo\\p C:\\repo\\safe\\*\\..\\..\\..\\Windows\\x', // 目标侧+ 'Remove-Item C:\\repo\\..\\Win*\\x', // `..` 在通配符之前+ 'Remove-Item C:\\repo\\safe\\?\\..\\..\\..\\Windows\\x', // `?` 同理+ 'Remove-Item "C:\\repo\\safe\\[ab]\\..\\..\\..\\Windows\\x"', // 字符组同理+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例一:通配符分量被 `..` **抵消**后仍在区内 → 灰区。占位符做法自动算对这一档,+ // 「先看前缀再单独识别 `..`」那种写法会把它误升级。+ expect(classifyShellCommand('Remove-Item C:\\repo\\a*\\..\\b', win, { platform: 'win32' }))+ .toBe('prompt');+ expect(classifyShellCommand('Remove-Item C:\\repo\\x\\*\\..\\..\\y', win, { platform: 'win32' }))+ .toBe('prompt');+ // 反例二:普通区内 glob 判档不变。+ for (const c of ['Remove-Item C:\\repo\\build\\*', 'Remove-Item *.log', 'Remove-Item C:\\repo\\dist\\*.tmp']) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');+ }+ });++ it('Tee-Object 是写通道;别名 tee 保持走 POSIX 分支的多目标语义', () => {+ // `Get-Content payload | Tee-Object -FilePath <系统路径>` 与 `… | tee <系统路径>` 是同一个+ // 写通道,但 `tee-object` 没登记 → 取不到目标、漏成灰区(codex 报)。+ const win = ['C:\\repo'];+ const hosts = 'C:\\Windows\\System32\\drivers\\etc\\hosts';+ for (const c of [+ `Get-Content payload | Tee-Object -FilePath ${hosts}`,+ `Get-Content payload | Tee-Object ${hosts}`, // 位置参数+ `Get-Content payload | Tee-Object -Append -FilePath ${hosts}`, // 开关不吃值+ `Tee-Object -FilePath ${hosts}`, // 不在管道右侧也算写通道+ `Get-Content payload | tee -FilePath ${hosts}`, // 别名 + 具名参数+ `Get-Content payload | tee ${hosts}`,+ ]) {+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');+ }++ // 反例一:区内目标与"根本不写文件"的形态仍是灰区。+ expect(classifyShellCommand('Get-Content payload | Tee-Object -FilePath C:\\repo\\a.txt', win, { platform: 'win32' }))+ .toBe('prompt');+ expect(classifyShellCommand('Get-Content payload | Tee-Object -Variable v', win, { platform: 'win32' }))+ .toBe('prompt');++ // 反例二(**回归**):别名 `tee` 只登记全名、不进 PowerShell 表 —— POSIX 的 tee 可以写多个+ // 文件,那条分支取**全部**操作数。若把 `tee` 也映射成 `targets: 'first'`,下面这条就只剩+ // 第一个目标、`/etc/hosts` 会漏掉,那是把既有覆盖面改小而不是补漏。+ expect(classifyShellCommand('echo x | tee a /etc/hosts', ['/repo'])).toBe('prompt-each-time');+ expect(classifyShellCommand('echo x | tee /etc/hosts', ['/repo'])).toBe('prompt-each-time');+ expect(classifyShellCommand('echo x | tee a b c', ['/repo'])).toBe('prompt');+ });+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 82daf07f08..38ccf4debf 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -329,6 +329,11 @@ const POWERSHELL_WRITE_CMDLETS: ReadonlyMap<['add-content', { targets: 'first' }],['new-item', { targets: 'first' }],['out-file', { targets: 'first' }], // 常在管道右侧:`'x' | Out-File <path>`+ // `Get-Content payload | Tee-Object -FilePath <path>` 与 `… | tee <path>` 是同一个写通道。+ // **只登记全名**:别名 `tee` 已经落在 POSIX 的 `tee`/`sponge` 分支(那条取**全部**操作数,+ // 因为 POSIX tee 可以写多个文件)。把 `tee` 加到这张表会让它改走 `targets: 'first'`,+ // `echo x | tee a b c` 就只剩第一个目标 —— 那是把既有覆盖面改小,不是补漏。+ ['tee-object', { targets: 'first' }],['clear-content', { targets: 'first' }],['set-itemproperty', { targets: 'first' }],['set-item', { targets: 'first' }],@@ -3081,22 +3086,25 @@ function systemWriteTargetsInSegment(const aliasFirmlinks = (opts.platform ?? process.platform) === 'darwin';const base = opts.cwd ?? workspaceRoots[0];return targets.some((t) => {- // 会展开的通配符目标(见 GLOB_WRITE_TARGET_PREFIX):静态上不是一条路径而是一组,- // 只有"所有可能结果的共同前缀在工作区内"才算可证安全,否则要求同意。+ // 会展开的通配符目标(见 GLOB_WRITE_TARGET_PREFIX):静态上不是一条路径而是一组。if (t.startsWith(GLOB_WRITE_TARGET_PREFIX)) {const pattern = t.slice(GLOB_WRITE_TARGET_PREFIX.length);// 通配符落在 provider 限定符里(`HK*:\SYSTEM\x`)→ 连"是哪个 provider"都证不出来。// 这类 drive 段带通配符的写法在真 PowerShell 里解析不出驱动器,但判据不能靠"它大概会报错"// 兜底 —— 与本文件其它不可证口径一致,直接要求同意。if (WILDCARD_IN_DRIVE_QUALIFIER.test(pattern)) return true;- const prefix = literalPrefixBeforeGlob(pattern);- // 前缀就是 provider 根时(`Cert:\LocalMachine\*` 的 `Cert:\LocalMachine\`)同样要判 ——- // 上面那道用整串判过了,这里兜住"通配符出现在更靠前位置"的写法。- if (isProtectedProviderPath(prefix)) return true;- if (opts.cwdUnknown && !isAbsolutePath(toForwardSlashes(prefix))) return true;- const resolved = canonicalPath(normalizeTarget(prefix, [base]), aliasFirmlinks);- // 前缀本身就落在系统目录(`C:\Windows\*`)→ 直接命中,不必再谈工作区。- if (isProtectedSystemPath(resolved)) return true;+ // 把每个**含通配符的路径分量**换成一个不可折叠的占位符,再走与普通目标完全相同的归一 ++ // 判定链。这样 `..` 由 normalizeSlashes 正常折叠,通配符分量也参与折叠 —— 于是+ // `C:\repo\safe\*\..\..\..\Windows\…\hosts` → `C:/Windows/…/hosts`(必问),+ // `C:\repo\a*\..\b` → `C:/repo/b`(灰区,通配被 `..` 抵消),+ // `C:\repo\build\*` → `C:/repo/build/<占位>`(灰区)。+ // 通配符**不匹配** `.` / `..` 目录项,所以拿一个普通分量代表它是可靠的最坏边界。+ const concrete = pattern.split(/([\\/])/)+ .map((part) => (POWERSHELL_WILDCARD.test(part) ? GLOB_COMPONENT_PLACEHOLDER : part))+ .join('');+ if (opts.cwdUnknown && !isAbsolutePath(toForwardSlashes(concrete))) return true;+ const resolved = canonicalPath(normalizeTarget(concrete, [base]), aliasFirmlinks);+ if (isProtectedProviderPath(resolved) || isProtectedSystemPath(resolved)) return true;return !isInsideWorkspace(resolved, workspaceRoots, aliasFirmlinks);}// 每个目标查两种形态:原样(保留 Windows `\` 分隔符)与去 POSIX `\` 转义(`/e\tc`→`/etc`)。@@ -3110,16 +3118,15 @@ function systemWriteTargetsInSegment(}/**- * 通配符模式里「所有可能展开结果的共同前缀」:第一个通配符之前的最后一个路径分隔符为止。- * PowerShell 的 `*`/`?`/`[...]` 都不跨分隔符,所以这个前缀对每个展开结果都成立。- * 模式整段就是通配符(`*.log`)时前缀为空 → 由调用方按有效 cwd 解析。+ * 代表「一个含通配符的路径分量」的占位符。要求:归一化时不会被折叠(不是 `.` / `..` / 空)、+ * 不可能命中受保护路径判据、也不可能出现在真实路径里。+ *+ * 早先这里是"取第一个通配符之前的共同前缀"。那个做法漏了**通配符之后的 `..`**:+ * `Remove-Item C:\repo\safe\*\..\..\..\Windows\System32\drivers\etc\hosts` 的共同前缀是+ * `C:\repo\safe\`,判成区内 → 灰区,而它实际写的是 hosts(codex 报)。换成占位符后整条路径+ * 一起归一,`..` 正常折叠,不需要单独识别 `..`,也顺带修正了通配被 `..` 抵消的情形。*/-function literalPrefixBeforeGlob(pattern: string): string {- const first = pattern.search(POWERSHELL_WILDCARD);- const head = first < 0 ? pattern : pattern.slice(0, first);- const cut = Math.max(head.lastIndexOf('/'), head.lastIndexOf('\\'));- return cut < 0 ? '.' : head.slice(0, cut + 1);-}+const GLOB_COMPONENT_PLACEHOLDER = '\u0000globpart';/** 系统/区外批量破坏与受保护分支强推不能只交给模型裁决。 */function scopedDestructionNeedsConsent(