feat(policy): add --policy flag for user defined policies#18500
feat(policy): add --policy flag for user defined policies#18500allenhutchison merged 19 commits intomainfrom
Conversation
Summary of ChangesHello @allenhutchison, 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 policy management capabilities of the Gemini CLI by introducing a Highlights
Changelog
Activity
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.
Code Review
This pull request introduces a valuable --policy flag, allowing users to specify custom policy files and directories. The implementation is well-structured, with updates to argument parsing, settings schemas, and the core policy loading logic. The ability to handle both individual files and directories in the toml-loader is a great enhancement.
I've found one critical issue in packages/core/src/policy/toml-loader.ts related to an uninitialized variable that could lead to a crash, along with an inconsistency in file handling. My review comment provides a detailed explanation and a suggested fix.
Once that is addressed, this will be a solid feature addition to the CLI.
|
Size Change: +1.84 kB (+0.01%) Total Size: 24.4 MB
ℹ️ View Unchanged
|
…i/gemini-cli into adh/feature/add-policy-flag
…config.test.ts`.
….toml` extension when loading single files.
…y-flag # Conflicts: # packages/cli/src/config/config.test.ts
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a --policy flag, allowing users to specify custom policy files, which is a great enhancement for flexibility and session-specific configurations. The implementation is well-structured, covering CLI argument parsing, core logic updates in the policy engine, testing, and documentation.
I've found one high-severity issue related to handling empty paths from the --policy flag, which could lead to unexpected policy priority changes. A code suggestion is provided to address this edge case.
Overall, this is a solid contribution that significantly improves the policy engine's usability.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Abhijit-2592
left a comment
There was a problem hiding this comment.
The changes LGTM overall. I think in terms of security this is better than implementing project level policy approval as the user has explicit control here.
Kindly fix the failing CI tests
This fixes a test failure where loadPoliciesFromToml was failing silently because fs.stat was not mocked for the custom policy directory path, causing readdir to be skipped.
|
@Abhijit-2592 fixed the failing test. Thanks for the review. |
Abhijit-2592
left a comment
There was a problem hiding this comment.
LGTM & Approved with a single comment about duplicate logic. Missed this in the last review
…yDirectories Address PR review comment by refactoring createPolicyEngineConfig() to use getPolicyDirectories() instead of manually building the policy directory list. Updated getPolicyDirectories() to accept an optional policyPaths parameter to support the --policy flag.
Summary
Add a
--policyflag to the Gemini CLI to allow users to specify additional policy files or directories. These user-provided policies replace the standard user policy directory (~/.gemini/policies), giving users full control over the policy engine's rules for a specific session or setup.Details
--policyflag to CLI arguments.PolicySettingsand settings schema to includepolicyPaths.loadPoliciesFromTomlto support individual file paths in addition to directories.createPolicyEngineConfigto prioritizepolicyPathsand exclude the default user policy directory when they are present.createNonInteractiveUIto outputinfo,warning, anderrormessages to the console, enabling/policies listto work in headless mode.Related Issues
Closes #11301
How to Validate
ls-deny.toml:npm start -- --policy ls-deny.toml --prompt "/policies list".ls-deny.tomlis listed under user policies and standard policies from~/.gemini/policiesare NOT present.Pre-Merge Checklist