UAT: CLEVERAGENTS_FORMAT env var not checked in CLI format resolution — ADR-021 requires env var override #4771

Open
opened 2026-04-08 18:55:45 +00:00 by HAL9000 · 1 comment
Owner

Bug Report

Feature area: Output rendering framework / format resolution
Severity: Medium
Discovered by: UAT Testing (uat-tester-cli-rendering-001)


Expected Behavior (from ADR-021)

ADR-021 specifies the format resolution chain:

The format is resolved per-invocation: --format CLI flag > CLEVERAGENTS_FORMAT env var > core.format config key > default (rich).

Setting CLEVERAGENTS_FORMAT=json should make all CLI commands output JSON by default, without needing to pass --format json every time.

Expected usage:

export CLEVERAGENTS_FORMAT=json
agents version          # Should output JSON
agents info             # Should output JSON
agents config list      # Should output JSON

Actual Behavior

The main_callback in src/cleveragents/cli/main.py uses OutputFormat.RICH as the hardcoded default without checking CLEVERAGENTS_FORMAT:

# src/cleveragents/cli/main.py lines 310-320
fmt: Annotated[
    OutputFormat,
    typer.Option(
        "--format",
        "-f",
        help="Output format for all subcommands: ...",
    ),
] = OutputFormat.RICH,  # Hardcoded default — CLEVERAGENTS_FORMAT not checked!

The Settings class in config/settings.py does define format reading from CLEVERAGENTS_FORMAT (line 136-143), but this value is never used to set the default in main_callback.

This is documented as a known deviation in src/cleveragents/cli/output/__init__.py:

SD-15 (CLEVERAGENTS_FORMAT env var not checked)
The spec defines CLEVERAGENTS_FORMAT for overriding the default format. This implementation only accepts --format CLI flag.

Steps to Reproduce

export CLEVERAGENTS_FORMAT=json
agents version
# Outputs Rich-formatted text instead of JSON

Code Location

  • src/cleveragents/cli/main.pymain_callback function (lines 310–320)
  • src/cleveragents/config/settings.pyformat field (lines 136–143)
  • src/cleveragents/cli/output/__init__.py — SD-15 deviation note (lines 79–81)

Fix Required

Read CLEVERAGENTS_FORMAT (or settings.format) in main_callback to set the default format:

import os

@app.callback()
def main_callback(
    ctx: typer.Context,
    ...
    fmt: Annotated[
        OutputFormat,
        typer.Option("--format", "-f", help="..."),
    ] = OutputFormat.RICH,
) -> None:
    # Resolve format: CLI flag > CLEVERAGENTS_FORMAT env var > core.format config > rich
    effective_fmt = fmt
    if fmt == OutputFormat.RICH:  # Only override if user didn't explicitly set --format
        env_format = os.environ.get("CLEVERAGENTS_FORMAT", "").lower()
        if env_format in {f.value for f in OutputFormat}:
            effective_fmt = OutputFormat(env_format)
    
    ctx.ensure_object(dict)
    ctx.obj["format"] = effective_fmt.value

References

  • ADR-021 §Six Output Formats: "The format is resolved per-invocation: --format CLI flag > CLEVERAGENTS_FORMAT env var > core.format config key > default (rich)"
  • src/cleveragents/cli/output/__init__.py SD-15 deviation note
  • src/cleveragents/config/settings.py lines 136–143

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: uat-tester

## Bug Report **Feature area:** Output rendering framework / format resolution **Severity:** Medium **Discovered by:** UAT Testing (uat-tester-cli-rendering-001) --- ## Expected Behavior (from ADR-021) ADR-021 specifies the format resolution chain: > The format is resolved per-invocation: `--format` CLI flag > `CLEVERAGENTS_FORMAT` env var > `core.format` config key > default (`rich`). Setting `CLEVERAGENTS_FORMAT=json` should make all CLI commands output JSON by default, without needing to pass `--format json` every time. **Expected usage:** ```bash export CLEVERAGENTS_FORMAT=json agents version # Should output JSON agents info # Should output JSON agents config list # Should output JSON ``` ## Actual Behavior The `main_callback` in `src/cleveragents/cli/main.py` uses `OutputFormat.RICH` as the hardcoded default without checking `CLEVERAGENTS_FORMAT`: ```python # src/cleveragents/cli/main.py lines 310-320 fmt: Annotated[ OutputFormat, typer.Option( "--format", "-f", help="Output format for all subcommands: ...", ), ] = OutputFormat.RICH, # Hardcoded default — CLEVERAGENTS_FORMAT not checked! ``` The `Settings` class in `config/settings.py` does define `format` reading from `CLEVERAGENTS_FORMAT` (line 136-143), but this value is never used to set the default in `main_callback`. This is documented as a known deviation in `src/cleveragents/cli/output/__init__.py`: > **SD-15 (CLEVERAGENTS_FORMAT env var not checked)** > The spec defines `CLEVERAGENTS_FORMAT` for overriding the default format. This implementation only accepts `--format` CLI flag. ## Steps to Reproduce ```bash export CLEVERAGENTS_FORMAT=json agents version # Outputs Rich-formatted text instead of JSON ``` ## Code Location - `src/cleveragents/cli/main.py` — `main_callback` function (lines 310–320) - `src/cleveragents/config/settings.py` — `format` field (lines 136–143) - `src/cleveragents/cli/output/__init__.py` — SD-15 deviation note (lines 79–81) ## Fix Required Read `CLEVERAGENTS_FORMAT` (or `settings.format`) in `main_callback` to set the default format: ```python import os @app.callback() def main_callback( ctx: typer.Context, ... fmt: Annotated[ OutputFormat, typer.Option("--format", "-f", help="..."), ] = OutputFormat.RICH, ) -> None: # Resolve format: CLI flag > CLEVERAGENTS_FORMAT env var > core.format config > rich effective_fmt = fmt if fmt == OutputFormat.RICH: # Only override if user didn't explicitly set --format env_format = os.environ.get("CLEVERAGENTS_FORMAT", "").lower() if env_format in {f.value for f in OutputFormat}: effective_fmt = OutputFormat(env_format) ctx.ensure_object(dict) ctx.obj["format"] = effective_fmt.value ``` ## References - ADR-021 §Six Output Formats: "The format is resolved per-invocation: `--format` CLI flag > `CLEVERAGENTS_FORMAT` env var > `core.format` config key > default (`rich`)" - `src/cleveragents/cli/output/__init__.py` SD-15 deviation note - `src/cleveragents/config/settings.py` lines 136–143 --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — spec compliance bug identified by UAT testing
  • Story Points: 3 (M) — targeted fix to align implementation with spec
  • MoSCoW: Must Have — spec compliance is required for correct system behavior

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — spec compliance bug identified by UAT testing - **Story Points**: 3 (M) — targeted fix to align implementation with spec - **MoSCoW**: Must Have — spec compliance is required for correct system behavior --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:04:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#4771
No description provided.