feat: add --draft-only mode for agent workflows#460
feat: add --draft-only mode for agent workflows#460Sigmabrogz wants to merge 1 commit intogoogleworkspace:mainfrom
--draft-only mode for agent workflows#460Conversation
Signed-off-by: Sigmabrogz <bnb1000bnb@gmail.com>
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 enhances the application's safety for automated workflows by introducing a Highlights
Changelog
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. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a --draft-only mode to prevent accidental email sending, which is a great safety feature for agent workflows. The implementation correctly adds the flag and intercepts the relevant API calls in both the generic execution path and the Gmail helper functions. My review includes one high-severity suggestion to improve the robustness and maintainability of this new safety feature by simplifying a redundant flag check and centralizing hardcoded strings as constants to prevent typos and code duplication.
| let draft_only = matches.get_flag("draft-only") || matched_args.get_flag("draft-only"); | ||
| if draft_only { | ||
| if let Some(ref id) = method.id { | ||
| if id == "gmail.users.messages.send" || id == "gmail.users.drafts.send" { | ||
| return Err(GwsError::Validation( | ||
| "Draft-only mode is enabled. Sending emails is blocked.".to_string(), | ||
| )); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
This block implements the core logic for --draft-only mode, but it can be made more robust and maintainable.
-
Redundant Flag Check: The
draft-onlyflag is global, so checkingmatched_args.get_flag("draft-only")is sufficient. The current logic is inconsistent with how thedry-runflag is handled just above. -
Hardcoded Strings: The method IDs (
gmail.users.messages.send,gmail.users.drafts.send) and the error message are hardcoded. For a critical safety feature, these should be defined as constants to prevent typos and improve maintainability. -
Duplicated Logic: The error message string is duplicated in
src/helpers/gmail/mod.rs:584. Defining it as a constant would solve this.
I recommend creating shared constants for the method IDs and the error message, and simplifying the flag check. For example, you could define them in src/helpers/gmail/mod.rs and use them here.
| let draft_only = matches.get_flag("draft-only") || matched_args.get_flag("draft-only"); | |
| if draft_only { | |
| if let Some(ref id) = method.id { | |
| if id == "gmail.users.messages.send" || id == "gmail.users.drafts.send" { | |
| return Err(GwsError::Validation( | |
| "Draft-only mode is enabled. Sending emails is blocked.".to_string(), | |
| )); | |
| } | |
| } | |
| } | |
| let draft_only = matched_args.get_flag("draft-only"); | |
| if draft_only { | |
| if let Some(ref id) = method.id { | |
| // It's recommended to define these strings as constants | |
| // in a shared module (e.g. `src/helpers/gmail/mod.rs`) | |
| // to avoid typos and duplication. | |
| if id == "gmail.users.messages.send" || id == "gmail.users.drafts.send" { | |
| return Err(GwsError::Validation( | |
| "Draft-only mode is enabled. Sending emails is blocked.".to_string(), | |
| )); | |
| } | |
| } | |
| } |
Fixes #424
Adds a global
--draft-onlyflag to intercept and block anyusers.messages.sendorusers.drafts.sendrequests in the Gmail API wrapper, returning an error. Useful for AI agent workflows to prevent accidental emails.