helpers
helpers
¶
Shared utilities for Marianne CLI commands.
This module contains helpers used across multiple CLI command modules: - Logger setup and configuration - Backend creation helpers - Config loading utilities - Console/Rich setup - State backend discovery - Common utility functions
Classes¶
ErrorMessages
¶
Constants for CLI error messages.
Centralizing error messages ensures consistent user-facing output and simplifies potential localization.
OutputLevel
¶
Bases: str, Enum
Output verbosity level.
CliLoggingConfig
dataclass
¶
Centralized CLI logging configuration state.
Replaces 4 module-level variables with a single typed dataclass. All getter/setter functions below delegate to this instance.
Functions¶
set_output_level
¶
Set the output level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
OutputLevel
|
The new output level. |
required |
is_verbose
¶
is_quiet
¶
set_log_level
¶
Set the log level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Log level string (DEBUG, INFO, WARNING, ERROR). |
required |
set_log_file
¶
Set the log file path.
When a log file is specified, logs are written to the file in console format. Rich CLI output (progress bars, status tables) is separate from structured logging and still displays on console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Path for log file output, or None to disable file logging. |
required |
Source code in src/marianne/cli/helpers.py
set_log_format
¶
Set the log format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmt
|
str
|
Log format string (json, console, both). |
required |
configure_global_logging
¶
Configure logging based on global CLI options.
This is called after all callbacks have processed their options. Only configures once per session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Console
|
Rich console for error output. |
required |
Raises:
| Type | Description |
|---|---|
Exit
|
If logging configuration fails. |
Source code in src/marianne/cli/helpers.py
create_notifiers_from_config
¶
Create Notifier instances from notification configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification_configs
|
list[NotificationConfig]
|
List of NotificationConfig from job config. |
required |
Returns:
| Type | Description |
|---|---|
list[Notifier]
|
List of configured Notifier instances. |
Source code in src/marianne/notifications/factory.py
require_conductor
¶
Exit with a clear error when the conductor is not running.
Used by CLI commands that route through the conductor IPC. If the
conductor was not reachable, this prints a helpful message directing
the user to mzt start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
routed
|
bool
|
Whether |
required |
json_output
|
bool
|
If True, output error as JSON instead of Rich markup. |
False
|
Raises:
| Type | Description |
|---|---|
Exit(1)
|
If the conductor is not running. |
Source code in src/marianne/cli/helpers.py
await_early_failure
async
¶
Poll job status briefly to detect early failures after submission.
After a job is submitted and accepted, template rendering errors or
other immediate failures happen within milliseconds. This function
polls the daemon for up to timeout seconds so the CLI can report
the failure inline instead of printing a cheerful "Job queued".
Fail-open: any exception returns None so this never blocks the CLI.
Source code in src/marianne/cli/helpers.py
query_rate_limits
async
¶
Query the conductor for active rate limit information.
Returns the backends dict from the daemon.rate_limits IPC
response, e.g. {"claude-cli": {"seconds_remaining": 120.0}}.
Returns None if the conductor is unreachable or an error occurs.
Fail-open: this never raises — callers can safely display extra info
when available and skip it when not.
Source code in src/marianne/cli/helpers.py
check_pid_alive
¶
Check if a process with the given PID is running.
Uses os.kill(pid, 0) — signal 0 checks existence without sending
a signal.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in src/marianne/cli/helpers.py
get_last_activity_time
¶
Get the most recent activity timestamp from the job.
Checks sheet last_activity_at fields and updated_at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
CheckpointState
|
CheckpointState to check. |
required |
Returns:
| Type | Description |
|---|---|
datetime | None
|
datetime of last activity, or None if not available. |