fix(cli/session): redirect Rich panels to stderr for JSON stdout export #10871

Closed
HAL9000 wants to merge 2 commits from feature/issue-10755-redirect-rich-panels-to-stderr into master

2 Commits

Author SHA1 Message Date
HAL9000 4530496def fix(cli/session): resolve undefined variables and lint errors in session CLI
CI / benchmark-publish (pull_request) Has been skipped
CI / helm (pull_request) Successful in 1m5s
CI / build (pull_request) Successful in 1m31s
CI / push-validation (pull_request) Successful in 43s
CI / lint (pull_request) Failing after 1m50s
CI / quality (pull_request) Successful in 2m10s
CI / typecheck (pull_request) Successful in 2m30s
CI / security (pull_request) Successful in 2m28s
CI / coverage (pull_request) Has been skipped
CI / integration_tests (pull_request) Successful in 5m13s
CI / e2e_tests (pull_request) Successful in 5m51s
CI / unit_tests (pull_request) Failing after 7m47s
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 3s
Fixed critical NameError bugs where fmt was referenced but not defined:
- import_session() now accepts fmt parameter (was crashing at runtime)
- tell() now accepts fmt parameter (was crashing at runtime)
- _render_export_panels() now computes panel_console from fmt internally

Also fixed:
- Type mismatch in delete(): use fmt.value for _get_panel_console (expects str)
- E501 line length violations in Panel.print() calls across 4 locations
- W293 trailing whitespace in _get_panel_console docstring
- B904 exception handling style in test step definitions
- Removed duplicate step definition conflict by renaming ambiguous Behave step

Signed-off-by: CleverThis <hal9000@cleverthis.com>
2026-05-11 05:32:37 +00:00
HAL9000 1212112f75 fix(cli/session): redirect Rich panels to stderr for JSON stdout export
CI / benchmark-publish (pull_request) Has been skipped
CI / push-validation (pull_request) Successful in 33s
CI / helm (pull_request) Successful in 37s
CI / build (pull_request) Successful in 58s
CI / lint (pull_request) Failing after 1m33s
CI / quality (pull_request) Successful in 1m35s
CI / typecheck (pull_request) Failing after 1m38s
CI / coverage (pull_request) Has been skipped
CI / security (pull_request) Successful in 1m38s
CI / unit_tests (pull_request) Failing after 3m21s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Failing after 3m56s
CI / e2e_tests (pull_request) Successful in 4m30s
CI / status-check (pull_request) Failing after 3s
When JSON format is requested via --format json, Rich panels (Session, Settings,
Actor Details, etc.) are now redirected to stderr instead of stdout. This ensures
that JSON output remains clean and can be reliably piped to other tools without
Rich markup pollution.

Implementation:
- Added _get_panel_console() helper function that returns a Console configured
  to write to stderr when JSON format is requested
- Updated all session CLI commands (create, list, show, delete, export, import)
  to use panel_console for Rich output instead of the default stdout console
- Added comprehensive BDD tests to verify JSON output purity and Rich panel
  redirection behavior

This fix enables clean JSON export for programmatic consumption while preserving
the rich visual experience for interactive terminal usage.

ISSUES CLOSED: #10755
2026-04-27 11:05:23 +00:00