fix: resolve bundled hooks path on npm global install#11339
Open
matthewpoe wants to merge 2 commits intoopenclaw:mainfrom
Open
fix: resolve bundled hooks path on npm global install#11339matthewpoe wants to merge 2 commits intoopenclaw:mainfrom
matthewpoe 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
This was referenced Feb 7, 2026
src/hooks/bundled-dir.ts
Outdated
Comment on lines
22
to
27
| // 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)) { |
Contributor
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.
SutanuNandigrami
pushed a commit
to SutanuNandigrami/openclaw
that referenced
this pull request
Feb 8, 2026
bfc1ccb to
f92900f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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!