Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
refactor(doctor): keep bootstrapDoctorChecks within its function-size baseline (#5063)
time-attack149249b5b6f6
diff --git a/src/commands/doctor/bootstrap-checks.ts b/src/commands/doctor/bootstrap-checks.tsindex 7d82b02e96..306ca30b93 100644--- a/src/commands/doctor/bootstrap-checks.ts+++ b/src/commands/doctor/bootstrap-checks.ts@@ -40,6 +40,21 @@ async function pushSupersededEnrollmentCheck(checks: Check[], engine: BrainEnginreturn true;}+/** #5063: commits on the workspace's named branch that origin/<branch> lacks, counted whatever the push age (0 when unknown). */+function commitsAheadOfOrigin(ws: string, branch: string): number {+ if (!branch) return 0;+ try {+ return parseInt(execFileSync('git', ['-C', ws, 'rev-list', '--count', `origin/${branch}..HEAD`], {+ stdio: ['ignore', 'pipe', 'ignore'], timeout: 10_000,+ }).toString().trim(), 10) || 0;+ } catch { return 0; }+}++/** #5063: a recent successful push of something never certifies a tree that is still ahead. */+function aheadOfOriginMessage(lastPush: string, ws: string, ahead: number): string {+ return `last push ok (${lastPush}), but ${ws} has ${ahead} commit(s) not on origin — recent agent memory is unpushed. Run \`gbrain sources push --path ${ws}\`.`;+}+export async function bootstrapDoctorChecks(engine: BrainEngine | null): Promise<Check[]> {const checks: Check[] = [];let home: string;@@ -277,25 +292,14 @@ export async function bootstrapDoctorChecks(engine: BrainEngine | null): Promise// per-turn push [hook.ts]. `known` distinguishes "verified clean"// from "couldn't verify" (no receipt/workspace, or the git probe// itself failed): unverified must NOT be treated as clean below.- let dirty = false;- let known = false;- // #5063: commits on a NAMED branch not yet on origin, counted whatever the push age.- let ahead = 0;+ let dirty = false, known = false, ahead = 0;if (ws) {try {const statusOut = execFileSync('git', ['-C', ws, 'status', '--porcelain'], {stdio: ['ignore', 'pipe', 'ignore'], timeout: 10_000,}).toString();- const branch = execFileSync('git', ['-C', ws, 'branch', '--show-current'], {- stdio: ['ignore', 'pipe', 'ignore'], timeout: 10_000,- }).toString().trim();- if (branch) {- try {- ahead = parseInt(execFileSync('git', ['-C', ws, 'rev-list', '--count', `origin/${branch}..HEAD`], {- stdio: ['ignore', 'pipe', 'ignore'], timeout: 10_000,- }).toString().trim(), 10) || 0;- } catch { ahead = 0; }- }+ const branch = execFileSync('git', ['-C', ws, 'branch', '--show-current'], { stdio: ['ignore', 'pipe', 'ignore'], timeout: 10_000 }).toString().trim();+ ahead = commitsAheadOfOrigin(ws, branch);if (statusOut.trim() !== '') {dirty = true;known = true;@@ -377,15 +381,9 @@ export async function bootstrapDoctorChecks(engine: BrainEngine | null): Promise? `last successful push ${staleIso} (>48h ago); workspace tree state unverified (the git probe failed) — check ${ws} manually, or run \`gbrain sources push --path ${ws}\` to be safe`: `last successful push ${staleIso} (>48h ago); workspace tree state unverified (no bootstrap receipt on this machine names a workspace to check) — check the workspace manually`,});- } else if (ahead > 0) {- // #5063: a recent successful push of something never certifies a tree that is still ahead.- checks.push({- name: 'bootstrap_push_health',- status: 'warn',- message: `last push ok (${staleIso}), but ${ws} has ${ahead} commit(s) not on origin — recent agent memory is unpushed. Run \`gbrain sources push --path ${ws}\`.`,- });} else {- checks.push({ name: 'bootstrap_push_health', status: 'ok', message: `last push ok (${staleIso})` });+ checks.push(ahead > 0 ? { name: 'bootstrap_push_health', status: 'warn', message: aheadOfOriginMessage(staleIso, ws!, ahead) }+ : { name: 'bootstrap_push_health', status: 'ok', message: `last push ok (${staleIso})` });}}} else if (statusFilesOnDisk) {