Class DevModeService

java.lang.Object
ai.nervemind.app.service.DevModeService
All Implemented Interfaces:
ai.nervemind.common.service.DevModeServiceInterface

@Service public class DevModeService extends Object implements ai.nervemind.common.service.DevModeServiceInterface
Service for Developer Mode features.

Centralizes all developer mode checks and provides utilities for:

  • Node execution timing and performance metrics
  • Debug bundle export (workflow + execution logs)
  • HTTP request verbose logging
  • Expression context inspection

Developer mode is controlled by the advanced.devMode setting. When enabled, additional debugging features become available throughout the application.

Since:
1.0.0
See Also:
  • Constructor Details

    • DevModeService

      public DevModeService(ai.nervemind.common.service.SettingsServiceInterface settingsService, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Creates the DevModeService with required dependencies.
      Parameters:
      settingsService - the settings service for reading dev mode state
      objectMapper - the JSON object mapper for serialization
  • Method Details

    • isDevModeEnabled

      public boolean isDevModeEnabled()
      Check if developer mode is enabled.
      Specified by:
      isDevModeEnabled in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      true if developer mode is enabled in settings
    • ifDevMode

      public void ifDevMode(Runnable action)
      Execute an action only if dev mode is enabled.
      Specified by:
      ifDevMode in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      action - the action to execute
    • recordNodeStart

      public void recordNodeStart(String nodeId, String nodeName, String nodeType)
      Record the start of a node execution.
      Specified by:
      recordNodeStart in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      nodeId - the node ID
      nodeName - the node display name
      nodeType - the node type
    • recordNodeEnd

      public long recordNodeEnd(String nodeId, boolean success, String error)
      Record the end of a node execution.
      Specified by:
      recordNodeEnd in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      nodeId - the node ID
      success - whether execution succeeded
      error - error message if failed
      Returns:
      the duration in milliseconds, or -1 if not tracked
    • getNodeTiming

      public DevModeService.NodeTimingInfo getNodeTiming(String nodeId)
      Get timing information for a node.
      Parameters:
      nodeId - the node ID
      Returns:
      timing info, or null if not available
    • getAllNodeTimings

      public Map<String, DevModeService.NodeTimingInfo> getAllNodeTimings()
      Get all node timings for the current execution.
      Returns:
      map of node ID to timing info
    • clearTimings

      public void clearTimings()
      Clear all timing data (call at execution start).
      Specified by:
      clearTimings in interface ai.nervemind.common.service.DevModeServiceInterface
    • formatTimingSummary

      public String formatTimingSummary()
      Format a timing summary for console display.
      Specified by:
      formatTimingSummary in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      formatted timing summary string
    • logExecutionEvent

      public void logExecutionEvent(String level, String nodeId, String nodeName, String message, Object data)
      Log an execution event.
      Specified by:
      logExecutionEvent in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      level - log level (INFO, WARN, ERROR, DEBUG)
      nodeId - node ID (can be null for workflow-level events)
      nodeName - node name (can be null)
      message - log message
      data - optional data object to include
    • getExecutionLog

      public List<DevModeService.ExecutionLogEntry> getExecutionLog()
      Get all execution log entries.
      Returns:
      list of log entries
    • logHttpRequest

      public void logHttpRequest(String nodeId, String method, String url, Map<String,String> requestHeaders, String requestBody, int responseStatus, Map<String,String> responseHeaders, String responseBody, long durationMs)
      Log an HTTP request/response for verbose mode.
      Specified by:
      logHttpRequest in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      nodeId - the node ID making the request
      method - HTTP method
      url - request URL
      requestHeaders - request headers
      requestBody - request body (truncated for preview)
      responseStatus - response status code
      responseHeaders - response headers
      responseBody - response body (truncated for preview)
      durationMs - request duration
    • getHttpRequestLogs

      public List<DevModeService.HttpRequestLog> getHttpRequestLogs()
      Get HTTP request logs.
      Specified by:
      getHttpRequestLogs in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      list of HTTP request logs
    • formatHttpLogs

      public String formatHttpLogs()
      Format HTTP request logs as a readable string.
      Specified by:
      formatHttpLogs in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      formatted HTTP logs string
    • clearHttpRequestLogs

      public void clearHttpRequestLogs()
      Clear HTTP request logs.
      Specified by:
      clearHttpRequestLogs in interface ai.nervemind.common.service.DevModeServiceInterface
    • exportDebugBundle

      public Path exportDebugBundle(ai.nervemind.common.dto.WorkflowDTO workflow, Path outputPath, String executionId) throws IOException
      Export a debug bundle containing workflow, execution data, and logs.
      Specified by:
      exportDebugBundle in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      workflow - the workflow to include
      outputPath - the output directory path
      executionId - the execution ID (can be null)
      Returns:
      the path to the created bundle file
      Throws:
      IOException - if export fails
    • exportNodeAsJson

      public String exportNodeAsJson(Object node)
      Export a node's configuration as JSON string.
      Specified by:
      exportNodeAsJson in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      node - the node to export
      Returns:
      JSON string representation
    • buildExpressionContext

      public Object buildExpressionContext(Map<String,Object> variables, Map<String,Object> nodeOutputs, Map<String,Object> workflowData)
      Build expression context for inspection.
      Specified by:
      buildExpressionContext in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      variables - current workflow variables
      nodeOutputs - outputs from previous nodes
      workflowData - workflow-level data
      Returns:
      formatted expression context
    • formatExpressionContext

      public String formatExpressionContext(Object context)
      Format expression context as readable string.
      Specified by:
      formatExpressionContext in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      context - the expression context
      Returns:
      formatted string
    • isVerboseHttpLoggingEnabled

      public boolean isVerboseHttpLoggingEnabled()
      Check if verbose HTTP logging is enabled. This is a subset of dev mode for HTTP-specific logging.
      Specified by:
      isVerboseHttpLoggingEnabled in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      true if verbose HTTP logging should be used
    • getTimedNodeCount

      public int getTimedNodeCount()
      Get the total number of nodes timed in current execution.
      Specified by:
      getTimedNodeCount in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      count of timed nodes
    • getTotalExecutionTime

      public long getTotalExecutionTime()
      Get the total execution time of all completed nodes.
      Specified by:
      getTotalExecutionTime in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      total duration in milliseconds
    • isStepExecutionEnabled

      public boolean isStepExecutionEnabled()
      Check if step-by-step execution mode is enabled.
      Specified by:
      isStepExecutionEnabled in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      true if step mode is active
    • setStepExecutionEnabled

      public void setStepExecutionEnabled(boolean enabled)
      Enable or disable step-by-step execution mode.
      Specified by:
      setStepExecutionEnabled in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      enabled - true to enable step mode
    • waitForStepContinue

      public boolean waitForStepContinue(String nodeId, String nodeName) throws InterruptedException
      Wait for step continuation if in step mode. Called by execution service after each node.
      Specified by:
      waitForStepContinue in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      nodeId - the node that just completed
      nodeName - the node name
      Returns:
      true if execution should continue, false if cancelled
      Throws:
      InterruptedException - if waiting is interrupted
    • continueStep

      public void continueStep()
      Signal to continue to the next step. Called by UI when user clicks Continue.
      Specified by:
      continueStep in interface ai.nervemind.common.service.DevModeServiceInterface
    • cancelStepExecution

      public void cancelStepExecution()
      Signal to cancel step execution. Called by UI when user clicks Cancel/Stop.
      Specified by:
      cancelStepExecution in interface ai.nervemind.common.service.DevModeServiceInterface
    • resetStepExecution

      public void resetStepExecution()
      Reset step execution state (call at execution start).
      Specified by:
      resetStepExecution in interface ai.nervemind.common.service.DevModeServiceInterface
    • getPausedNodeId

      public String getPausedNodeId()
      Get the node ID that is currently paused (if any).
      Specified by:
      getPausedNodeId in interface ai.nervemind.common.service.DevModeServiceInterface
      Returns:
      node ID of paused node, or null if not paused
    • addStepExecutionListener

      public void addStepExecutionListener(ai.nervemind.common.service.DevModeServiceInterface.StepExecutionListener listener)
      Adds a listener for step execution events.
      Specified by:
      addStepExecutionListener in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      listener - the listener to add
    • removeStepExecutionListener

      public void removeStepExecutionListener(ai.nervemind.common.service.DevModeServiceInterface.StepExecutionListener listener)
      Removes a step execution listener.
      Specified by:
      removeStepExecutionListener in interface ai.nervemind.common.service.DevModeServiceInterface
      Parameters:
      listener - the listener to remove