Skip to content

refactor(core): replace manual syncPlanModeTools with declarative policy rules#20596

Merged
jerop merged 3 commits intomainfrom
refactor/policy-based-plan-tools
Mar 2, 2026
Merged

refactor(core): replace manual syncPlanModeTools with declarative policy rules#20596
jerop merged 3 commits intomainfrom
refactor/policy-based-plan-tools

Conversation

@jerop
Copy link
Copy Markdown
Contributor

@jerop jerop commented Feb 27, 2026

Unified plan-related tool visibility management by leveraging the existing Policy Engine instead of imperative registration/unregistration.

Key changes:

  • Removed syncPlanModeTools from Config class and its calls during initialization and mode transitions.
  • Added declarative DENY rules to plan.toml, write.toml, and yolo.toml to control enter_plan_mode and exit_plan_mode visibility based on the current ApprovalMode.

Closes #20595


Plan mode has ExitPlanMode tool

Screenshot 2026-02-27 at 2 12 37 PM

Default mode has EnterPlanMode tool
Screenshot 2026-02-27 at 2 12 52 PM


Auto-Edit mode has EnterPlanMode tool
Screenshot 2026-02-27 at 2 13 06 PM


YOLO mode does not have EnterPlanMode or EnterPlanMode tools
Screenshot 2026-02-27 at 2 13 21 PM

@jerop jerop requested a review from a team as a code owner February 27, 2026 19:06
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 refactors the management of plan-related tool visibility by transitioning from an imperative, code-driven synchronization mechanism to a declarative, policy-based approach. This change centralizes tool visibility logic within the Policy Engine, making it more consistent and easier to manage across different operational modes. The primary impact is a cleaner, more robust system for controlling which tools are available to the model based on the current approval mode, enhancing maintainability and reducing potential for inconsistencies.

Highlights

  • Removed imperative tool synchronization: The manual syncPlanModeTools method from the Config class and its calls during initialization and mode transitions have been removed.
  • Introduced declarative policy rules: New DENY rules were added to plan.toml, write.toml, and yolo.toml to control the visibility of enter_plan_mode and exit_plan_mode based on the current ApprovalMode.
  • Updated tool registration logic: The Config.createToolRegistry now unconditionally registers plan tools if the feature is enabled, relying on policy rules for visibility control.
  • Refactored approval mode updates: The updateApprovalMode method now refreshes the model's toolset via geminiClient.setTools() when transitioning between modes, ensuring policies are re-evaluated.
  • Revised test suite: Existing tests were updated to reflect the new policy-based filtering, and obsolete syncPlanModeTools tests were removed.
Changelog
  • packages/core/src/config/config.test.ts
    • Removed imports for ExitPlanModeTool and EnterPlanModeTool.
    • Added a new test case to verify EnterPlanModeTool and ExitPlanModeTool are registered when the plan feature is enabled.
    • Removed the entire describe('syncPlanModeTools', ...) test block, as the method was removed.
  • packages/core/src/config/config.ts
    • Removed imports for ENTER_PLAN_MODE_TOOL_NAME and EXIT_PLAN_MODE_TOOL_NAME.
    • Removed the call to this.syncPlanModeTools() during initialize().
    • Removed the syncPlanModeTools() method entirely.
    • Modified updateApprovalMode() to directly call this.geminiClient.setTools() when a plan or YOLO mode transition occurs, replacing the call to syncPlanModeTools().
  • packages/core/src/policy/policies/plan.toml
    • Added a new rule to deny enter_plan_mode when the system is already in 'plan' mode, with a specific deny message.
  • packages/core/src/policy/policies/write.toml
    • Added a new rule to deny exit_plan_mode when the system is in 'default' or 'autoEdit' modes, with a specific deny message.
  • packages/core/src/policy/policies/yolo.toml
    • Added a new rule to deny both enter_plan_mode and exit_plan_mode when the system is in 'yolo' mode.
  • packages/core/src/policy/policy-engine.test.ts
    • Added a test case to ensure enter_plan_mode is denied when already in PLAN mode.
    • Added a test case to ensure exit_plan_mode is denied when in DEFAULT mode.
    • Added a test case to ensure both plan tools are denied when in YOLO mode.
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.

@jerop jerop force-pushed the refactor/policy-based-plan-tools branch from 76c386d to da3ed4d Compare February 27, 2026 19:08
Copy link
Copy Markdown
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 refactors the management of plan-related tools (enter_plan_mode and exit_plan_mode) by replacing the imperative syncPlanModeTools method with declarative policy rules. The logic for enabling or disabling these tools based on the current ApprovalMode is now handled by DENY rules in the plan.toml, write.toml, and yolo.toml policy files. The Config class is simplified by removing the manual synchronization logic, and tests have been updated to reflect this new declarative approach. The plan-related tools are now always registered if the feature is enabled, with their visibility controlled by the policy engine.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 27, 2026

Size Change: -1.19 kB (0%)

Total Size: 25.8 MB

Filename Size Change
./bundle/gemini.js 25.3 MB -1.19 kB (0%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

@jerop jerop enabled auto-merge February 27, 2026 19:17
@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 27, 2026
@jerop jerop added the release/patch-to-preview PR needs to be patch to preview release label Feb 27, 2026
@jerop jerop force-pushed the refactor/policy-based-plan-tools branch 3 times, most recently from 971148d to 926dabb Compare March 2, 2026 21:41
jerop added 2 commits March 2, 2026 16:42
…icy rules

Unified plan-related tool visibility management by leveraging the existing Policy Engine instead of imperative registration/unregistration.

Key changes:
- Removed syncPlanModeTools from Config class and its calls during initialization and mode transitions.
- Added declarative DENY rules to plan.toml, write.toml, and yolo.toml to control enter_plan_mode and exit_plan_mode visibility based on the current ApprovalMode.
- Updated Config.createToolRegistry to always register plan tools if the feature is enabled.
- Refactored updateApprovalMode to refresh the model's toolset via geminiClient.setTools() when transitioning between modes.
- Updated tests to reflect policy-based filtering and removed obsolete sync tests.

Closes #20595
@jerop jerop force-pushed the refactor/policy-based-plan-tools branch from 926dabb to 981d5c4 Compare March 2, 2026 21:42
@jerop jerop disabled auto-merge March 2, 2026 22:03
@jerop jerop force-pushed the refactor/policy-based-plan-tools branch from 981d5c4 to d2a0c6f Compare March 2, 2026 22:03
@jerop jerop force-pushed the refactor/policy-based-plan-tools branch from d2a0c6f to 0408daa Compare March 2, 2026 22:05
@jerop jerop enabled auto-merge March 2, 2026 22:07
@jerop jerop added this pull request to the merge queue Mar 2, 2026
Merged via the queue into main with commit d05ba11 Mar 2, 2026
27 checks passed
@jerop jerop deleted the refactor/policy-based-plan-tools branch March 2, 2026 22:44
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
struckoff pushed a commit to struckoff/gemini-cli that referenced this pull request Mar 6, 2026
@jerop jerop removed the release/patch-to-preview PR needs to be patch to preview release label Mar 9, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Manual Synchronization of Plan-Related Tools

2 participants