fix(notification): use permission.asked and main-session fallback
This commit is contained in:
@@ -78,7 +78,7 @@ describe("session-notification input-needed events", () => {
|
||||
|
||||
await hook({
|
||||
event: {
|
||||
type: "permission.ask",
|
||||
type: "permission.asked",
|
||||
properties: {
|
||||
sessionID,
|
||||
},
|
||||
|
||||
33
src/plugin/tool-execute-before-session-notification.test.ts
Normal file
33
src/plugin/tool-execute-before-session-notification.test.ts
Normal 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 {}
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user