2025-12-31 14:07:14 +09:00
|
|
|
# CLI KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-02-16 15:26:53 +09:00
|
|
|
CLI entry: `bunx oh-my-opencode`. 107+ files with Commander.js + @clack/prompts TUI. 5 commands: install, run, doctor, get-local-version, mcp-oauth.
|
2025-12-31 14:07:14 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
```
|
|
|
|
|
cli/
|
2026-02-10 14:53:39 +09:00
|
|
|
├── index.ts # Entry point (5 lines)
|
|
|
|
|
├── cli-program.ts # Commander.js program (150+ lines, 5 commands)
|
|
|
|
|
├── install.ts # TTY routing (TUI or CLI installer)
|
2026-02-09 14:29:53 +09:00
|
|
|
├── cli-installer.ts # Non-interactive installer (164 lines)
|
|
|
|
|
├── tui-installer.ts # Interactive TUI with @clack/prompts (140 lines)
|
2026-02-16 15:26:53 +09:00
|
|
|
├── config-manager/ # 20 config utilities
|
2026-02-10 14:53:39 +09:00
|
|
|
│ ├── add-plugin-to-opencode-config.ts # Plugin registration
|
2026-02-16 15:26:53 +09:00
|
|
|
│ ├── add-provider-config.ts # Provider setup (Google/Antigravity)
|
|
|
|
|
│ ├── detect-current-config.ts # Installed providers detection
|
2026-02-10 14:53:39 +09:00
|
|
|
│ ├── write-omo-config.ts # JSONC writing
|
2026-02-16 15:26:53 +09:00
|
|
|
│ ├── generate-omo-config.ts # Config generation
|
|
|
|
|
│ ├── jsonc-provider-editor.ts # JSONC editing
|
|
|
|
|
│ └── ... # 14 more utilities
|
|
|
|
|
├── doctor/ # 4 check categories, 21 check files
|
|
|
|
|
│ ├── runner.ts # Parallel check execution + result aggregation
|
|
|
|
|
│ ├── formatter.ts # Colored output (default/status/verbose/JSON)
|
|
|
|
|
│ └── checks/ # system (4), config (1), tools (4), models (6 sub-checks)
|
2026-02-09 14:29:53 +09:00
|
|
|
├── run/ # Session launcher (24 files)
|
2026-02-10 14:53:39 +09:00
|
|
|
│ ├── runner.ts # Run orchestration (126 lines)
|
2026-02-16 15:26:53 +09:00
|
|
|
│ ├── agent-resolver.ts # Agent: flag → env → config → Sisyphus
|
|
|
|
|
│ ├── session-resolver.ts # Session create or resume with retries
|
2026-02-10 14:53:39 +09:00
|
|
|
│ ├── event-handlers.ts # Event processing (125 lines)
|
|
|
|
|
│ ├── completion.ts # Completion detection
|
|
|
|
|
│ └── poll-for-completion.ts # Polling with timeout
|
|
|
|
|
├── mcp-oauth/ # OAuth token management (login, logout, status)
|
|
|
|
|
├── get-local-version/ # Version detection + update check
|
|
|
|
|
├── model-fallback.ts # Model fallback configuration
|
|
|
|
|
└── provider-availability.ts # Provider availability checks
|
2025-12-31 14:07:14 +09:00
|
|
|
```
|
|
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
## COMMANDS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-02-10 14:53:39 +09:00
|
|
|
| Command | Purpose | Key Logic |
|
|
|
|
|
|---------|---------|-----------|
|
|
|
|
|
| `install` | Interactive setup | Provider selection → config generation → plugin registration |
|
|
|
|
|
| `run` | Session launcher | Agent: flag → env → config → Sisyphus. Enforces todo completion. |
|
2026-02-16 15:26:53 +09:00
|
|
|
| `doctor` | 4-category health checks | system, config, tools, models (6 sub-checks) |
|
2026-02-10 14:53:39 +09:00
|
|
|
| `get-local-version` | Version check | Detects installed, compares with npm latest |
|
|
|
|
|
| `mcp-oauth` | OAuth tokens | login (PKCE flow), logout, status |
|
2026-01-13 21:00:00 +09:00
|
|
|
|
2026-02-16 15:26:53 +09:00
|
|
|
## RUN SESSION LIFECYCLE
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-02-16 15:26:53 +09:00
|
|
|
1. Load config, resolve agent (CLI > env > config > Sisyphus)
|
|
|
|
|
2. Create server connection (port/attach), setup cleanup/signal handlers
|
|
|
|
|
3. Resolve session (create new or resume with retries)
|
|
|
|
|
4. Send prompt, start event processing, poll for completion
|
|
|
|
|
5. Execute on-complete hook, output JSON if requested, cleanup
|
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
|
|
|
|
2026-01-23 02:14:08 +09:00
|
|
|
1. Create `src/cli/doctor/checks/my-check.ts`
|
2026-02-10 14:53:39 +09:00
|
|
|
2. Export `getXXXCheckDefinition()` returning `CheckDefinition`
|
2026-01-26 11:48:30 +09:00
|
|
|
3. Add to `getAllCheckDefinitions()` in `checks/index.ts`
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2026-01-17 22:01:56 +09:00
|
|
|
|
2026-02-10 14:53:39 +09:00
|
|
|
- **Blocking in non-TTY**: Check `process.stdout.isTTY`
|
|
|
|
|
- **Direct JSON.parse**: Use `parseJsonc()` from shared
|
|
|
|
|
- **Silent failures**: Return `warn` or `fail` in doctor, don't throw
|
|
|
|
|
- **Hardcoded paths**: Use `getOpenCodeConfigPaths()` from config-manager
|