@bitefoundry/gdocs 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +204 -2
  3. package/bin/gdocs.js +125 -0
  4. package/package.json +35 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BiteFoundry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,205 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # `@bitefoundry/gdocs`
4
+
5
+ **Fast Google Docs terminal client & AI agent toolkit — RTT-style editorial TUI, scriptable CLI, local HTTP JSON API, and stdio MCP server.**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/%40bitefoundry%2Fgdocs?style=flat-square&color=1A73E8)](https://www.npmjs.com/package/@bitefoundry/gdocs)
8
+ [![platforms](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-24292F?style=flat-square)](https://github.com/BiteFoundry/google/releases/latest)
9
+ [![Rust & Ratatui](https://img.shields.io/badge/built%20with-Rust%20%2B%20Ratatui-DEA584?style=flat-square&logo=rust)](https://github.com/BiteFoundry/google/blob/master/Cargo.toml)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-00875A?style=flat-square)](LICENSE)
11
+
12
+ [BiteFoundry](https://bitefoundry.dev) · [Latest Release](https://github.com/BiteFoundry/google/releases/latest)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ ## Highlights
19
+
20
+ | Pillar | Capabilities |
21
+ | :--- | :--- |
22
+ | **4-Mode Google Auth** | Authenticate via **BYO OAuth 2.0 PKCE** (`--oauth`), **Read-Only Docs/Drive scopes** (`--readonly`), **gcloud Application Default Credentials** (`--adc`), or **Service Account JSON key** (`--service-account`). Tokens are stored in the OS keyring with `0600` encrypted-dir fallback; corporate root CAs are supported via `--ca-cert`. |
23
+ | **RTT-Style Editorial TUI** | Calm 4-step contrast ladder (`bitefoundry-theme`) with **pre-raw-mode OSC 11 terminal brightness auto-detection** (`editorial-auto`, `editorial-light`, `editorial-dark`, and **16 live-preview presets** via `Ctrl+T`), single rounded hairline frame with border-embedded tabs & hints, transparent hairline scrollbars, full mouse support (**drag text selection + OSC 52 / clipboard copy**, **`Alt+M`** mouse capture toggle, 450ms multi-click, draggable pane dividers with double-click reset, scrollbar thumb dragging, inline clickable links), and **Korean 2-beolsik IME** command-key normalization (`ㅂ→q`, `ㅊ→c`). |
24
+ | **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. |
25
+ | **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). |
26
+
27
+ ---
28
+
29
+ ## Quick Start
30
+
31
+ ```bash
32
+ # 1. Install the native prebuilt binary (Windows / macOS / Linux — x64 & arm64)
33
+ npm i -g @bitefoundry/gdocs
34
+
35
+ # 2. Try the full offline editorial TUI & CLI immediately (no Google credentials required)
36
+ gdocs --demo
37
+ gdocs --demo list -j
38
+
39
+ # 3. Or authenticate with your Google Workspace account
40
+ gdocs login --adc
41
+ gdocs
42
+ ```
43
+
44
+ Or build from source with Cargo:
45
+
46
+ ```bash
47
+ cargo install --git https://github.com/BiteFoundry/google gdocs-cli --locked
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Authentication Modes
53
+
54
+ `gdocs` supports four authentication configurations, with multi-account profile switching via `--account <NAME>`:
55
+
56
+ ```bash
57
+ # 1. BYO OAuth 2.0 PKCE (browser loopback callback)
58
+ gdocs login --oauth --client-id "<OAUTH_CLIENT_ID>" [--client-secret "<SECRET>"]
59
+
60
+ # 2. Read-only scopes (restricts token grant to Docs & Drive read-only)
61
+ gdocs login --oauth --client-id "<OAUTH_CLIENT_ID>" --readonly
62
+ # or enforce read-only at runtime across CLI, HTTP API, and MCP:
63
+ gdocs --read-only list -j
64
+
65
+ # 3. gcloud Application Default Credentials (reuses existing gcloud ADC session)
66
+ gdocs login --adc [--adc-path /path/to/application_default_credentials.json]
67
+
68
+ # 4. Google Cloud Service Account JSON key
69
+ gdocs login --service-account /path/to/service-account.json
70
+ ```
71
+
72
+ Inspect active account and local cache health at any time:
73
+
74
+ ```bash
75
+ gdocs whoami -j
76
+ gdocs doctor -j
77
+ ```
78
+
79
+ ---
80
+
81
+ ## CLI Reference
82
+
83
+ Every command supports `-j` / `--json`, `--account <NAME>`, `--demo`, and `--read-only`.
84
+
85
+ ```bash
86
+ # Direct URL / ID shortcut (reads compact Markdown; add -j for JSON)
87
+ gdocs "https://docs.google.com/document/d/<DOC_ID>/edit?tab=t.0" -j
88
+
89
+ # Read document or isolate a single tab / heading section
90
+ gdocs get <DOC_URL_OR_ID> [--tab <TAB>] [--section "<HEADING>"] [--full] [--max-chars 8000]
91
+
92
+ # Inspect H1–H6 heading outline with exact UTF-16 spans
93
+ gdocs sections <DOC_URL_OR_ID> [--tab <TAB>] -j
94
+
95
+ # List & search documents (local SQLite FTS5 + Korean/CJK, or --remote Drive search)
96
+ gdocs list [--folder <FOLDER_ID>] [--shared-with-me] [--query "<Q>"] [--limit 20] -j
97
+ gdocs search "<QUERY>" [--remote] [--limit 20] -j
98
+
99
+ # Read and add document comments
100
+ gdocs comments list <DOC_URL_OR_ID> [--unresolved] -j
101
+ gdocs comments add <DOC_URL_OR_ID> "LGTM — ready to ship" [--quote "<ANCHOR_TEXT>"] -j
102
+
103
+ # Create, append, and surgically edit documents (supports --dry-run & optimistic --prev-revision-id)
104
+ gdocs create "Q4 Architecture RFC" [--parent <FOLDER_ID>] [--markdown "# Overview"] [--file draft.md]
105
+ gdocs append <DOC_URL_OR_ID> --markdown "## Next Steps" [--tab <TAB>] [--dry-run]
106
+ gdocs edit <DOC_URL_OR_ID> --section "Timeline" --file timeline.md [--dry-run]
107
+ gdocs edit <DOC_URL_OR_ID> --find "Draft v1" --replace "Final v1" [--dry-run]
108
+
109
+ # Local HTTP JSON API, stdio MCP server, and verified GitHub Release self-updater
110
+ gdocs serve [--bind 127.0.0.1] [--port 8794] [--token "$TOKEN"] [--read-only]
111
+ gdocs mcp [--read-only] [--max-output-chars 24000]
112
+ gdocs update [--check] [--force]
113
+ ```
114
+
115
+ ---
116
+
117
+ ## MCP Server (`gdocs mcp`)
118
+
119
+ Add `gdocs` to Claude Desktop, Cursor, Windsurf, or any MCP-compatible host:
120
+
121
+ ```json
122
+ {
123
+ "mcpServers": {
124
+ "gdocs": {
125
+ "command": "gdocs",
126
+ "args": ["mcp"]
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ Pass `"args": ["mcp", "--read-only"]` to block all write tools with `isError: true`.
133
+
134
+ ### 10 Built-in MCP Tools
135
+
136
+ | Tool | Kind | Purpose |
137
+ | :--- | :--- | :--- |
138
+ | `get_doc` | Read | Read a Google Doc as Markdown with tabs, sections, and links (compact 8,000-char default, `full: true` for complete text). |
139
+ | `list_doc_sections` | Read | List H1–H6 heading outline with exact UTF-16 start/end offsets for a document tab. |
140
+ | `list_docs` | Read | List recent Google Docs from Drive with optional `folder_id`, `shared_with_me`, `query`, and `limit` filters. |
141
+ | `search_docs` | Read | Search cached docs locally via SQLite FTS5 + Korean/CJK `LIKE` fallback, or remotely via Drive (`remote: true`). |
142
+ | `list_doc_comments` | Read | List comment threads (quotes, authors, replies) with optional `unresolved_only: true`. |
143
+ | `gdocs_status` | Read | Return active account profile, granted scopes, `read_only` state, and local SQLite cache counts. |
144
+ | `create_doc` | Write | Create a new Google Doc with optional `parent_id` folder and initial `markdown` body. |
145
+ | `append_doc_markdown` | Write | Safely append Markdown to a tab with UTF-16 indexing, optional `prev_revision_id` lock, and `dry_run` unified diff. |
146
+ | `replace_doc_section` | Write | Replace the body of a uniquely matched heading section (`match_count == 1`) with optional `dry_run` diff. |
147
+ | `replace_doc_text` | Write | Replace a single exact plain-text occurrence (`match_count == 1` strictly enforced) with optional `dry_run` diff. |
148
+
149
+ ---
150
+
151
+ ## Local HTTP JSON API (`gdocs serve`)
152
+
153
+ 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`.
154
+
155
+ ```bash
156
+ gdocs serve --bind 127.0.0.1 --port 8794 --token "$GDOCS_TOKEN"
157
+
158
+ curl "http://127.0.0.1:8794/health"
159
+ curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs?limit=10"
160
+ curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>?full=true"
161
+ curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/sections"
162
+ curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/comments"
163
+ curl -H "Authorization: Bearer $GDOCS_TOKEN" "http://127.0.0.1:8794/api/v1/search?q=Architecture"
164
+ curl -X POST -H "Authorization: Bearer $GDOCS_TOKEN" -H "Content-Type: application/json" \
165
+ -d '{"markdown":"## Summary\nReady.","dry_run":true}' \
166
+ "http://127.0.0.1:8794/api/v1/docs/<DOC_ID>/append"
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Editorial TUI Keybindings & Mouse
172
+
173
+ | Input | Action |
174
+ | :--- | :--- |
175
+ | `j` / `k` · `↑` / `↓` | Scroll active pane or move selection |
176
+ | `Tab` / `Shift+Tab` | Cycle focus (`Docs` → `Outline` → `Reader` → `Comments`) |
177
+ | `[` / `]` | Switch previous / next Google Doc tab |
178
+ | `Enter` | Open selected document or jump to outline heading |
179
+ | `c` | Toggle Comments sidebar |
180
+ | `/` or `Ctrl+F` | Search documents (FTS5 + Korean/CJK) |
181
+ | `Ctrl+K` | Open Command Palette |
182
+ | `Ctrl+T` | Open live Theme Picker (16 presets + OSC 11 `editorial-auto`) |
183
+ | `o` | Open active document in browser |
184
+ | `0` | Reset dragged pane widths |
185
+ | `?` / `q` / `Esc` | Help overlay / Close modal or quit |
186
+ | **Click** | Select doc, outline heading, tab pill, or inline link |
187
+ | **Drag Reader** | Select text & copy via Clipboard + OSC 52 |
188
+ | **Drag Divider** | Resize panes (double-click divider to reset) |
189
+ | `Alt+M` | Toggle mouse capture for native terminal selection |
190
+
191
+ ---
192
+
193
+ ## Cargo Workspace Architecture & Roadmap
194
+
195
+ This repository is structured as a unidirectional Cargo workspace sharing `google-core` across upcoming Google Workspace terminal tools:
196
+
197
+ ```text
198
+ google-core <── gdocs-core <── gdocs-tui <── gdocs-cli (@bitefoundry/gdocs — v0.1.0, live)
199
+ <── gsheets-core / gsheets-tui / gsheets-cli (@bitefoundry/gsheets — planned)
200
+ <── gdrive-core / gdrive-tui / gdrive-cli (@bitefoundry/gdrive — planned)
201
+ ```
202
+
203
+ ---
204
+
205
+ > **Disclaimer:** Unofficial terminal client for Google Docs and Google Drive. Not affiliated with, endorsed by, or sponsored by Google LLC.
package/bin/gdocs.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('node:fs');
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+ const { spawn } = require('node:child_process');
8
+
9
+ const SUPPORTED = [
10
+ 'win32-x64',
11
+ 'win32-arm64',
12
+ 'darwin-x64',
13
+ 'darwin-arm64',
14
+ 'linux-x64',
15
+ 'linux-arm64',
16
+ ];
17
+
18
+ function fail(message) {
19
+ process.stderr.write(`gdocs: ${message}\n`);
20
+ process.exit(1);
21
+ }
22
+
23
+ function formatLinuxGlibcHint() {
24
+ return [
25
+ 'Prebuilt Linux binaries target GLIBC >= 2.28 (Ubuntu 20.04+ / Debian 10+ / RHEL 8+).',
26
+ 'If you are on an older glibc distribution or Alpine/musl, build from source with Cargo:',
27
+ ' cargo install --git https://github.com/BiteFoundry/google gdocs-cli --locked',
28
+ 'or clone the repository and run:',
29
+ ' cargo build --release -p gdocs-cli',
30
+ ].join('\n');
31
+ }
32
+
33
+ const platform = process.platform;
34
+ const arch = process.arch;
35
+ const platformKey = `${platform}-${arch}`;
36
+ const packageName = `@bitefoundry/gdocs-${platformKey}`;
37
+ const binaryName = platform === 'win32' ? 'gdocs.exe' : 'gdocs';
38
+
39
+ let packageDir = null;
40
+ try {
41
+ packageDir = path.dirname(require.resolve(`${packageName}/package.json`));
42
+ } catch {
43
+ packageDir = null;
44
+ }
45
+
46
+ const binaryPath = packageDir ? path.join(packageDir, 'bin', binaryName) : null;
47
+
48
+ if (!binaryPath || !fs.existsSync(binaryPath)) {
49
+ const lines = [
50
+ `no prebuilt binary found for ${platformKey}.`,
51
+ '',
52
+ `Expected the optional dependency "${packageName}" to provide:`,
53
+ ` ${binaryPath || `node_modules/${packageName}/bin/${binaryName}`}`,
54
+ '',
55
+ `Supported platforms: ${SUPPORTED.join(', ')}`,
56
+ '',
57
+ 'Try one of:',
58
+ ' npm install -g @bitefoundry/gdocs --include=optional',
59
+ ' npm install @bitefoundry/gdocs --include=optional',
60
+ ' npx --yes @bitefoundry/gdocs',
61
+ '',
62
+ 'Or build from source with Cargo:',
63
+ ' cargo build --release -p gdocs-cli',
64
+ ];
65
+ fail(lines.join('\n'));
66
+ }
67
+
68
+ if (platform !== 'win32') {
69
+ try {
70
+ fs.accessSync(binaryPath, fs.constants.X_OK);
71
+ } catch {
72
+ try {
73
+ fs.chmodSync(binaryPath, 0o755);
74
+ } catch {
75
+ // Read-only install; spawn will report EACCES if needed.
76
+ }
77
+ }
78
+ }
79
+
80
+ const child = spawn(binaryPath, process.argv.slice(2), {
81
+ stdio: 'inherit',
82
+ windowsHide: false,
83
+ });
84
+
85
+ child.on('error', (err) => {
86
+ if (
87
+ platform === 'linux' &&
88
+ (err.code === 'ENOENT' || /GLIBC_/i.test(String(err.message || '')))
89
+ ) {
90
+ fail(
91
+ `failed to launch ${binaryPath}: ${err.message}\n\n${formatLinuxGlibcHint()}`,
92
+ );
93
+ }
94
+ fail(`failed to launch ${binaryPath}: ${err.message}`);
95
+ });
96
+
97
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
98
+ const handler = () => {
99
+ if (!child.killed) {
100
+ try {
101
+ child.kill(signal);
102
+ } catch {
103
+ // Child already exited.
104
+ }
105
+ }
106
+ };
107
+ try {
108
+ process.on(signal, handler);
109
+ } catch {
110
+ // Signal unsupported on this platform.
111
+ }
112
+ }
113
+
114
+ child.on('exit', (code, signal) => {
115
+ if (signal) {
116
+ const number = os.constants.signals[signal] || 1;
117
+ process.exit(128 + number);
118
+ }
119
+ if (platform === 'linux' && code === 127) {
120
+ process.stderr.write(
121
+ `gdocs: binary exited with code 127 (missing shared library, dynamic linker, or GLIBC symbol version).\n${formatLinuxGlibcHint()}\n`,
122
+ );
123
+ }
124
+ process.exit(code === null ? 1 : code);
125
+ });
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@bitefoundry/gdocs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "mcpName": "io.github.BiteFoundry/gdocs",
5
+ "description": "Fast Google Docs terminal client & AI agent toolkit (CLI, TUI, HTTP API, MCP)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/BiteFoundry/google.git",
9
+ "directory": "npm/gdocs"
10
+ },
11
+ "license": "MIT",
12
+ "bin": {
13
+ "gdocs": "bin/gdocs.js"
14
+ },
15
+ "files": [
16
+ "bin/gdocs.js"
17
+ ],
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "keywords": [
22
+ "google-docs",
23
+ "gdocs",
24
+ "google-workspace",
25
+ "cli",
26
+ "tui",
27
+ "mcp"
28
+ ],
29
+ "optionalDependencies": {
30
+ "@bitefoundry/gdocs-win32-x64": "0.1.1",
31
+ "@bitefoundry/gdocs-win32-arm64": "0.1.1",
32
+ "@bitefoundry/gdocs-darwin-x64": "0.1.1",
33
+ "@bitefoundry/gdocs-darwin-arm64": "0.1.1",
34
+ "@bitefoundry/gdocs-linux-x64": "0.1.1",
35
+ "@bitefoundry/gdocs-linux-arm64": "0.1.1"
36
+ }
37
+ }