bug(cli): JSON/YAML envelope 'command' field is always empty string in CLI command output #9356

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

Metadata

  • Commit Message: fix(cli): populate 'command' field in JSON/YAML envelope for all CLI commands
  • Branch: fix/json-yaml-envelope-command-field

Background and Context

The Output Rendering Framework specification (§Output Rendering Framework, JSON envelope structure) requires that the command field in the JSON/YAML output envelope contains the CLI command string that produced the output (e.g., "agents action list", "agents plan status"). This field is used by programmatic consumers to identify which command produced the output.

The format_output() helper in src/cleveragents/cli/formatting.py accepts an optional command: str = "" parameter that populates the envelope's command field. However, all CLI command handlers (e.g., action.py, plan.py, skill.py, tool.py, resource.py, etc.) call format_output(data, fmt) without passing the command= argument, resulting in an empty string in the envelope.

This was discovered during UAT testing of the Output Rendering Framework (feature area: JSON envelope structure).

Current Behavior

When any CLI command is run with --format json or --format yaml, the command field in the envelope is always an empty string "":

Reproduction:

agents action list --format json

Output:

{
  "command": "",    BUG: should be "agents action list"
  "status": "ok",
  "exit_code": 0,
  "data": [...],
  "timing": {"duration_ms": 0},
  "messages": [{"level": "ok", "text": "ok"}]
}

Root cause — all CLI command handlers call format_output without the command= argument:

# src/cleveragents/cli/commands/action.py (and all other command files)
console.print(format_output(data, fmt))  # ← missing command= argument

The format_output() signature supports it:

def format_output(data, format_type, *, command: str = "", ...):

Expected Behavior

The command field in the JSON/YAML envelope should contain the CLI command string that produced the output. For example:

  • agents action list --format json"command": "agents action list"
  • agents plan status --format json"command": "agents plan status"
  • agents skill list --format json"command": "agents skill list"

The messages[0].text field should also reflect the command name (currently it shows "ok" instead of "agents action list completed").

Acceptance Criteria

  • agents action list --format json produces "command": "agents action list" in the envelope
  • agents plan list --format json produces "command": "agents plan list" in the envelope
  • agents skill list --format json produces "command": "agents skill list" in the envelope
  • agents tool list --format json produces "command": "agents tool list" in the envelope
  • The messages[0].text field reflects the command name (e.g., "agents action list completed")
  • YAML format also populates the command field correctly
  • All existing BDD scenarios in features/cli_json_envelope.feature and features/cli_output_formats.feature continue to pass

Supporting Information

  • Affected files: All CLI command handlers that call format_output():
    • src/cleveragents/cli/commands/action.py
    • src/cleveragents/cli/commands/plan.py
    • src/cleveragents/cli/commands/skill.py
    • src/cleveragents/cli/commands/tool.py
    • src/cleveragents/cli/commands/resource.py
    • src/cleveragents/cli/commands/session.py
    • src/cleveragents/cli/commands/validation.py
    • src/cleveragents/cli/commands/project_context.py
    • src/cleveragents/cli/commands/server.py
    • src/cleveragents/cli/renderers.py
  • Root cause: All callers of format_output() omit the command= keyword argument
  • Related spec: Output Rendering Framework, JSON envelope command field (§Output Rendering Framework)
  • Feature files: features/cli_json_envelope.feature, features/cli_output_formats.feature
  • Discovered by: UAT Test Pool — Output Rendering Framework test run (2026-04-14)

