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-bobobbde6366cbc3
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index 0e628d4a97..c1e00bb671 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -74,6 +74,7 @@ vi.mock('../registry', () => ({
addInstall: vi.fn(),
getInstall: vi.fn(),
readManifest: vi.fn(),
+ listAllInstalls: vi.fn(),
removeInstall: vi.fn(),
},
}));
@@ -182,6 +183,7 @@ describe('skillhub/installService', () => {
const { registryService } = await import('../registry');
vi.mocked(registryService.getInstall).mockResolvedValue(null);
vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([]);
return { source, target: inspectLocalSkillTarget(source, [source])! };
}
@@ -220,6 +222,7 @@ describe('skillhub/installService', () => {
const { registryService } = await import('../registry');
vi.mocked(registryService.getInstall).mockResolvedValue(null);
vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([]);
const { uninstall } = await import('../installService');
const { shell } = await import('electron');
const target = inspectLocalSkillTarget(source, [alias])!;
@@ -242,6 +245,7 @@ describe('skillhub/installService', () => {
const { registryService } = await import('../registry');
vi.mocked(registryService.getInstall).mockResolvedValue(null);
vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([]);
const { setCindySkillEnabled, isCindySkillEnabled } = await import('../activationPreferences');
await setCindySkillEnabled(source, false);
const { shell } = await import('electron');
@@ -1166,6 +1170,7 @@ describe('skillhub/installService', () => {
const { registryService } = await import('../registry');
vi.mocked(registryService.getInstall).mockResolvedValue(null);
vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([]);
vi.mocked(sharedSkills.projectWorkingDirFromSkillPath).mockImplementation((entry) => entry === alias ? projectRoot : null);
const { uninstall } = await import('../installService');
const result = await uninstall(target.sourcePath, target);
@@ -1241,6 +1246,31 @@ describe('skillhub/installService', () => {
vi.mocked(getCurrentDataOwnerId).mockReturnValue('user-1');
});
+ it('uses the original registry name after a case-only source directory rename', async () => {
+ const physicalDir = path.join(TEST_ROOT, 'case-registry', '.agents', 'skills', 'Foo');
+ const logicalDir = path.join(TEST_ROOT, 'case-registry-alias', '.agents', 'skills', 'foo');
+ fs.mkdirSync(physicalDir, { recursive: true });
+ fs.writeFileSync(path.join(physicalDir, 'SKILL.md'), 'fixture');
+ makeDirectoryLink(logicalDir, physicalDir);
+ const entry = { version: '1.0.0', authorId: 'owner', folderHash: 'hash',
+ installedAt: 1, updatedAt: 1, origin: 'installed' as const };
+ const { registryService } = await import('../registry');
+ const { uninstall } = await import('../installService');
+ vi.mocked(registryService.getInstall).mockImplementation(async (name) => {
+ if (name === 'Foo') throw new Error('REGISTRY_CORRUPTED');
+ return name === 'foo' ? entry : null;
+ });
+ vi.mocked(registryService.readManifest).mockRejectedValue(new Error('REGISTRY_CORRUPTED'));
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([
+ { skillName: 'foo', installPath: path.join(TEST_ROOT, 'unrelated'), entry },
+ { skillName: 'foo', installPath: logicalDir, entry },
+ ]);
+ const result = await uninstall(physicalDir);
+ expect(result).toEqual({ success: true });
+ expect(fs.existsSync(physicalDir)).toBe(false);
+ expect(registryService.removeInstall).toHaveBeenCalledWith('foo', logicalDir);
+ });
+
it('uninstalls a linked install when the scanner passes its physical path', async () => {
const skillName = 'linked-uninstall-skill';
const projectRoot = path.join(TEST_ROOT, 'linked-uninstall-project');
@@ -2211,6 +2241,7 @@ describe('skillhub/installService', () => {
const { registryService } = await import('../registry');
vi.mocked(registryService.getInstall).mockResolvedValue(null);
vi.mocked(registryService.readManifest).mockResolvedValue(null);
+ vi.mocked(registryService.listAllInstalls).mockResolvedValue([]);
const target = inspectLocalSkillTarget(source, [alias])!;
if (order === 'install-first') {
const releaseInstall = tryAcquireSkillInstallLock(aliasName, 'market-install')!;
diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.ts
index 5c94f6cc64..bddee06471 100644
--- a/apps/desktop/src/main/skillhub/installService.ts
+++ b/apps/desktop/src/main/skillhub/installService.ts
@@ -974,7 +974,7 @@ export async function uninstall(
return await uninstallLocked(
absolutePath,
resolved,
- skillName,
+ registryMatch?.skillName ?? skillName,
cloudUserId,
registryMatch,
target,
@@ -987,6 +987,7 @@ export async function uninstall(
/** Registry entry plus the exact key that must be removed after uninstall. */
interface RegistryInstallMatch {
+ skillName: string;
installPath: string;
entry: StoredInstall;
}
@@ -1014,26 +1015,34 @@ async function findRegistryInstallForPath(
]);
for (const installPath of candidatePaths) {
const entry = await registryService.getInstall(skillName, installPath).catch(() => null);
- if (entry) return { installPath, entry };
+ if (entry) return { skillName, installPath, entry };
}
const manifest = await registryService.readManifest(skillName).catch(() => null);
- if (!manifest) return null;
- for (const [installPath, entry] of Object.entries(manifest.installs)) {
+ for (const [installPath, entry] of Object.entries(manifest?.installs ?? {})) {
let realInstallPath: string;
try {
realInstallPath = fs.realpathSync(installPath);
} catch {
// 目录已删时仍允许用规范化路径与候选路径直接比对
if (candidatePaths.some((candidate) => pathTextEquals(path.normalize(installPath), candidate))) {
- return { installPath, entry };
+ return { skillName, installPath, entry };
}
continue;
}
if (candidatePaths.some((candidate) => resolvedPathEquals(realInstallPath, candidate))) {
- return { installPath, entry };
+ return { skillName, installPath, entry };
}
}
+ // A case-only directory rename does not rename the registry manifest. Resolve
+ // its original key by physical identity; do not loosen manifest self-validation.
+ const installs = await registryService.listAllInstalls();
+ for (const record of installs) {
+ if (skillInstallLockKey(record.skillName) !== skillInstallLockKey(skillName)) continue;
+ try {
+ if (fs.realpathSync.native(record.installPath) === resolved) return record;
+ } catch { /* Missing records do not prove ownership of a live source. */ }
+ }
return null;
}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 0ec020fec6..2dbe242cb4 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -48,7 +48,8 @@
实体卸载;检查覆盖入口、发现根及引擎配置目录各级,拒绝其中的符号链接,保留发现
布局以上的已跟踪项目别名兼容。外部入口移除及清理重试保留源文件和按物理身份共享的
停用偏好。安装、学习、导入、重命名及卸载共用小写归一的名称锁,一次操作的多个锁名
- 按相同规则去重;大小写敏感卷上的同名大小写变体也保守互斥。
+ 按相同规则去重;大小写敏感卷上的同名大小写变体也保守互斥。卸载遇到目录大小写
+ 变体时按实际文件身份匹配清单,并使用清单原始名称清理记录及自动同步偏好。
- `scope=market|team` 是公开与组织目录的通用读取上下文;列表得到的 scope 必须贯穿详情、
文件、版本、扫描、下载、Learn 和批量同步。同 slug 在不同 scope 下是两条独立远端记录;
但全局 Skill 发现路径仍按 slug 只有一个安装槽,自动同步配置重复同一 slug 时由首个有效项