debug_window_detection
Identify and resolve window detection issues by retrieving detailed diagnostics about PowerShell environment, process enumeration, and window detection capabilities for streamlined debugging.
Instructions
Comprehensive debugging information for window detection issues.
Returns:
JSON string with detailed diagnostics about PowerShell environment,
process enumeration, and window detection capabilities.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.py:608-654 (handler)MCP tool handler for debug_window_detection. Decorated with @mcp.tool() for registration. Collects environment info, calls WindowsWindowManager's debug method if available, lists current windows, and returns JSON diagnostics.@mcp.tool() async def debug_window_detection() -> str: """ Comprehensive debugging information for window detection issues. Returns: JSON string with detailed diagnostics about PowerShell environment, process enumeration, and window detection capabilities. """ try: wm = get_window_manager() # Get basic environment info env_info = wm.get_environment_info() debug_result = { "status": "success", "environment": env_info, "window_detection_debug": {} } # If using Windows manager, get detailed debug info if hasattr(wm.manager, 'debug_window_detection'): logger.info("Running comprehensive window detection debug...") debug_info = wm.manager.debug_window_detection() debug_result["window_detection_debug"] = debug_info else: debug_result["window_detection_debug"] = { "message": "Debug functionality only available for Windows Window Manager" } # Also include current window list for comparison current_windows = wm.list_windows() debug_result["current_window_list"] = current_windows debug_result["current_window_count"] = len(current_windows) logger.info(f"Debug complete: found {len(current_windows)} windows") return json.dumps(debug_result, indent=2) except Exception as e: logger.error(f"Failed to run debug window detection: {e}") return json.dumps({ "status": "error", "error": str(e), "environment": {"error": "Could not determine environment"} })
- capture.py:562-690 (helper)Core implementation in WindowsWindowManager class. Executes PowerShell scripts to test PowerShell availability, enumerate processes/windows, gather verbose debug output, and parse statistics for window detection diagnostics.def debug_window_detection(self) -> Dict[str, any]: """ Comprehensive debugging information for window detection. Returns detailed diagnostics about the PowerShell environment and window detection. """ debug_info = { 'powershell_available': self.powershell_available, 'detection_methods': [], 'raw_powershell_output': '', 'parsing_errors': [], 'process_info': {} } if not self.powershell_available: debug_info['error'] = 'PowerShell not available' return debug_info try: # Test basic PowerShell functionality basic_test = subprocess.run( ['powershell.exe', '-Command', 'Get-Process | Select-Object -First 5 Name, Id | ConvertTo-Json'], capture_output=True, text=True, check=True, timeout=10 ) debug_info['basic_powershell_test'] = 'SUCCESS' debug_info['sample_processes'] = basic_test.stdout.strip()[:200] + '...' except Exception as e: debug_info['basic_powershell_test'] = f'FAILED: {str(e)}' return debug_info # Test our enhanced window detection script with verbose output try: debug_script = ''' $VerbosePreference = "Continue" Write-Verbose "Starting window detection debug..." Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; using System.Text; public class Win32 { [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr hWnd); [DllImport("user32.dll")] public static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32.dll")] public static extern int GetWindowTextLength(IntPtr hWnd); } "@ $allProcesses = Get-Process | Measure-Object | Select-Object -ExpandProperty Count Write-Verbose "Total processes found: $allProcesses" $processesWithWindows = Get-Process | Where-Object { $_.MainWindowHandle -ne 0 } | Measure-Object | Select-Object -ExpandProperty Count Write-Verbose "Processes with windows: $processesWithWindows" $windows = @() Get-Process | Where-Object { $_.MainWindowHandle -ne 0 -and $_.ProcessName -notmatch "^(dwm|csrss|winlogon|wininit)$" } | ForEach-Object { Write-Verbose "Processing: $($_.ProcessName) (ID: $($_.Id))" $handle = [IntPtr]$_.MainWindowHandle $isVisible = [Win32]::IsWindowVisible($handle) $isMinimized = [Win32]::IsIconic($handle) $isMaximized = [Win32]::IsZoomed($handle) # Only include capturable windows (same logic as main script) if (-not ($isVisible -or $isMinimized)) { Write-Verbose "Skipping hidden window: $($_.ProcessName)" return } $windows += @{ process_name = $_.ProcessName process_id = $_.Id window_handle = $_.MainWindowHandle.ToString() main_window_title = $_.MainWindowTitle is_visible = $isVisible is_minimized = $isMinimized is_maximized = $isMaximized window_state = if ($isMinimized) { "minimized" } elseif ($isMaximized) { "maximized" } else { "normal" } } } Write-Host "PROCESS_COUNT:$allProcesses" Write-Host "WINDOWS_COUNT:$processesWithWindows" Write-Host "FILTERED_COUNT:$($windows.Count)" $windows | ConvertTo-Json -Depth 2 ''' result = subprocess.run( ['powershell.exe', '-Command', debug_script], capture_output=True, text=True, timeout=30 ) debug_info['enhanced_script_exit_code'] = result.returncode debug_info['raw_powershell_output'] = result.stdout debug_info['powershell_stderr'] = result.stderr # Parse the debug output lines = result.stdout.split('\n') for line in lines: if line.startswith('PROCESS_COUNT:'): debug_info['total_processes'] = int(line.split(':')[1]) elif line.startswith('WINDOWS_COUNT:'): debug_info['processes_with_windows'] = int(line.split(':')[1]) elif line.startswith('FILTERED_COUNT:'): debug_info['filtered_windows'] = int(line.split(':')[1]) except Exception as e: debug_info['enhanced_script_error'] = str(e) return debug_info