Skip to content

Conversation

@piexian
Copy link

@piexian piexian commented Jan 5, 2026

This pull request introduces persistent storage for usage statistics in the service. It adds logic to save and load usage data to a file, ensuring statistics are retained across restarts. The changes include new functions for persistence, integration of these functions into the service lifecycle, and necessary dependency updates.

Usage statistics persistence:

  • Added SetPersistPath, LoadStatistics, and SaveStatistics functions to handle saving and loading usage statistics to a JSON file (usage_stats.json). These functions use the configured path and provide error handling and logging. (internal/usage/logger_plugin.go)
  • Updated imports and initialization in sdk/cliproxy/service.go to set the persistence path and load statistics on service start, and to save statistics on shutdown. (sdk/cliproxy/service.go) [1] [2] [3]
  • Added dependencies on encoding/json, os, path/filepath, and logrus for file operations and logging. (internal/usage/logger_plugin.go)

Copilot AI review requested due to automatic review settings January 5, 2026 19:43
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @piexian, 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 crucial feature for the service: the ability to persist usage statistics. By implementing functions to save and load these statistics to a JSON file, the service can now retain valuable usage data across restarts, providing a more complete and continuous record of activity.

Highlights

  • Usage Statistics Persistence Functions: New functions SetPersistPath, LoadStatistics, and SaveStatistics were added to internal/usage/logger_plugin.go to manage saving and loading usage statistics to/from a usage_stats.json file.
  • Service Lifecycle Integration: The sdk/cliproxy/service.go file was updated to call SetPersistPath and LoadStatistics on service startup, and SaveStatistics on service shutdown, ensuring statistics are loaded and saved automatically.
  • Dependency Updates: Necessary Go standard library packages (encoding/json, os, path/filepath) and logrus were imported in internal/usage/logger_plugin.go to support file operations and logging.

🧠 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 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 👍 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

  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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 adds persistence for usage statistics, which is a great enhancement for retaining data across service restarts. The implementation correctly integrates with the service lifecycle. My review includes two main suggestions for the internal/usage/logger_plugin.go file to improve the robustness and maintainability of the new persistence logic. First, I recommend making the file save operation atomic to prevent data corruption in case of an unexpected shutdown. Second, I suggest replacing a magic string for the filename with a constant to improve code clarity.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds persistent storage for usage statistics to ensure data is retained across service restarts. The implementation saves statistics to a JSON file in the same directory as the config file.

  • Added persistence functions (SetPersistPath, LoadStatistics, SaveStatistics) to save and load usage statistics
  • Integrated persistence into the service lifecycle by loading statistics on startup and saving on shutdown
  • Changed the internal/usage package import from blank to named to enable calling the new persistence functions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
sdk/cliproxy/service.go Changed internal/usage import to named import and added calls to initialize persist path, load statistics on startup, and save statistics during shutdown
internal/usage/logger_plugin.go Added persistence-related imports (encoding/json, os, path/filepath, logrus) and implemented three new functions for managing statistics persistence to/from a JSON file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

HsnSaboor added a commit to HsnSaboor/CLIProxyAPI that referenced this pull request Jan 6, 2026
…auto-update, request timeout, multi-candidate, auth persistence

Applied features from upstream PRs:
- PR router-for-me#878: Usage statistics persistence (SetPersistPath, LoadStatistics, SaveStatistics)
- PR router-for-me#877: Codex plan type credential filename handling
- PR router-for-me#868: Claude request cloaking utilities (obfuscation, fake user IDs)
- PR router-for-me#715: Auto-update command for self-updating binary
- PR router-for-me#860: Configurable request timeout with RequestTimeout config
- PR router-for-me#879: Gemini multi-candidate support (n param -> candidateCount)
- PR router-for-me#869: Auth token persistence for non-Google OAuth providers

Fixed build issues:
- Added applyPayloadConfig wrapper function
- Added originalTranslated computation in claude/antigravity/codex executors
- Fixed model registry hook methods
- Removed duplicate SanitizeFunctionName
- Fixed gemini_schema placeholder logic for nested object properties

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@hkfires
Copy link
Collaborator

hkfires commented Jan 6, 2026

Sorry, we did not accept any pr about persist usage statistics

@hkfires hkfires closed this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants