Skip to content

Commit 688777c

Browse files
committed
docs: document doctor config preflight checks
1 parent d2ff1c3 commit 688777c

6 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/commands/doctor-config-audit-scrub.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor repair for redacting historical config audit log argv records. */
12
import fs from "node:fs/promises";
23
import os from "node:os";
34
import { note } from "../../packages/terminal-core/src/note.js";
@@ -9,6 +10,12 @@ function formatEntryCount(count: number): string {
910
return `${count} ${count === 1 ? "entry" : "entries"}`;
1011
}
1112

13+
/**
14+
* Scrubs pre-redactor config audit records or previews the number of affected entries.
15+
*
16+
* The rewrite aborts if new records are appended while doctor is processing the JSONL file, so
17+
* live gateways do not lose audit entries during cleanup.
18+
*/
1219
export async function maybeScrubConfigAuditLog(params: {
1320
shouldRepair: boolean;
1421
env?: NodeJS.ProcessEnv;

src/commands/doctor-config-flow.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Main doctor config flow: preflight, migrations, previews, repairs, and final write decision. */
12
import path from "node:path";
23
import { note } from "../../packages/terminal-core/src/note.js";
34
import { formatCliCommand } from "../cli/command-format.js";
@@ -103,6 +104,12 @@ async function refreshGatewayAuthStateAfterAuthProfileRepair(): Promise<void> {
103104
}
104105
}
105106

107+
/**
108+
* Loads config, runs doctor migrations/repairs, and returns the config write plan.
109+
*
110+
* This is the config-side orchestration boundary for doctor; it keeps preview notes, repair
111+
* mutations, gateway auth refreshes, and final write confirmation in one ordered flow.
112+
*/
106113
export async function loadAndMaybeMigrateDoctorConfig(params: {
107114
options: DoctorOptions;
108115
confirm: (p: { message: string; initialValue: boolean }) => Promise<boolean>;

src/commands/doctor-config-preflight.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Config preflight for doctor: legacy config/state migration, recovery, and snapshot loading. */
12
import fs from "node:fs/promises";
23
import path from "node:path";
34
import { note } from "../../packages/terminal-core/src/note.js";
@@ -92,6 +93,7 @@ function addDoctorLegacyIssues(
9293
return { ...snapshot, legacyIssues };
9394
}
9495

96+
/** Returns true during updater-managed config rewrites where plugin validation may be stale. */
9597
export function shouldSkipPluginValidationForDoctorConfigPreflight(
9698
env: NodeJS.ProcessEnv = process.env,
9799
): boolean {
@@ -107,6 +109,12 @@ function noteStateMigrationResult(result: { changes: string[]; warnings: string[
107109
}
108110
}
109111

112+
/**
113+
* Runs early doctor config checks before the main config repair flow.
114+
*
115+
* It may migrate legacy state/config paths, recover corrupt target config when requested, and
116+
* returns the best-effort config snapshot used by later doctor checks.
117+
*/
110118
export async function runDoctorConfigPreflight(
111119
options: {
112120
migrateState?: boolean;

src/commands/doctor-cron.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/** Re-exports cron doctor checks from the grouped doctor/cron implementation. */
12
export * from "./doctor/cron/index.js";

src/commands/doctor-device-pairing.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor diagnostics for pending, paired, and locally cached device auth state. */
12
import path from "node:path";
23
import { normalizeUniqueSingleOrTrimmedStringList } from "@openclaw/normalization-core/string-normalization";
34
import { note } from "../../packages/terminal-core/src/note.js";
@@ -466,6 +467,7 @@ function collectLocalDeviceAuthIssues(snapshot: DoctorPairingSnapshot): string[]
466467
role,
467468
]);
468469
const gatewayIssuedAtMs = pairedToken.rotatedAtMs ?? pairedToken.createdAtMs;
470+
// Local device auth survives gateway restarts; compare timestamps to catch stale cached tokens.
469471
if (entry.updatedAtMs < gatewayIssuedAtMs) {
470472
lines.push(
471473
`- Local cached ${role} device token for ${deviceLabel} predates the gateway rotation. This is a stale device-token pattern and can fail with device token mismatch. Reconnect with shared gateway auth to refresh it, or rotate again with ${rotateCommand}.`,
@@ -488,6 +490,12 @@ function formatPairingStoreReadIssue(error: JsonFileReadError): string {
488490
return `- Device pairing store ${error.filePath} ${problem}. OpenClaw refused to treat it as empty to avoid overwriting approved pairings. Fix the JSON or file permissions, or move it aside and re-pair devices.`;
489491
}
490492

493+
/**
494+
* Emits device pairing repair guidance from live gateway state or local pairing files.
495+
*
496+
* Remote gateways only report through the gateway API; local gateways can fall back to on-disk
497+
* pairing state when the gateway is down.
498+
*/
491499
export async function noteDevicePairingHealth(params: {
492500
cfg: OpenClawConfig;
493501
healthOk: boolean;

src/commands/doctor-disk-space.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/** Doctor contribution for low disk space around the OpenClaw state directory. */
12
import os from "node:os";
3+
import { note } from "../../packages/terminal-core/src/note.js";
24
import type { OpenClawConfig } from "../config/config.js";
35
import { resolveStateDir } from "../config/paths.js";
4-
import { resolveRequiredHomeDir } from "../infra/home-dir.js";
56
import { tryReadDiskSpace } from "../infra/disk-space.js";
6-
import { note } from "../../packages/terminal-core/src/note.js";
7+
import { resolveRequiredHomeDir } from "../infra/home-dir.js";
78
import { shortenHomePath } from "../utils.js";
89

910
// 100 MB — below this, config writes and session transcripts are likely to

0 commit comments

Comments
 (0)