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): load again: the ruRE offer no longer registers a second bare session.start, tool.call and turn.complete (0.7.1, #4485) (#4487)

rUvd7fcaf3b2580
diff --git a/plugins/ruflo-mods/.claude-plugin/plugin.json b/plugins/ruflo-mods/.claude-plugin/plugin.json
index 1543ebd25c..0c327ebec0 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.7.0",
+ "version": "0.7.1",
"author": {
"name": "ruvnet",
"url": "https://github.com/ruvnet"
diff --git a/plugins/ruflo-mods/CHANGELOG.md b/plugins/ruflo-mods/CHANGELOG.md
index 0d1f107822..62604a2e86 100644
--- a/plugins/ruflo-mods/CHANGELOG.md
+++ b/plugins/ruflo-mods/CHANGELOG.md
@@ -2,6 +2,10 @@
Newest first. One `## <version> — <date>` heading per version, then `feat:`, `fix:`, `breaking:` and `chore:` bullets (ADR-478). Built from git history; older versions: `git log -- plugins/ruflo-mods`.
+## 0.7.1 — 2026-10-25
+- fix: ruflo-mods 0.7.0 did not load in Claude Code (#4485): the hooks module was refused with `on("session.start") is registered twice without a matcher`, so no hook ran and `/ruflo mods` answered "not loaded". The ruRE offer registered a second bare `session.start`, `tool.call` and `turn.complete`. Its session work now runs inside the one `session.start` handler (the pure `hasRure` takes the tool list; Claude Code follows `$` only inside the file that spells it), and its two other hooks carry a match-all matcher, as the session rollup's do. It was refused even with `rureOffer` off, because the loader checks registrations statically.
+- chore: the test host now refuses the same thing the loader does, and a test loads the mod with every boolean option from the manifest turned on, so an optional module cannot break the mod unseen again
+
## 0.7.0 — 2026-10-23
- feat: option `rureOffer` (default off, ADR-498): when the model reads or writes a binary, library, `.asar` or CUDA file inside the project, one line beneath the answer says ruRE can look inside it without running it, and how (`/ruflo run dt-re-auto <path>`, or `rure_analyze_binary` / `rure_analyze_cuda`). Offer only: it never runs ruRE, never denies or edits a call, shows at most three files a turn and twelve a session once each, only validated project-relative paths, and nothing from the file. Inert without a ruRE tool and on subagent answers
diff --git a/plugins/ruflo-mods/hooks/rure-offer/index.ts b/plugins/ruflo-mods/hooks/rure-offer/index.ts
index f27c97ecff..31462ae091 100644
--- a/plugins/ruflo-mods/hooks/rure-offer/index.ts
+++ b/plugins/ruflo-mods/hooks/rure-offer/index.ts
@@ -6,6 +6,21 @@ import { candidate, MAX_BYTES, MAX_PENDING, MAX_PER_SESSION, MAX_PER_TURN, OFFER
/** A ruRE tool the session can call: `mcp__<server>__rure_analyze_binary`, the one every ruRE install carries. */
const RURE_TOOL = /__rure_analyze_binary$/
+/**
+ * Claude Code refuses a hooks module that registers one event twice WITHOUT a matcher (#4485), and the always-on modules already hold the
+ * bare `tool.call` and `turn.complete`. An optional module therefore registers with a match-all matcher on a field every such event carries
+ * (the same idiom as the session rollup), and its `session.start` work lives in the one handler in session.ts (`hasRure`).
+ */
+const ANY = /^[\s\S]*$/
+
+/**
+ * Whether a tool list holds a ruRE tool. Pure: Claude Code's loader follows `$` only inside the file that spells it, so the
+ * `$.tool.list()` call is in session.ts's single `session.start` handler (a second unmatched one is refused, #4485) and passes the list here.
+ */
+export function hasRure(tools: ReadonlyArray<{ name: string; mcp?: boolean }>): boolean {
+ return tools.some(tool => tool.mcp === true && RURE_TOOL.test(tool.name))
+}
+
/**
* The ruRE offer (ADR-498). Off unless the `rureOffer` option is on. When the model reads or writes a file ruRE can look inside (an
* executable, a library, an Electron `.asar`, a CUDA `.cubin`), it adds ONE line beneath that turn's answer naming up to three such files
@@ -19,19 +34,7 @@ export function registerRureOffer(on: On, state: ModState) {
offer.enabled = true
- on('session.start', async ($, e, next) => {
- const result = await next(e)
-
- try {
- offer.available = (await $.tool.list()).some(tool => tool.mcp && RURE_TOOL.test(tool.name))
- } catch {
- offer.available = false
- }
-
- return result
- })
-
- on('tool.call', async ($, e, next) => {
+ on('tool.call', { tool: ANY }, async ($, e, next) => {
const result = await next(e)
if (!offer.available || (result as { deny?: unknown } | undefined)?.deny !== undefined || !OFFER_TOOLS.has(e.tool)) return result
@@ -43,7 +46,7 @@ export function registerRureOffer(on: On, state: ModState) {
return result
})
- on('turn.complete', async ($, e, next) => {
+ on('turn.complete', { turnId: ANY }, async ($, e, next) => {
const result = await next(e)
// Only the main loop's answer carries the line: a subagent's answer goes back to the model that asked for it.
diff --git a/plugins/ruflo-mods/hooks/session.ts b/plugins/ruflo-mods/hooks/session.ts
index a7a84d5f09..7b00cd1d75 100644
--- a/plugins/ruflo-mods/hooks/session.ts
+++ b/plugins/ruflo-mods/hooks/session.ts
@@ -2,6 +2,7 @@ import type { EngineInterface, On } from 'claude-code'
import type { GuidanceHooks } from './guidance'
import { detectBrain } from './grounding'
+import { hasRure } from './rure-offer'
import { versionText } from './probe'
import { HANDSHAKE_MARKER, ownedEvents } from './ownership'
import type { ModOptions } from './options'
@@ -117,6 +118,7 @@ export function registerSession(on: On, state: ModState, options: ModOptions, gu
state.statusLine = options.statusLine && !hasClassicStatusLine(settings)
if (state.probe.enabled) state.probe.version = versionText(await $.session.version().catch(() => undefined))
if (state.grounding.enabled) state.grounding.status = await detectGrounding($, settings)
+ if (state.rureOffer.enabled) state.rureOffer.available = await $.tool.list().then(hasRure, () => false)
guidance?.start()
redraw(state)
await $.command
diff --git a/plugins/ruflo-mods/scripts/smoke.sh b/plugins/ruflo-mods/scripts/smoke.sh
index d78bc8b6d5..f4cd6b1d07 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.7.0 (ADR-404, ADR-447).
+# Structural + security smoke for ruflo-mods v0.7.1 (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.7.0"
+step "1. plugin.json declares ruflo-mods 0.7.1"
grep -q '"name": "ruflo-mods"' "$ROOT/.claude-plugin/plugin.json" \
- && grep -q '"version": "0.7.0"' "$ROOT/.claude-plugin/plugin.json" && ok || bad "name/version"
+ && grep -q '"version": "0.7.1"' "$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/v3/@claude-flow/cli/__tests__/mods/harness.ts b/v3/@claude-flow/cli/__tests__/mods/harness.ts
index bb8b79aa7a..cffb20c676 100644
--- a/v3/@claude-flow/cli/__tests__/mods/harness.ts
+++ b/v3/@claude-flow/cli/__tests__/mods/harness.ts
@@ -152,6 +152,18 @@ function matches(matcher: Record<string, unknown> | undefined, e: Record<string,
export type Core = (event: string, e: any) => any;
+/**
+ * Claude Code's hooks loader refuses a module that registers the same event twice WITHOUT a matcher ("on(\"session.start\") is registered
+ * twice without a matcher"), and then none of the mod's hooks run. The fake host used to accept it, which is how ruflo-mods 0.7.0 shipped
+ * broken (#4485). Mirror the rule so every mod test, and the all-options test, fails the same way.
+ */
+export function assertLoadable(regs: ReadonlyArray<{ event: string; matcher?: unknown }>): void {
+ const bare = new Map<string, number>();
+ for (const reg of regs) if (reg.matcher === undefined) bare.set(reg.event, (bare.get(reg.event) ?? 0) + 1);
+ const twice = [...bare].filter(([, count]) => count > 1).map(([event]) => event);
+ if (twice.length) throw new Error(`hooks module did not load: ${twice.map((event) => `on("${event}") is registered twice without a matcher`).join('; ')}`);
+}
+
export function loadMod(register: (on: any, options: any) => unknown, world: World, options: Record<string, unknown> = {}) {
const regs: Registration[] = [];
const on = (event: string, a: unknown, b?: unknown) => {
@@ -165,6 +177,7 @@ export function loadMod(register: (on: any, options: any) => unknown, world: Wor
};
};
register(on, options);
+ assertLoadable(regs);
const $ = engineOf(world);
async function dispatch(event: string, e: any, core: (e: any) => any): Promise<any> {
diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-all-options-load.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-all-options-load.test.ts
new file mode 100644
index 0000000000..b4d0e1f6f4
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/mods/mods-all-options-load.test.ts
@@ -0,0 +1,36 @@
+/**
+ * ruflo-mods must load with EVERY optional module on. A module that is only registered when its option is on can break the whole mod
+ * (#4485: rureOffer registered a second `session.start` without a matcher, so Claude Code refused the hooks module and `/ruflo mods`
+ * answered "not loaded"), and the default-options tests never see it. The options are read from the manifest, so a new one is covered
+ * the day it is added.
+ */
+import { readFileSync } from 'node:fs';
+import { describe, it, expect } from 'vitest';
+
+import { register } from '../../../../../plugins/ruflo-mods/hooks/register';
+import { assertLoadable, loadMod, memoryWorld } from './harness';
+
+const manifest = JSON.parse(readFileSync(new URL('../../../../../plugins/ruflo-mods/.claude-plugin/plugin.json', import.meta.url), 'utf8'));
+const booleans = Object.entries(manifest.userConfig as Record<string, { type?: string }>).filter(([, spec]) => spec.type === 'boolean').map(([key]) => key);
+
+describe('ruflo-mods loads with every option on (#4485)', () => {
+ it('the manifest declares boolean options, including rureOffer', () => {
+ expect(booleans.length).toBeGreaterThan(5);
+ expect(booleans).toContain('rureOffer');
+ });
+
+ it('registers no event twice without a matcher when all options are on', () => {
+ const mod = loadMod(register, memoryWorld(), Object.fromEntries(booleans.map((key) => [key, true])));
+ expect(() => assertLoadable(mod.regs)).not.toThrow();
+ });
+
+ it('each option on its own also loads', () => {
+ for (const key of booleans) expect(() => loadMod(register, memoryWorld(), { [key]: true }), key).not.toThrow();
+ });
+
+ it('the rule itself: two bare registrations of one event are refused, a matcher or a different event is fine', () => {
+ expect(() => assertLoadable([{ event: 'session.start' }, { event: 'session.start' }])).toThrow('registered twice without a matcher');
+ expect(() => assertLoadable([{ event: 'session.start' }, { event: 'session.start', matcher: { surface: /x/ } }])).not.toThrow();
+ expect(() => assertLoadable([{ event: 'session.start' }, { event: 'turn.complete' }])).not.toThrow();
+ });
+});