agentleFS
googleworkspacegoogleworkspace/cli/AGENTS.md

cli

AGENTS.md31k starsChanged 8 months agoApache-2.0View on GitHub

gws is a Rust CLI tool for interacting with Google Workspace APIs. It dynamically generates its command surface at runtime by parsing Google Discovery Service JSON documents. [!IMPORTANT] Dynamic Discovery: This project does NOT use generated Rust crates (e.g., google-drive3) for API interaction. Instead, it fetches the Discovery JSON at runtime and builds clap commands dynamically. When adding a new service, you only need to register it in crates/google-workspace/src/services.rs and verify the Discovery URL pattern in crates/google-workspace/src/discovery.rs. Do NOT add…

  • Reads credentials

Adopted by

Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data

Week of Sep 27: 0 new projectsWeek of Oct 4: 0 new projectsWeek of Oct 11: 0 new projectsWeek of Oct 18: 0 new projectsWeek of Oct 25: 0 new projectsWeek of Nov 1: 0 new projectsWeek of Nov 8: 0 new projectsWeek of Nov 15: 0 new projects
Sep 2026Oct 2026Nov 2026
New projects taking a version of this file each week, over the 8 weeks our latest run read: only 0 in all, so this is a hint, not a trend.

Who's talking about googleworkspace/cli

The biggest 5 of 93 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 93

Talked about on GitHub, Bluesky and Hacker News (93 times).

On GitHub · 50

45 more on GitHub

On Bluesky · 39

34 more on Bluesky

On Hacker News · 4

The file

We split this AGENTS.md into the rules it gives an agent

9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every PR must include a changeset file.

    line 26
  2. Very specific:

    Use patch for fixes/chores, minor for new features, major for breaking changes.

    line 36
  3. Very specific:

    Use double quotes for simple strings: Type "gws --help" Enter

    line 88
  4. Distinctive:

    Use backtick quotes when the typed text contains JSON with double quotes:

    line 89
  5. Distinctive:

    When adding new helpers or CLI flags that accept file paths, always validate using the shared helpers:

    line 109
  6. Distinctive:

    When a user-supplied string is used as a GCP resource identifier (project ID, topic name, space name, etc.) that gets embedded in a URL …

    line 152
  7. Distinctive:

    When adding a new helper or CLI command:

    line 164
  8. Distinctive:

    Use these labels to categorize pull requests and issues:

    line 175
  9. Very specific:

    All variables can also live in a .env file (loaded via dotenvy).

    line 239

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

Project Overview

gws is a Rust CLI tool for interacting with Google Workspace APIs. It dynamically generates its command surface at runtime by parsing Google Discovery Service JSON documents.

[!IMPORTANT] Dynamic Discovery: This project does NOT use generated Rust crates (e.g., google-drive3) for API interaction. Instead, it fetches the Discovery JSON at runtime and builds clap commands dynamically. When adding a new service, you only need to register it in crates/google-workspace/src/services.rs and verify the Discovery URL pattern in crates/google-workspace/src/discovery.rs. Do NOT add new crates to Cargo.toml for standard Google APIs.

[!NOTE] Package Manager: Use pnpm instead of npm for Node.js package management in this repository.

Build & Test

[!IMPORTANT] Test Coverage: The codecov/patch check requires that new or modified lines are covered by tests. When adding code, extract testable helper functions rather than embedding logic in main/run where it's hard to unit-test. Run cargo test locally and verify new branches are exercised.

cargo build          # Build in dev mode
cargo clippy -- -D warnings  # Lint check
cargo test           # Run tests

Changesets

Every PR must include a changeset file. Create one at .changeset/<descriptive-name>.md:

---
"@googleworkspace/cli": patch
---

Brief description of the change

Use patch for fixes/chores, minor for new features, major for breaking changes. The CI policy check will fail without a changeset.

Architecture

The CLI uses a two-phase argument parsing strategy:

  1. Parse argv to extract the service name (e.g., drive)
  2. Fetch the service's Discovery Document, build a dynamic clap::Command tree, then re-parse

