fix(statusline): read installed version from plugin package.json (#1951) (#1960)

The statusline showed a hard-coded "RuFlo V3.5" regardless of the
installed version, even on alpha.27 where `ruflo doctor` correctly
reported the real version.

Two files had the bug:

1. `v3/@claude-flow/cli/.claude/helpers/statusline.cjs` — fully hard-coded
   `▊ RuFlo V3.5 ` in both header constructions, with no version-reading
   logic at all. Added a startup version-probe (4 candidate package.jsons,
   preferring the plugin install at `~/.claude/plugins/marketplaces/ruflo/`)
   and wired `${RUFLO_VERSION}` into both headers.

2. `.claude/helpers/statusline.cjs` — already had version-reading, but its
   candidate list only checked project-local `node_modules` paths, never
   the plugin install location. Plugin users always fell back to `'3.5'`.
   Added the plugin path as the first candidate.

3. `v3/@claude-flow/cli/src/init/statusline-generator.ts` — the template
   that writes `<project>/.claude/helpers/statusline.cjs` at init time had
   the same too-narrow candidate list. Same fix, applied to the template.

Probe order for all three:
  1. ~/.claude/plugins/marketplaces/ruflo/package.json   (plugin install)
  2. <cwd>/node_modules/@claude-flow/cli/package.json    (npm install)
  3. <cwd>/node_modules/ruflo/package.json               (umbrella)
  4. <cwd>/v3/@claude-flow/cli/package.json              (source checkout)

Falls through to a hard-coded default if all four are missing or malformed.

Build verified clean (tsc) on @claude-flow/cli.

Resolves #1951.

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
This commit is contained in:
rUvandReuven authored and GitHub committed 2026-05-13 09:24:07 -04:00
1 parent 434a8f95bb
commit 7ca28a7593
3 files changed
+71 -20

No files matched your search

+15 -4
View File
@@ -26,18 +26,29 @@ const CONFIG = {
const CWD = process.cwd();
// Read package version once at startup
// Read package version once at startup. Probe the plugin's own install
// location first — `~/.claude/plugins/marketplaces/ruflo/package.json` — so
// users who installed via `/plugin install ruflo@ruflo` see the real version,
// not the hardcoded fallback (#1951).
let pkgVersion = '3.5';
try {
const os = require('os');
const home = os.homedir();
const pkgPaths = [
path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo', 'package.json'),
path.join(CWD, 'node_modules', '@claude-flow', 'cli', 'package.json'),
path.join(CWD, 'node_modules', 'ruflo', 'package.json'),
path.join(CWD, 'v3', '@claude-flow', 'cli', 'package.json'),
];
for (const p of pkgPaths) {
if (fs.existsSync(p)) {
if (!fs.existsSync(p)) continue;
try {
const pkg = JSON.parse(fs.readFileSync(p, 'utf-8'));
if (pkg.version) { pkgVersion = pkg.version; break; }
}
if (pkg && typeof pkg.version === 'string' && pkg.version.length > 0) {
pkgVersion = pkg.version;
break;
}
} catch { /* malformed package.json — try next */ }
}
} catch { /* use default */ }
@@ -25,8 +25,37 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execSync, execFileSync } = require('child_process');
// Read the installed plugin version once at startup. Probe the plugin's own
// install location first (`~/.claude/plugins/marketplaces/ruflo/package.json`),
// then npm-style installs, then the source-checkout location. The previous
// code hardcoded `RuFlo V3.5` in the header — so users on alpha.27+ still
// saw V3.5 in the statusline even though `ruflo doctor` reported the real
// version (#1951).
let RUFLO_VERSION = '3.6';
try {
const home = os.homedir();
const cwd = process.cwd();
const pkgPaths = [
path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo', 'package.json'),
path.join(cwd, 'node_modules', '@claude-flow', 'cli', 'package.json'),
path.join(cwd, 'node_modules', 'ruflo', 'package.json'),
path.join(cwd, 'v3', '@claude-flow', 'cli', 'package.json'),
];
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) {
RUFLO_VERSION = pkg.version;
break;
}
} catch { /* malformed package.json — try next */ }
}
} catch { /* fall through to the hardcoded default */ }
// Configuration
const CONFIG = {
enabled: true,
@@ -402,7 +431,7 @@ function generateStatusline() {
const lines = [];
// Header Line
let header = `${c.bold}${c.brightPurple}▊ RuFlo V3.5 ${c.reset}`;
let header = `${c.bold}${c.brightPurple}▊ RuFlo V${RUFLO_VERSION} ${c.reset}`;
header += `${swarm.coordinationActive ? c.brightCyan : c.dim}● ${c.brightCyan}${user.name}${c.reset}`;
if (user.gitBranch) {
header += ` ${c.dim}│${c.reset} ${c.brightBlue}⎇ ${user.gitBranch}${c.reset}`;
@@ -508,7 +537,7 @@ function generateSafeStatusline() {
const lines = [];
// Header Line
let header = `${c.bold}${c.brightPurple}▊ RuFlo V3.5 ${c.reset}`;
let header = `${c.bold}${c.brightPurple}▊ RuFlo V${RUFLO_VERSION} ${c.reset}`;
header += `${swarm.coordinationActive ? c.brightCyan : c.dim}● ${c.brightCyan}${user.name}${c.reset}`;
if (user.gitBranch) {
header += ` ${c.dim}│${c.reset} ${c.brightBlue}⎇ ${user.gitBranch}${c.reset}`;
@@ -641,23 +641,34 @@ function generateStatusline() {
const integration = getIntegrationStatus();
const lines = [];
// Header
// Read version from package.json
// Header — read version from the FIRST package.json we find, preferring
// the plugin install at ~/.claude/plugins/marketplaces/ruflo/package.json.
// The previous list only checked project-local node_modules, so plugin
// users saw the hard-coded fallback (V3.5) even on newer alphas (#1951).
let pkgVersion = '3.6';
try {
const pkgPath = path.join(CWD, 'node_modules', '@claude-flow', 'cli', 'package.json');
if (fs.existsSync(pkgPath)) {
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
if (pkg.version) pkgVersion = pkg.version;
} else {
// Try npx-installed location
const npxPkg = path.join(CWD, 'v3', '@claude-flow', 'cli', 'package.json');
if (fs.existsSync(npxPkg)) {
const pkg = JSON.parse(fs.readFileSync(npxPkg, 'utf-8'));
if (pkg.version) pkgVersion = pkg.version;
}
const home = require('os').homedir();
const pkgPaths = [
// 1. The plugin's own root (installed via /plugin install).
path.join(home, '.claude', 'plugins', 'marketplaces', 'ruflo', 'package.json'),
// 2. Project-local @claude-flow/cli — npm-style install.
path.join(CWD, 'node_modules', '@claude-flow', 'cli', 'package.json'),
// 3. Project-local ruflo umbrella.
path.join(CWD, 'node_modules', 'ruflo', 'package.json'),
// 4. Source-checkout location (when developing in this repo).
path.join(CWD, 'v3', '@claude-flow', 'cli', 'package.json'),
];
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) {
pkgVersion = pkg.version;
break;
}
} catch { /* malformed package.json — try next */ }
}
} catch { /* use default */ }
} catch { /* fall through to the hardcoded default */ }
let header = c.bold + c.brightPurple + '\\u258A RuFlo V' + pkgVersion + ' ' + c.reset;
header += (swarm.coordinationActive ? c.brightCyan : c.dim) + '\\u25CF ' + c.brightCyan + git.name + c.reset;
if (git.gitBranch) {