Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Browser Mode Implementation - Complete ✅

Successfully implemented --browser mode for Cletus with a React-based web UI!

Features Implemented

  • Browser Mode Flag: Added --browser and --port CLI arguments
  • HTTP Server: Node.js HTTP server serving static files with secure path handling
  • WebSocket Support: Real-time bidirectional communication for chat operations
  • React Client: Modern, responsive web UI built with React
  • Server-Side Operations: All AI operations and file I/O run server-side via WebSocket
  • Reusable Architecture: Leverages existing Cletus logic (ConfigFile, ChatFile, AI components)
  • TypeScript: Strict typing throughout, no any/unknown usage
  • Component Structure: Well-organized, split into small focused components
  • Security: Path traversal protection, localhost-only binding by default

Architecture

Server (src/browser/server.ts):

  • HTTP server for static file serving with secure path resolution
  • WebSocket server for real-time chat communication
  • API endpoints for config and chat data
  • Lazy-loads AI components to avoid startup delays
  • Binds to 127.0.0.1 (localhost only) for security

Client (src/browser/client/):

  • Pages: InitPage, MainPage (chat list + settings), ChatPage
  • Components: Sidebar, ChatList, ChatHeader, MessageList, MessageItem, ChatInput, OperationDisplay, Collapsible, SettingsView
  • Styling: CSS with dark/light mode support

Screenshots

Initialization Page (when no config exists):

Cletus Browser Init

Usage

# Start browser mode (binds to localhost:3000 by default)
cletus --browser

# Specify custom port
cletus --browser --port 8080

Technical Notes

  • Operations run server-side with results streamed via WebSocket
  • Operation input/output displayed in collapsible sections
  • Static files served from dist-browser/ directory
  • No server-side rendering needed - fully client-side React app
  • WebSocket handles: chat initialization, message sending, status updates, streaming responses
  • Secure path resolution prevents directory traversal attacks

Build Process

  • Main CLI: esbuild.config.cjsdist/index.js
  • Browser client: esbuild.browser.cjsdist-browser/
  • Both built with npm run build

Security

  • ✅ CodeQL scan: No vulnerabilities found
  • ✅ Path traversal protection with resolved absolute paths
  • ✅ Localhost-only binding by default
  • ✅ No any/unknown TypeScript usage
  • ✅ Lazy loading of optional dependencies (sharp)
Original prompt

This section details on the original issue you should resolve

