Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
b7b1cd3
fix: resolve compilation errors, clean unused imports, migrate async …
May 10, 2026
ae35cac
fix: clippy warnings - rename from_str, remove unnecessary cast, fix …
May 10, 2026
ea9e3a9
fix: clippy - mixed array sizes in micro-ci phases.rs
May 10, 2026
74ca712
fix: restore mut on server binding, remove redundant ref in pattern
May 10, 2026
812a24a
chore: checkpoint before final warning analysis
May 10, 2026
360aa4b
fix: lifetime annotation on resolve_tool_name, macros import in tool-…
May 10, 2026
e30dca1
fix: final cleanup - lifetime annotations, move-after-use, unreachabl…
May 10, 2026
f911421
chore: save state before code value analysis
May 10, 2026
0bc34fc
feat: 集成代码价值六维分类 + 修复全部编译错误和警告
May 10, 2026
a60a759
feat: deep-port 6 modules from Claude Code stubs to production-ready …
May 10, 2026
03029f1
feat: port 8 high-value Claude Code modules + fix reasoning_content t…
May 10, 2026
8d931bf
feat(lsp): integrate 4 LSP implementations into unified industrial sy…
May 11, 2026
c935583
feat(lsp): integrate LSP engine with gRPC layer - add 3-tier architec…
May 11, 2026
90a93c5
fix(lsp): resolve all jcode-lsp compilation errors and fix gRPC modul…
May 11, 2026
b0b1e70
feat(ast): implement AST-level intelligent refactoring operations (Di…
May 11, 2026
42ce305
feat(lsp): add multi-workspace support and deep scan analysis report
May 11, 2026
ff38b31
feat(lsp): enhance core LSP modules with production-ready features
May 11, 2026
8ff577f
feat(ws): add comprehensive Web IDE WebSocket server
May 11, 2026
f90ee97
fix(grpc): fix method signatures and expand service implementations
May 11, 2026
7b6ec98
feat: update server entry point and dependencies
May 11, 2026
f9a6e0a
feat: Add RAG Toolchain Closed-Loop System (jcode-rag crate)
May 11, 2026
db29b48
feat: Add jcode-llm crate - LLM Provider Integration
May 11, 2026
6dffe64
feat: Add gRPC LlmService + OpenAI-compatible REST API
May 11, 2026
a3df8bb
feat: 完成LLM集成、RAG工具链和API开发
May 11, 2026
969a0c4
feat: 完成gRPC服务端实现和REST API完善
May 11, 2026
b058df0
feat: Add CarpAI advanced features and IDE integration
May 12, 2026
3636d9c
feat: Create carpai-sdk crate (Unified Client SDK)
May 12, 2026
9f77231
chore: Update Cargo.lock for carpai-sdk dependencies
May 12, 2026
cb4dd21
fix: Resolve all clippy warnings and compilation errors in carpai-sdk
May 12, 2026
0dc5fe1
feat: comprehensive optimization and new modules
May 13, 2026
735aa1f
feat: implement enhanced CLI toolset (Git, Cost, Tasks)
May 13, 2026
08d9fc0
fix: 系统化修复编译错误
May 13, 2026
1a2c7fb
fix: 继续修复编译错误
May 13, 2026
3d607ba
fix: 修复 78 个编译错误,cargo clippy 通过
May 13, 2026
57a53b4
chore: cargo clippy --fix 自动修复 60+ 文件的样式警告
May 13, 2026
c526ec6
feat: 完善 CarpAI 六大功能模块
May 13, 2026
347eb69
feat: 补全缺失的 CLI 和 Slash 命令
May 14, 2026
b581b68
feat: 沙箱智能截断 + 补全5个缺失命令
May 14, 2026
a775a82
chore: 保存未提交变更 + 清理 unused import
May 14, 2026
7cf6b17
chore: 保存 tool/plan_mode.rs 新建文件及 tool/mod.rs 变更
May 14, 2026
6dfe870
chore: tool module changes
May 14, 2026
f024ebc
feat: 全面补齐CarpAI功能,实现与Claude Code全面对齐
May 14, 2026
0820aab
feat: 实现CarpAI中期+长期愿景功能增强
May 14, 2026
35f73f4
feat: 完善CarpAI核心功能 - Snippet/MCP/Clippy修复
May 14, 2026
7f9a29f
feat: 实现动态工具注册API (+2分) - 追平98-99分
May 14, 2026
1b121bf
feat: 实现剩余10分功能 - 学习系统+Aho-Corasick+文档 (+10分)
May 14, 2026
c3afcf8
feat: Tree-sitter AST parser + compile fixes
May 14, 2026
d010377
feat: 实现Claude Code级别的推理与上下文能力 - CoT引擎+500K上下文+实时回传
May 14, 2026
289163d
feat: Phase1-移植Claude Code P0核心CLI命令 (25个新命令)
May 14, 2026
4951693
feat: Phase2-实现P1高频命令 (/review/init/memory/permissions/vim/bug/status…
May 14, 2026
18a4137
feat: Phase3-实现P2专业特性 (agents/plugin/remote-control/ultrareview/setup…
May 14, 2026
0125e99
docs: CLI迁移完整报告 - CarpAI vs Claude Code对比
May 14, 2026
4094f21
feat: 实现NLP能力+快速原型引擎+增强重构系统 (Claude Code深度借鉴)
May 14, 2026
edcee31
fix: 删除多余的模块占位符文件 (nlp.rs和prototype.rs)
May 14, 2026
cf6b4fb
feat: 集成Rust最佳实践知识库到CarpAI核心能力
May 14, 2026
b490c9e
feat: 完成Phase 2/3全优先级任务 - 新增6大核心模块 (4350行)
May 14, 2026
07d6968
feat: Phase 1 Warp集成 - Block UI + NL Command + JSON渲染 + 动作栏 + 流式输出 (2…
May 14, 2026
c5a6cad
feat: Phase 2 Warp深化 - Rope + Timeline + Replay + Context Actions (33…
May 14, 2026
e6fcbb7
feat: Phase 3 差异化特性 - Sharing + Intelligence + Collab + VideoExport (…
May 14, 2026
d8bb5f2
fix: 补全 ArgSpec、SubcommandSpec、CommandSpec 结构体缺失字段
May 16, 2026
b0e378f
fix: compile errors and warnings (Unicode, ArgSpec, const, types, imp…
May 16, 2026
ef752a4
修复 type annotations、E0308/E0277 错误以及语法错误
May 17, 2026
7199c81
feat: 修复多个编译错误 - Allocator trait、Default trait、类型不匹配等
May 17, 2026
389f47e
fix: 添加 chrono clock feature 解决 hour() 方法问题
May 17, 2026
1b2197d
fix: 修复 CLI 命令函数、CompletionSuggestion 字段、private fields、类型导入等问题
May 17, 2026
5103a38
fix: 修复 PackageManager::GoMod、RiskLevel Ord trait、多个 Instant Default 实现
May 17, 2026
951daea
fix: 删除 expanded_cmds 中不存在的函数导入
May 17, 2026
ff85766
fix: 继续修复编译错误 - 删除不存在函数导入
May 17, 2026
5556bb5
fix: 使用子任务修复 skeletons.rs 和 dispatch.rs - 错误减少到 251 个
May 17, 2026
80db78a
修复多个编译错误:Agent方法、LSP函数、WebSocket通信等
May 18, 2026
2a719d6
修复 WebSocket 导入问题
May 18, 2026
030edc0
完整实现 LSP 功能:with_lsp_client、ensure_lsp_manager、parse_range函数
May 18, 2026
2c7ce8a
修复多个编译错误:tree_sitter可变借用、LSP命令、WebSocket类型等
May 18, 2026
49c9e02
修复 SSH 模块错误:duration变量、stderr变量、SftpSessionManager类型
May 18, 2026
f0bce1b
修复 WebSocket 和 LSP 命令问题
May 18, 2026
e715bcb
修复 commands.rs 和 openai_stream_runtime.rs 的类型问题
May 18, 2026
e4a653c
修复 commands.rs 和 openai_stream_runtime.rs 的剩余类型问题
May 18, 2026
777d4a9
修复 Server/LSP/WS/CLI/Provider 模块编译错误
May 18, 2026
70aa923
修复多个模块编译错误:cli/reasoning/provider/tui/session等模块
May 18, 2026
bf80028
修复 auto_mode/completion/tui/工具/其余模块编译错误
May 18, 2026
272e7ab
fix: apply cargo clippy --fix and cargo fix for SSH/NLP/Auto-mode mod…
May 19, 2026
934e16f
fix: resolve MutexGuard across await points and add dead_code suppres…
May 19, 2026
1df91c6
fix: resolve 98 actionable warnings across the codebase
May 19, 2026
2e60968
fix: suppress dead_code warnings for future feature placeholder code
May 19, 2026
439fa2d
chore: clean up temporary analysis file
May 19, 2026
0890dc4
Q1 completion: RPC voting mechanism, concurrency protection, module s…
May 19, 2026
2be7bbc
Save changes: SSH pool improvements and prototype engine updates
May 19, 2026
995febe
Q3 Prototype Engine: Implement requirement analysis framework and cod…
May 19, 2026
1801cea
Fix SSH PTY Windows implementation and enable windows-sys features
May 19, 2026
6ad5029
Fix prototype module: Add FileType enum, BudgetTier EnterprisePlus, a…
May 19, 2026
b890403
Fix prototype module: Add missing enum variants and .into() conversions
May 19, 2026
5ccf6bf
Implement P0-P2 features: incremental indexing, cache optimization, p…
May 20, 2026
4423d22
Activate symbol-level application conflict detection
May 20, 2026
d95d800
Add refactor template library and preview UI; Activate symbol-level c…
May 21, 2026
e619bf7
Add complete gRPC CollaborationService for Figma-like real-time colla…
May 21, 2026
39370e4
完成多项功能实现:SSO集成、Prometheus监控、Python/TypeScript SDK、OpenAPI文档
May 21, 2026
57d7054
完善代码审查命令和DAP调试器集成
May 21, 2026
446c158
完善代码补全引擎
May 21, 2026
e091c41
创建 VS Code 插件
May 21, 2026
d454d25
修复编译错误:vc移动问题、async_trait、类型转换
May 21, 2026
5f7338c
修复 CompletionProvider trait 和 DAP 协议类型
May 21, 2026
2173365
fix: resolve multiple compilation issues
May 22, 2026
4b2319e
Phase 1: 创建缺失模块和修复简单问题
May 23, 2026
04ed2fb
WIP: Phase 2 类型系统问题修复前状态
May 23, 2026
f750939
docs: Phase 2 类型系统修复任务清单 (30个任务)
May 23, 2026
5183ee7
fix: Phase 2 - Resolve multiple critical compilation issues
May 23, 2026
b5fe87f
fix: VectorDatabase trait async compatibility and logging macro issues
May 23, 2026
a3d8549
fix: VectorDatabase async and logging fixes
May 23, 2026
dcc917c
fix: Layered fix - multiple modules compilation errors
May 23, 2026
a321207
fix: layered fixes - knowledge_agents, completion_engine, agent_runti…
May 23, 2026
7820058
fix: resolve final 2 E0004 errors - AstEditOp match completeness
May 23, 2026
5d3d329
fix: resolve 133 compilation errors and 102 warnings across carpai crate
May 23, 2026
11c6d21
fix: carpai 0 errors final E0308 + inference_optimizer syntax + ente…
May 23, 2026
62e0b99
feat: activate 2 dead-code chains CollabAwareCompleter + BehaviorLea…
May 23, 2026
ff9a27b
feat: comprehensive fix 0 errors, enterprise merge, dead-code activa…
May 23, 2026
6d3a63f
docs: add enterprise merge plan + production readiness analysis + err…
May 24, 2026
acb22e4
feat(carpai-core): Week 1 trait layer + 6 Local impls, cargo check p…
May 24, 2026
cd0faf6
style(carpai-core): fix clippy 0 errors, resolve 2 errors + 16 warnings
May 24, 2026
49ce403
feat(carpai-core): Phase 1D Tool System + Completion System (8 modul…
May 24, 2026
00ce0a4
feat(carpai-core): Wk3 Interface Contract + Wk6-7 Performance Module …
May 24, 2026
f2ad725
feat: Phase 1E complete - memory+session modules migration + core inf…
May 24, 2026
ae40ebe
feat: Phase 1E completion - code quality, API docs, E2E framework
May 25, 2026
c6e1feb
fix: UTF-8 encoding issue in hot_exec.rs + prepare for Week 9-10 inte…
May 25, 2026
0697926
feat: Week 9-10 cross-team integration - 26+ compilation fixes
May 25, 2026
f23d818
style: unify naming conventions and code style
May 25, 2026
44460dc
docs: publish CONVENTIONS.md v2.1 mixed naming rule (abbrev common +…
May 25, 2026
44d5c0e
refactor(conventions): complete v2.1 naming convention fixes
May 25, 2026
e0b6f1f
CarpAI v1.0.0 - Client-only source release
May 26, 2026
c436c12
Add commercial license
May 26, 2026
82dfa11
CarpAI v1.0.0 - Client-only release (removed server code)
May 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions $null
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ERROR: Invalid syntax. Default option is not allowed more than '1' time(s).
Type "TIMEOUT /?" for usage.
12 changes: 12 additions & 0 deletions .cargo/patches.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ============================================================
# Cargo 依赖补丁 — 将 git 依赖替换为本地 vendor 版本
# 消除供应链风险
#
# 使用方法:
# 运行 scripts/vendor_agentgrep.sh 完成 vendor 后,
# 将本文件重命名为 patches.toml 或直接添加到 config.toml:
# cat patches.toml.example >> config.toml
# ============================================================

[patch."https://github.com/1jehuang/agentgrep.git"]
agentgrep = { path = "crates/vendor-agentgrep" }
40 changes: 39 additions & 1 deletion .claude/mcp.json
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
{"servers":{}}
{
"servers": {
"carpai-github": {
"command": "python",
"args": ["mcp-servers/github/src/server.py"]
},
"carpai-postgres": {
"command": "python",
"args": ["mcp-servers/postgres/src/server.py"],
"env": {
"PG_OFFLINE_FALLBACK": "1"
}
},
"carpai-docker": {
"command": "python",
"args": ["mcp-servers/docker/src/server.py"]
},
"carpai-kubernetes": {
"command": "python",
"args": ["mcp-servers/kubernetes/src/server.py"]
},
"carpai-redis": {
"command": "python",
"args": ["mcp-servers/redis/src/server.py"]
},
"carpai-sentry": {
"command": "python",
"args": ["mcp-servers/sentry/src/server.py"]
},
"carpai-aws": {
"command": "python",
"args": ["mcp-servers/aws/src/server.py"]
},
"carpai-datadog": {
"command": "python",
"args": ["mcp-servers/datadog/src/server.py"]
}
}
}

Large diffs are not rendered by default.

313 changes: 313 additions & 0 deletions .codebuddy/plans/CarpAI_连通-补实-超越_三步整合_be1493c9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
---
name: CarpAI 连通-补实-超越 三步整合
overview: 三阶段重构:(1)连通 - 打通6个独立模块之间的断层(LSP→跨文件修复→多文件编辑→Swarm→MCP→技能系统);(2)补实 - 将占位/空壳实现替换为真实代码(WS层LSP、TypeChecker::check_with_lsp、Sub-Agent执行引擎、StdioTransport);(3)超越 - 实现Swarm+LSP融合(SwarmTurnStrategy、LSP事件桥接、符号级冲突检测),超越Cursor的独立Agent模式
todos:
- id: connect-deps
content: 在根Cargo.toml中添加4个孤岛crate依赖并修复StdioTransport的unimplemented!()致命桩
status: completed
- id: connect-ast-bridge
content: 实现AstEdit→FileSet类型适配器(bridge.rs),打通跨文件修复→多文件原子编辑数据流
status: completed
dependencies:
- connect-deps
- id: connect-ws-lsp
content: WS层4个LSP处理器接入jcode-lsp,替换模拟数据为真实LSP调用
status: completed
dependencies:
- connect-deps
- id: solidify-type-checker
content: TypeChecker::check_with_lsp()注入真实LSP诊断能力(feature门控)
status: completed
dependencies:
- connect-ws-lsp
- id: solidify-ast-multilang
content: TreeSitterAstAdapter升级TypeScript/Python/Go真实tree-sitter解析
status: completed
dependencies:
- connect-ws-lsp
- id: solidify-sub-agent
content: sub_agents.rs execute_task_real()接入实际Provider调用
status: completed
dependencies:
- connect-deps
- id: solidify-self-correction
content: 自修正循环连接AiFixProvider trait,支持LLM修复建议注入
status: completed
dependencies:
- solidify-type-checker
- id: transcend-swarm-strategy
content: 实现SwarmTurnStrategy,在swarm agent turn中注入LSP诊断上下文
status: completed
dependencies:
- solidify-sub-agent
- solidify-self-correction
- id: transcend-lsp-bridge
content: LSP publishDiagnostics→Swarm Channel事件桥接
status: completed
dependencies:
- transcend-swarm-strategy
- id: transcend-conflict-detect
content: 基于LSP符号依赖图的Swarm任务冲突检测
status: completed
dependencies:
- transcend-lsp-bridge
---

## 产品概述

CarpAI 三阶段架构升级:将6个互不连接的独立模块打通为端到端流水线,将占位/空壳实现替换为真实代码,并在连通补实基础上实现Swarm+LSP融合这一Cursor不具备的能力。

## 核心功能

### 阶段一:连通(打通断层)

- 建立LSP诊断 → 跨文件修复引擎的实时诊断管道(替换TypeChecker空桩)
- 实现AstEdit → FileSet类型适配器(打通跨文件修复→多文件原子编辑的数据流)
- 将4个孤岛crate接入主二进制依赖(jcode-cross-file-repair、jcode-multi-file-edit、jcode-skills、jcode-mcp-advanced)
- 修复StdioTransport的unimplemented!()致命桩
- WS层4个LSP处理器从模拟数据切换到真实jcode-lsp调用

### 阶段二:补实(替换空壳)

- TreeSitterAstAdapter non-Rust语言从正则降级升级为真实tree-sitter解析(TypeScript/Python/Go)
- TypeChecker::check_with_lsp()注入jcode-lsp诊断能力,支持非Rust语言
- sub_agents.rs execute_task_real()从格式化字符串空壳替换为实际Provider调用
- jcode-cross-file-repair的自修正循环连接到真实LLM修复建议生成

### 阶段三:超越(Swarm+LSP融合)

- 实现SwarmTurnStrategy(TurnStrategy trait的新实现),在swarm agent turn中自动注入LSP诊断上下文
- LSP publishDiagnostics → Swarm Channel事件桥接,让swarm内所有成员感知编译错误
- 基于LSP符号依赖图的冲突检测,避免多个swarm agent同时修改同一符号
- Sub-Agent执行引擎连接Provider+LSP上下文注入

## 技术栈

- 语言:Rust (edition 2024, workspace统一)
- 异步运行时:tokio
- LSP协议:lsp-types + JSON-RPC over stdio
- AST解析:tree-sitter 0.24 + tree-sitter-rust 0.23(需新增tree-sitter-typescript/tree-sitter-python/tree-sitter-go)
- Agent框架:现有TurnStrategy trait + Agent结构体
- Swarm框架:jcode-swarm-core(ChannelIndex双向索引 + SwarmMemberRecord)
- 构建系统:Cargo workspace

## 实现方案

### 阶段一:连通 — 依赖链打通

**1. 主二进制接入4个孤岛crate**

在根`Cargo.toml`的`[dependencies]`中添加:

- `jcode-cross-file-repair = { path = "crates/jcode-cross-file-repair" }`
- `jcode-multi-file-edit = { path = "crates/jcode-multi-file-edit" }`
- `jcode-skills = { path = "crates/jcode-skills" }`
- `jcode-mcp-advanced = { path = "crates/jcode-mcp-advanced" }`

这4个crate当前编译但未被链接,添加依赖后主二进制可以使用其API。

**2. AstEdit → FileSet 适配器**

核心问题:`jcode-cross-file-repair`输出`Vec<AstEdit>`,`jcode-multi-file-edit`输入`Vec<FileSet>`,类型不兼容。

方案:在`jcode-cross-file-repair`中新增`bridge.rs`模块,实现`AstEdit → FileOperation → FileSet`的转换函数:

- `AstEditOp::ReplaceFunction` → `FileEditOp::Replace { start_line, end_line, new_content }`
- `AstEditOp::AddImport` → `FileEditOp::Insert { line: 1, content }`
- `AstEditOp::RemoveImport` → `FileEditOp::Delete { start_line, end_line }`
- `AstEditOp::ChangeType` → `FileEditOp::Replace`
- `AstEditOp::RenameSymbol` → `FileEditOp::Replace`

在`jcode-cross-file-repair/Cargo.toml`中添加`jcode-multi-file-edit`依赖。

**3. StdioTransport修复**

`crates/jcode-mcp-advanced/src/transport.rs`的`new()`中`write_tx`和`read_rx`使用了`unimplemented!()`。

方案:改为`Option`延迟初始化模式:

- 字段类型改为`Arc<tokio::sync::Mutex<Option<...>>>`
- `new()`中填入`None`
- `connect()`中spawn子进程后设置为`Some(tx)`/`Some(rx)`
- 使用时通过`as_ref().expect("transport not connected")`确保已连接

**4. WS层LSP处理器接入真实jcode-lsp**

`src/ws/handlers/lsp.rs`中4个函数全部返回模拟数据。需要注入`LspServerManager`实例。

方案:

- 在`SessionManager`或WebSocket app state中持有`Arc<LspServerManager>`
- `handle_completion()` → 调用`lsp_manager.get_completion(file, line, character)`
- `handle_definition()` → 调用`lsp_manager.goto_definition(file, line, character)`
- `handle_references()` → 调用`lsp_manager.find_references(file, line, character)`
- `handle_diagnostics()` → 调用`lsp_manager.get_diagnostics(file)`

### 阶段二:补实 — 空壳替换

**5. TypeChecker::check_with_lsp()注入真实诊断**

当前`check_with_lsp()`永远返回`Ok(Vec::new())`。

方案:让`TypeChecker`持有可选的`Arc<LspServerManager>`引用:

```rust
pub struct TypeChecker {
lsp_manager: Option<Arc<LspServerManager>>,
}
impl TypeChecker {
pub fn with_lsp(manager: Arc<LspServerManager>) -> Self { ... }
pub async fn check_with_lsp(&self, file: &str) -> Result<Vec<TypeError>> {
if let Some(lsp) = &self.lsp_manager {
let diags = lsp.get_diagnostics(file).await?;
Ok(diags.into_iter().map(|d| TypeError::from_lsp_diagnostic(d, file)).collect())
} else { Ok(Vec::new()) }
}
}
```

在`jcode-cross-file-repair/Cargo.toml`中添加`jcode-lsp`为可选依赖(feature门控)。

**6. TreeSitterAstAdapter多语言升级**

当前non-Rust语言降级为正则匹配。需要为TypeScript/Python/Go添加真实tree-sitter解析。

方案:

- 添加`tree-sitter-typescript`、`tree-sitter-python`、`tree-sitter-go`依赖(feature门控)
- 在`LanguageKind::TypeScript/Python/Go`分支中调用对应parser
- `find_dependents()`从`line.contains(symbol)`升级为AST级import分析

**7. sub_agents.rs执行引擎**

`execute_task_real()`当前仅格式化输出字符串,未调用任何LLM。

方案:将`SubAgentTask`扩展,持有`Arc<dyn Provider>`引用(或通过回调),使`execute_task_real()`实际发送消息到Provider并收集响应:

- `SubAgentTask`新增`provider: Option<Arc<dyn Provider>>`字段
- `execute_task_real()`检查是否有provider,有则发送instruction+context作为用户消息,收集响应
- 无provider时回退到当前格式化行为(向后兼容)

**8. 自修正循环连接LLM**

`SelfCorrectionLoop::run()`当前的自修正逻辑是基于规则的简单修复。需要连接到LLM获取修复建议。

方案:在`SelfCorrectionLoop`中注入可选的`AiFixProvider` trait:

```rust
pub trait AiFixProvider: Send + Sync {
async fn suggest_fix(&self, request: &AiFixRequest) -> Option<Fix>;
}
```

默认实现使用基于规则的修复(现有逻辑),可选注入LLM provider获取AI修复建议。

### 阶段三:超越 — Swarm+LSP融合

**9. SwarmTurnStrategy实现**

在`src/agent/turn_strategy.rs`中新增`SwarmTurnStrategy`,实现`TurnStrategy` trait:

核心行为(覆盖9个阶段中的关键几个):

- `build_prompt()` — 在系统提示中注入当前文件的LSP诊断信息(编译错误、未使用变量等)
- `inject_memory()` — 注入swarm channel中其他agent的完成报告和LSP诊断事件
- `repair()` — 检查LSP诊断,如果有编译错误则优先修复
- `build_memory()` — 收集swarm channel中的最新事件

数据结构:

```rust
pub struct SwarmTurnStrategy {
swarm_channel: Arc<ChannelIndex>,
lsp_manager: Arc<LspServerManager>,
working_files: Arc<RwLock<Vec<String>>>,
}
```

**10. LSP → Swarm Channel事件桥接**

实现`LspEventBridge`,将LSP的`publishDiagnostics`事件转发到swarm channel:

```rust
pub struct LspEventBridge {
lsp_manager: Arc<LspServerManager>,
swarm_channel: Arc<ChannelIndex>,
}
impl LspEventBridge {
pub async fn start(&self) {
// 订阅LSP诊断事件
// 转换为SwarmMessage::LspDiagnostics
// 广播到swarm channel
}
}
```

**11. 符号级冲突检测**

利用LSP的`textDocument/references`和`textDocument/definition`构建符号依赖图,在swarm任务分配时检测写冲突:

```rust
pub struct SymbolConflictDetector {
lsp_manager: Arc<LspServerManager>,
}
impl SymbolConflictDetector {
pub async fn detect_conflicts(&self, tasks: &[SubAgentTask]) -> Vec<ConflictReport> {
// 对每个任务,提取其修改的符号集合
// 利用LSP references查找每个符号的依赖
// 检测多个任务修改同一符号或互相依赖的符号
}
}
```

在`ParallelTaskScheduler`调度前调用冲突检测,将冲突任务改为串行执行。

## 实现备注

- **编译验证**:每阶段完成后执行`cargo check`验证,避免累积错误
- **Feature门控**:jcode-lsp→jcode-cross-file-repair的依赖用feature门控(`lsp-bridge`),不强制所有消费者引入LSP
- **向后兼容**:SwarmTurnStrategy是新增实现,不影响现有StandardTurnStrategy
- **性能**:LSP诊断注入为异步操作,不阻塞agent turn主路径;符号冲突检测在任务分配时一次性执行
- **资源管理**:共享`LspServerManager`实例避免重复启动语言服务器;StdioTransport修复后MCP stdio传输可用

## 目录结构

```
CarpAI/
├── Cargo.toml # [MODIFY] 添加4个孤岛crate依赖
├── src/
│ ├── agent/
│ │ ├── turn_strategy.rs # [MODIFY] 新增SwarmTurnStrategy实现
│ │ └── turn_loops.rs # [MODIFY] 支持TurnStrategy动态分发
│ ├── sub_agents.rs # [MODIFY] execute_task_real()接入Provider
│ ├── ws/
│ │ ├── handlers/
│ │ │ └── lsp.rs # [MODIFY] 4个处理器接入jcode-lsp
│ │ └── session.rs # [MODIFY] SessionManager持有LspServerManager
│ ├── server/
│ │ └── swarm.rs # [MODIFY] 集成LspEventBridge
│ └── refactor_engine.rs # [MODIFY] 接入jcode-cross-file-repair
├── crates/
│ ├── jcode-cross-file-repair/
│ │ ├── Cargo.toml # [MODIFY] 添加jcode-lsp(feature门控)+jcode-multi-file-edit依赖
│ │ ├── src/
│ │ │ ├── lib.rs # [MODIFY] 导出bridge模块
│ │ │ ├── type_checker.rs # [MODIFY] check_with_lsp()注入真实LSP诊断
│ │ │ ├── ast.rs # [MODIFY] TreeSitterAstAdapter多语言升级
│ │ │ ├── bridge.rs # [NEW] AstEdit → FileSet类型适配器
│ │ │ └── self_correction.rs # [MODIFY] 可选AiFixProvider注入
│ ├── jcode-multi-file-edit/
│ │ └── (无改动,作为下游消费者)
│ ├── jcode-mcp-advanced/
│ │ └── src/transport.rs # [MODIFY] StdioTransport unimplemented→Option
│ ├── jcode-lsp/
│ │ └── (无Cargo.toml改动,新增tree-sitter-* feature门控)
│ └── jcode-swarm-core/
│ └── (无改动,Swarm融合在应用层实现)
```

## Agent Extensions

### SubAgent

- **code-explorer**: 用于在实现各桥接模块时搜索所有引用旧类型/API的文件并批量更新依赖关系和use语句;用于验证类型适配器的完整性
Loading