doukui 0.8.0 → 0.9.1

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.
Files changed (66) hide show
  1. package/README.en.md +85 -18
  2. package/README.md +8 -8
  3. package/bin/commands/help.js +2 -0
  4. package/bin/commands/plan-lint.js +105 -0
  5. package/bin/commands/verify.js +263 -0
  6. package/bin/doukui.js +2 -0
  7. package/package.json +1 -1
  8. package/plugins/core/hook-session-start/index.js +1 -1
  9. package/plugins/core/hook-skill-gate/index.js +154 -19
  10. package/plugins/core/hook-skill-gate/plugin.json +1 -1
  11. package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +7 -28
  12. package/plugins/core/skill-agent-dispatcher/monitoring-reference.md +5 -177
  13. package/plugins/core/skill-agent-dispatcher/plugin.json +1 -1
  14. package/plugins/core/skill-agent-dispatcher/recovery-reference.md +99 -58
  15. package/plugins/core/skill-agent-dispatcher/roles-reference.md +9 -22
  16. package/plugins/core/skill-agent-dispatcher/skill.md +112 -524
  17. package/plugins/core/skill-agentic-loop/mirror-rules.md +15 -3
  18. package/plugins/core/skill-agentic-loop/plugin.json +1 -1
  19. package/plugins/core/skill-agentic-loop/skill.md +123 -324
  20. package/plugins/core/skill-batch-task-creator/plugin.json +1 -1
  21. package/plugins/core/skill-batch-task-creator/skill.md +22 -24
  22. package/plugins/core/skill-checklist/skill.md +15 -141
  23. package/plugins/core/skill-completion-report/plugin.json +1 -1
  24. package/plugins/core/skill-doukui-plan/plugin.json +1 -1
  25. package/plugins/core/skill-doukui-plan/skill.md +33 -38
  26. package/plugins/core/skill-experience-logger/plugin.json +1 -1
  27. package/plugins/core/skill-human-checkpoint/skill.md +1 -0
  28. package/plugins/core/skill-split-work-package/plugin.json +1 -1
  29. package/plugins/core/skill-split-work-package/skill.md +20 -18
  30. package/plugins/core/skill-task-creator/plugin.json +1 -1
  31. package/plugins/core/skill-task-creator/skill.md +25 -165
  32. package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
  33. package/plugins/plugin-registry.json +0 -36
  34. package/plugins/runtime/claude-md-injector.js +1 -0
  35. package/plugins/runtime/harness-build.js +5 -5
  36. package/plugins/runtime/plan-reader.js +21 -3
  37. package/plugins/runtime/resolve-plugin-path.js +2 -2
  38. package/plugins/runtime/settings-merger.js +5 -0
  39. package/plugins/contracts/capabilities.js +0 -268
  40. package/plugins/core/provider-memory-store/index.js +0 -510
  41. package/plugins/core/provider-memory-store/plugin.json +0 -9
  42. package/plugins/core/provider-state-store/index.js +0 -244
  43. package/plugins/core/provider-state-store/plugin.json +0 -9
  44. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
  45. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
  46. package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
  47. package/plugins/core/provider-watchdog/index.js +0 -151
  48. package/plugins/core/provider-watchdog/plugin.json +0 -13
  49. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
  50. package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
  51. package/plugins/core/skill-watchdog-manager/skill.md +0 -143
  52. package/plugins/core/validator-doc-sync/index.js +0 -248
  53. package/plugins/core/validator-doc-sync/plugin.json +0 -12
  54. package/plugins/core/validator-work-package/index.js +0 -300
  55. package/plugins/core/validator-work-package/plugin.json +0 -12
  56. package/plugins/runtime/audit-logger.js +0 -311
  57. package/plugins/runtime/build-cli.js +0 -89
  58. package/plugins/runtime/event-bus.js +0 -207
  59. package/plugins/runtime/hook-dispatcher.js +0 -315
  60. package/plugins/runtime/plugin-loader.js +0 -798
  61. package/plugins/runtime/plugin-trust.js +0 -182
  62. package/plugins/runtime/sandbox-context.js +0 -235
  63. package/plugins/runtime/sandbox-manager.js +0 -609
  64. package/plugins/runtime/sandbox-worker.js +0 -215
  65. package/plugins/runtime/text-tokenize.js +0 -24
  66. package/plugins/runtime/validator-pipeline.js +0 -475
@@ -5,430 +5,229 @@ description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱
5
5
 
6
6
  # Agentic Loop (半自主目标驱动执行循环 · implicit session team 多 agent 版)
7
7
 
8
- 判定规则自持(`mirror-rules.md` 为唯一真相源)的目标驱动自主循环 Skill。把现有"线性 + 人驱动"的 P2→P3 升级为"目标驱动 + 自主闭环 + 人监督":含 checklist 失败项的任务能自主 P2→P3→P2 重试至达成,或触顶/发散/熔断时安全回退到 P1 人介入。
8
+ 判定规则自持(`mirror-rules.md` 为唯一真相源)的目标驱动自主循环 Skill:含 checklist 失败项的任务自主 P2→P3→P2 重试至达成,或触顶/发散/熔断时安全回退到 P1。
9
9
 
10
- > **🔴 本 skill 的两条不可违反红线**(用户实测暴露的两大问题,本版强制修复):
11
- > 1. **入口必须先规划**:触发即进 Plan 模式,**按三级优先级解析计划路径**(参数路径 > `.claude/plan.md` > `docs/plan/` 扫描),经 `plan-reader` 拆为 WP 集合;无可用计划时回退用 `skill-task-creator`/`skill-split-work-package` 从原始需求拆 WP,或提示用户用 `/skill-doukui-plan` 生成计划到 `docs/plan/`(Step 0)。**没有拆好的 WP,loop 不启动**——禁止跳过规划直接写代码。
12
- > 2. **Act 必须多 agent**:loop 永不自己写代码。每轮 Act 一律委托 `skill-agent-dispatcher`,用 **implicit session team + subagent**(`Agent(subagent_type='general-purpose')` 1:1 spawn Teamee,subagent 自动加入 implicit session team,无需 TeamCreate)执行选定 WP。**单 agent 手写 = 违规**。
10
+ > **🔴 两条不可违反红线**(全文仅此处定义,Important 引用):
11
+ > 1. **入口必须先规划**:触发即进 Plan 模式,按**三级优先级**解析计划路径(参数路径 > `.claude/plan.md` > `docs/plan/` 扫描),经 `doukui plan-lint` 拆为 WP 集合;无计划时回退 `skill-task-creator`/`skill-split-work-package` 从原始需求拆 WP,或提示用户用 `/skill-doukui-plan` 生成计划到 `docs/plan/`(Step 0)。**没有拆好的 WP,loop 不启动**。
12
+ > 2. **Act 必须多 agent**:loop 永不自己写代码。每轮 Act 一律委托 `skill-agent-dispatcher`,用 implicit session team + subagent(1:1 spawn Teamee,`subagent_type` 走 dispatcher 的 `resolve_subagent_type(role_id)` 双分支路由)执行选定 WP。**单 agent 手写 = 违规**。
13
13
 
14
- > **设计依据**: `docs/reports/agentic-loop-design.md`(循环体 §4 / 安全边界 §7 / 持久化 §8 / 实现指引 §10)
15
- > **判定规则**: `mirror-rules.md`(本 skill 目录)——Observe/Think/Reflect/Decide 规则与阈值默认的唯一真相源
16
-
17
- > **🔴 决策规则真相源声明**:
18
- > - **唯一真相源** = `plugins/core/skill-agentic-loop/mirror-rules.md`——Observe/Think/Reflect/Decide 的判定规则(Think/Decide 优先级、proximity 公式、发散判定)与全部阈值默认值自持于该文件。
19
- > - 本 skill.md 是行为正文(流程编排 + Act 委托);判定规则细节一律以 mirror-rules.md 为准。
20
- > - 修改判定规则或默认阈值:**直接改 mirror-rules.md**。会话内自轮询是唯一执行路径,不存在 JS 判定代码镜像,也没有 CI 镜像锁。
21
- > - 引用规则时一律用**步骤名/符号名**(如「Think 规则」「`failingDrivers`」),禁止硬编码行号(行号随文本漂移)。
22
-
23
- ---
14
+ > **设计依据**: `docs/design/agentic-loop-design.md`(循环体 §4 / 安全边界 §7 / 持久化 §8 / 实现指引 §10)
15
+ > **判定规则**: `mirror-rules.md`(本 skill 目录)——Observe/Think/Reflect/Decide 规则与**阈值默认值**的唯一真相源,改规则或默认阈值直接改它。引用规则用步骤名/符号名(禁止硬编码行号);不存在 JS 判定代码镜像与 CI 镜像锁。
24
16
 
