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 credential parser state gaps

Chrisc1825d2d7d97
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 3ab62cd188..ff32ee5702 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
@@ -384,6 +384,11 @@ describe('对抗语料 — dotenv 凭证路径', () => {
it('命令分段中的 dotenv 文件操作数一律要求确认', () => {
for (const command of [
'cat .env',
+ 'cat <.env',
+ 'cat <".env"',
+ 'cat 0<.env.local',
+ 'env -- cat <./.env.production',
+ 'grep API_KEY <.env.test',
'cat /repo/.env && true',
"cat /repo/.env | sed -n '1p'",
'cat /repo/.env ',
@@ -491,6 +496,10 @@ describe('对抗语料 — dotenv 凭证路径', () => {
'git grep .env -- data.json',
'git grep -- .env data.json',
'git grep -e API_KEY -- README.md',
+ 'git grep -l --no-files-with-matches API_KEY',
+ 'git grep --files-with-matches --no-name-only API_KEY',
+ 'git grep -L --no-files-without-match API_KEY',
+ 'git grep -l --no-name API_KEY',
'git grep -e-l',
'git grep -e -l',
'git grep -ne -l',
@@ -549,6 +558,12 @@ describe('对抗语料 — dotenv 凭证路径', () => {
it.each([
['cat .environment', 'auto-approve'],
+ ['cat <README.md', 'auto-approve'],
+ ["cat '<.env'", 'auto-approve'],
+ ['cat <<<.env', 'auto-approve'],
+ ['cat 0<README.md', 'auto-approve'],
+ ["grep '<.env' data.txt", 'auto-approve'],
+ ['grep KEY <data.txt', 'auto-approve'],
['cat config.env.local', 'auto-approve'],
['cat *', 'auto-approve'],
['cat *.env', 'auto-approve'],
@@ -618,6 +633,8 @@ describe('对抗语料 — dotenv 凭证路径', () => {
['git grep -l API_KEY', 'auto-approve'],
['git grep -L API_KEY', 'auto-approve'],
['git grep --files-with-matches API_KEY', 'auto-approve'],
+ ['git grep -l --no-files-with-matches --name-only API_KEY', 'auto-approve'],
+ ['git grep --no-name-only -L API_KEY', 'auto-approve'],
['git grep -e API_KEY -l', 'auto-approve'],
['git grep -f patterns.txt -L', 'auto-approve'],
['git show :README.md', '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 85caf3ec9e..61b393ab1a 100644
--- a/packages/maker-core/src/agents/shared/auto-review.ts
+++ b/packages/maker-core/src/agents/shared/auto-review.ts
@@ -4886,6 +4886,16 @@ function shellOperandCouldMatchDotenv(
});
}
+function inputRedirectionTargets(command: string): string[] {
+ const targets: string[] = [];
+ const re = /(?:^|[\s;&|()])(?:\d*|\{[A-Za-z_][A-Za-z0-9_]*\})?(?:<>|<(?![<&(]))\s*("(?:[^"\\]|\\.)*"|'[^']*'|[^\s;&|<>()]+)/g;
+ for (const match of command.matchAll(re)) {
+ const target = match[1].replace(/['"]/g, '');
+ if (target) targets.push(target);
+ }
+ return targets;
+}
+
function readerArgumentsReadDotenv(
bin: string,
args: readonly string[],
@@ -5127,7 +5137,30 @@ function gitArgumentsReadDotenv(args: readonly string[]): boolean {
return false;
}
+type GitGrepOutputMode = 'content' | 'files-only';
+
+const GIT_GREP_OUTPUT_OPTIONS: readonly { name: string; mode: GitGrepOutputMode }[] = [
+ { name: '--files-with-matches', mode: 'files-only' },
+ { name: '--files-without-match', mode: 'files-only' },
+ { name: '--name-only', mode: 'files-only' },
+ { name: '--no-files-with-matches', mode: 'content' },
+ { name: '--no-files-without-match', mode: 'content' },
+ { name: '--no-name-only', mode: 'content' },
+];
+
+function resolveGitGrepOutputMode(name: string): GitGrepOutputMode | null {
+ const exact = GIT_GREP_OUTPUT_OPTIONS.find((option) => option.name === name);
+ if (exact) return exact.mode;
+ const modes = new Set(
+ GIT_GREP_OUTPUT_OPTIONS
+ .filter((option) => option.name.startsWith(name))
+ .map((option) => option.mode),
+ );
+ return modes.size === 1 ? [...modes][0] ?? null : null;
+}
+
function gitGrepListsOnly(args: readonly string[]): boolean {
+ let outputMode: GitGrepOutputMode = 'content';
for (let tokenIndex = 0; tokenIndex < args.length; tokenIndex += 1) {
const token = args[tokenIndex];
if (token === '--') break;
@@ -5139,7 +5172,7 @@ function gitGrepListsOnly(args: readonly string[]): boolean {
if (equalsIndex < 0) tokenIndex += 1;
continue;
}
- if (token === '--files-with-matches' || token === '--files-without-match' || token === '--name-only') return true;
+ outputMode = resolveGitGrepOutputMode(name) ?? outputMode;
continue;
}
if (!/^-[^-]/.test(token)) continue;
@@ -5149,10 +5182,10 @@ function gitGrepListsOnly(args: readonly string[]): boolean {
if (optionIndex === token.length - 1) tokenIndex += 1;
break;
}
- if (option === 'l' || option === 'L') return true;
+ if (option === 'l' || option === 'L') outputMode = 'files-only';
}
}
- return false;
+ return outputMode === 'files-only';
}
const GIT_METADATA_ONLY_FLAGS = [
@@ -5255,6 +5288,7 @@ function shellCommandReadsDotenv(
}
if (!DOTENV_FILE_READER_BINS.has(bin)) continue;
+ if (inputRedirectionTargets(segment).some((target) => shellOperandCouldMatchDotenv(target))) return true;
const args = tokens.slice(1);
if (grepRecursesIntoPotentialDotenv(bin, args)) return true;
if (bin === 'rg' && rgSearchesPotentialDotenv(args)) return true;