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(pi): gate abbreviated status patches

Chris3cff329a9d4a
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts
index c4f3647fd0..7ea34a5cfa 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-policy.test.ts
@@ -46,6 +46,8 @@ describe('classifyPiToolForAutoReview', () => {
it('routes bash through the shell classifier', () => {
expect(verdict('bash', { command: 'ls -la' })).toBe('auto-approve');
expect(verdict('bash', { command: 'git status' })).toBe('auto-approve');
+ expect(verdict('bash', { command: 'git status --verb' })).toBe('prompt-each-time');
+ expect(verdict('bash', { command: 'git status --no-v' })).toBe('auto-approve');
expect(verdict('bash', { command: 'git log -L1,1:.env' })).toBe('prompt-each-time');
expect(verdict('bash', { command: 'git log -L 1,1:.env.local' })).toBe('prompt-each-time');
expect(verdict('bash', { command: 'git log -L1,1:README.md' })).toBe('auto-approve');
diff --git a/packages/maker-core/src/agents/shared/auto-review.adversarial.test.ts b/packages/maker-core/src/agents/shared/auto-review.adversarial.test.ts
index d77c2e9426..8d89e1b5c3 100644
--- a/packages/maker-core/src/agents/shared/auto-review.adversarial.test.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.adversarial.test.ts
@@ -584,6 +584,17 @@ describe('对抗语料 — dotenv 凭证路径', () => {
'git blame --cont .env.local README.md',
'git status -v',
'git status -vv',
+ 'git status --v',
+ 'git status --ve',
+ 'git status --ver',
+ 'git status --verb',
+ 'git status --verbo',
+ 'git status --verbose',
+ 'command git status --v',
+ 'env -- git status --verb',
+ 'git --no-pager status --verbo',
+ 'git -C /repo status --ve',
+ 'git status --verb -- .env',
'git show HEAD:.env.local',
'git cat-file -p HEAD:.env.production',
'git show :0:.env',
@@ -768,6 +779,14 @@ describe('对抗语料 — dotenv 凭证路径', () => {
['git blame --contents README.md src/index.ts', 'auto-approve'],
['git blame --cont=README.md src/index.ts', 'auto-approve'],
['git status --short', 'auto-approve'],
+ ['git status --no-v', 'auto-approve'],
+ ['git status --no-verb', 'auto-approve'],
+ ['git status --verbosex', 'auto-approve'],
+ ['git status --verb=1', 'auto-approve'],
+ ['git status --s', 'auto-approve'],
+ ['git status --sh', 'auto-approve'],
+ ['git status --sho', 'auto-approve'],
+ ['git status -- -v', 'auto-approve'],
['git log --format=prefix:.env', 'auto-approve'],
['git log --format=-L1,1:.env', 'auto-approve'],
['git log --stat', 'auto-approve'],
diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.ts
index de76e3f991..01ed6ce59f 100644
--- a/packages/maker-core/src/agents/shared/auto-review.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.ts
@@ -5350,6 +5350,31 @@ function gitCatFileReadsUnscopedContent(args: readonly string[]): boolean {
return contentMode && !objectArgs.some(isSafeGitObjectPath);
}
+// Git parse-options accepts unique long-option prefixes. Keep the complete status option
+// set here so ambiguous prefixes such as `--s` do not resolve to one arbitrary candidate.
+const GIT_STATUS_LONG_OPTIONS = [
+ '--verbose', '--short', '--branch', '--show-stash', '--ahead-behind', '--porcelain', '--long',
+ '--null', '--untracked-files', '--ignored', '--ignore-submodules', '--column', '--renames',
+ '--find-renames',
+] as const;
+
+function resolveGitStatusLongOption(name: string): typeof GIT_STATUS_LONG_OPTIONS[number] | null {
+ const exact = GIT_STATUS_LONG_OPTIONS.find((option) => option === name);
+ if (exact) return exact;
+ const matches = GIT_STATUS_LONG_OPTIONS.filter((option) => option.startsWith(name));
+ return matches.length === 1 ? matches[0] ?? null : null;
+}
+
+function gitStatusRequestsVerbose(args: readonly string[]): boolean {
+ for (const token of args) {
+ if (token === '--') break;
+ if (/^-[^-]*v/.test(token)) return true;
+ if (!token.startsWith('--') || token.includes('=') || token.startsWith('--no-')) continue;
+ if (resolveGitStatusLongOption(token) === '--verbose') return true;
+ }
+ return false;
+}
+
function gitContentReadWithoutPath(sub: string, args: readonly string[]): boolean {
if (sub === 'grep') return !gitGrepListsOnly(args);
if (sub === 'diff') return !gitMetadataOnlyRequested(args) || gitPatchRequested(args);
@@ -5360,7 +5385,7 @@ function gitContentReadWithoutPath(sub: string, args: readonly string[]): boolea
}
if (sub === 'log' || sub === 'whatchanged') return gitPatchRequested(args);
if (sub === 'cat-file') return gitCatFileReadsUnscopedContent(args);
- if (sub === 'status') return args.some((arg) => arg === '--verbose' || /^-[^-]*v/.test(arg));
+ if (sub === 'status') return gitStatusRequestsVerbose(args);
return false;
}