Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 333ea6e

Browse files
committed
implement patch, update ui, improve rendering
1 parent 05d0e86 commit 333ea6e

File tree

38 files changed

+3304
-2254
lines changed

38 files changed

+3304
-2254
lines changed

README.md

Lines changed: 271 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
55
A powerful terminal-based AI assistant for developers, providing intelligent coding assistance directly in your terminal.
66

7-
[![OpenCode Demo](https://asciinema.org/a/dtc4nJyGSZX79HRUmFLY3gmoy.svg)](https://asciinema.org/a/dtc4nJyGSZX79HRUmFLY3gmoy)
8-
97
## Overview
108

119
OpenCode is a Go-based CLI application that brings AI assistance to your terminal. It provides a TUI (Terminal User Interface) for interacting with various AI models to help with coding tasks, debugging, and more.
1210

1311
## Features
1412

1513
- **Interactive TUI**: Built with [Bubble Tea](https://github.com/charmbracelet/bubbletea) for a smooth terminal experience
16-
- **Multiple AI Providers**: Support for OpenAI, Anthropic Claude, and Google Gemini models
14+
- **Multiple AI Providers**: Support for OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, and Groq
1715
- **Session Management**: Save and manage multiple conversation sessions
1816
- **Tool Integration**: AI can execute commands, search files, and modify code
19-
- **Vim-like Editor**: Integrated editor with Vim keybindings for text input
17+
- **Vim-like Editor**: Integrated editor with text input capabilities
2018
- **Persistent Storage**: SQLite database for storing conversations and sessions
19+
- **LSP Integration**: Language Server Protocol support for code intelligence
20+
- **File Change Tracking**: Track and visualize file changes during sessions
2121

2222
## Installation
2323

@@ -34,11 +34,107 @@ OpenCode looks for configuration in the following locations:
3434
- `$XDG_CONFIG_HOME/opencode/.opencode.json`
3535
- `./.opencode.json` (local directory)
3636

37-
You can also use environment variables:
37+
### Environment Variables
38+
39+
You can configure OpenCode using environment variables:
40+
41+
| Environment Variable | Purpose |
42+
| ----------------------- | ------------------------ |
43+
| `ANTHROPIC_API_KEY` | For Claude models |
44+
| `OPENAI_API_KEY` | For OpenAI models |
45+
| `GEMINI_API_KEY` | For Google Gemini models |
46+
| `GROQ_API_KEY` | For Groq models |
47+
| `AWS_ACCESS_KEY_ID` | For AWS Bedrock (Claude) |
48+
| `AWS_SECRET_ACCESS_KEY` | For AWS Bedrock (Claude) |
49+
| `AWS_REGION` | For AWS Bedrock (Claude) |
50+
51+
### Configuration File Structure
52+
53+
```json
54+
{
55+
"data": {
56+
"directory": ".opencode"
57+
},
58+
"providers": {
59+
"openai": {
60+
"apiKey": "your-api-key",
61+
"disabled": false
62+
},
63+
"anthropic": {
64+
"apiKey": "your-api-key",
65+
"disabled": false
66+
}
67+
},
68+
"agents": {
69+
"coder": {
70+
"model": "claude-3.7-sonnet",
71+
"maxTokens": 5000
72+
},
73+
"task": {
74+
"model": "claude-3.7-sonnet",
75+
"maxTokens": 5000
76+
},
77+
"title": {
78+
"model": "claude-3.7-sonnet",
79+
"maxTokens": 80
80+
}
81+
},
82+
"mcpServers": {
83+
"example": {
84+
"type": "stdio",
85+
"command": "path/to/mcp-server",
86+
"env": [],
87+
"args": []
88+
}
89+
},
90+
"lsp": {
91+
"go": {
92+
"disabled": false,
93+
"command": "gopls"
94+
}
95+
},
96+
"debug": false,
97+
"debugLSP": false
98+
}
99+
```
38100

39-
- `ANTHROPIC_API_KEY`: For Claude models
40-
- `OPENAI_API_KEY`: For OpenAI models
41-
- `GEMINI_API_KEY`: For Google Gemini models
101+
## Supported AI Models
102+
103+
### OpenAI Models
104+
105+
| Model ID | Name | Context Window |
106+
| ----------------- | --------------- | ---------------- |
107+
| `gpt-4.1` | GPT 4.1 | 1,047,576 tokens |
108+
| `gpt-4.1-mini` | GPT 4.1 Mini | 200,000 tokens |
109+
| `gpt-4.1-nano` | GPT 4.1 Nano | 1,047,576 tokens |
110+
| `gpt-4.5-preview` | GPT 4.5 Preview | 128,000 tokens |
111+
| `gpt-4o` | GPT-4o | 128,000 tokens |
112+
| `gpt-4o-mini` | GPT-4o Mini | 128,000 tokens |
113+
| `o1` | O1 | 200,000 tokens |
114+
| `o1-pro` | O1 Pro | 200,000 tokens |
115+
| `o1-mini` | O1 Mini | 128,000 tokens |
116+
| `o3` | O3 | 200,000 tokens |
117+
| `o3-mini` | O3 Mini | 200,000 tokens |
118+
| `o4-mini` | O4 Mini | 128,000 tokens |
119+
120+
### Anthropic Models
121+
122+
| Model ID | Name | Context Window |
123+
| ------------------- | ----------------- | -------------- |
124+
| `claude-3.5-sonnet` | Claude 3.5 Sonnet | 200,000 tokens |
125+
| `claude-3-haiku` | Claude 3 Haiku | 200,000 tokens |
126+
| `claude-3.7-sonnet` | Claude 3.7 Sonnet | 200,000 tokens |
127+
| `claude-3.5-haiku` | Claude 3.5 Haiku | 200,000 tokens |
128+
| `claude-3-opus` | Claude 3 Opus | 200,000 tokens |
129+
130+
### Other Models
131+
132+
| Model ID | Provider | Name | Context Window |
133+
| --------------------------- | ----------- | ----------------- | -------------- |
134+
| `gemini-2.5` | Google | Gemini 2.5 Pro | - |
135+
| `gemini-2.0-flash` | Google | Gemini 2.0 Flash | - |
136+
| `qwen-qwq` | Groq | Qwen Qwq | - |
137+
| `bedrock.claude-3.7-sonnet` | AWS Bedrock | Claude 3.7 Sonnet | - |
42138

43139
## Usage
44140

@@ -48,36 +144,78 @@ opencode
48144

49145
# Start with debug logging
50146
opencode -d
147+
148+
# Start with a specific working directory
149+
opencode -c /path/to/project
51150
```
52151

53-
### Keyboard Shortcuts
152+
## Command-line Flags
153+
154+
| Flag | Short | Description |
155+
| --------- | ----- | ----------------------------- |
156+
| `--help` | `-h` | Display help information |
157+
| `--debug` | `-d` | Enable debug mode |
158+
| `--cwd` | `-c` | Set current working directory |
159+
160+
## Keyboard Shortcuts
161+
162+
### Global Shortcuts
163+
164+
| Shortcut | Action |
165+
| -------- | ------------------------------------------------------- |
166+
| `Ctrl+C` | Quit application |
167+
| `Ctrl+?` | Toggle help dialog |
168+
| `Ctrl+L` | View logs |
169+
| `Esc` | Close current overlay/dialog or return to previous mode |
170+
171+
### Chat Page Shortcuts
172+
173+
| Shortcut | Action |
174+
| -------- | --------------------------------------- |
175+
| `Ctrl+N` | Create new session |
176+
| `Ctrl+X` | Cancel current operation/generation |
177+
| `i` | Focus editor (when not in writing mode) |
178+
| `Esc` | Exit writing mode and focus messages |
179+
180+
### Editor Shortcuts
54181

55-
#### Global Shortcuts
182+
| Shortcut | Action |
183+
| ------------------- | ----------------------------------------- |
184+
| `Ctrl+S` | Send message (when editor is focused) |
185+
| `Enter` or `Ctrl+S` | Send message (when editor is not focused) |
186+
| `Esc` | Blur editor and focus messages |
56187

57-
- `?`: Toggle help panel
58-
- `Ctrl+C` or `q`: Quit application
59-
- `L`: View logs
60-
- `Backspace`: Go back to previous page
61-
- `Esc`: Close current view/dialog or return to normal mode
188+
### Logs Page Shortcuts
62189

63-
#### Session Management
190+
| Shortcut | Action |
191+
| ----------- | ------------------- |
192+
| `Backspace` | Return to chat page |
64193

65-
- `N`: Create new session
66-
- `Enter` or `Space`: Select session (in sessions list)
194+
## AI Assistant Tools
67195

68-
#### Editor Shortcuts (Vim-like)
196+
OpenCode's AI assistant has access to various tools to help with coding tasks:
69197

70-
- `i`: Enter insert mode
71-
- `Esc`: Enter normal mode
72-
- `v`: Enter visual mode
73-
- `V`: Enter visual line mode
74-
- `Enter`: Send message (in normal mode)
75-
- `Ctrl+S`: Send message (in insert mode)
198+
### File and Code Tools
76199

77-
#### Navigation
200+
| Tool | Description | Parameters |
201+
| ------------- | --------------------------- | ---------------------------------------------------------------------------------------- |
202+
| `glob` | Find files by pattern | `pattern` (required), `path` (optional) |
203+
| `grep` | Search file contents | `pattern` (required), `path` (optional), `include` (optional), `literal_text` (optional) |
204+
| `ls` | List directory contents | `path` (optional), `ignore` (optional array of patterns) |
205+
| `view` | View file contents | `file_path` (required), `offset` (optional), `limit` (optional) |
206+
| `write` | Write to files | `file_path` (required), `content` (required) |
207+
| `edit` | Edit files | Various parameters for file editing |
208+
| `patch` | Apply patches to files | `file_path` (required), `diff` (required) |
209+
| `diagnostics` | Get diagnostics information | `file_path` (optional) |
78210

79-
- Arrow keys: Navigate through lists and content
80-
- Page Up/Down: Scroll through content
211+
### Other Tools
212+
213+
| Tool | Description | Parameters |
214+
| ------------- | -------------------------------------- | ----------------------------------------------------------------------------------------- |
215+
| `bash` | Execute shell commands | `command` (required), `timeout` (optional) |
216+
| `fetch` | Fetch data from URLs | `url` (required), `format` (required), `timeout` (optional) |
217+
| `sourcegraph` | Search code across public repositories | `query` (required), `count` (optional), `context_window` (optional), `timeout` (optional) |
218+
| `agent` | Run sub-tasks with the AI agent | `prompt` (required) |
81219

82220
## Architecture
83221

@@ -92,6 +230,101 @@ OpenCode is built with a modular architecture:
92230
- **internal/logging**: Logging infrastructure
93231
- **internal/message**: Message handling
94232
- **internal/session**: Session management
233+
- **internal/lsp**: Language Server Protocol integration
234+
235+
## MCP (Model Context Protocol)
236+
237+
OpenCode implements the Model Context Protocol (MCP) to extend its capabilities through external tools. MCP provides a standardized way for the AI assistant to interact with external services and tools.
238+
239+
### MCP Features
240+
241+
- **External Tool Integration**: Connect to external tools and services via a standardized protocol
242+
- **Tool Discovery**: Automatically discover available tools from MCP servers
243+
- **Multiple Connection Types**:
244+
- **Stdio**: Communicate with tools via standard input/output
245+
- **SSE**: Communicate with tools via Server-Sent Events
246+
- **Security**: Permission system for controlling access to MCP tools
247+
248+
### Configuring MCP Servers
249+
250+
MCP servers are defined in the configuration file under the `mcpServers` section:
251+
252+
```json
253+
{
254+
"mcpServers": {
255+
"example": {
256+
"type": "stdio",
257+
"command": "path/to/mcp-server",
258+
"env": [],
259+
"args": []
260+
},
261+
"web-example": {
262+
"type": "sse",
263+
"url": "https://example.com/mcp",
264+
"headers": {
265+
"Authorization": "Bearer token"
266+
}
267+
}
268+
}
269+
}
270+
```
271+
272+
### MCP Tool Usage
273+
274+
Once configured, MCP tools are automatically available to the AI assistant alongside built-in tools. They follow the same permission model as other tools, requiring user approval before execution.
275+
276+
## LSP (Language Server Protocol)
277+
278+
OpenCode integrates with Language Server Protocol to provide rich code intelligence features across multiple programming languages.
279+
280+
### LSP Features
281+
282+
- **Multi-language Support**: Connect to language servers for different programming languages
283+
- **Code Intelligence**: Get diagnostics, completions, and navigation assistance
284+
- **File Watching**: Automatically notify language servers of file changes
285+
- **Diagnostics**: Display errors, warnings, and hints in your code
286+
287+
### Supported LSP Features
288+
289+
| Feature | Description |
290+
| ----------------- | ----------------------------------- |
291+
| Diagnostics | Error checking and linting |
292+
| Completions | Code suggestions and autocompletion |
293+
| Hover | Documentation on hover |
294+
| Definition | Go to definition |
295+
| References | Find all references |
296+
| Document Symbols | Navigate symbols in current file |
297+
| Workspace Symbols | Search symbols across workspace |
298+
| Formatting | Code formatting |
299+
| Code Actions | Quick fixes and refactorings |
300+
301+
### Configuring LSP
302+
303+
Language servers are configured in the configuration file under the `lsp` section:
304+
305+
```json
306+
{
307+
"lsp": {
308+
"go": {
309+
"disabled": false,
310+
"command": "gopls"
311+
},
312+
"typescript": {
313+
"disabled": false,
314+
"command": "typescript-language-server",
315+
"args": ["--stdio"]
316+
}
317+
}
318+
}
319+
```
320+
321+
### LSP Integration with AI
322+
323+
The AI assistant can access LSP features through the `diagnostics` tool, allowing it to:
324+
325+
- Check for errors in your code
326+
- Suggest fixes based on diagnostics
327+
- Provide intelligent code assistance
95328

96329
## Development
97330

@@ -124,8 +357,16 @@ OpenCode builds upon the work of several open source projects and developers:
124357

125358
## License
126359

127-
[License information coming soon]
360+
OpenCode is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
128361

129362
## Contributing
130363

131-
[Contribution guidelines coming soon]
364+
Contributions are welcome! Here's how you can contribute:
365+
366+
1. Fork the repository
367+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
368+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
369+
4. Push to the branch (`git push origin feature/amazing-feature`)
370+
5. Open a Pull Request
371+
372+
Please make sure to update tests as appropriate and follow the existing code style.

0 commit comments

Comments
 (0)