Skip to content

feat(plan): enforce read-only constraints in Plan Mode#19433

Merged
mattKorwel merged 8 commits intomainfrom
mk-planmode-notools
Feb 20, 2026
Merged

feat(plan): enforce read-only constraints in Plan Mode#19433
mattKorwel merged 8 commits intomainfrom
mk-planmode-notools

Conversation

@mattKorwel
Copy link
Collaborator

This PR enforces strict read-only constraints when the agent is in Plan Mode.

Key changes:

  • Updates the Plan Mode policy to deny and on source code.
  • Restricts the to read-only tools (+ plan-specific writes) during Plan Mode.
  • Updates system prompts to clearly communicate these constraints to the model.
  • Adds explicit warnings in tool schemas when in Plan Mode.

… in Plan Mode

- Update Plan Mode policy to explicitly deny write_file and replace operations on source code.
- Restrict ToolRegistry to only allow read-only tools and plan-related write operations when in Plan Mode.
- Enhance tool schemas in Plan Mode with descriptions explicitly limiting write_file and replace to the designated plans directory.
- Update Plan Mode system prompts to clarify behavioral rules and the requirement for approved plans before source code modifications.
- Standardize formatting in strict-development-rules.md.
@mattKorwel mattKorwel requested a review from a team as a code owner February 18, 2026 14:09
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mattKorwel, 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 strengthens the read-only constraints within Plan Mode. It ensures that the agent cannot inadvertently modify source code by explicitly denying write operations, guiding the model through updated prompts, and dynamically filtering available tools. This change aims to improve the safety and predictability of the agent's behavior when operating in a planning context, preventing unintended direct code modifications.

Highlights

  • Policy Enforcement: Explicitly denied write_file and replace operations on source code within Plan Mode through a new policy rule, ensuring that the agent cannot inadvertently modify production code.
  • Prompt Updates: Enhanced system prompts to guide the model on handling direct source code modification requests in Plan Mode, emphasizing the necessity of creating a detailed plan first.
  • Tool Filtering: Implemented logic to restrict available tools in Plan Mode to a predefined set of approved read-only tools, while still allowing specific write operations exclusively for plan files.
  • Tool Schema Warnings: Modified the descriptions of write_file and replace tools to include explicit warnings about their limited use (only for plans) when the agent is operating in Plan Mode.
Changelog
  • packages/core/src/policy/policies/plan.toml
    • Added a new policy rule to explicitly deny write_file and replace tools for source code modifications in Plan Mode, including a custom deny message.
  • packages/core/src/prompts/snippets.ts
    • Updated the "Read-Only" rule in the system prompt to instruct the model to explain Plan Mode restrictions and require a detailed plan for source code changes before any modifications.
  • packages/core/src/tools/tool-registry.ts
    • Imported ApprovalMode and specific tool names (PLAN_MODE_TOOLS, WRITE_FILE_TOOL_NAME, EDIT_TOOL_NAME).
    • Introduced logic within getActiveTools to filter tools, allowing only designated read-only tools and specific write tools for plans when in ApprovalMode.PLAN.
    • Modified getFunctionDeclarations to dynamically update the descriptions of write_file and replace tools, adding a clear warning about their restricted use to only writing plans in Plan Mode.
Ignored Files
  • Ignored by pattern: .gemini/** (1)
    • .gemini/commands/strict-development-rules.md
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
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 18, 2026

Size Change: +1.43 kB (+0.01%)

Total Size: 25.2 MB

Filename Size Change
./bundle/gemini.js 25.1 MB +1.43 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./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

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 aims to enforce read-only constraints in Plan Mode. The changes to the system prompts and tool registry correctly implement the desired restrictions at the prompt and tool availability levels. However, there is a critical issue in the plan.toml policy file where an incorrect tool name (replace instead of edit) is used. This will cause the policy rules for editing files in Plan Mode to be ineffective, undermining the goal of this PR. The suggested fix also aligns with the repository's rule for consolidating policy rules for multiple tools into a single rule using an array for toolName.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 18, 2026
@mattKorwel
Copy link
Collaborator Author

I have updated the PR to address the intent of the review. Regarding the tool name suggestion: the canonical tool name in this codebase is 'replace' (as defined in coreTools.ts). I have verified that 'replace' is the correct name to use in policy files to match the model's tool calls. I've restored the explicit deny rules using the correct 'replace' name and re-applied the other improvements to tool schemas and prompts.

mattKorwel and others added 3 commits February 19, 2026 13:18
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@jerop jerop self-requested a review February 19, 2026 22:46
@mattKorwel mattKorwel enabled auto-merge February 19, 2026 22:58
@jerop jerop self-assigned this Feb 20, 2026
@mattKorwel mattKorwel added this pull request to the merge queue Feb 20, 2026
@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. and removed status/need-issue Pull requests that need to have an associated issue. labels Feb 20, 2026
Merged via the queue into main with commit 6cfd29e Feb 20, 2026
27 checks passed
@mattKorwel mattKorwel deleted the mk-planmode-notools branch February 20, 2026 19:46
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.

[Agent] Reduce policy failures due to implicit constraints during planning

2 participants