diff --git a/src/state.test.ts b/src/state.test.ts index 4ea72a7..1ebb7ac 100644 --- a/src/state.test.ts +++ b/src/state.test.ts @@ -252,6 +252,62 @@ describe("createStore", () => { assert.equal(session?.lastEvent, "AskUserQuestion"); }); + it("PreToolUse with Write stays running in plan mode", () => { + const store = createStore(); + store.handleEvent({ session_id: "s1", hook_event_name: "SessionStart" }); + store.handleEvent({ session_id: "s1", hook_event_name: "UserPromptSubmit" }); + const session = store.handleEvent({ + session_id: "s1", + hook_event_name: "PreToolUse", + tool_name: "Write", + permission_mode: "plan", + }); + assert.equal(session?.status, "running"); + assert.equal(session?.lastEvent, "Write"); + }); + + it("PreToolUse with Edit stays running in plan mode", () => { + const store = createStore(); + store.handleEvent({ session_id: "s1", hook_event_name: "SessionStart" }); + store.handleEvent({ session_id: "s1", hook_event_name: "UserPromptSubmit" }); + const session = store.handleEvent({ + session_id: "s1", + hook_event_name: "PreToolUse", + tool_name: "Edit", + permission_mode: "plan", + }); + assert.equal(session?.status, "running"); + assert.equal(session?.lastEvent, "Edit"); + }); + + it("PreToolUse with NotebookEdit stays running in plan mode", () => { + const store = createStore(); + store.handleEvent({ session_id: "s1", hook_event_name: "SessionStart" }); + store.handleEvent({ session_id: "s1", hook_event_name: "UserPromptSubmit" }); + const session = store.handleEvent({ + session_id: "s1", + hook_event_name: "PreToolUse", + tool_name: "NotebookEdit", + permission_mode: "plan", + }); + assert.equal(session?.status, "running"); + assert.equal(session?.lastEvent, "NotebookEdit"); + }); + + it("PreToolUse with ExitPlanMode still transitions to waiting in plan mode", () => { + const store = createStore(); + store.handleEvent({ session_id: "s1", hook_event_name: "SessionStart" }); + store.handleEvent({ session_id: "s1", hook_event_name: "UserPromptSubmit" }); + const session = store.handleEvent({ + session_id: "s1", + hook_event_name: "PreToolUse", + tool_name: "ExitPlanMode", + permission_mode: "plan", + }); + assert.equal(session?.status, "waiting"); + assert.equal(session?.lastEvent, "ExitPlanMode"); + }); + it("PreToolUse with Edit transitions to waiting in default mode", () => { const store = createStore(); store.handleEvent({ session_id: "s1", hook_event_name: "SessionStart" }); diff --git a/src/state.ts b/src/state.ts index f53a62a..4fcaa15 100644 --- a/src/state.ts +++ b/src/state.ts @@ -58,7 +58,9 @@ export function createStore(): Store { displayEvent = toolName || hook_event_name; const permissionMode = typeof payload.permission_mode === "string" ? payload.permission_mode : ""; - const isEditAutoApproved = permissionMode === "acceptEdits" && EDIT_TOOLS.has(toolName); + const isEditAutoApproved = + (permissionMode === "acceptEdits" || permissionMode === "plan") && + EDIT_TOOLS.has(toolName); status = !isEditAutoApproved && (ALWAYS_INTERACTIVE_TOOLS.has(toolName) || EDIT_TOOLS.has(toolName))