Skill: mrgoodb/migrate (version 1.0.0)

--- name: migrate description: Export and import Clawdbot installations for migration between machines. Use when the user wants to migrate Clawdbot to a new computer, backup their setup, or restore from a backup. Handles workspace files, config, WhatsApp sessions, and optionally credentials. --- # Clawdbot Migration Export and import complete Clawdbot installations. ## Export Create a portable archive of the current installation: ```bash bash scripts/export.sh ``` Options: - `--output, -o PATH` — Output directory (default: current) - `--workspace PATH` — Workspace path (default: ~/clawd) - `--include-sessions` — Include session transcripts - `--include-credentials` — Include credentials ⚠️ handle with care Example: ```bash bash scripts/export.sh -o /tmp --include-sessions ``` Creates: `clawdbot-export-YYYYMMDD_HHMMSS.tar.gz` ## Import Restore from an export archive on a new machine: ```bash bash scripts/import.sh <archive.tar.gz> ``` Options: - `--workspace PATH` — Target workspace (default: ~/clawd) - `--force, -f` — Overwrite without prompting Example: ```bash bash scripts/import.sh clawdbot-export-20260129_120000.tar.gz --force ``` ## What's Included | Component | Default | Flag | |-----------|---------|------| | Workspace (~/clawd) | ✓ | — | | Config (clawdbot.json) | ✓ | — | | Managed skills | ✓ | — | | WhatsApp session | ✓ | — | | Session transcripts | ✗ | `--include-sessions` | | Credentials | ✗ | `--include-credentials` | **Excluded from workspace** (can be rebuilt): `node_modules/`, `.next/`, `.open-next/`, `.vercel/`, `.wrangler/`, `.git/`, `dist/`, `build/` ## Migration Workflow 1. On old machine: ```bash bash scripts/export.sh -o ~/Desktop ``` 2. Transfer archive to new machine (scp, USB, cloud, etc.) 3. On new machine: ```bash npm install -g clawdbot bash scripts/import.sh ~/clawdbot-export-*.tar.gz cd ~/clawd && clawdbot gateway start ``` WhatsApp session transfers automatically — no re-scan needed.

path: scripts/export.sh
content: #!/bin/bash
# Clawdbot Migration Export Script
# Creates a portable archive of workspace + config

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

# Defaults
WORKSPACE="${CLAWDBOT_WORKSPACE:-$HOME/clawd}"
CONFIG_DIR="$HOME/.clawdbot"
OUTPUT_DIR="${1:-.}"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
ARCHIVE_NAME="clawdbot-export-${TIMESTAMP}.tar.gz"
INCLUDE_SESSIONS=false
INCLUDE_CREDENTIALS=false

# Parse args
while [[ $# -gt 0 ]]; do
    case $1 in
        --workspace) WORKSPACE="$2"; shift 2 ;;
        --output|-o) OUTPUT_DIR="$2"; shift 2 ;;
        --include-sessions) INCLUDE_SESSIONS=true; shift ;;
        --include-credentials) INCLUDE_CREDENTIALS=true; shift ;;
        --name) ARCHIVE_NAME="$2"; shift 2 ;;
        --help|-h)
            echo "Usage: export.sh [OPTIONS]"
            echo ""
            echo "Options:"
            echo "  --workspace PATH       Workspace directory (default: ~/clawd)"
            echo "  --output, -o PATH      Output directory (default: current dir)"
            echo "  --include-sessions     Include session transcripts"
            echo "  --include-credentials  Include credentials (DANGEROUS)"
            echo "  --name FILENAME        Custom archive name"
            exit 0
            ;;
        *) shift ;;
    esac
done

echo -e "${GREEN}🚀 Clawdbot Export${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

# Validate paths
if [ ! -d "$WORKSPACE" ]; then
    echo -e "${RED}✗ Workspace not found: $WORKSPACE${NC}"
    exit 1
fi

if [ ! -d "$CONFIG_DIR" ]; then
    echo -e "${RED}✗ Config directory not found: $CONFIG_DIR${NC}"
    exit 1
fi

# Create temp staging directory
STAGING=$(mktemp -d)
trap "rm -rf $STAGING" EXIT

echo -e "${YELLOW}→ Staging workspace...${NC}"
mkdir -p "$STAGING/workspace"

# Use rsync to exclude large/rebuilable directories
rsync -a --exclude='node_modules' \
         --exclude='.next' \
         --exclude='.open-next' \
         --exclude='.vercel' \
         --exclude='.wrangler' \
         --exclude='.git' \
         --exclude='dist' \
         --exclude='build' \
         --exclude='*.log' \
         --exclude='.DS_Store' \
         "$WORKSPACE/" "$STAGING/workspace/" 2>/dev/null || \
