From 2eac7904297c51c4e5f2eea968c0b3e07d1fe3b4 Mon Sep 17 00:00:00 2001 From: ruv Date: Tue, 16 Jun 2026 16:58:41 -0400 Subject: [PATCH] fix(metaharness): dispatcher propagates flags to subprocess (iter 42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL BUG FIX surfaced during iter-42 CI dispatcher round-trip testing. Iter-36 wired the SUBCOMMANDS map but the dispatcher only forwarded context.args (positionals), not context.flags. Every metaharness subcommand called via `node bin/cli.js metaharness X --flag value` saw an empty argv at the script layer and emitted "missing arg" gracefully — masking the bug behind valid-looking degraded output. The iter-36 unit tests + smoke gates DIDN'T catch this because they called the script directly (`node scripts/similarity.mjs --a ...`), which bypasses the dispatcher entirely. Iter 42's "end-to-end CLI dispatcher round-trip" CI step was the first to exercise the real path. ROOT CAUSE The CLI parser splits user argv into: context.args = positional args (after subcommand) context.flags = parsed --key=value pairs (camelCase-normalized) The iter-36 dispatcher read only context.args, dropping every --flag. Worse: parser normalizes --per-dimension → perDimension at the same step, so even passing context.flags through naively wouldn't work — needs camelCase→kebab-case re-conversion. FIX (v3/@claude-flow/cli/src/commands/metaharness.ts) 1. Read context.flags in the dispatcher 2. Filter out SKIP_KEYS (parser bucket '_', global --config/--verbose/etc) 3. Re-kebab each flag name (perDimension → --per-dimension) 4. Handle booleans (omit if false, emit bare flag if true) 5. Handle arrays (emit --key value multiple times) 6. Append reconstructed flags to positionalRest → subArgs 7. Always use --long form (never -short) since plugin scripts argv-match on literal '--a', '--b' rather than via a parser WHAT NOW WORKS (was silently broken before iter 42) node bin/cli.js metaharness similarity --a a.json --b b.json --format json → overall: 0.8296, components, weights — full output node bin/cli.js metaharness similarity --a a.json --b b.json --per-dimension → perDimension breakdown present node bin/cli.js metaharness similarity --a-key X --b-key Y → kebab compound name correctly preserved node bin/cli.js metaharness audit-trend --baseline-key X --current-key Y \ --alert-on-distance-below 0.99 → triggered: true, exit 1 node bin/cli.js metaharness genome --path . --alert-on-risk-above 0.99 → alert: {...} This affects every metaharness subcommand, not just similarity — score, genome, mcp-scan, threat-model, oia-audit, audit-list, audit-trend, similarity, mint. All previously sent flags to /dev/null. CI STEPS RE-ENABLED (.github/workflows/metaharness-ci.yml) Three new steps in similarity-tests job: - Performance gate (iter 41) — bench-similarity --max-mean-us 10 - CLI dispatcher round-trip via `node bin/cli.js metaharness similarity` - Help text lists 'similarity' subcommand (anti-regression) This time the dispatcher path actually exercises the bug-prone code: if anyone removes the flag-reconstruction logic, CI fails. SMOKE STEP 17z5 anchors the fix: - reconstructedFlags marker present - ctxFlags read present - toKebab helper present - SKIP_KEYS set present - iter-42 comment present GATES THIS ITER smoke: 45 → 46 (step 17z5 green) fleet: 33/33 tsc: clean rebuild runtime: all 4 dispatcher round-trip paths produce expected output OBSERVATION FOR FUTURE This bug was invisible because graceful degradation made it LOOK like the intended path. Lesson: graceful-degradation output for "missing required arg" should distinguish "user forgot a flag" (exit 2) from "upstream dep not installed" (exit 0). They both currently emit {degraded: true, reason} with different reason strings. Worth a follow-up clarification in _harness.mjs, but not in scope this iter. Co-Authored-By: RuFlo --- .github/workflows/metaharness-ci.yml | 36 ++++++++++++++++++ plugins/ruflo-metaharness/scripts/smoke.sh | 13 +++++++ .../cli/src/commands/metaharness.ts | 38 ++++++++++++++++++- 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/.github/workflows/metaharness-ci.yml b/.github/workflows/metaharness-ci.yml index 6595ec8591..97ccfe5a26 100644 --- a/.github/workflows/metaharness-ci.yml +++ b/.github/workflows/metaharness-ci.yml @@ -284,3 +284,39 @@ jobs: echo "✓ structural-distance alert correctly exited non-zero (got $?)" fi + - name: Performance gate — sub-10μs mean per similarity() call (iter 41) + # CI runners are slower than Apple-Silicon baseline (~0.4μs); 10μs + # ceiling gives ~25× headroom while still catching ~10× regressions. + # 100k iters keeps the job fast (~50ms total work). + run: | + node plugins/ruflo-metaharness/scripts/bench-similarity.mjs \ + --iters 100000 \ + --max-mean-us 10 + + - name: Build CLI dist (for dispatcher round-trip) + run: | + cd v3/@claude-flow/cli + npm install --no-audit --no-fund --ignore-scripts --silent + npm run build + + - name: CLI dispatcher round-trip — `node bin/cli.js metaharness similarity` (iter 36) + # Proves the iter-36 SUBCOMMANDS entry actually dispatches at the + # CLI surface, not just at the script. Closes the gap between + # "the script works in isolation" and "the user-facing command works". + run: | + set -e + OUT=$(node v3/@claude-flow/cli/bin/cli.js metaharness similarity \ + --a /tmp/a.json --b /tmp/b.json --format json) + echo "$OUT" | head -20 + echo "$OUT" | grep -q '"overall"' || { echo "FAIL: dispatcher did not emit overall"; exit 1; } + echo "$OUT" | grep -q '"adr": "ADR-152"' || { echo "FAIL: dispatcher output missing ADR tag"; exit 1; } + echo "✓ CLI dispatcher round-trip green" + + - name: CLI help lists similarity subcommand + # Anti-regression on the help text (iter 36 added this line). + run: | + set -e + OUT=$(node v3/@claude-flow/cli/bin/cli.js metaharness 2>&1 || true) + echo "$OUT" | grep -q "similarity" || { echo "FAIL: help text dropped similarity"; exit 1; } + echo "✓ help text references similarity subcommand" + diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh index c9f7b7c3a3..4488e9e747 100755 --- a/plugins/ruflo-metaharness/scripts/smoke.sh +++ b/plugins/ruflo-metaharness/scripts/smoke.sh @@ -191,6 +191,19 @@ grep -q "execCli(\[\s*'-y'\s*,\s*'metaharness@latest'" "$F" 2>/dev/null || \ grep -q "cwd: opts" "$F" || miss="$miss no-cwd-passthrough" [[ -z "$miss" ]] && ok || bad "$miss" +step "17z5. CLI dispatcher round-trips flags (iter 42 — fixes existing bug)" +miss="" +DISP="$ROOT/../../v3/@claude-flow/cli/src/commands/metaharness.ts" +# Reconstruction logic literal markers (anti-deletion) +grep -q "reconstructedFlags" "$DISP" 2>/dev/null || miss="$miss no-reconstruction" +grep -q "ctxFlags" "$DISP" 2>/dev/null || miss="$miss no-ctx-flags-read" +grep -q "toKebab" "$DISP" 2>/dev/null || miss="$miss no-kebab-helper" +# SKIP_KEYS list documents which flags don't propagate +grep -q "SKIP_KEYS" "$DISP" 2>/dev/null || miss="$miss no-skip-set" +# Comment explains the fix +grep -q "iter 42" "$DISP" 2>/dev/null || miss="$miss no-iter42-marker" +[[ -z "$miss" ]] && ok || bad "$miss" + step "17z4. bench-similarity.mjs — perf characterization + regression gate (iter 41)" F="$ROOT/scripts/bench-similarity.mjs" miss="" diff --git a/v3/@claude-flow/cli/src/commands/metaharness.ts b/v3/@claude-flow/cli/src/commands/metaharness.ts index e8add5ab19..8a8326aa8d 100644 --- a/v3/@claude-flow/cli/src/commands/metaharness.ts +++ b/v3/@claude-flow/cli/src/commands/metaharness.ts @@ -117,7 +117,43 @@ export const metaharnessCommand: Command = { async action(context: CommandContext): Promise { const args = (context as { args?: string[] }).args || []; const subcommand = args[0]; - const subArgs = args.slice(1); + const positionalRest = args.slice(1); + + // iter 42 — round-trip parsed flags back into argv so the + // subprocess receives them. Without this the CLI parser consumes + // `--a foo` into `flags.a` and the script sees an empty argv, + // emitting a graceful-but-wrong "missing arg" payload (the iter-36 + // bug surfaced during iter-42 dispatcher round-trip testing). + const ctxFlags = (context as { flags?: Record }).flags || {}; + const reconstructedFlags: string[] = []; + const SKIP_KEYS = new Set([ + '_', // parser's positional bucket + 'config', // global CLI flag (--config ); consumed before dispatch + 'verbose', 'v', + 'quiet', 'q', + 'help', 'h', + ]); + // Parser normalizes kebab-case → camelCase (--per-dimension → perDimension). + // Plugin scripts expect kebab-case at argv, so we re-kebab here. + const toKebab = (s: string): string => + s.replace(/([A-Z])/g, (m) => `-${m.toLowerCase()}`); + for (const [key, value] of Object.entries(ctxFlags)) { + if (SKIP_KEYS.has(key)) continue; + if (value === undefined || value === null) continue; + // Always use --kebab even for single-char keys: similarity.mjs + // matches literal `--a` / `--b` via argv loop, not via a parser. + // Reconstructing as short-form (`-a`) would silently misroute. + const flag = `--${toKebab(key)}`; + if (typeof value === 'boolean') { + if (value === true) reconstructedFlags.push(flag); + // false → omit (--no-X handled by users invoking explicit --no- form) + } else if (Array.isArray(value)) { + for (const v of value) reconstructedFlags.push(flag, String(v)); + } else { + reconstructedFlags.push(flag, String(value)); + } + } + const subArgs = [...positionalRest, ...reconstructedFlags]; if (!subcommand || subcommand === 'help' || subcommand === '--help' || subcommand === '-h') { output.writeln(output.bold('npx ruflo metaharness [options]'));