Skip to content

Latest commit

 

History

History
90 lines (64 loc) · 4.69 KB

File metadata and controls

90 lines (64 loc) · 4.69 KB

UI and Logging Systems

The cli_engineer tool features a flexible and informative user interface and logging system designed to provide insight into the agent's operations. It offers two primary UI modes and a robust logging mechanism that can operate in tandem.

User Interface (UI)

The application provides two distinct user experiences: a real-time Dashboard UI (default) and an Enhanced Text UI for simpler, script-friendly output.

1. Dashboard UI (ui_dashboard.rs)

The Dashboard is the default, recommended interface for interactive use. It provides a rich, in-place updating view of the agent's status without scrolling.

Key Features:

  • Real-Time Metrics: Displays API calls, total cost, artifacts created, and context usage.
  • Live Progress: Shows the current phase, task description, and overall progress.
  • In-Place Updates: Uses crossterm to control the terminal, rendering a static layout that updates its content dynamically.
  • Dual Log Panes:
    • Session Logs: A top pane shows formatted and colored log output (INFO, WARN, ERROR).
    • Model Reasoning: A bottom pane streams the LLM's "thoughts" or reasoning process in real-time, offering a look into how it makes decisions.
  • Event-Driven: The UI listens to events from the EventBus to update its state, decoupling it from the core application logic.

This UI is managed by the DashboardUI struct and is initialized in main.rs when the --no-dashboard flag is absent.

// From src/main.rs (simplified)
if !args.no_dashboard {
    // Use dashboard UI
    let mut ui = DashboardUI::new(false);
    ui.set_event_bus(event_bus.clone());
    ui.start()?;
    // ... run agent ...
    ui.finish()?;
}

2. Enhanced Text UI (ui_enhanced.rs)

When the --no-dashboard flag is used, the application falls back to a more traditional, scrolling terminal output, managed by the EnhancedUI struct.

Key Features:

  • Progress Bars: Uses the indicatif crate to display multi-line progress bars for the main task and metrics.
  • Colored Output: Provides clear, color-coded status messages for different events (e.g., task start, artifact creation, errors).
  • Session Summary: Prints a final summary of metrics upon completion.
  • Script-Friendly: The linear, scrolling output is suitable for CI/CD pipelines or logging to a file.

3. Legacy UI (ui.rs)

The src/ui.rs file contains a basic, legacy UI handler (UIHandler) that shows a simple spinning character (|, /, -, \). It serves as a minimal fallback but is largely superseded by the DashboardUI and EnhancedUI.

Logging Infrastructure

The logging system is designed to work seamlessly with both UI modes and provide persistent records of agent sessions.

1. Dashboard Logger (logger_dashboard.rs)

This is the primary logger used with the Dashboard UI. It's a custom implementation of the log::Log trait.

How it Works:

  1. It's initialized in main.rs when in dashboard mode.
  2. It captures all log records generated by the application (using the log crate macros like info!, warn!, etc.).
  3. Instead of printing directly to the console, it creates an Event::LogLine and emits it to the EventBus.
  4. The DashboardUI subscribes to the EventBus and displays these LogLine events in its log pane.
  5. If file logging is enabled (-v flag), it simultaneously writes the formatted log message to a timestamped file (e.g., cli_engineer_20240915_183000.log).

This architecture decouples the logging source from the display, allowing the UI to handle rendering without interfering with the application's execution flow.

2. Simple Logger (logger.rs)

This logger is used in --no-dashboard mode. It's a straightforward setup using the simplelog crate.

How it Works:

  1. It initializes a SimpleLogger that writes directly to the standard error stream.
  2. The log level is determined by the -v flag (Info if verbose, Warn otherwise).
  3. The init_with_file_logging function configures a file writer to save all session logs to a timestamped file when -v is active.

Interaction and Flow

The choice of UI and logger is determined at startup in main.rs:

  1. Default Mode (No flags):

    • DashboardUI is created.
    • DashboardLogger is initialized.
    • DashboardLogger captures logs -> EventBus.
    • DashboardUI listens to EventBus and renders logs, metrics, and progress.
  2. Simple Mode (--no-dashboard):

    • EnhancedUI is created.
    • logger::init() or logger::init_with_file_logging() is called.
    • SimpleLogger writes logs directly to the console and/or a file.
    • EnhancedUI listens to the EventBus for progress and status events to update its progress bars.