diff --git a/features/session_cli.feature b/features/session_cli.feature index 643843a32..901283243 100644 --- a/features/session_cli.feature +++ b/features/session_cli.feature @@ -119,6 +119,12 @@ Feature: Session CLI commands And the session CLI output should be valid JSON And the session CLI JSON envelope message should be "Session deleted" + Scenario: Delete session with --format color emits Rich output + Given there is a mocked session to delete + When I run session CLI delete with --yes and --format color + Then the session CLI delete should succeed + And the session CLI output should contain "deleted" + Scenario: Delete non-existent session When I run session CLI delete with a non-existent ID Then the session CLI should exit with error diff --git a/features/steps/session_cli_steps.py b/features/steps/session_cli_steps.py index 0cabe09a7..e3321f176 100644 --- a/features/steps/session_cli_steps.py +++ b/features/steps/session_cli_steps.py @@ -428,6 +428,13 @@ def step_delete_yes_json(context: Context) -> None: ) +@when("I run session CLI delete with --yes and --format color") +def step_delete_yes_color(context: Context) -> None: + context.result = context.runner.invoke( + session_app, ["delete", context.session_id, "--yes", "--format", "color"] + ) + + @when("I run session CLI delete with a non-existent ID") def step_delete_nonexistent(context: Context) -> None: context.mock_service.get.side_effect = SessionNotFoundError("Session not found") diff --git a/src/cleveragents/cli/commands/session.py b/src/cleveragents/cli/commands/session.py index a73730df5..f65c51a5c 100644 --- a/src/cleveragents/cli/commands/session.py +++ b/src/cleveragents/cli/commands/session.py @@ -717,9 +717,21 @@ def delete( service.delete(session_id) - # Rich output: render Deletion Summary and Cleanup panels - if fmt == OutputFormat.RICH: - # Deletion Summary panel + if fmt not in (OutputFormat.RICH, OutputFormat.COLOR): + # Machine-readable formats: emit a structured JSON/YAML envelope per spec + # (docs/specification.md §"agents session delete" line ~1959) + typer.echo( + format_output( + {"session_id": session_id}, + fmt.value, + command=_command_label( + "delete", session_id, "--yes", "--format", fmt.value + ), + messages=[{"level": "ok", "text": "Session deleted"}], + ) + ) + else: + # Rich/Color output: render Deletion Summary and Cleanup panels summary_table = Table.grid(padding=(0, 1)) summary_table.add_column(style="cyan bold", justify="left") summary_table.add_column(style="white", justify="left") @@ -746,19 +758,6 @@ def delete( console.print(Panel(cleanup_table, title="Cleanup", border_style="blue")) console.print() console.print("[green]✓ OK[/green] Session deleted") - else: - # Non-rich formats: emit a structured JSON/YAML envelope per spec - # (docs/specification.md §"agents session delete" line ~1959) - typer.echo( - format_output( - {"session_id": session_id}, - fmt.value, - command=_command_label( - "delete", session_id, "--yes", "--format", fmt.value - ), - messages=[{"level": "ok", "text": "Session deleted"}], - ) - ) except SessionNotFoundError as exc: console.print(f"[red]Session not found:[/red] {session_id}")