#!/bin/bash # Bounded `flutter analyze` for agents (from app/): tool/analyze.sh [paths...] # Prints one verdict line with error/warning/info counts and the duration, at # most ANALYZE_MAX_ISSUES (default 40) issue lines, and the full log path. # Exits with flutter analyze's own status. FLUTTER=${FLUTTER:-/Users/alan/development/flutter/bin/flutter} max=${ANALYZE_MAX_ISSUES:-40} [ -f pubspec.yaml ] || cd "$(dirname "$0")/.." || exit 1 tmp=${TMPDIR:-/tmp} log=$(mktemp "${tmp%/}/flutter-analyze.XXXXXX") || exit 1 start=$SECONDS "$FLUTTER" analyze "$@" > "$log" 2>&1; status=$? issues=$(grep -cE '^ *(error|warning|info) • ' "$log") count() { grep -cE "^ *$1 • " "$log"; } if [ "$status" = 0 ] && [ "$issues" = 0 ]; then echo "analyze: clean; $((SECONDS-start))s; exit 0" else echo "analyze: $(count error) errors, $(count warning) warnings, $(count info) infos; $((SECONDS-start))s; exit $status" if [ "$issues" = 0 ]; then tail -20 "$log" | cut -c1-300 else grep -E '^ *(error|warning|info) • ' "$log" | head -n "$max" | cut -c1-300 [ "$issues" -gt "$max" ] && echo "... and $((issues-max)) more issues" fi fi echo "full output: $log" exit $status