Skip to content

Conversation

@SiegristJ
Copy link

This PR enables extensions to utilize the existing Hook System by exposing the hooks configuration field in ExtensionConfig and passing it through the ExtensionManager.

Context
The HookRegistry (in core/src/hooks/hookRegistry.ts) already contains logic to load hooks from extensions:

1 // Existing logic in HookRegistry.ts
2 const extensions = this.config.getExtensions() || [];
3 for (const extension of extensions) {
4 if (extension.isActive && extension.hooks) {
5 // logic to register hooks
6 }
7 }

However, extensions were unable to actually use this feature because:

  1. The ExtensionConfig interface (in cli/src/config/extension.ts) was missing the hooks definition.
  2. The ExtensionManager (in cli/src/config/extension-manager.ts) was not passing the hooks field from the loaded JSON to the runtime extension object.

Changes

  • packages/cli/src/config/extension.ts: Added optional hooks field to ExtensionConfig interface, importing HookDefinition and HookEventName from core.
  • packages/cli/src/config/extension-manager.ts: Updated loadExtension to assign hooks: config.hooks when initializing the extension object.

Impact
This change transforms extensions from static tool providers into capable agent interceptors. It unblocks critical enterprise use cases such as:

  • Custom Memory Systems: Capturing AfterAgent events to store history and BeforeModel events to inject context (e.g., RAG, Episodic Memory).
  • Safety & Compliance: Implementing PII scrubbing or policy checks via BeforeModel or BeforeTool hooks.
  • Audit Logging: Recording comprehensive session activity to external systems.

Verification
Verified locally by building the CLI and loading a test extension with BeforeModel and AfterAgent hooks. Confirmed that the HookRegistry correctly identified and registered the hooks from the extension's
gemini-extension.json

@SiegristJ SiegristJ requested a review from a team as a code owner November 27, 2025 02:51
@google-cla
Copy link

google-cla bot commented Nov 27, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SiegristJ, 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 significantly enhances the capabilities of extensions by integrating them with the core Hook System. It addresses previous limitations where extensions could not leverage hooks due to missing configuration definitions and data passing mechanisms. By modifying the ExtensionConfig interface and the ExtensionManager, extensions can now define and register custom hooks, enabling them to intercept and influence various application events, thereby unlocking advanced functionalities for enterprise use cases.

Highlights

  • Hook System Integration: Extensions can now utilize the existing Hook System by exposing the hooks configuration field in ExtensionConfig.
  • Configuration Update: The ExtensionConfig interface has been updated to include an optional hooks definition, importing necessary types from the core library.
  • Extension Manager Enhancement: The ExtensionManager is now updated to correctly pass the hooks field from the loaded JSON configuration to the runtime extension object.
  • Enabling Advanced Use Cases: This change unblocks critical enterprise use cases such as custom memory systems, safety and compliance features, and comprehensive audit logging through extension-defined hooks.
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
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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.

Copy link
Contributor

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

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 successfully exposes the hook system to extensions by adding the hooks configuration field. The changes are straightforward. However, I've identified a critical security concern: the installation consent flow does not inform the user that an extension can execute arbitrary commands via hooks. My review includes a comment with details on how to address this to ensure users are aware of the capabilities they are granting to an extension.

contextFileName?: string | string[];
excludeTools?: string[];
settings?: ExtensionSetting[];
hooks?: { [K in HookEventName]?: HookDefinition[] };
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The introduction of hooks allows extensions to execute arbitrary commands on the user's machine (via HookType.Command), which is a significant security-sensitive capability. The user should be explicitly informed about this during the installation consent flow.

Currently, the extensionConsentString function in packages/cli/src/config/extensions/consent.ts does not account for the hooks property. Please update the consent mechanism to inform the user if an extension uses hooks, for example by listing which events it hooks into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant