Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(upgrade): supervisor restart keeps global = flags (parseGlobalFlags) and pins the kept readers to EQUALS_READERS; narrow directEntryArgs docstring to auth; equalsExempt comment notes the jobs submit consent readers
garrytan90a2994b51d3
diff --git a/src/cli/flag-equals.ts b/src/cli/flag-equals.tsindex 951bd3293a..a0bdef86da 100644--- a/src/cli/flag-equals.ts+++ b/src/cli/flag-equals.ts@@ -302,7 +302,7 @@ export function findUnknownFlag(args: string[], legal: ReadonlySet<string>): strreturn null;}-/** A command module's direct `bun run` entry, in main's order: global flags stripped and applied, the `=` rule (own `=` parsers pass through), and main's unknown-flag check with its envelope (legacy keys included). */+/** auth.ts's direct `bun run` entry, in main's order: global flags stripped and applied, the `=` rule (`command sub` own `=` parsers pass through; auth has no whole-command own parser, strict spec or exempt path), and main's unknown-flag check with its envelope (legacy keys included). */export async function directEntryArgs(command: string, raw: string[]): Promise<{ args: string[] } | { refusal: OperationError; legacy?: Record<string, string> }> {const { cliOpts, rest } = parseGlobalFlags(raw);setCliOptions(cliOpts);diff --git a/src/cli/main.ts b/src/cli/main.tsindex 247f7e97d1..3793f65d96 100755--- a/src/cli/main.ts+++ b/src/cli/main.ts@@ -1335,7 +1335,7 @@ export async function cliOnlyFlagArgs(command: string, subArgs: string[]): Promireturn splitFlagEquals(command, subArgs);}-/** call and config set take arbitrary values, and eval brainbench refuses unknown tokens with its own exit code; every other validation-exempt path (jobs submit, config get and unset) reads exact tokens. */+/** call and config set take arbitrary values, and eval brainbench refuses unknown tokens with its own exit code; every other validation-exempt path (jobs submit, config get and unset) reads exact tokens, apart from the consent values EQUALS_READERS keeps for jobs submit. */function equalsExempt(command: string, subArgs: string[]): boolean {return command === 'call' || command === 'config' && subArgs[0] === 'set' || command === 'eval' && subArgs[0] === 'brainbench';}diff --git a/src/core/upgrade-restart.ts b/src/core/upgrade-restart.tsindex 5768b712ea..8194d8e5bf 100644--- a/src/core/upgrade-restart.ts+++ b/src/core/upgrade-restart.ts@@ -32,6 +32,7 @@* warm CLI socket, when serve had one, accepts this build.*/import { basename, resolve } from 'node:path';+import { parseGlobalFlags } from './cli-options.ts';export type ProcessRole = 'serve' | 'autopilot' | 'supervisor' | 'worker' | 'mcp' | 'sync';@@ -205,10 +206,12 @@ const label = (p: Pick<HostProcess, 'role' | 'pid' | 'version'>) => `${p.role} p/*** The supervisor's stop and start commands from the arguments it runs with, so the restart keeps its queue, concurrency and PID file.- * A `--flag=value` token other than --job-isolation was ignored by the supervisor that holds it (an older release) and is refused by this one, so it is dropped: the restart runs what the supervisor applied.+ * A `--flag=value` token that is neither a global flag nor --job-isolation was ignored by the supervisor that holds it (an older release) and is refused by this one, so it is dropped: the restart runs what the supervisor applied.*/export function supervisorRestartArgv(args: readonly string[]): { stop: string[]; start: string[]; pid_file: string | null } {- const rest = args.slice(args.indexOf('supervisor') + 1).filter(arg => arg !== 'start' && arg !== '--detach' && arg !== '--json' && !(/^--[^=]+=/.test(arg) && !arg.startsWith('--job-isolation=')));+ let local: ReadonlySet<string> = new Set();+ try { local = new Set(parseGlobalFlags([...args]).rest); } catch { /* an unparseable global flag: keep every token, as before */ }+ const rest = args.slice(args.indexOf('supervisor') + 1).filter(arg => arg !== 'start' && arg !== '--detach' && arg !== '--json' && !(/^--[^=]+=/.test(arg) && local.has(arg) && !arg.startsWith('--job-isolation=')));const at = rest.indexOf('--pid-file');const pidFile = at === -1 ? null : rest[at + 1] ?? null;return {diff --git a/test/cli-flag-equals.test.ts b/test/cli-flag-equals.test.tsindex 21f3a42959..9c1d9ccd1b 100644--- a/test/cli-flag-equals.test.ts+++ b/test/cli-flag-equals.test.ts@@ -12,7 +12,7 @@ import { readFileSync } from 'node:fs';import { Glob } from 'bun';import { CLI_ONLY, cliOnlyFlagArgs, validateCommandFlags } from '../src/cli/main.ts';import { CLI_FLAG_REGISTRY } from '../src/core/cli-flag-registry.generated.ts';-import { COMMAND_VALUES, END_OF_OPTIONS, EQUALS_READERS, OWN_EQUALS_PARSERS, directEntryArgs, findUnknownFlag, knownSwitches } from '../src/cli/flag-equals.ts';+import { COMMAND_VALUES, END_OF_OPTIONS, EQUALS_READERS, OWN_EQUALS_PARSERS, directEntryArgs, findUnknownFlag, knownSwitches, splitFlagEquals } from '../src/cli/flag-equals.ts';import { CLI_COMMANDS } from '../src/cli/command-table.ts';import { SEARCH_SUBCOMMANDS } from '../src/cli/subcommands.ts';import { SYNC_FLAGS } from '../src/core/sync-flags.ts';@@ -31,7 +31,6 @@ import { parseGoogleAttachmentsArgs } from '../src/commands/google-attachments.timport { parseGraduationArgs, routesToGraduation } from '../src/commands/migrate-graduation.ts';import type { GBrainConfig } from '../src/core/config.ts';import { parseAppendArgs } from '../src/cli/commands/append.ts';-import { splitFlagEquals } from '../src/cli/flag-equals.ts';const PASSTHROUGH = new Set(['call', 'retrieval-upgrade']);diff --git a/test/upgrade-restart.test.ts b/test/upgrade-restart.test.tsindex 7c1a29374b..ad3fbba037 100644--- a/test/upgrade-restart.test.ts+++ b/test/upgrade-restart.test.ts@@ -6,6 +6,8 @@* heartbeat rows, the service managers and the socket.*/import { describe, expect, test } from 'bun:test';+import { EQUALS_READERS } from '../src/cli/flag-equals.ts';+import { parseGlobalFlags } from '../src/core/cli-options.ts';import {bunGlobalCopyOf, classifyGbrainCommand, collectHostProcesses, mismatchedBuilds, planRestart, restartProblems, runRestartSteps, supervisorRestartArgv, unverifiedBuilds, verifyRestart,type HostProcess, type ProcessSources, type RestartContext, type RestartExecutor, type WarmSocketState,@@ -72,6 +74,13 @@ describe('supervisorRestartArgv', () => {pid_file: null,});});++ test('keeps the global flags and every = value the supervisor applied', () => {+ const argv = ['jobs', 'supervisor', 'start', '--brain=work', '--timeout=30s', '--queue', 'ingest', '--progress-interval=500'];+ expect(parseGlobalFlags([...argv]).cliOpts.brain).toBe('work');+ expect(supervisorRestartArgv(argv).start).toEqual(['gbrain', 'jobs', 'supervisor', 'start', '--detach', '--brain=work', '--timeout=30s', '--queue', 'ingest', '--progress-interval=500', '--json']);+ for (const flag of EQUALS_READERS['jobs supervisor'] ?? []) expect(supervisorRestartArgv(['jobs', 'supervisor', 'start', `${flag}=x`]).start).toContain(`${flag}=x`);+ });});describe('collectHostProcesses', () => {