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(metaharness): MCP wrapper success now derives from exitCode (iter 44)

ruv644b718b390d
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index 917a4c4863..1e1b57f2e7 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -191,6 +191,22 @@ 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 "17z7. MCP wrapper success semantic fix (iter 44 β€” exitCode is the source of truth)"
+miss=""
+WRAPPER="$ROOT/../../v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts"
+# runScript signature includes success now
+grep -q "success: boolean" "$WRAPPER" 2>/dev/null || miss="$miss no-success-type"
+grep -q "success = exitCode === 0" "$WRAPPER" 2>/dev/null || miss="$miss no-exitcode-derived-success"
+# All 8 handlers use r.success, NOT !r.degraded
+COUNT_OLD=$(grep -c "success: !r.degraded" "$WRAPPER" 2>/dev/null; true)
+[[ "$COUNT_OLD" == "0" ]] || miss="$miss old-pattern-still-present:$COUNT_OLD"
+COUNT_NEW=$(grep -c "success: r.success" "$WRAPPER" 2>/dev/null; true)
+[[ "$COUNT_NEW" == "8" ]] || miss="$miss new-pattern-count:$COUNT_NEW-expected-8"
+# Runtime anchors: iter 44 success assertions present
+T="$ROOT/scripts/test-mcp-tools.mjs"
+grep -q "iter 44 fix" "$T" 2>/dev/null || miss="$miss no-iter44-anchors"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17z6. test-mcp-tools.mjs Phase 4 positive-case (iter 43 β€” output-shape gate)"
F="$ROOT/scripts/test-mcp-tools.mjs"
miss=""
diff --git a/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs b/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs
index 899fab338d..6ced39d5f1 100755
--- a/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs
+++ b/plugins/ruflo-metaharness/scripts/test-mcp-tools.mjs
@@ -220,6 +220,10 @@ async function main() {
assert(rAlert.data?.alert?.triggered === true,
'similarity alertBelow=0.99 triggers alert');
assert(rAlert.exitCode === 1, 'similarity alertBelow=0.99 β†’ exitCode 1');
+ // iter 44 β€” success semantic anchor (was true under the pre-iter-44
+ // `!degraded` rule; now false because exitCode !== 0 dominates).
+ assert(rAlert.success === false,
+ 'similarity alertBelow=0.99 β†’ success === false (iter 44 fix)');
}
// metaharness_audit_trend β€” positive case via file inputs
@@ -257,6 +261,11 @@ async function main() {
'audit_trend bad-keys path exits 2 (script-level guard fires)');
assert(r.data === null || r.data === undefined,
'audit_trend bad-keys path: data null (no JSON emitted on stderr exit)');
+ // iter 44 β€” success semantic anchor. Pre-iter-44 wrapper returned
+ // success:true for this case (because no degraded marker). Now
+ // returns false because exitCode !== 0.
+ assert(r.success === false,
+ 'audit_trend bad-keys path: success === false (iter 44 fix)');
}
// Cleanup
diff --git a/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts
index 061999fb3d..03ced5eed9 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts
@@ -57,12 +57,47 @@ function locatePluginScripts(): string | null {
return null;
}
-function runScript(scriptName: string, args: string[]): Promise<{ exitCode: number; stdout: string; json: unknown; degraded: boolean }> {
+/**
+ * Result of running a metaharness plugin script.
+ *
+ * SUCCESS SEMANTICS (iter 44 β€” fix for iter-43-flagged bug)
+ * `success` is computed from the canonical signal: exitCode === 0.
+ *
+ * Three observable cases:
+ * 1. exitCode 0 + valid JSON β†’ success: true, degraded: false
+ * (happy path; data is the script's JSON output)
+ *
+ * 2. exitCode 0 + degraded payload β†’ success: true, degraded: true
+ * (ADR-150 constraint #3 β€” upstream `@metaharness/*` absent, script
+ * emits `{degraded:true, reason:"metaharness-not-available"}` and
+ * exits 0 so ruflo stays operational. `success: true` because the
+ * script DID run as designed; the agent reads `degraded: true` to
+ * know the dep was missing.)
+ *
+ * 3. exitCode != 0 β†’ success: false
+ * Two sub-cases:
+ * a. exitCode 1 with alert.triggered JSON β†’ intentional alert
+ * failure (e.g. --alert-on-fit-below 70). Agents read
+ * `data.alert.triggered` for the reason.
+ * b. exitCode 2 with stderr-only β†’ user error (bad arg).
+ * `data` is null because no JSON was on stdout.
+ *
+ * BEFORE iter 44 `success` was computed as `!degraded`, which collapsed
+ * case 3b into success: true / exitCode: 2 β€” contradictory.
+ */
+function runScript(scriptName: string, args: string[]): Promise<{
+ exitCode: number;
+ stdout: string;
+ json: unknown;
+ degraded: boolean;
+ success: boolean;
+}> {
return new Promise((resolve) => {
const dir = locatePluginScripts();
if (!dir) {
resolve({
- exitCode: 0, stdout: '', json: { degraded: true, reason: 'plugin-not-found' }, degraded: true,
+ exitCode: 0, stdout: '', json: { degraded: true, reason: 'plugin-not-found' },
+ degraded: true, success: true, // plugin absent β†’ equivalent to case 2
});
return;
}
@@ -83,11 +118,20 @@ function runScript(scriptName: string, args: string[]): Promise<{ exitCode: numb
const m = /\{[\s\S]*\}/.exec(stdout);
if (m) { try { json = JSON.parse(m[0]); } catch { /* leave null */ } }
const looksDegraded = !!(json && typeof json === 'object' && (json as { degraded?: unknown }).degraded === true);
- resolve({ exitCode: code ?? 0, stdout, json, degraded: looksDegraded });
+ const exitCode = code ?? 0;
+ // iter 44 β€” success now reflects exit code, not the degraded marker.
+ // exit 0 = script ran as designed (whether the result was happy
+ // data or a graceful-degradation payload). exit != 0 = something
+ // went wrong (intentional alert OR user/system error).
+ const success = exitCode === 0;
+ resolve({ exitCode, stdout, json, degraded: looksDegraded, success });
});
p.on('error', () => {
clearTimeout(timer);
- resolve({ exitCode: 127, stdout, json: { degraded: true, reason: 'spawn-failed' }, degraded: true });
+ resolve({
+ exitCode: 127, stdout, json: { degraded: true, reason: 'spawn-failed' },
+ degraded: true, success: false,
+ });
});
});
}
@@ -109,7 +153,7 @@ export const metaharnessTools: MCPTool[] = [
const args = ['--path', path];
if (input.alertOnFitBelow !== undefined) args.push('--alert-on-fit-below', String(input.alertOnFitBelow));
const r = await runScript('score.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -128,7 +172,7 @@ export const metaharnessTools: MCPTool[] = [
const args = ['--path', path];
if (input.alertOnRiskAbove !== undefined) args.push('--alert-on-risk-above', String(input.alertOnRiskAbove));
const r = await runScript('genome.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -146,7 +190,7 @@ export const metaharnessTools: MCPTool[] = [
const path = (input.path as string) || '.';
const failOn = (input.failOn as string) || 'high';
const r = await runScript('mcp-scan.mjs', ['--path', path, '--fail-on', failOn]);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -164,7 +208,7 @@ export const metaharnessTools: MCPTool[] = [
const path = (input.path as string) || '.';
const failOn = (input.failOn as string) || 'high';
const r = await runScript('threat-model.mjs', ['--path', path, '--fail-on', failOn]);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -185,7 +229,7 @@ export const metaharnessTools: MCPTool[] = [
if (input.dryRun === true) args.push('--dry-run');
if (input.alertOnWorst !== undefined) args.push('--alert-on-worst', String(input.alertOnWorst));
const r = await runScript('oia-audit.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -204,7 +248,7 @@ export const metaharnessTools: MCPTool[] = [
if (input.limit !== undefined) args.push('--limit', String(input.limit));
if (input.since !== undefined) args.push('--since', String(input.since));
const r = await runScript('audit-list.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -231,7 +275,7 @@ export const metaharnessTools: MCPTool[] = [
if (input.perDimension === true) args.push('--per-dimension');
if (input.alertBelow !== undefined) args.push('--alert-below', String(input.alertBelow));
const r = await runScript('similarity.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
{
@@ -253,7 +297,7 @@ export const metaharnessTools: MCPTool[] = [
const args = ['--baseline-key', baselineKey, '--current-key', currentKey];
if (input.alertOnWorsening === true) args.push('--alert-on-worsening');
const r = await runScript('audit-trend.mjs', args);
- return { success: !r.degraded, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
+ return { success: r.success, data: r.json, degraded: r.degraded, exitCode: r.exitCode };
},
},
];