Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(cli): agent run scans exactly where parseRunFlags reads flags
garrytan79cb0c0d5dab
diff --git a/src/cli/flag-equals.ts b/src/cli/flag-equals.tsindex 0de7e4c642..322023b481 100644--- a/src/cli/flag-equals.ts+++ b/src/cli/flag-equals.ts@@ -35,9 +35,11 @@* the same way by jsonRequested). Refusals name `--flag=…`, never the value,* which may be a credential. A short flag never takes `=` (`-y=n` is refused,* never taken as consent); a quoted argument with whitespace that only starts- * like one (`capture "-n=3 is the answer"`) is text. `agent run` stops the- * scan where parseRunFlags starts the prompt (the first word that is not a- * flag or a flag's value). OWN_EQUALS_PARSERS pass their argv through. On a+ * like one (`capture "-n=3 is the answer"`) is text. `agent run` scans only+ * where parseRunFlags reads flags: the leading flag zone (up to the first word+ * that is not one of its flags or a value flag's value) and, when the prompt+ * holds no bare `--`, the trailing switches it hoists (`--detach=true` there+ * refuses); the prompt between them is text. OWN_EQUALS_PARSERS pass their argv through. On a* command with a registry row, unregistered flags keep the token for the* validator to name; on a path with none (the hand-parsed search* subcommands), every `=` token but `--json=true` refuses with a neutral@@ -257,10 +259,18 @@ export async function splitFlagEquals(command: string, args: readonly string[]):const out: string[] = [];const where = args[0] && !args[0].startsWith('-') ? `gbrain ${command} ${args[0]}` : `gbrain ${command}`;let pastDashDash = false;+ let promptAt = -1;+ let tailAt = args.length;+ if (command === 'agent' && args[0] === 'run') {+ const { RUN_VALUE_FLAGS, BOOLEAN_TAIL_FLAGS } = await import('../commands/agent.ts');+ promptAt = 1;+ while (promptAt < args.length && args[promptAt] !== '--' && (/^--[^=]+=/.test(args[promptAt]!) || RUN_VALUE_FLAGS.has(args[promptAt]!) || BOOLEAN_TAIL_FLAGS.has(args[promptAt]!))) promptAt += RUN_VALUE_FLAGS.has(args[promptAt]!) ? 2 : 1;+ if (!args.slice(promptAt).includes('--')) while (tailAt > promptAt && BOOLEAN_TAIL_FLAGS.has(args[tailAt - 1]!.split('=')[0]!)) tailAt--;+ }for (let i = 0; i < args.length; i++) {const token = args[i]!;if (token === '--' && END_OF_OPTIONS.has(`${command} ${args[0]}`)) return { args: [...out, ...args.slice(i)] };- if (command === 'agent' && args[0] === 'run' && i >= 1 && !token.startsWith('--') && !/^--[^=]+$/.test(args[i - 1]!)) return { args: [...out, ...args.slice(i)] };+ if (i === promptAt && promptAt < tailAt) { out.push(...args.slice(i, tailAt)); i = tailAt - 1; continue; }pastDashDash ||= token === '--';const m = EQUALS_TOKEN.exec(token);const flag = m?.[1];diff --git a/src/commands/agent.ts b/src/commands/agent.tsindex 78caa84a02..e6cc60a931 100644--- a/src/commands/agent.ts+++ b/src/commands/agent.ts@@ -154,7 +154,10 @@ interface RunFlags {}/** No-value switches that may also trail the prompt and get hoisted out (#1738). */-const BOOLEAN_TAIL_FLAGS = new Set(['--follow', '--no-follow', '--detach']);+export const BOOLEAN_TAIL_FLAGS = new Set(['--follow', '--no-follow', '--detach']);++/** Flags parseRunFlags reads with their value in the next argument (the CLI entry's = scan reads the flag zone through this). */+export const RUN_VALUE_FLAGS = new Set(['--subagent-def', '--model', '--max-turns', '--tools', '--timeout-ms', '--source', '--fanout-manifest']);function applyBooleanFlag(flags: RunFlags, a: string): void {if (a === '--follow') flags.follow = true;diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.tsindex 5450106e72..10537adaa3 100644--- a/test/cli-flag-equals.test.ts+++ b/test/cli-flag-equals.test.ts@@ -528,13 +528,21 @@ describe('#7619 refusals that keep consent, scope and targets right', () => {}});- // Value: protects=free text that only looks like an = flag reaches the handler (capture text, the agent run prompt), while the flag zone still refuses; fails_when=the scan reads quoted text or the prompt as flags, or stops before the flag zone ends; why_new=the short-flag and prompt rows only covered refusals; seam=none; no_claim=agent run's own parse after the gate (argv-level)+ // Value: protects=free text that only looks like an = flag reaches the handler (capture text, the agent run prompt), while the flag zone and the trailing switches agent run hoists still refuse; fails_when=the scan reads quoted text or the prompt as flags, or skips the flag zone or the hoisted trailing switches; why_new=the short-flag and prompt rows only covered refusals; seam=none; no_claim=agent run's own parse after the gate (argv-level)test('free text that only looks like an = flag is not scanned', async () => {expect(await argvFor('capture', ['-n=3 is the answer'])).toEqual(['-n=3 is the answer']);expect(await argvFor('agent', ['run', 'fix', 'the', '--model=opus', 'bug'])).toEqual(['run', 'fix', 'the', '--model=opus', 'bug']);expect(await argvFor('agent', ['run', '--model', 'opus', 'fix', '--tools=x'])).toEqual(['run', '--model', 'opus', 'fix', '--tools=x']);expect(await refusalFor('agent', ['run', '--model=opus', 'fix'])).toContain('--model=…');expect(await refusalFor('agent', ['run', '--detach', '--tools=x', 'fix'])).toContain('--tools=…');+ for (const args of [['run', '--detach', 'fix', '--model=opus'], ['run', '--follow', 'summarize', '--tools=bash'], ['run', '--detach', '-n=3'], ['run', '--note', '--tools=x'], ['run', 'fix', '--', '--detach=true'], ['run', '--', '--model=opus', 'fix']]) {+ expect(await argvFor('agent', args)).toEqual(args);+ }+ for (const [args, flag] of [[['run', 'summarize the page', '--detach=true'], '--detach'], [['run', 'fix', '--detach', '--no-follow=1'], '--no-follow'], [['run', 'fix', '--follow=false', '--detach'], '--follow']] as const) {+ const message = await refusalFor('agent', [...args]);+ expect(message).toContain(`${flag}=…`);+ expect(message).toMatch(new RegExp(`${flag} is a switch|write ${flag} on its own`));+ }});test('the hand-parsed search subcommands refuse an = form without vouching for the flag', async () => {