Workspace Layout

The repository is a Cargo workspace with two crates:

CratePackagePurpose
crates/google-workspace/google-workspacePublishable library — core types and helpers
crates/google-workspace-cli/google-workspace-cliBinary crate — the gws CLI

Library (crates/google-workspace/src/)

FilePurpose
discovery.rsSerde models for Discovery Document + async fetch/cache
services.rsService alias → Discovery API name/version mapping
error.rsGwsError enum, exit codes, JSON serialization
validate.rsPath/URL/resource validators, encode_path_segment()
client.rsHTTP client with retry logic

CLI (crates/google-workspace-cli/src/)

FilePurpose
main.rsEntrypoint, two-phase CLI parsing, method resolution
auth.rsOAuth2 token acquisition via env vars, encrypted credentials, or ADC
credential_store.rsAES-256-GCM encryption/decryption of credential files
auth_commands.rsgws auth subcommands: login, logout, setup, status, export
commands.rsRecursive clap::Command builder from Discovery resources
executor.rsHTTP request construction, response handling, schema validation
schema.rsgws schema command — introspect API method schemas
logging.rsOpt-in structured logging (stderr + file) via tracing
timezone.rsAccount timezone resolution: --timezone flag, Calendar Settings API

Demo Videos

Demo recordings are generated with VHS (.tape files).

vhs docs/demo.tape

VHS quoting rules

  • Use double quotes for simple strings: Type "gws --help" Enter
  • Use backtick quotes when the typed text contains JSON with double quotes:
    Type `gws drive files list --params '{"pageSize":5}'` Enter
    \" escapes inside double-quoted Type strings are not supported by VHS and will cause parse errors.

Scene art

ASCII art title cards live in art/. The scripts/show-art.sh helper clears the screen and cats the file. Portrait scenes use scene*.txt; landscape chapters use long-*.txt.

Input Validation & URL Safety

[!IMPORTANT] This CLI is frequently invoked by AI/LLM agents. Always assume inputs can be adversarial — validate paths against traversal (../../.ssh), restrict format strings to allowlists, reject control characters, and encode user values before embedding them in URLs.

[!NOTE] Environment variables are trusted inputs. The validation rules above apply to CLI arguments that may be passed by untrusted AI agents. Environment variables (e.g. GOOGLE_WORKSPACE_CLI_CONFIG_DIR) are set by the user themselves — in their shell profile, .env file, or deployment config — and are not subject to path traversal validation. This is consistent with standard conventions like XDG_CONFIG_HOME, CARGO_HOME, etc.

Path Safety (crates/google-workspace/src/validate.rs)

When adding new helpers or CLI flags that accept file paths, always validate using the shared helpers:

ScenarioValidatorRejects
File path for writing (--output-dir)validate::validate_safe_output_dir()Absolute paths, ../ traversal, symlinks outside CWD, control chars
File path for reading (--dir)validate::validate_safe_dir_path()Absolute paths, ../ traversal, symlinks outside CWD, control chars
Enum/allowlist values (--msg-format)clap value_parser (see gmail/mod.rs)Any value not in the allowlist
// In your argument parser:
if let Some(output_dir) = matches.get_one::<String>("output-dir") {
    crate::validate::validate_safe_output_dir(output_dir)?;
    builder.output_dir(Some(output_dir.clone()));
}

URL Encoding (crates/google-workspace-cli/src/helpers/mod.rs)

User-supplied values embedded in URL path segments must be percent-encoded. Use the shared helper:

// CORRECT — encodes slashes, spaces, and special characters
let url = format!(
    "https://www.googleapis.com/drive/v3/files/{}",
    crate::helpers::encode_path_segment(file_id),
);

// WRONG — raw user input in URL path
let url = format!("https://www.googleapis.com/drive/v3/files/{}", file_id);

For query parameters, use reqwest's .query() builder which handles encoding automatically:

// CORRECT — reqwest encodes query values
client.get(url).query(&[("q", user_query)]).send().await?;

// WRONG — manual string interpolation in query strings
let url = format!("{}?q={}", base_url, user_query);

