← Back to PRs

#9914: fix(hooks): resolve bundled hook dist paths and packaging checks

by zimmra open 2026-02-05 21:39 View on GitHub →
scripts stale
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