CLI Logger & Spinner
Relevant source files
The following files were used as context for generating this wiki page:
The CLI Logger & Spinner module provides the primary user interface for Morty, offering real-time feedback on AI agent progress, task status, and system notifications. It encompasses terminal color management, status spinners for long-running operations, and cross-platform desktop notifications to alert users when tasks are completed or fail.
The system is implemented across both the original Bash-based implementation (morty.sh) and the modern TypeScript CLI. It ensures that users can track complex workflows, such as parallel execution across multiple isolated git worktrees, through concise and color-coded terminal output.
Logging and Visual Feedback
Morty employs a structured logging system to differentiate between informational messages, warnings, errors, and successful operations. In the Bash implementation, this is achieved through ANSI escape sequences and tput for terminal manipulation. The TypeScript implementation utilizes libraries like picocolors for stylized output.
Log Levels and Formatting
The system defines several distinct log levels, each associated with specific colors and prefixes:
| Level | Color/Style | Prefix | Description |
|---|---|---|---|
| Info | Blue | [INFO] | General operational information. |
| Success | Green | [OK] / ✓ | Successful completion of tasks or steps. |
| Warning | Yellow | [WARN] | Non-fatal issues or important notices. |
| Error | Red | [ERROR] / ✗ | Critical failures that may halt execution. |
| Debug | Dim / Gray | [DEBUG] | Detailed internal traces (active only in verbose mode). |
Sources: morty.sh:65-92, cli/src/ui/logger.ts:5-45
Terminal State Management
The Logger includes logic to detect if the terminal supports color output. In Bash, it checks tput colors to ensure color codes are only emitted when appropriate, preventing garbled output in environments that do not support them.
Sources: morty.sh:53-61
Progress Monitoring and Spinners
The Progress Monitor is a background system that provides a live visual indicator of the AI engine's current activity. It uses a spinning character sequence and a "step" descriptor that changes dynamically based on the AI's interaction with the codebase.
Dynamic Step Detection
The monitor parses the output stream of the AI engine to identify the current execution phase. It looks for specific patterns such as tool calls, shell commands, or file updates.
The diagram shows how the system maps AI output patterns to user-friendly status strings.
Sources: morty.sh:767-814
Spinner Implementation
Spinners are handled differently depending on the execution mode:
- Sequential Mode: A dedicated background process (
monitor_progress) manages the spinner and status text, clearing and redrawing the line usingtput crandtput el. - Parallel Mode: The system tracks multiple agents simultaneously, displaying a summarized status line that counts agents in "setup", "running", "done", or "failed" states.
Sources: morty.sh:816-832, morty.sh:1200-1235
Cross-Platform Notifications
Morty includes a notification system to alert users of task completion or errors, especially useful during long-running autonomous loops. This system leverages native OS capabilities across macOS, Linux, and Windows.
Notification Providers
The system attempts to use available binaries on the host system to trigger alerts:
| Operating System | Mechanism | Audio Feedback |
|---|---|---|
| macOS | osascript (AppleScript) | afplay (Glass.aiff) |
| Linux | notify-send | paplay (freedesktop sounds) |
| Windows | powershell.exe | System.Media.SystemSounds |
Sources: morty.sh:841-876, cli/src/ui/notify.ts:10-50
The sequence diagram illustrates the platform-specific branching logic for sending notifications.
Sources: morty.sh:841-861, cli/src/ui/notify.ts
Parallel Execution UI
When running in parallel mode (--parallel), the CLI Logger transitions to a batch-oriented display. This interface manages the complexity of multiple agents working in isolated git worktrees.
Batch Results Display
For each batch of parallel agents, the logger outputs:
- Spawn Header: Indicates the batch number and number of agents being spawned.
- Live Summary: A single line refreshed via the spinner that shows the real-time count of agent statuses.
- Final Tally: A detailed list of each agent's result, including the task name, branch name created, and input/output token usage.
- Error Logs: If an agent fails, the logger extracts and displays the first 20 lines of that specific agent's log file for immediate debugging.
Sources: morty.sh:1165-1175, morty.sh:1240-1285, cli/src/execution/parallel.ts:165-210
Summary Reporting
Upon completion of the entire PRD or task list, a final summary is rendered including:
- Token Usage: Aggregated input and output tokens across all iterations.
- Cost Estimation: A calculated cost based on token counts or actual cost reported by engines like OpenCode.
- Duration: For engines like Cursor or Factory Droid, the total API time in minutes and seconds.
- Branches: A list of all git branches created during the session.
Sources: morty.sh:1463-1517
Conclusion
The CLI Logger & Spinner module is critical for maintaining visibility into Morty's autonomous operations. By combining dynamic progress monitoring, tiered logging, and native system notifications, it provides a robust feedback loop that allows developers to monitor complex, multi-agent coding tasks without constant terminal supervision.