fix: resolve bundled hooks path on npm global install#11339
fix: resolve bundled hooks path on npm global install#11339matthewpoe wants to merge 2 commits intoopenclaw:mainfrom
Conversation
On npm global installs (Linux), the bundled code lives in dist/ rather than dist/hooks/bundled-dir.js, so moduleDir resolves to dist/ and path.join(moduleDir, 'bundled') looks for dist/bundled instead of dist/hooks/bundled. Adding 'hooks' to the path join fixes discovery for all four bundled hooks (session-memory, boot-md, command-logger, soul-evil). Fixes openclaw#11331
src/hooks/bundled-dir.ts
Outdated
| // npm: resolve `<packageRoot>/dist/hooks/bundled` relative to this module. | ||
| // When bundled, import.meta.url resolves to dist/, so we need hooks/bundled. | ||
| try { | ||
| const moduleDir = path.dirname(fileURLToPath(import.meta.url)); | ||
| const distBundled = path.join(moduleDir, "bundled"); | ||
| const distBundled = path.join(moduleDir, "hooks", "bundled"); | ||
| if (fs.existsSync(distBundled)) { |
There was a problem hiding this comment.
Breaks non-bundled npm layout
moduleDir here is dirname(fileURLToPath(import.meta.url)). In a standard (non-flattened) npm install where this module lives at dist/hooks/bundled-dir.js (as your previous comment described), moduleDir will be dist/hooks, so path.join(moduleDir, "hooks", "bundled") resolves to dist/hooks/hooks/bundled and bundled hooks won’t be discovered. This only works if import.meta.url points at dist/ (flattened bundle), so this change needs to handle both layouts (e.g., try moduleDir/bundled and moduleDir/hooks/bundled, or resolve from package root).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/hooks/bundled-dir.ts
Line: 22:27
Comment:
**Breaks non-bundled npm layout**
`moduleDir` here is `dirname(fileURLToPath(import.meta.url))`. In a standard (non-flattened) npm install where this module lives at `dist/hooks/bundled-dir.js` (as your previous comment described), `moduleDir` will be `dist/hooks`, so `path.join(moduleDir, "hooks", "bundled")` resolves to `dist/hooks/hooks/bundled` and bundled hooks won’t be discovered. This only works if `import.meta.url` points at `dist/` (flattened bundle), so this change needs to handle both layouts (e.g., try `moduleDir/bundled` and `moduleDir/hooks/bundled`, or resolve from package root).
How can I resolve this? If you propose a fix, please make it concise.Try moduleDir/bundled first (non-flattened: dist/hooks/bundled-dir.js), then moduleDir/hooks/bundled (flattened: dist/chunk.js). Covers both install layouts without breaking either.
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing as AI-assisted stale-fix triage. Linked issue #11331 ("Bug: Bundled hooks broken on npm global install (Linux) — path resolution + missing handler files") is currently closed and was closed on 2026-02-14T02:04:51Z with state reason completed. If this specific implementation is still needed on current main, please reopen #11339 (or open a new focused fix PR) and reference #11331 for fast re-triage. |
Summary
Fixes #11331 (path resolution). The related build/packaging issue is tracked separately in #11348.
Problem
On npm global installs, the build bundles bundled-dir.ts into a flat chunk in dist/, so import.meta.url resolves to dist/ rather than dist/hooks/bundled-dir.js. The existing code does path.join(moduleDir, "bundled") which looks for dist/bundled, but the hooks live at dist/hooks/bundled.
This causes all four bundled hooks (session-memory, boot-md, command-logger, soul-evil) to be undiscoverable.
Fix
One-line change: add "hooks" to the path join so it correctly resolves to dist/hooks/bundled.
Verification
Setting OPENCLAW_BUNDLED_HOOKS_DIR to the correct path manually confirms the gateway discovers all four hook directories. This fix makes that the default behavior.
Greptile Overview
Greptile Summary
Updates
resolveBundledHooksDir()to look for bundled hooks underdist/hooks/bundledwhenimport.meta.urlresolves to the flatteneddist/directory (observed on npm global installs).However, the new join logic uses
path.join(moduleDir, "hooks", "bundled"), which breaks the standard (non-flattened) layout whereimport.meta.urlpoints atdist/hooks/bundled-dir.js(it would resolve todist/hooks/hooks/bundled). The resolver should account for both layouts (or resolve from the package root) to avoid regressing non-global installs.Confidence Score: 2/5
import.meta.urlpoints atdist/hooks/bundled-dir.js(standard output), causing bundled hooks to become undiscoverable in that scenario.(2/5) Greptile learns from your feedback when you react with thumbs up/down!