Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
统一远程命令加载逻辑
DavidShenec7f7b842fa5
diff --git a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.tsindex 2190fb5e29..33ee6db55e 100644--- a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts+++ b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts@@ -48,18 +48,18 @@ describe('loadAllCommands deviceId', () => {expect(cmds.map((x) => x.name).sort()).toEqual(['compact', 'goal', 'help', 'localskill']);});- it('本地 Claude 新对话无 workingDir 时仍加载全局 skills', async () => {+ it('本地 Claude 新对话 workingDir=null 时仍加载全局 skills', async () => {const s = stubElectron();- const cmds = await loadAllCommands('claude-code', undefined);+ const cmds = await loadAllCommands('claude-code', null);expect(s.invoke).not.toHaveBeenCalled();expect(s.listAgentSkills).toHaveBeenCalledWith('claude-code', {});expect(cmds.some((x) => x.name === 'localskill')).toBe(true);});- it('SSH remote 用 null 显式关闭控制端本机 skill 扫描', async () => {+ it('SSH remote 用 skipAgentSkills 显式关闭控制端本机 skill 扫描', async () => {const s = stubElectron();- const cmds = await loadAllCommands('claude-code', null);+ const cmds = await loadAllCommands('claude-code', null, { skipAgentSkills: true });expect(s.listAgentSkills).not.toHaveBeenCalled();expect(s.invoke).not.toHaveBeenCalledWith(@@ -70,9 +70,9 @@ describe('loadAllCommands deviceId', () => {expect(cmds.some((x) => x.kind === 'agent-skill')).toBe(false);});- it('本地 Codex 新对话无 workingDir 时保持不请求 skills/list', async () => {+ it('本地 Codex 新对话 workingDir=null 时保持不请求 skills/list', async () => {const s = stubElectron();- const cmds = await loadAllCommands('codex', undefined);+ const cmds = await loadAllCommands('codex', null);expect(s.listAgentSkills).not.toHaveBeenCalled();expect(cmds.some((x) => x.kind === 'agent-skill')).toBe(false);@@ -97,9 +97,9 @@ describe('loadAllCommands deviceId', () => {expect(cmds.some((x) => x.name === 'goal')).toBe(true);});- it('device-link Claude 新对话无 workingDir 时从被控端加载全局 skills', async () => {+ it('device-link Claude 新对话 workingDir=null 时从被控端加载全局 skills', async () => {const s = stubElectron();- const cmds = await loadAllCommands('claude-code', undefined, undefined, 'dev-1');+ const cmds = await loadAllCommands('claude-code', null, undefined, 'dev-1');expect(s.listAgentSkills).not.toHaveBeenCalled();expect(s.invoke).toHaveBeenCalledWith('dev-1', 'maker:list-agent-skills', [diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex b716fe8a62..c06fe07fc1 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -2959,11 +2959,11 @@ export function ChatInput({(opts?: { forceReload?: boolean }) => {const seq = ++slashCommandLoadSeqRef.current;// device-link 远程会话:agent-builtin / agent-skill 从被控端读(deviceLinkDeviceId);- // workingDir 是被控端路径(SSH remoteHostId 才置 null 关扫描)。desktop 命令始终本地。+ // workingDir 是被控端路径;SSH remote 显式关扫描。desktop 命令始终本地。loadAllCommands(paletteAgentKind,- isRemoteSession ? null : workingDir,- opts,+ workingDir,+ { ...opts, skipAgentSkills: isRemoteSession },deviceLinkDeviceId,).then((cmds) => {diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex 74851b31d8..260636993f 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -1081,9 +1081,8 @@ export function CCAgentSessionView({useEffect(() => {let cancelled = false;const agentKind = session?.agentKind === 'codex' ? 'codex' : 'claude-code';- // SSH remote 传 null:loadAllCommands 退化为 desktop + agent-builtin,不扫控制端本机 skills。- // 本地无 workingDir 传 undefined:Claude 仍可扫描全局 skills。- const wd = isRemoteSession ? null : session?.workingDir;+ // SSH remote 显式禁用控制端本机 skill 扫描;本地无 workingDir 时 Claude 仍扫全局 skills。+ const wd = session?.workingDir;// 先同步清空:切换会话(尤其 local→remote)时 loadAllCommands 是异步的,清空可避免// 刷新完成前 getHelpCommandsSnapshot / desktop 命令识别复用上一个项目的本地 skills。setAllCommands([]);@@ -1091,7 +1090,7 @@ export function CCAgentSessionView({// (与 ChatInput palette 同源)。否则此 cache 取的是控制端命令,maybeDispatchDesktopSlashCommand// 会把被控端 skill/builtin 影子掉的 /clear、/help 等误判成 desktop 命令、在控制端执行。// 本机会话 remoteDeviceId=undefined → 行为不变。desktop 命令始终本地(见 loadAllCommands)。- loadAllCommands(agentKind, wd, undefined, remoteDeviceId)+ loadAllCommands(agentKind, wd, { skipAgentSkills: isRemoteSession }, remoteDeviceId).then((cmds) => {if (!cancelled) setAllCommands(cmds);})@@ -1564,8 +1563,8 @@ export function CCAgentSessionView({// device-link 远程会话同源:传 remoteDeviceId,fallback 快照也从被控端读(见上方 cache effect 说明)。return await loadAllCommands(agentKind,- isRemoteSession ? null : session?.workingDir,- undefined,+ session?.workingDir,+ { skipAgentSkills: isRemoteSession },remoteDeviceId,);} catch {diff --git a/apps/desktop/src/renderer/lib/slashCommands.ts b/apps/desktop/src/renderer/lib/slashCommands.tsindex 15d9978fd3..0b7be5562d 100644--- a/apps/desktop/src/renderer/lib/slashCommands.ts+++ b/apps/desktop/src/renderer/lib/slashCommands.ts@@ -85,13 +85,13 @@ export function filterSlashCommands(* 拉三路 IPC, 合并成 UnifiedCommand[]。** - 任何一路失败按空列表处理(已在 main 端做 try/catch + 返回 success:false), 不阻塞 palette。- * - workingDir=undefined 表示本地无项目:Claude 仍扫描全局 skills。- * - workingDir=null 表示显式禁用扫描(SSH remote):避免读取控制端本机 skills。+ * - workingDir 为空时 Claude 仍扫描全局 skills。+ * - SSH remote 由 opts.skipAgentSkills 显式禁用扫描,避免读取控制端本机 skills。*/export async function loadAllCommands(agentKind: AgentKind,workingDir: string | null | undefined,- opts?: { forceReload?: boolean },+ opts?: { forceReload?: boolean; skipAgentSkills?: boolean },deviceId?: string,): Promise<UnifiedCommand[]> {const api = window.electronAPI.maker;@@ -109,7 +109,7 @@ export async function loadAllCommands(? (window.electronAPI.deviceLink.invoke(deviceId, 'maker:list-agent-commands', [agentKind]) as Promise<CmdRes>): api.listAgentCommands(agentKind)).catch(() => ({ success: false }));- const shouldLoadSkills = workingDir !== null && (agentKind === 'claude-code' || Boolean(workingDir));+ const shouldLoadSkills = !opts?.skipAgentSkills && (agentKind === 'claude-code' || Boolean(workingDir));const skillParams = {...(workingDir ? { workingDir } : {}),...(opts?.forceReload !== undefined ? { forceReload: opts.forceReload } : {}),