Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 100 additions & 101 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
# Deep Code 配置
# Deep Code Configuration

## 配置层级
## Configuration Hierarchy

配置按以下优先级顺序应用(数字较小的会被数字较大的覆盖):
Configuration is applied in the following priority order (lower-numbered sources are overridden by higher-numbered ones):

| 层级 | 配置来源 | 说明 |
| ---- | ------------ | ------------------------------------------- |
| 1 | 默认值 | 应用程序内硬编码的默认值 |
| 2 | 用户设置文件 | 当前用户的全局设置 |
| 3 | 项目设置文件 | 项目特定的设置 |
| 4 | 环境变量 | 系统范围或会话特定的变量 |
| Layer | Configuration Source | Description |
| ----- | -------------------- | ---------------------------------------------- |
| 1 | Defaults | Hardcoded defaults within the application |
| 2 | User settings file | Global settings for the current user |
| 3 | Project settings file| Project-specific settings |
| 4 | Environment variables| System-wide or session-specific variables |

## 设置文件
## Settings File

Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两个层级的存放位置:
Deep Code uses the `settings.json` file for persistent configuration, supporting two storage locations:

| 文件类型 | 位置 | 作用范围 |
| ------------ | ---------------------------------- | ---------------------------------------------------- |
| 用户设置文件 | `~/.deepcode/settings.json` | 适用于当前用户的所有 Deep Code 会话。 |
| 项目设置文件 | `项目根目录/.deepcode/settings.json` | 仅在该特定项目中运行 Deep Code 时生效。项目设置会覆盖用户设置。 |
| File Type | Location | Scope |
| ------------------- | ----------------------------------------- | --------------------------------------------------------------------- |
| User settings file | `~/.deepcode/settings.json` | Applies to all Deep Code sessions for the current user. |
| Project settings file | `<project root>/.deepcode/settings.json` | Takes effect only when running Deep Code in that specific project. Project settings override user settings. |

### `settings.json` 中的可用设置
### Available Settings in `settings.json`

以下是 `settings.json` 支持的全部顶层字段,以及 `env` 内部支持的子字段:
The following are all the top-level fields supported in `settings.json`, along with the sub-fields inside `env`:

