π€― 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(chat): inject device-bound project skills into the slash menu (#15797)
Arvin Xu60fa4e31cdcb
diff --git a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.tsindex 11f3277321c..596f0cd1d5e 100644--- a/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts+++ b/src/features/ChatInput/InputEditor/ActionTag/useSlashActionItems.ts@@ -1,5 +1,5 @@import { isDesktop } from '@lobechat/const';-import { type ListProjectSkillsResult, type ProjectSkillItem } from '@lobechat/electron-client-ipc';+import { type ProjectSkillItem } from '@lobechat/electron-client-ipc';import type { IEditor, SlashOptions } from '@lobehub/editor';import { SkillsIcon } from '@lobehub/ui/icons';import isEqual from 'fast-deep-equal';@@ -9,9 +9,11 @@ import { ArchiveIcon, MessageSquarePlusIcon } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { resolveExecutionTarget } from '@/helpers/executionTarget';import { useEffectiveWorkingDirectory } from '@/hooks/useEffectiveWorkingDirectory';-import { useClientDataSWR } from '@/libs/swr';-import { localFileService } from '@/services/electron/localFileService';+import { useFetchProjectSkills } from '@/hooks/useFetchProjectSkills';+import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import { useToolStore } from '@/store/tool';import { agentDocumentSkillsSelectors } from '@/store/tool/selectors';@@ -53,11 +55,31 @@ export const useSlashActionItems = (): SlashOptions['items'] => {// set (and for local-device runs), not just an explicit agent/topic pick.const workingDirectory = useEffectiveWorkingDirectory(agentId);- const projectSkillsEnabled = isDesktop && !!workingDirectory;- const { data: projectSkillsData } = useClientDataSWR<ListProjectSkillsResult>(- projectSkillsEnabled ? ['project-skills', workingDirectory] : null,- () => localFileService.listProjectSkills({ scope: workingDirectory! }),- { revalidateOnFocus: false, shouldRetryOnError: false },+ // Device-bound (remote) runs scan project skills on that device over the+ // `device.listProjectSkills` RPC; the local desktop reads over Electron IPC.+ // Mirror the WorkingSidebar exactly: resolve the EFFECTIVE target first, then+ // treat it as remote only when it lands on `device` with a bound device. The+ // effective target matters because a hetero agent saved as desktop "This+ // device" (`local` + boundDeviceId) coerces to `device` when opened on web β+ // reading the raw stored target would miss that and leave the menu empty even+ // though the sidebar lists the skills.+ const agencyConfig = useAgentStore((s) =>+ agentId ? agentByIdSelectors.getAgencyConfigById(agentId)(s) : undefined,+ );+ const isHetero = useAgentStore((s) =>+ agentId ? agentByIdSelectors.isAgentHeterogeneousById(agentId)(s) : false,+ );+ const effectiveTarget = resolveExecutionTarget(agencyConfig, { isDesktop, isHetero });+ const isDeviceMode = effectiveTarget === 'device' && !!agencyConfig?.boundDeviceId;+ const remoteDeviceId = isDeviceMode ? agencyConfig.boundDeviceId : undefined;++ // Local desktop reads over IPC; a bound device reads over RPC. Either path+ // makes project skills reachable even when this client isn't the desktop app+ // (previously gated on `isDesktop` alone, so remote/web runs got nothing).+ const projectSkillsEnabled = (isDesktop || !!remoteDeviceId) && !!workingDirectory;+ const { data: projectSkillsData } = useFetchProjectSkills(+ projectSkillsEnabled ? workingDirectory : undefined,+ remoteDeviceId,);const projectSkills = projectSkillsData?.skills;diff --git a/src/features/SkillsList/useProjectSkills.ts b/src/features/SkillsList/useProjectSkills.tsindex f6f71960674..1ea16f8637e 100644--- a/src/features/SkillsList/useProjectSkills.ts+++ b/src/features/SkillsList/useProjectSkills.ts@@ -2,8 +2,7 @@ import { type ListProjectSkillsResult, type ProjectSkillItem } from '@lobechat/eimport path from 'pathe';import { useMemo } from 'react';-import { useClientDataSWR } from '@/libs/swr';-import { projectSkillService } from '@/services/projectSkill';+import { useFetchProjectSkills } from '@/hooks/useFetchProjectSkills';import { useChatStore } from '@/store/chat';import type { SkillListItem } from './SkillsList';@@ -36,11 +35,7 @@ export const useProjectSkills = (const openLocalFile = useChatStore((s) => s.openLocalFile);const isRemote = !!deviceId;- const { data, isLoading } = useClientDataSWR<ListProjectSkillsResult | undefined>(- workingDirectory ? ['project-skills', deviceId ?? 'local', workingDirectory] : null,- () => projectSkillService.listProjectSkills({ deviceId, scope: workingDirectory! }),- { revalidateOnFocus: false, shouldRetryOnError: false },- );+ const { data, isLoading } = useFetchProjectSkills(workingDirectory, deviceId);// listProjectSkills approves `data.root` for preview. Hand that exact value// back to openLocalFile so LocalFileProtocolManager.createPreviewUrl'sdiff --git a/src/hooks/useFetchProjectSkills.ts b/src/hooks/useFetchProjectSkills.tsnew file mode 100644index 00000000000..d466423ac23--- /dev/null+++ b/src/hooks/useFetchProjectSkills.ts@@ -0,0 +1,27 @@+import { type ListProjectSkillsResult } from '@lobechat/electron-client-ipc';++import { useClientDataSWR } from '@/libs/swr';+import { projectSkillService } from '@/services/projectSkill';++/**+ * Shared SWR fetch for filesystem-backed project skills under `.agents/skills/`+ * / `.claude/skills/` in a working directory.+ *+ * `deviceId` picks the transport: a bound device scans over the+ * `device.listProjectSkills` RPC, the local desktop reads over Electron IPC. The+ * SWR key is stable across callers (the `/` slash menu and the SkillsList UI+ * hook), so they dedupe a single fetch. Pass `undefined` workingDirectory to+ * keep the hook inert β no fetch fires.+ */+export const useFetchProjectSkills = (workingDirectory: string | undefined, deviceId?: string) => {+ const isRemote = !!deviceId;+ return useClientDataSWR<ListProjectSkillsResult | undefined>(+ workingDirectory ? ['project-skills', deviceId ?? 'local', workingDirectory] : null,+ () => projectSkillService.listProjectSkills({ deviceId, scope: workingDirectory! }),+ // Remote skills live on a device this client can't watch for filesystem+ // changes, so refetch on focus to pick up edits made on the device. The+ // local IPC path stays off-focus β its scan is cheap to trigger explicitly+ // and the desktop already sees its own filesystem.+ { revalidateOnFocus: isRemote, shouldRetryOnError: false },+ );+};