Skip to content

Commit b9ece60

Browse files
committed
merge: integrate refactor phase2 simplify
Merge the refactor/phase2-simplify branch into main while preserving main history.
2 parents c991dc2 + 3ce6bfc commit b9ece60

121 files changed

Lines changed: 17501 additions & 5055 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.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ uploads/
7575

7676
# secrets (use .env or environment variables instead)
7777
# NEVER commit real API keys; use the *.example files as templates.
78-
mcp_agent.secrets.yaml
78+
deepcode_config.json
7979
nanobot_config.json
8080
*.secrets.yaml
8181
*.secrets.yml

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes to DeepCode will be documented in this file.
2424
- **Process Hanging**: Fixed infinite loops and hanging on errors - process now exits cleanly
2525
- **Token Cost Tracking**: Restored accurate token usage and cost display (was showing $0.0000)
2626
- **PDF to Markdown Conversion**: Fixed automatic conversion and file location handling
27-
- **Document Segmentation**: Properly uses configured 50K character threshold from `mcp_agent.config.yaml`
27+
- **Document Segmentation**: Properly uses configured 50K character threshold from `deepcode_config.json`
2828
- **Error Propagation**: Abort mechanism now properly stops process after 10 consecutive real errors
2929

3030
### Changed

README.md

Lines changed: 134 additions & 99 deletions
Large diffs are not rendered by default.

README_ZH.md

Lines changed: 130 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,27 @@
157157

158158
## 📰 新闻
159159

160+
🧭 **[2026-05-01] OpenRouter 模型选择器、session 清理与工作流体验增强**
161+
162+
- 🧠 **Settings 中新增 OpenRouter 模型目录。** 新版 UI 可以从 `https://openrouter.ai/api/v1/models` 获取 OpenRouter 模型元数据,本地缓存后提供可搜索的 Default、Planning、Implementation 三阶段模型下拉框。用户可以直接选择 `z-ai/glm-5.1` 这类 OpenRouter 精确模型 id,无需手动编辑 JSON。
163+
- 🔄 **运行时模型切换。** 在 Settings 保存模型选择后,会更新 `deepcode_config.json` 并刷新进程内 LLM runtime;之后新启动的 workflow 会立即使用新的 provider/model 组合。
164+
- 🗑️ **Session 删除改为安全级联清理。** 在 UI 中删除 session 时,会删除持久化 session 记录和对应的 `deepcode_lab/tasks/<task_id>/` 工作目录,但保留可被多个 session 共享的 `uploads/` 原始文件。若 session 下仍有 `pending``running``waiting_for_input` task,后端会返回明确的 `409 Conflict`
165+
- 📊 **Paper2Code 进度显示更准确。** 前端现在会展示后端阶段消息,并避免在长时间 LLM 阶段尚未完成时,把中间步骤误标记为完全 Done。
166+
- 🛡️ **工作流稳定性修复。** 上传阶段会拒绝 Git LFS pointer 文件;取消任务会及时中断后端工作;浏览器中的过期 session id 会自动恢复;planner 在模型输出错误的工具调用/延迟执行文本时会回退到最小合法 plan;文档分割阶段跳过额外质量验证 LLM 调用,减少卡在 50% 的概率。
167+
168+
---
169+
170+
🗂️ **[2026-04-28] 持久化 session 与双层结构化日志**
171+
172+
- 🆕 **Session 现在会持久化。** 每次 CLI / UI 运行都会自动挂到一个 session,默认保存在 `~/.deepcode/sessions/<id>/`(可用 `DEEPCODE_SESSIONS_DIR` 覆盖)。session 使用 JSONL 存储,支持 `python cli/main_cli.py session list|show <id>|new|resume <id>|delete <id>`,后端也提供 `GET /api/v1/sessions`
173+
- 🔄 **恢复历史任务。** CLI 可以用 `--session <id>` 把新任务挂到旧 session;UI / API 可以在 `POST /api/v1/workflows/paper-to-code``chat-planning` 中传 `session_id`。后端重启后会从磁盘恢复历史 task,崩溃前仍在运行的 task 会标记为 `interrupted`
174+
- 💻 **CLI 交互增强。** 进入 `python cli/main_cli.py` 后,可以在主菜单输入 `/resume` 打开历史 session 选择器,`/new [title]` 新建并切换 session,`/session` 查看当前 session,`/help` 查看命令。也支持 Cursor/Codex 风格的内联输入:`@/path/to/paper.pdf``@"C:\path with spaces\paper.pdf"``@https://...`
175+
- 📜 **双层结构化日志。** 全局日志写入 `logs/server-YYYYMMDD.jsonl`;每个任务的日志写入 `deepcode_lab/tasks/<task_id>/logs/{system,llm,mcp}.jsonl`。所有 `loguru.logger` 调用都会通过 contextvar 自动带上 `task_id` / `session_id`,LLM/MCP 调用还会记录耗时、token、请求/响应摘要。
176+
- 📡 **WebSocket 日志流。** 单 task 日志流:`/ws/tasks/{task_id}/logs?channel=llm`;按 session 聚合多个 task:`/ws/sessions/{session_id}/logs`。旧的假 `/ws/logs/{session_id}` 已移除。
177+
- 🧹 **清理旧实现。** 删除 `utils/simple_llm_logger.py``utils/dialogue_logger.py`,原内存版 `services/session_service.py` 改为 `core.sessions.SessionStore` 的 thin facade。
178+
179+
---
180+
160181
🎉 **[2026-02] DeepCode + nanobot 集成 — 通过飞书聊天使用 DeepCode!**
161182

162183
<div align="center">
@@ -430,7 +451,6 @@ DeepCode利用**模型上下文协议 (MCP)** 标准与各种工具和服务无
430451

431452
| 🛠️ **MCP服务器** | 🔧 **主要功能** | 💡 **目的和能力** |
432453
|-------------------|-------------------------|-------------------------------|
433-
| **🌐 bocha-mcp** | 替代搜索 | 具有独立API访问的辅助搜索选项 |
434454
| **📂 filesystem** | 文件系统操作 | 本地文件和目录管理,读/写操作 |
435455
| **🌐 fetch** | Web内容检索 | 从URL和Web资源获取和提取内容 |
436456
| **📥 github-downloader** | 存储库管理 | 克隆和下载GitHub存储库进行分析 |
@@ -610,9 +630,9 @@ sudo apt-get install -y nodejs
610630
# 🚀 直接安装 DeepCode 包
611631
pip install deepcode-hku
612632

613-
# 🔑 下载配置文件
614-
curl -O https://raw.githubusercontent.com/HKUDS/DeepCode/main/mcp_agent.config.yaml
615-
curl -O https://raw.githubusercontent.com/HKUDS/DeepCode/main/mcp_agent.secrets.yaml
633+
# 🔑 下载统一配置模板
634+
curl -O https://raw.githubusercontent.com/HKUDS/DeepCode/main/deepcode_config.json.example
635+
cp deepcode_config.json.example deepcode_config.json
616636
```
617637

618638
#### 🔧 **开发安装 (从源码)**
@@ -651,60 +671,70 @@ npm install --prefix new_ui/frontend
651671

652672
### 🔧 **步骤2: 配置**
653673

654-
> 以下配置适用于**所有安装方式**(pip、UV、源码安装和 Docker 均通用)。
674+
> 以下配置适用于**所有安装方式**(pip、UV、源码安装和 Docker 均通用)。所有设置统一收敛在一个文件中:`deepcode_config.json`(参考 nanobot 设计)。
655675
656676
#### 🔑 API 密钥 *(必需)*
657677

658-
编辑 `mcp_agent.secrets.yaml`,填入你的 API 密钥:
659-
660-
```yaml
661-
# 至少需要配置一个 LLM 提供商的 API Key
662-
openai:
663-
api_key: "your_openai_api_key"
664-
base_url: "https://openrouter.ai/api/v1" # 可选: 用于 OpenRouter 或自定义端点
665-
666-
anthropic:
667-
api_key: "your_anthropic_api_key" # 用于 Claude 模型
678+
编辑 `deepcode_config.json`,至少填入一个 provider 的 `apiKey`。可以直接写入字符串,也可以使用 `${ENV_VAR}` 引用环境变量,加载时自动解析。
668679

669-
google:
670-
api_key: "your_google_api_key" # 用于 Gemini 模型
680+
```json
681+
{
682+
"providers": {
683+
"openai": { "apiKey": "your_openai_api_key" },
684+
"anthropic": { "apiKey": "${ANTHROPIC_API_KEY}" },
685+
"gemini": { "apiKey": "" }
686+
}
687+
}
671688
```
672689

673690
#### 🤖 LLM 提供商 *(可选)*
674691

675-
编辑 `mcp_agent.config.yaml` 选择你偏好的 LLM 提供商(第 ~106 行)
692+
DeepCode 会根据 `model` 前缀(例如 `openai/...``anthropic/...``gemini/...`)自动识别后端。如需强制指定
676693

677-
```yaml
678-
# 选项: "google", "anthropic", "openai"
679-
# 如果未设置或不可用,将自动回退到第一个可用的提供商
680-
llm_provider: "google"
694+
```json
695+
{
696+
"agents": {
697+
"defaults": { "provider": "openai" }
698+
}
699+
}
681700
```
682701

683-
#### 🔍 搜索 API 密钥 *(可选)*
684-
685-
在 `mcp_agent.config.yaml` 中配置 Web 搜索:
702+
不同阶段可以单独覆盖模型:
686703

687-
```yaml
688-
# Bocha-MCP(可选)— 在 bocha-mcp.env 部分设置
689-
bocha-mcp:
690-
env:
691-
BOCHA_API_KEY: "your_bocha_api_key_here"
704+
```json
705+
{
706+
"agents": {
707+
"defaults": { "provider": "openrouter", "model": "z-ai/glm-5.1" },
708+
"planning": { "provider": "openrouter", "model": "z-ai/glm-5.1" },
709+
"implementation": { "provider": "openrouter", "model": "z-ai/glm-5.1" }
710+
},
711+
"providers": {
712+
"openrouter": { "apiKey": "your_openrouter_key", "apiBase": "https://openrouter.ai/api/v1" }
713+
}
714+
}
692715
```
693716

694-
#### 📄 文档分割 *(可选)*
717+
OpenRouter 模型必须使用 OpenRouter 官方模型目录返回的精确 `id`,例如
718+
`z-ai/glm-5.1``anthropic/claude-sonnet-4.5`
719+
`google/gemini-2.5-pro`。在新版 UI 中,可以打开 **Settings → OpenRouter
720+
Models** 搜索实时模型目录,并分别更新 Default、Planning、Implementation
721+
模型。保存后会刷新 runtime,之后新启动的 workflow 会使用新的模型配置。
695722

696-
在 `mcp_agent.config.yaml` 中控制文档处理:
723+
#### 📄 文档分割 *(可选)*
697724

698-
```yaml
699-
document_segmentation:
700-
enabled: true # true/false — 是否使用智能文档分割
701-
size_threshold_chars: 50000 # 触发分割的文档大小阈值
725+
```json
726+
{
727+
"documentSegmentation": {
728+
"enabled": true,
729+
"sizeThresholdChars": 50000
730+
}
731+
}
702732
```
703733

704734
<details>
705735
<summary><strong>🪟 Windows 用户: 额外的 MCP 服务器配置</strong></summary>
706736

707-
如果您使用 Windows,可能需要在 `mcp_agent.config.yaml` 中手动配置 MCP 服务器:
737+
如果您使用 Windows,可能需要在 `deepcode_config.json``tools.mcpServers` 中手动配置 MCP 服务器:
708738

709739
```bash
710740
# 1. 全局安装 MCP 服务器
@@ -714,46 +744,36 @@ npm i -g @modelcontextprotocol/server-filesystem
714744
npm -g root
715745
```
716746

717-
然后更新您的 `mcp_agent.config.yaml` 使用绝对路径:
718-
719-
```yaml
720-
mcp:
721-
servers:
722-
filesystem:
723-
command: "node"
724-
args: ["C:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js", "."]
747+
```json
748+
{
749+
"tools": {
750+
"mcpServers": {
751+
"filesystem": {
752+
"type": "stdio",
753+
"command": "node",
754+
"args": ["C:/Program Files/nodejs/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js", "."]
755+
}
756+
}
757+
}
758+
}
725759
```
726760

727761
> **注意**: 将路径替换为步骤 2 中您实际的全局 node_modules 路径。
728762
729763
</details>
730764

731765
<details>
732-
<summary><strong>🔍 搜索服务器配置(可选)</strong></summary>
766+
<summary><strong>🔍 网页搜索配置</strong></summary>
733767

734-
DeepCode 支持可选的 Bocha 搜索,以及内置的 `fetch` 用于网页内容抓取
768+
DeepCode 通过内置的 `fetch` MCP 服务器(无需 API key)抓取网页内容,并通过 `filesystem` 读取本地文件。辅助搜索服务器默认使用 `filesystem`
735769

