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-mods): reject a legacy or unknown-mode policy projection as unreadable; report shows the mode (ADR-450 T10), 0.3.12

ruvecb0c0bfa66a
diff --git a/plugins/ruflo-mods/.claude-plugin/plugin.json b/plugins/ruflo-mods/.claude-plugin/plugin.json
index 765d2490b5..03faa23b6b 100644
--- a/plugins/ruflo-mods/.claude-plugin/plugin.json
+++ b/plugins/ruflo-mods/.claude-plugin/plugin.json
@@ -1,7 +1,7 @@
{
"name": "ruflo-mods",
"description": "ruflo as a Claude Code mod (function hooks, ADR-404): in-process prompt routing, edit learning signals, tighten-only tool checks from ruflo policy, the cost-tracker budget ladder, a mod trust gate for newly installed mods, and the $.ruflo noun other mods compose their status with. Opt-in and removable: the classic hook-handler hooks stay the default and take every event back whenever the mod is not loaded.",
- "version": "0.3.11",
+ "version": "0.3.12",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
diff --git a/plugins/ruflo-mods/README.md b/plugins/ruflo-mods/README.md
index 0ea7c87b3d..b3cc35a623 100644
--- a/plugins/ruflo-mods/README.md
+++ b/plugins/ruflo-mods/README.md
@@ -61,7 +61,7 @@ In a session, `/ruflo mods` (through ruflo-console's `/ruflo`) reports what the
- **Routing:** in an initialized Ruflo project (an existing `.claude-flow/` directory), `prompt.submit` routes each prompt in-process and hands the route, plus ranked memory, to the model as context. The text is the same as the classic `route` hook produces.
- **Edit learning:** `tool.call` records finished edits for the intelligence consolidator, once per turn.
-- **Tool checks:** `tool.check` only tightens. It applies the dangerous-command list and ruflo policy rules that name `claude-code.*` actions (written by the CLI to `.claude-flow/policy/claude-code.json`). It never loosens a verdict.
+- **Tool checks:** `tool.check` only tightens. It applies the dangerous-command list and ruflo policy rules that name `claude-code.*` actions (written by the CLI to `.claude-flow/policy/claude-code.json`). It never loosens a verdict. A projection whose mode is `legacy` (or anything but `observe`/`enforce`) is rejected as unreadable, because the CLI never writes one (it deletes the file), so the call is put to you; `/ruflo-mods` shows `policy: <mode> (projection read)` or `policy: unreadable` (ADR-450 T10).
- **Trust gate:** `plugin.register` names what a later-installed mod can do (host commands, network, environment, tool verdicts) and, under `modTrust: refuse-risky`, refuses it unless allow-listed.
- **`$.ruflo`:** other mods add a status segment with `$.ruflo.segment({ id, text })` instead of drawing a second bar; `lastRoute()` and `snapshot()` read what the mod measured. Contract: `types/index.d.ts`.
- **Budget:** `session.measure` applies the cost-tracker budget ladder to live session cost (`costBudgetUsd`); Each rung is announced once per session, even if cost falls and rises again. `costHardStop` halts new subagents at 100%.
diff --git a/plugins/ruflo-mods/hooks/guard/policy.ts b/plugins/ruflo-mods/hooks/guard/policy.ts
index 43e21c61f0..b08b327fd1 100644
--- a/plugins/ruflo-mods/hooks/guard/policy.ts
+++ b/plugins/ruflo-mods/hooks/guard/policy.ts
@@ -19,7 +19,8 @@ import type { Verdict } from './verdict'
export const PROJECTION_PATH = '.claude-flow/policy/claude-code.json'
export const ACTION_PREFIX = 'claude-code.'
-export type PolicyMode = 'legacy' | 'observe' | 'enforce'
+/** `legacy` is never projected: the CLI deletes the file for it, so a file that says so was hand-written (ADR-450 T10). */
+export type PolicyMode = 'observe' | 'enforce'
type Effect = 'allow' | 'deny' | 'require_approval'
export type ProjectedRule = {
@@ -53,7 +54,7 @@ export type ToolRequest = {
}
}
-const MODES = new Set(['legacy', 'observe', 'enforce'])
+const MODES = new Set(['observe', 'enforce'])
const EFFECTS = new Set(['allow', 'deny', 'require_approval'])
const DESTRUCTIVE = new Set(['Bash', 'Write', 'Edit', 'MultiEdit', 'NotebookEdit'])
const NETWORK = new Set(['Bash', 'WebFetch', 'WebSearch'])
@@ -74,7 +75,7 @@ export function parseProjection(text: string): Projection {
if (raw === null || typeof raw !== 'object') throw new Error('projection is not an object')
const { version, mode, rules } = raw as Record<string, unknown>
if (version !== 1) throw new Error(`unsupported projection version ${String(version)}`)
- if (typeof mode !== 'string' || !MODES.has(mode)) throw new Error('projection mode invalid')
+ if (typeof mode !== 'string' || !MODES.has(mode)) throw new Error('projection mode invalid (only observe or enforce are ever written)')
if (!Array.isArray(rules)) throw new Error('projection rules invalid')
const valid = rules.map((r: unknown, i): ProjectedRule => {
const rule = r as Record<string, unknown> | null
@@ -163,7 +164,7 @@ export type PolicyOpinion = { readonly verdict?: Verdict; readonly wouldBe?: str
* never loosens). In `observe`, `wouldBe` names what enforce would do.
*/
export function policyOpinion(projection: Projection, tool: string, input: unknown): PolicyOpinion {
- if (projection.mode === 'legacy' || projection.rules.length === 0) return {}
+ if (projection.rules.length === 0) return {}
const req = toolRequest(tool, input)
const matched = projection.rules
.filter(rule => ruleMatches(rule, req))
diff --git a/plugins/ruflo-mods/hooks/state.ts b/plugins/ruflo-mods/hooks/state.ts
index f807530a84..cc1473a02b 100644
--- a/plugins/ruflo-mods/hooks/state.ts
+++ b/plugins/ruflo-mods/hooks/state.ts
@@ -27,7 +27,7 @@ export type ModState = {
edits: EditRecord[]
guidance: GuidanceState
editCount: number
- policy: 'none' | 'legacy' | 'observe' | 'enforce' | 'unreadable'
+ policy: 'none' | 'observe' | 'enforce' | 'unreadable'
/** The research run (marker startedAt) whose first web call was already put to the person. */
researchAsked?: string
budget: { level: BudgetLevel; usd?: number; limit?: number }
@@ -125,7 +125,7 @@ export function statusText(s: ModState): string | undefined {
parts.push(s.lastRoute.matched ? `${s.lastRoute.agent} ${pct}%` : `no route (${pct}%)`)
}
if (s.editCount) parts.push(`${s.editCount} edit${s.editCount === 1 ? '' : 's'}`)
- if (s.policy !== 'none' && s.policy !== 'legacy') parts.push(`policy ${s.policy}`)
+ if (s.policy !== 'none') parts.push(`policy ${s.policy}`)
if (s.tightened) parts.push(`${s.tightened} tightened`)
if (s.budget.limit !== undefined && s.budget.level !== 'OK') parts.push(`budget ${s.budget.level}`)
}
@@ -136,6 +136,10 @@ export function statusText(s: ModState): string | undefined {
/** Redraws the status line from the state. */
export const redraw = (s: ModState) => s.draw(statusText(s))
+/** The projection state as a short fixed phrase; `unreadable` covers a hand-written legacy or unknown mode. */
+const policyWord = (p: ModState['policy']) =>
+ p === 'none' ? 'none' : p === 'unreadable' ? 'unreadable (rejected: calls ask)' : `${p} (projection read)`
+
/** What `/ruflo-mods` prints. */
export function report(s: ModState): string {
const route = s.lastRoute
@@ -151,7 +155,7 @@ export function report(s: ModState): string {
` owns: ${[...s.owned].join(', ') || 'nothing (classic hooks keep every event)'}`,
` routed: ${s.routed} prompt(s); last ${route}`,
` edits: ${s.editCount} recorded, ${s.edits.length} pending write`,
- ` policy: ${s.policy}; ${s.tightened} call(s) tightened, ${s.observed} observed`,
+ ` policy: ${policyWord(s.policy)}; ${s.tightened} call(s) tightened, ${s.observed} observed`,
` budget: ${budget}`,
` tool hints: ${s.toolHints.enabled ? `${s.toolHints.described.size} tool(s) described` : 'off (set the toolHints option)'}`,
` agent trim: ${s.agentTrim.enabled ? `${s.agentTrim.hidden.size} type(s) hidden` : 'off (set the agentTrim option)'}`,
diff --git a/plugins/ruflo-mods/scripts/smoke.sh b/plugins/ruflo-mods/scripts/smoke.sh
index 6d43121910..d093a97389 100755
--- a/plugins/ruflo-mods/scripts/smoke.sh
+++ b/plugins/ruflo-mods/scripts/smoke.sh
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
-# Structural + security smoke for ruflo-mods v0.3.11 (ADR-404, ADR-447).
+# Structural + security smoke for ruflo-mods v0.3.12 (ADR-404, ADR-447).
# Static only: CI has no Claude Code, so the hooks module's behaviour is held
# by v3/@claude-flow/cli/__tests__/mods/*.test.ts and, where function hooks are
# on, by `claude plugin test plugins/ruflo-mods`.
@@ -12,9 +12,9 @@ ok() { printf "PASS\n"; PASS=$((PASS+1)); }
bad() { printf "FAIL: %s\n" "$1"; FAIL=$((FAIL+1)); }
HOOKS="$ROOT/hooks"
-step "1. plugin.json declares ruflo-mods 0.3.11"
+step "1. plugin.json declares ruflo-mods 0.3.12"
grep -q '"name": "ruflo-mods"' "$ROOT/.claude-plugin/plugin.json" \
- && grep -q '"version": "0.3.11"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
+ && grep -q '"version": "0.3.12"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
step "2. hooks.json names exactly one module and no classic hook commands"
grep -q '"modules": \["./register.ts"\]' "$HOOKS/hooks.json" && ! grep -q '"command"' "$HOOKS/hooks.json" \
diff --git a/plugins/ruflo-mods/tests/register.test.ts b/plugins/ruflo-mods/tests/register.test.ts
index 244aa66efd..c378dd991d 100644
--- a/plugins/ruflo-mods/tests/register.test.ts
+++ b/plugins/ruflo-mods/tests/register.test.ts
@@ -134,6 +134,33 @@ describe('register', () => {
expect((await $.tool.check({ tool: 'Read', input: { file_path: 'a.ts' } })).decision).toBe('ask')
})
+ test('tool.check: a legacy or unknown-mode projection is unreadable, so the call asks; the report names the state (ADR-450 T10)', async ($, on) => {
+ const PATH = `${ROOT}/.claude-flow/policy/claude-code.json`
+ const rule = { id: 'no-push', effect: 'deny', actions: ['claude-code.tool.Bash'], resources: ['git push*'] }
+ const mk = (mode: unknown) => JSON.stringify({ version: 1, mode, rules: [rule] })
+ const w = world(on, {}, { [PATH]: mk('enforce') })
+ on('tool.check', () => ({ decision: 'allow' }))
+ on('command.run', () => ({ text: 'core' }))
+ await $.session.start(START)
+ const read = { tool: 'Read', input: { file_path: 'a.ts' } }
+ const report = async () => ((await $.command.run({ command: 'ruflo-mods', args: '', origin: { kind: 'composer' }, presentation: { isFullscreen: false, columns: 100 } })).text ?? '')
+
+ expect((await $.tool.check(read)).decision).toBe('allow')
+ expect(await report()).toContain('policy: enforce (projection read)')
+
+ for (const bad of ['legacy', 'LEGACY', 'off', '', null, 7, ['enforce'], {}]) {
+ w.files.set(PATH, mk(bad))
+ const out = await $.tool.check(read)
+ expect(out.decision).toBe('ask')
+ expect(out.reason).toContain('unreadable')
+ expect(await report()).toContain('policy: unreadable')
+ }
+
+ w.files.set(PATH, mk('observe'))
+ expect((await $.tool.check(read)).decision).toBe('allow')
+ expect(await report()).toContain('policy: observe (projection read)')
+ })
+
test('records a finished edit once per turn, in the classic pending-insights format', async ($, on) => {
const w = world(on)
on('tool.call', () => ({ result: 'edited' }))
diff --git a/plugins/ruflo-mods/types/index.d.ts b/plugins/ruflo-mods/types/index.d.ts
index fbb3164494..b8bec24029 100644
--- a/plugins/ruflo-mods/types/index.d.ts
+++ b/plugins/ruflo-mods/types/index.d.ts
@@ -39,7 +39,7 @@ export type RufloSnapshot = {
routed: number
lastRoute: RufloRoute | null
/** `none`: no ruflo policy for Claude Code tools. `unreadable`: present, failing closed. */
- policy: 'none' | 'legacy' | 'observe' | 'enforce' | 'unreadable'
+ policy: 'none' | 'observe' | 'enforce' | 'unreadable'
/** Tool calls ruflo tightened (allow to ask or deny, ask to deny). */
tightened: number
/** Calls observe-mode policy would have tightened. */