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(hooks): spawn funnel refresh from the inline hook-handler fallback

ruv87212ddbf77f
diff --git a/v3/@claude-flow/cli/__tests__/hook-handler-artifact-parity.test.ts b/v3/@claude-flow/cli/__tests__/hook-handler-artifact-parity.test.ts
index 758517299e..4be1eb37b6 100644
--- a/v3/@claude-flow/cli/__tests__/hook-handler-artifact-parity.test.ts
+++ b/v3/@claude-flow/cli/__tests__/hook-handler-artifact-parity.test.ts
@@ -19,6 +19,7 @@ import { describe, it, expect } from 'vitest';
import { readFileSync, existsSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
+import { generateHookHandler } from '../src/init/helpers-generator.js';
describe('hook-handler.cjs β€” root/package artifact parity', () => {
it('the root and package copies are byte-identical', () => {
@@ -29,3 +30,30 @@ describe('hook-handler.cjs β€” root/package artifact parity', () => {
expect(readFileSync(rootArtifact, 'utf-8')).toBe(readFileSync(pkgArtifact, 'utf-8'));
});
});
+
+describe('generateHookHandler() fallback β€” funnel refresh wiring (#2661-adjacent)', () => {
+ // Unlike the committed .cjs artifacts above, this fallback IS generated
+ // from generateHookHandler() directly β€” it's the inline template used
+ // when copying the real file from the package fails. Its own
+ // session-restore handler must still spawn the funnel refresh, or a
+ // fallback-only install would never populate the promo cache.
+ const source = generateHookHandler();
+
+ it('defines spawnFunnelRefresh as a detached, unref\'d, best-effort spawn', () => {
+ expect(source).toContain('function spawnFunnelRefresh()');
+ expect(source).toContain('detached: true');
+ expect(source).toContain('child.unref()');
+ });
+
+ it('wires spawnFunnelRefresh() into the session-restore handler', () => {
+ const idx = source.indexOf("'session-restore':");
+ expect(idx).toBeGreaterThan(-1);
+ const handlerBody = source.slice(idx, idx + 200);
+ expect(handlerBody).toContain('spawnFunnelRefresh();');
+ });
+
+ it('is syntactically valid JavaScript', () => {
+ const withoutShebang = source.replace(/^#!.*\n/, '');
+ expect(() => new Function(withoutShebang)).not.toThrow();
+ });
+});
diff --git a/v3/@claude-flow/cli/src/init/helpers-generator.ts b/v3/@claude-flow/cli/src/init/helpers-generator.ts
index bb51ef54c0..7e664702c2 100644
--- a/v3/@claude-flow/cli/src/init/helpers-generator.ts
+++ b/v3/@claude-flow/cli/src/init/helpers-generator.ts
@@ -457,9 +457,39 @@ export function generateHookHandler(): string {
"const path = require('path');",
"const fs = require('fs');",
"const os = require('os');",
+ "const { spawn } = require('child_process');",
'',
'const helpersDir = __dirname;',
'',
+ // #2661-adjacent fix: `refreshRemoteMessages()` (the funnel promo/disclosure
+ // pool) is fire-and-forget by design so the statusline's own short-lived
+ // per-render subprocess never blocks on a network call β€” but that also
+ // means it NEVER gets a chance to finish there (confirmed live: two
+ // consecutive cold-cache statusline renders returned promo:null and no
+ // cache file was ever written). `refresh-funnel` exists specifically to
+ // be spawned from a longer-lived context; wire that spawn here, once per
+ // session, detached so it survives this hook process exiting and isn't
+ // awaited so it never adds to the hook's own timeout budget.
+ //
+ // Deliberately always via npx (--prefer-offline avoids a registry round
+ // trip when already cached), never a locally-resolved bin/cli.js path:
+ // a fire-and-forget detached spawn has no way to recover if the first
+ // candidate is a broken/unbuilt local install (confirmed live β€” a stale
+ // marketplace checkout with a bin/cli.js that exists but throws
+ // MODULE_NOT_FOUND on its own dist/ silently ate the spawn with no
+ // fallback and no visible error, since stdio is intentionally ignored).
+ // npx resolves a real, structurally-valid published package every time.
+ 'function spawnFunnelRefresh() {',
+ ' try {',
+ " var cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';",
+ " var args = ['--prefer-offline', '@claude-flow/cli', 'hooks', 'refresh-funnel', '--quiet'];",
+ ' var child = spawn(cmd, args, {',
+ " detached: true, stdio: 'ignore', env: Object.assign({}, process.env),",
+ ' });',
+ ' child.unref();',
+ ' } catch (e) { /* best-effort β€” the statusline\'s own fallback still renders */ }',
+ '}',
+ '',
'function safeRequire(modulePath) {',
' try {',
' if (fs.existsSync(modulePath)) {',
@@ -625,6 +655,7 @@ export function generateHookHandler(): string {
' },',
'',
" 'session-restore': () => {",
+ ' spawnFunnelRefresh();',
' if (session) {',
' var existing = session.restore && session.restore();',
' if (!existing) {',