736-
```yaml
737-
# 默认搜索服务器配置
738-
# 选项: "bocha-mcp"
739-
default_search_server: "bocha-mcp"
740-
```
741-
742-
**可用选项:**
743-
- **🌐 Bocha-MCP** (`"bocha-mcp"`): 替代搜索服务器。需要 `BOCHA_API_KEY`。使用本地 Python 服务器实现。
744-
745-
**完整 MCP 服务器配置(mcp_agent.config.yaml):**
746-
```yaml
747-
# Bocha-MCP(可选)
748-
bocha-mcp:
749-
command: "python"
750-
args: ["tools/bocha_search_server.py"]
751-
env:
752-
PYTHONPATH: "."
753-
BOCHA_API_KEY: "your_bocha_api_key_here"
770+
```json
771+
{
772+
"tools": { "defaultSearchServer": "filesystem" }
773+
}
754774
```
755775

756-
> **💡 提示**: 两个搜索服务器都需要 API 密钥配置。选择最适合您的 API 访问和需求的选项
776+
> **💡 提示**: 若要接入其他搜索后端,在 `deepcode_config.json``tools.mcpServers` 下新增条目,并把 `tools.defaultSearchServer` 改成对应名称即可
757777
758778
</details>
759779

@@ -764,7 +784,7 @@ bocha-mcp:
764784
<table width="100%">
765785
<tr>
766786
<th width="33%">🐳 Docker (推荐)</th>
767-
<th width="33%">🚀 本地 (<code>deepcode</code> 命令)</th>
787+
<th width="33%">🚀 本地 — 不使用 Docker</th>
768788
<th width="33%">🛠️ 其他方式</th>
769789
</tr>
770790
<tr><td>
@@ -774,37 +794,40 @@ bocha-mcp:
774794
```bash
775795
git clone https://github.com/HKUDS/DeepCode.git
776796
cd DeepCode/
777-
cp mcp_agent.secrets.yaml.example \
778-
mcp_agent.secrets.yaml
779-
# 编辑填入 API Key
797+
cp deepcode_config.json.example \
798+
deepcode_config.json
799+
# 编辑 deepcode_config.json 填入 API Key
780800

781801
./deepcode_docker/run_docker.sh
782802
# 访问 → http://localhost:8000
783803
```
784804

785805
</td><td>
786806

787-
首次运行自动安装依赖
807+
直接在宿主机运行新版 UI(前端 + 后端,不使用容器)
788808

789809
```bash
790-
deepcode
810+
deepcode --local
791811
# 前端 → http://localhost:5173
792812
# 后端 → http://localhost:8000
793813
# Ctrl+C 停止
794814
```
795815

796816
特性:用户交互循环、实时进度、内联对话。
797817

818+
> 注意:不带参数的 `deepcode` 会走 Docker 启动路径。如果 Docker Desktop
819+
> 没有运行,请使用上面的 `deepcode --local`
820+
798821
</td><td>
799822

800823
```bash
801824
# macOS / Linux
802825
./run.sh
803-
# 或: python deepcode.py
826+
# 或: python deepcode.py --local
804827

805828
# Windows
806829
run.bat
807-
# 或: python deepcode.py
830+
# 或: python deepcode.py --local
808831

809832
# 经典 Streamlit UI
810833
deepcode --classic
@@ -817,6 +840,39 @@ deepcode --cli
817840
</td></tr>
818841
</table>
819842

843+
#### 💻 **CLI session 与内联输入**
844+
845+
CLI 默认带 session。没有传 `--session` 时会自动创建新 session,并保存在
846+
`~/.deepcode/sessions/<id>/`;传 `--session <id>` 时,新 task 会追加到已有
847+
session。
848+
849+
```bash
850+
# 在 shell 中管理 session
851+
python cli/main_cli.py session list
852+
python cli/main_cli.py session show <session_id>
853+
python cli/main_cli.py session resume <session_id> # 显示历史后进入交互模式
854+
python cli/main_cli.py --session <session_id> --file paper.pdf
855+
```
856+
857+
进入 `python cli/main_cli.py` 后,可以在主菜单直接输入:
858+
859+
```text
860+
/resume # 从编号列表中选择历史 session
861+
/new 我的实验 # 新建并切换到一个 session
862+
/session # 显示当前活跃 session
863+
@/absolute/path.pdf # 不弹文件选择框,直接处理文件
864+
@"C:\path with spaces\paper.pdf"
865+
@https://arxiv.org/pdf/....
866+
```
867+
868+
这些入口创建的 task 都会继承当前 `session_id`;per-task 日志会写入
869+
`deepcode_lab/tasks/<task>/logs/`
870+
871+
在 Web UI 中,可以通过顶部 **Sessions** 菜单恢复或删除 session。删除
872+
session 会移除 JSONL session 记录和对应的 `deepcode_lab/tasks/` 工作目录,
873+
但不会删除 `uploads/` 中的原始上传文件。如果该 session 仍有 `pending`
874+
`running``waiting_for_input` task,后端会拒绝删除,直到任务被取消或完成。
875+
820876
<details>
821877
<summary><strong>🐳 Docker 管理命令</strong></summary>
822878

__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
__repo__ = "https://github.com/Jany-M/DeepCode/"
1212

1313
# Import main components for easy access
14-
from utils import FileProcessor, DialogueLogger
14+
from utils import FileProcessor
1515

1616
__all__ = [
1717
"FileProcessor",
18-
"DialogueLogger",
1918
"__version__",
2019
"__author__",
2120
"__url__",

0 commit comments

Comments
 (0)