doukui 0.3.1 → 0.5.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.
@@ -0,0 +1,100 @@
1
+ # 镜像路径规则(engine 行为镜像 · 会话内默认路径)
2
+
3
+ > **何时读本文件(v0.4.1 起默认)**:skill Step 2.5 的**默认执行路径**——在当前会话内按本文件
4
+ > 规则框自轮询跑 loop。driver 子进程(`doukui loop`)改为显式 opt-in(用户明确要求「起 driver /
5
+ > 后台跑」时;其 CLI 探测失败仍输出 provider settings 修复指引,不静默换路径)。翻转依据:driver
6
+ > executor 单轮默认 15min 硬超时对大体量 WP 是结构性缺陷,会话内路径无此问题。
7
+ >
8
+ > **镜像一致性**:本文件规则文本是 `provider-loop-engine/index.js`(判定逻辑)+
9
+ > `plugins/runtime/loop-defaults.js`(阈值默认)的行为镜像,由
10
+ > `test/runtime/test-agentic-loop-skill-mirror.js` CI 锁定数字一致性。改规则先改 engine/loop-defaults,
11
+ > 再同步本文件。
12
+
13
+ ## 主循环骨架
14
+
15
+ **Claude 循环执行 Observe→Think→Act→Reflect→Decide 一轮,按 verdict 分流**。判定规则严格复现
16
+ `provider-loop-engine` 的 `_think` / `_decide` / evaluator 语义(见下方各步规则框)。
17
+
18
+ ```
19
+ safetyMaxRounds = 50 # 外层保险(内部已有 max_iterations/max_wall_time 双重硬上限)
20
+ rounds = 0
21
+ finalVerdict = null
22
+
23
+ while rounds < safetyMaxRounds:
24
+ rounds += 1
25
+ iteration += 1
26
+
27
+ # ---- Observe(Step 3a)----
28
+ snapshot = observe() # 读 PROGRESS.md/task.md:pending/completed/failed WP + 上轮 checklist
29
+
30
+ # ---- Think(Step 3b,复现 engine _think)----
31
+ decision = think(snapshot) # dispatch | retry | resplit | noop
32
+
33
+ # ---- Act(Step 4,委托 dispatcher 多 agent)----
34
+ checklistResult = act(decision) # 🔴 委托 skill-agent-dispatcher 用 implicit session team 多 agent 执行
35
+
36
+ # ---- Reflect(Step 3c,复现 engine evaluator)----
37
+ evalResult = reflect(snapshot, checklistResult) # proximity / converged / diverged
38
+
39
+ # ---- Decide(Step 3d,复现 engine _decide)----
40
+ verdict = decide(evalResult, snapshot) # continue | achieved | timeout | diverged | circuit_broken
41
+
42
+ # 记录本轮到 history(progress-tracker)
43
+ record(iteration, verdict, evalResult.proximity)
44
+
45
+ 输出: "[loop {loopId}] iter {iteration} verdict={verdict} proximity={evalResult.proximity}"
46
+
47
+ if verdict == 'continue':
48
+ continue
49
+ finalVerdict = verdict
50
+ break
51
+
52
+ # 按 verdict 分流(见 skill.md Step 5 / Step 6)
53
+ ```
54
+
55
+ ## Step 3a: Observe 规则
56
+ 读取当前快照(来源:`skill-progress-tracker` 的 PROGRESS.md + task.md):
57
+ - `workPackages`:goal.wpIds 中 `pending`(未完成)/ `completed`(已通过 checklist)/ `failed`(上轮 checklist 失败待重试)/ `blocked`(依赖未满足)
58
+ - `lastChecklist`:上轮 Act 产出的 CheckResult(来自 skill-checklist 机器可读 block)
59
+ - 进度趋势:最近 N 轮 proximity 序列(发散检测用)
60
+
61
+ > **`failed` 的来源口径**(对齐 engine `_think` retry 分支 + loop-snapshot `buildWorkPackages`,WP-176-2):
62
+ > `workPackages.failed` 不是凭空写出,而是由 `lastChecklist.failedItems` 聚合——把每条失败项的 `wpId` 去重后得到待重试的 WP 列表(排除已 `completed`、限定 `goal.wpIds` 范围)。这样 `_think` 的 `wp.failed.length > 0` 才能真实命中 retry(修复偏差1:原先 failed 写死空数组 → retry 永远走不到)。运行时 Claude 聚合时同理:从上轮 CheckResult.failedItems 取 wpId 集合作为 `failed`。
63
+
64
+ ## Step 3b: Think 规则(镜像 engine `_think`:dispatch/retry/resplit/noop 优先级)
65
+ 优先级:**失败项重试 > 待执行调度 > 被阻塞 noop**
66
+ 1. 若有 `failed` WP(`wp.failed` 非空,见 Step 3a 来源口径)→ `retry`:
67
+ - `targetWp = wp.failed[0]`(首个失败 WP)
68
+ - `strategy`:该 WP 有 checkpoint → `checkpoint_resume`,否则 `full_restart`
69
+ - **`failingDrivers`**:携带 Reflect 回填的失败项明细(优先 `state.failingDrivers`,回退最近一次 `state.lastEval.failingDrivers`,二者均空降级为 `[]`),供 skill.md Step 4.2 下发给承接重做的 Teamee 作为 refine 反馈
70
+ 2. 若 `failed` 为空但上轮 `lastChecklist.passed === false` → `resplit`(`targetWp = lastChecklist.wpId`,`strategy='resplit'`,不越界 P0 全局规划)
71
+ 3. 若有 `pending` WP(且在 goal.wpIds 范围内,越界保护)→ `dispatch`(`targetWp` 为 goal 范围内首个 pending,`strategy='full_restart'`)
72
+ 4. 全部被阻塞 → `noop`(持续 noop 由发散/上限兜底)
73
+
74
+ > **retry vs resplit 分流对齐**(修复偏差1 + engine/运行时落差):engine `_think` 的真实数据流是 `wp.failed.length > 0` 命中 retry、`failed` 空但 `lastChecklist.passed===false` 命中 resplit。运行时 Claude 复现时严格按此优先级——先看 `failed`(来自 failedItems 聚合),再看 `lastChecklist.passed`,二者顺序不可换,否则会像旧版 engine 那样把真实 retry 误判成 resplit。
75
+
76
+ ## Step 3c: Reflect 规则(复现 `reflection-evaluator`)
77
+ - `proximity = 1 - (failed / total)`(来自上轮 CheckResult.summary;钳到 [0,1]);无 checklist 时降级按 WP 完成度 `completed/total`
78
+ - `converged`:本轮 proximity 严格 > 上一轮
79
+ - `divergenceStreak`:从 history 末尾数连续多少轮 proximity 不增(含回退)
80
+ - `diverged`:`divergenceStreak >= divergence_threshold`(默认 3);已达成态(proximity≥goal 且 allPassed)不算发散
81
+ - `failingDrivers`:由 `CheckResult.failedItems` 归一化产出,每项结构 `{wpId, category, item, reason}`(`reflection-evaluator` 辅助函数聚合,WP-176-1)
82
+
83
+ > **`failingDrivers` refine 通道(完整流转,修复偏差2)**——engine 路径与运行时复现必须打通同一条链路:
84
+ > 1. **产出**:Reflect 把 `lastChecklist.failedItems` 归一化为 `failingDrivers`(写入 `EvalResult.failingDrivers`)。
85
+ > 2. **回填 state**(engine `reflect` 阶段的 state 回填):`state.failingDrivers = evalResult.failingDrivers || []`、`state.divergenceStreak = evalResult.divergenceStreak`。运行时 Claude 等效地把它记到本轮 PROGRESS.md / state 记录里,供下轮读取。
86
+ > 3. **下轮 Think 消费**(Step 3b):retry decision 携带 `decision.failingDrivers`(优先 `state.failingDrivers`,回退 `state.lastEval.failingDrivers`)。
87
+ > 4. **进入 skill.md Step 4.2**:把 `decision.failingDrivers` 映射进 `dispatchTarget.failingDrivers`。
88
+ > 5. **dispatcher → 重做 Teamee**(WP-176-6):dispatcher restart 创建新 Teamee 时把 `failingDrivers` 注入 prompt,Teamee 据此优先修复这些失败项。
89
+ >
90
+ > 缺第 2 步(回填)或第 4 步(进 dispatcher 参数)都会让链路断裂——这正是偏差1/偏差2 的根因:数据算出来了但没流到重做者手里。
91
+
92
+ ## Step 3d: Decide 规则(镜像 engine `_decide`:熔断 > 发散 > 达成 > 上限 > 继续)
93
+ 优先级 **熔断 > 发散 > 达成 > 上限 > 继续**(「达成」上提到「上限」之前——修复末轮 `iteration==max_iterations` 时 proximity 已达标却被抢判 `timeout` 的 bug:末轮达标应判 `achieved`,未达标才判 `timeout` 兜底):
94
+ 1. **熔断**:watchdog/守护异常(terminated / 持续 degraded)→ `circuit_broken`(运行时若 dispatcher 监控报告守护异常即触发)
95
+ 2. **发散**:`divergenceStreak >= divergence_threshold` → `diverged`
96
+ 3. **达成**:`allPassed && proximity >= proximity_goal && noPending && noFailed` → `achieved`
97
+ 4. **上限**:`iteration >= max_iterations`、墙钟超 `max_wall_time_ms`、或单轮时长超 `max_round_time_ms` → `timeout`(兜底:本轮未达成才判 timeout)
98
+ 5. 否则 → `continue`
99
+
100
+ > **`noFailed` 现真实生效**(修复偏差1 + 落差,engine `_decide` 的 noFailed 判定):`noFailed = (!wp.failed || wp.failed.length===0) && (!evalResult.failingDrivers || evalResult.failingDrivers.length===0)`。即 WP 级 failed 列表与 CheckResult 级 failingDrivers 明细**任一非空**都判为"仍有失败项",不能进 `achieved`。运行时 Claude 复现时须同时检查这两个来源,不可只看 `wp.failed`。
@@ -2,7 +2,7 @@
2
2
  "name": "skill-agentic-loop",
3
3
  "version": "1.1.0",
4
4
  "type": "skill",
5
- "description": "Use when user says \"自主循环\", \"agentic loop\", \"目标驱动执行\", or needs a goal-driven P2↔P3 self-closing loop that retries failed checklist items autonomously until achieved/diverged/timeout, then returns to P1 human-checkpoint or proceeds to P4. Loop is decision layer; Act is delegated to agent-dispatcher via Agent Teams (subagents) — loop never writes code itself.",
5
+ "description": "Use when user says \"自主循环\", \"agentic loop\", \"目标驱动执行\", or needs a goal-driven P2↔P3 self-closing loop that retries failed checklist items autonomously until achieved/diverged/timeout, then returns to P1 human-checkpoint or proceeds to P4",
6
6
  "triggers": ["自主循环", "agentic loop", "目标驱动", "自闭环", "自动重试", "P2P3 loop", "skill-agentic-loop"],
7
7
  "dependencies": ["provider:loop-engine", "provider:state-store", "provider:watchdog"],
8
8
  "provides": ["skill:agentic-loop"],
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: skill-agentic-loop
3
- description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱动执行\", or needs a goal-driven P2↔P3 self-closing loop that retries failed checklist items autonomously until achieved/diverged/timeout, then returns to P1 human-checkpoint or proceeds to P4. Loop is decision layer; Act is delegated to agent-dispatcher via Agent Teams (subagents) — loop never writes code itself."
3
+ description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱动执行\", or needs a goal-driven P2↔P3 self-closing loop that retries failed checklist items autonomously until achieved/diverged/timeout, then returns to P1 human-checkpoint or proceeds to P4"
4
4
  ---
