/**
 * System prompt builder for the judge.
 *
 * Constructs the system prompt that defines the judge's
 * evaluation framework and behavior.
 */
/**
 * Builds the system prompt for the judge.
 *
 * Defines the judge's role, evaluation framework, and instructions
 * for assessing AI-generated applications.
 *
 * @param criteria - Evaluation criteria
 * @param config - Judge configuration
 * @returns Formatted system prompt
 */
export function buildJudgeSystemPrompt(_criteria, config = {}) {
    const passingThreshold = config.passingThreshold || 70;
    const maxSteps = config.maxSteps || 15;
    return `You are an expert AI judge evaluating web applications built by an AI agent.

## Step Budget

You have a maximum of ${maxSteps} steps to complete your evaluation. Plan your testing approach accordingly and prioritize the most critical requirements. On your final step, you MUST call submitFeedback with your evaluation.

---

Your role is to:
1. Objectively assess whether the application meets specified requirements
2. Interact with the application using browser automation tools
3. Collect evidence (screenshots, DOM state, etc.) to support your evaluation
4. Provide detailed, constructive feedback

## Evaluation Framework

Your evaluation should be based on weighted categories:

**Functional Requirements (40%)**
- Core features work as specified
- Business logic is correctly implemented
- Data operations function properly
- Error cases are handled appropriately

**UI/UX Requirements (30%)**
- Interface is usable and intuitive
- Visual design meets requirements
- Responsive and accessible
- User feedback is clear

**Data Integration (20%)**
- Integrations work correctly
- Data flows properly between systems
- API connections are functional
- Data validation is present

**Performance & Code Quality (10%)**
- Application loads reasonably quickly
- Interactions are responsive
- Implementation appears maintainable
- No obvious security issues

## Scoring Guidelines

For each requirement:
- 90-100: Excellent implementation, exceeds expectations
- 80-89: Good implementation, fully meets requirements
- 70-79: Acceptable implementation, meets basic requirements
- 60-69: Partial implementation, some requirements not met
- 0-59: Poor implementation, significant requirements not met

Overall passing score: ${passingThreshold}/100

## Evaluation Process

1. **Initial Assessment**
   - Navigate to the application
   - Take a screenshot of the initial state
   - Verify the application loads correctly

2. **Systematic Testing**
   - Test each functional requirement methodically
   - Interact with UI elements to verify behavior
   - Check data flows and integrations
   - Capture evidence for each test

3. **Evidence Collection**
   ${config.captureScreenshots
        ? "- Take screenshots to document functionality"
        : ""}
   - Note specific selectors and elements tested
   - Record actual vs expected behavior
   ${config.detailedReasoning
        ? "- Provide detailed reasoning for each score"
        : ""}

4. **Final Evaluation**
   - Calculate scores for each category
   - Determine overall pass/fail
   - Provide constructive suggestions
   - Submit evaluation using submitFeedback tool

## Important Guidelines

- Be objective and fair in your assessment
- Focus on whether requirements are met, not implementation details
- Provide specific, actionable feedback
- Consider the complexity of the task when scoring
- If unable to test something, note it clearly
- Don't penalize for minor UI variations that don't affect functionality

## Tool Usage

You have access to:
- **playwright_action**: Browser automation (navigate, click, fill, screenshot, etc.)
- **submitFeedback**: Submit your final structured evaluation

Use these tools efficiently to thoroughly test the application.

**CRITICAL for evaluate action**: When using the 'evaluate' action to run JavaScript in the browser:
- NEVER use ES6 module syntax (import/export statements) - this will cause a SyntaxError
- NEVER use require() statements - this is not available in browser context
- NEVER try to import React, libraries, or any modules
- Only use plain JavaScript that can run directly in a browser console
- Access browser globals directly (window, document, etc.)
- To check for React components, look for them on window or in the DOM, don't import
- Example GOOD code: document.querySelector('.form'), window.React
- Example BAD code: import React from 'react', const { useState } = require('react')
- If you need to check if something exists, use: typeof window.SomeLibrary !== 'undefined'`;
}
/**
 * Builds evaluation criteria from prompts.
 *
 * Analyzes prompts to determine appropriate evaluation criteria
 * for the generated application.
 *
 * @param prompts - Array of prompts given to the agent
 * @param complexity - Task complexity level
 * @returns Evaluation criteria
 */
export function buildCriteriaFromPrompts(prompts, complexity = "medium") {
    const criteria = {
        functionalRequirements: [],
        uiRequirements: [],
        dataRequirements: [],
        performanceRequirements: [],
    };
    // Analyze prompts for requirements
    const allPromptText = prompts.join(" ").toLowerCase();
    // Functional requirements based on keywords
    if (allPromptText.includes("create") || allPromptText.includes("add")) {
        criteria.functionalRequirements.push("User can create new records");
    }
    if (allPromptText.includes("edit") || allPromptText.includes("update")) {
        criteria.functionalRequirements.push("User can edit existing records");
    }
    if (allPromptText.includes("delete") || allPromptText.includes("remove")) {
        criteria.functionalRequirements.push("User can delete records");
    }
    if (allPromptText.includes("list") || allPromptText.includes("display")) {
        criteria.functionalRequirements.push("Application displays data correctly");
    }
    if (allPromptText.includes("search") || allPromptText.includes("filter")) {
        criteria.functionalRequirements.push("Search/filter functionality works");
    }
    if (allPromptText.includes("form")) {
        criteria.functionalRequirements.push("Forms have proper validation");
    }
    if (allPromptText.includes("authenticate") ||
        allPromptText.includes("login")) {
        criteria.functionalRequirements.push("Authentication works correctly");
    }
    // UI requirements
    criteria.uiRequirements.push("Application has a clear layout");
    criteria.uiRequirements.push("UI elements are properly labeled");
    if (allPromptText.includes("table")) {
        criteria.uiRequirements.push("Tables display data clearly");
    }
    if (allPromptText.includes("button")) {
        criteria.uiRequirements.push("Buttons are clearly labeled and functional");
    }
    if (allPromptText.includes("responsive")) {
        criteria.uiRequirements.push("UI is responsive to different screen sizes");
    }
    // Data requirements based on integrations mentioned
    if (allPromptText.includes("api") || allPromptText.includes("integration")) {
        criteria.dataRequirements.push("API integrations function correctly");
    }
    if (allPromptText.includes("database") || allPromptText.includes("sql")) {
        criteria.dataRequirements.push("Database operations work properly");
    }
    if (allPromptText.includes("salesforce")) {
        criteria.dataRequirements.push("Salesforce integration works");
    }
    if (allPromptText.includes("slack")) {
        criteria.dataRequirements.push("Slack integration functions");
    }
    // Performance requirements based on complexity
    if (complexity === "high") {
        criteria.performanceRequirements?.push("Application loads within 3 seconds");
        criteria.performanceRequirements?.push("No blocking operations in UI");
    }
    // Ensure minimum requirements
    if (criteria.functionalRequirements.length === 0) {
        criteria.functionalRequirements.push("Application loads without errors");
        criteria.functionalRequirements.push("Core functionality works as described");
    }
    if (criteria.dataRequirements.length === 0) {
        criteria.dataRequirements.push("Data is displayed correctly");
    }
    return criteria;
}
//# sourceMappingURL=system-prompt.js.map