name: Sync g-slave to standalone repo

on:
  push:
    branches: [main]
    paths:
      - 'commands/g-slave.md'

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout claude-mods
        uses: actions/checkout@v4

      - name: Prepare g-slave.md (strip frontmatter)
        run: |
          # Remove YAML frontmatter for standalone repo
          sed '1{/^---$/!q;};1,/^---$/d' commands/g-slave.md > g-slave-clean.md
          cat g-slave-clean.md | head -20

      - name: Checkout g-slave repo
        uses: actions/checkout@v4
        with:
          repository: 0xDarkMatter/g-slave
          token: ${{ secrets.G_SLAVE_SYNC_TOKEN }}
          path: g-slave-repo

      - name: Copy and push
        run: |
          cp g-slave-clean.md g-slave-repo/g-slave.md
          cd g-slave-repo
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add g-slave.md
          git diff --staged --quiet || git commit -m "sync: Update from claude-mods"
          git push
