Skip to content

cli: add JSON output and distinct exit codes to doctor #19

Closed

Description

@Ducksss

Summary

Add machine-readable payload-components doctor --json output and distinct exit codes so humans and CI can tell healthy projects, recoverable install drift, and unsupported project shapes apart.

Current Baseline

  • payload-components doctor exists and prints concise human-readable diagnostics.
  • The command checks supported project shape, required post-install scripts, recorded install state, missing files, missing dependencies, missing Payload fragments, stale manifest metadata, and partial install state.
  • The CLI currently sets exit code 1 for every unhealthy result; unsupported project shape and recoverable drift are not separated.
  • There is no --json flag yet.

Scope

  • Add payload-components doctor --json without changing the default human output.
  • Return exit 0 for healthy projects, 1 for recoverable drift or partial install state, and 2 for unsupported project shape or fatal diagnostic failure.
  • Include project summary, checked components, findings, severity, suggested next action, and state-file path where relevant in JSON output.
  • Document the exit code and JSON contract in the install or registry docs.
  • Keep doctor read-only.

Out Of Scope

  • Automatic repair or rollback.
  • New supported project shapes.
  • Private registry, entitlement, or token checks.
  • Replacing the existing human output.

Acceptance Criteria

  • Healthy supported projects exit 0 and report no findings.
  • Recoverable drift exits 1 with component name, issue type, details, and retry guidance.
  • Unsupported project shape exits 2 with a concise reason.
  • --json output is stable enough for CI and documented.
  • Human output remains concise and actionable.
  • Doctor does not create or modify .payload-components/state.json.

Test Plan

  • tests/int/payload-components-doctor-command.int.spec.ts covers healthy, drift, partial state, unsupported project, and --json output.
  • pnpm test:install.
  • pnpm lint.

Activity

  1. added
    enhancement
    on May 13, 2026
  2. Ducksss commented on Jun 12, 2026

    @Ducksss
    OwnerAuthor

    PR #57 implements payload-kit doctor for the Fumadocs baseline.

    Implemented behavior:

    • Human output by default.
    • --json machine-readable output.
    • Exit 0 for supported targets with no recoverable drift.
    • Exit 1 for partial installs, missing installed files, missing dependencies, stale state, direct shadcn copies, or missing Payload registration.
    • Exit 2 for unsupported project shape or fatal project detection/doctor failure.

    Validation: new tests/int/payload-kit-doctor.int.spec.ts plus pnpm test:release passed.

  3. changed the title [-]PK-22 Productize doctor exit codes and CI mode[/-] [+]PK-22 Productize payload-kit doctor exit codes and JSON output[/+] on Jun 15, 2026
  4. Ducksss commented on Jun 15, 2026

    @Ducksss
    OwnerAuthor

    Status reset on 2026-06-15: keeping this open. PR #57 contains prior doctor work, but it is still open and the current dev baseline keeps payload-kit doctor as a placeholder.

  5. changed the title [-]PK-22 Productize payload-kit doctor exit codes and JSON output[/-] [+]cli: add JSON output and distinct exit codes to doctor[/+] on Jun 18, 2026
  6. Ducksss commented on Aug 9, 2026

    @Ducksss
    OwnerAuthor

    Shipped. Verified against `dev` (63a195f) — every acceptance criterion is met:

    • Exit codes — `DoctorExitCode = 0 | 1 | 2` in `tools/payload-components/commands/doctor.ts`. `resolveExitCode` returns `2` when any error carries a project scope (`project`/`scripts`/`state`), `1` for remaining component-level errors, `0` when clean — so "your repo is wrong" is distinguishable from "one component drifted".
    • `--json` — parsed in `tools/payload-components/cli.ts` (allow-listed for `doctor` alongside `list`/`diff`/`templates`, rejected if repeated) and rendered at the end of `doctorCommand`. Default human output is unchanged: `renderText` walks the same findings in emission order.
    • Structured report — `DoctorReport` carries `components`, `findings`, `exitCode`, and `healthy`; every finding has a `scope` so consumers group without parsing prose.
    • Read-only — doctor still only reads state; nothing writes `.payload-components/state.json`.
    • Documented — `content/docs/cli.mdx` covers `doctor --json` (line 301) and has a dedicated `## Exit codes` section (line 367).
    • Tested — `tests/int/payload-components-doctor-command.int.spec.ts` and `tests/int/payload-components-doctor-orchestration.int.spec.ts`.

    Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions