2025-12-31 14:07:14 +09:00
|
|
|
# CLI KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
CLI entry point: `bunx oh-my-opencode`. Interactive installer, doctor diagnostics, session runner. Uses Commander.js + @clack/prompts TUI.
|
2025-12-31 14:07:14 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2025-12-31 14:07:14 +09:00
|
|
|
```
|
|
|
|
|
cli/
|
2026-01-17 22:01:56 +09:00
|
|
|
├── index.ts # Commander.js entry, 5 subcommands
|
2026-01-22 22:48:50 +09:00
|
|
|
├── install.ts # Interactive TUI installer (520 lines)
|
|
|
|
|
├── config-manager.ts # JSONC parsing, multi-level merge (641 lines)
|
2026-01-17 22:01:56 +09:00
|
|
|
├── types.ts # InstallArgs, InstallConfig, DetectedConfig
|
|
|
|
|
├── doctor/
|
2025-12-31 14:07:14 +09:00
|
|
|
│ ├── index.ts # Doctor command entry
|
2026-01-17 22:01:56 +09:00
|
|
|
│ ├── runner.ts # Check orchestration
|
|
|
|
|
│ ├── formatter.ts # Colored output, symbols
|
|
|
|
|
│ ├── constants.ts # Check IDs, categories, symbols
|
|
|
|
|
│ ├── types.ts # CheckResult, CheckDefinition
|
2026-01-22 22:48:50 +09:00
|
|
|
│ └── checks/ # 14 checks across 6 categories (21 files)
|
2026-01-17 22:01:56 +09:00
|
|
|
│ ├── version.ts # OpenCode + plugin version
|
|
|
|
|
│ ├── config.ts # JSONC validity, Zod validation
|
|
|
|
|
│ ├── auth.ts # Anthropic, OpenAI, Google
|
|
|
|
|
│ ├── dependencies.ts # AST-Grep, Comment Checker
|
|
|
|
|
│ ├── lsp.ts # LSP server connectivity
|
|
|
|
|
│ ├── mcp.ts # MCP server validation
|
|
|
|
|
│ └── gh.ts # GitHub CLI availability
|
|
|
|
|
├── run/
|
|
|
|
|
│ ├── index.ts # Run command entry
|
|
|
|
|
│ └── runner.ts # Session launcher
|
|
|
|
|
└── get-local-version/
|
|
|
|
|
├── index.ts # Version detection
|
|
|
|
|
└── formatter.ts # Version output
|
2025-12-31 14:07:14 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## CLI COMMANDS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
| Command | Purpose |
|
|
|
|
|
|---------|---------|
|
2026-01-17 22:01:56 +09:00
|
|
|
| `install` | Interactive setup, subscription detection |
|
|
|
|
|
| `doctor` | 14 health checks, `--verbose`, `--json`, `--category` |
|
|
|
|
|
| `run` | Launch OpenCode session with completion enforcement |
|
|
|
|
|
| `get-local-version` | Version detection, update checking |
|
2026-01-13 21:00:00 +09:00
|
|
|
|
2026-01-17 22:01:56 +09:00
|
|
|
## DOCTOR CHECK CATEGORIES
|
|
|
|
|
|
|
|
|
|
| Category | Checks |
|
|
|
|
|
|----------|--------|
|
|
|
|
|
| installation | opencode, plugin registration |
|
|
|
|
|
| configuration | config validity, Zod validation |
|
|
|
|
|
| authentication | anthropic, openai, google |
|
|
|
|
|
| dependencies | ast-grep CLI/NAPI, comment-checker |
|
|
|
|
|
| tools | LSP, MCP connectivity |
|
|
|
|
|
| updates | version comparison |
|
2025-12-31 14:07:14 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## HOW TO ADD CHECK
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
1. Create `src/cli/doctor/checks/my-check.ts`:
|
|
|
|
|
```typescript
|
|
|
|
|
export function getMyCheckDefinition(): CheckDefinition {
|
|
|
|
|
return {
|
|
|
|
|
id: "my-check",
|
|
|
|
|
name: "My Check",
|
|
|
|
|
category: "configuration",
|
|
|
|
|
check: async () => ({ status: "pass", message: "OK" })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
2. Export from `checks/index.ts`
|
|
|
|
|
3. Add to `getAllCheckDefinitions()`
|
|
|
|
|
|
|
|
|
|
## TUI FRAMEWORK
|
|
|
|
|
|
|
|
|
|
- **@clack/prompts**: `select()`, `spinner()`, `intro()`, `outro()`, `note()`
|
|
|
|
|
- **picocolors**: Colored terminal output
|
|
|
|
|
- **Symbols**: ✓ (pass), ✗ (fail), ⚠ (warn), ○ (skip)
|
|
|
|
|
|
|
|
|
|
## CONFIG-MANAGER
|
|
|
|
|
|
|
|
|
|
- **JSONC**: Comments (`// ...`), block comments, trailing commas
|
|
|
|
|
- **Multi-source**: User (`~/.config/opencode/`) + Project (`.opencode/`)
|
|
|
|
|
- **Env override**: `OPENCODE_CONFIG_DIR` for profile isolation
|
|
|
|
|
- **Validation**: Zod schema with error aggregation
|
2025-12-31 14:07:14 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
|
|
|
|
- **Blocking in non-TTY**: Check `process.stdout.isTTY`
|
|
|
|
|
- **Direct JSON.parse**: Use `parseJsonc()` for config
|
|
|
|
|
- **Silent failures**: Always return warn/fail in doctor
|
|
|
|
|
- **Hardcoded paths**: Use `ConfigManager`
|