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
@@ -1,91 +1,132 @@
1
1
  # Dispatcher Recovery Reference(异常处置与恢复细则)
2
2
 
3
- > 本文件是 skill-agent-dispatcher 的按需参考(渐进式加载约定,P2a 二轮瘦身外移)。
4
- > 检测条件与不变量规则本体仍在 SKILL.md(Phase D2-idle 顶部注释块 + 文末 HARD-GATE);以下展开仅在自愈/恢复场景触发时按 📖指针 Read。
5
- > 来源章节:SKILL.md Step 6.5 Phase D2-idle-heal 自愈流程、上下文恢复协议。
3
+ > 本文件是 skill-agent-dispatcher 的按需参考(渐进式加载约定)。规则本体仍在 SKILL.md(Phase D2-idle 注释块 + idle 自愈关键不变量 + Step 8 重派发 + 文末 HARD-GATE);以下仅在自愈 / 重派发 / 恢复场景触发时按 📖指针 Read。
4
+ > 状态载体统一为 Lead 循环内变量 `idle_state = {task_id: {started_at, idle_nudge_sent, retry_count}}`(与 `teamee_map` 同侧),事件记入 PROGRESS.md 该轮 history。
6
5
 
7
6
  ## Phase D2-idle-heal 自愈流程
8
7
 
9
- 触发条件(见 SKILL.md Phase D2-idle 检测段):task_stalled 且 (now() - assigned_at) >= idle_threshold。以下为命中后的完整展开(缩进原样保留):
8
+ 触发条件(SKILL.md Phase D2-idle 检测段):task_stalled 且 `(now() - idle_state[task_id].started_at) >= idle_threshold`。命中后展开(`st` 即 `idle_state[task_id]`):
10
9
 
