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): preserve offline uninstall intent and canonical paths

xd-bobobd5a357b4910
diff --git a/apps/desktop/help-knowledge/skills.md b/apps/desktop/help-knowledge/skills.md
index eb49b0d908..05f4d83b05 100644
--- a/apps/desktop/help-knowledge/skills.md
+++ b/apps/desktop/help-knowledge/skills.md
@@ -34,6 +34,7 @@ Skills are reusable agent capabilities you package as a folder and load into you
- The switch is local to this device and Cindy profile. It does not edit external CLI settings, sync to other devices, or override a native engine's own disabled state. Enable it again to let the engine discover it normally.
- In the skill's details, use **… → Uninstall skill**. Confirm the location and shared-file impact. Standalone skills, including locally written skills without a market installation record, move to the system trash. Recovery is through the operating system's trash.
- External source imports remove only their discovery links and keep the external source files. Package-owned or built-in skills must be removed through their owning package; their uninstall action is unavailable here. Skills provided by Cindy plugins are managed on the owning plugin's page, including when discovered through shared skill links.
+- Offline removal of an automatically synced skill is remembered on this device, including after restart or sign-in. Automatic sync skips it until you explicitly install it again.
- Uninstalling a shared copy affects external CLIs that use it. It does not unpublish a skill or delete other users' copies. If file removal fails, Cindy keeps the installation. If only metadata/link cleanup fails, the notice offers **Retry cleanup** until the current window is closed or reloaded. Retry before then; closing or reloading ends the retry receipt without restoring the removed files.
**Publishing your own skill:**
diff --git a/apps/desktop/src/main/maker-ipc/helpKnowledge.generated.ts b/apps/desktop/src/main/maker-ipc/helpKnowledge.generated.ts
index 364d8a4817..e824f848e0 100644
--- a/apps/desktop/src/main/maker-ipc/helpKnowledge.generated.ts
+++ b/apps/desktop/src/main/maker-ipc/helpKnowledge.generated.ts
@@ -144,7 +144,7 @@ export const HELP_KNOWLEDGE: HelpKnowledgeDoc[] = [
id: "skills",
title: "Skills (reusable agent capabilities)",
summary: "Browse, install, disable, uninstall, publish, and update agent skills; installed skills appear as \"/\" slash commands and are shared across Claude Code and Codex.",
- content: "Skills are reusable agent capabilities you package as a folder and load into your sessions. They're managed on the same page as Plugins — **Skills** and **Plugins** are two tabs of one management surface (the Skills tab is the in-app browser for finding, installing, publishing, and updating skills).\n\n**Skills work with both agents:**\n\n- Skills are **engine-shared** — the same installed skill is available to both Claude Code and Codex, so you install it once.\n\n**Where skills live on disk:**\n\n- Global (available to every session): the shared root `~/.agents/skills/<name>/`, which is cross-linked to `~/.claude/skills/` and `~/.codex/skills/` so every engine sees the same skills. On Windows that's under `C:\\Users\\<you>\\`.\n- Project-scoped (only inside one working directory): `<working-dir>/.agents/skills/<name>/` or `<working-dir>/.claude/skills/<name>/`.\n- Each skill is its own folder with a required `SKILL.md` at the root (the prompt / spec the agent reads). Sibling files and subfolders in that folder are also visible to the agent.\n\n**Importing a local skill:**\n\n- On the Skills page, use **Import skill** (top-right) to pick a `.zip` package or a standalone `SKILL.md` file.\n- A zip must contain a `SKILL.md` (at the package root, or inside a single top-level folder). The YAML frontmatter must include non-empty `name` and `description` fields; `name` must match `^[a-z0-9-]{1,200}$`.\n- You then choose where to install: global, a known project, or another directory. Cindy extracts metadata from the file automatically and lists the skill with that name and description.\n- Imported skills can be uninstalled from the detail page, and you can publish them to SkillHub later if you want.\n\n**Using an installed skill:**\n\n- Hover over a local skill in the `/` suggestions and choose **View skill details** in its information panel to open that exact skill. This does not insert or send the command. Pi package skills remain usable from `/`, but do not show this local detail shortcut; manage them through their package.\n\n- Type `/` in the composer to open the slash-command palette; your installed skills show up there alongside built-in and agent commands. Pick one to run it.\n\n**Disabling or uninstalling a local skill (Desktop):**\n\n- Open a skill's detail page to use the switch in the top action bar. For a market skill installed in multiple locations, select the local copy from the location dropdown beside the switch. Turning it off keeps the files and removes the skill from new-task command previews. Active tasks retain the skill preference snapshot applied when their Agent started, including their command palette. New or restarted Claude Code, Codex, and Pi agents apply that choice; an already-running agent keeps its existing context.\n- The switch is local to this device and Cindy profile. It does not edit external CLI settings, sync to other devices, or override a native engine's own disabled state. Enable it again to let the engine discover it normally.\n- In the skill's details, use **… → Uninstall skill**. Confirm the location and shared-file impact. Standalone skills, including locally written skills without a market installation record, move to the system trash. Recovery is through the operating system's trash.\n- External source imports remove only their discovery links and keep the external source files. Package-owned or built-in skills must be removed through their owning package; their uninstall action is unavailable here. Skills provided by Cindy plugins are managed on the owning plugin's page, including when discovered through shared skill links.\n- Uninstalling a shared copy affects external CLIs that use it. It does not unpublish a skill or delete other users' copies. If file removal fails, Cindy keeps the installation. If only metadata/link cleanup fails, the notice offers **Retry cleanup** until the current window is closed or reloaded. Retry before then; closing or reloading ends the retry receipt without restoring the removed files.\n\n**Publishing your own skill:**\n\n- Find the publish action on the Skills page and point it at the skill's local folder. It zips the folder and uploads it — reading your directory in place, without copying or moving anything.\n- On first publish, you set the skill's **visibility**: PUBLIC (anyone in the org) or DEPARTMENT_SCOPED (only the departments you choose).\n- The local registry records what you published, so the app knows it's \"yours\" for future updates.\n\n**Updating an already-published skill:**\n\n- On your own skill's detail page you'll see a **发布新版本** (Publish New Version) button.\n- Edit the local folder however you want and publish — the version is **auto-incremented server-side**, you don't pick a number.\n- **Old versions stay live alongside the new one.** Users who already installed an older version keep it until they choose to update.\n- The display name and description are sent on every republish, so editing those metadata fields just means doing a republish.\n\n**Managing an already-published skill:**\n\n- Change who can see or use your skill from the management menu — public, shared with selected teams / departments, or private to you.\n- **Unpublish** makes it private again and returns ownership to your personal scope; it does not remove copies other users already installed.\n- **Authorship is fixed.** Only the original author's account can publish new versions of a given skill (enforced server-side as `NOT_AUTHOR`).\n\n**Browsing and installing others' skills:**\n\n- The marketplace lets you install skills into your global skills directory. You can request a specific version on install; the local registry tracks which version you have.\n\n**Notes:**\n\n- A skill folder without a `SKILL.md` at its root won't be picked up (lowercase `skill.md` is also accepted).\n- Project-scoped skills only show up in sessions whose working directory matches — useful for skills tied to a particular repo's conventions.\n- Editing files inside an installed skill folder takes effect on the next session start; you don't need to reinstall.\n- Uninstalling only removes your local copy. For your own published skills, use unpublish or manage visibility to change market availability.",
+ content: "Skills are reusable agent capabilities you package as a folder and load into your sessions. They're managed on the same page as Plugins — **Skills** and **Plugins** are two tabs of one management surface (the Skills tab is the in-app browser for finding, installing, publishing, and updating skills).\n\n**Skills work with both agents:**\n\n- Skills are **engine-shared** — the same installed skill is available to both Claude Code and Codex, so you install it once.\n\n**Where skills live on disk:**\n\n- Global (available to every session): the shared root `~/.agents/skills/<name>/`, which is cross-linked to `~/.claude/skills/` and `~/.codex/skills/` so every engine sees the same skills. On Windows that's under `C:\\Users\\<you>\\`.\n- Project-scoped (only inside one working directory): `<working-dir>/.agents/skills/<name>/` or `<working-dir>/.claude/skills/<name>/`.\n- Each skill is its own folder with a required `SKILL.md` at the root (the prompt / spec the agent reads). Sibling files and subfolders in that folder are also visible to the agent.\n\n**Importing a local skill:**\n\n- On the Skills page, use **Import skill** (top-right) to pick a `.zip` package or a standalone `SKILL.md` file.\n- A zip must contain a `SKILL.md` (at the package root, or inside a single top-level folder). The YAML frontmatter must include non-empty `name` and `description` fields; `name` must match `^[a-z0-9-]{1,200}$`.\n- You then choose where to install: global, a known project, or another directory. Cindy extracts metadata from the file automatically and lists the skill with that name and description.\n- Imported skills can be uninstalled from the detail page, and you can publish them to SkillHub later if you want.\n\n**Using an installed skill:**\n\n- Hover over a local skill in the `/` suggestions and choose **View skill details** in its information panel to open that exact skill. This does not insert or send the command. Pi package skills remain usable from `/`, but do not show this local detail shortcut; manage them through their package.\n\n- Type `/` in the composer to open the slash-command palette; your installed skills show up there alongside built-in and agent commands. Pick one to run it.\n\n**Disabling or uninstalling a local skill (Desktop):**\n\n- Open a skill's detail page to use the switch in the top action bar. For a market skill installed in multiple locations, select the local copy from the location dropdown beside the switch. Turning it off keeps the files and removes the skill from new-task command previews. Active tasks retain the skill preference snapshot applied when their Agent started, including their command palette. New or restarted Claude Code, Codex, and Pi agents apply that choice; an already-running agent keeps its existing context.\n- The switch is local to this device and Cindy profile. It does not edit external CLI settings, sync to other devices, or override a native engine's own disabled state. Enable it again to let the engine discover it normally.\n- In the skill's details, use **… → Uninstall skill**. Confirm the location and shared-file impact. Standalone skills, including locally written skills without a market installation record, move to the system trash. Recovery is through the operating system's trash.\n- External source imports remove only their discovery links and keep the external source files. Package-owned or built-in skills must be removed through their owning package; their uninstall action is unavailable here. Skills provided by Cindy plugins are managed on the owning plugin's page, including when discovered through shared skill links.\n- Offline removal of an automatically synced skill is remembered on this device, including after restart or sign-in. Automatic sync skips it until you explicitly install it again.\n- Uninstalling a shared copy affects external CLIs that use it. It does not unpublish a skill or delete other users' copies. If file removal fails, Cindy keeps the installation. If only metadata/link cleanup fails, the notice offers **Retry cleanup** until the current window is closed or reloaded. Retry before then; closing or reloading ends the retry receipt without restoring the removed files.\n\n**Publishing your own skill:**\n\n- Find the publish action on the Skills page and point it at the skill's local folder. It zips the folder and uploads it — reading your directory in place, without copying or moving anything.\n- On first publish, you set the skill's **visibility**: PUBLIC (anyone in the org) or DEPARTMENT_SCOPED (only the departments you choose).\n- The local registry records what you published, so the app knows it's \"yours\" for future updates.\n\n**Updating an already-published skill:**\n\n- On your own skill's detail page you'll see a **发布新版本** (Publish New Version) button.\n- Edit the local folder however you want and publish — the version is **auto-incremented server-side**, you don't pick a number.\n- **Old versions stay live alongside the new one.** Users who already installed an older version keep it until they choose to update.\n- The display name and description are sent on every republish, so editing those metadata fields just means doing a republish.\n\n**Managing an already-published skill:**\n\n- Change who can see or use your skill from the management menu — public, shared with selected teams / departments, or private to you.\n- **Unpublish** makes it private again and returns ownership to your personal scope; it does not remove copies other users already installed.\n- **Authorship is fixed.** Only the original author's account can publish new versions of a given skill (enforced server-side as `NOT_AUTHOR`).\n\n**Browsing and installing others' skills:**\n\n- The marketplace lets you install skills into your global skills directory. You can request a specific version on install; the local registry tracks which version you have.\n\n**Notes:**\n\n- A skill folder without a `SKILL.md` at its root won't be picked up (lowercase `skill.md` is also accepted).\n- Project-scoped skills only show up in sessions whose working directory matches — useful for skills tied to a particular repo's conventions.\n- Editing files inside an installed skill folder takes effect on the next session start; you don't need to reinstall.\n- Uninstalling only removes your local copy. For your own published skills, use unpublish or manage visibility to change market availability.",
},
{
id: "updates-and-about",
diff --git a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
index 9c6203c966..68d22e99d3 100644
--- a/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/installService.test.ts
@@ -158,7 +158,7 @@ async function setupInstallDownload(skillName: string, zipBuf: Uint8Array) {
describe('skillhub/installService', () => {
beforeEach(async () => {
vi.resetModules();
- vi.clearAllMocks();
+ vi.resetAllMocks();
removeTestRoot();
fs.mkdirSync(TEST_ROOT, { recursive: true });
const { projectWorkingDirFromSkillPath } = await import('../../maker-host/shared-global-skills.js');
@@ -1271,6 +1271,7 @@ describe('skillhub/installService', () => {
schemaVersion: 1,
ignoredSkills: [],
autoSyncCandidates: [],
+ pendingOfflineUninstalls: [],
});
});
@@ -1436,6 +1437,44 @@ describe('skillhub/installService', () => {
);
});
+ it.each([true, undefined])('persists offline auto-sync opt-out across restart (autoSynced=%s)', async (autoSynced) => {
+ const { source, target } = await localFixture('offline-auto');
+ const { getCurrentUserId } = await import('../../authManager');
+ const { registryService } = await import('../registry');
+ const { recordAutoSyncCandidateSkills } = await import('../autoSyncPreferences');
+ await recordAutoSyncCandidateSkills('original-user', ['offline-auto']);
+ vi.mocked(getCurrentUserId).mockReturnValue(null);
+ vi.mocked(registryService.getInstall).mockResolvedValue({
+ origin: 'installed', autoSynced, version: '1', authorId: '', folderHash: 'hash', installedAt: 1, updatedAt: 1,
+ });
+ const { uninstall } = await import('../installService');
+ expect(await uninstall(source, target)).toEqual({ success: true });
+ vi.resetModules();
+ const { listIgnoredAutoSyncSkills, clearIgnoredAutoSyncSkill } = await import('../autoSyncPreferences');
+ expect(await listIgnoredAutoSyncSkills('original-user')).toContain('offline-auto');
+ expect(await listIgnoredAutoSyncSkills('another-user')).toContain('offline-auto');
+ // Manual installation is the existing explicit reset of this device-level opt-out.
+ await clearIgnoredAutoSyncSkill('offline-auto', 'original-user');
+ expect(await listIgnoredAutoSyncSkills('original-user')).not.toContain('offline-auto');
+ });
+
+ it('rolls back an offline opt-out when trash fails', async () => {
+ const { source, target } = await localFixture('offline-trash-failure');
+ const { getCurrentUserId } = await import('../../authManager');
+ const { registryService } = await import('../registry');
+ const { shell } = await import('electron');
+ vi.mocked(getCurrentUserId).mockReturnValue(null);
+ vi.mocked(registryService.getInstall).mockResolvedValue({
+ origin: 'installed', autoSynced: true, version: '1', authorId: '', folderHash: 'hash', installedAt: 1, updatedAt: 1,
+ });
+ vi.mocked(shell.trashItem).mockRejectedValueOnce(new Error('trash unavailable'));
+ const { uninstall } = await import('../installService');
+ const { listIgnoredAutoSyncSkills } = await import('../autoSyncPreferences');
+ expect((await uninstall(source, target)).success).toBe(false);
+ expect(await listIgnoredAutoSyncSkills('original-user')).not.toContain('offline-trash-failure');
+ expect(fs.existsSync(source)).toBe(true);
+ });
+
it('records an auto-sync ignore marker when uninstalling an auto-synced skill', async () => {
const finalDir = path.join(TEST_ROOT, '.agents', 'skills', 'auto-skill');
fs.mkdirSync(finalDir, { recursive: true });
@@ -1551,6 +1590,7 @@ describe('skillhub/installService', () => {
schemaVersion: 1,
ignoredSkills: [],
autoSyncCandidates: [],
+ pendingOfflineUninstalls: [],
});
});
diff --git a/apps/desktop/src/main/skillhub/autoSyncPreferences.ts b/apps/desktop/src/main/skillhub/autoSyncPreferences.ts
index 0f281e88e9..1ff8097331 100644
--- a/apps/desktop/src/main/skillhub/autoSyncPreferences.ts
+++ b/apps/desktop/src/main/skillhub/autoSyncPreferences.ts
@@ -31,6 +31,8 @@ interface PreferenceStore {
schemaVersion: 1;
ignoredSkills: IgnoredSkill[];
autoSyncCandidates: AutoSyncCandidateSkill[];
+ /** Offline removals affect shared device files until an explicit manual install. */
+ pendingOfflineUninstalls: string[];
}
interface ReadStoreResult {
@@ -47,7 +49,7 @@ function normalizeSkillName(name: string): string {
}
function emptyStore(): PreferenceStore {
- return { schemaVersion: STORE_VERSION, ignoredSkills: [], autoSyncCandidates: [] };
+ return { schemaVersion: STORE_VERSION, ignoredSkills: [], autoSyncCandidates: [], pendingOfflineUninstalls: [] };
}
function parseStore(value: unknown): PreferenceStore {
@@ -95,7 +97,11 @@ function parseStore(value: unknown): PreferenceStore {
});
}
}
+ const pending = (value as { pendingOfflineUninstalls?: unknown }).pendingOfflineUninstalls;
return {
+ pendingOfflineUninstalls: Array.isArray(pending)
+ ? [...new Set(pending.filter((name): name is string => typeof name === 'string').map(normalizeSkillName).filter(Boolean))]
+ : [],
schemaVersion: STORE_VERSION,
ignoredSkills: Array.from(byName.values()),
autoSyncCandidates: Array.from(byCandidate.values()),
@@ -145,21 +151,25 @@ function enqueueMutation(task: () => Promise<void>): Promise<void> {
return next;
}
-export async function listIgnoredAutoSyncSkills(userId: string): Promise<Set<string>> {
+export async function listIgnoredAutoSyncSkills(userId?: string): Promise<Set<string>> {
const { store, resetFromError } = await readStoreResult({ resetOnError: true });
if (resetFromError) {
await writeStore(store);
}
- return new Set(store.ignoredSkills
+ return new Set([...store.pendingOfflineUninstalls, ...store.ignoredSkills
.filter((skill) => skill.userId === userId)
- .map((skill) => skill.name));
+ .map((skill) => skill.name)]);
}
-export async function ignoreAutoSyncSkill(name: string, userId: string): Promise<void> {
+export async function ignoreAutoSyncSkill(name: string, userId?: string): Promise<void> {
const normalized = normalizeSkillName(name);
- if (!normalized || !userId) return;
+ if (!normalized) return;
await enqueueMutation(async () => {
const { store } = await readStoreResult({ resetOnError: true });
+ if (!userId) {
+ await writeStore({ ...store, pendingOfflineUninstalls: [...new Set([...store.pendingOfflineUninstalls, normalized])] });
+ return;
+ }
const ignoredAt = Math.floor(Date.now() / 1000);
const next = store.ignoredSkills.filter((skill) => !(skill.name === normalized && skill.userId === userId));
next.push({ name: normalized, userId, ignoredAt });
@@ -167,14 +177,15 @@ export async function ignoreAutoSyncSkill(name: string, userId: string): Promise
});
}
-export async function clearIgnoredAutoSyncSkill(name: string, userId: string): Promise<void> {
+export async function clearIgnoredAutoSyncSkill(name: string, userId?: string): Promise<void> {
const normalized = normalizeSkillName(name);
- if (!normalized || !userId) return;
+ if (!normalized) return;
await enqueueMutation(async () => {
const { store, resetFromError } = await readStoreResult({ resetOnError: true });
const next = store.ignoredSkills.filter((skill) => !(skill.name === normalized && skill.userId === userId));
- if (!resetFromError && next.length === store.ignoredSkills.length) return;
- await writeStore({ ...store, schemaVersion: STORE_VERSION, ignoredSkills: next });
+ const pending = store.pendingOfflineUninstalls.filter((name) => name !== normalized);
+ if (!resetFromError && next.length === store.ignoredSkills.length && pending.length === store.pendingOfflineUninstalls.length) return;
+ await writeStore({ ...store, schemaVersion: STORE_VERSION, ignoredSkills: next, pendingOfflineUninstalls: pending });
});
}
@@ -202,9 +213,9 @@ export async function recordAutoSyncCandidateSkills(
});
}
-export async function isKnownAutoSyncCandidateSkill(name: string, userId: string): Promise<boolean> {
+export async function isKnownAutoSyncCandidateSkill(name: string, userId?: string): Promise<boolean> {
const normalized = normalizeSkillName(name);
- if (!normalized || !userId) return false;
+ if (!normalized) return false;
const store = await readStore();
- return store.autoSyncCandidates.some((skill) => skill.userId === userId && skill.name === normalized);
+ return store.autoSyncCandidates.some((skill) => (!userId || skill.userId === userId) && skill.name === normalized);
}
diff --git a/apps/desktop/src/main/skillhub/installService.ts b/apps/desktop/src/main/skillhub/installService.ts
index eb87345271..a1d0c858ed 100644
--- a/apps/desktop/src/main/skillhub/installService.ts
+++ b/apps/desktop/src/main/skillhub/installService.ts
@@ -935,7 +935,8 @@ export async function uninstall(
// 防御:resolve 后验证路径是精确的 skill 根目录(只允许一层 slug,防 traversal)
let resolved: string;
try {
- resolved = fs.realpathSync(absolutePath);
+ // Match the scan snapshot's native canonical path, including Windows 8.3 aliases.
+ resolved = fs.realpathSync.native(absolutePath);
} catch {
resolved = path.resolve(absolutePath);
}
@@ -1044,11 +1045,11 @@ async function uninstallLocked(
const registryEntry = registryMatch?.entry;
if (!canMutate()) return { success: false, errorCode: 'CANCELLED', message: 'Skill mutation context changed' };
- const recordIgnore = !!(cloudUserId && registryEntry && await shouldRecordAutoSyncIgnore(skillName, registryEntry, cloudUserId));
- const wasIgnored = recordIgnore && (await listIgnoredAutoSyncSkills(cloudUserId!)).has(skillName);
+ const recordIgnore = !!(registryEntry && await shouldRecordAutoSyncIgnore(skillName, registryEntry, cloudUserId ?? undefined));
+ const wasIgnored = recordIgnore && (await listIgnoredAutoSyncSkills(cloudUserId ?? undefined)).has(skillName);
// Persist the user's opt-out before touching files, so auto-sync cannot recreate the Skill.
if (recordIgnore && !wasIgnored) {
- try { await ignoreAutoSyncSkill(skillName, cloudUserId!); }
+ try { await ignoreAutoSyncSkill(skillName, cloudUserId ?? undefined); }
catch { return { success: false, errorCode: 'WRITE_FAILED', message: 'Could not save uninstall preference' }; }
}
const candidates = [...new Set([
@@ -1070,7 +1071,7 @@ async function uninstallLocked(
if (exists) await shell.trashItem(target?.operationPath ?? resolved);
} catch (err) {
if (recordIgnore && !wasIgnored) {
- await clearIgnoredAutoSyncSkill(skillName, cloudUserId!).catch((error) => log.warn('[skillInstall] restore auto-sync preference failed:', error));
+ await clearIgnoredAutoSyncSkill(skillName, cloudUserId ?? undefined).catch((error) => log.warn('[skillInstall] restore auto-sync preference failed:', error));
}
return { success: false, errorCode: 'WRITE_FAILED', message: err instanceof Error ? err.message : String(err) };
}
@@ -1158,7 +1159,7 @@ export async function retryUninstallCleanup(token: string, canMutate: () => bool
} finally { release(); }
}
-async function shouldRecordAutoSyncIgnore(skillName: string, registryEntry: StoredInstall, userId: string): Promise<boolean> {
+async function shouldRecordAutoSyncIgnore(skillName: string, registryEntry: StoredInstall, userId?: string): Promise<boolean> {
if (registryEntry.autoSynced === true) return true;
if (registryEntry.origin !== 'installed' || registryEntry.autoSynced !== undefined) return false;
// 兼容 auto-sync 首版:当时 registry 没有 autoSynced 字段,候选集合来自最近一次 auto-sync 配置。