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(ruflo-aidefence): adopt plugin contract + canonicalize 3-gate pattern (ADR-0001)

Reuven9982c701fa9a
diff --git a/plugins/ruflo-aidefence/.claude-plugin/plugin.json b/plugins/ruflo-aidefence/.claude-plugin/plugin.json
index dd9ce19ff8..442aadf860 100644
--- a/plugins/ruflo-aidefence/.claude-plugin/plugin.json
+++ b/plugins/ruflo-aidefence/.claude-plugin/plugin.json
@@ -14,6 +14,9 @@
"safety",
"pii",
"injection",
- "security"
+ "security",
+ "prompt-injection",
+ "defense-in-depth",
+ "mcp"
]
}
diff --git a/plugins/ruflo-aidefence/README.md b/plugins/ruflo-aidefence/README.md
index b7cdaa02f3..a38c940360 100644
--- a/plugins/ruflo-aidefence/README.md
+++ b/plugins/ruflo-aidefence/README.md
@@ -32,3 +32,36 @@ This plugin pairs with three runtime hardening features that ship in the host (A
- `safety-scan` -- Scan inputs for prompt injection and unsafe content
- `pii-detect` -- Detect PII in text, code, and configurations
+
+## Compatibility
+
+- **CLI:** pinned to `@claude-flow/cli` v3.6 major+minor.
+- **MCP surface:** 6 `aidefence_*` tools (`scan`, `analyze`, `stats`, `learn`, `is_safe`, `has_pii`) plus `transfer_detect-pii` for categorized findings.
+- **Verification:** `bash plugins/ruflo-aidefence/scripts/smoke.sh` is the contract.
+
+## The 3-gate pattern (canonical)
+
+Every consumer plugin handling untrusted content should apply these three gates **in order**:
+
+| # | Gate | Tool | When |
+|---|------|------|------|
+| 1 | Pre-storage PII | `aidefence_has_pii` | Before any AgentDB / `memory_store` write β€” redact or quarantine before persistence. |
+| 2 | Sanitization | `aidefence_scan` | For cookies, tokens, high-entropy blobs β€” vault behind an opaque handle rather than embed raw values. |
+| 3 | Prompt-injection | `aidefence_is_safe` | Before any extracted text re-enters an LLM prompt β€” quarantine to `findings.md` if flagged. |
+
+This is the pattern `ruflo-browser` ADR-0001 Β§4 codified and `ruflo-aidefence` ADR-0001 canonicalizes. Reference these gates by name in any new plugin that handles user-supplied content.
+
+## Namespace coordination
+
+This plugin owns the `security-patterns` AgentDB namespace (kebab-case, follows the convention from [ruflo-agentdb ADR-0001 Β§"Namespace convention"](../ruflo-agentdb/docs/adrs/0001-agentdb-optimization.md)). Reserved namespaces (`pattern`, `claude-memories`, `default`) MUST NOT be shadowed.
+
+## Verification
+
+```bash
+bash plugins/ruflo-aidefence/scripts/smoke.sh
+# Expected: "10 passed, 0 failed"
+```
+
+## Architecture Decisions
+
+- [`ADR-0001` β€” ruflo-aidefence plugin contract (pinning, namespace coordination, 3-gate pattern, smoke as contract)](./docs/adrs/0001-aidefence-contract.md)
diff --git a/plugins/ruflo-aidefence/docs/adrs/0001-aidefence-contract.md b/plugins/ruflo-aidefence/docs/adrs/0001-aidefence-contract.md
new file mode 100644
index 0000000000..ad0bdf4435
--- /dev/null
+++ b/plugins/ruflo-aidefence/docs/adrs/0001-aidefence-contract.md
@@ -0,0 +1,87 @@
+---
+id: ADR-0001
+title: ruflo-aidefence plugin contract β€” pinning, namespace coordination, 3-gate pattern, smoke as contract
+status: Proposed
+date: 2026-05-04
+authors:
+ - reviewer (Claude Code)
+tags: [plugin, aidefence, security, pii, prompt-injection, namespace, smoke-test]
+---
+
+## Context
+
+`ruflo-aidefence` documents the AIDefence MCP family (`aidefence_scan`, `_analyze`, `_stats`, `_learn`, `_is_safe`, `_has_pii`) β€” 6 tools at `v3/@claude-flow/cli/src/mcp-tools/security-tools.ts:108, 191, 277, 329, 424, 479`. Plugin is at v0.2.0 with full surface coverage and a "Defence-in-depth pairing" block already documenting the host-level hardening (loader-hijack denylist, file mode 0600, encryption-at-rest opt-in).
+
+Gaps observed against the pattern from `ruflo-ruvector` / `ruflo-agentdb` / `ruflo-browser` / `ruflo-intelligence` / `ruflo-adr` ADRs:
+
+1. **No plugin-level ADR.** Every other plugin updated this session has one.
+2. **No smoke test.**
+3. **Free-form `security-patterns` namespace.** The agent writes there without referencing `ruflo-agentdb` ADR-0001's namespace convention.
+4. **No Compatibility section.**
+5. **The ruflo-browser ADR-0001 Β§4** mandates three AIDefence gates (PII pre-storage, cookie sanitization, prompt-injection check on returned content) β€” `ruflo-aidefence` should canonicalize this 3-gate pattern so other plugins consume it the same way.
+
+## Decision
+
+### 1. Add this ADR (Proposed)
+
+`docs/adrs/0001-aidefence-contract.md`. Cross-links the five sibling ADRs.
+
+### 2. README augmentation
+
+Append three sections, retain existing content:
+
+- **Compatibility** β€” pin to `@claude-flow/cli` v3.6.
+- **Namespace coordination** β€” `security-patterns` as the canonical namespace this plugin owns; defer to `ruflo-agentdb` ADR-0001 Β§"Namespace convention".
+- **The 3-gate pattern** β€” formalize the gates `ruflo-browser` ADR-0001 Β§4 already uses. Three gates, every consumer plugin handling untrusted content should apply them in this order:
+ 1. **Pre-storage PII gate** (`aidefence_has_pii`) β€” before any AgentDB / memory_store write
+ 2. **Sanitization gate** (`aidefence_scan`) β€” for cookies, tokens, high-entropy blobs; vault rather than embed
+ 3. **Prompt-injection gate** (`aidefence_is_safe`) β€” for any extracted content flowing back to an LLM
+- **Architecture Decisions** + **Verification** sections.
+
+### 3. Plugin metadata
+
+`plugin.json` keeps `0.2.0` (already at the cadence). Description retained. Keywords add `prompt-injection`, `defense-in-depth`, `mcp`.
+
+### 4. Smoke contract (`scripts/smoke.sh`)
+
+10 checks:
+
+1. plugin.json declares `0.2.0` with the new keywords.
+2. All 6 `aidefence_*` MCP tools referenced in plugin docs.
+3. `transfer_detect-pii` is also referenced (used by pii-detect skill).
+4. README has Compatibility section pinning to v3.6.
+5. README defers to `ruflo-agentdb` ADR-0001 namespace convention.
+6. README documents the 3-gate pattern (PII pre-storage, sanitization, prompt-injection).
+7. README's "Defence-in-depth pairing" block remains intact (loader-hijack denylist, file mode 0600, encryption-at-rest).
+8. ADR-0001 exists with status `Proposed`.
+9. Both skills (`safety-scan`, `pii-detect`) have valid frontmatter (name + description + allowed-tools).
+10. No skill grants wildcard tool access.
+
+## Consequences
+
+**Positive:**
+- 3-gate pattern is now contractually owned by this plugin; consumer plugins reference it instead of re-deriving.
+- Joins the contract every other plugin updated this session follows.
+- `security-patterns` namespace is now declared.
+
+**Negative:**
+- One downstream plugin (`ruflo-browser`) embeds the 3-gate pattern in its own ADR Β§4. Updating it to defer here is a separate, mechanical task (the gates remain identical; only the canonical home changes).
+
+**Neutral:**
+- No new MCP tools, no new skills, no new commands. Documentation + smoke only. Plugin behavior unchanged.
+
+## Verification
+
+```bash
+bash plugins/ruflo-aidefence/scripts/smoke.sh
+# Expected: "10 passed, 0 failed"
+```
+
+## Related
+
+- `plugins/ruflo-ruvector/docs/adrs/0001-pin-ruvector-0.2.25.md`
+- `plugins/ruflo-agentdb/docs/adrs/0001-agentdb-optimization.md` β€” namespace convention
+- `plugins/ruflo-browser/docs/adrs/0001-browser-skills-architecture.md` β€” Β§4 codifies the 3-gate pattern this ADR canonicalizes
+- `plugins/ruflo-intelligence/docs/adrs/0001-intelligence-surface-completeness.md`
+- `plugins/ruflo-adr/docs/adrs/0001-adr-plugin-pattern.md`
+- `v3/@claude-flow/cli/src/mcp-tools/security-tools.ts` β€” 6 `aidefence_*` tool definitions
diff --git a/plugins/ruflo-aidefence/scripts/smoke.sh b/plugins/ruflo-aidefence/scripts/smoke.sh
new file mode 100755
index 0000000000..fd6a32c0a7
--- /dev/null
+++ b/plugins/ruflo-aidefence/scripts/smoke.sh
@@ -0,0 +1,84 @@
+#!/usr/bin/env bash
+# Structural smoke test for ruflo-aidefence v0.2.0 (ADR-0001).
+set -u
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+PASS=0
+FAIL=0
+step() { printf "β†’ %s ... " "$1"; }
+ok() { printf "PASS\n"; PASS=$((PASS+1)); }
+bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
+
+step "1. plugin.json declares 0.2.0 with new keywords"
+v=$(grep -E '"version"' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
+if [[ "$v" != "0.2.0" ]]; then
+ bad "expected 0.2.0, got '$v'"
+else
+ miss=""
+ for k in prompt-injection defense-in-depth mcp; do
+ grep -q "\"$k\"" "$ROOT/.claude-plugin/plugin.json" || miss="$miss $k"
+ done
+ [[ -z "$miss" ]] && ok || bad "missing keywords:$miss"
+fi
+
+step "2. all 6 aidefence_* MCP tools referenced in plugin docs"
+miss=""
+for t in aidefence_scan aidefence_analyze aidefence_stats aidefence_learn aidefence_is_safe aidefence_has_pii; do
+ grep -rq "$t" "$ROOT" --include='*.md' || miss="$miss $t"
+done
+[[ -z "$miss" ]] && ok || bad "undocumented:$miss"
+
+step "3. transfer_detect-pii referenced (used by pii-detect skill)"
+grep -q "transfer_detect-pii" "$ROOT/skills/pii-detect/SKILL.md" \
+ && ok || bad "pii-detect skill missing transfer_detect-pii"
+
+step "4. README pins @claude-flow/cli to v3.6"
+grep -qE "@claude-flow/cli.*v3\.6|v3\.6.*claude-flow/cli" "$ROOT/README.md" \
+ && ok || bad "Compatibility pin to v3.6 missing"
+
+step "5. README defers to ruflo-agentdb namespace convention"
+grep -q "ruflo-agentdb" "$ROOT/README.md" \
+ && grep -q "Namespace convention" "$ROOT/README.md" \
+ && ok || bad "namespace coordination block incomplete"
+
+step "6. README documents the 3-gate pattern"
+F="$ROOT/README.md"
+miss=""
+grep -qE "3-gate|3 gates|three gates" "$F" || miss="$miss header"
+grep -q "Pre-storage PII" "$F" || miss="$miss gate1"
+grep -q "Sanitization" "$F" || miss="$miss gate2"
+grep -q "Prompt-injection" "$F" || miss="$miss gate3"
+[[ -z "$miss" ]] && ok || bad "3-gate pattern incomplete:$miss"
+
+step "7. Defence-in-depth pairing block intact (loader-hijack, 0600, encryption)"
+F="$ROOT/README.md"
+miss=""
+grep -q "Loader-hijack denylist" "$F" || miss="$miss denylist"
+grep -qE "0600|0700" "$F" || miss="$miss file-mode"
+grep -q "Encryption at rest" "$F" || miss="$miss encryption"
+[[ -z "$miss" ]] && ok || bad "defence-in-depth block missing:$miss"
+
+step "8. ADR-0001 exists with status Proposed"
+ADR="$ROOT/docs/adrs/0001-aidefence-contract.md"
+[[ -f "$ADR" ]] && grep -qE "^status:[[:space:]]*Proposed" "$ADR" \
+ && ok || bad "ADR missing or status != Proposed"
+
+step "9. both skills have valid frontmatter"
+miss=""
+for s in safety-scan pii-detect; do
+ f="$ROOT/skills/$s/SKILL.md"
+ [[ -f "$f" ]] || { miss="$miss missing-$s"; continue; }
+ for k in 'name:' 'description:' 'allowed-tools:'; do
+ grep -q "^$k" "$f" || miss="$miss $s-no-$k"
+ done
+done
+[[ -z "$miss" ]] && ok || bad "$miss"
+
+step "10. no wildcard tool grants in skills"
+bad_skills=""
+for f in "$ROOT"/skills/*/SKILL.md; do
+ grep -q '^allowed-tools:[[:space:]]*\*' "$f" && bad_skills="$bad_skills $(basename $(dirname "$f"))"
+done
+[[ -z "$bad_skills" ]] && ok || bad "wildcard:$bad_skills"
+
+printf "\n%s passed, %s failed\n" "$PASS" "$FAIL"
+[[ $FAIL -eq 0 ]] || exit 1