<?php
if (!defined('ABSPATH')) exit;

if (!class_exists('VMO_Website_Generation_Agent_Base')) {
    class VMO_Website_Generation_Agent_Base {
        protected $agent_key = '';
        protected $label = '';
        protected $tier = 'strategic';
        protected $focus = '';
        protected $requirements = array();
        protected $artifacts = array();

        public function __construct($agent_key, $label, $tier, $focus, array $requirements = array(), array $artifacts = array()) {
            $this->agent_key = sanitize_key((string) $agent_key);
            $this->label = sanitize_text_field((string) $label);
            $this->tier = sanitize_key((string) $tier);
            $this->focus = sanitize_text_field((string) $focus);
            $this->requirements = $requirements;
            $this->artifacts = $artifacts;
        }

        public function key() {
            return $this->agent_key;
        }

        public function model() {
            if (function_exists('vmo_get_website_agent_model')) {
                return vmo_get_website_agent_model($this->agent_key);
            }
            if (function_exists('vmo_get_model')) {
                return vmo_get_model($this->tier === 'supreme' ? 'supreme' : 'strategic');
            }
            return $this->tier === 'supreme' && defined('VMO_MODEL_SUPREME') ? VMO_MODEL_SUPREME : (defined('VMO_MODEL_STRATEGIC') ? VMO_MODEL_STRATEGIC : 'gpt-5.5');
        }

        public function run(array $context = array()) {
            $result = $this->build_output($context);
            return array(
                'agent' => $this->agent_key,
                'class' => get_class($this),
                'label' => $this->label,
                'model' => $this->model(),
                'tier' => $this->tier,
                'version' => 'v2.0-2026-04-30',
                'execution_status' => 'model_bound_contract_ready',
                'ai_execution_mode' => 'canonical_orchestrated_model_call',
                'direct_publish_allowed' => false,
                'output_contract' => 'structured_json_only',
                'prompt' => $this->build_agent_prompt($context),
                'input_contract' => $this->build_input_contract(),
                'output_schema' => $this->build_output_schema(),
                'acceptance_criteria' => $this->build_acceptance_criteria(),
                'blocking_failures' => $this->build_blocking_failures(),
                'verification_hooks' => $this->build_verification_hooks(),
                'result' => $result,
            );
        }

        protected function build_output(array $context) {
            return array(
                'focus' => $this->focus,
                'requirements' => $this->requirements,
                'required_artifacts' => $this->artifacts,
                'context_signals' => $this->extract_context_signals($context),
                'handoff_policy' => 'return_structured_state_to_canonical_pipeline',
            );
        }

        protected function build_agent_prompt(array $context) {
            $signals = $this->extract_context_signals($context);
            return trim($this->label . "\n"
                . 'Focus: ' . $this->focus . "\n"
                . 'Model: ' . $this->model() . "\n"
                . 'Return strict JSON only. Do not publish, preview, or call legacy/basic generators. ' . "\n"
                . 'Required inputs: ' . implode(', ', array_map('strval', $this->requirements)) . "\n"
                . 'Required artifacts: ' . implode(', ', array_map('strval', $this->artifacts)) . "\n"
                . 'Context signals: ' . wp_json_encode($signals));
        }

        protected function build_input_contract() {
            return array(
                'requires' => array_values(array_map('strval', $this->requirements)),
                'canonical_context_required' => true,
                'business_brief_required' => true,
                'research_context_allowed' => true,
                'existing_component_state_allowed' => true,
            );
        }

        protected function build_output_schema() {
            return array(
                'format' => 'json_object',
                'agent' => 'string',
                'summary' => 'string',
                'decisions' => 'array',
                'required_artifacts' => array_values(array_map('strval', $this->artifacts)),
                'component_state_updates' => 'array',
                'media_requests' => 'array',
                'tracking_requirements' => 'array',
                'qa_requirements' => 'array',
                'handoff_policy' => 'return_structured_state_to_canonical_pipeline',
            );
        }

        protected function build_acceptance_criteria() {
            $criteria = array(
                'Uses VMO_Canonical_Website_Pipeline only.',
                'Returns structured JSON artifacts for canonical assembly.',
                'Does not expose preview, publish, or user-facing fallback output.',
                'Preserves standalone HTML/CSS/JS public runtime contract.',
                'Preserves react-style component state and builder ownership.',
            );
            foreach ($this->artifacts as $artifact) {
                $criteria[] = 'Provides artifact: ' . (string) $artifact . '.';
            }
            return array_values(array_unique($criteria));
        }

        protected function build_blocking_failures() {
            return array(
                'legacy_or_basic_generator_called_directly',
                'missing_required_structured_artifact',
                'unresolved_media_markers_at_preview_or_publish',
                'wordpress_runtime_dependency_in_public_output',
                'component_state_missing_or_not_source_of_truth',
                'final_qa_gate_failed',
            );
        }

        protected function build_verification_hooks() {
            return array(
                'canonical_pipeline_context' => 'canonical_generation_context.v2_agent_plan.agents.' . $this->agent_key,
                'operations_manifest' => 'agent_plan.agents.' . $this->agent_key,
                'final_qa_gate' => 'vmo_website_final_qa_gate',
                'publish_gate' => 'preview_ready_and_media_complete_required',
            );
        }

        protected function extract_context_signals(array $context) {
            $business_type = strtolower((string) ($context['business_type'] ?? $context['industry'] ?? $context['extracted_information']['industry'] ?? ''));
            $serialized = strtolower(wp_json_encode($context));
            return array(
                'business_type' => $business_type,
                'is_food' => (bool) preg_match('/restaurant|food|cafe|bakery|bar|catering/', $serialized),
                'is_ecommerce' => (bool) preg_match('/ecommerce|e-commerce|shop|store|product|cart|checkout|shipping/', $serialized),
                'is_booking' => (bool) preg_match('/booking|appointment|reservation|schedule/', $serialized),
                'has_location' => (bool) preg_match('/address|service area|location|city|map/', $serialized),
                'visual_preset' => sanitize_key((string) ($context['canonical_generation_context']['selected_visual_preset'] ?? $context['visual_preset'] ?? '')),
            );
        }
    }
}

