From 143c0a0713e10d8ecb06dc3b35454c7b3d3dc936 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Sun, 30 Nov 2025 01:30:25 +0000 Subject: [PATCH] fix: strip ANSI sequences when capturing tmux output without colors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add stripAnsiSequences function to remove ANSI escape codes from terminal output when includeColors is false. This ensures test assertions can match against clean text without terminal formatting codes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- packages/server/src/server/terminal-mcp/tmux.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/server/src/server/terminal-mcp/tmux.ts b/packages/server/src/server/terminal-mcp/tmux.ts index 31a912764..3646a2aac 100644 --- a/packages/server/src/server/terminal-mcp/tmux.ts +++ b/packages/server/src/server/terminal-mcp/tmux.ts @@ -46,6 +46,16 @@ export type ShellType = "bash" | "zsh" | "fish"; let shellConfig: { type: ShellType } = { type: "bash" }; +const ANSI_ESCAPE_REGEX = + /\u001B[\[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g; + +function stripAnsiSequences(value: string): string { + if (!value) { + return ""; + } + return value.replace(ANSI_ESCAPE_REGEX, ""); +} + export function setShellConfig(config: { type: string }): void { // Validate shell type const validShells: ShellType[] = ["bash", "zsh", "fish"]; @@ -216,8 +226,9 @@ export async function capturePaneContent( const trimmed = output.trimEnd(); const allLines = trimmed.split("\n"); const lastLines = allLines.slice(-lines); + const joined = lastLines.join("\n"); - return lastLines.join("\n"); + return includeColors ? joined : stripAnsiSequences(joined); } /**