#!/bin/bash
# List active worktrees for a product
# Usage: list-worktrees.sh <product-slug>

SLUG=$1

if [ -z "$SLUG" ]; then
  echo "Usage: list-worktrees.sh <product-slug>" >&2
  exit 1
fi

STATE_FILE="/home/aria/products/$SLUG/.worktree-state.json"

if [ -f "$STATE_FILE" ]; then
  ACTIVE=$(jq -r '.active | length' "$STATE_FILE")
  if [ "$ACTIVE" -eq 0 ]; then
    echo "No active worktrees for $SLUG"
  else
    echo "Active worktrees for $SLUG:"
    jq -r '.active | to_entries[] | "  \(.key): \(.value.description) (by \(.value.requester), started \(.value.started))"' "$STATE_FILE"
  fi
else
  echo "No worktree state file for $SLUG"
fi
