clean up TODO output

This commit is contained in:
Dhanji R. Prasanna
2025-12-02 06:48:58 +11:00
parent 1b4ea93ba4
commit 0e4c935a70

View File

@@ -1,78 +1,21 @@
use g3_core::ui_writer::UiWriter; use g3_core::ui_writer::UiWriter;
use std::io::{self, Write}; use std::io::{self, Write};
use std::sync::Mutex;
/// Console implementation of UiWriter that prints to stdout /// Console implementation of UiWriter that prints to stdout
pub struct ConsoleUiWriter { pub struct ConsoleUiWriter {
current_tool_name: Mutex<Option<String>>, current_tool_name: std::sync::Mutex<Option<String>>,
current_tool_args: Mutex<Vec<(String, String)>>, current_tool_args: std::sync::Mutex<Vec<(String, String)>>,
current_output_line: Mutex<Option<String>>, current_output_line: std::sync::Mutex<Option<String>>,
output_line_printed: Mutex<bool>, output_line_printed: std::sync::Mutex<bool>,
in_todo_tool: Mutex<bool>,
} }
impl ConsoleUiWriter { impl ConsoleUiWriter {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
current_tool_name: Mutex::new(None), current_tool_name: std::sync::Mutex::new(None),
current_tool_args: Mutex::new(Vec::new()), current_tool_args: std::sync::Mutex::new(Vec::new()),
current_output_line: Mutex::new(None), current_output_line: std::sync::Mutex::new(None),
output_line_printed: Mutex::new(false), output_line_printed: std::sync::Mutex::new(false),
in_todo_tool: Mutex::new(false),
}
}
fn print_todo_line(&self, line: &str) {
// Transform and print todo list lines elegantly
let trimmed = line.trim();
// Skip the "📝 TODO list:" prefix line
if trimmed.starts_with("📝 TODO list:") || trimmed == "📝 TODO list is empty" {
return;
}
// Handle empty lines
if trimmed.is_empty() {
println!();
return;
}
// Detect indentation level
let indent_count = line.chars().take_while(|c| c.is_whitespace()).count();
let indent = " ".repeat(indent_count / 2); // Convert spaces to visual indent
// Format based on line type
if trimmed.starts_with("- [ ]") {
// Incomplete task
let task = trimmed.strip_prefix("- [ ]").unwrap_or(trimmed).trim();
println!("{}{}", indent, task);
} else if trimmed.starts_with("- [x]") || trimmed.starts_with("- [X]") {
// Completed task
let task = trimmed
.strip_prefix("- [x]")
.or_else(|| trimmed.strip_prefix("- [X]"))
.unwrap_or(trimmed)
.trim();
println!("{}\x1b[2m☑ {}\x1b[0m", indent, task);
} else if trimmed.starts_with("- ") {
// Regular bullet point
let item = trimmed.strip_prefix("- ").unwrap_or(trimmed).trim();
println!("{}{}", indent, item);
} else if trimmed.starts_with("# ") {
// Heading
let heading = trimmed.strip_prefix("# ").unwrap_or(trimmed).trim();
println!("\n\x1b[1m{}\x1b[0m", heading);
} else if trimmed.starts_with("## ") {
// Subheading
let subheading = trimmed.strip_prefix("## ").unwrap_or(trimmed).trim();
println!("\n\x1b[1m{}\x1b[0m", subheading);
} else if trimmed.starts_with("**") && trimmed.ends_with("**") {
// Bold text (section marker)
let text = trimmed.trim_start_matches("**").trim_end_matches("**");
println!("{}\x1b[1m{}\x1b[0m", indent, text);
} else {
// Regular text or note
println!("{}{}", indent, trimmed);
} }
} }
} }
@@ -138,13 +81,6 @@ impl UiWriter for ConsoleUiWriter {
// Store the tool name and clear args for collection // Store the tool name and clear args for collection
*self.current_tool_name.lock().unwrap() = Some(tool_name.to_string()); *self.current_tool_name.lock().unwrap() = Some(tool_name.to_string());
self.current_tool_args.lock().unwrap().clear(); self.current_tool_args.lock().unwrap().clear();
// Check if this is a todo tool call
let is_todo = tool_name == "todo_read" || tool_name == "todo_write";
*self.in_todo_tool.lock().unwrap() = is_todo;
// For todo tools, we'll skip the normal header and print a custom one later
if is_todo {}
} }
fn print_tool_arg(&self, key: &str, value: &str) { fn print_tool_arg(&self, key: &str, value: &str) {
@@ -167,12 +103,6 @@ impl UiWriter for ConsoleUiWriter {
} }
fn print_tool_output_header(&self) { fn print_tool_output_header(&self) {
// Skip normal header for todo tools
if *self.in_todo_tool.lock().unwrap() {
println!(); // Just add a newline
return;
}
println!(); println!();
// Now print the tool header with the most important arg in bold green // Now print the tool header with the most important arg in bold green
if let Some(tool_name) = self.current_tool_name.lock().unwrap().as_ref() { if let Some(tool_name) = self.current_tool_name.lock().unwrap().as_ref() {
@@ -259,21 +189,14 @@ impl UiWriter for ConsoleUiWriter {
} }
fn print_tool_output_line(&self, line: &str) { fn print_tool_output_line(&self, line: &str) {
// Special handling for todo tools // Skip the TODO list header line
if *self.in_todo_tool.lock().unwrap() { if line.starts_with("📝 TODO list:") {
self.print_todo_line(line);
return; return;
} }
println!("\x1b[2m{}\x1b[0m", line); println!("\x1b[2m{}\x1b[0m", line);
} }
fn print_tool_output_summary(&self, count: usize) { fn print_tool_output_summary(&self, count: usize) {
// Skip for todo tools
if *self.in_todo_tool.lock().unwrap() {
return;
}
println!( println!(
"\x1b[2m({} line{})\x1b[0m", "\x1b[2m({} line{})\x1b[0m",
count, count,
@@ -282,13 +205,6 @@ impl UiWriter for ConsoleUiWriter {
} }
fn print_tool_timing(&self, duration_str: &str) { fn print_tool_timing(&self, duration_str: &str) {
// For todo tools, just print a simple completion message
if *self.in_todo_tool.lock().unwrap() {
println!();
*self.in_todo_tool.lock().unwrap() = false;
return;
}
// Parse the duration string to determine color // Parse the duration string to determine color
// Format is like "1.5s", "500ms", "2m 30.0s" // Format is like "1.5s", "500ms", "2m 30.0s"
let color_code = if duration_str.ends_with("ms") { let color_code = if duration_str.ends_with("ms") {