Skip to content

feat: add --draft-only mode for agent workflows#460

Open
Sigmabrogz wants to merge 1 commit intogoogleworkspace:mainfrom
Sigmabrogz:feat/draft-only
Open

feat: add --draft-only mode for agent workflows#460
Sigmabrogz wants to merge 1 commit intogoogleworkspace:mainfrom
Sigmabrogz:feat/draft-only

Conversation

@Sigmabrogz
Copy link

Fixes #424

Adds a global --draft-only flag to intercept and block any users.messages.send or users.drafts.send requests in the Gmail API wrapper, returning an error. Useful for AI agent workflows to prevent accidental emails.

Signed-off-by: Sigmabrogz <bnb1000bnb@gmail.com>
@Sigmabrogz Sigmabrogz requested a review from jpoehnelt as a code owner March 13, 2026 06:45
@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

⚠️ No Changeset found

Latest commit: 3bb784f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@googleworkspace-bot googleworkspace-bot added the area: core Core CLI parsing, commands, error handling, utilities label Mar 13, 2026
@google-cla
Copy link

google-cla bot commented Mar 13, 2026

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.

@gemini-code-assist
Copy link
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 enhances the application's safety for automated workflows by introducing a --draft-only mode. This mode prevents any outgoing email send operations, ensuring that AI agents or other automated processes can interact with the Gmail API without inadvertently dispatching messages.

Highlights

  • New CLI Flag: A global --draft-only command-line flag has been introduced to enable a safe mode for agent workflows.
  • Email Sending Prevention: Logic was implemented to strictly intercept and block users.messages.send and users.drafts.send requests when the --draft-only flag is active, returning a validation error.
  • Agent Workflow Safety: This feature provides a crucial safety mechanism for AI agent workflows, preventing accidental email dispatches by ensuring that send operations are blocked.
Changelog
  • src/commands.rs
    • Added the --draft-only global argument definition.
  • src/helpers/gmail/mod.rs
    • Introduced a conditional check within the send_raw_email function to return a validation error if --draft-only is active.
  • src/main.rs
    • Integrated a check at the main execution level to intercept and block gmail.users.messages.send and gmail.users.drafts.send API calls when --draft-only is enabled.
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 Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 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.

Comment on lines +222 to +231
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(),
));
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This block implements the core logic for --draft-only mode, but it can be made more robust and maintainable.

  1. Redundant Flag Check: The draft-only flag is global, so checking matched_args.get_flag("draft-only") is sufficient. The current logic is inconsistent with how the dry-run flag is handled just above.

  2. 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.

  3. 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.

Suggested change
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(),
));
}
}
}

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

Labels

area: core Core CLI parsing, commands, error handling, utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Gmail draft-only mode for CLI+agent workflows

2 participants