11
10
  ```
12
11
  # 输出: "⚠️ idle 检测: Teamee {teamee_name} (task {task_id}) 停滞,进入自愈流程"
13
- # ---- Phase D2-idle-heal: 自愈流程 ----
14
- # Step 1: 首轮仅催促一次(去重位),给满一个 idle_threshold 窗口,本轮不重 spawn
15
- if not idle_nudge_sent:
16
- SendMessage(
17
- to=teamee_name,
18
- summary="idle 检测催促,请立即执行任务",
19
- message=f"检测到任务 {task_id} 长时间未推进。请立即开始执行 WP 文档中的任务,完成后用 SendMessage 向 team-lead 发送完成报告。"
20
- )
21
- update_task_file(task_id, set_idle_nudge=True)
12
+ # ---- Step 1: 首轮仅催促一次(去重位),给满一个 idle_threshold 窗口,本轮不重 spawn ----
13
+ if not st["idle_nudge_sent"]:
14
+ SendMessage(to=teamee_name, summary="idle 检测催促,请立即执行任务",
15
+ message=f"检测到任务 {task_id} 长时间未推进。请立即开始执行 WP 文档中的任务,完成后用 SendMessage 向 team-lead 发送完成报告。")
16
+ st["idle_nudge_sent"] = True
17
+ record_progress("nudge", task_id) # 事件写入 PROGRESS.md
22
18
  continue # 下一轮若仍 idle 且已催促,才进 Step 2-4
23
19
  # 输出: "idle 自愈: task {task_id} 已催促过仍无推进,进 Step 2-4 重 spawn"
24
- # Step 2: 验证 spawn 参数(定位根因,避免原样重 spawn 仍 idle)
20
+ # ---- Step 2: 验证 spawn 参数(定位根因,避免原样重 spawn 仍 idle)----
25
21
  assignment = wp_assignments[task_id]
26
22
  spawn_params_ok = (
27
- assignment.subagent_type == resolve_subagent_type(assignment.role_id) # 双分支放行: roleId 生成物或 general-purpose 回退
28
- and assignment.team_name == team_name
23
+ resolve_subagent_type(assignment.role_id) in (assignment.role_id, "general-purpose") # 双分支放行
29
24
  and task_id in assignment.prompt
30
25
  and assignment.wp_doc_path in assignment.prompt
31
26
  and "SendMessage" in assignment.prompt # prompt 须要求完成报告用 SendMessage
32
27
  )
33
28
  if not spawn_params_ok:
34
- # 输出: "spawn 参数异常 (subagent_type/批次标签 team_name/prompt 完整性),将在重 spawn 时修正"
29
+ # 输出: "spawn 参数异常 (subagent_type/prompt 完整性),将在重 spawn 时修正"
35
30
  pass
36
- # Step 3: 仍不执行 → 逻辑销毁旧 Teamee(无协议帧)
31
+ # ---- Step 3: 仍不执行 → 逻辑销毁旧 Teamee(无协议帧)----
37
32
  markTeameeDestroyed(teamee_map, task_id)
38
- # Step 4: 检查 retry_count < max_retries → 重新 spawn(复用 Phase D.1 restart 指令段的重 spawn 逻辑)
39
- # 复用 idle 检测顶部已读取的 task_file(read_task_file 结果),避免重复 IO
40
- retry_count = task_file.get("retry_count", 0)
41
- max_retries = task_file.get("max_retries", 3)
42
- if retry_count < max_retries:
43
- # 重新 spawn 专用 Teamee(递增 retry_count),复用 restart 守护进程指令段的重 spawn 逻辑
33
+ # ---- Step 4: retry_count < max_retries → 重新 spawn ----
34
+ max_retries = 3
35
+ if st["retry_count"] < max_retries:
44
36
  new_teamee_name = f"{assignment.role_id}-t{task_id}-idle-retry"
45
- prompt = build_refine_prompt(
46
- teamee_name=new_teamee_name,
47
- task_id=task_id,
48
- role_prompt=assignment.role_prompt,
49
- memories=assignment.memories,
50
- wp_doc_path=assignment.wp_doc_path,
51
- failing_drivers=[] # idle 重 spawn 非失败项修复,failing_drivers 为空
52
- )
53
- Agent( # 自动加入 implicit session team,无需 team_name 参数
54
- name=new_teamee_name,
55
- subagent_type=resolve_subagent_type(assignment.role_id), # 双分支路由(见 Step 6 规则)
56
- prompt=prompt
57
- )
37
+ prompt = build_refine_prompt( # idle 重 spawn 非失败项修复,failing_drivers 为空
38
+ teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
39
+ memories=assignment.memories, wp_doc_path=assignment.wp_doc_path, failing_drivers=[])
40
+ Agent(name=new_teamee_name, subagent_type=resolve_subagent_type(assignment.role_id), prompt=prompt) # 双分支路由(见 Step 6 规则)
58
41
  teamee_map[task_id] = new_teamee_name
59
- # 三合一调用(缺任一复活死亡螺旋):递增 retry + 刷新 started_at + 重置催促去重位
60
- update_task_file(
61
- task_id,
62
- increment_retry=True,
63
- reset_started_at=True, # F4
64
- set_idle_nudge=False # F3
65
- )
66
- # 输出: "idle 自愈: task {task_id} 重新 spawn 为 {new_teamee_name} (retry {retry_count+1}/{max_retries}),已刷新 started_at + 重置催促去重位"
42
+ # 三合一赋值(缺任一复活死亡螺旋):递增 retry + 刷新 started_at + 重置催促去重位
43
+ st["retry_count"] += 1; st["started_at"] = now(); st["idle_nudge_sent"] = False
44
+ record_progress("idle-respawn", task_id, st["retry_count"])
45
+ # 输出: "idle 自愈: task {task_id} 重新 spawn 为 {new_teamee_name} (retry {st['retry_count']}/{max_retries})"
67
46
  else:
68
- # Step 5: 超限 → 熔断,绝不 Lead 接手,转 Step 7 清理
47
+ # ---- Step 5: 超限 → 熔断,绝不 Lead 接手,转 Step 7 清理 ----
69
48
  TaskUpdate(taskId=task_id, status="failed")
70
- update_task_file(task_id, status="failed")
71
- # 输出: "🔴 idle 自愈超限: task {task_id} 重试 {retry_count}/{max_retries} 仍 idle,熔断标记 failed,绝不 Lead 接手,转 Step 7 清理"
49
+ idle_state.pop(task_id, None)
50
+ record_progress("idle-circuit-broken", task_id)
51
+ # 输出: "🔴 idle 自愈超限: task {task_id} 重试 {st['retry_count']}/{max_retries} 仍 idle,熔断标记 failed,绝不 Lead 接手,转 Step 7 清理"
72
52
  ```
