Skip to content

Commit b73bc39

Browse files
authored
Merge pull request RooCodeInc#1365 from KJ7LNW/roo-fix-terminal-undefined-exit-code
refactor terminal architecture to address critical issues with the current design
2 parents 3b2d6bc + 701b5a7 commit b73bc39

34 files changed

+2160
-1503
lines changed

package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,31 @@
128128
"command": "roo-cline.addToContext",
129129
"title": "Roo Code: Add To Context",
130130
"category": "Roo Code"
131+
},
132+
{
133+
"command": "roo-cline.terminalAddToContext",
134+
"title": "Roo Code: Add Terminal Content to Context",
135+
"category": "Terminal"
136+
},
137+
{
138+
"command": "roo-cline.terminalFixCommand",
139+
"title": "Roo Code: Fix This Command",
140+
"category": "Terminal"
141+
},
142+
{
143+
"command": "roo-cline.terminalExplainCommand",
144+
"title": "Roo Code: Explain This Command",
145+
"category": "Terminal"
146+
},
147+
{
148+
"command": "roo-cline.terminalFixCommandInCurrentTask",
149+
"title": "Roo Code: Fix This Command (Current Task)",
150+
"category": "Terminal"
151+
},
152+
{
153+
"command": "roo-cline.terminalExplainCommandInCurrentTask",
154+
"title": "Roo Code: Explain This Command (Current Task)",
155+
"category": "Terminal"
131156
}
132157
],
133158
"menus": {
@@ -153,6 +178,28 @@
153178
"group": "Roo Code@4"
154179
}
155180
],
181+
"terminal/context": [
182+
{
183+
"command": "roo-cline.terminalAddToContext",
184+
"group": "Roo Code@1"
185+
},
186+
{
187+
"command": "roo-cline.terminalFixCommand",
188+
"group": "Roo Code@2"
189+
},
190+
{
191+
"command": "roo-cline.terminalExplainCommand",
192+
"group": "Roo Code@3"
193+
},
194+
{
195+
"command": "roo-cline.terminalFixCommandInCurrentTask",
196+
"group": "Roo Code@5"
197+
},
198+
{
199+
"command": "roo-cline.terminalExplainCommandInCurrentTask",
200+
"group": "Roo Code@6"
201+
}
202+
],
156203
"view/title": [
157204
{
158205
"command": "roo-cline.plusButtonClicked",

src/activate/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { handleUri } from "./handleUri"
22
export { registerCommands } from "./registerCommands"
33
export { registerCodeActions } from "./registerCodeActions"
44
export { createRooCodeAPI } from "./createRooCodeAPI"
5+
export { registerTerminalActions } from "./registerTerminalActions"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import * as vscode from "vscode"
2+
import { ClineProvider } from "../core/webview/ClineProvider"
3+
import { Terminal } from "../integrations/terminal/Terminal"
4+
5+
const TERMINAL_COMMAND_IDS = {
6+
ADD_TO_CONTEXT: "roo-cline.terminalAddToContext",
7+
FIX: "roo-cline.terminalFixCommand",
8+
FIX_IN_CURRENT_TASK: "roo-cline.terminalFixCommandInCurrentTask",
9+
EXPLAIN: "roo-cline.terminalExplainCommand",
10+
EXPLAIN_IN_CURRENT_TASK: "roo-cline.terminalExplainCommandInCurrentTask",
11+
} as const
12+
13+
export const registerTerminalActions = (context: vscode.ExtensionContext) => {
14+
registerTerminalAction(context, TERMINAL_COMMAND_IDS.ADD_TO_CONTEXT, "TERMINAL_ADD_TO_CONTEXT")
15+
16+
registerTerminalActionPair(context, TERMINAL_COMMAND_IDS.FIX, "TERMINAL_FIX", "What would you like Roo to fix?")
17+
18+
registerTerminalActionPair(
19+
context,
20+
TERMINAL_COMMAND_IDS.EXPLAIN,
21+
"TERMINAL_EXPLAIN",
22+
"What would you like Roo to explain?",
23+
)
24+
}
25+
26+
const registerTerminalAction = (
27+
context: vscode.ExtensionContext,
28+
command: string,
29+
promptType: "TERMINAL_ADD_TO_CONTEXT" | "TERMINAL_FIX" | "TERMINAL_EXPLAIN",
30+
inputPrompt?: string,
31+
) => {
32+
context.subscriptions.push(
33+
vscode.commands.registerCommand(command, async (args: any) => {
34+
let content = args.selection
35+
if (!content || content === "") {
36+
content = await Terminal.getTerminalContents(promptType === "TERMINAL_ADD_TO_CONTEXT" ? -1 : 1)
37+
}
38+
39+
if (!content) {
40+
vscode.window.showWarningMessage("No terminal content selected")
41+
return
42+
}
43+
44+
const params: Record<string, any> = {
45+
terminalContent: content,
46+
}
47+
48+
if (inputPrompt) {
49+
params.userInput =
50+
(await vscode.window.showInputBox({
51+
prompt: inputPrompt,
52+
})) ?? ""
53+
}
54+
55+
await ClineProvider.handleTerminalAction(command, promptType, params)
56+
}),
57+
)
58+
}
59+
60+
const registerTerminalActionPair = (
61+
context: vscode.ExtensionContext,
62+
baseCommand: string,
63+
promptType: "TERMINAL_ADD_TO_CONTEXT" | "TERMINAL_FIX" | "TERMINAL_EXPLAIN",
64+
inputPrompt?: string,
65+
) => {
66+
// Register new task version
67+
registerTerminalAction(context, baseCommand, promptType, inputPrompt)
68+
// Register current task version
69+
registerTerminalAction(context, `${baseCommand}InCurrentTask`, promptType, inputPrompt)
70+
}

0 commit comments

Comments
 (0)