fix(#6392): latest prompt being reloaded when ending a persistent process (#6857)

Co-authored-by: jacob314 <jacob314@gmail.com>
This commit is contained in:
HugoMurillo
2025-08-26 12:01:31 -06:00
committed by GitHub
parent d340ddae62
commit cf9de689c3
2 changed files with 99 additions and 6 deletions

View File

@@ -5,9 +5,22 @@
*/
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
import type { DOMElement } from 'ink';
import { Box, measureElement, Static, Text, useStdin, useStdout } from 'ink';
import { StreamingState, type HistoryItem, MessageType } from './types.js';
import {
Box,
type DOMElement,
measureElement,
Static,
Text,
useStdin,
useStdout,
} from 'ink';
import {
StreamingState,
type HistoryItem,
MessageType,
ToolCallStatus,
type HistoryItemWithoutId,
} from './types.js';
import { useTerminalSize } from './hooks/useTerminalSize.js';
import { useGeminiStream } from './hooks/useGeminiStream.js';
import { useLoadingIndicator } from './hooks/useLoadingIndicator.js';
@@ -102,6 +115,17 @@ interface AppProps {
version: string;
}
function isToolExecuting(pendingHistoryItems: HistoryItemWithoutId[]) {
return pendingHistoryItems.some((item) => {
if (item && item.type === 'tool_group') {
return item.tools.some(
(tool) => ToolCallStatus.Executing === tool.status,
);
}
return false;
});
}
export const AppWrapper = (props: AppProps) => {
const kittyProtocolStatus = useKittyKeyboardProtocol();
return (
@@ -564,6 +588,11 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
() => cancelHandlerRef.current(),
);
const pendingHistoryItems = useMemo(
() => [...pendingSlashCommandHistoryItems, ...pendingGeminiHistoryItems],
[pendingSlashCommandHistoryItems, pendingGeminiHistoryItems],
);
// Message queue for handling input during streaming
const { messageQueue, addMessage, clearQueue, getQueuedMessagesText } =
useMessageQueue({
@@ -573,6 +602,11 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
// Update the cancel handler with message queue support
cancelHandlerRef.current = useCallback(() => {
if (isToolExecuting(pendingHistoryItems)) {
buffer.setText(''); // Just clear the prompt
return;
}
const lastUserMessage = userMessages.at(-1);
let textToSet = lastUserMessage || '';
@@ -586,7 +620,13 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
if (textToSet) {
buffer.setText(textToSet);
}
}, [buffer, userMessages, getQueuedMessagesText, clearQueue]);
}, [
buffer,
userMessages,
getQueuedMessagesText,
clearQueue,
pendingHistoryItems,
]);
// Input handling - queue messages for processing
const handleFinalSubmit = useCallback(
@@ -622,8 +662,6 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
);
const { handleInput: vimHandleInput } = useVim(buffer, handleFinalSubmit);
const pendingHistoryItems = [...pendingSlashCommandHistoryItems];
pendingHistoryItems.push(...pendingGeminiHistoryItems);
const { elapsedTime, currentLoadingPhrase } =
useLoadingIndicator(streamingState);