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): hide empty categories in skill browsing

xd-bobo85f777124dba
diff --git a/apps/desktop/src/main/skillhub/__tests__/marketService.test.ts b/apps/desktop/src/main/skillhub/__tests__/marketService.test.ts
index 6303cf37b0..0e4a96dbc8 100644
--- a/apps/desktop/src/main/skillhub/__tests__/marketService.test.ts
+++ b/apps/desktop/src/main/skillhub/__tests__/marketService.test.ts
@@ -379,6 +379,32 @@ describe('SkillhubMarketService', () => {
opts: undefined,
}]);
});
+
+ it.each(['market', 'team'] as const)('excludes empty browse tags from older %s servers, including nested tags', async (scope) => {
+ const { fetch, calls } = makeFetch([[
+ { slug: 'empty', name: 'Empty', skillCount: 0, mySkillCount: 2,
+ children: [{ slug: 'used', name: 'Used', skillCount: 3, mySkillCount: 1 }] },
+ { slug: 'missing-count', name: 'Missing' },
+ ]]);
+ const service = new SkillhubMarketService({ fetch });
+
+ await expect(service.listCategories(scope, false)).resolves.toEqual({
+ success: true,
+ categories: [{ slug: 'used', name: 'Used', count: 3, myCount: 1 }],
+ totalCount: 3,
+ myTotalCount: 1,
+ });
+ expect(calls[0]?.path).toBe(`/api/skills-hub/categories?scope=${scope}&includeEmpty=false`);
+ });
+
+ it('keeps unused tags selectable in explicit full-list mode', async () => {
+ const { fetch, calls } = makeFetch([[{ slug: 'empty', name: 'Empty', skillCount: 0 }]]);
+ const service = new SkillhubMarketService({ fetch });
+ await expect(service.listCategories('market', true)).resolves.toMatchObject({
+ categories: [{ slug: 'empty', count: 0 }],
+ });
+ expect(calls[0]?.path).toBe('/api/skills-hub/categories?scope=market');
+ });
});
describe('skillhub market helpers', () => {
diff --git a/apps/desktop/src/main/skillhub/marketService.ts b/apps/desktop/src/main/skillhub/marketService.ts
index 3ed1508bf6..8703a6fb5d 100644
--- a/apps/desktop/src/main/skillhub/marketService.ts
+++ b/apps/desktop/src/main/skillhub/marketService.ts
@@ -296,7 +296,7 @@ export class SkillhubMarketService {
};
}
- async listCategories(scope: SkillhubCatalogScope = 'market') {
+ async listCategories(scope: SkillhubCatalogScope = 'market', includeEmpty = true) {
const items = await this.fetch<Array<{
slug: string;
name: string;
@@ -309,8 +309,9 @@ export class SkillhubMarketService {
skillCount?: number;
mySkillCount?: number;
}>;
- }>>(`/api/skills-hub/categories?scope=${scope}`);
- const categories = flattenHubCategories(items ?? []);
+ }>>(`/api/skills-hub/categories?scope=${scope}${includeEmpty ? '' : '&includeEmpty=false'}`);
+ // Older servers may ignore includeEmpty; keep their empty tags out of browse results too.
+ const categories = flattenHubCategories(items ?? []).filter((category) => includeEmpty || category.count > 0);
const totalCount = categories.reduce((s, c) => s + c.count, 0);
const myTotalCount = categories.reduce((s, c) => s + c.myCount, 0);
return { success: true as const, categories, totalCount, myTotalCount };
diff --git a/apps/desktop/src/main/skillhub/registerIpc.ts b/apps/desktop/src/main/skillhub/registerIpc.ts
index 0836419af6..0e85b28aa4 100644
--- a/apps/desktop/src/main/skillhub/registerIpc.ts
+++ b/apps/desktop/src/main/skillhub/registerIpc.ts
@@ -577,12 +577,12 @@ export function registerSkillhubIpc(options: RegisterSkillhubIpcOptions): void {
// Market 分类列表 — 若 broker / 网络不可用,降级空数组
ipcMain.handle(
'skillhub:list-categories',
- async (_event, params?: { scope?: 'market' | 'team' }) => {
+ async (_event, params?: { scope?: 'market' | 'team'; includeEmpty?: boolean }) => {
try {
// Renderer payload is untrusted: only the two catalog scopes are valid,
// and an absent/invalid value keeps the historical market behavior.
const scope = params?.scope === 'team' ? 'team' : 'market';
- return await marketService.listCategories(scope);
+ return await marketService.listCategories(scope, params?.includeEmpty !== false);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
log.warn('list-categories failed', message);
diff --git a/apps/desktop/src/preload/preload.ts b/apps/desktop/src/preload/preload.ts
index c7fbb2406b..b7b4e03db0 100644
--- a/apps/desktop/src/preload/preload.ts
+++ b/apps/desktop/src/preload/preload.ts
@@ -3197,6 +3197,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
// Market 分类列表
listCategories: (params?: {
scope?: import('../shared/skillhubCatalog').SkillhubCatalogScope;
+ /** Defaults to true for publish/edit pickers; browse filters pass false. */
+ includeEmpty?: boolean;
}): Promise<{
success: boolean;
categories?: import('../shared/skillhubCategory').MarketCategory[];
diff --git a/apps/desktop/src/renderer/features/skillhub/hooks/__tests__/useCategoryList.test.tsx b/apps/desktop/src/renderer/features/skillhub/hooks/__tests__/useCategoryList.test.tsx
index a16e9406d0..7fece120be 100644
--- a/apps/desktop/src/renderer/features/skillhub/hooks/__tests__/useCategoryList.test.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/hooks/__tests__/useCategoryList.test.tsx
@@ -52,6 +52,7 @@ describe('useCategoryList data-owner isolation', () => {
const first = renderHook(() => useCategoryList('team'));
await waitFor(() => expect(listCategories).toHaveBeenCalledTimes(1));
+ expect(listCategories).toHaveBeenLastCalledWith({ scope: 'team', includeEmpty: false });
first.unmount();
setDataOwnerGeneration('owner-b', 2);
diff --git a/apps/desktop/src/renderer/features/skillhub/hooks/useMarketList.ts b/apps/desktop/src/renderer/features/skillhub/hooks/useMarketList.ts
index bb60ea1b5d..8fdc8e7c83 100644
--- a/apps/desktop/src/renderer/features/skillhub/hooks/useMarketList.ts
+++ b/apps/desktop/src/renderer/features/skillhub/hooks/useMarketList.ts
@@ -699,7 +699,7 @@ export function useCategoryList(scope: SkillhubCatalogScope = 'market'): Categor
new Map<SkillhubCatalogScope, Promise<CategoryListState>>();
if (!inflightCategories.has(owner)) inflightCategories.set(owner, ownerInflight);
const existing = ownerInflight.get(scope);
- const inflight = existing ?? window.electronAPI.skillhub.listCategories({ scope })
+ const inflight = existing ?? window.electronAPI.skillhub.listCategories({ scope, includeEmpty: false })
.then((res) => (res.success
? { categories: res.categories ?? [], totalCount: res.totalCount ?? 0, myTotalCount: res.myTotalCount ?? 0 }
: EMPTY_CATEGORY_STATE))
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index 3b7c53c8dd..b4644f9aea 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -3411,6 +3411,8 @@ interface ElectronAPI {
}>;
listCategories: (params?: {
scope?: import('../shared/skillhubCatalog').SkillhubCatalogScope;
+ /** Defaults to true for publish/edit pickers; browse filters pass false. */
+ includeEmpty?: boolean;
}) => Promise<{
success: boolean;
categories?: import('../shared/skillhubCategory').MarketCategory[];
diff --git a/apps/desktop/src/shared/skillhubCategory.ts b/apps/desktop/src/shared/skillhubCategory.ts
index 8950429696..738690b06a 100644
--- a/apps/desktop/src/shared/skillhubCategory.ts
+++ b/apps/desktop/src/shared/skillhubCategory.ts
@@ -1,8 +1,8 @@
/**
* SkillHub 分类(main / preload / renderer 共享类型)。
* slug 是后端稳定标识,name 是展示用本地化字符串。
- * count = 该分类下总 skill 数(Hub skillCount)。
- * myCount = 该分类下当前用户发布的 skill 数(Hub mySkillCount)。
+ * count = 当前目录中该分类下可见的 skill 数(Hub skillCount)。
+ * myCount = 同一目录中当前用户发布的 skill 数(Hub mySkillCount)。
*/
export interface MarketCategory {
slug: string;