Skip to content

feat(policy): Implement Tool Annotation Matching in Policy Engine - #20029

Merged
jerop merged 1 commit into
mainfrom
feat/policy-annotations-core-v2
Feb 23, 2026
Merged

feat(policy): Implement Tool Annotation Matching in Policy Engine#20029
jerop merged 1 commit into
mainfrom
feat/policy-annotations-core-v2

Conversation

@jerop

@jerop jerop commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #20025
Follow up on #20024

  • Add toolAnnotations field to PolicyRule and SafetyCheckerRule types.
  • Implement partial record matching for toolAnnotations in the policy engine.
  • Update check and checkShellCommand to propagate annotations during evaluation.
  • Update TOML loader to support parsing toolAnnotations from policy files.
  • Add comprehensive unit and integration tests for behavior-based security rules using readOnlyHint.

Note: Future work will implement the pipeline to capture and propagate annotations from discovered MCP servers as part of #19655.

@jerop
jerop requested a review from a team as a code owner February 23, 2026 16:00
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @jerop, 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 engine by introducing support for tool annotations. This new feature allows policy rules to be defined and enforced based on metadata associated with tools, such as a readOnlyHint. By propagating these annotations through the policy evaluation process and enabling their parsing from TOML configuration, the system gains a more flexible and powerful mechanism for security and behavior-based policy enforcement.

Highlights

  • Tool Annotation Support: Introduced a toolAnnotations field to PolicyRule and SafetyCheckerRule types, enabling policies to be defined based on tool metadata.
  • Policy Engine Matching Logic: Implemented partial record matching for toolAnnotations within the policy engine, allowing for more granular control over tool execution based on their metadata.
  • Annotation Propagation: Updated the check and checkShellCommand methods to correctly propagate toolAnnotations during the policy evaluation process.
  • TOML Loader Enhancement: Enhanced the TOML policy loader to support parsing toolAnnotations from policy configuration files.
  • Comprehensive Testing: Added extensive unit and integration tests to validate the new annotation matching behavior and ensure its correctness.
Changelog
  • packages/cli/src/config/policy-engine.integration.test.ts
    • Added an integration test case to verify that the policy engine correctly matches rules based on toolAnnotations.
  • packages/core/src/policy/policy-engine.test.ts
    • Added unit tests to confirm that the policy engine can match tools by semantic annotations and supports scoped annotation rules.
  • packages/core/src/policy/policy-engine.ts
    • Modified the ruleMatches function to incorporate toolAnnotations in the rule matching logic.
    • Updated the check and checkShellCommand methods to accept and pass toolAnnotations during policy evaluation.
  • packages/core/src/policy/toml-loader.test.ts
    • Added a test to ensure that toolAnnotations are correctly parsed from TOML policy files.
  • packages/core/src/policy/toml-loader.ts
    • Extended PolicyRuleSchema and SafetyCheckerRuleSchema to include an optional toolAnnotations field.
    • Modified the loadPoliciesFromToml function to properly load toolAnnotations into policy rules.
  • packages/core/src/policy/types.ts
    • Added the toolAnnotations property to the PolicyRule and SafetyCheckerRule interfaces.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request since its creation.
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.

@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality area/enterprise Issues related to Telemetry, Policy, Quota / Licensing 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request introduces tool annotation matching to the policy engine, allowing for more granular control over tool execution based on metadata. This is a significant improvement for defining behavior-based security rules. The changes include updating policy types, implementing the matching logic, and propagating annotations through methods. Additionally, the TOML loader has been updated to support parsing toolAnnotations from policy files, and tests have been added to validate the new functionality. The code is well-tested and adheres to the project's architectural guidelines.

Base automatically changed from feat/policy-wildcards-v2 to main February 23, 2026 19:26
@jerop
jerop requested a review from a team as a code owner February 23, 2026 19:26
…ngine

- Add toolAnnotations field to PolicyRule and SafetyCheckerRule types.

- Implement partial record matching for toolAnnotations in the policy engine.

- Update check and checkShellCommand to propagate annotations during evaluation.

- Update TOML loader to support parsing toolAnnotations from policy files.

- Add comprehensive unit and integration tests for behavior-based security rules using readOnlyHint.

Note: Future work will implement the pipeline to capture and propagate annotations from discovered MCP servers.

Fixes #20025
@jerop
jerop force-pushed the feat/policy-annotations-core-v2 branch from fc59660 to ff19f78 Compare February 23, 2026 21:24
@jerop
jerop enabled auto-merge February 23, 2026 21:25
@jerop jerop linked an issue Feb 23, 2026 that may be closed by this pull request
@github-actions

Copy link
Copy Markdown

Size Change: +852 B (0%)

Total Size: 25.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +852 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./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

@jerop
jerop added this pull request to the merge queue Feb 23, 2026
Merged via the queue into main with commit 3e5e608 Feb 23, 2026
27 checks passed
@jerop
jerop deleted the feat/policy-annotations-core-v2 branch February 23, 2026 21:53
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality area/enterprise Issues related to Telemetry, Policy, Quota / Licensing 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Semantic Tool Annotation Matching in Policy Engine

4 participants