5
5
 
6
6
  # Agentic Loop (半自主目标驱动执行循环 · implicit session team 多 agent 版)
@@ -19,7 +19,7 @@ description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱
19
19
  > - **唯一真相源** = `plugins/core/provider-loop-engine/index.js`(判定逻辑)+ `plugins/runtime/loop-defaults.js`(阈值默认值,单源化)。
20
20
  > - 修改判定规则或默认阈值:**先改 engine / loop-defaults,再同步本 skill 的镜像段落**(含 `skill-agentic-loop/plugin.json` 的 config 静态镜像)。
21
21
  > - 镜像一致性由 `test/runtime/test-agentic-loop-skill-mirror.js` CI 锁定(skill 文本中的默认阈值数字必须与 loop-defaults.js 相等);引用 engine 时一律用**符号名**(如 engine `_think`),禁止硬编码行号(行号随代码漂移)。
22
- > - 代码驱动路径(`doukui loop`)由 JS engine 直接决策,本 skill 仅在**会话内路径**(无 driver)下按镜像规则自轮询。
22
+ > - 代码驱动路径(`doukui loop`)由 JS engine 直接决策;**会话内路径**(无 driver,Step 2.5 起为默认)按镜像规则自轮询。
23
23
 
24
24
  ---
25
25
 
@@ -71,21 +71,6 @@ description: "Use when user says \"自主循环\", \"agentic loop\", \"目标驱
71
71
 
72
72
  ---
73
73
 
74
- ## 集成映射(loop 五层 ↔ 现有 skill)
75
-
76
- | loop 层 | 职责 | 集成对象 | 说明 |
77
- |---------|------|---------|------|
78
- | **P0 规划** | 拆 WP 集合(loop 输入前提) | **优先 `plan-reader`(读 `.claude/plan.md`)**;无计划时回退 `skill-task-creator` / `skill-split-work-package` | Step 0,触发即进 Plan 模式 |
79
- | **入口(P1)** | 人确认目标与安全边界 | `skill-human-checkpoint` | Step 1,loop 启动前必须经 P1 确认 |
80
- | **Observe** | 聚合环境快照 | `skill-progress-tracker`(PROGRESS.md)+ task.md | Claude 读取未完成 WP / 上轮 checklist 结果 / 进度 |
81
- | **Think** | 决策下一步(复现 engine `_think` 规则) | 本 skill 内置规则 | dispatch / retry / resplit / noop |
82
- | **Act** | **执行 WP + 重验 checklist(多 agent)** | `skill-agent-dispatcher`(implicit session team + subagent) | Step 4,委托 dispatcher,**loop 不写代码** |
83
- | **Reflect** | 收敛/发散/接近度评分(复现 engine `_decide`/evaluator 规则) | `skill-checklist`(机器可读 JSON)+ 本 skill 规则 | checklist 输出 CheckResult,按规则算 proximity |
84
- | **Decide** | 三类终止判定(复现 engine `_decide` 规则) | 本 skill 规则 | 熔断 > 发散 > 达成 > 上限 > 继续 |
85
- | **出口(P4)** | 达成后汇报 | `skill-completion-report` | 仅 achieved verdict 触发 |
86
-
87
- ---
88
-
89
74
  ## Flow
90
75
 
91
76
  ```dot
@@ -195,8 +180,9 @@ loop 是半自主的,**入口必须经 P1 人确认**。调用 `skill-human-ch
195
180
 
196
181
  > **WP-S3 风险分级轻量化**:plan 顶层声明 `风险分级: low`(如纯文档/测试补充类任务)时,
197
182
  > P1 确认做**轻量化**——只向用户报一句「该 plan 已声明低风险(N 个 WP:xx/xx/xx),
198
- > 确认开跑?」,无需用户通读完整方案。若用户已在环境设 `DOUKUI_LOW_RISK_GATE=1` 且
199
- > state 记录 planRisk=low,gated hook 也自动豁免强制暂停。未声明风险的 plan 照常完整人审。
183
+ > 确认开跑?」,无需用户通读完整方案。state 记录 planRisk=low 时,gated hook 自动豁免
184
+ > 强制暂停(v0.3.2 起默认自动,旧版环境变量 DOUKUI_LOW_RISK_GATE 已退役)。
185
+ > 未声明风险的 plan 照常完整人审。
200
186
 
201
187
  1. **目标定义**:Step 0 产出的 `goal.wpIds` + 达成判定(checklist 全过 + proximity ≥ `proximity_goal` 默认 0.9)
202
188
  2. **安全边界**:loop 仅 P2↔P3 自主;触顶/发散/熔断时**直接输出终止报告**(不再强制回 P1,见 Step 5)
