π OpenHands: AI-Driven Development
fix(hooks): pick the Available Hooks text by hook type (#18215)
fengyue-xvec8013777f931
diff --git a/__tests__/components/features/conversation-panel/hooks-modal.test.tsx b/__tests__/components/features/conversation-panel/hooks-modal.test.tsxindex 9b16c7a418..cf3907c758 100644--- a/__tests__/components/features/conversation-panel/hooks-modal.test.tsx+++ b/__tests__/components/features/conversation-panel/hooks-modal.test.tsx@@ -249,6 +249,70 @@ describe("HookEventItem", () => {expect(screen.getByText("Type: agent")).toBeInTheDocument();});+ it("should show an agent hook's system_prompt, not its stray prompt, when both are set", () => {+ const bothFieldsHookEvent: HookEvent = {+ event_type: "session_start",+ matchers: [+ {+ matcher: "*",+ hooks: [+ {+ type: "agent",+ command: "",+ prompt: "QA_F07 stray prompt",+ system_prompt: "QA_F07 agent system prompt",+ },+ ],+ },+ ],+ };++ const { container } = render(+ <HookEventItem+ {...defaultProps}+ hookEvent={bothFieldsHookEvent}+ isExpanded={true}+ />,+ );++ const preBlocks = container.querySelectorAll("pre");+ expect(preBlocks).toHaveLength(1);+ expect(preBlocks[0]).toHaveTextContent("QA_F07 agent system prompt");+ expect(preBlocks[0]).not.toHaveTextContent("QA_F07 stray prompt");+ expect(screen.getByText("Type: agent")).toBeInTheDocument();+ });++ it("should show no text box for an agent hook that only has a prompt", () => {+ const promptOnlyAgentHookEvent: HookEvent = {+ event_type: "stop",+ matchers: [+ {+ matcher: "*",+ hooks: [+ {+ type: "agent",+ command: "",+ prompt: "QA_F07 prompt-only agent hook",+ timeout: 60,+ },+ ],+ },+ ],+ };++ const { container } = render(+ <HookEventItem+ {...defaultProps}+ hookEvent={promptOnlyAgentHookEvent}+ isExpanded={true}+ />,+ );++ expect(container.querySelectorAll("pre")).toHaveLength(0);+ expect(screen.getByText("Type: agent")).toBeInTheDocument();+ expect(screen.getByText("Timeout: 60s")).toBeInTheDocument();+ });+it("should not render an empty box when a hook omits its text", () => {const textlessHookEvent: HookEvent = {event_type: "session_start",diff --git a/src/components/features/conversation-panel/hook-matcher-content.tsx b/src/components/features/conversation-panel/hook-matcher-content.tsxindex 6913af89a4..305193821c 100644--- a/src/components/features/conversation-panel/hook-matcher-content.tsx+++ b/src/components/features/conversation-panel/hook-matcher-content.tsx@@ -28,9 +28,14 @@ export function HookMatcherContent({ matcher }: HookMatcherContentProps) {{t(I18nKey.HOOKS_MODAL$COMMANDS)}</Typography.Text>{(matcher.hooks ?? []).map((hook, index) => {- // Prompt and agent hooks carry their text in `prompt`/`system_prompt`- // with an empty `command`; only command hooks are guaranteed a command.- const text = hook.command || hook.prompt || hook.system_prompt;+ // Pick the field each hook type runs with; an agent hook may also+ // carry a `prompt`, which it never reads.+ const text =+ hook.type === "agent"+ ? hook.system_prompt+ : hook.type === "prompt"+ ? hook.prompt+ : hook.command;return (<div key={`${text}-${index}`} className="mt-2">{text ? (