doukui 0.6.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +85 -18
- package/README.md +32 -72
- package/bin/commands/help.js +2 -25
- package/bin/commands/plan-lint.js +105 -0
- package/bin/commands/verify.js +263 -0
- package/bin/doukui.js +3 -3
- package/package.json +2 -3
- package/plugins/core/hook-session-start/index.js +1 -1
- package/plugins/core/hook-skill-gate/index.js +64 -15
- package/plugins/core/hook-skill-gate/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
- package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +89 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
- package/plugins/core/skill-agent-dispatcher/recovery-reference.md +132 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
- package/plugins/core/skill-agent-dispatcher/skill.md +124 -796
- package/plugins/core/skill-agentic-loop/mirror-rules.md +95 -24
- package/plugins/core/skill-agentic-loop/plugin.json +2 -7
- package/plugins/core/skill-agentic-loop/skill.md +125 -354
- package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
- package/plugins/core/skill-checklist/skill.md +15 -141
- package/plugins/core/skill-completion-report/plugin.json +1 -1
- package/plugins/core/skill-completion-report/skill.md +7 -1
- package/plugins/core/skill-doukui-plan/plugin.json +1 -1
- package/plugins/core/skill-doukui-plan/skill.md +24 -21
- package/plugins/core/skill-experience-logger/plugin.json +1 -1
- package/plugins/core/skill-human-checkpoint/skill.md +1 -0
- package/plugins/core/skill-split-work-package/plugin.json +1 -1
- package/plugins/core/skill-task-creator/plugin.json +1 -1
- package/plugins/core/skill-task-creator/skill.md +1 -139
- package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
- package/plugins/plugin-registry.json +0 -48
- package/plugins/runtime/harness-build.js +5 -5
- package/plugins/runtime/plan-reader.js +54 -21
- package/plugins/runtime/resolve-plugin-path.js +2 -2
- package/templates/harness-config.yaml +0 -100
- package/bin/commands/loop-server.js +0 -357
- package/bin/commands/loop.js +0 -1508
- package/plugins/contracts/capabilities.js +0 -268
- package/plugins/contracts/checkresult-schema.json +0 -75
- package/plugins/core/provider-loop-engine/index.js +0 -1411
- package/plugins/core/provider-loop-engine/plugin.json +0 -15
- package/plugins/core/provider-memory-store/index.js +0 -510
- package/plugins/core/provider-memory-store/plugin.json +0 -9
- package/plugins/core/provider-state-store/index.js +0 -244
- package/plugins/core/provider-state-store/plugin.json +0 -9
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
- package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
- package/plugins/core/provider-watchdog/index.js +0 -151
- package/plugins/core/provider-watchdog/plugin.json +0 -13
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
- package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
- package/plugins/core/skill-watchdog-manager/skill.md +0 -143
- package/plugins/core/validator-doc-sync/index.js +0 -248
- package/plugins/core/validator-doc-sync/plugin.json +0 -12
- package/plugins/core/validator-work-package/index.js +0 -300
- package/plugins/core/validator-work-package/plugin.json +0 -12
- package/plugins/runtime/audit-logger.js +0 -311
- package/plugins/runtime/build-cli.js +0 -89
- package/plugins/runtime/checkresult-validator.js +0 -131
- package/plugins/runtime/context-window.js +0 -81
- package/plugins/runtime/event-bus.js +0 -207
- package/plugins/runtime/executor-claude.js +0 -604
- package/plugins/runtime/executor-default.js +0 -448
- package/plugins/runtime/executor-local.js +0 -178
- package/plugins/runtime/executor-sdk.js +0 -415
- package/plugins/runtime/hook-dispatcher.js +0 -315
- package/plugins/runtime/loop-actuator.js +0 -292
- package/plugins/runtime/loop-coordinator.js +0 -347
- package/plugins/runtime/loop-defaults.js +0 -29
- package/plugins/runtime/loop-dispatch-batch.js +0 -351
- package/plugins/runtime/loop-executor.js +0 -120
- package/plugins/runtime/loop-report.js +0 -395
- package/plugins/runtime/loop-server-core.js +0 -750
- package/plugins/runtime/loop-snapshot.js +0 -581
- package/plugins/runtime/loop-trace.js +0 -242
- package/plugins/runtime/loop-worktree.js +0 -404
- package/plugins/runtime/multi-window-coordinator.js +0 -560
- package/plugins/runtime/objective-verifier.js +0 -136
- package/plugins/runtime/plan-lint.js +0 -106
- package/plugins/runtime/plugin-loader.js +0 -798
- package/plugins/runtime/plugin-trust.js +0 -182
- package/plugins/runtime/provider-failover.js +0 -114
- package/plugins/runtime/provider-resolver.js +0 -342
- package/plugins/runtime/reflection-evaluator.js +0 -545
- package/plugins/runtime/sandbox-context.js +0 -235
- package/plugins/runtime/sandbox-manager.js +0 -609
- package/plugins/runtime/sandbox-worker.js +0 -215
- package/plugins/runtime/self-rescue-ladder.js +0 -51
- package/plugins/runtime/text-tokenize.js +0 -25
- package/plugins/runtime/validator-pipeline.js +0 -475
|
@@ -9,11 +9,7 @@ description: "Use when user says \"批量执行\", \"并行执行\", \"调度子
|
|
|
9
9
|
|
|
10
10
|
## When to Use
|
|
11
11
|
|
|
12
|
-
**触发词**:
|
|
13
|
-
- "批量执行" / "并行执行"
|
|
14
|
-
- "调度子代理" / "派发任务"
|
|
15
|
-
- "执行工作包 WP-XXX, WP-YYY"
|
|
16
|
-
- "开始批量任务"
|
|
12
|
+
**触发词**: "批量执行" / "并行执行" / "调度子代理" / "派发任务" / "执行工作包 WP-XXX, WP-YYY" / "开始批量任务" / "agent-dispatcher"
|
|
17
13
|
|
|
18
14
|
## Quick Reference
|
|
19
15
|
|
|
@@ -22,142 +18,48 @@ description: "Use when user says \"批量执行\", \"并行执行\", \"调度子
|
|
|
22
18
|
| 无依赖的多个工作包 | 并行执行 (每 WP 一个专用 Teamee) |
|
|
23
19
|
| 有依赖链的工作包 | blockedBy 阻塞 + 依赖解除后按需创建 Teamee |
|
|
24
20
|
| 混合依赖 | 监控循环动态创建 + 即时销毁 |
|
|
25
|
-
|
|
26
|
-
---
|
|
21
|
+
| retry / resplit 重做某个 WP | Lead 带 `dispatchTarget` 再调本 skill(Step 8 重派发) |
|
|
27
22
|
|
|
28
23
|
## 团队机制现状 (🔴 必读)
|
|
29
24
|
|
|
30
|
-
Claude Code harness 为 **implicit session team 模式**:每个 session 自动有一个 implicit team,subagent(Teamee)一经 spawn 自动加入,**并行 spawn + SendMessage + 共享 Task List 的协作能力随之可用**。`TeamCreate`/`TeamDelete`
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
- **`team-cleanup` CLI 仅用于清理历史残留**的显式/UUID 团队目录(旧机制遗留),非当前 session team。
|
|
36
|
-
- `roles-reference.md` 的 Prompt 模板若含历史措辞(`团队名称: {team_name}`、shutdown 协议帧),以 `build_single_task_prompt()` 行为为准,忽略之。
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## Architecture
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
┌─────────────────────────────────────────────────────────────┐
|
|
44
|
-
│ Team Lead (主 Agent) │
|
|
45
|
-
│ │
|
|
46
|
-
│ 1. 解析工作包 → 分析依赖 │
|
|
47
|
-
│ 2. 初始化批次标签 team_name (Lead 内部逻辑标识) │
|
|
48
|
-
│ 3. TaskCreate 创建任务 + 设置 blockedBy │
|
|
49
|
-
│ 4. 角色匹配 → 预计算每个 WP 的角色和记忆 │
|
|
50
|
-
│ 5. 监控循环: │
|
|
51
|
-
│ - 检测 newly-unblocked 任务 → 按需创建专用 Teamee (1:1) │
|
|
52
|
-
│ - 检测已完成的任务 → 即时销毁对应 Teamee │
|
|
53
|
-
│ - 维护映射表 {task_id → teamee_name} │
|
|
54
|
-
│ 6. 全部完成后逻辑销毁 + 可选 team-cleanup 清理历史残留 │
|
|
55
|
-
│ 7. 经验提取 + completion-report │
|
|
56
|
-
└─────────────────────────────────────────────────────────────┘
|
|
57
|
-
│
|
|
58
|
-
┌─────────────────────┼─────────────────────┐
|
|
59
|
-
▼ ▼ ▼
|
|
60
|
-
┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
61
|
-
│ Teamee A │ │ Teamee B │ │ Teamee C │
|
|
62
|
-
│ WP-037 │ │ WP-038 │ │ WP-039 │
|
|
63
|
-
│ (或四位如 │ │ WP-1038 │ │ WP-1039 │)
|
|
64
|
-
│ 专用绑定 │ │ 专用绑定 │ │ 专用绑定 │
|
|
65
|
-
└────┬─────┘ └────┬─────┘ └────┬─────┘
|
|
66
|
-
│ 已完成 │ 执行中 │ blockedBy #2
|
|
67
|
-
│ 即时销毁 │ │ 等待创建
|
|
68
|
-
▼ ▼ ▼
|
|
69
|
-
┌───────────────────────────────┐
|
|
70
|
-
│ 共享 Task List │
|
|
71
|
-
│ Task #1: WP-037 (completed) │
|
|
72
|
-
│ Task #2: WP-038 (in_progress)│
|
|
73
|
-
│ Task #3: WP-039 (blockedBy #2)│
|
|
74
|
-
└───────────────────────────────┘
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
---
|
|
25
|
+
Claude Code harness 为 **implicit session team 模式**:每个 session 自动有一个 implicit team,subagent(Teamee)一经 spawn 自动加入,**并行 spawn + SendMessage + 共享 Task List 的协作能力随之可用**。`TeamCreate`/`TeamDelete` 工具已移除。运行规则:
|
|
26
|
+
- **`team_name` 是 Lead 内部的批次逻辑标签**,仅用于执行报告标识;不进 Agent 参数、不驱动团队创建、不作 team-cleanup 目标。
|
|
27
|
+
- **Teamee 销毁走逻辑销毁**(`markTeameeDestroyed`,从映射表移除),无协议帧;session team 随 session 自动清理(`team-cleanup` CLI 只清历史残留目录,见下文)。
|
|
28
|
+
- **持久化口径**:PROGRESS.md 为唯一持久层,dispatcher 不写自有 state 文件;上下文压缩恢复 = 读 TaskList + PROGRESS.md 该轮 history。
|
|
29
|
+
- **人介入通道**:pause / abort / 全局终止 = 直接告知 Lead(skill-agentic-loop Step 6 既有语义),无文件指令通道。
|
|
78
30
|
|
|
79
31
|
## SendMessage 使用规范 (🔴 必须遵守)
|
|
80
32
|
|
|
81
|
-
1. **🔴 绝不携带 protocol frame**(`shutdown_request` / `shutdown_response` / `permission` / `mode` / `plan` 的 JSON)——harness
|
|
33
|
+
1. **🔴 绝不携带 protocol frame**(`shutdown_request` / `shutdown_response` / `permission` / `mode` / `plan` 的 JSON)——harness 工具层直接拦截报错,根本不要尝试。
|
|
82
34
|
2. **只用于纯文本状态沟通**,且**必须带 summary 参数**(5-10 词预览):`SendMessage(to=target, summary="Task 1 status update", message="Task #1 已完成进度 50%")`
|
|
83
|
-
3. **Teamee 销毁走逻辑销毁**(`markTeameeDestroyed(teamee_map, task_id)
|
|
84
|
-
4. **历史残留团队目录清理走确定性 CLI
|
|
85
|
-
|
|
86
|
-
**原则**:SendMessage 是**纯文本沟通通道**;Teamee 生命周期管理(销毁/清理)走**逻辑销毁 + CLI**,两者解耦。
|
|
87
|
-
|
|
88
|
-
---
|
|
35
|
+
3. **Teamee 销毁走逻辑销毁**(`markTeameeDestroyed(teamee_map, task_id)`),不依赖任何协议帧,无需等待响应、无需发送 shutdown。
|
|
36
|
+
4. **历史残留团队目录清理走确定性 CLI**(按需执行):`node bin/doukui.js team-cleanup <residual_team_name> --force`——CLI 直接走文件系统删除,不调用 TeamDelete。
|
|
89
37
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
解析工作包清单 → 分析依赖 → 检测循环依赖(有则报错退出)
|
|
94
|
-
→ 初始化批次标签 team_name → TaskCreate + 设置 blockedBy
|
|
95
|
-
→ 角色匹配(预计算,Read roles-reference.md)
|
|
96
|
-
→ 监控循环(Step 6.5):
|
|
97
|
-
检测 newly-unblocked → 创建专用 Teamee(预分配 owner)
|
|
98
|
-
检测已完成 → 逻辑销毁对应 Teamee
|
|
99
|
-
所有任务 completed 或超时 → 退出循环
|
|
100
|
-
→ 逻辑销毁残留 + 可选 team-cleanup CLI → 经验提取 → 生成执行报告
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
---
|
|
38
|
+
**原则**:SendMessage 是**纯文本沟通通道**;Teamee 生命周期管理走**逻辑销毁 + CLI**,两者解耦。
|
|
104
39
|
|
|
105
40
|
## Step-by-Step Implementation
|
|
106
41
|
|
|
107
42
|
### Step 1: 解析工作包 + 分析依赖
|
|
108
43
|
|
|
109
|
-
|
|
110
|
-
1. 读取 task.md 获取下一个可用 WP 编号
|
|
111
|
-
2. 提取待执行工作包的依赖关系
|
|
112
|
-
3. 构建依赖图,检测循环依赖
|
|
113
|
-
4. 确定执行顺序(拓扑排序)
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Step 2: 初始化批次标签 team_name
|
|
117
|
-
|
|
118
|
-
> ⚠️ **语义变更(implicit session team 模式)**: `team_name` **不再调用 TeamCreate**(工具已移除),也**不再作为 Agent 调用的参数**(harness 已忽略)。它现在只是 Lead 内部的"批次逻辑标签",用于状态文件、心跳、执行报告标识"这批执行"。实际团队由 harness 自动分配 implicit session team。
|
|
119
|
-
|
|
120
|
-
```
|
|
121
|
-
# Lead 内部变量赋值(无工具调用)
|
|
122
|
-
team_name = "batch-{YYYYMMDD}-{work-package-ids}" # 批次逻辑标签,非 harness 团队名
|
|
123
|
-
# 实际 harness 团队是 implicit session-xxx,由 session 自动分配,Lead 无需也无法干预
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
**命名规范(批次标签,仅用于标识/可读性)**:
|
|
127
|
-
- 单工作包: `batch-20260314-WP073` / `batch-20260314-WP1073`
|
|
128
|
-
- 批量工作包: `batch-20260314-WP073-075` / `batch-20260314-WP1073-1075`
|
|
44
|
+
读 task.md 取下一个可用 WP 编号 → 提取待执行工作包的依赖关系 → 构建依赖图并检测循环依赖(有环报错退出)→ 拓扑排序确定执行顺序。
|
|
129
45
|
|
|
130
|
-
|
|
131
|
-
- 写入 `dispatcher-state.json` / `heartbeat.json`(见 Step 6.5)
|
|
132
|
-
- idle 检测的批次一致性校验 `assignment.team_name == team_name`(见 Phase D2-idle)
|
|
133
|
-
- 执行报告的批次标识(见 Execution Report)
|
|
46
|
+
### Step 2: 批次标签 team_name(Lead 内部变量,无工具调用)
|
|
134
47
|
|
|
135
|
-
|
|
136
|
-
- ❌ 不作为 `Agent(team_name=...)` 参数(harness 已忽略)
|
|
137
|
-
- ❌ 不驱动 TeamCreate(工具已移除)
|
|
138
|
-
- ❌ 不作为 team-cleanup CLI 的目标(team-cleanup 用于历史残留,当前 session team 自动清理)
|
|
48
|
+
`team_name = "batch-{YYYYMMDD}-{work-package-ids}"`(单工作包 `batch-20260314-WP073`,批量 `batch-20260314-WP073-075`),仅用于执行报告的批次标识。
|
|
139
49
|
|
|
140
50
|
### Step 3: 创建任务 + 设置依赖
|
|
141
51
|
|
|
142
52
|
```
|
|
143
|
-
# 为每个工作包创建 Task
|
|
144
|
-
|
|
145
53
|
TaskCreate:
|
|
146
54
|
subject: "WP-037: 凝视区域形状升级"
|
|
147
55
|
description: |
|
|
148
56
|
## 📖 必读:工作包文档
|
|
149
|
-
|
|
150
|
-
**执行前请先阅读工作包文档获取完整上下文:**
|
|
151
|
-
- 文档路径: `docs/wp/WP-037.md`
|
|
152
|
-
- 包含: 问题分析、实施计划、关键文件、验收标准
|
|
153
|
-
|
|
57
|
+
- 文档路径: `docs/wp/WP-037.md`(问题分析、实施计划、关键文件、验收标准)
|
|
154
58
|
---
|
|
155
|
-
|
|
156
59
|
{工作包简要描述}
|
|
157
60
|
status: pending
|
|
158
61
|
|
|
159
|
-
# 设置依赖关系
|
|
160
|
-
TaskUpdate:
|
|
62
|
+
TaskUpdate: # 设置依赖关系
|
|
161
63
|
taskId: "{依赖任务的 ID}"
|
|
162
64
|
addBlockedBy: ["{被依赖任务的 ID}"]
|
|
163
65
|
```
|
|
@@ -166,17 +68,9 @@ TaskUpdate:
|
|
|
166
68
|
|
|
167
69
|
### Step 4-5: 角色匹配 + 记忆准备
|
|
168
70
|
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
Read("plugins/core/skill-agent-dispatcher/roles-reference.md")
|
|
172
|
-
```
|
|
71
|
+
📖 执行前 Read `plugins/core/skill-agent-dispatcher/roles-reference.md`:**Step 4** 角色匹配算法(关键词/任务类型/模块标签加权评分)、**Step 5** 预计算角色和记忆的流程、角色赋能系统、记忆注入机制、经验沉淀闭环。
|
|
173
72
|
|
|
174
|
-
|
|
175
|
-
- **Step 4**: 角色匹配算法(关键词/任务类型/模块标签加权评分)
|
|
176
|
-
- **Step 5**: 预计算角色和记忆的完整流程
|
|
177
|
-
- **角色赋能系统**: 核心角色表、领域角色表、角色文件位置
|
|
178
|
-
- **记忆注入机制**: 经验提取逻辑、动态数量、回退机制
|
|
179
|
-
- **经验沉淀闭环**: 执行完成后的经验提取流程
|
|
73
|
+
**模型分级提示**: role YAML 声明 `model` 字段时,先 `doukui build` 生成 `.claude/agents/{roleId}.md`,之后 Teamee 按 frontmatter model 路由(spawn 时走 Step 6 双分支路由)。
|
|
180
74
|
|
|
181
75
|
### Step 6: 初始创建 Teamee(首次可用任务)
|
|
182
76
|
|
|
@@ -186,47 +80,38 @@ Step 5 完成后,立即检查有哪些任务的 blockedBy 已满足。
|
|
|
186
80
|
不可跳过此步骤!
|
|
187
81
|
</HARD-GATE>
|
|
188
82
|
|
|
189
|
-
**⚠️
|
|
83
|
+
**⚠️ 重要: Teamee spawn 路由双分支规则(全流程所有 spawn 点统一遵循,下文各处不再重复)**:
|
|
190
84
|
|
|
191
|
-
|
|
192
|
-
|
|
85
|
+
- **存在生成物 `.claude/agents/{roleId}.md` → `subagent_type={roleId}`**(Claude Code 按其 frontmatter model 路由模型,实现 per-role 模型分级)
|
|
86
|
+
- **无生成物 → 回退 `subagent_type="general-purpose"`**(Prompt 携带角色赋能,与历史行为一致)
|
|
87
|
+
- 判定方法:spawn 前查该角色 id 的 `.claude/agents/{roleId}.md` 是否存在(一次 ls/glob)
|
|
193
88
|
|
|
194
89
|
```
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
wp_doc_path=assignment.wp_doc_path
|
|
221
|
-
)
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
# 记录映射关系
|
|
225
|
-
teamee_map[task.id] = teamee_name
|
|
226
|
-
|
|
227
|
-
# ---- 1:1 映射验证 ----
|
|
228
|
-
all_tasks_verify = TaskList()
|
|
229
|
-
unblocked_verify = [t for t in all_tasks_verify if t.status == "pending" and is_unblocked(t)]
|
|
90
|
+
def resolve_subagent_type(role_id):
|
|
91
|
+
"""spawn 路由双分支(全流程唯一判定点,各 spawn 处调用)"""
|
|
92
|
+
return role_id if file_exists(f".claude/agents/{role_id}.md") else "general-purpose"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
两个分支都禁止使用 `Explore` 或其他只读 agent 类型(没有 Write/Edit/Bash,无法写代码/改文件/跑测试)。
|
|
96
|
+
|
|
97
|
+
**标准 spawn 块**(Step 6 初始创建、Step 6.5 Phase C、Step 8 重派发统一复用;重派发仅命名/prompt/idle 计数不同,见 Step 8):
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
teamee_map = {} # {task_id: teamee_name}
|
|
101
|
+
idle_state = {} # {task_id: {started_at, idle_nudge_sent, retry_count}} idle 自愈状态,Lead 循环内变量
|
|
102
|
+
|
|
103
|
+
for task in [t for t in TaskList() if t.status == "pending" and is_unblocked(t)]: # Step 6.5 加 t.owner == "" and t.id not in teamee_map
|
|
104
|
+
assignment = wp_assignments[task.id]
|
|
105
|
+
teamee_name = f"{assignment.role_id}-t{task.id}"
|
|
106
|
+
TaskUpdate(taskId=task.id, owner=teamee_name) # 预分配 owner
|
|
107
|
+
Agent(name=teamee_name, subagent_type=resolve_subagent_type(assignment.role_id), # 双分支路由;自动加入 implicit session team
|
|
108
|
+
prompt=build_single_task_prompt(teamee_name, task.id, assignment.role_prompt, assignment.memories, assignment.wp_doc_path))
|
|
109
|
+
teamee_map[task.id] = teamee_name
|
|
110
|
+
idle_state[task.id] = {"started_at": now(), "idle_nudge_sent": False, "retry_count": 0}
|
|
111
|
+
# 输出: "为任务 {task.id} 创建专用 Teamee: {teamee_name}";spawn 事件写入 PROGRESS.md
|
|
112
|
+
|
|
113
|
+
# ---- 1:1 映射验证(仅 Step 6 初始创建时)----
|
|
114
|
+
unblocked_verify = [t for t in TaskList() if t.status == "pending" and is_unblocked(t)]
|
|
230
115
|
if len(teamee_map) != len(unblocked_verify):
|
|
231
116
|
# 输出: "⚠️ 验证失败: 有 {len(unblocked_verify)} 个已解除阻塞的 WP 但只创建了 {len(teamee_map)} 个 Teamee"
|
|
232
117
|
# 输出: "❌ 这可能意味着某些 WP 被错误合并。请检查以上步骤是否严格遵循 1:1 映射规则。"
|
|
@@ -246,736 +131,179 @@ Lead Agent 必须进入监控循环,不可跳过!
|
|
|
246
131
|
</HARD-GATE>
|
|
247
132
|
|
|
248
133
|
```
|
|
249
|
-
#
|
|
250
|
-
|
|
251
|
-
#
|
|
252
|
-
# 1. 任务完成 → 调 markTeameeDestroyed(teamee_map, task_id) 逻辑销毁(无协议帧)
|
|
253
|
-
# 2. SendMessage 仅用于纯文本状态沟通(必须带 summary),绝不携带 protocol frame
|
|
254
|
-
# (shutdown/permission/mode/plan JSON 一律禁止,harness 会拦截报错)
|
|
255
|
-
# 3. 下文所有「输出:」注释均为**直接文本输出**(写进回复正文),禁止用 SendMessage 发送
|
|
134
|
+
# 基础规则 (🔴 必须遵守):
|
|
135
|
+
# 1. 任务完成 → markTeameeDestroyed(teamee_map, task_id) 逻辑销毁(无协议帧)
|
|
136
|
+
# 2. 下文所有「输出:」注释均为**直接文本输出**(写进回复正文),禁止用 SendMessage 发送;SendMessage 规范见上文
|
|
256
137
|
|
|
257
138
|
loop_interval = 30 # 秒
|
|
258
139
|
max_wait_time = 7200 # 2 小时
|
|
140
|
+
start_time = now()
|
|
141
|
+
# 上下文压缩恢复:读 PROGRESS.md 该轮 history(spawn / 催促 / 重 spawn 事件)重建 teamee_map 与 idle_state;
|
|
142
|
+
# idle_state 不可恢复时按空处理(最坏后果 = 已催促的 Teamee 再被催促一次)
|
|
259
143
|
|
|
260
|
-
# ---- 状态持久化初始化 (防上下文压缩丢失) ----
|
|
261
|
-
state_file = ".claude-daemon/dispatcher-state.json"
|
|
262
|
-
heartbeat_file = ".claude-daemon/heartbeat.json"
|
|
263
|
-
daemon_actions_file = ".claude-daemon/daemon-actions.json"
|
|
264
|
-
|
|
265
|
-
# ---- 多窗口环境检测 ----
|
|
266
|
-
# 当 DOUKUI_MULTI_WINDOW_SESSION 和 DOUKUI_WINDOW_ID 环境变量同时存在时,
|
|
267
|
-
# 将状态文件写入 windows/{window_id}/ 子目录,支持协调器聚合
|
|
268
|
-
multi_window_session = env("DOUKUI_MULTI_WINDOW_SESSION")
|
|
269
|
-
window_id = env("DOUKUI_WINDOW_ID")
|
|
270
|
-
is_multi_window = bool(multi_window_session and window_id)
|
|
271
|
-
|
|
272
|
-
if is_multi_window:
|
|
273
|
-
state_dir = f".claude-daemon/windows/{window_id}"
|
|
274
|
-
ensure_dir(state_dir)
|
|
275
|
-
state_file = f"{state_dir}/state.json"
|
|
276
|
-
heartbeat_file = f"{state_dir}/heartbeat.json"
|
|
277
|
-
|
|
278
|
-
# ---- 状态恢复统一通道(初始恢复与每轮 Phase 0 共用,防三处手抄漂移) ----
|
|
279
|
-
def restore_from_state(state):
|
|
280
|
-
"""从 state payload 恢复关键变量(缺失字段保当前值/默认值):
|
|
281
|
-
team_name / teamee_map / wp_assignments / start_time(parse_iso8601) /
|
|
282
|
-
loop_iteration / processed_action_ids / max_batch_size(默认5) /
|
|
283
|
-
current_batch / pending_batches / global_pause_flag(默认False)。"""
|
|
284
|
-
...
|
|
285
|
-
|
|
286
|
-
# 检查是否存在已有状态文件(上下文压缩后恢复)
|
|
287
|
-
if file_exists(state_file):
|
|
288
|
-
try:
|
|
289
|
-
existing_state = json_loads(Read(file_path=state_file))
|
|
290
|
-
except Exception as e:
|
|
291
|
-
# 输出: "⚠️ 状态文件解析失败,使用默认初始状态: {e}"
|
|
292
|
-
existing_state = {}
|
|
293
|
-
if existing_state.get("status") == "monitoring":
|
|
294
|
-
restore_from_state(existing_state) # 上下文压缩后重新进入走此分支
|
|
295
|
-
# 输出: "从状态文件恢复: {len(teamee_map)} 个活跃 Teamee, 迭代 {loop_iteration}"
|
|
296
|
-
|
|
297
|
-
# ---- 批量大小控制参数 ----
|
|
298
|
-
max_batch_size = get_config("agent_dispatcher.max_batch_size", default=5)
|
|
299
|
-
current_batch = current_batch if 'current_batch' in locals() else []
|
|
300
|
-
pending_batches = pending_batches if 'pending_batches' in locals() else []
|
|
301
|
-
|
|
302
|
-
# ---- 状态写回统一通道(全循环唯一构造点,防五处手抄漂移) ----
|
|
303
|
-
def build_state_payload(status="monitoring"):
|
|
304
|
-
"""构造 dispatcher-state.json 完整 payload。
|
|
305
|
-
字段:team_name / teamee_map / wp_assignments / start_time / loop_iteration /
|
|
306
|
-
processed_action_ids / total_tasks / status / max_batch_size / current_batch /
|
|
307
|
-
pending_batches / global_pause_flag。
|
|
308
|
-
多窗口模式(is_multi_window)自动附加 window_id + session_id。
|
|
309
|
-
completed 终态时省略 global_pause_flag。"""
|
|
310
|
-
payload = { ...上述字段全部取自当前变量... }
|
|
311
|
-
if is_multi_window:
|
|
312
|
-
payload["window_id"] = window_id
|
|
313
|
-
payload["session_id"] = multi_window_session
|
|
314
|
-
return payload
|
|
315
|
-
|
|
316
|
-
def write_state(status="monitoring"):
|
|
317
|
-
"""build_state_payload + Write(state_file)。每次 teamee_map / processed_action_ids /
|
|
318
|
-
批次变更后必须调用(防上下文压缩丢失)。"""
|
|
319
|
-
Write(file_path=state_file, content=json_dumps(build_state_payload(status)))
|
|
320
|
-
|
|
321
|
-
# 首次写入状态文件
|
|
322
|
-
write_state("monitoring")
|
|
323
|
-
|
|
324
|
-
start_time = start_time if 'start_time' in locals() else now()
|
|
325
144
|
while (now() - start_time) < max_wait_time:
|
|
326
145
|
loop_iteration += 1
|
|
146
|
+
tasks = TaskList() # ---- Phase A ----
|
|
327
147
|
|
|
328
|
-
# ---- Phase
|
|
329
|
-
if file_exists(state_file):
|
|
330
|
-
try:
|
|
331
|
-
state = json_loads(Read(file_path=state_file))
|
|
332
|
-
except Exception as e:
|
|
333
|
-
# 输出: "⚠️ 状态文件解析失败,使用当前内存状态继续: {e}"
|
|
334
|
-
state = {}
|
|
335
|
-
restore_from_state(state)
|
|
336
|
-
|
|
337
|
-
# ---- Phase 0.1: 多窗口阶段信号检查 ----
|
|
338
|
-
# 读取 multi-window-session.json,检查当前窗口的阶段是否就绪
|
|
339
|
-
if is_multi_window:
|
|
340
|
-
session_file = ".claude-daemon/multi-window-session.json"
|
|
341
|
-
try:
|
|
342
|
-
session_data = json_loads(Read(file_path=session_file))
|
|
343
|
-
except Exception:
|
|
344
|
-
session_data = None
|
|
345
|
-
|
|
346
|
-
if session_data:
|
|
347
|
-
my_stage = None
|
|
348
|
-
for s in session_data.get("stages", []):
|
|
349
|
-
if window_id in s.get("windows", []):
|
|
350
|
-
my_stage = s
|
|
351
|
-
break
|
|
352
|
-
|
|
353
|
-
if my_stage:
|
|
354
|
-
if my_stage.get("status") == "pending":
|
|
355
|
-
# 当前阶段未就绪,跳过本轮 Teamee 创建
|
|
356
|
-
# 输出: "⏸ 窗口 {window_id} 阶段 {my_stage['stage_id']} 尚未就绪,等待阶段信号"
|
|
357
|
-
pass # 跳过后续 Phase C 创建逻辑(通过标志控制)
|
|
358
|
-
elif my_stage.get("status") == "completed":
|
|
359
|
-
# 当前阶段已完成,检查是否有下一阶段
|
|
360
|
-
next_stage = None
|
|
361
|
-
for s in session_data.get("stages", []):
|
|
362
|
-
if s.get("stage_id") == my_stage.get("stage_id") + 1:
|
|
363
|
-
next_stage = s
|
|
364
|
-
break
|
|
365
|
-
if next_stage and next_stage.get("status") == "active":
|
|
366
|
-
# 切换到下一阶段的任务
|
|
367
|
-
assigned_wps = next_stage.get("work_packages", assigned_wps)
|
|
368
|
-
current_stage = next_stage.get("stage_id", current_stage)
|
|
369
|
-
# 输出: "🔄 窗口 {window_id} 切换到阶段 {next_stage['stage_id']}: {next_stage.get('name', '')}"
|
|
370
|
-
|
|
371
|
-
# ---- Phase A: 获取任务状态 ----
|
|
372
|
-
tasks = TaskList()
|
|
373
|
-
|
|
374
|
-
# ---- Phase A.1: 写入守护进程心跳 (DISP-001) ----
|
|
375
|
-
# 每轮监控循环迭代写入心跳文件,供外部守护进程监控
|
|
376
|
-
heartbeat_data = {
|
|
377
|
-
"session_id": "{team_name}",
|
|
378
|
-
"pid": get_process_pid(), # 通过 Bash `echo $$` 或 process.pid 获取
|
|
379
|
-
"team_name": "{team_name}",
|
|
380
|
-
"loop_iteration": loop_iteration,
|
|
381
|
-
"total_tasks": len(tasks),
|
|
382
|
-
"completed_tasks": count(t.status == "completed" for t in tasks),
|
|
383
|
-
"in_progress_tasks": count(t.status == "in_progress" for t in tasks),
|
|
384
|
-
"pending_tasks": count(t.status == "pending" for t in tasks),
|
|
385
|
-
"last_update": now_iso8601(),
|
|
386
|
-
"status": "monitoring" # monitoring / shutting_down / completed
|
|
387
|
-
}
|
|
388
|
-
# 多窗口模式下增加 window_id 字段
|
|
389
|
-
if is_multi_window:
|
|
390
|
-
heartbeat_data["window_id"] = window_id
|
|
391
|
-
Write(file_path=heartbeat_file, content=json_dumps(heartbeat_data))
|
|
392
|
-
|
|
393
|
-
# ---- Phase B: 逻辑销毁已完成的 Teamee(无协议帧) ----
|
|
394
|
-
for task in tasks:
|
|
148
|
+
for task in tasks: # ---- Phase B: 逻辑销毁已完成的 Teamee ----
|
|
395
149
|
if task.status == "completed" and task.id in teamee_map:
|
|
396
|
-
|
|
397
|
-
# 输出: "任务 {task.id} 已完成,逻辑销毁 Teamee: {teamee_name}"
|
|
398
|
-
|
|
399
|
-
# B1. 逻辑销毁:从映射表移除(不发任何协议帧;in-process Teamee 随 session 终止)
|
|
150
|
+
# 输出: "任务 {task.id} 已完成,逻辑销毁 Teamee: {teamee_map[task.id]}"
|
|
400
151
|
markTeameeDestroyed(teamee_map, task.id)
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
# B2. 更新任务状态文件 (DISP-002)
|
|
404
|
-
# Teamee 完成后更新对应的 task-{id}.json 文件
|
|
405
|
-
update_task_file(task.id, status="completed")
|
|
152
|
+
idle_state.pop(task.id, None)
|
|
406
153
|
|
|
407
|
-
|
|
408
|
-
write_state("monitoring")
|
|
409
|
-
|
|
410
|
-
# ---- Phase C: 按需创建 Teamee 处理 newly-unblocked 任务 ----
|
|
411
|
-
# C0. 读取并发配置,计算当前时段的并发上限
|
|
412
|
-
concurrency_config = get_config("agent_dispatcher.concurrency")
|
|
413
|
-
max_concurrent = get_max_concurrent(concurrency_config, now())
|
|
154
|
+
max_concurrent = get_max_concurrent(get_config("agent_dispatcher.concurrency"), now()) # ---- Phase C ----
|
|
414
155
|
active_count = len(teamee_map)
|
|
415
|
-
|
|
416
|
-
# ---- C0.2 批量大小控制 ----
|
|
417
|
-
# 收集本轮可创建的 unblocked 任务,按 max_batch_size 分批
|
|
418
|
-
unblocked_candidates = sorted([t for t in tasks if t.status == "pending" and t.owner == "" and is_unblocked(t) and t.id not in teamee_map], key=lambda t: t.id)
|
|
419
|
-
# 如果当前批次有活跃任务,不创建新批次(等当前批次完成)
|
|
420
|
-
current_batch_active = any(tid in teamee_map for tid in current_batch) if current_batch else False
|
|
421
|
-
|
|
422
|
-
if unblocked_candidates and not current_batch_active:
|
|
423
|
-
# 取前 max_batch_size 个作为当前批次
|
|
424
|
-
current_batch = [t.id for t in unblocked_candidates[:max_batch_size]]
|
|
425
|
-
overflow = unblocked_candidates[max_batch_size:]
|
|
426
|
-
if overflow:
|
|
427
|
-
pending_batches.extend([t.id for t in overflow])
|
|
428
|
-
# 输出: "批量控制: 当前批次 {len(current_batch)} 个任务, 待处理批次 {len(pending_batches)} 个任务"
|
|
429
|
-
|
|
430
156
|
for task in tasks:
|
|
431
157
|
if task.status == "pending" and task.owner == "" and is_unblocked(task):
|
|
432
|
-
# C0.1
|
|
433
|
-
if active_count >= max_concurrent:
|
|
158
|
+
if active_count >= max_concurrent: # C0.1 并发上限(含 schedules 时段匹配)
|
|
434
159
|
# 输出: "并发上限 {max_concurrent} 已达,任务 {task.id} 保持 pending"
|
|
435
160
|
continue
|
|
436
|
-
|
|
437
|
-
# C0.3 批量控制:只处理当前批次内的任务
|
|
438
|
-
if current_batch and task.id not in current_batch:
|
|
161
|
+
if task.id in teamee_map: # C1. 防止重复创建
|
|
439
162
|
continue
|
|
440
|
-
|
|
441
|
-
# C1. 检查是否已有映射(防止重复创建)
|
|
442
|
-
if task.id in teamee_map:
|
|
443
|
-
continue
|
|
444
|
-
|
|
445
|
-
# C2. 从预计算结果获取角色信息
|
|
446
|
-
assignment = wp_assignments[task.id]
|
|
447
|
-
teamee_name = f"{assignment.role_id}-t{task.id}"
|
|
448
|
-
|
|
449
|
-
# C3. 预分配 owner
|
|
450
|
-
TaskUpdate(taskId=task.id, owner=teamee_name)
|
|
451
|
-
|
|
452
|
-
# C4. 创建专用 Teamee(自动加入 implicit session team,无需 team_name 参数)
|
|
453
|
-
Agent(
|
|
454
|
-
name=teamee_name,
|
|
455
|
-
subagent_type="general-purpose",
|
|
456
|
-
prompt=build_single_task_prompt(
|
|
457
|
-
teamee_name=teamee_name,
|
|
458
|
-
task_id=task.id,
|
|
459
|
-
role_prompt=assignment.role_prompt,
|
|
460
|
-
memories=assignment.memories,
|
|
461
|
-
wp_doc_path=assignment.wp_doc_path
|
|
462
|
-
)
|
|
463
|
-
)
|
|
464
|
-
|
|
465
|
-
# C5. 记录映射关系
|
|
466
|
-
teamee_map[task.id] = teamee_name
|
|
163
|
+
<执行 Step 6「标准 spawn 块」的单任务体> # C2-C5:预计算角色 → 命名 → 预分配 owner → Agent → 记录映射与 idle_state
|
|
467
164
|
active_count += 1
|
|
468
|
-
# 输出: "为任务 {task.id} 创建专用 Teamee: {teamee_name}"
|
|
469
|
-
|
|
470
|
-
# C6. 创建任务状态文件 (DISP-002)
|
|
471
|
-
# Teamee 创建后初始化对应的 task-{id}.json 文件
|
|
472
|
-
create_task_file(
|
|
473
|
-
task_id=task.id,
|
|
474
|
-
wp_id=assignment.wp_id,
|
|
475
|
-
teamee_name=teamee_name,
|
|
476
|
-
status="in_progress",
|
|
477
|
-
complexity_score=assignment.complexity_score
|
|
478
|
-
)
|
|
479
|
-
|
|
480
|
-
# ---- Phase C.5: 状态持久化写回 (teamee_map 变更) ----
|
|
481
|
-
write_state("monitoring")
|
|
482
|
-
|
|
483
|
-
# ---- Phase D.1: 读取守护进程指令 (DISP-003) ----
|
|
484
|
-
# 在判断退出条件前,读取守护进程下发的指令
|
|
485
|
-
daemon_actions_path = ".claude-daemon/daemon-actions.json"
|
|
486
|
-
if file_exists(daemon_actions_path):
|
|
487
|
-
actions_data = Read(file_path=daemon_actions_path)
|
|
488
|
-
try:
|
|
489
|
-
actions = json_loads(actions_data).get("actions", [])
|
|
490
|
-
except Exception as e:
|
|
491
|
-
# 输出: "⚠️ 守护进程指令文件解析失败,跳过本轮指令: {e}"
|
|
492
|
-
actions = []
|
|
493
|
-
|
|
494
|
-
for action in actions:
|
|
495
|
-
# 检查指令是否已被处理
|
|
496
|
-
if action.get("id") in processed_action_ids:
|
|
497
|
-
continue
|
|
498
165
|
|
|
499
|
-
|
|
500
|
-
action_type = action.get("action")
|
|
501
|
-
strategy = action.get("strategy", "full_restart")
|
|
502
|
-
reason = action.get("reason", "")
|
|
503
|
-
# 读取 Agentic Loop 下发的失败项明细(refine 通道,WP-176-6):
|
|
504
|
-
# 来源 skill-agentic-loop Step 4.2 的 dispatchTarget.failingDrivers,
|
|
505
|
-
# 每项 {wpId, category, item, reason};仅 retry/resplit 有值,dispatch 首次执行为空。
|
|
506
|
-
failing_drivers = action.get("failing_drivers", [])
|
|
507
|
-
|
|
508
|
-
if action_type == "restart":
|
|
509
|
-
# 重启指令: 逻辑销毁旧 Teamee → 创建新 Teamee
|
|
510
|
-
if target_task_id in teamee_map:
|
|
511
|
-
old_teamee = teamee_map[target_task_id]
|
|
512
|
-
|
|
513
|
-
# D1a. 逻辑销毁旧 Teamee(无协议帧)
|
|
514
|
-
markTeameeDestroyed(teamee_map, target_task_id)
|
|
515
|
-
|
|
516
|
-
# D1b. 根据策略创建新 Teamee
|
|
517
|
-
# 🔴 两种策略都注入 failing_drivers(refine 通道,WP-176-6):
|
|
518
|
-
# 让承接重做的 Teamee 知道"重点修哪些失败项",而非盲目原样重做。
|
|
519
|
-
assignment = wp_assignments[target_task_id]
|
|
520
|
-
new_teamee_name = f"{assignment.role_id}-t{target_task_id}-retry"
|
|
521
|
-
|
|
522
|
-
if strategy == "checkpoint_resume":
|
|
523
|
-
# 复杂任务: 注入已完成文件上下文 + 失败项重点修复段
|
|
524
|
-
context = action.get("context", {})
|
|
525
|
-
prompt = build_resume_prompt(
|
|
526
|
-
teamee_name=new_teamee_name,
|
|
527
|
-
task_id=target_task_id,
|
|
528
|
-
role_prompt=assignment.role_prompt,
|
|
529
|
-
completed_files=context.get("completed_files", []),
|
|
530
|
-
remaining=context.get("remaining", []),
|
|
531
|
-
failing_drivers=failing_drivers
|
|
532
|
-
)
|
|
533
|
-
else: # full_restart
|
|
534
|
-
# 简单任务: 从头执行(仍注入失败项重点修复段,区分 retry 与首次 dispatch)
|
|
535
|
-
prompt = build_refine_prompt(
|
|
536
|
-
teamee_name=new_teamee_name,
|
|
537
|
-
task_id=target_task_id,
|
|
538
|
-
role_prompt=assignment.role_prompt,
|
|
539
|
-
memories=assignment.memories,
|
|
540
|
-
wp_doc_path=assignment.wp_doc_path,
|
|
541
|
-
failing_drivers=failing_drivers
|
|
542
|
-
)
|
|
543
|
-
|
|
544
|
-
# D1c. 创建新 Teamee(自动加入 implicit session team,无需 team_name 参数)
|
|
545
|
-
Agent(
|
|
546
|
-
name=new_teamee_name,
|
|
547
|
-
subagent_type="general-purpose",
|
|
548
|
-
prompt=prompt
|
|
549
|
-
)
|
|
550
|
-
teamee_map[target_task_id] = new_teamee_name
|
|
551
|
-
|
|
552
|
-
# D1d. 更新重试计数
|
|
553
|
-
update_task_file(target_task_id, increment_retry=True)
|
|
554
|
-
|
|
555
|
-
# 标记指令已处理
|
|
556
|
-
processed_action_ids.append(action.get("id"))
|
|
557
|
-
|
|
558
|
-
elif action_type == "abort":
|
|
559
|
-
# 中止单个任务
|
|
560
|
-
if target_task_id in teamee_map:
|
|
561
|
-
teamee_name = teamee_map[target_task_id]
|
|
562
|
-
# 逻辑销毁(无协议帧)
|
|
563
|
-
markTeameeDestroyed(teamee_map, target_task_id)
|
|
564
|
-
update_task_file(target_task_id, status="failed")
|
|
565
|
-
processed_action_ids.append(action.get("id"))
|
|
566
|
-
|
|
567
|
-
elif action_type == "pause":
|
|
568
|
-
# 暂停创建新 Teamee(已有 Teamee 继续运行)
|
|
569
|
-
global_pause_flag = True
|
|
570
|
-
processed_action_ids.append(action.get("id"))
|
|
571
|
-
|
|
572
|
-
elif action_type == "abort_all":
|
|
573
|
-
# 全局中止: 逻辑销毁所有 Teamee,终止监控循环(无协议帧)
|
|
574
|
-
for task_id in list(teamee_map.keys()):
|
|
575
|
-
markTeameeDestroyed(teamee_map, task_id)
|
|
576
|
-
teamee_map.clear()
|
|
577
|
-
# 输出: "收到 abort_all 指令,终止监控循环"
|
|
578
|
-
processed_action_ids.append(action.get("id"))
|
|
579
|
-
break # 跳出监控循环
|
|
580
|
-
|
|
581
|
-
# D1e. 回写已处理的 iteration
|
|
582
|
-
if actions:
|
|
583
|
-
Write(file_path=daemon_actions_path, content=json_dumps({
|
|
584
|
-
"actions": [a for a in actions if a.get("id") not in processed_action_ids],
|
|
585
|
-
"last_processed_iteration": loop_iteration
|
|
586
|
-
}))
|
|
587
|
-
|
|
588
|
-
# ---- Phase D.5: 状态持久化写回 (processed_action_ids 变更) ----
|
|
589
|
-
write_state("monitoring")
|
|
590
|
-
|
|
591
|
-
# ---- Phase D: 判断退出条件 ----
|
|
592
|
-
completed = count(status == "completed")
|
|
593
|
-
total = len(tasks)
|
|
594
|
-
|
|
595
|
-
if completed == total:
|
|
596
|
-
# 写入最终心跳 (DISP-001): 状态为 completed
|
|
597
|
-
heartbeat_data["status"] = "completed"
|
|
598
|
-
if is_multi_window:
|
|
599
|
-
heartbeat_data["window_id"] = window_id
|
|
600
|
-
Write(file_path=heartbeat_file, content=json_dumps(heartbeat_data))
|
|
601
|
-
# 写入最终状态文件
|
|
602
|
-
write_state("completed")
|
|
166
|
+
if count(status == "completed") == len(tasks): # ---- Phase D: 退出条件 ----
|
|
603
167
|
# 输出: "所有任务完成,退出监控循环"
|
|
604
168
|
break
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
in_progress = count(status == "in_progress")
|
|
608
|
-
pending = count(status == "pending")
|
|
609
|
-
if pending > 0 and in_progress == 0 and len(teamee_map) == 0:
|
|
610
|
-
# 输出: "异常: 有待处理任务但无活跃 Teamee 且无映射"
|
|
169
|
+
if count(status == "pending") > 0 and count(status == "in_progress") == 0 and len(teamee_map) == 0:
|
|
170
|
+
# 输出: "异常: 有待处理任务但无活跃 Teamee 且无映射" # Phase D2 异常检测
|
|
611
171
|
break
|
|
612
172
|
|
|
613
|
-
# Phase D2-idle: idle
|
|
614
|
-
#
|
|
615
|
-
# 走自愈流程(催促→重 spawn→熔断),🔴 绝不 Lead 接手(见文末 HARD-GATE)。
|
|
616
|
-
# 关键不变量(防"spawn 即判 idle→每轮自愈→熔断"死亡螺旋):
|
|
617
|
-
# - idle 计时起点 = 任务状态文件 started_at(回退 last_update → start_time),非 TaskList 对象
|
|
618
|
-
# - 催促去重位 idle_nudge_sent:本 idle 窗口内仅催促一次,催促后给满一个 idle_threshold 窗口
|
|
619
|
-
# 才允许进重 spawn;首轮只催促不重 spawn
|
|
620
|
-
# - 重 spawn 时 increment_retry + reset_started_at + set_idle_nudge=False 三者必须
|
|
621
|
-
# 同一次 update_task_file 完成(缺任一都会复活死亡螺旋)
|
|
173
|
+
# ---- Phase D2-idle: idle 不执行检测(映射非空但 Task 长时间未推进)----
|
|
174
|
+
# 🔴 命中 → 自愈流程(催促 → 重 spawn → 熔断),绝不 Lead 接手(见文末 HARD-GATE)
|
|
622
175
|
idle_threshold = loop_interval * 2 # 建议取 loop_interval 的 2-3 倍或显式配置项
|
|
623
176
|
for task_id, teamee_name in list(teamee_map.items()):
|
|
624
177
|
task = find_by_id(tasks, task_id)
|
|
625
178
|
if task is None:
|
|
626
179
|
continue
|
|
627
|
-
# 双验证:
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
assigned_at = task_file.get("started_at") or task_file.get("last_update") or start_time
|
|
632
|
-
idle_nudge_sent = task_file.get("idle_nudge_sent", False)
|
|
633
|
-
if task_stalled and (now() - assigned_at) >= idle_threshold:
|
|
634
|
-
# 输出: "⚠️ idle 检测: Teamee {teamee_name} (task {task_id}) 停滞,进入自愈流程"
|
|
635
|
-
# ---- Phase D2-idle-heal: 自愈流程 ----
|
|
636
|
-
# Step 1: 首轮仅催促一次(去重位),给满一个 idle_threshold 窗口,本轮不重 spawn
|
|
637
|
-
if not idle_nudge_sent:
|
|
638
|
-
SendMessage(
|
|
639
|
-
to=teamee_name,
|
|
640
|
-
summary="idle 检测催促,请立即执行任务",
|
|
641
|
-
message=f"检测到任务 {task_id} 长时间未推进。请立即开始执行 WP 文档中的任务,完成后用 SendMessage 向 team-lead 发送完成报告。"
|
|
642
|
-
)
|
|
643
|
-
update_task_file(task_id, set_idle_nudge=True)
|
|
644
|
-
continue # 下一轮若仍 idle 且已催促,才进 Step 2-4
|
|
645
|
-
# 输出: "idle 自愈: task {task_id} 已催促过仍无推进,进 Step 2-4 重 spawn"
|
|
646
|
-
# Step 2: 验证 spawn 参数(定位根因,避免原样重 spawn 仍 idle)
|
|
647
|
-
assignment = wp_assignments[task_id]
|
|
648
|
-
spawn_params_ok = (
|
|
649
|
-
assignment.subagent_type == "general-purpose"
|
|
650
|
-
and assignment.team_name == team_name
|
|
651
|
-
and task_id in assignment.prompt
|
|
652
|
-
and assignment.wp_doc_path in assignment.prompt
|
|
653
|
-
and "SendMessage" in assignment.prompt # prompt 须要求完成报告用 SendMessage
|
|
654
|
-
)
|
|
655
|
-
if not spawn_params_ok:
|
|
656
|
-
# 输出: "spawn 参数异常 (subagent_type/批次标签 team_name/prompt 完整性),将在重 spawn 时修正"
|
|
657
|
-
pass
|
|
658
|
-
# Step 3: 仍不执行 → 逻辑销毁旧 Teamee(无协议帧)
|
|
659
|
-
markTeameeDestroyed(teamee_map, task_id)
|
|
660
|
-
# Step 4: 检查 retry_count < max_retries → 重新 spawn(复用 Phase D.1 restart 指令段的重 spawn 逻辑)
|
|
661
|
-
# 复用 idle 检测顶部已读取的 task_file(read_task_file 结果),避免重复 IO
|
|
662
|
-
retry_count = task_file.get("retry_count", 0)
|
|
663
|
-
max_retries = task_file.get("max_retries", 3)
|
|
664
|
-
if retry_count < max_retries:
|
|
665
|
-
# 重新 spawn 专用 Teamee(递增 retry_count),复用 restart 守护进程指令段的重 spawn 逻辑
|
|
666
|
-
new_teamee_name = f"{assignment.role_id}-t{task_id}-idle-retry"
|
|
667
|
-
prompt = build_refine_prompt(
|
|
668
|
-
teamee_name=new_teamee_name,
|
|
669
|
-
task_id=task_id,
|
|
670
|
-
role_prompt=assignment.role_prompt,
|
|
671
|
-
memories=assignment.memories,
|
|
672
|
-
wp_doc_path=assignment.wp_doc_path,
|
|
673
|
-
failing_drivers=[] # idle 重 spawn 非失败项修复,failing_drivers 为空
|
|
674
|
-
)
|
|
675
|
-
Agent( # 自动加入 implicit session team,无需 team_name 参数
|
|
676
|
-
name=new_teamee_name,
|
|
677
|
-
subagent_type="general-purpose",
|
|
678
|
-
prompt=prompt
|
|
679
|
-
)
|
|
680
|
-
teamee_map[task_id] = new_teamee_name
|
|
681
|
-
# 三合一调用(缺任一复活死亡螺旋):递增 retry + 刷新 started_at + 重置催促去重位
|
|
682
|
-
update_task_file(
|
|
683
|
-
task_id,
|
|
684
|
-
increment_retry=True,
|
|
685
|
-
reset_started_at=True, # F4
|
|
686
|
-
set_idle_nudge=False # F3
|
|
687
|
-
)
|
|
688
|
-
# 输出: "idle 自愈: task {task_id} 重新 spawn 为 {new_teamee_name} (retry {retry_count+1}/{max_retries}),已刷新 started_at + 重置催促去重位"
|
|
689
|
-
else:
|
|
690
|
-
# Step 5: 超限 → 熔断,绝不 Lead 接手,转 Step 7 清理
|
|
691
|
-
TaskUpdate(taskId=task_id, status="failed")
|
|
692
|
-
update_task_file(task_id, status="failed")
|
|
693
|
-
# 输出: "🔴 idle 自愈超限: task {task_id} 重试 {retry_count}/{max_retries} 仍 idle,熔断标记 failed,绝不 Lead 接手,转 Step 7 清理"
|
|
694
|
-
|
|
695
|
-
# Phase D3: 批次自动加载 — 当前批次全部完成后从 pending_batches 加载下一批
|
|
696
|
-
if current_batch and len(teamee_map) == 0:
|
|
697
|
-
batch_completed = all(
|
|
698
|
-
find_by_id(tasks, tid).status == "completed" for tid in current_batch
|
|
699
|
-
if find_by_id(tasks, tid)
|
|
700
|
-
)
|
|
701
|
-
if batch_completed and pending_batches:
|
|
702
|
-
next_batch_size = min(max_batch_size, len(pending_batches))
|
|
703
|
-
current_batch = pending_batches[:next_batch_size]
|
|
704
|
-
pending_batches = pending_batches[next_batch_size:]
|
|
705
|
-
# 输出: "当前批次完成,自动加载下一批: {len(current_batch)} 个任务, 剩余 {len(pending_batches)} 个"
|
|
706
|
-
# 写回状态文件保存批次进度
|
|
707
|
-
write_state("monitoring")
|
|
180
|
+
# 双验证:status 未推进 + 产物弱信号(WP 文档无产物路径声明 → 按停滞判定)
|
|
181
|
+
st = idle_state.get(task_id, {"started_at": start_time, "idle_nudge_sent": False, "retry_count": 0})
|
|
182
|
+
if task.status in ("pending", "in_progress") and (now() - st["started_at"]) >= idle_threshold:
|
|
183
|
+
pass # 📖按需:Read recovery-reference.md(§Phase D2-idle-heal)—— 催促去重 / spawn 参数验证 / 重 spawn 三合一 / 超限熔断
|
|
708
184
|
|
|
709
185
|
sleep(loop_interval)
|
|
710
186
|
|
|
711
|
-
# 超时处理
|
|
712
|
-
if (now() - start_time) >= max_wait_time:
|
|
713
|
-
# 写入最终心跳 (DISP-001): 状态为 shutting_down
|
|
714
|
-
heartbeat_data["status"] = "shutting_down"
|
|
715
|
-
if is_multi_window:
|
|
716
|
-
heartbeat_data["window_id"] = window_id
|
|
717
|
-
Write(file_path=heartbeat_file, content=json_dumps(heartbeat_data))
|
|
187
|
+
if (now() - start_time) >= max_wait_time: # 超时处理
|
|
718
188
|
# 输出: "监控超时,强制执行清理"
|
|
719
|
-
# 逻辑销毁所有残留 Teamee(无协议帧)
|
|
720
189
|
remaining_count = len(teamee_map)
|
|
721
190
|
for task_id in list(teamee_map.keys()):
|
|
722
|
-
markTeameeDestroyed(teamee_map, task_id)
|
|
191
|
+
markTeameeDestroyed(teamee_map, task_id) # 逻辑销毁所有残留 Teamee(无协议帧)
|
|
723
192
|
# 输出: "监控超时,已逻辑销毁 {remaining_count} 个残留 Teamee,转入 Step 7 目录清理"
|
|
724
193
|
```
|
|
725
194
|
|
|
726
|
-
|
|
195
|
+
**idle 自愈关键不变量**(防"spawn 即判 idle→每轮自愈→熔断"死亡螺旋):
|
|
196
|
+
- idle 计时起点 = `idle_state[task_id].started_at`(spawn / 重 spawn 时刷新为 now()),**非 TaskList 对象**
|
|
197
|
+
- 催促去重位 `idle_nudge_sent`:本 idle 窗口内仅催促一次,催促后给满一个 idle_threshold 窗口才允许进重 spawn;**首轮只催促不重 spawn**
|
|
198
|
+
- 重 spawn 时 `retry_count += 1` + `started_at = now()` + `idle_nudge_sent = False` **三者必须同一次赋值完成**(缺任一都会复活死亡螺旋)
|
|
199
|
+
- 状态载体是 Lead 循环内变量,spawn / 催促 / 重 spawn 事件记入 PROGRESS.md;上下文压缩后 `idle_state` 清零,**最坏后果 = 多催促一次**(天花板:压缩频繁且自愈频发时再评估回持久化)
|
|
727
200
|
|
|
728
|
-
|
|
201
|
+
**辅助函数已外移**(is_unblocked 阻塞判断 / get_max_concurrent + is_time_in_range 并发上限时段匹配,含跨午夜):
|
|
729
202
|
|
|
730
|
-
|
|
731
|
-
1. Read 状态文件(多窗口模式读 windows/{window_id}/state.json)
|
|
732
|
-
- 不存在 → 首次运行或已清理,从头开始
|
|
733
|
-
- status == "completed" → 执行已完成,无需恢复
|
|
734
|
-
- status == "monitoring" → 进入恢复流程
|
|
203
|
+
📖按需:实现阻塞判断与并发控制时 → Read monitoring-reference.md(§辅助函数 is_unblocked / 并发控制)
|
|
735
204
|
|
|
736
|
-
|
|
205
|
+
**监控循环关键特性**: Phase B (即时销毁) 先于 Phase C (创建),资源先释放再分配;每轮检查 `teamee_map` 防重复创建/销毁;异常检测同时检查映射是否为空。
|
|
737
206
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
4. 继续监控循环(从恢复的 loop_iteration + 1 开始)
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
**辅助函数 — 判断任务是否已解除阻塞**:
|
|
744
|
-
```
|
|
745
|
-
def is_unblocked(task):
|
|
746
|
-
"""检查任务的所有 blockedBy 依赖是否都已满足"""
|
|
747
|
-
if not task.blockedBy:
|
|
748
|
-
return True
|
|
749
|
-
all_tasks = TaskList()
|
|
750
|
-
for blocker_id in task.blockedBy:
|
|
751
|
-
blocker = find_by_id(all_tasks, blocker_id)
|
|
752
|
-
if blocker.status != "completed":
|
|
753
|
-
return False
|
|
754
|
-
return True
|
|
755
|
-
```
|
|
756
|
-
|
|
757
|
-
**辅助函数 — 并发控制**(Phase C 使用):
|
|
758
|
-
```
|
|
759
|
-
def get_max_concurrent(config, current_time):
|
|
760
|
-
"""根据当前时间匹配 schedule,返回对应并发上限"""
|
|
761
|
-
if not config or not config.get("schedules"):
|
|
762
|
-
return config.get("default_max", 6) if config else 6
|
|
763
|
-
|
|
764
|
-
current_hhmm = current_time.strftime("%H:%M")
|
|
765
|
-
for schedule in config["schedules"]:
|
|
766
|
-
start = schedule["time_range"]["start"]
|
|
767
|
-
end = schedule["time_range"]["end"]
|
|
768
|
-
if is_time_in_range(current_hhmm, start, end):
|
|
769
|
-
return schedule["max_concurrent"]
|
|
770
|
-
|
|
771
|
-
return config.get("default_max", 6)
|
|
772
|
-
|
|
773
|
-
def is_time_in_range(current, start, end):
|
|
774
|
-
"""判断当前时间是否在范围内,支持跨午夜"""
|
|
775
|
-
if start <= end:
|
|
776
|
-
return start <= current < end
|
|
777
|
-
else: # 跨午夜,如 22:00-06:00
|
|
778
|
-
return current >= start or current < end
|
|
779
|
-
```
|
|
780
|
-
|
|
781
|
-
**监控循环关键特性**:
|
|
782
|
-
- **Phase B (即时销毁)** 在 Phase C (创建) 之前执行,确保资源先释放再分配
|
|
783
|
-
- 每次循环都检查 `teamee_map` 防止重复创建/重复销毁
|
|
784
|
-
- 异常检测同时检查 `teamee_map` 是否为空,避免误判
|
|
785
|
-
|
|
786
|
-
---
|
|
787
|
-
|
|
788
|
-
### Step 6.6: 守护进程辅助函数 (DISP-001/002/003)
|
|
207
|
+
### Step 7: 清理(逻辑销毁 + 历史残留目录可选清理)
|
|
789
208
|
|
|
790
|
-
|
|
209
|
+
当前 session 的 implicit team 随 session 自动清理,无需 TeamDelete;Step 6.5 已逻辑销毁全部 Teamee。本步骤职责:① 确认 `teamee_map` 已空;② 可选地用 `team-cleanup` CLI 清理**历史残留**的显式/UUID 团队目录(非当前 session team)。
|
|
791
210
|
|
|
792
|
-
|
|
211
|
+
📖 执行前 Read `plugins/core/skill-agent-dispatcher/cleanup-reference.md`:权限要求、Step 7a-7h 完整清理流程(安全检查 → 逻辑销毁 → team-cleanup CLI → 验证)、Error Handling、Cleanup Guarantee。
|
|
793
212
|
|
|
794
|
-
### Step
|
|
213
|
+
### Step 8: 重派发(retry / resplit 入口)
|
|
795
214
|
|
|
796
|
-
|
|
797
|
-
> - **当前 session 的 implicit team 随 session 结束自动清理,无需 TeamDelete**(工具也已移除)。
|
|
798
|
-
> - Lead 在 Step 6.5 已通过 `markTeameeDestroyed` 完成所有 Teamee 的逻辑销毁(映射表已空)。
|
|
799
|
-
> - 本步骤主要职责:① 确认 `teamee_map` 已空;② 可选地用 `team-cleanup` CLI 清理**历史残留**的显式/UUID 团队目录(如旧的 `cybershop-wp101`),**而非当前 session team**。
|
|
215
|
+
**触发**:Lead(`skill-agentic-loop`)带 `dispatchTarget{mode: retry|resplit, wpId, strategy, failingDrivers}` 直接再调本 skill——这是 retry / resplit 的唯一入口。
|
|
800
216
|
|
|
801
|
-
**📖 在执行此步骤前,读取清理参考文档:**
|
|
802
217
|
```
|
|
803
|
-
|
|
218
|
+
1. 定位目标:按 dispatchTarget.wpId 找到 Task(teamee_map 中有映射的旧 Teamee)
|
|
219
|
+
2. 逻辑销毁旧 Teamee:markTeameeDestroyed(teamee_map, task_id)
|
|
220
|
+
3. 命名与路由:new_teamee_name = f"{assignment.role_id}-t{task_id}-retry"
|
|
221
|
+
subagent_type = resolve_subagent_type(assignment.role_id) # 双分支路由(同 Step 6)
|
|
222
|
+
4. prompt(两种策略都注入 failingDrivers,每项 {wpId, category, item, reason};为空不输出重点修复段):
|
|
223
|
+
- strategy == "checkpoint_resume" → build_resume_prompt(completed_files, remaining, failing_drivers)
|
|
224
|
+
- 否则(full_restart / resplit)→ build_refine_prompt(memories, wp_doc_path, failing_drivers)
|
|
225
|
+
让承接重做的 Teamee 优先修复这些失败项,而非原样重做
|
|
226
|
+
5. 重 spawn:Agent(name=new_teamee_name, subagent_type=..., prompt=prompt)
|
|
227
|
+
TaskUpdate(taskId=task_id, owner=new_teamee_name);teamee_map[task_id] = new_teamee_name
|
|
228
|
+
idle_state[task_id] = {"started_at": now(), "idle_nudge_sent": False, "retry_count": 旧值 + 1} # 三合一
|
|
229
|
+
6. 重派发事件(wpId / strategy / failingDrivers 条数 / retry 次数)写入 PROGRESS.md → 回 Step 6.5 监控循环
|
|
804
230
|
```
|
|
805
231
|
|
|
806
|
-
|
|
807
|
-
- **权限要求**: Bash 工具权限配置建议
|
|
808
|
-
- **Step 7a-7h**: 完整清理流程(安全检查 → 逻辑销毁 → team-cleanup CLI → 验证)
|
|
809
|
-
- **Error Handling**: 循环依赖、Teamee 失败、超时等错误处理
|
|
810
|
-
- **Cleanup Guarantee**: 清理保障矩阵
|
|
811
|
-
|
|
812
|
-
---
|
|
232
|
+
📖按需:prompt 构造细则(重点修复段)与重派发后 idle 处理 → Read recovery-reference.md(§重派发 restart 规格)
|
|
813
233
|
|
|
814
234
|
## Teamee Prompt 模板
|
|
815
235
|
|
|
816
|
-
|
|
817
|
-
```
|
|
818
|
-
Read("plugins/core/skill-agent-dispatcher/roles-reference.md")
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
`roles-reference.md` 底部包含完整的 Teamee Prompt 模板,用于 `build_single_task_prompt()` 构建。
|
|
822
|
-
模板要点:1:1 任务绑定、工作包文档优先阅读、完成后等待 shutdown_request、状态同步必须执行。
|
|
823
|
-
|
|
824
|
-
---
|
|
236
|
+
📖 创建 Teamee 时(Step 6 / Step 6.5 / Step 8)Read `plugins/core/skill-agent-dispatcher/roles-reference.md` 底部的完整 Prompt 模板(`build_single_task_prompt()` 构建):1:1 任务绑定、工作包文档优先阅读、完成后以 SendMessage 向 Lead 报告并等待逻辑销毁、状态同步必须执行。
|
|
825
237
|
|
|
826
238
|
## 共享上下文机制
|
|
827
239
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
| 资源 | 共享方式 |
|
|
831
|
-
|------|----------|
|
|
832
|
-
| `CLAUDE.md` | 所有 Teamee 自动加载 |
|
|
833
|
-
| Skills | 继承 Lead 的 skills |
|
|
834
|
-
| MCP Servers | 共享相同的 MCP 配置 |
|
|
835
|
-
| 项目代码 | 共享同一工作目录 |
|
|
836
|
-
|
|
837
|
-
### 主动共享 (通过 SendMessage)
|
|
838
|
-
|
|
839
|
-
> 注:Teamee 一经 spawn **自动加入 implicit session team**,无需 Lead 显式分配团队——SendMessage 与共享 Task List 的协作能力由 implicit session team 提供,未受 harness 团队机制变更影响。
|
|
840
|
-
|
|
841
|
-
| 消息类型 | 格式 | 用途 |
|
|
842
|
-
|----------|------|------|
|
|
843
|
-
| `shutdown_request` | (deprecated) | Lead 不再发 shutdown_request;harness 拦截含 protocol frame 的 SendMessage message |
|
|
844
|
-
| `shutdown_response` | (deprecated) | 同上;Teamee 状态同步改为 TaskUpdate(completed) → Lead 检测 → markTeameeDestroyed → 批末 team-cleanup CLI |
|
|
845
|
-
| 纯文本状态 | string + summary | Teamee 间/向 Lead 的进度沟通(唯一允许的 SendMessage 用途) |
|
|
240
|
+
Teamee 自动共享 CLAUDE.md / Skills / MCP Servers / 项目代码(无需干预);主动共享走 SendMessage 纯文本状态沟通。
|
|
846
241
|
|
|
847
|
-
|
|
242
|
+
📖按需:需消息类型格式表/共享方式明细 → Read monitoring-reference.md(§共享上下文机制)
|
|
848
243
|
|
|
849
244
|
## Dependency Analysis
|
|
850
245
|
|
|
851
246
|
### 依赖图构建
|
|
852
247
|
|
|
853
|
-
1. **读取工作包清单** -
|
|
854
|
-
2. **解析依赖声明** - 提取 `依赖: WP-XXX` 信息
|
|
855
|
-
3. **构建有向图** - 节点=工作包,边=依赖关系
|
|
856
|
-
4. **拓扑排序** - 确定执行顺序
|
|
857
|
-
5. **检测循环依赖** - 如有循环则报错
|
|
858
|
-
|
|
859
|
-
### 循环依赖检测
|
|
248
|
+
1. **读取工作包清单** → 2. **解析依赖声明**(`依赖: WP-XXX`)→ 3. **构建有向图**(节点=工作包,边=依赖)→ 4. **拓扑排序** → 5. **检测循环依赖**(有环则报错)
|
|
860
249
|
|
|
861
250
|
```
|
|
862
|
-
❌ 检测到循环依赖: WP-037 → WP-038 → WP-039 → WP-037
|
|
863
|
-
(四位编号示例: WP-1037 → WP-1038 → WP-1039 → WP-1037)
|
|
251
|
+
❌ 检测到循环依赖: WP-037 → WP-038 → WP-039 → WP-037(四位编号同理)
|
|
864
252
|
请手动解除依赖关系后重试。
|
|
865
253
|
```
|
|
866
254
|
|
|
867
255
|
### 依赖分析输出规范
|
|
868
256
|
|
|
869
|
-
|
|
257
|
+
**输出必须且只能包含**:① 每个 WP 的 `blockedBy` 依赖关系(来自 WP 文档声明);② 拓扑排序后的执行批次(可并行 / 必须串行);③ 循环依赖检测结果。
|
|
870
258
|
|
|
871
|
-
|
|
872
|
-
2. 拓扑排序后的执行批次(哪些可以并行、哪些必须串行)
|
|
873
|
-
3. 循环依赖检测结果
|
|
259
|
+
**禁止输出**:❌ 各 WP 修改的文件列表或文件重叠分析;❌ "WP-XXX~YYY 修改同一文件"之类陈述;❌ 基于文件重叠的调度建议。
|
|
874
260
|
|
|
875
|
-
|
|
876
|
-
- ❌ 各 WP 修改的文件列表或文件重叠分析
|
|
877
|
-
- ❌ "WP-XXX~YYY 修改同一文件" 之类的陈述
|
|
878
|
-
- ❌ 基于文件重叠的调度建议
|
|
879
|
-
|
|
880
|
-
**原因**: 文件冲突评估不属于 dispatcher 职责。如果 WP 之间需要串行,应在 WP 创建阶段通过 blockedBy 声明。
|
|
881
|
-
|
|
882
|
-
---
|
|
261
|
+
**原因**: 文件冲突评估不属于 dispatcher 职责。WP 之间需要串行,应在 WP 创建阶段通过 blockedBy 声明。
|
|
883
262
|
|
|
884
263
|
## File Conflict Policy
|
|
885
264
|
|
|
886
|
-
### 核心规则:1:1 映射不受文件冲突影响
|
|
887
|
-
|
|
888
265
|
| 规则 | 说明 |
|
|
889
266
|
|------|------|
|
|
890
267
|
| **绝对禁止** | 不得因多个 WP 修改同一文件而合并为单 agent |
|
|
891
268
|
| **绝对禁止** | 不得自行添加基于文件重叠的 blockedBy 依赖 |
|
|
892
269
|
| **唯一依据** | blockedBy 只来自 WP 文档中声明的依赖关系 |
|
|
893
270
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
场景:WP-023, WP-024, WP-025 都修改 file.java,且都依赖 WP-022
|
|
271
|
+
场景:WP-023, WP-024, WP-025 都修改 file.java 且都依赖 WP-022 —— ❌ 合并到一个 agent 顺序执行;✅ 无互相依赖 → 并行执行,每 WP 一个 Teamee;✅ 需要串行 → 回 WP 创建阶段添加 blockedBy(WP-024 blockedBy WP-023)。
|
|
897
272
|
|
|
898
|
-
|
|
899
|
-
- ✅ 正确:WP 创建阶段没有互相依赖 → 并行执行,每 WP 一个 Teamee
|
|
900
|
-
- ✅ 正确:如果需要串行 → 回到 WP 创建阶段添加 blockedBy(WP-024 blockedBy WP-023)
|
|
901
|
-
|
|
902
|
-
### Forbidden Thoughts(文件冲突相关)
|
|
903
|
-
|
|
904
|
-
| Thought | Reality |
|
|
273
|
+
| Forbidden Thought | Reality |
|
|
905
274
|
|---------|---------|
|
|
906
|
-
| "它们修改同一文件,应该合并" | ❌ 1:1
|
|
907
|
-
| "并行编辑同一文件会冲突" | ❌ 这不是 dispatcher 应该关心的问题 |
|
|
275
|
+
| "它们修改同一文件,应该合并" / "应该串行" | ❌ 1:1 规则是绝对的;安全性由 WP 设计者负责 |
|
|
908
276
|
| "我应该为它们添加隐式依赖" | ❌ blockedBy 只来自 WP 文档声明 |
|
|
909
|
-
| "
|
|
910
|
-
|
|
911
|
-
---
|
|
277
|
+
| "并行编辑同一文件会冲突" | ❌ 这不是 dispatcher 应该关心的问题 |
|
|
912
278
|
|
|
913
279
|
## Execution Report
|
|
914
280
|
|
|
915
|
-
批量执行完成后生成汇总报告到 `docs/reports/{YYYY-MM-DD}_{工作包列表}_execution_report.md
|
|
916
|
-
|
|
917
|
-
模板必备段落:
|
|
918
|
-
1. **基本信息**:批次标签 (team_name) / 执行日期 / 工作包列表
|
|
919
|
-
2. **执行总览**:表格(Task ID / 工作包 / 角色 / 状态 / 依赖 / 说明)
|
|
920
|
-
3. **详细结果**:每个 WP 的执行者、子任务完成情况、文件变更
|
|
921
|
-
4. **文件变更汇总**:新增 / 修改 / 测试计数
|
|
922
|
-
5. **新增经验**:如有新经验,注明已写入角色专属库
|
|
923
|
-
6. 报告生成时间戳
|
|
924
|
-
|
|
925
|
-
---
|
|
281
|
+
批量执行完成后生成汇总报告到 `docs/reports/{YYYY-MM-DD}_{工作包列表}_execution_report.md`,必备段落:**基本信息**(批次标签 / 执行日期 / 工作包列表)、**执行总览**(Task ID / 工作包 / 角色 / 状态 / 依赖 / 说明)、**详细结果**(每个 WP 的执行者、子任务完成情况、文件变更)、**文件变更汇总**(新增 / 修改 / 测试计数)、**新增经验**(如有)、报告生成时间戳。
|
|
926
282
|
|
|
927
283
|
## 拆分工作包执行支持
|
|
928
284
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
### 执行流程
|
|
932
|
-
|
|
933
|
-
```
|
|
934
|
-
1. 读取父工作包文档 (docs/wp/WP-XXX.md)
|
|
935
|
-
2. 检测拆分模式 (simple/standard/fine-grained)
|
|
936
|
-
3. 解析子工作包列表 + 依赖关系
|
|
937
|
-
4. 创建 Task List 任务 + 设置 blockedBy
|
|
938
|
-
5. 角色匹配 → 分配角色
|
|
939
|
-
6. 按依赖顺序调度执行
|
|
940
|
-
7. 验证关卡: verify 失败 → 停止后续; verify 通过 → 继续
|
|
941
|
-
```
|
|
285
|
+
工作包有子工作包时自动识别并按依赖调度(simple / standard / fine-grained 三种拆分模式;验证关卡 verify 失败 → 停止后续)。
|
|
942
286
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
| 模式 | 处理方式 |
|
|
946
|
-
|------|----------|
|
|
947
|
-
| **simple** | 不拆分,直接作为单个任务调度 |
|
|
948
|
-
| **standard** | 4 个子任务: impl → test → verify → review(依赖链) |
|
|
949
|
-
| **fine-grained** | 按模块拆分多个 impl,每个独立 test,最后统一 verify + review |
|
|
950
|
-
|
|
951
|
-
---
|
|
287
|
+
📖按需:遇拆分工作包/需判定拆分模式处理方式 → Read monitoring-reference.md(§拆分工作包执行支持)
|
|
952
288
|
|
|
953
289
|
## Integration with Other Skills
|
|
954
290
|
|
|
955
291
|
| Skill | 集成点 |
|
|
956
292
|
|-------|--------|
|
|
957
|
-
| `
|
|
958
|
-
| `human-checkpoint` | 批量执行前确认执行计划 |
|
|
959
|
-
| `
|
|
960
|
-
| `
|
|
961
|
-
| `experience-logger` | 批量执行后记录经验 |
|
|
962
|
-
| `task-creator` | 支持拆分工作包创建 |
|
|
963
|
-
| `batch-task-creator` | 支持批量拆分 |
|
|
964
|
-
|
|
965
|
-
---
|
|
293
|
+
| `skill-agentic-loop` | Act 执行单元:loop 带 `dispatchTarget` 调用本 skill(首次 dispatch / Step 8 重派发) |
|
|
294
|
+
| `role-manager` / `human-checkpoint` / `completion-report` | 查看角色 / 批量执行前确认执行计划 / 批量执行后生成报告 |
|
|
295
|
+
| `checklist` / `experience-logger` | 每个工作包完成后检查 / 批量执行后记录经验 |
|
|
296
|
+
| `task-creator` / `batch-task-creator` | 支持拆分工作包创建 / 批量拆分 |
|
|
966
297
|
|
|
967
298
|
## Important
|
|
968
299
|
|
|
969
|
-
1. **implicit session team 自动提供协作能力** -
|
|
970
|
-
2. **
|
|
971
|
-
3.
|
|
972
|
-
4.
|
|
973
|
-
5.
|
|
974
|
-
6.
|
|
975
|
-
7.
|
|
976
|
-
8. **🔴 Teamee 逻辑销毁是强制的,目录清理按需** - 无论成功/失败/超时,Lead 都必须通过 `markTeameeDestroyed` 清空 `teamee_map`(Step 6.5/Step 7 已保证);当前 session 的 implicit team 随 session 自动清理,**无需 TeamDelete**(工具已移除)。`team-cleanup` CLI 仅用于清理**历史残留**的显式/UUID 团队目录,定位为可选的运维清理工具。
|
|
977
|
-
9. **🔴 监控循环不可跳过** - Lead 必须进入 Step 6.5 监控循环,负责动态创建和即时销毁
|
|
978
|
-
10. **🔴 文件冲突不得触发合并** - 即使多个 WP 修改同一文件,也必须每 WP 一个 Teamee。blockedBy 依赖只以 WP 文档声明为准,禁止自行添加隐式依赖
|
|
300
|
+
1. **implicit session team 自动提供协作能力** - subagent 自动加入,共享 Task List + SendMessage,**无需 TeamCreate**(工具已移除);`team_name` 仅为 Lead 内部批次标签。
|
|
301
|
+
2. **Lead 按需分配 (1:1)** - 每个 WP 由 Lead 创建专用 Teamee 并预分配,禁止一个 Teamee 处理多个 WP。
|
|
302
|
+
3. **逻辑销毁 + 批末清理** - Teamee 完成后立即从映射表移除(markTeameeDestroyed,无协议帧);目录级清理在批末按需执行(team-cleanup CLI)。
|
|
303
|
+
4. **角色匹配 + 记忆注入 + 经验沉淀闭环** - 专业角色比通用代理更高效,从历史经验中学习。
|
|
304
|
+
5. **🔴 监控循环不可跳过** - Lead 必须进入 Step 6.5 监控循环,负责动态创建和即时销毁。
|
|
305
|
+
6. **🔴 文件冲突不得触发合并** - 多 WP 改同一文件也必须每 WP 一个 Teamee;blockedBy 只以 WP 文档声明为准,禁加隐式依赖。
|
|
306
|
+
7. **🔴 retry / resplit 只走 Step 8 重派发** - Lead 带 `dispatchTarget` 再调,逻辑销毁旧 Teamee 后以注入 `failingDrivers` 的 refine prompt 重 spawn;idle 自愈状态存 Lead 循环内变量,PROGRESS.md 是唯一持久层。
|
|
979
307
|
|
|
980
308
|
---
|
|
981
309
|
|