summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/slashCommandProcessor.ts
diff options
context:
space:
mode:
authorHiroaki Mitsuyoshi <[email protected]>2025-08-09 15:59:22 +0900
committerGitHub <[email protected]>2025-08-09 06:59:22 +0000
commit6487cc16895976ef6c983f8beca08a64addb6688 (patch)
treee2d4d06bc37331d0c36a1c27442457d42f81d385 /packages/cli/src/ui/hooks/slashCommandProcessor.ts
parent191cc01bf5833a4c7636f8fc4d9b4c5066982822 (diff)
feat(chat): Add overwrite confirmation dialog to `/chat save` (#5686)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/hooks/slashCommandProcessor.ts')
-rw-r--r--packages/cli/src/ui/hooks/slashCommandProcessor.ts39
1 files changed, 39 insertions, 0 deletions
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<null | {
+ prompt: React.ReactNode;
+ onConfirm: (confirmed: boolean) => void;
+ }>(null);
+
const [sessionShellAllowlist, setSessionShellAllowlist] = useState(
new Set<string>(),
);
@@ -220,6 +225,7 @@ export const useSlashCommandProcessor = (
async (
rawQuery: PartListUnion,
oneTimeShellAllowlist?: Set<string>,
+ overwriteConfirmed?: boolean,
): Promise<SlashCommandProcessorResult | false> => {
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,
};
};