修复: 代码审查发现的安全与兼容性问题

- git_worktree: commit config 改用 --local 避免污染全局 git config

- git_worktree: merge-tree 改用旧版兼容语法(三参数替代 --write-tree)

- coordinator: executor 'static 约束加注释说明(JoinSet spawn 要求)

- coordinator: Token reserve 按层 SubTask 数累加(原固定 10k 不准确)

- coordinator: 更新结构体注释(反映当前并行实现而非 Phase 1 串行)

- 39 个测试全绿,行为零回归
This commit is contained in:
lxy
2026-07-01 23:37:58 +08:00
parent 3e93a2cd70
commit 840949ad05
2 changed files with 27 additions and 25 deletions
+12 -10
View File
@@ -129,16 +129,15 @@ pub struct ConflictItem {
/// 多 Agent 协作调度器
///
/// # Phase 1(当前)
/// 当前实现:
/// - 规则驱动 decompose(关键词匹配)
/// - dispatch_with_budget: JoinSet 层内并行 + token 预算管控
/// - dispatch_serial: 串行降级路径(无 'static 约束)
/// - merge: 拼接产出 + 同文件冲突检测
///
/// 规则驱动 decompose + 串行 dispatch + 简单拼接 merge。
/// 适用于「读后写」「搜索后分析」等可预测的意图组合。
///
/// # Phase 2(预留)
///
/// - LLM 驱动 decomposeLLM 生成 Plan 结构)
/// - JoinSet 并行 dispatch(层内并行)
/// - Reviewer Agent 仲裁 merge(冲突检测 + 自动解决)
/// Phase 2 预留:
/// - LLM 驱动 decompose
/// - Reviewer Agent 仲裁
pub struct Coordinator {
/// 人设注册表(内置 5 人设 + 自定义)
registry: PersonaRegistry,
@@ -268,6 +267,9 @@ impl Coordinator {
budget: Option<&Arc<TokenBudgetPool>>,
) -> Vec<ExecutionResult>
where
// 'static + Clone 要求:JoinSet::spawn 需要 owned 闭包(不能借用 self/db)。
// 调用方需用 Arc 包裹共享状态(db/session)传入闭包。
// 不需要并行时用 dispatch_serial(无 'static 约束)。
F: Fn(SubTask, String) -> Fut + Clone + Send + Sync + 'static,
Fut: std::future::Future<Output = ExecutionResult> + Send,
{
@@ -308,7 +310,7 @@ impl Coordinator {
}
let can_parallel = budget
.map(|b| b.try_reserve(10_000))
.map(|b| b.try_reserve(layer.len() as u64 * 10_000)) // 每层按 SubTask 数累加
.unwrap_or(true);
if can_parallel {