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(desktop): 跨 Agent 全局 Skill 拉入默认关闭,需显式 opt-in (#3031)

Battleplus8b5f49192909
diff --git a/apps/desktop/src/main/__tests__/sharedGlobalSkills.test.ts b/apps/desktop/src/main/__tests__/sharedGlobalSkills.test.ts
index 2638dc5bb5..e3309266fd 100644
--- a/apps/desktop/src/main/__tests__/sharedGlobalSkills.test.ts
+++ b/apps/desktop/src/main/__tests__/sharedGlobalSkills.test.ts
@@ -44,13 +44,47 @@ afterEach(async () => {
});
describe('prepareSharedGlobalSkillLinks', () => {
+ it('does not pull other-agent skills into the shared index by default (opt-in gate, #2930)', async () => {
+ const root = await makeTmpDir();
+ const homeDir = path.join(root, 'home');
+ const paths = sharedGlobalSkillsPaths(homeDir);
+ await writeSkill(paths.claudeSkillsDir, 'claude-only');
+
+ const result = await prepareSharedGlobalSkillLinks({ homeDir });
+
+ expect(result.changed).toBe(false);
+ expect(result.actions).toEqual([]);
+ expect(result.warnings).toEqual([
+ 'cross-agent global skill sync is disabled; set crossAgentSyncEnabled to opt in',
+ ]);
+ // 未 opt-in 时,不把 Claude 的用户技能拉进 ~/.agents/skills。
+ await expect(fs.lstat(path.join(paths.sharedSkillsDir, 'claude-only'))).rejects.toMatchObject({
+ code: 'ENOENT',
+ });
+ });
+
+ it('still projects the shared index into Claude when sync is disabled (Ghost projection)', async () => {
+ const root = await makeTmpDir();
+ const homeDir = path.join(root, 'home');
+ const paths = sharedGlobalSkillsPaths(homeDir);
+ const sharedSkill = await writeSkill(paths.sharedSkillsDir, 'ghost-managed');
+
+ const result = await prepareSharedGlobalSkillLinks({ homeDir });
+
+ expect(result.changed).toBe(true);
+ // ~/.agents → ~/.claude 的 Cindy 自有索引投影仍保留(Ghost skill 依赖它)。
+ expect(await sameRealPath(path.join(paths.claudeSkillsDir, 'ghost-managed'), sharedSkill)).toBe(true);
+ // 纯 Ghost 对账不应打扰(无其它 Agent 用户技能可同步时,不提示)。
+ expect(result.warnings).toEqual([]);
+ });
+
it('links existing Claude skills into the shared skills root for Codex visibility', async () => {
const root = await makeTmpDir();
const homeDir = path.join(root, 'home');
const paths = sharedGlobalSkillsPaths(homeDir);
const claudeSkill = await writeSkill(paths.claudeSkillsDir, 'claude-only');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.changed).toBe(true);
expect(result.warnings).toEqual([]);
@@ -74,6 +108,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
await expect(
prepareSharedGlobalSkillLinks({
homeDir,
+ isCrossAgentSyncEnabled: () => true,
assertOwnerStable: () => {
if (!ownerStable) throw new Error('owner changed');
},
@@ -98,7 +133,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
const paths = sharedGlobalSkillsPaths(homeDir);
const sharedSkill = await writeSkill(paths.sharedSkillsDir, 'shared-only');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.changed).toBe(true);
expect(result.warnings).toEqual([]);
@@ -111,8 +146,8 @@ describe('prepareSharedGlobalSkillLinks', () => {
const paths = sharedGlobalSkillsPaths(homeDir);
const codexSkill = await writeSkill(paths.codexSkillsDir, 'codex-only');
- await prepareSharedGlobalSkillLinks({ homeDir });
- const secondResult = await prepareSharedGlobalSkillLinks({ homeDir });
+ await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
+ const secondResult = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(secondResult.changed).toBe(false);
expect(secondResult.warnings).toEqual([]);
@@ -136,6 +171,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
await expect(
prepareSharedGlobalSkillLinks({
homeDir,
+ isCrossAgentSyncEnabled: () => true,
assertOwnerStable: () => {
if (!ownerStable) throw new Error('owner changed');
},
@@ -161,7 +197,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
const sharedSkill = await writeSkill(paths.sharedSkillsDir, 'duplicate');
const codexSkill = await writeSkill(paths.codexSkillsDir, 'duplicate');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.warnings.some((warning) => warning.includes('duplicate'))).toBe(true);
expect(await sameRealPath(path.join(paths.sharedSkillsDir, 'duplicate'), sharedSkill)).toBe(true);
@@ -178,7 +214,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
await fs.mkdir(paths.sharedSkillsDir, { recursive: true });
await fs.symlink(externalSkill, sharedLink, process.platform === 'win32' ? 'junction' : 'dir');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.warnings.some((warning) => warning.includes('user-link'))).toBe(true);
expect(await sameRealPath(sharedLink, externalSkill)).toBe(true);
@@ -191,12 +227,12 @@ describe('prepareSharedGlobalSkillLinks', () => {
const paths = sharedGlobalSkillsPaths(homeDir);
const codexSkill = await writeSkill(paths.codexSkillsDir, 'removed-codex-skill');
- await prepareSharedGlobalSkillLinks({ homeDir });
+ await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(await sameRealPath(path.join(paths.sharedSkillsDir, 'removed-codex-skill'), codexSkill)).toBe(true);
expect(await sameRealPath(path.join(paths.claudeSkillsDir, 'removed-codex-skill'), codexSkill)).toBe(true);
await fs.rm(codexSkill, { recursive: true, force: true });
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.changed).toBe(true);
await expect(fs.lstat(path.join(paths.sharedSkillsDir, 'removed-codex-skill'))).rejects.toMatchObject({
@@ -216,8 +252,8 @@ describe('prepareSharedGlobalSkillLinks', () => {
await fs.mkdir(paths.codexSkillsDir, { recursive: true });
await fs.symlink(sharedSkill, codexLink, process.platform === 'win32' ? 'junction' : 'dir');
- await prepareSharedGlobalSkillLinks({ homeDir });
- const secondResult = await prepareSharedGlobalSkillLinks({ homeDir });
+ await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
+ const secondResult = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(secondResult.changed).toBe(false);
expect(secondResult.warnings).toEqual([]);
@@ -232,7 +268,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
const sharedSkill = await writeSkill(paths.sharedSkillsDir, 'duplicate');
const claudeSkill = await writeSkill(paths.claudeSkillsDir, 'duplicate');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.warnings.some((warning) => warning.includes('duplicate'))).toBe(true);
expect(await sameRealPath(path.join(paths.sharedSkillsDir, 'duplicate'), sharedSkill)).toBe(true);
@@ -250,7 +286,7 @@ describe('prepareSharedGlobalSkillLinks', () => {
await fs.mkdir(paths.claudeSkillsDir, { recursive: true });
await fs.symlink(externalSkill, claudeLink, process.platform === 'win32' ? 'junction' : 'dir');
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.warnings.some((warning) => warning.includes('user-link'))).toBe(true);
expect(await sameRealPath(claudeLink, externalSkill)).toBe(true);
@@ -263,11 +299,11 @@ describe('prepareSharedGlobalSkillLinks', () => {
const paths = sharedGlobalSkillsPaths(homeDir);
const claudeSkill = await writeSkill(paths.claudeSkillsDir, 'removed-later');
- await prepareSharedGlobalSkillLinks({ homeDir });
+ await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(await sameRealPath(path.join(paths.sharedSkillsDir, 'removed-later'), claudeSkill)).toBe(true);
await fs.rm(claudeSkill, { recursive: true, force: true });
- const result = await prepareSharedGlobalSkillLinks({ homeDir });
+ const result = await prepareSharedGlobalSkillLinks({ homeDir, isCrossAgentSyncEnabled: () => true });
expect(result.changed).toBe(true);
await expect(fs.lstat(path.join(paths.sharedSkillsDir, 'removed-later'))).rejects.toMatchObject({
diff --git a/apps/desktop/src/main/maker-host/shared-global-skills-settings.ts b/apps/desktop/src/main/maker-host/shared-global-skills-settings.ts
new file mode 100644
index 0000000000..d5771a4cfe
--- /dev/null
+++ b/apps/desktop/src/main/maker-host/shared-global-skills-settings.ts
@@ -0,0 +1,63 @@
+/**
+ * shared-global-skills-settings —— 全局 Skill 跨 Agent 链接的显式 opt-in。
+ *
+ * File: <userData>/shared-global-skills-settings.json
+ * { "crossAgentSyncEnabled": true }
+ *
+ * Default off(#2930):默认不跨 Agent 修改任何全局 Skill 根,共享必须由用户显式
+ * opt-in。文件只存被改过的字段,未改过的字段随未来默认值变化流动。
+ */
+
+import { app } from 'electron';
+import path from 'node:path';
+
+import { desktopMakerLogger } from './logger-adapter.js';
+import {
+ createOverrideSettingsFile,
+ type OverrideSettingsState,
+} from './override-settings-file.js';
+
+const log = desktopMakerLogger.child('shared-global-skills-settings');
+
+export interface SharedGlobalSkillsSettings {
+ crossAgentSyncEnabled: boolean;
+}
+
+const DEFAULTS: SharedGlobalSkillsSettings = {
+ crossAgentSyncEnabled: false,
+};
+
+function settingsFilePath(): string {
+ return path.join(app.getPath('userData'), 'shared-global-skills-settings.json');
+}
+
+function normalize(raw: unknown): SharedGlobalSkillsSettings {
+ if (!raw || typeof raw !== 'object') return { ...DEFAULTS };
+ const r = raw as Record<string, unknown>;
+ return {
+ crossAgentSyncEnabled:
+ typeof r.crossAgentSyncEnabled === 'boolean'
+ ? r.crossAgentSyncEnabled
+ : DEFAULTS.crossAgentSyncEnabled,
+ };
+}
+
+const store = createOverrideSettingsFile<SharedGlobalSkillsSettings>({
+ filePath: settingsFilePath,
+ defaults: DEFAULTS,
+ normalize,
+ log,
+ label: 'shared global skills',
+});
+
+export function readSharedGlobalSkillsSettings(): SharedGlobalSkillsSettings {
+ // 隐藏配置约定:直接改文件也是正式 opt-in 入口,读取前按 mtime 失效缓存,
+ // 否则运行期间写入 crossAgentSyncEnabled 仍会读到旧值直到重启(review P2)。
+ store.invalidateIfChanged();
+ return store.read();
+}
+
+export function readSharedGlobalSkillsSettingsState(): OverrideSettingsState<SharedGlobalSkillsSettings> {
+ store.invalidateIfChanged();
+ return store.readState();
+}
diff --git a/apps/desktop/src/main/maker-host/shared-global-skills.ts b/apps/desktop/src/main/maker-host/shared-global-skills.ts
index 7ee061da1f..aa028420fb 100644
--- a/apps/desktop/src/main/maker-host/shared-global-skills.ts
+++ b/apps/desktop/src/main/maker-host/shared-global-skills.ts
@@ -36,6 +36,11 @@ interface PrepareOptions {
homeDir?: string;
/** Optional owner-bound caller guard for Ghost-managed fanout. */
assertOwnerStable?: () => void;
+ /**
+ * 跨 Agent 链接的显式 opt-in 判定(#2930)。缺省时读
+ * shared-global-skills-settings(默认关);注入用于单测确定性控制。
+ */
+ isCrossAgentSyncEnabled?: () => boolean;
}
export interface SharedProjectSkillLinksResult {
@@ -336,6 +341,15 @@ export async function prepareSharedGlobalSkillLinks(
): Promise<SharedGlobalSkillLinksResult> {
opts.assertOwnerStable?.();
const paths = sharedGlobalSkillsPaths(opts.homeDir);
+ // #2930:跨 Agent 的「拉入」默认关闭,必须显式 opt-in(Claude→shared、
+ // Codex→Claude、Codex→shared)。Cindy 自有索引向 Claude 的投影(shared→Claude)
+ // 保留,避免破坏 Ghost skill 的 .claude 兼容链接(职责分界见 skillSlot.ts)。
+ const crossAgentSyncEnabled = opts.isCrossAgentSyncEnabled
+ ? opts.isCrossAgentSyncEnabled()
+ : // 延迟 import:本模块是纯 Node(无 electron 静态依赖),settings store 引
+ // electron 的 app.getPath,静态引入会拖坏单测环境。
+ (await import('./shared-global-skills-settings.js'))
+ .readSharedGlobalSkillsSettings().crossAgentSyncEnabled;
opts.assertOwnerStable?.();
await fsp.mkdir(paths.sharedSkillsDir, { recursive: true });
opts.assertOwnerStable?.();
@@ -369,17 +383,46 @@ export async function prepareSharedGlobalSkillLinks(
opts.assertOwnerStable,
)) || changed;
- const initialClaudeEntries = (await listSkillEntries('claude', paths.claudeSkillsDir))
+ // 其它 Agent 根里、且不是「指向受管根」投影的用户技能,才是跨 Agent 拉入的对象。
+ const claudeEntries = (await listSkillEntries('claude', paths.claudeSkillsDir))
.filter((entry) => !(entry.isSymlink && pointsInto(entry, [sharedRootCompare, codexRootCompare])));
- const claudeToShared = await linkEntriesIntoRoot(
- initialClaudeEntries,
- paths.sharedSkillsDir,
- false,
- opts.assertOwnerStable,
- );
- actions.push(...claudeToShared.actions);
- warnings.push(...claudeToShared.warnings);
- changed = changed || claudeToShared.changed;
+ const codexEntries = (await listSkillEntries('codex', paths.codexSkillsDir))
+ .filter((entry) => !(entry.isSymlink && pointsInto(entry, [sharedRootCompare, claudeRootCompare])));
+
+ if (crossAgentSyncEnabled) {
+ const claudeToShared = await linkEntriesIntoRoot(
+ claudeEntries,
+ paths.sharedSkillsDir,
+ false,
+ opts.assertOwnerStable,
+ );
+ actions.push(...claudeToShared.actions);
+ warnings.push(...claudeToShared.warnings);
+ changed = changed || claudeToShared.changed;
+
+ const codexToClaude = await linkEntriesIntoRoot(
+ codexEntries,
+ paths.claudeSkillsDir,
+ false,
+ opts.assertOwnerStable,
+ );
+ actions.push(...codexToClaude.actions);
+ warnings.push(...codexToClaude.warnings);
+ changed = changed || codexToClaude.changed;
+
+ const codexToShared = await linkEntriesIntoRoot(
+ codexEntries,
+ paths.sharedSkillsDir,
+ false,
+ opts.assertOwnerStable,
+ );
+ actions.push(...codexToShared.actions);
+ warnings.push(...codexToShared.warnings);
+ changed = changed || codexToShared.changed;
+ } else if (claudeEntries.length > 0 || codexEntries.length > 0) {
+ // 未 opt-in 且存在可同步的用户技能时才提示;纯 Ghost 对账不打扰。
+ warnings.push('cross-agent global skill sync is disabled; set crossAgentSyncEnabled to opt in');
+ }
const sharedEntries = await listSkillEntries('shared', paths.sharedSkillsDir);
const sharedToClaude = await linkEntriesIntoRoot(
@@ -392,28 +435,6 @@ export async function prepareSharedGlobalSkillLinks(
warnings.push(...sharedToClaude.warnings);
changed = changed || sharedToClaude.changed;
- const codexEntries = (await listSkillEntries('codex', paths.codexSkillsDir))
- .filter((entry) => !(entry.isSymlink && pointsInto(entry, [sharedRootCompare, claudeRootCompare])));
- const codexToClaude = await linkEntriesIntoRoot(
- codexEntries,
- paths.claudeSkillsDir,
- false,
- opts.assertOwnerStable,
- );
- actions.push(...codexToClaude.actions);
- warnings.push(...codexToClaude.warnings);
- changed = changed || codexToClaude.changed;
-
- const codexToShared = await linkEntriesIntoRoot(
- codexEntries,
- paths.sharedSkillsDir,
- false,
- opts.assertOwnerStable,
- );
- actions.push(...codexToShared.actions);
- warnings.push(...codexToShared.warnings);
- changed = changed || codexToShared.changed;
-
opts.assertOwnerStable?.();
return {
...paths,