Merge pull request #253 from RooVetGit/cat_pager

Improvements to terminal output when executing commands
This commit is contained in:
Matt Rubens
2024-12-31 08:06:51 -08:00
committed by GitHub
10 changed files with 114 additions and 7 deletions

View File

@@ -721,9 +721,9 @@ export class Cline {
}
}
let result = ""
let lines: string[] = []
process.on("line", (line) => {
result += line + "\n"
lines.push(line)
if (!didContinue) {
sendCommandOutput(line)
} else {
@@ -731,6 +731,22 @@ export class Cline {
}
})
const getFormattedOutput = async () => {
const { terminalOutputLineLimit } = await this.providerRef.deref()?.getState() ?? {}
const limit = terminalOutputLineLimit ?? 0
if (limit > 0 && lines.length > limit) {
const beforeLimit = Math.floor(limit * 0.2) // 20% of lines before
const afterLimit = limit - beforeLimit // remaining 80% after
return [
...lines.slice(0, beforeLimit),
`\n[...${lines.length - limit} lines omitted...]\n`,
...lines.slice(-afterLimit)
].join('\n')
}
return lines.join('\n')
}
let completed = false
process.once("completed", () => {
completed = true
@@ -749,7 +765,8 @@ export class Cline {
// grouping command_output messages despite any gaps anyways)
await delay(50)
result = result.trim()
const output = await getFormattedOutput()
const result = output.trim()
if (userFeedback) {
await this.say("user_feedback", userFeedback.text, userFeedback.images)

View File

@@ -76,6 +76,7 @@ type GlobalStateKey =
| "fuzzyMatchThreshold"
| "preferredLanguage" // Language setting for Cline's communication
| "writeDelayMs"
| "terminalOutputLineLimit"
export const GlobalFileNames = {
apiConversationHistory: "api_conversation_history.json",
@@ -642,6 +643,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
await this.updateGlobalState("writeDelayMs", message.value)
await this.postStateToWebview()
break
case "terminalOutputLineLimit":
await this.updateGlobalState("terminalOutputLineLimit", message.value)
await this.postStateToWebview()
break
case "deleteMessage": {
const answer = await vscode.window.showInformationMessage(
"Are you sure you want to delete this message and all subsequent messages?",
@@ -1046,6 +1051,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
screenshotQuality,
preferredLanguage,
writeDelayMs,
terminalOutputLineLimit,
} = await this.getState()
const allowedCommands = vscode.workspace
@@ -1075,6 +1081,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
screenshotQuality: screenshotQuality ?? 75,
preferredLanguage: preferredLanguage ?? 'English',
writeDelayMs: writeDelayMs ?? 1000,
terminalOutputLineLimit: terminalOutputLineLimit ?? 500,
}
}
@@ -1174,6 +1181,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
preferredLanguage,
writeDelayMs,
screenshotQuality,
terminalOutputLineLimit,
] = await Promise.all([
this.getGlobalState("apiProvider") as Promise<ApiProvider | undefined>,
this.getGlobalState("apiModelId") as Promise<string | undefined>,
@@ -1218,6 +1226,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
this.getGlobalState("preferredLanguage") as Promise<string | undefined>,
this.getGlobalState("writeDelayMs") as Promise<number | undefined>,
this.getGlobalState("screenshotQuality") as Promise<number | undefined>,
this.getGlobalState("terminalOutputLineLimit") as Promise<number | undefined>,
])
let apiProvider: ApiProvider
@@ -1279,6 +1288,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
screenshotQuality: screenshotQuality ?? 75,
fuzzyMatchThreshold: fuzzyMatchThreshold ?? 1.0,
writeDelayMs: writeDelayMs ?? 1000,
terminalOutputLineLimit: terminalOutputLineLimit ?? 500,
preferredLanguage: preferredLanguage ?? (() => {
// Get VSCode's locale setting
const vscodeLang = vscode.env.language;

View File

@@ -16,8 +16,11 @@ export class TerminalRegistry {
static createTerminal(cwd?: string | vscode.Uri | undefined): TerminalInfo {
const terminal = vscode.window.createTerminal({
cwd,
name: "Cline",
iconPath: new vscode.ThemeIcon("robot"),
name: "Roo Cline",
iconPath: new vscode.ThemeIcon("rocket"),
env: {
PAGER: "cat"
}
})
const newInfo: TerminalInfo = {
terminal,

View File

@@ -0,0 +1,37 @@
import * as vscode from "vscode"
import { TerminalRegistry } from "../TerminalRegistry"
// Mock vscode.window.createTerminal
const mockCreateTerminal = jest.fn()
jest.mock("vscode", () => ({
window: {
createTerminal: (...args: any[]) => {
mockCreateTerminal(...args)
return {
exitStatus: undefined,
}
},
},
ThemeIcon: jest.fn(),
}))
describe("TerminalRegistry", () => {
beforeEach(() => {
mockCreateTerminal.mockClear()
})
describe("createTerminal", () => {
it("creates terminal with PAGER set to cat", () => {
TerminalRegistry.createTerminal("/test/path")
expect(mockCreateTerminal).toHaveBeenCalledWith({
cwd: "/test/path",
name: "Roo Cline",
iconPath: expect.any(Object),
env: {
PAGER: "cat"
}
})
})
})
})

View File

@@ -61,6 +61,7 @@ export interface ExtensionState {
fuzzyMatchThreshold?: number
preferredLanguage: string
writeDelayMs: number
terminalOutputLineLimit?: number
}
export interface ClineMessage {

View File

@@ -48,6 +48,7 @@ export interface WebviewMessage {
| "enhancedPrompt"
| "draggedImages"
| "deleteMessage"
| "terminalOutputLineLimit"
text?: string
disabled?: boolean
askResponse?: ClineAskResponse