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): bind built-in skills to stable grants

xd-bobofecee6b6e7b2
diff --git a/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts b/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
index e240783ae4..f3e57137ad 100644
--- a/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
+++ b/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
@@ -234,6 +234,7 @@ describe('passive shared-userData instance auth isolation', () => {
expect(bootstrapSource).toContain(
'await desktopClaudeAuthAdapter.ensureSharedGlobalSkills();',
);
+ expect(bootstrapSource).not.toContain('prepareBuiltInSkills({');
expect(bootstrapSource).not.toContain('await prepareSharedGlobalSkillLinks();');
expect(bootstrapSource).not.toContain('refreshBuiltInSharedSkillLinks');
@@ -242,6 +243,7 @@ describe('passive shared-userData instance auth isolation', () => {
const body = authAdapterSource.slice(start, end);
const ownerBoundary = body.indexOf('withSharedGlobalSkillProjectionMutation(ownerId');
expect(ownerBoundary).toBeGreaterThan(-1);
+ expect(body.indexOf('prepareBuiltInSkills({')).toBeGreaterThan(ownerBoundary);
expect(body.indexOf('refreshBuiltInSharedSkillLinks({')).toBeGreaterThan(ownerBoundary);
expect(body.indexOf('prepareSharedGlobalSkillLinks({')).toBeGreaterThan(ownerBoundary);
expect(body.indexOf('refreshBuiltInClaudeSkillLinks({')).toBeGreaterThan(ownerBoundary);
diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.ts
index 95e9a87e12..817588e936 100644
--- a/apps/desktop/src/main/bootstrap-electron.ts
+++ b/apps/desktop/src/main/bootstrap-electron.ts
@@ -579,8 +579,6 @@ import { skillhubAutoSyncService } from './skillhub/autoSyncService';
import { rehydrateCloseSuppression } from './maker-host/rehydrateCloseSuppression.js';
import {
builtInSkillDescriptors,
- prepareBuiltInSkills,
- resolveBundledSystemSkillsRoot,
} from './maker-host/built-in-skills.js';
import { isCindyLearnSkillEnabled } from './skillhub/activationPreferences';
// Maker Core 一阶段重构(新链路)—— 静态 import 避免 dynamic import 触发 vite chunking
@@ -8585,23 +8583,10 @@ app.on('ready', async () => {
await ensureMainAppPresence('app-ready');
- // Cindy-owned Skills are packaged as immutable resources and copied into a
- // stable profile-independent path. Home-level projections happen only through
- // ensureSharedGlobalSkills(), whose stable-owner boundary rejects passive instances;
- // they never replace a same-name user Skill.
+ // Cindy-owned Skill activation and all home-level projections happen through
+ // one stable-owner boundary. Passive shared-userData instances may consume the
+ // active bundle but cannot switch it or its projections.
try {
- const prepared = await prepareBuiltInSkills({
- bundledRoot: resolveBundledSystemSkillsRoot({
- isPackaged: app.isPackaged,
- appPath: app.getAppPath(),
- resourcesPath: process.resourcesPath,
- }),
- userDataDir: app.getPath('userData'),
- appDataDir: app.getPath('appData'),
- });
- for (const warning of prepared.warnings) {
- createLogger('built-in-skills').warn('built-in Skill preparation warning', { warning });
- }
await desktopClaudeAuthAdapter.ensureSharedGlobalSkills();
} catch (error) {
// A broken optional Skill must not block the desktop from starting.
diff --git a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
index 43df2fcc50..657523d725 100644
--- a/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/claudeAuthAdapterOAuthEnv.test.ts
@@ -110,8 +110,10 @@ vi.mock('../shared-global-skills.js', () => ({
}));
vi.mock('../built-in-skills.js', () => ({
+ prepareBuiltInSkills: async () => ({ descriptors: [], warnings: [] }),
refreshBuiltInSharedSkillLinks: async () => ({ warnings: [] }),
refreshBuiltInClaudeSkillLinks: async () => ({ warnings: [] }),
+ resolveBundledSystemSkillsRoot: () => '/tmp/cindy-bundled-system-skills',
}));
vi.mock('../anthropic-compat-proxy-host.js', () => ({
diff --git a/apps/desktop/src/main/maker-host/auth-adapters.ts b/apps/desktop/src/main/maker-host/auth-adapters.ts
index 642ebf3a93..a633cba61a 100644
--- a/apps/desktop/src/main/maker-host/auth-adapters.ts
+++ b/apps/desktop/src/main/maker-host/auth-adapters.ts
@@ -40,8 +40,10 @@ import { prepareCodexGlobalPluginsBridge } from './codex-global-plugins.js';
import { DESKTOP_CAPABILITY_ROUTING_POLICY } from './capability-routing.js';
import { prepareSharedGlobalSkillLinks } from './shared-global-skills.js';
import {
+ prepareBuiltInSkills,
refreshBuiltInClaudeSkillLinks,
refreshBuiltInSharedSkillLinks,
+ resolveBundledSystemSkillsRoot,
} from './built-in-skills.js';
import {
copyCodexAuthSnapshot,
@@ -604,9 +606,22 @@ export class DesktopClaudeAuthAdapter implements AuthAdapter {
try {
const ownerId = getActiveAppSession().dataOwnerId;
const result = await withSharedGlobalSkillProjectionMutation(ownerId, async () => {
+ // Bundle activation and every projection of that bundle share one
+ // stable-owner critical section. Passive instances are rejected before
+ // they can switch the process-independent active manifest.
+ const preparedBuiltIns = await prepareBuiltInSkills({
+ bundledRoot: resolveBundledSystemSkillsRoot({
+ isPackaged: app.isPackaged,
+ appPath: app.getAppPath(),
+ resourcesPath: process.resourcesPath,
+ }),
+ userDataDir: app.getPath('userData'),
+ appDataDir: app.getPath('appData'),
+ });
const builtInSharedProjection = await refreshBuiltInSharedSkillLinks({
userDataDir: app.getPath('userData'),
appDataDir: app.getPath('appData'),
+ descriptors: preparedBuiltIns.descriptors,
});
const sharedProjection = await prepareSharedGlobalSkillLinks({
assertOwnerStable: () => assertGhostSkillProjectionBoundaryStableForOwner(ownerId),
@@ -614,9 +629,11 @@ export class DesktopClaudeAuthAdapter implements AuthAdapter {
const isolatedClaudeProjection = await refreshBuiltInClaudeSkillLinks({
userDataDir: app.getPath('userData'),
appDataDir: app.getPath('appData'),
+ descriptors: preparedBuiltIns.descriptors,
});
return {
warnings: [
+ ...preparedBuiltIns.warnings,
...builtInSharedProjection.warnings,
...sharedProjection.warnings,
...isolatedClaudeProjection.warnings,
diff --git a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
index b9ae55b77d..8be51e3bd7 100644
--- a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
@@ -470,6 +470,64 @@ describe('registerSkillhubIpc usage handlers', () => {
expect(writeSkillFile).not.toHaveBeenCalled();
});
+ it('keeps a scanned built-in version immutable after the active bundle advances', async () => {
+ const versionsRoot = path.join(fixtureRoot, 'shared-system-skills', '.versions');
+ const previousRoot = path.join(versionsRoot, 'v7-previous', 'learn');
+ const currentRoot = path.join(versionsRoot, 'v8-current', 'learn');
+ const previousFile = path.join(previousRoot, 'SKILL.md');
+ fs.mkdirSync(previousRoot, { recursive: true });
+ fs.mkdirSync(currentRoot, { recursive: true });
+ fs.writeFileSync(previousFile, '# Previous built-in\n');
+ fs.writeFileSync(path.join(currentRoot, 'SKILL.md'), '# Current built-in\n');
+ let activeRoot = previousRoot;
+ const sender = { id: 19, on: vi.fn(), once: vi.fn() };
+ scanAllSkills.mockResolvedValueOnce({
+ skills: [{
+ id: 'builtin:learn',
+ kind: 'skill',
+ name: 'learn',
+ absolutePath: previousRoot,
+ discoveredPath: previousRoot,
+ discoveryPaths: [previousRoot],
+ scope: 'global',
+ builtIn: true,
+ }],
+ sources: [],
+ });
+ const { registerSkillhubIpc } = await import('../registerIpc');
+ registerSkillhubIpc({
+ getMaker: () => ({ listAgentSkills }) as never,
+ getManagedSkillRoots,
+ getBuiltInSkills: () => [{
+ name: 'learn',
+ absolutePath: activeRoot,
+ nativeClaudePath: '/tmp/claude-home/skills/learn',
+ }],
+ getAllowedProjectRoots,
+ marketService: marketService as never,
+ publishService: { publish, cancel } as never,
+ });
+
+ await handlers.get('skillhub:scan')?.({ sender }, { projects: [] });
+ activeRoot = currentRoot;
+
+ await expect(handlers.get('skillhub:write-file')?.(
+ { sender },
+ { filePath: previousFile, content: '# changed' },
+ )).resolves.toMatchObject({ success: false, error: expect.stringContaining('read-only') });
+ await expect(handlers.get('skillhub:rename-local')?.(
+ { sender },
+ { absolutePath: previousRoot, newName: 'renamed' },
+ )).resolves.toMatchObject({ success: false, error: expect.stringContaining('read-only') });
+ await expect(handlers.get('skillhub:publish')?.(
+ { sender },
+ { absolutePath: previousRoot },
+ )).resolves.toMatchObject({ success: false, message: expect.stringContaining('cannot be published') });
+ expect(writeSkillFile).not.toHaveBeenCalled();
+ expect(renameLocalSkill).not.toHaveBeenCalled();
+ expect(publish).not.toHaveBeenCalled();
+ });
+
it.each(['unchanged', 'grant-wait', 'mutation-wait', 'boundary-pending'] as const)(
'guards local rename at its original owner generation: %s', async (transition) => {
const sender = { id: 71, on: vi.fn(), once: vi.fn() };
diff --git a/apps/desktop/src/main/skillhub/registerIpc.ts b/apps/desktop/src/main/skillhub/registerIpc.ts
index e40607ab5f..0f659eb59d 100644
--- a/apps/desktop/src/main/skillhub/registerIpc.ts
+++ b/apps/desktop/src/main/skillhub/registerIpc.ts
@@ -599,8 +599,12 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
ipcMain.handle(
'skillhub:write-file',
async (event, params: { filePath: string; content: string }) => {
- if (!await findScannedSkillGrant(event, params.filePath)) return scanGrantDenied();
- if (isBuiltInSkillPath(params.filePath)) {
+ const grant = await findScannedSkillGrant(event, params.filePath);
+ if (!grant) return scanGrantDenied();
+ // The scan grant is the durable attestation for the exact immutable
+ // version shown to this renderer. The active manifest may have advanced
+ // since the scan, so re-checking only the current descriptors is unsafe.
+ if (grant.builtIn || isBuiltInSkillPath(params.filePath)) {
return { success: false, error: 'Cindy built-in Skills are read-only' };
}
return writeSkillFile(params);
@@ -627,8 +631,9 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
async (event, params: { absolutePath: string; newName: string }) => {
const ownerScope = activeOwnerScopeKey();
const canMutate = () => ownerScope === activeOwnerScopeKey() && !isAppSessionBoundaryPending();
- if (!await findScannedSkillGrant(event, params.absolutePath)) return scanGrantDenied();
- if (isBuiltInSkillPath(params.absolutePath)) {
+ const grant = await findScannedSkillGrant(event, params.absolutePath);
+ if (!grant) return scanGrantDenied();
+ if (grant.builtIn || isBuiltInSkillPath(params.absolutePath)) {
return { success: false, error: 'Cindy built-in Skills are read-only' };
}
if (!canMutate()) return { success: false, error: 'Skill mutation context changed' };
@@ -990,8 +995,8 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
ipcMain.handle(
'skillhub:publish',
async (event, params: PublishParams) => {
- assertTrustedAppRendererEvent(event);
- if (isBuiltInSkillPath(params.absolutePath)) {
+ const grant = await findScannedSkillGrant(event, params.absolutePath);
+ if (grant?.builtIn || isBuiltInSkillPath(params.absolutePath)) {
return { success: false as const, errorCode: 'INTERNAL' as const, message: 'Cindy built-in Skills cannot be published' };
}
return publishService.publish(params);