Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(cli): eval <sub> --help prints the subcommand's own usage (D-N1)

time-attacka4278b406ad0
diff --git a/src/cli.ts b/src/cli.ts
index a8396d1fae..9128a92709 100755
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -2313,9 +2313,13 @@ async function routeEngineFreeHelp(command: string, args: string[]): Promise<boo
// takes-quality replay / whoknows) so each sub's own usage keeps winning;
// every remaining `eval … --help` form prints the full subcommand usage
// instead of the old one-line stub (or a "No brain configured" error).
+ // D-N1: a named subcommand (`eval replay --help`) gets its own usage. The
+ // sub always sees `--help` as its first argument, the form every sub's
+ // usage branch answers before it touches the engine.
if (command === 'eval' && (args.includes('--help') || args.includes('-h'))) {
- const { runEvalCommand } = await import('./commands/eval.ts');
- await runEvalCommand(null as never, ['--help']);
+ const sub = args[0] !== undefined && !args[0].startsWith('-') ? args[0] : undefined;
+ const { run } = await import('./cli/commands/eval.ts');
+ await run(null as never, sub ? [sub, '--help'] : ['--help']);
return true;
}
diff --git a/src/commands/eval-retrieval-quality.ts b/src/commands/eval-retrieval-quality.ts
index 85ac9a9868..31255b0070 100644
--- a/src/commands/eval-retrieval-quality.ts
+++ b/src/commands/eval-retrieval-quality.ts
@@ -24,7 +24,13 @@ import {
type SearchFn,
} from '../eval/retrieval-quality/harness.ts';
+const USAGE = 'Usage: gbrain eval retrieval-quality <fixture.jsonl> [--json] [--source <id>] [--ab-relational] [--decide <slot>=<off|on|shadow> ...] [--decide-provider <id>] [--decide-dataset <jsonl>]';
+
export async function runEvalRetrievalQuality(engine: BrainEngine, argv: string[]): Promise<void> {
+ if (argv.includes('--help') || argv.includes('-h')) {
+ console.log(USAGE);
+ return;
+ }
// System One arm (`--decide`): read-only on the connected brain (src/eval/decide-eval-flags.ts).
let args: string[];
let decideRun: DecideEvalRun | null;
@@ -47,7 +53,7 @@ export async function runEvalRetrievalQuality(engine: BrainEngine, argv: string[
const fixture = args.find(a => !a.startsWith('--') && a !== sourceId);
if (!fixture) {
- console.error('Usage: gbrain eval retrieval-quality <fixture.jsonl> [--json] [--source <id>] [--ab-relational] [--decide <slot>=<off|on|shadow> ...] [--decide-provider <id>] [--decide-dataset <jsonl>]');
+ console.error(USAGE);
process.exit(2);
}
diff --git a/test/cli-help-eval-subcommands.test.ts b/test/cli-help-eval-subcommands.test.ts
new file mode 100644
index 0000000000..5b0c20b432
--- /dev/null
+++ b/test/cli-help-eval-subcommands.test.ts
@@ -0,0 +1,62 @@
+/**
+ * D-N1 (fix wave 9) — `gbrain eval <sub> --help` must print that
+ * subcommand's own usage, not the generic `gbrain eval --qrels` block.
+ *
+ * The subcommand list is read from `gbrain eval --help` itself, so a new
+ * subcommand added to the eval usage block is covered without editing this
+ * file. Hermetic no-brain env: help must work before a brain exists.
+ */
+
+import { describe, test, expect } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { join } from 'node:path';
+
+const CLI_ENTRY = join(process.cwd(), 'src/cli.ts');
+const GENERIC_EVAL_USAGE = 'gbrain eval — measure and compare retrieval quality';
+
+function runCli(args: string[]): { out: string; status: number } {
+ const env: Record<string, string | undefined> = {
+ ...process.env,
+ GBRAIN_HOME: '/tmp/gbrain-test-help-dn1-nonexistent',
+ };
+ delete env.GBRAIN_DATABASE_URL;
+ delete env.DATABASE_URL;
+ const result = spawnSync('bun', ['--no-env-file', 'run', CLI_ENTRY, ...args], { encoding: 'utf8', env });
+ return { out: `${result.stdout ?? ''}${result.stderr ?? ''}`, status: result.status ?? -1 };
+}
+
+function listedSubcommands(): string[] {
+ const { out } = runCli(['eval', '--help']);
+ const section = out.split('SUBCOMMANDS')[1]?.split('\nOPTIONS')[0] ?? '';
+ const names: string[] = [];
+ for (const line of section.split('\n')) {
+ const m = /^\s{2}([a-z][a-z0-9-]*(?:\s\/\s[a-z][a-z0-9-]*)*)\s{2,}/.exec(line);
+ if (m) names.push(...m[1].split(' / '));
+ }
+ return names;
+}
+
+describe('D-N1 — every eval subcommand answers --help with its own usage', () => {
+ const subs = listedSubcommands();
+
+ test('the eval usage block lists the subcommands this test iterates', () => {
+ expect(subs.length).toBeGreaterThanOrEqual(15);
+ expect(subs).toContain('replay');
+ expect(subs).toContain('suspected-contradictions');
+ }, 60000);
+
+ for (const sub of subs) {
+ test(`eval ${sub} --help`, () => {
+ const { out, status } = runCli(['eval', sub, '--help']);
+ expect(status).not.toBe(-1);
+ expect(out).not.toContain(GENERIC_EVAL_USAGE);
+ expect(out).toContain(sub);
+ }, 60000);
+ }
+
+ test('an unknown subcommand still gets the generic eval usage', () => {
+ const { out, status } = runCli(['eval', 'not-a-real-sub', '--help']);
+ expect(status).toBe(0);
+ expect(out).toContain(GENERIC_EVAL_USAGE);
+ }, 60000);
+});