#!/usr/bin/env bash set -euo pipefail usage() { cat <<'USAGE' Usage: research research --sources research --thinking research --deliver Examples: research swiftui state management in 2026 research --sources 5 best local llm coding setups research --thinking high ai coding agents comparison USAGE } source_count="3" thinking_level="" deliver="false" agent_id="${RESEARCH_AGENT_ID:-main}" while (( "$#" )); do case "$1" in --sources) shift if [[ $# -eq 0 ]]; then echo "[research] --sources requires a number" >&2 usage exit 1 fi source_count="$1" ;; --thinking) shift if [[ $# -eq 0 ]]; then echo "[research] --thinking requires a level" >&2 usage exit 1 fi thinking_level="$1" ;; --deliver) deliver="true" ;; -h|--help) usage exit 0 ;; --) shift break ;; -*) echo "[research] unknown argument: $1" >&2 usage exit 1 ;; *) break ;; esac shift done if [[ $# -eq 0 ]]; then echo "[research] topic is required" >&2 usage exit 1 fi if ! [[ "$source_count" =~ ^[0-9]+$ ]] || [[ "$source_count" -lt 1 ]]; then echo "[research] --sources must be a positive integer" >&2 exit 1 fi if ! command -v openclaw >/dev/null 2>&1; then echo "[research] openclaw CLI is required" >&2 exit 1 fi topic="$*" message=$( cat <