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 reader file options
Chris6bab1c79d6ca
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 4f4fbb89d0..2b134988e4 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@@ -426,6 +426,32 @@ describe('对抗语料 — dotenv 凭证路径', () => {'file --files-from=.env','file --files-from .env.local','file --files-f=.env.production',+ 'file --magic-file=.env',+ 'file --magic-file=README.md:.env',+ 'file --magic-f .env.local',+ 'file -mREADME.md:.env.production',+ 'file -M .env.test',+ 'date --file=.env',+ 'date --fi .env.local',+ 'date --reference=.env',+ 'date --ref .env.local',+ 'ag --path-to-ignore=.env needle .',+ 'ag --path-to-i .env.local needle .',+ 'tree --infofile=.env',+ 'tree --infof .env.local',+ 'wc --files0-from=.env',+ 'wc --files0-from .env.local',+ 'wc --files0-f=.env.production',+ 'sort --files0-from=.env',+ 'sort --files0-from .env.local',+ 'sort --files0-f=.env.production',+ 'sort --random-source=.env',+ 'sort --random-sou .env.local',+ 'du --files0-from=.env',+ 'du --files0-from .env.local',+ 'du --files0-f=.env.production',+ 'du --exclude-from=.env',+ 'du --exclude-f .env.local','diff --from-file .env.local /dev/null','diff --from-f=.env.production /dev/null','diff --to-file=.env.test /dev/null',@@ -581,6 +607,19 @@ describe('对抗语料 — dotenv 凭证路径', () => {expect(classifyShellCommand(command, roots, opts)).toBe('prompt');});+ it('date 短选项按平台区分 GNU 文件值与 macOS 数据值', () => {+ expect(classifyShellCommand('date -f .env 0', roots, { ...opts, platform: 'linux' }))+ .toBe('prompt-each-time');+ expect(classifyShellCommand('date -r.env', roots, { ...opts, platform: 'linux' }))+ .toBe('prompt-each-time');+ expect(classifyShellCommand('date -f .env 0', roots, { ...opts, platform: 'darwin' }))+ .toBe('auto-approve');+ expect(classifyShellCommand('date -r .env', roots, { ...opts, platform: 'darwin' }))+ .toBe('auto-approve');+ expect(classifyShellCommand('date -d.env', roots, { ...opts, platform: 'linux' }))+ .toBe('auto-approve');+ });+it('brace expansion 在全局候选预算内惰性遍历,超限时 fail-closed', () => {const explosiveOperand = Array.from({ length: 8 },@@ -626,6 +665,34 @@ describe('对抗语料 — dotenv 凭证路径', () => {['file --files-from=README.md', 'auto-approve'],['file --files-from README.md', 'auto-approve'],['file --files-f=README.md', 'auto-approve'],+ ['file --magic-file=README.md', 'auto-approve'],+ ['file --magic-file=README.md:OTHER', 'auto-approve'],+ ['file --magic-f README.md', 'auto-approve'],+ ['file -mREADME.md:OTHER', 'auto-approve'],+ ['file -M README.md', 'auto-approve'],+ ['file -Fm.env README.md', 'auto-approve'],+ ['file -F.env README.md', 'auto-approve'],+ ['file -Pname=.env README.md', 'auto-approve'],+ ['file -em.env README.md', 'auto-approve'],+ ['date --file=README.md', 'auto-approve'],+ ['date --fi README.md', 'auto-approve'],+ ['date --reference=README.md', 'auto-approve'],+ ['date --ref README.md', 'auto-approve'],+ ['date .env', 'auto-approve'],+ ['ag --path-to-ignore=README.md needle .', 'auto-approve'],+ ['ag --path-to-i README.md needle .', 'auto-approve'],+ ['tree --infofile=README.md', 'auto-approve'],+ ['tree --infof README.md', 'auto-approve'],+ ['wc --files0-from=README.md', 'auto-approve'],+ ['wc --files0-from README.md', 'auto-approve'],+ ['wc --files0-f=README.md', 'auto-approve'],+ ['sort --files0-from=README.md', 'auto-approve'],+ ['sort --files0-from README.md', 'auto-approve'],+ ['sort --random-source=README.md', 'auto-approve'],+ ['du --files0-from=README.md', 'auto-approve'],+ ['du --files0-from README.md', 'auto-approve'],+ ['du --exclude-from=README.md', 'auto-approve'],+ ['du --exclude=.env src', 'auto-approve'],['column data.csv', 'auto-approve'],['grep --regexp=. data.json', 'auto-approve'],['grep -e.env data.json', 'auto-approve'],diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 36d32759ea..278e7726a2 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -168,7 +168,7 @@ const DOTENV_FILE_READER_BINS: ReadonlySet<string> = new Set(['cat', 'head', 'tail', 'wc', 'stat', 'file', 'realpath', 'readlink','grep', 'egrep', 'fgrep', 'rg', 'ag', 'find', 'tree', 'du','diff', 'cmp', 'sort', 'uniq', 'cut', 'tr', 'column', 'nl', 'tac',- 'jq', 'yq', 'base64', 'md5', 'md5sum', 'sha256sum', 'cksum', 'sed',+ 'jq', 'yq', 'base64', 'md5', 'md5sum', 'sha256sum', 'cksum', 'sed', 'date',]);@@ -4733,10 +4733,10 @@ export function commandExecutableNames(command: string): string[] {}const FIRST_DATA_ARGUMENT_BINS: ReadonlySet<string> = new Set([- 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'sed', 'jq', 'yq',+ 'grep', 'egrep', 'fgrep', 'rg', 'ag', 'sed', 'jq', 'yq', 'date',]);-type ReaderOptionKind = 'data' | 'data-file' | 'selector' | 'filter' | 'aux-file';+type ReaderOptionKind = 'data' | 'data-file' | 'selector' | 'filter' | 'aux-file' | 'aux-file-list';type ReaderLongOption = { name: string; kind: ReaderOptionKind };const GREP_LONG_OPTIONS: readonly ReaderLongOption[] = [@@ -4767,6 +4767,29 @@ const DIFF_LONG_OPTIONS: readonly ReaderLongOption[] = [];const FILE_LONG_OPTIONS: readonly ReaderLongOption[] = [{ name: '--files-from', kind: 'data-file' },+ { name: '--magic-file', kind: 'aux-file-list' },+];+const FILES0_FROM_LONG_OPTIONS: readonly ReaderLongOption[] = [+ { name: '--files0-from', kind: 'data-file' },+];+const DU_LONG_OPTIONS: readonly ReaderLongOption[] = [+ ...FILES0_FROM_LONG_OPTIONS,+ { name: '--exclude', kind: 'filter' },+ { name: '--exclude-from', kind: 'aux-file' },+];+const SORT_LONG_OPTIONS: readonly ReaderLongOption[] = [+ ...FILES0_FROM_LONG_OPTIONS,+ { name: '--random-source', kind: 'aux-file' },+];+const DATE_LONG_OPTIONS: readonly ReaderLongOption[] = [+ { name: '--file', kind: 'data-file' },+ { name: '--reference', kind: 'aux-file' },+];+const AG_LONG_OPTIONS: readonly ReaderLongOption[] = [+ { name: '--path-to-ignore', kind: 'aux-file' },+];+const TREE_LONG_OPTIONS: readonly ReaderLongOption[] = [+ { name: '--infofile', kind: 'aux-file' },];function readerLongOptions(bin: string): readonly ReaderLongOption[] {@@ -4776,6 +4799,12 @@ function readerLongOptions(bin: string): readonly ReaderLongOption[] {if (bin === 'jq' || bin === 'yq') return JQ_LONG_OPTIONS;if (bin === 'diff') return DIFF_LONG_OPTIONS;if (bin === 'file') return FILE_LONG_OPTIONS;+ if (bin === 'wc') return FILES0_FROM_LONG_OPTIONS;+ if (bin === 'du') return DU_LONG_OPTIONS;+ if (bin === 'sort') return SORT_LONG_OPTIONS;+ if (bin === 'date') return DATE_LONG_OPTIONS;+ if (bin === 'ag') return AG_LONG_OPTIONS;+ if (bin === 'tree') return TREE_LONG_OPTIONS;return [];}@@ -4791,7 +4820,11 @@ function resolveReaderLongOption(bin: string, name: string): ReaderOptionKind |return kinds.size === 1 ? candidates[0]?.kind ?? null : null;}-function readerShortOptionKind(bin: string, option: string): ReaderOptionKind | null {+function readerShortOptionKind(+ bin: string,+ option: string,+ platform: NodeJS.Platform = process.platform,+): ReaderOptionKind | null {if (bin === 'grep' || bin === 'egrep' || bin === 'fgrep' || bin === 'sed') {if (option === 'e') return 'data';if (option === 'f') return 'data-file';@@ -4804,6 +4837,12 @@ function readerShortOptionKind(bin: string, option: string): ReaderOptionKind |if ((bin === 'jq' || bin === 'yq') && option === 'f') return 'data-file';if (bin === 'ag' && option === 'G') return 'selector';if (bin === 'file' && option === 'f') return 'data-file';+ if (bin === 'file' && (option === 'm' || option === 'M')) return 'aux-file-list';+ if (bin === 'file' && (option === 'e' || option === 'F' || option === 'P')) return 'data';+ if (bin === 'date' && option === 'f') return platform === 'darwin' ? 'data' : 'data-file';+ if (bin === 'date' && option === 'r') return platform === 'darwin' ? 'data' : 'aux-file';+ if (bin === 'date' && (option === 'd' || option === 'I' || option === 's'+ || option === 'v' || option === 'z')) return 'data';return null;}@@ -4891,10 +4930,22 @@ function shellOperandCouldMatchDotenv(});}+function readerOptionValueIsSensitive(+ kind: ReaderOptionKind,+ value: string | undefined,+ isSensitiveOperand: (value: string) => boolean,+): boolean {+ if (kind === 'selector') return selectorCouldMatchDotenv(value ?? '');+ if (!value || (kind !== 'data-file' && kind !== 'aux-file' && kind !== 'aux-file-list')) return false;+ const operands = kind === 'aux-file-list' ? value.split(/[:;]/) : [value];+ return operands.some((operand) => shellOperandCouldMatchDotenv(operand, isSensitiveOperand));+}+function readerArgumentsReadDotenv(bin: string,args: readonly string[],isSensitiveOperand: (value: string) => boolean = isDotenvCredentialPath,+ platform: NodeJS.Platform = process.platform,): boolean {let dataArgumentProvided = !FIRST_DATA_ARGUMENT_BINS.has(bin);let optionsEnded = false;@@ -4913,10 +4964,7 @@ function readerArgumentsReadDotenv(if (kind) {const attached = equalsIndex >= 0 ? token.slice(equalsIndex + 1) : undefined;const value = attached ?? args[index + 1];- const isSensitive = kind === 'selector'- ? selectorCouldMatchDotenv(value ?? '')- : (kind === 'data-file' || kind === 'aux-file')- && Boolean(value && shellOperandCouldMatchDotenv(value, isSensitiveOperand));+ const isSensitive = readerOptionValueIsSensitive(kind, value, isSensitiveOperand);if (kind !== 'data' && isSensitive) return true;if (attached === undefined) index += 1;if (kind === 'data' || kind === 'data-file') dataArgumentProvided = true;@@ -4927,14 +4975,11 @@ function readerArgumentsReadDotenv(if (!optionsEnded && /^-[^-]/.test(token)) {let handled = false;for (let optionIndex = 1; optionIndex < token.length; optionIndex += 1) {- const kind = readerShortOptionKind(bin, token.charAt(optionIndex));+ const kind = readerShortOptionKind(bin, token.charAt(optionIndex), platform);if (!kind) continue;const attached = token.slice(optionIndex + 1) || undefined;const value = attached ?? args[index + 1];- const isSensitive = kind === 'selector'- ? selectorCouldMatchDotenv(value ?? '')- : (kind === 'data-file' || kind === 'aux-file')- && Boolean(value && shellOperandCouldMatchDotenv(value, isSensitiveOperand));+ const isSensitive = readerOptionValueIsSensitive(kind, value, isSensitiveOperand);if (kind !== 'data' && isSensitive) return true;if (attached === undefined) index += 1;if (kind === 'data' || kind === 'data-file') dataArgumentProvided = true;@@ -5312,7 +5357,7 @@ function shellCommandReadsDotenv(const args = tokens.slice(1);if (grepRecursesIntoPotentialDotenv(bin, args)) return true;if (bin === 'rg' && rgSearchesPotentialDotenv(args)) return true;- if (readerArgumentsReadDotenv(bin, args)) return true;+ if (readerArgumentsReadDotenv(bin, args, isDotenvCredentialPath, opts.platform ?? process.platform)) return true;}return false;}