Architecture: Web Console
Relevant source files
The following files were used as context for generating this wiki page:The OpenCode Web Console is the primary public-facing website for the OpenCode project. It serves as a landing page to introduce the AI coding agent, showcase its features, provide installation instructions, and direct users to documentation and community channels. The console is a modern, client-rendered application built with the SolidJS framework.
While the web console itself is a frontend presentation layer, it promotes the core OpenCode agent, which is a CLI tool designed for software engineering tasks. The agent's behavior and capabilities, which the console markets, are defined in various prompt and template files. These definitions outline workflows for tasks like code modification, bug fixing, and feature implementation, ensuring the agent adheres to project conventions and safety standards.
Sources: packages/console/app/src/routes/index.tsx, packages/opencode/src/session/prompt/gemini.txt
Frontend Architecture
The web console is built as a Single Page Application (SPA) using SolidJS. It is composed of several components that are organized into routes.
Sources: packages/console/app/src/routes/index.tsx, CONTRIBUTING.md
Technology Stack
The frontend utilizes a modern JavaScript-based stack.
This diagram illustrates the main technologies used in the web console's frontend.
Sources: packages/console/app/src/routes/index.tsx:2-17, CONTRIBUTING.md:19-22
| Technology | Purpose | Source File |
|---|---|---|
| SolidJS | The core JavaScript framework for building the user interface. | packages/console/app/src/routes/index.tsx |
| @solidjs/router | Handles client-side routing and asynchronous data loading. | packages/console/app/src/routes/index.tsx:8 |
| @solidjs/meta | Manages HTML metadata tags like <title> and <meta>. | packages/console/app/src/routes/index.tsx:2 |
| @kobalte/core/tabs | A UI component library used for the installation command tabs. | packages/console/app/src/routes/index.tsx:9 |
| Bun | Used as the package manager and development server. | CONTRIBUTING.md:19 |
| CSS | Direct CSS imports are used for styling components. | packages/console/app/src/routes/index.tsx:1 |
Component Structure
The main landing page is composed of several distinct section components, each serving a specific purpose.
This diagram shows the high-level component breakdown of the main landing page.
Sources: packages/console/app/src/routes/index.tsx:50-388
Key Features & Implementation
Asynchronous Data Fetching
The console fetches external data, such as the latest GitHub release information, asynchronously. This is achieved using the createAsync function from @solidjs/router.
The following sequence diagram illustrates the data flow for fetching GitHub release information.
The implementation in index.tsx looks like this:
// packages/console/app/src/routes/index.tsx:16-17
const githubData = createAsync(() => github())
const release = createMemo(() => githubData()?.release)
This data is then used to render a link to the latest release notes.
Sources: packages/console/app/src/routes/index.tsx:16-17, 53-55
Interactive Installation Commands
A key feature is the interactive tabbed display for installation commands. This allows users to easily select and copy the command for their preferred package manager (curl, npm, bun, brew, paru).
Copy-to-Clipboard Functionality
Each command is a button that, when clicked, copies the command text to the user's clipboard and provides visual feedback.
The logic is handled by a click event handler.
The handleCopyClick function implements this flow:
// packages/console/app/src/routes/index.tsx:21-31
const handleCopyClick = (event: Event) => {
const button = event.currentTarget as HTMLButtonElement
const text = button.textContent
if (text) {
navigator.clipboard.writeText(text)
button.setAttribute("data-copied", "")
setTimeout(() => {
button.removeAttribute("data-copied")
}, 1500)
}
}
A similar implementation using onMount can be found in the temp.tsx route.
Sources: packages/console/app/src/routes/index.tsx:21-31, 80, packages/console/app/src/routes/temp.tsx:18-33
Installation Options
The console presents multiple ways to install OpenCode.
| Method | Command |
|---|---|
curl | `curl -fsSL https://opencode.ai/install |
npm | npm i -g opencode-ai |
bun | bun add -g opencode-ai |
brew | brew install opencode |
paru | paru -S opencode |
Sources: packages/console/app/src/routes/index.tsx:83-144
Relation to the Core Agent
The web console acts as a frontend for the OpenCode CLI agent. The agent's core logic and operational workflows are defined in a series of prompt files. These files instruct the AI on how to perform software engineering tasks, what conventions to follow, and how to use its available tools.
For example, the gemini.txt prompt defines the agent's primary workflow:
- Understand: Use tools like
grepandglobto analyze the codebase. - Plan: Formulate a plan and share it with the user.
- Implement: Use tools like
editandwriteto make changes. - Verify: Run tests and linters to ensure correctness and quality.
Specific tasks, like code reviews, have their own templates. The review.txt template instructs the agent on how to review uncommitted changes, specific commits, or pull requests by running git and gh commands. It also defines what to look for, such as bugs, structural issues, and performance problems, while advising the agent to be certain before flagging an issue.
This separation of concerns allows the web console to focus on user-facing presentation and marketing, while the core agent's complex logic is managed independently in the packages/opencode directory.
Sources: packages/opencode/src/session/prompt/gemini.txt, packages/opencode/src/command/template/review.txt