Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(review): accept-all never confirms a flagged page; it is listed as skipped with its own trust confirm (#7116)

garrytan58cd22704bf2
diff --git a/src/commands/trust.ts b/src/commands/trust.ts
index 7e44f3dcde..1493f8b4b0 100644
--- a/src/commands/trust.ts
+++ b/src/commands/trust.ts
@@ -42,7 +42,8 @@ export const TRUST_OWNER_USAGE = [
' preferences (f<id>), held writes (h<id>), agent pages flagged as instructions (p:<source>/<slug>) and your',
' allow rules (a<id>), grouped by day and page, each with its exact commands.',
' review --accept-all (--from <source> | --kind <kind> | --since <when>)...',
- ' Accept every listed item matching the filters (at least one filter) after one typed confirmation.',
+ ' Accept every listed item matching the filters (at least one filter) after one typed confirmation. A flagged',
+ ' page is never included: read it, then run trust confirm on it.',
' confirm <f<id>|t<id>|p:<source>/<slug>|tp<id>|h<id>> [--source <id>]',
' Mark it "confirmed by you" (accepts a proposal; releases a held write). Asks you to type its token.',
' release <h<id>> Release a held write into memory as "confirmed by you" (asks for its token).',
@@ -151,8 +152,9 @@ function resultLine(r: OwnerActionResult): string {
const ACCEPT_ALL_ITEM_MAX = 1_000;
/**
- * DX-15: accept every matching item after one typed confirmation. An item whose preview fails, or whose summary is too
- * long to show in one list, is listed as skipped: it is not in the confirmation and is never applied (#7820).
+ * DX-15: accept every matching item after one typed confirmation. An item whose preview fails, whose summary is too
+ * long to show in one list, or that is a flagged page (its preview names the page, not the flagged text) is listed as
+ * skipped: it is not in the confirmation and is never applied (#7820, #7116).
*/
async function acceptAll(backend: TrustBackend, args: string[], json: boolean): Promise<void> {
const filter = reviewFilter(args);
@@ -162,26 +164,28 @@ async function acceptAll(backend: TrustBackend, args: string[], json: boolean):
}
const review = await backend.review(filter);
// A contradiction has no single accept: each of its commands decides it differently, so --accept-all leaves it for the owner.
- const skipped = review.items.filter(item => item.kind === 'contradiction')
+ const contradictions = review.items.filter(item => item.kind === 'contradiction')
.map(item => ({ ref: item.ref, reason: 'contradiction', next: 'Decide it with one of its commands: gbrain trust review --kind contradiction' }));
- const inputs = review.items.filter(item => item.kind !== 'contradiction')
+ const flagged = review.items.filter(item => item.kind === 'flagged_page').map(item => ({ ref: item.ref, reason: 'confirm_on_its_own', next: `gbrain trust confirm ${item.ref}` }));
+ const inputs = review.items.filter(item => item.kind !== 'contradiction' && item.kind !== 'flagged_page')
.map(item => ({ action: item.kind === 'hold' ? 'release' : 'confirm', ref: item.ref, source: item.source_id } as OwnerActionInput));
- const skipLines = () => { for (const s of skipped) console.log(`${s.ref}: skipped (a contradiction; ${s.next})`); };
- if (inputs.length === 0) {
- if (json) await writeStdoutFinal(`${JSON.stringify({ accepted: [], skipped }, null, 2)}\n`); else if (skipped.length) skipLines(); else console.log('Nothing matches those filters.');
+ const skipLines = () => { for (const s of contradictions) console.log(`${s.ref}: skipped (a contradiction; ${s.next})`); };
+ if (inputs.length === 0 && flagged.length === 0) {
+ if (json) await writeStdoutFinal(`${JSON.stringify({ accepted: [], skipped: contradictions }, null, 2)}\n`); else if (contradictions.length) skipLines(); else console.log('Nothing matches those filters.');
return;
}
const settled = await Promise.allSettled(inputs.map(input => backend.preview(input)));
- const skipped = settled.flatMap((s, i) => {
+ const skipped = [...flagged, ...settled.flatMap((s, i) => {
const next = `gbrain trust ${inputs[i]!.action} ${inputs[i]!.ref}`;
if (s.status === 'rejected') return [{ ref: inputs[i]!.ref!, reason: 'preview_failed', error: s.reason instanceof OperationError ? s.reason.toJSON() : String(s.reason), next }];
return s.value.summary.length > ACCEPT_ALL_ITEM_MAX ? [{ ref: inputs[i]!.ref!, reason: 'summary_too_long', next }] : [];
- });
+ })];
const previewed = settled.flatMap((s, i) => s.status === 'fulfilled' && s.value.summary.length <= ACCEPT_ALL_ITEM_MAX ? [{ input: inputs[i]!, preview: s.value }] : []);
const previews = previewed.map(p => p.preview);
const command = ['gbrain', 'trust', 'review', '--accept-all', ...args.filter(a => a !== '--accept-all' && a !== '--json')];
const token = `all-${createHash('sha256').update(previews.map(p => `${p.ref}:${p.binding}`).join('\n')).digest('hex').slice(0, 8)}`;
- const why = (reason: string) => reason === 'preview_failed' ? 'its preview failed' : 'it is too long to confirm in one list';
+ const why = (reason: string) => reason === 'preview_failed' ? 'its preview failed'
+ : reason === 'confirm_on_its_own' ? 'a page flagged as instructions is confirmed only after you read it' : 'it is too long to confirm in one list';
const summary = [`Accept ${previews.length} item(s):`, ...previews.map(p => ` ${p.ref.padEnd(6)} ${p.summary}`),
...skipped.map(s => ` ${s.ref.padEnd(6)} skipped: ${why(s.reason)}, so it is not accepted (run ${s.next} on its own)`)].join('\n');
if (previews.length) await requireOwnerConfirmation(LOCAL_CTX, { ref: `${previews.length} items`, token, summary, command });
@@ -199,7 +203,7 @@ async function acceptAll(backend: TrustBackend, args: string[], json: boolean):
else failed.push({ ref: preview.ref, error: error instanceof OperationError ? error.toJSON() : String(error) });
}
}
- if (json) await writeStdoutFinal(`${JSON.stringify({ accepted, pending, failed, skipped }, null, 2)}\n`);
+ if (json) await writeStdoutFinal(`${JSON.stringify({ accepted, pending, failed, skipped: [...contradictions, ...skipped] }, null, 2)}\n`);
else {
skipLines();
for (const r of accepted) console.log(resultLine(r));
diff --git a/test/fixtures/goldens/trust/help.txt b/test/fixtures/goldens/trust/help.txt
index 40380e6417..9a8bf1d5f5 100644
--- a/test/fixtures/goldens/trust/help.txt
+++ b/test/fixtures/goldens/trust/help.txt
@@ -4,7 +4,8 @@ Usage: gbrain trust <review|confirm|release|drop|revert|explain|allow|disable|ba
preferences (f<id>), held writes (h<id>), agent pages flagged as instructions (p:<source>/<slug>) and your
allow rules (a<id>), grouped by day and page, each with its exact commands.
review --accept-all (--from <source> | --kind <kind> | --since <when>)...
- Accept every listed item matching the filters (at least one filter) after one typed confirmation.
+ Accept every listed item matching the filters (at least one filter) after one typed confirmation. A flagged
+ page is never included: read it, then run trust confirm on it.
confirm <f<id>|t<id>|p:<source>/<slug>|tp<id>|h<id>> [--source <id>]
Mark it "confirmed by you" (accepts a proposal; releases a held write). Asks you to type its token.
release <h<id>> Release a held write into memory as "confirmed by you" (asks for its token).
diff --git a/test/trust-owner-actions.test.ts b/test/trust-owner-actions.test.ts
index 9f9c2ed07f..4cb83a357e 100644
--- a/test/trust-owner-actions.test.ts
+++ b/test/trust-owner-actions.test.ts
@@ -461,10 +461,11 @@ describe('review, explain and accept-all (CEO-2, DX-10, DX-15, DX-16)', () => {
}), 60_000);
// Value: protects=an agent-written page the write gate flagged as an instruction (withheld from proactive surfaces
- // until confirmed) is listed by trust review and confirmed by one accept-all; a lowered page is not listed twice;
+ // until confirmed) is listed by trust review and confirmed on its own, never by accept-all, whose preview shows only
+ // its ref; a lowered page is not listed twice;
// fails_when=review reads only proposals, preferences and holds (#7116: the page needs its own trust confirm);
// why_new=the other review tests flag nothing; seam=none; no_claim=claim-pending legacy pages
- test('#7116: review lists an agent page the write gate flagged as an instruction, and accept-all confirms it', async () => withEnv({ GBRAIN_HOME: home }, async () => {
+ test('#7116: review lists an agent page the write gate flagged as an instruction; accept-all skips it and trust confirm raises it', async () => withEnv({ GBRAIN_HOME: home }, async () => {
for (const engine of engines) {
const b = await brain(engine);
const other = await brain(engine);
@@ -488,10 +489,18 @@ describe('review, explain and accept-all (CEO-2, DX-10, DX-15, DX-16)', () => {
const io = typesToken();
const original = console.log;
- console.log = () => {};
- try { await runTrustOwnerCommand(localTrustBackend(engine), 'review', ['--accept-all', '--from', b.sourceId, '--kind', 'flagged_page']); }
- finally { console.log = original; }
+ const out: string[] = [];
+ console.log = (line: unknown) => { out.push(String(line)); };
+ let code: number | undefined;
+ try { await runTrustOwnerCommand(localTrustBackend(engine), 'review', ['--accept-all', '--from', b.sourceId]); code = currentExitCode(); }
+ finally { console.log = original; process.exitCode = 0; _resetCliExitVerdictForTests(); }
expect(io.prompt()).toContain('Accept 1 item(s)');
+ expect(io.prompt()).toContain(`${ref} skipped: a page flagged as instructions is confirmed only after you read it`);
+ expect(out).toContain(`${ref}: skipped, a page flagged as instructions is confirmed only after you read it; run gbrain trust confirm ${ref} on its own`);
+ expect(code).toBe(1);
+ expect((await pageRow(b, 'notes/flagged-a-example')).trust_tier).toBe('agent_written');
+ typesToken();
+ await ownerDo(b, { action: 'confirm', ref });
expect((await pageRow(b, 'notes/flagged-a-example')).trust_tier).toBe('user_confirmed');
expect((await buildTrustReview(engine, { sourceId: b.sourceId, kind: 'flagged_page' })).items).toEqual([]);
expect((await buildTrustReview(engine, { sourceId: other.sourceId })).items.map(i => i.ref)).toEqual([`p:${other.sourceId}/notes/flagged-a-example`]);