Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(pi): gate ag hidden credential searches
Chris73c7d36f5f58
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.tsindex 7ea34a5cfa..67ce81a4ae 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@@ -51,6 +51,9 @@ describe('classifyPiToolForAutoReview', () => {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');+ expect(verdict('bash', { command: 'ag -u API_KEY .' })).toBe('prompt-each-time');+ expect(verdict('bash', { command: 'ag --hidden API_KEY .' })).toBe('prompt-each-time');+ expect(verdict('bash', { command: 'ag API_KEY ordinary.txt' })).toBe('auto-approve');expect(verdict('bash', { command: 'sudo whoami' })).toBe('prompt-each-time');// Destructive but replaceable actions are gray: the current-model reviewer// should block or ask with the actual user intent instead of always interrupting.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.tsindex 2dd109e2d5..e9b703d4bb 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@@ -441,6 +441,24 @@ describe('对抗语料 — dotenv 凭证路径', () => {'date --ref .env.local','ag --path-to-ignore=.env needle .','ag --path-to-i .env.local needle .',+ "ag --file-search-regex '.env' API_KEY .",+ 'ag --hidden --no-recurse API_KEY .env',+ 'ag -u API_KEY .',+ 'ag -uuu API_KEY .',+ 'ag --hidden API_KEY .',+ 'ag --hid API_KEY .',+ 'ag --unrestricted API_KEY .',+ 'ag --unr API_KEY .',+ 'ag --u API_KEY .',+ 'ag --hidden --ignore .env API_KEY .',+ 'ag --hidden --ignore-dir .git API_KEY .',+ 'ag --after --hidden API_KEY .',+ 'ag --after=2 --hidden API_KEY .',+ 'ag --hidden --no-recurse --recurse API_KEY .',+ 'ag -unr API_KEY .',+ 'ag -Gbook -u API_KEY .',+ 'env -- ag -u API_KEY .',+ 'command ag --hidden API_KEY .','tree --infofile=.env','tree --infof .env.local','wc --files0-from=.env',@@ -745,6 +763,18 @@ describe('对抗语料 — dotenv 凭证路径', () => {['date .env', 'auto-approve'],['ag --path-to-ignore=README.md needle .', 'auto-approve'],['ag --path-to-i README.md needle .', 'auto-approve'],+ ['ag API_KEY ordinary.txt', 'auto-approve'],+ ['ag -U API_KEY .', 'auto-approve'],+ ['ag --skip-vcs-ignores API_KEY .', 'auto-approve'],+ ['ag -G --hidden API_KEY .', 'auto-approve'],+ ['ag --ignore --hidden API_KEY .', 'auto-approve'],+ ['ag --pager --hidden API_KEY .', 'auto-approve'],+ ['ag --ackmate-dir-filter --hidden API_KEY .', 'auto-approve'],+ ['ag -A --hidden API_KEY .', 'auto-approve'],+ ['ag --hidden --no-recurse API_KEY .', 'auto-approve'],+ ['ag --hidden --norecurse API_KEY .', 'auto-approve'],+ ['ag -un API_KEY .', 'auto-approve'],+ ["ag -u -g '.env'", 'auto-approve'],['tree --infofile=README.md', 'auto-approve'],['tree --infof README.md', 'auto-approve'],['wc --files0-from=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.tsindex 12f958a537..f3989e34fe 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -4808,6 +4808,9 @@ const DATE_LONG_OPTIONS: readonly ReaderLongOption[] = [{ name: '--reference', kind: 'aux-file' },];const AG_LONG_OPTIONS: readonly ReaderLongOption[] = [+ { name: '--file-search-regex', kind: 'selector' },+ { name: '--ignore', kind: 'filter' },+ { name: '--ignore-dir', kind: 'filter' },{ name: '--path-to-ignore', kind: 'aux-file' },];const TREE_LONG_OPTIONS: readonly ReaderLongOption[] = [@@ -5311,6 +5314,88 @@ function rgCustomTypeCouldMatchCredential(rgCustomTypeCouldMatchCredential(included, definitions, nextVisiting));}+type AgScopeOptionKind =+ | 'hidden'+ | 'recursive'+ | 'non-recursive'+ | 'value'+ | 'optional-value'+ | 'filename-only'+ | 'flag';++const AG_SCOPE_LONG_OPTIONS: ReadonlyArray<{ name: string; kind: AgScopeOptionKind }> = [+ { name: '--ackmate-dir-filter', kind: 'value' },+ { name: '--after', kind: 'optional-value' },+ { name: '--before', kind: 'optional-value' },+ { name: '--color-line-number', kind: 'value' },+ { name: '--color-match', kind: 'value' },+ { name: '--color-path', kind: 'value' },+ { name: '--context', kind: 'optional-value' },+ { name: '--depth', kind: 'value' },+ { name: '--filename-pattern', kind: 'filename-only' },+ { name: '--file-search-regex', kind: 'value' },+ { name: '--heading', kind: 'flag' },+ { name: '--help', kind: 'flag' },+ { name: '--hidden', kind: 'hidden' },+ { name: '--ignore', kind: 'value' },+ { name: '--ignore-case', kind: 'flag' },+ { name: '--ignore-dir', kind: 'value' },+ { name: '--max-count', kind: 'value' },+ { name: '--no-recurse', kind: 'non-recursive' },+ { name: '--norecurse', kind: 'non-recursive' },+ { name: '--pager', kind: 'value' },+ { name: '--path-to-ignore', kind: 'value' },+ { name: '--recurse', kind: 'recursive' },+ { name: '--unrestricted', kind: 'hidden' },+ { name: '--width', kind: 'value' },+ { name: '--workers', kind: 'value' },+];+const AG_VALUE_SHORT_OPTIONS: ReadonlySet<string> = new Set(['A', 'B', 'C', 'G', 'm', 'p', 'W']);++function agSearchesPotentialCredential(args: readonly string[]): boolean {+ let hidden = false;+ let recursive = true;+ let filenameOnly = false;++ for (let index = 0; index < args.length; index += 1) {+ const token = args[index];+ if (token === '--') break;++ if (token.startsWith('--')) {+ const equalsIndex = token.indexOf('=');+ const name = equalsIndex >= 0 ? token.slice(0, equalsIndex) : token;+ const exact = AG_SCOPE_LONG_OPTIONS.find((option) => option.name === name);+ const matches = exact+ ? [exact]+ : AG_SCOPE_LONG_OPTIONS.filter((option) => option.name.startsWith(name));+ const option = matches.length === 1 ? matches[0] : null;+ if (!option) continue;+ if (option.kind === 'hidden') hidden = true;+ if (option.kind === 'recursive') recursive = true;+ if (option.kind === 'non-recursive') recursive = false;+ if (option.kind === 'filename-only') filenameOnly = true;+ if ((option.kind === 'value' || option.kind === 'filename-only') && equalsIndex < 0) index += 1;+ continue;+ }++ if (!/^-[^-]/.test(token)) continue;+ for (let optionIndex = 1; optionIndex < token.length; optionIndex += 1) {+ const option = token.charAt(optionIndex);+ if (option === 'u') hidden = true;+ if (option === 'n') recursive = false;+ if (option === 'r' || option === 'R') recursive = true;+ if (option === 'g') filenameOnly = true;+ if (option !== 'g' && !AG_VALUE_SHORT_OPTIONS.has(option)) continue;+ if (optionIndex === token.length - 1) index += 1;+ break;+ }+ }++ // Explicit ignore patterns only subtract candidates and cannot prove that the+ // complete credential language is excluded. Unrestricted mode ignores them.+ return hidden && recursive && !filenameOnly;+}+function rgSearchesPotentialDotenv(args: readonly string[]): boolean {let hidden = false;let unrestricted = 0;@@ -5729,6 +5814,7 @@ function shellCommandReadsDotenv(if (readsCredentialInput) return true;const args = tokens.slice(1);if (grepRecursesIntoPotentialDotenv(bin, args)) return true;+ if (bin === 'ag' && agSearchesPotentialCredential(args)) return true;if (bin === 'rg' && rgSearchesPotentialDotenv(args)) return true;if (readerArgumentsReadDotenv(bin, args, isDotenvCredentialPath, opts.platform ?? process.platform)) return true;}