Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(auto-review): FileSystem:: 剥离提到 glob/非 glob 分支之前的唯一入口

Chris8fcdcd6aabb0
diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.ts
index b1cdd02a9a..96eebb69ec 100644
--- a/packages/maker-core/src/agents/shared/auto-review.test.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts
@@ -2849,6 +2849,48 @@ describe('参数形式的系统路径写入 / setsid 选项(第三十五批评
.toBe('prompt-each-time');
});
+ it('FileSystem:: 限定符 + 通配符组合:剥离点必须在 glob/非 glob 两条分支之前', () => {
+ // 上一轮只在**非 glob** 那条分支里剥 `FileSystem::`,于是限定符 + 通配符的组合照旧漏:
+ // `FileSystem::C:\Win*\System32\…` 里 `FileSystem::C:` 不是单字母盘符 → 被当相对路径锚到
+ // 工作区下,真实的系统删除落到灰区(codex 报)。
+ // 修法不是在 glob 分支再补一次剥离,而是把剥离提到**两条分支之前的唯一入口** —— 以后再加
+ // 分支也不会漏。registry / certificate 的结论由 provider 判据单独给出,不能剥(见反例组)。
+ const win = ['C:\\repo'];
+ for (const c of [
+ 'Remove-Item FileSystem::C:\\Win*\\System32\\drivers\\etc\\hosts',
+ 'Set-Content FileSystem::C:\\Win*\\System32\\drivers\\etc\\hosts owned',
+ 'Remove-Item filesystem::C:\\Win*\\System32\\x', // 大小写
+ 'Remove-Item Microsoft.PowerShell.Core\\FileSystem::C:\\Win*\\System32\\x', // 完整 provider 名
+ 'Remove-Item FileSystem::C:\\Windows\\System32\\*', // 通配在末段
+ // 通配符之后还接 `..` 跳转 —— 占位符归一那条判据要能在剥掉限定符后照常生效。
+ 'Remove-Item FileSystem::C:\\repo\\safe\\*\\..\\..\\..\\Windows\\System32\\x',
+ 'Copy-Item C:\\repo\\p FileSystem::C:\\Win*\\x', // 目标侧
+ 'Export-Csv -Path FileSystem::C:\\Win*\\System32\\x', // 其它写 cmdlet
+ 'pwsh -Command Remove-Item FileSystem::C:\\Win*\\System32\\x', // 载荷下探
+ ]) {
+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt-each-time');
+ }
+
+ // 反例一:registry / certificate 限定符**不能**被当文件路径剥掉 —— 剥了就丢 provider 身份。
+ expect(classifyShellCommand('Remove-Item Registry::HKEY_LOCAL_MACHINE\\SYSTEM\\*', win, { platform: 'win32' }))
+ .toBe('prompt-each-time');
+ expect(classifyShellCommand('Remove-Item Certificate::LocalMachine\\Root\\*', win, { platform: 'win32' }))
+ .toBe('prompt-each-time');
+ // 反例二:区内目标判档不变(剥离只让判据看见真实路径,不改口径)。
+ for (const c of [
+ 'Remove-Item FileSystem::C:\\repo\\build\\*',
+ 'Remove-Item FileSystem::C:\\repo\\a.txt',
+ 'Remove-Item C:\\repo\\build\\*',
+ 'Remove-Item FileSystem::C:\\repo\\a*\\..\\b', // 通配被 `..` 抵消后仍在区内
+ ]) {
+ expect(classifyShellCommand(c, win, { platform: 'win32' }), c).toBe('prompt');
+ }
+ // 反例三:非 glob 的限定符形态仍必问(上一轮的回归基线)。
+ expect(classifyShellCommand(
+ 'Remove-Item FileSystem::C:\\Windows\\System32\\drivers\\etc\\hosts', win, { platform: 'win32' },
+ )).toBe('prompt-each-time');
+ });
+
it('curl/wget 在 PowerShell 里是 iwr 别名:-OutFile 与 POSIX -o/-O 取并集', () => {
// Windows PowerShell 里 `curl` / `wget` 是 Invoke-WebRequest 的别名,落地参数写成 `-OutFile`,
// 而这两个 bin 走的是 POSIX 分支(只认 `-o`/`-O`/`--output`)→ 受保护落地漏掉(codex 报)。
diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.ts
index e7f4eb8307..d0d0a91473 100644
--- a/packages/maker-core/src/agents/shared/auto-review.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.ts
@@ -3215,10 +3215,19 @@ function systemWriteTargetsInSegment(
const aliasFirmlinks = (opts.platform ?? process.platform) === 'darwin';
const base = opts.cwd ?? workspaceRoots[0];
return targets.some((rawTarget) => {
+ const isGlob = rawTarget.startsWith(GLOB_WRITE_TARGET_PREFIX);
+ // **两条分支之前只剥一次**:`FileSystem::C:\Windows\…` 的 provider 限定符必须在任何归一之前
+ // 去掉 —— normalizeTarget 只认单字母盘符,会把整串当相对路径拼到工作区下
+ // (`C:/repo/FileSystem::C:/Windows/…`),此后再怎么判都看不出它是系统路径。
+ // 上一轮只在下面的非 glob 分支里剥,于是 `FileSystem::C:\Win*\System32\…` 这类
+ // **限定符 + 通配符**的组合照旧漏掉(codex 报)。剥离点提到分支之前,glob 与非 glob 同时覆盖,
+ // 以后再加分支也不会漏。registry / certificate 的结论已在上面单独给出,不能剥。
+ const t = stripFileSystemQualifier(isGlob
+ ? rawTarget.slice(GLOB_WRITE_TARGET_PREFIX.length)
+ : rawTarget);
// 会展开的通配符目标(见 GLOB_WRITE_TARGET_PREFIX):静态上不是一条路径而是一组。
- if (rawTarget.startsWith(GLOB_WRITE_TARGET_PREFIX)) {
- const t = rawTarget;
- const pattern = t.slice(GLOB_WRITE_TARGET_PREFIX.length);
+ if (isGlob) {
+ const pattern = t;
// 通配符落在 provider 限定符里(`HK*:\SYSTEM\x`)→ 连"是哪个 provider"都证不出来。
// 这类 drive 段带通配符的写法在真 PowerShell 里解析不出驱动器,但判据不能靠"它大概会报错"
// 兜底 —— 与本文件其它不可证口径一致,直接要求同意。
@@ -3237,10 +3246,6 @@ function systemWriteTargetsInSegment(
if (isProtectedProviderPath(resolved) || isProtectedSystemPath(resolved)) return true;
return !isInsideWorkspace(resolved, workspaceRoots, aliasFirmlinks);
}
- // `FileSystem::C:\Windows\…` 的 provider 限定符必须在**归一之前**剥掉:normalizeTarget 只认
- // 单字母盘符,会把整串当相对路径拼到工作区下(`C:/repo/FileSystem::C:/Windows/…`),此后再怎么判
- // 都看不出它是系统路径(codex 报)。registry / certificate 那两个 provider 已在上面给出结论。
- const t = stripFileSystemQualifier(rawTarget);
// 每个目标查三种形态:原样(保留 Windows `\` 分隔符)、去 POSIX `\` 转义(`/e\tc`→`/etc`)、
// 去 PowerShell 反引号转义。后者是 codex 报的绕过:PowerShell 里 `` ` `` 转义下一个字符,
// 所以 ``C:\Win`dows\System32\drivers\etc\hosts`` 运行时就是 hosts,但判据要匹配字面