wip(docs): i18n (#12681)
This commit is contained in:
67
packages/web/src/content/docs/zh-cn/1-0.mdx
Normal file
67
packages/web/src/content/docs/zh-cn/1-0.mdx
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: 遷移到 1.0
|
||||
description: OpenCode 1.0 中的新增内容。
|
||||
---
|
||||
|
||||
OpenCode 1.0完全重写了TUI。
|
||||
|
||||
我们从存在的性能和功能问题的基于 go+bubbletea 的 TUI 迁移到使用 zig+solidjs 编写的内部框架 (OpenTUI)。
|
||||
|
||||
新的 TUI 的工作方式与旧的 TUI 类似,因为它连接到相同的开放代码服务器。
|
||||
|
||||
---
|
||||
|
||||
## 升級中
|
||||
|
||||
如果您當前正在使用以前的版本,則不應自動升級到 1.0
|
||||
版本。然而,一些旧版本的 OpenCode 总是获取最新版本。
|
||||
|
||||
要手動升級,請運行
|
||||
|
||||
```bash
|
||||
$ opencode upgrade 1.0.0
|
||||
```
|
||||
|
||||
要降级回0.x,请运行
|
||||
|
||||
```bash
|
||||
$ opencode upgrade 0.15.31
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 用戶體驗變化
|
||||
|
||||
会话历史记录更加压缩,仅显示编辑和 bash 工具的完整详细信息。
|
||||
|
||||
我们添加了一个命令栏,几乎所有内容都通过了它。按 ctrl+p 可以在任意上下文中调出它并查看您可以执行的所有操作。
|
||||
|
||||
添加了包含有用信息的會話側邊欄(可以切換)。
|
||||
|
||||
我們刪除了一些我們不確定是否有人實際使用的功能。如果缺少重要內容,請提出問題,我們會盡快將其添加回來。
|
||||
|
||||
---
|
||||
|
||||
## 重大變化
|
||||
|
||||
### 按鍵綁定已重命名
|
||||
|
||||
- messages_revert -> messages_undo
|
||||
- switch_agent -> agent_cycle
|
||||
- switch_agent_reverse -> agent_cycle_reverse
|
||||
- switch_mode -> agent_cycle
|
||||
- switch_mode_reverse -> agent_cycle_reverse
|
||||
|
||||
### 按鍵綁定已移除
|
||||
|
||||
- 消息佈局切換
|
||||
- 下一條消息
|
||||
- 上一條消息
|
||||
- 文件差異切換
|
||||
- 文件搜索
|
||||
- 文件關閉
|
||||
- 文件列表
|
||||
- 應用程序幫助
|
||||
- 項目初始化
|
||||
- 工具詳細信息
|
||||
- 思維塊
|
||||
156
packages/web/src/content/docs/zh-cn/acp.mdx
Normal file
156
packages/web/src/content/docs/zh-cn/acp.mdx
Normal file
@@ -0,0 +1,156 @@
|
||||
---
|
||||
title: ACP 支持
|
||||
description: 在任何 ACP 兼容编辑器中使用 OpenCode。
|
||||
---
|
||||
|
||||
OpenCode 支持[代理客户端协议](https://agentclientprotocol.com) 或 (ACP),允许您直接在兼容的编辑器和 IDE 中使用它。
|
||||
|
||||
:::提示
|
||||
有关支持 ACP 的编辑器和工具的列表,请查看[非加太进度进度报告](https://zed.dev/blog/acp-progress-report#available-now)。
|
||||
:::
|
||||
|
||||
ACP 是一种开放协议,用于标准化代码编辑器和 AI 编码代理之间的通信。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
要通过 ACP 使用 OpenCode,须编辑器配置为运行 `opencode acp` 命令。
|
||||
|
||||
该命令将 OpenCode 作为 ACP 兼容的子进程启动,通过 stdio 通过 JSON-RPC 与您的编辑器进行通信。
|
||||
|
||||
以下是支持 ACP 的流行编辑器的示例。
|
||||
|
||||
---
|
||||
|
||||
### 澤德
|
||||
|
||||
添加到您的[泽德](https://zed.dev)配置(`~/.config/zed/settings.json`):
|
||||
|
||||
```json title="~/.config/zed/settings.json"
|
||||
{
|
||||
"agent_servers": {
|
||||
"OpenCode": {
|
||||
"command": "opencode",
|
||||
"args": ["acp"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
要打开它,请使用 **命令面板** 中的 `agent: new thread` 操作。
|
||||
|
||||
您还可以通过编辑`keymap.json`来绑定键盘快捷键:
|
||||
|
||||
```json title="keymap.json"
|
||||
[
|
||||
{
|
||||
"bindings": {
|
||||
"cmd-alt-o": [
|
||||
"agent::NewExternalAgentThread",
|
||||
{
|
||||
"agent": {
|
||||
"custom": {
|
||||
"name": "OpenCode",
|
||||
"command": {
|
||||
"command": "opencode",
|
||||
"args": ["acp"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### JetBrains IDE
|
||||
|
||||
根据[文件](https://www.jetbrains.com/help/ai-assistant/acp.html)添加到你的[JetBrains IDE](https://www.jetbrains.com/) acp.json]:
|
||||
|
||||
```json title="acp.json"
|
||||
{
|
||||
"agent_servers": {
|
||||
"OpenCode": {
|
||||
"command": "/absolute/path/bin/opencode",
|
||||
"args": ["acp"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
要打开它,请在 AI Chat 代理选择器中使用新的“OpenCode”代理。
|
||||
|
||||
---
|
||||
|
||||
### 前衛
|
||||
|
||||
添加到您的[前卫](https://github.com/yetone/avante.nvim)配置:
|
||||
|
||||
```lua
|
||||
{
|
||||
acp_providers = {
|
||||
["opencode"] = {
|
||||
command = "opencode",
|
||||
args = { "acp" }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果需要傳遞環境變量:
|
||||
|
||||
```lua {6-8}
|
||||
{
|
||||
acp_providers = {
|
||||
["opencode"] = {
|
||||
command = "opencode",
|
||||
args = { "acp" },
|
||||
env = {
|
||||
OPENCODE_API_KEY = os.getenv("OPENCODE_API_KEY")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 代码合作者.nvim
|
||||
|
||||
相当于 OpenCode 网关 [代码伙伴.nvim](https://github.com/olimorris/codecompanion.nvim) 中的 ACP 代理,接下来将以下内容添加到 Neovim 配置中:
|
||||
|
||||
```lua
|
||||
require("codecompanion").setup({
|
||||
interactions = {
|
||||
chat = {
|
||||
adapter = {
|
||||
name = "opencode",
|
||||
model = "claude-sonnet-4",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
此配置将 CodeCompanion 设置为使用 OpenCode 作为聊天的 ACP 代理。
|
||||
|
||||
如果您需要交付环境变量(如 `OPENCODE_API_KEY`),请参阅 CodeCompanion.nvim 文档中的 [配置充电器:环境变量Z](https://codecompanion.olimorris.dev/getting-started#setting-an-api-key) 了解完整信息。
|
||||
|
||||
## 支持
|
||||
|
||||
OpenCode 通过 ACP 的工作方式与在终端中的工作方式相同。支持所有功能:
|
||||
|
||||
:::笔记
|
||||
目前不支持某些内置斜杠命令,例如 `/undo` 和 `/redo`。
|
||||
:::
|
||||
|
||||
- 內置工具(文件操作、終端命令等)
|
||||
- 自定義工具和斜杠命令
|
||||
- 在 OpenCode 配置中配置的 MCP 服务器
|
||||
- `AGENTS.md` 的项目特定规则
|
||||
- 自定义程序和 linter
|
||||
- 代理和權限系統
|
||||
747
packages/web/src/content/docs/zh-cn/agents.mdx
Normal file
747
packages/web/src/content/docs/zh-cn/agents.mdx
Normal file
@@ -0,0 +1,747 @@
|
||||
---
|
||||
title: 代理商
|
||||
description: 配置和使用專門的代理。
|
||||
---
|
||||
|
||||
代理是專門的人工智能助手,可以針對特定任務和工作流程進行配置。它們允許您創建具有自定義提示、模型和工具訪問權限的專用工具。
|
||||
|
||||
:::提示
|
||||
使用計劃代理來分析代碼並審查建議,而無需進行任何代碼更改。
|
||||
:::
|
||||
|
||||
您可以在會話期間在代理之間切換,或使用 `@` 提及來調用它們。
|
||||
|
||||
---
|
||||
|
||||
## 類型
|
||||
|
||||
OpenCode有两种类型的代理;主代理和次代理。
|
||||
|
||||
---
|
||||
|
||||
### 主要代理
|
||||
|
||||
主要代理是与您直接交互的主要助手。您可以使用 **Tab** 键或您配置的 `switch_agent` 键绑定循环浏览它们。这些代理处理您的主要对话。工具访问是通过权限配置的 - 例如,“构建”启用了所有工具,而“计划”则受到限制。
|
||||
|
||||
:::提示
|
||||
您可以在会话期间使用 **Tab** 键在主要代理之间进行切换。
|
||||
:::
|
||||
|
||||
OpenCode附带两个内置的主要代理:**Build** 和 **Plan**。地
|
||||
看看下面這些。
|
||||
|
||||
---
|
||||
|
||||
### 子代理
|
||||
|
||||
子代理是主要代理可以調用來執行特定任務的專業助手。您還可以通過在消息中**@提及**它們來手動調用它們。
|
||||
|
||||
OpenCode附带两个内置子代理:**General** 和 **Explore**。我们将在下面看看这个。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
OpenCode附带两个内置主代理和两个内置子代理。
|
||||
|
||||
---
|
||||
|
||||
### 使用構建
|
||||
|
||||
_模式_:`primary`
|
||||
|
||||
構建是啟用所有工具的**默認**主要代理。這是用於需要完全訪問文件操作和系統命令的開發工作的標準代理。
|
||||
|
||||
---
|
||||
|
||||
### 使用計劃
|
||||
|
||||
_模式_:`primary`
|
||||
|
||||
專為規劃和分析而設計的受限代理。我們使用權限系統為您提供更多控制並防止意外更改。
|
||||
默认情况下,以下所有项均设置为`ask`:
|
||||
|
||||
- `file edits`:所有书写、修复和编辑
|
||||
- `bash`:所有 bash 命令
|
||||
|
||||
当您希望 LLM 分析代码、建议更改或创建计划而不是对代码库进行任何实际修改时,此代理非常有用。
|
||||
|
||||
---
|
||||
|
||||
### 使用一般
|
||||
|
||||
_模式_:`subagent`
|
||||
|
||||
用於研究複雜問題和執行多步驟任務的通用代理。具有完整的工具訪問權限(待辦事項除外),因此可以在需要時更改文件。使用它可以並行運行多個工作單元。
|
||||
|
||||
---
|
||||
|
||||
### 使用探索
|
||||
|
||||
_模式_:`subagent`
|
||||
|
||||
用於探索代碼庫的快速只讀代理。無法修改文件。當您需要按模式快速查找文件、搜索代碼中的關鍵字或回答有關代碼庫的問題時,請使用此功能。
|
||||
|
||||
---
|
||||
|
||||
### 使用壓實
|
||||
|
||||
_模式_:`primary`
|
||||
|
||||
隐藏的系统代理,将长上下文压缩为更小的抽象。它会在需要时自动运行,并且无法在 UI 中选择。
|
||||
|
||||
---
|
||||
|
||||
### 使用標題
|
||||
|
||||
_模式_:`primary`
|
||||
|
||||
生成短会话标题的隐藏系统代理。它会自动运行,并且无法在 UI 中选择。
|
||||
|
||||
---
|
||||
|
||||
### 使用總結
|
||||
|
||||
_模式_:`primary`
|
||||
|
||||
创建会话摘要的系统代理。它会自动运行,并且无法在 UI 中选择。
|
||||
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
1. 对于主要代理,请在会话期间使用 **Tab** 键循环浏览它们。您还可以使用配置的 `switch_agent` 键绑定。
|
||||
|
||||
2. 可以調用子代理:
|
||||
- **自動**由主要代理根據其描述執行專門任務。
|
||||
- 通過在消息中**@提及**子代理手動進行。例如。
|
||||
|
||||
```txt frame="none"
|
||||
@general help me search for this function
|
||||
```
|
||||
|
||||
3. **會話之間導航**:當子代理創建自己的子會話時,您可以使用以下命令在父會話和所有子會話之間導航:
|
||||
- **\<Leader>+Right**(或您配置的 `session_child_cycle` 鍵綁定)向前循環父級 → 子級 1 → 子級 2 → ... → 父級
|
||||
- **\<Leader>+Left**(或您配置的 `session_child_cycle_reverse` 鍵綁定)向後循環父級 ← 子級 1 ← 子級 2 ← ... ← 父級
|
||||
|
||||
這使您可以在主要對話和專門的子代理工作之間無縫切換。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以自定義內置代理或通過配置創建您自己的代理。可以通過兩種方式配置代理:
|
||||
|
||||
---
|
||||
|
||||
### JSON
|
||||
|
||||
在 `opencode.json` 配置文件中配置代理:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"build": {
|
||||
"mode": "primary",
|
||||
"model": "anthropic/claude-sonnet-4-20250514",
|
||||
"prompt": "{file:./prompts/build.txt}",
|
||||
"tools": {
|
||||
"write": true,
|
||||
"edit": true,
|
||||
"bash": true
|
||||
}
|
||||
},
|
||||
"plan": {
|
||||
"mode": "primary",
|
||||
"model": "anthropic/claude-haiku-4-20250514",
|
||||
"tools": {
|
||||
"write": false,
|
||||
"edit": false,
|
||||
"bash": false
|
||||
}
|
||||
},
|
||||
"code-reviewer": {
|
||||
"description": "Reviews code for best practices and potential issues",
|
||||
"mode": "subagent",
|
||||
"model": "anthropic/claude-sonnet-4-20250514",
|
||||
"prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
|
||||
"tools": {
|
||||
"write": false,
|
||||
"edit": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 降價
|
||||
|
||||
您还可以使用 Markdown 文件定义代理。将它们放入:
|
||||
|
||||
- 全球:`~/.config/opencode/agents/`
|
||||
- 每个项目:`.opencode/agents/`
|
||||
|
||||
```markdown title="~/.config/opencode/agents/review.md"
|
||||
---
|
||||
description: Reviews code for quality and best practices
|
||||
mode: subagent
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
temperature: 0.1
|
||||
tools:
|
||||
write: false
|
||||
edit: false
|
||||
bash: false
|
||||
---
|
||||
|
||||
You are in code review mode. Focus on:
|
||||
|
||||
- Code quality and best practices
|
||||
- Potential bugs and edge cases
|
||||
- Performance implications
|
||||
- Security considerations
|
||||
|
||||
Provide constructive feedback without making direct changes.
|
||||
```
|
||||
|
||||
Markdown 文件名成为代理名称。例如,`review.md` 创建`review` 代理。
|
||||
|
||||
---
|
||||
|
||||
## 選項
|
||||
|
||||
讓我們詳細看看這些配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 描述
|
||||
|
||||
使用 `description` 选项提供代理的作用以及使用时的简要描述。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"review": {
|
||||
"description": "Reviews code for best practices and potential issues"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這是一個**必需的**配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 溫度
|
||||
|
||||
使用 `temperature` 配置控制 LLM 响应的随机性和创意。
|
||||
|
||||
較低的值使響應更加集中和確定,而較高的值則增加創造力和可變性。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"plan": {
|
||||
"temperature": 0.1
|
||||
},
|
||||
"creative": {
|
||||
"temperature": 0.8
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
溫度值的範圍通常為 0.0 到 1.0:
|
||||
|
||||
- **0.0-0.2**:非常集中且確定的響應,非常適合代碼分析和規劃
|
||||
- **0.3-0.5**:具有一定創造力的平衡響應,適合一般開發任務
|
||||
- **0.6-1.0**:更有創意和多樣化的反應,有助於頭腦風暴和探索
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"analyze": {
|
||||
"temperature": 0.1,
|
||||
"prompt": "{file:./prompts/analysis.txt}"
|
||||
},
|
||||
"build": {
|
||||
"temperature": 0.3
|
||||
},
|
||||
"brainstorm": {
|
||||
"temperature": 0.7,
|
||||
"prompt": "{file:./prompts/creative.txt}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果未指定温度,OpenCode 将使用特定于型号的默认值;大多数型号通常为 0,Qwen 型号为 0.55。
|
||||
|
||||
---
|
||||
|
||||
### 最大步數
|
||||
|
||||
控制代理在被迫僅使用文本響應之前可以執行的最大代理迭代次數。這允許希望控製成本的用戶對代理操作設置限制。
|
||||
|
||||
如果未設置,代理將繼續迭代,直到模型選擇停止或用戶中斷會話。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"quick-thinker": {
|
||||
"description": "Fast reasoning with limited iterations",
|
||||
"prompt": "You are a quick thinker. Solve problems with minimal steps.",
|
||||
"steps": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
當達到限制時,代理會收到特殊的系統提示,指示其響應其工作摘要和建議的剩餘任務。
|
||||
|
||||
:::警告
|
||||
旧版 `maxSteps` 字段已废弃。请改用`steps`。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 禁用
|
||||
|
||||
设置为`true`以取消代理。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"review": {
|
||||
"disable": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 迅速的
|
||||
|
||||
使用 `prompt` 配置为代理指定自定义系统提示文件。提示文件应包含特定于代理目的的说明。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"review": {
|
||||
"prompt": "{file:./prompts/code-review.txt}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
该路径相对于文件所在位置的配置。因此,这适用于全局 OpenCode 配置和项目特定配置。
|
||||
|
||||
---
|
||||
|
||||
### 模型
|
||||
|
||||
使用 `model` 配置此代理的模型。对于使用针对不同任务优化的不同模型很有用。例如,更快的规划模型、更强大的实施模型。
|
||||
|
||||
:::提示
|
||||
如果您不指定模型,主代理将使用[全局配置的模型](/docs/config#models),而子代理将使用调用子代理的主代理的模型。
|
||||
:::
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"plan": {
|
||||
"model": "anthropic/claude-haiku-4-20250514"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
OpenCode配置中的模型ID使用格式`provider/model-id`。例如,如果您使用[开放代码禅](/docs/zen),则您将使用`opencode/gpt-5.1-codex`来表示GPT 5.1 Codex。
|
||||
|
||||
---
|
||||
|
||||
### 工具
|
||||
|
||||
使用 `tools` 配置控制此代理中可用的工具。您可以通过将特定工具设置为 `true` 或 `false` 来启用或禁用特定工具。
|
||||
|
||||
```json title="opencode.json" {3-6,9-12}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"tools": {
|
||||
"write": true,
|
||||
"bash": true
|
||||
},
|
||||
"agent": {
|
||||
"plan": {
|
||||
"tools": {
|
||||
"write": false,
|
||||
"bash": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
:::笔记
|
||||
特定於代理的配置會覆蓋全局配置。
|
||||
:::
|
||||
|
||||
您还可以使用通配符同时控制多个工具。例如,要禁用 MCP 服务器中的所有工具:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"readonly": {
|
||||
"tools": {
|
||||
"mymcp_*": false,
|
||||
"write": false,
|
||||
"edit": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[了解有关工具的更多信息](/docs/tools)。
|
||||
|
||||
---
|
||||
|
||||
### 權限
|
||||
|
||||
您可以配置权限来管理代理可以执行的操作。 目前,`edit`、`bash` 和 `webfetch` 工具的权限可以配置为:
|
||||
|
||||
- `"ask"` — 运行工具提示批准之前
|
||||
- `"allow"` — 尚未批准所有操作
|
||||
- `"deny"` — 取消该工具
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "deny"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您可以覆蓋每個代理的這些權限。
|
||||
|
||||
```json title="opencode.json" {3-5,8-10}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "deny"
|
||||
},
|
||||
"agent": {
|
||||
"build": {
|
||||
"permission": {
|
||||
"edit": "ask"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您还可以在 Markdown 代理中设置权限。
|
||||
|
||||
```markdown title="~/.config/opencode/agents/review.md"
|
||||
---
|
||||
description: Code review without edits
|
||||
mode: subagent
|
||||
permission:
|
||||
edit: deny
|
||||
bash:
|
||||
"*": ask
|
||||
"git diff": allow
|
||||
"git log*": allow
|
||||
"grep *": allow
|
||||
webfetch: deny
|
||||
---
|
||||
|
||||
Only analyze code and suggest changes.
|
||||
```
|
||||
|
||||
您可以设置特定的 bash 命令的权限。
|
||||
|
||||
```json title="opencode.json" {7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"build": {
|
||||
"permission": {
|
||||
"bash": {
|
||||
"git push": "ask",
|
||||
"grep *": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這可以採用全局模式。
|
||||
|
||||
```json title="opencode.json" {7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"build": {
|
||||
"permission": {
|
||||
"bash": {
|
||||
"git *": "ask"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您還可以使用`*`通配符來管理所有命令的權限。
|
||||
由於最後一個匹配規則優先,因此將 `*` 通配符放在前面,將特定規則放在後面。
|
||||
|
||||
```json title="opencode.json" {8}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"build": {
|
||||
"permission": {
|
||||
"bash": {
|
||||
"*": "ask",
|
||||
"git status *": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[了解有关权限的更多信息](/docs/permissions)。
|
||||
|
||||
---
|
||||
|
||||
### 模式
|
||||
|
||||
使用`mode` 配置控制代理的模式。 `mode` 选项用于确定如何使用代理。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"review": {
|
||||
"mode": "subagent"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`mode` 选项可设置为`primary`、`subagent` 或`all`。如果未指定`mode`,则默认为`all`。
|
||||
|
||||
---
|
||||
|
||||
### 隱
|
||||
|
||||
使用`hidden: true`从`@`自动完成菜单隐藏子代理。对于只能由其他代理通过任务工具以编程方式调用的内部子代理很有用。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"internal-helper": {
|
||||
"mode": "subagent",
|
||||
"hidden": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這僅影響自動完成菜單中的用戶可見性。如果權限允許,模型仍然可以通過任務工具調用隱藏代理。
|
||||
|
||||
:::笔记
|
||||
仅适用于`mode: subagent`代理。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 任務權限
|
||||
|
||||
使用`permission.task`控制代理可以通过任务工具调用哪些子代理。使用glob模式进行灵活匹配。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"orchestrator": {
|
||||
"mode": "primary",
|
||||
"permission": {
|
||||
"task": {
|
||||
"*": "deny",
|
||||
"orchestrator-*": "allow",
|
||||
"code-reviewer": "ask"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
当设置为`deny`时,子代理社区任务工具描述中因此完全删除,模型不会尝试调用它。
|
||||
|
||||
:::提示
|
||||
规则按顺序评估,**最后匹配的规则触发**。在上面的示例中,`orchestrator-planner` 匹配`*`(拒绝)和`orchestrator-*`(允许),但由于`orchestrator-*` 位于`*` 之后,因此结果为`allow`。
|
||||
:::
|
||||
|
||||
:::提示
|
||||
用戶始終可以通過 `@` 自動完成菜單直接調用任何子代理,即使代理的任務權限會拒絕它。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 顏色
|
||||
|
||||
在UI中的界面外观中使用`color`选项自定义代理。这会影响代理在界面中的显示方式。
|
||||
|
||||
使用有效的十六进制颜色(例如`#FF5733`)或主题颜色:`primary`、`secondary`、`accent`、`success`、`warning`、`error`、`info`。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"creative": {
|
||||
"color": "#ff6b6b"
|
||||
},
|
||||
"code-reviewer": {
|
||||
"color": "accent"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 顶P
|
||||
|
||||
使用 `top_p` 选项控制响应多样性。控制随机性的温度替代方案。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"agent": {
|
||||
"brainstorm": {
|
||||
"top_p": 0.9
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
值範圍從 0.0 到 1.0。較低的值更加集中,較高的值更加多樣化。
|
||||
|
||||
---
|
||||
|
||||
### 額外的
|
||||
|
||||
您在代理配置中指定的任何其他選項都將作為模型選項**直接**傳遞給提供程序。這允許您使用特定於提供商的功能和參數。
|
||||
|
||||
例如,使用 OpenAI 的推理模型,您可以控制推理工作:
|
||||
|
||||
```json title="opencode.json" {6,7}
|
||||
{
|
||||
"agent": {
|
||||
"deep-thinker": {
|
||||
"description": "Agent that uses high reasoning effort for complex problems",
|
||||
"model": "openai/gpt-5",
|
||||
"reasoningEffort": "high",
|
||||
"textVerbosity": "low"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這些附加選項是特定於型號和提供商的。檢查提供商的文檔以獲取可用參數。
|
||||
|
||||
:::提示
|
||||
运行 `opencode models` 查看可用模型的列表。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 創建代理
|
||||
|
||||
您可以使用以下命令創建新代理:
|
||||
|
||||
```bash
|
||||
opencode agent create
|
||||
```
|
||||
|
||||
此交互式命令將:
|
||||
|
||||
1. 詢問代理保存在哪裡;全局或特定項目。
|
||||
2. 描述代理應該做什麼。
|
||||
3. 生成適當的系統提示和標識符。
|
||||
4. 讓您選擇代理可以訪問哪些工具。
|
||||
5. 最后,使用代理配置创建一个markdown文件。
|
||||
|
||||
---
|
||||
|
||||
## 使用案例
|
||||
|
||||
以下是不同代理的一些常見用例。
|
||||
|
||||
- **構建代理**:啟用所有工具的完整開發工作
|
||||
- **規劃代理**:分析規劃,不做改動
|
||||
- **審查代理**:具有隻讀訪問權限和文檔工具的代碼審查
|
||||
- **调试代理**:专注于启用bash和读取工具的调查
|
||||
- **文檔代理**:使用文件操作但不使用系統命令的文檔編寫
|
||||
|
||||
---
|
||||
|
||||
## 示例
|
||||
|
||||
以下是一些您可能會覺得有用的示例代理。
|
||||
|
||||
:::提示
|
||||
您有想要分享的经纪人吗? [提交 PR](https://github.com/anomalyco/opencode)。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 文件代理
|
||||
|
||||
```markdown title="~/.config/opencode/agents/docs-writer.md"
|
||||
---
|
||||
description: Writes and maintains project documentation
|
||||
mode: subagent
|
||||
tools:
|
||||
bash: false
|
||||
---
|
||||
|
||||
You are a technical writer. Create clear, comprehensive documentation.
|
||||
|
||||
Focus on:
|
||||
|
||||
- Clear explanations
|
||||
- Proper structure
|
||||
- Code examples
|
||||
- User-friendly language
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 安全審核員
|
||||
|
||||
```markdown title="~/.config/opencode/agents/security-auditor.md"
|
||||
---
|
||||
description: Performs security audits and identifies vulnerabilities
|
||||
mode: subagent
|
||||
tools:
|
||||
write: false
|
||||
edit: false
|
||||
---
|
||||
|
||||
You are a security expert. Focus on identifying potential security issues.
|
||||
|
||||
Look for:
|
||||
|
||||
- Input validation vulnerabilities
|
||||
- Authentication and authorization flaws
|
||||
- Data exposure risks
|
||||
- Dependency vulnerabilities
|
||||
- Configuration security issues
|
||||
```
|
||||
601
packages/web/src/content/docs/zh-cn/cli.mdx
Normal file
601
packages/web/src/content/docs/zh-cn/cli.mdx
Normal file
@@ -0,0 +1,601 @@
|
||||
---
|
||||
title: 命令行界面
|
||||
description: OpenCode CLI 选项和命令。
|
||||
---
|
||||
|
||||
import { Tabs, TabItem } from "@astrojs/starlight/components"
|
||||
|
||||
默认情况下,OpenCode CLI 在不带任何参数运行时启动[途径易](/docs/tui)。
|
||||
|
||||
```bash
|
||||
opencode
|
||||
```
|
||||
|
||||
但它也接受允许本页记录的命令。这您以Smashing方式与OpenCode交互。
|
||||
|
||||
```bash
|
||||
opencode run "Explain how closures work in JavaScript"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 推
|
||||
|
||||
启动OpenCode用户终端界面。
|
||||
|
||||
```bash
|
||||
opencode [project]
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| ------------ | ----- | ------------------------------------------ |
|
||||
| `--continue` | `-c` | 继续上期 |
|
||||
| `--session` | `-s` | 会话 ID 继续 |
|
||||
| `--prompt` | |提示使用|
|
||||
| `--model` | `-m` |以提供者/模型形式使用的模型 |
|
||||
| `--agent` | |代理使用|
|
||||
| `--port` | | 监听端口 |
|
||||
| `--hostname` | | 监听的主机名 |
|
||||
|
||||
---
|
||||
|
||||
## 命令
|
||||
|
||||
OpenCode CLI 还具有以下命令。
|
||||
|
||||
---
|
||||
|
||||
### 代理人
|
||||
|
||||
管理 OpenCode 代理。
|
||||
|
||||
```bash
|
||||
opencode agent [command]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 附
|
||||
|
||||
将终端通过 `serve` 或 `web` 命令启动已运行的 OpenCode 耳机服务器。
|
||||
|
||||
```bash
|
||||
opencode attach [url]
|
||||
```
|
||||
|
||||
这允许将 TUI 与远程 OpenCode 钱包一起使用。例如:
|
||||
|
||||
```bash
|
||||
# Start the backend server for web/mobile access
|
||||
opencode web --port 4096 --hostname 0.0.0.0
|
||||
|
||||
# In another terminal, attach the TUI to the running backend
|
||||
opencode attach http://10.20.30.40:4096
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| ----------- | ----- | --------------------------------- |
|
||||
| `--dir` | |启动 TUI 的工作目录 |
|
||||
| `--session` | `-s` | 会话 ID 继续 |
|
||||
|
||||
---
|
||||
|
||||
#### 創造
|
||||
|
||||
使用自定義配置創建新代理。
|
||||
|
||||
```bash
|
||||
opencode agent create
|
||||
```
|
||||
|
||||
此命令將指導您使用自定義系統提示和工具配置創建新代理。
|
||||
|
||||
---
|
||||
|
||||
#### 列表
|
||||
|
||||
列出所有可用的代理。
|
||||
|
||||
```bash
|
||||
opencode agent list
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 授權
|
||||
|
||||
用於管理提供商的憑據和登錄的命令。
|
||||
|
||||
```bash
|
||||
opencode auth [command]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 登入
|
||||
|
||||
OpenCode 由 [模型.dev](https://models.dev) 上的型号列表提供支持,因此您可以使用 `opencode auth login` 来为您想要使用的任何型号配置 API 按键。它存储在 `~/.local/share/opencode/auth.json` 中。
|
||||
|
||||
```bash
|
||||
opencode auth login
|
||||
```
|
||||
|
||||
当OpenCode启动时,它会从会计文件加载提供程序。如果您的环境中定义了任何按键或项目中的`.env`文件。
|
||||
|
||||
---
|
||||
|
||||
#### 列表
|
||||
|
||||
列出憑證文件中存儲的所有經過身份驗證的提供程序。
|
||||
|
||||
```bash
|
||||
opencode auth list
|
||||
```
|
||||
|
||||
或者簡短的版本。
|
||||
|
||||
```bash
|
||||
opencode auth ls
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 註銷
|
||||
|
||||
通過從憑據文件中清除提供程序,將您從提供程序中註銷。
|
||||
|
||||
```bash
|
||||
opencode auth logout
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### github
|
||||
|
||||
管理 GitHub 代理以实现存储库自动化。
|
||||
|
||||
```bash
|
||||
opencode github [command]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 安裝
|
||||
|
||||
在您的存储库中安装 GitHub 代理。
|
||||
|
||||
```bash
|
||||
opencode github install
|
||||
```
|
||||
|
||||
这将设置必要的 GitHub Actions 工作流程并指导您完成配置过程。 [了解更多](/docs/github)。
|
||||
|
||||
---
|
||||
|
||||
#### 跑步
|
||||
|
||||
运行 GitHub 代理。这通常用在 GitHub Actions 中。
|
||||
|
||||
```bash
|
||||
opencode github run
|
||||
```
|
||||
|
||||
##### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| --------- | -------------------------------------- |
|
||||
| `--event` | 用于运行代理的 GitHub 模拟事件 |
|
||||
| `--token` | GitHub 个人访问令牌 |
|
||||
|
||||
---
|
||||
|
||||
### MCP
|
||||
|
||||
管理模型上下文協議服務器。
|
||||
|
||||
```bash
|
||||
opencode mcp [command]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 添加
|
||||
|
||||
将 MCP 服务器添加到您的配置中。
|
||||
|
||||
```bash
|
||||
opencode mcp add
|
||||
```
|
||||
|
||||
此命令将指导您添加本地或远程 MCP 服务器。
|
||||
|
||||
---
|
||||
|
||||
#### 列表
|
||||
|
||||
列出所有已配置的 MCP 服务器及其连接状态。
|
||||
|
||||
```bash
|
||||
opencode mcp list
|
||||
```
|
||||
|
||||
或者使用簡短版本。
|
||||
|
||||
```bash
|
||||
opencode mcp ls
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 授權
|
||||
|
||||
使用启用 OAuth 的 MCP 服务器进行身份验证。
|
||||
|
||||
```bash
|
||||
opencode mcp auth [name]
|
||||
```
|
||||
|
||||
如果您不提供服务器名称,系统将提示您从可用的支持 OAuth 的服务器中进行选择。
|
||||
|
||||
您还可以开始支持 OAuth 的及其服务器身份验证状态。
|
||||
|
||||
```bash
|
||||
opencode mcp auth list
|
||||
```
|
||||
|
||||
或者使用簡短版本。
|
||||
|
||||
```bash
|
||||
opencode mcp auth ls
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 註銷
|
||||
|
||||
删除 MCP 服务器的 OAuth 工具。
|
||||
|
||||
```bash
|
||||
opencode mcp logout [name]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 偵錯
|
||||
|
||||
调试MCP服务器的OAuth连接问题。
|
||||
|
||||
```bash
|
||||
opencode mcp debug <name>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 型號
|
||||
|
||||
列出已配置提供商的所有可用模型。
|
||||
|
||||
```bash
|
||||
opencode models [provider]
|
||||
```
|
||||
|
||||
此命令以 `provider/model` 格式显示您配置的提供程序中可用的所有模型。
|
||||
|
||||
这对于确定[你的配置](/docs/config/)中使用的意图模型名称很有用。
|
||||
|
||||
您可以选择提供项目ID并按该提供项目筛选模型。
|
||||
|
||||
```bash
|
||||
opencode models anthropic
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| ----------- | ------------------------------------------------------------ |
|
||||
| `--refresh` |来自 models.dev | 刷新模型存储
|
||||
| `--verbose` |使用更详细的模型输出(包括成本等元数据)|
|
||||
|
||||
使用`--refresh`标志来更新服务器的模型列表。当新模型已添加到提供程序并且您希望在OpenCode中查看它们时,这非常有用。
|
||||
|
||||
```bash
|
||||
opencode models --refresh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 跑步
|
||||
|
||||
通过直接传递提示以非交互模式运行 opencode。
|
||||
|
||||
```bash
|
||||
opencode run [message..]
|
||||
```
|
||||
|
||||
这对于编写脚本、自动化,或者当您想要快速获得答案而不是完整的 TUI 时非常有用。例如。
|
||||
|
||||
```bash "opencode run"
|
||||
opencode run Explain the use of context in Go
|
||||
```
|
||||
|
||||
您还可以添加到正在运行的`opencode serve`实例,会员每次运行时MCP服务器冷启动时间:
|
||||
|
||||
```bash
|
||||
# Start a headless server in one terminal
|
||||
opencode serve
|
||||
|
||||
# In another terminal, run commands that attach to it
|
||||
opencode run --attach http://localhost:4096 "Explain async/await in JavaScript"
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| ------------ | ----- | ------------------------------------------------------------------ |
|
||||
| `--command` | | 要运行的命令,使用消息作为参数 |
|
||||
| `--continue` | `-c` | 继续上期 |
|
||||
| `--session` | `-s` | 会话 ID 继续 |
|
||||
| `--share` | |分享会议|
|
||||
| `--model` | `-m` |以提供者/模型形式使用的模型 |
|
||||
| `--agent` | |代理使用|
|
||||
| `--file` | `-f` |要附加到消息的文件 |
|
||||
| `--format` | |格式:默认(格式化)或json(原始JSON事件)|
|
||||
| `--title` | |会话标题(如果未提供值,则使用断断的提示)|
|
||||
| `--attach` | | 连接到正在运行的 opencode 服务器(例如,http://localhost:4096)|
|
||||
| `--port` | |本地服务器的端口(默认为随机端口) |
|
||||
|
||||
---
|
||||
|
||||
### 服務
|
||||
|
||||
启动无头OpenCode服务器以进行API访问。查看[服务器文档](/docs/server)以获取完整的HTTP 接口。
|
||||
|
||||
```bash
|
||||
opencode serve
|
||||
```
|
||||
|
||||
这将启动一个 HTTP 服务器,该服务器提供对 opencode 功能的 API 访问,并占用 TUI 接口。设置 `OPENCODE_SERVER_PASSWORD` 以启用 HTTP 基本身份验证(用户名默认为 `opencode`)。
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| ------------ | ------------------------------------------ |
|
||||
| `--port` |监听端口|
|
||||
| `--hostname` | 监听的主机名 |
|
||||
| `--mdns` | 启用 mDNS 发现 |
|
||||
| `--cors` | 允许 CORS 的其他浏览器源 |
|
||||
|
||||
---
|
||||
|
||||
### 會議
|
||||
|
||||
管理 OpenCode 会话。
|
||||
|
||||
```bash
|
||||
opencode session [command]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 列表
|
||||
|
||||
列出所有 OpenCode 会话。
|
||||
|
||||
```bash
|
||||
opencode session list
|
||||
```
|
||||
|
||||
##### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| ------------- | ----- | ------------------------------------ |
|
||||
| `--max-count` | `-n` | 限制为最近的 N 个会话 |
|
||||
| `--format` | | 输出格式:table 或 json(table) |
|
||||
|
||||
---
|
||||
|
||||
### 統計數據
|
||||
|
||||
显示OpenCode会话的令牌使用情况和成本统计信息。
|
||||
|
||||
```bash
|
||||
opencode stats
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| ----------- | --------------------------------------------------------------------------- |
|
||||
| `--days` | 显示过去N天(所有时间)的统计数据|
|
||||
| `--tools` | 显示工具数量(全部)|
|
||||
| `--models` | 隐藏显示模型使用情况解读(默认)。输入一个数字来显示前 N |
|
||||
| `--project` |按项目过滤(所有项目,空字符串:当前项目)|
|
||||
|
||||
---
|
||||
|
||||
### 出口
|
||||
|
||||
将会话数据导出为JSON。
|
||||
|
||||
```bash
|
||||
opencode export [sessionID]
|
||||
```
|
||||
|
||||
如果您不提供会话 ID,系统将提示您从可用的会话中进行选择。
|
||||
|
||||
---
|
||||
|
||||
### 進口
|
||||
|
||||
从 JSON 文件或 OpenCode 共享 URL 导入会话数据。
|
||||
|
||||
```bash
|
||||
opencode import <file>
|
||||
```
|
||||
|
||||
您可以从本地文件或 OpenCode 共享 URL 导入。
|
||||
|
||||
```bash
|
||||
opencode import session.json
|
||||
opencode import https://opncd.ai/s/abc123
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 網絡
|
||||
|
||||
使用Web界面启动无头OpenCode服务器。
|
||||
|
||||
```bash
|
||||
opencode web
|
||||
```
|
||||
|
||||
这将启动HTTP服务器并打开Web浏览器以通过Web界面访问OpenCode。设置`OPENCODE_SERVER_PASSWORD`以启用HTTP基本身份验证(用户名默认为`opencode`)。
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| ------------ | ------------------------------------------ |
|
||||
| `--port` |监听端口|
|
||||
| `--hostname` | 监听的主机名 |
|
||||
| `--mdns` | 启用 mDNS 发现 |
|
||||
| `--cors` | 允许 CORS 的其他浏览器源 |
|
||||
|
||||
---
|
||||
|
||||
### 丙烯酰胺
|
||||
|
||||
启动ACP(代理客户端协议)服务器。
|
||||
|
||||
```bash
|
||||
opencode acp
|
||||
```
|
||||
|
||||
此启动一个ACP服务器,该服务器使用nd-JSON通过stdin/stdout进行通信命令。
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|描述 |
|
||||
| ------------ | --------------------- |
|
||||
| `--cwd` |工作目录 |
|
||||
| `--port` |监听端口|
|
||||
| `--hostname` | 监听的主机名 |
|
||||
|
||||
---
|
||||
|
||||
### 解除安裝
|
||||
|
||||
卸载OpenCode并删除所有相关文件。
|
||||
|
||||
```bash
|
||||
opencode uninstall
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| --------------- | ----- | ------------------------------------------- |
|
||||
| `--keep-config` | `-c` |保留配置文件|
|
||||
| `--keep-data` | `-d` | 保留会话数据和快照|
|
||||
| `--dry-run` | |在显示不删除的情况下将删除的内容 |
|
||||
| `--force` | `-f` | 跳过确认提示 |
|
||||
|
||||
---
|
||||
|
||||
### 升級
|
||||
|
||||
将 opencode 更新到最新版本或特定版本。
|
||||
|
||||
```bash
|
||||
opencode upgrade [target]
|
||||
```
|
||||
|
||||
升級到最新版本。
|
||||
|
||||
```bash
|
||||
opencode upgrade
|
||||
```
|
||||
|
||||
升級到特定版本。
|
||||
|
||||
```bash
|
||||
opencode upgrade v0.1.48
|
||||
```
|
||||
|
||||
#### 旗幟
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| ---------- | ----- | ----------------------------------------------------------------- |
|
||||
| `--method` | `-m` |使用的安装方法;卷曲、npm、pnpm、bun、brew |
|
||||
|
||||
---
|
||||
|
||||
## 全球旗幟
|
||||
|
||||
opencode CLI采用以下全局标志。
|
||||
|
||||
|旗幟|短|描述 |
|
||||
| -------------- | ----- | ------------------------------------ |
|
||||
| `--help` | `-h` | 显示帮助|
|
||||
| `--version` | `-v` | 打印版本号 |
|
||||
| `--print-logs` | |将日志打印到stderr |
|
||||
| `--log-level` | |日志级别(调试、信息、警告、错误)|
|
||||
|
||||
---
|
||||
|
||||
## 環境變量
|
||||
|
||||
可以使用环境变量配置OpenCode。
|
||||
|
||||
|變量|類型 |描述 |
|
||||
| ------------------------------------- | ------- | ------------------------------------------------- |
|
||||
| `OPENCODE_AUTO_SHARE` | 布尔 | 自动共享会话 |
|
||||
| `OPENCODE_GIT_BASH_PATH` |字符串| Windows 上 Git Bash 可执行文件的路径 |
|
||||
| `OPENCODE_CONFIG` |字符串|配置文件路径 |
|
||||
| `OPENCODE_CONFIG_DIR` |字符串|配置目录的路径 |
|
||||
| `OPENCODE_CONFIG_CONTENT` |字符串|内联 json 配置内容 |
|
||||
| `OPENCODE_DISABLE_AUTOUPDATE` | 布尔 | 取消自动更新检查 |
|
||||
| `OPENCODE_DISABLE_PRUNE` | 布尔 | 取消数据的裁剪 |
|
||||
| `OPENCODE_DISABLE_TERMINAL_TITLE` | 布尔 | 取消自动终端标题更新 |
|
||||
| `OPENCODE_PERMISSION` |字符串|内联 json 权限配置 |
|
||||
| `OPENCODE_DISABLE_DEFAULT_PLUGINS` | 布尔 | 取消默认插件 |
|
||||
| `OPENCODE_DISABLE_LSP_DOWNLOAD` | 布尔 | 禁用自动 LSP 服务器下载 |
|
||||
| `OPENCODE_ENABLE_EXPERIMENTAL_MODELS` | 布尔 | 制作实验模型 |
|
||||
| `OPENCODE_DISABLE_AUTOCOMPACT` |布尔|取消自动上下文压缩|
|
||||
| `OPENCODE_DISABLE_CLAUDE_CODE` | 布尔 | 禁止从 `.claude` 读取(提示+技巧)|
|
||||
| `OPENCODE_DISABLE_CLAUDE_CODE_PROMPT` | 布尔 | 禁用读取`~/.claude/CLAUDE.md` |
|
||||
| `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS` | 布尔 | 禁用加载`.claude/skills` |
|
||||
| `OPENCODE_DISABLE_MODELS_FETCH` | 布尔 | 禁止从远程源获取模型 |
|
||||
| `OPENCODE_FAKE_VCS` |字符串|用于测试目的的假 VCS 成立 |
|
||||
| `OPENCODE_DISABLE_FILETIME_CHECK` |布尔|取消文件时间检查以进行优化|
|
||||
| `OPENCODE_CLIENT` |字符串|客户端标识符(默认为`cli`)|
|
||||
| `OPENCODE_ENABLE_EXA` | 布尔 | 启用 Exa 网络搜索工具 |
|
||||
| `OPENCODE_SERVER_PASSWORD` |字符串|为 `serve`/`web` 赠送基本身份验证 |
|
||||
| `OPENCODE_SERVER_USERNAME` |字符串|覆盖基本身份验证用户名(默认`opencode`)|
|
||||
| `OPENCODE_MODELS_URL` |字符串|用于获取模型配置的自定义 URL |
|
||||
|
||||
---
|
||||
|
||||
### 實驗性的
|
||||
|
||||
這些環境變量啟用可能會更改或刪除的實驗性功能。
|
||||
|
||||
|變量|類型 |描述 |
|
||||
| ----------------------------------------------- | ------- | --------------------------------------- |
|
||||
| `OPENCODE_EXPERIMENTAL` | 布尔 | 实现所有实验性功能 |
|
||||
| `OPENCODE_EXPERIMENTAL_ICON_DISCOVERY` | 布尔 | 新增图标发现 |
|
||||
| `OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT` | 布尔 | 在 TUI 中禁用选择时复制 |
|
||||
| `OPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS` | 数量 | bash 命令的默认超时(以毫秒为单位) |
|
||||
| `OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX` | 数量 | LLM 响应的最大输出令牌 | LLM
|
||||
| `OPENCODE_EXPERIMENTAL_FILEWATCHER` | 布尔 | 为整个目录启用文件观察器 |
|
||||
| `OPENCODE_EXPERIMENTAL_OXFMT` |布尔 | 启用 oxfmt 清理程序 |
|
||||
| `OPENCODE_EXPERIMENTAL_LSP_TOOL` | 布尔 | 实现实验性 LSP 工具 |
|
||||
| `OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER` | 布尔 | 禁用文件观察器 |
|
||||
| `OPENCODE_EXPERIMENTAL_EXA` |布尔 | 实现实验性Exa功能 |
|
||||
| `OPENCODE_EXPERIMENTAL_LSP_TY` |布尔 | 实现实验性 LSP 类型检查 |
|
||||
| `OPENCODE_EXPERIMENTAL_MARKDOWN` | 布尔 | 实现实验性 Markdown 功能 |
|
||||
| `OPENCODE_EXPERIMENTAL_PLAN_MODE` |布尔 |启用计划模式 |
|
||||
323
packages/web/src/content/docs/zh-cn/commands.mdx
Normal file
323
packages/web/src/content/docs/zh-cn/commands.mdx
Normal file
@@ -0,0 +1,323 @@
|
||||
---
|
||||
title: 命令
|
||||
description: 為重複任務創建自定義命令。
|
||||
---
|
||||
|
||||
自定义命令允许您指定在 TUI 中执行该命令时要运行的提示。
|
||||
|
||||
```bash frame="none"
|
||||
/my-command
|
||||
```
|
||||
|
||||
除了`/init`、`/undo`、`/redo`、`/share`、`/help`等内置命令之外,还有自定义命令。 [了解更多](/docs/tui#commands)。
|
||||
|
||||
---
|
||||
|
||||
## 創建命令文件
|
||||
|
||||
在`commands/`目录中创建markdown文件来定义自定义命令。
|
||||
|
||||
创建`.opencode/commands/test.md`:
|
||||
|
||||
```md title=".opencode/commands/test.md"
|
||||
---
|
||||
description: Run tests with coverage
|
||||
agent: build
|
||||
model: anthropic/claude-3-5-sonnet-20241022
|
||||
---
|
||||
|
||||
Run the full test suite with coverage report and show any failures.
|
||||
Focus on the failing tests and suggest fixes.
|
||||
```
|
||||
|
||||
frontmatter 定义命令属性。内容成为模板。
|
||||
|
||||
通過鍵入 `/` 後跟命令名稱來使用該命令。
|
||||
|
||||
```bash frame="none"
|
||||
"/test"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以通过 OpenCode 配置或通过在 `commands/` 目录中创建 markdown 文件来添加自定义命令。
|
||||
|
||||
---
|
||||
|
||||
### JSON
|
||||
|
||||
在 OpenCode [配置](/docs/config) 中使用 `command` 选项:
|
||||
|
||||
```json title="opencode.jsonc" {4-12}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"command": {
|
||||
// This becomes the name of the command
|
||||
"test": {
|
||||
// This is the prompt that will be sent to the LLM
|
||||
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
|
||||
// This is shown as the description in the TUI
|
||||
"description": "Run tests with coverage",
|
||||
"agent": "build",
|
||||
"model": "anthropic/claude-3-5-sonnet-20241022"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
现在您可以在 TUI 中运行这个命令:
|
||||
|
||||
```bash frame="none"
|
||||
/test
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 降價
|
||||
|
||||
您还可以使用 Markdown 文件定义命令。将它们放入:
|
||||
|
||||
- 全球:`~/.config/opencode/commands/`
|
||||
- 每个项目:`.opencode/commands/`
|
||||
|
||||
```markdown title="~/.config/opencode/commands/test.md"
|
||||
---
|
||||
description: Run tests with coverage
|
||||
agent: build
|
||||
model: anthropic/claude-3-5-sonnet-20241022
|
||||
---
|
||||
|
||||
Run the full test suite with coverage report and show any failures.
|
||||
Focus on the failing tests and suggest fixes.
|
||||
```
|
||||
|
||||
Markdown 文件名成为命令名。例如,`test.md` 让
|
||||
你運行:
|
||||
|
||||
```bash frame="none"
|
||||
/test
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 提示配置
|
||||
|
||||
自定義命令的提示支持幾個特殊的佔位符和語法。
|
||||
|
||||
---
|
||||
|
||||
### 論據
|
||||
|
||||
使用`$ARGUMENTS`占位符将参数提交给命令。
|
||||
|
||||
```md title=".opencode/commands/component.md"
|
||||
---
|
||||
description: Create a new component
|
||||
---
|
||||
|
||||
Create a new React component named $ARGUMENTS with TypeScript support.
|
||||
Include proper typing and basic structure.
|
||||
```
|
||||
|
||||
使用參數運行命令:
|
||||
|
||||
```bash frame="none"
|
||||
/component Button
|
||||
```
|
||||
|
||||
`$ARGUMENTS` 将替换为 `Button`。
|
||||
|
||||
您還可以使用位置參數訪問各個參數:
|
||||
|
||||
- `$1` - 第一個參數
|
||||
- `$2` - 第二個參數
|
||||
- `$3` - 第三個參數
|
||||
- 等等...
|
||||
|
||||
例如:
|
||||
|
||||
```md title=".opencode/commands/create-file.md"
|
||||
---
|
||||
description: Create a new file with content
|
||||
---
|
||||
|
||||
Create a file named $1 in the directory $2
|
||||
with the following content: $3
|
||||
```
|
||||
|
||||
運行命令:
|
||||
|
||||
```bash frame="none"
|
||||
/create-file config.json src "{ \"key\": \"value\" }"
|
||||
```
|
||||
|
||||
這取代了:
|
||||
|
||||
- `$1` 与 `config.json`
|
||||
- `$2` 与 `src`
|
||||
- `$3` 与 `{ "key": "value" }`
|
||||
|
||||
---
|
||||
|
||||
### 外殼輸出
|
||||
|
||||
使用 _!`command`_ 将 [bash命令](/docs/tui#bash-commands) 输出注入到提示符中。
|
||||
|
||||
例如,要創建分析測試覆蓋率的自定義命令:
|
||||
|
||||
```md title=".opencode/commands/analyze-coverage.md"
|
||||
---
|
||||
description: Analyze test coverage
|
||||
---
|
||||
|
||||
Here are the current test results:
|
||||
!`npm test`
|
||||
|
||||
Based on these results, suggest improvements to increase coverage.
|
||||
```
|
||||
|
||||
或者查看最近的更改:
|
||||
|
||||
```md title=".opencode/commands/review-changes.md"
|
||||
---
|
||||
description: Review recent changes
|
||||
---
|
||||
|
||||
Recent git commits:
|
||||
!`git log --oneline -10`
|
||||
|
||||
Review these changes and suggest any improvements.
|
||||
```
|
||||
|
||||
命令在項目的根目錄中運行,其輸出成為提示的一部分。
|
||||
|
||||
---
|
||||
|
||||
### 文件參考
|
||||
|
||||
使用 `@` 後跟文件名將文件包含在命令中。
|
||||
|
||||
```md title=".opencode/commands/review-component.md"
|
||||
---
|
||||
description: Review component
|
||||
---
|
||||
|
||||
Review the component in @src/components/Button.tsx.
|
||||
Check for performance issues and suggest improvements.
|
||||
```
|
||||
|
||||
文件內容會自動包含在提示中。
|
||||
|
||||
---
|
||||
|
||||
## 選項
|
||||
|
||||
讓我們詳細看看配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 模板
|
||||
|
||||
`template` 选项定义执行命令时将发送到 LLM 的提示。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"command": {
|
||||
"test": {
|
||||
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes."
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這是一個**必需的**配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 描述
|
||||
|
||||
使用 `description` 选项提供命令功能的简要描述。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"command": {
|
||||
"test": {
|
||||
"description": "Run tests with coverage"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
当您输入命令时,这将在 TUI 中显示为描述。
|
||||
|
||||
---
|
||||
|
||||
### 代理人
|
||||
|
||||
使用`agent`配置选择指定哪个[代理人](/docs/agents)应执行此命令。
|
||||
如果是 [子代理](/docs/agents/#subagents) 该命令将默认触发子代理调用。
|
||||
要取消此行为,则将`subtask`设置为`false`。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"command": {
|
||||
"review": {
|
||||
"agent": "plan"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這是一個**可選**配置選項。如果未指定,則默認為您當前的代理。
|
||||
|
||||
---
|
||||
|
||||
### 子任務
|
||||
|
||||
使用`subtask`布尔值强制命令触发[子代理](/docs/agents/#subagents)调用。
|
||||
如果您希望命令不污染您的主要上下文並且將**強制**代理充當子代理,那麼這非常有用,
|
||||
即使`mode`在[代理人](/docs/agents)配置上设置为`primary`。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"command": {
|
||||
"analyze": {
|
||||
"subtask": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這是一個**可選**配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 模型
|
||||
|
||||
使用 `model` 配置覆盖此命令的默认模型。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"command": {
|
||||
"analyze": {
|
||||
"model": "anthropic/claude-3-5-sonnet-20241022"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
這是一個**可選**配置選項。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
opencode包含`/init`、`/undo`、`/redo`、`/share`、`/help`等内置命令;【了解更多](/docs/tui#commands)。
|
||||
|
||||
:::笔记
|
||||
自定義命令可以覆蓋內置命令。
|
||||
:::
|
||||
|
||||
如果您定義同名的自定義命令,它將覆蓋內置命令。
|
||||
685
packages/web/src/content/docs/zh-cn/config.mdx
Normal file
685
packages/web/src/content/docs/zh-cn/config.mdx
Normal file
@@ -0,0 +1,685 @@
|
||||
---
|
||||
title: 配置
|
||||
description: 使用 OpenCode JSON 配置。
|
||||
---
|
||||
|
||||
您可以使用 JSON 配置文件配置 OpenCode。
|
||||
|
||||
---
|
||||
|
||||
## 格式
|
||||
|
||||
OpenCode 支持 **JSON** 和 **JSONC**(带注释的 JSON)格式。
|
||||
|
||||
```jsonc title="opencode.jsonc"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
// Theme configuration
|
||||
"theme": "opencode",
|
||||
"model": "anthropic/claude-sonnet-4-5",
|
||||
"autoupdate": true,
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 地點
|
||||
|
||||
您可以將配置放置在幾個不同的位置,它們有一個
|
||||
不同的優先順序。
|
||||
|
||||
:::笔记
|
||||
配置文件**合併在一起**,而不是替換。
|
||||
:::
|
||||
|
||||
配置文件被合併在一起,而不是被替換。以下配置位置的設置被合併。僅當密鑰衝突時,後面的配置才會覆蓋前面的配置。保留所有配置中的非衝突設置。
|
||||
|
||||
例如,如果您的全局配置设置`theme: "opencode"`和`autoupdate: true`,并且您的项目配置设置ZZPH最终2ZZ,则配置将包括所有三个设置。
|
||||
|
||||
---
|
||||
|
||||
### 優先順序
|
||||
|
||||
配置源按以下順序加載(後面的源覆蓋前面的源):
|
||||
|
||||
1. **远程配置**(来自`.well-known/opencode`)-组织默认值
|
||||
2. **全局配置** (`~/.config/opencode/opencode.json`) - 用户首选项
|
||||
3. **自定义配置** (`OPENCODE_CONFIG` env var) - 自定义覆盖
|
||||
4. **项目配置**(项目中的`opencode.json`)- 项目特定的设置
|
||||
5. **`.opencode` 目录** - 代理、命令、插件
|
||||
6. **内联配置** (`OPENCODE_CONFIG_CONTENT` env var) - 运行时覆盖
|
||||
|
||||
這意味著項目配置可以覆蓋全局默認值,全局配置可以覆蓋遠程組織默認值。
|
||||
|
||||
:::笔记
|
||||
`.opencode` 和`~/.config/opencode` 目录对子目录使用**复数名称**:`agents/`、`commands/`、`modes/`、`plugins/`、`skills/`、`tools/` 和`themes/`。为了坚固兼容,还支持单数名称(例如`agent/`)。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 偏僻的
|
||||
|
||||
组织可以通过 `.well-known/opencode` 端点提供默认配置。当您向支持的成功进行身份验证时,会自动获取该信息。
|
||||
|
||||
首先加載遠程配置,作為基礎層。所有其他配置源(全局、項目)都可以覆蓋這些默認值。
|
||||
|
||||
例如,如果您的组织提供默认取消的 MCP 服务器:
|
||||
|
||||
```json title="Remote config from .well-known/opencode"
|
||||
{
|
||||
"mcp": {
|
||||
"jira": {
|
||||
"type": "remote",
|
||||
"url": "https://jira.example.com/mcp",
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您可以在本地配置中啟用特定服務器:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"mcp": {
|
||||
"jira": {
|
||||
"type": "remote",
|
||||
"url": "https://jira.example.com/mcp",
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 全球的
|
||||
|
||||
将全局 OpenCode 配置放在 `~/.config/opencode/opencode.json` 中。使用全局配置来实现用户范围的首选项,例如主题、提供程序或按键绑定。
|
||||
|
||||
全局配置覆蓋遠程組織默認值。
|
||||
|
||||
---
|
||||
|
||||
### 每個項目
|
||||
|
||||
在项目根目录中添加`opencode.json`。项目配置在标准配置文件中具有最高优先级 - 它覆盖全局配置和远程配置。
|
||||
|
||||
:::提示
|
||||
將項目特定配置放在項目的根目錄中。
|
||||
:::
|
||||
|
||||
当OpenCode启动时,它会在当前目录中查找配置文件或打开到最近的Git目录。
|
||||
|
||||
这也可以安全地签入 Git 并使用与全局模式相同的模式。
|
||||
|
||||
---
|
||||
|
||||
### 自定義路徑
|
||||
|
||||
使用 `OPENCODE_CONFIG` 环境变量指定自定义配置文件路径。
|
||||
|
||||
```bash
|
||||
export OPENCODE_CONFIG=/path/to/my/custom-config.json
|
||||
opencode run "Hello world"
|
||||
```
|
||||
|
||||
自定義配置按優先順序在全局配置和項目配置之間加載。
|
||||
|
||||
---
|
||||
|
||||
### 自定義目錄
|
||||
|
||||
使用`OPENCODE_CONFIG_DIR`指定自定义配置目录
|
||||
環境變量。將在該目錄中搜索代理、命令、
|
||||
模式和插件类似于标准`.opencode`目录一样,并且应该
|
||||
遵循相同的結構。
|
||||
|
||||
```bash
|
||||
export OPENCODE_CONFIG_DIR=/path/to/my/config-directory
|
||||
opencode run "Hello world"
|
||||
```
|
||||
|
||||
自定义目录在全局配置和`.opencode`目录加载后,因此**可以覆盖**它们的设置。
|
||||
|
||||
---
|
||||
|
||||
## 模式
|
||||
|
||||
配置文件具有在 [**`opencode.ai/config.json`**](https://opencode.ai/config.json) 中配置的架构。
|
||||
|
||||
您的編輯器應該能夠根據架構進行驗證和自動完成。
|
||||
|
||||
---
|
||||
|
||||
### 途易
|
||||
|
||||
您可以通过 `tui` 选项配置特定于 TUI 的设置。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"tui": {
|
||||
"scroll_speed": 3,
|
||||
"scroll_acceleration": {
|
||||
"enabled": true
|
||||
},
|
||||
"diff_style": "auto"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
可用選項:
|
||||
|
||||
- `scroll_acceleration.enabled` - 启用 macOS 风格的滚动加速。 **优先于`scroll_speed`。 **
|
||||
- `scroll_speed` - 自定义滚动速度倍增(默认值:`3`,简单:`1`)。如果`scroll_acceleration.enabled`是`true`,则忽略。
|
||||
- `diff_style` - 控制差异渲染。 `"auto"` 适应宽度,`"stacked"` 始终显示单列。
|
||||
|
||||
[在此处了解有关使用 TUI 的更多信息](/docs/tui)。
|
||||
|
||||
---
|
||||
|
||||
### 伺服器
|
||||
|
||||
您可以通过`server` 选项为`opencode serve` 和`opencode web` 命令配置服务器设置。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"server": {
|
||||
"port": 4096,
|
||||
"hostname": "0.0.0.0",
|
||||
"mdns": true,
|
||||
"mdnsDomain": "myproject.local",
|
||||
"cors": ["http://localhost:5173"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
可用選項:
|
||||
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
- `mdns` - 启用 mDNS 服务发现。这允许网络上的其他设备发现您的 OpenCode 服务器。
|
||||
- `mdnsDomain` - mDNS 服务的自定义域名。默认为 `opencode.local`。对于在同一个网络上运行多个实例很有用。
|
||||
- `cors` - 从基于浏览器的客户端使用 HTTP 服务器时允许 CORS 的其他来源。值必须是完整来源(方案+主机+任选端口),例如 `https://app.example.com`。
|
||||
|
||||
[在此处了解有关服务器的更多信息](/docs/server)。
|
||||
|
||||
---
|
||||
|
||||
### 工具
|
||||
|
||||
您可以通过 `tools` 选项管理法学硕士可以使用的工具。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"tools": {
|
||||
"write": false,
|
||||
"bash": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[在此处了解有关工具的更多信息](/docs/tools)。
|
||||
|
||||
---
|
||||
|
||||
### 型號
|
||||
|
||||
您可以通过 `provider`、`model` 和 `small_model` 选项来配置要在 OpenCode 配置中使用的提供的程序和模型。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {},
|
||||
"model": "anthropic/claude-sonnet-4-5",
|
||||
"small_model": "anthropic/claude-haiku-4-5"
|
||||
}
|
||||
```
|
||||
|
||||
`small_model` 选项为标题生成等轻量级任务配置单独的模型。默认情况下,如果您的成功可以提供更便宜的模型,OpenCode 会尝试使用更便宜的模型,否则它会退回到您的主模型。
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {
|
||||
"anthropic": {
|
||||
"options": {
|
||||
"timeout": 600000,
|
||||
"setCacheKey": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- `timeout` - 请求超时以毫秒为单位(默认值:300000)。设置为 `false` 以禁用。
|
||||
- `setCacheKey` -确保始终为指定的提供者设置存储硬盘。
|
||||
|
||||
您还可以配置[本地模型](/docs/models#local)。[了解更多](/docs/models)。
|
||||
|
||||
---
|
||||
|
||||
#### 特定於提供商的選項
|
||||
|
||||
有些提供程序支持除通用 `timeout` 和 `apiKey` 之外的其他配置选项。
|
||||
|
||||
##### 亞馬遜基岩
|
||||
|
||||
Amazon Bedrock 支持 AWS 特定配置:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {
|
||||
"amazon-bedrock": {
|
||||
"options": {
|
||||
"region": "us-east-1",
|
||||
"profile": "my-aws-profile",
|
||||
"endpoint": "https://bedrock-runtime.us-east-1.vpce-xxxxx.amazonaws.com"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
- `profile` - 来自 `~/.aws/credentials` 的 AWS 命名配置文件(默认为 `AWS_PROFILE` env var)
|
||||
- `endpoint` - VPC 终端节点的自定义节点 URL。这是使用 AWS 特定术语的通用 `baseURL` 选项的别名。如果两者都指定,`endpoint` 优先。
|
||||
|
||||
:::笔记
|
||||
承载令牌(`AWS_BEARER_TOKEN_BEDROCK` 或`/connect`)优先于基于配置文件的身份验证。详情请参见【认证优先级](/docs/providers#authentication-precedence)。
|
||||
:::
|
||||
|
||||
[了解有关 Amazon Bedrock 配置的更多信息](/docs/providers#amazon-bedrock)。
|
||||
|
||||
---
|
||||
|
||||
### 主題
|
||||
|
||||
您可以通过 OpenCode 配置中配置中的 `theme` 选项要使用的主题。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"theme": ""
|
||||
}
|
||||
```
|
||||
|
||||
[在这里了解更多](/docs/themes)。
|
||||
|
||||
---
|
||||
|
||||
### 代理商
|
||||
|
||||
您可以通过 `agent` 选项为特定任务配置专用代理。
|
||||
|
||||
```jsonc title="opencode.jsonc"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"agent": {
|
||||
"code-reviewer": {
|
||||
"description": "Reviews code for best practices and potential issues",
|
||||
"model": "anthropic/claude-sonnet-4-5",
|
||||
"prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
|
||||
"tools": {
|
||||
// Disable file modification tools for review-only agent
|
||||
"write": false,
|
||||
"edit": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
您还可以使用 `~/.config/opencode/agents/` 或 `.opencode/agents/` 中的 markdown 文件定义代理。 [在这里了解更多](/docs/agents)。
|
||||
|
||||
---
|
||||
|
||||
### 默認代理
|
||||
|
||||
您可以使用 `default_agent` 选项默认设置代理。当没有明确指定时,这将确定使用哪个代理。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"default_agent": "plan"
|
||||
}
|
||||
```
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
此设置适用于所有界面:TUI、CLI (`opencode run`)、桌面应用程序和 GitHub Action。
|
||||
|
||||
---
|
||||
|
||||
### 分享
|
||||
|
||||
您可以通过`share`选项配置[分享](/docs/share)功能。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"share": "manual"
|
||||
}
|
||||
```
|
||||
|
||||
這需要:
|
||||
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
- `"auto"` - 自动分享新对话
|
||||
- `"disabled"` - 完全禁用共享
|
||||
|
||||
默认情况下,共享设置为手动模式,您需要使用 `/share` 命令显式共享对话。
|
||||
|
||||
---
|
||||
|
||||
### 命令
|
||||
|
||||
您可以通过`command`选项为重复任务配置自定义命令。
|
||||
|
||||
```jsonc title="opencode.jsonc"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"command": {
|
||||
"test": {
|
||||
"template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
|
||||
"description": "Run tests with coverage",
|
||||
"agent": "build",
|
||||
"model": "anthropic/claude-haiku-4-5",
|
||||
},
|
||||
"component": {
|
||||
"template": "Create a new React component named $ARGUMENTS with TypeScript support.\nInclude proper typing and basic structure.",
|
||||
"description": "Create a new component",
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
您还可以使用 `~/.config/opencode/commands/` 或 `.opencode/commands/` 中的 Markdown 文件定义命令。 [在这里了解更多](/docs/commands)。
|
||||
|
||||
---
|
||||
|
||||
### 按鍵綁定
|
||||
|
||||
您可以通过 `keybinds` 选项自定义您的按键绑定。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"keybinds": {}
|
||||
}
|
||||
```
|
||||
|
||||
[在这里了解更多](/docs/keybinds)。
|
||||
|
||||
---
|
||||
|
||||
### 自動更新
|
||||
|
||||
OpenCode 将在启动时自动下载任何新的更新。您可以使用 `autoupdate` 选项取消此功能。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"autoupdate": false
|
||||
}
|
||||
```
|
||||
|
||||
如果您不想更新但希望在新版本可用时收到通知,则需将`autoupdate`设置为`"notify"`。
|
||||
请注意,这仅在未使用 Homebrew 等包管理器安装时才有效。
|
||||
|
||||
---
|
||||
|
||||
### 格式化程序
|
||||
|
||||
您可以通过`formatter`选项配置代码初始化程序。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"formatter": {
|
||||
"prettier": {
|
||||
"disabled": true
|
||||
},
|
||||
"custom-prettier": {
|
||||
"command": ["npx", "prettier", "--write", "$FILE"],
|
||||
"environment": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"extensions": [".js", ".ts", ".jsx", ".tsx"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
---
|
||||
|
||||
### 權限
|
||||
|
||||
默认情况下,opencode **允许所有操作**,无需明确批准。您可以使用 `permission` 选项更改此设置。
|
||||
|
||||
例如,要确保 `edit` 和 `bash` 工具需要用户批准:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "ask",
|
||||
"bash": "ask"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[在此处了解有关权限的更多信息](/docs/permissions)。
|
||||
|
||||
---
|
||||
|
||||
### 壓實
|
||||
|
||||
您可以通过 `compaction` 选项控制上下文压缩行为。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"compaction": {
|
||||
"auto": true,
|
||||
"prune": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
- `prune` - 删除旧工具以输出保存令牌(默认值:`true`)。
|
||||
|
||||
---
|
||||
|
||||
### 守望者
|
||||
|
||||
您可以通过`watcher`选项配置文件观察器忽略模式。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"watcher": {
|
||||
"ignore": ["node_modules/**", "dist/**", ".git/**"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
模式遵循 glob 语法。使用它可以从文件监视中排除杂的目录。
|
||||
|
||||
---
|
||||
|
||||
### MCP服务器
|
||||
|
||||
您可以通过 `mcp` 选项配置要使用的 MCP 服务器。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {}
|
||||
}
|
||||
```
|
||||
|
||||
[在这里了解更多](/docs/mcp-servers)。
|
||||
|
||||
---
|
||||
|
||||
### 插件
|
||||
|
||||
[插件](/docs/plugins) 使用自定义工具、挂钩和集成扩展 OpenCode。
|
||||
|
||||
将插件文件放置在`.opencode/plugins/` 或`~/.config/opencode/plugins/` 中。您还可以通过 `plugin` 选项从 npm 加载插件。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
|
||||
}
|
||||
```
|
||||
|
||||
[在这里了解更多](/docs/plugins)。
|
||||
|
||||
---
|
||||
|
||||
### 指示
|
||||
|
||||
您可以通过 `instructions` 选项配置您正在使用的型号的说明。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
|
||||
}
|
||||
```
|
||||
|
||||
這需要指令文件的路徑和全局模式數組。 [了解更多
|
||||
关于规则在这里](/docs/rules)。
|
||||
|
||||
---
|
||||
|
||||
### 殘疾服務提供者
|
||||
|
||||
您可以通过 `disabled_providers` 选项取消自动加载的提供程序。当您想要阻止加载某些提供程序(即使其可用)时,这非常有用。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"disabled_providers": ["openai", "gemini"]
|
||||
}
|
||||
```
|
||||
|
||||
:::笔记
|
||||
`disabled_providers` 优先于`enabled_providers`。
|
||||
:::
|
||||
|
||||
`disabled_providers` 选项接受提供者 ID 内存。当提供者被取消时:
|
||||
|
||||
- 即使設置了環境變量也不會加載。
|
||||
- 即使通过`/connect`命令配置API钥匙,也不会加载它。
|
||||
- 提供商的型號不會出現在型號選擇列表中。
|
||||
|
||||
---
|
||||
|
||||
### 啟用的提供商
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"enabled_providers": ["anthropic", "openai"]
|
||||
}
|
||||
```
|
||||
|
||||
当您想要限制 OpenCode 仅使用特定的提供程序而不是一一禁止它们时,这非常有用。
|
||||
|
||||
:::笔记
|
||||
`disabled_providers` 优先于`enabled_providers`。
|
||||
:::
|
||||
|
||||
如果有人提供程序同时出现在`enabled_providers`和`disabled_providers`中,则`disabled_providers`优先考虑一致性。
|
||||
|
||||
---
|
||||
|
||||
### 實驗性的
|
||||
|
||||
`experimental` 键包含正在积极开发的选项。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"experimental": {}
|
||||
}
|
||||
```
|
||||
|
||||
:::警告
|
||||
實驗選項不穩定。它們可能會更改或被刪除,恕不另行通知。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 變量
|
||||
|
||||
您可以在配置文件中使用變量替換來引用環境變量和文件內容。
|
||||
|
||||
---
|
||||
|
||||
### 環境變量
|
||||
|
||||
使用`{env:VARIABLE_NAME}`替换环境变量:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"model": "{env:OPENCODE_MODEL}",
|
||||
"provider": {
|
||||
"anthropic": {
|
||||
"models": {},
|
||||
"options": {
|
||||
"apiKey": "{env:ANTHROPIC_API_KEY}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果未設置環境變量,它將被替換為空字符串。
|
||||
|
||||
---
|
||||
|
||||
### 文件
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"instructions": ["./custom-instructions.md"],
|
||||
"provider": {
|
||||
"openai": {
|
||||
"options": {
|
||||
"apiKey": "{file:~/.secrets/openai-key}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
文件路徑可以是:
|
||||
|
||||
- 相對於配置文件目錄
|
||||
- 或者以 `/` 或 `~` 開頭的絕對路徑
|
||||
|
||||
這些對於:
|
||||
|
||||
- 将API等敏感数据保存在单独的文件中。
|
||||
- 包含大型指令文件,而不會弄亂您的配置。
|
||||
- 跨多個配置文件共享通用配置片段。
|
||||
170
packages/web/src/content/docs/zh-cn/custom-tools.mdx
Normal file
170
packages/web/src/content/docs/zh-cn/custom-tools.mdx
Normal file
@@ -0,0 +1,170 @@
|
||||
---
|
||||
title: 定制工具
|
||||
description: 創建法學碩士可以在開放代碼中調用的工具。
|
||||
---
|
||||
|
||||
自定义工具是您创建的函数,LLM 可以在对话期间调用。它们与 opencode 的[内置工具](/docs/tools) 一起工作,例如 `read`、`write` 和 `bash`。
|
||||
|
||||
---
|
||||
|
||||
## 創建工具
|
||||
|
||||
工具定义为 **TypeScript** 或 **JavaScript** 文件。但是,工具定义调用可以使用 **任何语言** 编写的脚本 - TypeScript 或 JavaScript 仅用于工具定义本身。
|
||||
|
||||
---
|
||||
|
||||
### 地點
|
||||
|
||||
它們可以定義為:
|
||||
|
||||
- 通过将它们放在项目的 `.opencode/tools/` 目录中来本地进行。
|
||||
- Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
---
|
||||
|
||||
### 結構
|
||||
|
||||
创建工具最简单的方法是使用 `tool()` 帮助程序,它提供类型安全和验证。
|
||||
|
||||
```ts title=".opencode/tools/database.ts" {1}
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
|
||||
export default tool({
|
||||
description: "Query the project database",
|
||||
args: {
|
||||
query: tool.schema.string().describe("SQL query to execute"),
|
||||
},
|
||||
async execute(args) {
|
||||
// Your database logic here
|
||||
return `Executed query: ${args.query}`
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
**文件名**成为**工具名称**。以上创建了一个 `database` 工具。
|
||||
|
||||
---
|
||||
|
||||
#### 每個文件多個工具
|
||||
|
||||
您還可以從單個文件導出多個工具。每個導出都會成為**一個單獨的工具**,名稱為**`<filename>_<exportname>`**:
|
||||
|
||||
```ts title=".opencode/tools/math.ts"
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
|
||||
export const add = tool({
|
||||
description: "Add two numbers",
|
||||
args: {
|
||||
a: tool.schema.number().describe("First number"),
|
||||
b: tool.schema.number().describe("Second number"),
|
||||
},
|
||||
async execute(args) {
|
||||
return args.a + args.b
|
||||
},
|
||||
})
|
||||
|
||||
export const multiply = tool({
|
||||
description: "Multiply two numbers",
|
||||
args: {
|
||||
a: tool.schema.number().describe("First number"),
|
||||
b: tool.schema.number().describe("Second number"),
|
||||
},
|
||||
async execute(args) {
|
||||
return args.a * args.b
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
这将创建两个工具:`math_add` 和 `math_multiply`。
|
||||
|
||||
---
|
||||
|
||||
### 論據
|
||||
|
||||
您可以使用`tool.schema`(即[佐德](https://zod.dev))来定义参数类型。
|
||||
|
||||
```ts "tool.schema"
|
||||
args: {
|
||||
query: tool.schema.string().describe("SQL query to execute")
|
||||
}
|
||||
```
|
||||
|
||||
您还可以直接导入[佐德](https://zod.dev)并返回一个普通对象:
|
||||
|
||||
```ts {6}
|
||||
import { z } from "zod"
|
||||
|
||||
export default {
|
||||
description: "Tool description",
|
||||
args: {
|
||||
param: z.string().describe("Parameter description"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
// Tool implementation
|
||||
return "result"
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 情境
|
||||
|
||||
工具接收有關當前會話的上下文:
|
||||
|
||||
```ts title=".opencode/tools/project.ts" {8}
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
|
||||
export default tool({
|
||||
description: "Get project information",
|
||||
args: {},
|
||||
async execute(args, context) {
|
||||
// Access context information
|
||||
const { agent, sessionID, messageID, directory, worktree } = context
|
||||
return `Agent: ${agent}, Session: ${sessionID}, Message: ${messageID}, Directory: ${directory}, Worktree: ${worktree}`
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
使用 `context.directory` 作为会话工作目录。
|
||||
使用 `context.worktree` 作为 git 工作树根。
|
||||
|
||||
---
|
||||
|
||||
## 示例
|
||||
|
||||
### 用Python编写一个工具
|
||||
|
||||
您可以使用任何您想要的语言编写工具。下面是一个使用 Python 将两个数字相加的示例。
|
||||
|
||||
首先,使用创建 Python 脚本的工具:
|
||||
|
||||
```python title=".opencode/tools/add.py"
|
||||
import sys
|
||||
|
||||
a = int(sys.argv[1])
|
||||
b = int(sys.argv[2])
|
||||
print(a + b)
|
||||
```
|
||||
|
||||
然後創建調用它的工具定義:
|
||||
|
||||
```ts title=".opencode/tools/python-add.ts" {10}
|
||||
import { tool } from "@opencode-ai/plugin"
|
||||
import path from "path"
|
||||
|
||||
export default tool({
|
||||
description: "Add two numbers using Python",
|
||||
args: {
|
||||
a: tool.schema.number().describe("First number"),
|
||||
b: tool.schema.number().describe("Second number"),
|
||||
},
|
||||
async execute(args, context) {
|
||||
const script = path.join(context.worktree, ".opencode/tools/add.py")
|
||||
const result = await Bun.$`python3 ${script} ${args.a} ${args.b}`.text()
|
||||
return result.trim()
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
这里我们使用 [`Bun.$`](https://bun.com/docs/runtime/shell) 实用程序来运行 Python 脚本。
|
||||
76
packages/web/src/content/docs/zh-cn/ecosystem.mdx
Normal file
76
packages/web/src/content/docs/zh-cn/ecosystem.mdx
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
title: 生態系統
|
||||
description: 使用 OpenCode 构建的项目和集成。
|
||||
---
|
||||
|
||||
基于 OpenCode 的社区项目集合。
|
||||
|
||||
:::笔记
|
||||
想要将您的 OpenCode 相关项目添加到此列表中吗?提交 PR。
|
||||
:::
|
||||
|
||||
您还可以查看[很棒的开放代码](https://github.com/awesome-opencode/awesome-opencode)和[开放代码缓存](https://opencode.cafe),这是一个聚合生态系统和社区的社区。
|
||||
|
||||
---
|
||||
|
||||
## 插件
|
||||
|
||||
|名稱 |描述 |
|
||||
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
||||
| [Opencode-Daytona](https://github.com/jamesmurdza/daytona/blob/main/guides/typescript/opencode/README.md) | 在隔离的 Daytona 沙箱中自动运行 OpenCode 会话 | 使用 git 同步和实时预览
|
||||
| [opencode-helicone-会话](https://github.com/H2Shami/opencode-helicone-session) |自动注入 Helicone 会话标头以进行请求包 |
|
||||
| [打开代码类型注入](https://github.com/nick-vi/opencode-type-inject) |使用查找工具将 TypeScript/Svelte 类型自动注入到文件读取中 |
|
||||
| [opencode-openai-codex-auth](https://github.com/numman-ali/opencode-openai-codex-auth) | 使用您的 ChatGPT Plus/Pro 订阅而不是 API 积分 |
|
||||
| [opencode-gemini-auth](https://github.com/jenslys/opencode-gemini-auth) |使用您现有的 Gemini 计划而不是 API 设备 |
|
||||
| [opencode-反重力-auth](https://github.com/NoeFabris/opencode-antigravity-auth) |使用反重力的免费模型代替API |
|
||||
| [opencode-devcontainers 开放代码开发容器](https://github.com/athal7/opencode-devcontainers) | 具有浅克隆和自动分配端口的多分支开发容器隔离 |
|
||||
| [opencode-google-antigravity-auth](https://github.com/shekohex/opencode-google-antigravity-auth) | Google Antigravity OAuth 插件,支持 Google 搜索和更强大的 API 处理 |
|
||||
| [opencode-动态宽度修剪](https://github.com/Tarquinen/opencode-dynamic-context-pruning) |通过修剪过时的工具输出来优化代币使用|
|
||||
| [opencode-websearch-引用](https://github.com/ghoulr/opencode-websearch-cited.git) | 为具有Google接地风格的受支持增加本机网络搜索支持|
|
||||
| [opencode-pty](https://github.com/shekohex/opencode-pty.git) |使AI代理能够在PTY中运行后台进程,末端发送其交互输入。
|
||||
| [opencode-shell-策略](https://github.com/JRedeker/opencode-shell-strategy) |非吸引力 shell 命令说明 - 阻止依赖 TTY 的操作挂起
|
||||
| [opencode-wakatime](https://github.com/angristan/opencode-wakatime) |使用 Wakatime 跟踪 OpenCode 使用情况 |
|
||||
| [opencode-md-表清理程序](https://github.com/franlol/opencode-md-table-formatter/tree/main) |清理法学大师生成的降价表|
|
||||
| [开放代码变形快速应用](https://github.com/JRedeker/opencode-morph-fast-apply) | 使用Morph Fast Apply API和取消编辑标记将代码编辑速度提高10倍 |
|
||||
| [哦我的开放代码](https://github.com/code-yeongyu/oh-my-opencode) | 后台代理、预构建的LSP/AST/MCP工具、精选代理、兼容Claude代码|
|
||||
| [开放代码通知器](https://github.com/panta82/opencode-notificator) | OpenCode 会话的桌面通知和声音警报 | OpenCode 会话的桌面通知和声音警报
|
||||
| [开放代码通知程序](https://github.com/mohak34/opencode-notifier) | 针对权限、完成和错误事件的桌面通知和声音警报 |
|
||||
| [opencode-zellij-namer](https://github.com/24601/opencode-zellij-namer) | 基于 OpenCode 上下文的 AI 支持的自动 Zellij 会话命名 |
|
||||
| [开放代码技巧](https://github.com/zenobi-us/opencode-skillful) | 允许OpenCode代理通过技能发现和注入失败延迟加载提示 |
|
||||
| [开放代码超级内存](https://github.com/supermemoryai/opencode-supermemory) | 使用超级内存跨会话持久内存|
|
||||
| [@ZZPH0ZZ](https://github.com/backnotprop/plannotator/tree/main/apps/opencode-plugin) |具有視覺註釋和私人/離線共享的交互式計劃審查|
|
||||
| [@ZZPH0ZZ](https://github.com/spoons-and-mirrors/subtask2) |將開放代碼/命令擴展為具有精細流程控制的強大編排系統 |
|
||||
| [开放代码调度程序](https://github.com/different-ai/opencode-scheduler) | 使用带 cron 语法的 launchd (Mac) 或 systemd (Linux) 安排重复作业 |
|
||||
| [微码](https://github.com/vtemian/micode) | 塑造头脑风暴 → 计划 → 实施具有会议连续性的工作流程 |
|
||||
| [奥克托](https://github.com/vtemian/octto) |用于通过多问题形式进行AI头痛风暴的交互式浏览器UI
|
||||
| [opencode-后台代理](https://github.com/kdcokenny/opencode-background-agents) | 具有异步委托和上下文持久性的Claude Code风格后台代理 |
|
||||
| [打开代码通知](https://github.com/kdcokenny/opencode-notify) | OpenCode 的本机操作系统通知 – 了解任务何时完成 |
|
||||
| [开放代码工作区](https://github.com/kdcokenny/opencode-workspace) | 一堆多代理编排工具 – 16个,组件一次安装 |
|
||||
| [开放代码工作树](https://github.com/kdcokenny/opencode-worktree) | OpenCode 的零难度 git 工作树 |
|
||||
|
||||
---
|
||||
|
||||
## 專案
|
||||
|
||||
|名稱 |描述 |
|
||||
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
|
||||
| [木牧](https://github.com/remorses/kimaki) |用于控制 OpenCode 会话的 Discord 机器人,基于 SDK 构建 |
|
||||
| [开放代码.nvim](https://github.com/NickvanDyke/opencode.nvim) | Neovim 插件,用于编辑器采集提示,基于 API 构建 |
|
||||
| [门户网站](https://github.com/hosenur/portal) |通过Tailscale/VPN实现OpenCode的移动优先Web UI |
|
||||
| [打开代码插件模板](https://github.com/zenobi-us/opencode-plugin-template/) |用于构建 OpenCode 插件的模板 |
|
||||
| [开放代码.nvim](https://github.com/sudo-tee/opencode.nvim) | Neovim opencode 前端 - 基于终端的 AI 编码代理 |
|
||||
| [ai-sdk-provider-opencode-sdk](https://github.com/ben-vargas/ai-sdk-provider-opencode-sdk) | Vercel AI SDK 提供程序,用于通过 @opencode-ai/sdk 使用 OpenCode |
|
||||
| [开放室](https://github.com/btriapitsyn/openchamber) | OpenCode 的 Web/桌面應用程序和 VS Code 扩展 |
|
||||
| [OpenCode-Obsidian](https://github.com/mtymek/opencode-obsidian) |在 Obsidian 的 UI 中嵌入 OpenCode 的 Obsidian 插件 |
|
||||
| [开放式工作](https://github.com/different-ai/openwork) | Claude Cowork 的替代开源方案,由 OpenCode 提供支持 |
|
||||
| [奥克斯](https://github.com/kdcokenny/ocx) | OpenCode扩展管理器具有可移植、隔离的配置文件。
|
||||
| [代码游牧者](https://github.com/NeuralNomadsAI/CodeNomad) | OpenCode 的桌面、Web、移动和远程客户端应用程序 |
|
||||
|
||||
---
|
||||
|
||||
## 代理商
|
||||
|
||||
|名稱 |描述 |
|
||||
| ----------------------------------------------------------------- | ------------------------------------------------------------ |
|
||||
| [代理](https://github.com/Cluster444/agentic) |用于格式化开发的定价人工智能代理和命令]
|
||||
| [开放代码代理](https://github.com/darrenhinde/opencode-agents) |用于增强工作流程的配置、提示、代理和插件 |
|
||||
170
packages/web/src/content/docs/zh-cn/enterprise.mdx
Normal file
170
packages/web/src/content/docs/zh-cn/enterprise.mdx
Normal file
@@ -0,0 +1,170 @@
|
||||
---
|
||||
title: 企業
|
||||
description: 在您的组织中安全地使用 OpenCode。
|
||||
---
|
||||
|
||||
import config from "../../../../config.mjs"
|
||||
export const email = `mailto:${config.email}`
|
||||
|
||||
OpenCode Enterprise 适用于希望确保其代码和数据永远不会离开其基础设施的组织。它可以通过使用与 SSO 和内部 AI 网关集成的集中方式配置来实现此目的。
|
||||
|
||||
:::笔记
|
||||
OpenCode 不存储您的任何代码或上下文数据。
|
||||
:::
|
||||
|
||||
要开始使用OpenCode Enterprise:
|
||||
|
||||
1. 與您的團隊進行內部試驗。
|
||||
2. **<a href={email}>聯繫我們</a>**討論定價和實施選項。
|
||||
|
||||
---
|
||||
|
||||
## 審判
|
||||
|
||||
OpenCode 是开源的,不存储您的任何代码或上下文数据,因此您的开发人员只需 [开始吧](/docs/) 并进行试用。
|
||||
|
||||
---
|
||||
|
||||
### 數據處理
|
||||
|
||||
**OpenCode 不会存储您的代码或上下文数据。 **所有处理都在本地进行或通过直接 API 调用您的 AI 成功。
|
||||
|
||||
這意味著只要您使用您信任的提供商或內部提供商
|
||||
AI网关,您可以安全使用OpenCode。
|
||||
|
||||
这里唯一需要注意的是可选的 `/share` 功能。
|
||||
|
||||
---
|
||||
|
||||
#### 分享對話
|
||||
|
||||
如果启用用户 `/share` 功能,对话和关联的数据将被发送到我们用于在 opencode.ai 上托管这些共享页面的服务。
|
||||
|
||||
数据当前通过我们的CDN边缘网络提供服务,并缓存在用户附近的边缘。
|
||||
|
||||
我們建議您在試用時禁用此功能。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"share": "disabled"
|
||||
}
|
||||
```
|
||||
|
||||
[了解更多关于分享的信息](/docs/share)。
|
||||
|
||||
---
|
||||
|
||||
### 代碼所有權
|
||||
|
||||
**您拥有 OpenCode 生成的所有代码。 ** 没有许可限制或语音报表。
|
||||
|
||||
---
|
||||
|
||||
## 定價
|
||||
|
||||
我們對 OpenCode Enterprise 使用單機模型。如果您有自己的 LLM 網關,我們不會對使用的令牌收取費用。有關定價和實施選項的更多詳細信息,請**<a href={email}>聯繫我們</a>**。
|
||||
|
||||
---
|
||||
|
||||
## 部署
|
||||
|
||||
完成试验并准备好使用 OpenCode 后,请访问:
|
||||
您的組織,您可以**<a href={email}>聯繫我們</a>**進行討論
|
||||
定價和實施選項。
|
||||
|
||||
---
|
||||
|
||||
### 中央配置
|
||||
|
||||
我们可以将 OpenCode 设置为您的整个组织使用单一的中央配置。
|
||||
|
||||
这种集中式配置可以与您的 SSO 成功集成,并确保所有用户仅访问您的内部 AI 网关。
|
||||
|
||||
---
|
||||
|
||||
### 單點登錄集成
|
||||
|
||||
通过中央配置,OpenCode 可以与您组织的 SSO 成功集成以进行身份验证。
|
||||
|
||||
这使得 OpenCode 能够通过现有的身份管理系统获取内部 AI 网关的凭据。
|
||||
|
||||
---
|
||||
|
||||
### 内部AI网关
|
||||
|
||||
通过中央配置,OpenCode 还可以配置为仅使用您的内部 AI 网关。
|
||||
|
||||
您还可以取消所有其他人工智能启动,确保所有请求都通过组织批准的基础设施。
|
||||
|
||||
---
|
||||
|
||||
### 自託管
|
||||
|
||||
雖然我們建議禁用共享頁面以確保您的數據永遠不會離開
|
||||
您的組織,我們還可以幫助您在您的基礎設施上自行託管它們。
|
||||
|
||||
目前這已在我們的路線圖上。如果您有興趣,**<a href={email}>讓我們知道</a>**。
|
||||
|
||||
---
|
||||
|
||||
## 常問問題
|
||||
|
||||
<details>
|
||||
<summary>什麼是 OpenCode Enterprise? </summary>
|
||||
|
||||
OpenCode Enterprise 适用于希望确保其代码和数据永远不会离开其基础设施的组织。它可以通过使用与 SSO 和内部 AI 网关集成的集中方式配置来实现此目的。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>如何開始使用 OpenCode Enterprise? </summary>
|
||||
|
||||
与您的团队进行内部实验即可。OpenCode 默认情况下不存储您的代码或上下文数据,可以轻松上手。
|
||||
|
||||
然後**<a href={email}>聯繫我們</a>**討論定價和實施選項。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>企業定價如何運作? </summary>
|
||||
|
||||
我們提供按席位企業定價。如果您有自己的 LLM 網關,我們不會對使用的令牌收取費用。如需了解更多詳情,請**<a href={email}>聯繫我們</a>**,獲取根據您組織的需求定制的報價。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>OpenCode Enterprise 保證我的數據安全嗎? </summary>
|
||||
|
||||
OpenCode 不存储您的代码或上下文数据。所有处理都在本地进行或通过直接 API 调用您的 AI 工作。通过中央配置和 SSO 集成,您的数据在组织的基础架构中保持安全。
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>我們可以使用自己的私有 NPM 註冊表嗎? </summary>
|
||||
|
||||
OpenCode 通过 Bun 的本机 `.npmrc` 文件支持来支持香蕉 npm 肥料。如果您的组织使用了花生,例如 JFrog Artifactory、Nexus 或类似的肥料,请确保开发人员在运行 OpenCode 之前经过身份验证。
|
||||
|
||||
要使用您的私有註冊表設置身份驗證:
|
||||
|
||||
```bash
|
||||
npm login --registry=https://your-company.jfrog.io/api/npm/npm-virtual/
|
||||
```
|
||||
|
||||
这将创建带有身份验证详细信息的 `~/.npmrc`。 OpenCode 会自动
|
||||
拿起這個。
|
||||
|
||||
:::警告
|
||||
在运行 OpenCode 之前,您必须登录灌木丛。
|
||||
:::
|
||||
|
||||
或者,您可以手动配置`.npmrc`文件:
|
||||
|
||||
```bash title="~/.npmrc"
|
||||
registry=https://your-company.jfrog.io/api/npm/npm-virtual/
|
||||
//your-company.jfrog.io/api/npm/npm-virtual/:_authToken=${NPM_AUTH_TOKEN}
|
||||
```
|
||||
|
||||
开发人员必须在运行OpenCode之前登录棉花,以确保从企业种植樱桃。
|
||||
|
||||
</details>
|
||||
130
packages/web/src/content/docs/zh-cn/formatters.mdx
Normal file
130
packages/web/src/content/docs/zh-cn/formatters.mdx
Normal file
@@ -0,0 +1,130 @@
|
||||
---
|
||||
title: 格式化程序
|
||||
description: OpenCode 使用特定于语言的清理程序。
|
||||
---
|
||||
|
||||
使用在语言的格式化程序编写或编辑文件后,OpenCode会自动格式化文件。这可以确保生成的代码遵循项目的代码风格。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
OpenCode附带了多个适用于流行语言和框架的内置初始化程序。下面是格式化程序、支持的文件扩展名以及所需的命令或配置选项的列表。
|
||||
|
||||
|格式化程序|擴展 |要求|
|
||||
| -------------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
||||
|政府| .go | `gofmt` 命令可用 |
|
||||
|混合| .ex、.exs、.eex、.heex、.leex、.neex、.sface | `mix` 命令可用 |
|
||||
|更漂亮| .js、.jsx、.ts、.tsx、.html、.css、.md、.json、.yaml 和 [更多的](https://prettier.io/docs/en/index.html) | `package.json` | `prettier` 依赖关系
|
||||
|生物群系 | .js、.jsx、.ts、.tsx、.html、.css、.md、.json、.yaml 和 [更多的](https://biomejs.dev/) | `biome.json(c)` 配置文件 |
|
||||
|之字形 | .zig、.zon | `zig` 命令可用 |
|
||||
| clang 格式 | .c、.cpp、.h、.hpp、.ino 和 [更多的](https://clang.llvm.org/docs/ClangFormat.html) | `.clang-format` 配置文件 |
|
||||
|克特林特 | .kt、.kts | `ktlint` 命令可用 |
|
||||
|领子 | .py, .pyi | `ruff` 命令可通过配置 |
|
||||
|生锈 | .rs | `rustfmt` 命令可用 |
|
||||
| 货物运输 | .rs | `cargo fmt` 命令可用 |
|
||||
|美丽| .py, .pyi | `uv` 命令可用 |
|
||||
|鲁博科普 | .rb、.rake、.gemspec、.ru | `rubocop` 命令可用 |
|
||||
|标准rb | .rb、.rake、.gemspec、.ru | `standardrb` 命令可用 |
|
||||
| html美化器 | .erb、.html.erb | `htmlbeautifier` 命令可用 |
|
||||
|空气| .R | `air` 命令可用 |
|
||||
|飞镖 | .dart | `dart` 命令可用 |
|
||||
| ocaml 格式 | .ml、.mli | `ocamlformat` 可用命令和 `.ocamlformat` 配置文件 |
|
||||
|地形 | .tf、.tfvars | `terraform` 命令可用 |
|
||||
|微光| .gleam | `gleam` 命令可用 |
|
||||
|尼克斯夫MTT | .nix | `nixfmt` 命令可用 |
|
||||
| sfmt| .sh、.bash | `shfmt` 命令可用 |
|
||||
|品脱| .php | `composer.json` | `laravel/pint` 依赖关系
|
||||
| oxfmt(实验)| .js、.jsx、.ts、.tsx | `package.json` 和[实验环境指标](/docs/cli/#experimental) | `oxfmt` 依赖关系
|
||||
| 奥尔莫鲁 | .hs | `ormolu` 命令可用 |
|
||||
|
||||
因此,如果您的项目的`package.json`或`prettier`,OpenCode将自动使用它。
|
||||
|
||||
---
|
||||
|
||||
## 它是如何運作的
|
||||
|
||||
当OpenCode写入或编辑文件时,它:
|
||||
|
||||
1. 根據所有啟用的格式化程序檢查文件擴展名。
|
||||
2. 對文件運行適當的格式化程序命令。
|
||||
3. 自動應用格式更改。
|
||||
|
||||
此過程在後台進行,確保無需任何手動步驟即可維護您的代碼樣式。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以通过 OpenCode 配置中的 `formatter` 部分自定义程序。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"formatter": {}
|
||||
}
|
||||
```
|
||||
|
||||
每個格式化程序配置支持以下內容:
|
||||
|
||||
|物業 |類型 |描述 |
|
||||
| ------------- | -------- | ------------------------------------------------------- |
|
||||
| `disabled` | 布尔 | 将其设置为 `true` 以取消删除程序 |
|
||||
| `command` |字符串[] | 格式化运行的命令 |
|
||||
| `environment` |对象|运行格式化程序时要设置的环境变量 |
|
||||
| `extensions` |字符串[] |此整理程序应处理的文件扩展名 |
|
||||
|
||||
讓我們看一些例子。
|
||||
|
||||
---
|
||||
|
||||
### 禁用格式化程序
|
||||
|
||||
要全局取消**所有**清理程序,然后`formatter`设置为`false`:
|
||||
|
||||
```json title="opencode.json" {3}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"formatter": false
|
||||
}
|
||||
```
|
||||
|
||||
要取消**特定**删除程序,则`disabled`设置为`true`:
|
||||
|
||||
```json title="opencode.json" {5}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"formatter": {
|
||||
"prettier": {
|
||||
"disabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 自定義格式化程序
|
||||
|
||||
您可以覆蓋內置格式化程序或通過指定命令、環境變量和文件擴展名添加新格式化程序:
|
||||
|
||||
```json title="opencode.json" {4-14}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"formatter": {
|
||||
"prettier": {
|
||||
"command": ["npx", "prettier", "--write", "$FILE"],
|
||||
"environment": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"extensions": [".js", ".ts", ".jsx", ".tsx"]
|
||||
},
|
||||
"custom-markdown-formatter": {
|
||||
"command": ["deno", "fmt", "$FILE"],
|
||||
"extensions": [".md"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
命令中的 **`$FILE` 占位符** 将替换为正在格式化的文件的路径。
|
||||
321
packages/web/src/content/docs/zh-cn/github.mdx
Normal file
321
packages/web/src/content/docs/zh-cn/github.mdx
Normal file
@@ -0,0 +1,321 @@
|
||||
---
|
||||
title: GitHub
|
||||
description: 在 GitHub 问题和拉取请求中使用 OpenCode。
|
||||
---
|
||||
|
||||
OpenCode 与您的 GitHub 工作流程集成。在评论中提及 `/opencode` 或 `/oc`,OpenCode 将在您的 GitHub Actions 运行器中执行任务。
|
||||
|
||||
---
|
||||
|
||||
## 特徵
|
||||
|
||||
- **分类问题**:要求 OpenCode 调查问题并向您解释。
|
||||
- **修复和实施**:要求 OpenCode 修复问题或实施功能。将在一个新的分支中工作并提交包含所有更改的 PR。
|
||||
- **安全**:OpenCode 在 GitHub 的运行器中运行。
|
||||
|
||||
---
|
||||
|
||||
## 安裝
|
||||
|
||||
在 GitHub 存储库中的项目中运行以下命令:
|
||||
|
||||
```bash
|
||||
opencode github install
|
||||
```
|
||||
|
||||
这将引导您完成安装 GitHub 应用程序、创建工作流程和设置机密。
|
||||
|
||||
---
|
||||
|
||||
### 手動設置
|
||||
|
||||
或者您可以手動設置。
|
||||
|
||||
1. 错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
|
||||
前往[**github.com/apps/opencode-agent**](https://github.com/apps/opencode-agent)。确保它已安装在目标存储库上。
|
||||
|
||||
2. **添加工作流程**
|
||||
|
||||
将以下工作流程文件添加到存储库中的`.github/workflows/opencode.yml`中。确保在`env`中设置适当的`model`和所需的API按键。
|
||||
|
||||
```yml title=".github/workflows/opencode.yml" {24,26}
|
||||
name: opencode
|
||||
|
||||
on:
|
||||
issue_comment:
|
||||
types: [created]
|
||||
pull_request_review_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
opencode:
|
||||
if: |
|
||||
contains(github.event.comment.body, '/oc') ||
|
||||
contains(github.event.comment.body, '/opencode')
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 1
|
||||
persist-credentials: false
|
||||
|
||||
- name: Run OpenCode
|
||||
uses: anomalyco/opencode/github@latest
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
with:
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
# share: true
|
||||
# github_token: xxxx
|
||||
```
|
||||
|
||||
3. 错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
|
||||
在您的组织或项目的**设置**中,展开左侧的**秘密和变量**,然后选择**操作**。并添加所需的API钥匙。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
- `model`:与 OpenCode 一起使用的模型。采用 `provider/model` 格式。这是**必需的**。
|
||||
- `agent`:要使用的代理。必须是一级代理。如果未找到,则从配置回退到 `default_agent` 或 `"build"`。
|
||||
- `share`:是否共享OpenCode会话。对于公共存储库,默认为**true**。
|
||||
- `prompt`:可选的自定义提示以覆盖默认行为。使用它来自定义 OpenCode 处理请求的方式。
|
||||
- `token`:可选的 GitHub 访问令牌,用于执行创建评论、提交更改和打开拉取请求等操作。默认情况下,OpenCode 使用来自 OpenCode GitHub 应用程序的安装访问令牌,因此提交、评论和拉取请求显示为来自应用。
|
||||
|
||||
或者,您可以使用 GitHub Action 运行程序的[内置`GITHUB_TOKEN`](https://docs.github.com/en/actions/tutorials/authenticate-with-github_token),而无需安装 OpenCode GitHub 应用程序。只需确保在您的工作流程中所需的权限:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
|
||||
---
|
||||
|
||||
## 支持的活動
|
||||
|
||||
OpenCode 可以由以下 GitHub 事件触发:
|
||||
|
||||
|事件類型 |觸發者 |詳情 |
|
||||
| ----------------------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
||||
| `issue_comment` |对问题或 PR 发表评论 |在评论中提及 `/opencode` 或 `/oc`。 OpenCode 读取上下文并可以创建分支、打开 PR 或回复。
|
||||
| `pull_request_review_comment` |对 PR 中的特定代码行进行评论 |在检查代码时提及`/opencode` 或`/oc`。 OpenCode 接收文件路径、行号和 diff 上下文。 |
|
||||
| `issues` |问题已打开或已编辑|创建或修改问题时自动触发OpenCode。需要`prompt` 输入。
|
||||
| `pull_request` | PR 已开启或已更新 |当 PR 打开、同步或重新打开时自动触发 OpenCode。对于自动评论很有用。
|
||||
| `schedule` | 基于 Cron 的计划 | 按计划运行 OpenCode。需要 `prompt` 输入。输出进入日志和 PR(没有可评论的问题)。
|
||||
| `workflow_dispatch` | 从 GitHub UI 手动触发 |通过“操作”选项卡触发 OpenCode。需要 `prompt` 输入。输出进入日志和 PR。 |
|
||||
|
||||
### 時間表示例
|
||||
|
||||
按计划运行OpenCode以执行自动化任务:
|
||||
|
||||
```yaml title=".github/workflows/opencode-scheduled.yml"
|
||||
name: Scheduled OpenCode Task
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 9 * * 1" # Every Monday at 9am UTC
|
||||
|
||||
jobs:
|
||||
opencode:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Run OpenCode
|
||||
uses: anomalyco/opencode/github@latest
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
with:
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
prompt: |
|
||||
Review the codebase for any TODO comments and create a summary.
|
||||
If you find issues worth addressing, open an issue to track them.
|
||||
```
|
||||
|
||||
对于计划事件,`prompt` 输入是**必需的**,因为没有注释可以从中提取指令。希望计划工作流在没有用户上下文的情况下运行并进行权限检查,因此如果您 OpenCode 创建分支或 PR,工作流必须支持 `contents: write` 和 `pull-requests: write`。
|
||||
|
||||
---
|
||||
|
||||
### 拉取請求示例
|
||||
|
||||
或更新公关时间自动审核:
|
||||
|
||||
```yaml title=".github/workflows/opencode-review.yml"
|
||||
name: opencode-review
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, ready_for_review]
|
||||
|
||||
jobs:
|
||||
review:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
pull-requests: read
|
||||
issues: read
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: anomalyco/opencode/github@latest
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
use_github_token: true
|
||||
prompt: |
|
||||
Review this pull request:
|
||||
- Check for code quality issues
|
||||
- Look for potential bugs
|
||||
- Suggest improvements
|
||||
```
|
||||
|
||||
对于`pull_request`事件,如果未提供`prompt`,OpenCode将默认审核拉取请求。
|
||||
|
||||
---
|
||||
|
||||
### 問題分類示例
|
||||
|
||||
自動分類新問題。此示例過濾超過 30 天的帳戶以減少垃圾郵件:
|
||||
|
||||
```yaml title=".github/workflows/opencode-triage.yml"
|
||||
name: Issue Triage
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
steps:
|
||||
- name: Check account age
|
||||
id: check
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const user = await github.rest.users.getByUsername({
|
||||
username: context.payload.issue.user.login
|
||||
});
|
||||
const created = new Date(user.data.created_at);
|
||||
const days = (Date.now() - created) / (1000 * 60 * 60 * 24);
|
||||
return days >= 30;
|
||||
result-encoding: string
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
if: steps.check.outputs.result == 'true'
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- uses: anomalyco/opencode/github@latest
|
||||
if: steps.check.outputs.result == 'true'
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
with:
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
prompt: |
|
||||
Review this issue. If there's a clear fix or relevant docs:
|
||||
- Provide documentation links
|
||||
- Add error handling guidance for code examples
|
||||
Otherwise, do not comment.
|
||||
```
|
||||
|
||||
对于 `issues` 事件,`prompt` 输入是**必需的**,因为没有注释可足以提取指令。
|
||||
|
||||
---
|
||||
|
||||
## 自定義提示
|
||||
|
||||
覆盖默认提示,为您的工作流程自定义 OpenCode 的行为。
|
||||
|
||||
```yaml title=".github/workflows/opencode.yml"
|
||||
- uses: anomalyco/opencode/github@latest
|
||||
with:
|
||||
model: anthropic/claude-sonnet-4-5
|
||||
prompt: |
|
||||
Review this pull request:
|
||||
- Check for code quality issues
|
||||
- Look for potential bugs
|
||||
- Suggest improvements
|
||||
```
|
||||
|
||||
這對於執行與您的項目相關的特定審查標準、編碼標准或重點領域非常有用。
|
||||
|
||||
---
|
||||
|
||||
## 示例
|
||||
|
||||
以下是如何在 GitHub 中使用 OpenCode 的一些示例。
|
||||
|
||||
- **解釋一個問題**
|
||||
|
||||
在 GitHub 问题中添加此评论。
|
||||
|
||||
```
|
||||
/opencode explain this issue
|
||||
```
|
||||
|
||||
OpenCode 将阅读整个线程,包括所有评论,并回复并提供语音解释。
|
||||
|
||||
- **解決問題**
|
||||
|
||||
在 GitHub 问题中,说:
|
||||
|
||||
```
|
||||
/opencode fix this
|
||||
```
|
||||
|
||||
OpenCode 将创建一个新分支,实施更改,并使用更改打开 PR。
|
||||
|
||||
- **审查 PR 并进行更改**
|
||||
|
||||
在 GitHub PR 上留下以下评论。
|
||||
|
||||
```
|
||||
Delete the attachment from S3 when the note is removed /oc
|
||||
```
|
||||
|
||||
错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
|
||||
- **查看特定代碼行**
|
||||
|
||||
直接在PR的“文件”选项卡中的代码行上留下评论。OpenCode自动检测文件、行号和差异上下文以提供准确的响应。
|
||||
|
||||
```
|
||||
[Comment on specific lines in Files tab]
|
||||
/oc add error handling here
|
||||
```
|
||||
|
||||
错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
- 正在審查的確切文件
|
||||
- 具體代碼行
|
||||
- 周围的差异上下文
|
||||
- 行號信息
|
||||
|
||||
這允許更有針對性的請求,而無需手動指定文件路徑或行號。
|
||||
195
packages/web/src/content/docs/zh-cn/gitlab.mdx
Normal file
195
packages/web/src/content/docs/zh-cn/gitlab.mdx
Normal file
@@ -0,0 +1,195 @@
|
||||
---
|
||||
title: GitLab
|
||||
description: 在 GitLab 问题和合并请求中使用 OpenCode。
|
||||
---
|
||||
|
||||
OpenCode 通过 GitLab CI/CD 管道或与 GitLab Duo 与您的 GitLab 工作流程集成。
|
||||
|
||||
在这两种情况下,OpenCode 都会在您的 GitLab 运行器上运行。
|
||||
|
||||
---
|
||||
|
||||
## GitLab。
|
||||
|
||||
OpenCode 在常规 GitLab 管道中工作。您可以将其构建为管道 [CI](https://docs.gitlab.com/ee/ci/components/)
|
||||
|
||||
在这里,我们使用社区创建的 OpenCode CI/CD 组件 — [nagyv/gitlab-opencode](https://gitlab.com/nagyv/gitlab-opencode)。
|
||||
|
||||
---
|
||||
|
||||
### 特徵
|
||||
|
||||
- **每个作业使用每个自定义配置**:使用自定义配置目录配置OpenCode,例如`./config/#custom-directory`以启用或禁用OpenCode调用的功能。
|
||||
- 错误 500(服务器错误)!!1500。这是一个错误。出现错误。请稍后重试。我们只知道这些。
|
||||
- **灵活**:CI 组件支持多种输入来自定义其行为
|
||||
|
||||
---
|
||||
|
||||
### 設定
|
||||
|
||||
1. 将 OpenCode 身份验证 JSON 作为文件类型 CI 环境变量存储在 **设置** > **CI/CD** > **变量** 下。确保将它们标记为“隐藏和隐藏”。
|
||||
2. 将以下内容添加到您的 `.gitlab-ci.yml` 文件中。
|
||||
|
||||
```yaml title=".gitlab-ci.yml"
|
||||
include:
|
||||
- component: $CI_SERVER_FQDN/nagyv/gitlab-opencode/opencode@2
|
||||
inputs:
|
||||
config_dir: ${CI_PROJECT_DIR}/opencode-config
|
||||
auth_json: $OPENCODE_AUTH_JSON # The variable name for your OpenCode authentication JSON
|
||||
command: optional-custom-command
|
||||
message: "Your prompt here"
|
||||
```
|
||||
|
||||
有关此组件的更多输入和示例[查看文档](https://gitlab.com/explore/catalog/nagyv/gitlab-opencode)。
|
||||
|
||||
---
|
||||
|
||||
## 亚搏体育app二人组
|
||||
|
||||
OpenCode 与您的 GitLab 工作流程集成。
|
||||
在评论中提及`@opencode`,OpenCode 将在您的 GitLab CI 管道中执行任务。
|
||||
|
||||
---
|
||||
|
||||
### 特徵
|
||||
|
||||
- **分类问题**:要求 OpenCode 调查问题并向您解释。
|
||||
- **修复和实施**:要求OpenCode修复问题或实施功能。
|
||||
它將創建一個新分支並提出包含更改的合併請求。
|
||||
- **安全**:OpenCode 在您的 GitLab 运行器上运行。
|
||||
|
||||
---
|
||||
|
||||
### 設定
|
||||
|
||||
OpenCode 在您的 GitLab CI/CD 管道中运行,您需要进行以下设置:
|
||||
|
||||
:::提示
|
||||
查看[**GitLab 文档**](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/) 获取最新说明。
|
||||
:::
|
||||
|
||||
1. 配置您的 GitLab 环境
|
||||
2. 安装CI/CD
|
||||
3. 获取AI模型成功 API键
|
||||
4. 創建服務帳戶
|
||||
5. 配置 CI/CD 变量
|
||||
6. 創建一個流配置文件,這是一個示例:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Flow configuration</summary>
|
||||
|
||||
```yaml
|
||||
image: node:22-slim
|
||||
commands:
|
||||
- echo "Installing opencode"
|
||||
- npm install --global opencode-ai
|
||||
- echo "Installing glab"
|
||||
- export GITLAB_TOKEN=$GITLAB_TOKEN_OPENCODE
|
||||
- apt-get update --quiet && apt-get install --yes curl wget gpg git && rm --recursive --force /var/lib/apt/lists/*
|
||||
- curl --silent --show-error --location "https://raw.githubusercontent.com/upciti/wakemeops/main/assets/install_repository" | bash
|
||||
- apt-get install --yes glab
|
||||
- echo "Configuring glab"
|
||||
- echo $GITLAB_HOST
|
||||
- echo "Creating OpenCode auth configuration"
|
||||
- mkdir --parents ~/.local/share/opencode
|
||||
- |
|
||||
cat > ~/.local/share/opencode/auth.json << EOF
|
||||
{
|
||||
"anthropic": {
|
||||
"type": "api",
|
||||
"key": "$ANTHROPIC_API_KEY"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
- echo "Configuring git"
|
||||
- git config --global user.email "opencode@gitlab.com"
|
||||
- git config --global user.name "OpenCode"
|
||||
- echo "Testing glab"
|
||||
- glab issue list
|
||||
- echo "Running OpenCode"
|
||||
- |
|
||||
opencode run "
|
||||
You are an AI assistant helping with GitLab operations.
|
||||
|
||||
Context: $AI_FLOW_CONTEXT
|
||||
Task: $AI_FLOW_INPUT
|
||||
Event: $AI_FLOW_EVENT
|
||||
|
||||
Please execute the requested task using the available GitLab tools.
|
||||
Be thorough in your analysis and provide clear explanations.
|
||||
|
||||
<important>
|
||||
Please use the glab CLI to access data from GitLab. The glab CLI has already been authenticated. You can run the corresponding commands.
|
||||
|
||||
If you are asked to summarize an MR or issue or asked to provide more information then please post back a note to the MR/Issue so that the user can see it.
|
||||
You don't need to commit or push up changes, those will be done automatically based on the file changes you make.
|
||||
</important>
|
||||
"
|
||||
- git checkout --branch $CI_WORKLOAD_REF origin/$CI_WORKLOAD_REF
|
||||
- echo "Checking for git changes and pushing if any exist"
|
||||
- |
|
||||
if ! git diff --quiet || ! git diff --cached --quiet || [ --not --zero "$(git ls-files --others --exclude-standard)" ]; then
|
||||
echo "Git changes detected, adding and pushing..."
|
||||
git add .
|
||||
if git diff --cached --quiet; then
|
||||
echo "No staged changes to commit"
|
||||
else
|
||||
echo "Committing changes to branch: $CI_WORKLOAD_REF"
|
||||
git commit --message "Codex changes"
|
||||
echo "Pushing changes up to $CI_WORKLOAD_REF"
|
||||
git push https://gitlab-ci-token:$GITLAB_TOKEN@$GITLAB_HOST/gl-demo-ultimate-dev-ai-epic-17570/test-java-project.git $CI_WORKLOAD_REF
|
||||
echo "Changes successfully pushed"
|
||||
fi
|
||||
else
|
||||
echo "No git changes detected, skipping push"
|
||||
fi
|
||||
variables:
|
||||
- ANTHROPIC_API_KEY
|
||||
- GITLAB_TOKEN_OPENCODE
|
||||
- GITLAB_HOST
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
详细说明可以参考[GitLab CLI 代理文档](https://docs.gitlab.com/user/duo_agent_platform/agent_assistant/)。
|
||||
|
||||
---
|
||||
|
||||
### 示例
|
||||
|
||||
以下是如何在 GitLab 中使用 OpenCode 的一些示例。
|
||||
|
||||
:::提示
|
||||
您可以配置使用 `@opencode` 不同的触发主板。
|
||||
:::
|
||||
|
||||
- **解釋一個問題**
|
||||
|
||||
在 GitLab 问题中添加此评论。
|
||||
|
||||
```
|
||||
@opencode explain this issue
|
||||
```
|
||||
|
||||
OpenCode 将阅读该问题并回复并提供清晰的解释。
|
||||
|
||||
- **解決問題**
|
||||
|
||||
在 GitLab 问题中,说:
|
||||
|
||||
```
|
||||
@opencode fix this
|
||||
```
|
||||
|
||||
OpenCode 将创建一个新分支,实施更改,并打开包含更改的合并请求。
|
||||
|
||||
- **審查合併請求**
|
||||
|
||||
对 GitLab 合并请求留下以下评论。
|
||||
|
||||
```
|
||||
@opencode review this merge request
|
||||
```
|
||||
|
||||
OpenCode 将审核合并请求并提供反馈。
|
||||
48
packages/web/src/content/docs/zh-cn/ide.mdx
Normal file
48
packages/web/src/content/docs/zh-cn/ide.mdx
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: 集成開發環境
|
||||
description: VS Code、Cursor 等 IDE 的 OpenCode 扩展
|
||||
---
|
||||
|
||||
OpenCode 与 VS Code、Cursor 或任何支持终端的 IDE 集成。只需在终端中运行 `opencode` 即可开始。
|
||||
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
- **快速启动**:使用 `Cmd+Esc` (Mac) 或 `Ctrl+Esc` (Windows/Linux) 在分割终端视图中打开 OpenCode,或者聚焦现有终端会话(如果现有终端会话正在运行)。
|
||||
- **新会话**:使用 `Cmd+Shift+Esc` (Mac) 或 `Ctrl+Shift+Esc` (Windows/Linux) 启动新的 OpenCode 终端会话,即使该会话已打开。您还可以单击 UI 中的 OpenCode 按钮。
|
||||
- **上下文获取**:自动与OpenCode共享您当前的选择或选项卡。
|
||||
- **文件引用快捷方式**:使用`Cmd+Option+K` (Mac) 或`Alt+Ctrl+K` (Linux/Windows) 插入文件引用。例如,`@File#L37-42`。
|
||||
|
||||
---
|
||||
|
||||
## 安裝
|
||||
|
||||
要在 VS Code 和 Cursor、Windsurf、VSCodium 等流行分支上安装 OpenCode:
|
||||
|
||||
1. 打开VS代码
|
||||
2. 打開集成終端
|
||||
3. 运行 `opencode` - 扩展会自动安装
|
||||
|
||||
另一方面,如果您想在从 TUI 运行 `/editor` 或 `/export` 时使用自己的 IDE,则需要设置 `export EDITOR="code --wait"`。 [了解更多](/docs/tui/#editor-setup)。
|
||||
|
||||
---
|
||||
|
||||
### 手動安裝
|
||||
|
||||
在扩展市场中搜索**OpenCode**,然后单击**安装**。
|
||||
|
||||
---
|
||||
|
||||
### 故障排除
|
||||
|
||||
如果擴展無法自動安裝:
|
||||
|
||||
- 确定您在集成终止中运行`opencode`。
|
||||
- 确认您的 IDE 和 CLI 已安装:
|
||||
- 对于 VS 代码:`code` 命令
|
||||
- 适用字体:`cursor` 命令
|
||||
- 对于风帆冲浪:`windsurf` 命令
|
||||
- 对于 VSCodium:`codium` 命令
|
||||
- 如果,请运行 `Cmd+Shift+P` (Mac) 或 `Ctrl+Shift+P` (Windows/Linux) 并搜索“Shell Command: Install 'code' command in PATH”(或适用于您的 IDE 的没有对应命令)
|
||||
- 确保 VS Code 能够安装扩展
|
||||
359
packages/web/src/content/docs/zh-cn/index.mdx
Normal file
359
packages/web/src/content/docs/zh-cn/index.mdx
Normal file
@@ -0,0 +1,359 @@
|
||||
---
|
||||
title: 簡介
|
||||
description: 开始使用OpenCode。
|
||||
---
|
||||
|
||||
import { Tabs, TabItem } from "@astrojs/starlight/components"
|
||||
import config from "../../../../config.mjs"
|
||||
export const console = config.console
|
||||
|
||||
[**开放代码**](/)是一个开源人工智能编码代理。它可用于基于终端的界面、桌面应用程序或IDE扩展。
|
||||
|
||||

|
||||
|
||||
讓我們開始吧。
|
||||
|
||||
---
|
||||
|
||||
#### 先決條件
|
||||
|
||||
要在终端中使用OpenCode,您需要:
|
||||
|
||||
1. 現代終端模擬器,例如:
|
||||
- [韦兹术语](https://wezterm.org),跨平台
|
||||
- [阿拉克里蒂](https://alacritty.org),跨平台
|
||||
- [幽灵般的](https://ghostty.org),Linux 和 macOS
|
||||
- [ 猫咪](https://sw.kovidgoyal.net/kitty/),Linux 和 macOS
|
||||
|
||||
2. 您想要使用的 LLM 强大的 API 钥匙。
|
||||
|
||||
---
|
||||
|
||||
## 安裝
|
||||
|
||||
安装 OpenCode 最简单的方法是通过安装脚本。
|
||||
|
||||
```bash
|
||||
curl -fsSL https://opencode.ai/install | bash
|
||||
```
|
||||
|
||||
您還可以使用以下命令安裝它:
|
||||
|
||||
- **使用 Node.js**
|
||||
|
||||
<Tabs>
|
||||
|
||||
<TabItem label="npm">
|
||||
```bash
|
||||
npm install -g opencode-ai
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem label="Bun">
|
||||
```bash
|
||||
bun install -g opencode-ai
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem label="pnpm">
|
||||
```bash
|
||||
pnpm install -g opencode-ai
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem label="Yarn">
|
||||
```bash
|
||||
yarn global add opencode-ai
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
||||
- **在 macOS 和 Linux 上使用 Homebrew**
|
||||
|
||||
```bash
|
||||
brew install anomalyco/tap/opencode
|
||||
```
|
||||
|
||||
> 我们使用 OpenCode Tap 来获取最新版本。官方 `brew install opencode` 公式由 Homebrew 团队建议,维护频率较低。
|
||||
|
||||
- **在 Arch Linux 上使用 Paru**
|
||||
|
||||
```bash
|
||||
paru -S opencode-bin
|
||||
```
|
||||
|
||||
#### 視窗
|
||||
|
||||
:::tip[Recommended: 使用 WSL]
|
||||
为了在 Windows 上获得最佳体验,我们建议使用[适用于 Linux 的 Windows 子系统 (WSL)](/docs/windows-wsl)。它提供了更好的性能并与 OpenCode 的功能完全兼容。
|
||||
:::
|
||||
|
||||
- **使用巧克力**
|
||||
|
||||
```bash
|
||||
choco install opencode
|
||||
```
|
||||
|
||||
- **使用勺子**
|
||||
|
||||
```bash
|
||||
scoop install opencode
|
||||
```
|
||||
|
||||
- **使用 NPM**
|
||||
|
||||
```bash
|
||||
npm install -g opencode-ai
|
||||
```
|
||||
|
||||
- **使用米塞**
|
||||
|
||||
```bash
|
||||
mise use -g github:anomalyco/opencode
|
||||
```
|
||||
|
||||
- **使用 Docker**
|
||||
|
||||
```bash
|
||||
docker run -it --rm ghcr.io/anomalyco/opencode
|
||||
```
|
||||
|
||||
目前正在支持在 Windows 上安装 OpenCode 时使用 Bun。
|
||||
|
||||
您还可以从[发布](https://github.com/anomalyco/opencode/releases) 获取二进制文件。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
借助 OpenCode,您可以通过配置 API 来使用任何 LLM 成功。
|
||||
|
||||
如果您不熟悉使用 LLM 成功,我们建议使用[开放代码禅](/docs/zen)。
|
||||
这是经过 OpenCode 测试和验证的精选模型列表
|
||||
團隊。
|
||||
|
||||
1. 在 TUI 中运行 `/connect` 命令,选择 opencode,然后前往 [opencode.ai/auth](https://opencode.ai/auth)。
|
||||
|
||||
```txt
|
||||
/connect
|
||||
```
|
||||
|
||||
2. 登录,添加您的账单信息,然后复制您的详细 API 密钥。
|
||||
|
||||
3. 粘贴您的 API 钥匙。
|
||||
|
||||
```txt
|
||||
┌ API key
|
||||
│
|
||||
│
|
||||
└ enter
|
||||
```
|
||||
|
||||
或者,您可以选择其他巨头之一。 [了解更多](/docs/providers#directory)。
|
||||
|
||||
---
|
||||
|
||||
## 初始化
|
||||
|
||||
現在您已經配置了提供程序,您可以導航到一個項目
|
||||
你想繼續工作。
|
||||
|
||||
```bash
|
||||
cd /path/to/project
|
||||
```
|
||||
|
||||
并运行OpenCode。
|
||||
|
||||
```bash
|
||||
opencode
|
||||
```
|
||||
|
||||
接下来,通过运行以下命令来初始化项目的 OpenCode。
|
||||
|
||||
```bash frame="none"
|
||||
/init
|
||||
```
|
||||
|
||||
这涉及 OpenCode 分析您的项目并在以下位置创建 `AGENTS.md` 文件
|
||||
項目根。
|
||||
|
||||
:::提示
|
||||
您应该将项目的 `AGENTS.md` 文件提交到 Git。
|
||||
:::
|
||||
|
||||
这有助于 OpenCode 理解项目结构和编码模式
|
||||
用過的。
|
||||
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
您现在已准备好使用 OpenCode 来处理您的项目。请轻松询问
|
||||
任何事物!
|
||||
|
||||
如果您不熟悉使用 AI 编码代理,以下是一些可能会有所帮助的示例
|
||||
幫助。
|
||||
|
||||
---
|
||||
|
||||
### 提出問題
|
||||
|
||||
您可以要求 OpenCode 向您解释代码库。
|
||||
|
||||
:::提示
|
||||
使用`@`鍵模糊搜索工程中的文件。
|
||||
:::
|
||||
|
||||
```txt frame="none" "@packages/functions/src/api/index.ts"
|
||||
How is authentication handled in @packages/functions/src/api/index.ts
|
||||
```
|
||||
|
||||
如果您沒有處理代碼庫的一部分,這會很有幫助。
|
||||
|
||||
---
|
||||
|
||||
### 添加功能
|
||||
|
||||
您可以要求 OpenCode 向您的项目添加新功能。但是我们首先建议要求它制定一个计划。
|
||||
|
||||
1. **制定計劃**
|
||||
|
||||
OpenCode 有一个*计划模式*,该模式禁止其进行更改和
|
||||
相反,建議*如何*實現該功能。
|
||||
|
||||
使用 **Tab** 键切换到它。您会在右下角有一个指示符。
|
||||
|
||||
```bash frame="none" title="Switch to Plan mode"
|
||||
<TAB>
|
||||
```
|
||||
|
||||
現在讓我們描述一下我們想要它做什麼。
|
||||
|
||||
```txt frame="none"
|
||||
When a user deletes a note, we'd like to flag it as deleted in the database.
|
||||
Then create a screen that shows all the recently deleted notes.
|
||||
From this screen, the user can undelete a note or permanently delete it.
|
||||
```
|
||||
|
||||
您需要为 OpenCode 提供足够的详细信息才能了解您想要的内容。它有帮助
|
||||
就像與團隊中的初級開發人員交談一樣與它交談。
|
||||
|
||||
:::提示
|
||||
为 OpenCode 提供大量上下文和示例,以帮助其理解您的内容
|
||||
想。
|
||||
:::
|
||||
|
||||
2. **迭代計劃**
|
||||
|
||||
一旦它為您提供了計劃,您就可以提供反饋或添加更多詳細信息。
|
||||
|
||||
```txt frame="none"
|
||||
We'd like to design this new screen using a design I've used before.
|
||||
[Image #1] Take a look at this image and use it as a reference.
|
||||
```
|
||||
|
||||
:::提示
|
||||
將圖像拖放到終端中以將其添加到提示中。
|
||||
:::
|
||||
|
||||
OpenCode 可以扫描您提供的任何图像并将其添加到提示中。您可以
|
||||
通過將圖像拖放到終端中來完成此操作。
|
||||
|
||||
3. **構建功能**
|
||||
|
||||
一旦您對計劃感到滿意,請切換回*構建模式*
|
||||
再次按 **Tab** 键。
|
||||
|
||||
```bash frame="none"
|
||||
<TAB>
|
||||
```
|
||||
|
||||
並要求它做出改變。
|
||||
|
||||
```bash frame="none"
|
||||
Sounds good! Go ahead and make the changes.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 做出改變
|
||||
|
||||
对于更直接的更改,您可以要求 OpenCode 直接构建它
|
||||
無需先審查計劃。
|
||||
|
||||
```txt frame="none" "@packages/functions/src/settings.ts" "@packages/functions/src/notes.ts"
|
||||
We need to add authentication to the /settings route. Take a look at how this is
|
||||
handled in the /notes route in @packages/functions/src/notes.ts and implement
|
||||
the same logic in @packages/functions/src/settings.ts
|
||||
```
|
||||
|
||||
您需要确保提供大量详细信息,以便 OpenCode 做出正确的决定
|
||||
變化。
|
||||
|
||||
---
|
||||
|
||||
### 撤消更改
|
||||
|
||||
假设您要求 OpenCode 进行一些更改。
|
||||
|
||||
```txt frame="none" "@packages/functions/src/api/index.ts"
|
||||
Can you refactor the function in @packages/functions/src/api/index.ts?
|
||||
```
|
||||
|
||||
但你意識到這不是你想要的。您**可以撤消**更改
|
||||
使用 `/undo` 命令。
|
||||
|
||||
```bash frame="none"
|
||||
/undo
|
||||
```
|
||||
|
||||
OpenCode 现在将恢复您所做的更改并显示您的原始消息
|
||||
再次。
|
||||
|
||||
```txt frame="none" "@packages/functions/src/api/index.ts"
|
||||
Can you refactor the function in @packages/functions/src/api/index.ts?
|
||||
```
|
||||
|
||||
您可以从这里调整提示并要求 OpenCode 重试。
|
||||
|
||||
:::提示
|
||||
您可以多次运行 `/undo` 以取消消减更改。
|
||||
:::
|
||||
|
||||
或者您**可以使用 `/redo` 命令重做**更改。
|
||||
|
||||
```bash frame="none"
|
||||
/redo
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 分享
|
||||
|
||||
您与 OpenCode 的对话可以[与您的
|
||||
團隊](/docs/分享)。
|
||||
|
||||
```bash frame="none"
|
||||
/share
|
||||
```
|
||||
|
||||
這將創建當前對話的鏈接並將其複製到剪貼板。
|
||||
|
||||
:::笔记
|
||||
默認情況下不共享對話。
|
||||
:::
|
||||
|
||||
这是带有 OpenCode 的[示例对话](https://opencode.ai/s/4XP1fce5)。
|
||||
|
||||
---
|
||||
|
||||
## 定制
|
||||
|
||||
就是这样!您现在已经是使用 OpenCode 的专家了。
|
||||
|
||||
要让您成为自己的,我们建议[选择一个主题](/docs/themes)、[自定义交互绑定](/docs/keybinds)、[配置代码整理程序](/docs/formatters)、[创建自定义命令](/docs/commands)或使用[开放代码配置](/docs/config)。
|
||||
192
packages/web/src/content/docs/zh-cn/keybinds.mdx
Normal file
192
packages/web/src/content/docs/zh-cn/keybinds.mdx
Normal file
@@ -0,0 +1,192 @@
|
||||
---
|
||||
title: 按鍵綁定
|
||||
description: 自定義您的按鍵綁定。
|
||||
---
|
||||
|
||||
OpenCode 有一个按键绑定列表,您可以通过 OpenCode 配置进行自定义。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"keybinds": {
|
||||
"leader": "ctrl+x",
|
||||
"app_exit": "ctrl+c,ctrl+d,<leader>q",
|
||||
"editor_open": "<leader>e",
|
||||
"theme_list": "<leader>t",
|
||||
"sidebar_toggle": "<leader>b",
|
||||
"scrollbar_toggle": "none",
|
||||
"username_toggle": "none",
|
||||
"status_view": "<leader>s",
|
||||
"tool_details": "none",
|
||||
"session_export": "<leader>x",
|
||||
"session_new": "<leader>n",
|
||||
"session_list": "<leader>l",
|
||||
"session_timeline": "<leader>g",
|
||||
"session_fork": "none",
|
||||
"session_rename": "none",
|
||||
"session_share": "none",
|
||||
"session_unshare": "none",
|
||||
"session_interrupt": "escape",
|
||||
"session_compact": "<leader>c",
|
||||
"session_child_cycle": "<leader>right",
|
||||
"session_child_cycle_reverse": "<leader>left",
|
||||
"session_parent": "<leader>up",
|
||||
"messages_page_up": "pageup,ctrl+alt+b",
|
||||
"messages_page_down": "pagedown,ctrl+alt+f",
|
||||
"messages_line_up": "ctrl+alt+y",
|
||||
"messages_line_down": "ctrl+alt+e",
|
||||
"messages_half_page_up": "ctrl+alt+u",
|
||||
"messages_half_page_down": "ctrl+alt+d",
|
||||
"messages_first": "ctrl+g,home",
|
||||
"messages_last": "ctrl+alt+g,end",
|
||||
"messages_next": "none",
|
||||
"messages_previous": "none",
|
||||
"messages_copy": "<leader>y",
|
||||
"messages_undo": "<leader>u",
|
||||
"messages_redo": "<leader>r",
|
||||
"messages_last_user": "none",
|
||||
"messages_toggle_conceal": "<leader>h",
|
||||
"model_list": "<leader>m",
|
||||
"model_cycle_recent": "f2",
|
||||
"model_cycle_recent_reverse": "shift+f2",
|
||||
"model_cycle_favorite": "none",
|
||||
"model_cycle_favorite_reverse": "none",
|
||||
"variant_cycle": "ctrl+t",
|
||||
"command_list": "ctrl+p",
|
||||
"agent_list": "<leader>a",
|
||||
"agent_cycle": "tab",
|
||||
"agent_cycle_reverse": "shift+tab",
|
||||
"input_clear": "ctrl+c",
|
||||
"input_paste": "ctrl+v",
|
||||
"input_submit": "return",
|
||||
"input_newline": "shift+return,ctrl+return,alt+return,ctrl+j",
|
||||
"input_move_left": "left,ctrl+b",
|
||||
"input_move_right": "right,ctrl+f",
|
||||
"input_move_up": "up",
|
||||
"input_move_down": "down",
|
||||
"input_select_left": "shift+left",
|
||||
"input_select_right": "shift+right",
|
||||
"input_select_up": "shift+up",
|
||||
"input_select_down": "shift+down",
|
||||
"input_line_home": "ctrl+a",
|
||||
"input_line_end": "ctrl+e",
|
||||
"input_select_line_home": "ctrl+shift+a",
|
||||
"input_select_line_end": "ctrl+shift+e",
|
||||
"input_visual_line_home": "alt+a",
|
||||
"input_visual_line_end": "alt+e",
|
||||
"input_select_visual_line_home": "alt+shift+a",
|
||||
"input_select_visual_line_end": "alt+shift+e",
|
||||
"input_buffer_home": "home",
|
||||
"input_buffer_end": "end",
|
||||
"input_select_buffer_home": "shift+home",
|
||||
"input_select_buffer_end": "shift+end",
|
||||
"input_delete_line": "ctrl+shift+d",
|
||||
"input_delete_to_line_end": "ctrl+k",
|
||||
"input_delete_to_line_start": "ctrl+u",
|
||||
"input_backspace": "backspace,shift+backspace",
|
||||
"input_delete": "ctrl+d,delete,shift+delete",
|
||||
"input_undo": "ctrl+-,super+z",
|
||||
"input_redo": "ctrl+.,super+shift+z",
|
||||
"input_word_forward": "alt+f,alt+right,ctrl+right",
|
||||
"input_word_backward": "alt+b,alt+left,ctrl+left",
|
||||
"input_select_word_forward": "alt+shift+f,alt+shift+right",
|
||||
"input_select_word_backward": "alt+shift+b,alt+shift+left",
|
||||
"input_delete_word_forward": "alt+d,alt+delete,ctrl+delete",
|
||||
"input_delete_word_backward": "ctrl+w,ctrl+backspace,alt+backspace",
|
||||
"history_previous": "up",
|
||||
"history_next": "down",
|
||||
"terminal_suspend": "ctrl+z",
|
||||
"terminal_title_toggle": "none",
|
||||
"tips_toggle": "<leader>h",
|
||||
"display_thinking": "none"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 領袖鑰匙
|
||||
|
||||
OpenCode 对大多数按键绑定使用 `leader` 键。这可以避免终端中的冲突。
|
||||
|
||||
默认情况下,`ctrl+x` 是主键,大多数操作要求您先按主键,再按键盘。例如,要开始新会话,请先按 `ctrl+x`,然后按 `n`。
|
||||
|
||||
您不需要為鍵綁定使用主鍵,但我們建議您這樣做。
|
||||
|
||||
---
|
||||
|
||||
## 禁用按鍵綁定
|
||||
|
||||
您可以通过将按键添加到您的配置中并使用值“none”来取消按键绑定。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"keybinds": {
|
||||
"session_compact": "none"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 桌面提示快捷方式
|
||||
|
||||
OpenCode 桌面应用程序提示输入支持常见的 Readline/Emacs 风格的文本编辑快捷方式。这些是内置的,目前无法通过 `opencode.json` 进行配置。
|
||||
|
||||
|快捷方式 |行動|
|
||||
| -------- | ---------------------------------------- |
|
||||
| `ctrl+a` | 移至当前行起点 |
|
||||
| `ctrl+e` | 移至当前行尾 |
|
||||
| `ctrl+b` |将牙刷墨水移动一个字符|
|
||||
| `ctrl+f` |将光标向前移动一个字符 |
|
||||
| `alt+b` |将杭州墨水移动一个字|
|
||||
| `alt+f` |将曼哈顿向前移动一个字 |
|
||||
| `ctrl+d` |删除光标下的字符|
|
||||
| `ctrl+k` |尾巴狂奔 |
|
||||
| `ctrl+u` | 杀至行首 |
|
||||
| `ctrl+w` |删除前一个单词|
|
||||
| `alt+d` | 杀死下一个词 |
|
||||
| `ctrl+t` | 转置字符 |
|
||||
| `ctrl+g` |取消彈出窗口/中止運行響應 |
|
||||
|
||||
---
|
||||
|
||||
## Shift+Enter
|
||||
|
||||
默认情况下,某些终端不发送带有 Enter 的修饰配置键。您可能需要将终端发送 `Shift+Enter` 作为转义序列。
|
||||
|
||||
### Windows终端
|
||||
|
||||
打开您的`settings.json`:
|
||||
|
||||
```
|
||||
%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json
|
||||
```
|
||||
|
||||
将其添加到根级`actions`数据库:
|
||||
|
||||
```json
|
||||
"actions": [
|
||||
{
|
||||
"command": {
|
||||
"action": "sendInput",
|
||||
"input": "\u001b[13;2u"
|
||||
},
|
||||
"id": "User.sendInput.ShiftEnterCustom"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
将其添加到根级`keybindings`数据库:
|
||||
|
||||
```json
|
||||
"keybindings": [
|
||||
{
|
||||
"keys": "shift+enter",
|
||||
"id": "User.sendInput.ShiftEnterCustom"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
保存文件并重新启动Windows终端或打开新选项卡。
|
||||
188
packages/web/src/content/docs/zh-cn/lsp.mdx
Normal file
188
packages/web/src/content/docs/zh-cn/lsp.mdx
Normal file
@@ -0,0 +1,188 @@
|
||||
---
|
||||
title: LSP服务器
|
||||
description: OpenCode 与您的 LSP 服务器集成。
|
||||
---
|
||||
|
||||
OpenCode 与您的语言服务器协议 (LSP) 集成,以帮助 LLM 与您的代码库交互。它使用诊断向法学硕士提供反馈。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
OpenCode附带了多种适用于流行语言的内置LSP服务器:
|
||||
|
||||
| LSP服务器|扩展|要求|
|
||||
| ------------------ | ------------------------------------------------------------------- | ------------------------------------------------------------ |
|
||||
|天文 | .astro | Astro 项目自动安装 |
|
||||
| bash | .sh、.bash、.zsh、.ksh | 自动安装bash-语言- 服务器 |
|
||||
|叮叮| .c、.cpp、.cc、.cxx、.c++、.h、.hpp、.hh、.hxx、.h++ |自动安装 C/C++ 项目 |
|
||||
|夏普| .cs | `.NET SDK` 已安装 |
|
||||
| Clojure-lsp | 语言.clj、.cljs、.cljc、.edn | `clojure-lsp` 命令可用 |
|
||||
|飞镖 | .dart | `dart` 命令可用 |
|
||||
| 给定 | .ts、.tsx、.js、.jsx、.mjs | `deno`命令可用(自动检测deno.json/deno.jsonc)|
|
||||
|长生不老药-LS | .ex、.exs | `elixir` 命令可用 |
|
||||
|埃斯林特 | .ts、.tsx、.js、.jsx、.mjs、.cjs、.mts、.cts、.vue | `eslint` 项目中的依赖项 |
|
||||
|锐利 | .fs、.fsi、.fsx、.fsscript | `.NET SDK` 已安装 |
|
||||
|微光| .gleam | `gleam` 命令可用 |
|
||||
|男生们| .go | `go` 命令可用 |
|
||||
| HLS | .hs、.lhs | `haskell-language-server-wrapper` 命令可用 |
|
||||
| jdtls| .java | `Java SDK (version 21+)` 已安装 |
|
||||
| kotlin-ls | .kt、.kts | Kotlin 项目的自动安装 |
|
||||
| lua-ls | .lua |自动安装 Lua 项目 |
|
||||
|尼克斯 | .nix | `nixd` 命令可用 |
|
||||
| ocaml-lsp | .ml、.mli | `ocamllsp` 命令可用 |
|
||||
|奥克斯林特 | .ts、.tsx、.js、.jsx、.mjs、.cjs、.mts、.cts、.vue、.astro、.svelte | `oxlint` 项目中的依赖项 |
|
||||
| php intelephense | php php .php | PHP 项目的自动安装 |
|
||||
|棱镜| .prisma | `prisma` 命令可用 |
|
||||
|皮赖特| .py, .pyi | `pyright` 依赖项已安装 |
|
||||
| ruby-lsp(rubocop)| .rb、.rake、.gemspec、.ru | `ruby` 和 `gem` 命令可用 |
|
||||
|生锈| .rs | `rust-analyzer` 命令可用 |
|
||||
|源套件-lsp | .swift、.objc、.objcpp | `swift` 已安装(`xcode` 在 macOS 上)|
|
||||
|苗条| .svelte | Svelte 项目的自动安装 |
|
||||
| 立场 | .tf、.tfvars | 从 GitHub 版本自动安装 |
|
||||
|微雾| .typ、.typc | 来自 GitHub 版本自动安装 |
|
||||
| 稿件 | 稿件.ts、.tsx、.js、.jsx、.mjs、.cjs、.mts、.cts | `typescript` 项目中的依赖项 |
|
||||
| 视图 | .vue | Vue 项目自动安装 |
|
||||
| yaml-ls | .yaml、.yml |自动安装 Red Hat yaml-language-server |
|
||||
|中立 | .zig、.zon | `zig` 命令可用 |
|
||||
|
||||
当检测到上述文件扩展名之一并且满足要求时,LSP服务器将自动启用。
|
||||
|
||||
:::笔记
|
||||
您可以通过将`OPENCODE_DISABLE_LSP_DOWNLOAD`环境变量设置为`true`来取消自动LSP服务器下载。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 它是如何運作的
|
||||
|
||||
当opencode打开一个文件时,它:
|
||||
|
||||
1. 根据所有启用的 LSP 服务器检查文件扩展名。
|
||||
2. 如果尚未运行,则启动相应的LSP服务器。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以通过opencode配置中的`lsp`部分自定义LSP服务器。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": {}
|
||||
}
|
||||
```
|
||||
|
||||
每个LSP服务器支持以下功能:
|
||||
|
||||
|物業 |類型 |描述 |
|
||||
| ---------------- | -------- | ------------------------------------------------- |
|
||||
| `disabled` |布尔 |将其设置为`true`以禁用LSP服务器|
|
||||
| `command` |字符串[] |启动LSP服务器的命令|
|
||||
| `extensions` |字符串[] |此 LSP 服务器应处理的文件扩展名 |
|
||||
| `env` |对象|启动服务器时设置的环境变量|
|
||||
| `initialization` |对象|发送到LSP服务器的初始化选项|
|
||||
|
||||
讓我們看一些例子。
|
||||
|
||||
---
|
||||
|
||||
### 環境變量
|
||||
|
||||
启动LSP服务器时使用`env`参数设置环境变量:
|
||||
|
||||
```json title="opencode.json" {5-7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": {
|
||||
"rust": {
|
||||
"env": {
|
||||
"RUST_LOG": "debug"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 初始化選項
|
||||
|
||||
使用`initialization`属性将初始化选项传递给LSP服务器。这些是在LSP `initialize`请求发送期间的服务器特定设置:
|
||||
|
||||
```json title="opencode.json" {5-9}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": {
|
||||
"typescript": {
|
||||
"initialization": {
|
||||
"preferences": {
|
||||
"importModuleSpecifierPreference": "relative"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
:::笔记
|
||||
初始化选项因 LSP 服务器而异。检查 LSP 服务器的文档以获得可用选项。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 取消LSP服务器
|
||||
|
||||
要全局取消**所有** LSP服务,其中`lsp`设置为`false`:
|
||||
|
||||
```json title="opencode.json" {3}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": false
|
||||
}
|
||||
```
|
||||
|
||||
要取消**特定** LSP服务器,使`disabled`设置为`true`:
|
||||
|
||||
```json title="opencode.json" {5}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": {
|
||||
"typescript": {
|
||||
"disabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 自定义 LSP 服务器
|
||||
|
||||
您可以通过指定命令和文件扩展名来添加自定义LSP服务器:
|
||||
|
||||
```json title="opencode.json" {4-7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"lsp": {
|
||||
"custom-lsp": {
|
||||
"command": ["custom-lsp-server", "--stdio"],
|
||||
"extensions": [".custom"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 附加信息
|
||||
|
||||
### PHP 英特尔芬斯
|
||||
|
||||
PHP Intelephense 通过许可证密钥提供高级功能。您可以通过将(仅)密钥挂钩位于以下位置的文本文件中来提供许可证密钥:
|
||||
|
||||
- 在 macOS/Linux 上:`$HOME/intelephense/licence.txt`
|
||||
- 在 Windows 上:`%USERPROFILE%/intelephense/licence.txt`
|
||||
|
||||
該文件應僅包含許可證密鑰,不包含其他內容。
|
||||
511
packages/web/src/content/docs/zh-cn/mcp-servers.mdx
Normal file
511
packages/web/src/content/docs/zh-cn/mcp-servers.mdx
Normal file
@@ -0,0 +1,511 @@
|
||||
---
|
||||
title: MCP服务器
|
||||
description: 添加本地和远程MCP工具。
|
||||
---
|
||||
|
||||
您可以使用“模型上下文协议”或MCP将外部工具添加到OpenCode。OpenCode支持本地和远程服务器。
|
||||
|
||||
添加使用后,MCP工具将自动与内置工具一起供法学硕士。
|
||||
|
||||
---
|
||||
|
||||
#### 注意事項
|
||||
|
||||
当您使用 MCP 服务器时,它会添加到上下文中。如果您有很多工具,这会很快增加。因此,我们建议您选择使用哪些 MCP 服务器。
|
||||
|
||||
:::提示
|
||||
MCP服务器会添加到您的上下文中,因此您需要小心启用哪些服务器。
|
||||
:::
|
||||
|
||||
某些MCP服务器(例如GitHub MCP服务器)往往会添加大量代币,并且很容易超出上下文限制。
|
||||
|
||||
---
|
||||
|
||||
## 使能夠
|
||||
|
||||
您可以在`mcp`下的[开放代码配置](https://opencode.ai/docs/config/)中定义MCP服务器。为每个MCP添加唯一的名称。当提示LLM时,您可以通过名称引用该MCP。
|
||||
|
||||
```jsonc title="opencode.jsonc" {6}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"name-of-mcp-server": {
|
||||
// ...
|
||||
"enabled": true,
|
||||
},
|
||||
"name-of-other-mcp-server": {
|
||||
// ...
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
您还可以通过将`enabled`设置为`false`来取消服务器。如果您想暂时取消服务器而不将其从配置中删除,这非常有用。
|
||||
|
||||
---
|
||||
|
||||
### 覆蓋遠程默認值
|
||||
|
||||
组织可以通过其 `.well-known/opencode` 端点提供默认的 MCP 服务器。这些服务器可能默认被禁用,允许用户选择他们需要的服务器。
|
||||
|
||||
要从组织的远程特定启用服务器,请使用配置 `enabled: true` 将其添加到本地配置:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"jira": {
|
||||
"type": "remote",
|
||||
"url": "https://jira.example.com/mcp",
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您的本地配置值会覆盖远程默认值。有关更多详细信息,请参阅[配置优先级](/docs/config#precedence-order)。
|
||||
|
||||
---
|
||||
|
||||
## 當地的
|
||||
|
||||
使用`type`将本地MCP服务器添加到MCP对像中的`"local"`。
|
||||
|
||||
```jsonc title="opencode.jsonc" {15}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-local-mcp-server": {
|
||||
"type": "local",
|
||||
// Or ["bun", "x", "my-mcp-command"]
|
||||
"command": ["npx", "-y", "my-mcp-command"],
|
||||
"enabled": true,
|
||||
"environment": {
|
||||
"MY_ENV_VAR": "my_env_var_value",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
该命令是本地MCP服务器的启动方式。您还可以确定环境变量列表。
|
||||
|
||||
例如,以下是添加测试 [`@modelcontextprotocol/server-everything`](https://www.npmjs.com/package/@modelcontextprotocol/server-everything) MCP 服务器的方法。
|
||||
|
||||
```jsonc title="opencode.jsonc"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"mcp_everything": {
|
||||
"type": "local",
|
||||
"command": ["npx", "-y", "@modelcontextprotocol/server-everything"],
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
要使用它,我可以将 `use the mcp_everything tool` 添加到我的提示中。
|
||||
|
||||
```txt "mcp_everything"
|
||||
use the mcp_everything tool to add the number 3 and 4
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 選項
|
||||
|
||||
以下是配置本地 MCP 服务器的所有选项。
|
||||
|
||||
|選項|類型 |必填 |描述 |
|
||||
| ------------- | ------- | -------- | ----------------------------------------------------------------------------------- |
|
||||
| `type` |字符串|是| MCP 服务器连接类型,必须是`"local"`。
|
||||
| `command` | 数据库 | 是 | 运行 MCP 服务器的命令和参数。
|
||||
| `environment` |对象| |运行服务器时设置的环境变量。
|
||||
| `enabled` | 布尔 | |在启动时启用或禁用MCP 服务器。
|
||||
| `timeout` | 数量 | |从MCP服务器获取工具的超时(以毫秒为单位)。默认为5000(5秒)。 |
|
||||
|
||||
---
|
||||
|
||||
## 偏僻的
|
||||
|
||||
通过将`type`设置为ZZPH1Z添加远程MCP服务器。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-remote-mcp": {
|
||||
"type": "remote",
|
||||
"url": "https://my-mcp-server.com",
|
||||
"enabled": true,
|
||||
"headers": {
|
||||
"Authorization": "Bearer MY_API_KEY"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`url` 是远程MCP服务器的URL,使用`headers`选项您可以创建标头列表。
|
||||
|
||||
---
|
||||
|
||||
#### 選項
|
||||
|
||||
|選項|類型 |必填 |描述 |
|
||||
| --------- | ------- | -------- | ----------------------------------------------------------------------------------- |
|
||||
| `type` |字符串|是| MCP 服务器连接类型,必须是`"remote"`。
|
||||
| | `url` |字符串|是|远程MCP服务器的URL。
|
||||
| `enabled` | 布尔 | |在启动时启用或禁用MCP 服务器。
|
||||
| `headers` |对象| |随请求一起发送的标头。
|
||||
| `oauth` |对象| | OAuth 身份验证。请参阅下面的配置[开放认证](#oauth) 部分。 |
|
||||
| `timeout` | 数量 | |从MCP服务器获取工具的超时(以毫秒为单位)。默认为5000(5秒)。 |
|
||||
|
||||
---
|
||||
|
||||
## 開放認證
|
||||
|
||||
OpenCode自动处理远程MCP服务器的OAuth身份验证。当服务器需要身份验证时,OpenCode将:
|
||||
|
||||
1. 检测 401 响应并启动 OAuth 流程
|
||||
2. 如果服务器支持,请使用**动态客户端注册 (RFC 7591)**
|
||||
3. 安全地存儲令牌以供將來的請求
|
||||
|
||||
---
|
||||
|
||||
### 自動的
|
||||
|
||||
对于大多数支持 OAuth 的 MCP 配置服务器,不需要特殊配置。只需远程服务器:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-oauth-server": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.example.com/mcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果服務器需要身份驗證,OpenCode 將在您第一次嘗試使用它時提示您進行身份驗證。如果沒有,您可以使用 `opencode mcp auth <server-name>`[手動觸發流量](#authenticating)。
|
||||
|
||||
---
|
||||
|
||||
### 預登記
|
||||
|
||||
如果您有来自MCP服务器强大的客户端,则可以配置它们:
|
||||
|
||||
```json title="opencode.json" {7-11}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-oauth-server": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.example.com/mcp",
|
||||
"oauth": {
|
||||
"clientId": "{env:MY_MCP_CLIENT_ID}",
|
||||
"clientSecret": "{env:MY_MCP_CLIENT_SECRET}",
|
||||
"scope": "tools:read tools:execute"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 正在驗證
|
||||
|
||||
您可以手動觸發身份驗證或管理憑據。
|
||||
|
||||
使用特定MCP服务器进行身份验证:
|
||||
|
||||
```bash
|
||||
opencode mcp auth my-oauth-server
|
||||
```
|
||||
|
||||
列出所有MCP服务器及其身份验证状态:
|
||||
|
||||
```bash
|
||||
opencode mcp list
|
||||
```
|
||||
|
||||
刪除存儲的憑據:
|
||||
|
||||
```bash
|
||||
opencode mcp logout my-oauth-server
|
||||
```
|
||||
|
||||
`mcp auth` 命令将打开您的浏览器进行授权。授权后,OpenCode 令牌安全地存储在 `~/.local/share/opencode/mcp-auth.json` 中。
|
||||
|
||||
---
|
||||
|
||||
#### 禁用 OAuth
|
||||
|
||||
如果要禁用服务器的自动OAuth(例如,对于使用API密钥的服务器),则`oauth`设置为`false`:
|
||||
|
||||
```json title="opencode.json" {7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-api-key-server": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.example.com/mcp",
|
||||
"oauth": false,
|
||||
"headers": {
|
||||
"Authorization": "Bearer {env:MY_API_KEY}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### OAuth 选项
|
||||
|
||||
|選項|類型 |描述 |
|
||||
| -------------- | --------------- | -------------------------------------------------------------------------------- |
|
||||
| `oauth` |对象\|假| OAuth 配置对象,或 `false` 以取消 OAuth 自动检测。
|
||||
| `clientId` |字符串| OAuth 客户端 ID。如果未提供,将尝试动态客户端注册。 |
|
||||
| `clientSecret` |字符串| OAuth客户端密钥(如果需要授权服务器)。
|
||||
| `scope` |字符串|授权期间请求的 OAuth 范围。
|
||||
|
||||
#### 偵錯
|
||||
|
||||
如果远程MCP服务器无法进行身份验证,您可以通过以下方式诊断问题:
|
||||
|
||||
```bash
|
||||
# View auth status for all OAuth-capable servers
|
||||
opencode mcp auth list
|
||||
|
||||
# Debug connection and OAuth flow for a specific server
|
||||
opencode mcp debug my-oauth-server
|
||||
```
|
||||
|
||||
`mcp debug`命令显示当前身份验证状态、测试HTTP连接并尝试OAuth发现流程。
|
||||
|
||||
---
|
||||
|
||||
## 管理
|
||||
|
||||
您的 MCP 可以作为 OpenCode 中的工具以及内置工具使用。,您可以像任何其他工具一样通过 OpenCode 配置来管理它们。
|
||||
|
||||
---
|
||||
|
||||
### 全球的
|
||||
|
||||
這意味著您可以全局啟用或禁用它們。
|
||||
|
||||
```json title="opencode.json" {14}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-mcp-foo": {
|
||||
"type": "local",
|
||||
"command": ["bun", "x", "my-mcp-command-foo"]
|
||||
},
|
||||
"my-mcp-bar": {
|
||||
"type": "local",
|
||||
"command": ["bun", "x", "my-mcp-command-bar"]
|
||||
}
|
||||
},
|
||||
"tools": {
|
||||
"my-mcp-foo": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
我们还可以使用 glob 模式来取消所有匹配的 MCP。
|
||||
|
||||
```json title="opencode.json" {14}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-mcp-foo": {
|
||||
"type": "local",
|
||||
"command": ["bun", "x", "my-mcp-command-foo"]
|
||||
},
|
||||
"my-mcp-bar": {
|
||||
"type": "local",
|
||||
"command": ["bun", "x", "my-mcp-command-bar"]
|
||||
}
|
||||
},
|
||||
"tools": {
|
||||
"my-mcp*": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
这里我们使用 glob 模式 `my-mcp*` 来取消所有 MCP。
|
||||
|
||||
---
|
||||
|
||||
### 每個代理人
|
||||
|
||||
如果您有大量 MCP 服务器,您可以选择为每个代理启用它们并全局取消它们。因此:
|
||||
|
||||
1. 全局禁用它作為工具。
|
||||
2. 在您的[代理配置](/docs/agents#tools)中,启用MCP作为服务器工具。
|
||||
|
||||
```json title="opencode.json" {11, 14-18}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"my-mcp": {
|
||||
"type": "local",
|
||||
"command": ["bun", "x", "my-mcp-command"],
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"tools": {
|
||||
"my-mcp*": false
|
||||
},
|
||||
"agent": {
|
||||
"my-agent": {
|
||||
"tools": {
|
||||
"my-mcp*": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### 全局模式
|
||||
|
||||
glob 模式使用简单的正则表达式 globbing 模式:
|
||||
|
||||
- `*` 匹配零个或多个任意字符(例如,`"my-mcp*"` 匹配 `my-mcp_search`、`my-mcp_list` 等)
|
||||
- `?` 恰好匹配一個字符
|
||||
- 所有其他字符均按字面意思匹配
|
||||
|
||||
:::笔记
|
||||
MCP服务器工具以名称服务器作为出口进行注册,要因此禁用服务器的所有工具,只需使用:
|
||||
|
||||
```
|
||||
"mymcpservername_*": false
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 示例
|
||||
|
||||
以下是一些常见的 MCP 服务器的示例。如果您想记录其他服务器,您可以提交 PR。
|
||||
|
||||
---
|
||||
|
||||
### 哨兵
|
||||
|
||||
添加[哨兵MCP服务器](https://mcp.sentry.dev)以与您的Sentry项目和问题进行交互。
|
||||
|
||||
```json title="opencode.json" {4-8}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"sentry": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.sentry.dev/mcp",
|
||||
"oauth": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
添加配置后,使用Sentry进行身份验证:
|
||||
|
||||
```bash
|
||||
opencode mcp auth sentry
|
||||
```
|
||||
|
||||
这将打开一个浏览器窗口以完成 OAuth 流程并将 OpenCode 连接到您的 Sentry 账户。
|
||||
|
||||
通过身份验证后,您可以在提示中使用Sentry工具来查询问题、项目和错误数据。
|
||||
|
||||
```txt "use sentry"
|
||||
Show me the latest unresolved issues in my project. use sentry
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 背景7
|
||||
|
||||
添加[Context7 MCP 服务器](https://github.com/upstash/context7) 以搜索文档。
|
||||
|
||||
```json title="opencode.json" {4-7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"context7": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.context7.com/mcp"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果您注册了免费帐户,则可以使用 API 轴并获得更高的速率限制。
|
||||
|
||||
```json title="opencode.json" {7-9}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"context7": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.context7.com/mcp",
|
||||
"headers": {
|
||||
"CONTEXT7_API_KEY": "{env:CONTEXT7_API_KEY}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
这里我们假设您设置了 `CONTEXT7_API_KEY` 环境变量。
|
||||
|
||||
将 `use context7` 添加到提示中以使用 Context7 MCP 服务器。
|
||||
|
||||
```txt "use context7"
|
||||
Configure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7
|
||||
```
|
||||
|
||||
或者,您可以将类似的内容添加到您的[代理.md](/docs/rules/)。
|
||||
|
||||
```md title="AGENTS.md"
|
||||
When you need to search docs, use `context7` tools.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Vercel 的 Grep
|
||||
|
||||
添加 [Vercel 的 Grep](https://grep.app) MCP 服务器正在搜索 GitHub 上的代码片段。
|
||||
|
||||
```json title="opencode.json" {4-7}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mcp": {
|
||||
"gh_grep": {
|
||||
"type": "remote",
|
||||
"url": "https://mcp.grep.app"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
由于我们将 MCP 服务器命名为 `gh_grep`,因此您可以将 `use the gh_grep tool` 添加到提示中以便代理使用它。
|
||||
|
||||
```txt "use the gh_grep tool"
|
||||
What's the right way to set a custom domain in an SST Astro component? use the gh_grep tool
|
||||
```
|
||||
|
||||
或者,您可以将类似的内容添加到您的[代理.md](/docs/rules/)。
|
||||
|
||||
```md title="AGENTS.md"
|
||||
If you are unsure how to do something, use `gh_grep` to search code examples from GitHub.
|
||||
```
|
||||
223
packages/web/src/content/docs/zh-cn/models.mdx
Normal file
223
packages/web/src/content/docs/zh-cn/models.mdx
Normal file
@@ -0,0 +1,223 @@
|
||||
---
|
||||
title: 型號
|
||||
description: 配置LLM提供者和模型。
|
||||
---
|
||||
|
||||
OpenCode 使用[人工智能软件开发工具包](https://ai-sdk.dev/) 和[模型.dev](https://models.dev) 来支持**75+ LLM 成功**,并且支持运行本地模型。
|
||||
|
||||
---
|
||||
|
||||
## 供應商
|
||||
|
||||
默认情况下会预加载大多数流行的提供程序。如果您已通过 `/connect` 命令添加了提供程序的辅助程序,那么它们将在您启动 OpenCode 时可用。
|
||||
|
||||
了解有关[提供者](/docs/providers) 的更多信息。
|
||||
|
||||
---
|
||||
|
||||
## 選擇型號
|
||||
|
||||
配置完提供商後,您可以通過輸入以下內容來選擇您想要的型號:
|
||||
|
||||
```bash frame="none"
|
||||
/models
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 推薦型號
|
||||
|
||||
那裡有很多型號,每週都會有新型號問世。
|
||||
|
||||
:::提示
|
||||
考慮使用我們推薦的模型之一。
|
||||
:::
|
||||
|
||||
然而,既擅長生成代碼又擅長工具調用的只有少數。
|
||||
|
||||
以下是与 OpenCode 配合良好的几个模型,排名不分前面。(这不是好看的列表,也不一定是最新的):
|
||||
|
||||
- GPT 5.2
|
||||
- GPT 5.1 法典
|
||||
- 近距離工作4.5
|
||||
- 克勞德十四行詩 4.5
|
||||
- 极小极M2.1
|
||||
- 雙子座 3 專業版
|
||||
|
||||
---
|
||||
|
||||
## 設置默認值
|
||||
|
||||
要將其中之一設置為默認模型,您可以在您的
|
||||
打開代碼配置。
|
||||
|
||||
```json title="opencode.json" {3}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"model": "lmstudio/google/gemma-3n-e4b"
|
||||
}
|
||||
```
|
||||
|
||||
这里完整的ID是`provider_id/model_id`。例如,如果您使用[开放代码禅](/docs/zen),则您将使用`opencode/gpt-5.1-codex`来表示GPT 5.1 Codex。
|
||||
|
||||
如果您配置了[定制生产](/docs/providers#custom),则`provider_id` 是配置中`provider` 部分的按键,`model_id` 是`provider.models` 中的按键。
|
||||
|
||||
---
|
||||
|
||||
## 配置模型
|
||||
|
||||
您可以通过 config.json 全局配置模型的选项。
|
||||
|
||||
```jsonc title="opencode.jsonc" {7-12,19-24}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {
|
||||
"openai": {
|
||||
"models": {
|
||||
"gpt-5": {
|
||||
"options": {
|
||||
"reasoningEffort": "high",
|
||||
"textVerbosity": "low",
|
||||
"reasoningSummary": "auto",
|
||||
"include": ["reasoning.encrypted_content"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"anthropic": {
|
||||
"models": {
|
||||
"claude-sonnet-4-5-20250929": {
|
||||
"options": {
|
||||
"thinking": {
|
||||
"type": "enabled",
|
||||
"budgetTokens": 16000,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
在这里,我们为两个内置模型配置全局设置:`gpt-5`(通过 `openai` 提供程序访问时间)和 `claude-sonnet-4-20250514`(通过 `anthropic` 提供程序访问时间)。
|
||||
内置结构和型号名称可以在[模型.dev](https://models.dev) 上找到。
|
||||
|
||||
您还可以为您正在使用的任何代理配置这些选项。代理配置会覆盖此处的所有全局选项。 [了解更多](/docs/agents/#additional)。
|
||||
|
||||
您還可以定義擴展內置變體的自定義變體。變體允許您為同一模型配置不同的設置,而無需創建重複的條目:
|
||||
|
||||
```jsonc title="opencode.jsonc" {6-21}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {
|
||||
"opencode": {
|
||||
"models": {
|
||||
"gpt-5": {
|
||||
"variants": {
|
||||
"high": {
|
||||
"reasoningEffort": "high",
|
||||
"textVerbosity": "low",
|
||||
"reasoningSummary": "auto",
|
||||
},
|
||||
"low": {
|
||||
"reasoningEffort": "low",
|
||||
"textVerbosity": "low",
|
||||
"reasoningSummary": "auto",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 變體
|
||||
|
||||
许多型号支持具有不同配置的多种变体。OpenCode附带了流行建设的内置默认变体。
|
||||
|
||||
### 內置變體
|
||||
|
||||
OpenCode 附带了许多重大的默认变体:
|
||||
|
||||
**人擇**:
|
||||
|
||||
- `high` - 高思维预算(默认)
|
||||
- `max` - 最大预算规划
|
||||
|
||||
**開放人工智能**:
|
||||
|
||||
因型號而異,但大致如下:
|
||||
|
||||
- `none` - 没有推理
|
||||
- `minimal` - 最少的推理工作
|
||||
- `low` - 推理工作量低
|
||||
- `medium` - 中等推理努力
|
||||
- `high` - 高推理能力
|
||||
- `xhigh` - 极高的推理能力
|
||||
|
||||
**谷歌**:
|
||||
|
||||
- `low` - 降低工作量/代幣預算
|
||||
- `high` - 更高的努力/代幣預算
|
||||
|
||||
:::提示
|
||||
該列表並不全面。許多其他提供商也有內置的默認值。
|
||||
:::
|
||||
|
||||
### 定制變體
|
||||
|
||||
您可以覆蓋現有變體或添加您自己的變體:
|
||||
|
||||
```jsonc title="opencode.jsonc" {7-18}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"provider": {
|
||||
"openai": {
|
||||
"models": {
|
||||
"gpt-5": {
|
||||
"variants": {
|
||||
"thinking": {
|
||||
"reasoningEffort": "high",
|
||||
"textVerbosity": "low",
|
||||
},
|
||||
"fast": {
|
||||
"disabled": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### 循環變體
|
||||
|
||||
使用按键绑定`variant_cycle`在变体之间快速切换。 [了解更多](/docs/keybinds)。
|
||||
|
||||
---
|
||||
|
||||
## 加載模型
|
||||
|
||||
当OpenCode启动时,它会按以下优先顺序检查模型:
|
||||
|
||||
1. `--model` 或 `-m` 配置命令行标志。格式与文件中的相同:`provider_id/model_id`。
|
||||
|
||||
2. OpenCode 配置中的模型列表。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"model": "anthropic/claude-sonnet-4-20250514"
|
||||
}
|
||||
```
|
||||
|
||||
这里的格式是`provider/model`。
|
||||
|
||||
3. 最後使用的型號。
|
||||
|
||||
4. 第一個模型使用內部優先級。
|
||||
331
packages/web/src/content/docs/zh-cn/modes.mdx
Normal file
331
packages/web/src/content/docs/zh-cn/modes.mdx
Normal file
@@ -0,0 +1,331 @@
|
||||
---
|
||||
title: 模式
|
||||
description: 不同的模式適用於不同的用例。
|
||||
---
|
||||
|
||||
:::警告
|
||||
现在通过opencode配置中的`agent`选项配置模式。这
|
||||
`mode` 选项现已废弃。 [了解更多](/docs/agents)。
|
||||
:::
|
||||
|
||||
opencode 中的模式允许自定义不同的示例行为、工具和提示。
|
||||
|
||||
它具有兩種內置模式:**構建**和**計劃**。您可以定制
|
||||
这些或通过 opencode 配置配置您自己的。
|
||||
|
||||
您可以在會話期間在模式之間切換或在配置文件中配置它們。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
opencode 有两种内置模式。
|
||||
|
||||
---
|
||||
|
||||
### 建造
|
||||
|
||||
構建是啟用所有工具的**默認**模式。這是開發工作的標準模式,您需要完全訪問文件操作和系統命令。
|
||||
|
||||
---
|
||||
|
||||
### 計劃
|
||||
|
||||
專為規劃和分析而設計的受限模式。在計劃模式下,默認情況下禁用以下工具:
|
||||
|
||||
- `write` - 无法创建新文件
|
||||
- `edit` - 无法修改现有文件,位于 `.opencode/plans/*.md` 的用于详细说明计划本身的文件另外
|
||||
- `patch` - 无法应用补丁
|
||||
- `bash` - 无法执行 shell 命令
|
||||
|
||||
当您希望人工智能分析代码、建议更改或创建计划而不对代码库进行任何实际修改时,此模式非常有用。
|
||||
|
||||
---
|
||||
|
||||
## 交換
|
||||
|
||||
您可以在会话期间使用 _Tab_ 键在模式之间切换。或者您配置的 `switch_mode` 键绑定。
|
||||
|
||||
另请参见:[格式化程序](/docs/formatters)相关代码配置的信息。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以自定義內置模式或通過配置創建自己的模式。可以通過兩種方式配置模式:
|
||||
|
||||
### JSON 配置
|
||||
|
||||
在 `opencode.json` 配置文件中配置模式:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mode": {
|
||||
"build": {
|
||||
"model": "anthropic/claude-sonnet-4-20250514",
|
||||
"prompt": "{file:./prompts/build.txt}",
|
||||
"tools": {
|
||||
"write": true,
|
||||
"edit": true,
|
||||
"bash": true
|
||||
}
|
||||
},
|
||||
"plan": {
|
||||
"model": "anthropic/claude-haiku-4-20250514",
|
||||
"tools": {
|
||||
"write": false,
|
||||
"edit": false,
|
||||
"bash": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 降價配置
|
||||
|
||||
您还可以使用 Markdown 文件定义模式。将它们放入:
|
||||
|
||||
- 全球:`~/.config/opencode/modes/`
|
||||
- 项目:`.opencode/modes/`
|
||||
|
||||
```markdown title="~/.config/opencode/modes/review.md"
|
||||
---
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
temperature: 0.1
|
||||
tools:
|
||||
write: false
|
||||
edit: false
|
||||
bash: false
|
||||
---
|
||||
|
||||
You are in code review mode. Focus on:
|
||||
|
||||
- Code quality and best practices
|
||||
- Potential bugs and edge cases
|
||||
- Performance implications
|
||||
- Security considerations
|
||||
|
||||
Provide constructive feedback without making direct changes.
|
||||
```
|
||||
|
||||
Markdown 文件名成为模式名称(例如,`review.md` 创建`review` 模式)。
|
||||
|
||||
讓我們詳細看看這些配置選項。
|
||||
|
||||
---
|
||||
|
||||
### 模型
|
||||
|
||||
使用`model`配置覆盖此模式的默认模型。对于使用针对不同任务优化的不同模型很有用。例如,更快的规划模型、更强大的实施模型。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"mode": {
|
||||
"plan": {
|
||||
"model": "anthropic/claude-haiku-4-20250514"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 溫度
|
||||
|
||||
使用`temperature`配置控制AI响应的随机性和创造。较低的值使响应更加集中和确定,而较高的值则增加创造力和可变性。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"mode": {
|
||||
"plan": {
|
||||
"temperature": 0.1
|
||||
},
|
||||
"creative": {
|
||||
"temperature": 0.8
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
溫度值的範圍通常為 0.0 到 1.0:
|
||||
|
||||
- **0.0-0.2**:非常集中且確定的響應,非常適合代碼分析和規劃
|
||||
- **0.3-0.5**:具有一定創造力的平衡響應,適合一般開發任務
|
||||
- **0.6-1.0**:更有創意和多樣化的反應,有助於頭腦風暴和探索
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"mode": {
|
||||
"analyze": {
|
||||
"temperature": 0.1,
|
||||
"prompt": "{file:./prompts/analysis.txt}"
|
||||
},
|
||||
"build": {
|
||||
"temperature": 0.3
|
||||
},
|
||||
"brainstorm": {
|
||||
"temperature": 0.7,
|
||||
"prompt": "{file:./prompts/creative.txt}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果未指定温度,opencode将使用特定于模型的默认值(大多数模型通常为0,Qwen模型为0.55)。
|
||||
|
||||
---
|
||||
|
||||
### 迅速的
|
||||
|
||||
使用 `prompt` 配置为模式指定自定义系统提示文件。提示文件应包含特定于该模式用途的指令。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"mode": {
|
||||
"review": {
|
||||
"prompt": "{file:./prompts/code-review.txt}"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
該路徑是相對於配置文件所在位置的。所以這適用於
|
||||
全局开放代码配置和项目特定配置。
|
||||
|
||||
---
|
||||
|
||||
### 工具
|
||||
|
||||
使用 `tools` 配置控制模式下可用的工具。您可以通过将特定工具设置为 `true` 或 `false` 来启用或禁用特定工具。
|
||||
|
||||
```json
|
||||
{
|
||||
"mode": {
|
||||
"readonly": {
|
||||
"tools": {
|
||||
"write": false,
|
||||
"edit": false,
|
||||
"bash": false,
|
||||
"read": true,
|
||||
"grep": true,
|
||||
"glob": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
如果未指定任何工具,則默認啟用所有工具。
|
||||
|
||||
---
|
||||
|
||||
#### 可用工具
|
||||
|
||||
這裡是所有可以通過模式配置控制的工具。
|
||||
|
||||
|工具|描述 |
|
||||
| ----------- | ----------------------- |
|
||||
| `bash` | 执行shell命令 |
|
||||
| `edit` | 修改现有文件 |
|
||||
| `write` |创建新文件 |
|
||||
| `read` | 读取文件内容 |
|
||||
| `grep` |搜索文件内容 |
|
||||
| `glob` |按模式查找文件 |
|
||||
| `list` | 上市目录内容 |
|
||||
| `patch` |对文件应用补丁 |
|
||||
| `todowrite` | 管理待办事项列表 |
|
||||
| `todoread` |阅读待办事项列表 |
|
||||
| `webfetch` |获取网页内容 |
|
||||
|
||||
---
|
||||
|
||||
## 自定義模式
|
||||
|
||||
您可以通過將自定義模式添加到配置來創建自己的自定義模式。以下是使用這兩種方法的示例:
|
||||
|
||||
### 使用 JSON 配置
|
||||
|
||||
```json title="opencode.json" {4-14}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"mode": {
|
||||
"docs": {
|
||||
"prompt": "{file:./prompts/documentation.txt}",
|
||||
"tools": {
|
||||
"write": true,
|
||||
"edit": true,
|
||||
"bash": false,
|
||||
"read": true,
|
||||
"grep": true,
|
||||
"glob": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 使用 Markdown 文件
|
||||
|
||||
在`.opencode/modes/`中为项目特定模式创建模式文件,在`~/.config/opencode/modes/`中为全局模式创建模式文件:
|
||||
|
||||
```markdown title=".opencode/modes/debug.md"
|
||||
---
|
||||
temperature: 0.1
|
||||
tools:
|
||||
bash: true
|
||||
read: true
|
||||
grep: true
|
||||
write: false
|
||||
edit: false
|
||||
---
|
||||
|
||||
You are in debug mode. Your primary goal is to help investigate and diagnose issues.
|
||||
|
||||
Focus on:
|
||||
|
||||
- Understanding the problem through careful analysis
|
||||
- Using bash commands to inspect system state
|
||||
- Reading relevant files and logs
|
||||
- Searching for patterns and anomalies
|
||||
- Providing clear explanations of findings
|
||||
|
||||
Do not make any changes to files. Only investigate and report.
|
||||
```
|
||||
|
||||
```markdown title="~/.config/opencode/modes/refactor.md"
|
||||
---
|
||||
model: anthropic/claude-sonnet-4-20250514
|
||||
temperature: 0.2
|
||||
tools:
|
||||
edit: true
|
||||
read: true
|
||||
grep: true
|
||||
glob: true
|
||||
---
|
||||
|
||||
You are in refactoring mode. Focus on improving code quality without changing functionality.
|
||||
|
||||
Priorities:
|
||||
|
||||
- Improve code readability and maintainability
|
||||
- Apply consistent naming conventions
|
||||
- Reduce code duplication
|
||||
- Optimize performance where appropriate
|
||||
- Ensure all tests continue to pass
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 使用案例
|
||||
|
||||
以下是不同模式的一些常見用例。
|
||||
|
||||
- **構建模式**:啟用所有工具的完整開發工作
|
||||
- **計劃模式**:分析和計劃,無需更改
|
||||
- **審閱模式**:使用只讀訪問權限和文檔工具進行代碼審閱
|
||||
- **调试模式**:专注于启用bash和读取工具的调查
|
||||
- **文檔模式**:使用文件操作但不使用系統命令的文檔編寫
|
||||
|
||||
您可能還會發現不同的模型適用於不同的用例。
|
||||
57
packages/web/src/content/docs/zh-cn/network.mdx
Normal file
57
packages/web/src/content/docs/zh-cn/network.mdx
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
title: 網絡
|
||||
description: 配置代理和自定義證書。
|
||||
---
|
||||
|
||||
OpenCode支持企业网络环境的标准代理环境变量和自定义证书。
|
||||
|
||||
---
|
||||
|
||||
## 代理人
|
||||
|
||||
OpenCode 尊重标准代理环境变量。
|
||||
|
||||
```bash
|
||||
# HTTPS proxy (recommended)
|
||||
export HTTPS_PROXY=https://proxy.example.com:8080
|
||||
|
||||
# HTTP proxy (if HTTPS not available)
|
||||
export HTTP_PROXY=http://proxy.example.com:8080
|
||||
|
||||
# Bypass proxy for local server (required)
|
||||
export NO_PROXY=localhost,127.0.0.1
|
||||
```
|
||||
|
||||
:::警告
|
||||
TUI 与本地 HTTP 服务器通信。您必须绕过此连接的代理以防止路由循环。
|
||||
:::
|
||||
|
||||
您可以使用[CLI 标志](/docs/cli#run)配置服务器的端口和主机名。
|
||||
|
||||
---
|
||||
|
||||
### 認證
|
||||
|
||||
如果您的代理需要基本身份验证,请在 URL 中包含凭据。
|
||||
|
||||
```bash
|
||||
export HTTPS_PROXY=http://username:password@proxy.example.com:8080
|
||||
```
|
||||
|
||||
:::警告
|
||||
避免對密碼進行硬編碼。使用環境變量或安全憑證存儲。
|
||||
:::
|
||||
|
||||
对于需要高级身份验证(例如 NTLM 或 Kerberos)的代理,请考虑使用支持您的身份验证方法的 LLM 网关。
|
||||
|
||||
---
|
||||
|
||||
## 定制證書
|
||||
|
||||
如果您的企业使用自定义 CA 进行 HTTPS 连接,请配置 OpenCode 以信任它们。
|
||||
|
||||
```bash
|
||||
export NODE_EXTRA_CA_CERTS=/path/to/ca-cert.pem
|
||||
```
|
||||
|
||||
这适用于代理连接和直接 API 访问。
|
||||
237
packages/web/src/content/docs/zh-cn/permissions.mdx
Normal file
237
packages/web/src/content/docs/zh-cn/permissions.mdx
Normal file
@@ -0,0 +1,237 @@
|
||||
---
|
||||
title: 權限
|
||||
description: 控制哪些操作需要批准才能運行。
|
||||
---
|
||||
|
||||
OpenCode 使用`permission` 配置来决定给定的操作是否应自动运行、提示您或被阻止。
|
||||
|
||||
从 `v1.1.1` 开始,旧版配置 `tools` 布尔已被废弃,并已合并到 `permission` 中。仍支持旧版的 `tools` 配置以实现平滑兼容。
|
||||
|
||||
---
|
||||
|
||||
## 行動
|
||||
|
||||
每個權限規則解析為以下之一:
|
||||
|
||||
- `"allow"` — 尚未批准运行
|
||||
- `"ask"` — 提示批准
|
||||
- `"deny"` — 阻止该操作
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以全局設置權限(使用`*`),並覆蓋特定工具。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"*": "ask",
|
||||
"bash": "allow",
|
||||
"edit": "deny"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您還可以一次設置所有權限:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": "allow"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 粒度規則(對象語法)
|
||||
|
||||
對於大多數權限,您可以使用對像根據工具輸入應用不同的操作。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"bash": {
|
||||
"*": "ask",
|
||||
"git *": "allow",
|
||||
"npm *": "allow",
|
||||
"rm *": "deny",
|
||||
"grep *": "allow"
|
||||
},
|
||||
"edit": {
|
||||
"*": "deny",
|
||||
"packages/web/src/content/docs/*.mdx": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
規則通過模式匹配進行評估,**最後匹配的規則獲勝**。常見的模式是將包羅萬象的 `"*"` 規則放在前面,然後再放置更具體的規則。
|
||||
|
||||
### 通配符
|
||||
|
||||
權限模式使用簡單的通配符匹配:
|
||||
|
||||
- `*` 匹配零個或多個任意字符
|
||||
- `?` 恰好匹配一個字符
|
||||
- 所有其他字符均按字面意思匹配
|
||||
|
||||
### 主目錄擴展
|
||||
|
||||
您可以在模式目录中使用 `~` 或 `$HOME` 来引用您的主目录。这对于 [`external_directory`](#external-directories) 规则特别有用。
|
||||
|
||||
- `~/projects/*` -> `/Users/username/projects/*`
|
||||
- `$HOME/projects/*` -> `/Users/username/projects/*`
|
||||
- `~` -> `/Users/username`
|
||||
|
||||
### 外部目錄
|
||||
|
||||
使用 `external_directory` 允许工具调用启动 OpenCode 的工作目录之外的路径。这适用于任何采用路径作为输入的工具(例如 `read`、`edit`、`list`、`glob`、`grep` 和许多Z`bash` 命令)。
|
||||
|
||||
主扩展(如`~/...`)仅影响模式的编写方式。它不会使外部路径成为当前工作空间的一部分,因此仍然必须通过 `external_directory` 允许工作目录之外的路径。
|
||||
|
||||
例如,这允许访问`~/projects/personal/`下的所有内容:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"external_directory": {
|
||||
"~/projects/personal/**": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
这里允许的任何目录都会继承与当前工作空间默认相同的值。自[`read`默认为`allow`](#defaults)起,也允许读取`external_directory`下面的边界,除非被覆盖。当工具应在这些路径中时添加显式规则,例如在保留读取的同时阻止编辑:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"external_directory": {
|
||||
"~/projects/personal/**": "allow"
|
||||
},
|
||||
"edit": {
|
||||
"~/projects/personal/**": "deny"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
将列表重点放在受信任的路径上,并根据其他工具的需要分层额外的允许或拒绝规则(例如`bash`)。
|
||||
|
||||
---
|
||||
|
||||
## 可用權限
|
||||
|
||||
OpenCode权限由工具名称和一些安全防护措施决定:
|
||||
|
||||
- `read` — 读取文件(与文件路径匹配)
|
||||
- `edit` — 所有文件修改(头部`edit`、`write`、`patch`、`multiedit`)
|
||||
- `glob` — 文件通配符(匹配通配符模式)
|
||||
- `grep` — 内容搜索(匹配正则表达式模式)
|
||||
- `list` — 上市目录中的文件(与目录路径匹配)
|
||||
- `bash` — 运行 shell 命令(匹配 `git status --porcelain` 等解析命令)
|
||||
- `task` — 启动子代理(与子代理类型匹配)
|
||||
- `skill` — 加载技能(与技能名称匹配)
|
||||
- `lsp` — 运行 LSP 查询(当前非粒度)
|
||||
- `todoread`、`todowrite` — 讀取/更新待辦事項列表
|
||||
- `webfetch` — 获取 URL(与 URL 匹配)
|
||||
- `websearch`、`codesearch` — 網頁/代碼搜索(与查询匹配)
|
||||
- `external_directory` — 当工具访问项目工作目录外部的路径时触发
|
||||
- `doom_loop` — 当相同的工具调用相同的输入重复 3 次时触发
|
||||
|
||||
---
|
||||
|
||||
## 預設值
|
||||
|
||||
如果您未指定任何内容,OpenCode分散许可的默认值开始:
|
||||
|
||||
- 大部分权限默认为`"allow"`。
|
||||
- `doom_loop`和`external_directory`默认为`"ask"`。
|
||||
- `read` 是 `"allow"`,但 `.env` 文件默认被拒绝:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"permission": {
|
||||
"read": {
|
||||
"*": "allow",
|
||||
"*.env": "deny",
|
||||
"*.env.*": "deny",
|
||||
"*.env.example": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## “問”的作用是什麼
|
||||
|
||||
当 OpenCode 提示批准时,UI 会提供清晰的结果:
|
||||
|
||||
- `once` — 仅批准此请求
|
||||
- `always` — 批准与建议模式匹配的未来请求(对于当前 OpenCode 会话的其余部分)
|
||||
- `reject` — 拒绝请求
|
||||
|
||||
`always` 将批准的模式集由该工具提供(例如,bash 批准通常将安全端口(如 `git status*`)列入白名单)。
|
||||
|
||||
---
|
||||
|
||||
## 代理商
|
||||
|
||||
您可以覆盖每个代理的权限。代理权限与全局配置合并,代理规则优先。 [了解更多](/docs/agents#permissions)关于代理权限。
|
||||
|
||||
:::笔记
|
||||
有关更详细的模式匹配示例,请参见上面的 [粒度规则(对象语法)](#granular-rules-object-syntax) 部分。
|
||||
:::
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"bash": {
|
||||
"*": "ask",
|
||||
"git *": "allow",
|
||||
"git commit *": "deny",
|
||||
"git push *": "deny",
|
||||
"grep *": "allow"
|
||||
}
|
||||
},
|
||||
"agent": {
|
||||
"build": {
|
||||
"permission": {
|
||||
"bash": {
|
||||
"*": "ask",
|
||||
"git *": "allow",
|
||||
"git commit *": "ask",
|
||||
"git push *": "deny",
|
||||
"grep *": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您还可以在 Markdown 中配置代理权限:
|
||||
|
||||
```markdown title="~/.config/opencode/agents/review.md"
|
||||
---
|
||||
description: Code review without edits
|
||||
mode: subagent
|
||||
permission:
|
||||
edit: deny
|
||||
bash: ask
|
||||
webfetch: deny
|
||||
---
|
||||
|
||||
Only analyze code and suggest changes.
|
||||
```
|
||||
|
||||
:::提示
|
||||
对参数的命令使用模式匹配。 `"grep *"` 允许 `grep pattern file.txt`,而 `"grep"` 单独会阻止它。像 `git status` 这样的命令适用于默认行为,但在传递参数时需要显式许可(如 `"git status *"`)。
|
||||
:::
|
||||
385
packages/web/src/content/docs/zh-cn/plugins.mdx
Normal file
385
packages/web/src/content/docs/zh-cn/plugins.mdx
Normal file
@@ -0,0 +1,385 @@
|
||||
---
|
||||
title: 插件
|
||||
description: 编写您自己的插件来扩展 OpenCode。
|
||||
---
|
||||
|
||||
插件允许您通过挂钩各种事件和自定义行为来扩展 OpenCode。您可以创建插件来添加新功能、与外部服务集成或修改 OpenCode 的默认行为。
|
||||
|
||||
例如,查看社区创建的[插件](/docs/ecosystem#plugins)。
|
||||
|
||||
---
|
||||
|
||||
## 使用插件
|
||||
|
||||
有兩種加載插件的方法。
|
||||
|
||||
---
|
||||
|
||||
### 從本地文件
|
||||
|
||||
将 JavaScript 或 TypeScript 文件放置在插件目录中。
|
||||
|
||||
- `.opencode/plugins/` - 项目级插件
|
||||
- `~/.config/opencode/plugins/` - 全局插件
|
||||
|
||||
這些目錄中的文件會在啟動時自動加載。
|
||||
|
||||
---
|
||||
|
||||
### 来自 npm
|
||||
|
||||
在配置文件中指定 npm 包。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"plugin": ["opencode-helicone-session", "opencode-wakatime", "@my-org/custom-plugin"]
|
||||
}
|
||||
```
|
||||
|
||||
支持常规和范围的 npm 包。
|
||||
|
||||
浏览[生态系统](/docs/ecosystem#plugins)中的可用插件。
|
||||
|
||||
---
|
||||
|
||||
### 插件是如何安裝的
|
||||
|
||||
**npm 插件** 在启动时使用 Bun 自动安装。包及其依赖项缓存在 `~/.cache/opencode/node_modules/` 中。
|
||||
|
||||
**本地插件**直接从插件目录加载。要使用外部包,您必须在配置目录中创建`package.json`(请参阅[依赖关系](#dependencies)),或将插件发布到npm和[将其添加到您的配置中](/docs/config#plugins)。
|
||||
|
||||
---
|
||||
|
||||
### 加載順序
|
||||
|
||||
插件從所有源加載,所有掛鉤按順序運行。加載順序為:
|
||||
|
||||
1. 全局配置 (`~/.config/opencode/opencode.json`)
|
||||
2. 项目配置(`opencode.json`)
|
||||
3. 插件全局目录 (`~/.config/opencode/plugins/`)
|
||||
4. 项目插件目录(`.opencode/plugins/`)
|
||||
|
||||
具有相同的名称和版本,但是重复的 npm 包将被加载一次。,本地插件和名称相似的 npm 插件都是分开加载的。
|
||||
|
||||
---
|
||||
|
||||
## 創建一個插件
|
||||
|
||||
插件是一个 **JavaScript/TypeScript 模块多个**,它导出一个或插件
|
||||
功能。每個函數接收一個上下文對象並返回一個鉤子對象。
|
||||
|
||||
---
|
||||
|
||||
### 依賴關係
|
||||
|
||||
本地插件和自定义工具可以使用外部 npm 包。将 `package.json` 添加到您的配置目录,其中包含您需要的依赖项。
|
||||
|
||||
```json title=".opencode/package.json"
|
||||
{
|
||||
"dependencies": {
|
||||
"shescape": "^2.1.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
OpenCode 在启动时运行 `bun install` 来安装这些。然后你的插件和工具就可以导入它们了。
|
||||
|
||||
```ts title=".opencode/plugins/my-plugin.ts"
|
||||
import { escape } from "shescape"
|
||||
|
||||
export const MyPlugin = async (ctx) => {
|
||||
return {
|
||||
"tool.execute.before": async (input, output) => {
|
||||
if (input.tool === "bash") {
|
||||
output.args.command = escape(output.args.command)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 基本結構
|
||||
|
||||
```js title=".opencode/plugins/example.js"
|
||||
export const MyPlugin = async ({ project, client, $, directory, worktree }) => {
|
||||
console.log("Plugin initialized!")
|
||||
|
||||
return {
|
||||
// Hook implementations go here
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
插件函數接收:
|
||||
|
||||
- `project`:当前项目信息。
|
||||
- `directory`:当前工作目录。
|
||||
- `worktree`:git 工作树路径。
|
||||
- `client`:用于与AI交互的开放代码SDK客户端。
|
||||
- `$`:Bun的[外壳API](https://bun.com/docs/runtime/shell)用于执行命令。
|
||||
|
||||
---
|
||||
|
||||
### TypeScript 支持
|
||||
|
||||
对于 TypeScript 插件,您可以从插件包中导入类型:
|
||||
|
||||
```ts title="my-plugin.ts" {1}
|
||||
import type { Plugin } from "@opencode-ai/plugin"
|
||||
|
||||
export const MyPlugin: Plugin = async ({ project, client, $, directory, worktree }) => {
|
||||
return {
|
||||
// Type-safe hook implementations
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 活動
|
||||
|
||||
插件可以訂閱事件,如下面的示例部分所示。以下是可用的不同事件的列表。
|
||||
|
||||
#### 命令事件
|
||||
|
||||
- `command.executed`
|
||||
|
||||
#### 文件事件
|
||||
|
||||
- `file.edited`
|
||||
- `file.watcher.updated`
|
||||
|
||||
#### 安裝活動
|
||||
|
||||
- `installation.updated`
|
||||
|
||||
#### LSP活动
|
||||
|
||||
- `lsp.client.diagnostics`
|
||||
- `lsp.updated`
|
||||
|
||||
#### 消息事件
|
||||
|
||||
- `message.part.removed`
|
||||
- `message.part.updated`
|
||||
- `message.removed`
|
||||
- `message.updated`
|
||||
|
||||
#### 權限事件
|
||||
|
||||
- `permission.asked`
|
||||
- `permission.replied`
|
||||
|
||||
#### 服務器事件
|
||||
|
||||
- `server.connected`
|
||||
|
||||
#### 會議活動
|
||||
|
||||
- `session.created`
|
||||
- `session.compacted`
|
||||
- `session.deleted`
|
||||
- `session.diff`
|
||||
- `session.error`
|
||||
- `session.idle`
|
||||
- `session.status`
|
||||
- `session.updated`
|
||||
|
||||
#### 都都活動
|
||||
|
||||
- `todo.updated`
|
||||
|
||||
#### 殼牌活動
|
||||
|
||||
- `shell.env`
|
||||
|
||||
#### 工具事件
|
||||
|
||||
- `tool.execute.after`
|
||||
- `tool.execute.before`
|
||||
|
||||
#### 途易活動
|
||||
|
||||
- `tui.prompt.append`
|
||||
- `tui.command.execute`
|
||||
- `tui.toast.show`
|
||||
|
||||
---
|
||||
|
||||
## 示例
|
||||
|
||||
以下是一些可用于扩展 opencode 的插件示例。
|
||||
|
||||
---
|
||||
|
||||
### 發送通知
|
||||
|
||||
當某些事件發生時發送通知:
|
||||
|
||||
```js title=".opencode/plugins/notification.js"
|
||||
export const NotificationPlugin = async ({ project, client, $, directory, worktree }) => {
|
||||
return {
|
||||
event: async ({ event }) => {
|
||||
// Send notification on session completion
|
||||
if (event.type === "session.idle") {
|
||||
await $`osascript -e 'display notification "Session completed!" with title "opencode"'`
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
我们在 macOS 上使用 `osascript` AppleScript。这里我们用它运行来发送通知。
|
||||
|
||||
:::笔记
|
||||
如果您使用 OpenCode 桌面应用程序,它可以在响应准备就绪或会话错误时自动发送系统通知。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### .env 保护
|
||||
|
||||
阻止opencode读取`.env`文件:
|
||||
|
||||
```javascript title=".opencode/plugins/env-protection.js"
|
||||
export const EnvProtection = async ({ project, client, $, directory, worktree }) => {
|
||||
return {
|
||||
"tool.execute.before": async (input, output) => {
|
||||
if (input.tool === "read" && output.args.filePath.includes(".env")) {
|
||||
throw new Error("Do not read .env files")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 注入環境變量
|
||||
|
||||
将环境变量注入所有shell执行(AI工具和用户终端):
|
||||
|
||||
```javascript title=".opencode/plugins/inject-env.js"
|
||||
export const InjectEnvPlugin = async () => {
|
||||
return {
|
||||
"shell.env": async (input, output) => {
|
||||
output.env.MY_API_KEY = "secret"
|
||||
output.env.PROJECT_ROOT = input.cwd
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 定制工具
|
||||
|
||||
插件还可以向 opencode 添加自定义工具:
|
||||
|
||||
```ts title=".opencode/plugins/custom-tools.ts"
|
||||
import { type Plugin, tool } from "@opencode-ai/plugin"
|
||||
|
||||
export const CustomToolsPlugin: Plugin = async (ctx) => {
|
||||
return {
|
||||
tool: {
|
||||
mytool: tool({
|
||||
description: "This is a custom tool",
|
||||
args: {
|
||||
foo: tool.schema.string(),
|
||||
},
|
||||
async execute(args, context) {
|
||||
const { directory, worktree } = context
|
||||
return `Hello ${args.foo} from ${directory} (worktree: ${worktree})`
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`tool` 帮助器创建一个可以调用的自定义工具的开放代码。它采用 Zod 模式函数并返回一个工具定义:
|
||||
|
||||
- `description`:该工具的作用
|
||||
- `args`:Zod 模式的工具参数
|
||||
- `execute`:调用工具时运行的函数
|
||||
|
||||
您的自定義工具將可與內置工具一起用於開放代碼。
|
||||
|
||||
---
|
||||
|
||||
### 記錄
|
||||
|
||||
使用 `client.app.log()` 而不是 `console.log` 进行成型日志记录:
|
||||
|
||||
```ts title=".opencode/plugins/my-plugin.ts"
|
||||
export const MyPlugin = async ({ client }) => {
|
||||
await client.app.log({
|
||||
body: {
|
||||
service: "my-plugin",
|
||||
level: "info",
|
||||
message: "Plugin initialized",
|
||||
extra: { foo: "bar" },
|
||||
},
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
级别:`debug`、`info`、`warn`、`error`。详情请参见【SDK文档](https://opencode.ai/docs/sdk)。
|
||||
|
||||
---
|
||||
|
||||
### 壓實鉤
|
||||
|
||||
自定義壓縮會話時包含的上下文:
|
||||
|
||||
```ts title=".opencode/plugins/compaction.ts"
|
||||
import type { Plugin } from "@opencode-ai/plugin"
|
||||
|
||||
export const CompactionPlugin: Plugin = async (ctx) => {
|
||||
return {
|
||||
"experimental.session.compacting": async (input, output) => {
|
||||
// Inject additional context into the compaction prompt
|
||||
output.context.push(`
|
||||
## Custom Context
|
||||
|
||||
Include any state that should persist across compaction:
|
||||
- Current task status
|
||||
- Important decisions made
|
||||
- Files being actively worked on
|
||||
`)
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`experimental.session.compacting`钩子在LLM生成驱动机之前触发。使用它来填充默认压缩提示会丢失的特定于域的上下文。
|
||||
|
||||
您还可以通过设置`output.prompt`来完全替换压缩提示:
|
||||
|
||||
```ts title=".opencode/plugins/custom-compaction.ts"
|
||||
import type { Plugin } from "@opencode-ai/plugin"
|
||||
|
||||
export const CustomCompactionPlugin: Plugin = async (ctx) => {
|
||||
return {
|
||||
"experimental.session.compacting": async (input, output) => {
|
||||
// Replace the entire compaction prompt
|
||||
output.prompt = `
|
||||
You are generating a continuation prompt for a multi-agent swarm session.
|
||||
|
||||
Summarize:
|
||||
1. The current task and its status
|
||||
2. Which files are being modified and by whom
|
||||
3. Any blockers or dependencies between agents
|
||||
4. The next steps to complete the work
|
||||
|
||||
Format as a structured prompt that a new agent can use to resume work.
|
||||
`
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
当设置`output.prompt`时,它会取代完全默认的压缩提示。在这种情况下,`output.context` 内存将被忽略。
|
||||
1889
packages/web/src/content/docs/zh-cn/providers.mdx
Normal file
1889
packages/web/src/content/docs/zh-cn/providers.mdx
Normal file
File diff suppressed because it is too large
Load Diff
180
packages/web/src/content/docs/zh-cn/rules.mdx
Normal file
180
packages/web/src/content/docs/zh-cn/rules.mdx
Normal file
@@ -0,0 +1,180 @@
|
||||
---
|
||||
title: 規則
|
||||
description: 設置開放代碼的自定義指令。
|
||||
---
|
||||
|
||||
您可以通过 `AGENTS.md` 文件创建 opencode 的自定义指令。这和 Cursor 的规则类似。它包含将包含在 LLM 上下文中的说明,方便您的特定项目自定义其行为。
|
||||
|
||||
---
|
||||
|
||||
## 初始化
|
||||
|
||||
要创建新的`AGENTS.md`文件,您可以在opencode中运行`/init`命令。
|
||||
|
||||
:::提示
|
||||
您应该将项目的 `AGENTS.md` 文件提交到 Git。
|
||||
:::
|
||||
|
||||
这将扫描您的项目及其所有内容,以了解该项目的内容并生成一个 `AGENTS.md` 文件。这有助于更好地打开代码导航项目。
|
||||
|
||||
如果您已有现有的 `AGENTS.md` 文件,将尝试添加到其中。
|
||||
|
||||
---
|
||||
|
||||
## 例子
|
||||
|
||||
您也可以手动创建此文件。以下是您可以导入 `AGENTS.md` 文件中的一些内容的示例。
|
||||
|
||||
```markdown title="AGENTS.md"
|
||||
# SST v3 Monorepo Project
|
||||
|
||||
This is an SST v3 monorepo with TypeScript. The project uses bun workspaces for package management.
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `packages/` - Contains all workspace packages (functions, core, web, etc.)
|
||||
- `infra/` - Infrastructure definitions split by service (storage.ts, api.ts, web.ts)
|
||||
- `sst.config.ts` - Main SST configuration with dynamic imports
|
||||
|
||||
## Code Standards
|
||||
|
||||
- Use TypeScript with strict mode enabled
|
||||
- Shared code goes in `packages/core/` with proper exports configuration
|
||||
- Functions go in `packages/functions/`
|
||||
- Infrastructure should be split into logical files in `infra/`
|
||||
|
||||
## Monorepo Conventions
|
||||
|
||||
- Import shared modules using workspace names: `@my-app/core/example`
|
||||
```
|
||||
|
||||
我們在此處添加特定於項目的說明,這將在您的團隊中共享。
|
||||
|
||||
---
|
||||
|
||||
## 類型
|
||||
|
||||
opencode 还支持从多个位置读取 `AGENTS.md` 文件。这有不同的目的。
|
||||
|
||||
### 專案
|
||||
|
||||
将 `AGENTS.md` 放置在项目根目录中以获取特定于项目的规则。这些仅适用于您在此目录或子目录中工作时。
|
||||
|
||||
### 全球的
|
||||
|
||||
您还可以在 `~/.config/opencode/AGENTS.md` 文件中包含全局规则。这适用于所有开放代码会话。
|
||||
|
||||
由于此未提交给 Git 或与您的团队共享,因此我们建议使用它来指定 LLM 应遵循的任何个人规则。
|
||||
|
||||
### 克勞德代碼兼容性
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
- **项目规则**:项目目录中的`CLAUDE.md`(如果`AGENTS.md`不存在则使用)
|
||||
- **全局规则**:`~/.claude/CLAUDE.md`(如果不存在`~/.config/opencode/AGENTS.md`则使用)
|
||||
- **技能**:`~/.claude/skills/` — 详情请参见[代理技巧](/docs/skills/)
|
||||
|
||||
要取消Claude Code兼容性,请设置以下环境变量之一:
|
||||
|
||||
```bash
|
||||
export OPENCODE_DISABLE_CLAUDE_CODE=1 # Disable all .claude support
|
||||
export OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1 # Disable only ~/.claude/CLAUDE.md
|
||||
export OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1 # Disable only .claude/skills
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 優先級
|
||||
|
||||
当opencode启动时,它会按以下顺序查找规则文件:
|
||||
|
||||
1. **本地文件**,从当前目录向上浏览(`AGENTS.md`,`CLAUDE.md`)
|
||||
2. **全局文件** `~/.config/opencode/AGENTS.md`
|
||||
3. **克劳德代码文件**位于`~/.claude/CLAUDE.md`(禁用禁用)
|
||||
|
||||
第一个匹配的文件每个在类别中触发。例如,如果您同时拥有`AGENTS.md`和`CLAUDE.md`,则仅使用`AGENTS.md`。同样,`~/.config/opencode/AGENTS.md`优先于`~/.claude/CLAUDE.md`。
|
||||
|
||||
---
|
||||
|
||||
## 定制說明
|
||||
|
||||
您可以在 `opencode.json` 或全局 `~/.config/opencode/opencode.json` 中指定自定义指令文件。这允许您和您的团队重用现有规则,而不必将它们复制到 AGENTS.md。
|
||||
|
||||
例子:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
|
||||
}
|
||||
```
|
||||
|
||||
您还可以使用远程URL从Web加载说明。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"instructions": ["https://raw.githubusercontent.com/my-org/shared-rules/main/style.md"]
|
||||
}
|
||||
```
|
||||
|
||||
遠程指令的獲取有 5 秒的超時時間。
|
||||
|
||||
所有说明文件均与您的`AGENTS.md`文件合并。
|
||||
|
||||
---
|
||||
|
||||
## 引用外部文件
|
||||
|
||||
虽然opencode不会自动解析`AGENTS.md`中的文件引用,但您可以通过两种方式实现类似的功能:
|
||||
|
||||
### 使用 opencode.json
|
||||
|
||||
推荐的方法是在`opencode.json`中使用`instructions`字段:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"instructions": ["docs/development-standards.md", "test/testing-guidelines.md", "packages/*/AGENTS.md"]
|
||||
}
|
||||
```
|
||||
|
||||
### AGENTS.md 中的手册说明
|
||||
|
||||
您可以通过在 `AGENTS.md` 中明确提供的指令来教 opencode 读取外部文件。这是一个实际的示例:
|
||||
|
||||
```markdown title="AGENTS.md"
|
||||
# TypeScript Project Rules
|
||||
|
||||
## External File Loading
|
||||
|
||||
CRITICAL: When you encounter a file reference (e.g., @rules/general.md), use your Read tool to load it on a need-to-know basis. They're relevant to the SPECIFIC task at hand.
|
||||
|
||||
Instructions:
|
||||
|
||||
- Do NOT preemptively load all references - use lazy loading based on actual need
|
||||
- When loaded, treat content as mandatory instructions that override defaults
|
||||
- Follow references recursively when needed
|
||||
|
||||
## Development Guidelines
|
||||
|
||||
For TypeScript code style and best practices: @docs/typescript-guidelines.md
|
||||
For React component architecture and hooks patterns: @docs/react-patterns.md
|
||||
For REST API design and error handling: @docs/api-standards.md
|
||||
For testing strategies and coverage requirements: @test/testing-guidelines.md
|
||||
|
||||
## General Guidelines
|
||||
|
||||
Read the following file immediately as it's relevant to all workflows: @rules/general-guidelines.md.
|
||||
```
|
||||
|
||||
這種方法允許您:
|
||||
|
||||
- 創建模塊化、可重用的規則文件
|
||||
- 通过符号链接或git子模块在项目之间共享规则
|
||||
- 保持 AGENTS.md 简洁,同时参考详细指南
|
||||
- 确保opencode仅在特定任务需要时加载文件
|
||||
|
||||
:::提示
|
||||
对于 monorepos 或具有共享标准的项目,使用 `opencode.json` 和 glob 模式(如 `packages/*/AGENTS.md`)比手动指令更易于维护。
|
||||
:::
|
||||
391
packages/web/src/content/docs/zh-cn/sdk.mdx
Normal file
391
packages/web/src/content/docs/zh-cn/sdk.mdx
Normal file
@@ -0,0 +1,391 @@
|
||||
---
|
||||
title: 軟體開發工具包
|
||||
description: opencode 服务器的类型不同于安全 JS 客户端。
|
||||
---
|
||||
|
||||
import config from "../../../../config.mjs"
|
||||
export const typesUrl = `${config.github}/blob/dev/packages/sdk/js/src/gen/types.gen.ts`
|
||||
|
||||
opencode JS/TS SDK 提供类型其他安全的客户端用于与服务器交互。
|
||||
使用它以程序设计方式构建集成和控制开放代码。
|
||||
|
||||
[了解更多关于服务器如何工作的](/docs/server)。例如,检视社区构建的[projects](/docs/ecosystem#projects)。
|
||||
|
||||
---
|
||||
|
||||
## 安裝
|
||||
|
||||
从npm安装SDK:
|
||||
|
||||
```bash
|
||||
npm install @opencode-ai/sdk
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 建立客戶端
|
||||
|
||||
创建opencode的示例项:
|
||||
|
||||
```javascript
|
||||
import { createOpencode } from "@opencode-ai/sdk"
|
||||
|
||||
const { client } = await createOpencode()
|
||||
```
|
||||
|
||||
這會同時啟動伺服器和客戶端
|
||||
|
||||
#### 選項
|
||||
|
||||
|選項|型別 |描述 |預設|
|
||||
| ---------- | ------------- | ------------------------------ | ----------- |
|
||||
| `hostname` | `string` | 服务器主机名 | `127.0.0.1` |
|
||||
| `port` | `number` |伺服器埠 | `4096` |
|
||||
| `signal` | `AbortSignal` | 取消的中止讯号 | `undefined` |
|
||||
| `timeout` | `number` | 服务器启动超时(以毫秒为单位)| `5000` |
|
||||
| `config` | `Config` |放置的财产 | `{}` |
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
You can pass a configuration object to customize behavior. The instance still picks up your `opencode.json`, but you can override or add configuration inline:
|
||||
|
||||
```javascript
|
||||
import { createOpencode } from "@opencode-ai/sdk"
|
||||
|
||||
const opencode = await createOpencode({
|
||||
hostname: "127.0.0.1",
|
||||
port: 4096,
|
||||
config: {
|
||||
model: "anthropic/claude-3-5-sonnet-20241022",
|
||||
},
|
||||
})
|
||||
|
||||
console.log(`Server running at ${opencode.server.url}`)
|
||||
|
||||
opencode.server.close()
|
||||
```
|
||||
|
||||
## 僅限客戶
|
||||
|
||||
如果您已经有 opencode 的正在执行示例项,则可以创建一个客户端示例项来连线到它:
|
||||
|
||||
```javascript
|
||||
import { createOpencodeClient } from "@opencode-ai/sdk"
|
||||
|
||||
const client = createOpencodeClient({
|
||||
baseUrl: "http://localhost:4096",
|
||||
})
|
||||
```
|
||||
|
||||
#### 選項
|
||||
|
||||
|選項|型別 |描述 |預設 |
|
||||
| --------------- | ---------- | -------------------------------- | ----------------------- |
|
||||
| `baseUrl` | `string` |伺服器的 URL | `http://localhost:4096` |
|
||||
| `fetch` | `function` |习俗获取实现| `globalThis.fetch` |
|
||||
| `parseAs` | `string` |响应解析方法| `auto` |
|
||||
| `responseStyle` | `string` | 返回样式:`data` 或 `fields` | `fields` |
|
||||
| `throwOnError` | `boolean` | 掷骰错误而不是返回 | `false` |
|
||||
|
||||
---
|
||||
|
||||
## 型別
|
||||
|
||||
SDK 包括所有 API 型以外的 TypeScript 定义。直接汇入其中:
|
||||
|
||||
```typescript
|
||||
import type { Session, Message, Part } from "@opencode-ai/sdk"
|
||||
```
|
||||
|
||||
所有型別均根據伺服器的 OpenAPI 規範生成,並可在 <a href={typesUrl}> 型別檔案 </a> 中找到。
|
||||
|
||||
---
|
||||
|
||||
## 錯誤
|
||||
|
||||
SDK 可能会丢掷错误,您可以捕获并处理这些错误:
|
||||
|
||||
```typescript
|
||||
try {
|
||||
await client.session.get({ path: { id: "invalid-id" } })
|
||||
} catch (error) {
|
||||
console.error("Failed to get session:", (error as Error).message)
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 蜜蜂
|
||||
|
||||
SDK跨越型别安全客户端公开所有服务器API。
|
||||
|
||||
---
|
||||
|
||||
### 全球的
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ----------------- | ------------------------------- | ------------------------------------ |
|
||||
| `global.health()` |检查服务器健康状况和版本 | `{ healthy: true, version: string }` |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
const health = await client.global.health()
|
||||
console.log(health.data.version)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 應用程式
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| -------------- | ------------------------- | ------------------------------------------- |
|
||||
| `app.log()` | 登录日志 | `boolean` |
|
||||
| `app.agents()` |列出所有可用的代理 | <a href={typesUrl}><code>代理[]</code></a> |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Write a log entry
|
||||
await client.app.log({
|
||||
body: {
|
||||
service: "my-app",
|
||||
level: "info",
|
||||
message: "Operation completed",
|
||||
},
|
||||
})
|
||||
|
||||
// List available agents
|
||||
const agents = await client.app.agents()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 專案
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------------- | ------------------- | --------------------------------------------- |
|
||||
| `project.list()` |列出所有專案 | <a href={typesUrl}><code>專案[]</code></a> |
|
||||
| `project.current()` |獲取當前專案 | <a href={typesUrl}><code>專案</code></a> |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// List all projects
|
||||
const projects = await client.project.list()
|
||||
|
||||
// Get current project
|
||||
const currentProject = await client.project.current()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 小路
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------ | ---------------- | ---------------------------------------- |
|
||||
| `path.get()` |獲取當前路徑 | <a href={typesUrl}><code>路徑</code></a> |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Get current path information
|
||||
const pathInfo = await client.path.get()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 配置
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| -------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
||||
| `config.get()` |獲取配置資訊 | <a href={typesUrl}><code>配置</code></a> |
|
||||
| `config.providers()` |列出提供商和預設模型 | `{ providers: `<a href={typesUrl}><code>提供商[]</code></a>`, default: { [key: string]: string } }` |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
const config = await client.config.get()
|
||||
|
||||
const { providers, default: defaults } = await client.config.providers()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 會議
|
||||
|
||||
|方法|描述 |筆記|
|
||||
| ---------------------------------------------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `session.list()` |列出會話 |返回 <a href={typesUrl}><code>Session[]</code></a> |
|
||||
| `session.get({ path })` |獲取會話 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.children({ path })` |列出子會話 |返回 <a href={typesUrl}><code>Session[]</code></a> |
|
||||
| `session.create({ body })` |建立會話 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.delete({ path })` | 离开会话 | 返回`boolean` |
|
||||
| `session.update({ path, body })` |更新會話屬性 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.init({ path, body })` | Analyze app and create `AGENTS.md` | Returns `boolean` |
|
||||
| `session.abort({ path })` |中止正在执行的会话 |返回`boolean` |
|
||||
| `session.share({ path })` |分享會 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.unshare({ path })` |取消共享會話 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.summarize({ path, body })` | 会议总结 |返回`boolean` |
|
||||
| `session.messages({ path })` |列出會話中的訊息 |返回 `{ info: `<a href={typesUrl}><code>訊息</code></a>`, parts: `<a href={typesUrl}><code>部分[]</code></a>`}[]` |
|
||||
| `session.message({ path })` |獲取訊息詳情 |返回 `{ info: `<a href={typesUrl}><code>訊息</code></a>`, parts: `<a href={typesUrl}><code>部分[]</code></a>`}` |
|
||||
| `session.prompt({ path, body })` |傳送提示資訊 | `body.noReply: true` 返回 UserMessage(僅限上下文)。預設返回 <a href={typesUrl}><code>AssistantMessage</code></a> 以及 AI 響應 |
|
||||
| `session.command({ path, body })` |向會話傳送命令 |返回 `{ info: `<a href={typesUrl}><code>AssistantMessage</code></a>`, parts: `<a href={typesUrl}><code>部分[]</code></a>`}` |
|
||||
| `session.shell({ path, body })` |執行 shell 命令 |返回 <a href={typesUrl}><code>AssistantMessage</code></a> |
|
||||
| `session.revert({ path, body })` |回覆訊息 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `session.unrevert({ path })` |恢復已恢復的訊息 |返回 <a href={typesUrl}><code>會話</code></a> |
|
||||
| `postSessionByIdPermissionsByPermissionId({ path, body })` |回复许可权限请求 |返回`boolean` |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Create and manage sessions
|
||||
const session = await client.session.create({
|
||||
body: { title: "My session" },
|
||||
})
|
||||
|
||||
const sessions = await client.session.list()
|
||||
|
||||
// Send a prompt message
|
||||
const result = await client.session.prompt({
|
||||
path: { id: session.id },
|
||||
body: {
|
||||
model: { providerID: "anthropic", modelID: "claude-3-5-sonnet-20241022" },
|
||||
parts: [{ type: "text", text: "Hello!" }],
|
||||
},
|
||||
})
|
||||
|
||||
// Inject context without triggering AI response (useful for plugins)
|
||||
await client.session.prompt({
|
||||
path: { id: session.id },
|
||||
body: {
|
||||
noReply: true,
|
||||
parts: [{ type: "text", text: "You are a helpful assistant." }],
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 檔案
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------- |
|
||||
| `find.text({ query })` |搜索档案中文字 | 含 `path`、`lines`、`line_number`、`absolute_offset`、`submatches` | 与像团队的匹配 |
|
||||
| `find.files({ query })` |按名称查询档案和目录 | `string[]`(路径)|
|
||||
| `find.symbols({ query })` |查詢工作區符號 | <a href={typesUrl}><code>符號[]</code></a> |
|
||||
| `file.read({ query })` | 读取档案 | `{ type: "raw" \| "patch", content: string }` |
|
||||
| `file.status({ query? })` |獲取跟蹤檔案的狀態 | <a href={typesUrl}><code>檔案[]</code></a> |
|
||||
|
||||
`find.files` 支持一些可选的查询栏位:
|
||||
|
||||
- `type`:`"file"` 或 `"directory"`
|
||||
- `directory`:覆盖搜索的专案根目录
|
||||
- `limit`:最大结果 (1–200)
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Search and read files
|
||||
const textResults = await client.find.text({
|
||||
query: { pattern: "function.*opencode" },
|
||||
})
|
||||
|
||||
const files = await client.find.files({
|
||||
query: { query: "*.ts", type: "file" },
|
||||
})
|
||||
|
||||
const directories = await client.find.files({
|
||||
query: { query: "packages", type: "directory", limit: 20 },
|
||||
})
|
||||
|
||||
const content = await client.file.read({
|
||||
query: { path: "src/index.ts" },
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### TUI
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------------------------ | ------------------------- | --------- |
|
||||
| `tui.appendPrompt({ body })` |将文字附加到提示| `boolean` |
|
||||
| `tui.openHelp()` | 开启帮助对话方块 | `boolean` |
|
||||
| `tui.openSessions()` |开启会话选择器 | `boolean` |
|
||||
| `tui.openThemes()` |开启主题选择器 | `boolean` |
|
||||
| `tui.openModels()` | 开启模型选择器 | `boolean` |
|
||||
| `tui.submitPrompt()` |提交当前提示| `boolean` |
|
||||
| `tui.clearPrompt()` |清除提示| `boolean` |
|
||||
| `tui.executeCommand({ body })` |执行命令| `boolean` |
|
||||
| `tui.showToast({ body })` | 显示吐司通知 | `boolean` |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Control TUI interface
|
||||
await client.tui.appendPrompt({
|
||||
body: { text: "Add this to prompt" },
|
||||
})
|
||||
|
||||
await client.tui.showToast({
|
||||
body: { message: "Task completed", variant: "success" },
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 授權
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------------- | ------------------------------ | --------- |
|
||||
| `auth.set({ ... })` |设定身份验证凭据| `boolean` |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
await client.auth.set({
|
||||
path: { id: "anthropic" },
|
||||
body: { type: "api", key: "your-api-key" },
|
||||
})
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 活動
|
||||
|
||||
|方法|描述 |回應 |
|
||||
| ------------------- | ------------------------- | ------------------------- |
|
||||
| `event.subscribe()` | 服务器传送的事件流 | 服务器传送的事件流 |
|
||||
|
||||
---
|
||||
|
||||
#### 示例
|
||||
|
||||
```javascript
|
||||
// Listen to real-time events
|
||||
const events = await client.event.subscribe()
|
||||
for await (const event of events.stream) {
|
||||
console.log("Event:", event.type, event.properties)
|
||||
}
|
||||
```
|
||||
287
packages/web/src/content/docs/zh-cn/server.mdx
Normal file
287
packages/web/src/content/docs/zh-cn/server.mdx
Normal file
@@ -0,0 +1,287 @@
|
||||
---
|
||||
title: 伺服器
|
||||
description: 通过 HTTP 与 opencode 服务器交互。
|
||||
---
|
||||
|
||||
import config from "../../../../config.mjs"
|
||||
export const typesUrl = `${config.github}/blob/dev/packages/sdk/js/src/gen/types.gen.ts`
|
||||
|
||||
The `opencode serve` command runs a headless HTTP server that exposes an OpenAPI endpoint that an opencode client can use.
|
||||
|
||||
---
|
||||
|
||||
### 用法
|
||||
|
||||
```bash
|
||||
opencode serve [--port <number>] [--hostname <string>] [--cors <origin>]
|
||||
```
|
||||
|
||||
#### 選項
|
||||
|
||||
| 旗幟 | 描述 | 預設 |
|
||||
| --------------- | --------------------- | ---------------- |
|
||||
| `--port` | 监听音频 | `4096` |
|
||||
| `--hostname` | 监听的主机名 | `127.0.0.1` |
|
||||
| `--mdns` | 启用 mDNS 发现 | `false` |
|
||||
| `--mdns-domain` | Custom domain name for mDNS service | `opencode.local` |
|
||||
| `--cors` | 允许的其他浏览器来源 | `[]` |
|
||||
|
||||
`--cors` 可以多次交付:
|
||||
|
||||
```bash
|
||||
opencode serve --cors http://localhost:5173 --cors https://app.example.com
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 驗證
|
||||
|
||||
Set `OPENCODE_SERVER_PASSWORD` to protect the server with HTTP basic auth. The username defaults to `opencode`, or set `OPENCODE_SERVER_USERNAME` to override it. This applies to both `opencode serve` and `opencode web`.
|
||||
|
||||
```bash
|
||||
OPENCODE_SERVER_PASSWORD=your-password opencode serve
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 它是如何運作的
|
||||
|
||||
When you run `opencode` it starts a TUI and a server. Where the TUI is the
|
||||
与服务器器对话的客户端。服务器器公开 OpenAPI 3.1 规范
|
||||
该端点还用于生成 [SDK](/docs/sdk)。
|
||||
|
||||
:::提示
|
||||
使用opencode服务器以程序设计方式与opencode交互。
|
||||
:::
|
||||
|
||||
该架构让 opencode 支持客户端,并允许您以多种设计方式与 opencode 交互。
|
||||
|
||||
You can run `opencode serve` to start a standalone server. If you have the
|
||||
opencode TUI running, `opencode serve` will start a new server.
|
||||
|
||||
---
|
||||
|
||||
#### 連線到現有伺服器
|
||||
|
||||
当您启动 TUI 时,它会随机分配端口和主机名。您可以重新设置 `--hostname` 和 `--port` [flags](/docs/cli)。使用它连线到其服务器然后器。
|
||||
|
||||
[**_T2_**](#tui) 端点可用于跨境服务器驱动 TUI。例如,您可以预填充或执行提示。此设置由 OpenCode [IDE](/docs/ide) 外挂使用。
|
||||
|
||||
---
|
||||
|
||||
## 規格
|
||||
|
||||
服务器发布了OpenAPI 3.1规范,可以在以下位置检视:
|
||||
|
||||
```
|
||||
http://<hostname>:<port>/doc
|
||||
```
|
||||
|
||||
例如,`http://localhost:4096/doc`。使用规范生成客户端或检查请求和响应类型其他。或者在 Swagger 浏览器中查看它。
|
||||
|
||||
---
|
||||
|
||||
## 蜜蜂
|
||||
|
||||
opencode服务器公开以下API。
|
||||
|
||||
---
|
||||
|
||||
### 全球的
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ---------------- | ------------------------ | ------------------------------------ |
|
||||
| `GET` | `/global/health` | 获取服务器运行状况和版本 | `{ healthy: true, version: string }` |
|
||||
| `GET` | `/global/event` | 获取全域性事件(SSE 流) | 事件流 |
|
||||
|
||||
---
|
||||
|
||||
### 專案
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ------------------ | ------------ | ------------------------------------------ |
|
||||
| `GET` | `/project` | 列出所有專案 | <a href={typesUrl}><code>專案[]</code></a> |
|
||||
| `GET` | `/project/current` | 獲取當前專案 | <a href={typesUrl}><code>專案</code></a> |
|
||||
|
||||
---
|
||||
|
||||
### 路径和VCS
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ------- | ----------------------- | ------------------------------------------- |
|
||||
| `GET` | `/path` | 獲取當前路徑 | <a href={typesUrl}><code>路徑</code></a> |
|
||||
| `GET` | `/vcs` | 獲取當前專案的 VCS 資訊 | <a href={typesUrl}><code>VcsInfo</code></a> |
|
||||
|
||||
---
|
||||
|
||||
### 例項
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------ | ------------------- | -------------- | --------- |
|
||||
| `POST` | `/instance/dispose` | 执行当前实例项 | `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### 配置
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------- | ------------------- | -------------------- | -------------------------------------------------------------------------------------- |
|
||||
| `GET` | `/config` | 獲取配置資訊 | <a href={typesUrl}><code>配置</code></a> |
|
||||
| `PATCH` | `/config` | 更新配置 | <a href={typesUrl}><code>配置</code></a> |
|
||||
| `GET` | `/config/providers` | 列出提供商和預設模型 | `{ providers: `<a href={typesUrl}>提供商[]</a>`, default: { [key: string]: string } }` |
|
||||
|
||||
---
|
||||
|
||||
### 提供者
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------ | -------------------------------- | ---------------------- | --------------------------------------------------------------------------------- |
|
||||
| `GET` | `/provider` | 列出所有提供商 | `{ all: `<a href={typesUrl}>提供商[]</a>`, default: {...}, connected: string[] }` |
|
||||
| `GET` | `/provider/auth` | 獲取提供商身份驗證方法 | `{ [providerID: string]: `<a href={typesUrl}>ProviderAuthMethod[]</a>` }` |
|
||||
| `POST` | `/provider/{id}/oauth/authorize` | 使用 OAuth 授權提供商 | <a href={typesUrl}><code>ProviderAuthAuthorization</code></a> |
|
||||
| `POST` | `/provider/{id}/oauth/callback` | 处理成功的 OAuth 回拨 | `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### 會議
|
||||
|
||||
| 方法 | 路徑 | 描述 | 筆記 |
|
||||
| -------- | ---------------------------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
|
||||
| `GET` | `/session` | 列出所有會話 | 返回 <a href={typesUrl}><code>Session[]</code></a> |
|
||||
| `POST` | `/session` | 建立新會話 | 正文: `{ parentID?, title? }`,返回 <a href={typesUrl}><code>Session</code></a> |
|
||||
| `GET` | `/session/status` | 獲取所有會話的會話狀態 | 返回 `{ [sessionID: string]: `<a href={typesUrl}>SessionStatus</a>` }` |
|
||||
| `GET` | `/session/:id` | 獲取會話詳細資訊 | 返回<a href={typesUrl}><code>會話</code></a> |
|
||||
| `DELETE` | `/session/:id` | 删除会话及所有资料 | 返回`boolean` |
|
||||
| `PATCH` | `/session/:id` | 更新會話屬性 | 正文: `{ title? }`,返回 <a href={typesUrl}><code>Session</code></a> |
|
||||
| `GET` | `/session/:id/children` | 獲取會話的子會話 | 返回 <a href={typesUrl}><code>Session[]</code></a> |
|
||||
| `GET` | `/session/:id/todo` | 獲取會話的待辦事項列表 | 返回 <a href={typesUrl}><code>Todo[]</code></a> |
|
||||
| `POST` | `/session/:id/init` | Analyze app and create `AGENTS.md` | body: `{ messageID, providerID, modelID }`, returns `boolean` |
|
||||
| `POST` | `/session/:id/fork` | 在訊息中分叉現有會話 | 正文: `{ messageID? }`,返回 <a href={typesUrl}><code>Session</code></a> |
|
||||
| `POST` | `/session/:id/abort` | 中止正在执行的会话 | 返回`boolean` |
|
||||
| `POST` | `/session/:id/share` | 分享會議 | 返回<a href={typesUrl}><code>會話</code></a> |
|
||||
| `DELETE` | `/session/:id/share` | 取消共享會話 | 返回<a href={typesUrl}><code>會話</code></a> |
|
||||
| `GET` | `/session/:id/diff` | 獲取本次會話的差異 | 查詢:`messageID?`,返回 <a href={typesUrl}><code>FileDiff[]</code></a> |
|
||||
| `POST` | `/session/:id/summarize` | 会议总结 | 正文:`{ providerID, modelID }`,返回 `boolean` |
|
||||
| `POST` | `/session/:id/revert` | 回覆讯息 | 正文:`{ messageID, partID? }`,返回 `boolean` |
|
||||
| `POST` | `/session/:id/unrevert` | 恢复所有已恢复的消息 | 返回`boolean` |
|
||||
| `POST` | `/session/:id/permissions/:permissionID` | 回复许可权限请求 | 正文:`{ response, remember? }`,返回 `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### 留言
|
||||
|
||||
| 方法 | 路徑 | 描述 | 筆記 |
|
||||
| ------ | --------------------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `GET` | `/session/:id/message` | 列出會話中的訊息 | 查詢: `limit?`,返回 `{ info: `<a href={typesUrl}>訊息</a>`, parts: `<a href={typesUrl}>Part[]</a>`}[]` |
|
||||
| `POST` | `/session/:id/message` | 傳送訊息並等待回覆 | 正文: `{ messageID?, model?, agent?, noReply?, system?, tools?, parts }`,返回 `{ info: `<a href={typesUrl}>訊息</a>`, parts: `<a href={typesUrl}>部分[]</a>`}` |
|
||||
| `GET` | `/session/:id/message/:messageID` | 獲取訊息詳情 | 返回 `{ info: `<a href={typesUrl}>訊息</a>`, parts: `<a href={typesUrl}>部分[]</a>`}` |
|
||||
| `POST` | `/session/:id/prompt_async` | 非同步传送消息(休眠等待) | 主体:与 `/session/:id/message` 相同,返回 `204 No Content` |
|
||||
| `POST` | `/session/:id/command` | 執行斜槓命令 | 正文: `{ messageID?, agent?, model?, command, arguments }`,返回 `{ info: `<a href={typesUrl}>訊息</a>`, parts: `<a href={typesUrl}>部分[]</a>`}` |
|
||||
| `POST` | `/session/:id/shell` | 執行 shell 命令 | 正文: `{ agent, model?, command }`,返回 `{ info: `<a href={typesUrl}>訊息</a>`, parts: `<a href={typesUrl}>部分[]</a>`}` |
|
||||
|
||||
---
|
||||
|
||||
### 命令
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ---------- | ------------ | ------------------------------------------ |
|
||||
| `GET` | `/command` | 列出所有命令 | <a href={typesUrl}><code>命令[]</code></a> |
|
||||
|
||||
---
|
||||
|
||||
### 檔案
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ------------------------ | -------------------- | ----------------------------------------------------------------------------------- |
|
||||
| `GET` | `/find?pattern=<pat>` | 搜尋檔案中的文字 | 具有 `path`、`lines`、`line_number`、`absolute_offset`、`submatches` 的匹配對像陣列 |
|
||||
| `GET` | `/find/file?query=<q>` | 按名稱查詢檔案和目錄 | `string[]`(路徑) |
|
||||
| `GET` | `/find/symbol?query=<q>` | 查詢工作區符號 | <a href={typesUrl}><code>符號[]</code></a> |
|
||||
| `GET` | `/file?path=<path>` | 列出檔案和目錄 | <a href={typesUrl}><code>FileNode[]</code></a> |
|
||||
| `GET` | `/file/content?path=<p>` | 讀取檔案 | <a href={typesUrl}><code>檔案內容</code></a> |
|
||||
| `GET` | `/file/status` | 獲取跟蹤檔案的狀態 | <a href={typesUrl}><code>檔案[]</code></a> |
|
||||
|
||||
#### `/find/file` 查询引数
|
||||
|
||||
- `query`(必需)—搜寻字串(模糊匹配)
|
||||
- `type`(可选)— 将结果限制为 `"file"` 或 `"directory"`
|
||||
- `directory` (任选) — 覆盖搜索的专案根目录
|
||||
- `limit`(任选)— 最大结果 (1–200)
|
||||
- `dirs`(任选)— 旧标志(`"false"`仅返回档案)
|
||||
|
||||
---
|
||||
|
||||
### 工具(實驗)
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ------------------------------------------- | ---------------------------- | -------------------------------------------- |
|
||||
| `GET` | `/experimental/tool/ids` | 列出所有工具 ID | <a href={typesUrl}><code>工具ID</code></a> |
|
||||
| `GET` | `/experimental/tool?provider=<p>&model=<m>` | 列出具有模型 JSON 模式的工具 | <a href={typesUrl}><code>工具列表</code></a> |
|
||||
|
||||
---
|
||||
|
||||
### LSP、格式化程式和 MCP
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------ | ------------ | ------------------- | ------------------------------------------------------ |
|
||||
| `GET` | `/lsp` | 獲取 LSP 伺服器狀態 | <a href={typesUrl}><code>LSPStatus[]</code></a> |
|
||||
| `GET` | `/formatter` | 獲取格式化程式狀態 | <a href={typesUrl}><code>FormatterStatus[]</code></a> |
|
||||
| `GET` | `/mcp` | 獲取 MCP 伺服器狀態 | `{ [name: string]: `<a href={typesUrl}>MCP狀態</a>` }` |
|
||||
| `POST` | `/mcp` | 动态添加 MCP 服务器 | 主体:`{ name, config }`,返回 MCP 状态对象 |
|
||||
|
||||
---
|
||||
|
||||
### 代理商
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | -------- | ------------------ | ------------------------------------------ |
|
||||
| `GET` | `/agent` | 列出所有可用的代理 | <a href={typesUrl}><code>代理[]</code></a> |
|
||||
|
||||
---
|
||||
|
||||
### 記錄
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------ | ------------------------------------------- | ------ | -------------------- |
|
||||
| `POST` | 身体:`{ service, level, message, extra? }` | `/log` | 写入日志。 `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### TUI
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ------ | ----------------------- | ----------------------------------------- | ------------ |
|
||||
| `POST` | `/tui/append-prompt` | 将文字附加到提示 | `boolean` |
|
||||
| `POST` | `/tui/open-help` | 开启帮助对话方块 | `boolean` |
|
||||
| `POST` | `/tui/open-sessions` | 开启会话选择器 | `boolean` |
|
||||
| `POST` | `/tui/open-themes` | 开启主题选择器 | `boolean` |
|
||||
| `POST` | `/tui/open-models` | 开启模型选择器 | `boolean` |
|
||||
| `POST` | `/tui/submit-prompt` | 提交当前提示 | `boolean` |
|
||||
| `POST` | `/tui/clear-prompt` | 清除提示 | `boolean` |
|
||||
| `POST` | `/tui/execute-command` | 执行命令 (`{ command }`) | `boolean` |
|
||||
| `POST` | `/tui/show-toast` | 显示祝酒 (`{ title?, message, variant }`) | `boolean` |
|
||||
| `GET` | `/tui/control/next` | 等待下一个控制请求 | 控制请求对象 |
|
||||
| `POST` | `/tui/control/response` | 响应控制请求 (`{ body }`) | `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### 授權
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ----------- | ------------------------------------------ | --------- |
|
||||
| `PUT` | `/auth/:id` | 设置身份验证凭据。正文必须与提供者架构匹配 | `boolean` |
|
||||
|
||||
---
|
||||
|
||||
### 活動
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ---------------------------------------------- | ------------------ | -------- | -------------------- |
|
||||
| `GET` | 第一个事件是`server.connected`,然后是巴士事件 | 服务器传送的事件流 | `/event` | 服务器传送的事件流。 |
|
||||
|
||||
---
|
||||
|
||||
### 檔案
|
||||
|
||||
| 方法 | 路徑 | 描述 | 回應 |
|
||||
| ----- | ------ | --------------- | ------------------------- |
|
||||
| `GET` | `/doc` | 开启API 3.1规范 | 具有OpenAPI规范的HTML页面 |
|
||||
128
packages/web/src/content/docs/zh-cn/share.mdx
Normal file
128
packages/web/src/content/docs/zh-cn/share.mdx
Normal file
@@ -0,0 +1,128 @@
|
||||
---
|
||||
title: 分享
|
||||
description: 分享您的 OpenCode 对话。
|
||||
---
|
||||
|
||||
OpenCode 的共享功能允许您建立指向 OpenCode 对话的公共链接,以便您可以与蓝牙进行战斗或从其他人那里获得帮助。
|
||||
|
||||
:::笔记
|
||||
任何知道連結的人都可以公開訪問共享對話。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 它是如何運作的
|
||||
|
||||
当您分享对话时,OpenCode:
|
||||
|
||||
1. 为您的会话建立唯一的公共 URL
|
||||
2. 將您的對話歷史記錄同步到我們的伺服器
|
||||
3. 透過可共享連結訪問對話 — `opncd.ai/s/<share-id>`
|
||||
|
||||
---
|
||||
|
||||
## 分享
|
||||
|
||||
OpenCode 支持清晰控制对话共享方式的共享模式:
|
||||
|
||||
---
|
||||
|
||||
### 手動(預設)
|
||||
|
||||
在默认情况下,OpenCode 使用手动共享模式。会话不会自动共享,但您可以使用 `/share` 命令手动共享它们:
|
||||
|
||||
```
|
||||
/share
|
||||
```
|
||||
|
||||
这将生成一个唯一的 URL,将其复制到您的剪贴簿中。
|
||||
|
||||
要在[配置文件](/docs/config) 中显式设置手动模式:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opncd.ai/config.json",
|
||||
"share": "manual"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 自動分享
|
||||
|
||||
您可以通过将 [config file](/docs/config) 中的 `share` 选项设置为 `"auto"` 来为所有新对话启用自动共享:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opncd.ai/config.json",
|
||||
"share": "auto"
|
||||
}
|
||||
```
|
||||
|
||||
啟用自動共享後,每個新對話都會自動共享並生成連結。
|
||||
|
||||
---
|
||||
|
||||
### 殘疾人
|
||||
|
||||
您可以通过将 [config file](/docs/config) 中的 `share` 选项设置为 `"disabled"` 来完全禁用共享:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opncd.ai/config.json",
|
||||
"share": "disabled"
|
||||
}
|
||||
```
|
||||
|
||||
To enforce this across your team for a given project, add it to the `opencode.json` in your project and check into Git.
|
||||
|
||||
---
|
||||
|
||||
## 取消共享
|
||||
|
||||
要停止共享對話並將其從公共訪問中刪除:
|
||||
|
||||
```
|
||||
/unshare
|
||||
```
|
||||
|
||||
這將刪除共享連結並刪除與對話相關的資料。
|
||||
|
||||
---
|
||||
|
||||
## 隱私
|
||||
|
||||
分享對話時需要記住一些事項。
|
||||
|
||||
---
|
||||
|
||||
### 資料保留
|
||||
|
||||
共享對話仍然可以訪問,直到您明確取消共享。這
|
||||
包括:
|
||||
|
||||
- 完整的對話歷史記錄
|
||||
- 所有訊息和回覆
|
||||
- 會話後設資料
|
||||
|
||||
---
|
||||
|
||||
### 建議
|
||||
|
||||
- 僅共享不包含敏感資訊的對話。
|
||||
- 分享之前檢視對話內容。
|
||||
- 協作完成後取消共享對話。
|
||||
- 避免與專有程式碼或機密資料共享對話。
|
||||
- 對於敏感專案,完全禁用共享。
|
||||
|
||||
---
|
||||
|
||||
## 對於企業
|
||||
|
||||
對於企業部署,共享功能可以是:
|
||||
|
||||
- **出於安全合規性完全禁用**
|
||||
- **仅限** 仅透过 SSO 进行身份验证的用户
|
||||
- **在您自己的基礎設施上自行託管**
|
||||
|
||||
[了解更多关于在您的组织中使用开放代码的](/docs/enterprise)。
|
||||
222
packages/web/src/content/docs/zh-cn/skills.mdx
Normal file
222
packages/web/src/content/docs/zh-cn/skills.mdx
Normal file
@@ -0,0 +1,222 @@
|
||||
---
|
||||
title: 《代理技巧》
|
||||
description: “贯穿 SKILL.md 定义可重用行为”
|
||||
---
|
||||
|
||||
代理让 OpenCode 技能从您的存储库或主目录中找到可重用的指令。
|
||||
技能贯穿本机 `skill` 工具输入导入 - 代理可以检视可用技能并可以在需要时加载完整内容。
|
||||
|
||||
---
|
||||
|
||||
## 放置檔案
|
||||
|
||||
为每个技能名称建立一个资料夹,并在其中放入`SKILL.md`。
|
||||
OpenCode 搜索这些位置:
|
||||
|
||||
- Project config: `.opencode/skills/<name>/SKILL.md`
|
||||
- Global config: `~/.config/opencode/skills/<name>/SKILL.md`
|
||||
- 專案Claude相容:`.claude/skills/<name>/SKILL.md`
|
||||
- 全域性 Claude 相容: `~/.claude/skills/<name>/SKILL.md`
|
||||
- 專案代理相容:`.agents/skills/<name>/SKILL.md`
|
||||
- 全球代理相容:`~/.agents/skills/<name>/SKILL.md`
|
||||
|
||||
---
|
||||
|
||||
## 瞭解發現
|
||||
|
||||
对于专案本地路径, OpenCode 从当前工作目录向上走,直到到达 git 工作树。
|
||||
It loads any matching `skills/*/SKILL.md` in `.opencode/` and any matching `.claude/skills/*/SKILL.md` or `.agents/skills/*/SKILL.md` along the way.
|
||||
|
||||
Global definitions are also loaded from `~/.config/opencode/skills/*/SKILL.md`, `~/.claude/skills/*/SKILL.md`, and `~/.agents/skills/*/SKILL.md`.
|
||||
|
||||
---
|
||||
|
||||
## 寫前言
|
||||
|
||||
每个 `SKILL.md` 必须以 YAML frontmatter 。
|
||||
僅識別這些欄位:
|
||||
|
||||
- `name`(必填)
|
||||
- `description`(必填)
|
||||
- `license`(任选)
|
||||
- `compatibility`(任选)
|
||||
- `metadata`(任选,字串到字串对映)
|
||||
|
||||
未知的 frontmatter 栏位将被忽略。
|
||||
|
||||
---
|
||||
|
||||
## 驗證姓名
|
||||
|
||||
`name` 必须:
|
||||
|
||||
- 長度為 1–64 個字元
|
||||
- 為小寫字母數字並帶有單個連字元分隔符
|
||||
- 不以 `-` 開始或結束
|
||||
- 不包含連續的 `--`
|
||||
- 匹配包含 `SKILL.md` 的目录名
|
||||
|
||||
等效的正規表示式:
|
||||
|
||||
```text
|
||||
^[a-z0-9]+(-[a-z0-9]+)*$
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 遵循長度規則
|
||||
|
||||
`description` 必须是 1-1024 个字元。
|
||||
保持足夠具體,以便代理能夠正確選擇。
|
||||
|
||||
---
|
||||
|
||||
## 使用一個例子
|
||||
|
||||
Create `.opencode/skills/git-release/SKILL.md` like this:
|
||||
|
||||
```markdown
|
||||
---
|
||||
name: git-release
|
||||
description: Create consistent releases and changelogs
|
||||
license: MIT
|
||||
compatibility: opencode
|
||||
metadata:
|
||||
audience: maintainers
|
||||
workflow: github
|
||||
---
|
||||
|
||||
## What I do
|
||||
|
||||
- Draft release notes from merged PRs
|
||||
- Propose a version bump
|
||||
- Provide a copy-pasteable `gh release create` command
|
||||
|
||||
## When to use me
|
||||
|
||||
Use this when you are preparing a tagged release.
|
||||
Ask clarifying questions if the target versioning scheme is unclear.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 識別工具說明
|
||||
|
||||
OpenCode 列出了 `skill` 工具描述中的可用技能。
|
||||
每個條目都包含技能名稱和描述:
|
||||
|
||||
```xml
|
||||
<available_skills>
|
||||
<skill>
|
||||
<name>git-release</name>
|
||||
<description>Create consistent releases and changelogs</description>
|
||||
</skill>
|
||||
</available_skills>
|
||||
```
|
||||
|
||||
代理透過呼叫工具來載入技能:
|
||||
|
||||
```
|
||||
skill({ name: "git-release" })
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 配置許可權
|
||||
|
||||
Control which skills agents can access using pattern-based permissions in `opencode.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"permission": {
|
||||
"skill": {
|
||||
"*": "allow",
|
||||
"pr-review": "allow",
|
||||
"internal-*": "deny",
|
||||
"experimental-*": "ask"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|許可|行為 |
|
||||
| ---------- | ----------------------------------------- |
|
||||
| `allow` | 技能立即加载 |
|
||||
| `deny` | 对特工隐藏技能,访问被拒绝 |
|
||||
| `ask` | 加载前提示用户批准 |
|
||||
|
||||
模式支持万用字元:`internal-*` 匹配 `internal-docs`、`internal-tools` 等。
|
||||
|
||||
---
|
||||
|
||||
## 覆蓋每個代理
|
||||
|
||||
為特定代理授予與全域性預設許可權不同的許可權。
|
||||
|
||||
**對於自定義代理**(在代理前言中):
|
||||
|
||||
```yaml
|
||||
---
|
||||
permission:
|
||||
skill:
|
||||
"documents-*": "allow"
|
||||
---
|
||||
```
|
||||
|
||||
**For built-in agents** (in `opencode.json`):
|
||||
|
||||
```json
|
||||
{
|
||||
"agent": {
|
||||
"plan": {
|
||||
"permission": {
|
||||
"skill": {
|
||||
"internal-*": "allow"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 禁用技能工具
|
||||
|
||||
完全禁用不應該使用技能的特工:
|
||||
|
||||
**對於定製代理**:
|
||||
|
||||
```yaml
|
||||
---
|
||||
tools:
|
||||
skill: false
|
||||
---
|
||||
```
|
||||
|
||||
**對於內建代理**:
|
||||
|
||||
```json
|
||||
{
|
||||
"agent": {
|
||||
"plan": {
|
||||
"tools": {
|
||||
"skill": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
禁用後,`<available_skills>` 部分將被完全省略。
|
||||
|
||||
---
|
||||
|
||||
## 解決載入問題
|
||||
|
||||
如果某項技能沒有顯示:
|
||||
|
||||
1. 验证 `SKILL.md` 拼写为全部大写
|
||||
2. 检查 frontmatter 是否包括 `name` 和 `description`
|
||||
3. 確保技能名稱在所有位置都是唯一的
|
||||
4. 查询权限——具有`deny`的代理隐藏技能
|
||||
369
packages/web/src/content/docs/zh-cn/themes.mdx
Normal file
369
packages/web/src/content/docs/zh-cn/themes.mdx
Normal file
@@ -0,0 +1,369 @@
|
||||
---
|
||||
title: 主題
|
||||
description: 選擇內建主題或定義您自己的主題。
|
||||
---
|
||||
|
||||
使用 OpenCode,您可以从多个内建主题中进行选择,使用适合您的终端主题的主题,或定义您自己的自定义主题。
|
||||
|
||||
By default, OpenCode uses our own `opencode` theme.
|
||||
|
||||
---
|
||||
|
||||
## 終端要求
|
||||
|
||||
為了使主題能夠正確顯示完整的調色盤,您的終端必須支援**真彩色**(24 位顏色)。大多數現代終端預設支援此功能,但您可能需要啟用它:
|
||||
|
||||
- **检查支持**:执行 `echo $COLORTERM` - 它应该输出 `truecolor` 或 `24bit`
|
||||
- **启用真彩色**:在shell配置文件中设置环境变量`COLORTERM=truecolor`
|
||||
- **您的终端相容性**:确保终端模拟器支持24位颜色(大多数现代终端,如iTerm2、Alacritty、Kitty、Windows终端和最新版本的GNOME终端都支持)
|
||||
|
||||
如果沒有真彩色支援,主題的顏色精度可能會降低或回落到最接近的 256 色近似值。
|
||||
|
||||
---
|
||||
|
||||
## 內建主題
|
||||
|
||||
OpenCode 带有几个内建主题。
|
||||
|
||||
|名稱 |描述 |
|
||||
| ---------------------- | ---------------------------------------------------------------------------- |
|
||||
| `system` |适应您所处的背景颜色|
|
||||
| `tokyonight` | Based on the [Tokyonight](https://github.com/folke/tokyonight.nvim) theme |
|
||||
| `everforest` | Based on the [Everforest](https://github.com/sainnhe/everforest) theme |
|
||||
| `ayu` | Based on the [Ayu](https://github.com/ayu-theme) dark theme |
|
||||
| `catppuccin` | Based on the [Catppuccin](https://github.com/catppuccin) theme |
|
||||
| `catppuccin-macchiato` | Based on the [Catppuccin](https://github.com/catppuccin) theme |
|
||||
| `gruvbox` | Based on the [Gruvbox](https://github.com/morhetz/gruvbox) theme |
|
||||
| `kanagawa` | Based on the [Kanagawa](https://github.com/rebelot/kanagawa.nvim) theme |
|
||||
| `nord` | Based on the [Nord](https://github.com/nordtheme/nord) theme |
|
||||
| `matrix` | 骇客风格黑底绿主题|
|
||||
| `one-dark` | Based on the [Atom One](https://github.com/Th3Whit3Wolf/one-nvim) Dark theme |
|
||||
|
||||
此外,我們還在不斷新增新主題。
|
||||
|
||||
---
|
||||
|
||||
## 系統主題
|
||||
|
||||
`system` 主题旨在自动适应您的最终方案。与使用固定颜色的传统主题不同,_system_ 主题:
|
||||
|
||||
- **生成灰度**:根據終端的背景顏色建立自定義灰度,確保最佳對比度。
|
||||
- **使用 ANSI 颜色**:使用标准 ANSI 颜色 (0-15) 进行语法突出显示和 UI 元素,尊重 Windows 的调色盘。
|
||||
- **保留默认设置**:使用 `none` 作为文字和背景颜色以保持本机的外观。
|
||||
|
||||
系統主題適合以下使用者:
|
||||
|
||||
- 希望 OpenCode 与终端的外观相匹配
|
||||
- 使用自定義終端配色方案
|
||||
- 希望所有終端應用程式具有一致的外觀
|
||||
|
||||
---
|
||||
|
||||
## 使用主題
|
||||
|
||||
您可以通过使用 `/theme` 命令调出主题选择来选择主题。或者您可以在 [config](/docs/config) 中指定它。
|
||||
|
||||
```json title="opencode.json" {3}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"theme": "tokyonight"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 自定義主題
|
||||
|
||||
OpenCode 支持灵活的基于 JSON 的主题系统,允许用户轻松创建和自定义主题。
|
||||
|
||||
---
|
||||
|
||||
### 等級制度
|
||||
|
||||
主題按以下順序從多個目錄載入,其中後面的目錄覆蓋前面的目錄:
|
||||
|
||||
1. **內建主題** - 這些主題嵌入在二進製檔案中
|
||||
2. **User config directory** - Defined in `~/.config/opencode/themes/*.json` or `$XDG_CONFIG_HOME/opencode/themes/*.json`
|
||||
3. **Project root directory** - Defined in the `<project-root>/.opencode/themes/*.json`
|
||||
4. **Current working directory** - Defined in `./.opencode/themes/*.json`
|
||||
|
||||
如果多個目錄包含同名主題,則將使用優先順序較高的目錄中的主題。
|
||||
|
||||
---
|
||||
|
||||
### 建立主題
|
||||
|
||||
要创建自定义主题,请在主题目录中创建 JSON 档案。
|
||||
|
||||
對於使用者範圍的主題:
|
||||
|
||||
```bash no-frame
|
||||
mkdir -p ~/.config/opencode/themes
|
||||
vim ~/.config/opencode/themes/my-theme.json
|
||||
```
|
||||
|
||||
以及針對特定專案的主題。
|
||||
|
||||
```bash no-frame
|
||||
mkdir -p .opencode/themes
|
||||
vim .opencode/themes/my-theme.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### JSON 格式
|
||||
|
||||
主题使用灵活的 JSON 格式,支持:
|
||||
|
||||
- **十六进位制造颜色**: `"#ffffff"`
|
||||
- **ANSI 颜色**: `3` (0-255)
|
||||
- **颜色参考**: `"primary"` 或自定义定义
|
||||
- **深色/light 变体**: `{"dark": "#000", "light": "#fff"}`
|
||||
- **无颜色**: `"none"` - 使用终端的默认颜色或透明
|
||||
|
||||
---
|
||||
|
||||
### 顏色定義
|
||||
|
||||
`defs` 部分是可选的,它允许您定义可在主题中引用的可重用颜色。
|
||||
|
||||
---
|
||||
|
||||
### 終端預設值
|
||||
|
||||
特殊值 `"none"` 可用于任何颜色以继承默认的默认颜色。这对于建立与终端方案无缝的融合主题特别有用:
|
||||
|
||||
- `"text": "none"` - 使用遥控器的预设前景色
|
||||
- `"background": "none"` - 使用桌面的背景颜色
|
||||
|
||||
---
|
||||
|
||||
### 例子
|
||||
|
||||
以下是自定義主題的示例:
|
||||
|
||||
```json title="my-theme.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/theme.json",
|
||||
"defs": {
|
||||
"nord0": "#2E3440",
|
||||
"nord1": "#3B4252",
|
||||
"nord2": "#434C5E",
|
||||
"nord3": "#4C566A",
|
||||
"nord4": "#D8DEE9",
|
||||
"nord5": "#E5E9F0",
|
||||
"nord6": "#ECEFF4",
|
||||
"nord7": "#8FBCBB",
|
||||
"nord8": "#88C0D0",
|
||||
"nord9": "#81A1C1",
|
||||
"nord10": "#5E81AC",
|
||||
"nord11": "#BF616A",
|
||||
"nord12": "#D08770",
|
||||
"nord13": "#EBCB8B",
|
||||
"nord14": "#A3BE8C",
|
||||
"nord15": "#B48EAD"
|
||||
},
|
||||
"theme": {
|
||||
"primary": {
|
||||
"dark": "nord8",
|
||||
"light": "nord10"
|
||||
},
|
||||
"secondary": {
|
||||
"dark": "nord9",
|
||||
"light": "nord9"
|
||||
},
|
||||
"accent": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"error": {
|
||||
"dark": "nord11",
|
||||
"light": "nord11"
|
||||
},
|
||||
"warning": {
|
||||
"dark": "nord12",
|
||||
"light": "nord12"
|
||||
},
|
||||
"success": {
|
||||
"dark": "nord14",
|
||||
"light": "nord14"
|
||||
},
|
||||
"info": {
|
||||
"dark": "nord8",
|
||||
"light": "nord10"
|
||||
},
|
||||
"text": {
|
||||
"dark": "nord4",
|
||||
"light": "nord0"
|
||||
},
|
||||
"textMuted": {
|
||||
"dark": "nord3",
|
||||
"light": "nord1"
|
||||
},
|
||||
"background": {
|
||||
"dark": "nord0",
|
||||
"light": "nord6"
|
||||
},
|
||||
"backgroundPanel": {
|
||||
"dark": "nord1",
|
||||
"light": "nord5"
|
||||
},
|
||||
"backgroundElement": {
|
||||
"dark": "nord1",
|
||||
"light": "nord4"
|
||||
},
|
||||
"border": {
|
||||
"dark": "nord2",
|
||||
"light": "nord3"
|
||||
},
|
||||
"borderActive": {
|
||||
"dark": "nord3",
|
||||
"light": "nord2"
|
||||
},
|
||||
"borderSubtle": {
|
||||
"dark": "nord2",
|
||||
"light": "nord3"
|
||||
},
|
||||
"diffAdded": {
|
||||
"dark": "nord14",
|
||||
"light": "nord14"
|
||||
},
|
||||
"diffRemoved": {
|
||||
"dark": "nord11",
|
||||
"light": "nord11"
|
||||
},
|
||||
"diffContext": {
|
||||
"dark": "nord3",
|
||||
"light": "nord3"
|
||||
},
|
||||
"diffHunkHeader": {
|
||||
"dark": "nord3",
|
||||
"light": "nord3"
|
||||
},
|
||||
"diffHighlightAdded": {
|
||||
"dark": "nord14",
|
||||
"light": "nord14"
|
||||
},
|
||||
"diffHighlightRemoved": {
|
||||
"dark": "nord11",
|
||||
"light": "nord11"
|
||||
},
|
||||
"diffAddedBg": {
|
||||
"dark": "#3B4252",
|
||||
"light": "#E5E9F0"
|
||||
},
|
||||
"diffRemovedBg": {
|
||||
"dark": "#3B4252",
|
||||
"light": "#E5E9F0"
|
||||
},
|
||||
"diffContextBg": {
|
||||
"dark": "nord1",
|
||||
"light": "nord5"
|
||||
},
|
||||
"diffLineNumber": {
|
||||
"dark": "nord2",
|
||||
"light": "nord4"
|
||||
},
|
||||
"diffAddedLineNumberBg": {
|
||||
"dark": "#3B4252",
|
||||
"light": "#E5E9F0"
|
||||
},
|
||||
"diffRemovedLineNumberBg": {
|
||||
"dark": "#3B4252",
|
||||
"light": "#E5E9F0"
|
||||
},
|
||||
"markdownText": {
|
||||
"dark": "nord4",
|
||||
"light": "nord0"
|
||||
},
|
||||
"markdownHeading": {
|
||||
"dark": "nord8",
|
||||
"light": "nord10"
|
||||
},
|
||||
"markdownLink": {
|
||||
"dark": "nord9",
|
||||
"light": "nord9"
|
||||
},
|
||||
"markdownLinkText": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"markdownCode": {
|
||||
"dark": "nord14",
|
||||
"light": "nord14"
|
||||
},
|
||||
"markdownBlockQuote": {
|
||||
"dark": "nord3",
|
||||
"light": "nord3"
|
||||
},
|
||||
"markdownEmph": {
|
||||
"dark": "nord12",
|
||||
"light": "nord12"
|
||||
},
|
||||
"markdownStrong": {
|
||||
"dark": "nord13",
|
||||
"light": "nord13"
|
||||
},
|
||||
"markdownHorizontalRule": {
|
||||
"dark": "nord3",
|
||||
"light": "nord3"
|
||||
},
|
||||
"markdownListItem": {
|
||||
"dark": "nord8",
|
||||
"light": "nord10"
|
||||
},
|
||||
"markdownListEnumeration": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"markdownImage": {
|
||||
"dark": "nord9",
|
||||
"light": "nord9"
|
||||
},
|
||||
"markdownImageText": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"markdownCodeBlock": {
|
||||
"dark": "nord4",
|
||||
"light": "nord0"
|
||||
},
|
||||
"syntaxComment": {
|
||||
"dark": "nord3",
|
||||
"light": "nord3"
|
||||
},
|
||||
"syntaxKeyword": {
|
||||
"dark": "nord9",
|
||||
"light": "nord9"
|
||||
},
|
||||
"syntaxFunction": {
|
||||
"dark": "nord8",
|
||||
"light": "nord8"
|
||||
},
|
||||
"syntaxVariable": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"syntaxString": {
|
||||
"dark": "nord14",
|
||||
"light": "nord14"
|
||||
},
|
||||
"syntaxNumber": {
|
||||
"dark": "nord15",
|
||||
"light": "nord15"
|
||||
},
|
||||
"syntaxType": {
|
||||
"dark": "nord7",
|
||||
"light": "nord7"
|
||||
},
|
||||
"syntaxOperator": {
|
||||
"dark": "nord9",
|
||||
"light": "nord9"
|
||||
},
|
||||
"syntaxPunctuation": {
|
||||
"dark": "nord4",
|
||||
"light": "nord0"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
379
packages/web/src/content/docs/zh-cn/tools.mdx
Normal file
379
packages/web/src/content/docs/zh-cn/tools.mdx
Normal file
@@ -0,0 +1,379 @@
|
||||
---
|
||||
title: 工具
|
||||
description: 管理 LLM 可以使用的工具。
|
||||
---
|
||||
|
||||
Tools allow the LLM to perform actions in your codebase. OpenCode comes with a set of built-in tools, but you can extend it with [custom tools](/docs/custom-tools) or [MCP servers](/docs/mcp-servers).
|
||||
|
||||
默认情况下,所有工具都是**启用**并且不需要执行权限。您可以交叉[permissions](/docs/permissions) 控制工具行为。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
使用 `permission` 栏位控制工具行为。您可以允许、拒绝或要求批准每个工具。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "deny",
|
||||
"bash": "ask",
|
||||
"webfetch": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
您还可以使用万用字元同时控制多个工具。例如,要求 MCP 服务器批准所有工具:
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"mymcp_*": "ask"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
[了解更多](/docs/permissions)关于配置许可权。
|
||||
|
||||
---
|
||||
|
||||
## 內建
|
||||
|
||||
以下是 OpenCode 中可用的所有内置工具。
|
||||
|
||||
---
|
||||
|
||||
### 巴什
|
||||
|
||||
在专案环境中执行shell命令。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"bash": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This tool allows the LLM to run terminal commands like `npm install`, `git status`, or any other shell command.
|
||||
|
||||
---
|
||||
|
||||
### 編輯
|
||||
|
||||
使用精確的字串替換修改現有檔案。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
该工具取消替换精确的文字来匹配对文件执行精确编辑。这是 LLM 修改程序代码的主要方式。
|
||||
|
||||
---
|
||||
|
||||
### 寫
|
||||
|
||||
建立新檔案或覆蓋現有檔案。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
使用它允许 LLM 创建新文件。如果现有文件已经存在,将会覆盖它们。
|
||||
|
||||
:::笔记
|
||||
`write`工具由`edit`许可权控制,该许可权主题所有文件修改(`edit`、`write`、`patch`、`multiedit`)。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 讀
|
||||
|
||||
從程式碼庫中讀取檔案內容。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"read": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
該工具讀取檔案並返回其內容。它支援讀取大檔案的特定行範圍。
|
||||
|
||||
---
|
||||
|
||||
### grep
|
||||
|
||||
使用正規表示式搜尋檔案內容。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"grep": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
在您的程式碼庫中快速進行內容搜尋。支援完整的正規表示式語法和檔案模式過濾。
|
||||
|
||||
---
|
||||
|
||||
### 全域性
|
||||
|
||||
透過模式匹配查詢檔案。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"glob": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
使用 `**/*.js` 或 `src/**/*.ts` 等全域性模式搜索档案。返回按时间排序的匹配档案路径修改。
|
||||
|
||||
---
|
||||
|
||||
### 列表
|
||||
|
||||
列出給定路徑中的檔案和目錄。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"list": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
該工具列出目錄內容。它接受全域性模式來過濾結果。
|
||||
|
||||
---
|
||||
|
||||
### lsp(实验性)
|
||||
|
||||
与您配置的LSP服务器交互,通知计划码智慧功能,例如定义、引用、悬停资讯和呼叫层次结构。
|
||||
|
||||
:::笔记
|
||||
This tool is only available when `OPENCODE_EXPERIMENTAL_LSP_TOOL=true` (or `OPENCODE_EXPERIMENTAL=true`).
|
||||
:::
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"lsp": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
支援的操作包括 `goToDefinition`、`findReferences`、`hover`、`documentSymbol`、`workspaceSymbol`、`goToImplementation`、`prepareCallHierarchy`、`incomingCalls` 和 `outgoingCalls`。
|
||||
|
||||
To configure which LSP servers are available for your project, see [LSP Servers](/docs/lsp).
|
||||
|
||||
---
|
||||
|
||||
### 修補
|
||||
|
||||
對檔案應用補丁。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"edit": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
該工具將補丁檔案應用到您的程式碼庫。對於應用來自各種來源的差異和補丁很有用。
|
||||
|
||||
:::笔记
|
||||
`patch`工具由`edit`许可权控制,该许可权主题所有文件修改(`edit`、`write`、`patch`、`multiedit`)。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 技能
|
||||
|
||||
加载[skill](/docs/skills)(`SKILL.md` 档案)并在对话中返回其内容。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"skill": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 待辦寫入
|
||||
|
||||
在編碼會話期間管理待辦事項列表。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"todowrite": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
建立和更新任务列表以跟踪复杂操作期间的详细信息。LLM 使用它来组织多步骤任务。
|
||||
|
||||
:::笔记
|
||||
默认情况下,子代理取消此工具,但您可以手动启用它。 [了解更多](/docs/agents/#permissions)
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 託多雷德
|
||||
|
||||
閱讀現有的待辦事項列表。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"todoread": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
读取当前完成待办事项列表状态。由 LLM 用于跟踪哪些任务待处理或已已。
|
||||
|
||||
:::笔记
|
||||
默认情况下,子代理取消此工具,但您可以手动启用它。 [了解更多](/docs/agents/#permissions)
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 網頁抓取
|
||||
|
||||
獲取網頁內容。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"webfetch": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
允许 LLM 获取和读取网页。对于查询文件或研究线上资源很有用。
|
||||
|
||||
---
|
||||
|
||||
### 網路搜尋
|
||||
|
||||
在網路上搜尋資訊。
|
||||
|
||||
:::笔记
|
||||
仅当使用 OpenCode 提供或 `OPENCODE_ENABLE_EXA` 程序环境变量设置为任何真值(例如 `true` 或 `1`)时,此工具才可用。
|
||||
|
||||
要在启动 OpenCode 时启用:
|
||||
|
||||
```bash
|
||||
OPENCODE_ENABLE_EXA=1 opencode
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"websearch": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
使用 Exa AI 执行网路搜索以线上查询相关资讯。对于研究主题、查询时事或收集训练超出数据范围的资讯很有用。
|
||||
|
||||
不需要 API 金钥匙 — 该工具消耗身份验证即可直接连线到 Exa AI 的托管 MCP 服务。
|
||||
|
||||
:::提示
|
||||
当您需要查询资讯(发现)时,请使用 `websearch`;当您需要从特定 URL 检索内容(搜索)时,请使用 `webfetch`。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
### 問題
|
||||
|
||||
在執行過程中詢問使用者問題。
|
||||
|
||||
```json title="opencode.json" {4}
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"permission": {
|
||||
"question": "allow"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
该工具允许 LLM 在任务期间询问用户问题。它适用于:
|
||||
|
||||
- 收集使用者偏好或要求
|
||||
- 澄清不明確的指令
|
||||
- 就實施選擇做出決策
|
||||
- 提供選擇方向
|
||||
|
||||
每個問題都包含標題、問題文字和選項列表。使用者可以從提供的選項中進行選擇或輸入自定義答案。當存在多個問題時,使用者可以在提交所有答案之前在這些問題之間導航。
|
||||
|
||||
---
|
||||
|
||||
## 定製工具
|
||||
|
||||
自定义工具可以让您定义LLM可以调用自己的函式。这些是在您的配置文件中定义的并且可以执行任何程序代码。
|
||||
|
||||
[了解更多](/docs/custom-tools)关于创建自定义工具。
|
||||
|
||||
---
|
||||
|
||||
## MCP 伺服器
|
||||
|
||||
MCP(模型上下文协议)服务器允许您集成外部工具和服务。这包括数据库访问、API 集成和第三方服务。
|
||||
|
||||
[了解更多](/docs/mcp-servers)关于配置MCP服务器。
|
||||
|
||||
---
|
||||
|
||||
## 內部結構
|
||||
|
||||
Internally, tools like `grep`, `glob`, and `list` use [ripgrep](https://github.com/BurntSushi/ripgrep) under the hood. By default, ripgrep respects `.gitignore` patterns, which means files and directories listed in your `.gitignore` will be excluded from searches and listings.
|
||||
|
||||
---
|
||||
|
||||
### 忽略模式
|
||||
|
||||
要包含通常会被忽略的文件,请在专案根目录中建立 `.ignore` 文件。该文件可以明确允许某些路径。
|
||||
|
||||
```text title=".ignore"
|
||||
!node_modules/
|
||||
!dist/
|
||||
!build/
|
||||
```
|
||||
|
||||
例如,此 `.ignore` 档案允许 ripgrep 在 `node_modules/`、`dist/` 和 `build/` 目录中搜索,即使它们列在 `.gitignore` 中。
|
||||
300
packages/web/src/content/docs/zh-cn/troubleshooting.mdx
Normal file
300
packages/web/src/content/docs/zh-cn/troubleshooting.mdx
Normal file
@@ -0,0 +1,300 @@
|
||||
---
|
||||
title: 故障排除
|
||||
description: 常見問題以及如何解決它們。
|
||||
---
|
||||
|
||||
要排除 OpenCode 的问题,请首先检查其存储在磁碟上的日志和本地数据。
|
||||
|
||||
---
|
||||
|
||||
## 紀錄
|
||||
|
||||
日誌檔案寫入:
|
||||
|
||||
- **macOS/Linux**: `~/.local/share/opencode/log/`
|
||||
- **Windows**: Press `WIN+R` and paste `%USERPROFILE%\.local\share\opencode\log`
|
||||
|
||||
日志档案以时间命名(例如`2025-01-09T123456.log`),并保留最近10个日志档案。
|
||||
|
||||
You can set the log level with the `--log-level` command-line option to get more detailed debug information. For example, `opencode --log-level DEBUG`.
|
||||
|
||||
---
|
||||
|
||||
## 貯存
|
||||
|
||||
opencode程序将会话数据和其他应用程序数据存储在磁碟上:
|
||||
|
||||
- **macOS/Linux**: `~/.local/share/opencode/`
|
||||
- **Windows**: Press `WIN+R` and paste `%USERPROFILE%\.local\share\opencode`
|
||||
|
||||
該目錄包含:
|
||||
|
||||
- `auth.json` - 身份验证资料,例如API金密钥、OAuth令牌
|
||||
- `log/` - 应用日志
|
||||
- `project/` - 专案特定数据,例如会话和消息数据
|
||||
- 如果專案位於 Git 儲存庫中,則它儲存在 `./<project-slug>/storage/` 中
|
||||
- 如果不是 Git 存储库,则存储在 `./global/storage/` 中
|
||||
|
||||
---
|
||||
|
||||
## 桌面應用程式
|
||||
|
||||
OpenCode Desktop runs a local OpenCode server (the `opencode-cli` sidecar) in the background. Most issues are caused by a misbehaving plugin, a corrupted cache, or a bad server setting.
|
||||
|
||||
### 快速檢查
|
||||
|
||||
- 完全退出並重新啟動應用程式。
|
||||
- 如果應用程式顯示錯誤螢幕,請單擊“**重新啟動**”並複制錯誤詳細資訊。
|
||||
- macOS only: `OpenCode` menu -> **Reload Webview** (helps if the UI is blank/frozen).
|
||||
|
||||
---
|
||||
|
||||
### 禁用外掛
|
||||
|
||||
如果桌面應用程式在啟動時崩潰、掛起或行為異常,請首先禁用外掛。
|
||||
|
||||
#### 檢查全域性配置
|
||||
|
||||
开启全域性文件并查询`plugin`键。
|
||||
|
||||
- **macOS/Linux**: `~/.config/opencode/opencode.jsonc` (or `~/.config/opencode/opencode.json`)
|
||||
- **macOS/Linux** (older installs): `~/.local/share/opencode/opencode.jsonc`
|
||||
- **Windows**: Press `WIN+R` and paste `%USERPROFILE%\.config\opencode\opencode.jsonc`
|
||||
|
||||
如果您配置了外掛,請透過刪除金鑰或將其設定為空陣列來暫時禁用它們:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"plugin": [],
|
||||
}
|
||||
```
|
||||
|
||||
#### 檢查外掛目錄
|
||||
|
||||
OpenCode 还可以从磁碟加载本地外挂。暂时将它们移开(或重新命名资料夹)并重新启动桌面应用程序:
|
||||
|
||||
- **全域性外掛**
|
||||
- **macOS/Linux**: `~/.config/opencode/plugins/`
|
||||
- **Windows**: Press `WIN+R` and paste `%USERPROFILE%\.config\opencode\plugins`
|
||||
- **專案外掛**(僅當您使用每個專案配置時)
|
||||
- `<your-project>/.opencode/plugins/`
|
||||
|
||||
如果應用程式再次開始工作,請一次重新啟用一個外掛,以找出導致問題的外掛。
|
||||
|
||||
---
|
||||
|
||||
### 清除快取
|
||||
|
||||
如果取消外挂没有帮助(或者外挂安装被卡住),请清除快取,方便OpenCode可以重建它。
|
||||
|
||||
1. 完全退出 OpenCode 桌面。
|
||||
2. 刪除快取目錄:
|
||||
|
||||
- **macOS**: Finder -> `Cmd+Shift+G` -> paste `~/.cache/opencode`
|
||||
- **Linux**: delete `~/.cache/opencode` (or run `rm -rf ~/.cache/opencode`)
|
||||
- **Windows**: Press `WIN+R` and paste `%USERPROFILE%\.cache\opencode`
|
||||
|
||||
3. 重新启动 OpenCode 桌面。
|
||||
|
||||
---
|
||||
|
||||
### 修復伺服器連線問題
|
||||
|
||||
OpenCode Desktop 可以启动自己的本地服务器(默认配置)或连线到您的服务器 URL。
|
||||
|
||||
如果您看到**“连线失败”**对话中断(或者应用程序永远无法穿透启动萤幕),请检查自定义服务器URL。
|
||||
|
||||
#### 清除桌面桌面服务器 URL
|
||||
|
||||
在主螢幕中,單擊伺服器名稱(帶有狀態點)以開啟伺服器選擇器。在“**預設伺服器**”部分中,單擊“**清除**”。
|
||||
|
||||
#### 从配置中删除 `server.port` / `server.hostname`
|
||||
|
||||
If your `opencode.json(c)` contains a `server` section, temporarily remove it and restart the desktop app.
|
||||
|
||||
#### 檢查環境變數
|
||||
|
||||
如果您在环境中设置了 `OPENCODE_PORT`,桌面应用程序将尝试将交换机用于本地服务器。
|
||||
|
||||
- 取消设置`OPENCODE_PORT`(或选择一个休闲摊)并重新启动。
|
||||
|
||||
---
|
||||
|
||||
### Linux:Wayland / X11 问题
|
||||
|
||||
在 Linux 上,某些 Wayland 设置可能会导致空白视窗或合成器错误。
|
||||
|
||||
- 如果您在 Wayland 程序上并且应用的是 blank/crashing,请尝试使用 `OC_ALLOW_WAYLAND=1` 启动。
|
||||
- 如果这让事情变得更糟糕,请完成其删除并尝试在 X11 会话下启动。
|
||||
|
||||
---
|
||||
|
||||
### Windows:WebView2执行时
|
||||
|
||||
在 Windows 上,OpenCode 桌面需要 Microsoft Edge **WebView2 执行时**。如果应用程序打开为空白视窗或无法启动,请 install/update WebView2 并重试。
|
||||
|
||||
---
|
||||
|
||||
### Windows:一般问题
|
||||
|
||||
If you're experiencing slow performance, file access issues, or terminal problems on Windows, try using [WSL (Windows Subsystem for Linux)](/docs/windows-wsl). WSL provides a Linux environment that works more seamlessly with OpenCode's features.
|
||||
|
||||
---
|
||||
|
||||
### 通知不顯示
|
||||
|
||||
OpenCode 桌面仅在以下情况下显示系统通知:
|
||||
|
||||
- 在您的作业系统中设置为 OpenCode 启用了通知,并且
|
||||
- 應用程式視窗未聚焦。
|
||||
|
||||
---
|
||||
|
||||
### 重置桌面應用程式儲存(最後的手段)
|
||||
|
||||
如果应用程序无法并且启动您无法从 UI 内部清除设置,请重置桌面应用程序的存储状态。
|
||||
|
||||
1. 退出 OpenCode 桌面。
|
||||
2. 查询并删除这些文件(它们位于 OpenCode 桌面应用程序数据目录中):
|
||||
|
||||
- `opencode.settings.dat` (desktop default server URL)
|
||||
- `opencode.global.dat` and `opencode.workspace.*.dat` (UI state like recent servers/projects)
|
||||
|
||||
快速找到目錄:
|
||||
|
||||
- **macOS**:Finder -> `Cmd+Shift+G` -> `~/Library/Application Support`(然后搜索上面的档名)
|
||||
- **Linux**:在`~/.local/share`下搜索上述档名
|
||||
- **Windows**:按 `WIN+R` -> `%APPDATA%` (然后搜索上面的档名)
|
||||
|
||||
---
|
||||
|
||||
## 尋求幫助
|
||||
|
||||
如果您遇到 OpenCode 问题:
|
||||
|
||||
1. **报告 GitHub** 上的问题
|
||||
|
||||
报告错误或请求功能的最佳方式是利用我们的 GitHub 存储库:
|
||||
|
||||
[**github.com/anomalyco/opencode/issues**](https://github.com/anomalyco/opencode/issues)
|
||||
|
||||
在建立新問題之前,請搜尋現有問題以檢視您的問題是否已被報告。
|
||||
|
||||
2. **加入我們的不和諧**
|
||||
|
||||
获得实时帮助和社群讨论,请加入我们的Discord服务器:
|
||||
|
||||
[**opencode.ai/discord**](https://opencode.ai/discord)
|
||||
|
||||
---
|
||||
|
||||
## 常見問題
|
||||
|
||||
以下是一些常見問題以及解決方法。
|
||||
|
||||
---
|
||||
|
||||
### OpenCode 无法启动
|
||||
|
||||
1. 檢查日誌中是否有錯誤訊息
|
||||
2. 尝试使用 `--print-logs` 执行以检视终端中的输出
|
||||
3. Ensure you have the latest version with `opencode upgrade`
|
||||
|
||||
---
|
||||
|
||||
### 身份驗證問題
|
||||
|
||||
1. 尝试使用 TUI 中的 `/connect` 命令重新进行身份验证
|
||||
2. 检查您的API金钥匙是否有效
|
||||
3. 保证您的网路允许连线到达辉煌的API
|
||||
|
||||
---
|
||||
|
||||
### 型號不可用
|
||||
|
||||
1. 檢查您是否已透過提供商的身份驗證
|
||||
2. 驗證配置中的型號名稱是否正確
|
||||
3. 某些型號可能需要特定的訪問許可權或訂閱
|
||||
|
||||
如果您遇到 `ProviderModelNotFoundError` 您很可能是错误的
|
||||
在某處引用模型。
|
||||
模型應該像這樣引用:`<providerId>/<modelId>`
|
||||
|
||||
示例:
|
||||
|
||||
- `openai/gpt-4.1`
|
||||
- `openrouter/google/gemini-2.5-flash`
|
||||
- `opencode/kimi-k2`
|
||||
|
||||
To figure out what models you have access to, run `opencode models`
|
||||
|
||||
---
|
||||
|
||||
### 提供者初始化錯誤
|
||||
|
||||
如果遇到 ProviderInitError,您的配置可能无效或损坏。
|
||||
|
||||
要解決這個問題:
|
||||
|
||||
1. 首先,按照[提供商指南](/docs/providers) 验证您的事业是否已正确设置
|
||||
2. 如果問題仍然存在,請嘗試清除儲存的配置:
|
||||
|
||||
```bash
|
||||
rm -rf ~/.local/share/opencode
|
||||
```
|
||||
|
||||
On Windows, press `WIN+R` and delete: `%USERPROFILE%\.local\share\opencode`
|
||||
|
||||
3. 使用 TUI 中的 `/connect` 命令指示您的企业重新进行身份验证。
|
||||
|
||||
---
|
||||
|
||||
### AI_API_CallError 和提供程序包问题
|
||||
|
||||
如果您遇到 API 呼叫错误,这可能是由于过去提供程序包造成的。 opencode 根据需要动态安装提供程序包(OpenAI、Anthropic、Google 等)将其快取放在本地。
|
||||
|
||||
要解決提供程式包問題:
|
||||
|
||||
1. 清除提供程式包快取:
|
||||
|
||||
```bash
|
||||
rm -rf ~/.cache/opencode
|
||||
```
|
||||
|
||||
On Windows, press `WIN+R` and delete: `%USERPROFILE%\.cache\opencode`
|
||||
|
||||
2. 重新启动 opencode 以重新安装最新的提供程序包
|
||||
|
||||
这将需要 opencode 下载最新版本的提供程序包,这通常可以解决模型引数和 API 更改的相容性问题。
|
||||
|
||||
---
|
||||
|
||||
### 複製/paste 不适用 Linux
|
||||
|
||||
Linux 用户需要安装以下剪贴簿实用程序之一才能使 copy/paste 功能正常工作:
|
||||
|
||||
**对于X11系统:**
|
||||
|
||||
```bash
|
||||
apt install -y xclip
|
||||
# or
|
||||
apt install -y xsel
|
||||
```
|
||||
|
||||
** 对于 Wayland 系统:**
|
||||
|
||||
```bash
|
||||
apt install -y wl-clipboard
|
||||
```
|
||||
|
||||
**對於無頭環境:**
|
||||
|
||||
```bash
|
||||
apt install -y xvfb
|
||||
# and run:
|
||||
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
|
||||
export DISPLAY=:99.0
|
||||
```
|
||||
|
||||
opencode 将检测您是否正在使用 Wayland 并更喜欢 `wl-clipboard`,否则将尝试按以下顺序剪贴簿工具:`xclip` 和 `xsel`。
|
||||
390
packages/web/src/content/docs/zh-cn/tui.mdx
Normal file
390
packages/web/src/content/docs/zh-cn/tui.mdx
Normal file
@@ -0,0 +1,390 @@
|
||||
---
|
||||
title: TUI
|
||||
description: 使用 OpenCode 终端用户界面。
|
||||
---
|
||||
|
||||
import { Tabs, TabItem } from "@astrojs/starlight/components"
|
||||
|
||||
OpenCode 提供交互式终端介面或 TUI,以便使用 LLM 处理您的专案。
|
||||
|
||||
执行OpenCode启动当前目录的TUI。
|
||||
|
||||
```bash
|
||||
opencode
|
||||
```
|
||||
|
||||
或者您可以為特定的工作目錄啟動它。
|
||||
|
||||
```bash
|
||||
opencode /path/to/project
|
||||
```
|
||||
|
||||
进入TUI后,您可以查看消息进行提示。
|
||||
|
||||
```text
|
||||
Give me a quick summary of the codebase.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 檔案參考
|
||||
|
||||
您可以使用 `@` 在訊息中引用檔案。這會在當前工作目錄中進行模糊檔案搜尋。
|
||||
|
||||
:::提示
|
||||
您還可以使用 `@` 來引用訊息中的檔案。
|
||||
:::
|
||||
|
||||
```text "@packages/functions/src/api/index.ts"
|
||||
How is auth handled in @packages/functions/src/api/index.ts?
|
||||
```
|
||||
|
||||
檔案的內容會自動新增到對話中。
|
||||
|
||||
---
|
||||
|
||||
## bash 命令
|
||||
|
||||
以`!`开始一条消息以执行shell命令。
|
||||
|
||||
```bash frame="none"
|
||||
!ls -la
|
||||
```
|
||||
|
||||
命令的輸出將作為工具結果新增到對話中。
|
||||
|
||||
---
|
||||
|
||||
## 命令
|
||||
|
||||
使用 OpenCode TUI 时,您可以输入 `/` 后跟命令名称来快速执行操作。例如:
|
||||
|
||||
```bash frame="none"
|
||||
/help
|
||||
```
|
||||
|
||||
大多数命令还是以使用 `ctrl+x` 作为主键的键系结,其中 `ctrl+x` 是默认主键。 [了解更多](/docs/keybinds)。
|
||||
|
||||
以下是所有可用的斜槓命令:
|
||||
|
||||
---
|
||||
|
||||
### 連線
|
||||
|
||||
将新增到 OpenCode。允许您从可用的成功中进行选择并新增他们的 API 重要。
|
||||
|
||||
```bash frame="none"
|
||||
/connect
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 袖珍的
|
||||
|
||||
压缩当前会话。_别名_: `/summarize`
|
||||
|
||||
```bash frame="none"
|
||||
/compact
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x c`
|
||||
|
||||
---
|
||||
|
||||
### 細節
|
||||
|
||||
切換工具執行詳細資訊。
|
||||
|
||||
```bash frame="none"
|
||||
/details
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x d`
|
||||
|
||||
---
|
||||
|
||||
### 編輯
|
||||
|
||||
开启外部编辑器来编写消息。使用`EDITOR`环境变量中设定的编辑器。 [了解更多](#editor-setup)。
|
||||
|
||||
```bash frame="none"
|
||||
/editor
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x e`
|
||||
|
||||
---
|
||||
|
||||
### 出口
|
||||
|
||||
退出OpenCode。 _别名_:`/quit`、`/q`
|
||||
|
||||
```bash frame="none"
|
||||
/exit
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x q`
|
||||
|
||||
---
|
||||
|
||||
### 出口
|
||||
|
||||
将当前对话汇出到 Markdown 并在默认编辑器中开启。使用 `EDITOR` 环境变数中设定的编辑器。 [了解更多](#editor-setup)。
|
||||
|
||||
```bash frame="none"
|
||||
/export
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x x`
|
||||
|
||||
---
|
||||
|
||||
### 幫助
|
||||
|
||||
顯示幫助對話方塊。
|
||||
|
||||
```bash frame="none"
|
||||
/help
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x h`
|
||||
|
||||
---
|
||||
|
||||
### 初始化
|
||||
|
||||
Create or update `AGENTS.md` file. [Learn more](/docs/rules).
|
||||
|
||||
```bash frame="none"
|
||||
/init
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x i`
|
||||
|
||||
---
|
||||
|
||||
### 型號
|
||||
|
||||
列出可用型號。
|
||||
|
||||
```bash frame="none"
|
||||
/models
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x m`
|
||||
|
||||
---
|
||||
|
||||
### 新的
|
||||
|
||||
开始新的会话。 _别名_: `/clear`
|
||||
|
||||
```bash frame="none"
|
||||
/new
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x n`
|
||||
|
||||
---
|
||||
|
||||
### 重做
|
||||
|
||||
删除之前重做消除的讯息。仅在使用`/undo`后可用。
|
||||
|
||||
:::提示
|
||||
任何檔案更改也將被恢復。
|
||||
:::
|
||||
|
||||
在内部,这使用 Git 来管理文件更改。所以你的专案**需要
|
||||
是一个Git存储库**。
|
||||
|
||||
```bash frame="none"
|
||||
/redo
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x r`
|
||||
|
||||
---
|
||||
|
||||
### 會議
|
||||
|
||||
上市会话并在会话之间切换。 _别名_:`/resume`、`/continue`
|
||||
|
||||
```bash frame="none"
|
||||
/sessions
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x l`
|
||||
|
||||
---
|
||||
|
||||
### 分享
|
||||
|
||||
共享当前会话。 [了解更多](/docs/share)。
|
||||
|
||||
```bash frame="none"
|
||||
/share
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x s`
|
||||
|
||||
---
|
||||
|
||||
### 主題
|
||||
|
||||
列出可用的主題。
|
||||
|
||||
```bash frame="none"
|
||||
/theme
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x t`
|
||||
|
||||
---
|
||||
|
||||
### 思維
|
||||
|
||||
切换对话中 thinking/reasoning 块的可视性。启用后,您可以看到支持增强套件思维的模型的推理过程。
|
||||
|
||||
:::笔记
|
||||
该命令仅控制是否**显示** - 不启用或取消模型的推理功能。要切换实际推理功能,请使用 `ctrl+t` 回圈切换模型变体。
|
||||
:::
|
||||
|
||||
```bash frame="none"
|
||||
/thinking
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### 撤消
|
||||
|
||||
撤消對話中的最後一條訊息。刪除最近的使用者訊息、所有後續響應以及任何檔案更改。
|
||||
|
||||
:::提示
|
||||
所做的任何檔案更改也將被恢復。
|
||||
:::
|
||||
|
||||
在内部,这使用 Git 来管理文件更改。所以你的专案**需要
|
||||
是一个Git存储库**。
|
||||
|
||||
```bash frame="none"
|
||||
/undo
|
||||
```
|
||||
|
||||
** 按键系结:** `ctrl+x u`
|
||||
|
||||
---
|
||||
|
||||
### 取消共享
|
||||
|
||||
取消共享当前会话。 [了解更多](/docs/share#un-sharing)。
|
||||
|
||||
```bash frame="none"
|
||||
/unshare
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 編輯器設定
|
||||
|
||||
`/editor` 和 `/export` 命令都使用 `EDITOR` 环境变量中指定的编辑器。
|
||||
|
||||
<Tabs>
|
||||
<TabItem label="Linux/macOS">
|
||||
```bash
|
||||
# Example for nano or vim
|
||||
export EDITOR=nano
|
||||
export EDITOR=vim
|
||||
|
||||
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
|
||||
# include --wait
|
||||
export EDITOR="code --wait"
|
||||
```
|
||||
|
||||
要使其永久存在,请将其添加到您的 shell 配置文件中;
|
||||
`~/.bashrc`、`~/.zshrc` 等
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem label="Windows (CMD)">
|
||||
```bash
|
||||
set EDITOR=notepad
|
||||
|
||||
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
|
||||
# include --wait
|
||||
set EDITOR=code --wait
|
||||
```
|
||||
|
||||
要使其永久化,请使用 **系统属性** > **环境
|
||||
变量**。
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem label="Windows (PowerShell)">
|
||||
```powershell
|
||||
$env:EDITOR = "notepad"
|
||||
|
||||
# For GUI editors, VS Code, Cursor, VSCodium, Windsurf, Zed, etc.
|
||||
# include --wait
|
||||
$env:EDITOR = "code --wait"
|
||||
```
|
||||
|
||||
要使其永久化,请将其添加到您的 PowerShell 配置文件中。
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
流行的編輯器選項包括:
|
||||
|
||||
- `code` - Visual Studio 程序代码
|
||||
- `cursor` - 游标
|
||||
- `windsurf` - 风帆冲浪
|
||||
- `nvim` - Neo 的编辑器
|
||||
- `vim` - Vim 编辑器
|
||||
- `nano` - 奈米编辑器
|
||||
- `notepad` - Windows 文章书
|
||||
- `subl` - 崇高文字
|
||||
|
||||
:::笔记
|
||||
一些编辑器如 VS Code 需要以 `--wait` 标志启动。
|
||||
:::
|
||||
|
||||
某些编辑器需要命令列引数才能在阻止模式下执行。 `--wait` 标志使编辑器程序阻塞直至关闭。
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以使用 OpenCode 配置文件自定义 TUI 行为。
|
||||
|
||||
```json title="opencode.json"
|
||||
{
|
||||
"$schema": "https://opencode.ai/config.json",
|
||||
"tui": {
|
||||
"scroll_speed": 3,
|
||||
"scroll_acceleration": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 選項
|
||||
|
||||
- `scroll_acceleration` - 启用 macOS 式滚动加速以实现平滑、自然的滚动。启用后,滚动速度会随着快速滚动滚动而增加,并在较慢的移动时保持精确。 **此设定优先于 `scroll_speed` 并在启用时覆盖它。 **
|
||||
- `scroll_speed` - 控制使用滚动控制器时 TUI 滚动的速度(简单:`1`)。默认为 `3`。 **注意:如果 `scroll_acceleration.enabled` 设置为 `true`,则忽略此设置。 **
|
||||
|
||||
---
|
||||
|
||||
## 定製化
|
||||
|
||||
您可以使用命令选项板(`ctrl+x h` 或 `/help`)自定义 TUI 检视的各个方面。这些设置在重新启动后仍然存在。
|
||||
|
||||
---
|
||||
|
||||
#### 使用者名稱顯示
|
||||
|
||||
切換您的使用者名稱是否出現在聊天訊息中。透過以下方式訪問:
|
||||
|
||||
- 命令面板:搜尋“使用者名稱”或“隱藏使用者名稱”
|
||||
- 该设置会自动保留,放在 TUI 会话中被记住
|
||||
142
packages/web/src/content/docs/zh-cn/web.mdx
Normal file
142
packages/web/src/content/docs/zh-cn/web.mdx
Normal file
@@ -0,0 +1,142 @@
|
||||
---
|
||||
title: 網路
|
||||
description: 在浏览器中使用OpenCode。
|
||||
---
|
||||
|
||||
OpenCode 可以在浏览器中作为 Web 应用程序执行,消耗终端可以提供同样强大的 AI 编码体验。
|
||||
|
||||

|
||||
|
||||
## 入門
|
||||
|
||||
绕过执行以下命令启动 Web 简介:
|
||||
|
||||
```bash
|
||||
opencode web
|
||||
```
|
||||
|
||||
这将在 `127.0.0.1` 上启动一个具有随机可用端口的本地服务器,并自动在默认浏览器中开启 OpenCode。
|
||||
|
||||
:::警告
|
||||
如果未设置`OPENCODE_SERVER_PASSWORD`,服务器将不安全。这对于本地使用来说很好,但应该针对网路访问进行设置。
|
||||
:::
|
||||
|
||||
:::tip[Windows 使用者]
|
||||
For the best experience, run `opencode web` from [WSL](/docs/windows-wsl) rather than PowerShell. This ensures proper file system access and terminal integration.
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 配置
|
||||
|
||||
您可以使用命令列标志或在[config file](/docs/config).conf 中配置Web服务器。
|
||||
|
||||
### 港口
|
||||
|
||||
默认情况下,OpenCode 选择一个可用的端口。您可以指定一个端口:
|
||||
|
||||
```bash
|
||||
opencode web --port 4096
|
||||
```
|
||||
|
||||
### 主機名
|
||||
|
||||
情况默认下,服务器系结到`127.0.0.1`(仅限本地主机)。要使OpenCode在您的网路上可访问:
|
||||
|
||||
```bash
|
||||
opencode web --hostname 0.0.0.0
|
||||
```
|
||||
|
||||
使用`0.0.0.0`时,OpenCode将显示本地地址和网络地址:
|
||||
|
||||
```
|
||||
Local access: http://localhost:4096
|
||||
Network access: http://192.168.1.100:4096
|
||||
```
|
||||
|
||||
### mDNS 发现
|
||||
|
||||
启用 mDNS 使您的服务器在本地网上可以发现:
|
||||
|
||||
```bash
|
||||
opencode web --mdns
|
||||
```
|
||||
|
||||
This automatically sets the hostname to `0.0.0.0` and advertises the server as `opencode.local`.
|
||||
|
||||
您可以自定义 mDNS 域名以在同一网路上执行多个示例:
|
||||
|
||||
```bash
|
||||
opencode web --mdns --mdns-domain myproject.local
|
||||
```
|
||||
|
||||
### CORS
|
||||
|
||||
允许CORS使用其他域(对于自定义前缀有用):
|
||||
|
||||
```bash
|
||||
opencode web --cors https://example.com
|
||||
```
|
||||
|
||||
### 驗證
|
||||
|
||||
要保护访问,请使用 `OPENCODE_SERVER_PASSWORD` 环境变数设置密码:
|
||||
|
||||
```bash
|
||||
OPENCODE_SERVER_PASSWORD=secret opencode web
|
||||
```
|
||||
|
||||
The username defaults to `opencode` but can be changed with `OPENCODE_SERVER_USERNAME`.
|
||||
|
||||
---
|
||||
|
||||
## 使用網路介面
|
||||
|
||||
启动后,网路界面将提供对您的 OpenCode 会话的访问。
|
||||
|
||||
### 會議
|
||||
|
||||
從主頁檢視和管理您的會話。您可以檢視活動會話並開始新會話。
|
||||
|
||||

|
||||
|
||||
### 伺服器狀態
|
||||
|
||||
單擊“檢視伺服器”可檢視連線的伺服器及其狀態。
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 連線終端
|
||||
|
||||
您可以将终端 TUI 连线到正在执行的 Web 服务器:
|
||||
|
||||
```bash
|
||||
# Start the web server
|
||||
opencode web --port 4096
|
||||
|
||||
# In another terminal, attach the TUI
|
||||
opencode attach http://localhost:4096
|
||||
```
|
||||
|
||||
这允许您同时使用 Web 界面和终端,共享相同的会话和状态。
|
||||
|
||||
---
|
||||
|
||||
## 配置檔案
|
||||
|
||||
You can also configure server settings in your `opencode.json` config file:
|
||||
|
||||
```json
|
||||
{
|
||||
"server": {
|
||||
"port": 4096,
|
||||
"hostname": "0.0.0.0",
|
||||
"mdns": true,
|
||||
"cors": ["https://example.com"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
命令列標誌優先於配置檔案設定。
|
||||
113
packages/web/src/content/docs/zh-cn/windows-wsl.mdx
Normal file
113
packages/web/src/content/docs/zh-cn/windows-wsl.mdx
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: Windows (WSL)
|
||||
description: 在 Windows 上通过 WSL 使用 OpenCode。
|
||||
---
|
||||
|
||||
import { Steps } from "@astrojs/starlight/components"
|
||||
|
||||
虽然 OpenCode 可以直接在 Windows 上运行,但为了获得最佳体验,我们推荐使用 [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install)。WSL 提供了一个与 OpenCode 功能无缝协作的 Linux 环境。
|
||||
|
||||
:::tip[为什么使用 WSL?]
|
||||
WSL 提供更好的文件系统性能、完整的终端支持,以及与 OpenCode 依赖的开发工具的兼容性。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 设置
|
||||
|
||||
<Steps>
|
||||
|
||||
1. **安装 WSL**
|
||||
|
||||
如果你还没有安装,请按照 Microsoft 官方指南 [安装 WSL](https://learn.microsoft.com/en-us/windows/wsl/install)。
|
||||
|
||||
2. **在 WSL 中安装 OpenCode**
|
||||
|
||||
完成 WSL 设置后,打开 WSL 终端并使用任一[安装方式](/docs/)安装 OpenCode。
|
||||
|
||||
```bash
|
||||
curl -fsSL https://opencode.ai/install | bash
|
||||
```
|
||||
|
||||
3. **从 WSL 使用 OpenCode**
|
||||
|
||||
进入你的项目目录(可通过 `/mnt/c/`、`/mnt/d/` 等访问 Windows 文件)并运行 OpenCode。
|
||||
|
||||
```bash
|
||||
cd /mnt/c/Users/YourName/project
|
||||
opencode
|
||||
```
|
||||
|
||||
</Steps>
|
||||
|
||||
---
|
||||
|
||||
## 桌面应用 + WSL 服务器
|
||||
|
||||
如果你想使用 OpenCode 桌面应用,但希望在 WSL 中运行服务器:
|
||||
|
||||
1. **在 WSL 中启动服务器**,并使用 `--hostname 0.0.0.0` 以允许外部连接:
|
||||
|
||||
```bash
|
||||
opencode serve --hostname 0.0.0.0 --port 4096
|
||||
```
|
||||
|
||||
2. **将桌面应用连接到** `http://localhost:4096`
|
||||
|
||||
:::note
|
||||
如果你的环境中 `localhost` 不可用,请改用 WSL 的 IP 地址连接(在 WSL 中执行:`hostname -I`),并使用 `http://<wsl-ip>:4096`。
|
||||
:::
|
||||
|
||||
:::caution
|
||||
使用 `--hostname 0.0.0.0` 时,请设置 `OPENCODE_SERVER_PASSWORD` 来保护服务器。
|
||||
|
||||
```bash
|
||||
OPENCODE_SERVER_PASSWORD=your-password opencode serve --hostname 0.0.0.0
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## Web 客户端 + WSL
|
||||
|
||||
在 Windows 上获得最佳 Web 体验:
|
||||
|
||||
1. **请在 WSL 终端中运行 `opencode web`**,而不是在 PowerShell 中运行:
|
||||
|
||||
```bash
|
||||
opencode web --hostname 0.0.0.0
|
||||
```
|
||||
|
||||
2. **在 Windows 浏览器中访问** `http://localhost:<port>`(OpenCode 会打印该 URL)
|
||||
|
||||
从 WSL 运行 `opencode web` 可以确保正确的文件系统访问和终端集成,同时仍可在 Windows 浏览器中访问。
|
||||
|
||||
---
|
||||
|
||||
## 访问 Windows 文件
|
||||
|
||||
WSL 可以通过 `/mnt/` 目录访问你所有的 Windows 文件:
|
||||
|
||||
- `C:` drive → `/mnt/c/`
|
||||
- `D:` drive → `/mnt/d/`
|
||||
- 其他盘符同理
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
cd /mnt/c/Users/YourName/Documents/project
|
||||
opencode
|
||||
```
|
||||
|
||||
:::tip
|
||||
为了获得更流畅的体验,建议将仓库克隆或复制到 WSL 文件系统中(例如 `~/code/`),并在那里运行 OpenCode。
|
||||
:::
|
||||
|
||||
---
|
||||
|
||||
## 提示
|
||||
|
||||
- 即使项目存放在 Windows 盘符中,也建议在 WSL 中运行 OpenCode,文件访问会更顺畅
|
||||
- 可将 OpenCode 与 VS Code 的 [WSL 扩展](https://code.visualstudio.com/docs/remote/wsl)配合使用,形成一体化开发流程
|
||||
- OpenCode 的配置和会话会保存在 WSL 环境中的 `~/.local/share/opencode/`
|
||||
254
packages/web/src/content/docs/zh-cn/zen.mdx
Normal file
254
packages/web/src/content/docs/zh-cn/zen.mdx
Normal file
@@ -0,0 +1,254 @@
|
||||
---
|
||||
title: 禪
|
||||
description: 由 OpenCode 提供的精选模型列表。
|
||||
---
|
||||
|
||||
import config from "../../../../config.mjs"
|
||||
export const console = config.console
|
||||
export const email = `mailto:${config.email}`
|
||||
|
||||
Error 500 (Server Error)!!1500.That’s an error.There was an error. Please try again later.That’s all we know.
|
||||
|
||||
:::笔记
|
||||
OpenCode Zen 目前处于一个测试阶段。
|
||||
:::
|
||||
|
||||
Zen 的工作方式与 OpenCode 中的任何其他提供程序相同。您登入 OpenCode Zen 并获得
|
||||
你的API钥匙。它是**完全可选的**,你不需要使用它即可使用
|
||||
开放代码。
|
||||
|
||||
---
|
||||
|
||||
## 背景
|
||||
|
||||
市面上有很多型號,但其中只有少數幾個
|
||||
這些模型可以很好地用作編碼代理。此外,大多數提供商都
|
||||
配置非常不同;所以你會得到截然不同的效能和質量。
|
||||
|
||||
:::提示
|
||||
我们测试了一组与 OpenCode 配合良好的模型并提供方案。
|
||||
:::
|
||||
|
||||
因此,如果您使用 OpenRouter 之类的东西使用模型,您永远无法
|
||||
確定您是否獲得了您想要的模型的最佳版本。
|
||||
|
||||
為瞭解決這個問題,我們做了幾件事:
|
||||
|
||||
1. 我們測試了一組選定的模型,並與他們的團隊討論瞭如何
|
||||
最好執行它們。
|
||||
2. 然後我們與一些提供商合作以確保這些服務得到服務
|
||||
正確。
|
||||
3. 最后,我们对 model/provider 的组合进行了基准测试,总结了
|
||||
並附上一份我們覺得不錯的推薦清單。
|
||||
|
||||
OpenCode Zen 是一个AI闸道器,可以让您访问这些模型。
|
||||
|
||||
---
|
||||
|
||||
## 它是如何運作的
|
||||
|
||||
OpenCode Zen 的工作方式与 OpenCode 中的任何其他功能相同。
|
||||
|
||||
1. 您登入 **<a href={console}>OpenCode Zen</a>**,新增您的帳單
|
||||
详细资讯,然后复制您的 API 金钥匙。
|
||||
2. 您在 TUI 中执行 `/connect` 命令,选择 OpenCode Zen,然后贴上 API 金钥匙。
|
||||
3. 在 TUI 中执行 `/models` 以检视我们推荐的型号列表。
|
||||
|
||||
您需要按請求付費,並且您可以將積分新增到您的帳戶中。
|
||||
|
||||
---
|
||||
|
||||
## 端點
|
||||
|
||||
您还可以通过以下 API 端点访问我们的模型。
|
||||
|
||||
|型号|型号ID |端点 |人工智慧SDK包|
|
||||
| ------------------ | ------------------ | -------------------------------------------------- | --------------------------- |
|
||||
| GPT 5.2 | gpt-5.2 | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5.2 Codex | gpt-5.2-codex | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5.1 | gpt-5.1 | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5.1 Codex | gpt-5.1-codex | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5.1 Codex Max | gpt-5.1-codex-max | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5.1 Codex Mini | gpt-5.1-codex-mini | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5 | gpt-5 | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5 Codex | gpt-5-codex | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| GPT 5 Nano | gpt-5-nano | `https://opencode.ai/zen/v1/responses` | `@ai-sdk/openai` |
|
||||
| Claude Sonnet 4.5 | claude-sonnet-4-5 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Sonnet 4 | claude-sonnet-4 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Haiku 4.5 | claude-haiku-4-5 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Haiku 3.5 | claude-3-5-haiku | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Opus 4.6 | claude-opus-4-6 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Opus 4.5 | claude-opus-4-5 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Claude Opus 4.1 | claude-opus-4-1 | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| Gemini 3 Pro | gemini-3-pro | `https://opencode.ai/zen/v1/models/gemini-3-pro` | `@ai-sdk/google` |
|
||||
| Gemini 3 Flash | gemini-3-flash | `https://opencode.ai/zen/v1/models/gemini-3-flash` | `@ai-sdk/google` |
|
||||
| MiniMax M2.1 | minimax-m2.1 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| MiniMax M2.1 Free | minimax-m2.1-free | `https://opencode.ai/zen/v1/messages` | `@ai-sdk/anthropic` |
|
||||
| GLM 4.7 | glm-4.7 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| GLM 4.7 Free | glm-4.7-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| GLM 4.6 | glm-4.6 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Kimi K2.5 | kimi-k2.5 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Kimi K2.5 Free | kimi-k2.5-free | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Kimi K2 Thinking | kimi-k2-thinking | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Kimi K2 | kimi-k2 | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Qwen3 Coder 480B | qwen3-coder | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
| Big Pickle | big-pickle | `https://opencode.ai/zen/v1/chat/completions` | `@ai-sdk/openai-compatible` |
|
||||
|
||||
OpenCode 配置中的 [model id](/docs/config/#models)
|
||||
uses the format `opencode/<model-id>`. For example, for GPT 5.2 Codex, you would
|
||||
use `opencode/gpt-5.2-codex` in your config.
|
||||
|
||||
---
|
||||
|
||||
### 型號
|
||||
|
||||
您可以從以下位置獲取可用模型及其後設資料的完整列表:
|
||||
|
||||
```
|
||||
https://opencode.ai/zen/v1/models
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 定價
|
||||
|
||||
我們支援即用即付模式。以下是**每 100 萬代幣的價格**。
|
||||
|
||||
|型號|輸入 |輸出|快取讀取 |快取寫入|
|
||||
| --------------------------------- | ------ | ------ | ----------- | ------------ |
|
||||
|大泡菜|免費|免費|免費| - |
|
||||
| MiniMax M2.1 免费 |免费|免费|免费| - |
|
||||
|迷你最大M2.1 | 0.30 美元 | 1.20 美元 | 0.10 美元 | - |
|
||||
| GLM 4.7 免费 |免费|免费|免费| - |
|
||||
| GLM 4.7 | 0.60 美元 | 2.20 美元 | 0.10 美元 | - |
|
||||
| GLM 4.6 | 0.60 美元 | 2.20 美元 | 0.10 美元 | - |
|
||||
| Kimi K2.5 免费|免费|免费|免费| - |
|
||||
|作为K2.5| 0.60 美元 | $3.00 | 0.08 美元 | - |
|
||||
| Kimi K2 思考 | 0.40 美元 | 2.50 美元 | - | - |
|
||||
|作为K2 | 0.40 美元 | 2.50 美元 | - | - |
|
||||
| Qwen3 编码器 480B | 0.45 美元 | 1.50 美元 | - | - |
|
||||
| Claude Sonnet 4.5(≤ 200K 令牌)| $3.00 | 15.00 美元 | 0.30 美元 | 3.75 美元 |
|
||||
|克劳德十四行诗 4.5(> 200K 代币)| 6.00 美元 | 22.50 美元 | 0.60 美元 | 7.50 美元 |
|
||||
| Claude Sonnet 4(≤ 200K 令牌)| $3.00 | 15.00 美元 | 0.30 美元 | 3.75 美元 |
|
||||
| Claude Sonnet 4(> 200K 令牌)| 6.00 美元 | 22.50 美元 | 0.60 美元 | 7.50 美元 |
|
||||
| Claude 俳句 4.5 | 1.00 美元 | 5.00 美元 | 0.10 美元 | 1.25 美元 |
|
||||
| Claude 俳句 3.5 | 0.80 美元 | 4.00 美元 | 0.08 美元 | 1.00 美元 |
|
||||
|克劳德作品4.6(≤ 200K 代币)| 5.00 美元 | 25.00 美元 | 0.50 美元 | 6.25 美元 |
|
||||
| Claude Opus 4.6(> 200K 代幣)| 10.00 美元 | 37.50 美元 | 1.00 美元 | 12.50 美元 |
|
||||
| Claude 工作 4.5 | 5.00 美元 | 25.00 美元 | 0.50 美元 | 6.25 美元 |
|
||||
| Claude 工作 4.1 | 15.00 美元 | 75.00 美元 | 1.50 美元 | 18.75 美元 |
|
||||
| Gemini 3 Pro(≤20万代币)| 2.00 美元 | 12.00 美元 | 0.20 美元 | - |
|
||||
| Gemini 3 Pro(>20万代币)| 4.00 美元 | 18.00 美元 | 0.40 美元 | - |
|
||||
|双子座 3 闪光 | 0.50 美元 | $3.00 | 0.05 美元 | - |
|
||||
| GPT 5.2 | 1.75 美元 | 14.00 美元 | 0.175 美元 | - |
|
||||
| GPT 5.2 法典 | 1.75 美元 | 14.00 美元 | 0.175 美元 | - |
|
||||
| GPT 5.1 | 1.07 美元 | 8.50 美元 | 0.107 美元 | - |
|
||||
| GPT 5.1 法典 | 1.07 美元 | 8.50 美元 | 0.107 美元 | - |
|
||||
| GPT 5.1 法典最大 | 1.25 美元 | 10.00 美元 | 0.125 美元 | - |
|
||||
| GPT 5.1 迷你版 | 0.25 美元 | 2.00 美元 | 0.025 美元 | - |
|
||||
| GPT 5 | 1.07 美元 | 8.50 美元 | 0.107 美元 | - |
|
||||
| GPT 5 法典 | 1.07 美元 | 8.50 美元 | 0.107 美元 | - |
|
||||
| GPT 5 奈米 |免费|免费|免费| - |
|
||||
|
||||
您可能会在您的使用历史记录中注意到_Claude Haiku 3.5_。这是一个[低成本模型](/docs/config/#models),用于生成会话标题。
|
||||
|
||||
:::笔记
|
||||
信用卡費用按成本轉嫁(4.4% + 每筆交易 0.30 美元);除此之外我們不收取任何費用。
|
||||
:::
|
||||
|
||||
免費模型:
|
||||
|
||||
- GLM 4.7 免费版本在 OpenCode 上限时提供。团队正在利用这段时间收集反馈并改进模型。
|
||||
- Kimi K2.5 在 OpenCode 限时免费发布。团队正在利用这段时间收集反馈并改进模型。
|
||||
- MiniMax M2.1 在 OpenCode 限时免费供应。团队正在利用这段时间收集反馈并改进模型。
|
||||
- Big Pickle 是一个隐形模型,在 OpenCode 上限时免费。团队正在利用这个临时收集反馈并改进模型。
|
||||
|
||||
<a href={email}>如果您有任何疑問,請聯絡我們</a>。
|
||||
|
||||
---
|
||||
|
||||
### 自動重新載入
|
||||
|
||||
如果您的余额低于 5 美元,Zen 将自动充值 20 美元。
|
||||
|
||||
您可以更改自動充值金額。您還可以完全禁用自動重新載入。
|
||||
|
||||
---
|
||||
|
||||
### 每月限額
|
||||
|
||||
您還可以為整個工作區和每個工作區設定每月使用限制
|
||||
你的團隊成員。
|
||||
|
||||
例如,假设您将每月使用中断设置为 20 美元,Zen 将不会使用
|
||||
一个月超过 20 美元。但如果你启用了自动重新加载,Zen 可能会结束
|
||||
如果您的餘額低於 5 美元,則向您收取超過 20 美元的費用。
|
||||
|
||||
---
|
||||
|
||||
## 隱私
|
||||
|
||||
我們所有的模型都在美國託管。我們的提供商遵循零保留政策,不會將您的資料用於模型訓練,但以下情況除外:
|
||||
|
||||
- Big Pickle:在免费期间,收集可用于改进模型的数据。
|
||||
- GLM 4.7 免费:在免费期间,收集可用于改进模型的数据。
|
||||
- Kimi K2.5 免费:在免费期间,收集可用于改进模型的数据。
|
||||
- MiniMax M2.1 免费:在免费期间,收集可用于改进模型的数据。
|
||||
- OpenAI APIs: Requests are retained for 30 days in accordance with [OpenAI's Data Policies](https://platform.openai.com/docs/guides/your-data).
|
||||
- Anthropic APIs: Requests are retained for 30 days in accordance with [Anthropic's Data Policies](https://docs.anthropic.com/en/docs/claude-code/data-usage).
|
||||
|
||||
---
|
||||
|
||||
## 對於團隊
|
||||
|
||||
Zen 对团队也很有效。您可以参与第三方、角色、策划
|
||||
您的團隊使用的模型等等。
|
||||
|
||||
:::笔记
|
||||
作為測試版的一部分,工作空間目前對團隊免費。
|
||||
:::
|
||||
|
||||
作為測試版的一部分,管理工作空間目前對團隊免費。我們將會
|
||||
很快就會分享更多有關定價的細節。
|
||||
|
||||
---
|
||||
|
||||
### 角色
|
||||
|
||||
您可以邀請團隊成員到您的工作區並分配角色:
|
||||
|
||||
- **管理员**:管理模型、成员、API 金钥匙和设备
|
||||
- **成员**:仅管理自己的API 金?
|
||||
|
||||
管理員還可以為每個成員設定每月支出限額,以控製成本。
|
||||
|
||||
---
|
||||
|
||||
### 模型訪問
|
||||
|
||||
管理員可以啟用或禁用工作區的特定模型。對禁用模型發出的請求將返回錯誤。
|
||||
|
||||
這對於您想要禁用以下模型的情況很有用:
|
||||
收集資料。
|
||||
|
||||
---
|
||||
|
||||
### 帶上你自己的鑰匙
|
||||
|
||||
您可以使用自己的 OpenAI 或 Anthropic API 键,同时仍然访问 Zen 中的其他模型。
|
||||
|
||||
当您使用自己的金密钥时,令牌将由强大的直接设备组成,而不是由 Zen。
|
||||
|
||||
例如,您的组织可能已经拥有 OpenAI 或 Anthropic 的金?
|
||||
你想使用它而不是 Zen 提供的。
|
||||
|
||||
---
|
||||
|
||||
## 去寻找
|
||||
|
||||
我们建立OpenCode Zen是为了:
|
||||
|
||||
1. **基准**编码代理的最佳models/providers。
|
||||
2. 可以使用**最高質量**選項,而不是降低效能或轉向更便宜的提供商。
|
||||
3. 透過按成本價銷售來傳遞任何**價格下跌**;所以唯一的加價就是支付我們的加工費。
|
||||
4. 通过允许您将其与任何其他编码代理一起使用,**无锁定**。并且始终允许您将任何其他成功与 OpenCode 一起使用。
|
||||
Reference in New Issue
Block a user