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(statusline): pick highest local package version, not first-found

ruv6643d44d3226
diff --git a/.claude/helpers/hook-handler.cjs b/.claude/helpers/hook-handler.cjs
index b2b91a8c75..625e059a21 100755
--- a/.claude/helpers/hook-handler.cjs
+++ b/.claude/helpers/hook-handler.cjs
@@ -15,9 +15,99 @@
const path = require('path');
const fs = require('fs');
+const os = require('os');
const helpersDir = __dirname;
+// Resolve an installed @claude-flow/cli (or ruflo) bin β€” mirrors
+// statusline-generator.ts's resolveCliBin() candidate list. Used only to
+// spawn the detached funnel-refresh helper below; failures are silent (no
+// candidate found just means the refresh never fires this session).
+//
+// Verifies dist/src/index.js exists alongside bin/cli.js, not just the bin
+// itself β€” Claude Code's own plugin marketplace mechanism installs by
+// `git clone`/`git pull` with no build step, so `~/.claude/plugins/
+// marketplaces/ruflo` is a SOURCE-ONLY checkout by construction: bin/cli.js
+// is present on disk but importing dist/src/index.js throws
+// ERR_MODULE_NOT_FOUND on every real command (confirmed live β€” only
+// `--version` happens to survive it, since it reads package.json directly).
+// Without this check, resolveCliBinForHook() picked that doomed candidate
+// first every time and spawnDetachedFunnelRefresh() below had no fallback,
+// so the promo/disclosure row could never populate for any marketplace
+// install, on any OS.
+function resolveCliBinForHook() {
+ try {
+ const home = os.homedir();
+ const cwd = process.cwd();
+ const candidates = [
+ path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo', 'bin', 'cli.js'),
+ path.join(cwd, 'node_modules', '@claude-flow', 'cli', 'bin', 'cli.js'),
+ path.join(cwd, 'node_modules', 'ruflo', 'bin', 'cli.js'),
+ path.join(cwd, 'v3', '@claude-flow', 'cli', 'bin', 'cli.js'),
+ // helpersDir is .claude/helpers/ inside the package itself when this
+ // file is running from a real @claude-flow/cli install (not a project
+ // that merely copied the helper) β€” its bin/ is two levels up.
+ path.join(helpersDir, '..', '..', 'bin', 'cli.js'),
+ ];
+ for (const p of candidates) {
+ try {
+ if (fs.existsSync(p) && fs.existsSync(path.join(path.dirname(p), '..', 'dist', 'src', 'index.js'))) {
+ return p;
+ }
+ } catch (e) { /* try next candidate */ }
+ }
+ } catch (e) { /* ignore */ }
+ return null;
+}
+
+// Fire-and-forget doesn't work when the CALLER is itself a short-lived
+// subprocess (confirmed live: two consecutive statusline renders 5s apart
+// both saw an empty funnel-messages-cache, because the async HTTPS fetch
+// inside a `void refreshRemoteMessages()` call gets killed when the spawning
+// process exits before the request completes). Spawning fully DETACHED +
+// unref'd decouples the refresh's lifetime from this hook's β€” it keeps
+// running (up to message-transport.ts's own 4s fetch timeout) even after
+// session-restore's own process has already exited, so it actually gets a
+// chance to write the cache. Never awaited here β€” must not add to
+// SessionStart's own timeout budget.
+//
+// No usable local candidate (resolveCliBinForHook() returned null) falls
+// back to npx: this call is detached/unref'd, so a slower npx cold-start
+// costs nothing perceptible β€” unlike the statusline's own synchronous
+// render path, where local-first exists purely for per-render latency.
+// `--prefer-offline` avoids a registry round trip for the tarball when
+// already cached while still resolving the current `@latest` version.
+function spawnDetachedHookRefresh(subcommand) {
+ try {
+ const { spawn } = require('child_process');
+ const cliBin = resolveCliBinForHook();
+ const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
+ const spawnArgs = cliBin
+ ? [process.execPath, [cliBin, 'hooks', subcommand, '--quiet']]
+ : [cmd, ['--prefer-offline', '@claude-flow/cli', 'hooks', subcommand, '--quiet']];
+ const child = spawn(spawnArgs[0], spawnArgs[1], {
+ detached: true,
+ stdio: 'ignore',
+ env: process.env,
+ });
+ child.unref();
+ } catch (e) { /* best-effort only */ }
+}
+
+function spawnDetachedFunnelRefresh() {
+ spawnDetachedHookRefresh('refresh-funnel');
+}
+
+// Same fallback-aware pattern as spawnDetachedFunnelRefresh() above, for
+// ADR-316's co-pilot advisor tip. Safe to call on EVERY session-restore:
+// refresh-advisor's own action checks consent + a 24h TTL BEFORE spending
+// anything, so an unconsented or already-fresh install is a fast no-op file
+// read, never a network call. Never awaited here β€” must not add to
+// SessionStart's own timeout budget.
+function spawnDetachedAdvisorRefresh() {
+ spawnDetachedHookRefresh('refresh-advisor');
+}
+
// Safe require with stdout suppression - the helper modules have CLI
// sections that run unconditionally on require(), so we mute console
// during the require to prevent noisy output.
@@ -168,6 +258,57 @@ const handlers = {
} else {
console.log('[INFO] Router not available, using default routing');
}
+
+ // Rate-limit -> sponsored-capacity nudge (ADR-312/313). Fires here,
+ // client-side, BEFORE the API call this prompt would make β€” so it still
+ // reaches the transcript even if that call then fails from the rate
+ // limit. Cheap local file reads only; never a network call or a child
+ // process, so it cannot add latency to prompt submission.
+ try {
+ const rlFunnelEnv = process.env.RUFLO_FUNNEL;
+ const rlDisabledByEnv = rlFunnelEnv !== undefined && /^(0|false|off|no)$/i.test(String(rlFunnelEnv).trim());
+ const rlCiVars = ['CI', 'GITHUB_ACTIONS', 'GITLAB_CI', 'CIRCLECI', 'TRAVIS', 'BUILDKITE', 'JENKINS_URL', 'TEAMCITY_VERSION', 'TF_BUILD'];
+ const rlIsCi = rlCiVars.some((v) => {
+ const val = process.env[v];
+ return val !== undefined && val !== '' && val !== '0' && String(val).toLowerCase() !== 'false';
+ });
+ const rlHome = path.join(os.homedir(), '.ruflo');
+ let rlUserDisabled = false;
+ try {
+ const rlUserCfg = JSON.parse(fs.readFileSync(path.join(rlHome, 'funnel.json'), 'utf8'));
+ rlUserDisabled = !!(rlUserCfg && rlUserCfg.enabled === false);
+ } catch (e) { /* absent/malformed = not disabled */ }
+ let rlProjectDisabled = false;
+ try {
+ const rlProjCfg = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'claude-flow.config.json'), 'utf8'));
+ rlProjectDisabled = !!(rlProjCfg && rlProjCfg.funnel && rlProjCfg.funnel.enabled === false);
+ } catch (e) { /* absent/malformed = not disabled */ }
+
+ if (!rlDisabledByEnv && !rlIsCi && !rlUserDisabled && !rlProjectDisabled) {
+ let rlStatus = null;
+ try { rlStatus = JSON.parse(fs.readFileSync(path.join(rlHome, 'rate-limit-status.json'), 'utf8')); } catch (e) { /* not flagged */ }
+ let rlIsLimited = false;
+ if (rlStatus && rlStatus.limited) {
+ if (rlStatus.since) {
+ const rlSinceMs = Date.parse(rlStatus.since);
+ rlIsLimited = isNaN(rlSinceMs) ? true : (Date.now() - rlSinceMs) < 6 * 60 * 60 * 1000;
+ } else {
+ rlIsLimited = true;
+ }
+ }
+ if (rlIsLimited) {
+ let rlConsented = false;
+ try {
+ const rlConsentFile = JSON.parse(fs.readFileSync(path.join(rlHome, 'consent.json'), 'utf8'));
+ const rlReceipt = rlConsentFile && rlConsentFile['sponsored-downtime'];
+ rlConsented = !!(rlReceipt && rlReceipt.granted === true && rlReceipt.at !== null && rlReceipt.policyVersion === 1);
+ } catch (e) { /* not consented */ }
+ if (!rlConsented) {
+ console.log('[COGNITUM] Hit your Claude usage limit? Free sponsored capacity is available at cognitum.one/meta-llm β€” run: ruflo proxy sponsor-enable --yes');
+ }
+ }
+ }
+ } catch (e) { /* nudge must never break the hook */ }
},
'pre-bash': () => {
@@ -234,6 +375,14 @@ const handlers = {
console.log(`[INTELLIGENCE] Loaded ${initResult.nodes} patterns, ${initResult.edges} edges`);
}
}
+ // Warm the funnel message cache once per session (see
+ // spawnDetachedFunnelRefresh's doc comment for why this must happen
+ // here, detached, rather than as the statusline's own fire-and-forget).
+ spawnDetachedFunnelRefresh();
+ // ADR-316 co-pilot advisor tip β€” same detached pattern; cheap no-op
+ // when not consented or still within the 24h TTL (see refresh-advisor's
+ // own doc comment).
+ spawnDetachedAdvisorRefresh();
},
'session-end': async () => {
diff --git a/.claude/helpers/statusline.cjs b/.claude/helpers/statusline.cjs
index 1fae69d876..85f64b6188 100755
--- a/.claude/helpers/statusline.cjs
+++ b/.claude/helpers/statusline.cjs
@@ -598,6 +598,22 @@ function getCostFromStdin() {
}
// Read package version from the first package.json we find.
+// Compares dotted-numeric version strings (e.g. "3.27.1" vs "3.27.10").
+// Returns >0 if a>b, <0 if a<b, 0 if equal-as-far-as-parseable. Deliberately
+// simple (no prerelease/build-metadata handling) β€” this only orders local
+// package.json versions against each other, never anything untrusted from
+// a payload, so a full semver implementation would be dead weight here.
+function compareVersions(a, b) {
+ const pa = String(a).split('.').map((n) => parseInt(n, 10));
+ const pb = String(b).split('.').map((n) => parseInt(n, 10));
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
+ const na = Number.isFinite(pa[i]) ? pa[i] : 0;
+ const nb = Number.isFinite(pb[i]) ? pb[i] : 0;
+ if (na !== nb) return na - nb;
+ }
+ return 0;
+}
+
function getPkgVersion() {
let ver = '3.6';
try {
@@ -629,11 +645,24 @@ function getPkgVersion() {
);
}
} catch { /* ignore */ }
+ // Pick the HIGHEST version among every candidate that exists, not the
+ // first one found. The marketplace plugin path is probed first (list
+ // order above), but Claude Code's own plugin marketplace mechanism
+ // syncs on its own git-pull cadence, independent of npm publishes β€” a
+ // freshly-published npm version can sit alongside a stale marketplace
+ // checkout for a while (observed live: marketplace one release behind
+ // right after a publish). Taking the first EXISTING candidate meant the
+ // header could show a stale version even when a newer install (e.g.
+ // node_modules/@claude-flow/cli from a plain npm install) was sitting right there.
+ let found = false;
for (const p of pkgPaths) {
if (!fs.existsSync(p)) continue;
try {
const pkg = JSON.parse(fs.readFileSync(p, 'utf-8'));
- if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) { ver = pkg.version; break; }
+ if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) {
+ if (!found || compareVersions(pkg.version, ver) > 0) ver = pkg.version;
+ found = true;
+ }
} catch { /* ignore */ }
}
} catch { /* ignore */ }
diff --git a/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json b/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json
index 70259dcd39..e7f0980dac 100644
--- a/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json
+++ b/v3/@claude-flow/cli/.claude/helpers/helpers.manifest.json
@@ -1,13 +1,13 @@
{
"manifest": {
- "version": "3.27.1",
+ "version": "3.27.2",
"files": {
"auto-memory-hook.mjs": "68be7e9a9eba7bf9c4e8a230db7bf61a243b965639f8504842799d6c6ca28762",
"hook-handler.cjs": "2e4927ff158c0079a67a6f0ef0b99ac748d600d33798b0a5fbd5a6a82225ec03",
"intelligence.cjs": "bd1f8e4b034944aee1df0391dc47ac2e8cc4b3aa542c65407a59d49620bbf76b",
- "statusline.cjs": "44882bcda49ff6dc1d3738e25b6ec23e07bdc0177321b8cd15dd966ff1c7090f"
+ "statusline.cjs": "f553f12a34e7df405a64501cdedb684374ef92670279380bc95f625fc68b2d1b"
}
},
- "signature": "roS3Sgyq3yDDiQvm0pyB3ZzdGMUoQnRYJjFdbTSW5HZqPRirjf72qgkzQu+Yw+fNfVBrS9ljS/kWpnJKt/6DAw==",
+ "signature": "40Y8+mFRgH7LZZ5TeeDM6aIUcAKrNaN82nyJJzFyepx/HM1chZeK2yEUIbtPhyE0PdyoO4W1OuR3mlxLHgBjCA==",
"algorithm": "ed25519"
}
diff --git a/v3/@claude-flow/cli/.claude/helpers/statusline.cjs b/v3/@claude-flow/cli/.claude/helpers/statusline.cjs
index 1fae69d876..85f64b6188 100644
--- a/v3/@claude-flow/cli/.claude/helpers/statusline.cjs
+++ b/v3/@claude-flow/cli/.claude/helpers/statusline.cjs
@@ -598,6 +598,22 @@ function getCostFromStdin() {
}
// Read package version from the first package.json we find.
+// Compares dotted-numeric version strings (e.g. "3.27.1" vs "3.27.10").
+// Returns >0 if a>b, <0 if a<b, 0 if equal-as-far-as-parseable. Deliberately
+// simple (no prerelease/build-metadata handling) β€” this only orders local
+// package.json versions against each other, never anything untrusted from
+// a payload, so a full semver implementation would be dead weight here.
+function compareVersions(a, b) {
+ const pa = String(a).split('.').map((n) => parseInt(n, 10));
+ const pb = String(b).split('.').map((n) => parseInt(n, 10));
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
+ const na = Number.isFinite(pa[i]) ? pa[i] : 0;
+ const nb = Number.isFinite(pb[i]) ? pb[i] : 0;
+ if (na !== nb) return na - nb;
+ }
+ return 0;
+}
+
function getPkgVersion() {
let ver = '3.6';
try {
@@ -629,11 +645,24 @@ function getPkgVersion() {
);
}
} catch { /* ignore */ }
+ // Pick the HIGHEST version among every candidate that exists, not the
+ // first one found. The marketplace plugin path is probed first (list
+ // order above), but Claude Code's own plugin marketplace mechanism
+ // syncs on its own git-pull cadence, independent of npm publishes β€” a
+ // freshly-published npm version can sit alongside a stale marketplace
+ // checkout for a while (observed live: marketplace one release behind
+ // right after a publish). Taking the first EXISTING candidate meant the
+ // header could show a stale version even when a newer install (e.g.
+ // node_modules/@claude-flow/cli from a plain npm install) was sitting right there.
+ let found = false;
for (const p of pkgPaths) {
if (!fs.existsSync(p)) continue;
try {
const pkg = JSON.parse(fs.readFileSync(p, 'utf-8'));
- if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) { ver = pkg.version; break; }
+ if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) {
+ if (!found || compareVersions(pkg.version, ver) > 0) ver = pkg.version;
+ found = true;
+ }
} catch { /* ignore */ }
}
} catch { /* ignore */ }
diff --git a/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts b/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts
index baab3056ee..3928365530 100644
--- a/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts
+++ b/v3/@claude-flow/cli/__tests__/statusline-cost-display.test.ts
@@ -20,7 +20,7 @@
import { describe, it, expect } from 'vitest';
import { execFileSync } from 'child_process';
-import { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from 'fs';
import { tmpdir } from 'os';
import path from 'path';
import { fileURLToPath } from 'url';
@@ -172,3 +172,49 @@ describe('CLI delegation command is Windows-safe (no POSIX-only shell redirect)'
for (const line of cmdLines) expect(line).not.toContain('2>/dev/null');
});
});
+
+describe('getPkgVersion() β€” highest candidate wins, not first-found', () => {
+ // Claude Code's own plugin marketplace mechanism syncs on its own git-pull
+ // cadence, independent of npm publishes β€” a freshly-published npm version
+ // can sit alongside a stale marketplace checkout for a while (observed
+ // live: right after a publish, the marketplace path β€” checked FIRST in
+ // the candidate list β€” still read the prior release). Taking the first
+ // EXISTING candidate meant the header could show a stale version even
+ // when a newer install was sitting right there in another candidate.
+ it('source pins the max-version-wins comparison, not break-on-first-match', () => {
+ expect(SCRIPT).toContain('function compareVersions(');
+ expect(SCRIPT).toContain('compareVersions(pkg.version, ver) > 0');
+ });
+
+ it('renders the HIGHER of two real candidate package.json versions', () => {
+ const home = mkdtempSync(path.join(tmpdir(), 'ruflo-statusline-ver-home-'));
+ const cwd = mkdtempSync(path.join(tmpdir(), 'ruflo-statusline-ver-cwd-'));
+ const scriptPath = path.join(cwd, 'statusline.cjs');
+ writeFileSync(scriptPath, SCRIPT, 'utf-8');
+ try {
+ // Marketplace candidate (checked first) β€” deliberately the STALE one.
+ const marketplaceDir = path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo');
+ mkdirSync(marketplaceDir, { recursive: true });
+ writeFileSync(path.join(marketplaceDir, 'package.json'), JSON.stringify({ version: '3.27.0' }));
+ // v3 monorepo candidate (checked later) β€” the NEWER one.
+ const monorepoDir = path.join(cwd, 'v3', '@claude-flow', 'cli');
+ mkdirSync(monorepoDir, { recursive: true });
+ writeFileSync(path.join(monorepoDir, 'package.json'), JSON.stringify({ version: '3.27.1' }));
+
+ const payload = JSON.stringify({ model: { display_name: 'Opus 4.8' } });
+ const out = execFileSync(process.execPath, [scriptPath], {
+ input: payload,
+ encoding: 'utf-8',
+ cwd,
+ env: { PATH: '/nonexistent', HOME: home },
+ timeout: 15000,
+ });
+ const header = stripAnsi(out).split('\n')[0];
+ expect(header).toContain('V3.27.1');
+ expect(header).not.toContain('V3.27.0');
+ } finally {
+ rmSync(home, { recursive: true, force: true });
+ rmSync(cwd, { recursive: true, force: true });
+ }
+ });
+});
diff --git a/v3/@claude-flow/cli/catalog-manifest.json b/v3/@claude-flow/cli/catalog-manifest.json
index 41aa736125..d4f8837644 100644
--- a/v3/@claude-flow/cli/catalog-manifest.json
+++ b/v3/@claude-flow/cli/catalog-manifest.json
@@ -1,8 +1,8 @@
{
"schemaVersion": 1,
"generation": 1,
- "generatedAt": "2026-07-14T03:48:36.860Z",
- "gitSha": "5ca9ce1b",
+ "generatedAt": "2026-07-14T04:02:10.768Z",
+ "gitSha": "dbcfe15f",
"catalog": {
"agents": 164,
"tools": 387,
diff --git a/v3/@claude-flow/cli/package-lock.json b/v3/@claude-flow/cli/package-lock.json
index 1ddddf9f94..0830e9d2ae 100644
--- a/v3/@claude-flow/cli/package-lock.json
+++ b/v3/@claude-flow/cli/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@claude-flow/cli",
- "version": "3.27.1",
+ "version": "3.27.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@claude-flow/cli",
- "version": "3.27.1",
+ "version": "3.27.2",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index e0e59f41cc..7b76a5593b 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
- "version": "3.27.1",
+ "version": "3.27.2",
"type": "module",
"description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
"main": "dist/src/index.js",
diff --git a/v3/@claude-flow/cli/src/init/statusline-generator.ts b/v3/@claude-flow/cli/src/init/statusline-generator.ts
index 046eaea429..d74cef31bb 100644
--- a/v3/@claude-flow/cli/src/init/statusline-generator.ts
+++ b/v3/@claude-flow/cli/src/init/statusline-generator.ts
@@ -625,6 +625,22 @@ function getCostFromStdin() {
}
// Read package version from the first package.json we find.
+// Compares dotted-numeric version strings (e.g. "3.27.1" vs "3.27.10").
+// Returns >0 if a>b, <0 if a<b, 0 if equal-as-far-as-parseable. Deliberately
+// simple (no prerelease/build-metadata handling) β€” this only orders local
+// package.json versions against each other, never anything untrusted from
+// a payload, so a full semver implementation would be dead weight here.
+function compareVersions(a, b) {
+ const pa = String(a).split('.').map((n) => parseInt(n, 10));
+ const pb = String(b).split('.').map((n) => parseInt(n, 10));
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
+ const na = Number.isFinite(pa[i]) ? pa[i] : 0;
+ const nb = Number.isFinite(pb[i]) ? pb[i] : 0;
+ if (na !== nb) return na - nb;
+ }
+ return 0;
+}
+
function getPkgVersion() {
let ver = '3.6';
try {
@@ -656,11 +672,24 @@ function getPkgVersion() {
);
}
} catch { /* ignore */ }
+ // Pick the HIGHEST version among every candidate that exists, not the
+ // first one found. The marketplace plugin path is probed first (list
+ // order above), but Claude Code's own plugin marketplace mechanism
+ // syncs on its own git-pull cadence, independent of npm publishes β€” a
+ // freshly-published npm version can sit alongside a stale marketplace
+ // checkout for a while (observed live: marketplace one release behind
+ // right after a publish). Taking the first EXISTING candidate meant the
+ // header could show a stale version even when a newer install (e.g.
+ // node_modules/@claude-flow/cli from a plain npm install) was sitting right there.
+ let found = false;
for (const p of pkgPaths) {
if (!fs.existsSync(p)) continue;
try {
const pkg = JSON.parse(fs.readFileSync(p, 'utf-8'));
- if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) { ver = pkg.version; break; }
+ if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) {
+ if (!found || compareVersions(pkg.version, ver) > 0) ver = pkg.version;
+ found = true;
+ }
} catch { /* ignore */ }
}
} catch { /* ignore */ }