Repository navigation
Description
Context
npm/node module resolution walks up the directory tree looking for node_modules. If a user accidentally runs npm install sequant from $HOME, every subdirectory of home then resolves to that stale copy — not just the intended project.
Encountered live: ~/package.json contained only { "dependencies": { "sequant": "^1.20.0" } } from an install months prior. npx sequant update from a project subdirectory resolved to $HOME/node_modules/[email protected] instead of either the project-local install or the npx cache, so update/sync ran ancient template logic against a freshly-initialized v2.2.0 project.
The CLI already warns today:
⚠️ Running sequant from local node_modules
For latest version: npx sequant@latest
…but the warning doesn't name the path, and the pathological $HOME/node_modules case is indistinguishable from a legitimate project-local install.
Proposal
When the CLI resolves its own install path to $HOME/node_modules/sequant exactly, emit a distinct warning that names the path and the cleanup commands:
⚠️ Sequant is running from $HOME/node_modules/sequant — this pollutes
resolution for every subdirectory of your home directory.
If accidental (usually is — one stray `npm install sequant` from ~ does it):
remove $HOME/node_modules
remove $HOME/package.json and $HOME/package-lock.json
If intentional: use `npm install -g sequant` or the Claude Code plugin.
Acceptance Criteria
- CLI resolves its own install path on startup (via
import.meta.url/__dirname) - When resolved path equals
path.join(os.homedir(), 'node_modules', 'sequant'), emit the distinct warning with cleanup guidance - Legitimate project-local installs (
<project>/node_modules/sequant) retain the existing generic warning unchanged - Global installs (
npm root -g) and npx cache paths are not flagged - Unit test covers all four cases: home stray, project-local, global, npx cache
Out of Scope
- Auto-removing the stray install — too destructive to automate inside
$HOME - Detecting pollution at other parent levels (e.g.
~/Projects/node_modules) — same footgun, much rarer
Priority
Low. Rare edge case — the existing generic warning already points users toward npx sequant@latest, which is the correct workaround. Filing for completeness.
Activity
admarble commentedon Apr 23, 2026
→ PROCEED — Stray $HOME/node_modules/sequant install detection + targeted warning. AC-5 names unit test coverage, so testgen applies.
Workflow:
spec → testgen → exec → qa· 5 ACs```
npx sequant run 539 --phases spec,testgen,exec,qa
```
admarble commentedon Apr 25, 2026
Complexity: Standard (5 ACs, 2 directories:
bin/,src/lib/)AC Quality Check
All 5 ACs are concrete and measurable — paths are named, comparisons are exact (
path.join(os.homedir(), 'node_modules', 'sequant')), and the "four cases" test set is explicitly enumerated. No vague terms.Scope Assessment
Non-Goals (from issue):
~/Projects/node_modules)bin/cli.ts,src/lib/version-check.ts+ test)Verdict: SCOPE_OK — single feature, narrowly scoped, clear non-goals.
Acceptance Criteria
AC-1: CLI resolves its own install path on startup (via
import.meta.url/__dirname)Verification: Unit Test
Scenario: Given the CLI is invoked → When startup runs → Then resolved install path equals the directory containing sequant's
package.json.Note:
version-check.tsalready walks up from__dirnameto findpackage.json(seegetCurrentVersion). Reuse that logic in a newgetInstallRoot()helper.AC-2: When resolved path equals
path.join(os.homedir(), 'node_modules', 'sequant'), emit the distinct warning with cleanup guidanceVerification: Unit Test
Scenario: Given install root ===
$HOME/node_modules/sequant→ When startup warning logic runs → Then output contains: the resolved path, "pollutes resolution for every subdirectory", the two cleanup commands, and the "If intentional" alternative.Assumptions: Exact-equality match (not
startsWith) — covered by AC-2's "exactly" wording and the non-goal excluding deeper paths.AC-3: Legitimate project-local installs (
<project>/node_modules/sequant) retain the existing generic warning unchangedVerification: Unit Test
Scenario: Given install root ===
/some/project/node_modules/sequant(not equal to$HOME/node_modules/sequant) → When startup runs → Then existing "Running sequant from local node_modules" warning is emitted, and the home-stray warning is NOT emitted.AC-4: Global installs (
npm root -g) and npx cache paths are not flaggedVerification: Unit Test
Scenario: Given install root in
npm root -goutput OR matching~/.npm/_npx/<hash>/node_modules/sequant→ When startup runs → Then no warning is emitted (current behavior preserved for these cases).AC-5: Unit test covers all four cases: home stray, project-local, global, npx cache
Verification: Unit Test
Scenario:
version-check.test.tsincludes one test per case, mockingos.homedir()and__dirname-equivalent input to the new function.Note: Existing test file mocks
process.env.HOME = "/home/user". Addos.homedir()mock or pass install path as argument for testability.Implementation Plan
Phase 1: Detection logic (
src/lib/version-check.ts)getInstallRoot(): string | null— walks up from__dirnameto the directory containing sequant'spackage.json(extract from existinggetCurrentVersionlogic).isHomeStrayInstall(installRoot?: string): boolean— returnstrueiff resolved root ===path.join(os.homedir(), 'node_modules', 'sequant'). Accepts optional override for testability.isLocalNodeModulesInstall()unchanged — AC-3 requires the generic warning to be preserved.Phase 2: Warning emission (
bin/cli.ts)isHomeStrayInstall()first → emit the distinct warning with the path and both cleanup commands. Else ifisLocalNodeModulesInstall()→ keep the existing generic warning. Usechalk.yellowfor parity.Phase 3: Tests (
src/lib/version-check.test.ts)describe("isHomeStrayInstall", ...)block with four cases:/home/user/node_modules/sequant→ returnstrue/projects/foo/node_modules/sequant→ returnsfalse/usr/local/lib/node_modules/sequant→ returnsfalse/home/user/.npm/_npx/abc123/node_modules/sequant→ returnsfalseisHomeStrayInstall(installRoot)to avoid mocking__dirname.Design Review
src/lib/version-check.ts— already ownsisLocalNodeModulesInstall()andgetCurrentVersion()walk-up logic. Adding a sibling function preserves cohesion.isLocalNodeModulesInstall()predicate-plus-warning pattern. Same chalk styling, same--quietopt-out, same warning location inbin/cli.ts.getInstallType()enum?" — Considered, but a separate predicate keeps the diff minimal, preserves AC-3's "unchanged" guarantee for the generic warning, and avoids touching call sites that only care about local-vs-not.Feature Quality Planning
All standard checks pass. Notable items:
isLocalNodeModulesInstall()signature unchanged; new function is additive.path.join+path.normalize(orpath.resolve) for the comparison — case sensitivity isn't a concern on macOS/Linux butpath.joinnormalizes separators consistently.os.homedir()+path.join+ string compare on startup — negligible.Open Questions
Recommended Workflow
Phases: spec → testgen → exec → qa
Quality Loop: disabled (SCOPE_OK)
Reasoning: ACs are Unit Test-verified across four mocked path scenarios → testgen will stub the four cases up front. No UI, so
/testskipped.no-browser-testnot needed.Label Review
Current:
enhancement,cliRecommended: add
simple-fixor leave as-isReason: ~30-line diff across 3 files, no architectural impact.
cliandenhancementalready cover it.admarble commentedon Apr 25, 2026
admarble commentedon Apr 25, 2026
Exec Complete (orchestrated)
Branch:
feature/539-cli-detect-stray-home-node-modules(commit 2d6bed6)AC Coverage
getInstallRoot()walks up from__dirnameto sequant's package.json (src/lib/version-check.ts:96-114)bin/cli.ts:81-101whenisHomeStrayInstall()returns true; names the resolved path, both cleanup commands, and the "If intentional" alternativeremovePkgline (bin/cli.ts:91-99)isHomeStrayInstall()uses exact-equality check vspath.join(os.homedir(), 'node_modules', 'sequant'); global (/usr/local/lib/...) and npx-cache (~/.npm/_npx/...) paths never matchsrc/lib/version-check.test.tscover home-stray, project-local, global, npx-cache (plus a fifth for the null install root case)Quality Gates
tsc)eslint src/ bin/ --max-warnings 0)version-check.test.ts, 5 of which are new)admarble commentedon Apr 25, 2026
QA Review for Issue #539
AC Coverage
getInstallRoot()walks up from__dirnamelooking for sequant'spackage.json(src/lib/version-check.ts:111-128); mirrors the existinggetCurrentVersion()walk-up pattern$HOME/node_modules/sequantbin/cli.ts:82-93interpolates the resolved install path, names the cleanup commands (remove $HOME/node_modules,remove $HOME/package.jsonandpackage-lock.json), and lists the legitimate alternatives (npm install -g sequant, Claude Code plugin) — matches the warning template in the issue bodyelse ifbranch (bin/cli.ts:94-102) preserves the original message text,pmCommands.removePkginterpolation, and chalk styling byte-for-byteisHomeStrayInstalluses exact path-equality vspath.join(os.homedir(), "node_modules", "sequant"). Verified by tests:/usr/local/lib/node_modules/sequant→ false,/home/user/.npm/_npx/abc123/node_modules/sequant→ false. Globals continue to receive the existing generic warning (pre-existing behavior, AC-3 says unchanged)version-check.test.ts:155-185adds 5 tests: home-stray (true), project-local (false), global (false), npx-cache (false), null install root (false). All pass; full suite green (2678 tests)Coverage: 5/5 AC items fully met.
Quality Plan Verification
N/A —
/specdid not generate a Quality Plan section for this issue (Standard tier, narrowly scoped).CI Status
No PR opened yet — orchestrator will create one after this verdict.
Quality Metrics
anyintroduced)--max-warnings 0)Test Coverage Analysis
src/lib/version-check.tssrc/lib/version-check.test.ts(5 new tests forisHomeStrayInstall)bin/cli.tssrc/lib/version-check.test.tsCHANGELOG.mdCoverage: 1/1 changed source-with-logic file has tests.
bin/cli.tschange is a 12-line template-interpolation branch around already-tested predicates; emission text is not covered by automated tests, consistent with the existingisLocalNodeModulesInstallwarning.Code Review
Strengths:
installRootas a parameter, enabling deterministic testing of all four path cases without__dirnamefakery.getInstallRoot()mirrors the existinggetCurrentVersion()pattern — same termination condition (dir !== path.dirname(dir)), same package.json + name guard.process.env.HOME).Issues:
Suggestions (non-blocking):
getInstallRoot()andgetCurrentVersion()both walk up from__dirnamelooking for sequant'spackage.json. Could be DRYed into a single helper that returns{ root, pkg }, but the current duplication is small and the return types differ (path vs version string) — not worth refactoring in this PR.Anti-Pattern Detection
any/as anyintroducedcatch {}ingetInstallRoot()mirrors the same pattern ingetCurrentVersion()— intentional (file may not exist on the way up the tree)No new anti-patterns introduced.
package.jsonnot modified — dependency audit N/A.CLI Registration Verification
N/A — this PR does not modify
RunOptionsor any other option interface. The warning logic runs unconditionally at CLI startup; no new flags introduced (continues to honor existing--quiet).Skill Command Verification
N/A — no
.claude/skills/**/*.mdfiles modified.Smoke Test
npx tsx bin/cli.ts --helpruns cleanly in the worktree (no warning, since the worktree path is not$HOME/node_modules/sequant). End-to-end manual verification of the home-stray warning would require physically constructing$HOME/node_modules/sequant— pre-existing behavior of the generic warning was already verified as preserved (isLocalNodeModulesInstalland the else-if branch are byte-for-byte unchanged).Manual Test ACs
N/A — all 5 ACs use Verification: Unit Test.
CHANGELOG Verification
[Unreleased]entry### Added—Stray $HOME/node_modules/sequant detection ... (#539))Risk Assessment
~/Projects/node_modules/sequant) won't get the targeted warning — only the generic one. This is explicitly out of scope per the issue's Non-Goals ("same footgun, much rarer"). On Windows,path.resolve()normalizes drive letters and separators consistently, so the equality check should hold; macOS case-insensitive HFS+ relies onos.homedir()returning the case-correct path (which it does in practice).$HOME/node_modules/sequantand runs the CLI from there — the predicate logic is fully unit-tested, and the warning emission is template interpolation (no branching). Risk of regression is low.Verdict: READY_FOR_MERGE
All 5 ACs met literally. Code quality is high: predicate is testable, mirrors existing patterns, comments justify the why, build/lint/tests all green. CHANGELOG entry present. No security or scope concerns.
Documentation
Next Steps
admarble commentedon Apr 25, 2026
/fullsolve Complete
Issue: #539
Status: READY_FOR_MERGE
PR: #553
Summary
version-check.test.ts)src/lib/version-check.ts,bin/cli.ts,src/lib/version-check.test.ts,CHANGELOG.md)Iterations
vi.mock("os")after the first test run revealed macOS reads OS-level home regardless ofprocess.env.HOME)Ready for human review and merge.
fix(#539): address QA gaps — global exclusion, parent path, render test
fix(#539): Windows global path detection + polish
test(#539): close coverage gaps in isLocalNodeModulesInstall
feat(#539): detect stray $HOME/node_modules/sequant on startup (#553)
admarble commentedon May 11, 2026
Documentation Generated
File:
docs/troubleshooting.md(new section: "Stray\$HOME/node_modules/sequantinstall" under "Installation Issues (npm)")Added as a troubleshooting entry rather than a standalone feature doc — the warning users see is concrete and self-contained, and the fix is a few shell commands.
Section Includes
$HOMEfirst)$HOME/node_modules/sequantpath triggers — project-local, global, and npx cache paths are not flaggedNext Steps
Ready to merge.
docs: backfill user-facing docs for issues since v2.2.0