@vocoder/cli 0.1.4 → 0.1.7

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vocoder/cli
2
2
 
3
- Command-line tool for Vocoder. Handles project setup, string extraction from source code, and translation synchronization.
3
+ Command-line tool for Vocoder. Handles project setup, string extraction, and translation sync.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,59 +18,169 @@ npx vocoder <command>
18
18
 
19
19
  ### `vocoder init`
20
20
 
21
- Connect your repository to Vocoder.
21
+ Connect your repository to Vocoder. Runs a full TUI-based onboarding flow — authentication, workspace selection, GitHub connection, and project configuration all happen in the terminal. A browser is opened only for steps that require OAuth (sign-in, GitHub App install).
22
22
 
23
23
  ```bash
24
24
  vocoder init
25
25
  ```
26
26
 
27
- The command detects your git remote and checks if a Vocoder project already exists for the repository. If found, it confirms the connection and prints next steps. If not, it opens a browser-based setup flow to create a new project.
27
+ **Fast path:** If the current repository's remote is already linked to a Vocoder project, `init` detects it and prints the scaffold instructions immediately no prompts, no browser.
28
+
29
+ **Full flow:**
30
+
31
+ ```
32
+ ◆ Vocoder Setup
33
+
34
+ ● Open the link below to sign in or create your account:
35
+ ◇ Authentication URL ──────────────────────────────────────╮
36
+ │ │
37
+ │ https://vocoder.app/auth/cli?session=<token> │
38
+ │ │
39
+ ├────────────────────────────────────────────────────────────
40
+
41
+ ◆ Open in your browser? › Yes
42
+
43
+ ◒ Waiting for authentication...
44
+ ◇ Authenticated as eric@example.com
45
+
46
+ ◒ Loading workspaces...
47
+ ◆ Select workspace
48
+ │ ● My Workspace (2 projects)
49
+ │ ○ Create new workspace
50
+
51
+
52
+ ◇ Workspace: My Workspace
53
+
54
+ ◆ Project name › my-app
55
+ ◆ Source language (type to search) › en → English — en
56
+ ◆ Target languages (type to search) › es → Spanish — es
57
+ ◆ Target branches (comma-separated) › main
58
+
59
+ ◒ Creating project...
60
+
61
+ ◆ Step 1: Add the plugin to vite.config.ts
62
+ │ ...
63
+ ◆ Step 2: Add the provider to App.tsx
64
+ │ ...
65
+ ◆ Step 3: Wrap translatable strings
66
+
67
+ ◆ Use Vocoder with Claude Code
68
+ │ claude mcp add --scope project --transport stdio \
69
+ │ --env VOCODER_API_KEY=vc_xxxx \
70
+ │ vocoder -- npx -y @vocoder/mcp
71
+
72
+ ◆ You're all set.
73
+ ```
74
+
75
+ **Returning user (stored token, existing workspace):**
76
+
77
+ No browser opens. The stored auth token is verified, workspaces are listed, and the flow continues directly in the terminal.
78
+
79
+ ```
80
+ ◆ Vocoder Setup
81
+
82
+ ◒ Checking authentication...
83
+ ◇ Authenticated as eric@example.com
84
+
85
+ ◒ Loading workspaces...
86
+ ◆ Select workspace
87
+ │ ● My Workspace (2 projects)
88
+ │ ○ Create new workspace
89
+
90
+ ```
91
+
92
+ **New workspace (GitHub App install):**
93
+
94
+ If creating a new workspace, a second browser step installs the GitHub App. The CLI opens the install URL and waits for the browser to redirect back to a local callback server.
95
+
96
+ ```
97
+ ◆ Connect your new workspace to GitHub
98
+ │ ● Install the Vocoder GitHub App
99
+ │ ○ Link an existing installation
100
+
101
+
102
+ ○ Opening GitHub to install the Vocoder App...
103
+ Complete the installation in your browser.
104
+
105
+ ◇ Connected to GitHub as itsmoops
106
+ ```
28
107
 
29
108
  **Options:**
30
109
 
31
110
  | Flag | Description |
32
111
  |---|---|
