Task configuration:
{"task_id": "21", "task_name": "change_language", "description": "Change the display language in FreeCAD to Chinese Simplified first, then change it back to English", "application_info": {"name": "FreeCAD", "executable_path": "/usr/local/bin/FreeCAD", "args": []}, "task_parameters": {"first_language": "Chinese Simplified", "final_language": "English"}, "instruction_template": "The application is already open. In the FreeCAD application, using open first start setup, first change the interface language to ${first_language}, then change it back to ${final_language}", "evaluation_setup": {"scripts": [{"role": "hook", "path": "hooker.js"}, {"role": "handler", "path": "handler.py"}], "timeout": 120}, "preconditions": {"FreeCAD_running": true}, "total_key_steps": 2, "events": {"script_initialized": {"description": "Hook script initialization", "is_key_step": false}, "function_found": {"description": "Found language switching function", "is_key_step": false}, "function_called": {"description": "Language switching function was called", "is_key_step": false}, "first_language_set": {"description": "First language change detected", "is_key_step": true, "key_step_index": 1, "key_step_name": "Successfully changed language to Chinese Simplified"}, "final_language_set": {"description": "Final language change detected", "is_key_step": true, "key_step_index": 2, "key_step_name": "Successfully changed language back to English"}, "error": {"description": "Error event", "is_key_step": false}}, "mcp_servers": [{"command": "python3", "args": ["/home/agent/.local/share/FreeCAD/Mod/freecad_mcp/src/freecad_bridge.py"]}]}

Hook script:
// FreeCAD Language Switching Monitoring Hook Script
// Used to monitor language switching operations in FreeCAD

(function() {
  // Script constants setup
  const FUNCTION_NAME = "_ZN3Gui10Translator16activateLanguageEPKc"
  const ORIGIN_FUNCTION_NAME = "Translator::activateLanguage"
  const FUNCTION_BEHAVIOR = "language switch"

  const SCRIPT_INITIALIZED = "script_initialized"
  const FUNCTION_NOT_FOUND = "function_not_found"
  const FUNCTION_FOUND = "function_found"
  const FUNCTION_CALLED = "function_called"
  const FIRST_LANGUAGE_SET = "first_language_set"
  const FINAL_LANGUAGE_SET = "final_language_set"
  const ERROR = "error"
  const HOOK_INSTALLED = "hook_installed"

  const APP_NAME = "FreeCAD"
  
  // Global variables
  let funcFound = false;
  let firstLanguageDetected = false;
  let firstLanguage = "Chinese Simplified";  // Expected first language
  let finalLanguage = "English";  // Expected final language
  
  // Send events to the evaluation system
  function sendEvent(eventType, data = {}) {
      const payload = {
          event: eventType,
          ...data,
          timestamp: new Date().getTime()
      };
      send(payload);
  }
  
  // Find Translator::activateLanguage function
  function getFunction() {
      // Try to find directly through export symbols
      let FuncAddr = DebugSymbol.getFunctionByName(FUNCTION_NAME);
      
      // If not found, report error
      if (!FuncAddr) {
          sendEvent(ERROR, {
              error_type: FUNCTION_NOT_FOUND,
              message: `Could not find ${ORIGIN_FUNCTION_NAME} function`
          });
          return null;
      }
      
      // Report function found
      funcFound = true;
      sendEvent(FUNCTION_FOUND, {
          address: FuncAddr.toString(),
          message: `Found ${ORIGIN_FUNCTION_NAME} function`
      });
      
      return FuncAddr;
  }
  
  // Initialize hook and execute immediately
  function initHook() {
      sendEvent(SCRIPT_INITIALIZED, {
          message: `${APP_NAME} ${FUNCTION_BEHAVIOR} monitoring script started`
      });
      
      // Find language switching function
      const funcAddr = getFunction();
      if (!funcAddr) {
          return;
      }
      
      // Install language switching function hook
      Interceptor.attach(funcAddr, {
          onEnter: function(args) {
              try {
                  sendEvent(FUNCTION_CALLED, {
                      message: `Intercepted ${FUNCTION_BEHAVIOR} function call`
                  });
                  this.language = args[1].readCString();
              } catch (error) {
                  sendEvent(ERROR, {
                      error_type: "general_error",
                      message: `Execution error: ${error.message}`
                  });
              }
          },

          onLeave: function(retval) {
              try {
                  // Check if this is the first time setting to Chinese
                  if (this.language === firstLanguage && !firstLanguageDetected) {
                      firstLanguageDetected = true;
                      sendEvent(FIRST_LANGUAGE_SET, {
                          message: `Detected first ${FUNCTION_BEHAVIOR} operation`,
                          language: this.language
                      });
                  }
                  // Check if this is the final setting to English
                  else if (this.language === finalLanguage && firstLanguageDetected) {
                      sendEvent(FINAL_LANGUAGE_SET, {
                          message: `Detected final ${FUNCTION_BEHAVIOR} operation`,
                          language: this.language
                      });
                  }
              } catch (error) {
                  sendEvent(ERROR, {
                      error_type: "general_error",
                      message: `Execution error: ${error.message}`
                  });
              }
          }
      });
      
      sendEvent(HOOK_INSTALLED, {
          message: `Hook installation complete, waiting for ${FUNCTION_BEHAVIOR} operations...`
      });
  }
  
  // Execute hook initialization immediately
  initHook();
})();


