docs(policy-engine): add tool argument keys reference and shell policy cross-links#25292
Conversation
…y cross-links Add a "Tool argument keys" section to the tools reference page listing JSON argument keys for all built-in tools, making toolName and argsPattern usable without guesswork. Add a "Policy engine shorthands" section to the shell tool page documenting commandPrefix and commandRegex as policy-rule convenience fields. Fixes google-gemini#18750
Summary of ChangesHello, 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 improves the developer experience by filling documentation gaps related to the policy engine. It provides clear references for tool argument structures and clarifies the usage of specific policy rule shorthands, ensuring users can configure security policies more effectively without ambiguity. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds documentation for tool argument keys and policy engine shorthands for shell commands. Several critical issues were identified in the new documentation: the argument keys for glob, grep_search, and read_file do not match the actual codebase definitions, which would cause policy rules to fail. Additionally, the regex example for blocking .env files requires multiple levels of escaping to be valid in a TOML/JSON context, and the documented commandPrefix and commandRegex shorthands are currently unimplemented in the policy engine, making their inclusion misleading.
Note: Security Review has been skipped due to the limited scope of the PR.
| ```toml | ||
| [[rule]] | ||
| toolName = "write_file" | ||
| argsPattern = '"file_path":".*\.env"' |
There was a problem hiding this comment.
According to the repository's general rules, regular expressions embedded in TOML strings require multiple levels of escaping for literal characters like dots to account for TOML, JSON, and regex parsing layers. In a literal TOML string (single quotes), a literal dot for the regex engine should be represented as \\..
| argsPattern = '"file_path":".*\.env"' | |
| argsPattern = '"file_path":".*\\.env"' |
References
- When a regular expression is embedded within a JSON string, which is itself embedded within a TOML string, multiple levels of escaping are required. For example, to represent a literal dot for the regex engine, it must be written as \. in the TOML file to account for escaping at the TOML, JSON, and regex parsing layers.
There was a problem hiding this comment.
The argsPattern value is in a TOML single-quoted (literal) string, which has no escape processing per the TOML spec. The string '\.env' gives the regex \.env, where \. correctly matches a literal dot. Using '\\.env' would give regex \\.env, which matches a literal backslash followed by any character — not the intended behavior. The existing policy engine docs use the same single-quote convention without double escaping (e.g., argsPattern = '"command":"(git|npm)').
Fix JSON argument keys for glob (dir_path not path, add respect_gemini_ignore), grep_search (dir_path not path, include_pattern not include, add all optional params), and read_file (start_line/end_line not offset/limit) to match actual parameter names in base-declarations.ts.
|
Hi, I reviewed this PR and found a few areas that might need clarification/improvement:
I’d be happy to contribute improvements if needed. |
|
Thanks for looking! The argument keys were already corrected in c3736ba, and the other two points are addressed in my replies to the automated review above — the escaping is correct per the TOML spec for literal strings, and commandPrefix/commandRegex are implemented in toml-loader.ts as syntactic sugar that compiles to argsPattern. |
DavidAPierce
left a comment
There was a problem hiding this comment.
LGTM. Correctly documents the JSON argument keys for built-in tools and clarifies
the behavior of policy engine shorthands for shell commands.
…y cross-links (google-gemini#25292) Co-authored-by: David Pierce <davidapierce@google.com>
…y cross-links (google-gemini#25292) Co-authored-by: David Pierce <davidapierce@google.com>
Summary
This PR addresses the remaining documentation gaps identified in #18750 (complementary to #22081 which adds links from the policy engine page):
docs/reference/tools.md— A compact reference table listing JSON argument keys for all 24 built-in tools, with a practicalargsPatternexample. This makestoolNameandargsPatternusable without guesswork.docs/tools/shell.md— Documents thatcommandPrefixandcommandRegexexist as policy-rule convenience fields, clarifies they are notrun_shell_commandarguments, and links to the policy engine reference.Details
Issue items addressed
commandPrefixabsent from shell tool pageargsPatternrequires knowing JSON argument structureRelationship with #22081
PR #22081 adds cross-links from the policy engine page to the tools reference. This PR adds the reference content at those link targets and a cross-reference from the shell tool page back to the policy engine. The two PRs are complementary and non-overlapping.
How to validate
docs/reference/tools.mdand verify the new "Tool argument keys" subsection under "Available tools" contains a complete table of tools and their JSON argument keys..envwrites is syntactically correct.docs/tools/shell.mdand verify the new "Policy engine shorthands" subsection appears between "Arguments" and "Return values".Pre-merge checklist
Documentation-only change. Passes
prettier --checkand pre-commit hooks.Fixes #18750