Skip to content

Commit c4f5c5f

Browse files
committed
refactor: restore parseCommandAndOutput function from main
- Extracted inline parsing logic into a separate function like in main branch - Added check to not show CommandPatternSelector for empty/whitespace commands - This maintains the same functionality while keeping the code cleaner
1 parent a18be7d commit c4f5c5f

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

webview-ui/src/components/chat/CommandExecution.tsx

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { CommandExecutionStatus, commandExecutionStatusSchema } from "@roo-code/
77
import { ExtensionMessage } from "@roo/ExtensionMessage"
88
import { safeJsonParse } from "@roo/safeJsonParse"
99

10+
import { COMMAND_OUTPUT_STRING } from "@roo/combineCommandSequences"
11+
1012
import { vscode } from "@src/utils/vscode"
1113
import { useExtensionState } from "@src/context/ExtensionStateContext"
1214
import { cn } from "@src/lib/utils"
@@ -36,30 +38,7 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
3638
setDeniedCommands,
3739
} = useExtensionState()
3840

39-
const { command, output: parsedOutput } = useMemo(() => {
40-
// Parse command and output using the "Output:" separator
41-
const outputSeparator = "Output:"
42-
const outputIndex = text?.indexOf(`\n${outputSeparator}`) ?? -1
43-
44-
if (outputIndex !== -1) {
45-
// Text is split into command and output
46-
const cmd = (text ?? "").slice(0, outputIndex).trim()
47-
// Skip the newline and "Output:" text
48-
const afterSeparator = outputIndex + 1 + outputSeparator.length
49-
let startOfOutput = afterSeparator
50-
if (text![afterSeparator] === "\n") {
51-
startOfOutput = afterSeparator + 1
52-
}
53-
const out = text!.slice(startOfOutput).trim()
54-
return { command: cmd, output: out }
55-
} else if (text?.indexOf(outputSeparator) === 0) {
56-
// Edge case: text starts with "Output:" (no command)
57-
return { command: "", output: text.slice(outputSeparator.length).trim() }
58-
} else {
59-
// No output separator found, the entire text is the command
60-
return { command: text?.trim() || "", output: "" }
61-
}
62-
}, [text])
41+
const { command, output: parsedOutput } = useMemo(() => parseCommandAndOutput(text), [text])
6342

6443
// If we aren't opening the VSCode terminal for this command then we default
6544
// to expanding the command execution output.
@@ -192,7 +171,7 @@ export const CommandExecution = ({ executionId, text, icon, title }: CommandExec
192171
<CodeBlock source={command} language="shell" />
193172
<OutputContainer isExpanded={isExpanded} output={output} />
194173
</div>
195-
{command && (
174+
{command && command.trim() && (
196175
<CommandPatternSelector
197176
command={command}
198177
patterns={commandPatterns}
@@ -220,3 +199,20 @@ const OutputContainerInternal = ({ isExpanded, output }: { isExpanded: boolean;
220199
)
221200

222201
const OutputContainer = memo(OutputContainerInternal)
202+
203+
const parseCommandAndOutput = (text: string | undefined) => {
204+
if (!text) {
205+
return { command: "", output: "" }
206+
}
207+
208+
const index = text.indexOf(COMMAND_OUTPUT_STRING)
209+
210+
if (index === -1) {
211+
return { command: text, output: "" }
212+
}
213+
214+
return {
215+
command: text.slice(0, index),
216+
output: text.slice(index + COMMAND_OUTPUT_STRING.length),
217+
}
218+
}

0 commit comments

Comments
 (0)