fix(notification): use permission.asked and main-session fallback
This commit is contained in:
parent
931c0cd101
commit
f265e37cbc
@ -78,7 +78,7 @@ describe("session-notification input-needed events", () => {
|
|||||||
|
|
||||||
await hook({
|
await hook({
|
||||||
event: {
|
event: {
|
||||||
type: "permission.ask",
|
type: "permission.asked",
|
||||||
properties: {
|
properties: {
|
||||||
sessionID,
|
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 === "ask_user_question"
|
||||||
|| normalizedToolName === "askuserquestion"
|
|| normalizedToolName === "askuserquestion"
|
||||||
) {
|
) {
|
||||||
|
const sessionID = input.sessionID || getMainSessionID()
|
||||||
await hooks.sessionNotification?.({
|
await hooks.sessionNotification?.({
|
||||||
event: {
|
event: {
|
||||||
type: "tool.execute.before",
|
type: "tool.execute.before",
|
||||||
properties: {
|
properties: {
|
||||||
sessionID: input.sessionID,
|
sessionID,
|
||||||
tool: input.tool,
|
tool: input.tool,
|
||||||
args: output.args,
|
args: output.args,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user