#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
scripts
stale
Cluster:
Hooks Enhancements and Fixes
This pull request introduces a new build process for bundled hooks, improves the way hooks are resolved and validated, and adds comprehensive tests to ensure reliability. The most significant changes are the addition of a script to bundle hooks using `esbuild`, removal of the old metadata copy script, updates to the build pipeline, and enhancements to hook resolution and validation logic.
Fixes https://github.com/openclaw/openclaw/issues/8732
---
### Bundled Hooks Build Process
* Added a new script `scripts/build-bundled-hooks.ts` that bundles each hook's handler using `esbuild`, copies `HOOK.md`, and cleans the output directory before building. This replaces the previous manual copying process and ensures handlers are built as JavaScript bundles.
* Updated the build command in `package.json` to use the new `build-bundled-hooks.ts` script instead of the old `copy-hook-metadata.ts`.
* Added `esbuild` as a dependency in `package.json` and `pnpm-lock.yaml` to support the new build process.
* Removed the old `scripts/copy-hook-metadata.ts` script, as its functionality is now integrated into the new bundling script.
### Hook Resolution and Validation Improvements
* Enhanced `src/hooks/bundled-dir.ts` to resolve bundled hooks directories more robustly, supporting both dev and production layouts, and added options for custom resolution contexts.
* Updated handler candidate ordering to prefer JavaScript files (`handler.js`, `index.js`) over TypeScript files, improving compatibility and alignment with the new build output. This change affects hook validation (`src/hooks/install.ts`) and workspace loading (`src/hooks/workspace.ts`).
### Testing and Validation
* Updated locally running instance to confirm changes work as intended
* Added tests for the new bundled hooks build script in `src/scripts/build-bundled-hooks.test.ts`, covering output correctness, cleaning of stale files, and error handling when handlers are missing.
* Added tests for hook directory resolution in `src/hooks/bundled-dir.test.ts` and for handler selection logic in `src/hooks/workspace.test.ts`.
* Extended release checks in `scripts/release-check.ts` to ensure both `HOOK.md` and `handler.js` files for all bundled hooks are included in the package.
### Miscellaneous
* Simplified the import logic in `src/hooks/bundled/session-memory/handler.ts` to directly use the `generateSlugViaLLM` function, removing unnecessary dynamic imports.
These changes modernize the build and validation process for bundled hooks, improve reliability, and make the project easier to maintain and extend.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR replaces the previous bundled hook metadata copy step with an `esbuild`-based bundling script that emits `dist/hooks/bundled/<hook>/handler.js` and copies `HOOK.md`. It also hardens bundled hook directory resolution (`resolveBundledHooksDir`) to support different install/build layouts, updates hook validation and workspace hook loading to prefer JS handlers first, and extends release packaging checks and tests to ensure bundled hook assets are present and selected correctly.
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe to merge, but has a couple of concrete correctness pitfalls in the new build/release logic.
- Most changes are straightforward and well-covered by tests, but (1) the new bundling script’s handler candidate order contradicts the runtime hook selection order, and (2) the release check can throw if `src/hooks/bundled` isn’t present in the environment running the check. Both can cause unexpected behavior in real packaging/build scenarios.
- scripts/build-bundled-hooks.ts, scripts/release-check.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
87.2%
#11339: fix: resolve bundled hooks path on npm global install
by matthewpoe · 2026-02-07
84.3%
#3392: fix(hooks): remove debug console.log statements from session-memory...
by WinJayX · 2026-01-28
82.3%
#14746: fix(hooks): use globalThis for handler registry to survive bundler ...
by openperf · 2026-02-12
81.6%
#11169: fix(security): remove bundled soul-evil hook that enables silent ag...
by liuxiaopai-ai · 2026-02-07
80.1%
#16960: perf: skip cache-busting for bundled hooks, use mtime for workspace...
by mudrii · 2026-02-15
80.0%
#6405: feat(security): Add HTTP API security hooks for plugin scanning
by masterfung · 2026-02-01
79.1%
#14567: feat(hooks): add entire-checkpoints bundled hook for AI session tra...
by egorkaBurkenya · 2026-02-12
78.8%
#3973: fix: enhance npm package integrity checks and include critical files
by YeSuX · 2026-01-29
78.7%
#11153: refactor(hooks): replace console.warn/error with subsystem logger
by hclsys · 2026-02-07
78.0%