@devries-cameron20 / t3code Mirror · read-only / commits / 48a64a8b68
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 08:30 UTC

feat(web): make terminal close confirmation optional (#35305)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Jake Leventhal committed Nov 17, 2026 at 01:41 UTC 48a64a8b68c0783d7028b72a4569cf1055de475d
9 files changed +159 -14
apps/web/src/components/ThreadTerminalDrawer.browser.test.tsx
+2
@@ -208,6 +208,8 @@ vi.mock("../hooks/useSettings", async () => {
208 return {
209 useClientSettings: <T,>(select: (settings: typeof DEFAULT_CLIENT_SETTINGS) => T) =>
210 select(DEFAULT_CLIENT_SETTINGS),
211 + ensureClientSettingsHydrated: async () => {},
212 + getClientSettings: () => DEFAULT_CLIENT_SETTINGS,
213 };
214 });
215
apps/web/src/components/settings/SettingsPanels.tsx
+29
@@ -583,6 +583,9 @@ export function useSettingsRestore(onRestored?: () => void) {
583 ...(settings.confirmThreadArchive !== DEFAULT_UNIFIED_SETTINGS.confirmThreadArchive
584 ? ["Archive confirmation"]
585 : []),
586 + ...(settings.confirmTerminalClose !== DEFAULT_UNIFIED_SETTINGS.confirmTerminalClose
587 + ? ["Terminal close confirmation"]
588 + : []),
589 ...(settings.confirmThreadDelete !== DEFAULT_UNIFIED_SETTINGS.confirmThreadDelete
590 ? ["Delete confirmation"]
591 : []),
@@ -696,6 +699,7 @@ export function useSettingsRestore(onRestored?: () => void) {
699 addProjectBaseDirectory: DEFAULT_UNIFIED_SETTINGS.addProjectBaseDirectory,
700 ghqCloneLayout: DEFAULT_UNIFIED_SETTINGS.ghqCloneLayout,
701 confirmThreadArchive: DEFAULT_UNIFIED_SETTINGS.confirmThreadArchive,
702 + confirmTerminalClose: DEFAULT_UNIFIED_SETTINGS.confirmTerminalClose,
703 confirmThreadDelete: DEFAULT_UNIFIED_SETTINGS.confirmThreadDelete,
704 confirmThreadUnpin: DEFAULT_UNIFIED_SETTINGS.confirmThreadUnpin,
705 confirmQuit: DEFAULT_UNIFIED_SETTINGS.confirmQuit,
@@ -1010,6 +1014,31 @@ export function GeneralSettingsPanel() {
1014 />
1015 }
1016 />
1017 + <SettingsRow
1018 + {...setting("terminal-close-confirmation")}
1019 + description={<T>Ask before closing terminals and stopping their running processes.</T>}
1020 + resetAction={
1021 + settings.confirmTerminalClose !== DEFAULT_UNIFIED_SETTINGS.confirmTerminalClose ? (
1022 + <SettingResetButton
1023 + label="terminal close confirmation"
1024 + onClick={() =>
1025 + updateSettings({
1026 + confirmTerminalClose: DEFAULT_UNIFIED_SETTINGS.confirmTerminalClose,
1027 + })
1028 + }
1029 + />
1030 + ) : null
1031 + }
1032 + control={
1033 + <Switch
1034 + checked={settings.confirmTerminalClose}
1035 + onCheckedChange={(checked) =>
1036 + updateSettings({ confirmTerminalClose: Boolean(checked) })
1037 + }
1038 + aria-label={gt("Confirm terminal closing")}
1039 + />
1040 + }
1041 + />
1042 {isElectron ? (
1043 <SettingsRow
1044 {...setting("quit-confirmation")}
apps/web/src/components/settings/settingsSearch.ts
+6
@@ -852,6 +852,12 @@ export const SETTINGS_SEARCH_ITEMS = [
852 to: "/settings/general",
853 searchTerms: ["ask before thread chat history"],
854 },
855 + {
856 + id: "terminal-close-confirmation",
857 + title: msg("Terminal close confirmation"),
858 + to: "/settings/general",
859 + searchTerms: ["ask before delete stop process shell console history"],
860 + },
861 {
862 id: "quit-confirmation",
863 title: msg("Quit shortcut"),
apps/web/src/hooks/useRightPanelSurfaceClose.browser.test.tsx
+27 -11
@@ -68,7 +68,7 @@ vi.mock("@t3tools/client-runtime/state/runtime", () => ({
68 isAtomCommandInterrupted: () => false,
69 }));
70
71 -function setup() {
71 +function setup(mode: "single" | "all") {
72 fixture.allowed = new Set(["environment-a", "environment-b"]);
73 fixture.sessions = new Map();
74 fixture.failClose = false;
@@ -94,22 +94,32 @@ function setup() {
94 });
95 fixture.confirm = () => confirmation;
96 function Harness({ threadRef }: { threadRef: ScopedThreadRef }) {
97 - const { closeSurface } = useRightPanelSurfaceClose({
97 + const { closeSurface, closeAllSurfaces } = useRightPanelSurfaceClose({
98 threadRef,
99 terminalLabelsById: new Map(),
100 });
101 - return <button onClick={() => closeSurface(surface)}>Close original terminal</button>;
101 + return (
102 + <button onClick={() => (mode === "all" ? closeAllSurfaces() : closeSurface(surface))}>
103 + Close original terminal
104 + </button>
105 + );
106 }
107 return { original, other, Harness, resolve };
108 }
109
106 -it.each([false, true])(
107 - "keeps a pending close on its original environment and thread, fallback=%s",
108 - async (failClose) => {
109 - const { original, other, Harness, resolve } = setup();
110 +it.each([
111 + { mode: "single", failClose: false },
112 + { mode: "single", failClose: true },
113 + { mode: "all", failClose: false },
114 + { mode: "all", failClose: true },
115 +] as const)(
116 + "keeps a pending $mode close on its original environment and thread, fallback=$failClose",
117 + async ({ mode, failClose }) => {
118 + const { original, other, Harness, resolve } = setup(mode);
119 fixture.failClose = failClose;
120 await using screen = await render(<Harness threadRef={original} />);
121 await screen.getByRole("button").click();
122 + expect(fixture.sessions.size).toBe(2);
123 await screen.rerender(<Harness threadRef={other} />);
124 await act(async () => {
125 resolve(true);
@@ -123,12 +133,18 @@ it.each([false, true])(
133 },
134 );
135
126 -it.each(["cancel", "revoked"])(
127 - "leaves both sessions intact when confirmation is %s",
128 - async (outcome) => {
129 - const { original, other, Harness, resolve } = setup();
136 +it.each([
137 + { mode: "single", outcome: "cancel" },
138 + { mode: "single", outcome: "revoked" },
139 + { mode: "all", outcome: "cancel" },
140 + { mode: "all", outcome: "revoked" },
141 +] as const)(
142 + "leaves both sessions intact when $mode confirmation is $outcome",
143 + async ({ mode, outcome }) => {
144 + const { original, other, Harness, resolve } = setup(mode);
145 await using screen = await render(<Harness threadRef={original} />);
146 await screen.getByRole("button").click();
147 + expect(fixture.sessions.size).toBe(2);
148 await screen.rerender(<Harness threadRef={other} />);
149 if (outcome === "revoked") fixture.allowed.delete(original.environmentId);
150 await act(async () => {
apps/web/src/hooks/useRightPanelSurfaceClose.ts
+15 -1
@@ -131,7 +131,21 @@ export function useRightPanelSurfaceClose(input: {
131 terminalLabelsById.get(terminalId) ?? getTerminalLabel(terminalId);
132 const closeSurfaces = (toClose: readonly RightPanelSurface[]) => {
133 if (!threadRef) return;
134 - closeAfterAgentBrowserConfirmation(toClose, () => finishClose(toClose));
134 + closeAfterAgentBrowserConfirmation(toClose, () => {
135 + const labels = readEnvironmentScope(threadRef.environmentId, AuthTerminalOperateScope)
136 + ? toClose.flatMap((surface) =>
137 + surface.kind === "terminal" ? surface.terminalIds.map(labelFor) : [],
138 + )
139 + : [];
140 + const [first, ...rest] = labels;
141 + if (first === undefined) {
142 + finishClose(toClose);
143 + return;
144 + }
145 + void confirmTerminalClose([first, ...rest]).then((confirmed) => {
146 + if (confirmed) finishClose(toClose);
147 + });
148 + });
149 };
150
151 const closeSurface = useStableCallback((surface: RightPanelSurface) => {
apps/web/src/lib/terminalCloseConfirm.test.ts
+62 -2
@@ -1,6 +1,6 @@
1 import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2
3 -const { confirmMock, readLocalApiMock } = vi.hoisted(() => {
3 +const { confirmMock, readLocalApiMock, settingsMock, hydrateMock } = vi.hoisted(() => {
4 const confirmMock = vi.fn<(message: string, options?: unknown) => Promise<boolean>>();
5 const readLocalApiMock = vi.fn<
6 () =>
@@ -9,9 +9,19 @@ const { confirmMock, readLocalApiMock } = vi.hoisted(() => {
9 }
10 | undefined
11 >();
12 - return { confirmMock, readLocalApiMock };
12 + return {
13 + confirmMock,
14 + readLocalApiMock,
15 + settingsMock: { confirmTerminalClose: true },
16 + hydrateMock: vi.fn<() => Promise<void>>(),
17 + };
18 });
19
20 +vi.mock("~/hooks/useSettings", () => ({
21 + getClientSettings: () => settingsMock,
22 + ensureClientSettingsHydrated: () => hydrateMock(),
23 +}));
24 +
25 vi.mock("~/localApi", () => ({
26 readLocalApi: () => readLocalApiMock(),
27 }));
@@ -20,11 +30,60 @@ import { confirmTerminalClose, isTerminalCloseConfirmPending } from "./terminalC
30
31 describe("terminal close confirmation", () => {
32 beforeEach(() => {
33 + settingsMock.confirmTerminalClose = true;
34 + hydrateMock.mockReset();
35 + hydrateMock.mockResolvedValue(undefined);
36 confirmMock.mockReset();
37 readLocalApiMock.mockReset();
38 readLocalApiMock.mockReturnValue({ dialogs: { confirm: confirmMock } });
39 });
40
41 + it("closes single and multiple terminals immediately when confirmation is disabled", async () => {
42 + settingsMock.confirmTerminalClose = false;
43 +
44 + await expect(confirmTerminalClose(["Terminal 1"])).resolves.toBe(true);
45 + await expect(confirmTerminalClose(["Terminal 1", "Terminal 2"])).resolves.toBe(true);
46 + expect(confirmMock).not.toHaveBeenCalled();
47 + expect(isTerminalCloseConfirmPending()).toBe(false);
48 +
49 + settingsMock.confirmTerminalClose = true;
50 + confirmMock.mockResolvedValue(false);
51 + await expect(confirmTerminalClose(["Terminal 1"])).resolves.toBe(false);
52 + expect(confirmMock).toHaveBeenCalledOnce();
53 + });
54 +
55 + it("waits for the saved opt-out before closing immediately after reload", async () => {
56 + let finishHydration: () => void = () => undefined;
57 + hydrateMock.mockImplementation(
58 + () =>
59 + new Promise<void>((resolve) => {
60 + finishHydration = () => {
61 + settingsMock.confirmTerminalClose = false;
62 + resolve();
63 + };
64 + }),
65 + );
66 +
67 + const close = confirmTerminalClose(["Terminal 1"]);
68 + expect(isTerminalCloseConfirmPending()).toBe(true);
69 + expect(confirmMock).not.toHaveBeenCalled();
70 +
71 + finishHydration();
72 + await expect(close).resolves.toBe(true);
73 + expect(confirmMock).not.toHaveBeenCalled();
74 + expect(isTerminalCloseConfirmPending()).toBe(false);
75 + });
76 +
77 + it("asks for confirmation when saved settings cannot be loaded", async () => {
78 + settingsMock.confirmTerminalClose = false;
79 + hydrateMock.mockRejectedValue(new Error("storage unavailable"));
80 + confirmMock.mockResolvedValue(false);
81 +
82 + await expect(confirmTerminalClose(["Terminal 1"])).resolves.toBe(false);
83 + expect(confirmMock).toHaveBeenCalledOnce();
84 + expect(isTerminalCloseConfirmPending()).toBe(false);
85 + });
86 +
87 it("clears pending state and resolves false when the dialog rejects", async () => {
88 let reject: (reason?: unknown) => void = () => undefined;
89 confirmMock.mockImplementation(
@@ -37,6 +96,7 @@ describe("terminal close confirmation", () => {
96 const confirmation = confirmTerminalClose(["Terminal 1"]);
97 expect(isTerminalCloseConfirmPending()).toBe(true);
98
99 + await hydrateMock.mock.results[0]!.value;
100 reject(new Error("dialog failed"));
101 await expect(confirmation).resolves.toBe(false);
102 expect(isTerminalCloseConfirmPending()).toBe(false);
apps/web/src/lib/terminalCloseConfirm.ts
+10
@@ -1,7 +1,9 @@
1 +import { ensureClientSettingsHydrated, getClientSettings } from "~/hooks/useSettings";
2 import { readLocalApi } from "~/localApi";
3
4 let pendingConfirmations = 0;
5
6 +/** Whether a terminal-close action is waiting on settings or user confirmation. */
7 export function isTerminalCloseConfirmPending(): boolean {
8 return pendingConfirmations > 0;
9 }
@@ -13,6 +15,14 @@ export async function confirmTerminalClose(
15 if (!localApi) return true;
16 pendingConfirmations += 1;
17 try {
18 + let shouldConfirm = true;
19 + try {
20 + await ensureClientSettingsHydrated();
21 + shouldConfirm = getClientSettings().confirmTerminalClose;
22 + } catch {
23 + // If saved settings cannot be read, keep the destructive confirmation.
24 + }
25 + if (!shouldConfirm) return true;
26 return await localApi.dialogs.confirm(
27 labels.length === 1
28 ? [
packages/contracts/src/settings.test.ts
+6
@@ -129,6 +129,12 @@ describe("storage cleanup settings", () => {
129 });
130 });
131
132 +describe("ClientSettings terminal close confirmation", () => {
133 + it("keeps confirmation enabled for settings without a saved preference", () => {
134 + expect(decodeClientSettings({}).confirmTerminalClose).toBe(true);
135 + });
136 +});
137 +
138 describe("ServerSettings usage price overrides", () => {
139 const prices = { inputCostPerMillionTokens: 2, outputCostPerMillionTokens: 8 };
140
packages/contracts/src/settings.ts
+2
@@ -469,6 +469,7 @@ export const ClientSettingsSchema = Schema.Struct({
469 Schema.withDecodingDefault(Effect.succeed(DEFAULT_QUIT_CONFIRMATION_MODE)),
470 ),
471 confirmThreadArchive: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
472 + confirmTerminalClose: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
473 confirmThreadDelete: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
474 confirmThreadUnpin: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
475 diffFilesCollapsed: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
@@ -2067,6 +2068,7 @@ export const ClientSettingsPatch = Schema.Struct({
2068 browserDefaultProfileId: Schema.optionalKey(BrowserProfileId),
2069 confirmQuit: Schema.optionalKey(QuitConfirmationMode),
2070 confirmThreadArchive: Schema.optionalKey(Schema.Boolean),
2071 + confirmTerminalClose: Schema.optionalKey(Schema.Boolean),
2072 confirmThreadDelete: Schema.optionalKey(Schema.Boolean),
2073 confirmThreadUnpin: Schema.optionalKey(Schema.Boolean),
2074 diffFilesCollapsed: Schema.optionalKey(Schema.Boolean),