# Prompt Archiving

All prompts and data from the video generation pipeline are automatically archived in each task directory for debugging and analysis.

## Directory Structure

```
/mnt/video/wb_{product_id}/{task_id}/
├── prompts/                          # AI prompts sent to models
│   ├── stage2_story_vision.txt       # Claude prompt for story concept
│   ├── stage3_frame_design.txt       # Claude prompt for NanoBanana frames
│   └── stage4_veo3_prompt.txt        # Final Veo3 video generation prompt
├── generation.log                    # Complete pipeline log (JSON)
├── metadata.json                     # Summary metadata
├── pipeline.log                      # Real-time execution log
├── images/                           # Downloaded product images
├── processed/                        # Generated frames
│   ├── frame_act1.jpg
│   └── frame_act2.jpg
└── videos/                           # Generated videos
    ├── video_generated.mp4           # Raw 9:16 from Veo3
    └── video.mp4                     # Final cropped (3:4 for wbcard)
```

## Archived Files

### prompts/ Directory

Contains the exact prompts sent to AI models during generation.

**stage2_story_vision.txt**
- Complete Claude prompt for story concept generation
- Includes: product data, reviews, specifications, feedback analysis, previous generations
- Use to debug: Why Claude chose this style/archetype, how it interpreted feedback

**stage3_frame_design.txt**
- Complete Claude prompt for NanoBanana frame generation
- Includes: story vision, product images to analyze, reference prompts
- Use to debug: How frames were designed, what product details were used

**stage4_veo3_prompt.txt**
- Final assembled prompt for Veo3 video generation
- Format: `ACT 1 (3 sec): ... TRANSITION: ... ACT 2 (5 sec): ... --negatives`
- Use to debug: Exact video generation instructions, negative prompts applied

### generation.log (JSON)

Complete pipeline execution log with all stage data.

**Key sections**:

```json
{
  "task_id": "20260127_132905_wonv",
  "product_url": "https://www.wildberries.ru/catalog/271933299/detail.aspx",
  "product_id": "271933299",
  "started_at": "2026-01-27T13:29:05",
  "completed_at": "2026-01-27T13:33:14",

  "stages": {
    "stage1": {
      "started_at": "...",
      "data_source": "sellematics",
      "product_name": "Комплект шапка со снудом зимняя",
      "description": "Full product description...",
      "reviews": [...],  // All reviews
      "specifications": [...],  // All specs
      "reviews_count": 833,
      "rating": 4.8
    },

    "stage2": {
      "started_at": "...",
      "prompt_sent_to_claude": "# Stage 2: Story Vision\n\n...",
      "claude_response": "Full JSON response...",
      "story_vision": {
        "catchy_name": "Городская зима",
        "visual_style": "hip_hop",
        "video_kind": "standard",
        "archetype": "product_lifestyle",
        "act1": {...},
        "act2": {...}
      }
    },

    "stage3": {
      "prompt_sent_to_claude": "Read these product images:\n...",
      "claude_response": "FRAME ACT 1: ...",
      "frame_prompts": {
        "frame_act1": "Detailed NanoBanana prompt...",
        "frame_act2": "Detailed NanoBanana prompt..."
      }
    },

    "stage4": {
      "veo3_prompt": "ACT 1 (3 sec): ... --negatives"
    }
  },

  "errors": [],
  "build_info": {
    "git_commit": "5021b22c",
    "git_dirty": true
  }
}
```

### metadata.json

Simplified metadata for quick reference (subset of generation.log).

### pipeline.log

Real-time execution log with timestamps, useful for:
- Tracking execution progress
- Seeing API call durations
- Debugging async operations
- Token usage and errors

## Usage Examples

### 1. Debug Why Claude Chose a Specific Style

```bash
# Read Stage 2 prompt to see feedback analysis
cat /mnt/video/wb_271933299/20260127_132905_wonv/prompts/stage2_story_vision.txt

# Look for "MOST RECENT" feedback section to see what user requested
grep -A 10 "MOST RECENT" prompts/stage2_story_vision.txt
```

### 2. Check What Veo3 Was Asked to Generate

```bash
# Read final Veo3 prompt
cat prompts/stage4_veo3_prompt.txt

# Check negative prompts applied
grep "\-\-" prompts/stage4_veo3_prompt.txt
```

### 3. See Full Product Data (Reviews, Specs)

```bash
# Extract Stage 1 data from generation.log
jq '.stages.stage1' generation.log

# Get all reviews
jq '.stages.stage1.reviews' generation.log

# Get product description
jq -r '.stages.stage1.description' generation.log
```

### 4. Compare Prompts Across Generations

```bash
# Product with 3 generations
cd /mnt/video/wb_271933299/

# Compare how feedback changed prompts
for dir in 2026*/; do
  echo "=== $dir ==="
  grep "MOST RECENT" "$dir/prompts/stage2_story_vision.txt" | head -5
done
```

### 5. Reproduce a Generation

```bash
# Use saved prompts to manually test AI models
cd /mnt/video/wb_271933299/20260127_132905_wonv/

# Test Stage 2 prompt with Claude directly
cat prompts/stage2_story_vision.txt | claude

# Test Veo3 prompt
cat prompts/stage4_veo3_prompt.txt
# (Copy to Veo3 API tester)
```

## Archive Location

All task directories are under:
```
/mnt/video/wb_{product_id}/{task_id}/
```

Where:
- `product_id`: Wildberries product ID (e.g., `271933299`)
- `task_id`: Generation timestamp + random ID (e.g., `20260127_132905_wonv`)

**Example paths**:
```
/mnt/video/wb_271933299/20260127_132905_wonv/prompts/stage2_story_vision.txt
/mnt/video/wb_271933299/20260127_132905_wonv/generation.log
/mnt/video/wb_271933299/20260127_132905_wonv/pipeline.log
```

## Retention

Archives are kept indefinitely for:
- Debugging production issues
- Analyzing feedback patterns
- Training data review
- Audit trail

**Cleanup**: Old generations can be manually deleted if storage is needed, but keep recent ones (last 30 days) for debugging.

## See Also

- [CLAUDE.md](../CLAUDE.md) - Main project documentation
- [showcase.md](showcase.md) - Showcase/portfolio system
- [known-issues.md](known-issues.md) - Known bugs and limitations
