Architecture
Architecture of my-opencode-config
Section titled “Architecture of my-opencode-config”my-opencode-config is built with TypeScript to provide a structured and maintainable CLI tool for OpenCode configuration.
Key Design Principles
Section titled “Key Design Principles”- Modular Design: The project is split into
src/commandsfor business logic andsrc/utilsfor reusable helper functions. - Interactive Wizard: The tool uses
@clack/promptsto create an 8-step, step-by-step interactive setup wizard. - Resilient Configuration: Before any change is made,
my-opencode-configcreates a backup of the existingopencode.jsonfile. - Isolated Testing: E2E tests are executed inside a Docker container (Alpine Linux) to prevent local environment interference.
Project Structure
Section titled “Project Structure”./├── src/│ ├── index.ts # The entry point for the CLI - contains the 8-step wizard.│ ├── commands/ # Core business logic for each step.│ │ ├── auth.ts # OpenCode and Google authentication.│ │ ├── models.ts # Model fetching and scoring logic.│ │ ├── plugins.ts # Plugin management and merging.│ │ └── config.ts # Configuration file generation and backups.│ ├── utils/ # Reusable utility functions.│ │ ├── config.ts # Helper for configuration files.│ │ ├── logging.ts # Centralized logging logic.│ │ ├── opencode.ts # OpenCode CLI detection.│ │ └── prompts.ts # Custom prompts and UI helpers.│ └── types.ts # Shared TypeScript interfaces and types.├── tests/e2e/ # Docker-based end-to-end tests.├── dist/ # Compiled JavaScript output.└── package.json # Build and test scripts.Adding a New Step to the Wizard
Section titled “Adding a New Step to the Wizard”If you want to add a new step to the setup process, follow these guidelines:
- Define the Logic: Create a new command file in
src/commands/or add the logic to an existing one. - Update
src/index.ts: Add a new step to themain()function’sp.intro()andp.outro()chain. - Create Custom Prompts: If needed, add new prompt logic in
src/utils/prompts.ts. - Test the Change: Ensure the new step works correctly by adding it to the E2E test suite in
tests/e2e/run.sh.
Configuration Merging
Section titled “Configuration Merging”my-opencode-config uses a careful merging strategy to avoid overwriting existing user settings. It parses the current opencode.json and only updates or adds specific keys related to models, providers, and plugins.
Future Roadmap
Section titled “Future Roadmap”- Support More Providers: Add support for additional AI providers.
- Advanced Model Selection: Allow users to filter models by specific capabilities (e.g., vision, long context).
- Automated Plugin Updates: Periodically check and prompt for plugin updates.