diff --git a/src/core/task/index.ts b/src/core/task/index.ts index 635333cf..4e281186 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -1226,9 +1226,10 @@ export class Task { process.once("completed", clearCommandState) process.once("error", clearCommandState) process - .finally(() => { - clearCommandState() - }) + // process.continue() will complete the process promise, letting exeuction continue. therefore the command should not be considered 'completed', since it could still be running in the background + // .finally(() => { + // clearCommandState() + // }) .catch(() => { clearCommandState() }) diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index d869d95c..45e6a3e9 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -18,7 +18,6 @@ import { OptionsButtons } from "@/components/chat/OptionsButtons" import TaskFeedbackButtons from "@/components/chat/TaskFeedbackButtons" import { CheckmarkControl } from "@/components/common/CheckmarkControl" import CodeBlock, { - CHAT_ROW_COLLAPSED_BG_COLOR, CHAT_ROW_EXPANDED_BG_COLOR, CODE_BLOCK_BG_COLOR, TERMINAL_CODE_BLOCK_BG_COLOR, @@ -128,7 +127,15 @@ const CommandOutput = memo( // Auto-scroll to bottom when output changes (only when showing limited output) useEffect(() => { if (!isOutputFullyExpanded && outputRef.current) { + // Direct scrollTop manipulation outputRef.current.scrollTop = outputRef.current.scrollHeight + + // Another attempt with more delay (for slower renders) to ensure scrolling works + setTimeout(() => { + if (outputRef.current) { + outputRef.current.scrollTop = outputRef.current.scrollHeight + } + }, 50) } }, [output, isOutputFullyExpanded]) @@ -260,7 +267,6 @@ export const ChatRowContent = memo( // Command output expansion state (for all messages, but only used by command messages) const [isOutputFullyExpanded, setIsOutputFullyExpanded] = useState(false) - const commandStartTimeRef = useRef(null) const prevCommandExecutingRef = useRef(false) const [cost, apiReqCancelReason, apiReqStreamingFailedMessage, retryStatus] = useMemo(() => { if (message.text != null && message.say === "api_req_started") { @@ -277,8 +283,12 @@ export const ChatRowContent = memo( : undefined const isCommandMessage = message.ask === "command" || message.say === "command" - // Simplified: A command is executing if it's a command message that hasn't completed yet and is the last message - const isCommandExecuting = isCommandMessage && isLast && !message.commandCompleted + // Check if command has output to determine if it's actually executing + const commandHasOutput = message.text?.includes(COMMAND_OUTPUT_STRING) ?? false + // A command is executing if it has output but hasn't completed yet + const isCommandExecuting = isCommandMessage && !message.commandCompleted && commandHasOutput + // A command is pending if it hasn't started (no output) and hasn't completed + const isCommandPending = isCommandMessage && isLast && !message.commandCompleted && !commandHasOutput const isCommandCompleted = isCommandMessage && message.commandCompleted === true const isMcpServerResponding = isLast && lastModifiedMessage?.say === "mcp_server_request_started" @@ -462,7 +472,16 @@ export const ChatRowContent = memo( default: return [null, null] } - }, [type, cost, apiRequestFailedMessage, isCommandExecuting, apiReqCancelReason, isMcpServerResponding, message.text]) + }, [ + type, + cost, + apiRequestFailedMessage, + isCommandExecuting, + isCommandPending, + apiReqCancelReason, + isMcpServerResponding, + message.text, + ]) const headerStyle: React.CSSProperties = { display: "flex", @@ -835,13 +854,6 @@ export const ChatRowContent = memo( } } - // Track when command starts executing (only for command messages) - useEffect(() => { - if (isCommandMessage && isCommandExecuting && commandStartTimeRef.current === null) { - commandStartTimeRef.current = Date.now() - } - }, [isCommandMessage, isCommandExecuting]) - // Reset output expansion state when command stops (completes or is cancelled) useEffect(() => { // If command was executing and now isn't, clean up @@ -866,29 +878,6 @@ export const ChatRowContent = memo( } }, [isCommandMessage, isCommandExecuting, isExpanded, onToggleExpand, message.ts]) - // Auto-collapse when command completes (only if it ran > 500ms) - useEffect(() => { - if (isCommandMessage && isCommandCompleted && isExpanded) { - // Calculate how long the command ran - const duration = commandStartTimeRef.current ? Date.now() - commandStartTimeRef.current : 0 - - // Only auto-collapse if command ran for more than 500ms - if (duration > 500) { - // Wait 1.5 seconds before auto-collapsing to let user see the completion - const timer = setTimeout(() => { - onToggleExpand(message.ts) - // Clean up the ref after auto-collapse completes - commandStartTimeRef.current = null - }, 1500) - - return () => clearTimeout(timer) - } else { - // Command was too fast, didn't auto-collapse, so clean up now - commandStartTimeRef.current = null - } - } - }, [isCommandMessage, isCommandCompleted, isExpanded, onToggleExpand, message.ts]) - if (message.ask === "command" || message.say === "command") { const splitMessage = (text: string) => { const outputIndex = text.indexOf(COMMAND_OUTPUT_STRING) @@ -924,7 +913,9 @@ export const ChatRowContent = memo( const requestsApproval = rawCommand.endsWith(COMMAND_REQ_APP_STRING) const command = requestsApproval ? rawCommand.slice(0, -COMMAND_REQ_APP_STRING.length) : rawCommand const showCancelButton = - isCommandExecuting && typeof onCancelCommand === "function" && vscodeTerminalExecutionMode === "backgroundExec" + (isCommandExecuting || isCommandPending) && + typeof onCancelCommand === "function" && + vscodeTerminalExecutionMode === "backgroundExec" // Check if this is a Cline subagent command const isSubagentCommand = command.trim().startsWith("cline ") @@ -946,22 +937,18 @@ export const ChatRowContent = memo( - - - + + + ) // Customize icon and title for subagent commands const displayIcon = isSubagentCommand ? ( - isCommandExecuting ? ( - - ) : ( - - - - ) + + + ) : ( icon ) @@ -986,27 +973,32 @@ export const ChatRowContent = memo( style={{ borderRadius: 6, border: "1px solid var(--vscode-editorGroup-border)", - overflow: "visible", - backgroundColor: isExpanded ? CHAT_ROW_EXPANDED_BG_COLOR : CHAT_ROW_COLLAPSED_BG_COLOR, + overflow: "hidden", + backgroundColor: CHAT_ROW_EXPANDED_BG_COLOR, transition: "all 0.3s ease-in-out", }}> {command && (
-
+
- {isExpanded ? ( - - {isCommandExecuting ? "Running" : "Completed"} - - ) : isSubagentCommand && subagentPrompt ? ( - - {subagentPrompt} - - ) : ( - - {command} - - )} + + {isCommandExecuting + ? "Running" + : isCommandPending + ? "Pending" + : isCommandCompleted + ? "Completed" + : "Not Executed"} +
{showCancelButton && ( @@ -1092,18 +1066,10 @@ export const ChatRowContent = memo( {vscodeTerminalExecutionMode === "backgroundExec" ? "cancel" : "stop"} )} -
)} - {isSubagentCommand && subagentPrompt && isExpanded && ( + {isSubagentCommand && subagentPrompt && (
Prompt:{" "} @@ -1113,7 +1079,7 @@ export const ChatRowContent = memo(
)} - {output.length > 0 && ( + {/* {output.length > 0 && (
- )} - {isExpanded && !isSubagentCommand && ( + )} */} + {!isSubagentCommand && (
@@ -1142,7 +1108,7 @@ export const ChatRowContent = memo( )} {output.length > 0 && ( setIsOutputFullyExpanded(!isOutputFullyExpanded)} output={output}