Skip to content
BiteFoundryPublic

Repository files navigation

@bitefoundry/gdocs

Fast Google Docs terminal client & AI agent toolkit — RTT-style editorial TUI, scriptable CLI, local HTTP JSON API, and stdio MCP server.

npm version platforms Rust & Ratatui License: MIT

BiteFoundry · Engineering Design · MCP Reference · Latest Release


Highlights

Pillar Capabilities
Zero-Login Shared Links & 4-Mode Auth Open any public Google Doc (docs.google.com/document/d/...) or public Google Drive text/Markdown file (drive.google.com/file/d/...) immediately with gdocs "<SHARED_URL>" (TUI, CLI Markdown/JSON, and MCP — zero login required, with automatic macOS Hangul NFD→NFC normalization!), or sign in via OAuth JSON auto-discovery (--oauth-file auto / <client_secret.json>), BYO OAuth 2.0 PKCE (--oauth), Read-Only scopes (--readonly), gcloud ADC (--adc), or Service Account JSON (--service-account). Tokens live in the OS keyring with 0600 fallback; corporate root CAs are supported via --ca-cert.
Google Docs Native Editorial TUI Borderless RTT-style layout paired with Google Docs signature blue DNA (#1A73E8 / #669DF6), tinted document type chips (DOC / TXT / MD), two-tone reader header, semantic Markdown & plain-text highlighting (auto-outline for ==== banner .txt files, Key: Value labels, clickable bare URLs), pre-raw-mode OSC 11 terminal brightness auto-detection (editorial-auto, editorial-light, editorial-dark, and 16 live-preview presets via Ctrl+T), full desktop mouse parity (drag text selection + OSC 52 / clipboard copy, Alt+M capture toggle, 450ms multi-click, draggable pane dividers, scrollbar thumb dragging, inline clickable links), and Korean 2-beolsik IME command-key normalization (ㅂ→q, ㅊ→c, ㄱ→r, ㅐ→o).
UTF-16 Safe Editing Engine Reads multi-tab Google Docs as clean Markdown (compact by default at 8,000 chars) and performs surgical section replacement (--section), unique plain-text find/replace (--find/--replace, strictly enforcing match_count == 1), and appends using exact UTF-16 code-unit offsets, optimistic revisionId locks, and --dry-run unified diffs.
4-in-1 Agent & Local Interface Offline SQLite WAL + FTS5 cache (with 1–2 char Korean/CJK LIKE fallback), scriptable --json CLI with direct URL shortcut (gdocs <url-or-id> -j), hardened local HTTP JSON API (gdocs serve, default 127.0.0.1:8794), and stdio MCP server (gdocs mcp, 10 typed tools with --read-only guard).

Quick Start

# 1. Install the native prebuilt binary (Windows / macOS / Linux — x64 & arm64)
npm i -g @bitefoundry/gdocs
# or via Homebrew (macOS & Linux):
brew install bitefoundry/tap/gdocs

# 2. Read any public Google Doc or Drive .txt/.md file immediately — ZERO login required!
#    Opens directly in the editorial TUI in a terminal, or prints Markdown when piped / JSON with -j
gdocs "https://docs.google.com/document/d/<PUBLIC_DOC_ID>/edit"
gdocs "https://drive.google.com/file/d/<PUBLIC_FILE_ID>/view?usp=drive_link"
gdocs "https://docs.google.com/document/d/<PUBLIC_DOC_ID>/edit" -j

# 3. Or explore the built-in offline demo workspace
gdocs --demo
gdocs --demo list -j

# 4. Sign in for private docs, Drive listing, comments & editing
gdocs login --oauth-file auto          # auto-finds newest client_secret_*.json in Downloads
# or: gdocs login --adc
gdocs

Or run the containerized MCP server via GHCR (linux/amd64 & linux/arm64) or build from source with Cargo:

docker run -i --rm ghcr.io/bitefoundry/gdocs:latest mcp --read-only
cargo install --git https://github.com/BiteFoundry/google gdocs-cli --locked

Authentication Modes

Public shared Google Docs ("Anyone with the link can view") work out of the box with zero login across gdocs <url>, gdocs get, gdocs sections, and gdocs mcp (pass --public to force public export even when signed in).

For private documents, Drive listing, comments, and edits, gdocs supports four authentication configurations with multi-account profile switching via --account <NAME>:

# 1. Google Cloud Console OAuth Desktop JSON (auto-discovers newest client_secret_*.json in Downloads)
gdocs login --oauth-file auto
gdocs login --oauth-file /path/to/client_secret_xxx.json

#    Or pass client ID/secret explicitly (BYO OAuth 2.0 PKCE)
gdocs login --oauth --client-id "<OAUTH_CLIENT_ID>" [--client-secret "<SECRET>"]

# 2. Read-only scopes (restricts token grant to Docs & Drive read-only)
gdocs login --oauth-file auto --readonly
# or enforce read-only at runtime across CLI, HTTP API, and MCP:
gdocs --read-only list -j

# 3. gcloud Application Default Credentials (reuses existing gcloud ADC session)
gdocs login --adc [--adc-path /path/to/application_default_credentials.json]

# 4. Google Cloud Service Account JSON key
gdocs login --service-account /path/to/service-account.json

Inspect active account and local cache health at any time:

gdocs whoami -j
gdocs doctor -j

CLI Reference

Global Flags

Every command accepts these global flags (plus --tui when passing a direct DOC_URL_OR_ID shortcut):

Flag Description
--account <NAME> Named Google account profile from config.toml.
--demo Run offline with built-in demo documents (no Google credentials required).
--public Force zero-login public shared-link export (ignores configured accounts).
--theme <NAME> Preferred TUI or print theme (e.g. editorial-auto, editorial-light, editorial-dark).
-j, --json Emit structured JSON output.
--read-only Block all mutating operations across CLI, HTTP API, MCP, and TUI $EDITOR.
-p, --print Render document as styled ANSI text to stdout without entering the TUI (honors NO_COLOR).
--pager Pipe styled ANSI document output through $PAGER (implies --print).
--no-nerd-fonts Use strictly 7-bit ASCII icons instead of Unicode symbols (also BITEFOUNDRY_ASCII=1 or TERM=dumb).

Subcommands

Command Summary
login Authenticate a Google Workspace account (OAuth PKCE / --oauth-file, --adc, or --service-account).
whoami Show active account profile, scopes, and credential status.
doctor Diagnose configuration, token storage, and SQLite WAL cache health (--probe for live check).
get Read a Google Doc as Markdown (compact 8,000-char default, --full, --tab, --section, -p).
sections List heading sections (H1–H6) with exact UTF-16 spans.
list List recent Google Docs from Drive (--folder, --shared-with-me, --query, --limit).
search Search cached docs locally (FTS5 + Korean/CJK LIKE) or remotely on Drive (--remote).
comments Read (comments list) or add (comments add) comments on a Google Doc.
create Create a new Google Doc with optional --parent folder and --markdown / --file body.
append Safely append Markdown to a Google Doc (--tab, --prev-revision-id, --dry-run).
edit Safely replace a unique heading section (--section) or unique text (--find/--replace) with --dry-run.
serve Start the local HTTP JSON API server (default 127.0.0.1:8794).
mcp Run the JSON-RPC 2.0 stdio MCP server exposing 10 Google Docs tools.
update Check for (--check) or apply verified GitHub Release self-updates (--force).
# Direct URL / ID shortcut (opens editorial TUI on a TTY, prints Markdown when piped, or JSON with -j)
gdocs "https://docs.google.com/document/d/<DOC_ID>/edit?tab=t.0"
gdocs "https://docs.google.com/document/d/<DOC_ID>/edit?tab=t.0" -j
gdocs --public "https://docs.google.com/document/d/<PUBLIC_DOC_ID>/edit" --tui

# Non-interactive styled ANSI print & pager mode (zero ESC bytes when piped or NO_COLOR=1)
gdocs --demo -p
gdocs get <DOC_URL_OR_ID> --pager --no-nerd-fonts

# Read document or isolate a single tab / heading section
gdocs get <DOC_URL_OR_ID> [--tab <TAB>] [--section "<HEADING>"] [--full] [--max-chars 8000]

# Inspect H1–H6 heading outline with exact UTF-16 spans
gdocs sections <DOC_URL_OR_ID> [--tab <TAB>] -j

# List & search documents (local SQLite FTS5 + Korean/CJK, or --remote Drive search)
gdocs list [--folder <FOLDER_ID>] [--shared-with-me] [--query "<Q>"] [--limit 20] -j
gdocs search "<QUERY>" [--remote] [--limit 20] -j

# Read and add document comments
gdocs comments list <DOC_URL_OR_ID> [--unresolved] -j
gdocs comments add <DOC_URL_OR_ID> "LGTM — ready to ship" [--quote "<ANCHOR_TEXT>"] -j

# Create, append, and surgically edit documents (supports --dry-run & optimistic --prev-revision-id)
gdocs create "Q4 Architecture RFC" [--parent <FOLDER_ID>] [--markdown "# Overview"] [--file draft.md]
gdocs append <DOC_URL_OR_ID> --markdown "## Next Steps" [--tab <TAB>] [--dry-run]
gdocs edit <DOC_URL_OR_ID> --section "Timeline" --file timeline.md [--dry-run]
gdocs edit <DOC_URL_OR_ID> --find "Draft v1" --replace "Final v1" [--dry-run]

# Local HTTP JSON API, stdio MCP server, and verified GitHub Release self-updater
gdocs serve [--bind 127.0.0.1] [--port 8794] [--token "$TOKEN"] [--read-only]
gdocs mcp [--read-only] [--max-output-chars 32000]
gdocs update [--check] [--force]

MCP Server (gdocs mcp)

Add gdocs to Claude Desktop, Cursor, Windsurf, or any MCP-compatible host:

{
  "mcpServers": {
    "gdocs": {
      "command": "gdocs",
      "args": ["mcp"]
    }
  }
}

Pass "args": ["mcp", "--read-only"] to block all write tools with isError: true. See docs/MCP.md for full parameter schemas and safety guarantees.

10 Built-in MCP Tools

Tool Kind Purpose
get_doc Read Read a Google Doc as Markdown with tabs, sections, and links (compact 8,000-char default, full: true for complete text).
list_doc_sections Read List H1–H6 heading outline with exact UTF-16 start/end offsets for a document tab.
list_docs Read List recent Google Docs from Drive with optional folder_id, shared_with_me, query, and limit filters.
search_docs Read Search cached docs locally via SQLite FTS5 + Korean/CJK LIKE fallback, or remotely via Drive (remote: true).
list_doc_comments Read List comment threads (quotes, authors, replies) with optional unresolved_only: true.
gdocs_status Read Return active account profile, granted scopes, read_only state, and local SQLite cache counts.
create_doc Write Create a new Google Doc with optional parent_id folder and initial markdown body.
append_doc_markdown Write Safely append Markdown to a tab with UTF-16 indexing, optional prev_revision_id lock, and dry_run unified diff.
replace_doc_section Write Replace the body of a uniquely matched heading section (match_count == 1) with optional dry_run diff.
replace_doc_text Write Replace a single exact plain-text occurrence (match_count == 1 strictly enforced) with optional dry_run diff.

Local HTTP JSON API (gdocs serve)

Default bind: 127.0.0.1:8794. Without --token, gdocs serve generates a random per-session Bearer token on stderr (pass --allow-keyless on loopback only; non-loopback binds always require --token). DNS rebinding (Host check) and foreign browser Origin / Sec-Fetch-Site: cross-site requests are rejected with 403.

gdocs serve --bind 127.0.0.1 --port 8794 --token "$GDOCS_TOKEN"

curl "http://127.0.0.1:8794/health"
curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs?limit=10"
curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>?full=true"
curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/sections"
curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/comments"
curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/search?q=Architecture"
curl -X POST -H "Authorization: Bearer $GDOCS_TOKEN" -H "Content-Type: application/json" \
  -d '{"markdown":"## Summary\nReady.","dry_run":true}' \
  "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/append"

Editorial TUI Keybindings & Mouse

All keybindings are defined in a single ActionRegistry (GDOCS_ACTIONS) shared across the bottom hint bar, Ctrl+K Command Palette, ? Help overlay, and contextual which-key leader popups.

Input Action
j / k · ↑ / ↓ Scroll active pane or move selection
J / K Scroll reader preview down / up (±3 lines) while focused on Docs or Outline
Ctrl+D / Ctrl+U Scroll reader half-page down / up
G Jump to bottom of active pane
Tab / Shift+Tab Cycle focus (Docs → Outline → Reader → Comments)
g d / g o / g r / g c / g g which-key Go chords: focus Documents, Outline, Reader, Comments, or jump to top
y l / y m / y i which-key Yank chords: copy document URL, Markdown, or document ID (Clipboard + OSC 52)
[ / ] Switch previous / next Google Doc tab
Enter Open selected document or jump to outline heading
z Toggle focused pane zoom (Esc unzooms)
e Edit active document in $EDITOR (gated by --read-only; remote push requires Shift+Y confirmation)
c Toggle Comments sidebar
/ or Ctrl+F Search documents (FTS5 + Korean/CJK)
Ctrl+K Open Command Palette
Ctrl+T Open live Theme Picker (16 presets + OSC 11 editorial-auto)
r Refresh document list and active document
o Open active document in browser
0 Reset dragged pane widths
? / q / Esc Help overlay / Quit or close modal / Cancel leader or unzoom
Click Select doc, outline heading, tab pill, or inline link
Drag Reader Select text & copy via Clipboard + OSC 52
Drag Divider Resize panes (double-click divider to reset)
Alt+M Toggle mouse capture for native terminal selection
한글 두벌식 IME Command-mode shortcuts normalize automatically (ㅋ→z, ㅎ→g, ㅛ→y, ㄷ→e, ㅂ→q, ㅊ→c, ㄱ→r, ㅐ→o, plus shifted Shift+ㅓ→J, Shift+ㅏ→K, Shift+ㅛ→Y)

Cargo Workspace Architecture & Roadmap

This repository is structured as a unidirectional Cargo workspace sharing google-core across upcoming Google Workspace terminal tools (see docs/design.md for architecture diagrams, tradeoffs, security model, and terminal compatibility details):

google-core  <──  gdocs-core  <──  gdocs-tui  <──  gdocs-cli   (@bitefoundry/gdocs  — live)
             <──  gsheets-core / gsheets-tui / gsheets-cli      (@bitefoundry/gsheets — planned)
             <──  gdrive-core  / gdrive-tui  / gdrive-cli       (@bitefoundry/gdrive  — planned)

Disclaimer: Unofficial terminal client for Google Docs and Google Drive. Not affiliated with, endorsed by, or sponsored by Google LLC.

Releases

Packages

Contributors

Languages