#!/usr/bin/env bash
# rsend — send a message into a Clare-managed conversation.
#
# Usage:
#   rsend <convo> <message...>
#
# <convo>    A Clare project name, or @group, that has live Claude sessions
#            assigned to it (see `clare status`).
# <message>  Free text. Joined with spaces and delivered as a user prompt to
#            every assigned session.
#
# Examples:
#   rsend roadmap "are we still blocked on auth?"
#   rsend @backend "deploy is green, you can resume merges"
#
# Implementation: thin wrapper over `clare broadcast <convo> <msg> --yes`.
# Requires the `clare` CLI on $PATH (https://…/@clare).

set -euo pipefail

if [ $# -lt 2 ] || [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
    cat >&2 <<'USAGE'
usage: rsend <convo> <message...>

  <convo>    Clare project name or @group
  <message>  text to deliver (any number of args, joined with spaces)

Lists live targets:   clare status
USAGE
    exit 2
fi

target="$1"; shift

if ! command -v clare >/dev/null 2>&1; then
    echo "rsend: 'clare' not found on PATH — install @clare first" >&2
    exit 127
fi

exec clare broadcast "$target" "$@" --yes
