Skip to content

Comments

feat(policy): repurpose "Always Allow" persistence to workspace level#19707

Merged
Abhijit-2592 merged 2 commits intomainfrom
abhijit-2592/feature/repurpose-allow-for-all-session-to-workspace
Feb 20, 2026
Merged

feat(policy): repurpose "Always Allow" persistence to workspace level#19707
Abhijit-2592 merged 2 commits intomainfrom
abhijit-2592/feature/repurpose-allow-for-all-session-to-workspace

Conversation

@Abhijit-2592
Copy link
Contributor

Summary

Repurposes the "Allow for all future sessions" (policy persistence) functionality from the user level to the workspace level. This ensures that tool and MCP server permissions granted by the user are scoped to the specific project/workspace rather than being applied globally.

Details

  • Scoping: Updated createPolicyUpdater in packages/core/src/policy/config.ts to accept a Storage instance and use storage.getWorkspacePoliciesDir() for persisting rules to .gemini/policies/auto-saved.toml.
  • Priority Tier: Moved dynamic "Always Allow" rules from the User Tier (3.95) to the Workspace Tier (2.95) using a new ALWAYS_ALLOW_PRIORITY constant.
  • Refactoring: Introduced static constants for all policy priority levels to eliminate hardcoded numbers and improved comment clarity.
  • Integration: Updated CLI orchestration in gemini.tsx and the policy wrapper in packages/cli/src/config/policy.ts to pass the Storage instance correctly.

Related Issues

Fixes #19704

How to Validate

  1. Run Gemini CLI in a project directory.
  2. Trigger a tool that requires confirmation.
  3. Select "Allow for all future sessions".
  4. Verify that .gemini/policies/auto-saved.toml is created in the current directory.
  5. Verify that the rule is NOT applied when running Gemini CLI in a different directory.
  6. Run core tests: npm test -w @google/gemini-cli-core -- src/policy/policy-updater.test.ts src/policy/persistence.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt

@Abhijit-2592 Abhijit-2592 requested a review from a team as a code owner February 20, 2026 20:21
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Abhijit-2592, 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 refines how tool and MCP server permissions are managed by shifting the 'Always Allow' persistence mechanism from a global user setting to a project-specific workspace setting. This change enhances security and project isolation by ensuring that granted permissions are relevant only to the active workspace, preventing unintended global effects. The implementation involves updating policy configuration, introducing new priority constants, and adjusting the policy updater to leverage workspace-level storage.

Highlights

  • Policy Persistence Scoping: The 'Always Allow' policy persistence functionality has been repurposed from a global user level to a workspace-specific level, ensuring permissions are scoped to the current project.
  • Priority Tier Adjustment: Dynamic 'Always Allow' rules have been moved from the User Tier (3.95) to the Workspace Tier (2.95) using a new ALWAYS_ALLOW_PRIORITY constant, reflecting their new workspace scope.
  • Policy Updater Refactoring: The createPolicyUpdater function now accepts a Storage instance, allowing it to use storage.getWorkspacePoliciesDir() for persisting rules to .gemini/policies/auto-saved.toml within the project directory.
  • Static Priority Constants: Hardcoded policy priority numbers have been replaced with static constants (e.g., MCP_EXCLUDED_PRIORITY, ALLOWED_TOOLS_FLAG_PRIORITY), improving code readability and maintainability.
  • CLI Integration Updates: The CLI orchestration and policy wrapper have been updated to correctly pass the Storage instance to the createPolicyUpdater function.