<issue_title>Cletus: Add --browser mode</issue_title>
<issue_description>When specified - instead of a CLI it launches a HTTP server & react client with a fancier UI for initialization, settings, chats, chat interface, and looking at all message & operation input & output. The operation input & output should be in collapsible sections. The react client app should be slick and responsive with a really good UX. The development should split out components very heavily to avoid massive files. The development should be done in a browser folder - leaving the existing code as untouched as possible. The client code should have the ability to have operation specific rendering just like what's in the CLI client in the operations folder. Since this is local there's not much use for having any server side functionality - if a server is avoidable at all that's fine. Use good TypeScript practices - use the existing types. Don't use any/unknown or forceful casting.</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: Cletus-Developer
An agent that understands the cletus package.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 16 commits December 16, 2025 17:43
Co-authored-by: ClickerMonkey <421233+ClickerMonkey@users.noreply.github.com>
Co-authored-by: ClickerMonkey <421233+ClickerMonkey@users.noreply.github.com>
Co-authored-by: ClickerMonkey <421233+ClickerMonkey@users.noreply.github.com>
Co-authored-by: ClickerMonkey <421233+ClickerMonkey@users.noreply.github.com>
Co-authored-by: ClickerMonkey <421233+ClickerMonkey@users.noreply.github.com>
Replaces legacy UI components with new modular components under 'ui', removes unused components, and introduces Tailwind CSS for styling. Adds Tailwind and related dependencies, updates build configs, and refactors browser app structure to support new operations and improved UI. Cleans up and reorganizes code for maintainability and scalability.
Introduces new React components for chat UI, including selectors for agent mode, assistant, model, and mode, as well as modals for chat settings, commands, and todos. Updates ChatInput and MessageItem to support richer metadata and message content, and improves UI consistency. Adds a migration script for chat message format and updates utility UI components for better accessibility and appearance.
Introduces an OperationApprovalPanel React component for approving or rejecting operations in chat messages. Updates the WebSocket server and protocol to handle operation approval, including new 'handle_operations' message types and backend logic for updating message operations. Refactors message and operation handling in ChatPage and related components, improves type safety, and cleans up unused props. Adds a browser-specific tsconfig for improved TypeScript support.
Adds folder picker for working directory in chat settings, improves chat title editing and message clearing confirmation in ChatPage, and synchronizes working directory (cwd) between client and server. Refactors BaseOperationDisplay to render JSON data in a more user-friendly HTML/table format. Updates websocket types and dba operation to support these changes.
Introduces UI and logic for approving/rejecting assistant operations, including bulk and per-operation controls. Refactors operation renderer components to support approval props and concise summaries, and centralizes operation renderer prop types. Updates ChatInput, MessageList, and ChatPage to handle operation approval state and actions.
Introduces a new QuestionsModal component for collecting user answers to dynamic questions. Integrates the modal into ChatPage, handling submission and cancellation, and updates chat metadata accordingly.
Introduces a new ToolsetSelector component for selecting toolsets in the chat UI and integrates it into ChatPage. Refactors the question answering flow: question answers are now submitted as structured data to the server, which formats and adds messages, clears questions, and triggers the orchestrator. Updates websocket types and server logic to support the new 'submit_question_answers' message. Cleans up ChatInput and AgentModeSelector UI for clarity.
Introduces a ProfileModal component for editing user settings in the browser UI, with support for updating user config via WebSocket. Adds persistent tool tracking in the chat agent context to keep recently used tools visible. Refactors toolset initialization and registration, and improves typing indicator UI. Also updates schemas, config, and WebSocket types to support user updates, and fixes minor UI and logic issues.
Replaces the main chat UI with a new UnifiedLayout component, consolidating chat, sidebar, and settings into a single layout. Refactors operation renderer files to use a new createRenderer utility for consistent display and summary logic, and improves summary details for file, shell, and type operations. Removes unused display settings from the profile modal and updates operation renderer type signatures for stricter typing.
@ClickerMonkey ClickerMonkey force-pushed the copilot/add-browser-mode-feature branch from 31f45c7 to 4c83e03 Compare December 18, 2025 02:56
Extracted chat orchestration logic into a reusable runChat function in server.ts to reduce code duplication and improve maintainability. Simplified OperationDisplay in index.tsx to directly use operation-specific renderers and moved the OperationDisplayProps interface to render.tsx.
Adds visual feedback and disables buttons during operation processing in ChatInput and BaseOperationDisplay. Introduces a 'hasOperationsProcessing' prop to ChatInput and updates UnifiedLayout to track and pass this state. Also adds a Cache (JSON) tab to operation details and removes the unused ChatPage component.
ChatSidebar header updated from 'Chats' to 'Cletus'. In server.ts, added process-level error and warning handlers to prevent silent crashes. Enhanced chat message persistence by saving or updating pending and complete messages immediately, ensuring no data loss on errors or cancellations. Improved fireAndForget utility to accept async functions, and ensured partial progress is saved on orchestrator errors.
Removed MainPage and ChatList components, consolidating chat selection and creation logic into UnifiedLayout and ChatSidebar. Improved message loading feedback and temporary message handling for a more responsive UI. Updated server-side WebSocket handling to support interruptible operations and more robust operation execution feedback. Added 'processing' state to client-server protocol for better UI state management.
Introduces a WebSocketContext and provider to manage WebSocket connections and state across the app. Refactors app and main page components to use the new context, improving code organization and connection lifecycle management. Updates websocket-types to support message handler unsubscription and connection state checks. Renames UnifiedLayout to MainPage for clarity.
Replaces useRef with useState for managing the WebSocket instance in WebSocketProvider. Updates context initialization and useWebSocket hook to improve type safety and error handling.
Refactors message creation to ensure consistent 'created' timestamps and corrects temporary message logic in MainPage. Improves chat state clearing on chat selection and prevents duplicate messages. Also updates renderer function signatures for better type safety.
Introduces an ImageViewer component for zooming, panning, and downloading images, and updates image rendering in MessageItem and artist operations to use ClickableImage. Adds a /file route to the browser server for serving local files, enabling secure access to images and other assets. Also increases summary display height in BaseOperationDisplay for improved readability.
Introduces ChatOperationManager and BroadcastManager to manage per-chat operation state and broadcast server events to all clients watching a chat. Adds ConnectionRegistry for tracking client subscriptions to chats, enabling real-time multi-client synchronization. Refactors WebSocket server and client logic to support chat subscription, operation state sync, and robust cancellation, and updates message types and handlers for chat-scoped events. Also improves chat creation UX and tool type safety.
Deleted obsolete components: ChatFooter, ChatHeader, CommandsPanel, and OperationApprovalPanel. Refactored operation display logic by moving and renaming BaseOperationDisplay to OperationDisplay, consolidating status helpers, and updating props usage. Improved operation approval handling and streamlined message operation status updates.
Expanded documentation for the cletus agent to include browser architecture, stricter TypeScript guidelines, and detailed instructions for adding and implementing tools and operations. Clarifies operation execution, code reuse, and rendering practices for both CLI and web environments.
@ClickerMonkey ClickerMonkey marked this pull request as ready for review December 20, 2025 03:15
@ClickerMonkey ClickerMonkey merged commit f3ad0e4 into main Dec 20, 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.

Cletus: Add --browser mode

2 participants