Feature: CLI output formats parity
  As a developer using the CleverAgents CLI
  I want all action and plan commands to support --format json|yaml|plain|table|rich
  So that I can integrate CLI output with external tooling

  Background:
    Given a CLI output format test runner
    And a mocked lifecycle service for format tests

  # Action list --format json
  Scenario: Action list outputs valid JSON
    Given there are actions for format testing
    When I run action list with --format json
    Then the output should be valid JSON
    And the JSON should contain key "namespaced_name"

  # Action show --format yaml
  Scenario: Action show outputs valid YAML
    Given there is a single action for format testing
    When I run action show with --format yaml
    Then the output should be valid YAML
    And the YAML should contain key "namespaced_name"

  # Plan list --format json
  Scenario: Plan list outputs valid JSON
    Given there are plans for format testing
    When I run plan list with --format json
    Then the output should be valid JSON
    And the JSON should contain key "plan_id"

  # Plan status --format json (single plan)
  Scenario: Plan status single plan outputs valid JSON
    Given there is a single plan for format testing
    When I run plan status with plan id and --format json
    Then the output should be valid JSON
    And the JSON should contain key "processing_state"

  # Plan status --format plain (single plan)
  Scenario: Plan status single plan outputs plain text
    Given there is a single plan for format testing
    When I run plan status with plan id and --format plain
    Then the format output should contain "plan_id:"
    And the format output should contain "processing_state:"

  # Action list --format table
  Scenario: Action list outputs table format
    Given there are actions for format testing
    When I run action list with --format table
    Then the format output should contain "namespaced_name"

  # Action list --format plain
  Scenario: Action list outputs plain format
    Given there are actions for format testing
    When I run action list with --format plain
    Then the format output should contain "namespaced_name:"

  # Action archive --format json
  Scenario: Action archive outputs valid JSON
    Given there is an archivable action for format testing
    When I run action archive with --format json
    Then the output should be valid JSON
    And the JSON should contain key "archived"

  # Plan status list all --format json
  Scenario: Plan status no args outputs valid JSON for list
    Given there are plans for format status listing
    When I run plan status without id and --format json
    Then the output should be valid JSON
    And the JSON should contain key "plan_id"

  # Plan use --format json
  Scenario: Plan use outputs valid JSON
    Given there is an action for plan use format test
    When I run plan use with --format json
    Then the output should be valid JSON
    And the JSON should contain key "plan_id"

  # Plan cancel --format json
  Scenario: Plan cancel outputs valid JSON
    Given there is a plan for cancel format test
    When I run plan cancel with --format json
    Then the output should be valid JSON
    And the JSON should contain key "processing_state"

  # Format consistency: same data, different renders
  Scenario: JSON and YAML contain the same action keys
    Given there is a single action for format testing
    When I run action show with --format json
    And I save the output keys as json_keys
    And I run action show with --format yaml
    And I save the output keys as yaml_keys
    Then json_keys and yaml_keys should match

  # Direct formatting module tests
  @tdd_issue @tdd_issue_4364 @tdd_expected_fail
  Scenario: Format output handles all format types for dict
    When I call format_output with a dict and format json
    Then the format result should be valid JSON dict
    When I call format_output with a dict and format yaml
    Then the format result should be valid YAML dict
    When I call format_output with a dict and format plain
    Then the format result should contain plain key-value pairs
    When I call format_output with a dict and format table
    Then the format result should contain table output
    When I call format_output with a dict and format rich
    Then the format result should be valid JSON dict

  Scenario: Format output handles list data
    When I call format_output with a list and format plain
    Then the format result should contain separator lines

  Scenario: Serialize value handles enums and nested dicts
    When I call serialize_value with enum and nested data
    Then the serialized result should have string enum values
