Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(repair): per-row fix lines keep their consent; refused rows and outcomes carry the refusal's why (GST-1555 /ship pass 1)
garrytan56618c969d89
diff --git a/src/commands/repair.ts b/src/commands/repair.tsindex ba17f2e5c6..1f4c443733 100644--- a/src/commands/repair.ts+++ b/src/commands/repair.ts@@ -443,10 +443,13 @@ export function renderRepairResult(result: RepairResult, opts: { diff: boolean }}if (result.scan?.partial) lines.push(' scan: partial (the census did not finish within its bound; more candidates may exist, rerun to resume it)');if (result.stopped) lines.push(` STOPPED: ${result.stopped.message}`);- if (result.stopped?.fix?.argv) lines.push(` fix: ${shellQuote(result.stopped.fix.argv)}${result.stopped.fix.consent.length ? ` (asks the user first: ${result.stopped.fix.consent.join(', ')})` : ''}`);+ const fixLine = (indent: string, fix: { argv?: string[]; consent?: string[] } | undefined) => {+ if (fix?.argv) lines.push(`${indent}fix: ${shellQuote(fix.argv)}${fix.consent?.length ? ` (asks the user first: ${fix.consent.join(', ')})` : ''}`);+ };+ fixLine(' ', result.stopped?.fix);for (const entry of result.listing ?? []) {lines.push(` ${entry.class}: ${entry.item}${entry.detail ? ` (${entry.detail})` : ''}`);- if (entry.fix?.argv) lines.push(` fix: ${shellQuote(entry.fix.argv)}`);+ fixLine(' ', entry.fix);}const render = repairSpec(result.kind).handler.render;if (result.details && render) lines.push(...render(result.details, opts));@@ -455,8 +458,7 @@ export function renderRepairResult(result: RepairResult, opts: { diff: boolean }if (!outcome.detail) continue;lines.push(` ${outcome.outcome}: ${outcome.item} ${Object.entries(outcome.detail).filter(([key]) => key !== 'commit_step' && key !== 'fix').map(([k, v]) => `${k}=${v}`).join(', ')}${outcome.reason ? ` (${outcome.reason})` : ''}`);if (typeof outcome.detail.commit_step === 'string') lines.push(` commit: ${outcome.detail.commit_step}`);- const fix = outcome.detail.fix as { argv?: string[] } | undefined;- if (fix?.argv) lines.push(` fix: ${shellQuote(fix.argv)}`);+ fixLine(' ', outcome.detail.fix as { argv?: string[]; consent?: string[] } | undefined);}if (result.mode === 'dry_run' && result.affected) lines.push(` apply: ${result.apply_command}`);return lines.join('\n');diff --git a/src/core/repair/file-drift.ts b/src/core/repair/file-drift.tsindex 58ff6a8baf..1b127fce23 100644--- a/src/core/repair/file-drift.ts+++ b/src/core/repair/file-drift.ts@@ -687,7 +687,7 @@ async function applyDeletedSide(ctx: OperationContext, page: ApprovedPage, artifif (acceptedPendingReceipt(error) || !(error instanceof OperationError) || ['owner_unavailable', 'writer_lock_unavailable', 'writer_busy', 'write_pending'].includes(error.code)) throw error;const changed = ['changed_since_preview', 'revision_conflict', 'page_identity_changed', 'page_not_found', 'source_changed'].includes(error.code);return { applied: false, outcome: changed ? 'changed_since_preview' : 'refused', reason: error.code,- detail: { request_id: requestId, action, message: error.message, fix: error.fix ?? repreviewFix(page, 'detach_page' in artifact+ detail: { request_id: requestId, action, message: error.message, ...(error.why ? { why: error.why } : {}), fix: error.fix ?? repreviewFix(page, 'detach_page' in artifact? ['gbrain', 'repair', 'file-drift', '--source', page.source_id, '--held', '--side', 'deleted', '--state', 'file_gone', '--provenance', 'never_committed', '--only', artifact.detach_page.path, '--prefer', 'database']: heldDriftPreviewArgv(page.source_id, 'deleted', ('remove_file' in artifact ? artifact.remove_file : artifact.import_file).state, artifact.prefer,('remove_file' in artifact ? artifact.remove_file : artifact.import_file).path)) } };@@ -846,7 +846,7 @@ export const fileDriftRepair: RepairHandler = {} catch (error) {if (!(error instanceof OperationError) || ['owner_unavailable', 'writer_registration_required'].includes(error.code)) throw error;count(`refused_${error.code}`);- listing.push({ item: `${sourceId}:${label}`, class: 'refused', detail: `${error.code}: ${error.message}`, ...(error.fix ? { fix: error.fix } : {}) });+ listing.push({ item: `${sourceId}:${label}`, class: 'refused', detail: `${error.code}: ${error.message}${error.why ? ` (${error.why})` : ''}`, ...(error.fix ? { fix: error.fix } : {}) });}}});@@ -933,7 +933,7 @@ export const fileDriftRepair: RepairHandler = {const changed = error.code === 'revision_conflict' || error.code === 'page_identity_changed' || error.code === 'page_not_found'|| error.code === 'source_changed' && error.message.startsWith('Reconciliation preview is stale');outcome = { applied: false, outcome: changed ? 'changed_since_preview' : 'refused', reason: error.code,- detail: { request_id: requestId, message: error.message, fix: error.fix ?? repreviewFix(page, ['gbrain', 'repair', 'file-drift', '--source', page.source_id, '--slug', page.slug, '--prefer', artifact.prefer]) } };+ detail: { request_id: requestId, message: error.message, ...(error.why ? { why: error.why } : {}), fix: error.fix ?? repreviewFix(page, ['gbrain', 'repair', 'file-drift', '--source', page.source_id, '--slug', page.slug, '--prefer', artifact.prefer]) } };}if (last) {await clearApprovedSet(ctx.engine, { command: 'file-drift', hash });diff --git a/test/file-drift-segmented-protected-gst1555.test.ts b/test/file-drift-segmented-protected-gst1555.test.tsindex 0e4453273d..41e588addb 100644--- a/test/file-drift-segmented-protected-gst1555.test.ts+++ b/test/file-drift-segmented-protected-gst1555.test.ts@@ -30,7 +30,8 @@ import { performManagedSync } from '../src/core/persistence/sync-run.ts';import { strictReconcileKeys } from '../src/core/persistence/reconcile-merge.ts';import { materializedSnapshot } from '../src/core/persistence/segmented-apply.ts';import { REVISION_BACKFILL_MAX_ATTEMPTS, REVISION_BACKFILL_STATE_KEY } from '../src/core/page-state/revision-backfill-schema.ts';-import { resolveRepairScope } from '../src/core/repair/core.ts';+import { renderRepairResult } from '../src/commands/repair.ts';+import { resolveRepairScope, type RepairResult } from '../src/core/repair/core.ts';import { repairRunner } from '../src/core/repair/registry.ts';import { managedBrain, settleManagedGitEffects } from './helpers/managed-brain.ts';import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';@@ -184,4 +185,18 @@ describe('GST-1555 reconcile field refusals name the fields', () => {const refusal = (() => { try { strictReconcileKeys({ path: '/title', extra: 1 }, ['path', 'action'], ['path', 'action']); } catch (error) { return error; } })() as { code: string; why: string };expect(refusal).toMatchObject({ code: 'invalid_params', why: 'unsupported: extra; missing: action' });});++ test('the text output prints each row\'s fix with its consent, and never the fix as a detail value', () => {+ const text = renderRepairResult({ kind: 'file-drift', mode: 'apply', affected: 1, sample: [], residuals: {}, scope: { kind: 'all' },+ cost: { lifetime_ids: 0, receipt_bytes: 0, embedding_pages: 0, embedding_usd: null }, capacity: [], resumed_from: null, applied: 0, skipped: 0, failed: [],+ complete: true, apply_command: 'gbrain repair file-drift --source default --slug notes/alpha --apply',+ listing: [{ item: 'default:notes/alpha', class: 'refused', detail: 'invalid_params: example', fix: { argv: ['gbrain', 'doctor', '--json'], consent: [], actor: 'agent', why: 'example', requires_exclusive: false } }],+ outcomes: { changed_since_preview: 1 },+ outcome_items: [{ item: 'default:notes/alpha', outcome: 'changed_since_preview', detail: { request_id: 'example',+ fix: { argv: ['gbrain', 'repair', 'file-drift', '--source', 'default', '--slug', 'notes/alpha', '--prefer', 'file'], consent: ['destructive'], actor: 'agent', why: 'example', requires_exclusive: false } } }],+ } as unknown as RepairResult);+ expect(text).toContain(' fix: gbrain doctor --json\n');+ expect(text).toContain(' fix: gbrain repair file-drift --source default --slug notes/alpha --prefer file (asks the user first: destructive)');+ expect(text).not.toContain('fix=');+ });});