doukui 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +42 -0
- package/README.md +147 -2
- package/bin/commands/build.js +178 -0
- package/bin/commands/config.js +88 -0
- package/bin/commands/help.js +83 -0
- package/bin/commands/init.js +194 -0
- package/bin/commands/install.js +202 -0
- package/bin/commands/interactive.js +352 -0
- package/bin/commands/list.js +108 -0
- package/bin/commands/loop-server.js +357 -0
- package/bin/commands/loop.js +1398 -0
- package/bin/commands/migrate.js +120 -0
- package/bin/commands/setup-global.js +81 -0
- package/bin/commands/status.js +140 -0
- package/bin/commands/team-cleanup.js +190 -0
- package/bin/commands/validate-config.js +35 -0
- package/bin/commands/validate.js +21 -0
- package/bin/commands/version.js +22 -0
- package/bin/context.js +143 -0
- package/bin/doukui.js +216 -0
- package/package.json +47 -4
- package/plugins/contracts/capabilities.js +268 -0
- package/plugins/contracts/checkresult-schema.json +75 -0
- package/plugins/contracts/config-schema.json +179 -0
- package/plugins/contracts/plugin-interface.js +262 -0
- package/plugins/contracts/plugin-schema.json +104 -0
- package/plugins/core/hook-session-start/index.js +281 -0
- package/plugins/core/hook-session-start/plugin.json +7 -0
- package/plugins/core/hook-skill-gate/index.js +661 -0
- package/plugins/core/hook-skill-gate/plugin.json +12 -0
- package/plugins/core/provider-loop-engine/index.js +1397 -0
- package/plugins/core/provider-loop-engine/plugin.json +15 -0
- package/plugins/core/provider-memory-store/index.js +510 -0
- package/plugins/core/provider-memory-store/plugin.json +9 -0
- package/plugins/core/provider-role-registry/index.js +376 -0
- package/plugins/core/provider-role-registry/plugin.json +9 -0
- package/plugins/core/provider-state-store/index.js +244 -0
- package/plugins/core/provider-state-store/plugin.json +9 -0
- package/plugins/core/provider-watchdog/assets/daemon-config.template.json +32 -0
- package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +676 -0
- package/plugins/core/provider-watchdog/assets/watchdog.js +754 -0
- package/plugins/core/provider-watchdog/index.js +151 -0
- package/plugins/core/provider-watchdog/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +214 -0
- package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +249 -0
- package/plugins/core/skill-agent-dispatcher/plugin.json +13 -0
- package/plugins/core/skill-agent-dispatcher/roles-reference.md +253 -0
- package/plugins/core/skill-agent-dispatcher/skill.md +1291 -0
- package/plugins/core/skill-agentic-loop/plugin.json +20 -0
- package/plugins/core/skill-agentic-loop/skill.md +572 -0
- package/plugins/core/skill-batch-task-creator/plugin.json +15 -0
- package/plugins/core/skill-batch-task-creator/skill.md +620 -0
- package/plugins/core/skill-checklist/plugin.json +10 -0
- package/plugins/core/skill-checklist/skill.md +171 -0
- package/plugins/core/skill-completion-report/plugin.json +10 -0
- package/plugins/core/skill-completion-report/skill.md +331 -0
- package/plugins/core/skill-doukui-plan/plugin.json +15 -0
- package/plugins/core/skill-doukui-plan/skill.md +233 -0
- package/plugins/core/skill-doukui-sync/plugin.json +10 -0
- package/plugins/core/skill-doukui-sync/skill.md +76 -0
- package/plugins/core/skill-experience-logger/plugin.json +10 -0
- package/plugins/core/skill-experience-logger/skill.md +235 -0
- package/plugins/core/skill-human-checkpoint/plugin.json +10 -0
- package/plugins/core/skill-human-checkpoint/skill.md +194 -0
- package/plugins/core/skill-progress-tracker/plugin.json +10 -0
- package/plugins/core/skill-progress-tracker/skill.md +228 -0
- package/plugins/core/skill-role-manager/plugin.json +10 -0
- package/plugins/core/skill-role-manager/skill.md +252 -0
- package/plugins/core/skill-split-work-package/plugin.json +15 -0
- package/plugins/core/skill-split-work-package/skill.md +441 -0
- package/plugins/core/skill-task-archive/plugin.json +10 -0
- package/plugins/core/skill-task-archive/skill.md +116 -0
- package/plugins/core/skill-task-creator/plugin.json +15 -0
- package/plugins/core/skill-task-creator/skill.md +886 -0
- package/plugins/core/skill-team-cleanup/plugin.json +10 -0
- package/plugins/core/skill-team-cleanup/skill.md +266 -0
- package/plugins/core/skill-watchdog-manager/plugin.json +10 -0
- package/plugins/core/skill-watchdog-manager/skill.md +143 -0
- package/plugins/core/skill-workflow-orchestrator/plugin.json +13 -0
- package/plugins/core/skill-workflow-orchestrator/skill.md +273 -0
- package/plugins/core/validator-doc-sync/index.js +248 -0
- package/plugins/core/validator-doc-sync/plugin.json +12 -0
- package/plugins/core/validator-work-package/index.js +300 -0
- package/plugins/core/validator-work-package/plugin.json +12 -0
- package/plugins/plugin-registry.json +186 -0
- package/plugins/runtime/agent-def-generator.js +150 -0
- package/plugins/runtime/audit-logger.js +311 -0
- package/plugins/runtime/build-cli.js +89 -0
- package/plugins/runtime/checkresult-validator.js +131 -0
- package/plugins/runtime/claude-md-injector.js +159 -0
- package/plugins/runtime/cleanup-utils.js +293 -0
- package/plugins/runtime/config-manager.js +317 -0
- package/plugins/runtime/config-validator.js +320 -0
- package/plugins/runtime/context-window.js +81 -0
- package/plugins/runtime/event-bus.js +207 -0
- package/plugins/runtime/executor-claude.js +828 -0
- package/plugins/runtime/executor-default.js +448 -0
- package/plugins/runtime/executor-local.js +178 -0
- package/plugins/runtime/executor-sdk.js +390 -0
- package/plugins/runtime/harness-build.js +1037 -0
- package/plugins/runtime/hook-dispatcher.js +315 -0
- package/plugins/runtime/logger.js +192 -0
- package/plugins/runtime/loop-actuator.js +292 -0
- package/plugins/runtime/loop-coordinator.js +347 -0
- package/plugins/runtime/loop-defaults.js +29 -0
- package/plugins/runtime/loop-dispatch-batch.js +247 -0
- package/plugins/runtime/loop-executor.js +120 -0
- package/plugins/runtime/loop-report.js +327 -0
- package/plugins/runtime/loop-server-core.js +750 -0
- package/plugins/runtime/loop-snapshot.js +581 -0
- package/plugins/runtime/loop-trace.js +242 -0
- package/plugins/runtime/loop-worktree.js +404 -0
- package/plugins/runtime/manifest-resolver.js +457 -0
- package/plugins/runtime/multi-window-coordinator.js +560 -0
- package/plugins/runtime/objective-verifier.js +136 -0
- package/plugins/runtime/plan-reader.js +763 -0
- package/plugins/runtime/plugin-loader.js +798 -0
- package/plugins/runtime/plugin-trust.js +182 -0
- package/plugins/runtime/plugin-validator.js +491 -0
- package/plugins/runtime/provider-failover.js +114 -0
- package/plugins/runtime/provider-resolver.js +342 -0
- package/plugins/runtime/reflection-evaluator.js +540 -0
- package/plugins/runtime/resolve-plugin-path.js +297 -0
- package/plugins/runtime/safe-path.js +119 -0
- package/plugins/runtime/sandbox-context.js +235 -0
- package/plugins/runtime/sandbox-manager.js +609 -0
- package/plugins/runtime/sandbox-worker.js +215 -0
- package/plugins/runtime/settings-merger.js +172 -0
- package/plugins/runtime/state-store.js +527 -0
- package/plugins/runtime/team-cleanup.js +497 -0
- package/plugins/runtime/text-tokenize.js +25 -0
- package/plugins/runtime/validator-pipeline.js +475 -0
- package/plugins/runtime/yaml-parser.js +692 -0
- package/templates/harness-config.yaml +388 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: skill-workflow-orchestrator
|
|
3
|
+
description: "Use when user says \"开始工作流\", \"执行完整流程\", or needs to run the full development workflow from requirements to completion with automatic checkpoint management."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow Orchestrator
|
|
7
|
+
|
|
8
|
+
整体工作流编排技能,协调各阶段 skills 按正确顺序执行。
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
**触发词**:
|
|
13
|
+
- "开始工作流" / "执行完整流程"
|
|
14
|
+
- "从需求开始" / "完整开发流程"
|
|
15
|
+
- "启动工作流" / "运行工作流"
|
|
16
|
+
|
|
17
|
+
## Workflow Stages
|
|
18
|
+
|
|
19
|
+
```mermaid
|
|
20
|
+
flowchart TB
|
|
21
|
+
subgraph P0["阶段零:需求与规划"]
|
|
22
|
+
A1["用户提出需求"] --> A2["AI 拆分工作包"]
|
|
23
|
+
A2 --> A3["编写文档"]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
subgraph P1["🔴 人介入审核"]
|
|
27
|
+
H1["暂停等待审核"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
subgraph P2["阶段二:执行实现"]
|
|
31
|
+
B1["执行工作包"]
|
|
32
|
+
B2["编写测试"]
|
|
33
|
+
B3["运行测试"]
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
subgraph P3["阶段三:检查与交付"]
|
|
37
|
+
C1["执行 Checklist"]
|
|
38
|
+
C2["记录经验"]
|
|
39
|
+
C3["更新进度"]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
subgraph P4["阶段四:汇报询问"]
|
|
43
|
+
D1["生成完成报告"]
|
|
44
|
+
D2["询问下一步"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
P0 --> P1
|
|
48
|
+
P1 --> P2
|
|
49
|
+
P2 --> P3
|
|
50
|
+
P3 --> P4
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Stage Details
|
|
54
|
+
|
|
55
|
+
### 阶段零:需求与规划
|
|
56
|
+
|
|
57
|
+
**调用的 Skills**:
|
|
58
|
+
- `task-creator` / `split-work-package` - 拆分工作包
|
|
59
|
+
|
|
60
|
+
**输出**:
|
|
61
|
+
- 工作包 ID 和详情
|
|
62
|
+
- 文档草稿(如需要)
|
|
63
|
+
|
|
64
|
+
### 阶段一:人介入审核 🔴
|
|
65
|
+
|
|
66
|
+
**调用的 Skills**:
|
|
67
|
+
- `human-checkpoint` - 强制暂停等待审核
|
|
68
|
+
|
|
69
|
+
**行为**:
|
|
70
|
+
- 输出审核清单
|
|
71
|
+
- 等待用户确认
|
|
72
|
+
- 处理修改意见
|
|
73
|
+
|
|
74
|
+
### 阶段二:执行实现
|
|
75
|
+
|
|
76
|
+
**调用的 Skills**:
|
|
77
|
+
- `agent-dispatcher` - 批量执行(如适用)
|
|
78
|
+
- `gut-testing` - 编写/运行测试
|
|
79
|
+
|
|
80
|
+
**行为**:
|
|
81
|
+
- 按依赖顺序执行工作包
|
|
82
|
+
- 每个工作包完成后运行测试
|
|
83
|
+
- 收集执行结果
|
|
84
|
+
|
|
85
|
+
### 阶段三:检查与交付
|
|
86
|
+
|
|
87
|
+
**调用的 Skills**:
|
|
88
|
+
- `checklist` - 质量检查
|
|
89
|
+
- `experience-logger` - 记录经验
|
|
90
|
+
- `progress-manager` / `record-progress` - 更新进度
|
|
91
|
+
|
|
92
|
+
**行为**:
|
|
93
|
+
- 执行完整检查清单
|
|
94
|
+
- 记录遇到的问题和解决方案
|
|
95
|
+
- 更新所有进度文档
|
|
96
|
+
|
|
97
|
+
### 阶段四:汇报询问
|
|
98
|
+
|
|
99
|
+
**调用的 Skills**:
|
|
100
|
+
- `completion-report` - 生成报告
|
|
101
|
+
|
|
102
|
+
**行为**:
|
|
103
|
+
- 生成标准化完成报告
|
|
104
|
+
- 明确询问下一步安排
|
|
105
|
+
- 等待用户指令
|
|
106
|
+
|
|
107
|
+
## Flow
|
|
108
|
+
|
|
109
|
+
```dot
|
|
110
|
+
digraph orchestrator {
|
|
111
|
+
rankdir=TB;
|
|
112
|
+
|
|
113
|
+
"开始工作流" [shape=box];
|
|
114
|
+
"阶段0: 需求与规划" [shape=box];
|
|
115
|
+
"阶段1: 人介入审核" [shape=box, style=filled, fillcolor=red];
|
|
116
|
+
"用户确认?" [shape=diamond];
|
|
117
|
+
"阶段2: 执行实现" [shape=box];
|
|
118
|
+
"阶段3: 检查与交付" [shape=box];
|
|
119
|
+
"阶段4: 汇报询问" [shape=box];
|
|
120
|
+
"继续?" [shape=diamond];
|
|
121
|
+
"结束" [shape=box];
|
|
122
|
+
|
|
123
|
+
"开始工作流" -> "阶段0: 需求与规划";
|
|
124
|
+
"阶段0: 需求与规划" -> "阶段1: 人介入审核";
|
|
125
|
+
"阶段1: 人介入审核" -> "用户确认?";
|
|
126
|
+
"用户确认?" -> "阶段2: 执行实现" [label="确认"];
|
|
127
|
+
"用户确认?" -> "阶段0: 需求与规划" [label="修改"];
|
|
128
|
+
"阶段2: 执行实现" -> "阶段3: 检查与交付";
|
|
129
|
+
"阶段3: 检查与交付" -> "阶段4: 汇报询问";
|
|
130
|
+
"阶段4: 汇报询问" -> "继续?";
|
|
131
|
+
"继续?" -> "阶段0: 需求与规划" [label="新任务"];
|
|
132
|
+
"继续?" -> "结束" [label="结束"];
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Execution Commands
|
|
137
|
+
|
|
138
|
+
### 启动完整工作流
|
|
139
|
+
```
|
|
140
|
+
用户: 开始工作流,实现 XXX 功能
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
执行流程:
|
|
144
|
+
1. 调用 `task-creator` 拆分工作包
|
|
145
|
+
2. 调用 `human-checkpoint` 等待审核
|
|
146
|
+
3. 用户确认后调用 `agent-dispatcher` 执行
|
|
147
|
+
4. 调用 `checklist` 检查
|
|
148
|
+
5. 调用 `experience-logger` 记录
|
|
149
|
+
6. 调用 `completion-report` 汇报
|
|
150
|
+
|
|
151
|
+
### 从特定阶段开始
|
|
152
|
+
```
|
|
153
|
+
用户: 从执行阶段开始工作流
|
|
154
|
+
用户: 跳过审核直接执行
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 仅执行检查阶段
|
|
158
|
+
```
|
|
159
|
+
用户: 执行检查阶段
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Skill Coordination Matrix
|
|
163
|
+
|
|
164
|
+
| 阶段 | 主 Skill | 协作 Skills | 输出 |
|
|
165
|
+
|------|----------|-------------|------|
|
|
166
|
+
| 需求与规划 | task-creator | split-work-package | 工作包清单 |
|
|
167
|
+
| 人介入审核 | human-checkpoint | - | 用户确认 |
|
|
168
|
+
| 执行实现 | agent-dispatcher | gut-testing | 代码+测试 |
|
|
169
|
+
| 检查与交付 | checklist | experience-logger, record-progress | 检查报告 |
|
|
170
|
+
| 汇报询问 | completion-report | - | 完成报告 |
|
|
171
|
+
|
|
172
|
+
## Checkpoint Behavior
|
|
173
|
+
|
|
174
|
+
每个阶段之间的检查点行为:
|
|
175
|
+
|
|
176
|
+
```markdown
|
|
177
|
+
帅哥,[当前阶段]已完成,准备进入[下一阶段]。
|
|
178
|
+
|
|
179
|
+
📋 当前状态:
|
|
180
|
+
- 已完成: [已完成的内容]
|
|
181
|
+
- 待执行: [下一阶段内容]
|
|
182
|
+
|
|
183
|
+
🔴 确认后回复"继续"进入下一阶段,或提出修改意见。
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Error Recovery
|
|
187
|
+
|
|
188
|
+
### 阶段失败处理
|
|
189
|
+
|
|
190
|
+
| 阶段 | 失败场景 | 恢复策略 |
|
|
191
|
+
|------|----------|----------|
|
|
192
|
+
| 需求与规划 | 需求不明确 | 回到用户澄清 |
|
|
193
|
+
| 人介入审核 | 用户要求修改 | 重新规划后再次审核 |
|
|
194
|
+
| 执行实现 | 工作包执行失败 | 记录失败原因,继续其他工作包 |
|
|
195
|
+
| 检查与交付 | Checklist 不通过 | 修复问题后重新检查 |
|
|
196
|
+
| 汇报询问 | 用户不满意 | 回到执行阶段修正 |
|
|
197
|
+
|
|
198
|
+
### 工作流中断恢复
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
用户: 恢复工作流
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
执行流程:
|
|
205
|
+
1. 读取 `task.md` 确认当前状态
|
|
206
|
+
2. 确定中断点
|
|
207
|
+
3. 从中断阶段继续执行
|
|
208
|
+
|
|
209
|
+
## Quick Start Examples
|
|
210
|
+
|
|
211
|
+
### 示例 1: 完整新功能开发
|
|
212
|
+
```
|
|
213
|
+
用户: 开始工作流,实现成就系统
|
|
214
|
+
|
|
215
|
+
AI 执行:
|
|
216
|
+
1. [阶段0] 调用 task-creator 拆分成就系统工作包
|
|
217
|
+
2. [阶段1] 调用 human-checkpoint 等待审核
|
|
218
|
+
3. [用户确认后] 调用 agent-dispatcher 执行工作包
|
|
219
|
+
4. [阶段3] 调用 checklist 检查 + experience-logger 记录
|
|
220
|
+
5. [阶段4] 调用 completion-report 汇报询问
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 示例 2: 快速 Bug 修复
|
|
224
|
+
```
|
|
225
|
+
用户: 开始工作流,修复卡牌显示Bug
|
|
226
|
+
|
|
227
|
+
AI 执行:
|
|
228
|
+
1. [阶段0] 创建 WP-XXX 修复工作包
|
|
229
|
+
2. [阶段1] 简化审核(单工作包)
|
|
230
|
+
3. [阶段2] 直接执行修复
|
|
231
|
+
4. [阶段3] 检查 + 记录
|
|
232
|
+
5. [阶段4] 汇报完成
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### 示例 3: 批量任务执行
|
|
236
|
+
```
|
|
237
|
+
用户: 批量执行 WP-037 到 WP-040
|
|
238
|
+
|
|
239
|
+
AI 执行:
|
|
240
|
+
1. [跳过阶段0] 直接读取现有工作包
|
|
241
|
+
2. [阶段1] 确认执行计划
|
|
242
|
+
3. [阶段2] 调用 agent-dispatcher 并行执行
|
|
243
|
+
4. [阶段3] 批量检查 + 记录
|
|
244
|
+
5. [阶段4] 批量汇报
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Important
|
|
248
|
+
|
|
249
|
+
1. **阶段顺序不可跳过** - 必须按 P0→P1→P2→P3→P4 顺序执行
|
|
250
|
+
2. **人介入必须等待** - P1 阶段必须等待用户确认
|
|
251
|
+
3. **检查必须通过** - P3 阶段 checklist 不通过不能进入 P4
|
|
252
|
+
4. **汇报必须询问** - P4 阶段必须询问下一步安排
|
|
253
|
+
5. **状态必须记录** - 每个阶段完成后更新 task.md
|
|
254
|
+
6. **🔴 清理必须执行** - 如果使用了 agent-dispatcher,P2→P3 转换时必须验证 Teamee 已逻辑销毁(teamee_map 已空;当前 session implicit team 随 session 自动清理,无需 TeamDelete)
|
|
255
|
+
|
|
256
|
+
## 阶段间清理检查
|
|
257
|
+
|
|
258
|
+
**执行阶段 (P2) 完成后,进入检查阶段 (P3) 前**:
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
# 如果使用了 agent-dispatcher(批量执行)
|
|
262
|
+
if used_agent_teams:
|
|
263
|
+
# 验证 Teamee 已逻辑销毁(teamee_map 已空);当前 session implicit team 随 session 自动清理,无需 TeamDelete
|
|
264
|
+
if not teamee_map_empty:
|
|
265
|
+
print("⚠️ 警告: Teamee 未全部逻辑销毁(teamee_map 非空)!")
|
|
266
|
+
print("建议补执行 markTeameeDestroyed 清空映射表")
|
|
267
|
+
# 在报告中标注此警告
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**检查点验证**:
|
|
271
|
+
| 检查项 | 通过条件 | 失败处理 |
|
|
272
|
+
|--------|----------|----------|
|
|
273
|
+
| Teamee 已逻辑销毁 | teamee_map 已空 | 在报告中添加警告,建议补执行 markTeameeDestroyed |
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* validator-doc-sync - 文档同步验证器
|
|
3
|
+
*
|
|
4
|
+
* 检测 task.md 与 docs/wp/ 目录之间的不一致:
|
|
5
|
+
* - task.md 中列出但 docs/wp/ 中缺少的 WP 文档
|
|
6
|
+
* - docs/wp/ 中存在但 task.md 未列出的 WP 文档
|
|
7
|
+
* - 状态不一致(task.md 标记完成但 WP 文档内容为空等)
|
|
8
|
+
*
|
|
9
|
+
* 使用方式:
|
|
10
|
+
* var Validator = require('./index.js');
|
|
11
|
+
* var v = new Validator({ projectRoot: '/path/to/project' });
|
|
12
|
+
* var result = v.validate(); // { valid, errors, warnings }
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
var fs = require('fs');
|
|
18
|
+
var path = require('path');
|
|
19
|
+
var { ValidatorPlugin } = require('../../contracts/plugin-interface');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* WP 编号正则:匹配 task.md 表格行中的 WP-NNN
|
|
23
|
+
*/
|
|
24
|
+
var WP_TABLE_ROW_RE = /^\|\s*(WP-\d+)\s*\|/;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 状态标记正则
|
|
28
|
+
*/
|
|
29
|
+
var STATUS_COMPLETE_RE = /✅\s*完成/;
|
|
30
|
+
var STATUS_IN_PROGRESS_RE = /🔄\s*进行中/;
|
|
31
|
+
var STATUS_PENDING_RE = /📋\s*待开始/;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 从 task.md 提取状态标记
|
|
35
|
+
*/
|
|
36
|
+
function parseStatus(statusCell) {
|
|
37
|
+
if (STATUS_COMPLETE_RE.test(statusCell)) return 'completed';
|
|
38
|
+
if (STATUS_IN_PROGRESS_RE.test(statusCell)) return 'in-progress';
|
|
39
|
+
if (STATUS_PENDING_RE.test(statusCell)) return 'pending';
|
|
40
|
+
return 'unknown';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 检查文件内容是否实质为空
|
|
45
|
+
* 除去空白、标题行、YAML front matter 后内容极少视为空
|
|
46
|
+
*/
|
|
47
|
+
function isContentEmpty(content) {
|
|
48
|
+
if (!content) return true;
|
|
49
|
+
|
|
50
|
+
// 去除 YAML front matter
|
|
51
|
+
var body = content.replace(/^---[\s\S]*?---\n*/, '');
|
|
52
|
+
// 去除 markdown 标题和分隔线
|
|
53
|
+
body = body.replace(/^#{1,6}\s+.*$/gm, '');
|
|
54
|
+
body = body.replace(/^---+$/gm, '');
|
|
55
|
+
body = body.replace(/^>.*$/gm, '');
|
|
56
|
+
// 去除纯空白行
|
|
57
|
+
var lines = body.split('\n').filter(function (line) {
|
|
58
|
+
return line.trim().length > 0;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return lines.length < 3;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* DocSyncValidator
|
|
66
|
+
*/
|
|
67
|
+
class DocSyncValidator extends ValidatorPlugin {
|
|
68
|
+
/**
|
|
69
|
+
* @param {object} [options]
|
|
70
|
+
* @param {string} [options.projectRoot] - 项目根目录,默认 process.cwd()
|
|
71
|
+
*/
|
|
72
|
+
constructor(options) {
|
|
73
|
+
super();
|
|
74
|
+
options = options || {};
|
|
75
|
+
|
|
76
|
+
this.name = 'validator-doc-sync';
|
|
77
|
+
this.version = '1.0.0';
|
|
78
|
+
this.description = '文档同步验证器';
|
|
79
|
+
this.blocking = false;
|
|
80
|
+
|
|
81
|
+
/** @type {string} */
|
|
82
|
+
this._projectRoot = options.projectRoot || process.cwd();
|
|
83
|
+
/** @type {string} */
|
|
84
|
+
this._taskMdPath = path.join(this._projectRoot, 'task.md');
|
|
85
|
+
/** @type {string} */
|
|
86
|
+
this._docsWpDir = path.join(this._projectRoot, 'docs', 'wp');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 解析 task.md,提取所有 WP 条目及其状态
|
|
91
|
+
* @returns {Array<{id: string, status: string, rawStatus: string}>}
|
|
92
|
+
*/
|
|
93
|
+
parseTaskMd() {
|
|
94
|
+
var content = this._readFile(this._taskMdPath);
|
|
95
|
+
if (content === null) return [];
|
|
96
|
+
|
|
97
|
+
var entries = [];
|
|
98
|
+
var lines = content.split('\n');
|
|
99
|
+
|
|
100
|
+
for (var i = 0; i < lines.length; i++) {
|
|
101
|
+
var match = WP_TABLE_ROW_RE.exec(lines[i]);
|
|
102
|
+
if (match) {
|
|
103
|
+
// 拆分表格单元格
|
|
104
|
+
var cells = lines[i].split('|').filter(function (c) { return c.trim().length > 0; });
|
|
105
|
+
var rawStatus = cells.length >= 2 ? cells[1].trim() : '';
|
|
106
|
+
// cells[0] 是 WP ID, cells[1] 是标题, cells[2] 是状态
|
|
107
|
+
// 实际格式:| WP-NNN | 标题 | 状态 | ...
|
|
108
|
+
rawStatus = cells.length >= 3 ? cells[2].trim() : (cells.length >= 2 ? cells[1].trim() : '');
|
|
109
|
+
|
|
110
|
+
entries.push({
|
|
111
|
+
id: match[1],
|
|
112
|
+
status: parseStatus(rawStatus),
|
|
113
|
+
rawStatus: rawStatus,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return entries;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 扫描 docs/wp/ 目录,返回存在的 WP 文件列表
|
|
123
|
+
* @returns {string[]} WP ID 列表,如 ['WP-001', 'WP-002']
|
|
124
|
+
*/
|
|
125
|
+
scanDocsWp() {
|
|
126
|
+
var entries = [];
|
|
127
|
+
var files = this._readdir(this._docsWpDir);
|
|
128
|
+
|
|
129
|
+
for (var i = 0; i < files.length; i++) {
|
|
130
|
+
var match = /^(WP-\d+)\.md$/i.exec(files[i]);
|
|
131
|
+
if (match) {
|
|
132
|
+
entries.push(match[1].toUpperCase());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return entries;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 执行文档同步验证
|
|
141
|
+
* @param {object} [context] - 验证上下文(保留兼容接口)
|
|
142
|
+
* @returns {{ valid: boolean, errors: string[], warnings: string[] }}
|
|
143
|
+
*/
|
|
144
|
+
validate(context) {
|
|
145
|
+
var errors = [];
|
|
146
|
+
var warnings = [];
|
|
147
|
+
|
|
148
|
+
// 1. 检查 task.md 可读
|
|
149
|
+
var taskEntries = this.parseTaskMd();
|
|
150
|
+
if (taskEntries.length === 0) {
|
|
151
|
+
// 尝试读取原始文件判断是真的空还是读不到
|
|
152
|
+
var rawContent = this._readFile(this._taskMdPath);
|
|
153
|
+
if (rawContent === null) {
|
|
154
|
+
errors.push('task.md 文件不存在或无法读取: ' + this._taskMdPath);
|
|
155
|
+
return { valid: false, errors: errors, warnings: warnings };
|
|
156
|
+
}
|
|
157
|
+
// 文件存在但解析不出 WP 条目
|
|
158
|
+
warnings.push('task.md 中未找到工作包条目');
|
|
159
|
+
return { valid: true, errors: errors, warnings: warnings };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 2. 检查 docs/wp/ 目录可读
|
|
163
|
+
var docFiles = this.scanDocsWp();
|
|
164
|
+
|
|
165
|
+
// 3. 构建索引集合
|
|
166
|
+
var taskMap = {};
|
|
167
|
+
for (var i = 0; i < taskEntries.length; i++) {
|
|
168
|
+
taskMap[taskEntries[i].id] = taskEntries[i];
|
|
169
|
+
}
|
|
170
|
+
var docSet = {};
|
|
171
|
+
for (var j = 0; j < docFiles.length; j++) {
|
|
172
|
+
docSet[docFiles[j]] = true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// 4. task.md 中有但 docs/wp/ 缺少的 WP
|
|
176
|
+
for (var k = 0; k < taskEntries.length; k++) {
|
|
177
|
+
var id = taskEntries[k].id;
|
|
178
|
+
if (!docSet[id]) {
|
|
179
|
+
errors.push(id + ' 在 task.md 中列出但 docs/wp/ 中缺少对应文档');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 5. docs/wp/ 中有但 task.md 未列出的 WP
|
|
184
|
+
for (var m = 0; m < docFiles.length; m++) {
|
|
185
|
+
var docId = docFiles[m];
|
|
186
|
+
if (!taskMap[docId]) {
|
|
187
|
+
warnings.push(docId + ' 在 docs/wp/ 中存在但 task.md 未列出');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 6. 状态不一致检测:task.md 标记完成但 WP 文档内容为空
|
|
192
|
+
for (var n = 0; n < taskEntries.length; n++) {
|
|
193
|
+
var entry = taskEntries[n];
|
|
194
|
+
if (entry.status === 'completed' && docSet[entry.id]) {
|
|
195
|
+
var wpPath = path.join(this._docsWpDir, entry.id + '.md');
|
|
196
|
+
var wpContent = this._readFile(wpPath);
|
|
197
|
+
if (wpContent !== null && isContentEmpty(wpContent)) {
|
|
198
|
+
errors.push(entry.id + ' 在 task.md 中标记为已完成,但 WP 文档内容实质为空');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// task.md 标记待开始但 WP 文档内容丰富(可能忘记更新状态)
|
|
203
|
+
if (entry.status === 'pending' && docSet[entry.id]) {
|
|
204
|
+
var wpPendingPath = path.join(this._docsWpDir, entry.id + '.md');
|
|
205
|
+
var wpPendingContent = this._readFile(wpPendingPath);
|
|
206
|
+
if (wpPendingContent !== null && !isContentEmpty(wpPendingContent)) {
|
|
207
|
+
warnings.push(entry.id + ' 在 task.md 中标记为待开始,但 WP 文档已有实质内容,可能需要更新状态');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
valid: errors.length === 0,
|
|
214
|
+
errors: errors,
|
|
215
|
+
warnings: warnings,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// --- internal helpers ---
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 同步读取文件,失败返回 null
|
|
223
|
+
* @param {string} filePath
|
|
224
|
+
* @returns {string|null}
|
|
225
|
+
*/
|
|
226
|
+
_readFile(filePath) {
|
|
227
|
+
try {
|
|
228
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
229
|
+
} catch (err) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 同步读取目录,失败返回空数组
|
|
236
|
+
* @param {string} dirPath
|
|
237
|
+
* @returns {string[]}
|
|
238
|
+
*/
|
|
239
|
+
_readdir(dirPath) {
|
|
240
|
+
try {
|
|
241
|
+
return fs.readdirSync(dirPath);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
module.exports = DocSyncValidator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "validator-doc-sync",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "validator",
|
|
5
|
+
"description": "文档同步验证器 - 检测 task.md 与 docs/wp/ 的不一致",
|
|
6
|
+
"dependencies": [],
|
|
7
|
+
"provides": ["validator:doc-sync"],
|
|
8
|
+
"metadata": {
|
|
9
|
+
"targets": ["build", "manual"]
|
|
10
|
+
},
|
|
11
|
+
"config": {}
|
|
12
|
+
}
|