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 git line-log credential reads
Chris387a4141c750
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 1e2ef2018e..c4f3647fd0 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,9 @@ 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 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: '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 352c653121..d77c2e9426 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@@ -559,6 +559,15 @@ describe('对抗语料 — dotenv 凭证路径', () => {"git show -- 'notes:.env'",'git log -p','git log --patch',+ 'git log -L1,1:.env',+ 'git log -L 1,1:.env.local',+ 'git log -L:dotenv:.env.production',+ 'git log -L :dotenv:.env.test',+ 'git log -L/foo:bar/,/baz:qux/:.env',+ 'git log -L1,1:.env{,.local}',+ 'git whatchanged -L1,1:.env',+ 'git whatchanged -L 1,1:.env.local',+ 'git show -L1,1:.env','git whatchanged -p','git cat-file -p HEAD','git cat-file blob HEAD',@@ -760,7 +769,16 @@ describe('对抗语料 — dotenv 凭证路径', () => {['git blame --cont=README.md src/index.ts', 'auto-approve'],['git status --short', 'auto-approve'],['git log --format=prefix:.env', 'auto-approve'],+ ['git log --format=-L1,1:.env', 'auto-approve'],['git log --stat', 'auto-approve'],+ ['git log -L1,1:README.md', 'auto-approve'],+ ['git log -L 1,1:README.md', 'auto-approve'],+ ['git log -L:heading:README.md', 'auto-approve'],+ ['git log -L/foo:bar/,/baz:qux/:README.md', 'auto-approve'],+ ['git log -L1,1:.environment', 'auto-approve'],+ ['git log -L1,1:notes:.env', 'auto-approve'],+ ['git log -- -L1,1:.env', 'auto-approve'],+ ['git whatchanged -L1,1:README.md', 'auto-approve'],['git whatchanged', 'auto-approve'],["git log --pretty 'prefix:.env'", 'auto-approve'],['git grep -l API_KEY', 'auto-approve'],diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 4b1894f4a2..de76e3f991 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -5176,6 +5176,53 @@ function gitBlameContentsReadDotenv(args: readonly string[]): boolean {return false;}+/**+ * `-L` uses `<range>:<file>`: regex ranges may contain colons inside `/.../`, while+ * function ranges begin with `:` and use the next unescaped colon as the separator.+ */+function gitLineRangeFile(value: string): string | null {+ let escaped = false;+ if (value.startsWith(':')) {+ for (let index = 1; index < value.length; index += 1) {+ const char = value.charAt(index);+ if (escaped) { escaped = false; continue; }+ if (char === '\\') { escaped = true; continue; }+ if (char === ':') return value.slice(index + 1);+ }+ return null;+ }++ let inRegex = false;+ for (let index = 0; index < value.length; index += 1) {+ const char = value.charAt(index);+ if (escaped) { escaped = false; continue; }+ if (char === '\\') { escaped = true; continue; }+ if (char === '/') { inRegex = !inRegex; continue; }+ if (char === ':' && !inRegex) return value.slice(index + 1);+ }+ return null;+}++function gitLineRangeReadsDotenv(args: readonly string[]): boolean {+ for (let index = 0; index < args.length; index += 1) {+ const token = args[index];+ if (token === '--') break;+ let value: string | undefined;+ if (token === '-L') {+ value = args[index + 1];+ index += 1;+ } else if (token.startsWith('-L')) {+ value = token.slice(2);+ } else {+ continue;+ }+ if (!value) return true;+ const file = gitLineRangeFile(value);+ if (file === null || shellOperandCouldMatchDotenv(file, isGitDotenvOperand)) return true;+ }+ return false;+}+function gitArgumentsReadDotenv(args: readonly string[]): boolean {let pathspecOnly = false;for (let index = 0; index < args.length; index += 1) {@@ -5347,6 +5394,8 @@ function shellCommandReadsDotenv(if (gitGrepExpandsSearchScope(invocation.args)) return true;if (readerArgumentsReadDotenv('grep', invocation.args, isGitDotenvOperand)) return true;} else if ((invocation.sub === 'blame' && gitBlameContentsReadDotenv(invocation.args))+ || ((invocation.sub === 'log' || invocation.sub === 'whatchanged' || invocation.sub === 'show')+ && gitLineRangeReadsDotenv(invocation.args))|| gitArgumentsReadDotenv(invocation.args)) {return true;}