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

feat(metaharness): parseMcpScanText closes iter-49 dead-code gap (iter 50)

ruva4fd2b12f46f
diff --git a/plugins/ruflo-metaharness/scripts/_harness.mjs b/plugins/ruflo-metaharness/scripts/_harness.mjs
index 116873c531..3d122833c5 100755
--- a/plugins/ruflo-metaharness/scripts/_harness.mjs
+++ b/plugins/ruflo-metaharness/scripts/_harness.mjs
@@ -107,6 +107,49 @@ export function runHarness(args, opts) {
return { stdout, stderr, exitCode: r.status ?? 0, json, durationMs, degraded: false };
}
+/**
+ * iter 50 β€” parse `harness mcp-scan` text output into structured findings.
+ *
+ * Upstream `harness mcp-scan` emits plain text even with --json:
+ *
+ * harness mcp-scan β€” <path>
+ *
+ * [INFO] No MCP security issues found
+ * Policy is default-deny with safe capability grants and an audit log.
+ *
+ * Result: INFO (1 finding, 0 high)
+ *
+ * Closes the iter-49-flagged gap where audit-trend.mjs reads
+ * `json.findings` expecting an array, but mcp-scan's r.json was null.
+ * Used by BOTH mcp-scan.mjs (the wrapper) and oia-audit.mjs (composite
+ * audit) so the structured-findings invariant holds across the pipeline.
+ */
+export function parseMcpScanText(stdout) {
+ const findings = [];
+ const lines = (stdout || '').split('\n');
+ let current = null;
+ for (const line of lines) {
+ const m = /^\s*\[([A-Z]+)\]\s+(.+?)\s*$/.exec(line);
+ if (m) {
+ if (current) findings.push(current);
+ current = { severity: m[1].toLowerCase(), message: m[2] };
+ } else if (current && /^\s{6,}\S/.test(line)) {
+ const cont = line.trim();
+ if (cont) current.message += ' ' + cont;
+ } else if (current && line.trim() === '') {
+ findings.push(current);
+ current = null;
+ }
+ }
+ if (current) findings.push(current);
+ const resultMatch = /Result:\s+([A-Z]+)\s+\((\d+)\s+finding/i.exec(stdout);
+ const summary = resultMatch ? {
+ overallSeverity: resultMatch[1].toLowerCase(),
+ totalCount: parseInt(resultMatch[2], 10),
+ } : null;
+ return { findings, summary };
+}
+
// Convenience emitters for skill scripts β€” keep the boilerplate out of
// each skill so they focus on argument parsing + exit-code semantics.
export function emitDegradedJsonAndExit(reason) {
diff --git a/plugins/ruflo-metaharness/scripts/mcp-scan.mjs b/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
index 2df9985c8d..9e2b3619c6 100755
--- a/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
+++ b/plugins/ruflo-metaharness/scripts/mcp-scan.mjs
@@ -16,9 +16,11 @@
// 1 at least one finding β‰₯ --fail-on severity
// 2 config error or scan failure
-import { runHarness, emitDegradedJsonAndExit } from './_harness.mjs';
+// iter 50 β€” parseMcpScanText extracted to _harness.mjs so oia-audit
+// can use the same parser without duplicating logic.
+import { runHarness, emitDegradedJsonAndExit, parseMcpScanText } from './_harness.mjs';
-const SEVERITY_RANK = { low: 1, medium: 2, high: 3 };
+const SEVERITY_RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 3 };
const ARGS = (() => {
const a = { path: '.', format: 'json', failOn: 'high' };
@@ -45,9 +47,19 @@ function main() {
if (r.stderr) console.error(r.stderr.slice(0, 400));
process.exit(2);
}
- // The JSON output shape from `harness mcp-scan` includes findings[].
- const payload = r.json ?? { rawStdout: r.stdout.slice(0, 400) };
- const findings = Array.isArray(payload?.findings) ? payload.findings : [];
+ // The JSON output shape from `harness mcp-scan` historically didn't
+ // include structured findings β€” it emits text even with --json. Parse
+ // the text into findings (iter 50) so audit-trend's introduced/cleared
+ // diff actually works. If a future upstream version DOES emit
+ // findings[], the parsed-text findings are overridden.
+ const parsed = parseMcpScanText(r.stdout);
+ const payload = {
+ ...(r.json ?? {}),
+ findings: Array.isArray(r.json?.findings) ? r.json.findings : parsed.findings,
+ summary: r.json?.summary ?? parsed.summary,
+ rawStdout: r.stdout.slice(0, 400),
+ };
+ const findings = payload.findings;
const threshold = SEVERITY_RANK[ARGS.failOn];
const offending = findings.filter((f) => SEVERITY_RANK[String(f.severity || 'low').toLowerCase()] >= threshold);
diff --git a/plugins/ruflo-metaharness/scripts/oia-audit.mjs b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
index 3822eaf761..03cdd666ef 100755
--- a/plugins/ruflo-metaharness/scripts/oia-audit.mjs
+++ b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
@@ -25,7 +25,7 @@
// 2 config error or audit failure
import { spawnSync } from 'node:child_process';
-import { runHarness, runMetaharness, emitDegradedJsonAndExit } from './_harness.mjs';
+import { runHarness, runMetaharness, emitDegradedJsonAndExit, parseMcpScanText } from './_harness.mjs';
const SEVERITY_RANK = { clean: 0, low: 1, medium: 2, high: 3 };
const NS = process.env.OIA_AUDIT_NAMESPACE || 'metaharness-audit';
@@ -52,12 +52,21 @@ const ARGS = (() => {
// we need to dispatch to runMetaharness for score+genome, not runHarness.
function runOne(args, label, engine = 'harness') {
const r = engine === 'metaharness' ? runMetaharness(args) : runHarness(args);
+ // iter 50 β€” when label is 'mcp-scan' and the upstream returned text
+ // (json null), parse findings via the shared text parser so audit-trend
+ // can run its introduced/cleared diff on real data. The upstream may
+ // someday emit structured JSON; if so r.json wins and we skip the parse.
+ let json = r.json;
+ if (label === 'mcp-scan' && !json && !r.degraded && r.stdout) {
+ const parsed = parseMcpScanText(r.stdout);
+ json = { findings: parsed.findings, summary: parsed.summary, rawStdout: r.stdout.slice(0, 400) };
+ }
return {
label,
exitCode: r.exitCode,
degraded: r.degraded,
reason: r.degraded ? r.reason : null,
- json: r.json,
+ json,
durationMs: r.durationMs,
stderrTail: r.degraded ? (r.stderr || '').slice(-200) : null,
};
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index e87ec1fa58..954d601d5e 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -191,6 +191,26 @@ 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 "17z13. mcp-scan findings parsed from text β†’ audit-trend diff works (iter 50)"
+miss=""
+HARNESS="$ROOT/scripts/_harness.mjs"
+# Shared parser exported
+grep -q "export function parseMcpScanText" "$HARNESS" 2>/dev/null || miss="$miss no-shared-parser"
+# mcp-scan.mjs uses it
+SCAN="$ROOT/scripts/mcp-scan.mjs"
+grep -q "parseMcpScanText" "$SCAN" 2>/dev/null || miss="$miss scan-not-importing"
+# oia-audit.mjs uses it for the mcp-scan label
+OIA="$ROOT/scripts/oia-audit.mjs"
+grep -q "parseMcpScanText" "$OIA" 2>/dev/null || miss="$miss oia-not-importing"
+grep -q "label === 'mcp-scan'" "$OIA" 2>/dev/null || miss="$miss no-label-dispatch"
+# Runtime: mcp-scan produces an array
+OUT=$(node "$SCAN" --path . --format json 2>/dev/null)
+echo "$OUT" | grep -q '"findings": \[' || miss="$miss runtime-no-findings-array"
+echo "$OUT" | grep -q '"severity":' || miss="$miss runtime-no-severity-field"
+# Runtime: roundtrip passes 25/25 (was 24/24 with mcp-scan SKIP)
+node "$ROOT/scripts/test-pipeline-roundtrip.mjs" 2>&1 | grep -q "25 passed, 0 failed" || miss="$miss roundtrip-not-25"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17z12. roundtrip covers non-similarity schemas + flags mcp-scan gap (iter 49)"
miss=""
F="$ROOT/scripts/test-pipeline-roundtrip.mjs"