fix(notification): use permission.asked and main-session fallback

This commit is contained in:
acamq
2026-02-21 16:42:23 -07:00
parent 931c0cd101
commit f265e37cbc
3 changed files with 36 additions and 2 deletions

View File

@@ -78,7 +78,7 @@ describe("session-notification input-needed events", () => {
await hook({
event: {
type: "permission.ask",
type: "permission.asked",
properties: {
sessionID,
},

View File

@@ -0,0 +1,33 @@
const { describe, expect, test, spyOn } = require("bun:test")
const sessionState = require("../features/claude-code-session-state")
const { createToolExecuteBeforeHandler } = require("./tool-execute-before")
describe("createToolExecuteBeforeHandler session notification sessionID", () => {
test("uses main session fallback when input sessionID is empty", async () => {
const mainSessionID = "ses_main"
const getMainSessionIDSpy = spyOn(sessionState, "getMainSessionID").mockReturnValue(mainSessionID)
let capturedSessionID: string | undefined
const hooks = {
sessionNotification: async (input) => {
capturedSessionID = input.event.properties?.sessionID
},
}
const handler = createToolExecuteBeforeHandler({
ctx: { client: { session: { messages: async () => ({ data: [] }) } } },
hooks,
})
await handler(
{ tool: "question", sessionID: "", callID: "call_q" },
{ args: { questions: [{ question: "Continue?", options: [{ label: "Yes" }] }] } },
)
expect(getMainSessionIDSpy).toHaveBeenCalled()
expect(capturedSessionID).toBe(mainSessionID)
})
})
export {}

View File

@@ -37,11 +37,12 @@ export function createToolExecuteBeforeHandler(args: {
|| normalizedToolName === "ask_user_question"
|| normalizedToolName === "askuserquestion"
) {
const sessionID = input.sessionID || getMainSessionID()
await hooks.sessionNotification?.({
event: {
type: "tool.execute.before",
properties: {
sessionID: input.sessionID,
sessionID,
tool: input.tool,
args: output.args,
},