TodoWrite

Add Deep Analysis preset prompts as JS constant

Add Deep Analysis button and results panel to thread_view.php UI

Implement automated multi-pass analysis function

Implementing automated multi-pass analysis

Add progress tracking and sequential pass execution

Test the automated flow


Todos have been modified successfully. Ensure that you continue to use the todo list to track your progress. Please proceed with the current tasks if applicable

Add Deep Analysis preset prompts as JS constant

Add Deep Analysis button and results panel to thread_view.php UI

Implement automated multi-pass analysis function

Implementing automated multi-pass analysis

Add progress tracking and sequential pass execution

Test the automated flow

Test the automated flow


Now add the main JS — the `DEEP_ANALYSIS_PASSES` constant and the `runDeepAnalysis()` function. I'll add it after the `AI_AGENTS` constant block:


  1520→                name: 'Profiler',
  1521→                icon: '\uD83D\uDC64',
  1522→                systemPrompt: 'You are a contact profiling specialist. Build a psychological and business profile of the contact based on their emails:\n- Communication style (formal/casual, verbose/concise)\n- Decision-making patterns\n- Negotiation style and tendencies\n- Responsiveness and reliability\n- Priorities and motivations\n- Relationship health indicators\n- Loyalty signals\nProvide specific examples from the emails to support your assessment.',
  1523→                quickPrompts: [
  1524→                    'Build a full profile',
  1525→                    'Communication style analysis',
  1526→                    'How loyal is this contact?',
  1527→                    'What motivates them?'
  1528→                ]
  1529→            },
  1530→            email_composer: {
  1531→                name: 'Composer',
  1532→                icon: '\u270D\uFE0F',
  1533→                systemPrompt: 'You are a professional email composer. Based on the conversation context:\n- Draft a professional, well-structured reply\n- Match the appropriate tone (formal/casual based on the thread)\n- Address all open questions or action items\n- Be concise but thorough\n- Include appropriate greetings and sign-offs\nOutput ONLY the email draft, ready to send.',
  1534→                quickPrompts: [

                name: 'Profiler',
                icon: '\uD83D\uDC64',
                systemPrompt: 'You are a contact profiling specialist. Build a psychological and business profile of the contact based on their emails:\n- Communication style (formal/casual, verbose/concise)\n- Decision-making patterns\n- Negotiation style and tendencies\n- Responsiveness and reliability\n- Priorities and motivations\n- Relationship health indicators\n- Loyalty signals\nProvide specific examples from the emails to support your assessment.',
                quickPrompts: [
                    'Build a full profile',
                    'Communication style analysis',
                    'How loyal is this contact?',
                    'What motivates them?'
                ]
            },
            email_composer: {
                name: 'Composer',
                icon: '\u270D\uFE0F',
                systemPrompt: 'You are a professional email composer. Based on the conversation context:\n- Draft a professional, well-structured reply\n- Match the appropriate tone (formal/casual based on the thread)\n- Address all open questions or action items\n- Be concise but thorough\n- Include appropriate greetings and sign-offs\nOutput ONLY the email draft, ready to send.',
                quickPrompts: [


  1537→                    'Compose a polite decline',
  1538→                    'Draft a meeting request'
  1539→                ]
  1540→            }
  1541→        };
  1542→
  1543→        let selectedAgent = 'general';
  1544→
  1545→        // ============================================
  1546→        // TOKEN ESTIMATION

                    'Compose a polite decline',
                    'Draft a meeting request'
                ]
            }
        };

        let selectedAgent = 'general';

        // ============================================
        // TOKEN ESTIMATION


