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): isolate mutable array defaults between parses

Rudy Celekli3160d70810ce
diff --git a/tests/parser-array-defaults.test.mjs b/tests/parser-array-defaults.test.mjs
new file mode 100644
index 0000000000..5dca4fa6ac
--- /dev/null
+++ b/tests/parser-array-defaults.test.mjs
@@ -0,0 +1,10 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { CommandParser } from '../v3/@claude-flow/cli/src/parser.ts';
+test('command array defaults are independent across parses', () => {
+ const defaults = ['base']; const p = new CommandParser(); p.registerCommand({ name: 'root', description: '', options: [{ name: 'models', description: '', type: 'array', default: defaults }] });
+ p.parse(['root']).flags.models.push('injected'); assert.deepEqual(p.parse(['root']).flags.models, ['base']); assert.deepEqual(defaults, ['base']);
+});
+test('custom array defaults are independent across parses', () => {
+ const defaults = ['base']; const p = new CommandParser({ defaults: { models: defaults } }); p.parse([]).flags.models.push('injected'); assert.deepEqual(p.parse([]).flags.models, ['base']); assert.deepEqual(defaults, ['base']);
+});
diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.ts
index 026d18034e..3ecf18e0b2 100644
--- a/v3/@claude-flow/cli/src/parser.ts
+++ b/v3/@claude-flow/cli/src/parser.ts
@@ -600,7 +600,7 @@ export class CommandParser {
for (const opt of layer) {
const key = this.normalizeKey(opt.name);
if (flags[key] === undefined && opt.default !== undefined) {
- flags[key] = opt.default as string | boolean | number | string[];
+ flags[key] = (Array.isArray(opt.default) ? [...opt.default] : opt.default) as string | boolean | number | string[];
}
}
}
@@ -610,7 +610,7 @@ export class CommandParser {
for (const [key, value] of Object.entries(this.options.defaults)) {
const normalizedKey = this.normalizeKey(key);
if (flags[normalizedKey] === undefined) {
- flags[normalizedKey] = value as string | boolean | number | string[];
+ flags[normalizedKey] = (Array.isArray(value) ? [...value] : value) as string | boolean | number | string[];
}
}
}