feat(core): implement additionalContext for BeforeModel hooks and aggregate context from multiple hooks#23957
feat(core): implement additionalContext for BeforeModel hooks and aggregate context from multiple hooks#23957
Conversation
…regate context from multiple hooks
|
Hi @mbleigh, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this. We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines. Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed. Thank you for your understanding and for being a part of our community! |
|
Size Change: +2.78 kB (+0.01%) Total Size: 34 MB
ℹ️ View Unchanged
|
Summary of ChangesHello, 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 enhances the hook system by standardizing how additional context is provided to LLM requests. By moving context injection into 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces the additionalContext field for BeforeModel hooks, enabling hooks to append text to user messages wrapped in <hook_context> tags. The implementation includes logic to aggregate context from multiple hooks and updates the BeforeModelHookOutput to handle the injection into the LLM request. Feedback suggests refactoring the content normalization logic in packages/core/src/hooks/types.ts to improve type safety by removing unnecessary type assertions.
… blocks for better provenance
526d1e5 to
cda12a4
Compare
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383). We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'. This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community! |
Summary
This PR implements the
additionalContextfield forBeforeModelhooks and ensures that additional context is properly aggregated when multiple hooks are executed. It also transitions theBeforeAgenthook's context handling to use the more robustBeforeModelinfrastructure, removing legacy manual prompt concatenation.Details
HookAggregatorto collectadditionalContextfrom all executed hooks (regardless of event type) and join them with newlines.BeforeModelHookOutput.applyLLMRequestModificationsto parsecontentsand append the aggregated context (wrapped in<hook_context>tags) to the last user message, or create a new one if necessary.BeforeAgentcontext injection fromHookRunner, relying instead on the standard aggregation and application flow.packages/core/src/hooks/types.tsand its tests related to unsafe type assertions andanyusage.docs/hooks/reference.mdto document the newadditionalContextbehavior forBeforeModelhooks.Related Issues
Related to #24682 (Internal tracking for hook system enhancements)
How to Validate
npm test -w @google/gemini-cli-core -- src/hooks/hookAggregator.test.ts src/hooks/hookRunner.test.ts src/hooks/types.test.tsadditionalContextfrom aBeforeModelhook appears in the model's transcript (wrapped in tags).Pre-Merge Checklist