Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(skillhub): 按扫描条目管理位置并清理跨范围链接

xd-bobo1169823faba5
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index b07b496a3a..7293061c14 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -229,6 +229,28 @@ describe('skillhub/installService', () => {
expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('external content');
});
+ it('cleans cross-scope aliases after physical removal and preserves a retargeted link', async () => {
+ const { source } = await localFixture('foo');
+ const globalAlias = path.join(TEST_ROOT, 'home', '.agents', 'skills', 'global-alias');
+ const projectAlias = path.join(TEST_ROOT, 'project', '.agents', 'skills', 'project-alias');
+ const replacedAlias = path.join(TEST_ROOT, 'other', '.agents', 'skills', 'replaced-alias');
+ for (const alias of [globalAlias, projectAlias, replacedAlias]) makeDirectoryLink(alias, source);
+ const { inspectLocalSkillTarget } = await import('../localSkillTarget');
+ const target = inspectLocalSkillTarget(source, [source, globalAlias, projectAlias, replacedAlias])!;
+ const otherSource = path.join(TEST_ROOT, 'unrelated');
+ fs.mkdirSync(otherSource);
+ fs.unlinkSync(replacedAlias);
+ makeDirectoryLink(replacedAlias, otherSource);
+ const { uninstall } = await import('../installService');
+ expect(await uninstall(source, target)).toEqual({ success: true });
+ for (const alias of [globalAlias, projectAlias]) {
+ expect(fs.lstatSync(alias, { throwIfNoEntry: false })).toBeUndefined();
+ // A fresh directory can now occupy the old alias name.
+ fs.mkdirSync(alias);
+ }
+ expect(fs.realpathSync.native(replacedAlias)).toBe(fs.realpathSync.native(otherSource));
+ });
+
it('rejects a source replaced while registry inspection is pending', async () => {
const { source, target } = await localFixture('replaced');
const { registryService } = await import('../registry');
diff --git a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
index 0e6edc8ca5..51d6bf2b48 100644
--- a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
@@ -634,6 +634,56 @@ describe('registerSkillhubIpc usage handlers', () => {
return { event, absolutePath, project };
}
+ async function scanSharedAliases(physicalProjectSkill: boolean) {
+ const root = fs.mkdtempSync(path.join(fixtureRoot, 'shared-aliases-'));
+ const projects = [path.join(root, 'project-a'), path.join(root, 'project-b')];
+ const source = physicalProjectSkill
+ ? path.join(projects[0]!, '.agents', 'skills', 'foo') : path.join(root, 'external', 'foo');
+ fs.mkdirSync(source, { recursive: true });
+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'fixture');
+ const absolutePath = fs.realpathSync.native(source);
+ const aliases = [path.join(root, 'home', '.agents', 'skills', 'global-alias'),
+ ...projects.map((project) => path.join(project, '.agents', 'skills', 'project-alias'))];
+ for (const alias of aliases) {
+ fs.mkdirSync(path.dirname(alias), { recursive: true });
+ fs.symlinkSync(source, alias, process.platform === 'win32' ? 'junction' : 'dir');
+ }
+ const records = aliases.map((alias, index) => ({
+ id: `entry-${index}`, kind: 'skill', name: 'foo', absolutePath,
+ scope: index === 0 ? 'global' : 'project',
+ discoveredPath: alias, discoveryPaths: [alias],
+ ...(index > 0 ? { projectRoot: projects[index - 1] } : {}),
+ }));
+ getAllowedProjectRoots.mockResolvedValue(projects);
+ scanAllSkills.mockResolvedValue({ skills: records, sources: [] });
+ const event = { sender: { id: 71, on: vi.fn(), once: vi.fn() } };
+ await handlers.get('skillhub:scan')!(event, { projects: projects.map((projectRoot, index) => ({ projectRoot, hash: `p${index}` })) });
+ return { absolutePath, aliases, records, projects, event };
+ }
+
+ it('uses the selected scan ID for external aliases and retains the selected project boundary', async () => {
+ const { absolutePath, aliases, projects, event } = await scanSharedAliases(false);
+ installServiceMocks.uninstall.mockResolvedValueOnce({ success: true });
+ await handlers.get('skillhub:uninstall')!(event, { absolutePath, skillId: 'entry-2' });
+ expect(installServiceMocks.uninstall).toHaveBeenCalledWith(absolutePath,
+ expect.objectContaining({ operationPath: aliases[2], aliases: [aliases[2]], linkOnly: true }), expect.any(Function));
+ await expect(handlers.get('skillhub:uninstall')!(event, { absolutePath, skillId: 'unknown' }))
+ .rejects.toThrow('PRECONDITION_FAILED');
+ getAllowedProjectRoots.mockResolvedValue([projects[0]]);
+ await expect(handlers.get('skillhub:uninstall')!(event, { absolutePath, skillId: 'entry-2' }))
+ .rejects.toThrow('PERMISSION_DENIED');
+ await expect(handlers.get('skillhub:set-enabled')!(event, { absolutePath, skillId: 'entry-2', enabled: false }))
+ .rejects.toThrow('PERMISSION_DENIED');
+ });
+
+ it('captures differently named discovery links across scopes for physical Skill removal', async () => {
+ const { absolutePath, aliases, event } = await scanSharedAliases(true);
+ installServiceMocks.uninstall.mockResolvedValueOnce({ success: true });
+ await handlers.get('skillhub:uninstall')!(event, { absolutePath, skillId: 'entry-1' });
+ expect(installServiceMocks.uninstall).toHaveBeenCalledWith(absolutePath,
+ expect.objectContaining({ operationPath: absolutePath, aliases: expect.arrayContaining(aliases), linkOnly: false }), expect.any(Function));
+ });
+
it('refreshes the Codex cwd cache after uninstalling a granted project skill', async () => {
const { event, absolutePath, project } = await scanLocalFixture();
installServiceMocks.uninstall.mockResolvedValueOnce({ success: true, projectWorkingDir: project });
diff --git a/apps/desktop/src/main/skillhub/registerIpc.ts b/apps/desktop/src/main/skillhub/registerIpc.ts
index 3b52d0b6e6..df31c4140c 100644
--- a/apps/desktop/src/main/skillhub/registerIpc.ts
+++ b/apps/desktop/src/main/skillhub/registerIpc.ts
@@ -133,12 +133,14 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
}
}
};
- const requireLocalSkill = async (event: Electron.IpcMainInvokeEvent, source: string) => {
+ const requireLocalSkill = async (event: Electron.IpcMainInvokeEvent, source: string, skillId?: string) => {
assertTrustedAppRendererEvent(event);
if (typeof source !== 'string' || !path.isAbsolute(source)) throwIpcError('INVALID_PARAMS', 'Invalid Skill');
+ if (skillId !== undefined && (typeof skillId !== 'string' || !skillId)) throwIpcError('INVALID_PARAMS', 'Invalid Skill identity');
const ownerId = getCurrentDataOwnerId();
const grant = scannedSkillRootsBySender.get(event.sender.id);
- const record = localSkillsBySender.get(event.sender.id)?.find(({ skill }) => skill.absolutePath === source);
+ const record = localSkillsBySender.get(event.sender.id)?.find(({ skill }) =>
+ skill.absolutePath === source && (skillId === undefined || skill.id === skillId));
if (!record || !ownerId || grant?.ownerId !== ownerId || isAppSessionBoundaryPending()) {
throwIpcError('PRECONDITION_FAILED', 'Refresh the Skill list and retry');
}
@@ -216,13 +218,27 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
}
}
scannedSkillRootsBySender.set(event.sender.id, { ownerId, entries });
- localSkillsBySender.set(event.sender.id, skills.flatMap((skill) => {
+ const records = skills.flatMap((skill) => {
if (skill.kind !== 'skill') return [];
try {
return [{ skill, physicalIdentity: physicalIdentity(skill.absolutePath),
target: inspectLocalSkillTarget(skill.absolutePath, skill.discoveryPaths ?? [skill.discoveredPath], options.getManagedSkillRoots()) }];
} catch { return []; }
- }));
+ });
+ const aliasesByIdentity = new Map<string, Set<string>>();
+ for (const record of records) {
+ const aliases = aliasesByIdentity.get(record.physicalIdentity) ?? new Set<string>();
+ for (const alias of record.target?.aliases ?? []) aliases.add(alias);
+ aliasesByIdentity.set(record.physicalIdentity, aliases);
+ }
+ for (const record of records) {
+ // Removing the physical entity must clean every scanned scope's links.
+ // Removing an external import keeps its scope-local operation/aliases.
+ if (record.target && !record.target.linkOnly) {
+ record.target.aliases = [...aliasesByIdentity.get(record.physicalIdentity)!];
+ }
+ }
+ localSkillsBySender.set(event.sender.id, records);
};
const hasScannedSkillGrant = (
@@ -959,9 +975,9 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
},
);
- ipcMain.handle('skillhub:set-enabled', async (event, params: { absolutePath: string; enabled: boolean }) => {
+ ipcMain.handle('skillhub:set-enabled', async (event, params: { absolutePath: string; skillId?: string; enabled: boolean }) => {
if (typeof params?.enabled !== 'boolean') throwIpcError('INVALID_PARAMS', 'Invalid Skill state');
- const record = await requireLocalSkill(event, params.absolutePath);
+ const record = await requireLocalSkill(event, params.absolutePath, params.skillId);
const { skill } = record;
const ownerId = getCurrentDataOwnerId();
const canMutate = () => {
@@ -984,8 +1000,8 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
// Main resolves the exact scanned entity; no arbitrary renderer path deletion.
ipcMain.handle(
'skillhub:uninstall',
- async (event, { absolutePath }: { absolutePath: string }) => {
- const { target } = await requireLocalSkill(event, absolutePath);
+ async (event, { absolutePath, skillId }: { absolutePath: string; skillId?: string }) => {
+ const { target } = await requireLocalSkill(event, absolutePath, skillId);
if (!target || !isLocalSkillTargetCurrent(target) || isPluginManagedSkillPath(target.sourcePath, options.getManagedSkillRoots())) {
throwIpcError('PRECONDITION_FAILED', 'Skill cannot be uninstalled; refresh and retry');
}
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index ae120022c1..ab2cd125c9 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -2946,7 +2946,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
// ~/.claude/{skills,commands,agents},project 来源由调用方传入的 projectRoot 决定。
// 返回商店层 Skill[] 与兼容用 sources[];scan 本身只读。
skillhub: {
- setEnabled: (params: { absolutePath: string; enabled: boolean }): Promise<{ cindyEnabled: boolean }> =>
+ setEnabled: (params: { absolutePath: string; skillId?: string; enabled: boolean }): Promise<{ cindyEnabled: boolean }> =>
ipcRenderer.invoke('skillhub:set-enabled', params),
onLocalStateChanged: fanOutSkillhubLocalStateChanged,
scan: (params: {
@@ -3377,8 +3377,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
// Main 校验当前扫描实体后移入系统回收站。
uninstall: (
absolutePath: string,
+ skillId?: string,
): Promise<{ success: true; cleanupToken?: string } | { success: false; errorCode: string; message: string }> =>
- ipcRenderer.invoke('skillhub:uninstall', { absolutePath }),
+ ipcRenderer.invoke('skillhub:uninstall', { absolutePath, skillId }),
retryUninstallCleanup: (token: string): Promise<{ complete: boolean }> =>
ipcRenderer.invoke('skillhub:retry-uninstall-cleanup', token),
diff --git a/apps/desktop/src/renderer/features/skillhub/components/LocalSkillControls.tsx b/apps/desktop/src/renderer/features/skillhub/components/LocalSkillControls.tsx
index aef198b05d..32ede8a7ff 100644
--- a/apps/desktop/src/renderer/features/skillhub/components/LocalSkillControls.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/components/LocalSkillControls.tsx
@@ -33,7 +33,7 @@ export function LocalSkillControls({ skill, disabled = false, onUninstalled }: {
setBusy(true);
setPendingEnabled(value);
try {
- await window.electronAPI.skillhub.setEnabled({ absolutePath: skill.absolutePath, enabled: value });
+ await window.electronAPI.skillhub.setEnabled({ absolutePath: skill.absolutePath, skillId: skill.id, enabled: value });
await refresh();
toast.success(t(value ? 'skillhub.management.enabledToast' : 'skillhub.management.disabledToast', { name: skill.name }));
} catch (error) { reportError(error, 'toggleFailed'); }
@@ -61,7 +61,7 @@ export function LocalSkillControls({ skill, disabled = false, onUninstalled }: {
cancelText: t('skillhub.detail.uninstallDialog.cancel'),
});
if (!accepted) return;
- const result = await window.electronAPI.skillhub.uninstall(skill.absolutePath);
+ const result = await window.electronAPI.skillhub.uninstall(skill.absolutePath, skill.id);
if (!result.success) {
toast.error(t('skillhub.management.uninstallFailed'));
return;
diff --git a/apps/desktop/src/renderer/features/skillhub/components/MarketLocalSkills.tsx b/apps/desktop/src/renderer/features/skillhub/components/MarketLocalSkills.tsx
index 32b43cc405..f816120094 100644
--- a/apps/desktop/src/renderer/features/skillhub/components/MarketLocalSkills.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/components/MarketLocalSkills.tsx
@@ -14,7 +14,7 @@ export function MarketLocalSkills({ skill }: {
}) {
const { t } = useTranslation();
const { skills } = useSkillhub();
- const [selectedPath, setSelectedPath] = useState<string | null>(null);
+ const [selectedId, setSelectedId] = useState<string | null>(null);
const copies = skills.filter((local) => {
if (local.kind !== 'skill' || local.name !== skill.name) return false;
return local.registryEntry
@@ -24,9 +24,14 @@ export function MarketLocalSkills({ skill }: {
});
if (copies.length === 0) return null;
- const selected = copies.find((local) => local.absolutePath === selectedPath) ?? copies[0]!;
+ const selected = copies.find((local) => local.id === selectedId) ?? copies[0]!;
const scopeLabel = (local: SkillhubSkill) => t(local.scope === 'project'
? 'skillhub.detail.scopeProject' : 'skillhub.detail.scopeGlobal');
+ const locationLabel = (local: SkillhubSkill) => {
+ const discoveredPath = local.discoveredPath ?? local.absolutePath;
+ return local.scope === 'project' && local.projectRoot
+ ? `${local.projectRoot} · ${discoveredPath}` : discoveredPath;
+ };
return (
<div className="flex h-8 shrink-0 items-center gap-2 border-l border-[var(--border-default)] pl-3">
@@ -34,22 +39,22 @@ export function MarketLocalSkills({ skill }: {
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" className="w-40 gap-1.5 px-3"
- aria-label={t('skillhub.sidebar.marketInstalledHeading')} title={selected.absolutePath}>
+ aria-label={t('skillhub.sidebar.marketInstalledHeading')} title={locationLabel(selected)}>
<span className="truncate">{scopeLabel(selected)}</span>
<ChevronDown size={14} className="shrink-0" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end"
className="w-[var(--radix-dropdown-menu-trigger-width)] min-w-0 rounded-xl border-[var(--border-default)] bg-[var(--surface-elevated)] p-1.5 shadow-none">
- <DropdownMenuRadioGroup value={selected.absolutePath} onValueChange={setSelectedPath}>
+ <DropdownMenuRadioGroup value={selected.id} onValueChange={setSelectedId}>
{copies.map((local) => (
- <DropdownMenuRadioItem key={local.absolutePath} value={local.absolutePath}
+ <DropdownMenuRadioItem key={local.id} value={local.id}
className="rounded-lg text-13 focus:bg-[var(--surface-hover)] data-[state=checked]:bg-[var(--surface-chip)]">
<span className="min-w-0">
<span className="block">{scopeLabel(local)}{' · '}
{local.registryEntry ? `v${local.registryEntry.version}` : t('skillhub.sidebar.marketLocalCopy')}
</span>
- <span className="block break-all text-11 text-[var(--text-secondary)]">{local.absolutePath}</span>
+ <span className="block break-all text-11 text-[var(--text-secondary)]">{locationLabel(local)}</span>
</span>
</DropdownMenuRadioItem>
))}
@@ -57,7 +62,7 @@ export function MarketLocalSkills({ skill }: {
</DropdownMenuContent>
</DropdownMenu>
)}
- <LocalSkillControls key={selected.absolutePath} skill={selected} />
+ <LocalSkillControls key={selected.id} skill={selected} />
</div>
);
}
diff --git a/apps/desktop/src/renderer/features/skillhub/components/__tests__/LocalSkillControls.test.tsx b/apps/desktop/src/renderer/features/skillhub/components/__tests__/LocalSkillControls.test.tsx
index a42928c3ec..2bf890da9e 100644
--- a/apps/desktop/src/renderer/features/skillhub/components/__tests__/LocalSkillControls.test.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/components/__tests__/LocalSkillControls.test.tsx
@@ -14,7 +14,7 @@ vi.mock('@/lib/toast', () => ({ toast: {
} }));
import { LocalSkillControls } from '../LocalSkillControls';
-const skill = { name: 'example', kind: 'skill', absolutePath: '/fixture/.agents/skills/example',
+const skill = { id: 'global-example', name: 'example', kind: 'skill', absolutePath: '/fixture/.agents/skills/example',
scope: 'global', cindyEnabled: true, canUninstall: true } as SkillhubSkill;
async function chooseUninstall() {
@@ -70,7 +70,7 @@ describe('Local Skill management', () => {
render(<LocalSkillControls skill={{ ...skill, cindyEnabled: false }} />);
fireEvent.click(screen.getByRole('switch'));
await waitFor(() => expect(mocks.success).toHaveBeenCalledWith('skillhub.management.enabledToast'));
- expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: skill.absolutePath, enabled: true });
+ expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: skill.absolutePath, skillId: skill.id, enabled: true });
expect(mocks.refresh).toHaveBeenCalledOnce();
});
@@ -90,7 +90,7 @@ describe('Local Skill management', () => {
expect(mocks.confirm.mock.calls[0][0].description).toBe([
'skillhub.management.unlinkDescription', 'skillhub.management.projectScope', 'skillhub.management.sharedImpact',
].join('\n\n'));
- expect(mocks.uninstall).toHaveBeenCalledWith(skill.absolutePath);
+ expect(mocks.uninstall).toHaveBeenCalledWith(skill.absolutePath, skill.id);
});
it('keeps package-owned uninstall unavailable', async () => {
diff --git a/apps/desktop/src/renderer/features/skillhub/components/__tests__/MarketLocalSkills.test.tsx b/apps/desktop/src/renderer/features/skillhub/components/__tests__/MarketLocalSkills.test.tsx
index 5a688ba072..2334c761cf 100644
--- a/apps/desktop/src/renderer/features/skillhub/components/__tests__/MarketLocalSkills.test.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/components/__tests__/MarketLocalSkills.test.tsx
@@ -36,6 +36,7 @@ const market: MarketSkill = {
latestPublishedFromDeviceId: null, cardState: 'installed-latest',
};
const local = {
+ id: 'global-calendar',
name: market.name, kind: 'skill', absolutePath: '/fixture/.agents/skills/gws-calendar',
scope: 'global', registryEntry: { catalogScope: 'market', version: '1.0.2' },
cindyEnabled: true, canUninstall: true,
@@ -78,16 +79,16 @@ describe('market Skill details', () => {
expect(screen.getByRole('switch').getAttribute('data-state')).toBe('checked');
fireEvent.click(screen.getByRole('switch'));
await waitFor(() => expect(mocks.refresh).toHaveBeenCalledOnce());
- expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: local.absolutePath, enabled: false });
+ expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: local.absolutePath, skillId: local.id, enabled: false });
fireEvent.keyDown(screen.getByRole('button', { name: 'skillhub.management.moreLabel' }), { key: 'Enter' });
fireEvent.click(await screen.findByRole('menuitem', { name: 'skillhub.detail.uninstall' }));
- await waitFor(() => expect(mocks.uninstall).toHaveBeenCalledWith(local.absolutePath));
+ await waitFor(() => expect(mocks.uninstall).toHaveBeenCalledWith(local.absolutePath, local.id));
});
});
describe('market installed location matching', () => {
it('selects a local copy in the toolbar and falls back after that copy is removed', async () => {
- const project = { ...local, scope: 'project', projectRoot: '/project',
+ const project = { ...local, id: 'project-calendar', scope: 'project', projectRoot: '/project',
absolutePath: '/project/.agents/skills/gws-calendar', cindyEnabled: false } as SkillhubSkill;
mocks.skills = [local, project];
const { rerender } = render(<MarketLocalSkills skill={market} />);
@@ -97,7 +98,7 @@ describe('market installed location matching', () => {
fireEvent.click(await screen.findByRole('menuitemradio', { name: new RegExp(project.absolutePath) }));
expect(screen.getByRole('switch').getAttribute('aria-checked')).toBe('false');
fireEvent.click(screen.getByRole('switch'));
- await waitFor(() => expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: project.absolutePath, enabled: true }));
+ await waitFor(() => expect(mocks.setEnabled).toHaveBeenCalledWith({ absolutePath: project.absolutePath, skillId: project.id, enabled: true }));
mocks.skills = [local];
rerender(<MarketLocalSkills skill={market} />);
expect(screen.getAllByRole('switch')).toHaveLength(1);
@@ -107,6 +108,24 @@ describe('market installed location matching', () => {
expect(screen.queryByRole('switch')).toBeNull();
});
+ it.each(['global', 'project'] as const)('selects the second entry sharing a physical path with a %s entry', async (firstScope) => {
+ const first = { ...local, scope: firstScope, projectRoot: '/first-project' };
+ const second = { ...local, id: 'second-project-calendar', scope: 'project', projectRoot: '/second-project' } as SkillhubSkill;
+ mocks.skills = [first, second];
+ render(<MarketLocalSkills skill={market} />);
+ fireEvent.keyDown(screen.getByRole('button', { name: 'skillhub.sidebar.marketInstalledHeading' }), { key: 'Enter' });
+ const locations = await screen.findAllByRole('menuitemradio');
+ expect(locations[1]!.textContent).toContain('/second-project');
+ fireEvent.click(locations[1]!);
+ fireEvent.click(screen.getByRole('switch'));
+ await waitFor(() => expect(mocks.setEnabled).toHaveBeenCalledWith({
+ absolutePath: second.absolutePath, skillId: second.id, enabled: false,
+ }));
+ fireEvent.keyDown(screen.getByRole('button', { name: 'skillhub.management.moreLabel' }), { key: 'Enter' });
+ fireEvent.click(await screen.findByRole('menuitem', { name: 'skillhub.detail.uninstall' }));
+ await waitFor(() => expect(mocks.uninstall).toHaveBeenCalledWith(second.absolutePath, second.id));
+ });
+
it('does not manage same-name copies from another catalog or unregistered third-party copies', () => {
mocks.skills = [
{ ...local, registryEntry: { ...local.registryEntry!, catalogScope: 'team' } },
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 7af77d16b6..73fb8f203b 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -3162,7 +3162,7 @@ interface ElectronAPI {
// ── SkillHub (xdt-maker-技能中心 v0.2) ──
skillhub: {
- setEnabled: (params: { absolutePath: string; enabled: boolean }) => Promise<{ cindyEnabled: boolean }>;
+ setEnabled: (params: { absolutePath: string; skillId?: string; enabled: boolean }) => Promise<{ cindyEnabled: boolean }>;
onLocalStateChanged: (callback: () => void) => () => void;
scan: (params: { projects?: SkillhubProjectInput[] }) => Promise<{
success: boolean;
@@ -3501,6 +3501,7 @@ interface ElectronAPI {
cancelInstall: (name: string) => Promise<{ success: boolean }>;
uninstall: (
absolutePath: string,
+ skillId?: string,
) => Promise<{ success: true; cleanupToken?: string } | { success: false; errorCode: string; message: string }>;
retryUninstallCleanup: (token: string) => Promise<{ complete: boolean }>;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index f24fbbb17d..a98e3ff35d 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -37,6 +37,10 @@
### Skill Hub 目录与管理契约
+- Desktop 本地技能管理用扫描条目 `id` 区分不同 scope / 项目中的同源记录;启停与卸载
+ 的本地 IPC 可选携带 `skillId`,Main 同时匹配路径、当前发送窗口的扫描记录和项目授权,
+ 缺省字段保留旧调用行为,不向 device-link 新开放管理能力。启停偏好仍按物理身份共享;
+ 物理卸载的清理快照汇总已扫描 scope 的同源发现链接,外部导入只移除所选 scope 的入口。
- `scope=market|team` 是公开与组织目录的通用读取上下文;列表得到的 scope 必须贯穿详情、
文件、版本、扫描、下载、Learn 和批量同步。同 slug 在不同 scope 下是两条独立远端记录;
但全局 Skill 发现路径仍按 slug 只有一个安装槽,自动同步配置重复同一 slug 时由首个有效项