Remove machine mode entirely from g3
- Delete machine_ui_writer.rs - Remove --machine CLI flag from cli_args.rs - Remove run_machine_mode(), run_interactive_machine(), run_autonomous_machine() functions - Remove handle_machine_command() function - Simplify OutputMode enum to just use SimpleOutput directly - Simplify SimpleOutput struct (remove machine_mode field) - Remove machine_mode parameter from setup_workspace_directory() - Remove test_machine_option_accepted test - Disable ACD by default in agent_mode (requires --acd flag) - Change 'memory checkpoint' message formatting - Remove dehydration status message
This commit is contained in:
@@ -11,101 +11,17 @@ use crate::simple_output::SimpleOutput;
|
||||
/// Maximum number of retry attempts for timeout errors
|
||||
const MAX_TIMEOUT_RETRIES: u32 = 3;
|
||||
|
||||
/// Output mode for task execution feedback
|
||||
pub enum OutputMode<'a> {
|
||||
/// Console mode with SimpleOutput for user-friendly messages
|
||||
Console(&'a SimpleOutput),
|
||||
/// Machine mode with structured output markers
|
||||
Machine,
|
||||
}
|
||||
|
||||
impl<'a> OutputMode<'a> {
|
||||
fn print_thinking(&self) {
|
||||
match self {
|
||||
OutputMode::Console(output) => output.print("🤔 Thinking..."),
|
||||
OutputMode::Machine => {} // No thinking indicator in machine mode
|
||||
}
|
||||
}
|
||||
|
||||
fn print_cancelled(&self) {
|
||||
match self {
|
||||
OutputMode::Console(output) => output.print("\n⚠️ Operation cancelled by user (Ctrl+C)"),
|
||||
OutputMode::Machine => println!("CANCELLED"),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_cancelled_simple(&self) {
|
||||
match self {
|
||||
OutputMode::Console(output) => output.print("⚠️ Operation cancelled by user"),
|
||||
OutputMode::Machine => println!("CANCELLED"),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_retry_success(&self, attempt: u32) {
|
||||
match self {
|
||||
OutputMode::Console(output) => {
|
||||
output.print(&format!("✅ Request succeeded after {} attempts", attempt))
|
||||
}
|
||||
OutputMode::Machine => println!("RETRY_SUCCESS: attempt {}", attempt),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_response(&self, response: &str, output: Option<&SimpleOutput>) {
|
||||
match self {
|
||||
OutputMode::Console(o) => o.print_smart(response),
|
||||
OutputMode::Machine => {
|
||||
println!("AGENT_RESPONSE:");
|
||||
println!("{}", response);
|
||||
println!("END_AGENT_RESPONSE");
|
||||
// Ignore the output parameter in machine mode
|
||||
let _ = output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_timeout_retry(&self, attempt: u32, delay: std::time::Duration) {
|
||||
match self {
|
||||
OutputMode::Console(output) => {
|
||||
output.print(&format!(
|
||||
"⏱️ Timeout error detected (attempt {}/{}). Retrying in {:?}...",
|
||||
attempt, MAX_TIMEOUT_RETRIES, delay
|
||||
));
|
||||
}
|
||||
OutputMode::Machine => {
|
||||
println!(
|
||||
"TIMEOUT: attempt {} of {}, retrying in {:?}",
|
||||
attempt, MAX_TIMEOUT_RETRIES, delay
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_error(&self, e: &anyhow::Error, attempt: u32) {
|
||||
match self {
|
||||
OutputMode::Console(_) => {} // Handled by handle_execution_error
|
||||
OutputMode::Machine => {
|
||||
println!("ERROR: {}", e);
|
||||
if attempt > 1 {
|
||||
println!("FAILED_AFTER_RETRIES: {}", attempt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a task with retry logic for timeout errors.
|
||||
///
|
||||
/// This is the unified implementation used by both console and machine modes.
|
||||
pub async fn execute_task_with_retry<W: UiWriter>(
|
||||
agent: &mut Agent<W>,
|
||||
input: &str,
|
||||
show_prompt: bool,
|
||||
show_code: bool,
|
||||
mode: OutputMode<'_>,
|
||||
output: &SimpleOutput,
|
||||
) {
|
||||
let mut attempt = 0;
|
||||
|
||||
mode.print_thinking();
|
||||
output.print("🤔 Thinking...");
|
||||
|
||||
// Create cancellation token for this request
|
||||
let cancellation_token = CancellationToken::new();
|
||||
@@ -123,7 +39,7 @@ pub async fn execute_task_with_retry<W: UiWriter>(
|
||||
}
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
cancel_token_clone.cancel();
|
||||
mode.print_cancelled();
|
||||
output.print("\n⚠️ Operation cancelled by user (Ctrl+C)");
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -131,17 +47,14 @@ pub async fn execute_task_with_retry<W: UiWriter>(
|
||||
match execution_result {
|
||||
Ok(result) => {
|
||||
if attempt > 1 {
|
||||
mode.print_retry_success(attempt);
|
||||
output.print(&format!("✅ Request succeeded after {} attempts", attempt));
|
||||
}
|
||||
mode.print_response(&result.response, match &mode {
|
||||
OutputMode::Console(o) => Some(*o),
|
||||
OutputMode::Machine => None,
|
||||
});
|
||||
output.print_smart(&result.response);
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
if e.to_string().contains("cancelled") {
|
||||
mode.print_cancelled_simple();
|
||||
output.print("⚠️ Operation cancelled by user");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -157,7 +70,10 @@ pub async fn execute_task_with_retry<W: UiWriter>(
|
||||
let delay_ms = 1000 * (2_u64.pow(attempt - 1));
|
||||
let delay = std::time::Duration::from_millis(delay_ms);
|
||||
|
||||
mode.print_timeout_retry(attempt, delay);
|
||||
output.print(&format!(
|
||||
"⏱️ Timeout error detected (attempt {}/{}). Retrying in {:?}...",
|
||||
attempt, MAX_TIMEOUT_RETRIES, delay
|
||||
));
|
||||
|
||||
// Wait before retrying
|
||||
tokio::time::sleep(delay).await;
|
||||
@@ -165,14 +81,7 @@ pub async fn execute_task_with_retry<W: UiWriter>(
|
||||
}
|
||||
|
||||
// For non-timeout errors or after max retries
|
||||
match &mode {
|
||||
OutputMode::Console(output) => {
|
||||
handle_execution_error(&e, input, output, attempt);
|
||||
}
|
||||
OutputMode::Machine => {
|
||||
mode.print_error(&e, attempt);
|
||||
}
|
||||
}
|
||||
handle_execution_error(&e, input, output, attempt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user