73
53
 
74
- ## 上下文恢复协议
54
+ > 上下文压缩后 `idle_state` 清零,恢复时按 `{"started_at": start_time, "idle_nudge_sent": False, "retry_count": 0}` 兜底——最坏后果是多催促一次。
55
+
56
+ ## 重派发 restart 规格(SKILL.md Step 8 的展开)
57
+
58
+ `failingDrivers` 每项 `{wpId, category, item, reason}`(来源 loop Step 4.2,Reflect 从 `lastChecklist.failedItems` 归一化);仅 retry/resplit 有值,dispatch 首次执行为空。
59
+
60
+ ```
61
+ # 1. 定位目标 Task:按 dispatchTarget.wpId 匹配 TaskList 中 subject "WP-XXX: ..."(或 wp_assignments 的 wp_id)
62
+ # 2. 逻辑销毁旧 Teamee(无协议帧):markTeameeDestroyed(teamee_map, task_id)
63
+ # 3. 命名与路由
64
+ assignment = wp_assignments[task_id]
65
+ new_teamee_name = f"{assignment.role_id}-t{task_id}-retry"
66
+ # 4. prompt:两种策略都注入 failing_drivers(refine 通道),让承接重做的 Teamee 优先修这些失败项
67
+ context = dispatchTarget.get("context", {})
68
+ if dispatchTarget["strategy"] == "checkpoint_resume":
69
+ prompt = build_resume_prompt( # 复杂任务:注入已完成文件上下文 + 失败项重点修复段
70
+ teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
71
+ completed_files=context.get("completedFiles", []), remaining=context.get("remaining", []),
72
+ failing_drivers=dispatchTarget["failingDrivers"])
73
+ else: # full_restart / resplit:从头执行,仍注入失败项重点修复段(区分 retry 与首次 dispatch)
74
+ prompt = build_refine_prompt(
75
+ teamee_name=new_teamee_name, task_id=task_id, role_prompt=assignment.role_prompt,
76
+ memories=assignment.memories, wp_doc_path=assignment.wp_doc_path,
77
+ failing_drivers=dispatchTarget["failingDrivers"])
78
+ # 5. 重 spawn + 三合一 idle 赋值
79
+ Agent(name=new_teamee_name, subagent_type=resolve_subagent_type(assignment.role_id), prompt=prompt)
80
+ TaskUpdate(taskId=task_id, owner=new_teamee_name)
81
+ teamee_map[task_id] = new_teamee_name
82
+ st = idle_state.setdefault(task_id, {"retry_count": 0})
83
+ idle_state[task_id] = {"started_at": now(), "idle_nudge_sent": False, "retry_count": st["retry_count"] + 1}
84
+ record_progress("redispatch", task_id, dispatchTarget["mode"], dispatchTarget["strategy"], len(dispatchTarget["failingDrivers"]))
85
+ # 6. 回 Step 6.5 监控循环
86
+ ```
75
87
 
76
- **上下文恢复协议**:
88
+ **resplit 模式补充**:`strategy='resplit'` 时把当前失败 WP 拆为子 WP(TaskCreate 子任务 + blockedBy,按 monitoring-reference.md「拆分工作包执行支持」调度),旧 Teamee 同样逻辑销毁;只拆当前失败 WP,不越界 P0。
77
89
 