33
- | `--api-url <url>` | Override Vocoder API URL |
34
- | `--yes` | Skip confirmation prompts |
35
- | `--project-name <name>` | Pre-fill project name |
36
- | `--source-locale <locale>` | Pre-fill source locale |
37
- | `--target-locales <list>` | Comma-separated target locales (e.g., `es,fr,de`) |
112
+ | `--yes` | Skip "Open in your browser?" confirmation |
113
+ | `--ci` | Non-interactive mode. Prints the auth URL as `VOCODER_AUTH_URL: <url>` on its own line to stdout — no browser opens, no interactive prompts, no local callback server. The CLI polls `GET /api/cli/auth/session` every 2 seconds until the browser completes authentication. Intended for automated test harnesses that drive the browser step externally. |
114
+
115
+ **Auth storage:**
116
+
117
+ After sign-in, the CLI stores a persistent auth token at `~/.config/vocoder/auth.json` (mode `0600`). The file contains:
118
+
119
+ ```json
120
+ {
121
+ "token": "vcu_...",
122
+ "apiUrl": "https://vocoder.app",
123
+ "userId": "...",
124
+ "email": "user@example.com",
125
+ "name": "User Name",
126
+ "createdAt": "2026-04-25T12:00:00.000Z"
127
+ }
128
+ ```
129
+
130
+ Tokens never expire. Use `vocoder logout` to revoke.
131
+
132
+ **Token priority:**
133
+
134
+ | Command | Token source |
135
+ |---|---|
136
+ | `vocoder init` | `VOCODER_AUTH_TOKEN` env var → `~/.config/vocoder/auth.json` |
137
+ | `vocoder sync` | `VOCODER_API_KEY` env var → `.env` file |
138
+ | MCP tools | `VOCODER_API_KEY` env var |
139
+
140
+ ---
38
141
 
39
142
  ### `vocoder sync`
40
143
 
41
- Extract translatable strings from your source code and push them to Vocoder for translation.
144
+ Submit extracted strings for translation and retrieve results.
42
145
 
43
146
  ```bash
44
147
  vocoder sync
45
148
  ```
46
149
 
47
- This command:
48
-
49
- 1. Detects the current git branch and repository
50
- 2. Scans your source files for `<T>` components and `t()` calls
51
- 3. Extracts the source text, file location, and any context/formality hints
52
- 4. Sends the extracted strings to the Vocoder API
53
- 5. Optionally waits for translations to complete (based on sync mode)
150
+ Reads `VOCODER_API_KEY` from environment or `.env`. Extracts `<T>` and `t()` usages from source files, submits them to Vocoder, and polls until translations are returned. Writes locale JSON files to the configured output path.
54
151
 
55
152
  **Options:**
56
153
 
57
154
  | Flag | Description |
58
155
  |---|---|
59
- | `--branch <name>` | Override branch detection |
60
- | `--include <pattern>` | Glob pattern(s) to include (repeatable) |
61
- | `--exclude <pattern>` | Glob pattern(s) to exclude (repeatable) |
62
- | `--force` | Sync even if not on a target branch |
63
- | `--mode <mode>` | Sync mode: `auto`, `required`, or `best-effort` |
64
- | `--max-wait-ms <ms>` | Max wait time before fallback (milliseconds) |
65
- | `--no-fallback` | Fail instead of falling back to cached translations |
66
- | `--dry-run` | Show what would be synced without sending |
67
- | `--verbose` | Show detailed progress |
156
+ | `--locale <code>` | Sync only this target locale |
157
+ | `--dry-run` | Show what would be synced without submitting |
158
+ | `--verbose` | Show extraction and sync details |
159
+
160
+ ---
161
+
162
+ ### `vocoder logout`
163
+
164
+ Revoke the stored auth token and clear `~/.config/vocoder/auth.json`.
165
+
166
+ ```bash
167
+ vocoder logout
168
+ ```
169
+
170
+ Also revokes the token server-side so it can no longer be used for API calls.
171
+
172
+ ---
173
+
174
+ ### `vocoder whoami`
68
175
 
69
- #### Sync Modes
176
+ Print the currently authenticated user.
70
177
 
71
- - **`auto`** (default) -- Checks the project's sync policy. Blocking branches (e.g., `main`, `production`) use `required` mode; other branches use `best-effort`.
72
- - **`required`** -- Waits for translations to complete before finishing. Fails if translations can't be completed within the timeout.
73
- - **`best-effort`** -- Sends strings for translation but doesn't wait. Falls back to the latest available translations.
178
+ ```bash
179
+ vocoder whoami
180
+ # Authenticated as eric@example.com (My Workspace)
181
+ ```
182
+
183
+ ---
74
184
 
75
185
  ### `vocoder wrap`
76
186
 
@@ -80,7 +190,7 @@ Automatically wrap string literals in your source code with `<T>` and `t()`.
80
190
  vocoder wrap
81
191
  ```
82
192
 
83
- Scans your JSX/TSX files for user-facing string literals and wraps them with the appropriate Vocoder translation markers. Uses AST analysis to detect strings that are likely user-facing (not keys, classnames, or internal identifiers).
193
+ Scans JSX/TSX files for user-facing string literals and wraps them with the appropriate translation markers. Uses AST analysis to detect strings that are likely user-facing (not keys, classnames, or internal identifiers).
84
194
 
85
195
  **Options:**
86
196
 
@@ -93,29 +203,35 @@ Scans your JSX/TSX files for user-facing string literals and wraps them with the
93
203
  | `--confidence <level>` | Minimum confidence: `high`, `medium`, `low` (default: `high`) |
94
204
  | `--verbose` | Detailed output |
95
205
 
96
- ## Environment Variables
206
+ ---
97
207
 
98
- | Variable | Required | Description |
99
- |---|---|---|
100
- | `VOCODER_API_KEY` | Yes (for `sync`) | API key for authenticating with the Vocoder API |
101
- | `VOCODER_API_URL` | No | Override API URL (default: `https://vocoder.app`) |
208
+ ## How `init` interacts with the browser
209
+
210
+ The CLI never redirects the terminal to a URL or relies on the browser to complete setup. Instead:
211
+
212
+ 1. The CLI starts a local HTTP server on a random available port.
213
+ 2. It requests an auth session from Vocoder, passing the local port as the callback destination.
214
+ 3. The terminal displays the verification URL and (optionally) opens it in the system browser.
215
+ 4. After the user signs in, `vocoder.app/auth/cli` silently pings `localhost:<port>/callback?token=...` in the background.
216
+ 5. The CLI's local server receives the token instantly and the TUI continues — no polling delay.
217
+
218
+ If the local server fails to bind (port conflict, firewall), the CLI falls back to polling `GET /api/cli/auth/session` every 2 seconds until the token is available.
102
219
 
103
- The CLI reads `.env` files in the project root automatically.
220
+ The same local server pattern is used for the GitHub App install callback.
221
+
222
+ ---
104
223
 
105
224
  ## String Extraction
106
225
 
107
- The CLI uses Babel to parse JSX/TSX files and extract strings from:
226
+ The `wrap` command uses Babel to parse JSX/TSX files and detect strings that are likely user-facing:
108
227
 
109
- - `<T>` component children: `<T>Hello, world!</T>`
110
- - `<T>` component `msg` prop: `<T msg="{count, plural, one {# item} other {# items}}" />`
111
- - `t()` function calls: `t('Hello, world!')`
228
+ - JSX text content is wrapped with `<T>`
229
+ - String props like `placeholder`, `title`, `aria-label` are wrapped with `t()`
230
+ - Non-translatable strings (class names, keys, URLs) are left alone
112
231
 
113
- It tracks imports from `@vocoder/react` to ensure only Vocoder components are extracted (not unrelated components that happen to be named `T`).
232
+ It tracks imports from `@vocoder/react` to avoid double-wrapping strings already marked for translation.
114
233
 
115
- Each extracted string includes:
116
- - The source text (used as the translation key)
117
- - File path and line number
118
- - Optional `context` and `formality` props
234
+ ---
119
235
 
120
236
  ## Git Integration
121
237
 
@@ -125,6 +241,18 @@ The CLI auto-detects the repository and branch:
125
241
  - **Branch:** Checks CI environment variables first (GitHub Actions, Vercel, Netlify, etc.), then falls back to reading `.git/HEAD`
126
242
  - **Scope path:** For monorepos, computes the relative path from the git root to the working directory
127
243
 
244
+ ---
245
+
246
+ ## Environment Variables
247
+
248
+ | Variable | Used by | Purpose |
249
+ |---|---|---|
250
+ | `VOCODER_API_KEY` | `sync`, MCP | Project API key (`vc_` prefix) |
251
+ | `VOCODER_AUTH_TOKEN` | `init` | Override stored user auth token (`vcu_` prefix) |
252
+ | `VOCODER_API_URL` | All commands | Override API base URL (default: `https://vocoder.app`) |
253
+
254
+ ---
255
+
128
256
  ## License
129
257
 
130
258
  MIT