25
17
  ## 运行时执行模型(执行者必读)
26
18
 
27
- **Claude 是 loop 的执行者。** 本 skill 把 `mirror-rules.md` 的判定规则翻译成你可照做的行为指令:
28
-
29
19
  | 层 | 谁执行 | 说明 |
30
20
  |----|--------|------|
31
- | **Observe / Think / Reflect / Decide** | Claude 按 mirror-rules 规则判定 | 判定规则(终止优先级、proximity 公式、发散检测)定义在 `mirror-rules.md`,你在运行时按规则框执行做决策。 |
32
- | **Act** | **Claude 委托 `skill-agent-dispatcher` 多 agent 执行** | 这是本 skill 唯一的执行出口。用 implicit session team + subagent 执行 WP,**绝不自己写代码**。把 Think 的 decision 映射为 dispatchTarget → 调 dispatcher → skill-checklist 重验回填 CheckResult(见 Step 4.0–4.5)。 |
33
- | **持久化** | Claude 用 `skill-progress-tracker`(PROGRESS.md)+ task.md | 记录每轮 verdict/proximity/进度,防上下文压缩丢失。 |
21
+ | **Observe / Think / Reflect / Decide** | Claude 按 mirror-rules 规则判定 | 终止优先级、proximity 公式、发散检测均在 `mirror-rules.md` |
22
+ | **Act** | **委托 `skill-agent-dispatcher` 多 agent 执行**(唯一执行出口) | decision → dispatchTarget → 调 dispatcher → `skill-checklist` 重验回填 CheckResult(Step 4)。**loop 不直接 spawn Teamee,更不写代码** |
23
+ | **持久化** | `skill-progress-tracker`(PROGRESS.md)+ task.md | 每轮记 verdict/proximity,防上下文压缩丢失 |
34
24
 
35
- > 简言之:**决策靠规则(mirror-rules.md),执行靠团队(来自 dispatcher),记录靠 progress-tracker。** loop 自身不自己动手写代码。
36
-
37
- ---
25
+ **loop 永远不绕过 dispatcher 直接执行**——dispatcher 是 loop Act 层的执行单元。
38
26
 
39
27
  ## When to Use
40
28
 
41
- **触发词**:
42
- - "自主循环" / "agentic loop" / "目标驱动执行"
43
- - "自动重试失败项" / "P2P3 自闭环"
44
- - "这个任务自动跑到达成为止"
29
+ **触发词**: "自主循环" / "agentic loop" / "目标驱动执行" / "自动重试失败项" / "P2P3 自闭环" / "这个任务自动跑到达成为止"
45
30
 
46
- **适用场景**(满足任一即适合用 loop 而非线性 dispatcher):
47
- - **已生成计划,需自主执行**(首要场景):用户已在 brainstorming/plan 阶段产出 `.claude/plan.md`,希望 loop 读取计划、拆 WP、用 implicit session team 多 agent 自闭环跑到 checklist 全过——这正是 Step 0 路径 A 的入口
48
- - **目标驱动**:用户给的是"目标"(一批 WP 全部 checklist 通过),不是固定任务集,需要动态决定下一步
49
- - **需 P2↔P3 自主重试**:预期会有 checklist 失败项,希望失败后自动回到 P2 refine,而不是等人修复
50
- - **长程收敛任务**:多轮迭代才能达成,且每轮可量化接近度(proximity)
31
+ **适用**: 已生成计划需自主执行(首要:`/skill-doukui-plan` 产出 `docs/plan/{slug}.md` 或 `.claude/plan.md`,Step 0 路径 A);目标驱动、需动态决定下一步;需 P2↔P3 自主重试;多轮迭代的长程收敛任务。
32
+ **不适用**: 一次性小改动、不要自闭环 → 直接 `skill-agent-dispatcher`;需 P0 重新规划 → loop 不越界 P0。
51
33
 
52
- **不适用**(用现有线性流程即可,强用 loop 反而绕路):
53
- - 用户明确只要"一次性把某个小改动做完"、不要自闭环、不要 checklist → 直接 `skill-agent-dispatcher`
54
- - 需要 P0 重新规划的任务 → loop 不越界 P0(见安全边界)
34
+ > **WP 数量不构成退化理由**:拆出 1 个 WP 也走完整多 agent 闭环;唯一不启动的情形是解析不出 WP 或存在循环依赖,提示用户提供/修正计划而非"退化"(修复 cboot 根因:旧版让"单 WP、无失败预期"合法退化)。
55
35
 
56
- > **重要**:loop 的输入前提是**已拆好的 WP 集合**(`goal.wpIds`)。两条来源——优先读 `.claude/plan.md`(plan-reader),无则 Step 0 用 task-creator/split-work-package 从原始需求拆。**WP 数量不构成退化为线性 dispatcher 的理由**:拆出 1 个 WP 也走完整多 agent 闭环(见 Step 0 红线约束)。唯一不启动的情形是 plan-reader 解析不出任何 WP 或计划存在循环依赖——此时提示用户提供/修正计划,而非"退化"。
57
-
58
- ---
59
-
60
- ## 核心定位:loop 是决策层 + 规划入口,Act 委托 dispatcher 多 agent
61
-
62
- > 🔴 **不可违反的安全边界**(design.md §7.1、§9.1 风险表)
63
-
64
- | 角色 | 职责 | 实现 |
65
- |------|------|------|
66
- | **loop(本 skill)** | 决策层:P0 拆 WP(优先读 `.claude/plan.md` 经 plan-reader,回退 task-creator/split-work-package)→ P1 确认 → Observe→Think→Act→Reflect→Decide → 出口分流 | Claude 按本 skill 指令执行 |
67
- | **agent-dispatcher** | **Act 执行单元**:implicit session team + subagent 实际执行 WP / retry / resplit | 每轮 Act 委托它,**loop 不直接 `Agent()` spawn Teamee,更不自己写代码** |
68
-
69
- **loop 永远不绕过 dispatcher 直接执行**。loop 的 `Act` 通过委托 dispatcher 用 implicit session team 多 agent 执行 Think 选定的 WP,执行结果再由 checklist 重验。dispatcher 是"任务调度循环",loop 是"目标驱动循环"——前者是后者 Act 层的执行单元。**单 agent 手写代码是本 skill 明令禁止的退化行为。**
70
-
71
- ---
36
+ ## Step-by-Step Implementation
72
37
 
73
- ## Flow
74
-
75
- ```dot
76
- digraph agentic_loop {
77
- rankdir=TB;
78
-
79
- "P0: task-creator/split-work-package 拆 WP" [shape=box, style=filled, fillcolor=lightblue];
80
- "P1: human-checkpoint 确认目标与边界" [shape=box, style=filled, fillcolor=lightcoral];
81
- "while 循环(Claude 按规则迭代)" [shape=diamond, style=filled, fillcolor=orange];
82
-
83
- "Observe: 读 PROGRESS.md/task.md 聚合快照" [shape=box];
84
- "Think: 决策 dispatch/retry/resplit (mirror-rules 规则)" [shape=box];
85
- "Act: decision→dispatcher(implicit session team)→回填 CheckResult" [shape=box, style=filled, fillcolor=lightyellow];
86
- "Reflect: checklist 评分 + progress-tracker 记录" [shape=box];
87
- "Decide: 三类终止判定 (mirror-rules 规则)" [shape=diamond];
88
-
89
- "verdict=continue" [shape=box];
90
- "verdict=achieved → P4 completion-report" [shape=box, style=filled, fillcolor=lightgreen];
91
- "verdict=timeout/diverged/circuit_broken → 输出终止报告" [shape=box, style=filled, fillcolor=red];
92
-
93
- "P0: task-creator/split-work-package 拆 WP" -> "P1: human-checkpoint 确认目标与边界";
94
- "P1: human-checkpoint 确认目标与边界" -> "while 循环(Claude 按规则迭代)";
95
- "while 循环(Claude 按规则迭代)" -> "Observe: 读 PROGRESS.md/task.md 聚合快照";
96
- "Observe: 读 PROGRESS.md/task.md 聚合快照" -> "Think: 决策 dispatch/retry/resplit (mirror-rules 规则)";
97
- "Think: 决策 dispatch/retry/resplit (mirror-rules 规则)" -> "Act: decision→dispatcher(implicit session team)→回填 CheckResult";
98
- "Act: decision→dispatcher(implicit session team)→回填 CheckResult" -> "Reflect: checklist 评分 + progress-tracker 记录";
99
- "Reflect: checklist 评分 + progress-tracker 记录" -> "Decide: 三类终止判定 (mirror-rules 规则)";
100
- "Decide: 三类终止判定 (mirror-rules 规则)" -> "verdict=continue";
101
- "Decide: 三类终止判定 (mirror-rules 规则)" -> "verdict=achieved → P4 completion-report";
102
- "Decide: 三类终止判定 (mirror-rules 规则)" -> "verdict=timeout/diverged/circuit_broken → 输出终止报告";
103
- "verdict=continue" -> "while 循环(Claude 按规则迭代)";
104
- }
105
38
  ```
