Skip to content

fix(statusline): getPkgVersion() resolves main repo node_modules when CWD is a git worktree (#2742) - #2743

Closed
michaelaperez-byte wants to merge 1 commit into
ruvnet:mainfrom
michaelaperez-byte:loop/T19-worktree-pkg-version
Closed

fix(statusline): getPkgVersion() resolves main repo node_modules when CWD is a git worktree (#2742)#2743
michaelaperez-byte wants to merge 1 commit into
ruvnet:mainfrom
michaelaperez-byte:loop/T19-worktree-pkg-version

Conversation

@michaelaperez-byte

Copy link
Copy Markdown
Contributor

Summary

Fixes #2742

When Claude Code runs inside a git worktree (common multi-agent pattern), the worktree has no node_modules of its own. getPkgVersion() in the generated statusline (statusline.cjs) probed CWD/node_modules/... — which all missed — causing the statusline to show a stale baked-in version instead of the actually-installed one.

Fix

Added a worktree probe to getPkgVersion() that resolves the main repo node_modules when CWD is a linked worktree. In a worktree, .git is a plain file containing gitdir: /path/to/main/.git/worktrees/<name>. The probe:

  1. Walks up from CWD to find the nearest .git entry
  2. If .git is a file (worktree indicator), reads the gitdir: line
  3. Extracts the main repo root via lastIndexOf('/.git/worktrees/')
  4. Adds the main repo node_modules/ruflo/package.json and node_modules/@claude-flow/cli/package.json to the candidate paths

Pure fs operations — no process spawn (matches the template design constraint for the render path). Slots into the existing candidate list before the #2221 global-install probes, so the highest-version-wins selection applies unchanged.

Changes

File Change
.claude/helpers/statusline.cjs +27 lines (worktree probe in getPkgVersion())
v3/@claude-flow/cli/.claude/helpers/statusline.cjs +27 lines (identical, drift-guard enforced)
v3/@claude-flow/cli/__tests__/issue-2742-worktree-pkg-version.test.ts +125 lines (5 test cases)

Total: 3 files, +179 lines, 0 deletions (additive only).

Verification

Independent detached-HEAD worktree verification — all gates PASS:

Context

Same function/lineage as #2195 and #2221 — this closes the remaining resolution gap for worktree environments. Reporter (Markus-Buchholz) provided the code snippet; this PR adapts it to the existing code style.

Generated by ruflo-loop (z-ai/glm-5.2, cheap tier).

@michaelaperez-byte

Copy link
Copy Markdown
Contributor Author

Superseded by merged PR #2747

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

statusline getPkgVersion() misses the project install when CWD is a git worktree — falls back to baked-in version

1 participant