UAT: agents plan apply --format json output doesn't match spec — missing artifacts, changes, validation, sandbox_cleanup, lifecycle fields #3442

Open
opened 2026-04-05 16:51:39 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: bugfix/m3-plan-apply-json-output-spec
  • Commit Message: fix(cli): build spec-required apply output dict with artifacts, changes, validation, lifecycle fields in plan apply
  • Milestone: v3.2.0
  • Parent Epic: #933

Background and Context

The agents plan apply --format json command outputs a raw plan state dict (phase, processing_state, project_links, etc.) but the spec requires a completely different structure focused on applied artifacts, change statistics, validation results, and lifecycle summary.

Expected Behavior (from spec):

{
  "command": "agents plan apply 01HXM8C2ZK4Q7C2B3F2R4VYV6J",
  "status": "ok",
  "exit_code": 0,
  "data": {
    "plan_id": "01HXM8C2ZK4Q7C2B3F2R4VYV6J",
    "artifacts": 6,
    "changes": {
      "insertions": 42,
      "deletions": 9
    },
    "project": "local/api-service",
    "applied_at": "2026-02-08T13:04:00Z",
    "validation": {
      "tests": { "status": "passed", "passed": 24, "total": 24 },
      "lint": { "status": "passed", "warnings": 0 },
      "type_check": { "status": "passed", "errors": 0 },
      "duration_s": 12.4
    },
    "sandbox_cleanup": {
      "worktree": "removed",
      "branch": "merged to main",
      "checkpoint": "archived"
    },
    "lifecycle": {
      "phase": "apply",
      "state": "applied",
      "total_duration": "00:06:14",
      "total_cost": "$0.0847",
      "decisions_made": 8,
      "child_plans": 2
    }
  },
  "timing": { "duration_ms": 374000 },
  "messages": [{ "level": "ok", "text": "Plan applied successfully" }]
}

Actual Behavior:
agents plan apply --format json outputs the raw plan domain model dict via _plan_spec_dict():

{
  "plan_id": "01HXM8C2ZK4Q7C2B3F2R4VYV6J",
  "namespaced_name": "local/my-plan",
  "phase": "apply",
  "processing_state": "applied",
  "state": "applied",
  "project_links": [...],
  ...
}

The output is missing: artifacts, changes (insertions/deletions), validation, sandbox_cleanup, lifecycle (total_duration, total_cost, decisions_made, child_plans) fields. The output also lacks the spec-required envelope (command, status, exit_code, data, timing, messages).

Code Location:

  • src/cleveragents/cli/commands/plan.py, line 2054–2056 — lifecycle_apply_plan() — calls format_output(_plan_spec_dict(plan), fmt) which returns wrong structure
  • src/cleveragents/cli/commands/plan.py, line 853 — _lifecycle_apply_with_id() — same issue
  • src/cleveragents/cli/commands/plan.py, line 187 — _plan_spec_dict() — returns plan domain model dict, not apply-specific output

Steps to Reproduce:

  1. Create and execute a plan
  2. Apply: agents plan apply <PLAN_ID> --yes --format json
  3. Observe: raw plan state dict without artifacts/changes/validation fields

Subtasks

  • Create _apply_output_dict(plan) function that builds the spec-required apply output structure
  • Add artifacts count, changes (insertions/deletions), project, applied_at fields
  • Add validation results (tests, lint, type_check) from plan's validation_summary
  • Add sandbox_cleanup and lifecycle summary fields
  • Wrap in spec-required JSON envelope (command, status, exit_code, data, timing, messages)
  • Update lifecycle_apply_plan() and _lifecycle_apply_with_id() to use new output function
  • Add BDD unit tests for plan apply --format json output structure
  • Verify nox -e typecheck passes
  • Verify coverage >= 97%

