From 0795e55f0e7d2f2822bcd83eaf066eb99c67f858 Mon Sep 17 00:00:00 2001 From: Tolik Malibroda <54813212+tolikmalibroda@users.noreply.github.com> Date: Mon, 2 Jun 2025 22:05:45 +0200 Subject: feat: Add --yolo mode that automatically accepts all tools executions (#695) Co-authored-by: N. Taylor Mullen --- .../cli/src/ui/hooks/useAutoAcceptIndicator.ts | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts') diff --git a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts index 5af1783b..aaa1dc68 100644 --- a/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts +++ b/packages/cli/src/ui/hooks/useAutoAcceptIndicator.ts @@ -6,7 +6,7 @@ import { useState, useEffect } from 'react'; import { useInput } from 'ink'; -import type { Config } from '@gemini-code/core'; +import { ApprovalMode, type Config } from '@gemini-code/core'; export interface UseAutoAcceptIndicatorArgs { config: Config; @@ -14,8 +14,8 @@ export interface UseAutoAcceptIndicatorArgs { export function useAutoAcceptIndicator({ config, -}: UseAutoAcceptIndicatorArgs): boolean { - const currentConfigValue = config.getAlwaysSkipModificationConfirmation(); +}: UseAutoAcceptIndicatorArgs): ApprovalMode { + const currentConfigValue = config.getApprovalMode(); const [showAutoAcceptIndicator, setShowAutoAcceptIndicator] = useState(currentConfigValue); @@ -23,15 +23,25 @@ export function useAutoAcceptIndicator({ setShowAutoAcceptIndicator(currentConfigValue); }, [currentConfigValue]); - useInput((_input, key) => { - if (key.tab && key.shift) { - const alwaysAcceptModificationConfirmations = - !config.getAlwaysSkipModificationConfirmation(); - config.setAlwaysSkipModificationConfirmation( - alwaysAcceptModificationConfirmations, - ); + useInput((input, key) => { + let nextApprovalMode: ApprovalMode | undefined; + + if (key.ctrl && input === 'y') { + nextApprovalMode = + config.getApprovalMode() === ApprovalMode.YOLO + ? ApprovalMode.DEFAULT + : ApprovalMode.YOLO; + } else if (key.tab && key.shift) { + nextApprovalMode = + config.getApprovalMode() === ApprovalMode.AUTO_EDIT + ? ApprovalMode.DEFAULT + : ApprovalMode.AUTO_EDIT; + } + + if (nextApprovalMode) { + config.setApprovalMode(nextApprovalMode); // Update local state immediately for responsiveness - setShowAutoAcceptIndicator(alwaysAcceptModificationConfirmations); + setShowAutoAcceptIndicator(nextApprovalMode); } }); -- cgit v1.2.3