@@ -57,6 +57,20 @@ const PULSE_WIDTH = 5;
5757 /** Maximum number of committed messages rendered before older history is chunked. */
5858 const CONVERSATION_CHUNK_MESSAGES = 50;
5959
60+/** Centralized interactive quit rules for keypresses and submitted input. */
61+const QUIT_RULES: Readonly<{
62+ /** Submitted raw inputs that trigger graceful quit. */
63+ inputs: ReadonlySet<string>;
64+ /** Keypresses that always trigger graceful quit. */
65+ keysAlways: ReadonlySet<string>;
66+ /** Keypresses that trigger graceful quit only when input is empty. */
67+ keysWhenEmptyInput: ReadonlySet<string>;
68+}> = {
69+ inputs: new Set([":q"]),
70+ keysAlways: new Set(["ctrl+c"]),
71+ keysWhenEmptyInput: new Set(["ctrl+d"]),
72+};
73+
6074 // ---------------------------------------------------------------------------
6175 // UI state (module-scoped, not in AppState)
6276 // ---------------------------------------------------------------------------
@@ -92,6 +106,23 @@ let stdinWasRaw = false;
92106 /** Active overlay for interactive commands (/model, /effort, etc.). */
93107 let activeOverlay: ActiveOverlay | null = null;
94108
109+/** Determine whether a raw input line should trigger a graceful quit. */
110+export function isQuitInput(raw: string): boolean {
111+ const trimmed = raw.trim();
112+ return QUIT_RULES.inputs.has(trimmed);
113+}
114+
115+/** Determine whether a keypress should trigger a graceful quit. */
116+export function isQuitKey(key: string, input: string): boolean {
117+ if (QUIT_RULES.keysAlways.has(key)) {
118+ return true;
119+ }
120+ if (input === "" && QUIT_RULES.keysWhenEmptyInput.has(key)) {
121+ return true;
122+ }
123+ return false;
124+}
125+
95126 /**
96127 * Reset all module-scoped UI state.
97128 *
@@ -299,6 +330,14 @@ export function createInputController(state: AppState): InputController {
299330 onKeyPress: (key) => {
300331 if (key === "enter") {
301332 const raw = inputValue;
333+
334+ if (isQuitInput(raw)) {
335+ inputValue = "";
336+ cel.render();
337+ requestGracefulExit(state);
338+ return false;
339+ }
340+
302341 inputValue = "";
303342 cel.render();
304343 handleInput(raw, state);
@@ -418,6 +457,11 @@ async function gracefulExit(state: AppState): Promise<void> {
418457 process.exit(0);
419458 }
420459
460+/** Request a graceful exit and hard-fail if shutdown errors. */
461+function requestGracefulExit(state: AppState): void {
462+ gracefulExit(state).catch(() => process.exit(1));
463+}
464+
421465 /** Restore the terminal to the shell before suspending. */
422466 function suspendTerminalUi(): void {
423467 stopDividerAnimation();
@@ -539,12 +583,8 @@ export function renderBaseLayout(
539583 commandController.showInputHistoryOverlay(state);
540584 return;
541585 }
542- if (key === "ctrl+c") {
543- gracefulExit(state).catch(() => process.exit(1));
544- return;
545- }
546- if (key === "ctrl+d" && inputValue === "") {
547- gracefulExit(state).catch(() => process.exit(1));
586+ if (isQuitKey(key, inputValue)) {
587+ requestGracefulExit(state);
548588 return;
549589 }
550590 if (key === "ctrl+z") {