# Phase 01.1.6: Stash Warning and Confirmation [MANDATORY IF user selects stash] (RCA-008)

**When to execute:** User selected "Stash ALL files" in Phase 01.1.5

**Purpose:** Provide clear warning about file visibility consequences before stashing untracked files

**Implementation:**

```
# Get file counts from git-validator result (or calculate)
total_files = git_validator_result["git_status"]["uncommitted_changes"]

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"]
ELSE:
    # Fallback: Count ourselves
    Bash(command="git status --short | grep '^??' | wc -l", description="Count untracked files")
    untracked_count = result
    modified_count = total_files - untracked_count

# Show detailed file breakdown
IF untracked_count > 0:
    Display: "Preparing to show untracked files that would be stashed..."

    # Show first 10 untracked files
    Bash(command="git status --short | grep '^??' | head -10", description="Show untracked files")

    IF untracked_count > 10:
        Display: "... and {untracked_count - 10} more untracked files"

    # Check for story files specifically
    Bash(command="git status --short | grep '^??' | grep -c 'STORY-' || echo '0'", description="Count story files")
    story_file_count = result

    IF story_file_count > 0:
        Display: "⚠️  {story_file_count} STORY files detected in untracked files:"
        Bash(command="git status --short | grep '^??' | grep 'STORY-'", description="Show story files")

# Display warning box
Display: ""
Display: "╔═══════════════════════════════════════════════════════════════╗"
Display: "║  ⚠️  WARNING: STASHING {total_files} FILES                    ║"
Display: "╠═══════════════════════════════════════════════════════════════╣"
Display: "║                                                               ║"
Display: "║  What 'git stash' does:                                       ║"
Display: "║    • Temporarily HIDES files from your filesystem             ║"
Display: "║    • Files are stored in git's stash storage                  ║"
Display: "║    • They are NOT deleted (recoverable)                       ║"
Display: "║    • They will NOT be visible until you restore them          ║"
Display: "║                                                               ║"

IF untracked_count > 0:
    Display: "║  ⚠️  {untracked_count} UNTRACKED FILES WILL BE HIDDEN:        ║"
    Display: "║    These are NEW files you created that aren't in git yet.    ║"
    IF story_file_count > 0:
        Display: "║    This includes {story_file_count} STORY files!              ║"
    Display: "║                                                               ║"

Display: "║  To recover stashed files later:                              ║"
Display: "║    git stash pop        # Restores and removes from stash     ║"
Display: "║    git stash apply      # Restores but keeps in stash         ║"
Display: "║                                                               ║"
Display: "╚═══════════════════════════════════════════════════════════════╝"
Display: ""

# Second confirmation required for safety
AskUserQuestion(
    questions=[{
        question: "Are you SURE you want to stash {total_files} files?",
        header: "Confirm Stash",
        multiSelect: false,
        options: [
            {
                label: "Yes, stash them (I understand they'll be hidden)",
                description: "Proceed with stashing. Files will be recoverable with 'git stash pop'."
            },
            {
                label: "No, continue without stashing instead",
                description: "Cancel stashing. Use file-based tracking instead. All files stay visible."
            },
            {
                label: "No, let me commit them first",
                description: "Cancel development. I'll commit these files properly before re-running /dev."
            }
        ]
    }]
)

# Handle confirmation response
SWITCH confirmation_response_answers["Confirm Stash"]:

    CASE "Yes, stash them (I understand they'll be hidden)":
        # Execute stash with clear message
        Bash(
            command="git stash push -m 'WIP: Stashed by /dev at {timestamp}' --include-untracked",
            description="Stash all changes including untracked files"
        )
        Display: "✅ Stashed {total_files} files to stash@{0}"
        Display: ""
        Display: "To restore your files later: git stash pop"
        SET workflow_mode = "git"

    CASE "No, continue without stashing instead":
        Display: "✅ Cancelled stashing. Proceeding with file-based tracking."
        SET workflow_mode = "file-based"

    CASE "No, let me commit them first":
        Display: "✅ Cancelled stashing. Development paused."
        Display: "Please commit your changes, then re-run /dev"
        HALT workflow
```

**Success Criteria:**
- Warning box displays BEFORE stashing
- User sees list of files that will be hidden
- Story files explicitly called out if present
- Recovery commands shown before AND after stashing
- Double confirmation required (Phase 01.1.5 + Phase 01.1.6)
- User can cancel at any point

**Token cost:** ~2,000 tokens

**Rationale:** RCA-008 incident showed users don't understand git stash behavior with `--include-untracked`. This double-confirmation prevents accidental file hiding.