Subtasks

  • Update all CLI command handlers to pass command="agents <subcommand> <action>" to format_output()
  • Update src/cleveragents/cli/commands/action.py — pass command= for all format_output() calls
  • Update src/cleveragents/cli/commands/plan.py — pass command= for all format_output() calls
  • Update src/cleveragents/cli/commands/skill.py — pass command= for all format_output() calls
  • Update src/cleveragents/cli/commands/tool.py — pass command= for all format_output() calls
  • Update src/cleveragents/cli/commands/resource.py — pass command= for all format_output() calls
  • Update remaining command files (session.py, validation.py, project_context.py, server.py, renderers.py)
  • Add/update BDD scenario in features/cli_json_envelope.feature to assert non-empty command field
  • Run nox -s unit_tests -- features/cli_json_envelope.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): populate 'command' field in JSON/YAML envelope for all CLI commands` - **Branch**: `fix/json-yaml-envelope-command-field` --- ## Background and Context The Output Rendering Framework specification (§Output Rendering Framework, JSON envelope structure) requires that the `command` field in the JSON/YAML output envelope contains the CLI command string that produced the output (e.g., `"agents action list"`, `"agents plan status"`). This field is used by programmatic consumers to identify which command produced the output. The `format_output()` helper in `src/cleveragents/cli/formatting.py` accepts an optional `command: str = ""` parameter that populates the envelope's `command` field. However, all CLI command handlers (e.g., `action.py`, `plan.py`, `skill.py`, `tool.py`, `resource.py`, etc.) call `format_output(data, fmt)` without passing the `command=` argument, resulting in an empty string in the envelope. This was discovered during UAT testing of the Output Rendering Framework (feature area: JSON envelope structure). ## Current Behavior When any CLI command is run with `--format json` or `--format yaml`, the `command` field in the envelope is always an empty string `""`: **Reproduction:** ```bash agents action list --format json ``` **Output:** ```json { "command": "", ← BUG: should be "agents action list" "status": "ok", "exit_code": 0, "data": [...], "timing": {"duration_ms": 0}, "messages": [{"level": "ok", "text": "ok"}] } ``` **Root cause** — all CLI command handlers call `format_output` without the `command=` argument: ```python # src/cleveragents/cli/commands/action.py (and all other command files) console.print(format_output(data, fmt)) # ← missing command= argument ``` The `format_output()` signature supports it: ```python def format_output(data, format_type, *, command: str = "", ...): ``` ## Expected Behavior The `command` field in the JSON/YAML envelope should contain the CLI command string that produced the output. For example: - `agents action list --format json` → `"command": "agents action list"` - `agents plan status --format json` → `"command": "agents plan status"` - `agents skill list --format json` → `"command": "agents skill list"` The `messages[0].text` field should also reflect the command name (currently it shows `"ok"` instead of `"agents action list completed"`). ## Acceptance Criteria - [ ] `agents action list --format json` produces `"command": "agents action list"` in the envelope - [ ] `agents plan list --format json` produces `"command": "agents plan list"` in the envelope - [ ] `agents skill list --format json` produces `"command": "agents skill list"` in the envelope - [ ] `agents tool list --format json` produces `"command": "agents tool list"` in the envelope - [ ] The `messages[0].text` field reflects the command name (e.g., `"agents action list completed"`) - [ ] YAML format also populates the `command` field correctly - [ ] All existing BDD scenarios in `features/cli_json_envelope.feature` and `features/cli_output_formats.feature` continue to pass ## Supporting Information - **Affected files:** All CLI command handlers that call `format_output()`: - `src/cleveragents/cli/commands/action.py` - `src/cleveragents/cli/commands/plan.py` - `src/cleveragents/cli/commands/skill.py` - `src/cleveragents/cli/commands/tool.py` - `src/cleveragents/cli/commands/resource.py` - `src/cleveragents/cli/commands/session.py` - `src/cleveragents/cli/commands/validation.py` - `src/cleveragents/cli/commands/project_context.py` - `src/cleveragents/cli/commands/server.py` - `src/cleveragents/cli/renderers.py` - **Root cause:** All callers of `format_output()` omit the `command=` keyword argument - **Related spec:** Output Rendering Framework, JSON envelope `command` field (§Output Rendering Framework) - **Feature files:** `features/cli_json_envelope.feature`, `features/cli_output_formats.feature` - **Discovered by:** UAT Test Pool — Output Rendering Framework test run (2026-04-14) ## Subtasks - [ ] Update all CLI command handlers to pass `command="agents <subcommand> <action>"` to `format_output()` - [ ] Update `src/cleveragents/cli/commands/action.py` — pass `command=` for all `format_output()` calls - [ ] Update `src/cleveragents/cli/commands/plan.py` — pass `command=` for all `format_output()` calls - [ ] Update `src/cleveragents/cli/commands/skill.py` — pass `command=` for all `format_output()` calls - [ ] Update `src/cleveragents/cli/commands/tool.py` — pass `command=` for all `format_output()` calls - [ ] Update `src/cleveragents/cli/commands/resource.py` — pass `command=` for all `format_output()` calls - [ ] Update remaining command files (`session.py`, `validation.py`, `project_context.py`, `server.py`, `renderers.py`) - [ ] Add/update BDD scenario in `features/cli_json_envelope.feature` to assert non-empty `command` field - [ ] Run `nox -s unit_tests -- features/cli_json_envelope.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:12 +00:00
Author
Owner

Triage: Verified [AUTO-OWNR-1]

Valid bug: The JSON/YAML output envelope's command field is always an empty string because all CLI command handlers call format_output(data, fmt) without passing the command= argument. This affects all CLI commands that produce JSON/YAML output, breaking the spec requirement for the command field to identify which command produced the output.

Assigning to v3.2.0 as this affects all CLI commands. Priority Medium — machine-readable output is broken for the command field.

MoSCoW: Should Have — the command field is important for programmatic consumers to identify the source command, but the data itself is still correct.


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

✅ **Triage: Verified** [AUTO-OWNR-1] Valid bug: The JSON/YAML output envelope's `command` field is always an empty string because all CLI command handlers call `format_output(data, fmt)` without passing the `command=` argument. This affects all CLI commands that produce JSON/YAML output, breaking the spec requirement for the `command` field to identify which command produced the output. Assigning to **v3.2.0** as this affects all CLI commands. Priority **Medium** — machine-readable output is broken for the `command` field. MoSCoW: **Should Have** — the `command` field is important for programmatic consumers to identify the source command, but the data itself is still correct. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
HAL9000 removed this from the v3.2.0 milestone 2026-04-14 15:25:00 +00:00
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#9356
No description provided.