Task configuration:
{"task_id": "16", "task_name": "create_cube_with_fillet", "description": "Create a cube with fillets in FreeCAD", "application_info": {"name": "FreeCAD", "executable_path": "/usr/local/bin/FreeCAD", "args": []}, "task_parameters": {"source_path": "/FreeCAD/", "filename": "task16.FCStd", "cube_length": 30.0, "cube_width": 30.0, "cube_height": 30.0, "fillet_radius": 5.0}, "instruction_template": "The application is already open. Create a cube in FreeCAD with length ${cube_length}mm, width ${cube_width}mm, and height ${cube_height}mm, then add fillets with a radius of ${fillet_radius}mm to all its edges. The cube should be created as an additive cube (typeid), and the fillets should be created using the create a fillet feature on cube. Do not create the shapes separately and use Boolean subtraction or cut. Finally, save the file to ${source_path}${filename}", "evaluation_setup": {"scripts": [{"role": "hook", "path": "hooker.js"}, {"role": "handler", "path": "handler.py"}], "timeout": 300, "evaluator_type": "HookManager"}, "preconditions": {"freecad_running": false}, "total_key_steps": 2, "events": {"script_initialized": {"description": "Hook script initialized", "is_key_step": false}, "function_found": {"description": "Document save function found", "is_key_step": false}, "function_called": {"description": "Document save function called", "is_key_step": true, "key_step_index": 1, "key_step_name": "Document saved"}, "function_key_word_detected": {"description": "Detected key content in saved document", "is_key_step": true, "key_step_index": 2, "key_step_name": "Created cube with fillets and saved successfully"}, "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 Cube with Fillets Monitoring Hook Script
// Used to monitor FreeCAD creation of a cube with fillets and detect task completion
// After creating a cube with fillets and saving the file, the test program listens for the save and checks if the corresponding document contains the required cube with fillets

(function() {
  // Script constants setting
  const FUNCTION_NAME = "_ZNK3App8Document10saveToFileEPKc"
  const ORIGIN_FUNCTION_NAME = "Document::saveToFile"
  const FUNCTION_BEHAVIOR = "Document Save"

  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 events to the evaluation system
  function sendEvent(eventType, data = {}) {
      const payload = {
          event: eventType,
          ...data,
          timestamp: new Date().getTime()
      };
      send(payload);
  }
  
  // Find Document::saveToFile function
  function getFunction() {
      // Try to find the function directly through exported symbols
      let FuncAddr = DebugSymbol.getFunctionByName(FUNCTION_NAME);
      
      // If not found, report error
      if (!FuncAddr) {
          sendEvent(ERROR, {
              error_type: FUNCTION_NOT_FOUND,
              message: `Unable to 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 has 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`
                  });
                  this.filename = args[1].readCString();
              } catch (error) {
                  sendEvent(ERROR, {
                      error_type: "general_error",
                      message: `Execution error: ${error.message}`
                  });
              }
          },

          onLeave: function(retval) {
              try {
                if (retval) {
                    const pythonCode = `
import freecad
import FreeCAD
import Part
import math

# Open the specified file
file_path = '${this.filename}'
doc = FreeCAD.open(file_path)

# Get the active document
if doc is None:
    result = None
else:
    # Find cube and fillets
    cube = None
    fillet = None
    has_fillet = False
    fillet_radius = 0.0
    processed_objects = set()  # To track processed objects
    # Check all objects, looking for cube and fillets
    for subobj in doc.Objects:
        if hasattr(subobj, "Shape") and hasattr(subobj.Shape, "ShapeType"):
            # Use TypeId to check if it's an additive cube
            if subobj.TypeId == 'PartDesign::AdditiveBox' or subobj.TypeId == 'Part::Box':
                # Use object ID as a unique identifier
                obj_id = subobj.ID if hasattr(subobj, "ID") else subobj.Name
                
                # If this object has already been processed, skip it
                if obj_id in processed_objects:
                    continue
                processed_objects.add(obj_id)
                
                if subobj.Shape.ShapeType == "Solid":
                    # Check if it's a cube, read properties directly
                    cube_length = subobj.Length.Value if hasattr(subobj, "Length") else 0
                    cube_width = subobj.Width.Value if hasattr(subobj, "Width") else 0
                    cube_height = subobj.Height.Value if hasattr(subobj, "Height") else 0
                    
                    # Store cube information
                    cube = {
                        'length': cube_length,
                        'width': cube_width,
                        'height': cube_height
                    }
            
            # Check if there are fillet features (could be multiple types)
            elif subobj.TypeId == 'PartDesign::Fillet' or 'Fillet' in subobj.TypeId:
                # Use object ID as a unique identifier
                obj_id = subobj.ID if hasattr(subobj, "ID") else subobj.Name
                
                # If this object has already been processed, skip it
                if obj_id in processed_objects:
                    continue
                processed_objects.add(obj_id)
                
                # Mark that fillets exist
                has_fillet = True
                
                # Try to get the fillet radius
                if hasattr(subobj, "Radius"):
                    if isinstance(subobj.Radius, list):
                        # If it's a list, take the first value
                        if len(subobj.Radius) > 0:
                            fillet_radius = float(subobj.Radius[0])
                    else:
                        # Get value directly
                        fillet_radius = float(subobj.Radius)
                elif hasattr(subobj, "FilletRadius"):
                    fillet_radius = float(subobj.FilletRadius)
    
    # Return results - ensure we return pure numbers without units
    # Handle values that may have units
    def extract_value(val):
        if val is None:
            return None
        try:
            # If it's a string with unit (like "10.0 mm"), extract the numeric part
            if isinstance(val, str) and ' ' in val:
                return float(val.split()[0])
            # If it's a FreeCAD Quantity object, try to convert to float
            return float(val)
        except:
            # If conversion fails, return the original value
            return val
    
    result = {
        'cube_length': extract_value(cube['length']) if cube else None,
        'cube_width': extract_value(cube['width']) if cube else None,
        'cube_height': extract_value(cube['height']) if cube else None,
        'fillet_radius': extract_value(fillet_radius),
        'has_fillet': has_fillet
    }
                    `
                    sendEvent(FUNCTION_KEY_WORD_DETECTED, {
                        message: `Detected ${FUNCTION_BEHAVIOR} operation`,
                        filename: this.filename,
                        code: pythonCode
                    });
                }
                // 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 Cube with Fillets Event Handler
Responsible for processing events generated by the hook script and updating evaluation metrics
"""

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
CUBE_LENGTH = "cube_length"
CUBE_WIDTH = "cube_width"
CUBE_HEIGHT = "cube_height"
FILLET_RADIUS = "fillet_radius"
HAS_FILLET = "has_fillet"

def execute_python_code(code: str, logger: Any) -> Dict[str, Any]:
    """
    Execute Python code and return the results
    
    Args:
        code: Python code to execute
        logger: Logger object
        
    Returns:
        Dict[str, Any]: Execution result
    """
    try:
        # Create a new namespace to execute the code
        namespace = {}
        exec(code, namespace)
        result = namespace.get('result', None)
        
        if result is None:
            logger.warning("Cube with fillets object not found")
            return None
            
        # Validate result format
        required_keys = [
            CUBE_LENGTH, CUBE_WIDTH, CUBE_HEIGHT, FILLET_RADIUS, HAS_FILLET
        ]
        if not all(key in result for key in required_keys):
            logger.error(f"Result missing required keys: {required_keys}")
            return None
            
        return result
    except Exception as e:
        logger.error(f"Error executing Python code: {str(e)}")
        return None

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 object
        task_parameter: Task parameters
        
    Returns:
        Optional[List[Dict[str, Any]]]: List of status updates, or None if no updates
    """
    updates = []
    
    if message.get('type') == 'send' and 'payload' in message:
        payload = message['payload']
        
        if 'event' in payload:
            event_type = payload['event']
            logger.debug(f"Received event: {event_type}")
            
            if event_type == SCRIPT_INITIALIZED:
                logger.info(f"Hook script initialized: {payload.get('message', '')}")
                
            elif event_type == FUNCTION_FOUND:
                logger.info(f"Function found: {payload.get('address', '')}")
                
            elif event_type == FUNCTION_CALLED:
                logger.info(f"Function called: {payload.get('message', '')}")
                # Update first key step status
                updates.append({
                    'status': 'key_step',
                    'index': 1,
                    'name': 'Document saved'
                })
                
            elif event_type == FUNCTION_KEY_WORD_DETECTED:
                # Execute Python code and get results
                code = payload.get('code', '')
                filename = payload.get('filename', '')
                expected_path = task_parameter.get("source_path", "") + task_parameter.get("filename", "")
                logger.info(f"Detected keywords, document path: {filename}, expected document path: {expected_path}")
                
                if filename == expected_path:
                    result = execute_python_code(code, logger)
                    if result:
                        # Check if cube with fillets parameters match expectations
                        expected_cube_length = task_parameter.get(CUBE_LENGTH, 30.0)
                        expected_cube_width = task_parameter.get(CUBE_WIDTH, 30.0)
                        expected_cube_height = task_parameter.get(CUBE_HEIGHT, 30.0)
                        expected_fillet_radius = task_parameter.get(FILLET_RADIUS, 5.0)

                        actual_cube_length = result[CUBE_LENGTH]
                        actual_cube_width = result[CUBE_WIDTH]
                        actual_cube_height = result[CUBE_HEIGHT]
                        actual_fillet_radius = result[FILLET_RADIUS]
                        actual_has_fillet = result[HAS_FILLET]

                        # Log key parameters
                        logger.info(f"Task parameter check: Expected cube length={expected_cube_length}, width={expected_cube_width}, height={expected_cube_height}")
                        logger.info(f"Expected fillets: radius={expected_fillet_radius}")
                        logger.info(f"Actual parameters: Actual cube length={actual_cube_length}, width={actual_cube_width}, height={actual_cube_height}")
                        logger.info(f"Actual fillets: radius={actual_fillet_radius}, has fillets: {actual_has_fillet}")

                        try:
                            # Try to get the numeric part (handle possible units)
                            actual_cube_length_value = float(str(actual_cube_length).split()[0]) if isinstance(actual_cube_length, str) else float(actual_cube_length)
                            actual_cube_width_value = float(str(actual_cube_width).split()[0]) if isinstance(actual_cube_width, str) else float(actual_cube_width)
                            actual_cube_height_value = float(str(actual_cube_height).split()[0]) if isinstance(actual_cube_height, str) else float(actual_cube_height)
                            
                            actual_fillet_radius_value = float(str(actual_fillet_radius).split()[0]) if isinstance(actual_fillet_radius, str) else float(actual_fillet_radius)
                            
                            # Allow a certain error range (0.01%)
                            cube_length_error = abs((actual_cube_length_value - expected_cube_length) / expected_cube_length) <= 0.0001
                            cube_width_error = abs((actual_cube_width_value - expected_cube_width) / expected_cube_width) <= 0.0001
                            cube_height_error = abs((actual_cube_height_value - expected_cube_height) / expected_cube_height) <= 0.0001
                            
                            fillet_radius_error = abs((actual_fillet_radius_value - expected_fillet_radius) / expected_fillet_radius) <= 0.0001
                            
                            has_fillet_correct = actual_has_fillet
                        except Exception as e:
                            logger.error(f"Error comparing parameters: {str(e)}")
                            cube_length_error = False
                            cube_width_error = False
                            cube_height_error = False
                            fillet_radius_error = False
                            has_fillet_correct = False
                        
                        cube_correct = cube_length_error and cube_width_error and cube_height_error
                        fillet_correct = fillet_radius_error and has_fillet_correct
                        
                        if cube_correct and fillet_correct:
                            # Update second key step status
                            updates.append({
                                'status': 'key_step',
                                'index': 2,
                                'name': 'Created cube with fillets and saved successfully'
                            })
                            
                            # Task completed successfully
                            updates.append({
                                'status': 'success',
                                'reason': 'Successfully created a cube with fillets that meets requirements and saved it'
                            })
                        else:
                            logger.warning(f"Parameter validation failed: " + 
                                          f"Cube correct: {cube_correct}, " +
                                          f"Fillets correct: {fillet_correct}")
                
            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}")
                
                # Record error event
                updates.append({
                    'status': 'error',
                    'type': error_type,
                    'message': error_message
                })
                
    elif message.get('type') == 'error':
        logger.error(f"Hook script error: {message.get('stack', '')}")
        
        # Record error event
        updates.append({
            'status': 'error',
            'type': 'script_error',
            'message': message.get('stack', 'Unknown error')
        })
    
    return updates if updates else None