π OpenHands: AI-Driven Development
fix(skills): load repository skills into conversations and scope skill menus to the conversation workspace (#707)
Vasco Schiavo49d73a69d7e8
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex 3313b87653..7ac02a11fa 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -117,6 +117,7 @@ describe("buildStartConversationRequest", () => {expect(payload.agent_settings.agent_context).toEqual({load_public_skills: true,load_user_skills: true,+ load_project_skills: true,});expect(payload.agent_settings.agent).toBe("CodeActAgent");expect(payload.agent_settings.enable_switch_llm_tool).toBe(true);@@ -824,6 +825,7 @@ describe("agent_settings runtime services suffix", () => {expect(payload.agent_settings.agent_context).toEqual({load_public_skills: true,load_user_skills: true,+ load_project_skills: true,});});@@ -901,6 +903,7 @@ describe("buildStartConversationRequest β ACP discriminator", () => {expect(payload.agent_settings.agent_context).toEqual({load_public_skills: true,load_user_skills: true,+ load_project_skills: true,});expect(payload.tags).toEqual({ [ACP_SERVER_TAG_KEY]: "claude-code" });});diff --git a/package-lock.json b/package-lock.jsonindex 048297e46c..cb89c9a88c 100644--- a/package-lock.json+++ b/package-lock.json@@ -13,7 +13,7 @@"@microlink/react-json-view": "1.31.20","@monaco-editor/react": "4.7.0","@openhands/extensions": "git+https://github.com/OpenHands/extensions.git#39711065f53166c52608462f60a4c8507253ce56",- "@openhands/typescript-client": "1.24.0",+ "@openhands/typescript-client": "1.24.3","@react-router/node": "7.14.2","@react-router/serve": "7.14.2","@tailwindcss/vite": "4.2.4",@@ -3454,9 +3454,9 @@}},"node_modules/@openhands/typescript-client": {- "version": "1.24.0",- "resolved": "https://registry.npmjs.org/@openhands/typescript-client/-/typescript-client-1.24.0.tgz",- "integrity": "sha512-rFKBcJ9GqvDOYBhgfaW9LYF0Ma2ehMIvLz09oo8zcPn/nZt9I/XvtdKqDslVPShxrCxWDVmKqNLQ7TKL7l+MQw==",+ "version": "1.24.3",+ "resolved": "https://registry.npmjs.org/@openhands/typescript-client/-/typescript-client-1.24.3.tgz",+ "integrity": "sha512-4w5rGbgXSnRKm6DZGedGRMWa4nIyl8/1+lEzinBIjZbdE0MD6+89EAItkk6FTvKU0jdVpoCAtmLWBP3Y/r8ORA==","license": "MIT","dependencies": {"@openrouter/sdk": "^0.12.35",diff --git a/package.json b/package.jsonindex 4901438f72..5a97f1e39f 100644--- a/package.json+++ b/package.json@@ -24,7 +24,7 @@"@microlink/react-json-view": "1.31.20","@monaco-editor/react": "4.7.0","@openhands/extensions": "git+https://github.com/OpenHands/extensions.git#39711065f53166c52608462f60a4c8507253ce56",- "@openhands/typescript-client": "1.24.0",+ "@openhands/typescript-client": "1.24.3","@react-router/node": "7.14.2","@react-router/serve": "7.14.2","@tailwindcss/vite": "4.2.4",diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex ed1a4d6e3f..6f7a3081ac 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -508,6 +508,7 @@ function buildAgentContext(agentSettings: SettingsRecord): SettingsRecord {...toRecord(agentSettings.agent_context),load_public_skills: shouldLoadPublicSkills(),load_user_skills: true,+ load_project_skills: true,...(runtimeServicesSuffix? { system_message_suffix: runtimeServicesSuffix }: {}),diff --git a/src/api/skills-service.ts b/src/api/skills-service.tsindex 0f91511c10..baa1b258c4 100644--- a/src/api/skills-service.ts+++ b/src/api/skills-service.ts@@ -6,7 +6,7 @@ import { fetchCloudSkills } from "./cloud/skills-service.api";import { getAgentServerClientOptions } from "./agent-server-client-options";class SkillsService {- static async getSkills(): Promise<SkillInfo[]> {+ static async getSkills(projectDir?: string): Promise<SkillInfo[]> {if (getActiveBackend().backend.kind === "cloud") {return fetchCloudSkills();}@@ -22,7 +22,7 @@ class SkillsService {load_user: true,load_project: true,load_org: false,- project_dir: getAgentServerWorkingDir(),+ project_dir: projectDir ?? getAgentServerWorkingDir(),});return (response.skills ?? []) as SkillInfo[];diff --git a/src/components/features/conversation-panel/skills-modal.tsx b/src/components/features/conversation-panel/skills-modal.tsxindex 16b402435a..a93242e594 100644--- a/src/components/features/conversation-panel/skills-modal.tsx+++ b/src/components/features/conversation-panel/skills-modal.tsx@@ -4,7 +4,7 @@ import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";import { ModalBody } from "#/components/shared/modals/modal-body";import { I18nKey } from "#/i18n/declaration";import { getAgentServerWorkingDir } from "#/api/agent-server-config";-import { useSkills } from "#/hooks/query/use-skills";+import { useConversationSkills } from "#/hooks/query/use-conversation-skills";import { AgentState } from "#/types/agent-state";import {groupSkillsByScope,@@ -36,13 +36,15 @@ export function SkillsModal({ onClose }: SkillsModalProps) {const [expandedAgents, setExpandedAgents] = useState<Record<string, boolean>>({},);+ // Scope the catalog to this conversation's attached workspace so the listed+ // skills match the project skills actually loaded into the conversation.const {data: skills,isLoading,isError,refetch,isRefetching,- } = useSkills();+ } = useConversationSkills();const groupedSkills = useMemo(() => (skills ? groupSkillsByScope(skills, projectDir) : null),diff --git a/src/hooks/chat/use-slash-command.ts b/src/hooks/chat/use-slash-command.tsindex a072cacdd7..a787b6d87a 100644--- a/src/hooks/chat/use-slash-command.ts+++ b/src/hooks/chat/use-slash-command.ts@@ -1,5 +1,5 @@import { useState, useCallback, useEffect, useMemo, useRef } from "react";-import { useSkills } from "#/hooks/query/use-skills";+import { useConversationSkills } from "#/hooks/query/use-conversation-skills";import { SkillInfo } from "#/types/settings";import { Microagent } from "#/api/open-hands.types";import { BUILT_IN_COMMANDS, MODEL_COMMAND } from "#/utils/constants";@@ -35,7 +35,9 @@ function getCursorOffset(element: HTMLElement): number {export const useSlashCommand = (chatInputRef: React.RefObject<HTMLDivElement | null>,) => {- const { data: skills, isLoading: isSkillsLoading } = useSkills();+ // Scope the skill catalog to this conversation's attached workspace so the+ // slash menu lists the same project skills that were loaded into it.+ const { data: skills, isLoading: isSkillsLoading } = useConversationSkills();const isCloud = useActiveBackend().backend.kind === "cloud";const { data: profilesData, isLoading: isProfilesLoading } = useLlmProfiles({enabled: !isCloud,diff --git a/src/hooks/query/use-conversation-skills.ts b/src/hooks/query/use-conversation-skills.tsnew file mode 100644index 0000000000..609e1db454--- /dev/null+++ b/src/hooks/query/use-conversation-skills.ts@@ -0,0 +1,13 @@+import { useActiveConversation } from "./use-active-conversation";+import { useSkills } from "./use-skills";++/**+ * Skills catalog scoped to the active conversation's attached workspace, so+ * the slash-command menu and skills modal list the same project skills that+ * were loaded into the conversation. Falls back to the global workspace dir+ * for "No workspace" conversations (``selected_workspace`` is null).+ */+export const useConversationSkills = () => {+ const conversation = useActiveConversation();+ return useSkills(conversation.data?.selected_workspace ?? undefined);+};diff --git a/src/hooks/query/use-skills.ts b/src/hooks/query/use-skills.tsindex af8ba5f4f5..95d634d7e0 100644--- a/src/hooks/query/use-skills.ts+++ b/src/hooks/query/use-skills.ts@@ -2,10 +2,15 @@ import { useQuery } from "@tanstack/react-query";import SkillsService from "#/api/skills-service";import { SkillInfo } from "#/types/settings";-export const useSkills = () =>+/**+ * @param projectDir Workspace root to load project skills from. Conversation+ * views pass the conversation's own workspace so the catalog matches the+ * skills loaded into that conversation; the global Skills page omits it.+ */+export const useSkills = (projectDir?: string) =>useQuery<SkillInfo[]>({- queryKey: ["skills"],- queryFn: SkillsService.getSkills,+ queryKey: ["skills", projectDir ?? null],+ queryFn: () => SkillsService.getSkills(projectDir),staleTime: 1000 * 60 * 10, // 10 minutes β skill list rarely changesrefetchOnWindowFocus: false,});