recursive-agent 0.8.2

A Rust coding-agent platform: kernel, tools, multi-agent orchestration, HTTP API, MCP, and TUI
Documentation
name: Release

on:
  push:
    tags:
      - 'v*.*.*'

env:
  CARGO_TERM_COLOR: always

jobs:
  # ── 1. Verify version + run tests ─────────────────────────────────────────
  verify:
    name: Verify & test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Configure git for tests
        run: |
          git config --global user.email "ci@recursive.local"
          git config --global user.name "CI Bot"
          git config --global safe.directory "*"

      - name: Verify tag matches Cargo.toml version
        run: |
          tag_version="${GITHUB_REF_NAME#v}"
          crate_version=$(cargo metadata --no-deps --format-version 1 \
            | python3 -c "import sys, json; pkgs = json.load(sys.stdin)['packages']; print(next(p['version'] for p in pkgs if p['name'] == 'recursive-agent'))")
          echo "tag=$tag_version  cargo=$crate_version"
          if [ "$tag_version" != "$crate_version" ]; then
            echo "::error::Tag '$GITHUB_REF_NAME' does not match Cargo.toml version '$crate_version'"
            exit 1
          fi

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ubuntu-latest-cargo-release-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ubuntu-latest-cargo-

      - name: Format check
        run: cargo fmt --all -- --check

      - name: Clippy
        run: cargo clippy --workspace --all-targets --all-features -- -D warnings

      - name: Test
        run: cargo test --workspace --verbose

  # ── 2. Build binaries for all platforms ───────────────────────────────────
  build:
    name: Build ${{ matrix.target }}
    needs: verify
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux (static musl builds — no glibc version dependency)
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            cross: true
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
            cross: true
          # macOS — aarch64 only for 0.7.0. We dropped x86_64-apple-darwin
          # because (a) GitHub's `macos-13` Intel runner pool is
          # chronically backlogged (the last attempt queued >24h and was
          # cancelled) and (b) cross-building x86_64 from the arm64
          # `macos-latest` runner needs extra cargo SDK config we don't
          # want to bake in. Intel Mac users are <5% of the install base
          # and can `cargo install recursive-cli` from source. Revisit
          # in 0.7.1 with a darwin-universal target.
          - target: aarch64-apple-darwin
            os: macos-latest
            cross: false
          # Windows
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            cross: false

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install cross (Linux cross-compilation)
        if: matrix.cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ matrix.target }}-cargo-

      - name: Build (cross)
        if: matrix.cross
        run: cross build --release --target ${{ matrix.target }} -p recursive-cli --bin recursive

      - name: Build (native)
        if: "!matrix.cross"
        run: cargo build --release --target ${{ matrix.target }} -p recursive-cli --bin recursive

      # Package into .tar.gz (Unix) or .zip (Windows)
      - name: Package (Unix)
        if: matrix.os != 'windows-latest'
        shell: bash
        run: |
          BIN="target/${{ matrix.target }}/release/recursive"
          ASSET="recursive-${{ matrix.target }}.tar.gz"
          tar -czf "$ASSET" -C "$(dirname $BIN)" "$(basename $BIN)"
          echo "ASSET=$ASSET" >> $GITHUB_ENV

      - name: Package (Windows)
        if: matrix.os == 'windows-latest'
        shell: pwsh
        run: |
          $BIN = "target\${{ matrix.target }}\release\recursive.exe"
          $ASSET = "recursive-${{ matrix.target }}.zip"
          Compress-Archive -Path $BIN -DestinationPath $ASSET
          "ASSET=$ASSET" | Out-File -FilePath $env:GITHUB_ENV -Append

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: recursive-${{ matrix.target }}
          path: ${{ env.ASSET }}
          retention-days: 1

  # ── 3. Create GitHub Release and attach binaries ──────────────────────────
  release:
    name: Create GitHub Release
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: List artifacts
        run: find artifacts -type f | sort

      - name: Compute checksums
        run: |
          cd artifacts
          find . -type f \( -name "*.tar.gz" -o -name "*.zip" \) | sort | while read f; do
            sha256sum "$f"
          done > ../SHA256SUMS.txt
          cat ../SHA256SUMS.txt

      - name: Create / update GitHub Release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          # Create release if it doesn't exist yet
          if ! gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
            gh release create "$GITHUB_REF_NAME" \
              --repo "$GITHUB_REPOSITORY" \
              --title "$GITHUB_REF_NAME" \
              --generate-notes
          fi

          # Upload all binaries + checksums
          find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) | while read f; do
            gh release upload "$GITHUB_REF_NAME" "$f" \
              --repo "$GITHUB_REPOSITORY" \
              --clobber
          done

          gh release upload "$GITHUB_REF_NAME" SHA256SUMS.txt \
            --repo "$GITHUB_REPOSITORY" \
            --clobber

          # `gh release create` invoked with the auto-issued GITHUB_TOKEN
          # leaves the release as a draft (the token cannot publish). For
          # a tag-driven release we want it public immediately, otherwise
          # the assets URL returns 404 for everyone without a token, and
          # downstream package managers (Homebrew, Scoop, AUR...) silently
          # fail to fetch their source tarball.
          gh release edit "$GITHUB_REF_NAME" \
            --repo "$GITHUB_REPOSITORY" \
            --draft=false

  # ── 4. Publish to crates.io ────────────────────────────────────────────────
  # Whole publishable workspace in dependency order (agui-* → recursive-agent
  # → tui/cli): `cargo publish` verifies each crate against REGISTRY versions
  # of its internal deps, so dependencies must land first and the index needs
  # a moment to propagate before dependents resolve them (hence the retry).
  # Failures are loud: a red crates.io job must not be silently swallowed —
  # it sat broken from 0.7.0 through 0.8.1 under continue-on-error while the
  # channel stalled at 0.6.0. "already exists" stays benign for re-tagged
  # reruns.
  publish-crate:
    name: Publish to crates.io
    needs: release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ubuntu-latest-cargo-publish-${{ hashFiles('**/Cargo.lock') }}

      - name: Publish workspace crates (dependency order)
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
        run: |
          set -uo pipefail
          if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
            echo "::warning::Secret CRATES_IO_TOKEN is not set — crates.io publish skipped."
            exit 0
          fi
          for pkg in agui-protocol agui-client agui-tui recursive-agent recursive-tui recursive-cli; do
            echo "==> Publishing $pkg"
            ok=""
            for attempt in 1 2 3 4 5 6 7 8; do
              out=$(cargo publish -p "$pkg" 2>&1) && { ok=yes; break; }
              if echo "$out" | grep -q "already exists"; then
                echo "$pkg already published — skipping."
                ok=yes; break
              fi
              # The freshly published dependency may not be visible in the
              # sparse index yet; wait and retry that specific case.
              if echo "$out" | grep -qE "no matching version|failed to select a version"; then
                echo "attempt $attempt: index has not caught up yet; retrying in 20s"
                echo "$out" | tail -3
                sleep 20
                continue
              fi
              break
            done
            if [ -z "$ok" ]; then
              echo "$out"
              echo "::error::cargo publish failed for $pkg"
              exit 1
            fi
          done
          echo "All workspace crates published."

  # ── 5. Bump the Homebrew tap ────────────────────────────────────────────────
  # Pushes a "recursive: bump to X.Y.Z" commit to jeffkit/homebrew-tap so the
  # brew channel ships with the release instead of silently lagging behind
  # (0.8.0 and 0.8.1 both had to be bumped by hand). Auth is a write deploy
  # key on jeffkit/homebrew-tap stored as the HOMEBREW_TAP_DEPLOY_KEY secret
  # (repo-scoped, revocable from the tap's Settings → Deploy keys) — without
  # it the job warns and skips, so the release itself never goes red.
  bump-homebrew:
    name: Bump homebrew tap
    needs: release
    runs-on: ubuntu-latest
    env:
      TAP_KEY_SET: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY != '' }}
    steps:
      - name: Skip (HOMEBREW_TAP_DEPLOY_KEY not configured)
        if: env.TAP_KEY_SET == 'false'
        run: |
          echo "::warning::Secret HOMEBREW_TAP_DEPLOY_KEY is not set — jeffkit/homebrew-tap was NOT bumped."
          echo "::warning::Add a write deploy key of jeffkit/homebrew-tap as this repo's HOMEBREW_TAP_DEPLOY_KEY secret, then re-run this job."

      - name: Checkout tap
        if: env.TAP_KEY_SET == 'true'
        uses: actions/checkout@v4
        with:
          repository: jeffkit/homebrew-tap
          ssh-key: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
          path: tap

      - name: Bump Formula/recursive.rb to ${{ github.ref_name }}
        if: env.TAP_KEY_SET == 'true'
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail
          # Checksums of the assets this same run just published.
          gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
            --pattern 'SHA256SUMS.txt' --dir /tmp/rel --clobber
          darwin_sha=$(grep 'recursive-aarch64-apple-darwin.tar.gz' /tmp/rel/SHA256SUMS.txt | awk '{print $1}')
          if ! [[ "$darwin_sha" =~ ^[0-9a-f]{64}$ ]]; then
            echo "::error::Could not parse darwin-arm64 sha256 from SHA256SUMS.txt"
            exit 1
          fi
          formula=tap/Formula/recursive.rb
          sed -i.bak \
            -e "s|releases/download/v[^/]*/recursive-aarch64-apple-darwin.tar.gz|releases/download/${GITHUB_REF_NAME}/recursive-aarch64-apple-darwin.tar.gz|" \
            -e "s|sha256 \"[0-9a-f]\{64\}\"|sha256 \"${darwin_sha}\"|" \
            "$formula"
          rm -f "$formula.bak"
          grep -q "${GITHUB_REF_NAME}/recursive-aarch64-apple-darwin" "$formula"
          grep -q "$darwin_sha" "$formula"
          if git -C tap diff --quiet; then
            echo "Formula already at ${GITHUB_REF_NAME} — nothing to do."
            exit 0
          fi
          git -C tap config user.name "github-actions[bot]"
          git -C tap config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git -C tap add Formula/recursive.rb
          git -C tap commit -m "recursive: bump to ${GITHUB_REF_NAME#v}"
          git -C tap push origin main