Skip to content

Commit 143af6a

Browse files
committed
feat(cli): add --json output to doctor
`doctor` is one of the first commands users and agents run when something is off — remote bug reports (e.g. heygen-com#294, heygen-com#316, heygen-com#317) typically include a doctor screenshot, which is painful to parse programmatically. Every other CLI command that reports state already supports `--json` (info, lint, compositions, catalog, benchmark, validate, capture). This brings `doctor` in line with that convention so: - CI pipelines can gate on `hyperframes doctor --json` (exit 1 on failure) without scraping terminal output - AI agents consuming telemetry / diagnostic data get structured input - Bug report tooling can attach machine-readable doctor output Schema: { "ok": boolean, "platform": "darwin" | "linux" | "win32", "arch": "arm64" | "x64" | ..., "checks": [ { "name": "FFmpeg", "ok": true, "detail": "ffmpeg version 8.1 …" }, { "name": "Docker", "ok": false, "detail": "Not found", "hint": "https://docs.docker.com/get-docker/" } ], "_meta": { "version", "latestVersion", "updateAvailable" } } Uses the existing `withMeta()` helper so the `_meta` envelope matches other `--json` commands. Human output format is unchanged.
1 parent 0f4fcbe commit 143af6a

1 file changed

Lines changed: 54 additions & 16 deletions

File tree

‎packages/cli/src/commands/doctor.ts‎

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { defineCommand } from "citty";
22
import type { Example } from "./_examples.js";
33
import { execSync } from "node:child_process";
44

5-
export const examples: Example[] = [["Check system dependencies", "hyperframes doctor"]];
5+
export const examples: Example[] = [
6+
["Check system dependencies", "hyperframes doctor"],
7+
["Output as JSON for CI / agents", "hyperframes doctor --json"],
8+
];
69
import { freemem, platform } from "node:os";
710
import { c } from "../ui/colors.js";
811
import { findBrowser } from "../browser/manager.js";
912
import { findFFmpeg } from "../browser/ffmpeg.js";
1013
import { VERSION } from "../version.js";
11-
import { getUpdateMeta } from "../utils/updateCheck.js";
14+
import { getUpdateMeta, withMeta } from "../utils/updateCheck.js";
1215
import { getSystemMeta, getShmSizeMb, getFreeDiskMb, bytesToMb } from "../telemetry/system.js";
1316

1417
interface Check {
@@ -178,14 +181,19 @@ function checkEnvironment(): CheckResult {
178181
return { ok: true, detail: parts.join(" \u00B7 ") };
179182
}
180183

184+
interface CheckOutcome {
185+
name: string;
186+
ok: boolean;
187+
detail: string;
188+
hint?: string;
189+
}
190+
181191
export default defineCommand({
182192
meta: { name: "doctor", description: "Check system dependencies and environment" },
183-
args: {},
184-
async run() {
185-
console.log();
186-
console.log(c.bold("hyperframes doctor"));
187-
console.log();
188-
193+
args: {
194+
json: { type: "boolean", description: "Output as JSON", default: false },
195+
},
196+
async run({ args }) {
189197
const checks: Check[] = [
190198
{ name: "Version", run: checkVersion },
191199
{ name: "Node.js", run: checkNode },
@@ -208,19 +216,49 @@ export default defineCommand({
208216
{ name: "Docker running", run: checkDockerRunning },
209217
);
210218

211-
let allOk = true;
212-
219+
const outcomes: CheckOutcome[] = [];
213220
for (const check of checks) {
214221
const result = await check.run();
215-
const icon = result.ok ? c.success("\u2713") : c.error("\u2717");
216-
const name = check.name.padEnd(16);
222+
outcomes.push({
223+
name: check.name,
224+
ok: result.ok,
225+
detail: result.detail,
226+
...(result.hint ? { hint: result.hint } : {}),
227+
});
228+
}
229+
const allOk = outcomes.every((o) => o.ok);
230+
231+
if (args.json) {
232+
console.log(
233+
JSON.stringify(
234+
withMeta({
235+
ok: allOk,
236+
platform: process.platform,
237+
arch: process.arch,
238+
checks: outcomes,
239+
}),
240+
null,
241+
2,
242+
),
243+
);
244+
// Non-zero exit so `hyperframes doctor --json` is usable as a CI gate.
245+
if (!allOk) process.exitCode = 1;
246+
return;
247+
}
248+
249+
console.log();
250+
console.log(c.bold("hyperframes doctor"));
251+
console.log();
252+
253+
for (const outcome of outcomes) {
254+
const icon = outcome.ok ? c.success("\u2713") : c.error("\u2717");
255+
const name = outcome.name.padEnd(16);
217256
console.log(
218-
` ${icon} ${c.bold(name)} ${result.ok ? c.dim(result.detail) : c.error(result.detail)}`,
257+
` ${icon} ${c.bold(name)} ${outcome.ok ? c.dim(outcome.detail) : c.error(outcome.detail)}`,
219258
);
220-
if (!result.ok && result.hint) {
221-
console.log(` ${" ".repeat(19)}${c.accent(result.hint)}`);
259+
if (!outcome.ok && outcome.hint) {
260+
console.log(` ${" ".repeat(19)}${c.accent(outcome.hint)}`);
222261
}
223-
if (!result.ok) allOk = false;
224262
}
225263

226264
console.log();

0 commit comments

Comments
 (0)