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
Attributes¶
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:¶
live_conductor_pid
¶
The PID the active conductor's PID file names, if that process is alive.
Clone-aware. This is the evidence that separates "busy" from "absent" (GH #455): a socket that does not answer while this PID is alive is a conductor blocked on disk, never one to start or restart. Reads only; never asserts or unlinks a PID file.
Source code in src/marianne/cli/helpers.py
conductor_socket_present
¶
Whether the socket the CLI would route through exists (clone-aware).
Source code in src/marianne/cli/helpers.py
busy_conductor_message
¶
The one sentence every CLI path uses for a live conductor that did not answer.
Source code in src/marianne/cli/helpers.py
report_daemon_route_error
¶
Report an IPC outcome once, without changing its running-state meaning.
An absent verdict needs two proofs: the connect was refused or the socket
is missing, AND no live PID is held. With a live PID the same failure is
reported busy (GH #455), and no path here ever suggests mzt start,
mzt restart or mzt stop --force for a conductor that may be alive.
Source code in src/marianne/cli/helpers.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
report_daemon_access_denied
¶
Preserve the established denial reporting entry point.
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 "not running" with the hint "Start it with: mzt start" only when no live PID is held; a live PID makes the same outcome "busy or unresponsive" (GH #455).
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. |