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): require scan grants for Skill publish

xd-bobo017160b9ca5e
diff --git a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
index b564fc1176..383a0b65c3 100644
--- a/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/registerIpcUsage.test.ts
@@ -247,7 +247,20 @@ describe('registerSkillhubIpc usage handlers', () => {
marketService: marketService as never,
publishService: { publish, cancel } as never,
});
- const event = { sender: { id: 12 } };
+ scanAllSkills.mockResolvedValueOnce({
+ skills: [{
+ id: 'builtin:cindy-skill-creator',
+ kind: 'skill',
+ name: 'cindy-skill-creator',
+ absolutePath: builtInRoot,
+ discoveredPath: builtInRoot,
+ scope: 'global',
+ builtIn: true,
+ }],
+ sources: [],
+ });
+ const event = { sender: { id: 12, on: vi.fn(), once: vi.fn() } };
+ await handlers.get('skillhub:scan')!(event, { projects: [] });
await expect(handlers.get('skillhub:publish')!(event, {
absolutePath: builtInFile,
@@ -256,6 +269,20 @@ describe('registerSkillhubIpc usage handlers', () => {
expect(publish).not.toHaveBeenCalled();
});
+ it('rejects publishing a path absent from the sender latest scan', async () => {
+ const event = { sender: { id: 13, on: vi.fn(), once: vi.fn() } };
+
+ await expect(handlers.get('skillhub:publish')!(event, {
+ absolutePath: '/repo/.pi/skills/authorized/demo',
+ name: 'demo',
+ isFirstPublish: true,
+ })).resolves.toMatchObject({
+ success: false,
+ error: expect.stringContaining('Refresh'),
+ });
+ expect(publish).not.toHaveBeenCalled();
+ });
+
describe.each([
{ channel: 'skillhub:get-scan-status', field: 'slug', method: 'getScanStatus' },
{ channel: 'skillhub:list-published-versions', field: 'name', method: 'listPublishedVersions' },
@@ -578,6 +605,11 @@ describe('registerSkillhubIpc usage handlers', () => {
it.each(['unchanged', 'grant-wait', 'mutation-wait', 'boundary-pending'] as const)(
'guards local rename at its original owner generation: %s', async (transition) => {
+ resolveExistingSkillPathForGrant.mockImplementation((candidate: string) => {
+ if (candidate.includes('/authorized/demo')) return '/physical/demo';
+ if (candidate === '/physical/renamed') return '/physical/renamed';
+ return null;
+ });
const sender = { id: 71, on: vi.fn(), once: vi.fn() };
scanAllSkills.mockResolvedValueOnce({ skills: [{
absolutePath: '/physical/demo', discoveredPath: '/repo/.pi/skills/authorized/demo',
@@ -607,6 +639,45 @@ describe('registerSkillhubIpc usage handlers', () => {
},
);
+ it('carries a scanned user Skill grant across rename into immediate publish', async () => {
+ resolveExistingSkillPathForGrant.mockImplementation((candidate: string) => {
+ if (candidate.includes('/authorized/demo')) return '/physical/demo';
+ if (candidate === '/physical/renamed') return '/physical/renamed';
+ return null;
+ });
+ isExistingSkillPathGranted.mockImplementation((candidate: string, roots: Set<string>) => (
+ (candidate.includes('/authorized/demo') && roots.has('/physical/demo'))
+ || (candidate === '/physical/renamed' && roots.has('/physical/renamed'))
+ ));
+ scanAllSkills.mockResolvedValueOnce({ skills: [{
+ absolutePath: '/physical/demo',
+ discoveredPath: '/repo/.pi/skills/authorized/demo',
+ scope: 'project',
+ projectRoot: '/repo',
+ }], sources: [] });
+ renameLocalSkill.mockResolvedValueOnce({
+ success: true,
+ newAbsolutePath: '/physical/renamed',
+ });
+ publish.mockResolvedValueOnce({ success: true });
+ const sender = { id: 72, on: vi.fn(), once: vi.fn() };
+
+ await handlers.get('skillhub:scan')!({ sender }, { projects: [] });
+ await expect(handlers.get('skillhub:rename-local')!({ sender }, {
+ absolutePath: '/repo/.pi/skills/authorized/demo',
+ newName: 'renamed',
+ })).resolves.toEqual({ success: true, newAbsolutePath: '/physical/renamed' });
+ const publishParams = {
+ absolutePath: '/physical/renamed',
+ name: 'renamed',
+ isFirstPublish: true,
+ };
+
+ await expect(handlers.get('skillhub:publish')!({ sender }, publishParams))
+ .resolves.toEqual({ success: true });
+ expect(publish).toHaveBeenCalledWith(publishParams);
+ });
+
it('revokes project scan grants after the last active project session disappears', async () => {
const sender = { id: 12, on: vi.fn(), once: vi.fn() };
scanAllSkills.mockResolvedValueOnce({
diff --git a/apps/desktop/src/main/skillhub/registerIpc.ts b/apps/desktop/src/main/skillhub/registerIpc.ts
index 970eeca100..f70b4cd13a 100644
--- a/apps/desktop/src/main/skillhub/registerIpc.ts
+++ b/apps/desktop/src/main/skillhub/registerIpc.ts
@@ -639,7 +639,18 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
}
if (!canMutate()) return { success: false, error: 'Skill mutation context changed' };
const result = await renameLocalSkill(params, canMutate);
- if (result.success) broadcastLocalChange();
+ if (result.success) {
+ // The publish dialog intentionally continues with the renamed path.
+ // Carry forward the exact non-built-in grant that authorized the
+ // rename so publish can remain fail-closed without forcing a rescan
+ // between the two operations.
+ const renamedRoot = resolveExistingSkillPathForGrant(result.newAbsolutePath);
+ if (!renamedRoot) {
+ return { success: false, error: 'Skill was renamed; refresh the Skill list and retry' };
+ }
+ grant.root = renamedRoot;
+ broadcastLocalChange();
+ }
return result;
},
);
@@ -997,8 +1008,23 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
'skillhub:publish',
async (event, params: PublishParams) => {
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' };
+ if (!grant) {
+ const message = 'Refresh the Skill list before publishing';
+ return {
+ success: false as const,
+ errorCode: 'INTERNAL' as const,
+ error: message,
+ message,
+ };
+ }
+ if (grant.builtIn || isBuiltInSkillPath(params.absolutePath)) {
+ const message = 'Cindy built-in Skills cannot be published';
+ return {
+ success: false as const,
+ errorCode: 'INTERNAL' as const,
+ error: message,
+ message,
+ };
}
return publishService.publish(params);
},