Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(cli): don't refuse free text that only looks like an = flag

garrytanb28a4492b192
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 5b09ddc3f3..24d800bb0b 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) 2
test/claude-cli-recipe.test.ts claude-cli LanguageModel — text-only round trip 4 readFileSync
test/claude-cli-recipe.test.ts claude-cli LanguageModel — tool use 17 readFileSync
test/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 23 readFileSync,source-surface-helper
+test/cli-flag-equals.test.ts #7619 refusals that keep consent, scope and targets right 24 readFileSync,source-surface-helper
test/cli-flag-equals.test.ts #7619 split rules 21 readFileSync,source-surface-helper
test/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-helper
test/cli.test.ts BigInt-safe output normalization (#2450) 5 source-surface-helper
diff --git a/src/cli/flag-equals.ts b/src/cli/flag-equals.ts
index 9dfef59082..0de7e4c642 100644
--- a/src/cli/flag-equals.ts
+++ b/src/cli/flag-equals.ts
@@ -34,7 +34,10 @@
* `--json=true` becomes `--json` (the agent contract's JSON spelling, read
* 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). OWN_EQUALS_PARSERS pass their argv through. On a
+ * 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
* 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 +260,11 @@ export async function splitFlagEquals(command: string, args: readonly string[]):
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)] };
pastDashDash ||= token === '--';
const m = EQUALS_TOKEN.exec(token);
const flag = m?.[1];
- if (flag !== undefined && !flag.startsWith('--')) {
+ if (flag !== undefined && !flag.startsWith('--') && !/\s/.test(token)) {
return { refusal: usageError(`gbrain ${command}: \`${flag}=…\`: a short flag takes no =.`, `Write ${flag} on its own, or ${flag} <value> with the value as the next argument.`) };
}
const registered = flag !== undefined && (!legal || legal.includes(flag) || flag.startsWith('--no-') && legal.includes(`--${flag.slice(5)}`));
diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.ts
index 61ed955498..5450106e72 100644
--- a/test/cli-flag-equals.test.ts
+++ b/test/cli-flag-equals.test.ts
@@ -528,6 +528,15 @@ 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)
+ 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=…');
+ });
+
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'], [['stats', '--yes=n'], '--yes'], [['modes', '--dry-run=x'], '--dry-run'], [['stats', '--no-thing=x'], '--no-thing']] as const) {
const r = await cliOnlyFlagArgs('search', [...args]);