Changelog
  • packages/cli/src/config/policy.ts
    • Updated createPolicyUpdater to accept a Storage instance as a new parameter.
  • packages/cli/src/gemini.tsx
    • Modified the call to createPolicyUpdater to pass the config.storage instance.
  • packages/core/src/policy/config.ts
    • Added new constants for specific policy priority offsets, including ALWAYS_ALLOW_PRIORITY.
    • Updated comments to reflect the new mixed-tier approach for settings-based and dynamic rules.
    • Replaced hardcoded priority values (e.g., 3.9, 3.4, 3.3, 3.2, 3.1, 3.95) with their corresponding new static constants.
    • Modified the createPolicyUpdater function signature to accept a Storage instance.
    • Changed the policy persistence directory from Storage.getUserPoliciesDir() to storage.getWorkspacePoliciesDir().
    • Updated the priority for 'Always Allow' rules from 3.95 to ALWAYS_ALLOW_PRIORITY (Workspace Tier).
  • packages/core/src/policy/persistence.test.ts
    • Imported the ALWAYS_ALLOW_PRIORITY constant.
    • Added a mockStorage instance to the test setup.
    • Updated calls to createPolicyUpdater to include the mockStorage instance.
    • Replaced Storage.getUserPoliciesDir with mockStorage.getWorkspacePoliciesDir in tests.
    • Adjusted assertions to expect ALWAYS_ALLOW_PRIORITY instead of the hardcoded 3.95.
  • packages/core/src/policy/policy-updater.test.ts
    • Imported the ALWAYS_ALLOW_PRIORITY constant.
    • Added a mockStorage instance to the test setup.
    • Updated calls to createPolicyUpdater to include the mockStorage instance.
    • Replaced Storage.getUserPoliciesDir with mockStorage.getWorkspacePoliciesDir in tests.
    • Added assertions for ALWAYS_ALLOW_PRIORITY to the addRule expectations.
Activity
  • The author provided a detailed summary of changes, including scoping, priority tier adjustments, refactoring, and integration updates.
  • Validation steps were outlined to verify the new workspace-level policy persistence.
  • The pre-merge checklist indicates that tests have been added/updated and validated on MacOS.
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.

@github-actions
Copy link

github-actions bot commented Feb 20, 2026

Size Change: +909 B (0%)

Total Size: 25.2 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +909 B (0%)
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

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 effectively repurposes the "Always Allow" policy persistence from the user level to the workspace level, significantly enhancing security and project-specific configuration. No high or critical security vulnerabilities were found. The implementation is robust, correctly modifying createPolicyUpdater to use a Storage instance for workspace-scoped persistence and appropriately moving dynamic rule priority to the workspace tier. The refactoring of hardcoded priority values into named constants improves readability and maintainability. The changes also ensure proper TOML serialization, maintain a clear priority hierarchy, and include thorough test updates, making this a solid contribution to the policy engine's design.

@gemini-cli gemini-cli bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 20, 2026
Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/feature/repurpose-allow-for-all-session-to-workspace branch 3 times, most recently from 5e8f295 to 738478b Compare February 20, 2026 21:18
@Abhijit-2592 Abhijit-2592 added this pull request to the merge queue Feb 20, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 20, 2026
Repurposes the "Allow for all future sessions" (policy persistence) functionality
from the user level to the workspace level. This ensures that tool and MCP server
permissions granted by the user are scoped to the specific project/workspace
rather than being applied globally.

Key changes:
- Updated `createPolicyUpdater` to accept a `Storage` instance and use the
  workspace policies directory for TOML persistence.
- Moved dynamic "Always Allow" rules from the User Tier (3.95) to the
  Workspace Tier (2.95) using a new `ALWAYS_ALLOW_PRIORITY` constant.
- Introduced static constants for all policy priority levels in
  `packages/core/src/policy/config.ts` to eliminate hardcoded numbers.
- Consistently used constant names in documentation and introduced
  `AUTO_SAVED_POLICY_FILENAME` for the policy filename.
- Updated CLI orchestration to pass the `Storage` instance to the policy updater.
- Updated core unit tests to verify workspace-level persistence and priority logic.

Fixes #19704
…documentation

- Moved `AUTO_SAVED_POLICY_FILENAME` and added `getAutoSavedPolicyPath()` to the `Storage` class.
- Relocated priority calculation logic explanation to the constant definition in `config.ts`.
- Removed obsolete priority comments from tool confirmation logic.
@Abhijit-2592 Abhijit-2592 force-pushed the abhijit-2592/feature/repurpose-allow-for-all-session-to-workspace branch from 738478b to fd1cadc Compare February 20, 2026 21:41
@Abhijit-2592 Abhijit-2592 added this pull request to the merge queue Feb 20, 2026
Merged via the queue into main with commit c5baf39 Feb 20, 2026
27 checks passed
@Abhijit-2592 Abhijit-2592 deleted the abhijit-2592/feature/repurpose-allow-for-all-session-to-workspace branch February 20, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/enterprise Issues related to Telemetry, Policy, Quota / Licensing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repurpose Always Allow policy persistence to Workspace level

2 participants