Skip to content

Make project/repo selection optional for daf investigate command #364

@itdove

Description

@itdove

Overview

Currently, daf investigate requires project/repository selection either via --path flag, --projects flag with workspace, or interactive workspace selection. For generic investigations not tied to a specific project, this workflow is cumbersome.

Current Behavior

The daf investigate command handles project selection in this order:

  1. Multi-project mode (via --projects + --workspace): Specify multiple repos explicitly
  2. Direct path (via --path): Bypass workspace selection entirely
  3. Interactive workspace selection: Calls prompt_repository_selection_with_multiproject()
    • If workspace selected: prompts for repo(s) from that workspace
    • If no workspace: falls back to current directory automatically

Issue: Step 3's automatic fallback to current directory doesn't give users control over WHERE they want to work.

Requested Enhancement

Make project/repo selection truly optional with an interactive prompt when no path is specified:

Prompt options when no --path or --projects specified:

  1. Work in current directory - Use os.getcwd() as-is
  2. Clone to temp directory - If current dir is a git repo, offer temp clone (uses existing prompt_and_clone_to_temp() logic)
  3. Specify a different path - Allow entering arbitrary path
  4. Select from workspace - Existing workspace selection flow
  5. Cancel - Exit without creating session

Use Cases

Generic research not tied to a repo:

daf investigate --goal "Research Redis caching patterns"
# Prompt: Where do you want to work?
#   1. Current directory (/Users/dev/notes)
#   2. Specify a different path
#   3. Select from workspace
#   4. Cancel

Investigation in current repo with clean state:

cd /workspace/my-project
daf investigate --goal "Analyze authentication flow"
# Prompt: Where do you want to work?
#   1. Current directory (/workspace/my-project)
#   2. Clone to temp directory (clean main branch)
#   3. Specify a different path
#   4. Select from workspace
#   5. Cancel

Quick investigation without workspace setup:

daf investigate --goal "Explore API patterns" --path ~/Documents/notes
# No prompt - directly uses specified path

Implementation Notes

Files to modify:

  • devflow/cli/commands/investigate_command.py:
    • Lines 186-200: Replace prompt_repository_selection_with_multiproject() call with new prompting logic
    • Add _prompt_for_investigation_location() helper function

Key changes:

def _prompt_for_investigation_location(config) -> tuple[Optional[str], bool]:
    """Prompt user where they want to conduct investigation.
    
    Returns:
        Tuple of (project_path, is_temp_clone)
        Returns (None, False) if user cancels
    """
    from rich.prompt import Prompt
    
    current_dir = Path.cwd()
    is_git_repo = GitUtils.is_git_repository(current_dir)
    
    options = [
        f"1. Work in current directory ({current_dir})",
    ]
    
    if is_git_repo:
        options.append("2. Clone to temp directory (clean main branch)")
        options.append("3. Specify a different path")
        options.append("4. Select from workspace")
        options.append("5. Cancel")
        choice_map = {
            "1": ("current", False),
            "2": ("temp", True),
            "3": ("specify", False),
            "4": ("workspace", False),
            "5": ("cancel", False)
        }
    else:
        options.append("2. Specify a different path")
        options.append("3. Select from workspace")
        options.append("4. Cancel")
        choice_map = {
            "1": ("current", False),
            "2": ("specify", False),
            "3": ("workspace", False),
            "4": ("cancel", False)
        }
    
    console.print("\n[cyan]Where do you want to work?[/cyan]")
    for option in options:
        console.print(f"  {option}")
    
    choice = Prompt.ask("Select option", default="1")
    
    action, is_temp = choice_map.get(choice, ("cancel", False))
    
    if action == "cancel":
        return None, False
    elif action == "current":
        return str(current_dir), False
    elif action == "temp":
        # Use existing temp clone logic
        from devflow.utils.temp_directory import prompt_and_clone_to_temp
        result = prompt_and_clone_to_temp(current_dir)
        if result:
            temp_dir, original_path = result
            return temp_dir, True
        return str(current_dir), False  # Fallback if clone fails
    elif action == "specify":
        custom_path = Prompt.ask("Enter path")
        path = Path(custom_path).expanduser().absolute()
        if not path.exists():
            console.print(f"[red]✗[/red] Path does not exist: {path}")
            return None, False
        return str(path), False
    elif action == "workspace":
        # Use existing workspace selection
        project_paths, workspace_name = prompt_repository_selection_with_multiproject(
            config, allow_multiple=False
        )
        if project_paths:
            return project_paths[0], False
        return None, False

Integration point in create_investigation_session():

# Around line 186-200, replace:
else:
    # Prompt for repository selection from workspace...
    from devflow.cli.utils import prompt_repository_selection_with_multiproject
    project_paths, selected_workspace_name = prompt_repository_selection_with_multiproject(...)
    
# With:
else:
    # Prompt user where they want to work
    project_path, needs_temp_clone = _prompt_for_investigation_location(config)
    
    if not project_path:
        # User cancelled
        if is_json_mode():
            output_json(success=False, error={"message": "Investigation cancelled", "code": "CANCELLED"})
        sys.exit(0)
    
    # Note: temp_clone logic already exists below, will be triggered by needs_temp_clone flag

Acceptance Criteria

  • When daf investigate is run without --path or --projects, user is prompted with location options
  • Option 1 (current directory) works for both git and non-git directories
  • Option 2 (temp clone) only appears if current directory is a git repo
  • Option 3 (specify path) validates that entered path exists
  • Option 4 (workspace selection) uses existing workspace flow
  • Option 5 (cancel) exits gracefully without creating session
  • --path flag still bypasses all prompts (backward compatibility)
  • --projects + --workspace still works for multi-project mode
  • --temp-clone / --no-temp-clone flags override prompt behavior
  • All existing tests pass
  • New tests cover the prompting logic
  • JSON mode (--json) skips interactive prompts and uses sensible defaults

Testing Checklist

# Test 1: No flags, current dir (git repo)
cd /workspace/my-repo
daf investigate --goal "Test"
# Should prompt with 5 options including temp clone

# Test 2: No flags, current dir (non-git)
cd ~/Documents
daf investigate --goal "Test"
# Should prompt with 4 options (no temp clone option)

# Test 3: With --path flag
daf investigate --goal "Test" --path /tmp
# Should skip all prompts, use /tmp directly

# Test 4: With --projects + --workspace
daf investigate --goal "Test" --projects "repo1,repo2" --workspace default
# Should skip prompts, use multi-project mode

# Test 5: JSON mode
DAF_MOCK_MODE=1 daf investigate --goal "Test" --json
# Should skip prompts, use default (current directory)

# Test 6: Cancel flow
daf investigate --goal "Test"
# Choose option 5 (Cancel)
# Should exit without creating session

Related Code

  • devflow/cli/commands/investigate_command.py: Main command implementation
  • devflow/cli/utils.py: prompt_repository_selection_with_multiproject()
  • devflow/utils/temp_directory.py: prompt_and_clone_to_temp(), should_clone_to_temp()
  • devflow/git/utils.py: GitUtils.is_git_repository()

Benefits

  1. Flexibility: Generic investigations don't require workspace setup
  2. User control: Explicit choice of working directory
  3. Better UX: Clear options instead of automatic fallback
  4. Backward compatible: Existing --path and --projects workflows unchanged
  5. Consistent: Aligns with DevAIFlow's philosophy of explicit, user-controlled workflows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions