Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(repair): restore the repair command tail the merge resolution dropped

garrytana65653759042
diff --git a/src/commands/repair.ts b/src/commands/repair.ts
index ee56da7664..b64888ccd3 100644
--- a/src/commands/repair.ts
+++ b/src/commands/repair.ts
@@ -429,4 +429,49 @@ export async function runRepairCommand(engine: BrainEngine, args: string[]): Pro
} else {
console.log(`Scope: brain ${scope.brain_id}; sources ${scope.source_ids.join(', ') || '(none)'}`);
for (const result of results) console.log(renderRepairResult(result, { diff }));
- const embedKinds = results.filter(r => repairMayEmbed(repairSpec(r.kind), noEmbed)).map(r => r.kind);
\ No newline at end of file
+ const embedKinds = results.filter(r => repairMayEmbed(repairSpec(r.kind), noEmbed)).map(r => r.kind);
+ if (!apply && embedKinds.length) console.log(`Kinds that may queue paid embeddings: ${embedKinds.join(', ')} (pass --no-embed to skip; `
+ + 'page-write kinds are re-embedded by their publication either way; cap spend with gbrain doctor --remediate --yes --include-repairs --max-usd <n> --expect <plan_hash> from gbrain doctor --remediation-plan --json).');
+ const llmResults = results.filter(r => r.cost.llm_usd !== undefined);
+ if (!apply && llmResults.length) {
+ const usd = llmResults.some(r => r.cost.llm_usd === null) ? null : llmResults.reduce((sum, r) => sum + (r.cost.llm_usd ?? 0), 0);
+ const left = llmResults.map(r => r.cost.llm_cap_remaining_usd).filter((cap): cap is number => typeof cap === 'number');
+ console.log(`Kinds that may call a paid model: ${llmResults.map(r => r.kind).join(', ')} (${usd === null ? 'estimate unavailable: the model is unpriced' : `estimated $${usd.toFixed(4)}`}`
+ + `${left.length ? `; $${Math.min(...left).toFixed(4)} left under today's cap` : ''}).`);
+ }
+ if (explicitKindsNotRun.length) console.log(`Explicit-only kinds (not run without their name; preview each): ${explicitKindsNotRun.map(n => n.preview_command).join('; ')}`);
+ }
+ if (repairExitVerdict(results) !== 0) setCliExitVerdict(1);
+}
+
+/**
+ * Runs each kind in order; a kind that stops (capacity, a held writer, a pending write) ends the loop. A kind whose plan
+ * or apply throws item-scoped (GBRA-130 A-45) is reported as a result stopped with reason `error` and the loop goes on;
+ * a run-scoped error, or most kinds failing (`item_failures_systemic`), stops the command. `named`: the operator named
+ * one kind, whose error is the command's error. `registry`: the kinds' specs (tests pass stubs).
+ */
+export async function runRepairKinds(kinds: readonly RepairKind[], scope: RepairScope, opts: { apply: boolean; source?: string; noEmbed: boolean; named: boolean; registry?: readonly RepairKindSpec[] },
+ run: (kind: RepairKind) => Promise<RepairResult>): Promise<Array<RepairResult & { paid: boolean }>> {
+ const results: Array<RepairResult & { paid: boolean }> = [];
+ const kindRun = new ItemRun('repair.all_kinds');
+ for (const k of kinds) {
+ let result: RepairResult;
+ try {
+ result = await run(k);
+ kindRun.succeed();
+ } catch (error) {
+ if (opts.named) throw error;
+ kindRun.fail(k, error);
+ results.push({ ...kindErrorResult(k, scope, { apply: opts.apply, error, source: opts.source }), paid: false });
+ continue;
+ }
+ results.push({ ...result, paid: repairMaySpend(repairSpec(k, opts.registry), opts.noEmbed) });
+ if (result.stopped) break;
+ }
+ return results;
+}
+
+/** Exit 1 when any kind stopped early or refused an item; 0 only when every pending item was attempted and applied or skipped. */
+export function repairExitVerdict(results: ReadonlyArray<Pick<RepairResult, 'stopped' | 'failed'>>): 0 | 1 {
+ return results.some(r => r.stopped || r.failed.length > 0) ? 1 : 0;
+}