Edit

        let selectedAgent = 'general';

        // ============================================
        // DEEP ANALYSIS — Automated 5-Pass
        // ============================================
        const DEEP_ANALYSIS_PASSES = [
            {
                id: 'timeline',
                name: 'Business Relationship Timeline',
                agent: 'general',
                prompt: 'Analyze the COMPLETE email history chronologically. Build a detailed timeline of the business relationship:\n\n1. KEY MILESTONES: When did the relationship start? What were the major projects/deals? When did things start going wrong? When did we lose them?\n2. TURNING POINTS: Identify the exact moments where the relationship shifted negatively. Quote specific emails.\n3. OUR MISTAKES: What did we do wrong? Late deliveries, missed expectations, poor communication, pricing issues? Be brutally honest.\n4. THEIR SATISFACTION CURVE: Rate their satisfaction (1-10) at each major point in the timeline.\n5. UNRESOLVED ISSUES: What was never properly addressed or closed?\n6. LAST INTERACTION: What was the tone and content of our last exchange? Did we leave the door open?'
            },
            {
                id: 'pressure',
                name: 'Pressure & Manipulation Detection',
                agent: 'deception_detector',
                prompt: 'Analyze ALL emails from the other party\'s team members for:\n\n1. PRESSURE TACTICS: Where did they push unreasonable deadlines, scope changes, or price reductions? Quote specific examples.\n2. BROKEN PROMISES from their side: Did they commit to volumes, timelines, payments that didn\'t materialize?\n3. DOUBLE STANDARDS: Did they hold us to standards they didn\'t meet themselves?\n4. ESCALATION PATTERNS: When and why did they escalate to the CEO? Was it justified or a power play?\n5. BLAME SHIFTING: Did they blame us for problems that were partially/fully their responsibility?\n6. GOOD FAITH SIGNALS: To be fair — where were they genuinely reasonable or helpful?\n\nRate each team member\'s negotiation tactics: FAIR / AGGRESSIVE / MANIPULATIVE with evidence.'
            },
            {
                id: 'profiles',
                name: 'Psychological Profiles',
                agent: 'contact_profiler',
                prompt: 'Build detailed psychological and business profiles for EACH person from the other party in these emails. For each person provide:\n\n1. NAME & ROLE (infer from email signatures and context)\n2. COMMUNICATION STYLE: Formal/casual, direct/indirect, emotional/analytical\n3. DECISION-MAKING: Do they decide alone or need approval? Fast or slow? Risk-averse?\n4. WHAT MOTIVATES THEM: Price? Quality? Relationships? Status? Control?\n5. HOW THEY HANDLE CONFLICT: Confrontational, avoidant, diplomatic, passive-aggressive?\n6. THEIR INFLUENCE: Who has real power vs who is just executing?\n7. THEIR ATTITUDE TOWARD US: Positive, neutral, negative? Did it change over time?\n8. APPROACH STRATEGY: How should we approach THIS specific person to rebuild the relationship?\n\nPay special attention to the CEO — what drives them, what frustrates them, what would win them back?'
            },
            {
                id: 'financial',
                name: 'Financial & Business Patterns',
                agent: 'quote_analyst',
                prompt: 'Analyze the complete financial and business history:\n\n1. ALL PRICES QUOTED: Every amount, every project, every change order — create a table\n2. PRICING TRENDS: Did our prices go up/down? Did they push for discounts? How much did we concede?\n3. SCOPE CREEP: Where did work expand beyond original quotes without matching price increases?\n4. PAYMENT BEHAVIOR: Were they prompt payers? Any disputes over invoices?\n5. VOLUME vs COMMITMENT: Did they promise volume that didn\'t materialize?\n6. COMPETITOR MENTIONS: Did they mention other suppliers? Use competitor pricing as leverage?\n7. PROFITABILITY ASSESSMENT: Based on the patterns, were they a profitable client or were we losing money?\n8. RE-ENGAGEMENT PRICING: What pricing strategy should we use to win them back without repeating past mistakes?'
            },
            {
                id: 'winback',
                name: 'Win-Back Strategy',
                agent: 'general',
                prompt: 'Based on everything in these emails AND your previous analysis passes (timeline, pressure tactics, profiles, financials), create a CONCRETE win-back strategy:\n\n1. ROOT CAUSE SUMMARY: In 3 sentences, why did we lose them?\n2. WHAT THEY VALUED: What did they actually appreciate about working with us?\n3. WHAT THEY HATED: What were their consistent pain points?\n4. COMPETITIVE POSITION: What would make them choose us over their current supplier?\n5. APPROACH PLAN:\n   - WHO to contact first (and why that person)\n   - WHEN (timing considerations based on their business cycle)\n   - HOW (email, call, in-person meeting?)\n   - WHAT to say (draft an opening message)\n   - WHAT TO OFFER (specific value proposition addressing their known pain points)\n6. RED LINES: What should we NOT agree to if they come back? What terms caused problems before?\n7. SUCCESS METRICS: How will we know the re-engagement is working?\n\nBe specific. Reference actual names, actual issues, actual quotes from the emails.'
            }
        ];

        // ============================================
        // TOKEN ESTIMATION