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): close git dotenv search gaps

Chrisa2eb1c6d20d4
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 0c5dcad38e..1b8407b8fa 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
@@ -420,6 +420,16 @@ describe('对抗语料 — dotenv 凭证路径', () => {
'git show :0:.env',
"git diff -- ':(top).env'",
"git grep API_KEY -- ':(top).env.local'",
+ 'git show :.env',
+ 'git show :./.env.local',
+ 'git grep --untracked --no-exclude-standard .',
+ 'git grep --untracked --exclude-standard .',
+ 'git grep --no-index .',
+ 'git grep --untr --no-exclude-standard .',
+ 'git grep -in --untracked .',
+ 'env git --no-pager grep --untracked --no-exclude-standard .',
+ 'command git grep --no-index .',
+ 'git status --short && git grep --untracked .',
]) {
expect(classifyShellCommand(command, roots, opts)).toBe('prompt-each-time');
}
@@ -450,7 +460,18 @@ describe('对抗语料 — dotenv 凭证路径', () => {
['git cat-file -p HEAD:README.md', 'auto-approve'],
['git log --format=prefix:.env', 'auto-approve'],
['git show --format=prefix:.env HEAD', 'auto-approve'],
+ ["git show --format 'prefix:.env' HEAD", 'auto-approve'],
+ ["git log --pretty 'prefix:.env'", 'auto-approve'],
+ ["git show -- 'notes:.env'", 'auto-approve'],
+ ["git diff -- 'notes:.env'", 'auto-approve'],
["git diff -- ':(exclude).env'", 'auto-approve'],
+ ["git diff -- ':!.env'", 'auto-approve'],
+ ['git show :README.md', 'auto-approve'],
+ ['git show :./README.md', 'auto-approve'],
+ ['git grep . -- --untracked', 'auto-approve'],
+ ['git grep -e --untracked -- README.md', 'auto-approve'],
+ ['git grep -e--untracked -- README.md', 'auto-approve'],
+ ['git grep --regexp=--no-index -- README.md', 'auto-approve'],
] as const)('%s 保持既有 %s 档位', (command, expected) => {
expect(classifyShellCommand(command, roots, opts)).toBe(expected);
});
diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.ts
index 4c6690d334..3705709653 100644
--- a/packages/maker-core/src/agents/shared/auto-review.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.ts
@@ -4840,7 +4840,7 @@ function readerArgumentsReadDotenv(
if (!optionsEnded && /^-[^-]/.test(token)) {
let handled = false;
for (let optionIndex = 1; optionIndex < token.length; optionIndex += 1) {
- const kind = readerShortOptionKind(bin, token[optionIndex]);
+ const kind = readerShortOptionKind(bin, token.charAt(optionIndex));
if (!kind) continue;
const attached = token.slice(optionIndex + 1) || undefined;
const value = attached ?? args[index + 1];
@@ -4867,25 +4867,74 @@ function readerArgumentsReadDotenv(
return false;
}
+function gitGrepExpandsSearchScope(args: readonly string[]): boolean {
+ for (let index = 0; index < args.length; index += 1) {
+ const token = args[index];
+ if (token === '--') return false;
+
+ if (token.startsWith('--')) {
+ const equalsIndex = token.indexOf('=');
+ const name = equalsIndex >= 0 ? token.slice(0, equalsIndex) : token;
+ if ('--untracked'.startsWith(name) || '--no-index'.startsWith(name)) return true;
+
+ const kind = resolveReaderLongOption('grep', name);
+ if (kind && equalsIndex < 0) index += 1;
+ continue;
+ }
+
+ if (/^-[^-]/.test(token)) {
+ for (let optionIndex = 1; optionIndex < token.length; optionIndex += 1) {
+ const kind = readerShortOptionKind('grep', token.charAt(optionIndex));
+ if (!kind) continue;
+ if (optionIndex === token.length - 1) index += 1;
+ break;
+ }
+ }
+ }
+ return false;
+}
+
function isGitDotenvOperand(value: string): boolean {
if (isDotenvCredentialPath(value)) return true;
if (value.startsWith('-')) return false;
- const stagePath = /^:[0-3]:(.+)$/.exec(value);
- if (stagePath) return isDotenvCredentialPath(stagePath[1]);
-
const longPathspec = /^:\(([^)]*)\)(.+)$/.exec(value);
if (longPathspec) {
if (/(?:^|,)(?:exclude|!)(?:,|$)/.test(longPathspec[1])) return false;
return selectorCouldMatchDotenv(longPathspec[2]);
}
if (value.startsWith(':/')) return selectorCouldMatchDotenv(value.slice(2));
+ if (value.startsWith(':!') || value.startsWith(':^')) return false;
+
+ const indexPath = /^:(?:[0-3]:)?(.+)$/.exec(value);
+ return Boolean(indexPath && isDotenvCredentialPath(indexPath[1]));
+}
+function isGitRevisionDotenvOperand(value: string): boolean {
+ if (value.startsWith('-')) return false;
const revisionPathSeparator = value.indexOf(':');
return revisionPathSeparator > 0
&& isDotenvCredentialPath(value.slice(revisionPathSeparator + 1));
}
+function gitArgumentsReadDotenv(args: readonly string[]): boolean {
+ let pathspecOnly = false;
+ for (let index = 0; index < args.length; index += 1) {
+ const token = args[index];
+ if (token === '--') {
+ pathspecOnly = true;
+ continue;
+ }
+ if (!pathspecOnly && (token === '--format' || token === '--pretty')) {
+ index += 1;
+ continue;
+ }
+ if (isGitDotenvOperand(token)) return true;
+ if (!pathspecOnly && isGitRevisionDotenvOperand(token)) return true;
+ }
+ return false;
+}
+
function shellCommandReadsDotenv(
command: string,
workspaceRoots: string[],
@@ -4902,10 +4951,11 @@ function shellCommandReadsDotenv(
if (bin === 'git') {
const invocation = parseGitInvocation(tokens, workspaceRoots, opts);
- if (!invocation || !SAFE_GIT_SUBCOMMANDS.has(invocation.sub)) continue;
+ if (!invocation?.sub || !SAFE_GIT_SUBCOMMANDS.has(invocation.sub)) continue;
if (invocation.sub === 'grep') {
+ if (gitGrepExpandsSearchScope(invocation.args)) return true;
if (readerArgumentsReadDotenv('grep', invocation.args, isGitDotenvOperand)) return true;
- } else if (invocation.args.some(isGitDotenvOperand)) {
+ } else if (gitArgumentsReadDotenv(invocation.args)) {
return true;
}
continue;