Skip to content

docs(extensions): correct excludeTools examples that never match - #28963

Open
chandlerm923 wants to merge 1 commit into
google-gemini:mainfrom
chandlerm923:docs/extension-exclude-tools-example
Open

chandlerm923 wants to merge 1 commit into
google-gemini:mainfrom
chandlerm923:docs/extension-exclude-tools-example

Conversation

@chandlerm923

Copy link
Copy Markdown

Summary

docs/extensions/best-practices.md told extension authors to write

{ "excludeTools": ["run_shell_command(rm -rf *)"] }

and stated that this "ensures the CLI blocks dangerous commands". It does not.
Extension excludeTools entries are compared against whole tool names, so an
entry containing (...) matches nothing and is silently dropped — the tool stays
available to the model with no warning.

This corrects the two extension doc pages and the shipped example manifest to
show a form that actually takes effect.

Details

Config.getExcludeTools() folds extension.excludeTools into a Set
(packages/core/src/config/config.ts:2431-2439), and ToolRegistry.isActiveTool
tests membership directly (packages/core/src/tools/tool-registry.ts:637):

return !possibleNames.some((name) => excludeTools?.has(name));

possibleNames holds the tool's real names — run_shell_command, its class
name, and MCP-qualified variants — none of which equal
"run_shell_command(rm -rf *)".

The parenthesised toolName(args) shape is real syntax, but it belongs to
tools.core / tools.allowed, which are parsed by mapToolsToRules
(packages/core/src/policy/config.ts:445-476). Extension excludeTools never
goes through that path.

For the "block one specific command" case the page was describing, that
capability now lives in the policy engine: the settings-level tools.exclude was
deprecated in its favour (#18508, documented at docs/tools/shell.md:158 and
docs/cli/enterprise.md:267), and extensions can ship rules in a policies/
directory. The TOML snippet added here mirrors the shipped example extension in
packages/cli/src/commands/extensions/examples/policies/.

Note on decision: that example extension uses ask_user for rm -rf, but the
original prose promised the CLI "blocks" the command, so deny preserves the
stated intent. Happy to switch it to ask_user if you'd rather the two examples
match exactly.

Related Issues

Related to #28962

How to Validate

The exclusion behaviour, using the real Config and ToolRegistry:

const config = new Config(params);
vi.spyOn(config, 'getExcludeTools').mockReturnValue(new Set(entry));
const registry = await config.createToolRegistry();
registry.getAllTools().some((t) => t.name === 'run_shell_command');
excludeTools entry run_shell_command still registered
[] yes
["run_shell_command"] no — excluded
["run_shell_command(rm -rf)"] yes — entry ignored
["run_shell_command(rm -rf *)"] yes — entry ignored

The policy snippet added to best-practices.md, loaded through the real
extension policy loader and evaluated by PolicyEngine:

loadExtensionPolicies('my-safe-extension', '<ext>/policies')
  -> 0 errors, 1 rule
run_shell_command {"command":"rm -rf /tmp/victim"}  ->  deny
run_shell_command {"command":"ls -la"}              ->  allow

Docs checks:

npx prettier --check docs/extensions/best-practices.md docs/extensions/reference.md \
  packages/cli/src/commands/extensions/examples/exclude-tools/gemini-extension.json
npm run lint

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed) — this PR is the
    documentation change
  • Added/updated tests (if needed) — n/a, no source behaviour changes
  • Noted breaking changes (if any) — none; docs and one example manifest only
  • Validated on required platforms/methods:
    • MacOS
      • npm run

`excludeTools` entries are compared against whole tool names:
`Config.getExcludeTools()` collects them into a `Set` and `ToolRegistry`
tests membership with `Set.has()`. An entry such as
`run_shell_command(rm -rf)` therefore matches nothing and is silently
ignored, yet `best-practices.md` presented that form and stated it
"ensures the CLI blocks dangerous commands".

Show the form that works, and point readers at the policy engine for
command-level blocking, which is where that capability now lives (the
settings-level `tools.exclude` was deprecated in favour of it). The
policy snippet mirrors the shipped example extension in
`examples/policies/`.

Related to google-gemini#28962
@chandlerm923
chandlerm923 requested review from a team as code owners August 22, 2026 13:26
@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 corrects misleading documentation regarding the 'excludeTools' property in extension manifests. It clarifies that 'excludeTools' matches only against full tool names and does not support partial command-level filtering as previously suggested. The changes direct users toward the policy engine for fine-grained command control and update the associated example manifest to reflect valid usage.

Highlights

  • Documentation Correction: Updated documentation to clarify that 'excludeTools' only supports full tool names, removing incorrect examples that suggested command-specific filtering.
  • Policy Engine Guidance: Introduced guidance on using the policy engine for command-specific restrictions, providing a concrete TOML example for blocking dangerous shell commands.
  • Example Manifest Update: Corrected the 'gemini-extension.json' example to use a valid 'excludeTools' configuration.
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 the 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 counterproductive. 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.

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 github-actions Bot added the size/s A small PR label Aug 22, 2026
@github-actions

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 37
  • Additions: +25
  • Deletions: -12
  • Files changed: 3

@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

This pull request updates the documentation and example configuration for excludeTools to clarify that it only supports matching whole tool names. It guides users to use the policy engine in the policies/ directory for restricting individual commands instead. I have no additional feedback to provide as there are no review comments.

Note: Security Review has been skipped due to the limited scope of the PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants