#!/usr/bin/env bash # Read-only local environment and repository diagnosis. set -u root=$(cd "$(dirname "$0")/.." && pwd) offline=0 case "${1:-}" in --offline) offline=1 ;; "") ;; -h|--help) echo "usage: tools/doctor.sh [--offline]"; exit 0 ;; *) echo "unknown option: $1" >&2; exit 2 ;; esac fail=0 warn=0 ok() { printf 'OK: %s\n' "$1"; } bad() { printf 'FAIL: %s\n' "$1"; fail=1; } warning() { printf 'WARN: %s\n' "$1"; warn=$((warn + 1)); } for command in git python3 cargo rustc bash; do if command -v "$command" >/dev/null 2>&1; then ok "$command ($(command -v "$command"))" else bad "required command missing: $command" fi done if [ "$fail" -eq 0 ]; then (cd "$root" && cargo metadata --no-deps --format-version 1 >/dev/null 2>&1) \ && ok "Cargo workspace metadata" || bad "Cargo workspace metadata" (cd "$root" && python3 tools/work_orders.py validate >/dev/null 2>&1) \ && ok "work-order metadata" || bad "work-order metadata (run tools/work_orders.py validate)" git -C "$root" rev-parse --verify origin/main >/dev/null 2>&1 \ && ok "origin/main available" || bad "origin/main unavailable" fi if [ -L "$root/target" ]; then target=$(readlink "$root/target") case "$target" in "$root"/*) ok "target symlink stays inside worktree" ;; *) bad "target points outside worktree: $target" ;; esac else ok "target is private or absent" fi if command -v sccache >/dev/null 2>&1; then ok "sccache available"; else warning "sccache unavailable (optional)"; fi if command -v pnpm >/dev/null 2>&1; then ok "pnpm available"; else warning "pnpm unavailable (needed only for site work)"; fi if [ "$(uname -s)" = Linux ] && [ -z "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ]; then command -v xvfb-run >/dev/null 2>&1 \ && ok "xvfb-run available for Bevy evidence" \ || warning "no display or xvfb-run; headless Bevy evidence cannot run" else ok "display path available for hidden Bevy evidence" fi if [ "$offline" -eq 1 ]; then warning "Tangled context/auth skipped (--offline)" elif command -v tang >/dev/null 2>&1; then (cd "$root" && tang context >/dev/null 2>&1) \ && ok "Tangled repository context/auth" \ || warning "Tangled context/auth unavailable" else warning "tang unavailable (decision issues omitted)" fi printf 'doctor: %s required failure(s), %s warning(s)\n' "$fail" "$warn" [ "$fail" -eq 0 ]