OpenClaw-Setup/openclaw-setup-max/scripts/research.sh

109 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'USAGE'
Usage:
research <topic...>
research --sources <count> <topic...>
research --thinking <off|minimal|low|medium|high> <topic...>
research --deliver <topic...>
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 <<EOF
Research topic: $topic
Instructions:
- Search the web for up-to-date, reputable sources.
- Review at least $source_count distinct sources.
- Summarize the key points in concise bullet points.
- Include a short "Sources" section with direct links.
- Mention relevant publish/event dates when time-sensitive.
EOF
)
cmd=(openclaw agent --channel last --message "$message")
if [[ -n "$agent_id" ]]; then
cmd+=(--agent "$agent_id")
fi
if [[ -n "$thinking_level" ]]; then
cmd+=(--thinking "$thinking_level")
fi
if [[ "$deliver" == "true" ]]; then
cmd+=(--deliver)
fi
"${cmd[@]}"