Evaluation handler:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
FreeCAD Event Handler
Responsible for processing events generated by the hook script and determining if the task is completed
"""

import os
from typing import Dict, Any, Optional, List

# 事件类型常量
SCRIPT_INITIALIZED = "script_initialized"
FUNCTION_NOT_FOUND = "function_not_found"
FUNCTION_FOUND = "function_found"
FUNCTION_CALLED = "function_called"
FIRST_LANGUAGE_SET = "first_language_set"
FINAL_LANGUAGE_SET = "final_language_set"
ERROR = "error"
HOOK_INSTALLED = "hook_installed"

# 关键字相关常量
KEY = "language"
KEY_WORDS = [KEY]

def message_handler(message: Dict[str, Any], logger: Any, task_parameter: Dict[str, Any]) -> Optional[List[Dict[str, Any]]]:
    """
    Process messages received from the hook script
    
    Args:
        message: Frida message object
        logger: Logger
        task_parameter: Task parameters
        
    Returns:
        List[Dict[str, Any]]: List of dictionaries containing status updates, or None if no updates
    """
    # Process the message
    if message.get('type') == 'send' and 'payload' in message:
        payload = message['payload']
        
        # Check if it contains an event type
        if 'event' in payload:
            event_type = payload['event']
            logger.debug(f"Event received: {event_type}")
            
            # Handle specific events
            if event_type == SCRIPT_INITIALIZED:
                logger.info(f"Hook script initialized: {payload.get('message', '')}")
                return None
                
            elif event_type == FUNCTION_FOUND:
                logger.info(f"Function found: {payload.get('address', '')}")
                return None
                
            elif event_type == FUNCTION_CALLED: 
                logger.info(f"Function called: {payload.get('message', '')}")
                return None
                
            elif event_type == FIRST_LANGUAGE_SET:
                log_info = f"Function detected first language setting: {payload.get('message', '')}"
                for key in KEY_WORDS:
                    if key in payload:
                        log_info += f", {key}: {payload.get(key, '')}"
                logger.info(log_info)

                expected_language = task_parameter.get("first_language", '')
                actual_language = payload.get(KEY, '')
                logger.debug(f"Expected language: {expected_language}, Actual language: {actual_language}")

                if actual_language == expected_language:
                    # Create status update list
                    updates = []
                    
                    # Report key step completed
                    updates.append({
                        'status': 'key_step',
                        'index': 1,
                        'name': f'Successfully changed language to {expected_language}'
                    })
                    
                    logger.info(f"First step completed!")
                    return updates
                
            elif event_type == FINAL_LANGUAGE_SET:
                log_info = f"Function detected final language setting: {payload.get('message', '')}"
                for key in KEY_WORDS:
                    if key in payload:
                        log_info += f", {key}: {payload.get(key, '')}"
                logger.info(log_info)

                expected_language = task_parameter.get("final_language", '')
                actual_language = payload.get(KEY, '')
                logger.debug(f"Expected language: {expected_language}, Actual language: {actual_language}")

                if actual_language == expected_language:
                    # Create status update list
                    updates = []
                    
                    # Report key step completed
                    updates.append({
                        'status': 'key_step',
                        'index': 2,
                        'name': f'Successfully changed language to {expected_language}'
                    })
                    
                    # Report task success
                    updates.append({
                        'status': 'success',
                        'reason': f'Language switching task completed successfully'
                    })
                    
                    logger.info(f"Task completed successfully!")
                    return updates
                
            elif event_type == ERROR:
                error_type = payload.get("error_type", "unknown")
                error_message = payload.get("message", "Unknown error")
                
                logger.error(f"Hook script error ({error_type}): {error_message}")
                
                return [{
                    'status': 'error',
                    'type': error_type,
                    'message': error_message
                }]
                
    elif message.get('type') == 'error':
        logger.error(f"Hook script error: {message.get('stack', '')}")
        
        return [{
            'status': 'error',
            'type': 'script_error',
            'message': message.get('stack', 'Unknown error')
        }]
    
    return None