if (!class_exists('VMO_Agent_Master_Website_Orchestrator')) {
    class VMO_Agent_Master_Website_Orchestrator extends VMO_Website_Generation_Agent_Base {
        public function __construct() { parent::__construct('master_orchestrator', 'Master Website Orchestrator', 'supreme', 'Classify the website mode, engine mix, AI-planned operational flow, agents, media needs, and preview policy.', array('business context', 'research context', 'goals', 'systems', 'approved business model'), array('site_mode', 'business_engines', 'required_agents', 'business_flow_plan', 'preview_policy')); }
        protected function build_output(array $context) {
            $signals = $this->extract_context_signals($context);
            $site_mode = $signals['is_food'] ? 'restaurant_food_appetite_page' : ($signals['is_ecommerce'] ? 'ecommerce_storytelling_site' : 'premium_standalone_experience');
            if ($signals['visual_preset'] === 'fullscreen_minisite_hero' || strpos($signals['visual_preset'], 'minisite') !== false) {
                $site_mode = 'fullscreen_minisite';
            }
            return array(
                'site_mode' => $site_mode,
                'business_engines' => array_values(array_filter(array($signals['is_food'] ? 'restaurant' : '', $signals['is_ecommerce'] ? 'ecommerce' : '', $signals['is_booking'] ? 'booking' : '', 'ai_business_flow_engine', 'dashboard_connected_website'))),
                'visual_benchmark_family' => array_values(array_filter(array($signals['visual_preset'], $signals['is_food'] ? 'restaurant_appetite' : '', $signals['is_ecommerce'] ? 'product_storytelling' : '', 'premium_standalone_export'))),
                'required_agents' => array('jerreme_handoff_normalizer', 'website_strategy', 'business_flow_designer', 'visual_experience_director', 'hero_scene_director', 'motion_experience_director', 'media_director', 'mobile_experience_director', 'website_kpi_wiring', 'final_qa_critic'),
                'business_flow_policy' => 'ai_designed_from_consultation_and_research_then_composed_with_modular_engines',
                'final_preview_policy' => 'block_until_media_complete_and_qa_passed',
                'context_signals' => $signals,
            );
        }
    }

    class VMO_Agent_Jerreme_Handoff_Normalizer extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('jerreme_handoff_normalizer', 'Jerreme Handoff / Consultation Normalizer', 'strategic', 'Convert consultation, research, roadmap, and approvals into a website generation brief.', array('business identity', 'approved recommendations', 'required website functions', 'dashboard dependencies'), array('website_brief', 'provisioning_dependencies')); } }
    class VMO_Agent_Website_Strategy extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('website_strategy', 'Website Strategy Agent', 'supreme', 'Define audience, psychology, trust objections, proof, conversion flow, and text density.', array('target audience', 'emotional hook', 'trust objections', 'conversion path'), array('strategy_brief', 'conversion_map')); } }
    class VMO_Agent_Competitor_Market_Intelligence extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('competitor_market_intelligence', 'Competitor & Market Intelligence Agent', 'supreme', 'Use competitor research to shape strategy without copying.', array('positioning gaps', 'SEO gaps', 'CTA patterns', 'trust signals'), array('market_opportunity_map')); } }
    class VMO_Agent_Visual_Color_Psychology extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('visual_color_psychology', 'Competitor Visual / Color Psychology Agent', 'supreme', 'Turn market expectations into color, contrast, typography, image mood, and visual outclassing decisions.', array('palette psychology', 'contrast', 'image mood', 'typography tone'), array('visual_psychology_brief')); } }
    class VMO_Agent_Visual_Experience_Director extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('visual_experience_director', 'Visual Experience Director', 'supreme', 'Select the visual benchmark family, design language, density, depth, and premium experience rules.', array('benchmark family', 'visual language', 'premium menu', 'depth rules'), array('design_system_direction')); } }
    class VMO_Agent_Hero_Scene_Director extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('hero_scene_director', 'Hero Scene Director', 'supreme', 'Design the hero as a layered scene with background, subject, foreground content, CTA, and optional atmospherics.', array('minimum three hero layers', 'focal subject', 'CTA layer', 'mobile hero fallback'), array('hero_scene_plan')); } }
    class VMO_Agent_Motion_Experience_Director extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('motion_experience_director', 'Motion Experience Director', 'supreme', 'Choose GSAP, ScrollTrigger, parallax, click-detail, smooth-scroll, and reduced-motion grammar.', array('motion presets', 'reduced motion', 'mobile fallback', 'performance budget'), array('motion_plan')); } }
    class VMO_Agent_Media_Director extends VMO_Website_Generation_Agent_Base {
        public function __construct() { parent::__construct('media_director', 'Media Director Agent', 'supreme', 'Plan, classify, generate, attach, and block preview until required media is complete, including every ecommerce product media packet.', array('desktop/mobile assets', 'poster frames', 'transparent subjects', 'alt text', 'placement map', 'product card image', 'product hero image', 'gallery images', 'detail images', 'product lifestyle image', 'mobile fallback image', 'video poster when needed'), array('media_manifest', 'product_media_packet')); }
        protected function build_output(array $context) {
            $manifest = function_exists('vmo_get_website_media_manifest_service') ? vmo_get_website_media_manifest_service()->build_from_payload($context['website_payload'] ?? array(), $context) : array();
            return array('focus' => $this->focus, 'media_manifest' => $manifest, 'product_media_packet_required_before_preview' => true, 'preview_blocker' => empty($manifest['media_complete']), 'handoff_policy' => 'media_queue_then_final_qa');
        }
    }
    class VMO_Agent_Logo_Brand_Identity extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('logo_brand_identity', 'Logo & Brand Identity Agent', 'strategic', 'Handle logo intake/generation, favicon, brand mark, palette, font pairing, QR styling, and preloader direction.', array('logo', 'favicon', 'palette', 'font pairing'), array('brand_identity_pack')); } }
    class VMO_Agent_Navigation_Menu_Director extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('navigation_menu_director', 'Navigation & Menu Experience Agent', 'supreme', 'Choose premium desktop and mobile menus that stay simple, accessible, high-z-index, and CTA-forward.', array('floating glass menu', 'mobile bottom pill', 'sticky ecommerce buy path', 'accessibility'), array('navigation_plan')); } }
    class VMO_Agent_Fullscreen_Minisite_Experience extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('fullscreen_minisite_experience', 'Full-Screen Mini-Site Experience Agent', 'supreme', 'Plan hero-stage websites where menu pages open inside the same visual world.', array('full-screen panels', 'section transitions', 'visual-first low text'), array('minisite_structure')); } }
    class VMO_Agent_Ecommerce_Storytelling extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('ecommerce_storytelling', 'Ecommerce Storytelling Agent', 'supreme', 'Turn product sites into complete product content packets, scroll stories, quick views, click-to-detail, VMO Pay and shipping flows.', array('product title', 'short description', 'long description', 'product story', 'key benefits', 'technical details/specifications', 'materials ingredients dimensions compatibility care usage details where relevant', 'variant option descriptions', 'shipping fulfillment notes', 'SEO title and meta description', 'Product schema and Offer schema', 'media alt text', 'product FAQ', 'upsell cross-sell copy', 'checkout CTA', 'shipping triggers'), array('ecommerce_story_plan', 'product_content_packet', 'product_media_packet')); } }
    class VMO_Agent_Food_Restaurant_Experience extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('food_restaurant_experience', 'Restaurant / Food Visual Appetite Agent', 'supreme', 'Make food websites appetite-focused with ordering/reservation CTAs, location, social proof, and food-appropriate overlays.', array('appetite hero', 'menu cards', 'order/reserve', 'tap-to-call', 'directions'), array('food_experience_plan')); } }
    class VMO_Agent_Business_Flow_Designer extends VMO_Website_Generation_Agent_Base {
        public function __construct() { parent::__construct('business_flow_designer', 'AI Business Flow Designer Agent', 'supreme', 'Design the operational flow from consultation, research, approved business model, VMO Pay actions, modular engines, dashboard completion statuses, notifications, CRM, CFO, and KPI wiring without treating benchmarks as templates.', array('approved business model', 'visitor transaction steps', 'owner operational steps', 'completion statuses', 'payment actions', 'notifications', 'records', 'CRM mapping', 'CFO mapping', 'website forms buttons pages'), array('business_flow_plan', 'operational_module_contract', 'completion_status_contract')); }
        public function model() {
            if (function_exists('vmo_get_website_agent_model')) {
                return vmo_get_website_agent_model($this->agent_key);
            }
            if (defined('VMO_MODEL_SUPREME')) {
                return VMO_MODEL_SUPREME;
            }
            return 'gpt-5.5-pro';
        }
        protected function build_output(array $context) {
            $metadata = array();
            foreach (array('business_flow_plan', 'vmo_business_flow_plan', 'operational_flow_plan', 'business_model', 'website_payload', 'business_data', 'canonical_generation_context') as $key) {
                if (!empty($context[$key]) && is_array($context[$key])) {
                    $metadata[$key] = $context[$key];
                }
            }
            $plan = array(
                'business_flow_type' => 'custom_business_flow',
                'modules_required' => array('vmo_pay', 'crm_history', 'cfo_reporting', 'dashboard_completion_queue', 'notification_composer', 'kpi_tracking'),
                'visitor_steps' => array('discover_offer', 'review_details', 'submit_action_or_checkout', 'receive_confirmation'),
                'owner_steps' => array('review_transaction_or_request', 'complete_next_operational_step', 'mark_flow_complete', 'review_cfo_and_kpi_impact'),
                'completion_statuses' => array('awaiting_fulfillment', 'in_progress', 'completed', 'cancelled', 'refunded'),
                'payment_actions' => array('checkout_start', 'payment_succeeded', 'order_synced_to_business_flow'),
                'notifications' => array('buyer_receipt_or_confirmation', 'owner_next_action_guidance'),
                'records' => array('vmo_store_orders', 'vmo_business_flow_instances', 'vmo_fulfillment_tasks', 'vmo_transaction_links', 'crm_customer_history'),
                'dashboard_cfo_crm_kpi_mapping' => array('paid_revenue', 'pending_fulfillment_revenue', 'completed_fulfilled_revenue', 'refunds', 'fees', 'taxes', 'net_revenue', 'customer_history', 'conversion_events'),
                'website_requirements' => array('clear offer action', 'VMO Pay checkout when required', 'status-aware confirmation copy', 'tracking attributes for business flow events'),
                'benchmark_policy' => 'benchmarks_are_minimum_quality_standards_not_templates',
            );
            if (class_exists('VMO_Business_Flow_Engine')) {
                $plan = VMO_Business_Flow_Engine::get_instance()->design_flow_plan_from_context($metadata);
            }
            return array(
                'business_flow_plan' => $plan,
                'operational_module_contract' => array('source' => 'ai_planned_business_flow', 'runtime_bridge' => 'VMO_Business_Flow_Engine', 'payment_truth' => 'vmo_store_orders.status', 'completion_truth' => 'business_flow_status_and_fulfillment_status'),
                'completion_status_contract' => $plan['completion_statuses'] ?? array(),
                'handoff_policy' => 'persist_business_flow_plan_to_generated_site_package_and_payment_metadata',
            );
        }
    }
    class VMO_Agent_Mobile_Experience_Director extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('mobile_experience_director', 'Mobile Experience Director', 'supreme', 'Create a separate mobile pass with crop, fallback, menu, sticky CTA, swipe/tap behavior, and performance limits.', array('mobile hero crop', 'sticky CTA', 'tap targets', 'motion fallback'), array('mobile_experience_plan')); } }
    class VMO_Agent_WordPress_Security_Integrator extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('wordpress_security_integrator', 'Standalone Export & Safety Agent', 'strategic', 'Map component state into standalone HTML/CSS/JS that can be staged in WordPress but never depends on WordPress at runtime.', array('scoped CSS', 'safe scripts', 'sanitized HTML', 'resolved media assets', 'SEO meta', 'no shortcodes', 'no wp-admin/admin-ajax/wp-json runtime dependency'), array('standalone_render_contract')); } }
    class VMO_Agent_SEO_Content_Intelligence extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('seo_content_intelligence', 'SEO & Content Expansion Agent', 'supreme', 'Make SEO part of architecture: keywords, competitors, schema, internal links, content roadmap, and Today/Actions.', array('keywords', 'schema', 'local SEO', 'content roadmap'), array('seo_architecture_plan')); } }
    class VMO_Agent_Website_KPI_Wiring extends VMO_Website_Generation_Agent_Base {
        public function __construct() { parent::__construct('website_kpi_wiring', 'Analytics / KPI Wiring Agent', 'strategic', 'Wire generated websites to visitors, events, CRM, payments, business-flow statuses, shipping, SEO, dashboard, Today, and continuous improvement.', array('visitor tracking', 'CTA clicks', 'forms', 'product views', 'checkout starts', 'purchases', 'business flow status', 'shipping status'), array('tracking_contract', 'dashboard_indicators')); }
        protected function build_output(array $context) {
            return array(
                'tracking_contract' => array(
                    'tracker' => 'vmo_analytics_tracker',
                    'required_events' => array('page_view', 'cta_click', 'form_submit', 'phone_click', 'email_click', 'product_view', 'checkout_start', 'purchase', 'order_created', 'business_flow_status', 'fulfillment_completed', 'shipping_status', 'seo_status'),
                    'required_attributes' => array('data-vmo-track', 'data-vmo-event', 'data-vmo-section', 'data-vmo-product-id'),
                    'dashboard_targets' => array('website_visitors', 'page_views', 'sources_referrers', 'utm_campaigns', 'conversion_rate', 'orders', 'paid_revenue', 'pending_fulfillment_revenue', 'completed_fulfilled_revenue', 'net_revenue', 'seo_score', 'today_actions'),
                ),
                'handoff_policy' => 'persist_to_operations_manifest_and_kpi_dashboard',
            );
        }
    }
    class VMO_Agent_Website_Refinement_Assistant extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('website_refinement_assistant', 'VMO/Jarvis Website Refinement Agent', 'strategic', 'Support post-generation text, voice, media, layout, mobile, SEO, section, hero, menu, and style refinement.', array('builder chat', 'voice instructions', 'media replacement', 'mobile-only edits'), array('refinement_capabilities')); } }
    class VMO_Agent_Final_QA_Critic extends VMO_Website_Generation_Agent_Base { public function __construct() { parent::__construct('final_qa_critic', 'Final QA / Critic Agent', 'supreme', 'Block weak sites across strategy, premium visuals, hero, media, mobile, navigation, conversion, SEO, dashboard, operations, performance, accessibility, safety, and wow factor.', array('v2 score thresholds', 'critical blockers', 'remediation tasks'), array('final_qa_contract')); } }
}