78
- 如果监控循环因上下文压缩(auto-compact)而中断,按以下步骤恢复:
90
+ ### build_resume_prompt / build_refine_prompt(重点修复段)
79
91
 
92
+ `failing_drivers` 非空时输出「重点修复」段,为空不输出(退化为标准 prompt,向后兼容):
93
+
94
+ ```
95
+ def render_refine_section(failing_drivers, mode_label):
96
+ refine_lines = "\n".join(f"- [{d.get('category','?')}] {d.get('item','?')} — {d.get('reason','?')}(WP: {d.get('wpId','?')})" for d in failing_drivers)
97
+ return f'''
98
+ ## 🔴 本轮重点修复的失败项(来自上轮 checklist,优先处理)
99
+ 你是在 {mode_label} 模式下重新执行任务。以下是你上轮 checklist 未通过的失败项明细。
100
+ **请优先、针对性地修复这些项**,而非盲目原样重做:
101
+ {refine_lines}
102
+ 逐条核对你修复了每一项的失败原因(reason)。只有它们通过,本轮才算有效改进(而非无效重做)。'''
103
+
104
+ def build_resume_prompt(teamee_name, task_id, role_prompt, completed_files, remaining, failing_drivers=None):
105
+ base = f'''你是 {teamee_name},是一名 {role_prompt}。
106
+ ## 任务重启 (Checkpoint Resume)
107
+ 你正在重新执行任务 #{task_id}。之前的执行已完成部分工作,你将从断点继续。
108
+ ### 已完成的文件
109
+ {chr(10).join(f"- {f}" for f in completed_files)}
110
+ ### 待完成的工作
111
+ {chr(10).join(f"- {r}" for r in remaining)}
112
+ 请阅读已完成文件的最新状态,然后继续执行剩余工作。不要重复已完成的工作,直接从断点继续。'''
113
+ return base + (render_refine_section(failing_drivers, "checkpoint_resume") if failing_drivers else "")
114
+
115
+ def build_refine_prompt(teamee_name, task_id, role_prompt, memories, wp_doc_path, failing_drivers=None):
116
+ base = build_single_task_prompt(teamee_name, task_id, role_prompt, memories, wp_doc_path)
117
+ return base + (render_refine_section(failing_drivers, "retry(full_restart)") if failing_drivers else "")
80
118
  ```
81
- 1. Read 状态文件(多窗口模式读 windows/{window_id}/state.json)
82
- - 不存在 → 首次运行或已清理,从头开始
83
- - status == "completed" → 执行已完成,无需恢复
84
- - status == "monitoring" → 进入恢复流程
85
119
 
86
- 2. restore_from_state(state) # 字段清单见监控循环顶部的统一恢复通道定义
120
+ ## 上下文恢复协议
87
121
 
88
- 3. 验证恢复有效性: teamee_map 中的 teamee 若已不存在,从映射表移除
122
+ 监控循环因上下文压缩(auto-compact)中断后恢复(dispatcher 不写自有 state 文件,PROGRESS.md 是唯一持久层):
89
123
 
90
- 4. 继续监控循环(从恢复的 loop_iteration + 1 开始)
124
+ ```
125
+ 1. Read PROGRESS.md 尾部最近 history(loop 记录 / spawn / 催促 / 重 spawn / 重派发事件)
126
+ - 无记录 → 首次运行,从头开始;已终止(completed/failed)→ 无需恢复
127
+ 2. TaskList() 取任务状态,重建 teamee_map:in_progress 且 owner 非空的 task → teamee_map[task.id] = owner
128
+ 3. 重建 idle_state:history 有最近 spawn/重 spawn 时间则以此为 started_at,
129
+ 否则按 {"started_at": start_time, "idle_nudge_sent": False, "retry_count": 0} 兜底(最坏后果 = 多催促一次)
130
+ 4. 校验有效性:teamee_map 中的 Teamee 已失联(SendMessage 无响应且超过 idle_threshold)→ 走 Phase D2-idle-heal
131
+ 5. 继续监控循环(loop_iteration 从恢复值 +1 开始)
91
132
  ```
