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): oia-audit bundles fingerprint + audit-trend computes structural distance (iter 38)

ruv55b6934dc18a
diff --git a/plugins/ruflo-metaharness/scripts/audit-trend.mjs b/plugins/ruflo-metaharness/scripts/audit-trend.mjs
index a5ac22a780..b99173f813 100755
--- a/plugins/ruflo-metaharness/scripts/audit-trend.mjs
+++ b/plugins/ruflo-metaharness/scripts/audit-trend.mjs
@@ -26,6 +26,10 @@
import { readFileSync, existsSync } from 'node:fs';
import { spawnSync } from 'node:child_process';
+// iter 38 β€” structural-distance drift via ADR-152 Β§3.1 production module.
+// Falls back to null if either record predates iter-38 oia-audit (no
+// fingerprint field) β€” graceful degradation, never throws.
+import { similarity } from './_similarity.mjs';
const SEVERITY_RANK = { clean: 0, low: 1, medium: 2, high: 3 };
const NS = process.env.AUDIT_TREND_NAMESPACE || 'metaharness-audit';
@@ -38,6 +42,8 @@ const ARGS = (() => {
baseline: null, current: null,
baselineKey: null, currentKey: null,
alertOnWorsening: false, format: 'table',
+ // iter 38 β€” structural-distance gate (ADR-152 Β§3.1 dep)
+ alertOnDistanceBelow: null,
};
for (let i = 2; i < process.argv.length; i++) {
const v = process.argv[i];
@@ -46,6 +52,7 @@ const ARGS = (() => {
else if (v === '--baseline-key') a.baselineKey = process.argv[++i];
else if (v === '--current-key') a.currentKey = process.argv[++i];
else if (v === '--alert-on-worsening') a.alertOnWorsening = true;
+ else if (v === '--alert-on-distance-below') a.alertOnDistanceBelow = Number(process.argv[++i]);
else if (v === '--format') a.format = process.argv[++i];
}
return a;
@@ -131,6 +138,36 @@ function main() {
const introduced = currFindings.filter((f) => !baseSet.has(fingerprint(f)));
const cleared = baseFindings.filter((f) => !currSet.has(fingerprint(f)));
+ // iter 38 β€” structural distance via ADR-152 Β§3.1 similarity().
+ // Both records need a fingerprint (score+genome) β€” iter-38 oia-audit
+ // adds it; older records skip with verdict 'unavailable'.
+ let structuralDistance = null;
+ if (baseline.fingerprint?.score && baseline.fingerprint?.genome
+ && current.fingerprint?.score && current.fingerprint?.genome) {
+ const sim = similarity(baseline.fingerprint, current.fingerprint);
+ structuralDistance = {
+ overall: sim.overall,
+ // Distance is the complement of similarity in [0,1]
+ distance: Number((1 - sim.overall).toFixed(4)),
+ components: sim.components,
+ verdict: sim.overall >= 0.95 ? 'near-identical'
+ : sim.overall >= 0.80 ? 'minor-drift'
+ : sim.overall >= 0.50 ? 'moderate-drift'
+ : 'major-drift',
+ };
+ } else {
+ structuralDistance = {
+ verdict: 'unavailable',
+ reason: 'one or both records predate iter-38 oia-audit fingerprint bundling',
+ };
+ }
+
+ // Distance alert is independent of severity worsening β€” a harness can
+ // structurally drift while keeping the same worst-severity verdict.
+ const distanceAlertTriggered = ARGS.alertOnDistanceBelow != null
+ && structuralDistance.overall != null
+ && structuralDistance.overall < ARGS.alertOnDistanceBelow;
+
const payload = {
baseline: {
startedAt: baseline.startedAt,
@@ -150,12 +187,17 @@ function main() {
introduced: introduced.slice(0, 20), // truncate for output sanity
cleared: cleared.slice(0, 20),
},
+ // iter 38 β€” structural distance via ADR-152 Β§3.1
+ structuralDistance,
},
- alert: ARGS.alertOnWorsening ? {
- triggered: worsened,
- reason: worsened
- ? `composite worst ${baseWorst} β†’ ${currWorst}`
- : `composite worst stable or improved (${baseWorst} β†’ ${currWorst})`,
+ alert: (ARGS.alertOnWorsening || ARGS.alertOnDistanceBelow != null) ? {
+ triggered: worsened || distanceAlertTriggered,
+ reasons: [
+ ARGS.alertOnWorsening && worsened
+ ? `composite worst ${baseWorst} β†’ ${currWorst}` : null,
+ distanceAlertTriggered
+ ? `structural similarity ${structuralDistance.overall} < threshold ${ARGS.alertOnDistanceBelow}` : null,
+ ].filter(Boolean),
} : null,
generatedAt: new Date().toISOString(),
};
@@ -196,8 +238,26 @@ function main() {
}
}
console.log('');
+ // iter 38 β€” structural distance row
+ if (structuralDistance.verdict !== 'unavailable') {
+ console.log(`## Structural distance (ADR-152 Β§3.1)`);
+ console.log('');
+ console.log(`| Metric | Value |`);
+ console.log(`|---|---:|`);
+ console.log(`| overall similarity | ${structuralDistance.overall.toFixed(4)} |`);
+ console.log(`| distance (1 βˆ’ sim) | ${structuralDistance.distance.toFixed(4)} |`);
+ console.log(`| verdict | **${structuralDistance.verdict}** |`);
+ console.log('');
+ } else {
+ console.log(`Structural distance: _unavailable β€” ${structuralDistance.reason}_`);
+ console.log('');
+ }
if (payload.alert) {
- console.log(payload.alert.triggered ? `⚠ **ALERT**: ${payload.alert.reason}` : `βœ“ ${payload.alert.reason}`);
+ if (payload.alert.triggered) {
+ console.log(`⚠ **ALERT**: ${payload.alert.reasons.join('; ')}`);
+ } else {
+ console.log(`βœ“ no alert triggered`);
+ }
}
}
diff --git a/plugins/ruflo-metaharness/scripts/oia-audit.mjs b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
index d25ecd75c4..cf0537ac77 100755
--- a/plugins/ruflo-metaharness/scripts/oia-audit.mjs
+++ b/plugins/ruflo-metaharness/scripts/oia-audit.mjs
@@ -84,10 +84,15 @@ function main() {
const oia = runOne(['oia-manifest', ARGS.path], 'oia-manifest');
const tm = runOne(['threat-model', ARGS.path], 'threat-model');
const mcp = runOne(['mcp-scan', ARGS.path], 'mcp-scan');
+ // iter 38 β€” bundle score + genome so audit-trend can compute structural
+ // distance via _similarity.mjs (ADR-152 Β§3.1 dep). Both are pure-read
+ // and degrade gracefully like the other three.
+ const score = runOne(['score', ARGS.path], 'score');
+ const genome = runOne(['genome', ARGS.path], 'genome');
- // If all three say "metaharness not available", surface the degraded
+ // If all FIVE say "metaharness not available", surface the degraded
// payload exactly once and exit 0 (architectural constraint #3).
- if (oia.degraded && tm.degraded && mcp.degraded) {
+ if (oia.degraded && tm.degraded && mcp.degraded && score.degraded && genome.degraded) {
emitDegradedJsonAndExit('metaharness-not-available');
return;
}
@@ -116,7 +121,14 @@ function main() {
startedAt,
finishedAt: new Date().toISOString(),
composite: { worst: compositeWorst, threatModelWorst: tmWorst, mcpScanWorst: mcpWorst },
- components: { oiaManifest: oia, threatModel: tm, mcpScan: mcp },
+ components: { oiaManifest: oia, threatModel: tm, mcpScan: mcp, score, genome },
+ // iter 38 β€” denormalized harness fingerprint for cheap similarity().
+ // Mirrors the shape `_similarity.mjs::similarity()` expects so
+ // audit-trend can call it without reshuffling components.
+ fingerprint: {
+ score: score?.json && !score.degraded ? score.json : null,
+ genome: genome?.json && !genome.degraded ? genome.json : null,
+ },
alert: ARGS.alertWorst !== null ? {
threshold: ARGS.alertWorst,
triggered: alertTriggered,
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index 0cfdf850ed..dffb41fbe9 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -191,6 +191,37 @@ 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 "17z. ADR-152 Β§3.1 deep integration β€” oia-audit fingerprint + audit-trend structuralDistance (iter 38)"
+miss=""
+# oia-audit captures score + genome AND surfaces a fingerprint{score,genome}
+OIA="$ROOT/scripts/oia-audit.mjs"
+grep -q "score = runOne(\['score'" "$OIA" 2>/dev/null || miss="$miss no-score-capture"
+grep -q "genome = runOne(\['genome'" "$OIA" 2>/dev/null || miss="$miss no-genome-capture"
+grep -q "fingerprint: {" "$OIA" 2>/dev/null || miss="$miss no-fingerprint-field"
+# audit-trend imports the production similarity module and surfaces a verdict
+AT="$ROOT/scripts/audit-trend.mjs"
+grep -q "from './_similarity.mjs'" "$AT" 2>/dev/null || miss="$miss no-similarity-import"
+grep -q "structuralDistance" "$AT" 2>/dev/null || miss="$miss no-structural-distance-field"
+grep -q "near-identical\|minor-drift\|moderate-drift\|major-drift" "$AT" 2>/dev/null || miss="$miss no-verdict-thresholds"
+grep -q -- "--alert-on-distance-below" "$AT" 2>/dev/null || miss="$miss no-distance-alert-flag"
+# Runtime: graceful fallback when fingerprint missing (no crash on old records)
+TMPOLD=$(mktemp); TMPNEW=$(mktemp)
+cat > "$TMPOLD" <<'JSON'
+{"startedAt":"2026-06-01T00:00:00Z","composite":{"worst":"clean"},"components":{"oiaManifest":{},"threatModel":{},"mcpScan":{"json":{"findings":[]}}}}
+JSON
+cat > "$TMPNEW" <<'JSON'
+{"startedAt":"2026-06-15T00:00:00Z","composite":{"worst":"clean"},"components":{"oiaManifest":{},"threatModel":{},"mcpScan":{"json":{"findings":[]}}},"fingerprint":{"score":{"harnessFit":82,"recommendedMode":"CLI + MCP","archetype":"typescript-sdk-harness","template":"vertical:coding"},"genome":{"repo_type":"node_mcp_ci","agent_topology":["maintainer","tester"],"risk_score":0.3}}}
+JSON
+OUT=$(node "$AT" --baseline "$TMPOLD" --current "$TMPNEW" --format json 2>/dev/null)
+echo "$OUT" | grep -q '"verdict": "unavailable"' || miss="$miss no-graceful-fallback"
+# Runtime: structural-distance path emits a numeric overall when both have fingerprints
+cp "$TMPNEW" "$TMPOLD"
+OUT2=$(node "$AT" --baseline "$TMPOLD" --current "$TMPNEW" --format json 2>/dev/null)
+echo "$OUT2" | grep -q '"verdict": "near-identical"' || miss="$miss no-near-identical-self"
+echo "$OUT2" | grep -q '"distance": 0' || miss="$miss self-distance-not-zero"
+rm -f "$TMPOLD" "$TMPNEW"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17y. ADR-152 production β€” _similarity.mjs module + similarity.mjs skill + MCP tool + dispatcher (iter 36)"
miss=""
# Production module