cp -r "$WORKSPACE"/* "$STAGING/workspace/" 2>/dev/null || true

# Cleanup if rsync wasn't available
rm -rf "$STAGING/workspace/.git" "$STAGING/workspace/node_modules" "$STAGING/workspace/.next" 2>/dev/null || true

echo -e "${YELLOW}→ Staging config...${NC}"
mkdir -p "$STAGING/config"

# Always include main config
[ -f "$CONFIG_DIR/clawdbot.json" ] && cp "$CONFIG_DIR/clawdbot.json" "$STAGING/config/"

# Include skills
if [ -d "$CONFIG_DIR/skills" ]; then
    cp -r "$CONFIG_DIR/skills" "$STAGING/config/"
fi

# Include WhatsApp session (for seamless migration)
if [ -d "$CONFIG_DIR/whatsapp" ]; then
    echo -e "${YELLOW}→ Including WhatsApp session...${NC}"
    cp -r "$CONFIG_DIR/whatsapp" "$STAGING/config/"
fi

# Optional: sessions
if [ "$INCLUDE_SESSIONS" = true ] && [ -d "$CONFIG_DIR/agents" ]; then
    echo -e "${YELLOW}→ Including session transcripts...${NC}"
    cp -r "$CONFIG_DIR/agents" "$STAGING/config/"
fi

# Optional: credentials (dangerous)
if [ "$INCLUDE_CREDENTIALS" = true ] && [ -d "$CONFIG_DIR/credentials" ]; then
    echo -e "${RED}⚠ Including credentials (handle with care!)${NC}"
    cp -r "$CONFIG_DIR/credentials" "$STAGING/config/"
fi

# Create manifest
cat > "$STAGING/manifest.json" << EOF
{
  "version": "1.0",
  "exported_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
  "hostname": "$(hostname)",
  "workspace_path": "$WORKSPACE",
  "includes": {
    "workspace": true,
    "config": true,
    "whatsapp_session": $([ -d "$CONFIG_DIR/whatsapp" ] && echo "true" || echo "false"),
    "sessions": $INCLUDE_SESSIONS,
    "credentials": $INCLUDE_CREDENTIALS
  }
}
EOF

# Create archive
echo -e "${YELLOW}→ Creating archive...${NC}"
mkdir -p "$OUTPUT_DIR"
tar -czf "$OUTPUT_DIR/$ARCHIVE_NAME" -C "$STAGING" .

# Summary
SIZE=$(du -h "$OUTPUT_DIR/$ARCHIVE_NAME" | cut -f1)
echo ""
echo -e "${GREEN}✓ Export complete!${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e "  Archive: ${GREEN}$OUTPUT_DIR/$ARCHIVE_NAME${NC}"
echo -e "  Size: $SIZE"
echo ""
echo "To import on new machine:"
echo "  1. Copy archive to new machine"
echo "  2. Run: bash import.sh $ARCHIVE_NAME"


path: scripts/import.sh
content: #!/bin/bash
# Clawdbot Migration Import Script
# Restores workspace + config from export archive

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'

# Defaults
WORKSPACE="${CLAWDBOT_WORKSPACE:-$HOME/clawd}"
CONFIG_DIR="$HOME/.clawdbot"
ARCHIVE=""
FORCE=false

# Parse args
while [[ $# -gt 0 ]]; do
    case $1 in
        --workspace) WORKSPACE="$2"; shift 2 ;;
        --force|-f) FORCE=true; shift ;;
        --help|-h)
            echo "Usage: import.sh ARCHIVE [OPTIONS]"
            echo ""
            echo "Arguments:"
            echo "  ARCHIVE                Path to clawdbot export archive"
            echo ""
            echo "Options:"
            echo "  --workspace PATH       Target workspace directory (default: ~/clawd)"
            echo "  --force, -f            Overwrite existing files without prompting"
            exit 0
            ;;
        *)
            if [ -z "$ARCHIVE" ]; then
                ARCHIVE="$1"
            fi
            shift
            ;;
    esac
done

if [ -z "$ARCHIVE" ]; then
    echo -e "${RED}✗ No archive specified${NC}"
    echo "Usage: import.sh ARCHIVE [OPTIONS]"
    exit 1
fi

if [ ! -f "$ARCHIVE" ]; then
    echo -e "${RED}✗ Archive not found: $ARCHIVE${NC}"
    exit 1
fi

echo -e "${GREEN}🚀 Clawdbot Import${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"

# Create temp extraction directory
STAGING=$(mktemp -d)
trap "rm -rf $STAGING" EXIT

echo -e "${YELLOW}→ Extracting archive...${NC}"
tar -xzf "$ARCHIVE" -C "$STAGING"

# Check manifest
if [ -f "$STAGING/manifest.json" ]; then
    echo -e "${CYAN}Archive info:${NC}"
    cat "$STAGING/manifest.json" | grep -E '"exported_at"|"hostname"' | sed 's/[",]//g' | sed 's/^/  /'
    echo ""
fi

# Check for existing installations
if [ -d "$WORKSPACE" ] && [ "$FORCE" = false ]; then
    echo -e "${YELLOW}⚠ Workspace already exists: $WORKSPACE${NC}"
    read -p "  Merge/overwrite? [y/N] " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "Aborted."
        exit 1
    fi
fi

if [ -d "$CONFIG_DIR" ] && [ "$FORCE" = false ]; then
    echo -e "${YELLOW}⚠ Config directory already exists: $CONFIG_DIR${NC}"
    read -p "  Merge/overwrite? [y/N] " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo "Aborted."
        exit 1
    fi
fi

# Restore workspace
if [ -d "$STAGING/workspace" ]; then
    echo -e "${YELLOW}→ Restoring workspace to $WORKSPACE...${NC}"
    mkdir -p "$WORKSPACE"
    cp -r "$STAGING/workspace"/* "$WORKSPACE/" 2>/dev/null || true
    echo -e "  ${GREEN}✓${NC} Workspace restored"
fi

# Restore config
if [ -d "$STAGING/config" ]; then
    echo -e "${YELLOW}→ Restoring config to $CONFIG_DIR...${NC}"
    mkdir -p "$CONFIG_DIR"
    
    # Main config
    if [ -f "$STAGING/config/clawdbot.json" ]; then
        cp "$STAGING/config/clawdbot.json" "$CONFIG_DIR/"
        echo -e "  ${GREEN}✓${NC} Config file restored"
    fi
    
    # Skills
    if [ -d "$STAGING/config/skills" ]; then
        cp -r "$STAGING/config/skills" "$CONFIG_DIR/"
        echo -e "  ${GREEN}✓${NC} Managed skills restored"
    fi
    
    # WhatsApp session
    if [ -d "$STAGING/config/whatsapp" ]; then
        cp -r "$STAGING/config/whatsapp" "$CONFIG_DIR/"
        echo -e "  ${GREEN}✓${NC} WhatsApp session restored"
    fi
    
    # Sessions (if included)
    if [ -d "$STAGING/config/agents" ]; then
        cp -r "$STAGING/config/agents" "$CONFIG_DIR/"
        echo -e "  ${GREEN}✓${NC} Session transcripts restored"
    fi
    
    # Credentials (if included)
    if [ -d "$STAGING/config/credentials" ]; then
        cp -r "$STAGING/config/credentials" "$CONFIG_DIR/"
        echo -e "  ${GREEN}✓${NC} Credentials restored"
    fi
fi

# Update workspace path in config if different
if [ -f "$CONFIG_DIR/clawdbot.json" ]; then
    # Check if jq is available
    if command -v jq &> /dev/null; then
        CURRENT_WS=$(jq -r '.agent.workspace // empty' "$CONFIG_DIR/clawdbot.json" 2>/dev/null || true)
        if [ -n "$CURRENT_WS" ] && [ "$CURRENT_WS" != "$WORKSPACE" ]; then
            echo -e "${YELLOW}→ Updating workspace path in config...${NC}"
            jq --arg ws "$WORKSPACE" '.agent.workspace = $ws' "$CONFIG_DIR/clawdbot.json" > "$CONFIG_DIR/clawdbot.json.tmp"
            mv "$CONFIG_DIR/clawdbot.json.tmp" "$CONFIG_DIR/clawdbot.json"
        fi
    fi
fi

echo ""
echo -e "${GREEN}✓ Import complete!${NC}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Next steps:"
echo "  1. Install Clawdbot (if not installed):"
echo "     npm install -g clawdbot"
echo ""
echo "  2. Start the gateway:"
echo "     cd $WORKSPACE && clawdbot gateway start"
echo ""
if [ -d "$STAGING/config/whatsapp" ]; then
    echo -e "  ${GREEN}✓${NC} WhatsApp session included - no re-scan needed!"
else
    echo "  3. Link WhatsApp (if needed):"
    echo "     clawdbot whatsapp link"
fi


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: suspicious | SkillSpector: suspicious (MEDIUM)