@cli
Feature: Global --format flag propagation to subcommands
  As a developer using the CleverAgents CLI
  I want the --format flag to be a global option on the root `agents` command
  So that I can set the output format once and have it apply to all subcommands
  Per the specification: "The framework supports six distinct output formats,
  selectable via the global --format flag."

  Background:
    Given the global format flag test runner is set up

  # -----------------------------------------------------------------------
  # Subtask 1 & 2: main_callback accepts --format and stores in ctx.obj
  # -----------------------------------------------------------------------

  Scenario: Global --format json flag is accepted by the root command
    When I invoke the CLI with global args "--format json version"
    Then the global format command should succeed
    And the global format output should be valid JSON

  Scenario: Global --format yaml flag is accepted by the root command
    When I invoke the CLI with global args "--format yaml version"
    Then the global format command should succeed
    And the global format output should be valid YAML

  Scenario: Global --format plain flag is accepted by the root command
    When I invoke the CLI with global args "--format plain version"
    Then the global format command should succeed
    And the global format output should contain plain text

  Scenario: Global --format rich flag is accepted by the root command
    When I invoke the CLI with global args "--format rich version"
    Then the global format command should succeed

  Scenario: Global --format table flag is accepted by the root command
    When I invoke the CLI with global args "--format table version"
    Then the global format command should succeed

  Scenario: Global --format color flag is accepted by the root command
    When I invoke the CLI with global args "--format color version"
    Then the global format command should succeed

  Scenario: Global -f shorthand flag is accepted by the root command
    When I invoke the CLI with global args "-f json version"
    Then the global format command should succeed
    And the global format output should be valid JSON

  # -----------------------------------------------------------------------
  # Subtask 3: version, info, diagnostics read format from global ctx.obj
  # -----------------------------------------------------------------------

  @tdd_issue @tdd_issue_4363 @tdd_expected_fail
  Scenario: version command reads format from global ctx.obj
    When I invoke the CLI with global args "--format json version"
    Then the global format command should succeed
    And the global format output should be valid JSON
    And the global format JSON output should contain key "version"

  Scenario: info command reads format from global ctx.obj
    When I invoke the CLI with global args "--format json info"
    Then the global format command should succeed
    And the global format output should be valid JSON

  Scenario: diagnostics command reads format from global ctx.obj
    When I invoke the CLI with global args "--format json diagnostics"
    Then the global format command should succeed
    And the global format output should be valid JSON

  Scenario: version command defaults to rich format when no --format given
    When I invoke the CLI with global args "version"
    Then the global format command should succeed

  Scenario: info command defaults to rich format when no --format given
    When I invoke the CLI with global args "info"
    Then the global format command should succeed

  Scenario: diagnostics command defaults to rich format when no --format given
    When I invoke the CLI with global args "diagnostics"
    Then the global format command should succeed

  # -----------------------------------------------------------------------
  # Subtask 4: ctx.obj["format"] is stored and accessible
  # -----------------------------------------------------------------------

  Scenario: ctx.obj stores the selected format value json
    When I call main_callback directly with format "json"
    Then the context object should have format "json"

  Scenario: ctx.obj stores yaml format value
    When I call main_callback directly with format "yaml"
    Then the context object should have format "yaml"

  Scenario: ctx.obj stores plain format value
    When I call main_callback directly with format "plain"
    Then the context object should have format "plain"

  Scenario: ctx.obj stores rich format value (default)
    When I call main_callback directly with format "rich"
    Then the context object should have format "rich"

  Scenario: ctx.obj stores table format value
    When I call main_callback directly with format "table"
    Then the context object should have format "table"

  Scenario: ctx.obj stores color format value
    When I call main_callback directly with format "color"
    Then the context object should have format "color"

  # -----------------------------------------------------------------------
  # All six formats work end-to-end with version command
  # -----------------------------------------------------------------------

  Scenario Outline: All six formats work with the version command via global flag
    When I invoke the CLI with global args "--format <format> version"
    Then the global format command should succeed

    Examples:
      | format |
      | json   |
      | yaml   |
      | plain  |
      | rich   |
      | table  |
      | color  |

  # -----------------------------------------------------------------------
  # All six formats work end-to-end with info command
  # -----------------------------------------------------------------------

  Scenario Outline: All six formats work with the info command via global flag
    When I invoke the CLI with global args "--format <format> info"
    Then the global format command should succeed

    Examples:
      | format |
      | json   |
      | yaml   |
      | plain  |
      | rich   |
      | table  |
      | color  |

  # -----------------------------------------------------------------------
  # All six formats work end-to-end with diagnostics command
  # -----------------------------------------------------------------------

  Scenario Outline: All six formats work with the diagnostics command via global flag
    When I invoke the CLI with global args "--format <format> diagnostics"
    Then the global format command should succeed

    Examples:
      | format |
      | json   |
      | yaml   |
      | plain  |
      | rich   |
      | table  |
      | color  |
