mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 14:16:34 +09:00
feat(metaharness): oia-audit composite worker — Phase 2 worker #13 (iter 7)
ADR-150 Phase 2 ships the 13th background worker. `harness-oia-audit` bundles three orthogonal MetaHarness static-analysis surfaces into one timestamped audit record: - harness oia-manifest (Open Infrastructure Architecture L1-L9) - harness threat-model (categorized MCP-surface threats) - harness mcp-scan (per-server/tool policy + perms + deps) The combined record is persisted to memory namespace `metaharness-audit` keyed by ISO timestamp. Designed for weekly cron — accumulated audit records enable drift detection over time via memory list/retrieve. COMPOSITE SEVERITY composite.worst = max(threatModel.worst, max(mcpScan.findings.severity)) Ranked: clean < low < medium < high --alert-on-worst <severity> exits 1 when composite ≥ threshold. Recommended CI default: --alert-on-worst high (fails on HIGH only). GRACEFUL DEGRADATION (ADR-150 rule #3) - When ALL three components report metaharness-not-available, emits the standard degraded payload and exits 0. - When only some are degraded, each component carries its own degraded:true flag — the audit runs partial and persists what it could gather. - --dry-run skips memory persistence (local-only mode). WIRED - scripts/oia-audit.mjs (~155 LOC) - skills/harness-oia-audit/SKILL.md - commands/ruflo-metaharness.md — new harness oia-audit subcommand - agents/metaharness-architect.md — 5 → 6 skills table - Smoke step 2 enumeration updated (5 → 6 skills) - Smoke step 17c: structural invariants for all 3 component invocations, composite severity computation, memory persistence, alert flag, exit semantics CRON WIRING (deferred) The workflow file (.github/workflows/oia-audit-weekly.yml) is left for a follow-up — needs decision on cron timing + alert escalation path. The script itself is ready: `cron: '17 4 * * 0'` weekly Sunday 04:17 UTC works as the canonical default. Smoke: 18 → 19. Fleet: 33/33. Three audits green. Co-Authored-By: RuFlo <ruv@ruv.net>
This commit is contained in:
1 parent
d941846e78
commit
88bff4759f
5 files changed
+267
-3
No files matched your search
@@ -25,7 +25,7 @@ keeping ruflo independently operational at all times.
|
||||
If a PR breaks any of these four rules, it is a breaking change and
|
||||
needs its own ADR.
|
||||
|
||||
## Skills (5 — what each does, when to invoke)
|
||||
## Skills (6 — what each does, when to invoke)
|
||||
|
||||
| Skill | Role | Invoke when |
|
||||
|---|---|---|
|
||||
@@ -33,6 +33,7 @@ needs its own ADR.
|
||||
| `harness-genome` | 7-section categorical report | Pre-mint architecture review; drift detection over time |
|
||||
| `harness-mcp-scan` | Static MCP security findings | Every PR; enterprise security review |
|
||||
| `harness-threat-model` | Categorized threat report | Pre-launch review; periodic OIA-audit cadence |
|
||||
| `harness-oia-audit` | Composite weekly audit worker (iter 7) | Cron-scheduled; bundles oia+threat+mcp into one timestamped record in `metaharness-audit` namespace |
|
||||
| `harness-mint` | Scaffold a custom harness | User wants to fork; ALWAYS dry-run first, never write to project root |
|
||||
|
||||
## Tools (subprocess-only, no library imports)
|
||||
|
||||
@@ -31,6 +31,13 @@ shared helper; no library imports on ruflo's boot path.
|
||||
3. Output suitable for sharing with security/infosec team
|
||||
4. Will be auto-fired by the Phase-2 oia-audit background worker on a schedule
|
||||
|
||||
**`harness oia-audit [--path .] [--dry-run] [--alert-on-worst clean|low|medium|high] [--format table|json]`** -- Phase-2 composite worker (ADR-150). Bundles oia-manifest + threat-model + mcp-scan into one timestamped audit record, stores in `metaharness-audit` memory namespace.
|
||||
1. Run `node plugins/ruflo-metaharness/scripts/oia-audit.mjs`
|
||||
2. Composite worst-severity = max(threatModel.worst, mcpScan.findings.severity)
|
||||
3. `--alert-on-worst high` exits 1 when composite ≥ high — CI weekly drift gate
|
||||
4. `--dry-run` skips memory persistence — useful for local checks
|
||||
5. Designed for cron schedule: weekly snapshot enables audit drift tracking via memory diff
|
||||
|
||||
**`harness mint --name <id> --template <vertical:coding|minimal|…> [--host claude-code|codex|…] [--target /abs/path] [--confirm] [--format table|json]`** -- Scaffold a custom AI agent harness. DRY-RUN by default; --confirm required to write.
|
||||
1. Run `node plugins/ruflo-metaharness/scripts/mint.mjs --name <id> --template <id> --host <id>`
|
||||
2. **Safety**: refuses to write to the calling repo root or any path inside it; defaults to `/tmp/ruflo-mint-<ts>-<name>/`
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
#!/usr/bin/env node
|
||||
// oia-audit.mjs — composite Phase-2 worker (ADR-150).
|
||||
//
|
||||
// Bundles three MetaHarness static-analysis surfaces into one timestamped
|
||||
// audit record:
|
||||
// - harness oia-manifest (Open Infrastructure Architecture L1-L9 alignment)
|
||||
// - harness threat-model (categorized MCP-surface threat report)
|
||||
// - harness mcp-scan (per-server/tool policy + permissions + deps)
|
||||
//
|
||||
// The combined record is stored in the `metaharness-audit` memory
|
||||
// namespace, keyed by ISO timestamp. Designed to be invoked on a cron
|
||||
// schedule (e.g. weekly) so audit drift is visible over time.
|
||||
//
|
||||
// USAGE
|
||||
// node scripts/oia-audit.mjs # run + store
|
||||
// node scripts/oia-audit.mjs --path <dir> # audit specific dir
|
||||
// node scripts/oia-audit.mjs --dry-run # don't write to memory
|
||||
// node scripts/oia-audit.mjs --alert-on-worst high
|
||||
// # exit 1 if threat-model worst >= high
|
||||
// node scripts/oia-audit.mjs --format json
|
||||
//
|
||||
// EXIT CODES
|
||||
// 0 audit OK (or degraded)
|
||||
// 1 --alert-on-worst threshold exceeded
|
||||
// 2 config error or audit failure
|
||||
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { runHarness, emitDegradedJsonAndExit } from './_harness.mjs';
|
||||
|
||||
const SEVERITY_RANK = { clean: 0, low: 1, medium: 2, high: 3 };
|
||||
const NS = process.env.OIA_AUDIT_NAMESPACE || 'metaharness-audit';
|
||||
const CLI_PKG = process.env.CLI_CORE === '1'
|
||||
? '@claude-flow/cli-core@alpha'
|
||||
: '@claude-flow/cli@latest';
|
||||
|
||||
const ARGS = (() => {
|
||||
const a = { path: '.', format: 'json', dryRun: false, alertWorst: null };
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
const v = process.argv[i];
|
||||
if (v === '--path') a.path = process.argv[++i];
|
||||
else if (v === '--dry-run') a.dryRun = true;
|
||||
else if (v === '--alert-on-worst') a.alertWorst = String(process.argv[++i] || '').toLowerCase();
|
||||
else if (v === '--format') a.format = process.argv[++i];
|
||||
}
|
||||
return a;
|
||||
})();
|
||||
|
||||
function runOne(args, label) {
|
||||
const r = runHarness(args);
|
||||
return {
|
||||
label,
|
||||
exitCode: r.exitCode,
|
||||
degraded: r.degraded,
|
||||
reason: r.degraded ? r.reason : null,
|
||||
json: r.json,
|
||||
durationMs: r.durationMs,
|
||||
stderrTail: r.degraded ? (r.stderr || '').slice(-200) : null,
|
||||
};
|
||||
}
|
||||
|
||||
function persist(payload) {
|
||||
const key = `audit-${new Date().toISOString().replace(/[:.]/g, '-')}`;
|
||||
const r = spawnSync('npx', [
|
||||
CLI_PKG, 'memory', 'store',
|
||||
'--namespace', NS,
|
||||
'--key', key,
|
||||
'--value', JSON.stringify(payload),
|
||||
], { stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf-8', shell: process.platform === 'win32' });
|
||||
return {
|
||||
ok: r.status === 0,
|
||||
namespace: NS,
|
||||
key,
|
||||
error: r.status === 0 ? null : (r.stderr || '').slice(0, 200),
|
||||
};
|
||||
}
|
||||
|
||||
function main() {
|
||||
if (ARGS.alertWorst !== null && !SEVERITY_RANK.hasOwnProperty(ARGS.alertWorst)) {
|
||||
console.error(`oia-audit: --alert-on-worst must be one of clean|low|medium|high; got ${ARGS.alertWorst}`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const startedAt = new Date().toISOString();
|
||||
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');
|
||||
|
||||
// If all three say "metaharness not available", surface the degraded
|
||||
// payload exactly once and exit 0 (architectural constraint #3).
|
||||
if (oia.degraded && tm.degraded && mcp.degraded) {
|
||||
emitDegradedJsonAndExit('metaharness-not-available');
|
||||
return;
|
||||
}
|
||||
|
||||
// Aggregate the worst-severity signal across mcp-scan + threat-model.
|
||||
const tmWorst = String(tm.json?.worst || 'clean').toLowerCase();
|
||||
const mcpFindings = Array.isArray(mcp.json?.findings) ? mcp.json.findings : [];
|
||||
const mcpWorst = mcpFindings.reduce((acc, f) => {
|
||||
const s = String(f.severity || 'low').toLowerCase();
|
||||
return SEVERITY_RANK[s] > SEVERITY_RANK[acc] ? s : acc;
|
||||
}, 'clean');
|
||||
const compositeWorst = SEVERITY_RANK[tmWorst] > SEVERITY_RANK[mcpWorst] ? tmWorst : mcpWorst;
|
||||
|
||||
let alertTriggered = false;
|
||||
let alertReason = null;
|
||||
if (ARGS.alertWorst !== null) {
|
||||
const threshold = SEVERITY_RANK[ARGS.alertWorst];
|
||||
if (SEVERITY_RANK[compositeWorst] >= threshold && threshold > 0) {
|
||||
alertTriggered = true;
|
||||
alertReason = `composite worst=${compositeWorst} ≥ ${ARGS.alertWorst}`;
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
path: ARGS.path,
|
||||
startedAt,
|
||||
finishedAt: new Date().toISOString(),
|
||||
composite: { worst: compositeWorst, threatModelWorst: tmWorst, mcpScanWorst: mcpWorst },
|
||||
components: { oiaManifest: oia, threatModel: tm, mcpScan: mcp },
|
||||
alert: ARGS.alertWorst !== null ? {
|
||||
threshold: ARGS.alertWorst,
|
||||
triggered: alertTriggered,
|
||||
reason: alertReason || `composite worst=${compositeWorst} < ${ARGS.alertWorst} — OK`,
|
||||
} : null,
|
||||
persisted: null,
|
||||
};
|
||||
|
||||
if (!ARGS.dryRun) {
|
||||
payload.persisted = persist(payload);
|
||||
}
|
||||
|
||||
if (ARGS.format === 'json') {
|
||||
console.log(JSON.stringify(payload, null, 2));
|
||||
} else {
|
||||
console.log(`# oia-audit — ${ARGS.path}`);
|
||||
console.log('');
|
||||
console.log(`| Component | Exit | Degraded | Duration |`);
|
||||
console.log(`|---|---:|:---:|---:|`);
|
||||
console.log(`| oia-manifest | ${oia.exitCode} | ${oia.degraded ? '⚠' : '✓'} | ${oia.durationMs}ms |`);
|
||||
console.log(`| threat-model | ${tm.exitCode} | ${tm.degraded ? '⚠' : '✓'} | ${tm.durationMs}ms |`);
|
||||
console.log(`| mcp-scan | ${mcp.exitCode} | ${mcp.degraded ? '⚠' : '✓'} | ${mcp.durationMs}ms |`);
|
||||
console.log('');
|
||||
console.log(`Composite worst severity: **${compositeWorst}** (tm=${tmWorst}, mcp=${mcpWorst})`);
|
||||
if (payload.persisted) {
|
||||
console.log(`Persisted: ${payload.persisted.ok ? `${payload.persisted.namespace}:${payload.persisted.key}` : `FAILED: ${payload.persisted.error}`}`);
|
||||
}
|
||||
if (payload.alert) {
|
||||
console.log('');
|
||||
console.log(payload.alert.triggered ? `⚠ **ALERT**: ${payload.alert.reason}` : `✓ ${payload.alert.reason}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (alertTriggered) process.exit(1);
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -20,9 +20,9 @@ else
|
||||
[[ -z "$miss" ]] && ok || bad "missing keywords:$miss"
|
||||
fi
|
||||
|
||||
step "2. all five skills present with valid frontmatter"
|
||||
step "2. all six skills present with valid frontmatter"
|
||||
miss=""
|
||||
for s in harness-score harness-genome harness-mint harness-mcp-scan harness-threat-model; do
|
||||
for s in harness-score harness-genome harness-mint harness-mcp-scan harness-threat-model harness-oia-audit; do
|
||||
f="$ROOT/skills/$s/SKILL.md"
|
||||
[[ -f "$f" ]] || { miss="$miss missing-$s"; continue; }
|
||||
for k in 'name:' 'description:' 'allowed-tools:'; do
|
||||
@@ -170,6 +170,27 @@ if (!od.metaharness) { console.error('missing metaharness in optionalDependencie
|
||||
if (j.dependencies && j.dependencies.metaharness) { console.error('metaharness leaked into dependencies'); process.exit(1); }
|
||||
" 2>/dev/null && ok || bad "ruflo wrapper missing metaharness optionalDep"
|
||||
|
||||
step "17c. oia-audit composite worker (Phase 2 — iter 7)"
|
||||
F="$ROOT/scripts/oia-audit.mjs"
|
||||
miss=""
|
||||
[[ -x "$F" ]] || miss="$miss not-executable"
|
||||
node --check "$F" 2>/dev/null || miss="$miss syntax-error"
|
||||
grep -q "runHarness" "$F" || miss="$miss no-runner"
|
||||
# All three component invocations
|
||||
grep -q "oia-manifest" "$F" || miss="$miss no-oia-manifest"
|
||||
grep -q "threat-model" "$F" || miss="$miss no-threat-model"
|
||||
grep -q "mcp-scan" "$F" || miss="$miss no-mcp-scan"
|
||||
# Composite severity computation
|
||||
grep -q "compositeWorst\|composite.*Worst" "$F" || miss="$miss no-composite-severity"
|
||||
grep -q "SEVERITY_RANK" "$F" || miss="$miss no-severity-rank"
|
||||
# Memory persistence (default behavior, --dry-run to skip)
|
||||
grep -q "metaharness-audit" "$F" || miss="$miss no-namespace"
|
||||
grep -q "memory.*store" "$F" || miss="$miss no-memory-store"
|
||||
# Alert exit code
|
||||
grep -q "alert-on-worst" "$F" || miss="$miss no-alert-flag"
|
||||
grep -q "process.exit(1)" "$F" || miss="$miss no-fail-closed"
|
||||
[[ -z "$miss" ]] && ok || bad "$miss"
|
||||
|
||||
step "17b. harness type in plugin registry (Phase 2 — iter 6)"
|
||||
F="$ROOT/../../v3/@claude-flow/cli/src/plugins/store/types.ts"
|
||||
miss=""
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
---
|
||||
name: harness-oia-audit
|
||||
description: Composite Phase-2 audit worker (ADR-150). Bundles harness oia-manifest + threat-model + mcp-scan into one timestamped audit record stored in the `metaharness-audit` memory namespace. Designed for cron-scheduled drift detection.
|
||||
argument-hint: "[--path .] [--dry-run] [--alert-on-worst clean|low|medium|high] [--format table|json]"
|
||||
allowed-tools: Bash
|
||||
---
|
||||
|
||||
The 13th worker (ADR-150 Phase 2) — runs three MetaHarness static
|
||||
surfaces in one shot, computes a composite worst-severity signal, and
|
||||
persists the audit record to memory so drift over time is visible.
|
||||
|
||||
## Algorithm
|
||||
|
||||
Implementation: [`scripts/oia-audit.mjs`](../../scripts/oia-audit.mjs).
|
||||
|
||||
1. Run `harness oia-manifest <path>` — Open Infrastructure Architecture
|
||||
layer alignment (L1-L9).
|
||||
2. Run `harness threat-model <path>` — categorized MCP-surface threat
|
||||
report with `worst: clean|low|medium|high`.
|
||||
3. Run `harness mcp-scan <path>` — per-server/tool policy + permissions
|
||||
+ dep findings.
|
||||
4. Composite worst = `max(threatModel.worst, max(mcpScan.findings.severity))`.
|
||||
5. Persist payload to memory namespace `metaharness-audit` with key
|
||||
`audit-<iso-timestamp>` (unless `--dry-run`).
|
||||
6. `--alert-on-worst <severity>`: exit 1 if composite worst ≥ threshold.
|
||||
|
||||
## Graceful degradation
|
||||
|
||||
When ALL three components report `metaharness-not-available`, the script
|
||||
emits the standard degraded payload and exits 0. When only some are
|
||||
degraded, each individual component carries its own `degraded: true`
|
||||
flag in the audit record — the audit still runs and persists what it
|
||||
could gather.
|
||||
|
||||
## CI / cron integration
|
||||
|
||||
Designed for weekly cron in `.github/workflows/`:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
schedule:
|
||||
- cron: '17 4 * * 0' # Sundays at 04:17 UTC
|
||||
jobs:
|
||||
oia-audit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
- run: node plugins/ruflo-metaharness/scripts/oia-audit.mjs --alert-on-worst high
|
||||
```
|
||||
|
||||
`--alert-on-worst high` fails the job on any HIGH-severity finding;
|
||||
drift below HIGH is logged but doesn't block.
|
||||
|
||||
## Memory namespace
|
||||
|
||||
Each audit run stores under `metaharness-audit:audit-<iso-ts>`. To list
|
||||
recent audits:
|
||||
|
||||
```bash
|
||||
npx @claude-flow/cli@latest memory list --namespace metaharness-audit --limit 10
|
||||
```
|
||||
|
||||
To diff two audits (drift detection):
|
||||
|
||||
```bash
|
||||
A=$(npx ... memory retrieve --key audit-2026-06-01... --namespace metaharness-audit)
|
||||
B=$(npx ... memory retrieve --key audit-2026-06-15... --namespace metaharness-audit)
|
||||
# Compare composite.worst, components.threatModel.worst, etc.
|
||||
```
|
||||
|
||||
A future ADR can wire this into a dedicated `cost-diff`-style diff
|
||||
viewer specifically for audit drift.
|
||||
|
||||
## Pairs with
|
||||
|
||||
- `harness-threat-model` — the underlying threat-model component
|
||||
- `harness-mcp-scan` — the underlying MCP-scan component
|
||||
- `harness-score` + `harness-genome` — readiness metrics (orthogonal to audit)
|
||||
Reference in new issue
Block a user