Merge pull request #10 from dhanji/micn/interactive-requirements
Add --interactive-requirements flag for AI-enhanced requirements mode
This commit is contained in:
@@ -216,6 +216,10 @@ pub struct Cli {
|
||||
#[arg(long, value_name = "TEXT")]
|
||||
pub requirements: Option<String>,
|
||||
|
||||
/// Interactive mode: prompt for requirements and save to requirements.md before starting autonomous mode
|
||||
#[arg(long)]
|
||||
pub interactive_requirements: bool,
|
||||
|
||||
/// Use retro terminal UI (inspired by 80s sci-fi)
|
||||
#[arg(long)]
|
||||
pub retro: bool,
|
||||
@@ -303,6 +307,112 @@ pub async fn run() -> Result<()> {
|
||||
|
||||
// Create project model
|
||||
let project = if cli.autonomous {
|
||||
// Handle interactive requirements mode with AI enhancement
|
||||
if cli.interactive_requirements {
|
||||
println!("\n📝 Interactive Requirements Mode");
|
||||
println!("================================\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, Write};
|
||||
let mut requirements_input = String::new();
|
||||
io::stdin().read_to_string(&mut requirements_input)?;
|
||||
|
||||
if requirements_input.trim().is_empty() {
|
||||
anyhow::bail!("No requirements provided. Exiting.");
|
||||
}
|
||||
|
||||
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(),
|
||||
)?;
|
||||
|
||||
let ui_writer = ConsoleUiWriter::new();
|
||||
let mut temp_agent = Agent::new_with_readme_and_quiet(
|
||||
temp_config,
|
||||
ui_writer,
|
||||
None,
|
||||
true, // quiet mode
|
||||
).await?;
|
||||
|
||||
// Craft the enhancement prompt
|
||||
let enhancement_prompt = format!(
|
||||
r#"You are a requirements analyst. Take this brief user input and expand it into a structured requirements 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");
|
||||
|
||||
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 let Some(requirements_text) = cli.requirements {
|
||||
// Use requirements text override
|
||||
Project::new_autonomous_with_requirements(workspace_dir.clone(), requirements_text)?
|
||||
|
||||
39
test-ai-requirements.sh
Executable file
39
test-ai-requirements.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user