🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(ruflo-mods): stand down for legacy CLI `hooks route|post-edit` settings and check the %USERPROFILE% helper (#3803)
Dragan Spiridonov8613d5bdfea3
diff --git a/plugins/ruflo-mods/hooks/ownership.ts b/plugins/ruflo-mods/hooks/ownership.tsindex a88348e9c6..c2d4610f90 100644--- a/plugins/ruflo-mods/hooks/ownership.ts+++ b/plugins/ruflo-mods/hooks/ownership.ts@@ -48,6 +48,17 @@ export function classicConfigured(settings: unknown, ownable: Ownable): booleanreturn commandsOf(settings, event).some(c => word.test(c))}+/**+ * Whether settings run the CLI's own `hooks route` / `hooks post-edit` on this event: the form `ruflo init` wrote before+ * hook-handler.cjs (e.g. `npx claude-flow@v3alpha hooks route --task "$PROMPT"`). That command never reads the handshake,+ * so the mod must stand down for it whatever the helper does.+ */+export function legacyCliConfigured(settings: unknown, ownable: Ownable): boolean {+ const { event, subcommand } = CLASSIC[ownable]+ const word = new RegExp(`(?:^|[\\s/"'])(?:@claude-flow/cli|claude-flow|ruflo)(?:@[\\w.-]+)?["']?\\s+hooks\\s+${subcommand}(?![\\w-])`)+ return commandsOf(settings, event).some(c => word.test(c))+}+/*** The events the mod owns this session.*@@ -55,5 +66,5 @@ export function classicConfigured(settings: unknown, ownable: Ownable): boolean* @param helperHonours whether the hook-handler.cjs the hooks run carries the marker*/export function ownedEvents(settings: unknown, helperHonours: boolean): Ownable[] {- return OWNABLE.filter(o => !classicConfigured(settings, o) || helperHonours)+ return OWNABLE.filter(o => !legacyCliConfigured(settings, o) && (!classicConfigured(settings, o) || helperHonours))}diff --git a/plugins/ruflo-mods/hooks/session.ts b/plugins/ruflo-mods/hooks/session.tsindex aef9cf64c4..19037201b0 100644--- a/plugins/ruflo-mods/hooks/session.ts+++ b/plugins/ruflo-mods/hooks/session.ts@@ -39,7 +39,9 @@ export const HEARTBEAT_PATH = '.claude-flow/mods/session.json'async function helperHonours($: EngineInterface): Promise<boolean> {const root = await $.session.root().catch(() => undefined)const home = await $.env.get('HOME').catch(() => undefined)- for (const base of new Set([root, home])) {+ // The generated Windows command falls back to %USERPROFILE%\.claude\helpers when the project has no copy.+ const profile = await $.env.get('USERPROFILE').catch(() => undefined)+ for (const base of new Set([root, home, profile])) {if (!base) continueconst path = `${base}/${HELPER}`if (!(await $.fs.exists(path).catch(() => true))) continuediff --git a/plugins/ruflo-mods/tests/register.test.ts b/plugins/ruflo-mods/tests/register.test.tsindex 647af215c7..4325b60895 100644--- a/plugins/ruflo-mods/tests/register.test.ts+++ b/plugins/ruflo-mods/tests/register.test.ts@@ -243,3 +243,43 @@ describe('missing means the read said ENOENT, not that some text did (#3793)', (expect(writes).toEqual([])})})++/** settings.json as `ruflo init` wrote it before the hook-handler.cjs switch (Feb 2026). */+const LEGACY = {+ hooks: {+ UserPromptSubmit: [{ hooks: [{ type: 'command', command: 'npx @claude-flow/cli@latest hooks route --task "$PROMPT"' }] }],+ PostToolUse: [{ matcher: 'Write|Edit|MultiEdit', hooks: [{ type: 'command', command: 'npx @claude-flow/cli@latest hooks post-edit --file "$TOOL_INPUT_file_path" --success "${TOOL_SUCCESS:-true}"' }] }],+ },+}++describe('ownership: the legacy CLI hooks route (pre-hook-handler init)', () => {+ test('a legacy `npx @claude-flow/cli hooks route` hook (no handshake) keeps route; the mod does not route too', async ($, on) => {+ const w = world(on, LEGACY)+ const seen: (readonly string[] | undefined)[] = []+ on('prompt.submit', ($, e) => (seen.push(e.context), { text: e.text }))+ await $.session.start(START)+ await $.prompt.submit(prompt('implement the api'))++ expect(w.env.get('RUFLO_MODS_OWNS') ?? '').not.toContain('route')+ expect(seen[0]).toBeUndefined()+ })+})++/** settings-generator hookCmd on Windows: project copy, else %USERPROFILE%'s. */+const WIN_ROUTE = {+ hooks: {+ UserPromptSubmit: [{ hooks: [{ command: 'cmd /c "IF EXIST \\"%CLAUDE_PROJECT_DIR%\\.claude\\helpers\\hook-handler.cjs\\" (node \\"%CLAUDE_PROJECT_DIR%\\.claude\\helpers\\hook-handler.cjs\\" route) ELSE (node \\"%USERPROFILE%\\.claude\\helpers\\hook-handler.cjs\\" route)"' }] }],+ },+}++describe('ownership: Windows %USERPROFILE% helper', () => {+ test('an old helper under %USERPROFILE% (HOME unset, as on Windows) makes the mod stand down for route', async ($, on) => {+ // A POSIX-style path: the test engine resolves paths as POSIX (C:/... would read as relative and never exist).+ const PROFILE = '/c/Users/me'+ const w = world(on, WIN_ROUTE, { [`${PROFILE}/.claude/helpers/hook-handler.cjs`]: '// an older helper' })+ w.env.set('USERPROFILE', PROFILE)+ await $.session.start(START)++ expect(w.env.get('RUFLO_MODS_OWNS') ?? '').not.toContain('route')+ })+})diff --git a/v3/@claude-flow/cli/__tests__/mods/mods-ownership.test.ts b/v3/@claude-flow/cli/__tests__/mods/mods-ownership.test.tsindex ee3e30f962..734504dddd 100644--- a/v3/@claude-flow/cli/__tests__/mods/mods-ownership.test.ts+++ b/v3/@claude-flow/cli/__tests__/mods/mods-ownership.test.ts@@ -12,7 +12,7 @@ import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { register } from '../../../../../plugins/ruflo-mods/hooks/register';-import { classicConfigured, ownedEvents } from '../../../../../plugins/ruflo-mods/hooks/ownership';+import { classicConfigured, legacyCliConfigured, ownedEvents } from '../../../../../plugins/ruflo-mods/hooks/ownership';import { loadMod, memoryWorld, realWorld, type World } from './harness';const REPO = resolve(__dirname, '../../../../..');@@ -50,6 +50,25 @@ describe('ADR-404 ownership rule', () => {expect(ownedEvents(CLASSIC, true)).toEqual(['route', 'post-edit']);});+ it('stands down where settings still run the CLI\'s own hooks route/post-edit (pre-hook-handler init), handshake or not', () => {+ const legacy = (route: string, edit: string) => ({ hooks: {+ UserPromptSubmit: [{ hooks: [{ command: route }] }],+ PostToolUse: [{ matcher: 'Write|Edit|MultiEdit', hooks: [{ command: edit }] }],+ } });+ for (const s of [+ legacy('[ -n "$PROMPT" ] && npx claude-flow@v3alpha hooks route --task "$PROMPT" --intelligence || true',+ 'if [ -n "$TOOL_INPUT_file_path" ]; then npx claude-flow@v3alpha hooks post-edit --file "$TOOL_INPUT_file_path"; fi; exit 0'),+ legacy('npx @claude-flow/cli@latest hooks route --task "$PROMPT"', 'npx @claude-flow/cli@latest hooks post-edit --file x'),+ legacy('npx ruflo hooks route --task "$PROMPT"', 'ruflo hooks post-edit --file x'),+ ]) {+ expect(legacyCliConfigured(s, 'route')).toBe(true);+ expect(ownedEvents(s, true)).toEqual([]);+ }+ expect(legacyCliConfigured(CLASSIC, 'route')).toBe(false);+ expect(legacyCliConfigured(legacy('npx claude-flow hooks router-stats', 'npx myruflo hooks post-edit'), 'route')).toBe(false);+ expect(legacyCliConfigured(legacy('npx claude-flow hooks router-stats', 'npx myruflo hooks post-edit'), 'post-edit')).toBe(false);+ });+it('never owns pre-bash or session events', () => {expect(ownedEvents({}, true)).not.toContain('pre-bash');});