Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/core/tools/executeCommandTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ export async function executeCommand(

const callbacks: RooTerminalCallbacks = {
onLine: async (output: string, process: RooTerminalProcess) => {
const status: CommandExecutionStatus = { executionId, status: "output", output }
clineProvider?.postMessageToWebview({ type: "commandExecutionStatus", text: JSON.stringify(status) })
const compressed = Terminal.compressTerminalOutput(output, terminalOutputLineLimit)
cline.say("command_output", compressed)

if (runInBackground) {
return
}

try {
const { response, text, images } = await cline.ask("command_output", "")
const { response, text, images } = await cline.ask("command_output", compressed)
runInBackground = true

if (response === "messageResponse") {
Expand All @@ -170,12 +170,10 @@ export async function executeCommand(
},
onCompleted: (output: string | undefined) => {
result = Terminal.compressTerminalOutput(output ?? "", terminalOutputLineLimit)
cline.say("command_output", result)
completed = true
},
onShellExecutionStarted: (pid: number | undefined) => {
console.log(`[executeCommand] onShellExecutionStarted: ${pid}`)
const status: CommandExecutionStatus = { executionId, status: "started", pid, command }
const status: CommandExecutionStatus = { executionId, status: "running", pid }
clineProvider?.postMessageToWebview({ type: "commandExecutionStatus", text: JSON.stringify(status) })
},
onShellExecutionComplete: (details: ExitCodeDetails) => {
Expand Down
32 changes: 1 addition & 31 deletions src/integrations/terminal/ExecaTerminalProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,18 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {
this.terminal.setActiveStream(stream, subprocess.pid)

for await (const line of stream) {
if (this.aborted) {
break
}

this.fullOutput += line

const now = Date.now()

if (this.isListening && (now - this.lastEmitTime_ms > 500 || this.lastEmitTime_ms === 0)) {
if (this.isListening && (now - this.lastEmitTime_ms > 250 || this.lastEmitTime_ms === 0)) {
this.emitRemainingBufferIfListening()
this.lastEmitTime_ms = now
}

this.startHotTimer(line)
}

if (this.aborted) {
let timeoutId: NodeJS.Timeout | undefined

const kill = new Promise<void>((resolve) => {
timeoutId = setTimeout(() => {
try {
subprocess.kill("SIGKILL")
} catch (e) {}

resolve()
}, 5_000)
})

try {
await Promise.race([subprocess, kill])
} catch (error) {
console.log(
`[ExecaTerminalProcess] subprocess termination error: ${error instanceof Error ? error.message : String(error)}`,
)
}

if (timeoutId) {
clearTimeout(timeoutId)
}
}

this.emit("shell_execution_complete", { exitCode: 0 })
} catch (error) {
if (error instanceof ExecaError) {
Expand Down
8 changes: 1 addition & 7 deletions src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,8 @@ export type CustomSupportPrompts = z.infer<typeof customSupportPromptsSchema>
export const commandExecutionStatusSchema = z.discriminatedUnion("status", [
z.object({
executionId: z.string(),
status: z.literal("started"),
status: z.literal("running"),
pid: z.number().optional(),
command: z.string(),
}),
z.object({
executionId: z.string(),
status: z.literal("output"),
output: z.string(),
}),
z.object({
executionId: z.string(),
Expand Down
32 changes: 32 additions & 0 deletions src/shared/combineCommandSequences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,35 @@ export function combineCommandSequences(messages: ClineMessage[]): ClineMessage[
return msg
})
}

export const splitCommandOutput = (text: string) => {
const outputIndex = text.indexOf(COMMAND_OUTPUT_STRING)

if (outputIndex === -1) {
return { command: text, output: "" }
}

return {
command: text.slice(0, outputIndex).trim(),

output: text
.slice(outputIndex + COMMAND_OUTPUT_STRING.length)
.trim()
.split("")
.map((char) => {
switch (char) {
case "\t":
return "→ "
case "\b":
return "⌫"
case "\f":
return "⏏"
case "\v":
return "⇳"
default:
return char
}
})
.join(""),
}
}
10 changes: 8 additions & 2 deletions webview-ui/src/components/chat/ChatRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import deepEqual from "fast-deep-equal"
import { VSCodeBadge, VSCodeButton } from "@vscode/webview-ui-toolkit/react"

import { ClineApiReqInfo, ClineAskUseMcpServer, ClineMessage, ClineSayTool } from "@roo/shared/ExtensionMessage"
import { COMMAND_OUTPUT_STRING } from "@roo/shared/combineCommandSequences"
import { splitCommandOutput, COMMAND_OUTPUT_STRING } from "@roo/shared/combineCommandSequences"
import { safeJsonParse } from "@roo/shared/safeJsonParse"

import { useCopyToClipboard } from "@src/utils/clipboard"
Expand Down Expand Up @@ -979,13 +979,19 @@ export const ChatRowContent = ({
</>
)
case "command":
const { command, output } = splitCommandOutput(message.text || "")

return (
<>
<div style={headerStyle}>
{icon}
{title}
</div>
<CommandExecution executionId={message.progressStatus?.id} text={message.text} />
<CommandExecution
executionId={message.progressStatus?.id}
command={command}
output={output}
/>
</>
)
case "use_mcp_server":
Expand Down
Loading