Task configuration:
{"task_id": "01", "task_name": "new_doc", "description": "Create a new document in FreeCAD", "application_info": {"name": "FreeCAD", "executable_path": "/usr/local/bin/FreeCAD", "args": []}, "task_parameters": {}, "instruction_template": "The application is already open. Create a new document in FreeCAD application and show the result", "evaluation_setup": {"scripts": [{"role": "hook", "path": "hooker.js"}, {"role": "handler", "path": "handler.py"}], "timeout": 120}, "preconditions": {"FreeCAD_running": true}, "total_key_steps": 1, "events": {"script_initialized": {"description": "Hook script initialized", "is_key_step": false}, "function_found": {"description": "Found document creation function", "is_key_step": false}, "function_called": {"description": "Document creation function was called", "is_key_step": false}, "function_key_word_detected": {"description": "Detected document creation key content", "is_key_step": true, "key_step_index": 1, "key_step_name": "Successfully created new document"}, "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 New Document Monitoring Hook Script
// Used to monitor the creation of new documents in FreeCAD

(function() {
  // Script constants
  const FUNCTION_NAME = "_ZN3App11Application11newDocumentEPKcS2_bb"
  const ORIGIN_FUNCTION_NAME = "Application::newDocument"
  const FUNCTION_BEHAVIOR = "create new document"

  const SCRIPT_INITIALIZED = "script_initialized"
  const FUNCTION_NOT_FOUND = "function_not_found"
  const FUNCTION_FOUND = "function_found"
  const FUNCTION_CALLED = "function_called"
  const FUNCTION_KEY_WORD_DETECTED = "function_key_word_detected"
  const ERROR = "error"
  const HOOK_INSTALLED = "hook_installed"

  const APP_NAME = "FreeCAD"
  
  // Global variables
  let funcFound = false;
  
  // Send event to evaluation system
  function sendEvent(eventType, data = {}) {
      const payload = {
          event: eventType,
          ...data,
          timestamp: new Date().getTime()
      };
      send(payload);
  }
  
  // Find Application::newDocument function
  function getFunction() {
      // Try to find directly through exported symbol
      let FuncAddr = DebugSymbol.getFunctionByName(FUNCTION_NAME);
      
      // If not found, report error
      if (!FuncAddr) {
          sendEvent(ERROR, {
              error_type: FUNCTION_NOT_FOUND,
              message: `Cannot 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;
  }
  
  // Read C++ standard string content
  function readCXXStdString(Ptr) {
      const str_ptr = Ptr;
      const len = str_ptr.add(0x8).readU64();
      const str = str_ptr.readPointer().readCString(len)
      return str;
  }
  
  // Initialize hook and execute immediately
  function initHook() {
      sendEvent(SCRIPT_INITIALIZED, {
          message: `${APP_NAME} ${FUNCTION_BEHAVIOR} monitoring script started`
      });
      
      // Find target function
      const funcAddr = getFunction();
      if (!funcAddr) {
          return;
      }
      
      // Install function hook
      Interceptor.attach(funcAddr, {
          onEnter: function(args) {
              try {
                  sendEvent(FUNCTION_CALLED, {
                      message: `Intercepted ${FUNCTION_BEHAVIOR} function call`
                  });
              } catch (error) {
                  sendEvent(ERROR, {
                      error_type: "general_error",
                      message: `Execution error: ${error.message}`
                  });
              }
          },

          onLeave: function(retval) {
              try {
                  let Label = retval.add(0xB8)
                  let FileName = Label.add(0x60)

                  let LabelCXXStringPtr = Label.add(0x40)
                  let FileNameCXXStringPtr = FileName.add(0x40)

                  Label = readCXXStdString(LabelCXXStringPtr)
                  FileName = readCXXStdString(FileNameCXXStringPtr)
                  sendEvent(FUNCTION_KEY_WORD_DETECTED, {
                      message: `Detected ${FUNCTION_BEHAVIOR} operation`,
                      label: Label,
                      filename: FileName
                  });
                  // Detect keywords
                  
              } catch (error) {
                  sendEvent(ERROR, {
                      error_type: "general_error",
                      message: `Execution error: ${error.message}`
                  });
              }
          }
      });
      
      sendEvent(HOOK_INSTALLED, {
          message: `Hook installation complete, waiting for ${FUNCTION_BEHAVIOR} operation...`
      });
  }
  
  // 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 complete
"""

from typing import Dict, Any, Optional, List

# Event type constants
SCRIPT_INITIALIZED = "script_initialized"
FUNCTION_NOT_FOUND = "function_not_found"
FUNCTION_FOUND = "function_found"
FUNCTION_CALLED = "function_called"
FUNCTION_KEY_WORD_DETECTED = "function_key_word_detected"
ERROR = "error"
HOOK_INSTALLED = "hook_installed"

# Keyword related constants
KEY_WORD = ["label", "filename"]

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 status update
    """
    # Process message
    if message.get('type') == 'send' and 'payload' in message:
        payload = message['payload']
        
        # Check if message contains event type
        if 'event' in payload:
            event_type = payload['event']
            logger.debug(f"Received event: {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 == FUNCTION_KEY_WORD_DETECTED:
                log_info = f"Function detected keyword: {payload.get('message', '')}"
                for key in KEY_WORD:
                    if key in payload:  # Ensure key exists
                        log_info += f", {key}: {payload.get(key, '')}"
                logger.info(log_info)
                
                # Create status update list
                updates = []
                
                # Report key step completed
                updates.append({
                    'status': 'key_step',
                    'index': 1,
                    'name': 'Successfully created new document'
                })
                
                # Report task success
                updates.append({
                    'status': 'success',
                    'reason': 'Successfully created a new document'
                })
                
                logger.info("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