-
Notifications
You must be signed in to change notification settings - Fork 9.7k
feat: expose existing hook registry capabilities to extensions #13880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
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. |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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[] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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:
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:
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