|
1 | 1 | import { ClineMessage } from "./ExtensionMessage" |
2 | 2 |
|
| 3 | +export const COMMAND_OUTPUT_STRING = "Output:" |
| 4 | + |
3 | 5 | /** |
4 | 6 | * Combines sequences of command and command_output messages in an array of ClineMessages. |
5 | 7 | * |
@@ -27,30 +29,28 @@ export function combineCommandSequences(messages: ClineMessage[]): ClineMessage[ |
27 | 29 | for (let i = 0; i < messages.length; i++) { |
28 | 30 | if (messages[i].type === "ask" && messages[i].ask === "command") { |
29 | 31 | let combinedText = messages[i].text || "" |
30 | | - let didAddOutput = false |
31 | 32 | let j = i + 1 |
| 33 | + let previous: { type: "ask" | "say"; text: string } | undefined |
32 | 34 |
|
33 | 35 | while (j < messages.length) { |
34 | | - if (messages[j].type === "ask" && messages[j].ask === "command") { |
35 | | - // Stop if we encounter the next command. |
36 | | - break |
| 36 | + const { type, ask, say, text = "" } = messages[j] |
| 37 | + |
| 38 | + if (type === "ask" && ask === "command") { |
| 39 | + break // Stop if we encounter the next command. |
37 | 40 | } |
38 | 41 |
|
39 | | - if (messages[j].ask === "command_output" || messages[j].say === "command_output") { |
40 | | - if (!didAddOutput) { |
41 | | - // Add a newline before the first output. |
| 42 | + if (ask === "command_output" || say === "command_output") { |
| 43 | + if (!previous) { |
42 | 44 | combinedText += `\n${COMMAND_OUTPUT_STRING}` |
43 | | - didAddOutput = true |
44 | 45 | } |
45 | 46 |
|
46 | | - // Handle cases where we receive empty command_output (i.e. |
47 | | - // when extension is relinquishing control over exit command |
48 | | - // button). |
49 | | - const output = messages[j].text || "" |
| 47 | + const isDuplicate = previous && previous.type !== type && previous.text === text |
50 | 48 |
|
51 | | - if (output.length > 0) { |
52 | | - combinedText += output |
| 49 | + if (text.length > 0 && !isDuplicate) { |
| 50 | + combinedText += text |
53 | 51 | } |
| 52 | + |
| 53 | + previous = { type, text } |
54 | 54 | } |
55 | 55 |
|
56 | 56 | j++ |
@@ -109,5 +109,3 @@ export const splitCommandOutput = (text: string) => { |
109 | 109 | .join(""), |
110 | 110 | } |
111 | 111 | } |
112 | | - |
113 | | -export const COMMAND_OUTPUT_STRING = "Output:" |
0 commit comments