From 7ebdaf580b30e943be19a86bf13f2b136aca1e4c Mon Sep 17 00:00:00 2001 From: rUv Date: Wed, 6 May 2026 16:52:51 -0400 Subject: [PATCH] fix(cli): pre-load lazy commands so short flags scope correctly (#1791.2) (#1803) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ruflo hive-mind task -d "smoke"` was silently rejecting the short flag: $ ruflo hive-mind task -d "smoke" [ERROR] Task description is required even though `taskCommand` defines `{ name: 'description', short: 'd' }`. Root cause is the lazy-command path in the parser. When the parser walks argv in pass 1 and encounters a name registered via `registerLazyCommandName` (hive-mind, neural, performance, security, ruvector, …), it `break`s out without resolving subcommands — by design, since the lazy module hasn't been imported yet. That means `buildScopedAliases()` only ever sees the parent's options, and the subcommand's short flags never make it into the alias map. `-d` falls through to global resolution, gets stored as `flags.d = "smoke"`, and the action handler reading `flags.description` sees `undefined`. Fix: in `CLI.run()`, before calling `parser.parse()`, eagerly load any lazy command that appears as the first non-flag positional, then `registerCommand()` it as a normal command. Parse then sees the full subcommand tree and scopes flags correctly. Cost: lazy commands now load on first use rather than after the parser identifies them as the dispatch target — but they would have loaded moments later anyway, so the wall-clock impact is essentially zero. Commands the user doesn't invoke still don't load. Adds `parser.isLazyOnly(name)` helper so the CLI can ask the question without reaching into private state. Closes #1791 (sub-bug 2). --- v3/@claude-flow/cli/src/index.ts | 16 ++++++++++++++++ v3/@claude-flow/cli/src/parser.ts | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/v3/@claude-flow/cli/src/index.ts b/v3/@claude-flow/cli/src/index.ts index ea10d02cfe..5678a6b027 100644 --- a/v3/@claude-flow/cli/src/index.ts +++ b/v3/@claude-flow/cli/src/index.ts @@ -83,6 +83,22 @@ export class CLI { */ async run(args: string[] = process.argv.slice(2)): Promise { try { + // #1791.2 — If the user invoked a lazy command (e.g. `hive-mind task`), + // pre-load it BEFORE parsing so the parser can build scoped flag + // aliases for its subcommands. Without this, short flags defined on + // the lazy command's subcommand options (`-d` for description, etc.) + // never get into the alias map and silently fall through to global + // resolution — the user sees `[ERROR] Task description is required` + // even though they passed `-d "smoke"`. + for (const arg of args) { + if (arg.startsWith('-')) continue; + if (this.parser.isLazyOnly(arg)) { + const cmd = await getCommandAsync(arg); + if (cmd) this.parser.registerCommand(cmd); + } + break; // only the first non-flag positional is the command name + } + // Parse arguments const parseResult = this.parser.parse(args); const { command: commandPath, flags, positional } = parseResult; diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.ts index 61f5c6c7f7..6eea07b2a1 100644 --- a/v3/@claude-flow/cli/src/parser.ts +++ b/v3/@claude-flow/cli/src/parser.ts @@ -119,6 +119,18 @@ export class CommandParser { this.lazyCommandNames.add(name); } + /** + * #1791.2 — true when `name` is a lazy command that hasn't been promoted + * to a fully registered Command yet. The CLI uses this to eagerly load + * the module before parsing so its subcommand flags (e.g. `-d` for + * `hive-mind task --description`) are scoped into the alias map. Without + * this, lazy commands' short flags silently fall through to global + * resolution and the action handler sees an empty `flags.description`. + */ + isLazyOnly(name: string): boolean { + return this.lazyCommandNames.has(name) && !this.commands.has(name); + } + private isKnownCommandName(name: string): boolean { return this.commands.has(name) || this.lazyCommandNames.has(name); }