if (!function_exists('vmo_get_website_generation_agents')) {
    function vmo_get_website_generation_agents() {
        return array(
            'master_orchestrator' => new VMO_Agent_Master_Website_Orchestrator(),
            'jerreme_handoff_normalizer' => new VMO_Agent_Jerreme_Handoff_Normalizer(),
            'website_strategy' => new VMO_Agent_Website_Strategy(),
            'competitor_market_intelligence' => new VMO_Agent_Competitor_Market_Intelligence(),
            'visual_color_psychology' => new VMO_Agent_Visual_Color_Psychology(),
            'visual_experience_director' => new VMO_Agent_Visual_Experience_Director(),
            'hero_scene_director' => new VMO_Agent_Hero_Scene_Director(),
            'motion_experience_director' => new VMO_Agent_Motion_Experience_Director(),
            'media_director' => new VMO_Agent_Media_Director(),
            'logo_brand_identity' => new VMO_Agent_Logo_Brand_Identity(),
            'navigation_menu_director' => new VMO_Agent_Navigation_Menu_Director(),
            'fullscreen_minisite_experience' => new VMO_Agent_Fullscreen_Minisite_Experience(),
            'ecommerce_storytelling' => new VMO_Agent_Ecommerce_Storytelling(),
            'food_restaurant_experience' => new VMO_Agent_Food_Restaurant_Experience(),
            'business_flow_designer' => new VMO_Agent_Business_Flow_Designer(),
            'mobile_experience_director' => new VMO_Agent_Mobile_Experience_Director(),
            'wordpress_security_integrator' => new VMO_Agent_WordPress_Security_Integrator(),
            'seo_content_intelligence' => new VMO_Agent_SEO_Content_Intelligence(),
            'website_kpi_wiring' => new VMO_Agent_Website_KPI_Wiring(),
            'website_refinement_assistant' => new VMO_Agent_Website_Refinement_Assistant(),
            'final_qa_critic' => new VMO_Agent_Final_QA_Critic(),
        );
    }
}

