#!/bin/bash # Trinity → BlackRoad Codex Integration # Integrates Light Trinity standards into the Codex verification system set -e CODEX_DB="$HOME/.blackroad/codex/codex.db" # Ensure Codex database exists if [ ! -f "$CODEX_DB" ]; then echo "❌ BlackRoad Codex database not found" echo "Run: ~/blackroad-codex-verification-suite.sh init" exit 1 fi echo "🚦 Integrating Light Trinity into BlackRoad Codex..." # Add Trinity standards to Codex sqlite3 "$CODEX_DB" <<'SQL' -- Trinity Standards Table CREATE TABLE IF NOT EXISTS trinity_standards ( id INTEGER PRIMARY KEY AUTOINCREMENT, light_type TEXT NOT NULL CHECK(light_type IN ('greenlight', 'yellowlight', 'redlight')), category TEXT NOT NULL, standard_name TEXT NOT NULL, requirement TEXT NOT NULL, test_command TEXT, failure_severity TEXT CHECK(failure_severity IN ('critical', 'high', 'medium', 'low')), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Trinity Compliance Table CREATE TABLE IF NOT EXISTS trinity_compliance ( id INTEGER PRIMARY KEY AUTOINCREMENT, entity_type TEXT NOT NULL, -- 'template', 'deployment', 'task' entity_name TEXT NOT NULL, greenlight_pass BOOLEAN DEFAULT 0, yellowlight_pass BOOLEAN DEFAULT 0, redlight_pass BOOLEAN DEFAULT 0, compliance_status TEXT CHECK(compliance_status IN ('pending', 'partial', 'full', 'failed')), last_checked TIMESTAMP DEFAULT CURRENT_TIMESTAMP, notes TEXT ); -- Trinity Test Results CREATE TABLE IF NOT EXISTS trinity_test_results ( id INTEGER PRIMARY KEY AUTOINCREMENT, entity_name TEXT NOT NULL, light_type TEXT NOT NULL, test_name TEXT NOT NULL, passed BOOLEAN NOT NULL, details TEXT, tested_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Insert RedLight Standards INSERT OR IGNORE INTO trinity_standards (light_type, category, standard_name, requirement, test_command, failure_severity) VALUES ('redlight', 'brand', 'Color Palette', 'Must use BlackRoad gradient: #FF9D00→#0066FF', 'rl_test_passed "$name" "visual" "Brand colors"', 'critical'), ('redlight', 'performance', 'FPS Target', 'Must achieve >30 FPS (excellent: >60)', 'rl_performance_metrics "$name" "$fps" "$load" "$mem"', 'high'), ('redlight', 'performance', 'Load Time', 'Must load in <3s (excellent: <1s)', 'rl_performance_metrics "$name" "$fps" "$load" "$mem"', 'high'), ('redlight', 'accessibility', 'WCAG Compliance', 'Must meet WCAG 2.1 AA standards', 'rl_test_passed "$name" "accessibility" "WCAG 2.1 AA"', 'critical'), ('redlight', 'architecture', 'Self-Contained', 'Single HTML or minimal dependencies', 'rl_template_create "$name" "$cat" "$desc"', 'medium'), ('redlight', 'deployment', 'Deploy-Ready', 'Works on Cloudflare Pages/GitHub Pages', 'rl_template_deploy "$name" "$url" "$platform"', 'high'); -- Insert YellowLight Standards INSERT OR IGNORE INTO trinity_standards (light_type, category, standard_name, requirement, test_command, failure_severity) VALUES ('yellowlight', 'platform', 'Approved Platform', 'Must use approved platform (Cloudflare/Railway/Pi/DO)', 'yl_deployment_succeeded "$svc" "$platform" "$url"', 'critical'), ('yellowlight', 'monitoring', 'Health Endpoint', 'Must have /health or /status endpoint', 'yl_health_check "$svc" "$url" "$time"', 'critical'), ('yellowlight', 'reliability', 'Rollback Capability', 'Must support version rollback', 'yl_deployment_rollback "$svc" "$from" "$to"', 'high'), ('yellowlight', 'automation', 'CI/CD Pipeline', 'Must have automated deployment', 'yl_workflow_done "$repo" "passed" "$duration"', 'medium'), ('yellowlight', 'security', 'Secrets Management', 'No secrets in code, must use vault', 'yl_secret_stored "$name" "$vault"', 'critical'), ('yellowlight', 'logging', 'Memory Logging', 'All deployments logged to PS-SHA∞', 'yl_deployment_succeeded "$svc" "$platform" "$url"', 'high'); -- Insert GreenLight Standards INSERT OR IGNORE INTO trinity_standards (light_type, category, standard_name, requirement, test_command, failure_severity) VALUES ('greenlight', 'tracking', 'State Tracking', 'All work tracked in GreenLight', 'gl_wip "$task" "$status"', 'critical'), ('greenlight', 'events', 'NATS Publishing', 'State changes publish to NATS', 'N/A', 'high'), ('greenlight', 'phases', 'Phase Completion', 'All projects have phase tracking', 'gl_phase_done "$phase" "$proj" "$summary"', 'medium'), ('greenlight', 'coordination', 'Cross-Agent', 'Agent coordination logged', 'gl_coordinate "$from" "$to" "$msg"', 'medium'), ('greenlight', 'memory', 'PS-SHA∞ Logging', 'All actions logged to memory', 'N/A', 'critical'); SQL echo "✅ Trinity standards added to Codex" # Create Trinity compliance checker cat > "$HOME/trinity-check-compliance.sh" <<'CHECKER' #!/bin/bash # Check Trinity compliance for an entity ENTITY_NAME="$1" ENTITY_TYPE="${2:-template}" if [ -z "$ENTITY_NAME" ]; then echo "Usage: $0 [entity_type]" exit 1 fi CODEX_DB="$HOME/.blackroad/codex/codex.db" echo "🚦 Checking Trinity compliance for: $ENTITY_NAME" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" # Check each Light for light in greenlight yellowlight redlight; do echo "" case "$light" in greenlight) emoji="🟢" ;; yellowlight) emoji="🟡" ;; redlight) emoji="🔴" ;; esac echo "$emoji ${light^^} Standards:" sqlite3 "$CODEX_DB" < "$HOME/trinity-record-test.sh" <<'RECORDER' #!/bin/bash # Record a Trinity test result ENTITY_NAME="$1" LIGHT_TYPE="$2" # greenlight, yellowlight, redlight TEST_NAME="$3" PASSED="$4" # 0 or 1 DETAILS="${5:-}" if [ -z "$PASSED" ]; then echo "Usage: $0 [details]" exit 1 fi CODEX_DB="$HOME/.blackroad/codex/codex.db" # Record test result sqlite3 "$CODEX_DB" < 0 THEN 'partial' ELSE 'failed' END FROM trinity_test_results WHERE entity_name = '$ENTITY_NAME'; SQL echo "✅ Recorded: $TEST_NAME for $ENTITY_NAME ($LIGHT_TYPE) → $([ "$PASSED" = "1" ] && echo 'PASS' || echo 'FAIL')" RECORDER chmod +x "$HOME/trinity-record-test.sh" echo "✅ Created Trinity test recorder: ~/trinity-record-test.sh" # Update memory source ~/memory-greenlight-templates.sh gl_phase_done "integration" "Trinity Codex Integration" \ "Integrated Light Trinity standards into BlackRoad Codex: 3 new tables (trinity_standards, trinity_compliance, trinity_test_results), 16 standards defined (6 RedLight, 6 YellowLight, 5 GreenLight), 2 compliance tools created (~/trinity-check-compliance.sh, ~/trinity-record-test.sh). All future work validated against Trinity gates via Codex." \ "🌌" echo "" echo "🚦 Trinity → Codex Integration Complete!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "Tables created:" echo " • trinity_standards (16 standards)" echo " • trinity_compliance (entity tracking)" echo " • trinity_test_results (test history)" echo "" echo "Tools created:" echo " • ~/trinity-check-compliance.sh " echo " • ~/trinity-record-test.sh " echo "" echo "Usage:" echo " ~/trinity-record-test.sh 'blackroad-mars' 'redlight' 'Brand Colors' 1 'Gradient validated'" echo " ~/trinity-check-compliance.sh 'blackroad-mars'"