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-bobo785c721c9b2f
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index 7293061c14..7a03a8d6ef 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -209,8 +209,9 @@ describe('skillhub/installService', () => {
expect(isCindySkillEnabled(source)).toBe(false);
});
- it('removes only an external import link and leaves its source untouched', async () => {
- const source = path.join(TEST_ROOT, 'external', 'shared');
+ it.each(['ordinary', 'skill-shaped'])('removes only an external import link and leaves its source untouched (%s)', async (layout) => {
+ const source = layout === 'ordinary' ? path.join(TEST_ROOT, 'external', 'shared')
+ : path.join(TEST_ROOT, 'checkout', '.agents', 'skills', 'shared');
const alias = path.join(TEST_ROOT, '.agents', 'skills', 'shared');
fs.mkdirSync(source, { recursive: true });
fs.writeFileSync(path.join(source, 'SKILL.md'), 'external content');
@@ -229,6 +230,40 @@ describe('skillhub/installService', () => {
expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('external content');
});
+ it.each(['complete', 'retry'])('preserves shared disabled state after removing one external scope (%s)', async (outcome) => {
+ const source = path.join(TEST_ROOT, 'external', 'shared');
+ const alias = path.join(TEST_ROOT, '.agents', 'skills', 'global-import');
+ const otherAlias = path.join(TEST_ROOT, 'project', '.agents', 'skills', 'project-import');
+ fs.mkdirSync(source, { recursive: true });
+ fs.writeFileSync(path.join(source, 'SKILL.md'), 'external content');
+ for (const entry of [alias, otherAlias]) makeDirectoryLink(entry, source);
+ const { inspectLocalSkillTarget } = await import('../localSkillTarget');
+ const target = inspectLocalSkillTarget(source, [alias])!;
+ const { registryService } = await import('../registry');
+ vi.mocked(registryService.getInstall).mockResolvedValue(null);
+ vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ const { setCindySkillEnabled, isCindySkillEnabled } = await import('../activationPreferences');
+ await setCindySkillEnabled(source, false);
+ const { shell } = await import('electron');
+ let cleanupBlocked = false;
+ vi.mocked(shell.trashItem).mockImplementationOnce(async (entry) => {
+ await fs.promises.rename(entry, path.join(TEST_ROOT, 'removed-import'));
+ cleanupBlocked = outcome === 'retry';
+ });
+ const { uninstall, retryUninstallCleanup } = await import('../installService');
+ const result = await uninstall(source, target, () => !cleanupBlocked);
+ expect(result).toMatchObject({ success: true });
+ if (outcome === 'retry') {
+ expect(result).toHaveProperty('cleanupToken');
+ if (result.success && result.cleanupToken) {
+ expect(await retryUninstallCleanup(result.cleanupToken, () => true)).toBe(true);
+ }
+ }
+ expect(fs.lstatSync(alias, { throwIfNoEntry: false })).toBeUndefined();
+ expect(fs.readFileSync(path.join(otherAlias, 'SKILL.md'), 'utf8')).toBe('external content');
+ expect(isCindySkillEnabled(otherAlias)).toBe(false);
+ });
+
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');
diff --git a/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts b/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts
index 531d366ada..aa2fc16d5c 100644
--- a/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts
@@ -43,6 +43,21 @@ describe('local Skill removal targets', () => {
expect(inspectLocalSkillTarget(system, [system])).toBeNull();
});
+ it.each([
+ ['.agents', 'skills'], ['.claude', 'skills'], ['.pi', 'agent', 'skills'], ['codex-home', 'skills'],
+ ])('treats a linked source under a Skill-shaped checkout as an import (%s)', (...segments) => {
+ const key = segments.join('-');
+ const source = directory(`checkout-${key}`, ...segments, 'source');
+ const alias = path.join(root, '.agents', 'skills', `import-${key}`);
+ fs.mkdirSync(path.dirname(alias), { recursive: true });
+ fs.symlinkSync(source, alias, process.platform === 'win32' ? 'junction' : 'dir');
+ expect(inspectLocalSkillTarget(source, [alias])).toMatchObject({ operationPath: alias, linkOnly: true });
+ // Ownership is established only when this group also discovers the direct entry.
+ expect(inspectLocalSkillTarget(source, [alias, source])).toMatchObject({
+ operationPath: fs.realpathSync.native(source), linkOnly: false,
+ });
+ });
+
it('detects replacement of a directory after the confirmation snapshot', () => {
const dir = directory('.claude', 'skills', 'replace');
const target = inspectLocalSkillTarget(dir, [dir])!;
diff --git a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
index 51d6bf2b48..7509c1d62d 100644
--- a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
@@ -654,6 +654,7 @@ describe('registerSkillhubIpc usage handlers', () => {
discoveredPath: alias, discoveryPaths: [alias],
...(index > 0 ? { projectRoot: projects[index - 1] } : {}),
}));
+ if (physicalProjectSkill) records[1]!.discoveryPaths.push(source);
getAllowedProjectRoots.mockResolvedValue(projects);
scanAllSkills.mockResolvedValue({ skills: records, sources: [] });
const event = { sender: { id: 71, on: vi.fn(), once: vi.fn() } };
diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.ts
index f14720b4d5..985280f876 100644
--- a/apps/desktop/src/main/skillhub/installService.ts
+++ b/apps/desktop/src/main/skillhub/installService.ts
@@ -1083,7 +1083,7 @@ async function uninstallLocked(
const cleanup: UninstallCleanup = {
skillName, resolved, operationPath: target?.operationPath ?? resolved, absolutePath,
- registryMatch, links,
+ registryMatch, links, linkOnly: target?.linkOnly ?? false,
};
const complete = await finishUninstallCleanup(cleanup, canMutate);
const cleanupToken = complete ? undefined : crypto.randomUUID();
@@ -1099,6 +1099,7 @@ interface UninstallCleanup {
skillName: string;
resolved: string;
operationPath: string;
+ linkOnly: boolean;
absolutePath: string;
registryMatch: RegistryInstallMatch | null;
links: Array<{ path: string; value: string; ino: number }>;
@@ -1145,7 +1146,9 @@ async function finishUninstallCleanup(cleanup: UninstallCleanup, canMutate: () =
}
}
}
- if (!isCindySkillEnabled(resolved)) {
+ // Unlinking an import does not remove the physical Skill or the user's shared
+ // preference. Other scopes (and later reimports) must keep that explicit state.
+ if (!cleanup.linkOnly && !isCindySkillEnabled(resolved)) {
await setCindySkillEnabled(resolved, true, canMutate).catch((err) => {
complete = false;
log.warn('[skillInstall] activation cleanup failed:', err);
diff --git a/apps/desktop/src/main/skillhub/localSkillTarget.ts b/apps/desktop/src/main/skillhub/localSkillTarget.ts
index 5a7de6b205..d6a4029f49 100644
--- a/apps/desktop/src/main/skillhub/localSkillTarget.ts
+++ b/apps/desktop/src/main/skillhub/localSkillTarget.ts
@@ -51,8 +51,10 @@ export function inspectLocalSkillTarget(source: string, discoveryPaths: readonly
});
let operationPath = sourcePath;
let linkOnly = false;
- if (!isStandaloneSkillPath(sourcePath)) {
+ const hasDirectEntry = aliases.some((value) => !fs.lstatSync(value).isSymbolicLink());
+ if (!isStandaloneSkillPath(sourcePath) || !hasDirectEntry) {
// A link into an external checkout is an import reference, not ownership of that checkout.
+ // The checkout's own directory layout does not establish local ownership.
const externalLink = aliases.find((value) => fs.lstatSync(value).isSymbolicLink());
if (!externalLink) return null;
operationPath = externalLink;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index a98e3ff35d..6591fc00bc 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -41,6 +41,8 @@
的本地 IPC 可选携带 `skillId`,Main 同时匹配路径、当前发送窗口的扫描记录和项目授权,
缺省字段保留旧调用行为,不向 device-link 新开放管理能力。启停偏好仍按物理身份共享;
物理卸载的清理快照汇总已扫描 scope 的同源发现链接,外部导入只移除所选 scope 的入口。
+ 源目录形状不能单独证明归属:同一分组必须有直接、非符号链接的发现入口,才可按独立
+ 实体卸载。外部入口移除及清理重试保留源文件和按物理身份共享的停用偏好。
- `scope=market|team` 是公开与组织目录的通用读取上下文;列表得到的 scope 必须贯穿详情、
文件、版本、扫描、下载、Learn 和批量同步。同 slug 在不同 scope 下是两条独立远端记录;
但全局 Skill 发现路径仍按 slug 只有一个安装槽,自动同步配置重复同一 slug 时由首个有效项