π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(parser): subcommand's non-boolean flag overrides global boolean set
ruv3b81e1c09629
diff --git a/v3/@claude-flow/cli/__tests__/parser.test.ts b/v3/@claude-flow/cli/__tests__/parser.test.tsindex c5c8568755..abec740d86 100644--- a/v3/@claude-flow/cli/__tests__/parser.test.ts+++ b/v3/@claude-flow/cli/__tests__/parser.test.ts@@ -285,6 +285,52 @@ describe('CommandParser', () => {const result = p.parse(['memory', 'store', '--no-upsert']);expect(result.flags.upsert).toBe(false);});++ // #2778 follow-up: getScopedBooleanFlags previously walked EVERY+ // registered command's options and marked any boolean-typed flag as+ // boolean everywhere. That broke a numeric --parallel on `hooks route`+ // because `swarm start --parallel` (boolean) polluted the global set.+ // Narrowest-scope wins: subcommand's non-boolean declaration overrides.+ it('subcommand non-boolean flag overrides a boolean declaration on another command', () => {+ const swarmCmd: Command = {+ name: 'swarm',+ description: 'Swarm',+ subcommands: [+ {+ name: 'start',+ description: 'Start swarm',+ options: [+ { name: 'parallel', type: 'boolean', description: 'Enable parallel execution' },+ ],+ },+ ],+ };+ const hooksCmd: Command = {+ name: 'hooks',+ description: 'Hooks',+ subcommands: [+ {+ name: 'route',+ description: 'Route',+ options: [+ { name: 'parallel', type: 'number', description: 'Fanout width' },+ ],+ },+ ],+ };+ const p = new CommandParser({ allowUnknownFlags: true });+ p.registerCommand(swarmCmd);+ p.registerCommand(hooksCmd);++ // On hooks route, `--parallel 7` must reach as the NUMBER 7 β not the+ // boolean `true` that the polluted global set would have produced.+ const result = p.parse(['hooks', 'route', '--parallel', '7']);+ expect(result.flags.parallel).toBe(7);++ // And on swarm start, `--parallel` still parses as boolean.+ const swarmResult = p.parse(['swarm', 'start', '--parallel']);+ expect(swarmResult.flags.parallel).toBe(true);+ });});// -------------------------------------------------------------------------diff --git a/v3/@claude-flow/cli/src/commands/hooks.ts b/v3/@claude-flow/cli/src/commands/hooks.tsindex 2a86b50d4d..71565dd472 100644--- a/v3/@claude-flow/cli/src/commands/hooks.ts+++ b/v3/@claude-flow/cli/src/commands/hooks.ts@@ -768,17 +768,26 @@ const routeCommand: Command = {default: 'single',},{- // #2778 β deliberately NOT `parallel` (short 'p'). Both swarm.ts and- // workflow.ts declare `--parallel` as a BOOLEAN, and the parser's- // global boolean-flag registry pollutes subcommand-scoped numeric- // flags with the same name (parseFlag then treats `--parallel 7` as- // `parallel:true` and drops the value). Using a distinct name avoids- // the collision without touching parser semantics that other- // subcommands rely on.- name: 'moa-parallel',+ // #2778 canonical fanout-width flag. Restored to `--parallel` in+ // v3.32.14 after the parser scoping fix landed (subcommand's+ // non-boolean declaration now overrides the global boolean set,+ // so `--parallel 7` on `hooks route` no longer collides with the+ // boolean `--parallel` on `swarm start` / `workflow run`).+ // NOTE: no `default:` here β default is resolved in the action so+ // we can distinguish "user explicitly passed --parallel" from+ // "user passed --moa-parallel (the v3.32.13 compat alias)". Without+ // this, the parser's applied default would shadow the alias.+ name: 'parallel',+ short: 'p',description: 'MoA fanout width (N parallel calls at Haiku tier; only meaningful when --mode=moa)',type: 'number',- default: 3,+ },+ {+ // v3.32.13 compat alias β kept so any users who upgraded to that+ // release keep working. Prefer `--parallel` going forward.+ name: 'moa-parallel',+ description: 'DEPRECATED alias for --parallel (kept for v3.32.13 backward compat)',+ type: 'number',},{name: 'consensus',@@ -791,15 +800,20 @@ const routeCommand: Command = {examples: [{ command: 'claude-flow hooks route -t "Fix authentication bug"', description: 'Route task to optimal agent (single mode)' },{ command: 'claude-flow hooks route -t "Optimize database queries" -K 5', description: 'Get top 5 suggestions' },- { command: 'claude-flow hooks route -t "Design payment webhook" --mode moa --moa-parallel 3', description: 'MoA fanout: 3Γ Haiku + consensus (dream-cycle #2778)' },+ { command: 'claude-flow hooks route -t "Design payment webhook" --mode moa --parallel 3', description: 'MoA fanout: 3Γ Haiku + consensus (dream-cycle #2778)' },],action: async (ctx: CommandContext): Promise<CommandResult> => {const task = (ctx.flags.task as string) || ctx.args[0];const topK = ctx.flags.topK as number || 3;const mode = (ctx.flags.mode as string) || 'single';- // #2778 β flag is --moa-parallel (parser normalizes to camelCase moaParallel)- // to avoid collision with the boolean --parallel from swarm/workflow.- const parallel = Math.max(2, (ctx.flags.moaParallel as number) || 3);+ // #2778: prefer canonical --parallel; fall back to --moa-parallel+ // (v3.32.13 compat alias). Nullish coalescing so an explicit 0 still+ // falls through to the alias / default, and neither flag being set+ // resolves to 3 (the ACL 2026 SRW paper's baseline fanout width).+ const parallelRaw = (ctx.flags.parallel as number | undefined)+ ?? (ctx.flags.moaParallel as number | undefined)+ ?? 3;+ const parallel = Math.max(2, parallelRaw);const consensus = (ctx.flags.consensus as string) || 'majority-vote';if (!task) {diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.tsindex 8648cb9cc1..2029c3cec9 100644--- a/v3/@claude-flow/cli/src/parser.ts+++ b/v3/@claude-flow/cli/src/parser.ts@@ -459,14 +459,34 @@ export class CommandParser {/*** Get boolean flags scoped to a specific command/subcommand.+ *+ * `getBooleanFlags()` walks EVERY command + subcommand in the registry+ * and adds their boolean options into one flat set. That's convenient+ * for the common case but causes cross-subcommand pollution: if `swarm+ * start --parallel` is boolean AND `hooks route --parallel` is numeric,+ * the flat set marks `parallel` as boolean, and `hooks route --parallel 7`+ * drops the `7` as a positional (parseFlag treats booleanFlags-hit as+ * "consume no value"). This is the exact bug that forced the+ * --moa-parallel rename in the 2026-07-26 dream-cycle #2778 fix.+ *+ * Fix: if the resolved subcommand declares the flag as a non-boolean+ * type, REMOVE it from the boolean set. Narrowest scope wins.+ * (Documented via in-tree comment in commands/hooks.ts and the #2778+ * commit message.)*/private getScopedBooleanFlags(resolvedCmd?: Command): Set<string> {const flags = this.getBooleanFlags();if (resolvedCmd?.options) {for (const opt of resolvedCmd.options) {+ const key = this.normalizeKey(opt.name);if (opt.type === 'boolean') {- flags.add(this.normalizeKey(opt.name));+ flags.add(key);+ } else if (opt.type) {+ // Subcommand explicitly re-declares this flag as a non-boolean+ // type (string/number/array) β narrowest scope wins, so drop+ // it from the boolean set to override any global pollution.+ flags.delete(key);}}}