Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(cli): #7619 ship review pass 2: neutral refusal on paths with no registry row (no value echo, no switch vouching), own-parser consent table, reverse reader-evidence pin
garrytan560e400f32a9
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 222117d3a9..34e2c2070b 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -76,7 +76,7 @@ test/claude-cli-recipe.test.ts claude-cli LanguageModel — output cap (#6424) 2test/claude-cli-recipe.test.ts claude-cli LanguageModel — text-only round trip 4 readFileSynctest/claude-cli-recipe.test.ts claude-cli LanguageModel — tool use 17 readFileSynctest/claude-cli-recipe.test.ts claude-cli recipe registration 2 readFileSync-test/cli-flag-equals.test.ts #7619 refusals that keep consent, scope and targets right 15 readFileSync,source-surface-helper+test/cli-flag-equals.test.ts #7619 refusals that keep consent, scope and targets right 17 readFileSync,source-surface-helpertest/cli-flag-equals.test.ts #7619 split rules 21 readFileSync,source-surface-helpertest/cli-force-exit-teardown-arming.test.ts cli.ts — disconnect hard-deadline armed at teardown entry, not before the op body 1 readFileSync,source-surface-helpertest/cli.test.ts BigInt-safe output normalization (#2450) 5 source-surface-helperdiff --git a/src/cli/flag-equals.ts b/src/cli/flag-equals.tsindex fd89fb5c18..c6684b09f2 100644--- a/src/cli/flag-equals.ts+++ b/src/cli/flag-equals.ts@@ -229,6 +229,7 @@ export async function splitFlagEquals(command: string, args: readonly string[]):const readers = [...EQUALS_READERS[command] ?? [], ...EQUALS_READERS[`${command} ${args[0]}`] ?? []];let types: Map<string, string> | undefined;const out: string[] = [];+ const where = args[0] && !args[0].startsWith('-') ? `gbrain ${command} ${args[0]}` : `gbrain ${command}`;let pastDashDash = false;for (let i = 0; i < args.length; i++) {const token = args[i]!;@@ -248,14 +249,14 @@ export async function splitFlagEquals(command: string, args: readonly string[]):types ??= new Map((await loadCuratedHelp(command))?.flags.map(f => [f.name, f.type]));const own = types.get(flag) ?? (command === 'sync' ? (SYNC_FLAGS as Record<string, { arity: string }>)[flag]?.arity : undefined);const isSwitch = own !== undefined ? own === 'boolean' : flag.startsWith('--no-') || COMMAND_SWITCHES[command]?.includes(flag) || (await knownSwitches()).has(flag);- const refusal = isSwitch+ const refusal = !legal+ ? [`${where} reads no = form`, `Check the flag in ${where} --help: write a switch on its own (a value never turns it off), or a value as the next argument.`]+ : isSwitch? [`${flag} is a switch and takes no value`, `Write ${flag} on its own, or leave it out.`]: value === '' || /^-[-A-Za-z]/.test(value)? [`the value is empty or looks like a flag`, `Write ${flag} <value> with the value as the next argument.`]: own === undefined && /^(true|false|yes|no|y|n|on|off|0|1)$/i.test(value)? [`write ${flag} on its own if it is a switch, or with its value as the next argument`, `If ${flag} is a switch, write it on its own to turn it on, or leave it out to turn it off: a value never turns it off. If it takes a value, put the value in the next argument.`]- : !legal- ? [`gbrain ${command} ${args[0]} reads no = form`, `Check the flag in gbrain ${command} ${args[0]} --help, then write its value as the next argument.`]: own === undefined? [`this command takes ${flag} <value> as two arguments`, `Write ${flag} <value>, or ${flag} on its own if it is a switch.`]: null;diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.tsindex 403bb48bc1..61ffdc3bc3 100644--- a/test/cli-flag-equals.test.ts+++ b/test/cli-flag-equals.test.ts@@ -22,6 +22,13 @@ import { loadCuratedHelp } from '../src/cli/help/render.ts';import { parseAccessFlag, parseSurfaceFlag } from '../src/mcp/surface.ts';import { parseMovementArgs } from '../src/commands/sources-writer-movement.ts';import { parseAddTypeArgs } from '../src/commands/schema-add-type.ts';+import { parseRepairArgs } from '../src/commands/repair.ts';+import { parseTakesMutation } from '../src/commands/takes-mutation.ts';+import { parseReconcileArgs } from '../src/commands/source-reconcile.ts';+import { parseMigrateEmbeddingsFlags } from '../src/core/embedding-migration-cli.ts';+import { parseGoogleAttachmentsArgs } from '../src/commands/google-attachments.ts';+import { parseAppendArgs } from '../src/cli/commands/append.ts';+import { splitFlagEquals } from '../src/cli/flag-equals.ts';const PASSTHROUGH = new Set(['call', 'retrieval-upgrade']);@@ -416,7 +423,12 @@ describe('#7619 split rules', () => {const READER = [/['"`]--[a-z0-9-]+=/, /(?:startsWith|indexOf|===)\(?\s*`\$\{\w+\}=`/, /startsWith\(\w+ \+ '='\)/];const found = [...new Glob('src/**/*.ts').scanSync('.')].filter(p => !p.endsWith('.generated.ts') && READER.some(r => r.test(readFileSync(p, 'utf8'))));expect(found.filter(p => !(p in MODULE_OWNERS))).toEqual([]);- for (const p of Object.keys(MODULE_OWNERS)) expect(readFileSync(p, 'utf8').length).toBeGreaterThan(0);+ const EVIDENCE = [...READER, /\.indexOf\('='\)/, /`\$\{\w+\}=`/, /\(\?:=\(\.\*\)\)/, /\(=\|\$\)/, /\bparseListingFlags\(|\bextractDecideEvalFlags\(/];+ for (const [p, owner] of Object.entries(MODULE_OWNERS)) {+ const src = readFileSync(p, 'utf8');+ expect(src.length).toBeGreaterThan(0);+ if (Array.isArray(owner)) expect(EVIDENCE.some(r => r.test(src)) ? p : `${p}: no = reader evidence`).toBe(p);+ }const owned = new Set(Object.values(MODULE_OWNERS).filter(v => Array.isArray(v)).flat());expect([...owned].sort()).toEqual(Object.keys(EQUALS_READERS).sort());for (const [key, flags] of Object.entries(EQUALS_READERS)) for (const flag of flags) expect(CLI_FLAG_REGISTRY[key.split(' ')[0]!]).toContain(flag);@@ -489,10 +501,10 @@ describe('#7619 refusals that keep consent, scope and targets right', () => {});test('the hand-parsed search subcommands refuse an = form without vouching for the flag', async () => {- for (const [args, flag] of [[['modes', '--mdoe=balanced'], '--mdoe'], [['diagnose', 'q', '--target', 'x', '--source=source-a'], '--source']] as const) {+ for (const [args, flag] of [[['modes', '--mdoe=balanced'], '--mdoe'], [['diagnose', 'q', '--target', 'x', '--source=source-a'], '--source'], [['stats', '--yes=n'], '--yes'], [['modes', '--dry-run=x'], '--dry-run'], [['stats', '--no-thing=x'], '--no-thing']] as const) {const r = await cliOnlyFlagArgs('search', [...args]);expect('refusal' in r && r.refusal.message).toContain(`${flag}=…`);- expect('refusal' in r && r.refusal.message).not.toContain(`takes ${flag}`);+ expect('refusal' in r && r.refusal.message).toContain('reads no = form');expect('refusal' in r && r.refusal.suggestion).toContain(`gbrain search ${args[0]} --help`);}});@@ -546,6 +558,25 @@ describe('#7619 refusals that keep consent, scope and targets right', () => {expect(() => parseMovementArgs(['source-a', '--json=false'])).toThrow('--json is a switch');});+ test('own = parsers behind the gate refuse a value on consent and mutation switches', () => {+ const rows: [string, () => unknown][] = [+ ['repair --yes=n', () => parseRepairArgs(['file-drift', '--apply', '--yes=n'])],+ ['repair --apply=false', () => parseRepairArgs(['file-drift', '--apply=false'])],+ ['takes --force=false', () => parseTakesMutation(['add', 'people/alice-example', '--claim', 'x', '--force=false'])],+ ['reconcile --preview=false', () => parseReconcileArgs(['notes', '--preview=false'])],+ ['retrieval-upgrade --yes=true', () => parseMigrateEmbeddingsFlags(['--yes=true'], { route: 'retrieval-upgrade' })],+ ['retrieval-upgrade --dry-run=false', () => parseMigrateEmbeddingsFlags(['--dry-run=false'], { route: 'retrieval-upgrade' })],+ ['google attachments --yes=n', () => parseGoogleAttachmentsArgs(['backfill', '--source', 'default', '--yes=n'])],+ ['append --json=false', () => parseAppendArgs(['notes/a', '--json=false'])],+ ];+ for (const [label, run] of rows) expect(run, label).toThrow(/value|unknown flag/);+ });++ test('a command with no registry row never echoes an = value', async () => {+ const r = await splitFlagEquals('unregistered-example', ['--token=AbcSecretValue123']);+ expect(JSON.stringify(r)).not.toContain('AbcSecretValue123');+ });+test('OWN_EQUALS_PARSERS and the = option parsers match in both directions', () => {const OWNERS: Record<string, string | null> = {'src/commands/company-brain-connect.ts': 'sources connect', 'src/commands/company-brain-inspect.ts': 'sources inspect',