bug(cli): --format color in format_output() renders plain text instead of ANSI-colored output #9347

Open
opened 2026-04-14 15:19:02 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: fix(cli): delegate --format color in format_output() to ColorMaterializer
  • Branch: fix/format-output-color-ansi

Background and Context

The Output Rendering Framework specification requires that --format color produces ANSI-colored terminal output. The ColorMaterializer class correctly produces ANSI codes when used directly via OutputSession. However, the legacy format_output() helper in src/cleveragents/cli/formatting.py does not delegate to ColorMaterializer — it calls _format_plain() instead, producing plain text with no ANSI codes.

This was discovered during UAT testing of the Output Rendering Framework (feature area: --format global flag).

Current Behavior

When format_output(data, 'color') is called (which is what CLI commands use when --format color is passed), the output is identical to plain text — no ANSI escape codes are present.

Reproduction:

from cleveragents.cli.formatting import format_output
result = format_output({'name': 'test', 'count': 42}, 'color')
# result == 'name: test\ncount: 42'  ← plain text, no ANSI codes

Source of the bug (src/cleveragents/cli/formatting.py, lines 319–320):

if fmt == OutputFormat.COLOR.value:
    return _format_plain(safe_data)  # ← BUG: should use ColorMaterializer

Contrast with correct behaviorColorMaterializer used directly via OutputSession produces ANSI output:

from cleveragents.cli.output import OutputSession, ColorMaterializer
strategy = ColorMaterializer()
with OutputSession(format='color', strategy=strategy) as session:
    panel = session.panel("Test Panel")
    panel.set_entry("name", "test")
    panel.close()
output = strategy.get_output()
# output == '\x1b[1m\x1b[36mTest Panel\x1b[0m\n  \x1b[1mname\x1b[0m: test'  ← ANSI codes present

Expected Behavior

format_output(data, 'color') should produce ANSI-colored output by delegating to ColorMaterializer (or equivalent ANSI rendering), consistent with the Output Rendering Framework specification and the behavior of ColorMaterializer when used directly.

The --format color CLI flag should produce colored terminal output with ANSI escape codes for key names, values, and panel titles.

