diff --git a/src/hooks/openclaw.test.ts b/src/hooks/openclaw.test.ts index 958123303..db3b69a91 100644 --- a/src/hooks/openclaw.test.ts +++ b/src/hooks/openclaw.test.ts @@ -44,7 +44,7 @@ describe("createOpenClawHook", () => { await hook?.["tool.execute.before"]?.( { tool: "ask_user_question", sessionID: "session-2" }, - { args: { question: "Need approval?" } }, + { args: { questions: [{ question: "Need approval?", options: [{ label: "Yes" }] }] } }, ) expect(wakeOpenClawMock).toHaveBeenCalledWith( @@ -57,4 +57,26 @@ describe("createOpenClawHook", () => { }), ) }) + + test("falls back to args.question string when questions array absent", async () => { + const { createOpenClawHook } = await import("./openclaw") + const hook = createOpenClawHook( + { directory: "/tmp/project" } as any, + { openclaw: { enabled: true } } as any, + ) + + await hook?.["tool.execute.before"]?.( + { tool: "question", sessionID: "session-3" }, + { args: { question: "Fallback?" } }, + ) + + expect(wakeOpenClawMock).toHaveBeenCalledWith( + expect.anything(), + "ask-user-question", + expect.objectContaining({ + question: "Fallback?", + sessionId: "session-3", + }), + ) + }) }) diff --git a/src/hooks/openclaw.ts b/src/hooks/openclaw.ts index b1fb8edcb..00bce217e 100644 --- a/src/hooks/openclaw.ts +++ b/src/hooks/openclaw.ts @@ -50,7 +50,11 @@ export function createOpenClawHook( return } - const question = typeof output.args.question === "string" ? output.args.question : undefined + // question tool uses args.questions array, not args.question + const questions = Array.isArray(output.args.questions) ? output.args.questions : [] + const question = questions.length > 0 && typeof questions[0]?.question === "string" + ? questions[0].question + : typeof output.args.question === "string" ? output.args.question : undefined const context: OpenClawContext = { sessionId: input.sessionID, projectPath: ctx.directory,