Skip to content

Commit c0b3c8c

Browse files
committed
docs: document doctor session checks
1 parent 0913b69 commit c0b3c8c

6 files changed

Lines changed: 23 additions & 5 deletions

src/commands/doctor-session-locks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor diagnostics and cleanup for stale session write lock files. */
12
import { note } from "../../packages/terminal-core/src/note.js";
23
import { resolveAgentSessionDirs } from "../agents/session-dirs.js";
34
import {
@@ -39,6 +40,7 @@ function formatLockLine(lock: SessionLockInspection): string {
3940
return `- ${shortenHomePath(lock.lockPath)} ${pidStatus} ${ageStatus} ${staleStatus}${removedStatus}`;
4041
}
4142

43+
/** Reports session write locks and removes stale locks when doctor repair is enabled. */
4244
export async function noteSessionLockHealth(params?: {
4345
shouldRepair?: boolean;
4446
config?: SessionWriteLockAcquireTimeoutConfig;

src/commands/doctor-session-snapshots.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor repair for stale runtime snapshot paths cached in session stores. */
12
import crypto from "node:crypto";
23
import fs from "node:fs";
34
import path from "node:path";
@@ -201,6 +202,7 @@ function resolveExpectedBundledSkillPath(params: {
201202
return params.pathExists(expectedPath) ? expectedPath : undefined;
202203
}
203204

205+
/** Finds cached bundled-skill paths that point at old runtime/temp package roots. */
204206
export function scanSessionStoreForStaleRuntimeSnapshotPaths(params: {
205207
store: Record<string, SessionEntry>;
206208
bundledSkillsDir: string | undefined;
@@ -284,10 +286,7 @@ function loadSessionStoreForSnapshotScan(storePath: string): Record<string, Sess
284286
return store;
285287
}
286288

287-
/**
288-
* Replace stale paths in raw text content (blob files or inline prompts).
289-
* Handles raw, JSON-escaped, and XML-escaped forms.
290-
*/
289+
/** Replaces stale paths in raw, JSON-escaped, and XML-escaped prompt text. */
291290
function replaceStalePathsInText(text: string, finding: StaleSessionSnapshotPathFinding): string {
292291
const jsonEscaped = JSON.stringify(finding.cachedPath).slice(1, -1);
293292
const jsonEscapedExpected = JSON.stringify(finding.expectedPath).slice(1, -1);
@@ -317,6 +316,7 @@ function replaceStalePathsInText(text: string, finding: StaleSessionSnapshotPath
317316
return result;
318317
}
319318

319+
/** Reports and optionally repairs stale bundled skill paths in session snapshot metadata. */
320320
export async function noteSessionSnapshotHealth(params?: {
321321
storePaths?: string[];
322322
bundledSkillsDir?: string;
@@ -366,7 +366,6 @@ export async function noteSessionSnapshotHealth(params?: {
366366
),
367367
);
368368

369-
// Auto-repair stale paths when shouldRepair is enabled
370369
if (params?.shouldRepair) {
371370
let repairedStores = 0;
372371
let totalReplacements = 0;

src/commands/doctor-session-state-providers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor repair for stale plugin-owned routing state persisted in session entries. */
12
import { normalizeOptionalString as normalizeString } from "@openclaw/normalization-core/string-coerce";
23
import { normalizeStringEntriesLower } from "@openclaw/normalization-core/string-normalization";
34
import { note } from "../../packages/terminal-core/src/note.js";
@@ -58,6 +59,7 @@ function resolveSessionAgentId(cfg: OpenClawConfig, sessionKey: string): string
5859
return parseAgentSessionKey(sessionKey)?.agentId ?? resolveDefaultAgentId(cfg);
5960
}
6061

62+
/** Resolves the currently configured provider/model/runtime route for a session key. */
6163
export function resolveConfiguredDoctorSessionStateRoute(params: {
6264
cfg: OpenClawConfig;
6365
sessionKey: string;
@@ -121,6 +123,7 @@ function entryMayContainPluginSessionRouteState(entry: SessionEntry): boolean {
121123
);
122124
}
123125

126+
/** Fast prefilter for session stores that might contain plugin-owned routing state. */
124127
export function storeMayContainPluginSessionRouteState(
125128
store: Record<string, SessionEntry>,
126129
): boolean {
@@ -328,6 +331,7 @@ function scanEntryForOwner(params: {
328331
};
329332
}
330333

334+
/** Scans session entries for state owned by plugins that no longer match the configured route. */
331335
export function scanSessionRouteStateOwners(params: {
332336
owners: readonly DoctorSessionRouteStateOwner[];
333337
store: Record<string, Record<string, unknown>>;
@@ -386,6 +390,7 @@ function clearRecordKeys(
386390
return true;
387391
}
388392

393+
/** Clears stale plugin-owned routing fields from a session entry and refreshes updatedAt. */
389394
export function applySessionRouteStateRepair(params: {
390395
entry: Record<string, unknown>;
391396
repair: DoctorSessionRouteStateRepair;
@@ -443,6 +448,7 @@ function groupRepairsByOwner(
443448
return grouped;
444449
}
445450

451+
/** Prompts for and applies plugin-owned session route state repairs to the session store. */
446452
export async function runPluginSessionStateDoctorRepairs(params: {
447453
cfg: OpenClawConfig;
448454
store: Record<string, SessionEntry>;

src/commands/doctor-session-transcripts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor repair for broken session transcript branches and legacy OpenAI Codex metadata. */
12
import type { Dirent } from "node:fs";
23
import fs from "node:fs/promises";
34
import path from "node:path";
@@ -208,6 +209,7 @@ async function writeTranscriptEntries(params: {
208209
return backupPath;
209210
}
210211

212+
/** Repairs one transcript file by keeping the active branch and backing up the original file. */
211213
export async function repairBrokenSessionTranscriptFile(params: {
212214
filePath: string;
213215
shouldRepair: boolean;
@@ -309,6 +311,7 @@ async function listSessionTranscriptFiles(sessionDirs: string[]): Promise<string
309311
return files.toSorted((a, b) => a.localeCompare(b));
310312
}
311313

314+
/** Scans session transcript files and reports or repairs legacy/broken transcript state. */
312315
export async function noteSessionTranscriptHealth(params?: {
313316
shouldRepair?: boolean;
314317
sessionDirs?: string[];

src/commands/doctor-skills-core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/** Pure helpers for doctor skill readiness repairs. */
12
import type { OpenClawConfig } from "../config/types.openclaw.js";
23
import type { SkillStatusEntry, SkillStatusReport } from "../skills/discovery/status.js";
34

5+
/** Returns allowed skills that are unusable in the current runtime environment. */
46
export function collectUnavailableAgentSkills(report: SkillStatusReport): SkillStatusEntry[] {
57
return report.skills.filter(
68
(skill) =>
@@ -11,6 +13,7 @@ export function collectUnavailableAgentSkills(report: SkillStatusReport): SkillS
1113
);
1214
}
1315

16+
/** Disables unavailable skills in config while preserving existing skill entries. */
1417
export function disableUnavailableSkillsInConfig(
1518
config: OpenClawConfig,
1619
skills: readonly SkillStatusEntry[],

src/commands/doctor-skills.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Doctor checks and repair prompts for unavailable configured skills. */
12
import { existsSync } from "node:fs";
23
import { note } from "../../packages/terminal-core/src/note.js";
34
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
@@ -57,10 +58,12 @@ function defaultGhConfigDiscoveryInput(): GhConfigDiscoveryInput {
5758
};
5859
}
5960

61+
/** Builds a GitHub CLI config-dir hint for eligible GitHub skill setups. */
6062
export function describeGhConfigDirHint(skills: SkillStatusEntry[]): string[] {
6163
return describeGhConfigDirHintFromDiscovery(skills, defaultGhConfigDiscoveryInput());
6264
}
6365

66+
/** Builds a GitHub CLI config-dir hint from injected discovery inputs for tests. */
6467
export function describeGhConfigDirHintFromDiscovery(
6568
skills: SkillStatusEntry[],
6669
discoveryInput: GhConfigDiscoveryInput,
@@ -84,6 +87,7 @@ export function describeGhConfigDirHintFromDiscovery(
8487
return formatGhConfigDirMismatchHint(result);
8588
}
8689

90+
/** Formats doctor note lines for skills that are allowed but unavailable. */
8791
export function formatUnavailableSkillDoctorLines(skills: SkillStatusEntry[]): string[] {
8892
const lines: string[] = [
8993
"Some skills are allowed for this agent but are not usable in the current runtime environment.",
@@ -99,6 +103,7 @@ export function formatUnavailableSkillDoctorLines(skills: SkillStatusEntry[]): s
99103
return lines;
100104
}
101105

106+
/** Checks default-agent skill readiness and optionally disables unavailable skills in config. */
102107
export async function maybeRepairSkillReadiness(params: {
103108
cfg: OpenClawConfig;
104109
prompter: DoctorPrompter;

0 commit comments

Comments
 (0)