feat(hooks): Hook Session Lifecycle & Compression Integration
Summary
- Adds SessionStart and SessionEnd hook integration with matcher support for different session triggers (startup, resume, clear, compress, exit, logout, prompt_input_exit).
- Adds PreCompress hook integration with matcher support for manual vs automatic compression triggers, allowing hooks to respond appropriately to different compression scenarios.
- Address issues found in #14099 about some hook-system integration tests not work on Windows
Details
This implements session lifecycle hooks with sophisticated matching based on the session trigger source. SessionStart hooks can respond differently to app startup vs chat resume vs clear commands. SessionEnd hooks can handle different termination reasons like graceful exit vs logout vs prompt abandonment. The matching logic allows fine-grained control over when session hooks execute, enabling specialized behavior for different session scenarios. This also implements PreCompress hooks that can respond differently to manual compression (user runs /compress) vs automatic compression (context threshold reached). Hooks can log compression events, ask for user confirmation, or modify compression behavior. The matcher logic distinguishes between manual and auto triggers, enabling different hook behavior for different compression scenarios.
Related Issues
Closes #9138 Closes #9139
How to Validate
- Test SessionStart hooks with different matchers (startup, resume, clear, compress)
- Test SessionEnd hooks with different matchers (exit, clear, logout, prompt_input_exit)
- Verify matcher logic correctly filters hooks based on session trigger
- Test session hook execution adds appropriate context
- Validate session hooks work with different CLI usage patterns
- Test PreCompress hooks with manual trigger (/compress command)
- Test PreCompress hooks with auto trigger (context threshold)
- Verify matcher logic correctly filters based on compression trigger
- Test hook integration with compression workflow
- Validate hooks can influence or log compression events appropriately
Pre-Merge Checklist
- [ ] Updated relevant documentation and README (if needed)
- [x] Added/updated tests (if needed)
- [ ] Noted breaking changes (if any)
- [ ] Validated on required platforms/methods:
- [x] MacOS
- [x] npm run
- [x] npx
- [ ] Docker
- [ ] Podman
- [ ] Seatbelt
- [ ] Windows
- [ ] npm run
- [ ] npx
- [ ] Docker
- [ ] Linux
- [ ] npm run
- [ ] npx
- [ ] Docker
- [x] MacOS
Summary of Changes
Hello @Edilmo, I'm Gemini Code Assist[^1]! 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 extensibility of the application by integrating new lifecycle hooks for user sessions and content compression. The primary goal is to provide developers with more granular control over these critical events, allowing for custom logic to be executed at specific points, such as application startup, session termination, or before content compression. This improves the system's adaptability to diverse operational scenarios and custom requirements.
Highlights
- Session Lifecycle Hooks: Introduced
SessionStartandSessionEndhooks with comprehensive matcher support.SessionStarthooks can differentiate between app startup, chat resume, or clear commands, whileSessionEndhooks can respond to various termination reasons like graceful exit, logout, or prompt abandonment. This allows for fine-grained control over session-related behaviors. - Compression Integration Hooks: Added
PreCompresshooks that can distinguish between manual compression (e.g., user command) and automatic compression (e.g., context threshold reached). This enables hooks to react differently based on the compression trigger, allowing for custom logging, user confirmation, or modification of compression behavior. - New Hook Trigger Functions: New utility functions (
fireSessionStartHook,fireSessionEndHook,firePreCompressHook) have been added topackages/core/src/core/sessionHookTriggers.tsto facilitate the firing of these new session and compression related hooks through the MessageBus.
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 :thumbsup: and :thumbsdown: 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.
[^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.