Skip to content

Conversation

@shadowfax92
Copy link
Contributor

No description provided.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 13, 2025

Greptile Overview

Greptile Summary

This PR enhances logging and window focus handling across the BrowserOS server. The changes remove excessive log message truncation that was hindering debugging, implement structured logging with metadata objects, and introduce a window focus tracking system for better multi-window automation control.

The logging improvements span multiple components including the Agent, Controller Extension, and Common Logger, replacing string concatenation and character truncation with clean structured logging that preserves complete message content. The window focus functionality allows the system to dynamically reassign the primary controller based on which browser window has focus, ensuring automation commands target the active window.

Configuration changes add optional RESOURCES_DIR and EXECUTION_DIR environment variables for flexible directory management, while the controller extension version is bumped to 1.0.0.8 to reflect these improvements.

Important Files Changed

Filename Score Overview
packages/common/src/logger.ts 5/5 Refactored to support structured logging with optional string truncation for console output
packages/controller-ext/src/background/BrowserOSController.ts 5/5 Added notifyWindowFocused method to send focus events via WebSocket
packages/controller-ext/src/background/index.ts 4/5 Added window focus event listener and updated to structured logging format
packages/controller-server/src/ControllerBridge.ts 4/5 Added focus event handling to reassign primary controller based on window focus
packages/agent/src/agent/ClaudeSDKAgent.ts 5/5 Removed message truncation to preserve complete log content for debugging
packages/agent/src/agent/CodexSDKAgent.ts 4/5 Removed log truncation and improved event logging clarity
packages/controller-ext/src/websocket/WebSocketClient.ts 5/5 Refactored WebSocket sending logic to eliminate code duplication
packages/controller-ext/src/utils/Logger.ts 4/5 Enhanced with optional structured data parameter for better debugging
packages/server/src/args.ts 4/5 Fixed path resolution to ensure directories are always absolute paths
packages/server/src/main.ts 4/5 Improved error handling and directory configuration with proper validation
.env.example 5/5 Added optional RESOURCES_DIR and EXECUTION_DIR configuration variables
packages/controller-ext/manifest.json 5/5 Version bump from 1.0.0.5 to 1.0.0.8 for extension release

Confidence score: 4/5

  • This PR improves debugging capabilities and adds useful window focus functionality with minimal risk
  • Score reflects solid implementation quality but complexity in path resolution logic and multi-component changes that need coordination
  • Pay close attention to packages/server/src/args.ts and packages/controller-server/src/ControllerBridge.ts for proper directory handling and focus event coordination

Sequence Diagram

sequenceDiagram
    participant User
    participant "BrowserOS Server" as Server
    participant "Controller Bridge" as Bridge
    participant "Chrome Extension" as Extension
    participant "Agent Server" as Agent
    participant "MCP Server" as MCP
    participant "Logger" as Log

    User->>Server: "Start server"
    Server->>Log: "Configure log directory"
    Server->>Server: "Parse command line arguments"
    Server->>Bridge: "Create ControllerBridge on port 9300"
    Server->>Server: "Connect to CDP (if enabled)"
    Server->>Server: "Merge tools (CDP + Controller + Klavis)"
    Server->>MCP: "Start MCP HTTP server on port 9100"
    Server->>Agent: "Start Agent WebSocket server on port 9200"
    Server->>Log: "Log server startup summary"

    Extension->>Bridge: "WebSocket connection"
    Bridge->>Log: "Extension connected"
    Extension->>Bridge: "Send ping heartbeat"
    Bridge->>Extension: "Send pong response"
    
    Extension->>Bridge: "Send focused event with windowId"
    Bridge->>Log: "Handle focus event - reassign primary client"

    User->>Agent: "Send task request"
    Agent->>Bridge: "Send controller request"
    Bridge->>Extension: "Forward request to extension"
    Extension->>Bridge: "Send response"
    Bridge->>Agent: "Forward response"
    Agent->>User: "Stream formatted events"

    User->>Server: "SIGINT/SIGTERM signal"
    Server->>MCP: "Shutdown MCP server"
    Server->>Agent: "Stop agent server"
    Server->>Bridge: "Close ControllerBridge"
    Server->>Log: "Log shutdown complete"
    Server->>Server: "Process exit"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@shadowfax92 shadowfax92 merged commit 0274d82 into main Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants