doukui 0.8.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.
Files changed (62) 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 +64 -15
  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-checklist/skill.md +15 -141
  22. package/plugins/core/skill-completion-report/plugin.json +1 -1
  23. package/plugins/core/skill-doukui-plan/plugin.json +1 -1
  24. package/plugins/core/skill-doukui-plan/skill.md +22 -22
  25. package/plugins/core/skill-experience-logger/plugin.json +1 -1
  26. package/plugins/core/skill-human-checkpoint/skill.md +1 -0
  27. package/plugins/core/skill-split-work-package/plugin.json +1 -1
  28. package/plugins/core/skill-task-creator/plugin.json +1 -1
  29. package/plugins/core/skill-task-creator/skill.md +1 -139
  30. package/plugins/core/skill-workflow-orchestrator/plugin.json +1 -1
  31. package/plugins/plugin-registry.json +0 -36
  32. package/plugins/runtime/harness-build.js +5 -5
  33. package/plugins/runtime/plan-reader.js +21 -3
  34. package/plugins/runtime/resolve-plugin-path.js +2 -2
  35. package/plugins/contracts/capabilities.js +0 -268
  36. package/plugins/core/provider-memory-store/index.js +0 -510
  37. package/plugins/core/provider-memory-store/plugin.json +0 -9
  38. package/plugins/core/provider-state-store/index.js +0 -244
  39. package/plugins/core/provider-state-store/plugin.json +0 -9
  40. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +0 -32
  41. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +0 -676
  42. package/plugins/core/provider-watchdog/assets/watchdog.js +0 -754
  43. package/plugins/core/provider-watchdog/index.js +0 -151
  44. package/plugins/core/provider-watchdog/plugin.json +0 -13
  45. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +0 -249
  46. package/plugins/core/skill-watchdog-manager/plugin.json +0 -10
  47. package/plugins/core/skill-watchdog-manager/skill.md +0 -143
  48. package/plugins/core/validator-doc-sync/index.js +0 -248
  49. package/plugins/core/validator-doc-sync/plugin.json +0 -12
  50. package/plugins/core/validator-work-package/index.js +0 -300
  51. package/plugins/core/validator-work-package/plugin.json +0 -12
  52. package/plugins/runtime/audit-logger.js +0 -311
  53. package/plugins/runtime/build-cli.js +0 -89
  54. package/plugins/runtime/event-bus.js +0 -207
  55. package/plugins/runtime/hook-dispatcher.js +0 -315
  56. package/plugins/runtime/plugin-loader.js +0 -798
  57. package/plugins/runtime/plugin-trust.js +0 -182
  58. package/plugins/runtime/sandbox-context.js +0 -235
  59. package/plugins/runtime/sandbox-manager.js +0 -609
  60. package/plugins/runtime/sandbox-worker.js +0 -215
  61. package/plugins/runtime/text-tokenize.js +0 -24
  62. package/plugins/runtime/validator-pipeline.js +0 -475
