diff --git a/src/cleveragents/cli/commands/plan.py b/src/cleveragents/cli/commands/plan.py index 44fe96707..d057ab8f9 100644 --- a/src/cleveragents/cli/commands/plan.py +++ b/src/cleveragents/cli/commands/plan.py @@ -307,6 +307,54 @@ def _plan_spec_dict(plan: Any) -> dict[str, object]: return {"plan": str(plan)} + +def _status_output_dict(plan: Any) -> dict[str, object]: + """Build the spec-required JSON envelope for a single-plan status output. + + Returns the structured JSON envelope for ``agents plan status PLAN_ID`` + as defined in the specification §agents plan status. + + Args: + plan: The plan object (either a v3 ``Plan`` or a legacy plan). + + Returns: + A JSON-serialisable dict matching the spec-required envelope. + """ + return { + "command": "plan status", + "status": "ok", + "exit_code": 0, + "data": _plan_spec_dict(plan), + "timing": {}, + "messages": [{"level": "ok", "text": "Plan status retrieved"}], + } + + +def _status_list_output(plans: list[Any]) -> dict[str, object]: + """Build the spec-required JSON envelope for a list-all-plans status output. + + Returns the structured JSON envelope for ``agents plan status`` (no + ``plan_id`` argument) as defined in the specification §agents plan status. + + Args: + plans: The list of plan objects to include in the data payload. + + Returns: + A JSON-serialisable dict matching the spec-required envelope. + """ + return { + "command": "plan status", + "status": "ok", + "exit_code": 0, + "data": [_plan_spec_dict(p) for p in plans], + "timing": {}, + "messages": [ + {"level": "ok", "text": f"{len(plans)} plan(s) retrieved"} + ], + } + + + def _execute_output_dict( plan: Any, started_at: datetime | None = None, @@ -2436,8 +2484,8 @@ def plan_status( # Non-rich formats if fmt != OutputFormat.RICH.value: - data = [_plan_spec_dict(p) for p in plans] - console.print(format_output(data, fmt)) + envelope = _status_list_output(plans) + console.print(format_output(envelope, fmt)) return # Show summary table @@ -2480,8 +2528,8 @@ def plan_status( plan = service.get_plan(plan_id) if fmt != OutputFormat.RICH.value: - data = _plan_spec_dict(plan) - console.print(format_output(data, fmt)) + envelope = _status_output_dict(plan) + console.print(format_output(envelope, fmt)) return _print_lifecycle_plan(plan, title="Plan Status")