From ae43cd5d371f741a64be8084cb08619800757d96 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 8 Apr 2025 20:35:57 -0700 Subject: [PATCH 1/2] lang: translate Russian comments to English in vscode-lm.ts Translated all Russian comments in the cleanTerminalOutput method to their English equivalents while preserving the code's functionality. This improves code readability for English-speaking developers. Signed-off-by: Eric Wheeler --- src/api/providers/vscode-lm.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/api/providers/vscode-lm.ts b/src/api/providers/vscode-lm.ts index 0ce2a6e26a6..afdfececfa2 100644 --- a/src/api/providers/vscode-lm.ts +++ b/src/api/providers/vscode-lm.ts @@ -289,36 +289,36 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan return ( text - // Нормализуем переносы строк + // Normalize line breaks .replace(/\r\n/g, "\n") .replace(/\r/g, "\n") - // Удаляем ANSI escape sequences - .replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "") // Полный набор ANSI sequences + // Remove ANSI escape sequences + .replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "") // Complete set of ANSI sequences .replace(/\x9B[0-?]*[ -/]*[@-~]/g, "") // CSI sequences - // Удаляем последовательности установки заголовка терминала и прочие OSC sequences + // Remove terminal title setting sequences and other OSC sequences .replace(/\x1B\][0-9;]*(?:\x07|\x1B\\)/g, "") - // Удаляем управляющие символы + // Remove control characters .replace(/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F]/g, "") - // Удаляем escape-последовательности VS Code + // Remove VS Code escape sequences .replace(/\x1B[PD].*?\x1B\\/g, "") // DCS sequences .replace(/\x1B_.*?\x1B\\/g, "") // APC sequences .replace(/\x1B\^.*?\x1B\\/g, "") // PM sequences .replace(/\x1B\[[\d;]*[HfABCDEFGJKST]/g, "") // Cursor movement and clear screen - // Удаляем пути Windows и служебную информацию + // Remove Windows paths and service information .replace(/^(?:PS )?[A-Z]:\\[^\n]*$/gm, "") .replace(/^;?Cwd=.*$/gm, "") - // Очищаем экранированные последовательности + // Clean escaped sequences .replace(/\\x[0-9a-fA-F]{2}/g, "") .replace(/\\u[0-9a-fA-F]{4}/g, "") - // Финальная очистка - .replace(/\n{3,}/g, "\n\n") // Убираем множественные пустые строки + // Final cleanup + .replace(/\n{3,}/g, "\n\n") // Remove multiple empty lines .trim() ) } From 7538e12aef48cc5aa69b3c743b6a93087a373747 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 8 Apr 2025 22:52:47 -0700 Subject: [PATCH 2/2] fix: preserve content integrity in VS Code LM provider The provider was modifying system information and model responses by stripping escape sequences and performing other transformations. The issue was discovered when attempting to use escape sequences like '\x1b' in text, which were being removed by the cleanTerminalOutput method. This caused problems in scenarios where escape sequences needed to be preserved, such as when working with terminal control codes. It is not the responsibility of the provider to modify input/output to and from the model. Roo expects all communication through different providers to be clean so that it can manage transformation centrally. Signed-off-by: Eric Wheeler --- src/api/providers/vscode-lm.ts | 48 +++------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/src/api/providers/vscode-lm.ts b/src/api/providers/vscode-lm.ts index afdfececfa2..1b5f5736375 100644 --- a/src/api/providers/vscode-lm.ts +++ b/src/api/providers/vscode-lm.ts @@ -282,54 +282,13 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan return this.client } - private cleanTerminalOutput(text: string): string { - if (!text) { - return "" - } - - return ( - text - // Normalize line breaks - .replace(/\r\n/g, "\n") - .replace(/\r/g, "\n") - - // Remove ANSI escape sequences - .replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "") // Complete set of ANSI sequences - .replace(/\x9B[0-?]*[ -/]*[@-~]/g, "") // CSI sequences - - // Remove terminal title setting sequences and other OSC sequences - .replace(/\x1B\][0-9;]*(?:\x07|\x1B\\)/g, "") - - // Remove control characters - .replace(/[\x00-\x09\x0B-\x0C\x0E-\x1F\x7F]/g, "") - - // Remove VS Code escape sequences - .replace(/\x1B[PD].*?\x1B\\/g, "") // DCS sequences - .replace(/\x1B_.*?\x1B\\/g, "") // APC sequences - .replace(/\x1B\^.*?\x1B\\/g, "") // PM sequences - .replace(/\x1B\[[\d;]*[HfABCDEFGJKST]/g, "") // Cursor movement and clear screen - - // Remove Windows paths and service information - .replace(/^(?:PS )?[A-Z]:\\[^\n]*$/gm, "") - .replace(/^;?Cwd=.*$/gm, "") - - // Clean escaped sequences - .replace(/\\x[0-9a-fA-F]{2}/g, "") - .replace(/\\u[0-9a-fA-F]{4}/g, "") - - // Final cleanup - .replace(/\n{3,}/g, "\n\n") // Remove multiple empty lines - .trim() - ) - } - private cleanMessageContent(content: any): any { if (!content) { return content } if (typeof content === "string") { - return this.cleanTerminalOutput(content) + return content } if (Array.isArray(content)) { @@ -352,8 +311,7 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan this.ensureCleanState() const client: vscode.LanguageModelChat = await this.getClient() - // Clean system prompt and messages - const cleanedSystemPrompt = this.cleanTerminalOutput(systemPrompt) + // Process messages const cleanedMessages = messages.map((msg) => ({ ...msg, content: this.cleanMessageContent(msg.content), @@ -361,7 +319,7 @@ export class VsCodeLmHandler extends BaseProvider implements SingleCompletionHan // Convert Anthropic messages to VS Code LM messages const vsCodeLmMessages: vscode.LanguageModelChatMessage[] = [ - vscode.LanguageModelChatMessage.Assistant(cleanedSystemPrompt), + vscode.LanguageModelChatMessage.Assistant(systemPrompt), ...convertToVsCodeLmMessages(cleanedMessages), ]