Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(skillhub): 保留外部导入与详情跳转的项目范围
xd-bobo99660bc22f82
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.tsindex c1e00bb671..9fb1d86a62 100644--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts@@ -1157,6 +1157,36 @@ describe('skillhub/installService', () => {);});+ it('only removes selected project import links and metadata while retaining global imports', async () => {+ const source = path.join(TEST_ROOT, 'scoped-external', 'foo');+ const projectAlias = path.join(TEST_ROOT, 'selected-project', '.agents', 'skills', 'foo');+ const fakeHome = path.join(TEST_ROOT, 'scoped-home');+ const globalAlias = path.join(fakeHome, '.claude', 'skills', 'foo');+ fs.mkdirSync(source, { recursive: true });+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'fixture');+ makeDirectoryLink(projectAlias, source);+ makeDirectoryLink(globalAlias, source);+ const { inspectLocalSkillTarget } = await import('../localSkillTarget');+ const { registryService } = await import('../registry');+ const { uninstall } = await import('../installService');+ const entry = { version: '1.0.0', authorId: 'owner', folderHash: 'hash',+ installedAt: 1, updatedAt: 1, origin: 'installed' as const };+ vi.mocked(registryService.getInstall).mockResolvedValue(entry);+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([+ { skillName: 'foo', installPath: globalAlias, entry },+ { skillName: 'foo', installPath: projectAlias, entry },+ ]);+ const home = vi.spyOn(os, 'homedir').mockReturnValue(fakeHome);+ try {+ const result = await uninstall(source, inspectLocalSkillTarget(source, [projectAlias])!);+ expect(result).toEqual({ success: true });+ expect(fs.existsSync(projectAlias)).toBe(false);+ expect(fs.existsSync(globalAlias)).toBe(true);+ expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('fixture');+ expect(registryService.removeInstall).toHaveBeenCalledExactlyOnceWith('foo', projectAlias);+ } finally { home.mockRestore(); }+ });+it('refreshes the importing project when removing an external skill alias', async () => {const projectRoot = path.join(TEST_ROOT, 'importing-project');const alias = path.join(projectRoot, '.agents', 'skills', 'alias');diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.tsindex bddee06471..1451a55ca7 100644--- a/apps/desktop/src/main/skillhub/installService.ts+++ b/apps/desktop/src/main/skillhub/installService.ts@@ -962,7 +962,11 @@ export async function uninstall(}try {// Keep the exact registry identity for metadata cleanup after trash succeeds.- const registryMatch = await findRegistryInstallForPath(skillName, absolutePath, resolved);+ const registryMatch = target?.linkOnly+ ? (await registryService.listAllInstalls()).find((record) =>+ [skillName, path.basename(target.operationPath)].some((name) => skillInstallLockKey(name) === skillInstallLockKey(record.skillName))+ && target.aliases.some((alias) => pathTextEquals(path.resolve(alias), path.resolve(record.installPath)))) ?? null+ : await findRegistryInstallForPath(skillName, absolutePath, resolved);if (!registryMatch && !target) {return { success: false, errorCode: 'INTERNAL', message: 'No installation record or current local Skill grant' };}@@ -1066,7 +1070,7 @@ async function uninstallLocked(try { await ignoreAutoSyncSkill(skillName, cloudUserId ?? undefined); }catch { return { success: false, errorCode: 'WRITE_FAILED', message: 'Could not save uninstall preference' }; }}- const candidates = [...new Set([+ const candidates = target?.linkOnly ? [...new Set([...target.aliases, target.operationPath])] : [...new Set([...(target?.aliases ?? []), absolutePath,path.join(os.homedir(), '.claude', 'skills', skillName),path.join(os.homedir(), '.codex', 'skills', skillName),diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 2d29f54618..3b153ec23e 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -8957,7 +8957,7 @@ export function ChatInput({if (cmd.kind !== 'agent-skill' || cmd.source !== 'skill' || !cmd.path || cmd.origin === 'package') return;if (!sessionId && cmd.scope !== 'global' && cmd.scope !== 'user') return;draftSaveSchedulerRef.current?.flush();- navigate(buildLocalSkillPathRoute(cmd.path), { state: { resetHistory: true } });+ navigate(buildLocalSkillPathRoute(cmd.path, { scope: cmd.scope, workingDir }), { state: { resetHistory: true } });} : undefined}onClose={() => {if (trigger.kind === 'slash') setSuppressedSlashAt(trigger.from);diff --git a/apps/desktop/src/renderer/features/skillhub/lib/__tests__/localRoutes.test.ts b/apps/desktop/src/renderer/features/skillhub/lib/__tests__/localRoutes.test.tsindex 02d85234ec..369030d084 100644--- a/apps/desktop/src/renderer/features/skillhub/lib/__tests__/localRoutes.test.ts+++ b/apps/desktop/src/renderer/features/skillhub/lib/__tests__/localRoutes.test.ts@@ -34,6 +34,26 @@ describe('local SkillHub routes', () => {}});+ it('resolves the selected scope and nearest project for shared physical sources', () => {+ const source = '/checkout/skill';+ const global = entry({ id: 'global', scope: 'global', absolutePath: source,+ discoveredPath: '/home/.agents/skills/foo', projectRoot: undefined });+ const project = entry({ id: 'project', absolutePath: source, projectRoot: '/repo',+ discoveredPath: '/repo/.agents/skills/foo' });+ const nested = entry({ id: 'nested', absolutePath: source, projectRoot: '/repo/sub',+ discoveredPath: '/repo/sub/.agents/skills/foo' });+ const resolve = (scope?: string, workingDir?: string) => findLocalSkillRouteEntry(+ [global, project, nested], {}, new URL(buildLocalSkillPathRoute(`${source}/SKILL.md`,+ { scope, workingDir }), 'https://cindy.local').searchParams);+ expect(resolve('project', '/repo')).toBe(project);+ expect(resolve('repo', '/repo/sub/task')).toBe(nested);+ expect(resolve('user', '/repo')).toBe(global);+ expect(resolve('project', '/unrelated')).toBeNull();+ expect(resolve()).toBeNull();+ expect(findLocalSkillRouteEntry([global, project, nested], {},+ new URLSearchParams({ path: '/repo/.agents/skills/foo/SKILL.md' }))).toBe(project);+ });+it('supports Windows entrypoints and standalone Skill files without guessing by name', () => {const windows = entry({ absolutePath: 'C:\\Skills\\Demo' });const standalone = entry({ absolutePath: '/package/skills', mdPath: '/package/skills/demo.md' });diff --git a/apps/desktop/src/renderer/features/skillhub/lib/localRoutes.ts b/apps/desktop/src/renderer/features/skillhub/lib/localRoutes.tsindex 364e59939a..25b9957f97 100644--- a/apps/desktop/src/renderer/features/skillhub/lib/localRoutes.ts+++ b/apps/desktop/src/renderer/features/skillhub/lib/localRoutes.ts@@ -9,6 +9,7 @@ interface LocalSkillRouteEntry {discoveredPath?: string;discoveryPaths?: string[];projectHash?: string;+ projectRoot?: string;sourceKey?: string;requiresSourceKey?: boolean;}@@ -29,8 +30,12 @@ interface LocalSkillRouteParams {}/** Resolve a palette's SKILL.md path after the SkillHub scanner has loaded. */-export function buildLocalSkillPathRoute(path: string): string {- return `/skillhub/local/by-path?${new URLSearchParams({ path }).toString()}`;+export function buildLocalSkillPathRoute(path: string, context: { scope?: string; workingDir?: string | null } = {}): string {+ const search = new URLSearchParams({ path });+ const scope = context.scope === 'user' ? 'global' : context.scope === 'repo' ? 'project' : context.scope;+ if (scope === 'global' || scope === 'project') search.set('scope', scope);+ if (scope === 'project' && context.workingDir) search.set('workingDir', context.workingDir);+ return `/skillhub/local/by-path?${search.toString()}`;}function skillDirectoryPath(path: string): string {@@ -62,9 +67,26 @@ export function findLocalSkillRouteEntry<T extends LocalSkillRouteEntry>(const commandPath = searchParams.get('path');if (!kind && !name && commandPath) {const target = skillDirectoryPath(commandPath);- return skills.find((skill) => skill.kind === 'skill' && [+ const scope = searchParams.get('scope');+ const workingDir = searchParams.get('workingDir');+ let matches = skills.filter((skill) => skill.kind === 'skill' && (!scope || skill.scope === scope) && [skill.absolutePath, skill.mdPath, skill.discoveredPath, ...(skill.discoveryPaths ?? []),- ].some((path) => path && skillDirectoryPath(path) === target)) ?? null;+ ].some((path) => path && skillDirectoryPath(path) === target));+ if (scope === 'project' && workingDir) {+ const cwd = skillDirectoryPath(workingDir);+ matches = matches.filter((skill) => skill.projectRoot &&+ (cwd === skillDirectoryPath(skill.projectRoot) || cwd.startsWith(`${skillDirectoryPath(skill.projectRoot)}/`)));+ const nearest = Math.max(0, ...matches.map((skill) => skillDirectoryPath(skill.projectRoot!).length));+ matches = matches.filter((skill) => skillDirectoryPath(skill.projectRoot!).length === nearest);+ }+ // Older path-only URLs may still identify a unique lexical discovery entry.+ // Never pick an arbitrary copy merely because they share a physical source.+ if (matches.length > 1) {+ const lexical = matches.filter((skill) => [skill.discoveredPath, ...(skill.discoveryPaths ?? [])]+ .some((path) => path && skillDirectoryPath(path) === target));+ if (lexical.length === 1) return lexical[0]!;+ }+ return matches.length === 1 ? matches[0]! : null;}if (!kind || !name) return null;const decodedName = decodeURIComponent(name);diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 2dbe242cb4..dc594a6b4e 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -43,7 +43,9 @@`activation-preferences.json` 的可选 `discoveryPaths` 按物理路径保存已扫描的绝对发现路径数组;缺省兼容旧偏好。启动时复核指向,启用时删除该身份的入口记录,重命名时同事务迁移到新入口。插件托管技能只能在所属插件管理,详情禁用开关,Main 拒绝独立启停。- 物理卸载的清理快照汇总已扫描 scope 的同源发现链接,外部导入只移除所选 scope 的入口。+ 物理卸载的清理快照汇总已扫描 scope 的同源发现链接,外部导入只移除所选 scope 的入口+ 与对应词法注册记录,不追加其它范围的全局候选。斜杠详情路径携带 scope 与工作目录,+ 同源多副本按范围和最近项目匹配;旧路径无法唯一消歧时不任意选择副本。源目录形状不能单独证明归属:同一分组必须有直接、非符号链接的发现入口,才可按独立实体卸载;检查覆盖入口、发现根及引擎配置目录各级,拒绝其中的符号链接,保留发现布局以上的已跟踪项目别名兼容。外部入口移除及清理重试保留源文件和按物理身份共享的