#!/bin/bash

# Export clean version of Mirror Magi Meta-Agent
# Excludes user-specific files and state

echo "🎯 Exporting clean Mirror Magi Meta-Agent..."

# Create export directory
EXPORT_DIR="../mirror-magi-export"
rm -rf "$EXPORT_DIR"
mkdir -p "$EXPORT_DIR/meta-agent"

# Copy essential files
echo "📁 Copying files..."
cp -r bin core scripts templates docs "$EXPORT_DIR/meta-agent/"
cp package.json package-lock.json index.js "$EXPORT_DIR/meta-agent/"
cp README.md CHANGELOG.md CONTRIBUTING.md LICENSE .gitignore .npmignore "$EXPORT_DIR/meta-agent/"

# Copy config templates only
mkdir -p "$EXPORT_DIR/meta-agent/config"
cp config/*.template.* config/command-templates.json "$EXPORT_DIR/meta-agent/config/" 2>/dev/null || true

# Create empty state directory with .gitkeep
mkdir -p "$EXPORT_DIR/meta-agent/state"
echo "{}" > "$EXPORT_DIR/meta-agent/state/.gitkeep"

# Remove any accidentally copied user files
find "$EXPORT_DIR" -name "project-config.json" -delete
find "$EXPORT_DIR" -name "agent-persona.md" -delete
find "$EXPORT_DIR" -name "master-plan.json" -delete
find "$EXPORT_DIR" -name "*.log" -delete
find "$EXPORT_DIR" -name ".DS_Store" -delete

# Show clean structure
echo ""
echo "🏗️  CLEAN STRUCTURE:"
echo "meta-agent/"
echo "├── README.md              # 🎯 Beautiful workflow visualization"
echo "├── index.js               # 🔌 Programmatic API"  
echo "├── package.json           # 📦 Package configuration"
echo "├── LICENSE                # ⚖️ MIT License"
echo "├── CONTRIBUTING.md        # 🤝 Contribution guidelines"
echo "├── CHANGELOG.md           # 📋 Version history"
echo "├── .npmignore             # 📦 NPM publish exclusions"
echo "├── bin/                   # 🔧 CLI commands"
echo "├── core/                  # 🚀 Core engines"
echo "├── scripts/               # 🛠️ All executable scripts"
echo "│   ├── validation/"
echo "│   ├── planning/"
echo "│   ├── execution/"
echo "│   └── legacy/"
echo "├── docs/                  # 📚 Documentation"
echo "├── config/                # ⚙️ Configuration templates"
echo "├── templates/             # 📝 Command templates"
echo "└── state/                 # 💾 Runtime state (empty with .gitkeep)"

echo ""
echo "✅ Export complete!"
echo "📁 Location: $EXPORT_DIR"
echo ""
echo "🚀 Ready for:"
echo "• 📦 NPM publishing (npm publish)"
echo "• 🐙 GitHub publishing"  
echo "• 🤝 Professional sharing"
echo "• 🔗 Open source distribution"
echo ""
echo "📋 Next steps:"
echo "1. cd $EXPORT_DIR"
echo "2. git init"
echo "3. git add ."
echo "4. git commit -m 'Mirror Magi Meta-Agent v2.0'"
echo "5. Create GitHub repo and push"
echo "6. npm publish (if publishing to npm)"

# Make executable
chmod +x "$EXPORT_DIR/meta-agent/scripts/export-clean.sh" 