This commit is contained in:
Dhanji Prasanna
2025-10-10 13:52:04 +11:00
parent 16216532d0
commit 2d959b3d63

View File

@@ -4,20 +4,20 @@ use g3_config::Config;
use g3_core::{project::Project, ui_writer::UiWriter, Agent};
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
use std::path::PathBuf;
use std::path::Path;
use std::path::PathBuf;
use tokio_util::sync::CancellationToken;
use tracing::{error, info};
use g3_core::error_handling::{classify_error, ErrorType, RecoverableError};
mod retro_tui;
mod theme;
mod tui;
mod ui_writer_impl;
mod theme;
use retro_tui::RetroTui;
use theme::ColorTheme;
use tui::SimpleOutput;
use ui_writer_impl::{ConsoleUiWriter, RetroTuiWriter};
use theme::ColorTheme;
#[derive(Parser)]
#[command(name = "g3")]
@@ -183,7 +183,14 @@ pub async fn run() -> Result<()> {
if cli.retro {
// Use retro terminal UI
run_interactive_retro(config, cli.show_prompt, cli.show_code, cli.theme, readme_content).await?;
run_interactive_retro(
config,
cli.show_prompt,
cli.show_code,
cli.theme,
readme_content,
)
.await?;
} else {
// Use standard terminal UI
let output = SimpleOutput::new();
@@ -221,7 +228,10 @@ fn read_project_readme(workspace_dir: &Path) -> Option<String> {
match std::fs::read_to_string(&readme_path) {
Ok(content) => {
// Return the content with a note about which file was read
return Some(format!("📚 Project README (from {}):\n\n{}", readme_name, content));
return Some(format!(
"📚 Project README (from {}):\n\n{}",
readme_name, content
));
}
Err(e) => {
// Log the error but continue looking for other README files
@@ -234,7 +244,13 @@ fn read_project_readme(workspace_dir: &Path) -> Option<String> {
None
}
async fn run_interactive_retro(config: Config, show_prompt: bool, show_code: bool, theme_name: Option<String>, readme_content: Option<String>) -> Result<()> {
async fn run_interactive_retro(
config: Config,
show_prompt: bool,
show_code: bool,
theme_name: Option<String>,
readme_content: Option<String>,
) -> Result<()> {
use crossterm::event::{self, Event, KeyCode, KeyModifiers};
use std::time::Duration;
@@ -403,7 +419,10 @@ async fn run_interactive_retro(config: Config, show_prompt: bool, show_code: boo
{
Ok(result) => {
if attempt > 1 {
tui.output(&format!("SYSTEM: REQUEST SUCCEEDED AFTER {} ATTEMPTS", attempt));
tui.output(&format!(
"SYSTEM: REQUEST SUCCEEDED AFTER {} ATTEMPTS",
attempt
));
}
tui.output(&result.response);
tui.status("READY");
@@ -413,7 +432,11 @@ async fn run_interactive_retro(config: Config, show_prompt: bool, show_code: boo
// Check if this is a timeout error that we should retry
let error_type = classify_error(&e);
if matches!(error_type, ErrorType::Recoverable(RecoverableError::Timeout)) && attempt < MAX_TIMEOUT_RETRIES {
if matches!(
error_type,
ErrorType::Recoverable(RecoverableError::Timeout)
) && attempt < MAX_TIMEOUT_RETRIES
{
// Calculate retry delay with exponential backoff
let delay_ms = 1000 * (2_u64.pow(attempt - 1));
let delay = std::time::Duration::from_millis(delay_ms);
@@ -482,10 +505,8 @@ async fn run_interactive<W: UiWriter>(
let output = SimpleOutput::new();
output.print("");
output.print("🤖 G3 AI Coding Agent - Interactive Mode");
output.print(
"I solve problems by writing and executing code. Tell me what you need to accomplish!",
);
output.print("🪿 G3 AI Coding Agent - Interactive Mode");
output.print("I solve problems by writing and executing code. what shall we build today?");
output.print("");
// Display message if README was loaded
@@ -497,7 +518,7 @@ async fn run_interactive<W: UiWriter>(
// Display provider and model information
match agent.get_provider_info() {
Ok((provider, model)) => {
output.print(&format!("🔧 Provider: {} | Model: {}", provider, model));
output.print(&format!("🔧 {} | {}", provider, model));
}
Err(e) => {
error!("Failed to get provider info: {}", e);
@@ -505,9 +526,7 @@ async fn run_interactive<W: UiWriter>(
}
output.print("");
output.print("Type 'exit' or 'quit' to exit, use Up/Down arrows for command history");
output.print("For multiline input: use \\ at the end of a line to continue");
output.print("Submit multiline with Enter (without backslash)");
output.print("CTRL-D to quit; ↑/↓ for history");
output.print("");
// Initialize rustyline editor with history
@@ -672,7 +691,11 @@ async fn execute_task<W: UiWriter>(
// Check if this is a timeout error that we should retry
let error_type = classify_error(&e);
if matches!(error_type, ErrorType::Recoverable(RecoverableError::Timeout)) && attempt < MAX_TIMEOUT_RETRIES {
if matches!(
error_type,
ErrorType::Recoverable(RecoverableError::Timeout)
) && attempt < MAX_TIMEOUT_RETRIES
{
// Calculate retry delay with exponential backoff
let delay_ms = 1000 * (2_u64.pow(attempt - 1));
let delay = std::time::Duration::from_millis(delay_ms);