@@ -1,151 +0,0 @@
1
- 'use strict';
2
-
3
- const ProviderPlugin = require('../../contracts/plugin-interface').ProviderPlugin;
4
-
5
- /**
6
- * Watchdog Provider Plugin
7
- *
8
- * Provides watchdog daemon status query API.
9
- * When enabled and built, deploys watchdog assets to .claude/watchdog/.
10
- */
11
- class WatchdogProvider extends ProviderPlugin {
12
- constructor() {
13
- super();
14
- this.name = 'provider-watchdog';
15
- this.version = '0.1.0';
16
- this.description = 'Watchdog Daemon Provider';
17
- this.provides = 'provider:watchdog';
18
- }
19
-
20
- async onActivate(context) {
21
- this._context = context;
22
- context.logger.info('WatchdogProvider activated');
23
- }
24
-
25
- async factory(context) {
26
- const fs = require('fs');
27
- const path = require('path');
28
-
29
- return {
30
- /**
31
- * 读取配置中的 heartbeat_dir,回退到默认值
32
- * @private
33
- * @returns {string}
34
- */
35
- _getHeartbeatDir: function () {
36
- const configPath = path.join('.claude-daemon', 'daemon-config.json');
37
- if (fs.existsSync(configPath)) {
38
- try {
39
- const cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
40
- return cfg.heartbeat_dir || '.claude-daemon';
41
- } catch (e) {
42
- // 解析失败,使用默认值
43
- }
44
- }
45
- return '.claude-daemon';
46
- },
47
-
48
- /**
49
- * 检查 watchdog 是否已部署到目标项目
50
- * @returns {boolean}
51
- */
52
- isDeployed: function () {
53
- const watchdogPath = path.join('.claude', 'watchdog', 'watchdog.js');
54
- return fs.existsSync(watchdogPath);
55
- },
56
-
57
- /**
58
- * 获取 watchdog 部署路径
59
- * @returns {string}
60
- */
61
- getDeployPath: function () {
62
- return path.join('.claude', 'watchdog');
63
- },
64
-
65
- /**
66
- * 获取守护进程状态文件路径
67
- * @returns {string}
68
- */
69
- getStatusFilePath: function () {
70
- return path.join(this._getHeartbeatDir(), 'daemon-status.json');
71
- },
72
-
73
- /**
74
- * 读取守护进程状态对象(原始 status.json),失败降级为 null。
75
- * 供 getHealth / isRunning 共用,避免重复解析。
76
- * @private
77
- * @returns {object|null}
78
- */
79
- _readStatus: function () {
80
- const statusFile = this.getStatusFilePath();
81
- if (!fs.existsSync(statusFile)) {
82
- return null;
83
- }
84
- try {
85
- return JSON.parse(fs.readFileSync(statusFile, 'utf8'));
86
- } catch (e) {
87
- return null;
88
- }
89
- },
90
-
91
- /**
92
- * 查询守护进程健康(design.md §6.3.2,WP-174-5)。
93
- *
94
- * 返回三态健康模型,供 loop-engine 熔断判定区分 degraded:
95
- * - 'healthy' : health 未终止,且心跳不过期
96
- * - 'degraded' : health 非终止但心跳过期(持续 degraded 触发熔断)
97
- * - 'terminated' : health === 'terminated',或状态文件缺失/损坏
98
- *
99
- * 同时保留 `running` 布尔(等价于旧的 isRunning 语义:health !== 'terminated'),
100
- * 便于只关心"是否完全挂掉"的调用方平滑迁移。
101
- *
102
- * @returns {{ state: 'healthy'|'degraded'|'terminated', running: boolean, health?: string, stale?: boolean, raw?: object }}
103
- */
104
- getHealth: function () {
105
- const STALE_THRESHOLD_MS = 120000; // 与 multi-window-coordinator 心跳过期阈值一致
106
- const status = this._readStatus();
107
- if (!status) {
108
- return { state: 'terminated', running: false };
109
- }
110
- const health = status.health || 'unknown';
111
- if (health === 'terminated') {
112
- return { state: 'terminated', running: false, health: health, raw: status };
113
- }
114
- // 非终止:检查心跳新鲜度以区分 healthy / degraded
115
- var stale = false;
116
- if (status.last_update || status.last_heartbeat || status.updated_at) {
117
- var ts = status.last_update || status.last_heartbeat || status.updated_at;
118
- var age = Date.now() - new Date(ts).getTime();
119
- if (!isNaN(age) && age > STALE_THRESHOLD_MS) {
120
- stale = true;
121
- }
122
- }
123
- return {
124
- state: stale ? 'degraded' : 'healthy',
125
- running: true,
126
- health: health,
127
- stale: stale,
128
- raw: status,
129
- };
130
- },
131
-
132
- /**
133
- * 检查守护进程是否正在运行(向后兼容)。
134
- *
135
- * 语义保持不变:health !== 'terminated'(即未完全挂掉即视为 running,
136
- * 不因心跳过期返回 false —— 否则会破坏现有只关心"完全终止"的调用方)。
137
- * 需要区分 healthy/degraded 的调用方应改用 getHealth()。
138
- * @returns {boolean}
139
- */
140
- isRunning: function () {
141
- const status = this._readStatus();
142
- if (!status) {
143
- return false;
144
- }
145
- return status.health !== 'terminated';
146
- }
147
- };
148
- }
149
- }
150
-
151
- module.exports = WatchdogProvider;
@@ -1,13 +0,0 @@
1
- {
2
- "name": "provider-watchdog",
3
- "version": "1.0.0",
4
- "type": "provider",
5
- "description": "Watchdog 守护进程 Provider - 为 Agent Teams 提供外部监控、故障检测和自动重启能力",
6
- "dependencies": [],
7
- "provides": ["provider:watchdog"],
8
- "metadata": {
9
- "deploy_assets": true,
10
- "deploy_path": "watchdog"
11
- },
12
- "config": {}
13
- }
@@ -1,249 +0,0 @@
1
- # Dispatcher Daemon Helpers Reference (DISP-001/002/003)
2
-
3
- > 本文件是 skill-agent-dispatcher Step 6.6 的按需参考(渐进式加载,WP-D6)。监控循环主体仍在本体 skill.md;本文件的辅助函数**仅在实现守护进程集成时 Read**。
4
-
5
- ### Step 6.6: 守护进程辅助函数 (DISP-001/002/003)
6
-
7
- 以下辅助函数用于守护进程集成,在监控循环中被调用:
8
-
9
- #### get_process_pid()
10
- 获取当前进程 PID,用于心跳写入。
11
-
12
- ```
13
- def get_process_pid():
14
- """获取当前进程 PID"""
15
- # 方法 1: 通过 Bash 工具
16
- result = Bash(command="echo $$")
17
- return int(result.strip())
18
-
19
- # 方法 2: 通过环境变量 (如果可用)
20
- # return int(os.getenv("PID", "unknown"))
21
- ```
22
-
23
- #### now_iso8601()
24
- 获取当前时间的 ISO 8601 格式字符串。
25
-
26
- ```
27
- def now_iso8601():
28
- """返回当前时间的 ISO 8601 格式字符串"""
29
- from datetime import datetime, timezone
30
- return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
31
- ```
32
-
33
- #### create_task_file()
34
- 创建任务状态文件,用于守护进程监控单个任务进度。
35
-
36
- ```
37
- def create_task_file(task_id, wp_id, teamee_name, status, complexity_score):
38
- """创建或初始化任务状态文件"""
39
- task_data = {
40
- "task_id": str(task_id),
41
- "wp_id": wp_id,
42
- "teamee_name": teamee_name,
43
- "status": status,
44
- "complexity_score": complexity_score,
45
- "progress_markers": [
46
- {
47
- "time": now_iso8601(),
48
- "action": "started",
49
- "detail": f"Teamee {teamee_name} 开始执行"
50
- }
51
- ],
52
- "retry_count": 0,
53
- "max_retries": 3,
54
- "retry_history": [],
55
- "idle_nudge_sent": False, # idle 催促去重位(WP-183-2-impl F3):本 idle 窗口内是否已催促过,重 spawn 后由 update_task_file(reset_started_at=True) 顺带重置
56
- "started_at": now_iso8601(),
57
- "last_update": now_iso8601()
58
- }
59
- Write(
60
- file_path=f".claude-daemon/tasks/task-{task_id}.json",
61
- content=json_dumps(task_data, indent=2)
62
- )
63
- ```
64
-
65
- #### update_task_file()
66
- 更新任务状态文件,支持状态更新、追加进度标记、递增重试计数、刷新 idle 计时起点、设置/重置 idle 催促去重位。
67
-
68
- ```
69
- def update_task_file(task_id, status=None, increment_retry=False, append_marker=None,
70
- reset_started_at=False, set_idle_nudge=None):
71
- """更新任务状态文件
72
-
73
- 扩展参数(idle 自愈流程,WP-183-2-impl F3/F4 修复):
74
- - reset_started_at: 重 spawn 后刷新 started_at 为 now_iso8601(),
75
- 使新 Teamee 获得完整 idle_threshold 执行窗口,避免一出生即满足 idle 阈值(F4)。
76
- TaskList task 对象不携带时间字段,started_at 是 idle 计时的权威起点(见 F2)。
77
- - set_idle_nudge: True/False。True=记录本轮已催促(去重位),
78
- False=重 spawn 后重置为未催促,让新 Teamee 有一次催促机会(F3)。
79
- """
80
- task_path = f".claude-daemon/tasks/task-{task_id}.json"
81
- existing_data = Read(file_path=task_path)
82
- try:
83
- task_data = json_loads(existing_data)
84
- except Exception as e:
85
- # ── 状态输出(直接文本输出,禁止使用 SendMessage)──
86
- # 输出: "⚠️ 任务状态文件解析失败,跳过更新: {e}"
87
- return
88
-
89
- # 更新状态
90
- if status:
91
- task_data["status"] = status
92
-
93
- # 递增重试计数
94
- if increment_retry:
95
- task_data["retry_count"] += 1
96
- task_data["retry_history"].append({
97
- "time": now_iso8601(),
98
- "iteration": loop_iteration
99
- })
100
-
101
- # 追加进度标记
102
- if append_marker:
103
- task_data["progress_markers"].append({
104
- "time": now_iso8601(),
105
- "action": append_marker.get("action", "update"),
106
- "detail": append_marker.get("detail", "")
107
- })
108
-
109
- # 刷新 idle 计时起点(F4):重 spawn 后让新 Teamee 重新获得 idle_threshold 窗口
110
- if reset_started_at:
111
- task_data["started_at"] = now_iso8601()
112
-
113
- # 设置/重置 idle 催促去重位(F3):True=已催促本窗口,False=重 spawn 后清位
114
- if set_idle_nudge is not None:
115
- task_data["idle_nudge_sent"] = bool(set_idle_nudge)
116
-
117
- task_data["last_update"] = now_iso8601()
118
- Write(file_path=task_path, content=json_dumps(task_data, indent=2))
119
- ```
120
-
121
- #### read_task_file()
122
- 读取任务状态文件并解析为 dict(供 idle 检测读取 `started_at`/`idle_nudge_sent` 等权威字段)。
123
- TaskList 返回的 task 对象不携带 `assigned_at`/`started_at` 等时间字段,idle 计时起点
124
- 必须从任务状态文件读取(WP-183-2-impl F2 修复)。
125
-
126
- ```
127
- def read_task_file(task_id):
128
- """读取任务状态文件,返回 dict;文件不存在/解析失败返回 {}"""
129
- task_path = f".claude-daemon/tasks/task-{task_id}.json"
130
- if not file_exists(task_path):
131
- return {}
132
- try:
133
- return json_loads(Read(file_path=task_path))
134
- except Exception:
135
- return {}
136
- ```
137
-
138
- #### expected_product_path()
139
- 返回 task 的预期产物路径,供 idle 检测的 `Glob(expected_product_path(task))` 判定产物是否已生成。
140
- **WP-183-2-impl F1 修复**:WP 文档体系当前无"预期产物路径"声明字段,assignment 对象亦无该字段,
141
- 故此处降级为弱信号——返回 None 时,idle 检测的 `not product_exists` 恒为 True,产物判定退化为
142
- "task 状态文件 `last_update` 长时间未变 + 无新增 progress_marker"(由 assigned_at 比对 idle_threshold 体现)。
143
-
144
- TODO(后续 WP):若 WP 文档体系引入产物路径声明(如 assignment.expected_products 或 WP 文档
145
- `预期产物:` 列表),将本函数改为从该字段返回 Glob 路径,使 idle 检测升级为强信号产物判定。
146
-
147
- ```
148
- def expected_product_path(task):
149
- """返回 task 的预期产物路径;WP 文档体系暂无产物路径声明字段,降级返回 None(弱信号,F1)
150
-
151
- 降级理由:assignment 对象(role_id/role_prompt/memories/wp_doc_path/complexity_score/
152
- subagent_type/team_name/prompt)与 WP 文档当前均无产物路径字段,引入新字段需扩大改动范围
153
- 且与运行时不符。返回 None 时 Glob 调用方应将 product_exists 视为"未知→按停滞判定"。
154
- """
155
- # TODO: WP 文档体系引入产物路径声明后,从 assignment.expected_products 或 WP 文档读取
156
- return None
157
- ```
158
-
159
- > **调用方约定(idle 检测段)**:`expected_product_path(task)` 返回 None 时,idle 段不依赖
160
- > `Glob` 的返回值判定产物存在性,而是退化为时间+进度弱信号(`task_stalled` 中
161
- > `not product_exists` 对 None 结果恒 True,故停滞判定仅依赖 status 与时间阈值)。
162
-
163
- #### build_resume_prompt()
164
- 为复杂任务的 checkpoint_resume 重启策略构建 prompt,注入已完成文件上下文 + 失败项重点修复段(refine 通道,WP-176-6)。
165
-
166
- `failing_drivers` 来自 Agentic Loop Step 4.2 下发的 `dispatchTarget.failingDrivers`(经 daemon-actions 的 `failing_drivers` 字段传入),每项 `{wpId, category, item, reason}`。仅当列表非空时输出"重点修复"段,让重做 Teamee 针对性修复而非原样重做;为空(dispatch 首次执行)时不输出该段,向后兼容。
167
-
168
- ```
169
- def build_resume_prompt(teamee_name, task_id, role_prompt, completed_files, remaining, failing_drivers=None):
170
- """为 checkpoint_resume 重启策略构建 prompt(含 refine 重点修复段)"""
171
- # 渲染"重点修复"段:仅当有失败项明细时输出(修复偏差2,WP-176-6)
172
- if failing_drivers:
173
- refine_lines = chr(10).join(
174
- f"- [{d.get('category', '?')}] {d.get('item', '?')} — {d.get('reason', '?')}"
175
- f"(WP: {d.get('wpId', '?')})"
176
- for d in failing_drivers
177
- )
178
- refine_section = f'''
179
- ### 🔴 本轮重点修复的失败项(来自上轮 checklist,优先处理)
180
- 以下是你上轮 checklist 未通过的失败项明细。**请优先、针对性地修复这些项**,而非盲目原样重做:
181
- {refine_lines}
182
-
183
- 逐条核对你修复了每一项的失败原因(reason)。这些是 refine 的核心目标——只有它们通过,本轮才算有效改进(而非无效重做)。
184
- '''
185
- else:
186
- refine_section = "" # failing_drivers 为空(dispatch 首次执行)时不输出该段,向后兼容
187
-
188
- return f'''你是 {teamee_name},是一名 {role_prompt}。
189
-
190
- ## 任务重启 (Checkpoint Resume)
191
-
192
- 你正在重新执行任务 #{task_id}。之前的执行已完成部分工作,你将从断点继续。
193
-
194
- ### 已完成的文件
195
- {chr(10).join(f"- {f}" for f in completed_files)}
196
-
197
- ### 待完成的工作
198
- {chr(10).join(f"- {r}" for r in remaining)}
199
- {refine_section}
200
- 请阅读已完成文件的最新状态,然后继续执行剩余工作。
201
- 不要重复已完成的工作,直接从断点继续。
202
- '''
203
- ```
204
-
205
- #### build_refine_prompt()
206
- 为 full_restart 重启策略构建 refine prompt:在标准单任务 prompt 基础上注入"重点修复"段(refine 通道,WP-176-6)。
207
-
208
- retry 时若 WP 无 checkpoint,Think 选 `full_restart` 策略,此时同样需要让承接 Teamee 知道"重点修哪些失败项",而非从头盲目重做。`failing_drivers` 来源与 `build_resume_prompt` 一致(Agentic Loop Step 4.2 的 `dispatchTarget.failingDrivers`,经 daemon-actions `failing_drivers` 字段传入)。为空时不注入 refine 段,退化为标准 `build_single_task_prompt`。
209
-
210
- ```
211
- def build_refine_prompt(teamee_name, task_id, role_prompt, memories, wp_doc_path, failing_drivers=None):
212
- """为 full_restart retry 构建 prompt(在标准单任务 prompt 上叠加 refine 重点修复段)"""
213
- # 基础 prompt:复用标准单任务构造(角色赋能 + 记忆 + WP 文档路径)
214
- base_prompt = build_single_task_prompt(
215
- teamee_name=teamee_name,
216
- task_id=task_id,
217
- role_prompt=role_prompt,
218
- memories=memories,
219
- wp_doc_path=wp_doc_path
220
- )
221
-
222
- # 仅当有失败项明细时追加 refine 段(修复偏差2,WP-176-6)
223
- if failing_drivers:
224
- refine_lines = chr(10).join(
225
- f"- [{d.get('category', '?')}] {d.get('item', '?')} — {d.get('reason', '?')}"
226
- f"(WP: {d.get('wpId', '?')})"
227
- for d in failing_drivers
228
- )
229
- refine_section = f'''
230
-
231
- ---
232
-
233
- ## 🔴 本轮重点修复的失败项(来自上轮 checklist,优先处理)
234
-
235
- 你是在 retry(full_restart)模式下重新执行任务 #{task_id}。以下是你上轮 checklist 未通过的失败项明细。**请优先、针对性地修复这些项**,而非盲目原样重做:
236
- {refine_lines}
237
-
238
- 逐条核对你修复了每一项的失败原因(reason)。这些是 refine 的核心目标——只有它们通过,本轮才算有效改进(而非无效重做)。
239
- '''
240
- return base_prompt + refine_section
241
-
242
- # failing_drivers 为空(dispatch 首次执行 / 无失败项明细)→ 退化为标准单任务 prompt
243
- return base_prompt
244
- ```
245
-
246
- **进度标记追加时机**:
247
- 1. Teamee 发送消息时 (通过 SendMessage 监听)
248
- 2. 检测到文件变更时 (通过 Git 状态或文件系统监听)
249
- 3. 任务状态变更时 (完成/失败/重试)
@@ -1,10 +0,0 @@
1
- {
2
- "name": "skill-watchdog-manager",
3
- "version": "1.0.0",
4
- "type": "skill",
5
- "description": "Use when user says \"启动守护进程\", \"watchdog\", \"守护进程状态\", or needs to manage the Watchdog daemon for agent-dispatcher monitoring.",
6
- "triggers": ["启动守护进程", "watchdog", "守护进程状态", "停止守护进程", "watchdog status", "watchdog start", "watchdog stop"],
7
- "dependencies": ["provider:watchdog"],
8
- "provides": ["skill:watchdog-manager"],
9
- "config": {}
10
- }
@@ -1,143 +0,0 @@
1
- ---
2
- name: skill-watchdog-manager
3
- description: "Use when user says \"启动守护进程\", \"watchdog\", \"守护进程状态\", or needs to manage the Watchdog daemon for agent-dispatcher monitoring."
4
- ---
5
-
6
- # Watchdog Manager
7
-
8
- Watchdog 守护进程管理技能,用于启动/停止/查看守护进程状态,与 agent-dispatcher 配合使用。
9
-
10
- ## When to Use
11
-
12
- **触发词**:
13
- - "启动守护进程" / "开启 watchdog"
14
- - "停止守护进程" / "关闭 watchdog"
15
- - "守护进程状态" / "watchdog 状态"
16
- - "watchdog" / "watchdog start" / "watchdog stop"
17
-
18
- ## Prerequisites
19
-
20
- Watchdog 必须已部署到项目中。检查条件:
21
-
22
- ```
23
- # 检查 watchdog 是否已部署
24
- file_exists = Bash(command="test -f .claude/watchdog/watchdog.js && echo 'exists' || echo 'not_found'")
25
- ```
26
-
27
- **如果文件不存在**:说明 watchdog provider 未启用。告知用户需要在 `plugins/plugin-registry.json` 中启用 `provider-watchdog` 后重新执行 `node bin/doukui.js build`。
28
-
29
- ## Commands
30
-
31
- ### 初始化(首次使用)
32
-
33
- ```bash
34
- node .claude/watchdog/watchdog.js init
35
- ```
36
-
37
- 创建 `.claude-daemon/` 目录和默认配置文件。
38
-
39
- ### 启动守护进程
40
-
41
- ```bash
42
- # 前台模式(调试用)
43
- node .claude/watchdog/watchdog.js start --foreground
44
-
45
- # 后台模式(生产用,默认)
46
- node .claude/watchdog/watchdog.js start
47
- ```
48
-
49
- ### 查看状态
50
-
51
- ```bash
52
- node .claude/watchdog/watchdog.js status
53
- ```
54
-
55
- 输出包括:PID、运行模式、健康状态、会话信息、任务列表、重启历史、熔断状态。
56
-
57
- ### 手动重启任务
58
-
59
- ```bash
60
- node .claude/watchdog/watchdog.js restart --task <task_id>
61
- ```
62
-
63
- ### 暂停/恢复检测
64
-
65
- ```bash
66
- # 暂停
67
- node .claude/watchdog/watchdog.js pause
68
-
69
- # 恢复
70
- node .claude/watchdog/watchdog.js pause --resume
71
- ```
72
-
73
- ### 停止守护进程
74
-
75
- ```bash
76
- node .claude/watchdog/watchdog.js stop
77
- ```
78
-
79
- ## Workflow Integration
80
-
81
- ### 与 agent-dispatcher 配合
82
-
83
- Watchdog 通过文件系统与 agent-dispatcher 通信:
84
-
85
- ```
86
- agent-dispatcher 写入 → .claude-daemon/heartbeat.json ← watchdog 读取
87
- agent-dispatcher 写入 → .claude-daemon/tasks/task-{id}.json ← watchdog 读取
88
- watchdog 写入 → .claude-daemon/daemon-actions.json ← agent-dispatcher 读取
89
- ```
90
-
91
- **推荐工作流**:
92
-
93
- 1. 用户发出"批量执行"请求 → agent-dispatcher skill 被触发
94
- 2. agent-dispatcher 开始监控循环,自动写入心跳和任务文件(DISP-001/002)
95
- 3. watchdog 独立运行,检测卡死任务并下发 restart/abort 指令(DISP-003)
96
- 4. 任务完成后 watchdog 自动检测并退出
97
-
98
- **启动时序**:
99
-
100
- ```
101
- # 终端 1:先启动 watchdog
102
- node .claude/watchdog/watchdog.js start
103
-
104
- # 终端 2:再启动 agent-dispatcher 批量任务
105
- # (agent-dispatcher 会自动写入心跳和任务文件)
106
- ```
107
-
108
- ## Architecture Reference
109
-
110
- ### 三级检测
111
-
112
- | 等级 | 检测目标 | 判定条件 | 动作 |
113
- |------|----------|----------|------|
114
- | L1 任务级 | 单个 Teamee | task-{id}.json 无更新且无新 progress_markers | restart 指令 |
115
- | L2 会话级 | Team Lead | heartbeat.json 无更新 | 检查 OS 进程 |
116
- | L3 进程级 | Claude Code CLI | OS 进程 PID 不存在 | abort_all 指令 |
117
-
118
- ### 四层防御
119
-
120
- 1. retry_count 计数器(max_retries: 3)
121
- 2. 动作消费确认(防止重复下发)
122
- 3. 指数退避(冷却: 0/2/5 分钟)
123
- 4. 全局熔断(连续 3 次失败触发)
124
-
125
- ### 重启策略
126
-
127
- - `full_restart`:complexity_score <= 6 的简单任务
128
- - `checkpoint_resume`:complexity_score > 6 的复杂任务,注入已完成文件上下文
129
-
130
- ## Configuration
131
-
132
- 配置文件:`.claude-daemon/daemon-config.json`
133
-
134
- 关键配置项:
135
- - `check_interval_sec`: 守护进程轮询间隔(默认 30 秒)
136
- - `timeouts.task_stalled_min`: 单任务无进展超时(默认 15 分钟)
137
- - `retry.max_retries`: 单任务最大重试次数(默认 3)
138
-
139
- ## Error Handling
140
-
141
- - **守护进程启动失败**:检查 `.claude-daemon/daemon-stdout.log` 和 `daemon-stderr.log`
142
- - **任务反复重启**:查看熔断状态,可能需要调整 `timeouts.task_stalled_min` 或 `retry.max_retries`
143
- - **进程检测不准**:Windows 上使用 `tasklist`,Unix 上使用 `kill -0`