Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(cli): keep cli-error.ts out of the command table's import closure (pglite-embedded compile check)

garrytan07f5180bbd62
diff --git a/src/cli.ts b/src/cli.ts
index 90ce532381..46a8313ab6 100755
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -465,8 +465,9 @@ async function main() {
// test/init-migrate-only.test.ts. D1/D3: exit 2 + did-you-mean.
const message = migrationError?.message ?? `unknown flag ${unknown} for 'gbrain ${command}'`;
const flagOp = cliOps.get(command) ?? cliAliases.get(command);
- const known = CLI_FLAG_REGISTRY[command] ?? Object.keys(flagOp?.params ?? {}).map(k => `--${k.replace(/_/g, '-')}`);
- exitCliError(await unknownFlagError(command, unknown, message, known), command, { legacy: { status: 'error', reason: 'invalid_flag', message } });
+ const curated = findCliCommand(command)?.help;
+ const known = curated ? (await curated()).help.flags.map(f => f.name) : CLI_FLAG_REGISTRY[command] ?? Object.keys(flagOp?.params ?? {}).map(k => `--${k.replace(/_/g, '-')}`);
+ exitCliError(unknownFlagError(command, unknown, message, known), command, { legacy: { status: 'error', reason: 'invalid_flag', message } });
}
}
diff --git a/src/cli/cli-error.ts b/src/cli/cli-error.ts
index 6e64272c0a..a169374253 100644
--- a/src/cli/cli-error.ts
+++ b/src/cli/cli-error.ts
@@ -22,7 +22,6 @@ import { redactUrlsInText } from '../core/url-redact.ts';
import { redactConnectionInfo } from '../core/audit/redact-connection-info.ts';
import { suggestNearest } from '../core/levenshtein.ts';
import { isConsentRefusal, printConsentRefusal } from '../core/consent.ts';
-import { findCliCommand } from './command-table.ts';
export interface CliErrorWriteOpts {
/** Raw argv (defaults to process.argv.slice(2)); decides `--json`. */
@@ -95,13 +94,12 @@ export function usageError(
}
/**
- * D3: `unknown_flag` with a did-you-mean drawn from the command's curated
- * help flags when it has a help module, else from `fallback` (the generated
- * acceptance registry / op params).
+ * D3: `unknown_flag` with a did-you-mean drawn from `candidates`: the
+ * command's curated help flags when it has a help module, else the generated
+ * acceptance registry / op params (the caller resolves them, so this module
+ * stays free of the command table's import closure).
*/
-export async function unknownFlagError(command: string, flag: string, message: string, fallback: readonly string[] = []): Promise<OperationError> {
- const help = findCliCommand(command)?.help;
- const candidates = help ? (await help()).help.flags.map(f => f.name) : fallback;
+export function unknownFlagError(command: string, flag: string, message: string, candidates: readonly string[] = []): OperationError {
const bare = flag.split('=')[0];
const nearest = suggestNearest(bare, candidates.filter(c => c !== bare));
const suggestion = nearest