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-bobo655539e9a636
diff --git a/apps/desktop/src/main/skillhub/__tests__/installLock.test.ts b/apps/desktop/src/main/skillhub/__tests__/installLock.test.tsindex 4c0215aa6e..99ea116e28 100644--- a/apps/desktop/src/main/skillhub/__tests__/installLock.test.ts+++ b/apps/desktop/src/main/skillhub/__tests__/installLock.test.ts@@ -28,6 +28,24 @@ describe('installLock(final-switch 共享互斥)', () => {release!();});+ it('shares case variants across mutation owners and keeps release tokens isolated', () => {+ const first = tryAcquireSkillInstallLock('Mixed-Case', 'market-uninstall')!;+ try {+ expect(getSkillInstallLockOwner('mixed-case')).toBe('market-uninstall');+ for (const owner of ['market-install', 'learn-apply', 'local-import', 'local-rename'] as const) {+ const conflicting = tryAcquireSkillInstallLock('MIXED-CASE', owner);+ conflicting?.();+ expect(conflicting).toBeNull();+ }+ } finally { first(); }+ const second = tryAcquireSkillInstallLock('mixed-case', 'market-install')!;+ try {+ first();+ expect(getSkillInstallLockOwner('Mixed-Case')).toBe('market-install');+ } finally { second(); }+ expect(getSkillInstallLockOwner('MIXED-CASE')).toBeNull();+ });+it('不同名互不阻塞', () => {const a = tryAcquireSkillInstallLock('skill-c', 'market-install');const b = tryAcquireSkillInstallLock('skill-d', 'learn-apply');diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.tsindex 7a03a8d6ef..0e628d4a97 100644--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts@@ -2195,9 +2195,10 @@ describe('skillhub/installService', () => {expect(vi.mocked(registryService.addInstall)).not.toHaveBeenCalled();});- it.each(['install-first', 'uninstall-first'])('locks differently named import entries against install (%s)', async (order) => {- const source = path.join(TEST_ROOT, 'checkout', 'source');- const alias = path.join(TEST_ROOT, '.agents', 'skills', 'alias');+ it.each([['install-first', 'source', 'alias'], ['uninstall-first', 'source', 'alias'],+ ['install-first', 'Foo', 'foo'], ['uninstall-first', 'Foo', 'foo']])('locks import entries against install (%s, %s, %s)', async (order, sourceName, aliasName) => {+ const source = path.join(TEST_ROOT, 'checkout', sourceName);+ const alias = path.join(TEST_ROOT, '.agents', 'skills', aliasName);fs.mkdirSync(source, { recursive: true });fs.writeFileSync(path.join(source, 'SKILL.md'), 'external content');makeDirectoryLink(alias, source);@@ -2212,11 +2213,11 @@ describe('skillhub/installService', () => {vi.mocked(registryService.readManifest).mockResolvedValue(null);const target = inspectLocalSkillTarget(source, [alias])!;if (order === 'install-first') {- const releaseInstall = tryAcquireSkillInstallLock('alias', 'market-install')!;+ const releaseInstall = tryAcquireSkillInstallLock(aliasName, 'market-install')!;try {expect((await uninstall(source, target)).success).toBe(false);expect(shell.trashItem).not.toHaveBeenCalled();- expect(getSkillInstallLockOwner('source')).toBeNull();+ expect(getSkillInstallLockOwner(sourceName)).toBe(sourceName.toLowerCase() === aliasName.toLowerCase() ? 'market-install' : null);} finally { releaseInstall(); }} else {let finishTrash: (() => void) | undefined;@@ -2227,14 +2228,27 @@ describe('skillhub/installService', () => {const removing = uninstall(source, target);await vi.waitFor(() => expect(finishTrash).toBeDefined());try {- expect((await install({ name: 'alias', installPath: alias, version: '1' }, () => {})).success).toBe(false);- expect(getSkillInstallLockOwner('alias')).toBe('market-uninstall');+ expect((await install({ name: aliasName, installPath: alias, version: '1' }, () => {})).success).toBe(false);+ expect(getSkillInstallLockOwner(aliasName)).toBe('market-uninstall');} finally { finishTrash!(); }expect(await removing).toEqual({ success: true });}expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('external content');- expect(getSkillInstallLockOwner('alias')).toBeNull();- expect(getSkillInstallLockOwner('source')).toBeNull();+ expect(getSkillInstallLockOwner(aliasName)).toBeNull();+ expect(getSkillInstallLockOwner(sourceName)).toBeNull();+ });++ it('rejects physical uninstall while a differently cased market name holds the lock', async () => {+ const { source, target } = await localFixture('Foo');+ const { tryAcquireSkillInstallLock } = await import('../installLock');+ const { uninstall } = await import('../installService');+ const { shell } = await import('electron');+ const release = tryAcquireSkillInstallLock('foo', 'market-install')!;+ try {+ expect((await uninstall(source, target)).success).toBe(false);+ expect(shell.trashItem).not.toHaveBeenCalled();+ expect(fs.existsSync(source)).toBe(true);+ } finally { release(); }});it('rejects uninstall while a learn apply holds the shared lock', async () => {diff --git a/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts b/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.tsindex aa2fc16d5c..bc10679bb8 100644--- a/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts+++ b/apps/desktop/src/main/skillhub/__tests__/localSkillTarget.test.ts@@ -58,6 +58,33 @@ describe('local Skill removal targets', () => {});});+ it.each([+ ['.agents', 'skills'], ['.claude', 'skills'], ['.codex', 'skills'],+ ['.pi', 'skills'], ['.pi', 'agent', 'skills'], ['codex-home', 'skills'], ['pi-agent-home', 'skills'],+ ])('rejects symlinks in any discovery layout segment (%s)', (...segments) => {+ for (let linkedIndex = 0; linkedIndex < segments.length; linkedIndex += 1) {+ const key = `${segments.join('-')}-${linkedIndex}`;+ const source = directory(`root-checkout-${key}`, ...segments, 'source');+ const owner = path.join(root, `root-import-${key}`);+ const linkedAncestor = path.join(owner, ...segments.slice(0, linkedIndex + 1));+ const actualAncestor = path.join(root, `root-checkout-${key}`, ...segments.slice(0, linkedIndex + 1));+ fs.mkdirSync(path.dirname(linkedAncestor), { recursive: true });+ fs.symlinkSync(actualAncestor, linkedAncestor, process.platform === 'win32' ? 'junction' : 'dir');+ const entry = path.join(owner, ...segments, 'source');+ expect(fs.lstatSync(entry).isSymbolicLink()).toBe(false);+ expect(inspectLocalSkillTarget(source, [entry])).toBeNull();+ expect(fs.readFileSync(path.join(source, 'SKILL.md'), 'utf8')).toBe('test');+ }+ });++ it('allows a tracked project alias above the discovery layout', () => {+ const source = directory('direct-project', '.agents', 'skills', 'source');+ const projectAlias = path.join(root, 'project-alias');+ fs.symlinkSync(path.join(root, 'direct-project'), projectAlias, process.platform === 'win32' ? 'junction' : 'dir');+ expect(inspectLocalSkillTarget(source, [path.join(projectAlias, '.agents', 'skills', '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/installLock.ts b/apps/desktop/src/main/skillhub/installLock.tsindex be35ed5e6f..2f9fb9bb65 100644--- a/apps/desktop/src/main/skillhub/installLock.ts+++ b/apps/desktop/src/main/skillhub/installLock.ts@@ -12,8 +12,8 @@* 语义:* - try-lock(fail-fast):已被持有时再次获取直接失败,不排队 —— 与两侧既有* 语义一致(市场侧返回"正在安装中"错误,learn 侧抛 LEARN_BUSY)。- * - 键为 skillName(与 installService 原 inflight Map 的键一致):自定义- * installPath 的市场安装同样按 name 互斥,宁可保守多拦。+ * - 键为小写归一后的 skillName:自定义 installPath 同样按 name 互斥,+ * 大小写敏感卷上的不同大小写名称也保守串行,不凭 OS 猜测卷的大小写语义。* - 进程内即可:市场安装与 learn 落盘都跑在 desktop main 进程。*/@@ -33,6 +33,11 @@ interface LockHolder {const holders = new Map<string, LockHolder>();+/** Conservatively serialize case variants, including on case-insensitive Windows/macOS volumes. */+export function skillInstallLockKey(skillName: string): string {+ return skillName.toLowerCase();+}+/*** 尝试获取 skillName 的安装锁。* - 成功 → 返回幂等的 release 函数(必须在 finally 里调用);@@ -42,16 +47,17 @@ export function tryAcquireSkillInstallLock(skillName: string,owner: SkillInstallLockOwner,): (() => void) | null {- if (holders.has(skillName)) return null;+ const key = skillInstallLockKey(skillName);+ if (holders.has(key)) return null;const token = Symbol(skillName);- holders.set(skillName, { owner, token });+ holders.set(key, { owner, token });return () => {- const current = holders.get(skillName);- if (current && current.token === token) holders.delete(skillName);+ const current = holders.get(key);+ if (current && current.token === token) holders.delete(key);};}/** 当前持有者(未被持有返回 null)。 */export function getSkillInstallLockOwner(skillName: string): SkillInstallLockOwner | null {- return holders.get(skillName)?.owner ?? null;+ return holders.get(skillInstallLockKey(skillName))?.owner ?? null;}diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.tsindex 985280f876..5c94f6cc64 100644--- a/apps/desktop/src/main/skillhub/installService.ts+++ b/apps/desktop/src/main/skillhub/installService.ts@@ -40,7 +40,7 @@ import {import { registryService } from './registry';import type { StoredInstall } from './registry/types';import { computeFolderHash } from './folderHash';-import { getSkillInstallLockOwner, tryAcquireSkillInstallLock } from './installLock';+import { getSkillInstallLockOwner, skillInstallLockKey, tryAcquireSkillInstallLock } from './installLock';import {prepareSharedGlobalSkillLinks,prepareSharedProjectSkillLinks,@@ -952,7 +952,7 @@ export async function uninstall(const releaseLocks: Array<() => void> = [];// An imported discovery link can have a different name from its source. Install// replaces that entry under its discovery name, so hold both locks through trash.- for (const lockName of new Set([skillName, path.basename(target?.operationPath ?? absolutePath)])) {+ for (const lockName of new Set([skillName, path.basename(target?.operationPath ?? absolutePath)].map(skillInstallLockKey))) {const release = tryAcquireSkillInstallLock(lockName, 'market-uninstall');if (!release) {for (const unlock of releaseLocks) unlock();diff --git a/apps/desktop/src/main/skillhub/localSkillTarget.ts b/apps/desktop/src/main/skillhub/localSkillTarget.tsindex d6a4029f49..c0df2b48e7 100644--- a/apps/desktop/src/main/skillhub/localSkillTarget.ts+++ b/apps/desktop/src/main/skillhub/localSkillTarget.ts@@ -10,9 +10,24 @@ export interface LocalSkillTarget {aliases: string[];}+const standaloneSkillSuffix = /\/(?:\.(?:claude|agents|codex|pi)\/skills|\.pi\/agent\/skills|(?:codex-home|pi-agent-home)\/skills)\/[^/.][^/]*$/i;+function isStandaloneSkillPath(value: string): boolean {const normalized = path.resolve(value).replace(/\\/g, '/');- return /\/(?:\.(?:claude|agents|codex|pi)\/skills|\.pi\/agent\/skills|(?:codex-home|pi-agent-home)\/skills)\/[^/.][^/]*$/i.test(normalized);+ return standaloneSkillSuffix.test(normalized);+}++function isDirectSkillEntry(value: string): boolean {+ let current = path.resolve(value);+ const suffix = current.replace(/\\/g, '/').match(standaloneSkillSuffix)?.[0];+ if (!suffix) return false;+ // Check the entry, discovery root and engine config directories. The owner+ // prefix may itself be a tracked project alias or an OS path such as /var.+ for (const _segment of suffix.split('/').filter(Boolean)) {+ if (fs.lstatSync(current).isSymbolicLink()) return false;+ current = path.dirname(current);+ }+ return true;}function targetIdentity(operationPath: string): string {@@ -51,7 +66,7 @@ export function inspectLocalSkillTarget(source: string, discoveryPaths: readonly});let operationPath = sourcePath;let linkOnly = false;- const hasDirectEntry = aliases.some((value) => !fs.lstatSync(value).isSymbolicLink());+ const hasDirectEntry = aliases.some(isDirectSkillEntry);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.diff --git a/apps/desktop/src/main/skillhub/scanner.ts b/apps/desktop/src/main/skillhub/scanner.tsindex 96a9dd700a..44ffe2600f 100644--- a/apps/desktop/src/main/skillhub/scanner.ts+++ b/apps/desktop/src/main/skillhub/scanner.ts@@ -1,5 +1,5 @@import { isCindySkillEnabled, renameSkillWithActivation } from './activationPreferences';-import { tryAcquireSkillInstallLock } from './installLock';+import { skillInstallLockKey, tryAcquireSkillInstallLock } from './installLock';import { inspectLocalSkillTarget, isPluginManagedSkillPath } from './localSkillTarget';/*** SkillHub Scanner — 商店层 (registry / market) 视图组装。@@ -872,7 +872,7 @@ export async function renameLocalSkill(params: {}const releases: Array<() => void> = [];- for (const name of [oldName, newName]) {+ for (const name of new Set([oldName, newName].map(skillInstallLockKey))) {const release = tryAcquireSkillInstallLock(name, 'local-rename');if (!release) {releases.forEach((unlock) => unlock());diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 6591fc00bc..49f543afe3 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -42,7 +42,10 @@缺省字段保留旧调用行为,不向 device-link 新开放管理能力。启停偏好仍按物理身份共享;物理卸载的清理快照汇总已扫描 scope 的同源发现链接,外部导入只移除所选 scope 的入口。源目录形状不能单独证明归属:同一分组必须有直接、非符号链接的发现入口,才可按独立- 实体卸载。外部入口移除及清理重试保留源文件和按物理身份共享的停用偏好。+ 实体卸载;检查覆盖入口、发现根及引擎配置目录各级,拒绝其中的符号链接,保留发现+ 布局以上的已跟踪项目别名兼容。外部入口移除及清理重试保留源文件和按物理身份共享的+ 停用偏好。安装、学习、导入、重命名及卸载共用小写归一的名称锁,一次操作的多个锁名+ 按相同规则去重;大小写敏感卷上的同名大小写变体也保守互斥。- `scope=market|team` 是公开与组织目录的通用读取上下文;列表得到的 scope 必须贯穿详情、文件、版本、扫描、下载、Learn 和批量同步。同 slug 在不同 scope 下是两条独立远端记录;但全局 Skill 发现路径仍按 slug 只有一个安装槽,自动同步配置重复同一 slug 时由首个有效项