if (!function_exists('vmo_get_website_v2_required_agent_keys')) {
    function vmo_get_website_v2_required_agent_keys() {
        return array(
            'master_orchestrator',
            'jerreme_handoff_normalizer',
            'website_strategy',
            'competitor_market_intelligence',
            'visual_color_psychology',
            'visual_experience_director',
            'hero_scene_director',
            'motion_experience_director',
            'media_director',
            'logo_brand_identity',
            'navigation_menu_director',
            'fullscreen_minisite_experience',
            'ecommerce_storytelling',
            'food_restaurant_experience',
            'business_flow_designer',
            'mobile_experience_director',
            'wordpress_security_integrator',
            'seo_content_intelligence',
            'website_kpi_wiring',
            'website_refinement_assistant',
            'final_qa_critic',
        );
    }
}

if (!function_exists('vmo_build_website_v2_agent_plan')) {
    function vmo_build_website_v2_agent_plan(array $context = array(), array $canonical_context = array()) {
        $context['canonical_generation_context'] = $canonical_context;
        $agents = vmo_get_website_generation_agents();
        $outputs = array();
        foreach ($agents as $key => $agent) {
            $outputs[$key] = $agent->run($context);
        }
        $required_agent_keys = vmo_get_website_v2_required_agent_keys();
        $missing_agents = array_values(array_diff($required_agent_keys, array_keys($outputs)));
        $acceptance_matrix = array();
        foreach ($outputs as $key => $output) {
            $acceptance_matrix[$key] = array(
                'model' => (string) ($output['model'] ?? ''),
                'execution_status' => (string) ($output['execution_status'] ?? ''),
                'acceptance_criteria' => $output['acceptance_criteria'] ?? array(),
                'blocking_failures' => $output['blocking_failures'] ?? array(),
                'verification_hooks' => $output['verification_hooks'] ?? array(),
            );
        }
        return array(
            'version' => 'v2.0-2026-04-30',
            'pipeline' => 'VMO_Canonical_Website_Pipeline',
            'agent_count' => count($outputs),
            'required_agent_count' => count($required_agent_keys),
            'all_required_agents_registered' => empty($missing_agents),
            'missing_required_agents' => $missing_agents,
            'production_contract_enforced' => empty($missing_agents),
            'execution_mode' => 'model_bound_agent_contracts_orchestrated_by_canonical_pipeline',
            'preview_policy' => 'block_until_media_complete_and_final_qa_passes',
            'mandatory_artifacts' => array('website_brief', 'strategy_brief', 'business_flow_plan', 'operational_module_contract', 'completion_status_contract', 'design_system_direction', 'hero_scene_plan', 'motion_plan', 'media_manifest', 'brand_identity_pack', 'navigation_plan', 'ecommerce_story_plan', 'mobile_experience_plan', 'standalone_render_contract', 'seo_architecture_plan', 'tracking_contract', 'final_qa_contract'),
            'mandatory_final_gates' => array('canonical_pipeline_only', 'business_flow_plan_present', 'payment_to_fulfillment_bridge_present', 'completion_status_contract_present', 'media_manifest_complete', 'final_qa_gate_passed', 'preview_ready_and_media_complete', 'standalone_runtime_safe', 'component_state_manifest_present', 'kpi_tracking_contract_present'),
            'component_state_policy' => array(
                'source_of_truth' => 'react_style_component_state',
                'builder_shell' => 'wordpress_plugin_can_stage_and_export_only',
                'runtime_output' => 'standalone_html_css_js',
                'forbidden_runtime_dependencies' => array('shortcodes', 'wp-admin', 'admin-ajax.php', 'wp-json', 'wp-content/plugins', 'wp-content/themes', 'window.wp'),
                'builder_editing' => 'vmo_plugin_template_component_props_then_rendered_html',
                'wordpress_editor_usage' => 'disabled_for_generated_sites',
            ),
            'orchestration_sequence' => array_keys($agents),
            'acceptance_matrix' => $acceptance_matrix,
            'agents' => $outputs,
        );
    }
}
