From ed84a940f97673a31cdd7aae77259f63975cedbe Mon Sep 17 00:00:00 2001 From: Michael Neale Date: Wed, 22 Oct 2025 14:27:17 +1100 Subject: [PATCH] tweak auto mode --- CHANGELOG.md | 12 +++-- README.md | 27 +++++++++- crates/g3-cli/src/lib.rs | 111 ++++++++++++++++++++++++++++++++------- test-ai-requirements.sh | 39 ++++++++++++++ 4 files changed, 163 insertions(+), 26 deletions(-) create mode 100755 test-ai-requirements.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 145734d..ce725bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,14 @@ ### Added **Interactive Requirements Mode** -- **Interactive Requirements Entry**: New `--interactive-requirements` flag for autonomous mode - - Prompts user to enter requirements via stdin (multi-line support) - - Automatically saves requirements to `requirements.md` in workspace - - Shows preview of entered requirements +- **AI-Enhanced Interactive Requirements**: New `--interactive-requirements` flag for autonomous mode + - User enters brief description of what they want to build + - AI automatically enhances input into structured requirements.md document + - Generates professional markdown with: + - Project title and overview + - Organized requirements (functional, technical, quality) + - Acceptance criteria + - User can review, accept, edit manually, or cancel before proceeding - Seamlessly transitions to autonomous mode **Autonomous Mode Configuration** diff --git a/README.md b/README.md index 5428098..b274b92 100644 --- a/README.md +++ b/README.md @@ -61,13 +61,36 @@ G3 features an autonomous mode where two agents collaborate: - **Player Agent**: Executes tasks and implements solutions - **Coach Agent**: Reviews work and provides feedback -### Option 1: Interactive Requirements (Recommended) +### Option 1: Interactive Requirements with AI Enhancement (Recommended) ```bash g3 --autonomous --interactive-requirements ``` -Enter your requirements (multi-line), then press **Ctrl+D** (Unix/Mac) or **Ctrl+Z** (Windows) to start. +**How it works:** +1. Describe what you want to build (can be brief) +2. Press **Ctrl+D** (Unix/Mac) or **Ctrl+Z** (Windows) +3. AI enhances your input into a structured requirements document +4. Review the enhanced requirements +5. Choose to proceed, edit manually, or cancel +6. If accepted, autonomous mode starts automatically + +**Example:** +``` +You type: "build a todo app with cli in python" + +AI generates: +# Todo List CLI Application + +## Overview +A command-line todo list application built in Python... + +## Functional Requirements +1. Add tasks with descriptions +2. Mark tasks as complete +3. Delete tasks +... +``` ### Option 2: Direct Requirements diff --git a/crates/g3-cli/src/lib.rs b/crates/g3-cli/src/lib.rs index 5748478..0c578c3 100644 --- a/crates/g3-cli/src/lib.rs +++ b/crates/g3-cli/src/lib.rs @@ -397,14 +397,14 @@ pub async fn run() -> Result<()> { // Create project model let project = if cli.autonomous { - // Handle interactive requirements mode + // Handle interactive requirements mode with AI enhancement if cli.interactive_requirements { println!("\nšŸ“ Interactive Requirements Mode"); println!("================================\n"); - println!("Please enter your project requirements."); - println!("You can enter multiple lines. Press Ctrl+D (Unix) or Ctrl+Z (Windows) when done.\n"); + println!("Describe what you want to build (can be brief):"); + println!("Press Ctrl+D (Unix) or Ctrl+Z (Windows) when done.\n"); - use std::io::{self, Read}; + use std::io::{self, Read, Write}; let mut requirements_input = String::new(); io::stdin().read_to_string(&mut requirements_input)?; @@ -412,25 +412,96 @@ pub async fn run() -> Result<()> { anyhow::bail!("No requirements provided. Exiting."); } - // Save to requirements.md in workspace + println!("\nšŸ¤– Enhancing your requirements with AI...\n"); + + // Create a temporary agent to enhance the requirements + let temp_config = Config::load_with_overrides( + cli.config.as_deref(), + cli.provider.clone(), + cli.model.clone(), + )?; + + // Create a simple output writer for the enhancement task + let ui_writer = ConsoleUiWriter::new(); + let mut temp_agent = Agent::new_with_readme_and_quiet( + temp_config, + ui_writer, + None, + true, // quiet mode for enhancement + ).await?; + + // Create enhancement prompt + let enhancement_prompt = format!( + r#"Convert the following user input into a well-structured requirements.md document. + +User Input: +{} + +Create a professional requirements document with: +1. A clear project title (# heading) +2. An overview section explaining what will be built +3. Organized requirements (functional, technical, quality) +4. Acceptance criteria +5. Any technical constraints or preferences mentioned + +Format as proper markdown. Be specific and actionable. If the user's input is vague, make reasonable assumptions but keep it focused on what they described. + +Output ONLY the markdown content, no explanations or meta-commentary."#, + requirements_input.trim() + ); + + // Execute enhancement task + let result = temp_agent + .execute_task_with_timing(&enhancement_prompt, None, false, false, false, false) + .await?; + + let enhanced_requirements = result.response.trim().to_string(); + + // Show the enhanced requirements + println!("\nšŸ“‹ Enhanced Requirements Document:"); + println!("{}\n", "=".repeat(60)); + println!("{}", enhanced_requirements); + println!("{}\n", "=".repeat(60)); + + // Ask for confirmation + println!("\nā“ Is this requirements document acceptable?"); + println!(" [y] Yes, proceed with autonomous mode"); + println!(" [e] Edit and save manually"); + println!(" [n] No, cancel\n"); + + print!("Your choice (y/e/n): "); + io::stdout().flush()?; + + let mut choice = String::new(); + io::stdin().read_line(&mut choice)?; + let choice = choice.trim().to_lowercase(); + let requirements_path = workspace_dir.join("requirements.md"); - std::fs::write(&requirements_path, &requirements_input)?; - println!("\nāœ… Requirements saved to: {}", requirements_path.display()); - println!("šŸ“ Length: {} characters\n", requirements_input.len()); - - // Show a preview - let preview_lines: Vec<&str> = requirements_input.lines().take(5).collect(); - println!("Preview (first 5 lines):"); - println!("---"); - for line in preview_lines { - println!("{}", line); + match choice.as_str() { + "y" | "yes" => { + // Save enhanced requirements + std::fs::write(&requirements_path, &enhanced_requirements)?; + println!("\nāœ… Requirements saved to: {}", requirements_path.display()); + println!("šŸš€ Starting autonomous mode...\n"); + } + "e" | "edit" => { + // Save enhanced requirements for manual editing + std::fs::write(&requirements_path, &enhanced_requirements)?; + println!("\nāœ… Requirements saved to: {}", requirements_path.display()); + println!("šŸ“ Please edit the file and run: g3 --autonomous"); + println!(" Exiting for now.\n"); + return Ok(()); + } + "n" | "no" => { + println!("\nāŒ Cancelled. No files were saved.\n"); + return Ok(()); + } + _ => { + println!("\nāŒ Invalid choice. Cancelled.\n"); + return Ok(()); + } } - if requirements_input.lines().count() > 5 { - println!("... ({} more lines)", requirements_input.lines().count() - 5); - } - println!("---\n"); - println!("šŸš€ Starting autonomous mode...\n"); } if let Some(requirements_text) = cli.requirements { diff --git a/test-ai-requirements.sh b/test-ai-requirements.sh new file mode 100755 index 0000000..06c97fc --- /dev/null +++ b/test-ai-requirements.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# Test script for AI-enhanced interactive requirements mode + +echo "Testing AI-enhanced interactive requirements mode..." +echo "" + +# Create a test workspace +TEST_WORKSPACE="/tmp/g3-test-interactive-$(date +%s)" +mkdir -p "$TEST_WORKSPACE" + +echo "Test workspace: $TEST_WORKSPACE" +echo "" + +# Create sample brief input +BRIEF_INPUT="build a calculator cli in rust with basic operations" + +echo "Brief input:" +echo "---" +echo "$BRIEF_INPUT" +echo "---" +echo "" + +echo "This will:" +echo "1. Send brief input to AI" +echo "2. AI generates structured requirements.md" +echo "3. Show enhanced requirements" +echo "4. Prompt for confirmation (y/e/n)" +echo "" + +echo "To test manually, run:" +echo "cargo run -- --autonomous --interactive-requirements --workspace $TEST_WORKSPACE" +echo "" +echo "Then type: $BRIEF_INPUT" +echo "Press Ctrl+D" +echo "Review the AI-generated requirements" +echo "Choose 'y' to proceed, 'e' to edit, or 'n' to cancel" +echo "" + +echo "Test workspace will be at: $TEST_WORKSPACE"