Description
When installing from source (as documented in the README under For Developers), two issues occur simultaneously:
opencli --version always reports 0.0.0 instead of the actual version.
- Every command in
~/.opencli/clis/ fails with Failed to load module ... Cannot find module '/Users/<user>/.opencli/src/registry.js'.
Environment
- Install method: from source (
git clone → npm install → npm run build → npm link / pnpm link --global)
- Node: v24.14.1 (via nvm)
- npm: latest
- OS: macOS
- opencli version (package.json): 1.6.3
Steps to Reproduce
git clone git@github.com:jackwener/opencli.git && cd opencli
npm install
npm run build
npm link # or: pnpm link --global
opencli --version
opencli doctor
Root Cause Analysis
Bug 1 — version reports 0.0.0
src/version.ts resolves package.json with one level up from __dirname:
// src/version.ts
const pkgJsonPath = path.resolve(__dirname, '..', 'package.json');
At runtime after npm run build, __dirname is dist/src/. One level up is dist/, where no package.json exists. The try/catch silently falls back to '0.0.0'.
This works fine for npm install -g users because npm automatically includes the root package.json in the published package, placing it at <package-root>/package.json — exactly one level above dist/src/. But when running from a cloned repo, the root package.json is two levels above dist/src/.
Fix:
- const pkgJsonPath = path.resolve(__dirname, '..', 'package.json');
+ const pkgJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
Bug 2 — Failed to load module ~/.opencli/clis/*.js
The postinstall / fetch-adapters.js script downloads pre-compiled .js adapter files into ~/.opencli/clis/. These files contain hardcoded absolute-style imports:
Cannot find module '/Users/<user>/.opencli/src/registry.js'
Cannot find module '/Users/<user>/.opencli/src/errors.js'
However, ~/.opencli/src/ is never created — the core runtime lives inside the npm package's dist/src/, not under ~/.opencli/. These pre-compiled clis appear to have been built against an older layout where the source was symlinked or copied into ~/.opencli/src/.
Workaround (user-side): rm -rf ~/.opencli/clis/ causes opencli to fall back to the built-in YAML-driven commands in dist/clis/, avoiding the broken imports entirely.
Expected Behavior
opencli --version → 1.6.3
opencli doctor → no Failed to load module warnings
Actual Behavior
opencli --version → 0.0.0
- Hundreds of
⚠ Failed to load module warnings for every adapter in ~/.opencli/clis/
Suggested Fix
For Bug 1, the one-line change above in src/version.ts is sufficient. It is backward-compatible: when installed via npm install -g, the root package.json is still two levels above dist/src/ inside the installed package directory.
For Bug 2, the pre-compiled .js files distributed by fetch-adapters.js may need to be rebuilt with correct import paths that resolve against the npm package's installed location rather than ~/.opencli/src/.
Description
When installing from source (as documented in the README under For Developers), two issues occur simultaneously:
opencli --versionalways reports0.0.0instead of the actual version.~/.opencli/clis/fails withFailed to load module ... Cannot find module '/Users/<user>/.opencli/src/registry.js'.Environment
git clone→npm install→npm run build→npm link/pnpm link --global)Steps to Reproduce
Root Cause Analysis
Bug 1 —
versionreports0.0.0src/version.tsresolvespackage.jsonwith one level up from__dirname:At runtime after
npm run build,__dirnameisdist/src/. One level up isdist/, where nopackage.jsonexists. Thetry/catchsilently falls back to'0.0.0'.This works fine for
npm install -gusers because npm automatically includes the rootpackage.jsonin the published package, placing it at<package-root>/package.json— exactly one level abovedist/src/. But when running from a cloned repo, the rootpackage.jsonis two levels abovedist/src/.Fix:
Bug 2 —
Failed to load module ~/.opencli/clis/*.jsThe
postinstall/fetch-adapters.jsscript downloads pre-compiled.jsadapter files into~/.opencli/clis/. These files contain hardcoded absolute-style imports:However,
~/.opencli/src/is never created — the core runtime lives inside the npm package'sdist/src/, not under~/.opencli/. These pre-compiled clis appear to have been built against an older layout where the source was symlinked or copied into~/.opencli/src/.Workaround (user-side):
rm -rf ~/.opencli/clis/causes opencli to fall back to the built-in YAML-driven commands indist/clis/, avoiding the broken imports entirely.Expected Behavior
opencli --version→1.6.3opencli doctor→ noFailed to load modulewarningsActual Behavior
opencli --version→0.0.0⚠ Failed to load modulewarnings for every adapter in~/.opencli/clis/Suggested Fix
For Bug 1, the one-line change above in
src/version.tsis sufficient. It is backward-compatible: when installed vianpm install -g, the rootpackage.jsonis still two levels abovedist/src/inside the installed package directory.For Bug 2, the pre-compiled
.jsfiles distributed byfetch-adapters.jsmay need to be rebuilt with correct import paths that resolve against the npm package's installed location rather than~/.opencli/src/.