Lightweight coding agent that runs in your terminal
Rust
feat: allow switching approval modes when prompted to approve an edit/command (#400)
Scott Leibrand9eeb78e54f6d
diff --git a/codex-cli/src/components/chat/terminal-chat-command-review.tsx b/codex-cli/src/components/chat/terminal-chat-command-review.tsxindex 124178b0e1..eadb9071ae 100644--- a/codex-cli/src/components/chat/terminal-chat-command-review.tsx+++ b/codex-cli/src/components/chat/terminal-chat-command-review.tsx@@ -15,11 +15,18 @@ const DEFAULT_DENY_MESSAGE =export function TerminalChatCommandReview({confirmationPrompt,onReviewCommand,+ // callback to switch approval mode overlay+ onSwitchApprovalMode,explanation: propExplanation,+ // whether this review Select is active (listening for keys)+ isActive = true,}: {confirmationPrompt: React.ReactNode;onReviewCommand: (decision: ReviewDecision, customMessage?: string) => void;+ onSwitchApprovalMode: () => void;explanation?: string;+ // when false, disable the underlying Select so it won't capture input+ isActive?: boolean;}): React.ReactElement {const [mode, setMode] = React.useState<"select" | "input" | "explanation">("select",@@ -70,6 +77,7 @@ export function TerminalChatCommandReview({const opts: Array<| { label: string; value: ReviewDecision }| { label: string; value: "edit" }+ | { label: string; value: "switch" }> = [{label: "Yes (y)",@@ -93,6 +101,11 @@ export function TerminalChatCommandReview({label: "Edit or give feedback (e)",value: "edit",},+ // allow switching approval mode+ {+ label: "Switch approval mode (s)",+ value: "switch",+ },{label: "No, and keep going (n)",value: ReviewDecision.NO_CONTINUE,@@ -106,7 +119,8 @@ export function TerminalChatCommandReview({return opts;}, [showAlwaysApprove]);- useInput((input, key) => {+ useInput(+ (input, key) => {if (mode === "select") {if (input === "y") {onReviewCommand(ReviewDecision.YES);@@ -121,6 +135,9 @@ export function TerminalChatCommandReview({);} else if (input === "a" && showAlwaysApprove) {onReviewCommand(ReviewDecision.ALWAYS);+ } else if (input === "s") {+ // switch approval mode+ onSwitchApprovalMode();} else if (key.escape) {onReviewCommand(ReviewDecision.NO_EXIT);}@@ -143,7 +160,8 @@ export function TerminalChatCommandReview({);}}- });+ }, { isActive }+ );return (<Box flexDirection="column" gap={1} borderStyle="round" marginTop={1}>@@ -191,9 +209,13 @@ export function TerminalChatCommandReview({<Text>Allow command?</Text><Box paddingX={2} flexDirection="column" gap={1}><Select- onChange={(value: ReviewDecision | "edit") => {+ isDisabled={!isActive}+ visibleOptionCount={approvalOptions.length}+ onChange={(value: ReviewDecision | "edit" | "switch") => {if (value === "edit") {setMode("input");+ } else if (value === "switch") {+ onSwitchApprovalMode();} else {onReviewCommand(value);}diff --git a/codex-cli/src/components/chat/terminal-chat-input.tsx b/codex-cli/src/components/chat/terminal-chat-input.tsxindex d032e22d17..a046a1e788 100644--- a/codex-cli/src/components/chat/terminal-chat-input.tsx+++ b/codex-cli/src/components/chat/terminal-chat-input.tsx@@ -407,7 +407,11 @@ export default function TerminalChatInput({<TerminalChatCommandReviewconfirmationPrompt={confirmationPrompt}onReviewCommand={submitConfirmation}+ // allow switching approval mode via 'v'+ onSwitchApprovalMode={openApprovalOverlay}explanation={explanation}+ // disable when input is inactive (e.g., overlay open)+ isActive={active}/>);}diff --git a/codex-cli/src/components/chat/terminal-chat-new-input.tsx b/codex-cli/src/components/chat/terminal-chat-new-input.tsxindex 948329d9f9..9ceb4bbccc 100644--- a/codex-cli/src/components/chat/terminal-chat-new-input.tsx+++ b/codex-cli/src/components/chat/terminal-chat-new-input.tsx@@ -346,7 +346,11 @@ export default function TerminalChatInput({<TerminalChatCommandReviewconfirmationPrompt={confirmationPrompt}onReviewCommand={submitConfirmation}+ // allow switching approval mode via 'v'+ onSwitchApprovalMode={openApprovalOverlay}explanation={explanation}+ // disable when input is inactive (e.g., overlay open)+ isActive={active}/>);}diff --git a/codex-cli/src/components/chat/terminal-chat.tsx b/codex-cli/src/components/chat/terminal-chat.tsxindex 74112da232..c30ccd2e04 100644--- a/codex-cli/src/components/chat/terminal-chat.tsx+++ b/codex-cli/src/components/chat/terminal-chat.tsx@@ -206,6 +206,13 @@ export default function TerminalChat({}useEffect(() => {+ // Skip recreating the agent if awaiting a decision on a pending confirmation+ if (confirmationPrompt != null) {+ if (isLoggingEnabled()) {+ log("skip AgentLoop recreation due to pending confirmationPrompt");+ }+ return;+ }if (isLoggingEnabled()) {log("creating NEW AgentLoop");log(@@ -293,10 +300,12 @@ export default function TerminalChat({agentRef.current = undefined;forceUpdate(); // re‑render after teardown too};+ // We intentionally omit 'approvalPolicy' and 'confirmationPrompt' from the deps+ // so switching modes or showing confirmation dialogs doesn’t tear down the loop.+ // eslint-disable-next-line react-hooks/exhaustive-deps}, [model,config,- approvalPolicy,requestConfirmation,additionalWritableRoots,]);@@ -580,12 +589,16 @@ export default function TerminalChat({<ApprovalModeOverlaycurrentMode={approvalPolicy}onSelect={(newMode) => {- agent?.cancel();- setLoading(false);+ // update approval policy without cancelling an in-progress sessionif (newMode === approvalPolicy) {return;}+ // update statesetApprovalPolicy(newMode as ApprovalPolicy);+ // update existing AgentLoop instance+ if (agentRef.current) {+ (agentRef.current as unknown as { approvalPolicy: ApprovalPolicy }).approvalPolicy = newMode as ApprovalPolicy;+ }setItems((prev) => [...prev,{