Skip to content

feat(hooks): Hook Event Handling - #9097

Merged
scidomino merged 8 commits into
google-gemini:mainfrom
Edilmo:edilmo/9096
Nov 24, 2025
Merged

feat(hooks): Hook Event Handling#9097
scidomino merged 8 commits into
google-gemini:mainfrom
Edilmo:edilmo/9096

Conversation

@Edilmo

@Edilmo Edilmo commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

TLDR

Creates HookEventHandler that coordinates the complete hook
execution pipeline via MessageBus, achieving complete decoupling of integration
points from hook system internals.
Part of full hook system implementation here

Dive Deeper

This is the central coordinator implementing a
MessageBus-mediated architecture. HookEventHandler subscribes to
HOOK_EXECUTION_REQUEST messages, enriches them with base fields (session_id,
cwd, timestamp), translates SDK types using HookTranslator, coordinates the
pipeline (planning → execution → aggregation → telemetry), and publishes full
HOOK_EXECUTION_RESPONSE messages. The MessageBus request() method provides
RPC-style communication with internal correlation ID management. The
createHookOutput() factory ensures proper type reconstruction from responses.
Integration points achieve complete decoupling - they only know about MessageBus
and pass event-specific data.

Reviewer Test Plan

  • Test all fire*Event methods work correctly
  • Verify SDK type translation happens transparently
  • Test MessageBus subscription and request handling
  • Validate hook output reconstruction via createHookOutput
  • Test sequential execution modifies input between hooks
  • Test parallel execution runs hooks concurrently
  • Verify telemetry is generated for all hook executions
  • Test MessageBus mock infrastructure in unit tests

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Closes #9096

@Edilmo
Edilmo requested a review from a team as a code owner September 22, 2025 13:46
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Edilmo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust and extensible hook system into the CLI. The core of this system is the HookEventHandler, which orchestrates the entire lifecycle of a hook, from identifying relevant hooks for a given event to executing them and consolidating their outcomes. This enables developers to inject custom logic at various predefined points within the CLI's operation, supporting both external command execution and JavaScript-based plugins, thereby enhancing the system's flexibility and customizability.

Highlights

  • New Hook Event Handling System: Introduced a comprehensive hook system with a central HookEventHandler to coordinate the complete hook execution pipeline, including planning, execution, aggregation, and telemetry.
  • Configurability: Added hooks configuration to the CLI's settings schema and core configuration, allowing users and extensions to define custom hooks for various events.
  • Modular Components: Developed dedicated components: HookPlanner for selecting and planning hook execution, HookRunner for executing command-line scripts or JavaScript plugins, and HookAggregator for merging results with event-specific strategies.
  • Type Translation: Implemented HookTranslator to convert SDK-specific types (like LLM requests/responses) into a stable, decoupled format for hooks and vice-versa, ensuring compatibility and stability for hook developers.
  • Telemetry Integration: Integrated telemetry for hook calls, providing observability into hook execution, including success/failure rates, durations, and event details.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive hook system, which is a significant and valuable addition. The architecture with a planner, runner, aggregator, and translator is well-structured. The code is generally of high quality with good test coverage for the new components.

I've identified a few high-severity issues that should be addressed:

  • A bug in telemetry logging that omits crucial hook input data.
  • A command parsing issue in the hook runner that will break hooks with quoted arguments.
  • Missing test coverage for the sequential hook execution logic.

Addressing these points will improve the observability, correctness, and robustness of the new hook system.

Comment thread packages/core/src/hooks/hookEventHandler.ts
Comment thread packages/core/src/hooks/hookRunner.ts Outdated
Comment thread packages/core/src/hooks/hookRunner.test.ts
@ghost ghost removed the status/need-issue label Oct 30, 2025
@Edilmo
Edilmo force-pushed the edilmo/9096 branch 5 times, most recently from ae91549 to 5fab2eb Compare November 10, 2025 22:57
@scidomino

Copy link
Copy Markdown
Collaborator

/gemini review

Comment thread packages/core/src/confirmation-bus/message-bus.ts Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a robust, message-bus-oriented hook event handling system, which is a great step towards decoupling integrations. The implementation is comprehensive, including planning, execution, aggregation, and telemetry for hooks. The new HookEventHandler and the request-response pattern on the MessageBus are well-designed. My review focuses on improving type safety in a few key areas to prevent potential runtime errors from malformed message payloads. I've identified some unsafe type assertions and duplicated logic that could be refactored for better robustness and maintainability.

Comment thread packages/core/src/confirmation-bus/message-bus.ts Outdated
Comment thread packages/core/src/hooks/hookEventHandler.ts
Comment thread packages/core/src/policy/policy-engine.ts
@scidomino
scidomino added this pull request to the merge queue Nov 24, 2025
Merged via the queue into google-gemini:main with commit 2034098 Nov 24, 2025
21 checks passed
kimjune01 added a commit to kimjune01/gemini-cli-claude that referenced this pull request Nov 24, 2025
Merge latest upstream changes from google-gemini/gemini-cli main branch.

## Merge Conflict Resolution

**File:** packages/core/src/services/chatCompressionService.ts

**Conflict:** Both branches modified the compression service API:
- main: Migrated to new model config system (getBaseLlmClient, modelConfigKey)
- feat/deliberate-compaction: Added goal-focused compression (userGoal parameter)

**Resolution:** Combined both changes:
- Used new model config API from main (getBaseLlmClient, modelStringToModelConfigAlias, abortSignal)
- Preserved goal-focused enhancement (getChatCompressionPrompt(userGoal))
- Result: New API + goal awareness working together

**Additional Changes:**
- Updated chatCompressionService.test.ts to use new BaseLlmClient API
- Changed all test mocks from getContentGenerator to getBaseLlmClient
- Added BaseLlmClient import and proper type casts
- Fixed linting: changed messagesPreserved/messagesCompressed to const
- Build passes successfully

## Upstream Changes Merged

From google-gemini/gemini-cli main (95693e2..d14779b):
- feat(core): Land bool for alternate system prompt (google-gemini#13764)
- feat(hooks): Hook Agent Lifecycle Integration (google-gemini#9105)
- feat(hooks): Hook Event Handling (google-gemini#9097)
- fix: Minor improvements to configs and getPackageJson (google-gemini#12510)
- feat(hooks): Hook Telemetry Infrastructure (google-gemini#9082)
- feat(core): Migrate chatCompressionService to model configs (google-gemini#12863)
- Add session subtask in /stats command (google-gemini#13750)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
mboshernitsan pushed a commit that referenced this pull request Nov 25, 2025
thacio added a commit to thacio/auditaria that referenced this pull request Nov 26, 2025
danpalmer pushed a commit to danpalmer/gemini-cli that referenced this pull request Nov 29, 2025
cocosheng-g pushed a commit that referenced this pull request May 6, 2026
@sripasg sripasg added the size/xl An extra large PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/xl An extra large PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook Event Handling

4 participants