106
-
107
- ---
108
-
109
- ## Step-by-Step Implementation
39
+ Step 0 规划 → Step 1 human-checkpoint → Step 2 初始化记录 → Step 2.5 会话内自轮询(Observe → Think → Act(Step 4)→ Reflect → Decide)→ Step 5 出口分流
40
+ ```
110
41
 
111
42
  ### Step 0: P0 规划(Plan 模式内拆 WP)🔴 不可跳过
112
43
 
113
- 本 skill 标注 `plan_mode_required: true`,触发即进 Plan 模式。**在 Plan 模式内完成 WP 拆解,不得直接写代码**。
114
-
115
- Step 0 有**两条入口路径,按优先级取其一**:
116
-
117
- #### 路径 A(优先):读取已有计划文件拆 WP
44
+ 本 skill 标注 `plan_mode_required: true`,触发即进 Plan 模式,**在 Plan 模式内完成 WP 拆解,不得直接写代码**。两条入口路径按优先级取其一:
118
45
 
119
- 用户典型的预期流程是"先生成计划,再由 loop 按计划拆 WP 自主执行"。入口按**三级优先级**解析出 `planFilePath`(`plan-reader.parsePlanToGoal({planFilePath})` 已支持自定义路径,无需改 runtime 代码):
120
-
121
- ##### 路径解析(三级优先级,取首个命中)
46
+ #### 路径 A(优先):读已有计划,`doukui plan-lint` 取 goal
122
47
 
123
48
  | 优先级 | 来源 | 说明 |
124
49
  |--------|------|------|
125
- | **1(最高)** | 调用方传入路径参数 | 用户触发时附带,如 `/skill-agentic-loop docs/plan/xxx.md` 或 `plan=docs/plan/xxx.md`。Claude 解析该参数作为 `planFilePath` 传给 `plan-reader` |
126
- | **2** | `.claude/plan.md` 存在 | 向后兼容(现有行为):若项目根下存在 `.claude/plan.md`,用它 |
127
- | **3(新增回退)** | 扫描 `docs/plan/*.md` 最新 | 取 `docs/plan/` 下最近修改的一个 `.md` 文件作为 `planFilePath`(`skill-doukui-plan` 的产物落点) |
128
-
129
- > 解析出 `planFilePath` 后**统一交给 `plan-reader`**;三级优先级只决定读哪个文件,不影响解析逻辑。三级都未命中 → 视为"无可用计划",按下方异常处理 `plan-not-found` 提示(或走路径 B 回退)。
130
-
131
- 1. **读取计划**:按上述三级优先级解析出 `planFilePath`(默认 `.claude/plan.md`),用 `plan-reader`(`plugins/runtime/plan-reader.js`)的解析规则将其转为 loop 输入。
132
- - **解析规则**(plan-reader 的纯文本策略,会话内 Claude 按同一规则复现读取):
133
- - `##` / `###` section、`Step N:` 行 → 每个可执行 section 映射为一个 WP(标题含显式 `WP-NNN` 则沿用该编号,否则按 task.md 最大编号 +1 派生)
134
- - `- [ ]` / `- [x]` 任务项 → 该 WP 的 checklist(每项带稳定 id,供跨轮 Reflect 评分)
135
- - 「依赖 / depends on / 先完成 / requires / after」语义 → dependencyGraph
136
- - **产出结构**(`parsePlanToGoal()` 返回值):
137
- ```
138
- {
139
- goal: { wpIds: ['WP-...'], checklistSpec, successCriteria },
140
- workPackages: [{ wpId, title, checklist:[{id,category,item}], dependencies }],
141
- dependencyGraph: { nodes, edges, order, hasCycle, cycle },
142
- error: null | 'plan-not-found' | 'plan-empty' | 'plan-no-sections' | ...
143
- }
144
- ```
145
- 2. **直接采用为 loop 输入**:把 `goal.wpIds` + `workPackages[*].checklist` + `dependencyGraph` 作为 loop 输入,**不重新做 P0 拆解**(计划已是用户认可的目标分解)。
146
- 3. **异常处理**(plan-reader 的容错契约):
147
- - `goal.wpIds` 为空(计划缺失 / 为空 / 解析不出任何可执行 section)→ **不启动 loop**,提示用户"未读到可执行计划:请先用 `/skill-doukui-plan` 生成计划到 `docs/plan/`(再用 `/skill-agentic-loop docs/plan/xxx.md` 传入),或手动写 `.claude/plan.md`,或改用线性 `skill-agent-dispatcher` 直接执行"。提示语指向"提供/生成计划 / 改用 dispatcher",**不得**说"loop 无收益 / 退化"。
148
- - `dependencyGraph.hasCycle === true`(plan-reader 检测到循环依赖,会抛 `PLAN_CYCLIC_DEPENDENCY`)→ 捕获,提示用户"计划存在循环依赖(cycle:...),请修正 plan.md 的依赖声明后再启动 loop"。
50
+ | **1(最高)** | 调用方传入路径参数 | 如 `/skill-agentic-loop docs/plan/xxx.md`,该路径即 `planFilePath` |
51
+ | **2** | `.claude/plan.md` 存在 | 向后兼容 |
52
+ | **3(回退)** | 扫描 `docs/plan/*.md` 最新 | 取最近修改的 `.md`(`skill-doukui-plan` 产物落点) |
53
+
54
+ 1. **实跑** `doukui plan-lint <显式路径> --json`(只读,Plan 模式内可执行)。退出码 0 = 可用:取 `goal` + `workPackages`(含 `checklist[{id,category,item,verify}]`)+ `dependencyGraph` 作为 loop 输入,**不重新做 P0 拆解**(计划已是用户认可的目标分解)。
55
+ 2. **退出码 1 = 不可用**,按原因提示用户,**不启动 loop**:
56
+ - `plan-not-found` / `wpIds-empty` → 提示"未读到可执行计划:请先用 `/skill-doukui-plan` 生成计划到 `docs/plan/`(再用 `/skill-agentic-loop docs/plan/xxx.md` 传入),或写 `.claude/plan.md`,或改用线性 `skill-agent-dispatcher`"。**不得**说"loop 无收益 / 退化"。
57
+ - `cyclic-dependency` → 提示修正计划的依赖声明后再启动。`successCriteria-empty` → 提示补充「## 成功标准」section。
58
+ 3. **CLI 被权限拦截时的回退**(P1 列 WP 仍可完成):人肉核验四条——① 每个 `##` section 含 `- [ ]` 任务项(纯叙述不算 WP);② 有非空「## 成功标准」section;③ 依赖无环;④ verify 尾标形如 `[verify: command]`(命令不含右方括号)。通过即按同样的 goal / workPackages / dependencyGraph 结构手工拆出 WP。
149
59
  4. 进入 Step 1。
150
60
 
151
- #### 路径 B(回退):无 plan.md 时从原始需求 P0 拆解
152
-
153
- 仅当**不存在 `.claude/plan.md`**(或用户明确给出原始需求且尚未生成计划)时走此路径,保持向后兼容:
61
+ #### 路径 B(回退):无计划时从原始需求拆 WP
154
62
 
155
- 1. **分析目标**:把用户的原始需求理解为"目标"(如"做个赛博风电商前端能本地跑"),而非"立即动手的任务"。
156
- 2. **拆 WP**:调用 `skill-task-creator` / `skill-split-work-package`,把目标拆成一组可执行、有明确验收 checklist 的工作包(WP-XXX)。每个 WP 必须有:
157
- - 明确的交付物 + 验收 checklist(可量化"通过/失败")
158
- - 依赖关系(供 dispatcher 排序)
159
- 3. 进入 Step 1。
63
+ 三级路径都未命中且用户给出原始需求时:把需求当"目标",调 `skill-task-creator` / `skill-split-work-package` 拆成 WP(每个 WP 有交付物 + 可量化验收 checklist + 依赖),进入 Step 1。
160
64
 
161
65
  #### 共同产出(两条路径都满足)
162
66
 
163
- ```
164
- # Step 0 产出(写入 task.md / Plan):
165
- # - goal.wpIds: [WP-101, WP-102, WP-103, ...]
166
- # - 每个 WP 的验收 checklist(供 Reflect 评分)
167
- # - 达成判定: 全部 WP checklist 全过 AND proximity >= 0.9 AND 无 pending/failed WP
168
- # - 依赖图(供 dispatcher blockedBy 排序)
169
- # - 标注入口来源: plan-reader(路径 A)或 task-creator/split-work-package(路径 B)
170
- ```
67
+ `goal.wpIds` + 每个 WP 的验收 checklist(含 verify 尾标项)+ 依赖图(供 dispatcher blockedBy 排序)+ `planFilePath`;达成判定 = 全部 WP checklist 全过 AND proximity ≥ proximity_goal AND 无 pending/failed WP。写入 task.md 并标注入口来源。
171
68
 
172
- > 没有 Step 0 产出的 WP 集合,**禁止进入后续步骤**。这是修复"没规划阶段直接开写"的硬性闸门。
173
- >
174
- > 🔴 **关于 WP 数量与退化(强制约束,根因修复)**:loop **一律执行**,**不因 WP 数量退化**。即使 Step 0 拆完只有 1 个 WP,也走完整多 agent 闭环——loop 不做"单 WP 即建议改用线性 dispatcher"的判断。唯一允许的"不启动"情形是 **plan-reader 解析不出任何 WP(`goal.wpIds` 为空)** 或 **循环依赖**,二者均提示用户提供/修正计划,而非"退化"。这条约束修复了 cboot 会话根因:旧版 Step 0 第 4 点让 Claude 在"单 WP、无失败预期"时合法退化、跳过整个 loop。
69
+ > 没有 Step 0 产出的 WP 集合,**禁止进入后续步骤**——修复"没规划阶段直接开写"的硬性闸门。
175
70
 
176
71
  ### Step 1: 前置确认(P1 human-checkpoint)
177
72
 
178
- loop 是半自主的,**入口必须经 P1 人确认**。调用 `skill-human-checkpoint`,向用户确认:
73
+ loop 半自主,**入口必须经 P1 人确认**:P1 清单并入 `ExitPlanMode` 提交内容(写 Plan 模式计划文件,门控放行),**计划全文即审批内容**,批准即 P1 通过、门控自动复位。
179
74
 
180
- > **WP-S3 风险分级轻量化**:plan 顶层声明 `风险分级: low`(如纯文档/测试补充类任务)时,
181
- > P1 确认做**轻量化**——只向用户报一句「该 plan 已声明低风险(N 个 WP:xx/xx/xx),
182
- > 确认开跑?」,无需用户通读完整方案。state 记录 planRisk=low 时,gated hook 自动豁免
183
- > 强制暂停(v0.3.2 起默认自动,旧版环境变量 DOUKUI_LOW_RISK_GATE 已退役)。
184
- > 未声明风险的 plan 照常完整人审。
75
+ > **风险分级轻量化**:plan 声明 `风险分级: low`(纯文档/测试补充类,plan-lint 输出 `riskLow=true`)时,P1 只报一句「已声明低风险(N 个 WP:xx/xx/xx),确认开跑?」;未声明风险的 plan 照常完整人审。
185
76
 
186
- 1. **目标定义**:Step 0 产出的 `goal.wpIds` + 达成判定(checklist 全过 + proximity ≥ `proximity_goal` 默认 0.9)
187
- 2. **安全边界**:loop 仅 P2↔P3 自主;触顶/发散/熔断时**直接输出终止报告**(不再强制回 P1,见 Step 5)
188
- 3. **上限(全部可配置)**:用户/调用方可在触发或确认时指定,未指定用默认值:
189
- - `max_iterations`:默认 **6**(轮次上限;用户可改,如 `max_iterations=10`)
190
- - `max_round_time_ms`:默认 **600000**(单轮最长时间,10 分钟)
191
- - `max_wall_time_ms`:默认 **3600000**(总墙钟上限,1 小时)
192
- - `divergence_threshold`:默认 **3**(连续 N 轮 proximity 无进展即判发散)
193
- - `proximity_goal`:默认 **0.9**(达成判定阈值)
77
+ 1. **目标定义**:Step 0 产出的 `goal.wpIds` + 达成判定(checklist 全过 + proximity ≥ `proximity_goal`)
78
+ 2. **安全边界**:loop 仅 P2↔P3 自主,不越界 P0;出口 achieved→P4 completion-report,timeout/diverged/circuit_broken→终止报告(Step 5),不强制回 P1
79
+ 3. **上限(全部可配置)**:五项阈值 **默认值唯一自持于 mirror-rules.md「阈值默认值」节**;覆盖方式:触发时随参数(如 `/skill-agentic-loop max_iterations=10`)或审批前澄清指定(AskUserQuestion 不替代审批),生效值记入 Step 2。
194
80
 
195
- **阈值的两种传入方式(均会覆盖默认值,写入 Step 2 的 loop 记录)**:
196
-
197
- - **方式 A:触发 skill 时随参数传入**——在触发 `/skill-agentic-loop` 时附参数,如 `/skill-agentic-loop max_iterations=10 max_round_time_ms=900000`。Claude 解析后作为该 loop 的上限。
198
- - **方式 B:P1 确认时由用户指定**——在 human-checkpoint 确认清单里附「是否调整阈值」选项,用户可在确认目标的同时覆盖任一阈值;用户不改则沿用方式 A 的值或默认值。
199
-
200
- ```
201
- # 调用 human-checkpoint,附审核清单:
202
- # - 目标 WP 集合: [WP-101, WP-102, ...](Step 0 产出)
203
- # - 达成判定: checklist 全过 AND proximity >= proximity_goal(默认0.9) AND 无 pending/failed WP
204
- # - 自主范围: 仅 P2↔P3,不越界 P0 重新规划
205
- # - 上限(可配置,未指定取默认——默认值自持于 mirror-rules.md / 本 skill,修改只改那里): max_iterations=6 / max_round_time_ms=600000 / max_wall_time_ms=3600000 / divergence_threshold=3 / proximity_goal=0.9
206
- # - 出口: achieved→P4(completion-report) / timeout|diverged|circuit_broken→直接输出终止报告(见 Step 5,不强制回 P1)
207
- # - 「是否调整阈值」选项:用户可在此时覆盖 max_iterations / max_round_time_ms / max_wall_time_ms / divergence_threshold
208
- # 用户确认后进入 Step 2;用户修改目标则回到 Step 0 调整 WP。
209
- ```
81
+ 批准后进入 Step 2;要调整则改计划重新提交。
210
82
 
211
83
  ### Step 2: 初始化 loop 记录(goal + loopId)
212
84
 
213
- 记录 loop 运行的目标与边界(供持久化与恢复)。生成一个 `loopId`(如 `loop-20260613-电商前端-{rand}`),写入 PROGRESS.md / task.md:
85
+ 批准后(门控随审批自动复位):生成 `loopId`(如 `loop-20260613-电商前端-{rand}`),写入 PROGRESS.md:
214
86
 
215
87
  ```
216
- # loop 运行记录(写入 PROGRESS.md):
88
+ # loop 运行记录(PROGRESS.md):
217
89
  # loopId: loop-20260613-cybershop-a1b2c3
218
- # goal: { wpIds: [WP-101, WP-102, WP-103], successCriteria: all_pass_and_proximity>=0.9 }
219
- # 上限(可配置,此处写确认后的生效值,默认见 Step 1): max_iterations=6, max_round_time_ms=600000, max_wall_time_ms=3600000, divergence_threshold=3, proximity_goal=0.9
90
+ # planFilePath: docs/plan/cybershop.md # 🔴 每轮 doukui verify 显式携带,不依赖缺省解析
91
+ # goal: { wpIds: [WP-101, WP-102, WP-103], successCriteria: [...] }
92
+ # 上限(生效值,默认见 mirror-rules.md「阈值默认值」): max_iterations=…, max_round_time_ms=…, max_wall_time_ms=…, divergence_threshold=…, proximity_goal=…
220
93
  # iteration: 0
221
94
  # history: [] (每轮追加 verdict/proximity)
222
95
  ```
223
96
 
224
- > 运行时由 Claude 通过 PROGRESS.md 维护 loop 状态(progress-tracker),防上下文压缩。
97
+ > 运行时由 Claude 通过 PROGRESS.md 维护 loop 状态(progress-tracker),防上下文压缩。路径 B 无计划文件时 `planFilePath` 写 task.md,checklist 项全为 manual。
225
98
 
226
99
  ### Step 2.5: 进入会话内自轮询(唯一执行路径)🔴
227
100
 
228
- **本会话直接跑**——Read 本 skill 目录的 `mirror-rules.md`,按其规则框在当前会话内自轮询
229
- (Observe→Think→Act→Reflect→Decide,Act 委托 `skill-agent-dispatcher` 多 agent)。
230
-
231
- - `mirror-rules.md` 是判定规则的**唯一真相源**:Think/Decide 优先级、proximity 公式、发散判定、
232
- 阈值默认值全部自持于该文件,本 skill 不重复展开。
233
- - 会话内由本会话 Claude 驱动 dispatcher 多 agent 执行,无外部子进程、无单轮硬超时掐死问题。
234
- - 用户要求「后台挂机跑」时如实说明:执行路径只有会话内自轮询一种,后台进程模式已退役。
235
-
236
- ### Step 4: Act 集成(🔴 委托 dispatcher implicit session team 多 agent,loop 不写代码)
237
-
238
- > 🔴 **首条硬规则(违反即失败)**:**loop 是决策层,Act 必须委托 `skill-agent-dispatcher`(implicit session team + subagent)执行,loop 永不自己写代码。** 即使任务是「单 WP、看起来简单的纯文本替换」,也必须走多 agent 闭环——**单 agent 手写代码(Claude 自己 Write/Edit 完成 WP)= 违规**,无任何例外。这是修复 cboot 根因(旧版让 Claude 在「单 WP、无失败预期」时合法退化、跳过整个 loop)的指令层最终保险:Step 0 已删退化路径,此处再钉死「Act 永不手写」。
239
- >
240
- > 这是修复"单 agent 手写"的核心步骤。**loop 的 Act 永远委托 `skill-agent-dispatcher`,用 implicit session team + subagent 执行;Claude 不得自己 Write/Edit 代码完成 WP。**
101
+ **本会话直接跑**——Read `mirror-rules.md`,按其规则框在当前会话内自轮询(Observe→Think→Act→Reflect→Decide,Act 委托 dispatcher);无外部子进程、无单轮硬超时掐死。用户要求「后台挂机跑」时如实说明:执行路径只有会话内自轮询一种。
241
102
 
242
- 每轮 Act,把 Think 的 `decision`(dispatch/retry/resplit/noop)交给 dispatcher 多 agent 执行,执行后调 `skill-checklist` 重验,解析机器可读结果。
103
+ ### Step 4: Act 集成(🔴 委托 dispatcher 多 agent,loop 不写代码)
243
104
 
244
- #### 4.0 会话内端到端执行模型(必读)
245
-
246
- > 每轮数据流在会话内闭环,无外部执行器。理解这条链路,才能正确执行「decision → dispatcher → 回填」:
105
+ #### 4.0 会话内端到端数据流
247
106
 
248
107
  ```
249
- think(snapshot) → decision(dispatch/retry/resplit/noop,retry/resplit 时携带 failingDrivers)
250
- → Claude 把 decision 映射为 dispatchTarget(见 4.2,「待 dispatcher 消费的指令」)
251
- → 调 skill-agent-dispatcher 执行(implicit session team + 1:1 Teamee,见 4.3)
252
- → skill-checklist 重验,解析 CheckResult(见 4.4)
253
- → 作为本轮 lastChecklist 交给 Reflect(见 4.5 / mirror-rules Step 3c)
254
- → 下一轮 Observe/Think 消费 lastChecklist,状态机继续流转
108
+ think(snapshot) → decision(dispatch/retry/resplit/noop,retry/resplit 携带 failingDrivers)
109
+ → 映射为 dispatchTarget(4.2)→ 调 skill-agent-dispatcher(4.3)
110
+ → skill-checklist 重验:实跑 doukui verify,解析 CheckResult(4.4)
111
+ → 作为本轮 lastChecklist 交给 Reflect(4.5 / mirror-rules Step 3c)→ 下一轮 Observe/Think 消费
255
112
  ```
256
113
 
257
- > **关键边界**:`dispatchTarget` 只是「待执行的指令」,不是「已执行结果」——发出 dispatch 不代表子代理已跑完,一律以 checklist 回填的 CheckResult 为准。等价信息(decision/checklistResult)记到本轮 PROGRESS.md / 上下文,由 Claude 直接驱动 dispatcher。
114
+ > **关键边界**:`dispatchTarget` 只是「待执行的指令」,不是「已执行结果」——一律以 checklist 回填的 CheckResult 为准。
258
115
 
259
116
  #### 4.1 noop 直接返回
260
- 若 `decision.action === 'noop'`:无可执行项,跳过 Act(Reflect/Decide 会处理)。
117
+
118
+ 若 `decision.action === 'noop'`:无可执行项,跳过 Act。
261
119
 
262
120
  #### 4.2 把 Think 决策映射为 dispatcher 任务
121
+
263
122
  ```
264
123
  dispatchTarget = {
265
124
  wpId: decision.targetWp,
266
125
  mode: decision.action, # dispatch | retry | resplit
267
126
  strategy: decision.strategy || 'full_restart', # full_restart | checkpoint_resume | resplit
268
127
  context: (retry+checkpoint_resume) ? { completedFiles, remaining } : undefined,
269
- failingDrivers: decision.failingDrivers || [] # 🔴 retry 时重点修复的失败项明细(修复偏差2)
128
+ failingDrivers: decision.failingDrivers || [] # 🔴 retry/resplit 时重点修复的失败项明细
270
129
  }
271
130
  ```
272
131
 
273
- > **`failingDrivers` 字段语义**(修复偏差2,承接 Step 3c refine 通道第 4 步):
274
- > - **来源**:从 Think 产出的 `decision.failingDrivers` 读取(其源头是 Reflect 回填的 `state.failingDrivers` / `state.lastEval.failingDrivers`,每项 `{wpId, category, item, reason}`,来自 `lastChecklist.failedItems`)。
275
- > - **何时有意义**:仅 `mode=retry`(或 `resplit`)时有值——重做既有 WP 时告诉承接 Teamee"重点修哪些失败项"。`mode=dispatch`(首次执行)时为空数组。
276
- > - **去向**:传给 `skill-agent-dispatcher`,由 dispatcher restart 创建新 Teamee 时注入 prompt(WP-176-6 负责),Teamee 应优先修复 `failingDrivers` 列出的项,而非原样重做。这一步打通了"发现问题 → 针对性重做"的反馈链路(偏差1/2 的根因正是此处断链)。
132
+ > **`failingDrivers` 语义**:来源 Think 的 `decision.failingDrivers`(源头是 Reflect 从 `lastChecklist.failedItems` 归一化的 `{wpId, category, item, reason}`);仅 `mode=retry`/`resplit` 时有值,`dispatch` 为空数组;去向是 dispatcher「重派发」步骤——refine prompt 注入它,让重做 Teamee 优先修复这些失败项而非原样重做。
133
+
134
+ #### 4.3 委托 skill-agent-dispatcher 执行(单 WP)
277
135
 
278
- #### 4.3 🔴 委托 skill-agent-dispatcher 用 implicit session team 多 agent 执行(参照其 skill.md)
279
- 触发 `skill-agent-dispatcher` 执行 `dispatchTarget.wpId`(单个 WP)。dispatcher 内部完成全部多 agent 编排(**loop 不自己 spawn,也不自己写代码**):
136
+ 触发 `skill-agent-dispatcher` 执行 `dispatchTarget`。dispatcher 内部完成全部编排(**loop 不自己 spawn,也不写代码**):TaskCreate(WP, description 含 WP 文档路径) + blockedBy 依赖 → 角色匹配(roles-reference.md)→ 1:1 spawn 专用 Teamee:
280
137
 
281
138
  ```
282
- # dispatcher 流程(见 skill-agent-dispatcher 的 Step-by-Step Implementation 章节):
283
- 1. 初始化批次标签 team_name="loop-{loopId}-{wpId}-{rand}"(Lead 内部逻辑标识,非 harness 团队名;harness 自动分配 implicit session team,无需 TeamCreate)
284
- 2. TaskCreate(WP, description 含 WP 文档路径) + 设置 blockedBy 依赖
285
- 3. 角色匹配(roles-reference.md:关键词/任务类型/模块标签加权)→ 预计算角色与记忆
286
- 4. 为该 WP 创建专用 Teamee(1:1 映射):
287
- Agent(
288
- name="{role_id}-t{task.id}",
289
- subagent_type="general-purpose", # 🔴 必须 general-purpose(需 Write/Edit/Bash 完成实现)
290
- prompt=build_single_task_prompt(...) # 含 WP 文档路径 + 角色赋能 + 记忆
291
- )
292
- 5. 监控循环:Teamee 执行 → TaskUpdate completed → markTeameeDestroyed 逻辑销毁(无协议帧)→ 从映射表移除
293
- 6. 批末:当前 session implicit team 随 session 自动清理;历史残留的显式/UUID 团队目录可用 `node bin/doukui.js team-cleanup <team>` 清理(CLI 直接走 fs.rmSync,不调 TeamDelete)
139
+ Agent(
140
+ name="{role_id}-t{task.id}", # retry 时命名 {role_id}-t{task.id}-retry
141
+ subagent_type=resolve_subagent_type(role_id), # 双分支:存在 .claude/agents/{role_id}.md 生成物 → role_id;否则回退 general-purpose
142
+ prompt=build_single_task_prompt(...) # 含 WP 文档路径 + 角色赋能 + 记忆(retry 时为注入 failingDrivers 的 refine prompt)
143
+ )
294
144
  ```
295
145
 
296
- > **关键不变量**(见 dispatcher 的 Important 章节):每个 WP 由一个专用 Teamee 执行,绝不共享;完成即销毁;必须 `general-purpose`。loop 仅产出决策并把决策递给 dispatcher,**spawn Teamee 与写代码全归 dispatcher 内部的 Teamee**。
146
+ → 监控循环:Teamee 执行 → TaskUpdate completed → `markTeameeDestroyed` 逻辑销毁(无协议帧)。retry/resplit 走 dispatcher「重派发」步骤(逻辑销毁旧 Teamee → refine prompt 重 spawn),不越界 P0。
147
+
148
+ > **关键不变量**:每个 WP 由一个专用 Teamee 执行,绝不共享;完成即销毁;路由只走 `resolve_subagent_type` 双分支(两分支都具备 Write/Edit/Bash,禁止 Explore 等只读类型)。
149
+
150
+ #### 4.4 执行后按 skill-checklist 重验(实跑 `doukui verify`)
297
151
 
298
- #### 4.4 执行后调用 skill-checklist 重验,解析机器可读结果
299
152
  ```
300
- # 1. 触发 skill-checklist 对 dispatchTarget.wpId 执行检查
301
- # 2. 从其 Report 末尾解析 ```json:machine-readable ...``` fenced block,得到 CheckResult:
302
- # { wpId, passed, summary:{total,passed,failed}, categories[], failedItems[] }
303
- # 3. item.id 必须跨轮稳定(类别前缀+序号),否则发散检测误判
304
- checklistResult = parseChecklistMachineReadable(dispatchTarget.wpId)
153
+ # Lead 实跑(planFilePath 取自 Step 2 记录头):
154
+ doukui verify <planFilePath> --wp {dispatchTarget.wpId} [--timeout 秒] [--json]
155
+ # 退出码:0 = 全部 verify 项通过 / 1 = 有失败(含用法或解析错误)/ 2 = 该 WP 无 verify 项(全 manual)
156
+ # - verify 项(带 [verify: command] 尾标):以退出码为准,命令失败即 fail,不凭 Teamee 自述放行;
157
+ # 命令不可执行(PATH/环境)或超时 → 记环境 fail 并在 failingDrivers 标注
158
+ # - manual 项(无尾标):Lead 逐条判定,与 verify 结果合并为最终 CheckResult(passed = verify 全过且 manual 全过)
159
+ # - 人读输出末尾的 ```json:machine-readable 块即 CheckResult(--json 直出同结构):
160
+ # { wpId, passed, summary:{total,passed,failed,manual}, verifyResults:[{id,item,command,exitCode,passed}],
161
+ # failedItems:[{category,id,item,reason}], manualItems:[{id,item}] }
162
+ # - item.id 由 plan-reader 生成({wpId-slug}-{序号}),跨轮稳定,否则发散检测误判
305
163
  ```
306
164
 
307
- > retry/resplit 时,通过 dispatcher 的 daemon-actions 通道下发 `restart`(带 strategy)或重新调度(见 dispatcher 的 Step 6.5 Phase D.1 守护指令段),不越界 P0。
308
-
309
165
  #### 4.5 把 checklistResult 交给 Reflect(Step 3c 消费)
310
- 将 `checklistResult` 作为本轮 `lastChecklist`,Reflect 据此算 proximity/failingDrivers。
311
166
 
312
- > **若 checklist 尚未输出机器可读 block**:Reflect 走降级评分(基于 WP 完成度近似 proximity,见 mirror-rules Step 3c 降级规则)。
167
+ 将 `checklistResult` 作为本轮 `lastChecklist`,Reflect 据此算 proximity/failingDrivers。若尚未产出机器可读 block,Reflect 走降级评分(基于 WP 完成度近似 proximity,见 mirror-rules Step 3c)。
313
168
 
314
169
  ### Step 5: 出口分流(verdict 衔接)
315
170
 
316
- `decide` 产出的 verdict 决定 loop 后续走向。**衔接必须无歧义**:
317
-
318
171
  | verdict | 含义 | 后续动作 | 进入阶段 |
319
172
  |---------|------|---------|---------|
320
- | `continue` | 未达终止条件,可继续迭代 | 回 Step 3 下一轮 | P2↔P3 继续 |
321
- | `achieved` | checklist 全过 + proximity 达标 + 无 pending/failed | 调 `skill-completion-report` | **进 P4** |
322
- | `timeout` | 迭代上限 / 墙钟上限 / 单轮时长超限 | **输出终止报告**(读 `state.terminalReport`,含趋势 + 失败明细) | **输出报告(终止)** |
323
- | `diverged` | 连续 `divergence_threshold` 轮 proximity 无进展 | **输出终止报告**(附最近 N 轮趋势) | **输出报告(终止)** |
324
- | `circuit_broken` | 守护异常/dispatcher 监控报告终止 | **输出终止报告**(提示守护异常) | **输出报告(终止)** |
173
+ | `continue` | 未达终止条件 | 回下一轮 | P2↔P3 继续 |
174
+ | `achieved` | checklist 全过 + proximity 达标 + 无 pending/failed | 调 `skill-completion-report`(附 loop.history 摘要:迭代数 / proximity 趋势 / 各 WP 状态) | **进 P4** |
175
+ | `timeout` | 迭代上限 / 墙钟上限 / 单轮时长超限 | 输出终止报告(趋势 + 失败明细) | **输出报告(终止)** |
176
+ | `diverged` | 连续 `divergence_threshold` 轮 proximity 无进展 | 输出终止报告(附最近 N 轮趋势) | **输出报告(终止)** |
177
+ | `circuit_broken` | 人主动全局终止(Step 6) | 输出终止报告 | **输出报告(终止)** |
325
178
 
326
- > 🔴 **出口行为变更(WP-177)**:触顶/发散/熔断不再强制回 P1。终态 verdict(timeout/diverged/circuit_broken)一律**直接生成并输出总结报告**给用户(按下述 `outputTerminalReport` 契约)。人仍可经 `applyDirective`(Step 6)主动 pause/abort 介入——这是保留的安全边界,**不是默认回 P1 流程**。
179
+ > 🔴 **出口行为**:终态 verdict 一律直接输出终止报告,不强制回 P1;人仍可经 Step 6 主动介入(保留的安全边界,非默认回 P1 流程)。
327
180
 
328
- ```
329
- if finalVerdict == 'achieved':
330
- # → P4:触发 skill-completion-report,附 loop.history 摘要(迭代数 / proximity 趋势 / 各 WP 状态)
331
- runCompletionReport(loopId)
332
- else:
333
- # timeout / diverged / circuit_broken → 直接输出终止报告(不再回 P1)
334
- outputTerminalReport(loopId, finalVerdict)
335
- ```
181
+ #### `outputTerminalReport(loopId, verdict)` 终止报告契约
336
182
 
337
- #### `outputTerminalReport(loopId, verdict)` 终止报告呈现动作(WP-177)
338
- ```
339
183
  1. 记录最终 status 到 PROGRESS.md
340
- 2. 会话内按下述契约生成报告,报告含:
341
- - 结论 summary:第 N 轮以 verdict 终止 / 最终 proximity / 剩余失败项数 / 建议下一步
342
- - proximity 趋势表(最近 N 轮 iteration / proximity / failedCount / verdict)
343
- - 失败项明细表(wpId / category / item / reason,来自 failingDrivers)
344
- 3. 直接把报告 markdown 输出给用户(不必触发 human-checkpoint 全流程)。
345
- 4. 报告末尾附「可选后续」提示(非强制 P1):
346
- - 继续等待(重新进入 Step 3 主循环恢复运行)
347
- - 调整 goal 或阈值(回 Step 0 / Step 1 修改)
348
- - 手动修复失败项(人接管)
349
- - 终止
350
- > 注:以上「可选后续」是建议,由人主动选择;loop 默认不再自动回 P1。
351
- > 人若要介入,经 applyDirective(Step 6)下发 pause/abort。
352
- ```
353
-
354
- ### Step 6: 外部介入通道(人可随时干预)
184
+ 2. 会话内生成报告:结论 summary(第 N 轮以 verdict 终止 / 最终 proximity / 剩余失败项数 / 建议下一步)+ proximity 趋势表(最近 N 轮 iteration / proximity / failedCount / verdict)+ 失败项明细表(wpId / category / item / reason,来自 failingDrivers)
185
+ 3. 直接把报告 markdown 输出给用户(不必触发 human-checkpoint 全流程),末尾附「可选后续」(建议,非强制 P1):继续等待 / 调整 goal 或阈值(回 Step 0 / Step 1)/ 手动修复失败项(人接管)/ 终止
355
186
 
356
- loop 运行期间,人可随时介入(参考 dispatcher daemon-actions,design.md §7.1):
357
- - **暂停**:人要求暂停 → loop 不再推进新轮(已有 Teamee 继续运行完)
358
- - **中止**:人要求终止 → 记录 status=aborted,verdict=aborted,回 P1
359
- - **全局熔断**:人要求全局终止 → verdict=circuit_broken,回 P1
187
+ ### Step 6: 人介入通道(直接告知 Lead)
360
188
 
361
- ---
189
+ loop 运行期间,人可随时直接向 Lead 说(无文件通道):**暂停**(不再推进新轮,已有 Teamee 跑完)/ **中止**(status=aborted,verdict=aborted,回 P1)/ **全局熔断**(verdict=circuit_broken,mirror-rules Step 3d 规则「熔断」,回 P1)。
362
190
 
363
191
  ## 安全边界(不可越界,design.md §7.1)
364
192
 
365
- | 边界 | 规则 | 在本 skill 的体现 |
366
- |------|------|------------------|
367
- | **入口必先规划** | 触发即进 Plan 模式,Step 0 拆 WP 不可跳过(优先读 `.claude/plan.md`,回退 task-creator/split-work-package) | `plan_mode_required: true` + Step 0 硬闸门 |
368
- | **不越界 P0** | loop 仅 P2↔P3 自主。即使 Think 判定"需新拆分",也仅在现有 goal 范围内(resplit 拆当前失败 WP),**不重新触发 P0 全局规划** | Think 的 resplit 只针对上轮失败 WP;dispatch 有越界保护(pending WP 必须在 goal.wpIds 内) |
369
- | **P1 保留点** | loop 入口必须 P1 确认;触顶/发散/熔断直接输出终止报告,人经 applyDirective(Step 6)主动 pause/abort 介入 | Step 1 入口 / Step 5 出口分流 |
370
- | **Act 必须多 agent** | loop 永不自己写代码,Act 一律委托 dispatcher 用 implicit session team + subagent | Step 4,单 agent 手写 = 违规 |
371
- | **不做破坏性操作** | loop 的 Act 仅 dispatch/retry/resplit,不删除产物、不 force push、不改 git history | Act 仅委托 dispatcher 执行 WP,无破坏性副作用 |
372
- | **人可随时介入** | 暂停/中止/全局熔断通道 | Step 6 |
373
- | **双重硬上限** | max_iterations + max_wall_time_ms 防 loop 无限循环;守护异常熔断兜底 | Decide 规则 ③ 上限判定 + ① 熔断判定 |
374
-
375
- ---
193
+ | 边界 | 规则(在本 skill 的体现) |
194
+ |------|------|
195
+ | **入口必先规划** | 触发即进 Plan 模式,Step 0 不可跳过(`plan_mode_required: true` + 硬闸门) |
196
+ | **不越界 P0** | loop 仅 P2↔P3 自主。即使 Think 判定"需新拆分",也仅在现有 goal 范围内 resplit 拆当前失败 WP,不重新触发 P0 全局规划(dispatch 有越界保护,pending WP 必须在 goal.wpIds 内) |
197
+ | **P1 保留点** | 入口必须 P1 确认;终态直接输出终止报告,人经 Step 6 主动介入(Step 1 / Step 5) |
198
+ | **Act 必须多 agent** | loop 永不自己写代码,Act 一律委托 dispatcher(Step 4,单 agent 手写 = 违规) |
199
+ | **不做破坏性操作** | Act 仅 dispatch/retry/resplit,不删除产物、不 force push、不改 git history |
200
+ | **人可随时介入** | 暂停/中止/全局熔断(Step 6) |
201
+ | **双重硬上限** | `max_iterations` + `max_wall_time_ms` 防无限循环;人主动全局终止熔断兜底 |
376
202
 
377
203
  ## 状态持久化(防上下文压缩,design.md §8)
378
204
 
379
- loop 全程用 `skill-progress-tracker`(PROGRESS.md)+ task.md 记录,对照 agent-dispatcher `dispatcher-state.json` 思路:
380
-
381
- | 机制 | 实现 | 对照 dispatcher |
382
- |------|------|----------------|
383
- | **每轮写回** | 每轮 Decide 后把 verdict/proximity/iteration 追加到 PROGRESS.md history | dispatcher Phase B.5/C.5/D.5 |
384
- | **压缩后恢复** | 重新进入时读 PROGRESS.md 的 loop 记录,从最近 history 末尾 + iteration 恢复 | dispatcher Phase 0 |
385
- | **心跳可观测** | PROGRESS.md 含 `lastUpdatedAt` / `iteration`,供人/守护检测卡死 | dispatcher heartbeat |
205
+ loop 全程用 `skill-progress-tracker`(PROGRESS.md)+ task.md 记录:每轮 Decide 后把 verdict/proximity/iteration 追加到 history;压缩后重新进入时读 loop 记录,从最近 history 末尾 + iteration 恢复;记录含 `lastUpdatedAt` / `iteration`,供人观测卡死。
386
206
 
387
- **关键不变量**:
388
- - 任意轮中断后重新进入必须能从最近 history 恢复(幂等)。
389
- - iteration 单调递增,压缩后不回退。
390
- - history 完整保留所有轮判定(发散检测依赖完整 history)。
391
-
392
- ---
393
-
394
- ## 多 loop 协调(可选,design.md §10 / WP-174-5)
395
-
396
- 当一次会话并行多个 loop(多个独立目标各跑一个 loop)时,按聚合规则产出全局 verdict。全局优先级:**熔断 > 失败 > 达成 > 运行**:
397
- - `global_achieved`:全部 loop achieved → 进 P4
398
- - `global_circuit_broken`:任一 loop 熔断 → 全局回退
399
- - `global_failed`:任一 loop timeout/diverged → 回 P1
400
- - `global_running`:仍有 loop 迭代中
401
-
402
- > 单 loop 场景退化为该单 loop 的 verdict,逻辑一致。
403
-
404
- ---
207
+ **关键不变量**:任意轮中断后重新进入必须能从最近 history 恢复(幂等);iteration 单调递增,压缩后不回退;history 完整保留所有轮判定(发散检测依赖完整 history)。
405
208
 
406
209
  ## Integration with Other Skills
407
210
 
408
- | Skill | 集成点 | 本 skill 中的角色 |
409
- |-------|--------|------------------|
410
- | `plan-reader` | P0 规划入口(优先) | Step 0 路径 A:按三级优先级解析 planFilePath(参数路径 > `.claude/plan.md` > `docs/plan/` 扫描),拆为 `{goal.wpIds, checklist, 依赖图}`(`parsePlanToGoal({planFilePath})`) |
411
- | `skill-doukui-plan` | 计划来源入口(推荐) | 用户用 `/skill-doukui-plan` 生成符合 plan-reader 契约的计划到 `docs/plan/{slug}.md`,再以 `/skill-agentic-loop docs/plan/{slug}.md` 传入。是路径 A 优先级 1/3 的主要计划来源 |
412
- | `skill-task-creator` / `skill-split-work-package` | P0 规划(回退) | Step 0 路径 B:无 plan.md 时从原始需求拆 WP(loop 输入前提) |
413
- | `skill-human-checkpoint` | P1 入口 | Step 1 确认目标与边界;三类终止回退点 |
414
- | `skill-progress-tracker` | Observe / 持久化 | 读 PROGRESS.md 聚合快照;每轮记录 history |
415
- | `skill-agent-dispatcher` | **Act 执行单元(多 agent)** | Step 4 委托其用 implicit session team + subagent 执行 WP/retry/resplit,**loop 不写代码** |
416
- | `skill-checklist` | Reflect 评判 | Act 后重验,解析机器可读 JSON 为 CheckResult |
417
- | `skill-experience-logger` | Reflect 经验提炼 | 每轮 reflect 时提炼失败项经验(可选) |
418
- | `skill-completion-report` | P4 出口 | achieved verdict 触发,生成完成报告 |
419
- | `mirror-rules.md` | 判定规则唯一真相源 | Step 2.5 起按其规则框自轮询(Observe/Think/Reflect/Decide 规则 + 阈值默认) |
420
-
421
- ---
211
+ | Skill | 集成点 |
212
+ |-------|--------|
213
+ | `doukui plan-lint`(plan-reader) | P0 规划入口:Step 0 路径 A 解析 planFilePath,`--json` 取 `{goal, workPackages, dependencyGraph}` |
214
+ | `doukui verify` | Step 4.4 verify 项批跑,退出码口径 |
215
+ | `skill-doukui-plan` | 计划来源:生成到 `docs/plan/{slug}.md`,再以 `/skill-agentic-loop docs/plan/{slug}.md` 传入 |
216
+ | `skill-task-creator` / `skill-split-work-package` | Step 0 路径 B 从原始需求拆 WP |
217
+ | `skill-human-checkpoint` / `skill-progress-tracker` | Step 1 P1 确认 / Observe 读快照与每轮 history 记录 |
218
+ | `skill-agent-dispatcher` | **Act 执行单元**:Step 4 委托其 1:1 spawn Teamee 执行 WP / 重派发 retry·resplit |
219
+ | `skill-checklist` / `skill-experience-logger` | Act 后重验解析 CheckResult / 每轮提炼失败项经验(可选) |
220
+ | `skill-completion-report` | P4 出口:achieved 触发 |
221
+ | `mirror-rules.md` | 判定规则唯一真相源:Step 2.5 起按其规则框自轮询 |
422
222
 
423
223
  ## Important
424
224
 
425
- 1. **入口必先规划** — `plan_mode_required: true`,触发即进 Plan 模式,Step 0 用 task-creator/split-work-package 拆 WP。没有 `goal.wpIds`,loop 不启动。禁止跳过规划直接写代码。
426
- 2. **Act 必须多 agent(绝对红线,无任何例外)** — loop 是决策层,Act 一律委托 `skill-agent-dispatcher` 用 implicit session team + subagent(`Agent(subagent_type='general-purpose')` 1:1 spawn Teamee,subagent 自动加入 implicit session team,无需 TeamCreate)执行。**单 agent 手写代码 = 违规**,含「单 WP、看起来简单」的情形也无例外(修复 cboot 退化根因)。
427
- 3. **loop 是决策层,dispatcher 是 Act 执行单元** — loop 仅产出决策并把决策递给 dispatcher;spawn Teamee 与写代码全归 dispatcher 内部(design.md §7.1 / §9.1)。
428
- 4. **P1 保留点** — 半自主默认,启动前必须 human-checkpoint 确认;触顶/发散/熔断时直接输出终止报告(不再强制回 P1 全流程),人经 applyDirective(Step 6)主动 pause/abort 介入。
429
- 5. **verdict 衔接无歧义** — `achieved` → P4(completion-report);`timeout`/`diverged`/`circuit_broken` → 输出终止报告(`outputTerminalReport`,见 Step 5);`continue` → 下一轮。
430
- 6. **不越界 P0** — 即使 Think 判定需 resplit,也仅限当前 goal 范围内拆失败 WP,不触发 P0 全局重新规划。
431
- 7. **状态全程持久化** — 用 progress-tracker(PROGRESS.md)每轮写回 history,压缩后从最近 history 恢复,iteration 单调递增。
432
- 8. **双重硬上限 + 熔断兜底** — `max_iterations` + `max_wall_time_ms` 防无限循环,守护异常触发 `circuit_broken`。
433
- 9. **判定规则唯一真相源 = mirror-rules.md** — observe/think/reflect/decide 的判定规则(Think/Decide 优先级、proximity 公式、发散判定、阈值默认)自持于 `mirror-rules.md`,会话内按其规则框执行(见 Step 2.5 / 4.0);不存在 JS 判定代码与 CI 镜像锁,改规则直接改 mirror-rules.md。
434
- 10. **依赖 checklist 机器可读输出** — Act 的 refine 反馈依赖 checklist Report 末尾的 `json:machine-readable` block;未就绪时走降级评分。
225
+ 1. **两条红线无任何例外**(见文首):无 `goal.wpIds` 不启动;单 WP、看起来简单也必须走 dispatcher(修复 cboot 退化根因)。
226
+ 2. **loop 是决策层,dispatcher 是 Act 执行单元** — spawn Teamee 与写代码全归 dispatcher(design.md §7.1 / §9.1)。
227
+ 3. **P1 保留点** — 启动前必须 human-checkpoint;终态直接输出终止报告,人经 Step 6 主动介入。
228
+ 4. **verdict 衔接无歧义** — `achieved` → P4;`timeout`/`diverged`/`circuit_broken` → `outputTerminalReport`;`continue` → 下一轮。
229
+ 5. **不越界 P0** — resplit 仅限当前 goal 内拆失败 WP。
230
+ 6. **状态全程持久化** — 每轮写回 history,压缩后从最近 history 恢复,iteration 单调递增。
231
+ 7. **双重硬上限 + 熔断兜底** — `max_iterations` + `max_wall_time_ms` 防无限循环;人主动全局终止触发 `circuit_broken`。
232
+ 8. **判定规则唯一真相源 = mirror-rules.md** — 规则与阈值默认值自持于该文件,改规则直接改它。
233
+ 9. **依赖 checklist 机器可读输出 + verify 退出码** — refine 反馈依赖 CheckResult 的 `failedItems`;verify 项以 `doukui verify` 退出码为准,manual 项才 LLM 判;未就绪时走降级评分。
@@ -4,7 +4,7 @@
4
4
  "type": "skill",
5
5
  "description": "批量任务创建 Skill - 批量创建工作包定义(仅定义不实现),支持跨任务依赖声明和全局依赖图生成",
6
6
  "triggers": ["批量创建任务", "批量新建任务", "batch-task-creator", "batch create tasks", "create multiple tasks"],
7
- "dependencies": ["provider:state-store"],
7
+ "dependencies": [],
8
8
  "provides": ["skill:batch-task-creator"],
9
9
  "metadata": {
10
10
  "gatedByCode": true