Acceptance Criteria

  • format_output(data, 'color') returns a string containing ANSI escape codes (\x1b[)
  • The color output includes bold/colored key names and panel titles
  • The fix delegates to ColorMaterializer or format_output_session with color format
  • All existing BDD scenarios in features/output_rendering.feature and features/cli_output_formats.feature continue to pass
  • nox -s unit_tests -- features/output_rendering.feature features/cli_output_formats.feature passes

Supporting Information

  • Affected file: src/cleveragents/cli/formatting.py lines 319–320
  • Root cause: format_output() calls _format_plain() for color format instead of using ColorMaterializer
  • Related spec: Output Rendering Framework, ColorMaterializer (ANSI codes without cursor movement)
  • Feature files: features/output_rendering.feature, features/cli_output_formats.feature
  • Discovered by: UAT Test Pool — Output Rendering Framework test run (2026-04-14)

Subtasks

  • Update format_output() in src/cleveragents/cli/formatting.py to delegate color format to ColorMaterializer via format_output_session or direct OutputSession usage
  • Verify ANSI codes are present in color format output
  • Add/update BDD scenario in features/cli_output_formats.feature to assert ANSI codes in color output
  • Run nox -s unit_tests -- features/output_rendering.feature features/cli_output_formats.feature and confirm pass
  • Verify coverage ≥97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor

## Metadata - **Commit Message**: `fix(cli): delegate --format color in format_output() to ColorMaterializer` - **Branch**: `fix/format-output-color-ansi` --- ## Background and Context The Output Rendering Framework specification requires that `--format color` produces ANSI-colored terminal output. The `ColorMaterializer` class correctly produces ANSI codes when used directly via `OutputSession`. However, the legacy `format_output()` helper in `src/cleveragents/cli/formatting.py` does not delegate to `ColorMaterializer` — it calls `_format_plain()` instead, producing plain text with no ANSI codes. This was discovered during UAT testing of the Output Rendering Framework (feature area: `--format` global flag). ## Current Behavior When `format_output(data, 'color')` is called (which is what CLI commands use when `--format color` is passed), the output is identical to plain text — no ANSI escape codes are present. **Reproduction:** ```python from cleveragents.cli.formatting import format_output result = format_output({'name': 'test', 'count': 42}, 'color') # result == 'name: test\ncount: 42' ← plain text, no ANSI codes ``` **Source of the bug** (`src/cleveragents/cli/formatting.py`, lines 319–320): ```python if fmt == OutputFormat.COLOR.value: return _format_plain(safe_data) # ← BUG: should use ColorMaterializer ``` **Contrast with correct behavior** — `ColorMaterializer` used directly via `OutputSession` produces ANSI output: ```python from cleveragents.cli.output import OutputSession, ColorMaterializer strategy = ColorMaterializer() with OutputSession(format='color', strategy=strategy) as session: panel = session.panel("Test Panel") panel.set_entry("name", "test") panel.close() output = strategy.get_output() # output == '\x1b[1m\x1b[36mTest Panel\x1b[0m\n \x1b[1mname\x1b[0m: test' ← ANSI codes present ``` ## Expected Behavior `format_output(data, 'color')` should produce ANSI-colored output by delegating to `ColorMaterializer` (or equivalent ANSI rendering), consistent with the Output Rendering Framework specification and the behavior of `ColorMaterializer` when used directly. The `--format color` CLI flag should produce colored terminal output with ANSI escape codes for key names, values, and panel titles. ## Acceptance Criteria - [ ] `format_output(data, 'color')` returns a string containing ANSI escape codes (`\x1b[`) - [ ] The color output includes bold/colored key names and panel titles - [ ] The fix delegates to `ColorMaterializer` or `format_output_session` with `color` format - [ ] All existing BDD scenarios in `features/output_rendering.feature` and `features/cli_output_formats.feature` continue to pass - [ ] `nox -s unit_tests -- features/output_rendering.feature features/cli_output_formats.feature` passes ## Supporting Information - **Affected file:** `src/cleveragents/cli/formatting.py` lines 319–320 - **Root cause:** `format_output()` calls `_format_plain()` for `color` format instead of using `ColorMaterializer` - **Related spec:** Output Rendering Framework, `ColorMaterializer` (ANSI codes without cursor movement) - **Feature files:** `features/output_rendering.feature`, `features/cli_output_formats.feature` - **Discovered by:** UAT Test Pool — Output Rendering Framework test run (2026-04-14) ## Subtasks - [ ] Update `format_output()` in `src/cleveragents/cli/formatting.py` to delegate `color` format to `ColorMaterializer` via `format_output_session` or direct `OutputSession` usage - [ ] Verify ANSI codes are present in `color` format output - [ ] Add/update BDD scenario in `features/cli_output_formats.feature` to assert ANSI codes in `color` output - [ ] Run `nox -s unit_tests -- features/output_rendering.feature features/cli_output_formats.feature` and confirm pass - [ ] Verify coverage ≥97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor
HAL9000 added this to the v3.2.0 milestone 2026-04-14 15:24:14 +00:00
Author
Owner

Triage: Verified [AUTO-OWNR-1]

Valid bug: --format color in format_output() renders plain text instead of ANSI-colored output. The root cause is that format_output() calls _format_plain() for the color format instead of delegating to ColorMaterializer. The ColorMaterializer class correctly produces ANSI codes when used directly, but the legacy format_output() helper bypasses it.

Assigning to v3.2.0 as output rendering is core infrastructure. Priority Medium — the color format is broken.

MoSCoW: Should Have — ANSI-colored output is an important feature for terminal users, but the data is still accessible via other formats.


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

✅ **Triage: Verified** [AUTO-OWNR-1] Valid bug: `--format color` in `format_output()` renders plain text instead of ANSI-colored output. The root cause is that `format_output()` calls `_format_plain()` for the `color` format instead of delegating to `ColorMaterializer`. The `ColorMaterializer` class correctly produces ANSI codes when used directly, but the legacy `format_output()` helper bypasses it. Assigning to **v3.2.0** as output rendering is core infrastructure. Priority **Medium** — the color format is broken. MoSCoW: **Should Have** — ANSI-colored output is an important feature for terminal users, but the data is still accessible via other formats. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
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#9347
No description provided.