π 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
feat(metaharness): ADR-152 spike landed β similarity invariants pass, ADR Accepted (iter 35)
ruv9de004b3f6fe
diff --git a/plugins/ruflo-metaharness/scripts/_spike-similarity.mjs b/plugins/ruflo-metaharness/scripts/_spike-similarity.mjsnew file mode 100755index 0000000000..c0f34f6c8a--- /dev/null+++ b/plugins/ruflo-metaharness/scripts/_spike-similarity.mjs@@ -0,0 +1,223 @@+#!/usr/bin/env node+// _spike-similarity.mjs β ADR-152 Β§"Smallest demonstrable spike" gate.+//+// This file is the implementation gate for ADR-152 (Genome Similarity Search).+// Per ADR-151's scope-only constraint, ADR-152 cannot graduate to "Accepted"+// until the two invariants below are proven by running this script.+//+// THE TWO INVARIANTS (from ADR-152 Β§"Smallest demonstrable spike")+// 1. similarity(X, X) === 1 (self-match exact)+// 2. similarity(legal, devops) < similarity(legal, support)+// (vertical-affinity correct)+//+// USAGE+// node scripts/_spike-similarity.mjs (run + assert)+// node scripts/_spike-similarity.mjs --format json (CI-consumable)+//+// EXIT CODES+// 0 both invariants hold+// 1 at least one invariant fails (ADR-152 cannot graduate)+//+// LIFECYCLE+// Once ADR-152 is Accepted, the full similarity implementation lands in+// `_similarity.mjs` (production module). This file (`_spike-similarity.mjs`)+// remains as the regression-suite anchor for the two invariants.++const ARGS = (() => {+ const a = { format: 'table' };+ for (let i = 2; i < process.argv.length; i++) {+ if (process.argv[i] === '--format') a.format = process.argv[++i];+ }+ return a;+})();++// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+// THE PROPOSED IMPLEMENTATION (ADR-152 Β§"Decision")+//+// Pure-TS. Takes two {genome, score} JSON shapes; emits {overall,+// components: {cosine, categorical, jaccard}}. The 9 numerical features ++// 4 categorical fields + 1 set field per ADR-152.+// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++function projectToVec(input) {+ const s = input.score || {};+ const g = input.genome || {};+ return [+ (s.harnessFit ?? 0) / 100,+ (s.compileConfidence ?? 0) / 100,+ (s.taskCoverage ?? 0) / 100,+ (s.toolSafety ?? 0) / 100,+ (s.memoryUsefulness ?? 0) / 100,+ g.risk_score ?? 0,+ g.test_confidence ?? 0,+ g.publish_readiness ?? 0,+ // estCostPerRunUsd: log10 transform, clamped to [0, 1]+ Math.max(0, Math.min(1, Math.log10((s.estCostPerRunUsd ?? 0) + 0.001) / Math.log10(10))),+ ];+}++function cosine(a, b) {+ let dot = 0, na = 0, nb = 0;+ for (let i = 0; i < a.length; i++) {+ dot += a[i] * b[i];+ na += a[i] * a[i];+ nb += b[i] * b[i];+ }+ const denom = Math.sqrt(na) * Math.sqrt(nb);+ if (denom === 0) return 0;+ // Map cosine from [-1, 1] to [0, 1] for nonnegative vectors it's [0, 1] already+ return Math.max(0, Math.min(1, dot / denom));+}++function categoricalAgreement(a, b) {+ const fields = ['repo_type', 'archetype', 'template', 'recommendedMode'];+ let matches = 0;+ for (const f of fields) {+ const av = a.genome?.[f] ?? a.score?.[f];+ const bv = b.genome?.[f] ?? b.score?.[f];+ if (av && bv && av === bv) matches++;+ }+ return matches / fields.length;+}++function jaccard(a, b) {+ const A = new Set(a.genome?.agent_topology ?? []);+ const B = new Set(b.genome?.agent_topology ?? []);+ if (A.size === 0 && B.size === 0) return 1;+ const intersection = [...A].filter((x) => B.has(x)).length;+ const union = new Set([...A, ...B]).size;+ return union === 0 ? 0 : intersection / union;+}++function similarity(a, b) {+ const cos = cosine(projectToVec(a), projectToVec(b));+ const cat = categoricalAgreement(a, b);+ const jac = jaccard(a, b);+ const overall = 0.6 * cos + 0.25 * cat + 0.15 * jac;+ return {+ overall: Math.round(overall * 10000) / 10000,+ components: {+ cosine: Math.round(cos * 10000) / 10000,+ categorical: Math.round(cat * 10000) / 10000,+ jaccard: Math.round(jac * 10000) / 10000,+ },+ };+}++// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+// THREE SYNTHETIC FIXTURES designed to exercise the invariants. These+// mirror the JSON shapes `harness genome` + `harness score` emit (verified+// against [email protected] via iter-26 test-with-openrouter.mjs).+// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++const LEGAL = {+ score: {+ harnessFit: 78, compileConfidence: 92, taskCoverage: 65,+ toolSafety: 88, memoryUsefulness: 70, estCostPerRunUsd: 0.04,+ recommendedMode: 'CLI + MCP', archetype: 'compliance-harness',+ template: 'vertical:legal', scaffoldReady: true,+ },+ genome: {+ repo_type: 'node_mcp_ci',+ agent_topology: ['contract-analyst', 'redline-reviewer', 'risk-rater', 'compliance-officer'],+ risk_score: 0.45,+ mcp_surface: 'remote',+ test_confidence: 0.7,+ publish_readiness: 0.6,+ },+};++const SUPPORT = {+ score: {+ harnessFit: 75, compileConfidence: 90, taskCoverage: 70,+ toolSafety: 90, memoryUsefulness: 72, estCostPerRunUsd: 0.05,+ recommendedMode: 'CLI + MCP', archetype: 'compliance-harness',+ template: 'vertical:support', scaffoldReady: true,+ },+ genome: {+ repo_type: 'node_mcp_ci',+ agent_topology: ['triager', 'kb-searcher', 'responder', 'risk-rater', 'compliance-officer'],+ risk_score: 0.40,+ mcp_surface: 'remote',+ test_confidence: 0.75,+ publish_readiness: 0.65,+ },+};++const DEVOPS = {+ score: {+ harnessFit: 88, compileConfidence: 95, taskCoverage: 85,+ toolSafety: 70, memoryUsefulness: 55, estCostPerRunUsd: 0.08,+ recommendedMode: 'CLI', archetype: 'cli-operator-harness',+ template: 'vertical:devops', scaffoldReady: true,+ },+ genome: {+ repo_type: 'python_ops',+ agent_topology: ['incident-commander', 'deployer', 'rollback', 'oncall-pager'],+ risk_score: 0.25,+ mcp_surface: 'local',+ test_confidence: 0.85,+ publish_readiness: 0.9,+ },+};++// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+// INVARIANT VERIFICATION (the gate)+// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ++const self = similarity(LEGAL, LEGAL);+const legalVsSupport = similarity(LEGAL, SUPPORT);+const legalVsDevops = similarity(LEGAL, DEVOPS);++const inv1Pass = self.overall === 1;+const inv2Pass = legalVsDevops.overall < legalVsSupport.overall;++const payload = {+ adr: 'ADR-152',+ spike: '_spike-similarity.mjs',+ invariants: {+ selfMatch: { pass: inv1Pass, value: self.overall, expected: 1 },+ verticalAffinity: {+ pass: inv2Pass,+ legalVsDevops: legalVsDevops.overall,+ legalVsSupport: legalVsSupport.overall,+ reason: inv2Pass+ ? `legal:devops (${legalVsDevops.overall}) < legal:support (${legalVsSupport.overall}) β vertical affinity correct`+ : `INVARIANT VIOLATED: legal:devops (${legalVsDevops.overall}) β₯ legal:support (${legalVsSupport.overall})`,+ },+ },+ detail: {+ 'similarity(LEGAL, LEGAL)': self,+ 'similarity(LEGAL, SUPPORT)': legalVsSupport,+ 'similarity(LEGAL, DEVOPS)': legalVsDevops,+ },+ graduates: inv1Pass && inv2Pass,+ generatedAt: new Date().toISOString(),+};++if (ARGS.format === 'json') {+ console.log(JSON.stringify(payload, null, 2));+} else {+ console.log(`# ADR-152 Β§Spike β Genome Similarity Search\n`);+ console.log(`Invariant 1 β selfMatch:`);+ console.log(` similarity(LEGAL, LEGAL).overall = ${self.overall}`);+ console.log(` expected: 1`);+ console.log(` ${inv1Pass ? 'β PASS' : 'β FAIL'}`);+ console.log('');+ console.log(`Invariant 2 β verticalAffinity (legal closer to support than to devops):`);+ console.log(` similarity(LEGAL, SUPPORT).overall = ${legalVsSupport.overall}`);+ console.log(` similarity(LEGAL, DEVOPS).overall = ${legalVsDevops.overall}`);+ console.log(` ${inv2Pass ? 'β PASS' : 'β FAIL'} β ${payload.invariants.verticalAffinity.reason}`);+ console.log('');+ console.log(`Per-component breakdown:`);+ console.log(` LEGAL vs SUPPORT β cosine=${legalVsSupport.components.cosine} categorical=${legalVsSupport.components.categorical} jaccard=${legalVsSupport.components.jaccard}`);+ console.log(` LEGAL vs DEVOPS β cosine=${legalVsDevops.components.cosine} categorical=${legalVsDevops.components.categorical} jaccard=${legalVsDevops.components.jaccard}`);+ console.log('');+ if (payload.graduates) {+ console.log(`β Both invariants hold. ADR-152 may graduate Proposed β Accepted.`);+ } else {+ console.log(`β Invariant violation. ADR-152 stays Proposed.`);+ }+}++if (!payload.graduates) process.exit(1);diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.shindex 4f47247988..1e0438e629 100755--- a/plugins/ruflo-metaharness/scripts/smoke.sh+++ b/plugins/ruflo-metaharness/scripts/smoke.sh@@ -191,6 +191,30 @@ 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 "17x. ADR-152 spike β similarity invariants verified at structural level (iter 35)"+F="$ROOT/scripts/_spike-similarity.mjs"+miss=""+[[ -x "$F" ]] || miss="$miss not-executable"+node --check "$F" 2>/dev/null || miss="$miss syntax-error"+# The 3-component similarity formula matches ADR-152's decision+grep -q "0.6 \* cos + 0.25 \* cat + 0.15 \* jac" "$F" || miss="$miss weight-formula-drift"+# Both invariants explicit+grep -q "selfMatch" "$F" || miss="$miss no-invariant-1"+grep -q "verticalAffinity" "$F" || miss="$miss no-invariant-2"+# 3 fixtures (LEGAL/SUPPORT/DEVOPS) β anti-regression+for fix in LEGAL SUPPORT DEVOPS; do+ grep -q "const ${fix} = {" "$F" || miss="$miss missing-fixture-${fix}"+done+# Fail-closed on invariant violation+grep -q "process.exit(1)" "$F" || miss="$miss no-fail-closed"+# ADR-152 status updated to Accepted+ADR152="$ROOT/../../v3/docs/adr/ADR-152-genome-similarity-search.md"+grep -q "Status\*\*: Accepted" "$ADR152" 2>/dev/null || miss="$miss adr152-not-accepted"+# ADR-151 Β§3.1 marker upgraded+PARENT151="$ROOT/../../v3/docs/adr/ADR-151-harness-intelligence-layer.md"+grep -q "ACCEPTED iter 35" "$PARENT151" 2>/dev/null || miss="$miss adr151-marker-stale"+[[ -z "$miss" ]] && ok || bad "$miss"+step "17w. ADR-152 Genome Similarity Search drafted (iter 34, Phase 3 critical-path)"F="$ROOT/../../v3/docs/adr/ADR-152-genome-similarity-search.md"miss=""@@ -208,7 +232,7 @@ grep -q "Smallest demonstrable spike" "$F" 2>/dev/null || miss="$miss no-spike-c# Cross-link from ADR-151 updated to DRAFTEDPARENT151="$ROOT/../../v3/docs/adr/ADR-151-harness-intelligence-layer.md"grep -q "ADR-152-genome-similarity-search.md" "$PARENT151" 2>/dev/null || miss="$miss adr151-not-updated"-grep -q "DRAFTED iter 34" "$PARENT151" 2>/dev/null || miss="$miss adr151-no-drafted-marker"+grep -qE "DRAFTED iter 34|ACCEPTED iter 3[0-9]" "$PARENT151" 2>/dev/null || miss="$miss adr151-no-progress-marker"[[ -z "$miss" ]] && ok || bad "$miss"step "17v. ADR-151 Phase 3 scope shell drafted (iter 33)"diff --git a/v3/docs/adr/ADR-151-harness-intelligence-layer.md b/v3/docs/adr/ADR-151-harness-intelligence-layer.mdindex 8b2080a7a1..b35efb6ae7 100644--- a/v3/docs/adr/ADR-151-harness-intelligence-layer.md+++ b/v3/docs/adr/ADR-151-harness-intelligence-layer.md@@ -31,7 +31,7 @@ Adopt the **Harness Intelligence Layer** as a Phase-3 capability cluster, scoped### Phase-3 sub-capabilities (in implementation-dependency order)-#### 3.1 β Genome Similarity Search ([ADR-152](ADR-152-genome-similarity-search.md), DRAFTED iter 34)+#### 3.1 β Genome Similarity Search ([ADR-152](ADR-152-genome-similarity-search.md), ACCEPTED iter 35 β spike landed, both invariants pass)**What:** Given two harnesses (or one harness + a candidate repo), compute a similarity score across the 7 genome sections and the 5 scorecard dimensions. Return a normalized 0..1 number plus a per-dimension breakdown.diff --git a/v3/docs/adr/ADR-152-genome-similarity-search.md b/v3/docs/adr/ADR-152-genome-similarity-search.mdindex bdbd0beaf1..de472f3ed6 100644--- a/v3/docs/adr/ADR-152-genome-similarity-search.md+++ b/v3/docs/adr/ADR-152-genome-similarity-search.md@@ -1,9 +1,26 @@# ADR-152 β Genome Similarity Search-**Status**: Proposed-**Date**: 2026-06-16+**Status**: Accepted (spike landed iter 35 β both invariants pass)+**Date**: 2026-06-16 (revised same-day with spike result)**Parent**: [ADR-151](ADR-151-harness-intelligence-layer.md) (Phase 3 scope shell β Harness Intelligence Layer)**Inherits**: ADR-150's four architectural constraints (removable / optional / graceful / CI-gate)+**Spike**: `plugins/ruflo-metaharness/scripts/_spike-similarity.mjs` ([iter-35 commit](https://github.com/ruvnet/ruflo/commit/HEAD))++## Spike result (iter 35 β measured)++```+similarity(LEGAL, LEGAL).overall = 1.0000 β Invariant 1 (self-match) β exact+similarity(LEGAL, SUPPORT).overall = 0.8296+similarity(LEGAL, DEVOPS).overall = 0.5840 β Invariant 2 (vertical affinity) β support > devops++Per-component (LEGAL vs SUPPORT): cosine=0.9987 categorical=0.75 jaccard=0.2857+Per-component (LEGAL vs DEVOPS): cosine=0.9734 categorical=0 jaccard=0+```++Notable findings from the spike:+- **Numerical cosine alone is too coarse** β LEGAL vs DEVOPS scored cosine=0.9734 despite being unrelated verticals. The numerics are clustered around similar scorecard ranges. Categorical + jaccard pulled the composite correctly to 0.58 vs 0.83.+- **The 0.6/0.25/0.15 weighting from the Β§Decision section reproduces the intended ordering** on the synthetic LEGAL/SUPPORT/DEVOPS fixtures.+- **`categorical: 0` for LEGAL/DEVOPS** correctly fires because they share no enum field (different archetypes, different templates, different recommendedMode). This is a strong feature of the design β categorical disagreement is a clean kill-switch.## Context