Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-core): accumulate credential scan prefix effects once
zqchris9d7aab465249
diff --git a/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts b/apps/desktop/src/main/remote-agent/__tests__/credentials.test.tsindex 7b4df6912e..24119a7b3c 100644--- a/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/credentials.test.ts@@ -269,6 +269,23 @@ describe('secrets written in the command', () => {describe('long development commands', () => {+ describe.each([false, true])('shared gate with path resolver: %s', (withResolver) => {+ it.each([500, 1000, 2000, 4000])('scans %i small segments in under a second and still checks the tail', (count) => {+ const prefix = 'echo a;'.repeat(count);+ const resolveFilePath = vi.fn((operand: string, cwd: string) => `${cwd}/${operand}`);+ const opts = {+ cwd: '/repo',+ ...(withResolver ? { resolveFilePath } : {}),+ };+ for (const [tail, expected] of [['echo done', false], ['cat README.md', false], ['cat .env', true], ['cat ~/.ssh/id_rsa', true]] as const) {+ const start = performance.now();+ expect(isShareCredentialCommand(prefix + tail, ['/repo'], opts), tail).toBe(expected);+ expect(performance.now() - start, tail).toBeLessThan(1000);+ }+ if (withResolver) expect(resolveFilePath).toHaveBeenCalledOnce();+ });+ });+it('scans beyond the model review budget without treating script length as a credential read', () => {const script = "python3 - <<'PY'\n" + '# ordinary edit\n'.repeat(500)+ "p='main.ts'\ns=open(p).read()\nopen(p,'w').write(s.replace('true','false'))\nPY";diff --git a/docs/product-rules/provider-sharing.md b/docs/product-rules/provider-sharing.mdindex d03518d9dc..d4d310af91 100644--- a/docs/product-rules/provider-sharing.md+++ b/docs/product-rules/provider-sharing.md@@ -288,8 +288,9 @@ Desktop「设置 → 模型供应商」的左栏(2026-10-08 用户裁决):- 命令只能按命令文本识别(脚本里读的、编码后再解开的认不出来),是防误发,不是防恶意;- 减少误弹(2026-10-12 用户裁决)。**以下几条只用于这张分享任务的确认卡**,本机任务、同账号远程供应商与自动审查的判定都不变:- - 普通编辑脚本不因超过模型审阅的 4096 字符预算就算凭证读取。凭证检查扫描完整命令,- 独立限制解析资源;长脚本尾部实际读取密钥时仍要求确认;+ - 普通编辑脚本不因超过模型审阅的 4096 字符预算就算凭证读取。凭证检查在独立的 256 KiB+ 输入上限内扫描完整命令,前序命令副作用按段累积,不为每段重新扫描全部前序段;超过输入+ 上限或解析深度上限时仍要求确认,长脚本尾部实际读取密钥时也仍要求确认;- `.env.example` / `.env.sample` / `.env.template` 与公钥 `*.pub` 按惯例不含密钥,不算凭证类文件(读取、启动时同步都照普通文件);放在凭证目录里(如 `~/.ssh/id_rsa.pub`)时仍算。命令中读取文件时,执行前按该命令段的实际目录核对原始路径与链接的真实目标;模板、公钥与配置目录里的说明diff --git a/packages/maker-core/src/agents/shared/auto-review.test.ts b/packages/maker-core/src/agents/shared/auto-review.test.tsindex bb68b703f3..a12dbda1cb 100644--- a/packages/maker-core/src/agents/shared/auto-review.test.ts+++ b/packages/maker-core/src/agents/shared/auto-review.test.ts@@ -4752,6 +4752,37 @@ describe('shellCommandReadsCredentials — 只认凭证那一部分红线', () =// 两个附加选项只供供应商分享的受邀者任务用(apps/desktop/src/main/remote-agent/credentials.ts)。describe('shellCommandReadsCredentials — 分享任务的附加选项', () => {+ it('accumulates prior mutations without tainting earlier reads or losing the file-only cd exemption', () => {+ vi.stubEnv('CDPATH', undefined);+ try {+ const files: boolean[] = [];+ const git: boolean[] = [];+ expect(shellCommandReadsCredentials(+ 'echo a;cd /repo/examples && cat example.pub;git diff;touch generated;cat example.pub;git diff', roots, {+ cwd: '/repo',+ platform: 'linux',+ fileReadRequiresConsent: (read) => { files.push(read.priorSegmentsMayMutate === true); return false; },+ gitContentRead: (read) => { git.push(read.priorSegmentsMayMutate === true); return true; },+ },+ )).toBe(false);+ expect(files).toEqual([false, true]);+ expect(git).toEqual([true, true]);+ } finally {+ vi.unstubAllEnvs();+ }+ });++ it('keeps a mutation sticky across later read-only segments for both Git read callbacks', () => {+ const reads: boolean[] = [];+ const record = (read: GitRead) => { reads.push(read.priorSegmentsMayMutate === true); return true; };+ expect(shellCommandReadsCredentials(+ 'echo a;git config --list;git diff;git add -A;echo done;git config --list;git diff', roots, {+ cwd: '/repo', gitContentRead: record, gitConfigRead: record,+ },+ )).toBe(false);+ expect(reads).toEqual([false, false, true, true]);+ });+it.each(["bash -c 'cat .env'","python -c 'open(\".env\").read()'",diff --git a/packages/maker-core/src/agents/shared/auto-review.ts b/packages/maker-core/src/agents/shared/auto-review.tsindex 02b150593a..65ecd9877d 100644--- a/packages/maker-core/src/agents/shared/auto-review.ts+++ b/packages/maker-core/src/agents/shared/auto-review.ts@@ -6253,37 +6253,34 @@ function gitUsesConfigOverride(tokens: readonly string[]): boolean {* 前置段按只读命令执行时,才允许把这次读取交给执行器做本机凭证豁免;认不出的段一律* 按可能有副作用处理,保持 fail-closed。*/-function priorShellSegmentsMayMutate(+function shellSegmentMutation(segments: readonly ExecutableSegment[],- segmentIndex: number,+ index: number,workspaceRoots: string[],opts: ShellReviewOptions,segmentCwds: readonly (string | undefined)[],- allowResolvedDirectoryChanges = false,-): boolean {- for (let index = 0; index < segmentIndex; index += 1) {- const segmentCwd = segmentCwds[index];- const segmentOpts: ShellReviewOptions = {- ...opts,- cwd: segmentCwd ?? opts.cwd,- cwdUnknown: segmentCwd === undefined ? true : opts.cwdUnknown,- };- // git status may refresh the index, so it cannot establish a stable pre-read state- // for a later credential exemption even though its output is otherwise read-only.- const tokens = stripShellControlTokens(tokenize(segments[index].text));- const unwrapped = unwrapCommand(tokens, segmentOpts.cwd ?? workspaceRoots[0], segmentOpts.cwdUnknown === true);- if (allowResolvedDirectoryChanges && !process.env.CDPATH- && tokens[0] === 'cd' && tokens.length === 2 && !tokens[1].startsWith('-')- && segments[index].separatorAfter === 'and' && segmentCwds[index + 1] !== undefined- && !segmentHasSideEffectRedirectOrSubstitution(segments[index].text)) continue;- const invocation = unwrapped.tokens[0] && executableName(unwrapped.tokens[0]) === 'git'- ? parseGitInvocation(unwrapped.tokens, workspaceRoots, segmentOpts)- : undefined;- if (invocation?.sub === 'status' || classifyShellSegment(segments[index].text, workspaceRoots, segmentOpts) !== 'auto-approve') {- return true;- }- }- return false;+): { mayMutate: boolean; mayMutateFiles: boolean } {+ const segment = segments[index];+ const segmentCwd = segmentCwds[index];+ const segmentOpts: ShellReviewOptions = {+ ...opts,+ cwd: segmentCwd ?? opts.cwd,+ cwdUnknown: segmentCwd === undefined ? true : opts.cwdUnknown,+ };+ // git status may refresh the index, so it cannot establish a stable pre-read state+ // for a later credential exemption even though its output is otherwise read-only.+ const tokens = stripShellControlTokens(tokenize(segment.text));+ const unwrapped = unwrapCommand(tokens, segmentOpts.cwd ?? workspaceRoots[0], segmentOpts.cwdUnknown === true);+ const resolvedDirectoryChange = !process.env.CDPATH+ && tokens[0] === 'cd' && tokens.length === 2 && !tokens[1].startsWith('-')+ && segment.separatorAfter === 'and' && segmentCwds[index + 1] !== undefined+ && !segmentHasSideEffectRedirectOrSubstitution(segment.text);+ const invocation = unwrapped.tokens[0] && executableName(unwrapped.tokens[0]) === 'git'+ ? parseGitInvocation(unwrapped.tokens, workspaceRoots, segmentOpts)+ : undefined;+ const mayMutate = invocation?.sub === 'status'+ || classifyShellSegment(segment.text, workspaceRoots, segmentOpts) !== 'auto-approve';+ return { mayMutate, mayMutateFiles: mayMutate && !resolvedDirectoryChange };}/**@@ -6312,7 +6309,19 @@ function shellCommandReadsDotenv(// 调用方核实 Git 或文件读取时需要各段的实际目录。const segmentCwds = opts.gitContentRead || opts.gitConfigRead || opts.fileReadRequiresConsent? segmentWorkingDirs(segments, workspaceRoots, opts) : [];+ const sharesGitCredentialChecks = opts.gitContentRead !== undefined || opts.gitConfigRead !== undefined;+ let previousMayMutate = false;+ let previousMayMutateFiles = false;for (const [segmentIndex, { text: segment }] of segments.entries()) {+ // Accumulate the prefix once, instead of reclassifying all prior segments for+ // every read. Updating at entry also covers earlier segments that continued.+ // File checks may accept a resolved cd; Git checks retain the stricter state.+ if (segmentIndex > 0 && (sharesGitCredentialChecks || opts.fileReadRequiresConsent)+ && (!previousMayMutate || (opts.fileReadRequiresConsent && !previousMayMutateFiles))) {+ const previous = shellSegmentMutation(segments, segmentIndex - 1, workspaceRoots, opts, segmentCwds);+ previousMayMutate ||= previous.mayMutate;+ previousMayMutateFiles ||= previous.mayMutateFiles;+ }const inputRedirections = parseShellInputRedirections(segment);if (inputRedirections.hasUnresolvedTarget) return true;const inspectionCommand = inputRedirections.targets.length > 0@@ -6326,15 +6335,14 @@ function shellCommandReadsDotenv();const tokens = unwrapped.tokens;const bin = executableName(tokens[0] ?? '');- const sharesGitCredentialChecks = opts.gitContentRead !== undefined || opts.gitConfigRead !== undefined;const configOverride = bin === 'git' && gitUsesConfigOverride(tokens);const priorMutation = sharesGitCredentialChecks || opts.fileReadRequiresConsent- ? priorShellSegmentsMayMutate(segments, segmentIndex, workspaceRoots, opts, segmentCwds)+ ? previousMayMutate|| segmentHasSideEffectRedirectOrSubstitution(segment)|| configOverride: false;const priorFileMutation = opts.fileReadRequiresConsent- ? priorShellSegmentsMayMutate(segments, segmentIndex, workspaceRoots, opts, segmentCwds, true)+ ? previousMayMutateFiles|| segmentHasSideEffectRedirectOrSubstitution(segment)|| rawTokens[0] !== tokens[0]: false;