Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(doctor): run_doctor renders fixes for its transport; remote and CLI doctor parity pinned (E2)
garrytan624a368bd679
diff --git a/scripts/test-weights.json b/scripts/test-weights.jsonindex f8a597c73d..56ebeb41a6 100644--- a/scripts/test-weights.json+++ b/scripts/test-weights.json@@ -554,6 +554,7 @@"test/doctor-queue-divergence.test.ts": 1866,"test/doctor-raw-provenance.test.ts": 398,"test/doctor-remediation-plan-render.test.ts": 2,+ "test/doctor-remote-parity.test.ts": 3000,"test/doctor-reranker-health.test.ts": 10,"test/doctor-retrieval-reflex.test.ts": 34,"test/doctor-schema-column-diff.test.ts": 337,diff --git a/scripts/ubicloud/weights.json b/scripts/ubicloud/weights.jsonindex a170d5bc47..c9a5dd7c41 100644--- a/scripts/ubicloud/weights.json+++ b/scripts/ubicloud/weights.json@@ -1162,6 +1162,7 @@"unit:test/doctor-queue-divergence.test.ts": 3760,"unit:test/doctor-raw-provenance.test.ts": 1563,"unit:test/doctor-remediation-plan-render.test.ts": 328,+ "unit:test/doctor-remote-parity.test.ts": 3000,"unit:test/doctor-reranker-health.test.ts": 296,"unit:test/doctor-retrieval-reflex.test.ts": 269,"unit:test/doctor-schema-column-diff.test.ts": 1774,diff --git a/src/commands/doctor/check-fix.ts b/src/commands/doctor/check-fix.tsindex 844233ab45..cf530366d2 100644--- a/src/commands/doctor/check-fix.ts+++ b/src/commands/doctor/check-fix.ts@@ -9,7 +9,7 @@* Stored checks carry `Action`; `finalizeCheckFixes` renders them for the* report's transport (CLI `gbrain doctor --json`, MCP `run_doctor`).*/-import { cliRenderContext, renderAction, type Action, type RenderContext, type RenderedAction } from '../../core/agent-output.ts';+import { cliRenderContext, redactForTransport, renderAction, type Action, type RenderContext, type RenderedAction } from '../../core/agent-output.ts';import { embeddingEnablement, type ReadinessEntry, type ReadinessState } from '../../core/readiness.ts';import { loadConfig } from '../../core/config.ts';import { classifyPgAccessError } from '../../core/pg-access-classify.ts';@@ -113,13 +113,14 @@ function isRendered(fix: Action | RenderedAction): fix is RenderedAction {}/**- * Report-time pass: render every stored `fix` for the caller's transport and+ * Report-time pass: render every stored `fix` for the caller's transport+ * (redacted on http: no local paths, PIDs or key names) and* mark any non-ok check that still has neither a fix nor a reason as* `unstructured` (its message is the guidance).*/export function finalizeCheckFixes<T extends CheckLike>(checks: readonly T[], render: RenderContext = cliRenderContext()): T[] {return checks.map((c) => {- if (c.fix) return isRendered(c.fix) ? c : { ...c, fix: renderAction(c.fix, render) };+ if (c.fix) return isRendered(c.fix) ? c : { ...c, fix: redactForTransport(renderAction(c.fix, render), render.transport) };if (c.status === 'ok' || c.fix_unavailable_reason) return c;return { ...c, fix_unavailable_reason: 'unstructured' as const };});diff --git a/src/commands/doctor/report-remote.ts b/src/commands/doctor/report-remote.tsindex bcfa4c938b..57d5e537b5 100644--- a/src/commands/doctor/report-remote.ts+++ b/src/commands/doctor/report-remote.ts@@ -63,6 +63,7 @@ import {multiSourceDriftNotVerified,} from './schema-pack-checks.ts';import { checkError } from './check-fix.ts';+import type { RenderContext } from '../../core/agent-output.ts';// Same alias the local doctor keeps for its own freshness checks; the alias// is a private one-liner in doctor.ts's check-fn library, so this module@@ -71,7 +72,7 @@ const _resolveSyncFreshnessHours = resolveHoursEnv;export async function doctorReportRemote(engine: BrainEngine,- opts: { sourceIds?: string[]; remote?: boolean } = {},+ opts: { sourceIds?: string[]; remote?: boolean; render?: RenderContext } = {},): Promise<DoctorReport> {const checks: Check[] = [];@@ -111,7 +112,7 @@ export async function doctorReportRemote(checks.push(await checkPgliteScratchProbe({ realInitFailed: true, storeDamageEvidence, realStorePath }));}// Without a connection, every other check is meaningless — short-circuit.- return computeDoctorReport(checks);+ return computeDoctorReport(checks, { render: opts.render });}// 2. Schema version. Uses engine.getConfig('version') — the same engine-@@ -442,5 +443,5 @@ export async function doctorReportRemote(const { remoteWaveHandoff } = await import('./wave-checks.ts');checks.push(...await remoteWaveHandoff(engine, opts.sourceIds));- return computeDoctorReport(checks);+ return computeDoctorReport(checks, { render: opts.render });}diff --git a/src/commands/remote.ts b/src/commands/remote.tsindex a62ec4374b..b430a8e500 100644--- a/src/commands/remote.ts+++ b/src/commands/remote.ts@@ -21,6 +21,7 @@import { loadConfig, isThinClient } from '../core/config.ts';import { callRemoteTool, unpackToolResult, RemoteMcpError } from '../core/mcp-client.ts';import type { DoctorReport, Check } from './doctor.ts';+import { fixLine } from './doctor/check-fix.ts';interface RemoteFlags {json: boolean;@@ -238,8 +239,10 @@ function renderDoctorReport(report: DoctorReport): void {console.log('\nGBrain Health Check (remote host)');console.log('=================================');for (const c of report.checks) {- const icon = c.status === 'ok' ? 'OK' : c.status === 'warn' ? 'WARN' : 'FAIL';+ const icon = c.status === 'ok' ? (c.severity === 'info' ? 'INFO' : 'OK') : c.status === 'warn' ? 'WARN' : 'FAIL';console.log(` [${icon}] ${c.name}: ${c.message}`);+ const fix = c.status === 'ok' ? null : fixLine(c.fix);+ if (fix) console.log(` Fix: ${fix}`);}console.log(`\nHealth score: ${report.health_score}/100. Status: ${report.status}.`);if (report.status === 'unhealthy') {diff --git a/src/core/ops/admin.ts b/src/core/ops/admin.tsindex 9a9af64993..6278f9cf18 100644--- a/src/core/ops/admin.ts+++ b/src/core/ops/admin.ts@@ -178,7 +178,9 @@ const run_doctor: Operation = {// unscoped ctx = brain-wide.const scope = sourceScopeOpts(ctx);const sourceIds = scope.sourceIds ?? (scope.sourceId ? [scope.sourceId] : undefined);- return doctorReportRemote(ctx.engine, { sourceIds, remote: ctx.remote });+ const transport = ctx.remote === false ? 'cli' : ctx.transport ?? 'http';+ return doctorReportRemote(ctx.engine, { sourceIds, remote: ctx.remote,+ render: { transport, isCallable: (op) => op === 'run_doctor', preapproved: () => false } });},scope: 'admin',localOnly: false,diff --git a/test/doctor-remote-parity.test.ts b/test/doctor-remote-parity.test.tsnew file mode 100644index 0000000000..282372ae4d--- /dev/null+++ b/test/doctor-remote-parity.test.ts@@ -0,0 +1,60 @@+/**+ * Agent-first operator wave E2: `run_doctor` (MCP, `doctorReportRemote`) and+ * the CLI `doctor` (`buildChecks`) agree on the same brain. Both surfaces call+ * the same check functions; this pins that every check name both emit has the+ * same status, severity and readiness_state on a keyless day-zero brain, and+ * that the remote report renders fixes for its transport (CLI-only commands+ * become tell_user_to_run for host_admin over HTTP, with no local paths).+ */+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { buildChecks, doctorReportRemote } from '../src/commands/doctor.ts';+import { withEnv } from './helpers/with-env.ts';++let home: string;+let engine: PGLiteEngine;+const ENV = { OPENAI_API_KEY: undefined, VOYAGE_API_KEY: undefined, ANTHROPIC_API_KEY: undefined } as const;++beforeAll(async () => {+ home = mkdtempSync(join(tmpdir(), 'gbrain-remote-parity-'));+ mkdirSync(join(home, '.gbrain'));+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', embedding_disabled: true }));+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+ await engine.setConfig('embedding_disabled', 'true');+});++afterAll(async () => {+ await engine.disconnect();+ rmSync(home, { recursive: true, force: true });+});++describe('run_doctor and CLI doctor agree', () => {+ test('shared checks have the same status, severity and readiness_state', async () => {+ await withEnv({ ...ENV, GBRAIN_HOME: home, HOME: home }, async () => {+ const local = new Map((await buildChecks(engine, ['--json'])).map(c => [c.name, c]));+ const remote = await doctorReportRemote(engine, { remote: true });+ const shared = remote.checks.filter(c => local.has(c.name));+ expect(shared.length).toBeGreaterThan(20);+ const disagreements = shared+ .map(r => ({ r, l: local.get(r.name)! }))+ .filter(({ r, l }) => r.status !== l.status || (r.severity ?? null) !== (l.severity ?? null) || (r.readiness_state ?? null) !== (l.readiness_state ?? null))+ .map(({ r, l }) => `${r.name}: local ${l.status}/${l.severity ?? '-'} remote ${r.status}/${r.severity ?? '-'}`);+ expect(disagreements).toEqual([]);+ });+ });++ test('fixes render for the caller transport: CLI-only → host_admin + tell_user_to_run over HTTP, local paths redacted', async () => {+ const { computeDoctorReport } = await import('../src/commands/doctor.ts');+ const report = computeDoctorReport([{ name: 'embeddings', status: 'warn', message: 'x',+ fix: { argv: ['gbrain', 'init', '--force', '--path', `${home}/.gbrain/brain.pglite`], consent: [], actor: 'agent', why: `brain at ${home}/.gbrain`, requires_exclusive: true } }],+ { render: { transport: 'http', isCallable: () => false, preapproved: () => false } });+ const fix = report.checks[0].fix as Record<string, unknown>;+ expect(fix).toMatchObject({ actor: 'host_admin', next: 'tell_user_to_run' });+ expect(JSON.stringify(fix)).not.toContain(home);+ });+});