Skip to content

Commit 005d8ed

Browse files
merge upstream main (v0.1.26): resolve conflicts in .gitignore, App.tsx, PromptInput.tsx
2 parents 2461d41 + b820bd7 commit 005d8ed

99 files changed

Lines changed: 5182 additions & 816 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.deepcode/AGENTS.md

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ src/
99
├── settings.ts # Settings resolution from ~/.deepcode/settings.json
1010
├── prompt.ts # System prompt builder, tool definitions, built-in skills
1111
├── common/
12+
│ ├── bash-timeout.ts # Bash command timeout enforcement
13+
│ ├── debug-logger.ts # Debug logging for OpenAI API calls
14+
│ ├── error-logger.ts # API error logging
15+
│ ├── file-history.ts # GitFileHistory — checkpoint/undo via Git branches
16+
│ ├── file-utils.ts # File read/write with encoding and diff preview
1217
│ ├── model-capabilities.ts # Model detection and thinking-mode defaults
18+
│ ├── notify.ts # Desktop notification after LLM turn completion
19+
│ ├── openai-client.ts # OpenAI client singleton with keep-alive agent
1320
│ ├── openai-thinking.ts # OpenAI thinking request options builder
14-
│ ├── file-utils.ts # File read/write with encoding and diff preview
21+
│ ├── permissions.ts # Permission scoping, decisions, and tool-call tracking
22+
│ ├── process-tree.ts # Process tree construction and orphan detection
1523
│ ├── shell-utils.ts # Shell path resolution (Git Bash, zsh, bash)
1624
│ ├── state.ts # In-memory file state and snippet tracking
17-
│ ├── runtime.ts # Tool validation runtime helpers
18-
│ ├── notify.ts # Desktop notification after LLM turn completion
19-
│ ├── debug-logger.ts # Debug logging for OpenAI API calls
20-
│ └── error-logger.ts # API error logging
21-
├── ui/
22-
│ ├── App.tsx # Root Ink component — state, routing, session orchestration
23-
│ ├── PromptInput.tsx # Multi-line input with file mentions (@), slash commands, image paste, skills
24-
│ ├── MessageView.tsx # Renders assistant/tool messages with markdown
25-
│ ├── McpStatusList.tsx # MCP server connection status and available tools
26-
│ ├── ProcessStdoutView.tsx # Ctrl+O fullscreen overlay for live process stdout
27-
│ ├── UpdatePrompt.tsx # UpdatePlan task list progress display
28-
│ ├── fileMentions.ts # @-mention file scanning, filtering, and insertion
29-
│ └── ...
25+
│ ├── update-check.ts # Latest-version check against npm registry
26+
│ └── validate.ts # Tool validation runtime helpers (was runtime.ts)
3027
├── mcp/
3128
│ ├── mcp-client.ts # MCP client — JSON-RPC communication with MCP servers
3229
│ └── mcp-manager.ts # MCP manager — lifecycle, tool registration, execution, status
@@ -39,12 +36,21 @@ src/
3936
│ ├── update-plan-handler.ts # Updates the task plan progress display
4037
│ ├── web-search-handler.ts # Web search via natural language queries
4138
│ └── ask-user-question-handler.ts # Interactive user prompts with options
39+
├── ui/
40+
│ ├── components/ # Reusable Ink components (MessageView, DropdownMenu, ModelsDropdown, SkillsDropdown, etc.)
41+
│ ├── contexts/ # React contexts (AppContext, RawModeContext)
42+
│ ├── hooks/ # Custom hooks (cursor, useHistoryNavigation, usePasteHandling, useTerminalInput)
43+
│ ├── views/ # Top-level screen components (App, PromptInput, SessionList, PermissionPrompt, ProcessStdoutView, etc.)
44+
│ ├── core/ # Core UI logic (file-mentions, slash-commands, prompt-buffer, thinking-state, etc.)
45+
│ ├── utils/ # Shared utility helpers
46+
│ ├── index.ts # UI module barrel exports
47+
│ └── constants.ts # UI-wide constants
4248
├── tests/ # One *.test.ts per source module, plus run-tests.mjs
4349
templates/
4450
├── tools/ # Tool descriptions fed to the LLM
4551
├── skills/ # Built-in skill definitions (agent-drift-guard, plan-and-execute)
46-
── prompts/ # EJS templates (e.g., init_command.md.ejs)
47-
docs/ # User-facing documentation (configuration, MCP, skills)
52+
── prompts/ # EJS templates (e.g., init_command.md.ejs)
53+
docs/ # User-facing documentation (configuration, MCP, notify, permissions)
4854
dist/ # Bundled CLI output (gitignored)
4955
```
5056

@@ -78,13 +84,13 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
7884

7985
**Formatting/Linting**: Prettier + ESLint (typescript-eslint, react-hooks). Run `npm run check` before pushing. On commit, Husky + lint-staged auto-formats staged `*.{ts,tsx,js,mjs,cjs,ejs,jsx}` and `*.json` files.
8086

81-
**File naming**: `kebab-case.ts` for modules, `kebab-case.tsx` for React/Ink components. Test files: `*.test.ts`.
87+
**File naming**: `kebab-case.ts` for modules, `kebab-case.tsx` for React/Ink components. Test files: `*.test.ts` (always kebab-case).
8288

8389
## Testing Guidelines
8490

8591
- **Framework**: Node.js native test runner (`node:test`) with `tsx` for TypeScript
8692
- **Assertions**: `node:assert/strict`
87-
- **Coverage**: Target meaningful unit tests for core logic (session management, tool handlers, settings resolution, prompt buffer). Test files are in `src/tests/` matching the source module name.
93+
- **Coverage**: Target meaningful unit tests for core logic (session management, tool handlers, settings resolution, prompt buffer, permissions, MCP client). Test files are in `src/tests/` matching the source module name.
8894
- **Test naming**: `describe`/`test` blocks with descriptive names. Example: `test("SessionManager preserves structured system content when building OpenAI messages", ...)`
8995
- **Relaxed lint rules**: Test files allow `any` and unused vars.
9096
- Run all tests with `npm test` before submitting a PR. A cross-platform test runner is available at `src/tests/run-tests.mjs`.
@@ -109,13 +115,17 @@ Run the CLI locally for manual testing: `node dist/cli.js` (after `npm run bundl
109115

110116
## Architecture Overview
111117

112-
The CLI (`@vegamo/deepcode-cli`) renders a terminal UI using [Ink](https://github.com/vadimdemedes/ink) (React for terminals). `SessionManager` drives the LLM interaction loop: it builds system prompts, sends user messages with optional skills/images, streams responses, executes tool calls via `ToolExecutor`, and compacts context when token thresholds are exceeded (512K for DeepSeek V4 models, 128K for others).
118+
The CLI (`@vegamo/deepcode-cli`) renders a terminal UI using [Ink](https://github.com/vadimdemedes/ink) (React for terminals). `SessionManager` drives the LLM interaction loop: it builds system prompts, sends user messages with optional skills/images, streams responses, executes tool calls via `ToolExecutor`, and compacts context when token thresholds are exceeded (512K for DeepSeek V4 models, 128K for others). OpenAI client connectivity is managed by `createOpenAIClient()` in `src/common/openai-client.ts`, which caches the client singleton and applies a 180-second keep-alive timeout.
113119

114120
Seven built-in tools are available to the LLM: `bash`, `read`, `write`, `edit`, `AskUserQuestion`, `UpdatePlan`, and `WebSearch`. Tool definitions are registered in `src/tools/executor.ts` and described to the LLM via `src/prompt.ts` and `templates/tools/`. The `UpdatePlan` tool enables the LLM to display and update a structured task list in the terminal.
115121

122+
A **permission system** (`src/common/permissions.ts`) controls tool execution scopes (read/write/delete/network/git-log, etc.) with configurable allow/deny/ask decisions. The `PermissionPrompt` view presents interactive prompts when a tool requires user approval.
123+
124+
A **file history system** (`src/common/file-history.ts`) provides undo/checkpoint support by creating lightweight Git branches per session. The `GitFileHistory` class manages blob storage and branch references via a `.deepcode-file-history.json` manifest.
125+
116126
**Slash commands**: `/model`, `/new`, `/init`, `/resume`, `/continue`, `/mcp`, `/exit`, plus dynamic `/skill-name` for each loaded skill.
117127

118-
**Key UI features**: `@` file mentions in the prompt input (scans project files), `Ctrl+O` to view live process stdout in fullscreen, `Ctrl+V` to paste images, MCP server status display.
128+
**Key UI features**: `@` file mentions in the prompt input (scans project files), `Ctrl+O` to view live process stdout in fullscreen, `Ctrl+V` to paste images, MCP server status display, undo selector, and permission prompts.
119129

120130
**CLI flags**: `-p <prompt>` / `--prompt` to auto-submit a prompt on launch, `-v` / `--version`, `-h` / `--help`.
121131

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
*.log
88
.claude/
99
.mcp.json
10+
.deepcode/settings.json

README-en.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ When the AI assistant completes a task, Deep Code can automatically execute a no
137137

138138
For detailed configuration instructions, see: [docs/notify_en.md](docs/notify_en.md)
139139

140+
### Does Deep Code only support YOLO mode?
141+
142+
No. Deep Code has a built-in fine-grained permission control mechanism that lets you confirm operations before the AI assistant executes shell commands, reads/writes files, accesses the network, and more. You can configure each permission scope's policy — always allow, always ask, or deny — via the `permissions` field in `settings.json`. See [docs/permission.md](docs/permission.md) for details.
143+
140144
## Contributing
141145

142146
Contributions are welcome! Here's how to get started:

README-zh_CN.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
122122

123123
详细配置指南:[docs/notify.md](docs/notify.md)
124124

125+
### Deep Code 只支持 YOLO 模式吗?
126+
127+
不是。Deep Code 内置了细粒度的权限控制机制,支持在 AI 助手执行 Shell 命令、读写文件、访问网络等操作前进行确认。你可以通过 `settings.json` 中的 `permissions` 字段按需配置每种权限范围的策略:始终允许、始终询问、或直接拒绝。详见 [docs/permission.md](docs/permission.md)
128+
125129
### 是否支持 Coding Plan?
126130

127131
支持。只要把 `~/.deepcode/settings.json``env.BASE_URL` 配置为 OpenAI 兼容的接口地址就行。以火山方舟的 Coding Plan 为例:
@@ -136,6 +140,7 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
136140
"thinkingEnabled": true
137141
}
138142
```
143+
139144
## 贡献
140145

141146
欢迎贡献代码!以下是参与方式:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
122122

123123
详细配置指南:[docs/notify.md](docs/notify.md)
124124

125+
### Deep Code 只支持 YOLO 模式吗?
126+
127+
不是。Deep Code 内置了细粒度的权限控制机制,支持在 AI 助手执行 Shell 命令、读写文件、访问网络等操作前进行确认。你可以通过 `settings.json` 中的 `permissions` 字段按需配置每种权限范围的策略:始终允许、始终询问、或直接拒绝。详见 [docs/permission.md](docs/permission.md)
128+
125129
### 是否支持 Coding Plan?
126130

127131
支持。只要把 `~/.deepcode/settings.json``env.BASE_URL` 配置为 OpenAI 兼容的接口地址就行。以火山方舟的 Coding Plan 为例:
@@ -136,6 +140,7 @@ Deep Code 支持 MCP(Model Context Protocol),可以连接 GitHub、浏览
136140
"thinkingEnabled": true
137141
}
138142
```
143+
139144
## 贡献
140145

141146
欢迎贡献代码!以下是参与方式:

docs/configuration.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
3131
| `thinkingEnabled` | boolean | 是否启用思考模式(DeepSeek V4 系列默认启用) |
3232
| `reasoningEffort` | string | 推理强度,可选 `"high"``"max"`(默认 `"max"`|
3333
| `debugLogEnabled` | boolean | 是否启用调试日志输出(默认 `false`|
34+
| `telemetryEnabled` | boolean | 是否启用匿名使用数据上报(默认 `true`|
3435
| `notify` | string | 任务完成通知脚本的完整路径(如 Slack 通知脚本) |
3536
| `webSearchTool` | string | 自定义联网搜索脚本的完整路径 |
3637
| `mcpServers` | object | MCP 服务器配置(键为服务名,值为 McpServerConfig 对象) |
@@ -45,6 +46,7 @@ Deep Code 使用 `settings.json` 设置文件进行持久化配置,支持两
4546
| `THINKING_ENABLED` | string | 是否启用思考模式 |
4647
| `REASONING_EFFORT` | string | 推理强度 |
4748
| `DEBUG_LOG_ENABLED` | string | 是否启用调试日志输出 |
49+
| `TELEMETRY_ENABLED` | string | 是否启用匿名使用数据上报 |
4850
| `<其他任意KEY>` | string | 自定义环境变量 |
4951

5052
#### `thinkingEnabled` — 思考模式
@@ -130,6 +132,16 @@ MCP(Model Context Protocol)服务器配置。值是键值对,键为服务
130132

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

135+
#### `telemetryEnabled` — 匿名使用数据上报
136+
137+
设为 `false` 可关闭匿名使用数据上报(默认 `true`)。上报仅包含匿名的机器标识,不包含对话内容、代码或 API 密钥。
138+
139+
也可以通过环境变量关闭:
140+
141+
```bash
142+
DEEPCODE_TELEMETRY_ENABLED=0 deepcode
143+
```
144+
133145
## 环境变量优先级
134146

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

docs/configuration_en.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ The following are all the top-level fields supported in `settings.json`, along w
3131
| `thinkingEnabled` | boolean | Whether to enable thinking mode (enabled by default for DeepSeek V4 series)|
3232
| `reasoningEffort` | string | Reasoning intensity, either `"high"` or `"max"` (default `"max"`) |
3333
| `debugLogEnabled` | boolean | Enable debug log output (default `false`) |
34+
| `telemetryEnabled` | boolean | Enable anonymous usage reporting (default `true`) |
3435
| `notify` | string | Full path to a task-completion notification script (e.g., Slack notification script) |
3536
| `webSearchTool` | string | Full path to a custom web search script |
3637
| `mcpServers` | object | MCP server configurations (keys are service names, values are McpServerConfig objects) |
@@ -45,6 +46,7 @@ The following are all the top-level fields supported in `settings.json`, along w
4546
| `THINKING_ENABLED`| string | Enable thinking mode |
4647
| `REASONING_EFFORT`| string | Reasoning intensity |
4748
| `DEBUG_LOG_ENABLED`| string| Enable debug log output |
49+
| `TELEMETRY_ENABLED`| string| Enable anonymous usage reporting |
4850
| `<any other KEY>` | string | Custom environment variable |
4951

5052
#### `thinkingEnabled` — Thinking Mode
@@ -129,6 +131,16 @@ For detailed MCP usage instructions, refer to [mcp.md](mcp.md).
129131

130132
Set to `true` to enable detailed debug logging (default `false`), useful for troubleshooting API calls and tool execution.
131133

134+
#### `telemetryEnabled` — Anonymous Usage Reporting
135+
136+
Set to `false` to disable anonymous usage reporting (default `true`). The report only includes an anonymous machine identifier and does not contain conversation content, code, or API keys.
137+
138+
You can also disable it via environment variable:
139+
140+
```bash
141+
DEEPCODE_TELEMETRY_ENABLED=0 deepcode
142+
```
143+
132144
## Environment Variable Priority
133145

134146
Environment variables are a common way to configure applications, especially for sensitive information (such as api-key) or settings that may change between environments.

docs/permission.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Deep Code 权限机制
2+
3+
Deep Code 内置了一套细粒度的权限控制机制,在 AI 助手执行工具调用(如执行 Shell 命令、读写文件、访问网络等)前,根据用户配置的策略决定是自动放行、直接拒绝、还是弹出交互式确认。
4+
5+
## 概述
6+
7+
每次 AI 助手调用工具时,系统会自动分析该操作涉及的**权限范围(Permission Scope)**,然后根据 `settings.json` 中的权限配置做出决策。对于需要用户确认的操作,会在终端中弹出交互式选择界面,用户可以选择:
8+
9+
- **Yes** — 仅本次放行
10+
- **Yes, and always allow** — 本次放行,并将该权限范围写入项目配置文件,后续同类操作不再询问
11+
- **No** — 拒绝本次操作
12+
13+
## 权限范围
14+
15+
Deep Code 定义了以下 10 种权限范围,覆盖了工具调用的各类风险场景:
16+
17+
| 权限范围 | 说明 |
18+
| -------- | ---- |
19+
| `read-in-cwd` | 读取当前工作区内的文件 |
20+
| `read-out-cwd` | 读取当前工作区外的文件 |
21+
| `write-in-cwd` | 在当前工作区内创建或覆写文件 |
22+
| `write-out-cwd` | 在当前工作区外创建或覆写文件 |
23+
| `delete-in-cwd` | 删除当前工作区内的文件 |
24+
| `delete-out-cwd` | 删除当前工作区外的文件 |
25+
| `query-git-log` | 查询 Git 历史(如 `git log``git show``git blame`|
26+
| `mutate-git-log` | 修改 Git 历史(如 `git commit``git rebase``git tag`|
27+
| `network` | 访问网络(如 `curl``npm install` 等联网操作) |
28+
| `mcp` | 调用 MCP 外部工具 |
29+
30+
此外还有一个特殊的 `unknown` 范围,当 LLM 无法准确分类命令的副作用时使用,**`unknown` 总是触发询问**
31+
32+
## 权限配置
33+
34+
`~/.deepcode/settings.json`(用户级)或 `.deepcode/settings.json`(项目级)中通过 `permissions` 字段配置:
35+
36+
```json
37+
{
38+
"permissions": {
39+
"allow": [],
40+
"deny": [],
41+
"ask": [],
42+
"defaultMode": "allowAll"
43+
}
44+
}
45+
```
46+
47+
### 配置项说明
48+
49+
| 字段 | 类型 | 说明 |
50+
| ---- | ---- | ---- |
51+
| `allow` | `string[]` | 始终自动放行的权限范围列表 |
52+
| `deny` | `string[]` | 始终自动拒绝的权限范围列表 |
53+
| `ask` | `string[]` | 始终弹出询问的权限范围列表 |
54+
| `defaultMode` | `"allowAll"` \| `"askAll"` | 未在 `allow`/`deny`/`ask` 中明确列出的权限范围的默认处理方式。默认为 `"allowAll"` |
55+
56+
### 优先级规则
57+
58+
当一个工具调用涉及多个权限范围时,决策按以下优先级进行:
59+
60+
1. 若任一范围命中 `deny`**拒绝**
61+
2. 若任一范围命中 `ask`**询问**
62+
3. 若所有范围均在 `allow` 中 → **自动放行**
63+
4. 否则 → 按 `defaultMode` 处理
64+
65+
### 示例:宽松模式(默认)
66+
67+
```json
68+
{
69+
"permissions": {
70+
"defaultMode": "allowAll"
71+
}
72+
}
73+
```
74+
75+
默认行为:所有操作自动放行,无需确认。
76+
77+
### 示例:严格模式
78+
79+
```json
80+
{
81+
"permissions": {
82+
"allow": ["read-in-cwd", "write-in-cwd", "query-git-log"],
83+
"defaultMode": "askAll"
84+
}
85+
}
86+
```
87+
88+
此配置的效果:
89+
- 工作区内读写、Git 查询 → 自动放行
90+
- 其他操作都需要用户确认。
91+
92+
93+
## 持久化机制
94+
95+
当用户在权限提示中选择 "Yes, and always allow" 后,对应的权限范围会被写入当前项目的 `.deepcode/settings.json` 文件中:
96+
97+
- 新增范围会追加到 `permissions.allow` 列表
98+
- 如果该范围之前存在于 `deny``ask` 中,会被自动移除
99+
- 不会重复写入已存在的范围
100+
101+
这样后续同类操作就不再询问。

0 commit comments

Comments
 (0)