@@ -238,109 +224,36 @@ loop 是半自主的,**入口必须经 P1 人确认**。调用 `skill-human-ch
238
224
 
239
225
  > design 把状态放在 `state-store` key `loop.{loopId}`(engine 测试用)。运行时由 Claude 通过 PROGRESS.md 维护等效信息(progress-tracker),防上下文压缩。
240
226
 
241
- ### Step 2.5: 路径选择(v0.3.1 T6——driver 子进程优先,镜像降级)🔴
242
-
243
- **探测 `doukui --version`(或 `node <doukui包根>/bin/doukui.js --version`)**:
244
-
245
- - **✅ CLI 可用 → 必须走 driver 子进程路径(主路径)**:
246
- 1. 用 Bash 后台启动:`doukui loop <plan 路径> --executor=default --loop-id=<本 loopId> [--settings=<provider 配置>] &`
247
- —— 决策由 **JS engine 真跑**(Observe→Think→Reflect→Decide 全在 driver 进程内),本会话只做监控,**不复现任何判定规则**
248
- 2. 监控协议(每 30~60s 轮询一次,用 Bash `tail`):
249
- - `.doukui/loop-{loopId}/trace.jsonl` 尾部 1 行 = 最新轮次的五段计时 + verdict + token
250
- - `PROGRESS.md` = WP 完成标记
251
- - 终态:driver 退出(`wait` 或检查进程)后读 stdout 尾部的「Agentic Loop 终止报告」呈现给用户;含 `♻ WP-S1 自救` 行则说明自救链已自动介入
252
- 3. 会话在 loop 运行期间**只读不写**仓库文件(driver 子进程持有执行权,并行写会冲突)
253
- - **⚠️ CLI 不可用(未安装/无 provider settings)→ 走下方 Step 3 镜像路径(降级)**:
254
- Step 3 的规则框是 engine 决策的**行为镜像**,仅在无 driver 可启动时按其自轮询。
255
- 镜像与 engine 的一致性由 `test-agentic-loop-skill-mirror.js` CI 锁定。
256
-
257
- ### Step 3: 主循环(Claude 按规则迭代,按 verdict 分流)【降级路径——CLI 可用时走 Step 2.5 driver 路径】
258
-
259
- 这是 loop 的核心。**Claude 循环执行 Observe→Think→Act→Reflect→Decide 一轮,按 verdict 分流**。判定规则严格复现 `provider-loop-engine` 的 `_think` / `_decide` / evaluator 语义(见下方各步规则框)。
260
-
261
- ```
262
- safetyMaxRounds = 50 # 外层保险(内部已有 max_iterations/max_wall_time 双重硬上限)
263
- rounds = 0
264
- finalVerdict = null
265
-
266
- while rounds < safetyMaxRounds:
267
- rounds += 1
268
- iteration += 1
269
-
270
- # ---- Observe(Step 3a)----
271
- snapshot = observe() # 读 PROGRESS.md/task.md:pending/completed/failed WP + 上轮 checklist
272
-
273
- # ---- Think(Step 3b,复现 engine _think)----
274
- decision = think(snapshot) # dispatch | retry | resplit | noop
275
-
276
- # ---- Act(Step 4,委托 dispatcher 多 agent)----
277
- checklistResult = act(decision) # 🔴 委托 skill-agent-dispatcher 用 implicit session team 多 agent 执行
278
-
279
- # ---- Reflect(Step 3c,复现 engine evaluator)----
280
- evalResult = reflect(snapshot, checklistResult) # proximity / converged / diverged
281
-
282
- # ---- Decide(Step 3d,复现 engine _decide)----
283
- verdict = decide(evalResult, snapshot) # continue | achieved | timeout | diverged | circuit_broken
284
-
285
- # 记录本轮到 history(progress-tracker)
286
- record(iteration, verdict, evalResult.proximity)
287
-
288
- 输出: "[loop {loopId}] iter {iteration} verdict={verdict} proximity={evalResult.proximity}"
289
-
290
- if verdict == 'continue':
291
- continue
292
- finalVerdict = verdict
293
- break
294
-
295
- # 按 verdict 分流(见 Step 5 / Step 6)
296
- ```
297
-
298
- #### Step 3a: Observe 规则
299
- 读取当前快照(来源:`skill-progress-tracker` 的 PROGRESS.md + task.md):
300
- - `workPackages`:goal.wpIds 中 `pending`(未完成)/ `completed`(已通过 checklist)/ `failed`(上轮 checklist 失败待重试)/ `blocked`(依赖未满足)
301
- - `lastChecklist`:上轮 Act 产出的 CheckResult(来自 skill-checklist 机器可读 block)
302
- - 进度趋势:最近 N 轮 proximity 序列(发散检测用)
303
-
304
- > **`failed` 的来源口径**(对齐 engine `_think` retry 分支 + loop-snapshot `buildWorkPackages`,WP-176-2):
305
- > `workPackages.failed` 不是凭空写出,而是由 `lastChecklist.failedItems` 聚合——把每条失败项的 `wpId` 去重后得到待重试的 WP 列表(排除已 `completed`、限定 `goal.wpIds` 范围)。这样 `_think` 的 `wp.failed.length > 0` 才能真实命中 retry(修复偏差1:原先 failed 写死空数组 → retry 永远走不到)。运行时 Claude 聚合时同理:从上轮 CheckResult.failedItems 取 wpId 集合作为 `failed`。
306
-
307
- #### Step 3b: Think 规则(镜像 engine `_think`:dispatch/retry/resplit/noop 优先级)
308
- 优先级:**失败项重试 > 待执行调度 > 被阻塞 noop**
309
- 1. 若有 `failed` WP(`wp.failed` 非空,见 Step 3a 来源口径)→ `retry`:
310
- - `targetWp = wp.failed[0]`(首个失败 WP)
311
- - `strategy`:该 WP 有 checkpoint → `checkpoint_resume`,否则 `full_restart`
312
- - **`failingDrivers`**:携带 Reflect 回填的失败项明细(优先 `state.failingDrivers`,回退最近一次 `state.lastEval.failingDrivers`,二者均空降级为 `[]`),供 Step 4.2 下发给承接重做的 Teamee 作为 refine 反馈
313
- 2. 若 `failed` 为空但上轮 `lastChecklist.passed === false` → `resplit`(`targetWp = lastChecklist.wpId`,`strategy='resplit'`,不越界 P0 全局规划)
314
- 3. 若有 `pending` WP(且在 goal.wpIds 范围内,越界保护)→ `dispatch`(`targetWp` 为 goal 范围内首个 pending,`strategy='full_restart'`)
315
- 4. 全部被阻塞 → `noop`(持续 noop 由发散/上限兜底)
316
-
317
- > **retry vs resplit 分流对齐**(修复偏差1 + engine/运行时落差):engine `_think` 的真实数据流是 `wp.failed.length > 0` 命中 retry、`failed` 空但 `lastChecklist.passed===false` 命中 resplit。运行时 Claude 复现时严格按此优先级——先看 `failed`(来自 failedItems 聚合),再看 `lastChecklist.passed`,二者顺序不可换,否则会像旧版 engine 那样把真实 retry 误判成 resplit。
318
-
319
- #### Step 3c: Reflect 规则(复现 `reflection-evaluator`)
320
- - `proximity = 1 - (failed / total)`(来自上轮 CheckResult.summary;钳到 [0,1]);无 checklist 时降级按 WP 完成度 `completed/total`
321
- - `converged`:本轮 proximity 严格 > 上一轮
322
- - `divergenceStreak`:从 history 末尾数连续多少轮 proximity 不增(含回退)
323
- - `diverged`:`divergenceStreak >= divergence_threshold`(默认 3);已达成态(proximity≥goal 且 allPassed)不算发散
324
- - `failingDrivers`:由 `CheckResult.failedItems` 归一化产出,每项结构 `{wpId, category, item, reason}`(`reflection-evaluator` 辅助函数聚合,WP-176-1)
325
-
326
- > **`failingDrivers` refine 通道(完整流转,修复偏差2)**——engine 路径与运行时复现必须打通同一条链路:
327
- > 1. **产出**:Reflect 把 `lastChecklist.failedItems` 归一化为 `failingDrivers`(写入 `EvalResult.failingDrivers`)。
328
- > 2. **回填 state**(engine `reflect` 阶段的 state 回填):`state.failingDrivers = evalResult.failingDrivers || []`、`state.divergenceStreak = evalResult.divergenceStreak`。运行时 Claude 等效地把它记到本轮 PROGRESS.md / state 记录里,供下轮读取。
329
- > 3. **下轮 Think 消费**(Step 3b):retry decision 携带 `decision.failingDrivers`(优先 `state.failingDrivers`,回退 `state.lastEval.failingDrivers`)。
330
- > 4. **进入 Step 4.2**:把 `decision.failingDrivers` 映射进 `dispatchTarget.failingDrivers`。
331
- > 5. **dispatcher → 重做 Teamee**(WP-176-6):dispatcher restart 创建新 Teamee 时把 `failingDrivers` 注入 prompt,Teamee 据此优先修复这些失败项。
332
- >
333
- > 缺第 2 步(回填)或第 4 步(进 dispatcher 参数)都会让链路断裂——这正是偏差1/偏差2 的根因:数据算出来了但没流到重做者手里。
334
-
335
- #### Step 3d: Decide 规则(镜像 engine `_decide`:熔断 > 发散 > 达成 > 上限 > 继续)
336
- 优先级 **熔断 > 发散 > 达成 > 上限 > 继续**(「达成」上提到「上限」之前——修复末轮 `iteration==max_iterations` 时 proximity 已达标却被抢判 `timeout` 的 bug:末轮达标应判 `achieved`,未达标才判 `timeout` 兜底):
337
- 1. **熔断**:watchdog/守护异常(terminated / 持续 degraded)→ `circuit_broken`(运行时若 dispatcher 监控报告守护异常即触发)
338
- 2. **发散**:`divergenceStreak >= divergence_threshold` → `diverged`
339
- 3. **达成**:`allPassed && proximity >= proximity_goal && noPending && noFailed` → `achieved`
340
- 4. **上限**:`iteration >= max_iterations`、墙钟超 `max_wall_time_ms`、或单轮时长超 `max_round_time_ms` → `timeout`(兜底:本轮未达成才判 timeout)
341
- 5. 否则 → `continue`
342
-
343
- > **`noFailed` 现真实生效**(修复偏差1 + 落差,engine `_decide:1041-1042`):`noFailed = (!wp.failed || wp.failed.length===0) && (!evalResult.failingDrivers || evalResult.failingDrivers.length===0)`。即 WP 级 failed 列表与 CheckResult 级 failingDrivers 明细**任一非空**都判为"仍有失败项",不能进 `achieved`。运行时 Claude 复现时须同时检查这两个来源,不可只看 `wp.failed`。
227
+ ### Step 2.5: 路径选择(会话内镜像 loop 默认;driver 子进程显式 opt-in)🔴
228
+
229
+ **默认路径:会话内镜像自轮询(本会话直接跑)**——Read 本 skill 目录的 `mirror-rules.md`,按其规则框
230
+ 在当前会话内自轮询(Observe→Think→Act→Reflect→Decide,Act 委托 `skill-agent-dispatcher` 多 agent)。
231
+
232
+ > **默认翻转依据(v0.4.1,现场实证 nest 项目 loop-20261109)**:driver 路径的 executor 单轮默认
233
+ > 15min 硬超时对大体量 WP 是结构性缺陷——健康机器上 21 checklist 项的单轮也跑不完;内存紧张机器上
234
+ > SDK 子进程 15min 零字节产出被掐死,full_restart 每轮从干净 main 重来。会话内路径由本会话 Claude
235
+ > 驱动 dispatcher 多 agent 执行,**无单轮硬超时掐死问题**。镜像判定一致性由
236
+ > `test-agentic-loop-skill-mirror.js` CI 锁定。
237
+
238
+ **仅当用户明确要求「起 driver / 后台挂机跑 / `doukui loop`」时**,才走 driver 子进程路径:
239
+
240
+ 1. 先探测 `doukui --version`(或 `node <doukui包根>/bin/doukui.js --version`);探测失败几乎总是
241
+ **provider settings 未配置**(doukui skill 与 CLI 同包分发),向用户输出修复指引,不静默换路径:
242
+ 「driver 需要 provider settings 才能启动。请把 provider 配置 JSON 路径经 `--settings=<路径>` 传入
243
+ (如 `~/.claude/settings-glm.json`),或让 Claude 侧确认配置后重试。」
244
+ 2. 用 Bash 后台启动:`doukui loop <plan 路径> --executor=sdk --loop-id=<本 loopId> [--settings=<provider 配置>] [--round-timeout-ms=<N>] &`
245
+ —— 决策由 **JS engine 真跑**(Observe→Think→Reflect→Decide 全在 driver 进程内),本会话只做监控,
246
+ **不复现任何判定规则**。大体量 WP 记得调大单轮超时(`--round-timeout-ms`,缺省 15min)。
247
+ 3. 监控协议(每 30~60s 轮询一次,用 Bash `tail`):
248
+ - `.doukui/loop-{loopId}/trace.jsonl` 尾部 1 行 = 最新轮次的五段计时 + verdict + token
249
+ - `PROGRESS.md` = WP 完成标记
250
+ - 终态:driver 退出(`wait` 或检查进程)后读 stdout 尾部的「Agentic Loop 终止报告」呈现给用户;含 `♻ WP-S1 自救` 行则说明自救链已自动介入
251
+ 4. 会话在 loop 运行期间**只读不写**仓库文件(driver 子进程持有执行权,并行写会冲突)
252
+
253
+ > **镜像路径核心速查**(默认路径,详情在 mirror-rules.md):
254
+ > - **Think 优先级**:失败项重试(retry)> 待执行调度(dispatch)> 被阻塞 noop;`failed` 由 `lastChecklist.failedItems` 聚合 wpId 得到
255
+ > - **Reflect**:`proximity = 1 - (failed/total)`;连续 `divergence_threshold` 轮不增 → diverged
256
+ > - **Decide 优先级**:熔断 > 发散 > 达成 > 上限 > 继续(末轮达标判 achieved 不判 timeout)
344
257
 
345
258
  ### Step 4: Act 集成(🔴 委托 dispatcher implicit session team 多 agent,loop 不写代码)
346
259
 
@@ -391,7 +304,7 @@ dispatchTarget = {
391
304
  触发 `skill-agent-dispatcher` 执行 `dispatchTarget.wpId`(单个 WP)。dispatcher 内部完成全部多 agent 编排(**loop 不自己 spawn,也不自己写代码**):
392
305
 
393
306
  ```
