From 5d7e38a7860a1d546a367081eaaa81ed459a80dd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 20 Jan 2026 06:32:45 +0000 Subject: [PATCH] fix: avoid duplicate doctor config output --- src/commands/doctor-gateway-health.ts | 2 +- src/commands/doctor.ts | 11 ++++++++++- src/commands/health.ts | 8 +++++--- src/gateway/call.ts | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/commands/doctor-gateway-health.ts b/src/commands/doctor-gateway-health.ts index 138ac10ef..43840033d 100644 --- a/src/commands/doctor-gateway-health.ts +++ b/src/commands/doctor-gateway-health.ts @@ -16,7 +16,7 @@ export async function checkGatewayHealth(params: { typeof params.timeoutMs === "number" && params.timeoutMs > 0 ? params.timeoutMs : 10_000; let healthOk = false; try { - await healthCommand({ json: false, timeoutMs }, params.runtime); + await healthCommand({ json: false, timeoutMs, config: params.cfg }, params.runtime); healthOk = true; } catch (err) { const message = String(err); diff --git a/src/commands/doctor.ts b/src/commands/doctor.ts index 2519bcc0a..c2f9ad1ba 100644 --- a/src/commands/doctor.ts +++ b/src/commands/doctor.ts @@ -10,7 +10,7 @@ import { resolveHooksGmailModel, } from "../agents/model-selection.js"; import type { ClawdbotConfig } from "../config/config.js"; -import { CONFIG_PATH_CLAWDBOT, writeConfigFile } from "../config/config.js"; +import { CONFIG_PATH_CLAWDBOT, readConfigFileSnapshot, writeConfigFile } from "../config/config.js"; import { resolveGatewayService } from "../daemon/service.js"; import { buildGatewayConnectionDetails } from "../gateway/call.js"; import { resolveClawdbotPackageRoot } from "../infra/clawdbot-root.js"; @@ -269,5 +269,14 @@ export async function doctorCommand( } } + const finalSnapshot = await readConfigFileSnapshot(); + if (finalSnapshot.exists && !finalSnapshot.valid) { + runtime.error("Invalid config:"); + for (const issue of finalSnapshot.issues) { + const path = issue.path || ""; + runtime.error(`- ${path}: ${issue.message}`); + } + } + outro("Doctor complete."); } diff --git a/src/commands/health.ts b/src/commands/health.ts index 08d234374..526e69719 100644 --- a/src/commands/health.ts +++ b/src/commands/health.ts @@ -3,6 +3,7 @@ import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js"; import { getChannelPlugin, listChannelPlugins } from "../channels/plugins/index.js"; import type { ChannelAccountSnapshot } from "../channels/plugins/types.js"; import { withProgress } from "../cli/progress.js"; +import type { ClawdbotConfig } from "../config/config.js"; import { loadConfig } from "../config/config.js"; import { loadSessionStore, resolveStorePath } from "../config/sessions.js"; import { buildGatewayConnectionDetails, callGateway } from "../gateway/call.js"; @@ -501,9 +502,10 @@ export async function getHealthSnapshot(params?: { } export async function healthCommand( - opts: { json?: boolean; timeoutMs?: number; verbose?: boolean }, + opts: { json?: boolean; timeoutMs?: number; verbose?: boolean; config?: ClawdbotConfig }, runtime: RuntimeEnv, ) { + const cfg = opts.config ?? loadConfig(); // Always query the running gateway; do not open a direct Baileys socket here. const summary = await withProgress( { @@ -516,6 +518,7 @@ export async function healthCommand( method: "health", params: opts.verbose ? { probe: true } : undefined, timeoutMs: opts.timeoutMs, + config: cfg, }), ); // Gateway reachability defines success; channel issues are reported but not fatal here. @@ -526,13 +529,12 @@ export async function healthCommand( } else { const debugEnabled = isTruthyEnvValue(process.env.CLAWDBOT_DEBUG_HEALTH); if (opts.verbose) { - const details = buildGatewayConnectionDetails(); + const details = buildGatewayConnectionDetails({ config: cfg }); runtime.log(info("Gateway connection:")); for (const line of details.message.split("\n")) { runtime.log(` ${line}`); } } - const cfg = loadConfig(); const localAgents = resolveAgentOrder(cfg); const defaultAgentId = summary.defaultAgentId ?? localAgents.defaultAgentId; const agents = Array.isArray(summary.agents) ? summary.agents : []; diff --git a/src/gateway/call.ts b/src/gateway/call.ts index 3646a5086..c0557008e 100644 --- a/src/gateway/call.ts +++ b/src/gateway/call.ts @@ -22,6 +22,7 @@ export type CallGatewayOptions = { url?: string; token?: string; password?: string; + config?: ClawdbotConfig; method: string; params?: unknown; expectFinal?: boolean; @@ -109,7 +110,7 @@ export function buildGatewayConnectionDetails( export async function callGateway(opts: CallGatewayOptions): Promise { const timeoutMs = opts.timeoutMs ?? 10_000; - const config = loadConfig(); + const config = opts.config ?? loadConfig(); const isRemoteMode = config.gateway?.mode === "remote"; const remote = isRemoteMode ? config.gateway?.remote : undefined; const urlOverride =