Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(cli): apply defaults at every command depth

Rudy Celekli153d0ec999fd
diff --git a/tests/parser-nested-defaults.test.mjs b/tests/parser-nested-defaults.test.mjs
new file mode 100644
index 0000000000..4809ae9303
--- /dev/null
+++ b/tests/parser-nested-defaults.test.mjs
@@ -0,0 +1,12 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { CommandParser } from '../v3/@claude-flow/cli/src/parser.ts';
+const option = (value) => ({ name: 'format', description: 'Format', type: 'string', default: value });
+const parser = () => { const p = new CommandParser(); p.registerCommand({ name: 'root', description: '', options: [option('root')], subcommands: [{ name: 'child', description: '', options: [option('child')], subcommands: [{ name: 'nested', description: '', options: [option('nested')], subcommands: [{ name: 'deep', description: '', options: [option('deep')] }] }] }] }); return p; };
+test('nested and deep defaults take precedence over parent defaults', () => {
+ assert.equal(parser().parse(['root', 'child', 'nested']).flags.format, 'nested');
+ assert.equal(parser().parse(['root', 'child', 'nested', 'deep']).flags.format, 'deep');
+});
+test('explicit values still override defaults', () => {
+ assert.equal(parser().parse(['root', 'child', 'nested', 'deep', '--format=json']).flags.format, 'json');
+});
diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.ts
index 026d18034e..f11b63ae0b 100644
--- a/v3/@claude-flow/cli/src/parser.ts
+++ b/v3/@claude-flow/cli/src/parser.ts
@@ -164,7 +164,6 @@ export class CommandParser {
// command, because that's what caused `daemon start` to resolve as `start`
// with `daemon` left as a positional.
let resolvedCmd: Command | undefined;
- let resolvedSub: Command | undefined;
const resolvedCommands: Command[] = [];
let sawFirstPositional = false;
for (let index = 0; index < args.length; index++) {
@@ -201,7 +200,6 @@ export class CommandParser {
const child = parent.subcommands.find(sc => sc.name === arg || sc.aliases?.includes(arg));
if (child) {
resolvedCommands.push(child);
- resolvedSub ??= child;
continue;
}
}
@@ -287,7 +285,7 @@ export class CommandParser {
// `default: true` silently dropped and reached the action handler as
// `undefined`. That trapped `memory store --upsert` and every other
// subcommand that leaned on a per-flag default.
- this.applyDefaults(result.flags, resolvedCmd, resolvedSub);
+ this.applyDefaults(result.flags, resolvedCommands);
return result;
}
@@ -585,15 +583,10 @@ export class CommandParser {
return flags;
}
- private applyDefaults(flags: ParsedFlags, command?: Command, subcommand?: Command): void {
- // #2775: apply defaults from globals AND the resolved command/subcommand.
- // Subcommand > command > global (later writes lose to earlier — because
- // we only set when `undefined`, so the FIRST option definition that
- // supplies a default wins; walk narrow-to-broad so subcommand options
- // apply before broader ones do).
- const layers: CommandOption[][] = [];
- if (subcommand?.options) layers.push(subcommand.options);
- if (command?.options) layers.push(command.options);
+ private applyDefaults(flags: ParsedFlags, commands: Command[]): void {
+ // Walk every resolved command from narrow to broad so nested defaults
+ // have the same precedence as their declared flag types.
+ const layers = [...commands].reverse().map(command => command.options ?? []);
layers.push(this.globalOptions);
for (const layer of layers) {