@happy-vibecode/cli 0.1.1 → 0.1.2

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/README.md +475 -0
  2. package/dist/index.js +7023 -2257
  3. package/package.json +12 -8
  4. package/src/index.ts +8 -0
package/README.md CHANGED
@@ -4,6 +4,481 @@
4
4
  ![Runtime](https://img.shields.io/badge/runtime-Bun%20%7C%20Node-green)
5
5
  ![License](https://img.shields.io/badge/license-MIT-green)
6
6
 
7
+ Command-line interface for the Happy Vibecode platform. Bridges local AI agents to the cloud service via WebSocket, enabling remote control from the web dashboard or mobile app. All agents are served through **[opencode](https://opencode.ai)** as a unified model server — no direct subprocess spawning per agent.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Getting Started](#getting-started)
12
+ - [Features](#features)
13
+ - [Commands](#commands)
14
+ - [Architecture](#architecture)
15
+ - [Supported Agents](#supported-agents)
16
+ - [Project Structure](#project-structure)
17
+ - [Configuration](#configuration)
18
+ - [Dependencies](#dependencies)
19
+ - [Scripts](#scripts)
20
+ - [Examples](#examples)
21
+ - [Troubleshooting](#troubleshooting)
22
+ - [Contributing](#contributing)
23
+ - [License](#license)
24
+
25
+ ## Getting Started
26
+
27
+ ### Prerequisites
28
+
29
+ Install [opencode](https://opencode.ai):
30
+
31
+ ```bash
32
+ bun add -g opencode-ai
33
+ # or
34
+ npm install -g opencode-ai
35
+ ```
36
+
37
+ ### Installation
38
+
39
+ #### From npm (once published)
40
+
41
+ ```bash
42
+ npm install -g @happy-vibecode/cli
43
+ # Then run via:
44
+ happy <command>
45
+ ```
46
+
47
+ #### From source (development)
48
+
49
+ ```bash
50
+ # From the monorepo root
51
+ bun install
52
+ bun run -F @happy-vibecode/cli build
53
+
54
+ # Run directly
55
+ node packages/cli/dist/index.js <command>
56
+
57
+ # Or via bun
58
+ cd packages/cli
59
+ bun run start <command>
60
+ ```
61
+
62
+ ### Quick Start
63
+
64
+ ```bash
65
+ # 1. Authenticate with the Happy Vibecode platform
66
+ happy login
67
+
68
+ # 2. Initialize default agent configuration
69
+ happy init
70
+
71
+ # 3. Check your setup
72
+ happy doctor
73
+
74
+ # 4. List available opencode providers and models
75
+ happy providers
76
+
77
+ # 5. Connect your first agent
78
+ happy connect gemini
79
+
80
+ # 6. Connect with a specific model (provider/model format)
81
+ happy connect claude --model anthropic/claude-opus-4-5
82
+ ```
83
+
84
+ ## Features
85
+
86
+ - **opencode model server** — All agents run through `opencode serve` as a unified AI backend; no per-agent subprocess spawning
87
+ - **Hybrid server startup** — SDK `createOpencodeServer` used first; falls back to manual `child_process` spawn for compatibility
88
+ - **Multi-agent support** — Gemini, Claude Code, Codex, OpenCode AI, GitHub Copilot, Kilo, Cline, and custom agents
89
+ - **Provider/model discovery** — `happy providers` lists all opencode-configured providers and their models
90
+ - **WebSocket bridge** — Real-time bidirectional communication between agents and the cloud
91
+ - **opencode URL relay** — CLI sends the local opencode serve URL to connected web/mobile clients (enables direct access when needed)
92
+ - **Workspace management** — Configure and switch between project directories
93
+ - **Diagnostics** — `happy doctor` checks for config issues, agent binaries, and opencode serve health
94
+
95
+ ## Commands
96
+
97
+ ### Authentication
98
+
99
+ | Command | Description |
100
+ | -------------- | ----------------------------------------------------------------- |
101
+ | `happy login` | Register a new account or authenticate with an existing API token |
102
+ | `happy whoami` | Show current authenticated user and server status |
103
+
104
+ ### Agent Connection
105
+
106
+ | Command | Description |
107
+ | ----------------------- | ------------------------------------------------------------------- |
108
+ | `happy connect <agent>` | Connect a local AI agent to the Happy Vibecode bridge via WebSocket |
109
+ | `happy init` | Create a default `agents.json` configuration file |
110
+ | `happy providers` | List all providers and models available in opencode |
111
+
112
+ ### Connect Options
113
+
114
+ | Flag | Description |
115
+ | ----------------------- | ------------------------------------------------------------------------------------------ |
116
+ | `-r, --room <roomId>` | Bridge room ID (defaults to your user ID) |
117
+ | `-d, --dir <directory>` | Workspace directory to run agent in |
118
+ | `-w, --workspace <id>` | Workspace ID from config |
119
+ | `-m, --model <model>` | Model to use — plain (`claude-opus-4-5`) or `provider/model` (`anthropic/claude-opus-4-5`) |
120
+ | `-s, --server <url>` | opencode serve URL (default: `http://127.0.0.1:4096`, auto-starts if not running) |
121
+ | `-c, --cors <origins>` | CORS origins for opencode serve — comma-separated (used in manual spawn fallback) |
122
+ | `-v, --verbose` | Verbose output |
123
+
124
+ ### Workspace Management
125
+
126
+ | Command | Description |
127
+ | ----------------------------------- | ---------------------------------------------- |
128
+ | `happy workspace list` | List all configured workspaces |
129
+ | `happy workspace add <name> <path>` | Add a new workspace |
130
+ | `happy workspace remove <id>` | Remove a workspace |
131
+ | `happy workspace set-default <id>` | Set default provider and model for a workspace |
132
+ | `happy workspace activate <id>` | Set a workspace as the active workspace |
133
+
134
+ ### Configuration
135
+
136
+ | Command | Description |
137
+ | -------------------------------- | ----------------------------------- |
138
+ | `happy config show` | Display current configuration |
139
+ | `happy config set <key> <value>` | Set a configuration value |
140
+ | `happy config unset <key>` | Remove a configuration value |
141
+ | `happy config reset` | Reset all configuration to defaults |
142
+
143
+ ### Diagnostics
144
+
145
+ | Command | Description |
146
+ | -------------- | --------------------------------------------------------------- |
147
+ | `happy doctor` | Diagnose config, binary availability, and opencode serve health |
148
+ | `happy status` | Show server health status and active sessions |
149
+
150
+ ## Architecture
151
+
152
+ ```
153
+ happy connect <agent>
154
+
155
+ ├── 1. ensureOpencodeServer()
156
+ │ ├── a) Already running at :4096 → attach (health check passes)
157
+ │ ├── b) SDK createOpencodeServer() → managed spawn
158
+ │ └── c) child_process.spawn opencode serve :4096 + health poll (fallback)
159
+
160
+ ├── 2. Create SDK client → new session with resolved model
161
+ │ └── agentToOpencodeModel(agentId, --model flag)
162
+ │ ├── Format: "anthropic/claude-opus-4-5" → {providerID, modelID}
163
+ │ └── Format: "claude" → {providerID: "anthropic", modelID: "default"}
164
+
165
+ ├── 3. Open WebSocket to BridgeAgent Durable Object (cloud)
166
+ │ └── On WS open → send { type: 'opencode_url', url: 'http://127.0.0.1:4096' }
167
+ │ → send { type: 'status', status: 'cli_connected' }
168
+
169
+ └── 4. Relay loop
170
+ ├── WS message (prompt) → opencode session.prompt(text)
171
+ ├── opencode events → WS response chunks
172
+ └── SIGTERM / WS close → opencodeServer.close()
173
+ ```
174
+
175
+ ### Model Flag Format
176
+
177
+ The `--model` flag supports two formats:
178
+
179
+ ```bash
180
+ # Short form — provider inferred from agent type
181
+ happy connect gemini --model gemini-2.0-flash
182
+
183
+ # Full form — explicit provider/model
184
+ happy connect claude --model anthropic/claude-opus-4-5
185
+ happy connect gemini --model google/gemini-2.5-pro
186
+ happy connect codex --model openai/o3
187
+
188
+ # Agent-type to provider mapping
189
+ # gemini → google
190
+ # claude → anthropic
191
+ # codex → openai
192
+ # copilot → github
193
+ # opencode-ai, kilo, cline → anthropic
194
+ ```
195
+
196
+ ### Provider/Model Discovery
197
+
198
+ ```bash
199
+ # List all providers configured in opencode (reads ~/.config/opencode/config.json)
200
+ happy providers
201
+ ```
202
+
203
+ Example output:
204
+
205
+ ```
206
+ Available providers in opencode:
207
+ anthropic (env)
208
+ Models: claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5
209
+ google (env)
210
+ Models: gemini-2.5-pro, gemini-2.0-flash
211
+ openai (env)
212
+ Models: gpt-4o, o3
213
+ ```
214
+
215
+ ### opencode URL Relay
216
+
217
+ When the CLI connects, it sends `{ type: 'opencode_url', url }` through the WebSocket bridge to all connected web/mobile clients. The web app stores this URL and shows it in the debug panel (`Debug mode` toggle in the header), useful for verifying direct connectivity.
218
+
219
+ ## Supported Agents
220
+
221
+ | Agent | Resolved Provider | Notes |
222
+ | ------------- | ----------------- | ---------------------------------------------- |
223
+ | `gemini` | `google` | Routes through opencode, no direct spawn |
224
+ | `claude` | `anthropic` | Routes through opencode, no direct spawn |
225
+ | `codex` | `openai` | Routes through opencode, no direct spawn |
226
+ | `opencode-ai` | `anthropic` | Native opencode agent |
227
+ | `copilot` | `github` | Routes through opencode |
228
+ | `kilo` | `anthropic` | Routes through opencode |
229
+ | `cline` | `anthropic` | Routes through opencode |
230
+ | Custom | User-defined | Extend `PROVIDER_CONFIGS` in `llm-provider.ts` |
231
+
232
+ ## Project Structure
233
+
234
+ ```
235
+ packages/cli/
236
+ ├── src/
237
+ │ ├── index.ts # CLI entry — registers all commands via Commander
238
+ │ ├── config.ts # HappyConfig, readConfig/writeConfig, bridge code generation
239
+ │ ├── commands/
240
+ │ │ ├── login.ts # happy login
241
+ │ │ ├── connect.ts # happy connect <agent>
242
+ │ │ ├── init.ts # happy init
243
+ │ │ ├── providers.ts # happy providers — list opencode providers/models
244
+ │ │ ├── workspace.ts # happy workspace (list/add/remove/set-default/activate)
245
+ │ │ ├── config.ts # happy config (show/set/unset/reset)
246
+ │ │ ├── doctor.ts # happy doctor (config + opencode health checks)
247
+ │ │ ├── status.ts # happy status
248
+ │ │ └── whoami.ts # happy whoami
249
+ │ ├── config/
250
+ │ │ └── workspace.ts # Workspace CRUD operations
251
+ │ ├── types/
252
+ │ │ └── llm-provider.ts # LLMProvider, PROVIDER_CONFIGS, AgentDefinition, etc.
253
+ │ └── utils/
254
+ │ ├── agents-config.ts # DEFAULT_AGENTS from PROVIDER_CONFIGS
255
+ │ ├── opencode-server.ts # ensureOpencodeServer() — hybrid spawn (SDK → manual fallback)
256
+ │ └── log.ts # Debug logging (setDebug, debug, debugTime, debugFetch)
257
+ ├── dist/ # Built output (gitignored)
258
+ ├── tsconfig.json
259
+ ├── eslint.config.ts
260
+ └── package.json
261
+ ```
262
+
263
+ ## Configuration
264
+
265
+ ### HappyConfig
266
+
267
+ Stored at `~/.happy/config.json`:
268
+
269
+ | Field | Type | Description |
270
+ | ------------ | --------- | ----------------------------------------------- |
271
+ | `apiToken` | `string` | API authentication token |
272
+ | `serverUrl` | `string` | Happy Vibecode server URL (default: production) |
273
+ | `userId` | `string?` | Authenticated user ID |
274
+ | `bridgeCode` | `string?` | Bridge connection code |
275
+
276
+ ### Agents Configuration (`agents.json`)
277
+
278
+ Created by `happy init`. Defines available agents and workspaces:
279
+
280
+ ```typescript
281
+ interface AgentsConfig {
282
+ agents: AgentDefinition[]
283
+ workspaces?: WorkspaceConfig[]
284
+ }
285
+
286
+ interface AgentDefinition {
287
+ name: string // Display name
288
+ command: string // CLI command to execute (legacy — opencode is the actual server)
289
+ args?: string[] // Default arguments
290
+ promptFlag?: string // Flag for passing prompts
291
+ modelFlag?: string // Flag for passing model names
292
+ description?: string
293
+ }
294
+ ```
295
+
296
+ ### Debug Logging
297
+
298
+ Enable debug mode for verbose output:
299
+
300
+ ```bash
301
+ DEBUG=1 happy connect gemini
302
+ # Output includes: opencode server startup, WebSocket frames, SDK calls, timing
303
+ ```
304
+
305
+ ## Dependencies
306
+
307
+ ### Internal
308
+
309
+ | Package | Purpose |
310
+ | -------------------------------------- | ----------------------------------- |
311
+ | [`@happy-vibecode/shared`](../shared/) | Shared types and validation schemas |
312
+
313
+ ### External
314
+
315
+ | Package | Purpose |
316
+ | ------------------- | --------------------------------------------------------------------------------- |
317
+ | `@opencode-ai/sdk` | opencode SDK — `createOpencodeClient`, `createOpencodeServer`, session/prompt API |
318
+ | `commander` ^14.0.0 | CLI framework and command parsing |
319
+ | `execa` latest | Spawn and manage local processes |
320
+ | `ora` ^6.3.1 | Terminal spinner for loading states |
321
+ | `ws` ^8.18.2 | WebSocket client for bridge connections |
322
+
323
+ ## Scripts
324
+
325
+ | Script | Command | Description |
326
+ | ---------------- | --------------------------------------------------------------- | ------------------------ |
327
+ | `build` | `bun build ./src/index.ts --outfile dist/index.js --target bun` | Build for production |
328
+ | `dev` | `bun run --watch src/index.ts` | Run in watch mode |
329
+ | `start` | `bun run ./src/index.ts` | Run CLI directly |
330
+ | `lint` | `eslint .` | Lint source files |
331
+ | `lint:fix` | `eslint . --fix` | Lint and auto-fix |
332
+ | `typecheck` | `tsc --noEmit` | TypeScript type checking |
333
+ | `prepublishOnly` | `bun run lint:fix && bun run typecheck && bun run build` | Pre-publish checks |
334
+
335
+ ## Examples
336
+
337
+ ### Complete Setup Flow
338
+
339
+ ```bash
340
+ # Authenticate
341
+ happy login
342
+
343
+ # Initialize agent config
344
+ happy init
345
+
346
+ # Check everything
347
+ happy doctor
348
+
349
+ # See what models are available
350
+ happy providers
351
+
352
+ # Connect Gemini using default model
353
+ happy connect gemini
354
+
355
+ # Connect Claude with a specific model
356
+ happy connect claude --model anthropic/claude-opus-4-5
357
+
358
+ # Connect with CORS enabled (for local web dev)
359
+ happy connect gemini --cors http://localhost:5173
360
+ ```
361
+
362
+ ### Connecting Different Agents
363
+
364
+ ```bash
365
+ # Connect Gemini (resolves to google provider)
366
+ happy connect gemini
367
+
368
+ # Connect Claude Code (resolves to anthropic)
369
+ happy connect claude --model anthropic/claude-sonnet-4-5
370
+
371
+ # Connect OpenAI Codex (resolves to openai)
372
+ happy connect codex --model openai/o3
373
+
374
+ # Use full provider/model override for any agent
375
+ happy connect gemini --model anthropic/claude-opus-4-5
376
+ ```
377
+
378
+ ### Managing Configuration
379
+
380
+ ```bash
381
+ # View all config
382
+ happy config show
383
+
384
+ # Set server URL (for self-hosted)
385
+ happy config set serverUrl https://my-instance.example.com
386
+
387
+ # Reset to defaults
388
+ happy config reset
389
+ ```
390
+
391
+ ### Using Debug Mode
392
+
393
+ ```bash
394
+ # Enable verbose logging (shows opencode server startup, SDK calls, WS frames)
395
+ DEBUG=1 happy connect gemini
396
+ ```
397
+
398
+ ## Troubleshooting
399
+
400
+ ### `opencode binary not found`
401
+
402
+ Install opencode globally:
403
+
404
+ ```bash
405
+ bun add -g opencode-ai
406
+ # or
407
+ npm install -g opencode-ai
408
+ ```
409
+
410
+ Then verify: `opencode --version`
411
+
412
+ ### `command not found: happy`
413
+
414
+ After installing globally, ensure the npm global bin directory is in your `PATH`:
415
+
416
+ ```bash
417
+ npm config get prefix
418
+ # Add <prefix>/bin to your PATH
419
+ ```
420
+
421
+ When running from source, use `node dist/index.js` or `bun run start`.
422
+
423
+ ### `opencode serve did not become healthy`
424
+
425
+ opencode failed to start. Try starting it manually to see the error:
426
+
427
+ ```bash
428
+ opencode serve --port 4096
429
+ ```
430
+
431
+ Common causes: port already in use, missing API keys in `~/.config/opencode/config.json`.
432
+
433
+ ### `ECONNREFUSED` on connect
434
+
435
+ The Happy Vibecode server is unreachable. Check:
436
+
437
+ 1. Your internet connection
438
+ 2. The `serverUrl` in config: `happy config show`
439
+ 3. Server status: `happy status`
440
+
441
+ ### `401 Unauthorized`
442
+
443
+ Your API token is invalid or expired. Re-authenticate:
444
+
445
+ ```bash
446
+ happy login
447
+ ```
448
+
449
+ ### `happy doctor` reports issues
450
+
451
+ The doctor command checks:
452
+
453
+ - Config file existence and validity
454
+ - API token presence
455
+ - Agent binary availability
456
+ - **opencode binary** in PATH
457
+ - **opencode serve** health status (port 4096)
458
+
459
+ Follow the suggestions in the output to resolve each issue.
460
+
461
+ ## Contributing
462
+
463
+ See the root [CONTRIBUTING.md](../../README.md#contributing) for general guidelines.
464
+
465
+ For this package specifically:
466
+
467
+ - One command file per command in `src/commands/`
468
+ - Use Commander.js patterns for argument parsing
469
+ - Use `ora` for all async operations that may take time
470
+ - All AI interactions route through opencode SDK — no direct agent subprocess spawning
471
+ - Add new agent support by extending `PROVIDER_CONFIGS` in `src/types/llm-provider.ts`
472
+ - Run `bun run typecheck` and `bun run lint` before submitting changes
473
+
474
+ ## License
475
+
476
+ This project is part of the [Happy Vibecode](../../README.md) monorepo. See the root LICENSE file for details.
477
+
478
+ ![Version](https://img.shields.io/badge/version-0.1.1-blue)
479
+ ![Runtime](https://img.shields.io/badge/runtime-Bun%20%7C%20Node-green)
480
+ ![License](https://img.shields.io/badge/license-MIT-green)
481
+
7
482
  Command-line interface for the Happy Vibecode platform. Connects local AI agents (Gemini CLI, Claude Code, Codex, Kilo, Cline, and more) to the Happy Vibecode cloud service, enabling remote control of your coding agents from the web dashboard or mobile app via WebSocket bridges.
8
483
 
9
484
  ## Table of Contents