Skip to content

feat(doctor): add --json flag for structured machine-readable output#620

Merged
esengine merged 2 commits into
esengine:mainfrom
dimasd-angga:fix/issue-15-add-json-flag-to-reasonix-doctor
May 11, 2026
Merged

feat(doctor): add --json flag for structured machine-readable output#620
esengine merged 2 commits into
esengine:mainfrom
dimasd-angga:fix/issue-15-add-json-flag-to-reasonix-doctor

Conversation

@dimasd-angga

Copy link
Copy Markdown

Summary

Adds a --json flag to reasonix doctor that emits a single structured JSON document with version, summary, and checks[], intended for CI pipelines and tooling that need to parse health-check status without scraping human-formatted output. Default (flag absent) text output and exit-code semantics are unchanged: any fail check still exits 1, otherwise 0.

Changes

  • src/cli/commands/doctor.ts: extend DoctorCheck with a stable id field on every check (api-key, config, api-reach, tokenizer, sessions, hooks, semantic, project); add DoctorOptions and accept it on doctorCommand; add formatDoctorJson(checks, version) helper that builds { version, summary: { ok, warn, fail }, checks: [{ id, status, message }] }; when --json is set, suppress the header, per-check lines, and colored summary so stdout stays a single jq-parseable document, while still calling process.exit(1) on any fail.
  • src/cli/index.ts: register .option("--json", t("ui.jsonHint")) on the doctor command and forward { json: !!opts.json } into doctorCommand.
  • tests/doctor-json.test.ts: new vitest covering formatDoctorJson shape (version, summary counts, per-check {id,status,message}) and doctorCommand({ json: true }) end-to-end — asserts a single JSON document is written to stdout, no header/summary leaks, and exit code is 1 when any check fails / 0 otherwise.

Testing

npm test -- tests/doctor-json.test.ts — passes locally. The test stubs runDoctorChecks so no network or filesystem state is required, and captures console.log plus a mocked process.exit to verify both the payload and the exit-code branch.

Notes

The id values are derived from the existing labels and are now part of the exported DoctorCheck type. There are no in-repo consumers of DoctorCheck outside doctor.ts, so this is additive for external callers — downstream tools should key off id rather than the human-formatted label, which remains a presentation detail.

Closes #15

Enables programmatic consumption of doctor results by CI pipelines and tooling that need to parse health-check status without scraping human-formatted output. Each check now carries a stable `id` so downstream consumers can key off specific checks rather than brittle label strings, while exit-code semantics and the default text output remain unchanged.
@esengine

Copy link
Copy Markdown
Owner

Looks great — implementation matches the spec cleanly, tests are in the right shape, no new deps. Just a couple of lint nits blocking CI:

  • tests/doctor-json.test.ts lines 64 / 74 / 76 / 78 use delete process.env.X — biome's noDelete rule rejects it. Easiest fix is vi.stubEnv("HOME", tmpHome) in beforeEach (vitest auto-restores) and drop the manual save/restore dance entirely.
  • One formatter violation — npm run format will fix it.

Once CI's green, happy to merge. Thanks for picking this up.

@dimasd-angga

Copy link
Copy Markdown
Author

i will fix the CI, just a moment

Vitest's `vi.stubEnv` and `vi.unstubAllEnvs` provide automatic restoration of environment variables between tests, eliminating the manual save/restore boilerplate that's easy to get wrong. Collapsing the multi-line import also keeps the test file consistent with single-line import style elsewhere.
@dimasd-angga

Copy link
Copy Markdown
Author

Pushed an update addressing the follow-up.

  • Replace delete process.env.X with vi.stubEnv in doctor-json test
  • Run formatter to fix biome formatting violation

@esengine

Copy link
Copy Markdown
Owner

Clean implementation — id taxonomy lines up with the actual checks, the helper is properly factored, tests cover both the shape and the exit-code branch. CI green. Merging.

Thanks for the contribution!

@esengine esengine merged commit faf8932 into esengine:main May 11, 2026
3 checks passed
ChasLui pushed a commit to ChasLui/DeepSeek-Reasonix that referenced this pull request May 23, 2026
…sengine#620)

* feat(doctor): add --json flag for structured machine-readable output

Enables programmatic consumption of doctor results by CI pipelines and tooling that need to parse health-check status without scraping human-formatted output. Each check now carries a stable `id` so downstream consumers can key off specific checks rather than brittle label strings, while exit-code semantics and the default text output remain unchanged.

* test(doctor): use vi.stubEnv for env isolation in --json tests

Vitest's `vi.stubEnv` and `vi.unstubAllEnvs` provide automatic restoration of environment variables between tests, eliminating the manual save/restore boilerplate that's easy to get wrong. Collapsing the multi-line import also keeps the test file consistent with single-line import style elsewhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --json flag to reasonix doctor

2 participants