Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): pglite_leftovers names the size preview and the consent-gated delete for the old PGLite store (#7145)
garrytanc4a35495e234
diff --git a/src/commands/doctor/checks/local-audits.ts b/src/commands/doctor/checks/local-audits.tsindex 53ca4348d5..e8d65bcca4 100644--- a/src/commands/doctor/checks/local-audits.ts+++ b/src/commands/doctor/checks/local-audits.ts@@ -460,10 +460,21 @@ async function runHomeDirInWorktree(ctx: DoctorContext): Promise<Check[]> {);if (leftovers.status !== 'skip') {const copy = leftovers.retained?.[0];+ const store = leftovers.leftovers[0];checks.push({name: 'pglite_leftovers',status: leftovers.status,message: leftovers.message,+ // #7145: the legacy copier's old store gets the same consent-gated delete as a graduation copy, after a size preview.+ ...(!copy && store ? {+ details: { leftovers: leftovers.leftovers, preview: ['du', '-sh', store.path] },+ fix: {+ argv: ['rm', '-rf', store.path], consent: ['destructive'], actor: 'agent', requires_exclusive: false,+ verify: { argv: ['gbrain', 'doctor', '--only', 'pglite_leftovers', '--json'] }, docs: 'docs/guides/move-to-postgres.md#after-the-move',+ why: `${store.path} is the PGLite store the engine migration left behind; the brain reads Postgres (config.json engine), so nothing uses it. Preview its size with du -sh ${store.path}; deleting it frees that disk and cannot be undone.`,+ user_message: `Your brain moved to Postgres, but the old local PGLite copy is still at ${store.path}. Once you have a recent Postgres backup, should I delete it? It cannot be undone.`,+ },+ } : {}),...(copy ? {details: { retained: leftovers.retained },fix: {diff --git a/src/core/pglite-leftovers-check.ts b/src/core/pglite-leftovers-check.tsindex bc565cda39..d58bb58a1f 100644--- a/src/core/pglite-leftovers-check.ts+++ b/src/core/pglite-leftovers-check.ts@@ -282,7 +282,8 @@ export function assessPgliteLeftovers(`${anyIncomplete ? 'at least ' : ''}${humanBytes(total, anyIncomplete)} of reclaimable disk. ` +`It also inflates any backup that archives the gbrain home. Your live data is in the postgres ` +`engine; once you have verified that (a recent restore or backup of it), the dir is safe to ` +- `delete by hand — gbrain never deletes it for you.`,+ `delete by hand — gbrain never deletes it for you. Preview: du -sh ${leftovers[0]!.path}; then, after the user agrees: ` ++ `${leftovers.map((l) => `rm -rf ${l.path}`).join('; ')}.`,leftovers,};}diff --git a/test/doctor-pglite-leftovers-fix-7145.test.ts b/test/doctor-pglite-leftovers-fix-7145.test.tsnew file mode 100644index 0000000000..df36aed737--- /dev/null+++ b/test/doctor-pglite-leftovers-fix-7145.test.ts@@ -0,0 +1,36 @@+/**+ * #7145: pglite_leftovers names the exact cleanup for the legacy copier's old store, not only a graduation copy:+ * a size preview (du -sh) and a consent-gated delete (fix argv rm -rf <path>, consent destructive, asked of the user).+ * Synthetic gbrain home under the OS temp dir; nothing is deleted.+ */+import { afterAll, 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 { withEnv } from './helpers/with-env.ts';+import { homeDirInWorktreeEntry } from '../src/commands/doctor/checks/local-audits.ts';+import type { DoctorContext } from '../src/commands/doctor/context.ts';+import type { Check } from '../src/commands/doctor.ts';++const home = mkdtempSync(join(tmpdir(), 'gbrain-7145-leftovers-'));+afterAll(() => rmSync(home, { recursive: true, force: true }));++describe('pglite_leftovers cleanup command', () => {+ test('the old brain.pglite store gets a preview and a consent-gated delete of exactly that path', async () => {+ const gbrain = join(home, '.gbrain');+ const store = join(gbrain, 'brain.pglite');+ mkdirSync(store, { recursive: true });+ writeFileSync(join(store, 'PG_VERSION'), 'x'.repeat(4096));+ writeFileSync(join(gbrain, 'config.json'), JSON.stringify({ engine: 'postgres', database_url: 'postgresql://[email protected]:5432/brain' }));+ const checks = (await withEnv({ GBRAIN_HOME: home, GBRAIN_GRADUATION_RUN: undefined, GBRAIN_DATABASE_URL: undefined, DATABASE_URL: undefined },+ () => homeDirInWorktreeEntry.run({} as DoctorContext))) as Check[];+ const check = checks.find(c => c.name === 'pglite_leftovers')!;+ expect(check.status).toBe('warn');+ expect(check.fix).toMatchObject({ argv: ['rm', '-rf', store], consent: ['destructive'], actor: 'agent',+ verify: { argv: ['gbrain', 'doctor', '--only', 'pglite_leftovers', '--json'] } });+ expect(String((check.fix as { user_message?: string }).user_message)).toContain(store);+ expect(check.details).toMatchObject({ preview: ['du', '-sh', store], leftovers: [expect.objectContaining({ path: store })] });+ expect(check.message).toContain(`du -sh ${store}`);+ expect(check.message).toContain(`rm -rf ${store}`);+ });+});