From be35fa2a7f2c9dba8855d6d12be15243244c6bc5 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Thu, 22 Jan 2026 08:30:30 +0530 Subject: [PATCH] fix(cli): wrap ANSI codes in prompt for rustyline compatibility Rustyline needs ANSI escape codes wrapped in \x01...\x02 markers to correctly calculate visible prompt length. Without this, tab completion breaks because rustyline miscalculates cursor position. --- crates/g3-cli/src/interactive.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/g3-cli/src/interactive.rs b/crates/g3-cli/src/interactive.rs index 2d50c96..937dff7 100644 --- a/crates/g3-cli/src/interactive.rs +++ b/crates/g3-cli/src/interactive.rs @@ -23,6 +23,8 @@ use crate::utils::display_context_progress; /// Build the interactive prompt string. /// /// Format: +/// Note: ANSI escape codes are wrapped in \x01...\x02 markers for rustyline +/// to correctly calculate visible prompt length (required for tab completion). /// - Multiline mode: `"... > "` /// - No project: `"agent_name> "` (defaults to "g3") /// - With project: `"agent_name | project_name> "` where `| project_name>` is blue @@ -36,12 +38,15 @@ pub fn build_prompt(in_multiline: bool, agent_name: Option<&str>, active_project .file_name() .and_then(|n| n.to_str()) .unwrap_or("project"); + // Wrap ANSI codes in \x01...\x02 for rustyline to ignore them in length calculation + let blue = format!("\x01{}\x02", SetForegroundColor(Color::Blue)); + let reset = format!("\x01{}\x02", ResetColor); format!( "{} {}| {}>{} ", base_name, - SetForegroundColor(Color::Blue), + blue, project_name, - ResetColor + reset ) } else { format!("{}> ", base_name)