Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(book-mirror): paid fan-out asks through requireConsent; the raw stdin prompt is gone (C2, C5)
garrytanfa85bafeb14d
diff --git a/scripts/agent-contract-baselines/interactive-io.tsv b/scripts/agent-contract-baselines/interactive-io.tsvindex c4a6b63a34..6c297e6e28 100644--- a/scripts/agent-contract-baselines/interactive-io.tsv+++ b/scripts/agent-contract-baselines/interactive-io.tsv@@ -1,5 +1,4 @@# shrink-only baseline for scripts/check-agent-contract.ts rule interactive-io: path<TAB>count-src/commands/book-mirror.ts 1src/commands/capture.ts 1src/commands/connectors/auth.ts 1src/commands/hook.ts 3diff --git a/src/commands/book-mirror.ts b/src/commands/book-mirror.tsindex 97aaf11f74..a17232a860 100644--- a/src/commands/book-mirror.ts+++ b/src/commands/book-mirror.ts@@ -51,6 +51,7 @@ import type { MinionJobInput, SubagentHandlerData } from '../core/minions/types.import { operations } from '../core/operations.ts';import { loadConfig } from '../core/config.ts';import { getCliOptions } from '../core/cli-options.ts';+import { consentGateOrExit, engineConsentEnv } from '../core/consent-cli.ts';const COST_PER_CHAPTER_OPUS = 0.30; // rough; depends on chapter lengthconst COST_PER_CHAPTER_SONNET = 0.06;@@ -147,7 +148,8 @@ OPTIONALright-column quality drops.--max-turns <n> Per-chapter subagent turn budget. Default ${DEFAULT_MAX_TURNS}.--timeout-ms <n> Per-chapter wall-clock timeout.- --no-confirm / --yes Skip the cost-estimate confirmation prompt.+ --yes / --no-confirm The user's approval of the printed estimate; without it a+ non-interactive run submits nothing and exits 3.--no-follow Submit and exit; don't tail children.--dry-run Validate inputs + print plan; submit nothing.@@ -220,30 +222,6 @@ function estimateCost(chapters: ChapterEntry[], model: string): number {return chapters.length * perChapter;}-async function confirmInteractive(estimateUsd: number, chapters: number): Promise<boolean> {- if (process.stdin.isTTY !== true) {- // Non-TTY: refuse to spend without an explicit --yes / --no-confirm.- process.stderr.write(- `gbrain book-mirror: refusing to spend ~$${estimateUsd.toFixed(2)} on ${chapters} chapters from a non-TTY context. ` +- `Pass --yes to confirm.\n`- );- return false;- }- process.stderr.write(- `\nThis will spawn ${chapters} subagent jobs at ~$${(estimateUsd / chapters).toFixed(2)} each = ~$${estimateUsd.toFixed(2)} total.\n` +- `Continue? [y/N] `- );- return new Promise(resolve => {- process.stdin.setEncoding('utf8');- process.stdin.once('data', (chunk) => {- const reply = chunk.toString().trim().toLowerCase();- resolve(reply === 'y' || reply === 'yes');- process.stdin.pause();- });- process.stdin.resume();- });-}-// ── prompt assembly ────────────────────────────────────────function buildChapterPrompt(@@ -431,13 +409,21 @@ export async function runBookMirrorCmd(engine: BrainEngine, args: string[]): Proreturn;}- if (!flags.noConfirm) {- const ok = await confirmInteractive(estimateUsd, chapters.length);- if (!ok) {- process.stderr.write(`gbrain book-mirror: cancelled by user.\n`);- process.exit(0);- }- }+ // A4: paid fan-out. --yes (or its legacy alias --no-confirm), --max-usd,+ // tokenmax or a per-run preapproval authorize it; otherwise a TTY prompt+ // (interaction.readLine: EOF/timeout = decline, never a hang) or exit 3+ // with the consent payload. Nothing is submitted before consent.+ await consentGateOrExit({+ command: 'book-mirror', effects: ['paid'], actor: 'agent',+ what: `Run ${chapters.length} chapter subagent(s) for ${targetSlug}`,+ why: `Writes a personalized two-column mirror of "${bookTitle}" from the brain's context, one ${flags.model} subagent per chapter.`,+ risk: `Spends about $${estimateUsd.toFixed(2)} (~$${(estimateUsd / chapters.length).toFixed(2)} per chapter) with the model provider. Subagents are read-only; the result is one new page.`,+ user_message: `Spend about $${estimateUsd.toFixed(2)} to mirror ${chapters.length} chapter(s) of "${bookTitle}" against your brain?`,+ argv: ['gbrain', 'book-mirror', ...args.filter(a => a !== '--yes' && a !== '--no-confirm')],+ preview_argv: ['gbrain', 'book-mirror', ...args.filter(a => a !== '--yes' && a !== '--no-confirm'), '--dry-run'],+ est_usd: estimateUsd,+ args: flags.noConfirm ? [...args, '--yes'] : args,+ }, { json: false, env: engineConsentEnv(engine) });const publish = await prepareBookMirrorPublication(engine, targetSlug);