-
-
Notifications
You must be signed in to change notification settings - Fork 317
feat!: replace environment variables with statusline CLI options for context thresholds #578
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
Conversation
…context thresholds BREAKING CHANGE: Environment variables `CCUSAGE_CONTEXT_LOW_THRESHOLD` and `CCUSAGE_CONTEXT_MEDIUM_THRESHOLD` are no longer supported. Use CLI options `--context-low-threshold` and `--context-medium-threshold` instead. - Add `--context-low-threshold` and `--context-medium-threshold` options to statusline command - Implement zod validation for threshold values (0-100 range, integer, LOW < MEDIUM constraint) - Remove `getContextUsageThresholds()` function and related environment variable constants - Update documentation to reflect CLI option usage and configuration file support - Remove environment variable tests and validation logic - Update JSON schema to include new statusline options - Maintain backward compatibility through default values (50/80) Migration guide: - Old: `export CCUSAGE_CONTEXT_LOW_THRESHOLD=60` - New: `--context-low-threshold 60` - Configuration files also supported for persistent settings
|
Caution Review failedThe pull request is closed. WalkthroughIntroduces CLI/configurable context usage thresholds for the statusline command; removes environment-variable-based thresholds and related data-loader utility; updates schema and docs to reflect new configuration paths; adds Zod validation and new args in statusline; deletes env constants. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant CLI as statusline (CLI)
participant Z as Zod Parser
participant C as statuslineCommand
participant R as Renderer
U->>CLI: Run statusline --context-low-threshold --context-medium-threshold
CLI->>Z: Parse & validate thresholds (0–100, LOW < MEDIUM)
Z-->>CLI: Valid thresholds or error
alt thresholds invalid
CLI-->>U: Error: invalid threshold configuration
else thresholds valid
CLI->>C: Execute with thresholds
C->>R: Format context usage with provided thresholds
R-->>U: Statusline output (color-coded)
end
sequenceDiagram
rect rgb(245,248,255)
note over U,Env: Previous flow (removed)
participant U as User
participant Env as Environment
participant DL as DataLoader.getContextUsageThresholds
participant C as statuslineCommand
U->>C: Run statusline
C->>DL: Read thresholds
DL->>Env: Read env vars
Env-->>DL: Values/undefined
DL-->>C: Thresholds (clamped/ordered)
C-->>U: Statusline output
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (5)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Summary of Changes
Hello @ryoppippi, 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 introduces a breaking change by migrating the configuration of context usage color thresholds for the statusline command from environment variables to dedicated command-line interface (CLI) options. This enhances usability and aligns with modern CLI practices, while maintaining configuration file support.
Highlights
- CLI Option Integration: Replaced CCUSAGE_CONTEXT_LOW_THRESHOLD and CCUSAGE_CONTEXT_MEDIUM_THRESHOLD environment variables with new --context-low-threshold and --context-medium-threshold CLI options for the statusline command.
- Robust Validation: Implemented comprehensive Zod validation for the new CLI options, ensuring values are integers within the 0-100 range and enforcing the constraint that the low threshold must be less than the medium threshold.
- Codebase Refinement: Removed obsolete environment variable constants and the getContextUsageThresholds() utility function, simplifying the codebase.
- Documentation & Schema Updates: Updated the config-schema.json to include the new options and revised the docs/guide/statusline.md to reflect the new CLI-first configuration approach with usage examples.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
commit: |
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 is a great improvement, replacing environment variables with more discoverable CLI options for context thresholds. The use of Zod for validation is also a good addition. My review focuses on a couple of issues related to how these new options interact with configuration files. Specifically, the validation logic seems to be misplaced, and the options from config files are not being used. I've also pointed out a minor inconsistency in the JSON schema. Addressing these points will make the new feature more robust.
| // Validate threshold ordering constraint: LOW must be less than MEDIUM | ||
| if (ctx.values.contextLowThreshold >= ctx.values.contextMediumThreshold) { | ||
| throw new Error(`Context low threshold (${ctx.values.contextLowThreshold}) must be less than medium threshold (${ctx.values.contextMediumThreshold})`); | ||
| } |
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.
There are a couple of related issues with how the new context threshold options are handled with respect to configuration files.
-
Misplaced Validation: This validation block runs on
ctx.valuesbefore options from a configuration file are loaded and merged. This means any thresholds set in a config file will bypass this validation, potentially allowing an invalid state (e.g.,low_threshold >= medium_threshold). -
Ignoring Config Values: Later in the code (lines 421-425),
ctx.valuesis used again to get the thresholds. This means any values for these options set in a configuration file will be completely ignored, as they are loaded intomergedOptionsbut never used.
To fix this, the validation should be moved to after mergeConfigWithArgs, and the final merged options should be used for both validation and for determining the color logic. Also, since values from a config file might be strings, they should be coerced to numbers before comparison.
| "contextLowThreshold": { | ||
| "type": "string", | ||
| "description": "Context usage percentage below which status is shown in green (0-100)", | ||
| "markdownDescription": "Context usage percentage below which status is shown in green (0-100)", | ||
| "default": 50 | ||
| }, | ||
| "contextMediumThreshold": { | ||
| "type": "string", | ||
| "description": "Context usage percentage below which status is shown in yellow (0-100)", | ||
| "markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)", | ||
| "default": 80 | ||
| }, |
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 type for contextLowThreshold and contextMediumThreshold is set to "string", but their default values are numbers. This is inconsistent with other numeric options in the schema (like refreshInterval) and can be confusing for users editing the config file. It's better to define the type as "number" to ensure consistency and correct type handling by editors and validators.
| "contextLowThreshold": { | |
| "type": "string", | |
| "description": "Context usage percentage below which status is shown in green (0-100)", | |
| "markdownDescription": "Context usage percentage below which status is shown in green (0-100)", | |
| "default": 50 | |
| }, | |
| "contextMediumThreshold": { | |
| "type": "string", | |
| "description": "Context usage percentage below which status is shown in yellow (0-100)", | |
| "markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)", | |
| "default": 80 | |
| }, | |
| "contextLowThreshold": { | |
| "type": "number", | |
| "description": "Context usage percentage below which status is shown in green (0-100)", | |
| "markdownDescription": "Context usage percentage below which status is shown in green (0-100)", | |
| "default": 50 | |
| }, | |
| "contextMediumThreshold": { | |
| "type": "number", | |
| "description": "Context usage percentage below which status is shown in yellow (0-100)", | |
| "markdownDescription": "Context usage percentage below which status is shown in yellow (0-100)", | |
| "default": 80 | |
| }, |
Summary
This PR replaces environment variables with CLI options for configuring context usage color thresholds in the statusline command. This is a breaking change that improves usability and aligns with modern CLI patterns.
Breaking Changes
CCUSAGE_CONTEXT_LOW_THRESHOLDandCCUSAGE_CONTEXT_MEDIUM_THRESHOLDare no longer supported--context-low-thresholdand--context-medium-thresholdChanges Made
--context-low-thresholdand--context-medium-thresholdoptions to statusline commandgetContextUsageThresholds()function and related environment variable constantsMigration Guide
Old (Environment Variables):
New (CLI Options):
Configuration File (Persistent Settings):
See the Configuration Guide for details on setting these options in config files.
Validation Improvements
Test Plan
The change maintains all existing functionality while providing a cleaner, more discoverable interface through CLI options instead of environment variables.
Summary by CodeRabbit