-
Notifications
You must be signed in to change notification settings - Fork 10.4k
feat(cli): Add Interactive Hooks Configuration Wizard #15573
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?
feat(cli): Add Interactive Hooks Configuration Wizard #15573
Conversation
Summary of ChangesHello @AbdulTawabJuly, 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 user experience for configuring hooks in the Gemini CLI by introducing an interactive wizard. This new feature allows users to easily define and add hooks through a guided, step-by-step process directly within the command line, eliminating the previous requirement of manually editing JSON configuration files. The wizard ensures proper configuration through built-in validation and provides a clear summary before saving. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 introduces an interactive wizard for configuring hooks, which is a great usability improvement. The implementation is well-structured, using Ink for the UI and breaking down the wizard into logical components and steps. My review focuses on a few areas to improve correctness and user experience: ensuring proper user feedback in the standalone CLI command, correcting the configuration update logic to avoid duplicate entries, and fixing a minor UI inconsistency in the wizard's step numbering. Addressing these points will make the new feature more robust and polished.
| const newHookDef: HookDefinition = { | ||
| matcher: state.matcher || undefined, | ||
| hooks: [ | ||
| { | ||
| type: HookType.Command, | ||
| command: state.command, | ||
| name: state.name || undefined, | ||
| description: state.description || undefined, | ||
| timeout: state.timeout || undefined, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const hooksConfig = | ||
| (settings.merged.hooks as Record<string, unknown>) || {}; | ||
| const existingHooks = | ||
| (hooksConfig[state.event] as HookDefinition[]) || []; | ||
|
|
||
| const updatedHooks = [...existingHooks, newHookDef]; | ||
|
|
||
| settings.setValue( | ||
| SettingScope.Workspace, | ||
| `hooks.${state.event}`, | ||
| updatedHooks, | ||
| ); |
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 current implementation always creates a new HookDefinition object, even if one with the same matcher already exists for the given event. This leads to duplicate entries in the settings.json file, making it bloated and harder to manage. The logic should be updated to find an existing HookDefinition for the same matcher and add the new hook to its hooks array. A new HookDefinition should only be created if no matching one is found.
You will also need to import HookConfig from @google/gemini-cli-core.
const hooksConfig =
(settings.merged.hooks as Record<string, HookDefinition[]>) || {};
const existingHookDefs = hooksConfig[state.event]?.slice() || [];
const newHook: HookConfig = {
type: HookType.Command,
command: state.command!,
name: state.name || undefined,
description: state.description || undefined,
timeout: state.timeout || undefined,
};
// Use empty string for wildcard matcher for consistent comparison.
const matcher = state.matcher || '';
const existingDefIndex = existingHookDefs.findIndex(
(def) => (def.matcher || '') === matcher,
);
if (existingDefIndex > -1) {
// Add to existing hook definition.
const existingDef = existingHookDefs[existingDefIndex];
existingDef.hooks.push(newHook);
} else {
// Create a new hook definition.
const newHookDef: HookDefinition = {
matcher: state.matcher || undefined,
hooks: [newHook],
};
existingHookDefs.push(newHookDef);
}
settings.setValue(
SettingScope.Workspace,
`hooks.${state.event}`,
existingHookDefs,
);
Summary
This PR implements an interactive GUI wizard for configuring hooks, replacing the need for manual JSON editing. Users can now add hooks through a guided multi-step interface accessible via
/hooks add.Changes
addsubcommand to/hookscommand that launches the wizardImplementation Details
The wizard uses Ink components and follows the existing CLI UI patterns. State management is handled via React hooks, with validation performed at each step. The wizard saves hooks directly to
.gemini/settings.jsonusing the existing settings API.Related Issues
Fixes 15268
How to Validate
/hooks add=> Then just follow the steps shown on the UIPre-Merge Checklist