Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down
4 changes: 3 additions & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down