Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): preserve learn command fallback
xd-bobo46cffc4995e2
diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.tsindex e6eb47e5aa..53b027bc38 100644--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts@@ -87,6 +87,7 @@ import {} from './remoteChatHistory.js';import { botSessionLinks, sessions } from '../localDb/schema.js';import { isCindyLearnSkillEnabled } from '../skillhub/activationPreferences.js';+import { getLearnController } from '../learn-host/index.js';export interface DesktopMcpProvidersDeps {botCapabilities: Pick<ReturnType<typeof createBotCapabilityService>, 'list' | 'select'>;@@ -391,9 +392,6 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMcmessage: 'Cindy Learn is disabled in Local Skills.',};}- // Lazy import avoids coupling provider construction to learn-host startup.- // The callback is invoked only after bootstrap has initialized the host.- const { getLearnController } = await import('../learn-host/index.js');const controller = getLearnController();if (!controller) {return {diff --git a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.tsindex f9b8edb8cf..cc0574e988 100644--- a/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts+++ b/apps/desktop/src/renderer/__tests__/slashCommandsDeviceId.test.ts@@ -29,7 +29,10 @@ function stubElectron() {commands: import('@cindy/maker-core').UnifiedCommand[];runtimeStatus?: import('../../shared/piPackages').PiPackageCommandRuntimeStatus;}));- const listAgentSkills = vi.fn(async () => ({ success: true, skills: [c('localskill', 'agent-skill')] }));+ const listAgentSkills = vi.fn(async () => ({+ success: true,+ skills: [c('learn', 'agent-skill'), c('localskill', 'agent-skill')],+ }));const invoke = vi.fn(async (_deviceId: string, channel: string, args?: unknown[]) => {if (channel === 'maker:list-agent-commands') {return args?.[0] === 'pi'@@ -40,7 +43,9 @@ function stubElectron() {}: { success: true, commands: [c('host-cmd', 'agent-builtin')] };}- if (channel === 'maker:list-agent-skills') return { success: true, skills: [c('host-skill', 'agent-skill')] };+ if (channel === 'maker:list-agent-skills') {+ return { success: true, skills: [c('learn', 'agent-skill'), c('host-skill', 'agent-skill')] };+ }return { success: false };});vi.stubGlobal('window', {@@ -62,8 +67,10 @@ describe('loadAllCommands deviceId', () => {workingDir: '/w',sessionId: 'local-session',});- // 本地会话:goal 命令保留(可对本地 session 设目标)。- expect(cmds.map((x) => x.name).sort()).toEqual(['compact', 'goal', 'help', 'localskill']);+ // 本地会话:goal 命令保留,learn 由可用的 Agent Skill 提供。+ expect(cmds.map((x) => x.name).sort()).toEqual([+ 'compact', 'goal', 'help', 'learn', 'localskill',+ ]);});it('本地 Claude 新对话 workingDir=null 时仍加载全局 skills', async () => {@@ -147,8 +154,10 @@ describe('loadAllCommands deviceId', () => {'claude-code',{ workingDir: '/host/path', sessionId: 'remote-session' },]);- // 结果 = 本地 desktop(help + goal,远程会话不再剔除)+ 被控端 builtin(host-cmd)+ 被控端 skill(host-skill)- expect(cmds.map((x) => x.name).sort()).toEqual(['goal', 'help', 'host-cmd', 'host-skill']);+ // 结果 = 本地 desktop(help + goal)+ 被控端 builtin(host-cmd)+ 被控端 skills(learn + host-skill)+ expect(cmds.map((x) => x.name).sort()).toEqual([+ 'goal', 'help', 'host-cmd', 'host-skill', 'learn',+ ]);// device-link 下 /goal 保留:业务体经隧道到被控端 goal-host,palette 正常展示。expect(cmds.some((x) => x.name === 'goal')).toBe(true);});diff --git a/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts b/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.tsindex 9cb0a00635..9c164cacd6 100644--- a/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/slashCommands.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it, vi } from 'vitest';+import { afterEach, describe, expect, it, vi } from 'vitest';import { CINDY_LEARN_SOURCE_DESCRIPTION } from '../../../shared/cindyBuiltInSkills';import {@@ -9,6 +9,7 @@ import {hasUnavailableProjectSkillPreview,isCindyOfficialSlashCommand,isSlashCommandUnavailable,+ loadAllCommands,mergeCommands,nextAvailableSlashCommandIndex,rebaseInlineRangesAfterSlashCommandRewrite,@@ -28,6 +29,45 @@ const skill = (overrides: Partial<Extract<UnifiedCommand, { kind: 'agent-skill'...overrides,});+afterEach(() => {+ vi.unstubAllGlobals();+});++function stubCommandLists(skillResult: { success: boolean; skills?: UnifiedCommand[] }) {+ vi.stubGlobal('window', {+ electronAPI: {+ maker: {+ listDesktopCommands: vi.fn(async () => ({+ success: true,+ commands: [{ kind: 'desktop', name: 'learn', description: 'Learn' }],+ })),+ listAgentCommands: vi.fn(async () => ({ success: true, commands: [] })),+ listAgentSkills: vi.fn(async () => skillResult),+ },+ },+ });+}++describe('loadAllCommands Learn fallback', () => {+ it.each([+ ['the Skill query fails', { success: false }],+ ['Learn is not discovered yet', { success: true, skills: [] }],+ ])('keeps the Desktop Learn command when %s', async (_label, result) => {+ stubCommandLists(result as { success: boolean; skills?: UnifiedCommand[] });++ await expect(loadAllCommands('claude-code', null)).resolves.toEqual([+ { kind: 'desktop', name: 'learn', description: 'Learn' },+ ]);+ });++ it('uses an available Agent Skill instead of the Desktop Learn fallback', async () => {+ const learnSkill = skill({ name: 'learn', builtIn: true });+ stubCommandLists({ success: true, skills: [learnSkill] });++ await expect(loadAllCommands('claude-code', null)).resolves.toEqual([learnSkill]);+ });+});+describe('commandsForHelpCard', () => {it('preserves only the Main-attested built-in marker needed for localized descriptions', () => {expect(commandsForHelpCard([diff --git a/apps/desktop/src/renderer/lib/slashCommands.ts b/apps/desktop/src/renderer/lib/slashCommands.tsindex e6606ab77e..1587e5dfe7 100644--- a/apps/desktop/src/renderer/lib/slashCommands.ts+++ b/apps/desktop/src/renderer/lib/slashCommands.ts@@ -390,13 +390,17 @@ export async function loadAllCommands(}const rawDesktop = (desktopRes.success && desktopRes.commands ? desktopRes.commands : []) as UnifiedCommand[];+ const agentSkill = (skillRes.success && skillRes.skills ? skillRes.skills : []) as UnifiedCommand[];// Learn 已迁成可开关的官方 Skill。本地/Device Link 能读 Skill 清单时只展示- // agent-skill;SSH 显式跳过扫描,才使用仍可路由 Learn host 的 Desktop 兼容入口。- const desktop = shouldLoadSkills+ // 实际可用的 agent-skill;SSH 显式跳过扫描、扫描失败或尚未发现 Skill 时,+ // 保留仍可路由 Learn host 的 Desktop 兼容入口。+ const hasAvailableLearnSkill = agentSkill.some((command) => (+ command.name.toLowerCase() === 'learn' && !isSlashCommandUnavailable(command)+ ));+ const desktop = shouldLoadSkills && hasAvailableLearnSkill? rawDesktop.filter((command) => command.name !== 'learn'): rawDesktop;const agentBuiltin = (builtinRes.success && builtinRes.commands ? builtinRes.commands : []) as UnifiedCommand[];- const agentSkill = (skillRes.success && skillRes.skills ? skillRes.skills : []) as UnifiedCommand[];return mergeCommands(desktop, agentBuiltin, agentSkill);}