#!/usr/bin/env bash set -euo pipefail . "${ACTION_PATH}/scripts/lib.sh" configure_git_author if [ -z "${BOT_TOKEN:-}" ]; then echo 'Run `claude setup-token` locally and set the `bot-token` action input.' > "${COMMENT_FILE}" post_comment exit 1 fi export CLAUDE_CODE_OAUTH_TOKEN="${BOT_TOKEN}" FINAL_PROMPT="$(render_prompt)" # Claude refuses --dangerously-skip-permissions as root outside a sandbox. export IS_SANDBOX=1 # Stream events so the runner sees output and does not kill the job as a zombie. STREAM_FILE="$(mktemp)" # The reviewer token is unset so the agent cannot approve as the bot. env -u REVIEWER_TOKEN \ claude --print --dangerously-skip-permissions --model claude-fable-5 \ --output-format stream-json --verbose "${FINAL_PROMPT}" \ | tee "${STREAM_FILE}" \ | jq -r --unbuffered '.message.content[]? | .thinking // .text // .name // empty' jq -r 'select(.type == "result") | .result // ("Bot failed: " + .subtype)' "${STREAM_FILE}" \ | ansifilter > "${COMMENT_FILE}" post_result