Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Silence doctor progress in JSON mode (#851)
Kushalb30f0aa7cb1b
diff --git a/src/commands/doctor.ts b/src/commands/doctor.tsindex 6564444087..a695a80f8f 100644--- a/src/commands/doctor.ts+++ b/src/commands/doctor.ts@@ -4655,11 +4655,10 @@ export async function buildChecks(const checks: Check[] = [];let autoFixReport: AutoFixReport | null = null;- // Progress reporter. `--json` is doctor's own JSON output (list of checks);- // progress events stay on stderr regardless, gated by the global --quiet /- // --progress-json flags. On a 52K-page brain the DB checks can take minutes,- // and without a heartbeat agents can't tell doctor from a hang.- const progress = createProgress(cliOptsToProgressOptions(getCliOptions()));+ // Progress reporter. `--json` is doctor's machine-readable output, so plain+ // progress must not leak to stderr unless the caller explicitly asks for+ // structured progress with --progress-json.+ const progress = createProgress(doctorProgressOptions(jsonOutput));// --- Filesystem checks (always run, no DB needed) ---@@ -7688,6 +7687,14 @@ export async function runDoctor(// Helpers// ---------------------------------------------------------------------------+export function doctorProgressOptions(jsonOutput: boolean) {+ const cliOpts = getCliOptions();+ if (jsonOutput && !cliOpts.quiet && !cliOpts.progressJson) {+ return { mode: 'quiet' as const };+ }+ return cliOptsToProgressOptions(cliOpts);+}+/** Print the auto-fix report in human-readable form. JSON output goes through* outputResults alongside the check list; this is the pretty-print path. */function printAutoFixReport(report: AutoFixReport, dryRun: boolean, jsonOutput: boolean): void {diff --git a/test/doctor.test.ts b/test/doctor.test.tsindex a51aab48a8..c9adc3e9ea 100644--- a/test/doctor.test.ts+++ b/test/doctor.test.ts@@ -137,6 +137,25 @@ describe('doctor command', () => {expect(runDoctor.length).toBeLessThanOrEqual(3);});+ test('doctor --json suppresses implicit progress unless --progress-json is explicit', async () => {+ const { _resetCliOptionsForTest, setCliOptions, DEFAULT_CLI_OPTIONS } = await import('../src/core/cli-options.ts');+ const { doctorProgressOptions } = await import('../src/commands/doctor.ts');++ try {+ _resetCliOptionsForTest();+ expect(doctorProgressOptions(true).mode).toBe('quiet');+ expect(doctorProgressOptions(false).mode).toBe('auto');++ setCliOptions({ ...DEFAULT_CLI_OPTIONS, progressJson: true });+ expect(doctorProgressOptions(true).mode).toBe('json');++ setCliOptions({ ...DEFAULT_CLI_OPTIONS, quiet: true, progressJson: true });+ expect(doctorProgressOptions(true).mode).toBe('quiet');+ } finally {+ _resetCliOptionsForTest();+ }+ });+// Bug 7 — --fast should differentiate "no config anywhere" from "user// chose --fast with GBRAIN_DATABASE_URL / config-file URL present".test('getDbUrlSource reflects GBRAIN_DATABASE_URL env var', async () => {