output
output
¶
Rich output formatting for Marianne CLI.
This module centralizes all Rich-based formatting utilities for the CLI: - Color schemes for status values - Table builders with consistent styling - Progress bar configurations - Panel formatting helpers - Status and duration formatters
★ Insight ───────────────────────────────────── 1. Color scheme consistency: Centralizing color mappings in one module ensures visual consistency across all CLI commands. Users associate colors with meanings (green=success, red=error), so consistency builds intuitive understanding.
-
Table factory pattern: Instead of duplicating Table() configurations across commands, factory functions encapsulate styling decisions. This makes it easy to adjust all tables' appearance in one place.
-
Progress bar customization: Rich's Progress supports extensive customization via column composition. We define reusable configurations for different progress display needs (simple vs detailed with ETA). ─────────────────────────────────────────────────
Classes¶
StatusColors
¶
Functions¶
format_sheet_display_status
¶
Return (display_label, color) for a sheet's user-facing status.
Maps 'completed' with failed validations to 'failed' in user-facing output. A sheet that exhausted retries and was marked terminal is not 'completed' in any meaningful sense — displaying it as such misleads users (F-045).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
SheetStatus
|
The sheet's internal status enum. |
required |
validation_passed
|
bool | None
|
Whether validations passed. False = failed, None = no validations or not yet validated, True = passed. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
Tuple of (display_label, rich_color_name). |
Source code in src/marianne/cli/output.py
format_duration
¶
Format a duration in seconds to human-readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seconds
|
float | None
|
Duration in seconds, or None. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Human-readable duration string (e.g., "5.2s", "3m 12s", "1h 30m", "6d 12h"). |
Source code in src/marianne/cli/output.py
format_bytes
¶
Format bytes to human-readable string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_bytes
|
int
|
Number of bytes. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Human-readable size string (e.g., "128B", "1.5KB", "2.3MB"). |
Source code in src/marianne/cli/output.py
format_relative_time
¶
Format a datetime as a human-readable relative time string.
Produces compact relative times like "5m ago", "3h 15m ago", "6d 12h ago". Used in status displays where relative context matters more than absolute timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime | None
|
Datetime to format, or None. |
required |
now
|
datetime | None
|
Reference time for computing the delta. Defaults to UTC now. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Relative time string, or "-" if dt is None. |
Source code in src/marianne/cli/output.py
format_timestamp
¶
Format a datetime for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
datetime | None
|
datetime to format, or None. |
required |
include_tz
|
bool
|
Whether to include timezone suffix. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted timestamp string, or "-" if None. |
Source code in src/marianne/cli/output.py
format_validation_status
¶
Format validation status with appropriate styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passed
|
bool | None
|
True if passed, False if failed, None if not run. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rich-formatted validation status string. |
Source code in src/marianne/cli/output.py
format_error_code_for_display
¶
Format an error code for CLI display.
Prefers the structured error_code (e.g., "E006") when available. Falls back to mapping the error_category to its canonical error code prefix. Returns "E999" when neither is available.
This ensures the CLI never shows raw category strings like "timeout" as error codes — it always shows a proper Exx code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_code
|
str | None
|
Structured error code from SheetState (e.g., "E006"). |
required |
error_category
|
str | None
|
Error category string or ErrorCategory enum value. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A proper error code string (e.g., "E006", "E001", "E999"). |
Source code in src/marianne/cli/output.py
infer_error_type
¶
Infer error type from error category string or error code.
Recognizes both human-readable category strings (e.g., "rate_limit", "timeout") and structured error codes (e.g., "E101", "E006").
Error code ranges
E0xx (execution): transient — timeouts, kills, crashes, stale E1xx (rate/capacity): rate_limit — API limits, CLI limits, quota E2xx+ (validation/auth/config/unknown): permanent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error_category
|
str | None
|
Error category or error code from sheet state. |
required |
Returns:
| Type | Description |
|---|---|
Literal['transient', 'rate_limit', 'permanent']
|
Error type literal: transient, rate_limit, or permanent. |
Source code in src/marianne/cli/output.py
create_jobs_table
¶
Create a styled table for job listings.
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for job list display. |
Source code in src/marianne/cli/output.py
create_sheet_plan_table
¶
Create a styled table for dry-run sheet plan display.
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for sheet plan display. |
Source code in src/marianne/cli/output.py
create_sheet_details_table
¶
Create a styled table for detailed sheet status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
has_descriptions
|
bool
|
When True, adds a Description column after the
sheet number. Populated from |
False
|
has_instruments
|
bool
|
When True, adds an Instrument column showing which
instrument ran each sheet. Populated from
|
False
|
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for sheet details display. |
Source code in src/marianne/cli/output.py
create_synthesis_table
¶
Create a styled table for synthesis results (v18 evolution).
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for synthesis result display. |
Source code in src/marianne/cli/output.py
create_errors_table
¶
Create a styled table for error display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Optional title for the table. |
'Errors'
|
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for error display. |
Source code in src/marianne/cli/output.py
create_timeline_table
¶
Create a styled table for execution timeline.
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for timeline display. |
Source code in src/marianne/cli/output.py
create_patterns_table
¶
Create a styled table for learning pattern display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title for the patterns table. |
'Learned Patterns'
|
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table configured for pattern display. |
Source code in src/marianne/cli/output.py
create_simple_table
¶
Create a simple table without box styling.
Useful for key-value displays or compact listings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
show_header
|
bool
|
Whether to show column headers. |
False
|
Returns:
| Type | Description |
|---|---|
Table
|
Rich Table with minimal styling. |
Source code in src/marianne/cli/output.py
create_execution_progress
¶
Create a detailed progress bar for job execution.
Includes spinner, percentage, sheet count, elapsed time, ETA, and execution status display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console_instance
|
Console | None
|
Optional console to use. Defaults to module console. |
None
|
Returns:
| Type | Description |
|---|---|
Progress
|
Configured Progress instance (not yet started). |
Source code in src/marianne/cli/output.py
create_status_progress
¶
Create a simple progress bar for status display.
Shows description, bar, percentage, and count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console_instance
|
Console | None
|
Optional console to use. Defaults to module console. |
None
|
Returns:
| Type | Description |
|---|---|
Progress
|
Configured Progress instance (not yet started). |
Source code in src/marianne/cli/output.py
create_header_panel
¶
Create a header panel with consistent styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lines
|
Sequence[str]
|
Lines of text to display in the panel. |
required |
title
|
str
|
Panel title. |
required |
border_style
|
str
|
Border color/style (e.g., "cyan", "green", "yellow"). |
'default'
|
Returns:
| Type | Description |
|---|---|
Panel
|
Configured Panel instance. |
Source code in src/marianne/cli/output.py
create_run_summary_panel
¶
Create a run summary panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
JobCompletionSummary
|
RunSummary instance with job completion data. |
required |
job_status
|
JobStatus
|
Final job status for border color. |
required |
Returns:
| Type | Description |
|---|---|
Panel
|
Panel with styled run summary. |
Source code in src/marianne/cli/output.py
create_diagnostic_panel
¶
Create a diagnostic report header panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_name
|
str
|
Name of the job. |
required |
job_id
|
str
|
Job identifier. |
required |
status
|
JobStatus
|
Current job status. |
required |
Returns:
| Type | Description |
|---|---|
Panel
|
Panel with diagnostic header info. |
Source code in src/marianne/cli/output.py
create_server_panel
¶
Create a server startup info panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Panel title. |
required |
server_name
|
str
|
Name of the server being started. |
required |
info_lines
|
Sequence[str]
|
Additional info lines (URLs, settings, etc.). |
required |
Returns:
| Type | Description |
|---|---|
Panel
|
Panel with server info. |
Source code in src/marianne/cli/output.py
output_error
¶
output_error(message, *, error_code=None, hints=None, severity='error', json_output=False, console_instance=None, **json_extras)
Output a formatted error/warning with optional hints and JSON alternative.
Consolidates the common CLI error output pattern: - Rich mode: colored error prefix, blank line, dim hints - JSON mode: structured dict with error_code, message, hints
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The error message to display. |
required |
error_code
|
str | None
|
Optional error code (e.g., "E501"). |
None
|
hints
|
list[str] | None
|
Optional list of hint strings for the user. |
None
|
severity
|
Literal['error', 'warning']
|
"error" (red) or "warning" (yellow). |
'error'
|
json_output
|
bool
|
If True, output as JSON instead of Rich markup. |
False
|
console_instance
|
Console | None
|
Console to print to. Defaults to module console. |
None
|
**json_extras
|
str | int | float | bool | None
|
Extra key-value pairs included in JSON output only. |
{}
|
Source code in src/marianne/cli/output.py
output_json
¶
Output JSON data safely without Rich markup interpretation.
Rich's console.print() interprets square bracket patterns like
[red] as markup tags, which corrupts JSON output. This function
ensures JSON is output verbatim using markup=False and
highlight=False.
Also handles non-serializable types (datetime, enum) via
default=str to prevent serialization crashes on real-world data.
Control characters and ANSI escape sequences in string values are stripped to prevent invalid JSON (F-032).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
object
|
JSON-serializable dict or list. |
required |
console_instance
|
Console | None
|
Console to print to. Defaults to module console. |
None
|
Source code in src/marianne/cli/output.py
format_error_details
¶
Format detailed error information for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
CheckpointErrorRecord
|
ErrorRecord object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string with error details. |
Source code in src/marianne/cli/output.py
format_job_status_line
¶
Format a single job's status as a styled line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
CheckpointState
|
CheckpointState to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Rich-formatted status line. |
Source code in src/marianne/cli/output.py
print_job_status_header
¶
Print job status header panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
CheckpointState
|
CheckpointState to display. |
required |
console_instance
|
Console | None
|
Console to print to. Defaults to module console. |
None
|
Source code in src/marianne/cli/output.py
print_timing_section
¶
Print job timing information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
CheckpointState
|
CheckpointState with timing data. |
required |
console_instance
|
Console | None
|
Console to print to. Defaults to module console. |
None
|
Source code in src/marianne/cli/output.py
format_rate_limit_info
¶
Format active rate limit data into user-friendly display lines.
Takes the backends dict from the daemon.rate_limits IPC response
and produces one line per active limit, e.g.:
"Rate limit on claude-cli — clears in 2m 30s"
Expired or zero-remaining limits are silently dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backends
|
dict[str, dict[str, float]]
|
Mapping of instrument name to |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of formatted strings, one per active rate limit. Empty if none active. |