Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(skills): collect direct Skills before namespaces in Pi and learn scanners
Zhang Yunjin19a8ca2fcbfb
diff --git a/apps/desktop/src/main/learn-host/__tests__/skillsIndex.test.ts b/apps/desktop/src/main/learn-host/__tests__/skillsIndex.test.tsindex 219bad0040..4767b4065b 100644--- a/apps/desktop/src/main/learn-host/__tests__/skillsIndex.test.ts+++ b/apps/desktop/src/main/learn-host/__tests__/skillsIndex.test.ts@@ -136,6 +136,36 @@ describe('listInstalledSkills — symlink 跟随', () => {}});+ it('does not list a nested Skill when a direct Skill has the same leaf name', async () => {+ const fs = await import('node:fs');+ const path = await import('node:path');+ const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'learn-skills-idx-dup-'));+ const root = path.join(tmpHome, '.agents', 'skills');+ // '@scope' sorts before 'same-name', so the nested Skill is discovered first+ // unless direct Skills are collected before namespaces.+ const nested = path.join(root, '@scope', 'same-name');+ const direct = path.join(root, 'same-name');+ for (const skillDir of [nested, direct]) {+ fs.mkdirSync(skillDir, { recursive: true });+ fs.writeFileSync(+ path.join(skillDir, 'SKILL.md'),+ `---\nname: ${path.basename(path.dirname(skillDir)) === '@scope' ? 'nested' : 'direct'}\ndescription: dup\n---\nBody`,+ 'utf8',+ );+ }++ const homeSpy = vi.spyOn(os, 'homedir').mockReturnValue(tmpHome);+ try {+ const { listInstalledSkills } = await import('../skillsIndex');+ const { entries } = await listInstalledSkills();++ expect(entries.map((entry) => entry.absolutePath)).toEqual([direct]);+ } finally {+ homeSpy.mockRestore();+ fs.rmSync(tmpHome, { recursive: true, force: true });+ }+ });+it('sorts nested Skills deterministically before truncating at the cap', async () => {const fs = await import('node:fs');const path = await import('node:path');diff --git a/apps/desktop/src/main/learn-host/skillsIndex.ts b/apps/desktop/src/main/learn-host/skillsIndex.tsindex bc72040e37..8ab9f23b03 100644--- a/apps/desktop/src/main/learn-host/skillsIndex.ts+++ b/apps/desktop/src/main/learn-host/skillsIndex.ts@@ -99,6 +99,9 @@ export async function listInstalledSkills(): Promise<{ entries: InstalledSkillEntopLevel.sort((a, b) => a.name.localeCompare(b.name));skillTargets = [];+ // Direct Skills first, so they win over nested Skills with the same leaf+ // name regardless of directory order.+ const namespaces: typeof topLevel = [];for (const entry of topLevel) {const skillFile = await findSkillMd(entry.path);if (skillFile) {@@ -109,8 +112,10 @@ export async function listInstalledSkills(): Promise<{ entries: InstalledSkillEn// 本根 —— 只认真实目录会漏掉它们。直接 symlink skill 已在上方计入;// symlink namespace 不下钻,避免越界或循环。if (entry.isSymlink || shouldPruneSkillScanDirectory(entry.name)) continue;-- // 最多一层 namespace/author: <root>/<namespace>/<skill>。+ namespaces.push(entry);+ }+ // 最多一层 namespace/author: <root>/<namespace>/<skill>。+ for (const entry of namespaces) {let nestedEntries: Dirent[];try {nestedEntries = await fs.readdir(entry.path, { withFileTypes: true });diff --git a/packages/maker-core/src/agents/shared/remote-skill-scanner.test.ts b/packages/maker-core/src/agents/shared/remote-skill-scanner.test.tsindex 517ee911d1..3016409b47 100644--- a/packages/maker-core/src/agents/shared/remote-skill-scanner.test.ts+++ b/packages/maker-core/src/agents/shared/remote-skill-scanner.test.ts@@ -105,13 +105,21 @@ describe('remote Skill scanners', () => {const fileOps = fakeRemoteFiles({'$HOME/.claude/skills/same-name/SKILL.md': '---\ndescription: Direct\n---','$HOME/.claude/skills/@scope/same-name/SKILL.md': '---\ndescription: Nested\n---',+ '$HOME/.agents/skills/late-name/SKILL.md': '---\ndescription: Direct\n---',+ '$HOME/.agents/skills/@scope/late-name/SKILL.md': '---\ndescription: Nested\n---',});- const result = await scanRemoteClaudeSkills({ fileOps });-- expect(result.skills).toEqual([+ // Claude merges by name; Pi dedupes by path, so it must not return two+ // same-named Skills regardless of which one the directory order finds first.+ const claude = await scanRemoteClaudeSkills({ fileOps });+ expect(claude.skills.filter((skill) => skill.name === 'same-name')).toEqual([expect.objectContaining({ name: 'same-name', description: 'Direct' }),]);++ const pi = await scanRemotePiSkills({ fileOps });+ expect(pi.skills.filter((skill) => skill.name === 'late-name')).toEqual([+ expect.objectContaining({ name: 'late-name', description: 'Direct' }),+ ]);});it('discovers Pi global, project, and ancestor Skills only through the Git boundary', async () => {diff --git a/packages/maker-core/src/agents/shared/remote-skill-scanner.ts b/packages/maker-core/src/agents/shared/remote-skill-scanner.tsindex 74a96a1859..849b319c88 100644--- a/packages/maker-core/src/agents/shared/remote-skill-scanner.ts+++ b/packages/maker-core/src/agents/shared/remote-skill-scanner.ts@@ -105,6 +105,9 @@ async function scanSkillDirectories(input: {});};+ // Direct Skills win over nested Skills with the same leaf name regardless of+ // directory order: collect them before walking namespaces.+ const namespaces: string[] = [];for (const name of names) {const skillDir = path.posix.join(input.root, name);const skillFile = await existingSkillFile(input.fileOps, skillDir);@@ -114,8 +117,12 @@ async function scanSkillDirectories(input: {}if (shouldPruneSkillScanDirectory(name)) continue;if (await isSymlinkedNamespace(input.fileOps, skillDir)) continue;+ namespaces.push(name);+ }- // At most one namespace/author level: <root>/<namespace>/<skill>.+ // At most one namespace/author level: <root>/<namespace>/<skill>.+ for (const name of namespaces) {+ const skillDir = path.posix.join(input.root, name);const nestedNames = (await input.fileOps.listDir(skillDir)).filter((nested) => nested && !nested.startsWith('.') && !nested.includes('/')&& !/\.bak\.\d+$/.test(nested))