Now let me also update the JSON response to include the playbook key at the top level. Let me read the response part.


  5008→                if (!empty($r['deep_analysis_playbook']) && !isset($passes[$passNum]['playbook'])) {
  5009→                    $passes[$passNum]['playbook'] = $r['deep_analysis_playbook'];
  5010→                }
  5011→            }
  5012→
  5013→            // Re-index to sequential array
  5014→            ksort($passes);
  5015→            $passes = array_values($passes);
  5016→
  5017→            jsonResponse([
  5018→                'success' => true,
  5019→                'passes' => $passes,
  5020→                'total_responses' => count($responses)
  5021→            ]);
  5022→            break;
  5023→
  5024→        // ==========================================
  5025→        // Product Search - Start a new product search
  5026→        // ==========================================
  5027→        case 'startProductSearch':

                if (!empty($r['deep_analysis_playbook']) && !isset($passes[$passNum]['playbook'])) {
                    $passes[$passNum]['playbook'] = $r['deep_analysis_playbook'];
                }
            }

            // Re-index to sequential array
            ksort($passes);
            $passes = array_values($passes);

            jsonResponse([
                'success' => true,
                'passes' => $passes,
                'total_responses' => count($responses)
            ]);
            break;

        // ==========================================
        // Product Search - Start a new product search
        // ==========================================
        case 'startProductSearch':


I should also include the overall playbook key in the response — extract from the first pass that has it.


Edit

            // Re-index to sequential array
            ksort($passes);
            $passes = array_values($passes);

            jsonResponse([
                'success' => true,
                'passes' => $passes,
                'total_responses' => count($responses)
            ]);

            // Re-index to sequential array
            ksort($passes);
            $passes = array_values($passes);

            // Determine overall playbook key from first pass that has it
            $playbookKey = null;
            foreach ($passes as $p) {
                if (!empty($p['playbook'])) {
                    $playbookKey = $p['playbook'];
                    break;
                }
            }

            jsonResponse([
                'success' => true,
                'passes' => $passes,
                'playbook' => $playbookKey,
                'total_responses' => count($responses)
            ]);