Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): limit skill deduplication to settings display
xd2857964f0a4a
diff --git a/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx b/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsxindex 2f9fcf6057..5278bc9169 100644--- a/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx+++ b/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx@@ -151,13 +151,21 @@ export function BotCapabilitySettings({if (!isCurrent()) return;const [personalResult, skillResult, toolsetResult] = results;const next: Partial<Record<Kind, Entry[]>> = {};- if (skillResult.status === 'fulfilled' && skillResult.value.success)- next.skill = (skillResult.value.skills ?? []).map((item) => ({+ if (skillResult.status === 'fulfilled' && skillResult.value.success) {+ const seenSkillNames = new Set<string>();+ // Settings select skills by name. Multiple discovery sources must+ // share one switch, retaining the first source's metadata and state.+ next.skill = (skillResult.value.skills ?? []).filter((item) => {+ if (seenSkillNames.has(item.name)) return false;+ seenSkillNames.add(item.name);+ return true;+ }).map((item) => ({id: item.name,name: item.name,description: item.description,available: item.enabled !== false && item.runtimeStatus !== 'failed',}));+ }if (personalResult.status === 'fulfilled') next.skill = [...personalResult.value.map(item => ({ id: `personal:${item.slug}`, name: item.name, available: item.enabled !== false, personal: true })),...(next.skill ?? []),diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsxindex 2c18ddafbe..5f25f58c47 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx@@ -66,6 +66,41 @@ describe('controlled capability page lifetime', () => {});});+it.each([true, false])('shows one skill switch per selection ID and preserves the first enabled=%s state', async (enabled) => {+ const discovered = [+ { name: 'agent-ops', path: '/home/.agents/skills/agent-ops/SKILL.md', scope: 'repo',+ description: 'First source description', enabled },+ { name: 'agent-ops', path: '/home/.agents/skills/agent-ops/SKILL.md', scope: 'user',+ description: 'Duplicate source description', enabled: !enabled },+ { name: 'unique-skill', path: '/project/.pi/skills/unique-skill/SKILL.md', enabled: true },+ ];+ const listAgentSkills = vi.fn(async () => ({ success: true, skills: discovered }));+ Object.defineProperty(window, 'electronAPI', { configurable: true, value: {+ localDb: { sessionsPush: { onPatched: () => h.offPush }, bots: { listSkills: async () => [] } },+ maker: { onMcpChanged: () => h.offMcp, listCustomMcpServers: h.list,+ listAgentSkills, plugins: { list: async () => [] } },+ } });+ const onChange = vi.fn();+ const view = render(<BotCapabilitySettings expanded+ bot={{ id: 'bot-1', canonicalSessionId: 's1' } as BotProfile}+ capabilities={{ modelChain: [], modelChainOverride: null, mcpServers: [], toolsets: [] } as unknown as BotProfile['capabilities']}+ skills={[]} onChange={onChange} />);++ await waitFor(() => expect(view.getAllByRole('switch', { name: 'agent-ops' })).toHaveLength(1));+ const checkbox = view.getByRole('switch', { name: 'agent-ops' }) as HTMLButtonElement;+ expect(checkbox.disabled).toBe(!enabled);+ expect(view.getByText('First source description')).toBeTruthy();+ expect(view.queryByText('Duplicate source description')).toBeNull();+ expect(view.getByRole('switch', { name: 'unique-skill' })).toBeTruthy();+ if (enabled) {+ fireEvent.click(checkbox);+ expect(onChange).toHaveBeenCalledExactlyOnceWith('skill', ['agent-ops']);+ }+ // Rendering must leave the discovery catalog intact for other consumers.+ expect(discovered).toHaveLength(3);+ expect(listAgentSkills).toHaveBeenCalledOnce();+});+it('shows inherited tools as selected and preserves the others when one is explicitly removed', async () => {Object.defineProperty(window, 'electronAPI', { configurable: true, value: {diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-skills.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-skills.test.tsindex 211a218d80..b43afa3af4 100644--- a/packages/maker-core/src/agents/pi/__tests__/pi-skills.test.ts+++ b/packages/maker-core/src/agents/pi/__tests__/pi-skills.test.ts@@ -5,8 +5,8 @@* SKILL.md,与 CC/Codex 的技能可见性对齐;发现层零基线上下文(仅 name/description)。*/-import { mkdtempSync, mkdirSync, realpathSync, symlinkSync, writeFileSync, rmSync } from 'node:fs';-import os, { tmpdir } from 'node:os';+import { mkdtempSync, mkdirSync, realpathSync, writeFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';import path from 'node:path';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -43,10 +43,8 @@ describe('PiAgent.listAgentSkills (filesystem discovery, no binary spawn)', () =let workingDir = '';beforeEach(() => {workingDir = mkdtempSync(path.join(tmpdir(), 'pi-skills-'));- vi.spyOn(os, 'homedir').mockReturnValue(workingDir);});afterEach(() => {- vi.restoreAllMocks();rmSync(workingDir, { recursive: true, force: true });});@@ -75,66 +73,8 @@ describe('PiAgent.listAgentSkills (filesystem discovery, no binary spawn)', () =it('returns a skills array without throwing when the project has no skill dirs', async () => {const agent = new PiAgent(buildDeps());const result = await agent.listAgentSkills({ workingDir });- expect(result.skills).toEqual([]);- });-- it.each([true, false])('keeps one managed entry and its enabled=%s state when discovery follows a symlink to it', async (enabled) => {- const source = path.join(workingDir, 'managed', 'shared');- const sharedRoot = path.join(workingDir, '.agents', 'skills');- mkdirSync(source, { recursive: true });- mkdirSync(sharedRoot, { recursive: true });- const entry = path.join(source, 'SKILL.md');- writeFileSync(entry, '---\nname: shared\ndescription: scanned description\n---\n');- symlinkSync(source, path.join(sharedRoot, 'shared'), process.platform === 'win32' ? 'junction' : 'dir');- const managed = {- kind: 'agent-skill' as const, source: 'skill' as const, scope: 'user' as const,- name: 'shared', description: 'managed description', path: entry, enabled,- claudeCommandName: 'managed-shared',- };- const agent = new PiAgent({ ...buildDeps(), getManagedSkills: async () => [managed] });-- const result = await agent.listAgentSkills({ workingDir });-- expect(result.skills).toEqual([{- kind: 'agent-skill', source: 'skill', scope: 'user',- name: 'shared', description: 'managed description', path: entry, enabled,- runtimeCommandName: 'skill:shared',- }]);- });-- it('deduplicates overlapping package paths without hiding same-name skills from different files', async () => {- const source = path.join(workingDir, '.pi', 'skills', 'shared');- mkdirSync(source, { recursive: true });- const entry = path.join(source, 'SKILL.md');- writeFileSync(entry, '---\nname: shared\ndescription: project skill\n---\n');- const managedEntry = path.join(workingDir, 'managed', 'SKILL.md');- const uniquePackage = path.join(workingDir, 'package', 'SKILL.md');- const agent = new PiAgent({- ...buildDeps(),- getManagedSkills: async () => [{- kind: 'agent-skill', source: 'skill', scope: 'user',- name: 'shared', path: managedEntry, enabled: true, claudeCommandName: 'managed-shared',- }],- resolvePiManagedPackageResources: async () => ({- extensions: [], promptTemplates: [], packageRoots: [workingDir],- skills: [- { name: 'shared', path: managedEntry },- { name: 'shared', path: entry },- { name: 'package-only', path: uniquePackage },- ],- }),- });-- const result = await agent.listAgentSkills({ workingDir, includeManagedPiPackages: true });-- expect(result.skills.map((skill) => skill.path)).toEqual([uniquePackage, managedEntry, entry]);- expect(result.skills.filter((skill) => skill.name === 'shared')).toHaveLength(2);- expect(result.skills.find((skill) => skill.path === entry)).toMatchObject({- origin: 'package', runtimeStatus: 'approved', runtimeCommandName: 'skill:shared',- });- expect(result.skills.find((skill) => skill.path === uniquePackage)).toMatchObject({- origin: 'package', runtimeStatus: 'approved', runtimeCommandName: 'skill:package-only',- });+ // 真实环境可能有用户级 ~/.agents/skills,故只断言"不抛 + 是数组",不断言空。+ expect(Array.isArray(result.skills)).toBe(true);});it('includes Cindy-managed package skills only when the host explicitly allows them', async () => {diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.tsindex 95277301fd..29c68483dd 100644--- a/packages/maker-core/src/agents/pi/index.ts+++ b/packages/maker-core/src/agents/pi/index.ts@@ -8560,8 +8560,6 @@ export class PiAgent extends BaseAgent {}),opts.includeManagedPiPackages ? this.deps.resolvePiManagedPackageResources?.().catch(() => undefined) : undefined,]);- const packageSkillPaths = new Set((managedPackages?.skills ?? []).map((skill) => canonicalSkillPath(skill.path)));- const seenSkillPaths = new Set<string>();const out: ListAgentSkillsResult = {skills: [...(await this.deps.getManagedSkills?.() ?? []).map(({ claudeCommandName: _command, ...skill }) =>@@ -8580,8 +8578,7 @@ export class PiAgent extends BaseAgent {enabled: it.enabled ?? true,runtimeStatus: it.runtimeStatus,runtimeCommandName: `skill:${it.name}`,- }))- .filter((skill) => !packageSkillPaths.has(canonicalSkillPath(skill.path))),+ })),...(managedPackages?.skills ?? []).map((skill) => ({kind: 'agent-skill' as const,name: skill.name,@@ -8594,15 +8591,7 @@ export class PiAgent extends BaseAgent {runtimeStatus: 'approved' as const,runtimeCommandName: `skill:${skill.name}`,})),- ].filter((skill) => {- if (!skill.path) return true;- // Host-managed and package metadata win over filesystem aliases.- // Names alone cannot identify distinct project and user skills.- const identity = canonicalSkillPath(skill.path);- if (seenSkillPaths.has(identity)) return false;- seenSkillPaths.add(identity);- return true;- }).sort((a, b) => a.name.localeCompare(b.name)),+ ].sort((a, b) => a.name.localeCompare(b.name)),};if (errors.length > 0) out.errors = errors;return out;