Definition of Done

  • agents plan apply --format json outputs the spec-required structure with artifacts, changes, validation, lifecycle fields
  • 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 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
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Branch**: `bugfix/m3-plan-apply-json-output-spec` - **Commit Message**: `fix(cli): build spec-required apply output dict with artifacts, changes, validation, lifecycle fields in plan apply` - **Milestone**: v3.2.0 - **Parent Epic**: #933 ## Background and Context The `agents plan apply --format json` command outputs a raw plan state dict (phase, processing_state, project_links, etc.) but the spec requires a completely different structure focused on applied artifacts, change statistics, validation results, and lifecycle summary. **Expected Behavior (from spec):** ```json { "command": "agents plan apply 01HXM8C2ZK4Q7C2B3F2R4VYV6J", "status": "ok", "exit_code": 0, "data": { "plan_id": "01HXM8C2ZK4Q7C2B3F2R4VYV6J", "artifacts": 6, "changes": { "insertions": 42, "deletions": 9 }, "project": "local/api-service", "applied_at": "2026-02-08T13:04:00Z", "validation": { "tests": { "status": "passed", "passed": 24, "total": 24 }, "lint": { "status": "passed", "warnings": 0 }, "type_check": { "status": "passed", "errors": 0 }, "duration_s": 12.4 }, "sandbox_cleanup": { "worktree": "removed", "branch": "merged to main", "checkpoint": "archived" }, "lifecycle": { "phase": "apply", "state": "applied", "total_duration": "00:06:14", "total_cost": "$0.0847", "decisions_made": 8, "child_plans": 2 } }, "timing": { "duration_ms": 374000 }, "messages": [{ "level": "ok", "text": "Plan applied successfully" }] } ``` **Actual Behavior:** `agents plan apply --format json` outputs the raw plan domain model dict via `_plan_spec_dict()`: ```json { "plan_id": "01HXM8C2ZK4Q7C2B3F2R4VYV6J", "namespaced_name": "local/my-plan", "phase": "apply", "processing_state": "applied", "state": "applied", "project_links": [...], ... } ``` The output is missing: `artifacts`, `changes` (insertions/deletions), `validation`, `sandbox_cleanup`, `lifecycle` (total_duration, total_cost, decisions_made, child_plans) fields. The output also lacks the spec-required envelope (`command`, `status`, `exit_code`, `data`, `timing`, `messages`). **Code Location:** - `src/cleveragents/cli/commands/plan.py`, line 2054–2056 — `lifecycle_apply_plan()` — calls `format_output(_plan_spec_dict(plan), fmt)` which returns wrong structure - `src/cleveragents/cli/commands/plan.py`, line 853 — `_lifecycle_apply_with_id()` — same issue - `src/cleveragents/cli/commands/plan.py`, line 187 — `_plan_spec_dict()` — returns plan domain model dict, not apply-specific output **Steps to Reproduce:** 1. Create and execute a plan 2. Apply: `agents plan apply <PLAN_ID> --yes --format json` 3. Observe: raw plan state dict without artifacts/changes/validation fields ## Subtasks - [ ] Create `_apply_output_dict(plan)` function that builds the spec-required apply output structure - [ ] Add artifacts count, changes (insertions/deletions), project, applied_at fields - [ ] Add validation results (tests, lint, type_check) from plan's validation_summary - [ ] Add sandbox_cleanup and lifecycle summary fields - [ ] Wrap in spec-required JSON envelope (command, status, exit_code, data, timing, messages) - [ ] Update `lifecycle_apply_plan()` and `_lifecycle_apply_with_id()` to use new output function - [ ] Add BDD unit tests for `plan apply --format json` output structure - [ ] Verify `nox -e typecheck` passes - [ ] Verify coverage >= 97% ## Definition of Done - [ ] `agents plan apply --format json` outputs the spec-required structure with artifacts, changes, validation, lifecycle fields - [ ] 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 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 - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.2.0 milestone 2026-04-05 16:51:45 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Critical — Spec-required JSON output structure is completely wrong; breaks all programmatic consumers of plan apply
  • Milestone: v3.2.0 (already assigned)
  • Story Points: 3 (M) — Requires new output builder function + envelope wrapping + tests, but scope is well-defined to a single command
  • MoSCoW: Must Have — The spec mandates this output structure (§CLI Output Format). The v3.2.0 acceptance criterion "Output validation is flexible — checks structural components" cannot pass without correct output structure.
  • Parent Epic: #933 (A2A Protocol Compliance)

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Critical — Spec-required JSON output structure is completely wrong; breaks all programmatic consumers of `plan apply` - **Milestone**: v3.2.0 (already assigned) - **Story Points**: 3 (M) — Requires new output builder function + envelope wrapping + tests, but scope is well-defined to a single command - **MoSCoW**: Must Have — The spec mandates this output structure (§CLI Output Format). The v3.2.0 acceptance criterion "Output validation is flexible — checks structural components" cannot pass without correct output structure. - **Parent Epic**: #933 (A2A Protocol Compliance) --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
freemo removed this from the v3.2.0 milestone 2026-04-06 20:50:09 +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.

Reference
cleveragents/cleveragents-core#3442
No description provided.