🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(marketplace): list custom skills on the Skills page (#23762)
AmAzing-825c405526d0
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.jsonindex fb7b5fb350d..37d642b2012 100644--- a/locales/en-US/setting.json+++ b/locales/en-US/setting.json@@ -1389,6 +1389,7 @@"market.skills.agents.removeAll": "Remove all","market.skills.agents.title": "Assistants · {{count}}","market.skills.copyPrompt": "Copy this message",+ "market.skills.customGroup": "Custom","market.skills.desc": "Reusable ways of working for your assistants. Install one, then turn it on in an assistant.","market.skills.empty": "No matching skills","market.skills.github.add": "Add selected ({{count}})",@@ -1459,6 +1460,7 @@"market.skills.stats.stars": "GitHub stars","market.skills.title": "Skills","market.skills.uninstall": "Uninstall",+ "market.skills.uninstallFailed": "Couldn't uninstall. Try again later.","market.skills.version": "Version","marketPublish.status.archived": "Archived","marketPublish.status.deprecated": "Deprecated",diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.jsonindex 84960c395b1..9861f02e23f 100644--- a/locales/zh-CN/setting.json+++ b/locales/zh-CN/setting.json@@ -1389,6 +1389,7 @@"market.skills.agents.removeAll": "全部移除","market.skills.agents.title": "助手 · {{count}}","market.skills.copyPrompt": "复制这条消息",+ "market.skills.customGroup": "自定义","market.skills.desc": "给助手装上可复用的工作方法,安装后在助手里开启即可使用。","market.skills.empty": "没有匹配的技能","market.skills.github.add": "添加所选({{count}})",@@ -1459,6 +1460,7 @@"market.skills.stats.stars": "GitHub Star","market.skills.title": "技能","market.skills.uninstall": "卸载",+ "market.skills.uninstallFailed": "卸载失败,请稍后重试","market.skills.version": "版本","marketPublish.status.archived": "已归档","marketPublish.status.deprecated": "已弃用",diff --git a/packages/locales/src/default/setting.ts b/packages/locales/src/default/setting.tsindex 90b2c60c7fb..fe2c52155c2 100644--- a/packages/locales/src/default/setting.ts+++ b/packages/locales/src/default/setting.ts@@ -5540,6 +5540,7 @@ When I am ___, I need ___'market.skills.agents.removeAll': 'Remove all','market.skills.agents.title': 'Assistants · {{count}}','market.skills.copyPrompt': 'Copy this message',+ 'market.skills.customGroup': 'Custom','market.skills.desc':'Reusable ways of working for your assistants. Install one, then turn it on in an assistant.','market.skills.empty': 'No matching skills',@@ -5616,6 +5617,7 @@ When I am ___, I need ___'market.skills.stats.stars': 'GitHub stars','market.skills.title': 'Skills','market.skills.uninstall': 'Uninstall',+ 'market.skills.uninstallFailed': "Couldn't uninstall. Try again later.",'market.skills.version': 'Version','workspaceSetting.labels.archive.failedRetry':"Couldn't archive the label. Check your network and try again.",diff --git a/src/features/Marketplace/Skills/CustomSkills.tsx b/src/features/Marketplace/Skills/CustomSkills.tsxnew file mode 100644index 00000000000..928eb936756--- /dev/null+++ b/src/features/Marketplace/Skills/CustomSkills.tsx@@ -0,0 +1,108 @@+import { ActionIcon, confirmModal, createModal, DropdownMenu, Icon, Text } from '@lobehub/ui';+import * as stylex from '@stylexjs/stylex';+import { MoreHorizontalIcon, Trash2Icon } from 'lucide-react';+import { lazy, memo, Suspense, useMemo } from 'react';+import { useTranslation } from 'react-i18next';++import { useToolStore } from '@/store/tool';+import { agentSkillsSelectors } from '@/store/tool/selectors';+import type { AgentSkillListItem } from '@/store/tool/slices/agentSkills/projection';++import { customSkillsOf } from './customSkillFilter';+import { Row } from './github/GithubRows';+import SkillIcon from './SkillIcon';+import { useUninstallLibrarySkill } from './useUninstallLibrarySkill';++const AgentSkillDetail = lazy(() => import('@/features/AgentSkillDetail'));++const styles = stylex.create({+ grid: {+ display: 'grid',+ gridTemplateColumns: 'repeat(2, minmax(0, 1fr))',+ columnGap: 16,+ rowGap: 4,+ },+});++/** The user's own skills that came from neither the market nor GitHub. */+export const useCustomSkills = (query = '') => {+ const skills = useToolStore(agentSkillsSelectors.getUserAgentSkills);+ return useMemo(() => customSkillsOf(skills, query), [query, skills]);+};++/**+ * A custom skill: opening it shows its SKILL.md and files; its menu uninstalls it.+ * The library holds its only copy, so uninstalling asks first.+ */+const CustomSkillRow = memo<{ skill: AgentSkillListItem }>(({ skill }) => {+ const { t } = useTranslation('setting');+ const { t: tp } = useTranslation('plugin');+ const { failed, removing, uninstall } = useUninstallLibrarySkill(skill.id);++ const openDetail = () =>+ createModal({+ content: (+ <Suspense fallback={<div style={{ height: '100%' }} />}>+ <AgentSkillDetail skillId={skill.id} />+ </Suspense>+ ),+ footer: null,+ styles: { content: { height: 'calc(100dvh - 200px)', overflow: 'hidden', padding: 0 } },+ title: tp('dev.title.skillDetails'),+ width: 960,+ });++ const confirmUninstall = () =>+ confirmModal({+ content: tp('store.actions.confirmUninstall'),+ okButtonProps: { danger: true },+ okText: tp('store.actions.uninstall'),+ onOk: uninstall,+ title: tp('store.actions.uninstall'),+ });++ return (+ <Row+ icon={<SkillIcon size={40} />}+ title={skill.name}+ action={+ <DropdownMenu+ placement={'bottomRight'}+ items={[+ {+ danger: true,+ icon: <Icon icon={Trash2Icon} />,+ key: 'uninstall',+ label: t('market.skills.uninstall'),+ onClick: confirmUninstall,+ },+ ]}+ >+ <ActionIcon+ icon={MoreHorizontalIcon}+ loading={removing}+ title={t('connectorMarket.action.manage')}+ />+ </DropdownMenu>+ }+ subtitle={+ <Text ellipsis fontSize={12} type={failed ? 'danger' : 'secondary'}>+ {failed ? t('market.skills.uninstallFailed') : skill.description}+ </Text>+ }+ onOpen={openDetail}+ />+ );+});++CustomSkillRow.displayName = 'MarketCustomSkillRow';++export const CustomSkills = memo<{ items: AgentSkillListItem[] }>(({ items }) => (+ <div {...stylex.props(styles.grid)}>+ {items.map((skill) => (+ <CustomSkillRow key={skill.id} skill={skill} />+ ))}+ </div>+));++CustomSkills.displayName = 'MarketCustomSkills';diff --git a/src/features/Marketplace/Skills/SkillsPage.tsx b/src/features/Marketplace/Skills/SkillsPage.tsxindex d7afb570bea..65b33dbb76f 100644--- a/src/features/Marketplace/Skills/SkillsPage.tsx+++ b/src/features/Marketplace/Skills/SkillsPage.tsx@@ -14,6 +14,7 @@ import { agentSkillsSelectors } from '@/store/tool/selectors';import { SkillCategory, SkillSorts } from '@/types/discover';import BackLink from './BackLink';+import { CustomSkills, useCustomSkills } from './CustomSkills';import GithubImportPage from './github/GithubImportPage';import { GithubAddressRow } from './github/GithubRows';import {@@ -195,6 +196,7 @@ const Catalog = memo(() => {const { t } = useTranslation('setting');const installed = useInstalledSkills();const fromGithub = useInstalledGithubSkills();+ const custom = useCustomSkills();const { setGroup: setSkillGroup } = useSkillsNav();const useSkillCategories = useDiscoverStore((s) => s.useSkillCategories);const { isLoading, queryKey } = useSkillCategories();@@ -224,6 +226,11 @@ const Catalog = memo(() => {<InstalledGithubSkills items={fromGithub} /></Group>)}+ {custom.length > 0 && (+ <Group title={t('market.skills.customGroup')}>+ <CustomSkills items={custom} />+ </Group>+ )}{isLoading && !categories ? (<><SectionSkeleton count={PREVIEW_COUNT} />@@ -240,12 +247,13 @@ const Catalog = memo(() => {Catalog.displayName = 'MarketSkillCatalog';-/** Search results: matching installed skills first, then the market's. */+/** Search results: matching skills in the library first, then the market's. */const SearchResults = memo<{ query: string }>(({ query }) => {const { t } = useTranslation('setting');const [pageSize, setPageSize] = useState(PAGE_SIZE);const installed = useInstalledSkills().filter((skill) => matches(skill, query));const fromGithub = useInstalledGithubSkills(query);+ const custom = useCustomSkills(query);const address = parseGithubSource(query);const { setGithubUrl } = useSkillsNav();const { isLoading, items, total } = useMarketSkills({ q: query }, pageSize, !address);@@ -273,6 +281,11 @@ const SearchResults = memo<{ query: string }>(({ query }) => {<InstalledGithubSkills items={fromGithub} /></Group>)}+ {custom.length > 0 && (+ <Group title={t('market.skills.customGroup')}>+ <CustomSkills items={custom} />+ </Group>+ )}<Group title={t('market.skills.results')}>{isLoading && items.length === 0 ? (<GridSkeleton />@@ -347,7 +360,7 @@ const GroupPage = memo<{ group: string }>(({ group }) => {GroupPage.displayName = 'MarketSkillGroupPage';/**- * The Skills page: my skills (from the Market, then from GitHub), then the LobeHub+ * The Skills page: my skills (from the Market, from GitHub, then custom), then the LobeHub* Market's skills by category, each a short preview whose arrow opens the whole* group. Searching lists every match, then public GitHub repositories; a pasted* GitHub address offers that repository instead. "Add from GitHub" opens thediff --git a/src/features/Marketplace/Skills/customSkillFilter.test.ts b/src/features/Marketplace/Skills/customSkillFilter.test.tsnew file mode 100644index 00000000000..e8b84df8ff1--- /dev/null+++ b/src/features/Marketplace/Skills/customSkillFilter.test.ts@@ -0,0 +1,44 @@+import { describe, expect, it } from 'vitest';++import { customSkillsOf } from './customSkillFilter';++const manifest = { name: 'skill' } as any;++const cli = {+ description: 'Made with lh skill create',+ manifest,+ name: 'My Notes',+ source: 'user' as const,+};+const github = {+ ...cli,+ name: 'From GitHub',+ upstream: { owner: 'o', path: 'skills/pdf', ref: 'main', repo: 'r' },+};+const legacyGithub = {+ ...cli,+ manifest: { ...manifest, sourceUrl: 'https://github.com/o/r' },+ name: 'Legacy GitHub',+};+const market = { ...cli, name: 'Market', source: 'market' as const };+const builtin = { ...cli, name: 'Builtin', source: 'builtin' as const };++describe('customSkillsOf', () => {+ it('keeps user skills that have no GitHub origin', () => {+ expect(customSkillsOf([cli, github, legacyGithub, market, builtin])).toEqual([cli]);+ });++ it('keeps a user skill imported from a non-GitHub address', () => {+ const fromUrl = {+ ...cli,+ manifest: { ...manifest, sourceUrl: 'https://example.com/skill.zip' },+ };+ expect(customSkillsOf([fromUrl])).toEqual([fromUrl]);+ });++ it('matches the query against name and description', () => {+ expect(customSkillsOf([cli], 'notes')).toEqual([cli]);+ expect(customSkillsOf([cli], 'LH SKILL')).toEqual([cli]);+ expect(customSkillsOf([cli], 'pdf')).toEqual([]);+ });+});diff --git a/src/features/Marketplace/Skills/customSkillFilter.ts b/src/features/Marketplace/Skills/customSkillFilter.tsnew file mode 100644index 00000000000..16056dc0da8--- /dev/null+++ b/src/features/Marketplace/Skills/customSkillFilter.ts@@ -0,0 +1,23 @@+import type { SkillListItem } from '@lobechat/types';++import { githubSkillUrl } from './github/githubInstalled';++type LibrarySkill = Pick<+ SkillListItem,+ 'description' | 'manifest' | 'name' | 'source' | 'upstream'+>;++/**+ * The user's own skills with no GitHub origin: written by hand, created through+ * `lh skill create` or an agent, or imported from a URL or ZIP. Neither the+ * market's "Installed" group nor "From GitHub" lists them.+ */+export const customSkillsOf = <T extends LibrarySkill>(skills: T[], query = ''): T[] => {+ const q = query.trim().toLowerCase();+ return skills.filter(+ (skill) =>+ skill.source === 'user' &&+ !githubSkillUrl(skill) &&+ (!q || [skill.name, skill.description ?? ''].some((v) => v.toLowerCase().includes(q))),+ );+};diff --git a/src/features/Marketplace/Skills/github/GithubRows.tsx b/src/features/Marketplace/Skills/github/GithubRows.tsxindex 360cc6bd651..0da475397df 100644--- a/src/features/Marketplace/Skills/github/GithubRows.tsx+++ b/src/features/Marketplace/Skills/github/GithubRows.tsx@@ -4,14 +4,14 @@ import { GithubIcon } from '@lobehub/ui/icons';import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';import * as stylex from '@stylexjs/stylex';import { ExternalLinkIcon, MoreHorizontalIcon, StarIcon, Trash2Icon } from 'lucide-react';-import { memo, type ReactNode, useState } from 'react';+import { memo, type ReactNode } from 'react';import { useTranslation } from 'react-i18next';-import { useToolStore } from '@/store/tool';import type { AgentSkillListItem } from '@/store/tool/slices/agentSkills/projection';import IconTile from '../IconTile';import SkillIcon from '../SkillIcon';+import { useUninstallLibrarySkill } from '../useUninstallLibrarySkill';import { githubSkillRepo } from './githubInstalled';import type { GithubRepoHit } from './searchGithubRepos';import { useApplyGithubUpdate } from './useGithubSkillUpdates';@@ -46,7 +46,7 @@ const styles = stylex.create({});/** The cell every GitHub row shares with the Market's skill rows: icon, two lines, an action. */-const Row = ({+export const Row = ({action,icon,onOpen,@@ -140,23 +140,11 @@ export const GithubSkillRow = memo<{skill: AgentSkillListItem;}>(({ check, onOpen, skill }) => {const { t } = useTranslation('setting');- const deleteAgentSkill = useToolStore((s) => s.deleteAgentSkill);const { error, pending, update } = useApplyGithubUpdate(skill.id, check);- const [removing, setRemoving] = useState(false);+ const { failed: uninstallFailed, removing, uninstall } = useUninstallLibrarySkill(skill.id);const repo = githubSkillRepo(skill);const sourceUrl = skill.manifest?.sourceUrl ?? (repo ? `https://github.com/${repo}` : undefined);- const uninstall = async () => {- setRemoving(true);- try {- await deleteAgentSkill(skill.id);- } catch (cause) {- console.warn('[Market] Failed to uninstall skill:', cause);- } finally {- setRemoving(false);- }- };-return (<Rowicon={<SkillIcon size={40} />}@@ -195,10 +183,12 @@ export const GithubSkillRow = memo<{</>}subtitle={- <Text ellipsis fontSize={12} type={error ? 'danger' : 'secondary'}>- {error- ? t('market.skills.github.updateFailed')- : [repo, skill.description].filter(Boolean).join(' · ')}+ <Text ellipsis fontSize={12} type={error || uninstallFailed ? 'danger' : 'secondary'}>+ {uninstallFailed+ ? t('market.skills.uninstallFailed')+ : error+ ? t('market.skills.github.updateFailed')+ : [repo, skill.description].filter(Boolean).join(' · ')}</Text>}onOpen={onOpen}diff --git a/src/features/Marketplace/Skills/useUninstallLibrarySkill.test.ts b/src/features/Marketplace/Skills/useUninstallLibrarySkill.test.tsnew file mode 100644index 00000000000..3057b671c38--- /dev/null+++ b/src/features/Marketplace/Skills/useUninstallLibrarySkill.test.ts@@ -0,0 +1,38 @@+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useUninstallLibrarySkill } from './useUninstallLibrarySkill';++const deleteAgentSkill = vi.fn();++vi.mock('@/store/tool', () => ({+ useToolStore: (selector: (s: unknown) => unknown) => selector({ deleteAgentSkill }),+}));++describe('useUninstallLibrarySkill', () => {+ beforeEach(() => {+ deleteAgentSkill.mockReset();+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ });++ it('reports a failed uninstall instead of finishing silently', async () => {+ deleteAgentSkill.mockRejectedValueOnce(new Error('500'));+ const { result } = renderHook(() => useUninstallLibrarySkill('skill-1'));++ await act(() => result.current.uninstall());++ expect(deleteAgentSkill).toHaveBeenCalledWith('skill-1');+ expect(result.current.failed).toBe(true);+ expect(result.current.removing).toBe(false);+ });++ it('clears the failure when a retry succeeds', async () => {+ deleteAgentSkill.mockRejectedValueOnce(new Error('500')).mockResolvedValueOnce(undefined);+ const { result } = renderHook(() => useUninstallLibrarySkill('skill-1'));++ await act(() => result.current.uninstall());+ await act(() => result.current.uninstall());++ expect(result.current.failed).toBe(false);+ });+});diff --git a/src/features/Marketplace/Skills/useUninstallLibrarySkill.ts b/src/features/Marketplace/Skills/useUninstallLibrarySkill.tsnew file mode 100644index 00000000000..6af425d98d5--- /dev/null+++ b/src/features/Marketplace/Skills/useUninstallLibrarySkill.ts@@ -0,0 +1,28 @@+import { useState } from 'react';++import { useToolStore } from '@/store/tool';++/**+ * Removes a skill from the library by its row id. `failed` stays set after an+ * error until the next attempt, so the row can say the skill is still there.+ */+export const useUninstallLibrarySkill = (id: string) => {+ const deleteAgentSkill = useToolStore((s) => s.deleteAgentSkill);+ const [removing, setRemoving] = useState(false);+ const [failed, setFailed] = useState(false);++ const uninstall = async () => {+ setRemoving(true);+ setFailed(false);+ try {+ await deleteAgentSkill(id);+ } catch (cause) {+ console.warn('[Market] Failed to uninstall skill:', cause);+ setFailed(true);+ } finally {+ setRemoving(false);+ }+ };++ return { failed, removing, uninstall };+};diff --git a/tests/moduleNames.test.ts b/tests/moduleNames.test.tsnew file mode 100644index 00000000000..aa5be66c40c--- /dev/null+++ b/tests/moduleNames.test.ts@@ -0,0 +1,55 @@+// @vitest-environment node+import { execFileSync } from 'node:child_process';+import { existsSync } from 'node:fs';+import path from 'node:path';++import { describe, expect, it } from 'vitest';++const git = (args: string[], cwd = process.cwd()) =>+ execFileSync('git', args, { cwd, encoding: 'utf8', maxBuffer: 64 * 1024 ** 2 });+const MODULE_PATTERN = /\.[cm]?[jt]sx?$/;++/**+ * Tracked and new (not ignored) files on disk, so a local collision fails before+ * it is committed and a deletion not yet staged does not count.+ */+const listFiles = () => {+ const root = git(['rev-parse', '--show-toplevel']).trim();+ return git(['ls-files', '--cached', '--others', '--exclude-standard'], root)+ .split('\n')+ .filter((file) => file && existsSync(path.join(root, file)));+};++/**+ * Module paths (extension dropped) that differ only by letter case. macOS and+ * Windows filesystems are case-insensitive by default, so an import of one+ * resolves to whichever the resolver finds first, e.g. `./CustomSkills` loading+ * `customSkills.ts` instead of `CustomSkills.tsx`.+ */+const findCaseCollisions = (files: string[]) => {+ const byKey = new Map<string, Set<string>>();+ for (const file of files) {+ if (!MODULE_PATTERN.test(file)) continue;+ const modulePath = file.replace(MODULE_PATTERN, '');+ const key = modulePath.toLowerCase();+ byKey.set(key, (byKey.get(key) ?? new Set()).add(modulePath));+ }+ return [...byKey.values()].filter((paths) => paths.size > 1).map((paths) => [...paths].sort());+};++describe('module names', () => {+ it('flags modules whose paths differ only by case', () => {+ expect(+ findCaseCollisions([+ 'src/a/CustomSkills.tsx',+ 'src/a/customSkills.ts',+ 'src/a/index.ts',+ 'src/a/index.tsx',+ ]),+ ).toEqual([['src/a/CustomSkills', 'src/a/customSkills']]);+ });++ it('has no case-only collisions in the repository', () => {+ expect(findCaseCollisions(listFiles())).toEqual([]);+ });+});