Resource Name Validation (crates/google-workspace-cli/src/helpers/mod.rs)

When a user-supplied string is used as a GCP resource identifier (project ID, topic name, space name, etc.) that gets embedded in a URL path, validate it first:

// Validates the string does not contain path traversal segments (`..`), control characters, or URL-breaking characters like `?` and `#`.
let project = crate::validate::validate_resource_name(&project_id)?;
let url = format!("https://pubsub.googleapis.com/v1/projects/{}/topics/my-topic", project);

This prevents injection of query parameters, path traversal, or other malicious payloads through resource name arguments like --project or --space.

Checklist for New Features

When adding a new helper or CLI command:

  1. File paths → Use validate_safe_output_dir / validate_safe_dir_path
  2. Enum flags → Constrain via clap value_parser or validate_msg_format
  3. URL path segments → Use encode_path_segment()
  4. Query parameters → Use reqwest .query() builder
  5. Resource names (project IDs, space names, topic names) → Use validate_resource_name()
  6. Write tests for both the happy path AND the rejection path (e.g., pass ../../.ssh and assert Err)

PR Labels

Use these labels to categorize pull requests and issues:

  • area: discovery — Discovery document fetching, caching, parsing
  • area: http — Request execution, URL building, response handling
  • area: docs — README, contributing guides, documentation
  • area: tui — Setup wizard, picker, input fields
  • area: distribution — Nix flake, npm packaging, GitHub Actions release workflow, install methods
  • area: auth — OAuth, credentials, multi-account, ADC
  • area: skills — AI skill generation and management

Helper Commands (+verb)

Helpers are handwritten commands prefixed with + that provide value the schema-driven Discovery commands cannot: multi-step orchestration, format translation (e.g., Markdown → Docs JSON), or multi-API composition.

[!IMPORTANT] Do NOT add a helper that wraps a single API call already available via Discovery, adds flags to expose data already in the API response, or re-implements Discovery parameters as custom flags. Helper flags must control orchestration logic — use --params and --format/jq for API parameters and output filtering.

See src/helpers/README.md for full guidelines, anti-patterns, and a checklist for new helpers.

Environment Variables

Authentication

VariableDescription
GOOGLE_WORKSPACE_CLI_TOKENPre-obtained OAuth2 access token (highest priority; bypasses all credential file loading)
GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILEPath to OAuth credentials JSON (no default; if unset, falls back to encrypted credentials in ~/.config/gws/)
GOOGLE_WORKSPACE_CLI_KEYRING_BACKENDKeyring backend: keyring (default, uses OS keyring with file fallback) or file (file only, for Docker/CI/headless)

| GOOGLE_APPLICATION_CREDENTIALS | Standard Google ADC path; used as fallback when no gws-specific credentials are configured |

Configuration

VariableDescription
GOOGLE_WORKSPACE_CLI_CONFIG_DIROverride the config directory (default: ~/.config/gws)

OAuth Client

VariableDescription
GOOGLE_WORKSPACE_CLI_CLIENT_IDOAuth client ID (for gws auth login when no client_secret.json is saved)
GOOGLE_WORKSPACE_CLI_CLIENT_SECRETOAuth client secret (paired with CLIENT_ID above)

Sanitization (Model Armor)

VariableDescription
GOOGLE_WORKSPACE_CLI_SANITIZE_TEMPLATEDefault Model Armor template (overridden by --sanitize flag)
GOOGLE_WORKSPACE_CLI_SANITIZE_MODEwarn (default) or block

Helpers

VariableDescription
GOOGLE_WORKSPACE_PROJECT_IDGCP project ID override for quota/billing and fallback for helper commands (overridden by --project flag)

Logging

VariableDescription
GOOGLE_WORKSPACE_CLI_LOGLog level filter for stderr output (e.g., gws=debug). Off by default.
GOOGLE_WORKSPACE_CLI_LOG_FILEDirectory for JSON-line log files with daily rotation. Off by default.

All variables can also live in a .env file (loaded via dotenvy).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.