(props: CancelRequestHandlerProps)
| 61 | * Renders null but registers the 'chat:cancel' keybinding handler. |
| 62 | */ |
| 63 | export function CancelRequestHandler(props: CancelRequestHandlerProps): null { |
| 64 | const { |
| 65 | setToolUseConfirmQueue, |
| 66 | onCancel, |
| 67 | onAgentsKilled, |
| 68 | isMessageSelectorVisible, |
| 69 | screen, |
| 70 | abortSignal, |
| 71 | popCommandFromQueue, |
| 72 | vimMode, |
| 73 | isLocalJSXCommand, |
| 74 | isSearchingHistory, |
| 75 | isHelpOpen, |
| 76 | inputMode, |
| 77 | inputValue, |
| 78 | streamMode, |
| 79 | } = props |
| 80 | const store = useAppStateStore() |
| 81 | const setAppState = useSetAppState() |
| 82 | const queuedCommandsLength = useCommandQueue().length |
| 83 | const { addNotification, removeNotification } = useNotifications() |
| 84 | const lastKillAgentsPressRef = useRef<number>(0) |
| 85 | const viewSelectionMode = useAppState(s => s.viewSelectionMode) |
| 86 | |
| 87 | const handleCancel = useCallback(() => { |
| 88 | const cancelProps = { |
| 89 | source: |
| 90 | 'escape' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 91 | streamMode: |
| 92 | streamMode as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 93 | } |
| 94 | |
| 95 | // Priority 1: If there's an active task running, cancel it first |
| 96 | // This takes precedence over queue management so users can always interrupt Claude |
| 97 | if (abortSignal !== undefined && !abortSignal.aborted) { |
| 98 | logEvent('tengu_cancel', cancelProps) |
| 99 | setToolUseConfirmQueue(() => []) |
| 100 | onCancel() |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | // Priority 2: Pop queue when Claude is idle (no running task to cancel) |
| 105 | if (hasCommandsInQueue()) { |
| 106 | if (popCommandFromQueue) { |
| 107 | popCommandFromQueue() |
| 108 | return |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Fallback: nothing to cancel or pop (shouldn't reach here if isActive is correct) |
| 113 | logEvent('tengu_cancel', cancelProps) |
| 114 | setToolUseConfirmQueue(() => []) |
| 115 | onCancel() |
| 116 | }, [ |
| 117 | abortSignal, |
| 118 | popCommandFromQueue, |
| 119 | setToolUseConfirmQueue, |
| 120 | onCancel, |
nothing calls this directly
no test coverage detected