| 字段 | 类型 | 说明 |
| -------------------- | --------- | ------------------------------------------------------------------- |
| `env` | object | 环境变量分组(见下方子字段表) |
| `model` | string | 模型名称。优先级高于 `env.MODEL` |
| `thinkingEnabled` | boolean | 是否启用思考模式(DeepSeek V4 系列默认启用) |
| `reasoningEffort` | string | 推理强度,可选 `"high"` `"max"`(默认 `"max"` |
| `debugLogEnabled` | boolean | 是否启用调试日志输出(默认 `false` |
| `notify` | string | 任务完成通知脚本的完整路径(如 Slack 通知脚本) |
| `webSearchTool` | string | 自定义联网搜索脚本的完整路径 |
| `mcpServers` | object | MCP 服务器配置(键为服务名,值为 McpServerConfig 对象) |
| Field | Type | Description |
| ------------------ | ------- | --------------------------------------------------------------------------- |
| `env` | object | Group of environment variables (see sub-field table below) |
| `model` | string | Model name. Takes precedence over `env.MODEL` |
| `thinkingEnabled` | boolean | Whether to enable thinking mode (enabled by default for DeepSeek V4 series)|
| `reasoningEffort` | string | Reasoning intensity, either `"high"` or `"max"` (default `"max"`) |
| `debugLogEnabled` | boolean | Enable debug log output (default `false`) |
| `notify` | string | Full path to a task-completion notification script (e.g., Slack notification script) |
| `webSearchTool` | string | Full path to a custom web search script |
| `mcpServers` | object | MCP server configurations (keys are service names, values are McpServerConfig objects) |

#### `env` 子字段
#### `env` Sub-fields

| 字段 | 类型 | 说明 |
| ---------- | ------ | ------------------------------------------------------------------ |
| `MODEL` | string | 模型名称。例如 `"deepseek-v4-pro"``"deepseek-v4-flash"` |
| `BASE_URL` | string | API 请求的基础 URL。例如 `"https://api.deepseek.com"` |
| `API_KEY` | string | API 密钥 |
| `THINKING_ENABLED` | string | 是否启用思考模式 |
| `REASONING_EFFORT` | string | 推理强度 |
| `DEBUG_LOG_ENABLED` | string | 是否启用调试日志输出 |
| `<其他任意KEY>` | string | 自定义环境变量 |
| Field | Type | Description |
| ----------------- | ------ | ---------------------------------------------------------------- |
| `MODEL` | string | Model name, e.g. `"deepseek-v4-pro"`, `"deepseek-v4-flash"` |
| `BASE_URL` | string | Base URL for API requests, e.g. `"https://api.deepseek.com"` |
| `API_KEY` | string | API key |
| `THINKING_ENABLED`| string | Enable thinking mode |
| `REASONING_EFFORT`| string | Reasoning intensity |
| `DEBUG_LOG_ENABLED`| string| Enable debug log output |
| `<any other KEY>` | string | Custom environment variable |

#### `thinkingEnabled` — 思考模式
#### `thinkingEnabled` — Thinking Mode

是否启用 DeepSeek 思考模式。设置为 `true` 启用、`false` 禁用。
Whether to enable DeepSeek thinking mode. Set to `true` to enable, `false` to disable.

- 对于 `deepseek-v4-pro` `deepseek-v4-flash`,思考模式**默认启用**。
- 对于其他模型,思考模式**默认关闭**。
- For `deepseek-v4-pro` and `deepseek-v4-flash`, thinking mode is **enabled by default**.
- For other models, thinking mode is **disabled by default**.

#### `reasoningEffort` — 推理强度
#### `reasoningEffort` — Reasoning Intensity

当思考模式启用时,控制模型思考的深度:
When thinking mode is enabled, controls the depth of the model’s reasoning:

| 值 | 说明 |
| ------ | --------------------------------- |
| `max` | 最大推理深度(默认值) |
| `high` | 较高推理深度,token消耗相对较小 |
| Value | Description |
| ------ | --------------------------------------------------------- |
| `max` | Maximum reasoning depth (default) |
| `high` | Higher reasoning depth with relatively lower token usage |

#### `notify` — 任务完成通知
#### `notify` — Task Completion Notification

设置一个 Shell 脚本的完整路径。当 AI 助手完成一轮任务后,会自动执行该脚本,可用于发送通知(如 Slack 消息)。
Set a full path to a shell script. When the AI assistant finishes a round of tasks, the script is executed automatically, which can be used to send notifications (e.g., a Slack message).

```json
{
"notify": "/path/to/slack-notify.sh"
}
```

#### `webSearchTool` — 自定义联网搜索
#### `webSearchTool` — Custom Web Search

Deep Code 内置免费可用的 Web Search 工具。如果需要自定义搜索逻辑,可将 `webSearchTool` 设为一个可执行脚本的完整路径:
Deep Code has a built-in, free-to-use Web Search tool. If you need custom search logic, set `webSearchTool` to the full path of an executable script:

```json
{
"webSearchTool": "/path/to/my-search-script.sh"
}
```

脚本接收一个搜索查询参数,输出 JSON 格式的结果供 AI 使用。
The script receives a search query as an argument and outputs results in JSON format for the AI.

#### `mcpServers` — MCP 服务器
#### `mcpServers` — MCP Servers

MCPModel Context Protocol)服务器配置。值是键值对,键为服务名称,值为服务器配置对象。
Configuration for MCP (Model Context Protocol) servers. The value is a key-value pair, where the key is the service name and the value is a server configuration object.

```json
{
"mcpServers": {
"<服务名>": {
"<service name>": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
Expand All @@ -103,71 +103,70 @@ MCP(Model Context Protocol)服务器配置。值是键值对,键为服务
}
```

| McpServerConfig 字段 | 类型 | 必填 | 说明 |
| -------------------- | -------- | ---- | -------------------------------------------------------------------- |
| `command` | string | | 可执行文件路径或命令(如 `npx``node``python` |
| `args` | string[] | | 传递给命令的参数列表 |
| `env` | object | | 传递给 MCP 服务器进程的环境变量 |
| McpServerConfig field | Type | Required | Description |
| --------------------- | -------- | -------- | ------------------------------------------------------------------------ |
| `command` | string | Yes | Executable path or command (e.g. `npx`, `node`, `python`) |
| `args` | string[] | No | List of arguments passed to the command |
| `env` | object | No | Environment variables passed to the MCP server process |

> `command` `npx` 时,Deep Code 会自动在参数前补充 `-y`
> When `command` is `npx`, Deep Code automatically prepends `-y` to the arguments.

详细 MCP 使用说明请参考 [mcp.md](mcp.md)
For detailed MCP usage instructions, refer to [mcp.md](mcp.md).

#### `debugLogEnabled` — Debug Log

#### `debugLogEnabled` — 调试日志
Set to `true` to enable detailed debug logging (default `false`), useful for troubleshooting API calls and tool execution.

设为 `true` 可让程序输出详细的调试日志(默认 `false`),用于排查 API 调用和工具执行的问题。
## Environment Variable Priority

## 环境变量优先级
Environment variables are a common way to configure applications, especially for sensitive information (such as api-key) or settings that may change between environments.

环境变量是配置应用程序的常用方式,尤其适用于敏感信息(如 api-key)或可能在不同环境之间更改的设置。
### Priority Principle

### 优先级原则
Environment variable priority follows the logic of “the more specific and localized the configuration, the higher the priority”, and the override rule of “env files protect existing environment by default, system variables override env files”. (The `env` object in settings.json can be thought of as a type of env file.)

环境变量优先级遵循“越具体、越局部的配置,优先级越高”和“env文件默认保护现有环境,系统变量高于env文件”的覆盖逻辑。(settings.json的env对象可以认为是一种env文件)
Priority levels (from lowest to highest):
1. `env` defined at the top level of `settings.json` – this is a general configuration for the entire tool and all its subprocesses (global variables). Can be overridden by outer environment variables, but the environment variable KEY has the `DEEPCODE_` prefix removed.
2. `env` defined inside `mcpServers` in `settings.json` – this is the most specific configuration for a particular MCP service (local variables). Can be overridden by outer environment variables, but the KEY has the `MCP_` prefix removed.
3. Shell/system environment variables – operating system level.

优先级层级 (由低到高)
1. settings.json 外层的 env:这是针对整个工具及其所有子进程的通用配置(全局变量)。可被外层环境变量覆盖,但环境变量KEY会移除`DEEPCODE_`前缀。
2. settings.json mcpServers 内定义的 env:这是针对特定 MCP 服务的最具体配置(局部变量)。可被外层环境变量覆盖,但环境变量KEY会移除`MCP_`前缀。
3. Shell 环境系统变量:操作系统层面的环境变量。
### Scenarios

### 场景
#### 1. Setting the model’s api_key and base_url

#### 一、设置模型的api_key, base_url
Applied in the following priority order (lower-numbered sources are overridden by higher-numbered ones) – using api_key as an example:

按以下优先级顺序应用(数字较小的会被数字较大的覆盖)(以api_key为例):
1. Hardcoded default: `""`
2. User-level settings.json: `{"env": {"API_KEY": "abc123"}}`
3. Project-level settings.json: `{"env": {"API_KEY": "abc123"}}`
4. System environment variable: `DEEPCODE_API_KEY=abc123 deepcode`

1. 硬编码默认值: `""`
2. 用户级settings.json: `{"env": {"API_KEY": "abc123"}}`
3. 项目级settings.json: `{"env": {"API_KEY": "abc123"}}`
4. 系统环境变量: `DEEPCODE_API_KEY=abc123 deepcode`
#### 2. Setting model, thinkingEnabled, and reasoningEffort

#### 二、设置模型的model, thinkingEnabled, reasoningEffort
Applied in the following priority order (lower-numbered overridden by higher-numbered) – using thinkingEnabled as an example:

按以下优先级顺序应用(数字较小的会被数字较大的覆盖)(以thinkingEnabled为例):
1. Hardcoded default: `true`
2. User-level settings.json: `{"env": {"THINKING_ENABLED": "true"}}`
3. User-level settings.json: `{"thinkingEnabled": true}`
4. Project-level settings.json: `{"env": {"THINKING_ENABLED": "true"}}`
5. Project-level settings.json: `{"thinkingEnabled": true}`
6. System environment variable: `DEEPCODE_THINKING_ENABLED=true deepcode`

1. 硬编码默认值: `true`
2. 用户级settings.json: `{"env": {"THINKING_ENABLED": "true"}}`
3. 用户级settings.json: `{"thinkingEnabled": true}`
4. 项目级settings.json: `{"env": {"THINKING_ENABLED": "true"}}`
5. 项目级settings.json: `{"thinkingEnabled": true}`
6. 系统环境变量: `DEEPCODE_THINKING_ENABLED=true deepcode`
#### 3. Setting environment variables for external scripts like notify and webSearchTool

#### 三、设置启动notify, webSearchTool等外挂脚本的环境变量
Applied in the following priority order (lower-numbered overridden by higher-numbered) – using notify as an example:

按以下优先级顺序应用(数字较小的会被数字较大的覆盖)(以notify为例):
1. Hardcoded default: `os.environ.get('WEBHOOK', '...') # notify script code`
2. User-level settings.json: `{"env": {"WEBHOOK": "..."}}`
3. Project-level settings.json: `{"env": {"WEBHOOK": "true"}}`
4. System environment variable: `DEEPCODE_WEBHOOK=... deepcode`

1. 硬编码默认值:`os.environ.get('WEBHOOK', '...') # notify脚本代码`
2. 用户级settings.json: `{"env": {"WEBHOOK": "..."}}`
3. 项目级settings.json: `{"env": {"WEBHOOK": "true"}}`
4. 系统环境变量: `DEEPCODE_WEBHOOK=... deepcode`
#### 4. Setting environment variables for an MCP Service

#### 四、设置MCP Service的环境变量
Applied in the following priority order (lower-numbered overridden by higher-numbered) – using a GitHub MCP server as an example:

按以下优先级顺序应用(数字较小的会被数字较大的覆盖)(以github MCP server为例):

1. 用户级settings.json: `{"mcpServers":{"github":{"env":{"GITHUB_PERSONAL_ACCESS_TOKEN":"..."}}}}`
2. 用户级settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
3. 项目级settings.json: `{"mcpServers":{"github":{"env":{"GITHUB_PERSONAL_ACCESS_TOKEN":"..."}}}}`
4. 项目级settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
5. 系统环境变量: `DEEPCODE_MCP_GITHUB_PERSONAL_ACCESS_TOKEN=... deepcode`
1. User-level settings.json: `{"mcpServers":{"github":{"env":{"GITHUB_PERSONAL_ACCESS_TOKEN":"..."}}}}`
2. User-level settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
3. Project-level settings.json: `{"mcpServers":{"github":{"env":{"GITHUB_PERSONAL_ACCESS_TOKEN":"..."}}}}`
4. Project-level settings.json: `{"env": {"MCP_GITHUB_PERSONAL_ACCESS_TOKEN": "..."}}`
5. System environment variable: `DEEPCODE_MCP_GITHUB_PERSONAL_ACCESS_TOKEN=... deepcode`
Loading