Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(provider-sharing): account for inherited ripgrep config
MagicLizi4e522c1258c7
diff --git a/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts b/apps/desktop/src/main/remote-agent/__tests__/credentials.test.tsindex 353a1717ba..88c1751c0b 100644--- a/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts@@ -4,10 +4,13 @@* git 查看内容交给执行器在本机核实。*/import { isSensitiveCredentialPath, shellCommandReadsCredentials } from '@cindy/maker-core';-import { describe, expect, it } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { isShareCredentialCommand, isShareCredentialPath, shareCredentialGitReads } from '../credentials';+beforeEach(() => vi.stubEnv('RIPGREP_CONFIG_PATH', undefined));+afterEach(() => vi.unstubAllEnvs());+describe('isShareCredentialPath', () => {it('keeps the credential rules of local tasks', () => {for (const target of [@@ -79,6 +82,22 @@ describe('isShareCredentialCommand', () => {expect(isShareCredentialCommand('cat ~/.claude/skills/../settings.json', roots)).toBe(true);});+ it('checks inherited ripgrep config without changing local credential decisions', () => {+ const command = "rg -g '*.ts' PRIVATE .";+ expect(isShareCredentialCommand(command, roots)).toBe(false);+ const localDecision = shellCommandReadsCredentials(command, roots);+ vi.stubEnv('RIPGREP_CONFIG_PATH', '/unreadable/ripgrep-config');+ expect(isShareCredentialCommand(command, roots)).toBe(true);+ expect(shellCommandReadsCredentials(command, roots)).toBe(localDecision);+ expect(isShareCredentialCommand("rg --no-config -g '*.ts' PRIVATE .", roots)).toBe(false);+ expect(isShareCredentialCommand("rg -e --no-config -g '*.ts' .", roots)).toBe(true);+ expect(isShareCredentialCommand("rg --no-config --follow -g '*.ts' PRIVATE .", roots)).toBe(true);+ expect(isShareCredentialCommand("grep -rn --include='*.md' PRIVATE .", roots)).toBe(false);+ vi.stubEnv('RIPGREP_CONFIG_PATH', undefined);+ expect(isShareCredentialCommand(command, roots)).toBe(false);+ expect(isShareCredentialCommand("RIPGREP_CONFIG_PATH=/other/config rg -g '*.ts' PRIVATE .", roots)).toBe(true);+ });+it('lets searches narrowed to source and doc extensions run', () => {for (const command of ["rg -n 'API_KEY' --glob '*.ts'",diff --git a/apps/desktop/src/main/remote-agent/credentials.ts b/apps/desktop/src/main/remote-agent/credentials.tsindex 8e9bd00303..fd112286b1 100644--- a/apps/desktop/src/main/remote-agent/credentials.ts+++ b/apps/desktop/src/main/remote-agent/credentials.ts@@ -47,7 +47,8 @@ type ShareCommandOptions = Pick<CredentialCommandOptions, 'cwd' | 'platform'> &};function credentialCommandOptions(opts: ShareCommandOptions): CredentialCommandOptions {- const { resolveFilePath, ...commandOptions } = opts;+ const { resolveFilePath, ...shellOptions } = opts;+ const commandOptions = { ...shellOptions, ripgrepConfigActive: process.env.RIPGREP_CONFIG_PATH !== undefined };if (!resolveFilePath) return { ...commandOptions, sourceFileSelectors: true };let checkedPaths = 0;return {diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.tsindex 3c79a4278f..1c84c158dd 100644--- a/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/gitCredentials.git-integration.test.ts@@ -74,6 +74,7 @@ const savedEnv = Object.fromEntries(GIT_ENV_KEYS.map((key) => [key, process.env[beforeEach(() => {root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'share-git-credentials-')));vi.stubEnv('SHELL', '/bin/bash');+ vi.stubEnv('RIPGREP_CONFIG_PATH', undefined);vi.stubEnv('PATH', (process.env.PATH ?? '').split(path.delimiter).map((entry) => path.resolve(entry)).join(path.delimiter));// 临时目录的上层也可能是 git 仓库(比如整个用户目录):不往上找。开发机自己的全局与系统 git 配置// 也不读,免得里面的令牌影响结果。@@ -328,6 +329,30 @@ describe('GitCredentialHistory', () => {}});+ it.runIf(process.platform !== 'win32')('keeps consent when inherited ripgrep config follows source symlinks', async () => {+ const history = new GitCredentialHistory();+ const ripgrep = path.resolve(__dirname, '../../../../../../ripgrep-bin', process.platform + '-' + process.arch, 'rg');+ const config = path.join(root, 'ripgrep-config');+ const command = "rg -g '*.ts' PRIVATE .";+ write('.gitignore', '.env\n');+ write('.env', 'PRIVATE_FIXTURE=rg-config\n');+ fs.symlinkSync('.env', path.join(repo, 'safe.ts'));+ fs.writeFileSync(config, '--follow\n');+ vi.stubEnv('RIPGREP_CONFIG_PATH', config);+ expect(execFileSync(ripgrep, ['-g', '*.ts', 'PRIVATE', '.'], { cwd: repo, encoding: 'utf8' }))+ .toContain('PRIVATE_FIXTURE=rg-config');+ const disabled = spawnSync(ripgrep, ['--no-config', '-g', '*.ts', 'PRIVATE', '.'], { cwd: repo, encoding: 'utf8' });+ expect(disabled.status).toBe(1);+ expect(disabled.stdout).toBe('');+ expect(disabled.stderr).toBe('');+ await requiresCredentialConfirmation(history, command);+ const workspace = new ExecutorWorkspace({ workingDir: repo });+ const gate = new ExecutorGate(workspace, 'full', Date.now, { confirmCredentials: true });+ expect(gate.authorize({ kind: 'exec', command: "rg --no-config -g '*.ts' PRIVATE .", cwd: repo }).ok).toBe(true);+ fs.writeFileSync(config, '--hidden\n--glob=*.env\n');+ await requiresCredentialConfirmation(history, command);+ });+it('keeps consent when --bare selects a different repository in the same directory', async () => {const history = new GitCredentialHistory();expect(await provesSafe(history, 'git show HEAD')).toBe(true);diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex 0039e79409..fd3992057d 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -294,7 +294,10 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):文件名、`*.json` / `*.txt` / `*.sh` 这类可能存放凭证的格式、扩展名不确定的写法(`*.ts*`)仍要确认。搜索启用跟随符号链接(如 rg 的 `--follow` / `-L`、grep 的 `-R` / `--dereference-recursive`)时,源码扩展名不能证明链接目标非敏感,保留确认;短选项组合与可接受的长选项缩写同样处理;- - git 查看内容的命令(`git diff`、`git show`、`git log -p`、`git grep`)只看命令文本时按可能读到+ 宿主设置了 `RIPGREP_CONFIG_PATH`、命令里对它赋值时,也不能只凭源码扩展名豁免。+ 配置可能注入跟随链接或其它扩大读取范围的选项;只在 rg 后第一个参数明确为 `--no-config` 时+ 才继续按其它既有规则核实,不把搜索词、选项取值或 `--` 后的同名文本当成禁用配置的标志;+ - git 查看内容的命令(`git diff`、`git show`、`git log -p`、`git grep`)只看命令文本时按可能读到提交进仓库的凭证处理,执行前先在受邀者电脑上核实,读不到凭证类文件就不弹卡:仓库所有分支、标签、stash 与 reflog 的历史和暂存区里从没有凭证类文件;或命令用 `--` 限定的路径碰不到这些文件;或(`git diff` / `git show` / `git log`)按原命令只列出会显示的文件,其中没有凭证类文件。认不出 gitdiff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex 5eed3727a6..1e3a873fdc 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -4844,6 +4844,50 @@ describe('shellCommandReadsCredentials — 分享任务的附加选项', () => {}});+ it('keeps sharing searches behind consent when ripgrep config can inject options', () => {+ for (const command of [+ "rg -g '*.ts' token .",+ "rg -e --no-config -g '*.ts' .",+ "rg --regexp=--no-config -g '*.ts' .",+ "rg --glob --no-config -g '*.ts' token .",+ "rg -g--no-config -g '*.ts' token .",+ "rg -n --no-config -g '*.ts' token .",+ 'rg -- --no-config',+ ]) {+ const localDecision = shellCommandReadsCredentials(command, roots);+ expect(shellCommandReadsCredentials(command, roots, { ripgrepConfigActive: true }), command).toBe(localDecision);+ expect(shellCommandReadsCredentials(command, roots, { sourceFileSelectors: false, ripgrepConfigActive: true }), command)+ .toBe(localDecision);+ expect(shellCommandReadsCredentials(command, roots, { sourceFileSelectors: true, ripgrepConfigActive: true }), command)+ .toBe(true);+ }+ for (const command of [+ "RIPGREP_CONFIG_PATH=/other/config rg -g '*.ts' token .",+ "env RIPGREP_CONFIG_PATH=/other/config rg -g '*.ts' token .",+ "export RIPGREP_CONFIG_PATH=/other/config && rg -g '*.ts' token .",+ ]) {+ expect(shellCommandReadsCredentials(command, roots, { sourceFileSelectors: true }), command).toBe(true);+ }+ const opts = { sourceFileSelectors: true, ripgrepConfigActive: true };+ for (const command of [+ "rg --no-config -g '*.ts' token .",+ "RIPGREP_CONFIG_PATH=/other/config rg --no-config -g '*.ts' token .",+ "grep -rn --include='*.md' token .",+ ]) {+ expect(shellCommandReadsCredentials(command, roots, opts), command).toBe(false);+ }+ expect(shellCommandReadsCredentials("rg --no-config --follow -g '*.ts' token .", roots, opts)).toBe(true);+ expect(shellCommandReadsCredentials("rg -g '*.ts' token .", roots, { sourceFileSelectors: true })).toBe(false);+ const checkFile = vi.fn((read: { operand: string }) => read.operand === '.env');+ expect(shellCommandReadsCredentials("rg --no-config -g '*.ts' token .", roots, {+ ...opts, cwd: '/repo', fileReadRequiresConsent: checkFile,+ })).toBe(false);+ expect(checkFile).not.toHaveBeenCalledWith(expect.objectContaining({ operand: 'token' }));+ expect(shellCommandReadsCredentials("rg --no-config -g '*.ts' token .env", roots, {+ ...opts, cwd: '/repo', fileReadRequiresConsent: checkFile,+ })).toBe(true);+ });+it('marks sharing Git probes unsafe when --bare changes the repository context', () => {for (const subcommand of ['show HEAD', 'config --list']) {const command = 'git --bare ' + subcommand;diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 5b724b1086..49100f7f15 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -3260,6 +3260,7 @@ export type CredentialCommandOptions = ShellReviewOptions & {}) => boolean;/** rg -g、grep --include 这类搜索范围只选中源码与文档扩展名时不算读取凭证。 */sourceFileSelectors?: boolean;+ ripgrepConfigActive?: boolean;/*** git 查看内容又没有限定到具体文件时默认按可能读到提交进仓库的凭证处理;提供时先问调用方,* 返回 true 表示调用方已核实这次调用读不到凭证类文件。@@ -6441,11 +6442,16 @@ function shellCommandReadsDotenv(if (readsCredentialInput) return true;const args = tokens.slice(1);if (opts.sourceFileSelectors && searchFollowsSymlinks(bin, args)) return true;+ if (opts.sourceFileSelectors && bin === 'rg'+ && (opts.ripgrepConfigActive || /\bRIPGREP_CONFIG_PATH\s*=/i.test(command))+ && args[0] !== '--no-config') return true;+ const readerArgs = opts.sourceFileSelectors && bin === 'rg' && args[0] === '--no-config'+ ? args.slice(1) : args;if (grepRecursesIntoPotentialDotenv(bin, args, selectorCouldMatch)) return true;if (bin === 'ag' && agSearchesPotentialCredential(args)) return true;if (bin === 'rg' && rgSearchesPotentialDotenv(args, selectorCouldMatch)) return true;if (readerArgumentsReadDotenv(- bin, args, isDotenvCredentialPath, opts.platform ?? process.platform,+ bin, readerArgs, isDotenvCredentialPath, opts.platform ?? process.platform,selectorCouldMatch, fileReadRequiresConsent)) return true;}return false;