Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(lane-e): CI round 2 + Lane C follow-ups — e2e dream gateway key, autopilot consent test exit code, consent-honest repair and reinstall guidance
garrytand3d29f043035
diff --git a/scripts/agent-contract-baselines/yes-rerun-string.tsv b/scripts/agent-contract-baselines/yes-rerun-string.tsvindex 75c3531f97..1797ba002b 100644--- a/scripts/agent-contract-baselines/yes-rerun-string.tsv+++ b/scripts/agent-contract-baselines/yes-rerun-string.tsv@@ -1,11 +1,8 @@# shrink-only baseline for scripts/check-agent-contract.ts rule yes-rerun-string: path<TAB>countsrc/cli.ts 3src/commands/apply-migrations.ts 3-src/commands/config.ts 1src/commands/db-repair.ts 1-src/commands/doctor/checks/memory-writeback.ts 2src/commands/mcp-expose.ts 3-src/commands/migrations/v0_11_0.ts 1src/core/page-state/credential-reseal.ts 1src/core/schema-migrations/v039-multimodal-dual-column-v0-27-1.ts 2src/core/schema-migrations/v045-facts-hot-memory-v0-31.ts 1diff --git a/src/commands/config.ts b/src/commands/config.tsindex 8e9190ac6d..1b221d219a 100644--- a/src/commands/config.ts+++ b/src/commands/config.ts@@ -1155,7 +1155,7 @@ export async function runConfig(engine: BrainEngine, args: string[]) {`[config] Switching the default to a low-coverage column silently degrades search.`,);console.error(- `[config] Re-run with --coverage-override (or --yes) to proceed anyway:`,+ `[config] Ask the user first; to switch anyway, pass --coverage-override:`,);console.error(`[config] gbrain config set search_embedding_column ${value} --coverage-override`,diff --git a/src/commands/doctor/checks/core-health.ts b/src/commands/doctor/checks/core-health.tsindex 39a6aed75c..8096aaa319 100644--- a/src/commands/doctor/checks/core-health.ts+++ b/src/commands/doctor/checks/core-health.ts@@ -684,7 +684,7 @@ export async function checkPgliteScratchProbe(opts: {`A scratch PGLite store initialized, wrote and read back fine on this machine (${secs}s), ` +`so the runtime is healthy and YOUR STORE is damaged — not the WASM runtime. ` +`Your markdown is unaffected: the DB holds derived data (chunks, embeddings, links, facts) that a re-sync rebuilds. ` +- `Recover: \`gbrain pglite-repair --dry-run\` to diagnose, \`gbrain pglite-repair --yes\` for in-place WAL repair (data preserved); ` ++ `Recover: \`gbrain pglite-repair --dry-run\` diagnoses it and prints the plan-bound in-place WAL repair command (data preserved) to run once the user approves; ` +`if that can't fix it, restore a backup of the store directory or run \`gbrain reinit-pglite\` (wipes + re-inits + re-syncs; ` +`defaults embedding flags from your config file).`,details: { scratch_ok: true, duration_ms: r.duration_ms },diff --git a/src/commands/doctor/checks/memory-writeback.ts b/src/commands/doctor/checks/memory-writeback.tsindex 6c0b21361f..47aa47aed6 100644--- a/src/commands/doctor/checks/memory-writeback.ts+++ b/src/commands/doctor/checks/memory-writeback.ts@@ -23,6 +23,7 @@import { existsSync, readFileSync } from 'node:fs';import type { BrainEngine } from '../../../core/engine.ts';import type { Check } from '../../doctor.ts';+import type { Effect } from '../../../core/agent-output.ts';import { loadConfig } from '../../../core/config.ts';import { resolveGbrainHome } from '../../../core/gbrain-home.ts';import {@@ -235,19 +236,19 @@ export async function buildMemoryWritebackCheck(engine: BrainEngine | null): Pro}if (!existsSync(t.path)) {entry.probe = 'missing';- problems.push(`${t.host} instruction block missing at ${t.path} — re-run: gbrain bootstrap harness --yes`);+ problems.push(`${t.host} instruction block missing at ${t.path} — after the user agrees, reinstall: gbrain bootstrap harness --yes`);} else {const probe = probeAmbientBlock(readFileSync(t.path, 'utf8'));if (probe.state === 'absent' || probe.state === 'damaged') {entry.probe = probe.state === 'damaged' ? 'damaged' : 'missing';- problems.push(`${t.host} instruction block ${probe.state === 'damaged' ? 'has damaged markers' : 'missing'} at ${t.path} — re-run: gbrain bootstrap harness --yes`);+ problems.push(`${t.host} instruction block ${probe.state === 'damaged' ? 'has damaged markers' : 'missing'} at ${t.path} — after the user agrees, reinstall: gbrain bootstrap harness --yes`);} else if (probe.interior !== expectedBody) {entry.probe = 'drift';// The combo converges even when the file-plane posture stamp is// stale (e.g. facts.default_visibility flipped on ANOTHER// machine of a shared Postgres brain): the config set re-stamps// the mirror from DB truth, then the harness re-renders from it.- problems.push(`${t.host} instruction block is stale (config changed since install) — re-run: gbrain config set memory.auto_writeback ${wb.mode} && gbrain bootstrap harness --yes`);+ problems.push(`${t.host} instruction block is stale (config changed since install) — after the user agrees, refresh: gbrain config set memory.auto_writeback ${wb.mode} && gbrain bootstrap harness --yes`);} else {entry.probe = 'current';}@@ -322,6 +323,13 @@ export async function buildMemoryWritebackCheck(engine: BrainEngine | null): Pro? `ambient writeback ${wb.mode}: ${problems.join('; ')}`: `ambient writeback ${wb.mode} (ttl ${wb.transient_ttl}, template visibility ${wb.visibility}, audience ${audience.audience})`,details,+ ...(problems.some((p) => p.includes('gbrain bootstrap harness'))+ ? { fix: {+ argv: ['gbrain', 'bootstrap', 'harness', '--yes'], consent: ['persistent_install'] as Effect[], actor: 'agent' as const, requires_exclusive: false,+ why: 'Rewrites the gbrain memory instruction block in each harness config from the current writeback settings.',+ user_message: "gbrain's memory instructions in your agent app's config are missing or out of date. OK if I reinstall them?",+ verify: { argv: ['gbrain', 'doctor', '--only', MEMORY_WRITEBACK_CHECK_NAME, '--json'] } } }+ : problems.length ? { fix_unavailable_reason: 'operator_judgement' as const } : {}),};} catch (e) {return {diff --git a/src/commands/doctor/checks/pglite-worker.ts b/src/commands/doctor/checks/pglite-worker.tsindex ec188e2061..227bf974ec 100644--- a/src/commands/doctor/checks/pglite-worker.ts+++ b/src/commands/doctor/checks/pglite-worker.ts@@ -7,6 +7,12 @@import * as db from '../../../core/db.ts';import type { BrainEngine } from '../../../core/engine.ts';import type { Check } from '../../doctor.ts';+import { agentFix } from '../check-fix.ts';++/** Read-only diagnosis; it prints the plan-bound repair command the user approves. */+function pgliteRepairPreview() {+ return agentFix(['gbrain', 'pglite-repair', '--dry-run'], 'Diagnoses the PGLite store without changing it and prints the exact repair command, bound to this plan, for the user to approve.', 'pglite_data_dir');+}// ≥2 failed repair attempts inside 7 days = the corruption keeps regenerating.const REPAIR_RECURRENCE_WINDOW_MS = 7 * 24 * 3600 * 1000;@@ -79,8 +85,9 @@ export function computePgliteDataDirCheck(message:`PGLite failed to open and the data dir shows unclean-shutdown state (${diagnosis.detail}). ` +`This is the torn-WAL class behind issue #223 — repairable in place, data preserved: ` +- `\`gbrain pglite-repair --dry-run\` to diagnose, \`gbrain pglite-repair --yes\` to repair.${backupNote}${recurrence}`,+ `\`gbrain pglite-repair --dry-run\` diagnoses it and prints the plan-bound repair command to run once the user approves.${backupNote}${recurrence}`,remediation_status: 'human_only',+ fix: pgliteRepairPreview(),};case 'looks-healthy':default:@@ -90,10 +97,11 @@ export function computePgliteDataDirCheck(message:`PGLite failed to open but the data dir layout validates (${diagnosis.detail}). ` +`IF the connect error mentions \`Aborted()\` this is likely torn WAL state — ` +- `\`gbrain pglite-repair --dry-run\` to diagnose, \`gbrain pglite-repair --yes\` to repair in place ` ++ `\`gbrain pglite-repair --dry-run\` diagnoses it and prints the plan-bound in-place repair command to run once the user approves ` +`(repair discards the un-checkpointed WAL tail — don't run it for lock-contention or ` +`catalog-corruption errors; 58P01/pgvector load failures need \`gbrain reinit-pglite\` instead).${backupNote}${recurrence}`,remediation_status: 'human_only',+ fix: pgliteRepairPreview(),};}}diff --git a/src/commands/migrations/v0_11_0.ts b/src/commands/migrations/v0_11_0.tsindex 60c58eeed8..a9660d7b9b 100644--- a/src/commands/migrations/v0_11_0.ts+++ b/src/commands/migrations/v0_11_0.ts@@ -469,8 +469,8 @@ async function orchestrator(opts: OrchestratorOpts): Promise<OrchestratorResult>console.log(` skills/migrations/v0.11.0.md`);console.log('');console.log('The skill walks the host through each item using GBrain\'s plugin contract.');- console.log('Re-run `gbrain apply-migrations --yes` after each batch to auto-rewrite newly-');- console.log('registerable crons and mark items done.');+ console.log('After each batch, `gbrain apply-migrations --yes` (this upgrade\'s own command) rewrites newly-');+ console.log('registerable crons and marks items done.');}return {diff --git a/test/autopilot-install-consent.test.ts b/test/autopilot-install-consent.test.tsindex 30450b7e4c..8f263ceca9 100644--- a/test/autopilot-install-consent.test.ts+++ b/test/autopilot-install-consent.test.ts@@ -7,7 +7,7 @@* plan and writes nothing; `--yes` installs; the preapproval installs and says* so on stderr.*/-import { describe, expect, test } from 'bun:test';+import { afterAll, describe, expect, test } from 'bun:test';import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';@@ -48,6 +48,12 @@ async function install(extra: string[], opts: { preapprove?: boolean } = {}) {return { stdout: stdout.join('\n'), stderr: stderr.join(''), verdict: currentExitCode(), wrapperWritten: existsSync(wrapper) };}+afterAll(() => {+ // The refusal case sets exit verdict 3, which mirrors into process.exitCode.+ _resetCliExitVerdictForTests();+ process.exitCode = 0;+});+describe('autopilot --install consent', () => {test('non-TTY without --yes: exit 3, confirmation_required payload, nothing written', async () => {const r = await install(['--json']);diff --git a/test/e2e/dream.test.ts b/test/e2e/dream.test.tsindex 392d5a3cf9..17c28a268e 100644--- a/test/e2e/dream.test.ts+++ b/test/e2e/dream.test.ts@@ -15,6 +15,8 @@ import { join } from 'path';import { execSync } from 'child_process';import { tmpdir } from 'os';import { hasDatabase, setupLegacyEmbeddingDB, teardownDB, getEngine, getConn } from './helpers.ts';+import { configureGateway } from '../../src/core/ai/gateway.ts';+import { LEGACY_EMBEDDING_CONFIG } from '../helpers/legacy-embedding-config.ts';// Mock embedBatch so embed phase doesn't call OpenAI.mock.module('../../src/core/embedding.ts', () => ({@@ -67,6 +69,9 @@ describeE2E('E2E: gbrain dream CLI against real Postgres', () => {beforeAll(async () => {await setupLegacyEmbeddingDB();+ // embedBatch is mocked above, but the embed phase's credential preflight+ // reads the gateway env, and a failed phase now exits 1 (agent operator E4).+ configureGateway({ ...LEGACY_EMBEDDING_CONFIG, env: { OPENAI_API_KEY: 'placeholder-key-embed-is-mocked' } });repo = makeGitRepo();}, 30_000);