# Phase 01.1.5: User Consent for Git State Changes [MANDATORY IF uncommitted > 10] (RCA-008)

**CRITICAL: This step prevents autonomous file hiding (RCA-008 incident - 2025-11-13).**

**When to execute:** After git-validator returns results from Phase 01.1

**Trigger condition:**
- `uncommitted_changes > 10` OR
- `untracked_files > 0` (if git-validator provides this data)

**Purpose:** Obtain explicit user consent before any git operation that would hide/modify files, preventing the autonomous stashing incident where 21 story files were hidden without user knowledge.

**Implementation:**

```
IF git_validator_result["git_status"]["uncommitted_changes"] > 10 OR
   (git_validator_result["file_analysis"] AND git_validator_result["file_analysis"]["untracked_files"] > 0):

    # Extract counts from git-validator result
    total_changes = git_validator_result["git_status"]["uncommitted_changes"]

    # If git-validator provides file_analysis (Phase 2 enhancement), use it
    IF git_validator_result["file_analysis"] exists:
        untracked_count = git_validator_result["file_analysis"]["untracked_files"]
        modified_count = git_validator_result["file_analysis"]["modified_files"]
        file_breakdown = git_validator_result["file_analysis"]["file_breakdown"]
    ELSE:
        # Fallback: Calculate ourselves
        untracked_count = count uncommitted files marked "??" in git status
        modified_count = total_changes - untracked_count
        file_breakdown = null

    # Display status summary box
    Display: ""
    Display: "╔═══════════════════════════════════════════════════════════════╗"
    Display: "║  ⚠️  UNCOMMITTED CHANGES DETECTED                             ║"
    Display: "╠═══════════════════════════════════════════════════════════════╣"
    Display: "║                                                               ║"
    Display: "║  Total files: {total_changes}                                ║"

    IF untracked_count > 0 AND modified_count > 0:
        Display: "║    • {modified_count} modified files (tracked by git)        ║"
        Display: "║    • {untracked_count} untracked files (new, not in git)     ║"
    ELIF untracked_count > 0:
        Display: "║    • {untracked_count} untracked files (new, not in git)     ║"
    ELSE:
        Display: "║    • {modified_count} modified files                         ║"

    # Display file breakdown if available
    IF file_breakdown exists AND file_breakdown is not empty:
        Display: "║                                                               ║"
        Display: "║  Breakdown:                                                   ║"

        IF file_breakdown["story_files"] > 0:
            Display: "║    • {file_breakdown.story_files} story files (.story.md)    ║"
            Display: "║      ⚠️  User-created content - should not be hidden         ║"

        IF file_breakdown["python_cache"] > 0:
            Display: "║    • {file_breakdown.python_cache} Python cache files        ║"

        IF file_breakdown["config_files"] > 0:
            Display: "║    • {file_breakdown.config_files} config files              ║"

        IF file_breakdown["documentation"] > 0:
            Display: "║    • {file_breakdown.documentation} documentation files      ║"

        IF file_breakdown["code"] > 0:
            Display: "║    • {file_breakdown.code} code files                        ║"

        IF file_breakdown["other"] > 0:
            Display: "║    • {file_breakdown.other} other files                      ║"

    Display: "║                                                               ║"
    Display: "║  The development workflow can proceed in multiple ways:       ║"
    Display: "║                                                               ║"
    Display: "╚═══════════════════════════════════════════════════════════════╝"
    Display: ""

    # Ask user for strategy
    AskUserQuestion(
        questions=[{
            question: "How should we handle these uncommitted changes?",
            header: "Git Strategy",
            multiSelect: false,
            options: [
                {
                    label: "Continue anyway (safe - file-based tracking)",
                    description: "Proceed without touching git. Framework uses file-based change tracking. All your files stay visible."
                },
                {
                    label: "Stash ONLY modified files, keep untracked visible ⭐ Recommended",
                    description: "Hide {modified_count} modified (tracked) files in stash, but keep {untracked_count} untracked files visible."
                },
                {
                    label: "Show me the files first",
                    description: "Display list of all {total_changes} files so I can review what would be affected."
                },
                {
                    label: "Commit my changes first",
                    description: "Pause development. I'll commit these changes manually, then re-run /dev."
                },
                {
                    label: "Stash ALL files (modified + untracked) - Advanced",
                    description: "⚠️ Hide ALL {total_changes} files including untracked. Requires 'git stash pop' to restore."
                }
            ]
        }]
    )

    # Handle user response
    SWITCH user_response_answers["Git Strategy"]:

        CASE "Continue anyway (safe - file-based tracking)":
            SET workflow_mode = "file-based"
            Display: "✅ Proceeding with file-based tracking. Your files remain visible."
            # Continue to Phase 01.2

        CASE "Stash ONLY modified files, keep untracked visible ⭐ Recommended":
            # Use git stash WITHOUT --include-untracked flag
            Bash(
                command="git stash push -m 'WIP: Modified files only (by /dev at $(date +%Y-%m-%d_%H:%M:%S))'",
                description="Stash modified files only, preserve untracked"
            )
            Display: "✅ Stashed modified files, untracked files remain visible"
            SET workflow_mode = "git"

        CASE "Show me the files first":
            Bash(command="git status --short", description="Show uncommitted files")
            # Re-ask question after showing files

        CASE "Commit my changes first":
            Display: "Development paused. Commit changes and re-run /dev."
            HALT workflow

        CASE "Stash ALL files (modified + untracked) - Advanced":
            # Delegate to Phase 01.1.6 (Stash Warning Workflow)
            INVOKE: Phase 01.1.6

ELSE:
    # No uncommitted changes, or below threshold
    Display: "✓ Working tree: Clean (or below threshold)"
```

**Success Criteria:**
- User ALWAYS prompted when uncommitted_changes > 10 or untracked_files > 0
- User can see file list before deciding
- "Continue anyway" preserves all files via file-based tracking
- No files ever hidden without explicit user confirmation

**Token cost:** ~1,500 tokens

**Rationale:** RCA-008 incident (2025-11-13) occurred when AI agent autonomously ran `git stash --include-untracked` without user consent.
