zc2 0.0.29

P2P compute broker with credit-based billing, WAL, and broker mesh support
version: "3"

vars:
  BINARY_NAME: zc
  PACKAGE_NAME: zc2
  # The per-user bin dir, which PATH usually searches before /usr/local/bin.
  # Installing to /usr/local/bin left an older ~/.local/bin/zc shadowing the
  # fresh build, so the binary you had just built never ran.
  INSTALL_DIR:
    sh: echo "$HOME/.local/bin"
  INSTALL_PATH: "{{.INSTALL_DIR}}/{{.BINARY_NAME}}"
  COMMIT_SHA:
    sh: git show --format='%H' --no-patch
  TIMESTAMP:
    sh: date +%Y%m%d-%H%M%S
  # Signing for the macOS app. Manual signing with the Apple Development
  # identity works with no provisioning profile; the untested fallback is
  # '-allowProvisioningUpdates CODE_SIGN_STYLE=Automatic'.
  MACOS_SIGN_ARGS: 'CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="Apple Development"'

tasks:
  default:
    desc: Build binary and start Docker services
    cmds:
      - task: build

  # ---------------------------------------------------------------------------
  #  Build
  # ---------------------------------------------------------------------------
  build:
    desc: Build binary and start Docker services
    cmds:
      - task: build:bin
      - docker compose down
      - docker compose build
      - docker compose up -d

  build:bin:
    desc: Build the release binaries incrementally and install them to ~/.local/bin
    cmds:
      # --workspace also builds the zc-hooks sidecar, which owns the private
      # zakuro-client dep (#104). zc2 itself has no git dependencies. No
      # `cargo clean` and no `-j 4`: rebuilding after one edit takes ~11 s,
      # where the clean 4-job build took ~64 s.
      - cargo build --release --workspace
      - mkdir -p "{{.INSTALL_DIR}}"
      - install -m 0755 target/release/{{.BINARY_NAME}} target/release/zc-hooks "{{.INSTALL_DIR}}/"

  dev:
    desc: Debug build for fixing bugs (~1-2 s after an edit), linked as zc-dev
    cmds:
      - cargo build --bin {{.BINARY_NAME}}
      - mkdir -p "{{.INSTALL_DIR}}"
      - ln -sf "{{.ROOT_DIR}}/target/debug/{{.BINARY_NAME}}" "{{.INSTALL_DIR}}/zc-dev"

  build:docker:
    desc: Build Docker image only (no binary compilation)
    cmds:
      - docker compose build

  # ---------------------------------------------------------------------------
  #  Run
  # ---------------------------------------------------------------------------
  run:
    desc: Build and run the CLI
    deps: [build]
    cmds:
      - ./{{.BINARY_NAME}}

  release:
    desc: Run the release binary
    cmds:
      - "{{.INSTALL_PATH}}"

  debug:
    desc: Build and run with full backtrace
    deps: [build]
    env:
      RUST_BACKTRACE: full
    cmds:
      - ./{{.BINARY_NAME}}

  # ---------------------------------------------------------------------------
  #  Broker
  # ---------------------------------------------------------------------------
  broker:
    desc: Start broker in foreground mode
    cmds:
      - "{{.INSTALL_PATH}} broker"

  broker:daemon:
    desc: Start broker in daemon (background) mode
    cmds:
      - "{{.INSTALL_PATH}} -d broker"

  # ---------------------------------------------------------------------------
  #  Benchmarking
  # ---------------------------------------------------------------------------
  bench:
    desc: Run default benchmark (10 concurrent, 1000 requests)
    cmds:
      - "{{.INSTALL_PATH}} bench {{.CLI_ARGS}}"

  bench:compare:
    desc: Compare all routing strategies
    cmds:
      - "{{.INSTALL_PATH}} bench --compare {{.CLI_ARGS}}"

  # ---------------------------------------------------------------------------
  #  Local test: two brokers + two workers (no Docker)
  # ---------------------------------------------------------------------------
  test:two-brokers:
    desc: Run two brokers and two workers locally, then bench with different strategies
    cmds:
      - bash scripts/two-brokers-two-workers-local.sh

  # ---------------------------------------------------------------------------
  #  Diagnostics
  # ---------------------------------------------------------------------------
  info:
    desc: Show system info, clusters, and network status
    cmds:
      - "{{.INSTALL_PATH}} info"

  # ---------------------------------------------------------------------------
  #  Docker
  # ---------------------------------------------------------------------------
  docker:up:
    desc: Start Docker services
    cmds:
      - docker compose up -d

  docker:down:
    desc: Stop Docker services
    cmds:
      - docker compose down

  docker:logs:
    desc: Show Docker service logs
    cmds:
      - docker compose logs -f

  # ---------------------------------------------------------------------------
  #  macOS app (menu bar + widget) — see macos/README.md
  # ---------------------------------------------------------------------------
  macos:gen:
    desc: Generate macos/Zakuro.xcodeproj from macos/project.yml
    cmds:
      - xcodegen generate --spec macos/project.yml

  macos:build:
    desc: Build Zakuro.app (Release) signed with your Apple Development identity
    deps: [macos:gen]
    preconditions:
      - sh: test -n "$ZAKURO_DEVELOPMENT_TEAM"
        msg: "export ZAKURO_DEVELOPMENT_TEAM=<Team ID> first (see macos/README.md)"
    cmds:
      - xcodebuild -project macos/Zakuro.xcodeproj -scheme Zakuro -configuration Release -destination 'generic/platform=macOS' -derivedDataPath macos/build {{.MACOS_SIGN_ARGS}} DEVELOPMENT_TEAM=$ZAKURO_DEVELOPMENT_TEAM build

  macos:install:
    desc: Install Zakuro.app into /Applications, quit the running copy, relaunch
    deps: [macos:build]
    cmds:
      - pkill -x Zakuro || true
      - rm -rf /Applications/Zakuro.app
      - cp -R macos/build/Build/Products/Release/Zakuro.app /Applications/Zakuro.app
      - open /Applications/Zakuro.app

  macos:test:
    desc: Run ZakuroAgentKit tests (swift test) and the app's unit tests (xcodebuild test)
    cmds:
      - swift test --package-path macos/Packages/ZakuroAgentKit
      - xcodegen generate --spec macos/project.yml
      - xcodebuild test -project macos/Zakuro.xcodeproj -scheme Zakuro -destination 'platform=macOS,arch=arm64' -derivedDataPath macos/build CODE_SIGNING_ALLOWED=NO

  macos:stub-agent:
    desc: Serve a stub of the zc agent /v1 API (docs/agent-api/summary.v1.json) for app development
    cmds:
      - python3 -u macos/Scripts/stub-agent.py {{.CLI_ARGS}}

  # ---------------------------------------------------------------------------
  #  Housekeeping
  # ---------------------------------------------------------------------------
  clean:
    desc: Remove build artifacts
    cmds:
      - cargo clean
      - rm -rf target/