#!/usr/bin/env bash ############################################################################### # BlackRoad Traffic Light System # Status tracking and workflow management for native-ai-quantum-energy # # Usage: # ./blackroad-traffic-light.sh init # Initialize status database # ./blackroad-traffic-light.sh status # Show current status # ./blackroad-traffic-light.sh set [msg] # Set status (green|yellow|red) # ./blackroad-traffic-light.sh check # Run automated checks # ./blackroad-traffic-light.sh history # Show status history # ./blackroad-traffic-light.sh report # Generate status report ############################################################################### set -e REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" STATUS_DB="${REPO_ROOT}/.traffic-light-status.db" STATUS_FILE="${REPO_ROOT}/.traffic-light-status" # Colors for output RED='\033[0;31m' YELLOW='\033[1;33m' GREEN='\033[0;32m' BLUE='\033[0;34m' NC='\033[0m' # No Color ############################################################################### # Initialize the status database ############################################################################### init_status_db() { echo "Initializing BlackRoad Traffic Light System..." # Create simple status file cat > "${STATUS_FILE}" <> "${STATUS_FILE}" case "${new_status}" in green) echo -e "${GREEN}✓${NC} Status set to: ${GREEN}GREENLIGHT${NC}" ;; yellow) echo -e "${YELLOW}⚠${NC} Status set to: ${YELLOW}YELLOWLIGHT${NC}" ;; red) echo -e "${RED}✗${NC} Status set to: ${RED}REDLIGHT${NC}" ;; esac echo "Message: ${message}" } ############################################################################### # Run automated checks ############################################################################### run_checks() { echo "Running automated status checks..." echo "" local issues=0 local warnings=0 # Check if tests exist and run them if [[ -d "${REPO_ROOT}/tests" ]]; then echo -ne "Checking tests... " if command -v pytest &> /dev/null; then if pytest "${REPO_ROOT}/tests" -q --tb=no &> /dev/null; then echo -e "${GREEN}✓ PASS${NC}" else echo -e "${RED}✗ FAIL${NC}" ((issues++)) fi else echo -e "${YELLOW}⚠ pytest not installed${NC}" ((warnings++)) fi fi # Check for Python syntax errors echo -ne "Checking Python syntax... " if find "${REPO_ROOT}" -name "*.py" -exec python3 -m py_compile {} + 2>/dev/null; then echo -e "${GREEN}✓ PASS${NC}" else echo -e "${RED}✗ FAIL${NC}" ((issues++)) fi # Check for required files echo -ne "Checking required files... " local missing=0 for file in README.md LICENSE; do if [[ ! -f "${REPO_ROOT}/${file}" ]]; then ((missing++)) fi done if [[ ${missing} -eq 0 ]]; then echo -e "${GREEN}✓ PASS${NC}" else echo -e "${YELLOW}⚠ ${missing} file(s) missing${NC}" ((warnings++)) fi echo "" echo "Check Results:" echo " Issues: ${issues}" echo " Warnings: ${warnings}" echo "" # Determine recommended status if [[ ${issues} -gt 0 ]]; then echo -e "Recommended status: ${RED}REDLIGHT${NC}" echo "Run: $0 set red \"Automated checks failed\"" elif [[ ${warnings} -gt 0 ]]; then echo -e "Recommended status: ${YELLOW}YELLOWLIGHT${NC}" echo "Run: $0 set yellow \"Automated checks show warnings\"" else echo -e "Recommended status: ${GREEN}GREENLIGHT${NC}" echo "Run: $0 set green \"All automated checks passed\"" fi } ############################################################################### # Show status history ############################################################################### show_history() { if [[ ! -f "${STATUS_FILE}" ]]; then echo -e "${YELLOW}⚠${NC} No status history available" return 1 fi echo "" echo "═══════════════════════════════════════════════════" echo " Status History" echo "═══════════════════════════════════════════════════" echo "" grep -v "^#" "${STATUS_FILE}" | while IFS='|' read -r timestamp status message author; do case "${status}" in green) echo -e "${GREEN}🟢${NC} ${timestamp} - ${message} (${author})" ;; yellow) echo -e "${YELLOW}🟡${NC} ${timestamp} - ${message} (${author})" ;; red) echo -e "${RED}🔴${NC} ${timestamp} - ${message} (${author})" ;; esac done echo "" } ############################################################################### # Generate status report ############################################################################### generate_report() { local current_status=$(get_current_status) echo "" echo "═══════════════════════════════════════════════════" echo " BlackRoad Traffic Light Report" echo " Repository: native-ai-quantum-energy" echo " Generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" echo "═══════════════════════════════════════════════════" echo "" show_status echo "" echo "Recent History:" echo "───────────────────────────────────────────────────" grep -v "^#" "${STATUS_FILE}" | tail -5 | while IFS='|' read -r timestamp status message author; do echo " ${timestamp}: ${status} - ${message}" done echo "" echo "Documentation:" echo "───────────────────────────────────────────────────" case "${current_status}" in green) echo " See GREENLIGHT.md for full details" ;; yellow) echo " See YELLOWLIGHT.md for action items" ;; red) echo " See REDLIGHT.md for critical issues" ;; esac echo "" echo " BlackRoad Codex: See BLACKROAD-CODEX.md" echo "" } ############################################################################### # Main ############################################################################### main() { local cmd="${1:-status}" case "${cmd}" in init) init_status_db ;; status) show_status ;; set) if [[ $# -lt 2 ]]; then echo "Usage: $0 set [message]" exit 1 fi set_status "$2" "$3" ;; check) run_checks ;; history) show_history ;; report) generate_report ;; help|--help|-h) echo "BlackRoad Traffic Light System" echo "" echo "Usage:" echo " $0 init Initialize status tracking" echo " $0 status Show current status" echo " $0 set [msg] Set status (green|yellow|red)" echo " $0 check Run automated checks" echo " $0 history Show status history" echo " $0 report Generate status report" echo " $0 help Show this help" echo "" ;; *) echo -e "${RED}✗${NC} Unknown command: ${cmd}" echo "Run: $0 help" exit 1 ;; esac } main "$@"