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

fix(ruflo-agentdb): guard reads name/value pairs and refuses inputs past the screen budgets (0.4.2)

ruv3a4ddbbd9627
diff --git a/plugins/ruflo-agentdb/.claude-plugin/plugin.json b/plugins/ruflo-agentdb/.claude-plugin/plugin.json
index 8500de9cf2..9997346f70 100644
--- a/plugins/ruflo-agentdb/.claude-plugin/plugin.json
+++ b/plugins/ruflo-agentdb/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "ruflo-agentdb",
"description": "Substrate plugin for Ruflo memory: AgentDB controller bridge (15 agentdb_* MCP tools), RuVector ONNX embeddings (10 embeddings_* tools incl. RaBitQ 32x quantization), and WASM HNSW pattern router (3 ruvllm_hnsw_* tools). As a mod (ADR-445): opt-in safe recall into the prompt, a write guard that keeps secrets out of memory, /agentdb, and a status file the console shows",
- "version": "0.4.1",
+ "version": "0.4.2",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
diff --git a/plugins/ruflo-agentdb/README.md b/plugins/ruflo-agentdb/README.md
index 03808a08b0..ff6a3450a7 100644
--- a/plugins/ruflo-agentdb/README.md
+++ b/plugins/ruflo-agentdb/README.md
@@ -205,7 +205,7 @@ bash plugins/ruflo-agentdb/scripts/smoke.sh
The smoke script is the contract. It calls each documented MCP tool, exercises the RaBitQ workflow, and source-inspects the fallback path (no env-var gate exists to force the fallback live).
-## As a mod (0.4.1, ADR-445)
+## As a mod (0.4.2, ADR-445)
A function-hook mod ships beside the skills. Needs a Claude Code with mods (2.1.287+); older builds ignore it.
diff --git a/plugins/ruflo-agentdb/hooks/guard.ts b/plugins/ruflo-agentdb/hooks/guard.ts
index 554a688595..81d21966c1 100644
--- a/plugins/ruflo-agentdb/hooks/guard.ts
+++ b/plugins/ruflo-agentdb/hooks/guard.ts
@@ -3,10 +3,50 @@ import { isWriter } from './tools'
import { textsOf } from './screen'
export { textsOf }
+/** The shared walker's budgets (screen.ts NODES, CHARS). Past either, textsOf drops the rest silently, so the guard refuses instead of passing it. */
+const NODE_CAP = 20_000
+const CHAR_CAP = 2_000_000
+const NAME_FIELD = /^(?:key|name|field|label|variable|env|header|param|property)$/i
+const VALUE_FIELD = /^(?:value|val|content|secret|data|text|string)$/i
+
+/**
+ * What the shared walker cannot see: `{ key: 'api_key', value: '...' }` and `['api_key', '...']` hold the name and the value in two strings, so
+ * the key-assignment rule never sees them together. Returns those pairs as `name=value` texts and whether the input is past the walker's budgets.
+ */
+export function extras(input: unknown): { readonly pairs: string[]; readonly oversize: boolean } {
+ const pairs: string[] = []
+ const queue: unknown[] = [input]
+ let chars = 0
+ for (let head = 0; head < queue.length; head++) {
+ if (queue.length > NODE_CAP) return { pairs, oversize: true }
+ const node = queue[head]
+ if (typeof node === 'string') {
+ chars += node.length
+ if (chars > CHAR_CAP) return { pairs, oversize: true }
+ } else if (Array.isArray(node)) {
+ if (node.length === 2 && typeof node[0] === 'string' && typeof node[1] === 'string') pairs.push(`${node[0]}=${node[1]}`)
+ for (const v of node) queue.push(v)
+ } else if (typeof node === 'object' && node !== null) {
+ const o = node as Record<string, unknown>
+ const keys = Object.keys(o)
+ const name = keys.find(k => NAME_FIELD.test(k) && typeof o[k] === 'string')
+ const value = keys.find(k => VALUE_FIELD.test(k) && typeof o[k] === 'string')
+ if (name && value) pairs.push(`${o[name]}=${o[value]}`)
+ for (const k of keys) {
+ chars += k.length
+ queue.push(o[k])
+ }
+ }
+ }
+ return { pairs, oversize: false }
+}
+
/** The reason a memory write is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
if (!isWriter(tool)) return undefined
- return textsOf(input).some(hasSecret)
+ const { pairs, oversize } = extras(input)
+ if (oversize) return 'ruflo-agentdb: this memory write is too large to screen for secrets in full. Store it in smaller pieces.'
+ return textsOf(input).some(hasSecret) || pairs.some(hasSecret)
? 'ruflo-agentdb: this memory write holds what looks like a secret (a key, token or password). Store a reference to where it lives, not the value.'
: undefined
}
diff --git a/plugins/ruflo-agentdb/scripts/smoke.sh b/plugins/ruflo-agentdb/scripts/smoke.sh
index 42bcc38bbe..1738f6b289 100755
--- a/plugins/ruflo-agentdb/scripts/smoke.sh
+++ b/plugins/ruflo-agentdb/scripts/smoke.sh
@@ -48,10 +48,10 @@ grep -q "## Namespace convention" "$ROOT/README.md" \
&& ok || bad "Namespace convention section missing"
# 1. Plugin version + new keywords
-step "1. plugin.json declares version 0.4.1 with rabitq + namespace-convention keywords"
+step "1. plugin.json declares version 0.4.2 with rabitq + namespace-convention keywords"
v=$(grep -E '"version"[[:space:]]*:' "$ROOT/.claude-plugin/plugin.json" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
-if [[ "$v" != "0.4.1" ]]; then
- bad "expected 0.4.1, got '$v'"
+if [[ "$v" != "0.4.2" ]]; then
+ bad "expected 0.4.2, got '$v'"
else
miss=""
for k in rabitq quantization namespace-convention controller-bridge; do
diff --git a/plugins/ruflo-agentdb/tests/guard-scan.test.ts b/plugins/ruflo-agentdb/tests/guard-scan.test.ts
new file mode 100644
index 0000000000..5461cef9af
--- /dev/null
+++ b/plugins/ruflo-agentdb/tests/guard-scan.test.ts
@@ -0,0 +1,44 @@
+import { describe, expect, test, tier } from 'claude-code/testing'
+
+import { verdict } from '../hooks/guard'
+
+tier('user')
+
+const TOKEN = 'Zq8vT3mK9wX2LpR7sNd4'
+const refused = (input: unknown) => verdict('memory_store', input) !== undefined
+
+describe('the memory write guard reads what the walker cannot', () => {
+ test('a name field and a value field holding a credential are judged together', () => {
+ expect(refused({ key: 'api_key', value: TOKEN })).toBe(true)
+ expect(refused({ name: 'password', content: TOKEN })).toBe(true)
+ expect(refused({ entries: [{ field: 'secret', data: TOKEN }] })).toBe(true)
+ })
+
+ test('a [name, value] pair is judged together', () => {
+ expect(refused({ rows: [['token', TOKEN]] })).toBe(true)
+ })
+
+ test('the same shapes with ordinary values go through', () => {
+ expect(refused({ key: 'api_key', value: 'see the vault entry for the billing service' })).toBe(false)
+ expect(refused({ key: 'project', value: TOKEN })).toBe(false)
+ expect(refused({ rows: [['title', 'weekly notes']] })).toBe(false)
+ })
+
+ test('an input past the node budget is refused, not half read', () => {
+ const reason = verdict('memory_store', { list: Array.from({ length: 25_000 }, () => 1) })
+ expect(reason).toContain('too large to screen')
+ expect(reason).not.toContain(TOKEN)
+ })
+
+ test('an input past the character budget is refused', () => {
+ expect(refused({ a: 'p'.repeat(1_400_000), b: 'p'.repeat(1_400_000) })).toBe(true)
+ })
+
+ test('a large input under both budgets still goes through', () => {
+ expect(refused({ a: 'lorem '.repeat(50_000), list: Array.from({ length: 5_000 }, () => 'x') })).toBe(false)
+ })
+
+ test('a tool that is not a writer is never judged', () => {
+ expect(verdict('memory_search', { key: 'api_key', value: TOKEN })).toBeUndefined()
+ })
+})