Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-agent): run hosted commands with the local environment
Lizi9c4379408578
diff --git a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts b/apps/desktop/src/main/remote-agent/controller/execServerRelay.tsindex 70ded70b2b..b0d56cb110 100644--- a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts+++ b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts@@ -21,7 +21,7 @@ import {} from '@cindy/device-link';import type { ExecutorAction, ExecutorGateDecision } from '../executor/gate';-import { createExecutorEnv, resolveExecutorShell } from '../executor/shell';+import { resolveExecutorShell } from '../executor/shell';import type { ExecutorWorkspace } from '../executor/workspace';export const EXEC_SERVER_WS_PATH = '/ws/exec-server';@@ -36,7 +36,7 @@ export interface ExecServerRelayDeps {workspace: ExecutorWorkspace;authorize(action: ExecutorAction): ExecutorGateDecision;push(frames: RemoteAgentPushFrame[]): Promise<void>;- env?: NodeJS.ProcessEnv | (() => NodeJS.ProcessEnv);+ env?: NodeJS.ProcessEnv;log?: { warn(message: string, meta?: Record<string, unknown>): void };}@@ -184,9 +184,7 @@ export class ExecServerRelay {try {child = spawn(this.deps.codexPath, ['exec-server', '--listen', 'stdio://'], {cwd: this.deps.cwd,- env: typeof this.deps.env === 'function'- ? this.deps.env()- : createExecutorEnv(this.deps.env ?? process.env),+ env: this.deps.env ?? process.env,stdio: ['pipe', 'pipe', 'pipe'],windowsHide: true,});diff --git a/apps/desktop/src/main/remote-agent/controller/startRemote.ts b/apps/desktop/src/main/remote-agent/controller/startRemote.tsindex d87df77216..b02eaae118 100644--- a/apps/desktop/src/main/remote-agent/controller/startRemote.ts+++ b/apps/desktop/src/main/remote-agent/controller/startRemote.ts@@ -175,7 +175,6 @@ export async function startRemoteAgentSession(codexPath,cwd: workspace.workingDir,workspace,- env: () => workspace.hostedProcessEnv(path.join(os.tmpdir(), 'cindy-remote-agent')),authorize: (action) => executor.check(action),push: async (frames) => {await pushFrames?.(frames);diff --git a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.tsindex dbc359f545..e39f42cccf 100644--- a/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts+++ b/apps/desktop/src/main/remote-agent/executor/__tests__/executor.test.ts@@ -2,13 +2,13 @@ import fs from 'node:fs';import os from 'node:os';import path from 'node:path';-import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { handleExecMcpRequest } from '../ccMcp';import { RemoteExecutor } from '../executor';import { EXECUTOR_APPROVAL_TTL_MS, ExecutorGate, executorGateModeFor } from '../gate';import type { PdfTextExtractor } from '../files';-import { createExecutorEnv, findWindowsGitBash, truncateOutput } from '../shell';+import { findWindowsGitBash, truncateOutput } from '../shell';import { ExecutorWorkspace } from '../workspace';const RG = path.resolve(__dirname, '../../../../../../ripgrep-bin', `${process.platform}-${process.arch}`, process.platform === 'win32' ? 'rg.exe' : 'rg');@@ -59,36 +59,17 @@ beforeEach(() => {});afterEach(() => {+ vi.unstubAllEnvs();fs.rmSync(root, { recursive: true, force: true });});describe('workspace', () => {- it('filters credentials and real user directories from child environments while keeping PATH', () => {- const env = createExecutorEnv({- PATH: 'tool-path',- HOME: 'C:/Users/real',- USERPROFILE: 'C:/Users/real',- TEMP: 'C:/Users/real/AppData/Local/Temp',- OPENAI_API_KEY: 'secret',- SESSION_TOKEN: 'secret',- SAFE_FLAG: '1',- });- expect(env).toEqual({ PATH: 'tool-path', SAFE_FLAG: '1' });- });-- it('gives hosted processes virtual home and temp paths without dropping command search', () => {- const workspace = new ExecutorWorkspace({ workingDir: project });- workspace.setVirtualRoot('/Users/agent');- const env = workspace.hostedProcessEnv(path.join(root, 'hosted-temp'));- expect(env.PATH).toBeTruthy();- expect(env.HOME).not.toBe(os.homedir());- expect(workspace.resolve('~/.config')).toBe(path.join(env.HOME!, '.config'));- expect(workspace.mapTextForAgent(env.HOME!)).not.toContain(os.homedir());- expect(workspace.mapTextForAgent(env.TMP!)).not.toContain(os.tmpdir());- });-- it('passes the isolated environment to Claude shell commands', async () => {- const workspace = new ExecutorWorkspace({ workingDir: project });+ it('runs shell commands with the Desktop environment, showing known directories as virtual paths', async () => {+ const userConfig = path.join(root, 'user-config');+ fs.mkdirSync(userConfig);+ vi.stubEnv('CINDY_REMOTE_PROBE_TOKEN', 'from-desktop');+ vi.stubEnv('CINDY_REMOTE_PROBE_DIR', userConfig);+ const workspace = new ExecutorWorkspace({ workingDir: project, aliases: [{ from: '/Users/agent/config', to: userConfig }] });workspace.setVirtualRoot('/Users/agent');const executor = new RemoteExecutor({workspace,@@ -96,17 +77,30 @@ describe('workspace', () => {rgPath: RG,tempDir: path.join(root, 'shell-temp'),});- const bash = process.platform === 'win32' && !findWindowsGitBash()- ? 'node -p "process.env.HOME"'- : "node -p 'process.env.HOME'";- const result = await executor.callTool('Bash', { command: bash });+ const result = await executor.callTool('Bash', {+ command: 'node -p "[process.env.CINDY_REMOTE_PROBE_TOKEN, process.env.CINDY_REMOTE_PROBE_DIR].join(\' \')"',+ });const output = text(result);expect(result.isError).not.toBe(true);- expect(output).toContain('/Users/agent');- expect(output).not.toContain(os.homedir());+ expect(output).toContain('from-desktop /Users/agent/config');+ expect(output).not.toContain(userConfig);await executor.close();});+ it('virtualizes PATH directories not already covered by an alias and expands ~ to the real home', () => {+ const covered = path.join(root, 'covered');+ const tools = path.join(covered, 'tools');+ const other = path.join(root, 'other-tools');+ fs.mkdirSync(tools, { recursive: true });+ fs.mkdirSync(other);+ vi.stubEnv('PATH', [tools, other, path.join(root, 'missing')].join(path.delimiter));+ const workspace = new ExecutorWorkspace({ workingDir: project, aliases: [{ from: '/Users/agent/covered', to: covered }] });+ workspace.setVirtualRoot('/Users/agent');+ expect(workspace.mapTextForAgent(tools)).toBe('/Users/agent/covered/tools');+ expect(workspace.mapTextForAgent(other)).toMatch(/^\/Users\/agent\/additional\/runtime-\d+$/);+ expect(workspace.resolve('~/.config')).toBe(path.join(os.homedir(), '.config'));+ });+it('resolves relative paths against the working directory and maps shadow paths back', () => {const workspace = new ExecutorWorkspace({ workingDir: project, aliases: [{ from: '/remote/shadow/proj', to: project }] });expect(workspace.resolve('a/b.txt')).toBe(path.join(project, 'a/b.txt'));diff --git a/apps/desktop/src/main/remote-agent/executor/executor.ts b/apps/desktop/src/main/remote-agent/executor/executor.tsindex ab4c6d4cd0..c1cd496ad9 100644--- a/apps/desktop/src/main/remote-agent/executor/executor.ts+++ b/apps/desktop/src/main/remote-agent/executor/executor.ts@@ -7,7 +7,6 @@* NotebookEdit(Claude Code 的自带文件与命令工具关掉后由它顶替)。* 写文件前通知「每轮改动对比」抓取改前内容;命令执行后登记一次无法预知范围的改动。*/-import os from 'node:os';import path from 'node:path';import {@@ -108,17 +107,11 @@ export class RemoteExecutor {constructor(private readonly opts: RemoteExecutorOptions) {this.workspace = opts.workspace;this.gate = opts.gate;- const tempDir = opts.tempDir ?? path.join(os.tmpdir(), 'cindy-remote-agent');- // Initialize the task-local home before any Read/Write path is resolved; later calls refresh- // its virtual alias once the host mirror root is known.- opts.workspace.hostedProcessEnv(tempDir);- const rg = createRipgrepRunner(opts.rgPath);- this.rg = (args, cwd, runOptions) => rg(args, cwd, { ...runOptions, env: opts.workspace.hostedProcessEnv(tempDir) });+ this.rg = createRipgrepRunner(opts.rgPath);this.shell = new ShellSession({workingDir: opts.workspace.workingDir,isAllowedCwd: (cwd) => opts.workspace.contains(cwd),- tempDir,- env: () => opts.workspace.hostedProcessEnv(tempDir),+ tempDir: opts.tempDir,});this.writeHooks = {beforeWrite: async (absPath) => {@@ -147,7 +140,6 @@ export class RemoteExecutor {if (this.closed) return;this.closed = true;await this.shell.close();- await this.workspace.cleanupHostedProcessEnv();}private ensureOpen(): void {@@ -228,7 +220,7 @@ export class RemoteExecutor {if (typeof params.pattern !== 'string' || !params.pattern) throw new ExecutorRequestError('INVALID', 'pattern is required');const root = this.resolvePath(typeof params.path === 'string' && params.path ? params.path : '.');this.authorize({ kind: 'read', path: root, scope: 'tree' });- const result = await piGrep(this.opts.rgPath, root, params, signal, this.workspace.hostedProcessEnv(this.shell.getTempDir()));+ const result = await piGrep(this.opts.rgPath, root, params, signal);return { ...result, text: this.workspace.mapTextForAgent(result.text) };}case 'exec.run': {@@ -241,12 +233,7 @@ export class RemoteExecutor {? Math.min(timeoutSeconds, PI_BASH_MAX_TIMEOUT_SECONDS) * 1000: undefined;try {- const result = await runOnce(command, {- cwd,- timeoutMs,- signal,- env: this.workspace.hostedProcessEnv(this.shell.getTempDir()),- });+ const result = await runOnce(command, { cwd, timeoutMs, signal });return {output: this.workspace.mapOutputForAgent(result.output).toString('base64'),exitCode: result.exitCode,diff --git a/apps/desktop/src/main/remote-agent/executor/files.ts b/apps/desktop/src/main/remote-agent/executor/files.tsindex 2c3c2211ff..56fbeb87e1 100644--- a/apps/desktop/src/main/remote-agent/executor/files.ts+++ b/apps/desktop/src/main/remote-agent/executor/files.ts@@ -127,12 +127,12 @@ export async function detectImageMime(absPath: string): Promise<string | null> {export interface RipgrepRunner {/** 返回 rg 的 stdout 行;达到 maxLines 时提前结束。退出码 1(无匹配)视为正常。 */- (args: string[], cwd: string, opts: { maxLines: number; signal?: AbortSignal; env?: NodeJS.ProcessEnv }): Promise<string[]>;+ (args: string[], cwd: string, opts: { maxLines: number; signal?: AbortSignal }): Promise<string[]>;}export function createRipgrepRunner(rgPath: string): RipgrepRunner {- return (args, cwd, { maxLines, signal, env }) => new Promise((resolve, reject) => {- const child = spawn(rgPath, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], signal });+ return (args, cwd, { maxLines, signal }) => new Promise((resolve, reject) => {+ const child = spawn(rgPath, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], signal });const lines: string[] = [];let stderr = '';let stopped = false;diff --git a/apps/desktop/src/main/remote-agent/executor/search.ts b/apps/desktop/src/main/remote-agent/executor/search.tsindex d055e4d542..77711cd31f 100644--- a/apps/desktop/src/main/remote-agent/executor/search.ts+++ b/apps/desktop/src/main/remote-agent/executor/search.ts@@ -55,7 +55,6 @@ export async function piGrep(root: string,input: PiGrepInput,signal?: AbortSignal,- env?: NodeJS.ProcessEnv,): Promise<PiGrepResult> {const stat = await fsp.stat(root);const rootIsDirectory = stat.isDirectory();@@ -78,7 +77,7 @@ export async function piGrep(let lastLine = -1;await new Promise<void>((resolve, reject) => {- const child = spawn(rgPath, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], signal });+ const child = spawn(rgPath, args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], signal });const reader = readline.createInterface({ input: child.stdout });let stopped = false;reader.on('line', (raw) => {diff --git a/apps/desktop/src/main/remote-agent/executor/shell.ts b/apps/desktop/src/main/remote-agent/executor/shell.tsindex cd6740e75b..adf24a7117 100644--- a/apps/desktop/src/main/remote-agent/executor/shell.ts+++ b/apps/desktop/src/main/remote-agent/executor/shell.ts@@ -17,26 +17,6 @@ import path from 'node:path';export const CC_BASH_DEFAULT_TIMEOUT_MS = 120_000;export const CC_BASH_MAX_TIMEOUT_MS = 600_000;export const CC_BASH_MAX_OUTPUT_CHARS = 30_000;--const HIDDEN_EXECUTOR_ENV_NAMES = new Set([- 'HOME', 'USERPROFILE', 'HOMEDRIVE', 'HOMEPATH', 'PWD', 'OLDPWD', 'TMP', 'TEMP', 'TMPDIR',- 'APPDATA', 'LOCALAPPDATA', 'XDG_CONFIG_HOME', 'XDG_CACHE_HOME', 'XDG_DATA_HOME',- 'CLAUDE_CONFIG_DIR', 'CODEX_HOME', 'CINDY_CONFIG_DIR', 'CLAUDE_CODE_GIT_BASH_PATH',- 'SSH_AUTH_SOCK', 'GIT_CONFIG_GLOBAL', 'GIT_CONFIG_SYSTEM', 'NPM_CONFIG_USERCONFIG',-]);-const HIDDEN_EXECUTOR_ENV_KEYS = /(?:^|[_-])(API[_-]?KEY|KEY|TOKEN|SECRET|PASSWORD|PASSWD|AUTH|CREDENTIAL|COOKIE|PRIVATE)(?:$|[_-])/i;--/** 给控制端子进程的最小环境:保留命令搜索与平台运行时,去掉凭证和真实用户目录。 */-export function createExecutorEnv(input: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {- const output: NodeJS.ProcessEnv = {};- for (const [key, value] of Object.entries(input)) {- if (value === undefined) continue;- const upper = key.toUpperCase();- if (HIDDEN_EXECUTOR_ENV_NAMES.has(upper) || HIDDEN_EXECUTOR_ENV_KEYS.test(upper)) continue;- output[key] = value;- }- return output;-}/** 一次性执行的输出上限(超出部分丢弃头部,保留最新输出)。 */const RUN_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;const KILL_GRACE_MS = 2_000;@@ -228,7 +208,7 @@ export function runOnce(script: string, opts: RunOptions): Promise<RunResult> {try {child = spawn(shell.file, shell.args, {cwd: file.dir,- env: opts.env ?? createExecutorEnv(),+ env: opts.env ?? process.env,stdio: ['ignore', 'pipe', 'pipe'],detached: process.platform !== 'win32',windowsHide: true,@@ -314,8 +294,6 @@ export interface ShellSessionOptions {isAllowedCwd: (cwd: string) => boolean;/** 后台命令输出文件所在目录(本机)。 */tempDir?: string;- /** 每次启动子进程时生成隔离环境,避免复用启动时已过期的路径别名。 */- env?: () => NodeJS.ProcessEnv;}/** Git Bash 的 pwd 使用 MSYS 挂载路径,权限与后续文件工具必须回到 Windows 本机路径。 */@@ -361,12 +339,7 @@ export class ShellSession {const started = Date.now();let result: RunResult;try {- result = await runOnce(script, {- cwd: startCwd,- timeoutMs: timeout,- signal,- env: this.opts.env?.() ?? createExecutorEnv(),- });+ result = await runOnce(script, { cwd: startCwd, timeoutMs: timeout, signal });} catch (error) {await fsp.rm(cwdFile, { force: true });return { text: `Failed to run command: ${(error as Error).message}`, isError: true };@@ -425,7 +398,7 @@ export class ShellSession {try {child = spawn(shell.file, shell.args, {cwd: file.dir,- env: this.opts.env?.() ?? createExecutorEnv(),+ env: process.env,stdio: ['ignore', out, out],detached: process.platform !== 'win32',windowsHide: true,diff --git a/apps/desktop/src/main/remote-agent/executor/workspace.ts b/apps/desktop/src/main/remote-agent/executor/workspace.tsindex 2e047ec2c4..37d8c4fd7c 100644--- a/apps/desktop/src/main/remote-agent/executor/workspace.ts+++ b/apps/desktop/src/main/remote-agent/executor/workspace.ts@@ -6,7 +6,6 @@* 让 Agent 照常加载项目说明与 Skill)在这里映射回本机真实目录,模型即使用了影子路径也落在* 本机项目里。*/-import { randomUUID } from 'node:crypto';import fs from 'node:fs';import os from 'node:os';import path from 'node:path';@@ -95,8 +94,6 @@ export class ExecutorWorkspace {private extraDirs: string[];private aliases: ExecutorPathAlias[];private virtualRoot?: string;- private hostedEnvRoot?: string;- private hostedHomeDir?: string;constructor(roots: ExecutorWorkspaceRoots) {if (!path.isAbsolute(roots.workingDir)) throw new ExecutorPathError('working directory must be absolute');@@ -128,8 +125,26 @@ export class ExecutorWorkspace {.sort((a, b) => b.from.length - a.from.length);}+ /**+ * 命令沿用 Desktop 的完整环境(与本机 Agent 一致),虚拟化只作用于 Agent 看到的路径文本。+ * 用户目录与临时目录已有别名;PATH 里其余目录在这里登记,env / which 之类的输出也只露虚拟路径。+ */setVirtualRoot(root?: string): void {this.virtualRoot = root;+ if (root) this.virtualizeDirs(this.unaliasedSearchDirs());+ }++ private unaliasedSearchDirs(): string[] {+ const dirs: string[] = [];+ for (const entry of (process.env.PATH ?? '').split(path.delimiter)) {+ if (!entry || !path.isAbsolute(entry) || this.toAgentPath(entry) !== entry) continue;+ try {+ if (fs.statSync(entry).isDirectory()) dirs.push(entry);+ } catch {+ // PATH 里不存在的目录不会出现在输出里,无需登记。+ }+ }+ return dirs;}/** 运行中新增的目录分配新的 opaque 别名,撤销授权不撤销路径身份。 */@@ -221,89 +236,6 @@ export class ExecutorWorkspace {return projected === text ? data : Buffer.from(projected, 'utf8');}- /**- * 为控制端执行器创建隔离环境。只保留运行 shell 所需的通用系统变量;用户目录、临时目录- * 和凭证类变量都不从 Desktop 进程继承。目录仍在控制端落地,但会注册成虚拟别名,命令的- * env / printenv 输出再经过 mapOutputForAgent 时只会看到 Agent 侧路径。- */- hostedProcessEnv(tempDir: string): NodeJS.ProcessEnv {- const root = this.hostedEnvRoot ?? path.join(tempDir, 'env', randomUUID());- if (this.hostedEnvRoot !== root) {- this.hostedEnvRoot = root;- fs.mkdirSync(path.join(root, 'home'), { recursive: true });- fs.mkdirSync(path.join(root, 'tmp'), { recursive: true });- }- const fakeHome = path.join(root, 'home');- const fakeTemp = path.join(root, 'tmp');- this.hostedHomeDir = fakeHome;- this.virtualizeDirs([fakeHome, fakeTemp]);- const env: NodeJS.ProcessEnv = {};- const allowed = [- 'PATHEXT', 'SystemRoot', 'WINDIR', 'ComSpec', 'COMSPEC', 'SystemDrive', 'OS',- 'PROCESSOR_ARCHITECTURE', 'PROCESSOR_IDENTIFIER', 'PROCESSOR_LEVEL', 'PROCESSOR_REVISION',- 'NUMBER_OF_PROCESSORS', 'LANG', 'LC_ALL', 'LC_CTYPE', 'TERM', 'COLORTERM', 'CI',- 'NODE_ENV', 'FORCE_COLOR', 'NO_COLOR',- ];- for (const key of allowed) {- const value = process.env[key];- if (value !== undefined) env[key] = value;- }- const pathValue = process.env.PATH ?? process.env.Path ?? '';- // PATH 仍保留完整命令搜索能力;每个目录都登记成虚拟别名,printenv/env 的输出会投影回- // Agent 侧路径。这样用户级 Node/pnpm、Git Bash 等不会因为隔离而失效。- const pathEntries = pathValue.split(path.delimiter).filter(Boolean);- if (pathEntries.length) {- const pathRoot = path.join(root, 'path');- fs.mkdirSync(pathRoot, { recursive: true });- const hostedPathEntries: string[] = [];- for (const [index, target] of pathEntries.entries()) {- let stat: fs.Stats;- try {- stat = fs.statSync(target);- } catch {- continue;- }- if (!stat.isDirectory()) continue;- const link = path.join(pathRoot, `entry-${index}`);- try {- if (!fs.existsSync(link)) {- fs.symlinkSync(target, link, process.platform === 'win32' ? 'junction' : 'dir');- }- hostedPathEntries.push(link);- // Keep both sides addressable: child env uses the temporary link, while diagnostics such- // as process.execPath may still report the linked target directory.- this.virtualizeDirs([target, link]);- } catch {- // A PATH entry that cannot be linked is omitted rather than reintroducing a real path.- }- }- if (hostedPathEntries.length) env.PATH = hostedPathEntries.join(path.delimiter);- }- env.HOME = fakeHome;- env.USERPROFILE = fakeHome;- env.TMP = fakeTemp;- env.TEMP = fakeTemp;- env.TMPDIR = fakeTemp;- env.XDG_CONFIG_HOME = path.join(fakeHome, '.config');- env.XDG_CACHE_HOME = path.join(fakeHome, '.cache');- env.APPDATA = path.join(fakeHome, 'AppData', 'Roaming');- env.LOCALAPPDATA = path.join(fakeHome, 'AppData', 'Local');- env.USERNAME = 'agent';- env.USER = 'agent';- env.LOGNAME = 'agent';- if (process.platform !== 'win32') env.SHELL = '/bin/bash';- return env;- }-- /** 任务结束后移除 fake HOME/TMP 与 PATH 链接,避免临时目录残留。 */- async cleanupHostedProcessEnv(): Promise<void> {- const root = this.hostedEnvRoot;- this.hostedEnvRoot = undefined;- this.hostedHomeDir = undefined;- if (!root) return;- await fs.promises.rm(root, { recursive: true, force: true, maxRetries: 3, retryDelay: 50 }).catch(() => undefined);- }-/** 命令文本里出现的影子目录前缀替换成本机目录(按 shell 语法安全引用)。 */mapCommand(command: string, dialect: 'bash' | 'cmd' = 'bash'): string {const aliases = this.aliases.map((alias) => ({@@ -357,7 +289,7 @@ export class ExecutorWorkspace {}const trimmed = input.startsWith('@') ? input.slice(1) : input;const expanded = trimmed === '~' || trimmed.startsWith('~/')- ? path.join(this.hostedHomeDir ?? process.env.HOME ?? '', trimmed.slice(1))+ ? path.join(os.homedir(), trimmed.slice(1)): trimmed;return path.resolve(this.mapAlias(baseDir), this.mapAlias(expanded));}diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 298dc01daf..9f2614bc5d 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -474,6 +474,13 @@ handler 无 sender 依赖;不加入共享任务访客白名单,不进入自还原到 A 的真实路径,二进制内容保持原样。A 的真实目录继续用于权限 gate、执行与变更抓取,路径别名不增加授权。执行平台与 shell 保留 A 的实际值,以免跨 macOS / Windows / Linux 选错命令。此增量不修改 channel、relay、协议版本或服务器,也不是 OS 虚拟化。+- **执行环境**(2026-10-07 裁决):A 上的命令(Claude 的 Bash、Pi 的 `exec.run`、Codex exec-server、+ 搜索)沿用 A 的 Desktop 完整环境,与本机 Agent 一致:真实用户目录、临时目录、`SSH_AUTH_SOCK`、+ git / gh / npm 配置与用户自己的环境变量照常可用,不另造假 HOME,也不剥离凭证类变量。任务由 A 的+ 用户发起,风险与本机 Agent 相同,由 A 的任务权限档与执行器 gate 把关;上面「凭证」一条只指模型+ 登录与供应商凭证,命令输出照常经事件流回到 B 上的 Agent,与本机 Agent 把输出交给模型相同。虚拟化+ 只作用于 Agent 看到的路径文本:用户目录、临时目录已有别名,PATH 里其余目录在设置虚拟根时登记+ (`executor/workspace.ts` 的 `setVirtualRoot`,回归见 `executor/__tests__/executor.test.ts`)。- **回退**:`REMOTE_AGENT_METHODS` 含 `previewRewindFiles` / `commitRewindFiles`,B 在 `describeHandle`里声明支持后 A 才提供回退;文件按 A 本机的保存点链回退,对话由 B 截断。B 不支持时 A 关闭回退并提示升级那台的 Cindy。