394
- # dispatcher 流程(skill-agent-dispatcher/skill.md:181-302):
307
+ # dispatcher 流程(见 skill-agent-dispatcher 的 Step-by-Step Implementation 章节):
395
308
  1. 初始化批次标签 team_name="loop-{loopId}-{wpId}-{rand}"(Lead 内部逻辑标识,非 harness 团队名;harness 自动分配 implicit session team,无需 TeamCreate)
396
309
  2. TaskCreate(WP, description 含 WP 文档路径) + 设置 blockedBy 依赖
397
310
  3. 角色匹配(roles-reference.md:关键词/任务类型/模块标签加权)→ 预计算角色与记忆
@@ -405,7 +318,7 @@ dispatchTarget = {
405
318
  6. 批末:当前 session implicit team 随 session 自动清理;历史残留的显式/UUID 团队目录可用 `node bin/doukui.js team-cleanup <team>` 清理(CLI 直接走 fs.rmSync,不调 TeamDelete)
406
319
  ```
407
320
 
408
- > **关键不变量**(dispatcher §1262):每个 WP 由一个专用 Teamee 执行,绝不共享;完成即销毁;必须 `general-purpose`。loop 仅产出决策并把决策递给 dispatcher,**spawn Teamee 与写代码全归 dispatcher 内部的 Teamee**。
321
+ > **关键不变量**(见 dispatcher 的 Important 章节):每个 WP 由一个专用 Teamee 执行,绝不共享;完成即销毁;必须 `general-purpose`。loop 仅产出决策并把决策递给 dispatcher,**spawn Teamee 与写代码全归 dispatcher 内部的 Teamee**。
409
322
 
410
323
  #### 4.4 执行后调用 skill-checklist 重验,解析机器可读结果
411
324
  ```
@@ -416,7 +329,7 @@ dispatchTarget = {
416
329
  checklistResult = parseChecklistMachineReadable(dispatchTarget.wpId)
417
330
  ```
418
331
 
419
- > retry/resplit 时,通过 dispatcher 的 daemon-actions 通道下发 `restart`(带 strategy)或重新调度(`skill-agent-dispatcher/skill.md:635-740`),不越界 P0。
332
+ > retry/resplit 时,通过 dispatcher 的 daemon-actions 通道下发 `restart`(带 strategy)或重新调度(见 dispatcher 的 Step 6.5 Phase D.1 守护指令段),不越界 P0。
420
333
 
421
334
  #### 4.5 把 checklistResult 交给 Reflect(Step 3c 消费)
422
335
  将 `checklistResult` 作为本轮 `lastChecklist`,Reflect 据此算 proximity/failingDrivers。
@@ -535,45 +448,6 @@ loop 全程用 `skill-progress-tracker`(PROGRESS.md)+ task.md 记录,对
535
448
 
536
449
  ---
537
450
 
538
- ## Loop 主循环完整指令(执行者照做)
539
-
540
- ```
541
- # ============ Agentic Loop 主流程(半自主 · 多 agent)============
542
-
543
- # ---- Step 0: P0 规划(Plan 模式内,不可跳过)----
544
- # 触发即进 Plan 模式 → 优先读 .claude/plan.md(plan-reader 拆为 WP 集合);无计划则回退 task-creator/split-work-package
545
- # 产出 goal.wpIds + 各 WP checklist + 依赖图;不因 WP 数量退化,仅解析不出 WP / 循环依赖才提示用户提供计划
546
-
547
- # ---- Step 1: P1 确认 ----
548
- # skill-human-checkpoint 确认 goal / 上限 / 安全边界
549
-
550
- # ---- Step 2: 初始化 loop 记录 ----
551
- # 生成 loopId,写入 PROGRESS.md(goal/上限/iteration=0/history=[])
552
-
553
- # ---- Step 3: while 主循环(Claude 按规则迭代)----
554
- finalVerdict = null
555
- for rounds in 0..50: # 外层保险
556
- iteration += 1
557
- snapshot = observe() # Step 3a:读 PROGRESS.md/task.md
558
- decision = think(snapshot) # Step 3b:复现 engine _think(retry>dispatch>noop)
559
- checklistResult = act(decision) # Step 4:🔴 委托 dispatcher implicit session team 多 agent 执行
560
- evalResult = reflect(snapshot, checklistResult) # Step 3c:复现 evaluator(proximity/发散)
561
- verdict = decide(evalResult, snapshot) # Step 3d:复现 engine _decide(熔断>发散>达成>上限>继续)
562
- record(iteration, verdict, evalResult.proximity) # progress-tracker 写 history
563
- if verdict == 'continue': continue
564
- finalVerdict = verdict
565
- break
566
-
567
- # ---- Step 5: verdict 分流 ----
568
- if finalVerdict == 'achieved':
569
- runCompletionReport(loopId) # → P4
570
- else:
571
- outputTerminalReport(loopId, finalVerdict) # timeout/diverged/circuit_broken → 输出终止报告(不再回 P1)
572
- # =====================================================
573
- ```
574
-
575
- ---
576
-
577
451
  ## Important
578
452
 
579
453
  1. **入口必先规划** — `plan_mode_required: true`,触发即进 Plan 模式,Step 0 用 task-creator/split-work-package 拆 WP。没有 `goal.wpIds`,loop 不启动。禁止跳过规划直接写代码。
@@ -85,31 +85,20 @@ If you were dispatched as a subagent to execute a specific task, skip this skill
85
85
  | 包含"只写文档"、"不要执行"、"不具体执行"、"不要直接执行" | **快速模式** | 只定义任务,不分析代码 |
86
86
  | 无上述关键词 | **深度模式** | 可自由分析代码、评估复杂度 |
87
87
 
88
- ### 快速模式(用户明确说"不要执行"时)
88
+ ### 快速模式(用户明确说"不要执行"时)——红线,触发即适用
89
89
 
90
- 在 Plan 模式中,你只能:
91
- - ✅ 确定工作包编号
92
- - ✅ 写任务标题和目标(1-2句话)
93
- - ✅ 写子任务列表(可选)
94
- - ✅ 写验收标准(可选)
90
+ Plan 模式中你**禁止**:读取代码文件分析实现 / 检查代码是否存在 / 运行任何代码审计 /
91
+ 做任何"执行阶段"才该做的工作。只确定编号、写标题目标(1-2 句)、可选子任务与验收标准。
92
+ **只定义"做什么",不分析"怎么做"或"是否已做"。**
95
93
 
96
- 在 Plan 模式中,你**禁止**:
97
- - ❌ 读取代码文件分析实现
98
- - ❌ 检查代码是否存在
99
- - ❌ 运行任何代码审计
100
- - ❌ 做任何"执行阶段"才该做的工作
94
+ ### 深度模式细则(📖 共享参考,按需 Read)
101
95
 
102
- **规则**: 快速模式下,Plan 阶段只定义"做什么",不分析"怎么做"或"是否已做"
96
+ 深度模式下的自由度清单与上下文预算纪律(预读估算/分块读取/语义边界/上下文缺口表格),
97
+ 三 skill 共用同一份规范:
103
98
 
104
- ### 深度模式(默认)
105
-
106
- Plan 阶段可以自由进行:
107
- - ✅ 读取代码分析依赖
108
- - ✅ 评估任务复杂度
109
- - ✅ 检查现有实现
110
- - ✅ 设计拆分方案
111
-
112
- ---
99
+ ```
100
+ Read("plugins/core/skill-task-creator/context-budget-reference.md")
101
+ ```
113
102
 
114
103
  ## 🆕 智能批量拆分系统
115
104
 
@@ -197,53 +186,13 @@ graph TB
197
186
 
198
187
  ---
199
188
 
200
- ## 上下文窗口管理
201
-
202
- 仅在深度模式下生效。快速模式不读取文件,无需分块。
203
-
204
- ### 预读估算协议
205
-
206
- 1. 查看文件顶部的 `<!-- CONTEXT-CONFIG -->` 获取限制参数
207
- 2. 先用 Glob 发现文件,用 Bash `wc -l` 估算行数
208
- 3. 估算公式: 每行代码 ≈ 10 tokens,每行文本 ≈ 5 tokens
209
- 4. 可用预算 = max_tokens - safety_margin
210
-
211
- ### 读取策略决策树
212
-
213
- | 文件估算行数 | 策略 |
214
- |-------------|------|
215
- | ≤ thresholds.small (200行) | 直接用 Read 工具读取整个文件 |
216
- | thresholds.small ~ thresholds.medium (200-800行) | 分块读取: Read(offset, limit=chunk_lines) |
217
- | > thresholds.medium (800行) | Grep 扫描关键模式 → 定位行范围 → Read 目标段 |
218
- | 多文件合计超预算 | 排序优先级 → 读高优 → 低优用 Grep |
219
-
220
- ### 分块读取协议
221
-
222
- 1. **首块**(1 ~ chunk_lines): 建立"结构地图"(类/函数/节标题位置)
223
- 2. **后续块**: 根据结构地图判断是否包含相关内容
224
- 3. **提前终止**: 已获得足够信息时停止读取,不读完整文件
225
- 4. **跨块引用**: 记录依赖但不回读
226
-
227
- ### 语义边界规则(优先级从高到低)
228
-
229
- 1. 函数/方法边界 - 不在函数体中间断开
230
- 2. 类边界 - 不在类定义中间断开
231
- 3. Markdown 节标题 - 在 `##`/`###` 处断开
232
- 4. 代码块边界 - 在 `{ }` 之间断开
233
- 5. 行边界 - 最后手段
234
-
235
- ### 部分分析的合并
189
+ ## 上下文窗口管理(📖 共享参考,按需 Read)
236
190
 
237
- 置信度标注:
238
- - **[HIGH]** 基于完整直接读取
239
- - **[MEDIUM]** 基于部分读取 + 结构推断
240
- - **[LOW]** 仅基于 Grep 结果
191
+ 深度模式下的预读估算 / 读取策略决策树 / 分块读取 / 语义边界 / 部分分析合并 / 上下文缺口表格,
192
+ 三 skill(task-creator / batch-task-creator / split-work-package)共用同一份规范:
241
193
 
242
- 在 Plan 中包含"上下文缺口"子节:
243
194
  ```
244
- ## 上下文缺口
245
- | 文件 | 未读部分 | 影响 | 建议 |
246
- |------|----------|------|------|
195
+ Read("plugins/core/skill-task-creator/context-budget-reference.md")
247
196
  ```
248
197
 
249
198
  ### 批量创建专属规则
@@ -74,31 +74,20 @@ If you were dispatched as a subagent to execute a specific task, skip this skill
74
74
  | 包含"只写文档"、"不要执行"、"不具体执行"、"不要直接执行" | **快速模式** | 只定义任务,不分析代码 |
75
75
  | 无上述关键词 | **深度模式** | 可自由分析代码、评估复杂度 |
76
76
 
77
- ### 快速模式(用户明确说"不要执行"时)
77
+ ### 快速模式(用户明确说"不要执行"时)——红线,触发即适用
78
78
 
79
- 在 Plan 模式中,你只能:
80
- - ✅ 确定工作包编号
81
- - ✅ 写任务标题和目标(1-2句话)
82
- - ✅ 写子任务列表(可选)
83
- - ✅ 写验收标准(可选)
79
+ Plan 模式中你**禁止**:读取代码文件分析实现 / 检查代码是否存在 / 运行任何代码审计 /
80
+ 做任何"执行阶段"才该做的工作。只确定编号、写标题目标(1-2 句)、可选子任务与验收标准。
81
+ **只定义"做什么",不分析"怎么做"或"是否已做"。**
84
82
 
85
- 在 Plan 模式中,你**禁止**:
86
- - ❌ 读取代码文件分析实现
87
- - ❌ 检查代码是否存在
88
- - ❌ 运行任何代码审计
89
- - ❌ 做任何"执行阶段"才该做的工作
83
+ ### 深度模式细则(📖 共享参考,按需 Read)
90
84
 
91
- **规则**: 快速模式下,Plan 阶段只定义"做什么",不分析"怎么做"或"是否已做"
85
+ 深度模式下的自由度清单与上下文预算纪律(预读估算/分块读取/语义边界/上下文缺口表格),
86
+ 三 skill 共用同一份规范:
92
87
 
93
- ### 深度模式(默认)
94
-
95
- Plan 阶段可以自由进行:
96
- - ✅ 读取代码分析依赖
97
- - ✅ 评估任务复杂度
98
- - ✅ 检查现有实现
99
- - ✅ 设计拆分方案
100
-
101
- ---
88
+ ```
89
+ Read("plugins/core/skill-task-creator/context-budget-reference.md")
90
+ ```
102
91
 
103
92
  ## Forbidden Thoughts
104
93
 
@@ -116,53 +105,13 @@ Plan 阶段可以自由进行:
116
105
 
117
106
  ---
118
107
 
119
- ## 上下文窗口管理
120
-
121
- 仅在深度模式下生效。快速模式不读取文件,无需分块。
122
-
123
- ### 预读估算协议
124
-
125
- 1. 查看文件顶部的 `<!-- CONTEXT-CONFIG -->` 获取限制参数
126
- 2. 先用 Glob 发现文件,用 Bash `wc -l` 估算行数
127
- 3. 估算公式: 每行代码 ≈ 10 tokens,每行文本 ≈ 5 tokens
128
- 4. 可用预算 = max_tokens - safety_margin
129
-
130
- ### 读取策略决策树
131
-
132
- | 文件估算行数 | 策略 |
133
- |-------------|------|
134
- | ≤ thresholds.small (200行) | 直接用 Read 工具读取整个文件 |
135
- | thresholds.small ~ thresholds.medium (200-800行) | 分块读取: Read(offset, limit=chunk_lines) |
136
- | > thresholds.medium (800行) | Grep 扫描关键模式 → 定位行范围 → Read 目标段 |
137
- | 多文件合计超预算 | 排序优先级 → 读高优 → 低优用 Grep |
138
-
139
- ### 分块读取协议
140
-
141
- 1. **首块**(1 ~ chunk_lines): 建立"结构地图"(类/函数/节标题位置)
142
- 2. **后续块**: 根据结构地图判断是否包含相关内容
143
- 3. **提前终止**: 已获得足够信息时停止读取,不读完整文件
144
- 4. **跨块引用**: 记录依赖但不回读
145
-
146
- ### 语义边界规则(优先级从高到低)
147
-
148
- 1. 函数/方法边界 - 不在函数体中间断开
149
- 2. 类边界 - 不在类定义中间断开
150
- 3. Markdown 节标题 - 在 `##`/`###` 处断开
151
- 4. 代码块边界 - 在 `{ }` 之间断开
152
- 5. 行边界 - 最后手段
153
-
154
- ### 部分分析的合并
108
+ ## 上下文窗口管理(📖 共享参考,按需 Read)
155
109
 
156
- 置信度标注:
157
- - **[HIGH]** 基于完整直接读取
158
- - **[MEDIUM]** 基于部分读取 + 结构推断
159
- - **[LOW]** 仅基于 Grep 结果
110
+ 深度模式下的预读估算 / 读取策略决策树 / 分块读取 / 语义边界 / 部分分析合并 / 上下文缺口表格,
111
+ 三 skill(task-creator / batch-task-creator / split-work-package)共用同一份规范:
160
112
 
161
- 在 Plan 中包含"上下文缺口"子节:
162
113
  ```
163
- ## 上下文缺口
164
- | 文件 | 未读部分 | 影响 | 建议 |
165
- |------|----------|------|------|
114
+ Read("plugins/core/skill-task-creator/context-budget-reference.md")
166
115
  ```
167
116
 
168
117
  ### 工作包拆分专属规则