@@ -139,7 +139,7 @@ for task in tasks:
139
139
 
140
140
  ## Teamee Prompt 模板
141
141
 
142
- 以下模板用于 `build_single_task_prompt()` 函数,在 Step 6 / Step 6.5 创建 Teamee 时使用。
142
+ 以下模板用于 `build_single_task_prompt()` 函数,在 Step 6 / Step 6.5 / Step 8(重派发)创建 Teamee 时使用。
143
143
 
144
144
  ```markdown
145
145
  # [角色名称] - 单一任务专用执行
@@ -184,36 +184,23 @@ TaskGet(taskId="{task_id}") — 验证 owner 是你、status 是 pending 或 in_
184
184
  ### 3. 完成任务
185
185
  TaskUpdate(taskId="{task_id}", status="completed")
186
186
 
187
- ### 4. 等待关闭 (🔴 必须响应)
187
+ ### 4. 完成报告 (🔴 必须执行)
188
188
 
189
- **完成任务后,不要查找其他任务!直接等待 Lead 的 shutdown_request。**
190
-
191
- 当收到 `shutdown_request` 消息时,**必须**发送响应:
189
+ TaskUpdate(completed) 后,用 SendMessage 向 Lead 发一条**纯文本**完成报告(含 summary),然后停止工作,等待 Lead 逻辑销毁:
192
190
 
193
191
  ```
194
192
  SendMessage(
195
193
  to="team-lead",
196
- summary="Shutdown approved, exiting",
197
- message={
198
- "type": "shutdown_response",
199
- "request_id": "{从 shutdown_request 中提取的 request_id}",
200
- "approve": true
201
- }
194
+ summary="Task {task_id} 完成,等待销毁",
195
+ message="任务 {task_id} 已完成。变更文件:...;验收标准:全部通过 / 未通过项:..."
202
196
  )
203
197
  ```
204
198
 
205
- 发送响应后,你的工作结束,可以退出。
206
-
207
- **⚠️ SendMessage 使用注意**:
208
- 所有 SendMessage 调用都必须提供 `summary` 参数:
209
- - 使用 object 类型 message:`summary="...", message={"type": "status_update", ...}`
210
- - 使用 string message:`summary="...", message="..."`
211
- - 禁止任何 SendMessage 调用不提供 summary
199
+ **⚠️ SendMessage 使用注意**: 只发纯文本 + summary;**禁止发送任何 protocol frame**(shutdown_request / shutdown_response / permission / mode / plan 的 JSON)——harness 会直接拦截报错。
212
200
 
213
201
  **⚠️ 禁止事项**:
214
202
  - 不要认领或执行其他任务(可以查看 TaskList 了解进度,但不可对其他任务执行 TaskUpdate)
215
- - 不要在完成后继续工作
216
- - 必须等待 Lead 的 shutdown_request,不要主动退出
203
+ - 不要在完成后继续工作,也不要主动查找新任务;完成报告发出后即等待 Lead 逻辑销毁
217
204
 
218
205
  ## 相关经验(从历史中学习)
219
206
 
@@ -244,10 +231,10 @@ SendMessage(
244
231
  ⚠️ 如果不执行状态同步,工作包将被视为未完成!
245
232
 
246
233
  ## 重要提醒
247
- - **你只处理一个任务** — 完成后等待 shutdown,不要查找其他任务
234
+ - **你只处理一个任务** — 完成报告后等待逻辑销毁,不要查找其他任务
248
235
  - 完成后必须执行测试验证
249
236
  - 如遇阻塞问题,在任务描述中说明阻塞原因
250
237
  - 不要跳过任何验收标准
251
238
  - 任务完成后立即更新状态为 completed,方便 Lead 检测并解锁依赖任务
252
- - 收到 shutdown_request 后立即响应,不要延迟
239
+ - 完成报告发出后不要再做任何事,Lead 会逻辑销毁你
253
240
  ```