diff --git a/packages/app/src/components/prompt-input/submit.test.ts b/packages/app/src/components/prompt-input/submit.test.ts index b3201b3ef68a..b31c733061e7 100644 --- a/packages/app/src/components/prompt-input/submit.test.ts +++ b/packages/app/src/components/prompt-input/submit.test.ts @@ -13,6 +13,7 @@ const sessionCreateInputs: Array<{ location?: { directory: string } }> = [] const enabledAutoAccept: Array<{ server: string; sessionID: string; directory: string }> = [] +const directoryAutoAccept = new Set() const optimistic: Array<{ directory?: string sessionID?: string @@ -163,6 +164,9 @@ beforeAll(async () => { enableAutoAccept(sessionID: string, directory: string) { enabledAutoAccept.push({ server, sessionID, directory }) }, + isAutoAcceptingDirectory(directory: string) { + return directoryAutoAccept.has(directory) + }, }) return { usePermission: () => ({ currentServerState: () => state(permissionServer) }) } }) @@ -283,6 +287,7 @@ beforeEach(() => { createdSessions.length = 0 sessionCreateInputs.length = 0 enabledAutoAccept.length = 0 + directoryAutoAccept.clear() optimistic.length = 0 optimisticSeeded.length = 0 promoted.length = 0 @@ -359,6 +364,33 @@ describe("prompt submit worktree selection", () => { expect(syncedDirectories).toEqual(["/repo/worktree-a", "/repo/worktree-a", "/repo/worktree-b", "/repo/worktree-b"]) }) + test("applies settings directory auto-accept to new sessions when the prompt toggle is off", async () => { + directoryAutoAccept.add("/repo/main") + const submit = createPromptSubmit({ + prompt, + info: () => undefined, + imageAttachments: () => [], + commentCount: () => 0, + autoAccept: () => false, + mode: () => "shell", + working: () => false, + editor: () => undefined, + queueScroll: () => undefined, + promptLength: (value) => value.reduce((sum, part) => sum + ("content" in part ? part.content.length : 0), 0), + addToHistory: () => undefined, + resetHistoryNavigation: () => undefined, + setMode: () => undefined, + setPopover: () => undefined, + newSessionWorktree: () => "main", + onNewSessionWorktreeReset: () => undefined, + onSubmit: () => undefined, + }) + + await submit.handleSubmit({ preventDefault: () => undefined } as unknown as Event) + + expect(enabledAutoAccept).toEqual([{ server: "server-a", sessionID: "session-1", directory: "/repo/main" }]) + }) + test("applies auto-accept to newly created sessions", async () => { const submit = createPromptSubmit({ prompt, diff --git a/packages/app/src/components/prompt-input/submit.ts b/packages/app/src/components/prompt-input/submit.ts index c82c3a439939..99c96f712be0 100644 --- a/packages/app/src/components/prompt-input/submit.ts +++ b/packages/app/src/components/prompt-input/submit.ts @@ -353,7 +353,9 @@ export function createPromptSubmit(input: PromptSubmitInput) { const projectDirectory = sdk().directory const permissionState = permission.currentServerState() const isNewSession = !params.id - const shouldAutoAccept = isNewSession && input.autoAccept() + const shouldAutoAccept = + isNewSession && + (input.autoAccept() || permissionState.isAutoAcceptingDirectory(projectDirectory)) const worktreeSelection = input.newSessionWorktree?.() || "main" let sessionDirectory = projectDirectory