From 6487cc16895976ef6c983f8beca08a64addb6688 Mon Sep 17 00:00:00 2001 From: Hiroaki Mitsuyoshi <131056197+flowernotfound@users.noreply.github.com> Date: Sat, 9 Aug 2025 15:59:22 +0900 Subject: feat(chat): Add overwrite confirmation dialog to `/chat save` (#5686) Co-authored-by: Jacob Richman --- packages/cli/src/ui/hooks/slashCommandProcessor.ts | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts') diff --git a/packages/cli/src/ui/hooks/slashCommandProcessor.ts b/packages/cli/src/ui/hooks/slashCommandProcessor.ts index 9f4bbf90..ca08abb1 100644 --- a/packages/cli/src/ui/hooks/slashCommandProcessor.ts +++ b/packages/cli/src/ui/hooks/slashCommandProcessor.ts @@ -64,6 +64,11 @@ export const useSlashCommandProcessor = ( approvedCommands?: string[], ) => void; }>(null); + const [confirmationRequest, setConfirmationRequest] = useState void; + }>(null); + const [sessionShellAllowlist, setSessionShellAllowlist] = useState( new Set(), ); @@ -220,6 +225,7 @@ export const useSlashCommandProcessor = ( async ( rawQuery: PartListUnion, oneTimeShellAllowlist?: Set, + overwriteConfirmed?: boolean, ): Promise => { setIsProcessing(true); try { @@ -299,6 +305,7 @@ export const useSlashCommandProcessor = ( name: commandToExecute.name, args, }, + overwriteConfirmed, }; // If a one-time list is provided for a "Proceed" action, temporarily @@ -422,6 +429,36 @@ export const useSlashCommandProcessor = ( new Set(approvedCommands), ); } + case 'confirm_action': { + const { confirmed } = await new Promise<{ + confirmed: boolean; + }>((resolve) => { + setConfirmationRequest({ + prompt: result.prompt, + onConfirm: (resolvedConfirmed) => { + setConfirmationRequest(null); + resolve({ confirmed: resolvedConfirmed }); + }, + }); + }); + + if (!confirmed) { + addItem( + { + type: MessageType.INFO, + text: 'Operation cancelled.', + }, + Date.now(), + ); + return { type: 'handled' }; + } + + return await handleSlashCommand( + result.originalInvocation.raw, + undefined, + true, + ); + } default: { const unhandled: never = result; throw new Error( @@ -478,6 +515,7 @@ export const useSlashCommandProcessor = ( setShellConfirmationRequest, setSessionShellAllowlist, setIsProcessing, + setConfirmationRequest, ], ); @@ -487,5 +525,6 @@ export const useSlashCommandProcessor = ( pendingHistoryItems, commandContext, shellConfirmationRequest, + confirmationRequest, }; }; -- cgit v1.2.3